<?xml version="1.0"?>
<ROWSET>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ADAOSM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ADAOSM</REFTABLE>
  <HASHVAL>00A4C2B8D3D06194825DF78F66C07AD52CEDA53F</HASHVAL>
  <TEXT>ALTER TABLE ADAOSM ADD CONSTRAINT PK_ADAOSM PRIMARY KEY (CODADAOSM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ADAOSM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ADAOSM1</REFTABLE>
  <HASHVAL>58A18454F2B5F76E86475153BE0BC09A971C56A9</HASHVAL>
  <TEXT>ALTER TABLE ADAOSM1 ADD CONSTRAINT PK_ADAOSM1 PRIMARY KEY (CODADAOSM1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ALERTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ALERTE</REFTABLE>
  <HASHVAL>1A2E3B3E3B1F2BE55D00B38CD304C68217E02937</HASHVAL>
  <TEXT>ALTER TABLE ALERTE ADD CONSTRAINT PK_ALERTE PRIMARY KEY (CODALERTA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ALERTE0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ALERTE0</REFTABLE>
  <HASHVAL>C317465174751BC7C624760D7ED930F2CAD8D9A0</HASHVAL>
  <TEXT>ALTER TABLE ALERTE0 ADD CONSTRAINT PK_ALERTE0 PRIMARY KEY (CODALERTA0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZA</REFTABLE>
  <HASHVAL>CAB8C2992A26E130346E12886D9639B071B7F7DF</HASHVAL>
  <TEXT>ALTER TABLE ANALIZA ADD CONSTRAINT PK_ANALIZA PRIMARY KEY (CODANALIZA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ANALIZA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZA1</REFTABLE>
  <HASHVAL>4554FCBD6E6E1D74C0FA4C30677192F083B8018D</HASHVAL>
  <TEXT>ALTER TABLE ANALIZA1 ADD CONSTRAINT PK_ANALIZA1 PRIMARY KEY (CODANALIZA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ANALIZANOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZANOD</REFTABLE>
  <HASHVAL>64AC8614EEFD2F362C40922B5EA5EA430CB30B8F</HASHVAL>
  <TEXT>ALTER TABLE ANALIZANOD ADD CONSTRAINT PK_ANALIZANOD PRIMARY KEY (CODANALIZANOD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_APELTELEFON</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>APELTELEFON</REFTABLE>
  <HASHVAL>DE55EA72D5587C1E278E361565541E8E6CED9B60</HASHVAL>
  <TEXT>ALTER TABLE APELTELEFON ADD CONSTRAINT PK_APELTELEFON PRIMARY KEY (CODAPEL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ASIGURARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ASIGURARI</REFTABLE>
  <HASHVAL>E7E4F980FF509D44F1175686BB2314508A6EB7C5</HASHVAL>
  <TEXT>ALTER TABLE ASIGURARI ADD CONSTRAINT PK_ASIGURARI PRIMARY KEY (CODASIGURARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ASIGURARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ASIGURARI1</REFTABLE>
  <HASHVAL>7B2FD8C525AA0FD4C23B548E1A9269F996B9403D</HASHVAL>
  <TEXT>ALTER TABLE ASIGURARI1 ADD CONSTRAINT PK_ASIGURARI1 PRIMARY KEY (CODASIGURARE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_AVARIECAROSERIE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>AVARIECAROSERIE</REFTABLE>
  <HASHVAL>4D6259324FA5FAB30099BC198508458CF27A4B24</HASHVAL>
  <TEXT>ALTER TABLE AVARIECAROSERIE ADD CONSTRAINT PK_AVARIECAROSERIE PRIMARY KEY (CODAVARIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_AWBCOMANDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>AWBCOMANDA</REFTABLE>
  <HASHVAL>D216FF93B8C0B5D7CBF3D7CEE6EC5C1C195E1B1C</HASHVAL>
  <TEXT>ALTER TABLE AWBCOMANDA ADD CONSTRAINT PK_AWBCOMANDA PRIMARY KEY (CODAWBCOMANDA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BANKAUTENTIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BANKAUTENTIF</REFTABLE>
  <HASHVAL>A0D8AA13A30233693829DC485F926F8D8E5E1B71</HASHVAL>
  <TEXT>ALTER TABLE BANKAUTENTIF ADD CONSTRAINT PK_BANKAUTENTIF PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BCAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BCAR</REFTABLE>
  <HASHVAL>41F945FC1ED6B241520460DE4EFEB5279E380E31</HASHVAL>
  <TEXT>ALTER TABLE BCAR ADD CONSTRAINT PK_BCAR PRIMARY KEY (CODBCAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BONLINKERR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BONLINKERR</REFTABLE>
  <HASHVAL>4BD98B0A2DAB2DFA4348B44A4948F5EE62728E58</HASHVAL>
  <TEXT>ALTER TABLE BONLINKERR ADD CONSTRAINT PK_BONLINKERR PRIMARY KEY (CODBONLINKERR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETCAP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETCAP</REFTABLE>
  <HASHVAL>228A796722CC3CCD0800F3CA20A99DDC8FEAB703</HASHVAL>
  <TEXT>ALTER TABLE BUGETCAP ADD CONSTRAINT PK_BUGETCAP PRIMARY KEY (CODBUGETCAP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETCAP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETCAP1</REFTABLE>
  <HASHVAL>526A5D187A6E8A7FBB4D28736D276FD5FDC715DE</HASHVAL>
  <TEXT>ALTER TABLE BUGETCAP1 ADD CONSTRAINT PK_BUGETCAP1 PRIMARY KEY (CODBUGETCAP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETCL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETCL</REFTABLE>
  <HASHVAL>5EB2D92DD06567B5FFA6C2F19FE54A3C337965DE</HASHVAL>
  <TEXT>ALTER TABLE BUGETCL ADD CONSTRAINT PK_BUGETCL PRIMARY KEY (CODBUGETCL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETMF</REFTABLE>
  <HASHVAL>23D6EDCE3D9827303B65BE659F0B58F5AF84D206</HASHVAL>
  <TEXT>ALTER TABLE BUGETMF ADD CONSTRAINT PK_BUGETMF PRIMARY KEY (CODBUGETMF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETMF1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETMF1</REFTABLE>
  <HASHVAL>C90DAB9CEB609EEE32683221C7EB01D8D2CD598D</HASHVAL>
  <TEXT>ALTER TABLE BUGETMF1 ADD CONSTRAINT PK_BUGETMF1 PRIMARY KEY (CODBUGETMF1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETPROD</REFTABLE>
  <HASHVAL>58F2306734B60B145E844599E707540595B49102</HASHVAL>
  <TEXT>ALTER TABLE BUGETPROD ADD CONSTRAINT PK_BUGETPROD PRIMARY KEY (CODBUGETPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETPRODP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETPRODP</REFTABLE>
  <HASHVAL>0DA2416A7888CF5090385F62156D8F6CEBF9ACFA</HASHVAL>
  <TEXT>ALTER TABLE BUGETPRODP ADD CONSTRAINT PK_BUGETPRODP PRIMARY KEY (CODBUGETPRODP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETPRODT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETPRODT</REFTABLE>
  <HASHVAL>02C62EE328145CE196E9BAC5EA4E896932907D11</HASHVAL>
  <TEXT>ALTER TABLE BUGETPRODT ADD CONSTRAINT PK_BUGETPRODT PRIMARY KEY (CODBUGETPRODT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETPRODV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETPRODV</REFTABLE>
  <HASHVAL>5C4C8A56C84521167B705B590F65281DA37C33EE</HASHVAL>
  <TEXT>ALTER TABLE BUGETPRODV ADD CONSTRAINT PK_BUGETPRODV PRIMARY KEY (CODBUGETPRODV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETRECTIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETRECTIF</REFTABLE>
  <HASHVAL>18B9C32173C9B6155D28DF524831A7232C75043E</HASHVAL>
  <TEXT>ALTER TABLE BUGETRECTIF ADD CONSTRAINT PK_BUGETRECTIF PRIMARY KEY (CODBUGETRECTIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETRECTIF1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETRECTIF1</REFTABLE>
  <HASHVAL>96A091F8D33C901C905EEC1CDE65C35F6B768A46</HASHVAL>
  <TEXT>ALTER TABLE BUGETRECTIF1 ADD CONSTRAINT PK_BUGETRECTIF1 PRIMARY KEY (CODBUGETRECTIF1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETSTOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETSTOC</REFTABLE>
  <HASHVAL>2FBAE9DD19658CCC4170F243AF971C028C0687FD</HASHVAL>
  <TEXT>ALTER TABLE BUGETSTOC ADD CONSTRAINT PK_BUGETSTOC PRIMARY KEY (CODBUGETSTOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETVCL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETVCL</REFTABLE>
  <HASHVAL>3CB183828DDC868C949D7C013D3D52A8CABA9D2F</HASHVAL>
  <TEXT>ALTER TABLE BUGETVCL ADD CONSTRAINT PK_BUGETVCL PRIMARY KEY (CODBUGETVCL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_BUGETVL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETVL</REFTABLE>
  <HASHVAL>A8F62761772A23DCA968F7D45371339963059640</HASHVAL>
  <TEXT>ALTER TABLE BUGETVL ADD CONSTRAINT PK_BUGETVL PRIMARY KEY (CODBUGETVL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CAENSEC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CAENSEC</REFTABLE>
  <HASHVAL>B10D98468F86B78E240125877320104D0308D7A6</HASHVAL>
  <TEXT>ALTER TABLE CAENSEC ADD CONSTRAINT PK_CAENSEC PRIMARY KEY (CODCAENSEC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CAMPANII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CAMPANII</REFTABLE>
  <HASHVAL>4D2AF12AE26344E124386EB5110F62F53F2134C7</HASHVAL>
  <TEXT>ALTER TABLE CAMPANII ADD CONSTRAINT PK_CAMPANII PRIMARY KEY (CODCAMPANIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CAMPANIICOST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CAMPANIICOST</REFTABLE>
  <HASHVAL>9E182775C3585AFBD9B9CB64AA643CB976C9D789</HASHVAL>
  <TEXT>ALTER TABLE CAMPANIICOST ADD CONSTRAINT PK_CAMPANIICOST PRIMARY KEY (CODCAMPANIECOST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CAMPANIIPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CAMPANIIPART</REFTABLE>
  <HASHVAL>477C9F0AAC1CD15362624BA79B8F799D9E7732A5</HASHVAL>
  <TEXT>ALTER TABLE CAMPANIIPART ADD CONSTRAINT PK_CAMPANIIPART PRIMARY KEY (CODCAMPANIEPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CAMPANIIVENIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CAMPANIIVENIT</REFTABLE>
  <HASHVAL>03C5C8E304364A5DE7DDE9EA135C0BD764C0C6CE</HASHVAL>
  <TEXT>ALTER TABLE CAMPANIIVENIT ADD CONSTRAINT PK_CAMPANIIVENIT PRIMARY KEY (CODCAMPANIEVENIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CANAMED</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CANAMED</REFTABLE>
  <HASHVAL>052A3FB5D964C13241F20DCE46C00C7A206AA748</HASHVAL>
  <TEXT>ALTER TABLE CANAMED ADD CONSTRAINT PK_CANAMED PRIMARY KEY (CODCANAMED) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CANAMED1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CANAMED1</REFTABLE>
  <HASHVAL>A930B7DC5477A4B22FCA1CAA2481A0AEE325E364</HASHVAL>
  <TEXT>ALTER TABLE CANAMED1 ADD CONSTRAINT PK_CANAMED1 PRIMARY KEY (CODCANAMED1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CANTAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CANTAR</REFTABLE>
  <HASHVAL>2A6829F581B8BECF95D9C979F1427BBE54FA7CC0</HASHVAL>
  <TEXT>ALTER TABLE CANTAR ADD CONSTRAINT PK_CANTAR PRIMARY KEY (CODCANTAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CARDURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CARDURI</REFTABLE>
  <HASHVAL>9A466CBE0012638953578C58ECAD79CF76ED251B</HASHVAL>
  <TEXT>ALTER TABLE CARDURI ADD CONSTRAINT PK_CARDURI PRIMARY KEY (CODCARD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CASTOT_PREPAY</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CASTOT_PREPAY</REFTABLE>
  <HASHVAL>F2F755F5253BF98840BDB8DD9C83C47062C7A010</HASHVAL>
  <TEXT>ALTER TABLE CASTOT_PREPAY ADD CONSTRAINT PK_CASTOT_PREPAY PRIMARY KEY (COD_CASTOTPREPAY) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CASTOT_UTILITY</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CASTOT_UTILITY</REFTABLE>
  <HASHVAL>FB02EDB493F1B66F3B01D4CE235A3981EB02A213</HASHVAL>
  <TEXT>ALTER TABLE CASTOT_UTILITY ADD CONSTRAINT PK_CASTOT_UTILITY PRIMARY KEY (COD_CASTOTUTILITY) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CATEGARTTI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CATEGARTTI</REFTABLE>
  <HASHVAL>F4674608C9B08C708A029AC9D3A31627CD476EB2</HASHVAL>
  <TEXT>ALTER TABLE CATEGARTTI ADD CONSTRAINT PK_CATEGARTTI PRIMARY KEY (CODCATEGARTTI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CATEGCONST</REFTABLE>
  <HASHVAL>A4A72BCD40EFE70ABCD531B4439D77EEB0484D28</HASHVAL>
  <TEXT>ALTER TABLE CATEGCONST ADD CONSTRAINT PK_CATEGCONST PRIMARY KEY (CODCATEG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CENTRALIZARENC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CENTRALIZARENC</REFTABLE>
  <HASHVAL>042205D594555A38A7BFC01025D52CC28AF7C979</HASHVAL>
  <TEXT>ALTER TABLE CENTRALIZARENC ADD CONSTRAINT PK_CENTRALIZARENC PRIMARY KEY (CODCENTRALIZARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CENTRECOST</REFTABLE>
  <HASHVAL>113857910E54E0BB1400807DE243C31AD7F54410</HASHVAL>
  <TEXT>ALTER TABLE CENTRECOST ADD CONSTRAINT PK_CENTRECOST PRIMARY KEY (CODCENTRU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CENTRECOSTA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CENTRECOSTA</REFTABLE>
  <HASHVAL>1ED2F94E1F2B22552BDF0BC02070A434000722B1</HASHVAL>
  <TEXT>ALTER TABLE CENTRECOSTA ADD CONSTRAINT PK_CENTRECOSTA PRIMARY KEY (CODCENTRUA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CERTIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CERTIF</REFTABLE>
  <HASHVAL>FFE4071D99F3D5A8CB8719CBBEB56F2D4B408C2C</HASHVAL>
  <TEXT>ALTER TABLE CERTIF ADD CONSTRAINT PK_CERTIF PRIMARY KEY (CODCERTIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CFGACTIONS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CFGACTIONS</REFTABLE>
  <HASHVAL>45E01B9CA9D03DC2E967142E600DE4CF53D0CEC5</HASHVAL>
  <TEXT>ALTER TABLE CFGACTIONS ADD CONSTRAINT PK_CFGACTIONS PRIMARY KEY (CODCFGACTIONS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTAVANS</REFTABLE>
  <HASHVAL>248FAC50C9D7CD58C26032F3315D32235B077423</HASHVAL>
  <TEXT>ALTER TABLE CHELTAVANS ADD CONSTRAINT PK_CHELTAVANS PRIMARY KEY (CODCHELTAVANS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CHELTAVANS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTAVANS1</REFTABLE>
  <HASHVAL>89FBD90E0CD8FCF9B690582181E6BAE46CB38F8B</HASHVAL>
  <TEXT>ALTER TABLE CHELTAVANS1 ADD CONSTRAINT PK_CHELTAVANS1 PRIMARY KEY (CODCHELTAVANS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CHELTOPER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTOPER</REFTABLE>
  <HASHVAL>FCB4CBC583A01725C866771954CD6AA5B8C7CE85</HASHVAL>
  <TEXT>ALTER TABLE CHELTOPER ADD CONSTRAINT PK_CHELTOPER PRIMARY KEY (CODCHELTOPER) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CHELTOPER1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTOPER1</REFTABLE>
  <HASHVAL>444A991C09C3EEDDD39AD4014D0A39027EABEE2D</HASHVAL>
  <TEXT>ALTER TABLE CHELTOPER1 ADD CONSTRAINT PK_CHELTOPER1 PRIMARY KEY (CODCHELTOPER1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDLINK</REFTABLE>
  <HASHVAL>05D2B6C5705A74AF31592C49E62637CCEAD3A6A1</HASHVAL>
  <TEXT>ALTER TABLE CMDLINK ADD CONSTRAINT PK_CMDLINK PRIMARY KEY (CODCOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDLIVRLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDLIVRLINK</REFTABLE>
  <HASHVAL>98A187ADB11B8A194A858E883603FC23D17F94E0</HASHVAL>
  <TEXT>ALTER TABLE CMDLIVRLINK ADD CONSTRAINT PK_CMDLIVRLINK PRIMARY KEY (CODCOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODMAN</REFTABLE>
  <HASHVAL>69FA3FD6BA8DCE9599A7E233A3F0B1DBA000F3D5</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODMAN ADD CONSTRAINT PK_CMDPRODMAN PRIMARY KEY (CODCMDPRODMAN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODMAT</REFTABLE>
  <HASHVAL>7669A410279399723D78FD5BF5FE68FA53778E7D</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODMAT ADD CONSTRAINT PK_CMDPRODMAT PRIMARY KEY (CODCMDPRODMAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDPRODREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODREZ</REFTABLE>
  <HASHVAL>4613EA004A172C53F02EB136839EBC4E50C9BB32</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODREZ ADD CONSTRAINT PK_CMDPRODREZ PRIMARY KEY (CODCMDPRODREZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CMDPROIECTREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPROIECTREZ</REFTABLE>
  <HASHVAL>B6D452BC38968937629A1A15979268E871B23C54</HASHVAL>
  <TEXT>ALTER TABLE CMDPROIECTREZ ADD CONSTRAINT PK_CMDPROIECTREZ PRIMARY KEY (CODCMDPROIECTREZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CODDETALIU</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DETALIIET</REFTABLE>
  <HASHVAL>66781BB764DE7A4931D2FCCABEABF86CB32313ED</HASHVAL>
  <TEXT>ALTER TABLE DETALIIET ADD CONSTRAINT PK_CODDETALIU PRIMARY KEY (CODDETALIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CODDETALIUET1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DETALIIET1</REFTABLE>
  <HASHVAL>9745A8813513F07E10101FB24B3944BF71317F4C</HASHVAL>
  <TEXT>ALTER TABLE DETALIIET1 ADD CONSTRAINT PK_CODDETALIUET1 PRIMARY KEY (CODDETALIUET1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA</REFTABLE>
  <HASHVAL>E8131BF2567A9CFF3BEBC5C28071974303063F4F</HASHVAL>
  <TEXT>ALTER TABLE COMANDA ADD CONSTRAINT PK_COMANDA PRIMARY KEY (CODCOMANDA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA1</REFTABLE>
  <HASHVAL>9E26F85C2E5E81219CDDFEA4127979D758ACF165</HASHVAL>
  <TEXT>ALTER TABLE COMANDA1 ADD CONSTRAINT PK_COMANDA1 PRIMARY KEY (CODCOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA1ET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA1ET</REFTABLE>
  <HASHVAL>14899F17A8C104630D2EA288C69E4C7002DEABFB</HASHVAL>
  <TEXT>ALTER TABLE COMANDA1ET ADD CONSTRAINT PK_COMANDA1ET PRIMARY KEY (CODCOMANDA1ET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA2</REFTABLE>
  <HASHVAL>A016C78370BAC13F687FEC59409C5450C19AE12E</HASHVAL>
  <TEXT>ALTER TABLE COMANDA2 ADD CONSTRAINT PK_COMANDA2 PRIMARY KEY (CODCOMANDA2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA3</REFTABLE>
  <HASHVAL>FEEED6E273E58AB3F8375B1E52F0D711E2610E80</HASHVAL>
  <TEXT>ALTER TABLE COMANDA3 ADD CONSTRAINT PK_COMANDA3 PRIMARY KEY (CODCOMANDA3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMANDA4</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA4</REFTABLE>
  <HASHVAL>5D26D4C1DF3DEC1D3737187393A772FCA52A7EC7</HASHVAL>
  <TEXT>ALTER TABLE COMANDA4 ADD CONSTRAINT PK_COMANDA4 PRIMARY KEY (CODCOMANDA4) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_COMPENS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMPENS</REFTABLE>
  <HASHVAL>0655656966D345A06228F3E037E3DF06EEF526B3</HASHVAL>
  <TEXT>ALTER TABLE COMPENS ADD CONSTRAINT PK_COMPENS PRIMARY KEY (CODCOMPENS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONCURENTI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONCURENTI</REFTABLE>
  <HASHVAL>673EFF326C090B3A913B8DE6459658559B241212</HASHVAL>
  <TEXT>ALTER TABLE CONCURENTI ADD CONSTRAINT PK_CONCURENTI PRIMARY KEY (CODCONCURENT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONDCOR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONDCOR1</REFTABLE>
  <HASHVAL>D3E639B1DC63DC745C5B04759623BFBFFEA92923</HASHVAL>
  <TEXT>ALTER TABLE CONDCOR1 ADD CONSTRAINT PK_CONDCOR1 PRIMARY KEY (CODCONDCOR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONST1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONST1</REFTABLE>
  <HASHVAL>2485B122B30EF3F449DBCEDB2E01C73C018E7860</HASHVAL>
  <TEXT>ALTER TABLE CONST1 ADD CONSTRAINT PK_CONST1 PRIMARY KEY (CODCONST1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTLUNA</REFTABLE>
  <HASHVAL>77A65B6FBC379B3B2F446E7B847C3DA9F5CC46AF</HASHVAL>
  <TEXT>ALTER TABLE CONSTLUNA ADD CONSTRAINT PK_CONSTLUNA PRIMARY KEY (CODCONSTLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONSTMAKETA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTMAKETA</REFTABLE>
  <HASHVAL>138D1B1B29C16B032C1D7C7172D5268EC5EFF2C7</HASHVAL>
  <TEXT>ALTER TABLE CONSTMAKETA ADD CONSTRAINT PK_CONSTMAKETA PRIMARY KEY (CODCONSTMAKETA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONSTUSERCHECK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTUSERCHECK</REFTABLE>
  <HASHVAL>74248F616253A213CABA1AA4D7D18E4A50C5E688</HASHVAL>
  <TEXT>ALTER TABLE CONSTUSERCHECK ADD CONSTRAINT PK_CONSTUSERCHECK PRIMARY KEY (USERID) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONSTVALPOS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTVALPOS</REFTABLE>
  <HASHVAL>67F5189D9AAFC3A322D41DC665B3EE4B52AB4930</HASHVAL>
  <TEXT>ALTER TABLE CONSTVALPOS ADD CONSTRAINT PK_CONSTVALPOS PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT</REFTABLE>
  <HASHVAL>4FB9D43A4F36E690543A81C31337008778EC992D</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT ADD CONSTRAINT PK_CONTRACT PRIMARY KEY (CODCONTRACT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACT0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT0</REFTABLE>
  <HASHVAL>91AA9B23EEADAE1094787DBB4E460D8669FAE69E</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT0 ADD CONSTRAINT PK_CONTRACT0 PRIMARY KEY (CODCONTRACT0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT1</REFTABLE>
  <HASHVAL>14CE1B4C5F3FCE65A21AD95B76D0102D3CA43AC5</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT1 ADD CONSTRAINT PK_CONTRACT1 PRIMARY KEY (CODCONTRACT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT2</REFTABLE>
  <HASHVAL>0C9D733A7178597B20C57908079728452DB4ADC2</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT2 ADD CONSTRAINT PK_CONTRACT2 PRIMARY KEY (CODCONTRACT2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTC</REFTABLE>
  <HASHVAL>207EEC7D4832A99AA0F5E371AFC92012F5776E22</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTC ADD CONSTRAINT PK_CONTRACTC PRIMARY KEY (CODCONTRACTC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTC0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTC0</REFTABLE>
  <HASHVAL>03D7A9A0AE97FEB13B18522198766E4E60EE417A</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTC0 ADD CONSTRAINT PK_CONTRACTC0 PRIMARY KEY (CODCONTRACTC0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTT</REFTABLE>
  <HASHVAL>8D95E826D5229697F4FBDFEFC3503E98A3AAB0F4</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTT ADD CONSTRAINT PK_CONTRACTT PRIMARY KEY (CODCONTRACTT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTV</REFTABLE>
  <HASHVAL>A507CF82120DAC39B8AAE8F8E1DDC45BB6C318AE</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTV ADD CONSTRAINT PK_CONTRACTV PRIMARY KEY (CODCONTRACTV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTX</REFTABLE>
  <HASHVAL>839DD04C36934BF25452636FE717E8D9E0636218</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTX ADD CONSTRAINT PK_CONTRACTX PRIMARY KEY (CODCONTRACTX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CONTRACTXX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACTXX</REFTABLE>
  <HASHVAL>47C78A0103470A6445DD0ACB1616A6A6EC44F697</HASHVAL>
  <TEXT>ALTER TABLE CONTRACTXX ADD CONSTRAINT PK_CONTRACTXX PRIMARY KEY (CODCONTRACTXX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CORELAT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CORELAT1</REFTABLE>
  <HASHVAL>6B0C55CDD3AB19662D984D0EDFD5699AAAB8FE32</HASHVAL>
  <TEXT>ALTER TABLE CORELAT1 ADD CONSTRAINT PK_CORELAT1 PRIMARY KEY (CODCORELAT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CORELAT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CORELAT2</REFTABLE>
  <HASHVAL>5FBC9C9F60B7077C201963D61028626192861FEF</HASHVAL>
  <TEXT>ALTER TABLE CORELAT2 ADD CONSTRAINT PK_CORELAT2 PRIMARY KEY (CODCORELAT2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CRITERIIDISC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CRITERIIDISC</REFTABLE>
  <HASHVAL>651C836C15E034162E33DC80907B9C1B26175DC5</HASHVAL>
  <TEXT>ALTER TABLE CRITERIIDISC ADD CONSTRAINT PK_CRITERIIDISC PRIMARY KEY (CODCRITERIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CURSURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CURSURI</REFTABLE>
  <HASHVAL>E49D93455498738EBCF99F366ECA0071FCC00C5A</HASHVAL>
  <TEXT>ALTER TABLE CURSURI ADD CONSTRAINT PK_CURSURI PRIMARY KEY (CODCURS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CURSURI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CURSURI1</REFTABLE>
  <HASHVAL>9858D2CCA1A54D998FB0714E5C4658FC973DE697</HASHVAL>
  <TEXT>ALTER TABLE CURSURI1 ADD CONSTRAINT PK_CURSURI1 PRIMARY KEY (CODCURS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_CUSTODIEINI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CUSTODIEINI</REFTABLE>
  <HASHVAL>CFEF57846B526939064E7C8348F25AAE08D68046</HASHVAL>
  <TEXT>ALTER TABLE CUSTODIEINI ADD CONSTRAINT PK_CUSTODIEINI PRIMARY KEY (CODCUSTODIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D390</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390</REFTABLE>
  <HASHVAL>0F7988BC176F31F4C012B141CAF8FF96D4CBAEAF</HASHVAL>
  <TEXT>ALTER TABLE D390 ADD CONSTRAINT PK_D390 PRIMARY KEY (CODD390) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D390D</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390D</REFTABLE>
  <HASHVAL>2DFDD82C700273954A5DBD2E793172A90F214F64</HASHVAL>
  <TEXT>ALTER TABLE D390D ADD CONSTRAINT PK_D390D PRIMARY KEY (CODD390D) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D390O</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390O</REFTABLE>
  <HASHVAL>6B27B2EF06631AD1A215803555BDA04CDFB7B991</HASHVAL>
  <TEXT>ALTER TABLE D390O ADD CONSTRAINT PK_D390O PRIMARY KEY (CODD390O) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394</REFTABLE>
  <HASHVAL>40708E14E74F7F3102A68531F7E63AC89A052BBB</HASHVAL>
  <TEXT>ALTER TABLE D394 ADD CONSTRAINT PK_D394 PRIMARY KEY (CODD394) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416</REFTABLE>
  <HASHVAL>2AFCD32C8BE2E0538D22D3FBBCE9D3E110F0A6AD</HASHVAL>
  <TEXT>ALTER TABLE D39416 ADD CONSTRAINT PK_D39416 PRIMARY KEY (CODD39416) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416G</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G</REFTABLE>
  <HASHVAL>AE7E798BD58504AD704FE102283E6C090A80621F</HASHVAL>
  <TEXT>ALTER TABLE D39416G ADD CONSTRAINT PK_D39416G PRIMARY KEY (CODD39416G) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416G1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G1</REFTABLE>
  <HASHVAL>B248E96EF57258778E193D220D170F0E70461AAE</HASHVAL>
  <TEXT>ALTER TABLE D39416G1 ADD CONSTRAINT PK_D39416G1 PRIMARY KEY (CODD39416G1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416G2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G2</REFTABLE>
  <HASHVAL>581E94570F22E443339CAD31EAD8D313B339D7A6</HASHVAL>
  <TEXT>ALTER TABLE D39416G2 ADD CONSTRAINT PK_D39416G2 PRIMARY KEY (CODD39416G2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416G3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G3</REFTABLE>
  <HASHVAL>A38947E9AD15B2528A89728BD15116832FE9BF1D</HASHVAL>
  <TEXT>ALTER TABLE D39416G3 ADD CONSTRAINT PK_D39416G3 PRIMARY KEY (CODD39416G3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I</REFTABLE>
  <HASHVAL>6D86DBA06299A8450C627665CA1C74C73181F7DA</HASHVAL>
  <TEXT>ALTER TABLE D39416I ADD CONSTRAINT PK_D39416I PRIMARY KEY (CODD39416I) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I1</REFTABLE>
  <HASHVAL>0468599688DAA85A376A19E4F5B874866568F704</HASHVAL>
  <TEXT>ALTER TABLE D39416I1 ADD CONSTRAINT PK_D39416I1 PRIMARY KEY (CODD39416I1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I2</REFTABLE>
  <HASHVAL>28A1585AF80FEF0F88E08652A84E7E12C149B6A8</HASHVAL>
  <TEXT>ALTER TABLE D39416I2 ADD CONSTRAINT PK_D39416I2 PRIMARY KEY (CODD39416I2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I2A</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I2A</REFTABLE>
  <HASHVAL>6DB4A1ADB83BB53082DAAFC452F0B23B1D557489</HASHVAL>
  <TEXT>ALTER TABLE D39416I2A ADD CONSTRAINT PK_D39416I2A PRIMARY KEY (CODD39416I2A) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I3</REFTABLE>
  <HASHVAL>213BD45E6E21990466AFB9526DAFB83371C4561B</HASHVAL>
  <TEXT>ALTER TABLE D39416I3 ADD CONSTRAINT PK_D39416I3 PRIMARY KEY (CODD39416I3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416I4</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I4</REFTABLE>
  <HASHVAL>9450CAB81188554E6F56DC5AA4EE8697956B5350</HASHVAL>
  <TEXT>ALTER TABLE D39416I4 ADD CONSTRAINT PK_D39416I4 PRIMARY KEY (CODD39416I4) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416N</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416N</REFTABLE>
  <HASHVAL>28FDF2B944DD7FEA67A4B3B7DA2DCC490CB26861</HASHVAL>
  <TEXT>ALTER TABLE D39416N ADD CONSTRAINT PK_D39416N PRIMARY KEY (CODD39416N) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416NS2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416NS2</REFTABLE>
  <HASHVAL>DECB9DA543EEFD96DFE16824395400D4E79A4905</HASHVAL>
  <TEXT>ALTER TABLE D39416NS2 ADD CONSTRAINT PK_D39416NS2 PRIMARY KEY (CODD39416NS2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416R</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416R</REFTABLE>
  <HASHVAL>49BF16B8E6C7069EF7899A0A6F4CE980A56D1203</HASHVAL>
  <TEXT>ALTER TABLE D39416R ADD CONSTRAINT PK_D39416R PRIMARY KEY (CODD39416R) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN</REFTABLE>
  <HASHVAL>AAEF36DDD81620AAFBF0AADC6015AA199D4AF1C6</HASHVAL>
  <TEXT>ALTER TABLE D39416RN ADD CONSTRAINT PK_D39416RN PRIMARY KEY (CODD39416RN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RN0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN0</REFTABLE>
  <HASHVAL>A3DEC66A27A6F0C86CFC34B502E0F5E573F62E9B</HASHVAL>
  <TEXT>ALTER TABLE D39416RN0 ADD CONSTRAINT PK_D39416RN0 PRIMARY KEY (CODD39416RN0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RN1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN1</REFTABLE>
  <HASHVAL>761F22EC885028C6D52AD0CE102F57D9BA2B68C8</HASHVAL>
  <TEXT>ALTER TABLE D39416RN1 ADD CONSTRAINT PK_D39416RN1 PRIMARY KEY (CODD39416RN1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RNS2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RNS2</REFTABLE>
  <HASHVAL>E7D08F9750E5390F719389EE59F2AA89648811D7</HASHVAL>
  <TEXT>ALTER TABLE D39416RNS2 ADD CONSTRAINT PK_D39416RNS2 PRIMARY KEY (CODD39416RNS2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RNS3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RNS3</REFTABLE>
  <HASHVAL>1E984212DAB0D761ECFB26AC3308D83463D77680</HASHVAL>
  <TEXT>ALTER TABLE D39416RNS3 ADD CONSTRAINT PK_D39416RNS3 PRIMARY KEY (CODD39416RNS3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RP</REFTABLE>
  <HASHVAL>B5330F49046D1C003E5B328635A5E7228AE0CD99</HASHVAL>
  <TEXT>ALTER TABLE D39416RP ADD CONSTRAINT PK_D39416RP PRIMARY KEY (CODD39416RP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RP1</REFTABLE>
  <HASHVAL>96F5B2AA5EFEA7416C9D18AA7B05A4DCEC98EA3C</HASHVAL>
  <TEXT>ALTER TABLE D39416RP1 ADD CONSTRAINT PK_D39416RP1 PRIMARY KEY (CODD39416RP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RPS2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RPS2</REFTABLE>
  <HASHVAL>FF4AB993B31C2B72DA5AFC001255EC9B21CC7772</HASHVAL>
  <TEXT>ALTER TABLE D39416RPS2 ADD CONSTRAINT PK_D39416RPS2 PRIMARY KEY (CODD39416RPS2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416RPS3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RPS3</REFTABLE>
  <HASHVAL>8D88274266A2FB4211193D83E61660F52A834B7F</HASHVAL>
  <TEXT>ALTER TABLE D39416RPS3 ADD CONSTRAINT PK_D39416RPS3 PRIMARY KEY (CODD39416RPS3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416UE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416UE</REFTABLE>
  <HASHVAL>EC21E7962293E50938ECEB038FD4779A20224785</HASHVAL>
  <TEXT>ALTER TABLE D39416UE ADD CONSTRAINT PK_D39416UE PRIMARY KEY (CODD39416UE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416UES2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416UES2</REFTABLE>
  <HASHVAL>3545086CFDCE5C2349618F77945441426CE82496</HASHVAL>
  <TEXT>ALTER TABLE D39416UES2 ADD CONSTRAINT PK_D39416UES2 PRIMARY KEY (CODD39416UES2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D39416_ANAF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416_ANAF</REFTABLE>
  <HASHVAL>E8CA0803B10826212152C075313B906E85B1AE98</HASHVAL>
  <TEXT>ALTER TABLE D39416_ANAF ADD CONSTRAINT PK_D39416_ANAF PRIMARY KEY (CUI,DATA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394A</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394A</REFTABLE>
  <HASHVAL>F88A67632819C2A03945C96E561DE4CAAC11393C</HASHVAL>
  <TEXT>ALTER TABLE D394A ADD CONSTRAINT PK_D394A PRIMARY KEY (CODD394A) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394C</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394C</REFTABLE>
  <HASHVAL>C3AA3A409BF2756276747FC5147EED216CFE2A35</HASHVAL>
  <TEXT>ALTER TABLE D394C ADD CONSTRAINT PK_D394C PRIMARY KEY (CODD394C) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394CC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394CC</REFTABLE>
  <HASHVAL>9212CF04E972A68B08180E73A0EFF2B11AC1244B</HASHVAL>
  <TEXT>ALTER TABLE D394CC ADD CONSTRAINT PK_D394CC PRIMARY KEY (CODD394CC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394L</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394L</REFTABLE>
  <HASHVAL>84226DB816A956340A3F404810D2ACB0DE91E8A1</HASHVAL>
  <TEXT>ALTER TABLE D394L ADD CONSTRAINT PK_D394L PRIMARY KEY (CODD394L) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394V</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394V</REFTABLE>
  <HASHVAL>AF35E8C7F5CC156B1B657648E20652CB531E88B4</HASHVAL>
  <TEXT>ALTER TABLE D394V ADD CONSTRAINT PK_D394V PRIMARY KEY (CODD394V) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_D394VC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394VC</REFTABLE>
  <HASHVAL>4218C4C798078ACC683CB33DCD69736720C95621</HASHVAL>
  <TEXT>ALTER TABLE D394VC ADD CONSTRAINT PK_D394VC PRIMARY KEY (CODD394VC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DESCRIPTORI</REFTABLE>
  <HASHVAL>03C59DECA017D812E3921FA58616BED974B9CDD2</HASHVAL>
  <TEXT>ALTER TABLE DESCRIPTORI ADD CONSTRAINT PK_DESCRIPTORI PRIMARY KEY (CODDESCRIPTOR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DESCRIPTORI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DESCRIPTORI1</REFTABLE>
  <HASHVAL>E95E365B4BA484DCCE5E1B78A96D8D129EC1BBBB</HASHVAL>
  <TEXT>ALTER TABLE DESCRIPTORI1 ADD CONSTRAINT PK_DESCRIPTORI1 PRIMARY KEY (CODDESCRIPTOR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DETAILMAK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DETAILMAK</REFTABLE>
  <HASHVAL>1088AB92E81E27773541367CCA3CB50BFDA5FF7C</HASHVAL>
  <TEXT>ALTER TABLE DETAILMAK ADD CONSTRAINT PK_DETAILMAK PRIMARY KEY (CODDETAILMAK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DEZASAMBLARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DEZASAMBLARI</REFTABLE>
  <HASHVAL>5D41F41CAFF67D4A10BD3F919FE49085C289EE28</HASHVAL>
  <TEXT>ALTER TABLE DEZASAMBLARI ADD CONSTRAINT PK_DEZASAMBLARI PRIMARY KEY (CODLIVR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DEZASAMBLARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DEZASAMBLARI1</REFTABLE>
  <HASHVAL>4E52242D88CED516CA6AB2AB0F7338A47E19ACBC</HASHVAL>
  <TEXT>ALTER TABLE DEZASAMBLARI1 ADD CONSTRAINT PK_DEZASAMBLARI1 PRIMARY KEY (CODINTRLINK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DIFICULTATI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DIFICULTATI</REFTABLE>
  <HASHVAL>3BE47EDB0AA78D2F62580AC97D7CEE6601137AF3</HASHVAL>
  <TEXT>ALTER TABLE DIFICULTATI ADD CONSTRAINT PK_DIFICULTATI PRIMARY KEY (CODDIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DIFPRETPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DIFPRETPROD</REFTABLE>
  <HASHVAL>8E9C0167308A9E5D88E0BD58ADB49AB89A4522C8</HASHVAL>
  <TEXT>ALTER TABLE DIFPRETPROD ADD CONSTRAINT PK_DIFPRETPROD PRIMARY KEY (CODDIFPRETPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DIFPRETPROD1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DIFPRETPROD1</REFTABLE>
  <HASHVAL>479E167A79D728D82D377B09A8A9B3414C8F9D27</HASHVAL>
  <TEXT>ALTER TABLE DIFPRETPROD1 ADD CONSTRAINT PK_DIFPRETPROD1 PRIMARY KEY (CODDIFPRETPROD1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DINTRASTAT</REFTABLE>
  <HASHVAL>86E490DD6B335C9BC3E8DBACD9A7B33985E7CA92</HASHVAL>
  <TEXT>ALTER TABLE DINTRASTAT ADD CONSTRAINT PK_DINTRASTAT PRIMARY KEY (CODDINTRASTAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DINTRASTATA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DINTRASTATA</REFTABLE>
  <HASHVAL>E2D48E14E1C6C53F5D9DEA05F02F1A948A4C001B</HASHVAL>
  <TEXT>ALTER TABLE DINTRASTATA ADD CONSTRAINT PK_DINTRASTATA PRIMARY KEY (CODDINTRASTATA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DINTRASTATD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DINTRASTATD</REFTABLE>
  <HASHVAL>3AA44BAA6DC1551610487952FD628D0737B5A7A6</HASHVAL>
  <TEXT>ALTER TABLE DINTRASTATD ADD CONSTRAINT PK_DINTRASTATD PRIMARY KEY (CODDINTRASTATD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DIRTYJURNAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DIRTYJURNAL</REFTABLE>
  <HASHVAL>8E666514597172ED76CFF8F04BA68136D9713ECB</HASHVAL>
  <TEXT>ALTER TABLE DIRTYJURNAL ADD CONSTRAINT PK_DIRTYJURNAL PRIMARY KEY (ANLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISCART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCART</REFTABLE>
  <HASHVAL>A5FC531F64C93BB2C35C8831A41D12A187A2879F</HASHVAL>
  <TEXT>ALTER TABLE DISCART ADD CONSTRAINT PK_DISCART PRIMARY KEY (CODDISCART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISCINTERVAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCINTERVAL</REFTABLE>
  <HASHVAL>D95107B0411C4C8B40EF1A44E65C87A99217DC50</HASHVAL>
  <TEXT>ALTER TABLE DISCINTERVAL ADD CONSTRAINT PK_DISCINTERVAL PRIMARY KEY (CODDISCINTERVAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISCOUNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCOUNT</REFTABLE>
  <HASHVAL>7BC8BD15621DC10BE36F149D74C71EF169D1DFF2</HASHVAL>
  <TEXT>ALTER TABLE DISCOUNT ADD CONSTRAINT PK_DISCOUNT PRIMARY KEY (CODDISCOUNT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTANTA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTANTA</REFTABLE>
  <HASHVAL>97A4405931B60C542D3D451B34DE07E638310A40</HASHVAL>
  <TEXT>ALTER TABLE DISTANTA ADD CONSTRAINT PK_DISTANTA PRIMARY KEY (CODDISTANTA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIB</REFTABLE>
  <HASHVAL>65A06913BA7B642D8B594817B22F8D90D6B0045E</HASHVAL>
  <TEXT>ALTER TABLE DISTRIB ADD CONSTRAINT PK_DISTRIB PRIMARY KEY (CODDISTRIB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIB1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIB1</REFTABLE>
  <HASHVAL>B120A81B4532B80521B1FD5E6AB71CD7C38F30A3</HASHVAL>
  <TEXT>ALTER TABLE DISTRIB1 ADD CONSTRAINT PK_DISTRIB1 PRIMARY KEY (CODDISTRIB1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIB2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIB2</REFTABLE>
  <HASHVAL>734566D908F3D88D2D9DE8E687604CDAAE31D0D7</HASHVAL>
  <TEXT>ALTER TABLE DISTRIB2 ADD CONSTRAINT PK_DISTRIB2 PRIMARY KEY (CODDISTRIB2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIB3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIB3</REFTABLE>
  <HASHVAL>47061DF93F57C47C34797BA7F0F315F9A7757A2B</HASHVAL>
  <TEXT>ALTER TABLE DISTRIB3 ADD CONSTRAINT PK_DISTRIB3 PRIMARY KEY (CODDISTRIB3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIBCHELT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT</REFTABLE>
  <HASHVAL>102E7370DBCC2FFCD06FDFA32591A32DFB390D2E</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT ADD CONSTRAINT PK_DISTRIBCHELT PRIMARY KEY (CODDISTRIBCHELT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIBCHELT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT1</REFTABLE>
  <HASHVAL>ACA20F51EA92A455D68C68D2461F97A1A794017F</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT1 ADD CONSTRAINT PK_DISTRIBCHELT1 PRIMARY KEY (CODDISTRIBCHELT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISTRIBCHELT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT2</REFTABLE>
  <HASHVAL>D3253F4BF09EEFF632F21B7DEB10A64BFB8D248F</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT2 ADD CONSTRAINT PK_DISTRIBCHELT2 PRIMARY KEY (CODDISTRIBCHELT2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCCARNETE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCCARNETE</REFTABLE>
  <HASHVAL>D6A280309FD3EB791C7E9875D4FF3797F10AC861</HASHVAL>
  <TEXT>ALTER TABLE DOCCARNETE ADD CONSTRAINT PK_DOCCARNETE PRIMARY KEY (CODCARNET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCEXTRA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCEXTRA</REFTABLE>
  <HASHVAL>596D84AE05F8D778D2C469311DB7B4D6625522C6</HASHVAL>
  <TEXT>ALTER TABLE DOCEXTRA ADD CONSTRAINT PK_DOCEXTRA PRIMARY KEY (TIPDOC,CODDOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCFREE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCFREE</REFTABLE>
  <HASHVAL>6028FDF27DCB2643D033644634B1B7C45E785153</HASHVAL>
  <TEXT>ALTER TABLE DOCFREE ADD CONSTRAINT PK_DOCFREE PRIMARY KEY (CODDOCFREE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCFREEX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCFREEX</REFTABLE>
  <HASHVAL>729FBC410CC8678798D97152C6B3351AC14EB203</HASHVAL>
  <TEXT>ALTER TABLE DOCFREEX ADD CONSTRAINT PK_DOCFREEX PRIMARY KEY (STARTNR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCLINK</REFTABLE>
  <HASHVAL>90A933F7D415BE7190A7339F14B6466A2776FAF2</HASHVAL>
  <TEXT>ALTER TABLE DOCLINK ADD CONSTRAINT PK_DOCLINK PRIMARY KEY (CODDOCLINK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCLOCK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCLOCK</REFTABLE>
  <HASHVAL>91873F4DF33401B0412326322444A10AFFFE21CD</HASHVAL>
  <TEXT>ALTER TABLE DOCLOCK ADD CONSTRAINT PK_DOCLOCK PRIMARY KEY (CODDOCLOCK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCSUPLIM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCSUPLIM</REFTABLE>
  <HASHVAL>0096CB02D7FB255424C1537B029DCF3635E1C44F</HASHVAL>
  <TEXT>ALTER TABLE DOCSUPLIM ADD CONSTRAINT PK_DOCSUPLIM PRIMARY KEY (CODDOCSUPLIM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCSUPLIM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCSUPLIM1</REFTABLE>
  <HASHVAL>A217BCF5F181FF2D6F7E4A5287EA58B5EFCFBE64</HASHVAL>
  <TEXT>ALTER TABLE DOCSUPLIM1 ADD CONSTRAINT PK_DOCSUPLIM1 PRIMARY KEY (CODDOCSUPLIM1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCUMENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCUMENTE</REFTABLE>
  <HASHVAL>4D2D70F6EB7D4C865A2968E468D465CF1731D21C</HASHVAL>
  <TEXT>ALTER TABLE DOCUMENTE ADD CONSTRAINT PK_DOCUMENTE PRIMARY KEY (CODDOCUMENT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCUSERS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCUSERS</REFTABLE>
  <HASHVAL>27FF878CCF31B27527DAF8C5A4F9833556CC49C0</HASHVAL>
  <TEXT>ALTER TABLE DOCUSERS ADD CONSTRAINT PK_DOCUSERS PRIMARY KEY (CODDOCUSERS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOMENIIACT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOMENIIACT</REFTABLE>
  <HASHVAL>B6AB4D19C732515F4CB99613773522FA14A2EE52</HASHVAL>
  <TEXT>ALTER TABLE DOMENIIACT ADD CONSTRAINT PK_DOMENIIACT PRIMARY KEY (CODDOMENIUACT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOSARE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOSARE</REFTABLE>
  <HASHVAL>A95680A04766F197CBB3F71B3BD316AF1CE17A14</HASHVAL>
  <TEXT>ALTER TABLE DOSARE ADD CONSTRAINT PK_DOSARE PRIMARY KEY (CODDOSAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DPROFIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DPROFIT</REFTABLE>
  <HASHVAL>AC1B5A97A5F38B02967654593158E28EED71FB7D</HASHVAL>
  <TEXT>ALTER TABLE DPROFIT ADD CONSTRAINT PK_DPROFIT PRIMARY KEY (CODDPROFIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DPROFITC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DPROFITC</REFTABLE>
  <HASHVAL>479FE22908B9D4453091A0AABE73FDE903E5D4EE</HASHVAL>
  <TEXT>ALTER TABLE DPROFITC ADD CONSTRAINT PK_DPROFITC PRIMARY KEY (CODDPROFITC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DPROFITV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DPROFITV</REFTABLE>
  <HASHVAL>53DBDFCDD126CFA541E4407CE8EB0F6D01B2C3D8</HASHVAL>
  <TEXT>ALTER TABLE DPROFITV ADD CONSTRAINT PK_DPROFITV PRIMARY KEY (CODDPROFITV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DVI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI</REFTABLE>
  <HASHVAL>59E651DAD3FB741CDA5B3643DB36700424AA93C2</HASHVAL>
  <TEXT>ALTER TABLE DVI ADD CONSTRAINT PK_DVI PRIMARY KEY (CODDVI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DVI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI1</REFTABLE>
  <HASHVAL>24F5FFDDC175FFBB6D3DEE484C8FCED715534620</HASHVAL>
  <TEXT>ALTER TABLE DVI1 ADD CONSTRAINT PK_DVI1 PRIMARY KEY (CODDVI1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EFACTURA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EFACTURA</REFTABLE>
  <HASHVAL>9278331D9A00A2DCF9071A48AB915AEA40BB6998</HASHVAL>
  <TEXT>ALTER TABLE EFACTURA ADD CONSTRAINT PK_EFACTURA PRIMARY KEY (CODIES) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EFCUSTOM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EFCUSTOM</REFTABLE>
  <HASHVAL>F04474858711B6D1135B76BB26BD86143107DEA9</HASHVAL>
  <TEXT>ALTER TABLE EFCUSTOM ADD CONSTRAINT PK_EFCUSTOM PRIMARY KEY (CODEFCUSTOM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMBUGET</REFTABLE>
  <HASHVAL>E04A5909AE5FBC4AC424F1E4EC6D6A59DF48CDFE</HASHVAL>
  <TEXT>ALTER TABLE ELEMBUGET ADD CONSTRAINT PK_ELEMBUGET PRIMARY KEY (CODELEMBUGET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMBUGET1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMBUGET1</REFTABLE>
  <HASHVAL>AFCF53A82B0D7A43754343BAF4BF3E2254B42035</HASHVAL>
  <TEXT>ALTER TABLE ELEMBUGET1 ADD CONSTRAINT PK_ELEMBUGET1 PRIMARY KEY (CODELEMBUGET1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMBUGET2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMBUGET2</REFTABLE>
  <HASHVAL>8A5BAC1D6258B26B6309586B40F28DBFCC4F0ED8</HASHVAL>
  <TEXT>ALTER TABLE ELEMBUGET2 ADD CONSTRAINT PK_ELEMBUGET2 PRIMARY KEY (CODELEMBUGET2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTE</REFTABLE>
  <HASHVAL>7312E2340EC33CFF1C79DC8FB6557DD949B47847</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTE ADD CONSTRAINT PK_ELEMENTE PRIMARY KEY (CODELEMENT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMENTEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEA</REFTABLE>
  <HASHVAL>D7A08BD8C1EFCE7E1CF3761DC48545121CBAB9FE</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEA ADD CONSTRAINT PK_ELEMENTEA PRIMARY KEY (CODELEMENTA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMENTEC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEC</REFTABLE>
  <HASHVAL>8B9D24B89D3FBDC26956C6CFAF93848DA875C835</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEC ADD CONSTRAINT PK_ELEMENTEC PRIMARY KEY (CODELEMENTC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ELEMENTEM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEM</REFTABLE>
  <HASHVAL>E1A3DD47A29D422552DC762B429CC77781FC0294</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEM ADD CONSTRAINT PK_ELEMENTEM PRIMARY KEY (CODELEMENTM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EMULARE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EMULARE</REFTABLE>
  <HASHVAL>BE71F48CF1A9A93E0C39E0DD7928BF2E8DCF85BA</HASHVAL>
  <TEXT>ALTER TABLE EMULARE ADD CONSTRAINT PK_EMULARE PRIMARY KEY (CODEMULARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EMULARE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EMULARE1</REFTABLE>
  <HASHVAL>7A403FFF04CF201578684A9CA95782FAFDF5C048</HASHVAL>
  <TEXT>ALTER TABLE EMULARE1 ADD CONSTRAINT PK_EMULARE1 PRIMARY KEY (CODEMULARE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EMULARE2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EMULARE2</REFTABLE>
  <HASHVAL>03C0D76ABAF7E2DE9EE55701B092CC6E7FC732D7</HASHVAL>
  <TEXT>ALTER TABLE EMULARE2 ADD CONSTRAINT PK_EMULARE2 PRIMARY KEY (CODEMULARE2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARINOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARINOD</REFTABLE>
  <HASHVAL>8509AC05D461ED52108EDD5613BB73129303E85D</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARINOD ADD CONSTRAINT PK_ESTIMARINOD PRIMARY KEY (CODESTIMARENOD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARINOD_C1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARINOD_C1</REFTABLE>
  <HASHVAL>5A22CA7492144C08F96769BBE47E62E5A6F9754A</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARINOD_C1 ADD CONSTRAINT PK_ESTIMARINOD_C1 PRIMARY KEY (CODESTIMARENOD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARIPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARIPROD</REFTABLE>
  <HASHVAL>41D7D8594A750B5B7321F1E01F84B45033099F50</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARIPROD ADD CONSTRAINT PK_ESTIMARIPROD PRIMARY KEY (CODESTIMAREPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARIPROD1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARIPROD1</REFTABLE>
  <HASHVAL>9B60F356A4EAEF4FFD74110F7C73034F1B47F251</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARIPROD1 ADD CONSTRAINT PK_ESTIMARIPROD1 PRIMARY KEY (CODESTIMAREPROD1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARIPROD1M</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARIPROD1M</REFTABLE>
  <HASHVAL>BE82422F6AEACF874BD01C4E94F0D1A04FAB6B6B</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARIPROD1M ADD CONSTRAINT PK_ESTIMARIPROD1M PRIMARY KEY (CODESTIMAREPROD1M) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ESTIMARIPROD1N</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARIPROD1N</REFTABLE>
  <HASHVAL>6736996C8408204E453A00FA912839FCDA06808A</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARIPROD1N ADD CONSTRAINT PK_ESTIMARIPROD1N PRIMARY KEY (CODESTIMAREPROD1N) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA</REFTABLE>
  <HASHVAL>84F58BBBA72135B139C7B10E8D69979823FC87B4</HASHVAL>
  <TEXT>ALTER TABLE ETVA ADD CONSTRAINT PK_ETVA PRIMARY KEY (CODETVA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_390_394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_390_394</REFTABLE>
  <HASHVAL>4FD28764D6FB701FBA123B2FE4AE7AA546FC1E7C</HASHVAL>
  <TEXT>ALTER TABLE ETVA_390_394 ADD CONSTRAINT PK_ETVA_390_394 PRIMARY KEY (CODETVA_390_394) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_AMEF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_AMEF</REFTABLE>
  <HASHVAL>B19CE63688CCEAE5A75D77F50B37DF3BAFA8FCAC</HASHVAL>
  <TEXT>ALTER TABLE ETVA_AMEF ADD CONSTRAINT PK_ETVA_AMEF PRIMARY KEY (CODETVA_AMEF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_ETRANSPORT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_ETRANSPORT</REFTABLE>
  <HASHVAL>2D5381CA00C0F4E66EA960AEAF84E2ABE3D90B03</HASHVAL>
  <TEXT>ALTER TABLE ETVA_ETRANSPORT ADD CONSTRAINT PK_ETVA_ETRANSPORT PRIMARY KEY (CODETVA_ETRANSPORT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_FACTURA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_FACTURA</REFTABLE>
  <HASHVAL>E532B26057CB2CDB0077E6FCE9D795556E3059DA</HASHVAL>
  <TEXT>ALTER TABLE ETVA_FACTURA ADD CONSTRAINT PK_ETVA_FACTURA PRIMARY KEY (CODETVA_FACTURA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_FACTURA_TVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_FACTURA_TVA</REFTABLE>
  <HASHVAL>D813E022E748E2B23DC8052C3B54F7F248FEE3F5</HASHVAL>
  <TEXT>ALTER TABLE ETVA_FACTURA_TVA ADD CONSTRAINT PK_ETVA_FACTURA_TVA PRIMARY KEY (CODETVA_FACTURA_TVA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_LOCUINTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_LOCUINTE</REFTABLE>
  <HASHVAL>6EF1A0D4CFAC298003A4ADCBDD190FB070CDAE8B</HASHVAL>
  <TEXT>ALTER TABLE ETVA_LOCUINTE ADD CONSTRAINT PK_ETVA_LOCUINTE PRIMARY KEY (CODETVA_LOCUINTE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_VAMA_EXPORT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_VAMA_EXPORT</REFTABLE>
  <HASHVAL>7A373E6DACE761911393E710A13D2BADCC8BA11C</HASHVAL>
  <TEXT>ALTER TABLE ETVA_VAMA_EXPORT ADD CONSTRAINT PK_ETVA_VAMA_EXPORT PRIMARY KEY (CODETVA_VAMA_EXPORT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ETVA_VAMA_IMPORT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ETVA_VAMA_IMPORT</REFTABLE>
  <HASHVAL>A8B5EC42DFBA6102E335621485F988644488CA98</HASHVAL>
  <TEXT>ALTER TABLE ETVA_VAMA_IMPORT ADD CONSTRAINT PK_ETVA_VAMA_IMPORT PRIMARY KEY (CODETVA_VAMA_IMPORT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EURO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EURO</REFTABLE>
  <HASHVAL>93A7913EA9290D83EFE779B7B2668A83426E8A60</HASHVAL>
  <TEXT>ALTER TABLE EURO ADD CONSTRAINT PK_EURO PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EVIDENTAMF</REFTABLE>
  <HASHVAL>154008CADEBC3F5246D083E262CC210972F8AE3B</HASHVAL>
  <TEXT>ALTER TABLE EVIDENTAMF ADD CONSTRAINT PK_EVIDENTAMF PRIMARY KEY (CODMIFIX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EXPERT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EXPERT</REFTABLE>
  <HASHVAL>CF50C8726962952F6DC764B663DBEBBAA419371A</HASHVAL>
  <TEXT>ALTER TABLE EXPERT ADD CONSTRAINT PK_EXPERT PRIMARY KEY (CODEXPERT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_EXPERT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EXPERT1</REFTABLE>
  <HASHVAL>61C6003CA921F2F7C1B0EF254AC7637F0602CA05</HASHVAL>
  <TEXT>ALTER TABLE EXPERT1 ADD CONSTRAINT PK_EXPERT1 PRIMARY KEY (CODEXPERT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FACTSALINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FACTSALINK</REFTABLE>
  <HASHVAL>D5E3C7B41FE1D84984B8EAD89F5D1E82164801B4</HASHVAL>
  <TEXT>ALTER TABLE FACTSALINK ADD CONSTRAINT PK_FACTSALINK PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZ</REFTABLE>
  <HASHVAL>61A7B3B630E89040E107EDEFDD3190AFC7917A2E</HASHVAL>
  <TEXT>ALTER TABLE FAZ ADD CONSTRAINT PK_FAZ PRIMARY KEY (CODFAZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZ0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZ0</REFTABLE>
  <HASHVAL>2E5E03F53A8C143F9062786EFAFD65DBE65084B3</HASHVAL>
  <TEXT>ALTER TABLE FAZ0 ADD CONSTRAINT PK_FAZ0 PRIMARY KEY (CODFAZ0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZ1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZ1</REFTABLE>
  <HASHVAL>8A6777725ABCBC71AB5E5DF0FCC9EF434655618F</HASHVAL>
  <TEXT>ALTER TABLE FAZ1 ADD CONSTRAINT PK_FAZ1 PRIMARY KEY (CODFAZ1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZ2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZ2</REFTABLE>
  <HASHVAL>4B2E581C1C734DC50D199FE01EFB599B7C55B12D</HASHVAL>
  <TEXT>ALTER TABLE FAZ2 ADD CONSTRAINT PK_FAZ2 PRIMARY KEY (CODFAZ2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZ3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZ3</REFTABLE>
  <HASHVAL>B99ADDA6E8524B583047CE0AEEBDB550E39E333E</HASHVAL>
  <TEXT>ALTER TABLE FAZ3 ADD CONSTRAINT PK_FAZ3 PRIMARY KEY (CODFAZ3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FAZINTR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FAZINTR</REFTABLE>
  <HASHVAL>1944C59EFD95891CD5BB321BD43D7A5478EFA791</HASHVAL>
  <TEXT>ALTER TABLE FAZINTR ADD CONSTRAINT PK_FAZINTR PRIMARY KEY (CODFAZINTR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISAINF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAINF</REFTABLE>
  <HASHVAL>95891C3E64D91963037A0FCE31FDAE8466508F2A</HASHVAL>
  <TEXT>ALTER TABLE FISAINF ADD CONSTRAINT PK_FISAINF PRIMARY KEY (CODFISAINF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISAMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAMAN</REFTABLE>
  <HASHVAL>11E0FAEEFE2987718B13610309924B8548FB2932</HASHVAL>
  <TEXT>ALTER TABLE FISAMAN ADD CONSTRAINT PK_FISAMAN PRIMARY KEY (CODFISAMAN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISAMAND</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAMAND</REFTABLE>
  <HASHVAL>BC1746B26B7379083DD542489F63B8CE97974997</HASHVAL>
  <TEXT>ALTER TABLE FISAMAND ADD CONSTRAINT PK_FISAMAND PRIMARY KEY (CODFISAMAND) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISAMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAMF</REFTABLE>
  <HASHVAL>B9699975618BCF7D7631D4D3380078ED975DC720</HASHVAL>
  <TEXT>ALTER TABLE FISAMF ADD CONSTRAINT PK_FISAMF PRIMARY KEY (CODFISAMF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISAREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAREZ</REFTABLE>
  <HASHVAL>D20EE599DD033FB15FF34F7037CF6620C1C13F77</HASHVAL>
  <TEXT>ALTER TABLE FISAREZ ADD CONSTRAINT PK_FISAREZ PRIMARY KEY (CODFISAREZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISASDV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISASDV</REFTABLE>
  <HASHVAL>644C5A0C24546E011648066960B0658D76EDB227</HASHVAL>
  <TEXT>ALTER TABLE FISASDV ADD CONSTRAINT PK_FISASDV PRIMARY KEY (CODFISASDV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISASUP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISASUP</REFTABLE>
  <HASHVAL>57065A92EBAC95BD2D5A1FCFD1692EC84D96633B</HASHVAL>
  <TEXT>ALTER TABLE FISASUP ADD CONSTRAINT PK_FISASUP PRIMARY KEY (CODFISASUP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FISATEH</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISATEH</REFTABLE>
  <HASHVAL>2C01936F013A5494155FA5FD76AA7D8CC5310F12</HASHVAL>
  <TEXT>ALTER TABLE FISATEH ADD CONSTRAINT PK_FISATEH PRIMARY KEY (CODFISATEH) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FORMATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FORMATII</REFTABLE>
  <HASHVAL>B34D325D1563D0B147BB3D9387C271C5BB870A65</HASHVAL>
  <TEXT>ALTER TABLE FORMATII ADD CONSTRAINT PK_FORMATII PRIMARY KEY (CODFORMATIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FORMATII1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FORMATII1</REFTABLE>
  <HASHVAL>55D26C0738A4ED16CBBE0E656369AC129B1757B3</HASHVAL>
  <TEXT>ALTER TABLE FORMATII1 ADD CONSTRAINT PK_FORMATII1 PRIMARY KEY (CODFORMATIE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FORMATORI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FORMATORI</REFTABLE>
  <HASHVAL>DB3326D0F78710D33637D9E4E1ED1BE244DF9D3D</HASHVAL>
  <TEXT>ALTER TABLE FORMATORI ADD CONSTRAINT PK_FORMATORI PRIMARY KEY (CODFORMATOR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FUNCTII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FUNCTII</REFTABLE>
  <HASHVAL>A0726589EED2CE19EDCD4DCA5109AB558DE462DF</HASHVAL>
  <TEXT>ALTER TABLE FUNCTII ADD CONSTRAINT PK_FUNCTII PRIMARY KEY (CODFUNCTIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_FUNCTII1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FUNCTII1</REFTABLE>
  <HASHVAL>89DC8F970E0E41B4ECD6A155C50A8BB0F417FB79</HASHVAL>
  <TEXT>ALTER TABLE FUNCTII1 ADD CONSTRAINT PK_FUNCTII1 PRIMARY KEY (CODFUNCTIE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_GANTT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GANTT</REFTABLE>
  <HASHVAL>4FDA338C4848D918D040832DD5EA53DD3554D979</HASHVAL>
  <TEXT>ALTER TABLE GANTT ADD CONSTRAINT PK_GANTT PRIMARY KEY (CODGANTT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_GANTT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GANTT1</REFTABLE>
  <HASHVAL>582EA94EA8E9F8213C6B0801B1DF478035B7A347</HASHVAL>
  <TEXT>ALTER TABLE GANTT1 ADD CONSTRAINT PK_GANTT1 PRIMARY KEY (CODGANTT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_GENERAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GENERAL</REFTABLE>
  <HASHVAL>0315800EBA85D4BD1A72CF7DF5E58EE42D2104B0</HASHVAL>
  <TEXT>ALTER TABLE GENERAL ADD CONSTRAINT PK_GENERAL PRIMARY KEY (CODGENERAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_GRECHIV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GRECHIV</REFTABLE>
  <HASHVAL>392323F3450C5438D420FF6703A681AD96BF5396</HASHVAL>
  <TEXT>ALTER TABLE GRECHIV ADD CONSTRAINT PK_GRECHIV PRIMARY KEY (CODGRECHIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_GRUPEDRUM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GRUPEDRUM</REFTABLE>
  <HASHVAL>47564E87193F8EC64E6F52642DFB2A80B253F7DC</HASHVAL>
  <TEXT>ALTER TABLE GRUPEDRUM ADD CONSTRAINT PK_GRUPEDRUM PRIMARY KEY (CODGRUPA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESDISC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESDISC</REFTABLE>
  <HASHVAL>5D37CAE27381852C37B9CC366FD1EE107D34861E</HASHVAL>
  <TEXT>ALTER TABLE IESDISC ADD CONSTRAINT PK_IESDISC PRIMARY KEY (CODIESDISC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESIRI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>52CAE2040DE7858570A64C62346F974E660D06AE</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT PK_IESIRI PRIMARY KEY (CODIES) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESIRI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>854C075D3068569D532A3E62F846AEEDFC1D8BB0</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT PK_IESIRI1 PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESIRI1RETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1RETAIL</REFTABLE>
  <HASHVAL>DEF796EC65E14942C9BD175AD664EE7B772CB645</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1RETAIL ADD CONSTRAINT PK_IESIRI1RETAIL PRIMARY KEY (CODIES1RETAIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESIRIRETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRIRETAIL</REFTABLE>
  <HASHVAL>5AFCB2BEBCBE4CF10D27A7490E85B11FF06D7836</HASHVAL>
  <TEXT>ALTER TABLE IESIRIRETAIL ADD CONSTRAINT PK_IESIRIRETAIL PRIMARY KEY (CODIESRETAIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESLINK</REFTABLE>
  <HASHVAL>057E5D892FBA1F28A162686E93C45B07C0E79463</HASHVAL>
  <TEXT>ALTER TABLE IESLINK ADD CONSTRAINT PK_IESLINK PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESPRODLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESPRODLINK</REFTABLE>
  <HASHVAL>43DEC943B6BD33C294DC315D32CAF8AC68E59DD0</HASHVAL>
  <TEXT>ALTER TABLE IESPRODLINK ADD CONSTRAINT PK_IESPRODLINK PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IESPUNCTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESPUNCTE</REFTABLE>
  <HASHVAL>DEFC8DBD2583D2F9FCA427E7C4464333A7A1B692</HASHVAL>
  <TEXT>ALTER TABLE IESPUNCTE ADD CONSTRAINT PK_IESPUNCTE PRIMARY KEY (CODIESPUNCTE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INACTIVRETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INACTIVRETAIL</REFTABLE>
  <HASHVAL>4A72C8010E69E8242E3E86A7A766039955CCED10</HASHVAL>
  <TEXT>ALTER TABLE INACTIVRETAIL ADD CONSTRAINT PK_INACTIVRETAIL PRIMARY KEY (CODINACTIVRETAIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INTERFATAKLG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTERFATAKLG</REFTABLE>
  <HASHVAL>3A22296FBBD98EBFA46CEE0C1C4BE8764B3EEF44</HASHVAL>
  <TEXT>ALTER TABLE INTERFATAKLG ADD CONSTRAINT PK_INTERFATAKLG PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INTRARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI</REFTABLE>
  <HASHVAL>963C3603A6D06FDA925E575EDA3C21CEA01E2E85</HASHVAL>
  <TEXT>ALTER TABLE INTRARI ADD CONSTRAINT PK_INTRARI PRIMARY KEY (CODINTR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INTRARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI1</REFTABLE>
  <HASHVAL>902653FC958FDED00A4D70D32B91907F3AB4552C</HASHVAL>
  <TEXT>ALTER TABLE INTRARI1 ADD CONSTRAINT PK_INTRARI1 PRIMARY KEY (CODINTR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INTRLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRLINK</REFTABLE>
  <HASHVAL>43E3BB2D97491A4763459ED40F4157129FFE8A59</HASHVAL>
  <TEXT>ALTER TABLE INTRLINK ADD CONSTRAINT PK_INTRLINK PRIMARY KEY (CODINTR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INTRPRODLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRPRODLINK</REFTABLE>
  <HASHVAL>6EBC8A15B97E1CB36166F179BE084DB80D76AAE7</HASHVAL>
  <TEXT>ALTER TABLE INTRPRODLINK ADD CONSTRAINT PK_INTRPRODLINK PRIMARY KEY (CODINTR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTAR</REFTABLE>
  <HASHVAL>AB8618C831E154A04A368022BAB4F0E1C56290B5</HASHVAL>
  <TEXT>ALTER TABLE INVENTAR ADD CONSTRAINT PK_INVENTAR PRIMARY KEY (CODINVENTAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTAR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTAR1</REFTABLE>
  <HASHVAL>3AE01C5429273CBD321CC162CFBAE7212BB57B69</HASHVAL>
  <TEXT>ALTER TABLE INVENTAR1 ADD CONSTRAINT PK_INVENTAR1 PRIMARY KEY (CODINVENTAR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTCLASE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTCLASE</REFTABLE>
  <HASHVAL>B5EF46C337D98FB20FF2950BC18722338CFC2F8B</HASHVAL>
  <TEXT>ALTER TABLE INVENTCLASE ADD CONSTRAINT PK_INVENTCLASE PRIMARY KEY (CODINVENTCLASE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTCONT</REFTABLE>
  <HASHVAL>258032FDE1104E4940B53E6048B68937F4149E09</HASHVAL>
  <TEXT>ALTER TABLE INVENTCONT ADD CONSTRAINT PK_INVENTCONT PRIMARY KEY (CODINVENTCONT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTREZ</REFTABLE>
  <HASHVAL>995D39EF97E8FA0AA3A207BFA4CFA3DEDC0393E6</HASHVAL>
  <TEXT>ALTER TABLE INVENTREZ ADD CONSTRAINT PK_INVENTREZ PRIMARY KEY (CODREZOLVARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_INVENTSTOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTSTOC</REFTABLE>
  <HASHVAL>9C2523145BA57C525643DB3369CDB650B8233194</HASHVAL>
  <TEXT>ALTER TABLE INVENTSTOC ADD CONSTRAINT PK_INVENTSTOC PRIMARY KEY (CODINVENTSTOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART</REFTABLE>
  <HASHVAL>1698372BADCBE030624671FEE76198C1F996F8A8</HASHVAL>
  <TEXT>ALTER TABLE IOART ADD CONSTRAINT PK_IOART PRIMARY KEY (CODIOART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOART1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>BA1CAFFEDF02496105EF46F6078104A7F10ED0FC</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT PK_IOART1 PRIMARY KEY (CODIOART1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOARTLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOARTLINK</REFTABLE>
  <HASHVAL>C553289D4EE52FD582C95230F2ECD32895712BDD</HASHVAL>
  <TEXT>ALTER TABLE IOARTLINK ADD CONSTRAINT PK_IOARTLINK PRIMARY KEY (CODIOARTLINK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOBANK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOBANK</REFTABLE>
  <HASHVAL>EA30F84E98E81D0697DD1B2DAF3258E0DEE6FF2A</HASHVAL>
  <TEXT>ALTER TABLE IOBANK ADD CONSTRAINT PK_IOBANK PRIMARY KEY (CODIOBANK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOFILIAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL</REFTABLE>
  <HASHVAL>B3C263118042BECB843CF9D895CEFB7A624757CD</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL ADD CONSTRAINT PK_IOFILIAL PRIMARY KEY (CODIOFILIAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOFILIAL1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>9AC8BC8E76A081C3CA6A2CC144CBE5E7B974F209</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT PK_IOFILIAL1 PRIMARY KEY (CODIOFILIAL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPART</REFTABLE>
  <HASHVAL>48A7AC7A40FBE0E95426E3762EEECAFB8AB7EB90</HASHVAL>
  <TEXT>ALTER TABLE IOPART ADD CONSTRAINT PK_IOPART PRIMARY KEY (CODIOPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOPERS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS</REFTABLE>
  <HASHVAL>75F9A4EF907D444BC792A146B21C4467B5181A1F</HASHVAL>
  <TEXT>ALTER TABLE IOPERS ADD CONSTRAINT PK_IOPERS PRIMARY KEY (CODIOPERS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_IOPERS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>D4BB242B11FC8935FFFEE9A5AD5FA160B95CD3E5</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT PK_IOPERS1 PRIMARY KEY (CODIOPERS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JOBCOREL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JOBCOREL</REFTABLE>
  <HASHVAL>21FA5139774517E9DFF92FD862A058DA08A14295</HASHVAL>
  <TEXT>ALTER TABLE JOBCOREL ADD CONSTRAINT PK_JOBCOREL PRIMARY KEY (CODCOREL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JOBCORELREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JOBCORELREZ</REFTABLE>
  <HASHVAL>EAC0CC9BE55B730A9EB61D56D7F2BF5BA39BD2CD</HASHVAL>
  <TEXT>ALTER TABLE JOBCORELREZ ADD CONSTRAINT PK_JOBCORELREZ PRIMARY KEY (CODCORELREZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JOBLISTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JOBLISTE</REFTABLE>
  <HASHVAL>11D8FB2BFE15D7318956AC060DD142AC82609416</HASHVAL>
  <TEXT>ALTER TABLE JOBLISTE ADD CONSTRAINT PK_JOBLISTE PRIMARY KEY (CODJOB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JOBLISTE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JOBLISTE1</REFTABLE>
  <HASHVAL>28A0C83C17BFA73BADA1267603E233DB9B7B8ABE</HASHVAL>
  <TEXT>ALTER TABLE JOBLISTE1 ADD CONSTRAINT PK_JOBLISTE1 PRIMARY KEY (CODJOB1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JURNAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JURNAL</REFTABLE>
  <HASHVAL>8A0A88CA1A29F42D4D29C98B0751F9930B6E3E1C</HASHVAL>
  <TEXT>ALTER TABLE JURNAL ADD CONSTRAINT PK_JURNAL PRIMARY KEY (CODJURNAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_JURNAL1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JURNAL1</REFTABLE>
  <HASHVAL>629846CF42E2986F02D8D29D78A9FE1F9963412B</HASHVAL>
  <TEXT>ALTER TABLE JURNAL1 ADD CONSTRAINT PK_JURNAL1 PRIMARY KEY (CODJURNAL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSARE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSARE</REFTABLE>
  <HASHVAL>3105195E33864ABED9160866141D96B84C8C9017</HASHVAL>
  <TEXT>ALTER TABLE LANSARE ADD CONSTRAINT PK_LANSARE PRIMARY KEY (CODLANSARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSARE0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSARE0</REFTABLE>
  <HASHVAL>0D23C8A367A90E8BC275F70904A714251AE19716</HASHVAL>
  <TEXT>ALTER TABLE LANSARE0 ADD CONSTRAINT PK_LANSARE0 PRIMARY KEY (CODLANSARE0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSARE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSARE1</REFTABLE>
  <HASHVAL>CCA5FB25748273131E65CE2949F08EEF2B69575F</HASHVAL>
  <TEXT>ALTER TABLE LANSARE1 ADD CONSTRAINT PK_LANSARE1 PRIMARY KEY (CODLANSARE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSGEST</REFTABLE>
  <HASHVAL>5BA691A133D5271B32BB7EDEE02BAED7E6682E99</HASHVAL>
  <TEXT>ALTER TABLE LANSGEST ADD CONSTRAINT PK_LANSGEST PRIMARY KEY (CODLANSGEST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSPROD</REFTABLE>
  <HASHVAL>64BE4920ED9C95A4C5B8F2FFAFC54A4BEF2E856E</HASHVAL>
  <TEXT>ALTER TABLE LANSPROD ADD CONSTRAINT PK_LANSPROD PRIMARY KEY (CODLANSPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSPROD1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSPROD1</REFTABLE>
  <HASHVAL>55923183275AC5442FD6D0F0CD1F76FD7E4CFB0F</HASHVAL>
  <TEXT>ALTER TABLE LANSPROD1 ADD CONSTRAINT PK_LANSPROD1 PRIMARY KEY (CODLANSPROD1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSPROD2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSPROD2</REFTABLE>
  <HASHVAL>9600BC1F71FB5CDE6F5814492C13AE8D90635F01</HASHVAL>
  <TEXT>ALTER TABLE LANSPROD2 ADD CONSTRAINT PK_LANSPROD2 PRIMARY KEY (CODLANSPROD2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSPROD2S</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSPROD2S</REFTABLE>
  <HASHVAL>A2F60746A79ACACBD263AEFDD580C9F730BB4751</HASHVAL>
  <TEXT>ALTER TABLE LANSPROD2S ADD CONSTRAINT PK_LANSPROD2S PRIMARY KEY (CODLANSPROD2S) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ</REFTABLE>
  <HASHVAL>3EC9CE4F31202515E3540DE09BB98DEE1D77E70E</HASHVAL>
  <TEXT>ALTER TABLE LANSZ ADD CONSTRAINT PK_LANSZ PRIMARY KEY (CODLANSZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LANSZ1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ1</REFTABLE>
  <HASHVAL>12898602CF5825F03CDB94639E912AEFD7AEE2E1</HASHVAL>
  <TEXT>ALTER TABLE LANSZ1 ADD CONSTRAINT PK_LANSZ1 PRIMARY KEY (CODLANSZ1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVR</REFTABLE>
  <HASHVAL>F635D44F9A6167BB4A5863892700EC5E46DAC465</HASHVAL>
  <TEXT>ALTER TABLE LIVR ADD CONSTRAINT PK_LIVR PRIMARY KEY (CODLIVR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LIVR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVR1</REFTABLE>
  <HASHVAL>E8C24016DCA2CE125D29EE40A6C999042A1B8A86</HASHVAL>
  <TEXT>ALTER TABLE LIVR1 ADD CONSTRAINT PK_LIVR1 PRIMARY KEY (CODLIVR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LIVRVAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVRVAL</REFTABLE>
  <HASHVAL>8F4696D312ACCFB349E6DA89B0DFF42C7838E25D</HASHVAL>
  <TEXT>ALTER TABLE LIVRVAL ADD CONSTRAINT PK_LIVRVAL PRIMARY KEY (CODLIVRVAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LOCMUNCA</REFTABLE>
  <HASHVAL>4E9078CE2D1B7921ED18A9FF4398CF618E837364</HASHVAL>
  <TEXT>ALTER TABLE LOCMUNCA ADD CONSTRAINT PK_LOCMUNCA PRIMARY KEY (CODLOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LOCMUNCA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LOCMUNCA1</REFTABLE>
  <HASHVAL>4462EF266FF4CD7279DFAA38DFFB8CA7C136D6BC</HASHVAL>
  <TEXT>ALTER TABLE LOCMUNCA1 ADD CONSTRAINT PK_LOCMUNCA1 PRIMARY KEY (CODLOC1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LOCMUNCA2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LOCMUNCA2</REFTABLE>
  <HASHVAL>24C50B30FEE3E9D73659750495A19D93A3F6AF29</HASHVAL>
  <TEXT>ALTER TABLE LOCMUNCA2 ADD CONSTRAINT PK_LOCMUNCA2 PRIMARY KEY (CODLOC2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_LOGUSERTAB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LOGUSERTAB</REFTABLE>
  <HASHVAL>2CBFA437059B877E51DC15017019921FB31B4D11</HASHVAL>
  <TEXT>ALTER TABLE LOGUSERTAB ADD CONSTRAINT PK_LOGUSERTAB PRIMARY KEY (NUMEUSER) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MAILURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MAILURI</REFTABLE>
  <HASHVAL>7317DBF71F7DE140B2B273145927C6223E74F651</HASHVAL>
  <TEXT>ALTER TABLE MAILURI ADD CONSTRAINT PK_MAILURI PRIMARY KEY (CODMAIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MAILURI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MAILURI1</REFTABLE>
  <HASHVAL>FE13A1E7F5C1312029012BCBCE499BA60738CD3A</HASHVAL>
  <TEXT>ALTER TABLE MAILURI1 ADD CONSTRAINT PK_MAILURI1 PRIMARY KEY (CODMAIL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MAILURIDOCS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MAILURIDOCS</REFTABLE>
  <HASHVAL>AD5474F9216AA4B5B39653E39A407EE356F3F56E</HASHVAL>
  <TEXT>ALTER TABLE MAILURIDOCS ADD CONSTRAINT PK_MAILURIDOCS PRIMARY KEY (CODMAILDOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MANPRODLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MANPRODLINK</REFTABLE>
  <HASHVAL>D9BE52C143BB1FA9C83461F82D37A132637F3676</HASHVAL>
  <TEXT>ALTER TABLE MANPRODLINK ADD CONSTRAINT PK_MANPRODLINK PRIMARY KEY (CODRAPORTP2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MASCASERART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MASCASERART</REFTABLE>
  <HASHVAL>DB9AD1E1575241369BDDBAD250D5AC8C3C6CB789</HASHVAL>
  <TEXT>ALTER TABLE MASCASERART ADD CONSTRAINT PK_MASCASERART PRIMARY KEY (CODMASCA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MASCASERART1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MASCASERART1</REFTABLE>
  <HASHVAL>A84EB2D0D7144A7D3894674D3C4D2E19E9B5B248</HASHVAL>
  <TEXT>ALTER TABLE MASCASERART1 ADD CONSTRAINT PK_MASCASERART1 PRIMARY KEY (CODMASCA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MASTERMAK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MASTERMAK</REFTABLE>
  <HASHVAL>A290C60F60B50859B42ECA059B6F757EC575C10F</HASHVAL>
  <TEXT>ALTER TABLE MASTERMAK ADD CONSTRAINT PK_MASTERMAK PRIMARY KEY (CODMASTERMAK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MEDEX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MEDEX</REFTABLE>
  <HASHVAL>DD3C2D0445A670D6220C267DAAABDB00C4B288BA</HASHVAL>
  <TEXT>ALTER TABLE MEDEX ADD CONSTRAINT PK_MEDEX PRIMARY KEY (CODMEDEX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MEDEX1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MEDEX1</REFTABLE>
  <HASHVAL>383BBB0CE17D152991018E35D545716228BACDDA</HASHVAL>
  <TEXT>ALTER TABLE MEDEX1 ADD CONSTRAINT PK_MEDEX1 PRIMARY KEY (CODMEDEX1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MEDEX2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MEDEX2</REFTABLE>
  <HASHVAL>8B634E15D0338A287DA89C92D952806CCE34B821</HASHVAL>
  <TEXT>ALTER TABLE MEDEX2 ADD CONSTRAINT PK_MEDEX2 PRIMARY KEY (CODMEDEX2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MEDEX_TARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MEDEX_TARI</REFTABLE>
  <HASHVAL>E77542276D1D730E6F6633A144E83B85B726A646</HASHVAL>
  <TEXT>ALTER TABLE MEDEX_TARI ADD CONSTRAINT PK_MEDEX_TARI PRIMARY KEY (CODMEDEXT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENUDASH</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDASH</REFTABLE>
  <HASHVAL>7494EDEAC096F3A8A3FA3512E612BCAA7338E940</HASHVAL>
  <TEXT>ALTER TABLE MENUDASH ADD CONSTRAINT PK_MENUDASH PRIMARY KEY (CODMENUDASH) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENUDASH0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDASH0</REFTABLE>
  <HASHVAL>4426B0D279C5AE2142D744ACAEC9EBD028225BE4</HASHVAL>
  <TEXT>ALTER TABLE MENUDASH0 ADD CONSTRAINT PK_MENUDASH0 PRIMARY KEY (CODMENUDASH0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENUDASH1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDASH1</REFTABLE>
  <HASHVAL>F22BC8155FD574CDDCAD073238AD2F4AEE22B579</HASHVAL>
  <TEXT>ALTER TABLE MENUDASH1 ADD CONSTRAINT PK_MENUDASH1 PRIMARY KEY (CODMENUDASH1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENUDATE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDATE</REFTABLE>
  <HASHVAL>3BBA8E3027E8116E682778078EAC926BFBD0FE37</HASHVAL>
  <TEXT>ALTER TABLE MENUDATE ADD CONSTRAINT PK_MENUDATE PRIMARY KEY (CODMENUDATE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENUDATE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDATE1</REFTABLE>
  <HASHVAL>F685BAEA34239FC1121A057947E470ED553F83EE</HASHVAL>
  <TEXT>ALTER TABLE MENUDATE1 ADD CONSTRAINT PK_MENUDATE1 PRIMARY KEY (CODMENUDATE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MENULISTE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENULISTE1</REFTABLE>
  <HASHVAL>5097A34252AA3CA60423D2D9A7FB46CEC215349C</HASHVAL>
  <TEXT>ALTER TABLE MENULISTE1 ADD CONSTRAINT PK_MENULISTE1 PRIMARY KEY (CODMENU1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MESE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MESE</REFTABLE>
  <HASHVAL>EE01B0BF1168C94712D5C593F021005A52CFDF26</HASHVAL>
  <TEXT>ALTER TABLE MESE ADD CONSTRAINT PK_MESE PRIMARY KEY (CODMASA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MESE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MESE1</REFTABLE>
  <HASHVAL>1916D90EC3CB1260A5A3F1AFC6B0E487930EC9F8</HASHVAL>
  <TEXT>ALTER TABLE MESE1 ADD CONSTRAINT PK_MESE1 PRIMARY KEY (CODMASA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MFCLASIF</REFTABLE>
  <HASHVAL>97F5F70A72754D9AF80F94698707928DE840AA06</HASHVAL>
  <TEXT>ALTER TABLE MFCLASIF ADD CONSTRAINT PK_MFCLASIF PRIMARY KEY (CODCLASIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MIFIX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MIFIX</REFTABLE>
  <HASHVAL>EB6A646450A862322028BFCCC17BC91DDD500B12</HASHVAL>
  <TEXT>ALTER TABLE MIFIX ADD CONSTRAINT PK_MIFIX PRIMARY KEY (CODMIFIX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MIFIX1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MIFIX1</REFTABLE>
  <HASHVAL>B45385C1B3B28A38CE22B233CB11D43E63881DD8</HASHVAL>
  <TEXT>ALTER TABLE MIFIX1 ADD CONSTRAINT PK_MIFIX1 PRIMARY KEY (CODMIFIX1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MODIFICARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MODIFICARI</REFTABLE>
  <HASHVAL>AF4DF13305F480D9C7F04A31595E6CDE29F58FED</HASHVAL>
  <TEXT>ALTER TABLE MODIFICARI ADD CONSTRAINT PK_MODIFICARI PRIMARY KEY (CODMODIFICARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MODI_STATE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MODI_STATE</REFTABLE>
  <HASHVAL>25AB3DC7E79E99A63F6015047DC3CBA1AF50DA01</HASHVAL>
  <TEXT>ALTER TABLE MODI_STATE ADD CONSTRAINT PK_MODI_STATE PRIMARY KEY (CODMODI_STATE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MODPLATA2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MODPLATA2</REFTABLE>
  <HASHVAL>7686634D1AF093FA8A568788A582761B43F4B83C</HASHVAL>
  <TEXT>ALTER TABLE MODPLATA2 ADD CONSTRAINT PK_MODPLATA2 PRIMARY KEY (CODMODPLATA2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MODURIPLATI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MODURIPLATI</REFTABLE>
  <HASHVAL>586FBB2FA1A98C6A16A7408032C3F41636857BEB</HASHVAL>
  <TEXT>ALTER TABLE MODURIPLATI ADD CONSTRAINT PK_MODURIPLATI PRIMARY KEY (CODMODPLATA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MOTIVE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MOTIVE</REFTABLE>
  <HASHVAL>1C1354106F6674FD6E263AC0EE92B17A455F499D</HASHVAL>
  <TEXT>ALTER TABLE MOTIVE ADD CONSTRAINT PK_MOTIVE PRIMARY KEY (CODMOTIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MOTIVEP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MOTIVEP</REFTABLE>
  <HASHVAL>484C94F01447AECBD529742DE2CCC4540C7522C5</HASHVAL>
  <TEXT>ALTER TABLE MOTIVEP ADD CONSTRAINT PK_MOTIVEP PRIMARY KEY (CODMOTIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MPBCAR1_CODMPBCAR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MPBCAR1</REFTABLE>
  <HASHVAL>CC1BA3906C06F8E428F27AF19C07B82F0022BE84</HASHVAL>
  <TEXT>ALTER TABLE MPBCAR1 ADD CONSTRAINT PK_MPBCAR1_CODMPBCAR1 PRIMARY KEY (CODMPBCAR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MPBCAR2_CODMPBCAR2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MPBCAR2</REFTABLE>
  <HASHVAL>C603F82E620B8EA57AEFFF8B2A04C82B7D10225A</HASHVAL>
  <TEXT>ALTER TABLE MPBCAR2 ADD CONSTRAINT PK_MPBCAR2_CODMPBCAR2 PRIMARY KEY (CODMPBCAR2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_MPBCAR_CODMPBCAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MPBCAR</REFTABLE>
  <HASHVAL>59F82C51F9D9E282E2E4C1621857977A29371078</HASHVAL>
  <TEXT>ALTER TABLE MPBCAR ADD CONSTRAINT PK_MPBCAR_CODMPBCAR PRIMARY KEY (CODMPBCAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NACTIVIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NACTIVIT</REFTABLE>
  <HASHVAL>FB257B9869151BD88F8AE05DCE4F7613BCBB754D</HASHVAL>
  <TEXT>ALTER TABLE NACTIVIT ADD CONSTRAINT PK_NACTIVIT PRIMARY KEY (CODACTIVIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENDA</REFTABLE>
  <HASHVAL>876894B51B8CB0F6FAD7187AAC3AFE552D5B3978</HASHVAL>
  <TEXT>ALTER TABLE NAGENDA ADD CONSTRAINT PK_NAGENDA PRIMARY KEY (CODAGENDA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAGENDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENDA1</REFTABLE>
  <HASHVAL>0EA1564FA1FBC45568FAF792DC3F19CAC2FD2259</HASHVAL>
  <TEXT>ALTER TABLE NAGENDA1 ADD CONSTRAINT PK_NAGENDA1 PRIMARY KEY (CODAGENDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAGENTI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENTI1</REFTABLE>
  <HASHVAL>D104CA6BEE9D7FCA11F36C682256E1F856588F17</HASHVAL>
  <TEXT>ALTER TABLE NAGENTI1 ADD CONSTRAINT PK_NAGENTI1 PRIMARY KEY (CODAGENT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAGENTIPROC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENTIPROC</REFTABLE>
  <HASHVAL>2F5CB53E8A7A6E54471504072CA6AB9857C08649</HASHVAL>
  <TEXT>ALTER TABLE NAGENTIPROC ADD CONSTRAINT PK_NAGENTIPROC PRIMARY KEY (CODAGENTPROC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAGENTIVAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENTIVAL</REFTABLE>
  <HASHVAL>79CD234D5B3C3958485D90A0719B4F15E45C82D1</HASHVAL>
  <TEXT>ALTER TABLE NAGENTIVAL ADD CONSTRAINT PK_NAGENTIVAL PRIMARY KEY (CODAGENTVAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>6268A7603F19043FC68126E0336D63621B9DACD0</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT PK_NART PRIMARY KEY (CODARTICOL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NART1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>0CA17AABEB1376993F35E1CC097D61A9421FADA3</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT PK_NART1 PRIMARY KEY (CODARTICOL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTAMB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTAMB</REFTABLE>
  <HASHVAL>45E7BDD359D1EE5FC8D6D5D0381CFF27DB6BA629</HASHVAL>
  <TEXT>ALTER TABLE NARTAMB ADD CONSTRAINT PK_NARTAMB PRIMARY KEY (CODAMB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTATR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTATR</REFTABLE>
  <HASHVAL>A5CD3002DA8FCABCBA3DE5341BF16FB1C911B1A4</HASHVAL>
  <TEXT>ALTER TABLE NARTATR ADD CONSTRAINT PK_NARTATR PRIMARY KEY (CODARTATR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTCLI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTCLI</REFTABLE>
  <HASHVAL>167736594DE6FA9A2DF60BF27A1006F8E92153F1</HASHVAL>
  <TEXT>ALTER TABLE NARTCLI ADD CONSTRAINT PK_NARTCLI PRIMARY KEY (CODARTCLI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTDIM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTDIM</REFTABLE>
  <HASHVAL>5A752CEC9968F701B292FCE78D2A79D6D229F498</HASHVAL>
  <TEXT>ALTER TABLE NARTDIM ADD CONSTRAINT PK_NARTDIM PRIMARY KEY (CODARTDIM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTIMPLICITE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTIMPLICITE</REFTABLE>
  <HASHVAL>C472F5C55BEF0A995014278396545A0743F2828C</HASHVAL>
  <TEXT>ALTER TABLE NARTIMPLICITE ADD CONSTRAINT PK_NARTIMPLICITE PRIMARY KEY (CODIMPLICIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJ</REFTABLE>
  <HASHVAL>756F2CA482A711E91772959E7BEE344516D3496D</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJ ADD CONSTRAINT PK_NARTOBJ PRIMARY KEY (CODOBIECT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOBJ1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJ1</REFTABLE>
  <HASHVAL>A0D69B987D57F0437AEE41EB543B685ECA054266</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJ1 ADD CONSTRAINT PK_NARTOBJ1 PRIMARY KEY (CODOBIECT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOBJIMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJIMP</REFTABLE>
  <HASHVAL>FE96268C90DEF78D18B3F667F511282DFC133D02</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJIMP ADD CONSTRAINT PK_NARTOBJIMP PRIMARY KEY (CODOBJIMP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOBJSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJSUBUNIT</REFTABLE>
  <HASHVAL>2BA3B19FBC3AA71AE5B4FEEEC17A78BACD07000C</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJSUBUNIT ADD CONSTRAINT PK_NARTOBJSUBUNIT PRIMARY KEY (CODS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOBJTRAD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJTRAD</REFTABLE>
  <HASHVAL>E52EF7EC7F072C5C1F320E0737CF9B8BB9F54FC9</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJTRAD ADD CONSTRAINT PK_NARTOBJTRAD PRIMARY KEY (CODOBIECTTRAD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NARTOPT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOPT</REFTABLE>
  <HASHVAL>A71C0A70F44C8668EF08893721B2F356D339C7B2</HASHVAL>
  <TEXT>ALTER TABLE NARTOPT ADD CONSTRAINT PK_NARTOPT PRIMARY KEY (CODOPT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NATRIB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATRIB</REFTABLE>
  <HASHVAL>EEFDD1937675E5E7190B3055F11BC131A16A3674</HASHVAL>
  <TEXT>ALTER TABLE NATRIB ADD CONSTRAINT PK_NATRIB PRIMARY KEY (CODATRIBUT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NATRIB1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATRIB1</REFTABLE>
  <HASHVAL>6259624E79486DC02AE55A5DA39939C0F01BDD0C</HASHVAL>
  <TEXT>ALTER TABLE NATRIB1 ADD CONSTRAINT PK_NATRIB1 PRIMARY KEY (CODVALATR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NATROBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATROBJ</REFTABLE>
  <HASHVAL>4ED158635049104E815BD697E8E4C71C0F9B5606</HASHVAL>
  <TEXT>ALTER TABLE NATROBJ ADD CONSTRAINT PK_NATROBJ PRIMARY KEY (CODATROBJ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NAUTORIZATIIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAUTORIZATIIAUTO</REFTABLE>
  <HASHVAL>31290AFD2B366DAAA92FDF9AD75F41046EF434AB</HASHVAL>
  <TEXT>ALTER TABLE NAUTORIZATIIAUTO ADD CONSTRAINT PK_NAUTORIZATIIAUTO PRIMARY KEY (CODAUTORIZATII) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NBANK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANK</REFTABLE>
  <HASHVAL>786C97679129C5920DB8C1AC9BBA37D9525EAE0E</HASHVAL>
  <TEXT>ALTER TABLE NBANK ADD CONSTRAINT PK_NBANK PRIMARY KEY (CODBANK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NBANKCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT</REFTABLE>
  <HASHVAL>F5CFC53D3834F44319F588B4F994360440336F87</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT ADD CONSTRAINT PK_NBANKCONT PRIMARY KEY (CODBANKCONT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NBANKCONT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT1</REFTABLE>
  <HASHVAL>3EDC0E095A97EE3E0625729CD20173D4993AF8F0</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT1 ADD CONSTRAINT PK_NBANKCONT1 PRIMARY KEY (CODBANKCONT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NBANKSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKSOLDLUNA</REFTABLE>
  <HASHVAL>D9423AFC58FC730FCC77C0B5FC060B2F6B3A2651</HASHVAL>
  <TEXT>ALTER TABLE NBANKSOLDLUNA ADD CONSTRAINT PK_NBANKSOLDLUNA PRIMARY KEY (CODBANKSOLDLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC</REFTABLE>
  <HASHVAL>BB6E7436F6404A1B8D9BA20F23A6FA916293AC9E</HASHVAL>
  <TEXT>ALTER TABLE NC ADD CONSTRAINT PK_NC PRIMARY KEY (CODNC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NC1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC1</REFTABLE>
  <HASHVAL>2F71260C23299EF9233F6D63E89FE527D8F60E05</HASHVAL>
  <TEXT>ALTER TABLE NC1 ADD CONSTRAINT PK_NC1 PRIMARY KEY (CODNC1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCARSUPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCARSUPART</REFTABLE>
  <HASHVAL>B283C633FC184F973AA725E3DD7C391C9060A0A4</HASHVAL>
  <TEXT>ALTER TABLE NCARSUPART ADD CONSTRAINT PK_NCARSUPART PRIMARY KEY (CODCARSUPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCASEMARCAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCASEMARCAT</REFTABLE>
  <HASHVAL>565F1AF6389B459B376B8EB24BE38E50FCF6640D</HASHVAL>
  <TEXT>ALTER TABLE NCASEMARCAT ADD CONSTRAINT PK_NCASEMARCAT PRIMARY KEY (CODCASEMARCAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCASEMARCAT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCASEMARCAT1</REFTABLE>
  <HASHVAL>6970EB347A2157C9652BF83F13531E9409ACA0C6</HASHVAL>
  <TEXT>ALTER TABLE NCASEMARCAT1 ADD CONSTRAINT PK_NCASEMARCAT1 PRIMARY KEY (CODCASEMARCAT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCASEMARCAT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCASEMARCAT2</REFTABLE>
  <HASHVAL>7EBB625DD3881A33392DBAC4519DA6B943A2C8FD</HASHVAL>
  <TEXT>ALTER TABLE NCASEMARCAT2 ADD CONSTRAINT PK_NCASEMARCAT2 PRIMARY KEY (CODCASEMARCAT2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCATPRET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCATPRET</REFTABLE>
  <HASHVAL>558A1782AD919A3A721EFF4C2EAA9F27C79B19F0</HASHVAL>
  <TEXT>ALTER TABLE NCATPRET ADD CONSTRAINT PK_NCATPRET PRIMARY KEY (CODCATPRET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCCADOURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCCADOURI</REFTABLE>
  <HASHVAL>3634DA621A2518E06467ECBBA10A8315CC9649B0</HASHVAL>
  <TEXT>ALTER TABLE NCCADOURI ADD CONSTRAINT PK_NCCADOURI PRIMARY KEY (CODNCCADOURI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEA</REFTABLE>
  <HASHVAL>ECBBB9934FA38FF729AF3D034B635BE3BF3CBC15</HASHVAL>
  <TEXT>ALTER TABLE NCLASEA ADD CONSTRAINT PK_NCLASEA PRIMARY KEY (CODCLASEA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEAS</REFTABLE>
  <HASHVAL>544281D567AB510F6E3EE1DBDC3B38F21B25D947</HASHVAL>
  <TEXT>ALTER TABLE NCLASEAS ADD CONSTRAINT PK_NCLASEAS PRIMARY KEY (CODCLASEAS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEG</REFTABLE>
  <HASHVAL>FEC26D3CCFF2831FB9B4BB0E0E1C359570F53676</HASHVAL>
  <TEXT>ALTER TABLE NCLASEG ADD CONSTRAINT PK_NCLASEG PRIMARY KEY (CODCLASEG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEINT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEINT</REFTABLE>
  <HASHVAL>BDA5400977FD5A18DF1ACA087F878CE91D533880</HASHVAL>
  <TEXT>ALTER TABLE NCLASEINT ADD CONSTRAINT PK_NCLASEINT PRIMARY KEY (CODCLASEINT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEMF</REFTABLE>
  <HASHVAL>578685125F55792472E6F9D70F6CDDB42AA1003C</HASHVAL>
  <TEXT>ALTER TABLE NCLASEMF ADD CONSTRAINT PK_NCLASEMF PRIMARY KEY (CODCLASEMF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEOP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEOP</REFTABLE>
  <HASHVAL>60F2B85DBD7BF6ACD2F05285DEB07A66E7A33A59</HASHVAL>
  <TEXT>ALTER TABLE NCLASEOP ADD CONSTRAINT PK_NCLASEOP PRIMARY KEY (CODCLASEOP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEOPT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEOPT</REFTABLE>
  <HASHVAL>2C85E9FA1CEC851F00D82E6CAD5045EA43A9FA06</HASHVAL>
  <TEXT>ALTER TABLE NCLASEOPT ADD CONSTRAINT PK_NCLASEOPT PRIMARY KEY (CODCLASEOPT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEP</REFTABLE>
  <HASHVAL>B060E22E318213DBD6562F99DDBE755700994F49</HASHVAL>
  <TEXT>ALTER TABLE NCLASEP ADD CONSTRAINT PK_NCLASEP PRIMARY KEY (CODCLASEP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCLASEPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEPROD</REFTABLE>
  <HASHVAL>D6AEC99A862CBFACEAA3E37C35A80DD612C0DCC5</HASHVAL>
  <TEXT>ALTER TABLE NCLASEPROD ADD CONSTRAINT PK_NCLASEPROD PRIMARY KEY (CODCLASEPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT</REFTABLE>
  <HASHVAL>2F976025F307AC62307A6DD1D68750070701396E</HASHVAL>
  <TEXT>ALTER TABLE NCONT ADD CONSTRAINT PK_NCONT PRIMARY KEY (CODCONT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>EAA4B1B2A10B329CC86D7CEEAC9AC089D362D35C</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT PK_NCONT1 PRIMARY KEY (CODCONT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTREP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREP</REFTABLE>
  <HASHVAL>7AABD2DA4FF6C4ED9C5122703720455728B6E141</HASHVAL>
  <TEXT>ALTER TABLE NCONTREP ADD CONSTRAINT PK_NCONTREP PRIMARY KEY (CODCONTREP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTREPRUL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREPRUL</REFTABLE>
  <HASHVAL>8666D95A1DC44DB1386A793C001FAEEB319E449F</HASHVAL>
  <TEXT>ALTER TABLE NCONTREPRUL ADD CONSTRAINT PK_NCONTREPRUL PRIMARY KEY (CODCONTREPRUL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTREPSOLD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREPSOLD</REFTABLE>
  <HASHVAL>52CA3458448CABC78749D690D0EEFB099AF73C1F</HASHVAL>
  <TEXT>ALTER TABLE NCONTREPSOLD ADD CONSTRAINT PK_NCONTREPSOLD PRIMARY KEY (CODCONTREPSOLD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTRUL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTRUL</REFTABLE>
  <HASHVAL>1474501ADFACBA6B3EF2EACCFCB65D7DAB3E6564</HASHVAL>
  <TEXT>ALTER TABLE NCONTRUL ADD CONSTRAINT PK_NCONTRUL PRIMARY KEY (CODCONTRUL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTRULS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTRULS</REFTABLE>
  <HASHVAL>7F6272F66A1859569C77EFF3699518F7FA6AA653</HASHVAL>
  <TEXT>ALTER TABLE NCONTRULS ADD CONSTRAINT PK_NCONTRULS PRIMARY KEY (CODCONTRULS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTRULT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTRULT</REFTABLE>
  <HASHVAL>234F30D82F0B406A542733A332E1EAFFCDA37C15</HASHVAL>
  <TEXT>ALTER TABLE NCONTRULT ADD CONSTRAINT PK_NCONTRULT PRIMARY KEY (CODCONTRULT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTS</REFTABLE>
  <HASHVAL>37112EB796A244196ADE98A6A6E55D65A1A5F69A</HASHVAL>
  <TEXT>ALTER TABLE NCONTS ADD CONSTRAINT PK_NCONTS PRIMARY KEY (CODCONTS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTS1</REFTABLE>
  <HASHVAL>3E2EDE8C9C4E9643789B48C54219FF04824076A6</HASHVAL>
  <TEXT>ALTER TABLE NCONTS1 ADD CONSTRAINT PK_NCONTS1 PRIMARY KEY (CODCONTS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTSOLD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLD</REFTABLE>
  <HASHVAL>68CEFE0325CA868EFCAF1389F620AA7912DD2C11</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLD ADD CONSTRAINT PK_NCONTSOLD PRIMARY KEY (CODCONTSOLD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTSOLDS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDS</REFTABLE>
  <HASHVAL>2736CD5A9ED0D6A404D9A91AACF37AE782BCCAC3</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDS ADD CONSTRAINT PK_NCONTSOLDS PRIMARY KEY (CODCONTSOLDS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTSOLDSUB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDSUB</REFTABLE>
  <HASHVAL>BD79E3C50007B481313F2514A93B6B48910AA0BE</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDSUB ADD CONSTRAINT PK_NCONTSOLDSUB PRIMARY KEY (CODCONTSOLDSUB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTSOLDT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDT</REFTABLE>
  <HASHVAL>70385F5D5B0632AD36EADDBF8C0C5F83B583F830</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDT ADD CONSTRAINT PK_NCONTSOLDT PRIMARY KEY (CODCONTSOLDT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTT</REFTABLE>
  <HASHVAL>C9DBD4B73914FD315D2AAE9132654882402F369C</HASHVAL>
  <TEXT>ALTER TABLE NCONTT ADD CONSTRAINT PK_NCONTT PRIMARY KEY (CODCONTT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONTT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTT1</REFTABLE>
  <HASHVAL>41ED02CDD04A0A7812F88AC60D5DA575203A513C</HASHVAL>
  <TEXT>ALTER TABLE NCONTT1 ADD CONSTRAINT PK_NCONTT1 PRIMARY KEY (CODCONTT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NCONT_BAK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT_BAK</REFTABLE>
  <HASHVAL>6B64BF9BD8A4B89603514DA218E1D5CE9D0CDB96</HASHVAL>
  <TEXT>ALTER TABLE NCONT_BAK ADD CONSTRAINT PK_NCONT_BAK PRIMARY KEY (CODCONT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NECESAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NECESAR</REFTABLE>
  <HASHVAL>C63BB7F8D907664CD839D319AA592A806525F2B9</HASHVAL>
  <TEXT>ALTER TABLE NECESAR ADD CONSTRAINT PK_NECESAR PRIMARY KEY (CODNECESAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NECHIV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NECHIV</REFTABLE>
  <HASHVAL>2076FF51FE9A26CE62FBA3D9DAEB00A05521832A</HASHVAL>
  <TEXT>ALTER TABLE NECHIV ADD CONSTRAINT PK_NECHIV PRIMARY KEY (CODECHIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NELEMAEROAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NELEMAEROAUTO</REFTABLE>
  <HASHVAL>F8F49832A61BE833FB5BE0E3381F7C211DBE6450</HASHVAL>
  <TEXT>ALTER TABLE NELEMAEROAUTO ADD CONSTRAINT PK_NELEMAEROAUTO PRIMARY KEY (CODELEMAEROAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NESTJURNAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NESTJURNAL</REFTABLE>
  <HASHVAL>B7318E9CE6A7C6E0E1607953D808ACE6CE45CBCA</HASHVAL>
  <TEXT>ALTER TABLE NESTJURNAL ADD CONSTRAINT PK_NESTJURNAL PRIMARY KEY (CODNESTJURNAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST</REFTABLE>
  <HASHVAL>9C162A0E70479FE2688D482D37D61A1AF0CEBA69</HASHVAL>
  <TEXT>ALTER TABLE NGEST ADD CONSTRAINT PK_NGEST PRIMARY KEY (CODGEST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NGEST1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST1</REFTABLE>
  <HASHVAL>A266307CCC107F3D48E34EF61A76D992708CF6C6</HASHVAL>
  <TEXT>ALTER TABLE NGEST1 ADD CONSTRAINT PK_NGEST1 PRIMARY KEY (CODGEST1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGRUPEAUTO</REFTABLE>
  <HASHVAL>08C5B43D57EEE9591FC61291C6F446CE02D8E822</HASHVAL>
  <TEXT>ALTER TABLE NGRUPEAUTO ADD CONSTRAINT PK_NGRUPEAUTO PRIMARY KEY (CODGRUPEAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NIMOB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIMOB</REFTABLE>
  <HASHVAL>C7EF50A03B3F7E0F6F4370CBF17745D363C8F9EE</HASHVAL>
  <TEXT>ALTER TABLE NIMOB ADD CONSTRAINT PK_NIMOB PRIMARY KEY (CODNIMOB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NINSTAUTO</REFTABLE>
  <HASHVAL>30E34119F304BBB1D45EC374FC6B551FC3D2AC10</HASHVAL>
  <TEXT>ALTER TABLE NINSTAUTO ADD CONSTRAINT PK_NINSTAUTO PRIMARY KEY (CODINSTAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NINTERVENTIIAUTO</REFTABLE>
  <HASHVAL>BBD0A41B412FF1764D384744E3EA9D1A054E07BC</HASHVAL>
  <TEXT>ALTER TABLE NINTERVENTIIAUTO ADD CONSTRAINT PK_NINTERVENTIIAUTO PRIMARY KEY (CODINTERVENTIIAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NINTRASTAT</REFTABLE>
  <HASHVAL>21B33D5D5829015F1F4F297E138E98665C36A989</HASHVAL>
  <TEXT>ALTER TABLE NINTRASTAT ADD CONSTRAINT PK_NINTRASTAT PRIMARY KEY (CODNINTRASTAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NIR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIR</REFTABLE>
  <HASHVAL>EAD0A8169A784DBD184867708551A04603171607</HASHVAL>
  <TEXT>ALTER TABLE NIR ADD CONSTRAINT PK_NIR PRIMARY KEY (CODNIR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NIRSER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSER</REFTABLE>
  <HASHVAL>4B9EE5A842C65751944DBF78F2E8337A5B3703B6</HASHVAL>
  <TEXT>ALTER TABLE NIRSER ADD CONSTRAINT PK_NIRSER PRIMARY KEY (CODNIRSER) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NIRSTOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC</REFTABLE>
  <HASHVAL>8EC097854C95BF86B1684A71534767E4C95D8953</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC ADD CONSTRAINT PK_NIRSTOC PRIMARY KEY (CODNIRSTOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NIRSTOC1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC1</REFTABLE>
  <HASHVAL>08BF76E268693787EBC69C6583DB818429BE3CE5</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC1 ADD CONSTRAINT PK_NIRSTOC1 PRIMARY KEY (CODNIRSTOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NJUDET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NJUDET</REFTABLE>
  <HASHVAL>4989F5D9F1EA025E04989A5C898710DCA02AA9C4</HASHVAL>
  <TEXT>ALTER TABLE NJUDET ADD CONSTRAINT PK_NJUDET PRIMARY KEY (CODJUDET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NLIMBA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLIMBA</REFTABLE>
  <HASHVAL>4E25DBDD8C2710D5E5FCC34C6EE68692C8854CF5</HASHVAL>
  <TEXT>ALTER TABLE NLIMBA ADD CONSTRAINT PK_NLIMBA PRIMARY KEY (CODLIMBA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NLIMCREDIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLIMCREDIT</REFTABLE>
  <HASHVAL>306E225A8610534B50F0F20AB411037C593C6C71</HASHVAL>
  <TEXT>ALTER TABLE NLIMCREDIT ADD CONSTRAINT PK_NLIMCREDIT PRIMARY KEY (CODLIMCREDIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NLOCALIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLOCALIT</REFTABLE>
  <HASHVAL>954339781898742A1836D433AA8E3BA57ED7DB0B</HASHVAL>
  <TEXT>ALTER TABLE NLOCALIT ADD CONSTRAINT PK_NLOCALIT PRIMARY KEY (CODLOCALIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NLOCATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLOCATII</REFTABLE>
  <HASHVAL>39D1C2208C21AAAAF9D483F03EBC1DD87E38A50A</HASHVAL>
  <TEXT>ALTER TABLE NLOCATII ADD CONSTRAINT PK_NLOCATII PRIMARY KEY (CODLOCATIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMAKETE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMAKETE</REFTABLE>
  <HASHVAL>6A8EF9E40550A3CDF34EFE73248DF3B9B8E77D6D</HASHVAL>
  <TEXT>ALTER TABLE NMAKETE ADD CONSTRAINT PK_NMAKETE PRIMARY KEY (CODMAKETA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMARCIAUTO</REFTABLE>
  <HASHVAL>A6D7ACA1ADBA8F68BE9538A4BBD187AA9D8689CC</HASHVAL>
  <TEXT>ALTER TABLE NMARCIAUTO ADD CONSTRAINT PK_NMARCIAUTO PRIMARY KEY (CODMARCIAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMESERII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMESERII</REFTABLE>
  <HASHVAL>A8584FF01497F1B0AFC7FAB193F7BB6F07E969A5</HASHVAL>
  <TEXT>ALTER TABLE NMESERII ADD CONSTRAINT PK_NMESERII PRIMARY KEY (CODMESERIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMODELEAUTO</REFTABLE>
  <HASHVAL>59761F578C57157C5F87E505926E0568FF8E5601</HASHVAL>
  <TEXT>ALTER TABLE NMODELEAUTO ADD CONSTRAINT PK_NMODELEAUTO PRIMARY KEY (CODMODELEAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMONEDE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMONEDE</REFTABLE>
  <HASHVAL>2927E05C7926FF550859EE716436959619974E2C</HASHVAL>
  <TEXT>ALTER TABLE NMONEDE ADD CONSTRAINT PK_NMONEDE PRIMARY KEY (CODMONEDA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMONEDE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMONEDE1</REFTABLE>
  <HASHVAL>529EB0A349EBF7B4A232174805EF86E9A515E950</HASHVAL>
  <TEXT>ALTER TABLE NMONEDE1 ADD CONSTRAINT PK_NMONEDE1 PRIMARY KEY (CODMONEDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NMVS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMVS</REFTABLE>
  <HASHVAL>1714A8D454A834110CF02A339F3D9272F09FCA45</HASHVAL>
  <TEXT>ALTER TABLE NMVS ADD CONSTRAINT PK_NMVS PRIMARY KEY (CODNMVS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NOPER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOPER</REFTABLE>
  <HASHVAL>0D9B18340298A037C1302E28BA5A945D1E6FB3C1</HASHVAL>
  <TEXT>ALTER TABLE NOPER ADD CONSTRAINT PK_NOPER PRIMARY KEY (CODOP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NOPER1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOPER1</REFTABLE>
  <HASHVAL>EA725DB7C3B41DAE64E504FFF8F705A267855533</HASHVAL>
  <TEXT>ALTER TABLE NOPER1 ADD CONSTRAINT PK_NOPER1 PRIMARY KEY (CODOP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NORMEMAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NORMEMAT</REFTABLE>
  <HASHVAL>F95FFCC350EFAE1B77E3E6A5557BCD3CEE39A811</HASHVAL>
  <TEXT>ALTER TABLE NORMEMAT ADD CONSTRAINT PK_NORMEMAT PRIMARY KEY (CODNORMEMAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOTECREDIT</REFTABLE>
  <HASHVAL>EE51FCBA73C45736CD84AF26E2A63AA5A0AFA007</HASHVAL>
  <TEXT>ALTER TABLE NOTECREDIT ADD CONSTRAINT PK_NOTECREDIT PRIMARY KEY (CODNCREDIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NOTECREDIT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOTECREDIT1</REFTABLE>
  <HASHVAL>B8A8024E58AFAEEB829920390791FD0C5BAC3B82</HASHVAL>
  <TEXT>ALTER TABLE NOTECREDIT1 ADD CONSTRAINT PK_NOTECREDIT1 PRIMARY KEY (CODNCREDIT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NOTECREDITFACT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOTECREDITFACT</REFTABLE>
  <HASHVAL>9AC4ECBC6B07BE78C51D88B2F65EEFF3A5E85DFB</HASHVAL>
  <TEXT>ALTER TABLE NOTECREDITFACT ADD CONSTRAINT PK_NOTECREDITFACT PRIMARY KEY (CODNCFACT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARC0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC0</REFTABLE>
  <HASHVAL>1994C6BF3FDBF66F43E8258D7133707C6CF5C404</HASHVAL>
  <TEXT>ALTER TABLE NPARC0 ADD CONSTRAINT PK_NPARC0 PRIMARY KEY (CODNPARC0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARC1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC1</REFTABLE>
  <HASHVAL>C0DB9CFBAA5FAA1638A539AF3EC6CD69CE324A4E</HASHVAL>
  <TEXT>ALTER TABLE NPARC1 ADD CONSTRAINT PK_NPARC1 PRIMARY KEY (CODNPARC1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARC2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC2</REFTABLE>
  <HASHVAL>18D99EE8EDBD491CFF2F039FCF05E075D67EB715</HASHVAL>
  <TEXT>ALTER TABLE NPARC2 ADD CONSTRAINT PK_NPARC2 PRIMARY KEY (CODNPARC2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARC3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC3</REFTABLE>
  <HASHVAL>38125C9FCF6F12D589D574D5C66BFEEBD5D48FB3</HASHVAL>
  <TEXT>ALTER TABLE NPARC3 ADD CONSTRAINT PK_NPARC3 PRIMARY KEY (CODNPARC3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARCAUT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>4AA04DCCF07452B122FA0E59F611CC11A88E90C7</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT PK_NPARCAUT PRIMARY KEY (CODNPARCAUT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARCCOM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCCOM</REFTABLE>
  <HASHVAL>7236BF2EAE9F3F3927DBAFF3A1DBFCF113D8F2FE</HASHVAL>
  <TEXT>ALTER TABLE NPARCCOM ADD CONSTRAINT PK_NPARCCOM PRIMARY KEY (CODNPARCCOM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARCG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCG</REFTABLE>
  <HASHVAL>6DBCEA4FAD1A74969E7F28C435E9C900AA2D303E</HASHVAL>
  <TEXT>ALTER TABLE NPARCG ADD CONSTRAINT PK_NPARCG PRIMARY KEY (CODNPARCG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPART</REFTABLE>
  <HASHVAL>764513B1ABC5011AD8159AE1E57D1FD85A67F164</HASHVAL>
  <TEXT>ALTER TABLE NPART ADD CONSTRAINT PK_NPART PRIMARY KEY (CODPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPART1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPART1</REFTABLE>
  <HASHVAL>D7CF4B1EF1CC229A67A6A042957F669E1FA6438A</HASHVAL>
  <TEXT>ALTER TABLE NPART1 ADD CONSTRAINT PK_NPART1 PRIMARY KEY (CODPART1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPART1CRM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPART1CRM</REFTABLE>
  <HASHVAL>7000A660674E4637A1DF6BE26E5B59692CC7AB9A</HASHVAL>
  <TEXT>ALTER TABLE NPART1CRM ADD CONSTRAINT PK_NPART1CRM PRIMARY KEY (CODPART1CRM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTACTIVIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTACTIVIT</REFTABLE>
  <HASHVAL>99B0A4B96C44876FE1DEACA9350238BD2660A878</HASHVAL>
  <TEXT>ALTER TABLE NPARTACTIVIT ADD CONSTRAINT PK_NPARTACTIVIT PRIMARY KEY (CODPARTACTIVIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTB</REFTABLE>
  <HASHVAL>FCA6DB76A72BCF9C54FF984CF2F1E2C52E6EE392</HASHVAL>
  <TEXT>ALTER TABLE NPARTB ADD CONSTRAINT PK_NPARTB PRIMARY KEY (CODPARTB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTCODFISC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTCODFISC</REFTABLE>
  <HASHVAL>3A363937FF84AB14EC45F918965EDCA43CD555F3</HASHVAL>
  <TEXT>ALTER TABLE NPARTCODFISC ADD CONSTRAINT PK_NPARTCODFISC PRIMARY KEY (COD_CODFISCAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTCONCURENTI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTCONCURENTI</REFTABLE>
  <HASHVAL>ABE9D738116BD2D77CF423D81C2CFBE09DF72129</HASHVAL>
  <TEXT>ALTER TABLE NPARTCONCURENTI ADD CONSTRAINT PK_NPARTCONCURENTI PRIMARY KEY (CODPARTCONCURENT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTDISC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTDISC</REFTABLE>
  <HASHVAL>B4C14DDA0E91052510EAF6847B8B2E7FDA314A41</HASHVAL>
  <TEXT>ALTER TABLE NPARTDISC ADD CONSTRAINT PK_NPARTDISC PRIMARY KEY (CODPARTDISC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTDOMACT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTDOMACT</REFTABLE>
  <HASHVAL>D5B56A0773FA066144C17FC7EB513DB53B360008</HASHVAL>
  <TEXT>ALTER TABLE NPARTDOMACT ADD CONSTRAINT PK_NPARTDOMACT PRIMARY KEY (CODPARTDOMACT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTLSTCLASE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTLSTCLASE</REFTABLE>
  <HASHVAL>FC55631909C8B126B2E4A97A6C13C8F9A7DB44C4</HASHVAL>
  <TEXT>ALTER TABLE NPARTLSTCLASE ADD CONSTRAINT PK_NPARTLSTCLASE PRIMARY KEY (CODNPARTLSTCLASE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTSOLDLUNA</REFTABLE>
  <HASHVAL>672CA50DA0E5B1696A585C270AB4230F12253409</HASHVAL>
  <TEXT>ALTER TABLE NPARTSOLDLUNA ADD CONSTRAINT PK_NPARTSOLDLUNA PRIMARY KEY (CODPARTSOLDLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTSUBUNIT</REFTABLE>
  <HASHVAL>8B663EC1879078D61C02100AE4CF75D86E6DE672</HASHVAL>
  <TEXT>ALTER TABLE NPARTSUBUNIT ADD CONSTRAINT PK_NPARTSUBUNIT PRIMARY KEY (CODPARTSUBUNIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPARTTR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTTR</REFTABLE>
  <HASHVAL>681C4C0413A6D41AB31242FA03259768C083E400</HASHVAL>
  <TEXT>ALTER TABLE NPARTTR ADD CONSTRAINT PK_NPARTTR PRIMARY KEY (CODPARTTR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERS</REFTABLE>
  <HASHVAL>B3696EC2451A9750FD6629D223959DDD49104114</HASHVAL>
  <TEXT>ALTER TABLE NPERS ADD CONSTRAINT PK_NPERS PRIMARY KEY (CODPERS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERS1</REFTABLE>
  <HASHVAL>301B02425EDC18984D2BCA5D95157E54190E3DB3</HASHVAL>
  <TEXT>ALTER TABLE NPERS1 ADD CONSTRAINT PK_NPERS1 PRIMARY KEY (CODPERS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCONTACT</REFTABLE>
  <HASHVAL>5942FFA57222911D5B2F7C57C6A25EF8B5A70BE4</HASHVAL>
  <TEXT>ALTER TABLE NPERSCONTACT ADD CONSTRAINT PK_NPERSCONTACT PRIMARY KEY (CODPERSC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCURS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCURS</REFTABLE>
  <HASHVAL>88E5EE48EF0C04E0691B68D8FD8F72AA7E35A636</HASHVAL>
  <TEXT>ALTER TABLE NPERSCURS ADD CONSTRAINT PK_NPERSCURS PRIMARY KEY (CODNPERSCURS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCVLOCM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCVLOCM</REFTABLE>
  <HASHVAL>02214DBCA197D316697BED2EFB9FE7596B694A49</HASHVAL>
  <TEXT>ALTER TABLE NPERSCVLOCM ADD CONSTRAINT PK_NPERSCVLOCM PRIMARY KEY (CODPERSCVLOCM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCVPAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCVPAS</REFTABLE>
  <HASHVAL>D0B2EA93191C554D098C6612E81F65ED189AAAFF</HASHVAL>
  <TEXT>ALTER TABLE NPERSCVPAS ADD CONSTRAINT PK_NPERSCVPAS PRIMARY KEY (CODPERSCVPAS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCVSCOL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCVSCOL</REFTABLE>
  <HASHVAL>984758C6E8BB20710C2AE8399AF9E43FA34070C0</HASHVAL>
  <TEXT>ALTER TABLE NPERSCVSCOL ADD CONSTRAINT PK_NPERSCVSCOL PRIMARY KEY (CODPERSCVSCOL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSCVSKIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSCVSKIL</REFTABLE>
  <HASHVAL>E3FB533773124C4CEB9E5D55767F4C22390D4924</HASHVAL>
  <TEXT>ALTER TABLE NPERSCVSKIL ADD CONSTRAINT PK_NPERSCVSKIL PRIMARY KEY (CODPERSCVSKIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NPERSSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERSSOLDLUNA</REFTABLE>
  <HASHVAL>E716C5A9DBE699000041DE1ECC7C2F3496C85E20</HASHVAL>
  <TEXT>ALTER TABLE NPERSSOLDLUNA ADD CONSTRAINT PK_NPERSSOLDLUNA PRIMARY KEY (CODPERSSOLDLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NREMAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NREMAUTO</REFTABLE>
  <HASHVAL>2D499EFE4B5D2BB261AF2A56DD2887328BF5F390</HASHVAL>
  <TEXT>ALTER TABLE NREMAUTO ADD CONSTRAINT PK_NREMAUTO PRIMARY KEY (CODREMAUTO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NRINVLOCK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NRINVLOCK</REFTABLE>
  <HASHVAL>C1E3A107A0551A4F50E6237CB89BAC4B8FA956CC</HASHVAL>
  <TEXT>ALTER TABLE NRINVLOCK ADD CONSTRAINT PK_NRINVLOCK PRIMARY KEY (CODINVLOCK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSCADTL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSCADTL</REFTABLE>
  <HASHVAL>4BE874A7DC86A14A3E188888F1B408639306AA09</HASHVAL>
  <TEXT>ALTER TABLE NSCADTL ADD CONSTRAINT PK_NSCADTL PRIMARY KEY (CODSCADTL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSCADTL1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSCADTL1</REFTABLE>
  <HASHVAL>75A0C3E307BF5F04520DB0202BBC48C67849AA28</HASHVAL>
  <TEXT>ALTER TABLE NSCADTL1 ADD CONSTRAINT PK_NSCADTL1 PRIMARY KEY (CODSCADTL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSEDIIPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSEDIIPARTRETAIL</REFTABLE>
  <HASHVAL>7C8ACD9513198A58C0BF83EAC64C5D9A39D38897</HASHVAL>
  <TEXT>ALTER TABLE NSEDIIPARTRETAIL ADD CONSTRAINT PK_NSEDIIPARTRETAIL PRIMARY KEY (CODSEDIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSERII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSERII</REFTABLE>
  <HASHVAL>836BB025027CDF1400321BD37E2A48DE8D856F0C</HASHVAL>
  <TEXT>ALTER TABLE NSERII ADD CONSTRAINT PK_NSERII PRIMARY KEY (CODSERIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSERTAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSERTAR</REFTABLE>
  <HASHVAL>B9005627602CC93AD10B7678815F0EC245416A24</HASHVAL>
  <TEXT>ALTER TABLE NSERTAR ADD CONSTRAINT PK_NSERTAR PRIMARY KEY (CODSERTAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSERTAR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSERTAR1</REFTABLE>
  <HASHVAL>12EC5F732D3DD66B8D8B110B9F43BF489867E089</HASHVAL>
  <TEXT>ALTER TABLE NSERTAR1 ADD CONSTRAINT PK_NSERTAR1 PRIMARY KEY (CODSERTAR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSUBUNIT</REFTABLE>
  <HASHVAL>64C5C811C3716C2818EB41C3DBB003C857245CBA</HASHVAL>
  <TEXT>ALTER TABLE NSUBUNIT ADD CONSTRAINT PK_NSUBUNIT PRIMARY KEY (CODSUBUNIT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NSUBUNIT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSUBUNIT1</REFTABLE>
  <HASHVAL>00EE747C34407CDF09804D1296BFE2500BB04621</HASHVAL>
  <TEXT>ALTER TABLE NSUBUNIT1 ADD CONSTRAINT PK_NSUBUNIT1 PRIMARY KEY (CODSUBUNIT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTARI</REFTABLE>
  <HASHVAL>0DEA26D54F1D4D58706A8FE0E12EBF14D63A9F89</HASHVAL>
  <TEXT>ALTER TABLE NTARI ADD CONSTRAINT PK_NTARI PRIMARY KEY (CODTARA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTAXE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTAXE</REFTABLE>
  <HASHVAL>2BB18CA7EE9D5180B3B78D7E6D8108C9A69441F3</HASHVAL>
  <TEXT>ALTER TABLE NTAXE ADD CONSTRAINT PK_NTAXE PRIMARY KEY (CODTAXA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTAXE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTAXE1</REFTABLE>
  <HASHVAL>FDDC0E342D8C83196E015F1D44369F029C9C09AC</HASHVAL>
  <TEXT>ALTER TABLE NTAXE1 ADD CONSTRAINT PK_NTAXE1 PRIMARY KEY (CODTAXA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTIPSEDII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTIPSEDII</REFTABLE>
  <HASHVAL>5F5DD3F846A85A4356BC8BFAA29602C31807C090</HASHVAL>
  <TEXT>ALTER TABLE NTIPSEDII ADD CONSTRAINT PK_NTIPSEDII PRIMARY KEY (CODTIPSEDIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTIPSEDII1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTIPSEDII1</REFTABLE>
  <HASHVAL>A630E450AA53CBBF6D98FBC2F2E4676651AF10E3</HASHVAL>
  <TEXT>ALTER TABLE NTIPSEDII1 ADD CONSTRAINT PK_NTIPSEDII1 PRIMARY KEY (CODTIPSEDIU1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA</REFTABLE>
  <HASHVAL>B77EFFCBBA4AF93FF0D487AA7149F81A20EF7BC7</HASHVAL>
  <TEXT>ALTER TABLE NTVA ADD CONSTRAINT PK_NTVA PRIMARY KEY (CODTVA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NTVA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA1</REFTABLE>
  <HASHVAL>65924F88CAD1B7648EACEAE90889E77BFB8C93AD</HASHVAL>
  <TEXT>ALTER TABLE NTVA1 ADD CONSTRAINT PK_NTVA1 PRIMARY KEY (CODTVA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NUM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NUM</REFTABLE>
  <HASHVAL>6764A70D0A864AF84B4B493BCD55414120D4992C</HASHVAL>
  <TEXT>ALTER TABLE NUM ADD CONSTRAINT PK_NUM PRIMARY KEY (CODUM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NUM1</REFTABLE>
  <HASHVAL>7F2C446FEED04DB704F18ABD69F45F7B48B5B01D</HASHVAL>
  <TEXT>ALTER TABLE NUM1 ADD CONSTRAINT PK_NUM1 PRIMARY KEY (CODUM1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_NZONE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NZONE</REFTABLE>
  <HASHVAL>9B303FF05871EBEC5A9DA2D0B924CCA184B76B42</HASHVAL>
  <TEXT>ALTER TABLE NZONE ADD CONSTRAINT PK_NZONE PRIMARY KEY (CODZONA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OBIECTIVE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OBIECTIVE</REFTABLE>
  <HASHVAL>55FCC29503F7977897C6747F5F87C9017A62E4C2</HASHVAL>
  <TEXT>ALTER TABLE OBIECTIVE ADD CONSTRAINT PK_OBIECTIVE PRIMARY KEY (CODOBIECTIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OBLIGPIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OBLIGPIF</REFTABLE>
  <HASHVAL>59005C5327C61CF55CDBAAB545C08240E62E221E</HASHVAL>
  <TEXT>ALTER TABLE OBLIGPIF ADD CONSTRAINT PK_OBLIGPIF PRIMARY KEY (CODOBLIGPIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OFERTA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA</REFTABLE>
  <HASHVAL>89458CB94401BBD6D5FB7EE409CF08831E4E2E74</HASHVAL>
  <TEXT>ALTER TABLE OFERTA ADD CONSTRAINT PK_OFERTA PRIMARY KEY (CODOFERTA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OFERTA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA1</REFTABLE>
  <HASHVAL>7098632D1053F8EEA16FB61A3A2CDC43F5E07B1E</HASHVAL>
  <TEXT>ALTER TABLE OFERTA1 ADD CONSTRAINT PK_OFERTA1 PRIMARY KEY (CODOFERTA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OPORTUNITATI</REFTABLE>
  <HASHVAL>AA86345D1479AD56B69A4A45984385DF10CBE6DE</HASHVAL>
  <TEXT>ALTER TABLE OPORTUNITATI ADD CONSTRAINT PK_OPORTUNITATI PRIMARY KEY (CODOPORTUNITATE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OPORTUNITATI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OPORTUNITATI1</REFTABLE>
  <HASHVAL>647CA214340E0F02AF5094B4A410F389EAC00238</HASHVAL>
  <TEXT>ALTER TABLE OPORTUNITATI1 ADD CONSTRAINT PK_OPORTUNITATI1 PRIMARY KEY (CODOPORTUNITATE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OPREG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OPREG</REFTABLE>
  <HASHVAL>EC4E9F9222E2A6CCCE56DB1E15E9196695C86C12</HASHVAL>
  <TEXT>ALTER TABLE OPREG ADD CONSTRAINT PK_OPREG PRIMARY KEY (CODOP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_OPREG1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OPREG1</REFTABLE>
  <HASHVAL>32134C0A3A046E2A72896D30A3B204D08B1BAB31</HASHVAL>
  <TEXT>ALTER TABLE OPREG1 ADD CONSTRAINT PK_OPREG1 PRIMARY KEY (CODOP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ORAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ORAR</REFTABLE>
  <HASHVAL>C0D310E33F775F67F3D1514CD72721AC2F2E6565</HASHVAL>
  <TEXT>ALTER TABLE ORAR ADD CONSTRAINT PK_ORAR PRIMARY KEY (CODORAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ORELM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ORELM</REFTABLE>
  <HASHVAL>3EEB6AFDF5F8E57998BC764BEAB949AEACBFC24C</HASHVAL>
  <TEXT>ALTER TABLE ORELM ADD CONSTRAINT PK_ORELM PRIMARY KEY (CODORELM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETE</REFTABLE>
  <HASHVAL>3A4CF722279B1C7DF756E974B093E9FD82E394CC</HASHVAL>
  <TEXT>ALTER TABLE PACHETE ADD CONSTRAINT PK_PACHETE PRIMARY KEY (CODPACHETE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETE1</REFTABLE>
  <HASHVAL>659D25DFD1D15A7BB096C6E3C1BE187E8FE2D4CE</HASHVAL>
  <TEXT>ALTER TABLE PACHETE1 ADD CONSTRAINT PK_PACHETE1 PRIMARY KEY (CODPACHETE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETEDLLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEDLLINK</REFTABLE>
  <HASHVAL>3B549A7B9A7198DD60B2778380DA19D18C88EE2D</HASHVAL>
  <TEXT>ALTER TABLE PACHETEDLLINK ADD CONSTRAINT PK_PACHETEDLLINK PRIMARY KEY (CODCOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETELINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETELINK</REFTABLE>
  <HASHVAL>4DB4D9D09FE042BF80D843910A3EFC2DC4909E2C</HASHVAL>
  <TEXT>ALTER TABLE PACHETELINK ADD CONSTRAINT PK_PACHETELINK PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEOBJ</REFTABLE>
  <HASHVAL>FC9E5F437BF730682C0894CD20AAE548D9ECF03A</HASHVAL>
  <TEXT>ALTER TABLE PACHETEOBJ ADD CONSTRAINT PK_PACHETEOBJ PRIMARY KEY (CODPACHETEOBJ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETEOBJL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEOBJL</REFTABLE>
  <HASHVAL>8F09CE19AAFD0AF9A3C398327E371130DD1CAB84</HASHVAL>
  <TEXT>ALTER TABLE PACHETEOBJL ADD CONSTRAINT PK_PACHETEOBJL PRIMARY KEY (CODPACHETEOBJL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACHETEOBJLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEOBJLINK</REFTABLE>
  <HASHVAL>8E4DC353F2DAC8FD24079D9801EDA79EE827E18A</HASHVAL>
  <TEXT>ALTER TABLE PACHETEOBJLINK ADD CONSTRAINT PK_PACHETEOBJLINK PRIMARY KEY (CODIES1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACKING</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING</REFTABLE>
  <HASHVAL>747957628244965DE171E86B239871E35109BCDD</HASHVAL>
  <TEXT>ALTER TABLE PACKING ADD CONSTRAINT PK_PACKING PRIMARY KEY (CODPACKING) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACKING1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING1</REFTABLE>
  <HASHVAL>69DBD7E0BA31F0B3463866134349CE4FE3F2A4A2</HASHVAL>
  <TEXT>ALTER TABLE PACKING1 ADD CONSTRAINT PK_PACKING1 PRIMARY KEY (CODPACKING1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACKING2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING2</REFTABLE>
  <HASHVAL>B910D6317E0B3B744C27FAD17F2ADC34C3B995FF</HASHVAL>
  <TEXT>ALTER TABLE PACKING2 ADD CONSTRAINT PK_PACKING2 PRIMARY KEY (CODPACKING2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PACKING3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING3</REFTABLE>
  <HASHVAL>C7F74398302635F1C4A299B01DF45583DD6F96F7</HASHVAL>
  <TEXT>ALTER TABLE PACKING3 ADD CONSTRAINT PK_PACKING3 PRIMARY KEY (CODPACKING3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PARAMLISTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PARAMLISTE</REFTABLE>
  <HASHVAL>E5AD6B00B301565AB55EA864DDDC4AFC9B038DA6</HASHVAL>
  <TEXT>ALTER TABLE PARAMLISTE ADD CONSTRAINT PK_PARAMLISTE PRIMARY KEY (CODPARAMLISTE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PARTTOT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PARTTOT</REFTABLE>
  <HASHVAL>82921FEC8D26E44E4100AE6998328FD160D34BEF</HASHVAL>
  <TEXT>ALTER TABLE PARTTOT ADD CONSTRAINT PK_PARTTOT PRIMARY KEY (CODPARTTOT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PCALCUL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PCALCUL</REFTABLE>
  <HASHVAL>4707076CFB26849313771394CD56BD55684063D6</HASHVAL>
  <TEXT>ALTER TABLE PCALCUL ADD CONSTRAINT PK_PCALCUL PRIMARY KEY (CODPC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PCART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PCART</REFTABLE>
  <HASHVAL>6AD03EF4338862FF1D115C856B1FEFD0134C0551</HASHVAL>
  <TEXT>ALTER TABLE PCART ADD CONSTRAINT PK_PCART PRIMARY KEY (CODPCART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PCDIR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PCDIR</REFTABLE>
  <HASHVAL>989D84DECD4656A8E147274CA4E68CF3578A8275</HASHVAL>
  <TEXT>ALTER TABLE PCDIR ADD CONSTRAINT PK_PCDIR PRIMARY KEY (CODPCDIR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PCGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PCGEST</REFTABLE>
  <HASHVAL>000A790E103F363F5243C3417436B43CDD057EF2</HASHVAL>
  <TEXT>ALTER TABLE PCGEST ADD CONSTRAINT PK_PCGEST PRIMARY KEY (CODPCGEST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PCSECTII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PCSECTII</REFTABLE>
  <HASHVAL>C08F29A8F024EA868C4A794D04D07DF4EE78D657</HASHVAL>
  <TEXT>ALTER TABLE PCSECTII ADD CONSTRAINT PK_PCSECTII PRIMARY KEY (CODPCSECTII) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PERISABIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PERISABIL</REFTABLE>
  <HASHVAL>6E198A3144EA2B3FF45CEB819C1AF7AB317B42D5</HASHVAL>
  <TEXT>ALTER TABLE PERISABIL ADD CONSTRAINT PK_PERISABIL PRIMARY KEY (CODPERISABIL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PERISABIL1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PERISABIL1</REFTABLE>
  <HASHVAL>D0B2C80350BEBD288FADA851F83BF06414EF3DBE</HASHVAL>
  <TEXT>ALTER TABLE PERISABIL1 ADD CONSTRAINT PK_PERISABIL1 PRIMARY KEY (CODPERISABIL1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PERISABIL2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PERISABIL2</REFTABLE>
  <HASHVAL>307AAC3C988CB83BCC0C33FB305C7DDBEDDAD575</HASHVAL>
  <TEXT>ALTER TABLE PERISABIL2 ADD CONSTRAINT PK_PERISABIL2 PRIMARY KEY (CODPERISABIL2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PGS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PGS</REFTABLE>
  <HASHVAL>B18166506A241489A2E4153E388664A2F92D2F0C</HASHVAL>
  <TEXT>ALTER TABLE PGS ADD CONSTRAINT PK_PGS PRIMARY KEY (CODPGS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PGS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PGS1</REFTABLE>
  <HASHVAL>80195315AD55F40F4C859E23D842FC606140CE8B</HASHVAL>
  <TEXT>ALTER TABLE PGS1 ADD CONSTRAINT PK_PGS1 PRIMARY KEY (CODPGS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLANCURS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANCURS</REFTABLE>
  <HASHVAL>9D9F899D2AAAAF5E498FF13BC5FF65F5ED4A4E8C</HASHVAL>
  <TEXT>ALTER TABLE PLANCURS ADD CONSTRAINT PK_PLANCURS PRIMARY KEY (CODPLANCURS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLANCURS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANCURS1</REFTABLE>
  <HASHVAL>BA0E3FF021370559C3DEA5B692DFF0265DA49B71</HASHVAL>
  <TEXT>ALTER TABLE PLANCURS1 ADD CONSTRAINT PK_PLANCURS1 PRIMARY KEY (CODPLANCURS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLANIFNOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFNOD</REFTABLE>
  <HASHVAL>AB202DABC545C89D405AC2EF5FF5707DBB7D1F0F</HASHVAL>
  <TEXT>ALTER TABLE PLANIFNOD ADD CONSTRAINT PK_PLANIFNOD PRIMARY KEY (CODPLANIFNOD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFPROD</REFTABLE>
  <HASHVAL>CD58B3B7C116A33241E3BCC4BCD2F4D66705FDEE</HASHVAL>
  <TEXT>ALTER TABLE PLANIFPROD ADD CONSTRAINT PK_PLANIFPROD PRIMARY KEY (CODPLANIFPROD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLANIFPROD1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFPROD1</REFTABLE>
  <HASHVAL>72FDD1F9FAF5DF5A7B0E7CE0CC3B6B9152883768</HASHVAL>
  <TEXT>ALTER TABLE PLANIFPROD1 ADD CONSTRAINT PK_PLANIFPROD1 PRIMARY KEY (CODPLANIFPROD1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_POSBANCAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>POSBANCAR</REFTABLE>
  <HASHVAL>ACD4A3964540361C555A4953A26C0600FDD6F7E1</HASHVAL>
  <TEXT>ALTER TABLE POSBANCAR ADD CONSTRAINT PK_POSBANCAR PRIMARY KEY (CODPOSBANCAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PPLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PPLINK</REFTABLE>
  <HASHVAL>511405A2844E18B8AF53FCB8D6912EFCADD35951</HASHVAL>
  <TEXT>ALTER TABLE PPLINK ADD CONSTRAINT PK_PPLINK PRIMARY KEY (IDINREG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRECMDLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECMDLINK</REFTABLE>
  <HASHVAL>22B77613116137AF74009795AB5447942B9289A5</HASHVAL>
  <TEXT>ALTER TABLE PRECMDLINK ADD CONSTRAINT PK_PRECMDLINK PRIMARY KEY (CODCOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECOMANDA</REFTABLE>
  <HASHVAL>8822750CE45EF6123DD49CBECDB378EF65E83AE0</HASHVAL>
  <TEXT>ALTER TABLE PRECOMANDA ADD CONSTRAINT PK_PRECOMANDA PRIMARY KEY (CODPRECOMANDA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRECOMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECOMANDA1</REFTABLE>
  <HASHVAL>5FB9FDF549B441DCCF96BA206A0C16FC0509B14B</HASHVAL>
  <TEXT>ALTER TABLE PRECOMANDA1 ADD CONSTRAINT PK_PRECOMANDA1 PRIMARY KEY (CODPRECOMANDA1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PREDARIPLUS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PREDARIPLUS</REFTABLE>
  <HASHVAL>61976D7192C683DBD784247945F57C03A0AF2FB1</HASHVAL>
  <TEXT>ALTER TABLE PREDARIPLUS ADD CONSTRAINT PK_PREDARIPLUS PRIMARY KEY (IDINREG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRESTATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRESTATII</REFTABLE>
  <HASHVAL>E22B166DF740FBEA5BD316E398ADC1465AF0094D</HASHVAL>
  <TEXT>ALTER TABLE PRESTATII ADD CONSTRAINT PK_PRESTATII PRIMARY KEY (CODPRESTATIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRETM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRETM</REFTABLE>
  <HASHVAL>9206EC79F734C4B7F783D85E4C118DAB04A2EC0A</HASHVAL>
  <TEXT>ALTER TABLE PRETM ADD CONSTRAINT PK_PRETM PRIMARY KEY (CODPRETM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRETMAMB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRETMAMB</REFTABLE>
  <HASHVAL>FF78B765FA73DCACD23CC737E51D14B1382D40E7</HASHVAL>
  <TEXT>ALTER TABLE PRETMAMB ADD CONSTRAINT PK_PRETMAMB PRIMARY KEY (CODPRETMAMB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRETM_UPDATE_LOG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRETM_AUTOUPD_LOG</REFTABLE>
  <HASHVAL>3D7D4B0A0A0A9E5DBF43341AC0201A9B9C1B0755</HASHVAL>
  <TEXT>ALTER TABLE PRETM_AUTOUPD_LOG ADD CONSTRAINT PK_PRETM_UPDATE_LOG PRIMARY KEY (COD_MONEDA,COD_BANCA,RUN_DATE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODCOMP</REFTABLE>
  <HASHVAL>26B923958D39C5A68B74D7E9FC3F491E55C67AEA</HASHVAL>
  <TEXT>ALTER TABLE PRODCOMP ADD CONSTRAINT PK_PRODCOMP PRIMARY KEY (CODPRODCOMP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODGEST</REFTABLE>
  <HASHVAL>F97BAC8AC633E6FCFF52F1B2849AA160AFACC1B8</HASHVAL>
  <TEXT>ALTER TABLE PRODGEST ADD CONSTRAINT PK_PRODGEST PRIMARY KEY (CODPRODGEST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAN</REFTABLE>
  <HASHVAL>BAB74480D0AAA673062789100193431C38C5BA0A</HASHVAL>
  <TEXT>ALTER TABLE PRODMAN ADD CONSTRAINT PK_PRODMAN PRIMARY KEY (CODMAN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODMAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAS</REFTABLE>
  <HASHVAL>E5F7E9D3A4115C9F929744E3E15E6A40D97D4052</HASHVAL>
  <TEXT>ALTER TABLE PRODMAS ADD CONSTRAINT PK_PRODMAS PRIMARY KEY (CODPRODMAS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODMAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAT</REFTABLE>
  <HASHVAL>4E788BA43CEEAE3BDE152F2A5B43C709B88AA8AC</HASHVAL>
  <TEXT>ALTER TABLE PRODMAT ADD CONSTRAINT PK_PRODMAT PRIMARY KEY (CODMAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODMATECHIV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMATECHIV</REFTABLE>
  <HASHVAL>284662CDCAAC48E1D8CA0834C3ADDF08EF5620A7</HASHVAL>
  <TEXT>ALTER TABLE PRODMATECHIV ADD CONSTRAINT PK_PRODMATECHIV PRIMARY KEY (CODMATECHIV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODNET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODNET</REFTABLE>
  <HASHVAL>4204A1EB98CDF213DFB9A3BA9A3900CE1114C22C</HASHVAL>
  <TEXT>ALTER TABLE PRODNET ADD CONSTRAINT PK_PRODNET PRIMARY KEY (CODPRODNET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODNET1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODNET1</REFTABLE>
  <HASHVAL>D2D01C6ED73105DDCCFE3C148C139366A3E1ADF9</HASHVAL>
  <TEXT>ALTER TABLE PRODNET1 ADD CONSTRAINT PK_PRODNET1 PRIMARY KEY (CODPRODNET1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODNORME</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODNORME</REFTABLE>
  <HASHVAL>8F36A2BD8216E249C24B4520D6487483034FCF2C</HASHVAL>
  <TEXT>ALTER TABLE PRODNORME ADD CONSTRAINT PK_PRODNORME PRIMARY KEY (CODNORMA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODREZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODREZ</REFTABLE>
  <HASHVAL>D2D2EEA4EBC97AC7745AE949CAE987A4DE37524E</HASHVAL>
  <TEXT>ALTER TABLE PRODREZ ADD CONSTRAINT PK_PRODREZ PRIMARY KEY (CODREZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PRODSDV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODSDV</REFTABLE>
  <HASHVAL>69724C1B097495FB79D02591D213C1C9C451A8E1</HASHVAL>
  <TEXT>ALTER TABLE PRODSDV ADD CONSTRAINT PK_PRODSDV PRIMARY KEY (CODPRODSDV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF</REFTABLE>
  <HASHVAL>F9392066507068A06A64CCA68F33E3DE92D34DEA</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF ADD CONSTRAINT PK_PROGRAMF PRIMARY KEY (CODPROGRAMF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROGRAMF1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF1</REFTABLE>
  <HASHVAL>80D2AB32B6D43844CDC7C2134618E88CCAC47610</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF1 ADD CONSTRAINT PK_PROGRAMF1 PRIMARY KEY (CODPROGRAMF1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROGRAMFLMC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMFLMC</REFTABLE>
  <HASHVAL>D956E33B9115772D5832A82C706BA57EFB84AC2C</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMFLMC ADD CONSTRAINT PK_PROGRAMFLMC PRIMARY KEY (CODLMC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROGRAMFMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMFMAN</REFTABLE>
  <HASHVAL>00736B80FCA2EC2360C4A0EA2DDDD273E8F578A6</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMFMAN ADD CONSTRAINT PK_PROGRAMFMAN PRIMARY KEY (CODPFMAN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROGRAMFSDV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMFSDV</REFTABLE>
  <HASHVAL>6B8792B562E939CA805ECE653A972FE59928FAC5</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMFSDV ADD CONSTRAINT PK_PROGRAMFSDV PRIMARY KEY (CODPROGRAMFSDV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROIECT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECT</REFTABLE>
  <HASHVAL>9E20F1A031E0B5FB536485A7E63C28BE68DBEA2F</HASHVAL>
  <TEXT>ALTER TABLE PROIECT ADD CONSTRAINT PK_PROIECT PRIMARY KEY (CODPROIECT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROIECTCRM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECTCRM</REFTABLE>
  <HASHVAL>06462092A3C5595946187924018E8D699806853B</HASHVAL>
  <TEXT>ALTER TABLE PROIECTCRM ADD CONSTRAINT PK_PROIECTCRM PRIMARY KEY (CODPROIECTCRM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECTNOD</REFTABLE>
  <HASHVAL>2462B0C104F02088C01E2D6A689F19B7552C0FBA</HASHVAL>
  <TEXT>ALTER TABLE PROIECTNOD ADD CONSTRAINT PK_PROIECTNOD PRIMARY KEY (CODPROIECTNOD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMO</REFTABLE>
  <HASHVAL>AF717649BF53715F6F2486200F113FA831CE43B0</HASHVAL>
  <TEXT>ALTER TABLE PROMO ADD CONSTRAINT PK_PROMO PRIMARY KEY (CODPROMO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMO1CADOUSER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMO1CADOUSER</REFTABLE>
  <HASHVAL>D57AAA083256AE0264772846A8ACB5F5D6A92C20</HASHVAL>
  <TEXT>ALTER TABLE PROMO1CADOUSER ADD CONSTRAINT PK_PROMO1CADOUSER PRIMARY KEY (CODCADOUS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMO1SER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMO1SER</REFTABLE>
  <HASHVAL>F46AD044995F987229421B342B9A770939F3971D</HASHVAL>
  <TEXT>ALTER TABLE PROMO1SER ADD CONSTRAINT PK_PROMO1SER PRIMARY KEY (CODPROMO1S) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMOPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOPART</REFTABLE>
  <HASHVAL>6B0EEAD560EA0758836D46822BAC98A8BCE6EC82</HASHVAL>
  <TEXT>ALTER TABLE PROMOPART ADD CONSTRAINT PK_PROMOPART PRIMARY KEY (CODPROMOPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMOPRAG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOPRAG</REFTABLE>
  <HASHVAL>23C1CD5C8B0BA3ED127EA00354F13FBEEC3E4A4F</HASHVAL>
  <TEXT>ALTER TABLE PROMOPRAG ADD CONSTRAINT PK_PROMOPRAG PRIMARY KEY (CODPRAG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PROMOSUB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOSUB</REFTABLE>
  <HASHVAL>3EEBB83F44990683767984ADEDEF4FE4AB20A5D2</HASHVAL>
  <TEXT>ALTER TABLE PROMOSUB ADD CONSTRAINT PK_PROMOSUB PRIMARY KEY (CODPROMOSUB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PUNCTAJE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PUNCTAJE</REFTABLE>
  <HASHVAL>330CCAFEABD8B33586F1E3751101D787C08BFF61</HASHVAL>
  <TEXT>ALTER TABLE PUNCTAJE ADD CONSTRAINT PK_PUNCTAJE PRIMARY KEY (CODPUNCTAJ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_CATP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_CATP</REFTABLE>
  <HASHVAL>032567E1D26B6E9C1DE4826BD5CBFCF07E6F3C4F</HASHVAL>
  <TEXT>ALTER TABLE RAC_CATP ADD CONSTRAINT PK_RAC_CATP PRIMARY KEY (CODRAC_CATP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_CATP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_CATP1</REFTABLE>
  <HASHVAL>A8AF90B20AF76C33526995B53210DCF82ED46473</HASHVAL>
  <TEXT>ALTER TABLE RAC_CATP1 ADD CONSTRAINT PK_RAC_CATP1 PRIMARY KEY (CODRAC_CATP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_CATP2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_CATP2</REFTABLE>
  <HASHVAL>204B68F7FD79C39B911B3D48A6B099A7DC338FCC</HASHVAL>
  <TEXT>ALTER TABLE RAC_CATP2 ADD CONSTRAINT PK_RAC_CATP2 PRIMARY KEY (CODRAC_CATP2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_P</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_P</REFTABLE>
  <HASHVAL>E452EEEAE2A007CD35EA7E62205C4CD1AA246C5A</HASHVAL>
  <TEXT>ALTER TABLE RAC_P ADD CONSTRAINT PK_RAC_P PRIMARY KEY (CODRAC_P) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_P0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_P0</REFTABLE>
  <HASHVAL>E3B7C9750331FBC4EC1E5BE5A7511667082CD5B2</HASHVAL>
  <TEXT>ALTER TABLE RAC_P0 ADD CONSTRAINT PK_RAC_P0 PRIMARY KEY (CODRAC_P0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_P1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_P1</REFTABLE>
  <HASHVAL>4341CDD0F94850BD9AA5142EE8757E407BA837BE</HASHVAL>
  <TEXT>ALTER TABLE RAC_P1 ADD CONSTRAINT PK_RAC_P1 PRIMARY KEY (CODRAC_P1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAC_REZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAC_REZ</REFTABLE>
  <HASHVAL>3437236CCC834BFE340E3C5798FC0EB5455BCD26</HASHVAL>
  <TEXT>ALTER TABLE RAC_REZ ADD CONSTRAINT PK_RAC_REZ PRIMARY KEY (CODRAC_REZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP</REFTABLE>
  <HASHVAL>A19810FDB07EB2695D53566AFCF23EFE80035FE5</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP ADD CONSTRAINT PK_RAPORTP PRIMARY KEY (CODRAPORTP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPORTP0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP0</REFTABLE>
  <HASHVAL>507213B443C9C3C48C025F9CC734369B4E3F7931</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP0 ADD CONSTRAINT PK_RAPORTP0 PRIMARY KEY (CODRAPORTP0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPORTP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP1</REFTABLE>
  <HASHVAL>213DC0162B5E0E0D2DB93104873A65CCAB9BC59A</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP1 ADD CONSTRAINT PK_RAPORTP1 PRIMARY KEY (CODRAPORTP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPORTP2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP2</REFTABLE>
  <HASHVAL>C8107893B122B1A9DD77C74B62A61AE8C0070312</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP2 ADD CONSTRAINT PK_RAPORTP2 PRIMARY KEY (CODRAPORTP2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPORTP3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP3</REFTABLE>
  <HASHVAL>88141B20B299D984608044D18B950671C39C56B2</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP3 ADD CONSTRAINT PK_RAPORTP3 PRIMARY KEY (CODRAPORTP3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RAPSTOCMEDIST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPSTOCMEDIST</REFTABLE>
  <HASHVAL>947F66068696D8BED8F9B5B3757F20271C1DF163</HASHVAL>
  <TEXT>ALTER TABLE RAPSTOCMEDIST ADD CONSTRAINT PK_RAPSTOCMEDIST PRIMARY KEY (CODRAPMEDIST) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RECLAMATII</REFTABLE>
  <HASHVAL>7A92827538B0E7651EF5A7D771E2D1A087E3CF7D</HASHVAL>
  <TEXT>ALTER TABLE RECLAMATII ADD CONSTRAINT PK_RECLAMATII PRIMARY KEY (CODRECLAMATIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RECLAMATII1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RECLAMATII1</REFTABLE>
  <HASHVAL>734C3660B299EE4B7F22A710BCDA81A4307B0562</HASHVAL>
  <TEXT>ALTER TABLE RECLAMATII1 ADD CONSTRAINT PK_RECLAMATII1 PRIMARY KEY (CODRECLAMATIE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RECLAMATII2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RECLAMATII2</REFTABLE>
  <HASHVAL>E21BC30F0B881629B9B0ACEBE091D70C3DD2A0DC</HASHVAL>
  <TEXT>ALTER TABLE RECLAMATII2 ADD CONSTRAINT PK_RECLAMATII2 PRIMARY KEY (CODRECLAMATIE2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REG</REFTABLE>
  <HASHVAL>279CA26B436E1DEF26C61FA3057F61827DE53585</HASHVAL>
  <TEXT>ALTER TABLE REG ADD CONSTRAINT PK_REG PRIMARY KEY (CODREG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REG1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REG1</REFTABLE>
  <HASHVAL>98DA00CBAEB2A442380380B79B890D170AD32032</HASHVAL>
  <TEXT>ALTER TABLE REG1 ADD CONSTRAINT PK_REG1 PRIMARY KEY (CODREG1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REGLEAS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGLEAS1</REFTABLE>
  <HASHVAL>5AEC208F698DF666AE33D2489A4CC5ED4C480C45</HASHVAL>
  <TEXT>ALTER TABLE REGLEAS1 ADD CONSTRAINT PK_REGLEAS1 PRIMARY KEY (CODREGLEAS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REGOSS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGOSS</REFTABLE>
  <HASHVAL>E9DFF3D7D147124FB486C96498EAF296584C0C9C</HASHVAL>
  <TEXT>ALTER TABLE REGOSS ADD CONSTRAINT PK_REGOSS PRIMARY KEY (CODREGOSS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REGOSS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGOSS1</REFTABLE>
  <HASHVAL>B3C3E5F90D4020BD7308CCB420C2DE47FDBFC8B7</HASHVAL>
  <TEXT>ALTER TABLE REGOSS1 ADD CONSTRAINT PK_REGOSS1 PRIMARY KEY (CODREGOSS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REGPERS1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGPERS1</REFTABLE>
  <HASHVAL>6722650803991295F67AB5C43B782FE8D1194BB3</HASHVAL>
  <TEXT>ALTER TABLE REGPERS1 ADD CONSTRAINT PK_REGPERS1 PRIMARY KEY (CODREGPERS1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REGTREZOR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGTREZOR1</REFTABLE>
  <HASHVAL>41EA853EAC1FBD7355F52ECD27FC4E9FD39B7BE0</HASHVAL>
  <TEXT>ALTER TABLE REGTREZOR1 ADD CONSTRAINT PK_REGTREZOR1 PRIMARY KEY (CODREGTREZOR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RESTARTINACTIVE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RESTARTINACTIVE</REFTABLE>
  <HASHVAL>AF156CC47D700D8AAEC13D376765C356743D224A</HASHVAL>
  <TEXT>ALTER TABLE RESTARTINACTIVE ADD CONSTRAINT PK_RESTARTINACTIVE PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RESTAURANTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RESTAURANTE</REFTABLE>
  <HASHVAL>202EC3BBD00CDC7EC03CD7C7A2A1666EA6134741</HASHVAL>
  <TEXT>ALTER TABLE RESTAURANTE ADD CONSTRAINT PK_RESTAURANTE PRIMARY KEY (CODRESTAURANT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RESTOBSART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RESTOBSART</REFTABLE>
  <HASHVAL>90961705B40DC57D93318C8CE9913BDD68840EC3</HASHVAL>
  <TEXT>ALTER TABLE RESTOBSART ADD CONSTRAINT PK_RESTOBSART PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RETURO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RETURO</REFTABLE>
  <HASHVAL>13B0E69B195031086690CDF43FE36850FD6432BE</HASHVAL>
  <TEXT>ALTER TABLE RETURO ADD CONSTRAINT PK_RETURO PRIMARY KEY (CODRETURO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_RETUROSTINS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RETUROSTINS</REFTABLE>
  <HASHVAL>57C31C978E7A4ADA792A5898D526531924FD0B27</HASHVAL>
  <TEXT>ALTER TABLE RETUROSTINS ADD CONSTRAINT PK_RETUROSTINS PRIMARY KEY (CODRETUROSTINS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_REZERVATS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REZERVATS</REFTABLE>
  <HASHVAL>C5E92589645E54B3C1347A35465EC757067E3575</HASHVAL>
  <TEXT>ALTER TABLE REZERVATS ADD CONSTRAINT PK_REZERVATS PRIMARY KEY (CODREZERVATS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SABLONDESCRIPT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SABLONDESCRIPT</REFTABLE>
  <HASHVAL>7E498EEAE77611D5DA15E0A476A809AFCDFFCAF0</HASHVAL>
  <TEXT>ALTER TABLE SABLONDESCRIPT ADD CONSTRAINT PK_SABLONDESCRIPT PRIMARY KEY (CODSABLON) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SABLONDESCRIPT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SABLONDESCRIPT1</REFTABLE>
  <HASHVAL>4D0C49715ED7C4CF8148E49C29B5BDCCFDF6050F</HASHVAL>
  <TEXT>ALTER TABLE SABLONDESCRIPT1 ADD CONSTRAINT PK_SABLONDESCRIPT1 PRIMARY KEY (CODSABLON1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAFTCOL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAFTCOL</REFTABLE>
  <HASHVAL>390BEDBF14C8FE73422EDE0C6B689906E5C81FEB</HASHVAL>
  <TEXT>ALTER TABLE SAFTCOL ADD CONSTRAINT PK_SAFTCOL PRIMARY KEY (CODSAFTTAB,IDXLOCAL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAFTTAB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAFTTAB</REFTABLE>
  <HASHVAL>A27E6430D3111081DC85E29CB02BC2CF8B5F6A99</HASHVAL>
  <TEXT>ALTER TABLE SAFTTAB ADD CONSTRAINT PK_SAFTTAB PRIMARY KEY (CODSAFTTAB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SALI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SALI</REFTABLE>
  <HASHVAL>554D5B1A65C1C1CB0C226DCDF0428A2A03AFB9B8</HASHVAL>
  <TEXT>ALTER TABLE SALI ADD CONSTRAINT PK_SALI PRIMARY KEY (CODSALA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_CATRET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_CATRET</REFTABLE>
  <HASHVAL>1B16F1069D22EAE52420501A89BFBCCC76282C2A</HASHVAL>
  <TEXT>ALTER TABLE SAL_CATRET ADD CONSTRAINT PK_SAL_CATRET PRIMARY KEY (CODCATRET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_CATSPOR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_CATSPOR</REFTABLE>
  <HASHVAL>081EB6689D6609F41A98FB8CEAAF9902FA945A8D</HASHVAL>
  <TEXT>ALTER TABLE SAL_CATSPOR ADD CONSTRAINT PK_SAL_CATSPOR PRIMARY KEY (CODCATSPOR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_CONTRPP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_CONTRPP</REFTABLE>
  <HASHVAL>89F2166CD4BC8F6609237408DAE9F06757C902E7</HASHVAL>
  <TEXT>ALTER TABLE SAL_CONTRPP ADD CONSTRAINT PK_SAL_CONTRPP PRIMARY KEY (CODCONTRPP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_CONTRPP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_CONTRPP1</REFTABLE>
  <HASHVAL>83D38FBE0E1784A7AAC2DA817672F35F6AFD1779</HASHVAL>
  <TEXT>ALTER TABLE SAL_CONTRPP1 ADD CONSTRAINT PK_SAL_CONTRPP1 PRIMARY KEY (CODCONTRPP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_DEDGEN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN</REFTABLE>
  <HASHVAL>67CB5393C9FFAEB43043BC68A841B64250CB676A</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN ADD CONSTRAINT PK_SAL_DEDGEN PRIMARY KEY (CODDEDGEN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_DEDGEN0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN0</REFTABLE>
  <HASHVAL>E4C4ED654DA2441F02F88BB599E342A63A266A03</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN0 ADD CONSTRAINT PK_SAL_DEDGEN0 PRIMARY KEY (CODDEDGEN0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_DEDGEN1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN1</REFTABLE>
  <HASHVAL>E340DFC16BE4C2748EE7A619820BE5D4A3BDEAF3</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN1 ADD CONSTRAINT PK_SAL_DEDGEN1 PRIMARY KEY (CODDEDGEN1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_FONDP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_FONDP</REFTABLE>
  <HASHVAL>A2AAB1522956318B7726647AFBD4571C597069DF</HASHVAL>
  <TEXT>ALTER TABLE SAL_FONDP ADD CONSTRAINT PK_SAL_FONDP PRIMARY KEY (CODFONDP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_IMPOZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ</REFTABLE>
  <HASHVAL>752BBBB25DF9D7B9EEA036854AD4FA9D648DE153</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ ADD CONSTRAINT PK_SAL_IMPOZ PRIMARY KEY (CODIMPOZ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_IMPOZ0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ0</REFTABLE>
  <HASHVAL>9F8DC260C295796D19B19A5BF4BCD346044A711B</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ0 ADD CONSTRAINT PK_SAL_IMPOZ0 PRIMARY KEY (CODIMPOZ0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_IMPOZ1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ1</REFTABLE>
  <HASHVAL>AF8CA5D12B99CB1118733FD0911C08192FA8A70F</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ1 ADD CONSTRAINT PK_SAL_IMPOZ1 PRIMARY KEY (CODIMPOZ1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_INTRERUP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_INTRERUP</REFTABLE>
  <HASHVAL>653D16E1ADBBEAA271A3BACC0B848D7FFBA1AB63</HASHVAL>
  <TEXT>ALTER TABLE SAL_INTRERUP ADD CONSTRAINT PK_SAL_INTRERUP PRIMARY KEY (CODINTRERUP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NASIG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG</REFTABLE>
  <HASHVAL>2654AA1D99177590F054594A6754F92B21CA9C20</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG ADD CONSTRAINT PK_SAL_NASIG PRIMARY KEY (CODNASIG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NASIG0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG0</REFTABLE>
  <HASHVAL>7CB6B0B6E8A47E2CEED6687A5B2686D0F6EA0189</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG0 ADD CONSTRAINT PK_SAL_NASIG0 PRIMARY KEY (CODNASIG0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NASIG1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG1</REFTABLE>
  <HASHVAL>28E073D19878DE04989F43780E2881DB9B3E7685</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG1 ADD CONSTRAINT PK_SAL_NASIG1 PRIMARY KEY (CODNASIG1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NASIG2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG2</REFTABLE>
  <HASHVAL>C56B138FE29A5D3824068849FBDF25D67FCC6CF2</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG2 ADD CONSTRAINT PK_SAL_NASIG2 PRIMARY KEY (CODNASIG2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NASIG3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG3</REFTABLE>
  <HASHVAL>298EB64A02F5A205AE31866BBB66136E81D932F4</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG3 ADD CONSTRAINT PK_SAL_NASIG3 PRIMARY KEY (CODNASIG3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NCONTRIB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB</REFTABLE>
  <HASHVAL>595656A5FCFDD12481AF8259FACFD4A84D478711</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB ADD CONSTRAINT PK_SAL_NCONTRIB PRIMARY KEY (CODNCONTRIB) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NCONTRIB1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>ED05DDFF657C742DAB3AA2DC299CBD57F2A7F0B4</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT PK_SAL_NCONTRIB1 PRIMARY KEY (CODNCONTRIB1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NDREP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP</REFTABLE>
  <HASHVAL>FF569AE246384958F81352C16B670B25C395633F</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP ADD CONSTRAINT PK_SAL_NDREP PRIMARY KEY (CODNDREP) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NDREP0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP0</REFTABLE>
  <HASHVAL>5373D0BA9A2450FEDE85AB2E2DB43F613A1F67BA</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP0 ADD CONSTRAINT PK_SAL_NDREP0 PRIMARY KEY (CODNDREP0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_NDREP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP1</REFTABLE>
  <HASHVAL>E1E34FF73CD5FE0E9D41ADA53CE1A4F4E02B67AB</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP1 ADD CONSTRAINT PK_SAL_NDREP1 PRIMARY KEY (CODNDREP1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_RA21</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RA21</REFTABLE>
  <HASHVAL>0D2978D4DE389F9DE60744A5FDCFBDBA624AC304</HASHVAL>
  <TEXT>ALTER TABLE SAL_RA21 ADD CONSTRAINT PK_SAL_RA21 PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_RA24</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RA24</REFTABLE>
  <HASHVAL>4E90AB486A9DC8CEB7D0ABE51153B6FFF3E7CDF1</HASHVAL>
  <TEXT>ALTER TABLE SAL_RA24 ADD CONSTRAINT PK_SAL_RA24 PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_RETINERI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RETINERI</REFTABLE>
  <HASHVAL>C5502106D34FD132172734AD8D409972F5F995AF</HASHVAL>
  <TEXT>ALTER TABLE SAL_RETINERI ADD CONSTRAINT PK_SAL_RETINERI PRIMARY KEY (CODRETINERE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_RETINERI0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RETINERI0</REFTABLE>
  <HASHVAL>8CDACB8086B48E83C0A3A5FA7D82C5C585B91477</HASHVAL>
  <TEXT>ALTER TABLE SAL_RETINERI0 ADD CONSTRAINT PK_SAL_RETINERI0 PRIMARY KEY (CODRETINERE0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_SPORURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI</REFTABLE>
  <HASHVAL>88340EAA6294ED740D5A0C96BC4977BB22DE30C9</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI ADD CONSTRAINT PK_SAL_SPORURI PRIMARY KEY (CODSPOR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_SPORURI0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI0</REFTABLE>
  <HASHVAL>F1FDBBFD91F34A10A41F9F6C1E7E3C4BFC581252</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI0 ADD CONSTRAINT PK_SAL_SPORURI0 PRIMARY KEY (CODSPOR0) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_SPORURI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI1</REFTABLE>
  <HASHVAL>7C99831019AEBE8A96BDC092718AFCC7B9C34119</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI1 ADD CONSTRAINT PK_SAL_SPORURI1 PRIMARY KEY (CODSPOR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SAL_SPORURI2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI2</REFTABLE>
  <HASHVAL>02D282AA0DA385D5D3F0EC0637C03AA7788A6906</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI2 ADD CONSTRAINT PK_SAL_SPORURI2 PRIMARY KEY (CODSPOR2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SCENARIILIVR</REFTABLE>
  <HASHVAL>69193429FC4E6FD66A096F1173B59A2C60250E27</HASHVAL>
  <TEXT>ALTER TABLE SCENARIILIVR ADD CONSTRAINT PK_SCENARIILIVR PRIMARY KEY (CODSCENARIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SCENARIILIVR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SCENARIILIVR1</REFTABLE>
  <HASHVAL>F1AEEE16F8A6B1E49D7197754E9466C6B78C8248</HASHVAL>
  <TEXT>ALTER TABLE SCENARIILIVR1 ADD CONSTRAINT PK_SCENARIILIVR1 PRIMARY KEY (CODSCENARIU1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SCENARIILIVR2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SCENARIILIVR2</REFTABLE>
  <HASHVAL>3C29B6A0D6390DEFBD53C2DED6B3E3EAF901A460</HASHVAL>
  <TEXT>ALTER TABLE SCENARIILIVR2 ADD CONSTRAINT PK_SCENARIILIVR2 PRIMARY KEY (CODSCENARIU2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SERVPOST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SERVPOST</REFTABLE>
  <HASHVAL>4C1F10F9E8391759B964A0F4B2D5DF9B26FDF318</HASHVAL>
  <TEXT>ALTER TABLE SERVPOST ADD CONSTRAINT PK_SERVPOST PRIMARY KEY (CODSERVICIU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SETTASK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SETTASK</REFTABLE>
  <HASHVAL>3EEC09A60F4881562F5AE6FD8A5B7F127437153F</HASHVAL>
  <TEXT>ALTER TABLE SETTASK ADD CONSTRAINT PK_SETTASK PRIMARY KEY (CODTASK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SETTASKOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SETTASKOBJ</REFTABLE>
  <HASHVAL>6ECA70C84EEBA5C820D5587EE5E8E0F6BCCB1523</HASHVAL>
  <TEXT>ALTER TABLE SETTASKOBJ ADD CONSTRAINT PK_SETTASKOBJ PRIMARY KEY (CODTASKOBJ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SETTASKOBJASOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SETTASKOBJASOC</REFTABLE>
  <HASHVAL>1F1826D0A29865AA528B0CD41D30B842C832E8CF</HASHVAL>
  <TEXT>ALTER TABLE SETTASKOBJASOC ADD CONSTRAINT PK_SETTASKOBJASOC PRIMARY KEY (CODTASKOBJASOC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SGRCOLECT</REFTABLE>
  <HASHVAL>825F8BE7F86380B3B1FF51BD6FFC35D1EF68454C</HASHVAL>
  <TEXT>ALTER TABLE SGRCOLECT ADD CONSTRAINT PK_SGRCOLECT PRIMARY KEY (CODSGRCOLECT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SGRCOLECT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SGRCOLECT1</REFTABLE>
  <HASHVAL>BED42589089DB18ABCB40F2FA1D1D1C3CAA5F816</HASHVAL>
  <TEXT>ALTER TABLE SGRCOLECT1 ADD CONSTRAINT PK_SGRCOLECT1 PRIMARY KEY (CODSGRCOLECT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SITFIN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFIN</REFTABLE>
  <HASHVAL>2869034E9D3322531218B25029ABB90F3DD3251F</HASHVAL>
  <TEXT>ALTER TABLE SITFIN ADD CONSTRAINT PK_SITFIN PRIMARY KEY (CODSITFIN) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SITFINALTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFINALTE</REFTABLE>
  <HASHVAL>8746A13722CCA1BA22146480C98DE3A8AB800750</HASHVAL>
  <TEXT>ALTER TABLE SITFINALTE ADD CONSTRAINT PK_SITFINALTE PRIMARY KEY (CODALTE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SITFINBUGET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFINBUGET</REFTABLE>
  <HASHVAL>9C9552EC1F33F3FF7B094D4B96D5A0D0922C0B00</HASHVAL>
  <TEXT>ALTER TABLE SITFINBUGET ADD CONSTRAINT PK_SITFINBUGET PRIMARY KEY (CODSITFINBUGET) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SITFINCOL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFINCOL</REFTABLE>
  <HASHVAL>6D387C3731A1DD8457BA1F06AEE762FC196A1B45</HASHVAL>
  <TEXT>ALTER TABLE SITFINCOL ADD CONSTRAINT PK_SITFINCOL PRIMARY KEY (CODCOLOANA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SITFINLIN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFINLIN</REFTABLE>
  <HASHVAL>ECCD37399A267F7992C53E44191A69BAF9C7A507</HASHVAL>
  <TEXT>ALTER TABLE SITFINLIN ADD CONSTRAINT PK_SITFINLIN PRIMARY KEY (CODLINIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SMSURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SMSURI</REFTABLE>
  <HASHVAL>C06A7F700E8219527A0325DC73C102A71D0B12E9</HASHVAL>
  <TEXT>ALTER TABLE SMSURI ADD CONSTRAINT PK_SMSURI PRIMARY KEY (CODSMS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SOLDINI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SOLDINI</REFTABLE>
  <HASHVAL>2A51E301AFEA4345D78CE6147AFCEC2FD35AFFBD</HASHVAL>
  <TEXT>ALTER TABLE SOLDINI ADD CONSTRAINT PK_SOLDINI PRIMARY KEY (CODSOLDINI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SOLDPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SOLDPART</REFTABLE>
  <HASHVAL>AFC0B0851FF2FE0730730F48890D30F6B004B330</HASHVAL>
  <TEXT>ALTER TABLE SOLDPART ADD CONSTRAINT PK_SOLDPART PRIMARY KEY (CODSOLDPART) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SOLDPERSINI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SOLDPERSINI</REFTABLE>
  <HASHVAL>94A51FDFC3C6EA6D74DB51B6054AE07747430DD9</HASHVAL>
  <TEXT>ALTER TABLE SOLDPERSINI ADD CONSTRAINT PK_SOLDPERSINI PRIMARY KEY (CODSOLDPERSINI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPLITCHELT</REFTABLE>
  <HASHVAL>84BD3FFE6D5C2CB1EF4E324D562939EC1A45D115</HASHVAL>
  <TEXT>ALTER TABLE SPLITCHELT ADD CONSTRAINT PK_SPLITCHELT PRIMARY KEY (CODSPLITCHELT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SPLITCHELT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPLITCHELT1</REFTABLE>
  <HASHVAL>D5B983C5DF497E30B1E29E04FCA8B3CBCD0C88BF</HASHVAL>
  <TEXT>ALTER TABLE SPLITCHELT1 ADD CONSTRAINT PK_SPLITCHELT1 PRIMARY KEY (CODSPLITCHELT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SPVARHIVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPVARHIVA</REFTABLE>
  <HASHVAL>0D7C93036B808652701CFF545632C3F5691E6C90</HASHVAL>
  <TEXT>ALTER TABLE SPVARHIVA ADD CONSTRAINT PK_SPVARHIVA PRIMARY KEY (CODSPVARHIVA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STAREESTIMARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STAREESTIMARI</REFTABLE>
  <HASHVAL>B44A9237F5057453A79246932412B390C2CC6AC5</HASHVAL>
  <TEXT>ALTER TABLE STAREESTIMARI ADD CONSTRAINT PK_STAREESTIMARI PRIMARY KEY (CODSTARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STAREESTIMARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STAREESTIMARI1</REFTABLE>
  <HASHVAL>7C678C0EF584ECAA6F6AE9C9E40CD8296C253E21</HASHVAL>
  <TEXT>ALTER TABLE STAREESTIMARI1 ADD CONSTRAINT PK_STAREESTIMARI1 PRIMARY KEY (CODSTARE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STAREESTIMARI2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STAREESTIMARI2</REFTABLE>
  <HASHVAL>634F5D83841192C844F96B7B90F8AA6B71D98AE0</HASHVAL>
  <TEXT>ALTER TABLE STAREESTIMARI2 ADD CONSTRAINT PK_STAREESTIMARI2 PRIMARY KEY (CODSTARE2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STATUSDECL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STATUSDECL</REFTABLE>
  <HASHVAL>21C0B3C46200BE05B3D0309CB13A6379E467BAEB</HASHVAL>
  <TEXT>ALTER TABLE STATUSDECL ADD CONSTRAINT PK_STATUSDECL PRIMARY KEY (CODSTATUSDECL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STINGERE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STINGERE</REFTABLE>
  <HASHVAL>462975E31DF9B0837E909A117B2FFA4097B3DDDD</HASHVAL>
  <TEXT>ALTER TABLE STINGERE ADD CONSTRAINT PK_STINGERE PRIMARY KEY (CODSTINGERE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCFAKE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCFAKE1</REFTABLE>
  <HASHVAL>616076CEE98F44E3BC4AB2028E23529B1831ECD7</HASHVAL>
  <TEXT>ALTER TABLE STOCFAKE1 ADD CONSTRAINT PK_STOCFAKE1 PRIMARY KEY (CODSTOCFAKE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCINI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCINI</REFTABLE>
  <HASHVAL>ECC42301BF59DA93585A03F2D9BDBAEA91D6C7ED</HASHVAL>
  <TEXT>ALTER TABLE STOCINI ADD CONSTRAINT PK_STOCINI PRIMARY KEY (CODSTOCINI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCPOSURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCPOSURI</REFTABLE>
  <HASHVAL>E329478329E933072CC26EE4684DB1660AEC79A2</HASHVAL>
  <TEXT>ALTER TABLE STOCPOSURI ADD CONSTRAINT PK_STOCPOSURI PRIMARY KEY (CODSTOCPOS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCVALINI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCVALINI</REFTABLE>
  <HASHVAL>2C7A7050E797829006939CAA079C722FF95F9EDA</HASHVAL>
  <TEXT>ALTER TABLE STOCVALINI ADD CONSTRAINT PK_STOCVALINI PRIMARY KEY (CODSTOCVALINI) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCVALLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCVALLUNA</REFTABLE>
  <HASHVAL>D423298336CE106F61191A199D31F54344AEED07</HASHVAL>
  <TEXT>ALTER TABLE STOCVALLUNA ADD CONSTRAINT PK_STOCVALLUNA PRIMARY KEY (CODSTOCVALLUNA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SYNCPRETRETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SYNCPRETRETAIL</REFTABLE>
  <HASHVAL>1949F38C7B1A2E230E886D1357CB0C842A6BA064</HASHVAL>
  <TEXT>ALTER TABLE SYNCPRETRETAIL ADD CONSTRAINT PK_SYNCPRETRETAIL PRIMARY KEY (CODSYNC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_SYNCPROMORETAIL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SYNCPROMORETAIL</REFTABLE>
  <HASHVAL>382CEBA6A78A4CABA7F210715302A3CC93BB5D49</HASHVAL>
  <TEXT>ALTER TABLE SYNCPROMORETAIL ADD CONSTRAINT PK_SYNCPROMORETAIL PRIMARY KEY (CODSYNCPROMO) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TARGETAG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG</REFTABLE>
  <HASHVAL>F2BA6CBD99D3B9D96117A4C7A95015CA093326F4</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG ADD CONSTRAINT PK_TARGETAG PRIMARY KEY (CODTARGETAG) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TARGETAG1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG1</REFTABLE>
  <HASHVAL>7AC36B9234A4287785CD0A4B46AC0CB3D2CA685C</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG1 ADD CONSTRAINT PK_TARGETAG1 PRIMARY KEY (CODTARGETAG1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TARIFEMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARIFEMAN</REFTABLE>
  <HASHVAL>FDF0984B89B5E88157BA52F2B6F7BE5F344F1A88</HASHVAL>
  <TEXT>ALTER TABLE TARIFEMAN ADD CONSTRAINT PK_TARIFEMAN PRIMARY KEY (CODTARIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TARIFEMAN1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARIFEMAN1</REFTABLE>
  <HASHVAL>D2C200DB2BE03D2F26565BD0D05DA1427DC2C69E</HASHVAL>
  <TEXT>ALTER TABLE TARIFEMAN1 ADD CONSTRAINT PK_TARIFEMAN1 PRIMARY KEY (CODTARIF1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TARIFE_MASTER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARIFE_MASTER</REFTABLE>
  <HASHVAL>FD7EB92D0170B17387EE62DC72DD39D527E2FC2C</HASHVAL>
  <TEXT>ALTER TABLE TARIFE_MASTER ADD CONSTRAINT PK_TARIFE_MASTER PRIMARY KEY (CODTARIFM) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TAXDECL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TAXDECL</REFTABLE>
  <HASHVAL>0692212DE03ACA5D75C75382559CBBD0C1D3F4F2</HASHVAL>
  <TEXT>ALTER TABLE TAXDECL ADD CONSTRAINT PK_TAXDECL PRIMARY KEY (CODTAXDECL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TEME</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TEME</REFTABLE>
  <HASHVAL>75C69567B4179F92176CB1931760C9482EA52076</HASHVAL>
  <TEXT>ALTER TABLE TEME ADD CONSTRAINT PK_TEME PRIMARY KEY (CODTEMA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TIPCHELT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TIPCHELT</REFTABLE>
  <HASHVAL>1F60F2B6744B0D89C3857C99C6D2B5D2C8F07A0F</HASHVAL>
  <TEXT>ALTER TABLE TIPCHELT ADD CONSTRAINT PK_TIPCHELT PRIMARY KEY (CODTIPCHELT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TIPLUCRARISA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TIPLUCRARISA</REFTABLE>
  <HASHVAL>2B2B50C300D297BC5835EA45460B09CF22F1806C</HASHVAL>
  <TEXT>ALTER TABLE TIPLUCRARISA ADD CONSTRAINT PK_TIPLUCRARISA PRIMARY KEY (CODTIPLUCRARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TIPLUCRARISA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TIPLUCRARISA1</REFTABLE>
  <HASHVAL>707745B73626396C7DA2B9E1BEE6DCC50186230C</HASHVAL>
  <TEXT>ALTER TABLE TIPLUCRARISA1 ADD CONSTRAINT PK_TIPLUCRARISA1 PRIMARY KEY (CODTIPLUCRARE1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TIPURIPLATI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TIPURIPLATI</REFTABLE>
  <HASHVAL>495EA599BB0A54BC4E7C46C2120BD082A41B1F84</HASHVAL>
  <TEXT>ALTER TABLE TIPURIPLATI ADD CONSTRAINT PK_TIPURIPLATI PRIMARY KEY (CODTIPPLATA) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TMP_CMDTL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TMP_CMDTL</REFTABLE>
  <HASHVAL>F27564DBB6A58BB6014DBF0BA83A021CDA339788</HASHVAL>
  <TEXT>ALTER TABLE TMP_CMDTL ADD CONSTRAINT PK_TMP_CMDTL PRIMARY KEY (CODCMDTL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TMP_NARTCLI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TMP_NARTCLI</REFTABLE>
  <HASHVAL>FA5F3CF7131D4D244B2D9F4D4EAD456F4E4614D2</HASHVAL>
  <TEXT>ALTER TABLE TMP_NARTCLI ADD CONSTRAINT PK_TMP_NARTCLI PRIMARY KEY (CODARTCLI) </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TMP_PLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TMP_PLUNA</REFTABLE>
  <HASHVAL>8EF5782D933270921F11701A52AC5B50B37E0F52</HASHVAL>
  <TEXT>ALTER TABLE TMP_PLUNA ADD CONSTRAINT PK_TMP_PLUNA PRIMARY KEY (CODCMDPL) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TMP_SAFT_MANEVRA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TMP_SAFT_MANEVRA</REFTABLE>
  <HASHVAL>C23E329F4ACAF57C3236FB064D8461AA4305100A</HASHVAL>
  <TEXT>ALTER TABLE TMP_SAFT_MANEVRA ADD CONSTRAINT PK_TMP_SAFT_MANEVRA PRIMARY KEY (FILTRU,AL,CODUNIC) </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TOWORD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TOWORD</REFTABLE>
  <HASHVAL>8F8CBE7866F1B33E004BE8CF487078E8381BC67D</HASHVAL>
  <TEXT>ALTER TABLE TOWORD ADD CONSTRAINT PK_TOWORD PRIMARY KEY (CODTOWORD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSACARD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSACARD</REFTABLE>
  <HASHVAL>50D09C3D312DCE370619D0ABB5EC99CABD82127A</HASHVAL>
  <TEXT>ALTER TABLE TRANSACARD ADD CONSTRAINT PK_TRANSACARD PRIMARY KEY (CODTRANSACARD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF</REFTABLE>
  <HASHVAL>7462A5333881B4D28201ED67448251C9E1102AA9</HASHVAL>
  <TEXT>ALTER TABLE TRANSF ADD CONSTRAINT PK_TRANSF PRIMARY KEY (CODTRANSF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSF1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF1</REFTABLE>
  <HASHVAL>4DA9CDE08413ABFD35F66012C12CA2F7FB91AC63</HASHVAL>
  <TEXT>ALTER TABLE TRANSF1 ADD CONSTRAINT PK_TRANSF1 PRIMARY KEY (CODTRANSF1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSPORT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSPORT</REFTABLE>
  <HASHVAL>AE9E0D758C6C516613FE09A31EF7BDC02D57AF69</HASHVAL>
  <TEXT>ALTER TABLE TRANSPORT ADD CONSTRAINT PK_TRANSPORT PRIMARY KEY (CODTRANSPORT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSPORT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSPORT1</REFTABLE>
  <HASHVAL>37D68EE4464E952F146F09BBD341191BCD1FACCD</HASHVAL>
  <TEXT>ALTER TABLE TRANSPORT1 ADD CONSTRAINT PK_TRANSPORT1 PRIMARY KEY (CODTRANSPORT1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRANSPORT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSPORT2</REFTABLE>
  <HASHVAL>1D223A0629564EA9CD9382666A67FA473299049B</HASHVAL>
  <TEXT>ALTER TABLE TRANSPORT2 ADD CONSTRAINT PK_TRANSPORT2 PRIMARY KEY (CODTRANSPORT2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRASEU</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRASEU</REFTABLE>
  <HASHVAL>757ED6E55575F9C64303EDF9F40FCA8C1D33C756</HASHVAL>
  <TEXT>ALTER TABLE TRASEU ADD CONSTRAINT PK_TRASEU PRIMARY KEY (CODTRASEU) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRASEULIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRASEULIVR</REFTABLE>
  <HASHVAL>952A47F3D44E3048DC8AAA920801F051ED25EF16</HASHVAL>
  <TEXT>ALTER TABLE TRASEULIVR ADD CONSTRAINT PK_TRASEULIVR PRIMARY KEY (CODTRASEULIVR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TREZOR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TREZOR</REFTABLE>
  <HASHVAL>8CEC5965280F3AB4EAD5CF89A178F7F313A29EB3</HASHVAL>
  <TEXT>ALTER TABLE TREZOR ADD CONSTRAINT PK_TREZOR PRIMARY KEY (CODTREZOR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TREZOR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TREZOR1</REFTABLE>
  <HASHVAL>625674783ADA8B13BE1F2115B194C2813B7CCFCD</HASHVAL>
  <TEXT>ALTER TABLE TREZOR1 ADD CONSTRAINT PK_TREZOR1 PRIMARY KEY (CODTREZOR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRIGAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRIGAR</REFTABLE>
  <HASHVAL>C0964B2657DCB8BC902C942B9EA8FF7E3D1929E5</HASHVAL>
  <TEXT>ALTER TABLE TRIGAR ADD CONSTRAINT PK_TRIGAR PRIMARY KEY (CODTRIGAR) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRIGAR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRIGAR1</REFTABLE>
  <HASHVAL>9634BA4FE302B1EFA9E071F566BD3923123FB47B</HASHVAL>
  <TEXT>ALTER TABLE TRIGAR1 ADD CONSTRAINT PK_TRIGAR1 PRIMARY KEY (CODTRIGAR1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TRIGAR_MODIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRIGAR_MODIF</REFTABLE>
  <HASHVAL>AE9579894B794BF863FCCC52471B02F6A9D25083</HASHVAL>
  <TEXT>ALTER TABLE TRIGAR_MODIF ADD CONSTRAINT PK_TRIGAR_MODIF PRIMARY KEY (CODMODIF) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TVASERV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TVASERV</REFTABLE>
  <HASHVAL>6E16AD89B7765F46427490B2FA57CD951EEAA8AC</HASHVAL>
  <TEXT>ALTER TABLE TVASERV ADD CONSTRAINT PK_TVASERV PRIMARY KEY (CODTVASERV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_TVASERV1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TVASERV1</REFTABLE>
  <HASHVAL>92264DDCFCE086DE877E0FB270D003B1057A731D</HASHVAL>
  <TEXT>ALTER TABLE TVASERV1 ADD CONSTRAINT PK_TVASERV1 PRIMARY KEY (CODTVASERV1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE</REFTABLE>
  <HASHVAL>9D5DAD7968903373266EAA95FC35C46D8C94C38B</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE ADD CONSTRAINT PK_UTILAJE PRIMARY KEY (CODUTILAJ) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE1</REFTABLE>
  <HASHVAL>4A1FEBF86D093006C7FD2EDF93667E5A052B33F2</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE1 ADD CONSTRAINT PK_UTILAJE1 PRIMARY KEY (CODUTILAJ1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2</REFTABLE>
  <HASHVAL>E27EF95A2BB084055A7C5C8046E11FBE37D8698D</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2 ADD CONSTRAINT PK_UTILAJE2 PRIMARY KEY (CODUTILAJ2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE20</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE20</REFTABLE>
  <HASHVAL>7C999721C74816BE3F8B6059693EE43F360A82C0</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE20 ADD CONSTRAINT PK_UTILAJE20 PRIMARY KEY (CODUTILAJ20) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE2C</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2C</REFTABLE>
  <HASHVAL>9B678F5F018C45721902EAD089FAD9BFC48308A9</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2C ADD CONSTRAINT PK_UTILAJE2C PRIMARY KEY (CODUTILAJ2C) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE2P</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2P</REFTABLE>
  <HASHVAL>9F4B9FCA11234F4478BD030416B7D8C3568090FF</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2P ADD CONSTRAINT PK_UTILAJE2P PRIMARY KEY (CODUTILAJ2P) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJE3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE3</REFTABLE>
  <HASHVAL>AE2E56A06660080DA718AB44C4242019B774DA1E</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE3 ADD CONSTRAINT PK_UTILAJE3 PRIMARY KEY (CODUTILAJ3) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJEDEV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJEDEV</REFTABLE>
  <HASHVAL>349DFCD59C49BF7DCAB8BACD47313BEC049317FA</HASHVAL>
  <TEXT>ALTER TABLE UTILAJEDEV ADD CONSTRAINT PK_UTILAJEDEV PRIMARY KEY (CODUTILAJDEV) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJEMON</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJEMON</REFTABLE>
  <HASHVAL>9A0A782990A9135B8E38654D2B69F687C7B63F27</HASHVAL>
  <TEXT>ALTER TABLE UTILAJEMON ADD CONSTRAINT PK_UTILAJEMON PRIMARY KEY (CODMONITORIZARE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_UTILAJETIPINDEX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJETIPINDEX</REFTABLE>
  <HASHVAL>7DBB0321D6BAEF38199A74B6E15FDD631992E813</HASHVAL>
  <TEXT>ALTER TABLE UTILAJETIPINDEX ADD CONSTRAINT PK_UTILAJETIPINDEX PRIMARY KEY (CODTINDEX) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VERSION</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VERSION</REFTABLE>
  <HASHVAL>03B44393534DE260F415CFFE6D828E195F2AE503</HASHVAL>
  <TEXT>ALTER TABLE VERSION ADD CONSTRAINT PK_VERSION PRIMARY KEY (VERSION) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VIEW_JOINS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VIEW_JOINS</REFTABLE>
  <HASHVAL>7001D6167BF78796351ABDC8400E4D1AE2D1F50C</HASHVAL>
  <TEXT>ALTER TABLE VIEW_JOINS ADD CONSTRAINT PK_VIEW_JOINS PRIMARY KEY (CODVIEW_JOINS) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VOUCHER</REFTABLE>
  <HASHVAL>0B8A099AAC92C3EA6D638609D3731A42D613D8FC</HASHVAL>
  <TEXT>ALTER TABLE VOUCHER ADD CONSTRAINT PK_VOUCHER PRIMARY KEY (CODVOUCHER) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VOUCHERCADOU</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VOUCHERCADOU</REFTABLE>
  <HASHVAL>5FADD0755F0E0F1FE1B398073034D0C8B8A618CF</HASHVAL>
  <TEXT>ALTER TABLE VOUCHERCADOU ADD CONSTRAINT PK_VOUCHERCADOU PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VOUCHERCADOULINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VOUCHERCADOULINK</REFTABLE>
  <HASHVAL>7959B8F325E255A69025E829A647C277F7D06962</HASHVAL>
  <TEXT>ALTER TABLE VOUCHERCADOULINK ADD CONSTRAINT PK_VOUCHERCADOULINK PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_VOUCHERLINK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>VOUCHERLINK</REFTABLE>
  <HASHVAL>9E82A7A8B613915519619508FA617822C0171585</HASHVAL>
  <TEXT>ALTER TABLE VOUCHERLINK ADD CONSTRAINT PK_VOUCHERLINK PRIMARY KEY (CODVLINK) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_WEEKCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>WEEKCASHFLOW</REFTABLE>
  <HASHVAL>CD7E421C757DF8A94C589F56B077C6A1C37597C2</HASHVAL>
  <TEXT>ALTER TABLE WEEKCASHFLOW ADD CONSTRAINT PK_WEEKCASHFLOW PRIMARY KEY (CODCASHFLOW) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_WEEKCASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>WEEKCASHFLOW1</REFTABLE>
  <HASHVAL>876B9CE9D494F969B0FECB4EA30E3307F1012C57</HASHVAL>
  <TEXT>ALTER TABLE WEEKCASHFLOW1 ADD CONSTRAINT PK_WEEKCASHFLOW1 PRIMARY KEY (CODCASHFLOW1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ZEURO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ZEURO</REFTABLE>
  <HASHVAL>70B14D6EC358587CDEFECEB8E3FB2007A66D21E8</HASHVAL>
  <TEXT>ALTER TABLE ZEURO ADD CONSTRAINT PK_ZEURO PRIMARY KEY (COD) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ZINELUC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ZINELUC</REFTABLE>
  <HASHVAL>97A4999BFAC17E8C1208AC61EE93385A84F8523E</HASHVAL>
  <TEXT>ALTER TABLE ZINELUC ADD CONSTRAINT PK_ZINELUC PRIMARY KEY (CODZINELUC) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_ZINELUC1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ZINELUC1</REFTABLE>
  <HASHVAL>64ADBCDB0002C01EB19EDEC405524F40E338951C</HASHVAL>
  <TEXT>ALTER TABLE ZINELUC1 ADD CONSTRAINT PK_ZINELUC1 PRIMARY KEY (CODZINELUC1) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DISCEXCEPTII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCEXCEPTII</REFTABLE>
  <HASHVAL>94BFDB2BC7BCF020844CC11C0AE812973F37DC18</HASHVAL>
  <TEXT>ALTER TABLE DISCEXCEPTII ADD CONSTRAINT PK_DISCEXCEPTII UNIQUE (CODDISCEXCEPTIE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_DOCEDITAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCEDITAT</REFTABLE>
  <HASHVAL>2A5C7CEE14FD796D16D3D33682850782B7DCD70F</HASHVAL>
  <TEXT>ALTER TABLE DOCEDITAT ADD CONSTRAINT PK_DOCEDITAT UNIQUE (CODDOCEDITAT) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_PLATI2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLATI2</REFTABLE>
  <HASHVAL>E9090E4F41071429C875ABDB9F8D2773DC847EFF</HASHVAL>
  <TEXT>ALTER TABLE PLATI2 ADD CONSTRAINT PK_PLATI2 UNIQUE (CODPLATA2) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PK_STOCFAKE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCFAKE</REFTABLE>
  <HASHVAL>AE43F9E471D2D4E3CC0680BF6D7C58A54AC2CB6E</HASHVAL>
  <TEXT>ALTER TABLE STOCFAKE ADD CONSTRAINT PK_STOCFAKE UNIQUE (CODSTOCFAKE) USING INDEX TABLESPACE WMINDX</TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>CODDEPOZIT_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCUMENTE</REFTABLE>
  <HASHVAL>005505524C9624FA9810CC06A057EBAD5B94A9C3</HASHVAL>
  <TEXT>ALTER TABLE DOCUMENTE ADD CONSTRAINT CODDEPOZIT_FK FOREIGN KEY (CODDEPOZIT) REFERENCES DOCUMENTE (CODDOCUMENT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>CONSTMAKETA_CONST1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTMAKETA</REFTABLE>
  <HASHVAL>EC9E8A582A9240BC31F20CBBB4E79C550B09A835</HASHVAL>
  <TEXT>ALTER TABLE CONSTMAKETA ADD CONSTRAINT CONSTMAKETA_CONST1_FK FOREIGN KEY (CODCONST1) REFERENCES CONST1 (CODCONST1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>CONSTMAKETA_NMAKETE_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTMAKETA</REFTABLE>
  <HASHVAL>27D1A4299939680434336DFFD07608BFAA879287</HASHVAL>
  <TEXT>ALTER TABLE CONSTMAKETA ADD CONSTRAINT CONSTMAKETA_NMAKETE_FK FOREIGN KEY (CODMAKETA) REFERENCES NMAKETE (CODMAKETA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISCART_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCART</REFTABLE>
  <HASHVAL>550AC8BE954AEC81BBBE8E98ACE326DEE11EACA8</HASHVAL>
  <TEXT>ALTER TABLE DISCART ADD CONSTRAINT DISCART_FK FOREIGN KEY (CODDISCOUNT) REFERENCES DISCOUNT (CODDISCOUNT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISCINTERVAL_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCINTERVAL</REFTABLE>
  <HASHVAL>116B433BB6110CC474299079D6F2D2A608C41CF7</HASHVAL>
  <TEXT>ALTER TABLE DISCINTERVAL ADD CONSTRAINT DISCINTERVAL_FK FOREIGN KEY (CODDISCOUNT) REFERENCES DISCOUNT (CODDISCOUNT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISCOUNT_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCOUNT</REFTABLE>
  <HASHVAL>DEEE065EB48B370C6EA01583DBE3D4E475F29A05</HASHVAL>
  <TEXT>ALTER TABLE DISCOUNT ADD CONSTRAINT DISCOUNT_FK FOREIGN KEY (CODCRITERIU) REFERENCES CRITERIIDISC (CODCRITERIU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISTRIBCHELT1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT2</REFTABLE>
  <HASHVAL>3CF9D5CA79A4A65F8A652057B8DEE5B1F0DF0FED</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT2 ADD CONSTRAINT DISTRIBCHELT1_FK FOREIGN KEY (CODDISTRIBCHELT1) REFERENCES DISTRIBCHELT1 (CODDISTRIBCHELT1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISTRIBCHELT_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT1</REFTABLE>
  <HASHVAL>2F9E00F1D2113AD52A879F86ED1B4FD9D488D6BA</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT1 ADD CONSTRAINT DISTRIBCHELT_FK FOREIGN KEY (CODDISTRIBCHELT) REFERENCES DISTRIBCHELT (CODDISTRIBCHELT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DISTRIBCHELT_FKX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT2</REFTABLE>
  <HASHVAL>29E0793264A270DC0ADFBC8B533A70FA69537CED</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT2 ADD CONSTRAINT DISTRIBCHELT_FKX FOREIGN KEY (CODDISTRIBCHELT) REFERENCES DISTRIBCHELT (CODDISTRIBCHELT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DOCFREE_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCFREE</REFTABLE>
  <HASHVAL>EF421D2A3887575BB7C236715DED58DD8CD8F18B</HASHVAL>
  <TEXT>ALTER TABLE DOCFREE ADD CONSTRAINT DOCFREE_FK FOREIGN KEY (CODCARNET) REFERENCES DOCCARNETE (CODCARNET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DOCLINK_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCLINK</REFTABLE>
  <HASHVAL>C0FDB50AA9E65E128F2FF44776635FC12EC2195B</HASHVAL>
  <TEXT>ALTER TABLE DOCLINK ADD CONSTRAINT DOCLINK_FK FOREIGN KEY (CODCARNET) REFERENCES DOCCARNETE (CODCARNET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DOCLOCK_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCLOCK</REFTABLE>
  <HASHVAL>495A2D1A1FC651203723F59B13371F7B9B430B52</HASHVAL>
  <TEXT>ALTER TABLE DOCLOCK ADD CONSTRAINT DOCLOCK_FK FOREIGN KEY (CODCARNET) REFERENCES DOCCARNETE (CODCARNET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>DOCUSERS_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCUSERS</REFTABLE>
  <HASHVAL>412C736A6C4D6C2290A362929AC78DD451F07747</HASHVAL>
  <TEXT>ALTER TABLE DOCUSERS ADD CONSTRAINT DOCUSERS_FK FOREIGN KEY (CODCARNET) REFERENCES DOCCARNETE (CODCARNET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ADAOSM1_ADAOSM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ADAOSM1</REFTABLE>
  <HASHVAL>ADA6C64E91669BF0BBB996E5179F0F29E9F3D4E0</HASHVAL>
  <TEXT>ALTER TABLE ADAOSM1 ADD CONSTRAINT FK_ADAOSM1_ADAOSM FOREIGN KEY (CODADAOSM) REFERENCES ADAOSM (CODADAOSM)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ANALIZA1_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZA1</REFTABLE>
  <HASHVAL>AF30536D759247DD8716C05CA4967CA96A425040</HASHVAL>
  <TEXT>ALTER TABLE ANALIZA1 ADD CONSTRAINT FK_ANALIZA1_ANALIZA FOREIGN KEY (CODANALIZA) REFERENCES ANALIZA (CODANALIZA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ANALIZA1_DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZA1</REFTABLE>
  <HASHVAL>D072A61F1B506A81EB0F832549D0B4FE20C6D757</HASHVAL>
  <TEXT>ALTER TABLE ANALIZA1 ADD CONSTRAINT FK_ANALIZA1_DESCRIPTORI FOREIGN KEY (CODDESCRIPTOR) REFERENCES DESCRIPTORI (CODDESCRIPTOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ANALIZANOD_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZANOD</REFTABLE>
  <HASHVAL>BA4B94E0834179E2D77C95DAE75C29D6F477D1A8</HASHVAL>
  <TEXT>ALTER TABLE ANALIZANOD ADD CONSTRAINT FK_ANALIZANOD_ANALIZA FOREIGN KEY (CODANALIZA) REFERENCES ANALIZA (CODANALIZA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ANALIZANOD_ANALIZA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZANOD</REFTABLE>
  <HASHVAL>31DFB421E317B7B350056BD44A4F7E671BBAE72C</HASHVAL>
  <TEXT>ALTER TABLE ANALIZANOD ADD CONSTRAINT FK_ANALIZANOD_ANALIZA1 FOREIGN KEY (CODANALIZA1) REFERENCES ANALIZA1 (CODANALIZA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ANALIZANOD_DESCRIPTORI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ANALIZANOD</REFTABLE>
  <HASHVAL>56FDEAE25EB1D86C169906CCD5F2F332C62ED07B</HASHVAL>
  <TEXT>ALTER TABLE ANALIZANOD ADD CONSTRAINT FK_ANALIZANOD_DESCRIPTORI1 FOREIGN KEY (CODDESCRIPTOR1) REFERENCES DESCRIPTORI1 (CODDESCRIPTOR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_BUGETANALIZA_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETANALIZA</REFTABLE>
  <HASHVAL>888DCC7778779AEE66A6421FB02DA3BA8CC2B5C3</HASHVAL>
  <TEXT>ALTER TABLE BUGETANALIZA ADD CONSTRAINT FK_BUGETANALIZA_ANALIZA FOREIGN KEY (CODANALIZA) REFERENCES ANALIZA (CODANALIZA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_BUGETANALIZA_ANALIZANOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETANALIZA</REFTABLE>
  <HASHVAL>30F05663D243EDBE8AFD8B7C56B89BE401E90B71</HASHVAL>
  <TEXT>ALTER TABLE BUGETANALIZA ADD CONSTRAINT FK_BUGETANALIZA_ANALIZANOD FOREIGN KEY (CODANALIZANOD) REFERENCES ANALIZANOD (CODANALIZANOD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_BUGETANALIZA_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETANALIZA</REFTABLE>
  <HASHVAL>F5119901964DBC6234F87BF4DDD900FF33A94DB8</HASHVAL>
  <TEXT>ALTER TABLE BUGETANALIZA ADD CONSTRAINT FK_BUGETANALIZA_CENTRECOST FOREIGN KEY (CODCENTRU) REFERENCES CENTRECOST (CODCENTRU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_BUGETANALIZA_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>BUGETANALIZA</REFTABLE>
  <HASHVAL>E589991E611EFEE72B3B010F5A9DB42ECDB2C565</HASHVAL>
  <TEXT>ALTER TABLE BUGETANALIZA ADD CONSTRAINT FK_BUGETANALIZA_ELEMENTE FOREIGN KEY (CODELEMENT) REFERENCES ELEMENTE (CODELEMENT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CANTAR_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CANTAR</REFTABLE>
  <HASHVAL>C99330927454F2B31F3A97C366B6BD6BE6741E17</HASHVAL>
  <TEXT>ALTER TABLE CANTAR ADD CONSTRAINT FK_CANTAR_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CENTRECOSTA_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CENTRECOSTA</REFTABLE>
  <HASHVAL>C758882F10B07B93BEA6399C5F3C695E95D5C53E</HASHVAL>
  <TEXT>ALTER TABLE CENTRECOSTA ADD CONSTRAINT FK_CENTRECOSTA_CENTRECOST FOREIGN KEY (CODCENTRU) REFERENCES CENTRECOST (CODCENTRU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CENTRECOSTA_CODANALIZA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CENTRECOSTA</REFTABLE>
  <HASHVAL>4712D8B51B125DF08186744F7FD0E63CE31B7A37</HASHVAL>
  <TEXT>ALTER TABLE CENTRECOSTA ADD CONSTRAINT FK_CENTRECOSTA_CODANALIZA FOREIGN KEY (CODANALIZA) REFERENCES ANALIZA (CODANALIZA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CERTIF_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CERTIF</REFTABLE>
  <HASHVAL>A2A6C0B3430AAD910D3BCE584A90AEA026687003</HASHVAL>
  <TEXT>ALTER TABLE CERTIF ADD CONSTRAINT FK_CERTIF_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CHELTAVANS_INTRARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTAVANS</REFTABLE>
  <HASHVAL>E0FB92FD334AC48655D38F062B40302CF27B3959</HASHVAL>
  <TEXT>ALTER TABLE CHELTAVANS ADD CONSTRAINT FK_CHELTAVANS_INTRARI1 FOREIGN KEY (CODINTR1) REFERENCES INTRARI1 (CODINTR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDLINK_CODLINIECOMANDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDLINK</REFTABLE>
  <HASHVAL>170B775EAA1F19D7712B66368B5F373BF44F614E</HASHVAL>
  <TEXT>ALTER TABLE CMDLINK ADD CONSTRAINT FK_CMDLINK_CODLINIECOMANDA FOREIGN KEY (CODLINIECOMANDA) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDPRODMAN_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODMAN</REFTABLE>
  <HASHVAL>1F5D4D42036F93C92DD8272415C8BC8154D945E9</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODMAN ADD CONSTRAINT FK_CMDPRODMAN_COMANDA1 FOREIGN KEY (CODCOMANDA1) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDPRODMAT_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODMAT</REFTABLE>
  <HASHVAL>5A59D217CCF6042336C6CEAC41C9F8DFD76F2C3D</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODMAT ADD CONSTRAINT FK_CMDPRODMAT_COMANDA1 FOREIGN KEY (CODCOMANDA1) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDPRODMAT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODMAT</REFTABLE>
  <HASHVAL>78F3F86E415993D7A004CF9713DAF3726574B554</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODMAT ADD CONSTRAINT FK_CMDPRODMAT_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDPRODREZ_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODREZ</REFTABLE>
  <HASHVAL>F2246A61814AA5E1E404C91CDB96FC4302BCA520</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODREZ ADD CONSTRAINT FK_CMDPRODREZ_COMANDA1 FOREIGN KEY (CODCOMANDA1) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CMDPRODREZ_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CMDPRODREZ</REFTABLE>
  <HASHVAL>247D0D3CCB45801E19944C9FEBC65BBBB79334AF</HASHVAL>
  <TEXT>ALTER TABLE CMDPRODREZ ADD CONSTRAINT FK_CMDPRODREZ_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_COMANDA1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA1</REFTABLE>
  <HASHVAL>E3F9449A2D01DAB35AEC063C91537B2B7FD9C187</HASHVAL>
  <TEXT>ALTER TABLE COMANDA1 ADD CONSTRAINT FK_COMANDA1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_COMANDA1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA1</REFTABLE>
  <HASHVAL>9E5AB0B42843C4E345C3C2A8B84409B9C4C72934</HASHVAL>
  <TEXT>ALTER TABLE COMANDA1 ADD CONSTRAINT FK_COMANDA1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_COMANDA_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA</REFTABLE>
  <HASHVAL>9C34ADF9357A27763EF57C63905A83CAE0BE092D</HASHVAL>
  <TEXT>ALTER TABLE COMANDA ADD CONSTRAINT FK_COMANDA_NAGENDA FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_COMANDA_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMANDA</REFTABLE>
  <HASHVAL>BDA93A0CBC8EEFCA4B92C176BD2E9616628483F9</HASHVAL>
  <TEXT>ALTER TABLE COMANDA ADD CONSTRAINT FK_COMANDA_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_COMPENS_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>COMPENS</REFTABLE>
  <HASHVAL>88423E28A9365D0AABF23123D8C1E1CD741F17BC</HASHVAL>
  <TEXT>ALTER TABLE COMPENS ADD CONSTRAINT FK_COMPENS_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONST1_CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONST1</REFTABLE>
  <HASHVAL>B0902B8C39AFF2810B8AFF77FBA681AB0454369F</HASHVAL>
  <TEXT>ALTER TABLE CONST1 ADD CONSTRAINT FK_CONST1_CATEGCONST FOREIGN KEY (CODCATEG) REFERENCES CATEGCONST (CODCATEG)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONSTLUNA_CODCONST1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTLUNA</REFTABLE>
  <HASHVAL>EC0E50D3203D763C3397FDAF918B9E85B44CB961</HASHVAL>
  <TEXT>ALTER TABLE CONSTLUNA ADD CONSTRAINT FK_CONSTLUNA_CODCONST1 FOREIGN KEY (CODCONST1) REFERENCES CONST1 (CODCONST1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONSTVALPOS_CONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTVALPOS</REFTABLE>
  <HASHVAL>5C0DF7835652EA00D35AB1635D354E2CA2C1555D</HASHVAL>
  <TEXT>ALTER TABLE CONSTVALPOS ADD CONSTRAINT FK_CONSTVALPOS_CONSTLUNA FOREIGN KEY (CODCONSTLUNA) REFERENCES CONSTLUNA (CODCONSTLUNA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONSTVAL_CONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONSTVAL</REFTABLE>
  <HASHVAL>AD4043378FDEA017630EA4CE2F01EF1DB6D235A4</HASHVAL>
  <TEXT>ALTER TABLE CONSTVAL ADD CONSTRAINT FK_CONSTVAL_CONSTLUNA FOREIGN KEY (CODCONSTLUNA) REFERENCES CONSTLUNA (CODCONSTLUNA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONTRACT1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT1</REFTABLE>
  <HASHVAL>398E38B2802E32C173DA4B54424A150853605B33</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT1 ADD CONSTRAINT FK_CONTRACT1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONTRACT1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT1</REFTABLE>
  <HASHVAL>8600B013ED20F487649D068937E8DD9EB97D13C0</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT1 ADD CONSTRAINT FK_CONTRACT1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CONTRACT_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CONTRACT</REFTABLE>
  <HASHVAL>3A68A813234322C6A5805BAE92554D20A2AC7B05</HASHVAL>
  <TEXT>ALTER TABLE CONTRACT ADD CONSTRAINT FK_CONTRACT_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_CURS_FUNCTIE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FUNCTII1</REFTABLE>
  <HASHVAL>847D1D4B84044973F38C9CEE3A22E23A7D85506C</HASHVAL>
  <TEXT>ALTER TABLE FUNCTII1 ADD CONSTRAINT FK_CURS_FUNCTIE FOREIGN KEY (CODCURS) REFERENCES CURSURI (CODCURS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D390D_D390</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390D</REFTABLE>
  <HASHVAL>67F680CC7F1E79060C89C3A6696E898540A0140A</HASHVAL>
  <TEXT>ALTER TABLE D390D ADD CONSTRAINT FK_D390D_D390 FOREIGN KEY (CODD390) REFERENCES D390 (CODD390)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D390D_D390O</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390D</REFTABLE>
  <HASHVAL>07B119EA5E071B7EDDBB686AE76DA1974DB02E22</HASHVAL>
  <TEXT>ALTER TABLE D390D ADD CONSTRAINT FK_D390D_D390O FOREIGN KEY (CODD390O) REFERENCES D390O (CODD390O)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D390O_D390</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D390O</REFTABLE>
  <HASHVAL>2EF992BB45361A24B368160ED71BB8865C8095FA</HASHVAL>
  <TEXT>ALTER TABLE D390O ADD CONSTRAINT FK_D390O_D390 FOREIGN KEY (CODD390) REFERENCES D390 (CODD390)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416G1_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G1</REFTABLE>
  <HASHVAL>BA8727F147DAA5ECBA338E3C5683FF8C3FCEA85E</HASHVAL>
  <TEXT>ALTER TABLE D39416G1 ADD CONSTRAINT FK_D39416G1_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416G2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G2</REFTABLE>
  <HASHVAL>FABC113E3E430DFB58FCB0E10EA54B4AEB0114EB</HASHVAL>
  <TEXT>ALTER TABLE D39416G2 ADD CONSTRAINT FK_D39416G2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416G3_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G3</REFTABLE>
  <HASHVAL>D66E74BF5F1D69F3033F82FBB39244BE87E60225</HASHVAL>
  <TEXT>ALTER TABLE D39416G3 ADD CONSTRAINT FK_D39416G3_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416G_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416G</REFTABLE>
  <HASHVAL>8843E809A42E160E5727364D6B98681EE37F1B4E</HASHVAL>
  <TEXT>ALTER TABLE D39416G ADD CONSTRAINT FK_D39416G_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I1_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I1</REFTABLE>
  <HASHVAL>F9245EDC661E2085CAE1071148E17B08D4C258AD</HASHVAL>
  <TEXT>ALTER TABLE D39416I1 ADD CONSTRAINT FK_D39416I1_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I2A_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I2A</REFTABLE>
  <HASHVAL>A9D205D4C596DDDD8B7977709A45F4AAB9AD9DEC</HASHVAL>
  <TEXT>ALTER TABLE D39416I2A ADD CONSTRAINT FK_D39416I2A_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I2</REFTABLE>
  <HASHVAL>2D35A72B398675BDAB2EF017CB94AD4955729763</HASHVAL>
  <TEXT>ALTER TABLE D39416I2 ADD CONSTRAINT FK_D39416I2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I3_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I3</REFTABLE>
  <HASHVAL>31127C9CE77DB3AA3A750E041D16B15C5AF3355E</HASHVAL>
  <TEXT>ALTER TABLE D39416I3 ADD CONSTRAINT FK_D39416I3_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I4_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I4</REFTABLE>
  <HASHVAL>2C3602CB7B28C9BFE63DCAA3E26BC9307A62C9FD</HASHVAL>
  <TEXT>ALTER TABLE D39416I4 ADD CONSTRAINT FK_D39416I4_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416I_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416I</REFTABLE>
  <HASHVAL>7170C66852E9F7777EFDD96136A68A98ECCC347B</HASHVAL>
  <TEXT>ALTER TABLE D39416I ADD CONSTRAINT FK_D39416I_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416NS2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416NS2</REFTABLE>
  <HASHVAL>F90CD1FDD66C18FE033792BF71ADE088A7498F26</HASHVAL>
  <TEXT>ALTER TABLE D39416NS2 ADD CONSTRAINT FK_D39416NS2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416N_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416N</REFTABLE>
  <HASHVAL>C527F2A52DB0F99EB51DCC3D66B92E2F020D3500</HASHVAL>
  <TEXT>ALTER TABLE D39416N ADD CONSTRAINT FK_D39416N_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RN0_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN0</REFTABLE>
  <HASHVAL>7DF0318E63A387AD7EB36712B4CD4C91DEC6F696</HASHVAL>
  <TEXT>ALTER TABLE D39416RN0 ADD CONSTRAINT FK_D39416RN0_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RN1_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN1</REFTABLE>
  <HASHVAL>2C1C15234DA47B7FBCFA2F80CD3FCB36B254E13D</HASHVAL>
  <TEXT>ALTER TABLE D39416RN1 ADD CONSTRAINT FK_D39416RN1_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RNS2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RNS2</REFTABLE>
  <HASHVAL>276AEE46F7E05B63245549E1A7CACE022AE03AF2</HASHVAL>
  <TEXT>ALTER TABLE D39416RNS2 ADD CONSTRAINT FK_D39416RNS2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RNS3_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RNS3</REFTABLE>
  <HASHVAL>40DF0189B02BEB0591446FB0FC54A73C3D513FCD</HASHVAL>
  <TEXT>ALTER TABLE D39416RNS3 ADD CONSTRAINT FK_D39416RNS3_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RN_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RN</REFTABLE>
  <HASHVAL>855E245250C0E2AA81F8040C456B058D1890C683</HASHVAL>
  <TEXT>ALTER TABLE D39416RN ADD CONSTRAINT FK_D39416RN_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RP1_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RP1</REFTABLE>
  <HASHVAL>69B41BBE6A3D88AA1B9F02FCA5678602D25344AB</HASHVAL>
  <TEXT>ALTER TABLE D39416RP1 ADD CONSTRAINT FK_D39416RP1_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RPS2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RPS2</REFTABLE>
  <HASHVAL>94C5CCC23EA7427CEB8739624B82DBA19DC2498C</HASHVAL>
  <TEXT>ALTER TABLE D39416RPS2 ADD CONSTRAINT FK_D39416RPS2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RPS3_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RPS3</REFTABLE>
  <HASHVAL>23BA3F15148D78EAD828BF9D5D4F956FC9AAB2A3</HASHVAL>
  <TEXT>ALTER TABLE D39416RPS3 ADD CONSTRAINT FK_D39416RPS3_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416RP_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416RP</REFTABLE>
  <HASHVAL>DE06F34F8EC55402D5AA572BB99AAEE3D2951602</HASHVAL>
  <TEXT>ALTER TABLE D39416RP ADD CONSTRAINT FK_D39416RP_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416R_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416R</REFTABLE>
  <HASHVAL>CF6884017829670520C1B06D5284E124566E6CFA</HASHVAL>
  <TEXT>ALTER TABLE D39416R ADD CONSTRAINT FK_D39416R_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416UE2_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416UES2</REFTABLE>
  <HASHVAL>4C9A87AD095D8D02A1854911594B2594777A64DA</HASHVAL>
  <TEXT>ALTER TABLE D39416UES2 ADD CONSTRAINT FK_D39416UE2_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D39416UE_D39416</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D39416UE</REFTABLE>
  <HASHVAL>8FC722831C62E5CE250547CA7E0157BA025AA103</HASHVAL>
  <TEXT>ALTER TABLE D39416UE ADD CONSTRAINT FK_D39416UE_D39416 FOREIGN KEY (CODD39416) REFERENCES D39416 (CODD39416)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394A_D394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394A</REFTABLE>
  <HASHVAL>D471686195DE8115895264744FA60D268A761521</HASHVAL>
  <TEXT>ALTER TABLE D394A ADD CONSTRAINT FK_D394A_D394 FOREIGN KEY (CODD394) REFERENCES D394 (CODD394)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394CC_D394C</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394CC</REFTABLE>
  <HASHVAL>14F7C890678430DE6199C80F137CEE97935A285E</HASHVAL>
  <TEXT>ALTER TABLE D394CC ADD CONSTRAINT FK_D394CC_D394C FOREIGN KEY (CODD394C) REFERENCES D394C (CODD394C)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394C_D394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394C</REFTABLE>
  <HASHVAL>DAFD21273129CF50560E2F60D763977FF0A8EEBE</HASHVAL>
  <TEXT>ALTER TABLE D394C ADD CONSTRAINT FK_D394C_D394 FOREIGN KEY (CODD394) REFERENCES D394 (CODD394)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394L_D394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394L</REFTABLE>
  <HASHVAL>3481689C0D41E7814DC6659CFF7F0FC89B811013</HASHVAL>
  <TEXT>ALTER TABLE D394L ADD CONSTRAINT FK_D394L_D394 FOREIGN KEY (CODD394) REFERENCES D394 (CODD394)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394VC_D394V</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394VC</REFTABLE>
  <HASHVAL>4EB5B0D8229CA8C3B9504BD4F28EC56CD14310A2</HASHVAL>
  <TEXT>ALTER TABLE D394VC ADD CONSTRAINT FK_D394VC_D394V FOREIGN KEY (CODD394V) REFERENCES D394V (CODD394V)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_D394V_D394</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>D394V</REFTABLE>
  <HASHVAL>E1D8E0DF83211EED0923A2D74AC6C9F354FCC766</HASHVAL>
  <TEXT>ALTER TABLE D394V ADD CONSTRAINT FK_D394V_D394 FOREIGN KEY (CODD394) REFERENCES D394 (CODD394)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DESCRIPT1_DESCRIPT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DESCRIPTORI1</REFTABLE>
  <HASHVAL>9782F8C00698EBABFF6BC490E1FC6D62AE0CBE41</HASHVAL>
  <TEXT>ALTER TABLE DESCRIPTORI1 ADD CONSTRAINT FK_DESCRIPT1_DESCRIPT FOREIGN KEY (CODDESCRIPTOR) REFERENCES DESCRIPTORI (CODDESCRIPTOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DETALIIET1_DETALIIET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DETALIIET1</REFTABLE>
  <HASHVAL>C2D5B8AD09810F29CD0C6E856C01DDF6EE78C83C</HASHVAL>
  <TEXT>ALTER TABLE DETALIIET1 ADD CONSTRAINT FK_DETALIIET1_DETALIIET FOREIGN KEY (CODDETALIUET) REFERENCES DETALIIET (CODDETALIU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DETALIIET_CODPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DETALIIET</REFTABLE>
  <HASHVAL>0EF8BA1635BE1EB8EE40EEF25162607740C56F39</HASHVAL>
  <TEXT>ALTER TABLE DETALIIET ADD CONSTRAINT FK_DETALIIET_CODPART FOREIGN KEY (CODPARTTR) REFERENCES NPART (CODPART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DEZASAMBLARI1_INTR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DEZASAMBLARI1</REFTABLE>
  <HASHVAL>E8448C0EEE6D9573677D6672F4450AB1E0B2ECEA</HASHVAL>
  <TEXT>ALTER TABLE DEZASAMBLARI1 ADD CONSTRAINT FK_DEZASAMBLARI1_INTR FOREIGN KEY (CODINTRLINK) REFERENCES INTRARI (CODINTR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DEZASAMBLARI1_LIVR1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DEZASAMBLARI1</REFTABLE>
  <HASHVAL>B7A983603BC84589826A668C219B55B521EABFD3</HASHVAL>
  <TEXT>ALTER TABLE DEZASAMBLARI1 ADD CONSTRAINT FK_DEZASAMBLARI1_LIVR1 FOREIGN KEY (CODLIVR1) REFERENCES DEZASAMBLARI (CODLIVR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DINTRASTATA_DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DINTRASTATA</REFTABLE>
  <HASHVAL>82BB8C64832B86E61B6887C95140A9F47688C791</HASHVAL>
  <TEXT>ALTER TABLE DINTRASTATA ADD CONSTRAINT FK_DINTRASTATA_DINTRASTAT FOREIGN KEY (CODDINTRASTAT) REFERENCES DINTRASTAT (CODDINTRASTAT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DINTRASTATD_DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DINTRASTATD</REFTABLE>
  <HASHVAL>32073F3EF6094DC9A5C56E2EF920961A5AB7B839</HASHVAL>
  <TEXT>ALTER TABLE DINTRASTATD ADD CONSTRAINT FK_DINTRASTATD_DINTRASTAT FOREIGN KEY (CODDINTRASTAT) REFERENCES DINTRASTAT (CODDINTRASTAT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DISCART_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCART</REFTABLE>
  <HASHVAL>2E226B1F9CF2561478C93579FAA279222C372531</HASHVAL>
  <TEXT>ALTER TABLE DISCART ADD CONSTRAINT FK_DISCART_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DISCART_NCLASEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISCART</REFTABLE>
  <HASHVAL>1A5331C4FC501472498CDF68905ABCD47A1AD4DD</HASHVAL>
  <TEXT>ALTER TABLE DISCART ADD CONSTRAINT FK_DISCART_NCLASEA FOREIGN KEY (CODCLASA) REFERENCES NCLASEA (CODCLASEA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DISTRIBCHELT_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DISTRIBCHELT</REFTABLE>
  <HASHVAL>975800E4CE00C314D09897C2F7AF3EF2611CA7EF</HASHVAL>
  <TEXT>ALTER TABLE DISTRIBCHELT ADD CONSTRAINT FK_DISTRIBCHELT_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DOCSUPLIM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DOCSUPLIM1</REFTABLE>
  <HASHVAL>462B48B8FE4674AA0786D3BDF4F21B07C5C0B38F</HASHVAL>
  <TEXT>ALTER TABLE DOCSUPLIM1 ADD CONSTRAINT FK_DOCSUPLIM1 FOREIGN KEY (CODDOCSUPLIM) REFERENCES DOCSUPLIM (CODDOCSUPLIM)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DVI1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI1</REFTABLE>
  <HASHVAL>4D5DAF52FA2A2A72D817FEA0B2BC847B6D4E18E6</HASHVAL>
  <TEXT>ALTER TABLE DVI1 ADD CONSTRAINT FK_DVI1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DVI1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI1</REFTABLE>
  <HASHVAL>1A8C3FCB88F0142F46E08FE51F730B427D7C41B2</HASHVAL>
  <TEXT>ALTER TABLE DVI1 ADD CONSTRAINT FK_DVI1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DVI_NCONT_CONTCHELT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI</REFTABLE>
  <HASHVAL>0F0C9A44A48D262B4465821FC726534D83202745</HASHVAL>
  <TEXT>ALTER TABLE DVI ADD CONSTRAINT FK_DVI_NCONT_CONTCHELT FOREIGN KEY (CONTCHELT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_DVI_NCONT_CONTTVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>DVI</REFTABLE>
  <HASHVAL>422FE231EB8347643B7825F5DFB3E12CE1833756</HASHVAL>
  <TEXT>ALTER TABLE DVI ADD CONSTRAINT FK_DVI_NCONT_CONTTVA FOREIGN KEY (CONTTVA) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ELEMENTEA_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEA</REFTABLE>
  <HASHVAL>8EB1A5446D65CD7D99FC489F0800B95A537BA9B8</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEA ADD CONSTRAINT FK_ELEMENTEA_ELEMENTE FOREIGN KEY (CODELEMENT) REFERENCES ELEMENTE (CODELEMENT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ELEMENTEC_ELEMENTEM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEC</REFTABLE>
  <HASHVAL>F2FB39AF76550DB5A31653C1E86197708EE197B2</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEC ADD CONSTRAINT FK_ELEMENTEC_ELEMENTEM FOREIGN KEY (CODELEMENTM) REFERENCES ELEMENTEM (CODELEMENTM)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ELEMENTEM_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ELEMENTEM</REFTABLE>
  <HASHVAL>E001471F44A971A96B6A3F313B2B625F23A25531</HASHVAL>
  <TEXT>ALTER TABLE ELEMENTEM ADD CONSTRAINT FK_ELEMENTEM_ELEMENTE FOREIGN KEY (CODELEMENT) REFERENCES ELEMENTE (CODELEMENT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_EMULARE1_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>EMULARE1</REFTABLE>
  <HASHVAL>06ED83425937E6000D43E2ADB33D346B404E33FB</HASHVAL>
  <TEXT>ALTER TABLE EMULARE1 ADD CONSTRAINT FK_EMULARE1_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ESTIMARINOD_C1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARINOD_C1</REFTABLE>
  <HASHVAL>B812D4713BAA43A7509D3ECCD6D42349BE8B30A7</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARINOD_C1 ADD CONSTRAINT FK_ESTIMARINOD_C1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_ESTIMARINOD_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>ESTIMARINOD</REFTABLE>
  <HASHVAL>1F52F372C0434DE7EF3E5B53FDBFCB0AF585F531</HASHVAL>
  <TEXT>ALTER TABLE ESTIMARINOD ADD CONSTRAINT FK_ESTIMARINOD_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAINF_FISAPRO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAINF</REFTABLE>
  <HASHVAL>37E27E44AA5A16472A271ACD7B42B25A416352FE</HASHVAL>
  <TEXT>ALTER TABLE FISAINF ADD CONSTRAINT FK_FISAINF_FISAPRO FOREIGN KEY (CODFISAPRO) REFERENCES FISASUP (CODFISASUP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAMAND_FISAMAN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAMAND</REFTABLE>
  <HASHVAL>7F5ABFFFF452DFDF468383BFDDF79D90862853E0</HASHVAL>
  <TEXT>ALTER TABLE FISAMAND ADD CONSTRAINT FK_FISAMAND_FISAMAN FOREIGN KEY (CODFISAMAN) REFERENCES FISAMAN (CODFISAMAN)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAMAN_TRASEU</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAMAN</REFTABLE>
  <HASHVAL>4E95FD8A72715F665D5AE92D6A8053189AA8F5D1</HASHVAL>
  <TEXT>ALTER TABLE FISAMAN ADD CONSTRAINT FK_FISAMAN_TRASEU FOREIGN KEY (CODTRASEU) REFERENCES TRASEU (CODTRASEU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAREZ_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAREZ</REFTABLE>
  <HASHVAL>23E377B710D06754F32B2B83573A3C36E8FAA04D</HASHVAL>
  <TEXT>ALTER TABLE FISAREZ ADD CONSTRAINT FK_FISAREZ_NARTOBJ FOREIGN KEY (CODPREZ) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAREZ_NARTOBJ_GEN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAREZ</REFTABLE>
  <HASHVAL>E62426B8D20FF69A119E0399A7007BF7C0D9592A</HASHVAL>
  <TEXT>ALTER TABLE FISAREZ ADD CONSTRAINT FK_FISAREZ_NARTOBJ_GEN FOREIGN KEY (CODGENERIC) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISAREZ_TRASEU</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISAREZ</REFTABLE>
  <HASHVAL>E0CE17BCCA1B9699B06F0ED1723502ECACA59D46</HASHVAL>
  <TEXT>ALTER TABLE FISAREZ ADD CONSTRAINT FK_FISAREZ_TRASEU FOREIGN KEY (CODTRASEU) REFERENCES TRASEU (CODTRASEU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISASDV_NARTOBJ_GEN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISASDV</REFTABLE>
  <HASHVAL>B5B2A3B5BC2F2B5F0F9C724C1F3E306F145E78F4</HASHVAL>
  <TEXT>ALTER TABLE FISASDV ADD CONSTRAINT FK_FISASDV_NARTOBJ_GEN FOREIGN KEY (CODGENERIC) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISASUP_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISASUP</REFTABLE>
  <HASHVAL>5E8DB24F3B7E3AE3901C7171E48297141D27A3EB</HASHVAL>
  <TEXT>ALTER TABLE FISASUP ADD CONSTRAINT FK_FISASUP_NARTOBJ FOREIGN KEY (CODOBIECTNOD) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FISASUP_PROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FISASUP</REFTABLE>
  <HASHVAL>FD5AD62C4402047D8E4F5D7801CFF493AF825A3E</HASHVAL>
  <TEXT>ALTER TABLE FISASUP ADD CONSTRAINT FK_FISASUP_PROIECTNOD FOREIGN KEY (CODPROIECTNOD) REFERENCES PROIECTNOD (CODPROIECTNOD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FORMATII1_FORMATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FORMATII1</REFTABLE>
  <HASHVAL>78F6912F72B7BB053C3D92398ED1006FA6CE4155</HASHVAL>
  <TEXT>ALTER TABLE FORMATII1 ADD CONSTRAINT FK_FORMATII1_FORMATII FOREIGN KEY (CODFORMATIE) REFERENCES FORMATII (CODFORMATIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FORMATII1_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>FORMATII1</REFTABLE>
  <HASHVAL>6B24059BB8D5F113C2847B3C5247DB50AC09CAA9</HASHVAL>
  <TEXT>ALTER TABLE FORMATII1 ADD CONSTRAINT FK_FORMATII1_LOCMUNCA FOREIGN KEY (LOCMUNCA) REFERENCES LOCMUNCA (CODLOC)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_FORMATORI_TEME</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TEME</REFTABLE>
  <HASHVAL>B58AAA72153C09D630D2897E3057FC01F7B8EA1D</HASHVAL>
  <TEXT>ALTER TABLE TEME ADD CONSTRAINT FK_FORMATORI_TEME FOREIGN KEY (CODFORMATOR) REFERENCES FORMATORI (CODFORMATOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_GENERALREG_GENERAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GENERAL_REG</REFTABLE>
  <HASHVAL>82EB0191FF771DAFA15D8ECDCAC41E82459F67ED</HASHVAL>
  <TEXT>ALTER TABLE GENERAL_REG ADD CONSTRAINT FK_GENERALREG_GENERAL FOREIGN KEY (CODGENERAL) REFERENCES GENERAL (CODGENERAL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_GENERAL_MONEDE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>GENERAL</REFTABLE>
  <HASHVAL>6A59E34E14491E942454871D7365A083BEFA60E0</HASHVAL>
  <TEXT>ALTER TABLE GENERAL ADD CONSTRAINT FK_GENERAL_MONEDE FOREIGN KEY (MONEDA) REFERENCES NMONEDE (CODMONEDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESDISC_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESDISC</REFTABLE>
  <HASHVAL>CB35C52BE1ED4FA4CD210BF813CA3221DCA64825</HASHVAL>
  <TEXT>ALTER TABLE IESDISC ADD CONSTRAINT FK_IESDISC_CODDISCOUNT FOREIGN KEY (CODDISCOUNT) REFERENCES DISCOUNT (CODDISCOUNT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESDISC_CODIES</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESDISC</REFTABLE>
  <HASHVAL>56A9C20B2331CCFF630D1BA990C3BB56F737C8C1</HASHVAL>
  <TEXT>ALTER TABLE IESDISC ADD CONSTRAINT FK_IESDISC_CODIES FOREIGN KEY (CODIES) REFERENCES IESIRI (CODIES)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI1_IESIRI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>45C79D4740DBBC9020A05C7524FE910C83D46DCE</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT FK_IESIRI1_IESIRI FOREIGN KEY (CODIES) REFERENCES IESIRI (CODIES)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>A534740B395C7EB6BEE5D7ED0A385C00F6F17770</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT FK_IESIRI1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI1_NCONT_CONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>4655DA7CC30D166CDB6310E4E748B03BD31CD024</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT FK_IESIRI1_NCONT_CONT FOREIGN KEY (CONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI1_NCONT_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>75B4B8C1814D6B04B6C205315DE7B9A7E50C307E</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT FK_IESIRI1_NCONT_CONTSERV FOREIGN KEY (CONTSERV) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI1</REFTABLE>
  <HASHVAL>8FBC69A82AF33BD58B208868D6500BA339E552BF</HASHVAL>
  <TEXT>ALTER TABLE IESIRI1 ADD CONSTRAINT FK_IESIRI1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI_IOART_CONTINTERMED</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>2341F3304032B2BFDE78A630D1A2F1D9ACAF58FD</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT FK_IESIRI_IOART_CONTINTERMED FOREIGN KEY (CONTINTERMED) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>5E92859A4FB1F5556CB48BD63A3B10B2F1BFC29C</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT FK_IESIRI_NAGENDA FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI_NCONT_CONTDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>C5ADF60D848856275D0C90B196ADF497C4C49A19</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT FK_IESIRI_NCONT_CONTDISCOUNT FOREIGN KEY (CONTDISCOUNT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESIRI_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>73F62DC8784025715E1249CDAE1B30E818E86BCD</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT FK_IESIRI_NSUBUNIT FOREIGN KEY (CODSUBUNIT) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESLINK_CODLINIEAVIZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESLINK</REFTABLE>
  <HASHVAL>DA3908DD2B7E803A6CB8959347000707AF95A505</HASHVAL>
  <TEXT>ALTER TABLE IESLINK ADD CONSTRAINT FK_IESLINK_CODLINIEAVIZ FOREIGN KEY (CODLINIEAVIZ) REFERENCES IESIRI1 (CODIES1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESLINK_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESLINK</REFTABLE>
  <HASHVAL>740026B0F22FE89C3751BA2C7FC924AD1FC913A4</HASHVAL>
  <TEXT>ALTER TABLE IESLINK ADD CONSTRAINT FK_IESLINK_COMANDA1 FOREIGN KEY (CODLINIECOMANDA) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESPRODLINK_CMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESPRODLINK</REFTABLE>
  <HASHVAL>0DFF0FC119CEDF4B4C8562E27B1CE75227F91C13</HASHVAL>
  <TEXT>ALTER TABLE IESPRODLINK ADD CONSTRAINT FK_IESPRODLINK_CMDPRODMAT FOREIGN KEY (CODCMDPRODMAT) REFERENCES CMDPRODMAT (CODCMDPRODMAT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IESPUNCTE_IESIRI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESPUNCTE</REFTABLE>
  <HASHVAL>925498D9A32F988CF5CCFC0BF30066515E4627B8</HASHVAL>
  <TEXT>ALTER TABLE IESPUNCTE ADD CONSTRAINT FK_IESPUNCTE_IESIRI FOREIGN KEY (CODIES) REFERENCES IESIRI (CODIES)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IES_NSUBUNIT_SUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IESIRI</REFTABLE>
  <HASHVAL>D14FD550C43281A39FB068883C82E6C306F64610</HASHVAL>
  <TEXT>ALTER TABLE IESIRI ADD CONSTRAINT FK_IES_NSUBUNIT_SUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI1</REFTABLE>
  <HASHVAL>3A526ADE1DFF9A4C2D947B75B742BE796638BDB9</HASHVAL>
  <TEXT>ALTER TABLE INTRARI1 ADD CONSTRAINT FK_INTRARI1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI1_NCONT_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI1</REFTABLE>
  <HASHVAL>C6D53F07E5DC8D1992BBD17D863F3BF9AD402DA9</HASHVAL>
  <TEXT>ALTER TABLE INTRARI1 ADD CONSTRAINT FK_INTRARI1_NCONT_CONTSERV FOREIGN KEY (CONTSERV) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI1</REFTABLE>
  <HASHVAL>8D99CC94F591FFBEDD936B8E8EB2AD6865DFB49C</HASHVAL>
  <TEXT>ALTER TABLE INTRARI1 ADD CONSTRAINT FK_INTRARI1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI</REFTABLE>
  <HASHVAL>A0816836CD5572CBBD31B6C08AA363FF6C6027E7</HASHVAL>
  <TEXT>ALTER TABLE INTRARI ADD CONSTRAINT FK_INTRARI_NAGENDA FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI_NCONT_CONTSUPLIM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI</REFTABLE>
  <HASHVAL>B05E33BB2038F60F59D48E4829D2522B4D355059</HASHVAL>
  <TEXT>ALTER TABLE INTRARI ADD CONSTRAINT FK_INTRARI_NCONT_CONTSUPLIM FOREIGN KEY (CONTSUPLIM) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRARI_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI</REFTABLE>
  <HASHVAL>03F1E07318DE3649ED9566FB5E8FA22A1AE9D71D</HASHVAL>
  <TEXT>ALTER TABLE INTRARI ADD CONSTRAINT FK_INTRARI_NSUBUNIT FOREIGN KEY (CODSUBUNIT) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRLINK_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRLINK</REFTABLE>
  <HASHVAL>14DE41583D3E068D3F45EE889E6E528528FBF0B7</HASHVAL>
  <TEXT>ALTER TABLE INTRLINK ADD CONSTRAINT FK_INTRLINK_COMANDA1 FOREIGN KEY (CODLINIECOMANDA) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRLINK_INTRARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRLINK</REFTABLE>
  <HASHVAL>ECC79A9C57BC86EFD19AA984AFE97EC7908CD3BA</HASHVAL>
  <TEXT>ALTER TABLE INTRLINK ADD CONSTRAINT FK_INTRLINK_INTRARI1 FOREIGN KEY (CODLINIEAVIZ) REFERENCES INTRARI1 (CODINTR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRPRODLINK_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRPRODLINK</REFTABLE>
  <HASHVAL>D9146028EC012B57C9A0A5891CED41D6E37E60A4</HASHVAL>
  <TEXT>ALTER TABLE INTRPRODLINK ADD CONSTRAINT FK_INTRPRODLINK_COMANDA1 FOREIGN KEY (CODLINIECOMANDA) REFERENCES CMDPRODMAT (CODCMDPRODMAT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTRPRODLINK_INTRARI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRPRODLINK</REFTABLE>
  <HASHVAL>F65BEE71A4B21B8F755DB94374E92BA3C9953A75</HASHVAL>
  <TEXT>ALTER TABLE INTRPRODLINK ADD CONSTRAINT FK_INTRPRODLINK_INTRARI1 FOREIGN KEY (CODLINIEAVIZ) REFERENCES INTRARI1 (CODINTR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INTR_NSUBUNIT_SUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INTRARI</REFTABLE>
  <HASHVAL>2520CD0479E1ED06C5D4FB1B4BF638BFDBE339C8</HASHVAL>
  <TEXT>ALTER TABLE INTRARI ADD CONSTRAINT FK_INTR_NSUBUNIT_SUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_INVENTREZ_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>INVENTREZ</REFTABLE>
  <HASHVAL>BFF8642B2339587D3C67168B24092C1DFDA3C71E</HASHVAL>
  <TEXT>ALTER TABLE INVENTREZ ADD CONSTRAINT FK_INVENTREZ_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_CHELTUIELI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>00C8EB9DFF5D5DF1DCDF158A18507F396FF48535</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_CHELTUIELI FOREIGN KEY (CHELTUIELI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_CHTTVACOLEC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>DDFB12ECBE3D311073F7CEB9DD41EF9D7D69AED8</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_CHTTVACOLEC FOREIGN KEY (CHELTTVACOLECTAT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_CONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>A997480B8B67BFD0A2CC2DBC7C9581CB02C4555A</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_CONT FOREIGN KEY (CONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_CONTROTUNJIRI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>9833BFBFECCC9B3A559CBE77A57612424DCC1761</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_CONTROTUNJIRI FOREIGN KEY (CONTROTUNJIRI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_DIFERENTE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>0C5135F654EC26E2AB6B2CB0FE807408AE90CBEA</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_DIFERENTE FOREIGN KEY (DIFERENTE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_DIVERSE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>2AD347228485C63D09C5884FE879BAC12A4C15E4</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_DIVERSE FOREIGN KEY (DIVERSE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_MINUSINVENTAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>64B83E390E655B05B6A64AF7EE58D0E4E5BD7EB6</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_MINUSINVENTAR FOREIGN KEY (MINUSINVENTAR) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_PLUSINVENTAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>1323A488BF9F36689FD9C25257ED353224B08085</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_PLUSINVENTAR FOREIGN KEY (PLUSINVENTAR) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART1_NCONT_VENITURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>D3273DC18E1B4EFF899B5F8CEDC74F76EE2B51CE</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT FK_IOART1_NCONT_VENITURI FOREIGN KEY (VENITURI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOART_CODIOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CHELTAVANS</REFTABLE>
  <HASHVAL>C7C21CCA667348E3F82CF6948A89344708DD88B7</HASHVAL>
  <TEXT>ALTER TABLE CHELTAVANS ADD CONSTRAINT FK_IOART_CODIOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOFILIAL1_NCONT_CONTCB</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>E2F191818CD6334B83F41B8EE235DC5A4BA8E444</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT FK_IOFILIAL1_NCONT_CONTCB FOREIGN KEY (CONTDECONTCB) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOFILIAL1_NCONT_CONTCMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>878F600AF8660CEC488902A9063672E91260D20B</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT FK_IOFILIAL1_NCONT_CONTCMP FOREIGN KEY (CONTDECONTCMP) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOFILIAL1_NCONT_CONTDECONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>361907C6571DE27008C9B01A91D4CFB42A42A630</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT FK_IOFILIAL1_NCONT_CONTDECONT FOREIGN KEY (CONTDECONTARE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOFILIAL1_NCONT_CONTDECONTF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>94779743DE7404FDBF61EC041BC1A12F613F8F8A</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT FK_IOFILIAL1_NCONT_CONTDECONTF FOREIGN KEY (CONTDECONTAREF) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOFILIAL1_NCONT_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOFILIAL1</REFTABLE>
  <HASHVAL>1ACF84397067687C4B133665C51043F8AB07B3EE</HASHVAL>
  <TEXT>ALTER TABLE IOFILIAL1 ADD CONSTRAINT FK_IOFILIAL1_NCONT_CONTSERV FOREIGN KEY (CONTDECONTSERV) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTALTERET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>96226999CD44E1D2C673F4BB3B09C7F419E0DAED</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTALTERET FOREIGN KEY (CONTALTERETINERI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTAVANS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>468DF79D793B524530E58EE002CC933518AD7C8D</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTAVANS FOREIGN KEY (CONTAVANS) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTAVDECONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>DA4299035E64FBCFE6FBB594D82210A33EFE4F05</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTAVDECONT FOREIGN KEY (CONTAVANSDECONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTBOALA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>89512BA7CD61193A923F73EC12B71936FE84B941</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTBOALA FOREIGN KEY (CONTBOALA) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTECHIP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>799E8D782863006676C408E515B86729504839FB</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTECHIP FOREIGN KEY (CONTECHIPAMENT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTGARANTII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>BA28B2393102B7EF50416628FBE59BBC1D997F0F</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTGARANTII FOREIGN KEY (CONTGARANTII) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTIMPOZIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>B7B1B2C1565A657E51CAB592F190DD32CD7312D4</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTIMPOZIT FOREIGN KEY (CONTIMPOZIT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTIMPUTATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>679C145CBD0CCAC2B97D11FEAB8347E72292B571</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTIMPUTATII FOREIGN KEY (CONTIMPUTATII) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTLIKI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>522BB838697C0137811B4887146A212367EF8965</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTLIKI FOREIGN KEY (CONTLIKI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTNATURA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>A044168A96210A1876E041C54BD59873C63B55EC</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTNATURA FOREIGN KEY (CONTNATURA) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_IOPERS1_NCONT_CONTNERID</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>FB6A47C8994BB0CBA52A4B18742B42F11EAA3986</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT FK_IOPERS1_NCONT_CONTNERID FOREIGN KEY (CONTNERIDICATE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_JOBLISTE_ORAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>JOBLISTE</REFTABLE>
  <HASHVAL>D706B2A1671EF1165FE5511DD55E156E6315D966</HASHVAL>
  <TEXT>ALTER TABLE JOBLISTE ADD CONSTRAINT FK_JOBLISTE_ORAR FOREIGN KEY (CODORAR) REFERENCES ORAR (CODORAR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LANSZ1_LANSZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ1</REFTABLE>
  <HASHVAL>52ADE3062254CDD6940F39A5D9DCB4DFF96FF035</HASHVAL>
  <TEXT>ALTER TABLE LANSZ1 ADD CONSTRAINT FK_LANSZ1_LANSZ FOREIGN KEY (CODLANSZ) REFERENCES LANSZ (CODLANSZ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LANSZ1_NFORMATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ1</REFTABLE>
  <HASHVAL>262CAA80070557F52F2D4681CC7108A6B47E6BD5</HASHVAL>
  <TEXT>ALTER TABLE LANSZ1 ADD CONSTRAINT FK_LANSZ1_NFORMATII FOREIGN KEY (CODFORMATIE) REFERENCES FORMATII (CODFORMATIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LANSZ1_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ1</REFTABLE>
  <HASHVAL>750E58A34A9E6112D77BB34BE4A3E2312D599A5F</HASHVAL>
  <TEXT>ALTER TABLE LANSZ1 ADD CONSTRAINT FK_LANSZ1_PRODCOMP FOREIGN KEY (CODRETETA) REFERENCES PRODCOMP (CODPRODCOMP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LANSZ_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LANSZ</REFTABLE>
  <HASHVAL>98C74179831B3F07AC6315BFEEB15ADFBE6F1E4F</HASHVAL>
  <TEXT>ALTER TABLE LANSZ ADD CONSTRAINT FK_LANSZ_PLANIFPROD FOREIGN KEY (CODPLANIFPROD) REFERENCES PLANIFPROD (CODPLANIFPROD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LIVR1_LIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVR1</REFTABLE>
  <HASHVAL>22CF459D39E456A379F582E2CFA7CA4E07B3372C</HASHVAL>
  <TEXT>ALTER TABLE LIVR1 ADD CONSTRAINT FK_LIVR1_LIVR FOREIGN KEY (CODLIVR) REFERENCES LIVR (CODLIVR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LIVR1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVR1</REFTABLE>
  <HASHVAL>C4BC3F1F09A9768F53CCBCEAE6AF3B55C101F82D</HASHVAL>
  <TEXT>ALTER TABLE LIVR1 ADD CONSTRAINT FK_LIVR1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LIVRVAL_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVRVAL</REFTABLE>
  <HASHVAL>99AAF1EDD36198D6CDF9966A9C1716ED89FC9E42</HASHVAL>
  <TEXT>ALTER TABLE LIVRVAL ADD CONSTRAINT FK_LIVRVAL_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_LIVRVAL_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>LIVRVAL</REFTABLE>
  <HASHVAL>76BD003BF70314F9E46B6A0556D78FC655B57921</HASHVAL>
  <TEXT>ALTER TABLE LIVRVAL ADD CONSTRAINT FK_LIVRVAL_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_MASTERMIFIX_NIRSTOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MASTERMIFIX</REFTABLE>
  <HASHVAL>6DC5910891C45E1A0B01191E1B43E1AD0F0B0D4F</HASHVAL>
  <TEXT>ALTER TABLE MASTERMIFIX ADD CONSTRAINT FK_MASTERMIFIX_NIRSTOC FOREIGN KEY (CODNIRSTOC) REFERENCES NIRSTOC (CODNIRSTOC)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_MENUDAE_MENUDATE1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MENUDATE1</REFTABLE>
  <HASHVAL>AF4B133B7E91C5E3F0543F5330F26D04AD79484F</HASHVAL>
  <TEXT>ALTER TABLE MENUDATE1 ADD CONSTRAINT FK_MENUDAE_MENUDATE1 FOREIGN KEY (CODMENUDATE) REFERENCES MENUDATE (CODMENUDATE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_MIFIX1_MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MIFIX1</REFTABLE>
  <HASHVAL>65291416F155065B8CDB02CD3BC1340CE1DC3ED5</HASHVAL>
  <TEXT>ALTER TABLE MIFIX1 ADD CONSTRAINT FK_MIFIX1_MFCLASIF FOREIGN KEY (CODCLASIF) REFERENCES MFCLASIF (CODCLASIF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_MIFIX1_MIFIX</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MIFIX1</REFTABLE>
  <HASHVAL>A1ED7C08BFF8DD878966E24D0B874B22C0EEB6FE</HASHVAL>
  <TEXT>ALTER TABLE MIFIX1 ADD CONSTRAINT FK_MIFIX1_MIFIX FOREIGN KEY (CODMIFIX) REFERENCES MIFIX (CODMIFIX)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_MIFIX1_NIRSTOC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>MIFIX1</REFTABLE>
  <HASHVAL>8AC8F70C8B6BCDB950EBF568294BA81BF55EB6B3</HASHVAL>
  <TEXT>ALTER TABLE MIFIX1 ADD CONSTRAINT FK_MIFIX1_NIRSTOC FOREIGN KEY (CODNIRSTOC) REFERENCES NIRSTOC (CODNIRSTOC)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NAGENDA_LOCALIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NAGENDA</REFTABLE>
  <HASHVAL>C4AD570FEEE9264D769B4AA07173F9E5F94D4197</HASHVAL>
  <TEXT>ALTER TABLE NAGENDA ADD CONSTRAINT FK_NAGENDA_LOCALIT FOREIGN KEY (CODLOCALIT) REFERENCES NLOCALIT (CODLOCALIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART1_NART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>1B1799BF9D7D1D3BD2F702CAB985AC016767E24B</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT FK_NART1_NART FOREIGN KEY (CODARTICOL) REFERENCES NART (CODARTICOL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART1_NTAXE_CODACCIZE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>562AD1805B8EECC9959B43F25907E13DA3B9469B</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT FK_NART1_NTAXE_CODACCIZE FOREIGN KEY (CODACCIZE) REFERENCES NTAXE (CODTAXA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART1_NTAXE_CODTAXA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>4AC3ACF728C625A0ACFC9262E0E7F0187FF8D00E</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT FK_NART1_NTAXE_CODTAXA1 FOREIGN KEY (CODTAXA1) REFERENCES NTAXE (CODTAXA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART1_NTAXE_CODTAXA2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>79619D118C006D189618BD723D087A72EB90741A</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT FK_NART1_NTAXE_CODTAXA2 FOREIGN KEY (CODTAXA2) REFERENCES NTAXE (CODTAXA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART1_NTVA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART1</REFTABLE>
  <HASHVAL>A6DFD517FA8FCD1AD294E649CEC7B0B9BEA1CF12</HASHVAL>
  <TEXT>ALTER TABLE NART1 ADD CONSTRAINT FK_NART1_NTVA FOREIGN KEY (CODTVA) REFERENCES NTVA (CODTVA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTAMB_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTAMB</REFTABLE>
  <HASHVAL>12DF2FA941A4ABB481F1C70BC97966F6B0FCC018</HASHVAL>
  <TEXT>ALTER TABLE NARTAMB ADD CONSTRAINT FK_NARTAMB_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTATR_NART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTATR</REFTABLE>
  <HASHVAL>0650375A6E7EC190B0051F01A76055617B523170</HASHVAL>
  <TEXT>ALTER TABLE NARTATR ADD CONSTRAINT FK_NARTATR_NART FOREIGN KEY (CODARTICOL) REFERENCES NART (CODARTICOL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTCLI_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTCLI</REFTABLE>
  <HASHVAL>530E3332D76A3F2637649A0719738539EBC47EB7</HASHVAL>
  <TEXT>ALTER TABLE NARTCLI ADD CONSTRAINT FK_NARTCLI_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTCLI_NUM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTCLI</REFTABLE>
  <HASHVAL>13606795483824405042D8675F3F74E8F3EA6BC8</HASHVAL>
  <TEXT>ALTER TABLE NARTCLI ADD CONSTRAINT FK_NARTCLI_NUM FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTDIM_NART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTDIM</REFTABLE>
  <HASHVAL>387C15912C24F785F9A624B9F16B2D3B4DE3C00A</HASHVAL>
  <TEXT>ALTER TABLE NARTDIM ADD CONSTRAINT FK_NARTDIM_NART FOREIGN KEY (CODARTICOL) REFERENCES NART (CODARTICOL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTIMPLICITE_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTIMPLICITE</REFTABLE>
  <HASHVAL>6C64F5001BF890BF837C753283F29C44D9361B02</HASHVAL>
  <TEXT>ALTER TABLE NARTIMPLICITE ADD CONSTRAINT FK_NARTIMPLICITE_IOART FOREIGN KEY (CONTIMPLICIT) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTOBJ1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJ1</REFTABLE>
  <HASHVAL>FE928B3045F9BF065F2E906E192BDE3BAADED76A</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJ1 ADD CONSTRAINT FK_NARTOBJ1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTOBJ_NART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOBJ</REFTABLE>
  <HASHVAL>813C57A572A32347F0EC6FD3AC4DEFB2B28260B7</HASHVAL>
  <TEXT>ALTER TABLE NARTOBJ ADD CONSTRAINT FK_NARTOBJ_NART FOREIGN KEY (CODARTICOL) REFERENCES NART (CODARTICOL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTOPT1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOPT</REFTABLE>
  <HASHVAL>F302D6A0DEABF9F83EADE72F548C213C7A547754</HASHVAL>
  <TEXT>ALTER TABLE NARTOPT ADD CONSTRAINT FK_NARTOPT1_NARTOBJ FOREIGN KEY (CODOBIECTOPT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NARTOPT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTOPT</REFTABLE>
  <HASHVAL>254DB04096575D6C0E8DEC72AEB46BC926ACC63F</HASHVAL>
  <TEXT>ALTER TABLE NARTOPT ADD CONSTRAINT FK_NARTOPT_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>9323246ED34AC3D904E8938C112A5E1781B58831</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT FK_NART_IOART FOREIGN KEY (CONTIMPLICIT) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART_NCLASEAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>E01A313BD19494F7044748DEFD809BD53BF8A12E</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT FK_NART_NCLASEAS FOREIGN KEY (CLASAW) REFERENCES NCLASEAS (CODCLASEAS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART_NCONT_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>FBF789A98A2082A988AD0092DBDB761B1BDD7D26</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT FK_NART_NCONT_CONTSERV FOREIGN KEY (CONTSERVICIU) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART_NLASEAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>6E9A352A6D088C23E93428076E2399A028F92AD5</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT FK_NART_NLASEAS FOREIGN KEY (CLASASTATIST) REFERENCES NCLASEAS (CODCLASEAS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NART_NUM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NART</REFTABLE>
  <HASHVAL>ED6190744A71CCC70CAB33E88949854C37552AAC</HASHVAL>
  <TEXT>ALTER TABLE NART ADD CONSTRAINT FK_NART_NUM FOREIGN KEY (UM) REFERENCES NUM (CODUM)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NATROBJ_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATROBJ</REFTABLE>
  <HASHVAL>2745CED10BF01A7D53A3E334FDD6144CBD8772B1</HASHVAL>
  <TEXT>ALTER TABLE NATROBJ ADD CONSTRAINT FK_NATROBJ_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NBANKCONT_LOCALIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT</REFTABLE>
  <HASHVAL>FB31C01EA7995BAEFB75B21833C78C1E4B1DDE93</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT ADD CONSTRAINT FK_NBANKCONT_LOCALIT FOREIGN KEY (CODLOCALITATE) REFERENCES NLOCALIT (CODLOCALIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NC1_NCONT_CONTC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC1</REFTABLE>
  <HASHVAL>75B7392D30FF47256AFA61AD024A4C364039999E</HASHVAL>
  <TEXT>ALTER TABLE NC1 ADD CONSTRAINT FK_NC1_NCONT_CONTC FOREIGN KEY (CONTC) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NC1_NCONT_CONTD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC1</REFTABLE>
  <HASHVAL>92E847C9370C197F6D24DA384F1F891BFA35355A</HASHVAL>
  <TEXT>ALTER TABLE NC1 ADD CONSTRAINT FK_NC1_NCONT_CONTD FOREIGN KEY (CONTD) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NC1_NGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC1</REFTABLE>
  <HASHVAL>05E99C1C9A0BEDD8EEDE05BE2463DC313DB04115</HASHVAL>
  <TEXT>ALTER TABLE NC1 ADD CONSTRAINT FK_NC1_NGEST FOREIGN KEY (CODGEST) REFERENCES NGEST (CODGEST)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT1_NCONT_CONTINKIDSOLD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>7C3DCE9131A8141A4409A8221C43B927C282BE29</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT FK_NCONT1_NCONT_CONTINKIDSOLD FOREIGN KEY (CONTINKIDSOLD) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT1_NCONT_CONTTRANSFC</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>81E139BAA605DC760CC58BCA83D1FFF18373BE0D</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT FK_NCONT1_NCONT_CONTTRANSFC FOREIGN KEY (CONTTRANSFC) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT1_NCONT_CONTTRANSFD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>1A9196BBCE1D14145CEEEA201C22378C40D5BA6C</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT FK_NCONT1_NCONT_CONTTRANSFD FOREIGN KEY (CONTTRANSFD) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT1_NCONT_SINCRONIZARE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>07DE42353D8B082FA3674E0451FC825DBE9D9098</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT FK_NCONT1_NCONT_SINCRONIZARE FOREIGN KEY (SINCRONIZARE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONTREPRUL_NCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREPRUL</REFTABLE>
  <HASHVAL>7F1CC51905C0AF7E36D039FC00ECEC27B43608A8</HASHVAL>
  <TEXT>ALTER TABLE NCONTREPRUL ADD CONSTRAINT FK_NCONTREPRUL_NCONT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONTREPSOLD_NCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREPSOLD</REFTABLE>
  <HASHVAL>423706DC4575C90713920852D7F84518A5D49830</HASHVAL>
  <TEXT>ALTER TABLE NCONTREPSOLD ADD CONSTRAINT FK_NCONTREPSOLD_NCONT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONTREP_NCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTREP</REFTABLE>
  <HASHVAL>92EFEAAC3D4F6EE97CD3AE60D2005C63B84DEE3B</HASHVAL>
  <TEXT>ALTER TABLE NCONTREP ADD CONSTRAINT FK_NCONTREP_NCONT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONTRIB_SAL_NASIG0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG3</REFTABLE>
  <HASHVAL>ABE13490D26B2678AC55B2A1734EF5483261F562</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG3 ADD CONSTRAINT FK_NCONTRIB_SAL_NASIG0 FOREIGN KEY (CONTRIBUTIE) REFERENCES SAL_NCONTRIB (CODNCONTRIB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONTSOLD_NCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLD</REFTABLE>
  <HASHVAL>392F03012F72AD1660C5158FCBB8A3968037983E</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLD ADD CONSTRAINT FK_NCONTSOLD_NCONT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NASIG0_CNT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG0</REFTABLE>
  <HASHVAL>A720F431DC0ABE333DD735C1A63751C6476A028A</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG0 ADD CONSTRAINT FK_NCONT_SAL_NASIG0_CNT1 FOREIGN KEY (CONT1) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NASIG0_CNT2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG0</REFTABLE>
  <HASHVAL>A337222C44346011EF91F1221FCB0C719A32B3E8</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG0 ADD CONSTRAINT FK_NCONT_SAL_NASIG0_CNT2 FOREIGN KEY (CONT2) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NASIG3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG3</REFTABLE>
  <HASHVAL>47DE7AEABBF4796B1B23DD36FA645BDA9DB322FE</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG3 ADD CONSTRAINT FK_NCONT_SAL_NASIG3 FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NCONTRIB1_AMBP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>B05F0B34E63000F43782D0616A7A82621EC32DFB</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT FK_NCONT_SAL_NCONTRIB1_AMBP FOREIGN KEY (CODCONTAMBP) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NCONTRIB1_CAS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>D9A1A11254E029001CD715167BD9672640FEAF25</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT FK_NCONT_SAL_NCONTRIB1_CAS FOREIGN KEY (CODCONTCAS) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NCONTRIB1_CNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>F03FB805FE40BDE35BCA51EEFE982D4AC971F638</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT FK_NCONT_SAL_NCONTRIB1_CNT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NCONTRIB1_CNTCHLT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>D657CC3E3A921069C521B771F0321C393F6A53A8</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT FK_NCONT_SAL_NCONTRIB1_CNTCHLT FOREIGN KEY (CODCONTCHELT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NCONTRIB1_NCONTR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NCONTRIB1</REFTABLE>
  <HASHVAL>6347BA4696162BC51F1E2CB911FAE214487D32D7</HASHVAL>
  <TEXT>ALTER TABLE SAL_NCONTRIB1 ADD CONSTRAINT FK_NCONT_SAL_NCONTRIB1_NCONTR FOREIGN KEY (CODNCONTRIB) REFERENCES SAL_NCONTRIB (CODNCONTRIB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NCONT_SAL_NDREP0_CNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP0</REFTABLE>
  <HASHVAL>596785332A34C05FC261EA20C8F3A6AC2CC74960</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP0 ADD CONSTRAINT FK_NCONT_SAL_NDREP0_CNT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NC_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC</REFTABLE>
  <HASHVAL>E8BE7AB57B0D6820BEFE88BF0028DD0B0736063E</HASHVAL>
  <TEXT>ALTER TABLE NC ADD CONSTRAINT FK_NC_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NECHIV_GRECHIV</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NECHIV</REFTABLE>
  <HASHVAL>A5BF4C7EEB2338872800DB422466F9C8B0E1C7CC</HASHVAL>
  <TEXT>ALTER TABLE NECHIV ADD CONSTRAINT FK_NECHIV_GRECHIV FOREIGN KEY (CODGRUPA) REFERENCES GRECHIV (CODGRECHIV)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NECHIV_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NECHIV</REFTABLE>
  <HASHVAL>02F009C9177F381C0CDDB937DEF5A71FC1DFFE06</HASHVAL>
  <TEXT>ALTER TABLE NECHIV ADD CONSTRAINT FK_NECHIV_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NGEST1_NCONT_CHELTUIELI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST1</REFTABLE>
  <HASHVAL>50EB000255B1111FB8BF1F095D649E49D1EB3E6E</HASHVAL>
  <TEXT>ALTER TABLE NGEST1 ADD CONSTRAINT FK_NGEST1_NCONT_CHELTUIELI FOREIGN KEY (CHELTUIELI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NGEST1_NCONT_VENITURI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST1</REFTABLE>
  <HASHVAL>98C467C1C80E3772AB0CF665D8C4A46F4E7CB48A</HASHVAL>
  <TEXT>ALTER TABLE NGEST1 ADD CONSTRAINT FK_NGEST1_NCONT_VENITURI FOREIGN KEY (VENITURI) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSER_CODCERTIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSER</REFTABLE>
  <HASHVAL>392CAF984A0B501176B85F0DE338B87A0AAAEF27</HASHVAL>
  <TEXT>ALTER TABLE NIRSER ADD CONSTRAINT FK_NIRSER_CODCERTIF FOREIGN KEY (CODCERTIF) REFERENCES CERTIF (CODCERTIF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSER_NSERII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSER</REFTABLE>
  <HASHVAL>631A2661640C29CE08B5A322E25F3688AD39F5E1</HASHVAL>
  <TEXT>ALTER TABLE NIRSER ADD CONSTRAINT FK_NIRSER_NSERII FOREIGN KEY (CODSERIE) REFERENCES NSERII (CODSERIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSTOC_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC</REFTABLE>
  <HASHVAL>93EC42D820C80126611133972E434712E4A9FD18</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC ADD CONSTRAINT FK_NIRSTOC_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSTOC_LOCATIE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC</REFTABLE>
  <HASHVAL>1759C4613451B022AD702ADBC7C5FD1D1EA84400</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC ADD CONSTRAINT FK_NIRSTOC_LOCATIE FOREIGN KEY (CODLOCATIE) REFERENCES NLOCATII (CODLOCATIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSTOC_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC</REFTABLE>
  <HASHVAL>2DF283E780BA9450A55CAD6BC5E10C2A5BFFFE61</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC ADD CONSTRAINT FK_NIRSTOC_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIRSTOC_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIRSTOC</REFTABLE>
  <HASHVAL>FB121C3A58B6D88F9D56CBC6B4A8D7C1D290B394</HASHVAL>
  <TEXT>ALTER TABLE NIRSTOC ADD CONSTRAINT FK_NIRSTOC_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIR_INTRARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIR</REFTABLE>
  <HASHVAL>444103803035A72489C58DCCC9AF33D0974B916E</HASHVAL>
  <TEXT>ALTER TABLE NIR ADD CONSTRAINT FK_NIR_INTRARI FOREIGN KEY (CODINTR) REFERENCES INTRARI (CODINTR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NIR_NGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NIR</REFTABLE>
  <HASHVAL>92DC1C79275F48FA39F7E1E9DB8A824B2AA126E3</HASHVAL>
  <TEXT>ALTER TABLE NIR ADD CONSTRAINT FK_NIR_NGEST FOREIGN KEY (GEST) REFERENCES NGEST (CODGEST)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NLOCALIT_NJUDET</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLOCALIT</REFTABLE>
  <HASHVAL>3D91AC4C6566CA93F744E35442B4F76E01C9A322</HASHVAL>
  <TEXT>ALTER TABLE NLOCALIT ADD CONSTRAINT FK_NLOCALIT_NJUDET FOREIGN KEY (CODJUDET) REFERENCES NJUDET (CODJUDET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NLOCALIT_NTARI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLOCALIT</REFTABLE>
  <HASHVAL>368CC33FC01F4130B4A89FCE46B607CA9C37500E</HASHVAL>
  <TEXT>ALTER TABLE NLOCALIT ADD CONSTRAINT FK_NLOCALIT_NTARI FOREIGN KEY (CODTARA) REFERENCES NTARI (CODTARA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NLOCALIT_NZONE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NLOCALIT</REFTABLE>
  <HASHVAL>6AF5642EF2C5331FF0121EADF8C47EBCD1FF7E07</HASHVAL>
  <TEXT>ALTER TABLE NLOCALIT ADD CONSTRAINT FK_NLOCALIT_NZONE FOREIGN KEY (CODZONA) REFERENCES NZONE (CODZONA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NMODELEAUTO_CODMARCA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMODELEAUTO</REFTABLE>
  <HASHVAL>2768A007228C9ADC482747ED1DF5EFD1F3EDFE04</HASHVAL>
  <TEXT>ALTER TABLE NMODELEAUTO ADD CONSTRAINT FK_NMODELEAUTO_CODMARCA FOREIGN KEY (CODMARCIAUTO) REFERENCES NMARCIAUTO (CODMARCIAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NOPER_CLASAOP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOPER</REFTABLE>
  <HASHVAL>2241BCA4ADD4F19C334D39F75B3DF990409CB77D</HASHVAL>
  <TEXT>ALTER TABLE NOPER ADD CONSTRAINT FK_NOPER_CLASAOP FOREIGN KEY (CLASAOP) REFERENCES NCLASEOP (CODCLASEOP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NORMEMAT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NORMEMAT</REFTABLE>
  <HASHVAL>20ECCAA3A5B45FCCBE66748932DEEAA0EAE32E29</HASHVAL>
  <TEXT>ALTER TABLE NORMEMAT ADD CONSTRAINT FK_NORMEMAT_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NORMEMAT_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NORMEMAT</REFTABLE>
  <HASHVAL>5D138730F77C3CBAFEF36D85FF760DBBB9A5E3BF</HASHVAL>
  <TEXT>ALTER TABLE NORMEMAT ADD CONSTRAINT FK_NORMEMAT_PRODCOMP FOREIGN KEY (CODPRODCOMP) REFERENCES PRODCOMP (CODPRODCOMP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NORMEMAT_PRODNORME</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NORMEMAT</REFTABLE>
  <HASHVAL>7F17B8033F243B227F309E06BC579475EE8E8134</HASHVAL>
  <TEXT>ALTER TABLE NORMEMAT ADD CONSTRAINT FK_NORMEMAT_PRODNORME FOREIGN KEY (CODNORMA) REFERENCES PRODNORME (CODNORMA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NOTACREDIT1_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NOTECREDIT1</REFTABLE>
  <HASHVAL>626B6532B4BFE834D66337FA1C38AA2D1BB0EA98</HASHVAL>
  <TEXT>ALTER TABLE NOTECREDIT1 ADD CONSTRAINT FK_NOTACREDIT1_CODDISCOUNT FOREIGN KEY (CODDISCOUNT) REFERENCES DISCOUNT (CODDISCOUNT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARC1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC1</REFTABLE>
  <HASHVAL>A6E16987D00750AD4A2C6F5FE7B8D68DF04332F7</HASHVAL>
  <TEXT>ALTER TABLE NPARC1 ADD CONSTRAINT FK_NPARC1_NARTOBJ FOREIGN KEY (ART) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARC3_NINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARC3</REFTABLE>
  <HASHVAL>AB67670F161CB809BCDB790085F6BFED6030E109</HASHVAL>
  <TEXT>ALTER TABLE NPARC3 ADD CONSTRAINT FK_NPARC3_NINTERVENTIIAUTO FOREIGN KEY (INTERVENTIE) REFERENCES NINTERVENTIIAUTO (CODINTERVENTIIAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NELEMAEROAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>FA0A1E11630EDA5D8A9CEC0357E42636C69318DE</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NELEMAEROAUTO FOREIGN KEY (AER) REFERENCES NELEMAEROAUTO (CODELEMAEROAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>E3CD3AD1C5640B0A0DA13A9B3499A8F308C784C0</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NGRUPEAUTO FOREIGN KEY (GRUPAUTO) REFERENCES NGRUPEAUTO (CODGRUPEAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>6FD0ACE8E7F4C00CDB8B9CBE3CE9BF2BA87B548C</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NINSTAUTO FOREIGN KEY (INSTSP) REFERENCES NINSTAUTO (CODINSTAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>ADDF17265F0667DE12A29C2D628D8B0DE48923C7</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NMARCIAUTO FOREIGN KEY (MARCA) REFERENCES NMARCIAUTO (CODMARCIAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>DC192DB8DEAB2C399970C80C03A8067D32709356</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NMODELEAUTO FOREIGN KEY (MODEL) REFERENCES NMODELEAUTO (CODMODELEAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCAUT_NREMAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCAUT</REFTABLE>
  <HASHVAL>C4CAD4332D53352157504A5A0148C184FFC303A7</HASHVAL>
  <TEXT>ALTER TABLE NPARCAUT ADD CONSTRAINT FK_NPARCAUT_NREMAUTO FOREIGN KEY (TIPREM) REFERENCES NREMAUTO (CODREMAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARCCOM_COMANDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARCCOM</REFTABLE>
  <HASHVAL>0D727D5FAA0280FCCCADC12D0284DB72496F5EDF</HASHVAL>
  <TEXT>ALTER TABLE NPARCCOM ADD CONSTRAINT FK_NPARCCOM_COMANDA FOREIGN KEY (CODCOMANDA) REFERENCES COMANDA (CODCOMANDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPART1_IOPART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPART1</REFTABLE>
  <HASHVAL>5DC848A8E03D1C17CAF97E4087530A75B13EE73D</HASHVAL>
  <TEXT>ALTER TABLE NPART1 ADD CONSTRAINT FK_NPART1_IOPART FOREIGN KEY (CODIOPART) REFERENCES IOPART (CODIOPART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPARTB_LOCALIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPARTB</REFTABLE>
  <HASHVAL>7AFD32107AA124CAB7BE10750BA7CEF5FC9AD901</HASHVAL>
  <TEXT>ALTER TABLE NPARTB ADD CONSTRAINT FK_NPARTB_LOCALIT FOREIGN KEY (CODLOCALIT) REFERENCES NLOCALIT (CODLOCALIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NPERS1_IOPERS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NPERS1</REFTABLE>
  <HASHVAL>CB65042050458E7B610C8D7F9B346CEF5B6D6958</HASHVAL>
  <TEXT>ALTER TABLE NPERS1 ADD CONSTRAINT FK_NPERS1_IOPERS FOREIGN KEY (CODIOPERS) REFERENCES IOPERS (CODIOPERS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NSERII_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSERII</REFTABLE>
  <HASHVAL>20DEA1A7409245F586203A7A8F7EAAD3CE2FE253</HASHVAL>
  <TEXT>ALTER TABLE NSERII ADD CONSTRAINT FK_NSERII_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NSUBUNIT1_IOFILIAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NSUBUNIT1</REFTABLE>
  <HASHVAL>21639A6BAE2477119AAF28D1FC6F9BED47A29FA2</HASHVAL>
  <TEXT>ALTER TABLE NSUBUNIT1 ADD CONSTRAINT FK_NSUBUNIT1_IOFILIAL FOREIGN KEY (CODIOFILIAL) REFERENCES IOFILIAL (CODIOFILIAL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NTAXE1_NCONT_CODCONT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTAXE1</REFTABLE>
  <HASHVAL>AA44865347D8C83BF674C6F40A3964EBFEBCEE96</HASHVAL>
  <TEXT>ALTER TABLE NTAXE1 ADD CONSTRAINT FK_NTAXE1_NCONT_CODCONT FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NTAXE1_NCONT_CODCONTCHELT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTAXE1</REFTABLE>
  <HASHVAL>1BA7D109D45516C44507F2FDB10CDA20DB77BD5A</HASHVAL>
  <TEXT>ALTER TABLE NTAXE1 ADD CONSTRAINT FK_NTAXE1_NCONT_CODCONTCHELT FOREIGN KEY (CODCONTCHELT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_NUM1_NUM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NUM1</REFTABLE>
  <HASHVAL>6E442219D80E1C257C7473736107243D6DC88024</HASHVAL>
  <TEXT>ALTER TABLE NUM1 ADD CONSTRAINT FK_NUM1_NUM FOREIGN KEY (CODUM) REFERENCES NUM (CODUM)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_OFERTA1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA1</REFTABLE>
  <HASHVAL>4A7C6284E9BE35F349B55E92AF8E8024818B8FE3</HASHVAL>
  <TEXT>ALTER TABLE OFERTA1 ADD CONSTRAINT FK_OFERTA1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_OFERTA1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA1</REFTABLE>
  <HASHVAL>5CF4787FE7F85261F06B64753A42EB90BAC3890D</HASHVAL>
  <TEXT>ALTER TABLE OFERTA1 ADD CONSTRAINT FK_OFERTA1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_OFERTA_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA</REFTABLE>
  <HASHVAL>CE959527905925FD68CF62634099B3F588878422</HASHVAL>
  <TEXT>ALTER TABLE OFERTA ADD CONSTRAINT FK_OFERTA_NAGENDA FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_OFERTA_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OFERTA</REFTABLE>
  <HASHVAL>8B1559F4095AF215F85E4A6D5FA6174313D93A41</HASHVAL>
  <TEXT>ALTER TABLE OFERTA ADD CONSTRAINT FK_OFERTA_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_OREPONTAJ_FRM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>OREPONTAJ</REFTABLE>
  <HASHVAL>98648E70EB050BBBBB779E25DABE3D7357D9B7B8</HASHVAL>
  <TEXT>ALTER TABLE OREPONTAJ ADD CONSTRAINT FK_OREPONTAJ_FRM FOREIGN KEY (CODFORMATIE) REFERENCES FORMATII (CODFORMATIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACHETELINK_PACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETELINK</REFTABLE>
  <HASHVAL>646281837A96E2790F23CE90D76D23E15014C942</HASHVAL>
  <TEXT>ALTER TABLE PACHETELINK ADD CONSTRAINT FK_PACHETELINK_PACHETEOBJ FOREIGN KEY (CODPACHETEOBJ) REFERENCES PACHETEOBJ (CODPACHETEOBJ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACHETEOBJLINK_PACHETEOBJL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEOBJLINK</REFTABLE>
  <HASHVAL>053E5A33116B7C2835B42BF8513829DCA9FF0F50</HASHVAL>
  <TEXT>ALTER TABLE PACHETEOBJLINK ADD CONSTRAINT FK_PACHETEOBJLINK_PACHETEOBJL FOREIGN KEY (CODPACHETEOBJL) REFERENCES PACHETEOBJL (CODPACHETEOBJL)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACHETEOBJL_CODREZERVATS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACHETEOBJL</REFTABLE>
  <HASHVAL>D7C63F55DBE00098FB558847700E785642F1F8B6</HASHVAL>
  <TEXT>ALTER TABLE PACHETEOBJL ADD CONSTRAINT FK_PACHETEOBJL_CODREZERVATS FOREIGN KEY (CODREZERVATS) REFERENCES REZERVATS (CODREZERVATS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING1_CODAMB_PRIMAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING1</REFTABLE>
  <HASHVAL>61758BDE7D26E1F6C4FF3A37F75AFE4F2C80C198</HASHVAL>
  <TEXT>ALTER TABLE PACKING1 ADD CONSTRAINT FK_PACKING1_CODAMB_PRIMAR FOREIGN KEY (CODAMB_PRIMAR) REFERENCES NARTAMB (CODAMB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING1_CODAMB_SECUNDAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING1</REFTABLE>
  <HASHVAL>FD25960852EBF814C53D61932E796BCB3561C0B1</HASHVAL>
  <TEXT>ALTER TABLE PACKING1 ADD CONSTRAINT FK_PACKING1_CODAMB_SECUNDAR FOREIGN KEY (CODAMB_SECUNDAR) REFERENCES NARTAMB (CODAMB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING1_CODAMB_TERTIAR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING1</REFTABLE>
  <HASHVAL>1F036956A56771735110DEED1FE1C2A559E404A4</HASHVAL>
  <TEXT>ALTER TABLE PACKING1 ADD CONSTRAINT FK_PACKING1_CODAMB_TERTIAR FOREIGN KEY (CODAMB_TERTIAR) REFERENCES NARTAMB (CODAMB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING1_PACKING</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING1</REFTABLE>
  <HASHVAL>6AAA1A9749236F38829404D1BEB8C138762FD7D1</HASHVAL>
  <TEXT>ALTER TABLE PACKING1 ADD CONSTRAINT FK_PACKING1_PACKING FOREIGN KEY (CODPACKING) REFERENCES PACKING (CODPACKING)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING2_CODAMB_FINAL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING2</REFTABLE>
  <HASHVAL>56E19D69E2C9A969BDCBE9BD0F0AE9D98451F651</HASHVAL>
  <TEXT>ALTER TABLE PACKING2 ADD CONSTRAINT FK_PACKING2_CODAMB_FINAL FOREIGN KEY (CODAMB_FINAL) REFERENCES NARTAMB (CODAMB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING2_CODPACKING1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING2</REFTABLE>
  <HASHVAL>8158B1C9CC1EC13BC9183F2952ED3D5AD5776388</HASHVAL>
  <TEXT>ALTER TABLE PACKING2 ADD CONSTRAINT FK_PACKING2_CODPACKING1 FOREIGN KEY (CODPACKING1) REFERENCES PACKING1 (CODPACKING1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PACKING3_CODPACKING2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PACKING3</REFTABLE>
  <HASHVAL>00B0CF35207DA626F7082A7D99C50D34D8D1665B</HASHVAL>
  <TEXT>ALTER TABLE PACKING3 ADD CONSTRAINT FK_PACKING3_CODPACKING2 FOREIGN KEY (CODPACKING2) REFERENCES PACKING2 (CODPACKING2)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PLANIFNOD_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFNOD</REFTABLE>
  <HASHVAL>2C5094E64193232F50E83BFA95DF736547927AA0</HASHVAL>
  <TEXT>ALTER TABLE PLANIFNOD ADD CONSTRAINT FK_PLANIFNOD_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PLANIFNOD_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFNOD</REFTABLE>
  <HASHVAL>CD4B57B47FC6F3B495D7010D2F7B730A4E139A99</HASHVAL>
  <TEXT>ALTER TABLE PLANIFNOD ADD CONSTRAINT FK_PLANIFNOD_PLANIFPROD FOREIGN KEY (CODPLANIFPROD) REFERENCES PLANIFPROD (CODPLANIFPROD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PLANIFNOD_PLANIFPROD1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFNOD</REFTABLE>
  <HASHVAL>AF29252216E01B538E47922479505C8227D7FCBD</HASHVAL>
  <TEXT>ALTER TABLE PLANIFNOD ADD CONSTRAINT FK_PLANIFNOD_PLANIFPROD1 FOREIGN KEY (CODPLANIFPROD1) REFERENCES PLANIFPROD1 (CODPLANIFPROD1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PLANIFPROD_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PLANIFPROD</REFTABLE>
  <HASHVAL>270F50E02ED95F1DF3A44E20754992DF3DEADAEC</HASHVAL>
  <TEXT>ALTER TABLE PLANIFPROD ADD CONSTRAINT FK_PLANIFPROD_CODLANSPROD FOREIGN KEY (CODLANSPROD) REFERENCES LANSPROD (CODLANSPROD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRECMDLINK_CODPRECOMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECMDLINK</REFTABLE>
  <HASHVAL>0E0A5CB80764029BEDAC6FA2AEEC825B090DC658</HASHVAL>
  <TEXT>ALTER TABLE PRECMDLINK ADD CONSTRAINT FK_PRECMDLINK_CODPRECOMANDA1 FOREIGN KEY (CODPRECOMANDA1) REFERENCES PRECOMANDA1 (CODPRECOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRECOMANDA1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECOMANDA1</REFTABLE>
  <HASHVAL>57B06787E8FFDF0DA5FD49BD7D58C7286E743D18</HASHVAL>
  <TEXT>ALTER TABLE PRECOMANDA1 ADD CONSTRAINT FK_PRECOMANDA1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRECOMANDA1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECOMANDA1</REFTABLE>
  <HASHVAL>5BCDECC0052399CC7487BD96084815B8D675B9D9</HASHVAL>
  <TEXT>ALTER TABLE PRECOMANDA1 ADD CONSTRAINT FK_PRECOMANDA1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRECOMANDA_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRECOMANDA</REFTABLE>
  <HASHVAL>AA1D31515BB1886C4D10DEC53C2C4C7FE551C79F</HASHVAL>
  <TEXT>ALTER TABLE PRECOMANDA ADD CONSTRAINT FK_PRECOMANDA_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRETM_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRETM</REFTABLE>
  <HASHVAL>323EE4C84B7F666AE32F5688C8D7C9C8B26C90C1</HASHVAL>
  <TEXT>ALTER TABLE PRETM ADD CONSTRAINT FK_PRETM_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODCOMP_CODCLASAPROD</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODCOMP</REFTABLE>
  <HASHVAL>CDA3EE002C5158988DD9ED7E60B25CA089E7A4BA</HASHVAL>
  <TEXT>ALTER TABLE PRODCOMP ADD CONSTRAINT FK_PRODCOMP_CODCLASAPROD FOREIGN KEY (CODCLASAPROD) REFERENCES NCLASEPROD (CODCLASEPROD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODCOMP_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODCOMP</REFTABLE>
  <HASHVAL>E20C7807CA43CF5FBF17E2C2F4C2216F9D2433FC</HASHVAL>
  <TEXT>ALTER TABLE PRODCOMP ADD CONSTRAINT FK_PRODCOMP_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODMAN_CODOP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAN</REFTABLE>
  <HASHVAL>61C73228FE311E7A681B8E20DE4F6CCA116ADC29</HASHVAL>
  <TEXT>ALTER TABLE PRODMAN ADD CONSTRAINT FK_PRODMAN_CODOP FOREIGN KEY (CODOP) REFERENCES NOPER (CODOP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODMAN_CODTARIF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAN</REFTABLE>
  <HASHVAL>24FAD746FEE358EC4815B114BA771A293BA61C41</HASHVAL>
  <TEXT>ALTER TABLE PRODMAN ADD CONSTRAINT FK_PRODMAN_CODTARIF FOREIGN KEY (CODTARIF) REFERENCES TARIFEMAN (CODTARIF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODMAT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAT</REFTABLE>
  <HASHVAL>88E11ABF4E4C72EDE0C994FC83A5DFF364FA0AD4</HASHVAL>
  <TEXT>ALTER TABLE PRODMAT ADD CONSTRAINT FK_PRODMAT_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODMAT_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODMAT</REFTABLE>
  <HASHVAL>65B1D911A7D49CFB0311E3862B29605270D8BD6B</HASHVAL>
  <TEXT>ALTER TABLE PRODMAT ADD CONSTRAINT FK_PRODMAT_PRODCOMP FOREIGN KEY (CODPRODCOMP) REFERENCES PRODCOMP (CODPRODCOMP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODNORME_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODNORME</REFTABLE>
  <HASHVAL>B56CF368D5F857F1B1FA7EDB56CD03D82567B008</HASHVAL>
  <TEXT>ALTER TABLE PRODNORME ADD CONSTRAINT FK_PRODNORME_PRODCOMP FOREIGN KEY (CODPRODCOMP) REFERENCES PRODCOMP (CODPRODCOMP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODREZ_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODREZ</REFTABLE>
  <HASHVAL>EA0CD857F20AB4892587ADBDBF325DEECABCBEA8</HASHVAL>
  <TEXT>ALTER TABLE PRODREZ ADD CONSTRAINT FK_PRODREZ_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PRODREZ_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PRODREZ</REFTABLE>
  <HASHVAL>0C45CB9A35CBFF38F99766D785394FCB872F3CD4</HASHVAL>
  <TEXT>ALTER TABLE PRODREZ ADD CONSTRAINT FK_PRODREZ_PRODCOMP FOREIGN KEY (CODPRODCOMP) REFERENCES PRODCOMP (CODPRODCOMP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROGRAMSDV_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMFSDV</REFTABLE>
  <HASHVAL>94489D8CFD4614363FD2B196EE0ABA2B29414690</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMFSDV ADD CONSTRAINT FK_PROGRAMSDV_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROGRAMSDV_PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMFSDV</REFTABLE>
  <HASHVAL>9243E8150D9926357F25B4FA34F8CDC2C46ECEEF</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMFSDV ADD CONSTRAINT FK_PROGRAMSDV_PROGRAMF FOREIGN KEY (CODPROGRAMF) REFERENCES PROGRAMF (CODPROGRAMF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROIECTNOD_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECTNOD</REFTABLE>
  <HASHVAL>6A883C75CB608DF770F23BCD4B84FB0C4458559D</HASHVAL>
  <TEXT>ALTER TABLE PROIECTNOD ADD CONSTRAINT FK_PROIECTNOD_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROIECTNOD_PROIECT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECTNOD</REFTABLE>
  <HASHVAL>D49B5679B25612720929AACAD5F31717FBFDD04D</HASHVAL>
  <TEXT>ALTER TABLE PROIECTNOD ADD CONSTRAINT FK_PROIECTNOD_PROIECT FOREIGN KEY (CODPROIECT) REFERENCES PROIECT (CODPROIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROIECT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROIECT</REFTABLE>
  <HASHVAL>9FCF71DFA64DEF060D370219952D4669C26C40C0</HASHVAL>
  <TEXT>ALTER TABLE PROIECT ADD CONSTRAINT FK_PROIECT_NARTOBJ FOREIGN KEY (CODOBIECTPROD) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMOPART_LOCATIE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOPART</REFTABLE>
  <HASHVAL>6C03139B4F70BC8BF2353E3170BEB944EC63C45B</HASHVAL>
  <TEXT>ALTER TABLE PROMOPART ADD CONSTRAINT FK_PROMOPART_LOCATIE FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMOPART_NCLASEP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOPART</REFTABLE>
  <HASHVAL>A1180AA5E619F9C2ADE56036B62ADE4FEEDEA4DF</HASHVAL>
  <TEXT>ALTER TABLE PROMOPART ADD CONSTRAINT FK_PROMOPART_NCLASEP FOREIGN KEY (CODCLASEP) REFERENCES NCLASEP (CODCLASEP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMOPRAG_PROMO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOPRAG</REFTABLE>
  <HASHVAL>9C10B6AC408A4C578A0084A98BC21B30ADEEDC08</HASHVAL>
  <TEXT>ALTER TABLE PROMOPRAG ADD CONSTRAINT FK_PROMOPRAG_PROMO FOREIGN KEY (CODPROMO) REFERENCES PROMO (CODPROMO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMOSUB_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMOSUB</REFTABLE>
  <HASHVAL>AEE221AAFB4EB6459FC9B750FB9412651AAB0870</HASHVAL>
  <TEXT>ALTER TABLE PROMOSUB ADD CONSTRAINT FK_PROMOSUB_SUBUNITATEA FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMO_NAGENDA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMO</REFTABLE>
  <HASHVAL>BF6F2AB6F6BA8C33EEADB078419FBA175AD80AD8</HASHVAL>
  <TEXT>ALTER TABLE PROMO ADD CONSTRAINT FK_PROMO_NAGENDA FOREIGN KEY (CODLOCATIE) REFERENCES NAGENDA (CODAGENDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_PROMO_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROMO</REFTABLE>
  <HASHVAL>43068D18E46F64B602EE82169173403A76DC078B</HASHVAL>
  <TEXT>ALTER TABLE PROMO ADD CONSTRAINT FK_PROMO_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP0_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP0</REFTABLE>
  <HASHVAL>E39CC90A2AA66A06D4DC041AC2157D3B3F867040</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP0 ADD CONSTRAINT FK_RAPORTP0_COMANDA1 FOREIGN KEY (CODCOMANDA1) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP0_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP0</REFTABLE>
  <HASHVAL>F0F7FEA818460A6D4701BC026606BA99DAB75C6E</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP0 ADD CONSTRAINT FK_RAPORTP0_RAPORTP FOREIGN KEY (CODRAPORTP) REFERENCES RAPORTP (CODRAPORTP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP1_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP1</REFTABLE>
  <HASHVAL>238E846DE85FD3A5EC3F4933E96F5C8D31F4077F</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP1 ADD CONSTRAINT FK_RAPORTP1_RAPORTP FOREIGN KEY (CODRAPORTP) REFERENCES RAPORTP (CODRAPORTP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP1_RAPORTP0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP1</REFTABLE>
  <HASHVAL>5120717521BEE2958EA7A58CC953900D23E22B24</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP1 ADD CONSTRAINT FK_RAPORTP1_RAPORTP0 FOREIGN KEY (CODRAPORTP0) REFERENCES RAPORTP0 (CODRAPORTP0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP2</REFTABLE>
  <HASHVAL>FE0160051525234301F7872A43EB980E796DC15A</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP2 ADD CONSTRAINT FK_RAPORTP2_CODOBIECT FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_RAPORTP_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>RAPORTP</REFTABLE>
  <HASHVAL>B9964E1749463F51AFD0606EAADBC2D7B489A696</HASHVAL>
  <TEXT>ALTER TABLE RAPORTP ADD CONSTRAINT FK_RAPORTP_SUBUNITATEA FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_REGOSS1_REGOSS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>REGOSS1</REFTABLE>
  <HASHVAL>3CD72829D33652ACB654C08F0AEF4F44F46FCF57</HASHVAL>
  <TEXT>ALTER TABLE REGOSS1 ADD CONSTRAINT FK_REGOSS1_REGOSS FOREIGN KEY (CODREGOSS) REFERENCES REGOSS (CODREGOSS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SABLOND1_DESCRIPT1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SABLONDESCRIPT1</REFTABLE>
  <HASHVAL>ACFCFA31F961DF0D8EAF0830FE034949EE37E32A</HASHVAL>
  <TEXT>ALTER TABLE SABLONDESCRIPT1 ADD CONSTRAINT FK_SABLOND1_DESCRIPT1 FOREIGN KEY (CODDESCRIPTOR1) REFERENCES DESCRIPTORI1 (CODDESCRIPTOR1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SABLOND1_SABLOND</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SABLONDESCRIPT1</REFTABLE>
  <HASHVAL>DB53925092EA132474AB92E98CAE8AAD3370AFCD</HASHVAL>
  <TEXT>ALTER TABLE SABLONDESCRIPT1 ADD CONSTRAINT FK_SABLOND1_SABLOND FOREIGN KEY (CODSABLON) REFERENCES SABLONDESCRIPT (CODSABLON)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SABLOND_DESCRIPT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SABLONDESCRIPT</REFTABLE>
  <HASHVAL>570F61329633C7396D07526A1BECAB173789B3D1</HASHVAL>
  <TEXT>ALTER TABLE SABLONDESCRIPT ADD CONSTRAINT FK_SABLOND_DESCRIPT FOREIGN KEY (CODDESCRIPTOR) REFERENCES DESCRIPTORI (CODDESCRIPTOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_CATRET_RETINERI</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RETINERI</REFTABLE>
  <HASHVAL>76E751FA9571B19F013CD95FA757EA1AA9117121</HASHVAL>
  <TEXT>ALTER TABLE SAL_RETINERI ADD CONSTRAINT FK_SAL_CATRET_RETINERI FOREIGN KEY (CODCATRET) REFERENCES SAL_CATRET (CODCATRET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_CATSPOR_SPOR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI</REFTABLE>
  <HASHVAL>F37838797080177C4850AF1C2C0A87B8D3DED1D0</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI ADD CONSTRAINT FK_SAL_CATSPOR_SPOR FOREIGN KEY (CODCATSPOR) REFERENCES SAL_CATSPOR (CODCATSPOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_DEDGEN1_DEDGEN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN1</REFTABLE>
  <HASHVAL>82B3B7BEC2178F6720E2CC294BFB09196E14B718</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN1 ADD CONSTRAINT FK_SAL_DEDGEN1_DEDGEN FOREIGN KEY (CODDEDGEN) REFERENCES SAL_DEDGEN (CODDEDGEN)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_DEDGEN1_DEDGEN0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN1</REFTABLE>
  <HASHVAL>E9D9E21556FDDC970AC416C550EB926E11329B0E</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN1 ADD CONSTRAINT FK_SAL_DEDGEN1_DEDGEN0 FOREIGN KEY (CODDEDGEN0) REFERENCES SAL_DEDGEN0 (CODDEDGEN0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_DEDGEN_DEDGEN0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_DEDGEN0</REFTABLE>
  <HASHVAL>36BF33CFBB205AD858CAE6E63AC97EE334E17E38</HASHVAL>
  <TEXT>ALTER TABLE SAL_DEDGEN0 ADD CONSTRAINT FK_SAL_DEDGEN_DEDGEN0 FOREIGN KEY (CODDEDGEN) REFERENCES SAL_DEDGEN (CODDEDGEN)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_IMPOZ1_IMPOZ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ1</REFTABLE>
  <HASHVAL>B871665E5409D3AE3C6A777A51391B2ABC0E0770</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ1 ADD CONSTRAINT FK_SAL_IMPOZ1_IMPOZ FOREIGN KEY (CODIMPOZ) REFERENCES SAL_IMPOZ (CODIMPOZ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_IMPOZ1_IMPOZ0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ1</REFTABLE>
  <HASHVAL>2235E63E3D130CD8DF95EDCD4077CD0E9AC2713E</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ1 ADD CONSTRAINT FK_SAL_IMPOZ1_IMPOZ0 FOREIGN KEY (CODIMPOZ0) REFERENCES SAL_IMPOZ0 (CODIMPOZ0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_IMPOZ_IMPOZ0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_IMPOZ0</REFTABLE>
  <HASHVAL>CF11BABC12BBA01C5EF0332D5E9715BF20C128EB</HASHVAL>
  <TEXT>ALTER TABLE SAL_IMPOZ0 ADD CONSTRAINT FK_SAL_IMPOZ_IMPOZ0 FOREIGN KEY (CODIMPOZ) REFERENCES SAL_IMPOZ (CODIMPOZ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NASIG0_NASIG1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG1</REFTABLE>
  <HASHVAL>60A066FCD422EBCBBC113282889607099C47F3D5</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG1 ADD CONSTRAINT FK_SAL_NASIG0_NASIG1 FOREIGN KEY (CODNASIG0) REFERENCES SAL_NASIG0 (CODNASIG0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NASIG0_NASIG2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG2</REFTABLE>
  <HASHVAL>8045305057EB791C6E2F9274980EA41E80C1F686</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG2 ADD CONSTRAINT FK_SAL_NASIG0_NASIG2 FOREIGN KEY (CODNASIG0) REFERENCES SAL_NASIG0 (CODNASIG0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NASIG0_NASIG3</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG3</REFTABLE>
  <HASHVAL>0176889BC26BFC69D26F88BF091E01BAB1F1FF1B</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG3 ADD CONSTRAINT FK_SAL_NASIG0_NASIG3 FOREIGN KEY (CODNASIG0) REFERENCES SAL_NASIG0 (CODNASIG0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NASIG1_NASIG2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG2</REFTABLE>
  <HASHVAL>BC063766D8B31A20F5887C16AA88E9354D986A22</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG2 ADD CONSTRAINT FK_SAL_NASIG1_NASIG2 FOREIGN KEY (CODNASIG1) REFERENCES SAL_NASIG1 (CODNASIG1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NASIG_NASIG0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NASIG0</REFTABLE>
  <HASHVAL>BAC9D12476C19FD818D43F4039A7114C1F20C519</HASHVAL>
  <TEXT>ALTER TABLE SAL_NASIG0 ADD CONSTRAINT FK_SAL_NASIG_NASIG0 FOREIGN KEY (CODNASIG) REFERENCES SAL_NASIG (CODNASIG)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NCONTRIB_NDREP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP1</REFTABLE>
  <HASHVAL>27B263258F7993A16C066E6F0E39C78A87042E9E</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP1 ADD CONSTRAINT FK_SAL_NCONTRIB_NDREP1 FOREIGN KEY (CONTRIB) REFERENCES SAL_NCONTRIB (CODNCONTRIB)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NDREP0_NDREP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP1</REFTABLE>
  <HASHVAL>C76A58E79DC14249868E8D55F0D74186C8467CE3</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP1 ADD CONSTRAINT FK_SAL_NDREP0_NDREP1 FOREIGN KEY (CODNDREP0) REFERENCES SAL_NDREP0 (CODNDREP0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NDREP_NDREP0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP0</REFTABLE>
  <HASHVAL>891E49E134B5A8D3F1B6551CDE383BBF38369F0A</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP0 ADD CONSTRAINT FK_SAL_NDREP_NDREP0 FOREIGN KEY (CODNDREP) REFERENCES SAL_NDREP (CODNDREP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_NDREP_NDREP1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_NDREP1</REFTABLE>
  <HASHVAL>0B4B0BD30AAB6C725ACE3844DBD6790CB2F0E0E5</HASHVAL>
  <TEXT>ALTER TABLE SAL_NDREP1 ADD CONSTRAINT FK_SAL_NDREP_NDREP1 FOREIGN KEY (CODNDREP) REFERENCES SAL_NDREP (CODNDREP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_RETINERI_RETINERI0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_RETINERI0</REFTABLE>
  <HASHVAL>D5564740A1602608B0C9F14389762CF79B2CB5E5</HASHVAL>
  <TEXT>ALTER TABLE SAL_RETINERI0 ADD CONSTRAINT FK_SAL_RETINERI_RETINERI0 FOREIGN KEY (CODRETINERE) REFERENCES SAL_RETINERI (CODRETINERE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR0_SPORURI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI1</REFTABLE>
  <HASHVAL>E5776772B0B6D6DDA3C1580B32484D83A130BDB8</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI1 ADD CONSTRAINT FK_SAL_SPOR0_SPORURI1 FOREIGN KEY (CODSPOR0) REFERENCES SAL_SPORURI0 (CODSPOR0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR0_SPORURI2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI2</REFTABLE>
  <HASHVAL>D2090239C1FCAE1217DEB3AE0A84F5B2A1C08463</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI2 ADD CONSTRAINT FK_SAL_SPOR0_SPORURI2 FOREIGN KEY (CODSPOR0) REFERENCES SAL_SPORURI0 (CODSPOR0)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR_SPORURI0</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI0</REFTABLE>
  <HASHVAL>FD2482C745AE241E8DD7F2A42C76F3883BC66C8C</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI0 ADD CONSTRAINT FK_SAL_SPOR_SPORURI0 FOREIGN KEY (CODSPOR) REFERENCES SAL_SPORURI (CODSPOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR_SPORURI1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI1</REFTABLE>
  <HASHVAL>F9A308BBB84AF37440666F5E27275B4FB71E3C83</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI1 ADD CONSTRAINT FK_SAL_SPOR_SPORURI1 FOREIGN KEY (CODSPOR) REFERENCES SAL_SPORURI (CODSPOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR_SPORURI2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI2</REFTABLE>
  <HASHVAL>6896D61E375569EA9096E5B19963A28F43D253FE</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI2 ADD CONSTRAINT FK_SAL_SPOR_SPORURI2 FOREIGN KEY (CODSPOR) REFERENCES SAL_SPORURI (CODSPOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SAL_SPOR_SPORURIEXCL</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SAL_SPORURI2</REFTABLE>
  <HASHVAL>BB9E67E3B78FD872774A269C0A4FC72C8141D9A2</HASHVAL>
  <TEXT>ALTER TABLE SAL_SPORURI2 ADD CONSTRAINT FK_SAL_SPOR_SPORURIEXCL FOREIGN KEY (CODSPOREXCLUS) REFERENCES SAL_SPORURI (CODSPOR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SCENARIILIVR1_SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SCENARIILIVR1</REFTABLE>
  <HASHVAL>2677B321C68A8BFABEFF7883A79798915339733E</HASHVAL>
  <TEXT>ALTER TABLE SCENARIILIVR1 ADD CONSTRAINT FK_SCENARIILIVR1_SCENARIILIVR FOREIGN KEY (CODSCENARIU) REFERENCES SCENARIILIVR (CODSCENARIU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SCENARIILIVR2_SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SCENARIILIVR2</REFTABLE>
  <HASHVAL>A427335ED6191C2879DB4EDE83ED38FB6BFC17D2</HASHVAL>
  <TEXT>ALTER TABLE SCENARIILIVR2 ADD CONSTRAINT FK_SCENARIILIVR2_SCENARIILIVR FOREIGN KEY (CODSCENARIU) REFERENCES SCENARIILIVR (CODSCENARIU)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SITFINALTE_CODSITFIN</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SITFINALTE</REFTABLE>
  <HASHVAL>F9917E2F05C9F0849051747EF337AC6BDCD8E8F5</HASHVAL>
  <TEXT>ALTER TABLE SITFINALTE ADD CONSTRAINT FK_SITFINALTE_CODSITFIN FOREIGN KEY (CODSITFIN) REFERENCES SITFIN (CODSITFIN)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SPLITCHELT_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPLITCHELT</REFTABLE>
  <HASHVAL>26BE17AB61918EA6B336963123B53261961B9F00</HASHVAL>
  <TEXT>ALTER TABLE SPLITCHELT ADD CONSTRAINT FK_SPLITCHELT_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_SPLITCHELT_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPLITCHELT</REFTABLE>
  <HASHVAL>79D8D2978D9ED5933C98DBA3D20FA75E857CDB88</HASHVAL>
  <TEXT>ALTER TABLE SPLITCHELT ADD CONSTRAINT FK_SPLITCHELT_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_STOCLOCKEMUL_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCLOCKEMUL</REFTABLE>
  <HASHVAL>CFDB21A7D2C84CB88989AD902CC7D60FC1088C65</HASHVAL>
  <TEXT>ALTER TABLE STOCLOCKEMUL ADD CONSTRAINT FK_STOCLOCKEMUL_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_STOCVALLUNA_IOART</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>STOCVALLUNA</REFTABLE>
  <HASHVAL>17123F48E5229BD98B6F784CEF9ABD011C774E21</HASHVAL>
  <TEXT>ALTER TABLE STOCVALLUNA ADD CONSTRAINT FK_STOCVALLUNA_IOART FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TARGETAG1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG1</REFTABLE>
  <HASHVAL>DE61662744D3A05BB80FE307CCD6BE7B62B18FB7</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG1 ADD CONSTRAINT FK_TARGETAG1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TARGETAG1_NCLASEA</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG1</REFTABLE>
  <HASHVAL>B58F1B71E786D0C23C1B2EE7CDCA8ED17182911D</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG1 ADD CONSTRAINT FK_TARGETAG1_NCLASEA FOREIGN KEY (CODCLASA) REFERENCES NCLASEA (CODCLASEA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TARGETAG1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG1</REFTABLE>
  <HASHVAL>7C2F10D8BF874C8096D8594E48E3CD456590CE25</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG1 ADD CONSTRAINT FK_TARGETAG1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TARGETAG1_TARGETAG</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TARGETAG1</REFTABLE>
  <HASHVAL>E7C90C28C2044E91AA5DB136C30D2CE2F872C7C6</HASHVAL>
  <TEXT>ALTER TABLE TARGETAG1 ADD CONSTRAINT FK_TARGETAG1_TARGETAG FOREIGN KEY (CODTARGETAG) REFERENCES TARGETAG (CODTARGETAG)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TEME_CURS</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>CURSURI1</REFTABLE>
  <HASHVAL>E5A78286CAEB42C6853E643129FAE2E23EBF24C8</HASHVAL>
  <TEXT>ALTER TABLE CURSURI1 ADD CONSTRAINT FK_TEME_CURS FOREIGN KEY (CODTEMA) REFERENCES TEME (CODTEMA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TRANSF1_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF1</REFTABLE>
  <HASHVAL>12B3E1603366B84AB9304787D8830FDC8699D0E0</HASHVAL>
  <TEXT>ALTER TABLE TRANSF1 ADD CONSTRAINT FK_TRANSF1_NARTOBJ FOREIGN KEY (CODOBIECT) REFERENCES NARTOBJ (CODOBIECT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TRANSF1_NUM1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF1</REFTABLE>
  <HASHVAL>C105D4D754424CAAA1848C381972F4151873780E</HASHVAL>
  <TEXT>ALTER TABLE TRANSF1 ADD CONSTRAINT FK_TRANSF1_NUM1 FOREIGN KEY (UMSEC) REFERENCES NUM1 (CODUM1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TRANSF_NCONT_CONTSUPLIM</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF</REFTABLE>
  <HASHVAL>4F5C29ED53B371F99919273A688E6D3E5D964369</HASHVAL>
  <TEXT>ALTER TABLE TRANSF ADD CONSTRAINT FK_TRANSF_NCONT_CONTSUPLIM FOREIGN KEY (CONTSUPLIM) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TRANSF_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRANSF</REFTABLE>
  <HASHVAL>12E34AD5EE37461D8AE64754F35226DF56361C76</HASHVAL>
  <TEXT>ALTER TABLE TRANSF ADD CONSTRAINT FK_TRANSF_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TRASEU_FISASUP</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TRASEU</REFTABLE>
  <HASHVAL>28CE97D0F117AE4684FC53C0FF6BB444ADE1EE24</HASHVAL>
  <TEXT>ALTER TABLE TRASEU ADD CONSTRAINT FK_TRASEU_FISASUP FOREIGN KEY (CODFISASUP) REFERENCES FISASUP (CODFISASUP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TREZOR1_NGEST</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TREZOR1</REFTABLE>
  <HASHVAL>56459CC47D4C0E6C8873B207464D3FF856861F62</HASHVAL>
  <TEXT>ALTER TABLE TREZOR1 ADD CONSTRAINT FK_TREZOR1_NGEST FOREIGN KEY (CODGEST) REFERENCES NGEST (CODGEST)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_TREZOR_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TREZOR</REFTABLE>
  <HASHVAL>A3939EEE5E478F5A8BC815F50D93C9D8C7A50271</HASHVAL>
  <TEXT>ALTER TABLE TREZOR ADD CONSTRAINT FK_TREZOR_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJE2C_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2C</REFTABLE>
  <HASHVAL>2E0297CF681B3959819B18E102E4A1687DBB9785</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2C ADD CONSTRAINT FK_UTILAJE2C_UTILAJE FOREIGN KEY (CODUTILAJ) REFERENCES UTILAJE (CODUTILAJ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJE2C_UTILAJE2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2C</REFTABLE>
  <HASHVAL>9B4778C0D77227AC32D4FA7551C7DCD064F05AB7</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2C ADD CONSTRAINT FK_UTILAJE2C_UTILAJE2 FOREIGN KEY (CODUTILAJ2) REFERENCES UTILAJE2 (CODUTILAJ2)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJE2P_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2P</REFTABLE>
  <HASHVAL>2EB40B45788B8F0DE99736C7FE5C37420A2FF8C8</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2P ADD CONSTRAINT FK_UTILAJE2P_UTILAJE FOREIGN KEY (CODUTILAJ) REFERENCES UTILAJE (CODUTILAJ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJE2P_UTILAJE2</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2P</REFTABLE>
  <HASHVAL>E23E5CE6DB4B72422D076292B08926F1E595706C</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2P ADD CONSTRAINT FK_UTILAJE2P_UTILAJE2 FOREIGN KEY (CODUTILAJ2) REFERENCES UTILAJE2 (CODUTILAJ2)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJE2_NINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE2</REFTABLE>
  <HASHVAL>34B8F9119FFF2F4511E858E3E5F7157C44DCD899</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE2 ADD CONSTRAINT FK_UTILAJE2_NINTERVENTIIAUTO FOREIGN KEY (INTERVENTIE) REFERENCES NINTERVENTIIAUTO (CODINTERVENTIIAUTO)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>FK_UTILAJETIPINDEX_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJETIPINDEX</REFTABLE>
  <HASHVAL>36CBA012315D7637149C7D7C6B3698F87F2717A8</HASHVAL>
  <TEXT>ALTER TABLE UTILAJETIPINDEX ADD CONSTRAINT FK_UTILAJETIPINDEX_CODUTILAJ FOREIGN KEY (CODUTILAJ) REFERENCES UTILAJE (CODUTILAJ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>IDX_NCONTSOLDSUB_SUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDSUB</REFTABLE>
  <HASHVAL>EDB3D9070F7569A5E181E30806CCFFE3E85EC6B9</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDSUB ADD CONSTRAINT IDX_NCONTSOLDSUB_SUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>IOARTLINK_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOARTLINK</REFTABLE>
  <HASHVAL>565E9DC03C3CAEFD3634ED43ED790356DD2915D8</HASHVAL>
  <TEXT>ALTER TABLE IOARTLINK ADD CONSTRAINT IOARTLINK_FK FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>IOART_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOART1</REFTABLE>
  <HASHVAL>84683E8633BF5E1B695A222D9CF99EC66D9A5E7F</HASHVAL>
  <TEXT>ALTER TABLE IOART1 ADD CONSTRAINT IOART_C_FK FOREIGN KEY (CODIOART) REFERENCES IOART (CODIOART)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>IOBANK_BANKCONT1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT1</REFTABLE>
  <HASHVAL>635CB058F0911914E1B61F9CA61403D7EBAEFFD8</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT1 ADD CONSTRAINT IOBANK_BANKCONT1_FK FOREIGN KEY (CODIOBANCA) REFERENCES IOBANK (CODIOBANK)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>IOPERS_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>IOPERS1</REFTABLE>
  <HASHVAL>C70501245ACEDA8415429B80A1C40F2D10BBD568</HASHVAL>
  <TEXT>ALTER TABLE IOPERS1 ADD CONSTRAINT IOPERS_C_FK FOREIGN KEY (CODIOPERS) REFERENCES IOPERS (CODIOPERS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>MONEDE_BANKCONT_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT</REFTABLE>
  <HASHVAL>6E0091CBEF3742D5A6C97A8F2F4BB6207C41377C</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT ADD CONSTRAINT MONEDE_BANKCONT_FK FOREIGN KEY (CODMONEDA) REFERENCES NMONEDE (CODMONEDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>MONEDE_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMONEDE1</REFTABLE>
  <HASHVAL>551B0BE1CC22EE3F4292BDD0156F5ADF7355E3F5</HASHVAL>
  <TEXT>ALTER TABLE NMONEDE1 ADD CONSTRAINT MONEDE_C_FK FOREIGN KEY (CODMONEDA) REFERENCES NMONEDE (CODMONEDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>MONEDE_NC_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC</REFTABLE>
  <HASHVAL>4DDE54E7E0D1ADDEA9A45C97EB0E4926D4736643</HASHVAL>
  <TEXT>ALTER TABLE NC ADD CONSTRAINT MONEDE_NC_FK FOREIGN KEY (MONEDA) REFERENCES NMONEDE (CODMONEDA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NACTIVIT_NGEST_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST</REFTABLE>
  <HASHVAL>97BCE085406D8B19AC5B6703F896D0F870BAA763</HASHVAL>
  <TEXT>ALTER TABLE NGEST ADD CONSTRAINT NACTIVIT_NGEST_FK FOREIGN KEY (CODACTIVIT) REFERENCES NACTIVIT (CODACTIVIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NARTATR_NATROBJ_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATROBJ</REFTABLE>
  <HASHVAL>2097EEACF09782BD5A881DB0E76997B994DB6A54</HASHVAL>
  <TEXT>ALTER TABLE NATROBJ ADD CONSTRAINT NARTATR_NATROBJ_FK FOREIGN KEY (CODARTATR) REFERENCES NARTATR (CODARTATR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NATRIB1_NARTATR_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTATR</REFTABLE>
  <HASHVAL>5AAC403E082A9E5F63F477FA9CF09AD53AA1F722</HASHVAL>
  <TEXT>ALTER TABLE NARTATR ADD CONSTRAINT NATRIB1_NARTATR_FK FOREIGN KEY (CODVALPREDEF) REFERENCES NATRIB1 (CODVALATR)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NATRIB_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NATRIB1</REFTABLE>
  <HASHVAL>9355432BFD2B326C37E3B444AF5539466B3FC260</HASHVAL>
  <TEXT>ALTER TABLE NATRIB1 ADD CONSTRAINT NATRIB_C_FK FOREIGN KEY (CODATRIBUT) REFERENCES NATRIB (CODATRIBUT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NATRIB_NARTATR_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NARTATR</REFTABLE>
  <HASHVAL>18870128DC3F26B5F0587BE17FF80210C25A04D3</HASHVAL>
  <TEXT>ALTER TABLE NARTATR ADD CONSTRAINT NATRIB_NARTATR_FK FOREIGN KEY (CODATRIBUT) REFERENCES NATRIB (CODATRIBUT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NBANKCONT_C1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKCONT1</REFTABLE>
  <HASHVAL>E2A753285CCD8FEEDD56DE6229AD3BCA512361B8</HASHVAL>
  <TEXT>ALTER TABLE NBANKCONT1 ADD CONSTRAINT NBANKCONT_C1_FK FOREIGN KEY (CODBANKCONT) REFERENCES NBANKCONT (CODBANKCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NBANKCONT_C2_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NBANKSOLDLUNA</REFTABLE>
  <HASHVAL>64EBB349784E1CE890A837A8E1C11008C204F83E</HASHVAL>
  <TEXT>ALTER TABLE NBANKSOLDLUNA ADD CONSTRAINT NBANKCONT_C2_FK FOREIGN KEY (CODBANKCONT) REFERENCES NBANKCONT (CODBANKCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NBANK_MONEDE1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NMONEDE1</REFTABLE>
  <HASHVAL>59C2448D9F94E3DF53C965405AAF34641E1DAC85</HASHVAL>
  <TEXT>ALTER TABLE NMONEDE1 ADD CONSTRAINT NBANK_MONEDE1_FK FOREIGN KEY (CODBANCA) REFERENCES NBANK (CODBANK)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCATPRET_NGEST_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST</REFTABLE>
  <HASHVAL>A27111317EB1CC053B02C322421EA1AB888B3858</HASHVAL>
  <TEXT>ALTER TABLE NGEST ADD CONSTRAINT NCATPRET_NGEST_FK FOREIGN KEY (CODCATPRET) REFERENCES NCATPRET (CODCATPRET)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEAS_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEAS</REFTABLE>
  <HASHVAL>EED8B77F3F98F7B9E741BBCBA013069F6AF901F7</HASHVAL>
  <TEXT>ALTER TABLE NCLASEAS ADD CONSTRAINT NCLASEAS_C_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEAS (CODCLASEAS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEA_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEA</REFTABLE>
  <HASHVAL>C2FC78D4653841E0F79922542FD3576B5FDF3697</HASHVAL>
  <TEXT>ALTER TABLE NCLASEA ADD CONSTRAINT NCLASEA_C_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEA (CODCLASEA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEG_NGEST_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NGEST</REFTABLE>
  <HASHVAL>D7C2E5B0EACA1B30C940528EE097D58195302E4B</HASHVAL>
  <TEXT>ALTER TABLE NGEST ADD CONSTRAINT NCLASEG_NGEST_FK FOREIGN KEY (CODCLASA) REFERENCES NCLASEG (CODCLASEG)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEG_R_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEG</REFTABLE>
  <HASHVAL>355D16D706C817524C846FF226D19B1CC80F1569</HASHVAL>
  <TEXT>ALTER TABLE NCLASEG ADD CONSTRAINT NCLASEG_R_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEG (CODCLASEG)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEINT_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEINT</REFTABLE>
  <HASHVAL>95D7FC3C7BD0782A7B6A93D87657667310EBB615</HASHVAL>
  <TEXT>ALTER TABLE NCLASEINT ADD CONSTRAINT NCLASEINT_C_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEINT (CODCLASEINT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEMF_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEMF</REFTABLE>
  <HASHVAL>52966FDD8D769CD9C281F3ED78E72C5EFC7754E0</HASHVAL>
  <TEXT>ALTER TABLE NCLASEMF ADD CONSTRAINT NCLASEMF_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEMF (CODCLASEMF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEPROD_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEPROD</REFTABLE>
  <HASHVAL>55A478C0BAB9E7635D9DEA953553C12C5FE693F1</HASHVAL>
  <TEXT>ALTER TABLE NCLASEPROD ADD CONSTRAINT NCLASEPROD_C_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEPROD (CODCLASEPROD)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCLASEP_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCLASEP</REFTABLE>
  <HASHVAL>D38955E6C4B7DD53D40237073638F32074DDFEF3</HASHVAL>
  <TEXT>ALTER TABLE NCLASEP ADD CONSTRAINT NCLASEP_FK FOREIGN KEY (CODPARINTE) REFERENCES NCLASEP (CODCLASEP)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTS_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTS1</REFTABLE>
  <HASHVAL>E435B1AF7734E9FB62178E025F877EEE652A5CF4</HASHVAL>
  <TEXT>ALTER TABLE NCONTS1 ADD CONSTRAINT NCONTS_C_FK FOREIGN KEY (CODCONTS) REFERENCES NCONTS (CODCONTS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTS_RUL_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTRULS</REFTABLE>
  <HASHVAL>BBB40E51D1425482A291B98009861D4D7A9EA34D</HASHVAL>
  <TEXT>ALTER TABLE NCONTRULS ADD CONSTRAINT NCONTS_RUL_FK FOREIGN KEY (CODCONTS) REFERENCES NCONTS (CODCONTS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTS_R_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTS</REFTABLE>
  <HASHVAL>B78526DF58A13967659628B8FBD7A89CEFEC895B</HASHVAL>
  <TEXT>ALTER TABLE NCONTS ADD CONSTRAINT NCONTS_R_FK FOREIGN KEY (CODPARINTE) REFERENCES NCONTS (CODCONTS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTS_SOLD_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDS</REFTABLE>
  <HASHVAL>4A541DB7E132F82FAAF456DD37738E08130B136E</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDS ADD CONSTRAINT NCONTS_SOLD_FK FOREIGN KEY (CODCONTS) REFERENCES NCONTS (CODCONTS)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTT_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTT1</REFTABLE>
  <HASHVAL>948F7B629BC5D48C77E32A851E02BDF26895F541</HASHVAL>
  <TEXT>ALTER TABLE NCONTT1 ADD CONSTRAINT NCONTT_C_FK FOREIGN KEY (CODCONTT) REFERENCES NCONTT (CODCONTT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTT_RUL_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTRULT</REFTABLE>
  <HASHVAL>95476CD4EA92C3D8CA13CB15C439DC42659D1D3B</HASHVAL>
  <TEXT>ALTER TABLE NCONTRULT ADD CONSTRAINT NCONTT_RUL_FK FOREIGN KEY (CODCONTT) REFERENCES NCONTT (CODCONTT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTT_R_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTT</REFTABLE>
  <HASHVAL>B044B794370ABD338B160D7F6812BCCF2DC28109</HASHVAL>
  <TEXT>ALTER TABLE NCONTT ADD CONSTRAINT NCONTT_R_FK FOREIGN KEY (CODPARINTE) REFERENCES NCONTT (CODCONTT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONTT_SOLD_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONTSOLDT</REFTABLE>
  <HASHVAL>4416140E29382E22DECA94D0914BCA6ACA2A4EB9</HASHVAL>
  <TEXT>ALTER TABLE NCONTSOLDT ADD CONSTRAINT NCONTT_SOLD_FK FOREIGN KEY (CODCONTT) REFERENCES NCONTT (CODCONTT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT1</REFTABLE>
  <HASHVAL>814316BE3980537C4C1C97FB59FE6BB98F43E63C</HASHVAL>
  <TEXT>ALTER TABLE NCONT1 ADD CONSTRAINT NCONT_C_FK FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_NTVA1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA1</REFTABLE>
  <HASHVAL>211CF2D94295006120FD5F6D32C459CB8CA18558</HASHVAL>
  <TEXT>ALTER TABLE NTVA1 ADD CONSTRAINT NCONT_NTVA1_FK FOREIGN KEY (CODCONTDED) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_NTVA2_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA1</REFTABLE>
  <HASHVAL>77F640038D2C062E5C81FEB15146E83D50B9DD3F</HASHVAL>
  <TEXT>ALTER TABLE NTVA1 ADD CONSTRAINT NCONT_NTVA2_FK FOREIGN KEY (CODCONTCOLE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_NTVA3_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA1</REFTABLE>
  <HASHVAL>FF6DF8B711F2D61C906BE4FF546CB67AC0B859DB</HASHVAL>
  <TEXT>ALTER TABLE NTVA1 ADD CONSTRAINT NCONT_NTVA3_FK FOREIGN KEY (CODCONTNEEX) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_R_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NCONT</REFTABLE>
  <HASHVAL>44FEC275CF52B70F3E1AE27F547EEF1F840B25D3</HASHVAL>
  <TEXT>ALTER TABLE NCONT ADD CONSTRAINT NCONT_R_FK FOREIGN KEY (CODPARINTE) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NCONT_TVASERV1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TVASERV1</REFTABLE>
  <HASHVAL>29D50DB177EE89BB59B88D71A47A6A598719B209</HASHVAL>
  <TEXT>ALTER TABLE TVASERV1 ADD CONSTRAINT NCONT_TVASERV1_FK FOREIGN KEY (CODTVASERV) REFERENCES TVASERV (CODTVASERV)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NC_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NC1</REFTABLE>
  <HASHVAL>799517E01792D3D37378A146A98685E3BB5792D5</HASHVAL>
  <TEXT>ALTER TABLE NC1 ADD CONSTRAINT NC_FK FOREIGN KEY (CODNC) REFERENCES NC (CODNC)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NTARI_NJUDET_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NJUDET</REFTABLE>
  <HASHVAL>40716123FBD43B6E9CBAA9BA2ECD3E4966C19EED</HASHVAL>
  <TEXT>ALTER TABLE NJUDET ADD CONSTRAINT NTARI_NJUDET_FK FOREIGN KEY (CODTARA) REFERENCES NTARI (CODTARA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NTVA_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>NTVA1</REFTABLE>
  <HASHVAL>F632A40C7AF393F015E6FFBDF7BA6E291567A91D</HASHVAL>
  <TEXT>ALTER TABLE NTVA1 ADD CONSTRAINT NTVA_C_FK FOREIGN KEY (CODTVA) REFERENCES NTVA (CODTVA)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>NUTILAJ3_C_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>UTILAJE3</REFTABLE>
  <HASHVAL>BF6601F9D51DB6E32E36024F491323D52D9E634C</HASHVAL>
  <TEXT>ALTER TABLE UTILAJE3 ADD CONSTRAINT NUTILAJ3_C_FK FOREIGN KEY (CODUTILAJ) REFERENCES UTILAJE (CODUTILAJ)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PROGRAMF1_COMANDA1</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF1</REFTABLE>
  <HASHVAL>D536698816364655BE271921A914E2392C538BFC</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF1 ADD CONSTRAINT PROGRAMF1_COMANDA1 FOREIGN KEY (CODCOMANDA1) REFERENCES COMANDA1 (CODCOMANDA1)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PROGRAMF1_PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF1</REFTABLE>
  <HASHVAL>A76A7F3064AF3B74F836F21A47CE28DBE556E406</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF1 ADD CONSTRAINT PROGRAMF1_PROGRAMF FOREIGN KEY (CODPROGRAMF) REFERENCES PROGRAMF (CODPROGRAMF)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PROGRAMF_FORMATII</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF</REFTABLE>
  <HASHVAL>45AFBF64CE717B52D70E5DB1676F72B483852F1E</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF ADD CONSTRAINT PROGRAMF_FORMATII FOREIGN KEY (CODFORMATIE) REFERENCES FORMATII (CODFORMATIE)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>PROGRAMF_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>PROGRAMF</REFTABLE>
  <HASHVAL>D651C263882CA2C41DA3507987612C90A7C5D008</HASHVAL>
  <TEXT>ALTER TABLE PROGRAMF ADD CONSTRAINT PROGRAMF_NSUBUNIT FOREIGN KEY (SUBUNITATEA) REFERENCES NSUBUNIT (CODSUBUNIT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>SPLITCHELT_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>SPLITCHELT1</REFTABLE>
  <HASHVAL>84A11FCB7078B10134F20168BF16B77D5686BCA0</HASHVAL>
  <TEXT>ALTER TABLE SPLITCHELT1 ADD CONSTRAINT SPLITCHELT_FK FOREIGN KEY (CODSPLITCHELT) REFERENCES SPLITCHELT (CODSPLITCHELT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>CONSTRAINT</TYPE>
  <NAME>TVASERV_TVASERV1_FK</NAME>
  <TEMP>N</TEMP>
  <REFTABLE>TVASERV1</REFTABLE>
  <HASHVAL>ED4F34DB2C6A6C7D1230F7CF9A770CADC626D1D7</HASHVAL>
  <TEXT>ALTER TABLE TVASERV1 ADD CONSTRAINT TVASERV_TVASERV1_FK FOREIGN KEY (CODCONT) REFERENCES NCONT (CODCONT)</TEXT>
  <NIVEL>4</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>ACCESGRANTED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E49ACC349EB29B8BDF88B9818C42C3D65AF36E1E</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION AccesGranted(CodUser in number, CodExternFunctie in varchar2) return number is
Result number;
Acces number;
begin
  Result := 0;
  if winmadmin.pkg_userfirme.VERIFICA_DREPTURI_USER(CodUser, CodExternFunctie, Acces) &gt; 0 then 
    Result := BitAnd(Acces,1);
  end if;
  return(Result);
end AccesGranted;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>CAN_DELETE_MASTER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11A399612405A5108F6E67C7D82D97B6BCF55B61</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION can_delete_master(ATAB IN VARCHAR2,
																							aCol IN VARCHAR2,
																							aCod IN NUMBER
																							)RETURN NUMBER
IS
	 sSql  VARCHAR2(1000);
	 iResult  NUMBER(20) := 0;
begin
  EXECUTE IMMEDIATE &apos;SELECT COUNT(&apos;||aCol||&apos;) FROM &apos;||aTab||
	                  &apos; WHERE &apos;||aCol||&apos;=&apos;||aCod  INTO iResult;



/*INSERT INTO x(SQL) VALUES(&apos;SELECT COUNT(&apos;||aCol||&apos;) FROM &apos;||aTab||
	                  &apos; WHERE &apos;||aCol||&apos;=&apos;||aCod ); COMMIT; */

 RETURN iResult;



end Can_Delete_Master;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>CIF_VALID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06E3A1CB923E42510F172A5B9B1DD55F74B12731</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION cif_valid (pCIF VARCHAR2) RETURN NUMBER IS
  vCif        VARCHAR2(99) := TRIM(pCIF);
  vAux        VARCHAR2(9)  := &apos;753217532&apos;;
  vSuma       INTEGER      := 0;
BEGIN
  IF LENGTH(vCif) = 0 OR LENGTH(vCif) &gt; 12
  THEN RETURN 0;
  END IF;

  WHILE NOT (SUBSTR(vCIF,1,1) BETWEEN &apos;0&apos; AND &apos;9&apos;)
  LOOP
    vCIF := SUBSTR(vCIF,2);
  END LOOP;

  IF NVL(vCIF,0) = 0
  THEN RETURN 0;
  END IF;

  IF LENGTH(vCif) = 0 OR LENGTH(vCif) &gt; 10
  THEN RETURN 0;
  END IF;

  vCIF := lPad(vCIf, 10, &apos;0&apos;);
  FOR i IN 1..9 LOOP
    vSuma := vSuma + SUBSTR(vCIF,i,1) * SUBSTR(vAUX,i,1);
  END LOOP;

  vSuma := MOD((vSuma * 10),11);
  IF vSuma = 10 THEN vSuma := 0; END IF;

  IF vSuma &lt;&gt; SUBSTR(vCIF,10,1)
  THEN RETURN 0;
  END IF;

  RETURN 1;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>CLOB_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>149A6F24FCA8C07951D46F84269A013472B4D2D4</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION clob_agg(INPUT clob) RETURN CLOB PARALLEL_ENABLE AGGREGATE USING T_CLOB_AGG;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>CNP_VALID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92E336BA857736629026D8857538E5EEDAF5AC2A</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION cnp_valid (pCNP VARCHAR2) RETURN NUMBER IS
  nCNP        NUMBER(13);
  sDNastere   VARCHAR2(10);
  dDNastere   DATE;
  nAux        NUMBER(10);
  vCNP        VARCHAR2(13);
  sControl    VARCHAR2(12)  := &apos;279146358279&apos;;
BEGIN
  BEGIN
    nCNP := To_Number(TRIM(pCNP));
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

  vCNP := To_Char(nCNP);
  IF LENGTH(vCNP) &lt;&gt; 13
  THEN RETURN 0;
  END IF;

-- Prima Cifra

--1 - persoane de sex masculin nascute intre 1 ianuarie 1900 si 31 decembrie 1999
--2 - persoane de sex feminin nascute intre 1 ianuarie 1900 si 31 decembrie 1999
--3 - persoane de sex masculin nascute intre 1 ianuarie 1800 si 31 decembrie 1899
--4 - persoane de sex feminin nascute intre 1 ianuarie 1800 si 31 decembrie 1899
--5 - persoane de sex masculin nascute intre 1 ianuarie 2000 si 31 decembrie 2099
--6 - persoane de sex feminin nascute intre 1 ianuarie 2000 si 31 decembrie 2099
--7 - persoane straine de sex masculin rezidente in Romania
--8 - persoane straine de sex feminin rezidente in Romania
--9 - persoanele straine

-- Cifrele 2-7 -&gt; anul nasterii yymmdd

  sDNastere := SubStr(vCNP, 2, 6);

  BEGIN
    dDNastere := To_Date(sDNastere, &apos;yymmdd&apos;);
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

-- cifrele 8,9 - Judetul
--  01 Alba
--  02 Arad
--  03 Arges
--  04 Bacau
--  05 Bihor
--  06 Bistrita-Nasaud
--  07 Botosani
--  08 Brasov
--  09 Braila
--  10 Buzau
--  11 Caras-Severin
--  12 Cluj
--  13 Constanta
--  14 Covasna
--  15 Dambovita
--  16 Dolj
--  17 Galati
--  18 Gorj
--  19 Harghita
--  20 Hunedoara
--  21 Ialomita
--  22 Iasi
--  23 Ilfov
--  24 Maramures
--  25 Mehedinti
--  26 Mures
--  27 Neamt
--  28 Olt
--  29 Prahova
--  30 Satu Mare
--  31 Salaj
--  32 Sibiu
--  33 Suceava
--  34 Teleorman
--  35 Timis
--  36 Tulcea
--  37 Vaslui
--  38 Valcea
--  39 Vrancea
--  40 Bucuresti
--  41 Bucuresti S.1
--  42 Bucuresti S.2
--  43 Bucuresti S.3
--  44 Bucuresti S.4
--  45 Bucuresti S.5
--  46 Bucuresti S.6
--  47 Bucuresti S.7 (sunt buletine cu sector 7)
--  51 Calarasi
--  52 Giurgiu

  BEGIN
    nAux := To_Number(SubStr(vCNP, 8, 2));
    IF NOT ( (nAux BETWEEN 1 AND 47) OR (nAux IN (51,52)) )
    THEN RETURN 0;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

-- cifrele 10-12 numar aleator intervalul 001-999

  BEGIN
    nAux := To_Number(SubStr(vCNP, 10, 3));
    IF nAux = 0
    THEN RETURN 0;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

-- cifra a 13-a cifra de control

  BEGIN
    nAux := 0;
    FOR i IN 1..12 LOOP
      nAux := nAux + To_Number(SubStr(vCNP,i,1)) * To_Number( SubStr(sControl,i,1));
    END LOOP;

    nAux := Mod(nAux, 11);

    IF nAux = 10
    THEN nAux := 1;
    END IF;

    IF nAux &lt;&gt; To_Number(SubStr(vCNP,13,1))
    THEN RETURN 0;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

  RETURN 1;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>CURATAUNICODE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD8190FFA4CE1BA28C0858AA59DDFCFC162CCE1F</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION CurataUnicode(Expresie in varchar2) return varchar2 is
i number(10);
rez varchar2(3200);
begin
  rez := &apos;&apos;;
  for i in 1..length(expresie) loop
    if ascii(SUBSTR(expresie, i, 1)) between 32 and 127 then
      rez := rez||SUBSTR(expresie, i, 1);
    end if;
  end loop;
  return rez;
end CurataUnicode;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>DATE_TO_UNIX_TS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C52045CED3161DBDC8A62CA70214063D7579435D</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION date_to_unix_ts( PDate in date ) return number is
l_unix_ts number;
begin
   l_unix_ts := Round(( PDate - date &apos;1970-01-01&apos; ) * 60 * 60 * 24, 0);
   return l_unix_ts;
end;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>FORMATARE_ETAJATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D87CAF7BBAA578023839A80D065D4B85452776ED</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION FORMATARE_ETAJATE(pSTR IN STRING, pNrEl IN NUMBER DEFAULT 10, pSep1 IN VARCHAR2 DEFAULT &apos;;&apos;, pSep2 IN VARCHAR2 DEFAULT &apos;|&apos;) RETURN VARCHAR2 IS
  vTmp  VARCHAR2(3200);
  vAux1 VARCHAR2(3200);
  vAux2 VARCHAR2(3200);
  vPos  INTEGER;
BEGIN
  vAux1 := pSTR;
  vAux2 := &apos;&apos;;

  LOOP
    vPos := InStr(vAux1, &apos;|&apos;, 1, pNrEl);

    IF vPos = 0 THEN 
      vTmp  := vAux1; 
      vAux1 := &apos;&apos;;
    ELSE 
      vTmp  := SubStr(vAux1,1,vPos - 1);
      vAux1 := SubStr(vAux1,vPos+1);
    END IF;

    IF vTmp IS NOT NULL THEN 
      vTmp  := REPLACE(vTmp, &apos;|&apos;, pSep1);
      IF vAux2 IS NULL 
      THEN vAux2 := vTmp;
      ELSE vAux2 := vAux2||pSep2||vTmp;
      END IF;
    END IF;     
    EXIT WHEN vPos = 0;  
  END LOOP;

  RETURN vAux2;
END FORMATARE_ETAJATE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETADRESA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05FDFF4AB621F79139024EEE42A812D4610B37AB</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GETADRESA (P_SECTOR INTEGER,P_STRADA VARCHAR2, P_NR1 NUMBER, P_NR2 VARCHAR2, P_BLOC VARCHAR2, P_SCARA VARCHAR2, P_ETAJ VARCHAR2, P_APART VARCHAR2, P_CODPOSTAL VARCHAR2)
RETURN varchar2 IS
  Result VARCHAR2(200) := &apos;&apos;;
BEGIN
  IF Coalesce(Length(Trim(p_strada)),0)    &lt;&gt; 0 THEN Result := Result || p_strada;                                END IF;
  IF Coalesce(p_Nr1, 0)                    &lt;&gt; 0 THEN Result := Result || &apos; Nr. &apos;   || To_Char(p_Nr1, &apos;FM99999&apos;);  END IF;
  IF Coalesce(Length(Trim(p_Nr2)),0)       &lt;&gt; 0 THEN Result := Result || &apos; &apos;       || p_Nr2;                      END IF;
  IF Coalesce(Length(Trim(p_bloc)),0)      &lt;&gt; 0 THEN Result := Result || &apos; Bl. &apos;   || p_bloc;                     END IF;
  IF Coalesce(Length(Trim(p_scara)),0)     &lt;&gt; 0 THEN Result := Result || &apos; Sc. &apos;   || p_scara;                    END IF;
  IF Coalesce(Length(Trim(p_etaj)),0)      &lt;&gt; 0 THEN Result := Result || &apos; Et. &apos;   || To_Char(p_etaj);            END IF;
  IF Coalesce(Length(Trim(p_apart)),0)     &lt;&gt; 0 THEN Result := Result || &apos; Ap. &apos;   || To_Char(p_apart);           END IF;
  IF Coalesce(Length(Trim(p_codpostal)),0) &lt;&gt; 0 THEN Result := Result || &apos; CP. &apos;   || p_codpostal;                END IF;
  IF Coalesce(p_sector, 0)                 &lt;&gt; 0 THEN Result := Result || &apos; Sect. &apos; || to_char(p_sector);          END IF;
  RETURN(Result);
END GetAdresa;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETDATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3BC69BD1F782FDD20A0B12E7F7FAAC4053FFE18</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GETDATA(P_AN IN NUMBER, P_LUNA IN NUMBER) RETURN DATE IS
  v_an   VARCHAR2(4);
  v_luna VARCHAR2(2);
  Result DATE        := NULL;
  bErr   BOOLEAN     := FALSE;
BEGIN
  IF (p_an is null)
  THEN bErr := true;
  ELSE v_an := To_Char(p_an,&apos;fm0000&apos;);
  END IF;
  
  IF (p_luna is null) or (p_luna not between 1 and 12)
  THEN bErr   := true;
  ELSE v_luna := To_Char(p_luna, &apos;fm00&apos;);
  END IF;

  IF not bErr THEN
    Result := To_Date(v_an||&apos;/&apos;||v_luna||&apos;/01&apos;, &apos;yyyy/mm/dd&apos;);
  END IF;
  RETURN Result;
END GETDATA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETDISCOUNTTEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35190789C7A0F3AF0D3DFAE42D478C6036FC64CA</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION getdiscounttext (P_LIM2 NUMBER, P_LIM3 NUMBER, P_LIM4 NUMBER, P_PROC1 NUMBER, P_PROC2 NUMBER, P_PROC3 NUMBER, P_PROC4 NUMBER)
 return varchar2 is
  Result VARCHAR2(200);
  v_limmax NUMBER;
begin
  IF (p_lim2 = 0) AND (p_lim3 = 0) AND (p_lim4 = 0) THEN
    IF(p_proc1 &gt; 0) then
      Result := to_char(p_proc1) || &apos; % Majorare &apos; ;
    ELSE
      Result := to_char(p_proc1*-1) || &apos; % Discount &apos; ;
    END IF;
  ELSE
    IF (p_lim2 &lt;&gt; 0) then
      IF (p_proc1 &gt; 0) then
        Result := &apos; pina la &apos; || to_char(p_lim2) || &apos; Majorare &apos; || to_char(p_proc1) || &apos; %&apos;;
      ELSE
        Result := &apos; pina la &apos; || to_char(p_lim2) || &apos; Discount &apos; || to_char(p_proc1) || &apos; %&apos;;
      END IF;
      v_limmax := p_lim2;
      IF (p_lim3 &lt;&gt; 0) and (p_lim3 &gt; p_lim2) then
        IF (p_proc2 &gt; 0) then
          Result := Result || &apos; |  intre &apos;|| to_char(p_lim2) ||&apos; si &apos; || to_char(p_lim3) || &apos; Majorare &apos; || to_char(p_proc2) || &apos; %&apos;;
        ELSE
          Result := Result || &apos; |  intre &apos;|| to_char(p_lim2) ||&apos; si &apos; || to_char(p_lim3) || &apos; Discount &apos; || to_char(p_proc2) || &apos; %&apos;;
        END IF;
        v_limmax := p_lim3;
        IF (p_lim4 &lt;&gt; 0) and (p_lim4 &gt; p_lim3) then
          IF (p_proc3 &gt; 0) then
            Result := Result || &apos; |  intre &apos;|| to_char(p_lim3) ||&apos; si &apos; || to_char(p_lim4) || &apos; Majorare &apos; || to_char(p_proc3) || &apos; %&apos;;
          ELSE
            Result := Result || &apos; |  intre &apos;|| to_char(p_lim3) ||&apos; si &apos; || to_char(p_lim4) || &apos; Discount &apos; || to_char(p_proc3) || &apos; %&apos;;
          END IF;
          v_limmax := p_lim4;
        END IF;
      END IF;

      IF (p_proc4 &gt; 0) then
        Result := Result || &apos; | peste &apos; || to_char(v_limmax) || &apos; Majorare &apos; || to_char(p_proc4) || &apos; %&apos;;
      ELSE
        Result := Result || &apos; | peste &apos;|| to_char(v_limmax)  || &apos; Discount &apos; || to_char(p_proc4) || &apos; %&apos;;
      END IF;

    END IF;
  END IF;

  return(Result);
end GetDiscountText;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETNUMEOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FDFAF87AD18EC022BE69E19AE2320A6E3119AC9</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION getnumeobiect (P_DENARTICOL VARCHAR2, P_CODOBIECT INTEGER, P_ALLNAME INTEGER DEFAULT 1 )
 return varchar2 is
  Result VARCHAR2(200);
begin
  Result := &apos;&apos;;
  if (p_allname = 1) then
    Result := p_denarticol;
  end if;
  FOR vrec_obj IN (SELECT a.CodValAtr, Valoare FROM NATROBJ a, NATRIB1 b WHERE a.codobiect = p_codobiect AND a.codvalatr = b.codvalatr) LOOP
      Result := Result || &apos; &apos; || vrec_obj.Valoare;
  END LOOP;

  return(Result);
end GetNumeObiect;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETNUMEOBIECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87643359FC7451E7A8C05489A60254C9982C7229</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION getnumeobiect1 (P_DENARTICOL VARCHAR2, P_CODOBIECT INTEGER, P_ALLNAME INTEGER DEFAULT 1 )
 return varchar2 is
  Result VARCHAR2(200);
begin
  Result := &apos;&apos;;
  if (p_allname = 1) then
    Result := p_denarticol;
  end if;
  FOR vrec_obj IN (SELECT a.CodValAtr, Valoare FROM NATROBJ a, NATRIB1 b
                   WHERE a.codobiect = p_codobiect AND a.codvalatr = b.codvalatr) LOOP
      Result := Result || &apos; &apos; || vrec_obj.Valoare;
  END LOOP;

  return(Result);
end GetNumeObiect1;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETNUMEOBIECTEXT4000</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2996C91692E746616572E65D59E0AC6EDC26B3FA</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GetNumeObiectExt4000 (pCodObiect INTEGER) RETURN VARCHAR2 IS
  result  VARCHAR2(4000);
  resCLob CLOB;
BEGIN
  resCLob := GetNumeObiectExtCLob(pCodObiect);

  IF Length(resCLob) &gt; 4000
  THEN result := SubStr(resCLob, 1, 3997)||&apos;...&apos;;
  ELSE result := resCLob;
  END IF;
  RETURN(Result);
END GetNumeObiectExt4000;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETNUMEOBIECTEXTCLOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21B2DCF58BA4B83375EF01F885874287538C9E5B</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GETNUMEOBIECTEXTCLOB (pCodObiect INTEGER) RETURN CLOB IS
  result CLOB;
BEGIN
  Result := &apos;&apos;;

  FOR vRec IN (
    SELECT a.den_articol FROM nartobj o INNER JOIN nart a ON a.codarticol = o.codarticol WHERE o.codobiect = pCodObiect
  ) LOOP
    Result := vRec.den_articol;
  END LOOP;

  FOR vRec IN (
    SELECT a.denumire||&apos; &apos;||a1.valoare Atribut
    FROM NATROBJ ao
      INNER JOIN NATRIB1 a1 ON a1.codvalatr = ao.codvalatr
      INNER JOIN NATRIB  a  ON a.codatribut = a1.codatribut
    WHERE ao.codobiect = pCodObiect
    ORDER BY ao.IndexLocal
  ) LOOP
    Result := Result || &apos; &apos; || vRec.Atribut;
  END LOOP;

  RETURN(Result);
END GetNumeObiectExtCLob;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GETUSERNAME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4831904CE1D92784A4B3A376D18F78A50C54ADFA</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GETUSERNAME (pUSER IN INTEGER) RETURN VARCHAR2 IS
BEGIN
  return(WinMAdmin.Pkg_Userfirme.getUserName(pUSER));
END GETUSERNAME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GET_CHECK_DIGIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E920DB7A2916AC6DAA910A91533853395AE6D0F5</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GET_CHECK_DIGIT (pCode VARCHAR2) RETURN NUMBER IS
  nCode NUMBER(20);
  vLast NUMBER(20);
  vSum  NUMBER(20) := 0;
  i     NUMBER     := 0;
BEGIN
  BEGIN
    nCode := To_Number(TRIM(pCode));
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;

  WHILE nCode &gt; 0 LOOP
    i := Abs(i-1);
    vLast := Mod(nCode, 10);
    vSum  := vSum + vLast*CASE WHEN i = 1 THEN 3 ELSE 1 END;
    nCode := (nCode-vLast)/10;
  END LOOP;

  vSum := Ceil(vSum/10)*10 - vSum;
  RETURN vSum;
EXCEPTION
  WHEN OTHERS THEN RETURN NULL;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GET_CODE_SCCC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04C58376141241868D741B596B49CA90D9C10416</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION GET_CODE_SCCC (pCode VARCHAR2) RETURN VARCHAR2 IS
  sCode VARCHAR2(20);
BEGIN
  sCode := SubStr(REGEXP_REPLACE(pCode,&apos;\D+&apos;, &apos;&apos;), 1, 17);
  sCode := Coalesce(sCode, &apos;0&apos;); 
  sCode := RPad(sCode, 17, &apos;0&apos;);
  sCode := sCode||GET_CHECK_DIGIT(sCode);
  RETURN sCode;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>GET_TABLE_XML</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92FB2702C286330299438A21AD54BFFD146AF331</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION Get_Table_XML  (pTable VARCHAR2) RETURN CLOB IS 
  cResult CLOB := Empty_Clob(); 
BEGIN
  cResult := dbms_xmlgen.getxml(&apos; SELECT * FROM &apos;||pTable);
  RETURN cResult;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>ISO_WEEK_TO_DATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F43EB81B8BAB9CD546AF969F32AA51FEAD5B6BB</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION iso_week_to_date(pYear IN INTEGER, pWeek IN INTEGER) RETURN DATE IS
  vAnStart DATE;
  vDate    DATE;
BEGIN
  vAnStart := Trunc(TO_DATE(pYear || &apos;.01.04&apos;, &apos;YYYY.MM.DD&apos;),&apos;IW&apos;);
  vDate    := vAnStart + 7 * (pWeek - 1);
  IF pYear &lt;&gt; TO_CHAR(vDate, &apos;IYYY&apos;) THEN
    vDate := NULL;
  END IF;
  RETURN vDate;
END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>NRTOSTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58F4A6068A7A8AAD7B79F54E706225D0EFDDF70F</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION nrtostr(pNr IN NUMBER ) RETURN VARCHAR2 IS
  vMask  VARCHAR2(100) := &apos;fm9G999G999G999G999G999G990&apos;;
  vRES   VARCHAR2(100);
  vAux   NUMBER;
BEGIN
  vAux  := Trunc(pNr);
  IF vAux &lt;&gt; pNr THEN
    vMask := vMask||&apos;D0999999&apos;;
  END IF;
  vRes := TO_CHAR(pNr,vMask, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
  return(vRes);
END nrtostr;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>NUMARRO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0AC6A74D76363B267EB535BFDC91CA9FCCC8C302</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION numarro(
  pNr      IN NUMBER,
  pMON     IN VARCHAR2 DEFAULT &apos;leu&apos;,
  pMONP    IN VARCHAR2 DEFAULT &apos;lei&apos;,
  pSMON    IN VARCHAR2 DEFAULT &apos;ban&apos;,
  pSMONP   IN VARCHAR2 DEFAULT &apos;bani&apos;,
  pNoSpace IN BOOLEAN  DEFAULT TRUE
) RETURN VARCHAR2 IS
  vInt   INTEGER;
  vFrac  INTEGER;
  vVal   VARCHAR2(3000);

  FUNCTION cifre (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 0 THEN &apos;zero&apos;  WHEN 1 THEN &apos;unu&apos;  WHEN 2 THEN &apos;doi&apos;   WHEN 3 THEN &apos;trei&apos; WHEN 4 THEN &apos;patru&apos;
             WHEN 5 THEN &apos;cinci&apos; WHEN 6 THEN &apos;sase&apos; WHEN 7 THEN &apos;sapte&apos; WHEN 8 THEN &apos;opt&apos;  WHEN 9 THEN &apos;noua&apos;
           END;
  END;

  FUNCTION nr1 (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 0 THEN &apos;zece&apos; WHEN 1 THEN &apos;unsprezece&apos; WHEN 2 THEN &apos;doisprezece&apos; WHEN 3 THEN &apos;treisprezece&apos; WHEN 4 THEN &apos;patrusprezece&apos;
             WHEN 5 THEN &apos;cincisprezece&apos; WHEN 6 THEN &apos;sasesprezece&apos; WHEN 7 THEN &apos;saptesprezece&apos; WHEN 8 THEN &apos;optsprezece&apos; WHEN 9 THEN &apos;nouasprezece&apos;
           END;
  END;

  FUNCTION nr2 (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 2 THEN &apos;douazeci&apos; WHEN 3 THEN &apos;treizeci&apos; WHEN 4 THEN &apos;patruzeci&apos; WHEN 5 THEN &apos;cincizeci&apos;
             WHEN 6 THEN &apos;saizeci&apos; WHEN 7 THEN &apos;saptezeci&apos; WHEN 8 THEN &apos;optzeci&apos; WHEN 9 THEN &apos;nouazeci&apos;
           END;
  END;

  FUNCTION Plural(sing VARCHAR2) RETURN VARCHAR2 IS
    Result VARCHAR(100);
  BEGIN
    Result := sing;
    IF sing IS NULL                                                    THEN Result := NULL;
    ELSIF length(sing) &gt; 3 AND SubStr(sing,length(sing)) IN (&apos;r&apos;, &apos;t&apos;) THEN Result := sing||&apos;i&apos;;
    ELSIF length(sing) &gt; 2 AND SubStr(sing,length(sing)-1) = &apos;nd&apos;      THEN Result := Substr(sing, 1, Length(sing) - 1)||&apos;zi&apos;;
    ELSIF SubStr(sing,length(sing)) = &apos;a&apos;                              THEN Result := SubStr(sing, 1, Length(sing) - 1)||&apos;e&apos;;
    ELSIF SubStr(sing,length(sing)) = &apos;u&apos;                              THEN Result := SubStr(sing, 1, Length(sing) - 1)||&apos;i&apos;;
    ELSIF SubStr(sing,length(sing)) = &apos;n&apos;                              THEN Result := sing||&apos;i&apos;;
    END IF;
    RETURN Lower(Result);
  end;

  FUNCTION IntToTxtRo (n INTEGER) RETURN VARCHAR2 IS
    result VARCHAR2(3000);
  BEGIN
    IF    n =          0 THEN result :=  &apos;&apos;;
    ELSIF n &lt;          0 THEN result := &apos;minus &apos;||IntToTxtRo (-n);
    ELSIF n &lt;         10 THEN result := cifre(n);
    ELSIF n &lt;         20 THEN result := nr1(n-10);
    ELSIF n &lt;        100 THEN result := nr2(Trunc(n/10))||CASE WHEN n mod 10 &lt;&gt; 0 THEN &apos; si &apos; END||IntToTxtRo (n mod 10);
    ELSIF n &lt;        200 THEN result := &apos;o suta &apos;||IntToTxtRo (n - 100);
    ELSIF n &lt;       1000 THEN result := cifre(Trunc(n/100))||&apos; sute &apos;||IntToTxtRo (n mod 100);
    ELSIF n &lt;       2000 THEN result := &apos;o mie &apos;||IntToTxtRo (n mod 1000);
    ELSIF n &lt;    1000000 THEN result := IntToTxtRo (Trunc(n/1000))||&apos; mii &apos;||IntToTxtRo (n mod 1000);
    ELSIF n &lt;    2000000 THEN result := &apos;un milion &apos;||IntToTxtRo (n mod 1000000);
    ELSIF n &lt; 1000000000 THEN result := IntToTxtRo (Trunc(n/1000000))||&apos; milioane &apos;||IntToTxtRo (n mod 1000000);
    ELSIF n &lt; 2000000000 THEN result := &apos;un miliard &apos;||IntToTxtRo (n mod 1000000000);
    ELSE result := IntToTxtRo(Trunc(n/1000000000))||&apos;  miliarde &apos;||IntToTxtRo (n mod 1000000000);
    END IF;

    RETURN result;
  END;

BEGIN
  vInt  := Trunc(pNr);
  vFrac := Trunc((pNr-vInt) * 100);
  vVal := &apos;&apos;;
  IF vInt &lt;&gt; 0 THEN
    vVal := IntToTxtRo(vInt);
    IF ABS(vInt) = 1
    THEN vVal := vVal|| &apos; &apos;||pMon;
    ELSE vVal := vVal|| &apos; &apos;||Coalesce(pMonP,Plural(pMon));
    END IF;
  END IF;
  IF vVal IS NOT NULL AND vFrac &lt;&gt; 0
  THEN vVal := vVal||&apos; si &apos;;
  END IF;
  IF vFrac &lt;&gt; 0 THEN
    vVal := vVal||IntToTxtRo(vFrac);
    IF vFrac = 1
    THEN vVal := vVal|| &apos; &apos;||pSMon;
    ELSE vVal := vVal|| &apos; &apos;||Coalesce(pSMonP,Plural(pSMon));
    END IF;
  END IF;
  IF vVal = &apos;&apos;
  THEN vVal := Cifre(0)||&apos; &apos;||Coalesce(pMonP,Plural(pMon));
  END IF;

  IF pNoSpace 
  THEN vVal := REPLACE(vVal,&apos; &apos;,&apos;&apos;);
  END IF;

  return(vVal);
END NumarRo;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>NUMARUK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1585656C7F66146FF05E26A52D689DB768C677BA</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION numaruk(
  pNr      IN NUMBER,
  pMON     IN VARCHAR2 DEFAULT &apos;RON&apos;,
  pSMON    IN VARCHAR2 DEFAULT &apos;ban&apos;,
  pNoSpace IN BOOLEAN  DEFAULT TRUE
) RETURN VARCHAR2 IS
  vInt   INTEGER;
  vFrac  INTEGER;
  vVal   VARCHAR2(3000);

  FUNCTION cifre (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 0 THEN &apos;zero&apos; WHEN 1 THEN &apos;one&apos; WHEN 2 THEN &apos;two&apos; WHEN 3 THEN &apos;three&apos; WHEN 4 THEN &apos;four&apos;
             WHEN 5 THEN &apos;five&apos; WHEN 6 THEN &apos;six&apos; WHEN 7 THEN &apos;seven&apos; WHEN 8 THEN &apos;eight&apos; WHEN 9 THEN &apos;nine&apos;
           END;
  END;

  FUNCTION nr1 (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 0 THEN &apos;ten&apos; WHEN 1 THEN &apos;eleven&apos; WHEN 2 THEN &apos;twelve&apos; WHEN 3 THEN &apos;thirteen&apos; WHEN 4 THEN &apos;fourteen&apos;
             WHEN 5 THEN &apos;fifteen&apos; WHEN 6 THEN &apos;sixteen&apos; WHEN 7 THEN &apos;seventeen&apos; WHEN 8 THEN &apos;eighteen&apos; WHEN 9 THEN &apos;nineteen&apos;
           END;
  END;

  FUNCTION nr2 (n INTEGER) RETURN VARCHAR2 IS
  BEGIN
    RETURN CASE n
             WHEN 2 THEN &apos;twenty&apos; WHEN 3 THEN &apos;thirty&apos; WHEN 4 THEN &apos;forty&apos; WHEN 5 THEN &apos;fifty&apos;
             WHEN 6 THEN &apos;sixty&apos; WHEN 7 THEN &apos;seventy&apos; WHEN 8 THEN &apos;eighty&apos; WHEN 9 THEN &apos;ninety&apos;
           END;
  END;

  FUNCTION IntToTxtEng (n INTEGER) RETURN VARCHAR2 IS
    result VARCHAR2(3000);
  BEGIN
    IF    n =          0 THEN result :=  &apos;&apos;;
    ELSIF n &lt;          0 THEN result := &apos;minus &apos;||IntToTxtEng (-n);
    ELSIF n &lt;         10 THEN result := cifre(n);
    ELSIF n &lt;         20 THEN result := nr1(n-10);
    ELSIF n &lt;        100 THEN result := nr2(Trunc(n/10))||CASE WHEN n mod 10 &lt;&gt; 0 THEN &apos; &apos; END||IntToTxtEng (n mod 10);
    ELSIF n &lt;        200 THEN result := &apos;one hundred &apos;||IntToTxtEng (n - 100);
    ELSIF n &lt;       1000 THEN result := cifre(Trunc(n/100))||&apos; hundreds &apos;||IntToTxtEng (n mod 100);
    ELSIF n &lt;       2000 THEN result := &apos;one thousand &apos;||IntToTxtEng (n mod 1000);
    ELSIF n &lt;    1000000 THEN result := IntToTxtEng (Trunc(n/1000))||&apos; thousands &apos;||IntToTxtEng (n mod 1000);
    ELSIF n &lt;    2000000 THEN result := &apos;one million &apos;||IntToTxtEng (n mod 1000000);
    ELSIF n &lt; 1000000000 THEN result := IntToTxtEng (Trunc(n/1000000))||&apos; millions &apos;||IntToTxtEng (n mod 1000000);
    ELSIF n &lt; 2000000000 THEN result := &apos;one billion &apos;||IntToTxtEng (n mod 1000000000);
    ELSE result := IntToTxtEng(Trunc(n/1000000000))||&apos; billions &apos;||IntToTxtEng (n mod 1000000000);
    END IF;

    RETURN result;
  END;
begin
  vInt  := Trunc(pNr);
  vFrac := Trunc((pNr-vInt) * 100);
  vVal := &apos;&apos;;
  IF vInt &lt;&gt; 0                       THEN vVal := IntToTxtEng(vInt)|| &apos; &apos; ||pMon;       END IF;
  IF vVal IS NOT NULL AND vFrac &lt;&gt; 0 THEN vVal := vVal||&apos; and &apos;;                        END IF;
  IF vFrac &lt;&gt; 0                      THEN vVal := vVal||IntToTxtEng(vFrac)||&apos; &apos;||pSMON; END IF;
  IF vVal = &apos;&apos;                       THEN vVal := Cifre(0)|| &apos; &apos;||pMon;                 END IF;

  IF pNoSpace 
  THEN vVal := REPLACE(vVal,&apos; &apos;,&apos;&apos;);
  END IF;

  return(vVal);
END NumarUK;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>NUMEPRENUME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00034920A71F5D9CDBE259DB4582A954E84EA485</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION numeprenume(PNUME IN VARCHAR2, PPRENUME IN VARCHAR2) RETURN VARCHAR IS
  vNumePrenume VARCHAR2(500);
BEGIN
  vNumePrenume := Trim(pNume);
  IF vNumePrenume IS NULL THEN
    vNumePrenume := Trim(pPrenume);
  ELSIF Trim(pPrenume) IS NOT NULL THEN
    vNumePrenume := vNumePrenume||&apos; &apos;||Trim(pPrenume);
  END IF;

  RETURN vNumePrenume;
END NUMEPRENUME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>NUMEPRENUME_OBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1069165F13E7ADEC2D04FEC28D1957C76744E677</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION numeprenume_obj(PNUME IN VARCHAR2, PPRENUME IN VARCHAR2) RETURN VC2_OBJ IS
BEGIN
  -- stef pentru a fi folosit in structurile de tip colect VC2_OBJ trebuie sa iaba dimensiunea cat VC2_NT
  -- VC2_NT_TO_VC3200_DIST(CAST(COLLECT (NUMEPRENUME(x.NUME,x.Prenume).VC2 ORDER BY x.NUME, x.PRENUME) AS vc2_nt))
  RETURN VC2_OBJ (SubStr(numeprenume(PNUME, PPRENUME) ,1,300));
END numeprenume_obj;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>SAFE_TO_DATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>071B92FD4E90D5A722DE7ADD52F42271941C2EE1</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION safe_to_date(
  p_val    VARCHAR2,
  p_format VARCHAR2 DEFAULT &apos;DD.MM.YYYY&apos;
) RETURN DATE IS
  l_date DATE;
BEGIN
  l_date := TO_DATE(p_val, p_format);
  RETURN l_date;
EXCEPTION
  WHEN OTHERS THEN
    RETURN NULL;
END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>SAFE_TO_NUMBER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3E2BDA1A347CEA390B27BE19A3D1EB051384907</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION safe_to_number(p_val VARCHAR2) RETURN NUMBER IS
  l_num NUMBER;
BEGIN
  l_num := TO_NUMBER(p_val);
  RETURN l_num;
EXCEPTION
  WHEN OTHERS THEN
    RETURN NULL;
END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>STRAGG3200</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A19E140D0D8D48A82B77AE110966C3074D8BDEDF</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION stragg3200 (P_INPUT VARCHAR2) RETURN VARCHAR2 AGGREGATE USING t_stragg3200;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>STRING_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD88F19F95FD79697418A376EAD732E2D8A24A8F</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION string_agg (P_INPUT VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>TRADUTIPSEDIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60788B9F25E868C9257D02C06D2954B441FEFC79</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION tradutipsediu(pSediuSocial IN NUMBER) RETURN VARCHAR IS
  vTipSediu VARCHAR2(500);
BEGIN
  vTipSediu := CASE pSediuSocial
                 WHEN 1 THEN &apos;livrare&apos;
                 WHEN 2 THEN &apos;facturare&apos;
                 WHEN 3 THEN &apos;facturare+livrare&apos;
                 WHEN 4 THEN &apos;social&apos;
                 WHEN 5 THEN &apos;social+livrare&apos;
                 WHEN 6 THEN &apos;social+facturare&apos;
                 WHEN 7 THEN &apos;social+facturare+livrare&apos;
                 WHEN 9 THEN &apos;livrare la beneficiar&apos;
               END;

  RETURN vTipSediu;
END tradutipsediu;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2X_NT_TO_CLOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A7113753062AABE77C5AFE77A6331561E2BC78A</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION vc2x_nt_to_clob ( nt_in  IN VC2x_NT) RETURN CLOB IS
  v_str CLOB;
  v_idx PLS_INTEGER;
  v_dlm VARCHAR2(10);
BEGIN
  v_idx := nt_in.FIRST;
  WHILE (v_idx IS NOT NULL) LOOP
    v_str := v_str || v_dlm || nt_in(v_idx);
    v_dlm := Nvl(PKG_GLOBALS.SEP,&apos;|&apos;);
    v_idx  := nt_in.NEXT(v_idx);
  END LOOP;
  RETURN v_str;

END VC2x_NT_TO_CLOB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_STRING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8C1CED2BDBD96E32CE4F3E49B33F587924D1891</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION vc2_nt_to_string (
                nt_in  IN VC2_NT,
                max_el IN INTEGER  DEFAULT 10
                ) RETURN VARCHAR2 IS
  v_idx PLS_INTEGER;
  v_str VARCHAR2(32767);
  v_dlm VARCHAR2(10);
BEGIN

  v_idx := nt_in.FIRST;
  WHILE (v_idx IS NOT NULL) AND (v_idx &lt;= max_el) LOOP
    v_str := v_str || v_dlm || nt_in(v_idx);
    v_idx  := nt_in.NEXT(v_idx);
    --v_dlm := &apos;| &apos;;
    v_dlm := Nvl(PKG_GLOBALS.SEP,&apos;|&apos;);
  END LOOP;

  IF v_idx &gt; max_el
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;
  RETURN v_str;

END vc2_nt_to_string;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_STRING_ML</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83822579BDA965776CE933F576D9E695AAC9F92E</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION vc2_nt_to_string_ml (
                nt_in        IN VC2_NT,
                max_el_lin   IN INTEGER  DEFAULT  0,
                max_el       IN INTEGER  DEFAULT 10
                ) RETURN VARCHAR2 IS
  v_idx  PLS_INTEGER;
  v_str VARCHAR2(32767);
  v_dlm VARCHAR2(10);

BEGIN

  v_idx := nt_in.FIRST;
  WHILE (v_idx IS NOT NULL) AND (v_idx &lt;= max_el) LOOP
    v_str := v_str || v_dlm || nt_in(v_idx);
    IF max_el_lin &lt;&gt; 0 AND Mod(v_idx,max_el_lin) = 0
    --THEN v_dlm := &apos;|&apos;;
    THEN v_dlm := PKG_GLOBALS.SEP||Chr(13);--&apos;|&apos;;
    ELSE v_dlm := PKG_GLOBALS.SEP;
    END IF;
    v_idx  := nt_in.NEXT(v_idx);
  END LOOP;

  IF v_idx &gt; max_el
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;

  RETURN v_str;

END vc2_nt_to_string_ml;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_STRING_SUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6811D103FC4556F16831E83C063F5E81A8DAF0E6</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION vc2_nt_to_string_sum (
                nt_in        IN VC2_NT
                ) RETURN VARCHAR2 IS
  v_idx      PLS_INTEGER;
  v_count    PLS_INTEGER;
  v_Pos       PLS_INTEGER;
  v_str_aux  VARCHAR2(200);
  v_str      VARCHAR2(32767);
  v_dlm      VARCHAR2(10);
  vPart1     VARCHAR2(100);
  vPart2     VARCHAR2(100);
  vPart1ant  VARCHAR2(100);
  vPart2ant  VARCHAR2(100);
  vSum       NUMBER;
  vNPart     NUMBER;
BEGIN
  -- colectul returnat trebui generat ordonat dupa coloanele de grupare
  -- functie care primeste siruri de forma xxxxx(~#nr#~)xxxxxxx si returneaza xxxxx(SUM(nr))xxxxxxx
  -- am pus (~# si #~) pt a avea o asociere mai putin normala ce nu cred ca s-ar putea pune prin serii

  v_idx     := nt_in.FIRST;
  v_count   := 0;
  IF v_idx IS NOT NULL THEN
    v_str_aux := nt_in(v_idx);
    v_Pos      := INSTR(v_str_aux,&apos;(~#&apos;);
    vPart1ant := Substr(v_str_aux, 1, v_Pos -1);
    v_Pos      := INSTR(v_str_aux,&apos;#~)&apos;);
    vPart2ant := Substr(v_str_aux, v_Pos + 3);
    vSum      := 0;
  END IF;

  WHILE (v_idx IS NOT NULL) AND (v_count &lt; 10) LOOP
    v_str_aux := nt_in(v_idx);
    v_Pos     := INSTR(v_str_aux,&apos;(~#&apos;);
    vPart1    := Substr(v_str_aux, 1, v_Pos -1);
    v_str_aux := Substr(v_str_aux, v_Pos + 3);
    v_Pos     := INSTR(v_str_aux,&apos;#~)&apos;);
    vPart2    := Substr(v_str_aux, v_Pos + 3);

    BEGIN
      vNPart  := Substr(v_str_aux, 1, v_Pos - 1);
    EXCEPTION
      WHEN OTHERS THEN vNPart := 0;
    END;

    IF  (vPart1ant = vPart1 OR (vPart1ant IS NULL AND vPart1 IS NULL))
    AND (vPart2ant = vPart2 OR (vPart2ant IS NULL AND vPart2 IS NULL))
    THEN
      vSum := vSum + vNPart;
    ELSE
      v_str     := v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant ;
      v_dlm     := &apos;| &apos;;
      v_Count   := v_Count + 1;
      vPart1ant := vPart1;
      vPart2ant := vPart2;
      vSum      := vNPart;
    END IF;

    v_idx  := nt_in.NEXT(v_idx);
    IF v_idx IS NULL AND v_count &lt; 10 THEN
      v_str     := v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant ;
    END IF;
  END LOOP;

  IF v_count = 10
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;
  RETURN v_str;

END VC2_NT_TO_STRING_SUM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_VC3200</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4B33F87AFB6F6362EAD2DD9B70C22E9E0ED76D7</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION VC2_NT_TO_VC3200 ( nt_in IN VC2_NT, pSep IN varchar2 default &apos;|&apos; ) RETURN VARCHAR2 IS
  v_idx     PLS_INTEGER;
  v_str     VARCHAR2(3200);
  v_dlm     VARCHAR2(10);
  bContinua BOOLEAN;
BEGIN
  bContinua := TRUE;
  v_idx := nt_in.FIRST;
  WHILE (v_idx IS NOT NULL) AND bContinua LOOP
    IF    v_idx = nt_in.LAST AND LengthB(v_str||v_dlm||nt_in(v_idx)) &gt; 3200 THEN bContinua := FALSE;
    ELSIF v_idx &lt; nt_in.LAST AND LengthB(v_str||v_dlm||nt_in(v_idx)) &gt; 3196 THEN bContinua := FALSE;
    END IF;

    IF bContinua THEN
      v_str := v_str || v_dlm || nt_in(v_idx);
      v_idx := nt_in.NEXT(v_idx);
      v_dlm := Coalesce(pSep, PKG_GLOBALS.SEP);
    END IF;
  END LOOP;

  IF NOT bContinua
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;

  RETURN v_str;

END vc2_nt_to_vc3200;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_VC3200_DIST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49D9CCF2DDCD04E110911D40CE237F8505D98125</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION VC2_NT_TO_VC3200_DIST ( NT_IN IN VC2_NT ) RETURN VARCHAR2 IS
  v_idx     PLS_INTEGER;
  v_str     VARCHAR2(3200);
  v_last    VARCHAR2(3000);
  v_act     VARCHAR2(3000);
  v_dlm     VARCHAR2(10);
  bContinua BOOLEAN;
BEGIN
  bContinua := TRUE;
  v_idx  := nt_in.FIRST;
  v_last := &apos;*####*&apos;;
  WHILE (v_idx IS NOT NULL) AND bContinua LOOP
    v_act := nt_in(v_idx);
    IF v_act &lt;&gt; v_last THEN
      v_last := v_act;
      IF    v_idx = nt_in.LAST AND LengthB(v_str||v_dlm||v_act) &gt; 3200 THEN bContinua := FALSE;
      ELSIF v_idx &lt; nt_in.LAST AND LengthB(v_str||v_dlm||v_act) &gt; 3196 THEN bContinua := FALSE;
      ELSE  v_str := v_str || v_dlm || v_act;
      END IF;
    END IF;
    IF bContinua THEN
      v_idx := nt_in.NEXT(v_idx);
      v_dlm := Nvl(PKG_GLOBALS.SEP,&apos;|&apos;);
    END IF;
  END LOOP;

  IF NOT bContinua
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;

  RETURN v_str;

END vc2_nt_to_vc3200_dist;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>FUNCTION</TYPE>
  <NAME>VC2_NT_TO_VC3200_SUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DA8EF292953423E0338399F21EB0F3BA8B12036</HASHVAL>
  <TEXT>CREATE OR REPLACE FUNCTION VC2_NT_TO_VC3200_SUM (
  nt_in IN VC2_NT
) RETURN VARCHAR2 IS
  v_idx      PLS_INTEGER;
  v_count    PLS_INTEGER;
  v_Pos       PLS_INTEGER;
  v_str_aux  VARCHAR2(200);
  v_str      VARCHAR2(32767);
  v_dlm      VARCHAR2(10);
  vPart1     VARCHAR2(100);
  vPart2     VARCHAR2(100);
  vPart1ant  VARCHAR2(100);
  vPart2ant  VARCHAR2(100);
  vSum       NUMBER;
  vNPart     NUMBER;
  bContinua BOOLEAN;
BEGIN
  -- colectul returnat trebui generat ordonat dupa coloanele de grupare
  -- functie care primeste siruri de forma xxxxx(~#nr#~)xxxxxxx si returneaza xxxxx(SUM(nr))xxxxxxx
  -- am pus (~# si #~) pt a avea o asociere mai putin normala ce nu cred ca s-ar putea pune prin serii

  bContinua := TRUE;
  v_idx     := nt_in.FIRST;
  IF v_idx IS NOT NULL THEN
    v_str_aux := nt_in(v_idx);
    v_Pos     := INSTR(v_str_aux,&apos;(~#&apos;);
    vPart1ant := Substr(v_str_aux, 1, v_Pos -1);
    v_Pos     := INSTR(v_str_aux,&apos;#~)&apos;);
    vPart2ant := Substr(v_str_aux, v_Pos + 3);
    vSum      := 0;
  END IF;

  WHILE (v_idx IS NOT NULL) AND bContinua LOOP
    v_str_aux := nt_in(v_idx);
    v_Pos     := INSTR(v_str_aux,&apos;(~#&apos;);
    vPart1    := Substr(v_str_aux, 1, v_Pos -1);
    v_str_aux := Substr(v_str_aux, v_Pos + 3);
    v_Pos     := INSTR(v_str_aux,&apos;#~)&apos;);
    vPart2    := Substr(v_str_aux, v_Pos + 3);

    BEGIN
      vNPart  := Substr(v_str_aux, 1, v_Pos - 1);
    EXCEPTION
      WHEN OTHERS THEN vNPart := 0;
    END;

    IF  (vPart1ant = vPart1 OR (vPart1ant IS NULL AND vPart1 IS NULL))
    AND (vPart2ant = vPart2 OR (vPart2ant IS NULL AND vPart2 IS NULL))
    THEN
      vSum := vSum + vNPart;
    ELSE

      IF    v_idx = nt_in.LAST AND LengthB(v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant) &gt; 3200 THEN bContinua := FALSE;
      ELSIF v_idx &lt; nt_in.LAST AND LengthB(v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant) &gt; 3196 THEN bContinua := FALSE;
      END IF;

      IF bContinua THEN
        v_str     := v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant ;
        v_dlm     := &apos;|&apos;;--Nvl(PKG_GLOBALS.SEP,&apos;|&apos;);
        vPart1ant := vPart1;
        vPart2ant := vPart2;
        vSum      := vNPart;
      END IF;
    END IF;

    v_idx  := nt_in.NEXT(v_idx);
    IF v_idx IS NULL AND bContinua THEN
      IF LengthB(v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant) &gt; 3200
      THEN bContinua := FALSE;
      ELSE v_str     := v_str || v_dlm ||vPart1ant||&apos;(&apos;||vSum||&apos;)&apos;||vPart2ant ;
      END IF;
    END IF;
  END LOOP;

  IF NOT bContinua
  THEN v_str := v_str || &apos; ...&apos;;
  END IF;
  RETURN v_str;

END vc2_nt_to_vc3200_sum;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>CMDLINK_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6EC11ABCD85580BA0AFAB35322C27FAB1E3F622</HASHVAL>
  <TEXT>CREATE INDEX CMDLINK_CMD ON CMDLINK (CODLINIECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>DOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0694384EC4D84542096BA9C29FB2902F31B68BB5</HASHVAL>
  <TEXT>CREATE INDEX DOI ON NATROBJ (CODVALATR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FK_BUGETMF1_CODBUGETMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB653701A0883418A6EC0E0C813DF56BB4FB04AC</HASHVAL>
  <TEXT>CREATE INDEX FK_BUGETMF1_CODBUGETMF ON BUGETMF1 (CODBUGETMF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FK_FAZINTR_CODFAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED20FCDC4EB2E63C82B7EE1F8A492E65A858A5A7</HASHVAL>
  <TEXT>CREATE INDEX FK_FAZINTR_CODFAZ ON FAZINTR (CODFAZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FK_RAPORTP3_MOTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E45F96ACA2DD9E3CB3DBB1653CAA71019233CC23</HASHVAL>
  <TEXT>CREATE INDEX FK_RAPORTP3_MOTIVE ON RAPORTP3 (CODMOTIV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FK_RAPORTP3_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7862D6F324A9DA73B012825A65E2EB16CC3B9BE6</HASHVAL>
  <TEXT>CREATE INDEX FK_RAPORTP3_RAPORTP ON RAPORTP3 (CODRAPORTP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FK_RAPORTP3_RAPORTP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57B1FFD67A9A35FD5D64B2CD00750178FC915D1E</HASHVAL>
  <TEXT>CREATE INDEX FK_RAPORTP3_RAPORTP1 ON RAPORTP3 (CODRAPORTP1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>FUZART_IDX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44D1DA5622084DB9463819076C459042954DF138</HASHVAL>
  <TEXT>CREATE INDEX FUZART_IDX ON FUZART (USERID,USERSTR,DATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3C4274385C4D1E79D2EF5F0AEBE7F78B4D352C6</HASHVAL>
  <TEXT>CREATE INDEX IDX ON IOART (DEN_IOART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ADAOSM1_CODADAOSM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4973F161871F4AE793105DDB6321F5A292A3D243</HASHVAL>
  <TEXT>CREATE INDEX IDX_ADAOSM1_CODADAOSM ON ADAOSM1 (CODADAOSM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_AVIZIESLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4BA62E19B87A467F07B81585D04428F358B780C</HASHVAL>
  <TEXT>CREATE INDEX IDX_AVIZIESLUNA ON AVIZIESLUNA (AN,LUNA,CODIES1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_AVIZINTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B53E4F0AC97D66C07A314723E7AF5FC7E80AF202</HASHVAL>
  <TEXT>CREATE INDEX IDX_AVIZINTLUNA ON AVIZINTLUNA (AN,LUNA,CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_AWBCOMANDA_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B5D29AA0E89CB9A271E90EA16941F87FE8492FF</HASHVAL>
  <TEXT>CREATE INDEX IDX_AWBCOMANDA_CODCOMANDA ON AWBCOMANDA (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BANKAUTENTIF_IBAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC669967F303633725623F8C3E7FDB3EBCDC9F36</HASHVAL>
  <TEXT>CREATE INDEX IDX_BANKAUTENTIF_IBAN ON BANKAUTENTIF (IBAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BONLINKERR_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E12108972548C836F3B85B420345A1681628F855</HASHVAL>
  <TEXT>CREATE INDEX IDX_BONLINKERR_CODIES ON BONLINKERR (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETCAP1_CODBP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBC5D7E3A06F3545808BD23C1E8BFD58041F788B</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETCAP1_CODBP ON BUGETCAP1 (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETCAP1_CODCLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37B0159AC19B79C04C4D85CB835F15E018101F6A</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETCAP1_CODCLS ON BUGETCAP1 (CODCLASEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETCAP_CODBP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>184791AF936C6742D0BB12A00FB441CAC8433C5E</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETCAP_CODBP ON BUGETCAP (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETCL_CODBUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B25BD2038382D2FE2E08674C9011E2382E2339A1</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETCL_CODBUGETPROD ON BUGETCL (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETCL_CODELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D23F13803CFCDFB381BB3B71EC54314559AAC63E</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETCL_CODELEMBUGET ON BUGETCL (CODELEMBUGET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETSTOC_CODBUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D9701AC8AC092970E0A73F5585E30961B975B20</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETSTOC_CODBUGETPROD ON BUGETSTOC (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETSTOC_CODCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6E4B1C968B9AAB9114EBFD91CC529FB3D68DFC9</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETSTOC_CODCLASEA ON BUGETSTOC (CODCLASEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETSTOC_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8367858FB19B184A6495C5A20991F602AFB474D3</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETSTOC_CODOBIECT ON BUGETSTOC (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETVCL_CODBUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA2EF5E1C1B0D6D9DF309BACDBA835FAD0E3D6B3</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETVCL_CODBUGETPROD ON BUGETVCL (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETVCL_CODCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4621EFB9C73F99B9F01F0283F0C92074FD2028C2</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETVCL_CODCLASEA ON BUGETVCL (CODCLASEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETVCL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>999D3A39ABA7557A0BA1AC71B05928CA47E251A3</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETVCL_CODOBIECT ON BUGETVCL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETVL_CODBUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>925463C9DD839AC5D14AE6876CFCFA604B34B600</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETVL_CODBUGETPROD ON BUGETVL (CODBUGETPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_BUGETVL_CODELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E779A5D5872305EA2C5143ADCC6537AC8B2F800F</HASHVAL>
  <TEXT>CREATE INDEX IDX_BUGETVL_CODELEMBUGET ON BUGETVL (CODELEMBUGET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CANTAR_CODDOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA377FB6DBE27C2BB59806911D3889A9DCA1EA64</HASHVAL>
  <TEXT>CREATE INDEX IDX_CANTAR_CODDOC1 ON CANTAR (CODDOC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CANTAR_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4B84022D198AB94677ECC0A93C0C7EE56767289</HASHVAL>
  <TEXT>CREATE INDEX IDX_CANTAR_CODOBIECT ON CANTAR (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CANTAR_SERIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5BB87A702AC4070A6199638796C8F779A6528FF</HASHVAL>
  <TEXT>CREATE INDEX IDX_CANTAR_SERIE ON CANTAR (SERIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CANTAR_USERIDBLOCAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3CC16FE35D6DC9617439230ABBF2E26D1E5CD54</HASHVAL>
  <TEXT>CREATE INDEX IDX_CANTAR_USERIDBLOCAJ ON CANTAR (USERIDBLOCAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CENTRECOST_TIPALOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD1745C16A116F770CD20B8715228CCCBB8C8643</HASHVAL>
  <TEXT>CREATE INDEX IDX_CENTRECOST_TIPALOC ON CENTRECOST (TIPALOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CENTRECOST_TIPCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35054BB273BA5487D42FBAEC138DC4124FB1692B</HASHVAL>
  <TEXT>CREATE INDEX IDX_CENTRECOST_TIPCHELT ON CENTRECOST (TIPCHELT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CFGACTIONS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57F06FBDA3A581EB711D4FEAABE561240F796EFB</HASHVAL>
  <TEXT>CREATE INDEX IDX_CFGACTIONS ON CFGACTIONS (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS1_ANSTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48802E2A8D3F7DCB5C9679DEBA8299C434BEA3FA</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS1_ANSTART ON CHELTAVANS1 (ANSTART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS1_CODCHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A790CF7C16834807CFA5918AD8AC51977ABAE413</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS1_CODCHELTAVANS ON CHELTAVANS1 (CODCHELTAVANS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS1_LUNASTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E42EBEF1F7E6D6D6CD3D8B49B32041B4AFA94668</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS1_LUNASTART ON CHELTAVANS1 (LUNASTART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS_CODIES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DD9601F615A761D4A00AED45CC83D6EB9B3EF7F</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS_CODIES1 ON CHELTAVANS (CODIES1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FAAC2067A1ACFCD420DB04DA8FEAEDF3F3A1620</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS_CODINTR1 ON CHELTAVANS (CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS_CODNC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B5D3EDF6D80B6B056C5FD6AE4C1AEFA5BE1297C</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS_CODNC1 ON CHELTAVANS (CODNC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTAVANS_CODOBLIGPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>251F4851E27D808C70D4DC09963A2D4275CE6BDB</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTAVANS_CODOBLIGPIF ON CHELTAVANS (CODOBLIGPIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CHELTOPER1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01093E8D00E19461BDAF617C1CA2973F7D06218E</HASHVAL>
  <TEXT>CREATE INDEX IDX_CHELTOPER1_CODOBIECT ON CHELTOPER1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPROBARI_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>431CCFFB3C158313CDA593E6D9470A7DA9E7B158</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPROBARI_CODDOC ON CMDAPROBARI (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPROBARI_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EE186DAD96ECD01C61BBF9FDE22D47292BA950A</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPROBARI_TIPDOC ON CMDAPROBARI (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96E6D5D7664B07F2BA5EEF61B88E697E60A6FCF1</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODCOMANDA1 ON CMDPRODMAN (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODLOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4EBA606828A09D3A0DC3182894446F1BCB9D284</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODLOC ON CMDPRODMAN (CODLOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>617AF792CED3D78B5749D1DF5E490A060CC64404</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODMAN ON CMDPRODMAN (CODMAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D94CD495E7A0881F4A573C4A95F9E56313A0A2E</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODOP ON CMDPRODMAN (CODOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODPRODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F31A7CDA539A4411CE9693CC0D1E4CCB4EB5CE15</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODPRODGEST ON CMDPRODMAN (CODPRODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_CODTARIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9AB82D52616043AE6B2C29B4DF508FEB04A20F0</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_CODTARIF ON CMDPRODMAN (CODTARIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAN_NROP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEA22A5B3A698502894F48844185E59CBEAC1C47</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAN_NROP ON CMDPRODMAN (NROP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAT_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AD619ECD6CB3279A9B4BFD3EA54E060642D83E6</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAT_CODCOMANDA1 ON CMDPRODMAT (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4329EE9279D8EB9194AECD1415B07076CBFA86FA</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAT_CODOBIECT ON CMDPRODMAT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAT_CODPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85774442BA57B22FC569CC0464BD31F1ADDF162C</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAT_CODPRODMAT ON CMDPRODMAT (CODPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CMDPRODMAT_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08E52DF7891413E9B3EA73C3467D97A52160F2AA</HASHVAL>
  <TEXT>CREATE INDEX IDX_CMDPRODMAT_TIP ON CMDPRODMAT (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBF83ED660EE54BBAD1A2D30DB4D7E9E1C727CFE</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODCATPRET ON SYNCPRETRETAIL (CODCATPRET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08CBC021B1C6386A43591353E9A5FADA31B87955</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODCOMANDA ON CMDAVANS (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODEXTALT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87E7DA7FEF6858C84671815307E2D597685F6E8C</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODEXTALT_CODOBIECT ON CODEXTALT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODEXTALT_COD_CODOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E140835E7B7230DD59424BFE799625BB73B783D0</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODEXTALT_COD_CODOBJ ON CODEXTALT (CODOBIECT,COD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODGENERAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1F4C4B692CA9F5848A40D002D0A076FD2507BF16</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODGENERAL ON TMP_CURS_REGULARIZAT_LUNA (CODGENERAL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODIESAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BAC78CF099B64659EDD161D38A881CD2874E7560</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODIESAVANS ON CMDAVANS (CODIESAVANS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODINTALT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3BAD0BBC02B805C69CE2F805A0D9D79597CB7B4</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODINTALT_CODOBIECT ON CODINTALT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E502891BC4C308F6F6E48B7BD8FF3F000648A954</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODOBIECT ON SYNCPRETRETAIL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODPOSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6E20F0C4D1F0480A5C0228F522DED7F9ECD6EB8</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODPOSTRETAIL ON SYNCPRETRETAIL (CODPOSTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CODSALA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC2E89447C02058F73231705DF959576DCECF0F0</HASHVAL>
  <TEXT>CREATE INDEX IDX_CODSALA ON SALIUSERI (CODSALA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1ET_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E197D833E45CF8250226D8453590D2C10D001735</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1ET_CODCOMANDA1 ON COMANDA1ET (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1LUNA_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF80CF517C149442EBEE84DC7DCD7B4A49D55100</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1LUNA_AN ON COMANDA1LUNA (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1LUNA_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3ECCFC911499F7405D3EF4D6FD8E811FC565D891</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1LUNA_CODCOMANDA1 ON COMANDA1LUNA (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1LUNA_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D84021B1FA2C0D96BEFED2F985DA04FDD062549</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1LUNA_LUNA ON COMANDA1LUNA (LUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CANTACCEPTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>244703DE94E20509266BACF3770FCE437ABDAE43</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CANTACCEPTAT ON COMANDA1 (CANTACCEPTAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8072244D31231284D03CD809F164F942D8209FA7</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CODCOMANDA ON COMANDA1 (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBB7EE57C64F82706F97D9A73DD23ADDEDB1B9FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CODNORMA ON COMANDA1 (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78044DCCBF62D8502DC4696483E408E2B7E150B4</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CODOBIECT ON COMANDA1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE0BCAA10CE427DB9754F3C5EEF48F06E8647AB2</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CODPROIECT ON COMANDA1 (CODPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6603FB79099FC5CB90C7A37767C6E6645C00B797</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_CODRETETA ON COMANDA1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_RESTACCEPTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>641B21AC1105D4973190169EB2B82A4295ACA656</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_RESTACCEPTAT ON COMANDA1 (RESTACCEPTAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_TERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCDF019CF7C0CCA0E8C5FAB6161BC065F3EB25D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_TERMEN ON COMANDA1 (TERMEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C846DD2079BD721B9E9C5A89441B6FB1FE117509</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA1_UMSEC ON COMANDA1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA3_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFC240EDD8E0A60869C763E96D721726C94D50E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA3_CODCOMANDA1 ON COMANDA3 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA3_CODOPERATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A8A9EC1B3729EB20902869E5069236A1DEC9040</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA3_CODOPERATIE ON COMANDA3 (CODOPERATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_AGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DEF1351EF5E5A7393617F50FF4FAE037F894881</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_AGENT ON COMANDA (AGENT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F95859CB90234D00AF5172E77BD91323C332A66</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_ANLUNA ON COMANDA (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E3A126A0F35ACFBAEEC4CFEDBDFD7A2F8C1C7DA</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_ANULAT ON COMANDA (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5789A1A26F16FC8938B52A6D14F29BC986DC51B6</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_CODGEST ON COMANDA (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82E3DC5D6F1D7014E1E403EF10DBDDE3B94D16A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_CODLOCATIE ON COMANDA (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_DELEGAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>817A7FCE9CCE51A311F35AFFAE2C30D03B6D8ADC</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_DELEGAT ON COMANDA (DELEGAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_DISPLIVRARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06E918FCDDEEBAFC225241465887D2E660F1267F</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_DISPLIVRARE ON COMANDA (DISPLIVRARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_INCHISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83973B139D364C9F24C6BCCF0D61DE0DCAEA2011</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_INCHISA ON COMANDA (INCHISA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E540B1B019DB9260943FDB145820B2E1B1DCE6D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_OPERAT ON COMANDA (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8887041F9F15420A61C798B314CE797B91B06FB1</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_PARTENER ON COMANDA (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>471ECBC4178CA7CC4B096391827CE0A264235666</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_SUBUNITATEA ON COMANDA (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B6D358CEDAF299B1870B09DC0266890ABBB6EA2</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_TIPDOC ON COMANDA (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMANDA_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B471395624D59B8ACD32D32D1A4B914DBF2F4A50</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMANDA_USERID ON COMANDA (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMPENS_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>130E6EEA154AC9F39CADAF02FC93FFCEDD8AA13B</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMPENS_CODGEST ON COMPENS (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMPENS_PARTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14050B4B9C6F77FE04773FF5F3FFB77FFFC36EC4</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMPENS_PARTC ON COMPENS (PARTC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMPENS_PARTD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>739D3CD19BD798C6C552AC50D0678DC253632111</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMPENS_PARTD ON COMPENS (PARTD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_COMPENS_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8CC9E4AA8D7BBF16AD447B3778792C0E347E450</HASHVAL>
  <TEXT>CREATE INDEX IDX_COMPENS_SUBUNITATEA ON COMPENS (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSM_CODCMDPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9EB83A483D63028D55C93B08C4FAD1B91CEA837</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSM_CODCMDPRODMAT ON CONSUMURI_MAN (CODCMDPRODMAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSM_CODCOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>32E050AA540406C15533324233929B25AB35152E</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSM_CODCOMANDA1 ON CONSUMURI_MAN (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSM_CODIES1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9BC9710140AD305046A232638F77E2CFEB40C005</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSM_CODIES1 ON CONSUMURI_MAN (CODIES1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSM_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>55B24D23F7BF11457A48FC4E9F2AD7A9D991B3AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSM_CODOBIECT ON CONSUMURI_MAN (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONST1_CODCATEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F01ECA8D2ACFD3F70B083F696970C48291399D87</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONST1_CODCATEG ON CONST1 (CODCATEG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONST1_SIMBOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2462D98B77380101A4457AD687908643EF5C3D36</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONST1_SIMBOL ON CONST1 (UPPER(&quot;SIMBOL&quot;)) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D704E1B6100DAFEB3050CC0CA420161FB7A5EF6</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTLUNA ON CONSTLUNA (CODCONST1,USERID,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTMAKETA_CODCONST1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E7428A9C034BFF1F26E256CE5E707146CF5925A</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTMAKETA_CODCONST1 ON CONSTMAKETA (CODCONST1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTMAKETA_CODMAKETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A31B08F308D4B754F9FDD5D58CE195B0524BC77A</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTMAKETA_CODMAKETA ON CONSTMAKETA (CODMAKETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTVALPOS_CODCONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F6293AE1CDB988B5C0A0B6CFAC0E7B4AA5F8C24</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTVALPOS_CODCONSTLUNA ON CONSTVALPOS (CODCONSTLUNA,IDX) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTVAL_CODCONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95A219366C4AF591408F1C122FB87967B80259FA</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTVAL_CODCONSTLUNA ON CONSTVAL (CODCONSTLUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONSTVAL_VALOARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>978C39005DB97B7A5C134CE905FF921C22A198B5</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONSTVAL_VALOARE ON CONSTVAL (COALESCE(&quot;VALOARE&quot;,&apos;0&apos;)) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT0_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39121886E9B2A9C8651AF4C0A54942DD3BD1EAF4</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT0_CODCONTRACT ON CONTRACT0 (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT1_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>551C185C80196022BFCA14C806EC1675E2F90337</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT1_CODCONTRACT ON CONTRACT1 (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA4AA2E63B18DD8A474091A443AFB492DC31BDA7</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT1_CODOBIECT ON CONTRACT1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EADAB8FA80AD1D6CCD7C72143AA2796FF0B2379B</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT1_UMSEC ON CONTRACT1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT2_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92041ADA5694A5A7468C2F0C0CAB14C1082F8AC3</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT2_CODCONTRACT ON CONTRACT2 (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTC0_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>419743A8248D301C497FBC6CE09EC3D9D13A8D10</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTC0_CODCONTRACT ON CONTRACTC0 (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTC_CODCONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59721608EB6BA448D9A6330DC360779BF0DA8BB3</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTC_CODCONTRACT1 ON CONTRACTC (CODCONTRACT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTT_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72D6747633AF6DA5CAEA7AA7B669AC275737DE99</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTT_CODCONTRACT ON CONTRACTT (CODCONTRACT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTV_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3776A3B01B644DAD099A38A4530B66EDDB58F80A</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTV_CODCONTRACT ON CONTRACTV (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTXX_CODCONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1B3E07403F917AEE4CB0747AAD5C5F5F20CEBB0</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTXX_CODCONTRACT1 ON CONTRACTXX (CODCONTRACT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACTX_CODCONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9B9DEA3C64074614371BECEC09AFAA6CF599640</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACTX_CODCONTRACT1 ON CONTRACTX (CODCONTRACT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT_CODGENERIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46A2F5FDAB309CB9BB5B53105F7E5A588BE1BB83</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT_CODGENERIC ON CONTRACT (CODGENERIC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT_MONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13B66BB18C421037A89E4C0352B66B2CD95FD67A</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT_MONEDA ON CONTRACT (MONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FE22FD0777B93FCC2C64339609EB8CDF42DF3B3</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT_PARTENER ON CONTRACT (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFC7E0AEB5E708D8A82B38DBCB181E96FDD66AFD</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT_SUBUNITATEA ON CONTRACT (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_CONTRACT_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CE6901948285B2B165D00C67A54B26898095ED7</HASHVAL>
  <TEXT>CREATE INDEX IDX_CONTRACT_TIPDOC ON CONTRACT (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_D39416RNS3_CODD39416RN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>300F5895A39346A40CE2A94520696EB019705596</HASHVAL>
  <TEXT>CREATE INDEX IDX_D39416RNS3_CODD39416RN1 ON D39416RNS3 (CODD39416RN1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_D39416RNS3_CODD39416RNS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D874337218654515DE10605F45FD087278CC803A</HASHVAL>
  <TEXT>CREATE INDEX IDX_D39416RNS3_CODD39416RNS2 ON D39416RNS3 (CODD39416RNS2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DEBUG_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD8F52147D9337F0BE34D8DED46D257398F09806</HASHVAL>
  <TEXT>CREATE INDEX IDX_DEBUG_USERID ON DEBUG_LISTE (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DFLANSZ1_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DEBF5596395071DDF7653A9C8005DCB81ABD55F</HASHVAL>
  <TEXT>CREATE INDEX IDX_DFLANSZ1_AN ON DFLANSZ1 (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DFLANSZ1_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05D03D8CE3C2039E45B75C1BFF7E5FFF541FF6EE</HASHVAL>
  <TEXT>CREATE INDEX IDX_DFLANSZ1_CODLANSZ ON DFLANSZ1 (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DFLANSZ1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2632E83EC859AB3BA446CBDF0A221E52B7E75A6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_DFLANSZ1_CODOBIECT ON DFLANSZ1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DFLANSZ1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0761690ACD0EA717F2A5B84631B2DFE9780A0286</HASHVAL>
  <TEXT>CREATE INDEX IDX_DFLANSZ1_CODRETETA ON DFLANSZ1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DFLANSZ_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>164D6ECB32370DE449E390B47F4D975D39F216FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_DFLANSZ_SAPTAMANA ON DFLANSZ1 (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISAMF_CODDOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA38DEC1C7A723FF93CE2901EB859C7797482359</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISAMF_CODDOC1 ON FISAMF (CODDOC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCART_CODCLASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6CBC53084746225E58B80AA90BB79D9F4742C540</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCART_CODCLASA ON DISCART (CODCLASA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCART_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64C5011E82C4EB017D13E99927DCB6B722516DCB</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCART_CODDISCOUNT ON DISCART (CODDISCOUNT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCART_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F99428CCCBC00245B068427502B9D20414AE39D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCART_CODOBIECT ON DISCART (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCEXCEPTII_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F705BA6744252C9AC3142B3E14CD4FFF656497F</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCEXCEPTII_CODDISCOUNT ON DISCEXCEPTII (CODDISCOUNT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCEXCEPTII_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23D3FF30767CD4069ABDDD59E0932526DD8C41B1</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCEXCEPTII_CODOBIECT ON DISCEXCEPTII (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCINTERVAL_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D8A68E2754BE83EF4308B1762CB499A00E10D08</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCINTERVAL_CODDISCOUNT ON DISCINTERVAL (CODDISCOUNT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCMONETAR_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7507707848749E5349D1771E663AB0BE1247E62E</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCMONETAR_CODIES ON DISCMONETAR (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISCOUNT_CODCRITERIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02106CC2D4394481AC5479DD8250AF6C345588D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISCOUNT_CODCRITERIU ON DISCOUNT (CODCRITERIU) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISTRIBCHELT2_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3658F4E49370A83ECDC61C04A1C40507E535B38</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISTRIBCHELT2_COD ON DISTRIBCHELT2 (CODDISTRIBCHELT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISTRIBCHELT2_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A391215101895CB0BCD102977B9DA470C1F70C9</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISTRIBCHELT2_CODGEST ON DISTRIBCHELT2 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DISTRIBCHELT_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CACA71737FDA185B31E3D3E28DA41077302BC11F</HASHVAL>
  <TEXT>CREATE INDEX IDX_DISTRIBCHELT_SUBUNITATEA ON DISTRIBCHELT (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCASOC_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C86B94B783F5296946C5EAC0AA65227174D2820A</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCASOC_CODDOC ON DOCASOC (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCASOC_CODDOCASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D7C92927D32E273F59FE4A94C36B3AB880BEFBB</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCASOC_CODDOCASOC ON DOCASOC (CODDOCASOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCASOC_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6512A13CA53704B767C5335A6831572B095DD3AA</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCASOC_TIPDOC ON DOCASOC (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCASOC_TIPDOCASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FE28160880E50E00A689FB467795FFBE86D5027</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCASOC_TIPDOCASOC ON DOCASOC (TIPDOCASOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCEDITAT_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04F4D29513B647C8506EDF473CEFF7181E3D5C0F</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCEDITAT_CODDOC ON DOCEDITAT (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCEDITAT_TABELA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>486B11660F12E692C2CD96CD6014B166FFAAB8F7</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCEDITAT_TABELA ON DOCEDITAT (TABELA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCEDITAT_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B92E5988F33B899025926953290362853A101F2B</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCEDITAT_USERID ON DOCEDITAT (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCFREEX_ENDNR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22CE78893DC368097A2F6CE852AC2D0263D78B18</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCFREEX_ENDNR ON DOCFREEX (ENDNR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCFREE_CODCARNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77B708D660ED78F63DE9AC0AAEDDF1F24636E6DA</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCFREE_CODCARNET ON DOCFREE (CODCARNET,STARTNR,ENDNR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCLINK_CODCARNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>581ACC09CFB7F6C15DC126547C0F4FF84C1547DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCLINK_CODCARNET ON DOCLINK (CODCARNET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCLOCK_CODCARNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48015A209F4D9B4804C5260992AD171235A93DDB</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCLOCK_CODCARNET ON DOCLOCK (CODCARNET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCUMENTE_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3BA54ECCFE1C287531ED30E34A031E6A92F494A</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCUMENTE_TIPDOC ON DOCUMENTE (TIPDOC,CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DOCUSERS_CODCARNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A6863E230E050F015182A4F4714D2E6F8289C7B</HASHVAL>
  <TEXT>CREATE INDEX IDX_DOCUSERS_CODCARNET ON DOCUSERS (CODCARNET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DPROFITC_CODDPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F5E921008D0DE6288A2C8A0BBD4DB422B58FFC5</HASHVAL>
  <TEXT>CREATE INDEX IDX_DPROFITC_CODDPROFIT ON DPROFITC (CODDPROFIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DPROFITV_CODDPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48D049453F336B4B74EF24A81689AB7F90EC7B94</HASHVAL>
  <TEXT>CREATE INDEX IDX_DPROFITV_CODDPROFIT ON DPROFITV (CODDPROFIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DVI1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC4DEFFAAF00542D093AAEABACCCB266EEA208BA</HASHVAL>
  <TEXT>CREATE INDEX IDX_DVI1_CODOBIECT ON DVI1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DVI1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6518CE31143C5F86635CB958B889652C26D0DB7A</HASHVAL>
  <TEXT>CREATE INDEX IDX_DVI1_UMSEC ON DVI1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DVI_CONTCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A010B7DAE118F19C06F7F9B562D82380C0F3BBE</HASHVAL>
  <TEXT>CREATE INDEX IDX_DVI_CONTCHELT ON DVI (CONTCHELT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_DVI_CONTTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0716D39EEDC042453BD67A4FC6B035B7A4E27270</HASHVAL>
  <TEXT>CREATE INDEX IDX_DVI_CONTTVA ON DVI (CONTTVA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ELEMBUGET1_CODELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>584F28EC49E757619C6201697F7766AD8A022594</HASHVAL>
  <TEXT>CREATE INDEX IDX_ELEMBUGET1_CODELEMBUGET ON ELEMBUGET1 (CODELEMBUGET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ELEMBUGET2_CODELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1356AF99CAB1BB123B5B4CDE07F987DA9DFB0752</HASHVAL>
  <TEXT>CREATE INDEX IDX_ELEMBUGET2_CODELEMBUGET ON ELEMBUGET2 (CODELEMBUGET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE1_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E212D8618473D922F62855C9741A963A120F33E</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE1_CODEMULARE ON EMULARE1 (CODEMULARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2B977C7418474AF603E69CC73A8EA040A4471E9</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE1_CODGEST ON EMULARE1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE1_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15761D189D397BD60358B7996033FFDB2666EC7C</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE1_CODIOART ON EMULARE1 (CODIOART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>564BACED126F196C6C59871626ADF67442023DB1</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE1_CODOBIECT ON EMULARE1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE1_PRETNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFBD7E092DC4E0982172A0CADAA5B1738A3E2ED1</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE1_PRETNIRSTOC ON EMULARE1 (PRETNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE2_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53BE51042531B7616B5EA0DBE7196CED8947A750</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE2_CODEMULARE ON EMULARE2 (CODEMULARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1E303270DDDF8A8C3BBA0D3AB19763CB700013E</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE_CODIES ON EMULARE (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE_DATABCODCASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>819C73285ED7009BDB17B84C89A0C6B2192208EE</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE_DATABCODCASA ON EMULARE (DATABON,CODCASAMARCAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE_DATABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>901ECE477759B5B95C9012E716884EDBF7031A16</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE_DATABON ON EMULARE (DATABON) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE_FACTURARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFAB19E5AB741D1B4631BBBA689261353A9CF26F</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE_FACTURARE ON EMULARE (FACTURARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_EMULARE_PRELUAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F19A988C1532A98B6267479240BF5A9CB7EC04A0</HASHVAL>
  <TEXT>CREATE INDEX IDX_EMULARE_PRELUAT ON EMULARE (PRELUAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B664627C1D731F12B133C771E1503A748CB17F79</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_AN ON ESTIMARINOD (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_CODESTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B30DC11D389A098C95B24D89152491EB02C8452E</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_CODESTPROD ON ESTIMARINOD_C1 (CODESTIMAREPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_CODESTPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB9E53B0BE6582D8220F6D49D4D8011DAD42634B</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_CODESTPROD1 ON ESTIMARINOD_C1 (CODESTIMAREPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>117012C1D26C95EA72D9FB111BFB76891E60B063</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_CODOBIECT ON ESTIMARINOD_C1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_CODPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81A5B57132147C86E575AFD4BFADF9FCA001A412</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_CODPRODMAT ON ESTIMARINOD_C1 (CODPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>942F63643D6817082386450CA6D5FF348373D21D</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_CODRETETA ON ESTIMARINOD_C1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_NODORIGINAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3599084FD98FD5E3705199D5319796724525E789</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_NODORIGINAL ON ESTIMARINOD_C1 (NODORIGINAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C1_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E22A67EC35AA4B98196D2614413AEC0466D9A4D</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C1_TIP ON ESTIMARINOD_C1 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_CODESTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A05E91258183EEFF8DAADB9F677CF5C8134F1C78</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_CODESTPROD ON ESTIMARINOD_C2 (CODESTIMAREPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_CODESTPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A41550C683DEE2F56A99D95C7BFF3A3F10D74C48</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_CODESTPROD1 ON ESTIMARINOD_C2 (CODESTIMAREPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0E917A17E238B1DE8E3509FB28A0D224B259B6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_CODOBIECT ON ESTIMARINOD_C2 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_CODPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76B14DFB9F88D2D08BC44114B16A5DBEC4AF202C</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_CODPRODMAT ON ESTIMARINOD_C2 (CODPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4A0D873022A154A915C8D3D152257976C7EA601</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_CODRETETA ON ESTIMARINOD_C2 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_NODORIGINAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>817B858035F7A274FE619819F20890C757E39A15</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_NODORIGINAL ON ESTIMARINOD_C2 (NODORIGINAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_C2_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D224E4918CF259CA991EB8B7F6F50380DC17B09F</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_C2_TIP ON ESTIMARINOD_C2 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_CODESTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B28A21C5F62D0F05856577E6BDAB35CDCEE54E8</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_CODESTPROD ON ESTIMARINOD (CODESTIMAREPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_CODESTPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E611CAE4D98A5CF979B86CBA84942291E3AA30DE</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_CODESTPROD1 ON ESTIMARINOD (CODESTIMAREPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA8AE492DFD77DE5584AB34395D844E3674131DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_CODOBIECT ON ESTIMARINOD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_CODPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56EC2AE50B2C6B670DD8FC0A63C11DF9E57C0F67</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_CODPRODMAT ON ESTIMARINOD (CODPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD1AFEA267ABCB6CC8162D956872F699930F3772</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_CODRETETA ON ESTIMARINOD (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_NODORIGINAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>73DF5E74613272E76159B0C0F04632881C6BF10B</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_NODORIGINAL ON ESTIMARINOD (NODORIGINAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EF9BE8586B574570A6A603827E7DD4E6DC6BC20</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_SAPTAMANA ON ESTIMARINOD (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTIMARINOD_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC46FE7F2E7E3C1176953E97F31CD06E4C35B74F</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTIMARINOD_TIP ON ESTIMARINOD (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTPROD1M_CODESTIMAREPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC960926E4419C38C8B0C016C6A9893876ABAE2F</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTPROD1M_CODESTIMAREPROD ON ESTIMARIPROD1M (CODESTIMAREPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTPROD1M_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D33B77CA2161DE6C0193E9DD36847BCACAC56F6F</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTPROD1M_CODOBIECT ON ESTIMARIPROD1M (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTPROD1N_CODESTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD413E45F251A6ADC14B033F3BF48798B62A523A</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTPROD1N_CODESTPROD ON ESTIMARIPROD1N (CODESTIMAREPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ESTPROD1N_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D8EF025278441821031640D0F0A86D3D2F5D11E</HASHVAL>
  <TEXT>CREATE INDEX IDX_ESTPROD1N_CODOBIECT ON ESTIMARIPROD1N (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_FACTSALINK_CODCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FA09FF2F61CAA524F315EB5555C087628E03E57</HASHVAL>
  <TEXT>CREATE INDEX IDX_FACTSALINK_CODCLASEA ON FACTSALINK (CODCLASEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_FACTSALINK_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A54D9567A67ED22A71B02D2BF298E90BD87DBAA5</HASHVAL>
  <TEXT>CREATE INDEX IDX_FACTSALINK_CODCOMANDA ON FACTSALINK (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_FISAMF_CODMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACB416ADAE5E9A4759F42A747358B9DD4E72B35B</HASHVAL>
  <TEXT>CREATE INDEX IDX_FISAMF_CODMIFIX ON FISAMF (CODMIFIX) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_FISAMF_CODOPERATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A46C03A66FC00B5389AA0F94AAA99642F2EA8929</HASHVAL>
  <TEXT>CREATE INDEX IDX_FISAMF_CODOPERATIE ON FISAMF (CODOPERATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_FISAMF_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C63A90483A22724F08B77FFCF57CB7BAA36BE569</HASHVAL>
  <TEXT>CREATE INDEX IDX_FISAMF_TIPDOC ON FISAMF (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GANTT_CODCMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9AC7B040C849694B14C16DEE1F48D1DC36E71DC6</HASHVAL>
  <TEXT>CREATE INDEX IDX_GANTT_CODCMDPRODMAN ON GANTT (CODCMDPRODMAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GANTT_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>392350BB32587318EFC8A455D173749D53E27BCB</HASHVAL>
  <TEXT>CREATE INDEX IDX_GANTT_CODCOMANDA1 ON GANTT (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GANTT_CODGANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C84639D3C5630F69898DC18CA83793BAE65DF3D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_GANTT_CODGANTT ON GANTT1 (CODGANTT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06D6457A3C5E93192530E05B17CB69744F966642</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_ANLUNA ON TMP_MANEVRA_INTR1_GRUPC (ANLUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB4B83F6E8AE8C9D643A0DD3E539CE381430F637</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CODCMDPRODMAT ON TMP_MANEVRA_INTR1_GRUPC (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>769B664E0356F51B3FFE0E8B19336E4824A263CA</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CODDOC ON TMP_MANEVRA_INTR1_GRUPC (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB43A965C1E601AB76ED7175A5560B11B1A7FA25</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CODOBIECT ON TMP_MANEVRA_INTR1_GRUPC (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CODOBIECTORIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A4032F3283A2632AE972EE361E15049DD1DFC02</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CODOBIECTORIG ON TMP_MANEVRA_INTR1_GRUPC (CODOBIECTORIG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CODSEMI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3D361417DE2F205EA407D488ED4BCF731068FBC</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CODSEMI ON TMP_MANEVRA_INTR1_GRUPC (CODCMDPRODMAT_SEMI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_COD_MAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F6A062B1FB2FCADAE8C5947A035451305776EAE</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_COD_MAT ON TMP_MANEVRA_INTR1_GRUPC (CODCMDPRODMAT_MAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_CONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DAE67DA3731454EA88A17DC358FD2D62EA5FF700</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_CONT ON TMP_MANEVRA_INTR1_GRUPC (CONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_GESTIUNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3329E51B36B8D559BBB358303149ECF224F27CB7</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_GESTIUNE ON TMP_MANEVRA_INTR1_GRUPC (GESTIUNE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_NSCONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFB1BAD7B0FBE4573B44BFFE58B23AFE9373D96A</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_NSCONSUM ON TMP_MANEVRA_INTR1_GRUPC (CODNIRSTOCCONSUM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF5B9E3CF8A7C0E6C251EC0145562201145E28F4</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_TIPDOC ON TMP_MANEVRA_INTR1_GRUPC (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GC_TIPLINIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8109980DF25884B4F497A312D30BA7E7FC87967</HASHVAL>
  <TEXT>CREATE INDEX IDX_GC_TIPLINIE ON TMP_MANEVRA_INTR1_GRUPC (TIPLINIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GENERAL_DATATVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7F9EB749003DD39E827D99A363B90EC1CF97D66</HASHVAL>
  <TEXT>CREATE INDEX IDX_GENERAL_DATATVA ON GENERAL (DATATVA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GENERAL_MONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F166554213E12E90122FC59ABDB468ECE5ED07A9</HASHVAL>
  <TEXT>CREATE INDEX IDX_GENERAL_MONEDA ON GENERAL (MONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GENERAL_TIPCODSEMNIFICATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF5F5712EC93908FBD3716340CBD434605DDB18C</HASHVAL>
  <TEXT>CREATE INDEX IDX_GENERAL_TIPCODSEMNIFICATIE ON GENERAL (TIPDOC,CODDOC,SEMNIFICATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GL_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>068CDD428B37C7F60585AB160A81F014A3C7F9E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_GL_ANLUNA ON TMP_MANEVRA_INTR1_GRUPL (ANLUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GL_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0608157F84C95E644D3BCBF0749967C2A7A6606</HASHVAL>
  <TEXT>CREATE INDEX IDX_GL_CODCMDPRODMAT ON TMP_MANEVRA_INTR1_GRUPL (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCMD1_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1077A986348A45FC5006B965ADAC239C0B4FFF92</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCMD1_CODCOMANDA1 ON TMP_GENNP_CMD1 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCMD1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>752E74DA120731D15C1B3DF03EE147451F03D579</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCMD1_CODGEST ON TMP_GENNP_CMD1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCMD1_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0223AE6E422EAA42F21C4B6115A2B11CF6D04EF0</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCMD1_CODPERS ON TMP_GENNP_CMD1 (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCMD1_CODPROGRAMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23D457AEC240FCDD3217401D22F8C3EC3D035936</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCMD1_CODPROGRAMF1 ON TMP_GENNP_CMD1 (CODPROGRAMF1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCMD1_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9242E6D8155C925A6AE7A69B0781D7B915D03C0B</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCMD1_USERID ON TMP_GENNP_CMD1 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCRS_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDBF632E5B8BC06C13AC644FE4DDCEAB694063DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCRS_CODCMDPRODMAT ON TMP_GENNP_CRS (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCRS_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>127BA460F10BCFE4D8CF0C5B2CA357CDAEEFCC8B</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCRS_CODOBIECT ON TMP_GENNP_CRS (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCRS_CODPROGRAMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB9C4763D4AE70BD5F1C975B2BA37FD552BCA819</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCRS_CODPROGRAMF1 ON TMP_GENNP_CRS (CODPROGRAMF1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCRS_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4288DBDD2498DF15B3122D418260F5824D0BB935</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCRS_TIP ON TMP_GENNP_CRS (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPCRS_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7A9495E7AE4A7718ADC36F20CF1E0014FAA266D</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPCRS_USERID ON TMP_GENNP_CRS (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPMAN_CODCMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01A89EA9101C7FF9C90A993394880AA05BDB69F3</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPMAN_CODCMDPRODMAN ON TMP_GENNP_CMDMAN (CODCMDPRODMAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_GNPMAN_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D82EF580696777E9DD194EC42233934221D88A1B</HASHVAL>
  <TEXT>CREATE INDEX IDX_GNPMAN_USERID ON TMP_GENNP_CMDMAN (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E2E2C0B5FBE34B4FE33B9ECC7DBD9AB414032BE</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI ON IESIRI (AN,LUNA,OPERAT,ANULAT,TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1RETAIL_CODIESRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF5C3781A2C7984A1D81AAB301C806E525F8AB34</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1RETAIL_CODIESRETAIL ON IESIRI1RETAIL (CODIESRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1RETAIL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECA071F5EBDB091599E05E6958FBC0A563F4BCFB</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1RETAIL_CODOBIECT ON IESIRI1RETAIL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1RETAIL_CONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE1BEA6EC91C3AE3853E59788C770B9A39486DEF</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1RETAIL_CONT ON IESIRI1RETAIL (CONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1RETAIL_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E7A133F843D751DF1A540CB17843B5B359D9CBD</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1RETAIL_CONTSERV ON IESIRI1RETAIL (CONTSERV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1RETAIL_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56173F04F5061928BD585325FB47232019198B95</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1RETAIL_UMSEC ON IESIRI1RETAIL (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CODCMDINT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>378703AE29D6421408304651DEEE66CB763E8047</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CODCMDINT1 ON IESIRI1 (CODCMDINT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>771AB70ADFE70D26113A4C2E5EB08BB99F6FF54C</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CODIES ON IESIRI1 (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CODIES1STORNO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>502247B008016413BF756C43BC8C0CC10009B110</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CODIES1STORNO ON IESIRI1 (CODIES1STORNO) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CODLINIEDOCIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C55C2D0D3520457524739B016A9475D6DF4D503F</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CODLINIEDOCIMP ON IESIRI1 (CODLINIEDOCIMP,TIPDOCIMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D808E027E3E29C7A334F1605F7175485F3A17AC3</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CODOBIECT ON IESIRI1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B7EF5A9B151BEA70FA33BE334001CFB4FC86973</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CONT ON IESIRI1 (CONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C4FA3A96BEE9FF259CEFF134AA233AB1E9B23FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_CONTSERV ON IESIRI1 (CONTSERV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_RESTFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1839B03B0F1CF14731D0A0F09D148403F5127876</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_RESTFACT ON IESIRI1 (RESTFACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93ABC8FE4B0D040BA01A841713DCBA71F5506450</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI1_UMSEC ON IESIRI1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0FA6A08EAB368FD0E7264AB90C2B42D6EBCFEE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_ANLUNA ON IESIRIRETAIL (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCB8F6DB360745DCE2C7F4C26AF52ED7D8474764</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_ANULAT ON IESIRIRETAIL (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E654ABCCA01977CBF7344368E65CA3CB6CF01DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_CODIES ON IESIRIRETAIL (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_CODSEDIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17F7451E8058E209569AD1F1184194945909BCB4</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_CODSEDIU ON IESIRIRETAIL (CODSEDIURETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_NRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60ED11C9C4363DD009AB33F94B41F1C4D22DF410</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_NRDOC ON IESIRIRETAIL (NRDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7AF8F1A19CF0B6CBD2F6A642DECB3F4D158AFD7</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_OPERAT ON IESIRIRETAIL (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7044D8A23881C80677B0A3B2897116C1547C30C7</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_PARTENER ON IESIRIRETAIL (CODPARTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_SERIADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B3A1DCBAEB4C6E61DF54256BFF5D2F00042E1E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_SERIADOC ON IESIRIRETAIL (SERIADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4C2C3C846C6971459F85EF43449F668D42120B9</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_SUBUNITATEA ON IESIRIRETAIL (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRIRETAIL_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E46AC828A96F88D092B715830C1AF7067EEEC4F</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRIRETAIL_TIPDOC ON IESIRIRETAIL (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04BB29C4791356422B7BD7EA03971D297F5AF317</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_ANLUNA ON IESIRI (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89AE9B5B12B31D2CA72B3C2F29ABBEFCE055BD27</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_CODLOCATIE ON IESIRI (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_CODMONETAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF60B902097113F15935D0456C228589B03118AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_CODMONETAR ON IESIRI (CODMONETAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8DC5A27B94B7C50D999FBBA731F16187B465855</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_CODSUBUNIT ON IESIRI (CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_CONTDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED2D498C44A4699A6B6CD252559643654956F1FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_CONTDISCOUNT ON IESIRI (CONTDISCOUNT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_CONTINTERMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3BE5463017D38673BA91F3372D2745393D1CA71A</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_CONTINTERMED ON IESIRI (CONTINTERMED) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_DATADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49335E6CDFBEF7F6F24F4AF94908DAE17BA71677</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_DATADOC ON IESIRI (DATADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_NRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC223039C1254137ED0AEF6C1F0F67A525BEE7EF</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_NRDOC ON IESIRI (NRDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>65FEFCE6DBE8E17347A5E05D4A7E420472EF14EE</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_PARTENER ON IESIRI (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_SERIADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>736319E09E62C2D54E9A9E283194259D786E3D42</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_SERIADOC ON IESIRI (SERIADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6649DA0355A31D368A33CB66014F6D587AF724B9</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_SUBUNITATEA ON IESIRI (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESIRI_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6ECB8C19B319DB8C2FDFF5857DBFCA66B0EF293E</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESIRI_TIPDOC ON IESIRI (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESLINK_CODLINIEAVIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1234A7397379DFBACF310B8EC7FD8F17B407DF1B</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESLINK_CODLINIEAVIZ ON IESLINK (CODLINIEAVIZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESLINK_CODLINIECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9C3614F18C868EB8F17E4A498DB0A6BCFA0B716</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESLINK_CODLINIECOMANDA ON IESLINK (CODLINIECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IESPUNCTE_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71792AFCDBE696E8992922352A7074A48A40635E</HASHVAL>
  <TEXT>CREATE INDEX IDX_IESPUNCTE_CODIES ON IESPUNCTE (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INACTIVRETAIL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57F9D65459984A84047D924B4D18190D6BCEDE67</HASHVAL>
  <TEXT>CREATE INDEX IDX_INACTIVRETAIL_CODOBIECT ON INACTIVRETAIL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INACTIVRETAIL_POSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>381945324D2436745D80FE481C5D4042E7208DBC</HASHVAL>
  <TEXT>CREATE INDEX IDX_INACTIVRETAIL_POSTRETAIL ON INACTIVRETAIL (CODPOSTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTERFATAKLG_IDMESAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FABBA35353E1E29EEE3EC871468B7AEA5F41EC8</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTERFATAKLG_IDMESAJ ON INTERFATAKLG (IDMESAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4003B47835D22DB90743A2E79D4E3CCEC36F8C7</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI ON INTRARI (AN,LUNA,OPERAT,ANULAT,TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_CODCMDINT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0180B58AFA688B2A42AE4B4D0E7BF698EBC96A6F</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_CODCMDINT1 ON INTRARI1 (CODCMDINT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>414BBF1D4E95D5C0AB11A6C0C9C00AC2CD64C558</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_CODINTR ON INTRARI1 (CODINTR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_CODINTR1STORNO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CED50256C8C19D23BAE4B7BF12F3460379CB1556</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_CODINTR1STORNO ON INTRARI1 (CODINTR1STORNO) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EA75DE1888C69D634C5F18424F63AEC9CEB59CD</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_CODOBIECT ON INTRARI1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BE781DC93F09D8228C6BD173BC6BBCF339C4F19</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_CONTSERV ON INTRARI1 (CONTSERV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_MAN_CODINTR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A33A1F3A0A9CA0146F59EBED36904491F02F7AA2</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_MAN_CODINTR1 ON INTRARI1_MAN (CODINTR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>088B8BCD90C0AE08066B9F343D1F69BF9154EBA5</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI1_UMSEC ON INTRARI1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B699D4C68E4069665F304E2FA3A0D73783BFEB7</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_ANLUNA ON INTRARI (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4A3C06167DE9B587CB3A8970220E96EA3FBAAC5</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_CODLOCATIE ON INTRARI (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CCF0B0692EDD9E0F9906C35D387A08CE9EF601A</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_CODMONEDA ON INTRARI (MONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>588D2BAAF3DF2D8BEF20B9CF4F72D279C9822E84</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_CODSUBUNIT ON INTRARI (CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_CONTSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35E819E01F91DCC6DC4A43360309B262E1621EB6</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_CONTSUPLIM ON INTRARI (CONTSUPLIM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_DATADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>154F174B734A08FD64239013F5AFD3220813AFC7</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_DATADOC ON INTRARI (DATADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_IDDESCARCARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2054E79B395C99AB0C27FEBFDB814B99EE504A02</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_IDDESCARCARE ON INTRARI (IDDESCARCARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96A8F506B944BFC19D00CA449344846EEDCAE743</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_PARTENER ON INTRARI (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B1EAE664CF6FFBD5C0FFF10ACF76A6E5ADB8B61</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_SUBUNITATEA ON INTRARI (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRARI_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEF57327095800E72C35A776BFFE4CACB2521BEA</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRARI_TIPDOC ON INTRARI (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRLINK_CODLINIEAVIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A89A63F47D452E5EBCD48430380211D4BC163354</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRLINK_CODLINIEAVIZ ON INTRLINK (CODLINIEAVIZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INTRLINK_CODLINIECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6788572DADD3066C8E6FDC765ADA2E35B85C4E90</HASHVAL>
  <TEXT>CREATE INDEX IDX_INTRLINK_CODLINIECOMANDA ON INTRLINK (CODLINIECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INVENTAR1_CODINVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>619DEDCB4043F23BBF9402E36BB4E21D5806D6DE</HASHVAL>
  <TEXT>CREATE INDEX IDX_INVENTAR1_CODINVENTAR ON INVENTAR1 (CODINVENTAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_INVENTSTOC_CODINVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B277D59ABBD5DF7CEB58767F58919B18B9C47049</HASHVAL>
  <TEXT>CREATE INDEX IDX_INVENTSTOC_CODINVENTAR ON INVENTSTOC (CODINVENTAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D1FC0614C92337C4A3169E5FECAEF6F9F052FAF</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_AL ON IOART1 (CODIOART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6CA32D4137AA60EA170544AA4CA5A3AE14BC4866</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_ANLUNA ON IOART1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_CHELTTVACOLECTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F279961750B8ACC06D6C65D821435325854B972</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_CHELTTVACOLECTAT ON IOART1 (CHELTTVACOLECTAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_CHELTUIELI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC4E63AE84B16BA3141676D7ACD21F02585DFDC1</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_CHELTUIELI ON IOART1 (CHELTUIELI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D8649545709CB04377F879564AE6F87703E6CFD</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_CODIOART ON IOART1 (CODIOART,ANSTART,LUNASTART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_CONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F023D4FB8D4C43F68AF34CBAC6BEAA75A878B7F8</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_CONT ON IOART1 (CONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_CONTROTUNJIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62B407D8C4EBCC2630C7F62FF2A7B66D2241EA71</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_CONTROTUNJIRI ON IOART1 (CONTROTUNJIRI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_DIFERENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AB54641BE1F5B0F559F537661AAE41C6D36D536</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_DIFERENTE ON IOART1 (DIFERENTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_DIVERSE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C68B1BCA068B610613C19F65DA16F3803AE7CBF9</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_DIVERSE ON IOART1 (DIVERSE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_MINUSINVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B6ADDC7BE9736C1ACDA25CF6D98B9FAFC5571D0</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_MINUSINVENTAR ON IOART1 (MINUSINVENTAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_PLUSINVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F690E0D3F540FF6C33ED28462B9C1A94A9DD978</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_PLUSINVENTAR ON IOART1 (PLUSINVENTAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOART1_VENITURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E55BAA9871D7DE0125CDD7EB86986E31EC6071D5</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOART1_VENITURI ON IOART1 (VENITURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOARTLINK_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A80DE1A8973B069AC6295818D91CD5B4D5D6F83</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOARTLINK_CODIOART ON IOARTLINK (CODIOART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOBANK1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90C37EEC33F9AD190633336BC4DF1151D8E98195</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOBANK1_AL ON IOBANK1 (CODIOBANK,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOFILIAL1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDDE3475553F3A70D8BFCA231ECF448FBE0E2F26</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOFILIAL1_AL ON IOFILIAL1 (CODIOFILIAL,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOFILIAL1_CONTCB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5788D99E66983078148F41FA73DFD2FE50FB437</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOFILIAL1_CONTCB ON IOFILIAL1 (CONTDECONTCB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOFILIAL1_CONTCMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC178177C70A70B29671F8E6B55CD846DD41513E</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOFILIAL1_CONTCMP ON IOFILIAL1 (CONTDECONTCMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOFILIAL1_CONTDECONTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25DBC4203FFBE6C658363DFB074CE8789459815F</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOFILIAL1_CONTDECONTARE ON IOFILIAL1 (CONTDECONTARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOFILIAL1_CONTSERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1698F24603FF94EFC6F87CF47A57A29DBF71A4DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOFILIAL1_CONTSERV ON IOFILIAL1 (CONTDECONTSERV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPART1X_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FCD0CFCB1F0D0034913AF42176F66A5BE0D327DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPART1X_AL ON IOPART1X (CODIOPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPART1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2A0F7DE477AB6929917AB09036C2C1C7B386192</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPART1_AL ON IOPART1 (CODIOPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPART1_X_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>354FA706064F0975BC7121C7D0D0FD6B960AC104</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPART1_X_AL ON IOPART1_X (CODIOPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E5A38241BC70A56D06ABE6146B7B68CBFCF1D6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_AL ON IOPERS1 (CODIOPERS,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CODIOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66536F74525B0E85AB1CDF029E61ACDD07F09C69</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CODIOPERS ON IOPERS1 (CODIOPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTALTERETINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F50A8A3CB59C6B6C5F67E7A5F2305AA76C5C760</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTALTERETINERI ON IOPERS1 (CONTALTERETINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>677EE0E2BADB6F162598EAF9593EFDB98C4CFC07</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTAVANS ON IOPERS1 (CONTAVANS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTAVANSDECONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E4F792E7B3730397D3EA158D32FB521420BA2D9</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTAVANSDECONT ON IOPERS1 (CONTAVANSDECONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTBOALA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E817859B791E793ED8BD74B271BB3CD359FE9050</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTBOALA ON IOPERS1 (CONTBOALA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTECHIPAMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B0CDA18DE31F987AA65698F3DD51010F97827D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTECHIPAMENT ON IOPERS1 (CONTECHIPAMENT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTGARANTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0AB689C3333B980A7BFF7D0EE62944B68C6D0162</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTGARANTII ON IOPERS1 (CONTGARANTII) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTIMPOZIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>035197A51FAD629364446968F31DF3C9FCDEDC87</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTIMPOZIT ON IOPERS1 (CONTIMPOZIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTIMPUTATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4ABC37F61DD7A058F5A3D464A4C456538329A43</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTIMPUTATII ON IOPERS1 (CONTIMPUTATII) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTLIKI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F235152F3E1BE6228F70EF978C79590348D82BF0</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTLIKI ON IOPERS1 (CONTLIKI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTNATURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E6391C07197F3E2A0342BC7C2FEA87E7E57B211</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTNATURA ON IOPERS1 (CONTNATURA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_IOPERS1_CONTNERIDICATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72FCDE3B9254376DB59ED5EDC145129908C93D35</HASHVAL>
  <TEXT>CREATE INDEX IDX_IOPERS1_CONTNERIDICATE ON IOPERS1 (CONTNERIDICATE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FABFA9711068C25D698647E442161D39AE56A46D</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL ON JURNAL (AN,LUNA,TIPDOC,CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B1E08EE4AEE5E43B188BCE2E17E94BF94BDD5AD</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL1 ON JURNAL1 (AN,LUNA,TIPDOC,CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E3BDD835BD08C532493B4CA88B3F120634FB3BB</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL1_ANLUNA ON JURNAL1 (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL1_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3BBEF917C0264E337237182001F28A08750AD628</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL1_DOC ON JURNAL1 (TIPDOC,CODDOC,INDEXLOCAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL1_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A05B670A4DB4D43C9CA2A7ABA824C55F9F837729</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL1_GEST ON JURNAL1 (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CBC0D57409DE7A3B88792D9FDF8A55C3DA267FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL_ANLUNA ON JURNAL (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL_CONTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0E8200C091F21CB8AD25915DA7CFFA3A344027A</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL_CONTC ON JURNAL (CONTC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL_CONTD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EA17D88E89B5029518023163BECDF4042AF7126</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL_CONTD ON JURNAL (CONTD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6E1531DB02EFA9C756F1D2B4DB24BF709FFD261</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL_DOC ON JURNAL (TIPDOC,CODDOC,INDEXLOCAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_JURNAL_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0E7AFD0DEB504141F8B90651B8370BE0AF84E38</HASHVAL>
  <TEXT>CREATE INDEX IDX_JURNAL_GEST ON JURNAL (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE0_CODCMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BA0903EE10397D053E3BDA2790B30A8DECA61F1</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE0_CODCMD1 ON LANSARE0 (CODCMD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE0_CODLANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3891A4C1BDD38C2C5030FBC78204158E7531C225</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE0_CODLANSARE ON LANSARE0 (CODLANSARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE0_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30CBC69782AA10A647A51EEAF3F042A10ADDF9BA</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE0_CODPROIECT ON LANSARE0 (CODPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE0_TERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75E57077D072A6311D8ED96FD779ECA5ECD52347</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE0_TERMEN ON LANSARE0 (TERMEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE1_CODCMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DAA523F4C4D91BBA676771EE7B07DED7402C2FB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE1_CODCMD1 ON LANSARE1 (CODCMD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE1_CODLANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACD652676D7871C7D6DEADD8A6ADC4F683E99D54</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE1_CODLANSARE ON LANSARE1 (CODLANSARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE1_CODLANSARE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2787C23DEC36BC21EA57D4F57674B76E40119259</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE1_CODLANSARE0 ON LANSARE1 (CODLANSARE0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE1_CODPROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6ADCC248AE0624D1EDA6947213D4F93360124333</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE1_CODPROIECTNOD ON LANSARE1 (CODPROIECTNOD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE1_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D34C05847439A7F6C388CA6F6FCEF1CF57B2E321</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE1_TIP ON LANSARE1 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARENEC_CODLANSARE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70DA70D3CE58DAC0432C45991DC446F248E2A2DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARENEC_CODLANSARE0 ON LANSARENEC (CODLANSARE0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARENEC_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E42447CBF3E60E771D1D3F3978A57488D44941A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARENEC_CODOBIECT ON LANSARENEC (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARENEC_CODPROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A09DD7B9B8AF10E30AAC2A11DF5DCBFC54B104E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARENEC_CODPROIECTNOD ON LANSARENEC (CODPROIECTNOD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28217EFD4088F0AAC4419C40E0360107119BC511</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_ANULAT ON LANSARE (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_AUTOMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62472D6EC053AE10C78CEA3860751DFF617B8F0A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_AUTOMAT ON LANSARE (CODSCENARIU,AUTOMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_BLOCAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0146AFF058D342B5201ED859F30791F7984A1110</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_BLOCAT ON LANSARE (BLOCAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_CODCMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21DA7E0C321157FC9FE8600444A6D24501488257</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_CODCMD1 ON LANSARE (CODCMD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_CODSCENARIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33DBB93E6A76AB9C6731A4D2645A6D1365CA711F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_CODSCENARIU ON LANSARE (CODSCENARIU) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_DATADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38A74890D9D27B7BCC49DEB9F3CE3D3C06942D6E</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_DATADOC ON LANSARE (DATADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSARE_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06D8BF8AE7AFC5BF094016E9AF5490D7D31EB40B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSARE_OPERAT ON LANSARE (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSGEST_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84502349DD5A175C23A8E6FBA44DC68FD9B08BFE</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSGEST_CODLANSPROD ON LANSGEST (CODLANSPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD1_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>295C697F04324F590CC3AA8A14850BF8C01456C3</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD1_CODLANSPROD ON LANSPROD1 (CODLANSPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F03E19EA317CECBB98EF785789EA02C2E9BF4843</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD1_CODOBIECT ON LANSPROD1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2S_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A807B48E37C8DDE1D8C0A06214CD5B83C2CD7A5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2S_CODGEST ON LANSPROD2S (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2S_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>076A8A990BD39D0C7BF3E4F405C3C498400A7B82</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2S_CODLANSPROD ON LANSPROD2S (CODLANSPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3D1C47D2476911A4C97CBF55098AFF1B323CC5B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2_CODGEST ON LANSPROD2 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>582664B8D06F050C3ED7F254405CE168952CE501</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2_CODLANSPROD ON LANSPROD2 (CODLANSPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2_CODLANSPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0B6A7B78E2E918F60974C5D0D9EB1187EE2698F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2_CODLANSPROD1 ON LANSPROD2 (CODLANSPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10425EC2E97B9608175745BDE2BA101B8D3983FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD2_CODOBIECT ON LANSPROD2 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D8526A889DCE6EE2C7A6F6CBA2B4B29F7ED1100</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD_ANLUNA ON LANSPROD (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBA6370E7551972F0D70224963647659A8021207</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD_ANULAT ON LANSPROD (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1290099DA1170D32C743180F12F9B74C8AD0339</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD_OPERAT ON LANSPROD (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D42F16CA6A86BF9E4E6449F03BD2436C91824BC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD_SAPTAMANA ON LANSPROD (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSPROD_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6167B2F09F501F39436A158E6AFDE5B0B837B0B7</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSPROD_SUBUNITATEA ON LANSPROD (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_DUMINICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D1B3F0A421160527BBBFBD376A47A205FF5BC30</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_DUMINICA ON LANSZ1_MANEVRA1_L (CODCMD1_DUMINICA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_JOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BCCBA5871A1A003AED0CDBCE1F25D1D1F2F7079</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_JOI ON LANSZ1_MANEVRA1_L (CODCMD1_JOI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_LUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67999F85B3361ED339C3CA3AA517EA6360854043</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_LUNI ON LANSZ1_MANEVRA1_L (CODCMD1_LUNI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_MARTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3728574F25DA908F48D9965150B34E5DDE7BD32</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_MARTI ON LANSZ1_MANEVRA1_L (CODCMD1_MARTI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_MIERCURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0C2E5E2D2504B370050E7D6FC2054EF5CDFABBC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_MIERCURI ON LANSZ1_MANEVRA1_L (CODCMD1_MIERCURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_SAMBATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>350AFA63310D98F0F14D88671156ACFC2661BB0F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_SAMBATA ON LANSZ1_MANEVRA1_L (CODCMD1_SAMBATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODCMD1_VINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>309F0CE56152732CFB0D3309F7772E7229B8A1B1</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODCMD1_VINERI ON LANSZ1_MANEVRA1_L (CODCMD1_VINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BF18A6B441633CC49B708E2C605B0F3765ECEFA</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODFORMATIE ON LANSZ1_MANEVRA1_L (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB990DD2052C8AEA00F9497D4959A22F813A34C3</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODGEST ON LANSZ1_MANEVRA1_L (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F5BDE8BC6B4993913315C4D80AA4833A2E91627</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODLANSZ ON LANSZ1_MANEVRA1_L (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>760BFF6D9C06A31522FB25E21E51139E2364816C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODLANSZ1 ON LANSZ1_MANEVRA1_L (CODLANSZ1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F21556EA33738A476484AE4C33FF11A4DC77130</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODNORMA ON LANSZ1_MANEVRA1_L (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A9601E40D5CB77E1908750CADE1E966D4141D439</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODOBIECT ON LANSZ1_MANEVRA1_L (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99DA6A4373F42517B67221D5C212DAECEA51764C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODPRODCOMP ON LANSZ1_MANEVRA1_L (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>980CDB349C8F1CDF99EB476BAB6F3950C8B490E4</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_CODRETETA ON LANSZ1_MANEVRA1_L (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_SCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>413487DD737D56E03437E8ACF247FFB31C4D2702</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_SCHIMB ON LANSZ1_MANEVRA1_L (SCHIMB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1L_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51C3FDED34B4E1FC15E1EE70F041BA96A5D70FFD</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1L_USERID ON LANSZ1_MANEVRA1_L (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_DUMINICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F20938E01D7C88793E25AB3B00B60851E2014CFB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_DUMINICA ON LANSZ1_MANEVRA1 (CODCMD1_DUMINICA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_JOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22603865FBCF5F97CD4CDC7D9EF73B9F41819FDC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_JOI ON LANSZ1_MANEVRA1 (CODCMD1_JOI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_LUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C343960D119D666AB481526CE34978D191C6F76</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_LUNI ON LANSZ1_MANEVRA1 (CODCMD1_LUNI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_MARTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21E2EAD4D016343C0CD3BCA5EAC2E29DAD0C044B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_MARTI ON LANSZ1_MANEVRA1 (CODCMD1_MARTI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_MIERCURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44B916980C2F924754D1110B6C409638A0BE43BD</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_MIERCURI ON LANSZ1_MANEVRA1 (CODCMD1_MIERCURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_SAMBATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D01906A494AF7E4D3265761678F7043CB416028B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_SAMBATA ON LANSZ1_MANEVRA1 (CODCMD1_SAMBATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODCMD1_VINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFDCD941C8F520C09FB3CE87A337136302A73BC7</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODCMD1_VINERI ON LANSZ1_MANEVRA1 (CODCMD1_VINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8888C5801C00946AB79B9B9D77DD2943A12CDE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODFORMATIE ON LANSZ1_MANEVRA1 (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C51A71A9E995EDBFE2A8A2CC641793849ADE9618</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODGEST ON LANSZ1_MANEVRA1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1A0B0C196EB95A4F3A406DE6F692B07161746CC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODLANSZ ON LANSZ1_MANEVRA1 (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFFA3E27417EBF82E541ADC5509C91FCB8B4ABDE</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODLANSZ1 ON LANSZ1_MANEVRA1 (CODLANSZ1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A241125F09C13CE7F6BFB2AAD2B51D40E5D249E8</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODNORMA ON LANSZ1_MANEVRA1 (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C99009FE88B146D26E346E9CCEBBA94AE16A6BAA</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODOBIECT ON LANSZ1_MANEVRA1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ABCEB65096A35363E95AC384B3FEC061ED60D0BA</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODPRODCOMP ON LANSZ1_MANEVRA1 (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDFF1DD42F7A876F8C93ECFB0A4D581E5A7F9201</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_CODRETETA ON LANSZ1_MANEVRA1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_ORDINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31B7BE2212DD1871A4CF5EB28FCE52EAC2A7CFBB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_ORDINE ON LANSZ1_MANEVRA1 (ORDINE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_SCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6C4C4BB6A8850E8460C829BA0C67C2FBECB2E38</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_SCHIMB ON LANSZ1_MANEVRA1 (SCHIMB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M1_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CA3B7969349FC9A73659B548924DDC669AB648B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M1_USERID ON LANSZ1_MANEVRA1 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_DUMINICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEB0A128B3BC4F90F8A60035BD7F9E0D768C2F0F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_DUMINICA ON LANSZ1_MANEVRA_L (CODCMD1_DUMINICA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_JOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70F15324DD821B9B567BD7414D2B0750091A1E46</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_JOI ON LANSZ1_MANEVRA_L (CODCMD1_JOI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_LUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E872B821EEDFAA05F760B15C68D3499333E10E07</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_LUNI ON LANSZ1_MANEVRA_L (CODCMD1_LUNI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_MARTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23B476EFFFF0E941693F91A0760E7FA251364F4C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_MARTI ON LANSZ1_MANEVRA_L (CODCMD1_MARTI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_MIERCURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2DC794CA34736D6240C3929017B3A8E2A1062F9</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_MIERCURI ON LANSZ1_MANEVRA_L (CODCMD1_MIERCURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_SAMBATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>579633037851A0BD8DC952C9330EDEBEF1971096</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_SAMBATA ON LANSZ1_MANEVRA_L (CODCMD1_SAMBATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODCMD1_VINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B90B686161FF978BBAB6DD2F28D325D3FF84B19</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODCMD1_VINERI ON LANSZ1_MANEVRA_L (CODCMD1_VINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B20DCAC69234AD182F48AAB980420A223C17A70B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODFORMATIE ON LANSZ1_MANEVRA_L (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0854927FD428EF2770F5DCC542142F02A250534</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODGEST ON LANSZ1_MANEVRA_L (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F2F6ED16E4A9030E761814E678B9C05D918F9AC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODLANSZ ON LANSZ1_MANEVRA_L (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DA64A0682A506B86F681F8419C75A763571FC4A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODLANSZ1 ON LANSZ1_MANEVRA_L (CODLANSZ1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AECBD25C9C77410C14F5ECB900FBAB095B8F55A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODNORMA ON LANSZ1_MANEVRA_L (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD33CE86BF57E1A19D99B511E9F9032676543A9B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODOBIECT ON LANSZ1_MANEVRA_L (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E3A9644F92823AC5915F89AAD4F222F0CBB4E3B</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODPRODCOMP ON LANSZ1_MANEVRA_L (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5DF863002BA4E47E731F051EE0C32CC19301AFE</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_CODRETETA ON LANSZ1_MANEVRA_L (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_SCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A1E69A30EFE6D56401236D60007AB89A91F583A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_SCHIMB ON LANSZ1_MANEVRA_L (SCHIMB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1ML_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E5131B8DED8B58BC3E672434C74205ED095C781</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1ML_USERID ON LANSZ1_MANEVRA_L (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_DUMINICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E1819D51FC58A9B404718E91896BDB48FA57F6D</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_DUMINICA ON LANSZ1_MANEVRA (CODCMD1_DUMINICA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_JOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3538021D09818CAADDF4A37956CC09E6D14F1C5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_JOI ON LANSZ1_MANEVRA (CODCMD1_JOI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_LUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DECAC66ED15A47F444FC1C63C405BEDE4173F23</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_LUNI ON LANSZ1_MANEVRA (CODCMD1_LUNI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_MARTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C9D25CA0DB1132F229418FE382CE8710C48B08C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_MARTI ON LANSZ1_MANEVRA (CODCMD1_MARTI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_MIERCURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4B687F3F35A1D1CE7A5B97CF439BD78CE5D6EF8</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_MIERCURI ON LANSZ1_MANEVRA (CODCMD1_MIERCURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_SAMBATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1E67D15A554245A1A5B8A2143EB1BCC9C93D57C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_SAMBATA ON LANSZ1_MANEVRA (CODCMD1_SAMBATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODCMD1_VINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF951F4B9AE187A2A85AFF7F8C705F6058046E2F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODCMD1_VINERI ON LANSZ1_MANEVRA (CODCMD1_VINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F725E9AC5A2D1057715D530AFA79F7D46E59BCEB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODFORMATIE ON LANSZ1_MANEVRA (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F3293998637DD6BA2CBDB2B5D4A7AC030B1B10F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODGEST ON LANSZ1_MANEVRA (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87D54143B0B0BE77DD84B0CA3D2C8106A9BC683A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODLANSZ ON LANSZ1_MANEVRA (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A305014B7BA22E195B258F2F20F8B033EE47EBCE</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODLANSZ1 ON LANSZ1_MANEVRA (CODLANSZ1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57EF8E353D2C678C2C2C3E6FF8799D8278223F0C</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODNORMA ON LANSZ1_MANEVRA (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>716FD9B6DC26CF8E4E2F98E439282EAAB37A0122</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODOBIECT ON LANSZ1_MANEVRA (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>935A63CD7646FC95414BD400E787D651931A26AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODPRODCOMP ON LANSZ1_MANEVRA (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D23CCF31ADCED7F399A93A55AEA130291CE88BCB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_CODRETETA ON LANSZ1_MANEVRA (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_ORDINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CB63456428095E459FFE0CA1627D6AFE2FA7FB3</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_ORDINE ON LANSZ1_MANEVRA (ORDINE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_SCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20CD374FDC4CD31F0A06FC4124FFAE06EC6954A5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_SCHIMB ON LANSZ1_MANEVRA (SCHIMB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1M_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6452B1F3C899D5DF4B20C059931206B57285B873</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1M_USERID ON LANSZ1_MANEVRA (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_DUMINICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D898D6C1E335742C9A3A9450706E9F718020DC78</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_DUMINICA ON LANSZ1 (CODCMD1_DUMINICA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_JOI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>787F19CDE64CD8ACC6A06F1C333FE090F3B0C707</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_JOI ON LANSZ1 (CODCMD1_JOI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_LUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>189A6A1E5B17434AD30EFF52589D55BDEF2F97DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_LUNI ON LANSZ1 (CODCMD1_LUNI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_MARTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5A7B973707452DC29C53D09D84BF870A73C26D6</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_MARTI ON LANSZ1 (CODCMD1_MARTI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_MIERCURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82D9F8D24CBC4AC5D2EEF7643C684B5894A40059</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_MIERCURI ON LANSZ1 (CODCMD1_MIERCURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_SAMBATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64A30991F7EC21203A34348693C027905E27D376</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_SAMBATA ON LANSZ1 (CODCMD1_SAMBATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODCMD1_VINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85A83459E792290C6A0841CECB7721FBC1164293</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODCMD1_VINERI ON LANSZ1 (CODCMD1_VINERI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9403232D348CA11B0BE98B88AE1230920131267</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODFORMATIE ON LANSZ1 (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A83A7CD11A7C784159EBE530E94F57C0B4BC9659</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODLANSZ ON LANSZ1 (CODLANSZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90C6150AA61AD681235B50EB7D79E2F219A055E9</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODOBIECT ON LANSZ1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8F5C56C435BC0A0C7B307FA92377978D4EC4075</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_CODRETETA ON LANSZ1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ1_SCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D07F22ABC6EFC175071D427DFB3A24E84E87D14</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ1_SCHIMB ON LANSZ1 (SCHIMB) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB7F874F88B7EE0181027213E5D910C5B54C9E5E</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_AN ON LANSZ (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>495A2F2D25E99A4907CA39B0BC226F86B1CFB2F5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_ANLUNA ON LANSZ (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1975028115AE6A50847AF2A2154B1BE8A9660303</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_ANULAT ON LANSZ (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64CC75753364624555AA52E507E8CC870678FE43</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_CODGEST ON LANSZ (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_CODPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4A85F1EA5F432CFF0329887B050BD6254401398</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_CODPLANIFPROD ON LANSZ (CODPLANIFPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_FINALIZAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB2D1FE705568F7774B7582D91F9B41859F62331</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_FINALIZAT ON LANSZ (FINALIZAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C32A119C45495290840BF728BE3E70A6A6D0031</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_OPERAT ON LANSZ (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>938E2D2B6DDCDA04A66E0E45FF98A9D8B741F342</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_SAPTAMANA ON LANSZ (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LANSZ_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FAA068A7D2B9D79A3FF039715100C997483FF3F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LANSZ_SUBUNITATEA ON LANSZ (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LASZ1_CMD_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7DC98E2B9C34426CBFEEC6D9DD0AB9C6CB110CC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LASZ1_CMD_CODCOMANDA1 ON LANSZ1_CMD (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LASZ1_CMD_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9598927E99E32AF6E7600976ADC3FD0ED2184DE5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LASZ1_CMD_CODLANSZ1 ON LANSZ1_CMD (CODLANSZ1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR11_CODDVI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18F3CE47DB11989C58A77D952A1AE26EFFDA5D96</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR11_CODDVI1 ON LIVR1 (CODDVI1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR11_CODNTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36EFD4E133716CEF63A35ED21C0680C2022309A5</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR11_CODNTR1 ON LIVR1 (CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR1_CODIES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBEF2B04FBD5CC1EDEAD8C2A25002AA21A7E2612</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR1_CODIES1 ON LIVR1 (CODIES1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR1_CODLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEDB840746ACE41B80FAA0BCB36CCB36F840BCED</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR1_CODLIVR ON LIVR1 (CODLIVR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR1_CODNIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03D3ED39F3F52494A3EBF032E03A304B5EA5638E</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR1_CODNIRSER ON LIVR1 (CODNIRSER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR1_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C05814CF446FC24E6F97E98C914173B07E6D95F1</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR1_CODNIRSTOC ON LIVR1 (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DF314A91AE18BC8E94B741D63E46B73DBE1216A</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR1_UMSEC ON LIVR1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVRTOT_CODLIVRTOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B180BDD1A713FBA48B4DB4B25FBD5AA1065EF4F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVRTOT_CODLIVRTOT ON TMP_LIVRTOT (CODLIVRTOT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVRVAL_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BDC97433474FE7F5AA3FB3DA77DBE041AFDB942F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVRVAL_CODIOART ON LIVRVAL (CODIOART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVRVAL_CODLIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4DECDEF2F67889B69BD28B92C73CF4A309C74DB</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVRVAL_CODLIVR1 ON LIVRVAL (CODLIVR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVRVAL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B56B247FB0DB9667B0FD161668B6BACEC82AE91</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVRVAL_CODOBIECT ON LIVRVAL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVRVAL_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D8FFB103741B2C60961F6642200251B9248E4DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVRVAL_GEST ON LIVRVAL (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3363DB7C97B60FCA3496D7A32095059BDECA3408</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR_CODIES ON LIVR (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>017078B0E77A624BEB62FD977759D99D8070D9D3</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR_CODINTR ON LIVR (CODINTR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR_CODTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F8BC9DD3744F4B390E7B4C4EED4BDB68A8C8F2F</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR_CODTRANSF ON LIVR (CODTRANSF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR_DATALIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C1556A5C571B758B804AB4A3210398B35AF6958</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR_DATALIVR ON LIVR (DATALIVR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_LIVR_TIPLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4BFC6A4317436DF2F9418E6F3001A475C70D763</HASHVAL>
  <TEXT>CREATE INDEX IDX_LIVR_TIPLIVR ON LIVR (TIPLIVR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAILURI_CODTIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BC022BAB3492594A28F96FEFA01463F44209038</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAILURI_CODTIPDOC ON MAILURI (CODDOC,TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANCONS_MAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D60857A967A441E1722C6FC0DEE9F6A6691A35A9</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANCONS_MAT ON MANEVRA_CONSUM (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANCONS_PROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A74A552C8CCD3AEADC2ED12C045C720573A7389</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANCONS_PROD ON MANEVRA_CONSUM (PRODUS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANCONS_SEMI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>773BF7638E68110D3BF2C4A8EA5B9480EAE162BA</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANCONS_SEMI ON MANEVRA_CONSUM (NODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANEVRACHAR_VALOARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E83A03AE42CBC33264D63BCF18F9089FEF1E696C</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANEVRACHAR_VALOARE ON TMP_MANEVRACHAR (VALOARE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANEVRA_UNIC_CODUNIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B14E008B0FAE6EA97D9C656E8728747ECE00019B</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANEVRA_UNIC_CODUNIC ON MANEVRA_UNIC (CODUNIC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANEVRA_UNIC_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBCD521532F566794BB72A1E619CC31F98F37A9C</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANEVRA_UNIC_USERID ON MANEVRA_UNIC (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MANPRODLINK_CODCMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>425F1F3E228D42081C82F60E58B76474A9DE3AF3</HASHVAL>
  <TEXT>CREATE INDEX IDX_MANPRODLINK_CODCMDPRODMAN ON MANPRODLINK (CODCMDPRODMAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_CMDPRODMAT_CODCMDPMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>00440F8A1701857F1165FA57EC2417FB174D2F86</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_CMDPRODMAT_CODCMDPMAT ON MAN_CMDPRODMAT (CODCMDPRODMAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_CMDPRODMAT_CODCOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E04D5B0FDA01CD2ED5936FA7E6D17A6334BF73F6</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_CMDPRODMAT_CODCOMANDA1 ON MAN_CMDPRODMAT (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_CMDPRODMAT_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E90FE41927A73A70ACD1C8AE06D6A22756C14749</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_CMDPRODMAT_CODOBIECT ON MAN_CMDPRODMAT (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_CMDPRODMAT_CODPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>14EDB4D1346810F395E9F0E69473DC0AACE0EA98</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_CMDPRODMAT_CODPRODMAT ON MAN_CMDPRODMAT (CODPRODMAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_CMDPRODMAT_TIP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E7CEE6F1D8339C205897B4376A5BEBB538B2ED6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_CMDPRODMAT_TIP ON MAN_CMDPRODMAT (TIP) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_ANLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>328D82E9896F16D2980881E40AEC0D55A10E63D6</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_ANLUNA ON MAN_COMANDA (&quot;AN&quot;*12+&quot;LUNA&quot;) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_ANULAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>44C89BDF719BCEFA57C2A6F793B0E91A07DD2C21</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_ANULAT ON MAN_COMANDA (ANULAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_CODCOMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B0B691E81736018D6329C8B8E62B43CA9D79A8D</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_CODCOMANDA ON MAN_COMANDA (CODCOMANDA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_CODGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>76B1EAF19DF27B1315AE8AE16AA36B8EF25C5640</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_CODGEST ON MAN_COMANDA (CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_CODLOCATIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A2998B441A0978E83F4CB4270221ADC3790CA49F</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_CODLOCATIE ON MAN_COMANDA (CODLOCATIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_DELEGAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AEA887F7415EE7619646927A40A6D1F2932014DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_DELEGAT ON MAN_COMANDA (DELEGAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_INCHISA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BC4B9F5AA5BFF40D0C000530C0F71695598C0C92</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_INCHISA ON MAN_COMANDA (INCHISA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_OPERAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>91999E6A3A97F9320B4CBF000A3162A7C1CF4AB7</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_OPERAT ON MAN_COMANDA (OPERAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_PARTENER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51AF7901D9A74C33DA218F3DFBE45CE1B0D872CC</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_PARTENER ON MAN_COMANDA (PARTENER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_SUBUNITATEA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1AB40A5AED0042E02F218609115FD02557869E91</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_SUBUNITATEA ON MAN_COMANDA (SUBUNITATEA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_COMANDA_TIPDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E798E389DFDC61AF50684F136CF9955B186C27E3</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_COMANDA_TIPDOC ON MAN_COMANDA (TIPDOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_I1_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C336A93F32C13E7FB3DFA0C6D0D0938C032F768</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_I1_CODCMDPRODMAT ON TMP_MANEVRA_INTR1 (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_I1_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59420F0E2D090E39263217B003AF0FC1F518640A</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_I1_CODINTR1 ON TMP_MANEVRA_INTR1 (CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_I1_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>883F542E5224D67BDC259F7F67D1BD248C72F824</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_I1_CODNIRSTOC ON TMP_MANEVRA_INTR1 (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MAN_I1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCC99B5F003BD2AA6B783669E072F3682FBAC529</HASHVAL>
  <TEXT>CREATE INDEX IDX_MAN_I1_CODOBIECT ON TMP_MANEVRA_INTR1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MASCASERART1_CODMASCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4FDCAA4077CA1B599D5C52D2890EB2503F0F8AD</HASHVAL>
  <TEXT>CREATE INDEX IDX_MASCASERART1_CODMASCA ON MASCASERART1 (CODMASCA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MASTERMIFIX_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E2F08C56244C8C8F298575F935DE5A741877748</HASHVAL>
  <TEXT>CREATE INDEX IDX_MASTERMIFIX_CODNIRSTOC ON MASTERMIFIX (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MESE1_CODMASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C4EB4C742D8AB4BF49C0F3955CB645BBEDA9AF8</HASHVAL>
  <TEXT>CREATE INDEX IDX_MESE1_CODMASA ON MESE1 (CODMASA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MESE_CODSALA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC17F08E4AFF57D5826ABAC4CB54202CC05DA9B7</HASHVAL>
  <TEXT>CREATE INDEX IDX_MESE_CODSALA ON MESE (CODSALA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>000A854171F502C074569189684FA196671AE25E</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_ANLUNA ON MIFIX1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_ANSTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49B412DD535AF7CA932DFC717AA3A7368AFF79DB</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_ANSTART ON MIFIX1 (ANSTART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_CODCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D55CA57B52B4705A447A4C63FB7FCB7EBC85E85</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_CODCLASIF ON MIFIX1 (CODCLASIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_CODMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A8AC7FCBEE0C8540C40D604E86CD507C242EB3BF</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_CODMIFIX ON MIFIX1 (CODMIFIX,&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8448BD6B3C1EE363549F875BF459375641D955AD</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_CODNIRSTOC ON MIFIX1 (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F544F0C389223A2EEEA0CBD66E030A60DD8DD0B4</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_CODPERS ON MIFIX1 (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MIFIX1_LUNASTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>617088996054BA9D837E5B7CE3A54A4079701385</HASHVAL>
  <TEXT>CREATE INDEX IDX_MIFIX1_LUNASTART ON MIFIX1 (LUNASTART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODIFICARI_TCD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A8675E593BCCFEF676E38B9A483D0A59F877C09C</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODIFICARI_TCD ON MODIFICARI (TABLENAME,CODMASTER,DATAMODIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODI_STATE_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A05D840DF01E3310BE06EFC6F96BDD777B4A38A</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODI_STATE_DOC ON MODI_STATE (TABLENAME,CODMASTER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODI_STATE_MODIDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99B16CAB1A0A209847C2669F1B5D515E1C7D4C01</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODI_STATE_MODIDATE ON MODI_STATE (MODIDATE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODI_STATE_TABLENAME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FD88886636763208E266543A238634B716AD8C2</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODI_STATE_TABLENAME ON MODI_STATE (TABLENAME,MODIDATE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODPLATA2_CODCARD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BE305329F85F01E705E236CC2AD4E558B584FC3</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODPLATA2_CODCARD ON MODPLATA2 (CODCARD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODPLATA2_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BE09091F259313E84AA5A3C1DB0FF57524E0D02</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODPLATA2_CODIES ON MODPLATA2 (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_MODURIPLATI_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC385CAF29AB39FA8489DFA910E14BACE1778D6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_MODURIPLATI_CODIES ON MODURIPLATI (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENDA1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDE7393C09EF78BC32B5E5628FE167B67544BBDF</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENDA1_AL ON NAGENDA1 (CODAGENDA,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENDA_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEC167E0FD88425EF2D7B6ADD3AA7DB49D669420</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENDA_CODGEST ON NAGENDA (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENDA_CODLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>411604E36E523E0A5D8BFCD5BD959F0626AA8BE1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENDA_CODLOCALIT ON NAGENDA (CODLOCALIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENDA_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEB9EBB7AC7B2609E5F6BD73457D9BFA4EBE86EE</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENDA_CODPART ON NAGENDA (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTI1_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4FBFC23ECBD0BD42560CB26695770B34B096A16</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTI1_CODPERS ON NAGENTI1 (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_CODAGENT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63CCB5F5AEFA1D271F9D2F2F8C99B767437D3144</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_CODAGENT1 ON NAGENTIPROC (CODAGENT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4515641362B4A78A71FBB940A1965FBAF4B2909</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_CODOBIECT ON NAGENTIPROC (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25AB57F5C1279C0A4A6D9FFC51E8B0410CB3D224</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_CODPART ON NAGENTIPROC (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C2F3858BE82A752A4CC3462CCE5300CAECA9782</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_CODPERS ON NAGENTIPROC (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_PECLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B24232A3A710588480CC9E4342EBB5FD99BB0A3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_PECLASEA ON NAGENTIPROC (PECLASEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIPROC_PECLASEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B76BECE98A49C6C0A22EEC4DE4E544EBE5C1DFA7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIPROC_PECLASEP ON NAGENTIPROC (PECLASEP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIVAL_CODAGENT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA27F669F48254F1C9A3E7569314D6A5E6A50A2D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIVAL_CODAGENT1 ON NAGENTIVAL (CODAGENT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIVAL_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D245A6DF99E6307B1B4A4F1FC7899C50FF6D6904</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIVAL_CODMONEDA ON NAGENTIVAL (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NAGENTIVAL_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1143005B78138BFF1ED718C58583A3E6C0358D4D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NAGENTIVAL_CODPERS ON NAGENTIVAL (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83BACE43697EEA5FCC287F5DD837517E0B5B50BC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_AL ON NART1 (CODARTICOL,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>842D117C8366163428EAD678CA7E81831A76F84D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_ANLUNA ON NART1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODACCIZE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4DDE0942CAE0420C849F9E375A5AFC776F7FE53</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODACCIZE ON NART1 (CODACCIZE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODACCIZEDVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48564B926E19A0F9041CF6F1EDD987F0CA50CE1A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODACCIZEDVI ON NART1 (CODACCIZEDVI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70EA19B31AAFE577E1413DD8334DF208DDCB162C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODARTICOL ON NART1 (CODARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODTAXA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C36C7CCC9EE1B9ADD828E941105D03A2E9253499</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODTAXA1 ON NART1 (CODTAXA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODTAXA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82C1446CFED8E39B0753F7FA9DBD22EE3910B9D7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODTAXA2 ON NART1 (CODTAXA2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART1_CODTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9967498BAA770B008DF0D58C3832BD609B18F7C9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART1_CODTVA ON NART1 (CODTVA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTAMB_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D70199F19AC5BEFA01ACD8F69DF96303AC00EBB1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTAMB_CODOBIECT ON NARTAMB (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTATR_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10AF885BD6ECE71AEEAEF169A7792CBFF91F2E68</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTATR_CODARTICOL ON NARTATR (CODARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTATR_CODATRIBUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC0C1D6455BFF77188B0E2F6BEA24513BEFE8DCD</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTATR_CODATRIBUT ON NARTATR (CODATRIBUT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTATR_CODVALPREDEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AB259B2C82A34882BDEADC0DAA417EE64808988</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTATR_CODVALPREDEF ON NARTATR (CODVALPREDEF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTCLI_CODEXTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2136F17DC8C3AACCDEE53808A285B838D59E423</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTCLI_CODEXTERN ON NARTCLI (CODEXTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTCLI_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96EC304E6B0A13E0A59C6B664040BEE140778D91</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTCLI_CODOBIECT ON NARTCLI (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTCLI_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A96D297F1E22326E3AABC5CBBF7EAA01FB6903A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTCLI_CODPART ON NARTCLI (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTCLI_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>188E0C218C23DA64EE1794CD31D78D82FB68FB51</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTCLI_UMSEC ON NARTCLI (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTDIM_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71923CE0BDF82E86C8BBDD9FB201436861C001B4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTDIM_CODARTICOL ON NARTDIM (CODARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTIMPLICITE_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E53E5FB8D6504906DBEBA6F61296994DC28CB1FA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTIMPLICITE_CODARTICOL ON NARTIMPLICITE (CODARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTIMPLICITE_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76512A673AD6D4FBE29F79BBC30C9A181EB2A876</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTIMPLICITE_CODSUBUNIT ON NARTIMPLICITE (CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTIMPLICITE_CONTIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D2B6494C570FF00AA8BE4E3F9CE8B0DDD51457D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTIMPLICITE_CONTIMPL ON NARTIMPLICITE (CONTIMPLICIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTIMPLICITE_GESTIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD30FC4553B89D976E0B19B6E751BECB5DE0AE99</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTIMPLICITE_GESTIMPL ON NARTIMPLICITE (GESTIMPLICITA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTIMPLICITE_LOCATIEIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F7875D111B70672A5F7B09C0F7666A0724E7398</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTIMPLICITE_LOCATIEIMPL ON NARTIMPLICITE (LOCATIEIMPLICITA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A946D47EADFEAE7CB0FAC0C87644FF297AC4BECC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ1_AL ON NARTOBJ1 (CODOBIECT,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47C84ABAC71680AA8C1642135C9B9B21566A05C2</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ1_ANLUNA ON NARTOBJ1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E124871A092E690A6CFF01D45878EED5DDF1B64C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ1_CODOBIECT ON NARTOBJ1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJGEST_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B3739E5D75A506985D337ACA333B45F65D93CB8</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJGEST_CODGEST ON NARTOBJGEST (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJGEST_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FDB867311F3E1157B576075A3B8CD5F50EB47E3D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJGEST_CODOBIECT ON NARTOBJGEST (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJIMP_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>214D705CA329177724C95D6560818BE8ABFD9E30</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJIMP_CODSUBUNIT ON NARTOBJIMP (CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAA08621C17E78AEBE84D0286368A9ED4A023D91</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJSUBUNIT ON NARTOBJSUBUNIT (CODOBIECT,SUBUNITATE,CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJTRAD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E83377F025465B13B0B815DABFE2E5D79A7FBB1B</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJTRAD_CODOBIECT ON NARTOBJTRAD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32248DC55059160A50149037C252D3E0D7EC012A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ_CODARTICOL ON NARTOBJ (CODARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ_CODEXTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F628E1D08C72AB37CB13EFB2EE84D9F25D0F3787</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ_CODEXTERN ON NARTOBJ (CODEXTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ_CODINTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BE80F223F72569E79713F7794F3D57B374F5703</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ_CODINTERN ON NARTOBJ (CODINTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOBJ_CODPRODUCATOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2B1A5E1B257EE177DE21711DFD080B562435AC5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOBJ_CODPRODUCATOR ON NARTOBJ (CODPRODUCATOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NARTOPT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4DE3C9F39803A990CAF634D896DEA5C0DDF8CE4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NARTOPT_CODOBIECT ON NARTOPT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_CASADEMARCAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D41FDAAB397C03A3AF37B3E1185C1E876F0F5FB0</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_CASADEMARCAT ON NART (CASADEMARCAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_CLASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03DE7ED35F02AEFB33E1DE0635E2F09848442F1D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_CLASA ON NART (CLASA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_CONTSERVICIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E52EA5AA0229D2347FAE9AB61EC78044006002F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_CONTSERVICIU ON NART (CONTSERVICIU) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_GESTIMPLICITA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A367A7F9211D43461B57EF10E1400481068C6C9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_GESTIMPLICITA ON NART (GESTIMPLICITA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_TIPARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC7BEFEF29EC423BAAC9A8E8ACFFD8A04E6E6119</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_TIPARTICOL ON NART (TIPARTICOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_UM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DB3210FE140B99D59EDF5ED5C4F46CBE2A91DC2</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_UM ON NART (UM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_UM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AAC1C5378B8316E788720B8B6E94BFD6163852D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_UM1 ON NART (UM1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NART_UM2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF6803FD4D8A82A6B1F0BB84CD0AE2975573EE26</HASHVAL>
  <TEXT>CREATE INDEX IDX_NART_UM2 ON NART (UM2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NATRIB1_CODATRIBUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3BB77888F6FC4D6A3A631CD032AEBA478D72A69</HASHVAL>
  <TEXT>CREATE INDEX IDX_NATRIB1_CODATRIBUT ON NATRIB1 (CODATRIBUT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NATROBJ_CODARTATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9381806BE06F4553F935E6EFCB03EB2F54A2951</HASHVAL>
  <TEXT>CREATE INDEX IDX_NATROBJ_CODARTATR ON NATROBJ (CODARTATR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NATROBJ_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84EEF273BA0080A691959C563D76A63739CB6B28</HASHVAL>
  <TEXT>CREATE INDEX IDX_NATROBJ_CODOBIECT ON NATROBJ (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKCONT1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC37C6431B474ABE44A6ACD46997D6F03B5DBFBC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKCONT1_AL ON NBANKCONT1 (CODBANKCONT,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKCONT1_CODBANKCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0ED0889B278EB51E34AB5C4E3F2FBB25B1629C05</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKCONT1_CODBANKCONT ON NBANKCONT1 (CODBANKCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKCONT1_CODIOBANCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B125792F081EC7F02EFBEE45809A05FB157AECEE</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKCONT1_CODIOBANCA ON NBANKCONT1 (CODIOBANCA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKCONT_CODLOCALITATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14C22A0488A43196E02DCB1C74A86FFDE28F585E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKCONT_CODLOCALITATE ON NBANKCONT (CODLOCALITATE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKCONT_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16492E7EE20BDC869FC099B7069142C49CE8BA7D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKCONT_CODMONEDA ON NBANKCONT (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NBANKSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4D21833464DEA2A2F29ACA3427A8B7FD80A28E9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NBANKSOLDLUNA ON NBANKSOLDLUNA (AN,LUNA,CODBANKCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81216FBB4F3FF9E05E6D9575538A2995CCF33DAE</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC1_CODGEST ON NC1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC1_CODNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A70167B7A97B1D99F5CF96BE61100F002F970548</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC1_CODNC ON NC1 (CODNC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC1_CONTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC2CFBD55A51C7436C406184C1F1BE4E9DB95736</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC1_CONTC ON NC1 (CONTC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC1_CONTD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D24FF6BAB640E3435288B985500A84148A053FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC1_CONTD ON NC1 (CONTD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEAS_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>429D18E123DD3C94769B74FDF5E54D2CB9A270FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEAS_CODPARINTE ON NCLASEAS (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEA_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D188EA76D3F6C9FB1162421FEBC7B94F6475C85D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEA_CODPARINTE ON NCLASEA (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEG_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>504A43C2C4B0AB824F97597216A0DDC08185BB97</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEG_CODPARINTE ON NCLASEG (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEINT_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6248F09D95428B9ACF1E112554182A8283E87CED</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEINT_CODPARINTE ON NCLASEINT (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEMF_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3A348C12AD8EB65EA53834EF0AA02F94F19B403</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEMF_CODPARINTE ON NCLASEMF (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEPROD_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>586D66A48ABF6434190B5C213ACB42AAFB9DA523</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEPROD_CODPARINTE ON NCLASEPROD (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCLASEP_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>557563FB42F267F8364509C66EF7AFFA3329B03F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCLASEP_CODPARINTE ON NCLASEP (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCODFISCRETAIL_CODFISCAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC3EA8C28BCBC98BD9175D74B31602EFA7B257F6</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCODFISCRETAIL_CODFISCAL ON NCODFISCRETAIL (COD_CODFISCAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38BD379234D3E6DF773D1661607888763B87591E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_AL ON NCONT1 (CODCONT,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CDC2159423279F5D9ECECE08F668C9B916A56A3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_CODCONT ON NCONT1 (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_CONTINKIDSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B2095A4D072951A447F8D4971EA169F26F6FE2E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_CONTINKIDSOLD ON NCONT1 (CONTINKIDSOLD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_CONTTRANSFC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3AB9D99FFA91B0045632D7C675FE3DE527C6E50</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_CONTTRANSFC ON NCONT1 (CONTTRANSFC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_CONTTRANSFD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F5D2D0AA643F74E514C4D57A9B2E36187F8EEEC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_CONTTRANSFD ON NCONT1 (CONTTRANSFD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT1_SINCRONIZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64E347507C5CE1E4999ED8F13758703E00E2D379</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT1_SINCRONIZARE ON NCONT1 (SINCRONIZARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTECHIVSUB_CODCONTECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F1D1F3D6B62B261E30002C81D2B2FB9E1787935</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTECHIVSUB_CODCONTECHIV ON NCONTECHIVSUB (CODCONTECHIV) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTECHIVSUB_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>308F8DA17CD3522A0AB7D1D209C00A1B687567B5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTECHIVSUB_CODSUBUNIT ON NCONTECHIVSUB (CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTECHIV_CONTNOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0688A576E5736592FCC21FC16702A04CF373AE0F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTECHIV_CONTNOU ON NCONTECHIV (CONTNOU) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTECHIV_CONTVECHI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FD1A0572653DBE57B738D9B6D1AA4B07D314846</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTECHIV_CONTVECHI ON NCONTECHIV (CONTVECHI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTREPRUL_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FBA413693518852565E871C9510481A49A911F6</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTREPRUL_CODCONT ON NCONTREPRUL (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTREPSOLD_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32A2ABCD0DCCA33E50F93BE12D28AFEE414D855A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTREPSOLD_CODCONT ON NCONTREPSOLD (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTREP_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEE9321E56ABA22949E13658BA3903C364657CF2</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTREP_CODCONT ON NCONTREP (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRULSUB_CODCONTRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BB33A589E201BD7767272018B9B2218281C0C5D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRULSUB_CODCONTRUL ON NCONTRULSUB (CODCONTRUL,SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRULSUB_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1ADC65FACD7980EC2654D7810650B0D5AA72EB39</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRULSUB_SUBUNITATEA ON NCONTRULSUB (SUBUNITATEA,CODCONTRUL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRULS_CODCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87D1B03275098C87D1F5CE0272B1DCC5EE9FCA33</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRULS_CODCONTS ON NCONTRULS (CODCONTS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRULT_CODCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D4851297E140C8141CA825306FD97B8C563F54C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRULT_CODCONTT ON NCONTRULT (CODCONTT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRUL_ALC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>65A5FBFE16463BD879407C4CC4FA6A003CAA5591</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRUL_ALC ON NCONTRUL (AN,LUNA,CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTRUL_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF0BB8DDCC667DFA7F4CE73034FB5F673357E720</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTRUL_CODCONT ON NCONTRUL (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTS1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FACFF1BDD7EB8FDAE3328B8064A39D295A4CB57</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTS1_AL ON NCONTS1 (CODCONTS,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTS1_CODCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71D2F5FE0A377744B82D53C00A8F5DC77F61A07A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTS1_CODCONTS ON NCONTS1 (CODCONTS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTSOLDSUB_CODCONTSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C8869DABB5E6C74EDC905B4AC87A863B9149CF1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTSOLDSUB_CODCONTSOLD ON NCONTSOLDSUB (CODCONTSOLD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTSOLDSUB_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1CD144E7D8ECE269DAA1AAE69F069BF7C242AE8</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTSOLDSUB_SUBUNITATEA ON NCONTSOLDSUB (SUBUNITATEA,CODCONTSOLD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTSOLDS_CODCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3082939B7FEECFDE1DCEA288CAA0ADC7D374F6FD</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTSOLDS_CODCONTS ON NCONTSOLDS (CODCONTS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTSOLDT_CODCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E5A573DFB7556C985CAA07ACA836D43B31E584A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTSOLDT_CODCONTT ON NCONTSOLDT (CODCONTT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTSOLD_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>119A249988CDACE731511375EB189EE4ED33AA0D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTSOLD_CODCONT ON NCONTSOLD (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTS_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88730FBB7D51F35659A2E9DEA8629E34D512F9E8</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTS_CODPARINTE ON NCONTS (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTT1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6778D15478330F8F2BD9784BF13C2DE12345B34D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTT1_AL ON NCONTT1 (CODCONTT,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTT1_CODCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCD6F5A88CE7625AB775D293CADF5820EC9550A9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTT1_CODCONTT ON NCONTT1 (CODCONTT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONTT_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39271C045163C5C24ED65FC4C4B3E2FF08805593</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONTT_CODPARINTE ON NCONTT (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NCONT_CODPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E16B3ADB0FB677E835F56CA69799D00BE6F3BDFA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NCONT_CODPARINTE ON NCONT (CODPARINTE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC_MONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>862E12C97410898D8EEB194CAFA4CC4490F8F453</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC_MONEDA ON NC (MONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC_PART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A86AC32537565AFA64046200E2F691DAE64B497</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC_PART ON NC (PART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NC_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26B94ECA76ED8FDA845AB649978D5FEE9AD3F2EC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NC_SUBUNITATEA ON NC (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NDELEGATRETAIL_CODPARTTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CB79844A1DEBF897425C272A20D881DACAB0646</HASHVAL>
  <TEXT>CREATE INDEX IDX_NDELEGATRETAIL_CODPARTTR ON NDELEGATRETAIL (CODPARTTR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NEC5_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04E7E681A0BC6FB2D1275F384928F0A027E3C520</HASHVAL>
  <TEXT>CREATE INDEX IDX_NEC5_CODOBIECT ON NECESAR5 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NEC5_NRINDICATOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0434429CF74ACD0FC7694C25524F2DC68D853345</HASHVAL>
  <TEXT>CREATE INDEX IDX_NEC5_NRINDICATOR ON NECESAR5 (NRINDICATOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NEC5_ORDINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B5E7FC03F85153FD3E5EF8C2EA8177DF0097D02</HASHVAL>
  <TEXT>CREATE INDEX IDX_NEC5_ORDINE ON NECESAR5 (ORDINE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NEC5_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B368C1D40A3948E4F2B19D04F6B9A498CACB2781</HASHVAL>
  <TEXT>CREATE INDEX IDX_NEC5_USERID ON NECESAR5 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESARCMD_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>370E11E191F83060980962D4CEB89162D69B9BCB</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESARCMD_CODCOMANDA1 ON NECESARCMD (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESARCMD_CODNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3F7A3A7149E796C4190D9F095F797C7B35D174D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESARCMD_CODNECESAR ON NECESARCMD (CODNECESAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESARDOC_CODNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C665844834A2E7006CE4B121A0C9E149DF291C1C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESARDOC_CODNECESAR ON NECESARDOC (CODNECESAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESARDOC_CODPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB0AA0436848B51C5C241D561E9FE64FA2F5737D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESARDOC_CODPLANIFPROD ON NECESARDOC (CODPLANIFPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESAROBJ_CODNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E987AD6400964CEFBC51C2A04B54832C99A598E3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESAROBJ_CODNECESAR ON NECESAROBJ (CODNECESAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECESAROBJ_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5DA4CDE13281E82FB65EC257B195F3A7FD8BB2B</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECESAROBJ_CODOBIECT ON NECESAROBJ (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NECHIV_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3ED470248E5BC9AE432D8CD229E922D73B86DD2</HASHVAL>
  <TEXT>CREATE INDEX IDX_NECHIV_CODOBIECT ON NECHIV (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FC5BCA065E187E6BB6D5B6DD626E9C27339ECCB</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST1_AL ON NGEST1 (CODGEST,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST1_CHELTUIELI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>058FE6917125951582BB9613D9C40DF4C81E376A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST1_CHELTUIELI ON NGEST1 (CHELTUIELI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96385DEE04C3DCDF02046D6FF307FCF3981B7846</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST1_CODGEST ON NGEST1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST1_VENITURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B279CA81894931E39FA08E1B36442A21CA67C337</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST1_VENITURI ON NGEST1 (VENITURI) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST_CODACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E62DD7D17D5FF8444096152BA34E6DAEF68E944F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST_CODACTIVIT ON NGEST (CODACTIVIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST_CODCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D864ACFD8A05A8A08856F4C61F77DC9FBBACE21A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST_CODCATPRET ON NGEST (CODCATPRET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST_CODCLASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61B366D2A9CF8DBA67A858F5FEBA85DA83047F9D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST_CODCLASA ON NGEST (CODCLASA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NGEST_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9C38A5D0D67A6CC32CA8FB6514162FAF62832DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_NGEST_TIP ON NGEST (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C2038103448FC3EC4B7E9EC3D8569CC0CDA4000</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRLUNA ON NIRLUNA (AN,LUNA,CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRLUNA_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A94D34816BF15823BFB7E1D1F05D5D96C60F6F33</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRLUNA_CODNIRSTOC ON NIRLUNA (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSERLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>217DE4F91401D1CDC10EC71DD2881C8FF87223AF</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSERLUNA ON NIRSERLUNA (AN,LUNA,CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSERLUNA_CODNIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D438FCC490C7CA631D8FD96F2489301B34E514C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSERLUNA_CODNIRSER ON NIRSERLUNA (CODNIRSER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSERLUNA_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>631A41D56BBEEB25827E5C274FE4A194C113DBB8</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSERLUNA_CODNIRSTOC ON NIRSERLUNA (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSER_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>164D669791D9431B8E4049A196B50018F901965C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSER_CODNIRSTOC ON NIRSER (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSER_CODSERIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D82DDCEE1FA20B7ED3A02A689148782ECC713DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSER_CODSERIE ON NIRSER (CODSERIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODDVI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A537756B685373E773B0B276E1A8EB007EFC2EAB</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODDVI1 ON NIRSTOC (CODDVI1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C85232AB2999C6C981BD64265DE9F693516D66C1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODINTR1 ON NIRSTOC (CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODLIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C13210768CCF0981C2CF2A796754EE6217382F0</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODLIVR1 ON NIRSTOC (CODLIVR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20E0D019C7B5931C0F472A41AF5B44A609DB44CF</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODLOCATIE ON NIRSTOC (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90534A6B194E0780BE0D6F5C060BF24474CCE72E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODNIR ON NIRSTOC (CODNIR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODNIRSTOCPARINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35DDA3329FC224531A4E04875EAC4C3E30A1455C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODNIRSTOCPARINTE ON NIRSTOC (COALESCE(&quot;CODNIRSTOCPARINTE&quot;,0)) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>679BA0D07819A19496534FD4638D85E714E79410</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODOBIECT ON NIRSTOC (CODOBIECT,REST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F60B3128AC9ED79204874C620AC84E9232B8146</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODSUBUNIT ON NIRSTOC (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_CODTRANSF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6FC26D18A71FE56891AB522A42FB8BB270D4EE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_CODTRANSF1 ON NIRSTOC (CODTRANSF1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_PRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEE0A416FFFB739E0998DF68F46C8743D5E13036</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_PRET ON NIRSTOC (PRET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIRSTOC_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F82720EE2CAA5370E687C60B46450506C03F679E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIRSTOC_UMSEC ON NIRSTOC (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7862A29C2B33B5ED8D24B6F6A387C9405CA57A4B</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_CODIES ON NIR (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF551F014B23F7C11A7439F5C05DE1D9BD876F73</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_CODINTR ON NIR (CODINTR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_CODTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01D05224000FEA40D011E7A3F53CE869191D59D3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_CODTRANSF ON NIR (CODTRANSF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_DATANIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD871CDA86ED1CE7E86EC2A9BF74D8F48FE94F6C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_DATANIR ON NIR (DATANIR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>847FE4CE6B02D7EE43D71D57062C76F20AC2AA0A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_GEST ON NIR (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NIR_TIPNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>135C648551DEFE0EE63C8D177654A32D16315921</HASHVAL>
  <TEXT>CREATE INDEX IDX_NIR_TIPNIR ON NIR (TIPNIR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NJUDET_CODTARA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAB1CF1645983E4878686E224C35F7E11000CD8A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NJUDET_CODTARA ON NJUDET (CODTARA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NLIMCREDIT1_CODLIMCREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E98F951201B11E57F4CBC586D5131865D9E071F2</HASHVAL>
  <TEXT>CREATE INDEX IDX_NLIMCREDIT1_CODLIMCREDIT ON NLIMCREDIT1 (CODLIMCREDIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NLOCALIT_CODJUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99EEC94ED61BDD20BF60472D425FB051F00B5226</HASHVAL>
  <TEXT>CREATE INDEX IDX_NLOCALIT_CODJUDET ON NLOCALIT (CODJUDET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NLOCALIT_CODTARA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15ED23B30FE5DD695DBDB84FA3C74A21AEDAAE74</HASHVAL>
  <TEXT>CREATE INDEX IDX_NLOCALIT_CODTARA ON NLOCALIT (CODTARA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NLOCALIT_CODZONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75729D9D7457D5156B15EAB981F941B4E2102143</HASHVAL>
  <TEXT>CREATE INDEX IDX_NLOCALIT_CODZONA ON NLOCALIT (CODZONA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NLOCATII_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47C990BC6BA973B0D9B383715804270BB2F9D3A1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NLOCATII_CODGEST ON NLOCATII (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NMONEDE1_CODBANCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F654C2E75B7C823982027F977B8BAEB37C2A4AE4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NMONEDE1_CODBANCA ON NMONEDE1 (CODBANCA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NMONEDE1_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>376819635BC9DBCC4DA2921D9B9E30995DE5DC6B</HASHVAL>
  <TEXT>CREATE INDEX IDX_NMONEDE1_CODMONEDA ON NMONEDE1 (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NODECHIV_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>485D92AB11B4A8E669223BB4B2D74002148744AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_NODECHIV_CODCOMANDA1 ON NODECHIV (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NODECHIV_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8FFA3443EE7C8615435EEFFF9C5134B2D2123C7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NODECHIV_CODOBIECT ON NODECHIV (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NODECHIV_CODPROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF515C61EA6EBEA7E5CDC8BB2622B93B0E0DA095</HASHVAL>
  <TEXT>CREATE INDEX IDX_NODECHIV_CODPROIECTNOD ON NODECHIV (CODPROIECTNOD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NODECHIV_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AF1E5FA4B1D4C82E1C514A2D682F52B99842F58</HASHVAL>
  <TEXT>CREATE INDEX IDX_NODECHIV_TIP ON NODECHIV (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NORMEMAT_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2E318A5B1713BA846F601326A7ACE50245953C3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NORMEMAT_CODNORMA ON NORMEMAT (CODNORMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NORMEMAT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52CEC848FAA3A8D8637AC8789D36733215FC366D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NORMEMAT_CODOBIECT ON NORMEMAT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NORMEMAT_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C1E595F4BEFD07CF72C577E3F03300818058788</HASHVAL>
  <TEXT>CREATE INDEX IDX_NORMEMAT_CODPRODCOMP ON NORMEMAT (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTACREDIT1_CODNC1ORIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C45C74392F0EA7D25B94475A15B7AAE74D75A86F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTACREDIT1_CODNC1ORIG ON NOTECREDIT1 (CODNCREDIT1ORIG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT1_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7ED559EE99E06B2CE901F9E629BB275C9A5A5589</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT1_CODDOC ON NOTECREDIT1 (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT1_CODNCREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>901B1816BCC67AEF0783E748FEA221E9A7D07394</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT1_CODNCREDIT ON NOTECREDIT1 (CODNCREDIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT1_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24DD6C2AAD118856760847239B545B3CFB6566F3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT1_TIP ON NOTECREDIT1 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT1_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7824753E60D91D751A82B59B7F303C0A37A8AC11</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT1_TIPDOC ON NOTECREDIT1 (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AFE85ADE51A3415DCF838BF72A0BE56C1E51823</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_ANLUNA ON NOTECREDIT (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5291FE4768673C93A89A3051B0669F4DA362EF5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_CODCONTRACT ON NOTECREDIT (CODCONTRACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D284BE26286480A41A429EC1EF2861A27716A2F4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_CODMONEDA ON NOTECREDIT (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF7069FEA3D660019D10E985001F5D70B125741C</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_CODPART ON NOTECREDIT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_CORECTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A82570E5CE30F31610CDB335A2A4FC9591E2A002</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_CORECTIE ON NOTECREDIT (CORECTIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>741ABAA093BBF5EB22F6891ECADEB0E02DE0F6F7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_SUBUNITATEA ON NOTECREDIT (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NOTECREDIT_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17E78BB358241C9A39302A7322E5DD592B75D7F5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NOTECREDIT_TIPDOC ON NOTECREDIT (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARCCOM_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C33DA81E2BF1E4473452842E6159702776067D7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARCCOM_CODCOMANDA ON NPARCCOM (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARCCOM_CODNPARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2140EA282F7CFC0590D68580A873B86F3E6B533A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARCCOM_CODNPARCAUT ON NPARCCOM (CODNPARCAUT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARCG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8729FFA42A06F8C11054A5C2B87AB2AFF8171B15</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARCG ON NPARCG (CODNPARCAUT,DATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART1CRM_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46BD96F5992020B3B5F9795AF4342E073217F029</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART1CRM_AL ON NPART1CRM (CODPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART1CRM_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A25C2E5A0E69694C63108AC06FCD2A62C1123CA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART1CRM_CODPART ON NPART1CRM (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART1X_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>268067D1D9137B522A6BAFF6D0C11C73D0A259E5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART1X_AL ON NPART1X (CODPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E12F44E25A2DFA6AC712102FE33B8581C518DC3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART1_AL ON NPART1 (CODPART,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART1_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66E1A51815755283EB94C8E7CEB274C421C08D8D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART1_CODPART ON NPART1 (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTACTIVIT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12CE52CC5CC513F7D259D7EB023E6A17684099C7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTACTIVIT_CODPART ON NPARTACTIVIT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTB_CODLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A00B7A6C3D295D28A00F2E9AA9C8F5DAC6FB26E</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTB_CODLOCALIT ON NPARTB (CODLOCALIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTB_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6925A9341A42AB8D18F4CA7CBAD073A1CD4DC16F</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTB_CODPART ON NPARTB (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTCODFISC_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D068932681FC148117B6A26A9544CE297FD9CB4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTCODFISC_CODPART ON NPARTCODFISC (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTDISC_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E811618A47ECF5B3AA47F72E71067FC42406F7DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTDISC_CODPART ON NPARTDISC (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTDOMACT_CODDOMENIUACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55379FE76CBC1A5BB5E514AA1A91AF2F298954A8</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTDOMACT_CODDOMENIUACT ON NPARTDOMACT (CODDOMENIUACT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTDOMACT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>143D7E6370141CA4174BAC96284BD1178BDC74BC</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTDOMACT_CODPART ON NPARTDOMACT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTLSTCLASE_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC0B3C04591C96036E79836C9BDBF7DB12121421</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTLSTCLASE_CODPART ON NPARTLSTCLASE (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTRETAIL_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>536C6C93F9C6FA3A608A74F62D652F6072CFBBC7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTRETAIL_CODPART ON NPARTRETAIL (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B779BD388AF978B9EF30B098D6BF7B4AC28F903D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTSOLDLUNA ON NPARTSOLDLUNA (AN,LUNA,CODPART,ICONT,CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTSOLDLUNASUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D39F26C4D319BCC4FDE1144862DAC25F53F34058</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTSOLDLUNASUB ON NPARTSOLDLUNASUB (AN,LUNA,CODPART,ICONT,CODMONEDA,SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTSUBUNIT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2530A472622107A8E3B564C1133C1375AFDDD5D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTSUBUNIT_CODPART ON NPARTSUBUNIT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTSUBUNIT_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A51A3E3F8B96B8E2DAFD7F9AA1CD8353942FFB1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTSUBUNIT_SUBUNITATEA ON NPARTSUBUNIT (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTTRLNK_CODPARTTRLNK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16775AC1D60C862A312BAD1269FD24E5A272BEFA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTTRLNK_CODPARTTRLNK ON NPARTTR_LNK (CODPARTTRLNK) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPARTTR_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72FAD7807BC45D762AD1286A1383CB48F9936CE6</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPARTTR_CODPART ON NPARTTR (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART_CODEXTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB6176B10F3E2750E23D3DC9073359923A174948</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART_CODEXTERN ON NPART (CODEXTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPART_CODINTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>045221D51BB5A376B56294409DF1C874D086A4F4</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPART_CODINTERN ON NPART (CODINTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERS1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCF0D62C695D1C4FA2CD3456B0595E4BC76B3224</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERS1_AL ON NPERS1 (CODPERS,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERS1_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>495D9BD277BC5D13D49DDD46A39EB53A8953EA9D</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERS1_CODPERS ON NPERS1 (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSCONTACT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C901540A440A4F65CE84EA85C8A4B2AA3A3F785</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSCONTACT_CODPART ON NPERSCONTACT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DAC7C9D2D672CF240B02CA6868D8712E578F43D9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSSOLDLUNA ON NPERSSOLDLUNA (AN,LUNA,CODPERS,CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSSOLDLUNASUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4773BF209D5AAB49457A9033DC665482C8B8E9A7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSSOLDLUNASUB ON NPERSSOLDLUNASUB (AN,LUNA,CODPERS,CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSSOLDLUNA_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4E3E0D446ECA67EF624389656459ABD5E15B350</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSSOLDLUNA_CODMONEDA ON NPERSSOLDLUNA (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSSOLDLUNA_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C99CCEC7FAE704870411DA294EE53D51662F468</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSSOLDLUNA_CODPERS ON NPERSSOLDLUNA (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPERSSOLDLUNA_ICONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4712E16DFB5241D984AC137B619667EAC15C1AD7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPERSSOLDLUNA_ICONT ON NPERSSOLDLUNA (ICONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPLINK_CODLIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F17BB5F4FE42EB62BA658FC8CC9189F2A8B3A0CA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPLINK_CODLIVR1 ON NPLINK (CODLIVR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NPLINK_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05444904196944ECD8696011EF04A2F7D10C5F2A</HASHVAL>
  <TEXT>CREATE INDEX IDX_NPLINK_CODNIRSTOC ON NPLINK (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NSCADENTARTL1_CODSCADTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C37CD2E1F94B77532DDD1DABCCBE92EC13AE7D3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NSCADENTARTL1_CODSCADTL ON NSCADTL1 (CODSCADTL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NSEDIIPARTRETAIL_CODAGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>378CFDF58E085F6DD9BB457757B8B7B7D74D4EA9</HASHVAL>
  <TEXT>CREATE INDEX IDX_NSEDIIPARTRETAIL_CODAGENDA ON NSEDIIPARTRETAIL (CODAGENDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NSERII_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0858ED3E3D7D91C6AFADD20C7EA19B4340E4DBF5</HASHVAL>
  <TEXT>CREATE INDEX IDX_NSERII_CODOBIECT ON NSERII (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NSUBUNIT1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DD72ABC95BC16FD9FB3918CEAD80E502CD45B23</HASHVAL>
  <TEXT>CREATE INDEX IDX_NSUBUNIT1_AL ON NSUBUNIT1 (CODSUBUNIT,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTAXE1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>272F1FF8B4AACCE2F7DB5B66380901A9CFE95DBA</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTAXE1_AL ON NTAXE1 (CODTAXA,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTAXE1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67BC885AE85BD82F519120FB239787D856693C30</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTAXE1_ANLUNA ON NTAXE1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTAXE1_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFF653E594625385E60D526C57D5837502EB6EE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTAXE1_CODCONT ON NTAXE1 (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTAXE1_CODCONTCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4672A72967CCFE6616C9E0694A2FFF0422DBDCD1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTAXE1_CODCONTCHELT ON NTAXE1 (CODCONTCHELT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2173039A38FBBCB223EFD5FAF39C786BF9578E7</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_AL ON NTVA1 (CODTVA,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A50BD98B55E6365C2DA22C42A57E094FC5711EEE</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_ANLUNA ON NTVA1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_CODCONTCOLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07A5BC36E2CA73B22E967A55C952B321DC8A7EBF</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_CODCONTCOLE ON NTVA1 (CODCONTCOLE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_CODCONTDED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53A8BF62652494BF41E71192C8989F6A43B35A20</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_CODCONTDED ON NTVA1 (CODCONTDED) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_CODCONTNEEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E02875AB53219B7BFC96F3F32C2D4F4CD6E1DFE1</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_CODCONTNEEX ON NTVA1 (CODCONTNEEX) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NTVA1_CODTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>446E24BEB359E5A1553E03D305C65A7666313E98</HASHVAL>
  <TEXT>CREATE INDEX IDX_NTVA1_CODTVA ON NTVA1 (CODTVA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_NUM1_CODUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8008119E24F1954AEF47EB8EFDD25B642F483A33</HASHVAL>
  <TEXT>CREATE INDEX IDX_NUM1_CODUM ON NUM1 (CODUM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBJ_CMDINT1_CODCMDINT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6CDAB169A3B38B9AD0A1F8CA628B26E3425D78E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBJ_CMDINT1_CODCMDINT1 ON OBJ_CMDINT1 (CODCMDINT1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBJ_CMDINT1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>169A55D5CE17E6C7E27F16FB598F514FB010ABE7</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBJ_CMDINT1_CODOBIECT ON OBJ_CMDINT1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIFLUNA_ALR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDB35A16B9BCF5E0D0741EA79029AEA5FD2DA03E</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIFLUNA_ALR ON OBLIGPIFLUNA (AN,LUNA,REST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIFLUNA_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02D5B34983B09304BBAD2780193CF061DF83EB17</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIFLUNA_ANLUNA ON OBLIGPIFLUNA (12*&quot;AN&quot;+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIFLUNA_CAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E17AC3DFB624F0B70DA60866BBAD39EF72B9E0E7</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIFLUNA_CAL ON OBLIGPIFLUNA (CODOBLIGPIF,AN,LUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIF_CODGENERAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD085DBBF585BEA9FBF8F2EF5AA6F544BD55B3CB</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIF_CODGENERAL ON OBLIGPIF (CODGENERAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIF_CODOBLIGASOCIAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32E337CBF2D0FEBF4EF464AE9F6BB997AB90C010</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIF_CODOBLIGASOCIAT ON OBLIGPIF (CODOBLIGASOCIAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIF_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E1F0303967464BE10A02AA0F9077EAB990F0E39</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIF_CODPART ON OBLIGPIF (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OBLIGPIF_SEMNIFICATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>480AD670D7C8808ED0F6502C4327DF1F55390726</HASHVAL>
  <TEXT>CREATE INDEX IDX_OBLIGPIF_SEMNIFICATIE ON OBLIGPIF (SEMNIFICATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45500B99C022DEE98EDB312AA51377AE8079BBE9</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA1_CODOBIECT ON OFERTA1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA1_CODOFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E386DC96D111A7B380D48B11502A991E82A055C2</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA1_CODOFERTA ON OFERTA1 (CODOFERTA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74E4FA4327B3FE4A6545746CCA14CE8FEF77EDDE</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA1_UMSEC ON OFERTA1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA_LOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>598CD065D76465C3C09634AD8CE2DCA3B77F5189</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA_LOCATIE ON OFERTA (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F6477BF9AE1B9A628D8C3833ECA476C2828BB2A</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA_PARTENER ON OFERTA (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OFERTA_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67704B8CDAA5FB7C879D772DCCD1D761AC4FAE86</HASHVAL>
  <TEXT>CREATE INDEX IDX_OFERTA_SUBUNITATEA ON OFERTA (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORART_CODCOMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>961B5265DDDC0E2CC74F8036868057BE1AB01229</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORART_CODCOMANDA ON TMP_ONORCOM_ARTICOLE (CODCOMANDA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORART_CODCOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>616229C9C6CB83C215799BE654C2F1CE0EE7530C</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORART_CODCOMANDA1 ON TMP_ONORCOM_ARTICOLE (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORART_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D2026E315ED8FDA6CF80E0C015AD78B57EB1C908</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORART_CODOBIECT ON TMP_ONORCOM_ARTICOLE (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORPREL_CODCOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9DEDBA58B4B0A50412BC983B1232F22E2060FCA6</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORPREL_CODCOMANDA1 ON TMP_ONORCOM_PRELSTOC (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORPREL_CODNIRSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51B0B729F014DDFB20A6D6A685E2C86CBA9044B0</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORPREL_CODNIRSER ON TMP_ONORCOM_PRELSTOC (CODNIRSER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ONORPREL_CODNIRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F11C98D9A20F509C11FFB07229DF814B37D182A0</HASHVAL>
  <TEXT>CREATE INDEX IDX_ONORPREL_CODNIRSTOC ON TMP_ONORCOM_PRELSTOC (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ORELM_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8027EF7EF537EC1F6595F5E8ED227B994350110</HASHVAL>
  <TEXT>CREATE INDEX IDX_ORELM_DATA ON ORELM (DATALM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OREPONTAJ_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF00D1484E372D58FCF4443E54F5118CADE431A6</HASHVAL>
  <TEXT>CREATE INDEX IDX_OREPONTAJ_CODFORMATIE ON OREPONTAJ (CODFORMATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_OREPONTAJ_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BB91C3B4519E41E73EBA8010A1B058AEB763029</HASHVAL>
  <TEXT>CREATE INDEX IDX_OREPONTAJ_CODPERS ON OREPONTAJ (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACHDLLINK_CODPACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53D96B15938D9BF21341C3973C5EA7A36998E259</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACHDLLINK_CODPACHETEOBJ ON PACHETEDLLINK (CODPACHETEOBJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACHETE1_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D68964C4D03231F61DB46E4B66969CF0CA93D715</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACHETE1_CODDOC ON PACHETE1 (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACHETE1_CODPACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50EB73722754DD6ADD1922BD1CA7BF48242201EF</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACHETE1_CODPACHETE ON PACHETE1 (CODPACHETE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACHETE1_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BBC38ED794A480FD897380C0AB114992AD41FF8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACHETE1_TIPDOC ON PACHETE1 (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACHETELINK_CODPACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCFDA5332552E5D14F4CD453C31B1BC65C702DE8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACHETELINK_CODPACHETEOBJ ON PACHETELINK (CODPACHETEOBJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACKING_CODAMB_PRIMAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5567E342D0197BF56748456DAED4D5C526493320</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACKING_CODAMB_PRIMAR ON PACKING1 (CODAMB_PRIMAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACKING_CODAMB_SECUNDAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C96F3020E46332921F74399B2E528C958AB663AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACKING_CODAMB_SECUNDAR ON PACKING1 (CODAMB_SECUNDAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACKING_CODAMB_TERTIAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A7B452CE5232D0E5007442D8B4C7DA0A3A0D8D0</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACKING_CODAMB_TERTIAR ON PACKING1 (CODAMB_TERTIAR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACKING_CODDOC_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C24E3503F174A63D54FFF37443CA656ED80F2702</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACKING_CODDOC_TIPDOC ON PACKING (CODDOC,TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PACKING_CODPACKING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7CD73F829F1D2FCB4DD0781B8C2D6C664CA5DA09</HASHVAL>
  <TEXT>CREATE INDEX IDX_PACKING_CODPACKING ON PACKING1 (CODPACKING) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PARTTOT_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08DD4D853EC07A61EE14E822C6F7E865D7F5CFDD</HASHVAL>
  <TEXT>CREATE INDEX IDX_PARTTOT_CODPART ON PARTTOT (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PC_MAN_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C457644B40D7E61B23D3CCE1F032E4FAF9C43ACD</HASHVAL>
  <TEXT>CREATE INDEX IDX_PC_MAN_CODOBIECT ON TMP_PRODCOMP_MAN (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PC_MAN_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>128329D264579BBA98BFA02FC6C7B9CD6F825D05</HASHVAL>
  <TEXT>CREATE INDEX IDX_PC_MAN_CODPRODCOMP ON TMP_PRODCOMP_MAN (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PC_MAN_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30C86BD10C940BC40C70A22D00C2BAE5F92A04C0</HASHVAL>
  <TEXT>CREATE INDEX IDX_PC_MAN_USERID ON TMP_PRODCOMP_MAN (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFLINK_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1D3CF7B7E39BC693BE0568D2D9DB8DCB9422433</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFLINK_CODCOMANDA1 ON PLANIFLINK (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFLINK_CODSTARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E23DAFF80CA84EB361AE7805A1FC0029B74816ED</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFLINK_CODSTARE1 ON PLANIFLINK (CODSTARE1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFLOCK_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>486F9BB0FC34DDA761F885993DE63993DD343C98</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFLOCK_CODGEST ON PLANIFLOCK (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFLOCK_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEA008D32EEA6F6D03947455CC3543A4D3802C9A</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFLOCK_USERID ON PLANIFLOCK (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9612BA8424291476E120975C99F76E31F5E77B4</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_CODOBIECT ON PLANIFNOD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_CODPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7CE48FD8D66FDEF8E3A69A1C0986F74E51EDDE8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_CODPLANIFPROD ON PLANIFNOD (CODPLANIFPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_CODPLANIFPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>341A16948050E1AEBF893AA75E6E335F828A2DAB</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_CODPLANIFPROD1 ON PLANIFNOD (CODPLANIFPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_CODPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F627DC105D696418D49A93E78ABCF73111B3B02</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_CODPRODMAT ON PLANIFNOD (CODPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75BCF9EE6583F1E8D576BE9DF93705C550F3409C</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_CODRETETA ON PLANIFNOD (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_NODORIGINAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D945EC3DD4C10A82EF7AA4116EE3AD865D51F15</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_NODORIGINAL ON PLANIFNOD (NODORIGINAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFNOD_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31BB5C09A48BE20B0D1B8343066CD03D55602146</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFNOD_TIP ON PLANIFNOD (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CODLANSPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>531978BEFCB4BC2573F5A3E40C89687DDA62D6FA</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CODLANSPROD1 ON PLANIFPROD1 (CODLANSPROD1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>118A61B90EE6FC620A2E8960C94D2EC431673DF0</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CODOBIECT ON PLANIFPROD1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CODPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F00ED058971F74BC039345DC343E81B9278CDBE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CODPLANIFPROD ON PLANIFPROD1 (CODPLANIFPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0035C2B4483D29211CC72FD01EF0F55A1B3EC3A9</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CODPROIECT ON PLANIFPROD1 (CODPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D80A117545C8510AAAC0AD5B2427F185E9AD9648</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CODRETETA ON PLANIFPROD1 (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD1_CUPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D048FC39D83E361ECE0535AA5E0BFBF64DC25CA3</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD1_CUPROIECT ON PLANIFPROD1 (CUPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPRODLUN_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE86C40FB3177129BB3EF1362177CB0DEB1F17CB</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPRODLUN_ANLUNA ON PLANIFPRODLUN (ANLUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPRODLUN_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEBAF49372CBC61A7EC8018BAA2DF439A98ADA8F</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPRODLUN_CODGEST ON PLANIFPRODLUN (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPRODLUN_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11B6A8E97DCF1276091E88105EA826BE36BFA1EF</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPRODLUN_CODOBIECT ON PLANIFPRODLUN (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD47F8BFF770C745C1516DE9E39A97DEA17285B5</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_ANLUNA ON PLANIFPROD (&quot;AN&quot;*12+&quot;LUNA&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9ED371858DD6423949FAFE73A87F4049F861ECAD</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_ANULAT ON PLANIFPROD (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5055CDF159B928413C5302BB506208FDF960F4C</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_CODLANSPROD ON PLANIFPROD (CODLANSPROD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_NRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53D84737C3B2FAD0773F79B9D0DA0A48CF3DBB0C</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_NRDOC ON PLANIFPROD (NRDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3342116E31860A1B808422BF2222AEB9E562545B</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_OPERAT ON PLANIFPROD (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53D96265D45B82E4E3F526473CDA5227C3B205D1</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_SAPTAMANA ON PLANIFPROD (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_SERIADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A56C14D7FB8318950D349B42DBE94365FCD2A5F7</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_SERIADOC ON PLANIFPROD (SERIADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLANIFPROD_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5C5525D6C1C3AFD6243193745CCD90FF4F50739</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLANIFPROD_SUBUNITATEA ON PLANIFPROD (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLATI1_CODOBLIGPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74E612FC1D45F8420125D6C80AD1CF6982B6FC44</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLATI1_CODOBLIGPIF ON PLATI1 (CODOBLIGPIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLATI1_CODPLATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B01C712CEEF0176097D39AF2909E333D8566BD5</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLATI1_CODPLATA ON PLATI1 (CODPLATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLATI1_STINSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7BAC9001023CBF58D852065C66F13421F3E4E17</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLATI1_STINSA ON PLATI1 (STINSA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLATI2_CODPLATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4073924BB9C419FA4FD4F56822AE66A4CEF0A4C4</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLATI2_CODPLATA ON PLATI2 (CODPLATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLSTR_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D4B4940CAFB6AEBFEDAC6C68D6D68A21158E399</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLSTR_AN ON PLANIFSTRUCT (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLSTR_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD6B4302371EC2FF590AF4AEFC18A647FF19AB43</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLSTR_CODOBIECT ON PLANIFSTRUCT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLSTR_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>894EA9C63976644C79841C81CBF6848BC7BCA9D8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLSTR_CODRETETA ON PLANIFSTRUCT (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PLSTR_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3B65FF2D045FFBBC2FEE420260979325FE1A95E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PLSTR_SAPTAMANA ON PLANIFSTRUCT (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PMPLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67FE5F326D3ED2C9B2F23B46E1AFCFFDEFAB1C2B</HASHVAL>
  <TEXT>CREATE INDEX IDX_PMPLUNA ON PMPLUNA (AN,LUNA,CODOBIECT,CODSUBUNIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PNODZTL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDC279F4DEC44C0C7CFCBFDD7E663DAF0A0075C9</HASHVAL>
  <TEXT>CREATE INDEX IDX_PNODZTL_CODOBIECT ON TMP_PLANIFNODZTL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PNODZTL_CODRETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>762060D214A7D05F24B3EFE5B812ADBA4CBA610D</HASHVAL>
  <TEXT>CREATE INDEX IDX_PNODZTL_CODRETETA ON TMP_PLANIFNODZTL (CODRETETA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PNODZTL_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD8F326E4B2BB45BF7AA2D7803C118EB61CDE676</HASHVAL>
  <TEXT>CREATE INDEX IDX_PNODZTL_USERID ON TMP_PLANIFNODZTL (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PN_MAN_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4A3CE982E2DA3F4B031530A3807EFE2562037A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_PN_MAN_CODOBIECT ON TMP_PROIECTNOD_MAN (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PN_MAN_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4575F9A97AE9585733913137D8086605AF08EE8E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PN_MAN_CODPROIECT ON TMP_PROIECTNOD_MAN (CODPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PN_MAN_CODPROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF36C487778B0052F073CF62A21DE7B4EF654AA8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PN_MAN_CODPROIECTNOD ON TMP_PROIECTNOD_MAN (CODPROIECTNOD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PN_MAN_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B84968FC2E6E80AFB809EC4013BECA073DF7445</HASHVAL>
  <TEXT>CREATE INDEX IDX_PN_MAN_USERID ON TMP_PROIECTNOD_MAN (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_POSBANCAR_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>524DB7F1FE6960A986A1DBA6CCA0E05789EE578A</HASHVAL>
  <TEXT>CREATE INDEX IDX_POSBANCAR_USERID ON POSBANCAR (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PPLINK_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>699263AB6713CFA62ADFA171CB93B79943ECBE2E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PPLINK_CODCOMANDA1 ON PPLINK (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PPLINK_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D159288604D62AEE6B3659DAFB8D26B0F3C6CA33</HASHVAL>
  <TEXT>CREATE INDEX IDX_PPLINK_CODINTR1 ON PPLINK (CODINTR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC4A42F55D38E4A47B63611A6906638C02206BAC</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA1_CODOBIECT ON PRECOMANDA1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA1_CODPRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E7A3C9178D3DE839ECEED56693DDA6F4603097D</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA1_CODPRECOMANDA ON PRECOMANDA1 (CODPRECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA1_CODSTARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A932CABF3D73F5CD230006D0AAEC73967D8528CD</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA1_CODSTARE1 ON PRECOMANDA1 (CODSTARE1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA1_TERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BC3B60EBF0BEC84F70EB47965C6ECE438F2536E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA1_TERMEN ON PRECOMANDA1 (TERMEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA59FA2F6C057522E00446B21416A1447EEDB3D6</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA1_UMSEC ON PRECOMANDA1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA_ANULAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EA6DA684BC0FD6D6F81E3783558FBAFC96F5ECC</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA_ANULAT ON PRECOMANDA (ANULAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA_INCHISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8215C836F279F0888CF93579A1682B9F3DE90F4E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA_INCHISA ON PRECOMANDA (INCHISA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA_OPERAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B1CEB3288513DDE8D49210CADDD9DF36BEE45DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA_OPERAT ON PRECOMANDA (OPERAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRECOMANDA_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FE7260A64AA88BEBCE574E49A4BE1FAD02CB4CB</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRECOMANDA_SUBUNITATEA ON PRECOMANDA (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_CODEXTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BC054EE808BA182A53FD4A42CD26ED2D7D2D37A</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_CODEXTERN ON PREDARIPLUS (CODEXTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_DATADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89310309C3E352E5833FD691424F84325EB38BD0</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_DATADOC ON PREDARIPLUS (DATADOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_DATAMODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>930B5C63F88E7AD37FAC1E3F2467745BD8EEE4EA</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_DATAMODIF ON PREDARIPLUS (DATAMODIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_NRCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47B158A573EDD2C251DE6FA44075ACD74D39F691</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_NRCMD ON PREDARIPLUS (NRCMD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_SECTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A385B9D9C0D194D07D24F69573B648F39C125333</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_SECTIE ON PREDARIPLUS (SECTIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDARIPLUS_USERIDBLOCAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A66B5CD4A9715935DF900252D9478F87C2EFBDF</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDARIPLUS_USERIDBLOCAJ ON PREDARIPLUS (USERIDBLOCAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDM_CODCMDPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19C16112C5D4C400F83B6533351F444BB68D9F18</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDM_CODCMDPRODMAT ON PREDARI_MAN (CODCMDPRODMAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDM_CODCOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2FC4C4F2E04C749D605DFFDA02BEC1FBC21E247A</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDM_CODCOMANDA1 ON PREDARI_MAN (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PREDM_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>155892101AF6E3914ACD5DE85D9A04D8D3E5A960</HASHVAL>
  <TEXT>CREATE INDEX IDX_PREDM_CODOBIECT ON PREDARI_MAN (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRED_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C78F84083E07EF09B7930D9E5AAE44408588635</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRED_CODOBIECT ON TMP_PREDARI_LANSPROD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRETMAMB_CODPRETM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFEB62074C06145D765E2A4910255545E7529D44</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRETMAMB_CODPRETM ON PRETMAMB (CODPRETM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRETM_CODCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D40B8711CB341B8FBF7B2876B0054165C9E17254</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRETM_CODCATPRET ON PRETM (CODCATPRET) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRETM_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4160EA51E2EA480F95730800C3D4A64E5FB3200B</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRETM_CODOBIECT ON PRETM (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRETM_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B3883559872D47E17AE7141E23CBBAD1512AB36</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRETM_SUBUNITATEA ON PRETM (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODCOMP_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C822AD685657C6AA34621D338E57A874C2AA59E6</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODCOMP_CODOBIECT ON PRODCOMP (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAN_CODLOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>302F4BDA295A87BA36FC34450CDBADC2D67EED2D</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAN_CODLOC ON PRODMAN (CODLOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAN_CODOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98E767FBCCC23A914395C1A91385A9242B0718D4</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAN_CODOP ON PRODMAN (CODOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAN_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B25760705723EAC5B19C87B1DDA9FAA931947001</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAN_CODPRODCOMP ON PRODMAN (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAN_CODPRODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC036FD64971E5CBEE67238C2F193954C9F5614D</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAN_CODPRODGEST ON PRODMAN (CODPRODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAN_CODTARIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34E77A2130B747932D6FDF678F3711BA29BD7A28</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAN_CODTARIF ON PRODMAN (CODTARIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMATECHIV_CODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF518D5E03B14DE1183DD9F91FEB4E896FDC66CE</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMATECHIV_CODMAT ON PRODMATECHIV (CODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMATECHIV_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25253A6DE5D5562D11C789667DBE426029DFD2DA</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMATECHIV_CODOBIECT ON PRODMATECHIV (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMATECHIV_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4DF4DCE5254B768DABBA685E26C3E9BB8DABA03</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMATECHIV_CODPRODCOMP ON PRODMATECHIV (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAT_CODATRIBUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>113B5D5BAB4EC9A99DF1AAC3C992CC7A35ED3ED0</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAT_CODATRIBUT ON PRODMAT (CODATRIBUT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D983ECA451177C1308161A27739BCA8D3B92DF53</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAT_CODOBIECT ON PRODMAT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAT_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF61D9E1D68D84A680EE5D8A5012AC38563562E1</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAT_CODPRODCOMP ON PRODMAT (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODMAT_CODPRODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADEED1FA9AA29CDDBAD7B3C5C6ECCCD6A9054E80</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODMAT_CODPRODGEST ON PRODMAT (CODPRODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODNORME_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF1B844C1307BBBE22057470C8415757F94D184E</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODNORME_CODPRODCOMP ON PRODNORME (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODNORME_IMPLICIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E74670AFF35357E8DB53C6B2054A250BD080CC53</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODNORME_IMPLICIT ON PRODNORME (IMPLICIT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PRODSDV_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4C723998C6CF6401E0AA2C7ECB83EBBBC3308B7</HASHVAL>
  <TEXT>CREATE INDEX IDX_PRODSDV_CODPRODCOMP ON PRODSDV (CODPRODCOMP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROGRAMF1_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8121477ED115D8B5099760B7FA482BADD5BDBDDB</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROGRAMF1_CODCOMANDA1 ON PROGRAMF1 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROGRAMF1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FD4C4FFA4F68803BA480A1E31897D21D8A33D1F</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROGRAMF1_CODGEST ON PROGRAMF1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROGRAMF1_CODPROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2193749E00A4308D8B9A18A842E4739BCD3D6EF1</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROGRAMF1_CODPROGRAMF ON PROGRAMF1 (CODPROGRAMF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROGRAMFSDV_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>957B3533935410D5A2B1D4E515F1416CE7B2D0CB</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROGRAMFSDV_CODGEST ON PROGRAMFSDV (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROGRAMFSDV_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76F30BDF110A934523C194D4A74087ADFBEA0CCD</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROGRAMFSDV_CODOBIECT ON PROGRAMFSDV (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROIECTNOD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F652396BEE57A4077CFB1F22C9717EBEAA15288B</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROIECTNOD_CODOBIECT ON PROIECTNOD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROIECTNOD_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EE8310FBD71F4F0D985DE353B65DF6D9BCBC86F</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROIECTNOD_CODPROIECT ON PROIECTNOD (CODPROIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMOPART_CLASAP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F476223A5670DB7E0AA54539E02F0347D4A2183</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMOPART_CLASAP ON PROMOPART (CODCLASEP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMOPART_LOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7932B37B495211E4FEAD9EC6A6F9627351D9F247</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMOPART_LOCATIE ON PROMOPART (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMOPART_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0736E6ED388EDB147B44223942A0AD2B4C359C40</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMOPART_PARTENER ON PROMOPART (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMOSUB_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBD2036C6FFC1A489B2EBAD4653006A02FA1D71A</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMOSUB_SUBUNITATEA ON PROMOSUB (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMO_LOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60F19A91402FA6212F4B1A4C758925B10248BF0B</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMO_LOCATIE ON PROMO (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMO_PARTENER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>985FFB62F173D9D0843459ECD9C99120C48A74C8</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMO_PARTENER ON PROMO (PARTENER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_PROMO_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>130B3104C089453C5C2546D2B63F0B3DFD2649EC</HASHVAL>
  <TEXT>CREATE INDEX IDX_PROMO_SUBUNITATEA ON PROMO (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RAPORTP1_CODRAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD6818AA1488C1E96BD6F43168CD213602FC5648</HASHVAL>
  <TEXT>CREATE INDEX IDX_RAPORTP1_CODRAPORTP ON RAPORTP1 (CODRAPORTP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RAPORTP2_CODRAPORTP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75CBC48D620552C28D2E77BAA506B217037919F7</HASHVAL>
  <TEXT>CREATE INDEX IDX_RAPORTP2_CODRAPORTP1 ON RAPORTP2 (CODRAPORTP1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RAPORTP_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E3901FEF49A962FF62862F9F4FB64EFCD294B1E</HASHVAL>
  <TEXT>CREATE INDEX IDX_RAPORTP_SUBUNITATEA ON RAPORTP (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B464774CC512743CBEE6DF4B62A3D4745F48FE78</HASHVAL>
  <TEXT>CREATE INDEX IDX_REG ON REG (AN,LUNA,TIPREG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REGOSS1_CODREGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>851CA384D8181824CF6E9ABABA79255F989A5011</HASHVAL>
  <TEXT>CREATE INDEX IDX_REGOSS1_CODREGOSS ON REGOSS1 (CODREGOSS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REGPERS1_CODREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEC5A40F2A628CBB6DF7404899E05FE72EF16B44</HASHVAL>
  <TEXT>CREATE INDEX IDX_REGPERS1_CODREG ON REGPERS1 (CODREG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REGTREZOR1_CODREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EF590F96966D0C61C6F81C1FD5D6E24293FD943</HASHVAL>
  <TEXT>CREATE INDEX IDX_REGTREZOR1_CODREG ON REGTREZOR1 (CODREG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RESTARTINACTIVE_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>625F726E284AA6573C0AA0F1AFA61A058F957E8F</HASHVAL>
  <TEXT>CREATE INDEX IDX_RESTARTINACTIVE_CODOBIECT ON RESTARTINACTIVE (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RESTARTINACTIVE_CODREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EC8E76170398EE140426DE8DD459F0A284DD018</HASHVAL>
  <TEXT>CREATE INDEX IDX_RESTARTINACTIVE_CODREST ON RESTARTINACTIVE (CODRESTAURANT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RETUROSTINS_CODRETURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9B1EAEBDCF645F2254C358779D53F761EF490A9</HASHVAL>
  <TEXT>CREATE INDEX IDX_RETUROSTINS_CODRETURO ON RETUROSTINS (CODRETURO) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RETUROSTINS_TIPDOCCODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B833FB19F3545A2084D3860CCBBDAAB5F2B4227</HASHVAL>
  <TEXT>CREATE INDEX IDX_RETUROSTINS_TIPDOCCODDOC ON RETUROSTINS (TIPDOC,CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RETURO_SESSIONID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA2F249A265AC735E3D10BC9E0566B4EB51DC218</HASHVAL>
  <TEXT>CREATE INDEX IDX_RETURO_SESSIONID ON RETURO (SESSIONID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RETURO_VOUCHERBARCODE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B50349EA21A659241BAC162C514629C4885163E</HASHVAL>
  <TEXT>CREATE INDEX IDX_RETURO_VOUCHERBARCODE ON RETURO (VOUCHERBARCODE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC8A9DD6AAD21DB692B52FF1811DDA111C049118</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODCMDPRODMAT ON REZERVATS (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A4A915090A07FBB3A08D8E31DB3CBB687511472</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODCOMANDA1 ON REZERVATS (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODCOMANDA1F</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4926E5C9352ADAF119B5059978EC3253FC8C1A8B</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODCOMANDA1F ON REZERVATS (CODCOMANDA1F) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODINVENTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8260E8C42BEC5691A4751454FE6CDBA7231E91FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODINVENTAR1 ON REZERVATS (CODINVENTAR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODNIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F81724469B80DC84FDA18190D7744F85DB2D8AE</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODNIRSER ON REZERVATS (CODNIRSER) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19277D934A39D779260721F2C222A902494308BB</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODNIRSTOC ON REZERVATS (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11A9499988DB885FEF23D9A770CFC9914B59F4DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_CODOBIECT ON REZERVATS (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_REZERVATS_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8296176C1982A0405D5C1EDF9F0F306F2B3043A0</HASHVAL>
  <TEXT>CREATE INDEX IDX_REZERVATS_UMSEC ON REZERVATS (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_RF_CTC_AUXCOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFA491F66AC2D0DC9876B109C9268D0116EC7DD5</HASHVAL>
  <TEXT>CREATE INDEX IDX_RF_CTC_AUXCOD ON RF_CTC_AUXCOD (COD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_DEDGEN0_CODDEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFAB214522403A09F0F6C3BE9F80A3462BC9E0A1</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_DEDGEN0_CODDEDGEN ON SAL_DEDGEN0 (CODDEDGEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_DEDGEN1_CODDEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9184650188C9670687656630BA2BF7D49A570CF8</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_DEDGEN1_CODDEDGEN ON SAL_DEDGEN1 (CODDEDGEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_DEDGEN1_CODDEDGEN0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A7579FE9CCC7E6447068E193241040296808140</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_DEDGEN1_CODDEDGEN0 ON SAL_DEDGEN1 (CODDEDGEN0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_IMPOZ0_CODIMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>886296C8BA6A632996BB75FEC9796AAC58827C2B</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_IMPOZ0_CODIMPOZ ON SAL_IMPOZ0 (CODIMPOZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_IMPOZ1_CODIMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD131BD8B4345990153718B0D6673487893BB7D7</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_IMPOZ1_CODIMPOZ ON SAL_IMPOZ1 (CODIMPOZ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_IMPOZ1_CODIMPOZ0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4CD3F32DE83E719E5CCF170030354361422AE8D0</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_IMPOZ1_CODIMPOZ0 ON SAL_IMPOZ1 (CODIMPOZ0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_INTRERUP_SIMBOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FE9E663E349EA80B13DDE5AC0DF63D1BE70515B</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_INTRERUP_SIMBOL ON SAL_INTRERUP (SIMBOL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG0_ZPF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51D05BE5B7477163E4C7ACEE993FCFC83C2381F5</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG0_ZPF ON SAL_NASIG0 (ZILEPLATAFIRMA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG1_COD0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3B81CB4E6AF300E5A09E7E9AFA03211ECC6B0B1</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG1_COD0 ON SAL_NASIG1 (CODNASIG0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG2_COD0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6C5D623FAA173741A73B574B44CFE0FFCA5DD1A</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG2_COD0 ON SAL_NASIG2 (CODNASIG0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG2_COD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E517FCC20122B7CF7061B004C3F59F397713B3A0</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG2_COD1 ON SAL_NASIG2 (CODNASIG1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG3_COD0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBB2A1CB174D03D4723C156B1FED0230A131837A</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG3_COD0 ON SAL_NASIG3 (CODNASIG0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F4244B616E1A2199B81D4EBDDDDCBFE1F55AC2D</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG_COD ON SAL_NASIG (CODASIG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NASIG_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A74EA11A532EE575542D8ABD2686BCFD24CCC9A2</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NASIG_TIP ON SAL_NASIG (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NCONTRIB1_TIPCTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>702D250564C3213C8B24E14E3127B9CEB166EBFE</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NCONTRIB1_TIPCTR ON SAL_NCONTRIB1 (TIPCONTRACTUAL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NCONTRIB_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78C4281F2E0E7E9719CD7CAE989A33467012877F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NCONTRIB_DENUMIRE ON SAL_NCONTRIB (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NCONTRIB_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A73FFC7B309BBD0C2168B2B3642948E884534CBE</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NCONTRIB_TIP ON SAL_NCONTRIB (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NDREP1_NDREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B10C3593EAD731E6E8C80EFD5DE50921794BE3BE</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NDREP1_NDREP ON SAL_NDREP1 (CODNDREP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NDREP1_NDREP0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19C7302B2AFF52F431AA49BCA8AD8B245E6F6FCE</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NDREP1_NDREP0 ON SAL_NDREP1 (CODNDREP0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NDREP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>821D5B103F6DAD025F9FAB941A58F7D05F19568F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NDREP_COD ON SAL_NDREP (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_NDREP_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8078C85628CD774DB40A42F2DD9B33F4931242E</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_NDREP_TIP ON SAL_NDREP (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RA21_CODSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5347C92215F476D5DDAE7C835583C24057FF3DC9</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RA21_CODSPOR ON SAL_RA21 (CODSPOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RA21_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03A025C9D078842993D99AF999DBA5CE7C8FD097</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RA21_DENUMIRE ON SAL_RA21 (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RA24_CODTIPSP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB4B739AB6739A8EC5A7AA4B298C5987CF17FBE9</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RA24_CODTIPSP ON SAL_RA24 (CODTIPSP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RA24_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3FDB2CDA9CA16B16AFBAF53591C6D86C4959A23</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RA24_DENUMIRE ON SAL_RA24 (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RETINERI0_CODRETINERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B9D7EA339D1CAC8D53828883AB9BCCE700EE51F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RETINERI0_CODRETINERE ON SAL_RETINERI0 (CODRETINERE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_RETINERI_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0A2C0676733452129BF0621214E271FD2B4AA37</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_RETINERI_DENUMIRE ON SAL_RETINERI (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_SPORURI0_CODSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>743BA40D2BEE71C73A2DC0CA0DAB72BD73AB6F66</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_SPORURI0_CODSPOR ON SAL_SPORURI0 (CODSPOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_SPORURI0_TIPCOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A333F213807C59DB7FAD40BEAB0A36EDD9FD379D</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_SPORURI0_TIPCOD ON SAL_SPORURI0 (TIP,CODSPOR0) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_SPORURI1_CODSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D2D42C7E8DF45F249F163F9B365C5BF99007D67</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_SPORURI1_CODSPOR ON SAL_SPORURI1 (CODSPOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_SPORURI2_CODSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>112BF981146F5CA718CDB09BE9312570D6AA8338</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_SPORURI2_CODSPOR ON SAL_SPORURI2 (CODSPOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SAL_SPORURI_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE65B46E31C2D395BC031050CD7CA4BE133C72EA</HASHVAL>
  <TEXT>CREATE INDEX IDX_SAL_SPORURI_DENUMIRE ON SAL_SPORURI (DENUMIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIICMD_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E053F1AE7F1769381F0AFEC3870AB73040AA4ACB</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIICMD_CODCOMANDA ON SERIICMD (CODCOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIICMD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50AD28DE37965ECD3CF330F2C58DC7644014569C</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIICMD_CODOBIECT ON SERIICMD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIIIES_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3733C3A220BC8B166B088BD816F9ABE371ED316F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIIIES_CODIES ON SERIIIES (CODIES) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIIIES_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C320E139C0FD87CCD52F5A858E1222FF901DFAD</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIIIES_CODOBIECT ON SERIIIES (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIIINTR_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>803229039D3F5DDC66457667E6C47D50025580DC</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIIINTR_CODINTR ON SERIIINTR (CODINTR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIIINTR_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE0AC3DD650C092D2AB5DE517FC66A0EB59D42E4</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIIINTR_CODOBIECT ON SERIIINTR (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIITRANSF_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB34D0A9C55EB86F39591944E2147BBB353B236B</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIITRANSF_CODOBIECT ON SERIITRANSF (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SERIITRANSF_CODTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD8773D9228D920B1F4830BF8A877EDFEFB7731B</HASHVAL>
  <TEXT>CREATE INDEX IDX_SERIITRANSF_CODTRANSF ON SERIITRANSF (CODTRANSF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SETTASKOBJASOC_CODIES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F46EDDB22612A7147ACAA52DC137EFBB3C54AA8</HASHVAL>
  <TEXT>CREATE INDEX IDX_SETTASKOBJASOC_CODIES1 ON SETTASKOBJASOC (CODIES1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SETTASKOBJASOC_CODTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>725348C9B046F8CF503A84183C2A272A5C5246AF</HASHVAL>
  <TEXT>CREATE INDEX IDX_SETTASKOBJASOC_CODTASK ON SETTASKOBJASOC (CODTASK) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SETTASKOBJ_CODTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41888BD30DD30D2E95FE8CDA4B394EF715AF7EEF</HASHVAL>
  <TEXT>CREATE INDEX IDX_SETTASKOBJ_CODTASK ON SETTASKOBJ (CODTASK) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SGRCOLECT1_CODSGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B7DEABDA31D862D2318B79732693AF0059611EB</HASHVAL>
  <TEXT>CREATE INDEX IDX_SGRCOLECT1_CODSGRCOLECT ON SGRCOLECT1 (CODSGRCOLECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINCRONIZAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3058EEBAA158253C143F0B2236643778DBBF4EF5</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINCRONIZAT ON SYNCPRETRETAIL (SINCRONIZAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL1_CODEMULARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B94A95BEFB81A23E81D54A1B9062A4CE9F9EF50D</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL1_CODEMULARE1 ON SINTEZAEMULARE1 (CODEMULARE1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL1_CODPOSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC27E2D1FE9E7BB8E0A705E4EB45F8946BE21441</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL1_CODPOSTRETAIL ON SINTEZAEMULARE1 (CODPOSTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL1_CODSINTEZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6CC0157FBA8440DDFB99069B3B5BECC1B1CB2DE</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL1_CODSINTEZA ON SINTEZAEMULARE1 (CODSINTEZA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL2_CODEMULARE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7720B111727FEDF863AD6E3377075001E2374DAD</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL2_CODEMULARE2 ON SINTEZAEMULARE2 (CODEMULARE2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL2_CODPOSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F41A2972AF8B65CBF73ECAB470A1E5A42FFE4CCC</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL2_CODPOSTRETAIL ON SINTEZAEMULARE2 (CODPOSTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMUL2_CODSINTEZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9996B7A074E98A505F3BBF203689A5F4E7B9EF7C</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMUL2_CODSINTEZA ON SINTEZAEMULARE2 (CODSINTEZA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SINTEZAEMULARE_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A9667D6FF5FB5B3ED5865499F160B79CA2629319</HASHVAL>
  <TEXT>CREATE INDEX IDX_SINTEZAEMULARE_CODEMULARE ON SINTEZAEMULARE (CODEMULARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SITFINALTE_COLOANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D522D64CC1181A90223B4FB8D153877F8FEFDC8F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SITFINALTE_COLOANA ON SITFINALTE (COLOANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SITFINALTE_RAND</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9966F7135A9B7D63F5D08E3560133BBD82C591D3</HASHVAL>
  <TEXT>CREATE INDEX IDX_SITFINALTE_RAND ON SITFINALTE (RAND) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SOLDINI_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03DA846998530F576FE36EDEB4838A836F48EE07</HASHVAL>
  <TEXT>CREATE INDEX IDX_SOLDINI_CODPART ON SOLDINI (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SOLDPARTLUNA_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACC9514151E36D7530C539A54E1053FA1D5E38BF</HASHVAL>
  <TEXT>CREATE INDEX IDX_SOLDPARTLUNA_CODPART ON SOLDPARTLUNA (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SOLDPART_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E833DFC86589020538E2C2CB02FAFF9A8114D082</HASHVAL>
  <TEXT>CREATE INDEX IDX_SOLDPART_CODPART ON SOLDPART (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPLITCHELT1_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC94C3FC769F22348BA7FB76795F7FBFFF090BF4</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPLITCHELT1_CODGEST ON SPLITCHELT1 (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPLITCHELT1_CODSPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFF9FA4B155F6D2A73A191CFC90B7F8A508C612E</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPLITCHELT1_CODSPLITCHELT ON SPLITCHELT1 (CODSPLITCHELT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPLITCHELT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>492F164574FA9230FB2AE5729F9531F71AD0A58E</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPLITCHELT_CODOBIECT ON SPLITCHELT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPLITCHELT_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C07E87EB1C3027E96ED53B0B957DBB4289768B7</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPLITCHELT_SUBUNITATEA ON SPLITCHELT (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPVARHIVA_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1531A5F77379F83456AC32615EE2E8DC2017BA9B</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPVARHIVA_ANLUNA ON SPVARHIVA (AN,LUNA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPVARHIVA_CIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA4C65AA72511DE11481E779AACFC0C0AFCAB0B1</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPVARHIVA_CIF ON SPVARHIVA (CIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPVARHIVA_DATAINCARCARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7DC13A288E923BC560660D5E677ACF366ED6043</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPVARHIVA_DATAINCARCARE ON SPVARHIVA (DATAINCARCARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SPVARHIVA_IDDESCARCARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32088D63110CB85BE40C548886ED835C80414614</HASHVAL>
  <TEXT>CREATE INDEX IDX_SPVARHIVA_IDDESCARCARE ON SPVARHIVA (IDDESCARCARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>852918B777A8CCB06E5946FCC8F0A709A4DE63C0</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODCOMANDA1 ON STAREESTIMARI2 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>176DF9AB15C9A2483550886B3B302273BF03A4E2</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODMONEDA ON STAREESTIMARI2 (CODMONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19033AEFAD61A646769B4AFA13D6544F76B03029</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODOBIECT ON STAREESTIMARI2 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A48827A0543AFC6DA72BCE1857A679E5C0E36F35</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODPART ON STAREESTIMARI2 (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODSTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2ED5370B667AA764E54F7FB8EEE194A8B6062671</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODSTARE ON STAREESTIMARI2 (CODSTARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_CODSTARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09E483EAA9F3D6CCD159E6E03621E8BB470C39E7</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_CODSTARE1 ON STAREESTIMARI2 (CODSTARE1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREEST2_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BDC1F1F2FED4396F9951767DFA045912FE3FEBB8</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREEST2_SAPTAMANA ON STAREESTIMARI2 (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B01EDC20B59ADB27ABF85046A3F757E03BAA4387</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI1_CODOBIECT ON STAREESTIMARI1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI1_CODSTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AB889229222850BFA2D450E89D71B877AB61AC6</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI1_CODSTARE ON STAREESTIMARI1 (CODSTARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI_AN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F10836EEF1B5751DF9A3B0EF9FB58A7DA09F1DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI_AN ON STAREESTIMARI (AN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI_ANG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FB7DFF26A474E04B885F14A05198C27CA2E6196</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI_ANG ON STAREESTIMARI (ANG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI_SAPTAMANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A3CF7820E38DF226C6B98ED6B322D4DFEA5A288</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI_SAPTAMANA ON STAREESTIMARI (SAPTAMANA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STAREESTIMARI_SAPTAMANAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>228F6AA33CAFEC2C0AB953D8333E46C674D6A258</HASHVAL>
  <TEXT>CREATE INDEX IDX_STAREESTIMARI_SAPTAMANAG ON STAREESTIMARI (SAPTAMANAG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STINGERE_CODSTINGATORPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6287AF6668B266D4507628BC39FF04D4223D2B03</HASHVAL>
  <TEXT>CREATE INDEX IDX_STINGERE_CODSTINGATORPIF ON STINGERE (CODSTINGATORPIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STINGERE_CODSTINSPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0042CC73FF3E378AB6A9744EBFC2AE03183FFCE</HASHVAL>
  <TEXT>CREATE INDEX IDX_STINGERE_CODSTINSPIF ON STINGERE (CODSTINSPIF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCFAKE1_CODSTOCFAKE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>390263DDB03ABAA1C9ABAC67E6748DCFDDC89229</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCFAKE1_CODSTOCFAKE ON STOCFAKE1 (CODSTOCFAKE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCINI_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40165B7E0100C740BF33DADA2867909D739EBA1C</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCINI_CODGEST ON STOCINI (CODGEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCMPART_CODEXTERN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA349103CCD691F767177A851AE8E8307A4B8164</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCMPART_CODEXTERN ON STOCMPART (CODEXTERN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCMPART_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5ABF34AF969807BA566AF6696B3A387D0C2B4D5</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCMPART_CODLOCATIE ON STOCMPART (CODLOCATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCNEC5_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D869351905D02BDB7F2408C6EFEF1F6CC607685A</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCNEC5_CODOBIECT ON TMP_STOCREAL_NEC5 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCNEC5_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A746F588F71CAD460D4862F0A3941833A6263A5</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCNEC5_TIP ON TMP_STOCREAL_NEC5 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCNEC5_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAED741B29117295D46D143653E3380C8F5A8711</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCNEC5_USERID ON TMP_STOCREAL_NEC5 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCVALINI_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FA3412E3EEB096203773B583A246C2DEED651BF</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCVALINI_GEST ON STOCVALINI (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCVALLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D230740497222581EE9E1B99F421535C7682444</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCVALLUNA ON STOCVALLUNA (AN,LUNA,GEST,CODIOART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_STOCVALLUNA_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>990809C72E0848D5A23092B60C1BABD6AC70A0B8</HASHVAL>
  <TEXT>CREATE INDEX IDX_STOCVALLUNA_GEST ON STOCVALLUNA (GEST) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SYNCPARTRETAIL_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA78820B26BE801C9D19DE35B2A58C3EE16FBDA4</HASHVAL>
  <TEXT>CREATE INDEX IDX_SYNCPARTRETAIL_CODPART ON SYNCPARTRETAIL (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SYNCPROMO_CODPOSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4475E5A107CCCFDC6F3E962B149454BBFE5468A1</HASHVAL>
  <TEXT>CREATE INDEX IDX_SYNCPROMO_CODPOSTRETAIL ON SYNCPROMORETAIL (CODPOSTRETAIL) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SYNCPROMO_CODPROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B11128415305599CF7FB67FD5FF96647B0C0B83F</HASHVAL>
  <TEXT>CREATE INDEX IDX_SYNCPROMO_CODPROMO ON SYNCPROMORETAIL (CODPROMO) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_SYNCPROMO_SINCRONIZAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A9950A2AC1F32AD1C2D1DD7F15B69039EF066F4</HASHVAL>
  <TEXT>CREATE INDEX IDX_SYNCPROMO_SINCRONIZAT ON SYNCPROMORETAIL (SINCRONIZAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG1_CODCLASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EB053A77BDE260217AF7F16E0DC28F0E4A2CA6D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG1_CODCLASA ON TARGETAG1 (CODCLASA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDCB129BD7856F6FBCF98D72CD6AEC6C3CE7993A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG1_CODOBIECT ON TARGETAG1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG1_CODTARGETAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE9F83225AEA095F06879C65746806551413A1E9</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG1_CODTARGETAG ON TARGETAG1 (CODTARGETAG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70C22CB55C422D0BDD9F7786EC94D6522329B5F7</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG1_UMSEC ON TARGETAG1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG_MONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB8D327E22F39FE13D69FDC9AE011652F95E6E8A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG_MONEDA ON TARGETAG (MONEDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>594F69B0D94BFFF9769ADC2578E06424F542F457</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG_SUBUNITATEA ON TARGETAG (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARGETAG_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7BB1D740B5665B8ECDA390B539CBB9AF736B665</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARGETAG_TIPDOC ON TARGETAG (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TARIFEMAN1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CDF497657CA5D202661C9250995DFC4D78140F9</HASHVAL>
  <TEXT>CREATE INDEX IDX_TARIFEMAN1_AL ON TARIFEMAN1 (CODTARIF,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TAXDECL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E71ADFFF66DB64F7DFCC908FD6F4C3843C3B89E</HASHVAL>
  <TEXT>CREATE INDEX IDX_TAXDECL ON TAXDECL (TIPDOC,CODDOC,CODDOC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TAXDECL2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FA10A63F8261C892142875BC99E5A49060E7C7D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TAXDECL2 ON TAXDECL (TIPDOC,CODDOC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_CODDOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0737B08661AA7E3FA13320D74F3DDBA3EF664E3C</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_CODDOC1 ON TMP_LST_FISAIMOB (CODDOC1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_CODIOART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F4AAD6090F9FD60D807E87F1BCACB69599C84E5</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_CODIOART1 ON TMP_LST_FISAIMOB (CODIOART1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_CODMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66AD170A586B507A8A3A0C09C3533BF2C299D138</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_CODMIFIX ON TMP_LST_FISAIMOB (CODMIFIX) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_CODMIFIX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37926D8FC223D942D7F3A05FF896E222CDD6E260</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_CODMIFIX1 ON TMP_LST_FISAIMOB (CODMIFIX1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_CODOPERATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2737E8C5310906714B41C963DA655F9FF5AA96E0</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_CODOPERATIE ON TMP_LST_FISAIMOB (CODOPERATIE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_DATADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>121D064A2CADC23DE6F513123364F368DC377EBF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_DATADOC ON TMP_LST_FISAIMOB (DATAOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_IMBUNATATIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6651470BEB1F23C99CB309E7CA2ACB8FED821061</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_IMBUNATATIRE ON TMP_LST_FISAIMOB (IMBUNATATIRE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_MF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70A434CA30FE26CDB38E96F7CEF3CCA685C336A5</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_MF ON TMP_LST_FISAIMOB (MF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_ORDINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70317EE40C1EED52957D637767EF5FC9555F2D8C</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_ORDINE ON TMP_LST_FISAIMOB (ORDINE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPFISA_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E838A0B1DE9131F9410DDCB1A2B2F35D122C44DF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPFISA_USERID ON TMP_LST_FISAIMOB (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPGENERAL_CODGENERAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FAC4D79BA571A24C60C5E5BEAE65E1B89A716B29</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPGENERAL_CODGENERAL ON TMP_GENERAL (CODGENERAL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPIESPINI_CODCMDPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5480261E37A5649BF5A8E5CBB96E5E6E4205EB78</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPIESPINI_CODCMDPRODMAT ON TMP_IESPRODLINK_INITIAL (CODCMDPRODMAT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPIESPINI_CODIES1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3B19BF455481C5A660C600256DE8E9E621B8941F</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPIESPINI_CODIES1 ON TMP_IESPRODLINK_INITIAL (CODIES1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPIOARTLUNA_CODIOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F400083E2A41F162BA9AA109E5278BA7F4322781</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPIOARTLUNA_CODIOART ON TMP_IOART_LUNA (CODIOART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPLIVR1_CODLIVR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>773284E2E9EE674E5C7A64E7A0F2A6B2DE17C524</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPLIVR1_CODLIVR1 ON TMP_LIVR1 (CODLIVR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPNARTLUNA_CODARTICOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB4E4A115104B3AD465C69F7BB97362950BB45D5</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPNARTLUNA_CODARTICOL ON TMP_NART_LUNA (CODARTICOL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPNARTLUNA_CODTVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C8EF2F9ACF25E428F1B08AF031D4036765B464A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPNARTLUNA_CODTVA ON TMP_NART_LUNA (CODTVA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPNATROBJ_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8581769ADD713C50C81107D8DFFF89AD62E69CE3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPNATROBJ_CODOBIECT ON TMP_NATROBJ (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMPSTINGERE_CODSTINGERE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C94EA046671170D3AFD9CEF0A5A21CC01798DC6</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMPSTINGERE_CODSTINGERE ON TMP_STINGERE (CODSTINGERE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_AL_CURSLINIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3EABB01B10B8651DAE5B923515A9CFC7E0234CFB</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_AL_CURSLINIE ON TMP_AL_CURSLINIE (AL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_AL_REFRESH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B8DB91EF082284446CDAEC558DE7E402F5A1B531</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_AL_REFRESH ON TMP_AL_REFRESH (COD) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_ANLUNA_VAL_AL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>849E39F4D38A291F9C5BC08D731F6B098313D999</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_ANLUNA_VAL_AL ON TMP_ANLUNA_VAL (AL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_ANLUNA_VAL_VALOARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>681D4120E0240AAB0A94DD27BEB1137DFBCCCDF8</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_ANLUNA_VAL_VALOARE ON TMP_ANLUNA_VAL (VALOARE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_APROVIZ_PART_LOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FA2F51AEEFD31F9A21B181A8DA62AED9E0C3974B</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_APROVIZ_PART_LOC ON TMP_APROVIZ_PART (CODLOCATIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_APROVIZ_PART_OBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>21F0EF351B7D65237AD39BC9B61515261EA53858</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_APROVIZ_PART_OBJ ON TMP_APROVIZ_PART (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_AUX_STINGATORI_S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ED56C4DEF5274649626A97DF3D62EAFAB1DA51E3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_AUX_STINGATORI_S ON TMP_AUX_STINGATORI (CODSTINSPIF,TIPDOCS,CODDOCS) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CAMERE_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CB5FB4D2D3BA70A3F17D7689719D9817099FE697</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CAMERE_LST ON TMP_CAMERE_LST (CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95961E336B316FFDFFC7768977FF8C6619F3040E</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD ON TMP_CMD (USERID,TIP,CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C66D16D7F9502B7D4E132A0DA5173A7E7C580E70</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD1_CODOBIECT ON TMP_CMD1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD1_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B0FAD6992FD631B7B7A1C68006F99FD97D2B37A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD1_TIP ON TMP_CMD1 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD1_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>896C5780DB7FFA215B1814B99D01316A6659A047</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD1_USERID ON TMP_CMD1 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C51EC452ACB02EF120BBD671AA19F4A16E16A8C</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD2_CODOBIECT ON TMP_CMD2 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD2_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DFCBDE6BAD5C040F07572456B8D8E401F8255E0</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD2_TIP ON TMP_CMD2 (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD2_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A4C0A44D3AA6EB4B42F43F59CBBF317CDF74309</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD2_USERID ON TMP_CMD2 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMDTL_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7110C988878982E0C539BB21F6056EB48C99D6F</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMDTL_CODOBIECT ON TMP_CMDTL (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMDTL_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0476CB775F71AEA5A9FF41CE2CBCECA7DDACB2C7</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMDTL_TIP ON TMP_CMDTL (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMDTL_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DC28161636BE8946F0BD7BEED3AA2BB2C6902BB</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMDTL_USERID ON TMP_CMDTL (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>678740D40D3E7A44AD2A139709C653A3E93429AC</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_CODOBIECT ON TMP_CMD (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_DURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB3053EFBC660BC95B3CF28691C25F15B0528AC8</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_DURI ON TMP_CMD (D1,D2,D3) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA2_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B1CBE785914025E169BC970E14150E65628CDBD</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA2_CODCOMANDA1 ON TMP_CMD_PLUNA2 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA2_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55D257A6E19AF575B823032E42922759EFF8E802</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA2_CODOBIECT ON TMP_CMD_PLUNA2 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA2_TERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45B32189C7FE532B84481D436E244F4255B28B0B</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA2_TERMEN ON TMP_CMD_PLUNA2 (TERMEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA2_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>123CA9857384DA236A06B054AA69121A2AECB0DB</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA2_USERID ON TMP_CMD_PLUNA2 (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA2_WEEK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFD0A19DF8F50B81096FDCD3AFFEB627F4EF1020</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA2_WEEK ON TMP_CMD_PLUNA2 (WEEK) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A25A8DF817FF66C4F54E81429850EE2F00E9AE90</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA_CODCOMANDA1 ON TMP_CMD_PLUNA (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56F7B47BD93E41D38362759AF839C0AFBB6D5322</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA_CODOBIECT ON TMP_CMD_PLUNA (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA_TERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC0F44660582A86EF9E141BE3F88EC4436DEB842</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA_TERMEN ON TMP_CMD_PLUNA (TERMEN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE61C21A83CAB93CDA330E80467526B9BF60D2E4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA_USERID ON TMP_CMD_PLUNA (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_PLUNA_WEEK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AE4CD62A442BB4C790D6F83AC4D6CFE5D265146</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_PLUNA_WEEK ON TMP_CMD_PLUNA (WEEK) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_TIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E815E7EF30C05410AEC84B1723FA5B7D4FCAD1B</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_TIP ON TMP_CMD (TIP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_TMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B3BAECB8F845378F850B1E4D7AEBBCFA6691CDC3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_TMP ON TMP_CMD_TMP (CODOBIECT,TIP) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_TMP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F99C513B5A8C50BFCF407062D68C88E0D4FE7075</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_TMP1 ON TMP_CMD_TMP1 (COD1,VAL,COD2) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CMD_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>485FA46FEB98CF5ED91C18A66F48FD8A5A3A9FF4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CMD_USERID ON TMP_CMD (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CONSTVALPOS_CCONSTLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E0758E59167F67222EE082905AA051AA094BCDA4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CONSTVALPOS_CCONSTLUNA ON TMP_CONSTVALPOS (CODCONSTLUNA,IDX) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_CONSTVAL_CODCONSTLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2A6D385196C0358A75E0C56D6A86263258E26E6</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_CONSTVAL_CODCONSTLUNA ON TMP_CONSTVAL (CODCONSTLUNA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_DOC_DIRTY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A23DF823CC28CD78B568DDF928F2247BF02FE41</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_DOC_DIRTY ON TMP_DOC_DIRTY (TIPDOC,CODDOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INTRARI1_CODINTR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CD6D8C78E1A11F66C962B00ABB79DFF4C5C55BCD</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INTRARI1_CODINTR1 ON TMP_INTRARI1 (CODINTR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INTRASTAT_NC_OBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>337E0556AD6690C65D66F8F24E7F07B49D03FB59</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INTRASTAT_NC_OBJ ON TMP_INTRASTAT_NC_OBJ (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INV1_CODINVENTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB54BCBAF64205288E726B8FAFC7DE6C9353247A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INV1_CODINVENTAR ON TMP_INVENTAR1 (CODINVENTAR) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INV1_CODIOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A1D10D938FA3D66357C9330C29FF8E81AE03C059</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INV1_CODIOART ON TMP_INVENTAR1 (CODIOART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INV1_CODLOCATIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ED08F7473BED99299F397EAF9F97E4F9CF255B87</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INV1_CODLOCATIE ON TMP_INVENTAR1 (CODLOCATIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INV1_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0151D64EEB05AF53F31A8B48F5C412FB07443069</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INV1_CODOBIECT ON TMP_INVENTAR1 (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INV1_CODSERIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BDAD290E784D134967FC670A2129CC507080BC09</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INV1_CODSERIE ON TMP_INVENTAR1 (CODSERIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4C4AC5C2AA9F2E93E8BAA0A3CDB14D4CC63605BB</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODGEST ON TMP_INVENTREZ (CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODINVENTAR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1D3A0341AA7F5BA15CF2D0AE09F852EA99DCF109</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODINVENTAR1 ON TMP_INVENTREZ (CODINVENTAR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODIOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D4E53EE09D8191B2AB8B101AD9B759BBAC98FA5C</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODIOART ON TMP_INVENTREZ (CODIOART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODLOCATIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>29E89322AF8570C04F60EA17BCC6DF5783D19A86</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODLOCATIE ON TMP_INVENTREZ (CODLOCATIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODNIRSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BC66BA6774EF7AF29094715E0E5C8C4EB79BEA05</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODNIRSER ON TMP_INVENTREZ (CODNIRSER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODNIRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6402A799242EB5BED7E0B5824F6CBF5FAF1B4203</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODNIRSTOC ON TMP_INVENTREZ (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVR_CODPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3D16473A2079BE3719A266B58B3AAE405CC06752</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVR_CODPART ON TMP_INVENTREZ (CODPART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVS_CODINVENTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9403C950276A1BF428AE61BD5E387FA77C70E82D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVS_CODINVENTAR ON TMP_INVENTSTOC (CODINVENTAR) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVS_CODINVENTAR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>82B67000518DC66850BFB295EBDEA13974E6F09D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVS_CODINVENTAR1 ON TMP_INVENTSTOC (CODINVENTAR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVS_CODNIRSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E80448208C94D9056F013D3CFD3D3C8C4EE5EE4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVS_CODNIRSER ON TMP_INVENTSTOC (CODNIRSER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_INVS_CODNIRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>631BDE39384FBF3D511814310C7B6D2B1DCBCCFF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_INVS_CODNIRSTOC ON TMP_INVENTSTOC (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_KM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB0D902DAAB7082B156A49DE2728F363CC3F7F07</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_KM1 ON TMP_KM1 (CODNPARCAUT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LANSZ1_CODFORMATIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10843856CD4C82DCF500EA94FABE30DB57C40639</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LANSZ1_CODFORMATIE ON TMP_LANSZ1 (CODFORMATIE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LANSZ1_CODLANSZ1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DED09848D3BCA86F387E65C335C204DDC698AD49</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LANSZ1_CODLANSZ1 ON TMP_LANSZ1 (CODLANSZ1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LANSZ1_CODRETETA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BC887122E382CE7935388A3650CB4D112FB1B0FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LANSZ1_CODRETETA ON TMP_LANSZ1 (CODRETETA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LANSZ1_OBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4C26C1690A4FB39FF7E4915AC3D039BA3E336C46</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LANSZ1_OBJ ON TMP_LANSZ1 (CODOBIECT,CODLANSZ) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LANSZ1_SCHIMB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>38851CC162D6C17F1D63D387C3DF8D85024A0035</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LANSZ1_SCHIMB ON TMP_LANSZ1 (SCHIMB) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LIST_BALANTA_BRUT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>89166466D97444EE5C92D20D88FCF97CCC066431</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LIST_BALANTA_BRUT ON TMP_LIST_BALANTA_BRUT (CODCOMUN) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_EUDR_CODLIVR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BE1F36286A9D63DAF31BE8508B64EFCDA44E02F5</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_EUDR_CODLIVR1 ON TMP_LST_EUDR (CODLIVR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_EUDR_CODNIRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A7854551C7F15099876B00A911F852A412201F1D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_EUDR_CODNIRSTOC ON TMP_LST_EUDR (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_FM_SI2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>104D31F0243939075653424F087FE7FF2787C63D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_FM_SI2 ON TMP_LST_FM_SI2 (CODOBIECT,CODIOART,CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_SCAD_PARTVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C73C8B70FA5C64E02AE52F64A8FD5A2BE438E535</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_SCAD_PARTVAL ON TMP_LST_SCAD_PARTVAL (PARTENER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_SCAD_SERTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>741CDB6EBB0DEDEE47049C7DA6D855437C3CA187</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_SCAD_SERTAR ON TMP_LST_SCAD_SERTAR (CODOBLIGPIF) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_SCAD_STINS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B70AB724220DA5E2537A294332979D7DA0B4D876</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_SCAD_STINS ON TMP_LST_SCAD_STINS (CODSTINSPIF) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_STINGATORI_O</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F62A5530396A46AD9F6B686C6F94998569619463</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_STINGATORI_O ON TMP_LST_STINGATORI (CODOBLIGPIF) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_STINGATORI_S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B735BC74190E81943841F9CBFA8C92DCF105F748</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_STINGATORI_S ON TMP_LST_STINGATORI (CODSTINSPIF) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>861BD8E81DBF6BAC5293947F225DD5AEE94B0334</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOP ON TMP_LST_TOP (CODPART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOPART_CODFURN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6B7138C6D78ADAC2FCEF0A8E8B577BFDD2472899</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOPART_CODFURN ON TMP_LST_TOPART (CODFURN) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOPART_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>56F9DA610BBE93E81EE1B39DA356A0854B22B9A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOPART_CODOBIECT ON TMP_LST_TOPART (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOPART_DATADOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8800912148C0DE9BAF1B9083308313A15362B882</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOPART_DATADOC ON TMP_LST_TOPART (DATADOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOPART_TIPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>35CFB98D08313D8D735ED9FD445F3BEDBA4C091D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOPART_TIPART ON TMP_LST_TOPART (TIPARTICOL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_TOPART_TIPFURN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B88B7EEE31654552E513A9271CB6124EF054A72A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_TOPART_TIPFURN ON TMP_LST_TOPART (TIPFURN) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_LST_VALACHIZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>142B175A6A4252F9F8645B6D80B563EA10A9309F</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_LST_VALACHIZ ON TMP_LST_VALACHIZ (CODLIVR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9D8C3BF09CABA2B2E9E7F7C8DE6962346E16A899</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MANEVRA ON TMP_MANEVRA (CODUNIC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MANEVRA2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B8FE6FBFF8D43A6283E24E9FCB578EA17701D82</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MANEVRA2 ON TMP_MANEVRA2 (CODUNIC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MANEVRA3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>21251775349FB512E960028C465D889DE1AA43A4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MANEVRA3 ON TMP_MANEVRA3 (CODUNIC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MANEVRA_LISTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62C0DA285FB4DF1EB7FB7D6014430DF171D92884</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MANEVRA_LISTE ON TMP_MANEVRA_LISTE (FILTRU,VALOARE) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MANPRETM_OBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DB2814D646A254019044ED5B0B6EFC3FD88F77DD</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MANPRETM_OBJ ON TMP_MANPRETM (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MEDEX1_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4D8547501D016E5712ED456D6C99A6A4BB5C502E</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MEDEX1_LST ON TMP_MEDEX1_LST (CODCIM) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_MLINC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B5A73F3D17E558E922A794BE14358D03E4CA7833</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_MLINC ON TMP_MANEVRA_LINIICOMENZI (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NARTATR_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FFFEFBD5293D6120C9F560280D83554F323C582D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NARTATR_LST ON TMP_NARTATR_LST (CODARTICOL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NARTCLI_CODOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FEC3A257366457551FCFE72C2D4B64F1C76F18F3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NARTCLI_CODOBIECT ON TMP_NARTCLI (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NARTOBJSUBUNIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78E331EAF2329A5667870EF5EEA3D19DF3D251C9</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NARTOBJSUBUNIT ON TMP_NARTOBJSUBUNIT (CODOBIECT,SUBUNITATE,CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NIRSTOC_CODINTR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>28A14999C672E48148F21E80E75DDEC3A8A39327</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NIRSTOC_CODINTR1 ON TMP_NIRSTOC (CODINTR1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NIRURI_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6DCFD9A4BDE88F3622F848F1639B31D3E11A97D4</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NIRURI_LUNA ON TMP_NIRURI_LUNA (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NIRURI_SER_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>778A9FA846B3096126771356AB3A092E591E54AA</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NIRURI_SER_LUNA ON TMP_NIRURI_SER_LUNA (CODNIRSER,CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_CODCMD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4F63AE2E3372BCCDC531A7304CD483C478DF266</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_CODCMD1 ON TMP_NIRSTOC1 (CODCOMANDA1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_CODNS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>57C860022FE3E79DC5685ED027D35D1D40153BD3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_CODNS ON TMP_NIRSTOC1 (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_CODNSO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>09C50E9E19F642EFC09F88947C2F16AAC3B47367</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_CODNSO ON TMP_NIRSTOC1 (CODNIRSTOCORIG) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_DINSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2EDDF4AC0346A3F6E27D9295B206F81368F0640D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_DINSTOC ON TMP_NIRSTOC1 (DINSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_DIRTY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>26A0CECDCE2B8012458E8385023C5F626D2FAD56</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_DIRTY ON TMP_NIRSTOC1 (DIRTY) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_MAN_AN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AE712FE81844E4DFF4247DA954C4123C9D530445</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_MAN_AN ON TMP_NIRSTOC1_MAN (AN) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_MAN_CODNS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>631334FF1A33EB858DF41D642722E9C387A51CC8</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_MAN_CODNS ON TMP_NIRSTOC1_MAN (CODNIRSTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_MAN_CODNSO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6873980ABFA9E989592D67861B284DA9FA75C876</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_MAN_CODNSO ON TMP_NIRSTOC1_MAN (CODNIRSTOCORIG) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_MAN_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F53CE252B31DDFED36FFF3ED4D42DF8D9640B1BF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_MAN_LUNA ON TMP_NIRSTOC1_MAN (LUNA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NS1_TIPDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7E1FE21B214E492501D4B7C5322F7B4E58C1FCD3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NS1_TIPDOC ON TMP_NIRSTOC1 (TIPDOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_NTVALUNA_CODTVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51AF2984DE3613A9FA9B091776517B9B272D5B6D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_NTVALUNA_CODTVA ON TMP_NTVA_LUNA (CODTVA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_OFERTA_CODFISCAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1FA73EBAB4B63E28473900620332382B6A9E65F3</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_OFERTA_CODFISCAL ON TMP_OFERTA (CODFISCAL) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_OFERTA_CODOFERTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2D5B4880F96847D5AE2A55A3C5640EB8F95E3232</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_OFERTA_CODOFERTA ON TMP_OFERTA (CODOFERTA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_OFERTA_PARTENER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7AAAA2C38B2D769D00D6E7C03BFBC57A46EE3C5D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_OFERTA_PARTENER ON TMP_OFERTA (PARTENER) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_PLANIFCMDMAT_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9E2DE4E133BDE423CE8CF55B33A729B6406F519</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_PLANIFCMDMAT_CODOBIECT ON TMP_PLANIFCMDMAT (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_PLANIFCMDMAT_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7EC01EC0BB48E43CEAC999341F41A86DFAF2059</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_PLANIFCMDMAT_USERID ON TMP_PLANIFCMDMAT (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_PLUNA_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FCAD1B0EB476BE0315865FAF94ECE084AA08F0CF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_PLUNA_CODOBIECT ON TMP_PLUNA (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_PLUNA_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40F94331E612A21046400D77C3402AD3ACD8A8BA</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_PLUNA_USERID ON TMP_PLUNA (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_PRETM_CODPRETM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FB3C069FF17DC8C04279D607A1F9525A7868071B</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_PRETM_CODPRETM ON TMP_PRETM (CODPRETM) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_RAPSTOCMED_NAO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F65D83137FA055FA0298C2987155A42C058F287</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_RAPSTOCMED_NAO ON TMP_RAPSTOCMED_NAO (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_RAPSTOCMED_SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>85156E628F52D05C13D0635B7CAB3FE60276F9C2</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_RAPSTOCMED_SUB ON TMP_RAPSTOCMED_SUB (CODSUBUNIT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SAFT_CC4426</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A914308ECCD489C3D7778B80F5F8D68CAEE1743</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SAFT_CC4426 ON TMP_SAFT_CC4426 (CODCONT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SAFT_NPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E0846F22A7AADAA815EBE6707562F34B85FEB1AD</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SAFT_NPART ON TMP_SAFT_NPART (CODPART,ICONT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SAFT_NPARTDET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>57876BB2248403B432EDF4727BC1A9BF45894B29</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SAFT_NPARTDET ON TMP_SAFT_NPARTDET (CODPART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SDG_CODGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B74973817E72D6F93AF5DD3554E588345CD9B42</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SDG_CODGEST ON TMP_STOC_DATA_GEST (CODGEST) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SDG_CODIOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A4EBC2651405F045A7E6F96138BCF72C2E4CCE3D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SDG_CODIOART ON TMP_STOC_DATA_GEST (CODIOART) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SDG_DATASTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4C86CF87B1B5825A1E5B52FABFDC1D68FBEB42EA</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SDG_DATASTOC ON TMP_STOC_DATA_GEST (DATASTOC) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SE1_CENTR_CODSTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00FC675106D57D73BF91A4B43BEC0F94AE2E94DA</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SE1_CENTR_CODSTARE ON TMP_STAREESTIMARI1_CENTR (CODSTARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SE1_CENTR_CODSTARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71FDA0D3B108625B5815AF0CDC534648D6ABBE5B</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SE1_CENTR_CODSTARE1 ON TMP_STAREESTIMARI1_CENTR (CODSTARE1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SE1_CENTR_USERID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C682683990EECF75E095952EC70A1CDCB70982A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SE1_CENTR_USERID ON TMP_STAREESTIMARI1_CENTR (USERID) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SOLDPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2D8BD8D03C6582D6A55F7FC7096DC88E9D211569</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SOLDPERS ON TMP_SOLDPERS (CODPERS,ICONT,CODMONEDA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_SOLDPERS_SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FFF9B2F3DF14F134D7D383308D8D8BC1644DCC0A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_SOLDPERS_SUB ON TMP_SOLDPERS_SUB (CODPERS,ICONT,CODMONEDA,SUBUNITATEA) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_STOCREAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2E2C345C579D7BF5B0EB990800F0BDB81EFDA54D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_STOCREAL ON TMP_STOCREAL (CODOBIECT,TIP) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TMP_STOCREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3F40D203DAE25AB9453173CDB87F29EC4E24264D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TMP_STOCREZ ON TMP_STOCREZ (CODOBIECT) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSACARD_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82A632DDDED763096DA454C96C4728A298C0FC85</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSACARD_CODEMULARE ON TRANSACARD (CODEMULARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D505E62146AD79A65B2F663EE97703A75B034F0</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF ON TRANSF (AN,LUNA,OPERAT,ANULAT,TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF1_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEC85D2DBF612E31CED91FBCE57F19C09290BE6D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF1_CODOBIECT ON TRANSF1 (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF1_CODTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B77887CDAF53D0B47329395B8AE93AEACCA605DA</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF1_CODTRANSF ON TRANSF1 (CODTRANSF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF1_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93FA7FED8FB4157977919DE85E44CBC2AB7D0677</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF1_UMSEC ON TRANSF1 (UMSEC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSFLINK_CODLINIECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BB50BBAC6B09710C22D3B33AA06314307658A6D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSFLINK_CODLINIECOMANDA ON TRANSFLINK (CODLINIECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSFLINK_CODTRANSF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6610C04AD7BA32422394F45E1D70EEA40CD954A</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSFLINK_CODTRANSF1 ON TRANSFLINK (CODTRANSF1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF_CONTSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EB4C708C7EF0BC515DF48E30350A42AAE636033</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF_CONTSUPLIM ON TRANSF (CONTSUPLIM) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TRANSF_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20EEA7D5F1D57567A60F12F8D33FD61769164B7E</HASHVAL>
  <TEXT>CREATE INDEX IDX_TRANSF_SUBUNITATEA ON TRANSF (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TREZOR1_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2054942F44AB6068A7759D208AE2D0911DD3FC5E</HASHVAL>
  <TEXT>CREATE INDEX IDX_TREZOR1_CODPART ON TREZOR1 (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TREZOR1_CODTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>312A0C38BF88622758AC4BF570056748BA8494C5</HASHVAL>
  <TEXT>CREATE INDEX IDX_TREZOR1_CODTREZOR ON TREZOR1 (CODTREZOR) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TREZOR_CODBANCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>274CADEEE9CBFD13AC102661A795A072F0544C7D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TREZOR_CODBANCA ON TREZOR (CODBANCA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TREZOR_SUBUNITATEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBFAD9E0E51ED52B5B44B3262C703725163F7933</HASHVAL>
  <TEXT>CREATE INDEX IDX_TREZOR_SUBUNITATEA ON TREZOR (SUBUNITATEA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TREZOR_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D628587F9693664242B8F8619E21D8A6B4CB5C94</HASHVAL>
  <TEXT>CREATE INDEX IDX_TREZOR_TIPDOC ON TREZOR (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TVASERV1_AL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA244FF38B4B26F6F5B53DA4F71AC5C56E6701BF</HASHVAL>
  <TEXT>CREATE INDEX IDX_TVASERV1_AL ON TVASERV1 (CODTVASERV,ALSTART,ALSTOP) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TVASERV1_ANLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99C8B44262434D4D11344D085D8B56D38A416973</HASHVAL>
  <TEXT>CREATE INDEX IDX_TVASERV1_ANLUNA ON TVASERV1 (&quot;ANSTART&quot;*12+&quot;LUNASTART&quot;) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_TVASERV1_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97DFA2B2F9DA280AE9FADB51BB33C9323A4FD41D</HASHVAL>
  <TEXT>CREATE INDEX IDX_TVASERV1_CODCONT ON TVASERV1 (CODCONT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UT20MON_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E6E346845CE4205000F9DC9738110D83957B2A7</HASHVAL>
  <TEXT>CREATE INDEX IDX_UT20MON_CODUTILAJ ON UTILAJE20_MON (CODUTILAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UT20MON_CODUTILAJ20</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AB61B33B5C663CD421916F9CDC2BA54E87D540B</HASHVAL>
  <TEXT>CREATE INDEX IDX_UT20MON_CODUTILAJ20 ON UTILAJE20_MON (CODUTILAJ20) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE20_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A6BE2DD10F11BA4980D3F76F2356C34B466C7E40</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE20_CODUTILAJ ON UTILAJE20 (CODUTILAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2C_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53D9319076C692B0CDDBE00D910E3C0DF84DC0FE</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2C_CODCOMANDA1 ON UTILAJE2C (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2C_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA1F7F6696D4469F7472F2312F218D0C322AAB17</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2C_CODUTILAJ ON UTILAJE2C (CODUTILAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2C_CODUTILAJ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>587DE01F99E24CE29AD187D6FCEDEC81B8E37563</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2C_CODUTILAJ2 ON UTILAJE2C (CODUTILAJ2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2P_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D8A93B7772546A965745B0E9258CC7C77D5D34A</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2P_CODPERS ON UTILAJE2P (CODPERS) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2P_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>401741305B13886EF55EA61254F076014F970A8C</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2P_CODUTILAJ ON UTILAJE2P (CODUTILAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJE2P_CODUTILAJ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC67FDBD308A14E16DB74055F0C2E09EEE79D7AD</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJE2P_CODUTILAJ2 ON UTILAJE2P (CODUTILAJ2) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJEDEV_CODIES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15853F354C36637147A1FBE9CD0E53D9D94C5D62</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJEDEV_CODIES1 ON UTILAJEDEV (CODIES1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJEDEV_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>779EF17687B142B14D1A6409A165C54CADA68F34</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJEDEV_CODOBIECT ON UTILAJEDEV (CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJEDEV_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCD2F9E5EAD87C2FAE7F9C8B6B092B9297A93B0D</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJEDEV_CODUTILAJ ON UTILAJEDEV (CODUTILAJ) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJEDEV_CODUTILAJ20</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>190F97C15B6DB272635DA761C483151465F4AF57</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJEDEV_CODUTILAJ20 ON UTILAJEDEV (CODUTILAJ20) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_UTILAJEMON_CODUTILAJ20</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49F62198187186C9FA24BEDC087C181901D5A1EA</HASHVAL>
  <TEXT>CREATE INDEX IDX_UTILAJEMON_CODUTILAJ20 ON UTILAJEMON (CODUTILAJ20) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_VANZARI_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DC4788B6A8657F7C676379785CD845582711A3E</HASHVAL>
  <TEXT>CREATE INDEX IDX_VANZARI_CODEMULARE ON VANZARI (CODEMULARE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_VANZARI_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF579599983EE08136D68AA8BE5818D8FD188857</HASHVAL>
  <TEXT>CREATE INDEX IDX_VANZARI_CODPART ON VANZARI (CODPART) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_VOUCHERCADOULINK_CODDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>941670D0357737D521423B7B155C261948FD058D</HASHVAL>
  <TEXT>CREATE INDEX IDX_VOUCHERCADOULINK_CODDOC ON VOUCHERCADOULINK (CODDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_VOUCHERCADOULINK_TIPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F4DF7DA0F5A37BB8F528D0E0247E627DBBFEEFA</HASHVAL>
  <TEXT>CREATE INDEX IDX_VOUCHERCADOULINK_TIPDOC ON VOUCHERCADOULINK (TIPDOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_VOUCHERCADOU_BARCODE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5F4963195DD3CB8BAE13DA3830CB9A55F26A6C3</HASHVAL>
  <TEXT>CREATE INDEX IDX_VOUCHERCADOU_BARCODE ON VOUCHERCADOU (BARCODE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_WEEKCASHFLOW1_CODCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C104392DA07C701BEDDFDBB97A676CD70250880A</HASHVAL>
  <TEXT>CREATE INDEX IDX_WEEKCASHFLOW1_CODCASHFLOW ON WEEKCASHFLOW1 (CODCASHFLOW) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_WEEKCASHPLATI_CODCASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>824EC1E3B0611346AF090269462ED80D0BD55B8C</HASHVAL>
  <TEXT>CREATE INDEX IDX_WEEKCASHPLATI_CODCASHFLOW1 ON WEEKCASHPLATI (CODCASHFLOW1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IDX_ZINELUC1_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F364216511C33C33EE658563DEA1274E6054009</HASHVAL>
  <TEXT>CREATE INDEX IDX_ZINELUC1_DATA ON ZINELUC1 (DATA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>IESPRODLINK_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AFB57290001AEB8A8376AB94ACF25149CC7358C</HASHVAL>
  <TEXT>CREATE INDEX IESPRODLINK_CMD ON IESPRODLINK (CODCMDPRODMAT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>INTRPRODLINK_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3157C5CC7EB61BF37A151E1E67A2BE3DD0F23BB</HASHVAL>
  <TEXT>CREATE INDEX INTRPRODLINK_CMD ON INTRPRODLINK (CODLINIECOMANDA) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>NATROBJ_FK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>585846C48FE5DF8688266A179552E2C110179393</HASHVAL>
  <TEXT>CREATE INDEX NATROBJ_FK ON NATROBJ (CODATROBJ,CODOBIECT) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>NIRSTOC1_CK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88ED45B0BEDAE7EFB1D91214F8CFB305AFEEAF75</HASHVAL>
  <TEXT>CREATE INDEX NIRSTOC1_CK ON NIRSTOC1 (CODCOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>NIRSTOC1_OK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3113F1C94FF3E0565C9E0BF6886C7AA114F741E</HASHVAL>
  <TEXT>CREATE INDEX NIRSTOC1_OK ON NIRSTOC1 (CODNIRSTOCORIG) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>NPARC2_CODNPARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9194AA8226BDCE8863173FBCD20682B1764D7B5D</HASHVAL>
  <TEXT>CREATE INDEX NPARC2_CODNPARCAUT ON NPARC2 (COD) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PACHETEOBJL_CODLIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B03630BBF5BD6687DD47093D32443436010C1DA3</HASHVAL>
  <TEXT>CREATE INDEX PACHETEOBJL_CODLIVR1 ON PACHETEOBJL (CODLIVR1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PACHETEOBJL_CODPACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14D271A97ED6E4A8311F2D232E78502A4CAAD5C5</HASHVAL>
  <TEXT>CREATE INDEX PACHETEOBJL_CODPACHETE ON PACHETEOBJL (CODPACHETE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PACHETEOBJ_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>774E9CC6014A6C48F1C3A644B5077C3949410B80</HASHVAL>
  <TEXT>CREATE INDEX PACHETEOBJ_CODNIRSTOC ON PACHETEOBJ (CODNIRSTOC) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PACHETEOBJ_CODPACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F703963805D8D5E08E32C8BCB358E5EF8A40F1D7</HASHVAL>
  <TEXT>CREATE INDEX PACHETEOBJ_CODPACHETE ON PACHETEOBJ (CODPACHETE) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PRECMDLINK_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76A20E49F766C5406E20405FCC0CEBFBE3A8F5CA</HASHVAL>
  <TEXT>CREATE INDEX PRECMDLINK_CMD ON PRECMDLINK (CODPRECOMANDA1) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PROGRAMFMAN_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1017C367DFAAA72D4272298FF2B1966BC65225B</HASHVAL>
  <TEXT>CREATE INDEX PROGRAMFMAN_CODCMDPRODMAT ON PROGRAMFMAN (CODCMDPRODMAN) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>PROGRAMFMAN_CODPROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C2CF0AFF86FCCF285ADB3076870F4A979B8310D</HASHVAL>
  <TEXT>CREATE INDEX PROGRAMFMAN_CODPROGRAMF ON PROGRAMFMAN (CODPROGRAMF) TABLESPACE WMINDX</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>INDEX</TYPE>
  <NAME>TMP_IESLINK_IDX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6173896DE3ADD8E6F189C8DC643046FA3FB6165F</HASHVAL>
  <TEXT>CREATE INDEX TMP_IESLINK_IDX ON TMP_IESLINK (CODIES1) </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>ORA_EXCEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B7D59E5627ECEDBECBC6B4E1DE7F4BEECF402EB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE ORA_EXCEL IS

   /*
    *  ORAEXCEL version 2.0.39
    *  Documentation and examples available on http://www.oraexcel.com/documentation
    *
    */

    /***************************************************************************
    *
    * ORA_EXCEL COPYRIGHT AND LEGAL NOTES
    *
    * This software is protected by International copyright Law. Unauthorized use,
    * duplication, reverse engineering, any form of redistribution, or use in part
    * or in whole other than by prior, express, printed and signed license for use
    * is subject to civil and criminal prosecution. If you have received this file
    * in error, please notify copyright holder and destroy this and any other copies
    * as instructed.
    *
    * END-USER LICENSE AGREEMENT FOR ORA_EXCEL IMPORTANT PLEASE READ THE TERMS AND
    * CONDITIONS OF THIS LICENSE AGREEMENT CAREFULLY BEFORE CONTINUING WITH THIS
    * PROGRAM INSTALL: ORA_EXCEL End-User License Agreement (&quot;EULA&quot;) is a legal
    * agreement between you (either an individual or a single entity) and ORA_EXCEL.
    * For the ORA_EXCEL software product(s) identified above which may include
    * associated software components, media, printed materials, and &quot;online&quot; or
    * electronic documentation (&quot;ORA_EXCEL&quot;). By installing, copying, or otherwise
    * using the SOFTWARE PRODUCT, you agree to be bound by the terms of this EULA.
    * This license agreement represents the entire agreement concerning the program
    * between you and ORA_EXCEL, (referred to as &quot;licenser&quot;), and it supersedes any
    * prior proposal, representation, or understanding between the parties. If you
    * do not agree to the terms of this EULA, do not install or use the SOFTWARE PRODUCT.
    *
    * The SOFTWARE PRODUCT is protected by copyright laws and international copyright
    * treaties, as well as other intellectual property laws and treaties.
    * The SOFTWARE PRODUCT is licensed, not sold.
    *
    * 1. GRANT OF LICENSE.
    * The SOFTWARE PRODUCT is licensed as follows:
    * (a) Installation and Use.
    * ORA_EXCEL grants you the right to install and use copies of the SOFTWARE PRODUCT
    * on your computer running a validly licensed copy of the operating system for which
    * the SOFTWARE PRODUCT was designed.
    * (b) Backup Copies.
    * You may also make copies of the SOFTWARE PRODUCT as may be necessary for backup
    * and archival purposes.
    *
    * 2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS.
    * (a) Maintenance of Copyright Notices.
    * You must not remove or alter any copyright notices on any and all copies of the
    * SOFTWARE PRODUCT.
    * (b) Distribution.
    * You may not distribute registered copies of the SOFTWARE PRODUCT to third parties.
    * Evaluation versions available for download from ORA_EXCEL&apos;s websites may be freely
    * distributed.
    * (c) Prohibition on Reverse Engineering, Decompilation, and Disassembly.
    * You may not reverse engineer, decompile, or disassemble the SOFTWARE PRODUCT,
    * except and only to the extent that such activity is expressly permitted by
    * applicable law notwithstanding this limitation.
    * (d) Rental.
    * You may not rent, lease, or lend the SOFTWARE PRODUCT.
    * (e) Support Services.
    * ORA_EXCEL may provide you with support services related to the SOFTWARE PRODUCT
    * (&quot;Support Services&quot;). Any supplemental software code provided to you as part of
    * the Support Services shall be considered part of the SOFTWARE PRODUCT and subject
    * to the terms and conditions of this EULA.
    * (f) Compliance with Applicable Laws.
    * You must comply with all applicable laws regarding use of the SOFTWARE PRODUCT.
    * 3. TERMINATION
    * Without prejudice to any other rights, ORA_EXCEL may terminate this EULA if you
    * fail to comply with the terms and conditions of this EULA. In such event, you must
    * destroy all copies of the SOFTWARE PRODUCT in your possession.
    * 4. COPYRIGHT
    * All title, including but not limited to copyrights, in and to the SOFTWARE PRODUCT
    * and any copies thereof are owned by ORA_EXCEL or its suppliers. All title and
    * intellectual property rights in and to the content which may be accessed through
    * use of the SOFTWARE PRODUCT is the property of the respective content owner and
    * may be protected by applicable copyright or other intellectual property laws and
    * treaties. This EULA grants you no rights to use such content. All rights not
    * expressly granted are reserved by ORA_EXCEL.
    * 5. NO WARRANTIES
    * ORA_EXCEL expressly disclaims any warranty for the SOFTWARE PRODUCT.
    * The SOFTWARE PRODUCT is provided &apos;As Is&apos; without any express or implied warranty
    * of any kind, including but not limited to any warranties of merchantability,
    * noninfringement, or fitness of a particular purpose. ORA_EXCEL does not warrant
    * or assume responsibility for the accuracy or completeness of any information,
    * text, graphics, links or other items contained within the SOFTWARE PRODUCT.
    * ORA_EXCEL makes no warranties respecting any harm that may be caused by the
    * transmission of a computer virus, worm, time bomb, logic bomb, or other such
    * computer program. ORA_EXCEL further expressly disclaims any warranty or
    * representation to Authorized Users or to any third party.
    * 6. LIMITATION OF LIABILITY
    * In no event shall ORA_EXCEL be liable for any damages (including, without
    * limitation, lost profits, business interruption, or lost information) rising
    * out of &apos;Authorized Users&apos; use of or inability to use the SOFTWARE PRODUCT,
    * even if ORA_EXCEL has been advised of the possibility of such damages.
    * In no event will ORA_EXCEL be liable for loss of data or for indirect,
    * special, incidental, consequential (including lost profit), or other
    * damages based in contract, tort or otherwise. ORA_EXCEL shall have no
    * liability with respect to the content of the SOFTWARE PRODUCT or any part
    * thereof, including but not limited to errors or omissions contained therein,
    * libel, infringements of rights of publicity, privacy, trademark rights,
    * business interruption, personal injury, loss of privacy, moral rights or
    * the disclosure of confidential information.
    *
    ****************************************************************************/


    -- Declaration of columns widths
    TYPE column_properites_type IS RECORD (column_name VARCHAR2(2),
                                           width NUMBER,
                                           hidden INTEGER DEFAULT 0);
    TYPE column_properites_table IS TABLE OF column_properites_type;
    column_properites_empty column_properites_table := column_properites_table();

    -- Declaration of merged cells type
    TYPE merged_cells_type IS RECORD(merged_cells VARCHAR2(100));
    TYPE merged_cells_table IS TABLE OF merged_cells_type;
    merged_cells_empty merged_cells_table := merged_cells_table();

    -- Declaration of hyperlinks table
    TYPE hyperlinks_type IS RECORD (hyperlink VARCHAR2(1000),
                                    cell VARCHAR2(10));
    TYPE hyperlinks_table IS table OF hyperlinks_type;
    hyperlinks_empty hyperlinks_table := hyperlinks_table();

    TYPE internal_hyperlinks_type IS RECORD (hyperlink VARCHAR2(1000),
                                             cell VARCHAR2(10));
    TYPE internal_hyperlinks_table IS table OF internal_hyperlinks_type;
    internal_hyperlinks_empty internal_hyperlinks_table := internal_hyperlinks_table();


    -- Declaration of comments table
    TYPE comments_type IS RECORD (comment_text VARCHAR2(1000),
                                  author VARCHAR2(30),
                                  box_width NUMBER,
                                  box_height NUMBER,
                                  row_id INTEGER,
                                  column_id INTEGER,
                                  cell VARCHAR2(10));
    TYPE comments_table IS TABLE OF comments_type;
    comments_empty comments_table := comments_table();

    TYPE sheet_buffer_table IS TABLE OF CLOB;
    sheet_buffer_empty sheet_buffer_table := sheet_buffer_table();

     -- Declaration of current cell informations type
    TYPE current_cell_type IS RECORD (cell_name VARCHAR2(20),
                                      cell_type VARCHAR2(1),
                                      cell_value VARCHAR2(100),
                                      format_num_fmt_id PLS_INTEGER := 0,
                                      format_font_id PLS_INTEGER := 0,
                                      format_fill_id PLS_INTEGER := 0,
                                      format_border_id PLS_INTEGER := 0,
                                      format_xf_id PLS_INTEGER := 0,
                                      format_id PLS_INTEGER,
                                      formula VARCHAR2(4000),
                                      bold BOOLEAN := FALSE,
                                      italic BOOLEAN := FALSE,
                                      underline BOOLEAN := FALSE,
                                      color VARCHAR2(8),
                                      bg_color VARCHAR2(8),
                                      horizontal_align VARCHAR2(1),
                                      vertical_align VARCHAR2(1),
                                      null_value BOOLEAN DEFAULT FALSE,
                                      border_top BOOLEAN DEFAULT FALSE,
                                      border_top_style VARCHAR2(6),
                                      border_top_color VARCHAR2(8),
                                      border_bottom BOOLEAN DEFAULT FALSE,
                                      border_bottom_style VARCHAR2(6),
                                      border_bottom_color VARCHAR2(8),
                                      border_left BOOLEAN DEFAULT FALSE,
                                      border_left_style VARCHAR2(6),
                                      border_left_color VARCHAR2(8),
                                      border_right BOOLEAN DEFAULT FALSE,
                                      border_right_style VARCHAR2(6),
                                      border_right_color VARCHAR2(8),
                                      border_style VARCHAR2(10),
                                      border_color VARCHAR2(8),
                                      wrap_text BOOLEAN DEFAULT FALSE,
                                      merge_cells BOOLEAN,
                                      merged_cells_cell_from VARCHAR2(2),
                                      merges_cells_cell_to VARCHAR2(2),
                                      merge_rows PLS_INTEGER,
                                      merge_rows_first BOOLEAN,
                                      cell_format PLS_INTEGER := 0,
                                      rotate_text_degree INTEGER := 0,
                                      indent_left INTEGER := 0,
                                      indent_right INTEGER := 0,
                                      cells_to_add VARCHAR2(4000));
    current_cell_record current_cell_type;
    TYPE current_cell_table_type IS TABLE OF current_cell_type INDEX BY PLS_INTEGER;
    --current_cell current_cell_table_type;
    current_cell_empty current_cell_table_type;

    -- Declaration of sheets type
    TYPE sheets_type IS RECORD (sheet_name VARCHAR2(32),
                                sheet_data CLOB,
                                sheet_data_buffer sheet_buffer_table,
                                last_row_num PLS_INTEGER,
                                top_right_column PLS_INTEGER,
                                column_properites column_properites_table,
                                merged_cells merged_cells_table,
                                merge_rows BOOLEAN DEFAULT FALSE,
                                margins_left NUMBER,
                                margins_right NUMBER,
                                margins_top NUMBER,
                                margins_bottom NUMBER,
                                margins_header NUMBER,
                                margins_footer NUMBER,
                                orientation VARCHAR2(10),
                                paper_size INTEGER,
                                header_text VARCHAR2(1000),
                                footer_text VARCHAR2(1000),
                                hyperlinks hyperlinks_table,
                                internal_hyperlinks internal_hyperlinks_table,
                                comments comments_table,
                                filter_from VARCHAR2(20),
                                filter_to VARCHAR2(20),
                                current_cell current_cell_table_type,
                                row_height NUMBER,
                                hide_row BOOLEAN,
                                freeze_panes_horizontal VARCHAR2(20),
                                freeze_panes_vertical VARCHAR2(20));
    TYPE sheets_table IS TABLE OF sheets_type;
    sheets_empty sheets_table := sheets_table();


    -- Declaration of format masks type
    TYPE format_masks_type IS RECORD(format_mask VARCHAR(60));
    TYPE format_masks_table IS TABLE OF format_masks_type;
    format_masks_empty format_masks_table := format_masks_table();

    -- Declaration of format masks table
    TYPE formats_type IS RECORD (num_fmt_id PLS_INTEGER,
                                font_id PLS_INTEGER,
                                fill_id PLS_INTEGER,
                                border_id PLS_INTEGER,
                                xf_id PLS_INTEGER,
                                horizontal_align VARCHAR2(1),
                                vertical_align VARCHAR2(1),
                                wrap_text BOOLEAN,
                                rotate_text_degree INTEGER,
                                indent_left INTEGER,
                                indent_right INTEGER);
    TYPE formats_table IS table OF formats_type;
    formats_empty formats_table := formats_table();



    -- Declaration of fonts type
    TYPE fonts_type IS RECORD (font_size PLS_INTEGER,
                               font_name VARCHAR2(100),
                               italic BOOLEAN := FALSE,
                               underline BOOLEAN := FALSE,
                               bold BOOLEAN := FALSE,
                               color VARCHAR2(8));
    TYPE fonts_table IS table OF fonts_type;
    fonts_empty fonts_table := fonts_table();

    -- Declaration of fills type
    TYPE fills_type IS RECORD (pattern_type VARCHAR2(10),
                               color VARCHAR2(8));
    TYPE fills_table IS TABLE OF fills_type;
    fills_empty fills_table := fills_table();


    -- Declaration of default font type
    TYPE default_font_type IS RECORD (font_size PLS_INTEGER,
                                      font_name VARCHAR2(100));

    -- Declaration of borders type
    TYPE borders_type IS RECORD (border_top BOOLEAN DEFAULT FALSE,
                                 border_top_style VARCHAR2(6),
                                 border_top_color VARCHAR2(8),
                                 border_bottom BOOLEAN DEFAULT FALSE,
                                 border_bottom_style VARCHAR2(6),
                                 border_bottom_color VARCHAR2(8),
                                 border_left BOOLEAN DEFAULT FALSE,
                                 border_left_style VARCHAR2(6),
                                 border_left_color VARCHAR2(8),
                                 border_right BOOLEAN DEFAULT FALSE,
                                 border_right_style VARCHAR2(6),
                                 border_right_color VARCHAR2(8),
                                 border_style VARCHAR2(10),
                                 border_color VARCHAR2(8));
    TYPE borders_table IS TABLE OF borders_type;
    borders_empty borders_table := borders_table();


    TYPE shared_buffer_table IS TABLE OF CLOB;
    shared_buffer_empty shared_buffer_table := shared_buffer_table();

    TYPE styles_type IS RECORD (style_name VARCHAR2(20),
                                font_name VARCHAR2(100),
                                font_size PLS_INTEGER,
                                formula VARCHAR2(4000),
                                bold BOOLEAN := FALSE,
                                italic BOOLEAN := FALSE,
                                underline BOOLEAN := FALSE,
                                color VARCHAR2(8),
                                bg_color VARCHAR2(8),
                                horizontal_align VARCHAR2(20),
                                vertical_align VARCHAR2(20),
                                border_top BOOLEAN DEFAULT FALSE,
                                border_top_style VARCHAR2(6),
                                border_top_color VARCHAR2(8),
                                border_bottom BOOLEAN DEFAULT FALSE,
                                border_bottom_style VARCHAR2(6),
                                border_bottom_color VARCHAR2(8),
                                border_left BOOLEAN DEFAULT FALSE,
                                border_left_style VARCHAR2(6),
                                border_left_color VARCHAR2(8),
                                border_right BOOLEAN DEFAULT FALSE,
                                border_right_style VARCHAR2(6),
                                border_right_color VARCHAR2(8),
                                border BOOLEAN,
                                border_style VARCHAR2(10),
                                border_color VARCHAR2(8),
                                wrap_text BOOLEAN DEFAULT FALSE,
                                format VARCHAR2(60) := NULL,
                                rotate_text_degree INTEGER := 0,
                                indent_left INTEGER := 0,
                                indent_right INTEGER := 0,
                                column_width INTEGER :=0);


    TYPE styles_table IS TABLE OF styles_type INDEX BY VARCHAR2(50);



    -- Declaration of documents type
    TYPE documents_type IS RECORD (sheets sheets_table,
                                   shared_strings CLOB,
                                   shared_strings_buffer shared_buffer_table,
                                   last_shared_string_num PLS_INTEGER,
                                   format_masks format_masks_table,
                                   formats formats_table,
                                   fonts fonts_table,
                                   default_font default_font_type,
                                   fills fills_table,
                                   borders borders_table,
                                   have_hyperlinks BOOLEAN,
                                   have_internal_hyperlinks BOOLEAN,
                                   author VARCHAR2(1000),
                                   styles styles_table);
    TYPE documents_table IS TABLE OF documents_type;
    documents documents_table;
    documents_empty documents_table := documents_table();

    --  Declaration of indexes
    doc_id PLS_INTEGER := 0;
    current_doc_id PLS_INTEGER;
    current_sheet_id PLS_INTEGER;
    current_row_id PLS_INTEGER;
    initialize_clob CLOB;
    current_cell_number PLS_INTEGER;
    cell_formatted BOOLEAN := FALSE;

    -- Declaration of cache objects
    cache_column_alpha_in PLS_INTEGER;
    cache_column_alpha_out VARCHAR2(20);
    cache_column_number_in VARCHAR2(20);
    cache_column_number_out PLS_INTEGER;

    TYPE line_string_type IS TABLE OF VARCHAR2(32767) INDEX BY PLS_INTEGER;
    line_string line_string_type;

    TYPE shared_strings_buffer_type IS TABLE OF VARCHAR2(32767) INDEX BY PLS_INTEGER;
    shared_strings_buffer shared_strings_buffer_type;

    TYPE sheet_data_buffer_type IS TABLE OF VARCHAR2(32767) INDEX BY PLS_INTEGER;
    sheet_data_buffer sheet_data_buffer_type;

    loaded_document BLOB := EMPTY_BLOB();
    loaded_shared_strings CLOB := EMPTY_CLOB();
    loaded_sheet CLOB := EMPTY_CLOB();

    TYPE cell_value_type IS RECORD(value VARCHAR2(32767),
                                   varchar2_value VARCHAR2(32767),
                                   number_value NUMBER,
                                   date_value DATE,
                                   type VARCHAR2(1));
    loaded_row_id INTEGER;
    loaded_row_string CLOB;
    TYPE loaded_styles_type IS TABLE OF VARCHAR2(1) INDEX BY PLS_INTEGER;
    loaded_styles loaded_styles_type;
    loaded_styles_empty loaded_styles_type;
    loaded_date_system VARCHAR2(4);
    local_charset VARCHAR2(30);
    date_system INTEGER;

    /***************************************************************************
    * Description: Creates new instance of excel document, initializes space
    *  storage and prepares parameters
    *
    * Input Parameters:
    *   - no input parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - doc_id [unique identifier of document]
    *
    ****************************************************************************/
    FUNCTION new_document
    RETURN PLS_INTEGER;
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Wrapper procedure of new_document function
    *
    * Input Parameters:
    *   - no input parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE new_document;
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Adds new sheet to document
    *
    * Input Parameters:
    *   - sheet_name [sheet name that will be displayed on sheet tab]
    *   - doc_id     [unique identificator od document]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - sheet_id  [unique identificator of sheet within document]
    *
    ****************************************************************************/
    FUNCTION add_sheet(sheet_name VARCHAR2,
                       doc_id PLS_INTEGER DEFAULT current_doc_id)
    RETURN PLS_INTEGER;
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Wrapper procedure of add_sheet function
    *
    * Input Parameters:
    *   - sheet_name [sheet name that will be displayed on sheet tab]
    *   - doc_id     [unique identificator of document]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE add_sheet(sheet_name VARCHAR2,
                        doc_id PLS_INTEGER DEFAULT current_doc_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Adds row to current or specified sheet
    *
    * Input Parameters:
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - row_id    [unique identificator of row within specified sheed and document]
    *
    ****************************************************************************/
    FUNCTION add_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                     sheet_id PLS_INTEGER DEFAULT current_sheet_id) RETURN PLS_INTEGER;
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Wrapper procedure for add_row function
    *
    * Input Parameters:
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE add_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                      sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets height of speficied row
    *
    * Input Parameters:
    *   - height     [height of the row]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_row_height(height NUMBER,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                             row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets value of numeric cell
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_value (name VARCHAR2,
                              value NUMBER,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets value of string cell
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - value      [date value that will be set to the cell]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_value (name VARCHAR2,
                              value VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Add excel xlsx internal xml formatting string to the cell
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - value      [xml string with internal formatting]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_internal_code (name VARCHAR2,
                                      value CLOB,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                      row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets value of date cell
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - value      [date value that will be set to the cell]
    *   - doc_id     [unique identificator of document
    *   - sheet_id   [unique identificator of sheet
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_value (name VARCHAR2,
                              value DATE,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets value of big string cell (CLOB)
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_value (name VARCHAR2,
                              value CLOB,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets format of the cell
    *
    * Input Parameters:
    *   - cell_name  [name of the cell on which format will be applied]
    *   - format     [format mask that will be applied to the cell, same as custom format in Excel]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_format (cell_name VARCHAR2,
                               format VARCHAR2,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                               row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Generates Excel document and stores it in BLOB variable
    *
    * Input Parameters:
    *   - blob_file  [BLOB variable where generated Excel will be stored]
    *   - doc_id     [unique identificator of document]
    *
    * Output Parameters:
    *   - blob_file  [BLOB variable where generated Excel will be stored]
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE save_to_blob(blob_file IN OUT BLOB,
                           doc_id PLS_INTEGER DEFAULT current_doc_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets font family of the cell
    *
    * Input Parameters:
    *   - cell_name  [name of the cell on which format will be applied]
    *   - font_name  [font family which will be applied to the cell ex. Arial]
    *   - font_size  [size that will be applied to the font for specified cell]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_font(cell_name VARCHAR2,
                            font_name VARCHAR2,
                            font_size PLS_INTEGER DEFAULT 10,
                            doc_id PLS_INTEGER DEFAULT current_doc_id,
                            sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                            row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets default font family for whole document
    *
    * Input Parameters:
    *   - font_name  [font family which will be applied to whole document ex. Arial]
    *   - font_size  [size that will be applied to the font for whole document]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_default_font (font_name VARCHAR2 DEFAULT &apos;Calibri&apos;,
                                font_size PLS_INTEGER DEFAULT 11,
                                doc_id PLS_INTEGER DEFAULT current_doc_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets cell type to bold
    *
    * Input Parameters:
    *   - name       [name of cell which content will be bolded]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_bold(name VARCHAR2,
                            doc_id PLS_INTEGER DEFAULT current_doc_id,
                            sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                            row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets cell stype to italic
    *
    * Input Parameters:
    *   - name       [name of cell which content will be formated to italic]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_italic(name VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets cell stype to underline
    *
    * Input Parameters:
    *   - name       [name of cell which content will be underline]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_underline(name VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets color of font within cell
    *
    * Input Parameters:
    *   - name       [name of cell which font will be colored]
    *   - color      [font color in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_color(name VARCHAR2,
                             color VARCHAR2,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                             row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets background color of cell
    *
    * Input Parameters:
    *   - name       [name of cell which background will be colored]
    *   - color      [background color in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_bg_color(name VARCHAR2,
                                color VARCHAR2,
                                doc_id PLS_INTEGER DEFAULT current_doc_id,
                                sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets left side horizontal alignement of cell
    *
    * Input Parameters:
    *   - name       [name of cell content will be placed to left side of column]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_align_left(name VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets horizontal alignement of cell to center
    *
    * Input Parameters:
    *   - name       [name of cell content will be centered]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_align_center(name VARCHAR2,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                    row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets horizontal alignement of cell to right
    *
    * Input Parameters:
    *   - name       [name of cell content will be placed to right side of column]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_align_right(name VARCHAR2,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets vertical alignement of cell to top
    *
    * Input Parameters:
    *   - name       [name of cell content will be placed to the top]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_vert_align_top(name VARCHAR2,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                      row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets vertical alignement of cell to middle
    *
    * Input Parameters:
    *   - name       [name of cell content will be placed in the middle]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_vert_align_middle(name VARCHAR2,
                                         doc_id PLS_INTEGER DEFAULT current_doc_id,
                                         sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                         row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets vertical alignement of cell to bottom
    *
    * Input Parameters:
    *   - name       [name of cell content will be placed to the bottom]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_vert_align_bottom(name VARCHAR2,
                                         doc_id PLS_INTEGER DEFAULT current_doc_id,
                                         sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                         row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets width of the column
    *
    * Input Parameters:
    *   - name       [name of the column which width will be set to specified value]
    *   - width      [width of column]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_column_width(name VARCHAR2,
                               width NUMBER,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets top border of the cell
    *
    * Input Parameters:
    *   - name       [name of cell on which top border will be set]
    *   - style      [style of the border:  thin, thick, double]
    *   - color      [color of border in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_border_top(name VARCHAR2,
                                  style VARCHAR2 DEFAULT &apos;thin&apos;,
                                  color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                  doc_id PLS_INTEGER DEFAULT current_doc_id,
                                  sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                  row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets bottom border of the cell
    *
    * Input Parameters:
    *   - name       [name of cell on which bottom border will be set]
    *   - style      [style of the border:  thin, thick, double]
    *   - color      [color of border in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_border_bottom(name VARCHAR2,
                                     style VARCHAR2 DEFAULT &apos;thin&apos;,
                                     color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                     doc_id PLS_INTEGER DEFAULT current_doc_id,
                                     sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                     row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets left border of the cell
    *
    * Input Parameters:
    *   - name       [name of cell on which left border will be set]
    *   - style      [style of the border:  thin, thick, double]
    *   - color      [color of border in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_border_left(name VARCHAR2,
                                   style VARCHAR2 DEFAULT &apos;thin&apos;,
                                   color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets right border of the cell
    *
    * Input Parameters:
    *   - name       [name of cell on which right border will be set]
    *   - style      [style of the border:  thin, thick, double]
    *   - color      [color of border in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_border_right(name VARCHAR2,
                                    style VARCHAR2 DEFAULT &apos;thin&apos;,
                                    color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                    row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets border of the cell
    *
    * Input Parameters:
    *   - name       [name of cell on which border will be set]
    *   - style      [style of the border:  thin, thick, double]
    *   - color      [color of border in RRGGBB hex format RR - red, GG - green, BB blue]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_border(name VARCHAR2,
                              style VARCHAR2 DEFAULT &apos;thin&apos;,
                              color VARCHAR2 DEFAULT &apos;00000000&apos;,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Fetches data with speified query and place results on specified
    * or current sheet
    *
    * Input Parameters:
    *   - query             [SQL query whih result will be added to sheet]
    *   - show_column_names [parameter to hide or show column names from SQL query, boolean values TRUE or FALSE]
    *   - doc_id            [unique identificator of document]
    *   - sheet_id          [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE query_to_sheet(query CLOB,
                             show_column_names BOOLEAN DEFAULT TRUE,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Generates Excel document and saves it to physical file in Oracle directory
    *
    * Input Parameters:
    *   - directory_name [name of Oracle directory where Excel document will be saved]
    *   - file_name      [file name of generated Excel document]
    *   - doc_id         [unique identificator of document]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE save_to_file(directory_name VARCHAR2,
                           file_name VARCHAR2,
                           doc_id PLS_INTEGER DEFAULT current_doc_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Merges cells horizontaly within specified range
    *
    * Input Parameters:
    *   - cell_from  [name of cell from merge will be started, name example: A1]
    *   - cell_to    [name of cell to where merge will finis, name example: C1]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE merge_cells (cell_from VARCHAR2,
                           cell_to VARCHAR2,
                           doc_id PLS_INTEGER DEFAULT current_doc_id,
                           sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                           row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Wraps text within cell
    *
    * Input Parameters:
    *   - name       [name of cell which text will be wrapped]
    *   - doc_id     [unique identificator of document on which is located sheet
    *                 where is lcaterd row with cell which conted will be wrapped]
    *   - sheet_id   [unique identificator of sheet on which is located row
    *                 row with cell which conted will be wrapped]
    *   - row_id     [unique identificator of row on which cell will be merged]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_wrap_text (name VARCHAR2,
                                  doc_id PLS_INTEGER DEFAULT current_doc_id,
                                  sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                  row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Merges cells vertically within specified range
    *
    * Input Parameters:
    *   - cell_from  [name of cell from merge will be started, name example: A1]
    *   - cell_to    [name of cell to where merge will finis, name example: C1]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE merge_rows (cell_from VARCHAR2,
                          cell_to PLS_INTEGER,
                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                          row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets cell formula
    *
    * Input Parameters:
    *   - name       [name of the cell where value will be added]
    *   - formula    [formula that will be used to calculate cell value]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
        PROCEDURE set_cell_formula(name VARCHAR2,
                                  formula VARCHAR2,
                                  doc_id PLS_INTEGER DEFAULT current_doc_id,
                                  sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                  row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Rotates text to a diagonal angle
    *
    * Input Parameters:
    *   - name       [name of cell content will be centered]
    *   - degrees    [degree from 90 to 180 which will be used to rotate text]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_rotate_text(name VARCHAR2,
                                   degrees INTEGER,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Initiates download of generated excel file using DAD
    *
    * Input Parameters:
    *   - file_name      [file name that will be suggested when download dialog appears]
    *   - doc_id         [unique identificator of document]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE download_file(file_name VARCHAR2,
                            doc_id PLS_INTEGER DEFAULT current_doc_id);
    ----------------------------------------------------------------------------


    /***************************************************************************
    * Description: Sets margins of sheet
    *
    * Input Parameters:
    *   - left_margin     [margin size on the left side of sheet]
    *   - right_margin    [margin size on the right side of sheet]
    *   - top_margin      [margin size on the top side of sheet]
    *   - bottom_margin   [margin size on the bottom side of sheet]
    *   - header_margin   [margin size on the header side of sheet]
    *   - footer_margin   [margin size on the footer side of sheet]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_sheet_margins(left_margin NUMBER,
                                right_margin NUMBER,
                                top_margin NUMBER,
                                bottom_margin NUMBER,
                                header_margin NUMBER,
                                footer_margin NUMBER,
                                sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets sheet orientation to landscape
    *
    * Input Parameters:
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_sheet_landscape(sheet_id PLS_INTEGER DEFAULT current_sheet_id); -- New
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets sheet paper size
    *
    * Input Parameters:
    *   - paper_size [paper size of sheet]
    *                Possible values:
    *                   1 - Letter (8-1/2 in. x 11 in.)
    *                   2 - Letter Small (8-1/2 in. x 11 in.)
    *                   3 - Tabloid (11 in. x 17 in.)
    *                   4 - Ledger (17 in. x 11 in.)
    *                   5 - Legal (8-1/2 in. x 14 in.)
    *                   6 - Statement (5-1/2 in. x 8-1/2 in.)
    *                   7 - Executive (7-1/2 in. x 10-1/2 in.)
    *                   8 - A3 (297 mm x 420 mm)
    *                   9 - A4 (210 mm x 297 mm)
    *                   10 - A4 Small (210 mm x 297 mm)
    *                   11 - A5 (148 mm x 210 mm)
    *                   12 - B4 (250 mm x 354 mm)
    *                   13 - A5 (148 mm x 210 mm)
    *                   14 - Folio (8-1/2 in. x 13 in.)
    *                   15 - Quarto (215 mm x 275 mm)
    *                   16 - 10 in. x 14 in.
    *                   17 - 11 in. x 17 in.
    *                   18 - Note (8-1/2 in. x 11 in.)
    *                   19 - Envelope #9 (3-7/8 in. x 8-7/8 in.)
    *                   20 - Envelope #10 (4-1/8 in. x 9-1/2 in.)
    *                   21 - Envelope #11 (4-1/2 in. x 10-3/8 in.)
    *                   22 - Envelope #12 (4-1/2 in. x 11 in.)
    *                   23 - Envelope #14 (5 in. x 11-1/2 in.)
    *                   24 - C size sheet
    *                   25 - D size sheet
    *                   26 - E size sheet
    *                   27 - Envelope DL (110 mm x 220 mm)
    *                   28 - Envelope C5 (162 mm x 229 mm)
    *                   29 - Envelope C3 (324 mm x 458 mm)
    *                   30 - Envelope C4 (229 mm x 324 mm)
    *                   31 - Envelope C6 (114 mm x 162 mm)
    *                   32 - Envelope C65 (114 mm x 229 mm)
    *                   33 - Envelope B4 (250 mm x 353 mm)
    *                   34 - Envelope B5 (176 mm x 250 mm)
    *                   35 - Envelope B6 (176 mm x 125 mm)
    *                   36 - Envelope (110 mm x 230 mm)
    *                   37 - Envelope Monarch (3-7/8 in. x 7-1/2 in.)
    *                   38 - Envelope (3-5/8 in. x 6-1/2 in.)
    *                   39 - U.S. Standard Fanfold (14-7/8 in. x 11 in.)
    *                   40 - German Legal Fanfold (8-1/2 in. x 13 in.)
    *                   41 - German Legal Fanfold (8-1/2 in. x 13 in.)
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_sheet_paper_size(paper_size INTEGER,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets sheet header text
    *
    * Input Parameters:
    *   - header_text [text that will be displayed on sheets header, limited to 1000 characters]
    *   - sheet_id    [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_sheet_header_text(header_text VARCHAR2,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id); -- New
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets sheet footer text
    *
    * Input Parameters:
    *   - header_text [text that will be displayed on sheets footer, limited to 1000 characters]
    *   - sheet_id    [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_sheet_footer_text(footer_text VARCHAR2,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id); -- New
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets hyperlink for cell
    *
    * Input Parameters:
    *   - name       [cell name]
    *   - hyperlink  [hyperlink that will be set on cell]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_hyperlink(name VARCHAR2,
                                 hyperlink VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets hyperlink within document, to same or another sheet and
    *              to cell within sheet
    *
    * Input Parameters:
    *   - name       [cell name]
    *   - hyperlink  [hyperlink that will be set on cell, example Sheet1!A1 will
    *                 link to sheet with name Sheet1 and to cell A1 within that
    *                 sheet - if sheet name containst spaces it must be enclosed
    *                 with sigle quotes example: &apos;&apos;&apos;My Sheet1&apos;&apos;!A1&apos; ]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_internal_hyperlink(name VARCHAR2,
                                          hyperlink VARCHAR2,
                                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                          row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets left indent within the cell
    *
    * Input Parameters:
    *   - name       [name of cell content will be indented from the left side]
    *   - indent     [number of indent from left site of cell]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_indent_left(name VARCHAR2,
                                   indent INTEGER,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets right indent within the cell
    *
    * Input Parameters:
    *   - name       [name of cell content will be indented from the right side]
    *   - indent     [number of indent from left site of cell]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_indent_right(name VARCHAR2,
                                   indent INTEGER,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets comment text and author name for cell
    *
    * Input Parameters:
    *   - name                [cell name]
    *   - author              [name of the autor of the comment]
    *   - comment_text        [comment text for the cell]
    *   - comment_box_width   [width of comment box]
    *   - comment_box_height  [height of comment box]
    *   - doc_id              [unique identificator of document]
    *   - sheet_id            [unique identificator of sheet]
    *   - row_id              [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cell_comment(name VARCHAR2,
                               autohr VARCHAR2,
                               comment_text VARCHAR2,
                               comment_box_width NUMBER DEFAULT 100,
                               comment_box_height NUMBER DEFAULT 60,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                               row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Hides column
    *
    * Input Parameters:
    *   - name       [name of the column which will be hidden]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE hide_column(name VARCHAR2,
                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                          sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Hides row
    *
    * Input Parameters:
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *   - row_id     [unique identificator of row]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE hide_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                       sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                       row_id PLS_INTEGER DEFAULT current_row_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Sets column auto filter between defined columns range
    *
    * Input Parameters:
    *   - cell_from  [cell name with row number from which auto filter will start, example: A1]
    *   - cell_to    [cell name with row number where auto filter will end, example: A5]
    *   - doc_id     [unique identificator of document]
    *   - sheet_id   [unique identificator of sheet]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_cells_filter(cell_from VARCHAR2,
                              cell_to VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Opens Excel file for reading
    *
    * Input Parameters:
    *   - directory_name [name of Oracle directory from where Excel document will be opened]
    *   - file_name      [file name of Excel document]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
     PROCEDURE open_document(directory_name VARCHAR2,
                             file_name VARCHAR2);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Release memory for currently opened document
    *
    * Input Parameters:
    *   - no imput parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
     PROCEDURE close_document;
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Loads sheet from opened document
    *
    * Input Parameters:
    *   - sheet_name - [name of sheet case isensitive]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE open_sheet(sheet_name VARCHAR2);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Loads sheet from opened document
    *
    * Input Parameters:
    *   - sheet_id - [numberic index od sheet (ex. 1 = first sheet, 2 = second sheet ...)]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE open_sheet(sheet_id PLS_INTEGER);
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Returns cell value
    *
    * Input Parameters:
    *   - cell_name - [cell name which conted will be returned (ex. A1)]
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - cell value type
    *       - varchar2_value  - cell value converted to varchar2 type
    *       - varchar2_number - cell value converted to number type
    *       - varchar2_date   - cell value converted to date type
    *
    ****************************************************************************/

    FUNCTION get_cell_value(cell_name VARCHAR2) RETURN cell_value_type;
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Returns last row number from loaded sheet
    *
    * Input Parameters:
    *   - no input parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - last row number
    *
    ****************************************************************************/
    FUNCTION get_last_row RETURN INTEGER;
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Set 1904 date system, the first day that is supported is
    *              January 1, 1904
    *
    * Input Parameters:
    *   - no input parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_1904_date_system;
    ----------------------------------------------------------------------------

    /***************************************************************************
    * Description: Set 1900 date system, the first day that is supported is
    *              January 1, 1900
    *
    * Input Parameters:
    *   - no input parameters
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE set_1900_date_system;

    /***************************************************************************
    * Description: Set document author property to custom value
    *
    * Input Parameters:
    *   - author - author name
    *   - doc_id - unique identificator of document
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/

    PROCEDURE set_document_author(author VARCHAR2, doc_id PLS_INTEGER DEFAULT current_doc_id);


    /***************************************************************************
    * Description: Add style to current docuemnt
    *
    * Input Parameters:
    *   - style_name            - style name used as referece to apply to cell
    *   - font_name             - font name examples: &apos;Tahoma&apos;, &apos;Arial&apos;, &apos;Times New Roman&apos;
    *   - font_size             - font size, default 11
    *   - formula               - cell formula
    *   - bold                  - bold cell content
    *   - italic                - italic cell content
    *   - underline             - underline cell content
    *   - color                 - text color in hex, example: red = FF0000
    *   - bg_color              - cell background color in hex, example: grey = CCCCCC
    *   - horizontal_align      - horizontal text alignment, values: &apos;left&apos;, &apos;center&apos;, &apos;right&apos;
    *   - vertical_align        - vertical text alignment, value: &apos;top&apos;, &apos;middle&apos;, &apos;bottom&apos;
    *   - border_top            - show cell top border, values: TRUE, FALSE
    *   - border_top_style      - top border style, values: &apos;thin&apos;, &apos;thick&apos;, &apos;double&apos;
    *   - border_top_color      - top border color in hex, example green = 00FF00
    *   - border_bottom         - show cell bottom border, values: TRUE, FALSE
    *   - border_bottom_style   - bottom border style, values: &apos;thin&apos;, &apos;thick&apos;, &apos;double&apos;
    *   - border_bottom_color   - bottom border color in hex, example green = 00FF00
    *   - border_left           - show cell left border, values: TRUE, FALSE
    *   - border_left_style     - left border style, values: &apos;thin&apos;, &apos;thick&apos;, &apos;double&apos;
    *   - border_left_color     - left border color in hex, example green = 00FF00
    *   - border_right          - show cell right border, values: TRUE, FALSE
    *   - border_right_style    - right border style, values: &apos;thin&apos;, &apos;thick&apos;, &apos;double&apos;
    *   - border_right_color    - right border color in hex, example green = 00FF00
    *   - border                - show all cell borders, values: TRUE, FALSE
    *   - border_style          - all cell borders style, values: &apos;thin&apos;, &apos;thick&apos;, &apos;double&apos;
    *   - border_color          - all cell borders color in hex, example green = 00FF00
    *   - wrap_text             - wrap text within cell, values: TRUE, FALSE
    *   - format                - format mas for cell
    *   - rotate_text_degree    - degree number for text rotation, values from 0 to 360
    *   - indent_left           - number of indents from left side, values: number greather than zero
    *   - indent_right          - Number of indents from right side, values: number greather than zero
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE add_style (style_name VARCHAR2,
                         font_name VARCHAR2 DEFAULT NULL,
                         font_size PLS_INTEGER DEFAULT NULL,
                         formula VARCHAR2 DEFAULT NULL,
                         bold BOOLEAN DEFAULT FALSE,
                         italic BOOLEAN DEFAULT FALSE,
                         underline BOOLEAN DEFAULT FALSE,
                         color VARCHAR2 DEFAULT NULL,
                         bg_color VARCHAR2 DEFAULT NULL,
                         horizontal_align VARCHAR2 DEFAULT NULL,
                         vertical_align VARCHAR2 DEFAULT NULL,
                         border_top BOOLEAN DEFAULT FALSE,
                         border_top_style VARCHAR2 DEFAULT NULL,
                         border_top_color VARCHAR2 DEFAULT NULL,
                         border_bottom BOOLEAN DEFAULT FALSE,
                         border_bottom_style VARCHAR2 DEFAULT NULL,
                         border_bottom_color VARCHAR2 DEFAULT NULL,
                         border_left BOOLEAN DEFAULT FALSE,
                         border_left_style VARCHAR2 DEFAULT NULL,
                         border_left_color VARCHAR2 DEFAULT NULL,
                         border_right BOOLEAN DEFAULT FALSE,
                         border_right_style VARCHAR2 DEFAULT NULL,
                         border_right_color VARCHAR2 DEFAULT NULL,
                         border BOOLEAN DEFAULT NULL,
                         border_style VARCHAR2 DEFAULT NULL,
                         border_color VARCHAR2 DEFAULT NULL,
                         wrap_text BOOLEAN DEFAULT FALSE,
                         format VARCHAR2 DEFAULT NULL,
                         rotate_text_degree INTEGER DEFAULT NULL,
                         indent_left INTEGER DEFAULT NULL,
                         indent_right INTEGER DEFAULT NULL,
                         column_width INTEGER DEFAULT NULL,
                         doc_id PLS_INTEGER DEFAULT current_doc_id);

    /***************************************************************************
    * Description: Appliest predefined style to cell
    *
    * Input Parameters:
    *   - cell_name  - name of cell, example &apos;A&apos;
    *   - style_name - name of style defined with procedure add_style
    *   - doc_id     - unique identificator of document
    *   - sheet_id   - unique identificator of sheet
    *   - row_id     - unique identificator of row
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/

    PROCEDURE set_cell_style(cell_name VARCHAR2,
                             style_name VARCHAR2,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                             row_id PLS_INTEGER DEFAULT current_row_id);

	/***************************************************************************
    * Description: Freeze panes horizontally
    *
    * Input Parameters:
    *   - freeze_columns_number  - top left column name with row number,
    *                              example: to freeze first row set &apos;A2&apos; as top
    *                              left row
    *   - doc_id                 - unique identificator of document
    *   - sheet_id               - unique identificator of sheet
    *   - row_id                 - unique identificator of row
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE freeze_panes_horizontal(freeze_columns_number VARCHAR2,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id);



    /***************************************************************************
    * Description: Freeze panes vertically
    *
    * Input Parameters:
    *   - freeze_rows_number  - top left column name with row number, example:
    *                           to freeze first column set 1 as top left row
    *   - doc_id              - unique identificator of document
    *   - sheet_id            - unique identificator of sheet
    *   - row_id              - unique identificator of row
    *
    * Output Parameters:
    *   - no output parameters
    *
    * Returns:
    *   - does not return anything
    *
    ****************************************************************************/
    PROCEDURE freeze_panes_vertical(freeze_rows_number VARCHAR2,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id);

END ORA_EXCEL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ADAOSMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>038EFA14607A7FEFE9C937222FA4C56A596CB36E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ADAOSMED IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end PKG_ADAOSMED; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_AGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8E6F41BAE23029B31B2AE9608FA36D794E177D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_AGENDA IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_AGENDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ABDF45E06629EB220F1246874CFC44C70A83AA61</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ALERTE IS

  C_LINE_SEP        CONSTANT  VARCHAR2(1)  := &apos;|&apos;;
  C_LINE_DENUMIRE   CONSTANT  VARCHAR2(50) := &apos;Denumire alerta&apos;    || C_LINE_SEP;
  C_LINE_FILTRE     CONSTANT  VARCHAR2(50) := &apos;Filtre specifice &apos;  || C_LINE_SEP;
  C_LINE_REZULTAT   CONSTANT  VARCHAR2(50) := &apos;Rezultat alerta &apos;   || C_LINE_SEP;
  C_LINE_CONTEXT    CONSTANT  VARCHAR2(50) := &apos;Context alerta &apos;    || C_LINE_SEP;

  g_RezultatAlerta clob := &apos;&apos;;

  procedure setuserid(aUserID in number);
  function getuserid return number;
  function GetSQLForExcell(xSQL in Clob, Ord in Varchar2, Cod in Number) return Clob;
  function GetColoane(fFields in Varchar2)	return Varchar2;
  function IsHTML(Nume in Varchar2)	return Boolean;

  PROCEDURE INS_MAN_ALERTE(AMESAJ IN VARCHAR2, AORDINE IN NUMBER);
  PROCEDURE CLEAR_MAN_ALERTE;
  procedure SetCodAlerta(aCod in number );
  function GetCodAlerta return number;

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );


  PROCEDURE SET_JOB(aCODALERTA IN NUMBER);
  PROCEDURE SET_STATE (aCODALERTA IN NUMBER,ASTATE IN NUMBER);
  PROCEDURE RUN_NOW(aDenumire in varchar2);
  PROCEDURE UPDATE_ARGUMENTS (aDenumire in varchar2, aScheduler in varchar2);
  FUNCTION FORMAT_HTML_MESSAGE(pMesaj IN clob) RETURN clob;
  PROCEDURE ACTUAL_ALERTE ;
  PROCEDURE ACTUAL_PROC_DATE;
  FUNCTION TEST_DEN(aDenumire in varchar2 ,obj_type out varchar2) RETURN NUMBER;
  FUNCTION TRANDU_FILTRU_WME (AFILTRU VARCHAR2, aDataType in varchar2) RETURN VARCHAR2;
  function RulezDinExe return boolean;
  procedure MailAlert(acodAlerta in number,acodRulare in number);
  function setInfoText(vCodAlerta in varchar2, pAn in number, pLuna in number) return varchar2;
  procedure postMesagerie(aCodAlerta in number, aCodRulare in number);
  procedure postMesagerie_AI(aCodAlerta in number, aCodRulare in number);
  procedure postTask(aCodAlerta in number, aCodRulare in number);
  procedure postTask_AI(aCodAlerta in number, aCodRulare in number);
  procedure postSMS(aCodAlerta in number, aCodRulare in number);
  procedure postSMS_AI(aCodAlerta in number, aCodRulare in number);
  PROCEDURE DO_ALERTA(VCODALERTA IN NUMBER);
  FUNCTION DO_ALERTA_WEBSERVICE(askemafirma varchar, vCodAlerta number) RETURN NUMBER;
  procedure UpdateAlerteDef(aCodAlerta in number, aCodAlertaDef out number);
  procedure UpdateProcDef(aCodAlerta in number);
  
end pkg_alerte;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_AMBALAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8A05D135F3ABB8E5DF70D816AC6AD737FA3E493</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_AMBALAJE IS
  FUNCTION  LOCK_AMBALAJEDELEGAT( aDelegat IN NUMBER,
                                  aSubunit IN NUMBER,
                                  aAllData IN BOOLEAN  DEFAULT TRUE,
                                  aData    IN VARCHAR2 DEFAULT NULL, -- format &apos;dd.mm.yyyy&apos;
                                  aAllTime IN BOOLEAN  DEFAULT TRUE,
                                  aOraIni  IN VARCHAR2 DEFAULT NULL, -- format &apos;h24:mm&apos;
                                  aOraFin  IN VARCHAR2 DEFAULT NULL  -- format &apos;h24:mm&apos;
                                ) RETURN VARCHAR2;
  PROCEDURE UNLOCK_AMBALAJEDELEGAT;
  PROCEDURE RETUR_AMBALAJEDELEGAT;
  PROCEDURE ACT_REZ_AMBDELEGAT;
END PKG_AMBALAJE;
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08C040937C81DD226858D64AD6912798E2F4FB2B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ANALIZA IS

  function  GetCodANALIZA return number;
  procedure SetCodANALIZA(aCodANALIZA in number);

  PROCEDURE GetBugete ( RecId IN NUMBER, aAN in NUMBER, aLUNA1 in NUMBER, aLUNA2 in NUMBER, Tip in number, aCodPlata in number  );
  PROCEDURE SaveBugete( RecId IN NUMBER, aAN in NUMBER, aLUNA1 in NUMBER, aLUNA2 in NUMBER, Tip in number  );

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  procedure TestBugete;
  procedure RectificareSintetice;
  function GetValSintetic(aCodAnalizaNod in number, aAn in number, aLuna in number, aCodCentru in number, aCodElement in number, aTip in number) return number;    
END pkg_ANALIZA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ASIGURARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BA63E95DA01D7FA6DBC9CB17D568F04D19B5F7F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ASIGURARI is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD; 

end PKG_ASIGURARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BANCI_NIVNATIONAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B577DC18A3BF5B6B1FBDF0E2906A97FF3D08300D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BANCI_NIVNATIONAL IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_Banci_NivNational; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>780FF456FB03B85975A5139FA5E9F239C901DD2A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BCAR IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE UNLOCK_ALL_USER_RECORDS(aCodBCAR in number default 0);
  PROCEDURE ELIBEREAZA_ALL_USER_RECORDS;
  PROCEDURE GET_BCAR_FURNIZOR(aCodFurn IN NUMBER, aTipDoc IN NUMBER, aCodDoc IN NUMBER, aSubunitate IN NUMBER);
  PROCEDURE UPDATE_BCAR_FURNIZOR(aCodDoc1 IN NUMBER, aTipDoc IN NUMBER, aCodBCAR IN NUMBER);
  PROCEDURE LOCK_BCAR_GENERARE_INTRARE(aCodFurn IN NUMBER, aTipDoc IN NUMBER, aCodDoc IN NUMBER, aSubunitate IN NUMBER);

  PROCEDURE UPDATE_RECORDS(pTipDoc IN NUMBER, pTMP_CODDOC1 IN NUMBER , pCODDOC1 IN NUMBER);

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNrDoc IN NUMBER, aCarnet IN NUMBER);

  FUNCTION RECALCULEAZA_BCAR RETURN VARCHAR2;

  PROCEDURE LOCK_RECORDS_TMPINTRARI1;
  PROCEDURE LOCK_RECORDS_TMPIESIRI1;

  PROCEDURE SERVICE_UNLOCK_BCAR;

  FUNCTION BCAR_PRELUAT(aCodBCAR IN NUMBER) RETURN NUMBER;
  FUNCTION BCAR_BLOCAT(aCodBCAR IN NUMBER) RETURN NUMBER;

  PROCEDURE ELIBEREAZA_NEW_USER_RECORDS;
  PROCEDURE UNLOCK_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER);
  FUNCTION CALCULEAZA_CANTUTILA(
           aCantBruta IN NUMBER, aCantNeta IN NUMBER,
           aCantAnalizaUmiditate IN NUMBER, aCantStasUmiditate IN NUMBER,
           aCantAnalizaStraine IN NUMBER, aCantStasStraine IN NUMBER,
           aCantAnalizaHectolitric IN NUMBER, aCantStasHectolitric IN NUMBER,
           aCantAnalizaSparturi IN NUMBER, aCantStasSparturi IN NUMBER,
           aPierd IN NUMBER,
           aAnDoc IN NUMBER, aLunaDoc IN NUMBER, aStas in number default 0
         ) return number;
  PROCEDURE UPDATE_BCAR(aCodCarnet in number);
  FUNCTION EVAL(aEvalString IN VARCHAR2) RETURN NUMBER;
  procedure SalveazaMP(aCodPart in number, aCodSediu in number, vCodObiect in number, aTipBCAR in number, aObs in varchar2, aCodMPBCAR out number);
  
end PKG_BCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BCS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AC728286E5E3ABDF7D85D0BA4BA31639ADBA4D4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BCS IS

FUNCTION ADAUGA_ARTICOL_NOU(TIPIDART IN NUMBER, IDART IN VARCHAR2, DENART IN VARCHAR2, UM VARCHAR2, aCODPART NUMBER ) RETURN NUMBER;



end PKG_BCS; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BILANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DFE5F8F97BCC500D49152ECA5AE52FEE57B1658</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BILANT IS

  vAL   NUMBER(5);
  vAn   NUMBER(4);
  vLuna NUMBER(2);

  PROCEDURE UMPLE_TMP_CDS_BILANT(pAn NUMBER, pLuna NUMBER, pSubunit NUMBER);
END pkg_bilant;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BONMASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1889881A0690A6172E7BA30B264EB24A3EF07858</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BONMASA is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_BONMASA;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BUGETMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7892903C8BC73C32DCFB7516C79A73111563EBC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BUGETMF is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD; 

end PKG_BUGETMF; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>062F176DF33F816D02E23161FB01B083B6EB87CB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BUGETPROD is

  TYPE BUGETSTOC_CURSOR IS REF CURSOR;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION GET_BUGETSTOC RETURN BUGETSTOC_CURSOR;

end PKG_BUGETPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_BUGETRECTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E06CB42C455E895617998E8D4CBBDC83C672915F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_BUGETRECTIF is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_BUGETRECTIF; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CAENSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71D3971AF3D2887BA3E4B03ABCF2BDA45FC222D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CAENSEC IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_CAENSEC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CAMPANII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E829CC4A17AA29C9851AA727BE34553E5290D128</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CAMPANII IS

  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;
  
  procedure AdaugaDocMarketing(aCodCampanie in number, aCodDoc in number, aTipDoc in number, aCodPart in number, aForce in number, aExista out number, aDenCampanie out varchar2);
  procedure StergeDocMarketing(aCodCampanie in number, aCodDoc in number, aTipDoc in number);

end PKG_CAMPANII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CANAMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FB2596AD968B44DBD368085DA09E9D50EAA87A1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CANAMED IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;   

end pkg_canamed; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>573BB4F7EEA9D764F0CF297BB0641437EAA29C92</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CANTAR IS

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);

  PROCEDURE UPDATE_RECORDS(pTIPDOC IN NUMBER, pTMP_CODDOC1 IN NUMBER , pCODDOC1 IN NUMBER);
  PROCEDURE LOCK_RECORD(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER);
  PROCEDURE UNLOCK_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER);
  PROCEDURE ANULEAZA_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER DEFAULT 0);
  PROCEDURE ANULEAZA_UNA(pCOD IN NUMBER);

  PROCEDURE X_ELIBEREAZA_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER DEFAULT 0, pID_CANTARIRE IN VARCHAR2);

  FUNCTION CANTARIT_AZI(aCodObiect IN NUMBER, aSubunitate in number, aDestinatie in number, aCodDest in number) RETURN NUMBER;
  FUNCTION CMDINT_AZI(aCodObiect IN NUMBER, aCodGest in number) RETURN NUMBER;

  PROCEDURE CANTARIRI_PE_LOT(aData IN VARCHAR2, aDestinatie in number, aCodDest in number, aTipDoc IN NUMBER, aSUBUNITATE IN NUMBER, aCodObiect IN NUMBER DEFAULT 0);
  PROCEDURE UPDATE_CANTARIRI_PE_LOT(aCodDoc1 IN NUMBER, aCODOBIECT IN NUMBER, aSERIE IN NUMBER, pID_CANTARIRE IN VARCHAR2);
  PROCEDURE ELIBEREAZA_ALL_USER_RECORDS;
  PROCEDURE ELIBEREAZA_ON_SP_POSTRECORDS;
  PROCEDURE UNLOCK_ALL_USER_RECORDS;
  PROCEDURE LOCK_RECORDS_TMPINTRARI1;
  PROCEDURE LOCK_RECORDS_TMPIESIRI1;
  PROCEDURE LOCK_RECORDS_TMPTRANSF1;

  PROCEDURE SERVICE_UNLOCK_CANTAR;

  PROCEDURE ELIBEREAZA_NEW_USER_RECORDS;
  PROCEDURE REFA_BLOCAJE_INITIALE;
  procedure LockNP(aCodCantar in number);
  procedure CheckNewData;
  procedure SetSalvare(aSaveCantar in number);
  
END PKG_CANTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CANTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE253E1A38A6D1307FCE497A35D062764567F05E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CANTARE IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_CANTARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CARDURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01F27E1F789A0B285421D1E0FDD17F8FD0222D69</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CARDURI is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ); 
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ); 
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ); 
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
  PROCEDURE SP_INSERTRECORD;

end PKG_CARDURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CARNETEDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BFA5B57068F89330F33FFB678C8CD5814062A35</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CARNETEDOC IS

  MACHETACURENTA NUMBER(20) := 0;
  CARNETTRANSF   NUMBER(20) := 0;
  CARNETLIVR     NUMBER(20) := 0;

  PROCEDURE SETCARNETTRANSF(ACODCARNET IN NUMBER);
  FUNCTION GETCARNETTRANSF RETURN NUMBER;
  PROCEDURE SETCARNETLIVR(ACODCARNET IN NUMBER);
  FUNCTION GETCARNETLIVR RETURN NUMBER;

  PROCEDURE SETMACHETACURENTA(MACHETA IN NUMBER);
  FUNCTION  GETMACHETACURENTA RETURN NUMBER;
  PROCEDURE REFACERECARNETE;
  PROCEDURE REFACERECARNET(aCodCarnet in number);

  FUNCTION CARNETACTIV(aCODMACHETA IN NUMBER, aCODCARNET IN NUMBER) RETURN NUMBER;
  PROCEDURE UNLOCKDOCUMENTEMACHETA(aMACHETA IN NUMBER);
  FUNCTION NUMARDISPONIBIL(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER;
  FUNCTION NUMARDISPONIBIL_EXT(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER;
  FUNCTION GETCARNETFORMACHETA(aMACHETA IN NUMBER, aSubunitate IN NUMBER) RETURN NUMBER;
  FUNCTION GETNEXTNRDOC(aCODCARNET IN NUMBER, SERIEDOC OUT VARCHAR2, SIMBOLDOC OUT VARCHAR2) RETURN VARCHAR2;
  FUNCTION COUNTFREENR(aCODCARNET IN NUMBER) RETURN NUMBER;
  FUNCTION COUNTFREENRX RETURN NUMBER;

  PROCEDURE LOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2);
  FUNCTION CANLOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER;
  PROCEDURE UNLOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2);
  PROCEDURE SOLVENUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2);

  PROCEDURE SOLVENUMARDOC_EXT(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER);
  PROCEDURE SOLVENUMARDOC_EXTX(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER);
  PROCEDURE PARCURGESIREFADOC(NUMETABLA VARCHAR2, CAMPCARNET VARCHAR2, CAMPNRDOC VARCHAR2);

  PROCEDURE RELEASENUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER);
  PROCEDURE COMPACTEAZAINTERVALE(aCARNETDOC IN NUMBER);
  PROCEDURE COMPACTEAZAINTERVALEX;

  FUNCTION CARNETE_COMENZIONLINE(CodCarnetCurent IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

  PROCEDURE GENEREAZA_CARNETE( aDEN       IN VARCHAR2,
                               aSIMBOL    IN VARCHAR2,
                               aSERIE     IN VARCHAR2,
                               STARTPAGE  IN NUMBER,
                               NRPAGINI   IN NUMBER,
                               NRCARNETE  IN NUMBER,
                               INDEXSERIE IN NUMBER
                              );

END PKG_CARNETEDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CASEOFFLINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53E1BA92301B56B3366CA945C265EE93EE133C98</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CASEOFFLINE IS

 PROCEDURE SP_EURO_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_ZEURO_GOTORECORD( RecId IN NUMBER, Zet IN NUMBER, DataRaport IN DATE );
 PROCEDURE SP_EURO_POSTRECORDS( Operation IN NUMBER, RecId IN NUMBER );
 PROCEDURE SP_ZEURO_POSTRECORDS( Operation IN NUMBER, RecId IN NUMBER, Zet IN NUMBER, DataRaport IN varchar2 );
 PROCEDURE SP_EURO_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_ZEURO_DELETERECORD( RecId IN NUMBER, Zet IN NUMBER, DataRaport IN date );
 FUNCTION SP_ZEURO_GETNEXTZET(aCodCasa IN NUMBER, DataRaport in varchar2) RETURN NUMBER;
 
end pkg_caseoffline; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15E427CC17AD37CB256E477C344AA3457789167A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CASHFLOW is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_CASHFLOW; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CASTOT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C58813FDD773CEE1C692488926C219AAA7548D0B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CASTOT is
  PROCEDURE POST_TRANZACTIE;
  PROCEDURE POST_TRANZACTIE_PREPAY;
end PKG_CASTOT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CATEGARTTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDCEDB22F957A6A3E4D7DEC4343D9CEABA3329A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_CATEGARTTI IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_CATEGARTTI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43FAFE8F95518D9992538A3A317CC46A292D9715</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CATEGCONST IS
  TIPCATEGORIE varchar2(1);
  type Val_Ref_Cursor is ref cursor;

  PROCEDURE CONST_TO_TMP_CONSTANTE(aSimbol in Varchar2);
  PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
  PROCEDURE SP_DELETERECORD (RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS (Operation in number , RecId out  NUMBER);
  PROCEDURE STERGE_CONSVAL_DUBLU;
  
  FUNCTION GetValAfisByValoare(pSimbol IN VARCHAR2, pTIP IN NUMBER, pValoare IN VARCHAR2) RETURN VARCHAR2;
  FUNCTION GetValAfis(pTIP IN NUMBER, pCodConstLuna IN NUMBER) RETURN VARCHAR2;
  FUNCTION GetValConstantaInCursor (aSimbol in varchar2, An in number, Luna in number) return Val_Ref_Cursor;
  FUNCTION GetValConstanta    (aSimbol in varchar2,an number,luna number) return varchar2;
  FUNCTION GetCodConstBySimbol(aSimbol in varchar2) return number;
  FUNCTION GetValConstByCode  (aCode in number,an number,luna number) return varchar2;

  PROCEDURE GetConst_Param(aSimbol IN VARCHAR2, aCodConst1 OUT NUMBER, aUserID OUT NUMBER);
  FUNCTION  GetConst_Val_SiViitor  (aCodConst1 IN NUMBER, aUserID IN NUMBER, aAL IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetConst_Val  (aCodConst1 IN NUMBER, aUserID IN NUMBER, aAL IN NUMBER) RETURN VARCHAR2;

  FUNCTION GETDENCONSTANTA(aSimbol in varchar2) return varchar2;

  PROCEDURE SETTIPCATEGORIE(aTIP IN VARCHAR2);
  FUNCTION  GETTIPCATEGORIE RETURN VARCHAR2;
  FUNCTION USERCORECT(aCODCONST1 IN NUMBER, aUserID IN NUMBER) RETURN NUMBER;

  FUNCTION ESTECONTPENTRU(aCODCONT IN NUMBER, aSIMBOLCONST IN VARCHAR2) RETURN NUMBER;
  FUNCTION ESTECONTPENTRU_ANLUNA(aCODCONT IN NUMBER, aSIMBOLCONST IN VARCHAR2, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;

  FUNCTION ESTEOBINV(aCODCONT IN NUMBER)              RETURN NUMBER;
  FUNCTION ESTEMIFIX(aCODCONT IN NUMBER)              RETURN NUMBER;
  FUNCTION ESTEMIFIXLEASING(aCODCONT IN NUMBER)       RETURN NUMBER;
  FUNCTION ESTEAMBALAJ(aCODCONT IN NUMBER)            RETURN NUMBER;
  FUNCTION ESTEPRODUS(aCODCONT IN NUMBER)             RETURN NUMBER;
  FUNCTION ESTEMATERIAL(aCODCONT IN NUMBER)           RETURN NUMBER;
  FUNCTION ESTESTOPAJ(aCODCONT IN NUMBER)             RETURN NUMBER;
  FUNCTION ESTECHELTAVANS(aCODCONT IN NUMBER)         RETURN NUMBER;
  FUNCTION ESTEVENITAVANS(aCODCONT IN NUMBER)         RETURN NUMBER;
  FUNCTION ESTECUSTODIE(aCODCONT IN NUMBER)           RETURN NUMBER;
  FUNCTION ESTEIMBUNATATIREMIFIX(aCODCONT IN NUMBER)  RETURN NUMBER;
  FUNCTION ESTEMFSaft(aCODCONT IN NUMBER)             RETURN NUMBER;
  FUNCTION ESTEGRUPUSER(aCODCONT IN NUMBER)           RETURN NUMBER;
  FUNCTION ESTEUSERDINGRUP(aCODCONT IN NUMBER)        RETURN NUMBER;

  PROCEDURE UMPLE_TMP_CODCONT_CONST (
    ESTEOBINV             BOOLEAN DEFAULT FALSE,
    ESTEMIFIX             BOOLEAN DEFAULT FALSE,
    ESTEMIFIXLEASING      BOOLEAN DEFAULT FALSE,
    ESTEAMBALAJ           BOOLEAN DEFAULT FALSE,
    ESTEPRODUS            BOOLEAN DEFAULT FALSE,
    ESTEMATERIAL          BOOLEAN DEFAULT FALSE,
    ESTESTOPAJ            BOOLEAN DEFAULT FALSE,
    ESTECHELTAVANS        BOOLEAN DEFAULT FALSE,
    ESTECUSTODIE          BOOLEAN DEFAULT FALSE,
    ESTEIMBUNATATIREMIFIX BOOLEAN DEFAULT FALSE
  );

  FUNCTION VERIFICA_CONST_PE_GRUPUL(aDENGRUP IN VARCHAR2, aANLunaSTART in Number) RETURN NUMBER;
  PROCEDURE MULTIPLICA_CONST_PE_GRUPUL(aDENGRUP IN VARCHAR2);
  FUNCTION VERIFICA_CONST_PE_USERI RETURN NUMBER;
  PROCEDURE MULTIPLICA_CONST_PE_USERI;
  FUNCTION GetValConstantaExt(aSimbol IN VARCHAR2, An IN NUMBER, Luna IN NUMBER, aUserID IN NUMBER, aSkemaFirma IN VARCHAR2) RETURN VARCHAR2;

end PKG_CATEGCONST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CATEGPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B96241AA9BCF7449CF8134D519E7563C1E69EB0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CATEGPRET IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION CLONEAZA_CATEGORIA (aCodSursa  NUMBER,NewName in varchar2) RETURN NUMBER ;
  PROCEDURE MODIFICA_PRET(CODNOU IN NUMBER, CODSURSA IN NUMBER, TIPMODIF IN NUMBER);
END pkg_CategPret; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64169692C006CCBF49D0350B8F4734FAA56B1EF2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CENTRECOST IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ); 
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ); 
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ); 
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
  PROCEDURE SP_INSERTRECORD;

end pkg_centrecost; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09F8F412E0566D602CA93FBE8935C7B90F534B26</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_certif is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_certif;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CFGTABLES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9099B35AC731AB440D011544E82D8B048BAA82B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CFGTABLES IS
  NUMEMODUL VARCHAR2(20) := &apos;&apos;;
  TIPCONFIG NUMBER(1) := 0;
  LocalTipDoc NUMBER;
	
  PROCEDURE TEST;
  procedure CHECKMON(aFieldName in varchar2, aCodExt in number, aCodMaster in number);
  FUNCTION GETDISPLAY(aNomLink in number, aDisplay in varchar2, aCod in number) return varchar2;
  PROCEDURE SETNUMEMODUL(aMODUL IN VARCHAR2);
  FUNCTION GETCODMODUL(aTipConfig IN NUMBER, aMASTER IN VARCHAR2, aLinkKey IN VARCHAR2, aTipLink IN NUMBER, aDescriere IN VARCHAR2) RETURN NUMBER;
  FUNCTION TESTCOPYCAMP(VALOARE IN VARCHAR2, TIPDEST IN VARCHAR2, MARIMEDEST IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SETGRANTMODUL( NumeModul IN VARCHAR2, FIRMA IN VARCHAR2);
  PROCEDURE SETTIPCONFIG(TIP IN NUMBER);
  

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE CHECK_STRUCT_EXTENSIE (tableName IN VARCHAR2, linkKey IN VARCHAR2);
  PROCEDURE EXT_UPDATE_COD_CORESP (pMasterTableName IN VARCHAR2, newCode IN NUMBER, oldCode IN NUMBER DEFAULT NULL);
  PROCEDURE EXT_GOTORECORD (pTipDoc IN NUMBER);
  PROCEDURE EXT_INSERTRECORD (pTipDoc IN NUMBER);
  PROCEDURE EXT_POSTRECORDS_INIT (pTipDoc IN NUMBER);
  PROCEDURE EXT_POSTRECORDS (pTipDoc IN NUMBER, OPERATION IN NUMBER default 0);
  PROCEDURE EXT_DELETERECORD (recId IN NUMBER, pTipDoc IN NUMBER) ;
  FUNCTION EXT_GET_EQV_TIP_DOC(tipDoc IN NUMBER) RETURN NUMBER;
  PROCEDURE CHECK_STRUCT_EXTENSIE_X_TIPDOC (pTipDoc IN NUMBER) ;
  PROCEDURE CHECK_STRUCT_INI_EXT_ALL;
  FUNCTION GET_EXT_TMP_FIELDS_WITH_TYPES (tableName IN VARCHAR2) return VARCHAR2;
  FUNCTION GET_EXT_FIELDS (tableName IN VARCHAR2, isTemporary IN NUMBER) return VARCHAR2;
  FUNCTION GET_FIELD_TYPE (TIP IN VARCHAR2, ZECIMALE IN NUMBER, MARIME IN NUMBER) return VARCHAR2;
  FUNCTION GET_EXT_TMP_FIELDS_NUM (tableName IN VARCHAR2) return NUMBER;
  FUNCTION GET_EXT_SQL_TMP (tableName IN VARCHAR2) RETURN VARCHAR2;
  FUNCTION GET_EXT_FIELDS_FROM_TABLE (pTableName IN VARCHAR2, pCodColumnName IN VARCHAR2, pLinkKey IN VARCHAR2, pStartWithComma IN NUMBER DEFAULT 1) return VARCHAR2;
  
	procedure GET_CFGActions(aTipDoc in number);
  PROCEDURE POST_CFGActions;
	procedure recreate_table(aTableName in varchar2);
  function LinkKey(aTableName in varchar2) return varchar2;
  function get_cfgtable_by_tip_doc(pTipDoc IN tmp_extcfgtable.tip_doc%TYPE,
                                          pStateList IN VARCHAR2 DEFAULT NULL) RETURN SYS_REFCURSOR;
  procedure ImportCfg;                                        
  
end PKG_CFGTABLES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8576A7D6BF8C3C0AE279D6E2ED5B836B89AEA392</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CHELTAVANS IS
  TIPCHELTAVANS NUMBER(2) := 0;
  VENITURI NUMBER(1) := 0;

  PROCEDURE SETTIPCHELTAVANS(ATIP IN NUMBER, aISVENIT IN NUMBER);

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

  PROCEDURE MAKE_TEMP_FOR_VIEWCHELTAVANS;
  PROCEDURE MAKE_TEMP_FOR_VIEWVENITAVANS;
end PKG_CHELTAVANS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CHELTAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41BB600D09A5432561A8A972F8CBE311D599A2FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CHELTAVANS_INI IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_CHELTAVANS_INI; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CHELTOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B63029736BF48E5A79DBD66A2A663AC60984329</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CHELTOPER is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_CHELTOPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6D205C0B6BC182C99E5134823B1F9FF799B7494</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEART IS
  CODCLASA_FILTRU_GENERATOR NUMBER(20) := 0;

  FUNCTION GetSimbolPred(aCodClasa in number, aNivel in number) return varchar2;
  function GetCodIdentParinte(acodparinte in number) return varchar2;
  procedure MakeCodIdent;
  PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER);
  FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

END pkg_ClaseArt;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEARTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A858DA3D8DA7BFF34B33981A73564ECE0B8FE613</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEARTS IS

  PROCEDURE MakeCodIdent;
  FUNCTION IS_SUBCLAS_OF(aCLASA IN NUMBER, MASTERCLAS IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

END pkg_ClaseArtS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54E56E5DBD97B4B70A4DF40D8FEFEDB2D6285E85</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEDISC is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_CLASEDISC;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A86D4CAA50DF4CC67334DAAF8E57D75D210AF66D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEGEST IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ClaseGest; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E85E0623507F98030A45E79AF5903661E6D4BC5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEINT is

  CODCLASA_FILTRU_GENERATOR NUMBER(20) := 0;
  PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER);
  FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_CLASEINT;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5827918956570A3EB2CF2D133922F337D2A6264E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEMF is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_CLASEMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3127FE91B21AC743D2DA7C5F992AD44E339B37D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEOP IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_claseop; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0894C8163B6CF81E7F8F4393768283FA88F2B3F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEOPT is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_CLASEOPT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EB86C37A2D3486C059A488DD43FCDE6595714D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEPART IS

  function GetCodIdentParinte(acodparinte in number) return varchar2;
  procedure MakeCodIdent;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ClasePart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLASEPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0DE53B859615A9291EFCE9E8681A89CCDDB7AEE3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLASEPROD IS

  CODCLASA_FILTRU_GENERATOR NUMBER(20) := 0;
  PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER);
  FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_claseprod; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CLEAN_DOCS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>336E1D489E6906B9223E15B272F94738EA4C5AF1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CLEAN_DOCS IS

 
 PROCEDURE Dezactiv_constr;
 PROCEDURE Activ_constr;
 PROCEDURE Activ_constrPK;

 PROCEDURE clean_all;
 
 PROCEDURE clean_iesiri;
 PROCEDURE clean_intrari;
 PROCEDURE clean_trezor;
 PROCEDURE clean_transf;
 PROCEDURE clean_nc;
 PROCEDURE clean_compens;

end pkg_clean_docs; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EAC39234AEDBD79C213184E4A9D79F1B233B4E2C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_COMANDA IS
  --g_CodCOMANDA1 NUMBER(18) := 0;
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PartenerCOMANDA NUMBER(20) := 0;

  procedure UpdateDataStart(aCodComanda1 in number);
  procedure AdaugaInObsCmd(aCodComanda in number, aCods in varchar2);
  procedure AdaugaInObsLinie(aCodComanda1 in number, aObs in varchar2);
  procedure UpdatePretPrjProd(aCodComanda1 in number, aPret in number, aCodReteta in number, aCodProiect in number);
  function ActualizeazaLinie(aCodComanda in number, aCodComanda1 in number, aCodObiect in number, aCodReteta in number, aCant in number) return number;
  function DinCmdCli(aCodComanda1 in number) return number;
  function DinCmdCliFaraProiect(aCodComanda1 in number) return number;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  procedure ModificaRezervariCC(acodcomanda in number);
  procedure SetCantInComand1(vCodComanda1 in number, vCant in number);
  procedure Set_Do_Commit(aDoCommit IN BOOLEAN);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);

  PROCEDURE SETPARTENERCOMANDA(aPart in NUMBER);
  FUNCTION CONDITIE_PART_COMANDA(aPart in NUMBER) RETURN NUMBER;

  FUNCTION AM_FACTURA_FURNIZOR_LA_COMANDA(aCODCOMANDA IN NUMBER)
    RETURN NUMBER;
  FUNCTION LINIE_COMANDA_FURNIZOR_STINSA(aCODCOMANDA1 IN NUMBER)
    RETURN NUMBER;

  FUNCTION AM_FACTURA_CLIENT_LA_COMANDA(aCODCOMANDA IN NUMBER) RETURN NUMBER;
  FUNCTION AM_FACTURA_SOFER_LA_COMANDA(aCODCOMANDA  IN NUMBER) RETURN NUMBER;
  FUNCTION LINIE_COMANDA_CLIENT_STINSA(aCODCOMANDA1 IN NUMBER) RETURN NUMBER;

  FUNCTION AM_TRANSFER_LA_COMANDA_GEST(aCODCOMANDA IN NUMBER) RETURN NUMBER;
  FUNCTION LINIE_COMANDA_GEST_STINSA(aCODCOMANDA1 IN NUMBER) RETURN NUMBER;
  FUNCTION LIVRAT_DIN_REZERVAT(aCODCOMANDA1 IN NUMBER,
                               aCODNIRSTOC  IN NUMBER,
                               aCODNIRSER   IN NUMBER) RETURN NUMBER;
  FUNCTION sunt_mat_neconsumate(aCODCOMANDA1 IN NUMBER) RETURN NUMBER;
  FUNCTION sunt_prod_neintrate(aCODCOMANDA1 IN NUMBER) RETURN NUMBER;
  FUNCTION LINIE_COMANDA_INTERNA_STINSA(aCODCOMANDA1 IN NUMBER) RETURN NUMBER;
  FUNCTION LINIE_COMANDA_SUB_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER;
  PROCEDURE MUTA_REZERVARI(CODCOMANDA1_SURSA IN NUMBER, CODCOMANDA1_DEST IN NUMBER, aCANT IN NUMBER);
  PROCEDURE MUTA_REZERVARI_OUT;
  PROCEDURE MUTA_REZERVARI_IN;
  PROCEDURE INCHIDE_LINIE_COMANDA(aCODLINIECOMANDA IN NUMBER);
  PROCEDURE INCHIDE_LINIE_COMANDA_FURN(aCODLINIECOMANDA IN NUMBER);

  FUNCTION GET_GESTIUNI_COMANDA1(aCODCOMANDA IN NUMBER ) RETURN VARCHAR2;
  FUNCTION INFO_STINGERE_COMANDA(aCODCOMANDA IN NUMBER) RETURN VARCHAR2;

  procedure BagaInComanda1et(RecId in number);
  procedure RescrieComanda1et;
  procedure GetInfoStocPeMat(pCodGest IN NUMBER DEFAULT 0);
  procedure InchideComanda(aCodComanda in number);
  function UpdateTermenComanda(aCodComanda1 in number, aTermen in varchar2) return number;
  PROCEDURE PREPARE_MAN_COMENZI_CLIENTI(aCODPART IN NUMBER, ANLUNALUCRU IN NUMBER);
  PROCEDURE PREPARE_MAN_COMENZI_PRODUCTIE(aCODGEST IN NUMBER, ANLUNALUCRU IN NUMBER, aDataRef IN VARCHAR2, aNP IN NUMBER DEFAULT 0);
  PROCEDURE MODIFICA_LINII_COMENZI;
  procedure CORECTIE_REZ_SA(acodcomanda1 in number, acant in number);
  PROCEDURE EMPTY_COMANDA_TEMPTABLES;
  procedure Set_PrelRezAut(aPrelRezAut IN NUMBER);
  procedure GETAWBCOMANDA(aCodComanda in number, aTipDoc in number, aCurier in number);
  procedure POSTAWBCOMANDA(aCodComanda in number, aTipDoc in number, aCurier in number);
  procedure PREPARE_TMP_NARTCLI(aCodPart in number);

  PROCEDURE ValidSetConst   (pAn  NUMBER, pLuna NUMBER);
  FUNCTION  ValidAdaosMinim (pCodComanda1 NUMBER) RETURN INTEGER;

END pkg_COMANDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_COMPARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBEC601CBCBF4CA75DA431A48A7AF0EBA16D63C4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_COMPARE IS
FUNCTION COMPARE(aCODJOB IN NUMBER) RETURN NUMBER;
procedure debug;
end PKG_COMPARE; 

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_COMPENSARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D46A097F3BDCFD4D0B112EDFC1EF1C2C2D87DB2A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_COMPENSARI IS

-- memoreaza CARNETDOC si NRDOC la intrarea pe macheta 
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ); 
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ); 
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ); 
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
  PROCEDURE SP_INSERTRECORD; 
  
--FUNCTION GETCURSLINIEOBLIG(aCODGENERAL IN NUMBER) RETURN VARCHAR2;

 
  FUNCTION SEMNCOMPENS(SEMNIFICATIE IN NUMBER, ICONT IN NUMBER ) RETURN NUMBER;
  FUNCTION GETCURSLINIESTINSA(aMONEDA IN NUMBER, aCURS IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_INFO_FACTURA_LITIGIU(aCODOBLIGSTINGATOR IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_DATA_FACTURA_LITIGIU(aCODOBLIGSTINGATOR IN NUMBER) RETURN DATE;
  PROCEDURE UPDATE_VALTRANZ_STINGERI(RECID IN NUMBER);

END PKG_COMPENSARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONCURENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BCAB8C90778D05B84172BCD09601EE7672E5144</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONCURENTI is

  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;

end PKG_CONCURENTI;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONFIGART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE913D1C2306399E70C00B0D6EB6546A1DCC234A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONFIGART IS
  --g_codioart1 NUMBER(18) := 0;

  CODIOART_FILTRU_GENERATOR NUMBER(20) := 0;
  PROCEDURE SET_CODIOART_FILTRU_GENERATOR(aCODIOART IN NUMBER);
  FUNCTION CODIOART_FILTRU_VALID(aCODIOART IN NUMBER) RETURN NUMBER;


  FUNCTION GETCODCARACTLUNA(aCODIOART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ConfigArt;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONFIGBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>567EE53BF985829036407CD2A3C052439B1F418A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONFIGBANK IS
--  g_codiobank1 NUMBER(18) := 0;
  type Luna_ref_cursor is ref cursor;

  FUNCTION GetRecordIoBank(IoBankCod IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor;
  FUNCTION GETCODCARACTLUNA(aCODIoBank IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ConfigBank;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONFIGFILIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BBCEB925E7D8F03EB6D963EE41ED9ED7EAD9605</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONFIGFILIAL IS
  FUNCTION GETCODCARACTLUNA(aCODIOFILIAL IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
end PKG_CONFIGFILIAL;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONFIGPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4EADF88CD82F9128B04666F65BF6EACD5169C99</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONFIGPART IS
--  g_CodIOPart1 NUMBER(18) := 0;
  type Luna_ref_cursor is ref cursor;

  IOPART_EDITAT NUMERIC(20) := 0;

  PROCEDURE SET_IOPART_EDITAT(aCODPART IN NUMBER);
  FUNCTION COD_IOPART_EDITAT_VALID(aCODPART IN NUMBER) RETURN NUMBER;


  FUNCTION GETCODCARACTLUNA(aCodIOPART IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER;
  FUNCTION GetRecordIopart(IoPartCod IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ConfigPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONFIGPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7C6C01207AA127A511A47057D92D6C0A33C25F3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONFIGPERS IS
  type Luna_ref_cursor is ref cursor;

  FUNCTION GetRECORDIOPERS(IoPErsCod IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor;
  FUNCTION GETCODCARACTLUNA(aCODIOPERS IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_ConfigPers;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONSTMASTER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B36013349222CF24E5DE103F6E65E7B9FBC6B13C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONSTMASTER IS
PROCEDURE FETCHDATA;
PROCEDURE POSTDATA;
PROCEDURE CHECK_CONSTANTE_USER(aUserID IN NUMBER);

end PKG_CONSTMASTER; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3301F6A87504B06105D116F91C6071014BC5DE1B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONTRACT IS

  type crsComisioane is ref cursor;

  procedure Test;

  function GetCodContract1Part(aCodObiect in number, aDataDoc in date, aCodPart in number) return number;
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

  FUNCTION  CALCULEAZA_DISCT_DOC(aTipDoc  IN NUMBER,
                                 aCodDoc  IN NUMBER,
                                 aDataRef IN VARCHAR2,
                                 aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER;
  FUNCTION  CALCULEAZA_DISCT_LINIE(aTipDoc  IN NUMBER,
                                   aCodDoc1 IN NUMBER,
                                   aDataRef IN DATE)  RETURN NUMBER;
  FUNCTION  CALCULEAZA_DISCV_DOC(aTipDoc  IN NUMBER,
                                 aCodDoc  IN NUMBER,
                                 aDataRef IN DATE,
                                 aValTotal IN NUMBER,
                                 aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER;
  FUNCTION  CALCULEAZA_DISCC_DOC(aTipDoc  IN NUMBER,
                                 aCodDoc  IN NUMBER,
                                 aDataRef IN DATE,
                                 aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER;
  FUNCTION  CALCULEAZA_DISCC_LINIE(aTipDoc  IN NUMBER,
                                   aCodDoc1 IN NUMBER,
                                   aDataRef IN DATE)  RETURN NUMBER;
  FUNCTION  GETOBJCADOU(aTipDoc    IN NUMBER,
                        aCodObiect IN NUMBER,
                        aPart      IN NUMBER,
                        aDataRef   IN VARCHAR2 ) RETURN VARCHAR2;
  FUNCTION  GETCANTCADOU(aTipDoc  IN NUMBER,
                         aCodDoc1 IN NUMBER,
                         aDataRef IN VARCHAR2 ) RETURN NUMBER;

  PROCEDURE SIMULEAZA_DISCV(aDataStart IN DATE,
                            aDataStop  IN DATE,
                            aTip       IN NUMBER  DEFAULT 0);

  PROCEDURE SIMULEAZA_DISCC(aDataStart IN DATE,
                            aDataStop  IN DATE,
                            aTip       IN NUMBER  DEFAULT 0);

  PROCEDURE SIMULEAZA_CADOU(aDataStart IN DATE,
                            aDataStop  IN DATE,
                            aTip       IN NUMBER  DEFAULT 0);

  PROCEDURE SIMCADOU_SET  (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE );

  FUNCTION  SIMCADOU_COD  (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE  ) RETURN NUMBER;

  FUNCTION  SIMCADOU_DEN  (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE  ) RETURN VARCHAR2;

  FUNCTION  SIMCADOU_CANT (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE  ,
                           aCant      IN NUMBER) RETURN NUMBER;

  PROCEDURE GETCADOU_SET  (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aCant      IN NUMBER,
                           aDataRef   IN DATE );

  FUNCTION  GETCADOU_COD  (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aCant      IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETCADOU_CANT (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aCant      IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION GETLINCONTR    (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETPRET       (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETPROCDISC   (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETADDIM      (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETC1ANEXA    (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN NUMBER;

  FUNCTION  GETC1DSTART   (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN DATE;

  FUNCTION  GETC1DSTOP    (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN DATE;

  FUNCTION  GETTERMEN     (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE ) RETURN termene_contract;

  FUNCTION  DISCMAXTERMEN (aTipDoc    IN NUMBER,
                           aCodObiect IN NUMBER,
                           aPart      IN NUMBER,
                           aLocatie   IN NUMBER,
                           aSubunit   IN NUMBER,
                           aDataRef   IN DATE  ,
                           aCant      IN NUMBER,
                           aPret      IN NUMBER ) RETURN NUMBER;

  FUNCTION  ContractVDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER;
  FUNCTION  ContractTDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER;
  FUNCTION  ContractCDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER;
  FUNCTION  UPD_CONTRACTEDINCADRU (aCodCadru IN NUMBER) RETURN VARCHAR2;
  FUNCTION  ADD_LINIEDINCADRU (aCodCadru1 IN NUMBER) RETURN VARCHAR2;
  FUNCTION  DEL_LINIEDINCADRU (aCodCadru1 IN NUMBER) RETURN VARCHAR2;
  PROCEDURE TMP_PROPAGACONDDISC   (aCodContract1 IN NUMBER);
  PROCEDURE CoeficientZILE(pPrimaZi IN DATE, pUltimaZi IN DATE, pC1DataStart IN DATE, pC1DataStop IN DATE, pTipPret IN PLS_INTEGER, vCoef IN OUT NUMBER, vNrZile IN OUT PLS_INTEGER);
  FUNCTION  ACTPRETABON  (aSubunit IN NUMBER, aMONEDA IN NUMBER, aTipC IN NUMBER, aAllPart IN NUMBER, aTipPer IN NUMBER, aDataRef IN VARCHAR2 ) RETURN VARCHAR2;
  FUNCTION  ACTPRETContr (aSubunit IN NUMBER, aMONEDA IN NUMBER, aTipC IN NUMBER, aTipDoc IN NUMBER, aTipObiect IN NUMBER, aAllPart IN NUMBER, aExpl in Varchar2) RETURN VARCHAR2;
  FUNCTION  getComisioane(aCodPart IN NUMBER) return crsComisioane;

  FUNCTION  getCantContor(aCodContract1 IN NUMBER, aData IN DATE) RETURN NUMBER;
  PROCEDURE setCantContor(aCodContract1 IN NUMBER, aData IN DATE);

  FUNCTION  getCantExtra (aCodContract1 IN NUMBER, aData IN DATE) RETURN NUMBER;

  FUNCTION  ObsLuna(pCDataStart DATE, pC2DataStop DATE, pPerFact NUMBER) RETURN VARCHAR2;
  PROCEDURE SetTMPFactAb(
    pTipPrel NUMBER, sDataRef VARCHAR2, pTipDataRef NUMBER, pLocalit NUMBER,
    pClasa NUMBER, pAgent NUMBER, pIOArt NUMBER, pGest NUMBER, sDataFact VARCHAR2,
    pPersoanaFizica NUMBER, pTipSediu NUMBER,
    pTraseu NUMBER DEFAULT 0
  );
  FUNCTION  getNrContrGestArt(aCodContract1 IN NUMBER) RETURN NUMBER;
  procedure CheckRecoltaArenda(aCodContract in number,  An in number);
  PROCEDURE MakeVenitInAvans(aCODCONTRACT2 IN NUMBER);
END PKG_CONTRACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONTREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9186D0808523B71ED8267D323B9015B0CCDAE3E7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONTREP IS
  PROCEDURE SP_GOTORECORD  (RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD  (RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS (Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_CONTREP; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONTURIBANCI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>795D4B031FEC029D8B68A03E732C8061F90A817D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONTURIBANCI IS
  TYPE DESCR_CONT_LUNA_CURSOR IS REF CURSOR;
  BANCACURENTA NUMBER(20):=0; -- cod banca la nivel de national
  CONT_SURSA_VIRAMENT NUMBER(20):=0;
  CONTBANCACURENT NUMBER(20):=0; -- contul curent pentru care calculez SOLDURI in V_SOLDBANKLUNA

  INITIALIZARI NUMBER(1) := 0; -- flag care imi spune ca vin de pe initializari solduri casa / banca

  PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER);

  PROCEDURE SETBANCACURENTA(aCODBANCA IN NUMBER);
  FUNCTION GETBANCACURENTA RETURN NUMBER;

  PROCEDURE SETCONTBANCACURENT(aCONTBANCA IN NUMBER);
  FUNCTION GETCONTBANCACURENT RETURN NUMBER;

  PROCEDURE SETCONT_SURSA_VIRAMENT(aCONT IN NUMBER);
  FUNCTION GETCONT_SURSA_VIRAMENT RETURN NUMBER;

  FUNCTION GET_COD_NBANKCONT1(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_BANKCONT_COD_CARACT_LUNA(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_RECORD_COD_CARACT_LUNA(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN  DESCR_CONT_LUNA_CURSOR;

  FUNCTION GET_O_CASA_IN_MONEDA(aMONEDA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_O_BANCA_IN_MONEDA(aMONEDA IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE MAKE_CURS_BANKCONT_LUNA(aDATA IN VARCHAR2);
  PROCEDURE STERGE_TREZOR_DIN_SOLDBANCA(aCODBANKCONT NUMBER);
END pkg_ConturiBanci;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CONVERTSOLDPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C41D2B4C7DF9130F86468CCC060576760D789EF7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CONVERTSOLDPERS IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_CONVERTSOLDPERS; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CREANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05211426F7C26EA787C116866CAE2582C394D538</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CREANTE is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_CREANTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CRITERIIDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>419EE9C43A0A7ECC2B48D292E2ED966F4184BBC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CRITERIIDISCOUNT IS
ISPUNCTAJ NUMBER(1) := 0;

  FUNCTION GETDISCINTERVALE(aCODDISCOUNT IN NUMBER) RETURN VARCHAR2;
  FUNCTION ART_ARE_DISCOUNT(aCODOBIECT IN NUMBER, 
                            aCODCRITERIU IN NUMBER, 
                            aVALOARE IN NUMBER, 
                            aVALOARECLASA IN NUMBER, 
                            aTIPSEDIU IN NUMBER, 
                            aPROCENT OUT NUMBER) RETURN NUMBER;
 
  FUNCTION ART_ARE_DISCOUNT_EXT(aCODOBIECT IN NUMBER, 
                               aCODCRITERIU IN NUMBER, 
                               aVALOARE IN NUMBER, 
                               aVALOARECLASA IN NUMBER, 
                               aDATAREF IN VARCHAR2, 
                               aTIPSEDIU IN NUMBER, 
                               aPROCENT OUT NUMBER) RETURN NUMBER;

  FUNCTION CONDITIE_OBJ_CLASA_GRUPA(aPECLASE IN NUMBER, aCODOBIECT IN NUMBER, aCODCLASA IN NUMBER,  aGRUPA IN VARCHAR2, OBIECTREAL IN VARCHAR2) RETURN NUMBER;
 
 
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION GET_CODDISCOUNT_FOR_CRITERIU
                            (aCODOBIECT IN NUMBER, 
                             aCODCRITERIU IN NUMBER,
                             aDATAREF IN VARCHAR2, 
                             aTIPSEDIU IN NUMBER
                             ) RETURN NUMBER;
 
 PROCEDURE COPIE_DISCOUNT(aCODCRITERIU1 NUMBER);
 PROCEDURE SET_ISPUNCTAJ(FLAG IN NUMBER);
 

END pkg_CriteriiDiscount; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CUPLARE_FIRME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7CE9C3D9B3420667A7F551A5BE90F6CC158396CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CUPLARE_FIRME IS

FUNCTION GET_COD_FIRMA(aID IN VARCHAR2) RETURN NUMBER;
PROCEDURE SP_GETDATA; 
PROCEDURE SP_POSTDATA; 

end PKG_CUPLARE_FIRME; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CURSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B84EDE3541688195184CFDC640C338D2D0C00DC8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CURSURI IS
 

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_CURSURI; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CUSTODIEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5EAA51BA65C22E70B933D9F65B95E20DD572435</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CUSTODIEINI IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_CUSTODIEINI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_CUSTOMFORM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30E56F031FC80C8C2C362C92902D5E52853C5400</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_CUSTOMFORM IS
  CodCustomForm NUMBER(20);
  CARNETDOC_I   NUMBER(20);
  NRDOC_I       NUMBER(20);

  PROCEDURE SetCodCustom(aCod in Number);

  PROCEDURE SP_GOTORECORD  ( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD  ( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS ( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SOLVENRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);

  PROCEDURE UPDATE_FROM_TMP( pTabName IN VARCHAR2, pColName IN VARCHAR2 );
END PKG_CUSTOMFORM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_D300</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>795619816F7B51FFC0F8E669E630DB0A4DCC62B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_D300 IS

  PROCEDURE ETVA_GETRECORD( RecId IN NUMBER ) ;
  PROCEDURE ETVA_AppendRECORD( aId IN NUMBER );
  PROCEDURE Get300(aAn in number, aLuna in number, aSubunit in number);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE UmpleAux(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER, pTip NUMBER);
  PROCEDURE Generare(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER, pTip NUMBER);

END PKG_D300;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_D390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A137A25FA1E480BA1A86F2E8D52B68585AA9632</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_D390 IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE Generare(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER);

END PKG_D390;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_D394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D388E26E338B0A4EEECA912477B041D7506F1005</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_D394 IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE Generare( pSursa INTEGER, pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER);
  PROCEDURE Centralizare;
  FUNCTION ExtrageNr (pSursa VARCHAR2) RETURN NUMBER;
  FUNCTION ExtrageLit(pSursa VARCHAR2) RETURN VARCHAR2;
  FUNCTION ExtrageCFBon(pSursa VARCHAR2) RETURN VARCHAR2;
  FUNCTION DenCN (pCodCN VARCHAR2) RETURN VARCHAR2;
  FUNCTION LimitaBon (pData DATE) RETURN NUMBER;

END PKG_D394;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_D39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA6A40C892421A0985F2B637715D4179CA050EA7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_D39416 IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE UmpleGEN( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER, pLei BOOLEAN DEFAULT FALSE);
  PROCEDURE CuratareANAF;
  PROCEDURE ExtraANAF;
  PROCEDURE CuiANAF (pCui VARCHAR2, pData VARCHAR2);
  PROCEDURE DoneANAF;
  PROCEDURE ActualizGEN;
  FUNCTION  GET_VAL_ACHIZ (pTipDoc IN NUMBER, pCodDoc IN NUMBER, pCodDoc1  IN NUMBER) RETURN NUMBER;
  PROCEDURE Generare( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER, pPas INTEGER DEFAULT 0, pNerezident INTEGER DEFAULT 0);
  PROCEDURE UmpleXML( pCodD39416 IN NUMBER );

END PKG_D39416;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DECODE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92E9F42446F7786D73B417E4E4D4EE0AE328928A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DECODE IS
FUNCTION DODECODE(TABLENAME IN VARCHAR2, LOOKUPFIELD IN VARCHAR2, LOOKUPDISPLAY IN VARCHAR2, COD IN NUMBER) RETURN VARCHAR2;
end PKG_DECODE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DELEGATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C22821B047997930786885E7568824C3BAF11EE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DELEGATI IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_DELEGATI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C568B4BF8AE2F3C8BBB64D7DFD6A3AA9B1CD5FA0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DESCRIPTORI IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;

 FUNCTION  GetDenAsociat (pTip IN NUMBER, pCodAsociat IN NUMBER) RETURN VARCHAR2;

end PKG_DESCRIPTORI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DESTINATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBE301A2F0ABF6C8D4D1A21299F1C77C8B0CFCDE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_destinatii is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_destinatii; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DETALIIET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75483BE617CAAC898216187672F05FBD144C44F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DETALIIET IS

 PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number,  aTipET in number, aCodDetaliu  out number, aTipTranzactie in number default null);

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
 PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
 
 
end PKG_DETALIIET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DIFICULTATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1951DB6D58F86FCF912B949837BCBA2467E5ED6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DIFICULTATI IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_dificultati; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DIFPRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C24ED58242E5AAC5E95F21E87BF1DED9DF2E1600</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DIFPRETPROD IS

  procedure MarkDirty_DifPretPRod;
  function InregValida(Tabla in varchar2, CodSubunit in number, CodGest in number, Key in number) return number;
  PROCEDURE MAKE_STOCINITIAL_LUNA(aAN IN NUMBER, aLUNA IN NUMBER);
  PROCEDURE MAKE_MISCARI_IN_LUNA(aAN IN NUMBER, aLUNA IN NUMBER);
  PROCEDURE MAKE_MISCARI_BalantaStoc(aAN IN NUMBER, aLUNA IN NUMBER);
  PROCEDURE Get_Records_DifPretProd(aGest in number, aSubunitate in number, aAN IN NUMBER, aLUNA IN NUMBER);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_DIFPRETPROD; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC0E5AD500476D86C8115C28114260DB2ED323B8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DINTRASTAT IS
  TYPE crsGlobal IS REF Cursor;

  PROCEDURE UmpleGEN(pAn INTEGER, pLuna INTEGER, pSubunit INTEGER);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE Generare(pAn INTEGER, pLuna INTEGER, pSubunit INTEGER);

  PROCEDURE UmpleXML(pCodIntrastat NUMBER, pTipOper IN NUMBER, pTip IN NUMBER, pExtinsa IN NUMBER);
END PKG_DINTRASTAT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DISTANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0865184CB8B129FE33462A79291BFC1EA34CEFB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DISTANTA is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_DISTANTA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C99B80C8EE8060D948CC8D944CEA17F44615D416</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DISTRIB IS

  procedure GENTASKURI(vCod in number);
  procedure GENTASK(vDen_Part in varchar2, vExecutant in varchar2, vData in varchar2, vProiect in varchar2, vCodPart in number);
  procedure ExportTrasee(RecId in number);
  procedure UpdateDistributie;
  procedure UpdateDistributieOnLuna(vAn IN NUMBER, vLuna IN NUMBER);
  function GetSoldPartLaData(vCodPart in number, vData in varchar) return number;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_distrib; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DISTRIBCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C359F15E48527B5E541E6739A681CE063ADC3DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DISTRIBCHELT IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );  

end PKG_DISTRIBCHELT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DOCSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A0763D5DBF24988A92D2405D62155E6D504050A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DOCSUPLIM IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_DOCSUPLIM; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DOCUMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC74182243520D60A66CA57613B22761D767DBE5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DOCUMENTE IS
  PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number ,aOwner in varchar2);
  PROCEDURE ACTUALIZARE(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2);
  PROCEDURE ACT_COND_UPDATE(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2, forceUpdate IN NUMBER DEFAULT 1);
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE ACTUALIZARE_X_NUMEFISIER(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2);
END PKG_DOCUMENTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DOMENIIACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB4D9BBA579999BF5DE6871EB65A5B2836BCA17F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DOMENIIACT is

  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;

end PKG_DOMENIIACT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DOSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>430E81DE2032632EAD23A8FCC426CC45CA02E8C4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DOSARE IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_DOSARE; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9509EFF69D2D505582C84C26CB2B24D47794DC01</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DPROFIT is

  function INCHID711CU121(vAn in number, vLuna in number, vSimbol in varchar2, vTipProfit in number) return number;
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_DPROFIT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_DVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26B9A8375F3F8BD9CB4019D9B68F48C01EA4B429</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_DVI IS
  CURS_IN     NUMBER(20, 7);

  FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;

  FUNCTION TOTAL_VALOARE_ICONT_VAMA(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_VALOARE_SEMNIF_VAMA(aSEMNIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_ICONT_VAMA(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_SEMNIF_VAMA(aSEMNIF IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_LOCKRECORD( RECID IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RECID IN NUMBER );
  PROCEDURE SP_GOTORECORD( RECID IN NUMBER );
  PROCEDURE SP_POSTRECORDS( OPERATION IN NUMBER, RECID OUT NUMBER );
  PROCEDURE SP_POSTRECORDS_FROM_IMPORT (RECID OUT NUMBER );
  PROCEDURE SOLVE_OBINV(aCODINTR IN NUMBER, aCODCLASIF IN NUMBER );
END PKG_DVI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EDITCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>033AED965D17C1575D3A423D6C790B7C8639C761</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EDITCONST IS

V_CODCONSTLUNA_ACTIV NUMBER (10);
V_CODCONST1_ACTIV NUMBER(10);

PROCEDURE SET_V_CODCONSTLUNA_ACTIV (COD IN NUMBER);
PROCEDURE SET_V_CODCONST1_ACTIV (COD IN NUMBER);

PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
PROCEDURE SP_DELETERECORD (RecId IN NUMBER);
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_POSTRECORDS (Operation IN NUMBER, RecId OUT NUMBER);

end PKG_EDITCONST; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EFACTCLONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42785E625E925A0813A304274E0BB4F80778BF1A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EFactClona is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  
end PKG_EFactClona; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EFCUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0A4D2B7A9C64814154E7AD33A71264AF99EC81C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EFCustom is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE ACTUAL_EFCUSTOM;
  
end PKG_EFCustom; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1B3DFF84BB9931AB5B50362F5D5C6E3E8F64D32</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ELEMBUGET is

PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;

end PKG_ELEMBUGET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B39C923F3943E0A4932180183B07AC38ECDFE6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ELEMENTE IS
 

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 
 
 FUNCTION DECODE_DESCRIPT1(ATIP IN NUMBER) RETURN VARCHAR2;
 FUNCTION VALIDEAZA_MASCA_CONT(MASCA IN VARCHAR2) RETURN BOOLEAN;
 PROCEDURE SET_VALORI_ANALIZA (ASIMBOL IN VARCHAR2, ATIPDOC IN NUMBER, ACODANALIZA IN NUMBER, ATIPCONT IN NUMBER );
 
 FUNCTION GET_SIMBOL     RETURN VARCHAR2;
 FUNCTION GET_TIPDOC     RETURN NUMBER;
 FUNCTION GET_CODANALIZA RETURN NUMBER;
 FUNCTION GET_TIPCONT   RETURN NUMBER;
end PKG_ELEMENTE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B23EEA97E3BB72E6892F6F8EEAF6AA150B623919</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EMULARE IS


  CODPARTIN NUMBER(20):= 0;

  FUNCTION GETTIPCASAMARCAT(aCODCASAMARCAT IN NUMBER) RETURN NUMBER;
  FUNCTION GETNEXTNRBON(aCODCASAMARCAT IN NUMBER, aDATABON VARCHAR2) RETURN NUMBER;
  PROCEDURE LOCKNRBON(aCODCASAMARCAT IN NUMBER, aNRBON IN NUMBER);
  PROCEDURE UNLOCKNRBON;
  PROCEDURE GET_FROM_STOC_BY_CODBARE(CODBARE VARCHAR2, TIPCOD IN NUMBER);
  PROCEDURE SETGESTIUNICASA(aCODCASADEMARCAT IN NUMBER);
  PROCEDURE SET_BONURI_PRELUATE(aCODMONETAR IN NUMBER);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE GET_FROM_STOC_BY_CODBARE_EXT(CODBARE VARCHAR2, TIPCOD IN NUMBER);
  PROCEDURE GET_FROM_STOC_BY_CODOBIECT(aCODOBIECT IN NUMBER);
  PROCEDURE STERGEINCASARI (aCODEMUL IN NUMBER);  
  
  PROCEDURE POSBANCAR_GOTORECORDS(aUserID IN NUMBER );
  PROCEDURE POSBANCAR_POSTRECORDS(aUserID IN NUMBER );
  
end pkg_emulare; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ESTIMARIPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8409CD42C346D4CFD5D8121E8D28EB56EE34197</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ESTIMARIPROD IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  procedure CalcValScadente(aAnImport in number, aAnF in number, aSaptamana in number, aScadenta in number, aCodObiect in number, AnCurent in number default 1);
  procedure setvstoc (valoare in number);
  procedure execute_sql_prod(sAn in varchar2, sSaptamana in varchar2, vVal in number, vCod in number, vDepasire in number);
  procedure SetParams(aCodEstimareProd1 in number, aSaptamana in number, aAn in number, CuRefresh in number default 0);
  PROCEDURE RefreshNod;
  procedure ClearMatStruct(aCodEstimareProd in number);
  procedure CalculValori(aCodEstimareProd1m in number, aAnImport in number, aAnF in number);
  procedure CalculeazaNecesar(aCodEstimareProd1m in number, aSaptamana in number);
  procedure BagaMateriale(aNodOriginal in number, aCodProdComp in number, aNivel in number,
                          aCodEstimareProd1 in number, aCodEstimareProd in number, aObservatii in varchar2, aSaptamana in number, aAn in number, aCant in number);
  procedure UpdateAchiz(aCodEstimareProd1m in number, sdata in varchar2, aCodOferta in number);
  function GENSTRUCT(vCodEstimareProd1 in number) return number;
  procedure umple_nec_prod(aSubunitate in number, aCodEstimareProd1 in number, aSaptamana in number, aAnImport in number, aAnF in number);
  procedure AduCmdF(aSaptamana in number, aSaptamanaF in number, aAnImport in number, aAnF in number, aCodEstimareProd1m in number, aSubunitatea in number);
  procedure UMPLEIOART1OFE(aAn in number, aLuna in number,aCodOferta in number);
  procedure CentralizeazaMat(aCodestimareProd1 in number, aAn in number, aLuna in number, aSubunitatea in number, sData in varchar2, aCodOferta in number, aCodEstimareProd in number);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);

end PKG_ESTIMARIPROD;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EUDR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66015CAD982F88EE49EE8DABDBAEA5FFF719977D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EUDR is

procedure UpdateNPLinkIntr(aCodIntr in number);
procedure UpdatePeZi(aRN_OLD in varchar2, aVN_OLD in varchar2, aRN in varchar2, aVN in varchar2, aDataDoc in varchar2);

end PKG_EUDR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA262F081C25180DF4D90C0BF32B558086D623BD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EvalS is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_EvalS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EVALUARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2F9A30E4313AEE05D1FA8F7F846707854560C82</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EVALUARI is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_EVALUARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EVALUATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21B31591170B4CE7513AD9A192A6248C3921E8FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EVALUATORI is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_EVALUATORI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B0E1616309BB0147E504A63069479D5A1AAC455</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EVIDENTAMF is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SOLVE_MIFIX(aCODTRANSF IN NUMBER, aCODMIFIX IN NUMBER);

end PKG_EVIDENTAMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3EF2E9E33E4FC78A07697892DBA29DE1B85C759</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EXPERT IS

  CODANALIZA NUMBER(20);
  TIPANALIZA NUMBER(20);
  PROCEDURE SETCODANALIZA(aCODANALIZA IN NUMBER);
  FUNCTION  GETCODANALIZA RETURN NUMBER;
  PROCEDURE SETTIPANALIZA(aTIPANALIZA IN NUMBER);
  FUNCTION  GETTIPANALIZA RETURN NUMBER;

  FUNCTION  GET_DEN_NOD (aCODNOD IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GET_DEN_DOC (CODDOC IN NUMBER, TIPDOC IN NUMBER, INDEXLOCAL IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE DEL_FaraLegatura;
  PROCEDURE DEL_Defecte;
end pkg_EXPERT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EXPORTEDI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDB5B273E36B33855A046523CF28BCA8F15FF2BD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_EXPORTEDI IS
  TYPE crsGlobal IS REF Cursor;
  FUNCTION  GetIDLaClient (pPartTip NUMBER, pCodIes NUMBER) RETURN VARCHAR2;
  FUNCTION  GetGLNLaClient(pPartTip NUMBER, pCodIes NUMBER) RETURN VARCHAR2;
  PROCEDURE SetXMLDocXChangeData   (
    pCodIes NUMBER, pDocType NUMBER,
    pComNumber  VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
    pAENumber   VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL,
    pBillingRef VARCHAR2 DEFAULT NULL, pBFDate  VARCHAR2 DEFAULT NULL,
    pNIRNumber  VARCHAR2 DEFAULT NULL, pNIRDate VARCHAR2 DEFAULT NULL
  );
  PROCEDURE SetXMLDocTecNetData    (
    pCodIes NUMBER, pDocType NUMBER,
    pRefNumber VARCHAR2 DEFAULT NULL, pRefDate VARCHAR2 DEFAULT NULL,
    pNirNumber VARCHAR2 DEFAULT NULL, pNirDate VARCHAR2 DEFAULT NULL,
    pComNumber VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
    pAENumber  VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL
  );
  PROCEDURE SetXMLDocEdiNetData    (
    pCodIes NUMBER, pDocType NUMBER,
    pRefNumber    VARCHAR2 DEFAULT NULL, pRefDate    VARCHAR2 DEFAULT NULL,
    pComNumber    VARCHAR2 DEFAULT NULL, pComDate    VARCHAR2 DEFAULT NULL,
    pNirNumber    VARCHAR2 DEFAULT NULL, pNirDate    VARCHAR2 DEFAULT NULL,
    pRetAnnNumber VARCHAR2 DEFAULT NULL, pRetAnnDate VARCHAR2 DEFAULT NULL
  );
  PROCEDURE SetExpertSupplierData  (
    pCodIes NUMBER, pDocType NUMBER,
    pRefSerie  VARCHAR2 DEFAULT NULL,
    pRefNumber VARCHAR2 DEFAULT NULL, pRefDate VARCHAR2 DEFAULT NULL,
    pNirNumber VARCHAR2 DEFAULT NULL, pNirDate VARCHAR2 DEFAULT NULL,
    pComNumber VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
    pAENumber  VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL
  );

  PROCEDURE PrepFirmaAdr            (pCodIes  NUMBER);
  PROCEDURE PrepXMLDocXChange       (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0);

  PROCEDURE PrepXMLDesAdvTecNet     (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0);
  FUNCTION  GetXMLDocTecNetData     (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal;

  PROCEDURE PrepXMLDocEdiNet        (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0);

  PROCEDURE PrepXMLDesAdvEdiNet     (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0);

  FUNCTION  GetXMLDocExpertSupplier (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal;
  FUNCTION  GetXMLDocExpertSupplierT(pCodIes  NUMBER)                         RETURN crsGlobal;
  FUNCTION  GetXMLDesAdvExpertSuppl (pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal;

  PROCEDURE SetXMLIATAData          (pCodIes  NUMBER);
END pkg_exportedi;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_EXP_HENKEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AD724A04A8DBDF943479DDD33B799C0917B850F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_exp_henkel IS

  PROCEDURE UMPLE_TMP(
    sDataIni IN VARCHAR2,
    sDataFin IN VARCHAR2);

  PROCEDURE AUX_TMP(
    sTMP      IN  VARCHAR2,
    sHeader   OUT VARCHAR2,
    sFooter   OUT VARCHAR2,
    sFileName OUT VARCHAR2
  );

  FUNCTION getCursorTmp(pTMP IN  VARCHAR2) RETURN SYS_REFCURSOR;
  PROCEDURE EXPORT_ZILNIC;
  PROCEDURE EXPORT_LUNAR;
  PROCEDURE EXPORT_15ZILE;

END pkg_exp_henkel;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3161E4502592BD53C3A369148A6F4B9B5CC7D60</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FAZ is

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE CORELAREFAZ1;

end PKG_FAZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FISAEVALP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45747726C195B7EF93B111BD21ACE471976F811B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FisaEvalP is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_FisaEvalP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FISAEVALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C20BEF664B80794BF834A8ED97264F3C1A03C3B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FisaEvalT is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_FisaEvalT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FISATEH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>843C73F4526E549C2315AD0C4E079EB320BDCE28</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FISATEH IS

  PROCEDURE SetBlacare(aCodFisaSup in number, Blocaj in number);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_fisateh; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FORMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99F2E266399D8BC46275196111301ECD8179CC2E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FORMATII IS
  
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_FORMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FORMATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28AF72175B8A395FD1D74F463C99C68F7446CC99</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FORMATORI IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_FORMATORI; 

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUNCTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0C668BE38190159CCF7BD3DF8B6DD87D227E736</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUNCTII IS
 

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_FUNCTII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EE1E593127331D605A372B6A49D94913B0780EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZART IS

  FUNCTION GET_CODEXTERN (art IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_PRODUCATOR(art IN NUMBER) RETURN VARCHAR2;

  FUNCTION VER_ARTSERV        (artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION VER_TIPSERIE       (artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION VER_UM             (artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION FUZ_ART_ATRIB_NEDEF(artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION FUZ_ART_ATRIB_DEF  (artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION FUZ_ART_SUB        (artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER;
  FUNCTION FUZ_ART_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) RETURN NUMBER;
  FUNCTION FUZ_OBJ_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) RETURN NUMBER;
  PROCEDURE CLR_TMP;
  PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SWITCH_FUZ(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  FUNCTION GET_CRS_GEN_FUZIONARE_CODEXT(p_nr_inreg IN NUMBER DEFAULT 0) RETURN sys_refcursor;
  FUNCTION GET_CRS_GEN_FUZIONARE_CODINT(p_nr_inreg IN NUMBER DEFAULT 0) RETURN sys_refcursor;
  PROCEDURE GENERARE_LISTA_FUZIONARE(
    p_userid            IN NUMBER,
    p_userstr           IN VARCHAR2,
    p_criteriu_filtrare IN NUMBER DEFAULT 0,
    p_nr_inreg          IN NUMBER DEFAULT 0
  );

END PKG_FUZART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C80AF5462D77CB76AA2EAF43D387FC20BF268B23</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZAUTO is

	PROCEDURE FUZ_AUTO_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE CLR_TMP;
  PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);

end PKG_FUZAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AF23962377F182FE9E95E682141153BB379A0EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZGEST IS
  
	FUNCTION GET_SUBUNIT(gest IN NUMBER) RETURN VARCHAR2;
	FUNCTION VER_SUBUNIT(gestinit IN NUMBER, gestfin IN NUMBER) RETURN NUMBER;
	FUNCTION FUZ_GEST_SUB(gestinit IN NUMBER, gestfin IN NUMBER) RETURN BOOLEAN;
  --FUNCTION CLASA9OK(gest IN NUMBER) RETURN BOOLEAN;
  FUNCTION VER_CLASA9(gestinit IN NUMBER, gestfin IN NUMBER) RETURN NUMBER;
	PROCEDURE FUZ_GEST_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE CLR_TMP;
	PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	
END PKG_FUZGEST; 

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>635C36562A1212C1BBD2F2C3ECBEF090C7FC58F1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZLOCALIT IS

	FUNCTION GET_SIMBAUTO(localit IN NUMBER) RETURN VARCHAR2;
	FUNCTION GET_DENSUP(localit IN NUMBER) RETURN VARCHAR2;
	PROCEDURE FUZ_LOCALIT_SUB(localitinit IN NUMBER, localitfin IN NUMBER);
	PROCEDURE FUZ_LOCALIT_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE CLR_TMP;
	PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);

END PKG_FUZLOCALIT; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>099CDECA1C504FC6FF68FA89746A4C4230C73B1F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZPART IS

  FUNCTION GET_CODFISC(codpartener IN NUMBER) RETURN VARCHAR2;
  FUNCTION TEST_CODFISC(codpartener IN NUMBER) RETURN NUMBER;
  FUNCTION FUZ_PART_SUB(codinit IN NUMBER, codfin IN NUMBER) RETURN BOOLEAN;
  FUNCTION FUZ_LOC_SUB(codpart IN NUMBER, locinit IN NUMBER, locfin  IN NUMBER) RETURN BOOLEAN;
  PROCEDURE FUZ_PART_MAIN(p_codinit IN NUMBER, p_codfin IN NUMBER, p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE FUZ_LOC_MAIN (p_codinit IN NUMBER, p_codfin IN NUMBER, p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE CLR_TMP;
  PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SWITCH_FUZ(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE GENERARE_LISTA_FUZIONARE(p_userid IN NUMBER, p_userstr IN VARCHAR2, p_criteriu_filtrare IN NUMBER DEFAULT 0, p_nr_inreg IN NUMBER DEFAULT 0);
END PKG_FUZPART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_FUZPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E0D2E39EE936D7319FFA55390327750EA0C1EAD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_FUZPERS IS

	FUNCTION GET_SUBUNIT(pers IN NUMBER) RETURN VARCHAR2;
	FUNCTION VER_SUBUNIT(persinit IN NUMBER, persfin IN NUMBER) RETURN NUMBER;
	FUNCTION FUZ_PERS_SUB(persinit IN NUMBER, persfin IN NUMBER) RETURN BOOLEAN;
	PROCEDURE FUZ_PERS_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2);
	PROCEDURE CLR_TMP;
	PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);
  PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2);

END PKG_FUZPERS;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GAMEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B6CE129FBCD9ABD7A26E0A807F5592FCDA3C252</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GAMEART is
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_GAMEART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GENCMDF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8361773BFF95F6537D9682B5715084EFA0E50A0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GENCMDF is

PROCEDURE PreiaDate(aCodPart in number, acodlocatie in number default 0);
procedure ClearTemp;
procedure SalvareDate;

end PKG_GENCMDF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GENERARE_CODURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45F6C37FCA29396D23DB6FBAF0BDDAB4044FE82B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GENERARE_CODURI IS

-- IDSEDIU
FUNCTION GET_NEXT_IDSEDIU(aUSERID IN NUMBER) RETURN VARCHAR2;
PROCEDURE UNLOCK_IDSEDIU(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_IDSEDIU(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;



-- PARTENERI
FUNCTION GET_NEXT_CODINTERN_PART(aUSERID IN NUMBER) RETURN VARCHAR2;
PROCEDURE UNLOCK_CODINTERN_PART(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_CODINTERN_PART(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;



FUNCTION GET_NEXT_CODEXTERN_PART(aUSERID IN NUMBER) RETURN NUMBER;
PROCEDURE UNLOCK_CODEXTERN_PART(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_CODEXTERN_PART(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;


--ARTICOLE
FUNCTION GET_NEXT_CODEXTERN_ART(aUSERID IN NUMBER) RETURN NUMBER;
PROCEDURE UNLOCK_CODEXTERN_ART(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_CODEXTERN_ART(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;

FUNCTION GET_NEXT_CODINTERN_ART(aUSERID IN NUMBER) RETURN NUMBER;
PROCEDURE UNLOCK_CODINTERN_ART(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_CODINTERN_ART(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;


-- MARCA PERSONAL
FUNCTION GET_NEXT_MARCA_PERS(aUSERID IN NUMBER) RETURN NUMBER;
PROCEDURE UNLOCK_MARCA_PERS(aUSERID IN NUMBER);
FUNCTION CAN_LOCK_MARCA_PERS(aCOD IN NUMBER, aUSERID IN NUMBER) RETURN NUMBER;



-- GENERARE ALL - ARTICOLE
PROCEDURE GEN_ALL_ART_CODEXTERN_UNIC(aUSERID IN NUMBER);
PROCEDURE GEN_ALL_ART_CODINTERN_UNIC(aUSERID IN NUMBER);


-- GENERARE ALL - PARTENERI
PROCEDURE GEN_ALL_PART_CODEXTERN_UNIC(aUSERID IN NUMBER);
PROCEDURE GEN_ALL_PART_CODINTERN_UNIC(aUSERID IN NUMBER);


PROCEDURE UPDATE_CODEXTERN_ART_FROM_TMP;
PROCEDURE UPDATE_CODINTERN_ART_FROM_TMP;

end PKG_GENERARE_CODURI; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GENNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>284817DF1C70D47EA580D965E87AC83E9A84CFB6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GENNP is

  procedure UPDATECMD1DINMAN;
  procedure ClearCrs;
  procedure ClearMan;
  procedure ClearTemps;
  procedure GetCrsArt;
  procedure GetCrsRez;
  procedure GetCrsMan(vDataRap in varchar2);
  procedure GetCrsMat(FromPF in NUMBER);
  procedure GetCrsMatC;
  procedure UmpleTemporare(aCodGest in number, aCodGestT in number);
  procedure ActualizeazaCmdMan(aCodCmdProdMan in number, aCant in number, aUserID in number);
  procedure ActualizeazaCmd1(aCodProgramF1 in number,
                             aCodComanda1 in number,
                             aCodObiect in number,
                             aPrioritate in number,
                             aCodGest in number,
                             aCodPers in number,
                             aCodFormatie in number,
                             aSchimb in number,
                             aTermen in varchar2,
                             aCant in number,
                             aUserID in number,
                             aRebut in number);
  procedure CORECTIETERMENI;

end PKG_GENNP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GLOBALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>165F2BCBFD432B0CD49D20F3A881B2C7E42E89AA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GLOBALS IS

  DATACALCULSTOC DATE;
  DATASOLDPART   DATE;
  DATASOLDBANCI  DATE;
  DATA0          DATE := to_date(&apos;30.12.1899&apos;, &apos;dd.mm.yyyy&apos;);
  DATADEAZI      DATE := SYSDATE;

  lstDATASTART   DATE;
  lstDATASTOP    DATE;
  lstANSTART     Number(4) := 0;
  lstANSTOP      Number(4) := 0;
  lstLUNASTART   Number(2) := 0;
  lstLUNASTOP    Number(2) := 0;
--interval1
  lstDATASTART1  DATE;
  lstDATASTOP1   DATE;
  lstANSTART1    Number(4) := 0;
  lstANSTOP1     Number(4) := 0;
  lstLUNASTART1  Number(2) := 0;
  lstLUNASTOP1   Number(2) := 0;
--interval2
  lstDATASTART2  DATE;
  lstDATASTOP2   DATE;
  lstANSTART2    Number(4) := 0;
  lstANSTOP2     Number(4) := 0;
  lstLUNASTART2  Number(2) := 0;
  lstLUNASTOP2   Number(2) := 0;
--interval3
  lstDATASTART3  DATE;
  lstDATASTOP3   DATE;
  lstANSTART3    Number(4) := 0;
  lstANSTOP3     Number(4) := 0;
  lstLUNASTART3  Number(2) := 0;
  lstLUNASTOP3   Number(2) := 0;
--interval4
  lstDATASTART4  DATE;
  lstDATASTOP4   DATE;
  lstANSTART4    Number(4) := 0;
  lstANSTOP4     Number(4) := 0;
  lstLUNASTART4  Number(2) := 0;
  lstLUNASTOP4   Number(2) := 0;
--interval5
  lstDATASTART5  DATE;
  lstDATASTOP5   DATE;
  lstANSTART5    Number(4) := 0;
  lstANSTOP5     Number(4) := 0;
  lstLUNASTART5  Number(2) := 0;
  lstLUNASTOP5   Number(2) := 0;

--valori
  lstVal1 VARCHAR2(100);
  lstVal2 VARCHAR2(100);
  lstVal3 VARCHAR2(100);
  lstVal4 VARCHAR2(100);
  lstVal5 VARCHAR2(100);

  MasterID       NUMBER(18) := null;
  USERID         NUMBER(18);
  USERNAME       VARCHAR(100);

  ConnectionIndex NUMBER(20) := 0;


  FIRMANAME VARCHAR(20);
  FIRMA_LONG_NAME VARCHAR2(100);
  FIRMA_ID VARCHAR(20);
  CODFIRMA NUMBER(20);

  LUNA_START_AN_CONTABIL NUMBER(2) := 1;

  DREPTSALARIZARE NUMBER(1) := 0;

  ZECIMALE_AMORTIZARE  Number(5) := -1;
  DEFAZAJ_AVIZ_IN  Number(5) := -1;
  DEFAZAJ_AVIZ_Out Number(5) := -1;

  SUBUNITATE NUMBER(20) := 1;
  SUBUNITATE_DOC NUMBER(20);

  ANINITIAL NUMBER(18);
  LUNAINITIALA NUMBER(18);

  ANCURENT NUMBER(18);
  LUNACURENTA NUMBER(18);

  ANMAXIM NUMBER(18);
  LUNAMAXIMA NUMBER(18);

  ANLUCRU NUMBER(18);
  LUNALUCRU NUMBER(18);

  ANTEMP NUMBER(18);
  LUNATEMP NUMBER(18);

  ANPRECEDENT NUMBER(18);
  LUNAPRECEDENTA NUMBER(18);

  ANBLOCAT NUMBER(4);
  LUNABLOCATA NUMBER(2);

  LUNARECORDSFLAG number(1) := 0;

  EXE_VERSION VARCHAR2(20);

  RECID_DOC_LISTARE NUMBER(20) := 0;
  OldRECID_DOC_LISTARE NUMBER(20) := 0;

  DEBUGMODE number(1);

  FILTRARE_STOC_VAL NUMBER(1) := 0;
  FILTRU_GEST_STOCVAL       NUMBER(20)    := 0;
  FILTRU_CODIOART_STOCVAL   NUMBER(20)    := 0;
  FILTRU_PROCTVA_STOCVAL    NUMBER(20, 7) := 0;
  FILTRU_DATALIMITA_STOCVAL VARCHAR2(10)  := &apos;&apos;;

  SEP VARCHAR2(20) := &apos;,&apos;; -- folosita ca seperator la concatenari ptr.functia
                           -- STRING_AGG
  CODCANAMED NUMBER(20);


  CODLIMBADENART NUMBER(20) := 0;

  PROCEDURE set_CODCANAMED (aCod IN NUMBER);
  FUNCTION Get_CODCANAMED RETURN NUMBER;

  TIPDOCIMPORTAT     Number(18)  := 0;
  TipIntrare         Number(18);
  TipIesire          Number(18);
  TipMiscareInterna  Number(18);
  TipComanda         Number(18);
  TipOferta          Number(18);
  TipPromotie        Number(18);
  TipContract        Number(18);
  TipDocCasaBanca    Number(18);
  CodDocCasaBanca    Number(20);
  PretPentruRetail   NUMBER(1) := 0;

  g_SplitTVAFirma    NUMBER(1) := 0;

  vCodGest number(20);
  vDataInventar Date;
  vToateArt number(1);
  vToateCont number(1);
  vToateClasele number(1);
  vToateClaseleS number(1);
  vToateProd number(1);
  vCodInventar number(20);

  function NrZileLibere(data1 in varchar2, data2 in varchar2) return number;
  FUNCTION isToateArt RETURN NUMBER;
  FUNCTION isToateClasele RETURN NUMBER;
  FUNCTION isToateClaseleS RETURN NUMBER;
  FUNCTION isToateProd RETURN NUMBER;
  FUNCTION isToateConturile RETURN NUMBER;
  FUNCTION GETCODGEST RETURN NUMBER;
  FUNCTION GETDATAINVENTAR RETURN DATE;
  FUNCTION GETCODINVENTAR RETURN NUMBER;
  procedure setparams_inventar(aCodInventar in number);

  TYPE aCURSOR IS REF CURSOR;

  procedure SetDataDeAzi(oData in varchar2);
  function GetDataDeAzi return date;

  PROCEDURE SETDEBUGMODE(aMode in boolean);
  FUNCTION ISDEBUGMODE RETURN NUMBER;

  procedure SetPretPentruRetail(TipPret in number);
  function GetSeparatorAdancime return char;
  procedure ResetAllRecordsLunaFlags;
  PROCEDURE SET_DREPT_SALARIZARE(aDrept in boolean);
  FUNCTION GET_DREPT_SALARIZARE return NUMBER;

  PROCEDURE GetCodObiect;
  FUNCTION DEL_INTRARE_DOCS(pAN IN NUMBER, pLUNASTART IN NUMBER, pLUNASTOP IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_EXE_VERSION (AVER IN VARCHAR2);
  FUNCTION GET_EXE_VERSION RETURN VARCHAR2;

  PROCEDURE SET_RECID_DOC_LISTARE( pRECID IN NUMBER);
  FUNCTION GET_RECID_DOC_LISTARE RETURN NUMBER;
  PROCEDURE Restore_OLDRECID_DOC_LISTARE;

  PROCEDURE UPDATe_mesaj_avarie(pID IN NUMBER);
  FUNCTION check_messages (tip OUT NUMBER,cnt OUT NUMBER,idmess OUT NUMBER) RETURN VARCHAR2;


  function  GETMASTER_OR_USERID RETURN NUMBER;
  procedure SETMasterID(aUserID IN NUMBER);

  function GETUSERID RETURN NUMBER;
  procedure SETUSERID(aUserID IN NUMBER);

  PROCEDURE SETSUBUNITATE_DOC (asubunitate NUMBER);
  FUNCTION  GETSUBUNITATE_DOC  RETURN NUMBER;

  FUNCTION SUBUNITATEDOC_VALIDA(ASUBUNITATE IN NUMBER) RETURN NUMBER;

  FUNCTION GETPREFIXDOC(aTIPDOC IN NUMBER) RETURN VARCHAR2;


  function GETSUBUNITATE RETURN NUMBER;
  procedure SETSUBUNITATE(aSUBUNITATE IN NUMBER);


  PROCEDURE SETUSERNAME(aUSERNAME IN VARCHAR2);
  FUNCTION GETUSERNAME RETURN VARCHAR2;

  PROCEDURE SETFIRMANAME(aFIRMANAME IN VARCHAR2);
  PROCEDURE SETFIRMA_LONG_NAME(aFIRMA_LONG_NAME IN VARCHAR2);
  PROCEDURE SETFIRMA_ID(aFIRMA_ID IN VARCHAR2);
  FUNCTION GETFIRMA_ID RETURN VARCHAR2;

  PROCEDURE SET_TIPDOC_IMPORTAT(aTIPDOC IN NUMBER);
  FUNCTION  GET_TIPDOC_IMPORTAT RETURN NUMBER;


  procedure SetLunaLucru(An in Number, Luna in Number, EsteMaster in number default 0);
  function  AnLunaLucru return Number;

  function  GetAnInitial return Number;
  FUNCTION GETLUNAINITIALA RETURN NUMBER;

  function  GetANLUCRU return Number;
  function  GetLUNALUCRU return Number;



  procedure SetLunaTemp(An in Number, Luna in Number);
  function  GetANTEMP return Number;
  function  GetLUNATEMP return Number;


  procedure SetLunaPRECEDENTA(An in Number, Luna in Number);
  function  GetANPRECEDENT return Number;
  function  GetLUNAPRECEDENTA return Number;

  PROCEDURE SetAnLunaBlocata(An in number, Luna in number);

  procedure getAnLunaBlocata(an out number,luna out number);

  function  getAnBlocat return number;
  function  getLunaBlocata return number;

  procedure SetSeparator(aSep in VarChar2);

  procedure SetTipIntrare(aTip in Number);
  function  GetTipIntrare return Number;


  procedure SetTipIesire(aTip in Number);
  function  GetTipIesire  return Number;

  procedure SetTipMiscareInterna(aTip in Number);
  function  GetTipMiscareInterna return Number;

  procedure SetTipComanda(aTip in Number);
  function  GetTipComanda  return Number;

  procedure SetTipOferta(aTip in Number);
  function  GetTipOferta  return Number;

  procedure SetTipPromotie(aTip in Number);
  function  GetTipPromotie  return Number;

  procedure SetTipContract(aTip in Number);
  function  GetTipContract  return Number;

  procedure SetTipDocCasaBanca(aTip in Number, aCod in number default 0);
  function  GetTipDocCasaBanca  return Number;
  function  GetCodDocCasaBanca  return Number;

  procedure CLEARTABLE(TableName varchar2);
  PROCEDURE CLEAR_TABLE_AND_COMMIT(TableName varchar2);

  procedure CALCULEAZA_LUNA_PRECEDENTA(An IN Number, Luna IN Number, NewAn OUT NUMBER, NewLUNA OUT NUMBER);
  procedure CALCULEAZA_LUNA_URMATOARE(An IN Number, Luna IN Number, NewAn OUT NUMBER, NewLUNA OUT NUMBER);

--  function SimbolContOblig(semnif in number, col_idx in number, codio in number) return varchar;
  function GET_CONT_CONTABIL_OBLIG(semnif in number, col_idx in number, codio in number) RETURN NUMBER;

  FUNCTION ACTUALCONST RETURN NUMBER;
  PROCEDURE CHECK_CONSTANTE_USER;
  FUNCTION GET_REST_PLATA_DOC(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN NUMBER;
--  PROCEDURE CREATE_TEMPORARY_TABLE(SURSA_TABLE_NAME IN VARCHAR2, DEST_TABLE_NAME IN VARCHAR2);

  procedure ResetJobOk;
  FUNCTION GETFIRMAVERSION(aJobOk out number)  RETURN NUMBER;
  PROCEDURE SETFIRMAVERSION(VER IN NUMBER);
-- functii pentru generator facturi
  PROCEDURE LOCK_STOC_CANT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER);
  PROCEDURE UNLOCK_STOC_CANT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER);
  PROCEDURE RELEASE_ALL_STOCLOCK;
  PROCEDURE RELEASE_ALL_STOCLOCK_GEST;
  FUNCTION GET_STOC_REAL(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER) RETURN NUMBER;

-- Functii pentru Emulare tastatura
  FUNCTION GET_STOC_REAL_EMUL(aCODOBIECT IN NUMBER,
                              aCODGEST IN NUMBER,
                              aCODIOART IN NUMBER,
                              aPRET IN NUMBER) RETURN NUMBER;
  FUNCTION GET_STOC_REAL_EMUL_CUMULAT(aCODOBIECT IN NUMBER,
                              aCODGEST IN NUMBER,
                              aCODIOART IN NUMBER
                              ) RETURN NUMBER;
  PROCEDURE LOCK_STOC_CANT_EMUL(aCODEMULARE1 IN NUMBER,
                                aCODOBIECT   IN NUMBER,
                                aCODGEST     IN NUMBER,
                                aCODIOART    IN NUMBER,
                                aPRET        IN NUMBER,
                                aCANT        IN NUMBER);


  PROCEDURE UNLOCK_STOC_CANT_EMUL(aCODEMULARE1 IN NUMBER);

  PROCEDURE RELEASE_ALL_STOCLOCK_EMUL;
  PROCEDURE LOCK_STOC_EMULEDITAT(aCODEMULARE IN NUMBER);
  PROCEDURE RELEASE_STOC_EMULEDITAT;

  PROCEDURE RELEASE_ALL_STOCLOCK_EMUL_EXT;
  PROCEDURE RELEASE_STOC_EMULEDITAT_EXT;

  PROCEDURE SET_FILTRARE_STOC_VAL(FILTRARE IN NUMBER);
  PROCEDURE SET_VALORI_FILTRU_STOC_VAL(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER, aDATALIMITA IN VARCHAR2);
  FUNCTION FILTRU_STOCVAL_TRANZACTII_OK(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER, aDATADOC IN DATE) RETURN NUMBER;
  FUNCTION FILTRU_STOCVAL_LUNAPREC_OK(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER) RETURN NUMBER;

  FUNCTION GET_SEQ_NEXTVAL(sSEQ IN VARCHAR2) RETURN NUMBER;

  -- echivalente import PDX ... ORACLE
  PROCEDURE UPDATE_COD_ECHIVALENT_ORACLE(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, KODORACLE IN NUMBER);
  FUNCTION GET_COD_ECHIVALENT_ORACLE(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2) RETURN NUMBER;

  PROCEDURE LOCK_VALSTINSA_OBLIGPIF(aCODOBLIGPIF IN NUMBER, aCODOBLIGSTINGATOR IN NUMBER, aVALOARE IN NUMBER);
  PROCEDURE UNLOCK_VALSTINSA_OBLIGPIF(aCODOBLIGPIF IN NUMBER, aCODOBLIGSTINGATOR IN NUMBER);
  PROCEDURE RELEASE_ALL_OBLIGPIFLOCK;
  -- BLOCARE CANTITATI LA STINGERE COMENZI--
  PROCEDURE LOCK_CANTSTINSA_CMD(aCODLINIECOMANDA IN NUMBER, aCODLINIESTINGATOARE IN NUMBER, aCANT IN NUMBER);
  PROCEDURE UNLOCK_CANTSTINSA_CMD(aCODLINIECOMANDA IN NUMBER, aCODLINIESTINGATOARE IN NUMBER);
  PROCEDURE RELEASE_ALL_CMDCANTLOCK;
  FUNCTION GET_CANTCMD_REALA(aCODLINIECOMANDA IN NUMBER) RETURN NUMBER;
  FUNCTION CANTCMD_PRELUATA_ALTI_USERI(aCODLINIECOMANDA IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_JURNREFAC_FLG(FLAG NUMBER);
  PROCEDURE CLEAR_JURNREFAC_FLG;

  function  Flag_OK_RefacereJurnal(aTip in number) return number ;
  PROCEDURE ClearFlag_RefacereJurnal(Unu in number);

  FUNCTION DOCINTRARE_ARE_STOC_IN_LUNA(aCODDOC IN NUMBER, aTIPDOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER;
  FUNCTION DOCINTRARE_ARE_SOLD_IN_LUNA(aCODDOC IN NUMBER, aTIPDOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER;
  PROCEDURE PUT_LINE(LINE IN VARCHAR2);
  PROCEDURE PUT_INFO(pINFOLINE IN VARCHAR2, pDETALII CLOB);
  PROCEDURE MAKE_IOPART_LUNA;
  FUNCTION GETDATACALCULSTOC RETURN DATE;
  FUNCTION GETDATASOLDPART RETURN DATE;

  FUNCTION GET_COD_ECHIVALENT_ORACLE_WM(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, aSUBUNIT IN NUMBER) RETURN NUMBER;
  PROCEDURE UPDATE_COD_ECHIV_ORACLE_WM(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, KODORACLE IN NUMBER, aSUBUNIT IN NUMBER);

  FUNCTION GETDATASOLDBANCI RETURN DATE;
  PROCEDURE CHECK_ARTICOLE_FARA_OBIECT0;

  PROCEDURE SETPARAMS_CUSTOM(aListID IN NUMBER, aListVER IN NUMBER);
  FUNCTION DATASTART      RETURN DATE ;
  FUNCTION DATASTOP       RETURN DATE ;
  FUNCTION ANSTART        RETURN NUMBER;
  FUNCTION ANSTOP         RETURN NUMBER;
  FUNCTION LUNASTART      RETURN NUMBER;
  FUNCTION LUNASTOP       RETURN NUMBER;
  FUNCTION ANLUNASTART         RETURN NUMBER;
  FUNCTION ANLUNASTOP          RETURN NUMBER;

  FUNCTION DATASTARTInterval1      RETURN DATE ;
  FUNCTION DATASTOPInterval1       RETURN DATE ;
  FUNCTION ANSTARTInterval1        RETURN NUMBER;
  FUNCTION ANSTOPInterval1         RETURN NUMBER;
  FUNCTION LUNASTARTInterval1      RETURN NUMBER;
  FUNCTION LUNASTOPInterval1       RETURN NUMBER;
  FUNCTION ANLUNASTARTInterval1         RETURN NUMBER;
  FUNCTION ANLUNASTOPInterval1          RETURN NUMBER;

  FUNCTION DATASTARTInterval2      RETURN DATE ;
  FUNCTION DATASTOPInterval2       RETURN DATE ;
  FUNCTION ANSTARTInterval2        RETURN NUMBER;
  FUNCTION ANSTOPInterval2         RETURN NUMBER;
  FUNCTION LUNASTARTInterval2      RETURN NUMBER;
  FUNCTION LUNASTOPInterval2       RETURN NUMBER;
  FUNCTION ANLUNASTARTInterval2         RETURN NUMBER;
  FUNCTION ANLUNASTOPInterval2          RETURN NUMBER;

  FUNCTION DATASTARTInterval3      RETURN DATE ;
  FUNCTION DATASTOPInterval3       RETURN DATE ;
  FUNCTION ANSTARTInterval3        RETURN NUMBER;
  FUNCTION ANSTOPInterval3         RETURN NUMBER;
  FUNCTION LUNASTARTInterval3      RETURN NUMBER;
  FUNCTION LUNASTOPInterval3       RETURN NUMBER;
  FUNCTION ANLUNASTARTInterval3         RETURN NUMBER;
  FUNCTION ANLUNASTOPInterval3          RETURN NUMBER;

  FUNCTION DATASTARTInterval4      RETURN DATE ;
  FUNCTION DATASTOPInterval4       RETURN DATE ;
  FUNCTION ANSTARTInterval4        RETURN NUMBER;
  FUNCTION ANSTOPInterval4         RETURN NUMBER;
  FUNCTION LUNASTARTInterval4      RETURN NUMBER;
  FUNCTION LUNASTOPInterval4       RETURN NUMBER;
  FUNCTION ANLUNASTARTInterval4         RETURN NUMBER;
  FUNCTION ANLUNASTOPInterval4          RETURN NUMBER;

  FUNCTION DATASTARTInterval5      RETURN DATE ;
  FUNCTION DATASTOPInterval5       RETURN DATE ;
  FUNCTION ANSTARTInterval5        RETURN NUMBER;
  FUNCTION ANSTOPInterval5         RETURN NUMBER;
  FUNCTION LUNASTARTInterval5      RETURN NUMBER;
  FUNCTION LUNASTOPInterval5       RETURN NUMBER;
  FUNCTION ANLUNASTARTInterval5         RETURN NUMBER;
  FUNCTION ANLUNASTOPInterval5          RETURN NUMBER;

  FUNCTION valoareNumeric1     RETURN NUMBER;
  FUNCTION valoareNumeric2     RETURN NUMBER;
  FUNCTION valoareNumeric3     RETURN NUMBER;
  FUNCTION valoareNumeric4     RETURN NUMBER;
  FUNCTION valoareNumeric5     RETURN NUMBER;
  FUNCTION valoareChar1           RETURN VARCHAR;
  FUNCTION valoareChar2           RETURN VARCHAR;
  FUNCTION valoareChar3           RETURN VARCHAR;
  FUNCTION valoareChar4           RETURN VARCHAR;
  FUNCTION valoareChar5           RETURN VARCHAR;


  PROCEDURE SETCODFIRMA(aCODFIRMA IN NUMBER);
  FUNCTION GETCODFIRMA RETURN NUMBER;
  PROCEDURE RECALCUL_DISCMAJ_IES(aCODIES IN NUMBER);
  PROCEDURE RECALCUL_AVARIE_INTR(aCODINTR IN NUMBER);
  FUNCTION GET_DISC_IES1(aCODIES1 IN NUMBER, aCodIes IN NUMBER, aCodCriteriu IN NUMBER) RETURN NUMBER;
  FUNCTION ISNUMERIC (P_STRING_VALUE IN VARCHAR2)RETURN NUMBER;

  FUNCTION  GetPMPCodIes RETURN NUMBER ;
  FUNCTION  GetPMPCodIntr RETURN NUMBER ;
  FUNCTION  GetPMPCodTransf RETURN NUMBER ;
  procedure SetPMPCodDocs(aCodIntr in number, aCodIes in number, aCodTransf in number );

  function  GET_DEFAZAJ_AVIZ_IN  return Number;
  function  GET_DEFAZAJ_AVIZ_OUT return Number;
  function  GET_ZECIMALE_AMORTIZARE return Number;
  FUNCTION  ANLUNAAVIZOK(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN NUMBER;
  PROCEDURE SET_DIMENSIUNI_NIRSTOC(aCODOBIECT IN NUMBER, aD1 IN NUMBER, aD2 IN NUMBER, aD3 IN NUMBER);
  PROCEDURE SET_DIMENSIUNI_PRODCOMP(aCODOBIECT IN NUMBER, aD1 IN NUMBER, aD2 IN NUMBER, aD3 IN NUMBER);

  PROCEDURE SET_LUNA_START_AN_CONTABIL(aLUNA IN NUMBER);
  FUNCTION GET_LUNA_START_AN_CONTABIL RETURN NUMBER;
  FUNCTION GET_AN_SOLDCONT_INI RETURN NUMBER;

  procedure SetLunaLucru_SIMPLA(An in Number, Luna in Number);

  procedure StartEvolutie(aID in number, aUserID in number, aTotal in number, aActiune in varchar2);
  procedure SetEvolutie(aID in number, aUserID in number, aCurent in number);
  procedure GetEvolutie(aID in number, aUserID in number, aTotal out number, aFacute out number);

  procedure SetLunaLucruAplOnline(An in Number, Luna in Number, EsteMaster in number default 0);

  PROCEDURE MarkDirtyJurnal;
  PROCEDURE ClearDirtyJurnal;
  function  DIRTYJURNAL_COUNT return number;
  FUNCTION ACCES_LA_GESTIUNEA(aGEST IN NUMBER) RETURN NUMBER;
  FUNCTION IS_SUBCLAS_OF(aCLASA IN NUMBER, MASTERCLAS IN NUMBER) RETURN NUMBER;
  FUNCTION STARE_APROBARI(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN VARCHAR2;

  PROCEDURE SETLIMBADENART;
  FUNCTION  GETLIMBADENART  RETURN NUMBER;

  PROCEDURE GET_LAST_MODI_PRET(aCODNIRSTOC_IN   IN NUMBER,
                              aCODNIRSER_IN    IN NUMBER,
                              aCODNIRSTOC_OUT OUT NUMBER,
                              aCODNIRSER_OUT  OUT NUMBER,
                              aPRET_OUT       OUT NUMBER,
                              aADAOS_OUT      OUT NUMBER
                              );
  FUNCTION GET_STOC_REAL_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, IGNOR_REZERVARI IN NUMBER DEFAULT 0 )RETURN NUMBER;
  procedure RESET_TMP_CONTCHELTAVANS;
  procedure RESET_TMP_CONTVENITAVANS;

  procedure SetDirectiva(oDirectiva in varchar2);
  function Directiva(oDirectiva in varchar2) return boolean;

  procedure clear_x;
  procedure baga_in_x(ceva in varchar2);

  PROCEDURE SETUSERDOC;

  function testParamListe return number;
  FUNCTION GETSERIINIRSTOC(aCODNIRSTOC IN NUMBER) RETURN VARCHAR2;
  FUNCTION GETSERIINIRNEOPERAT(aCODNIRSTOC IN NUMBER) RETURN VARCHAR2;

  FUNCTION ACCES_LA_GESTIUNEA_EXT(aGEST IN NUMBER) RETURN NUMBER;

  PROCEDURE LOCK_STOC_CANT_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER);
  PROCEDURE UNLOCK_STOC_CANT_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER);

  procedure CheckDebugMode(aSQL in CLOB, aListID in number, aListVer in number);
  procedure ClearDebugListe;
  FUNCTION BITOR (x IN NUMBER, y IN NUMBER) RETURN NUMBER;

  PROCEDURE SetDocExportatEdi (pTipDoc IN NUMBER, pCodDoc IN NUMBER);
  FUNCTION GetPretPentruRetail RETURN NUMBER;
  PROCEDURE LOCK_STOC_CANT_BULK;
  PROCEDURE UNLOCK_STOC_CANT_BULK;
  PROCEDURE MEMO_MODIFICARE_PRET(aCODOBIECT IN NUMBER, aCODSUBUNIT IN NUMBER);

  PROCEDURE LOCK_CANTSTINSA_AVIZ(aCODLINIEAVIZ IN NUMBER, aCODLINIEFACT IN NUMBER, aTIPAVIZ IN NUMBER, aCANT IN NUMBER);
  PROCEDURE UNLOCK_CANTSTINSA_AVIZ(aCODLINIEAVIZ IN NUMBER, aCODLINIEFACT IN NUMBER, aTIPAVIZ IN NUMBER);
  PROCEDURE RELEASE_ALL_AVIZCANTLOCK(aTIPAVIZ IN NUMBER);

  procedure SetConnectionIndex(aConnIndex IN NUMBER);
  FUNCTION GetConnectionIndex return Number;

	PROCEDURE PrepareTest(S IN NUMBER, A IN NUMBER, L IN NUMBER);


END PKG_GLOBALS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GRECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>848177DA52A0CD73F2935E2F29BAA96994BA4C97</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GRECHIV IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE GET_INFO_PARITATI(ACODOBIECT IN NUMBER,APARITATE OUT NUMBER,APARITATE_GENERIC OUT NUMBER, ADENUMIRE OUT VARCHAR2, ADENUM OUT VARCHAR2);
  FUNCTION GET_DENOBIECT_GENERIC (ACodGrupa  in number) return varchar2 ; 
end pkg_grechiv; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_GRUPEDRUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>288764135ABB5277E1275486B1CBA73A565DD595</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_GRUPEDRUM is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_GRUPEDRUM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IDENTEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>499EEF58C8885AEB6C9DAC8411982F1322A2029C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IdentEvalS is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_IdentEvalS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03C4883DB7DA2DE018EB2143E677DDF06FE37268</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IESIRI IS

  PartenerAviz NUMBER(18) := 0;
  vDataDoc Date;
-- flaguri
  Flag_SetValFin       NUMBER(1) := 1;
  Flag_AvizTVAColectat NUMBER(1) := 2;
-- memoreaza CARNETDOC si NRDOC la intrarea pe macheta
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  CARNETDOC_C NUMBER(20);
  NRDOC_C     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER, aNRCERTIF IN NUMBER, aCARNETCERTIF IN NUMBER);
  PROCEDURE REZOLVA_CARNET_CERTIF(ACARNETDOC IN NUMBER, ANRDOC IN NUMBER, ACODIES IN NUMBER);
  CURS_IN     NUMBER(20, 7);

  PROCEDURE Service_Preluat;
  function GetLinieComCli(aCODCOMANDA1 in number) return number;
  function GetLinieComInt(CodObiect  in NUMBER, OBS in Varchar2, NewObs out varchar2) return number;

  PROCEDURE SETDATADOC(aZI in Number, aLuna in Number, aAn in Number);
  FUNCTION  GETDATADOC RETURN DATE;
  PROCEDURE DISTRIBUIE_DIFERENTA_FACTURA(aCODIES IN NUMBER, DIFERENTE IN NUMBER);
  PROCEDURE PREIA_ATASAMENTE_COMENZI(aCODDOC IN NUMBER, aTIPDOC IN NUMBER);

  PROCEDURE SetValFin(RecId IN NUMBER, pForce IN NUMBER DEFAULT 0);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION AMFACTURALAAVIZ(CODAVIZ  IN NUMBER) RETURN NUMBER;
  FUNCTION LINIEAVIZSTINSA(aCODIES1 IN NUMBER) RETURN NUMBER;
  FUNCTION LINIEAVIZSTINSA_EXT(ACODIES1 IN NUMBER) RETURN NUMBER;
  PROCEDURE SETPARTENERAVIZ(aPart in NUMBER);
  FUNCTION CONDITIE_PART_AVIZ(aPart in NUMBER) RETURN NUMBER;

  FUNCTION NR_LIVRARI_DIN_IESIRIINROSU(aCODIES IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER;
  FUNCTION STOC_NEG_LA_STERGERE_LIVR_ROSU(aCODIES IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER;
  FUNCTION STOC_NEG_LASTERGERE_LIVR1_ROSU(aCODLIVR1 IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIR_IESROSU(aCodNirStoc IN NUMBER, aCODIES IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_LA_NIR_IESROSU(aCodNirStoc IN NUMBER, aCODIES IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RECID OUT NUMBER );
  PROCEDURE EMPTY_IESIRI_TEMPTABLES;

  procedure EXEC_DEBUG;

  FUNCTION CONDITIE_FACTURA_OPERATA(aOPERAT IN NUMBER, aConstValue in NUMBER) RETURN NUMBER;
  PROCEDURE MAKE_LIVRARI_AVIZE;
  PROCEDURE SOLVE_OBINV(aCODIES IN NUMBER, aCODCLASIF IN NUMBER );
  PROCEDURE SOLVE_DIMINUARE_OBINV(aCODIES IN NUMBER );

  PROCEDURE CHECK_COERENTA_NIRNOU_MF(aCODDOC IN NUMBER, aTIPDOC IN NUMBER);
  FUNCTION GETPROCTVALINIE(aCODLINIEDOCIMP IN NUMBER, PROCTVAIMPLICIT IN NUMBER) RETURN NUMBER;
  procedure CheckOldUtilaje(aCodIes in number);
  procedure RezolvUtilaje(aCodIes in number);
  procedure ClearManevraPtUtilaje;
  PROCEDURE REFA_CENTRALIZARI_PE_MONETARE;
  PROCEDURE REFA_CENTRALIZARI_PE_MONETAR(aCODMONETAR IN NUMBER);

  FUNCTION GetAmbalaje (pCodIes IN NUMBER) RETURN sys_refcursor;
  PROCEDURE PREPARE_AVIZE_CLIENTI(aCODPART IN NUMBER, ANLUNALUCRU IN NUMBER);

  PROCEDURE ANULEAZA_FACTURA(aCODIES IN NUMBER);
  procedure Set_Do_Commit(aDoCommit IN BOOLEAN);
  procedure Test_GOTO;
  FUNCTION PRETVANZARE(TIPIES IN NUMBER, ROT IN NUMBER, PRET IN NUMBER, PARITATE IN NUMBER, OPERATIE IN NUMBER) RETURN NUMBER;
  PROCEDURE STERGE_STINGERI_TREZOR(aCODIES NUMBER);
  procedure setjurnaldirty(aCodIes in number, aTipDoc in number);
  procedure CHECK_REZERVARICMD(aCodIes in number);
  procedure GetEFACTURA(aCodIes in number, aTipIes in number);
  PROCEDURE PostEFACTURA;
  PROCEDURE CHECK_MODIF_CARACT_MIFIX(aCODIES IN NUMBER);

END pkg_IESIRI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IESIRIRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C91CE5F92476475C52D568DB404E7CA919B3B11</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_iesiriretail is
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;


-- sincronizare facturi retail cu baza
  PROCEDURE MAKE_IESIRIRETAIL_FROM_IESIRI;
  PROCEDURE CLEAR_IESIRIRETAIL_TEMPS;
  PROCEDURE PREPARE_NEW_IESIRIRETAIL;
  PROCEDURE PREPARE_MODIF_IESIRIRETAIL;
  PROCEDURE DO_POST_NEWFACT_ONBAZA;
  PROCEDURE DO_POST_MODIFFACT_ONBAZA;
  PROCEDURE MUTA_CODIFICARI_PE_RETAIL;
  PROCEDURE SET_FLAG_MODIF(aCODIESRETAIL IN NUMBER);
  PROCEDURE PREPARE_TREZOR_FOR_JURNAL(aCODTREZOR NUMBER);
  
  
  FUNCTION CANLOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER) RETURN NUMBER;
  PROCEDURE LOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER);
  PROCEDURE UNLOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER);
  
  
  
end pkg_iesiriretail; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IMPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>923F64B9FF9299B44281404B8D26598B36D6C7E7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IMPORT IS

FUNCTION get_taracomunitara(pcodpart IN NUMBER) RETURN NUMBER;

PROCEDURE make_sold_part_ini;
PROCEDURE make_stocini;

PROCEDURE del_tabimpcod;

FUNCTION GET_NEW_TARA(p_den VARCHAR2, p_simbauto VARCHAR2, p_comunitarue varchar2) RETURN VARCHAR2;
FUNCTION GET_NEW_ZONA(p_den VARCHAR2, p_simb VARCHAR2, p_obs varchar2) RETURN VARCHAR2;
--FUNCTION GET_NEW_LOCALIT(p_den VARCHAR2, p_jud VARCHAR2, p_tara varchar2, p_siruta varchar2) RETURN VARCHAR2; (OLD)
FUNCTION GET_NEW_LOCALIT(p_den VARCHAR2, p_jud VARCHAR2, p_tara varchar2, p_siruta varchar2, p_zona varchar2) RETURN VARCHAR2;
end PKG_IMPORT; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IMPORTALTEAPLICATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>838687325EC2564CC91F056AD7CF71F5E3065EF4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IMPORTALTEAPLICATII IS

UMIMPLICITA          NUMBER(20)  := 0;
CLASAIMPLICITA       NUMBER(20)  := 0;
GEST_IMPLICITA       NUMBER(20)  := 0;
CODTVA_IMPLICIT      NUMBER(20)  := 0;

CODIOARTIMPLICIT     NUMBER(20)  := 0;
ROTINTRARE           NUMBER(5)   := 5;
ROTIESIRE            NUMBER(5)   := 5;
TIPINFOLUNARE        NUMBER(1)   := 0;
VANDUTLACASADEMARCAT NUMBER(1)   := 0;
V_DESCARCAREINTEGRALA  NUMBER(1)   := 0;
CARNETIMPLICIT_NT      NUMBER(20)  := 0;


SUBUNITATEIMPORT NUMBER(20) := 2;



PROCEDURE IMPORTA_VENITAVANS;
PROCEDURE PREPARE_JURNAL_CHELTAVANS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER); -- folosit la import de intrari/iesiri cand se genereaza automat cheltuieli in avans care trebuiesc contabilizate
PROCEDURE POST_JURNAL_CHELTAVANS;

PROCEDURE UPDATE_INFO_LAPARTENER(aCODOBIECT IN NUMBER, aCODPART IN NUMBER, aCODLACLIENT IN VARCHAR2, aDENLACLIENT IN VARCHAR2);
FUNCTION GETCODUM(aDENUM IN VARCHAR2) RETURN NUMBER;
FUNCTION GETCODLOCALITEXT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STIPLOCALIT IN VARCHAR2, STARA IN VARCHAR2, aSIRUTA IN VARCHAR2, NumaiTest in number default 0) RETURN NUMBER;
FUNCTION GETCODLOCALIT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STIPLOCALIT IN VARCHAR2, STARA IN VARCHAR2, NumaiTest in number default 0) RETURN NUMBER;
PROCEDURE ADAUGA_ARTICOL_NOU;
PROCEDURE ADAUGA_ARTICOL_NOU_EXT;

PROCEDURE ADAUGA_GESTIUNE_NOUA;

PROCEDURE ADAUGA_PARTENER_NOU;
PROCEDURE ADAUGA_PARTENER_NOU_EXT;
PROCEDURE CHECK_INFO_PART;
PROCEDURE MODIFICA_PARTENER;
PROCEDURE ADAUGA_NPERS;

FUNCTION GETCODSERIE(aCODOBIECT IN NUMBER , aSERIE IN VARCHAR2) RETURN NUMBER;
PROCEDURE UPDATEUTILAJ;
PROCEDURE EMPTY_NOMPART_TEMPTABLES;
FUNCTION CLONEAZA_OBIECT(aCodArticol IN NUMBER ) RETURN NUMBER;
FUNCTION VERIFICA_OBIECT_EXISTENT(aCODARTICOL IN NUMBER) RETURN NUMBER;

PROCEDURE IMPORTAPRETURIEXCEL;

PROCEDURE SETUMIMPLICITA(aUM IN NUMBER);
PROCEDURE SETCLASAIMPLICITA(aCLASA IN NUMBER);
PROCEDURE SETGESTIMPLICITA(aGEST IN NUMBER);
PROCEDURE SETCODIOARTIMPLICIT(aCODIOART IN NUMBER);
PROCEDURE SETSUBUNITATEIMPORT(aSUBUNIT IN NUMBER);
PROCEDURE SETCODTVAIMPLICIT(aCODTVA IN NUMBER);
PROCEDURE SETTIPINFOLUNARE(aTIP IN NUMBER);
PROCEDURE SETVANDUTLACASEDEMARCAT(aFLAG IN NUMBER);
PROCEDURE SETDESCARCAREINTEGRALA(aFLAG IN NUMBER);



PROCEDURE SETROTUNJIRI(aROTI IN NUMBER, aROTE IN NUMBER);
FUNCTION SUPRASCRIERE_COLOANA(NUMECOL IN VARCHAR2) RETURN NUMBER;
PROCEDURE SOLVE_ERORI_STERGERE;

PROCEDURE GET_NOMENCLATOARE_NPERS;
PROCEDURE POST_NOMENCLATOARE_NPERS;
PROCEDURE MIRROR_IESIRI(aRecID IN NUMBER);
PROCEDURE MIRROR_NPART(aRecID IN NUMBER);


PROCEDURE GET_STOC_INITIAL (aGEST IN NUMBER,  aCODIOART IN NUMBER, SUPRASCRIERE IN NUMBER);
PROCEDURE POST_STOC_INITIAL(aGEST IN NUMBER,  aCODIOART IN NUMBER, SUPRASCRIERE IN NUMBER );

PROCEDURE POST_LOGIMPORT;

PROCEDURE PREIA_TRANSFERURI_ANALIZATE(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2);
PROCEDURE PREIA_TRANSFERURI_ANALIZATE2(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2);
PROCEDURE PREIA_TRANSFERURI_WMS(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2);


PROCEDURE PREIA_IESIRI_ANALIZATE(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2);
PROCEDURE FISAMF;
PROCEDURE GET_STOC_INITIAL_EXT(SUPRASCRIERE IN NUMBER);
PROCEDURE POST_STOC_INITIAL_EXT(SUPRASCRIERE IN NUMBER );

PROCEDURE SET_CANTNIR_OPERAT_TRANSF (aCODTRANSF1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, ObsNIR IN VARCHAR2, CODUSER IN NUMBER);
PROCEDURE SET_CANTNIR_OPERAT_TRANSF_EXT (aCODTRANSF1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, ObsNIR IN VARCHAR2, CODUSER IN NUMBER);
PROCEDURE SET_CANTNIR_OPERAT_INTRARI (aCODINTR1 IN NUMBER, aCANT IN NUMBER);


FUNCTION GETCODSERIEINVENTAR1(aCODINVENTAR1 IN NUMBER, aSERIE VARCHAR2) RETURN NUMBER;
PROCEDURE MEMO_CANTNIR_OPERAT_INTRARI (aCODINTR1 IN NUMBER, 
                                      aCANT IN NUMBER, 
                                      aCODLOCATIE IN NUMBER, 
                                      aCODSERIE IN NUMBER, 
                                      aCODGEST IN NUMBER, 
                                      aTG IN VARCHAR2, 
                                      aDATAPROD IN VARCHAR2, 
                                      CODUSER IN NUMBER, 
                                      aNEWCODGEST IN NUMBER,
                                      aOBSSERIE IN VARCHAR2,
                                      aNEWCODLOCATIE IN NUMBER);

PROCEDURE SET_CANTNIR_OPERAT_INTRARI_EXT;

PROCEDURE MEMO_FAPTIC_INVENTAR (aCODINVENTAR1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, aCODOBIECT IN NUMBER, aTIPSERIE IN NUMBER, aCODSERIE IN NUMBER);
PROCEDURE SET_FAPTIC_INVENTAR(aCODINVENTAR IN NUMBER);

PROCEDURE SOLVE_TEXT_PROMO;
FUNCTION GETCODSERIEINTR1(aCODINTR1 IN NUMBER, aSERIE VARCHAR2) RETURN NUMBER;
PROCEDURE SETLOCATIEIMPLICITA(aCODART IN NUMBER, aCODLOCATIE IN NUMBER);
PROCEDURE UPDATE_STOC_INTRARE(aCODINTR IN NUMBER);

PROCEDURE SOLVE_CARNETE_RETAIL;


PROCEDURE PROCESEAZA_DL_WMS;

PROCEDURE SETCARNETIMPLICIT_NT(aCODCARNET NUMBER);

FUNCTION CONDITIE_LINK_NS(NS_CODINTR1 IN NUMBER, NS_CODDVI1 IN NUMBER,  aCODINTR1 IN NUMBER, aCODDVI1 IN NUMBER) RETURN NUMBER;
PROCEDURE SET_RECEPTII_PARTIALE_INTRARI;
PROCEDURE SET_RECEPTII_PARTIALE_INTRARI2;
PROCEDURE FINALIZARE_RECEPTII_PARTIALE(aCODINTR IN NUMBER);

FUNCTION SCHIMBAREZERVARE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          SERIEVECHE   IN VARCHAR2,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          SERIENOUA   IN VARCHAR2,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER;

FUNCTION MUTAREZERVARECUSERIE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          SERIEVECHE   IN VARCHAR2,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          SERIENOUA   IN VARCHAR2,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER;

FUNCTION MUTAREZERVAREFARASERIE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER;



PROCEDURE UPDATE_PRET_NART(aCODOBIECT IN NUMBER, aCODCATPRET IN NUMBER, aCODSUBUNIT IN NUMBER, PRET IN NUMBER);

PROCEDURE PREIA_SERII_COMANDA;
PROCEDURE PREIA_SERII_INTRARI;
PROCEDURE PREIA_SERII_IESIRI;

FUNCTION GETSERIEDINLOT(CODSERIELOT IN NUMBER ,aCODOBIECT IN NUMBER, aSERIE IN VARCHAR2 ) RETURN NUMBER;

PROCEDURE IMPORTA_MIFIX(TIP NUMBER);

PROCEDURE GET_SEDII_PART(aCODPART IN NUMBER);
PROCEDURE UPDATESEDIIPART;
PROCEDURE UPDATE_NARTAMB;
PROCEDURE UPDATE_CANTNIR;
PROCEDURE ADAUGA_CERTIFICAT;
PROCEDURE UPDATEDELEGAT;
PROCEDURE UPDATEPERSCONTACT;
end PKG_IMPORTALTEAPLICATII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IMPORTDATEWM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C131C21EF262499EE9C5FDA7A242DC14B476121</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IMPORTDATEWM IS
 PROCEDURE ADAUGA_PARTENER_NOU(aCODPART OUT NUMBER);
 PROCEDURE ADAUGA_LOCATIE_NOUA(aCODLOCATIE OUT NUMBER);
 PROCEDURE ADAUGA_CARNET_NOU(aCODCARNET OUT NUMBER);
 PROCEDURE ADAUGA_SERIE_NOUA(aCODSERIE OUT NUMBER);

end PKG_IMPORTDATEWM; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_IMPORT_PART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1D5EFEDD5127705DB9F6DEC2DDD4CBECEDC1853</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_IMPORT_PART IS

CODIOPARTIMPLICIT NUMBER(20) := 0;
CLASAIMPLICITA    NUMBER(20) := 0;
TIPINFOLUNARE     NUMBER(3)  := 0;

PROCEDURE SETCLASAIMPLICITA(aCLASA IN NUMBER);
PROCEDURE SETCODIOPARTIMPLICIT(aCODIOART IN NUMBER);
PROCEDURE SETTIPINFOLUNARE(aTIP IN NUMBER);
PROCEDURE IMPORTA_PART_EXCEL;
FUNCTION GETLOCALITSEDIU(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STARA IN VARCHAR2) RETURN NUMBER;
FUNCTION GETLOCALITSEDIU_EXT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STARA IN VARCHAR2) RETURN NUMBER;

FUNCTION GETCODMONEDA(aSIMBOL IN VARCHAR2) RETURN NUMBER;
FUNCTION GETCODBANCA(aSIMBOL IN VARCHAR2, aDENUMIRE IN VARCHAR2) RETURN NUMBER;
end PKG_IMPORT_PART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_INCHIDERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6CB59C9EF3B701F89700087BA5EA5FC8D975968F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_INCHIDERI IS
-- ATENTIE
-- procedurile MAKE.. de mai jos
-- calculeaza SOLDURI/STOCURI pentru luna TEMP avand grija sa o setezi inainte de apel cu proedura PKG_GLOBALS.SETLUNATEMP
-- luand in calcul si SOLDURILE / STOCURILE LUNII PRECEDENTE (avand de asemeni grija sa setezi LUNA PREC cu proedura PKG_GLOBALS.SETLUNAPRECEDENTA)

CODOBIECT_PMP NUMBER(20) := 0;
PROCEDURE MAKE_JurnalStingereTVA;
FUNCTION CalcTVADed( TipTVA in number, TVANeded in number, ProRata in number, ValTVAExtern in number) return number;
FUNCTION getOPIFRoot (pCodObligPif IN NUMBER, pCodObligAsociat IN NUMBER) RETURN NUMBER;
FUNCTION getStinsTVACole (pCodObligPif IN NUMBER, pAL NUMBER, pDataStopTVA DATE) RETURN NUMBER;
PROCEDURE MAKE_TMP_StingereTVADed(pFromLista NUMBER DEFAULT 0);
PROCEDURE MAKE_TMP_StingereTVACole(pFromLista NUMBER DEFAULT 0);
PROCEDURE MAKE_TMP_InchidereTVACole(pFromLista NUMBER DEFAULT 0);

PROCEDURE SET_CODOBIECT_PMP(aCODOBIECT IN NUMBER);
FUNCTION GET_CODOBIECT_PMP RETURN NUMBER;


PROCEDURE GOTO_INCHIDERE_CONTURI;
PROCEDURE MAKE_INCHIDERE_CONTURI;
PROCEDURE MAKE_INCHIDERE_CONTURI_SUBUNIT;
PROCEDURE MAKE_SOLD_BANK;

PROCEDURE MAKE_SOLD_PERS;
PROCEDURE MAKE_SOLD_PERS_SUB;

--PROCEDURE MAKE_SOLD_PERS_LUNA;
PROCEDURE MAKE_SOLD_PART;

PROCEDURE MAKE_SOLD_PART_EXT;
PROCEDURE MAKE_SOLD_PART_SUB_EXT;

PROCEDURE MAKE_SOLD_PART_SUB;
PROCEDURE MAKE_STOC_LUNA; -- fixeaza IN NIRLUNA stocul la final de luna
PROCEDURE MAKE_STOCVAL_LUNA;
PROCEDURE MAKE_PMP_LUNA;
PROCEDURE MAKE_PMP_ALL_LUNA;
PROCEDURE MAKE_AVIZINT_LUNA;
PROCEDURE REPARE_AVIZIES_STORNO;
PROCEDURE MAKE_AVIZIES_LUNA;
PROCEDURE MAKE_COMANDA1_LUNA;

PROCEDURE MAKE_STOC_MOMENT; -- RE-CALCULEAZA REST-ul baleind TOATE LIVRARILE

PROCEDURE MAKE_NCONT_LUNA(NUME_TABELA IN VARCHAR2, aAN IN NUMBER, aLUNA IN NUMBER);
PROCEDURE MAKE_RULAJE_NCONT;
PROCEDURE MAKE_RULAJE_NCONT_SUB;

PROCEDURE MAKE_REST_OBLIGPIF_LUNA;-- FIXEAZA RESTUL DIN OBLIGPIF LA SFARSITUL UNEI LUNI



FUNCTION AMORTIZARELUNARA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
FUNCTION AMORTIZARELUNARA_G(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
FUNCTION AMORTIZARELUNARA_F(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
FUNCTION AMORTIZARELUNARA_REZERVA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;


PROCEDURE MAKE_MIFIX;
PROCEDURE MAKE_CHELTAVANS;
FUNCTION GETAMOLUNA(AN IN NUMBER,
                    LUNA         IN NUMBER,
                    xAMO         IN NUMBER,
                    xNEUTIL      IN NUMBER,
                    xDURATAF     IN NUMBER,
                    xPRET        IN NUMBER,
                    xCANT        IN NUMBER,
                    xGRADU       IN NUMBER,
                    xANINTRARE   IN NUMBER,
                    xLUNAINTRARE IN NUMBER,
                    xTIPAMO      IN NUMBER,
                    xDURATAN     IN NUMBER,
                    XTIP         IN VARCHAR2) RETURN NUMBER;

--procedura reface in NCONTRUL rulajele curente plecand de la JURNAL;
--tranzactiile luate in calcul sunt cele cu AN = PKG_GLOBALS.ANLUCRU; LUNA = PKG_GLOBALS.LUNALUCRU;
PROCEDURE REMAKE_RULAJE_LUNA_FROMJURNAL(FAC_COMMIT IN NUMBER);


FUNCTION GETCHELTLUNA(AN           IN NUMBER,
                      LUNA         IN NUMBER,
                      xAMO         IN NUMBER,
                      xDURATAF     IN NUMBER,
                      xVALOARE     IN NUMBER,
                      xANINTRARE   IN NUMBER,
                      xLUNAINTRARE IN NUMBER,
                      xDURATAN     IN NUMBER) RETURN NUMBER;

FUNCTION  CHELTAVANSLUNA(ACODCHELTAVANS NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
PROCEDURE REPARA_OBLIGPIF_LUNA;
PROCEDURE MAKE_STOC_MOMENT_EXT;
PROCEDURE MAKE_STOC_LUNA_EXT;
PROCEDURE MAKE_STOC_LUNA_PRAGMA;
PROCEDURE REMAKE_RULAJE_SUB_FROMJURNAL(FAC_COMMIT IN NUMBER);

-- BUNE DE FOLOSIT DOARE PENTRU RECALCUN RULAJE SI SOLDURI INITIALE PE SUBUNITATI
PROCEDURE MAKE_RULAJE_SUBUNITATI;
PROCEDURE MAKE_SOLDINITIAL_SUBUNITATI;
PROCEDURE UPD_RUL_SI_SOLD_SUB_FROMTMP(pSub IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER);
PROCEDURE MAKE_STOC_LA_DATA(aDATA VARCHAR2);
PROCEDURE MAKE_OBLIGPART_LA_DATA(aDATA VARCHAR2);
PROCEDURE MAKE_SOLDURIBANCI_LA_DATA(aDATE VARCHAR2);


PROCEDURE MAKE_PMP_OBIECT_LUNA(aCODOBIECT IN NUMBER);
PROCEDURE REFA_MIFIX(aCODMIFIX IN NUMBER);


PROCEDURE MAKE_VOL_TRANZ_STINGERI;

FUNCTION GETCHELTLUNA_PEZILE(AN           IN NUMBER,
                             LUNA         IN NUMBER,
                             xAMO         IN NUMBER,
                             xVALOARE     IN NUMBER,
                             xDATASTART   IN VARCHAR2,
                             xDATAEND     IN VARCHAR2
                             )            RETURN NUMBER;

FUNCTION CHELTAVANSLUNA_PEZILE(ACODCHELTAVANS NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
FUNCTION GET_AMO_MIFIX(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;


PROCEDURE SIMULARE_AMORTIZARI(aANLUCRU IN NUMBER,
                              aLUNALUCRU IN NUMBER,
                              aANANALIZA IN NUMBER,
                              aLUNAANALIZA IN NUMBER);

PROCEDURE TEST;
PROCEDURE PROPAGA_EXTENSII_CHELTAVANS(NUME_EXTENSIE VARCHAR);
FUNCTION STOPARE_AMO_DEGRESIVA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
PROCEDURE TEST_MIFIX;

end PKG_INCHIDERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_INITSTOCSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1F7A891762305181DDAA4FD3C2E36611778665B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_INITSTOCSOLD IS

  procedure GenStocIni;
  procedure GenSoldPartIni;
  procedure GenStocValIni;

end pkg_InitStocSold; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_INTERFATAKLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7793D7CD952314A26C00B68C861FF253D335633B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_INTERFATAKLG is

PROCEDURE POSTINFOMESAJ;

end PKG_INTERFATAKLG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B7EC586D3EE9080EA777BBE70F4A4FC3FA31B06</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_INTRARI IS
  PartenerAviz NUMBER(18) := 0;
 -- memoreaza CARNETDOC si NRDOC la intrarea pe macheta
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  CURS_IN     NUMBER(20, 7);

  function GETSERIILOTCONSUM(aCodCmdProdMat in number) return varchar2;
  PROCEDURE Service_Preluat;
  PROCEDURE EMPTY_INTRARI_TEMPTABLES;

  PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RecId OUT NUMBER );


  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);


  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;


  FUNCTION GET_MAX_CODNIRSTOC_EDITAT RETURN NUMBER;
  FUNCTION NR_AVIZE_SUB_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION NR_LIVRARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION NR_LIVRARI_DIN_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER;

  FUNCTION SUMA_INTRARI_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_REST_STOC_IN_LUNA(ACODNIRSTOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;

  FUNCTION SUMA_LIVRARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIR_UM1(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIR_UM2(aCodNirStoc IN NUMBER) RETURN NUMBER;

  FUNCTION SUMA_MARIRI_NIR    (aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_NIR_UM1(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_NIR_UM2(aCodNirStoc IN NUMBER) RETURN NUMBER;

  FUNCTION SUMA_MARIRI_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER;
  FUNCTION GET_REST_STOC_SERIE(aCodNIR IN NUMBER, aCodNirSer IN NUMBER, aCantNIR IN NUMBER) RETURN NUMBER;



  FUNCTION NR_LIVRARI_DIN_DOCUMENT(aCodIntr IN NUMBER, aTipIntr IN NUMBER) RETURN NUMBER;

  FUNCTION GETSTOCARTICOL(aCodObiect IN NUMBER, aCodGest in number default 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZ(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZX(aCodObiect IN NUMBER, aCodIntr1 IN NUMBER DEFAULT 0, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZ1(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZ_VAL(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZ_RETANN(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETINREG(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTFURN_SUBUNIT(aCodObiect IN NUMBER) RETURN VARCHAR2;
  FUNCTION GETLASTCODFURN_SUBUNIT(aCodObiect IN NUMBER) RETURN VARCHAR2;
  FUNCTION GETLASTPRETACHIZVAL_NIRSTOC(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GETLASTCODINTR(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GETLASTPRETMAXIMAL(aCodObiect IN NUMBER) RETURN NUMBER;


  function getpretmediuachiz(aCodObiect in number) return number;
  FUNCTION GETLASTPRETACHIZ_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETINREG_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTSUPLIMACHIZ_SUBUNIT(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GETLPA_SUBUNIT_FARAAECUST(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLDA_SUBUNIT_FARAAECUST(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE;

  FUNCTION GET_REST_STOC(aCodNIR IN NUMBER, aCodNirStoc IN NUMBER, aCantNIR IN NUMBER) RETURN NUMBER;
  FUNCTION GET_REST_STOC_UM1(aCodNIR IN NUMBER, aCodNirStoc IN NUMBER, aCantUM1NIR IN NUMBER) RETURN NUMBER;
  FUNCTION GET_REST_STOC_UM2(aCodNIR IN NUMBER, aCodNirStoc IN NUMBER, aCantUM2NIR IN NUMBER) RETURN NUMBER;

  FUNCTION GET_REST_STOC_SERIE_UM1(aCodNIR in NUMBER, aCodNirSer IN NUMBER, aCantUM1NIR IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_NIRSER_UM1(aCodNirSer IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIRSER_UM1(aCodNirSer IN NUMBER) RETURN NUMBER;

  FUNCTION GET_REST_STOC_SERIE_UM2(aCodNIR in NUMBER, aCodNirSer IN NUMBER, aCantUM2NIR IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_MARIRI_NIRSER_UM2(aCodNirSer IN NUMBER) RETURN NUMBER;
  FUNCTION SUMA_LIVRARI_DIN_NIRSER_UM2(aCodNirSer IN NUMBER) RETURN NUMBER;


  PROCEDURE SETPARTENERAVIZ(aPart IN NUMBER);
  FUNCTION CONDITIE_PART_AVIZ(aPart IN NUMBER) RETURN NUMBER;

  FUNCTION AMFACTURALAAVIZ(CODAVIZ  IN NUMBER) RETURN NUMBER;
  FUNCTION AMAVIZLAFACTURAASTEPTARE(CODAVIZ  IN NUMBER) RETURN NUMBER;

  FUNCTION LINIEAVIZSTINSA(aCODINTR1 IN NUMBER) RETURN NUMBER;
  FUNCTION LINIEAVIZSTINSA_EXT(aCODINTR1 IN NUMBER) RETURN NUMBER;

  FUNCTION LINIEFACTASTEPTSTINSA(aCODINTR1 IN NUMBER) RETURN NUMBER;

  FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION DOCUMENTE_CU_NUMARUL(aCODDOC IN NUMBER, aSERIEDOC IN VARCHAR2, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER) RETURN NUMBER;
  FUNCTION DOCUMENTE_CU_NUMARUL_DATA(aCODDOC IN NUMBER, aSERIEDOC IN VARCHAR2, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER, aDATADOC IN VARCHAR2) RETURN NUMBER;
  FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER;

  FUNCTION DOCUMENTE_CU_NUMARUL_EXT(aCODDOC IN NUMBER, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER) RETURN NUMBER;
  FUNCTION DOCUMENTE_CU_NUMARUL_DATA_EXT(aCODDOC IN NUMBER, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER, aDATADOC IN VARCHAR2) RETURN NUMBER;

  FUNCTION NR_REZERVARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER;
  FUNCTION GETLASTPRET_NOTAPREDARE(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION ZECIMALEPRET(aZEC IN NUMBER) RETURN NUMBER;


  PROCEDURE SOLVE_OBINV(aCODINTR IN NUMBER, aCODCLASIF IN NUMBER );

  PROCEDURE DIMINUEAZA_REZERVARI(aCODNIRSTOC IN NUMBER, aCODNIRSER  IN NUMBER, CANT_IN_STOC IN NUMBER);

  FUNCTION GETLASTPRETACHIZVAL(aCodObiect IN NUMBER, aCodMoneda IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTPRETACHIZVAL_SUBUNIT(aCodObiect IN NUMBER, aCodMoneda IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTDATAACHIZ(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE;
  FUNCTION GETLASTDATAACHIZ_PER(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE;
  FUNCTION GETLASTDATAACHIZ_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE;
  FUNCTION GETLASTPRETACHIZ_FACT_AE (aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETLASTDATAACHIZ_FACT_AE(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE;

  FUNCTION GETLASTPRETACHIZFURN(aCodObiect IN NUMBER, aFURN IN NUMBER) RETURN NUMBER;
  procedure GenereazaModificareDePretMifix(aDataDoc in date, aAn in number, aLuna in number, aSubunitatea in number);

  FUNCTION GETLASTPRETACHIZ_EXT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER;
  function UPDATEEXTDATAREF(RecId in number, aDataRef in varchar2) return number;
  function GetDataStart(aRECID in number) return date;
  FUNCTION INTRAREPLUSMINUS(aCODINTR IN NUMBER, VALOBLIG IN NUMBER) RETURN NUMBER;
  FUNCTION GETCMDFURN(ACODOBIECT IN NUMBER) RETURN NUMBER;
  PROCEDURE MAKE_NIRSTOC_LA_DATA(aDATA IN VARCHAR2);
  PROCEDURE AdaugaScanare(
  aCodDoc in number,
  aTipDoc in number,
  aSN in varchar2,
  aEXP in varchar2,
  aCodSerie in number,
  aCodObiect in number,
  aGTIN in varchar2,
  aRaspuns in varchar2,
  aCodRaspuns in varchar2,
  aStatus in varchar2,
  aCod out varchar2
  );

  PROCEDURE POSTEFACTURA;
  function getpmachizgest(aCodObiect in number, aCodGest in number) return number;
  procedure Aproba;

END pkg_INTRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B05A6283AE9C935055D1044CC5041E0E3799BEB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_INVENTAR IS

 procedure RecalculRezervari(aCodInventar in number);
 procedure StergeLiniiGoale(aCodInventar in number);
 procedure CorectieInventContClase;
 procedure SPARGE_INVENTAR(aNrInventar in number, CodVechi in number);
 function TestCoerenta(aCodInventar in number) return number;
 FUNCTION GetCodInventar (aCodIes in number, CuLock in number ) RETURN NUMBER;
 function UpdateInventarFromDoc(aCodInventar in number, aCodDoc in number) return number;

 function TestIOClase(aITipCont in number, aIClase in number, aIProd in number, aIClaseS in number, aCodGest in number) return number;
 FUNCTION GETCODINVENTAR RETURN NUMBER;
 FUNCTION GETDATAINVENTAR RETURN DATE;
 FUNCTION GETCODGEST RETURN NUMBER;
 FUNCTION isToateArt RETURN NUMBER;
 FUNCTION isToateConturile RETURN NUMBER;
 FUNCTION isToateClasele RETURN NUMBER;
 FUNCTION isToateClaseleS RETURN NUMBER;
 FUNCTION isToateProd RETURN NUMBER;
 PROCEDURE SETPARAMS(aCodInventar IN NUMBER);

 procedure GetInventStoc(aCodInventar in number);
 function  UpdateInventStoc(aCodInventar in number) return number;
 function  UpdateInventRez(aCodInventar in number, aCodDoc in number, DoCommit in number default 0) return number;
 PROCEDURE GENERARE_INVENTAR(aCodInventar in number);
 PROCEDURE SetCodInventar1(aCodInventar in number);

 PROCEDURE RE_GENERARE_INVENTAR(aCodInventar in number);
 procedure GetInventStocTemp(aCodInventar in number);
 PROCEDURE SetCodInventar1Temp(aCodInventar in number);
 PROCEDURE PreiaDateNoi(aCodInventar in number);
 PROCEDURE RezolvaBlocaje(aCodInventar in number);

 PROCEDURE SETTIPREZOLVARE( aCodInventar IN NUMBER, aTipRezolvare IN NUMBER);
 FUNCTION  GET_DATACURENTA_SERVER RETURN VARCHAR2;

 function ExistaInLivrareDocRez(vCodNirStoc in number, vMarire in number, vDiminuare in number) return number;
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 function  ServiceInventar(aCodInventar IN NUMBER) return number;
 procedure CorectieInventar(aCodInventar IN NUMBER);
 procedure INCHIDEINVENTARENEFINALIZATE;
 procedure IMPORTSCANARE(aCodObiect in number, aCodUM1 in number, aSerie in varchar2, aTG in varchar2, aCant in number, aCodInventar in number);
 procedure Debug;
 procedure RezDifAut(aCodInventar in number);

end PKG_INVENTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_JOBLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F1DF97A82FBC7F621F2165CB1E3A47BF2EB7DC2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_JOBLISTE IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 
 
  PROCEDURE SAVELISTACONFIG;
  PROCEDURE LOADLISTACONFIG(aCodJob1 number); 
  PROCEDURE ACTJOBS(ACODJOB IN NUMBER );
  PROCEDURE RULEAZA_SET(ACODJOB IN NUMBER);
  
  PROCEDURE RULEAZA_SET_SINCRON(ACODJOB IN NUMBER);


  PROCEDURE MUTAINDEPO(ACODJOBLISTEFIN IN NUMBER, ADEPONAME IN VARCHAR2);
end pkg_jobliste; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_JUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2165A7198AB1B47CE7E49A403829F6C7B9CE6F24</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_JUDET IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_Judet; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DB52AD9EDA50E6F4E42AE9C22AA2595E83428A0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_JURNAL IS
TYPE CRS IS REF CURSOR;
TYPE JURN_FULL_CURSOR IS REF CURSOR;

 TCJCONST  NUMBER  := 100;
 TCJTVA    NUMBER  := 200;
 TCJIOART  NUMBER  := 300;
 TCJIOPART NUMBER  := 400;
 TCJIOPERS NUMBER  := 500;
 TCJIOBANK NUMBER  := 600;
 TCJFILIAL NUMBER  := 700;
 TCJCONT   NUMBER  := 800;
 TCJTAXE   NUMBER  := 900;
 TCJNGEST1 NUMBER  :=1000;

 GLB_SKIPUPDATEJURN NUMBER(1) := 0;

PROCEDURE CHECK_NESTJURNAL;
FUNCTION GET_INFO_JURNAL(aAn in number, aLuna in number, aDirty out number) RETURN VARCHAR2;
FUNCTION GET_JURNAL_FULL_LUNA_MULTI(aAn in number, aLuna in number) RETURN JURN_FULL_CURSOR;
FUNCTION GET_JURNAL_FULL_LUNA(aTipDoc in number) RETURN JURN_FULL_CURSOR;
FUNCTION GET_JURNAL_FULL(aTipDoc in number) RETURN JURN_FULL_CURSOR;
function CodNestJurnal(aCodContD in number, aCodContC in number, aCodGest in number, aCodCentru in number) return number;
function GetCodNestJurnal(aCodContD in number, aCodContC in number, aCodGest in number, aCodCentru in number) return number;
function TestDirtyTransfer(aTipDoc in number, aCodDoc in number, aCodNirStoc in number) return number;
function TestDirtyLivrari(aCodNirStoc in number, SchimbIOArt in number) return number;
function TestDirtyNirStoc(aCodNirStoc in number, SchimbIOArt in number) return number;
function TestDirtyIntrAE(aCodLinieAE in number) return number;
function TestDirtyIesAE(aCodLinieAE in number) return number;

procedure setDirtyTransfer(aTipDoc in number, aCodDoc in number, aCodNirStoc in number, aPret in number, UrmarirePUVAl in varchar2, aPUVAL IN NUMBER);

PROCEDURE setDirtyNirStoc(aCodNirStoc in number, aPret in number, UrmarirePUVAl in varchar2, aPUVAL in number) ;
PROCEDURE setDirtyIntrAE(aCodLinieAE in number, aCurs in number);
procedure setDirtyDVIAE(aCodLinieAE in number, aCurs in number);
PROCEDURE setDirtyIesAE(aCodLinieAE in number, aCurs in number);

procedure SetDirty(acoddoc in number, atipdoc in number, aSubunitatea in number, aAn in number, aLuna in number);

procedure setDirty_Cont (aCodCont in number, AnLunaStart in number, AnLunaFin in number);

PROCEDURE SETDIRTYTIPDOC (PTIPDOC IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER);
PROCEDURE SETDIRTYJURN (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER);
PROCEDURE SETDIRTYBAZA (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER);
PROCEDURE SETDIRTYBAZA2(PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER);
PROCEDURE SETDIRTYDESCRIPTOR (PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER );
PROCEDURE SETDIRTYICONT (PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PICONT IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER );
FUNCTION  NumaraDocsCont (aCONT IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER ) RETURN NUMBER;
FUNCTION  Count_InchideriSubunit(PANLUNA IN NUMBER) RETURN NUMBER;

FUNCTION  GETCONTFORJURNAL(CODDESCRIERE IN NUMBER, ICONT IN NUMBER, TIPCONT IN NUMBER, ANALITICCONT IN VARCHAR2, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER;

PROCEDURE UPDATE_JURN_FROM_TMP;
procedure Set_Rulaj_Din_Jurnal(Semn in number, aTIPDOC IN NUMBER, aCODDOC IN NUMBER, aAn IN NUMBER, aLuna IN NUMBER);
PROCEDURE MAKE_JURNAL(aTIPDOC IN NUMBER, aCODDOC IN NUMBER);

PROCEDURE MAKE_RULAJE_SELECTIV(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER, aLUNAI IN NUMBER DEFAULT 1);
PROCEDURE MAKE_RULAJE_SELECTIV_SEC(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER, aLUNAI IN NUMBER DEFAULT 1);
PROCEDURE MAKE_RULAJE_SELECTIV_EXT(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER);
PROCEDURE MAKE_RULAJE_PANA_LA_DATA(DATA IN VARCHAR, aSUBUNIT IN NUMBER);
PROCEDURE PREIAPRODNETERMLUNAPREC;

PROCEDURE DO_JURNS_DIN_TMP_JURNAL1(aTipDoc in number);
PROCEDURE DO_JURNAL_RULAJE_DIN_JURNAL1(aAN IN NUMBER, aLUNA IN NUMBER);

PROCEDURE SAVEETALON (aAN IN NUMBER, aLUNA IN NUMBER  );
FUNCTION  COMPARE_ETALON (aAN IN NUMBER, aLUNA IN NUMBER ) return crs ;
procedure setDirtyNP(aCodLinieNP in number, aPRET IN NUMBER, aConsumPonderat IN NUMBER DEFAULT 0);
procedure SetDirtyAllNPLuna;
procedure SetDirtyAllNPLunaAGREGARE(ConsumPonderat in number default 0, cuPMP in number default 0, cuRebuturi in number default 0);
procedure SetDirtyAllNPLunaAGREGARERebut;
procedure SetDirtyAllNPLunaAGREGAREMan(ManReal in number default 0);
procedure SetDirtyAllNPLunaAGREGAREManX;
function GetPredariInLuna(vCodComanda1 in number) return number;
function GetPredariInLunaCuRebut(vCodComanda1 in number) return number;
function GetPredari(vCodComanda1 in number) return number;
procedure SetDirtyAllNPLunaDEZAGREGARE(ConsumPonderat in number default 0);
procedure SetDirtyAllNPLunaPretReferinta;
function GetSpecificCantUM1(Rel in number, D1 in number, D2 in number, D3 in number, Cant in number)return number;

PROCEDURE UPDATE_JURN_FROM_MAN;

procedure RecalculPRETAchiz(aCodLinieAE in number);
procedure setDirtyIntrAEAstept(aCodLinieAE in number, aPret in number, aCurs in number);
procedure setDirtyIesAE_STORNO(aCodLinieAE in number, aPRET IN NUMBER, aCurs in number);
procedure setDirtyIntrAE_Storno(aCodLinieAE in number, aPret in Number, aCurs in number);

PROCEDURE SET_SKIPUPDATEJURNFLAG(aFLAG IN NUMBER);

procedure TestGET_JURNAL_FULL;

end PKG_JURNAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D13452D3E0B8081F743AFF4F258E54528EFA320B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LANSARE IS
TYPE MENU_CURSOR IS REF CURSOR;

procedure ActualizeazaCopiiProiectMan(aTermen in date, aCodLansare0 in number, aCodProiectNod in number);
procedure ActualizeazaProiectMan(aCodLansare0 in number, aCodProiect in number, aTermen in varchar2);
function GetCopilMaxim(aNod in number, aCodLansare0 in number) return number;
procedure SetCopilMaxim(aCodLansare0 in number);
procedure SetDrumCritic(aCodNod in number, aCodLansare0 in number);
procedure SetDecalaj(aCodNod in number, Total in number, aCodLansare0 in number);
procedure IncarcaProiectMan(aCodLansare0 IN NUMBER, aCodProiect IN NUMBER, aCant IN NUMBER);
procedure STERGEREZERVAREOBIECT(aCodComanda1 IN NUMBER, aCodObiect IN NUMBER, aTip IN NUMBER);
FUNCTION GETPROIECTNOD(aCodProiect IN NUMBER, aCant IN NUMBER, aCodComanda1 IN NUMBER) RETURN MENU_CURSOR;
function BAGAREZERVARE(aCodComanda1 IN NUMBER, aCodCmdProdMat IN NUMBER, aCodNirStoc IN NUMBER, aCodNirSer IN NUMBER, aCant IN NUMBER, aUMSec IN NUMBER, aCodObiect IN NUMBER, aCodComanda1f IN NUMBER) RETURN NUMBER;
procedure SetCantInLansare1(vCodLansare1 in number, vCant in number);
PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;

end PKG_LANSARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19098E65F0C46DEFC5BE6512E508CBFDE593714F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LANSPROD IS
 
  FUNCTION GETPREVACC(aCodObiect in number, aAn in number, aSet in number) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  procedure PreiaProduse(RecId in number, DataStart in varchar2, DataStop in varchar2);
    
END PKG_LANSPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E25BA87D8E22A8AB247454E9E1FBE7752D6B2B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LANSZ IS

  procedure UpdateLansz1Cmd1(aCamp in varchar2, aLansat in number, aCodComanda1 in number, aCodLansz1 in number);
  procedure ActualizeazaStoc;
  function CanLockLansZ(aAn in number, aSaptamana in number, aSubunit in number) return number;
  function ActualizeazaLinie(aCodLansZ1 in number, aCant in number, aZi in number) return number;
  function ActualizeazaLinieCmd1(aCodComanda1 in number, aCant in number) return number;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  procedure CreazaLansZ1(ACODGEST IN NUMBER, ACODLANSZ IN NUMBER, ASAPTAMANA IN NUMBER, AAN IN NUMBER, ASECTIE IN NUMBER);
  procedure CreazaLansZ1Man(ACODLANSZ IN NUMBER, ASAPTAMANA IN NUMBER, AAN IN NUMBER, ACODOBIECT IN NUMBER, ACODRETETA IN NUMBER, AUSERID IN NUMBER);
  PROCEDURE COMANDA1JOI(An number, Saptamana number);
  procedure updateCmdZile;
  procedure updateCmdZilePePL(aCodLansZ in number);
  procedure UpdateNoi(aCodLansz in number);
  procedure MAKE_LANS_TRIGG;
  procedure UpdatePLStructDinPlanif(aCodPlanifProd in number);
  procedure test(aCodLansZ in number);

end PKG_LANSZ;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIMBA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>268B588FCB19CEA11EF0DB47A7604FE5DC48B22B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIMBA IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  
  PROCEDURE LOAD_OBJTRAD;
  PROCEDURE SAVE_OBJTRAD;
  
  PROCEDURE TRADUCERE(aCodObiect IN NUMBER, aOverwrite IN NUMBER);
  PROCEDURE REWRITE_OBJTRAD;

end PKG_LIMBA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIMITACREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1AE8110F8CD7F1743F8583135E286C3C3D5C540</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LimitaCredit IS
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_LimitaCredit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_ALEGPERIOADA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1C7180CA23002ED0BB29743FBACA88B1A56A689</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_ALEGPERIOADA IS

  PROCEDURE setParams(
    pDataS        IN VARCHAR2 DEFAULT NULL,
    pDataF        IN VARCHAR2 DEFAULT NULL,
    pAnual        IN NUMBER   DEFAULT 0,
    pOpt1         IN NUMBER   DEFAULT 0,
    pOpt2         IN NUMBER   DEFAULT 0,
    pOpt3         IN NUMBER   DEFAULT 0,
    pOpt4         IN NUMBER   DEFAULT 0,
    pCodJob1      IN NUMBER   DEFAULT 0,
    pDataRef      IN VARCHAR2 DEFAULT NULL,
    pAllX         IN NUMBER   DEFAULT 1,
    pCriteriu     IN NUMBER   DEFAULT 0,
    pSumarIncFact IN NUMBER   DEFAULT 0);

  function GetSumarIncFact return number;
  FUNCTION getCriteriu RETURN NUMBER;
	FUNCTION getDataS    RETURN DATE;
  FUNCTION getPerioada RETURN VARCHAR2;
	FUNCTION getDataf    RETURN DATE;
  FUNCTION Anual       RETURN BOOLEAN;
  FUNCTION optiunea1   RETURN BOOLEAN;
  FUNCTION optiunea2   RETURN BOOLEAN;
  FUNCTION optiunea3   RETURN BOOLEAN;
  FUNCTION optiunea4   RETURN BOOLEAN;
  FUNCTION getDataRef  RETURN DATE;
  FUNCTION AllX        RETURN BOOLEAN;

end pkg_list_alegPerioada;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ACHIZFURNART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2C5F0AB8F0FC76BE0E409CF3A45E5A3185DB4CC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ACHIZFURNART IS

PROCEDURE BAGA_DINAMIC_COLS;
FUNCTION CAMPURI(pTIP IN VARCHAR2) RETURN VARCHAR2;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_ACHIZFURNART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_AECUSTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>029B37D52E1896E19A81825B0588F9F09A47B0F4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_AECUSTC IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_AECUSTC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_AECUSTF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4457487C60653FA24930D077AFA6C308DF3B3B9B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_aecustf IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_AECUSTF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_AJDEPCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>935D689703AC4418E466656E827621C5F003B687</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_AJDEPCLI is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_AJDEPCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_AJDEPSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20AF4DCC3C4ED2272AB20DF1ADA3C556CB51C14C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_AJDEPSTOC IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_AJDEPSTOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_AMBCUSTDEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2391A9B7723402933821E8F2673BB9D7506011F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_AMBCUSTDEL IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_AMBCUSTDEL;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZACONSUMURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9FAAC8ECC98437F55B367FDE94DBBB6B6F61D4E2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ANALIZACONSUMURI IS

  procedure RESET_PRET_NIRSTOC1;
  function  GetPretNirStoc(aCodNirStoc in number) return number;
  function  GetPretNirStoc1(aCodNirStoc in number) return number;
  procedure UpdatePretNirStoc1(FaraNP in boolean default False);
  procedure Corectii(vLuna in number, vAn in number);
  procedure CompleteazaTemporar(aAnLuna in number, aCodNirStoc in number);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  procedure UpdatePreturiPeLuna(aAn in number, aLuna in number);
  procedure proceseaza_mat(P in number, cantP in number, cantM in number, cantM_r in number, acodnirstoc in number, aStorno in number);

end pkg_list_base_analizaconsumuri;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZAPRVANZCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46056DE40A4F88C47E5916BDE144D028317A2EF3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ANALIZAPRVANZCLI IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  function getcatpretpart(aCodPart in number) return number;

END PKG_LIST_BASE_ANALIZAPRVANZCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZASCURTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87E78CB02E7DA752BB6616317E07E18E2759794F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ANALIZASCURTA IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE SetParams(aCodCmdProdMat in number default 0, aAnLuna in number default 0,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 );

end pkg_list_base_analizascurta;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ANTECALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05A9B754A5AB6D321CB1F1F0185B865C4C40BC5F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_antecalcul is

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_antecalcul;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_APELTEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4EFD4D7815571C8666B0D6E55A328006CB84F85</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_APELTEL is

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_APELTEL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ARTECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9067DA70F16506CC3E8CD4CC28C35D673FDEE94A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ARTECHIV IS

 PROCEDURE processlist(tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end pkg_list_base_artechiv; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ARTNEDESCARCATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB1C4DEB9DBFD76F9E2421F4B6239AD7028F5D74</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ARTNEDESCARCATE IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
end PKG_LIST_BASE_ArtNEDESCARCATE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ATRIBUTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09EA441FD49B99565DB8DD4DC72A4916F7FEFD61</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ATRIBUTE IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_ATRIBUTE; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FA22080AD2068146E8C2A9C6305A5AE28827CC3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALANTA IS

  TYPE crs IS REF CURSOR;

  PROCEDURE Set_G_tmpTABLE (aName in varchar2);

  PROCEDURE setJoinuri;

  FUNCTION getBalFirmaCur RETURN crs;
  FUNCTION getConturiBal  RETURN crs;

  function getAnIni return number;
  function getLunaIni return number;
  function getAnFin return number;
  function getLunaFin return number;

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setParams (
    v_clasa      IN VARCHAR2 DEFAULT NULL,
    v_sintetic   IN NUMBER   DEFAULT 0,
    v_plan       IN NUMBER   DEFAULT 0,
    v_valuta     IN NUMBER   DEFAULT 0,
    v_curs       IN NUMBER   DEFAULT 1,
    v_PeSubunit  IN NUMBER   DEFAULT 1,
    v_Lunara     IN NUMBER   DEFAULT 1,
    v_CodJob1    IN NUMBER   DEFAULT 0,
    v_LunaIni    IN NUMBER   DEFAULT 0,
    v_LunaFin    IN NUMBER   DEFAULT 0,
    v_PerFaraRul IN NUMBER   DEFAULT 0
  );
  FUNCTION SaveBalanta (anLuna in varchar2, TmpName in varchar2 ) RETURN NUMBER;
  FUNCTION COMPARE_BALANTA (ANLUNA IN VARCHAR2) return crs ;
  PROCEDURE BalaVer(aLISTID IN NUMBER);
  PROCEDURE UMPLE_TMP_BALANTA;
  procedure TestTmpBrut;
END PKG_LIST_BASE_BALANTA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALASUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0A64217F620C90DB83BAE07843E9C42BE97D42B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALASUBUNIT IS

end pkg_list_base_balaSubunit; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALCUMUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEDED9CCC77CF423501DFDA76AF73101F4758E9A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALCUMUL IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
end PKG_LIST_BASE_BALCUMUL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALCUMUL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>250DB5F3078CCB1D984C8EEE22A4F05CA1A936E1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALCUMUL1 IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_BALCUMUL1; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSINTPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7001E306622B5B682C50838EF0B5B4090FB5DE84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALSINTPART IS

  PROCEDURE SET_LISTA_PARAMS (
    IsAllMoneda IN NUMBER  DEFAULT 1,
    IsAllCont   IN NUMBER  DEFAULT 1,
    IsAllSub    IN NUMBER  DEFAULT 1,
    aLunaStart  IN NUMBER,
    aLunaFin    IN NUMBER,
    aTipIopart  IN NUMBER  DEFAULT 0,
    pCodJob1    IN NUMBER  DEFAULT 0,
    pAllSting   IN NUMBER  DEFAULT 0,
    IsSubStins  IN NUMBER  DEFAULT 0);
	PROCEDURE processlist(tmpname IN VARCHAR,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_BalSintPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSINTPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09B76EDF5D3BC114F2DF1BEC16D5106FCDD148A1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALSINTPERS IS

	PROCEDURE processList(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE processListHolding(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  function GetLunaU(aAn in number, aLuna in number) return number;
  function GetAnU(aAn in number, aLuna in number) return number;
	
END PKG_LIST_BASE_BALSINTPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62588239DEE4DAD5FD52CEB804F5C6378FB7CB00</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALSTOC IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

END PKG_LIST_BASE_BALSTOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EAE540898E236EB3CE9FABA6131272F29F74EBE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALSTOC1 IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_BALSTOC1; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOCPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D25FA0C4DBD29B89190FAD5830C2A8CCC1FDC01A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_balstocpart IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_BALSTOCPART;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOCREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D3B9932D9AC8865862415E869E794BC725E339B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BALSTOCREST IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

END PKG_LIST_BASE_BALSTOCREST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BAL_IFRS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4ABE99D2408A3BDB94A7AA3F366BA92F449D8526</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BAL_IFRS IS

  TYPE crs IS REF CURSOR;

  PROCEDURE Set_G_tmpTABLE (aName in varchar2);

  PROCEDURE setJoinuri;

  FUNCTION getConturiBal  RETURN crs;

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2);
  PROCEDURE setParams (
    v_clasa      IN NUMBER DEFAULT 0,
    v_sintetic   IN NUMBER DEFAULT 0,
    v_plan       IN NUMBER DEFAULT 0,
    v_valuta     IN NUMBER DEFAULT 0,
    v_PeSubunit  IN NUMBER DEFAULT 1,
    v_Lunara     IN NUMBER DEFAULT 1,
    v_Luna       IN NUMBER DEFAULT 0,
    v_An         IN NUMBER DEFAULT 0,
    V_CODJOB1    IN NUMBER DEFAULT 0,
    v_lunaI      IN NUMBER DEFAULT 1 );
  PROCEDURE DEBUG;

end pkg_list_base_bal_ifrs;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A68A8212807F1612732A4BBD94CEC76FC97A2000</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BCAR IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_BCAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BORDAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9AE6A9839ED0977E0E67CBDE391756FB539F14D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BORDAUTO is

  PROCEDURE SETPARAMS(pCodAuto IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_BORDAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15A748F4EBBD2FF2C62A27161D04B2B28E8161C3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BORDEROUABON IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_BORDEROUABON; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A353FE09BA1B1E720CBFBD6A24A52F813326447B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BORDEROUAMB IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_BORDEROUAMB; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DBB00BB72F3CD2BBF4B89CF419A69AE506BB0ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BORDEROUCOM IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_BORDEROUCOM; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUIESBULK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B0FB23BD72E6111E2935E41AEA97D14F9A30796</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_borderouiesbulk IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_borderouiesbulk;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_BUGETLUNAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB459ADD34AC4E6A4605D35C22E51DBB1D0C51E9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_BUGETLUNAR is

  PROCEDURE setParams(aCodBugetProd IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_BUGETLUNAR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CAMPANII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>539A243B693B51A9C6E5C438FCBDA5B8559A9F11</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_campanii IS

  FUNCTION  Costuri (pCodCampanie IN NUMBER) RETURN NUMBER;
  FUNCTION  Venituri(pCodCampanie NUMBER) RETURN NUMBER;
  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_CAMPANII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A55F52ACF03A4E204FF7B2DF4A3708A173919E43</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CANTAR IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_CANTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CDOCIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E53D8AB0B94C74978646CA15789C87FC4298B148</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CDOCIMP IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_CDOCIMP;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CENTRCONSUMMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83EB5CA54533FF428C6A9E94F22A684643360381</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CENTRCONSUMMAT IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_centrconsummat; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57F6D68CFA4EF044E38308AA65D5ACECF902EB78</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_centrecost IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_centrecost;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CENTRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D757E32AC2396F8AA918F2F7D81211DFEBC6761</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CENTRSTOC IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_CENTRSTOC;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05AFD8E0891EC81043A4635451D15CA863A16D8B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CERTIF IS

  PROCEDURE SETPARAMS( pCodCertif IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_certif;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFEEC5217EEFB18470B4777E9E1D38CBF4442677</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CERTIFLIVR IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_certiflivr;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFLIVRTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0C01E28451E726CF43BEBD688643913CBF6B3AA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CERTIFLIVRTRANSF IS

  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_certiflivrtransf;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>713752DE92C4B0283D9ECC08B510D5A5A7F18000</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CERTIFNIR IS

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_CERTIFNIR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DB51005EEA3DE684DE7C9159F039D1AEC865AC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CHELTAVANS IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_CHELTAVANS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CHELTPARCAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>179F8A93507CDB8279BD784C65F37902527EBA74</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CHELTPARCAUTO IS

PROCEDURE SETPARAMS(      pAnLunaIni IN NUMBER DEFAULT NULL,
                          pAnLunaFin IN NUMBER DEFAULT NULL,
                          pDistZile  IN NUMBER DEFAULT 0,
                          pConsZile  IN NUMBER DEFAULT 0,
                          pCC0       IN NUMBER DEFAULT 0,
                          V_CODJOB1  IN NUMBER DEFAULT 0 );

PROCEDURE PROCESSLIST(    tmpName   IN VARCHAR2,
                          aLISTID   IN NUMBER DEFAULT 0,
                          aLISTVER  IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

FUNCTION  xCodCentru(     pCodCont  IN NUMBER,
                          pAnLuna   IN NUMBER)
          RETURN NUMBER;

FUNCTION  ContCodCentru(  pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pCodCont1 IN NUMBER,
                          pCodCont2 IN NUMBER DEFAULT NULL)
          RETURN NUMBER;

FUNCTION  IContCodCentru( pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pICont    IN NUMBER,
                          pCodPart  IN NUMBER,
                          pSemnif   IN NUMBER)
          RETURN NUMBER;

END PKG_LIST_BASE_CHELTPARCAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CHELTPARCAUTO2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCE5C1048E1D83C6A9EC84384A384888ECC8F08C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CHELTPARCAUTO2 IS

PROCEDURE SETPARAMS(
  pDataStart IN VARCHAR2 DEFAULT NULL,
  pDataEnd   IN VARCHAR2 DEFAULT NULL,
  pAllCars   IN NUMBER DEFAULT 1,
  V_CODJOB1  IN NUMBER DEFAULT 0,
  pExclCont  IN NUMBER DEFAULT 0 );
PROCEDURE PROCESSLIST(
  tmpName   IN VARCHAR2,
  aLISTID   IN NUMBER DEFAULT 0,
  aLISTVER  IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_CHELTPARCAUTO2; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CLASEPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3CC7689A327ED89846AC58E32B61B0C7CA87E4E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CLASEPART is

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) ;
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_CLASEPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CLIFARAMISCAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA745174D044C49DC84085C72C41E06DD5920C84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_clifaramiscag IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_CLIFARAMISCAG;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30A40E36B2A4032D706A66CC39BB485B1B13186D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMANDA IS

  PROCEDURE BAGA_DINAMIC_COLS;
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE SetDocAv     (pCodComanda IN NUMBER);
  FUNCTION  GetDocAv_Nr  (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv_Data(pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv_Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv1Doc (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv1Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv2Doc (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv2Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv3Doc (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv3Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv4Doc (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv4Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv5Doc (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION  GetDocAv5Val (pCodComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION GetDataAvX(pCodComanda IN NUMBER, aIDX in number) RETURN DATE;

end pkg_list_base_comanda;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMANDRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A8AAD211EA5B558DB9F812AB3E60A5BA89C5094</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMANDRAC IS

PROCEDURE setParams(
  DataStart    IN VARCHAR2,
  DataStop     IN VARCHAR2,
  pAnual       IN Number  DEFAULT 0,
  pAllCars     IN Number  DEFAULT 1,
  pTipInterval IN NUMBER DEFAULT 0,
  V_CODJOB1    IN NUMBER  DEFAULT 0 );
PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_ComandRAC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMANDREPRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2DEEECC73F31AF711891C4FB64F5BDE062022C4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMANDRepRAC IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_COMANDRepRAC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMANDSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0050C5CA0AA8F4B4F1479B6BCDCCA564E61D3D1F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMANDSA IS
  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_COMANDSA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMANDSADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF9E29073CD7EFC6B9CBACA01E5A16368BE01A7D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMANDSADOC IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER, pCodPart NUMBER, pCodSediu NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE ADD_LIST_PARAMS;
PROCEDURE setJoinuri;

end PKG_LIST_BASE_COMANDSADOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA09BCB2013227409528DD1F78A8A11748D7796A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMDOC IS

  procedure ComMatMan(tmpName IN VARCHAR2);
  function GetCodComanda return number;
  PROCEDURE SETPARAMS( pCodComanda IN NUMBER DEFAULT NULL, pID IN NUMBER, pShortVer IN NUMBER default 0);
  PROCEDURE setJoinuri;
  PROCEDURE ADD_LIST_PARAMS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_COMDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB4BADBDF100EBF8B0514F9114F03E3C9FE4D8C6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMENZI IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_COMENZI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMENZIINCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CB14F5F94AD4B7D9A6CD04E32D4BD3AAA61532F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMENZIINCURS IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_comenziincurs;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45BCCB16B92F10ECFF4A3E2D01F7EC0A2EAE7628</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMETICHETE IS

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  FUNCTION get_NrAtrib RETURN Integer;
  FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
END PKG_LIST_BASE_COMETICHETE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1A4B996867A1061CA157AE2C101461CA530319D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMETICHETEMAN is

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  FUNCTION get_NrAtrib RETURN Integer;
  FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_COMETICHETEMAN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETEMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB64F08FB899F4A962899792FA2B23A0509016B5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMETICHETEMAT IS

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  FUNCTION get_NrAtrib RETURN Integer;
  FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_COMETICHETEMAT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMINTLANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2234090C9AC64384F0FA7A9F7D961B615913736F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMINTLANS IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_comintlans; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A21ED66B93EC5938C252E533A962842640CBC5FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_compens IS

  PROCEDURE Umple_TMP_LIST_COMPENS (vCodDoc NUMBER DEFAULT 0);
  FUNCTION  GET_EXPLICATIE(pSemnificatie INTEGER,
                           pDenPart      VARCHAR2,
                           pTipDoc       NUMBER,
                           pCodDoc       NUMBER,
                           pMoneda       VARCHAR2,
                           pSemnifStins  INTEGER
                          ) RETURN VARCHAR2;
  PROCEDURE processlist (tmp_name  VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

  FUNCTION GET_PREFIXDOC_FROM_VAR RETURN VARCHAR2;
  FUNCTION GET_NRDOC_FROM_VAR     RETURN NUMBER;
  FUNCTION GET_DATADOC_FROM_VAR   RETURN DATE;

END pkg_list_base_compens; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMPENSDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21C609CAB96E6E1BF5408E37A360695604EEF91C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMPENSDOC IS

  type USERS_CURSOR is ref cursor;
  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_compensdoc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMREPRACDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76E06FADFB45BAEE22F44293FAF9E687D47E5C79</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_COMREPRACDOC AS

PROCEDURE SETPARAMS( pCodDoc NUMBER);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE ADD_LIST_PARAMS;
PROCEDURE setJoinuri;

end PKG_LIST_BASE_COMREPRACDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_COMREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B93A864AC3EC0F6E2EC66D04D63CD95A4B196F0C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_comrez IS

  PROCEDURE SETPARAMS( pCodComanda IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END pkg_list_base_comrez;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1889BF34BAF07D8A593CDF1947D1CCF4B828A867</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONST IS

  PROCEDURE SETPARAMS(  pToateConstGen IN NUMBER DEFAULT 1,
                        pToateConstUt  IN NUMBER DEFAULT 1,
                        V_CODJOB1      IN NUMBER DEFAULT 0 );
  procedure Processlist(Tmpname in varchar2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

 PROCEDURE setJoinuri;
end Pkg_List_Base_Const;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONSUM_PROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42822938ED3A268B7B57ED7E4C903466C8708893</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONSUM_PROD IS

  FUNCTION GETLASTPRETACHIZ(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GET_PMP_OBIECT (aCodObiect in number, aCodSubunit in Number, aAnLuna in number DEFAULT 0 ) return number;
  PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Sursa IN NUMBER, v_Tip IN NUMBER, v_Stoc in NUMBER DEFAULT 0, v_flgAllGest in NUMBER DEFAULT 0, v_PMP in number default 0, v_Inactive in number default 0);
  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  FUNCTION GetPretMinStoc(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GetPretMaxStoc(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GetPretMinOferta(aCodObiect IN NUMBER) RETURN NUMBER;
  FUNCTION GetPretMaxOferta(aCodObiect IN NUMBER) RETURN NUMBER;

  function GetAllArt return number;
  function GetSursa return number;
  function GetTip return number;
  function GetStoc return number;
  function GetAllGest return number;
  PROCEDURE TEST;

end PKG_LIST_BASE_CONSUM_PROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONSUM_ZILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0C77BA89412F6D0F21ACF6852E0FE29C8351217</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONSUM_ZILE is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_CONSUM_ZILE;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONTEVOLUTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA0BC9BB44191276585DE0609E8E8E0CA1036DC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONTEVOLUTIE IS

PROCEDURE SETPARAMS(pLunaIni    IN INTEGER  DEFAULT NULL,
                    pLunaFin    IN INTEGER  DEFAULT NULL,
                    pTipAnaliza IN INTEGER  DEFAULT NULL,
                    pPlanCont   IN INTEGER  DEFAULT NULL,
                    V_CODJOB1   IN NUMBER   DEFAULT 0 );

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_contevolutie;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONTRABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37FAF1F88FD098A0C2239403BE1444697821387B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONTRABON IS
  PROCEDURE setparams(aTipPer IN NUMBER DEFAULT 0, V_CODJOB1 IN NUMBER  DEFAULT 0 );
  FUNCTION  CodContract2(aCodContract IN NUMBER) RETURN NUMBER;
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_CONTRABON;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CONTRACTDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D327ECEB5260F8D69A63C622BDC94A6F9ADA6D03</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CONTRACTDOC IS

  PROCEDURE SETPARAMS(pCodCONTRACT IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_CONTRACTDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CURSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD6A3682BA7C1892B5455B2A073AA1D6142F1305</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_CURSURI IS
  PROCEDURE SETPARAMS(pDataIni       IN VARCHAR2 DEFAULT NULL,
                      pDataFin       IN VARCHAR2 DEFAULT NULL,
                      pToateMonedele IN NUMBER   DEFAULT 1,
                      pToateBancile  IN NUMBER   DEFAULT 1,
                      V_CODJOB1      IN NUMBER   DEFAULT 0 );
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_CURSURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_CUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D46FEC725B795F08C227E217DD0498823C842D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_custom IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE TESTSTOC;
  procedure TEST_PRELANSARE(aLISTID in number);
  
END pkg_list_base_custom; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_D390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA0E417295E969C347E6FB95B1C9B6329D651A2A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_D390 IS

PROCEDURE SETPARAMS( pCodD390  IN NUMBER ,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_D390;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_D390BULK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3971E4FBB25CE8FFC66AA5E2F31D6EB05EAA5816</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_D390BULK IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_D390BULK;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_D394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>183D28170A391057F426D2927EBEF031E0AB54A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_D394 IS

PROCEDURE SETPARAMS( pCodD394  IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_D394;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DECONTPARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>322B087144B8DD716DB2D491BA4220B12AC36EC6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DECONTPARTICIP is

  PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_DECONTPARTICIP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DEVUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E9DE3186EB532841D812F124009D47CFE74F681</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DEVUTILAJ is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSPARAMS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetParams(pCodUtilaj20 in number);

end PKG_LIST_BASE_DEVUTILAJ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DIFB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A536BA918036E78261C8FF72A55FC202C944004</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_difb is

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_difb;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DIFBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50E2EF1834BE7637F31967A2D7A53E51ECDF0F02</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_difbj is

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_difbj;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DIFPECOMINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E9C6FC32C96C94A6344D1E61F2D83E808746FD4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DIFPECOMINT IS

  function getpretproiectat(acodobiect in integer, acodprodcomp in number) return number;
  function getpretachiz(aCodIes1 IN NUMBER) RETURN NUMBER;
  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_difpecomint;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DIRTY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D829D3AABB2A8B87F45EF8489DBA57018CE5BA2C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DIRTY IS

 PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_DIRTY; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DISPLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FD4FE3C936297FBC7E889EA8D1F303B7E0D1246</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DISPLIVR IS

 PROCEDURE PROCESSLIST;
end PKG_LIST_BASE_DISPLIVR; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B94D3F2461D24330DEFDCD8B922A9EBDF4E01E5C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DISTRIBC is

  PROCEDURE SETPARAMS(pCodDistrib IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_distribc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>457036FF69937C8B83536B96E68F5A5BF7525AF4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DISTRIBSTOC IS

  TYPE crs_cols IS REF CURSOR;
  PROCEDURE SetParams (
    pTipSel    IN INTEGER  DEFAULT 1,
    pToate     IN NUMBER   DEFAULT 1,
    pStoc0     IN NUMBER   DEFAULT 0,
    pDetCCS    IN NUMBER   DEFAULT 0,
    pVanzPer   IN NUMBER   DEFAULT 0,
    pDataIni   IN VARCHAR2 DEFAULT NULL,
    pDataFin   IN VARCHAR2 DEFAULT NULL,
    pVanzPerAE IN NUMBER   DEFAULT 0,
    V_CODJOB1  IN NUMBER   DEFAULT 0,
    pDetRez    IN NUMBER   DEFAULT 0,
    pInfoStoc  IN NUMBER   DEFAULT 0);

  function GetDataIni return date;
  function GetDataFin return date;
  function GetDataIniS return varchar2;
  function GetDataFinS return varchar2;
  PROCEDURE BAGA_DINAMIC_COLS;
  FUNCTION  GetToate return boolean;
  FUNCTION  GetStoc0 return boolean;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END pkg_list_base_distribstoc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBSTOCLC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AB573D07DF6C24195F493E6F35773A9E5C65D4C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DISTRIBSTOCLC is

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_DISTRIBSTOCLC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCAMBALAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>359AEE8196477858D7125455FA6C3F54B217A1EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCAMBALAJE IS

  function GetCodComanda return number;
  PROCEDURE SETPARAMS( pCodDoc IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCAMBALAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCANULATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1BD5F1543AA4DD8B8E73EDA17781F21665CE842</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCANULATE IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCANULATE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17986DFC3DAF6AFBCA9C69E53E78DC6309D95036</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_DOCASOC IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_DOCASOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCAUTOFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AC270A08F4082F74B95D90D83126CE3FE1FF1FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCAUTOFACT is

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCAUTOFACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A41EE16C400C361363182F35D135E80C8D5758B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCBCAR IS

  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCBCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCBONCONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>323D38F2DFD897DE4B5D652D9C504018769F7BFA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCBONCONSUM IS

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCBONCONSUM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCCANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF70C89B2E3AB5FC7B860DFDC3D42703F0E50E05</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCCANTAR is

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_DOCCANTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EA4B877C85C957CE506FC4A96890D93BDE51126</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCCASHFLOW is

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCCASHFLOW;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCESTM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71B224B8922EAFADA661EECB8F8E2073C4979DFD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCESTM is

  PROCEDURE setParams(aCodEstimareProd IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCESTM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCESTV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BECEE4639271DA4168A8A7F30A0EC44A3C159E63</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCESTV is

  PROCEDURE setParams(aCodEstimareProd IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCESTV;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCFAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F15E1EC3C7249BD82501D0E40A113978BDCD4E3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCFAZ IS

  PROCEDURE SETPARAMS(pCodFAZ in number);
  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_DOCFAZ;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51D69E39BB8D7F86A874BD1B1AC5B4F1BA26A8F5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCIES IS

  TYPE crs_cols IS REF CURSOR;

  function GetProcente(aCodIes1 IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER, pFiltruClasaArt IN BOOLEAN);
  FUNCTION  get_cursor_coloane RETURN crs_cols;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCIESRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12628911A954D0D9263BCE3EE842B540D37778BE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCIESRETAIL IS

  TYPE crs_cols IS REF CURSOR;

  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER, pFiltruClasaArt IN INTEGER );
  FUNCTION  get_cursor_coloane RETURN crs_cols;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_dociesretail;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13831DF437A84918462935C5D3D30EAB009825EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCINTR is

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A1979DF2390236227E9417FE759D11276B4E815</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCLANSPROD IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_doclansprod;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3F8E9F9AFA654EACA7C73FBB47C3B21D27EA3EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCLANSZ IS

  PROCEDURE setParams(aCodLansZ IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_doclansz;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB9CC5D9818415F6724A25ECCCB91DF04B9B6C94</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCLANSZ_STOC is

  PROCEDURE setParams(aCodLansZ IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  FUNCTION CODLANSZ RETURN NUMBER;

end PKG_LIST_BASE_DOCLANSZ_STOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ_TRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7530A62C56B6BBF1DA2B59D031D8F3BB47C476B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCLANSZ_TRANSF is

  PROCEDURE setParams(aCodLansZ IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCLANSZ_TRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCLIBERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>119A3B9AAACC003318FFBF37AAF604C3162BF167</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCLIBERE IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCLIBERE; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCMARIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAC8A3EEE44D94A55FBC07122929E9D8ED879AC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCMARIRI IS

PROCEDURE ADD_LIST_PARAMS;
PROCEDURE SetParams( aCodDoc IN NUMBER );
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCMARIRI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCMONETARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7969B41DFDD64D11B7EE73D04A6840905238B649</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCMONETARE IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
function GetCodIes return IESIRI.CODIES%TYPE;

end PKG_LIST_BASE_DOCMONETARE; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>679EFE00625F579FB2CA40C27A1251482CEC9CCF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCNECESAR IS

  PROCEDURE setParams(aCodNecesar IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCNECESAR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCNEOPERATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A09F56FAA44F0567E6DF38155D3C136C01EE2526</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCNEOPERATE IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCNEOPERATE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06E50F3CA1EB816A624EEB036D32454EC2D72D26</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCPLANIFPROD is

  PROCEDURE setParams(aCodPlanifProd IN number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCPLANIFPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E9DBA58A4A62B32F0B59EC7851BCC819F83AE3D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCPLATI IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
  PROCEDURE setJoinuri;

END pkg_list_base_docplati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLATIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1FA10FB036A9DD396BAA4A1D9B88AD2100E51FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCPLATIP IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SETPARAMS(pCodDoc IN NUMBER, pCodPart IN NUMBER);
  PROCEDURE setJoinuri;

END pkg_list_base_docplatip;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCPRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>723AFFE56E7E33FD31F8AC44217059B1E4F170E7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCPRODNET is

PROCEDURE SetParams( aCodDoc IN NUMBER, aTip in number);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_docprodnet;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCPROFORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FDEBB1A64610D5EDB8F7134E974B75990177E020</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_docproforma IS

  TYPE crs_cols IS REF CURSOR;

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  FUNCTION  get_cursor_coloane RETURN crs_cols;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCPROFORMA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCSETTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B63574BD8CDBE515B852701346C712B6A6860491</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCSETTASK IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE ProcessList(TmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_DOCSETTASK;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCTRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A93E6BAF2444009625E9866C79075CD2AF15CC14</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCTRANSPORT IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCTRANSPORT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D20381A726A251AAFE894C377ABFDC5159934F14</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCTREZOR IS

  PROCEDURE SETPARAMS( pCodTrezor  IN NUMBER DEFAULT NULL,
                       pCodTrezor1 IN NUMBER DEFAULT NULL
                      );
  PROCEDURE SetJoinuri;
  FUNCTION  OBLIGPIF_DENDOCLEGATURA( pCodObligPif IN NUMBER, pSemnificatie IN NUMBER) RETURN VARCHAR2;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_DOCTREZOR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCVOUCHRETR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>961CB7CD9627352E22678B4B89718F8463E0E11B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCVOUCHRETR IS

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER DEFAULT NULL, pTipDoc IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCVOUCHRETR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCVOUCHRRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92BA332438FF059128DB2785B40F052FB647BDC3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCVOUCHRRET IS

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCVOUCHRRET;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCWCF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E6DBA408DD9E541D457BEA87E29EE3225CC30F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCWCF IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCWCF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DOCWCFP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6799A1CAC5B9DCC96204B923326AE561EE5E19FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DOCWCFP IS

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_DOCWCFP;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DREPTUSERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F003B33FEAB67C5C2767EBEC4B5556DCD7A4A7C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DREPTUSERI IS

  --PROCEDURE SETPARAMS(ADATAS IN varchar2 ,ADATAF IN varchar2);
  procedure processList(tmpname in varchar2, listid in number default 0, listver in number default 0);
  PROCEDURE setJoinuri;
  
END PKG_LIST_BASE_DREPTUSERI;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DURATAMEDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01AEE34903EC44ED5B40AAF764AEA2ADB24B99E6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DURATAMEDCLI IS

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_DurataMedCli; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_DURATAMEDFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC97C268DB5B81B3D26808A93C172EF69CEE0A4D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_DURATAMEDFURN IS

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_DurataMedFurn; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EFECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>726DCA83A50F0ABB5FA8D76C9FD969BB87D1FB17</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EFECTE IS

  PROCEDURE SETPARAMS(pTipTranz IN NUMBER, 
                      pPeDocumente IN NUMBER  DEFAULT 0,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 ,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2
                      );
                      
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_EFECTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EFECTEREMISE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD62000FF93A4B4E67550FB8746790EFD818136A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_efecteremise IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
	PROCEDURE setJoinuri;

END PKG_LIST_BASE_EFECTEREMISE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7B1D90057E52DFF7B804B0474B1A4DBAC2E947E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_emulare IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_EMULARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EMULAREDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D417B2328B0057A99834ECF2462509606143454</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EMULAREDOC IS

  PROCEDURE SETPARAMS(pCodEmulare IN NUMBER, pCodGest IN NUMBER);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_EMULAREDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EMULARESINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D907F1CCFC0F2A48DC8D91885214C1A0ABAD459B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_emularesint IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END pkg_list_base_emularesint; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ETVAWME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>419857879084D51B1EC35F6F5FA82E7979B282E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ETVAWME IS

  PROCEDURE SETPARAMS(pNrCrt IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER, pSubunit IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_ETVAWME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EUDR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D640BD6819835ACC1CB11F0A45F85C99AFA050CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EUDR is

procedure CreateTmp;
procedure CompleteazaSemif(aCodnirstoc in number, aCodNirStocS in number, aCantSemif in number);
PROCEDURE setParams (
  pDupaData   IN NUMBER   DEFAULT 1,
  pDataIni    IN VARCHAR2 DEFAULT NULL,
  pDataFin    IN VARCHAR2 DEFAULT NULL,
  pLunaAnIni  IN INTEGER  DEFAULT 0,
  pLunaAnFin  IN INTEGER  DEFAULT 0,
  pNP         IN INTEGER  DEFAULT 0,
  pIes        IN INTEGER  DEFAULT 0,
  pTipA       IN INTEGER  DEFAULT 0,
  pTipV       IN INTEGER  DEFAULT 0,
  pEUDRA      IN VARCHAR2 DEFAULT NULL,
  pEUDRV      IN VARCHAR2 DEFAULT NULL,
  pAllCls     IN NUMBER   DEFAULT 1,
  pAllArt     IN NUMBER   DEFAULT 1,
  pCodJob1    IN NUMBER   DEFAULT 0
);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
procedure test;

end PKG_LIST_BASE_EUDR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1DDDBD2B00CE82119868EA387FA7383BED30AA1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EVIDENTAMF is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_EVIDENTAMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E66C5056EDE57E5EF198B687D446D4C935F17EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_expert IS
  PROCEDURE BAGA_DINAMIC_COLS;
  FUNCTION GETCODANALIZA RETURN NUMBER;
  PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  FUNCTION GET_VALOARE(S in varchar2 ,I in number) RETURN VARCHAR2;
  PROCEDURE POPULEAZA_COL_DINAMICE(tmpname in varchar2);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_EXPERT;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTBAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>297F6A9D9C3C6D68DC5A2D50F9360B4BD1386293</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EXPERTBAL IS
  PROCEDURE SETPARAMS (
    pCodAnaliza IN NUMBER,
    pAn         IN NUMBER,
    pLuna       IN NUMBER,
    v_CodJob1   IN NUMBER DEFAULT 0 );
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
END PKG_LIST_BASE_EXPERTBAL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50A97EE15E8ECA58DE9E6590E5F2D600D5D2D994</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EXPERTBUGET IS
  PROCEDURE BAGA_DINAMIC_COLS;
  FUNCTION GETCODANALIZA RETURN NUMBER;
  PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  FUNCTION GET_VALOARE(S in varchar2 ,I in number) RETURN VARCHAR2;
  PROCEDURE POPULEAZA_COL_DINAMICE(tmpname in varchar2);
  PROCEDURE setJoinuri;
END pkg_list_base_expertbuget;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTCC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEDF1E931011C5B9904DE3E80B48F07C0F96D203</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EXPERTCC IS

  PROCEDURE SETCODANALIZA (aCodAnaliza NUMBER);
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END pkg_list_base_expertcc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTCCBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFF9CE134E30400841B39DDBE44F67FFF5C0893C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EXPERTCCBUGET IS
  PROCEDURE BAGA_DINAMIC_COLS;
  PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_expertccbuget;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTEXECB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A0F156E25F9C64CEED0185E8D2598881A028529</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_EXPERTEXECB IS
  PROCEDURE SETPARAMS (pCodAnaliza NUMBER, pAn NUMBER, pLuna NUMBER, v_CodJob1 IN NUMBER  DEFAULT 0 );
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_EXPERTEXECB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FACTASTEPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E042D996DFE5FD308A87C59DA8E4599B845B7089</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FACTASTEPT IS

  PROCEDURE processlist (tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_FACTASTEPT;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FACTIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>496F3B6BCC2B4664797973EBA55A23C6622F16F5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FACTIES IS

  PROCEDURE PROCESSLIST(tmpName VARCHAR2);

end PKG_LIST_BASE_FACTIES; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FACTINTOCMIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DFA0CC09824B9CF2B2901B4B88EFCC03944F9F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FACTINTOCMIT IS
  PROCEDURE processlist (tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_factintocmit;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FACTNESOSIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC4F50F02177A3563D1B7E40F85C2E9E4BB30B89</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FACTNESOSIT IS

  PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE TEST;

End PKG_LIST_BASE_FACTNESOSIT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C67DFE487241D89978EF04EC52234CEB97E2EE5F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FAZ IS

  PROCEDURE SETPARAMS(pDataIni    IN VARCHAR2 DEFAULT NULL,
                      pDataFin    IN VARCHAR2 DEFAULT NULL,
                      pAllAuto    IN NUMBER   DEFAULT 1,
                      pAllSoferi  IN NUMBER   DEFAULT 1,
                      V_CODJOB1   IN NUMBER   DEFAULT 0 );
  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_FAZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FIDELIZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FE12F0C1C60AB53B1DA3D18984C08852C8958BD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FIDELIZARE IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_fidelizare; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAANALITIKPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D8A43266BB06B7EFEADED2F546743C1FCF25714</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAANALITIKPART IS

  PROCEDURE SET_LISTA_PARAMS (
    IsAllMoneda IN NUMBER  DEFAULT 1,
    IsAllCont   IN NUMBER  DEFAULT 1,
    IsAllSub    IN NUMBER  DEFAULT 1,
    IsBalanta   IN NUMBER  DEFAULT 1,
    aCodpart    IN NUMBER,
    aLunaStart  IN NUMBER,
    aLunaFin    IN NUMBER,
    aTipIopart  IN NUMBER  DEFAULT 0,
    IsDefalcLoc IN NUMBER  DEFAULT 1,
    IsDefalcDoc IN NUMBER  DEFAULT 0,
    AduInfoCM   IN NUMBER  DEFAULT 0,
    pCodJob1    IN NUMBER  DEFAULT 0,
    pAllSting   IN NUMBER  DEFAULT 0,
    IsSubStins  IN NUMBER  DEFAULT 0,
    pExpert     IN NUMBER  DEFAULT 0,
    pMonSold    IN NUMBER  DEFAULT 0
  );
  PROCEDURE setSemnificatii;
  PROCEDURE processList(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION GetDataDecont(pCodDoc IN NUMBER, pTipDoc IN NUMBER) RETURN VARCHAR2;
  function getreg1ifrs(aCodGeneral in number, aDifIFRS in number, aAnLuna  in number, aCursIFRS in number, aSoldDoc in number) return number;
  function getTrezIFRS(aCodGeneral in number, aMoneda  in number, aValoare in number, aAnLuna   in number) return number;

END pkg_list_base_fisaAnalitikPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1503E23A4DCD118519F86837BD8AD622FF8DA1F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISACONT IS

  TYPE crsFCont IS REF CURSOR;

  PROCEDURE UTIL_FISACONT(sTabCont OUT VARCHAR2, sCodCont  OUT VARCHAR2);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_FISACONT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA3EEB0514EC49A364E27401679876FA0ED8C0BF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_fisacont2 IS

  TYPE crsFCont IS REF CURSOR;

  PROCEDURE BAGA_DINAMIC_COLS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_FISACONT2;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA4A1888B4D1D9B11F2B57B655B9485409674313</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISACONT3 IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END pkg_list_base_fisacont3;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D13D4BA1EED49D5F9E4601616BDB3DAD271A042</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAMAG IS


	FUNCTION get_TVA_ARTICOL (p_codobiect IN NUMBER,p_an IN NUMBER,p_luna IN NUMBER) RETURN NUMBER;
	PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_FISAMAG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAG2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28BE654A8BF42E345A947B358713B340FD8E4FE2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAMAG2 IS

PROCEDURE SETPARAMS(ACODOBIECT IN NUMBER);
PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE maketmpSerii;
PROCEDURE setJoinuri;
end pkg_list_base_fisamag2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C1493FE650660D0A50648C12DF5596AEB4DFB69</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAMAS IS

  PROCEDURE SETPARAMS(pCodFisaMas IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_fisamas;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAMENTENANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D242728BFD442905DB39B623B691933817A81BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAMENTENANTA IS

  function AduDescriere(aCodUtilaj2 in number) return varchar2;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE SETPARAMS(aCODUTILAJ20 IN NUMBER,
					            V_CODJOB1 IN NUMBER  DEFAULT 0, 
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2
                      );

end PKG_LIST_BASE_FISAMENTENANTA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC83887AA593DC424FED5782D86C4BB9701351D4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAMF is

  PROCEDURE setParams (v_Tabla IN VARCHAR2, vCodMifix in number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE PROCESSPARAMS;

end PKG_LIST_BASE_FISAMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42E6947422CFF09BDB022B1A9F33FA2BAED141E3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISAPERS IS

  function GetSimbolCor(aCodObligPif in number, aCODNBANKCONT in number) return varchar2;
	PROCEDURE processList(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE processListHolding(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
	
END PKG_LIST_BASE_FISAPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISASAH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13B5338DAD70165AA2227FD686005E2EF16642AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FISASAH IS

  type crsConturi is ref cursor;
  PROCEDURE BagaDinamicCols ;
  FUNCTION  getConturi (pTip IN NUMBER DEFAULT 0, pAnLuna IN NUMBER DEFAULT 0) RETURN crsConturi;
  FUNCTION  getCodCont RETURN NUMBER;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetParams  (pTip IN NUMBER); -- pentru joburi
  PROCEDURE SetJoinuri;

END pkg_list_base_fisasah;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FISAURMINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>216B26127F0742EBFF2CD7E7DE9EB723BB7F1C31</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_fisaurminc IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

PROCEDURE SetJoinuri;

end pkg_list_base_fisaurminc;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_FUZIONARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8B36D05E639E872A2BE75C650FAD5288BADB01E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_FUZIONARE IS

  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetParams(aTip IN NUMBER);

END PKG_LIST_BASE_FUZIONARE; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_GANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74B55785287552A7F81DFE1274A13E0966446BB3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_gant is

PROCEDURE setJoinuri;
PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_gant; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_GEND39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C1919D019790305290A832DF17113E083975A68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_gend39416 IS

PROCEDURE SETPARAMS( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end pkg_list_base_gend39416;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_GENDINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>279F0C96CE189DE3E835BC28B82FFD54B3C6CC55</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_GENDINTRASTAT IS

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_GENDINTRASTAT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_GRADI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F96F6D10635D9A778DFFAF84DBCDE85D17325227</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_GRADI is

  PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_GRADI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_GRAD_INC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>453B0767F250C3FF9F01B3DCE5D448DBBE1CBD8C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_grad_inc IS

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
FUNCTION TOTAL_M(aCodGest IN NUMBER, aCodGrEchiv IN NUMBER, aZi IN DATE) RETURN Number;
FUNCTION TOTAL_I(aCodGest IN NUMBER, aCodGrEchiv IN NUMBER, aZi IN DATE) RETURN Number;

end PKG_LIST_BASE_GRAD_INC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45F4EA041E5348E2B9030204858C08A81F1F3583</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESEXT IS
  PROCEDURE PROCESSLIST  (tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_IESEXT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F818164AC155054F0A3C013A4DBB89E0B0CA3719</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESFURN IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_IESFURN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CDC0DA88211FBB01E8D4F0D135348195F052995</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESGEST IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_IESGEST; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D94F2E040DB717D397CC99ABB29D75E9724538B7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESIRI IS

function GetTop30(aCodAgent in number) return varchar2;
PROCEDURE setSimpl;
PROCEDURE setVar;
PROCEDURE unsetSimpl;
PROCEDURE BAGA_DINAMIC_COLS;
FUNCTION CALCPIES (   pCodIes      IN NUMBER,
                      pTipDoc      IN NUMBER,
                      pCant        IN NUMBER,
                      pPU          IN NUMBER,
                      pTVA         IN NUMBER,
                      pADDim       IN NUMBER,
                      pCoefDiscMaj IN NUMBER,
                      pValDiscPret IN NUMBER,
                      pInclTVA     IN NUMBER DEFAULT 0) RETURN NUMBER;
FUNCTION  Sql_tmp_lst_iessimpl (pFiltru IN VARCHAR2, pInclCodIOPART1 IN NUMBER DEFAULT 0, pInclCodContr1 IN NUMBER DEFAULT 0) RETURN CLOB;
FUNCTION  Sql_tmp_lst_iesiri   (pFiltru IN VARCHAR2) RETURN CLOB;
PROCEDURE INSERTIESSIMPL(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pSuplJoins IN VARCHAR2);
PROCEDURE INSERTSINTEZA (TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pSuplJoins IN VARCHAR2);
PROCEDURE PROCESSLIST   (tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

PROCEDURE SetJoinuri;

end PKG_LIST_BASE_IESIRI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESIRISIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>394FDBA89B3228184D313EEB429B9411C4D9FFBC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_iesirisimpl IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE SetJoinuri;

END pkg_list_base_iesirisimpl;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESIRISINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F1C8DC934130DA75F6ED8F8659AFE7A04B06328</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_iesirisint IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE SetJoinuri;

END pkg_list_base_iesirisint;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33AB52AEFED12F74FC6F457F54046C3B31B2AC27</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESMF is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;  

end PKG_LIST_BASE_IESMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IESPU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D44F7EB628826D8F034DABE7C9F1667633A178B3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IESPU is

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
PROCEDURE setJoinuri;  

end PKG_LIST_BASE_IESPU; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IMBMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B91C0E9ECA45ED6A2E9AC6871DE738652B66C54B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IMBMIFIX IS

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

end pkg_list_base_imbmifix;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IMOBILIZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEF810AB7CADC934FD0648CD88982DE917D18615</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IMOBILIZARI is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_IMOBILIZARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IMPORTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C51F2B8B2D42DA231916AB35B2D58F027427C4D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IMPORTURI IS

  function getaccizelinie(acoddvi1 in number) return number;
  function getcomisionlinie(acoddvi1 in number) return number;
  function gettaxelinie(acoddvi1 in number) return number;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_importuri; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INCFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>057ED20E93132E779C71E23645402B4F61CD8E4F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_incfact IS

  PROCEDURE setParams(pDataS    IN VARCHAR2 DEFAULT NULL,
                      pDataF    IN VARCHAR2 DEFAULT NULL,
                      pAnual    IN NUMBER DEFAULT 0,
                      pOpt1     IN NUMBER DEFAULT 0,
                      pOpt2     IN NUMBER DEFAULT 0,
                      pOpt3     IN NUMBER DEFAULT 0,
                      pOpt4     IN NUMBER DEFAULT 0,
                      V_CODJOB1 IN NUMBER  DEFAULT 0,
                      pDataRef IN VARCHAR2 DEFAULT NULL,
                      pAllAg    IN NUMBER DEFAULT 1,
                      pAllPart  IN NUMBER DEFAULT 1,
                      pCriteriu IN NUMBER  DEFAULT 0,
                      pSumarIncFact IN NUMBER DEFAULT 0,
                      pTotFact  IN NUMBER DEFAULT 0
                      );


  function GetValMarfa(aCodies number) return number;
  function GetAdaos2(aCodies number, aTipDoc number) return number;
  function doc0(aCodIes NUMBER) return number;
  function StingereValida(aCodDoc in number, aTipDoc in number) return number;
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  procedure AduStringuriCriteriu1(TmpName in varchar2);
  function GetValAchiz(aCodIes number) return number;

end pkg_list_base_incfact; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INLOCUIREAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15F9233F8EAE587176B457D6BAE3ED89C27AEEB3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INLOCUIREAGENT IS

 PROCEDURE processlist(tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_INLOCUIREAGENT; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INTERVUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CC439F1DF5217EF8C3AD550B690E67163D71A6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_intervutilaje IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_intervutilaje; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F83DDF7686FD4D8486C5AB284E0C72495999B109</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INTRARI IS

PROCEDURE setVar(aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
FUNCTION  Sql_tmp_lst_intrari   (pFiltru IN VARCHAR2) RETURN CLOB;
PROCEDURE INSERTSINTEZA(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pJoinExt IN VARCHAR2);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_INTRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INTRARISINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27FAE3B0DAABB5914B11C94274169054BE42398A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_intrarisint IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END pkg_list_base_intrarisint;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INTREXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A46B55732B3F07DE4984FC7D56F04F66EEE85935</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INTREXT IS
  PROCEDURE PROCESSLIST  (tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_INTREXT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INTRMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37D4CD059F4CABF058E337C1846D33272EC9F947</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INTRMF is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;  

end PKG_LIST_BASE_INTRMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08D9E121D1DD64A5178C2EB78D829EA0180BEE09</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INVENTAR IS

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setParams (aCodInventar IN NUMBER, pID IN NUMBER,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      );
PROCEDURE setJoinuri;
end pkg_list_base_inventar; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_INVENTAR_REST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01AA9774E051FC4821BA7428C033116D9B2B6F37</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_INVENTAR_REST IS

  procedure SetRestaurant(aCodRestaurant in number);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_INVENTAR_REST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7978CE149E8CE6A7D21894020C69EECF547D8692</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IOART IS


  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end PKG_LIST_BASE_IOART; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0E026F79FCD40057365C9D784290AC3E7AB5BE3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IOBANK IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;


end PKG_LIST_BASE_IOBANK; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>190C20BF9DC947F0C74FDB186B237B226A7C58DE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IOPART IS

 PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end pkg_list_base_iopart; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>922568CB0FF9D87618719E4665A91B109C7A506B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IOPERS IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;


end PKG_LIST_BASE_IOPERS; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_IPOASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA60775243426D79E7AB1755FFA6F6494BD55096</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_IPOASIG is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;    

end PKG_LIST_BASE_IPOASIG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ISTORICPRETIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31F6025E9126E76463F0EFE3A36E0DDEC1EB9724</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ISTORICPRETIES IS

  PROCEDURE SETPARAMS( pCodObiect IN NUMBER );
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_ISTORICPRETIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ISTORICPRETINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC759AE27611D55BED811A3F98A6507EF5C7A8F3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ISTORICPRETINTR IS

  PROCEDURE SETPARAMS( pCodObiect IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_ISTORICPRETINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_JOBCORELREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D278BE8A8D476E4B10B0881905961C3E746F0977</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_jobcorelrez is

  PROCEDURE SETPARAMS(pCodJob IN NUMBER DEFAULT NULL,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 );
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_jobcorelrez;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_JURNCUMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>985C76480D3175728D4CA4146FAC585C319EED05</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_JURNCUMP IS
  PROCEDURE SetPerioada (pAn NUMBER, pLuna NUMBER, pTip INTEGER, pSubunit NUMBER DEFAULT NULL, pExclNoEconomicActiv BOOLEAN DEFAULT FALSE);
  FUNCTION  GetAnLunaIni RETURN NUMBER;
  FUNCTION  GetAnLunaFin RETURN NUMBER;
  FUNCTION  GetAnLista   RETURN NUMBER;
  FUNCTION  GetLunaLista RETURN NUMBER;
  PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_jurnCump;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_JURNVANZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>485899270D80CE0EA3937B164102C25B9EAB7A2D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_JURNVANZ IS
  PROCEDURE SetPerioada (pAn NUMBER, pLuna NUMBER, pTip INTEGER, pSubunit NUMBER DEFAULT NULL, pExclNoEconomicActiv BOOLEAN DEFAULT FALSE);
  FUNCTION  GetAnLunaIni RETURN NUMBER;
  FUNCTION  GetAnLunaFin RETURN NUMBER;
  FUNCTION  GetDataIni   RETURN DATE;
  FUNCTION  GetDataFin   RETURN DATE;
  FUNCTION  GetAnLista   RETURN NUMBER;
  FUNCTION  GetLunaLista RETURN NUMBER;
  FUNCTION  getStinsDoc(pCodObligPif IN NUMBER, pAL IN NUMBER) RETURN NUMBER;
  PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_jurnVanz;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LANSETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1FE1D3EAAE303218FB73498AA5A212A35F2CA63</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LANSETICHETE IS

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER ,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      );
  FUNCTION get_NrAtrib RETURN Integer;
  FUNCTION DenAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2;
  FUNCTION ValAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2;
  FUNCTION CodAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_lansetichete;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC5D283B417F285E5E8D6B79463224F049BFCB98</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LANSZ IS

  PROCEDURE setParams(pSetimanaIni in number, pSetimanaFin in number, pAn in number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  procedure test;

end PKG_LIST_BASE_LANSZ; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LEADS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33A71EFFB1A28095EE178F92684264B6B7743BAE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_leads IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_LEADS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LISTDISPLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAF24A8153CB7C7D395D0C2316048919C4EAFD60</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LISTDISPLIVR is

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_LISTDISPLIVR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EC83B5296B1053646594F28FF07CEB61883609E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRARI IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION GET_PROCENT_TVA(ACODOBIECT IN NUMBER, ACODINTR1 IN NUMBER, ACODTRANSF1 IN NUMBER, ACODIES1 IN NUMBER) RETURN NUMBER;

end PKG_LIST_BASE_LIVRARI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>588DDB4BA4372B4CE2D0334EF10A038737947252</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_livrdoc IS

  PROCEDURE SETPARAMS( pCodIes  IN IESIRI.CODIES%TYPE       DEFAULT NULL,
                       pCodGest IN NGEST.CODGEST%TYPE       DEFAULT NULL,
                       pDoarInRosu IN BOOLEAN DEFAULT FALSE);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_LIVRDOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRFROMNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2589F19983CFC48124427100B7BA3780BB8D06AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRFROMNIR IS

  PROCEDURE SETPARAMS(pConditieStocNegativ IN VARCHAR2, pTipAnaliza IN NUMBER, pCodDocAnalizat IN VARCHAR2);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
  PROCEDURE setJoinuri;

end pkg_list_base_LIVRFROMNIR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRINTRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55B3972E3355EF2F9FA4DC4818B24798EF783526</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_livrintrdoc IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) ;
PROCEDURE setJoinuri;
PROCEDURE SETPARAMS( pCodIntr IN NUMBER DEFAULT NULL,
                     pCodGest IN NUMBER DEFAULT NULL);

END pkg_list_base_livrintrdoc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRNEREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B37EC9B6907F98EF9609C734223ABA704FBF81B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRNEREZ IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_LIVRNEREZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRPKDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3AA4135E166D98A5FE97F4178A837038018766D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRPKDOC IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  PROCEDURE SETPARAMS(pCodPachete IN NUMBER);

end pkg_list_base_livrpkdoc; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRSIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19D3419628F6E42421E87F6D00B1539A9738D2F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRSIMPL IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_LIVRSIMPL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LIVRTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD9ABBEB2F6A6AB9CA26B9DC166567D7F7D86A52</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LIVRTRANSF IS

PROCEDURE SETPARAMS( pCodTransf IN NUMBER DEFAULT NULL,
                     pCodGest   IN NUMBER DEFAULT NULL);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE SetJoinuri;

end PKG_LIST_BASE_LIVRTRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LOGIMPORTCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F8C6B8A19AFB75EA0BBC797B501118D73733C08</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LOGIMPORTCOM IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_LOGIMPORTCOM;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_LOGUSERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8388E3B4A2F1D8B9AE6A04E30D38D9E3EC86A4B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_LOGUSERI IS

  PROCEDURE SETPARAMS(ADATAS IN varchar2, ADATAF IN varchar2, v_codjob1 in number);
  procedure processList(tmpname in varchar2, listid in number default 0, listver in number default 0);
  PROCEDURE setJoinuri;

end pkg_list_base_loguseri;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34A8F41F469701A484BB0FC5A97E691E3A4A8331</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MAIL IS

PROCEDURE SETPARAMS( Zi1 DATE, Zi2 DATE );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_MAIL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MANCONFORMNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F650AF67D724CFA290090EAB6E15A651C1B2CA1F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MANCONFORMNP IS

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_manconformnp; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MANPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BA7E2A2C19F10B39BC0FAEB56C7C25B7FF7B4DF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MANPROD IS

  PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Tip IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 

end pkg_list_base_manprod; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MARIRIDIMIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11A88A59E4F93041C17D0FD0DE5048926396AD80</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MARIRIDIMIN IS

  PROCEDURE setTipLista (p_tipLista IN NUMBER);
  PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end pkg_list_base_maririDimin; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MATRCV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA1930E37BCC2B1FC06EAF2174EE2FC800C053C5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_matrcv IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end pkg_list_base_matrcv; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MATSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6C8719EDB12258A65F100C2FE187AEAEC105E79</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MATSA IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_MATSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0331037698CACC3F144C60215F5B133DE2209C4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MIFIX IS

  PROCEDURE setParams (
    p_ToateMF  IN NUMBER DEFAULT 1,
    p_TipSelMF IN NUMBER  DEFAULT 0,
    p_Amo IN NUMBER  DEFAULT 0);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_MIFIX; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MISCARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9FD5829E172A10F4046E761933929A2A8BD735BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_miscari IS

 PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end pkg_list_base_miscari; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MODIFPRETDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79CBD86DDB8C1D2B32BC3A62C6D3D29D937AD687</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_modifpretdoc IS

  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_MODIFPRETDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MODIPBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F86C861B5BF3F20E84B5EFD48479DB99614F7AF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MODIPBCAR is

PROCEDURE SETPARAMS(aTipBCAR in NUMBER, aCodSediu in NUMBER, aCodPart in NUMBER, aDataStart in varchar2, aDataStop in varchar2, aCodObiect in number, aObs in varchar2);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_MODIPBCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MONETARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79A0749854220AC57D5A566642AC8B97AE5EE3DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MONETARE IS

PROCEDURE setFiltre ( pToateArt IN BOOLEAN,  
                      pDupaData IN BOOLEAN DEFAULT FALSE,
                      sData     IN VARCHAR2);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_MONETARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MONETAREMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51C34BF4A8CB0BF9EA913F062EBBE97FD48E1414</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MONETAREMP IS

PROCEDURE BAGA_DINAMIC_COLS;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_MONETAREMP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MPCD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>891204895494CFAF9B24C393A0A0317032903AC7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MPCD is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
end PKG_LIST_BASE_MPCD;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MPCP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D220808E6D0CAE3F3F7E0851FC0ECD611A53D7A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MPCP is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_MPCP;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MPVD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07EB16132B6E18FE5A1737BF2CC33464C5301208</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_mpvd is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_mpvd;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_MPVP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15F725A0E92D46CDA2F38764222A9A52181BFEBE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_MPVP IS

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_MPVP; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7C19CE32844676E43D80804F06B8B7D0457D5C6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_naproviz1 IS
 PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
 PROCEDURE SETPARAMS(
  pToateGest    IN INTEGER  DEFAULT 1,
  pToateIoart   IN INTEGER  DEFAULT 1,
  pDataIni      IN VARCHAR2 DEFAULT NULL,                          
  pDataScad     IN VARCHAR2 DEFAULT NULL,
  pSubCurenta   IN INTEGER  DEFAULT 1,
  pExtra1       IN INTEGER  DEFAULT 0,                             
  pExtra2       IN INTEGER  DEFAULT 0,
  pCentralizat  IN INTEGER  DEFAULT 0,                             
  pCodJob1      IN NUMBER   DEFAULT 0,
  pCodProiect   IN NUMBER   DEFAULT 0,
  pCant         IN NUMBER   DEFAULT 1                              
 );
 function CodProiect return number;
 function SubCurenta return number;
 function AllGest return number;
 function AllIOArt return number;
 function Cant return number;
end PKG_LIST_BASE_NAPROVIZ1; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBAD2FCED72DAF72B66E6F8DE44C5ACBF533EE42</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ2 IS
  PROCEDURE SETPARAMS(
    pToateGest    IN NUMBER   DEFAULT 1,
    pToateIoart   IN NUMBER   DEFAULT 1,
    pDataCIni     IN VARCHAR2 DEFAULT NULL,
    pDataCFin     IN VARCHAR2 DEFAULT NULL,
    pTipVanz      IN VARCHAR2 DEFAULT NULL,
    pPerVanz      IN NUMBER   DEFAULT 0,
    pDataVIni     IN VARCHAR2 DEFAULT NULL,
    pDataVFin     IN VARCHAR2 DEFAULT NULL,
    pUltAchiz     IN NUMBER   DEFAULT 0,
    pCuTermen     IN NUMBER   DEFAULT 0,
    pTermen       IN VARCHAR2 DEFAULT NULL,
    pPeZile       IN NUMBER   DEFAULT 0,
    pNrZile       IN NUMBER   DEFAULT 0,
    pAfectare     IN NUMBER   DEFAULT 0,
    pClasa        IN NUMBER   DEFAULT 0,
    pClasaS       IN NUMBER   DEFAULT 0,
    pProd         IN NUMBER   DEFAULT 0,
    pZileStoc     IN NUMBER   DEFAULT 0,
    V_CODJOB1     IN NUMBER   DEFAULT 0,
    pPeLuni       IN NUMBER   DEFAULT 0,
    pRestCmd      IN NUMBER   DEFAULT 0,
    pDim          IN NUMBER   DEFAULT 0,
    pVanzEmul     IN NUMBER   DEFAULT 0,
    pClasaW       IN NUMBER   DEFAULT 0,
    pCuComenzi    IN NUMBER   DEFAULT 1,
    pCuArtFaraVanz IN NUMBER  DEFAULT 1,
    pDefalcat     IN NUMBER   DEFAULT 0,
    pAllCls       IN NUMBER   DEFAULT 1,
    pStocuriGest  IN NUMBER   DEFAULT 0
  );

  FUNCTION GETCUCOMENZI RETURN NUMBER;
  FUNCTION GETVANZEMUL RETURN BOOLEAN;
  FUNCTION GETDIM RETURN BOOLEAN;
  FUNCTION GETPELUNI RETURN BOOLEAN;
  FUNCTION GETTIPVANZ RETURN VARCHAR2;
  FUNCTION GETPEZILE RETURN NUMBER;
  FUNCTION GETNRZILE RETURN NUMBER;
  FUNCTION GETAFECTARE RETURN NUMBER;
  FUNCTION GETALLGEST RETURN NUMBER;
  FUNCTION GETALLIOART RETURN NUMBER;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION GETDATACINI RETURN DATE;
  FUNCTION GETDATACFIN RETURN DATE;
  FUNCTION GETDATAVINI RETURN DATE;
  FUNCTION GETDATAVFIN RETURN DATE;
  FUNCTION GETULTACHIZ RETURN BOOLEAN;
  FUNCTION GETCUTERMEN RETURN NUMBER;
  FUNCTION GETTERMEN RETURN DATE;
  FUNCTION GETCLASA RETURN NUMBER;
  FUNCTION GETCLASAS RETURN NUMBER;
  FUNCTION GETPROD RETURN NUMBER;
  FUNCTION GETZILESTOC RETURN NUMBER;
  FUNCTION GETRESTCMD RETURN BOOLEAN;
  FUNCTION ALLCLS RETURN BOOLEAN;
  PROCEDURE CalculeazaZileStoc(tmpName IN VARCHAR2);
end PKG_LIST_BASE_NAPROVIZ2; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3E96426995BFB3DDFE435EB49229662FA89CA37</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ3 IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_NAPROVIZ3; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>023FE56A5B9539CA32DBC16C3E37C562F2D4678C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ4 IS
  
  procedure UmpleTemporarGenerator(vCodNecesar in number);
  procedure UmpleTemporar;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  
end PKG_LIST_BASE_NAPROVIZ4; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ5</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70A0D300149DE8C0DA7800FC5268FBED5D231B05</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ5 IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  procedure MakeIesiri;
  procedure MakeStocuri;
  procedure MakeComenzi;
  procedure MakeConsumuri;
  procedure Test;

end pkg_list_base_naproviz5; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ6</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77A2F056DCD49C3D8770F9864389181AF6D85CDB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ6 is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  procedure UmpleTabela6Z(aDataRef in varchar2,
                          pClasa IN NUMBER DEFAULT 0,
                          pClasaS IN NUMBER DEFAULT 0,
                          pProd IN NUMBER DEFAULT 0,
                          pClasaW IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NAPROVIZ6;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ7</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66049AD77CA91638E6FF5673BE9165FA6D3BCE06</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NAPROVIZ7 is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE CalculeazaZileStoc(tmpName IN VARCHAR2);
  procedure test;

end PKG_LIST_BASE_NAPROVIZ7;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCD330AE2519F56CBE6F6B8E8DFF7825D59907E4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_nart IS

PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NARTOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4B2D6C88C2512544F5CFAFA37D2A4FA4C95864B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NARTOFE IS

PROCEDURE SETPARAMS( pToateArt     IN NUMBER DEFAULT 1,
                     pPretImplicit IN NUMBER DEFAULT 1,
                     pCatPret      IN NUMBER DEFAULT 0,
                     pStocSubCur   IN NUMBER DEFAULT 0);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NARTOFE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NARTPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>087C9DCF2765BD246935B5D3D472D30F23AA5B68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_nartpart IS

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_nartpart;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NARTUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EDCCCA906284D6B14138330F2048262A96EE239</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NARTUM IS

PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_NARTUM;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BC85EB86D3AD8C08A3C18DF7160355FF8DBD97E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NC IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NCDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41E6FC9776662A296C95701337C8E8BD485A742A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NCDOC IS

vCodNC NUMBER(20);

PROCEDURE SETPARAMS(pCodNC IN NUMBER);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NCDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49B395D3827DFF6B8924F36F81199E9D247D6756</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NCLASEA IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) ;
PROCEDURE setJoinuri;
end PKG_LIST_BASE_NCLASEA; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>462C4437B3F0DA0192AA1454867B8667FE4FA864</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NCONT IS

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 
PROCEDURE setJoinuri;
end PKG_LIST_BASE_NCONT; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E87E023316EE0BE45C9D989C60CFD19F24892AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NCONTS is

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NCONTS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61DDC96E394F8A2DCBCF85D9491B694C71EF24A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NCONTT is

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NCONTT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NECCMDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D474E6B0682E5CD93E9BE6CA8622C33E2244ED93</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NECCMDCLI is

procedure setparams(aCodAtribut in number);
PROCEDURE setJoinuri;
function GetSume(aCodArticol in number, aCodComanda in number, Idx in number) return varchar2;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NECCMDCLI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B08FDA696B4AC97EB0E6614D7D0F70E94F2C12D7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NIR IS

  PROCEDURE SETPARAMS(pCodNir IN NUMBER, pTipDoc IN NUMBER, pVerso IN NUMBER DEFAULT 1, pCodNirStoc in number default 0);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NIR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NIRIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F772717F08DA3155167412D6E0602B0E8CAF5AD1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_niries IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  procedure setJoinuri;
end PKG_LIST_BASE_NIRIES;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NIRSERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7BC52F551A82AE565DEE817D14E706DB0274AE2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NIRSERII IS

  PROCEDURE SETPARAMS(pCodNirStoc IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_nirserii;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NMVSHISTORY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AC876E3FC01548D07A4DFA27C88CE68FA2824FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NMVSHISTORY is

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_NMVSHISTORY;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOMARTAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D14A10BF87CDC484C0009E2A93130BAFD1E157B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOMARTAMB IS

  PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_nomartamb;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOMGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACB86E4413ED3D909A6B4E40C24B275276B67F10</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOMGEST IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end PKG_LIST_BASE_NOMGEST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOMOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D34935D25EA0AD3D9431E6F5CF5A43B425392A07</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOMOPER IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
  PROCEDURE setJoinuri;

end pkg_list_base_nomoper; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOMPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>654F7FEE00EB7E79CAB7F803FBDA7349C34773A8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_nompart IS
  procedure setparams(aAllPart in number);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_NOMPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOMPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4B44CA53E23D6FA7831C9E673316217A72F1DD9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOMPERS IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 );
  PROCEDURE setJoinuri;
  PROCEDURE SETPARAMS(
    aDetaliere in number, 
    aAllPers in number, 
    aAllTeme in number, 
    aAllCursuri in number, 
    aPerDataPlanif in number, 
    aDataIni in varchar2, 
    aDataFin in varchar2, 
    pCodJob1 in number,
    aGDPR in number default 1
  );
  function isDetaliere return number;
  function isAllPers return number;
  function isAllTeme return number;
  function isAllCursuri return number;
  function DataIni return varchar2;
  function DataFin return varchar2;
  function isPerDataPlanif return number;
  
end pkg_list_base_nompers; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOM_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>718A763FEC7737605D51F9D0263A22A88A918825</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOM_UTILAJE is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_NOM_UTILAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NORMEAP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5EFB15767D90D5EBD8C1640A060749DCF13532A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_normeap is

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 

end pkg_list_base_normeap; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>673390E6456CBD438C6606C2EEF5D0BC69FF3064</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTACANTARCOM IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_NOTACANTARCOM; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51331F7A63538DC361FD69C3A4585E7441110497</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTACANTARIES IS

  PROCEDURE SETPARAMS(pCodDoc IN INTEGER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NOTACANTARIES; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77960A6B77E110E55EC42F5C0047AEDD5AC66DCB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTACANTARINTR is

  PROCEDURE SETPARAMS(pCodDoc IN INTEGER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NOTACANTARINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB000FF6251416D523277050851A89FE6B285F00</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_notacantartransf IS

  PROCEDURE SETPARAMS(pCodDoc IN INTEGER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_NOTACANTARTRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34446B051865C73CA4824A2A73A779704555E874</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTACONT IS

 PROCEDURE SETPARAMS(pTipDoc IN NUMBER);
 PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end pkg_list_base_notacont;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5ACFA2DBCB73B2C332EF8817DBFC47AF00E2579</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTECREDIT IS
  FUNCTION  GetDiscV (pCodContract IN NUMBER, pValM IN NUMBER, pValTot IN NUMBER) RETURN NUMBER;
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_NOTECREDIT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NOTECREDITT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45B60D7983AEC3A87622E1B956E4752A5F6EA5E4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NOTECREDITT is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSPARAMS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  procedure SetParams(vCodNoteCredit IN NUMBER);

end PKG_LIST_BASE_NOTECREDITT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F78E3B7E0E87E0F3841D7C7CB4DD95C5609A2BB9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NP IS

 PROCEDURE processlist(tmpTable IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end PKG_LIST_BASE_NP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_NP_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06E3FFD473CF41A8BE0DA41A8321EBB1E710CCE7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_NP_M IS

  PROCEDURE processlist(tmpTable IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_NP_M; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_OFEPROFORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>435AD2AF50A5CBC444A65528B36CA883A978660E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_OFEPROFORMA IS

  TYPE crs_cols IS REF CURSOR;

  PROCEDURE SETPARAMS(pCodDoc IN NUMBER);
  FUNCTION  get_cursor_coloane RETURN crs_cols;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_ofeproforma;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_OFERTADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24306B5D9A35BF2A3E26468C40BED26632A1C91A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_OFERTADOC IS

  function GetCodOferta return number;
  FUNCTION GETCODOFERTA1FURN(aCodObiect in number, aDataStart in Date, aDataEnd in Date, aCantMin in number) return number;
  PROCEDURE SETPARAMS(pCodOferta IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_OFERTADOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_OFERTERAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BF781ED60812745AF45E571F8B76EA16E48A8E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_OFERTERAC IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE ADD_LIST_PARAMS;
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_OFERTERAC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8D0C27A3EEBC8DEF22ADF96CECE1E2F8D9ED91C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_oportunitati IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE UMPLETMPLISTA;

END PKG_LIST_BASE_OPORTUNITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_ORDONANTARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>096BC0E83FC3E299F7D61DD923B6833FC4FC671D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_ORDONANTARI is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_ORDONANTARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0490B0DE6D8CFF3F87B852D64E632FD7A880BA8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTO IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_PARCAUTO; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOANV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B45D0006035CB4A153961E18310BF5E1C1BD5774</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTOANV IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_PARCAUTOANV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>435673AED95E41971E2987E330EE3E25025CAB91</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTOAUT IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_PARCAUTOAUT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOCARB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E3386814BC0A7A91AB329E67640370DD440019B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTOCARB IS

PROCEDURE SETPARAMS(
  pAnLunaIni IN NUMBER DEFAULT NULL,
  pAnLunaFin IN NUMBER DEFAULT NULL,
  pDistZile  IN NUMBER DEFAULT 0,
  pConsZile  IN NUMBER DEFAULT 0,
  v_CodJob1  IN NUMBER DEFAULT 0);
PROCEDURE PROCESSLIST(
  tmpName   IN VARCHAR2,
  aLISTID   IN NUMBER DEFAULT 0,
  aLISTVER  IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_PARCAUTOCARB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>825BB4C43CDE0E2B1D24D935D9A1204A17D0FE0C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTOCHELT IS

PROCEDURE SETPARAMS(pAnLunaIni IN NUMBER DEFAULT NULL,
                    pAnLunaFin IN NUMBER DEFAULT NULL,
                    pCC0       IN NUMBER DEFAULT 0,
                    V_CODJOB1  IN NUMBER,
                    pExclCont  IN NUMBER DEFAULT 0);

PROCEDURE PROCESSLIST(    tmpName   IN VARCHAR2,
                          aLISTID   IN NUMBER DEFAULT 0,
                          aLISTVER  IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

FUNCTION  xCodCentru(     pCodCont  IN NUMBER,
                          pAnLuna   IN NUMBER)
          RETURN NUMBER;

FUNCTION  ContCodCentru(  pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pCodCont1 IN NUMBER,
                          pCodCont2 IN NUMBER DEFAULT NULL)
          RETURN NUMBER;

FUNCTION  IContCodCentru( pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pICont    IN NUMBER,
                          pCodPart  IN NUMBER,
                          pSemnif   IN NUMBER)
          RETURN NUMBER;

END PKG_LIST_BASE_PARCAUTOCHELT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOINTERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9718E18619E1E6057B287E40E389C82282B93C10</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PARCAUTOINTERV IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_PARCAUTOINTERV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PENALITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05F01FE8AF4DEEED6D7D19B9D0A96F4CEF0EC3F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PENALITATI is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PENALITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9240868E6979A22B4983F29C43FC7F88453BE56</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_perscontact IS

 PROCEDURE processlist (tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

END pkg_list_base_perscontact; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PERSLEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67239C166FE48CF7B1602B9B93E8A7DAA4EFFBC4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PERSLEG IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID in number default 0, aLISTVER in number default 0);
procedure setJoinuri;
end PKG_LIST_BASE_PERSLEG; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>355A4722F7C1092FAA2EC30D4E19498889037246</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PF IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_pf;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PFGANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DDCADDCD64E9C69A11E44A35FD3FCFD496CF132</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PFGANTT IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_pfGANTT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PFLOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7179CBFA171F7C6B81A39114BBB623DC9012AAFD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PFLOCM IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_pflocm;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PFMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1CC4EF6FFAFEF59B2CF51F284B134681FE5C455</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PFMAN IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END pkg_list_base_pfman;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PFMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CCBCB9157F054671F4EB41D296A4A9691EE8EFC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PFMAT IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_pfmat;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PFSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F61C51D3E8A3EA1B0D178C68B8199EE6F8694D94</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PFSDV IS

  PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_pfsdv;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PF_LOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B79FE0A2CEA175A5CC65170464B83AB3DDB50AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PF_LOCM IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_PF_LOCM; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PF_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B801450A3065FA03ACD563794B5825994B71BC8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PF_LUNA is

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_PF_LUNA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PLANACHIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88CFF31EDA2B7D3B1656121EC1F1294E720BDA4D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PLANACHIZ IS

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_PLANACHIZ;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77E8E3540987EF598906EA3936A030C142CE08C0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PLANIFCMD is

PROCEDURE setParams(aAn IN number, aSet in number, aAnG in number, aSetG in number);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
procedure PROCESSPARAMS(tmpName IN VARCHAR2);

end PKG_LIST_BASE_PLANIFCMD;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFCMD_CENTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BB1D12002766B76C3488392931627056F765995</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PLANIFCMD_CENTR is

PROCEDURE setParams(aAn IN number, aSet in number);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
procedure PROCESSPARAMS(tmpName IN VARCHAR2);

end PKG_LIST_BASE_PLANIFCMD_CENTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>107D92966B26D17000BF44FC5EF67F67AA2F10FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PLANIFPROD IS

  PROCEDURE setParams(aSetimana IN number, aAn in number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PLANIFPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32E9CC7D6799B33199CC54210E6051E094139ADC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PLANIFSTOC IS

  procedure SetParams(aDataStart in varchar2, aDataFin in varchar2, AllGestStoc in number, AllGestCmd in number, NoTermen in number, v_codjob1 in number);
  function GETPARBYCODEXTERN(aCodExtern in varchar2, aCodObiect in number) return number;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_PLANIFSTOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D0376FDB089EA95D475D8F175A8B4D916D53842</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PMP IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_PMP;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PONTAJESA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DE6373354F1E914A1E7BA4451CA5D30F6B3AAA3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PontajeSA IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_PontajeSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_POSTCALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AB0AF47C8C5E114099FE96A4FD3411A7839A5A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_POSTCALCUL is

  function GetCodPC return number;
  PROCEDURE SETPARAMS(pCodPC IN NUMBER DEFAULT NULL);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_postcalcul;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>757FF1BCC0A4C438F43CEE5E2250521F4D49797C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PRODCOMP IS

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSPARAMS;
  PROCEDURE PROCESSPARAMSRET;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  procedure SetParams(v_CodProdComp IN NUMBER, v_CodComanda1 in number);
  function  GetCod return number;

end pkg_list_base_prodcomp;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PRODESTPRJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8938F73568D5382A9A665884C91B83AF41A4FDC0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PRODESTPRJ is

PROCEDURE setJoinuri;
PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 
procedure test;
procedure testEstimeaza;

end PKG_LIST_BASE_PRODESTPRJ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PRODETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA6261D1C8C0CC9B3D613E4C4C00E395A938CA7C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PRODETICHETE is

procedure SETPARAMS(aCoduri in varchar2);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PRODETICHETE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PRODNETMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B97A8F2B476BEFF09D79769F552631DDA393C3BF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_prodnetman is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_prodnetman;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PRODNETMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E2F020976728AF22F17895497595EBC0C371BD1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_prodnetmat is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_prodnetmat;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>109B1B5CF57AD2D15F04C15237CACAFFE1B77709</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROFIT IS

  function GetValNC(aCodIntr1 IN NUMBER, aTip IN NUMBER) return number;
  function GETTERIES(vCodIes IN NUMBER) RETURN NUMBER;
  function GETTERIN(vCodIntr IN NUMBER) RETURN NUMBER;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_profit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROGLUNFAB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1A0125CDF5A49C4F6CCFFA4F39D918EB8973C34</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROGLUNFAB IS

  PROCEDURE SETPARAMS(
    pCentralizare IN NUMBER DEFAULT 0,
    pNeoperate    IN NUMBER DEFAULT 0,
    pZiuaIni      IN VARCHAR2 DEFAULT NULL,
    pZiuaFin      IN VARCHAR2 DEFAULT NULL,
    pLunar        IN NUMBER DEFAULT 0,
    V_CODJOB1     IN NUMBER DEFAULT 0
  );
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_PROGLUNFAB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>844DE4AED85501D0D9F0998F7924DD41918671E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROIECT IS

  PROCEDURE setParams(aCodProiect IN number, aCodComanda1 in number default 0);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_proiect;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROIECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B3DBFB37BDE45EABFFF773FB866E11F739325FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROIECTE IS

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PROIECTE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>910F29237AF832894F4770D0A3AECDB1CD1EF309</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROMO IS

  PROCEDURE SETPARAMS(  pDataIni  IN VARCHAR2,
                        pDataFin  IN VARCHAR2,
                        pTotiPart IN NUMBER DEFAULT 1,
                        pGrupPart IN NUMBER DEFAULT 1,
                        V_CODJOB1 IN NUMBER DEFAULT 0
                     );
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PROMO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_PROMODOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02E93D5D61C22F426F853E6136BF5AB2FB55FBD9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_PROMODOC IS

  PROCEDURE SETPARAMS(pCodPROMO IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_PROMODOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DASHMAN_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74065C7D0EEEDCEB9577F3C877180159635D00BD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_DASHMAN_DOC IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAC_DASHMAN_DOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DASHOP_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>031757B472E071C263150AFD97D63EA47A1DCC35</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_DASHOP_DOC IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAC_DASHOP_DOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4772006A6F7111283BF16F3213E08166C577A7B0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_DetInfo IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAC_DetInfo; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3959BA4026F6528FB92D4B250D2F354F968C5B5B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_DetInfoG IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAC_DetInfoG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFOLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E84D1314113E07FF4E00BCD478B7ABB914486FB5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_DetInfoLG is

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAC_DetInfoLG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINILIBERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76188E40A269E5F17178A019AAB56D3053AB2E0E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_MASINILIBERE IS

PROCEDURE SETPARAMS( Zi1 DATE, Zi2 DATE );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_RAC_MASINILIBERE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINIOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>984760B1CE53C7A1425F4F5581F02835225D0CDF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_MASINIOC IS

PROCEDURE SETPARAMS( Zi1 DATE, Zi2 DATE );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_RAC_MASINIOC;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINIOC_CE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B3DDE1CC4E332192EBE5BF45272799CC0FF9E0E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAC_MASINIOC_CE IS

PROCEDURE SETPARAMS( Zi1 DATE, Zi2 DATE );
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_RAC_MASINIOC_CE;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPCONSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AA0A6C97CA236D8672E3A5F92EDB761FDFC3EEE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPCONSPROD is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  procedure SetParams(aAnLuna in number default 0, aAllArt in number default 0, aCodComanda in number default 0);
  procedure UmplePredariSiConsumuri;
  procedure CreazaStructTeoretica;
  procedure test;

end PKG_LIST_BASE_RAPCONSPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPCONSUMPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D92D3A2702B92D825648D9A8D7E0DB815A1A7047</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPCONSUMPROD is

  PROCEDURE SETPARAMS(aTouch in number default 0);
  PROCEDURE PROCESSPARAMS;
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_RAPCONSUMPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPCREDITCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9BF60A736047705F96BC2A1CE51183A4C83E842</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPCREDITCLI IS

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) ;
PROCEDURE setJoinuri;
end pkg_list_base_rapcreditcli; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPGESTTVAVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D556438ED85AEFC01A2AC135349A9BC851073F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPGESTTVAVAL IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_RAPGESTTVAVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPINCPLATIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B1310B96651208D798B20BDAD563F0208CB09DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPINCPLATIART IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  function GetCodContract(aCodPart in number, aDataDoc in Date) return number;

end pkg_list_base_rapincplatiart;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTAGENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4CE661A42E88E803751E042680097A9813B828E6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTAGENTI IS

  PROCEDURE SETPARAMS  (pTipData IN NUMBER, pInceput IN VARCHAR2, pSfarsit IN VARCHAR2, v_codjob1 in number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_RAPORTAGENTI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTCUMPARARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A9FC6802488DF68E3E566AF2B13664C16B99A3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTCUMPARARI IS

  TYPE crs_cols IS REF CURSOR;

  PROCEDURE SETPARAMS  (
    pTipData   IN NUMBER, 
    pInceput   IN VARCHAR2, 
    pSfarsit   IN VARCHAR2, 
    pTipTarget IN NUMBER, 
    pValuta    IN NUMBER, 
    pCatPret   IN NUMBER DEFAULT 0, 
    pAllPart   IN NUMBER DEFAULT 0, 
    V_CODJOB1  IN NUMBER
  );
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_raportcumparari;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTCVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF10CDA37A16C41148FD289C5BBE5B9A5749BD32</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTGESTCVAL IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_RAPORTGESTCVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTPMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1E27F4ED29B9AA56DC65D5CA1C009B4E1D13708</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTGESTPMP IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_RAPORTGESTPMP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0676555184DC93395BFD1243A931B3CB437D615F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTGESTVAL IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_RAPORTGESTVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>141D9D1A1CDCB0D44870F596D4C70DEB56A4C74C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTP IS

  PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_RAPORTP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>480BB44CABD667E4A8B841951D2099FA03A48894</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTPDOC IS

  PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_RAPORTPDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTP_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0871F2EA927B49BB266A2AF87891DE84629F7359</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTP_M IS

  PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL);
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAPORTP_M; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTSCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7447014135FFF81C94C5098A2B4CD06FAC82B319</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPORTSCHIMB IS

  PROCEDURE setParams(aDataIni IN varchar2, aDataFin in varchar2, v_codjob1 in number);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAPORTSCHIMB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTVANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4E52DDDF4D828901E97DA754D014642F3B96D5C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_raportvanzari IS

  TYPE crs_cols IS REF CURSOR;

  PROCEDURE SETPARAMS  (pTipData IN NUMBER, pInceput IN VARCHAR2, pSfarsit IN VARCHAR2, pTipTarget IN NUMBER, pValuta IN NUMBER, pCatPret IN NUMBER DEFAULT 0, pAllPart IN NUMBER DEFAULT 0, V_CODJOB1 IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RAPORTVANZARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RAPSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>80E5F204E2668F5EE7BF2826ABCB22C6E258F7AB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RAPSTOC IS

  PROCEDURE SETPARAMS(pDataIni      IN VARCHAR2 DEFAULT NULL,
                      pDataFin      IN VARCHAR2 DEFAULT NULL,
                      pPromoSeparat IN NUMBER   DEFAULT 0,
                      pToateGest    IN NUMBER   DEFAULT 1,
                      pToateIOArt   IN NUMBER   DEFAULT 1,
                      v_codjob1     IN NUMBER   DEFAULT 0
                     );
  PROCEDURE BagaDinamicCols;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;

end PKG_LIST_BASE_RAPSTOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51A473AC5BC322C3BE80933507AACCF4F9C7AA67</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_realgest IS

  FUNCTION GetPlan        RETURN NUMBER;
  FUNCTION GetAnLunaIni   RETURN NUMBER;
  FUNCTION GetAnLunaFin   RETURN NUMBER;
  FUNCTION GetFaraMiscari RETURN BOOLEAN;
  FUNCTION GetCuConturi   RETURN BOOLEAN;
  FUNCTION GetDetLunara   RETURN BOOLEAN;
  FUNCTION GetDetCCost    RETURN BOOLEAN;
  FUNCTION GetSubunit     RETURN NUMBER;
  FUNCTION GetAllCC       RETURN BOOLEAN;
  function GetCuDoc       return number;
  FUNCTION GetCCInactive  RETURN BOOLEAN;
  FUNCTION GetExtra       RETURN BOOLEAN;
  PROCEDURE ver_col_analiza (tmpName IN VARCHAR2, nrmax IN NUMBER);
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE SetParams(
    vAnLunaIni   IN NUMBER,
    vAnLunaFin   IN NUMBER,
    vPlan        IN NUMBER,
    vFaraMiscari IN NUMBER DEFAULT 0,
    vCuConturi   IN NUMBER DEFAULT 0,
    vDetLunara   IN NUMBER DEFAULT 0,
    vDetCCost    IN NUMBER DEFAULT 0,
    vPeFirma     IN NUMBER DEFAULT 1,
    pCodJob1     IN NUMBER DEFAULT 0,
    pAllCC       IN NUMBER DEFAULT 0,
    pCCInactive  IN NUMBER DEFAULT 0,
    pDoc         IN NUMBER DEFAULT 0,
    pExtra       IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_REALGEST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>353531F5B4A2917B27A34EEBC404A0684CABB72C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REALGEST2 IS
  
  PROCEDURE BAGA_DINAMIC_COLS_LUN;
  PROCEDURE baga_dinamic_cols;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END pkg_list_base_realgest2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C0C6AAE533C7B1F32D9C886A8A5ABBA7794E131</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_realgest3 IS

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END pkg_list_base_realgest3; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RECEPTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08C533DE9F681E9F94972146140C06D773CBB5A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RECEPTII IS

--g_anLunaCur NUMBER (10);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;
end PKG_LIST_BASE_RECEPTII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E71A9E21EB5F865C0C8780F94E0C4558CAFBAFAE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RECLAMATII IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_RECLAMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGANALITIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF6B587C5BBE698BA75394E0A9DD6750F69507F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGANALITIC is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_REGANALITIC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGCASABANCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA2F169EDE5F721A64F16BFD4AD15E34D3FCC852</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGCASABANCA IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;


end PKG_LIST_BASE_REGCASABANCA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGCONTABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>029F1C4BF220E43A6FB832EA011D737FEC33B00B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGCONTABIL IS

  
 PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

 
 PROCEDURE setJoinuri ;

end PKG_LIST_BASE_REGCONTABIL; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGEVFISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAC984F96BEA2D0B194A223C652F3EFCBFC8F204</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGEVFISC is

  PROCEDURE SETPARAMS(pCodDProfit IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE ADD_LIST_PARAMS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_REGEVFISC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGINOUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F08917AF95D0E9191321C2E54BB91D66C9BAC081</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGINOUT IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_REGINOUT;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A4E2D3631AA0AE7F79EB1D944B2BB0156D3659B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGJURNAL IS
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setParams (
    vPlan       IN NUMBER,
    vLunaIni    IN NUMBER,
    vLunaFin    IN NUMBER,
    vSubCurenta IN NUMBER DEFAULT 0,
    v_Index     IN NUMBER DEFAULT 0,
    v_codjob1   IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION  Plan       RETURN NUMBER;
  FUNCTION  LunaIni    RETURN NUMBER;
  FUNCTION  LunaFin    RETURN NUMBER;
  FUNCTION  SubCurenta RETURN NUMBER;
  FUNCTION  isIndex    RETURN BOOLEAN;

end PKG_LIST_BASE_REGJURNAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78EA11F3DE12A9DC1F24CF69B3094A264040BF04</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGMF is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri; 

end PKG_LIST_BASE_REGMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGREEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E865C3DDC8C75FF07D2F8E334B2C3BB8BC460B70</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGREEV is

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;  

end PKG_LIST_BASE_REGREEV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGULARIZPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F85A481AFB23E82AFB41ACBCF1E1244DC4918630</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_regularizpart IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_REGULARIZPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REGULARIZTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01EFE2F6A18FFAB61B1ED95A8E31E3097C7D5135</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REGULARIZTREZ IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_REGULARIZTREZ; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RESTLISTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C05A14D4B365171E6F2CF1A0639F41D1B3A27416</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RESTLISTGEST is
  CODGEST     NUMBER(20, 0);
  CODRESTCMD  NUMBER(20, 0);
  ID          NUMBER(20, 0);
  VER         NUMBER(20, 0);
  
  
PROCEDURE SETPARAMS(aCODGEST IN NUMBER, aCODRESTCMD IN NUMBER, aID IN NUMBER, aVER IN NUMBER );
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE PROCESSLISTCFG(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE PROCESSLISTDIF(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_RESTLISTGEST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RESTLISTNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>969B1DABFECC2BC71F8124C23CAF413EDCAA2D97</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RESTLISTNP is
  CODNP  NUMBER(20, 0);
  ID          NUMBER(20, 0);
  VER         NUMBER(20, 0);
  
PROCEDURE setJoinuri;  
PROCEDURE SETPARAMS(aCODRESTNP IN NUMBER, aID IN NUMBER, aVER IN NUMBER );
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_RESTLISTNP; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RESTSITLISTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2022E49CE2419D97D024BA057377C596C0C5BDC3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RESTSITLISTGEST IS

  DATASTART  VARCHAR2(1000) := &apos;&apos;;
  DATAEND    VARCHAR2(1000) := &apos;&apos;;
  ID         NUMBER(20, 0);
  VER        NUMBER(20, 0);
  CODRESTAURANT    NUMBER(20, 0) := 0;
  
PROCEDURE SETPARAMS(
	aCODRESTAURANT IN NUMBER, 
	aDATASTART IN VARCHAR2, 
	aDATAEND IN VARCHAR2, 
	aID IN NUMBER, 
	aVER IN NUMBER ,
	pCodJob1     IN NUMBER  DEFAULT 0 );
	
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_RESTSITLISTGEST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REZDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD9B522335CB74B3725F3CBCABF23A2103178D68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REZDOC is

  PROCEDURE SETPARAMS(pCodComanda IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_rezdoc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_REZMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98E0A0A55B11EAC645100E6EAB8E461A11F94BF8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_REZMF IS

vCod NUMBER(20);

PROCEDURE SETPARAMS(pCod IN NUMBER);
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_REZMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_RPTVANZUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B91B86FA5355BFB64AF68703255F47DA7A502F98</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_RPTVANZUM IS
  PROCEDURE SETPARAMS(aCodUM in number);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_RPTVANZUM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SCADCHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45418B422B073B8D0AA56526AAB5C646FE3D7C45</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SCADCHELTAVANS IS

PROCEDURE BAGA_DINAMIC_COLS;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2 ,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_SCADCHELTAVANS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C57FE87B154FE0621575AB16C576E4C0BB4D058</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SCADENTARCL IS

  FUNCTION  CalcAdaosDoc( pCodDoc IN NUMBER,
                          pRest   IN NUMBER)
            RETURN NUMBER;

  PROCEDURE UMPLE_tmp_lst_scad_stins (aListID IN NUMBER, pFiltruLuna IN VARCHAR2);
  PROCEDURE UMPLE_tmp_lst_scad_sertar(aListID IN NUMBER);
  PROCEDURE UMPLETMP(aLISTID IN NUMBER DEFAULT 0);

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE SetJoinuri;

  FUNCTION GetJoinFiltru RETURN CLOB;

end pkg_list_base_scadentarCL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2281ABD00E41523510FCC80A2DCD0C17D556F9FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SCADENTARF IS

  FUNCTION  CalcAdaosDoc( pCodDoc  IN NUMBER,
                          pRest    IN NUMBER)
            RETURN NUMBER;

  PROCEDURE UMPLETMP(aLISTID IN NUMBER DEFAULT 0);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE SetJoinuri;

END PKG_LIST_BASE_SCADENTARF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARLEASING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E06B85CABB16EAD7B0C8CDBE9B592AAA37542F30</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SCADENTARLEASING IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_SCADENTARLEASING; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SEDIIPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA2E32EFE15290560BD2367C567057E115DB19D4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SEDIIPART IS

  PROCEDURE processlist (tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end pkg_list_base_sediipart; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SELANLUNAREF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A675E9997870804C6B84281EC39E95D5340A1CDA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SELANLUNAREF IS

  PROCEDURE SETPARAMS( pLuna INTEGER, pAn INTEGER, pSubunit INTEGER);
  FUNCTION An   RETURN NUMBER;
  FUNCTION Luna RETURN NUMBER;
  FUNCTION Sub  RETURN NUMBER;

end PKG_LIST_BASE_SELANLUNAREF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27D353134451DA5C6983CA4C353C08AB53D9CF30</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SERII IS
  

  
  PROCEDURE SETPARAMS(aConditie IN VARCHAR2, aTipSql IN NUMBER);
  FUNCTION  FILTRU_LIVR(pTipDoc       IN NUMBER,
                        pCodDoc       IN NUMBER,
                        pLinieDoc     IN NUMBER,
                        pTipSerie     IN NUMBER,
                        pUmSec        IN NUMBER DEFAULT NULL,
                        pCodIoart     IN NUMBER DEFAULT NULL,
                        pCodGest      IN NUMBER DEFAULT NULL,
                        pCodLocatie   IN NUMBER DEFAULT NULL,
                        pCodGestProd  IN NUMBER DEFAULT NULL,
                        pFurn         IN NUMBER DEFAULT NULL,
                        pD1           IN NUMBER DEFAULT NULL,
                        PD2           IN NUMBER DEFAULT NULL,
                        pD3           IN NUMBER DEFAULT NULL,
                        pDataAchiz    IN VARCHAR2 DEFAULT NULL,
                        pSign         IN NUMBER DEFAULT NULL,
                        pCodGestD     IN NUMBER DEFAULT NULL,
                        pCodLocatieD  IN NUMBER DEFAULT NULL)
  RETURN VARCHAR2;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SETJOINURI;


END PKG_LIST_BASE_SERII; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED11448B066672F2AABD50985A1622AD0E5B0106</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_sertar IS

PROCEDURE SETPARAMS(
  pOriceData  IN NUMBER   DEFAULT 1,
  pDataIni    IN VARCHAR2 DEFAULT NULL,
  pDataFin    IN VARCHAR2 DEFAULT NULL,
  pDepus0     IN NUMBER   DEFAULT 1,
  pDefalcat   IN NUMBER   DEFAULT 1,
  pCodJob1    IN NUMBER   DEFAULT 0 );

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

END PKG_LIST_BASE_SERTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SIM406</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>831642D7D1EAAF139F980281042442EC959EA36C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SIM406 IS

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_SIM406;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SIMULAMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE21D961CBA56584E4C29A95B1BF51BD1AA07A87</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SIMULAMO IS

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_SIMULAMO;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SINTTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A95FE6E72E9E69D1B0ED8559B0B71C10869051FB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SINTTREZ IS
  PROCEDURE BAGA_DINAMIC_COLS;
  PROCEDURE TMPPRepare(aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SINTTREZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SINTTREZDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A181AF0959B27D0D196EF6419B0ED0463AF824F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SINTTREZDET IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SINTTREZDET;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITACCRUALLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA96E7D0DDA90FBD3E30D31A56EAF223E548B16C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITACCRUALLS IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SITACCRUALLS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITARTFIRMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13A111BD46563BAF83424338ACF40AB7E38C1DB7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITARTFIRMA IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SITARTFIRMA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITBONRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D1E38B9BA96C4CCDBD8E526A6150CD4A081E60D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITBONRETAIL is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITBONRETAIL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITBONRETAILSINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B54F56C959A0790317704065A8D63D807D8A6F32</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITBONRETAILSINT is

  PROCEDURE BAGA_DINAMIC_COLS;
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITBONRETAILSINT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A243B6D3EAD24385FF0203B2704CC6B49F7571B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITCONSUM IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_SITCONSUM; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUMPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FCD1718413865B9A0C7D2FCCD16AD2BA067C076</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITCONSUMPROD IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_sitconsumprod;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUM_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0102F38FAAA9A60B96CB448F98C1483CC5827FA0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITCONSUM_M IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_SITCONSUM_M; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITDATORII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E1506239CFF5A4E5C173DACAE71B6815B6F94A8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITDATORII IS

  PROCEDURE setParams (pCodPart IN NUMBER, pCodAgenda IN NUMBER, pCodMoneda IN NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_SITDATORII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEB321D160E931B14FFD764A0983698A5AF4693A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITFIN IS
  
  procedure SetAllSubunit; 
  PROCEDURE setParams (v_Tabla IN VARCHAR2,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      );
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  procedure SetCod(v_CodSitFin IN NUMBER);
  function GetCod return number;
  function INCHID711CU121 return number;
  function INCHID712CU121 return number;
  function INCHID722CU121 return number;
  function INCHID765CU473 return number;
  function INCHID665CU473 return number;
  function INCHID665FARA473 return number;
  
end pkg_list_base_sitfin; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EE2767BB8C0735F5D5075DD966605A30C33DAAD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITIMOB IS

  FUNCTION  GetCodLivr1Vanz (pStare NUMBER, pCodnirstoc NUMBER, pAn NUMBER, pLuna NUMBER) RETURN NUMBER;
  PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE SETPARAMS (
    pLunaAnIni   IN INTEGER DEFAULT 0,
    pLunaAnFin   IN INTEGER DEFAULT 0,
    pOldMF       IN INTEGER DEFAULT 0,
    pAllGest     IN INTEGER,
    pAllIOArt    IN INTEGER,
    pAllMF       IN INTEGER,
    pCodJob1     IN NUMBER
  );
  function AnLunaIni return number;
  function AnLunaFin return number;

END PKG_LIST_BASE_SITIMOB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITINIESLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1924E789D8E57EFB7FF50EA97B095A9F87A8117</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITINIESLUNA IS
  PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_SITINIESLUNA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITONINV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>351CA47CDB45D8FA9E52A99B0D3D74E4A4A1E5D8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITONINV IS

  PROCEDURE UmpleTmp(pTotAnul BOOLEAN DEFAULT TRUE);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SITONINV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITPEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0653C7EDE1BF51671846D8571ED303FD8F3B00F6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITPEN is

PROCEDURE setParams(v_Tabla IN VARCHAR2,V_CODJOB1 IN NUMBER  DEFAULT 0);
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITPEN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITPUNCTCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0ABFAB05ECFA54C9B12643935894DE19483D1215</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITPUNCTCLI is

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_SITPUNCTCLI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITTRANSP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>666D4FF561CF82AFA72FE69E69D1B1548803BF78</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITTRANSP is

PROCEDURE SetJoinuri;
PROCEDURE ProcessList(tmpName IN VARCHAR2,aListID IN NUMBER DEFAULT 0,aListVer IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITTRANSP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>660F49D055B21EEACFB642B3429980D594DA5D84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITUTILAJE IS

 PROCEDURE setParams (p_ToateU IN NUMBER DEFAULT 1);
 PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
end PKG_LIST_BASE_SITUTILAJE; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITVANZRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B800FEED57C78E37FAE85BE571355F41779975F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITVANZRETAIL is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITVANZRETAIL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SITVANZRETSINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F9B3A66F5210C02085BBE0F9BD9615AB4ED2CE1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SITVANZRETSINT is

  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SITVANZRETSINT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>951BD203EA98FE680296F7BA5995FCF14B1A9207</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SOLDPART IS
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) ;
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SOLDPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SOLDPARTINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F28DEBDCAAE554F53D2E8BCCD94772B76686CB11</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_soldpartini IS
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_SOLDPARTINI;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>204DF1462E8CE97A1F93FE57569F1D7A9F344FCA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOC IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE setJoinuri;
  FUNCTION GetFurn (pCodObiect NUMBER, pCodNirstoc NUMBER, pFurn NUMBER) RETURN NUMBER;
END PKG_LIST_BASE_STOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCCONTROL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE41A19612F0841C9BEF432FC5572650CE2FD080</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCCONTROL IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_STOCCONTROL;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCCRITIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F68301FF8D13E8A88B695C787BDE1B24CE0BC8F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCCRITIC IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
end PKG_LIST_BASE_STOCCRITIC; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB157127F797E9CDB8B273408A515EF34CA55AC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCEP IS
  
  function GetDataIni return varchar2;
  function GetDataFin return varchar2;
  PROCEDURE SETPARAMS(
    pDataIni    IN VARCHAR2,
    pDataFin    IN VARCHAR2,
    pTipMedie   IN INTEGER,
    pIndCrest   IN NUMBER,
    pToataFirma IN NUMBER DEFAULT 1,
    pToateGest  IN NUMBER DEFAULT 1,
    pInclEpuiz  IN NUMBER DEFAULT 0,
    pUltAchiz   IN NUMBER DEFAULT 0,
    pToateArt   IN NUMBER DEFAULT 0,
    pCodJob1    IN NUMBER   DEFAULT 0,
    pToateClaseArt IN NUMBER DEFAULT 1,
    pToateArticole IN NUMBER DEFAULT 1  
  );
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  
end PKG_LIST_BASE_STOCEP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCEXP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>854DC01E3DA1FD40F2A03C4DCDADB88F4DAFBD2B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCEXP IS
  FUNCTION GETROOTCODNIR(pCODNIRSTOC IN NUMBER) RETURN NUMBER; 
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
end PKG_LIST_BASE_STOCEXP; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCFARAMISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10FD9AE7BFE089BD04B8DE888A211893EE12BF91</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCFARAMISC IS
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
end PKG_LIST_BASE_STOCFARAMISC; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>375C20E5FF2527E932805FD718D7CDDB8D4ECB1C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_stocofe IS

PROCEDURE SETPARAMS( pAllArt     IN NUMBER   DEFAULT 1,
                     pServicii   IN NUMBER   DEFAULT 1,
                     pTipPret    IN INTEGER  DEFAULT NULL,
                     pTipCalcul  IN INTEGER  DEFAULT NULL,
                     pCodMoneda  IN INTEGER  DEFAULT NULL,
                     pAllGest    IN NUMBER   DEFAULT 1,
                     pAllIoart   IN NUMBER   DEFAULT 1,
                     pAllAdaos   IN NUMBER   DEFAULT 0,
                     pCodjob1    IN NUMBER   DEFAULT 0);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_StocOfe;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCPROGNOZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AE843472FDC21F1BCC7013C37F70A32AA49E108</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_stocprognoza IS
  PROCEDURE SETPARAMS( pToateArt       IN NUMBER DEFAULT 1,
                       pComSubunit     IN NUMBER DEFAULT 1,
                       pConsum         IN NUMBER DEFAULT 1,
                       pToateGestStoc  IN NUMBER DEFAULT 1,
                       pExclNeconforme IN NUMBER DEFAULT 0);
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_STOCPROGNOZA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCREZERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A36CBEF36517A40D3970C2BA7F2E660BD2734E25</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCREZERV IS

  PROCEDURE SETPARAMS( pToateArt IN NUMBER DEFAULT 1);
  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_STOCREZERV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCROTATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE755B55D71F7B6BD7A0E869842EA8F49E9E16DC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCROTATIE IS

PROCEDURE SETPARAMS( pDataIni  IN VARCHAR2,
                     pDataFin  IN VARCHAR2,
                     pToateArt IN NUMBER DEFAULT 1,
                     pCodJob1  IN NUMBER DEFAULT 0);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_STOCROTATIE; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5D86E39580A349FD672E36C8F3B74B62D59D238</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCVAL IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_STOCVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCVECHIME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEABE3EDA4784E69472E37EF543666B7ED668764</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCVECHIME IS

 PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_STOCVECHIME;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_STOCVITROT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C505D39C9A5ABF14F7CD767DF4F1E488586B0DE8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_STOCVITROT IS

PROCEDURE SETPARAMS(
  pDataIni    IN VARCHAR2,
  pDataFin    IN VARCHAR2,
  pAnual      IN NUMBER DEFAULT 1,
  pAvizeSub   IN NUMBER DEFAULT 1,
  pTransfVal  IN NUMBER DEFAULT 1,
  pIesConsum  IN NUMBER DEFAULT 1,
  pToateArt   IN NUMBER DEFAULT 1,
  pToateGest  IN NUMBER DEFAULT 1,
  pToateIOArt IN NUMBER DEFAULT 1,
  pCentr      IN NUMBER DEFAULT 1,
  V_CODJOB1   IN NUMBER DEFAULT 0
);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_STOCVITROT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_SYNCPRETRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>536378E7E3D7954B1247ADBD986E3C7C95D8375F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_SYNCPRETRETAIL is

  PROCEDURE SetParams(pCodCatPret IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_SYNCPRETRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TASKURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>159EF6FED2A65911ADDB5386D847E176B4E667EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TASKURI IS

PROCEDURE SETPARAMS(
  includSterse in INTEGER  default 0,
  areInterval  in INTEGER  default 0,
  dataIni      in varchar2 default &apos;&apos;,
  datafin      in varchar2 default &apos;&apos;,
  includLog    in INTEGER  default 0,
  V_CODJOB1    IN NUMBER   DEFAULT 0
);
PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE SetJoinuri;

end pkg_list_base_taskuri;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TEHPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CCD1304A72805756D63517F08CC1EB271555A46</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TEHPROD IS

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0); 
  PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Sursa IN NUMBER);
  procedure PregatesteStructura;
  procedure BagaMateriale(aObservatii in varchar2, aCodObiect in number, aCant in number, aCodProdComp in number, aNivel in number, aCodMoneda in number, aCodOriginal in number);
  procedure make_mat;
    
end pkg_list_base_tehprod; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TEME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB48274DE56A37E058E133AA9185D56DA8A9C60F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TEME is

  PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_TEME;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TERMEDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23DD282DEFEFF03D4200403D08B8947FB988CBC7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TERMEDCLI IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

end pkg_list_base_termedcli; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TERMEDFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61675BA859E2B6BB5F64E16430FB2552AE27BD27</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TERMEDFURN IS

  PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  
end pkg_list_base_termedfurn; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E91CA5DBFBFE11CF6B2E3DC910302DA353203B7E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TOPART IS

PROCEDURE setParams ( pDataINI  IN VARCHAR2,
                      pDataFIN  IN VARCHAR2,
                      pPeFurn   IN NUMBER,
                      pSortType IN NUMBER,
                      pDocType  IN NUMBER,
                      V_CODJOB1 IN NUMBER  DEFAULT 0,
                      pCodAtribut IN NUMBER DEFAULT 0
                     );
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_TOPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TOPCLIANI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC305DD78A4695BE6641A0E341BEC448DA4B0AD8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TOPCLIANI IS

  function TotiPart return boolean;
  PROCEDURE SETPARAMS(pLunaStart IN NUMBER DEFAULT 1,
                    pLunaFin   IN NUMBER DEFAULT 12,
                    pTotiPart  IN NUMBER   DEFAULT 1,
                    V_CODJOB1 IN NUMBER  DEFAULT 0 
                   );
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION LunaIni return number;
  FUNCTION LunaFin return number;

end pkg_list_base_topcliani;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TOPCLIENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F740AABC386CDB2495CF919EAD7A6453FCD492E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TOPCLIENTI IS

  PROCEDURE setParams (
    pDataINI  IN VARCHAR2,
    pDataFIN  IN VARCHAR2,
    pAllIOArt IN NUMBER DEFAULT 1,
    pAllCls   IN NUMBER DEFAULT 1,
    pAvize    IN NUMBER DEFAULT 1,
    pAduCust  IN NUMBER DEFAULT 0,
    pAduEmul  IN NUMBER DEFAULT 0,
    pCodJob1  IN NUMBER DEFAULT 0);

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_topclienti;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TOPFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17CE5D56F6F1FCA6DD20B7B95B6333A8133F419D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_topfurn IS

  FUNCTION GETALLIOART_N RETURN NUMBER;
  FUNCTION GETALLCLS_N RETURN NUMBER;
  PROCEDURE setParams( 
    pDataINI IN VARCHAR2,
    pDataFIN IN VARCHAR2,
		pInLei    IN NUMBER,
		pCodJob1  IN NUMBER  DEFAULT 0,
		pAllIOArt IN NUMBER DEFAULT 1,
		pAllCls   IN NUMBER DEFAULT 1)
		;
    
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  FUNCTION GetNrFact_Art(aCodObiect IN NUMBER, aCodPart IN NUMBER, aTip IN NUMBER) RETURN NUMBER;
  FUNCTION GetNrFact_Part(aCodPart IN NUMBER) RETURN NUMBER;
  FUNCTION vInLei RETURN NUMBER;

end pkg_list_Base_topFurn; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TOPFURNANI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>80925E87E80335D815AD7A7B78BEBD9458E712DC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TOPFURNANI IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_topfurnani; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRADUCERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07D1869602AAE9A18AFF641C091CE62528879739</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRADUCERI IS

  -- Author  : DANIEL.LACATUSU
  -- Created : 10.01.2011 14:47:40
  -- Purpose : Liste pentru traduceri
  
  PROCEDURE SetJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetParams;

end PKG_LIST_BASE_TRADUCERI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRANSFDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F343DEA98181861A1A4E8F291AB3F73AE733949</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRANSFDOC IS

  FUNCTION GETVALTVA(aCodTransf IN NUMBER) RETURN NUMBER;
  PROCEDURE PROCESSPARAMS(vCodTransf IN NUMBER);
  PROCEDURE SETPARAMS( pCodDoc  IN NUMBER);
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_TRANSFDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46005EFCE6A5095093DAD9A27A1202DFAC7B752A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRAS IS
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE maketmpSerii;
	PROCEDURE setJoinuri;
end pkg_list_base_tras;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASCMDINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1764787EB16499C478C5BC871E226757E7B75AA2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASCMDINT is

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
  PROCEDURE TEST;
  procedure UmpleTemporar;

end PKG_LIST_BASE_TRASCMDINT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASEELIVRARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F811D7DBE16CB119BBB279239A15DEE7772A94D6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASEELIVRARE IS

  -- Author  : DANIEL.LACATUSU
  -- Created : 19.05.2010 17:44:27
  -- Purpose : 
  
  TYPE tCURSOR_PREGLIVR IS REF CURSOR;
  PROCEDURE SetJoinuri;
  PROCEDURE ProcessList(tmpName IN VARCHAR2,aListID IN NUMBER DEFAULT 0,aListVer IN NUMBER DEFAULT 0);
  PROCEDURE SetParams;

end PKG_LIST_BASE_TRASEELIVRARE; 

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D862DA164AC71B8338E6787E2BC5C8D62534068</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASFACT IS

  PROCEDURE SETPARAMS( pCodDistrib IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_trasfact;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASFACTINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADECB115CB7AE78F6E45A4F639EDA6874B4E8736</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASFACTINC IS

  PROCEDURE SETPARAMS( pCodDistrib IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_trasfactinc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5117C87F5CB05E11C7A9CC2A82FDEAACADEFDCE6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASINC IS

  PROCEDURE SETPARAMS( pCodDistrib IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_trasinc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_TRASPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1D32D9891F5AAAA7C7F2EF57C2B9BC6F6DC357C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_TRASPART IS

  function GetStatusPart(vCodDistrib2 IN NUMBER, vAn IN NUMBER, vLuna IN NUMBER) return VARCHAR2;
  PROCEDURE SETPARAMS( pCodDistrib  IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

end pkg_list_base_traspart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMAECLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15FAF8658FBBABEAE056BFE23A23A5CC2ECC6656</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmaecli IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  FUNCTION GetValAchiz(
    aCodIes1 IN NUMBER,
    aCantF   IN NUMBER DEFAULT 0,
    aAnF     IN NUMBER DEFAULT 0,
    aLunaF   IN NUMBER DEFAULT 0
  ) RETURN number;

END pkg_list_base_urmaecli;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMAEFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0824E2ADF778A11CA7FED72AA93ED9B3CAB7F60</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMAEFURN IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END pkg_list_base_urmaefurn; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMARIREINCASARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4087A3DCC3FE24F02A5839A684CC3AD76CF08AC2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMARIREINCASARI IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

PROCEDURE SetJoinuri;

end pkg_list_base_urmarireincasari; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMARIREPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F0C9FEF9D2ECB2EE666DE444EC9662A0F5C30DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMARIREPLATI IS

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end pkg_list_base_UrmarirePlati;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMARIRE_PREDARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ABBAA7F1E07362E623A0FE779C1548F30B9F42ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMARIRE_PREDARI is

  PROCEDURE setJoinuri;
  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_URMARIRE_PREDARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMARTPEFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6F18FF13F7CC628BC5FED5A9F93FFEE2E4BCEB9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMARTPEFURN IS

  PROCEDURE SetParamsPentruFiltru(dataFin in varchar2);
  PROCEDURE SetListaParams(
	  dataFin   IN VARCHAR2,
	  aCodPart  IN NUMBER,
	  bToateArt IN NUMBER DEFAULT 1,
    pCodJob1  IN NUMBER DEFAULT 0 );
  FUNCTION GET_CODPART RETURN NUMBER ;
  FUNCTION GET_DATA_FIN RETURN VARCHAR2 ;
  FUNCTION GET_DATA_INI RETURN VARCHAR2;
  FUNCTION GET_CANT_UMPRINC(CANT in number, CODUMSEC in number) RETURN NUMBER;
  PROCEDURE ProcessList(tmpName in varchar2, aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END pkg_list_base_urmArtPeFurn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>039CC3A92D7F7F4DF05A7FCE144D55FB17F191F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMBUGET is

procedure SetParams(aFiltruNrInv in varchar2);
PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;  

end PKG_LIST_BASE_URMBUGET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F164770C4F969D350051C8D4020671BEC533CEAB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCOMCLI IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_URMCOMCLI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1946AC3F1610FF65E654FF2564ECD238C6F665C2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmcomenzi IS

  PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_URMCOMENZI;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMFACTSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF5DF3A2BE88B8CFD64924AC2BD4452719F96D83</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCOMFACTSA IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_URMCOMFACTSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D213D1270D6152A0018F5A319691761E54BC4E2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmcomfurn IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

END PKG_LIST_BASE_URMCOMFURN;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>612FC384EBC518A4B6DEB500552199BFB48A169A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCONTR IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMCONTR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D02CC149094146CD60A6EFE0A1F8AA6ED451809C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCONTRABON IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMCONTRABON; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRARENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD9324A0E5F6059820AAFEB779216743B9C46D3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCONTRARENDA IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMCONTRARENDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5ED0FB8083AAEB7A6837768623D6750B54D9196E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCONTRCOM IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMCONTRCOM; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRLEASING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79CD41AD50BD095B74C01C0A1AE752784AA9755E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMCONTRLEASING IS
  PROCEDURE SETPARAMS( pTipSold  IN INTEGER DEFAULT 0);
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMCONTRLEASING;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D2A218BB6E7367B7CA9D1A98861DB5FCA034FD3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmcontrrac IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END pkg_list_base_urmcontrrac; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRRAC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44312BAAC55C5FD50FE2507EFF0F14C19506F40E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmcontrrac1 IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END pkg_list_base_urmcontrrac1; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMINCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55156B3E26B8FC094241E58270070A308C67D0C0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmincart IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  function GetCodContract(aCodPart in number, aDataDoc in Date) return number;

end pkg_list_base_urmincart; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMINCASARIDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51D198875DA3783A32252B57DF8595643A6EE329</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMINCASARIDOC IS

PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_URMINCASARIDOC; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMLOHN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98C930BF78B61FFB735E6E7AF09B0ACA223E6467</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmlohn IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END pkg_list_base_urmlohn;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMNCCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC6D543867F73F4056BF7FA6F104F29AF2D3F921</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMNCCLI IS
  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
END PKG_LIST_BASE_URMNCCLI; 

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A31EBA43FC8545B3F9233BF1102F1E64A7FA5C1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMOFE IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);

PROCEDURE SetJoinuri;

end PKG_LIST_BASE_URMOFE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMPLATIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>935236D1B770CB484D09ED16CEB991F69DE77D31</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_urmplatiart IS

  PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;
  function GetCodContract(aCodPart in number, aDataDoc in Date) return number;

end pkg_list_base_urmplatiart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMPLATIDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F51F1B55A467F3FEEAACAB33169BDB560879139</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMPLATIDOC IS
PROCEDURE setJoinuri;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

END PKG_LIST_BASE_URMPLATIDOC; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMREALDEZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CC93348F722EAB3D3BEB51E14103D6D55B04253</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMREALDEZ IS

  PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end pkg_list_base_urmrealdez; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMSUPV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24CF44FDB804086CA4B23A8DD88CC2645023945B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMSUPV is

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE SetJoinuri;

end PKG_LIST_BASE_URMSUPV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_URMVIRINTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7845ADF33A2CDE1578F78639B3F21D19BFC8721B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_URMVIRINTERNE IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
	PROCEDURE SetJoinuri;

END PKG_LIST_BASE_UrmVirInterne;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36BB026464464A23820DCB7EF530DCE7FD34B6B1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_UTILAJE IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END pkg_list_base_utilaje; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_UTILS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63DE6615FBAC54FD67B28F5DCA43408421137240</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_UTILS IS

  TYPE crs_serii  IS REF CURSOR;

  CT_CANT      CONSTANT NUMBER := 0;
  CT_REST      CONSTANT NUMBER := 1;
  CT_LIVR      CONSTANT NUMBER := 2;
  CT_TOATE     CONSTANT NUMBER := 3;
  CT_STOC_M    CONSTANT NUMBER := 4;
  CT_TRANSF    CONSTANT NUMBER := 5;
  CT_MODIFPRET CONSTANT NUMBER := 6;
  CT_CODNIRSER CONSTANT NUMBER := 7;

  gLunaIni number(2);
  gLunaFin number(2);
  gAnIni   number(4);
  gAnFin   number(4);

  function GetValFractie(aFractie IN varchar2) return number;
  procedure DropJ130;
  FUNCTION GET_DEN_BANCA(aCodBank IN number)RETURN VARCHAR2;
  FUNCTION GetPartComCli(aCodLinieComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION GetGestCom(aCodLinieComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION GetDocComCli(aCodLinieComanda IN NUMBER) RETURN VARCHAR2;
  FUNCTION EsteObiectValid (aCodObiect IN number) return number;
  PROCEDURE MAKE_PMP_LUNA_LISTE;
  PROCEDURE CalculeazaPmpListe;
  FUNCTION GetPMPObiect(aCodObiect IN number ,
                        aSubunitate IN number default 0,
                        aAn IN number default 0 ,
                        aLuna IN number default 0 ) return number;
  FUNCTION GetPMPObiectValuta(aCodObiect IN number ,
                              aSubunitate IN number default 0,
                              aAn IN number default 0 ,
                              aLuna IN number default 0
                        ) return number;

  PROCEDURE BAGA_SERII_IN_TMP(pCant NUMBER  DEFAULT CT_CANT);
  FUNCTION GetCursReferinta (aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA VARCHAR2) RETURN NUMBER;
  --FUNCTION GetCursReferinta (aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA DATE) RETURN NUMBER;
  FUNCTION GetInfoSitValuta(pSitValuta    OUT NUMBER,
                            pBancaValuta  OUT NUMBER,
													  pMonedaValuta OUT NUMBER)  RETURN BOOLEAN;

  PROCEDURE set_filtre (p_filtru IN VARCHAR2,p_val IN VARCHAR2);
  --Functii utile IN paketele pkg_list_base_...
	FUNCTION decode_luna (pLuna NUMBER) RETURN VARCHAR2;
  FUNCTION LunaScurta  (pLuna NUMBER) RETURN VARCHAR2;
	FUNCTION decode_luna (pData DATE)   RETURN VARCHAR2;
  FUNCTION LunaScurta  (pData DATE)   RETURN VARCHAR2;
	FUNCTION decode_zi   (pData DATE)   RETURN VARCHAR2;

  FUNCTION decode_tipdoc (vTip IN NUMBER) RETURN VARCHAR2;
  FUNCTION decode_tipdoc_scurt(pTipDoc NUMBER) return VARCHAR2;
  FUNCTION decode_inchideri(pTipInchidere NUMBER) return VARCHAR2;
  FUNCTION GET_CONT_IOPART (idx_col IN number,codpart IN NUMBER,SEMNIF IN NUMBER)RETURN VARCHAR2;
  FUNCTION GET_DENCONT_IOPART (idx_col IN number,codpart IN NUMBER,SEMNIF IN NUMBER)RETURN VARCHAR2;
  FUNCTION GET_CONT_IOPers (idx_col IN number,codpart IN number,SEMNIF IN NUMBER)RETURN VARCHAR2;
  FUNCTION GETSIMBOLCONT (vCODCONT NUMBER) RETURN VARCHAR2;
  FUNCTION GET_GEST(v_CODGEST IN NUMBER) RETURN VARCHAR2;
  FUNCTION get_umsec  (v_codum IN NUMBER ) RETURN VARCHAR2;
  FUNCTION get_cont_ioart(v_icont IN NUMBER,v_codioart IN NUMBER, v_an IN NUMBER, v_luna IN NUMBER ) RETURN VARCHAR2;
  FUNCTION get_cota_tva_art (v_codobiect IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN NUMBER ;
  FUNCTION get_part (v_cod IN NUMBER) RETURN VARCHAR2;
  FUNCTION get_tiparticol(v_codobiect IN NUMBER) RETURN NUMBER;
  FUNCTION GET_DEN_TAXA (pCodTaxa IN NUMBER) RETURN VARCHAR2;
  FUNCTION get_denioart (v_codioart IN NUMBER) RETURN VARCHAR2;
  FUNCTION COND_SUBUNIT(pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;, pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;, pSUBUNIT IN NUMBER DEFAULT NULL) RETURN VARCHAR2;
  FUNCTION COND_SUBUNITINCLACTIV(pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;, pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;, pSUBUNIT IN NUMBER DEFAULT NULL) RETURN VARCHAR2;
  FUNCTION COND_USERID (pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;USERID&apos;,      pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;) RETURN VARCHAR2;
  PROCEDURE GetSeriiIntrare;
  FUNCTION get_codconts (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN number;
  FUNCTION get_simbol_sec (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2;
  FUNCTION get_name_sec (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2;
  FUNCTION get_codcontt (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN number;
  FUNCTION get_simbol_ter (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2;
  FUNCTION get_name_ter (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2;

  PROCEDURE make_config_luna_iopart;
  PROCEDURE make_config_luna_ioart;

  FUNCTION  iCont_CodCont(pIcont   IN NUMBER,
                          pCodPart IN NUMBER,
                          pAnluna  IN NUMBER,
                          pSemnif  IN NUMBER)
            RETURN NUMBER;

  FUNCTION  decode_iCont( pIcont   IN NUMBER,
                          pCodPart IN NUMBER,
                          pAnluna  IN NUMBER,
                          pSemnif  IN NUMBER)
            RETURN VARCHAR2;

  FUNCTION GETCODNIRSTOC_ORIG (vCODNIRSTOC NUMBER) RETURN NUMBER;
  FUNCTION GETCODNIRSTOCPARINTE (vCODNIRSTOC NUMBER) RETURN NUMBER;

  PROCEDURE UMA_UTILS(cCant       IN  VARCHAR2,
                      cCodObiect  IN  VARCHAR2,
                      sInsertUMA  OUT VARCHAR2,
                      sSelectUMA  OUT VARCHAR2,
                      sJoinUMA    OUT VARCHAR2,
                      sCuFunctii  IN  BOOLEAN DEFAULT FALSE);

  PROCEDURE SET_UMA(pCodObiect IN NUMBER);
  FUNCTION  DUMA1(pCodObiect   IN NUMBER) RETURN VARCHAR2;
  FUNCTION  DUMA2(pCodObiect   IN NUMBER) RETURN VARCHAR2;
  FUNCTION  DUMA3(pCodObiect   IN NUMBER) RETURN VARCHAR2;
  FUNCTION  PUMA1(pCodObiect   IN NUMBER) RETURN NUMBER;
  FUNCTION  PUMA2(pCodObiect   IN NUMBER) RETURN NUMBER;
  FUNCTION  PUMA3(pCodObiect   IN NUMBER) RETURN NUMBER;
  FUNCTION  PUMAC(pCodObiect   IN NUMBER) RETURN NUMBER;
  FUNCTION  PUMAP(pCodObiect   IN NUMBER) RETURN NUMBER;
  FUNCTION  GetCursReg (pCodGeneral IN NUMBER, pCont IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER;
  FUNCTION  GetSoldPart(pCodPart IN NUMBER, pCodLocatie IN NUMBER) RETURN NUMBER;
  FUNCTION  GetSoldPartCumulat(pCodPart IN NUMBER, pCodLocatie IN NUMBER) RETURN NUMBER;
  FUNCTION  GetSoldClient(pCodPart IN NUMBER, pCodLocatie IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION  GetSoldFurnizor(pCodPart IN NUMBER, pCodLocatie IN NUMBER DEFAULT 0) RETURN NUMBER;

  FUNCTION  NIVELE_NCLASEA RETURN INTEGER;
  FUNCTION  NIVELE_ANALIZA RETURN INTEGER;

  PROCEDURE ExtractAnLuna (pAnLuna IN NUMBER, pAn OUT NUMBER, pLuna OUT NUMBER);
  PROCEDURE CLEAR_SIMBOL_LIPSA;
  PROCEDURE SET_LISTA_SIMBOL_LIPSA (pLista IN VARCHAR2);
  PROCEDURE ADD_SIMBOL_LIPSA (pSimbol IN VARCHAR2);
  FUNCTION  SET_SIMBOL_LIPSA (pCodCont IN NUMBER, pSimbol IN VARCHAR2) RETURN NUMBER;
  FUNCTION  LIST_SIMBOL_LIPSA RETURN VARCHAR2;

  PROCEDURE UMPLE_TMP_CONSTVAL_LST (pSimbolList VARCHAR2 DEFAULT NULL);
  PROCEDURE UMPLE_TMP_MEDEX1_LST;
  PROCEDURE UMPLE_TMP_NARTATR_LST;
  PROCEDURE UMPLE_TMP_CAMERE_LST;

  FUNCTION GET_Den_BancaCursPUV(pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_Simb_MonedaFactInValuta(pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_Cod_MonedaFactInValuta(pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER;

  FUNCTION GetObsDoc  (aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN VARCHAR2;
  FUNCTION GetDenDoc  (aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN VARCHAR2;
  FUNCTION GetUserDoc (aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER;
  FUNCTION GetPartDoc (aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER;
  FUNCTION GetTablaDoc(aTipDoc IN NUMBER) RETURN VARCHAR2;
  FUNCTION GetValDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER;

  PROCEDURE UMPLE_TMP_LST_CURS(aCODBANCA IN NUMBER DEFAULT NULL, aDATA DATE DEFAULT NULL, aCODMONEDA IN NUMBER DEFAULT NULL);

  FUNCTION Decode_TipPlata(pTipPlata NUMBER) RETURN VARCHAR2;
  FUNCTION Get_StocExternCamp RETURN VARCHAR2;

  FUNCTION MATCH_TVA      (p_PJTVA IN NUMBER, p_AnLuna IN NUMBER) RETURN NUMBER;
  FUNCTION MATCH_TVA_PROC (p_PJTVA IN NUMBER, p_AnLuna IN NUMBER) RETURN NUMBER;
  FUNCTION CALC_PROC_TVA (
    p_TipDoc     IN NUMBER,
    p_An         IN NUMBER,
    p_Luna       IN NUMBER,
    p_Cant       IN NUMBER,
    p_PU         IN NUMBER,
    p_TVA        IN NUMBER,
    p_CodObiect  IN NUMBER DEFAULT  0,
    p_ProcTvaArt IN NUMBER DEFAULT -1,
    p_RotEfatc   IN NUMBER DEFAULT  0
  ) RETURN NUMBER;
  FUNCTION CALC_MATCH_TVA (
    p_TipDoc     IN NUMBER,
    p_An         IN NUMBER,
    p_Luna       IN NUMBER,
    p_Cant       IN NUMBER,
    p_PU         IN NUMBER,
    p_TVA        IN NUMBER,
    p_CodObiect  IN NUMBER DEFAULT  0,
    p_ProcTvaArt IN NUMBER DEFAULT -1,
    p_RotEfatc   IN NUMBER DEFAULT  0,
    p_ReturnProc IN NUMBER DEFAULT  1
  ) RETURN NUMBER;

  function GetFirstNS(aCodNirStoc in number, aAnLuna in number) return number;

  FUNCTION GetCodArtCli(pCodObiect IN NUMBER, pCodPart IN NUMBER, pCodClaseP IN NUMBER) RETURN NUMBER;

  FUNCTION GetCoefDiscMonetar(
    pCodIes IN NUMBER, pTipLinie IN VARCHAR2, pCodObiect IN NUMBER, pContServ IN NUMBER, pCodIOArt IN NUMBER, pTipCoef IN NUMBER,
    pValLin IN NUMBER DEFAULT 0, pTVALin IN NUMBER DEFAULT 0
  ) RETURN NUMBER;

  FUNCTION getStinsOblig(pCodObligPif IN NUMBER) RETURN NUMBER;
  FUNCTION PondereComanda(pCodIes IN NUMBER, pCodComanda IN NUMBER) RETURN NUMBER;
  FUNCTION getStinsIes  (pCodIes IN NUMBER, pCodComanda IN NUMBER DEFAULT NULL) RETURN NUMBER;
  FUNCTION getTipTVA0 (pCodObiect IN NUMBER, pAn IN NUMBER , pLuna IN NUMBER) RETURN NUMBER;
  FUNCTION isGreenTax (pCodObiect IN NUMBER, pTipLinie IN VARCHAR2, pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER;

  function GetPretMediu(aCodObiect in number) return number;
  function GetCursMediu(aCodObiect in number) return number;
  function GETLUNADINSAPTAMANA(aSet in number, aAn in number) return number;
  function GetSecventa return Number;
  function GetPretMinAchiz(vCodObiect in number) return number;
  function GetPretMedAchiz(vCodObiect in number) return number;
  function GetPretMaxAchiz(vCodObiect in number) return number;
  function GetParinteNivelClsA(aNivel in number, acodclasea in number) return varchar2;
  function GetParinteNivelClsP(aNivel in number, acodclasep in number) return varchar2;
  function Get_termen_concedii(aDataIni in date, xDataFin in date, aCodComanda1 in number, aUserID in number) return date;
  procedure import_nc;
  procedure SetSubDedicate;
  procedure SetGestDedicate;
  procedure CreazaTabela(aSQL in varchar2);
  procedure UmpleTempConsAuto;

END pkg_list_base_utils;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD5D4AA8A769945CEB1D3594672971D600ABEC64</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZAGENT IS

PROCEDURE SETPARAMS(  pLunaIni     IN NUMBER  DEFAULT NULL,
                      pAnIni       IN NUMBER  DEFAULT NULL,
                      pLunaFin     IN NUMBER  DEFAULT NULL,
                      pAnFin       IN NUMBER  DEFAULT NULL,
                      pAllClient   IN NUMBER  DEFAULT 1,
                      pAllAgent    IN NUMBER  DEFAULT 1,
                      pCodJob1     IN NUMBER  DEFAULT 0
                    );

FUNCTION CAMPURI(pTIP IN VARCHAR2) RETURN VARCHAR2;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;

end PKG_LIST_BASE_VANZAGENT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZAGENTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADBA70FD86DF0F308D7226B6BCBF943E3024B1A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_vanzagentart IS

PROCEDURE SETPARAMS(  pLunaIni     IN NUMBER  DEFAULT NULL,
                      pAnIni       IN NUMBER  DEFAULT NULL,
                      pLunaFin     IN NUMBER  DEFAULT NULL,
                      pAnFin       IN NUMBER  DEFAULT NULL,
                      pAllClient   IN NUMBER  DEFAULT 1,
                      pAllAgent    IN NUMBER  DEFAULT 1,
                      pCodJob1     IN NUMBER  DEFAULT 0
                    );

FUNCTION CAMPURI(pTIP IN VARCHAR2) RETURN VARCHAR2;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_VANZAGENTART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>361413458CD4117B56183D8D5A88DCBABB83C15F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZARI IS

  DATASTART  VARCHAR2(1000) := &apos;&apos;;
  DATAEND    VARCHAR2(1000) := &apos;&apos;;
  ID         NUMBER(20, 0);
  VER        NUMBER(20, 0);
  CODRESTAURANT    NUMBER(20, 0) := 0;
  
PROCEDURE SETPARAMS(
	aCODRESTAURANT IN NUMBER, 
	aDATASTART IN VARCHAR2, 
	aDATAEND IN VARCHAR2, 
	aID IN NUMBER, 
	aVER IN NUMBER ,
	pCodJob1     IN NUMBER  DEFAULT 0 );
	
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_VANZARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZARIDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5935CF9F26D036372268CE7D0D08BD24055015F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZARIDISCOUNT IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;
END PKG_LIST_BASE_VANZARIDISCOUNT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZARI_SINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>503C28ABABDB10516E341415A7E57CF5A91AB8B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZARI_SINT is

  DATASTART  VARCHAR2(1000) := &apos;&apos;;
  DATAEND    VARCHAR2(1000) := &apos;&apos;;
  ID         NUMBER(20, 0);
  VER        NUMBER(20, 0);
  
  CODRESTAURANT    NUMBER(20, 0) := 0;
  
PROCEDURE SETPARAMS(
          aCODRESTAURANT IN NUMBER, 
					aDATASTART IN VARCHAR2, 
					aDATAEND IN VARCHAR2, 
					aID IN NUMBER, 
					aVER IN NUMBER,
	        pCodJob1 IN NUMBER  DEFAULT 0 );
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
end PKG_LIST_BASE_VANZARI_SINT; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZCLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A9EAAB8DE85CD53769D842DC015B487E3762F7B0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_vanzclaseart IS
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
 PROCEDURE setJoinuri;
end PKG_LIST_BASE_VANZCLASEART;
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08FEED4CD6B3693BC2A215444E3BA74CE0CD074D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZPER IS

PROCEDURE SETPARAMS(
  pTipPer     IN INTEGER  DEFAULT NULL,
  pTipData    IN INTEGER  DEFAULT 0,
  pInceput    IN VARCHAR2 DEFAULT NULL,
  pSfarsit    IN VARCHAR2 DEFAULT NULL,
  pTipDate    IN INTEGER  DEFAULT NULL,
  pInclTVA    IN INTEGER  DEFAULT 0,
  pInclUnit   IN INTEGER  DEFAULT 0,
  pValuta     IN INTEGER  DEFAULT 0,
  pLunaIni    IN INTEGER  DEFAULT NULL,
  pLunaFin    IN INTEGER  DEFAULT NULL,
  pTipUM      IN INTEGER  DEFAULT NULL,
  pUM         IN INTEGER  DEFAULT NULL,
  pInclServ   IN INTEGER  DEFAULT 0,
  pFaraVanz   IN INTEGER  DEFAULT 0,
  pCodJob1    IN NUMBER   DEFAULT 0,
  pCodAtribut IN NUMBER   DEFAULT 0,
  pValAchiz   IN NUMBER   DEFAULT 0,
  pExclCust   IN INTEGER  DEFAULT 0
);

PROCEDURE BAGA_DINAMIC_COLS;
FUNCTION CAMPURI(pTIP VARCHAR2, pAlias VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;
PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_VANZPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VANZ_SPEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>008081CC74615730367A5CC8018343A193A3E4E4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VANZ_SPEC IS

  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

end PKG_LIST_BASE_VANZ_SPEC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VENITURIRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5075728AF753708526307EF9D7F5A3DBA7116679</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VENITURIRAC IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_VENITURIRAC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VERIF_IMP_IES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A62201EE89D713372AFC26B2D47B6F256C0E7257</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VERIF_IMP_IES IS

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_VERIF_IMP_IES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VERIF_IMP_INTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22594E1E046B8F666A83EF6F2A320B81892B301B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VERIF_IMP_INTR IS

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0);
  PROCEDURE setJoinuri;

END PKG_LIST_BASE_VERIF_IMP_INTR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61B783D1E954BE7C70BC52FCD0C408599B51D22D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_base_VOUCHER IS

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE setJoinuri;

end PKG_LIST_BASE_VOUCHER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHERDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>793A48EA2CE91C037A654C190DB5BBAC2233C21A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VOUCHERDOC IS

PROCEDURE SETPARAMS( pCodDoc IN NUMBER);
PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);
PROCEDURE ADD_LIST_PARAMS;
PROCEDURE setJoinuri;

end pkg_list_base_VOUCHERdoc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHERINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>789EA8B95CA5A69840C4D05C99C59809FC6CCD92</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_BASE_VOUCHERINC is

  PROCEDURE SETPARAMS(pCodVoucher IN NUMBER);
  PROCEDURE setJoinuri;
  PROCEDURE ADD_LIST_PARAMS;
  PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0);

end PKG_LIST_BASE_VOUCHERINC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_CASABANKA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AD0B2D335157D61DFF6177BE23BC99BD0F526D6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_casabanka IS

  TYPE crs IS REF CURSOR;

	FUNCTION  getAllCasa(pLei IN Boolean DEFAULT NULL) RETURN crs;
  FUNCTION  getAllBanca(pLei IN Boolean DEFAULT NULL) RETURN crs;
	FUNCTION  getDataIni RETURN DATE;
	FUNCTION  getDataFin RETURN DATE;
	FUNCTION  getTipDoc  RETURN NUMBER;
  PROCEDURE setParams (v_DataIni IN VARCHAR2,
                       v_DataFin IN VARCHAR2,
                       v_tipDoc  IN NUMBER,
	                     pCodJob1 IN NUMBER  DEFAULT 0 );

end PKG_LIST_CASABANKA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_CONFIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>305717AD91BE2F5C529FAFE1ABF16C6AEFDF668A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_config IS

  type crs is ref cursor;
  gr_id_header number(10):= 200;
  gr_id_footer number(10):= 999999999;

FUNCTION ClientSelect (
  tmptable       IN VARCHAR2,      --&gt; numele tabelului temporar
  visible_cols   IN VARCHAR2,      --&gt; setu de coloane pe care le afiseaza IN lista, tot aici returnez si coloanele system (nrcrt,nrg..) dar care nu se afiseaza IN lista
  sum_cols       IN VARCHAR2,      --&gt; setu coloanele pe care fac sume la nivel de grup; toate coloane de aici trebuie sa fie si IN tmpTable
  group_cols     IN VARCHAR2,      --&gt; setu de coloane pe care fac grupare; toate coloane de aici trebuie sa fie si IN tmpTable
  where_cols     IN VARCHAR2,      --&gt; filtrul where !!! inca nu este implementat
  order_cols     IN VARCHAR2,      --&gt; coloanele de ordonare altele decat cele din group_cols
  sold_cols      IN VARCHAR2,      --&gt; coloanele de tip sold. Pentru fiecare coloana din sold_cols se va genera cate o coloana suplimentara cu suma respectiva. Denumirea coloanelor generate este de forma EXP_n
  resetsold_cols IN VARCHAR2,      --&gt; coloanele la nivelul carora resetez valoarea coloanei de sold. Soldul poate fi calculat la nivelul intregii liste sau se poate reseta la nivelul unui grup care va si specificat pe acest parametru
  calc_cols      IN VARCHAR2,      --&gt; coloane calculate. Vor fi date dupa forma: (a+b)col1,(x*y)col2 unde a,b,x si y sunt coloane din tmpTable iar col1 si col2 sunt numele acestor coloane calculate
  sum_calc       IN VARCHAR2,      --&gt; setu de coloane calculate pentru care fac sume la nivel de grup. Vor fi date dupa forma: (a+b)col1 (subset al calc_cols)
  sold_calc      IN VARCHAR2,      --&gt; Va Urma.....
  fara_total     IN VARCHAR2,      --&gt; un filtru where care poate exclude din calculul totalelor anumite linii; liniile respective sunt afisate IN lista
  viewName       IN VARCHAR2,
  sUserName      IN VARCHAR2,
  bCentralizat   IN BOOLEAN,       --&gt; flag daca lista este sau nu centralizata
  fInterval      IN VARCHAR2,
  sTable         IN VARCHAR2 DEFAULT &apos;?&apos;,
  groupsort      IN VARCHAR2
) return NUMBER;

FUNCTION Get_Group_id(nrcrt IN NUMBER) return NUMBER;
FUNCTION get_id_header RETURN NUMBER;
FUNCTION get_id_footer RETURN NUMBER;
FUNCTION getColoanefromExpresii (calc_cols VARCHAR2,nrCols OUT NUMBER) RETURN VARCHAR2;
FUNCTION get_sum_calc(sum_calc VARCHAR2, fara_total VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;
FUNCTION getDenseRankClause (sCols IN VARCHAR2, nrCols out number) return VARCHAR2;
FUNCTION CautaColoana(sCol IN VARCHAR2, sSirColoane IN CLOB, desc_ OUT BOOLEAN ) RETURN BOOLEAN;
PROCEDURE GET_DATE_FROM_VIEW(tmptable IN VARCHAR2, UserViewName IN VARCHAR2, sUserName IN VARCHAR2);

END PKG_LIST_CONFIG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_FISAANALITIKPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3CC6E00B3811A587EA4955D197EBDA83E9E4583</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_FISAANALITIKPART IS

TYPE crs IS REF CURSOR;

FUNCTION getInfoPart (
  aCodPart   IN NUMBER DEFAULT 0,
  aLunaStart IN NUMBER,
  aLunaFin   IN NUMBER,
  AreConturi IN BOOLEAN DEFAULT FALSE,
  AreMonezi  IN BOOLEAN DEFAULT FALSE,
  info_kind  IN NUMBER
) RETURN crs ;

END pkg_list_fisaanalitikPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFD90B4CFC79F315F89BAFE4A71BF42C2796665A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selart IS
  PROCEDURE setParam (pAllArt BOOLEAN);
  FUNCTION  IsAllArt RETURN BOOLEAN;
END pkg_list_selart;
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELCLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1AECD3AA0CC6458A27FB9A11508E99D83BD0E728</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELCLASEART IS
 
  PROCEDURE SETPARAMS(  pPerioada    IN VARCHAR2 DEFAULT NULL,
                        pToateClaseA IN NUMBER DEFAULT 1,
                        pTotiPart    IN NUMBER DEFAULT 1,
	                      v_DataIni IN VARCHAR2,
                        v_DataFin IN VARCHAR2,
                        pCodJob1 IN NUMBER  DEFAULT 0 
                      );

  FUNCTION Perioada    RETURN VARCHAR2; 
  FUNCTION ToateClaseA RETURN BOOLEAN; 
  FUNCTION TotiPart    RETURN BOOLEAN; 

end PKG_LIST_SELCLASEART; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELCOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64B591BF6359B664A8A9CA8F67510C03C670C861</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELCOMENZI IS

  PROCEDURE setParams (
    pDupaData IN NUMBER   DEFAULT 0,
    pPerS     IN VARCHAR2 DEFAULT NULL,
    pPerF     IN VARCHAR2 DEFAULT NULL,
    pAllGest  IN NUMBER   DEFAULT 0,
    pComInchise IN NUMBER DEFAULT 0,
    V_CODJOB1 IN NUMBER   DEFAULT 0);
  FUNCTION DupaData  RETURN BOOLEAN;
  FUNCTION Perioada  RETURN VARCHAR2;
  FUNCTION AllGest RETURN BOOLEAN;
  FUNCTION ComInchise RETURN NUMBER;

END PKG_LIST_SELCOMENZI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD8846F270896F8F150501DF3BBA8FA5BD247479</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELCONT IS

TYPE crsGlobal IS REF Cursor;

  FUNCTION GetPerioada RETURN crsGlobal;
  function GetPerioadaAni return crsGlobal;

  FUNCTION GetConturiCuMiscare(pLunaStart IN NUMBER , pLunaFin IN NUMBER) RETURN crsGlobal;
	FUNCTION getTipPlan RETURN INTEGER;
	FUNCTION getLuna RETURN VARCHAR2;
  FUNCTION getCuObs RETURN BOOLEAN;
  FUNCTION getSubunit RETURN NUMBER;
  FUNCTION getSoldSub RETURN BOOLEAN;

	FUNCTION GetLunaStart RETURN NUMBER;
	FUNCTION GetLunaStop RETURN NUMBER;

	PROCEDURE SetParams (
    pLunaStart IN NUMBER,
    pLunaFin   IN NUMBER,
    pPlan      IN NUMBER,
    pCuObs     IN NUMBER,
    pSubunit   IN NUMBER DEFAULT 1,
    pSoldSub   IN NUMBER DEFAULT 0,
    pCodJob1   IN NUMBER DEFAULT 0);
end pkg_list_selCont;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELDATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64F8304FBD4848A7EDFBE452C5D8A444466CBD69</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELDATA IS

PROCEDURE setAllParams(pDataRef   IN VARCHAR2 DEFAULT NULL,
                       pCodExtra1 IN NUMBER   DEFAULT NULL,
                       pChkExtra1 IN NUMBER   DEFAULT 0);

FUNCTION GetDataRef RETURN DATE;
FUNCTION CodExtra1  RETURN NUMBER;
FUNCTION ChkExtra1  RETURN BOOLEAN;

end PKG_LIST_SELDATA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELDELEGAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A9B36F47F52FB1AD8A89606FE08CF32CFBF5FB81</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELDELEGAT IS

  PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                        pDataIni    IN VARCHAR2 DEFAULT NULL,
                        pDataFin    IN VARCHAR2 DEFAULT NULL,
                        pLunaAnIni  IN INTEGER  DEFAULT 0,
                        pLunaAnFin  IN INTEGER  DEFAULT 0,
                        pAllDeleg   IN NUMBER   DEFAULT 1,
                        v_CODJOB1   IN NUMBER   DEFAULT 0 );

  FUNCTION DupaData       RETURN BOOLEAN;
  FUNCTION DataIni        RETURN DATE;
  FUNCTION DataFin        RETURN DATE;
  FUNCTION LunaAnIni      RETURN INTEGER;
  FUNCTION LunaAnFin      RETURN INTEGER;
  FUNCTION TotiDelegatii  RETURN BOOLEAN;

end PKG_LIST_SELDELEGAT; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELDOCEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08B43414FD30690997E459E834E06A043A4470AC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELDOCEXT IS
  -- STEF - Selectie asociata ListDocExtFrm -&gt; PKG_LIST_BASE_INTEXT, PKG_LIST_BASE_IESEXT
  PROCEDURE setParams (
    pDupaData IN NUMBER DEFAULT 0,
    pDataS    IN VARCHAR2,
    pDataF    IN VARCHAR2,
    V_CODJOB1 IN NUMBER DEFAULT 0);
  FUNCTION DupaData RETURN BOOLEAN;
  FUNCTION Perioada RETURN VARCHAR2;
  FUNCTION DataS    RETURN DATE;
  FUNCTION DataF    RETURN DATE;
END PKG_LIST_SELDOCEXT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67D4BBD559E9D0D0E5B36E2678B6E202006DFBCB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selectemulare IS

	FUNCTION  getDataIni RETURN DATE;
	FUNCTION  getDataFin RETURN DATE;
	FUNCTION  getTipPrel RETURN NUMBER;
  FUNCTION  getTipFiltrare RETURN NUMBER;
  function getSiRetur return boolean;
PROCEDURE setParams( v_DataIni IN VARCHAR2, 
	                   v_DataFin IN VARCHAR2, 
										 v_TipPrel IN NUMBER, 
										 v_TipFiltrare IN NUMBER, 
										 v_SiRetur IN NUMBER DEFAULT 0,
                     v_CODJOB1   IN NUMBER   DEFAULT 0 
										 ) ;

END PKG_LIST_SELECTEMULARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57186072FCC1C0B416E95BD18992B00AB7E00A77</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTGEST IS

  PROCEDURE SETPARAMS(
    pDataIni    IN VARCHAR2 DEFAULT NULL,
    pDataFin    IN VARCHAR2 DEFAULT NULL,
    pAllGest    IN NUMBER   DEFAULT 1,
    pDupaData   IN NUMBER   DEFAULT 1,
    pLunaAnIni  IN INTEGER  DEFAULT 0,
    pLunaAnFin  IN INTEGER  DEFAULT 0,
    pAduSerii   IN NUMBER   DEFAULT 1,
    pCalcPMP    IN NUMBER   DEFAULT 0,
    pDataDoc    IN NUMBER   DEFAULT 1,
    pExtra1     IN NUMBER   DEFAULT 0,
    v_CODJOB1   IN NUMBER   DEFAULT 0,
    pExtra2     IN NUMBER   DEFAULT 0,
    pExtra3     IN NUMBER   DEFAULT 0,
    pAllTipDoc  IN NUMBER   DEFAULT 1,
    sDocs       IN VARCHAR2 DEFAULT NULL
  );

  FUNCTION DataDoc       RETURN BOOLEAN;
  FUNCTION ToateGest     RETURN BOOLEAN;
  FUNCTION DataIni       RETURN DATE;
  FUNCTION DataFin       RETURN DATE;
  FUNCTION DupaData      RETURN BOOLEAN;
  FUNCTION LunaAnIni     RETURN INTEGER;
  FUNCTION LunaAnFin     RETURN INTEGER;
  FUNCTION AduSerii      RETURN INTEGER;
  FUNCTION CalculeazaPMP RETURN BOOLEAN;
  FUNCTION Extra1        RETURN BOOLEAN;
  FUNCTION Extra2        RETURN BOOLEAN;
  FUNCTION Extra3        RETURN BOOLEAN;
  FUNCTION ToateTipDoc   RETURN BOOLEAN;
  FUNCTION Docs          RETURN VARCHAR2;

end PKG_LIST_SELECTGEST;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTGEST2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C8BF378EE758E38FE4CEAD95ABA4C986C86FD11</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTGEST2 IS

PROCEDURE SETPARAMS(
  pAllGest  IN NUMBER  DEFAULT 1,
  pZiuaIni  IN INTEGER DEFAULT NULL,
  pZiuaFin  IN INTEGER DEFAULT NULL,
  pAllIOArt IN NUMBER  DEFAULT 1,
  pData     IN NUMBER  DEFAULT 1
);
FUNCTION ToateGest   RETURN BOOLEAN;
FUNCTION ZiuaIni     RETURN INTEGER;
FUNCTION ZiuaFin     RETURN INTEGER;
FUNCTION ToateIoart  RETURN BOOLEAN;
FUNCTION TipData     RETURN INTEGER;

END PKG_LIST_SELECTGEST2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTGESTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>888904403B8281B1561C0BBDA844769FE43C7CA9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTGESTART IS

PROCEDURE SetParams(
  pAllGest    IN NUMBER DEFAULT 1,
  pAllArt     IN NUMBER DEFAULT 1,
  pDataStart  IN VARCHAR2,
  pDataFin    IN VARCHAR2,
  pCodComanda IN NUMBER DEFAULT 0,
  pSerii      IN NUMBER DEFAULT 0,
  pCodJob1 IN NUMBER  DEFAULT 0,
  pAnaliza IN NUMBER  DEFAULT 0,
  pSaptamana IN NUMBER DEFAULT 0 );

  FUNCTION DataStart RETURN DATE;
  FUNCTION DataFin   RETURN DATE;
  FUNCTION AllGest   RETURN BOOLEAN;
  FUNCTION AllArt    RETURN BOOLEAN;
  FUNCTION CodComanda RETURN NUMBER;
  FUNCTION Serii RETURN NUMBER;
  FUNCTION Analiza RETURN NUMBER;
  FUNCTION Saptamana RETURN NUMBER;

end pkg_list_selectgestart; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTGESTPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4FCABB79BD31669E2261E3E8B88EC72DD7E1E7B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selectgestper is

PROCEDURE SETPARAMS(  pDataIni    IN VARCHAR2 DEFAULT NULL,
                      pDataFin    IN VARCHAR2 DEFAULT NULL,
                      pAllGest    IN NUMBER   DEFAULT 1,
                      pDupaData   IN NUMBER   DEFAULT 1,
                      pLunaAnIni  IN INTEGER  DEFAULT 0,
                      pLunaAnFin  IN INTEGER  DEFAULT 0,
                      pAduSerii   IN NUMBER   DEFAULT 1,
                      pCalcPMP    IN NUMBER   DEFAULT 0,
                      pDataDoc    IN NUMBER   DEFAULT 1,
                      pExtra1     IN NUMBER   DEFAULT 0,
                      v_CODJOB1   IN NUMBER   DEFAULT 0,
                      pExtra2     IN NUMBER   DEFAULT 0,
                      pExtra3     IN NUMBER   DEFAULT 0,
                      pIndiferent IN NUMBER   DEFAULT 1,
                      pDataDocIni IN VARCHAR2 DEFAULT NULL,
                      pDataDocFin IN VARCHAR2 DEFAULT NULL,
                      pCod        IN NUMBER   DEFAULT 0
                      );

  FUNCTION DataDoc       RETURN BOOLEAN;
  FUNCTION ToateGest     RETURN BOOLEAN;
  FUNCTION DataIni       RETURN DATE;
  FUNCTION DataFin       RETURN DATE;
  FUNCTION DupaData      RETURN BOOLEAN;
  FUNCTION LunaAnIni     RETURN INTEGER;
  FUNCTION LunaAnFin     RETURN INTEGER;
  FUNCTION AduSerii      RETURN BOOLEAN;
  FUNCTION CalculeazaPMP RETURN BOOLEAN;
  FUNCTION Extra1        RETURN BOOLEAN;
  FUNCTION Extra2        RETURN BOOLEAN;
  FUNCTION Extra3        RETURN BOOLEAN;
  FUNCTION Indiferent    RETURN BOOLEAN;
  FUNCTION DataDocIni    RETURN DATE;
  FUNCTION DataDocFin    RETURN DATE;
  FUNCTION Cod           RETURN NUMBER;

end pkg_list_selectgestper; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTGESTREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17A76D0910A18AAFCA4DCD4768F895D64687CFF7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTGESTREST IS

	FUNCTION  getDataIni RETURN DATE;
	FUNCTION  getDataFin RETURN DATE;
	PROCEDURE setParams(  v_DataIni IN VARCHAR2, 
												v_DataFin IN VARCHAR2, 
												v_CodGest IN NUMBER,
												pCodJob1 IN NUMBER  DEFAULT 0 );
END PKG_LIST_SELECTGESTREST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTIEPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8163D100E9F8C80CD45C015E4B123A90C0700F6D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTIEPROFIT IS

PROCEDURE SETPARAMS(pDataIni     IN VARCHAR2 DEFAULT NULL,
                    pDataFin     IN VARCHAR2 DEFAULT NULL,
                    pAllGest     IN NUMBER   DEFAULT 1,
                    pDupaData    IN NUMBER   DEFAULT 1,
                    pLunaAnIni   IN INTEGER  DEFAULT 0,
                    pLunaAnFin   IN INTEGER  DEFAULT 0,
                    pIntern      IN NUMBER   DEFAULT 1,
                    pExtern      IN NUMBER   DEFAULT 1,
                    pTransf      IN NUMBER   DEFAULT 1,
                    pSubunit     IN NUMBER   DEFAULT 1,
                    pFactAviz    IN NUMBER   DEFAULT 1,
                    pExtra1      IN NUMBER   DEFAULT 0,
                    pExtra2      IN NUMBER   DEFAULT 0,
                    pMon         IN NUMBER   DEFAULT 1,
                    pExtra3      IN NUMBER   DEFAULT 0,
                    pCodJob1 IN NUMBER  DEFAULT 0 )
;
FUNCTION ToateGest   RETURN BOOLEAN;
FUNCTION DataIni     RETURN DATE;
FUNCTION DataFin     RETURN DATE;
FUNCTION DupaData    RETURN BOOLEAN;
FUNCTION LunaAnIni   RETURN INTEGER;
FUNCTION LunaAnFin   RETURN INTEGER;

FUNCTION DocInterne  RETURN BOOLEAN;
FUNCTION DocExterne  RETURN BOOLEAN;
FUNCTION DocTransf   RETURN BOOLEAN;
FUNCTION DocSubunit  RETURN BOOLEAN;
FUNCTION DocFactAviz RETURN BOOLEAN;
FUNCTION DocMon      RETURN BOOLEAN;

FUNCTION Extra1      RETURN BOOLEAN;
FUNCTION Extra2      RETURN BOOLEAN;
FUNCTION Extra3      RETURN BOOLEAN;

END pkg_list_selectieprofit; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76D797074F65F1905EB6F5C7B76FA9FE2D2CACB7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTIOART IS

  PROCEDURE SETPARAMS(pToateIOArt IN NUMBER DEFAULT 1, pExtra in number default 0, pExtra2 in number default 1);
  FUNCTION ToateIOArt RETURN BOOLEAN;
  FUNCTION Extra RETURN BOOLEAN; 
  FUNCTION Extra2 RETURN BOOLEAN; 

end PKG_LIST_SELECTIOART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AD8287417BFE93F2BF42FB54531E6D1B9086364</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTLUNA IS

  PROCEDURE SETPARAMS(
    p_LunaStart IN NUMBER,
	  p_LunaFin   IN NUMBER,
		p_Curs      IN NUMBER DEFAULT 1,
    p_Extra1    IN NUMBER DEFAULT 0,
    pCodJob1    IN NUMBER DEFAULT 0,
    p_Fixed     IN NUMBER DEFAULT 0,
    p_Valuta    IN NUMBER DEFAULT 0,
    p_Extra2    IN NUMBER DEFAULT 0,
    p_Extra3    IN NUMBER DEFAULT 0
  );
  FUNCTION LunaStart RETURN NUMBER;
  FUNCTION LunaFin   RETURN NUMBER;
  FUNCTION Curs      RETURN NUMBER;
  FUNCTION Extra1    RETURN BOOLEAN;
  FUNCTION ColFix    RETURN BOOLEAN;
  FUNCTION isValuta  RETURN BOOLEAN;
  FUNCTION Extra2    RETURN BOOLEAN;
  FUNCTION Extra2Numeric RETURN NUMBER;
  FUNCTION Extra3    RETURN BOOLEAN;
  FUNCTION Extra3Numeric RETURN NUMBER;

end PKG_LIST_SELECTLUNA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTLUNAAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5337850B3BD8CB4D567E19EEF5F19C73926B5A75</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTLUNAAN IS

  PROCEDURE SETPARAMS(
    p_LunaStart IN NUMBER   DEFAULT NULL,
    p_LunaStop  IN NUMBER   DEFAULT NULL,
    pOpt1       IN NUMBER   DEFAULT 0,
    pOpt2       IN NUMBER   DEFAULT 0,
    pAllX       IN NUMBER   DEFAULT 1,
    pCodJob1    IN NUMBER   DEFAULT 0,
    pCurs       IN NUMBER   DEFAULT 1,
    pAllY       IN NUMBER   DEFAULT 1,
    pDataIni    IN VARCHAR2 DEFAULT NULL,
    pDataFin    IN VARCHAR2 DEFAULT NULL
  );

  FUNCTION LunaStart RETURN NUMBER;
  FUNCTION LunaStop  RETURN NUMBER;
  FUNCTION DataIni   RETURN VARCHAR2;
  FUNCTION DataFin   RETURN VARCHAR2;
  FUNCTION optiunea1 RETURN BOOLEAN;
  FUNCTION optiunea2 RETURN BOOLEAN;
  FUNCTION AllX      RETURN BOOLEAN;
  FUNCTION AllY      RETURN BOOLEAN;
  FUNCTION Curs      RETURN NUMBER;
  PROCEDURE SETPARAMS_ListeProprii(
    pUSERID      IN NUMBER,
    pListID      IN NUMBER,
    pListVer     IN NUMBER,
    pLuna1       IN NUMBER   DEFAULT NULL,
    pLuna2       IN NUMBER   DEFAULT NULL,
    pAn1         IN NUMBER   DEFAULT NULL,
    pAn2         IN NUMBER   DEFAULT NULL,
    pData1       IN VARCHAR2 DEFAULT &apos;?&apos;,
    pData2       IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt1Luna1   IN NUMBER   DEFAULT NULL,
    pInt1Luna2   IN NUMBER   DEFAULT NULL,
    pInt1An1     IN NUMBER   DEFAULT NULL,
    pInt1An2     IN NUMBER   DEFAULT NULL,
    pInt1Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt1Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt2Luna1   IN NUMBER   DEFAULT NULL,
    pInt2Luna2   IN NUMBER   DEFAULT NULL,
    pInt2An1     IN NUMBER   DEFAULT NULL,
    pInt2An2     IN NUMBER   DEFAULT NULL,
    pInt2Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt2Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt3Luna1   IN NUMBER   DEFAULT NULL,
    pInt3Luna2   IN NUMBER   DEFAULT NULL,
    pInt3An1     IN NUMBER   DEFAULT NULL,
    pInt3An2     IN NUMBER   DEFAULT NULL,
    pInt3Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt3Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt4Luna1   IN NUMBER   DEFAULT NULL,
    pInt4Luna2   IN NUMBER   DEFAULT NULL,
    pInt4An1     IN NUMBER   DEFAULT NULL,
    pInt4An2     IN NUMBER   DEFAULT NULL,
    pInt4Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt4Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt5Luna1   IN NUMBER   DEFAULT NULL,
    pInt5Luna2   IN NUMBER   DEFAULT NULL,
    pInt5An1     IN NUMBER   DEFAULT NULL,
    pInt5An2     IN NUMBER   DEFAULT NULL,
    pInt5Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pInt5Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
    pVal1        IN VARCHAR2 DEFAULT NULL,
    pVal2        IN VARCHAR2 DEFAULT NULL,
    pVal3        IN VARCHAR2 DEFAULT NULL,
    pVal4        IN VARCHAR2 DEFAULT NULL,
    pVal5        IN VARCHAR2 DEFAULT NULL
	);

END PKG_LIST_SELECTLUNAAN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89D3F07B94C4675E1FD94C532ECB163598803FF7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selectper IS

  -- 21.03.2008 - STEF - Selectie Perioada -- MIscari -&gt; sitPred.,sitCons.

  PROCEDURE SETPARAMS(
    pDataIni     IN VARCHAR2 DEFAULT NULL,
    pDataFin     IN VARCHAR2 DEFAULT NULL,
    pToateArt    IN NUMBER   DEFAULT 1,
    pToateGest   IN NUMBER   DEFAULT 1,
    pDupaData    IN NUMBER   DEFAULT 1,
    pLunaAnIni   IN INTEGER  DEFAULT 0,
    pLunaAnFin   IN INTEGER  DEFAULT 0,
    pAduSerii    IN NUMBER   DEFAULT 1,
    pCodJob1     IN NUMBER   DEFAULT 0,
    pTipPer      IN NUMBER   DEFAULT 0,
    pInfoNP      IN NUMBER   DEFAULT 0
  );
  
  FUNCTION DataIni   RETURN DATE;
  FUNCTION DataFin   RETURN DATE;
  FUNCTION ToateArt  RETURN BOOLEAN;
  FUNCTION ToateGest RETURN BOOLEAN;
  FUNCTION DupaData  RETURN BOOLEAN;
  FUNCTION LunaAnIni RETURN INTEGER;
  FUNCTION LunaAnFin RETURN INTEGER;
  function AduSerii return boolean;
  FUNCTION InfoNP RETURN BOOLEAN;
  FUNCTION TipPer RETURN INTEGER;
end PKG_LIST_SELECTPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTPERIOADA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C32BEE3D99B53388B14D3DD8E1C31F8781AE170</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selectperioada IS

  PROCEDURE SETPARAMS(
    pDupaData   IN NUMBER   DEFAULT 1,
    pDataIni    IN VARCHAR2 DEFAULT NULL,
    pDataFin    IN VARCHAR2 DEFAULT NULL,
    pAnLunaIni  IN NUMBER   DEFAULT NULL,
    pAnLunaFin  IN NUMBER   DEFAULT NULL,
    pOpt1       IN NUMBER   DEFAULT 0,
    pOpt2       IN NUMBER   DEFAULT 0,
    pAllX       IN NUMBER   DEFAULT 1,
    pCodJob1    IN NUMBER   DEFAULT 0,
    pDataOraIni IN VARCHAR2 DEFAULT NULL,
    pDataOraFin IN VARCHAR2 DEFAULT NULL);
    
  FUNCTION DupaData  RETURN BOOLEAN;
  FUNCTION DataIni   RETURN DATE;
  FUNCTION DataFin   RETURN DATE;
  FUNCTION AnLunaIni RETURN NUMBER;
  FUNCTION AnLunaFin RETURN NUMBER;
  FUNCTION optiunea1 RETURN BOOLEAN;
  FUNCTION optiunea2 RETURN BOOLEAN;
  FUNCTION AllX      RETURN BOOLEAN;
  FUNCTION DataOraIni RETURN DATE;
  FUNCTION DataOraFin RETURN DATE;

END pkg_list_selectperioada; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTSCAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75E46C724B1E228699B0FB77EE3C4AB5217BE3FE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTSCAD IS
  -- 24.03.2008 - STEF - Selectie Scadenda -- Stocuri -&gt; Balanta Stocurilor

  PROCEDURE SETPARAMS(
    pToateGest    IN INTEGER  DEFAULT 1,                             
    pToateIoart   IN INTEGER  DEFAULT 1,                             
    pFaraPret     IN INTEGER  DEFAULT 0,                             
    pDataIni      IN VARCHAR2 DEFAULT NULL,                          
    pDataScad     IN VARCHAR2 DEFAULT NULL,                          
    pLunaIni      IN NUMBER   DEFAULT NULL,                          
    pLunaFin      IN NUMBER   DEFAULT NULL,                          
    pCentralizat  IN NUMBER   DEFAULT NULL,                          
    pExtra1       IN INTEGER  DEFAULT 0,                             
    pExtra2       IN INTEGER  DEFAULT 0,                             
    pTipNecesar   IN NUMBER   DEFAULT 0,                             
    pPerVanz      IN INTEGER  DEFAULT 0,                             
    pDataVIni     IN VARCHAR2 DEFAULT NULL,                          
    pDataVScad    IN VARCHAR2 DEFAULT NULL,                          
    pFaraRezInv   IN INTEGER  DEFAULT 0,                             
    pCodJob1      IN NUMBER   DEFAULT 0,                             
    pSetimana     IN NUMBER   DEFAULT 0,                             
    pMod          IN NUMBER   DEFAULT 0,                             
    pExtra3       IN INTEGER  DEFAULT 0
    );

  FUNCTION DataVIni    RETURN VARCHAR2;
  FUNCTION DataVFIN    RETURN VARCHAR2;
  FUNCTION PerVanz     RETURN BOOLEAN;
  FUNCTION ToateGest   RETURN BOOLEAN;
  FUNCTION ToateGestN  RETURN NUMBER;
  FUNCTION ToateIoart  RETURN BOOLEAN;
  FUNCTION FaraPret    RETURN BOOLEAN;
  FUNCTION DataIni     RETURN DATE;
  FUNCTION DataScad    RETURN DATE;
  FUNCTION LunaIni     RETURN INTEGER;
  FUNCTION LunaFin     RETURN INTEGER;
  FUNCTION Centralizat RETURN INTEGER;
  FUNCTION Extra1      RETURN BOOLEAN;
  FUNCTION Extra2      RETURN BOOLEAN;
  FUNCTION Extra3      RETURN BOOLEAN;
  FUNCTION TipNecesar  RETURN INTEGER;
  FUNCTION FaraRezInventar RETURN BOOLEAN;
  FUNCTION Setimana    RETURN INTEGER;
  FUNCTION ModSelectie RETURN INTEGER;

END PKG_LIST_SELECTSCAD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELECTSCADENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC545DA092DBC567175C583ADF3FA379F6851929</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELECTSCADENTAR IS

  PROCEDURE setParams (
    p_DataRef        IN VARCHAR2,
    p_TranzInCurs    IN NUMBER   DEFAULT 0,
    p_TCursFirma     IN NUMBER   DEFAULT 0,
    p_Lei            IN NUMBER   DEFAULT 0,
    p_AdaosDoc       IN NUMBER   DEFAULT 0,
    p_DiscTermen     IN NUMBER   DEFAULT 0,
    p_ToateClasele   IN NUMBER   DEFAULT 1,
    p_TotiPart       IN NUMBER   DEFAULT 1,
    p_TipIntarziere  IN INTEGER  DEFAULT 0,
    p_TipCalculRest  IN INTEGER  DEFAULT 0,
    p_DataRest       IN VARCHAR2 DEFAULT NULL,
    p_TipPerioada    IN INTEGER  DEFAULT 0,
    p_ValSapt        IN NUMBER   DEFAULT 0,
    v_ListId         IN NUMBER   DEFAULT 0,
    v_CodJob1        IN NUMBER   DEFAULT 0,
    p_CumulatFirma   IN NUMBER   DEFAULT 0,
    p_DetTranzInCurs IN NUMBER   DEFAULT 0);


  FUNCTION DataRef        RETURN DATE;
  FUNCTION CuTranzInCurs  RETURN BOOLEAN;
  FUNCTION TranzCursFirma RETURN BOOLEAN;
  FUNCTION DetTranzInCurs RETURN BOOLEAN;
  FUNCTION InLei          RETURN BOOLEAN;
  FUNCTION CalcAdaosDoc   RETURN BOOLEAN;
  FUNCTION CalcDiscTermen RETURN BOOLEAN;
  FUNCTION ToateClasele   RETURN BOOLEAN;
  FUNCTION ToateClaseleNumber RETURN NUMBER;
  FUNCTION TotiPart       RETURN BOOLEAN;
  FUNCTION TotiPartNumber RETURN NUMBER;
  FUNCTION TipIntarziere  RETURN INTEGER;
  FUNCTION CodJob1 RETURN NUMBER;
  FUNCTION TipCalculRest  RETURN INTEGER;
  FUNCTION DataRest       RETURN DATE;
  FUNCTION TipPerioada    RETURN INTEGER;
  FUNCTION ValSapt        RETURN BOOLEAN;
  FUNCTION TMPOk          RETURN BOOLEAN;
  FUNCTION COND_SUBUNIT(
    pTabla   IN VARCHAR2 DEFAULT NULL,
    pColoana IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;
  ) RETURN VARCHAR2;

  FUNCTION  FiltruData (sListaCamp IN VARCHAR2) RETURN VARCHAR2;
END PKG_LIST_SELECTSCADENTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELFISAMAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2F4F51D9FBDA3F55464D633E3F996E1C6D72996</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELFISAMAG IS

--BAGAT TOTI PARAMETRII PE O SINGURA PROCEDURA
TYPE crs IS REF CURSOR;
PROCEDURE setAllParams(
  v_dataini    IN VARCHAR2,
  v_dataFin    IN VARCHAR2,
  v_DataStoc   IN VARCHAR2,
  v_flgGest    IN NUMBER,
  v_flgTipCont IN NUMBER,
  v_flgArt     IN NUMBER,
  v_StocLaZi   IN NUMBER   DEFAULT 0,
  v_areSerii   IN NUMBER   DEFAULT 0,
  v_CalcPMP    IN NUMBER   DEFAULT 0,
  v_DataRef    IN VARCHAR2 DEFAULT NULL,
  v_Stoc0      IN NUMBER   DEFAULT 0,
  v_CodJob1    IN NUMBER   DEFAULT 0,
  v_RezUM1     IN NUMBER   DEFAULT 0,
  v_ListID     IN NUMBER   DEFAULT 0,
  v_ExclNeconform IN NUMBER DEFAULT 0,
  v_Nedes      IN NUMBER   DEFAULT 0
);

FUNCTION getDataIni      RETURN DATE;
FUNCTION getDataFin      RETURN DATE;
FUNCTION getDataStoc     RETURN DATE;
FUNCTION getDataRef      RETURN DATE;
FUNCTION GetInterval     RETURN VARCHAR2;
FUNCTION isAllTipCont    RETURN BOOLEAN;
FUNCTION isAllGest       RETURN BOOLEAN;
FUNCTION StocLaZi        RETURN BOOLEAN;
FUNCTION areSerii        RETURN BOOLEAN;
FUNCTION calculeaza_pmp  RETURN BOOLEAN;
FUNCTION isToateArt      RETURN NUMBER;
FUNCTION getNumToateCont RETURN NUMBER;
FUNCTION getNumToateGest RETURN NUMBER;
FUNCTION inclArtStoc0    RETURN BOOLEAN;
FUNCTION TipStocIni      RETURN NUMBER;
FUNCTION RezUM1          RETURN BOOLEAN;
FUNCTION ListID          return number;
FUNCTION exclNeconform   RETURN BOOLEAN;
FUNCTION inclNedes       RETURN BOOLEAN;

END PKG_LIST_SELFISAMAG;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELFISAPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DAC32178CA0160ED9EBC8396037DC2B84612784</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELFISAPERS IS

  TYPE crs IS REF CURSOR;

  PROCEDURE SETPARAMS(
    p_AllMon    IN NUMBER DEFAULT 1,
    p_AllTipC   IN NUMBER DEFAULT 1,
    p_AnLunaIni IN NUMBER DEFAULT NULL,
    p_AnLunaFin IN NUMBER DEFAULT NULL,
    p_CodPers   IN NUMBER DEFAULT 0,
    p_Lei       IN NUMBER DEFAULT 0,
    p_Subunit   IN NUMBER DEFAULT 1 ,
    V_CODJOB1   IN NUMBER DEFAULT 0
  );

  FUNCTION isAllMon   RETURN BOOLEAN;
  FUNCTION isAllTipC  RETURN BOOLEAN;
  FUNCTION AnLunaIni  RETURN NUMBER;
  FUNCTION AnLunaFin  RETURN NUMBER;
  FUNCTION CodPers    RETURN NPERS.CODPERS%TYPE;
  FUNCTION gettipCont RETURN crs;
  FUNCTION isAllTipCN RETURN NUMBER;
  FUNCTION Lei        RETURN NUMBER;
  FUNCTION isSubunit  RETURN BOOLEAN;

end PKG_LIST_SELFISAPERS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELINTIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D7A0B86A08A54ECD954430B33074FA952084A93</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELINTIES IS
  -- STEF - Selectie asociata ListIntrariFrm -&gt; PKG_LIST_BASE_INTRARI, PKG_LIST_BASE_IESIRI, PKG_LIST_BASE_MONETARE
  PROCEDURE setParams (
    bObj      IN INTEGER,
    pDupaData IN NUMBER DEFAULT 0,
    pLista    IN INTEGER,
    pUM       IN INTEGER DEFAULT 0,
    pDataS    IN VARCHAR2,
    pDataF    IN VARCHAR2,
    pExtra1   IN NUMBER DEFAULT 0,
    pExtra2   IN NUMBER DEFAULT 0,
    pExtra3   IN NUMBER DEFAULT 0,
    pExtra4   IN NUMBER DEFAULT 0,
    pAtrib1   IN INTEGER DEFAULT 0,
    V_CODJOB1 IN NUMBER DEFAULT 0,
    pSeriiFaraCant IN NUMBER DEFAULT 0);
  FUNCTION ToateArt  RETURN BOOLEAN;
  FUNCTION DupaData  RETURN BOOLEAN;
  FUNCTION Perioada  RETURN VARCHAR2;
  FUNCTION Lista     RETURN INTEGER;
  FUNCTION Um        RETURN INTEGER;
  FUNCTION DataS     RETURN DATE;
  FUNCTION DataF     RETURN DATE;
  FUNCTION Extra1    RETURN BOOLEAN;
  FUNCTION Extra2    RETURN BOOLEAN;
  FUNCTION Extra3    RETURN BOOLEAN;
  FUNCTION Extra4    RETURN BOOLEAN;
  FUNCTION Atrib1    RETURN INTEGER;
  FUNCTION SeriiFaraCant RETURN BOOLEAN;
END PKG_LIST_SELINTIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELLIVRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7B053B7AEDC5C7F826A89A36B732783870248CD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELLIVRARI IS

  -- STEF - Selectie asociata ListLivrariFrm -&gt; PKG_LIST_BASE_LIVRSIMPL

  PROCEDURE setParams ( pTipData  IN INTEGER,
                        pDataS    IN VARCHAR2,
                        pDataF    IN VARCHAR2,
                        pAllGest  IN INTEGER DEFAULT 1,
                        pAllArt   IN INTEGER DEFAULT 1,
                        pAllDoc   IN INTEGER DEFAULT 1,
                        pUM       IN INTEGER DEFAULT 0,
                        pExtra1   IN INTEGER DEFAULT 0,
                        pExtra2   IN INTEGER DEFAULT 0,
                        pExtra3   IN INTEGER DEFAULT 0,
                        pExtra4   IN INTEGER DEFAULT 0,
                        v_CodJob1 IN NUMBER  DEFAULT 0);

  FUNCTION ToateGest RETURN BOOLEAN;
  FUNCTION ToateArt  RETURN BOOLEAN;
  FUNCTION ToateDoc  RETURN BOOLEAN;
  FUNCTION TipData   RETURN INTEGER;
  FUNCTION Perioada  RETURN VARCHAR2;
  FUNCTION Um        RETURN INTEGER;
  FUNCTION Extra1    RETURN BOOLEAN;
  FUNCTION Extra2    RETURN BOOLEAN;
  FUNCTION Extra3    RETURN BOOLEAN;
  FUNCTION Extra4    RETURN BOOLEAN;

END PKG_LIST_SELLIVRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELMOMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11E060B45AA1E4C5FD32366710463C7797106560</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selmoment IS

PROCEDURE setAllParams(pTip     IN NUMBER   DEFAULT 0,
											 pDataRef IN VARCHAR2 DEFAULT NULL,
                       pExtra1  IN BOOLEAN  DEFAULT FALSE);

FUNCTION GetTip     RETURN NUMBER;
FUNCTION GetDataRef RETURN DATE;
FUNCTION Extra1     RETURN BOOLEAN;

end PKG_LIST_SELMOMENT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22A42C166F30CE8A17638E4F50FB2EF34F1E1097</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELPART IS
  PROCEDURE setParam (pAllPart NUMBER);
  FUNCTION  IsAllPart RETURN BOOLEAN;
END pkg_list_selpart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELPARTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10882B38E15D7499C63BCFB77CEEBE913D43DA68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELPARTART IS
  PROCEDURE setParam (pAnLunaIni NUMBER, pAnLunaFin NUMBER, pAllPart NUMBER, pAllArt NUMBER, pExtra1 NUMBER DEFAULT 0, pExtra2 NUMBER DEFAULT 0);
  FUNCTION  AnLunaIni RETURN NUMBER;
  FUNCTION  ANLunaFin RETURN NUMBER;
  FUNCTION  IsAllArt  RETURN BOOLEAN;
  FUNCTION  IsAllPart RETURN BOOLEAN;
  FUNCTION  IsExtra1  RETURN BOOLEAN;
  FUNCTION  IsExtra2  RETURN BOOLEAN;
END PKG_LIST_SELPARTART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELPERAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9ADA737501625B10823CD8C99D0D8991FC0F2F6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELPERAGENT IS

  PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                        pDataIni    IN VARCHAR2 DEFAULT NULL,
                        pDataFin    IN VARCHAR2 DEFAULT NULL,
                        pLunaAnIni  IN INTEGER  DEFAULT 0,
                        pLunaAnFin  IN INTEGER  DEFAULT 0,
                        pAllAgent   IN NUMBER   DEFAULT 1,
                        v_CODJOB1   IN NUMBER   DEFAULT 0 );

  FUNCTION DupaData     RETURN BOOLEAN;
  FUNCTION DataIni      RETURN DATE;
  FUNCTION DataFin      RETURN DATE;
  FUNCTION LunaAnIni    RETURN INTEGER;
  FUNCTION LunaAnFin    RETURN INTEGER;
  FUNCTION TotiAgentii  RETURN BOOLEAN;

end pkg_list_selperagent;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELPERART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E375B556602A8C9AB17500F3931440A59162497E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_selperart IS

  PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                        pDataIni    IN VARCHAR2 DEFAULT NULL,
                        pDataFin    IN VARCHAR2 DEFAULT NULL,
                        pLunaAnIni  IN INTEGER  DEFAULT 0,
                        pLunaAnFin  IN INTEGER  DEFAULT 0,
                        pFiltruArt  IN INTEGER  DEFAULT 0,
                        pExtra1     IN NUMBER   DEFAULT 0,
                        v_CODJOB1   IN NUMBER   DEFAULT 0 );

  FUNCTION DupaData     RETURN BOOLEAN;
  FUNCTION DataIni      RETURN DATE;
  FUNCTION DataFin      RETURN DATE;
  FUNCTION LunaAnIni    RETURN INTEGER;
  FUNCTION LunaAnFin    RETURN INTEGER;
  FUNCTION FiltruArt    RETURN INTEGER;
  FUNCTION Extra1       RETURN BOOLEAN;

end PKG_LIST_SELPERART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELSITART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A796712CACD3D242A5D3DC93573AC024EC297D8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELSITART IS

  PROCEDURE SETPARAMS(
    pFaraData IN NUMBER   DEFAULT 1,
    pDataS    IN VARCHAR2 DEFAULT NULL,
    pDataF    IN VARCHAR2 DEFAULT NULL,
    pToateArt IN NUMBER   DEFAULT 1,
    pTotiPart IN NUMBER   DEFAULT 1,
    pToateDoc IN NUMBER   DEFAULT 1 ,
    V_CODJOB1 IN NUMBER   DEFAULT 0
  );
  FUNCTION Perioada RETURN VARCHAR2;
  FUNCTION ToateArt RETURN BOOLEAN;
  FUNCTION TotiPart RETURN BOOLEAN;
  FUNCTION ToateDoc RETURN BOOLEAN;

end PKG_LIST_SELSITART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELTRAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>702D5923EC5473887AF768E12D0A983E17D487C9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELTRAS IS

--BAGAT TOTI PARAMETRII PE O SINGURA PROCEDURA
TYPE crs IS REF CURSOR;
PROCEDURE setAllParams(v_dataini    IN VARCHAR2,
                       v_dataFin    IN VARCHAR2,
											 v_flgGest    IN NUMBER   DEFAULT 1,
											 v_flgTipCont IN NUMBER   DEFAULT 1,
											 v_flgSICentr IN NUMBER   DEFAULT 1,
                       v_CodJob1    IN NUMBER   DEFAULT 0);

FUNCTION getDataIni      RETURN DATE;
FUNCTION getDataFin      RETURN DATE;
FUNCTION GetInterval     RETURN VARCHAR2;
FUNCTION isAllTipCont    RETURN BOOLEAN;
FUNCTION isAllGest       RETURN BOOLEAN;
FUNCTION isSICentralizat RETURN BOOLEAN;

END PKG_LIST_SELTRAS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELURMDOCPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39B689D226E4331D3A0D12E0F990F1AED6E214E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELURMDOCPART IS

  PROCEDURE SETPARAMS( p_CodPArt    IN NUMBER,
                       p_NrDoc      IN NUMBER,
                       p_DataDoc    IN VARCHAR2,
                       pCodJob1     IN NUMBER   DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2) ;
  
  FUNCTION CodPart   RETURN NPART.CODPART%TYPE;
  FUNCTION NrDoc     RETURN IESIRI.NRDOC%TYPE;
  FUNCTION DataDoc   RETURN IESIRI.DATADOC%TYPE;


end PKG_LIST_SELUrmDocPart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELURMOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED9BB284A64958A60EA87D035B5AD30C2A8863DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELURMOFE IS

  -- 21.03.2008 - STEF - Selectie Perioada -- MIscari -&gt; sitPred.,sitCons.

  PROCEDURE SETPARAMS(  pDataIni     IN VARCHAR2 DEFAULT NULL,
                        pDataFin     IN VARCHAR2 DEFAULT NULL,
                        pTotiPart    IN NUMBER   DEFAULT 1 ,
                        V_CODJOB1 IN NUMBER  DEFAULT 0
                      );
  FUNCTION DataIni   RETURN DATE;
  FUNCTION DataFin   RETURN DATE;
  FUNCTION TotiPart  RETURN BOOLEAN;


END PKG_LIST_SELURMOFE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_SELUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31B6F094AA8E09A9332AC47BF59B68BAA8A08DDC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_SELUTILAJE IS

  PROCEDURE setParams(
                      pAllUtilaje     IN NUMBER   DEFAULT 1,
                      pAllInterventii IN NUMBER   DEFAULT 1,
                      pExtra1         IN NUMBER   DEFAULT 0,
                      pPerDataInterv  IN NUMBER   DEFAULT 0,
                      pAllTipUtilaje  IN NUMBER   DEFAULT 1,
                      pDataIni        IN VARCHAR2,
                      pDataFin        IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0);

  FUNCTION IsAllUtilaje     RETURN BOOLEAN;
  FUNCTION IsAllTipUtilaje  RETURN NUMBER;
  FUNCTION IsAllInterventii RETURN BOOLEAN;
  FUNCTION IsExtra1 RETURN BOOLEAN;
  FUNCTION PerDataInterv RETURN NUMBER;
  FUNCTION DataIni RETURN VARCHAR2;
  FUNCTION DataFin RETURN VARCHAR2;

END pkg_list_selutilaje; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_STRUCT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0DBE52B37B5D85B2E9C2EAEB049BD18D887A3595</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LIST_STRUCT IS
  type crs  is ref cursor;

  PROCEDURE StartSuplCols;
  PROCEDURE AddSuplTabs (aSuplCols IN OUT VARCHAR2, aTable IN VARCHAR2, aAlias IN VARCHAR2, aJoinCond IN VARCHAR2, aFORCEVALID IN NUMBER DEFAULT 0, aCUSTOMLST IN NUMBER DEFAULT 0);
  PROCEDURE AddSuplView (aSuplCols IN OUT CLOB, aView  IN CLOB    , aAlias IN VARCHAR2, aJoinCond IN VARCHAR2, aFORCEVALID IN NUMBER DEFAULT 0, aCUSTOMLST IN NUMBER DEFAULT 0);
  PROCEDURE GetSuplCols (alistid IN NUMBER, alistver IN NUMBER, sFields OUT CLOB, sAlias OUT CLOB, sNullAlias OUT CLOB, sJoin OUT CLOB, gSuplCols IN CLOB);
  PROCEDURE SetTableSpec (p_TableSpec IN VARCHAR2);
  PROCEDURE SetTableSpecRezerva (p_TableSpec IN VARCHAR2) ;
  PROCEDURE SetTableSpecFROMRezerva ;
  PROCEDURE AdunaColoanele;
  PROCEDURE ValideazaSuplCols(aListID IN NUMBER, aListVer IN NUMBER,aSuplCols IN VARCHAR2);
  FUNCTION  GET_VIEW_COLS(aViewName varchar2) return crs;

  PROCEDURE GenerateTMP (
    tmpName  IN VARCHAR2,
    listCols IN VARCHAR2,
    UserName IN VARCHAR2,
    plusCol1 IN VARCHAR2 DEFAULT NULL,
    plusCol2 IN VARCHAR2 DEFAULT NULL,
    plusCol3 IN VARCHAR2 DEFAULT NULL,
    plusCol4 IN VARCHAR2 DEFAULT NULL);
  PROCEDURE AlterTMP (tmpName IN VARCHAR2,listCols IN VARCHAR2, SuplCols IN VARCHAR2);
  FUNCTION  list_counter RETURN NUMBER;
  PROCEDURE DropTbl (tmpName IN VARCHAR2, Do1 integer default 1, Do2 integer default 1, Do3 integer default 1, Do4 integer default 1);
  FUNCTION  getCreateTemp (tmpName IN VARCHAR2) RETURN VARCHAR2;
  FUNCTION  TmpExists (tmpName IN Varchar2) RETURN NUMBER;
  FUNCTION  ColExists (TabName IN VARCHAR2, ColName IN VARCHAR2) RETURN NUMBER;

  PROCEDURE SPLIT_COLUMN(tbl_name in varchar2,col_name in varchar2,sep in varchar2,tmp_name in varchar2);

  FUNCTION getTimeStamp(aObject IN VARCHAR2) RETURN VARCHAR2;

  PROCEDURE ADD_CONFIG_DINAMIC_COLS(ALISTID IN NUMBER, ALISTVER IN NUMBER, PREFIX IN VARCHAR2, MAXIM IN NUMBER);

  FUNCTION SaveLista( aSaveTable in varchar2, aListTable in varchar2 ,sUserName in varchar2, iCodFirma in number ) RETURN NUMBER;

  PROCEDURE GOLESTE_PARAM;
  PROCEDURE ADAUGA_PARAM (pDenumire VARCHAR2, pValoare VARCHAR2);
  PROCEDURE ADAUGA_PARAM_EXT (pTable VARCHAR2, pField VARCHAR2, pValField NUMBER, pPrefix VARCHAR2 default &apos;&apos;);
  FUNCTION  GET_PARAM RETURN crs;
  function GetCursorForCols(aSQL in varchar2) return crs;
  PROCEDURE GeneratePIV (tmpName  IN VARCHAR2,  CMD IN VARCHAR2,  UserName IN VARCHAR2);
  procedure adunaColoaneleXView (pViewName in VARCHAR2);

END pkg_list_Struct;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LIST_UTILFISACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA56DCCEA0A5BB3C7A6C62306B1FCA3F42719F77</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_list_utilfisacont IS

  PROCEDURE UMPLE_TMP_LST_JURNAL1 (p_Plan IN NUMBER, p_LunaIni IN NUMBER, p_LunaFin IN NUMBER, p_SubCurenta IN NUMBER, p_ListId IN NUMBER);
  FUNCTION GET_BAZA (pTipBaza IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_INFOBAZA (pTipBaza IN NUMBER, pCodBaza IN NUMBER, pIndexLocal IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_DESCR (pTipCont IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_INFODESCR (pTipCont IN NUMBER, pCodDescr IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2;
  function GetDCJurnal(aCodJurnal in number) return timestamp;
  function GetPartJurnal(aCodJurnal in number) return number;
  function GetCodAutoStinse(aCodGeneral in number) return number;
  function GetObsDocJurnal(aCodJurnal in number) return varchar2;

END pkg_list_utilfisacont;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LOCALITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE86B162D5FF61936DFEA96803FA58D6E487C1EE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LOCALITATI IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_Localitati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4062667E3BB1CA0D93414B981A566F4161516F6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_LOCMUNCA IS

  function  GetDisponibilPeZi(aCodLoc in number) return number;
  procedure SaveGANTT;
  procedure PrepareGANTT(aData1 in varchar2, aData2 in varchar2, aDataStart in varchar2, aDataStop in varchar2, aCodProiect in number default 0, aCant in number default 0);
  procedure PrepareTMP_OREGANTT1(aData1 in varchar2, aData2 in varchar2);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_locmunca; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34E77A2D4048A960AC9EAB24D4182D213223E466</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MAIL IS




----------------------- Customizable Section -----------------------

-- Customize the SMTP host, port and your domain name below.

smtp_host     VARCHAR2(256);-- := &apos;webmail.winmentor.ro&apos;;
smtp_port     PLS_INTEGER;-- := 25;
smtp_domain   VARCHAR2(256);-- := &apos;winmentor.ro&apos;;
Smtp_Username VARCHAR2(256) := &apos;&apos;;
Smtp_Password VARCHAR2(256) := &apos;&apos;;

-- Posible values for smtp_authType as follows :
-- 1 = AUTH PLAIN
-- 2 = AUTH LOGIN
-- 3 = CRAM-MD5 / CRAM-SHA1

smtp_authType NUMBER (1):= 1;

SUCCESFULL_REPLY   CONSTANT NUMBER(3) := 235;
WAIT_FOR_COMMAND   CONSTANT NUMBER(3) := 334;

-- Customize the signature that will appear in the email&apos;s MIME header.
-- Useful for versioning.
MAILER_ID   CONSTANT VARCHAR2(256) := &apos;Mailer by Oracle UTL_SMTP&apos;;
--------------------- End Customizable Section ---------------------

-- A unique string that demarcates boundaries of parts in a multi-part email
-- The string should not appear inside the body of any part of the email.
-- Customize this if needed or generate this randomly dynamically.
--BOUNDARY CONSTANT VARCHAR2(256) := &apos;-----7D81B75CCC90D2974F7A1CBD&apos;;
BOUNDARY CONSTANT VARCHAR2(256)       := &apos;----=*#abc1234321cba#*=&apos;;
FIRST_BOUNDARY CONSTANT VARCHAR2(256) := &apos;--&apos; || BOUNDARY || utl_tcp.CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256)  := &apos;--&apos; || BOUNDARY || &apos;--&apos; || utl_tcp.CRLF;

-- A MIME type that denotes multi-part email (MIME) messages.
MULTIPART_MIME_TYPE   CONSTANT VARCHAR2(256) := &apos;multipart/mixed; boundary=&quot;&apos;|| BOUNDARY || &apos;&quot;&apos;;
MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER   := 76 / 4 * 3;

-- A simple email API for sending email in plain text in a single call.
-- The format of an email address is one of these:
-- someone@some-domain
-- &quot;Someone at some domain&quot; someone@some-domain
-- Someone at some domain someone@some-domain
-- The recipients is a list of email addresses separated by
-- either a &quot;,&quot; or a &quot;;&quot;

PROCEDURE mail(sender IN VARCHAR2, recipients IN VARCHAR2, subject IN VARCHAR2, message IN VARCHAR2);

-- Extended email API to send email in HTML or plain text with no size limit.
-- First, begin the email by begin_mail(). Then, call write_text() repeatedly
-- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
-- email in non-ASCII or multi-byte character set. End the email with
-- end_mail().

FUNCTION begin_mail(sender IN VARCHAR2, recipients IN VARCHAR2, subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection;

-- Write email body in ASCII
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection, message IN VARCHAR2);

-- Write email body in non-ASCII (including multi-byte). The email body
-- will be sent in the database character set.
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection, message IN VARCHAR2);

-- Write email body in binary
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection, message IN RAW);

-- APIs to send email with attachments. Attachments are sent by sending
-- emails in &quot;multipart/mixed&quot; MIME format. Specify that MIME format when
-- beginning an email with begin_mail().
-- Send a single text attachment.

PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection, data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL, last IN BOOLEAN DEFAULT FALSE);

PROCEDURE attach_mb_text(conn IN OUT NOCOPY utl_smtp.connection, data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL, last IN BOOLEAN DEFAULT FALSE);

-- Send a binary attachment. The attachment will be encoded in Base-64
-- encoding format.

PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW, mime_type IN VARCHAR2 DEFAULT &apos;application/octet&apos;,
inline IN BOOLEAN DEFAULT TRUE, filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);

-- Send an attachment with no size limit. First, begin the attachment
-- with begin_attachment(). Then, call write_text repeatedly to send
-- the attachment piece-by-piece. If the attachment is text-based but
-- in non-ASCII or multi-byte character set, use write_mb_text() instead.
-- To send binary attachment, the binary content should first be
-- encoded in Base-64 encoding format using the demo package for 8i,
-- or the native one in 9i. End the attachment with end_attachment.

PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;,
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL);

-- End the attachment.

PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection, last IN BOOLEAN DEFAULT FALSE);

-- End the email.

PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);

-- Extended email API to send multiple emails in a session for better
-- performance. First, begin an email session with begin_session.
-- Then, begin each email with a session by calling begin_mail_in_session
-- instead of begin_mail. End the email with end_mail_in_session instead
-- of end_mail. End the email session by end_session.

FUNCTION begin_session RETURN utl_smtp.connection;

-- Begin an email in a session.

PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection, sender IN VARCHAR2,
recipients IN VARCHAR2, subject IN VARCHAR2, mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;,
priority IN PLS_INTEGER DEFAULT NULL);

-- End an email in a session.

PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);

-- End an email session.

PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
---------

procedure SetCustomParams ( aSmtp_host in varchar2,
                            iSmtp_port in pls_integer,
                            aSmtp_domain in varchar2,
                            auth_type in number,
                            aSmtp_Username in varchar2,
                            aSmtp_Password in varchar2);

procedure Send_mail(aSender in varchar2,
                    vRecipients in varchar2,
                    vSubject in varchar2,
                    vMessage in varchar2,
                    vMailID in number);

function test_mail_data return varchar2;
procedure test;

FUNCTION SENDMAIL_BY_SERVICE(ServerMail IN VARCHAR2,
                             Port IN NUMBER,
                             FromAddress IN VARCHAR2,
                             UserName IN VARCHAR2,
                             Password IN VARCHAR2,
                             SUBJECT IN VARCHAR2,
                             ToAddress IN VARCHAR2,
                             Message in VARCHAR2
                            ) RETURN NUMBER;


end;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MAIL_UTILS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F6CE81987753359F9A77BB8BFBAA17CA053093D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MAIL_UTILS IS

procedure ResendMail(aCod in number);
PROCEDURE PostRecord_mail;
procedure prepare_mail(iCodServer in number, ZileAfter in number, Instant in number  default 0);
procedure DoTheJob(aMailID in number, FaraCommit in number default 0);
function GetCurrentUserMail return varchar2;
procedure PostDocumente(aCodDoc in number, aTipDoc in number,aOwner in varchar2);
procedure GetDocumente (aCodDoc in number, aTipDoc in number,aOwner in varchar2);
procedure TestSendEmail;
function TestUserMail (aCodUser in number, aCodGrup in number, aCodFirma in number) return varchar2;
function SendMailFromTrigger(Subject in varchar2, Message in varchar2, ToAddress in varchar2) return number;

end pkg_mail_utils; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MASCASERART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2D319A7F55C981165EA1DFB1B8FF37CBEE3273D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MASCASERART is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_MASCASERART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MEDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0AD98D12E7F80F76C10D6771E4C7A73BD6359AD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MEDEX IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION GetCompensare(CIM in varchar2, DataStart in date) return VARCHAR2;
  FUNCTION GetCompensareS(CIM in varchar2, DataStart in varchar2) return VARCHAR2;
  function ListaActuala(DataStart in Date) return number;
  FUNCTION Med1Valid(aCodMedex1 IN NUMBER) RETURN NUMBER;
  FUNCTION Med2Valid(aCodMedex2 IN NUMBER) RETURN NUMBER;

end pkg_medex; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MENUDASH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3CEF48D43CDEBF5C47F5669CC44254C98B45C1D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MENUDASH IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  
end pkg_menuDASH; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MENUDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD1B9B4FAFAFE05E452FE795D32B020339F41CA2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MENUDATE IS

  
  TYPE CRS IS REF CURSOR;
  
  FUNCTION GETBUTOANE(nrBtn in number) RETURN CRS;
  FUNCTION GETUSERMENU RETURN CRS;
  
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  
  

end pkg_menudate; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MESE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DA1DBFAEB025A88457B949B783A89ED92758278</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MESE is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_MESE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA19FD10BF97B2B21A934B345A6B7240EF8C2FFE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MFCLASIF IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_MFCLASIF; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EC5549266CBF20B029C20A184A458EF3F12066C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MIFIX IS

  function GETNRINVENTARNS(aCODNIRSTOC in number, aCODNIRSER in number) return number;
  function GETNRINVENTARNS_EXT(aCODNIRSTOC in number, aCODNIRSER in number) return varchar2;


  procedure PROPAGANEXT(aCodMifix in number, Tip in number);
  procedure empty_mifix_temptables;
  procedure GenMasterMifixDinReevaluare(aCodNirStoc in number);
  procedure InConservare(aCodMifix1 in number);
  procedure Vindere(aCodMifix1 in number, aCodIes in number);
  procedure Casare(aCodMifix1 in number, aCodIes in number);
  procedure UPDATEMIFIXSTRUCT(aCodNirStocVechi in number, aCodNirStocNou in number, aCodMifix1 in number,
                              aCodCentru in number, aAn in number, aLuna in number, aCodClasif in number,
                              aStare in number, aTipOperatie in number);
  procedure NewFisaMFFromTransf(aCodNirStoc in number, aCodMifix in number, aCodOperatie in number);
  function NEWMIFIX(aCodNirStoc in number, aCodClasif in number, aCodCentru in number, aNrInventar in number, aAn in number, aLuna in number) return number;
  PROCEDURE LOCKNUMARINV(aTIP IN VARCHAR2, aNUMARINV IN NUMBER);
  PROCEDURE UNLOCKNRINV;
  FUNCTION  GETNEXTNRINV(aTIP IN VARCHAR2) RETURN NUMBER;
  FUNCTION  GetINFOMFIMB(aCodMifixImb IN NUMBER) RETURN VARCHAR2;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;


  PROCEDURE SP_GOTORECORD_FOR_REEVAL(aCODNIRSTOC IN NUMBER);
  PROCEDURE SP_POST_REEVAL(DATADOC IN VARCHAR2, TIP IN NUMBER, aCODDOC1 IN NUMBER, aTIPDOC IN NUMBER);
  procedure make_mifix;
  procedure CasareFaraCommit(aCodMifix1 in number, aCodIes in number);
  procedure GenMFNoi(
    aCodNirStoc in number,
    aCodObiect in number,
    aGest in number,
    aCodIOArt in number,
    aCodClasif in number,
    aValoare in number,
    aCant in number,
    aCarnetDim in number,
    aSeriaDim in varchar2,
    aNrDim in number,
    aDataDim in varchar2,
    aCarnetMar in number,
    aSeriaMar in varchar2,
    aNrMar in number,
    aDataMar in varchar2,
    aSerieStart in varchar2,
    aInc in number,
    aCarnetDimLivr in number,
    aSeriaDimLivr in varchar2,
    aNrDimLivr in number,
    aDataDimLivr in varchar2,
    aCarnetMarLivr in number,
    aSeriaMarLivr in varchar2,
    aNrMarLivr in number,
    aDataMarLivr in varchar2,
    aNrInv in number
    );
  procedure NEWMIFIXFARACOMMIT(aCodNirStoc in number, aCodClasif in number, aCodCentru in number, aNrInventar in number, aAn in number, aLuna in number);

end PKG_MIFIX;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MISCARI_INTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB007E5A9733AF96789059BD443C1FA869C5489F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MISCARI_INTERNE IS

 -- memoreaza CARNETDOC si NRDOC la intrarea pe macheta
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  vCODMIFIX   NUMBER(20) := 0;
  v$Session_LivrDinRezTransf NUMBER(1) := 0;
  
  
  PROCEDURE SET_Session_LivrDinRezTransf(aFlag in number);
  PROCEDURE SETCODMIFIX(aCodMifix in number);
  procedure SetSkipMifix(aSkip in boolean);
  procedure SetDoCommit(aDoCommit in boolean);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  FUNCTION NR_LIVRARI_DIN_NIRTRANSF(aCODTRANSF IN NUMBER) RETURN NUMBER;
  FUNCTION STOCNEG_LA_STERG_TRANSF_ROSU(aCODTRANSF IN NUMBER) RETURN NUMBER;
  FUNCTION STOC_NEG_LIVR1_TRANSF_ROSU(aCODLIVR1 IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RECID OUT NUMBER );
  PROCEDURE EMPTY_TRANSF_TEMPTABLES;

  FUNCTION GETCURSORIGINAL(ANIRSTOCPARINTE IN NUMBER) RETURN NUMBER;
  PROCEDURE CHECK_REZERVARI(CODNIRSTOC_SURSA IN NUMBER, CODNIRSER_SURSA  IN NUMBER, CODNIRSTOC_DEST IN NUMBER, CODNIRSER_DEST IN NUMBER, aCANT IN NUMBER);
  PROCEDURE SOLVE_OBINV(aCODTRANSF IN NUMBER, aCODCLASIF IN NUMBER );
  PROCEDURE SOLVE_MIFIX(aCODTRANSF IN NUMBER);
  PROCEDURE CHECK_COERENTA_MODIPRET_MF(aCODDOC IN NUMBER);


end PKG_MISCARI_INTERNE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MODIF_CENTRE_COST_X_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4684464D62B34CD3A6EB6CF0DA89DCF225E0120</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MODIF_CENTRE_COST_X_DOC is

  procedure actualizareCentreCost(pDataStart     IN VARCHAR2,
                                  pDataEnd       IN VARCHAR2,
                                  centruCostIni  IN Number,
                                  centruCostNew  IN Number,
                                  pCodGest       IN Number default null,
                                  pCodAnalizaNod IN Number default null);

end PKG_MODIF_CENTRE_COST_X_DOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MONEDE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59D0173F04EF76477121FE281914F3C4C8A0C9EB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MONEDE IS
--  g_codmoneda1 NUMBER(18) := 0; 
  MONEDACURENTA NUMBER(20);
 
  FUNCTION GETDATACURS(aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATADOC IN DATE, aCURS IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SET_MONEDA_CURENTA(aCodMoneda IN NUMBER);
  FUNCTION GET_MONEDA_CURENTA RETURN NUMBER;
  FUNCTION MONEDA_VALIDA(aCODMONEDA IN NUMBER) RETURN NUMBER;
  FUNCTION TESTUNICITATESIMBOL(aSimbol IN VARCHAR2, aCODMONEDA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_SIMBOL_MONEDA(aCodMoneda IN NUMBER) RETURN VARCHAR2;
  
  FUNCTION GETCURSMONEDA(aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA VARCHAR2) RETURN NUMBER;
   
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ); 
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ); 
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ); 
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE UPDATE_PRETM_CURS ( p_simbol_banca nbank.simbol%TYPE );
   
END pkg_Monede; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MOTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7EED967939938063418A5F6B7145699BBDE6BD5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MOTIVE IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_MOTIVE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_MOTIVEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A6DF2FE9DAE01E8CA3C4B429297EB0D770D9228</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_MOTIVEP is

  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;

end PKG_MOTIVEP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3C4268DF774250F77347F35DACDF6E7A84AE880</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NC IS
--  g_CodNC1 NUMBER(18) := 0;
  FUNCTION VALOARE_GRUP_VALUTA(aVALGRUP IN NUMBER, aVALOARE IN NUMBER, aVALOARE_VALUTA IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE SP_POSTRECORDS_FROM_IMPORT(Operation IN NUMBER, RecId OUT NUMBER );
  procedure GenereazaModificareDePretMifix(aDataDoc in date, aAn in number, aLuna in number, aSubunitatea in number);

END pkg_NC;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCB025CA7F6EF0F681370852BA5247F652B148CE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NECESAR IS
  
  procedure UpdateLinieObj(aCodNecesar in number,
                           aCodObiect in number,
                           aAcceptat in number,
                           aAcceptatum1 in number,
                           aPLANIFPER in number,
                           aPLANIFPREC in number,
                           aStoc in number,
                           aStocmin in number,
                           aStocoptim in number,
                           aStocmax in number,
                           aREZERVAT in number,
                           aCC in number,
                           aCF in number,
                           aCIIES in number,
                           aCCPANALA in number,
                           aCIIESPANALA in number,
                           aPMP in number,
                           aValPMP in number,
                           aCFPER in number,
                           aNecesar in number,
                           aCFNext in number,
                           aPlanif in number,
                           aConsum in number,
                           aConsumPrec in number);
  procedure POSTNECESAR(RecIdOld in number,aCarnetDoc in number, aNrDoc in number, aSeriaDoc in varchar2, aDataDoc in varchar2, 
                        aObs in varchar2, aSaptamana in number, RecId out number, aTipNecesar in number, aSupliment in number);
  procedure DELETE(RecId in number);
  procedure UPDATECMDEXT(aCodNecesar in number, aField in varchar2, aCodComanda in number);                      

end pkg_necesar; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F204E6F94968543A86CB83E579897F68C4CCB8D7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NIMOB IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_NIMOB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NMESERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AEF9F1F5AE52EF4A5261B2A672AB65BCB42BD54</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NMESERII IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_nmeserii; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NMVS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>80879FFAF37C1DAC3CB91A128E88597DCAC3F0D1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_nmvs is

procedure InsertNMVS(aGTIN in varchar2, aLot in varchar2, aExp in varchar2, aSN in varchar2, aSkemeType in varchar2, aNewCodNMVS out number);
procedure UpdateNMVS(aCodNMVS in number, aRaspuns in varchar2, aCodRaspuns in varchar2, aStatus in varchar2, aMotiv in varchar2, 
                     aFunctie in varchar2, aSkemeType in varchar2, aGLN in varchar2, aNewCodNMVS out number);
PROCEDURE GETRECORDS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER);
PROCEDURE POSTRECORDS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER);
  
 
end pkg_nmvs; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C1066DB98B98459A4709EC0B0A438BF09D43008</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMACTIVIT IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_NomActivit; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMATRIBUTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>375085A65A693E2105CB8AAEB0403DFFCFE4B5C0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMATRIBUTE IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION AM_DATE_NARTOBJATR (
    vTip IN NUMBER DEFAULT 0, -- 0 FULL, 1 ARTICOL, 2 ATRIBUT
    vCod IN NUMBER DEFAULT 0
  ) RETURN NUMBER;
  PROCEDURE REPARA_NARTOBJATR(
    vTip IN NUMBER DEFAULT 0, -- 0 SMART, 1 FULL, 2 ARTICOL
    vCod IN NUMBER DEFAULT 0
  );
  PROCEDURE AddNewValAtrib(NewVal IN VarChar2, RecId in NUMBER, aCod OUT NUMBER );
END pkg_NomAtribute;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMAUTORIZATIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B7BC5B8A05ABB185F70E48FBA06399C02D8B73C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMAUTORIZATIIAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_nomAUTORIZATIIauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMCARSUPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A0B9909219C63C1FE3C9011F53694A9C6C5314B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMCARSUPART IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  function get_code(den in varchar2) return number;
  function IsUnicat(den in varchar2) return number;
  procedure BAGA_DCI(aDCI in varchar2, aCod out number);

end PKG_NOMCARSUPART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMCASEMARCAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41293F76660115CC46226B8FE6E8B32321CD8BFE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMCASEMARCAT IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION TEST_UNICITATE_NUMAR(NrLogic IN NUMBER, Cod IN NUMBER) RETURN NUMBER;
end pkg_nomcasemarcat; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMELEMAEROAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7785AC4DFCD3470ED032D08544AA03CD0B098AA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMELEMAEROAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nomelemaeroauto; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49482BDD0CFB35C815EFCE6C6373CB3A9BB6381C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMGEST IS


  GEST_CURENTA_LOCATII NUMBER(20) := 0;
  Locatia_CURENTA NUMBER(20) := 0;
  FUNCTION GETCODCARACTLUNA(aCODGEST IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER;
  PROCEDURE SET_GEST_CURENTA_LOCATII(aGEST IN NUMBER, aLoc IN NUMBER);
  FUNCTION  GET_GEST_CURENTA_LOCATII RETURN NUMBER;
  FUNCTION  GET_Locatia_CURENTA RETURN NUMBER;

  GEST_FILTRU_GENERATOR NUMBER(20) := 0;
  PROCEDURE SET_GEST_FILTRU_GENERATOR(aGEST IN NUMBER);
  FUNCTION GESTIUNE_FILTRU_VALIDA(aCODGEST IN NUMBER) RETURN NUMBER;
  FUNCTION GET_SUBUNIT_GEST(aCODGEST IN NUMBER) RETURN NUMBER;

  FUNCTION GESTIUNE_DEDICATA(aCODGEST IN NUMBER) RETURN NUMBER;
  FUNCTION GET_DEN_LOCATIE(aCODLOCATIE IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  function GetCoefSectie(aCodGest in number) return number;
END pkg_NomGest;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6A4DFF977AF2D0FAA261BF3F3080AC04A2231E0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMGRUPEAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nomgrupeauto; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F343B71C5EC627F66F69F872A1E80DC5A4EA9A2D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMINSTAUTO IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_nominstauto; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41255386E102F79F5EE959BC7428CEB36CE2E950</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMINTERVENTIIAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nominterventiiauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMLOCATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2416047426BAE0A33A4395FAB0C180BCF1D0B1B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMLOCATII IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_NOMLOCATII ; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>259E2F60BB78393C5BB77F79451A4D64296E04C9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMMARCIAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nommarciauto; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BB01E08D2609A549C5E2A6E6A74726F912FF2CE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_nommodeleauto IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nommodeleauto;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9FFE241DCA053D956C6564DCCFF47CC94FCB542B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMPART IS
  TYPE DESCR_CONT_LUNA_CURSOR IS REF CURSOR;
  TYPE Fact_CURSOR IS REF CURSOR;

  PARTENER_CURENT NUMBER(20) := 0;
-- se seteaza inaintea apelarii view_ului v_soldpart;

-- daca e zero VIEW_ul va contine soldurile lunare ale tuturor partenerilor
-- daca e diferit de 0 va contine soldurile partenerului cu acel cod
  PARTENER_SOLD_ANALIZAT NUMBER(20) := 0;

 -- pentru VIEW-ul cu codurui fiscale partener;
  PARTENER_CURENT_CF NUMBER(20) := 0;

  PART_DOC_ROSU NUMBER(20) := 0;

   -- pentru VIEW-ul cu LOCATII partener;
  PARTENER_CURENT_LOCATII NUMBER(20) := 0;
  PARTENER_ICONT_ANALIZAT NUMBER(20) := 0;

  PARTENER_EDITAT NUMBER(20) := 0;


  CLASA_PART NUMBER(20)      := 0;
  TIPSERV_CURENT NUMBER(20)  := 0;

  PROCEDURE Set_Stopaj_Salarii;

  PROCEDURE SETCLASAPART(aCLASA IN NUMBER);
  FUNCTION CONDITIECLASA(aCLASA IN NUMBER) RETURN NUMBER;

  FUNCTION GET_SUBUNIT_GEST(aCODGEST IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_CODPART_SOLD_ANALIZAT(aCODPART IN NUMBER);
  FUNCTION  CODPART_SOLD_ANALIZAT_VALID(aCODPART IN NUMBER) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  FUNCTION GET_COD_NPART1(aCodPart in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_PART_COD_CARACT_LUNA(aCodPart in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_RECORD_PART_CARACT_LUNA(aCodPart IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN DESCR_CONT_LUNA_CURSOR;

  PROCEDURE SET_PART_CURENT(aCODPART IN NUMBER);
  FUNCTION  GET_PART_CURENT RETURN NUMBER;
  FUNCTION GET_DENPART(aCodPart IN NUMBER) RETURN VARCHAR2;

  PROCEDURE SET_PART_DOCROSU(aCODPART IN NUMBER);
  FUNCTION  GET_PART_DOCROSU RETURN NUMBER;
  FUNCTION  PART_DOCROSU_VALID(aCODPART IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_PART_CURENT_CF(aCODPART IN NUMBER);
  FUNCTION  GET_PART_CURENT_CF RETURN NUMBER;

  PROCEDURE SET_PART_CURENT_LOCATII(aCODPART IN NUMBER);
  FUNCTION  GET_PART_CURENT_LOCATII RETURN NUMBER;

  PROCEDURE SET_PART_ICONT_ANALIZAT(aICONT IN NUMBER);
  FUNCTION GET_PART_ICONT_ANALIZAT RETURN NUMBER;

  PROCEDURE SET_PART_EDITAT(aCODPART IN NUMBER);
  FUNCTION CODPART_PART_EDITAT_VALID(aCODPART IN NUMBER) RETURN NUMBER;
  FUNCTION COD_EXTERN_UNIC(aCODPART IN NUMBER, aCODEXTERN IN VARCHAR2) RETURN NUMBER;
  FUNCTION COD_INTERN_UNIC(aCODPART IN NUMBER, aCODINTERN IN VARCHAR2) RETURN NUMBER;
  FUNCTION COD_FISCAL_UNIC(aCODPART IN NUMBER, aCODFISCAL IN VARCHAR2, aPartener OUT VARCHAR2) RETURN NUMBER;
  PROCEDURE MAKE_CURS_GENERAL_LUNA(aDATA IN VARCHAR2);
  PROCEDURE MAKE_CURS_MONEDA_LUNA(aDATA IN VARCHAR2);

  PROCEDURE SET_TIPSERVIRE_LOCATII(aTipServire IN NUMBER);
  FUNCTION  TIPSERVIRE_LOCATII_OK (aModServire IN NUMBER) RETURN NUMBER;

  FUNCTION GET_Fact_Part(aCodPart IN NUMBER) RETURN Fact_CURSOR;
  FUNCTION GET_Fact_Furn(aCodPart IN NUMBER) RETURN Fact_CURSOR;

  FUNCTION STR_CODFISCAL(aCODFISCAL IN VARCHAR2) RETURN VARCHAR2;

  PROCEDURE REFRESH_OPORTUNITATI(aCodPart IN NUMBER);
  FUNCTION GET_PARTACTIVIT(aCodPart IN NUMBER) RETURN VARCHAR2;
  FUNCTION Clone_PART_As_Delegat(aCodPart in Number, aCodPartTR in Number) RETURN NUMBER;

  PROCEDURE DOSYNCPARTRETAIL(aCODPART IN NUMBER);
  PROCEDURE CHECKPART1CRM(aCodPart in number := 0);
  PROCEDURE MAKE_OBLIGPART_LA_ZI(aCodPart in number);

  FUNCTION TVALAINCASARE (aCodFiscal IN VARCHAR2, aDate IN varchar2 DEFAULT NULL) RETURN NUMBER;
  PROCEDURE PROPAGAGDPR;
  FUNCTION GETVOLTRANZCLI(aCodPart in number) return number;

  PROCEDURE StructuraANAF_CuiInit (pCUI NUMERIC, pData DATE DEFAULT NULL);
  PROCEDURE StructuraANAF_Sinc;

  PROCEDURE PartANAF_Init;
  PROCEDURE PartANAF_Sinc;
  PROCEDURE PartANAF_ActDen;
  PROCEDURE PartANAF_ActSedSoc;
  PROCEDURE PartANAF_ActNrRegCom;
  PROCEDURE PartANAF_ActRO;
  PROCEDURE PartANAF_ActSplitTVA;
  PROCEDURE PartANAF_ActRTVAI;
  PROCEDURE PartANAF_ActStareInactiv;

  procedure UpdateNPART1String(Camp in varchar, valoare in varchar2);
  procedure UpdateNPART1Double(Camp in varchar, valoare in number);
  procedure UpdateNPART1Integer(Camp in varchar, valoare in number);
  
  procedure UpdateNPART1CRMInteger(Camp in varchar, valoare in number, aDataStart in date);
  procedure UpdateNPART1CRMString(Camp in varchar, valoare in Varchar2, aDataStart in date);

END pkg_NomPart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>667C95D2AAB261CC53615A9E4472AD1D6270D1D2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMPERS IS
  TYPE LUNA_REF_CURSOR IS REF CURSOR;

  PERSOANA_CURENTA NUMBER(20)    := 0; -- folosita in VIEW_uri CONT_PERS_CURENT NUMBER (20) := 0; -- folosit pentru VIEW_uri in care aduc sold Pers
  ICONT_PERS_CURENT NUMBER (20)  := 0; -- folosita pentru VIEW_uri in care aduc sold Pers
  MONEDA_PERS_CURENT NUMBER (20) := 0; -- folosita pentru VIEW_uri in care aduc sold Pers

  FUNCTION GETDATAN(aCNP IN VARCHAR2) RETURN DATE;
  FUNCTION GET_NUMEPRENUME(ACODPERS IN NUMBER) RETURN VARCHAR2;
  PROCEDURE Set_PASSWORD(aCodPers IN NUMBER, aPass IN VARCHAR2);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  FUNCTION GET_COD_NPERS1(aCodPers IN NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_PERS_COD_CARACT_LUNA(aCodPers in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_RECORD_PERS_CARACT_LUNA(aCodPers IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor;

PROCEDURE SET_PERSOANA_CURENTA(aCODPERS IN NUMBER);
FUNCTION  GET_PERSOANA_CURENTA RETURN NUMBER;


PROCEDURE SET_ICONTPERS_CURENT(aICONT IN NUMBER);
FUNCTION  GET_ICONTPERS_CURENT RETURN NUMBER;

PROCEDURE SET_MONEDAPERS_CURENT(aMONEDA IN NUMBER);
FUNCTION  GET_MONEDAPERS_CURENT RETURN NUMBER;
procedure PROPAGADISCVALAG(aCodPers in number);

END pkg_NomPers;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMREMAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8FA0AA47C415D94B11F7F16BD42A3E5CD344794</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMREMAUTO IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end pkg_nomremauto; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMRESTAURANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A6BAADDA246B7C20B11FA5AF5B25F03E2554DAE3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMRESTAURANTE is
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER) ;
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );

end PKG_NOMRESTAURANTE;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F00510E70AE08F54F5C41A623595BABE1A493A92</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMSUBUNIT IS

  FUNCTION CATECARNETE (aCODSUBUNIT IN NUMBER) RETURN NUMBER;
  FUNCTION GenereazaCarnete (aCodSubunit in number) return number;

  FUNCTION getDenSubunit (aCod IN NUMBER) RETURN VARCHAR2;
  FUNCTION GET_COD_NSUBUNIT1(ACODSUBUNIT IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_SUBUNIT_COD_CARACT_LUNA(ACODSUBUNIT IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER, ACODIOFILIAL OUT NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_NomSubunit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMTAXE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C97259E9C97F69E919BF5399D1103B679ACB347D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMTAXE IS
--  g_CodTaxa1 NUMBER(18) := 0;

  FUNCTION GETCODCARACTLUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_NomTaxe;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOMTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>406DD9804C743700FAD38E96161DA3347BC9CBD7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOMTVA IS


  TYPE TVAURILUNA_CURSOR IS REF CURSOR;

  FUNCTION GETCURSORTVAURILUNA(AN IN NUMBER, LUNA IN NUMBER) RETURN TVAURILUNA_CURSOR;
  FUNCTION GETPROCTVALUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GETCODCARACTLUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_NomTva;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOM_ARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>458BD76944843ECD7FD75AB77FF19DAB21770FC6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOM_ARTICOL IS
  TYPE aPretM_Cursor IS REF CURSOR;

  procedure UmpleTmpStoc;
  procedure UpdateStocuri;
  procedure UPDATE_CONTSERV;
  PROCEDURE UPDATE_NARTOBJGEST(aZi in number, aCodGest in number, aCodObiect in number, aStoc in number);
  procedure UpdateImpSubunit;
  procedure UpdateObjImpSubunit;
  --procedure UpdateNArt1Integer(Camp in varchar, valoare in number, An in number, Luna in number); --STEF EXISTA DEJA o proc. UpdateNArt1Integer apelata din ModificValoriFrm iar pe xe se pare ca face figuri asa ca am comentat
  procedure UpdateNArt1Integer(Camp in varchar, valoare in number);
  function getcodobiectgeneric(aCodArticol in number) return number;
  procedure UpdateNArtObj1Double(Camp in varchar, valoare in number);
  procedure UpdateNArtObj1Integer(Camp in varchar, valoare in number);
  procedure UpdateNArtObj1String(Camp in varchar, valoare in varchar2);
  FUNCTION  SET_CODOBIECT_ANALIZAT(aCodObiect in number) RETURN VARCHAR2;
  FUNCTION  GET_CODOBIECT_ANALIZAT RETURN NUMBER;

  PROCEDURE MULTIPLICA_PRETURI(aCODOBIECT IN NUMBER,ACODSUBUNIT IN NUMBER, SUPRASCRIU_PRET_ZERO IN NUMBER, DoarCategSursa IN NUMBER);


  FUNCTION COD_EXTERN_UNIC(aCODOBIECT IN NUMBER, aCODEXTERN IN VARCHAR2, aCODUMP IN NUMBER) RETURN NUMBER;
  FUNCTION COD_EXTERN_UNIC_AMB(aCODAMB IN NUMBER, aCODOBIECT IN NUMBER, aCODUMSEC IN NUMBER, aCODEXTERN IN VARCHAR2) RETURN NUMBER;


  FUNCTION COD_INTERN_UNIC(aCODOBIECT IN NUMBER, aCODINTERN IN VARCHAR2) RETURN NUMBER;
  FUNCTION DENUMIRE_UNICA_OBIECT(aCODOBIECT IN NUMBER, aDENUMIRE IN VARCHAR2) RETURN NUMBER;
  FUNCTION DENUMIRE_UNICA_ARTICOL(aCODARTICOL IN NUMBER, aDENUMIRE IN VARCHAR2) RETURN NUMBER;
  FUNCTION COD_PLU_UNIC(aCODOBIECT IN NUMBER, aCODPLU IN NUMBER) RETURN NUMBER;
	PROCEDURE ACTUALIZEAZA_NARTCLI( aCodObiect    IN NUMBER,
																	aCodPart      IN NUMBER,
                                  aCodClaseP    IN NUMBER,
																	aDenumire     IN VARCHAR2,
																	aCodExtern    IN VARCHAR2,
                                  aCodLaClient  IN VARCHAR2,
																	aUMSec        IN NUMBER,
																	aTipCodAfisat IN NUMBER DEFAULT 1,
                                  aForceUpd     IN NUMBER DEFAULT NULL);

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION Get_Next_CodObiect1 RETURN NUMBER;

  FUNCTION VERIFICA_OBIECT_EXISTENT (aCODARTICOL IN NUMBER, aCodAtribut IN NUMBER, aCodProdus IN NUMBER, vCodAtribut OUT NUMBER) RETURN NUMBER;
  procedure CLONARE_PRETM_ATRIB(aCodObiect IN NUMBER, aCodSubunit IN NUMBER );
/*
  function CLONARE_GRUPA(aCodObiect IN NUMBER) RETURN VARCHAR2;
  function CLONARE_Majorare(aCodObiect IN NUMBER) RETURN NUMBER;
  function CLONARE_Get_PretM_Sursa(aCodObiect IN NUMBER, aCodSubunit IN NUMBER ) RETURN aPretM_Cursor ;
*/
  FUNCTION CLONEAZA_OBIECT(aCodArticol IN NUMBER, aCodAtribut IN NUMBER, vCodProdus IN NUMBER, vCodAtribut OUT NUMBER) RETURN NUMBER;

  FUNCTION EXPORT_PRETURI_PE_SUBUNIT RETURN NUMBER;

  PROCEDURE TMPORDINEGRUPEPRET;
  procedure debug;
  PROCEDURE TEST(Operation IN NUMBER);
  FUNCTION GetStrNARTOBJEXT(DeLa IN NUMBER) RETURN VARCHAR2;
  PROCEDURE  CloneazaNArtObjEXT(CODOBIECTGENERIC IN NUMBER, CODART IN NUMBER);

  FUNCTION  ANALIZA_IMPLICIT(IMPLICITSURSA       IN NUMBER,
                             DoarCategSursa      IN NUMBER,
                             CODCATSURSA         IN NUMBER,
                             CODCATDESTIMPLICITA IN NUMBER
                             ) RETURN NUMBER;


PROCEDURE PROPAGA_PRETURI_LA_SUBUNITATI;

PROCEDURE UPDATECodAlt(aCODOBIECT IN NUMBER, aCODALT IN VARCHAR2);
PROCEDURE EXPORTA_PRETURI(aCODCATIMPLICITA IN NUMBER);
PROCEDURE PROPAGAOPTIONALE(aCodSursa in number);
procedure UpdateDuriRet;
PROCEDURE CHECKMODIFPRETRETAIL(aCODOBIECT IN NUMBER);
procedure test2;
PROCEDURE COPIE_CATEG_PRETURI;
END pkg_Nom_Articol;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOM_PARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB3A47B14FE0373EC9E9A191C4F48A904E64D33A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_nom_parcaut IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION  AUTO_IMPLICAT_IN_TRANZACTII(aCODAUTO IN NUMBER) RETURN NUMBER;
  function getultimacitire(aCodNParcAut in number) return number;
  procedure UPDATE_AUT;
  procedure UPDATE_AUTO;
  procedure UPDATE_BORDAUTO;
  procedure EMPTY_NPARCAUT_TEMPTABLES;
  
end PKG_NOM_PARCAUT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F1355411902C48A18244EE915E858E85CFDA442</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NOTECREDIT IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);

  PROCEDURE RUPE(aCodNCFact in number);
  procedure UPDATE_RECORDS(aTipDoc in number, aCodDoc1 in number, aCodCentralizare in number, aNrDoc in number, aDataDoc in date, aValT in number, aOldPU in number);
  procedure ADAUGASTRUCT(aCodNCredit1 in number, aCodIes1 in number, aVal in number);
  procedure PreiaProcente;
  function GetDiscVolLinie(aCodDoc1 in number, aTipNC in number) RETURN NUMBER;
  function GetValDiscNCVol(aCodIes1 in number, aCantLivr in number, aCodIes in number, aTipDoc in number, aCant in number, aPU in number, aTVA in number, aAdDim in number, aCoefdiscmaj in number, aValdiscpret in number, aValdoc in number, aTvaDoc in number) return number;
  function GetCodContract1(aCodObiect in number, aDataDoc in date, aCodContract in number, aCodDoc1 in number default 0) return number;
  procedure MAKE_MANEVRA_NC(aCodNCredit in number, CuCommit in boolean default True);
  procedure MAKE_MANEVRA_T(aCodContract in number);
  function IsCumulat(vCodDoc1 in number, vCodContract in number, vTip in number) return number;
  procedure UpdateCentralizare(aCodDoc in number, aCodNC in number, aCodDoc1 in number default 0);
  function GetProcOffInvoice(vCodPart IN NUMBER, vData IN VARCHAR2, vCodSubunit IN NUMBER, vCodSediu IN NUMBER) return number;
  function IntrareCuDiscount(CodIntr IN NUMBER) return number;
  PROCEDURE EMPTY_NOTE_TEMPTABLES;

  FUNCTION GETDISCVOLUM(aCODDOC IN NUMBER, aCodContract in number, aTip in number, aCodNCredit in number, PretBrut in number default 0, aCurs in number default 1) RETURN NUMBER;
  FUNCTION GETDISCVOLUMTRIM(aCODDOC IN NUMBER, aCodContract in number, aTip in number, aCodNCredit in number, Trimestru in number, PretBrut in number default 0, aCurs in number default 1) RETURN NUMBER;
  FUNCTION GETPROCCONTRACTVOLUM(vSuma IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER;
  FUNCTION GETVALDISCCONTRACTVOLUM(vSuma IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER;

  FUNCTION GETDISCTERMENCLI(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract IN NUMBER, vCodDoc1 IN NUMBER, vPlata IN NUMBER, vValOrig IN NUMBER DEFAULT 0) RETURN NUMBER;
  FUNCTION GETDISCTERMENFURN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract IN NUMBER, vCodDoc1 IN NUMBER, vPlata IN NUMBER) RETURN NUMBER;
  FUNCTION GETPROCCONTRACTTERMEN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract1 IN NUMBER) RETURN NUMBER;
  FUNCTION GETVALDISCCONTRACTTERMEN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract1 IN NUMBER) RETURN NUMBER;
  function GETDISCCUMULAT(vCodDoc1 in number, vCodContract1 in number, vTip in number, vValOrig IN NUMBER DEFAULT 0) return number;

  FUNCTION GETDISCCANT(vCant IN NUMBER, vValDoc IN NUMBER, vTotal IN NUMBER, vCodContract1 IN NUMBER, vPretMediu in number, vGlobal in number default 0, vCurs in number default 1) RETURN NUMBER;
  FUNCTION GETPROCCONTRACTCANT(vCodObiect IN NUMBER, vValoare IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER;

  FUNCTION GETPROCCONTRACTPEN(vCodContract IN NUMBER) RETURN NUMBER;

  function getvalobiecties(aCodIes1 IN NUMBER, aTipDiscount in number, aPretC in number) RETURN NUMBER;
  function getvalobiectintr(aCodIntr1 IN NUMBER, aTipDiscount in number, aPretC in number) RETURN NUMBER;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD_SEC( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);

  procedure GenereazaVolum(aCodNCredit in number,
                           aCodContract in number,
                           aTipArticol in number,
                           aDataStart in varchar2,
                           aDataStop in varchar2,
                           aCodMoneda in number,
                           aCodPart in number,
                           aSubunitatea in number,
                           aTrimestru in number,
                           aPretBrutV in number,
                           aTipDoc in number,
                           aTipDiscV in number,
                           aTotal out number,
                           aTotalLei out number
                          );
  procedure GEN_TMP_PEN(
    vZileGratie in number,
    vDataRef in varchar2,
    vIni in number default 0,
    vAllPart in number default 1,
    vAllMon in number default 1,
    sDataRef in varchar2,
    vRestZero in number default 0,
    vLitigii in number default 0,
    AnLunaIni in number);
  procedure test;
  PROCEDURE TEST1;
  function CHECK_NC_FACT(aCodDoc in number, aCodDoc1 in number, aTipDoc in number, aCodNC in number) return number;

end pkg_notecredit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D3195095631B8149B6FDFA3DF49919B986CF178</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NPARTRETAIL is
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;



  -- proceduri pentru sincronizari NPARTRETAIl NPART baza
  PROCEDURE MAKE_PARTRETAIL_FROM_NPART;-- RETAIL-ul populeaza tabela NPARTRETAIL din tabela de baza;
  PROCEDURE SET_FLAG_MODIF(aCODPARTRETAIL IN NUMBER);

  PROCEDURE PREPARE_NEW_PARTRETAIL;
  PROCEDURE PREPARE_MODIF_PARTRETAIL;

  PROCEDURE CLEAR_PARTRETAIL_TEMPS;
  PROCEDURE DO_POST_NEWPART_ONBAZA;
  PROCEDURE DO_POST_MODIFPART_ONBAZA;
  PROCEDURE MUTA_CODIFICARI_PE_RETAIL;

  FUNCTION GET_COD_LOCALIT(aCODLOCALIT IN NUMBER, aDENLOCALIT IN VARCHAR2, aCODJUDET IN VARCHAR2, aCODTARA IN VARCHAR2) RETURN NUMBER;

  FUNCTION COD_FISCAL_UNIC(aCODPART IN NUMBER, aCODFISCAL IN VARCHAR2) RETURN NUMBER;

-- sincronizari automate parteneri
  PROCEDURE PREPARE_PART_BAZA_FOR_SYNC(aCODPOSTRETAIL IN NUMBER);
  PROCEDURE SET_FLAG_SINCRONIZAT;

  PROCEDURE CLEAR_PART_TABLES;
  PROCEDURE MAKE_PARTRETAIL_FROM_TMPNPART;
  PROCEDURE SYNCRON_PARTBAZA_ON_RETAIL;

end PKG_NPARTRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_NZONE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58A7F6EECAF65E07A829DECABBC735D667F7AE2F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_NZONE IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_nzone; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OBIECTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>467589E705DFAEFA2E07C864448BE468871C4071</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_OBIECTIVE is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_OBIECTIVE;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39095CCBE28C25C6FCB83602903C47DF24C69FA4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_OFERTA IS

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE Umple_TMP_SelArtOfe(
              pTipOfe     IN NUMBER,
              pDataRef    IN VARCHAR2,
              pCodPart    IN NUMBER,
              pCodLocatie IN NUMBER,
              pSubunit    IN NUMBER);
  FUNCTION GetPretOfertaPartLocObj(aCodPart in number, aCodLocatie in number, aCodObiect in number, aDataRef in varchar2, aTipDoc in number) return NUMBER;
  FUNCTION GetPretOferta(aCodObiect IN NUMBER, aCant IN NUMBER, aDataRef IN VARCHAR2, aCodPart IN NUMBER, aCodLocatie IN NUMBER, aSubunitatea IN NUMBER, aTipOfe IN NUMBER) RETURN NUMBER;
  FUNCTION OfertaVal(aCodOferta IN NUMBER) RETURN NUMBER;
  FUNCTION GetPretMediuOferte(aCodobiect in number, aCodArticol in number default 0, aRetGenerica in boolean default False, aCodAtribut in number default -1, aModGenerice in number default 0) return number;
  FUNCTION GetPMPOferte(aCodobiect in number, aDate in varchar2) return number;
  FUNCTION ExistaOfertaValabila(aCodObiect in number) return number;
  FUNCTION GetCodOferta1(aCodObiect in number, aData in date, aCodPart in number, aCodLocatie in number, aSubunitatea in number, aTipDoc in number, aCant in number) return number;
  FUNCTION GetCodOferta1PretMin(aCodObiect in number, aData in date) return number;
  FUNCTION GetCodOferta1PretMinPart(aCodObiect in number, aData in date, aCodOferta in number) return number;
  PROCEDURE debug;
  function RoundPret(Pret in number,  Rot in number) return number;
  function updateComandaXOferta( pCodOferta IN NUMBER ) return varchar;
  function updateComandaXOfertaNoua( pCodOferta IN NUMBER ) return varchar;

END PKG_OFERTA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ONORARECOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB29E0CE3C623D4FD8FADC53A4BA4EE35BB86FD3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ONORARECOMENZI IS

  pFlagTermLivr       NUMBER(1);
  pFlagClaseArt       NUMBER(1);
  pDataSys            DATE;
  pDataTermLivrDeLa   DATE;
  pDataTermLivrPanaLa DATE;

  PROCEDURE settermen(aTermenDeLa IN VARCHAR2, aTermenPanaLa IN VARCHAR2 DEFAULT NULL );
  PROCEDURE CLR_LCK_COMENZI;

  FUNCTION  LCK_COMENZI(
              aCodSubunit         IN NUMBER,
              aDataTermLivrDeLa   IN VARCHAR2,
              aDataTermLivrPanaLa IN VARCHAR2,
              aNrComenzi          IN VARCHAR2,
              aCodDelegat         IN NUMBER,
              aCodMijlTransp      IN NUMBER,
              aCodTraseu          IN NUMBER,
              aCodAgent           IN NUMBER,
              aCodClient          IN NUMBER,
              aCodSubunitSursa    IN NUMBER,
              aCodGestSursa       IN NUMBER,
              aFlagClaseArt       IN NUMBER,
              aStadiuWMS          IN NUMBER,
              aTipPlata           IN NUMBER DEFAULT 0,
              aRez                IN NUMBER DEFAULT 0,
              aCmdC               IN NUMBER DEFAULT 0,
              aDL                 IN NUMBER DEFAULT 0,
              aCmdG               IN NUMBER DEFAULT 0,
              aCmdS               IN NUMBER DEFAULT 0,
              aAllSerii           IN NUMBER DEFAULT 1
            ) RETURN varchar2;
  procedure ULCK_COMANDA(aCodComanda IN NUMBER);

  procedure GET_TMP_Comenzi(SursaPU in number, CarePU in number, DataRef in varchar2, aRez IN NUMBER DEFAULT 0);
  procedure GET_TMP_OperLivr_Comenzi;
  procedure GET_TMP_OperLivr_Articole(aRez in number default 0);
  procedure GET_TMP_GrupCom;
  PROCEDURE GET_TMP_GrupComByCod;

  procedure GET_TMP_LivrStoc(
              aCodObiect IN NUMBER,
              aTipArticol IN NUMBER,
              aCodComanda IN NUMBER,
              aDateStart IN VARCHAR2,
              aCodObiectEchiv IN NUMBER,
              aCodComanda1 IN NUMBER
            );
  PROCEDURE GET_TMP_LivrStocAll;
  procedure PreluareAutomataDinStoc(pDataLivr IN VARCHAR2, pCodIOArt IN NUMBER, pCodGest IN NUMBER, pOrdineGR IN NUMBER DEFAULT 0, pImp IN NUMBER DEFAULT 0, pRezOnly IN NUMBER DEFAULT 0);
  procedure PreluareAutomataCantariri;

END PKG_OnorareComenzi;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OPERATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C84CB1314FA8E0A0A81AFA28CA6FD1127ABD48A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_OPERATII IS

  CLASA_OP NUMBER(20) := 0;

  PROCEDURE SETCLASAOP(aCLASA IN NUMBER);
  FUNCTION CONDITIECLASA(aCLASA IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

end pkg_operatii; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDE29BA5C706CD902F28D6B2B830CF945435179E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_OPORTUNITATI IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  function  GetDocInfo(aCodDoc in NUMBER, aTipDoc in NUMBER) return VARCHAR2;
  procedure StergeCodDoc (aCodOportunitate in NUMBER, aCodDoc in NUMBER, aTipDoc in NUMBER);
  procedure AdaugaCodDoc (aCodOportunitate in NUMBER, aCodDoc in NUMBER, aTipDoc in NUMBER, aOldCodDoc in number);
  procedure Set_Do_Commit(aDoCommit IN BOOLEAN);

end PKG_OPORTUNITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OPPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0F7AFF869807B38B747E01A5C84B2E1A150F019</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_OPPER is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_OPPER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_OPREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C960C66700BD9990A4A522F35A7A91EBBD80B911</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_opreg is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_opreg;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ORAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07A174B3C1F1C0F7B5CDE29937ED99E878AB751B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ORAR IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );

FUNCTION  Expirat (Denumire IN VARCHAR2) RETURN NUMBER;
procedure Creaza_orar(recid in number, operation in number) ;
procedure Avarie_orar;
procedure setParams;
procedure unJob;

procedure SaveGlobalEnviroment;
procedure SaveListaEnviroment(aSql in varchar2);
end pkg_orar;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ORA_LISTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E098F2BCEF6CDA0DE835D7B459EC7C2AA06B805</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ORA_LISTS IS
  JOB_DATAIni DATE := Null;
  JOB_DATAFin DATE := Null;
  JOB_CodJob1 NUMBER(20) := 0;

  PROCEDURE DropCompleteJobListeFin(aCod in number);
  PROCEDURE DropJobListeFin(aCod in number);
  PROCEDURE KeepLastResult;
  PROCEDURE DelJobListeFin_TablaInexist;
  PROCEDURE testjob;
  FUNCTION  TestStoredProcName(aCodJob1 IN NUMBER, aID IN NUMBER, aStoredProc in varchar2) return number;
  FUNCTION  GetNumeView(ViewName VARCHAR2, DataIni DATE, DataFin DATE, Subunit INTEGER) RETURN VARCHAR2;
  PROCEDURE SET_INTERVAL_LISTARE(aDataIni IN DATE, aDataFin IN DATE);
  FUNCTION  GET_JOB_DATAINI RETURN DATE;
  FUNCTION  GET_JOB_DATAFIN RETURN DATE;
  FUNCTION  SET_LAST_MONTH RETURN NUMBER;
  FUNCTION  SET_LAST_YEAR RETURN NUMBER;

  PROCEDURE CREATE_VIEW_4_LAST_JOB (aCodJob1 IN NUMBER);
  PROCEDURE ExportOraToXLSX(aSQL in varchar2, NumeExp in varchar2);
  FUNCTION  GET_VALUES_FROM_TMP(aSubunit  number, aCodJob1  number,DATAFIXATA IN NUMBER DEFAULT 0) RETURN NUMBER;
  PROCEDURE SET_VARIABILE_SESIUNE (ACODJOB1 IN NUMBER);
  PROCEDURE CREAZA_TABLA(NUMETMP IN OUT VARCHAR2, ALISTID IN NUMBER, ALISTVER IN NUMBER, aCodJob1 IN NUMBER DEFAULT NULL);
  PROCEDURE MESAJ_JOB_EXECUTAT(aCODJOB1 IN NUMBER);
  PROCEDURE SET_JOB(aCODORAR IN NUMBER, aCODJOB1 IN NUMBER ,activ in boolean default true);
  PROCEDURE SET_INTERVAL_DINAMIC(aCodJob1 IN NUMBER, aDataIni IN OUT VARCHAR2, aDataFin OUT VARCHAR2, aLunaAnIni IN OUT integer, aLunaAnFin OUT integer);
  PROCEDURE SET_INTERVAL_DINAMIC(aCodJob1 IN NUMBER, aDataIni IN OUT DATE,     aDataFin OUT DATE,     aLunaAnIni IN OUT integer, aLunaAnFin OUT integer);
  PROCEDURE SET_DATA_DINAMIC(aCodJob1 IN NUMBER, aData IN OUT DATE);
  PROCEDURE create_view_cumulat (aMask in varchar2, aViewName in varchar2);
	procedure testjobx;
  FUNCTION DO_JOBLISTA_WEBSERVICE(askemafirma varchar, aCodJob1 number) RETURN NUMBER;

END PKG_ORA_LISTS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15EA16B2650306B647D784C6F02BF106401FE4C5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PACHETE IS
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);

  PROCEDURE SETLISTARE(RecId IN NUMBER, aListat IN NUMBER);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  
  procedure DeleteLinie(aCodPachete in number, aCodLinie in number, aDenLinie in varchar2);
  procedure UpdatePacheteObjL;
  function getpartener(RecId in NUMBER) return varchar2;
  function getcodpartener(RecId in NUMBER) return number;
  function InsertDoc(RecId in number, CodDoc in number, TipDoc in number) return NUMBER;
  procedure InsertObj(RecId in number, aCodNirStoc in number, aCant in number, aCantUM1 in number);
  procedure InsertObjL(RecId in number, aCodLivr1 in number, aCant in number, aCantUM1 in number, aPachet in number default 0);
  function GetMasa(RecId in number) return number;
  function GetVolum(RecId in number) return number;
  function GetMasa1(RecId in number) return number;
  function GetVolum1(RecId in number) return number;
  function GetValoare1(RecId in number) return number;
  procedure UpdateVerifFactDL(RecID in number);
end pkg_pachete;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PACKING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2637827C487B38E50F1F6EDE274F2BEC49E4F451</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PACKING IS

 PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number,  aCodDetaliu  out number);

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
 PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SET_DIRTY(aCodDoc in number , aTipDoc in number,  aFlag  in number);
 
end PKG_PACKING; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>677CF38BE069D1943B94A45807706605F3E520B4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PARTICIP is
PROCEDURE SP_GOTORECORD;
PROCEDURE SP_POSTRECORDS;
end PKG_PARTICIP;

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PERISABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C689DECD534C69A321B708F4BA2FC61A5812FC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PERISABIL IS

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );

end PKG_PERISABIL; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B86279C37EE143817EBDA2D9BD787996F853996B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_perscontact IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_PERSCONTACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F95238CD648EC3D34B47FE9E91511D9E45156770</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PGS IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_PGS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PIPE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F51A2F35E6F54C0490955B2B87DE22599C806427</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PIPE is

  -- Author  : GABI
  -- Created : 6/20/2019 10:29:42 AM
  -- Purpose : mesagerie prin DBMS_PIPE


 -- ATENTIE --
 -- pentru a da acces la DBMS_PIPE trebuie sa te loghezi cu SYS (connect as SYSDBA) si data comanda : 
 -- GRANT EXECUTE ON DBMS_PIPE TO PUBLIC;   

procedure SEND_PIPE_MESSAGE(NUME_PIPE IN VARCHAR2, MESAJ IN VARCHAR2);

end PKG_PIPE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANCONTSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A113D62CF09E9B4C6E3158FE0DB89B545DC17BD6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANCONTSEC IS
  g_CodContS1    NUMBER(18) := 0;
  g_CodContSoldS NUMBER(18) := 0;
  g_CodcontrulS  NUMBER(18) := 0;

  INITIALIZARI NUMBER(1) := 0;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER);
  FUNCTION GET_CONT_COD_CARACT_LUNA(aCODCONTS IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
END pkg_PlanContSec; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANCONTTERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9129D74EF150BAACB1FFA279D4256220DFA9EC85</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANCONTTERT IS
  g_CodContT1    NUMBER(18) := 0;
  g_CodContSoldT NUMBER(18) := 0;
  g_CodContRulT  NUMBER(18) := 0;

  INITIALIZARI NUMBER(1) := 0;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER);
  FUNCTION GET_CONT_COD_CARACT_LUNA(aCodContT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
END PKG_PLANCONTTERT; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANCONTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3411202EC0C97F02DEF62A7DF0DF6888D69072ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANCONTURI IS

  INITIALIZARI NUMBER(1) := 0; -- flag care imi spune ca vin de pe initializari

  PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER);

  CODCONTREP NUMBER(20);

	PROCEDURE NCONT_NewEntry(ASIMBOL IN VARCHAR2, ANUME IN VARCHAR2, ANAME IN VARCHAR2, AAN IN number, ALUNA IN NUMBER, RECID OUT NUMBER);
	PROCEDURE NCONT_AddNewEntries;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  procedure SETSIMBOLSITFIN;
  FUNCTION GETNUMARANALITICE(CONT IN NUMBER, UNANSTART IN NUMBER, OLUNASTART IN NUMBER) RETURN NUMBER;
  FUNCTION GETSIMBOLCONT(CONT IN NUMBER) RETURN VARCHAR2;
  FUNCTION GETCODCONT_BY_SIMBOL(ASIMBOL IN VARCHAR2, Principal in number default 0) RETURN NUMBER;
  FUNCTION GETDENCONT(CONT IN NUMBER) RETURN VARCHAR2;
  PROCEDURE SETCODCONTREP(aCODCONT IN NUMBER);
  FUNCTION  GETCODCONTREP RETURN NUMBER;
  FUNCTION REPARTIZARE_SOLD_IN_LUNA(aCODCONT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_CONT_COD_CARACT_ANLUNA(aCODCONT IN NUMBER, aAnLuna IN NUMBER) RETURN NUMBER;
  FUNCTION GET_CONT_COD_CARACT_LUNA(aCODCONT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GET_AN_SOLDINI RETURN NUMBER;

  PROCEDURE POST_NCONT_ECHIV;


  FUNCTION CONTECHIVALAT(aCODCONT IN NUMBER) RETURN NUMBER;
  FUNCTION CONTECHIVALENT(aCODCONT IN NUMBER) RETURN NUMBER;

  PROCEDURE ECHIV_CONTSERV_INTRARI1;
  PROCEDURE ECHIV_CONTSERV_IESIRI1;
  PROCEDURE ECHIV_CONTSERV_NART;
  PROCEDURE ECHIV_IOART;
  PROCEDURE ECHIV_IOPART;
  PROCEDURE ECHIV_IOPERS;
  PROCEDURE ECHIV_CONSTANTE;
  PROCEDURE ECHIV_IOBANK;
  PROCEDURE ECHIV_IOFILIAL;
  PROCEDURE ECHIV_CORELATII;
  PROCEDURE ECHIV_NOTECREDIT;

  PROCEDURE SET_ECHIVALARI_AUTOMATE;

  PROCEDURE UPDATE_SOLD_PARINTE(aCODPARINTE IN NUMBER);
  PROCEDURE UPDATE_SOLD_SUB_PARINTE(aCODPARINTE IN NUMBER);

  PROCEDURE UPDATE_RULAJP_PARINTE(aCODPARINTE IN NUMBER);
  PROCEDURE UPDATE_RULAJP_SUB_PARINTE(aCODPARINTE IN NUMBER);
  PROCEDURE UPDATE_NUME_CONT(ANUME IN VARCHAR2, ASIMBOL IN VARCHAR2);


END pkg_PlanConturi;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5746DC3CC03CCE9ACFDA2128AF5F9F37F3EE7750</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PlanCurs IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_PlanCurs; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANIFCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE9090AC829D48726CF5143222F0CC1B29184A5C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANIFCMD is

  type Stare1_Ref_Cursor is ref cursor;
  function GetAllCls return number;
  function GetAllClsS return number;
  function GetAllProd return number;
  function Multip(aAn in number) return number;
  function LOCKSTARE(aCodStare in number) return number;
  function BLOCARECUREFRESH(aCodStare in number) return number;
  procedure PROPAGAMAT(aCodObiect in number, aCodStare in number, aStoc in number, aStocMin in number, aPret in number);
  function UpdateCmdF(aCodStare1 in number) return number;
  function GENNEWSTARE1(aCodStare in number, aCodObiect in number) return number;
  FUNCTION GetCursorStare1 (aSetG in number, aAnG in number, aSet in number, aAn in number, aCodStare1 in number, CuRefreshRestSE2 in boolean) RETURN Stare1_Ref_Cursor;
  procedure UmpleTemporarGenerator(vAnSet in number, vUserID in number, vSubunitatea in number, vCodObiect in number default 0);
  procedure SetDirtyDinTS;
  function GETANDREFRESHREST(aCodStare2 in number) return number;
  procedure REFRESHDATETS(aCodStareC in number, aCodStareN in number);
  function UpdateTermenPePreCmd(aCodPreComanda1 in number, aTermen in varchar2) return number;
  procedure SetNecesarAccPeStare1(aCodStare1 in number);
  procedure ModificaStareFaraCommit(aTermen in date, aCodComanda1 in number);
  function ModificaStare(aCodStare2 in number, aTermen in varchar, aCodComanda1 in number, aCodStare in number) return number;
  procedure setstare(aSetG in number, aAnG in number, aSet in number, aAn in number, aCodStare in number, aSubunitatea in number);
  --procedure test;
  procedure GenereazaStare(aAn in number, aSet in number, aCodOferta in number);
  procedure MakeTemporar(aSetG in number, aAnG in number, aSet in number, aAn in number, aAllCls in number, aAllClsS in number, aAllProd in number, aPrel in boolean, RemoveDirtyCmdF in boolean);
  procedure MakeTemporarCentralizat(aSet in number, aAn in number);
  procedure StergeSalvare(aCodStare in number);
  procedure UpdateNecesarInStare(aCodStare1 in number, aNecesar in number);
  procedure UPDATECMDEXTTL(aAn in number, aSet in number, aAnG in number, aSetG in number, aField in varchar2, aCodComanda in number);

end PKG_PLANIFCMD;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7700892328DB95BBC3241D46A566F9B3D43B92D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANIFPROD IS
 
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  procedure BagaMateriale(aNodOriginal in number, aCodObiect in number, aNecesar in number, aCodProdComp in number, aNivel in number, 
                          aCodPlanifProd1 in number, aCodPlanifProd in number, aObservatii in varchar2);
  function GENSTRUCT(vCodPlanifProd in number) return number;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_PLANIFPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLANIFPRODLUN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78447D20B57A2631D11124896371C4A04F197997</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLANIFPRODLUN is

function GetFirstDateOfWeek(aSaptamana in number, aAn in number) return varchar2;
procedure SetParams(aSaptamana in number, aCodGest in number, aCodCatPret in number, aAllCls in number, aAllGest in number, aAllIOArt in number, aCodMoneda in number);  
procedure SetParamsVanz(aAnLunaIni in number, aAnLunaFin in number);
procedure UmpleTabele;
PROCEDURE UMPLE_TMP_CMD;
procedure UpdateVanz(aRefresh in number default 0);
PROCEDURE CLEARTABLES;
PROCEDURE CLEARSALVARE(AANLUNA IN NUMBER, ACODGEST IN NUMBER);
PROCEDURE INSERTSALVARE(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, PL1 IN NUMBER, PL2 IN NUMBER, PL3 IN NUMBER, PL4 IN NUMBER, PL5 IN NUMBER, 
                        PL IN NUMBER, LANSARE IN NUMBER, ACODGEST IN NUMBER);
PROCEDURE UPDATE_LANSARE(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, ALANSARE IN NUMBER, ACODGEST IN NUMBER);
PROCEDURE UPDATE_PLANIF(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, PL1 IN NUMBER, PL2 IN NUMBER, PL3 IN NUMBER, PL4 IN NUMBER, PL5 IN NUMBER,
                        PL IN NUMBER, ACODGEST IN NUMBER, CuUPD in boolean);
PROCEDURE BLOCK_SECTIE(aUserID in number, aCodGest in number);
PROCEDURE UNBLOCK(aUserID in number);
procedure UPDATENEXT
(
  aCodObiect in number, 
  aAnLuna in number,
  aCodGest in number, 
  aPlanificat in number, 
  aPLWeek1 in number, 
  aPLWeek2 in number, 
  aPLWeek3 in number, 
  aPLWeek4 in number,
  aPLWeek5 in number
);

end PKG_PLANIFPRODLUN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D8D37718DBD2F913D6BDC45B8E90A3ECBCB2337</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PLATI IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(ANRDOC IN NUMBER, ACARNET IN NUMBER);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  function GetSoldBuget(aCodanalizanod in Number, aAn in Number, aLuna in Number, aCodPlata in Number, aTipDoc in number default 0) return number;
  function GetSoldBuget1(aCodanalizanod in Number, aAn in Number,aLuna in Number) return number;
  PROCEDURE CHECKADDCONTDEST(aCODPART IN NUMBER, aCONTDEST VARCHAR2);

end PKG_PLATI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8900263DD023C8E80E9241B4DDCCC5DBB4BB64E1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PMP IS

FUNCTION GET_PMP_LEI  (aCodObiect in number, aCodSubunit in Number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0) RETURN NUMBER;
FUNCTION GET_PMP_LAST (aCodObiect in number, aCodSubunit in Number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0) RETURN NUMBER;
FUNCTION GET_PMP_VALUTA_FROM_VAR RETURN NUMBER ;
FUNCTION GET_PMP_PREC_FROM_VAR RETURN NUMBER ;
FUNCTION GET_PMP_PREC_VALUTA_FROM_VAR RETURN NUMBER ;
FUNCTION GET_PMP_LAST_FROM_VAR RETURN NUMBER ;
FUNCTION GET_PMP_LAST_VALUTA_FROM_VAR RETURN NUMBER ;
FUNCTION GET_PMP_OBIECT (aCodObiect in number, aCodSubunit in Number, pmpvaluta out number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0 ) return number ;
FUNCTION GET_PMP_OBIECT_DOC (aCodObiect in number, aCodSubunit in Number, aPMPCodIntr in Number, aPMPCodIes in Number, aPMPCodTransf in Number,pmpvaluta out number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0 ) return number;
FUNCTION  am_miscari_cu_pmp return NUMBER;
PROCEDURE CALC_PMP (Tip in Number);
PROCEDURE CALC_PMP2(Tip in Number);
PROCEDURE UpdatePmp(Tip in Number);

END PKG_PMP;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_POSTCALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7F226F272E5858D8B90C59FF51FD26B92147BA3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_POSTCALCUL IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
FUNCTION UpdateFinala(aCodPC IN NUMBER, aOperat IN NUMBER) return Boolean;

end pkg_postcalcul;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_POSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4F1966AB01EACC60B5F822D914162A6E806F625</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_POSTRETAIL IS
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE CHECKFUZIONARI;
  PROCEDURE CHECKFUZIONARIPART;
  PROCEDURE CHECKARTDELETED;
  PROCEDURE CHECKFUZGEST;
  PROCEDURE CHECKFUZLOCALIT;
  PROCEDURE MEMO_MODIF_PRET_RETAIL(aCODOBIECT IN NUMBER,  aCODSUBUNIT IN NUMBER);
  PROCEDURE MEMO_MODIF_PROMO_RETAIL(aCODPROMO IN NUMBER, aTIPMODIF IN NUMBER);
  PROCEDURE PREPARE_TEMP_PRETURI(aCODPOSTRETAIL IN NUMBER);
  PROCEDURE PREIA_PRETURI_NOI(aCODPOSTRETAIL IN NUMBER, IDPREL OUT NUMBER);
  PROCEDURE UPDATEPUNCTERETAIL(aCODPART IN NUMBER, aCODPOSTRETAIL IN NUMBER);
  PROCEDURE PREIA_PUNCTE_PEBAZA(aCODPOSTRETAIL IN NUMBER);
  PROCEDURE PREPARE_GENMONETARE_RETAIL(aCODSUBUNIT IN NUMBER);
  PROCEDURE POST_MONETARE_RETAIL;
  PROCEDURE PREIA_SINTEZA_EMULARE(aCODPOSTRETAIL IN NUMBER);
  PROCEDURE GETSINTEZASTOC;
  PROCEDURE CHECKINACTIVARI_ART(aCODPOSTRETAIL IN NUMBER);
end PKG_POSTRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91F605C2C4B7E860596D7018731D18A68D323112</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PRECOMANDA is

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  
  procedure STERGE(aAn in number, aSet in number, aAnG in number, aSetG in number);
  procedure STERGELINIE(aCodPreComanda1 in number);
  procedure SALVEAZAPRECMD;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);

end PKG_PRECOMANDA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PREDARIPLUS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23B12651A53DAA92FD31A35F2C76F1609B0CAB78</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PREDARIPLUS is

PROCEDURE STERGE(AIDINREG IN NUMBER);
PROCEDURE UPDATE_CODEXTERN(AIDINREG IN NUMBER, ACODEXTERN IN VARCHAR2);
PROCEDURE UPDATE_LINIA(AIDINREG IN NUMBER, ALINIA IN VARCHAR2);
PROCEDURE UPDATE_UA(AIDINREG IN NUMBER, AUA IN VARCHAR2);
PROCEDURE UPDATE_SECTIE(AIDINREG IN NUMBER, ASECTIE IN VARCHAR2);
PROCEDURE UPDATE_CANTITATE(AIDINREG IN NUMBER, ACANTITATE IN NUMBER);
PROCEDURE PP_LOCK_ALLFREE(AUSERID IN NUMBER, ACODAFA IN VARCHAR2, ADATASTART IN VARCHAR2, ADATASTOP IN VARCHAR2);
PROCEDURE PP_LOCK(ACODCOMANDA1 IN NUMBER, AUSERID IN NUMBER, AID IN NUMBER, APRELUAT IN NUMBER);  
PROCEDURE PP_RELEASE(AUSERID IN NUMBER);
PROCEDURE PP_UPDATENP(AUSERID IN NUMBER, ACODCOMANDA1 IN NUMBER, ACODINTR IN NUMBER);
PROCEDURE SCADECANT(AID IN NUMBER, DESCAZUT IN NUMBER);
FUNCTION DUPLICARE(AID IN NUMBER, ACANT IN NUMBER) RETURN NUMBER;
PROCEDURE VERIFCANTWME;

end PKG_PREDARIPLUS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRESTATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFD6EC88BCD4D0515A9665F2DBB1FF4146991422</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PRESTATII is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_PRESTATII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD82BA08D845DDA74DE71D91C3DB162E8AD81692</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PRETPROD IS

  procedure CheckNS1Reziduale;
  procedure UpdateNirStoc1Consumuri(aCodNirStoc in number);
  procedure PopuleazaNirStoc1;
  procedure CompleteazaNirStoc1;
  procedure CheckNirStoc1;

  function  UpdatePretNS1Partial(Cate in number) return number;
  function  UpdateNirStoc1InLuna return number;
  function  GetPretMat(aCodComanda1 in number) return number;


  procedure UpdateNirStoc1;
  procedure UpdateCodComanda1OnNirStoc1;
  procedure UpdatePreturiByCodComanda1(aCodComanda1 in number);
  procedure SetDirtyStructura;
  procedure SetDirtyNirStoc1(aCodNirStoc in number);

  procedure CheckNirStoc1ByCodIntr(aCodIntr in number);
  procedure CheckNirStoc1ByCodTransf(aCodTransf in number);
  procedure Get_DifPretProdAllSubunit;

  function GetPretNirStoc1Mat(aCodNirStoc in number, CuResetManevra in boolean default true) return number;
  procedure debug;
  procedure GetDateCursorLuna;
  procedure CheckInfoCursor(Total out number, Realizat out number);
  procedure PreiaInfoCursor(Total out number, Realizat out number);
  function PregatireCalcul return number;
  function GetValConsumPeComanda(aCodComanda1 in number, CuSupliment in number) return number;
  function GetValBonConsum(aCodComanda1 in number) return number;
  function GetValBonConsumAchiz(aCodComanda1 in number) return number;
  function GetValManNet(aCodComanda1 in number) return number;
  function GetValManReal(aCodComanda1 in number, aDataRef in varchar default to_char(sysdate,&apos;dd.mm.yyyy&apos;)) return number;
  function GetPredariPeComanda(aCodComanda1 in number) return number;
  function GetPredariReziduu(aCodComanda1 in number) return number;
  function GetTotalPredariReziduu(aCodCmdProdMat in number) return number;
end PKG_PRETPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRETURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95A3DD60F2B29D456327B253A0C386115DA02471</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_preturi IS
  TYPE PRETURI_ART_CURSOR IS REF CURSOR;

  FUNCTION WMROTOPRET(ROT IN NUMBER, PRET IN NUMBER ) RETURN NUMBER;
  FUNCTION ROTUNJESTE_PRET(aCODOBIECT IN NUMBER, aPRET IN NUMBER, INLEI IN NUMBER) RETURN NUMBER;

  FUNCTION GETPRETRECEPTIE(aCODOBIECT IN NUMBER, aCODGEST IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER ) RETURN NUMBER;
  FUNCTION GETPRETRECEPTIEDINCATEGORIE(aCODOBIECT IN NUMBER, CATPRETGEST IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER ) RETURN NUMBER;

  FUNCTION CALCULEAZAPRETRECEPTIE(aCODOBIECT IN NUMBER, TIPCATEG IN NUMBER, PRETLEI IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER) RETURN NUMBER;

  FUNCTION GETCATPRETVANZARE(aCODOBIECT IN NUMBER, aCODPART IN NUMBER, NEEDMANUALSELECTION OUT NUMBER) RETURN NUMBER;
  FUNCTION GETCATPRETVANZARESUBUNIT(aCODOBIECT IN NUMBER, aCODSUBUNIT IN NUMBER, NEEDMANUALSELECTION OUT NUMBER) RETURN NUMBER;

  FUNCTION GET_LISTA_CAT_PRETURI(ACODOBIECT IN NUMBER) RETURN PRETURI_ART_CURSOR;
  FUNCTION GET_LISTA_CAT_PRETURI_RECEPTIE(ACODOBIECT IN NUMBER, aCODGEST IN NUMBER) RETURN PRETURI_ART_CURSOR;

  FUNCTION GET_RECORD_PRET_ARTICOL(ACODOBIECT IN NUMBER, ACATPRET IN NUMBER) RETURN PRETURI_ART_CURSOR;
  FUNCTION GET_RECORD_PRET_ARTICOL_UMSEC(ACODOBIECT IN NUMBER, ACATPRET IN NUMBER, AUMSEC IN NUMBER) RETURN PRETURI_ART_CURSOR;

  FUNCTION GET_INCADRARE_ADAOSM(DATAREF IN VARCHAR2, aPRETRIDICATA IN NUMBER) RETURN PRETURI_ART_CURSOR;
  FUNCTION GETTIPCATPRET(aCODCATPRET IN NUMBER) RETURN NUMBER;

  FUNCTION GETPRET     (aTip IN NUMBER, aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN DATE ) RETURN NUMBER; --aTip 0 - intrare , 1 - iesire
  FUNCTION GETPRET_IES (aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN VARCHAR2 ) RETURN NUMBER;
  FUNCTION GETPRET_INTR(aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN VARCHAR2 ) RETURN NUMBER;

  PROCEDURE TEST;
END PKG_PRETURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROCINTRETINERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB896D281FC80D0E9737D9D877B16DF7E0D0C9AB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROCINTRETINERE IS

 PROCEDURE UPDATE_NIRSER_DATAPROD;
 PROCEDURE SETJOB(ASCHED IN VARCHAR2);
 
 FUNCTION GETSTAREJOB(DEN_SCHED OUT VARCHAR2) RETURN NUMBER;
 
end PKG_PROCINTRETINERE; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROC_ACT_DATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFDD55D5EFEC475486317F4AD117D2D8015B2426</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROC_ACT_DATE IS
  
  type tCod is table of integer index by pls_integer;
  
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  
  PROCEDURE RUN_NOW(aCodProc in  number);
  procedure drop_job;
  PROCEDURE ACTUAL_PROC_DATE;
  procedure UpdateStocArt;
    
end pkg_proc_act_date; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15B14A530594AC78680CE120CA2AEC2F11871450</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PRODCOMP IS

  procedure SetParams(aAllRet in number, aFromImport in number default 0);
  procedure UpdateProcReal(vArt in number, vProc in number);
  procedure INLOCMAT(ArtNou in number, ArtVechi in number);
  procedure SetParamsT(aTipFiltru in number, aDataStart in varchar2, aDataStop in varchar2);
  procedure SetLucruCuGenerice(aMod in number);
  procedure SetTipPretDin(aTipPretDin in number);

  FUNCTION UpdateGeneric(aCodProdComp IN NUMBER, aGeneric IN NUMBER) return Boolean;
  FUNCTION UpdateImplicit(aCodProdComp IN NUMBER, aImplicit IN NUMBER) return Boolean;

  function GetRetetaGenerica(aCodObiect in number) return number;
  function GetValMatFromCompusi(aCodObiect in number) return number;
  function GetValManFromCompusi(aCodObiect in number) return number;
  function GetRegieFromCompusi(aCodObiect in number) return number;
  function GetValoareMat(aCodObiect in number, tippret in number) return number;
  function GetValoareMan(aCodObiect in number, TipPret in number) return number;
  function GetValoareMatDinDerivate(aCodObiect in number, tippret in number) return number;
  function GetValoareManDinDerivate(aCodObiect in number, TipPret in number) return number;
  function GetRegie(aCodObiect in number, TipPret in number) return number;
  procedure Set_Mat_Echivalat(aCodMat IN NUMBER);
  function Get_Mat_Echivalat return number;
  procedure UpdateManAll(aCodProdComp IN NUMBER);
  procedure SetDurataInRetete;
  procedure UpdatePretDinPostCalc(aTip IN NUMBER);
  procedure UpdateNArtObj1(aTip IN NUMBER);
  procedure UpdateNArtObj1AnteC;
  procedure ArmeazaTmps(aCodProdComp in number, aDinManevra in boolean default false);
  procedure UpdateDateRete;
  procedure GetPreturi(AnLunaDela in number, AnLunaPanaLa in number, aCodProdComp in number, aMarja in number, aDinManevra in boolean default false);
  procedure GetPreturi0(AnLunaDela in number, AnLunaPanaLa in number, aCodProdComp in number, aMarja in number);
  procedure UpdatePretFixMat(aCodObiect in number, aPret in number);
  procedure TestRetete;
  function ActualizeazaPret(aCodProdComp in number) return number;
  function GetPretMaterialCompus(aCodObiect in number, aPret in number, TipPret in number) return number;
  function GetPretFromStoc(aCodObiect in number) return number;
  function GetPretFromCompusi(aCodObiect in number) return number;
  procedure Set_Do_Commit(aDoCommit IN BOOLEAN);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  function PrjFExists(aCodProdComp in number) return number;
  FUNCTION GET_VALORE_PRODUS(aCodcomanda1 in number, aDeazagrezare in number, aPMP in number default 0) return number;

  procedure GetPreturiOferta(RetGenerica in boolean default False);
  procedure UpdateValManDinTarif(aCodTarif1 in number, aTipFiltru in number, aDataStart in varchar2, aDataStop in varchar2);
  procedure MakeOferta;
  procedure CurataExtreme(aMarja in number);
  procedure SeteazaStare(aMarja in number);
  procedure LoadPreturi(modul in number);
  procedure SavePreturi(modul in number);
  function GetPretDinRetete(aCodObiect in number) return number;
  procedure STERGERETETASIPROIECT(aCodProdComp in number);
  procedure UpdateNArtObj1ByTipCont(aAn IN NUMBER, aLuna in number);
  procedure EXEC_DEBUG;
  procedure CorectieMatDuplInProj;
  procedure CorectieCmdProdMat;
  procedure CorectieMatDuplInProjByCod(aCodProiect in number);
  procedure UpdateNArtObj1Double(aCodObiect in number, Camp in varchar, valoare in number);
  function baga_man_nou(
    aCodprodcomp in number,
    aNrop in number,
    aCodop in number,
    aCodloc in number,
    aCodtarif in number,
    aTu in number,
    aValoare in number,
    aCodprodgest in number,
    aDsv in number,
    aBps in number,
    aTpi in number,
    aDetalii in number,
		aFix in number,
		aNivel in NUMBER
  ) return number;
  function baga_mat_nou(
    aCodprodcomp in number,
    aCodobiect in number,
    aCant in number,
    aPret in number,
    aD1 in number,
    aD2 in number,
    aD3 in number,
    aIndexlocal in number,
    aCantum1 in number,
    aCodprodgest in number,
    aTip in number,
    aPretorig in number,
    aValoare in NUMBER
  ) return number;
  function CalcAndGetPretRef(aCodProdComp in number) return number;
  procedure sterge_mat(aCodMat in number);
  procedure sterge_man(aCodMan in number);
  function AduValoareMateriale(aCodProdComp in number) return number;
  function AduValoareManopera(aCodProdComp in number) return number;
  function AduValoareRegie(aCodProdComp in number, aValRegieMan out number) return number;
  procedure PropagaParitateCantInAdancime(aCodMat in number, aCant in number);
  procedure UpdateCantCuParitate(aCodproiectnod in number, aCant in number);
  procedure PROPAGAFISA(aCodProdComp in number);
  procedure ActualizeazaPretDinMat(aCodProdComp in number, aData in varchar2);
  function CloneazaReteta(aCodProdComp in number) return number;
  procedure DOVERIF;
  procedure propagagant(acodprodcomp in number);
  procedure UPDATECODRETETAMAT;
  procedure GENPRJIMPORT;
  procedure setmasa;
  function GetMasaS(aCodObiect in number) return number;
  procedure PregatesteStructura;
  procedure BagaMateriale(acodproiect in number, aCodObiect in number, aCant in number, aCodProdComp in number, 
                        aNivel in number, aCodOriginal in number, aIndex in varchar2, aCodProdus in number);
  procedure test;

END pkg_prodcomp;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>212E22C4FAD122C5F54F79224C6C6EE1C5FEF440</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PRODNET IS

  procedure IncarcaManCmd1(aSubunitatea in number, aCodGest in number, aCodCentru in number);
  procedure RefacereDirty(aCodProdNet in number, DoCommit in number default 1);
  procedure SetDirty(aCodCmdProdMat in number, An in number, Luna in number, aTip in number);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_prodnet;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD3F77D3481D130FEC9F9FF388B68CFC70DA43D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROGRAMF IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  procedure UpdatePFManevra(dDela in varchar2, dPanaLa in varchar2, oDeLa in varchar2, oPanaLa in varchar2, dCodProgramf in number, vAllGest in number, vAllTipCont in number);
  procedure ClearPF1Manevra;
  procedure ClearPFManOp;
  procedure InsertPF1Manevra(vCodProgramF in number, vCodComanda1 in number, vCodGest in number, vPrioritate in number, vTermen in varchar2, vCantProgramat in number, vCodCmdProdMan in number);
  procedure InsertPFManOp(vCodProgramF in number, vCantProgramat in number, vCodCmdProdMan in number);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  FUNCTION GETDISPONIBIL(aOIA IN number, NS IN NUMBER, DS IN NUMBER, DSTART IN DATE, aDSTOP IN DATE, aOSTART IN NUMBER, aOSTOP IN NUMBER, aZILENELUC IN NUMBER, CODGEST IN NUMBER, aCODLOC IN NUMBER) RETURN NUMBER;
  FUNCTION ESTE_SECTIA(aCodProgramF in number, aCodGest IN NUMBER) return number;
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE CALCUL_GEST(XT IN VARCHAR2, YT IN VARCHAR2);
  PROCEDURE CALCUL_CMD(XT IN VARCHAR2, YT IN VARCHAR2);
  PROCEDURE CALCUL_DETALII(XT IN VARCHAR2, YT IN VARCHAR2, vTip in number);
  PROCEDURE UPDATE_STOCURI(AllGest in number, AllTipCont in number);
  PROCEDURE UPDATEPF(aCodProgramF IN NUMBER, aCodComanda1 IN NUMBER, aCant IN NUMBER, aTermen IN VARCHAR2);
  function UpdateTermenPF(aCodProgramF1 in number, aTermen in varchar2) return number;
  procedure SetDinGoTo(aDinGoTo in boolean);
  procedure CURATA_ZERO(aCodProgramF in number);

end PKG_PROGRAMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>044255D7D6060C38961D76453F6A0F9F5BE0F0C5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROIECT IS

  vNecesar number(20,7);
  function GENRETCENTRALIZATOARE(aCodProiect in number) return number;
  function GetValCampProiectExtins(NrField in number, CodProiect in number) return varchar2;
  procedure SetNecesar(aNecesar in number);
  function GetNecesar return number;
  
  function LockProject(aCodProdComp in number) return number;
  function DeleteProject(aCodProdComp in number) return number;
  procedure BagaProiectNodDinReteta(aCodProiect in number, aCodProdComp in number, aCant in number, aIndexParinte in varchar2, aNodOriginal in number, aNivel in number, NeGeneric IN NUMBER DEFAULT 0);
  function GenProiectGeneric(aCodProdComp IN NUMBER) return number;
  function GENPRJFROMRETETA(aCodProdComp IN NUMBER, NeGeneric IN NUMBER DEFAULT 0) return number;
  FUNCTION UpdateImplicit(aCodProiect IN NUMBER, aImplicit IN NUMBER) return Boolean;
  procedure Set_Do_Commit(aDoCommit IN BOOLEAN);
  function GetCodProiect return number;
  procedure SetCodProiect(aCodProiect in number);
  function GetMasa(aCodProiect in number) return number;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD_FARALOCKCOMMIT( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  procedure TestAndUpdateGeneric(aCodProiect in number);
  procedure CloneazaProiect(vCodProiect in number, vCodRetVeche in number, vCodRetNoua in number, vCodProiectNou out number);
  procedure GENPRJ_INLOCRET(vCodRetVechi in number, vCodRetNou in number, vInactivePrj in number, vInactiveRet in number);
  procedure SetCopilMaxim(RecId in number);
  procedure BagaProiectNodDinRetetaX(aCodProiect in number, aCodProdComp in number, aCant in number, aIndexParinte in varchar2, aNodOriginal in number, aNivel in number);
  procedure GENPRJASCUNS(aCodProiect in number, aCodProiectNou out number);
  procedure CheckAndUpdateRetete(aCodProiect in number);
  procedure CloneazaPrjAscunse;
  procedure CheckTmpExt;
  procedure CorectExtUnic;
  procedure CurataExtAcunse;
  procedure CheckExtPrj(aCodProiect in number, aCodProiectI in number);
  procedure CheckExtPrjAscunse;
  function GetDurataCopii(aCodNod in number, aDur in number) return number;
  procedure SetIncepereCopii(aCodNod in number, aFinal in number);
  procedure TestDurata;
  PROCEDURE SETDURATANOD(aCodProiectNod in number);
  procedure UmpleMan;
  procedure PROPAGAGANT(aCodProiect in number);
  procedure UpdateIndexCopii(aCodProiectNod in number);
  procedure UpdateIndexParinte(aCodProiect in number default 0);

end pkg_proiect;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROIECTCRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>474B4B764A09E483F88D0D5CCC8863919BE9CF5E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROIECTCRM is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_PROIECTCRM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED5473F93EE7FFC24715A79B3DF9AACA69682868</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PROMO IS

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

END PKG_PROMO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_PUNCTAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF72B6D73896DFD4330945DAF36D2C5EE3F970DB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_PUNCTAJE IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  
  PROCEDURE GET_PUNCTE_SI_VALOARE(aDATA IN VARCHAR2, aVALOARE IN NUMBER, aPUNCTE OUT NUMBER, aVALPUNCTE OUT NUMBER);
  
END PKG_PUNCTAJE; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RAC_CATP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>994646738AB400F22CC7D74A333491F1B9B91762</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RAC_CATP is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_RAC_CATP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RAC_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C43F3AE6397865BD77559845CFACD481EB68943</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RAC_P is
type RAC_CURSOR   is REF cursor;
type RAC_CURSOR1   is REF cursor;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_RAC_P; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RAC_REZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E76B21B49A54D560CDA6675B9F3F9C13AED640BB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RAC_REZ is
DataPornire Date;
IsDataCuOra Number;

type RAC_CURSOR   is REF cursor;
type RAC_CURSOR1   is REF cursor;
type RAC_CURSOR2   is REF cursor;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

function RAC_Libere (aCodComanda in number, aCodComanda1 in number, aCodObiect in number, Zi1 in VarChar2, Zi2 in VarChar2) return RAC_CURSOR;
function RAC_Ocupate (aCodComanda in number, aCodComanda1 in number, aCodObiect in number, Zi in VarChar2, aTip in number) return RAC_CURSOR1;
function RAC_Reparatii (aCodAuto in number) return RAC_CURSOR2;
FUNCTION RAC_DATASTART  RETURN DATE;
PROCEDURE SET_RAC_DATASTART(aData in varchar2, DoTMP in integer Default 0);
PROCEDURE CloneREZ(aCod in number);
Procedure Init_Tmp_V_Auto (Zi1 in VarChar2);

procedure RefacereParcG;
procedure Init_ReparaParcG;
procedure ReparaParcG;
function IndexGrupaAuto return Number;
function RAC_DATACuOra return Number;
PROCEDURE Fill_RAC_TABLES;
PROCEDURE Fill_RAC_TMP;

end PKG_RAC_REZ; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>585468E3015E36588D36723644B0CE8857BC0895</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RAPORTP IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SP_LOCKRECORD  ( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD  ( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS ( Operation IN NUMBER, RecId OUT NUMBER );
  procedure MutaCant;

END PKG_RaportP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RAPSTOCMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8ACCF84C136D7BC8C29BDEF20F57796B1F551AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RAPSTOCMED IS

  PROCEDURE GOLESTE_TMP;
  PROCEDURE UMPLE_TMP(pNewData IN VARCHAR2, pOldData IN VARCHAR2, pCodSIUI IN VARCHAR2);
  PROCEDURE GetRaport;

END pkg_rapstocmed;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A002FC222588AF817F0960DE747965B962CF362</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RECLAMATII is
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);

  PROCEDURE UmpleDocAsoc(aCodDOC IN NUMBER, aTipDOC IN NUMBER, aCodDOCAsoc IN NUMBER, aTipDocAsoc IN NUMBER);
  PROCEDURE RezolvaReclamatie(RecID in number, aCodDOC IN NUMBER, aTipDOC IN NUMBER,aDataDoc in Date);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SOLVENRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_RECLAMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43BC828965B779C3B0AC98D40D190EAC94A3EF33</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REG IS

  data_reg DATE;
  zi_reg NUMBER(20);
  luna_reg NUMBER(20);
  an_reg NUMBER(20);
  bank_reg NUMBER(20);
  moneda_reg NUMBER(20);
  curs_reg NUMBER(23,7);
  /*subunit_reg NUMBER(20);*/
  
	/*PROCEDURE SetSubunitReg(subunit_p IN NUMBER);
  FUNCTION GetSubunitReg RETURN NUMBER;*/
  PROCEDURE SetDataReg(data_p IN VARCHAR2);
  FUNCTION GetDataReg RETURN DATE;
  FUNCTION GetLunaReg RETURN NUMBER;
  FUNCTION GetAnReg RETURN NUMBER;
  PROCEDURE SetBankReg(bank_p IN NUMBER);
  FUNCTION GetBankReg RETURN NUMBER;
  PROCEDURE SetMonedaReg(moneda_p IN NUMBER);
  FUNCTION GetMonedaReg RETURN NUMBER;
  PROCEDURE SetCursReg(curs_p IN NUMBER);
  FUNCTION GetCursReg RETURN NUMBER;
  PROCEDURE SetCursParamsReg(data_p IN VARCHAR2, bank_p IN NUMBER, moneda_p IN NUMBER);
  PROCEDURE SetParamsReg(data_p IN VARCHAR2, moneda_p IN NUMBER, curs_p IN NUMBER/*, subunit_p IN NUMBER*/);
  FUNCTION GetCursBanca(data_p IN VARCHAR2, banca_p IN NUMBER, moneda_p IN NUMBER) RETURN NUMBER;
  FUNCTION GetLastRegDate(/*subunit_p IN NUMBER, */moneda_p IN NUMBER, tipreg_p IN NUMBER) RETURN DATE;
  /*FUNCTION GetObligCurs(codgeneral_p IN NUMBER, curs_p IN NUMBER) RETURN NUMBER;*/
  FUNCTION GetTrezorCurs(codtrezor1_p IN NUMBER, subunit_p IN NUMBER, moneda_p IN NUMBER, curs_p IN NUMBER) RETURN NUMBER;
	
	FUNCTION GetNumRegsPerMonth(tip_p IN NUMBER, month_p IN NUMBER, year_p IN NUMBER, moneda_p IN NUMBER, codreg_p IN NUMBER) RETURN NUMBER;
  FUNCTION RegLeasing(sDataReg IN VarChar2)RETURN VarChar2;

END PKG_REG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28B444D68CCD098F7C5C045C987EE1F5A0169171</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REGOSS IS

  PROCEDURE SP_GOTORECORD(RecID IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE GenerateDataXTrimestru(pTrimestrul IN NUMBER, pCursReg IN NUMBER, pMoneda IN NUMBER, pForce IN NUMBER DEFAULT 0);
  FUNCTION GetNumRegsPerQuarter( pTrimestru IN NUMBER,  pMoneda IN NUMBER, pCodreg IN NUMBER) RETURN NUMBER;


END PKG_REGOSS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REGPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C15C1F7DAA24DB729F6CDC1731BBACCB03BABF12</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REGPART IS
  DATANEXTREG        DATE;
  CODNEXTREG         NUMBER(20);
  DIFERENTE          NUMBER(1)    := 0;
  INCLUSIVAVIZE      NUMBER(1)    := 0;
  MARJAREGAVIZE      NUMBER(20,7) := 0;
  INCLUSIV_CECURI    NUMBER(1)    := 0;


  INCLUSIV_AVANS_FACTURAT   NUMBER(1)    := 1;

  INCLUSIV_GARANTII   NUMBER(1)    := 0;

  INCLUSIV_LITIGII   NUMBER(1)    := 1;

  PROCEDURE GenerareReg;

  PROCEDURE SP_GOTORECORD(RecID IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  FUNCTION DATA_DOC_CORECTA(DATADOC IN DATE,  DATAREG IN DATE, DATANEXTREG IN DATE) RETURN NUMBER;

  PROCEDURE MAKE_STINGERE_LUNA;
  PROCEDURE MAKE_REGPART_LUNA;
  PROCEDURE MAKE_INFO_STINSE_LUNA;

  PROCEDURE SET_INCLUSIV_AVIZE(FLAG IN NUMBER);
  FUNCTION CONDITIE_AVIZE(aICONT IN NUMBER) RETURN NUMBER;


  PROCEDURE SET_INCLUSIV_CECURI(FLAG IN NUMBER);
  FUNCTION CONDITIE_CECURI(aSEMNIFICATIE IN NUMBER) RETURN NUMBER;


  PROCEDURE SET_INCLUSIV_AVANS_FACTURAT(FLAG IN NUMBER);
  FUNCTION CONDITIE_AVANS_FACTURAT(aSEMNIFICATIE IN NUMBER) RETURN NUMBER;
  FUNCTION CONDITIE_ICONT_AVANS_FACTURAT(aICONT IN NUMBER) RETURN NUMBER;
  FUNCTION  CONDITIE_AVANS_PE_NC(aSEMNIFICATIE IN NUMBER, aICONT IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_INCLUSIV_GARANTII(FLAG IN NUMBER);
  FUNCTION CONDITIE_GARANTII(aSEMNIFICATIE IN NUMBER) RETURN NUMBER;

  PROCEDURE SET_INCLUSIV_LITIGII(FLAG IN NUMBER);
  FUNCTION CONDITIE_LITIGII(aSEMNIFICATIE IN NUMBER) RETURN NUMBER;


  PROCEDURE SET_MARJA_REGAVIZE(MARJA IN NUMBER);
  FUNCTION CONDITIE_MARJA_REGAVIZE(SOLD IN NUMBER) RETURN NUMBER;


  PROCEDURE MAKE_STINGERI_LA_DATA_PART;
  PROCEDURE MAKE_STINGERI_LA_DATA;
  FUNCTION GET_CURS_REG_PROVIZION(aCODOBLIGPIF IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER;

END PKG_REGPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REGPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8798C0A1168DB57A8B0FC39DA820A6A5EBAF43B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REGPERS IS
  
  CURS_IN NUMBER(20, 7);  

  PROCEDURE GenerareReg;
    
  PROCEDURE SP_GOTORECORD(RecID IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

END PKG_REGPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REGTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FAF02E88D639FFBA3DDC4D60AC4D4CD97FE12EC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REGTREZOR IS
CURS_IN NUMBER(20, 7);  

  PROCEDURE GenerareReg;
    
  PROCEDURE SP_GOTORECORD(RecID IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

END PKG_REGTREZOR; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REMAKE_SEQUENCES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC9AC846380162D4DEF10B06854B06A5BACE6AE6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REMAKE_SEQUENCES IS
  PROCEDURE REMAKE_SEQUENCE(NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2,NUME_SEQ IN VARCHAR2);
  PROCEDURE RESTART_SEQUENCE(NUME_SEQ IN VARCHAR, VAL_START NUMBER DEFAULT 100);
  PROCEDURE REVAL_SEQUENCE(NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2,NUME_SEQ IN VARCHAR2,SHRINK_SEQ BOOLEAN DEFAULT FALSE);
  PROCEDURE REINIT_ALL_SEQUENCES;
  FUNCTION  REMAKE_ALL_SEQUENCES RETURN VARCHAR2;
  PROCEDURE REMAKE_ALL_SEQUENCES;
end PKG_REMAKE_SEQUENCES;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RESTAURANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C348D8493E2FB7F6DDB5933F465DCBB3E6EA2900</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RESTAURANT IS

PROCEDURE GET_COMENZI_MASA(aCODMASA IN NUMBER);
PROCEDURE POST_COMENZI_MASA(ACODMASA IN NUMBER);

FUNCTION CANLOCKNRCMD(aCODMASA IN NUMBER, aDATA IN VARCHAR2, aNRCMD IN NUMBER) RETURN NUMBER;
PROCEDURE RELEASELOCKNRCMD;

PROCEDURE GET_GEST_VER_LIST;
PROCEDURE POST_GEST_VER_LIST;


PROCEDURE GET_OSPATARI(aCODRESTAURANT IN NUMBER);
PROCEDURE POST_OSPATARI;

PROCEDURE GET_RESTCLASE(aCODRESTAURANT IN NUMBER);
PROCEDURE POST_RESTCLASE(aCODRESTAURANT IN NUMBER);

PROCEDURE GET_RESTOBSART(aCODRESTAURANT IN NUMBER);
PROCEDURE POST_RESTOBSART(aCODRESTAURANT IN NUMBER);




PROCEDURE GET_NOTAPLATA(aCODRESTCMD IN NUMBER);
PROCEDURE POST_NOTAPLATA;


PROCEDURE GET_COMANDA(aCODCOMANDA IN NUMBER);


PROCEDURE GET_GESTIMPLICITE(aCODRESTAURANT IN NUMBER);
PROCEDURE POST_GESTIMPLICITE;


PROCEDURE MUTACMD(CODCMDSURSA IN NUMBER, MASADEST IN NUMBER, DESTNRCMD IN NUMBER);

PROCEDURE MUTA_PE_ALTA_CMD(CODCMDSURSA IN NUMBER, CODCMDDEST IN NUMBER);



PROCEDURE POST_BONEMULARE;



PROCEDURE UNLOCKMASA(aCODMASA IN NUMBER);
FUNCTION CANLOCKMASA(aCODMASA IN NUMBER, aCODOSPATAR IN NUMBER) RETURN NUMBER;

PROCEDURE UNLOCK_MESE_RESTAURANT(aCODRESTAURANT IN NUMBER);



PROCEDURE MAKE_STOC_LA_DATA(aGEST IN NUMBER, aDATA IN VARCHAR2);
PROCEDURE MAKE_STOC_DATA_GEST(aDataStart IN VARCHAR2, aDataStop IN VARCHAR2);
PROCEDURE MAKE_MISCARI_IN_INTERVALUL(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE MAKE_BALANTA_STOC(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE MAKE_ALL_STOC_LA_DATA( aDATA IN VARCHAR2);

PROCEDURE SCADENEPRELUATE(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE SCADEPROTOCOL(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);

PROCEDURE SET_CMD_DIMINUATE;


PROCEDURE LOCK_STOC_CANT(aCODRESTCMD1 IN NUMBER, aCODOBIECT IN NUMBER, aCODGEST IN NUMBER, aCANT IN NUMBER);
PROCEDURE RELEASE_ALL_STOCLOCK;


PROCEDURE MEMO_BALSTOCREST(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE MEMO_RESTRAPORTZ(aCODPOSTRETAIL IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE CALCUALEAZADISCOUNT(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);
PROCEDURE NEPRELUATE(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2);

PROCEDURE POST_COMANDA;

end PKG_RESTAURANT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RESTOBIECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E226C8C749BB9B53E03003693A90CAD957AF37EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RESTOBIECTE is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_RESTOBIECTE;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RETURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FD1515496A1BDD990D629FDD593383AB694C717</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RETURO is

procedure CheckNewData;  
procedure UpdateUsedVouchers;
end PKG_RETURO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_REZERVARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DE43181B90D13D1B1A8AA6939F80B7985ECA5C3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_REZERVARI IS

  procedure GET_TMP_REZURI;
  procedure GET_TMP_MANEVRA_LINIICOMENZI(aCodComanda in number);
  procedure GET_TMP_REZ_CCOM1;
  procedure GET_TMP_REZ_REZ;
  procedure GET_TMP_REZ_PROIECTNOD;
  procedure GET_TMP_REZ_STOC(aCodComanda1 in number);

  procedure ActualizeazaNecesar(aCodComanda1 in Number, aCodProiectNod in Number, aParitate in Number);
  procedure UpdateNecesarPeRez(aCodComanda1 in number default 0);
  procedure UpdateGestIoArt(aCodComanda1 in Number, aCodObiect in Number, aCodGest in Number, aCodIOArt in Number);
  function  STERGEREZERVAREOBIECT(aCodComanda1 IN NUMBER, aCodObiect IN NUMBER, aTip IN NUMBER) return number;
  PROCEDURE CERERE_ACHIZITIE(aCodComanda1 in number);
  procedure DoRezervare(aCodComanda1 in number);
procedure EXEC_DEBUG;


end PKG_REZERVARI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ROPHARMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BA5A973B7DF72C174D68E13437094DF4A0E2A6E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ROPHARMA IS

PROCEDURE PREIA_NOM_TARI(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2);
PROCEDURE PREIA_JUDETE(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2);
FUNCTION  GETCODTARA_DEST(SKEMADEST IN VARCHAR2, aDENTARA IN VARCHAR2, aSIMBTARA IN VARCHAR2) RETURN NUMBER;
FUNCTION GETCODJUDET_DEST(SKEMADEST IN VARCHAR2, aDENJUDET IN VARCHAR2, aSIMBTARA IN VARCHAR2) RETURN NUMBER;
PROCEDURE PREIA_LOCALITATI(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2);


PROCEDURE DO_PRELUARE_TARI;
PROCEDURE DO_PRELUARE_JUDETE;
PROCEDURE DO_PRELUARE_LOCALITATI;

FUNCTION GET_COD_LOCALIT_DEST(aDENLOCALIT IN VARCHAR2, aTIP IN VARCHAR2, aDENJUDET IN VARCHAR2, aSIMBAUTO IN VARCHAR2, aCODSIRUTA IN NUMBER) RETURN NUMBER;
FUNCTION GET_COD_OF_TABLE(TABELA IN VARCHAR2, IDCOLUMN IN VARCHAR2, IDCOLUMN_VALUE IN VARCHAR2, CODCOLUMN IN VARCHAR2) RETURN NUMBER;
FUNCTION GET_COD_OF_TABLE_EXT(TABELA IN VARCHAR2, IDCOLUMN IN VARCHAR2, IDCOLUMN_VALUE IN VARCHAR2, CODCOLUMN IN VARCHAR2, SKEMA IN VARCHAR2) RETURN NUMBER;
FUNCTION GET_SUBUNITATE_DEST(aCODSUBUNIT IN NUMBER) RETURN NUMBER;
FUNCTION GET_UMSEC_OF_OBJECT(aCODOBIECT IN NUMBER) RETURN NUMBER;
end PKG_ROPHARMA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_RUPERE_FIRMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11BEF8A181C6BF3B4D9FF5B7CAED70E8E367BCEB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_RUPERE_FIRMA IS
  AL_RUPERE            NUMBER(5);
  AN_RUPERE            NUMBER(5);
  LUNA_RUPERE          NUMBER(2);
  AL_INITIALIZARI      NUMBER(5);
  AN_INITIALIZARI      NUMBER(5);
  LUNA_INITIALIZARI    NUMBER(2);

  sAL_INITIALIZARI     VARCHAR2(5);
  sAL_RUPERE           VARCHAR2(5);

  bReuse_RF_CTC_AUXCOD BOOLEAN;

  --***BEGIN***-- Proceduri utilitare folosite in cadrul altor proceduri din interiorul pachetului --***BEGIN***--
  PROCEDURE DO_CURATA_TABDETLUNA( sTable VARCHAR2);
  PROCEDURE DROP_TABLE(pTableName VARCHAR2);
  FUNCTION INTERVAL_CONTINUU RETURN NUMBER;
  -- La folosirea procedurilor urmatoare, sunt posibile optimizari folosind parametrul pMod -&gt; 1 &apos;IN&apos; / 2 &apos;EXISTS&apos;/ 3 &apos;JOIN;
  PROCEDURE COPY_TRUNC_COPY_KEEP   (pFKValid BOOLEAN, pSRCTableName VARCHAR2, pSRCField VARCHAR2, pKeepTable VARCHAR2, pKeepField VARCHAR2, pMod NUMERIC DEFAULT 1);
  PROCEDURE COPY_TRUNC_COPY_EXCLUDE(pFKValid BOOLEAN, pSRCTableName VARCHAR2, pSRCField VARCHAR2, pExclTable VARCHAR2, pExclField VARCHAR2, pMod NUMERIC DEFAULT 1);
  PROCEDURE COPY_TRUNC_COPY_COND   (pFKValid BOOLEAN, pSRCTableName VARCHAR2, pCond CLOB);
  --*** END ***-- Proceduri utilitare folosite in cadrul altor proceduri din interiorul pachetului --*** END ***--

  --***BEGIN***-- Proceduri apelate in DO_RUPERE_FIRMA --***BEGIN***--
  --00
  PROCEDURE SETANLUNARUPERE(aAN IN NUMBER, aLUNA IN NUMBER);
  --01
  PROCEDURE REPARA_INCOERENTA_ICONTURI;
  PROCEDURE DO_FIXARI_LUNI(bInclInchise BOOLEAN);
  --02
  PROCEDURE FIXEAZA_INITILIZARE_TREZOR;
  --03
  PROCEDURE FIXEAZA_INITILIZARE_COMENZI;
  --04
  PROCEDURE FIXEAZA_INITILIZARE_STOCURI;
  --05
  PROCEDURE FIXEAZA_INITILIZARE_STOCVAL;
  --06
  FUNCTION  GETCODFACTURALITIGIU(aCODOBLIGASOCIAT IN NUMBER) RETURN NUMBER;
  PROCEDURE REZOLVA_LITIGII;
  --08
  PROCEDURE FIXEAZA_INITILIZARE_SOLDURI;
  --09
  PROCEDURE FIXEAZA_AVIZINT_INITIAL;
  --10
  PROCEDURE FIXEAZA_AVIZIES_INITIAL;
  --13
  PROCEDURE CURATA_LIVR1;
  PROCEDURE CURATA_NIRSTOC;
  PROCEDURE CURATA_OBLIGPIF;
  PROCEDURE CURATA_INTRARI1;
  PROCEDURE CURATA_IESIRI1;
  PROCEDURE CURATA_CARNETEDOC;
  PROCEDURE FIXEAZA_STARTNR;
  PROCEDURE CURATA_LIVR;
  PROCEDURE CURATA_NIR;
  PROCEDURE CURATA_TRANSF1;
  PROCEDURE CURATA_TREZOR1;
  PROCEDURE CURATA_NC1;
  PROCEDURE CURATA_INTRARI;
  PROCEDURE CURATA_IESIRI;
  PROCEDURE CURATA_TRANSF;
  PROCEDURE CURATA_TREZOR;
  PROCEDURE CURATA_COMPENS;
  PROCEDURE CURATA_NC;
  PROCEDURE CURATA_OFERTA;
  PROCEDURE CURATA_PROMO;
  PROCEDURE CURATA_COMANDA;
  --14
  PROCEDURE STERGE_FIXARI_LUNARE_ANTER;
  --16
  PROCEDURE DO_CURATA_CONSTANTE;
  --22
  PROCEDURE CURATA_JURNALE;
  --23
  PROCEDURE CURATA_LANSZ;
  --24
  PROCEDURE CURATA_XXXPROD;
  --26
  PROCEDURE CURATA_STAREESTIMARI;
  --27
  PROCEDURE CURATA_PREDARIPLUS;
  --30
  PROCEDURE CURATA_DECLARATII;
  --84
  PROCEDURE CURATA_EXPERT;
  --85
  PROCEDURE CURATA_REG;
  --86
  PROCEDURE CURATA_MIFIX;
  --87
  PROCEDURE CURATA_INVENTAR;
  --88
  PROCEDURE CURATA_TAB_DOCUMENTE;
  --89
  PROCEDURE CURATA_MODIF;
  --91
  PROCEDURE CURATA_LST_BALANTA;
  --92
  PROCEDURE CURATA_TAB_EXTENSII;
  --93
  PROCEDURE CURATA_TAB_DIVERSE;
  --*** END ***-- Proceduri apelate in DO_RUPERE_FIRMA --*** END ***--

  --***BEGIN***-- Proceduri nefolosite in interiorul pachetului --***BEGIN***--
  PROCEDURE REPARA_REST_OBLIGPIF_INITIAL(ANINITIAL IN NUMBER, LUNAINITIALA IN NUMBER); ---????
  PROCEDURE REPARA_SOLDINI;
  --*** END ***-- Proceduri nefolosite in interiorul pachetului --*** END ***--

  PROCEDURE DO_RUPERE_FIRMA(pAN IN NUMBER, pLUNA IN NUMBER, pFixareLuniInchise IN BOOLEAN);
END PKG_RUPERE_FIRMA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SABLONDESCRIPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>86391ED5644E7F71EF5C989093C68348D204B313</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SABLONDESCRIPT IS
 
 TYPE CRS IS REF CURSOR;
 
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 
  FUNCTION GET_VALORI_DESCRIPTOR(ACODDESCRIPTOR IN NUMBER) RETURN CRS;
 
end pkg_sablondescript; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAFT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC177EAD63D620357CD83EC29204B638612B6BD2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAFT IS
  PROCEDURE TestTaxDecl;
  PROCEDURE RESET_SEQ;
  PROCEDURE UMPLE_NPARTDET (pALStart NUMBER, pALStop NUMBER, bSaft BOOLEAN DEFAULT FALSE );
  PROCEDURE BEGIN_SAFT(pTip NUMBER, pAn NUMBER, pLuna NUMBER, pSubunit INTEGER DEFAULT 1);
  PROCEDURE END_SAFT;
  PROCEDURE ActulizareCodSaftInNCont;
  PROCEDURE UpdateTaxDecl(pCaz NUMBER, pCodDoc NUMBER);
  PROCEDURE UpdateTaxDeclLuna(pAn IN NUMBER, pLuna IN NUMBER);
  PROCEDURE UpdateDiscMonLuna(pAn IN NUMBER, pLuna IN NUMBER);

  PROCEDURE PUT_INFO(pINFOLINE IN VARCHAR2, pDETALII CLOB);
END PKG_SAFT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SALI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87CBE81C3B61B8D915867844488D286557F00757</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SALI is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_SALI;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_CATRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C400B0E9E4502F4763E8029F5822A6D8482BCEDC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_CATRET IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end PKG_SAL_CATRET; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_CATSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6C4BDE7DDF514DF60F452139BCC3EBEC4CEE131</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_CATSPOR IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end PKG_SAL_CATSPOR; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_CONTRPP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>847B0B3BF3A9796007BC033407F8E8FDDCB45B30</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_CONTRPP IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end PKG_SAL_CONTRPP; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_DEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94DA188F984668A0B6E132D184BB6EE1F0C0CDA1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_DEDGEN IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_SAL_DEDGEN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_FONDP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A952B598BA7B6D4960A7748D24868A7EFA417E6F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_FONDP IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end PKG_SAL_FONDP; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_IMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D37F269E2E72DB8D5D16977ED44883B62507190B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_IMPOZ IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_SAL_IMPOZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_NASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62199DC8CB19EA6AEAB7443EF2CBE14833019724</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_NASIG IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;

end PKG_SAL_NASIG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_NCONTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E81F17D071F44D0EB3E5F621D66860C9E09A6E17</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_NCONTRIB IS

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;

end PKG_SAL_NCONTRIB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_NDREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2EF9BFD9F3D316734213A6C8940358BE566ABF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_NDREP is

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_SAL_NDREP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_RETINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52FBB632E2326A8616714858EB1E839D4E60DB81</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_RETINERI IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_SAL_RETINERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SAL_SPORURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22CD06CA075D23E18A8FE6BACCD6DB0CCE654FE3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SAL_SPORURI IS

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_SAL_SPORURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SCADENTARTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8FD37630C6A061586CC52EF69E08BB5F98F977A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ScadentarTL IS
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_ScadentarTL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42EAEA885407FE14B3CB72DE77E9215F063D502D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SCENARIILIVR IS

 procedure Set_Do_Commit(aDoCommit IN BOOLEAN);
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 PROCEDURE GOTO_ALL(G_SUBUNIT in number, aData1 in varchar2, aData2 in varchar2, NrCCli out number, NrScen out number);

end PKG_SCENARIILIVR; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SELECTARTICOLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9585579B6593D6DE70881EEA36733E0112D59C26</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SELECTARTICOLE IS

  CODCLASA NUMBER(18)   := 0;
  RETURNABIL NUMBER(1)  := 0;  -- view-uri articole daca e 1 sa aduca doar doare articole care circula in regim returnabil
  CODARTICOL NUMBER(18) := 0;
  UMPRINCIPALA NUMBER(18) := 0;
  PARITATESTOCMOMENT NUMBER(18, 7) := 1;
  COD_INTR_EXCLUS NUMBER(20) := 0; -- PENTRU VIEW-URI STOC LA MOMENT CAND EXCLUD INTRATREA PE CARE MA AFLU
  COD_TRANSF_EXCLUS NUMBER(20) := 0; -- PENTRU VIEW-URI STOC LA MOMENT CAND EXCLUD POZITIILE PROVENITE DIN TRANSFERUL PE CARE MA AFLU


  COD_OBIECT_ANALIZAT NUMBER(20) := 0; -- folosit in view-ul  V_INFO_OBJ_LUNA_LUCRU in care imi trag informatii OBIECT la nivel de luna

  OBIECT_TAXE_FACTURARE NUMBER(20) := 0; -- PENTRU VIEW-UL CARE IMI ADUCE TAXELE AFERENTE ACESTUI OBIECT PENTRU FACTURARE

  OBIECT_ECHIVALAT NUMBER(20) := 0; -- PENTRU VIEW-UL CARE IMI ADUCE ECHIVALENTELE UNUI OBIECT
  GRUPA_OBIECT_ECHIVALAT NUMBER(20) := 0; -- PENTRU VIEW-UL CARE IMI ADUCE ECHIVALENTELE UNUI OBIECT
  PARITATE_OBIECT_ECHIVALAT NUMBER(20,7) := 1;

  TYPE LUNA_REF_CURSOR IS REF CURSOR;
  TYPE NART_CURSOR IS REF CURSOR;
  TYPE NARTOBJ_CURSOR IS REF CURSOR;
  TYPE OBJ_STOCINFO_CURSOR IS REF CURSOR;

  PROCEDURE SETOBIECTANALIZAT(aCODOBIECT IN NUMBER);
  FUNCTION GETOBIECTANALIZAT RETURN NUMBER;

  PROCEDURE SETCLASA(CLASA IN NUMBER);
  FUNCTION GETCLASACURENTA RETURN NUMBER;
  FUNCTION CONDITIECLASA(OCLASA IN NUMBER) RETURN NUMBER;

  PROCEDURE SETCODART(ART IN NUMBER);
  FUNCTION GETCODARTCURENT RETURN NUMBER;
  FUNCTION GETDENOBIECT(OBIECT IN NUMBER) RETURN VARCHAR;
  FUNCTION GETDENOBIECTEXT(OBIECT IN NUMBER) RETURN VARCHAR;
  FUNCTION GETDEN_ART_OBJ(DENART IN VARCHAR, OBIECT IN NUMBER) RETURN VARCHAR;

  FUNCTION GETOBIECTIMPLICIT(
    ARTCOD IN   NUMBER,
    UMAMBALARE  OUT NUMBER,
    ZILEPLATA   OUT NUMBER,
    TIPPRETMAX  OUT NUMBER,
    PRETMAXIMAL OUT NUMBER,
    PROCADAOS   OUT NUMBER,
    CODEXTERN   OUT VARCHAR2,
    CODINTERN   OUT VARCHAR2,
    BLOCAT      OUT NUMBER,
    ROTUNJIRE   OUT NUMBER
  ) RETURN NUMBER;

  PROCEDURE SETUMPRINCIPALA(UMP IN NUMBER);
  FUNCTION CONDITIEUMPRINCIPALA(UMP IN NUMBER) RETURN NUMBER;

  FUNCTION GET_RECORD_NART(ACODART IN NUMBER) RETURN NART_CURSOR;
  FUNCTION GET_RECORD_NARTOBJ(ACODOBIECT IN NUMBER) RETURN NARTOBJ_CURSOR;
  FUNCTION GET_RECORD_NART1(ACODART IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NART_CURSOR;
  FUNCTION GET_RECORD_NARTOBJ1(ACODOBIECT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NART_CURSOR;


  FUNCTION GETARTOFOBJECT(CODOBJ IN NUMBER) RETURN NUMBER;
  FUNCTION GETCLASAOFART(CODART IN NUMBER) RETURN NUMBER;

  FUNCTION GETPROCENTTVA(CODART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER;
  FUNCTION GETRECORDTVA(CODART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN LUNA_REF_CURSOR;
  FUNCTION GETPROCTVALUNALUCRU(CODART IN NUMBER) RETURN NUMBER;

  FUNCTION GETRECORDIOART(IOARTCOD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN LUNA_REF_CURSOR;

  FUNCTION GET_INFO_OBIECT_LUNA(aCODOBIECT IN NUMBER) RETURN NARTOBJ_CURSOR;

  PROCEDURE SETPARITATESTOCMOMENT(PARITATE IN NUMBER);
  FUNCTION GETPARITATESTOCMOMENT RETURN NUMBER;

  FUNCTION GETDENGEST(GEST IN NUMBER) RETURN VARCHAR;
  FUNCTION GETDENIOART(IOART IN NUMBER) RETURN VARCHAR;

  PROCEDURE SETCODINTREXCLUS(COD IN NUMBER);
  FUNCTION GETCODINTREXCLUS RETURN NUMBER;
  FUNCTION EXCLUDSTOCDININTRAREA(ACODINTR IN NUMBER) RETURN NUMBER;

  PROCEDURE SETCODTRANSFEXCLUS(COD IN NUMBER);
  FUNCTION GETCODTRANSFEXCLUS RETURN NUMBER;
  FUNCTION EXCLUDSTOCDINTRANSFERUL(ACODTRANSF IN NUMBER) RETURN NUMBER;
  FUNCTION EXCLUDSTOCDINTRANSF1(ACODTRANSF1 IN NUMBER) RETURN NUMBER;

  FUNCTION GET_JUST_DENOBIECT(OBIECT IN NUMBER) RETURN VARCHAR;

  FUNCTION GETINFOSTOC(ACODOBIECT IN NUMBER) RETURN OBJ_STOCINFO_CURSOR;
  FUNCTION ARTICOLPROMOTIONAL(aCODOBIECT IN NUMBER, aPROCDISC OUT NUMBER) RETURN NUMBER;

  FUNCTION ARTICOLPROMOTIONALRETAIL(aCODOBIECT IN NUMBER, aCODPOSTRETAIL IN NUMBER, aPROCDISC OUT NUMBER) RETURN NUMBER;

  PROCEDURE SET_OBIECT_TAXE_FACTURARE(aOBIECT IN NUMBER);
  FUNCTION GET_OBIECT_TAXE_FACTURARE RETURN NUMBER;

  PROCEDURE SET_OBIECT_ECHIVALAT(aOBIECT IN NUMBER);
  FUNCTION GET_OBIECT_ECHIVALAT RETURN NUMBER;
  FUNCTION GET_GRUPA_OBIECT_ECHIVALAT RETURN NUMBER;
  FUNCTION GET_PARITATE_OBIECT_ECHIVALAT RETURN NUMBER;

  FUNCTION GETGRUPAOBIECT(aCODOBIECT IN NUMBER) RETURN VARCHAR2;

  FUNCTION OBIECT_IMPLICAT_IN_TRANZACTII(aCODOBIECT IN NUMBER) RETURN NUMBER;
  FUNCTION CHECK_TABLE_FOR_OBIECT(aTABLENAME IN VARCHAR2, aCODOBIECT IN NUMBER ) RETURN NUMBER;

  PROCEDURE SETRETURNABIL(aRETURNABIL IN NUMBER);
  FUNCTION CONDITIERETURNABIL(aRETURNABIL IN NUMBER) RETURN NUMBER;
  PROCEDURE MAKE_DEN_OBIECTE_CU_ATRIBUTE;

  FUNCTION CLASA_OBIECT_VALID_PE_LOCATIE (aCODLOCATIE IN NUMBER, aCODCLASA IN NUMBER, aCODOBIECT IN NUMBER) RETURN NUMBER;
END PKG_SELECTARTICOLE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F218901158D01ECC431B062EA64BCD92644A9531</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SERII IS

OBIECTCURENT NUMBER(20) := 0;

PROCEDURE SET_SEQ_SERIE_UNICA(NR IN NUMBER);
FUNCTION GetMascaLastSerie(aMasca in varchar2) RETURN varchar2;
PROCEDURE SETOBIECTCURENT(ACODOBIECT IN NUMBER);
FUNCTION GETOBIECTCURENT RETURN NUMBER;

PROCEDURE SP_LOCKRECORD(RECID IN NUMBER); 
PROCEDURE SP_INSERTRECORD; 
PROCEDURE SP_DELETERECORD(RECID IN NUMBER); 
PROCEDURE SP_GOTORECORD(RECID IN NUMBER);
PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER);

END PKG_SERII; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7729664948DA27E16E6979350F297146EC934F5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SERTAR IS
  
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

END PKG_SERTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SERVFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A677A599F3A3C8124B14A21627D39F3022E296B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SERVFACT IS
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );

end PKG_SERVFACT; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SERVICE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94429FC0069D0265A1B5DEE728F81967E8D1AB08</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SERVICE IS

  TIPJURNAL NUMBER(10) := 0; -- imi spune daca aduc doar documentele DIRTY sau toate; Daca este &lt;&gt; 0 atunci e dirty;

  PROCEDURE KEEP_ALIVE;
  PROCEDURE UNLOCK_USER_RECORDS;
  PROCEDURE SETZERORECORDS;
  PROCEDURE SET_TIP_REFACERE_JURNAL(TIP IN NUMBER);
  PROCEDURE MAKE_MANEVRA_DIRTY_DOCS;
  FUNCTION IS_DIRTY_DOC(aTIPDOC IN NUMBER, aCODDOC IN NUMBER, aTIPDOC1 in Number default 0) RETURN NUMBER;

  PROCEDURE CLEAR_RULAJE_FOR_JURNAL;
  PROCEDURE GET_INTRARI_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_IESIRI_FOR_JURNAL (STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_IESIRI_FOR_COEFDISCMAJ(aAN NUMBER, aLUNA NUMBER);

  PROCEDURE GET_INTERNE_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_MIFIX_FOR_JURNAL  (STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_TREZOR_FOR_JURNAL (STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_COMPENS_FOR_JURNAL (STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_NC_FOR_JURNAL (STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_REGPERS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_REGOSS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);

  PROCEDURE GET_DOCUMENTE_FOR_JURNAL;


  FUNCTION GET_INTRARI_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_IESIRI_RECORDCOUNT  RETURN NUMBER;
  FUNCTION GET_INTERNE_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_MIFIX_RECORDCOUNT   RETURN NUMBER;
  FUNCTION GET_TREZOR_RECORDCOUNT  RETURN NUMBER;
  FUNCTION GET_COMPENS_RECORDCOUNT  RETURN NUMBER;
  FUNCTION GET_NC_RECORDCOUNT  RETURN NUMBER;
  FUNCTION GET_PRODNET_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_DISTRIBCHELT_RECORDCOUNT RETURN NUMBER;

  FUNCTION GET_CONTRACT_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_REG_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_REGTREZOR_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_REGPERS_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_REGOSS_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_NOTECREDIT_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_POSTCALCUL_RECORDCOUNT RETURN NUMBER;
  FUNCTION GET_DIFPretPROD_RECORDCOUNT RETURN NUMBER;

  PROCEDURE CLEAR_DIRTY_FLAGS;
  FUNCTION  GET_CHELTAVANS_RECORDCOUNT(flg_ISVENIT IN NUMBER) RETURN NUMBER;
  PROCEDURE GET_CHELTAVANS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER, flg_ISVENIT IN NUMBER);
  PROCEDURE GET_REG_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_REGTREZOR_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_NOTECREDIT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_CONTRACT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_PRODNET_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_DISTRIBCHELT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_POSTCALCUL_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);
  PROCEDURE GET_DifPretProd_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER);

  PROCEDURE REPARTIZARE_SOLDURI_RULAJE(aSUBUNIT IN NUMBER);


  PROCEDURE CHECK_REGUL_LUNA;
  PROCEDURE CHECK_REGULTREZOR_LUNA;
  PROCEDURE CHECK_REGULPERS_LUNA;
  PROCEDURE CHECK_REGULOSS_LUNA;

  PROCEDURE DoMonitor (codExternMonitor varchar2,Obs IN varchar2 default &apos; &apos;, IDVer in number default 0);
  function LoWord(Nr in number) return number;
  function HiWord(Nr in number) return number;
  PROCEDURE ACT_STOC_MEDIU ;
  PROCEDURE CALCUL_NIRSTOC_PUVAL;
  PROCEDURE CHECK_STRUCT_EXTENSIE_TASK;
  PROCEDURE INDEXARE_EXTENSII;

END PKG_SERVICE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SERVPOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDA98734294EBFDF70F8E3840A9EBAA3123F8E08</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SERVPOST IS

  procedure SP_GoToRecord(RecId in number);
  procedure SP_LockRecord(RecId in number);
  procedure SP_PostRecords(Operation in number, RecId out number);
  procedure SP_DeleteRecord(RecId in number);
  procedure SP_InsertRecord;

end PKG_SERVPOST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SETLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F71C3BF38871404201C208BC4EDB2AC2630B23CD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SETLISTE IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end pkg_SetListe; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SETLUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>509317C73B951966075E6A042717FCA4D5E02F63</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SETLUNI IS
  procedure SetLunaCurenta(An in Number, Luna in Number);
  procedure GetLunaCurenta(An out Number, Luna out Number);

  procedure SetLunaInitiala(An in Number, Luna in Number);
  procedure GetLunaInitiala(An out Number, Luna out Number);

  procedure SetLunaMaxima(An in Number, Luna in Number);
  procedure GetLunaMaxima(An out Number, Luna out Number);

  procedure CreazaLunaMaxima(An in Number, Luna in Number);

      
end PKG_SETLUNI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SETTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83636F6CEFBC9C7CD807C5BF854829A57EBBBB2F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_settask IS

  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
--  PROCEDURE REMAKE_SEQUENCE(NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2,NUME_SEQ IN VARCHAR2, SKEMA IN VARCHAR2);
--  PROCEDURE SETGRANTMODUL( NumeModul IN VARCHAR2, FIRMA IN VARCHAR2);
  FUNCTION ObjExists (tmpName IN Varchar2, Tip in varchar2) RETURN NUMBER;
  PROCEDURE CHECK_STRUCT_EXTENSIE(CODSKEMA IN NUMBER);
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  procedure BagaInTaskLog(CODLOG in number,CODTASK in number,DATA in date,USER_SRC in varchar2,USER_DST in varchar2);
  FUNCTION TASKURI_NOI (aUserName varchar2) return number;
  PROCEDURE IMPORTXLS(
    aSUBUNITATE    in varchar2,
    aRESPONSABIL  in varchar2,
    aPROBLEMA    in varchar2,
    aDATACREARE  in varchar2,
    aCONSTRUCTOR in varchar2,
    aJUDET_C     in varchar2,
    aPROIECTANT  in varchar2,
    aNRPROIECT   in varchar2,
    aPROIECT     in varchar2,
    aJUDET_P     in varchar2,
    aSTADIU      in varchar2,
    aBENEFICIAR  in varchar2,
    aAREGEO      in varchar2,
    aVALOARE     in varchar2,
    aNROFERTA    in varchar2,
    aDATAOFERTA  in varchar2,
    aDATACONTACT in varchar2,
    aDATACT      in varchar2,
    aCOMENTARII  in varchar2,
    aOBSERVATII  in varchar2,
    aDVOBSERVATII in varchar2,
    aCASTIGATOR  in varchar2,
    aACTIUNI     in varchar2,
    aFORECAST    in varchar2
  );
  procedure import_date;

end pkg_SetTASK; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2EEADED8615B0A99E5BECE7DE37B31DDBD95420</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SGRCOLECT is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
end PKG_SGRCOLECT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SIMLANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DDB25E00B52E3BFE7ABF92C8FEFE06F454301D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SIMLANS IS

  procedure UpdataDataStocPlus(SCENARIU in number);
  procedure LoadScenariiLivr(aCodScenariu in number);
  procedure Populeaza_TMPURI( G_SUBUNIT in number,DataLivrS in varchar2,  DataLivrF in varchar2,DataCmdS  in varchar2,  DataCmdF  in varchar2, SCENARIU in number default 0, vCodComanda1 in number default 0);

end PKG_SIMLANS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17AFBA453746DF975C31723EF86D2B2412CF19CA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SITFIN IS

  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  
  procedure TESTCOLOANE(aCodSitFin in number);
  FUNCTION EVALUATE(Expr IN VARCHAR2, Val OUT NUMBER ) RETURN BOOLEAN;
  FUNCTION GetExprPrelucrata(Expr IN VARCHAR2) RETURN VARCHAR2;
  FUNCTION BOOL_EVALUATE(Exp in varchar2) RETURN NUMBER;
  FUNCTION GetCodSitFinByCodF(aCodF in varchar2) RETURN NUMBER;
end pkg_sitfin;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SMS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6784CF435653554C0699AAA85BF76126F112133A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SMS is

	SMS_PROVIDER      VARCHAR2(100) := &apos;?&apos;;                         
	SMS_URL           VARCHAR2(500) := &apos;?&apos;;                         
	SMS_METODA        VARCHAR2(100) := &apos;?&apos;;                         
	SMS_CONTENT_TYPE  VARCHAR2(100) := &apos;?&apos;;                         
	SMS_CONTENT_VALUE VARCHAR2(100) := &apos;?&apos;;                         
	SMS_FROMVALUE     VARCHAR2(100) := &apos;?&apos;;                         
	SMS_CHKSUM_PARAM  VARCHAR2(200) := &apos;?&apos;;                         
	SMS_JSON_PARAM    VARCHAR2(200) := &apos;?&apos;;                         
	SMS_JSON_DATA     VARCHAR2(200) := &apos;?&apos;;                         
	SMS_ERR_MARKER    VARCHAR2(100) := &apos;?&apos;;                         
  API_Key    VARCHAR2(1000) := &apos;?&apos;;
  API_Secret VARCHAR2(1000) := &apos;?&apos;;

FUNCTION md5hash (str IN VARCHAR2) RETURN VARCHAR2;
FUNCTION SEND_SMS_Full(NRTELEFON IN VARCHAR2, aMESAJ IN VARCHAR2, aNume IN VARCHAR2, aCodDoc in Number, aCodDoc1 in Number, aTipDoc in Number, ForceResend in number, MSG_EROARE OUT VARCHAR2, vNoCommit in number default 0) RETURN NUMBER;
--FUNCTION SEND_SMS_ORANGE(USERNAME IN VARCHAR2,AUTHKEY IN VARCHAR2, SENDER IN VARCHAR2, NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2, HOST_PORT IN VARCHAR2) RETURN NUMBER;
FUNCTION SEND_SMS_ORANGE(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2, MSG_EROARE OUT Varchar2) RETURN NUMBER;
FUNCTION SEND_SMS_ADVERT(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2,  MSG_EROARE out VARCHAR2) RETURN NUMBER;
FUNCTION SEND_SMS_CENTRALATELEFONICA(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2,  MSG_EROARE out VARCHAR2) RETURN NUMBER;


end PKG_SMS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SOLDINITIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD3945E7CA013A122E8EA90A01E2DF55CED67AF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SOLDINITIAL IS
 OLDCODPART NUMBER(20) := 0;

 FUNCTION SOLD_INI_STINSE(aCODPART IN NUMBER) RETURN NUMBER;
 FUNCTION LINII_AVIZE_INI_STINSE(aCODPART IN NUMBER) RETURN NUMBER;
 PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
 PROCEDURE SP_INSERTRECORD;
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
END PKG_SOLDINITIAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SOLDPERSINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5EB73564D08CCE05B06F7944B3D0DF71DEC0397</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SOLDPERSINI IS
  PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
END PKG_SOLDPERSINI; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>257EA7C702EE7F690F3BB004AB73F28C39512EC5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SPLITCHELT IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  
END pkg_SPLITCHELT; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SPLITTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF731F8D5F7A2198762E6B7670FD6C4DD9C700DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SPLITTVA is
  PROCEDURE SPLITTVA_OBLIGPART_INTRARI(aCODPART IN NUMBER);
  FUNCTION TVASTINS_OBLIG_BEFORE_SPLIT(aCODOBLIGPIF  IN NUMBER, VALOBLIG IN NUMBER, TVAOBLIG IN NUMBER) RETURN NUMBER;


  PROCEDURE MAKE_DINCARETVA_LUNA(aCODPART IN NUMBER);
  PROCEDURE MAKE_DINCARETVA_LUNA_ALL(aCODPART IN NUMBER);
end PKG_SPLITTVA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SPVARHIVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A9D3785DFC1F30EB0CBFAB31FDBA60B5B545998</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_SPVARHIVA is

procedure CheckNewData; 
end PKG_SPVARHIVA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STATCON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CA57C77FF05FC3C018DEB697DD38400747AF8FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_StatCon is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_StatCon; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STATCOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1062A02D298175C3628A1C1F59B4CB5CA03D673</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_StatCor is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_StatCor; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STOCINIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33598AD950F25261DD694503AF8E0610C6320A3A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STOCINIART
IS
 PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
 PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
 PROCEDURE SP_INSERTRECORD; 
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 procedure PropagaFurn(acodnirstoc in number, afurn in number);

end PKG_STOCINIART; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STOCINITIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E78ECB3D2750E7E46861C257F0C658BD0F97AABC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STOCINITIAL
IS
 PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
 PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
 PROCEDURE SP_INSERTRECORD; 
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER ); 
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );


 FUNCTION CAN_LOCK_CODGEST(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER;
 PROCEDURE UNLOCK_CODGEST(aUSERID IN NUMBER);
 PROCEDURE TEST;
 procedure PropagaFurn(acodnirstoc in number, afurn in number);
END PKG_STOCINITIAL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STOCPOSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8A4E75FA48CC6F9BEE9BBD1B9FA157E85D62821</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STOCPOSURI IS
 CODCATPRETPOSURI NUMBER(20) := 0;

 PROCEDURE SET_CATPRET_POSURI(aCATPRET IN NUMBER);
 PROCEDURE SP_GOTO;
 PROCEDURE SP_POST;
end PKG_STOCPOSURI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STOCVALINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3739540EB7A7F12CFA03EF94B3F5DE415DDB38B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STOCVALINI IS

PROCEDURE SP_LOCKRECORD (RecId IN NUMBER);
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_GOTORECORD (RecId IN NUMBER);
PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
end PKG_STOCVALINI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STOC_GENERARE_FACTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E4F0DDE38D377DF723FA66914D3E6385141FCB1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STOC_GENERARE_FACTURI IS
  INTERFACEFILTER    VARCHAR(1000) := &apos;&apos;;
  FILTRUMEDEX        VARCHAR(1000) := &apos;&apos;;
  INCLUSIV_STOC_ZERO NUMBER(1) := 0;
  MODLIVRAUTOMATA    NUMBER(4) := 0; -- FIXEAZA ORDER BY LA ADUCERE STOC
                                     -- 0 = FEFO
                                     -- 1 = FIFO
  CODLINIECOMANDA NUMBER(20) := 0;

  PROCEDURE SET_INTERFACE_FILTER(aFILTER IN VARCHAR2);
  PROCEDURE SET_MOD_LIVRARE_AUTOMATA(aMODLIVRARE IN NUMBER);
  PROCEDURE SET_CODLINIECOMANDA(aCODLINIECOMANDA IN NUMBER);
  PROCEDURE SET_FILTRU_MEDEX(aFILTER IN VARCHAR2);
  PROCEDURE SET_INCLUSIV_STOC_ZERO (aFLAG NUMBER);
  PROCEDURE make_config_luna;
  PROCEDURE make_STOC_GENERARE_FACTURI;
  PROCEDURE DropViewStoc;
  PROCEDURE POSTDISCLIKISTOC;
  PROCEDURE POSTSTARE;
  PROCEDURE FILLCODIOARTCORESP;
  PROCEDURE make_config_luna_EXT;
  PROCEDURE TestARE;
END PKG_STOC_GENERARE_FACTURI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_STRUCTURARETRASEU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F35070ED4DE54077C196D5D8FCE2D4FA794A0C3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_STRUCTURARETRASEU IS
  PROCEDURE PRELUARE_TRASEU(aTraseu IN NUMBER);
  PROCEDURE SALVARE_TRASEU(aTraseu IN NUMBER);
END PKG_STRUCTURARETRASEU;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_SUBSIDIARY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D2E21AFBB7F658427B1307F4CA11FE93769CAF7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_subsidiary IS
  PROCEDURE UMPLE_TMP(
    sDataIni IN VARCHAR2,
    sDataFin IN VARCHAR2,
    bOrder   IN BOOLEAN,
    bInvoice IN BOOLEAN,
    bStock   IN BOOLEAN DEFAULT FALSE);

  PROCEDURE AUX_TMP(
    sTMP      IN  VARCHAR2,
    sHeader   OUT VARCHAR2,
    sFooter   OUT VARCHAR2,
    sFileName OUT VARCHAR2
  );

  FUNCTION Get_zcliehier3(pCodPart NUMBER) RETURN VARCHAR2;
  FUNCTION getCursorTmp(pTMP IN  VARCHAR2) RETURN SYS_REFCURSOR;
  PROCEDURE EXPORT_ZILNIC(bStock IN BOOLEAN DEFAULT FALSE);
  PROCEDURE EXPORT_LUNAR(bStock IN BOOLEAN DEFAULT FALSE);
END pkg_subsidiary;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TARGETAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFD15045489680121D20E43BE1256476D094B44E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TARGETAG IS

  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

  FUNCTION  LIMITE_INTERVAL(  aCODSubunit IN NUMBER, aCODTARGETAG IN NUMBER, 
                              aAGENT IN NUMBER, 
                              aCLIENT IN NUMBER, 
                              aClasaPart IN NUMBER, 
                              aDATASTART IN OUT VARCHAR2, aDATASTOP IN OUT VARCHAR2, aTipTarget IN NUMBER) RETURN NUMBER ;

END PKG_TARGETAG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>313EFE291B2EC7D1F7711B68FA5CFEAD2436809B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TARI IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END pkg_Tari; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TARIFEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>434F58C8DBFF3D3D8800D7ECA22E699AD82505A2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TARIFEMAN IS

 PROCEDURE SET_VARIABILE(aOwner in varchar2); 

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD;
 PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
 PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );

end pkg_tarifeman; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TAXE_ACCIZE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C736CCA2FD2D1D193E4E52E8391B35100A15A836</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TAXE_ACCIZE IS
PROCEDURE PREGATESTE_TEMPORAR_ACCIZE(aTip in number);

end PKG_TAXE_ACCIZE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TEME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE8C5A1F699A087CF8CED6B8FB0E51B0D5C82418</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TEME IS

  PROCEDURE TEME_GETPERS;
  PROCEDURE TEME_GOTORECORD;
  PROCEDURE TEME_POSTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_TEME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TESATURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BE6D298E13BA22FF0EC830417D8C156EE7C0A96</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TESATURI is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_TESATURI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TIPCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E06FEEB3DAA9E507F56FBC4827ADE7DC1438AAE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TIPCHELT IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );


end pkg_tipChelt; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TIPLUCRARISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49DF33BDF266614CCBEE5A542788D273D76A3360</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TipLucrariSA IS

  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

end PKG_TipLucrariSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TIPPARTINCERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>549E9EB2F5293CE87935F247AF2540114D8DD341</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TIPPARTINCERT is
  PROCEDURE SP_GOTORECORD(RecId IN NUMBER);
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER);
  PROCEDURE SP_DELETERECORD(RecId IN NUMBER);
  PROCEDURE SP_INSERTRECORD;

end PKG_TIPPARTINCERT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TIPSEDII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B14841F859646CBA2F61773C16906B4F2D7B5A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TIPSEDII IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
END PKG_TIPSEDII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TRANSEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>781151197D8CDE5A9832B8F667BD9FC89ED59756</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TRANSEINI IS
  I NUMBER(20); 
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;   
end PKG_TRANSEINI; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3794F8046D67A26683A96AF4FD32B70DB76E28B8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TRANSPORT IS

 procedure SetValSuplimInDVI(aCodIntr in number, aTipRepart in number, aValSuplim in number);
 procedure SETVARSUPLIM(aStareRepartizare in number, aTipRepart in number, aValSuplim in number);
 procedure GETVARSUPLIM(aStareRepartizare out number, aTipRepart out number, aValSuplim out number);
 function GETSTAREREP return number;
 procedure SETSTAREREP(aStareRepartizare in number);
 function GetValServ(aCodIntr IN NUMBER) return number;
 function GetMasaFactIntr(aCodIntr IN NUMBER) return number;
 function GetVolumFactIntr(aCodIntr IN NUMBER) return number;
 Procedure GetDataTransportIndicativ;
 
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
 PROCEDURE SP_INSERTRECORD; 

end pkg_transport; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TRASEULIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF68D308C186A3B5C35665362284D76DD5915E84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TRASEULIVR IS

  -- Author  : DANIEL.LACATUSU
  -- Created : 26.02.2010 19:40:02
  -- Purpose : Trasee Livrare
  procedure ClearTemps;
  procedure SP_GOTORECORD(RecId in number);
  procedure SP_LOCKRECORD(RecId in number);
  procedure SP_POSTRECORDS(Operation in number, RecId out number);
  procedure SP_DELETERECORD(RecId in number);
  procedure SP_INSERTRECORD;
  
  procedure CLEAR_LOCK_COMENZI;
  
  function LOCK_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number, aCC in boolean, aCS in boolean, aCG in boolean, aFromManevra in number) return varchar2;
  --procedure UNLOCK_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number);
	
	function GET_SysDate return varchar2;
  
  procedure GET_TMP_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number, aCC in boolean, aCS in boolean, aCG in boolean);
  
  procedure GET_TMP_TOTALART(peEchiv boolean default false);
	-- procedure GET_TMP_TOTALART(aDate in varchar2, aDateEnd in varchar2, aSubunit in number);
  procedure GET_TMP_COMENZICLIENTI(peEchiv boolean default false);
	-- procedure GET_TMP_COMENZICLIENTI(aDate in varchar2, aDateEnd in varchar2, aSubunit in number);
	procedure GET_TMP_INFOCOMANDA(aCodComanda in number);
	procedure GET_TMP_INCARCARE;
	procedure GET_TMP_DETALIIDISTRIB;
  procedure GET_TMP_ARTICOLELIVRATE;
  -- procedure GET_TMP_ARTICOLELIVRATE(aDate in varchar2, aDateEnd in varchar2, aSubunit in number);
  procedure GET_TMP_TRASEUART(aCodTraseu in number, aCodObiect in number);
  
  procedure SET_ACCEPTAT;
  -- procedure UPDATE_TMP_INCARCARE;
  -- procedure UPDATE_TMP_ARTICOLELIVRATE(aDate in varchar2, aDateEnd in varchar2, aSubunit in number);
  
  procedure UPD_COMENZICLIENTI(aDateInc in varchar2, aCheckFlagLucru in number);
  procedure UPD_TRASEECLIENTI;

end PKG_TRASEULIVR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7F4DFFF3F347C820FF4DDD62D03B9B1CF565FAF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TREZOR IS
  CARNETDOC_I NUMBER(20);
  NRDOC_I     NUMBER(20);
  
  SkipAnalizaSold NUMBER(1) := 0;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  FUNCTION OBLIGATIE_STINSA(aCODOBLIGPIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_STINS_OBLIGATIE(aCODOBLIGPIF IN NUMBER) RETURN NUMBER;
  FUNCTION TOTAL_STINS_TVA(aCODOBLIGPIF IN NUMBER) RETURN NUMBER;
  FUNCTION EXISTADOCUMENTUL(CODDOC IN NUMBER) RETURN NUMBER;
  PROCEDURE SP_POSTRECORD_FROM_IMPORT( RecId OUT NUMBER );
  FUNCTION GETGESTEVIDENTA(aGEST IN NUMBER) RETURN VARCHAR2;
  FUNCTION OPERAT_ANULAT_OK(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN NUMBER;
  FUNCTION GETDENPARTDIECTPECONT (aCODPART IN NUMBER) RETURN VARCHAR2;
--  FUNCTION GETSIMBOLCONSTANTACEC(aSEMNIFICATIE IN NUMBER, aTIPDECONT IN NUMBER, aCODIOBANK IN NUMBER) RETURN VARCHAR2;
  FUNCTION CODCONTCEC(aCODNBANKCONT IN NUMBER, aSEMNIFICATIE IN NUMBER, aTIPDECONT IN NUMBER, aOBIECTTRANZ IN NUMBER, pAn IN NUMBER DEFAULT NULL, pLuna IN NUMBER DEFAULT NULL) RETURN NUMBER;
  FUNCTION SIMBOLCONTCEC(aCODNBANKCONT IN NUMBER, aSEMNIFICATIE IN NUMBER, aTIPDECONT IN NUMBER, aOBIECTTRANZ IN NUMBER, aAn IN NUMBER DEFAULT NULL, aLuna IN NUMBER DEFAULT NULL) RETURN VARCHAR2;

  PROCEDURE UPDATE_VALTRANZ_STINGERI(RECID IN NUMBER);
  FUNCTION PRELSERIADOC(aSERIADOC VARCHAR2) RETURN VARCHAR2;
  PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER);
  PROCEDURE SET_SKIPANALIZASOLD(FLAG IN NUMBER);

-- folosita la verificarea valabilitatii consent-lui bancar pentru citire tranzactii; folosit pentru API Libra si API SmartAccounts 
  PROCEDURE SAVE_CONSENT_INFO(aTipAPI IN NUMBER, aIBAN IN VARCHAR2, aTOKEN IN VARCHAR2, aConsentID IN VARCHAR2, aExternalID IN VARCHAR2);   
  PROCEDURE CUMULEAZA_EXTRASE(aCodMaster in number, aTipDoc in number, aCodBanca in number, aCodSubunit in number, aDataDoc in varchar2);

end PKG_TREZOR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TRIGAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70B9F5BB0A304C12FFF037DC0BF599C9A70D78B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TRIGAR IS
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION  GET_DDL( RecId IN NUMBER, pPrefix IN VARCHAR2) RETURN CLOB;
  FUNCTION GET_DDL_ACTIV( RecId IN NUMBER, pPrefix IN VARCHAR2) RETURN CLOB;
  PROCEDURE SET_DDL_TRG(RecId IN NUMBER, pPrefix IN VARCHAR2);

  procedure TaskToUser(acodUser in number, aCodPArt in number, aPROBLEMA in varchar2, SursaMesaj in varchar2, FaraCommit in number default 0);
  procedure TaskToPers(aCodPers in number, aCodPArt in number, aPROBLEMA in varchar2, SursaMesaj in varchar2);
	procedure MessageToPers(aCodPers in number, Mesaj in varchar2, SursaMesaj in varchar);
	procedure MessageToUser(acodUser in number, Mesaj in varchar2, SursaMesaj in varchar);
	procedure SendSMS(NrTelefon in varchar2, Mesaj in varchar2, NoCommit in number default 0);
	procedure SMSToPart(aCodPart in number, Mesaj in varchar2);
	procedure SMSToPers(aCodPers in number, Mesaj in varchar2, NoCommit in number default 0);
	procedure SMSToUSER(aCodUSER in number, Mesaj in varchar2, NoCommit in number default 0);
  PROCEDURE BAGA_IN_TRIGAR_MODIF(aUserID in number, aCodMaster in number, aCod in number, aTableName in varchar2, aFieldName in varchar2, aOldValue in varchar2, aNewValue in varchar2);
	
END PKG_TRIGAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_TVASERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>961F20EBFFE1A3CBC42C4592749406F1F3660732</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_TVASERV is

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_TVASERV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_UM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37E1AF34E39F14C921243D776280153AE881861C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_UM IS
--  g_codum1 NUMBER(18) := 0;
  function GetCoefUM(aCodUM1 in number) return number;
  function GetSpecificCantUM(aUM in number, aUM1 in number, aPrincipala in number, aPrincipala1 in number,
                             aRel in number, aD1 in number, aD2 in number, aD3 in number, aCant1 in number, aCoef in number) return number;
  function  GetSpecificCantUM1(aUM in number, aUM1 in number, aPrincipala in number, aPrincipala1 in number,
                               aRel in number, aD1 in number, aD2 in number, aD3 in number, aCant in number, aCoef in number) return number;                           
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION TEST_UNICITATE_UM(DenUM IN varchar2, Cod IN NUMBER) RETURN NUMBER;
END pkg_Um;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14746C215A1975E2781901032F2D5DF0BFDAEFEB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_UMSEC IS
  g_codum1 NUMBER(18) := 0;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  FUNCTION GETDENUM(ACODUM IN NUMBER) RETURN VARCHAR;
  /* ADUCE CODUM1 DIN NUM1 PENTRU UN CODUM SI O DENUMIRE */
  PROCEDURE GetUMSecDupaDEN(ACODUM IN NUMBER, DEN IN VARCHAR, ACODUMSEC OUT NUMBER);
  /* ADUCE CODUL SI DENUMIREA DIN NUM1 CE CORESPUND UNEI UMPRINCIPALE DIN NUM*/
  PROCEDURE GETINFOUMIMPLICITA(ACODUM IN NUMBER, CODUMSEC OUT NUMBER, DEN OUT VARCHAR);
  /* ADUCE CODUL DIN NUM1 CE CORESPUNDE UNEI UMPRINCIPALE DIN NUM*/
  FUNCTION GETCODUMIMPLICITA(ACODUMPRINCIPALA IN NUMBER) RETURN NUMBER;
  /* ADUCE DIN NUM1 DENUMIRE  SI PARITATE PENTRU UN CODUM1*/
  PROCEDURE GETINFOUMSEC(ACODUMSEC IN NUMBER, DEN OUT VARCHAR, PARIT OUT NUMBER);
  /* ADUCE DIN CODUL UMPRINCIPALA CORESPUNZATOR UNEI UMSECUNDARE*/
  FUNCTION GETCODUMPRINCIPALA(ACODUM1 IN NUMBER) RETURN NUMBER;

END PKG_UMSEC; 

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62C3DD96C86C7A5F986F0AE6510FB6D024963A7F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_UTILAJE IS

  procedure GENUTILAJ(vCodObiect in number, vUM in number, vCodPart in number);
  function AduUltimaCitire(aCodUtilaj in number, pTipIndex in number default 0 ) return number;
  PROCEDURE SETCODUTILAJ2C( aCodUtilaj2C IN NUMBER ); 
  function GETCODUTILAJ2C return number;
  function GetSectieInterventie(aCodProdComp in number) return number;
  function GetDenSectieInterventie(aCodProdComp in number) return varchar2;
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER);
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
  procedure ImportXLS;
  procedure Test;
  PROCEDURE GETLASTAPELURI(NRAPELURI IN NUMERIC);
  PROCEDURE POSTAPELURI;
end PKG_UTILAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_VANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DDBEACD84DF6D7C248B58E71404DF145C6B2B88</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_VANZARI is
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
PROCEDURE SP_INSERTRECORD;
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER );
PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
end PKG_VANZARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_VENITAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3CE881533B43B74ED57C108BCC5E202EA1F43F7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_VENITAVANS_INI is
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_VENITAVANS_INI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87B2A301012DE4896F16B40361ABBF8A8CBCD185</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_VOUCHER is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

end PKG_VOUCHER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_VOUCHERCADOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCDA37193523B8588B33CB1D59450A6AF68BA531</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_VOUCHERCADOU is
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SOLVEVOUCHERCADOU(TIPOPERATIE IN NUMBER); -- 1= activare; 2=stingere )
end PKG_VOUCHERCADOU;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_WEEKCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE66EB20C247476B095C3F34D92C87110A98CBF4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_WEEKCASHFLOW is
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;
  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );

end PKG_WEEKCASHFLOW;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_WMEONLINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC591DD481DB46B90DA5075DC2253BD332A51535</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE pkg_wmeonline IS
  TYPE NPERS_CURSOR IS REF CURSOR;
  TYPE NSUBUNIT_CURSOR IS REF CURSOR;
  TYPE NGEST_CURSOR IS REF CURSOR;
  TYPE NPART_CURSOR IS REF CURSOR;
  TYPE NAGENDA_CURSOR IS REF CURSOR;
  TYPE STOC_CURSOR IS REF CURSOR;
  TYPE CMD_CURSOR IS REF CURSOR;
  TYPE CMD1_CURSOR IS REF CURSOR;
  TYPE CMD2_CURSOR IS REF CURSOR;
  TYPE PRETOFERTA_CURSOR IS REF CURSOR;
  TYPE OFERTA_CURSOR IS REF CURSOR;
  TYPE OFERTA1_CURSOR IS REF CURSOR;
  TYPE OFERTA2_CURSOR IS REF CURSOR;
  TYPE WORD_ARRAY IS TABLE OF VARCHAR2(100);
  
  FUNCTION TOKENIZE_STRING(p_list IN VARCHAR2, token IN VARCHAR2) RETURN WORD_ARRAY;

  FUNCTION GET_INFOPERS_BY_LOGONNAME(aUSERNAME IN VARCHAR2) RETURN NPERS_CURSOR;
  FUNCTION getSubunitati (pUser IN NUMBER ,pFirma IN NUMBER) RETURN NSUBUNIT_CURSOR;
  PROCEDURE SetGestiuni (pUser IN NUMBER ,pFirma IN NUMBER, aCODPERS IN NUMBER);
  
  FUNCTION COUNT_CLIENTI(aDEN_PART IN VARCHAR2, aCODFISCAL IN VARCHAR2) RETURN NPART_CURSOR;
  FUNCTION GET_CLIENTI(aDEN_PART IN VARCHAR2, aCODFISCAL IN VARCHAR2) RETURN NPART_CURSOR;
  FUNCTION GET_SEDII_CLIENT(aCODPART IN NUMBER) RETURN NAGENDA_CURSOR;
  
  FUNCTION GET_CLIENTI_AGENT(aCODPERS IN NUMBER) RETURN NPART_CURSOR;
  FUNCTION GET_SEDII_CLIENT_FOR_AGENT(aCODPART IN NUMBER,  aCODPERS IN NUMBER) RETURN NAGENDA_CURSOR;
  FUNCTION getListaGestiuni RETURN NGEST_CURSOR;
  FUNCTION GETSTOCURI(aCODPART IN NUMBER,
                      aDenObiect IN VARCHAR2,
                      aDenClasa IN VARCHAR2,
                      aCodGest IN NUMBER,
                      aCODEXTERN IN VARCHAR2,
                      aCODINTERN IN VARCHAR2)
           RETURN STOC_CURSOR;

FUNCTION GETSTOCURI_STOC0(aCODPART IN NUMBER,
                      aDenObiect IN VARCHAR2,
                      aDenClasa IN VARCHAR2,
                      aCodGest IN NUMBER,
                      aCODEXTERN IN VARCHAR2,
                      aCODINTERN IN VARCHAR2,
                      aToggleVAT IN NUMBER,
                      aCODMONEDA IN NUMBER)
           RETURN STOC_CURSOR;  
           
FUNCTION GETSTOCURI_STOC0_FARA_PARTENER(
                      aDenObiect IN VARCHAR2,
                      aDenClasa IN VARCHAR2,
                      aCodGest IN NUMBER,
                      aCODEXTERN IN VARCHAR2,
                      aCODINTERN IN VARCHAR2,
                      aToggleVAT IN NUMBER)
           RETURN STOC_CURSOR; 

FUNCTION GET_NEXT_NUMAR_DOC(aCODCARNET IN NUMBER, SERIEDOC OUT VARCHAR2) return varchar2;
FUNCTION GET_CARNET_WMEONLINE(aCODSUBUNIT IN NUMBER, TIPMACHETA IN NUMBER) RETURN NUMBER;

FUNCTION GET_COMENZI_AGENT  ( aCODPERS IN NUMBER, 
                              aDenPART IN VARCHAR2, 
                              DATASTART IN VARCHAR2,
                              aOBS IN VARCHAR2,
                              aSTARE IN VARCHAR2,
                              aNRDOC IN VARCHAR2) RETURN CMD_CURSOR;
FUNCTION GET_OFERTE_AGENT (aCODPERS IN NUMBER,  aDenPART IN VARCHAR2, aDATAREF IN VARCHAR2 ) RETURN OFERTA_CURSOR;

FUNCTION GET_OFERTE_AGENT_SI_FARA_AGENT (
aCODPERS IN NUMBER,  
aDenPART IN VARCHAR2, 
aDATAREF IN VARCHAR2,
aNRDOC IN VARCHAR2,
aDATASTART IN VARCHAR2,
aDATAEND IN VARCHAR2,
aOBS IN VARCHAR2,
aDATAOFERTA IN VARCHAR2
) RETURN OFERTA_CURSOR;

FUNCTION GET_COMENZI_CLIENT (aCODPART      IN NUMBER,
                             DATASTART     IN VARCHAR2,
                             aSEDIULIVRARE IN VARCHAR2,
                             aOBS          IN VARCHAR2,
                             aSTARE        IN VARCHAR2,
                             aNRDOC        IN VARCHAR2,
							 aFACTURABIL   IN VARCHAR2,
                             aNRI          IN VARCHAR2
                            ) RETURN CMD_CURSOR;

FUNCTION GET_COMENZI_CLIENT_INTERVAL (aCODPART      IN NUMBER,  
                             DATASTART     IN VARCHAR2,
                             DATAEND       IN VARCHAR2,
                             aSEDIULIVRARE IN VARCHAR2,
                             aOBS          IN VARCHAR2,
                             aSTARE        IN VARCHAR2,
                             aNRDOC        IN VARCHAR2,
                             aFACTURABIL   IN VARCHAR2,
                             aNRI          IN VARCHAR2
                            ) RETURN CMD_CURSOR;


FUNCTION GET_DETALII_COMANDA (aCODCOMANDA IN NUMBER) RETURN CMD1_CURSOR;
FUNCTION GET_PRET_OFERTA(aCODPART   IN NUMBER,
                         aCODMONEDA IN NUMBER,
                         aCODOBIECT IN NUMBER)
         RETURN PRETOFERTA_CURSOR;

FUNCTION GET_PRET_OFERTA_AGENT(aCODPART   IN NUMBER,
                                             aCODMONEDA IN NUMBER,
                                             aCODOBIECT IN NUMBER,
                                             aCODPERS IN NUMBER
                                            )
         RETURN PRETOFERTA_CURSOR;
         
FUNCTION GET_PRET_OFERTA_AGENT_VALUTA(aCODPART   IN NUMBER,
                                             aCODOBIECT IN NUMBER,
                                             aCODPERS IN NUMBER
                                            )
         RETURN PRETOFERTA_CURSOR;
		 
FUNCTION GET_DETALII_OFERTA (aCODOFERTA IN NUMBER) RETURN OFERTA1_CURSOR; 

FUNCTION GET_DETALII_OFERTA_TVA (aCODOFERTA IN NUMBER, aToggleVAT IN NUMBER) RETURN OFERTA2_CURSOR; 

FUNCTION GET_DETALII_COMANDA_TVA (aCODCOMANDA IN NUMBER, aToggleVAT IN NUMBER) RETURN CMD2_CURSOR;
procedure SetRecordCmdProdMat (aCodObiect in number, aCodComanda1 in number, aCant in number, aCodCmdProdMat out number);

END PKG_WMEONLINE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE</TYPE>
  <NAME>PKG_ZINELUC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CCF3A6C21F0D2E4A53CA6BFA808C9E8C4BA4E5B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE PKG_ZINELUC IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER );
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER );
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER );
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER );
  PROCEDURE SP_INSERTRECORD;

  FUNCTION GET_DATAFIN( vDataStart IN DATE, vZile IN NUMBER) RETURN DATE;
  FUNCTION GET_DATAFIN_STRING( vDataStart IN VARCHAR2, vZile IN NUMBER) RETURN VARCHAR2;

end pkg_ZINELUC; 
 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>ORA_EXCEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FDFCEFD15CF71413F2C47A46F593C2B0567C946</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY ORA_EXCEL IS

    PROCEDURE print_clob (p_clob IN CLOB, filename VARCHAR2)
    AS
       l_offset   NUMBER DEFAULT 1;
    BEGIN
       RETURN;
       dbms_output.put_line(filename);
       LOOP
          EXIT WHEN NVL(l_offset,1) &gt; DBMS_LOB.getlength (p_clob);
          DBMS_OUTPUT.put_line (DBMS_LOB.SUBSTR (p_clob, 255, l_offset));
          l_offset := l_offset + 255;
       END LOOP;

    END;
    ----------------------------------------------------------------------------

    PROCEDURE append_to_clob(clob_variable IN OUT NOCOPY CLOB,
                             line VARCHAR2)
    IS
    BEGIN
        dbms_lob.writeappend(clob_variable, LENGTH(line), line);
    END;
    ----------------------------------------------------------------------------

    FUNCTION column_numeric2alpha (p_col PLS_INTEGER)
       RETURN VARCHAR2
    IS
    BEGIN

        IF cache_column_alpha_in = p_col THEN
            RETURN cache_column_alpha_out;
        END IF;


        cache_column_alpha_out :=  CASE
                                     WHEN p_col &gt; 702
                                     THEN
                                           CHR (64 + TRUNC ( (p_col - 27) / 676))
                                        || CHR (65 + MOD (TRUNC ( (p_col - 1) / 26) - 1, 26))
                                        || CHR (65 + MOD (p_col - 1, 26))
                                     WHEN p_col &gt; 26
                                     THEN
                                        CHR (64 + TRUNC ( (p_col - 1) / 26))
                                        || CHR (65 + MOD (p_col - 1, 26))
                                     ELSE
                                        CHR (64 + p_col)
                                  END;
        cache_column_alpha_in := p_col;

        RETURN cache_column_alpha_out;

    END;
    ----------------------------------------------------------------------------

    FUNCTION column_alpha2numeric (p_col VARCHAR2)
       RETURN PLS_INTEGER
    IS
    BEGIN

        IF cache_column_number_in = UPPER(p_col) THEN
            RETURN cache_column_number_out;
        END IF;

        cache_column_number_in := UPPER(p_col);

        cache_column_number_out := ASCII (SUBSTR (cache_column_number_in, -1))
                                  - 64
                                  + NVL ( (ASCII (SUBSTR (cache_column_number_in, -2, 1)) - 64) * 26, 0)
                                  + NVL ( (ASCII (SUBSTR (cache_column_number_in, -3, 1)) - 64) * 676, 0);


        RETURN cache_column_number_out;

    END;
    ----------------------------------------------------------------------------

    FUNCTION add_fill (fill fills_type, doc_id PLS_INTEGER) RETURN NUMBER IS
       fill_id PLS_INTEGER;
    BEGIN
        -- Check if string exists
        IF documents(doc_id).fills.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).fills.FIRST .. documents(doc_id).fills.LAST LOOP
                IF documents(doc_id).fills(i).pattern_type = fill.pattern_type AND
                   documents(doc_id).fills(i).color = fill.color
                THEN
                    IF i &gt; 1 THEN
                        RETURN i - 1;
                    ELSE
                        RETURN i;
                    END IF;
                END IF;
            END LOOP;
        END IF;

        -- If string not exists add to list
        documents(doc_id).fills.EXTEND;
        fill_id := documents(doc_id).fills.LAST;

        documents(doc_id).fills(fill_id).pattern_type := fill.pattern_type;
        documents(doc_id).fills(fill_id).color := fill.color;

        IF fill_id &gt; 1 THEN
            RETURN fill_id - 1;
        ELSE
            RETURN fill_id;
        END IF;
    END;
    ----------------------------------------------------------------------------

    FUNCTION add_border (border borders_type, doc_id PLS_INTEGER) RETURN NUMBER IS
       border_id PLS_INTEGER;
    BEGIN
        -- Check if string exists
        IF documents(doc_id).borders.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).borders.FIRST .. documents(doc_id).borders.LAST LOOP
                IF documents(doc_id).borders(i).border_top = border.border_top AND
                   documents(doc_id).borders(i).border_top_style = border.border_top_style AND
                   documents(doc_id).borders(i).border_top_color = border.border_top_color AND
                   documents(doc_id).borders(i).border_bottom = border.border_bottom AND
                   documents(doc_id).borders(i).border_bottom_style = border.border_bottom_style AND
                   documents(doc_id).borders(i).border_bottom_color = border.border_bottom_color AND
                   documents(doc_id).borders(i).border_left = border.border_left AND
                   documents(doc_id).borders(i).border_left_style = border.border_left_style AND
                   documents(doc_id).borders(i).border_left_color = border.border_left_color AND
                   documents(doc_id).borders(i).border_right = border.border_right AND
                   documents(doc_id).borders(i).border_right_style = border.border_right_style AND
                   documents(doc_id).borders(i).border_right_color = border.border_right_color AND
                   NVL(documents(doc_id).borders(i).border_color, &apos;*&apos;) = NVL(border.border_color, &apos;*&apos;) AND
                   NVL(documents(doc_id).borders(i).border_style, &apos;*&apos;) = NVL(border.border_style, &apos;*&apos;)
                THEN

                    IF i &gt; 0 THEN
                        RETURN i - 1;
                    ELSE
                        RETURN i;
                    END IF;

                END IF;
            END LOOP;
        END IF;

        documents(doc_id).borders.EXTEND;
        border_id := documents(doc_id).borders.LAST;

        documents(doc_id).borders(border_id).border_top := NVL(border.border_top, FALSE);
        documents(doc_id).borders(border_id).border_top_style := NVL(border.border_top_style, &apos;thin&apos;);
        documents(doc_id).borders(border_id).border_top_color := NVL(border.border_top_color, &apos;00000000&apos;);
        documents(doc_id).borders(border_id).border_bottom :=  NVL(border.border_bottom, FALSE);
        documents(doc_id).borders(border_id).border_bottom_style :=  NVL(border.border_bottom_style, &apos;thin&apos;);
        documents(doc_id).borders(border_id).border_bottom_color :=  NVL(border.border_bottom_color, &apos;00000000&apos;);
        documents(doc_id).borders(border_id).border_left :=  NVL(border.border_left, FALSE);
        documents(doc_id).borders(border_id).border_left_style :=  NVL(border.border_left_style, &apos;thin&apos;);
        documents(doc_id).borders(border_id).border_left_color :=  NVL(border.border_left_color, &apos;00000000&apos;);
        documents(doc_id).borders(border_id).border_right :=  NVL(border.border_right, FALSE);
        documents(doc_id).borders(border_id).border_right_style :=  NVL(border.border_right_style, &apos;thin&apos;);
        documents(doc_id).borders(border_id).border_right_color :=  NVL(border.border_right_color, &apos;000000&apos;);
        documents(doc_id).borders(border_id).border_color := border.border_color;
        documents(doc_id).borders(border_id).border_style := border.border_style;

        IF border_id &gt; 0 THEN
            RETURN border_id - 1;
        ELSE
            RETURN border_id;
        END IF;

    END;
    ----------------------------------------------------------------------------

    FUNCTION add_format (format formats_type, doc_id PLS_INTEGER) RETURN NUMBER IS
        last_id PLS_INTEGER;
    BEGIN
        -- Check if string exists
        IF documents(doc_id).formats.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).formats.FIRST .. documents(doc_id).formats.LAST LOOP
                IF documents(doc_id).formats(i).num_fmt_id = format.num_fmt_id AND
                   documents(doc_id).formats(i).font_id = format.font_id AND
                   documents(doc_id).formats(i).fill_id = format.fill_id AND
                   documents(doc_id).formats(i).border_id = format.border_id AND
                   documents(doc_id).formats(i).xf_id = format.xf_id AND
                   NVL(documents(doc_id).formats(i).horizontal_align, &apos;*&apos;) = NVL(format.horizontal_align, &apos;*&apos;) AND
                   NVL(documents(doc_id).formats(i).vertical_align, &apos;*&apos;) = NVL(format.vertical_align, &apos;*&apos;) AND
                   NVL(documents(doc_id).formats(i).wrap_text, FALSE) = NVL(format.wrap_text, FALSE) AND
                   NVL(documents(doc_id).formats(i).rotate_text_degree, 0) = NVL(format.rotate_text_degree, 0) AND
                   NVL(documents(doc_id).formats(i).indent_left, 0) = NVL(format.indent_left, 0) AND
                   NVL(documents(doc_id).formats(i).indent_right, 0) = NVL(format.indent_right, 0)
                THEN
                    RETURN i - 1;  -- First format is format with index 1, format with index 0 is default format
                END IF;

            END LOOP;
        END IF;
        -- If format not exists add to list
        documents(doc_id).formats.EXTEND;
        last_id := documents(doc_id).formats.LAST;

        documents(doc_id).formats(last_id).num_fmt_id := format.num_fmt_id;
        documents(doc_id).formats(last_id).font_id := format.font_id;
        documents(doc_id).formats(last_id).fill_id := format.fill_id;
        documents(doc_id).formats(last_id).border_id := format.border_id;
        documents(doc_id).formats(last_id).xf_id := format.xf_id;
        documents(doc_id).formats(last_id).horizontal_align := format.horizontal_align;
        documents(doc_id).formats(last_id).wrap_text := format.wrap_text;
        documents(doc_id).formats(last_id).vertical_align := format.vertical_align;
        documents(doc_id).formats(last_id).rotate_text_degree := format.rotate_text_degree;
        documents(doc_id).formats(last_id).indent_left := format.indent_left;
        documents(doc_id).formats(last_id).indent_right := format.indent_right;

        RETURN last_id - 1;

    END;
    ----------------------------------------------------------------------------


        FUNCTION add_font(font fonts_type,
                      font_id PLS_INTEGER DEFAULT NULL,
                      doc_id PLS_INTEGER) RETURN NUMBER
    IS
        last_id PLS_INTEGER;
        font_name VARCHAR2(100);
        font_size PLS_INTEGER;
    BEGIN

        -- font name from parameter
        IF font.font_name IS NOT NULL THEN
            font_name := font.font_name;

        -- font name from set_cell_font
        ELSIF NVL(font_id, 0) &gt; 0 AND NVL(documents(doc_id).fonts.LAST, 0) &gt;= NVL(font_id, 0) AND documents(doc_id).fonts(font_id).font_name IS NOT NULL THEN

            font_name := documents(doc_id).fonts(font_id).font_name;

        -- default font name
        ELSE
            font_name :=  documents(doc_id).default_font.font_name;
        END IF;

        -- font size from parameter
        IF font.font_size IS NOT NULL THEN
            font_size := font.font_size;

        -- font size from set_cell_font
        ELSIF NVL(font_id, 0) &gt; 0 AND NVL(documents(doc_id).fonts.LAST, 0) &gt;= NVL(font_id, 0) AND documents(doc_id).fonts(font_id).font_size IS NOT NULL THEN
            font_size := documents(doc_id).fonts(font_id).font_size;

        -- default font size
        ELSE
            font_size :=  documents(doc_id).default_font.font_size;
        END IF;

        -- Check if font exists
        IF documents(doc_id).fonts.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).fonts.FIRST .. documents(doc_id).fonts.LAST LOOP

                IF documents(doc_id).fonts(i).font_name = font_name AND
                   documents(doc_id).fonts(i).font_size = font_size AND
                   NVL(documents(doc_id).fonts(i).bold, FALSE) = NVL(font.bold, FALSE) AND
                   NVL(documents(doc_id).fonts(i).italic, FALSE) = NVL(font.italic, FALSE) AND
                   NVL(documents(doc_id).fonts(i).underline, FALSE) = NVL(font.underline, FALSE) AND
                   NVL(documents(doc_id).fonts(i).color, &apos;*&apos;) = NVL(font.color, &apos;*&apos;)
                THEN
                    RETURN i;
                END IF;

            END LOOP;

        END IF;

        -- If format not exists add to list
        documents(doc_id).fonts.EXTEND;
        last_id := documents(doc_id).fonts.LAST;

        documents(doc_id).fonts(last_id).font_name := font_name;
        documents(doc_id).fonts(last_id).font_size := font_size;
        documents(doc_id).fonts(last_id).bold := font.bold;
        documents(doc_id).fonts(last_id).italic := font.italic;
        documents(doc_id).fonts(last_id).underline := font.underline;
        documents(doc_id).fonts(last_id).color := font.color;

        RETURN last_id;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Function add_font&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------


    PROCEDURE prepare_cell_format(cell_name VARCHAR2, doc_id PLS_INTEGER DEFAULT current_doc_id, sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
        format formats_type;
        font fonts_type;
        fill fills_type;
        border borders_type;
        format_id PLS_INTEGER;
        format_string VARCHAR2(100);
        prepare_row_id INTEGER;
        formula VARCHAR2(4000);
    BEGIN

        prepare_row_id := REGEXP_SUBSTR(cell_name, &apos;[[:digit:]+].*&apos;);
        current_cell_number := column_alpha2numeric(REGEXP_SUBSTR(cell_name, &apos;[[:alpha:]+]*&apos;));

        IF cell_formatted = TRUE THEN

            -- Default format values
            format.num_fmt_id := 0;
            format.font_id := 0;
            format.fill_id := 0;
            format.border_id := 0;
            format.xf_id := 0;
            format.horizontal_align := NULL;
            format.wrap_text := FALSE;
            format.vertical_align := NULL;
            format_id := add_format(format, doc_id);

            IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_type = &apos;D&apos; AND NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_num_fmt_id, 0) = 0 THEN
                format.num_fmt_id := 14; -- 14 m/d/yyyy
            ELSE
                format.num_fmt_id := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_num_fmt_id, 0);
            END IF;

            -- Default font id, or font which is set by set_cell_font
            format.font_id := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_font_id, 0);

            -- Bold, Italic, underline, change  font id
            IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).bold = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).italic = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).underline = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).color IS NOT NULL
            THEN
                font.font_size := NULL;
                font.font_name := NULL;
                font.italic := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).italic;
                font.underline := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).underline;
                font.bold := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).bold;
                font.color := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).color;
                format.font_id := NVL(add_font(font, format.font_id, doc_id) , 0);
            END IF;

            format.fill_id := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_fill_id, 0);

            IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).bg_color IS NOT NULL THEN
                fill.pattern_type := &apos;solid&apos;;
                fill.color := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).bg_color;
                format.fill_id := NVL(add_fill(fill, doc_id), 0);
            END IF;

            format.border_id := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_border_id, 0);

            IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_top = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_bottom = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_left = TRUE OR
               documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_right = TRUE
            THEN
                border.border_top := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_top, FALSE);
                border.border_top_style := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_top_style, &apos;thin&apos;);
                border.border_top_color := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_top_color, &apos;00000000&apos;);

                border.border_bottom := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_bottom, FALSE);
                border.border_bottom_style := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_bottom_style, &apos;thin&apos;);
                border.border_bottom_color := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_bottom_color, &apos;00000000&apos;);

                border.border_left := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_left, FALSE);
                border.border_left_style := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_left_style, &apos;thin&apos;);
                border.border_left_color := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_left_color, &apos;00000000&apos;);

                border.border_right := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_right, FALSE);
                border.border_right_style := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_right_style, &apos;thin&apos;);
                border.border_right_color := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_right_color, &apos;00000000&apos;);

                border.border_style := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_style;
                border.border_color := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).border_color;

                format.border_id := NVL(add_border(border, doc_id), 0);
            END IF;

            format.xf_id := NVL(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_xf_id, 0);
            format.horizontal_align := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).horizontal_align;
            format.wrap_text :=documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).wrap_text;
            format.vertical_align := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).vertical_align;
            format.rotate_text_degree := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).rotate_text_degree;
            format.indent_left := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).indent_left;
            format.indent_right := documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).indent_right;


            format_id := add_format(format, doc_id);

        END IF;

        format_string := NULL;

        IF format_id IS NOT NULL THEN
            format_string := &apos; s=&quot;&apos;||format_id||&apos;&quot;&apos;;
        ELSIF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_id IS NOT NULL THEN
            format_string := &apos; s=&quot;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).format_id||&apos;&quot;&apos;;
        END IF;

        IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).formula IS NOT NULL THEN
            formula := &apos;&lt;f&gt;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).formula||&apos;&lt;/f&gt;&apos;;
        END IF;

        IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_type = &apos;N&apos; THEN
            line_string(doc_id) := &apos;&lt;c r=&quot;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_name||&apos;&quot;&apos;||format_string||&apos;&gt;&apos;||formula||&apos;&lt;v&gt;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_value||&apos;&lt;/v&gt;&lt;/c&gt;&apos;;
        ELSIF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_type = &apos;S&apos; THEN
            line_string(doc_id) := &apos;&lt;c r=&quot;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_name||&apos;&quot;&apos;||format_string||&apos;  t=&quot;s&quot;&gt;&apos;||formula||&apos;&lt;v&gt;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_value||&apos;&lt;/v&gt;&lt;/c&gt;&apos;;
        ELSIF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_type = &apos;D&apos; THEN
            line_string(doc_id) := &apos;&lt;c r=&quot;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_name||&apos;&quot;&apos;||format_string||&apos;&gt;&apos;||formula||&apos;&lt;v&gt;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_value||&apos;&lt;/v&gt;&lt;/c&gt;&apos;;
        ELSE
             line_string(doc_id) := &apos;&lt;c r=&quot;&apos;||documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cell_name||&apos;&quot;&apos;||format_string||&apos;/&gt;&apos;;
        END IF;


        sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||line_string(doc_id);

        IF LENGTH(sheet_data_buffer(doc_id)) &gt; 30000 THEN
            dbms_lob.writeappend(documents(doc_id).sheets(sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
            sheet_data_buffer(doc_id) := NULL;
        END IF;


        IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).merge_cells = TRUE AND documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).merged_cells_cell_from IS NOT NULL AND documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).merges_cells_cell_to IS NOT NULL THEN

            IF LENGTH(sheet_data_buffer(doc_id)) &gt; 32000 THEN
                dbms_lob.writeappend(documents(doc_id).sheets(sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
                sheet_data_buffer(doc_id) := NULL;
            END IF;

             FOR i IN (column_alpha2numeric(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).merged_cells_cell_from) + 1) .. column_alpha2numeric(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).merges_cells_cell_to) LOOP


                IF sheet_data_buffer(doc_id) IS NOT NULL THEN

                   -- Update format id
                   sheet_data_buffer(doc_id) := REGEXP_REPLACE(sheet_data_buffer(doc_id), &apos;\&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;(.*)s=&quot;(.*)&quot;(.*)/&gt;\&apos;, &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;\1s=&quot;&apos;||format_id||&apos;&quot;\3/&gt;&apos;);

                   -- Add format id
                   sheet_data_buffer(doc_id) := REPLACE(sheet_data_buffer(doc_id), &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;/&gt;&apos;, &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot; s=&quot;&apos;||format_id||&apos;&quot;/&gt;&apos;);

               ELSE

                   -- Update format id
                   documents(doc_id).sheets(sheet_id).sheet_data := REGEXP_REPLACE(documents(doc_id).sheets(sheet_id).sheet_data, &apos;\&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;(.*)s=&quot;(.*)&quot;(.*)/&gt;\&apos;, &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;\1s=&quot;&apos;||format_id||&apos;&quot;\3/&gt;&apos;);

                    -- Add format id
                   documents(doc_id).sheets(sheet_id).sheet_data := REPLACE(documents(doc_id).sheets(sheet_id).sheet_data, &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot;/&gt;&apos;, &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||prepare_row_id||&apos;&quot; s=&quot;&apos;||format_id||&apos;&quot;/&gt;&apos;);

               END IF;

            END LOOP;

            IF documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cells_to_add IS NOT NULL THEN
                sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id) || REPLACE(documents(doc_id).sheets(sheet_id).current_cell(current_cell_number).cells_to_add, &apos;s=&quot;\2&quot;&apos;, format_string);
            END IF;

        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100,  &apos;Procedure prepare_cell_format&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE prepare_columns(doc_id PLS_INTEGER DEFAULT current_doc_id, sheet_id PLS_INTEGER DEFAULT current_sheet_id) IS
        cell_index PLS_INTEGER;
        row_added BOOLEAN;
    BEGIN

        -- Get first index of currect_cell assoc array
        cell_index := documents(doc_id).sheets(sheet_id).current_cell.FIRST;

        IF cell_index IS NOT NULL THEN

            IF current_row_id &lt; 3 THEN

                IF INSTR(sheet_data_buffer(doc_id), &apos;spans=&quot;1:1&quot;&apos;) &gt; 0 THEN
                    sheet_data_buffer(doc_id) := REPLACE(sheet_data_buffer(doc_id), &apos;spans=&quot;1:1&quot;&apos;, &apos;spans=&quot;1:&apos;||REPLACE(documents(doc_id).sheets(sheet_id).top_right_column, &apos;0&apos;, &apos;1&apos;)||&apos;&quot;&apos;);
                END IF;

            END IF;


            row_added := FALSE;

            -- Loop through cells
            LOOP

                EXIT WHEN cell_index IS NULL;

                IF documents(doc_id).sheets(sheet_id).current_cell(cell_index).cell_name IS NOT NULL THEN

                    IF row_added = FALSE THEN

                        sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||&apos;&lt;row r=&quot;&apos;||REGEXP_SUBSTR(documents(doc_id).sheets(sheet_id).current_cell(cell_index).cell_name, &apos;[[:digit:]+].*&apos;)||&apos;&quot; spans=&quot;1:&apos;||REPLACE(documents(doc_id).sheets(sheet_id).top_right_column, &apos;0&apos;, &apos;1&apos;)||&apos;&quot;&apos;;

                        IF documents(doc_id).sheets(sheet_id).hide_row IS NOT NULL THEN
                            sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||&apos; hidden=&quot;1&quot;&apos;;
                            documents(doc_id).sheets(sheet_id).hide_row := NULL;
                        END IF;


                        IF documents(doc_id).sheets(sheet_id).row_height IS NOT NULL THEN
                            sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||&apos; ht=&quot;&apos;||REPLACE(TO_CHAR(documents(doc_id).sheets(sheet_id).row_height), &apos;,&apos;,&apos;.&apos;)||&apos;&quot; customHeight=&quot;1&quot;&apos;;
                            documents(doc_id).sheets(sheet_id).row_height := NULL;
                        END IF;

                        sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||&apos;&gt;&apos;;

                        row_added := TRUE;

                    END IF;

                    -- Set cell formatting
                    prepare_cell_format(documents(doc_id).sheets(sheet_id).current_cell(cell_index).cell_name, doc_id, sheet_id);

                    -- Initialize current cell values
                    --documents(doc_id).sheets(sheet_id).current_cell(cell_index) := current_cell_record;::documents::&lt;&quot;@164&quot;&gt;::current_cell::&lt;&quot;@93&quot;&gt;::cell_index::&lt;&quot;@195&quot;&gt;

                END IF;
                -- Get next cell array index
                cell_index := documents(doc_id).sheets(sheet_id).current_cell.NEXT(cell_index);

            END LOOP;

            -- Delete cells formattion for current row
            documents(doc_id).sheets(sheet_id).current_cell := current_cell_empty;

            sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id)||&apos;&lt;/row&gt;&apos;;


        END IF;


        IF LENGTH(sheet_data_buffer(doc_id)) &gt; 32000 THEN
            dbms_lob.writeappend(documents(doc_id).sheets(sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
            sheet_data_buffer(doc_id) := NULL;
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure prepare_columns&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION new_document
       RETURN PLS_INTEGER
    IS
        default_font default_font_type;
        fill fills_type;
        fill_id PLS_INTEGER;
        border borders_type;
        border_id PLS_INTEGER;
        expire_date DATE;
        format_id PLS_INTEGER;
        format formats_type;
    BEGIN

        IF doc_id &lt; 1 THEN
          documents := documents_empty;
        END IF;

        doc_id := doc_id + 1;
        documents.EXTEND;
        current_doc_id := documents.LAST;
        current_row_id := 0;

        -- Initialize collectuions
        documents(current_doc_id).sheets := sheets_empty;
        documents(current_doc_id).format_masks := format_masks_empty;
        documents(current_doc_id).formats := formats_empty;
        documents(current_doc_id).fonts := fonts_empty;
        documents(current_doc_id).fills := fills_empty;
        documents(current_doc_id).borders := borders_empty;

        -- Initialize shared strings CLOB
        documents(current_doc_id).shared_strings := EMPTY_CLOB;
        dbms_lob.createtemporary(documents(current_doc_id).shared_strings, TRUE);
        dbms_lob.open(documents(current_doc_id).shared_strings, dbms_lob.lob_readwrite);


        -- Initialize sheet data budder collection
        documents(current_doc_id).shared_strings_buffer := shared_buffer_empty;

        -- Initialize shared string counter, shared strings index starts at 0
        documents(current_doc_id).last_shared_string_num := - 1;

        -- Set default font
        default_font.font_name := &apos;Calibri&apos;;
        default_font.font_size := 11;
        documents(current_doc_id).default_font := default_font;

        -- Set default fills
        fill.pattern_type := &apos;none&apos;;
        fill.color := NULL;
        fill_id := add_fill(fill, doc_id);

        fill.pattern_type := &apos;gray125&apos;;
        fill.color := NULL;
        fill_id := add_fill(fill, doc_id);

        -- Set default border
        border.border_top := FALSE;
        border.border_top_style := &apos;thin&apos;;
        border.border_top_color := &apos;00000000&apos;;
        border.border_bottom := FALSE;
        border.border_bottom_style := &apos;thin&apos;;
        border.border_bottom_color := &apos;00000000&apos;;
        border.border_left := FALSE;
        border.border_left_style := &apos;thin&apos;;
        border.border_left_color := &apos;00000000&apos;;
        border.border_right := FALSE;
        border.border_right_style := &apos;thin&apos;;
        border.border_right_color := &apos;00000000&apos;;
        border_id := add_border(border, doc_id);

        -- Add default number format
        format.num_fmt_id := 0;
        format.font_id := 0;
        format.fill_id := 0;
        format.border_id := 0;
        format.xf_id := 0;

        format_id := add_format(format, doc_id);

        -- Initialize shared strings buffer
        shared_strings_buffer(current_doc_id) := NULL;

        -- Prepare clob which will be used to initialize clobs
        DBMS_LOB.createtemporary(initialize_clob, TRUE);
        DBMS_LOB.open(initialize_clob, dbms_lob.lob_readwrite);

       RETURN current_doc_id;

    END;
    ----------------------------------------------------------------------------

    PROCEDURE new_document
    IS
    BEGIN
       -- Call overridden function
       current_doc_id := new_document;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure new_document&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION add_sheet (sheet_name VARCHAR2,
                        doc_id PLS_INTEGER DEFAULT current_doc_id)
       RETURN PLS_INTEGER
    IS
    BEGIN

        -- Add new sheet
        documents(doc_id).sheets.EXTEND;

        -- Get new sheet id
        current_sheet_id := documents(doc_id).sheets.LAST;

        -- Set sheet name
        documents(doc_id).sheets(current_sheet_id).sheet_name := translate(sheet_name, &apos;:\/?*[]&apos;, &apos;________&apos;);

        -- Initialize row number
        documents(doc_id).sheets(current_sheet_id).last_row_num := 0;

        -- Initialize CLOB which will be used to store sheet data
        documents(doc_id).sheets(current_sheet_id).sheet_data := EMPTY_CLOB;

        -- Create temporary file for CLOB
        dbms_lob.createtemporary(documents(doc_id).sheets(current_sheet_id).sheet_data, TRUE);
        dbms_lob.open(documents(doc_id).sheets(current_sheet_id).sheet_data, dbms_lob.lob_readwrite);

        -- Initialize top right column
        documents(doc_id).sheets(current_sheet_id).top_right_column := 0;

        -- Initialize column widths collection
        documents(doc_id).sheets(current_sheet_id).column_properites := column_properites_empty;

        -- Initialize hyperlinks collection
        documents(doc_id).sheets(current_sheet_id).hyperlinks := hyperlinks_empty;

        -- Initialize internal hyperlinks collection
        documents(doc_id).sheets(current_sheet_id).internal_hyperlinks := internal_hyperlinks_empty;

        -- Initialize comments collection
        documents(doc_id).sheets(current_sheet_id).comments := comments_empty;

        -- Initialize sheet data budder collection
        documents(doc_id).sheets(current_sheet_id).sheet_data_buffer := sheet_buffer_empty;

        -- Initializa sheet cell info collection
        documents(doc_id).sheets(current_sheet_id).current_cell := current_cell_empty;

        -- Check is initialized, initialize if it is not
        BEGIN
            sheet_data_buffer(doc_id) := sheet_data_buffer(doc_id);
        EXCEPTION
            WHEN no_data_found THEN
                sheet_data_buffer(doc_id) := NULL;
        END;

        -- Check is initialized, initialize if it is not
        BEGIN
            line_string(doc_id) := line_string(doc_id);
        EXCEPTION
            WHEN no_data_found THEN
                line_string(doc_id) := NULL;
        END;

        -- Clean buffers
        IF sheet_data_buffer.LAST IS NULL THEN
            sheet_data_buffer(doc_id) := NULL;
        END IF;

        IF  line_string.LAST IS NULL THEN
            line_string(doc_id) := NULL;
        END IF;

        -- Write buffer from previous sheet
        IF current_sheet_id &gt; 1 THEN

            prepare_columns(doc_id, current_sheet_id - 1);

            IF LENGTH(sheet_data_buffer(doc_id)) &gt; 0 THEN
                dbms_lob.writeappend(documents(doc_id).sheets(current_sheet_id - 1).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
                sheet_data_buffer(doc_id) := NULL;
            END IF;

        END IF;

        -- Clean buffers
        sheet_data_buffer(doc_id) := NULL;
        line_string(doc_id) := NULL;

        -- Initialize collection for merged cells
        documents(doc_id).sheets(current_sheet_id).merged_cells := merged_cells_empty;

        RETURN current_sheet_id;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Function add_sheet&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_column_width(name VARCHAR2, width NUMBER, doc_id PLS_INTEGER DEFAULT current_doc_id, sheet_id PLS_INTEGER DEFAULT current_sheet_id) IS
        column_id PLS_INTEGER;
    BEGIN

        IF documents(doc_id).sheets(sheet_id).column_properites.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets(sheet_id).column_properites.FIRST .. documents(doc_id).sheets(sheet_id).column_properites.LAST LOOP
                IF documents(doc_id).sheets(sheet_id).column_properites(i).column_name = UPPER(name) THEN
                    column_id := i;
                    EXIT;
                END IF;
            END LOOP;

        END IF;

        IF column_id IS NULL THEN
            documents(doc_id).sheets(sheet_id).column_properites.EXTEND;
            column_id := documents(doc_id).sheets(sheet_id).column_properites.LAST;
        END IF;

        documents(doc_id).sheets(sheet_id).column_properites(column_id).column_name := UPPER(name);
        documents(doc_id).sheets(sheet_id).column_properites(column_id).width := width;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_column_widt&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE add_sheet (
       sheet_name VARCHAR2,
       doc_id PLS_INTEGER DEFAULT current_doc_id
    )
    IS
    BEGIN
       -- Call overridden function
       current_sheet_id := add_sheet (sheet_name, doc_id);
    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_sheet&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------


    FUNCTION add_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                     sheet_id PLS_INTEGER DEFAULT current_sheet_id) RETURN PLS_INTEGER
    IS
        last_buffer_id INTEGER;
        free_rows_limit INTEGER := 5 * 20;
    BEGIN

        prepare_columns(doc_id, sheet_id);

        -- Increment row number
        documents(doc_id).sheets(sheet_id).last_row_num := documents(doc_id).sheets(sheet_id).last_row_num + 1;
        current_row_id := documents(doc_id).sheets(sheet_id).last_row_num;

        -- Set application info, so it can be visible in v$session while procedure is running
        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL - Sheet &apos;||sheet_id||&apos; - Row &apos;||current_row_id);

        -- Move content from cache if cache contains more than 1000000 characters
        IF DBMS_LOB.getlength(documents(doc_id).sheets(sheet_id).sheet_data) &gt; 1000000 THEN

            documents(doc_id).sheets(sheet_id).sheet_data_buffer.EXTEND;
            last_buffer_id := documents(doc_id).sheets(sheet_id).sheet_data_buffer.LAST;

            dbms_lob.createtemporary(documents(doc_id).sheets(sheet_id).sheet_data_buffer(last_buffer_id), TRUE);
            dbms_lob.open(documents(doc_id).sheets(sheet_id).sheet_data_buffer(last_buffer_id), dbms_lob.lob_readwrite);

            DBMS_LOB.append(documents(doc_id).sheets(sheet_id).sheet_data_buffer(last_buffer_id), documents(doc_id).sheets(sheet_id).sheet_data);
            documents(doc_id).sheets(sheet_id).sheet_data := initialize_clob;

        END IF;

        -- Initialize cell formatting flag for next cycle
        cell_formatted := FALSE;

        RETURN current_row_id;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_row&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE add_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                      sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
        row_id PLS_INTEGER;
    BEGIN
        row_id := add_row(doc_id, sheet_id);
    END;


    FUNCTION add_format_mask (format_mask VARCHAR2, doc_id PLS_INTEGER) RETURN NUMBER IS
       mask_id PLS_INTEGER;
    BEGIN
        -- Check if string exists
        IF documents(doc_id).format_masks.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).format_masks.FIRST .. documents(doc_id).format_masks.LAST LOOP
                IF documents(doc_id).format_masks(i).format_mask = format_mask
                THEN
                    RETURN i + 164;
                END IF;
            END LOOP;
        END IF;

        -- If string not exists add to list
        documents(doc_id).format_masks.EXTEND;
        mask_id := documents(doc_id).format_masks.LAST;

        documents(doc_id).format_masks(mask_id).format_mask := format_mask;

        RETURN mask_id + 164;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Function add_format_mask&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_format (cell_name VARCHAR2,
                               format VARCHAR2,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                               row_id PLS_INTEGER DEFAULT current_row_id) IS

    BEGIN

        current_cell_number := column_alpha2numeric(cell_name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(cell_name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).format_num_fmt_id := add_format_mask(format, doc_id);
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_format&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------


    PROCEDURE set_cell_value (name VARCHAR2,
                              value NUMBER,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);

        -- Skeep cell tag id value is null
        IF value IS NOT NULL THEN

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_type := &apos;N&apos;; -- Number
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := REPLACE(TO_CHAR(value), &apos;,&apos;, &apos;.&apos;);

        END IF;

        -- Remember top right column number
        IF column_alpha2numeric(name) &gt; documents(doc_id).sheets(sheet_id).top_right_column THEN
            documents(doc_id).sheets(sheet_id).top_right_column := column_alpha2numeric(name);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_value number -&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_value (name VARCHAR2,
                              value VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS

        last_buffer_id INTEGER;

    BEGIN

        current_cell_number := column_alpha2numeric(name);

        IF DBMS_LOB.getlength(documents(doc_id).shared_strings) &gt; 1000000 THEN

            documents(doc_id).shared_strings_buffer.EXTEND;
            last_buffer_id := documents(doc_id).shared_strings_buffer.LAST;

            dbms_lob.createtemporary(documents(doc_id).shared_strings_buffer(last_buffer_id), TRUE);
            dbms_lob.open(documents(doc_id).shared_strings_buffer(last_buffer_id), dbms_lob.lob_readwrite);

            DBMS_LOB.append(documents(doc_id).shared_strings_buffer(last_buffer_id), documents(doc_id).shared_strings);
            documents(doc_id).shared_strings := initialize_clob;

        END IF;

        -- Skeep cell tag id value is null
        IF value IS NOT NULL THEN

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_type := &apos;S&apos;; -- String

            -- Increment shared strings counter
            documents(doc_id).last_shared_string_num := documents(doc_id).last_shared_string_num + 1;

            line_string(doc_id) := &apos;&lt;si&gt;&lt;t&gt;&apos;||REPLACE(dbms_xmlgen.convert(REGEXP_REPLACE(REPLACE(value, CHR(10), &apos;__NEW_LINE__&apos;),&apos;[[:cntrl:]]&apos;,&apos;&apos;)), &apos;__NEW_LINE__&apos;, CHR(10))||&apos;&lt;/t&gt;&lt;/si&gt;&apos;;
            IF (LENGTH(shared_strings_buffer(doc_id)) + LENGTH(line_string(doc_id))) &gt;= 25000 THEN

                dbms_lob.writeappend(documents(doc_id).shared_strings, LENGTH(shared_strings_buffer(doc_id)), shared_strings_buffer(doc_id));
                shared_strings_buffer(doc_id) := line_string(doc_id);

            ELSE

                shared_strings_buffer(doc_id) := shared_strings_buffer(doc_id) || line_string(doc_id);

            END IF;

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := documents(doc_id).last_shared_string_num; -- String

        END IF;

        -- Remember top right column number
        IF column_alpha2numeric(name) &gt; documents(doc_id).sheets(sheet_id).top_right_column THEN
            documents(doc_id).sheets(sheet_id).top_right_column := column_alpha2numeric(name);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_value varchar2&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_internal_code (name VARCHAR2,
                                      value CLOB,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                      row_id PLS_INTEGER DEFAULT current_row_id)
    IS

        last_buffer_id INTEGER;

    BEGIN

        current_cell_number := column_alpha2numeric(name);

        IF LENGTH(shared_strings_buffer(doc_id)) &gt; 0 THEN
            dbms_lob.writeappend(documents(doc_id).shared_strings, LENGTH(shared_strings_buffer(doc_id)), shared_strings_buffer(doc_id));
        END IF;

        IF DBMS_LOB.getlength(documents(doc_id).shared_strings) &gt; 1000000 THEN

            documents(doc_id).shared_strings_buffer.EXTEND;
            last_buffer_id := documents(doc_id).shared_strings_buffer.LAST;

            dbms_lob.createtemporary(documents(doc_id).shared_strings_buffer(last_buffer_id), TRUE);
            dbms_lob.open(documents(doc_id).shared_strings_buffer(last_buffer_id), dbms_lob.lob_readwrite);

            DBMS_LOB.append(documents(doc_id).shared_strings_buffer(last_buffer_id), documents(doc_id).shared_strings);
            documents(doc_id).shared_strings := initialize_clob;

        END IF;

        -- Skeep cell tag id value is null
        IF value IS NOT NULL THEN

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_type := &apos;S&apos;; -- String


            -- Increment shared strings counter
            documents(doc_id).last_shared_string_num := documents(doc_id).last_shared_string_num + 1;

            -- Add value to shared strings CLOB
            append_to_clob(documents(doc_id).shared_strings, &apos;&lt;si&gt;&apos;);
            dbms_lob.append(documents(doc_id).shared_strings, value);
            append_to_clob(documents(doc_id).shared_strings, &apos;&lt;/si&gt;&apos;);

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := documents(doc_id).last_shared_string_num;

        END IF;

        -- Remember top right column number
        IF column_alpha2numeric(name) &gt; documents(doc_id).sheets(sheet_id).top_right_column THEN
            documents(doc_id).sheets(sheet_id).top_right_column := column_alpha2numeric(name);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_internal_code &apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_value (name VARCHAR2,
                              value CLOB,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS

        last_buffer_id INTEGER;

    BEGIN

        current_cell_number := column_alpha2numeric(name);

        IF DBMS_LOB.getlength(documents(doc_id).shared_strings) &gt; 1000000 THEN

            documents(doc_id).shared_strings_buffer.EXTEND;
            last_buffer_id := documents(doc_id).shared_strings_buffer.LAST;

            dbms_lob.createtemporary(documents(doc_id).shared_strings_buffer(last_buffer_id), TRUE);
            dbms_lob.open(documents(doc_id).shared_strings_buffer(last_buffer_id), dbms_lob.lob_readwrite);

            DBMS_LOB.append(documents(doc_id).shared_strings_buffer(last_buffer_id), documents(doc_id).shared_strings);
            documents(doc_id).shared_strings := initialize_clob;

        END IF;

        -- Skeep cell tag id value is null
        IF value IS NOT NULL THEN

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_type := &apos;S&apos;; -- String


            -- Increment shared strings counter
            documents(doc_id).last_shared_string_num := documents(doc_id).last_shared_string_num + 1;

            -- Add value to shared strings CLOB
            append_to_clob(documents(doc_id).shared_strings, &apos;&lt;si&gt;&lt;t&gt;&apos;);
            dbms_lob.append(documents(doc_id).shared_strings, value);
            append_to_clob(documents(doc_id).shared_strings, &apos;&lt;/t&gt;&lt;/si&gt;&apos;);

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := documents(doc_id).last_shared_string_num;

        END IF;

        -- Remember top right column number
        IF column_alpha2numeric(name) &gt; documents(doc_id).sheets(sheet_id).top_right_column THEN
            documents(doc_id).sheets(sheet_id).top_right_column := column_alpha2numeric(name);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_value clob&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_value (name VARCHAR2,
                              value DATE,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS

        format formats_type;
        cell_format_id INTEGER;

    BEGIN

        current_cell_number := column_alpha2numeric(name);
        -- Skeep cell tag id value is null
        IF value IS NOT NULL THEN

            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_type := &apos;D&apos;; -- Date

            -- Prepare format mask
            IF value != TRUNC(value) THEN
                format.num_fmt_id := 22;
                format.font_id := 0;
                format.fill_id := 0;
                format.border_id := 0;
                format.xf_id := 0;
                cell_format_id := add_format(format, doc_id);
            ELSE
                format.num_fmt_id := 14;
                format.font_id := 0;
                format.fill_id := 0;
                format.border_id := 0;
                format.xf_id := 0;
                cell_format_id := add_format(format, doc_id);
            END IF;

            IF NVL(date_system, 1904) = 1904 THEN
                documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := REPLACE(TO_CHAR(ROUND(value - TO_DATE(&apos;01.01.1904&apos;,&apos;dd.mm.yyyy&apos;), 12) + 1), &apos;,&apos;, &apos;.&apos;);
            ELSE
                documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_value := REPLACE(TO_CHAR(ROUND(value - TO_DATE(&apos;01.01.1900&apos;,&apos;dd.mm.yyyy&apos;), 12) + 2), &apos;,&apos;, &apos;.&apos;);
            END IF;
            documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).format_id := cell_format_id;

        END IF;

         -- Remember top right column number
        IF column_alpha2numeric(name) &gt; documents(doc_id).sheets(sheet_id).top_right_column THEN
            documents(doc_id).sheets(sheet_id).top_right_column := column_alpha2numeric(name);
        END IF;


    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_value date&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION little_endian (in_big NUMBER,
                            in_bytes PLS_INTEGER := 4) RETURN RAW
    IS
    BEGIN
        RETURN UTL_RAW.substr (
            UTL_RAW.cast_from_binary_integer (in_big, UTL_RAW.little_endian),
            1,
            in_bytes
        );

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Function little_endian&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE add_file(compressed_blob in out nocopy blob,
                       name varchar2,
                       content blob)
    IS
        t_now DATE;
        t_blob BLOB;
        t_clen INTEGER;
    BEGIN
        t_now := SYSDATE;
        t_blob := utl_compress.lz_compress(content);
        t_clen := dbms_lob.getlength( t_blob );

    IF compressed_blob IS NULL THEN
      dbms_lob.createtemporary(compressed_blob, TRUE);
    END IF;

        dbms_lob.append(compressed_blob,
                          utl_raw.CONCAT(HEXTORAW(&apos;504B0304&apos;),
                                         HEXTORAW(&apos;1400&apos;),
                                         HEXTORAW(&apos;0000&apos;),
                                         HEXTORAW(&apos;0800&apos;),
                                         little_endian( TO_NUMBER(TO_CHAR(t_now, &apos;ss&apos;)) / 2
                                                      + TO_NUMBER(TO_CHAR(t_now, &apos;mi&apos;)) * 32
                                                      + TO_NUMBER(TO_CHAR(t_now, &apos;hh24&apos;)) * 2048
                                                      , 2
                                                      ),
                                         little_endian( TO_NUMBER(TO_CHAR( t_now, &apos;dd&apos;))
                                                      + TO_NUMBER(TO_CHAR( t_now, &apos;mm&apos;)) * 32
                                                      + (TO_NUMBER(TO_CHAR( t_now, &apos;yyyy&apos; )) - 1980) * 512
                                                      , 2)
                                       , dbms_lob.substr(t_blob, 4, t_clen - 7)
                                       , little_endian( t_clen - 18 )
                                       , little_endian( dbms_lob.getlength(content))
                                       , little_endian( length(name), 2)
                                       , HEXTORAW(&apos;0000&apos;)
                                       , utl_raw.cast_to_raw(name)
                                       )
                       );
        dbms_lob.copy(compressed_blob, t_blob, t_clen - 18, dbms_lob.getlength( compressed_blob ) + 1, 11);
        dbms_lob.freetemporary(t_blob);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_file&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ------------------------------------------------------------------------------

    PROCEDURE add_xml (document_blob IN OUT NOCOPY BLOB,
                       file_name VARCHAR2,
                       xml_clob CLOB) IS
       tmp_blob   BLOB := EMPTY_BLOB();
       tmp_raw RAW(5000);
    BEGIN
       DBMS_LOB.createtemporary (tmp_blob, TRUE);

       FOR i IN 0 .. TRUNC (LENGTH (xml_clob) / 2000)
       LOOP
          tmp_raw := UTL_I18N.string_to_raw (SUBSTR (xml_clob, i * 2000 + 1, 2000), &apos;AL32UTF8&apos;);
          IF tmp_raw IS NOT NULL THEN
            DBMS_LOB.append (tmp_blob, tmp_raw);
          END IF;
       END LOOP;

       add_file (document_blob, file_name, tmp_blob);
       DBMS_LOB.freetemporary (tmp_blob);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_xml&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE compress_document (compressed_blob IN OUT NOCOPY BLOB)
    IS
       t_cnt               PLS_INTEGER := 0;
       t_offs              INTEGER;
       t_offs_dir_header   INTEGER;
       t_offs_end_header   INTEGER;
       t_comment RAW (32767) := UTL_RAW.cast_to_raw (&apos; &apos;);
    BEGIN
       t_offs_dir_header := DBMS_LOB.getlength (compressed_blob);
       t_offs := DBMS_LOB.INSTR (compressed_blob, HEXTORAW (&apos;504B0304&apos;), 1);

       WHILE t_offs &gt; 0
       LOOP
          t_cnt := t_cnt + 1;
          DBMS_LOB.append (
             compressed_blob,
             UTL_RAW.CONCAT (
                HEXTORAW (&apos;504B0102&apos;),
                HEXTORAW (&apos;1400&apos;),
                DBMS_LOB.SUBSTR (compressed_blob, 26, t_offs + 4), HEXTORAW (&apos;0000&apos;),
                HEXTORAW (&apos;0000&apos;),
                HEXTORAW (&apos;0100&apos;),
                HEXTORAW (&apos;2000B681&apos;),
                little_endian (t_offs - 1),
                DBMS_LOB.SUBSTR (
                   compressed_blob,
                   UTL_RAW.cast_to_binary_integer (
                      DBMS_LOB.SUBSTR (compressed_blob, 2, t_offs + 26),
                      UTL_RAW.little_endian),
                   t_offs + 30)
                )
          );
          t_offs := DBMS_LOB.INSTR (compressed_blob, HEXTORAW (&apos;504B0304&apos;), t_offs + 32);
       END LOOP;

       t_offs_end_header := DBMS_LOB.getlength (compressed_blob);
       DBMS_LOB.append (
          compressed_blob,
          UTL_RAW.CONCAT (
             HEXTORAW (&apos;504B0506&apos;),
             HEXTORAW (&apos;0000&apos;),
             HEXTORAW (&apos;0000&apos;),
             little_endian (t_cnt, 2),
             little_endian (t_cnt, 2),
             little_endian (t_offs_end_header - t_offs_dir_header),
             little_endian (t_offs_dir_header),
             little_endian (NVL (UTL_RAW.LENGTH (t_comment), 0), 2),
             t_comment));

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure compress_document&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ------------------------------------------------------------------------------

    PROCEDURE blob2file (p_blob BLOB,
                         p_directory VARCHAR2,
                         p_filename VARCHAR2)
    IS
       t_fh    UTL_FILE.file_type;
       t_len   PLS_INTEGER := 32767;
    BEGIN
       t_fh := UTL_FILE.fopen (p_directory, p_filename, &apos;wb&apos;);

       FOR i IN 0 .. TRUNC ( (DBMS_LOB.getlength (p_blob) - 1) / t_len)
       LOOP
          UTL_FILE.put_raw (t_fh, DBMS_LOB.SUBSTR (p_blob, t_len, i * t_len + 1));
       END LOOP;

       UTL_FILE.fclose (t_fh);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure blob2file&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE save_to_blob(blob_file IN OUT BLOB,
                           doc_id PLS_INTEGER DEFAULT current_doc_id) IS
        file_content CLOB;
        file_content2 CLOB := EMPTY_CLOB;
        last_row PLS_INTEGER;
        top_right_column PLS_INTEGER;
        first_sheet PLS_INTEGER;
        last_sheet PLS_INTEGER;
        last_i PLS_INTEGER;
        show_header BOOLEAN;
        rel_id PLS_INTEGER;
        drawing_added BOOLEAN;
    BEGIN

        -- Write content from buffer of last sheet to clob of that sheet
        IF sheet_data_buffer(doc_id) IS NOT NULL THEN
            dbms_lob.writeappend(documents(doc_id).sheets(current_sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
            sheet_data_buffer(doc_id) := NULL;
        END IF;


        prepare_columns(doc_id, current_sheet_id);

        -- Delete cells formattion for current row
        documents(doc_id).sheets(current_sheet_id).current_cell := current_cell_empty;

        -- Write cell cata to CLOB
        IF sheet_data_buffer(doc_id) IS NOT NULL THEN
            dbms_lob.writeappend(documents(doc_id).sheets(current_sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
            sheet_data_buffer(doc_id) := NULL;
        END IF;

        -- Prepare temporary CLOB
        dbms_lob.createtemporary(blob_file, TRUE);
        dbms_lob.createtemporary(file_content2, TRUE);
        dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

        first_sheet := documents(doc_id).sheets.FIRST;
        last_sheet := documents(doc_id).sheets.LAST;


        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 1/12&apos;);
        -- [Content_Types].xml
        line_string(doc_id) := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)
                    || &apos;&lt;Types xmlns=&quot;http://schemas.openxmlformats.org/package/2006/content-types&quot;&gt;&apos;
                    || &apos;&lt;Override PartName=&quot;/xl/theme/theme1.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.theme+xml&quot;/&gt;&apos;
                    || &apos;&lt;Override PartName=&quot;/xl/styles.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml&quot;/&gt;&apos;
                    || &apos;&lt;Default Extension=&quot;rels&quot; ContentType=&quot;application/vnd.openxmlformats-package.relationships+xml&quot;/&gt;&apos;
                    || &apos;&lt;Default Extension=&quot;xml&quot; ContentType=&quot;application/xml&quot;/&gt;&apos;
                    || &apos;&lt;Override PartName=&quot;/xl/workbook.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml&quot;/&gt;&apos;
                    || &apos;&lt;Override PartName=&quot;/docProps/app.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.extended-properties+xml&quot;/&gt;&apos;
                    || &apos;&lt;Override PartName=&quot;/docProps/core.xml&quot; ContentType=&quot;application/vnd.openxmlformats-package.core-properties+xml&quot;/&gt;&apos;;

        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
        line_string(doc_id) := NULL;

        IF last_sheet IS NOT NULL THEN
            FOR i IN first_sheet .. last_sheet LOOP
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;Override PartName=&quot;/xl/worksheets/sheet&apos;||i||&apos;.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml&quot;/&gt;&apos;;
                IF LENGTH(line_string(doc_id)) &gt; 30000 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;
            END LOOP;
        END IF;

        IF documents(doc_id).shared_strings IS NOT NULL THEN
            line_string(doc_id) := line_string(doc_id) || &apos;&lt;Override PartName=&quot;/xl/sharedStrings.xml&quot; ContentType=&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml&quot;/&gt;&apos;;
        END IF;

        drawing_added := FALSE;
        IF last_sheet IS NOT NULL THEN

            FOR i IN first_sheet .. last_sheet LOOP

                IF documents(doc_id).sheets(i).comments.LAST IS NOT NULL THEN

                   line_string(doc_id) := line_string(doc_id) || &apos;&lt;Override ContentType=&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml&quot; PartName=&quot;/xl/comments&apos;||i||&apos;.xml&quot;/&gt;&apos;;

                    IF drawing_added = FALSE THEN
                        line_string(doc_id) := line_string(doc_id) || &apos;&lt;Default ContentType=&quot;application/vnd.openxmlformats-officedocument.vmlDrawing&quot; Extension=&quot;vml&quot;/&gt;&apos;;
                        drawing_added := TRUE;
                    END IF;

                END IF;

            END LOOP;

        END IF;

        line_string(doc_id) := line_string(doc_id) || &apos;&lt;/Types&gt;&apos;;
        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

        add_xml(blob_file, &apos;[Content_Types].xml&apos;, file_content2);

        dbms_lob.close(file_content2);

        print_clob(file_content2, &apos;[Content_Types].xml&apos;);
        ------------------------------------------------------------------------


        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 2/12&apos;);
        -- _rels/.rels
        file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)
                     || &apos;&lt;Relationships xmlns=&quot;http://schemas.openxmlformats.org/package/2006/relationships&quot;&gt;&apos;
                     || &apos;&lt;Relationship Id=&quot;rId3&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties&quot; Target=&quot;docProps/app.xml&quot;/&gt;&apos;
                     || &apos;&lt;Relationship Id=&quot;rId2&quot; Type=&quot;http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties&quot; Target=&quot;docProps/core.xml&quot;/&gt;&apos;
                     || &apos;&lt;Relationship Id=&quot;rId1&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument&quot; Target=&quot;xl/workbook.xml&quot;/&gt;&apos;
                     || &apos;&lt;/Relationships&gt;&apos;;
        add_xml(blob_file, &apos;_rels/.rels&apos;, file_content);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;_rels/.rels&apos;);


        -- xl/worksheets/_rels/sheetN.xml.rels
        IF documents(doc_id).sheets.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets.FIRST .. documents(doc_id).sheets.LAST LOOP

                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL OR
                   documents(doc_id).sheets(i).comments.LAST IS NOT NULL
                THEN
                    file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)
                                 || &apos;&lt;Relationships xmlns=&quot;http://schemas.openxmlformats.org/package/2006/relationships&quot;&gt;&apos;;
                    rel_id := 0;
                END IF;

                IF documents(doc_id).sheets(i).comments.LAST IS NOT NULL THEN

                   rel_id := rel_id + 1;
                   file_content := file_content ||&apos;&lt;Relationship Id=&quot;rId&apos;||rel_id||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing&quot; Target=&quot;../drawings/vmlDrawing&apos;||i||&apos;.vml&quot;/&gt;&apos;;

                   rel_id := rel_id + 1;
                   file_content := file_content ||&apos;&lt;Relationship Id=&quot;rId&apos;||rel_id||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments&quot; Target=&quot;../comments&apos;||i||&apos;.xml&quot;/&gt;&apos;;

                END IF;

                dbms_lob.createtemporary(file_content2, TRUE);
                dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL THEN

                    FOR j IN documents(doc_id).sheets(i).hyperlinks.FIRST .. documents(doc_id).sheets(i).hyperlinks.LAST LOOP
                       rel_id := rel_id + 1;
                       file_content := file_content ||&apos;&lt;Relationship Id=&quot;rId&apos;||rel_id||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink&quot; Target=&quot;&apos;||documents(doc_id).sheets(i).hyperlinks(j).hyperlink||&apos;&quot; TargetMode=&quot;External&quot;/&gt;&apos;;

                       IF LENGTH(file_content) &gt; 28000 THEN
                           dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
                           file_content := NULL;
                       END IF;

                    END LOOP;

                END IF;


                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL OR
                   documents(doc_id).sheets(i).comments.LAST IS NOT NULL
                THEN

                    file_content := file_content ||&apos;&lt;/Relationships&gt;&apos;;
                    dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);

                    add_xml(blob_file, &apos;xl/worksheets/_rels/sheet&apos;||i||&apos;.xml.rels&apos;, file_content2);
                    ------------------------------------------------------------------------
                    print_clob(file_content, &apos;xl/worksheets/_rels/sheet&apos;||i||&apos;.xml.rels&apos;);
                    dbms_lob.close(file_content2);

                END IF;

            END LOOP;

        END IF;

        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 3/12&apos;);
        -- xl\commentsN.xml
        IF documents(doc_id).sheets.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets.FIRST .. documents(doc_id).sheets.LAST LOOP

                IF documents(doc_id).sheets(i).comments.LAST IS NOT NULL THEN

                    file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;    &apos;||CHR(10)
                                 || &apos;&lt;comments xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot;&gt;&lt;authors&gt;&lt;author&gt;&apos;||dbms_xmlgen.convert(NVL(documents(doc_id).author, &apos;ORA_EXCEL&apos;))||&apos;&lt;/author&gt;&lt;/authors&gt;&lt;commentList&gt;&apos;;

                    FOR j IN documents(doc_id).sheets(i).comments.FIRST .. documents(doc_id).sheets(i).comments.LAST LOOP

                        file_content := file_content ||&apos;&lt;comment ref=&quot;&apos;||documents(doc_id).sheets(i).comments(j).cell||&apos;&quot; authorId=&quot;0&quot;&gt;&lt;text&gt;&apos;;

                        file_content := file_content ||&apos;&lt;r&gt;&lt;rPr&gt;&lt;b/&gt;&lt;sz val=&quot;9&quot;/&gt;&lt;color indexed=&quot;81&quot;/&gt;&lt;rFont val=&quot;Tahoma&quot;/&gt;&lt;family val=&quot;2&quot;/&gt;&lt;/rPr&gt;&lt;t&gt;&apos;||NVL(dbms_xmlgen.convert(documents(doc_id).sheets(i).comments(j).author), &apos;Comment:&apos;)||&apos;&lt;/t&gt;&lt;/r&gt;&lt;r&gt;&apos;;

                        file_content := file_content ||&apos;&lt;rPr&gt;&lt;sz val=&quot;9&quot;/&gt;&lt;color indexed=&quot;81&quot;/&gt;&lt;rFont val=&quot;Tahoma&quot;/&gt;&lt;family val=&quot;2&quot;/&gt;&lt;/rPr&gt;&lt;t xml:space=&quot;preserve&quot;&gt;&apos;||CHR(10)||dbms_xmlgen.convert(documents(doc_id).sheets(i).comments(j).comment_text)||&apos;&lt;/t&gt;&lt;/r&gt;&lt;/text&gt;&lt;/comment&gt;&apos;;

                    END LOOP;

                    file_content := file_content ||&apos;&lt;/commentList&gt;&lt;/comments&gt;&apos;;

                    add_xml(blob_file, &apos;xl/comments&apos;||i||&apos;.xml&apos;, file_content);
                    ------------------------------------------------------------------------
                    print_clob(file_content, &apos;xl/comments&apos;||i||&apos;.xml&apos;);

                END IF;

            END LOOP;

        END IF;


        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 4/12&apos;);
        -- xl\drawings\vmlDrawingN.vml
        IF documents(doc_id).sheets.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets.FIRST .. documents(doc_id).sheets.LAST LOOP

                IF documents(doc_id).sheets(i).comments.LAST IS NOT NULL THEN

                    dbms_lob.createtemporary(file_content2, TRUE);
                    dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

                    file_content := &apos;&lt;xml xmlns:v=&quot;urn:schemas-microsoft-com:vml&quot; xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;&gt;&apos;||CHR(10)
                                 || &apos;&lt;o:shapelayout v:ext=&quot;edit&quot;&gt;&lt;o:idmap v:ext=&quot;edit&quot; data=&quot;1&quot;/&gt;&lt;/o:shapelayout&gt;&lt;v:shapetype id=&quot;_x0000_t202&quot; coordsize=&quot;21600,21600&quot; o:spt=&quot;202&quot; path=&quot;m,l,21600r21600,l21600,xe&quot;&gt;&lt;v:stroke joinstyle=&quot;miter&quot;/&gt;&lt;v:path gradientshapeok=&quot;t&quot; o:connecttype=&quot;rect&quot;/&gt;&lt;/v:shapetype&gt;&apos;;

                    FOR j IN documents(doc_id).sheets(i).comments.FIRST .. documents(doc_id).sheets(i).comments.LAST LOOP

                        file_content := file_content ||&apos;&lt;v:shape id=&quot;_x0000_s&apos;||(1025 + j)||&apos;&quot; type=&quot;#_x0000_t202&quot; style=&apos;&apos;position:absolute;margin-left:57pt;margin-top:1.2pt;width:&apos;||NVL(documents(doc_id).sheets(i).comments(j).box_width, 100)||&apos;pt;height:&apos;||NVL(documents(doc_id).sheets(i).comments(j).box_height, 60)||
                                                       &apos;pt;z-index:1;visibility:hidden&apos;&apos; fillcolor=&quot;#ffffe1&quot; o:insetmode=&quot;auto&quot;&gt;&lt;v:fill color2=&quot;#ffffe1&quot;/&gt;&lt;v:shadow on=&quot;t&quot; color=&quot;black&quot; obscured=&quot;t&quot;/&gt;&lt;v:path o:connecttype=&quot;none&quot;/&gt;&lt;v:textbox style=&apos;&apos;mso-direction-alt:auto&apos;&apos;&gt;&apos;;
                        file_content := file_content ||&apos;&lt;div style=&apos;&apos;text-align:left&apos;&apos;&gt;&lt;/div&gt;&lt;/v:textbox&gt;&lt;x:ClientData ObjectType=&quot;Note&quot;&gt;&lt;x:MoveWithCells/&gt;&lt;x:SizeWithCells/&gt;&lt;x:Anchor&gt;1, 15, 0, 2, &apos;||ROUND(NVL(documents(doc_id).sheets(i).comments(j).box_width, 60) / 40)||&apos;, 31, &apos;||ROUND(NVL(documents(doc_id).sheets(i).comments(j).box_height, 60) / 15)||&apos;, 1&lt;/x:Anchor&gt;&lt;x:AutoFill&gt;False&lt;/x:AutoFill&gt;&apos;;
                        file_content := file_content ||&apos;&lt;x:Row&gt;&apos;||(documents(doc_id).sheets(i).comments(j).row_id)||&apos;&lt;/x:Row&gt;&lt;x:Column&gt;&apos;||(documents(doc_id).sheets(i).comments(j).column_id)||&apos;&lt;/x:Column&gt;&lt;/x:ClientData&gt;&lt;/v:shape&gt;&apos;;

                        IF LENGTH(file_content) &gt; 28000 THEN
                            dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
                            file_content := NULL;
                        END IF;

                    END LOOP;

                    file_content := file_content ||&apos;&lt;/xml&gt;&apos;;
                    dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);

                    add_xml(blob_file, &apos;xl\drawings\vmlDrawing&apos;||i||&apos;.vml&apos;, file_content2);
                    ------------------------------------------------------------------------
                    print_clob(file_content2, &apos;xl\drawings\vmlDrawing&apos;||i||&apos;.vml&apos;);
                    dbms_lob.close(file_content2);

                END IF;

            END LOOP;

        END IF;

        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 5/12&apos;);
        -- xl/_rels/workbook.xml.rels
        dbms_lob.createtemporary(file_content2, TRUE);
        dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

        file_content :=                 &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10);
        file_content := file_content || &apos;&lt;Relationships xmlns=&quot;http://schemas.openxmlformats.org/package/2006/relationships&quot;&gt;&apos;;

        IF last_sheet IS NOT NULL THEN
            FOR i IN first_sheet .. last_sheet LOOP
                file_content := file_content || &apos;&lt;Relationship Id=&quot;rId&apos;||i||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet&quot; Target=&quot;worksheets/sheet&apos;||i||&apos;.xml&quot;/&gt;&apos;;
                last_i := i;
                IF LENGTH(file_content) &gt; 10000 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
                    file_content := NULL;
                END IF;
            END LOOP;
        END IF;

        IF documents(doc_id).shared_strings IS NOT NULL THEN
            file_content := file_content || &apos;&lt;Relationship Id=&quot;rId&apos;||(last_sheet + 3)||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings&quot; Target=&quot;sharedStrings.xml&quot;/&gt;&apos;;
        END IF;

        file_content := file_content || &apos;&lt;Relationship Id=&quot;rId&apos;||(last_sheet + 2)||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles&quot; Target=&quot;styles.xml&quot;/&gt;&apos;
                                     || &apos;&lt;Relationship Id=&quot;rId&apos;||(last_sheet + 1)||&apos;&quot; Type=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme&quot; Target=&quot;theme/theme1.xml&quot;/&gt;&apos;
                                     || &apos;&lt;/Relationships&gt;&apos;;

        dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
        add_xml(blob_file, &apos;xl/_rels/workbook.xml.rels&apos;, file_content2);
        dbms_lob.close(file_content2);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;xl/_rels/workbook.xml.rels&apos;);


        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 6/12&apos;);
        -- xl/workbook.xml
        dbms_lob.createtemporary(file_content2, TRUE);
        dbms_lob.open(file_content2, dbms_lob.lob_readwrite);
        file_content :=    &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)
                        || &apos;&lt;workbook xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot; xmlns:r=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships&quot;&gt;&apos;
                        || &apos;&lt;fileVersion appName=&quot;xl&quot; lastEdited=&quot;4&quot; lowestEdited=&quot;4&quot; rupBuild=&quot;4505&quot;/&gt;&apos;
                        || &apos;&lt;workbookPr &apos;;
        IF NVL(date_system, 1904) = 1904 THEN
            file_content := file_content || &apos;date1904=&quot;true&quot;&apos;;
        END IF;

         file_content := file_content || &apos; defaultThemeVersion=&quot;124226&quot;/&gt;&apos;
                                      || &apos;&lt;bookViews&gt;&apos;
                                      || &apos;&lt;workbookView xWindow=&quot;120&quot; yWindow=&quot;120&quot; windowWidth=&quot;28695&quot; windowHeight=&quot;14310&quot;/&gt;&apos;
                                      || &apos;&lt;/bookViews&gt;&apos;
                                      || &apos;&lt;sheets&gt;&apos;;
        IF last_sheet IS NOT NULL THEN
            FOR i IN first_sheet .. last_sheet LOOP
                file_content := file_content || &apos;&lt;sheet name=&quot;&apos;||dbms_xmlgen.convert(documents(doc_id).sheets(i).sheet_name)||&apos;&quot; sheetId=&quot;&apos;||i||&apos;&quot; r:id=&quot;rId&apos;||i||&apos;&quot;/&gt;&apos;;
                IF LENGTH(file_content) &gt; 10000 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
                    file_content := NULL;
                END IF;
            END LOOP;
        END IF;
        file_content := file_content || &apos;&lt;/sheets&gt;&apos;
                                     || &apos;&lt;calcPr calcId=&quot;124519&quot;/&gt;&apos;
                                     || &apos;&lt;/workbook&gt;&apos;;
         dbms_lob.writeappend(file_content2, LENGTH(file_content), file_content);
        add_xml(blob_file, &apos;xl/workbook.xml&apos;, file_content2);
        dbms_lob.close(file_content2);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;xl/workbook.xml&apos;);





        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 7/12&apos;);
        -- xl/styles.xml
        dbms_lob.createtemporary(file_content2, TRUE);
        dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

        line_string(doc_id) :=  &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)||&apos;&lt;styleSheet xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot;&gt;&apos;;

        -- Formats
        IF documents(doc_id).format_masks.LAST IS NOT NULL THEN

            line_string(doc_id) := line_string(doc_id) || &apos;&lt;numFmts count=&quot;&apos;||NVL(documents(doc_id).format_masks.LAST, 0)||&apos;&quot;&gt;&apos;;

            FOR i IN documents(doc_id).format_masks.FIRST .. documents(doc_id).format_masks.LAST LOOP

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;numFmt numFmtId=&quot;&apos;||(i + 164)||&apos;&quot; formatCode=&quot;&apos;||documents(doc_id).format_masks(i).format_mask||&apos;&quot;/&gt;&apos;;

                IF LENGTH(line_string(doc_id)) &gt; 3500 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;
            END LOOP;

            line_string(doc_id) := line_string(doc_id) || &apos;&lt;/numFmts&gt;&apos;;

            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

            line_string(doc_id) := NULL;

        END IF;

        -- Fonts
        line_string(doc_id) :=  line_string(doc_id) || &apos;&lt;fonts count=&quot;&apos;||NVL(documents(doc_id).fonts.LAST, 1)||&apos;&quot;&gt;&apos;;

        -- Default font
        line_string(doc_id) := line_string(doc_id) || &apos;&lt;font&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) || &apos;&lt;sz val=&quot;&apos;||documents(doc_id).default_font.font_size||&apos;&quot;/&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) || &apos;&lt;name val=&quot;&apos;||documents(doc_id).default_font.font_name||&apos;&quot;/&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) || &apos;&lt;/font&gt;&apos;;


        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

        line_string(doc_id) := NULL;

        IF documents(doc_id).fonts.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).fonts.FIRST .. documents(doc_id).fonts.LAST LOOP

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;font&gt;&apos;;

                IF documents(doc_id).fonts(i).bold = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;b/&gt;&apos;;
                END IF;

                IF documents(doc_id).fonts(i).italic = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;i/&gt;&apos;;
                END IF;

                IF documents(doc_id).fonts(i).underline = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;u/&gt;&apos;;
                END IF;

                IF documents(doc_id).fonts(i).color IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;color rgb=&quot;&apos;||documents(doc_id).fonts(i).color||&apos;&quot;/&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;sz val=&quot;&apos;||documents(doc_id).fonts(i).font_size||&apos;&quot;/&gt;&apos;;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;name val=&quot;&apos;||dbms_xmlgen.convert(documents(doc_id).fonts(i).font_name)||&apos;&quot;/&gt;&apos;;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/font&gt;&apos;;
                IF LENGTH(line_string(doc_id)) &gt; 3500 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;

            END LOOP;
        END IF;

        line_string(doc_id) := line_string(doc_id) || &apos;&lt;/fonts&gt;&apos;;
        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

        -- Fills
        line_string(doc_id) := &apos;&lt;fills count=&quot;&apos;||NVL(documents(doc_id).fills.LAST, 0)||&apos;&quot;&gt;&apos;;

        IF documents(doc_id).fills.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).fills.FIRST .. documents(doc_id).fills.LAST LOOP

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;fill&gt;&apos;;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;patternFill patternType=&quot;&apos;||documents(doc_id).fills(i).pattern_type||&apos;&quot;&apos;;

                IF documents(doc_id).fills(i).color IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&gt;&lt;fgColor  rgb=&quot;&apos;||documents(doc_id).fills(i).color||&apos;&quot;/&gt;&lt;bgColor indexed=&quot;64&quot;/&gt;&lt;/patternFill&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) || &apos;/&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/fill&gt;&apos;;

                IF LENGTH(line_string(doc_id)) &gt; 3500 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;

            END LOOP;

        END IF;

        line_string(doc_id) := line_string(doc_id) || &apos;&lt;/fills&gt;&apos;;
        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

        line_string(doc_id) := &apos;&lt;borders count=&quot;&apos;||NVL(documents(doc_id).borders.LAST, 0)||&apos;&quot;&gt;&apos;;

        IF documents(doc_id).borders.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).borders.FIRST .. documents(doc_id).borders.LAST LOOP

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;border&gt;&apos;;

                IF documents(doc_id).borders(i).border_left = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;left style=&quot;&apos;||NVL(documents(doc_id).borders(i).border_left_style, &apos;thin&apos;)||&apos;&quot;&gt;&lt;color rgb=&quot;&apos;||NVL(documents(doc_id).borders(i).border_left_color, &apos;00000000&apos;)||&apos;&quot;/&gt;&lt;/left&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;left/&gt;&apos;;
                END IF;

                IF documents(doc_id).borders(i).border_right = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;right style=&quot;&apos;||NVL(documents(doc_id).borders(i).border_right_style, &apos;thin&apos;)||&apos;&quot;&gt;&lt;color rgb=&quot;&apos;||NVL(documents(doc_id).borders(i).border_right_color, &apos;00000000&apos;)||&apos;&quot;/&gt;&lt;/right&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;right/&gt;&apos;;
                END IF;

                IF documents(doc_id).borders(i).border_top = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;top style=&quot;&apos;||NVL(documents(doc_id).borders(i).border_top_style, &apos;thin&apos;)||&apos;&quot;&gt;&lt;color rgb=&quot;&apos;||NVL(documents(doc_id).borders(i).border_top_color, &apos;00000000&apos;)||&apos;&quot;/&gt;&lt;/top&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;top/&gt;&apos;;
                END IF;

                IF documents(doc_id).borders(i).border_bottom = TRUE THEN
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;bottom style=&quot;&apos;||NVL(documents(doc_id).borders(i).border_bottom_style, &apos;thin&apos;)||&apos;&quot;&gt;&lt;color rgb=&quot;&apos;||NVL(documents(doc_id).borders(i).border_bottom_color, &apos;00000000&apos;)||&apos;&quot;/&gt;&lt;/bottom&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;bottom/&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;diagonal/&gt;&apos;;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/border&gt;&apos;;

                IF LENGTH(line_string(doc_id)) &gt; 3500 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;

            END LOOP;

        END IF;


        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;/borders&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;cellStyleXfs count=&quot;1&quot;&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;xf numFmtId=&quot;0&quot; fontId=&quot;0&quot; fillId=&quot;0&quot; borderId=&quot;0&quot;/&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;/cellStyleXfs&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;cellXfs count=&quot;&apos;||(NVL(documents(doc_id).formats.LAST, 0) + 0)||&apos;&quot;&gt;&apos;;
        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
        line_string(doc_id) := NULL;

        IF documents(doc_id).formats.LAST IS NOT NULL THEN
            FOR i IN documents(doc_id).formats.FIRST .. documents(doc_id).formats.LAST LOOP

                line_string(doc_id) := line_string(doc_id) ||&apos;&lt;xf numFmtId=&quot;&apos;||documents(doc_id).formats(i).num_fmt_id||&apos;&quot; fontId=&quot;&apos;||documents(doc_id).formats(i).font_id||&apos;&quot; fillId=&quot;&apos;||documents(doc_id).formats(i).fill_id||&apos;&quot; borderId=&quot;&apos;||documents(doc_id).formats(i).border_id||&apos;&quot; xfId=&quot;&apos;||documents(doc_id).formats(i).xf_id||&apos;&quot;&apos;;

                IF documents(doc_id).formats(i).num_fmt_id &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; applyNumberFormat=&quot;1&quot;&apos;;
                END IF;

                IF documents(doc_id).formats(i).font_id &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; applyFont=&quot;1&quot;&apos;;
                END IF;

                IF documents(doc_id).formats(i).fill_id &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; applyFill=&quot;1&quot;&apos;;
                END IF;

                IF documents(doc_id).formats(i).border_id &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; applyBorder=&quot;1&quot;&apos;;
                END IF;

                IF documents(doc_id).formats(i).horizontal_align IS NOT NULL OR
                   documents(doc_id).formats(i).vertical_align IS NOT NULL OR
                   documents(doc_id).formats(i).indent_left IS NOT NULL OR
                   documents(doc_id).formats(i).indent_right IS NOT NULL
                THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; applyAlignment=&quot;1&quot;&apos;;
                END IF;


                IF documents(doc_id).formats(i).horizontal_align IS NOT NULL OR
                   documents(doc_id).formats(i).vertical_align IS NOT NULL OR
                   NVL(documents(doc_id).formats(i).wrap_text, FALSE) = TRUE OR
                   NVL(documents(doc_id).formats(i).rotate_text_degree, 0) != 0 OR
                   NVL(documents(doc_id).formats(i).indent_left, 0) != 0 OR
                   NVL(documents(doc_id).formats(i).indent_right, 0) != 0
                THEN

                    line_string(doc_id) := line_string(doc_id) || &apos;&gt;&lt;alignment&apos;;

                    IF documents(doc_id).formats(i).horizontal_align IS NOT NULL THEN
                        CASE documents(doc_id).formats(i).horizontal_align
                            WHEN &apos;L&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;left&quot;&apos;;
                            WHEN &apos;C&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;center&quot;&apos;;
                            WHEN &apos;R&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;right&quot;&apos;;
                            ELSE
                                line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;right&quot;&apos;;
                        END CASE;
                    END IF;

                    IF documents(doc_id).formats(i).vertical_align IS NOT NULL THEN
                        CASE documents(doc_id).formats(i).vertical_align
                            WHEN &apos;T&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; vertical=&quot;top&quot;&apos;;
                            WHEN &apos;M&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; vertical=&quot;center&quot;&apos;;
                            WHEN &apos;B&apos; THEN
                                line_string(doc_id) := line_string(doc_id) || &apos; vertical=&quot;bottom&quot;&apos;;
                            ELSE
                                line_string(doc_id) := line_string(doc_id) || &apos; vertical=&quot;bottom&quot;&apos;;
                        END CASE;
                    END IF;

                    IF NVL(documents(doc_id).formats(i).wrap_text, FALSE) = TRUE THEN
                        line_string(doc_id) := line_string(doc_id) || &apos; wrapText=&quot;1&quot;&apos;;
                    END IF;

                    IF NVL(documents(doc_id).formats(i).rotate_text_degree, 0) != 0  THEN
                         line_string(doc_id) := line_string(doc_id) || &apos; textRotation=&quot;&apos;||documents(doc_id).formats(i).rotate_text_degree||&apos;&quot;&apos;;
                    END IF;

                    IF NVL(documents(doc_id).formats(i).indent_left, 0) &gt; 0  THEN
                         IF documents(doc_id).formats(i).horizontal_align NOT IN (&apos;L&apos;,&apos;C&apos;,&apos;R&apos;) THEN
                            line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;left&quot; &apos;;
                         END IF;
                         line_string(doc_id) := line_string(doc_id) || &apos; indent=&quot;&apos;||documents(doc_id).formats(i).indent_left||&apos;&quot;&apos;;
                    END IF;

                    IF NVL(documents(doc_id).formats(i).indent_right, 0) &gt; 0  THEN
                        IF documents(doc_id).formats(i).horizontal_align NOT IN (&apos;L&apos;,&apos;C&apos;,&apos;R&apos;) THEN
                            line_string(doc_id) := line_string(doc_id) || &apos; horizontal=&quot;right&quot; &apos;;
                         END IF;
                         line_string(doc_id) := line_string(doc_id) || &apos; indent=&quot;&apos;||documents(doc_id).formats(i).indent_right||&apos;&quot;&apos;;
                    END IF;

                    line_string(doc_id) := line_string(doc_id) || &apos;/&gt;&apos;;
                END IF;


                IF documents(doc_id).formats(i).horizontal_align IS NOT NULL OR
                   documents(doc_id).formats(i).vertical_align IS NOT NULL OR
                   NVL(documents(doc_id).formats(i).wrap_text, FALSE) = TRUE OR
                   NVL(documents(doc_id).formats(i).rotate_text_degree, 0) != 0 OR
                   NVL(documents(doc_id).formats(i).indent_left, 0) != 0 OR
                   NVL(documents(doc_id).formats(i).indent_right, 0) != 0
                THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;/xf&gt;&apos;;
                ELSE
                    line_string(doc_id) := line_string(doc_id) || &apos;/&gt;&apos;;
                END IF;

                IF LENGTH(line_string(doc_id)) &gt; 3500 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;

            END LOOP;
        END IF;

        line_string(doc_id) := line_string(doc_id) || &apos;&lt;/cellXfs&gt;&apos;;

        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));



        IF documents(doc_id).have_hyperlinks = TRUE OR documents(doc_id).have_internal_hyperlinks = TRUE THEN
            line_string(doc_id) := &apos;&lt;cellStyles count=&quot;2&quot;&gt;&apos;;
            line_string(doc_id) := line_string(doc_id) ||&apos;&lt;cellStyle name=&quot;Hyperlink&quot; xfId=&quot;1&quot; builtinId=&quot;8&quot;/&gt;&apos;;
        ELSE
            line_string(doc_id) := &apos;&lt;cellStyles count=&quot;1&quot;&gt;&apos;;
        END IF;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;cellStyle name=&quot;Normal&quot; xfId=&quot;0&quot; builtinId=&quot;0&quot;/&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;/cellStyles&gt;&apos;;


        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;dxfs count=&quot;0&quot;/&gt;&apos;;
        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;tableStyles count=&quot;0&quot; defaultTableStyle=&quot;TableStyleMedium9&quot; defaultPivotStyle=&quot;PivotStyleLight16&quot;/&gt;&apos;;

        line_string(doc_id) := NULL;

        IF documents(doc_id).fills.LAST IS NOT NULL THEN


            show_header := TRUE;

            FOR i IN documents(doc_id).fills.FIRST .. documents(doc_id).fills.LAST LOOP

                IF documents(doc_id).fills(i).color IS NOT NULL THEN

                    IF show_header = TRUE THEN
                        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;colors&gt;&lt;mruColors&gt;&apos;;
                        show_header := FALSE;
                    END IF;

                    line_string(doc_id) := line_string(doc_id) ||&apos;&lt;color rgb=&quot;&apos;||documents(doc_id).fills(i).color||&apos;&quot;/&gt;&apos;;

                END IF;

            END LOOP;

            IF show_header = FALSE THEN
                line_string(doc_id) := line_string(doc_id) ||&apos;&lt;/mruColors&gt;&lt;/colors&gt;&apos;;
            END IF;

        END IF;

        line_string(doc_id) := line_string(doc_id) ||&apos;&lt;/styleSheet&gt;&apos;;
        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

        add_xml(blob_file, &apos;xl/styles.xml&apos;, file_content2);

        dbms_lob.close(file_content2);
        ------------------------------------------------------------------------
        print_clob(file_content2, &apos;xl/styles.xml&apos;);



        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 8/12&apos;);
        -- xl/sharedStrings.xm
        IF LENGTH(documents(doc_id).shared_strings) &gt; 0 OR LENGTH(shared_strings_buffer(doc_id)) &gt; 0 OR documents(doc_id).shared_strings_buffer.LAST IS NOT NULL THEN

            dbms_lob.createtemporary(file_content2, TRUE);
            dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

            line_string(doc_id) := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10)||&apos;&lt;sst xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot; count=&quot;&apos;||documents(doc_id).last_shared_string_num||&apos;&quot; uniqueCount=&quot;&apos;||documents(doc_id).last_shared_string_num||&apos;&quot;&gt;&apos;;----
            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

            -- Append shared strings from buffer
            IF shared_strings_buffer(doc_id) IS NOT NULL THEN
                dbms_lob.writeappend(documents(doc_id).shared_strings, LENGTH(shared_strings_buffer(doc_id)), shared_strings_buffer(doc_id));
                shared_strings_buffer(doc_id) := NULL;
            END IF;

            IF documents(doc_id).shared_strings_buffer.LAST IS NOT NULL THEN

                FOR buffer_id IN documents(doc_id).shared_strings_buffer.FIRST .. documents(doc_id).shared_strings_buffer.LAST LOOP

                    -- Append shared strings
                    dbms_lob.append(file_content2,  documents(doc_id).shared_strings_buffer(buffer_id));

                    dbms_lob.freetemporary(documents(doc_id).shared_strings_buffer(buffer_id));

                END LOOP;

            END IF;

            documents(doc_id).shared_strings_buffer.DELETE;

            IF DBMS_LOB.getlength(documents(doc_id).shared_strings) &gt; 0 THEN
                dbms_lob.append(file_content2,  documents(doc_id).shared_strings);
                documents(doc_id).shared_strings := initialize_clob;
            END IF;


            -- Release CLOB memory
            dbms_lob.freetemporary(documents(doc_id).shared_strings);

            line_string(doc_id) := &apos;&lt;/sst&gt;&apos;;
            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

            add_xml(blob_file, &apos;xl/sharedStrings.xml&apos;, file_content2);

            -- Release CLOB memory
            dbms_lob.close(file_content2);

        END IF;
        ------------------------------------------------------------------------
        print_clob(file_content2, &apos;xl/sharedStrings.xml&apos;);



        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 9/12&apos;);
        -- xl/theme/theme1.xml
        file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10);
        file_content := file_content || &apos;&lt;a:theme xmlns:a=&quot;http://schemas.openxmlformats.org/drawingml/2006/main&quot; name=&quot;Office Theme&quot;&gt;&lt;a:themeElements&gt;&lt;a:clrScheme name=&quot;Office&quot;&gt;&lt;a:dk1&gt;&lt;a:sysClr val=&quot;windowText&quot; lastClr=&quot;000000&quot;/&gt;&lt;/a:dk1&gt;&lt;a:lt1&gt;&lt;a:sysClr val=&quot;window&quot; lastClr=&quot;FFFFFF&quot;/&gt;&lt;/a:lt1&gt;&lt;a:dk2&gt;&lt;a:srgbClr val=&quot;1F497D&quot;/&gt;&lt;/a:dk2&gt;&lt;a:lt2&gt;&lt;a:srgbClr val=&quot;EEECE1&quot;/&gt;&lt;/a:lt2&gt;&lt;a:accent1&gt;&lt;a:srgbClr val=&quot;4F81BD&quot;/&gt;&lt;/a:accent1&gt;&lt;a:accent2&gt;&lt;a:srgbClr val=&quot;C0504D&quot;/&gt;&lt;/a:accent2&gt;&lt;a:accent3&gt;&lt;a:srgbClr val=&quot;9BBB59&quot;/&gt;&lt;/a:accent3&gt;&lt;a:accent4&gt;&lt;a:srgbClr val=&quot;8064A2&quot;/&gt;&lt;/a:accent4&gt;&lt;a:accent5&gt;&lt;a:srgbClr val=&quot;4BACC6&quot;/&gt;&lt;/a:accent5&gt;&lt;a:accent6&gt;&lt;a:srgbClr val=&quot;F79646&quot;/&gt;&lt;/a:accent6&gt;&lt;a:hlink&gt;&lt;a:srgbClr val=&quot;0000FF&quot;/&gt;&lt;/a:hlink&gt;&lt;a:folHlink&gt;&lt;a:srgbClr val=&quot;800080&quot;/&gt;&lt;/a:folHlink&gt;&lt;/a:clrScheme&gt;&lt;a:fontScheme name=&quot;Office&quot;&gt;&lt;a:majorFont&gt;&lt;a:latin typeface=&quot;Cambria&quot;/&gt;&lt;a:ea typeface=&quot;&quot;/&gt;&lt;a:cs typeface=&quot;&quot;/&gt;&lt;a:font script=&quot;Jpan&quot; typeface=&quot;MS P????&quot;/&gt;&apos;||
        &apos;&lt;a:font script=&quot;Hang&quot; typeface=&quot;?? ??&quot;/&gt;&lt;a:font script=&quot;Hans&quot; typeface=&quot;??&quot;/&gt;&apos;||
        &apos;&lt;a:font script=&quot;Hant&quot; typeface=&quot;????&quot;/&gt;&lt;a:font script=&quot;Arab&quot; typeface=&quot;Times New Roman&quot;/&gt;&lt;a:font script=&quot;Hebr&quot; typeface=&quot;Times New Roman&quot;/&gt;&lt;a:font script=&quot;Thai&quot; typeface=&quot;Tahoma&quot;/&gt;&lt;a:font script=&quot;Ethi&quot; typeface=&quot;Nyala&quot;/&gt;&lt;a:font script=&quot;Beng&quot; typeface=&quot;Vrinda&quot;/&gt;&lt;a:font script=&quot;Gujr&quot; typeface=&quot;Shruti&quot;/&gt;&lt;a:font script=&quot;Khmr&quot; typeface=&quot;MoolBoran&quot;/&gt;&lt;a:font script=&quot;Knda&quot; typeface=&quot;Tunga&quot;/&gt;&lt;a:font script=&quot;Guru&quot; typeface=&quot;Raavi&quot;/&gt;&lt;a:font script=&quot;Cans&quot; typeface=&quot;Euphemia&quot;/&gt;&lt;a:font script=&quot;Cher&quot; typeface=&quot;Plantagenet Cherokee&quot;/&gt;&lt;a:font script=&quot;Yiii&quot; typeface=&quot;Microsoft Yi Baiti&quot;/&gt;&lt;a:font script=&quot;Tibt&quot; typeface=&quot;Microsoft Himalaya&quot;/&gt;&lt;a:font script=&quot;Thaa&quot; typeface=&quot;MV Boli&quot;/&gt;&lt;a:font script=&quot;Deva&quot; typeface=&quot;Mangal&quot;/&gt;&lt;a:font script=&quot;Telu&quot; typeface=&quot;Gautami&quot;/&gt;&lt;a:font script=&quot;Taml&quot; typeface=&quot;Latha&quot;/&gt;&lt;a:font script=&quot;Syrc&quot; typeface=&quot;Estrangelo Edessa&quot;/&gt;&lt;a:font script=&quot;Orya&quot; typeface=&quot;Kalinga&quot;/&gt;&lt;a:font script=&quot;Mlym&quot; typeface=&quot;Kartika&quot;/&gt;&lt;a:font script=&quot;Laoo&quot; typeface=&quot;DokChampa&quot;/&gt;&apos;||
        &apos;&lt;a:font script=&quot;Sinh&quot; typeface=&quot;Iskoola Pota&quot;/&gt;&lt;a:font script=&quot;Mong&quot; typeface=&quot;Mongolian Baiti&quot;/&gt;&lt;a:font script=&quot;Viet&quot; typeface=&quot;Times New Roman&quot;/&gt;&lt;a:font script=&quot;Uigh&quot; typeface=&quot;Microsoft Uighur&quot;/&gt;&lt;/a:majorFont&gt;&lt;a:minorFont&gt;&lt;a:latin typeface=&quot;Calibri&quot;/&gt;&lt;a:ea typeface=&quot;&quot;/&gt;&lt;a:cs typeface=&quot;&quot;/&gt;&lt;a:font script=&quot;Jpan&quot; typeface=&quot;MS P????&quot;/&gt;&lt;a:font script=&quot;Hang&quot; typeface=&quot;?? ??&quot;/&gt;&lt;a:font script=&quot;Hans&quot; typeface=&quot;??&quot;/&gt;&lt;a:font script=&quot;Hant&quot; typeface=&quot;????&quot;/&gt;&lt;a:font script=&quot;Arab&quot; typeface=&quot;Arial&quot;/&gt;&lt;a:font script=&quot;Hebr&quot; typeface=&quot;Arial&quot;/&gt;&lt;a:font script=&quot;Thai&quot; typeface=&quot;Tahoma&quot;/&gt;&lt;a:font script=&quot;Ethi&quot; typeface=&quot;Nyala&quot;/&gt;&lt;a:font script=&quot;Beng&quot; typeface=&quot;Vrinda&quot;/&gt;&lt;a:font script=&quot;Gujr&quot; typeface=&quot;Shruti&quot;/&gt;&lt;a:font script=&quot;Khmr&quot; typeface=&quot;DaunPenh&quot;/&gt;&lt;a:font script=&quot;Knda&quot; typeface=&quot;Tunga&quot;/&gt;&lt;a:font script=&quot;Guru&quot; typeface=&quot;Raavi&quot;/&gt;&lt;a:font script=&quot;Cans&quot; typeface=&quot;Euphemia&quot;/&gt;&lt;a:font script=&quot;Cher&quot; typeface=&quot;Plantagenet Cherokee&quot;/&gt;&lt;a:font script=&quot;Yiii&quot; typeface=&quot;Microsoft Yi Baiti&quot;/&gt;&apos;||
        &apos;&lt;a:font script=&quot;Tibt&quot; typeface=&quot;Microsoft Himalaya&quot;/&gt;&lt;a:font script=&quot;Thaa&quot; typeface=&quot;MV Boli&quot;/&gt;&lt;a:font script=&quot;Deva&quot; typeface=&quot;Mangal&quot;/&gt;&lt;a:font script=&quot;Telu&quot; typeface=&quot;Gautami&quot;/&gt;&lt;a:font script=&quot;Taml&quot; typeface=&quot;Latha&quot;/&gt;&lt;a:font script=&quot;Syrc&quot; typeface=&quot;Estrangelo Edessa&quot;/&gt;&lt;a:font script=&quot;Orya&quot; typeface=&quot;Kalinga&quot;/&gt;&lt;a:font script=&quot;Mlym&quot; typeface=&quot;Kartika&quot;/&gt;&lt;a:font script=&quot;Laoo&quot; typeface=&quot;DokChampa&quot;/&gt;&lt;a:font script=&quot;Sinh&quot; typeface=&quot;Iskoola Pota&quot;/&gt;&lt;a:font script=&quot;Mong&quot; typeface=&quot;Mongolian Baiti&quot;/&gt;&lt;a:font script=&quot;Viet&quot; typeface=&quot;Arial&quot;/&gt;&lt;a:font script=&quot;Uigh&quot; typeface=&quot;Microsoft Uighur&quot;/&gt;&lt;/a:minorFont&gt;&lt;/a:fontScheme&gt;&lt;a:fmtScheme name=&quot;Office&quot;&gt;&lt;a:fillStyleLst&gt;&lt;a:solidFill&gt;&lt;a:schemeClr val=&quot;phClr&quot;/&gt;&lt;/a:solidFill&gt;&lt;a:gradFill rotWithShape=&quot;1&quot;&gt;&lt;a:gsLst&gt;&lt;a:gs pos=&quot;0&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;50000&quot;/&gt;&lt;a:satMod val=&quot;300000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;35000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;37000&quot;/&gt;&lt;a:satMod val=&quot;300000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&apos;||&apos;
        &lt;a:gs pos=&quot;100000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;15000&quot;/&gt;&lt;a:satMod val=&quot;350000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;/a:gsLst&gt;&lt;a:lin ang=&quot;16200000&quot; scaled=&quot;1&quot;/&gt;&lt;/a:gradFill&gt;&lt;a:gradFill rotWithShape=&quot;1&quot;&gt;&lt;a:gsLst&gt;&lt;a:gs pos=&quot;0&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;51000&quot;/&gt;&lt;a:satMod val=&quot;130000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;80000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;93000&quot;/&gt;&lt;a:satMod val=&quot;130000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;100000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;94000&quot;/&gt;&lt;a:satMod val=&quot;135000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;/a:gsLst&gt;&lt;a:lin ang=&quot;16200000&quot; scaled=&quot;0&quot;/&gt;&lt;/a:gradFill&gt;&lt;/a:fillStyleLst&gt;&lt;a:lnStyleLst&gt;&lt;a:ln w=&quot;9525&quot; cap=&quot;flat&quot; cmpd=&quot;sng&quot; algn=&quot;ctr&quot;&gt;&lt;a:solidFill&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;95000&quot;/&gt;&lt;a:satMod val=&quot;105000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:solidFill&gt;&lt;a:prstDash val=&quot;solid&quot;/&gt;&lt;/a:ln&gt;&lt;a:ln w=&quot;25400&quot; cap=&quot;flat&quot; cmpd=&quot;sng&quot; algn=&quot;ctr&quot;&gt;&lt;a:solidFill&gt;&lt;a:schemeClr val=&quot;phClr&quot;/&gt;&lt;/a:solidFill&gt;&lt;a:prstDash val=&quot;solid&quot;/&gt;&apos;||
        &apos;&lt;/a:ln&gt;&lt;a:ln w=&quot;38100&quot; cap=&quot;flat&quot; cmpd=&quot;sng&quot; algn=&quot;ctr&quot;&gt;&lt;a:solidFill&gt;&lt;a:schemeClr val=&quot;phClr&quot;/&gt;&lt;/a:solidFill&gt;&lt;a:prstDash val=&quot;solid&quot;/&gt;&lt;/a:ln&gt;&lt;/a:lnStyleLst&gt;&lt;a:effectStyleLst&gt;&lt;a:effectStyle&gt;&lt;a:effectLst&gt;&lt;a:outerShdw blurRad=&quot;40000&quot; dist=&quot;20000&quot; dir=&quot;5400000&quot; rotWithShape=&quot;0&quot;&gt;&lt;a:srgbClr val=&quot;000000&quot;&gt;&lt;a:alpha val=&quot;38000&quot;/&gt;&lt;/a:srgbClr&gt;&lt;/a:outerShdw&gt;&lt;/a:effectLst&gt;&lt;/a:effectStyle&gt;&lt;a:effectStyle&gt;&lt;a:effectLst&gt;&lt;a:outerShdw blurRad=&quot;40000&quot; dist=&quot;23000&quot; dir=&quot;5400000&quot; rotWithShape=&quot;0&quot;&gt;&lt;a:srgbClr val=&quot;000000&quot;&gt;&lt;a:alpha val=&quot;35000&quot;/&gt;&lt;/a:srgbClr&gt;&lt;/a:outerShdw&gt;&lt;/a:effectLst&gt;&lt;/a:effectStyle&gt;&lt;a:effectStyle&gt;&lt;a:effectLst&gt;&lt;a:outerShdw blurRad=&quot;40000&quot; dist=&quot;23000&quot; dir=&quot;5400000&quot; rotWithShape=&quot;0&quot;&gt;&lt;a:srgbClr val=&quot;000000&quot;&gt;&lt;a:alpha val=&quot;35000&quot;/&gt;&lt;/a:srgbClr&gt;&lt;/a:outerShdw&gt;&lt;/a:effectLst&gt;&lt;a:scene3d&gt;&lt;a:camera prst=&quot;orthographicFront&quot;&gt;&lt;a:rot lat=&quot;0&quot; lon=&quot;0&quot; rev=&quot;0&quot;/&gt;&lt;/a:camera&gt;&lt;a:lightRig rig=&quot;threePt&quot; dir=&quot;t&quot;&gt;&lt;a:rot lat=&quot;0&quot; lon=&quot;0&quot; rev=&quot;1200000&quot;/&gt;&lt;/a:lightRig&gt;&lt;/a:scene3d&gt;&apos;||
        &apos;&lt;a:sp3d&gt;&lt;a:bevelT w=&quot;63500&quot; h=&quot;25400&quot;/&gt;&lt;/a:sp3d&gt;&lt;/a:effectStyle&gt;&lt;/a:effectStyleLst&gt;&lt;a:bgFillStyleLst&gt;&lt;a:solidFill&gt;&lt;a:schemeClr val=&quot;phClr&quot;/&gt;&lt;/a:solidFill&gt;&lt;a:gradFill rotWithShape=&quot;1&quot;&gt;&lt;a:gsLst&gt;&lt;a:gs pos=&quot;0&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;40000&quot;/&gt;&lt;a:satMod val=&quot;350000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;40000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;45000&quot;/&gt;&lt;a:shade val=&quot;99000&quot;/&gt;&lt;a:satMod val=&quot;350000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;100000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;20000&quot;/&gt;&lt;a:satMod val=&quot;255000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;/a:gsLst&gt;&lt;a:path path=&quot;circle&quot;&gt;&lt;a:fillToRect l=&quot;50000&quot; t=&quot;-80000&quot; r=&quot;50000&quot; b=&quot;180000&quot;/&gt;&lt;/a:path&gt;&lt;/a:gradFill&gt;&lt;a:gradFill rotWithShape=&quot;1&quot;&gt;&lt;a:gsLst&gt;&lt;a:gs pos=&quot;0&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:tint val=&quot;80000&quot;/&gt;&lt;a:satMod val=&quot;300000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;a:gs pos=&quot;100000&quot;&gt;&lt;a:schemeClr val=&quot;phClr&quot;&gt;&lt;a:shade val=&quot;30000&quot;/&gt;&lt;a:satMod val=&quot;200000&quot;/&gt;&lt;/a:schemeClr&gt;&lt;/a:gs&gt;&lt;/a:gsLst&gt;&lt;a:path path=&quot;circle&quot;&gt;&apos;||
        &apos;&lt;a:fillToRect l=&quot;50000&quot; t=&quot;50000&quot; r=&quot;50000&quot; b=&quot;50000&quot;/&gt;&lt;/a:path&gt;&lt;/a:gradFill&gt;&lt;/a:bgFillStyleLst&gt;&lt;/a:fmtScheme&gt;&lt;/a:themeElements&gt;&lt;a:objectDefaults/&gt;&lt;a:extraClrSchemeLst/&gt;&lt;/a:theme&gt;&apos;;
        add_xml(blob_file, &apos;xl/theme/theme1.xml&apos;, file_content);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;xl/theme/theme1.xml&apos;);



        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 10/12&apos;);
        -- xl/worksheets/sheetN.xml
        IF documents(doc_id).sheets.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets.FIRST .. documents(doc_id).sheets.LAST LOOP

                dbms_lob.createtemporary(file_content2, TRUE);
                dbms_lob.open(file_content2, dbms_lob.lob_readwrite);

                top_right_column := documents(doc_id).sheets(i).top_right_column;
                last_row := documents(doc_id).sheets(i).last_row_num;

                line_string(doc_id) := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10);
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;worksheet xmlns=&quot;http://schemas.openxmlformats.org/spreadsheetml/2006/main&quot; xmlns:r=&quot;http://schemas.openxmlformats.org/officeDocument/2006/relationships&quot;&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;dimension ref=&quot;A1:&apos;||REPLACE(column_numeric2alpha(top_right_column), &apos;@&apos;, &apos;A&apos;)||REPLACE(last_row, &apos;0&apos;, &apos;1&apos;)||&apos;&quot;/&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;sheetViews&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;sheetView &apos;;
                IF i = 1 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; tabSelected=&quot;1&quot; &apos;;
                END IF;
                line_string(doc_id) := line_string(doc_id) || &apos; workbookViewId=&quot;0&quot;&gt;&apos;;

        -- Freeze panes
                IF documents(doc_id).sheets(i).freeze_panes_horizontal IS NOT NULL AND documents(doc_id).sheets(i).freeze_panes_vertical IS NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;pane ySplit=&quot;&apos;||documents(doc_id).sheets(i).freeze_panes_horizontal||&apos;&quot; topLeftCell=&quot;A&apos;||(documents(doc_id).sheets(i).freeze_panes_horizontal+1)||&apos;&quot; state=&quot;frozenSplit&quot;/&gt;&apos;;
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection pane=&quot;bottomLeft&quot; activeCell=&quot;A&apos;||(documents(doc_id).sheets(i).freeze_panes_horizontal+1)||&apos;&quot; sqref=&quot;A&apos;||(documents(doc_id).sheets(i).freeze_panes_horizontal+1)||&apos;&quot;/&gt;&apos;;
                ELSIF documents(doc_id).sheets(i).freeze_panes_horizontal IS NULL AND documents(doc_id).sheets(i).freeze_panes_vertical IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;pane xSplit=&quot;&apos;||documents(doc_id).sheets(i).freeze_panes_vertical||&apos;&quot; topLeftCell=&quot;&apos;||column_numeric2alpha((documents(doc_id).sheets(i).freeze_panes_vertical+1))||&apos;1&quot; activePane=&quot;topRight&quot; state=&quot;frozenSplit&quot;/&gt;&apos;;
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection pane=&quot;topRight&quot;/&gt;&apos;;
                ELSIF documents(doc_id).sheets(i).freeze_panes_horizontal IS NOT NULL AND documents(doc_id).sheets(i).freeze_panes_vertical IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;pane xSplit=&quot;&apos;||documents(doc_id).sheets(i).freeze_panes_vertical||&apos;&quot; ySplit=&quot;&apos;||documents(doc_id).sheets(i).freeze_panes_horizontal||&apos;&quot; topLeftCell=&quot;&apos;||column_numeric2alpha((documents(doc_id).sheets(i).freeze_panes_vertical+1))||(documents(doc_id).sheets(i).freeze_panes_vertical+1)||&apos;&quot; activePane=&quot;bottomRight&quot; state=&quot;frozenSplit&quot;/&gt;&apos;;
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection pane=&quot;bottomLeft&quot; activeCell=&quot;A&apos;||(documents(doc_id).sheets(i).freeze_panes_vertical)||&apos;&quot; sqref=&quot;A&apos;||(documents(doc_id).sheets(i).freeze_panes_vertical)||&apos;&quot;/&gt;&apos;;
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection pane=&quot;topRight&quot; activeCell=&quot;B&apos;||(documents(doc_id).sheets(i).freeze_panes_horizontal)||&apos;&quot; sqref=&quot;B&apos;||(documents(doc_id).sheets(i).freeze_panes_horizontal)||&apos;&quot;/&gt;&apos;;
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection pane=&quot;bottomRight&quot;/&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;selection/&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/sheetView&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/sheetViews&gt;&apos;;
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;sheetFormatPr defaultRowHeight=&quot;15&quot;/&gt;&apos;;

                IF top_right_column &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;cols&gt;&apos;;
                END IF;

                IF documents(doc_id).sheets(i).column_properites.LAST IS NOT NULL THEN
                    FOR col IN documents(doc_id).sheets(i).column_properites.FIRST .. documents(doc_id).sheets(i).column_properites.LAST LOOP
                        line_string(doc_id) := line_string(doc_id) || &apos;&lt;col min=&quot;&apos;||column_alpha2numeric(documents(doc_id).sheets(i).column_properites(col).column_name)||&apos;&quot; max=&quot;&apos;||column_alpha2numeric(documents(doc_id).sheets(i).column_properites(col).column_name)||&apos;&quot; width=&quot;&apos;||REPLACE(TO_CHAR(documents(doc_id).sheets(i).column_properites(col).width),&apos;,&apos;, &apos;.&apos;)||&apos;&quot; hidden=&quot;&apos;||NVL(documents(doc_id).sheets(i).column_properites(col).hidden, 0)||&apos;&quot; bestFit=&quot;1&quot; customWidth=&quot;1&quot;/&gt;&apos;;
                    END LOOP;
                ELSIF top_right_column &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;col min=&quot;&apos;||top_right_column||&apos;&quot; max=&quot;&apos;||top_right_column||&apos;&quot; width=&quot;10.140625&quot; bestFit=&quot;1&quot; customWidth=&quot;1&quot;/&gt;&apos;;
                END IF;

                IF top_right_column &gt; 0 THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;/cols&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;sheetData&gt;&apos;;
                dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));

                line_string(doc_id) := NULL;

                -- Append data from buffer
                IF sheet_data_buffer(doc_id) IS NOT NULL THEN
                    dbms_lob.writeappend(documents(doc_id).sheets(i).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
                    sheet_data_buffer(doc_id) := NULL;
                END IF;

                IF INSTR(documents(doc_id).sheets(i).sheet_data, &apos;spans=&quot;1:1&quot;&apos;) &gt; 0 THEN
                    documents(doc_id).sheets(i).sheet_data := REPLACE(documents(doc_id).sheets(i).sheet_data, &apos;spans=&quot;1:1&quot;&apos;, &apos;spans=&quot;1:&apos;||REPLACE(documents(doc_id).sheets(i).top_right_column, &apos;0&apos;, &apos;1&apos;)||&apos;&quot;&apos;);
                END IF;

                IF documents(doc_id).sheets(i).sheet_data_buffer.LAST IS NOT NULL THEN

                    FOR buffer_id IN documents(doc_id).sheets(i).sheet_data_buffer.FIRST .. documents(doc_id).sheets(i).sheet_data_buffer.LAST LOOP

                       -- Append rows
                        DBMS_LOB.append(file_content2, documents(doc_id).sheets(i).sheet_data_buffer(buffer_id));

                        dbms_lob.freetemporary(documents(doc_id).sheets(i).sheet_data_buffer(buffer_id));

                    END LOOP;

                END IF;

                documents(doc_id).sheets(i).sheet_data_buffer.DELETE;

                -- Write content from buffer if buffer is not empty
                IF DBMS_LOB.getlength(documents(doc_id).sheets(i).sheet_data) &gt; 0 THEN
                    DBMS_LOB.append(file_content2, documents(doc_id).sheets(i).sheet_data);
                END IF;

                documents(doc_id).sheets(i).sheet_data := initialize_clob;

                line_string(doc_id) :=  &apos;&lt;/sheetData&gt;&apos;;

                -- Append merged cells information tags
                IF documents(doc_id).sheets(i).merged_cells.LAST IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id)|| &apos;&lt;mergeCells count=&quot;&apos;||documents(doc_id).sheets(i).merged_cells.LAST||&apos;&quot;&gt;&apos;;
                    FOR merged_id IN documents(doc_id).sheets(i).merged_cells.FIRST .. documents(doc_id).sheets(i).merged_cells.LAST LOOP
                       line_string(doc_id) := line_string(doc_id)|| &apos;&lt;mergeCell ref=&quot;&apos;||documents(doc_id).sheets(i).merged_cells(merged_id).merged_cells||&apos;&quot;/&gt;&apos;;
                       IF  LENGTH(line_string(doc_id)) &gt; 3500 THEN
                            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                            line_string(doc_id) := NULL;
                       END IF;
                    END LOOP;
                    line_string(doc_id) := line_string(doc_id)|| &apos;&lt;/mergeCells&gt;&apos;;
                END IF;

                -- Set Auto Filter
                IF documents(doc_id).sheets(i).filter_from IS NOT NULL AND documents(doc_id).sheets(i).filter_to IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id)||&apos;&lt;autoFilter ref=&quot;&apos;||documents(doc_id).sheets(i).filter_from||&apos;:&apos;||documents(doc_id).sheets(i).filter_to||&apos;&quot;&gt;&lt;/autoFilter&gt;&apos;;
                END IF;

                -- Add hyperlinks
                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL OR
                   documents(doc_id).sheets(i).internal_hyperlinks.LAST IS NOT NULL
                THEN
                    line_string(doc_id) := line_string(doc_id)||&apos;&lt;hyperlinks&gt;&apos;;
                END IF;


                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL THEN

                    FOR h IN documents(doc_id).sheets(i).hyperlinks.FIRST .. documents(doc_id).sheets(i).hyperlinks.LAST LOOP

                        -- Empty buffer if it is almost full
                        IF  LENGTH(line_string(doc_id)) &gt; 3000 THEN
                            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                            line_string(doc_id) := NULL;
                        END IF;

                       line_string(doc_id) := line_string(doc_id)||&apos;&lt;hyperlink ref=&quot;&apos;||documents(doc_id).sheets(i).hyperlinks(h).cell||&apos;&quot; r:id=&quot;rId&apos;||h||&apos;&quot;/&gt;&apos;;

                    END LOOP;

                END IF;

                IF documents(doc_id).sheets(i).internal_hyperlinks.LAST IS NOT NULL THEN

                    FOR h IN documents(doc_id).sheets(i).internal_hyperlinks.FIRST .. documents(doc_id).sheets(i).internal_hyperlinks.LAST LOOP

                        -- Empty buffer if it is almost full
                        IF  LENGTH(line_string(doc_id)) &gt; 3000 THEN
                            dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                            line_string(doc_id) := NULL;
                        END IF;

                       line_string(doc_id) := line_string(doc_id)||&apos;&lt;hyperlink ref=&quot;&apos;||documents(doc_id).sheets(i).internal_hyperlinks(h).cell||&apos;&quot; location=&quot;&apos;||documents(doc_id).sheets(i).internal_hyperlinks(h).hyperlink||&apos;&quot; display=&quot;&quot;/&gt;&apos;;

                    END LOOP;

                END IF;

                IF documents(doc_id).sheets(i).hyperlinks.LAST IS NOT NULL OR
                   documents(doc_id).sheets(i).internal_hyperlinks.LAST IS NOT NULL
                THEN
                    line_string(doc_id) := line_string(doc_id)||&apos;&lt;/hyperlinks&gt;&apos;;
                END IF;



                -- Set page margins parameters
                line_string(doc_id) := line_string(doc_id) || &apos;&lt;pageMargins left=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_left), &apos;,&apos;, &apos;.&apos;), &apos;0.7&apos;)||
                                                              &apos;&quot; right=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_right), &apos;,&apos;, &apos;.&apos;), &apos;0.7&apos;)||
                                                              &apos;&quot; top=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_top), &apos;,&apos;, &apos;.&apos;), &apos;0.75&apos;)||
                                                              &apos;&quot; bottom=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_bottom), &apos;,&apos;, &apos;.&apos;), &apos;0.75&apos;)||
                                                              &apos;&quot; header=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_header), &apos;,&apos;, &apos;.&apos;), &apos;0.3&apos;)||
                                                              &apos;&quot; footer=&quot;&apos;||NVL(REPLACE(TO_CHAR(documents(doc_id).sheets(i).margins_footer), &apos;,&apos;, &apos;.&apos;), &apos;0.3&apos;)||&apos;&quot;/&gt;&apos;;


                line_string(doc_id) := line_string(doc_id) || &apos;&lt;pageSetup paperSize=&quot;&apos;||NVL(documents(doc_id).sheets(i).paper_size, 9)||&apos;&quot;&apos;;
                IF documents(doc_id).sheets(i).orientation = &apos;landscape&apos; THEN
                    line_string(doc_id) := line_string(doc_id) || &apos; orientation=&quot;landscape&quot;&apos;;
                END IF;
                line_string(doc_id) := line_string(doc_id) || &apos;/&gt;&apos;;


                -- Empty buffer if it is almost full
                IF  LENGTH(line_string(doc_id)) &gt; 3000 THEN
                    dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                    line_string(doc_id) := NULL;
                END IF;

                IF documents(doc_id).sheets(i).header_text IS NOT NULL OR documents(doc_id).sheets(i).footer_text IS NOT NULL THEN

                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;headerFooter&gt;&apos;;

                    IF documents(doc_id).sheets(i).header_text IS NOT NULL THEN
                        line_string(doc_id) := line_string(doc_id) || &apos;&lt;oddHeader&gt;&apos;||CHR(38)||&apos;amp;C&apos;||dbms_xmlgen.convert(documents(doc_id).sheets(i).header_text)||&apos;&lt;/oddHeader&gt;&apos;;
                    END IF;

                    -- Empty buffer if it is almost full
                    IF  LENGTH(line_string(doc_id)) &gt; 3000 THEN
                        dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                        line_string(doc_id) := NULL;
                    END IF;

                    IF documents(doc_id).sheets(i).footer_text IS NOT NULL THEN
                        line_string(doc_id) := line_string(doc_id) || &apos;&lt;oddFooter&gt;&apos;||CHR(38)||&apos;amp;C&apos;||dbms_xmlgen.convert(documents(doc_id).sheets(i).footer_text)||&apos;&lt;/oddFooter&gt;&apos;;
                    END IF;

                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;/headerFooter&gt;&apos;;

                END IF;

                -- Comments drawing
                IF documents(doc_id).sheets(i).comments.LAST IS NOT NULL THEN
                    line_string(doc_id) := line_string(doc_id) || &apos;&lt;legacyDrawing r:id=&quot;rId1&quot;/&gt;&apos;;
                END IF;

                line_string(doc_id) := line_string(doc_id) || &apos;&lt;/worksheet&gt;&apos;;
                dbms_lob.writeappend(file_content2, LENGTH(line_string(doc_id)), line_string(doc_id));
                line_string(doc_id) := NULL;

                add_xml(blob_file, &apos;xl/worksheets/sheet&apos;||i||&apos;.xml&apos;, file_content2);

                print_clob(file_content2, &apos;xl/worksheets/sheet&apos;||i||&apos;.xml&apos;);

                dbms_lob.close(file_content2);

            END LOOP;

            dbms_lob.freetemporary(file_content2);

        END IF;



        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 11/12&apos;);
        -- docProps/core.xml
        file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10);
        file_content := file_content || &apos;&lt;cp:coreProperties xmlns:cp=&quot;http://schemas.openxmlformats.org/package/2006/metadata/core-properties&quot; xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:dcterms=&quot;http://purl.org/dc/terms/&quot; xmlns:dcmitype=&quot;http://purl.org/dc/dcmitype/&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;&apos;;
        file_content := file_content || &apos;&lt;dc:creator&gt;&apos;||dbms_xmlgen.convert(NVL(documents(doc_id).author, &apos;www.oraexcel.com&apos;))||&apos;&lt;/dc:creator&gt;&apos;;
        file_content := file_content || &apos;&lt;cp:lastModifiedBy&gt;&apos;||dbms_xmlgen.convert(NVL(documents(doc_id).author, &apos;www.oraexcel.com&apos;))||&apos;&lt;/cp:lastModifiedBy&gt;&apos;;
        file_content := file_content || &apos;&lt;dcterms:created xsi:type=&quot;dcterms:W3CDTF&quot;&gt;&apos; || TO_CHAR( CURRENT_TIMESTAMP, &apos;yyyy-mm-dd&quot;T&quot;hh24:mi:ssTZH:TZM&apos; ) || &apos;&lt;/dcterms:created&gt;&apos;;
        file_content := file_content || &apos;&lt;dcterms:modified xsi:type=&quot;dcterms:W3CDTF&quot;&gt;&apos; || TO_CHAR( CURRENT_TIMESTAMP, &apos;yyyy-mm-dd&quot;T&quot;hh24:mi:ssTZH:TZM&apos; ) || &apos;&lt;/dcterms:modified&gt;&apos;;
        file_content := file_content || &apos;&lt;/cp:coreProperties&gt;&apos;;
        add_xml(blob_file, &apos;docProps/core.xml&apos;, file_content);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;docProps/core.xml&apos;);



       DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Formatting ... Step 12/12&apos;);
        -- docProps/app.xml
        file_content := &apos;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&apos;||CHR(10);
        file_content := file_content || &apos;&lt;Properties xmlns=&quot;http://schemas.openxmlformats.org/officeDocument/2006/extended-properties&quot; xmlns:vt=&quot;http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes&quot;&gt;&apos;;
        file_content := file_content || &apos;&lt;Application&gt;Microsoft Excel&lt;/Application&gt;&apos;;
        file_content := file_content || &apos;&lt;DocSecurity&gt;0&lt;/DocSecurity&gt;&apos;;
        file_content := file_content || &apos;&lt;ScaleCrop&gt;false&lt;/ScaleCrop&gt;&apos;;
        file_content := file_content || &apos;&lt;HeadingPairs&gt;&apos;;
        file_content := file_content || &apos;&lt;vt:vector size=&quot;2&quot; baseType=&quot;variant&quot;&gt;&apos;;
        file_content := file_content || &apos;&lt;vt:variant&gt;&lt;vt:lpstr&gt;Worksheets&lt;/vt:lpstr&gt;&lt;/vt:variant&gt;&apos;;
        file_content := file_content || &apos;&lt;vt:variant&gt;&lt;vt:i4&gt;&apos;||last_sheet||&apos;&lt;/vt:i4&gt;&lt;/vt:variant&gt;&apos;;
        file_content := file_content || &apos;&lt;/vt:vector&gt;&apos;;
        file_content := file_content || &apos;&lt;/HeadingPairs&gt;&apos;;
        file_content := file_content || &apos;&lt;TitlesOfParts&gt;&apos;;
        file_content := file_content || &apos;&lt;vt:vector size=&quot;&apos;||last_sheet||&apos;&quot; baseType=&quot;lpstr&quot;&gt;&apos;;
        IF last_sheet IS NOT NULL THEN
            FOR i IN first_sheet .. last_sheet LOOP
                file_content := file_content || &apos;&lt;vt:lpstr&gt;&apos;||dbms_xmlgen.convert(documents(doc_id).sheets(i).sheet_name)||&apos;&lt;/vt:lpstr&gt;&apos;;
            END LOOP;
        END IF;
        file_content := file_content || &apos;&lt;/vt:vector&gt;&apos;;
        file_content := file_content || &apos;&lt;/TitlesOfParts&gt;&apos;;
        file_content := file_content || &apos;&lt;LinksUpToDate&gt;false&lt;/LinksUpToDate&gt;&apos;;
        file_content := file_content || &apos;&lt;SharedDoc&gt;false&lt;/SharedDoc&gt;&apos;;
        file_content := file_content || &apos;&lt;HyperlinksChanged&gt;false&lt;/HyperlinksChanged&gt;&apos;;
        file_content := file_content || &apos;&lt;AppVersion&gt;12.0000&lt;/AppVersion&gt;&apos;;
        file_content := file_content || &apos;&lt;/Properties&gt;&apos;;
        add_xml(blob_file, &apos;docProps/app.xml&apos;, file_content);
        ------------------------------------------------------------------------
        print_clob(file_content, &apos;docProps/app.xml&apos;);


        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Finishing ...&apos;);

        compress_document( blob_file );

        -- Release sheet memory
        documents(doc_id).sheets.DELETE;

        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Done!&apos;);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure save_to_blob&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ------------------------------------------------------------------------

    PROCEDURE set_cell_font (cell_name VARCHAR2,
                             font_name VARCHAR2,
                             font_size PLS_INTEGER,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                             row_id PLS_INTEGER DEFAULT current_row_id)
    IS
        font fonts_type;
    BEGIN

        current_cell_number := column_alpha2numeric(cell_name);
        font.font_name := font_name;
        font.font_size := font_size;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(cell_name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).format_font_id := add_font(font, NULL, doc_id);
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_font&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_default_font (font_name VARCHAR2 DEFAULT &apos;Calibri&apos;,
                                font_size PLS_INTEGER DEFAULT 11,
                                doc_id PLS_INTEGER DEFAULT current_doc_id)
    IS
        default_font default_font_type;
    BEGIN
        default_font.font_name := font_name;
        default_font.font_size := font_size;
        documents(doc_id).default_font := default_font;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_default_font&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_bold(name VARCHAR2,
                            doc_id PLS_INTEGER DEFAULT current_doc_id,
                            sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                            row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).bold := TRUE;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_bold&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_italic(name VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).italic := TRUE;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_italic&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_underline(name VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).underline := TRUE;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_underline&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_color (name VARCHAR2,
                              color VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_color&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_bg_color (name VARCHAR2,
                                 color VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).bg_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_bg_color&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_align_left (name VARCHAR2,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).horizontal_align := &apos;L&apos;;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_align_left&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_align_center (name VARCHAR2,
                                     doc_id PLS_INTEGER DEFAULT current_doc_id,
                                     sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                     row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).horizontal_align := &apos;C&apos;;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_align_center&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_align_right (name VARCHAR2,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                    row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).horizontal_align := &apos;R&apos;;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_align_right&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_vert_align_top (name VARCHAR2,
                                       doc_id PLS_INTEGER DEFAULT current_doc_id,
                                       sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                       row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).vertical_align := &apos;T&apos;;
        cell_formatted := TRUE;


    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_vert_align_top&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_vert_align_middle (name VARCHAR2,
                                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                          row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).vertical_align := &apos;M&apos;;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_vert_align_middle&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_vert_align_bottom (name VARCHAR2,
                                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                          row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).vertical_align := &apos;B&apos;;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_vert_align_bottom&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_wrap_text (name VARCHAR2,
                                  doc_id PLS_INTEGER DEFAULT current_doc_id,
                                  sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                  row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).wrap_text := TRUE;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_wrap_text&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_border_top (name VARCHAR2,
                                   style VARCHAR2 DEFAULT &apos;thin&apos;,
                                   color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name :=  UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_border_top&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_border_bottom (name VARCHAR2,
                                      style VARCHAR2 DEFAULT &apos;thin&apos;,
                                      color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                      row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_border_bottom&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_border_left (name VARCHAR2,
                                    style VARCHAR2 DEFAULT &apos;thin&apos;,
                                    color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                    row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_border_left&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_border_right (name VARCHAR2,
                                     style VARCHAR2 DEFAULT &apos;thin&apos;,
                                     color VARCHAR2 DEFAULT &apos;00000000&apos;,
                                     doc_id PLS_INTEGER DEFAULT current_doc_id,
                                     sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                     row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_border_right&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_border (name VARCHAR2,
                               style VARCHAR2 DEFAULT &apos;thin&apos;,
                               color VARCHAR2 DEFAULT &apos;00000000&apos;,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                               row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;

        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_top_color := color;

        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_bottom_color := color;

        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_left_color := color;

        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right_style := style;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).border_right_color := color;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_border&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------


    PROCEDURE query_to_sheet(query CLOB,
                             show_column_names BOOLEAN DEFAULT TRUE,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
        curid    NUMBER;
        desctab  DBMS_SQL.DESC_TAB;
        colcnt   NUMBER;
        namevar  VARCHAR2(4000);
        numvar   NUMBER;
        datevar  DATE;
        ret NUMBER;
        tmp_query CLOB;
    BEGIN

        tmp_query := query;

        -- Open cursor
        curid := DBMS_SQL.open_cursor;

        -- Parse query
        DBMS_SQL.parse(curid, tmp_query, DBMS_SQL.native );

        -- Get column names and types
        DBMS_SQL.DESCRIBE_COLUMNS(curid, colcnt, desctab);

        -- Add row for column names
        IF show_column_names = TRUE THEN
            add_row(doc_id, sheet_id);
        END IF;

        -- Get column names and prepare column types
        FOR i IN 1 .. colcnt LOOP

            IF desctab(i).col_type IN ( 2, 100, 101 ) THEN

                DBMS_SQL.DEFINE_COLUMN(curid, i, numvar);
                IF show_column_names = TRUE THEN
                   set_cell_value(column_numeric2alpha(i), desctab(i).col_name, doc_id, sheet_id);
                END IF;

            ELSIF desctab(i).col_type IN ( 12, 178, 179, 180, 181 , 231 ) THEN

               DBMS_SQL.DEFINE_COLUMN(curid, i, datevar);
                IF show_column_names = TRUE THEN
                   set_cell_value(column_numeric2alpha(i), desctab(i).col_name, doc_id, sheet_id);
                END IF;

            ELSE -- in ( 1, 8, 9, 96, 112 )

                DBMS_SQL.DEFINE_COLUMN(curid, i, namevar, 4000);
                IF show_column_names = TRUE THEN
                   set_cell_value(column_numeric2alpha(i), desctab(i).col_name, doc_id, sheet_id);
                END IF;

            END IF;

        END LOOP;

        ret := DBMS_SQL.EXECUTE(curid);

        -- Fetch rows with DBMS_SQL package
        WHILE DBMS_SQL.FETCH_ROWS(curid) &gt; 0 LOOP


            -- Add row for every fetched row
            add_row(doc_id, sheet_id);

            FOR i IN 1 .. colcnt LOOP

                IF (desctab(i).col_type IN(1, 96, 9)) THEN
                    -- Get STRING column valus and add it to spreadsheet
                    DBMS_SQL.COLUMN_VALUE(curid, i, namevar);
                    set_cell_value(column_numeric2alpha(i), namevar, doc_id, sheet_id);

                ELSIF (desctab(i).col_type = 2) THEN

                    -- Get NUMERIC column valus and add it to spreadsheet
                    DBMS_SQL.COLUMN_VALUE(curid, i, numvar);
                    set_cell_value(column_numeric2alpha(i), numvar, doc_id, sheet_id);

                ELSIF (desctab(i).col_type = 12) THEN

                    -- Get DATE column valus and add it to spreadsheet
                    DBMS_SQL.COLUMN_VALUE(curid, i, datevar);
                    set_cell_value(column_numeric2alpha(i), datevar, doc_id, sheet_id);

                END IF;

            END LOOP;

        END LOOP;

        -- Close cursor
        DBMS_SQL.CLOSE_CURSOR(curid);

    EXCEPTION
        WHEN others THEN
            DBMS_SQL.CLOSE_CURSOR(curid);
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure query_to_sheet&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ---------------------------------------------------------------------------

    PROCEDURE save_to_file(directory_name VARCHAR2, file_name VARCHAR2, doc_id PLS_INTEGER DEFAULT current_doc_id) IS
        blob_file BLOB;
    BEGIN

        save_to_blob(blob_file, doc_id);

        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Writting to file ...&apos;);

        blob2file(blob_file, directory_name, file_name );

        DBMS_APPLICATION_INFO.set_client_info(&apos;ORA_EXCEL Done!&apos;);

    EXCEPTION
        WHEN UTL_FILE.FILE_OPEN THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;File &apos;||file_name||&apos; is open, please close it first&apos;||SQLCODE||&apos; &apos;||SQLERRM||CHR(10));
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure save_to_file&apos;||SQLCODE||&apos; &apos;||SQLERRM||CHR(10));
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_row_height(height NUMBER, doc_id PLS_INTEGER DEFAULT current_doc_id, sheet_id PLS_INTEGER DEFAULT current_sheet_id, row_id PLS_INTEGER DEFAULT current_row_id) IS
    BEGIN

        documents(doc_id).sheets(sheet_id).row_height := height;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_row_height&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

     PROCEDURE add_merged_cell(merged_cells VARCHAR2, doc_id PLS_INTEGER DEFAULT current_doc_id, sheet_id PLS_INTEGER DEFAULT current_sheet_id) IS
        column_id PLS_INTEGER;
    BEGIN

        IF documents(doc_id).sheets(sheet_id).merged_cells.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets(sheet_id).merged_cells.FIRST .. documents(doc_id).sheets(sheet_id).merged_cells.LAST LOOP

                IF documents(doc_id).sheets(sheet_id).merged_cells(i).merged_cells = UPPER(merged_cells) THEN
                    column_id := i;
                    EXIT;
                END IF;

            END LOOP;

        END IF;

        IF column_id IS NULL THEN
            documents(doc_id).sheets(sheet_id).merged_cells.EXTEND;
            column_id := documents(doc_id).sheets(sheet_id).merged_cells.LAST;
        END IF;

        documents(doc_id).sheets(sheet_id).merged_cells(column_id).merged_cells := UPPER(merged_cells);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_merged_cell&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE merge_cells (cell_from VARCHAR2,
                           cell_to VARCHAR2,
                           doc_id PLS_INTEGER DEFAULT current_doc_id,
                           sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                           row_id PLS_INTEGER DEFAULT current_row_id)
    IS
        cells_to_add VARCHAR2(4000);
    BEGIN

        -- Push data from buffer if buffer is almost full
        IF LENGTH(sheet_data_buffer(doc_id)) &gt; 32750 THEN

            dbms_lob.writeappend(documents(doc_id).sheets(sheet_id).sheet_data, LENGTH(sheet_data_buffer(doc_id)), sheet_data_buffer(doc_id));
            sheet_data_buffer(doc_id) := NULL;
        END IF;

        --Prepare cells to add
        cells_to_add := NULL;
        FOR i IN (column_alpha2numeric(cell_from) + 1) .. column_alpha2numeric(cell_to) LOOP
           cells_to_add := cells_to_add || &apos;&lt;c r=&quot;&apos;||column_numeric2alpha(i)||row_id||&apos;&quot; s=&quot;\2&quot;/&gt;&apos;;
           documents(doc_id).sheets(sheet_id).top_right_column := documents(doc_id).sheets(sheet_id).top_right_column + 1;
        END LOOP;

        add_merged_cell(cell_from||row_id||&apos;:&apos;||cell_to||row_id, doc_id, sheet_id);

        current_cell_number := column_alpha2numeric(cell_from);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(cell_from)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).merge_cells := TRUE;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).merged_cells_cell_from := cell_from;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).merges_cells_cell_to := cell_to;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cells_to_add := cells_to_add;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure merge_cells&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE merge_rows (cell_from VARCHAR2,
                          cell_to PLS_INTEGER,
                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                          row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        add_merged_cell(cell_from||row_id||&apos;:&apos;||cell_from||(row_id + cell_to), doc_id, sheet_id);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure merge_rows&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_formula(name VARCHAR2,
                              formula VARCHAR2,
                              doc_id PLS_INTEGER DEFAULT current_doc_id,
                              sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                              row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).formula := dbms_xmlgen.convert(REGEXP_REPLACE(formula,&apos;[[:cntrl:]]&apos;,&apos;&apos;));

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure merge_rows&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_rotate_text (name VARCHAR2,
                                    degrees INTEGER,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                    row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).rotate_text_degree := degrees;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_align_center&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE download_file(file_name VARCHAR2,
                            doc_id PLS_INTEGER DEFAULT current_doc_id)
    IS
        blob_file BLOB;
        blob_size INTEGER;
    BEGIN

        save_to_blob(blob_file, doc_id);

        -- Get BLOB size
        blob_size := dbms_lob.getlength(blob_file);

        -- Print content type header for MS Excel
        owa_util.mime_header(&apos;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&apos;, FALSE, NULL);

        -- Put BLOB size header
        htp.p(&apos;Content-length: &apos;|| blob_size);

        -- Set file name that will be suggested when download dialog appears
        htp.p(&apos;Content-Disposition: attachment; filename=&quot;&apos;||file_name||&apos;&quot;&apos;);

        -- Close header
        owa_util.http_header_close;

        -- Download BLOB
        wpg_docload.download_file(blob_file);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure download_file&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------
-- New
    PROCEDURE set_sheet_margins(left_margin NUMBER,
                                right_margin NUMBER,
                                top_margin NUMBER,
                                bottom_margin NUMBER,
                                header_margin NUMBER,
                                footer_margin NUMBER,
                                sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

        documents(doc_id).sheets(sheet_id).margins_left :=  left_margin / 2.54;
        documents(doc_id).sheets(sheet_id).margins_right :=  right_margin / 2.54;
        documents(doc_id).sheets(sheet_id).margins_top :=  top_margin / 2.54;
        documents(doc_id).sheets(sheet_id).margins_bottom :=  bottom_margin / 2.54;
        documents(doc_id).sheets(sheet_id).margins_header :=  header_margin / 2.54;
        documents(doc_id).sheets(sheet_id).margins_footer :=  footer_margin / 2.54;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_margins&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_sheet_landscape(sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

         documents(doc_id).sheets(sheet_id).orientation := &apos;landscape&apos;;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_landscape&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_sheet_paper_size(paper_size INTEGER,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

        IF paper_size BETWEEN 1 AND 41 THEN
            documents(doc_id).sheets(sheet_id).paper_size := paper_size;
        ELSE
             RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_paper_size - supported paper sizes are between 1 and 41&apos;);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_paper_size&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_sheet_header_text(header_text VARCHAR2,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

        documents(doc_id).sheets(sheet_id).header_text := SUBSTR(header_text, 1, 1000);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_header_text&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_sheet_footer_text(footer_text VARCHAR2,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

        documents(doc_id).sheets(sheet_id).footer_text := SUBSTR(footer_text, 1, 1000);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_sheet_footer_text&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_hyperlink(name VARCHAR2,
                                 hyperlink VARCHAR2,
                                 doc_id PLS_INTEGER DEFAULT current_doc_id,
                                 sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                 row_id PLS_INTEGER DEFAULT current_row_id)
    IS
        current_hyperlink_id INTEGER;
    BEGIN

        documents(doc_id).sheets(current_sheet_id).hyperlinks.EXTEND;
        current_hyperlink_id := documents(doc_id).sheets(current_sheet_id).hyperlinks.LAST;

        documents(doc_id).sheets(current_sheet_id).hyperlinks(current_hyperlink_id).cell := name||row_id;
        documents(doc_id).sheets(current_sheet_id).hyperlinks(current_hyperlink_id).hyperlink := hyperlink;
        documents(doc_id).have_hyperlinks := TRUE;

        set_cell_underline(name);
        set_cell_color(name, &apos;0000ff&apos;);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_hyperlink&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_internal_hyperlink(name VARCHAR2,
                                          hyperlink VARCHAR2,
                                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                                          sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                          row_id PLS_INTEGER DEFAULT current_row_id)
    IS
        current_hyperlink_id INTEGER;
    BEGIN

        documents(doc_id).sheets(current_sheet_id).internal_hyperlinks.EXTEND;
        current_hyperlink_id := documents(doc_id).sheets(current_sheet_id).internal_hyperlinks.LAST;

        documents(doc_id).sheets(current_sheet_id).internal_hyperlinks(current_hyperlink_id).cell := name||row_id;
        documents(doc_id).sheets(current_sheet_id).internal_hyperlinks(current_hyperlink_id).hyperlink := hyperlink;
        documents(doc_id).have_internal_hyperlinks := TRUE;

        set_cell_underline(name);
        set_cell_color(name, &apos;0000ff&apos;);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_internal_hyperlink&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_indent_left(name VARCHAR2,
                                   indent INTEGER,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).indent_left := indent;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_indent_left&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_indent_right(name VARCHAR2,
                                   indent INTEGER,
                                   doc_id PLS_INTEGER DEFAULT current_doc_id,
                                   sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                                   row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        current_cell_number := column_alpha2numeric(name);
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).cell_name := UPPER(name)||row_id;
        documents(doc_id).sheets(current_sheet_id).current_cell(current_cell_number).indent_right := indent;
        cell_formatted := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_indent_right&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cell_comment(name VARCHAR2,
                               autohr VARCHAR2,
                               comment_text VARCHAR2,
                               comment_box_width NUMBER,
                               comment_box_height NUMBER,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                               row_id PLS_INTEGER DEFAULT current_row_id)
    IS
        current_comment_id INTEGER;
    BEGIN

        documents(doc_id).sheets(current_sheet_id).comments.EXTEND;
        current_comment_id := documents(doc_id).sheets(current_sheet_id).comments.LAST;

        documents(doc_id).sheets(sheet_id).comments(current_comment_id).cell := name||row_id;
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).author := SUBSTR(autohr, 1, 30);
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).comment_text := SUBSTR(comment_text, 1, 1000);
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).box_width := comment_box_width;
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).box_height := comment_box_height;
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).row_id := row_id - 1;
        documents(doc_id).sheets(sheet_id).comments(current_comment_id).column_id := column_alpha2numeric(name) - 1;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_comment&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ---------------------------------------------------------------------------

    PROCEDURE hide_column(name VARCHAR2,
                          doc_id PLS_INTEGER DEFAULT current_doc_id,
                          sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
        column_id INTEGER;
    BEGIN

       IF documents(doc_id).sheets(sheet_id).column_properites.LAST IS NOT NULL THEN

            FOR i IN documents(doc_id).sheets(sheet_id).column_properites.FIRST .. documents(doc_id).sheets(sheet_id).column_properites.LAST LOOP
                IF documents(doc_id).sheets(sheet_id).column_properites(i).column_name = UPPER(name) THEN
                    column_id := i;
                    EXIT;
                END IF;
            END LOOP;

        END IF;

        IF column_id IS NULL THEN
            documents(doc_id).sheets(sheet_id).column_properites.EXTEND;
            column_id := documents(doc_id).sheets(sheet_id).column_properites.LAST;
        END IF;

        documents(doc_id).sheets(sheet_id).column_properites(column_id).column_name := UPPER(name);
        documents(doc_id).sheets(sheet_id).column_properites(column_id).hidden := 1;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure hide_column&apos;||SQLCODE||&apos; &apos;||SQLERRM);

    END;
    ---------------------------------------------------------------------------

    PROCEDURE hide_row(doc_id PLS_INTEGER DEFAULT current_doc_id,
                       sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                       row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        documents(doc_id).sheets(sheet_id).hide_row := TRUE;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure hide_row&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE set_cells_filter(cell_from VARCHAR2,
                               cell_to VARCHAR2,
                               doc_id PLS_INTEGER DEFAULT current_doc_id,
                               sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN

        documents(doc_id).sheets(sheet_id).filter_from := cell_from;
        documents(doc_id).sheets(sheet_id).filter_to := cell_to;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_filter&apos;||SQLCODE||&apos; &apos;||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION raw2num(value IN RAW) RETURN NUMBER IS
    BEGIN

           RETURN UTL_RAW.cast_to_binary_integer(value, UTL_RAW.little_endian);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure raw2num: &apos;||SQLCODE||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION blob2num (p_blob BLOB, p_len INTEGER, p_pos INTEGER)
       RETURN NUMBER
    IS
    BEGIN
       RETURN UTL_RAW.cast_to_binary_integer (
                 DBMS_LOB.SUBSTR (p_blob, p_len, p_pos),
                 UTL_RAW.little_endian);
    END;
    ----------------------------------------------------------------------------

    FUNCTION raw2varchar2 (p_raw RAW, p_encoding VARCHAR2)
       RETURN VARCHAR2
    IS
    BEGIN
       RETURN COALESCE (
                 UTL_I18N.raw_to_char (p_raw, p_encoding),
                 UTL_I18N.raw_to_char (
                    p_raw,
                    UTL_I18N.map_charset (p_encoding,
                                          UTL_I18N.GENERIC_CONTEXT,
                                          UTL_I18N.IANA_TO_ORACLE)));
    END;
    ----------------------------------------------------------------------------


    FUNCTION extract_file(p_zipped_blob    BLOB,
                          p_file_name      VARCHAR2,
                          p_encoding       VARCHAR2 := NULL)
       RETURN BLOB
    IS
       t_tmp        BLOB;
       t_ind        INTEGER;
       t_hd_ind     INTEGER;
       t_fl_ind     INTEGER;
       t_encoding   VARCHAR2 (32767);
       t_len        INTEGER;
       c_END_OF_CENTRAL_DIRECTORY constant raw(4) := hextoraw( &apos;504B0506&apos; ); -- End of central directory signature
    BEGIN
       t_ind := DBMS_LOB.getlength (p_zipped_blob) - 21;

       LOOP
          EXIT WHEN t_ind &lt; 1
                    OR DBMS_LOB.SUBSTR (p_zipped_blob, 4, t_ind) =
                         c_END_OF_CENTRAL_DIRECTORY;
          t_ind := t_ind - 1;
       END LOOP;

       --
       IF t_ind &lt;= 0
       THEN
          RETURN NULL;
       END IF;

       --
       t_hd_ind := blob2num (p_zipped_blob, 4, t_ind + 16) + 1;

       FOR i IN 1 .. blob2num (p_zipped_blob, 2, t_ind + 8)
       LOOP
          IF p_encoding IS NULL
          THEN
             IF UTL_RAW.bit_and (
                   DBMS_LOB.SUBSTR (p_zipped_blob, 1, t_hd_ind + 9),
                   HEXTORAW (&apos;08&apos;)) = HEXTORAW (&apos;08&apos;)
             THEN
                t_encoding := &apos;AL32UTF8&apos;;                                  -- utf8
             ELSE
                t_encoding := &apos;US8PC437&apos;;                      -- IBM codepage 437
             END IF;
          ELSE
             t_encoding := p_encoding;
          END IF;

          IF p_file_name =
                raw2varchar2 (
                   DBMS_LOB.SUBSTR (p_zipped_blob,
                                    blob2num (p_zipped_blob, 2, t_hd_ind + 28),
                                    t_hd_ind + 46),
                   t_encoding)
          THEN
             t_len := blob2num (p_zipped_blob, 4, t_hd_ind + 24); -- uncompressed length

             IF t_len = 0
             THEN
                IF SUBSTR (p_file_name, -1) IN (&apos;/&apos;, &apos;\&apos;)
                THEN                                           -- directory/folder
                   RETURN NULL;
                ELSE                                                 -- empty file
                   RETURN EMPTY_BLOB ();
                END IF;
             END IF;

             --
             IF DBMS_LOB.SUBSTR (p_zipped_blob, 2, t_hd_ind + 10) =
                   HEXTORAW (&apos;0800&apos;)                                    -- deflate
             THEN
                t_fl_ind := blob2num (p_zipped_blob, 4, t_hd_ind + 42);
                t_tmp := HEXTORAW (&apos;1F8B0800000000000003&apos;);         -- gzip header
                DBMS_LOB.COPY (
                   t_tmp,
                   p_zipped_blob,
                   blob2num (p_zipped_blob, 4, t_hd_ind + 20),
                   11,
                     t_fl_ind
                   + 31
                   + blob2num (p_zipped_blob, 2, t_fl_ind + 27) -- File name length
                   + blob2num (p_zipped_blob, 2, t_fl_ind + 29) -- Extra field length
                                                               );
                DBMS_LOB.append (
                   t_tmp,
                   UTL_RAW.CONCAT (
                      DBMS_LOB.SUBSTR (p_zipped_blob, 4, t_hd_ind + 16)   -- CRC32
                                                                       ,
                      little_endian (t_len)                 -- uncompressed length
                                           ));
                RETURN UTL_COMPRESS.lz_uncompress (t_tmp);
             END IF;

             --
             IF DBMS_LOB.SUBSTR (p_zipped_blob, 2, t_hd_ind + 10) =
                   HEXTORAW (&apos;0000&apos;)        -- The file is stored (no compression)
             THEN
                t_fl_ind := blob2num (p_zipped_blob, 4, t_hd_ind + 42);
                DBMS_LOB.createtemporary (t_tmp, TRUE);
                DBMS_LOB.COPY (
                   t_tmp,
                   p_zipped_blob,
                   t_len,
                   1,
                     t_fl_ind
                   + 31
                   + blob2num (p_zipped_blob, 2, t_fl_ind + 27) -- File name length
                   + blob2num (p_zipped_blob, 2, t_fl_ind + 29) -- Extra field length
                                                               );
                RETURN t_tmp;
             END IF;
          END IF;

          t_hd_ind :=
               t_hd_ind
             + 46
             + blob2num (p_zipped_blob, 2, t_hd_ind + 28)      -- File name length
             + blob2num (p_zipped_blob, 2, t_hd_ind + 30)    -- Extra field length
             + blob2num (p_zipped_blob, 2, t_hd_ind + 32);  -- File comment length
       END LOOP;

       --
       RETURN NULL;
    END;
    ----------------------------------------------------------------------------

    FUNCTION file_to_blob( directory IN VARCHAR2, file IN VARCHAR2 ) RETURN BLOB
    IS
        file_lob BFILE;
        file_blob BLOB;
    BEGIN

        file_lob := BFILENAME(directory, file);

        DBMS_LOB.open( file_lob, DBMS_LOB.file_readonly );
        DBMS_LOB.createtemporary( file_blob, true );
        DBMS_LOB.loadfromfile(file_blob, file_lob, DBMS_LOB.lobmaxsize);
        DBMS_LOB.close( file_lob );

        RETURN file_blob;

    EXCEPTION
        WHEN others THEN
            IF DBMS_LOB.isopen( file_lob ) = 1 THEN
                DBMS_LOB.close( file_lob );
            END IF;
            IF DBMS_LOB.istemporary( file_blob ) = 1 THEN
                DBMS_LOB.freetemporary( file_blob );
            END IF;
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure file_to_blob:&apos;||SQLCODE||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION blob_to_clob(src_blob IN BLOB) RETURN CLOB IS
        v_clob CLOB;
        v_amount NUMBER DEFAULT 2000;
        v_offset NUMBER DEFAULT 1;
        v_buffer VARCHAR2(32767);
        v_length PLS_INTEGER := DBMS_LOB.getlength(src_blob);
    BEGIN

        DBMS_LOB.createtemporary(v_clob, TRUE);

        DBMS_LOB.open(v_clob, DBMS_LOB.lob_readwrite);

        WHILE NVL(v_offset,1) &lt;= v_length LOOP

            v_buffer := utl_raw.cast_to_varchar2(DBMS_LOB.substr(src_blob, v_amount, v_offset));

            IF length(v_buffer) &gt; 0 THEN
                DBMS_LOB.writeappend(v_clob, length(v_buffer), v_buffer);
            END IF;

            v_offset := v_offset + v_amount;
            EXIT WHEN NVL(v_offset,1) &gt; v_length;

        END LOOP;

        RETURN v_clob;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure blob_to_clob:&apos; ||SQLCODE||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    PROCEDURE open_document(directory_name VARCHAR2, file_name VARCHAR2) IS
        blob_file BLOB := EMPTY_BLOB();
        clob_file CLOB := EMPTY_CLOB();
        i PLS_INTEGER;
        num_fmt_id INTEGER;
        apply_number_format INTEGER;
        format_line VARCHAR2(1000);
        format_code VARCHAR2(1000);
    BEGIN

        -- Release memory for currently opened docuement
        loaded_document := EMPTY_BLOB();
        loaded_shared_strings := EMPTY_CLOB();
        loaded_sheet := EMPTY_CLOB();
        loaded_row_id := NULL;
        loaded_row_string := EMPTY_CLOB();
        loaded_styles := loaded_styles_empty;
        loaded_date_system := NULL;

        -- Get local charset
        local_charset := SUBSTR(sys_context(&apos;USERENV&apos;, &apos;LANGUAGE&apos;), INSTR(sys_context(&apos;USERENV&apos;, &apos;LANGUAGE&apos;), &apos;.&apos;, -1) + 1, LENGTH(sys_context(&apos;USERENV&apos;, &apos;LANGUAGE&apos;)));

        -- Load file to BLOB
        loaded_document := file_to_blob(directory_name, file_name);

        -- Extract shared striings
        blob_file := extract_file(loaded_document, &apos;xl/sharedStrings.xml&apos;);

        -- If sharedStrings.xml exists extract it to CLOB
        IF DBMS_LOB.getlength(blob_file) &gt; 0 THEN
            loaded_shared_strings := blob_to_clob(blob_file);
        ELSE
            loaded_shared_strings := EMPTY_CLOB();
        END IF;

        loaded_sheet := EMPTY_CLOB();



        blob_file := extract_file(loaded_document, &apos;xl/styles.xml&apos;);

        -- If styles.xml exists extract it to CLOB
        IF DBMS_LOB.getlength(blob_file) &gt; 0 THEN

            clob_file := blob_to_clob(blob_file);

            i := 0;
            LOOP
                i := i + 1;
                format_line := REGEXP_SUBSTR(clob_file, &apos;\&lt;xf numFmtId\=\&quot;(.*?)\/\&gt;&apos;, INSTR(clob_file, &apos;&lt;cellXfs&apos;), i);


                num_fmt_id := NVL(TO_NUMBER(REPLACE(REPLACE(REGEXP_SUBSTR(format_line, &apos;numFmtId\=\&quot;([[:digit:]]+)\&quot;&apos;), &apos;numFmtId=&quot;&apos;, &apos;&apos;), &apos;&quot;&apos;, &apos;&apos;)), 0);

                apply_number_format := NVL(TO_NUMBER(REPLACE(REPLACE(REGEXP_SUBSTR(format_line, &apos;applyNumberFormat\=\&quot;([[:digit:]]+)\&quot;&apos;), &apos;applyNumberFormat=&quot;&apos;, &apos;&apos;), &apos;&quot;&apos;, &apos;&apos;)), 0);



                IF NVL(num_fmt_id, 0) IN (14, 15, 16, 17, 18, 19, 20, 21, 22, 45, 46, 47) THEN
                   loaded_styles(i) := &apos;D&apos;; -- Date
                ELSIF NVL(num_fmt_id, 0) IN (0 ,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) THEN----::num_fmt_id::&lt;&quot;@333&quot;&gt;
                    loaded_styles(i) := &apos;N&apos;; -- Number
                ELSE
                    loaded_styles(i) := &apos;S&apos;; -- String
                END IF;


                IF NVL(apply_number_format, 0) = 1 AND NVL(loaded_styles(i), &apos;*&apos;) != &apos;D&apos; THEN
                    loaded_styles(i) := &apos;N&apos;; -- Number
                END IF;


                IF num_fmt_id &gt;= 164 THEN

                   loaded_styles(i) := &apos;N&apos;; -- Number

                   format_line := REGEXP_SUBSTR(clob_file, &apos;\&lt;numFmt[[:space:]]numFmtId\=\&quot;&apos;||TO_CHAR(num_fmt_id)||&apos;&quot;[[:space:]]formatCode\=\&quot;(.*?)\&quot;&apos;, 1, 1);

                   IF format_line IS NOT NULL THEN

                        format_code := REPLACE(REPLACE(REGEXP_SUBSTR(format_line, &apos;formatCode\=\&quot;(.*?)\&quot;&apos;), &apos;formatCode=&quot;&apos;, &apos;&apos;), &apos;&quot;&apos;, &apos;&apos;);

                        -- Custom format containst date codes
                        IF REGEXP_LIKE(format_code, &apos;[d|m|y|h|s]&apos;) = TRUE THEN

                            loaded_styles(i) := &apos;D&apos;; -- Date

                        END IF;

                   END IF;

                END IF;

               -- dbms_output.put_line(&apos;loaded_styles(&apos;||i||&apos;):&apos;||loaded_styles(i));

            EXIT WHEN format_line IS NULL;

            END LOOP;

        ELSE

            loaded_styles := loaded_styles_empty;

        END IF;


        loaded_date_system := &apos;1900&apos;;

        blob_file := extract_file(loaded_document, &apos;xl/workbook.xml&apos;);

        -- If styles.xml exists extract it to CLOB
        IF DBMS_LOB.getlength(blob_file) &gt; 0 THEN

            clob_file := blob_to_clob(blob_file);

            IF INSTR(clob_file, &apos;date1904=&quot;true&quot;&apos;) &gt; 0 OR INSTR(clob_file, &apos;date1904=&quot;1&quot;&apos;) &gt; 0 THEN
                loaded_date_system := &apos;1904&apos;;
            END IF;

        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100,&apos;Procedure open_document: &apos;||SQLCODE||SQLERRM);
    END;
    ----------------------------------------------------------------------------

    FUNCTION get_format_type(format_number INTEGER) RETURN VARCHAR2 IS
    BEGIN

        RETURN loaded_styles(format_number + 1);

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure get_format_type:&apos;||SQLCODE||SQLERRM);
    END;

    PROCEDURE close_document IS
    BEGIN

        -- Release memory for currently opened docuement
        loaded_document := EMPTY_BLOB();
        loaded_shared_strings := EMPTY_CLOB();
        loaded_sheet := EMPTY_CLOB();
        loaded_row_id := NULL;
        loaded_row_string := EMPTY_CLOB();
        loaded_styles := loaded_styles_empty;
        loaded_date_system := NULL;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure close_document: &apos;||SQLCODE||SQLERRM);
    END;

    ----------------------------------------------------------------------------
    PROCEDURE open_sheet(sheet_id PLS_INTEGER) IS
        blob_file BLOB := EMPTY_BLOB();
    BEGIN

        loaded_row_string := EMPTY_CLOB();

        IF NVL(DBMS_LOB.getlength(loaded_document), 0) = 0 THEN
            --
            RAISE_APPLICATION_ERROR(-20100, &apos;Document not opened, please open document using open_document procedure first&apos;);
        END IF;

        blob_file := extract_file(loaded_document, &apos;xl/worksheets/sheet&apos;||sheet_id||&apos;.xml&apos;);

        IF DBMS_LOB.getlength(blob_file) &gt; 0 THEN
            loaded_sheet := blob_to_clob(blob_file);
        ELSE
            RAISE_APPLICATION_ERROR(-20100, &apos;Sheet with id &apos;||sheet_id||&apos; does not exists&apos;);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure open_sheet integer: &apos;||SQLCODE||SQLERRM);
    END;
    ----------------------------------------------------------------------------


    PROCEDURE open_sheet(sheet_name VARCHAR2) IS
        blob_file BLOB := EMPTY_BLOB();
        clob_file CLOB := EMPTY_CLOB();
        sheet_id INTEGER;
    BEGIN


        IF NVL(DBMS_LOB.getlength(loaded_document), 0) &gt; 0 THEN
            blob_file := extract_file(loaded_document, &apos;xl/workbook.xml&apos;);
        ELSE
            --Document not opened, please open document using open_document procedure first
            RAISE_APPLICATION_ERROR(-20100, &apos;Document not opened, please open document using open_document procedure first&apos;);
        END IF;

        clob_file := blob_to_clob(blob_file);

        sheet_id := TO_NUMBER(
                        REGEXP_SUBSTR(
                            REGEXP_SUBSTR(
                                REGEXP_SUBSTR(clob_file,
                                              &apos;sheet[[:space:]]name\=\&quot;&apos;||LOWER(sheet_name)||&apos;\&quot;[[:space:]]sheetId\=\&quot;(.*?)\&quot;&apos;, 1, 1, &apos;i&apos;
                                              ),
                                &apos;sheetId\=\&quot;(.*?)\&quot;&apos;
                            ),
                            &apos;([[:digit:]]+)&apos;
                        )
                    );

        IF sheet_id IS NOT NULL THEN
            open_sheet(sheet_id);
        ELSE
            RAISE_APPLICATION_ERROR(-20100, &apos;Sheet &apos;||sheet_name||&apos; does not exists&apos;);
        END IF;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure open_sheet varchar2&apos;||SQLCODE||SQLERRM);
    END;




    FUNCTION get_cell_value(cell_name VARCHAR2) RETURN cell_value_type IS
        row_id INTEGER;
        cell_value_string VARCHAR2(100);
        cell_value cell_value_type;
        format_id INTEGER;
        number_value NUMBER;

        PROCEDURE set_number_value IS
        BEGIN
--            dbms_output.put_line(&apos;set_number_value&apos;);
            cell_value.number_value := TO_NUMBER(cell_value_string,  TRANSLATE(cell_value_string, &apos;012345678&apos;, &apos;999999999&apos;), &apos;nls_numeric_characters=&apos;&apos;.,&apos;&apos;&apos;);
            cell_value.date_value := NULL;
            cell_value.varchar2_value := TO_CHAR(cell_value.number_value);
            cell_value.value := cell_value.varchar2_value;
            cell_value.type := &apos;N&apos;;
        END;

        PROCEDURE set_varchar2_value IS
        BEGIN
--            dbms_output.put_line(&apos;set_varchar2_value&apos;);
            cell_value.varchar2_value := regexp_substr(loaded_shared_strings, &apos;\&lt;t\&gt;(.*?)\&lt;\/t\&gt;&apos;, 1, TO_NUMBER(cell_value_string) + 1);
            cell_value.varchar2_value := CONVERT(SUBSTR(cell_value.varchar2_value, 4, LENGTH(cell_value.varchar2_value) -7), local_charset, &apos;UTF8&apos;);
            cell_value.date_value := NULL;
            cell_value.number_value := NULL;
            cell_value.value := cell_value.varchar2_value;
            cell_value.type := &apos;S&apos;;
        END;

        PROCEDURE set_date_value IS
        BEGIN
--            dbms_output.put_line(&apos;set_date_value&apos;);
            number_value := TO_NUMBER(cell_value_string,  TRANSLATE(cell_value_string, &apos;012345678&apos;, &apos;999999999&apos;), &apos;nls_numeric_characters=&apos;&apos;.,&apos;&apos;&apos;);
            IF loaded_date_system = &apos;1904&apos; THEN
                cell_value.date_value := TO_DATE(&apos;01.01.&apos;||loaded_date_system,&apos;dd.mm.yyyy&apos;) + number_value;
            ELSE
                cell_value.date_value := TO_DATE(&apos;01.01.&apos;||loaded_date_system,&apos;dd.mm.yyyy&apos;) + number_value - 2;
            END IF;
            cell_value.number_value := number_value;
            cell_value.varchar2_value := TO_CHAR(cell_value.date_value, &apos;yyyy-mm-dd hh24:mi:ss&apos;);
            cell_value.value := cell_value.varchar2_value;
            cell_value.type := &apos;D&apos;;
        END;

    BEGIN

        IF NVL(DBMS_LOB.getlength(loaded_document), 0) = 0 THEN
            --Document not opened, please open document using open_document procedure first
            RAISE_APPLICATION_ERROR(-20100, &apos;Document not opened, please open document using open_document procedure first&apos;);
        END IF;

         IF NVL(DBMS_LOB.getlength(loaded_sheet), 0) = 0 THEN
            --Sheet opened, please open sheet using open_sheet procedure first
            RAISE_APPLICATION_ERROR(-20100, &apos;Sheet opened, please open sheet using open_sheet procedure first&apos;);
        END IF;

        cell_value.varchar2_value := NULL;
        cell_value.number_value := NULL;
        cell_value.varchar2_value := NULL;


        row_id := REGEXP_SUBSTR(cell_name, &apos;[[:digit:]+].*&apos;);

        -- If row is not loaded load it to cache
        IF row_id != NVL(loaded_row_id, 0) THEN
            loaded_row_string := REGEXP_SUBSTR(loaded_sheet ,&apos;\&lt;row[[:space:]]r\=\&quot;&apos;||row_id||&apos;\&quot;(.*?)\&lt;\/row\&gt;&apos;);
            loaded_row_id := row_id;
        END IF;

        -- If row is loaded to chache
        IF NVL(DBMS_LOB.getlength(loaded_row_string), 0) &gt; 0 THEN

            -- Get cell value string
            cell_value_string := REGEXP_SUBSTR(REGEXP_SUBSTR(REGEXP_SUBSTR(loaded_row_string, &apos;r\=\&quot;&apos;||cell_name||&apos;\&quot;(.*?)\&lt;\/v\&gt;&apos;), &apos;\&lt;v\&gt;(.*?)\&lt;\/v\&gt;&apos;), &apos;[0-9.]+&apos;, 1, 1, &apos;i&apos;);

            -- If value is varchar2
            --IF REGEXP_LIKE(loaded_row_string, &apos;r\=\&quot;&apos;||cell_name||&apos;\&quot;(.*?)t\=\&quot;s\&quot;(.*?)&gt;&apos;) THEN
            IF REGEXP_LIKE(loaded_row_string, &apos;r=&quot;&apos;||cell_name||&apos;&quot;[s&quot;=t ]+&gt;&apos;) THEN

                set_varchar2_value;

            -- If there is foramt for cell
            ELSIF REGEXP_LIKE(loaded_row_string, &apos;r\=\&quot;&apos;||cell_name||&apos;\&quot;(.*?)s\=\&quot;(.*)\&quot;&apos;) = TRUE THEN

                -- Get format id
                format_id := TO_NUMBER(REPLACE(REPLACE(REGEXP_SUBSTR(REGEXP_SUBSTR(loaded_row_string, &apos;r=&quot;&apos;||cell_name||&apos;&quot;[s&quot;=0-9 ]+&apos;), &apos;s=&quot;([[:digit:]]+)&quot;&apos;), &apos;s=&quot;&apos;, &apos;&apos;), &apos;&quot;&apos;, &apos;&apos;));

                IF format_id IS NOT NULL THEN

                    CASE get_format_type(format_id)
                        WHEN &apos;N&apos; THEN
                            IF REGEXP_LIKE(loaded_row_string, &apos;r\=\&quot;&apos;||cell_name||&apos;\&quot;( ){1,}s\=\&quot;([[:digit:]]+)\&quot;( ){1,}t\=\&quot;s\&quot;&apos;) = TRUE THEN
                                set_varchar2_value;
                            ELSE
                                set_number_value;
                            END IF;
                        WHEN &apos;D&apos; THEN
                             set_date_value;
                        WHEN &apos;S&apos; THEN
                             set_varchar2_value;
                        ELSE

                            NULL;

                    END CASE;

                ELSE

                    set_number_value;

                END IF;

            ELSE
                set_number_value;
            END IF;

        END IF;

        RETURN cell_value;


    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure get_cell_value &apos;||SQLCODE||SQLERRM);
    END;

    FUNCTION get_last_row RETURN INTEGER IS
    BEGIN

        RETURN TO_NUMBER(REGEXP_SUBSTR(REGEXP_SUBSTR(loaded_sheet, &apos;r=&quot;([[:digit:]]+)&quot;&apos;, NVL(INSTR(loaded_sheet , &apos;&lt;row&apos;, -1), 1)), &apos;([[:digit:]]+)&apos;));

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure get_last_row &apos;||SQLCODE||SQLERRM);
    END;

    PROCEDURE set_1904_date_system IS
    BEGIN
        date_system := 1904;
    END;

    PROCEDURE set_1900_date_system IS
    BEGIN
        date_system := 1900;
    END;

    PROCEDURE set_document_author(author VARCHAR2, doc_id PLS_INTEGER DEFAULT current_doc_id) IS
    BEGIN
        documents(doc_id).author := SUBSTR(author, 1, 1000);
    END;

    PROCEDURE add_style (style_name VARCHAR2,
                         font_name VARCHAR2 DEFAULT NULL,
                         font_size PLS_INTEGER DEFAULT NULL,
                         formula VARCHAR2 DEFAULT NULL,
                         bold BOOLEAN DEFAULT FALSE,
                         italic BOOLEAN DEFAULT FALSE,
                         underline BOOLEAN DEFAULT FALSE,
                         color VARCHAR2 DEFAULT NULL,
                         bg_color VARCHAR2 DEFAULT NULL,
                         horizontal_align VARCHAR2 DEFAULT NULL,
                         vertical_align VARCHAR2 DEFAULT NULL,
                         border_top BOOLEAN DEFAULT FALSE,
                         border_top_style VARCHAR2 DEFAULT NULL,
                         border_top_color VARCHAR2 DEFAULT NULL,
                         border_bottom BOOLEAN DEFAULT FALSE,
                         border_bottom_style VARCHAR2 DEFAULT NULL,
                         border_bottom_color VARCHAR2 DEFAULT NULL,
                         border_left BOOLEAN DEFAULT FALSE,
                         border_left_style VARCHAR2 DEFAULT NULL,
                         border_left_color VARCHAR2 DEFAULT NULL,
                         border_right BOOLEAN DEFAULT FALSE,
                         border_right_style VARCHAR2 DEFAULT NULL,
                         border_right_color VARCHAR2 DEFAULT NULL,
                         border BOOLEAN DEFAULT NULL,
                         border_style VARCHAR2 DEFAULT NULL,
                         border_color VARCHAR2 DEFAULT NULL,
                         wrap_text BOOLEAN DEFAULT FALSE,
                         format VARCHAR2 DEFAULT NULL,
                         rotate_text_degree INTEGER DEFAULT NULL,
                         indent_left INTEGER DEFAULT NULL,
                         indent_right INTEGER DEFAULT NULL,
                         column_width INTEGER DEFAULT NULL,
                         doc_id PLS_INTEGER DEFAULT current_doc_id)
    IS
    BEGIN

        documents(doc_id).styles(style_name).style_name := style_name;
        documents(doc_id).styles(style_name).font_name := font_name;
        documents(doc_id).styles(style_name).font_size := font_size;
        documents(doc_id).styles(style_name).formula := formula;
        documents(doc_id).styles(style_name).bold := bold;
        documents(doc_id).styles(style_name).italic := italic;
        documents(doc_id).styles(style_name).underline := underline;
        documents(doc_id).styles(style_name).color := color;
        documents(doc_id).styles(style_name).bg_color := bg_color;
        documents(doc_id).styles(style_name).horizontal_align := horizontal_align;
        documents(doc_id).styles(style_name).vertical_align := vertical_align;
        documents(doc_id).styles(style_name).border_top := border_top;
        documents(doc_id).styles(style_name).border_top_style := border_top_style;
        documents(doc_id).styles(style_name).border_top_color := border_top_color;
        documents(doc_id).styles(style_name).border_bottom := border_bottom;
        documents(doc_id).styles(style_name).border_bottom_style := border_bottom_style;
        documents(doc_id).styles(style_name).border_bottom_color := border_bottom_color;
        documents(doc_id).styles(style_name).border_left := border_left;
        documents(doc_id).styles(style_name).border_left_style := border_left_style;
        documents(doc_id).styles(style_name).border_left_color := border_left_color;
        documents(doc_id).styles(style_name).border_right := border_right;
        documents(doc_id).styles(style_name).border_right_style := border_right_style;
        documents(doc_id).styles(style_name).border_right_color := border_right_color;
        documents(doc_id).styles(style_name).border := border;
        documents(doc_id).styles(style_name).border_style := border_style;
        documents(doc_id).styles(style_name).border_color := border_color;
        documents(doc_id).styles(style_name).wrap_text := wrap_text;
        documents(doc_id).styles(style_name).format := format;
        documents(doc_id).styles(style_name).rotate_text_degree := rotate_text_degree;
        documents(doc_id).styles(style_name).indent_left := indent_left;
        documents(doc_id).styles(style_name).indent_right := indent_right;
        documents(doc_id).styles(style_name).column_width := column_width;

    EXCEPTION
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure add_style &apos;||SQLCODE||SQLERRM);

    END;

    PROCEDURE set_cell_style(cell_name VARCHAR2,
                             style_name VARCHAR2,
                             doc_id PLS_INTEGER DEFAULT current_doc_id,
                             sheet_id PLS_INTEGER DEFAULT current_sheet_id,
                             row_id PLS_INTEGER DEFAULT current_row_id)
    IS
    BEGIN

        IF documents(doc_id).styles(style_name).font_name IS NOT NULL OR
           documents(doc_id).styles(style_name).font_size IS NOT NULL
        THEN
            set_cell_font(cell_name,
                          NVL(documents(doc_id).styles(style_name).font_name, &apos;Calibri&apos;),
                          NVL(documents(doc_id).styles(style_name).font_size, 11),
                          doc_id,
                          sheet_id,
                          row_id);
        END IF;

        IF documents(doc_id).styles(style_name).formula IS NOT NULL THEN
            set_cell_formula(cell_name, documents(doc_id).styles(style_name).formula, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).bold = TRUE THEN
            set_cell_bold(cell_name, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).italic = TRUE THEN
            set_cell_italic(cell_name, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).underline = TRUE THEN
            set_cell_underline(cell_name, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).color IS NOT NULL THEN
            set_cell_color(cell_name, documents(doc_id).styles(style_name).color, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).bg_color IS NOT NULL THEN
            set_cell_bg_color(cell_name, documents(doc_id).styles(style_name).bg_color, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).horizontal_align IS NOT NULL THEN

            CASE documents(doc_id).styles(style_name).horizontal_align
                WHEN &apos;left&apos; THEN
                    set_cell_align_left(cell_name, doc_id, sheet_id, row_id);
                WHEN &apos;right&apos; THEN
                    set_cell_align_right(cell_name, doc_id, sheet_id, row_id);
                WHEN &apos;center&apos; THEN
                    set_cell_align_center(cell_name, doc_id, sheet_id, row_id);
                ELSE
                    NULL;
            END CASE;

        END IF;

        IF documents(doc_id).styles(style_name).vertical_align IS NOT NULL THEN

            CASE documents(doc_id).styles(style_name).vertical_align
                WHEN &apos;top&apos; THEN
                    set_cell_vert_align_top(cell_name, doc_id, sheet_id, row_id);
                WHEN &apos;middle&apos; THEN
                    set_cell_vert_align_middle(cell_name, doc_id, sheet_id, row_id);
                WHEN &apos;bottom&apos; THEN
                    set_cell_vert_align_bottom(cell_name, doc_id, sheet_id, row_id);
                ELSE
                    NULL;
            END CASE;

        END IF;

        IF documents(doc_id).styles(style_name).border_top = TRUE THEN
            set_cell_border_top(cell_name,
                                NVL(documents(doc_id).styles(style_name).border_top_style, &apos;thin&apos;),
                                NVL(documents(doc_id).styles(style_name).border_top_color, &apos;00000000&apos;),
                                doc_id,
                                sheet_id,
                                row_id);
        END IF;

        IF documents(doc_id).styles(style_name).border_left = TRUE THEN
            set_cell_border_left(cell_name,
                                 NVL(documents(doc_id).styles(style_name).border_left_style, &apos;thin&apos;),
                                 NVL(documents(doc_id).styles(style_name).border_left_color, &apos;00000000&apos;),
                                 doc_id,
                                 sheet_id,
                                 row_id);
        END IF;

        IF documents(doc_id).styles(style_name).border_bottom = TRUE THEN
            set_cell_border_bottom(cell_name,
                                   NVL(documents(doc_id).styles(style_name).border_bottom_style, &apos;thin&apos;),
                                   NVL(documents(doc_id).styles(style_name).border_bottom_color, &apos;00000000&apos;),
                                   doc_id,
                                   sheet_id,
                                   row_id);
        END IF;

        IF documents(doc_id).styles(style_name).border_right = TRUE THEN
            set_cell_border_right(cell_name,
                                  NVL(documents(doc_id).styles(style_name).border_right_style, &apos;thin&apos;),
                                  NVL(documents(doc_id).styles(style_name).border_right_color, &apos;00000000&apos;),
                                  doc_id,
                                  sheet_id,
                                  row_id);
        END IF;

        IF documents(doc_id).styles(style_name).border = TRUE THEN

            set_cell_border_top(cell_name,
                                NVL(documents(doc_id).styles(style_name).border_style, &apos;thin&apos;),
                                NVL(documents(doc_id).styles(style_name).border_color, &apos;00000000&apos;),
                                doc_id,
                                sheet_id,
                                row_id);

            set_cell_border_left(cell_name,
                                 NVL(documents(doc_id).styles(style_name).border_style, &apos;thin&apos;),
                                 NVL(documents(doc_id).styles(style_name).border_color, &apos;00000000&apos;),
                                 doc_id,
                                 sheet_id,
                                 row_id);

            set_cell_border_bottom(cell_name,
                                   NVL(documents(doc_id).styles(style_name).border_style, &apos;thin&apos;),
                                   NVL(documents(doc_id).styles(style_name).border_color, &apos;00000000&apos;),
                                   doc_id,
                                   sheet_id,
                                   row_id);

             set_cell_border_right(cell_name,
                                  NVL(documents(doc_id).styles(style_name).border_style, &apos;thin&apos;),
                                  NVL(documents(doc_id).styles(style_name).border_color, &apos;00000000&apos;),
                                  doc_id,
                                  sheet_id,
                                  row_id);

        END IF;

        IF documents(doc_id).styles(style_name).wrap_text = TRUE THEN
            set_cell_wrap_text(cell_name, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).format IS NOT NULL THEN
            set_cell_format(cell_name, documents(doc_id).styles(style_name).format, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).rotate_text_degree IS NOT NULL THEN
            set_cell_rotate_text(cell_name, documents(doc_id).styles(style_name).rotate_text_degree, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).indent_left IS NOT NULL THEN
            set_cell_indent_left(cell_name, documents(doc_id).styles(style_name).indent_left, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).indent_right IS NOT NULL THEN
            set_cell_indent_right(cell_name, documents(doc_id).styles(style_name).indent_right, doc_id, sheet_id, row_id);
        END IF;

        IF documents(doc_id).styles(style_name).column_width IS NOT NULL THEN
            set_column_width(cell_name, documents(doc_id).styles(style_name).column_width, doc_id, sheet_id);
        END IF;

     EXCEPTION
        WHEN no_data_found THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_style - style &apos;||style_name||&apos; does not exists&apos;||SQLCODE||SQLERRM);
        WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure set_cell_style &apos;||SQLCODE||SQLERRM);

    END;


  PROCEDURE freeze_panes_horizontal(freeze_columns_number VARCHAR2,
                                      doc_id PLS_INTEGER DEFAULT current_doc_id,
                                      sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN
        documents(doc_id).sheets(sheet_id).freeze_panes_horizontal := freeze_columns_number;
    EXCEPTION
       WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure freeze_panes_horizontal:&apos;||SQLCODE||SQLERRM);

    END;


    PROCEDURE freeze_panes_vertical(freeze_rows_number VARCHAR2,
                                    doc_id PLS_INTEGER DEFAULT current_doc_id,
                                    sheet_id PLS_INTEGER DEFAULT current_sheet_id)
    IS
    BEGIN
        documents(doc_id).sheets(sheet_id).freeze_panes_vertical := freeze_rows_number;
    EXCEPTION
       WHEN others THEN
            RAISE_APPLICATION_ERROR(-20100, &apos;Procedure freeze_panes_vertical:&apos;||SQLCODE||SQLERRM);

    END;



END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ADAOSMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F6103BF0056F1D1AB84EC18C89932D4B2452942</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ADAOSMED IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codadaosm INTO Tmp FROM ADAOSM WHERE codadaosm = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM ADAOSM1 WHERE CODADAOSM = RecId ;
  DELETE FROM ADAOSM WHERE codadaosm = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_ADAOSM FIELDS( codadaosm ) VALUES (0) ;
  INSERT INTO TMP_ADAOSM1 FIELDS( codadaosm1 ) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  tmp number(20,7);
BEGIN
-- Master adaosm
  INSERT INTO  TMP_ADAOSM ( codadaosm, data )
    ( SELECT codadaosm, data
      FROM ADAOSM WHERE codadaosm = RecId ) ;
  tmp:=0;
-- Detail adaosm1
  FOR v_rec IN ( SELECT * FROM ADAOSM1 WHERE CODADAOSM = RecId ORDER BY limsup ) LOOP
         insert into TMP_ADAOSM1 (codadaosm1,CODADAOSM,liminf,limsup,cotaadaost,cotaadaosd)
         values (v_rec.codadaosm1,v_rec.CODADAOSM,tmp,v_rec.limsup,v_rec.cotaadaost,v_rec.cotaadaosd);
         tmp:=v_rec.limsup+0.01;
  END LOOP;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master ADAOSM
    SELECT  codadaosm INTO RecId FROM TMP_ADAOSM;
    UPDATE ADAOSM SET ( data )
       = ( SELECT data
          FROM TMP_ADAOSM )
      WHERE codadaosm = RecId ;


-- Detail ADAOSM1

    DELETE FROM ADAOSM1 where CODADAOSM = RecId and codadaosm1 not in (Select codadaosm1 from TMP_ADAOSM1);

    INSERT INTO ADAOSM1 ( codadaosm1,CODADAOSM,limsup,cotaadaost,cotaadaosd )
      SELECT  SEQ_ADAOSM1_CODADAOSM1.Nextval , RecId ,limsup,cotaadaost,cotaadaosd
      FROM TMP_ADAOSM1 WHERE codadaosm1 &lt; 0;-- adaugam inregistrarile noi ;

    -- si facem update la cele care au ramas
    FOR v_rec IN ( SELECT * FROM TMP_ADAOSM1 WHERE NVL(codadaosm1,-1) &gt; 0 ORDER BY codadaosm1 ) LOOP
       UPDATE ADAOSM1
       SET
        codadaosm1       = v_rec.codadaosm1,
        CODADAOSM        = v_rec.CODADAOSM,
        limsup           = v_rec.limsup,
        cotaadaost       = v_rec.cotaadaost,
        cotaadaosd       = v_rec.cotaadaosd
       WHERE CODADAOSM1  = v_rec.codadaosm1;
    END LOOP;
  ELSE  -- INSERT
-- Master ADAOSM
  SELECT seq_adaosm_codadaosm.NextVal INTO RecId FROM DUAL;
  INSERT INTO  ADAOSM ( codadaosm,data )
 ( SELECT  RecId, data
     FROM TMP_ADAOSM  ) ;
-- Detail IOART1
  INSERT INTO  ADAOSM1 ( codadaosm1,CODADAOSM,limsup,cotaadaost,COTAADAOSD)
     ( SELECT  seq_adaosm1_codadaosm1.Nextval ,RecId,limsup,cotaadaost,cotaadaosd FROM TMP_ADAOSM1 );

  END IF;
  NotifyModif(Operation, RecId, &apos;ADAOSM&apos;);
  COMMIT;
END;

end PKG_ADAOSMED; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_AGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C3DA3644D01D0C96368810FDE53EA83E99526A1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_AGENDA IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODAGENDA INTO Tmp FROM NAGENDA WHERE CODAGENDA = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomSedii --&gt; 520
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 520);
	DELETE FROM NAGENDA WHERE CODAGENDA = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NAGENDA FIELDS(CODAGENDA) VALUES (0) ;
  -- nomSedii --&gt; 520
  PKG_CFGTABLES.EXT_INSERTRECORD(520);  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NAGENDA
  INSERT INTO TMP_NAGENDA (
    CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
    SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
    CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
    CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
    INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
    EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, EDI_OBJTIP2, EDI_EXPCUMUL, EDI_EXPEAN,
    EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP, EDI_DENUM, EDI_SUBDIREXP,
    GLN, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport,
    ADRESA
  )
  SELECT
    CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
    SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
    CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
    CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
    INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
    Coalesce(EDI_EXPTIP,0), Coalesce(EDI_PARTTIP,0), EDI_PARTID, Coalesce(EDI_OBJTIP,0), Coalesce(EDI_OBJTIP2,0), Coalesce(EDI_EXPCUMUL,0), Coalesce(EDI_EXPEAN,0),
    Coalesce(EDI_IMPTIP,0), Coalesce(EDI_FURNTIP,0), EDI_FURNID, Coalesce(EDI_OBJTIPIMP,0), EDI_DENUM, EDI_SUBDIREXP,
    GLN, LONGITUDINE, LATITUDINE, OBS2,CODANTREPOZIT, ZileTransport,
    GETADRESA(SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL)
  FROM NAGENDA WHERE CODAGENDA = RecId ;

  DELETE FROM TMP_NPART;
  INSERT INTO TMP_NPART (CODPART, VALMINCMD, CANTMINCMD) SELECT CODPART, VALMINCMD, CANTMINCMD
  FROM NPART
  WHERE CODPART = (SELECT CODPART FROM TMP_NAGENDA);
  -- nomSedii --&gt; 520
  PKG_CFGTABLES.EXT_GOTORECORD(520);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aCODPART NUMBER(20);
BEGIN
  -- nomSedii --&gt; 520
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (520);
  IF Operation = 0 THEN  -- UPDATE
    -- Master NAGENDA
    SELECT CODAGENDA, CODPART INTO RecId, aCODPART  FROM TMP_NAGENDA;

    UPDATE NAGENDA
    SET (   CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
            SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
            CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
            CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
            INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
            EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, EDI_OBJTIP2, EDI_EXPCUMUL, EDI_EXPEAN, EDI_DENUM, EDI_SUBDIREXP,
            EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP,
            GLN, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport
            )
       = (SELECT
            CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
            SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
            CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
            CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
            INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
            EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, EDI_OBJTIP2, EDI_EXPCUMUL, EDI_EXPEAN, EDI_DENUM, EDI_SUBDIREXP,
            EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP,
            GLN, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport
          FROM TMP_NAGENDA )
    WHERE CODAGENDA = RecId ;
  ELSE  -- INSERT
-- Master NAGENDA
    SELECT SEQ_NAGENDA_CODAGENDA.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NAGENDA&apos;, RecId); 
    SELECT CODPART INTO aCODPART FROM TMP_NAGENDA;

    INSERT INTO  NAGENDA (
      CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
      SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
      CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
      CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
      INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, EDI_OBJTIP2, EDI_EXPCUMUL, EDI_EXPEAN, EDI_DENUM, EDI_SUBDIREXP,
      EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP,
      GLN, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport
    )
    SELECT
      RecId,     TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL,
      SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS,
      CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, COEFUTILAJE,
      CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
      INACTIV, CODCORESP, TRANSPCLIENT, SUPRAFATA, MODSERVIRE, IDSEDIU,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, EDI_OBJTIP2, EDI_EXPCUMUL, EDI_EXPEAN, EDI_DENUM, EDI_SUBDIREXP,
      EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP,
      GLN, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport
    FROM TMP_NAGENDA ;
  END IF;

  FOR V_REC IN (SELECT CODPART, VALMINCMD, CANTMINCMD FROM TMP_NPART)
  LOOP
    UPDATE NPART
    SET VALMINCMD  = V_REC.VALMINCMD, CANTMINCMD = V_REC.CANTMINCMD
    WHERE CODPART = V_REC.CODPART;
  END LOOP;
  -- nomSedii --&gt; 520
  PKG_CFGTABLES.EXT_POSTRECORDS(520); 
  NotifyModif(Operation, RecId, &apos;NAGENDA&apos;);
  COMMIT;
END;

END PKG_AGENDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B7802E8E4748F722C8E408E49FA220DF574F1F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ALERTE IS

g_CodAlerta number(20);
RulezDinExe_ boolean := false;

function RulezDinExe return boolean is
begin
return RulezDinExe_;
end;

procedure UpdateAlerteDef(aCodAlerta in number, aCodAlertaDef out number) is
begin
  winmadmin.pkg_userfirme.UpdateAlerteDef(aCodAlerta, pkg_globals.FIRMANAME, aCodAlertaDef);
end;  

procedure UpdateProcDef(aCodAlerta in number) is
begin
  winmadmin.pkg_userfirme.UpdateProcDef(aCodAlerta, pkg_globals.FIRMANAME);
end;  

procedure setuserid(aUserID in number) is
PRAGMA AUTONOMOUS_TRANSACTION;
acount number(10);
begin
  select count(*) into acount from user_alerte;
  if acount &gt; 0 then
    delete user_alerte;
    insert into user_alerte(userid) values(auserid);
  else
    insert into user_alerte(userid) values(auserid);
  end if;
  commit;
end;  

function getuserid return number is
acod number(20);
begin
  begin
    select userid into acod from user_alerte;
  exception when others then acod := 0;
  end;
  return acod;
end;

procedure SetCodAlerta(aCod in number ) is
begin
 g_CodAlerta := aCod;
end;

function GetCodAlerta return number is
begin
 return g_codAlerta;
end;

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codalerta INTO Tmp FROM ALERTE WHERE CODALERTA = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE INS_MAN_ALERTE(AMESAJ IN VARCHAR2, AORDINE IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO MAN_ALERTE(USERID, MESAJ, ORDINE)
  VALUES(PKG_ALERTE.GETUSERID, AMESAJ, AORDINE);
  COMMIT;
END;

PROCEDURE CLEAR_MAN_ALERTE IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM MAN_ALERTE WHERE USERID = PKG_ALERTE.GETUSERID;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
sJob varchar2(100);
BEGIN
  SP_LOCKRECORD(RecId);
  select denumire into sJob from alerte where codalerta = recid;
  DELETE FROM ALERTE0 WHERE CODALERTA = RecId ;
  DELETE FROM ALERTE WHERE  CODALERTA = RecId ;
  COMMIT;
 begin
  dbms_scheduler.drop_job(job_name =&gt; sJob);
 exception when others then
  null;
 end;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_ALERTE FIELDS( CODALERTA ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
BEGIN
 INSERT INTO TMP_ALERTE
 (CODALERTA,  DENUMIRE,CODINTERN,TIPALERTA,OBS,UserID,WebServer, Codorar,MAILTO,
         ACTIV,                       CustomFooter, CustomMessage,Mail_Individual,Customsubject,
         Fielduri, Ordonare, TipExport, TitluXLS,SUBUNITATEA,CodFIRMA, SQL, SQLcuSMS)
  SELECT
  A.CODALERTA,A.DENUMIRE,A.CODINTERN,A.TIPALERTA,A.OBS,UserID,WebServer, codorar,a.MAILTO,
         DECODE(J.ENABLED,&apos;TRUE&apos;,1,0), CustomFooter, CustomMessage,Mail_Individual,Customsubject,
         Fielduri, Ordonare, TipExport, TITLUXLS,SUBUNITATEA,CodFIRMA, A.SQL, A.SQLcuSMS
  FROM ALERTE A LEFT JOIN USER_SCHEDULER_JOBS J ON UPPER(A.DENUMIRE) = J.JOB_NAME
  WHERE A.CODALERTA = RECID;

  INSERT INTO TMP_ALERTE0 (codalerta0, codalerta, username, userid, recipient, email, mess, task, SMS, Tel)
  SELECT codalerta0, codalerta, username, userid, recipient, email, mess, task, SMS, Tel from ALERTE0 WHERE CODALERTA = RECID;

 COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDenumire     varchar2(100);
  aScheduler    varchar2(100);
  nr            number;
  isActiv       number(1);
  OldWebServer  number(1);
  NewWebServer  number(1);
  aCodAlertaDef number(20);
  aCodFirma     number(20);
  aTipAlerta    number(20);
BEGIN
  select coalesce(WebServer, 0), coalesce(CodAlertaDef,0), PKG_Globals.GetCodFirma, coalesce(activ,0), coalesce(tipalerta,0)
  into NewWebServer, aCodAlertaDef, aCodFirma, isActiv, aTipAlerta
  FROM TMP_ALERTE;
  IF OPERATION = 0 THEN --UPDATE
    SELECT CODALERTA INTO RECID FROM TMP_ALERTE;
    Select coalesce(WebServer, 0) into OldWebServer FROM ALERTE WHERE CODALERTA = RECID;
    UPDATE ALERTE
    SET (DENUMIRE,OBS,codorar,mailto,CustomFooter, CustomMessage,Mail_Individual, UserID, WebServer, CodFirma, Customsubject, Fielduri, Ordonare, TipExport, TitluXLS, SQL, SQLcuSMS) =
        (SELECT DENUMIRE,OBS,codorar,mailto,CustomFooter, CustomMessage,Mail_Individual, UserID, WebServer, PKG_Globals.GetCodFirma,Customsubject, Fielduri, Ordonare, TipExport, TitluXLS, SQL, SQLcuSMS FROM TMP_ALERTE)
    WHERE CODALERTA = RECID;

    SELECT DENUMIRE INTO aDenumire from alerte where codalerta = recID;
    SELECT denumire INTO aScheduler from orar where codorar = (select codorar from tmp_alerte);
    -- rename daca exista
    SELECT Count(*) INTO NR from USER_SCHEDULER_JOBS J where J.JOB_NAME = UPPER(aDENUMIRE);
    if Nr &gt; 0   then
      UPDATE_ARGUMENTS (aDenumire ,aScheduler );
    end if;

    DELETE FROM ALERTE0 WHERE CODALERTA = RECID AND CODALERTA0 NOT IN (SELECT CODALERTA0 FROM TMP_ALERTE0);

    FOR V_REC IN (SELECT * FROM TMP_ALERTE0 WHERE CODALERTA0 &gt; 0) LOOP
      UPDATE ALERTE0
      SET username  = V_REC.username,
          userid    = V_REC.userid,
          recipient = V_REC.recipient,
          email     = V_REC.email,
          mess      = V_REC.mess,
          task      = v_rec.task,
          SMS       = v_rec.SMS,
          Tel       = v_rec.Tel
      WHERE CODALERTA0 = V_REC.CODALERTA0;
    END LOOP;

    INSERT INTO ALERTE0(codalerta0, codalerta, username, userid, recipient, email, mess, task, SMS, Tel)
    SELECT SEQ_ALERTE0_CODALERTA0.NEXTVAL ,RECID, username, userid, recipient, email, mess, task, SMS, Tel FROM
    TMP_ALERTE0 WHERE CODALERTA0 &lt; 0;
    
    if aCodAlertaDef &gt; 0 and aTipAlerta = 0 then
      winmadmin.pkg_list_utils.delete_list_by_id(-aCodFirma, RECID);
    end if;
  ELSE -- INSERT
    SELECT SEQ_ALERTE_CODALERTA.NEXTVAL INTO RECID FROM DUAL;
    OldWebServer := NewWebServer;

    INSERT INTO ALERTE
            ( CODALERTA,DENUMIRE,CODINTERN,TIPALERTA,OBS,USERID,WebServer,DATACREARE,
              Codorar,MAILTO,CustomFooter, CustomMessage,Mail_Individual,Customsubject, Fielduri, Ordonare, TipExport, TitluXLS,subunitatea, SQL, CodFirma, SQLcuSMS)
    SELECT     RECID,DENUMIRE,CODINTERN,TIPALERTA,OBS,USERID,WebServer,SYSDATE,
              codorar,MAILTO,CustomFooter, CustomMessage,Mail_Individual,Customsubject, Fielduri, Ordonare, TipExport, TitluXLS,subunitatea, SQL, pkg_globals.GETCODFIRMA, SQLcuSMS FROM TMP_ALERTE;

    INSERT INTO ALERTE0(codalerta0, codalerta, username, userid, recipient, email, mess, task, SMS, Tel)
    SELECT SEQ_ALERTE0_CODALERTA0.NEXTVAL ,RECID, username, userid, recipient, email, mess, task, SMS, Tel FROM TMP_ALERTE0;
  END IF;
  if aCodAlertaDef &gt; 0 and aTipAlerta = 0 then
    winmadmin.pkg_list_utils.ImportAlertList(RECID, aCodAlertaDef, aCodFirma);
  end if;
  NotifyModif(Operation, RecId, &apos;ALERTE&apos;);
  SELECT Count(*) into NR from WINMADMIN.LISTSQL  where ListID = -PKG_GLOBALS.GETCODFIRMA and LISTVer = RECID;
  IF Nr = 0 THEN
    Insert into WINMADMIN.LISTSQL (
		CODLISTSQL,
		ListID, 
		LISTVer,
		Tip,
		FIELDNAME,
		SQL
		)
		Values ( 
		WINMADMIN.SEQ_LISTSQL_CODLISTSQL.NextVal,
		-PKG_GLOBALS.GETCODFIRMA, 
		RECID, 
		0,	
		&apos;A&apos;,
		(Select SQL from TMP_ALERTE)
		);
	else
    update WINMADMIN.LISTSQL set SQL = (Select SQL from TMP_ALERTE) where ListID = -PKG_GLOBALS.GETCODFIRMA and LISTVer = RECID;
	end if;

  SELECT Substr(OBS,1,50) INTO aDenumire from alerte where codalerta = recID;
  SELECT Count(*) into NR from WINMADMIN.LISTS  where ListID = -PKG_GLOBALS.GETCODFIRMA and LISTVer = RECID;
  IF Nr = 0 THEN
    Insert into WINMADMIN.LISTS (
		CODLISTS,
		ListID, 
		LISTVer,
		Name, 
		Name1, 
		STOREDPROCNAME, 
		CodSet,	IsDocument,		LeftMargin, RightMargin, TopMargin, BottomMargin,
		BorderStyle, BORDERCOLOR
		)
		Values ( 
		WINMADMIN.SEQ_LISTS_CODLISTS.NextVal,
		-PKG_GLOBALS.GETCODFIRMA, 
		RECID, 
		aDenumire,	
		aDenumire,
		&apos;PKG_LIST_BASE_CUSTOM.PROCESSLIST&apos;,
		1, 1, 10,5,5,5,
		1, 12635556
		);
	else
    update WINMADMIN.LISTS set Name = aDenumire where ListID = -PKG_GLOBALS.GETCODFIRMA and LISTVer = RECID;
	end if;

  COMMIT;

  SELECT DENUMIRE INTO aDenumire from alerte where codalerta = recID;
  SELECT Count(*) into NR from USER_SCHEDULER_JOBS J where UPPER(aDENUMIRE) = J.JOB_NAME;
  IF Nr = 0 THEN
    IF Nvl(IsActiv,0) = 1 THEN
      PKG_ALERTE.SET_JOB(RECID);
    END IF;
  ELSE
    if (OldWebServer &lt;&gt; NewWebServer) then 
			IF Nvl(IsActiv,0) = 1 THEN
				begin
					dbms_scheduler.drop_job(job_name =&gt; UPPER(aDENUMIRE));
				exception when others then
					null;
				end;
				PKG_ALERTE.SET_JOB(RECID);
			END IF;
		else 
			SELECT Count(*) INTO NR FROM USER_SCHEDULER_JOBS J WHERE UPPER(aDENUMIRE) = J.JOB_NAME and J.ENABLED = &apos;TRUE&apos;;
			IF Nr = 0 THEN
				IF Nvl(IsActiv,0) = 1 THEN
					dbms_scheduler.enable(aDenumire);
				END IF;
			ELSE
				IF Nvl(IsActiv,0) = 0 THEN
					dbms_scheduler.disable(aDenumire);
				END IF;
			END IF;
		END IF;
 END IF;

EXCEPTION WHEN OTHERS THEN
  ROLLBACK;
  RAISE;
END;

PROCEDURE UPDATE_ARGUMENTS (aDenumire in varchar2, aScheduler in varchar2) is
pragma autonomous_transaction;
begin
  dbms_scheduler.set_attribute(
    name      =&gt; aDenumire,
    attribute =&gt; &apos;SCHEDULE_NAME&apos;,
    value     =&gt; aScheduler);
end;

PROCEDURE SET_JOB(aCODALERTA IN NUMBER) IS
  aDenumire varchar2(100);
  sp        varchar2(100);
  sched     varchar2(100);
BEGIN


  SELECT a.denumire,a.codintern,o.denumire
  INTO adenumire,sp,sched
  FROM alerte a left join orar o on a.codorar = o.codorar
  WHERE codalerta = aCodAlerta;

  DBMS_SCHEDULER.create_job(
    job_name            =&gt; aDenumire ,
    job_type            =&gt; &apos;STORED_PROCEDURE&apos;,
    job_action          =&gt; sp,
    schedule_name       =&gt; sched,
    number_of_arguments =&gt; 1,
    Auto_drop           =&gt; false);

  dbms_scheduler.set_job_argument_value(
    job_name          =&gt; aDenumire,
    argument_position =&gt; 1,
    argument_value    =&gt; aCODALERTA);

  dbms_scheduler.enable(aDenumire);
END;

PROCEDURE SET_STATE (aCODALERTA IN NUMBER,ASTATE IN NUMBER) IS
  pragma autonomous_transaction;
  aDenumire varchar2(100);
BEGIN
  SELECT UPPER(DENUMIRE) INTO aDENUMIRE FROM ALERTE WHERE CODALERTA = aCODALERTA;
  IF ASTATE = 1 THEN
    DBMS_SCHEDULER.enable(AdENUMIRE);
  ELSE
    DBMS_SCHEDULER.disable(AdENUMIRE);
  END IF;
END;

PROCEDURE RUN_NOW(aDenumire in varchar2) IS
BEGIN
  RulezDinExe_ := True;
  Dbms_Scheduler.run_job(job_name =&gt; aDenumire ,use_current_session =&gt; TRUE);
END;

FUNCTION FORMAT_HTML_MESSAGE(pMesaj in clob) RETURN CLOB IS
  tmpMes CLOB;
  linie  varchar2(32000);
  res    CLOB           := &apos;&apos;; --&apos;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt;&apos;;

  function FormatLinie(aLinie in varchar2) return varchar2 is
    sRes varchar2(32000);
    l_denumire varchar2(200);
    l_filtre   varchar2(200);
    l_rezultat varchar2(200);
    l_context  varchar2(200);
  begin
    sRes := aLinie;
    l_denumire := replace(C_LINE_DENUMIRE,C_LINE_SEP,&apos;&apos;);
    l_filtre   := replace(C_LINE_FILTRE  ,C_LINE_SEP,&apos;&apos;);
    l_rezultat := replace(C_LINE_REZULTAT,C_LINE_SEP,&apos;&apos;);
    l_context  := replace(C_LINE_CONTEXT, C_LINE_SEP,&apos;&apos;);

    sRes:= replace(sRes,l_denumire,&apos;&lt;b&gt;&lt;u&gt;&apos;||l_denumire||&apos;&lt;/u&gt;&lt;/b&gt;&apos;);
    sRes:= replace(sRes,l_filtre,  &apos;&lt;br&gt;&lt;b&gt;&lt;u&gt;&apos;||l_filtre||  &apos;&lt;/u&gt;&lt;/b&gt;&apos;);
    sRes:= replace(sRes,l_rezultat,&apos;&lt;br&gt;&lt;b&gt;&lt;u&gt;&apos;||l_rezultat||&apos;&lt;/u&gt;&lt;/b&gt;&apos;);
    sRes:= replace(sRes,l_context ,&apos;&lt;br&gt;&lt;b&gt;&lt;u&gt;&apos;||l_context|| &apos;&lt;/u&gt;&lt;/b&gt;&apos;);
    RETURN sRes;
  end;

begin
  tmpMes := pMesaj;

  WHILE instr(tmpMes,C_LINE_SEP) &gt; 0 LOOP
    linie  := substr(tmpMes,1,instr(tmpMes,C_LINE_SEP) - 1);
    res    := res ||FormatLinie(linie) || &apos;&lt;br&gt;&apos;;
    tmpMes := substr(tmpMes,instr(tmpMes,C_LINE_SEP) + 1,length(tmpMes));
  end loop;
  res := res ||tmpMes;
  return  res;
end;

PROCEDURE ACTUAL_PROC_DATE IS
BEGIN
  delete from infoactualconst;

  INSERT INTO infoactualconst(denconst,tipoper)
  SELECT TMP.DENUMIRE,&apos;A&apos;
  FROM TMP_PROC_ACT_DEF TMP
  WHERE NOT EXISTS(SELECT P.CODPROCACTDEF FROM PROC_ACT_DEF P WHERE P.CODPROCACTDEF = TMP.CODPROCACTDEF);

  /*INSERT INTO INFOACTUALCONST(DENCONST,TIPOPER)
  SELECT P.DENUMIRE,&apos;S&apos;
  FROM  PROC_ACT_DEF P
  WHERE NOT EXISTS(SELECT TMP.CODPROCACTDEF FROM TMP_PROC_ACT_DEF TMP  WHERE P.CODPROCACTDEF = TMP.CODPROCACTDEF);*/


  MERGE INTO PROC_ACT_DEF P
  USING TMP_PROC_ACT_DEF TMP ON (P.CODPROCACTDEF = TMP.CODPROCACTDEF)
  WHEN MATCHED THEN
    UPDATE SET
      P.DENUMIRE  = TMP.DENUMIRE,
      P.SQL       = TMP.SQL,
      P.CODINTERN = TMP.CODINTERN
  WHEN NOT MATCHED THEN
    INSERT (P.CODPROCACTDEF,P.DENUMIRE,P.CODINTERN,P.SQL)
    VALUES (TMP.CODPROCACTDEF,TMP.DENUMIRE,TMP.CODINTERN,TMP.SQL);

  --DELETE FROM PROC_ACT_DEF P WHERE NOT EXISTS (SELECT TMP.CODPROCACTDEF FROM TMP_PROC_ACT_DEF TMP WHERE TMP.CODPROCACTDEF = P.CODPROCACTDEF);

  COMMIT;
END;

PROCEDURE ACTUAL_ALERTE IS
  iFound number(20) := 0;
  CODA NUMBER(20);
BEGIN

  DELETE FROM infoactualconst;

  INSERT INTO INFOACTUALCONST(DENCONST,TIPOPER)
    SELECT TMP.DENUMIRE,&apos;A&apos;
     FROM TMP_ALERTE_DEF TMP
     WHERE NOT EXISTS(SELECT A.CODALERTADEF FROM ALERTE_DEF A WHERE A.CODALERTADEF = TMP.CODALERTADEF);

  /*INSERT INTO INFOACTUALCONST(DENCONST,TIPOPER)
    SELECT A.DENUMIRE,&apos;S&apos;
     FROM ALERTE_DEF A
     WHERE NOT EXISTS(SELECT TMP.CODALERTADEF FROM TMP_ALERTE_DEF TMP WHERE A.CODALERTADEF = TMP.CODALERTADEF);*/

  MERGE INTO ALERTE_DEF A
  USING TMP_ALERTE_DEF TMP ON (A.CODALERTADEF = TMP.CODALERTADEF)
  WHEN MATCHED THEN
    UPDATE SET
      A.DENUMIRE  = TMP.DENUMIRE,
      A.SQL       = TMP.SQL,
      A.CODINTERN = TMP.CODINTERN
  WHEN NOT MATCHED THEN
    INSERT (A.CODALERTADEF,A.DENUMIRE,A.CODINTERN,A.SQL) VALUES (TMP.CODALERTADEF,TMP.DENUMIRE,TMP.CODINTERN,TMP.SQL);

  --DELETE FROM ALERTE_DEF A WHERE NOT EXISTS(SELECT TMP.CODALERTADEF FROM TMP_ALERTE_DEF TMP WHERE A.CODALERTADEF = TMP.CODALERTADEF);

  COMMIT;
END;

FUNCTION TEST_DEN(aDenumire in varchar2 ,obj_type out varchar2) RETURN NUMBER is
BEGIN
  obj_type := &apos;?&apos;;
  BEGIN
    SELECT object_type INTO obj_type
    FROM user_objects u
    WHERE upper(u.object_name) = upper(aDenumire) and rownum &lt;=1;
  EXCEPTION WHEN no_data_found THEN
    RETURN 1;
  END;
  RETURN 0;
end;

FUNCTION TRANDU_FILTRU_WME (AFILTRU VARCHAR2,aDataType in varchar2) RETURN VARCHAR2 is
sResult  varchar2(2000);
fltr     varchar2(2000);
begin
 fltr    := AFILTRU;
 sResult := replace(fltr,&apos;!&apos;,&apos; diferit de &apos;);
 sResult := replace(fltr,&apos;&apos;,&apos; si &apos;);
 sResult := replace(fltr,&apos;;&apos;,&apos; sau &apos;);
end;

procedure MailAlert(acodAlerta in number, acodRulare in number) is
  aSender           varchar2(100);
  aRecipients       varchar2(100);
  aSubject          varchar2(100);
  aMessage          clob;
  iMail             number(1) := 0;
  cMess             clob;
  cFooter           clob;
  cSubj             varchar(200);
  cRecip            varchar2(200);
  aCodUser          number(20);
  aSkemaUser        VARCHAR2(30);
  aCodFirma         number(20);
  aRezultat         clob := C_LINE_REZULTAT;
  aFiltre           varchar2(800) := null;
  Milisecunde       number(20) := 0;
  BufferMilisecunde number(20);
  Hohentzoler       Varchar2(10):= &apos;iHot&apos;;
	pAn               NUMBER(4) := Pkg_Globals.ANLUCRU;
  pLuna             NUMBER(2) := Pkg_Globals.LUNALUCRU;
  InitKey           VARCHAR2(100);

  procedure PrepareAndSend_mail( vSender in varchar2,
                                 vRecipients in varchar2,
                                 vSubject in varchar2,
                                 vMessage in clob,
                                 vMailID in number,
                                 vAttach  blob,
                                 vFileName in varchar
                                 ) is
    iCodMail    number(20);
    gUserMail   varchar2(256);
    gPassMail   varchar2(256);
    gPort       integer;
    gServerMail varchar2(256);
    gDomain     varchar2(256);
    gAuthType   integer      ;
    gCodServer  number(20)  := 0;
    NewRecip    varchar(200);
    LocalMess   clob;
    LocalSubject varchar2(100);
    gClientID           varchar2(200);
    gClientSecret       varchar2(200);
    gAuthEndPoint       varchar2(200);
    gAccesTokenEndPoint varchar2(200);
    gRefreshToken       varchar2(2000);
    gLogOutEndPoint     varchar2(200);
    gScopes             varchar2(300);
    gOAuth2             NUMBER;
    
    
    
  begin
    if Milisecunde &gt; 0 then Delay(Milisecunde);  end if;
    SELECT seq_mailuri_codmail.nextval INTO iCodMail from dual;

    WINMADMIN.PKG_USERFIRME.GET_USER_CREDENTIAL_ext( aCodUSER, 
                                                 gCodServer, 
                                                 aCodFirma, 
                                                 gUserMail, 
                                                 gPassMail, 
                                                 gPort, 
                                                 gServerMail, 
                                                 gDomain, 
                                                 gAuthType,
                                                 gRefreshToken,
                                                 goAuth2,
                                                 gClientID,
                                                 gClientSecret,
                                                 gAuthEndPoint,
                                                 gAccesTokenEndPoint,
                                                 gLogOutEndPoint,
                                                 gScopes
                                                 );






    NewRecip := Replace(vRECIPIENTS,&apos;?&apos;,vSENDER);
    LocalMess := Replace(vMessage, &apos;%SYSDATE%&apos;, To_Char(SysDate, &apos;dd.mm.yyyy&apos;));
    LocalMess := Replace(LocalMess, &apos;%LUNA%&apos;, To_Char(SysDate, &apos;MM&apos;));
    LocalMess := Replace(LocalMess, &apos;%ZIUA%&apos;,  PKG_LIST_BASE_UTILS.DECODE_ZI(sysdate));
    LocalMess := Replace(LocalMess, &apos;%ORA%&apos;, To_Char(SysDate, &apos;HH24&apos;));
    LocalMess := Replace(LocalMess, &apos;%MIN%&apos;, To_Char(SysDate, &apos;MI&apos;));

    LocalSubject := Replace(vSubject, &apos;%SYSDATE%&apos;, To_Char(SysDate, &apos;dd.mm.yyyy&apos;));
    LocalSubject := Replace(LocalSubject, &apos;%LUNA%&apos;, To_Char(SysDate, &apos;MM&apos;));
    LocalSubject := Replace(LocalSubject, &apos;%ZIUA%&apos;,  PKG_LIST_BASE_UTILS.DECODE_ZI(sysdate));
    LocalSubject := Replace(LocalSubject, &apos;%ORA%&apos;, To_Char(SysDate, &apos;HH24&apos;));
    LocalSubject := Replace(LocalSubject, &apos;%MIN%&apos;, To_Char(SysDate, &apos;MI&apos;));
    if Length(vAttach) &gt; 0 then
      INSERT INTO mailuri1 (CODMAIL1, CODMAIL, FileName, ATTACHFILE)
      VALUES              (seq_mailuri1_codmail1.nextval, iCodMail,vFileName, vAttach);
    end if;
    INSERT INTO mailuri (CODMAIL, SENDER, RECIPIENTS,SUBJECT, MSG,      USERID,   DATA,   status,host,       port, domain, Codfirma, CodServer)
    VALUES              (iCodMail,vSENDER,NewRecip,  LocalSubject,LocalMess, acodUser ,sysdate,0,     gServerMail,gport,gdomain,aCODFIRMA,gCodServer);
    COMMIT;
    PKG_MAIL_UTILS.DoTheJob(iCodMail);
    Milisecunde := BufferMilisecunde;
  end;

begin
  InitKey    := WINMADMIN.PKG_USERFIRME.GetKey;
  SELECT nag.email,a.mailto, nvl(Customsubject, a.Obs||&apos;[&apos;||a.denumire||&apos;]&apos;)
  INTO aSender, aRecipients, aSubject
  FROM alerte a
    INNER JOIN npers np ON a.userid = np.logonname
    INNER JOIN nagenda nag on nag.codagenda = np.agenda
  WHERE a.codalerta = aCodAlerta;
  Hohentzoler := Hohentzoler||&apos;z&apos;;

  SELECT mail_individual, CustomFooter, CustomMessage, Customsubject, UserID, CodFirma
  INTO iMail, cFooter, cMess, cSubj, acodUser, acodFirma
  FROM alerte
  WHERE codalerta = aCodAlerta;
  aSkemaUser := WINMADMIN.PKG_USERFIRME.GETUSERSKEMA(aCodUser);

  IF Nvl(pAn,0) = 0 OR Nvl(pLuna,0) = 0 THEN
    SELECT AnMaxim, LunaMaxima INTO pAn, pLuna FROM firmaluni;
  END IF;
  IF Nvl(PKG_GLOBALS.GETUSERID,0) = 0 THEN
    PKG_GLOBALS.SETUSERID(aCodUser);
  END IF;
  BufferMilisecunde := To_Number(1000*NVL(pkg_categconst.GetValConstanta(&apos;EDELAY&apos;, pAn, pLuna), &apos;0&apos;)) ;

  if (length(trim(aRecipients)) = 0) and (iMail = 0) then
    return;
	else
    WINMADMIN.PKG_USERFIRME.SetKey(UPPER(aSkemaUser)||&apos;NuF&apos;);
  end if;
  WINMADMIN.PKG_USERFIRME.SetKey(WINMADMIN.PKG_USERFIRME.GetKey||Hohentzoler||To_Char(aCodUser)||UPPER(aSkemaUser));

  for v_rec in ( select ai.rezultat, ai.Filebody, ai.FileName, ai.info_filtre,ai.mailto, ai.TaskTo, ai.MessTo
                from alerte_info ai
                where ai.codrulare = aCodRulare)
  loop
    if aFiltre is null then
    aFiltre := v_rec.info_filtre;
    end if;

    aRezultat := aRezultat ||&apos;|&apos;|| v_rec.rezultat ;

    if (length(trim(v_rec.mailto)) &gt; 1 ) then
      if Length(v_rec.Filebody) &gt; 0 then
        aMessage := pkg_alerte.FORMAT_HTML_MESSAGE(cMess||&apos;|&apos;||cFooter);
      else
        aMessage := pkg_alerte.FORMAT_HTML_MESSAGE(cMess||&apos;|&apos;||v_rec.Rezultat||&apos;|&apos;||cFooter);
      end if;
      BEGIN
        PrepareAndSend_mail(vSender     =&gt; aSender,
                            vRecipients =&gt; v_rec.mailto,
                            vSubject    =&gt; aSubject,
                            vMessage    =&gt; aMessage,
                            vMailID     =&gt; 0,
                            vAttach     =&gt; v_rec.Filebody,
                            vFileName   =&gt; v_rec.FileName
                            );
      EXCEPTION
        when others then null;
      END;
    end if;
  end loop;

  for v_rec in ( select a0.USERNAME, a0.USERID, a0.recipient, ai.Filebody, ai.FileName, ai.rezultat, ai.info_filtre
                  from alerte0 a0
                  inner join alerte_info ai on ai.codalerta = a0.codalerta
                  where ai.codrulare = aCodRulare
                  and nvl(a0.email,0) = 1)
  loop
    if (length(trim(v_rec.Recipient)) &gt; 1)  then
      if Length(v_rec.Filebody) &gt; 0 then
        aMessage := pkg_alerte.FORMAT_HTML_MESSAGE(cMess||&apos;|&apos;||cFooter);
      else
        aMessage := pkg_alerte.FORMAT_HTML_MESSAGE(cMess||&apos;|&apos;||v_rec.Rezultat||&apos;|&apos;||cFooter);
      end if;
      PrepareAndSend_mail(
        vSender =&gt; aSender,
        vRecipients  =&gt; v_rec.Recipient,
        vSubject     =&gt; aSubject,
        vMessage     =&gt; aMessage,
        vMailID     =&gt; 0,
        vAttach     =&gt; v_rec.Filebody,
        vFileName   =&gt; v_rec.FileName
        );
    end if;
  end loop;
  WINMADMIN.PKG_USERFIRME.SetKey(InitKey);
END;

procedure postTask(aCodAlerta in number, aCodRulare in number) is
  aFiltre varchar2(32000);
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  ausername varchar2(100);
  aSender varchar2(100);
  aCodFirma number(20);
  aCodUSer  number(20);
  TaskFirma number(1);
begin
   SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
   INTO TaskFirma from dual;
   select UserID, CodFirma
   into   acodUser, acodFirma
   from alerte where codalerta =aCodAlerta;
   select winmadmin.pkg_userfirme.getUserName(aCoduser) into aSender from dual;

  for v_rec in ( select a0.USERNAME, a0.USERID, ai.rezultat, ai.info_filtre
                 from alerte0 a0
                 inner join alerte_info ai on ai.codalerta = a0.codalerta
                 where ai.codrulare = aCodRulare
                 and nvl(a0.task,0) = 1)
  loop
    if aFiltre is null then
      aFiltre := substr(replace(v_rec.info_filtre,&apos;|&apos;,chr(13)||chr(10)),1,4000);
    end if;

    aRezultat := v_rec.rezultat ;
    ausername := v_rec.Username;
    if v_rec.Username is null then
      select winmadmin.pkg_userfirme.getUserName(v_rec.userid) into ausername from dual;
    end if;
    aMesaj := substr(replace(aRezultat,&apos;|&apos;,chr(13)||chr(10)),1,4000);

    if TaskFirma = 2 then
      INSERT INTO SETTASK (
        CODTASK,
        PROBLEMA, Subunitatea, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART
      )
      VALUES (
        Seq_SETTASK_CODTASK.Nextval,
        aMesaj, 1, aFiltre, &apos;AUTOMAT&apos;, &apos;FIRMA&apos;, aUSERNAME, aSender, aUSERNAME, SysDate,SysDate,&apos;ALERTE&apos;,0,1, aCODFIRMA, NULL
      ) ;
    else
      INSERT INTO WINMADMIN.SETTASK (
        CODTASK,
        PROBLEMA, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART
      )
      VALUES (
        winmadmin.PKG_USERFIRME.getSeqNextVal(&apos;Seq_SETTASK_CODTASK&apos;),
        aMesaj, aFiltre, &apos;AUTOMAT&apos;, &apos;FIRMA&apos;, aUSERNAME, aSender, aUSERNAME, SysDate,SysDate,&apos;ALERTE&apos;,0,1, aCODFIRMA, NULL
      ) ;
    end if;
  end loop;
  commit;
  postTask_AI(aCodAlerta,aCodRulare);
end;

procedure postTask_AI(aCodAlerta in number, aCodRulare in number) is
  aFiltre varchar2(32000);
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  username varchar2(100);
  aSender varchar2(100);
  aCodFirma number(20);
  aCodUSer  number(20);
  TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
 INTO TaskFirma from dual;
  select UserID, CodFirma
  into   acodUser, acodFirma
  from alerte where codalerta =aCodAlerta;
  select winmadmin.pkg_userfirme.getUserName(aCoduser) into aSender from dual;
  for x_rec in (select distinct ai.Taskto from alerte_info ai where ai.codrulare = aCodRulare and Nvl(ai.Taskto, &apos;?&apos;) &lt;&gt; &apos;?&apos;) loop
    aFiltre := null;
    aRezultat := null;
    for v_rec in (select ai.rezultat, ai.info_filtre, ai.Taskto from alerte_info ai  where ai.codrulare = aCodRulare and ai.messto = x_rec.Taskto) loop
       if aFiltre is null then
         aFiltre := substr(replace(v_rec.info_filtre,&apos;|&apos;,chr(13)||chr(10)),1,4000);
        end if;
       aRezultat := aRezultat ||&apos;|&apos;|| v_rec.rezultat ;

    end loop;

    aMesaj := substr(replace(aRezultat,&apos;|&apos;,chr(13)||chr(10)),1,4000);

    if TaskFirma = 2 then
      INSERT INTO SETTASK (
        CODTASK,
        PROBLEMA, Subunitatea, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART )
      values (
        Seq_SETTASK_CODTASK.NextVal,
        aMesaj, 1, aFiltre, &apos;AUTOMAT&apos;, &apos;FIRMA&apos;, x_rec.TaskTo, aSender, x_rec.TaskTo, SysDate, SysDate, &apos;ALERTE&apos;,0,1, aCODFIRMA, NULL ) ;
    else
      INSERT INTO WINMADMIN.SETTASK (
        CODTASK,
        PROBLEMA, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART )
      values (
        winmadmin.PKG_USERFIRME.getSeqNextVal(&apos;Seq_SETTASK_CODTASK&apos;),
        aMesaj, aFiltre, &apos;AUTOMAT&apos;, &apos;FIRMA&apos;, x_rec.TaskTo, aSender, x_rec.TaskTo, SysDate, SysDate, &apos;ALERTE&apos;,0,1, aCODFIRMA, NULL ) ;
    end if;
  end loop;
  commit;
end;


procedure postMesagerie(aCodAlerta in number, aCodRulare in number) is
  aFiltre varchar2(32000);
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  username varchar2(100);
begin
  for v_rec in ( select a0.USERNAME, a0.USERID, ai.rezultat, ai.info_filtre
                 from alerte0 a0
                 inner join alerte_info ai on ai.codalerta = a0.codalerta
                 where ai.codrulare = aCodRulare
                 and nvl(a0.mess,0) = 1)
  loop
    if aFiltre is null then
      aFiltre := v_rec.info_filtre;
    end if;

    aRezultat := v_rec.rezultat ;
    username := v_rec.Username;
    if v_rec.Username is null then
      select winmadmin.pkg_userfirme.getUserName(v_rec.userid) into username from dual;
    end if;
    aMesaj := substr(replace(aFiltre||&apos;|&apos;||aRezultat,&apos;|&apos;,chr(13)||chr(10)),1,4000);
    insert into winmadmin.mesaje(codmesaj,text,from_user,skemafirma,data,tip_mesaj) values
      (winmadmin.seq_mesaje_codmesaj.nextval,substr(aMesaj,1,4000),&apos;ALERTE&apos;,USER,sysdate,0);
    insert into winmadmin.mesaje1(codmesaj1,codmesaj,to_user) values
     (winmadmin.seq_mesaje1_codmesaj1.nextval,winmadmin.seq_mesaje_codmesaj.currval,username);

  end loop;
  commit;
  postMesagerie_AI(aCodAlerta,aCodRulare);
end;

procedure postMesagerie_AI(aCodAlerta in number, aCodRulare in number) is
  aFiltre varchar2(32000);
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  username varchar2(100);
begin
  for x_rec in (select distinct ai.messto from alerte_info ai where ai.codrulare = aCodRulare and Nvl(ai.messto, &apos;?&apos;) &lt;&gt; &apos;?&apos;) loop
    aFiltre := null;
    aRezultat := null;
    for v_rec in (select ai.rezultat, ai.info_filtre, ai.messto from alerte_info ai  where ai.codrulare = aCodRulare and ai.messto = x_rec.messto) loop
       if aFiltre is null then
          aFiltre := v_rec.info_filtre;
        end if;
       aRezultat := aRezultat ||&apos;|&apos;|| v_rec.rezultat ;

    end loop;
    aMesaj := replace(aFiltre||&apos;|&apos;||aRezultat,&apos;|&apos;,chr(13)||chr(10));

    insert into winmadmin.mesaje(codmesaj,text,from_user,skemafirma,data,tip_mesaj)
    values     (winmadmin.seq_mesaje_codmesaj.nextval,substr(aMesaj,1,4000),&apos;ALERTE&apos;,USER,sysdate,0);

    insert into winmadmin.mesaje1(codmesaj1,codmesaj,to_user)
    values     (winmadmin.seq_mesaje1_codmesaj1.nextval,winmadmin.seq_mesaje_codmesaj.currval,x_rec.MessTo);
  end loop;
  commit;
end;

function setInfoText(vCodAlerta in varchar2, pAn in number, pLuna in number) return varchar2 is
 sRes varchar2(32000);
begin
   select a.Obs||&apos;[&apos;||a.denumire||&apos;]&apos;||PKG_ALERTE.C_LINE_SEP||
          &apos;An = &apos;||pAn||&apos; Luna = &apos;||pLuna||PKG_ALERTE.C_LINE_SEP||
          &apos;Data rulare &apos;||to_Char(sysdate,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||PKG_ALERTE.C_LINE_SEP
   into sRes
   from alerte a left join nsubunit nsub on nsub.codsubunit = a.subunitatea
   where a.codalerta = vCodAlerta;
 RETURN sRes;
end;

function GetSQLForExcell(xSQL in Clob, Ord in Varchar2, Cod in Number) return Clob is
x Clob;
begin
  X := xSQL ||&apos; where COD = &apos;||COD||&apos; &apos;||Ord;
  Return X;
end;

function GetColoane(fFields in Varchar2)  return Varchar2 is
Coloane varchar(1000);
X varchar2(1000);
begin
  X := Replace(fFields, &apos;,&apos;, &apos;||&apos;&apos;&lt;/TD&gt;&lt;TD&gt;&apos;&apos;||Y.&apos;);
  Coloane := &apos;&apos;&apos;&lt;TD&gt;&apos;&apos;||Y.&apos; || X || &apos; ||&apos;&apos;&lt;/TD&gt;&apos;&apos;&apos;;
  Return Coloane;
end;

function IsHTML(Nume in Varchar2)  return Boolean is
begin
  Return InStr(Upper(nume), &apos;.HTML&apos;) &lt;&gt; 0;
end;

FUNCTION DO_ALERTA_WEBSERVICE(askemafirma varchar, vCodAlerta number) RETURN NUMBER
is
  --aUserID number(20) := 0;
  aLunaLucru number(2);
  aAnLucru   number(5); 
  IPWebServiceSMS   varchar2(100);
  PortWebServiceSMS varchar2(10);
  aDBName   varchar2(20);
  JobInfo   varchar2(3000);
  MSG_EROARE varchar2(1000);
  URL varchar2(1000); 
  aREq utl_http.req;
  RESP utl_http.resp;
  value VARCHAR2(32767);  
  Res        NUMBER(1) := 0;
  aPos       Number(10);
  StartPos   Number(10);
  EndPos     Number(10);
  OldUser    Number(20);
  aUserID    Number(20);
begin
  begin
    EXECUTE IMMEDIATE &apos;select anmaxim, lunamaxima from  &apos;|| aSkemaFirma|| &apos;.firmaluni &apos; into aAnlucru, aLunalucru ;
    EXECUTE IMMEDIATE  &apos;select UserID FROM &apos; || aSkemaFirma ||&apos;.alerte WHERE codalerta = &apos; || vCodAlerta INTO aUserID;
    exception when others then
      RETURN 0;
  end;  

  IPWebServiceSMS    := pkg_categconst.GetValConstantaExt(&apos;IPWebServiceSMS&apos;, aAnlucru, aLunalucru, aUserID, aSkemaFirma);
  PortWebServiceSMS  := pkg_categconst.GetValConstantaExt(&apos;PortWebServiceSMS&apos;, aAnlucru, aLunalucru, aUserID, aSkemaFirma);
    
    select global_name into aDBName from global_name ;
    JobInfo := &apos;{&quot;AlertaInfo&quot;:{
                                       &quot;DataBaseType&quot;:&quot;ORA&quot;,
                                       &quot;DBName&quot;:&quot;&apos;         || aDBName        ||&apos;&quot;,
                                       &quot;CodAlerta&quot;:&quot;&apos;        || vCodAlerta     ||&apos;&quot;,
                                       &quot;Skema&quot;:&quot;&apos;          || askemafirma    ||&apos;&quot;
                                     }}&apos;;
    MSG_EROARE := &apos;&apos;;
    URL        := &apos;http://&apos; || IPWebServiceSMS  || &apos;:&apos; || PortWebServiceSMS || &apos;/root/wmeserver/solveAlerta&apos;;
    
    UTL_HTTP.set_transfer_timeout(32000);
    
    areq       := UTL_HTTP.BEGIN_REQUEST ( LOWER(URL),&apos;POST&apos; );
    utl_http.set_header(areq, &apos;Content-Length&apos;, length(JobInfo));
    UTL_HTTP.WRITE_TEXT (areq, JobInfo);
   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

  END;  
  IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;
  RETURN RES;
end;  

PROCEDURE DO_ALERTA(VCODALERTA IN NUMBER) IS
  idx_rulare     number(20);
  sInfo          clob;
  pAn            NUMBER(4);
  pLuna          NUMBER(2);
  aSQL           CLOB;
  xSQL           CLOB;
  aCUSTOMMESSAGE CLOB;
  aCUSTOMFOOTER  CLOB;
  sSelect        CLOB;
  aTipAlerta     NUMBER(1);
  fName          varchar2(100);
  fFields        varchar2(1000);
  fOrd           varchar2(1000);
  fTip           Number(2);
  fSQLCUSMS      Number(2);
  Xls blob;
  sDDL           CLOB := &apos;CREATE TABLE &apos;;
  TmpName        VARCHAR2(  100);
  b integer;
  s varchar2(100);
	isWebServer   number;
	aCodFirma     number;
	
  function ClearExt(Nume in Varchar2)  return Varchar2 is
  begin
    s := Nume;
    b := InStr(Upper(nume), &apos;.&apos;);
    if b &gt; 0 then
      s := Substr(Nume, 1, b-1);
    end if;
    Return s;
  end;

BEGIN
  SELECT anMaxim,LunaMaxima INTO pAn , pLuna FROM firmaluni;
  SELECT Nvl(WebServer, 0), CodFirma into isWebServer, aCodFirma FROM alerte WHERE codalerta = vCodAlerta;
  if isWebServer = 1 then 
		fName := WINMADMIN.pkg_userfirme.GetSkemaFirma(aCodFirma);
    b := DO_ALERTA_WEBSERVICE(fName, vCodAlerta) ;
	else --not WebServer
		SELECT SQL, CUSTOMMESSAGE, CUSTOMFOOTER, Nvl(tipalerta,0), TitluXLS, Fielduri, Ordonare, TipExport, Nvl(SQLCUSMS,0) into
					 aSql,aCUSTOMMESSAGE,aCUSTOMFOOTER,Atipalerta, fName, fFields, fOrd, fTip, fSQLCUSMS
		FROM alerte
		WHERE codalerta = vCodAlerta;
		if fSQLCUSMS = 0 and atipalerta = 0 then
			b := InStr(Upper(aSQL), &apos;SELECT&apos;);
			if b &gt; 0 then
				aSQL := Substr(aSQL, 1, b + 6 - 1) || &apos; &apos;&apos;?&apos;&apos; SMSTo,&apos; || Substr(aSQL, b + 6);
			end if;
		end if;

		sInfo := PKG_ALERTE.SETINFOTEXT(vCodAlerta,pAn,pLuna);
		SELECT seq_alerta_info_rulare.nextval INTO idx_rulare FROM dual;
		tmpName := &apos;TMP_Alert_&apos;||VCODALERTA||&apos;_&apos;||idx_rulare;
		IF aTipAlerta = 0 then
			if Nvl(FTip, 0) = 1 then --xlsx
				FName := ClearExt(FName);
				FNAme := FName||&apos;.XLSX&apos;;
			elsif Nvl(FTip, 0) = 2 then
				FName := ClearExt(FName);
				FNAme := FName||&apos;.HTML&apos;;
			else
				if not PKG_Alerte.IsHTML(FName) then FNAme := FName||&apos;.XLSX&apos;; end if;
			end if;
			if Nvl(fFields,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
				if Nvl(fOrd,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
					fOrd := &apos; order by &apos; || fOrd;
				end if;
				IF pkg_list_Struct.TmpExists(tmpName) = 1 THEN
					EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName;
					EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName;
				END IF;
				IF pkg_list_Struct.TmpExists(tmpName||&apos;1&apos;) = 1 THEN
					EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName||&apos;1&apos;;
					EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName||&apos;1&apos;;
				END IF;
				sDDL := &apos;Create table &apos;||tmpname||&apos; as
				(select RowNum Cod, X.* from (
						 select distinct Nvl(SMSTo,&apos;&apos;?&apos;&apos;) SMSTo, Nvl(MailTo,&apos;&apos;?&apos;&apos;) MailTo, Nvl(TaskTo,&apos;&apos;?&apos;&apos;) TaskTo, Nvl(MessTo,&apos;&apos;?&apos;&apos;) MessTo from (&apos;||aSQL||&apos;))x )&apos;;
				EXECUTE IMMEDIATE sDDL;
				sDDl := &apos;Create table &apos;||tmpname||&apos;1 as (
					select m.Cod, X.* from
						(select *
						 from (&apos;||aSQL||&apos;))x
						 inner join &apos;||tmpname||&apos; m on m.SMSTo = Nvl(x.SMSTo,&apos;&apos;?&apos;&apos;) and m.MailTo = Nvl(x.MailTo,&apos;&apos;?&apos;&apos;) and m.TaskTo = Nvl(x.TaskTo,&apos;&apos;?&apos;&apos;) and m.MessTo = Nvl(x.MessTo,&apos;&apos;?&apos;&apos;))&apos;;
	--      insert into x(view_name,Test) values (VCODALERTA||&apos;,&apos;||IDX_RULARE, sDDl);
				EXECUTE IMMEDIATE sDDL;
				Commit;
	--      xSQL := &apos;Select  &apos;||fFields||&apos; from (&apos;||TmpName||&apos;1)&apos;;
				xSQL := &apos;Select &apos;||FFields||&apos; from (&apos;||TmpName||&apos;1)&apos;;
				sSelect :=&apos;
				declare
					Xls blob;
					MySQL clob;
					xSQL  clob;
					Coloane varchar2(1000);
					Tabela clob;
					A varchar2(100);
					B varchar2(100);
				begin
					for X in (select distinct COD, SMSTo, MailTo, TaskTo, MessTo from &apos;||TmpName||&apos;) loop
						if PKG_Alerte.IsHTML(&apos;&apos;&apos;||FName||&apos;&apos;&apos;) then
							Tabela := &apos;&apos;&apos;&apos;;
							Tabela := Tabela || &apos;&apos;&lt;HTML&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;HEAD&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;TITLE&gt;&apos;|| ClearExt(FName) ||&apos;&lt;/TITLE&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;/HEAD&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;BODY&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;H1&gt;&apos;||ClearExt(FName)||&apos;&lt;/H1&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;TABLE BORDER=&quot;1 &quot;&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;TR&gt;&lt;TH&gt;&apos; || Replace(fFields, &apos;,&apos;, &apos;&lt;/TH&gt;&lt;TH&gt;&apos;) || &apos;&lt;/TH&gt;&lt;/TR&gt;&apos;&apos;|| utl_tcp.CRLF;
							for Y in (Select * from &apos;||TmpName||&apos;1 where COD = X.COD &apos;||FOrd||&apos; )
							loop
								Tabela := Tabela || &apos;&apos;&lt;TR&gt;&apos;&apos;|| utl_tcp.CRLF;
								Tabela := Tabela || &apos; || PKG_Alerte.GetColoane(fFields) || &apos; || utl_tcp.CRLF;
								Tabela := Tabela || &apos;&apos;&lt;/TR&gt;&apos;&apos;|| utl_tcp.CRLF;
							end loop;
							Tabela := Tabela || &apos;&apos;&lt;/TABLE&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;/BODY&gt;&apos;&apos;|| utl_tcp.CRLF;
							Tabela := Tabela || &apos;&apos;&lt;/HTML&gt;&apos;&apos;|| utl_tcp.CRLF;

							INSERT INTO ALERTE_INFO(codalertainfo,codalerta,codrulare,dataexec,INFO_FILTRE, SMSTo, MailTo, TaskTo, MessTo, rezultat)
							Values (seq_alerte_CodAlerta.nextval,&apos;||VCODALERTA||&apos;,&apos;||Idx_RULARE||&apos;,SYSDATE,&apos;&apos;&apos;||sInfo||&apos;&apos;&apos;,X.SMSTo , X.MailTo , X.MessTo,X.TaskTo, Tabela);
						else
							ORA_EXCEL.new_document;
							ORA_EXCEL.set_1900_date_system;
							ORA_EXCEL.add_sheet(&apos;&apos;&apos;||ClearExt(FName)||&apos;&apos;&apos;);
							ORA_EXCEL.set_column_width(&apos;&apos;A&apos;&apos;, 25);
							ORA_EXCEL.set_column_width(&apos;&apos;B&apos;&apos;, 25);
							ORA_EXCEL.set_column_width(&apos;&apos;C&apos;&apos;, 25);
							ORA_EXCEL.set_column_width(&apos;&apos;D&apos;&apos;, 25);
							ORA_EXCEL.set_column_width(&apos;&apos;E&apos;&apos;, 25);
							ORA_EXCEL.set_column_width(&apos;&apos;F&apos;&apos;, 25);
							ORA_EXCEL.query_to_sheet(Pkg_Alerte.GetSQLForExcell(&apos;&apos;&apos;||xSQL||&apos;&apos;&apos;, &apos;&apos;&apos;||FOrd||&apos;&apos;&apos;, X.Cod));
							ORA_EXCEL.save_to_Blob(Xls);

							INSERT INTO ALERTE_INFO(codalertainfo,codalerta,codrulare,dataexec,INFO_FILTRE, SMSTo, MailTo, TaskTo, MessTo, rezultat, FileName, FileBody)
							Values (seq_alerte_CodAlerta.nextval,&apos;||VCODALERTA||&apos;,&apos;||Idx_RULARE||&apos;,SYSDATE,&apos;&apos;&apos;||sInfo||&apos;&apos;&apos;,X.SMSTo , X.MailTo , X.MessTo,X.TaskTo, pkg_alerte.g_RezultatAlerta, &apos;&apos;&apos;||FName||&apos;&apos;&apos;, XLS);
						end if;

						pkg_alerte.g_RezultatAlerta := &apos;&apos;&apos;&apos;;
						for Y in (Select * from &apos;||TmpName||&apos;1 where COD = X.COD)
						loop
							pkg_alerte.g_RezultatAlerta := pkg_alerte.g_RezultatAlerta||Y.REZULTAT||&apos;&apos;|&apos;&apos;;
						end loop;
					end loop;
				end;&apos;;
			else
				sSelect :=
					&apos;begin &apos;||
					&apos;for X in (select distinct SMSTo, MailTo, TaskTo, MessTo from (&apos;||aSQL||&apos;)) loop pkg_alerte.g_RezultatAlerta := &apos;&apos;&apos;&apos;;&apos;||
					&apos;  for Y in (Select * from (&apos;||aSQL||&apos;) where Nvl(SMSTo,&apos;&apos;?&apos;&apos;) = Nvl(X.SMSTo,&apos;&apos;?&apos;&apos;) and Nvl(MailTo,&apos;&apos;?&apos;&apos;) = Nvl(X.MailTo,&apos;&apos;?&apos;&apos;) and Nvl(MessTo,&apos;&apos;?&apos;&apos;) = Nvl(X.MessTo,&apos;&apos;?&apos;&apos;) and Nvl(TaskTo,&apos;&apos;?&apos;&apos;) = Nvl(X.TaskTo,&apos;&apos;?&apos;&apos;))&apos;||
					&apos;  loop  pkg_alerte.g_RezultatAlerta := pkg_alerte.g_RezultatAlerta||Y.REZULTAT||&apos;&apos;|&apos;&apos;; end loop;&apos;||
					&apos;  INSERT INTO ALERTE_INFO(codalertainfo,codalerta,codrulare,dataexec,INFO_FILTRE, SMSTo, MailTo, TaskTo, MessTo, rezultat)&apos;||
					&apos;  Values (seq_alerte_CodAlerta.nextval,&apos;||VCODALERTA||&apos;,&apos;||IDX_RULARE||&apos;,SYSDATE,&apos;&apos;&apos;||sInfo||&apos;&apos;&apos;,X.SMSTo , X.MailTo , X.MessTo,X.TaskTo, pkg_alerte.g_RezultatAlerta );&apos;||
					&apos;end loop; end;&apos;;
			end if;
			Delete x;
			INSERT into X(view_name, test) values(VCODALERTA||&apos;_&apos;||IDX_RULARE,sSelect);
			COMMIT;
			EXECUTE IMMEDIATE sSELECT;
			COMMIT ;

			IF pkg_list_Struct.TmpExists(tmpName) = 1 THEN
				EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName;
				EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName;
			END IF;
			IF pkg_list_Struct.TmpExists(tmpName||&apos;1&apos;) = 1 THEN
				EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName||&apos;1&apos;;
				EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName||&apos;1&apos;;
			END IF;

			pkg_alerte.MailAlert(vCodAlerta ,idx_rulare );
			pkg_alerte.postMesagerie(vCodAlerta ,idx_rulare );
			pkg_alerte.postTask(vCodAlerta ,idx_rulare );
			pkg_alerte.postSMS(vCodAlerta ,idx_rulare );
		ELSE
			sSelect := &apos;&apos;;
			if aCUSTOMMESSAGE &lt;&gt; empty_clob() then
				sSelect := &apos;DECLARE &apos;||aCUSTOMMESSAGE;
			end if;
			if aCUSTOMFOOTER &lt;&gt; empty_clob() then
				sSelect := sSelect||
					&apos;BEGIN &apos;;
				if (Instr(aCUSTOMFOOTER, &apos;%SQL%&apos;) &gt; 0) then
					aCUSTOMFOOTER := Replace(aCUSTOMFOOTER, &apos;%SQL%&apos;, &apos;&apos;&apos;&apos;||aSQL||&apos;&apos;&apos;&apos;);
					aSQL :=  empty_clob();
				end if;
				sSelect := sSelect||
					aCUSTOMFOOTER||
					&apos;END;&apos;;
							insert into X(view_name, test) values(VCODALERTA||&apos;_&apos;||IDX_RULARE,sSelect);commit;
				EXECUTE IMMEDIATE sSelect;
			end if;
			if aSql &lt;&gt; empty_clob() then
				EXECUTE IMMEDIATE aSQL;
			end if;

			sSelect := &apos;INSERT INTO ALERTE_INFO(codalertainfo,codalerta,codrulare,dataexec,INFO_FILTRE, REZULTAT)&apos;||
								 &apos;SELECT seq_alerte_CodAlerta.nextval,&apos;||VCODALERTA||&apos;,&apos;||IDX_RULARE||&apos;,SYSDATE,&apos;&apos;&apos;||sInfo||&apos;&apos;&apos;,&apos;||&apos;&apos;&apos;Update count:&apos;||sql%rowcount||&apos;&apos;&apos; from dual&apos;;
      EXECUTE IMMEDIATE SSELECT;
      COMMIT ;
      PKG_Globals.SetSeparator(PKG_GLOBALS.SEP);
    end if;
  end if; --not WebServer
END;

procedure postSMS(aCodAlerta in number, aCodRulare in number) is
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  MSG_EROARE VARCHAR2(100);
  n number;
begin
  for v_rec in ( select a0.USERNAME, a0.USERID, a0.Tel, ai.rezultat, ai.info_filtre
                 from alerte0 a0
                 inner join alerte_info ai on ai.codalerta = a0.codalerta
                 where ai.codrulare = aCodRulare
                 and nvl(a0.SMS,0) = 1
                 and Nvl(Tel, &apos;?&apos;) &lt;&gt; &apos;?&apos;)
  loop
    aRezultat := v_rec.rezultat ;
    aMesaj := substr(replace(aRezultat,&apos;|&apos;,chr(13)||chr(10)),1,4000);
    n := PKG_SMS.SEND_SMS_full(  v_rec.Tel,
                                 aMESAJ,
                                 &apos;Alerta&apos;,
                                 0,0,0,1,
                                 MSG_EROARE);

  end loop;
  postSMS_AI(aCodAlerta,aCodRulare);
end;

procedure postSMS_AI(aCodAlerta in number, aCodRulare in number) is
  aRezultat varchar2(32000);
  aMesaj varchar2(32000);
  MSG_EROARE VARCHAR2(100);
  n number;
  b number;
begin
  for x_rec in (select distinct ai.SMSto from alerte_info ai where ai.codrulare = aCodRulare and Nvl(ai.SMSto, &apos;?&apos;) &lt;&gt; &apos;?&apos;) loop
    aRezultat := null;
    for v_rec in
      (  select ai.rezultat, ai.info_filtre, ai.SMSto
         from alerte_info ai
         where ai.codrulare = aCodRulare and ai.SMSto = x_rec.SMSto  and ai.rezultat is not null)
    loop
      aRezultat := v_rec.rezultat ;
      LOOP
        b := Coalesce(Instr(aRezultat, &apos;|&apos;), 0);
        IF b &gt; 0 THEN
          aMesaj    := Substr(aRezultat, 1, b-1);
          aRezultat := Substr(aRezultat, b + 1);
          n := PKG_SMS.SEND_SMS_full(x_rec.SMSTo, aMESAJ,
                                       &apos;Alerta&apos;,
                                       0,0,0,1,
                                       MSG_EROARE);
        ELSE
          IF aRezultat IS NOT NULL THEN
            aMesaj    := aRezultat;
            aRezultat := NULL;
            n := PKG_SMS.SEND_SMS_full(x_rec.SMSTo, aMESAJ,
                                       &apos;Alerta&apos;,
                                       0,0,0,1,
                                       MSG_EROARE);
          END IF;
        END IF;
        EXIT WHEN ((b = 0)or(ARezultat IS NULL));
      END LOOP;
    end loop;
  end loop;
  commit;
end;

end pkg_alerte;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_AMBALAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F75EFB1F14BB4C060CFC9B6968A963E5F7D6CF8C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_AMBALAJE IS

FUNCTION  LOCK_AMBALAJEDELEGAT( aDelegat IN NUMBER,
                                aSubunit IN NUMBER,
                                aAllData IN BOOLEAN  DEFAULT TRUE,
                                aData    IN VARCHAR2 DEFAULT NULL, -- format &apos;dd.mm.yyyy&apos;
                                aAllTime IN BOOLEAN  DEFAULT TRUE,
                                aOraIni  IN VARCHAR2 DEFAULT NULL, -- format &apos;HH24:MI&apos;
                                aOraFin  IN VARCHAR2 DEFAULT NULL  -- format &apos;HH24:MI&apos;
                              ) RETURN VARCHAR2 IS
  vNrDoc     Comanda.NrDoc%TYPE;
  vUserIDB   Comanda.UserIDBlocaj%TYPE;
  vData      DATE;
  vAllData   INTEGER         := 1;
  vAllTime   INTEGER         := 1;
  vOraIni    VARCHAR2(5)     := Nvl(aOraIni,&apos;00:00&apos;);
  vOraFin    VARCHAR2(5)     := Nvl(aOraFin,&apos;23:59&apos;);
  lOraError  varchar2(2000)  := &apos;&apos;;
  RES_BUSY   exception;
  pragma exception_init(RES_BUSY, -54);
BEGIN
  UNLOCK_AMBALAJEDELEGAT;

  BEGIN
    vData := To_Date(aData,&apos;dd.mm.yyyy&apos;);
    IF NOT aAllData THEN vAllData := 0; END IF;
  EXCEPTION
    WHEN OTHERS THEN vData := SYSDATE;
  END;
  IF NOT aAllTime THEN vAllTime := 0; END IF;

  FOR v_rec IN
    (
      SELECT DISTINCT C.CodComanda
      FROM Comanda C INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
      WHERE C.TipDoc = 57 AND C.Anulat = 0 AND C.Operat = 1
        AND C.Subunitatea = aSubunit
        AND C.Delegat = aDelegat
        AND C1.RestAcceptat &lt;&gt; 0
        AND (vAllData = 1 OR c.datadoc = vData)
        AND (vAllTime = 1 OR To_Char(c.datacreare,&apos;HH24:MI&apos;) &gt;= vOraIni)
        AND (vAllTime = 1 OR To_Char(c.datacreare,&apos;HH24:MI&apos;) &lt;= vOraFin)
    )
  LOOP
    BEGIN
      SELECT NrDoc, NVL(UserIDBlocaj, 0) UserIDBlocaj
      INTO vNrDoc, vUserIDB
      FROM Comanda
      WHERE CodComanda = v_rec.CodComanda
      FOR UPDATE NOWAIT;

      IF vUserIDB &lt;&gt; 0 AND vUserIDB &lt;&gt; PKG_GLOBALS.UserID THEN
        RAISE RES_BUSY;
      END IF;

      UPDATE Comanda
      SET UserIDBlocaj = PKG_GLOBALS.UserID
      WHERE CodComanda = v_rec.CodComanda;

      INSERT INTO TMP_AMBDELEGAT(
        CODCOMANDA, TIPDOC, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC, MONEDA, DELEGAT, AGENT,
        CODLOCATIE, CODFISCAL, SUBUNITATEA, FARATRANSPORT, SCADENTAV, OBS, SEDIU, SIMB_MON, REZOLVAT,
        TIPCUSTODIE,
        PARTENER,
        DEN_PART,
        DenAgent,
        TIPIES,
        TipOrig,
        CodOrig,
        DocOrig,
        CodPartTr
      )
      SELECT
        C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.NRDOC, C.CARNETDOC, C.SERIADOC, C.DATADOC, C.MONEDA, C.DELEGAT, C.AGENT,
        C.CODLOCATIE, C.CODFISCAL, C.SUBUNITATEA, C.FARATRANSPORT, C.SCADENTAV, C.OBS, A.OBS, M.SIMBOL, 0,
        CASE WHEN Nvl(C.SUBUNITSURSA,0) &lt;&gt; 0 THEN 3              WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN 2          ELSE 1          END,
        CASE WHEN Nvl(C.SUBUNITSURSA,0) &lt;&gt; 0 THEN C.SUBUNITSURSA WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN C.CODGEST  ELSE C.PARTENER END,
        CASE WHEN Nvl(C.SUBUNITSURSA,0) &lt;&gt; 0 THEN S.DEN_SUBUNIT  WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN G.DEN_GEST ELSE P.DEN_PART END,
        AG.Nume||&apos; &apos;||AG.Prenume,
        0,
        /*CASE
          WHEN Nvl(C.SUBUNITSURSA,0) &lt;&gt; 0 THEN 23 -- Iesiri catre subunitati
          WHEN Nvl(C.CODGEST,0) &lt;&gt; 0      THEN 12 -- Nota de transfer
          WHEN A.SediuSocial IN (2,3,6,7) THEN 19 -- Facturi care clienti -- orice sediu care include facturare
          ELSE 20 -- Avize de Expeditie catre clienti -- practic restul tipurilor de sedii S.SediuSocial IN (1,4,5)
        END*/
        CASE WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN T.TipDoc    ELSE I.TipDoc END,
        CASE WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN T.CodTransf ELSE I.CodIes END,
        CASE
          WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN T.PrefixDoc||T.NrDoc||&apos;/&apos;||To_Char(T.DataDoc,&apos;dd.mm.yyyy&apos;)
          ELSE I.PrefixDoc||I.NrDoc||&apos;/&apos;||To_Char(I.DataDoc,&apos;dd.mm.yyyy&apos;)
        END,
        D.CODPARTTR
      FROM COMANDA C
        LEFT JOIN NPART P    ON P.CODPART    = C.PARTENER
        LEFT JOIN NPERS AG   ON AG.CodPers   = C.AGENT
        LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = C.SUBUNITSURSA
        LEFT JOIN NGEST G    ON G.CODGEST    = C.CODGEST
        LEFT JOIN NAGENDA A  ON A.CODAGENDA  = C.CODLOCATIE
        LEFT JOIN NMONEDE M  ON M.CODMONEDA  = C.MONEDA
        LEFT JOIN IESIRI I   ON I.CODIES     = C.CODIES
        LEFT JOIN TRANSF T   ON T.CODTRANSF  = C.CODIES
        LEFT JOIN NPARTTR D  ON D.CODPERS    = C.DELEGAT
      WHERE CodComanda = v_rec.CodComanda;

      INSERT INTO TMP_AMBDELEGAT1(
        CODCOMANDA1, CODCOMANDA, CODOBIECT, DENOBIECT, UMSEC, DENUM,
        CANTCOMANDAT, CANTRETURNAT, ORIGRETURNAT,
        CANTACCEPTAT, RESTACCEPTAT, TEMPACCEPTAT,
        CANTFACTURAT,
        PRETORIG, PU, PROCDISC, ADDIM, OBS, SCADENTA, VALOARE,
        PARITATE, CODARTICOL, TERMENPLATA, RELATIEUM1, RELATIEUM2,
        PROCTVA)
      SELECT
        C1.CODCOMANDA1, C1.CODCOMANDA, C1.CODOBIECT, O.DENUMIRE, C1.UMSEC, U1.DEN_UM1,
        C1.CANTCOMANDAT / U1.PARITATE, C1.CANTRETURNAT / U1.PARITATE, C1.CANTRETURNAT / U1.PARITATE,
        C1.CANTACCEPTAT / U1.PARITATE, C1.RESTACCEPTAT / U1.PARITATE, C1.CANTACCEPTAT / U1.PARITATE,
        (C1.CANTACCEPTAT - C1.RESTACCEPTAT) / U1.PARITATE,
        C1.PRETORIG * U1.PARITATE, C1.PU * U1.PARITATE, C1.PROCDISC, C1.ADDIM, C1.OBS, C1.SCADENTA, C1.PU * C1.CANTACCEPTAT,
        U1.PARITATE, O.CODARTICOL, O.TERMENPLATA, A.RELATIEUM1, A.RELATIEUM2,
        PKG_SELECTARTICOLE.GETPROCENTTVA(O.CodArticol, PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU)
      FROM COMANDA1 C1
        INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
        INNER JOIN NUM1 U1 ON U1.CODUM1 = C1.UMSEC
        INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      WHERE CodComanda = v_rec.CodComanda
        AND C1.RestAcceptat &lt;&gt; 0;
    EXCEPTION
      WHEN RES_BUSY THEN lOraError := lOraError || to_char(vNrDoc) || &apos;, &apos;;
    END;

  END LOOP;

  UPDATE TMP_AMBDELEGAT A
  SET A.REST_TOT = (SELECT Sum(Abs(A1.RESTACCEPTAT)) FROM TMP_AMBDELEGAT1 A1 WHERE A1.CodComanda = A.CodComanda);

  COMMIT;

  RETURN lOraError;

END;

PROCEDURE UNLOCK_AMBALAJEDELEGAT IS
  tmp_recid number(20);
  RES_BUSY exception;
  pragma exception_init(RES_BUSY, -54);
BEGIN

  FOR v_rec IN ( SELECT CodComanda FROM TMP_AMBDELEGAT )
  LOOP
    BEGIN
      SELECT CodComanda
      INTO tmp_recid
      FROM Comanda
      WHERE CodComanda = v_rec.CodComanda
      FOR UPDATE NOWAIT;

      UPDATE Comanda
      SET UserIDBlocaj = 0
      WHERE CodComanda = v_rec.CodComanda;
    EXCEPTION WHEN RES_BUSY THEN
      NULL;
    END;
  END LOOP;

  DELETE TMP_AMBDELEGAT;
  DELETE TMP_AMBDELEGAT1;

  COMMIT;

END;

PROCEDURE RETUR_AMBALAJEDELEGAT is
  tmp_recid NUMBER(20);
  vTotRez   NUMBER;
  vCodRez   NUMBER(20);
  vCantRet  NUMBER;
  vRestCom  NUMBER;
  vRestRez  NUMBER;
  RES_BUSY  exception;
  pragma exception_init(RES_BUSY, -54);
BEGIN

  FOR v_rec IN ( SELECT CodComanda FROM TMP_AMBDELEGAT )
  LOOP
    BEGIN
      SELECT CodComanda
      INTO tmp_recid
      FROM Comanda
      WHERE CodComanda = v_rec.CodComanda
      FOR UPDATE NOWAIT;

      FOR v_rec1 IN (
        SELECT CodComanda1, CantReturnat * Paritate CantReturnat
        FROM TMP_AMBDELEGAT1
        WHERE CODCOMANDA = tmp_recid
          AND Nvl(CantReturnat,0) &gt; Nvl(OrigReturnat,0)
          AND Nvl(RestAcceptat,0) &lt;&gt; 0
        )
      LOOP

        UPDATE COMANDA1 C1
        SET C1.CANTACCEPTAT = C1.CANTCOMANDAT - v_rec1.CantReturnat,
            C1.CANTRETURNAT = v_rec1.CantReturnat,
            C1.RESTACCEPTAT = C1.CANTCOMANDAT - v_rec1.CantReturnat -
              ( SELECT NVL(SUM(IL.CANT), 0)
                FROM IESLINK IL
                  LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                  LEFT JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                WHERE  IL.CODLINIECOMANDA = C1.CODCOMANDA1 AND II.OPERAT = 1 AND II.ANULAT = 0
              ) -
              ( SELECT NVL(SUM(IL.CANT), 0)
                FROM CMDLIVRLINK IL
                  LEFT JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                  LEFT JOIN COMANDA  II ON II.CODCOMANDA    = II1.CODCOMANDA
                WHERE IL.CODLINIECOMANDA = C1.CODCOMANDA1 AND II.OPERAT = 1 AND II.ANULAT = 0
              )
        WHERE CODCOMANDA1 = v_rec1.CodComanda1
        RETURNING C1.RESTACCEPTAT INTO vRestCom;

        IF    vRestCom = 0 THEN
          DELETE rezervats WHERE codcomanda1 = v_rec1.CodComanda1;
        ELSIF vRestCom &lt; 0 THEN
          SELECT Min(CodRezervats) INTO vCodRez FROM Rezervats WHERE codcomanda1 = v_rec1.CodComanda1;
          DELETE rezervats WHERE CodRezervats &lt;&gt; vCodRez AND codcomanda1 = v_rec1.CodComanda1;
          UPDATE rezervats
          SET --CantRezervat = vRestCom,
              Rest         = vRestCom
          WHERE codrezervats = vCodRez;
        ELSE
          DELETE rezervats WHERE codcomanda1 = v_rec1.CodComanda1 AND rest = 0;
          SELECT Nvl(Sum(rest),0) INTO vTotRez FROM rezervats WHERE codcomanda1 = v_rec1.CodComanda1;

          WHILE vTotRez &gt; vRestCom
          LOOP
            SELECT Max(CodRezervats) INTO vCodRez FROM rezervats WHERE codcomanda1 = v_rec1.CodComanda1;
            SELECT Rest INTO vRestRez FROM rezervats WHERE codrezervats = vCodRez;

            IF vTotRez - vRestCom &gt;= vRestRez THEN
              DELETE rezervats WHERE codrezervats = vCodRez;
              vTotRez := vTotRez - vCodRez;
            ELSE
              UPDATE rezervats
              SET --CantRezervat = vRestRez - vTotRez + vRestCom,
                  Rest         = vRestRez - vTotRez + vRestCom
              WHERE codrezervats = vCodRez;
              vTotRez := vRestCom;
            END IF;
          END LOOP;
        END IF;
      END LOOP;

    EXCEPTION
      WHEN RES_BUSY THEN NULL;
    END;
  END LOOP;

  UPDATE TMP_AMBDELEGAT1 TC1
  SET
    (   TC1.CANTCOMANDAT,
        TC1.CANTRETURNAT,
        TC1.ORIGRETURNAT,
        TC1.CANTACCEPTAT,
        TC1.TEMPACCEPTAT,
        TC1.RESTACCEPTAT
    ) =
    (
      SELECT
        C1.CANTCOMANDAT / TC1.PARITATE,
        C1.CANTRETURNAT / TC1.PARITATE,
        C1.CANTRETURNAT / TC1.PARITATE,
        C1.CANTACCEPTAT / TC1.PARITATE,
        C1.CANTACCEPTAT / TC1.PARITATE,
        C1.RESTACCEPTAT / TC1.PARITATE
      FROM COMANDA1 C1
      WHERE C1.CodComanda1 = TC1.CodComanda1
    )
  WHERE TC1.CANTRETURNAT &lt;&gt; TC1.ORIGRETURNAT;

  UPDATE TMP_AMBDELEGAT
  SET REZOLVAT = 1
  WHERE CODCOMANDA IN ( SELECT CodComanda
                        FROM (
                          SELECT CodComanda, Sum(RestAcceptat) Rest, Sum(Nvl(CantReturnat,0)) CRet, Sum(Nvl(OrigReturnat,0)) ORet
                          FROM TMP_AMBDELEGAT1
                          GROUP BY CodComanda
                        )
                        WHERE Rest = 0 AND CRet = ORet);

  COMMIT;

END;

PROCEDURE ACT_REZ_AMBDELEGAT IS
BEGIN

  UPDATE TMP_AMBDELEGAT TC
  SET OK_REZERVATS = 1;

  UPDATE TMP_AMBDELEGAT TC
  SET OK_REZERVATS = 0
  WHERE CODCOMANDA IN (
    SELECT DISTINCT CODCOMANDA FROM (
      SELECT TC1.CODCOMANDA, CASE WHEN Max(TC1.RESTACCEPTAT) &gt; Sum(Nvl(REST,0)) THEN 1 ELSE 0 END LIPSA
      FROM TMP_AMBDELEGAT1 TC1 LEFT JOIN REZERVATS R ON R.CODCOMANDA1 = TC1.CODCOMANDA1
      WHERE TC1.RESTACCEPTAT &gt; 0
      GROUP BY TC1.CODCOMANDA, TC1.CODCOMANDA1)
    WHERE LIPSA = 1);

  COMMIT;

END;


END PKG_AMBALAJE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AC36A882343F721807350ADB6056E44D0131705</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ANALIZA IS

vCodANALIZA number(20);

function GetCodANALIZA return number is
begin
  return vCodANALIZA;
end;

procedure SetCodANALIZA(aCodANALIZA in number) is
begin
  vCodANALIZA := aCodANALIZA;
end;

PROCEDURE  SaveBugete( RecId IN NUMBER, aAN in NUMBER, aLUNA1 in NUMBER, aLUNA2 in NUMBER, Tip in number  ) IS
begin
--  delete from XBUGETANALIZA;
--  insert into XBUGETANALIZA select * from tmp_bugetanaliza ;

  Update tmp_bugetanaliza set CodAnalizaNod = null where CodAnalizaNod = 0;
  Update tmp_bugetanaliza set CodCentru = null where CodCentru = 0;
  if Tip = 0 then
    delete from BUGETANALIZA BA WHERE BA.CODANALIZA = RecId AND BA.An = aAn and BA.LUNA BETWEEN aLUNA1 AND aLUNA2 AND CodElement is null;
    for v_rec in ( select * from tmp_bugetanaliza) loop
        if Nvl(v_rec.B1, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 1, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B1);
        end if;
        if Nvl(v_rec.B2, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 2, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B2);
        end if;
        if Nvl(v_rec.B3, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 3, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B3);
        end if;
        if Nvl(v_rec.B4, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 4, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B4);
        end if;
        if Nvl(v_rec.B5, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 5, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B5);
        end if;
        if Nvl(v_rec.B6, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 6, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B6);
        end if;
        if Nvl(v_rec.B7, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 7, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B7);
        end if;
        if Nvl(v_rec.B8, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 8, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B8);
        end if;
        if Nvl(v_rec.B9, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 9, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B9);
        end if;
        if Nvl(v_rec.B10, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 10, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B10);
        end if;
        if Nvl(v_rec.B11, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 11, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B11);
        end if;
        if Nvl(v_rec.B12, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 12, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B12);
        end if;
    end loop;
  elsif Tip = 1 then
    delete from BUGETANALIZA BA WHERE BA.CODANALIZA = RecId AND BA.An = aAn and BA.LUNA BETWEEN aLUNA1 AND aLUNA2 AND CodCentru is null;
    for v_rec in ( select * from tmp_bugetanaliza) loop
        if Nvl(v_rec.B1, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 1, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B1);
        end if;
        if Nvl(v_rec.B2, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 2, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B2);
        end if;
        if Nvl(v_rec.B3, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 3, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B3);
        end if;
        if Nvl(v_rec.B4, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 4, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B4);
        end if;
        if Nvl(v_rec.B5, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 5, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B5);
        end if;
        if Nvl(v_rec.B6, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 6, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B6);
        end if;
        if Nvl(v_rec.B7, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 7, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B7);
        end if;
        if Nvl(v_rec.B8, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 8, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B8);
        end if;
        if Nvl(v_rec.B9, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 9, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B9);
        end if;
        if Nvl(v_rec.B10, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 10, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B10);
        end if;
        if Nvl(v_rec.B11, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 11, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B11);
        end if;
        if Nvl(v_rec.B12, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, aAn, 12, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B12);
        end if;
    end loop;
  elsif Tip = 2 then
    delete from BUGETANALIZA BA WHERE BA.CODANALIZA = 0 AND BA.An = aAn and BA.LUNA BETWEEN aLUNA1 AND aLUNA2 AND CodElement is null;
		for v_rec in ( select * from tmp_bugetanaliza) loop
        if Nvl(v_rec.B1, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 1, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B1);
        end if;
        if Nvl(v_rec.B2, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 2, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B2);
        end if;
        if Nvl(v_rec.B3, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 3, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B3);
        end if;
        if Nvl(v_rec.B4, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 4, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B4);
        end if;
        if Nvl(v_rec.B5, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 5, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B5);
        end if;
        if Nvl(v_rec.B6, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 6, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B6);
        end if;
        if Nvl(v_rec.B7, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 7, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B7);
        end if;
        if Nvl(v_rec.B8, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 8, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B8);
        end if;
        if Nvl(v_rec.B9, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 9, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B9);
        end if;
        if Nvl(v_rec.B10, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 10, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B10);
        end if;
        if Nvl(v_rec.B11, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 11, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B11);
        end if;
        if Nvl(v_rec.B12, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, An, Luna, CodAnalizaNod, CodCentru, Buget)
                      Values(RecID, aAn, 12, v_rec.Codanalizanod, v_rec.Codcentru, v_rec.B12);
        end if;
    end loop;
  elsif Tip = 9 then
    delete from BUGETANALIZA BA WHERE BA.Tip = 9 and BA.CODANALIZA = RecId AND BA.An = aAn and BA.LUNA BETWEEN aLUNA1 AND aLUNA2;
    for v_rec in 
			( 
			select b.* from tmp_bugetanaliza b 
			              inner join AnalizaNod n on n.codanalizanod = b.Codanalizanod 
			where (Nvl(n.Tip,0) = 2 and nvl(b.CodCentru,0) = 7) or (Nvl(n.Tip,0) &lt; 2 and nvl(b.CodCentru,0) = 0)
			) 
		loop
        if Nvl(v_rec.B1, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 1, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B1);
        end if;
        if Nvl(v_rec.B2, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 2, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B2);
        end if;
        if Nvl(v_rec.B3, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 3, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B3);
        end if;
        if Nvl(v_rec.B4, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 4, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B4);
        end if;
        if Nvl(v_rec.B5, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 5, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B5);
        end if;
        if Nvl(v_rec.B6, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 6, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B6);
        end if;
        if Nvl(v_rec.B7, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 7, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B7);
        end if;
        if Nvl(v_rec.B8, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 8, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B8);
        end if;
        if Nvl(v_rec.B9, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 9, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B9);
        end if;
        if Nvl(v_rec.B10, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 10, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B10);
        end if;
        if Nvl(v_rec.B11, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 11, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B11);
        end if;
        if Nvl(v_rec.B12, 0) &lt;&gt; 0.0 then
          insert into BUGETANALIZA ( CodAnaliza, Tip, An, Luna, CodAnalizaNod, CodElement, Buget)
                      Values(RecID, 9, aAn, 12, v_rec.Codanalizanod, v_rec.CodElement, v_rec.B12);
        end if;
    end loop;
  end if;
  commit;
end;

PROCEDURE  GetBugete( RecId IN NUMBER, aAN in NUMBER, aLUNA1 in NUMBER, aLUNA2 in NUMBER, Tip in number, aCodPlata in number  ) IS
S varchar2(200);
CC number;

  procedure RezolvaZero is
	begin
      INSERT INTO  TMP_BUGETANALIZA(COD, CODELEMENT, CODANALIZANOD, NODPARINTE, ZERO, CODCENTRU, Dencentru, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, Simbolcentru )
      SELECT  Rownum, 0, AN.CodAnalizaNod, AN.NODPARINTE, AN.Nivel-cca.NODMAXIMANALIZA1 , CC.CodCentru, CC.Denumire, 0,0,0,0,0,0,0,0,0,0,0,0,0, cc.simbol
      FROM ( 
        SELECT Level-1 Nivel, CodAnaliza, CodAnalizaNod, NODPARINTE
        FROM ANALIZANOD WHERE CodAnaliza = RecId
        START WITH NODPARINTE = 0 CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE) AN,
        CENTRECOST CC, CENTRECOSTa CCa
      WHERE CC.Codcentru = CCa.CodCentru
        AND CCa.CodAnaliza = recid
        AND (CC.codcentru = 0 OR AN.Nivel &lt;= CCa.NODMAXIMANALIZA1 );

      FOR v_cca IN (SELECT CodCentru, NodMaximAnaliza1+1 Nivel FROM CENTRECOSTa WHERE CodAnaliza = recid)
      LOOP
        FOR v_rec IN (
          SELECT X.CODAnalizaNOD, BA.CODCENTRU, Sum(BA.BUGET) TOTAL,
            Sum(Decode(BA.Luna, 1,BA.BUGET,0))  B1, Sum(Decode(BA.Luna, 2,BA.BUGET,0))  B2, Sum(Decode(BA.Luna, 3,BA.BUGET,0))  B3,
            Sum(Decode(BA.Luna, 4,BA.BUGET,0))  B4, Sum(Decode(BA.Luna, 5,BA.BUGET,0))  B5, Sum(Decode(BA.Luna, 6,BA.BUGET,0))  B6,
            Sum(Decode(BA.Luna, 7,BA.BUGET,0))  B7, Sum(Decode(BA.Luna, 8,BA.BUGET,0))  B8, Sum(Decode(BA.Luna, 9,BA.BUGET,0))  B9,
            Sum(Decode(BA.Luna,10,BA.BUGET,0)) B10, Sum(Decode(BA.Luna,11,BA.BUGET,0)) B11, Sum(Decode(BA.Luna,12,BA.BUGET,0)) B12
          FROM (
            SELECT CODAnalizaNOD, CONNECt_BY_ROOT CODAnalizaNOD CodRef
            FROM ANALIZANOD
            START WITH CODANALIZANOD IN (SELECT CodAnalizaNOD
              FROM ANALIZANOD
              WHERE CodAnaliza = recid
                AND LEVEL = v_cca.Nivel
              START WITH NODPARINTE = 0
              CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE)
            CONNECT BY PRIOR NODPARINTE = CODAnalizaNOD
          ) X INNER JOIN BUGETANALIZA BA ON BA.CodAnalizanod = X.CodRef
          WHERE BA.AN = aAN AND BA.Luna BETWEEN aLUNA1 AND aLUNA2
            AND BA.CodCentru = v_cca.CodCentru
          GROUP BY X.CODAnalizaNOD, BA.CODCENTRU
        ) LOOP

          UPDATE TMP_BUGETANALIZA
          SET
            TOTAL = v_rec.TOTAL,
            B1    = v_rec.B1,
            B2    = v_rec.B2,
            B3    = v_rec.B3,
            B4    = v_rec.B4,
            B5    = v_rec.B5,
            B6    = v_rec.B6,
            B7    = v_rec.B7,
            B8    = v_rec.B8,
            B9    = v_rec.B9,
            B10   = v_rec.B10,
            B11   = v_rec.B11,
            B12   = v_rec.B12
          WHERE CODANALIZANOD = v_rec.CODANALIZANOD
            AND CODCENTRU=v_rec.CODCENTRU;

        END LOOP;
      END LOOP;
	end;
	
	procedure RezolvaUnu is
	begin
      INSERT INTO  TMP_BUGETANALIZA(COD, CODCENTRU, CODANALIZANOD, NODPARINTE, ZERO, CODELEMENT, DENElement, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, dencentru )
      SELECT  Rownum, 0, AN.CodAnalizaNod, AN.NODPARINTE, AN.Nivel-ea.NODMAXIMANALIZA1 , E.Codelement, E.Den_Element , 0,0,0,0,0,0,0,0,0,0,0,0,0, e.simbol
      FROM ( 
        SELECT Level-1 Nivel, CodAnaliza, CodAnalizaNod, NODPARINTE
        FROM ANALIZANOD WHERE CodAnaliza = RecId
        START WITH NODPARINTE = 0 CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE) AN,
        ELEMENTE E, ELEMENTEa Ea
      where E.CodElement = Ea.CodElement
            AND ea.CodAnaliza = recid
            and (E.codElement = 0 or AN.Nivel &lt;= ea.NODMAXIMANALIZA1 );

      FOR v_cca IN (SELECT CodElement, NodMaximAnaliza1+1 Nivel FROM ELEMENTEa WHERE CodAnaliza = recid)
      LOOP
        FOR v_rec IN (
          SELECT X.CODAnalizaNOD, BA.CODELEMENT, Sum(BA.BUGET) TOTAL,
            Sum(Decode(BA.Luna, 1,BA.BUGET,0))  B1, Sum(Decode(BA.Luna, 2,BA.BUGET,0))  B2, Sum(Decode(BA.Luna, 3,BA.BUGET,0))  B3,
            Sum(Decode(BA.Luna, 4,BA.BUGET,0))  B4, Sum(Decode(BA.Luna, 5,BA.BUGET,0))  B5, Sum(Decode(BA.Luna, 6,BA.BUGET,0))  B6,
            Sum(Decode(BA.Luna, 7,BA.BUGET,0))  B7, Sum(Decode(BA.Luna, 8,BA.BUGET,0))  B8, Sum(Decode(BA.Luna, 9,BA.BUGET,0))  B9,
            Sum(Decode(BA.Luna,10,BA.BUGET,0)) B10, Sum(Decode(BA.Luna,11,BA.BUGET,0)) B11, Sum(Decode(BA.Luna,12,BA.BUGET,0)) B12
          FROM (
            SELECT CODAnalizaNOD, CONNECt_BY_ROOT CODAnalizaNOD CodRef
            FROM ANALIZANOD
            START WITH CODANALIZANOD IN (SELECT CodAnalizaNOD
              FROM ANALIZANOD
              WHERE CodAnaliza = recid
                AND LEVEL = v_cca.Nivel
              START WITH NODPARINTE = 0
              CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE)
            CONNECT BY PRIOR NODPARINTE = CODAnalizaNOD
          ) X INNER JOIN BUGETANALIZA BA ON BA.CodAnalizanod = X.CodRef
          WHERE BA.AN = aAN AND BA.Luna BETWEEN aLUNA1 AND aLUNA2
            AND BA.CodElement = v_cca.CodElement
          GROUP BY X.CODAnalizaNOD, BA.CODElement
        ) LOOP

          UPDATE TMP_BUGETANALIZA
          SET
            TOTAL = v_rec.TOTAL,
            B1    = v_rec.B1,
            B2    = v_rec.B2,
            B3    = v_rec.B3,
            B4    = v_rec.B4,
            B5    = v_rec.B5,
            B6    = v_rec.B6,
            B7    = v_rec.B7,
            B8    = v_rec.B8,
            B9    = v_rec.B9,
            B10   = v_rec.B10,
            B11   = v_rec.B11,
            B12   = v_rec.B12
          WHERE CODANALIZANOD = v_rec.CODANALIZANOD
            AND CODElement=v_rec.CODElement;

        END LOOP;
      END LOOP;
	end;
		
	procedure RezolvaDoi is
	begin
      INSERT INTO  TMP_BUGETANALIZA(COD, CODELEMENT, DENELEMENT, CODANALIZANOD, NODPARINTE, ZERO, CODCENTRU, Dencentru, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, simbolcentru)
      SELECT  CC.CodCentru, null, CC.DOMENIU, null, null, null, CC.CodCentru, CC.Denumire, 0,0,0,0,0,0,0,0,0,0,0,0,0, cc.simbol
      FROM CENTRECOST CC where CC.CodCentru &gt; 0;

			FOR v_rec IN (
				SELECT BA.CODCENTRU, Sum(BA.BUGET) TOTAL,
					Sum(Decode(BA.Luna, 1,BA.BUGET,0))  B1, Sum(Decode(BA.Luna, 2,BA.BUGET,0))  B2, Sum(Decode(BA.Luna, 3,BA.BUGET,0))  B3,
					Sum(Decode(BA.Luna, 4,BA.BUGET,0))  B4, Sum(Decode(BA.Luna, 5,BA.BUGET,0))  B5, Sum(Decode(BA.Luna, 6,BA.BUGET,0))  B6,
					Sum(Decode(BA.Luna, 7,BA.BUGET,0))  B7, Sum(Decode(BA.Luna, 8,BA.BUGET,0))  B8, Sum(Decode(BA.Luna, 9,BA.BUGET,0))  B9,
					Sum(Decode(BA.Luna,10,BA.BUGET,0)) B10, Sum(Decode(BA.Luna,11,BA.BUGET,0)) B11, Sum(Decode(BA.Luna,12,BA.BUGET,0)) B12
				FROM BUGETANALIZA BA
				WHERE BA.AN = aAN AND BA.Luna BETWEEN aLUNA1 AND aLUNA2
				GROUP BY BA.CODCENTRU
			) LOOP

				UPDATE TMP_BUGETANALIZA
				SET
					TOTAL = v_rec.TOTAL,
					B1    = v_rec.B1,
					B2    = v_rec.B2,
					B3    = v_rec.B3,
					B4    = v_rec.B4,
					B5    = v_rec.B5,
					B6    = v_rec.B6,
					B7    = v_rec.B7,
					B8    = v_rec.B8,
					B9    = v_rec.B9,
					B10   = v_rec.B10,
					B11   = v_rec.B11,
					B12   = v_rec.B12
				WHERE CODCENTRU=v_rec.CODCENTRU;
			END LOOP;
	end;
	
  procedure PrepareBuget(aZero in number, aCod in number, Label in varchar2, CC in number) is
	begin
      INSERT INTO  TMP_BUGETANALIZA(
			       COD, CODCENTRU, CodElement, DENElement, CODANALIZANOD, NODPARINTE, 
			       ZERO, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12 )
      SELECT  Rownum, aCod, 0, Label, CODANALIZANOD, NODPARINTE, 
			       aZero, 0,0,0,0,0,0,0,0,0,0,0,0,0
			       FROM Tmp_Bugetanaliza where CODCENTRU = CC; 
	end;
	
BEGIN
    delete from TMP_BUGETANALIZA;
		if Tip = 0 then RezolvaZero; elsif tip = 1 then RezolvaUnu; elsif tip = 2 then RezolvaDoi;
		elsif tip = 9 then
      Delete Tmp_Analizanod_Ref;  
      insert into Tmp_Analizanod_Ref (CODAnalizaNOD, Tip, CodRef)
        SELECT CODAnalizaNOD, 1, CONNECt_BY_ROOT CODAnalizaNOD CodRef
          FROM ANALIZANOD
          START WITH CODANALIZANOD IN (SELECT CodAnalizaNOD
            FROM ANALIZANOD A
            WHERE CodAnaliza = RecID and Nvl(tip, 0) in (0,1)
                  and (select Count(*) from TMP_BUGETANALIZA X where X.NodParinte = A.CodAnalizaNod) = 0
            START WITH NODPARINTE = 0
            CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE)
          CONNECT BY PRIOR NODPARINTE = CODAnalizaNOD;
      insert into Tmp_Analizanod_Ref (CODAnalizaNOD, Tip, CodRef)
        SELECT CODAnalizaNOD, 2, CONNECt_BY_ROOT CODAnalizaNOD CodRef
          FROM ANALIZANOD
          START WITH CODANALIZANOD IN (SELECT CodAnalizaNOD
            FROM ANALIZANOD A
            WHERE CodAnaliza = RecID and Nvl(tip, 0) in (0,2)
                  and (select Count(*) from TMP_BUGETANALIZA X where X.NodParinte = A.CodAnalizaNod) = 0
            START WITH NODPARINTE = 0
            CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE)
          CONNECT BY PRIOR NODPARINTE = CODAnalizaNOD;

      INSERT INTO  TMP_BUGETANALIZA(
             COD, CODCENTRU, CodElement, DENElement, CODANALIZANOD, NODPARINTE, 
             ZERO, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12 )
      SELECT Rownum, 0, 0, &apos;c.0.Credit aprobat&apos;, AN.CodAnalizaNod, AN.NODPARINTE, 
             AN.Nivel,0,0,0,0,0,0,0,0,0,0,0,0,0
      FROM ( 
        SELECT 1 Nivel, CodAnaliza, CodAnalizaNod, NODPARINTE
        FROM ANALIZANOD WHERE CodAnaliza = RecID and Nvl(tip, 0) in (0,1)
        START WITH NODPARINTE = 0 CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE) AN;

      INSERT INTO  TMP_BUGETANALIZA(
             COD, CODCENTRU, CodElement, DENElement, CODANALIZANOD, NODPARINTE, 
             ZERO, Total, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12 )
      SELECT Rownum, 7, 0, &apos;v.0.Venituri planificate&apos;, AN.CodAnalizaNod, AN.NODPARINTE, 
             AN.Nivel,0,0,0,0,0,0,0,0,0,0,0,0,0
      FROM ( 
        SELECT 1 Nivel, CodAnaliza, CodAnalizaNod, NODPARINTE
        FROM ANALIZANOD WHERE CodAnaliza = RecID and Nvl(tip, 0) in (0,2)
        START WITH NODPARINTE = 0 CONNECT BY PRIOR CODAnalizaNOD = NODPARINTE) AN;


			update TMP_BUGETANALIZA A set ZERO = (select Count(*) from TMP_BUGETANALIZA X where X.NodParinte = A.CodAnalizaNod);
 	    update TMP_BUGETANALIZA A set Total=0, B1=0, B2=0, B3=0, B4=0, B5=0, B6=0, B7=0, B8=0, B9=0, B10=0, B11=0, B12=0
		  where ZERO &gt; 0;
      PrepareBuget(1, 1, &apos;c.1.Credit rectificat&apos;,0); 
      PrepareBuget(1, 2, &apos;c.2.Angajamente bugetare&apos;,0); 
      PrepareBuget(1, 3, &apos;c.3.Angajamente legale&apos;,0); 
      PrepareBuget(1, 4, &apos;c.4.Ordonantari&apos;,0);
		  PrepareBuget(1, 5, &apos;c.5.Plati efective&apos;,0);
      PrepareBuget(1, 6, &apos;c.6.Cheltuieli efectuate&apos;,0);
      PrepareBuget(1, 8, &apos;v.1.Venituri rectificate&apos;,7); 
			PrepareBuget(1, 9, &apos;v.2.Venituri facturate&apos;,7); 
		  PrepareBuget(1,10, &apos;v.3.Incasari efective&apos;,7); 
		  --buget=credit
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD,
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
				  SELECT BA.* from 
          BUGETANALIZA BA inner join AnalizaNod AN on AN.CodAnalizaNod = BA.CodAnalizaNod --and AN.Tip &lt; 2
				  WHERE BA.AN = aAN AND BA.Luna BETWEEN aLUNA1 AND aLUNA2
					AND BA.CodAnaliza = recid
					AND BA.Tip = 9 AND NOT EXISTS (SELECT A.CODANALIZANOD FROM ANALIZANOD A WHERE A.NODPARINTE = BA.CODANALIZANOD)
				 ) BA ON BA.CodAnalizanod = X.CodRef
        where X.Tip &lt; 2
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 0;

  			UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 1;
			END LOOP; --buget=credit
			--rectificari buget
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VCredit Buget--, R1.VANGAJAPROB, R1.VANGAJREAL, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VCredit,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VCredit Buget--,  -R1.VANGAJAPROB, -R1.VANGAJREAL, -R1.VPLATAAPROB, -R1.Vplatareal, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VCredit,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
        --where X.Tip &lt; 2
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 1;

			END LOOP; --rectificari buget

--      &apos;2.Angajamente bugetare&apos;, 
			--comenzi
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select C1.CodAnalizanod, C.Luna, C1.PU*C1.Cantacceptat*Nvl(C.Curs,1) Buget  
					from Comanda1 C1 
							 inner join Comanda C    on C.CodComanda = C1.CodComanda 
							 inner join AnalizaNod N on N.CodAnalizaNod = C1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE C.An = aAn and C.Operat = 1
								AND C.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 2;

			END LOOP; --comenzi
			--rectificari ang bugetare
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VANGAJAPROB Buget--, R1.VANGAJREAL, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VANGAJAPROB,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VANGAJAPROB Buget--,  -R1.VANGAJREAL, -R1.VPLATAAPROB, -R1.Vplatareal, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VANGAJAPROB,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 2;

			END LOOP; --rectificari ang bugetare

--      &apos;3.Angajamente legale&apos;, 
			--Intrari
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, BA.IsChelt,
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select C1.CodAnalizanod, C.Luna, Case when C1.Tiplinie = &apos;S&apos; then 1 else 0 end IsChelt,  (C1.PU*C1.Cant + C1.TVA)*Nvl(C.Curs,1) Buget  
					from Intrari1 C1 
							 inner join Intrari C    on C.CodIntr = C1.CodIntr
							 inner join AnalizaNod N on N.CodAnalizaNod = C1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE C.An = aAn and C.Operat = 1
								AND C.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD, BA.IsChelt
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 3;
				if V_REC.IsChelt = 1 then 
					UPDATE TMP_BUGETANALIZA
				  SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
					WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 6;
        end if; 
			END LOOP; --intrari
			--rectificari ang real

			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VANGAJREAL Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VANGAJREAL,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VANGAJREAL Buget--,  -R1.VPLATAAPROB, -R1.Vplatareal, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VANGAJREAL,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 3;

			END LOOP; --rectificari ang real

      -- Ordonantari 
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 ( --aici ordonantari
					select O.CodAnalizanod, P.Luna, P1.Valoare*Nvl(P.Curs,1) Buget  
					from ObligPIF O 
							 inner join Plati1 P1   on P1.CodObligPIF = O.CodObligPIF
							 inner join Plati P     on P.Codplata = P1.Codplata 
							 inner join AnalizaNod N on N.CodAnalizaNod = O.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE P.An = aAn 
								AND P.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
          union all
					select p1.Codanalizanodx Codanalizanod, P.Luna, P1.Valoare*Nvl(P.Curs,1) Buget
					from Plati1 P1 
					     inner join Plati P on P.CodPlata = P1.CodPlata 
							 inner join AnalizaNod N on N.CodAnalizaNod = P1.CodAnalizaNodx
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE P.An = aAn 
					      AND P.Luna between aLuna1 and aLuna2 and P1.CodObligPIF in (0,1,2) and A.CodAnaliza = RecID --and A.Tip = 1
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 4;

			END LOOP; --ordonantari
			--rectificari ordonantari
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VPLATAAPROB Buget--, R1.VPLATAAPROB, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VPLATAAPROB,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VPLATAAPROB Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VPLATAAPROB,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 4;

			END LOOP; --rectificari ordonantari


--      &apos;5.Plati efective&apos;, 
			--plati
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 ( --aici plati
					select O.CodAnalizanod, T.Luna, Case when (T1.TIPTRANZ = 1 and T1.OBIECTTRANZ = 1) then -1 else 1 end*O.Valoare*T1.Curs Buget  
					from ObligPIF O 
							 inner join General G    on G.CodGeneral = O.CodGeneral and G.Tipdoc in (29,30,31,33)
							 inner join Trezor1 T1   on T1.Codtrezor1 = G.Coddoc
							 inner join Trezor  T    on T.Codtrezor = T1.Codtrezor
							 inner join AnalizaNod N on N.CodAnalizaNod = O.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE T.An = aAn and T1.Anulat = 0 
								AND T.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
								AND ((T1.TIPTRANZ = 0 and T1.OBIECTTRANZ in (0,2,4,5)) or (T1.TIPTRANZ = 1 and T1.OBIECTTRANZ = 1))
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 5;

			END LOOP; --plati
			--rectificari plati
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.Vplatareal Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.Vplatareal,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.Vplatareal Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.Vplatareal,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 5;

			END LOOP; --rectificari plata real
--      &apos;6.Cheltuieli efectuate&apos;, 
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select O.CodAnalizanod, T.Luna, T1.ValDoc*T1.Curs Buget  
					from ObligPIF O 
							 inner join General G    on G.CodGeneral = O.CodGeneral and G.Tipdoc in (29,30,33)--,31)
							 inner join Trezor1 T1   on T1.Codtrezor1 = G.Coddoc and T1.TIPTRANZ = 0 and T1.OBIECTTRANZ in (4,5)
							 inner join Trezor  T    on T.Codtrezor = T1.Codtrezor
							 inner join AnalizaNod N on N.CodAnalizaNod = O.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE T.An = aAn and T1.Anulat = 0
								AND T.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
					union all
					select I1.CodAnalizanod, E.Luna, ((NS.Pret - NS.Adaos)*L1.Cant) Buget  
					from Livr1 L1
							 inner join Livr L    on L.CodLivr =  L1.CodLivr 
							 inner join Iesiri E  on E.CodIes = L.Codies
							 left  join NIRSTOC1 N1 on N1.CodNirStoc = L1.CodNirStoc
							 left  join NIRSTOC NS on NS.CodNirStoc = N1.CodNirStocOrig
							 left  join Intrari1 I1 on I1.CodIntr1 = NS.CodIntr1
							 inner join AnalizaNod N on N.CodAnalizaNod = I1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE E.An = aAn AND E.Luna BETWEEN aLUNA1 AND aLUNA2 and E.Operat = 1 
					      and A.CodAnaliza = RecID --and A.Tip = 1 
					      and E.TipDoc in (14, 19, 20, 21, 24)
					union all
					select I1.CodAnalizanod, E.Luna, -((NS.Pret - NS.Adaos)*L1.Cant) Buget  
					from Livr1 L1
							 inner join Livr L    on L.CodLivr =  L1.CodLivr 
							 inner join Iesiri E  on E.CodIes = L.Codies
							 left  join NIRSTOC1 N1 on N1.CodNirStoc = L1.CodNirStoc
							 left  join NIRSTOC NS on NS.CodNirStoc = N1.CodNirStocOrig
							 left  join Intrari1 I1 on I1.CodIntr1 = NS.CodIntr1
							 inner join AnalizaNod N on N.CodAnalizaNod = I1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE E.An = aAn AND E.Luna BETWEEN aLUNA1 AND aLUNA2 and E.Operat = 1 
					      and A.CodAnaliza = RecID --and A.Tip = 1 
					      and E.TipDoc = 15 and L1.Cant &lt; 0
					union all
					select L1.CodAnalizanod, L.Luna, L1.Valoare Buget  
					from NC1 L1
							 inner join NC L    on L.CodNC=  L1.CodNC and L.Sablon = 0
							 inner join NCont C    on C.Codcont =  L1.ContD and C.Tipcont &lt;&gt; 1 and C.Clasa = 6
							 inner join AnalizaNod N on N.CodAnalizaNod = L1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE L.An = aAn AND L.Luna BETWEEN aLUNA1 AND aLUNA2 
					      and A.CodAnaliza = RecID --and A.Tip = 1 
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 6;

			END LOOP; --chelt
			--rectificari chelt
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VChelt Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VChelt,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VChelt Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VChelt,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 6;

			END LOOP; --rectificari chelt
			--7.Venituri planificate
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
				  SELECT BA.* from 
          BUGETANALIZA BA inner join AnalizaNod AN on AN.CodAnalizaNod = BA.CodAnalizaNod --and AN.Tip = 2
				  WHERE BA.AN = aAN AND BA.Luna BETWEEN aLUNA1 AND aLUNA2
					AND BA.CodAnaliza = recid
					AND BA.Tip = 9 AND NOT EXISTS (SELECT A.CODANALIZANOD FROM ANALIZANOD A WHERE A.NODPARINTE = BA.CODANALIZANOD)
				 ) BA ON BA.CodAnalizanod = X.CodRef
        where X.Tip = 2
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 7;
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 8;
			END LOOP; --Planificat
			--rectificari Planificat
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VPlanif Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VPlanif,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VPlanif Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VPlanif,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 8;
			END LOOP; --rectificari fact
--      8.Venituri facturate 
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 
				 (
					select C1.CodAnalizanod, C.Luna, (C1.PU*C1.Cant + C1.TVA)*Nvl(C.Curs,1) Buget  
					from Iesiri1 C1 
							 inner join Iesiri C    on C.CodIes = C1.CodIes
							 inner join AnalizaNod N on N.CodAnalizaNod = C1.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE C.An = aAn and C.Operat = 1
								AND C.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 9;
			END LOOP; --iesiri
			--rectificari fact
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VFact Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VFact,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VFact Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VFact,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 9;
			END LOOP; --rectificari fact
			--9. incasari efective
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 ( --aici incasari
					select O.CodAnalizanod, T.Luna, Case when (T1.TIPTRANZ = 0 and T1.OBIECTTRANZ = 1) then -1 else 1 end*O.Valoare*T1.Curs Buget  
					from ObligPIF O 
							 inner join General G    on G.CodGeneral = O.CodGeneral and G.Tipdoc in (29,30,31,33)
							 inner join Trezor1 T1   on T1.Codtrezor1 = G.Coddoc
							 inner join Trezor  T    on T.Codtrezor = T1.Codtrezor
							 inner join AnalizaNod N on N.CodAnalizaNod = O.CodAnalizaNod
							 inner join Analiza    A on A.CodAnaliza = N.CodAnaliza 
					WHERE T.An = aAn and T1.Anulat = 0 
								AND T.Luna BETWEEN aLUNA1 AND aLUNA2 and A.CodAnaliza = RecID --and A.Tip = 1 
								AND ((T1.TIPTRANZ = 1 and T1.OBIECTTRANZ in (0,2,4,5)) or (T1.TIPTRANZ = 0 and T1.OBIECTTRANZ = 1))
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=v_rec.B1,B2=v_rec.B2,B3=v_rec.B3,B4=v_rec.B4,B5=v_rec.B5,B6=v_rec.B6,B7=v_rec.B7,B8=v_rec.B8,B9=v_rec.B9,B10=v_rec.B10,B11=v_rec.B11,B12=v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 10;
			END LOOP; --incasari
			--rectificari incasari
			FOR v_rec IN 
			(	SELECT X.CODAnalizaNOD, 
					Sum(Decode(BA.Luna, 1,Nvl(BA.Buget,0),0))  B1, Sum(Decode(BA.Luna, 2,Nvl(BA.Buget,0),0))  B2, Sum(Decode(BA.Luna, 3,Nvl(BA.Buget,0),0))  B3,
					Sum(Decode(BA.Luna, 4,Nvl(BA.Buget,0),0))  B4, Sum(Decode(BA.Luna, 5,Nvl(BA.Buget,0),0))  B5, Sum(Decode(BA.Luna, 6,Nvl(BA.Buget,0),0))  B6,
					Sum(Decode(BA.Luna, 7,Nvl(BA.Buget,0),0))  B7, Sum(Decode(BA.Luna, 8,Nvl(BA.Buget,0),0))  B8, Sum(Decode(BA.Luna, 9,Nvl(BA.Buget,0),0))  B9,
					Sum(Decode(BA.Luna,10,Nvl(BA.Buget,0),0)) B10, Sum(Decode(BA.Luna,11,Nvl(BA.Buget,0),0)) B11, Sum(Decode(BA.Luna,12,Nvl(BA.Buget,0),0)) B12
				FROM 
				 Tmp_Analizanod_Ref X 
				 INNER JOIN  
				 (
					select Nvl(R1.CodNodDest,0) CodAnalizanod, R.LunaDest Luna, R1.VIncasreal Buget--, R1.VPLATAAPROB, R1.Vplatareal, R1.Vchelt  
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaDest BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VIncasreal,0) &gt; 0
					UNION ALL
					select Nvl(R1.CodNodSursa,0) CodAnalizanod, R.LunaSursa Luna, -R1.VIncasreal Buget--,  -R1.VPLATAAPROB, -R1.Vchelt 
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				  WHERE R.CodAnaliza = recid
					AND R.AN = aAN AND R.LunaSursa BETWEEN aLUNA1 AND aLUNA2
					and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VIncasreal,0) &gt; 0
				 ) BA  ON BA.CodAnalizanod  = X.CodRef
				GROUP BY X.CODAnalizaNOD
			) LOOP
				UPDATE TMP_BUGETANALIZA
				SET B1=B1+v_rec.B1,B2=B2+v_rec.B2,B3=B3+v_rec.B3,B4=B4+v_rec.B4,B5=B5+v_rec.B5,B6=B6+v_rec.B6,B7=B7+v_rec.B7,B8=B8+v_rec.B8,B9=B9+v_rec.B9,B10=B10+v_rec.B10,B11=B11+v_rec.B11,B12=B12+v_rec.B12				
				WHERE CODANALIZANOD = v_rec.CODANALIZANOD and CodCentru = 10;
			END LOOP; --rectificari incasari real
    update TMP_BUGETANALIZA set Total = B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12;
  end if;
  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodANALIZA INTO Tmp
  FROM ANALIZA
  WHERE CodANALIZA = RecId
  FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCodANALIZA number(20);
BEGIN
  SP_LOCKRECORD(RecId);

  DELETE ANALIZANOD WHERE CODANALIZA = RecId;
  DELETE ANALIZA1   WHERE CODANALIZA = RecId;
  DELETE ANALIZA    WHERE CodANALIZA = RecId;

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_ANALIZA(CodANALIZA) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  INSERT INTO  TMP_ANALIZA (CODANALIZA, DEN_ANALIZA, Inactiv, Tip, IDELEMENT, IDCENTRU)
  SELECT A.CODANALIZA, A.DEN_ANALIZA, A.Inactiv, A.Tip, A.IDELEMENT, A.IDCENTRU
  FROM ANALIZA A
  WHERE A.CodANALIZA = RecId ;

  INSERT INTO  TMP_ANALIZA1 ( CODANALIZA1, CODANALIZA, CODDESCRIPTOR, INDEXLOCAL, DEN_DESCRIPTOR)
  SELECT A1.CODANALIZA1, A1.CODANALIZA, A1.CODDESCRIPTOR, A1.INDEXLOCAL, D.DEN_DESCRIPTOR
  FROM ANALIZA1 A1
    INNER JOIN DESCRIPTORI D ON D.CODDESCRIPTOR = A1.CODDESCRIPTOR
  WHERE A1.CodANALIZA = RecId ;

  INSERT INTO  TMP_ANALIZANOD (
    CODANALIZANOD, CODANALIZA, NODPARINTE, CODANALIZA1, CODDESCRIPTOR1,
    INDEXLOCAL, POZITIE, INACTIV, SIMBOLNOD, DenNod, Tip,
    DEN_DESCRIPTOR, 
		VAL_DESCRIPTOR1,
    CODASOCIAT, DEN_ASOCIAT, SIMBOL)
  SELECT
    AN.CODANALIZANOD, AN.CODANALIZA, AN.NODPARINTE, AN.CODANALIZA1, AN.CODDESCRIPTOR1,
    ROW_NUMBER() OVER (ORDER BY AN.CODANALIZANOD ASC), AN.POZITIE, AN.INACTIV, AN.SIMBOLNOD, AN.DenNod, AN.Tip,
    D.DEN_DESCRIPTOR, 
		Decode(Nvl(AN.NodPArinte,0),0,A.DEN_ANALIZA, NVL(D1.VALOARE, substr(AN.SimbolNod||&apos;=&apos;||AN.DenNod, 1, 150))),
    D1.CODASOCIAT, Decode(Nvl(AN.NodPArinte,0),0,A.DEN_ANALIZA, PKG_DESCRIPTORI.GetDenAsociat(D.Tip, D1.CODASOCIAT)),
    X.IND
  FROM ANALIZA A
    INNER JOIN ANALIZANOD AN ON AN.CODANALIZA = A.CODANALIZA
    LEFT  JOIN (SELECT CodAnalizaNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;0&apos;),&apos;.&apos;) IND
                FROM AnalizaNod START WITH NODPARINTE = 0 CONNECT BY PRIOR CODANALIZANOD = NODPARINTE) X on x.CodAnalizaNod = AN.CodAnalizaNod
    LEFT  JOIN ANALIZA1 A1 ON A1.CODANALIZA1 = AN.CODANALIZA1
    LEFT  JOIN DESCRIPTORI D ON D.CODDESCRIPTOR = A1.CODDESCRIPTOR
    LEFT  JOIN DESCRIPTORI1 D1 ON D1.CODDESCRIPTOR1 = AN.CODDESCRIPTOR1
  WHERE AN.CODANALIZA = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 vCOD      NUMBER(20);
 NR        NUMBER(20);
 IDX       NUMBER(20)  := 0;
BEGIN

  Select Count(*) into NR from TMP_Analiza1; 
	if NR = 0 then 
    Select Count(*) into NR from TMP_AnalizaNod; 
		if NR = 0 then 
			vCod := 0; 
		else 
			vCod := 1; 
		end if;
	else 
		vCod := 0; 
	end if;
  update TMP_Analiza set Tip = vCod;
	
  FOR V_REC IN (SELECT CodAnalizaNod FROM TMP_ANALIZANOD WHERE CodAnalizaNod &lt;= 0 ORDER BY IndexLocal) LOOP
    SELECT SEQ_ANALIZANOD_CODANALIZANOD.NEXTVAL INTO vCOD FROM DUAL;
    UPDATE TMP_ANALIZANOD SET NodParinte    = vCod WHERE NodParinte    = v_rec.CodAnalizaNod;
    UPDATE TMP_ANALIZANOD SET CodAnalizaNod = vCod WHERE CodAnalizaNod = v_rec.CodAnalizaNod;
  END LOOP;

  IF Operation = 0 THEN  -- UPDATE
    SELECT CodANALIZA INTO RecId FROM TMP_ANALIZA;

    UPDATE ANALIZA
    SET (CODANALIZA, DEN_ANALIZA, Inactiv, Tip, IDELEMENT, IDCENTRU) = (SELECT CODANALIZA, DEN_ANALIZA, Inactiv, Tip, IDELEMENT, IDCENTRU FROM TMP_ANALIZA)
    WHERE CodANALIZA = RecID;

    DELETE ANALIZANOD WHERE CodANALIZA = RecID AND CodAnalizaNod not in (SELECT CodAnalizaNod FROM TMP_ANALIZANOD);
    DELETE ANALIZA1   WHERE CodANALIZA = RecID AND CodAnaliza1   not in (SELECT CodAnaliza1   FROM TMP_ANALIZA1);

    FOR V_REC IN (SELECT CODANALIZA1, CODANALIZA, CODDESCRIPTOR FROM TMP_ANALIZA1 ORDER BY IndexLocal)
    LOOP
      IDX := IDX + 1;
      IF v_rec.CODANALIZA1 &gt; 0 THEN
        UPDATE ANALIZA1
        SET CODANALIZA    = v_rec.CODANALIZA,
            CODDESCRIPTOR = v_rec.CODDESCRIPTOR,
            INDEXLOCAL    = IDX
        WHERE CODANALIZA1 = v_rec.CODANALIZA1;
      ELSE
        SELECT SEQ_ANALIZA1_CODANALIZA1.NEXTVAL INTO vCod FROM DUAL;
        INSERT INTO ANALIZA1 (CODANALIZA1, CODANALIZA, CODDESCRIPTOR, INDEXLOCAL)
        VALUES (vCod, RecID, v_rec.CODDESCRIPTOR, IDX);

        UPDATE TMP_ANALIZANOD SET CodAnaliza1 = vCod WHERE CodAnaliza1 = v_rec.CODANALIZA1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_ANALIZANOD)
    LOOP
      SELECT NVL(COUNT(1), 0) INTO NR FROM ANALIZANOD WHERE CODANALIZANOD = V_REC.CODANALIZANOD;
      IF NR &gt; 0 THEN
        UPDATE ANALIZANOD
        SET CODANALIZA      = v_rec.CODANALIZA,
            NODPARINTE      = v_rec.NODPARINTE,
            CODANALIZA1     = v_rec.CODANALIZA1,
            CODDESCRIPTOR1  = v_rec.CODDESCRIPTOR1,
            POZITIE         = v_Rec.POZITIE,
            INACTIV         = v_Rec.INACTIV,
						SIMBOLNOD       = v_Rec.SIMBOLNOD,
						DenNod          = v_Rec.DenNod,
						Tip             = v_Rec.Tip
        WHERE CODANALIZANOD = v_rec.CODANALIZANOD;
      ELSE
        INSERT INTO ANALIZANOD (CODANALIZANOD, CODANALIZA, NODPARINTE, CODANALIZA1, CODDESCRIPTOR1, POZITIE, INACTIV,SIMBOLNOD,DenNod, Tip)
        VALUES (v_rec.CODANALIZANOD, RecID, v_rec.NODPARINTE, v_rec.CODANALIZA1, v_rec.CODDESCRIPTOR1, v_rec.POZITIE, v_rec.INACTIV, v_rec.SIMBOLNOD, v_rec.DenNod, v_rec.Tip);
      END IF;
    END LOOP;

  ELSE  -- INSERT

    SELECT SEQ_ANALIZA_CODANALIZA.NextVal INTO RecId FROM DUAL;
    INSERT INTO ANALIZA (CODANALIZA, DEN_ANALIZA, Inactiv, Tip, IDELEMENT, IDCENTRU) SELECT RecId, DEN_ANALIZA, Inactiv, Tip, IDELEMENT, IDCENTRU FROM TMP_ANALIZA;
    FOR V_REC IN (SELECT CODANALIZA1, CODANALIZA, CODDESCRIPTOR FROM TMP_ANALIZA1 ORDER BY IndexLocal )
    LOOP
      IDX := IDX + 1;
      SELECT SEQ_ANALIZA1_CODANALIZA1.NEXTVAL INTO vCod FROM DUAL;
      INSERT INTO ANALIZA1 (CODANALIZA1, CODANALIZA, CODDESCRIPTOR, INDEXLOCAL)
      VALUES (vCod, RecID, v_rec.CODDESCRIPTOR, IDX);

      UPDATE TMP_ANALIZANOD SET CodAnaliza1 = vCod WHERE CodAnaliza1 = v_rec.CODANALIZA1;
    END LOOP;

    INSERT INTO ANALIZANOD (CODANALIZANOD, CODANALIZA, NODPARINTE, CODANALIZA1, CODDESCRIPTOR1, POZITIE, INACTIV,SIMBOLNOD,DenNod, Tip)
    SELECT CODANALIZANOD, RecID, NODPARINTE, CODANALIZA1, CODDESCRIPTOR1, POZITIE, INACTIV,SIMBOLNOD,DenNod, Tip FROM TMP_ANALIZANOD;
  END IF;

  NotifyModif(Operation, RecId, &apos;ANALIZA&apos;);
  COMMIT;
END;

procedure RectificareSintetice is
aVal number(20,7);  
begin
  for v_rec in (select * 
                from bugetanaliza
                where tip = 9) loop
    aVal := GetValSintetic(v_rec.codanalizanod, v_rec.an, v_rec.luna, v_rec.codcentru, v_rec.codelement, v_rec.tip);
    update bugetanaliza set buget = aVal 
    where codanalizanod = v_rec.codanalizanod and an = v_rec.an and luna = v_rec.luna and nvl(codcentru,0) = nvl(v_rec.codcentru,0)
          and nvl(codelement,0) = nvl(v_rec.codelement,0) and tip = v_rec.tip;
    COMMIT;      
  end loop;
end;  

function GetValSintetic(aCodAnalizaNod in number, aAn in number, aLuna in number, aCodCentru in number, aCodElement in number, aTip in number) return number is
aCount number(10);  
aVal number(20,7);
begin
  select count(*) into aCount from analizanod where nodparinte = aCodAnalizaNod;
  if aCount = 0 then
    select buget into aVal from bugetanaliza 
    where codanalizanod = acodanalizanod and an = aan and luna = aluna and nvl(codcentru,0) = nvl(acodcentru,0)
          and nvl(codelement,0) = nvl(acodelement,0) and tip = atip;
  else
    aVal := 0;
    for v_rec in (select b.*
                  from bugetanaliza b
                       inner join analizanod a on b.codanalizanod = a.codanalizanod
                  where a.nodparinte = aCodAnalizaNod and
                        b.an = aan and b.luna = aluna and nvl(b.codcentru,0) = nvl(acodcentru,0)
                        and nvl(b.codelement,0) = nvl(acodelement,0) and b.tip = atip
                 ) loop
      aVal := aVal + GetValSintetic(v_rec.CodAnalizaNod, v_rec.An, v_rec.Luna, v_rec.CodCentru, v_rec.CodElement, v_rec.Tip);
    end loop;                    
  end if;
  return aVal;
end;  

procedure TestBugete is
begin
  GetBugete(116, 2014, 1, 12, 0,0 );
  commit;
  SaveBugete(116, 2014, 1, 12, 0 );
end;

END PKG_ANALIZA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ASIGURARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04F3DE15E8C574230A1B2922F7B278A3EC7F8E58</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ASIGURARI is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_62&apos;;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodAsigurare INTO Tmp FROM ASIGURARI WHERE CodAsigurare = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);  
BEGIN
  SP_LOCKRECORD(RecId);
  
  SELECT A.DATASTART, A.SUBUNITATEA, A.NRDOC||&apos;/&apos;||To_Char(A.DATASTART,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(A.TERMEN,&apos;dd.mm.yyyy&apos;)
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM ASIGURARI A
  WHERE CODASIGURARE = RecID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
  THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;ASIGURARI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE FROM ASIGURARI1 WHERE CodAsigurare = RecId;
  DELETE FROM ASIGURARI WHERE CodAsigurare = RecId;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_ASIGURARI(CodAsigurare) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_ASIGURARI(CODASIGURARE, NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, SUBUNITATEA, USERID, AN, LUNA, VALOARE)
  SELECT CODASIGURARE, NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, SUBUNITATEA, USERID, AN, LUNA, VALOARE
  FROM ASIGURARI 
  WHERE CODASIGURARE = RECID;
  
  INSERT INTO TMP_ASIGURARI1(CODASIGURARE1, CODASIGURARE, INDEXLOCAL, CODMIFIX, VALASIG, 
    DENUMIRE, NRINVENTAR, VALMF, CODOBIECT)
  SELECT A1.CODASIGURARE1, A1.CODASIGURARE, A1.INDEXLOCAL, A1.CODMIFIX, A1.VALASIG,
    OBJ.DENUMIRE, MFIX.NRINVENTAR, MFIX1.PRET, NS.CODOBIECT
  FROM ASIGURARI1 A1
    INNER JOIN MIFIX MFIX ON MFIX.CODMIFIX = A1.CODMIFIX
    INNER JOIN MIFIX1 MFIX1 ON MFIX1.CODMIFIX = MFIX.CODMIFIX
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MFIX1.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT   
  WHERE A1.CODASIGURARE = RECID 
        AND MFIX1.ANSTART*12+MFIX1.LUNASTART = (SELECT MAX(M2.ANSTART*12+M2.LUNASTART)
                                                FROM MIFIX1 M2 
                                                WHERE M2.CODMIFIX = A1.CODMIFIX);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);    
BEGIN
  SELECT A.DATASTART, A.SUBUNITATEA, A.NRDOC||&apos;/&apos;||To_Char(A.DATASTART,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(A.TERMEN,&apos;dd.mm.yyyy&apos;)
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM TMP_ASIGURARI A;
  
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodAsigurare INTO RecId FROM TMP_ASIGURARI;
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;ASIGURARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE ASIGURARI SET (NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, AN, LUNA, VALOARE)
    = (SELECT NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, AN, LUNA, VALOARE FROM TMP_ASIGURARI)
    WHERE CodAsigurare = RecId;
    
    DELETE FROM ASIGURARI1 AS1 WHERE AS1.CODASIGURARE = RECID AND NOT AS1.CODASIGURARE1 IN (SELECT CODASIGURARE1 FROM TMP_ASIGURARI1);
    FOR V_REC IN (SELECT * FROM TMP_ASIGURARI1) LOOP
      IF V_REC.CODASIGURARE1 &gt; 0 THEN
        UPDATE ASIGURARI1 SET
          INDEXLOCAL = V_REC.INDEXLOCAL,
          CODMIFIX   = V_REC.CODMIFIX,
          VALASIG    = V_REC.VALASIG
        WHERE CODASIGURARE1 = V_REC.CODASIGURARE1;
      ELSE 
        INSERT INTO ASIGURARI1 (CODASIGURARE1, CODASIGURARE, INDEXLOCAL, CODMIFIX, VALASIG)
        VALUES (SEQ_ASIGURARI1_CODASIGURARE1.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.CODMIFIX, V_REC.VALASIG); 
      END IF;
    END LOOP;
  ELSE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;ASIGURARI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
      
    SELECT SEQ_ASIGURARI_CODASIGURARE.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO ASIGURARI (CODASIGURARE, NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, SUBUNITATEA, USERID, DATACREARE, AN, LUNA, VALOARE)
    SELECT RECID, NRDOC, CODPART, DATASTART, TERMEN, CODCLASEMF, OBS, SUBUNITATEA, PKG_GLOBALS.GETUSERID, SYSDATE, AN, LUNA, VALOARE 
    FROM TMP_ASIGURARI;
    
    INSERT INTO ASIGURARI1 (CODASIGURARE1, CODASIGURARE, INDEXLOCAL, CODMIFIX, VALASIG)
    SELECT SEQ_ASIGURARI1_CODASIGURARE1.NEXTVAL, RECID, INDEXLOCAL, CODMIFIX, VALASIG
    FROM TMP_ASIGURARI1;
  END IF;
  COMMIT;
END;

end PKG_ASIGURARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BANCI_NIVNATIONAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D907CF1FCACDB3F2011B9F900D602E4BC3076D0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BANCI_NIVNATIONAL IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodBANK INTO Tmp FROM NBANK WHERE CodBANK = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc VARCHAR2(100);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;banca &apos;||N.DENUMIRE INTO aDoc
   FROM nbank n where N.CODBANK = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANK&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);  
END IF;  
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 528);
  SP_LOCKRECORD(RecId);
	DELETE FROM NBANK WHERE CodBANK = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NBANK FIELDS( CodBANK ) VALUES (0) ;  
  PKG_CFGTABLES.EXT_INSERTRECORD(528);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NBANK
  INSERT INTO  TMP_NBANK ( CodBANK,Denumire,Simbol, CODSWIFT, CODBNR )
    ( SELECT CodBANK,Denumire,Simbol, CODSWIFT, CODBNR
      FROM NBANK WHERE CodBANK = RecId ) ;
  PKG_CFGTABLES.EXT_GOTORECORD(528);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  
  aDoc VARCHAR2(100);
BEGIN
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (528);
  IF Operation = 0 THEN  -- UPDATE

-- Master NBANK
    SELECT  CodBANK INTO RecId FROM TMP_NBANK;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;banca &apos;||N.DENUMIRE INTO aDoc
   FROM TMP_nbank n where N.CODBANK = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANK&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);  
END IF;
   
    UPDATE NBANK SET ( Denumire,Simbol, CODSWIFT, CODBNR )
       = ( SELECT Denumire,Simbol, CODSWIFT, CODBNR
          FROM TMP_NBANK )
      WHERE CodBANK = RecId ;

  ELSE  -- INSERT
-- Master NBANK
  SELECT seq_NBANK_CodBANK.NextVal INTO RecId FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NBANK&apos;, RecId);
IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;banca &apos;||N.DENUMIRE INTO aDoc
   FROM TMP_nbank n ;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANK&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);  
END IF;


  INSERT INTO  NBANK ( CodBANK,Denumire,Simbol, CODSWIFT, CODBNR )
 ( SELECT  RecId ,Denumire,Simbol, CODSWIFT, CODBNR
     FROM TMP_NBANK  ) ;
  END IF;

  NotifyModif(Operation, RecId, &apos;NBANK&apos;);
  PKG_CFGTABLES.EXT_POSTRECORDS(528);
  COMMIT;

END;



END pkg_Banci_NivNational; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07FB4C6FAAA9BE9B45A272D274EE73B17D2015AB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BCAR IS

  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_43&apos;;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp          NUMBER(20);
BEGIN
  SELECT CodBCAR INTO Tmp FROM BCAR WHERE CodBCAR = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
  aCARNETDOC  NUMBER(20);
  aNRDOC      NUMBER(20);
  aDATADOC    DATE;
  aCodSubunit NUMBER(20);
  aDoc        VARCHAR2(200);
BEGIN
  SP_LOCKRECORD(RecId);
  -- mBonCantar --&gt;  67;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 67);
  SELECT CARNETDOC,  NRDOC,  DATADOC, CODSUBUNITATE, PREFIXDOC||NRDOC||&apos;/&apos;||To_Char(DATADOC,&apos;dd.mm.yyyy&apos;)
  INTO  aCARNETDOC, aNRDOC, aDataDoc, aCodSubunit,   aDoc
  FROM BCAR
  WHERE CODBCAR = RecID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BCAR&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

	DELETE FROM BCAR WHERE CodBCAR = RecId;

  -- anuleaza cantaririle asociate cu bonul sters
  --UPDATE CANTAR SET Anulat = 1 WHERE NVL(CodDoc1, 0) = RecId;

  -- elibereaza cantaririle asociate cu bonul sters
  UPDATE CANTAR
  SET TipDoc = null,
      CodDoc1 = null,
      UserIdBlocaj = null
  WHERE CodDoc1 = RecId AND
        UserIdBlocaj = PKG_GLOBALS.UserId;

  -- realoc numarul de document folosit
  PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_BCAR FIELDS(CodBCAR) VALUES (0);
  -- mBonCantar --&gt;  67;
  PKG_CFGTABLES.EXT_INSERTRECORD(67);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
aCodContract1 number(20);
BEGIN
  INSERT INTO TMP_BCAR
  (
    CodBCAR, Operat, CodCantarIn, CodCantarOut, TipDoc, CodDoc1,
    PrefixDoc, NrDoc, DataDoc, CarnetDoc,
    PrefixAvizIn, NrAvizIn, NrAvizOut, DataAvizIn,
    ISUmiditate, IAUmiditate,
    ISStraine, IAStraine,
    ISIncoltit, IAIncoltit,
    ISHectolitrica, IAHectolitrica,
    ISGluten, IAGluten,
    ISFuzaritate, IAFuzaritate,
    ISCadere, IACadere,
    ISDeformare, IADeformare,
    ISSticlozitate, IASticlozitate,
    ISSparturi, IASparturi,
    CodObiect, BrutKg, Tara, NetKg, UtilKg, PretAchiz, PretUscare,
    CodPartener, CodSediu, CodDelegat,
    CodSubunitate,
    UserID, DataCreare,
    CodSerie, Retur,
    ModCantar, TipBCAR,
    CodGestImpl, CodLocatImpl,
    Observatii,
    CodPers, MijlTransp, NrTransp, CodAuto,
    ICUmiditate,
    ICStraine,
    ICIncoltit,
    ICHectolitrica,
    ICGluten,
    ICFuzaritate,
    ICCadere,
    ICDeformare,
    ICSticlozitate,
    ICSparturi,
    NetKgClient, UtilKgClient,
    InfoClient,
    CodDoc1Storno,
    CodBCARDest,
    CodContract1,
    CodRemorca, NrRemorca, Document,
    NumeDelegat,
    InfoContract1,
    UtilStasKg,
    PretConfirmat,
    CodContract,
    TipContract,
    isproteina      ,
    isaflatoxina    ,
    isatac_plosnita ,
    iscontinut_ulei ,
    isaciditate     ,
    iaproteina      ,
    iaaflatoxina    ,
    iaatac_plosnita ,
    iacontinut_ulei ,
    iaaciditate     ,
    icproteina      ,
    icaflatoxina    ,
    icatac_plosnita ,
    iccontinut_ulei ,
    icaciditate,
    PRETLASTAS,
    IASISTAVE,
    IAREFRACTIE,
    IAINDICE_W,
    IATOXINA_DON,
    IABOABE_TOXICE,
    ISSISTAVE,
    ISREFRACTIE,
    ISINDICE_W,
    ISTOXINA_DON,
    ISBOABE_TOXICE,
    ICSISTAVE,
    ICREFRACTIE,
    ICINDICE_W,
    ICTOXINA_DON,
    ICBOABE_TOXICE,
    PIERDERITEH,
    Moneda,
    Curs,
    ID_CITIRE1,
    ID_CITIRE2
  )
  (
    SELECT
      B.CodBCAR, B.Operat, B.CodCantarIn, B.CodCantarOut,
      B.TipDoc,
      CASE
        WHEN B.TipDoc = 12 THEN T1.CodTransf1
        WHEN B.TipDoc &gt; 10 AND B.TIPDOC &lt;&gt; 12 THEN E1.CodIes1
        ELSE I1.CodIntr1
      END CodDoc1,
      B.PrefixDoc, B.NrDoc, B.DataDoc, B.CarnetDoc,
      B.PrefixAvizIn, B.NrAvizIn, B.NrAvizOut, B.DataAvizIn,
      B.ISUmiditate, B.IAUmiditate,
      B.ISStraine, B.IAStraine,
      B.ISIncoltit, B.IAIncoltit,
      B.ISHectolitrica, B.IAHectolitrica,
      B.ISGluten, B.IAGluten,
      B.ISFuzaritate, B.IAFuzaritate,
      B.ISCadere, B.IACadere,
      B.ISDeformare, B.IADeformare,
      B.ISSticlozitate, B.IASticlozitate,
      B.ISSparturi, B.IASparturi,
      B.CodObiect, B.BrutKg, B.Tara, B.NetKg, B.UtilKg, B.PretAchiz, B.PretUscare,
      B.CodPartener, B.CodSediu, B.CodDelegat,
      B.CodSubunitate,
      B.UserID, B.DataCreare,
      B.CodSerie, B.Retur,
      B.ModCantar, B.TipBCAR,
      B.CodGestImpl, B.CodLocatImpl,
      B.Observatii,
      B.CodPers, B.MijlTransp, B.NrTransp, B.CodAuto,
      B.ICUmiditate,
      B.ICStraine,
      B.ICIncoltit,
      B.ICHectolitrica,
      B.ICGluten,
      B.ICFuzaritate,
      B.ICCadere,
      B.ICDeformare,
      B.ICSticlozitate,
      B.ICSparturi,
      B.NetKgClient, B.UtilKgClient,
      B.InfoClient,
      B.CodDoc1Storno,
      B.CodBCARDest,
      B.CodContract1,
      B.CodRemorca, B.NrRemorca,
      CASE
        WHEN B.TipDoc = 12 THEN
					CASE
						WHEN B.CodDoc1 &gt; 0 THEN T.PrefixDoc || T.SeriaDoc || T.NrDoc || &apos; / &apos; || T.DataDoc
						ELSE &apos;?&apos;
					END
        WHEN B.TipDoc &gt; 10 AND B.TIPDOC &lt;&gt; 12 THEN
					CASE
						WHEN B.CodDoc1 &gt; 0 THEN E.PrefixDoc || E.SeriaDoc || E.NrDoc || &apos; / &apos; || E.DataDoc
						ELSE &apos;?&apos;
					END
        ELSE
					CASE
						WHEN B.CodDoc1 &gt; 0 THEN I.PrefixDoc || I.SeriaDoc || I.NrDoc || &apos; / &apos; || I.DataDoc
						ELSE &apos;?&apos;
					END
      END,
      D.Delegat,
      CASE
        WHEN B.CodContract1 &gt; 0 THEN C.NrDoc || &apos; / &apos; || C.DataStart
        ELSE &apos;?&apos;
      END,
      B.Utilstaskg,
      B.PretConfirmat,
      C.CodContract,
      C.TipDoc,
      B.isproteina      ,
      B.isaflatoxina    ,
      B.isatac_plosnita ,
      B.iscontinut_ulei ,
      B.isaciditate     ,
      B.iaproteina      ,
      B.iaaflatoxina    ,
      B.iaatac_plosnita ,
      B.iacontinut_ulei ,
      B.iaaciditate     ,
      B.icproteina      ,
      B.icaflatoxina    ,
      B.icatac_plosnita ,
      B.iccontinut_ulei ,
      B.icaciditate,
      CASE WHEN NVL(B.UTILSTASKG, 0) = 0 THEN 0
           ELSE ROUND(B.UTILKG * B.PRETACHIZ / B.UTILSTASKG, 6)
      END,
      B.IASISTAVE,
      B.IAREFRACTIE,
      B.IAINDICE_W,
      B.IATOXINA_DON,
      B.IABOABE_TOXICE,
      B.ISSISTAVE,
      B.ISREFRACTIE,
      B.ISINDICE_W,
      B.ISTOXINA_DON,
      B.ISBOABE_TOXICE,
      B.ICSISTAVE,
      B.ICREFRACTIE,
      B.ICINDICE_W,
      B.ICTOXINA_DON,
      B.ICBOABE_TOXICE,
      B.PIERDERITEH,
      B.MONEDA,
      B.CURS,
      B.ID_CITIRE1,
      B.ID_CITIRE2
    FROM BCAR B
    LEFT OUTER JOIN NPARTTR D ON D.CodPartTr = B.CodDelegat
    LEFT OUTER JOIN Contract1 C1 ON C1.CodContract1 = B.CodContract1
    LEFT OUTER JOIN CONTRACT C ON C.CodContract = C1.CodContract
    LEFT OUTER JOIN IESIRI1 E1 ON B.CodDoc1 = E1.CodIes1
    LEFT OUTER JOIN IESIRI E ON E.CodIes = E1.CodIes and E.Tipdoc = B.TipDoc
    LEFT OUTER JOIN Intrari1 I1 ON B.CodDoc1 = I1.CodIntr1
    LEFT OUTER JOIN Intrari I ON I.CodIntr = I1.CodIntr and I.Tipdoc = B.TipDoc
    LEFT OUTER JOIN TRANSF1 T1 ON B.CodDoc1 = T1.CodTRANSF1 AND B.TIPDOC = 12
    LEFT OUTER JOIN TRANSF T ON T.CodTRANSF = T1.CodTRANSF and T.Tipdoc = B.TipDoc
    WHERE B.CodBCAR = RecId
  );

  -- blocheaza cantaririle asociate cu bonul selectat
  UPDATE CANTAR
  SET UserIdBlocaj = PKG_GLOBALS.UserId
  WHERE CodDoc1 = RecId AND
        NVL(UserIdBlocaj, 0) = 0;

  begin
    select codcontract1 into acodcontract1 from tmp_bcar where rownum = 1;
  exception when others then aCodContract1 := 0;
  end;

  INSERT INTO TMP_CONTRACTXX (CODCONTRACTXX, CODCONTRACT1, PARAMETRU, VALSTART, VALSTOP, ABATERE, STARTPROC, STARTCORECTIE, PROC, CORECTIE, GENERARE)
  SELECT
    XX.CODCONTRACTXX, XX.CODCONTRACT1, XX.PARAMETRU, XX.VALSTART, XX.VALSTOP, XX.ABATERE, XX.STARTPROC, XX.STARTCORECTIE, XX.PROC, XX.CORECTIE, XX.GENERARE
  FROM CONTRACTXX xx
  WHERE CODCONTRACT1 = acodcontract1;
  -- mBonCantar --&gt;  67;
  PKG_CFGTABLES.EXT_GOTORECORD(67);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
  aCARNETDOC  INTEGER := 0;
  aNRDOC      INTEGER := 0;
  aDATADOC    DATE;
  aCodSubunit NUMBER(20);
  aDoc        VARCHAR2(200);
BEGIN

  SELECT CARNETDOC,  NRDOC,  DATADOC, CODSUBUNITATE, PREFIXDOC||NRDOC||&apos;/&apos;||To_Char(DATADOC,&apos;dd.mm.yyyy&apos;)
  INTO   aCARNETDOC, aNRDOC, aDataDoc, aCodSubunit,   aDoc
  FROM TMP_BCAR;
  -- mBonCantar --&gt;  67;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (67); 
  IF Operation = 0 THEN -- UPDATE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BCAR&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT CodBCAR INTO RecId FROM TMP_BCAR;

    UPDATE BCAR SET
    (
      Operat, CodCantarIn, CodCantarOut, TipDoc, CodDoc1,
      PrefixDoc, NrDoc, DataDoc, CarnetDoc,
      PrefixAvizIn, NrAvizIn, NrAvizOut, DataAvizIn,
      ISUmiditate, IAUmiditate,
      ISStraine, IAStraine,
      ISIncoltit, IAIncoltit,
      ISHectolitrica, IAHectolitrica,
      ISGluten, IAGluten,
      ISFuzaritate, IAFuzaritate,
      ISCadere, IACadere,
      ISDeformare, IADeformare,
      ISSticlozitate, IASticlozitate,
      ISSparturi, IASparturi,
      CodObiect, BrutKg, Tara, NetKg, UtilKg, PretAchiz, PretUscare,
      CodPartener, CodSediu, CodDelegat,
      CodSubunitate,
      UserID, DataCreare,
      CodSerie, Retur,
      ModCantar, TipBCAR,
      CodGestImpl, CodLocatImpl,
      Observatii,
      CodPers, MijlTransp, NrTransp, CodAuto,
      ICUmiditate,
      ICStraine,
      ICIncoltit,
      ICHectolitrica,
      ICGluten,
      ICFuzaritate,
      ICCadere,
      ICDeformare,
      ICSticlozitate,
      ICSparturi,
      NetKgClient, UtilKgClient,
      InfoClient,
      CodDoc1Storno,
      CodBCARDest,
      CodContract1,
      CodRemorca, NrRemorca, UtilStasKg,
      PretConfirmat,
      isproteina      ,
      isaflatoxina    ,
      isatac_plosnita ,
      iscontinut_ulei ,
      isaciditate     ,
      iaproteina      ,
      iaaflatoxina    ,
      iaatac_plosnita ,
      iacontinut_ulei ,
      iaaciditate     ,
      icproteina      ,
      icaflatoxina    ,
      icatac_plosnita ,
      iccontinut_ulei ,
      icaciditate,
      IASISTAVE,
      IAREFRACTIE,
      IAINDICE_W,
      IATOXINA_DON,
      IABOABE_TOXICE,
      ISSISTAVE,
      ISREFRACTIE,
      ISINDICE_W,
      ISTOXINA_DON,
      ISBOABE_TOXICE,
      ICSISTAVE,
      ICREFRACTIE,
      ICINDICE_W,
      ICTOXINA_DON,
      ICBOABE_TOXICE,
      PIERDERITEH,
      MONEDA,
      CURS,
      ID_CITIRE1,
      ID_CITIRE2
    ) =
    (
      SELECT
        Operat, CodCantarIn, CodCantarOut, TipDoc, CodDoc1,
        PrefixDoc, NrDoc, DataDoc, CarnetDoc,
        PrefixAvizIn, NrAvizIn, NrAvizOut, DataAvizIn,
        ISUmiditate, IAUmiditate,
        ISStraine, IAStraine,
        ISIncoltit, IAIncoltit,
        ISHectolitrica, IAHectolitrica,
        ISGluten, IAGluten,
        ISFuzaritate, IAFuzaritate,
        ISCadere, IACadere,
        ISDeformare, IADeformare,
        ISSticlozitate, IASticlozitate,
        ISSparturi, IASparturi,
        CodObiect, BrutKg, Tara, NetKg, UtilKg, PretAchiz, PretUscare,
        CodPartener, CodSediu, CodDelegat,
        CodSubunitate,
        UserID, DataCreare,
        CodSerie, Retur,
        ModCantar, TipBCAR,
        CodGestImpl, CodLocatImpl,
        Observatii,
        CodPers, MijlTransp, NrTransp, CodAuto,
        ICUmiditate,
        ICStraine,
        ICIncoltit,
        ICHectolitrica,
        ICGluten,
        ICFuzaritate,
        ICCadere,
        ICDeformare,
        ICSticlozitate,
        ICSparturi,
        NetKgClient, UtilKgClient,
        InfoClient,
        CodDoc1Storno,
        CodBCARDest,
        CodContract1,
        CodRemorca, NrRemorca, UtilStasKg,
        PretConfirmat,
        isproteina      ,
        isaflatoxina    ,
        isatac_plosnita ,
        iscontinut_ulei ,
        isaciditate     ,
        iaproteina      ,
        iaaflatoxina    ,
        iaatac_plosnita ,
        iacontinut_ulei ,
        iaaciditate     ,
        icproteina      ,
        icaflatoxina    ,
        icatac_plosnita ,
        iccontinut_ulei ,
        icaciditate,
        IASISTAVE,
        IAREFRACTIE,
        IAINDICE_W,
        IATOXINA_DON,
        IABOABE_TOXICE,
        ISSISTAVE,
        ISREFRACTIE,
        ISINDICE_W,
        ISTOXINA_DON,
        ISBOABE_TOXICE,
        ICSISTAVE,
        ICREFRACTIE,
        ICINDICE_W,
        ICTOXINA_DON,
        ICBOABE_TOXICE,
        PIERDERITEH,
        MONEDA,
        CURS,
        ID_CITIRE1,
        ID_CITIRE2
      FROM TMP_BCAR
    )
    WHERE CodBCAR = RecId;

    -- deblocheaza cantaririle asociate cu bonul editat
    UPDATE CANTAR
    SET UserIdBlocaj = Null
    WHERE CodDoc1 = RecId AND
          UserIdBlocaj = PKG_GLOBALS.UserId;

  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BCAR&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT SEQ_BCAR_CODBCAR.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;BCAR&apos;, RecId);
    INSERT INTO BCAR
    (
      CodBCAR, Operat, CodCantarIn, CodCantarOut, TipDoc, CodDoc1,
      PrefixDoc, NrDoc, DataDoc, CarnetDoc,
      PrefixAvizIn, NrAvizIn, NrAvizOut, DataAvizIn,
      ISUmiditate, IAUmiditate,
      ISStraine, IAStraine,
      ISIncoltit, IAIncoltit,
      ISHectolitrica, IAHectolitrica,
      ISGluten, IAGluten,
      ISFuzaritate, IAFuzaritate,
      ISCadere, IACadere,
      ISDeformare, IADeformare,
      ISSticlozitate, IASticlozitate,
      ISSparturi, IASparturi,
      CodObiect, BrutKg, Tara, NetKg, UtilKg, PretAchiz, PretUscare,
      CodPartener, CodSediu, CodDelegat,
      CodSubunitate,
      UserID, DataCreare,
      CodSerie, Retur,
      ModCantar, TipBCAR,
      CodGestImpl, CodLocatImpl,
      Observatii,
      CodPers, MijlTransp, NrTransp, CodAuto,
      ICUmiditate,
      ICStraine,
      ICIncoltit,
      ICHectolitrica,
      ICGluten,
      ICFuzaritate,
      ICCadere,
      ICDeformare,
      ICSticlozitate,
      ICSparturi,
      NetKgClient, UtilKgClient,
      InfoClient,
      CodDoc1Storno,
      CodBCARDest,
      CodContract1,
      CodRemorca, NrRemorca, UtilStasKg,
      PretConfirmat,
      isproteina      ,
      isaflatoxina    ,
      isatac_plosnita ,
      iscontinut_ulei ,
      isaciditate     ,
      iaproteina      ,
      iaaflatoxina    ,
      iaatac_plosnita ,
      iacontinut_ulei ,
      iaaciditate     ,
      icproteina      ,
      icaflatoxina    ,
      icatac_plosnita ,
      iccontinut_ulei ,
      icaciditate,
      IASISTAVE,
      IAREFRACTIE,
      IAINDICE_W,
      IATOXINA_DON,
      IABOABE_TOXICE,
      ISSISTAVE,
      ISREFRACTIE,
      ISINDICE_W,
      ISTOXINA_DON,
      ISBOABE_TOXICE,
      ICSISTAVE,
      ICREFRACTIE,
      ICINDICE_W,
      ICTOXINA_DON,
      ICBOABE_TOXICE,
      PIERDERITEH,
      MONEDA,
      CURS,
      ID_CITIRE1,
      ID_CITIRE2
   )
    (
      SELECT
        RecId, Operat, CodCantarIn, CodCantarOut, TipDoc, CodDoc1,
        PrefixDoc, NrDoc, DataDoc, CarnetDoc,
        PrefixAvizIn, NrAvizIn, NrAvizOut, DataAvizIn,
        ISUmiditate, IAUmiditate,
        ISStraine, IAStraine,
        ISIncoltit, IAIncoltit,
        ISHectolitrica, IAHectolitrica,
        ISGluten, IAGluten,
        ISFuzaritate, IAFuzaritate,
        ISCadere, IACadere,
        ISDeformare, IADeformare,
        ISSticlozitate, IASticlozitate,
        ISSparturi, IASparturi,
        CodObiect, BrutKg, Tara, NetKg, UtilKg, PretAchiz, PretUscare,
        CodPartener, CodSediu, CodDelegat,
        CodSubunitate,
        PKG_GLOBALS.UserId, CURRENT_TIMESTAMP,
        CodSerie, Retur,
        ModCantar, TipBCAR,
        CodGestImpl, CodLocatImpl,
        Observatii,
        CodPers, MijlTransp, NrTransp, CodAuto,
        ICUmiditate,
        ICStraine,
        ICIncoltit,
        ICHectolitrica,
        ICGluten,
        ICFuzaritate,
        ICCadere,
        ICDeformare,
        ICSticlozitate,
        ICSparturi,
        NetKgClient, UtilKgClient,
        InfoClient,
        CodDoc1Storno,
        CodBCARDest,
        CodContract1,
        CodRemorca, NrRemorca, UtilStasKg,
        PretConfirmat,
        isproteina      ,
        isaflatoxina    ,
        isatac_plosnita ,
        iscontinut_ulei ,
        isaciditate     ,
        iaproteina      ,
        iaaflatoxina    ,
        iaatac_plosnita ,
        iacontinut_ulei ,
        iaaciditate     ,
        icproteina      ,
        icaflatoxina    ,
        icatac_plosnita ,
        iccontinut_ulei ,
        icaciditate,
        IASISTAVE,
        IAREFRACTIE,
        IAINDICE_W,
        IATOXINA_DON,
        IABOABE_TOXICE,
        ISSISTAVE,
        ISREFRACTIE,
        ISINDICE_W,
        ISTOXINA_DON,
        ISBOABE_TOXICE,
        ICSISTAVE,
        ICREFRACTIE,
        ICINDICE_W,
        ICTOXINA_DON,
        ICBOABE_TOXICE,
        PIERDERITEH,
        MONEDA,
        CURS,
        ID_CITIRE1,
        ID_CITIRE2
      FROM TMP_BCAR
    );

    -- actualizare CARNETE DOCUMENTE
    IF (CARNETDOC_I &lt;&gt; 0) AND (NRDOC_I &lt;&gt; 0) AND (aCARNETDOC &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I) THEN
      PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
    END IF;
    PKG_CARNETEDOC.SOLVENUMARDOC(aCARNETDOC, aNRDOC);

    -- asociaza cantaririle selectate cu bonul inserat, dupa care deblocheaza bonul
    UPDATE CANTAR
    SET TipDoc = 67,
        CodDoc1 = RecId,
        UserIdBlocaj = Null
    WHERE NVL(CodDoc1, 0) = 0 AND
          UserIdBlocaj = PKG_GLOBALS.UserId;

  END IF;
  NotifyModif(Operation, RecId, &apos;BCAR&apos;);
  -- mBonCantar --&gt;  67;
  PKG_CFGTABLES.EXT_POSTRECORDS(67);
  COMMIT;
END;

PROCEDURE UNLOCK_ALL_USER_RECORDS(aCodBCAR in number default 0) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE BCAR
  SET USERIDBLOCAJ = NULL
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID;
  if aCodBCAR &gt; 0 then
    UPDATE BCAR
    SET USERIDBLOCAJ = NULL
    WHERE CODBCAR = ACODBCAR;
  end if;
  COMMIT;
END;

PROCEDURE ELIBEREAZA_ALL_USER_RECORDS IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE BCAR
  SET TIPDOC = NULL,
      CODDOC1 = NULL,
      USERIDBLOCAJ = NULL
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID;
  COMMIT;
END;

PROCEDURE ELIBEREAZA_NEW_USER_RECORDS IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE BCAR
  SET TIPDOC = NULL,
      CODDOC1 = NULL,
      USERIDBLOCAJ = NULL
  WHERE
    USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND CODDOC1 &lt; 0;
  COMMIT;
END;

PROCEDURE LOCK_BCAR_GENERARE_INTRARE(aCodFurn IN NUMBER, aTipDoc IN NUMBER, aCodDoc IN NUMBER, aSubunitate IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
aTipBCAR number(1);
BEGIN
  aTipBCAR := 1; -- tbcarProductie
  if aTipDoc IN (1, 2, 3, 4, 5, 8, 9) THEN aTipBCAR := 0; -- tbcarFurnizor
  elsif aTipDoc IN (16, 18, 19, 20, 21, 22) THEN aTipBCAR := 2; -- tbcarClient
  elsif aTipDoc = 6 THEN aTipBCAR := 3; --tbcarDeLaSubunitate
  elsif aTipDoc = 23 THEN aTipBCAR := 4; --tbcarCatreSubunitate
  elsif aTipDoc = 24 THEN aTipBCAR := 5; --tbcarConsumIntern
	end if;

-- blocheaza inregistrarile pentru preluare
  UPDATE BCAR
  SET UserIDBlocaj = PKG_GLOBALS.UserID,
      TipDoc = aTipDoc
  WHERE
    TipBCAR = aTipBCAR
		AND NVL( Operat, 0) = 1
		AND   ((( UserIDBlocaj = PKG_GLOBALS.UserID)AND (NVL(CodDoc1, 0) &lt; 0)) --preluari nepostate
		       OR
					( NVL(UserIDBlocaj, 0) = 0
		        AND CodPartener = aCodFurn
		        AND NVL(CodSubunitate, 1) = aSubunitate
		        AND NVL(TipDoc, 0)  = 0
		        AND NVL(CodDoc1, 0) = 0)
					) ;
  COMMIT;
END;

PROCEDURE GET_BCAR_FURNIZOR(aCodFurn IN NUMBER, aTipDoc IN NUMBER, aCodDoc IN NUMBER, aSubunitate IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
aTipBCAR number(1);
BEGIN
  DELETE FROM TMP_BCAR_PE_LOT;
  aTipBCAR := 1; -- tbcarProductie
  if aTipDoc IN (1, 2, 3, 4, 5, 8, 9) THEN aTipBCAR := 0; -- tbcarFurnizor
  elsif aTipDoc IN (16, 18, 19, 20, 21, 22) THEN aTipBCAR := 2; -- tbcarClient
  elsif aTipDoc = 6 THEN aTipBCAR := 3; --tbcarDeLaSubunitate
  elsif aTipDoc = 23 THEN aTipBCAR := 4; --tbcarCatreSubunitate
  elsif aTipDoc = 24 THEN aTipBCAR := 5; --tbcarConsumIntern
  elsif aTipDoc = 12 THEN aTipBCAR := 6; --tbcarConsumIntern
  elsif aTipDoc in (14,15) THEN aTipBCAR := 8; --tbcarReclasificare
	end if;

-- blocheaza inregistrarile pentru preluare
  UPDATE BCAR
  SET UserIDBlocaj = PKG_GLOBALS.UserID,
      TipDoc = aTipDoc
  WHERE
    TipBCAR = aTipBCAR
		AND NVL( Operat, 0) = 1
		AND   ((( UserIDBlocaj = PKG_GLOBALS.UserID)AND (NVL(CodDoc1, 0) &lt; 0)) --preluari nepostate
		       OR
					( NVL(UserIDBlocaj, 0) = 0
		        AND CodPartener = aCodFurn
		        AND NVL(CodSubunitate, 1) = aSubunitate
		        AND NVL(TipDoc, 0)  = 0
		        AND NVL(CodDoc1, 0) = 0)
					) ;
  COMMIT;

  -- pregateste tabela temporara pentru preluare
  INSERT INTO TMP_BCAR_PE_LOT
  (
    CodBCAR,
    Furnizor,
    CodObiect,
    NetKg,
    DenObiect,
    CodSerie,
    DataDoc,
    UtilKg,
    PretAchiz,
    PretUscare,
    Selectie,
    Grup,
    CodLocatie,
    NrDoc,
    Delegat,
    Auto,
    NrAvizIn,
    Retur,
    CodGestImpl,
    CodLocatImpl,
    CodPers,
    MijlTransp,
    NrTransp,
    CodAuto,
    NumeDelegat,
    CodDelegat,
    CodContract1,
    UtilStasKg,
    PretLaStas
  )
  (
    SELECT
      B.CodBCAR,
      B.CodPartener,
      B.CodObiect,
      DECODE(B.Retur, 1, -1, 1) * B.NetKg,
      A.Denumire,
      B.CodSerie,
      B.DataDoc,
      DECODE(B.Retur, 1, -1, 1) * B.UtilKg,
      B.PretAchiz,
      B.PretUscare,
      0,
      Null,
      NVL(B.CodSediu, 0),
      B.NrDoc,
      TR.Delegat,
      B.NrTransp, --TR.NrTransp
      B.NrAvizIn,
      NVL(B.Retur, 0),
      B.CodGestImpl,
      B.CodLocatImpl,
      B.CodPers,
      B.MijlTransp,
      B.NrTransp,
      B.CodAuto,
      TR.Delegat,
      B.CodDelegat,
      B.CodContract1,
      B.Utilstaskg,
      CASE WHEN NVL(B.UTILSTASKG, 0) = 0 THEN 0
           ELSE ROUND(B.UTILKG * B.PRETACHIZ / B.UTILSTASKG, 6)
      END
    FROM
      BCAR B
      INNER JOIN NARTOBJ A ON A.CodObiect = B.CodObiect
      LEFT OUTER JOIN NPARTTR TR ON TR.CodPartTr = B.CodDelegat
    WHERE
      B.UserIDBlocaj = PKG_GLOBALS.UserID
    	OR
		  ( B.CodBCAR in
			         ( select Bx.CodBCAR
  			  			 from BCAR Bx
					  	   inner join Intrari1 I1 on I1.CodIntr1 = Bx.CodDoc1
								 inner join Intrari I   on I.CodIntr = I1.CodIntr
								 where I.CodIntr = aCodDoc
                 AND Bx.TipBCAR = aTipBCAR
							 )
		  )
    	OR
		  ( B.CodBCAR in
			         ( select Bx.CodBCAR
  			  			 from BCAR Bx
					  	   inner join Iesiri1 I1 on I1.CodIes1 = Bx.CodDoc1
								 inner join Iesiri I   on I.CodIes = I1.CodIes
								 where I.CodIes = aCodDoc
                 AND Bx.TipBCAR = aTipBCAR
							 )
		  )
  );
  COMMIT;
END;

PROCEDURE UPDATE_BCAR_FURNIZOR(aCodDoc1 IN NUMBER, aTipDoc IN NUMBER, aCodBCAR IN NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE BCAR
  SET CodDoc1 = aCodDoc1
  WHERE
	  TipDoc = aTipDoc
    AND CodBCAR = aCodBCAR;
  COMMIT;
END;

PROCEDURE UPDATE_RECORDS(pTipDoc IN NUMBER, pTMP_CODDOC1 IN NUMBER , pCODDOC1 IN NUMBER) IS
BEGIN
  UPDATE BCAR
  SET CODDoc1 = pCODDOC1,
      USERIDBLOCAJ = null
  WHERE
	    USERIDBLOCAJ = PKG_GLOBALS.USERID
			AND TipDoc   = pTipDoc
			AND CodDoc1  = pTMP_CODDOC1;
END;

PROCEDURE SETNRDOC_I(aNrDoc IN NUMBER, aCarnet IN NUMBER) IS
BEGIN
  CARNETDOC_I := aCarnet;
  NRDOC_I     := aNrDoc;
END;

FUNCTION EVAL(aEvalString IN VARCHAR2) RETURN NUMBER IS
  retValue NUMBER(20, 7);
BEGIN
  IF aEvalString IS NULL THEN
    RETURN NULL;
  ELSE
    EXECUTE IMMEDIATE &apos;SELECT &apos;||REPLACE(aEvalString, &apos;,&apos;, &apos;.&apos;)||&apos; FROM DUAL&apos; INTO retValue;
    RETURN retValue;
  END IF;
END;

FUNCTION CALCULEAZA_SCAZ(
           aTipScaz IN VARCHAR2,
           aCantBruta IN NUMBER, aCantNeta IN NUMBER, aCantAnaliza IN NUMBER, aCantStas IN NUMBER,
           aAnDoc IN NUMBER, aLunaDoc IN NUMBER
         ) RETURN NUMBER IS
  sCBrut     VARCHAR2(300);
  sCNet      VARCHAR2(300);
  sCA        VARCHAR2(300);
  sCS        VARCHAR2(300);
  evalString VARCHAR2(300);
BEGIN
  sCBrut := TO_CHAR(NVL(aCantBruta, 0));
  sCNet  := TO_CHAR(NVL(aCantNeta, 0));
  sCA    := TO_CHAR(NVL(aCantAnaliza, 0));
  sCS    := TO_CHAR(NVL(aCantStas, 0));

  -- formulele din constante
  evalString := PKG_CATEGCONST.Getvalconstanta(aTipScaz, aAnDoc, aLunaDoc);

  evalString := REPLACE(evalString, &apos;CantBruta&apos;,   &apos;(&apos; || sCBrut || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;CantNeta&apos;,    &apos;(&apos; || sCNet  || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;CantAnaliza&apos;, &apos;(&apos; || sCA    || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;CantStas&apos;,    &apos;(&apos; || sCS    || &apos;)&apos;);

  RETURN EVAL(evalString);
END;

FUNCTION CALCULEAZA_CANTUTILA(
           aCantBruta IN NUMBER, aCantNeta IN NUMBER,
           aCantAnalizaUmiditate IN NUMBER, aCantStasUmiditate IN NUMBER,
           aCantAnalizaStraine IN NUMBER, aCantStasStraine IN NUMBER,
           aCantAnalizaHectolitric IN NUMBER, aCantStasHectolitric IN NUMBER,
           aCantAnalizaSparturi IN NUMBER, aCantStasSparturi IN NUMBER,
           aPierd IN NUMBER,
           aAnDoc IN NUMBER, aLunaDoc IN NUMBER, aStas in number default 0
         ) RETURN NUMBER IS
  lCantAnalizaUmiditate   NUMBER(20, 7) := 0.0;
  lCantAnalizaStraine     NUMBER(20, 7) := 0.0;
  lCantAnalizaHectolitric NUMBER(20, 7) := 0.0;
  lCantAnalizaSparturi    NUMBER(20, 7) := 0.0;
  sCBrut                  VARCHAR2(300);
  sCNet                   VARCHAR2(300);
  sSU                     VARCHAR2(300);
  sSS                     VARCHAR2(300);
  sSP                     VARCHAR2(300);
  sSH                     VARCHAR2(300);
  sPierd                  VARCHAR2(300);
  evalString              VARCHAR2(300);
BEGIN
  lCantAnalizaUmiditate   := aCantAnalizaUmiditate;
  lCantAnalizaStraine     := aCantAnalizaStraine;
  lCantAnalizaHectolitric := aCantAnalizaHectolitric;
  lCantAnalizaSparturi    := aCantAnalizaSparturi;

  -- conditii in care Analiza = STAS (si pentru Sparturi, insa indicele asta nu intra in formule)
  if aStas &lt;&gt; 1 then
    IF lCantAnalizaUmiditate   &lt; aCantStasUmiditate   THEN lCantAnalizaUmiditate   := aCantStasUmiditate;   END IF;
    IF lCantAnalizaStraine     &lt; aCantStasStraine     THEN lCantAnalizaStraine     := aCantStasStraine;     END IF;
    IF lCantAnalizaHectolitric &gt; aCantStasHectolitric THEN lCantAnalizaHectolitric := aCantStasHectolitric; END IF;
    IF lCantAnalizaSparturi    &lt; aCantStasSparturi    THEN lCantAnalizaSparturi    := aCantStasSparturi;    END IF;
  end if;

  sCBrut := TO_CHAR(aCantBruta);
  sCNet  := TO_CHAR(aCantNeta);
  sPierd := TO_CHAR(aPierd);
  sSU    := TO_CHAR(CALCULEAZA_SCAZ(&apos;ScazUmiditate&apos;,   aCantBruta, aCantNeta, lCantAnalizaUmiditate,   aCantStasUmiditate,   aAnDoc, aLunaDoc));
  sSS    := TO_CHAR(CALCULEAZA_SCAZ(&apos;ScazStraine&apos;,     aCantBruta, aCantNeta, lCantAnalizaStraine,     aCantStasStraine,     aAnDoc, aLunaDoc));
  sSH    := TO_CHAR(CALCULEAZA_SCAZ(&apos;ScazHectolitric&apos;, aCantBruta, aCantNeta, lCantAnalizaHectolitric, aCantStasHectolitric, aAnDoc, aLunaDoc));
  sSP    := TO_CHAR(CALCULEAZA_SCAZ(&apos;ScazSparturi&apos;,    aCantBruta, aCantNeta, lCantAnalizaSparturi,    aCantStasSparturi,    aAnDoc, aLunaDoc));

  -- formula din constante
  evalString := PKG_CATEGCONST.Getvalconstanta(&apos;CantUtila&apos;, aAnDoc, aLunaDoc);

  evalString := REPLACE(evalString, &apos;CantBruta&apos;,       &apos;(&apos; || sCBrut || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;CantNeta&apos;,        &apos;(&apos; || sCNet  || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;ScazUmiditate&apos;,   &apos;(&apos; || sSU    || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;ScazStraine&apos;,     &apos;(&apos; || sSS    || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;ScazHectolitric&apos;, &apos;(&apos; || sSH    || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;ScazSparturi&apos;,    &apos;(&apos; || sSP    || &apos;)&apos;);
  evalString := REPLACE(evalString, &apos;PierderiTeh&apos;,     &apos;(&apos; || sPierd || &apos;)&apos;);

  RETURN EVAL(evalString);
END;

FUNCTION RECALCULEAZA_BCAR RETURN VARCHAR2 IS
lISUmiditate    NUMBER(20,7) := 0.0;
lISStraine      NUMBER(20,7) := 0.0;
lISIncoltit     NUMBER(20,7) := 0.0;
lISHectolitrica NUMBER(20,7) := 0.0;
lISGluten       NUMBER(20,7) := 0.0;
lISFuzaritate   NUMBER(20,7) := 0.0;
lISCadere       NUMBER(20,7) := 0.0;
lISDeformare    NUMBER(20,7) := 0.0;
lISSticlozitate NUMBER(20,7) := 0.0;
lISSparturi     NUMBER(20,7) := 0.0;

lAnDoc          NUMBER(4);
lLunaDoc        NUMBER(2);

lCantUtila      NUMBER(20,7) := 0.0;
lCantStasUtila  NUMBER(20,7) := 0.0;
BEGIN

  -- am BCAR-urile, le iau pe cele nepreluate, neblocate
  -- am obiectul de pe BCAR si valorile indicilor STAS din nomenclator
  -- de pe BCAR iau cant.bruta, cant.neta, tara si valorile indicilor ANALIZA
  -- am formule din constante...

  -- dar mai intai deblochez BCAR-urile blocate...
  UPDATE BCAR SET UserIdBlocaj = NULL;

  SAVEPOINT SP_RECALCULEAZA_BCAR;

  BEGIN

    FOR
      vrec
    IN
      (
        SELECT
          *
        FROM
          BCAR
        WHERE
          NVL(CodDoc1,      0) = 0 AND
          NVL(UserIdBlocaj, 0) = 0
      )
    LOOP

      lAnDoc   := EXTRACT(YEAR  FROM vrec.DataDoc);
      lLunaDoc := EXTRACT(MONTH FROM vrec.DataDoc);

      SELECT
        NVL(AO1.Umiditate, 0),
        NVL(AO1.Corpuri_straine, 0),
        NVL(AO1.Incoltit, 0),
        NVL(AO1.Hectolitrica, 0),
        NVL(AO1.Gluten, 0),
        NVL(AO1.Fuzaritate, 0),
        NVL(AO1.Cadere, 0),
        NVL(AO1.Deformare, 0),
        NVL(AO1.Sticlozitate, 0),
        NVL(AO1.Sparturi, 0)
      INTO
        lISUmiditate,
        lISStraine,
        lISIncoltit,
        lISHectolitrica,
        lISGluten,
        lISFuzaritate,
        lISCadere,
        lISDeformare,
        lISSticlozitate,
        lISSparturi
      FROM
        NArtObj1 AO1
      WHERE
        AO1.CodObiect = vrec.CodObiect AND
        AO1.AnStart * 12 + AO1.LunaStart =
          (
            SELECT
              MAX(AO2.AnStart * 12 + AO2.LunaStart)
            FROM
              NArtObj1 AO2
            WHERE
              AO2.CodObiect = vrec.CodObiect AND
              AO2.AnStart * 12 + AO2.LunaStart &lt;= lAnDoc * 12 + lLunaDoc
          );

      lCantUtila := CALCULEAZA_CANTUTILA(
                      vrec.BrutKg, vrec.NetKg,
                      vrec.IAUmiditate, lISUmiditate,
                      vrec.IAStraine, lISStraine,
                      vrec.IAHectolitrica, lISHectolitrica,
                      vrec.IASparturi, lISSparturi,
                      coalesce(vrec.pierderiteh,0),
                      lAnDoc, lLunaDoc
                    );
      lCantStasUtila := CALCULEAZA_CANTUTILA(
                      vrec.BrutKg, vrec.NetKg,
                      vrec.IAUmiditate, lISUmiditate,
                      vrec.IAStraine, lISStraine,
                      vrec.IAHectolitrica, lISHectolitrica,
                      vrec.IASparturi, lISSparturi,
                      coalesce(vrec.pierderiteh,0),
                      lAnDoc, lLunaDoc, 1
                    );

      UPDATE
        BCAR
      SET
        ISUmiditate    = lISUmiditate,
        ISStraine      = lISStraine,
        ISIncoltit     = lISIncoltit,
        ISHectolitrica = lISHectolitrica,
        ISGluten       = lISGluten,
        ISFuzaritate   = lISFuzaritate,
        ISCadere       = lISCadere,
        ISDeformare    = lISDeformare,
        ISSticlozitate = lISSticlozitate,
        ISSparturi     = lISSparturi,
        UtilKg         = lCantUtila,
        UtilStasKg     = lCantStasUtila
      WHERE
        CodBCAR = vrec.CodBCAR;

    END LOOP;

    COMMIT;
    RETURN &apos;ALL_OK&apos;;

  END;

  EXCEPTION WHEN OTHERS THEN BEGIN
    ROLLBACK TO SP_RECALCULEAZA_BCAR;
    RETURN &apos;EXCEPTION&apos;;
  END;

END;

PROCEDURE LOCK_RECORDS_TMPINTRARI1 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  pTIPDOC  NUMBER;
BEGIN
   Select TipDoc into pTipDoc from TMP_INTRARI;
   FOR V_REC IN (SELECT * FROM TMP_INTRARI1)
   LOOP
      UPDATE BCAR SET USERIDBLOCAJ = PKG_GLOBALS.USERID
      WHERE TIPDOC = pTipDoc AND CODDOC1 = V_REC.CODINTR1;
   END LOOP;
  COMMIT;
END;

PROCEDURE LOCK_RECORDS_TMPIESIRI1 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  pTIPDOC  NUMBER;
BEGIN
   Select TipDoc into pTipDoc from TMP_IESIRI;
   FOR V_REC IN (SELECT * FROM TMP_IESIRI1)
   LOOP
      UPDATE BCAR SET USERIDBLOCAJ = PKG_GLOBALS.USERID
      WHERE TIPDOC = pTipDoc AND CODDOC1 = V_REC.CODIES1;
   END LOOP;
  COMMIT;
END;

PROCEDURE SERVICE_UNLOCK_BCAR IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE BCAR
  SET UserIdBlocaj = NULL, TipDoc = NULL
  WHERE NVL(CodDoc1, 0) &lt;= 0;
  COMMIT;
END;

FUNCTION BCAR_PRELUAT(aCodBCAR IN NUMBER) RETURN NUMBER IS
  lCodDoc1 NUMBER(20);
BEGIN
  SELECT NVL(CodDoc1, 0) INTO lCodDoc1 FROM BCAR WHERE CodBCAR = aCodBCAR;
  RETURN lCodDoc1;
  EXCEPTION WHEN NO_DATA_FOUND THEN RETURN 0;
END;

FUNCTION BCAR_BLOCAT(aCodBCAR IN NUMBER) RETURN NUMBER IS
  lUserIdBlocaj NUMBER(20);
BEGIN
  SELECT NVL(UserIdBlocaj, 0) INTO lUserIdBlocaj FROM BCAR WHERE CodBCAR = aCodBCAR;
  RETURN lUserIdBlocaj;
  EXCEPTION WHEN NO_DATA_FOUND THEN RETURN 0;
END;

PROCEDURE UNLOCK_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER) IS
BEGIN
  UPDATE BCAR
  SET USERIDBLOCAJ = null
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND TIPDOC = pTipDoc
    AND CODDOC1 = pCODDOC1;
END;

PROCEDURE UPDATE_BCAR(aCodCarnet in number) IS
BEGIN
  --calcul cantitate
  for v_rec in (select tmp.codbcar,
                       o1.umiditate o1_umiditate,
                       o1.corpuri_straine o1_straine,
                       o1.incoltit o1_incoltit,
                       o1.hectolitrica o1_hectolitrica,
                       o1.gluten o1_gluten,
                       o1.fuzaritate o1_fuzaritate,
                       o1.cadere o1_cadere,
                       o1.deformare o1_deformare,
                       o1.sticlozitate o1_sticlozitate,
                       o1.sparturi o1_sparturi,
                       o1.proteina o1_proteina,
                       o1.aflatoxina o1_aflatoxina,
                       o1.atac_plosnita o1_atac_plosnita,
                       o1.continut_ulei o1_continut_ulei,
                       o1.aciditate o1_aciditate,
                       o1.sistave o1_sistave,
                       o1.refractie o1_refractie,
                       o1.indice_w o1_indice_w,
                       o1.toxina_don o1_toxina_don,
                       o1.boabe_toxice o1_boabe_toxice,
                       ag.codagenda
                from tmp_bcar tmp
                     inner join nartobj1 o1 on o1.codobiect = tmp.codobiect and pkg_globals.getanlucru*12+pkg_globals.getlunalucru between o1.alstart and o1.alstop
                     left join nagenda ag on ag.codpart = tmp.codpartener and tmp.tipbcar in (0,2) and ag.sediusocial between 4 and 7
               ) loop
    update tmp_bcar set
      ISUMIDITATE    = v_rec.O1_UMIDITATE,
      ISSTRAINE      = v_rec.O1_STRAINE,
      ISINCOLTIT     = v_rec.O1_INCOLTIT,
      ISHECTOLITRICA = v_rec.O1_HECTOLITRICA,
      ISGLUTEN       = v_rec.O1_GLUTEN,
      ISFUZARITATE   = v_rec.O1_FUZARITATE,
      ISCADERE       = v_rec.O1_CADERE,
      ISDEFORMARE    = v_rec.O1_DEFORMARE,
      ISSTICLOZITATE = v_rec.O1_STICLOZITATE,
      ISSPARTURI     = v_rec.O1_SPARTURI,
      ISPROTEINA     = v_rec.O1_PROTEINA,
      ISAFLATOXINA   = v_rec.O1_AFLATOXINA,
      ISATAC_PLOSNITA = v_rec.O1_ATAC_PLOSNITA,
      ISCONTINUT_ULEI = v_rec.O1_CONTINUT_ULEi,
      ISACIDITATE    = v_rec.O1_ACIDITATE,
      ISSISTAVE      = v_rec.O1_SISTAVE,
      ISREFRACTIE    = v_rec.O1_REFRACTIE,
      ISINDICE_W     = v_rec.O1_INDICE_W,
      ISTOXINA_DON   = v_rec.O1_TOXINA_DON,
      ISBOABE_TOXICE = v_rec.O1_BOABE_TOXICE,
      NETKG          = COALESCE(BRUTKG,0) - COALESCE(TARA,0),
      CODSEDIU       = V_REC.CODAGENDA
    where codbcar = v_rec.codbcar;
  end loop;
  update tmp_bcar set
    UTILKG     = CALCULEAZA_CANTUTILA
                   (BrutKg, NetKg,
                    IAUmiditate, ISUmiditate,
                    IAStraine, ISStraine,
                    IAHectolitrica, ISHectolitrica,
                    IASparturi, ISSparturi,
                    coalesce(pierderiteh,0),
                    pkg_globals.getanlucru, pkg_globals.getlunalucru
                   ),
    UTILSTASKG = CALCULEAZA_CANTUTILA
                   (BrutKg, NetKg,
                    IAUmiditate, ISUmiditate,
                    IAStraine, ISStraine,
                    IAHectolitrica, ISHectolitrica,
                    IASparturi, ISSparturi,
                    coalesce(pierderiteh,0),
                    pkg_globals.getanlucru, pkg_globals.getlunalucru, 1
                   );
  insert into bcar(codbcar,operat,tipdoc,prefixdoc,nrdoc,datadoc,carnetdoc,
                   isumiditate,iaumiditate,isstraine,iastraine,isincoltit,iaincoltit,ishectolitrica,
                   iahectolitrica,isgluten,iagluten,isfuzaritate,iafuzaritate,iscadere,iacadere,
                   isdeformare,iadeformare,issticlozitate,iasticlozitate,issparturi,iasparturi,
                   codobiect,brutkg,tara,netkg,utilkg,pretachiz,pretuscare,codpartener,codsediu,coddelegat,
                   codsubunitate,userid,datacreare,codserie,retur,modcantar,useridblocaj,tipbcar,
                   codgestimpl,codlocatimpl,observatii,codpers,mijltransp,nrtransp,codauto,icumiditate,
                   icstraine,icincoltit,ichectolitrica,icgluten,icfuzaritate,iccadere,icdeformare,icsticlozitate,
                   icsparturi,netkgclient,utilkgclient,infoclient,coddoc1storno,codbcardest,codcontract1,nrremorca,
                   codremorca,utilstaskg,pretconfirmat,isproteina,isaflatoxina,isatac_plosnita,iscontinut_ulei,isaciditate,
                   iaproteina,iaaflatoxina,iaatac_plosnita,iacontinut_ulei,iaaciditate,icproteina,icaflatoxina,icatac_plosnita,
                   iccontinut_ulei,icaciditate,iasistave,iarefractie,iaindice_w,iatoxina_don,iaboabe_toxice,issistave,isrefractie,
                   isindice_w,istoxina_don,isboabe_toxice,icsistave,icrefractie,icindice_w,ictoxina_don,icboabe_toxice,pierderiteh)
  select seq_bcar_codbcar.nextval,0,tipdoc,prefixdoc,nrdoc,datadoc,case when coalesce(aCodCarnet,0) &gt; 0 then aCodCarnet end,
         coalesce(isumiditate,0),coalesce(iaumiditate,0),coalesce(isstraine,0),coalesce(iastraine,0),coalesce(isincoltit,0),coalesce(iaincoltit,0),coalesce(ishectolitrica,0),
         coalesce(iahectolitrica,0),coalesce(isgluten,0),coalesce(iagluten,0),coalesce(isfuzaritate,0),coalesce(iafuzaritate,0),coalesce(iscadere,0),coalesce(iacadere,0),
         coalesce(isdeformare,0),coalesce(iadeformare,0),coalesce(issticlozitate,0),coalesce(iasticlozitate,0),coalesce(issparturi,0),coalesce(iasparturi,0),
         coalesce(codobiect,0),coalesce(brutkg,0),coalesce(tara,0),coalesce(netkg,0),coalesce(utilkg,0),coalesce(pretachiz,0),coalesce(pretuscare,0),coalesce(codpartener,0),coalesce(codsediu,0),coalesce(coddelegat,0),
         pkg_globals.GETSUBUNITATE_DOC,pkg_globals.GETUSERID,sysdate,coalesce(codserie,0),retur,modcantar,useridblocaj,tipbcar,
         codgestimpl,codlocatimpl,&apos;Import EDI XLS&apos;,codpers,mijltransp,nrtransp,codauto,coalesce(icumiditate,0),
         coalesce(icstraine,0),coalesce(icincoltit,0),coalesce(ichectolitrica,0),coalesce(icgluten,0),coalesce(icfuzaritate,0),coalesce(iccadere,0),coalesce(icdeformare,0),coalesce(icsticlozitate,0),
         coalesce(icsparturi,0),coalesce(netkgclient,0),coalesce(utilkgclient,0),coalesce(infoclient,0),coalesce(coddoc1storno,0),coalesce(codbcardest,0),codcontract1,nrremorca,
         codremorca,coalesce(utilstaskg,0),coalesce(pretconfirmat,0),coalesce(isproteina,0),coalesce(isaflatoxina,0),coalesce(isatac_plosnita,0),coalesce(iscontinut_ulei,0),coalesce(isaciditate,0),
         coalesce(iaproteina,0),coalesce(iaaflatoxina,0),coalesce(iaatac_plosnita,0),coalesce(iacontinut_ulei,0),coalesce(iaaciditate,0),coalesce(icproteina,0),coalesce(icaflatoxina,0),coalesce(icatac_plosnita,0),
         coalesce(iccontinut_ulei,0),coalesce(icaciditate,0),coalesce(iasistave,0),coalesce(iarefractie,0),coalesce(iaindice_w,0),coalesce(iatoxina_don,0),coalesce(iaboabe_toxice,0),coalesce(issistave,0),coalesce(isrefractie,0),
         coalesce(isindice_w,0),coalesce(istoxina_don,0),coalesce(isboabe_toxice,0),coalesce(icsistave,0),coalesce(icrefractie,0),coalesce(icindice_w,0),coalesce(ictoxina_don,0),coalesce(icboabe_toxice,0),coalesce(pierderiteh,0)
  from tmp_bcar;

  commit;
END;

procedure SalveazaMP(aCodPart in number, aCodSediu in number, vCodObiect in number, aTipBCAR in number, aObs in varchar2, aCodMPBCAR out number) is
aCodObiect number(20);
aCant number(20,7);
aOldPret number(20,7);
aOldTVA  number(20,7);
CursPUVAL number(20,7);
UrmarirePUVAL varchar2(5);
aTipTVA varchar2(5);
aTVA number(20,7);
aProcTVA number(20,7);
aVALDOC     NUMBER(20, 7);
aTVADOC     NUMBER(20, 7);
aCODGENERAL NUMBER(20);
aVALOBLIG   NUMBER(20, 7);
aMONEDA     NUMBER(20);
NR          number(5);
aPRETORIG   number(20,7);
aVALDISCDOC NUMBER(20, 7);
aTVADISCDOC NUMBER(20, 7);
begin
  --execute immediate &apos;create table bcar1_x as select * from tmp_bcar_man1&apos;;

  select seq_mpbcar_codmpbcar.nextval into aCodMPBCAR from dual;
  insert into mpbcar(codmpbcar,
                     userid,
                     datacreare,
                     codpart,
                     codsediu,
                     tipbcar,
                     codobiect,
                     obs)
  values(aCodMPBCAR,
         pkg_globals.GETUSERID,
         sysdate,
         aCodPart,
         aCodSediu,
         aTipBCAR,
         vCodObiect,
         aObs);                   
  insert into mpbcar1(codmpbcar1,
                      codmpbcar,
                      codbcar,
                      nrdoc,
                      datadoc,
                      denobiect,
                      codobiect,
                      netkg,
                      utilkg,
                      pretachiz,
                      pretuscare,
                      pretlastas,
                      tipbcar,
                      pretachiznou,
                      codcontract1,
                      moneda,
                      curs,
                      iaumiditate,
                      iastraine,
                      iaincoltit,
                      iahectolitrica,
                      iagluten,
                      iafuzaritate,
                      iacadere,
                      iadeformare,
                      iasticlozitate,
                      iasparturi,
                      iaproteina,
                      iaaflatoxina,
                      iaatac_plosnita,
                      iacontinut_ulei,
                      iaaciditate,
                      iasistave,
                      iarefractie,
                      iaindice_w,
                      iatoxina_don,
                      iaboabe_toxice)
  select seq_mpbcar1_codmpbcar1.nextval,
         acodmpbcar,
         codbcar,
         nrdoc,
         datadoc,
         denobiect,
         codobiect,
         netkg,
         utilkg,
         pretachiz,
         pretuscare,
         pretlastas,
         tipbcar,
         pretachiznou,
         codcontract1,
         moneda,
         curs,
         iaumiditate,
         iastraine,
         iaincoltit,
         iahectolitrica,
         iagluten,
         iafuzaritate,
         iacadere,
         iadeformare,
         iasticlozitate,
         iasparturi,
         iaproteina,
         iaaflatoxina,
         iaatac_plosnita,
         iacontinut_ulei,
         iaaciditate,
         iasistave,
         iarefractie,
         iaindice_w,
         iatoxina_don,
         iaboabe_toxice
  from tmp_bcar_man1;
  insert into mpbcar2(codmpbcar2,
                      codmpbcar,
                      iaumiditate,
                      iastraine,
                      iaincoltit,
                      iahectolitrica,
                      iagluten,
                      iafuzaritate,
                      iacadere,
                      iadeformare,
                      iasticlozitate,
                      iasparturi,
                      iaproteina,
                      iaaflatoxina,
                      iaatac_plosnita,
                      iacontinut_ulei,
                      iaaciditate,
                      iasistave,
                      iarefractie,
                      iaindice_w,
                      iatoxina_don,
                      iaboabe_toxice)
  select seq_mpbcar2_codmpbcar2.nextval,
         acodmpbcar,
         iaumiditate,
         iastraine,
         iaincoltit,
         iahectolitrica,
         iagluten,
         iafuzaritate,
         iacadere,
         iadeformare,
         iasticlozitate,
         iasparturi,
         iaproteina,
         iaaflatoxina,
         iaatac_plosnita,
         iacontinut_ulei,
         iaaciditate,
         iasistave,
         iarefractie,
         iaindice_w,
         iatoxina_don,
         iaboabe_toxice
  from tmp_bcar_man2;
  
  if aTipBCAR = 0 then
    for v_rec in (select m1.codbcar, i1.codintr1, i.codintr, m1.pretachiznou pret, i.an, i.luna, i.datadoc, cf.codfiscal cf, i1.cant, i.curs, i.tipdoc
                  from tmp_bcar_man1 m1
                       left join intrari1 i1 on i1.codintr1 = m1.coddoc1
                       left join intrari i on i.codintr = i1.codintr and i.tipdoc = m1.tipdoc
                       LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL
                 ) loop
      update bcar set pretachiz = v_rec.pret where codbcar = v_rec.codbcar;
      NotifyModif(0, v_rec.codbcar, &apos;BCAR&apos;);
      if v_rec.codintr &gt; 0 then
        NotifyModif(0, v_rec.codbcar, &apos;INTRARI&apos;);
        update jurnal1 set dirty = 1 where coddoc = v_rec.codintr and tipdoc = v_rec.tipdoc;           
        --actualizez si avizul
        select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
        from intrari1 where CodIntr1 = v_rec.codintr1;

        CursPUVAL := 1;
        SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, v_rec.AN, v_rec.LUNA) INTO UrmarirePUVAL from dual;
        IF UrmarirePUVAL = &apos;1&apos; THEN
          BEGIN
            CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                         pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, v_rec.AN, v_rec.LUNA),
                         pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, v_rec.AN, v_rec.LUNA),
                         TO_CHAR(v_rec.DATADOC, &apos;dd.mm.yyyy&apos;)
                         );
          EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
          END;
        END IF;


        BEGIN
           SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
           EXCEPTION WHEN OTHERS THEN aTIPTVA := &apos;0&apos;;
        END;
        if aTIPTVA = 1 OR INSTR(UPPER(v_Rec.CF), &apos;RO&apos;) = 0 then aTVA := 0;
        else
          select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), v_rec.AN, v_rec.LUNA) into aProcTVA from dual;
          aTVA := Round(v_rec.Pret * v_rec.Cant * aProcTVA / 100, 6);
        end if;


        update intrari1 I1
        set
          PU       = CASE
                        WHEN coalesce(I1.COEFDISCMAJ, 1) = 0 THEN v_rec.PRET
                        ELSE v_Rec.Pret * coalesce(I1.COEFDISCMAJ, 1)
                      END,
          PRETORIG = v_Rec.pret, 
          TVA = aTVA
        where
          CodIntr1 = v_rec.codintr1;

        UPDATE INTRARI I
        SET
          VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = v_rec.codintr), 0),
          TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = v_rec.codintr), 0)
        WHERE
          I.CODINTR = v_rec.codintr;

      -- RECALCULEZ OBLIGATIILE PE 408;
        BEGIN
         SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0)
         INTO
           aVALDOC, aTVADoc, aMONEDA
          FROM
            INTRARI
          WHERE
            CODINTR = v_rec.codintr;
           EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0;
        END;

        SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = v_rec.codintr AND SEMNIFICATIE = 140;

        aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

        IF NR = 0 THEN
          SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
          VALUES (aCODGENERAL, 2, v_rec.codintr, aMONEDA, v_rec.Curs, 140);

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
          VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

        ELSE
          SELECT COUNT(*) INTO NR
          FROM
            OBLIGPIF O,
            GENERAL G
          WHERE
            G.TIPDOC = 2 AND G.CODDOC = v_rec.codintr AND G.SEMNIFICATIE = 140
            AND O.CODGENERAL = G.CODGENERAL;

          IF NR = 0 THEN
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
            VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = v_rec.codintr AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
          END IF;

          FOR V_REC_OBLIG IN
          (
            SELECT
               O.CODOBLIGPIF,
               O.CODGENERAL
            FROM
              GENERAL G,
              OBLIGPIF O
            WHERE
                  G.TIPDOC = 2
              AND G.CODDOC = v_rec.codintr
              AND G.SEMNIFICATIE = 140
              AND O.CODGENERAL = G.CODGENERAL
           )
           LOOP
             UPDATE OBLIGPIF
             SET
               VALOARE = aVALOBLIG,
               REST    = aVALOBLIG
             WHERE
               CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;
           END LOOP;
        END IF;
      end if;
    end loop;             
  else
    for v_rec in (select m1.codbcar, i1.codies1, i.codies, m1.pretachiznou pret, i.an, i.luna, i.datadoc, cf.codfiscal cf, i1.cant, i.curs, i.tipdoc,
                         coalesce(i.custodie,0) custodie, i.tiptva
                  from tmp_bcar_man1 m1
                       left join iesiri1 i1 on i1.codies1 = m1.coddoc1
                       left join iesiri i on i.codies = i1.codies and i.tipdoc = m1.tipdoc
                       LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL
                 ) loop
      update bcar set pretachiz = v_rec.pret where codbcar = v_rec.codbcar;
      NotifyModif(0, v_rec.codbcar, &apos;BCAR&apos;);
      if v_rec.codies &gt; 0 then
        NotifyModif(0, v_rec.codbcar, &apos;IESIRI&apos;);
        update jurnal1 set dirty = 1 where coddoc = v_rec.codies and tipdoc = v_rec.tipdoc;
        if (v_rec.custodie = 1)or(v_rec.TipTVA = 2) then
          aTIPTVA := 1;
        else
          BEGIN
             SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
             EXCEPTION WHEN OTHERS THEN aTIPTVA := 0;
          END;
        end if;

        if aTIPTVA = 1 then aTVA := 0;
        else
          select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), v_rec.AN, v_rec.LUNA) into aProcTVA from dual;
          aTVA := v_rec.Pret * v_rec.Cant * aProcTVA / 100;
        end if;

        aPRETORIG := v_rec.PRET;

      /*
        update iesiri1
        set
          PU       = aPret,
          PRETORIG = aPRETORIG,
          TVA      = aTVA
        where
        CodIes1 = aCodLinieAE;
      */
        update iesiri1 i1
        set
          PU       = aPRETORIG * i1.coefdiscmaj,
          PRETORIG = aPRETORIG,
          TVA      = CASE WHEN coalesce(v_rec.TIPTVA, 0) IN (2, 3, 4, 5, 6) THEN 0
                          ELSE aTVA
                     END
        where
          CodIes1 = v_rec.codies1;


        SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) INTO aVALDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;
        SELECT SUM( coalesce(TVA, 0)) INTO aTVADOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;

        SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0)  * coalesce(PROCDISC, 0)/100) INTO aVALDISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;
        SELECT SUM( coalesce(TVA, 0) *  coalesce(PROCDISC, 0)/100) INTO aTVADISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = v_rec.codies;

        UPDATE IESIRI I
        SET
          VALDOC      = coalesce(aVALDOC, 0) + coalesce(aVALDISCDOC,0) + coalesce(aTVADISCDOC,0),
          TVADOC      = coalesce(aTVADOC, 0) + coalesce(aTVADISCDOC,0),
          VALDISCOUNT = coalesce(aVALDISCDOC,0),
          TVADISCOUNT = coalesce(aTVADISCDOC,0)
        WHERE
          I.CODIES = v_rec.codies;

      -- RECALCULEZ OBLIGATIILE PE 418;
        BEGIN
         SELECT coalesce(VALDOC,0),  coalesce(MONEDA,0)
         INTO
           aVALDOC, aMONEDA
          FROM
            IESIRI
          WHERE
            CODIES = v_rec.codies;
           EXCEPTION WHEN OTHERS THEN aVALDOC := 0;aMONEDA := 0; 
          END;

        SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = v_rec.codies AND SEMNIFICATIE = 240;

        IF NR = 0 THEN
          SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
          VALUES (aCODGENERAL, 20, v_rec.codies, aMONEDA, v_rec.CURS, 240);

          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
          VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALDOC, aVALDOC, 7, 240, aCODPART);

        ELSE
          SELECT COUNT(*) INTO NR
          FROM
            OBLIGPIF O,
            GENERAL G
          WHERE
            G.TIPDOC = 20 AND G.CODDOC = v_rec.codies AND G.SEMNIFICATIE = 240
            AND O.CODGENERAL = G.CODGENERAL;

          IF NR = 0 THEN
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
            VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = v_rec.codies AND SEMNIFICATIE = 240), aVALDOC, aVALDOC, 7, 240, aCODPART);
          END IF;

          FOR V_REC_OBLIG IN
          (
            SELECT
               O.CODOBLIGPIF,
               O.CODGENERAL
            FROM
              GENERAL G,
              OBLIGPIF O
            WHERE
                  G.TIPDOC = 20
              AND G.CODDOC = v_rec.codies
              AND G.SEMNIFICATIE = 240
              AND O.CODGENERAL = G.CODGENERAL
           )
           LOOP
             UPDATE OBLIGPIF
             SET
               VALOARE = aVALDOC,
               REST    = aVALDOC
             WHERE
               CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;
           end loop;
         end if;
     end if;
   end loop;    
  end if;               
  
  commit;
end;  

END PKG_BCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BCS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D90F70618CF77DF7C5C126C63A7797700BE24AD9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BCS
IS

FUNCTION ADAUGA_ARTICOL_NOU(TIPIDART IN NUMBER, IDART IN VARCHAR2, DENART IN VARCHAR2, UM VARCHAR2, aCODPART NUMBER ) RETURN NUMBER
IS
 aCODART         NUMBER(20)   := 0; 
 aCODOBIECT      NUMBER(20)   := 0;
 aCODUM          NUMBER(20)   := 0;
 aCODUM1         NUMBER(20)   := 0;
 aCODEXTERN      VARCHAR2(80) := &apos;&apos;;
 aCODINTERN      VARCHAR2(80) := &apos;&apos;;
 aCODCNAS        VARCHAR2(20) := &apos;&apos;;
 aCODLAPARTENER  VARCHAR2(30) := &apos;&apos;;
 
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT CODUM INTO aCODUM FROM NUM WHERE UPPER(DEN_UM) = UPPER(UM);
    EXCEPTION WHEN OTHERS THEN aCODUM := 0;
  END;  
  
  IF aCODUM = 0 THEN 
    SELECT SEQ_NUM_CODUM.NEXTVAL INTO aCODUM FROM DUAL;  
    SELECT SEQ_NUM1_CODUM1.NEXTVAL INTO aCODUM1 FROM DUAL;
    
    INSERT INTO NUM  (CODUM, DEN_UM) VALUES (aCODUM, UM);   
    INSERT INTO NUM1 (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE)  VALUES (aCODUM1, aCODUM, 0, UM, 1);   
  
  END IF;
  
  SELECT SEQ_NART_CODARTICOL.NEXTVAL INTO aCODART FROM DUAL;  
  SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO aCODOBIECT FROM DUAL;  
  
  aCODEXTERN := &apos;&apos;; aCODINTERN := &apos;&apos;; 
  IF TIPIDART &lt;&gt; 3 THEN 
    IF TIPIDART = 5 -- CODLAPARTENER
    THEN aCODLAPARTENER := IDART;
    ELSE
    IF TIPIDART = 4 -- CODCNAS THEN
    THEN aCODCNAS := IDART;
    ELSE
    IF TIPIDART = 2 
      THEN aCODINTERN := IDART;
    ELSE 
      aCODEXTERN := IDART;
    END IF;
    END IF;
    END IF;
  END IF;  

  INSERT INTO NART(CODARTICOL, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE) VALUES (aCODART, DENART, 0, aCODUM, 0); 

  INSERT INTO NART1(CODARTICOL1, CODARTICOL, CODTVA, ANSTART, LUNASTART)
  VALUES (SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, PKG_CATEGCONST.GETVALCONSTANTA(&apos;TIPTVAImplicit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA);
  
  PRC_AL_REFRESH(&apos;NART1&apos;, aCODART);

  INSERT INTO NARTOBJ(CODOBIECT, CODARTICOL, CODEXTERN, CODINTERN, DENUMIRE, CODCNAS) 
    VALUES (aCODOBIECT, aCODART, aCODEXTERN, aCODINTERN, DENART, aCODCNAS);
  
  INSERT INTO NARTOBJ1(CODOBIECT1, CODOBIECT, ANSTART, LUNASTART) VALUES (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, aCODOBIECT, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA) ;
  
  PRC_AL_REFRESH(&apos;NARTOBJ1&apos;, aCODOBIECT);
  
  IF TIPIDART = 5 THEN
    INSERT INTO NARTCLI(CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN)
    VALUES(SEQ_NARTCLI_CODARTCLI.NEXTVAL, aCODOBIECT, aCODPART, DENART, aCODLAPARTENER);
  END IF;
   
  COMMIT;  

  RETURN aCODOBIECT;
  
END;

end PKG_BCS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BILANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>357BEBFA8B38129A4251B631A3DFC6FB133B89EB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BILANT IS

PROCEDURE PREPARE_AUX_TMP IS
BEGIN
  PKG_LIST_BASE_UTILS.CLEAR_SIMBOL_LIPSA;
  DELETE FROM TMP_NCONT_BAL;
  DELETE FROM TMP_NCONT1_BAL;

  INSERT INTO TMP_NCONT_BAL (
    CODCONT,
    SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL,
    CODPARINTE, NRANALITICE)
  WITH C1 AS (
    SELECT CODCONT, Max(NrAnalitice) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) NrAnalitice
    FROM ncont1
    WHERE (ANSTART * 12 + LUNASTART) &lt;= vAL
    GROUP BY CODCONT)
  SELECT
    C.CODCONT,
    C.SIMBOL, C.CLASA, C.DEN_CONT, C.NAME, C.TIPCONT, C.VIZIBILBALANTA, C.BALANTASINTETICA, C.NIVEL,
    COALESCE(C.CODPARINTE,0), COALESCE(C1.NRANALITICE, 0)
  FROM C1
    INNER JOIN NCONT C ON C.CODCONT = C1.CODCONT
  WHERE C.CODCONT &lt;&gt; 0
    AND NOT EXISTS (SELECT CONTVECHI FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= vAL )
    AND C.CLASA &lt; 8;

  INSERT INTO TMP_NCONT1_BAL ( CODCONT, FRUNZA)
  SELECT T.CODCONT, CASE WHEN EXISTS(SELECT 1 FROM TMP_NCONT_BAL X WHERE X.CODPARINTE = T.CODCONT) THEN 0 ELSE 1 END FRUNZA
  FROM TMP_NCONT_BAL T;
END;

PROCEDURE PREPARE_TMP_CDS_BILANT IS
BEGIN
  INSERT INTO TMP_CDS_BILANT (
    cod, scont, dcont, clasa, tcont,
    trd, trc, soldfind, soldfinc,
    codref, sref, tref,
    nivel, nranalitice,
    refnivel, refnranalitice,
    codparinte,
    soldid, precedentd, curentd, soldic, precedentc, curentc,
    asoldid, asoldic, aprecedentd, acurentd, aprecedentc, acurentc, asoldfind, asoldfinc,
    siipd, siipc, siicd, siicc)
	WITH /*RECURSIVE*/ aa (CODCONT, SIMBOL, DEN_CONT, CLASA, TIPCONT, NIVEL, NRANALITICE, CODPARINTE) AS (
	  SELECT CODCONT, SIMBOL, DEN_CONT, clasa, TIPCONT, NIVEL, NRANALITICE, CODPARINTE
	  FROM TMP_NCONT_BAL
	  WHERE COALESCE(CODPARINTE, 0) = 0
    UNION ALL
	  SELECT O.CODCONT, O.SIMBOL, O.DEN_CONT, O.CLASA, O.TIPCONT, O.NIVEL, O.NRANALITICE, O.CODPARINTE
	  FROM TMP_NCONT_BAL O INNER JOIN AA A ON A.CODCONT = O.CODPARINTE
	)
  SELECT
    CODCONT cod, SubStrB(SIMBOL,1,30) scont, SubStrB(DEN_CONT,1,100) dcont, clasa, Coalesce(TIPCONT,0)+1 tcont, -- tcont pe MENTOR e 1,2,3
    0 trd, 0 trc, 0 soldfind, 0 soldfinc,
    NULL codref, NULL sref, NULL tref,
    nivel, nranalitice,
    NULL refnivel, NULL refnranalitice,
    codparinte,
    0 soldid, 0 precedentd, 0 curentd, 0 soldic, 0 precedentc, 0 curentc,
    0 asoldid, 0 asoldic, 0 aprecedentd, 0 acurentd, 0 aprecedentc, 0 acurentc, 0 asoldfind, 0 asoldfinc,
    0 siipd, 0 siipc, 0 siicd, 0 siicc
  FROM AA;
END;


PROCEDURE UPDATE_DATA(
  pcodcont  IN NUMBER,
  psoldid   IN NUMBER, psoldic   IN NUMBER,
  prulajpd  IN NUMBER, prulajpc  IN NUMBER,
  prulajcd  IN NUMBER, prulajcc  IN NUMBER,
  pasoldid  IN NUMBER, pasoldic  IN NUMBER,
  parulajpd IN NUMBER, parulajpc IN NUMBER,
  parulajcd IN NUMBER, parulajcc IN NUMBER,
  psiipd    IN NUMBER, psiipc    IN NUMBER,
  psiicd    IN NUMBER, psiicc    IN NUMBER
) IS
  vCodP      NUMBER(20);
BEGIN
  BEGIN
    UPDATE TMP_CDS_BILANT
    SET soldid      = soldid      + psoldid,
        soldic      = soldic      + psoldic,
        precedentd  = precedentd  + prulajpd,
        precedentc  = precedentc  + prulajpc,
        curentd     = curentd     + prulajcd,
        curentc     = curentc     + prulajcc,
        asoldid     = asoldid     + pasoldid,
        asoldic     = asoldic     + pasoldic,
        aprecedentd = aprecedentd + parulajpd,
        aprecedentc = aprecedentc + parulajpc,
        acurentd    = acurentd    + parulajcd,
        acurentc    = acurentc    + parulajcc,
        siipd       = siipd       + psiipd,
        siipc       = siipc       + psiipc,
        siicd       = siicd       + psiicd,
        siicc       = siicc       + psiicc
    WHERE Cod = pCodCont
    RETURNING codparinte INTO vCodP;
  EXCEPTION
    WHEN No_Data_Found THEN vCodP := 0;
  END;

  IF vCodP &lt;&gt; 0 THEN
    UPDATE_DATA(
      vCodP,
      psoldid  , psoldic  ,
      prulajpd , prulajpc ,
      prulajcd , prulajcc ,
      pasoldid , pasoldic ,
      parulajpd, parulajpc,
      parulajcd, parulajcc,
      psiipd,    psiipc,
      psiicd,    psiicc
    );
  END IF;
END;

PROCEDURE PARSE_DATA IS
BEGIN
  FOR v_rec IN (
    SELECT
      codcont,
      SUM(CASE WHEN an = vAN THEN soldid  ELSE 0 END) soldid,   SUM(CASE WHEN an = vAN THEN soldic  ELSE 0 END) soldic,
      SUM(CASE WHEN an = vAN THEN rulajpd ELSE 0 END) rulajpd,  SUM(CASE WHEN an = vAN THEN rulajpc ELSE 0 END) rulajpc,
      SUM(CASE WHEN an = vAN THEN rulajcd ELSE 0 END) rulajcd,  SUM(CASE WHEN an = vAN THEN rulajcc ELSE 0 END) rulajcc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE soldid  END) asoldid,  SUM(CASE WHEN an = vAN THEN 0 ELSE soldic  END) asoldic,
      SUM(CASE WHEN an = vAN THEN 0 ELSE rulajpd END) arulajpd, SUM(CASE WHEN an = vAN THEN 0 ELSE rulajpc END) arulajpc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE rulajcd END) arulajcd, SUM(CASE WHEN an = vAN THEN 0 ELSE rulajcc END) arulajcc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE siid    END) siipd,    SUM(CASE WHEN an = vAN THEN 0 ELSE siic    END) siipc,
      SUM(CASE WHEN an = vAN THEN siid    ELSE 0 END) siicd,    SUM(CASE WHEN an = vAN THEN siic    ELSE 0 END) siicc
    FROM  (
      SELECT
        c.codcont, b.an,
        COALESCE(b.soldid,0) soldid, COALESCE(b.soldic,0) soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        0 siid, 0 siic
      FROM ncontsold B INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = B.CODCONT
      WHERE (COALESCE(b.soldid,0) &lt;&gt; 0 OR COALESCE(b.soldic,0) &lt;&gt; 0)
        AND b.an IN (vAN-1,vAn) AND b.luna = 1
        AND c.codcont &lt;&gt; 0
        AND c.frunza = 1
      UNION ALL
      SELECT
        c.codcont, b.an,
        0 soldid, 0 soldic,
        COALESCE(b.rulajpd, 0) rulajpd, COALESCE(b.rulajpc, 0) rulajpc,
        COALESCE(b.rulajcd, 0) rulajcd, COALESCE(b.rulajcc, 0) rulajcc,
        0 siid, 0 siic
      FROM ncontrul B INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = B.CODCONT
      WHERE (COALESCE(b.rulajpd, 0) &lt;&gt; 0 OR COALESCE(b.rulajpc, 0) &lt;&gt; 0 OR COALESCE(b.rulajcd, 0) &lt;&gt; 0 OR COALESCE(b.rulajcc, 0) &lt;&gt; 0)
        AND b.an IN (vAn-1,vAn) AND b.luna = vLuna
        AND c.codcont &lt;&gt; 0
        AND c.frunza = 1
      UNION ALL
      SELECT
        c.codcont, j.an,
        0 soldid, 0 soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        valoare siid, 0 siic
      FROM jurnal j INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = J.CONTD
      WHERE j.an IN (vAn-1,vAn)
        AND j.luna BETWEEN 1 AND vLuna
        AND j.tipdoc = 32
      UNION ALL
      SELECT
        c.codcont, j.an,
        0 soldid, 0 soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        0 siid, valoare siic
      FROM jurnal j INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = J.CONTD
      WHERE j.an IN (vAn-1,vAn)
        AND j.luna BETWEEN 1 AND vLuna
        AND j.tipdoc = 32
    ) A_PG
    GROUP BY codcont
  ) LOOP
    UPDATE_DATA(
      v_rec.codcont,
      v_rec.soldid,   v_rec.soldic,
      v_rec.rulajpd,  v_rec.rulajpc,
      v_rec.rulajcd,  v_rec.rulajcc,
      v_rec.asoldid,  v_rec.asoldic,
      v_rec.arulajpd, v_rec.arulajpc,
      v_rec.arulajcd, v_rec.arulajcc,
      v_rec.siipd,    v_rec.siipc,
      v_rec.siicd,    v_rec.siicc
    );
  END LOOP;
END;

PROCEDURE PARSE_DATA_SUBUNIT(pSubunit NUMBER) IS
BEGIN
  FOR v_rec IN (
    SELECT
      codcont,
      SUM(CASE WHEN an = vAN THEN soldid  ELSE 0 END) soldid,   SUM(CASE WHEN an = vAN THEN soldic  ELSE 0 END) soldic,
      SUM(CASE WHEN an = vAN THEN rulajpd ELSE 0 END) rulajpd,  SUM(CASE WHEN an = vAN THEN rulajpc ELSE 0 END) rulajpc,
      SUM(CASE WHEN an = vAN THEN rulajcd ELSE 0 END) rulajcd,  SUM(CASE WHEN an = vAN THEN rulajcc ELSE 0 END) rulajcc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE soldid  END) asoldid,  SUM(CASE WHEN an = vAN THEN 0 ELSE soldic  END) asoldic,
      SUM(CASE WHEN an = vAN THEN 0 ELSE rulajpd END) arulajpd, SUM(CASE WHEN an = vAN THEN 0 ELSE rulajpc END) arulajpc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE rulajcd END) arulajcd, SUM(CASE WHEN an = vAN THEN 0 ELSE rulajcc END) arulajcc,
      SUM(CASE WHEN an = vAN THEN 0 ELSE siid    END) siipd,    SUM(CASE WHEN an = vAN THEN 0 ELSE siic    END) siipc,
      SUM(CASE WHEN an = vAN THEN siid    ELSE 0 END) siicd,    SUM(CASE WHEN an = vAN THEN siic    ELSE 0 END) siicc
    FROM  (
      SELECT
        c.codcont, bf.an,
        COALESCE(b.soldid,0) soldid, COALESCE(b.soldic,0) soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        0 siid, 0 siic
      FROM ncontsold BF
        INNER JOIN ncontsoldsub B ON B.CODCONTSOLD = BF.CODCONTSOLD
        INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = BF.CODCONT
      WHERE (COALESCE(b.soldid,0) &lt;&gt; 0 OR COALESCE(b.soldic,0) &lt;&gt; 0)
        AND bf.an IN (vAN-1,vAn) AND bf.luna = 1
        AND b.Subunitatea = pSubunit
        AND c.codcont &lt;&gt; 0
        AND c.frunza = 1
      UNION ALL
      SELECT
        c.codcont, bf.an,
        0 soldid, 0 soldic,
        COALESCE(b.rulajpd, 0) rulajpd, COALESCE(b.rulajpc, 0) rulajpc,
        COALESCE(b.rulajcd, 0) rulajcd, COALESCE(b.rulajcc, 0) rulajcc,
        0 siid, 0 siic
      FROM ncontrul BF
        INNER JOIN ncontrulsub B ON BF.CODCONTRUL = B.CODCONTRUL
        INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = BF.CODCONT
      WHERE (COALESCE(b.rulajpd, 0) &lt;&gt; 0 OR COALESCE(b.rulajpc, 0) &lt;&gt; 0 OR COALESCE(b.rulajcd, 0) &lt;&gt; 0 OR COALESCE(b.rulajcc, 0) &lt;&gt; 0)
        AND bf.an IN (vAn-1,vAn) AND bf.luna = vLuna
        AND b.Subunitatea = pSubunit
        AND c.codcont &lt;&gt; 0
        AND c.frunza = 1
      UNION ALL
      SELECT
        c.codcont, j.an,
        0 soldid, 0 soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        valoare siid, 0 siic
      FROM jurnal j INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = J.CONTD
      WHERE j.an IN (vAn-1,vAn)
        AND j.luna BETWEEN 1 AND vLuna
        AND j.tipdoc = 32
        AND j.Subunitatea = pSubunit
      UNION ALL
      SELECT
        c.codcont, j.an,
        0 soldid, 0 soldic,
        0 rulajpd, 0 rulajpc,
        0 rulajcd, 0 rulajcc,
        0 siid, valoare siic
      FROM jurnal j INNER JOIN TMP_NCONT1_BAL C ON C.CODCONT = J.CONTD
      WHERE j.an IN (vAn-1,vAn)
        AND j.luna BETWEEN 1 AND vLuna
        AND j.tipdoc = 32
        AND j.Subunitatea = pSubunit
    )
    GROUP BY codcont
  ) LOOP
    UPDATE_DATA(
      v_rec.codcont,
      v_rec.soldid,   v_rec.soldic,
      v_rec.rulajpd,  v_rec.rulajpc,
      v_rec.rulajcd,  v_rec.rulajcc,
      v_rec.asoldid,  v_rec.asoldic,
      v_rec.arulajpd, v_rec.arulajpc,
      v_rec.arulajcd, v_rec.arulajcc,
      v_rec.siipd,    v_rec.siipc,
      v_rec.siicd,    v_rec.siicc) ;
  END LOOP;
END;

PROCEDURE REFINE_DATA IS
BEGIN
  -- stef tipcont e +1 fata de bd ca sa fie ca in Declaratii (1,2,3)
  UPDATE TMP_CDS_BILANT
  SET trd       = precedentd + curentd,
      trc       = precedentc + curentc,
      soldfind  = CASE
                    WHEN clasa IN (6,7) THEN 0
                    WHEN tcont = 1 THEN soldid + precedentd + curentd - soldic - precedentc - curentc
                    WHEN tcont = 2 THEN 0
                    WHEN soldid + precedentd + curentd &gt; soldic + precedentc + curentc THEN soldid + precedentd + curentd - soldic - precedentc - curentc
                    ELSE 0
                  END,
      soldfinc  = CASE
                    WHEN clasa IN (6,7) THEN 0
                    WHEN tcont = 1 THEN 0
                    WHEN tcont = 2 THEN soldic + precedentc + curentc - soldid - precedentd - curentd
                    WHEN soldid + precedentd + curentd &lt; soldic + precedentc + curentc THEN soldic + precedentc + curentc - soldid - precedentd - curentd
                    ELSE 0
                  END,
      asoldfind = CASE
                    WHEN clasa IN (6,7) THEN 0
                    WHEN tcont = 1 THEN asoldid + aprecedentd + acurentd - asoldic - aprecedentc - acurentc
                    WHEN tcont = 2 THEN 0
                    WHEN asoldid + aprecedentd + acurentd &gt; asoldic + aprecedentc + acurentc THEN asoldid + aprecedentd + acurentd - asoldic - aprecedentc - acurentc
                    ELSE 0
                  END,
      asoldfinc = CASE
                    WHEN clasa IN (6,7) THEN 0
                    WHEN tcont = 1 THEN 0
                    WHEN tcont = 2 THEN soldic + aprecedentc + acurentc - asoldid - aprecedentd - acurentd
                    WHEN asoldid + aprecedentd + acurentd &lt; asoldic + aprecedentc + acurentc THEN asoldic + aprecedentc + acurentc - asoldid - aprecedentd - acurentd
                    ELSE 0
                  END;
END;

PROCEDURE UMPLE_TMP_CDS_BILANT(pAn NUMBER, pLuna NUMBER, pSubunit NUMBER) IS
BEGIN
  vAn   := pAn;
  vLuna := pLuna;
  vAL   := vAn*12+vLuna;
  DELETE TMP_CDS_BILANT;
  PREPARE_AUX_TMP;
  PREPARE_TMP_CDS_BILANT;
  IF pSubunit = 1
  THEN PARSE_DATA;
  ELSE PARSE_DATA_SUBUNIT(pSubunit);
  END IF;
  REFINE_DATA;
  COMMIT;
END;

END pkg_bilant;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BONMASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6409EEF9C9DB516053A92F17B4AFE0A8B44AF44</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BONMASA is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT COD INTO Tmp FROM BONMASA WHERE COD = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM BONMASA WHERE COD = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_BONMASA FIELDS( COD ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_BONMASA SELECT * FROM BONMASA WHERE COD = RECID;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT COD INTO RECID FROM TMP_BONMASA;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE BONMASA
    SET
     (DENUMIRE, VALOARE) = (SELECT DENUMIRE, VALOARE FROM TMP_BONMASA)
    WHERE
      COD = RECID;
  ELSE  -- INSERT
    SELECT SEQ_BONMASA_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO BONMASA(COD, DENUMIRE, VALOARE)
    SELECT RECID, DENUMIRE, VALOARE FROM TMP_BONMASA;
  END IF; 

  NotifyModif(Operation, RecId, &apos;BONMASA&apos;);
  COMMIT;
  
END;


end PKG_BONMASA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BUGETMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE6A32D2E9A3E7A23400554CEBB2F3A832271DAA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BUGETMF IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_63&apos;;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodBugetMF INTO Tmp FROM BUGETMF WHERE CodBugetMF = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);  
BEGIN
  SP_LOCKRECORD(RecId);
  
  SELECT B.DATACREARE, B.SUBUNITATEA, M.NRINVENTAR
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM BUGETMF B
       LEFT JOIN MIFIX M ON M.CODMIFIX = B.CODMIFIX
  WHERE CODBUGETMF = RecID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
  THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BUGETMF&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE FROM BUGETMF1 WHERE CodBugetMF = RecId;
  DELETE FROM BUGETMF WHERE CodBugetMF = RecId;
  
  NotifyModif(2, RecId, &apos;BUGETMF&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
vZi varchar(2);
vLuna varchar2(2);
vAn varchar2(4);
BEGIN
  INSERT INTO TMP_BUGETMF(CodBugetMF) VALUES (0);
  vLuna := LPad(to_char(pkg_globals.GetLUNALUCRU),2,&apos;0&apos;);
  vAn   := to_char(pkg_globals.GetANLUCRU);
  vZi   := LPad(to_char(Extract(day from sysdate)), 2, &apos;0&apos;);
  if to_number(vZi) &gt; Extract(Day from Last_Day(to_date(&apos;01.&apos;||vLuna||&apos;.&apos;||vAn, &apos;dd.mm.yyyy&apos;))) then
    vZi := LPad(to_char(Extract (Day from Last_Day(to_date(&apos;01.&apos;||vLuna||&apos;.&apos;||vAn, &apos;dd.mm.yyyy&apos;)))), 2, &apos;0&apos;);
  end if;
  INSERT INTO TMP_BUGETMF1(CODBUGETMF1,CODBUGETMF, DATABUGET, INDEXLOCAL, DENUMIRE, STADIU) VALUES (-1,0, to_date(vZi||&apos;.&apos;||vLuna||&apos;.&apos;||vAn,&apos;dd.mm.yyyy&apos;), 1, &apos;Buget alocat&apos;, 0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
vDataMin date;  
BEGIN
  INSERT INTO TMP_BUGETMF(CODBUGETMF, CODMIFIX, USERID, SUBUNITATEA, DATACREARE, NRINVENTAR, CODOBIECT, DENUMIRE)
  SELECT BG.CODBUGETMF, BG.CODMIFIX, BG.USERID, BG.SUBUNITATEA, BG.DATACREARE, MF.NRINVENTAR, NS.CODOBIECT, OBJ.DENUMIRE
  FROM BUGETMF BG
       INNER JOIN MIFIX MF ON MF.CODMIFIX = BG.CODMIFIX
       INNER JOIN MIFIX1 MF1 ON MF.CODMIFIX = MF1.CODMIFIX AND MF1.ANSTART*12+MF1.LUNASTART = PKG_GLOBALS.GetANLUCRU * 12 + PKG_GLOBALS.GetLUNALUCRU 
       INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
  WHERE CODBUGETMF = RECID;
  
  INSERT INTO TMP_BUGETMF1(CODBUGETMF1, CODBUGETMF, INDEXLOCAL, DENUMIRE, VALOARE, DATABUGET, OBS, STADIU, OLDSTADIU)
  SELECT CODBUGETMF1, CODBUGETMF, INDEXLOCAL, DENUMIRE, VALOARE, DATABUGET, OBS, STADIU, STADIU
  FROM BUGETMF1
  WHERE CODBUGETMF = RECID;
  
  for v_rec in (select databuget
                from tmp_bugetmf1
                order by databuget
               ) loop
    vDataMin := v_rec.databuget;
    Exit;           
  end loop;             
  
  update tmp_bugetmf b set
  total = (select sum(nvl(valoare,0)) from tmp_bugetmf1),
  totalaprobat = (select sum(nvl(valoare,0)) from tmp_bugetmf1 where stadiu in (1,3)),
  achizitii = (select sum(case 
                            when nvl(i.moneda,0) = 0 then 1 
                            else i.curs 
                          end  
                          * nvl(l.cant, i1.cant) * i1.pu) 
               from intrari1 i1 
                    inner join intrari i on i1.codintr = i.codintr
                    left join intrlink l on l.codintr1 = i1.codintr1
                    left join comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
                    left join comanda c on c1.codcomanda = c.codcomanda
               where i1.codmifix = b.codmifix and nvl(i.anulat,0) = 0
                     and i.datadoc &gt;= vdatamin
               ),
  comenzi = (select nvl(sum(case when nvl(c.moneda,0) = 0 then 1 else c.curs end * (c1.cantacceptat - nvl(storno.cant,0)) * c1.pu - 
                    case when nvl(c.moneda,0) = 0 then 1 else c.curs end * nvl(fact.cant,0) * c1.pu +
                    nvl(fact.valoare,0)
                    ),0)
             from comanda1 c1
                  inner join comanda c on c1.codcomanda = c.codcomanda
                  left  join (select l.codliniecomanda, sum(l.cant) cant,
                              sum(case 
                                    when nvl(i.moneda,0) = 0 then 1 
                                    else i.curs 
                                  end * l.cant * i1.pu) valoare
                              from intrlink l 
                                   inner join intrari1 i1 on i1.codintr1 = l.codintr1
                                   inner join intrari i on i.codintr = i1.codintr
                                   inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1
                                   inner join comanda c on c1.codcomanda = c.codcomanda
                              where nvl(i.anulat,0) = 0     
                              group by l.codliniecomanda) fact on fact.codliniecomanda = c1.codcomanda1
                  left  join (select l.codliniecomanda, sum(l.cant) cant from cmdlivrlink l group by l.codliniecomanda) storno on storno.codliniecomanda = c1.codcomanda1
             where c1.codmifix = b.codmifix and nvl(c.anulat,0) = 0 and c.datadoc &gt;= vDataMin
             );
  update tmp_bugetmf b set
  comenzi = comenzi +
            (select nvl(sum(case when nvl(i.moneda,0) = 0 then 1 else i.curs end * i1.cant * i1.pu),0) val
             from intrari1 i1
                  inner join intrari i on i1.codintr = i.codintr
                  left join intrlink l on l.codintr1 = i1.codintr1
             where i1.codmifix = b.codmifix and nvl(i.anulat,0) = 0
                   and nvl(l.codintr1,0) = 0 and i.datadoc &gt;= vDataMin);
             
  UPDATE TMP_BUGETMF SET
  REST = NVL(TOTAL,0) - NVL(ACHIZITII,0);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);
aValoare    NUMBER(20,7);  
BEGIN
  SELECT B.DATACREARE, B.SUBUNITATEA, M.NRINVENTAR
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM TMP_BUGETMF B
       LEFT JOIN MIFIX M ON M.CODMIFIX = B.CODMIFIX;
       
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODBUGETMF INTO RecId FROM TMP_BUGETMF;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BUGETMF&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE BUGETMF SET CODMIFIX = 
    (select CODMIFIX from tmp_bugetmf)
    WHERE CodBUGETMF = RecId;
    
    DELETE FROM BUGETMF1 BG1 WHERE BG1.CODBUGETMF = RECID AND NOT BG1.CODBUGETMF1 IN (SELECT CODBUGETMF1 FROM TMP_BUGETMF1);
    FOR V_REC IN (SELECT * FROM TMP_BUGETMF1) LOOP
      IF V_REC.CODBUGETMF1 &gt; 0 THEN
        UPDATE BUGETMF1 SET
          INDEXLOCAL = V_REC.INDEXLOCAL, 
          DENUMIRE   = V_REC.DENUMIRE, 
          VALOARE    = V_REC.VALOARE, 
          DATABUGET  = V_REC.DATABUGET, 
          OBS        = V_REC.OBS, 
          STADIU     = V_REC.STADIU
        WHERE CODBUGETMF1 = V_REC.CODBUGETMF1;
      ELSE 
        INSERT INTO BUGETMF1 (CODBUGETMF1, CODBUGETMF, INDEXLOCAL, DENUMIRE, VALOARE, DATABUGET, OBS, STADIU)
        VALUES (SEQ_BUGETMF1_CODBUGETMF1.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.DENUMIRE, V_REC.VALOARE, V_REC.DATABUGET, V_REC.OBS, V_REC.STADIU); 
      END IF;
    END LOOP;
  ELSE  
    SELECT SEQ_BUGETMF_CODBUGETMF.NextVal INTO RecId FROM DUAL;
    
    select valoare into avaloare from tmp_bugetmf1 where rownum = 1;
    insert into x(test) values (&apos;val: &apos;||aValoare); 
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;BUGETMF&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    
    INSERT INTO BUGETMF (CODBUGETMF, CODMIFIX, USERID, SUBUNITATEA, DATACREARE)
    SELECT RECID, CODMIFIX, PKG_GLOBALS.GETUSERID, PKG_GLOBALS.GETSUBUNITATE, SYSDATE
    FROM TMP_BUGETMF;
    
    INSERT INTO BUGETMF1(CODBUGETMF1, CODBUGETMF, INDEXLOCAL, DENUMIRE, VALOARE, DATABUGET, OBS, STADIU)
    SELECT SEQ_BUGETMF1_CODBUGETMF1.NEXTVAL, RECID, INDEXLOCAL, DENUMIRE, VALOARE, DATABUGET, OBS, STADIU
    FROM TMP_BUGETMF1;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;BUGETMF&apos;);
  COMMIT;
END;

end PKG_BUGETMF; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4035266D0C286F190BE66F1C5D32C9EEE461A1B1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BUGETPROD is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CODBUGETPROD INTO Tmp FROM BUGETPROD WHERE CODBUGETPROD = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  
  DELETE FROM BUGETPRODV WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETPRODT WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETPRODP WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETVCL   WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETCAP1  WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETCAP   WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETSTOC  WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETVL    WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETCL    WHERE CODBUGETPROD = RECID;
  DELETE FROM BUGETPROD  WHERE CODBUGETPROD = RECID;
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
LastCod number(20);
aAnImport number(4);
aSaptamana number(2);
aAnF number(4);
aSaptamanaF number(2);
BEGIN
  aAnImport   := pkg_globals.GetANLUCRU;
  aSaptamana  := to_number(TO_CHAR(sysdate,&apos;IW&apos;));
  aSaptamanaF := to_number(to_char(to_date(&apos;31.12.&apos;||aAnImport, &apos;dd.mm.yyyy&apos;),&apos;IW&apos;));
  if aSaptamanaF = 1 then aSaptamanaF := 52; end if;
  aAnF        := aAnImport;
  
  INSERT INTO TMP_BUGETPROD FIELDS(CODBUGETPROD, Saptamana, AnImport, SaptamanaF, AnF) VALUES (0, aSaptamana, aAnImport, aSaptamanaF, aAnF);

  begin
    select max(CodBugetProd) into LastCod from bugetprod;
  exception when others then LastCod := 0;
  end;
  
  if LastCod &gt; 0 then
    insert into tmp_bugetcap (codbugetcap, codbugetprod, tipcap, codclasea, den_clasea)
    select - RowNum, 0, b.tipcap, b.codclasea, c.den_clasea
    from bugetcap b
         left join nclasea c on c.codclasea = b.codclasea
    where codbugetprod = lastcod;
    insert into tmp_bugetcapc(codbugetcap1, codclasea, den_clasea, tipcap)
    select - rownum, b.codclasea, c.den_clasea, 1
    from bugetcap b
         left join nclasea c on c.codclasea = b.codclasea
    where b.tipcap = 1 and b.codbugetprod = lastcod;
    insert into tmp_bugetcapv(codbugetcap1, codclasea, den_clasea, tipcap)
    select - rownum, b.codclasea, c.den_clasea, 2
    from bugetcap b
         left join nclasea c on c.codclasea = b.codclasea
    where b.tipcap = 2 and b.codbugetprod = LastCod;
  end if;
  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;;&apos;);  
  INSERT INTO TMP_BUGETPROD(CODBUGETPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF, DATASTART, DATASTOP)
  SELECT CODBUGETPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF,
         iso_week_to_date(animport, saptamana),
         iso_week_to_date(animport, saptamana) + 6
  FROM BUGETPROD 
  WHERE CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETPRODV(
    CODBUGETPRODV, CODBUGETPROD, CODOBIECT, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, 
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
    S50, S51, S52, S53,
    L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12,
    DENUMIRE, CODEXTERN, CODINTERN)
  SELECT 
    B.CODBUGETPRODV, B.CODBUGETPROD, B.CODOBIECT, 
    B.S1, B.S2, B.S3, B.S4, B.S5, B.S6, B.S7, B.S8, B.S9, 
    B.S10, B.S11, B.S12, B.S13, B.S14, B.S15, B.S16, B.S17, B.S18, B.S19, 
    B.S20, B.S21, B.S22, B.S23, B.S24, B.S25, B.S26, B.S27, B.S28, B.S29, 
    B.S30, B.S31, B.S32, B.S33, B.S34, B.S35, B.S36, B.S37, B.S38, B.S39, 
    B.S40, B.S41, B.S42, B.S43, B.S44, B.S45, B.S46, B.S47, B.S48, B.S49, 
    B.S50, B.S51, B.S52, B.S53,
    B.L1, B.L2, B.L3, B.L4, B.L5, B.L6, B.L7, B.L8, B.L9, B.L10, B.L11, B.L12,
    O.DENUMIRE, O.CODEXTERN, O.CODINTERN 
  FROM BUGETPRODV B
       INNER JOIN NARTOBJ O ON O.CODOBIECT = B.CODOBIECT 
  WHERE B.CODBUGETPROD = RECID;   
  
  INSERT INTO TMP_BUGETPRODT(
    CODBUGETPRODT, CODBUGETPROD, CODOBIECT, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, 
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
    S50, S51, S52, S53,
    L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12,
    DENUMIRE, CODEXTERN, CODINTERN)
  SELECT 
    B.CODBUGETPRODT, B.CODBUGETPROD, B.CODOBIECT, 
    B.S1, B.S2, B.S3, B.S4, B.S5, B.S6, B.S7, B.S8, B.S9, 
    B.S10, B.S11, B.S12, B.S13, B.S14, B.S15, B.S16, B.S17, B.S18, B.S19, 
    B.S20, B.S21, B.S22, B.S23, B.S24, B.S25, B.S26, B.S27, B.S28, B.S29, 
    B.S30, B.S31, B.S32, B.S33, B.S34, B.S35, B.S36, B.S37, B.S38, B.S39, 
    B.S40, B.S41, B.S42, B.S43, B.S44, B.S45, B.S46, B.S47, B.S48, B.S49, 
    B.S50, B.S51, B.S52, B.S53,
    B.L1, B.L2, B.L3, B.L4, B.L5, B.L6, B.L7, B.L8, B.L9, B.L10, B.L11, B.L12,
    O.DENUMIRE, O.CODEXTERN, O.CODINTERN 
  FROM BUGETPRODT B
       INNER JOIN NARTOBJ O ON O.CODOBIECT = B.CODOBIECT 
  WHERE B.CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETPRODP(
    CODBUGETPRODP, CODBUGETPROD, CODOBIECT, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, 
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
    S50, S51, S52, S53,
    L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, 
    DENUMIRE, CODEXTERN, CODINTERN)
  SELECT 
    B.CODBUGETPRODP, B.CODBUGETPROD, B.CODOBIECT, 
    B.S1, B.S2, B.S3, B.S4, B.S5, B.S6, B.S7, B.S8, B.S9, 
    B.S10, B.S11, B.S12, B.S13, B.S14, B.S15, B.S16, B.S17, B.S18, B.S19, 
    B.S20, B.S21, B.S22, B.S23, B.S24, B.S25, B.S26, B.S27, B.S28, B.S29, 
    B.S30, B.S31, B.S32, B.S33, B.S34, B.S35, B.S36, B.S37, B.S38, B.S39, 
    B.S40, B.S41, B.S42, B.S43, B.S44, B.S45, B.S46, B.S47, B.S48, B.S49,
    B.S50, B.S51, B.S52, B.S53,
    B.L1, B.L2, B.L3, B.L4, B.L5, B.L6, B.L7, B.L8, B.L9, B.L10, B.L11, B.L12,
    O.DENUMIRE, O.CODEXTERN, O.CODINTERN
  FROM BUGETPRODP B
       INNER JOIN NARTOBJ O ON O.CODOBIECT = B.CODOBIECT
  WHERE B.CODBUGETPROD = RECID;

  INSERT INTO TMP_BUGETCAP (CODBUGETCAP, CODBUGETPROD, TIPCAP, CODCLASEA, DEN_CLASEA)
  SELECT B.CODBUGETCAP, B.CODBUGETPROD, B.TIPCAP, B.CODCLASEA, C.DEN_CLASEA
  FROM BUGETCAP B
       INNER JOIN NCLASEA C ON C.CODCLASEA = B.CODCLASEA
  WHERE B.CODBUGETPROD = RECID;

  INSERT INTO TMP_BUGETCAPC(
    CODBUGETCAP1, CODBUGETPROD, CODCLASEA, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, 
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
    S50, S51, S52, S53,
    L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, 
    DEN_CLASEA, TIPCAP)
  SELECT 
    B.CODBUGETCAP1, B.CODBUGETPROD, B.CODCLASEA, 
    B.S1, B.S2, B.S3, B.S4, B.S5, B.S6, B.S7, B.S8, B.S9, 
    B.S10, B.S11, B.S12, B.S13, B.S14, B.S15, B.S16, B.S17, B.S18, B.S19, 
    B.S20, B.S21, B.S22, B.S23, B.S24, B.S25, B.S26, B.S27, B.S28, B.S29, 
    B.S30, B.S31, B.S32, B.S33, B.S34, B.S35, B.S36, B.S37, B.S38, B.S39, 
    B.S40, B.S41, B.S42, B.S43, B.S44, B.S45, B.S46, B.S47, B.S48, B.S49,
    B.S50, B.S51, B.S52, B.S53,
    B.L1, B.L2, B.L3, B.L4, B.L5, B.L6, B.L7, B.L8, B.L9, B.L10, B.L11, B.L12,
    C.DEN_CLASEA, 1
  FROM BUGETCAP1 B
       INNER JOIN BUGETCAP BC ON BC.CODCLASEA = B.CODCLASEA AND BC.CODBUGETPROD = B.CODBUGETPROD
       INNER JOIN NCLASEA C ON C.CODCLASEA = B.CODCLASEA
  WHERE B.CODBUGETPROD = RECID AND BC.TIPCAP = 1;
  
  INSERT INTO TMP_BUGETCAPV(
    CODBUGETCAP1, CODBUGETPROD, CODCLASEA, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, 
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
    S50, S51, S52, S53,
    L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, 
    DEN_CLASEA, TIPCAP)
  SELECT 
    B.CODBUGETCAP1, B.CODBUGETPROD, B.CODCLASEA, 
    B.S1, B.S2, B.S3, B.S4, B.S5, B.S6, B.S7, B.S8, B.S9, 
    B.S10, B.S11, B.S12, B.S13, B.S14, B.S15, B.S16, B.S17, B.S18, B.S19, 
    B.S20, B.S21, B.S22, B.S23, B.S24, B.S25, B.S26, B.S27, B.S28, B.S29, 
    B.S30, B.S31, B.S32, B.S33, B.S34, B.S35, B.S36, B.S37, B.S38, B.S39, 
    B.S40, B.S41, B.S42, B.S43, B.S44, B.S45, B.S46, B.S47, B.S48, B.S49,
    B.S50, B.S51, B.S52, B.S53,
    B.L1, B.L2, B.L3, B.L4, B.L5, B.L6, B.L7, B.L8, B.L9, B.L10, B.L11, B.L12,
    C.DEN_CLASEA, 2
  FROM BUGETCAP1 B
       INNER JOIN BUGETCAP BC ON BC.CODCLASEA = B.CODCLASEA AND BC.CODBUGETPROD = B.CODBUGETPROD 
       INNER JOIN NCLASEA C ON C.CODCLASEA = B.CODCLASEA
  WHERE B.CODBUGETPROD = RECID AND BC.TIPCAP = 2;
  
  INSERT INTO TMP_BUGETVCL(
    codbugetvcl,codbugetprod,codobiect,codclasea,tipcap,coefum,
    l1_cap,l1_stoc,l1_vanz,l1_target,l1_npcant,l1_pret,l1_npval,l1_coefcap,l1_npfcant,l1_npfval,l1_pretmmr,l1_pretmat,l1_var,l1_est,
    l2_cap,l2_stoc,l2_vanz,l2_target,l2_npcant,l2_pret,l2_npval,l2_coefcap,l2_npfcant,l2_npfval,l2_pretmmr,l2_pretmat,l2_var,l2_est,
    l3_cap,l3_stoc,l3_vanz,l3_target,l3_npcant,l3_pret,l3_npval,l3_coefcap,l3_npfcant,l3_npfval,l3_pretmmr,l3_pretmat,l3_var,l3_est,
    l4_cap,l4_stoc,l4_vanz,l4_target,l4_npcant,l4_pret,l4_npval,l4_coefcap,l4_npfcant,l4_npfval,l4_pretmmr,l4_pretmat,l4_var,l4_est,
    l5_cap,l5_stoc,l5_vanz,l5_target,l5_npcant,l5_pret,l5_npval,l5_coefcap,l5_npfcant,l5_npfval,l5_pretmmr,l5_pretmat,l5_var,l5_est,
    l6_cap,l6_stoc,l6_vanz,l6_target,l6_npcant,l6_pret,l6_npval,l6_coefcap,l6_npfcant,l6_npfval,l6_pretmmr,l6_pretmat,l6_var,l6_est,
    l7_cap,l7_stoc,l7_vanz,l7_target,l7_npcant,l7_pret,l7_npval,l7_coefcap,l7_npfcant,l7_npfval,l7_pretmmr,l7_pretmat,l7_var,l7_est,
    l8_cap,l8_stoc,l8_vanz,l8_target,l8_npcant,l8_pret,l8_npval,l8_coefcap,l8_npfcant,l8_npfval,l8_pretmmr,l8_pretmat,l8_var,l8_est,
    l9_cap,l9_stoc,l9_vanz,l9_target,l9_npcant,l9_pret,l9_npval,l9_coefcap,l9_npfcant,l9_npfval,l9_pretmmr,l9_pretmat,l9_var,l9_est,
    l10_cap,l10_stoc,l10_vanz,l10_target,l10_npcant,l10_pret,l10_npval,l10_coefcap,l10_npfcant,l10_npfval,l10_pretmmr,l10_pretmat,l10_var,l10_est,
    l11_cap,l11_stoc,l11_vanz,l11_target,l11_npcant,l11_pret,l11_npval,l11_coefcap,l11_npfcant,l11_npfval,l11_pretmmr,l11_pretmat,l11_var,l11_est,
    l12_cap,l12_stoc,l12_vanz,l12_target,l12_npcant,l12_pret,l12_npval,l12_coefcap,l12_npfcant,l12_npfval,l12_pretmmr,l12_pretmat,l12_var,l12_est,
    l1_npfval_orig, l2_npfval_orig, l3_npfval_orig, l4_npfval_orig, l5_npfval_orig, l6_npfval_orig, 
    l7_npfval_orig, l8_npfval_orig, l9_npfval_orig, l10_npfval_orig, l11_npfval_orig, l12_npfval_orig, codextern, denumire, den_clasea, Stipcap
    )
  SELECT 
    B.codbugetvcl,B.codbugetprod,B.codobiect,B.codclasea,B.tipcap,B.coefum,
    B.l1_cap,B.l1_stoc,B.l1_vanz,B.l1_target,B.l1_npcant,B.l1_pret,B.l1_npval,B.l1_coefcap,B.l1_npfcant,B.l1_npfval,B.l1_pretmmr,B.l1_pretmat,B.l1_var,B.l1_est,
    B.l2_cap,B.l2_stoc,B.l2_vanz,B.l2_target,B.l2_npcant,B.l2_pret,B.l2_npval,B.l2_coefcap,B.l2_npfcant,B.l2_npfval,B.l2_pretmmr,B.l2_pretmat,B.l2_var,B.l2_est,
    B.l3_cap,B.l3_stoc,B.l3_vanz,B.l3_target,B.l3_npcant,B.l3_pret,B.l3_npval,B.l3_coefcap,B.l3_npfcant,B.l3_npfval,B.l3_pretmmr,B.l3_pretmat,B.l3_var,B.l3_est,
    B.l4_cap,B.l4_stoc,B.l4_vanz,B.l4_target,B.l4_npcant,B.l4_pret,B.l4_npval,B.l4_coefcap,B.l4_npfcant,B.l4_npfval,B.l4_pretmmr,B.l4_pretmat,B.l4_var,B.l4_est,
    B.l5_cap,B.l5_stoc,B.l5_vanz,B.l5_target,B.l5_npcant,B.l5_pret,B.l5_npval,B.l5_coefcap,B.l5_npfcant,B.l5_npfval,B.l5_pretmmr,B.l5_pretmat,B.l5_var,B.l5_est,
    B.l6_cap,B.l6_stoc,B.l6_vanz,B.l6_target,B.l6_npcant,B.l6_pret,B.l6_npval,B.l6_coefcap,B.l6_npfcant,B.l6_npfval,B.l6_pretmmr,B.l6_pretmat,B.l6_var,B.l6_est,
    B.l7_cap,B.l7_stoc,B.l7_vanz,B.l7_target,B.l7_npcant,B.l7_pret,B.l7_npval,B.l7_coefcap,B.l7_npfcant,B.l7_npfval,B.l7_pretmmr,B.l7_pretmat,B.l7_var,B.l7_est,
    B.l8_cap,B.l8_stoc,B.l8_vanz,B.l8_target,B.l8_npcant,B.l8_pret,B.l8_npval,B.l8_coefcap,B.l8_npfcant,B.l8_npfval,B.l8_pretmmr,B.l8_pretmat,B.l8_var,B.l8_est,
    B.l9_cap,B.l9_stoc,B.l9_vanz,B.l9_target,B.l9_npcant,B.l9_pret,B.l9_npval,B.l9_coefcap,B.l9_npfcant,B.l9_npfval,B.l9_pretmmr,B.l9_pretmat,B.l9_var,B.l9_est,
    B.l10_cap,B.l10_stoc,B.l10_vanz,B.l10_target,B.l10_npcant,B.l10_pret,B.l10_npval,B.l10_coefcap,B.l10_npfcant,B.l10_npfval,B.l10_pretmmr,B.l10_pretmat,B.l10_var,B.l10_est,
    B.l11_cap,B.l11_stoc,B.l11_vanz,B.l11_target,B.l11_npcant,B.l11_pret,B.l11_npval,B.l11_coefcap,B.l11_npfcant,B.l11_npfval,B.l11_pretmmr,B.l11_pretmat,B.l11_var,B.l11_est,
    B.l12_cap,B.l12_stoc,B.l12_vanz,B.l12_target,B.l12_npcant,B.l12_pret,B.l12_npval,B.l12_coefcap,B.l12_npfcant,B.l12_npfval,B.l12_pretmmr,B.l12_pretmat,B.l12_var,B.l12_est,
    B.l1_npfval_orig, B.l2_npfval_orig, B.l3_npfval_orig, B.l4_npfval_orig, B.l5_npfval_orig, B.l6_npfval_orig,
    B.l7_npfval_orig, B.l8_npfval_orig, B.l9_npfval_orig, B.l10_npfval_orig, B.l11_npfval_orig, B.l12_npfval_orig,
    O.codextern, O.denumire, C.den_clasea, case when b.tipcap = 1 then &apos;Cantitativ&apos; when b.tipcap = 2 then &apos;Valoric&apos; end
  FROM BUGETVCL B
       LEFT JOIN NARTOBJ O ON B.CODOBIECT = O.CODOBIECT
       LEFT JOIN NCLASEA C ON C.CODCLASEA = B.CODCLASEA
  WHERE B.CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETSTOC(CODBUGETSTOC, CODBUGETPROD, CODOBIECT, CODCLASEA, STOC, COEFUM, VALTOTAL, VALMAT, CODEXTERN, DENUMIRE, DEN_CLASEA)
  SELECT BS.CODBUGETSTOC, BS.CODBUGETPROD, BS.CODOBIECT, BS.CODCLASEA, BS.STOC, BS.COEFUM, BS.VALTOTAL, BS.VALMAT, OBJ.CODEXTERN, OBJ.DENUMIRE, CLS.DEN_CLASEA
  FROM BUGETSTOC BS
       INNER JOIN NARTOBJ OBJ ON BS.CODOBIECT = OBJ.CODOBIECT
       LEFT JOIN NCLASEA CLS ON CLS.CODCLASEA = nvl(BS.CODCLASEA,0)
  WHERE BS.CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETVL(CODBUGETVL,CODBUGETPROD,ELEMENT,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,CODELEMBUGET)
  SELECT V.CODBUGETVL,V.CODBUGETPROD,E.ELEMENT,V.L1,V.L2,V.L3,V.L4,V.L5,V.L6,V.L7,V.L8,V.L9,V.L10,V.L11,V.L12,V.CODELEMBUGET
  FROM BUGETVL V
       INNER JOIN ELEMBUGET E ON V.CODELEMBUGET = E.CODELEMBUGET
  WHERE V.CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETCL(CODBUGETCL,CODBUGETPROD,ELEMENT,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,CODELEMBUGET)
  SELECT C.CODBUGETCL,C.CODBUGETPROD,E.ELEMENT,C.L1,C.L2,C.L3,C.L4,C.L5,C.L6,C.L7,C.L8,C.L9,C.L10,C.L11,C.L12,C.CODELEMBUGET
  FROM BUGETCL C
       INNER JOIN ELEMBUGET E ON C.CODELEMBUGET = E.CODELEMBUGET
  WHERE C.CODBUGETPROD = RECID;
  
  INSERT INTO TMP_BUGETVL_T(ELEMENT)
  VALUES (&apos;Total venituri din activitatea de productie&apos;);
  INSERT INTO TMP_BUGETCL_T(ELEMENT)
  VALUES (&apos;Cheltueili materiale si prestari aferente productiei&apos;);
  UPDATE TMP_BUGETVL_T
  SET
    L1 = (SELECT SUM(NVL(L1,0)) FROM TMP_BUGETVL),
    L2 = (SELECT SUM(NVL(L2,0)) FROM TMP_BUGETVL),
    L3 = (SELECT SUM(NVL(L3,0)) FROM TMP_BUGETVL),
    L4 = (SELECT SUM(NVL(L4,0)) FROM TMP_BUGETVL),
    L5 = (SELECT SUM(NVL(L5,0)) FROM TMP_BUGETVL),
    L6 = (SELECT SUM(NVL(L6,0)) FROM TMP_BUGETVL),
    L7 = (SELECT SUM(NVL(L7,0)) FROM TMP_BUGETVL),
    L8 = (SELECT SUM(NVL(L8,0)) FROM TMP_BUGETVL),
    L9 = (SELECT SUM(NVL(L9,0)) FROM TMP_BUGETVL),
    L10 = (SELECT SUM(NVL(L10,0)) FROM TMP_BUGETVL),
    L11 = (SELECT SUM(NVL(L11,0)) FROM TMP_BUGETVL),
    L12 = (SELECT SUM(NVL(L12,0)) FROM TMP_BUGETVL);
  UPDATE TMP_BUGETCL_T
  SET 
    L1 = (SELECT SUM(NVL(L1,0)) FROM TMP_BUGETCL),
    L2 = (SELECT SUM(NVL(L2,0)) FROM TMP_BUGETCL),
    L3 = (SELECT SUM(NVL(L3,0)) FROM TMP_BUGETCL),
    L4 = (SELECT SUM(NVL(L4,0)) FROM TMP_BUGETCL),
    L5 = (SELECT SUM(NVL(L5,0)) FROM TMP_BUGETCL),
    L6 = (SELECT SUM(NVL(L6,0)) FROM TMP_BUGETCL),
    L7 = (SELECT SUM(NVL(L7,0)) FROM TMP_BUGETCL),
    L8 = (SELECT SUM(NVL(L8,0)) FROM TMP_BUGETCL),
    L9 = (SELECT SUM(NVL(L9,0)) FROM TMP_BUGETCL),
    L10 = (SELECT SUM(NVL(L10,0)) FROM TMP_BUGETCL),
    L11 = (SELECT SUM(NVL(L11,0)) FROM TMP_BUGETCL),
    L12 = (SELECT SUM(NVL(L12,0)) FROM TMP_BUGETCL);
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
VCOD NUMBER(20);
BEGIN
  IF Operation = 0 THEN -- UPDATE
    select codbugetprod into recid from tmp_bugetprod;
    UPDATE BUGETPROD
    SET (AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF)
    =
    (SELECT AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF
    FROM TMP_BUGETPROD)
    WHERE CODBUGETPROD = RECID;
    
    DELETE BUGETPRODV B WHERE B.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETPRODV FROM TMP_BUGETPRODV TMP WHERE TMP.CODBUGETPRODV = B.CODBUGETPRODV);
    FOR V_REC IN (SELECT * FROM TMP_BUGETPRODV) LOOP
      IF V_REC.CODBUGETPRODV &gt; 0 THEN
        UPDATE BUGETPRODV
        SET
          CODOBIECT = V_REC.CODOBIECT, 
          S1 = V_REC.S1, S2 = V_REC.S2, S3 = V_REC.S3, S4 = V_REC.S4, S5 = V_REC.S5, S6 = V_REC.S6, S7 = V_REC.S7, S8 = V_REC.S8, S9 = V_REC.S9, 
          S10 = V_REC.S10, S11 = V_REC.S11, S12 = V_REC.S12, S13 = V_REC.S13, S14 = V_REC.S14, S15 = V_REC.S15, S16 = V_REC.S16, S17 = V_REC.S17, S18 = V_REC.S18, S19 = V_REC.S19, 
          S20 = V_REC.S20, S21 = V_REC.S21, S22 = V_REC.S22, S23 = V_REC.S23, S24 = V_REC.S24, S25 = V_REC.S25, S26 = V_REC.S26, S27 = V_REC.S27, S28 = V_REC.S28, S29 = V_REC.S29, 
          S30 = V_REC.S30, S31 = V_REC.S31, S32 = V_REC.S32, S33 = V_REC.S33, S34 = V_REC.S34, S35 = V_REC.S35, S36 = V_REC.S36, S37 = V_REC.S37, S38 = V_REC.S38, S39 = V_REC.S39, 
          S40 = V_REC.S40, S41 = V_REC.S41, S42 = V_REC.S42, S43 = V_REC.S43, S44 = V_REC.S44, S45 = V_REC.S45, S46 = V_REC.S46, S47 = V_REC.S47, S48 = V_REC.S48, S49 = V_REC.S49, 
          S50 = V_REC.S50, S51 = V_REC.S51, S52 = V_REC.S52, S53 = V_REC.S53,
          L1 = V_REC.L1, L2 = V_REC.L2, L3 = V_REC.L3, L4 = V_REC.L4, L5 = V_REC.L5, L6 = V_REC.L6, L7 = V_REC.L7, L8 = V_REC.L8, L9 = V_REC.L9, L10 = V_REC.L10, L11 = V_REC.L11, L12 = V_REC.L12
        WHERE CODBUGETPRODV = V_REC.CODBUGETPRODV;  
      ELSE
        INSERT INTO BUGETPRODV(
          CODBUGETPRODV, CODBUGETPROD, CODOBIECT, 
          S1, S2, S3, S4, S5, S6, S7, S8, S9, 
          S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
          S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
          S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
          S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
          S50, S51, S52, S53,
          L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
          )
        VALUES (
          SEQ_BUGETPRODV_CODV.NEXTVAL, RECID, V_REC.CODOBIECT, 
          V_REC.S1, V_REC.S2, V_REC.S3, V_REC.S4, V_REC.S5, V_REC.S6, V_REC.S7, V_REC.S8, V_REC.S9, 
          V_REC.S10, V_REC.S11, V_REC.S12, V_REC.S13, V_REC.S14, V_REC.S15, V_REC.S16, V_REC.S17, V_REC.S18, V_REC.S19, 
          V_REC.S20, V_REC.S21, V_REC.S22, V_REC.S23, V_REC.S24, V_REC.S25, V_REC.S26, V_REC.S27, V_REC.S28, V_REC.S29, 
          V_REC.S30, V_REC.S31, V_REC.S32, V_REC.S33, V_REC.S34, V_REC.S35, V_REC.S36, V_REC.S37, V_REC.S38, V_REC.S39, 
          V_REC.S40, V_REC.S41, V_REC.S42, V_REC.S43, V_REC.S44, V_REC.S45, V_REC.S46, V_REC.S47, V_REC.S48, V_REC.S49, 
          V_REC.S50, V_REC.S51, V_REC.S52, V_REC.S53,
          V_REC.L1, V_REC.L2, V_REC.L3, V_REC.L4, V_REC.L5, V_REC.L6, V_REC.L7, V_REC.L8, V_REC.L9, V_REC.L10, V_REC.L11, V_REC.L12
          ); 
      END IF;
    END LOOP;
    
    DELETE BUGETPRODT B WHERE B.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETPRODT FROM TMP_BUGETPRODT TMP WHERE TMP.CODBUGETPRODT = B.CODBUGETPRODT);
    FOR V_REC IN (SELECT * FROM TMP_BUGETPRODT) LOOP
      IF V_REC.CODBUGETPRODT &gt; 0 THEN
        UPDATE BUGETPRODT
        SET
          CODOBIECT = V_REC.CODOBIECT, 
          S1 = V_REC.S1, S2 = V_REC.S2, S3 = V_REC.S3, S4 = V_REC.S4, S5 = V_REC.S5, S6 = V_REC.S6, S7 = V_REC.S7, S8 = V_REC.S8, S9 = V_REC.S9, 
          S10 = V_REC.S10, S11 = V_REC.S11, S12 = V_REC.S12, S13 = V_REC.S13, S14 = V_REC.S14, S15 = V_REC.S15, S16 = V_REC.S16, S17 = V_REC.S17, S18 = V_REC.S18, S19 = V_REC.S19, 
          S20 = V_REC.S20, S21 = V_REC.S21, S22 = V_REC.S22, S23 = V_REC.S23, S24 = V_REC.S24, S25 = V_REC.S25, S26 = V_REC.S26, S27 = V_REC.S27, S28 = V_REC.S28, S29 = V_REC.S29, 
          S30 = V_REC.S30, S31 = V_REC.S31, S32 = V_REC.S32, S33 = V_REC.S33, S34 = V_REC.S34, S35 = V_REC.S35, S36 = V_REC.S36, S37 = V_REC.S37, S38 = V_REC.S38, S39 = V_REC.S39, 
          S40 = V_REC.S40, S41 = V_REC.S41, S42 = V_REC.S42, S43 = V_REC.S43, S44 = V_REC.S44, S45 = V_REC.S45, S46 = V_REC.S46, S47 = V_REC.S47, S48 = V_REC.S48, S49 = V_REC.S49, 
          S50 = V_REC.S50, S51 = V_REC.S51, S52 = V_REC.S52, S53 = V_REC.S53,
          L1 = V_REC.L1, L2 = V_REC.L2, L3 = V_REC.L3, L4 = V_REC.L4, L5 = V_REC.L5, L6 = V_REC.L6, L7 = V_REC.L7, L8 = V_REC.L8, L9 = V_REC.L9, L10 = V_REC.L10, L11 = V_REC.L11, L12 = V_REC.L12
        WHERE CODBUGETPRODT = V_REC.CODBUGETPRODT;  
      ELSE
        INSERT INTO BUGETPRODT(
          CODBUGETPRODT, CODBUGETPROD, CODOBIECT, 
          S1, S2, S3, S4, S5, S6, S7, S8, S9, 
          S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
          S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
          S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
          S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
          S50, S51, S52, S53,
          L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
          )
        VALUES (
          SEQ_BUGETPRODT_CODT.NEXTVAL, RECID, V_REC.CODOBIECT, 
          V_REC.S1, V_REC.S2, V_REC.S3, V_REC.S4, V_REC.S5, V_REC.S6, V_REC.S7, V_REC.S8, V_REC.S9, 
          V_REC.S10, V_REC.S11, V_REC.S12, V_REC.S13, V_REC.S14, V_REC.S15, V_REC.S16, V_REC.S17, V_REC.S18, V_REC.S19, 
          V_REC.S20, V_REC.S21, V_REC.S22, V_REC.S23, V_REC.S24, V_REC.S25, V_REC.S26, V_REC.S27, V_REC.S28, V_REC.S29, 
          V_REC.S30, V_REC.S31, V_REC.S32, V_REC.S33, V_REC.S34, V_REC.S35, V_REC.S36, V_REC.S37, V_REC.S38, V_REC.S39, 
          V_REC.S40, V_REC.S41, V_REC.S42, V_REC.S43, V_REC.S44, V_REC.S45, V_REC.S46, V_REC.S47, V_REC.S48, V_REC.S49, 
          V_REC.S50, V_REC.S51, V_REC.S52, V_REC.S53,
          V_REC.L1, V_REC.L2, V_REC.L3, V_REC.L4, V_REC.L5, V_REC.L6, V_REC.L7, V_REC.L8, V_REC.L9, V_REC.L10, V_REC.L11, V_REC.L12
          ); 
      END IF;
    END LOOP;
    
    DELETE BUGETPRODP B WHERE B.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETPRODP FROM TMP_BUGETPRODP TMP WHERE TMP.CODBUGETPRODP = B.CODBUGETPRODP);
    FOR V_REC IN (SELECT * FROM TMP_BUGETPRODP) LOOP
      IF V_REC.CODBUGETPRODP &gt; 0 THEN
        UPDATE BUGETPRODP
        SET
          CODOBIECT = V_REC.CODOBIECT, 
          S1 = V_REC.S1, S2 = V_REC.S2, S3 = V_REC.S3, S4 = V_REC.S4, S5 = V_REC.S5, S6 = V_REC.S6, S7 = V_REC.S7, S8 = V_REC.S8, S9 = V_REC.S9, 
          S10 = V_REC.S10, S11 = V_REC.S11, S12 = V_REC.S12, S13 = V_REC.S13, S14 = V_REC.S14, S15 = V_REC.S15, S16 = V_REC.S16, S17 = V_REC.S17, S18 = V_REC.S18, S19 = V_REC.S19, 
          S20 = V_REC.S20, S21 = V_REC.S21, S22 = V_REC.S22, S23 = V_REC.S23, S24 = V_REC.S24, S25 = V_REC.S25, S26 = V_REC.S26, S27 = V_REC.S27, S28 = V_REC.S28, S29 = V_REC.S29, 
          S30 = V_REC.S30, S31 = V_REC.S31, S32 = V_REC.S32, S33 = V_REC.S33, S34 = V_REC.S34, S35 = V_REC.S35, S36 = V_REC.S36, S37 = V_REC.S37, S38 = V_REC.S38, S39 = V_REC.S39, 
          S40 = V_REC.S40, S41 = V_REC.S41, S42 = V_REC.S42, S43 = V_REC.S43, S44 = V_REC.S44, S45 = V_REC.S45, S46 = V_REC.S46, S47 = V_REC.S47, S48 = V_REC.S48, S49 = V_REC.S49, 
          S50 = V_REC.S50, S51 = V_REC.S51, S52 = V_REC.S52, S53 = V_REC.S53,
          L1 = V_REC.L1, L2 = V_REC.L2, L3 = V_REC.L3, L4 = V_REC.L4, L5 = V_REC.L5, L6 = V_REC.L6, L7 = V_REC.L7, L8 = V_REC.L8, L9 = V_REC.L9, L10 = V_REC.L10, L11 = V_REC.L11, L12 = V_REC.L12
        WHERE CODBUGETPRODP = V_REC.CODBUGETPRODP;  
      ELSE
        INSERT INTO BUGETPRODP(
          CODBUGETPRODP, CODBUGETPROD, CODOBIECT, 
          S1, S2, S3, S4, S5, S6, S7, S8, S9, 
          S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
          S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
          S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
          S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
          S50, S51, S52, S53,
          L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
          )
        VALUES (
          SEQ_BUGETPRODP_CODP.NEXTVAL, RECID, V_REC.CODOBIECT, 
          V_REC.S1, V_REC.S2, V_REC.S3, V_REC.S4, V_REC.S5, V_REC.S6, V_REC.S7, V_REC.S8, V_REC.S9, 
          V_REC.S10, V_REC.S11, V_REC.S12, V_REC.S13, V_REC.S14, V_REC.S15, V_REC.S16, V_REC.S17, V_REC.S18, V_REC.S19, 
          V_REC.S20, V_REC.S21, V_REC.S22, V_REC.S23, V_REC.S24, V_REC.S25, V_REC.S26, V_REC.S27, V_REC.S28, V_REC.S29, 
          V_REC.S30, V_REC.S31, V_REC.S32, V_REC.S33, V_REC.S34, V_REC.S35, V_REC.S36, V_REC.S37, V_REC.S38, V_REC.S39, 
          V_REC.S40, V_REC.S41, V_REC.S42, V_REC.S43, V_REC.S44, V_REC.S45, V_REC.S46, V_REC.S47, V_REC.S48, V_REC.S49, 
          V_REC.S50, V_REC.S51, V_REC.S52, V_REC.S53,
          V_REC.L1, V_REC.L2, V_REC.L3, V_REC.L4, V_REC.L5, V_REC.L6, V_REC.L7, V_REC.L8, V_REC.L9, V_REC.L10, V_REC.L11, V_REC.L12
          ); 
      END IF;
    END LOOP;
    
    DELETE BUGETCAP C WHERE C.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETCAP FROM TMP_BUGETCAP TMP WHERE TMP.CODBUGETCAP = C.CODBUGETCAP);
    FOR V_REC IN (SELECT * FROM TMP_BUGETCAP) LOOP
      IF V_REC.CODBUGETCAP &gt; 0 THEN
        UPDATE BUGETCAP
        SET
          CODCLASEA = V_REC.CODCLASEA,
          TIPCAP    = V_REC.TIPCAP
        WHERE CODBUGETCAP = V_REC.CODBUGETCAP;
      ELSE
        INSERT INTO BUGETCAP(CODBUGETCAP, CODBUGETPROD, TIPCAP, CODCLASEA)
        VALUES (SEQ_BUGETCAP_CODBUGETCAP.NEXTVAL, RECID, V_REC.TIPCAP, V_REC.CODCLASEA);
      END IF;
    END LOOP;
    
    INSERT INTO TMP_BUGETCAPC
    SELECT * FROM TMP_BUGETCAPV;
    
    DELETE BUGETCAP1 C1 WHERE C1.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETCAP1 FROM TMP_BUGETCAPC TMP WHERE TMP.CODBUGETCAP1 = C1.CODBUGETCAP1);
    FOR V_REC IN (SELECT * FROM TMP_BUGETCAPC) LOOP
      IF V_REC.CODBUGETCAP1 &gt; 0 THEN
        UPDATE BUGETCAP1
        SET
          CODCLASEA = V_REC.CODCLASEA, 
          S1 = V_REC.S1, S2 = V_REC.S2, S3 = V_REC.S3, S4 = V_REC.S4, S5 = V_REC.S5, S6 = V_REC.S6, S7 = V_REC.S7, S8 = V_REC.S8, S9 = V_REC.S9, 
          S10 = V_REC.S10, S11 = V_REC.S11, S12 = V_REC.S12, S13 = V_REC.S13, S14 = V_REC.S14, S15 = V_REC.S15, S16 = V_REC.S16, S17 = V_REC.S17, S18 = V_REC.S18, S19 = V_REC.S19, 
          S20 = V_REC.S20, S21 = V_REC.S21, S22 = V_REC.S22, S23 = V_REC.S23, S24 = V_REC.S24, S25 = V_REC.S25, S26 = V_REC.S26, S27 = V_REC.S27, S28 = V_REC.S28, S29 = V_REC.S29, 
          S30 = V_REC.S30, S31 = V_REC.S31, S32 = V_REC.S32, S33 = V_REC.S33, S34 = V_REC.S34, S35 = V_REC.S35, S36 = V_REC.S36, S37 = V_REC.S37, S38 = V_REC.S38, S39 = V_REC.S39, 
          S40 = V_REC.S40, S41 = V_REC.S41, S42 = V_REC.S42, S43 = V_REC.S43, S44 = V_REC.S44, S45 = V_REC.S45, S46 = V_REC.S46, S47 = V_REC.S47, S48 = V_REC.S48, S49 = V_REC.S49, 
          S50 = V_REC.S50, S51 = V_REC.S51, S52 = V_REC.S52, S53 = V_REC.S53,
          L1 = V_REC.L1, L2 = V_REC.L2, L3 = V_REC.L3, L4 = V_REC.L4, L5 = V_REC.L5, L6 = V_REC.L6, L7 = V_REC.L7, L8 = V_REC.L8, L9 = V_REC.L9, L10 = V_REC.L10, L11 = V_REC.L11, L12 = V_REC.L12
        WHERE CODBUGETCAP1 = V_REC.CODBUGETCAP1;
      ELSE
        INSERT INTO BUGETCAP1(
          CODBUGETCAP1, CODBUGETPROD, CODCLASEA, 
          S1, S2, S3, S4, S5, S6, S7, S8, S9, 
          S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
          S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
          S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
          S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
          S50, S51, S52, S53,
          L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
          )
        VALUES (
          SEQ_BUGETCAP1_CODBUGETCAP1.NEXTVAL, RECID, V_REC.CODCLASEA, 
          V_REC.S1, V_REC.S2, V_REC.S3, V_REC.S4, V_REC.S5, V_REC.S6, V_REC.S7, V_REC.S8, V_REC.S9, 
          V_REC.S10, V_REC.S11, V_REC.S12, V_REC.S13, V_REC.S14, V_REC.S15, V_REC.S16, V_REC.S17, V_REC.S18, V_REC.S19, 
          V_REC.S20, V_REC.S21, V_REC.S22, V_REC.S23, V_REC.S24, V_REC.S25, V_REC.S26, V_REC.S27, V_REC.S28, V_REC.S29, 
          V_REC.S30, V_REC.S31, V_REC.S32, V_REC.S33, V_REC.S34, V_REC.S35, V_REC.S36, V_REC.S37, V_REC.S38, V_REC.S39, 
          V_REC.S40, V_REC.S41, V_REC.S42, V_REC.S43, V_REC.S44, V_REC.S45, V_REC.S46, V_REC.S47, V_REC.S48, V_REC.S49, 
          V_REC.S50, V_REC.S51, V_REC.S52, V_REC.S53,
          V_REC.L1, V_REC.L2, V_REC.L3, V_REC.L4, V_REC.L5, V_REC.L6, V_REC.L7, V_REC.L8, V_REC.L9, V_REC.L10, V_REC.L11, V_REC.L12
          ); 
      END IF;
    END LOOP;
    
    DELETE BUGETVCL VCL WHERE VCL.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETVCL FROM TMP_BUGETVCL TMP WHERE TMP.CODBUGETVCL = VCL.CODBUGETVCL);
    FOR V_REC IN (SELECT * FROM TMP_BUGETVCL) LOOP
      IF V_REC.CODBUGETVCL &gt; 0 THEN
        UPDATE BUGETVCL
        SET
          codobiect = V_REC.codobiect,codclasea = V_REC.CODCLASEA,tipcap= V_REC.TIPCAP,coefum = V_REC.COEFUM,
          l1_cap  = V_REC.l1_cap  ,l1_stoc  = V_REC.l1_stoc ,l1_vanz  = V_REC.l1_vanz ,l1_target  = V_REC.l1_target ,l1_npcant  = V_REC.l1_npcant ,l1_pret  = V_REC.l1_pret ,l1_npval  = V_REC.l1_npval ,l1_coefcap  = V_REC.l1_coefcap ,l1_npfcant  = V_REC.l1_npfcant ,l1_npfval  = V_REC.l1_npfval ,l1_pretmmr  = V_REC.l1_pretmmr ,l1_pretmat  = V_REC.l1_pretmat ,l1_var  = V_REC.l1_var ,l1_est  = V_REC.l1_est ,
          l2_cap  = V_REC.l2_cap  ,l2_stoc  = V_REC.l2_stoc ,l2_vanz  = V_REC.l2_vanz ,l2_target  = V_REC.l2_target ,l2_npcant  = V_REC.l2_npcant ,l2_pret  = V_REC.l2_pret ,l2_npval  = V_REC.l2_npval ,l2_coefcap  = V_REC.l2_coefcap ,l2_npfcant  = V_REC.l2_npfcant ,l2_npfval  = V_REC.l2_npfval ,l2_pretmmr  = V_REC.l2_pretmmr ,l2_pretmat  = V_REC.l2_pretmat ,l2_var  = V_REC.l2_var ,l2_est  = V_REC.l2_est ,
          l3_cap  = V_REC.l3_cap  ,l3_stoc  = V_REC.l3_stoc ,l3_vanz  = V_REC.l3_vanz ,l3_target  = V_REC.l3_target ,l3_npcant  = V_REC.l3_npcant ,l3_pret  = V_REC.l3_pret ,l3_npval  = V_REC.l3_npval ,l3_coefcap  = V_REC.l3_coefcap ,l3_npfcant  = V_REC.l3_npfcant ,l3_npfval  = V_REC.l3_npfval ,l3_pretmmr  = V_REC.l3_pretmmr ,l3_pretmat  = V_REC.l3_pretmat ,l3_var  = V_REC.l3_var ,l3_est  = V_REC.l3_est ,
          l4_cap  = V_REC.l4_cap  ,l4_stoc  = V_REC.l4_stoc ,l4_vanz  = V_REC.l4_vanz ,l4_target  = V_REC.l4_target ,l4_npcant  = V_REC.l4_npcant ,l4_pret  = V_REC.l4_pret ,l4_npval  = V_REC.l4_npval ,l4_coefcap  = V_REC.l4_coefcap ,l4_npfcant  = V_REC.l4_npfcant ,l4_npfval  = V_REC.l4_npfval ,l4_pretmmr  = V_REC.l4_pretmmr ,l4_pretmat  = V_REC.l4_pretmat ,l4_var  = V_REC.l4_var ,l4_est  = V_REC.l4_est ,
          l5_cap  = V_REC.l5_cap  ,l5_stoc  = V_REC.l5_stoc ,l5_vanz  = V_REC.l5_vanz ,l5_target  = V_REC.l5_target ,l5_npcant  = V_REC.l5_npcant ,l5_pret  = V_REC.l5_pret ,l5_npval  = V_REC.l5_npval ,l5_coefcap  = V_REC.l5_coefcap ,l5_npfcant  = V_REC.l5_npfcant ,l5_npfval  = V_REC.l5_npfval ,l5_pretmmr  = V_REC.l5_pretmmr ,l5_pretmat  = V_REC.l5_pretmat ,l5_var  = V_REC.l5_var ,l5_est  = V_REC.l5_est ,
          l6_cap  = V_REC.l6_cap  ,l6_stoc  = V_REC.l6_stoc ,l6_vanz  = V_REC.l6_vanz ,l6_target  = V_REC.l6_target ,l6_npcant  = V_REC.l6_npcant ,l6_pret  = V_REC.l6_pret ,l6_npval  = V_REC.l6_npval ,l6_coefcap  = V_REC.l6_coefcap ,l6_npfcant  = V_REC.l6_npfcant ,l6_npfval  = V_REC.l6_npfval ,l6_pretmmr  = V_REC.l6_pretmmr ,l6_pretmat  = V_REC.l6_pretmat ,l6_var  = V_REC.l6_var ,l6_est  = V_REC.l6_est ,
          l7_cap  = V_REC.l7_cap  ,l7_stoc  = V_REC.l7_stoc ,l7_vanz  = V_REC.l7_vanz ,l7_target  = V_REC.l7_target ,l7_npcant  = V_REC.l7_npcant ,l7_pret  = V_REC.l7_pret ,l7_npval  = V_REC.l7_npval ,l7_coefcap  = V_REC.l7_coefcap ,l7_npfcant  = V_REC.l7_npfcant ,l7_npfval  = V_REC.l7_npfval ,l7_pretmmr  = V_REC.l7_pretmmr ,l7_pretmat  = V_REC.l7_pretmat ,l7_var  = V_REC.l7_var ,l7_est  = V_REC.l7_est ,
          l8_cap  = V_REC.l8_cap  ,l8_stoc  = V_REC.l8_stoc ,l8_vanz  = V_REC.l8_vanz ,l8_target  = V_REC.l8_target ,l8_npcant  = V_REC.l8_npcant ,l8_pret  = V_REC.l8_pret ,l8_npval  = V_REC.l8_npval ,l8_coefcap  = V_REC.l8_coefcap ,l8_npfcant  = V_REC.l8_npfcant ,l8_npfval  = V_REC.l8_npfval ,l8_pretmmr  = V_REC.l8_pretmmr ,l8_pretmat  = V_REC.l8_pretmat ,l8_var  = V_REC.l8_var ,l8_est  = V_REC.l8_est ,
          l9_cap  = V_REC.l9_cap  ,l9_stoc  = V_REC.l9_stoc ,l9_vanz  = V_REC.l9_vanz ,l9_target  = V_REC.l9_target ,l9_npcant  = V_REC.l9_npcant ,l9_pret  = V_REC.l9_pret ,l9_npval  = V_REC.l9_npval ,l9_coefcap  = V_REC.l9_coefcap ,l9_npfcant  = V_REC.l9_npfcant ,l9_npfval  = V_REC.l9_npfval ,l9_pretmmr  = V_REC.l9_pretmmr ,l9_pretmat  = V_REC.l9_pretmat ,l9_var  = V_REC.l9_var ,l9_est  = V_REC.l9_est ,
          l10_cap = V_REC.l10_cap ,l10_stoc = V_REC.l10_stoc,l10_vanz = V_REC.l10_vanz,l10_target = V_REC.l10_target,l10_npcant = V_REC.l10_npcant,l10_pret = V_REC.l10_pret,l10_npval = V_REC.l10_npval,l10_coefcap = V_REC.l10_coefcap,l10_npfcant = V_REC.l10_npfcant,l10_npfval = V_REC.l10_npfval,l10_pretmmr = V_REC.l10_pretmmr,l10_pretmat = V_REC.l10_pretmat,l10_var = V_REC.l10_var,l10_est = V_REC.l10_est,
          l11_cap = V_REC.l11_cap ,l11_stoc = V_REC.l11_stoc,l11_vanz = V_REC.l11_vanz,l11_target = V_REC.l11_target,l11_npcant = V_REC.l11_npcant,l11_pret = V_REC.l11_pret,l11_npval = V_REC.l11_npval,l11_coefcap = V_REC.l11_coefcap,l11_npfcant = V_REC.l11_npfcant,l11_npfval = V_REC.l11_npfval,l11_pretmmr = V_REC.l11_pretmmr,l11_pretmat = V_REC.l11_pretmat,l11_var = V_REC.l11_var,l11_est = V_REC.l11_est,
          l12_cap = V_REC.l12_cap ,l12_stoc = V_REC.l12_stoc,l12_vanz = V_REC.l12_vanz,l12_target = V_REC.l12_target,l12_npcant = V_REC.l12_npcant,l12_pret = V_REC.l12_pret,l12_npval = V_REC.l12_npval,l12_coefcap = V_REC.l12_coefcap,l12_npfcant = V_REC.l12_npfcant,l12_npfval = V_REC.l12_npfval,l12_pretmmr = V_REC.l12_pretmmr,l12_pretmat = V_REC.l12_pretmat,l12_var = V_REC.l12_var,l12_est = V_REC.l12_est,
          l1_npfval_orig = V_REC.l1_npfval_orig, l2_npfval_orig = V_REC.l2_npfval_orig, l3_npfval_orig = V_REC.l3_npfval_orig, l4_npfval_orig = V_REC.l4_npfval_orig, l5_npfval_orig = V_REC.l5_npfval_orig, l6_npfval_orig = V_REC.l6_npfval_orig, 
          l7_npfval_orig = V_REC.l7_npfval_orig, l8_npfval_orig = V_REC.l8_npfval_orig, l9_npfval_orig = V_REC.l9_npfval_orig, l10_npfval_orig = V_REC.l10_npfval_orig, l11_npfval_orig = V_REC.l11_npfval_orig, l12_npfval_orig = V_REC.l12_npfval_orig
        WHERE CODBUGETVCL = V_REC.CODBUGETVCL;
      ELSE
        INSERT INTO BUGETVCL(
          codbugetvcl,codbugetprod,codobiect,codclasea,tipcap,coefum,
          l1_cap,l1_stoc,l1_vanz,l1_target,l1_npcant,l1_pret,l1_npval,l1_coefcap,l1_npfcant,l1_npfval,l1_pretmmr,l1_pretmat,l1_var,l1_est,
          l2_cap,l2_stoc,l2_vanz,l2_target,l2_npcant,l2_pret,l2_npval,l2_coefcap,l2_npfcant,l2_npfval,l2_pretmmr,l2_pretmat,l2_var,l2_est,
          l3_cap,l3_stoc,l3_vanz,l3_target,l3_npcant,l3_pret,l3_npval,l3_coefcap,l3_npfcant,l3_npfval,l3_pretmmr,l3_pretmat,l3_var,l3_est,
          l4_cap,l4_stoc,l4_vanz,l4_target,l4_npcant,l4_pret,l4_npval,l4_coefcap,l4_npfcant,l4_npfval,l4_pretmmr,l4_pretmat,l4_var,l4_est,
          l5_cap,l5_stoc,l5_vanz,l5_target,l5_npcant,l5_pret,l5_npval,l5_coefcap,l5_npfcant,l5_npfval,l5_pretmmr,l5_pretmat,l5_var,l5_est,
          l6_cap,l6_stoc,l6_vanz,l6_target,l6_npcant,l6_pret,l6_npval,l6_coefcap,l6_npfcant,l6_npfval,l6_pretmmr,l6_pretmat,l6_var,l6_est,
          l7_cap,l7_stoc,l7_vanz,l7_target,l7_npcant,l7_pret,l7_npval,l7_coefcap,l7_npfcant,l7_npfval,l7_pretmmr,l7_pretmat,l7_var,l7_est,
          l8_cap,l8_stoc,l8_vanz,l8_target,l8_npcant,l8_pret,l8_npval,l8_coefcap,l8_npfcant,l8_npfval,l8_pretmmr,l8_pretmat,l8_var,l8_est,
          l9_cap,l9_stoc,l9_vanz,l9_target,l9_npcant,l9_pret,l9_npval,l9_coefcap,l9_npfcant,l9_npfval,l9_pretmmr,l9_pretmat,l9_var,l9_est,
          l10_cap,l10_stoc,l10_vanz,l10_target,l10_npcant,l10_pret,l10_npval,l10_coefcap,l10_npfcant,l10_npfval,l10_pretmmr,l10_pretmat,l10_var,l10_est,
          l11_cap,l11_stoc,l11_vanz,l11_target,l11_npcant,l11_pret,l11_npval,l11_coefcap,l11_npfcant,l11_npfval,l11_pretmmr,l11_pretmat,l11_var,l11_est,
          l12_cap,l12_stoc,l12_vanz,l12_target,l12_npcant,l12_pret,l12_npval,l12_coefcap,l12_npfcant,l12_npfval,l12_pretmmr,l12_pretmat,l12_var,l12_est,
          l1_npfval_orig, l2_npfval_orig, l3_npfval_orig, l4_npfval_orig, l5_npfval_orig, l6_npfval_orig, 
          l7_npfval_orig, l8_npfval_orig, l9_npfval_orig, l10_npfval_orig, l11_npfval_orig, l12_npfval_orig
          )
        VALUES (
          SEQ_BUGETVCL_CODBUGETVCL.NEXTVAL, RECID,
          V_REC.codobiect,V_REC.CODCLASEA,V_REC.TIPCAP,V_REC.COEFUM,
          V_REC.l1_cap  ,V_REC.l1_stoc ,V_REC.l1_vanz ,V_REC.l1_target ,V_REC.l1_npcant ,V_REC.l1_pret ,V_REC.l1_npval ,V_REC.l1_coefcap ,V_REC.l1_npfcant ,V_REC.l1_npfval ,V_REC.l1_pretmmr ,V_REC.l1_pretmat ,V_REC.l1_var ,V_REC.l1_est ,
          V_REC.l2_cap  ,V_REC.l2_stoc ,V_REC.l2_vanz ,V_REC.l2_target ,V_REC.l2_npcant ,V_REC.l2_pret ,V_REC.l2_npval ,V_REC.l2_coefcap ,V_REC.l2_npfcant ,V_REC.l2_npfval ,V_REC.l2_pretmmr ,V_REC.l2_pretmat ,V_REC.l2_var ,V_REC.l2_est ,
          V_REC.l3_cap  ,V_REC.l3_stoc ,V_REC.l3_vanz ,V_REC.l3_target ,V_REC.l3_npcant ,V_REC.l3_pret ,V_REC.l3_npval ,V_REC.l3_coefcap ,V_REC.l3_npfcant ,V_REC.l3_npfval ,V_REC.l3_pretmmr ,V_REC.l3_pretmat ,V_REC.l3_var ,V_REC.l3_est ,
          V_REC.l4_cap  ,V_REC.l4_stoc ,V_REC.l4_vanz ,V_REC.l4_target ,V_REC.l4_npcant ,V_REC.l4_pret ,V_REC.l4_npval ,V_REC.l4_coefcap ,V_REC.l4_npfcant ,V_REC.l4_npfval ,V_REC.l4_pretmmr ,V_REC.l4_pretmat ,V_REC.l4_var ,V_REC.l4_est ,
          V_REC.l5_cap  ,V_REC.l5_stoc ,V_REC.l5_vanz ,V_REC.l5_target ,V_REC.l5_npcant ,V_REC.l5_pret ,V_REC.l5_npval ,V_REC.l5_coefcap ,V_REC.l5_npfcant ,V_REC.l5_npfval ,V_REC.l5_pretmmr ,V_REC.l5_pretmat ,V_REC.l5_var ,V_REC.l5_est ,
          V_REC.l6_cap  ,V_REC.l6_stoc ,V_REC.l6_vanz ,V_REC.l6_target ,V_REC.l6_npcant ,V_REC.l6_pret ,V_REC.l6_npval ,V_REC.l6_coefcap ,V_REC.l6_npfcant ,V_REC.l6_npfval ,V_REC.l6_pretmmr ,V_REC.l6_pretmat ,V_REC.l6_var ,V_REC.l6_est ,
          V_REC.l7_cap  ,V_REC.l7_stoc ,V_REC.l7_vanz ,V_REC.l7_target ,V_REC.l7_npcant ,V_REC.l7_pret ,V_REC.l7_npval ,V_REC.l7_coefcap ,V_REC.l7_npfcant ,V_REC.l7_npfval ,V_REC.l7_pretmmr ,V_REC.l7_pretmat ,V_REC.l7_var ,V_REC.l7_est ,
          V_REC.l8_cap  ,V_REC.l8_stoc ,V_REC.l8_vanz ,V_REC.l8_target ,V_REC.l8_npcant ,V_REC.l8_pret ,V_REC.l8_npval ,V_REC.l8_coefcap ,V_REC.l8_npfcant ,V_REC.l8_npfval ,V_REC.l8_pretmmr ,V_REC.l8_pretmat ,V_REC.l8_var ,V_REC.l8_est ,
          V_REC.l9_cap  ,V_REC.l9_stoc ,V_REC.l9_vanz ,V_REC.l9_target ,V_REC.l9_npcant ,V_REC.l9_pret ,V_REC.l9_npval ,V_REC.l9_coefcap ,V_REC.l9_npfcant ,V_REC.l9_npfval ,V_REC.l9_pretmmr ,V_REC.l9_pretmat ,V_REC.l9_var ,V_REC.l9_est ,
          V_REC.l10_cap ,V_REC.l10_stoc,V_REC.l10_vanz,V_REC.l10_target,V_REC.l10_npcant,V_REC.l10_pret,V_REC.l10_npval,V_REC.l10_coefcap,V_REC.l10_npfcant,V_REC.l10_npfval,V_REC.l10_pretmmr,V_REC.l10_pretmat,V_REC.l10_var,V_REC.l10_est,
          V_REC.l11_cap ,V_REC.l11_stoc,V_REC.l11_vanz,V_REC.l11_target,V_REC.l11_npcant,V_REC.l11_pret,V_REC.l11_npval,V_REC.l11_coefcap,V_REC.l11_npfcant,V_REC.l11_npfval,V_REC.l11_pretmmr,V_REC.l11_pretmat,V_REC.l11_var,V_REC.l11_est,
          V_REC.l12_cap ,V_REC.l12_stoc,V_REC.l12_vanz,V_REC.l12_target,V_REC.l12_npcant,V_REC.l12_pret,V_REC.l12_npval,V_REC.l12_coefcap,V_REC.l12_npfcant,V_REC.l12_npfval,V_REC.l12_pretmmr,V_REC.l12_pretmat,V_REC.l12_var,V_REC.l12_est,
          V_REC.l1_npfval_orig, V_REC.l2_npfval_orig, V_REC.l3_npfval_orig, V_REC.l4_npfval_orig, V_REC.l5_npfval_orig, V_REC.l6_npfval_orig, 
          V_REC.l7_npfval_orig, V_REC.l8_npfval_orig, V_REC.l9_npfval_orig, V_REC.l10_npfval_orig, V_REC.l11_npfval_orig, V_REC.l12_npfval_orig
          );
      END IF;
    END LOOP;
    
    DELETE BUGETSTOC BS WHERE BS.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETSTOC FROM TMP_BUGETSTOC TMP WHERE TMP.CODBUGETSTOC = BS.CODBUGETSTOC);
    FOR V_REC IN (SELECT * FROM TMP_BUGETSTOC) LOOP
      IF V_REC.CODBUGETSTOC &gt; 0 THEN
        UPDATE BUGETSTOC
        SET
          CODOBIECT = V_REC.CODOBIECT,
          CODCLASEA = V_REC.CODCLASEA,
          STOC      = V_REC.STOC,
          COEFUM    = V_REC.COEFUM,
          VALTOTAL  = V_REC.VALTOTAL,
          VALMAT    = V_REC.VALMAT
        WHERE CODBUGETSTOC = V_REC.CODBUGETSTOC;
      ELSE
        INSERT INTO BUGETSTOC(CODBUGETSTOC, CODBUGETPROD, CODOBIECT, CODCLASEA, STOC, COEFUM, VALTOTAL, VALMAT)
        VALUES (SEQ_BUGETSTOC_CODBUGETSTOC.NEXTVAL, RECID, V_REC.CODOBIECT, V_REC.CODCLASEA, V_REC.STOC, V_REC.COEFUM, V_REC.VALTOTAL, V_REC.VALMAT);
      END IF;
    END LOOP;
    
    DELETE BUGETVL V WHERE V.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETVL FROM TMP_BUGETVL TMP WHERE TMP.CODBUGETVL = V.CODBUGETVL);
    FOR V_REC IN (SELECT * FROM TMP_BUGETVL) LOOP
      IF V_REC.CODBUGETVL &gt; 0 THEN
        UPDATE BUGETVL
        SET
          CODELEMBUGET = V_REC.CODELEMBUGET,
          L1  = V_REC.L1,
          L2  = V_REC.L2,
          L3  = V_REC.L3,
          L4  = V_REC.L4,
          L5  = V_REC.L5,
          L6  = V_REC.L6,
          L7  = V_REC.L7,
          L8  = V_REC.L8,
          L9  = V_REC.L9,
          L10 = V_REC.L10,
          L11 = V_REC.L11,
          L12 = V_REC.L12
        WHERE CODBUGETVL = V_REC.CODBUGETVL;
      ELSE
        INSERT INTO BUGETVL(CODBUGETVL,CODBUGETPROD,CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12)
        VALUES (SEQ_BUGETVL_CODBUGETVL.NEXTVAL, RECID, V_REC.CODELEMBUGET,V_REC.L1,V_REC.L2,V_REC.L3,V_REC.L4,V_REC.L5,V_REC.L6,V_REC.L7,V_REC.L8,V_REC.L9,V_REC.L10,V_REC.L11,V_REC.L12);
      END IF;
    END LOOP;
    
    DELETE BUGETCL C WHERE C.CODBUGETPROD = RECID AND NOT EXISTS (SELECT TMP.CODBUGETCL FROM TMP_BUGETCL TMP WHERE TMP.CODBUGETCL = C.CODBUGETCL);
    FOR V_REC IN (SELECT * FROM TMP_BUGETCL) LOOP
      IF V_REC.CODBUGETCL &gt; 0 THEN
        UPDATE BUGETCL
        SET
          CODELEMBUGET = V_REC.CODELEMBUGET,
          L1  = V_REC.L1,
          L2  = V_REC.L2,
          L3  = V_REC.L3,
          L4  = V_REC.L4,
          L5  = V_REC.L5,
          L6  = V_REC.L6,
          L7  = V_REC.L7,
          L8  = V_REC.L8,
          L9  = V_REC.L9,
          L10 = V_REC.L10,
          L11 = V_REC.L11,
          L12 = V_REC.L12
        WHERE CODBUGETCL = V_REC.CODBUGETCL;
      ELSE
        INSERT INTO BUGETCL(CODBUGETCL,CODBUGETPROD,CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12)
        VALUES (SEQ_BUGETCL_CODBUGETCL.NEXTVAL, RECID, V_REC.CODELEMBUGET,V_REC.L1,V_REC.L2,V_REC.L3,V_REC.L4,V_REC.L5,V_REC.L6,V_REC.L7,V_REC.L8,V_REC.L9,V_REC.L10,V_REC.L11,V_REC.L12);
      END IF;
    END LOOP;
    
  ELSE  -- INSERT
    SELECT SEQ_BUGETPROD_COD.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO BUGETPROD(CODBUGETPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF)
    SELECT RECID, AN, LUNA, SUBUNITATEA, PKG_GLOBALS.GETUSERID, SYSDATE, OBS, ANULAT, BLOCAT, OPERAT, SAPTAMANA, ANIMPORT, SAPTAMANAF, ANF
    FROM TMP_BUGETPROD;
    
    INSERT INTO BUGETPRODV(
      CODBUGETPRODV, CODBUGETPROD, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
      )
    SELECT 
      SEQ_BUGETPRODV_CODV.NEXTVAL, RECID, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
    FROM TMP_BUGETPRODV;
    
    INSERT INTO BUGETPRODT(
      CODBUGETPRODT, CODBUGETPROD, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
      )
    SELECT 
      SEQ_BUGETPRODT_CODT.NEXTVAL, RECID, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
    FROM TMP_BUGETPRODT;
    
    INSERT INTO BUGETPRODP(
      CODBUGETPRODP, CODBUGETPROD, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
      )
    SELECT 
      SEQ_BUGETPRODP_CODP.NEXTVAL, RECID, CODOBIECT, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
    FROM TMP_BUGETPRODP;
    
    INSERT INTO BUGETCAP(CODBUGETCAP, CODBUGETPROD, TIPCAP, CODCLASEA)
    SELECT SEQ_BUGETCAP_CODBUGETCAP.NEXTVAL, RECID, TIPCAP, CODCLASEA FROM TMP_BUGETCAP;
    
    INSERT INTO BUGETCAP1(
      CODBUGETCAP1, CODBUGETPROD, CODCLASEA, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
      )
    SELECT
      SEQ_BUGETCAP1_CODBUGETCAP1.NEXTVAL, RECID, CODCLASEA,
      S1, S2, S3, S4, S5, S6, S7, S8, S9,
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19,
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29,
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39,
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49,
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
    FROM TMP_BUGETCAPC;
    
    INSERT INTO BUGETCAP1(
      CODBUGETCAP1, CODBUGETPROD, CODCLASEA, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, 
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, 
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, 
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, 
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49, 
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
      )
    SELECT
      SEQ_BUGETCAP1_CODBUGETCAP1.NEXTVAL, RECID, CODCLASEA,
      S1, S2, S3, S4, S5, S6, S7, S8, S9,
      S10, S11, S12, S13, S14, S15, S16, S17, S18, S19,
      S20, S21, S22, S23, S24, S25, S26, S27, S28, S29,
      S30, S31, S32, S33, S34, S35, S36, S37, S38, S39,
      S40, S41, S42, S43, S44, S45, S46, S47, S48, S49,
      S50, S51, S52, S53,
      L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12
    FROM TMP_BUGETCAPV;
    
    INSERT INTO BUGETVCL(
      codbugetvcl,codbugetprod,codobiect,codclasea,tipcap,coefum,
      l1_cap,l1_stoc,l1_vanz,l1_target,l1_npcant,l1_pret,l1_npval,l1_coefcap,l1_npfcant,l1_npfval,l1_pretmmr,l1_pretmat,l1_var,l1_est,
      l2_cap,l2_stoc,l2_vanz,l2_target,l2_npcant,l2_pret,l2_npval,l2_coefcap,l2_npfcant,l2_npfval,l2_pretmmr,l2_pretmat,l2_var,l2_est,
      l3_cap,l3_stoc,l3_vanz,l3_target,l3_npcant,l3_pret,l3_npval,l3_coefcap,l3_npfcant,l3_npfval,l3_pretmmr,l3_pretmat,l3_var,l3_est,
      l4_cap,l4_stoc,l4_vanz,l4_target,l4_npcant,l4_pret,l4_npval,l4_coefcap,l4_npfcant,l4_npfval,l4_pretmmr,l4_pretmat,l4_var,l4_est,
      l5_cap,l5_stoc,l5_vanz,l5_target,l5_npcant,l5_pret,l5_npval,l5_coefcap,l5_npfcant,l5_npfval,l5_pretmmr,l5_pretmat,l5_var,l5_est,
      l6_cap,l6_stoc,l6_vanz,l6_target,l6_npcant,l6_pret,l6_npval,l6_coefcap,l6_npfcant,l6_npfval,l6_pretmmr,l6_pretmat,l6_var,l6_est,
      l7_cap,l7_stoc,l7_vanz,l7_target,l7_npcant,l7_pret,l7_npval,l7_coefcap,l7_npfcant,l7_npfval,l7_pretmmr,l7_pretmat,l7_var,l7_est,
      l8_cap,l8_stoc,l8_vanz,l8_target,l8_npcant,l8_pret,l8_npval,l8_coefcap,l8_npfcant,l8_npfval,l8_pretmmr,l8_pretmat,l8_var,l8_est,
      l9_cap,l9_stoc,l9_vanz,l9_target,l9_npcant,l9_pret,l9_npval,l9_coefcap,l9_npfcant,l9_npfval,l9_pretmmr,l9_pretmat,l9_var,l9_est,
      l10_cap,l10_stoc,l10_vanz,l10_target,l10_npcant,l10_pret,l10_npval,l10_coefcap,l10_npfcant,l10_npfval,l10_pretmmr,l10_pretmat,l10_var,l10_est,
      l11_cap,l11_stoc,l11_vanz,l11_target,l11_npcant,l11_pret,l11_npval,l11_coefcap,l11_npfcant,l11_npfval,l11_pretmmr,l11_pretmat,l11_var,l11_est,
      l12_cap,l12_stoc,l12_vanz,l12_target,l12_npcant,l12_pret,l12_npval,l12_coefcap,l12_npfcant,l12_npfval,l12_pretmmr,l12_pretmat,l12_var,l12_est,
      l1_npfval_orig, l2_npfval_orig, l3_npfval_orig, l4_npfval_orig, l5_npfval_orig, l6_npfval_orig, 
      l7_npfval_orig, l8_npfval_orig, l9_npfval_orig, l10_npfval_orig, l11_npfval_orig, l12_npfval_orig
      )
    SELECT
      SEQ_BUGETVCL_codbugetvcl.NEXTVAL,RECID,codobiect,codclasea,tipcap,coefum,
      l1_cap,l1_stoc,l1_vanz,l1_target,l1_npcant,l1_pret,l1_npval,l1_coefcap,l1_npfcant,l1_npfval,l1_pretmmr,l1_pretmat,l1_var,l1_est,
      l2_cap,l2_stoc,l2_vanz,l2_target,l2_npcant,l2_pret,l2_npval,l2_coefcap,l2_npfcant,l2_npfval,l2_pretmmr,l2_pretmat,l2_var,l2_est,
      l3_cap,l3_stoc,l3_vanz,l3_target,l3_npcant,l3_pret,l3_npval,l3_coefcap,l3_npfcant,l3_npfval,l3_pretmmr,l3_pretmat,l3_var,l3_est,
      l4_cap,l4_stoc,l4_vanz,l4_target,l4_npcant,l4_pret,l4_npval,l4_coefcap,l4_npfcant,l4_npfval,l4_pretmmr,l4_pretmat,l4_var,l4_est,
      l5_cap,l5_stoc,l5_vanz,l5_target,l5_npcant,l5_pret,l5_npval,l5_coefcap,l5_npfcant,l5_npfval,l5_pretmmr,l5_pretmat,l5_var,l5_est,
      l6_cap,l6_stoc,l6_vanz,l6_target,l6_npcant,l6_pret,l6_npval,l6_coefcap,l6_npfcant,l6_npfval,l6_pretmmr,l6_pretmat,l6_var,l6_est,
      l7_cap,l7_stoc,l7_vanz,l7_target,l7_npcant,l7_pret,l7_npval,l7_coefcap,l7_npfcant,l7_npfval,l7_pretmmr,l7_pretmat,l7_var,l7_est,
      l8_cap,l8_stoc,l8_vanz,l8_target,l8_npcant,l8_pret,l8_npval,l8_coefcap,l8_npfcant,l8_npfval,l8_pretmmr,l8_pretmat,l8_var,l8_est,
      l9_cap,l9_stoc,l9_vanz,l9_target,l9_npcant,l9_pret,l9_npval,l9_coefcap,l9_npfcant,l9_npfval,l9_pretmmr,l9_pretmat,l9_var,l9_est,
      l10_cap,l10_stoc,l10_vanz,l10_target,l10_npcant,l10_pret,l10_npval,l10_coefcap,l10_npfcant,l10_npfval,l10_pretmmr,l10_pretmat,l10_var,l10_est,
      l11_cap,l11_stoc,l11_vanz,l11_target,l11_npcant,l11_pret,l11_npval,l11_coefcap,l11_npfcant,l11_npfval,l11_pretmmr,l11_pretmat,l11_var,l11_est,
      l12_cap,l12_stoc,l12_vanz,l12_target,l12_npcant,l12_pret,l12_npval,l12_coefcap,l12_npfcant,l12_npfval,l12_pretmmr,l12_pretmat,l12_var,l12_est,
      l1_npfval_orig, l2_npfval_orig, l3_npfval_orig, l4_npfval_orig, l5_npfval_orig, l6_npfval_orig, 
      l7_npfval_orig, l8_npfval_orig, l9_npfval_orig, l10_npfval_orig, l11_npfval_orig, l12_npfval_orig
    FROM TMP_BUGETVCL;
    
    INSERT INTO BUGETSTOC(CODBUGETSTOC, CODBUGETPROD, CODOBIECT, CODCLASEA, STOC, COEFUM, VALTOTAL, VALMAT)
    SELECT SEQ_BUGETSTOC_CODBUGETSTOC.NEXTVAL, RECID, CODOBIECT, CODCLASEA, STOC, COEFUM, VALTOTAL, VALMAT FROM TMP_BUGETSTOC;
    
    INSERT INTO BUGETVL(CODBUGETVL,CODBUGETPROD,CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12)
    SELECT SEQ_BUGETVL_CODBUGETVL.NEXTVAL, RECID, CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12
    FROM TMP_BUGETVL;
    
    INSERT INTO BUGETCL(CODBUGETCL,CODBUGETPROD,CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12)
    SELECT SEQ_BUGETCL_CODBUGETCL.NEXTVAL, RECID, CODELEMBUGET,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12
    FROM TMP_BUGETCL;
  END IF;
  
  COMMIT;
END;  

FUNCTION GET_BUGETSTOC RETURN BUGETSTOC_CURSOR
IS
TMPCURSOR BUGETSTOC_CURSOR;
ASUB NUMBER(20);
BEGIN
  ASUB := PKG_GLOBALS.GETSUBUNITATE;
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  DELETE TMP_MANEVRA;
  DELETE TMP_NIRSTOC_MAN;
  
  INSERT INTO TMP_MANEVRA(CODUNIC)
  SELECT CODOBIECT
  FROM NARTOBJ 
  WHERE PRODUSPROPRIU = 2 AND NVL(INACTIV,0) = 0;
  
  INSERT INTO TMP_NIRSTOC_MAN(CODOBIECT, CODNIR, REST)
  SELECT NS.CODOBIECT, NS.CODNIR, NS.REST
  FROM NIRSTOC NS
       INNER JOIN TMP_MANEVRA TMP ON TMP.CODUNIC = NS.CODOBIECT
       INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
       INNER JOIN NGEST G ON G.CODGEST = NIR.GEST,
       TMP_IOART_LUNA IOALUNA
  WHERE NS.CODIOART = IOALUNA.CODIOART AND G.TIP &lt;&gt; 4 AND NS.REST &lt;&gt; 0
        AND NIR.OPERAT = 1 AND IOALUNA.MG &lt;&gt; 5 AND (G.CODSUBUNIT = ASUB OR ASUB = 1);
  
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT 
      OBJ.CODOBIECT,
      OBJ.CODEXTERN,
      OBJ.DENUMIRE,
      CLS.CODCLASEA,
      CLS.DEN_CLASEA,
      DECODE(NVL(NUM.COEF,1),0,1,NVL(NUM.COEF,1)) COEFUM,
      NVL(PC.VALMAT,0) VALMAT,
      NVL(PC.VALMAT,0) + NVL(PC.VALMAN,0) + NVL(PC.VALREGIE,0) VALTOTAL,
      SUM(NS.REST) STOC
    FROM
      TMP_MANEVRA TMP
      INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = TMP.CODUNIC
      INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = ART.UM
      LEFT JOIN TMP_NIRSTOC_MAN NS ON NS.CODOBIECT = TMP.CODUNIC
      LEFT JOIN NCLASEA CLS ON CLS.CODCLASEA = NVL(ART.CLASA,0)
      LEFT JOIN PRODCOMP PC ON PC.CODOBIECT = TMP.CODUNIC AND PC.IMPLICIT = 1
    GROUP BY OBJ.CODOBIECT, OBJ.CODEXTERN, OBJ.DENUMIRE, CLS.CODCLASEA, CLS.DEN_CLASEA, NVL(NUM.COEF,1), NVL(PC.VALMAT,0), NVL(PC.VALMAN,0), NVL(PC.VALREGIE,0);
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

end PKG_BUGETPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_BUGETRECTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02EC6DD5802206CE4ACC99F84AFE26679EB5F1AE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_BUGETRECTIF is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodBUGETRECTIF INTO Tmp FROM BUGETRECTIF WHERE CodBUGETRECTIF = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM BUGETRECTIF WHERE CodBUGETRECTIF = RecId ;
 	DELETE FROM BUGETRECTIF1 WHERE CodBUGETRECTIF = RecId ;

	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_BUGETRECTIF FIELDS( CodBUGETRECTIF ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
	INSERT INTO  TMP_BUGETRECTIF 
	(   CODBUGETRECTIF,
      NRDOC,
      DATADOC,
      AN,
      LUNASURSA,
      LUNADEST,
      OBS,
      USERID,
      DATACREARE,
      CODANALIZA
   )
	SELECT 
	    B.CODBUGETRECTIF,
      B.NRDOC,
      B.DATADOC,
      B.AN,
      B.LUNASURSA,
      B.LUNADEST,
      B.OBS,
      B.USERID,
      B.DATACREARE,
      B.CODANALIZA
  FROM BUGETRECTIF B
  WHERE B.CodBUGETRECTIF = RECID;

  INSERT INTO  TMP_BUGETRECTIF1
	(   CODBUGETRECTIF1,
      CODBUGETRECTIF, 
      CODNODSURSA,
      CODNODDEST,
      VCREDIT,
      VANGAJAPROB,
      VANGAJREAL,
      VPLATAAPROB,
      VPLATAREAL,
      VCHELT,
			vplanif,
			vfact,
			vincasReal
		)
	SELECT 
	    B1.CODBUGETRECTIF1,
      B1.CODBUGETRECTIF, 
      B1.CODNODSURSA,
      B1.CODNODDEST,
      B1.VCREDIT,
      B1.VANGAJAPROB,
      B1.VANGAJREAL,
      B1.VPLATAAPROB,
      B1.VPLATAREAL,
      B1.VCHELT,
			B1.vplanif,
			B1.vfact,
			B1.vincasReal
  FROM BUGETRECTIF1 B1 
  where B1.CodBUGETRECTIF = RecId;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodBUGETRECTIF INTO RECID FROM TMP_BUGETRECTIF;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE BUGETRECTIF
    SET
	(   CODBUGETRECTIF,
      NRDOC,
      DATADOC,
      AN,
      LUNASURSA,
      LUNADEST,
      OBS,
      USERID,
      DATACREARE,
      CODANALIZA
   )
      = 
     (SELECT 
          CODBUGETRECTIF,
          NRDOC,
          DATADOC,
          AN,
          LUNASURSA,
          LUNADEST,
          OBS,
          USERID,
          DATACREARE,
          CODANALIZA
     FROM TMP_BUGETRECTIF)
     WHERE CodBUGETRECTIF = RECID;

--BugetRectif1  

    DELETE FROM BUGETRECTIF1 
    where CODBUGETRECTIF = RecID 
    and CodBUGETRECTIF1 not in (Select CODBUGETRECTIF1 from TMP_BUGETRECTIF1);

    for v_rec in (select * from TMP_BUGETRECTIF1 where CODBUGETRECTIF1 &lt; 0) loop
        INSERT INTO BUGETRECTIF1
          ( 
              CODBUGETRECTIF1,
              CODBUGETRECTIF, 
              CODNODSURSA,
              CODNODDEST,
              VCREDIT,
              VANGAJAPROB,
              VANGAJREAL,
              VPLATAAPROB,
              VPLATAREAL,
							VCHELT,
							vplanif,
							vfact,
							vincasReal
           )
          Values 
          ( SEQ_BUGETRECTIF1_CODBUGETRECT1.Nextval,
            RecId ,
            v_rec.CODNODSURSA,
            v_rec.CODNODDEST,
            v_rec.VCREDIT,
            v_rec.VANGAJAPROB,
            v_rec.VANGAJREAL,
            v_rec.VPLATAAPROB,
            v_rec.VPLATAREAL,
						v_rec.VCHELT,
						v_rec.vplanif,
						v_rec.vfact,
						v_rec.vincasReal
            );
    end loop;
    for v_rec in (select * from TMP_BUGETRECTIF1 where CODBUGETRECTIF1 &gt; 0) loop
        update BUGETRECTIF1 set 
         CODNODSURSA =  v_rec.CODNODSURSA,
         CODNODDEST  =  v_rec.CODNODDEST,
         VCREDIT     =  v_rec.VCREDIT,
         VANGAJAPROB =  v_rec.VANGAJAPROB,
         VANGAJREAL  =  v_rec.VANGAJREAL,
         VPLATAAPROB =  v_rec.VPLATAAPROB,
         VPLATAREAL  =  v_rec.VPLATAREAL,
         VCHELT      =  v_rec.VCHELT,
  			 vplanif     =  v_rec.vplanif,
         vfact       =  v_rec.vfact,
         vincasReal  =  v_rec.vincasReal
        where CODBugetRectif1 = v_rec.CODBugetRectif1;
    end loop;

ELSE  -- INSERT
    SELECT SEQ_BUGETRECTIF_CodBUGETRECT.NextVal INTO RecId FROM DUAL;
    INSERT INTO BUGETRECTIF(
          CODBUGETRECTIF,
          NRDOC,
          DATADOC,
          AN,
          LUNASURSA,
          LUNADEST,
          OBS,
          USERID,
          DATACREARE,
          CODANALIZA 
        )             
    SELECT 
       RECID , 
       NRDOC,
       DATADOC,
       AN,
       LUNASURSA,
       LUNADEST,
       OBS,
       PKG_GLOBALS.USERID, 
       SYSTIMESTAMP,
       CODANALIZA 
    FROM TMP_BugetRectif;

    for v_rec in (select * from TMP_BugetRectif1) loop
        INSERT INTO BugetRectif1 
        ( 
            CODBUGETRECTIF1,
            CODBUGETRECTIF, 
            CODNODSURSA,
            CODNODDEST,
            VCREDIT,
            VANGAJAPROB,
            VANGAJREAL,
            VPLATAAPROB,
            VPLATAREAL,
            VCHELT,
						vplanif,
						vfact,
						vincasReal
        )
          Values 
          ( SEQ_BUGETRECTIF1_CODBUGETRECT1.Nextval,
            RecId ,
            V_REC.CODNODSURSA,
            V_REC.CODNODDEST,
            V_REC.VCREDIT,
            V_REC.VANGAJAPROB,
            V_REC.VANGAJREAL,
            V_REC.VPLATAAPROB,
            V_REC.VPLATAREAL,
						v_rec.VCHELT,
						v_rec.vplanif,
						v_rec.vfact,
						v_rec.vincasReal
          );
    end loop;
  END IF;
  NotifyModif(Operation, RecId, &apos;BUGETRECTIF&apos;);
COMMIT;
END; 


end PKG_BUGETRECTIF; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CAENSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6495A0007F823F8949619B1273C6947A40DD3C73</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CAENSEC IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCAENSEC INTO Tmp FROM CAENSEC WHERE CODCAENSEC = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM CAENSEC WHERE CODCAENSEC = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CAENSEC FIELDS(CODCAENSEC) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master CAENSEC
  INSERT INTO TMP_CAENSEC (codcaensec, caen, denumire)
  SELECT codcaensec, caen, denumire
  FROM CAENSEC
  WHERE codcaensec = RecId ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    -- Master CAENSEC
    UPDATE CAENSEC
    SET (codcaensec, caen, denumire ) = (SELECT codcaensec, caen, denumire FROM TMP_CAENSEC )
    WHERE codcaensec = RecId ;
  ELSE  -- INSERT
-- Master CAENSEC
    SELECT SEQ_CAENSEC_CODCAENSEC.NextVal INTO RecId FROM DUAL;
    INSERT INTO  CAENSEC (codcaensec, caen, denumire)
    SELECT RecId, caen, denumire
    FROM TMP_CAENSEC ;
  END IF;

  NotifyModif(Operation, RecId, &apos;CAENSEC&apos;);
  COMMIT;

END;

END PKG_CAENSEC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CAMPANII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26E33E384AB4B2CE42A07001D5A2A0571BCB6246</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CAMPANII IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_54&apos;;

procedure SP_LockRecord(RecId in NUMBER) is
  Tmp NUMBER(20);
begin
  SELECT CodCampanie INTO Tmp FROM Campanii WHERE CodCampanie = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
  aDoc varchar2(250);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Campanie &quot;&apos;||dencampanie||&apos;&quot;&apos; INTO aDoc FROM Campanii WHERE codcampanie = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;Campanii&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM CampaniiCost WHERE CodCampanie = RecId;
  DELETE FROM CampaniiVenit WHERE CodCampanie = RecId;
  DELETE FROM CampaniiPart WHERE CodCampanie = RecId;
  DELETE FROM Campanii WHERE CodCampanie = RecId;
  NotifyModif(2, RECID, &apos;Campanii&apos;);
  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_Campanii FIELDS(CodCampanie) VALUES (0);
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
  --lInfoDoc VARCHAR2(250);
  --lValDoc NUMBER(20,7);
begin
  INSERT INTO Tmp_Campanii (
    CodCampanie,
    DenCampanie,
    Obiectiv,
    Target,
    DataInit, DataFin,
    CodMoneda,
    CodResponsabil,
    CostEstimat, VenitEstimat,
    CodSubunitate
  )(
    SELECT
      CodCampanie,
      DenCampanie,
      Obiectiv,
      Target,
      DataInit, DataFin,
      CodMoneda,
      CodResponsabil,
      CostEstimat, VenitEstimat,
      CodSubunitate
    FROM Campanii
    WHERE CodCampanie = RecId
  );

  INSERT INTO Tmp_CampaniiCost (
    CodCampanieCost, CodCampanie, CodDoc, TipDoc, IndexLocal,
    NrDoc,
    DataDoc,
    ValDoc,
    PrefixDoc,
    CodPart
  )(
    SELECT
      CC.CodCampanieCost, CC.CodCampanie, CC.CodDoc, CC.TipDoc, CC.IndexLocal,
      case
        when CC.TipDoc = 0 then CC.NrDoc
        when CC.TipDoc IN (1, 2, 3, 4, 5, 6, 7) then (SELECT To_Char(I.NrDoc) FROM Intrari I WHERE I.CodIntr = CC.CodDoc)
        when CC.TipDoc in (24,19,21,26) then (SELECT To_Char(I.NrDoc) FROM Iesiri I WHERE I.CodIes = CC.CodDoc)
        when CC.TipDoc in (29, 30, 31, 33) then (SELECT to_char(T1.NrDoc) FROM Trezor1 T1 WHERE T1.CodTrezor1 = CC.CodDoc)
        when CC.TipDoc = 35 then (SELECT To_Char(NC.NrDoc) FROM Nc WHERE NC.CodNc = CC.CodDoc)
      END NrDoc,
      case
        when CC.TipDoc = 0 then CC.DataDoc
        when CC.TipDoc in (1, 2, 3, 4, 5, 6, 7) then (SELECT I.DataDoc FROM Intrari I WHERE I.CodIntr = CC.CodDoc)
        when CC.TipDoc in (24,19,21,26) then (SELECT I.DataDoc FROM Iesiri I WHERE I.CodIes = CC.CodDoc)
        when CC.TipDoc in (29, 30, 31, 33) then (SELECT T1.DataDoc FROM Trezor1 T1 WHERE T1.CodTrezor1 = CC.CodDoc)
        when CC.TipDoc = 35 then (SELECT NC.DataDoc FROM Nc WHERE NC.CodNc = CC.CodDoc)
      END DataDoc,
      coalesce(cc.valdoc,case
        when CC.TipDoc = 0 then CC.ValDoc
        when CC.TipDoc in (1, 2, 3, 4, 5, 6, 7) then (SELECT SUM(I1.PretOrig * I1.Cant * NVL(I1.CoefDiscMaj, 1)) FROM Intrari1 I1 WHERE I1.CodIntr = CC.CodDoc)
        when CC.TipDoc in (24,19,21,26) then (SELECT SUM((I1.PretOrig * I1.Cant/* + I1.TVA*/) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = CC.CodDoc)
        when CC.TipDoc in (29, 30, 31, 33) then (SELECT case when T1.TipTranz = 0 then (T1.ValDoc + nvl(T1.Comision, 0)) else -(T1.ValDoc + nvl(T1.Comision, 0)) end FROM Trezor1 T1 WHERE T1.CodTrezor1 = CC.CodDoc)
        when CC.TipDoc = 35 then (SELECT Sum(Nc1.Valoare) FROM Nc1 WHERE NC1.CodNc = CC.CodDoc)
      END) ValDoc,
      case
        when CC.TipDoc = 0 then CC.PrefixDoc
        when CC.TipDoc IN (1, 2, 3, 4, 5, 6, 7) then (SELECT I.PrefixDoc FROM Intrari I WHERE I.CodIntr = CC.CodDoc)
        when CC.TipDoc in (24,19,21,26) then (SELECT I.PrefixDoc FROM Iesiri I WHERE I.CodIes = CC.CodDoc)
        when CC.TipDoc IN (29, 30, 31, 33) then &apos;TREZ&apos;
        when CC.TipDoc = 35 then &apos;NC&apos;
      END InfoDoc,
      case
        when CC.TipDoc = 0 then CC.CodPart
        when CC.TipDoc IN (1, 2, 3, 4, 5, 6, 7) then (SELECT I.Partener FROM Intrari I WHERE I.CodIntr = CC.CodDoc)
        when CC.TipDoc in (24,19,21,26) then (SELECT I.Partener FROM Iesiri I WHERE I.CodIes = CC.CodDoc)
        when CC.TipDoc IN (29, 30, 31, 33) then (SELECT T1.CodPart FROM Trezor1 T1 WHERE T1.CodTrezor1 = CC.CodDoc)
        when CC.TipDoc = 35 then (select nc.part from nc where nc.codnc = cc.coddoc)
      END CodPart
    FROM CampaniiCost CC
    WHERE CC.CodCampanie = RecId
  );
  INSERT INTO Tmp_CampaniiVenit (
    CodCampanieVenit, CodCampanie, CodDoc, TipDoc, IndexLocal,
    NrDoc,
    DataDoc,
    ValDoc,
    ValFact,
    PrefixDoc,
    CodPart
  )(
    SELECT
      CV.CodCampanieVenit, CV.CodCampanie, CV.CodDoc, CV.TipDoc, CV.IndexLocal,
      case
        when CV.TipDoc = 0 then CV.NrDoc
        when CV.TipDoc = 18 then (SELECT To_Char(C.NrDoc) FROM Comanda C WHERE C.CodComanda = CV.CodDoc)
        when CV.TipDoc IN (19, 26) then (SELECT To_Char(I.NrDoc) FROM Iesiri I WHERE I.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then (SELECT To_Char(NC.NrDoc) FROM Nc WHERE NC.CodNc = CV.CodDoc)
      END InfoDoc,
      case
        when CV.TipDoc = 0 then CV.DataDoc
        when CV.TipDoc = 18 then (SELECT C.DataDoc FROM Comanda C where C.CodComanda = CV.CodDoc)
        when CV.TipDoc IN (19, 26) then (SELECT I.DataDoc FROM Iesiri I WHERE I.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then (SELECT NC.DataDoc FROM Nc WHERE NC.CodNc = CV.CodDoc)
      END DataDoc,
      coalesce(cv.valdoc,case
        when CV.TipDoc = 0 then CV.ValDoc
        when CV.TipDoc = 18 then (SELECT SUM(C1.PU * C1.CantAcceptat * NVL(C1.CoefDiscMaj, 1)) FROM Comanda1 C1 WHERE C1.CodComanda = CV.CodDoc) -- acceptat
        when CV.TipDoc IN (19, 26) then (SELECT SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then (SELECT Sum(Nc1.Valoare) FROM Nc1 WHERE NC1.CodNc = CV.CodDoc)
      END) ValDoc,
      case
        when CV.TipDoc = 18 then
          (
            SELECT Nvl(SUM((I1.PretOrig * I1.Cant/* + I1.TVA*/) * NVL(I1.CoefDiscMaj, 1)),0)
            FROM Comanda1 C1
              LEFT OUTER JOIN IesLink IL ON IL.CodLinieComanda = C1.Codcomanda1
              LEFT OUTER JOIN Iesiri1 I1 ON I1.CodIes1 = IL.CodIes1
            WHERE C1.CodComanda = CV.CodDoc
          ) -- facturat
        when CV.TipDoc IN (19, 26) then (SELECT SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then 0
        else CV.Valfact
      END ValFact,
      case
        when CV.TipDoc = 0 then CV.PrefixDoc
        when CV.TipDoc = 18 then (SELECT C.PrefixDoc FROM Comanda C WHERE C.CodComanda = CV.CodDoc)
        when CV.TipDoc IN (19, 26) then (SELECT I.PrefixDoc FROM Iesiri I WHERE I.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then &apos;NC&apos;
      END PrefixDoc,
      case
        when CV.TipDoc = 0 then CV.CodPart
        when CV.TipDoc = 18 then (SELECT C.Partener FROM Comanda C WHERE C.CodComanda = CV.CodDoc)
        when CV.TipDoc IN (19, 26) then (SELECT I.Partener FROM Iesiri I WHERE I.CodIes = CV.CodDoc)
        when CV.TipDoc = 35 then (select nc.part from nc where nc.codnc = cv.coddoc)
      END CodPart
    FROM CampaniiVenit CV
    WHERE CV.CodCampanie = RecId
  );
  INSERT INTO TMP_CampaniiPart (
    CodCampaniePart,
    CodCampanie,
    CodPart,
    Den_Part,
    CodExtern,
    CodIntern,
    RegCom,
    CodFiscal,
    Selectat,
    CodOportunitate,
    oportunitate,
    codpers
  )(
    SELECT
      CP.CodCampaniePart,
      CP.CodCampanie,
      CP.CodPart,
      NP.Den_Part,
      NP.CodExtern,
      NP.CodIntern,
      NP.RegCom,
      NPCF.CodFiscal,
      0,
      o.codoportunitate,
      o.prefixdoc||&apos; &apos;||o.nrdoc||&apos;/&apos;||to_char(o.datadoc,&apos;dd.mm.yyyy&apos;),
      nvl(p.codpersc, pp.codpersc)
    FROM
      CampaniiPart CP
      LEFT JOIN NPart NP ON NP.CodPart = CP.CodPart
      LEFT JOIN NPartCodFisc NPCF ON NPCF.CodPart = CP.CodPart AND NPCF.Principal = 1
      left join nperscontact p on p.codpart = np.codpart and p.implicit = 1
      left join (select min(codpersc) codpersc, codpart from nperscontact group by codpart) pp on pp.codpart = np.codpart
      left join oportunitati o on o.codcampanie = cp.codcampaniepart
    WHERE CP.CodCampanie = RecId
  );
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
  aDoc varchar2(200);
begin
  if Operation = 0 then -- UPDATE
    SELECT CodCampanie INTO RecId FROM Tmp_Campanii;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Campanie &quot;&apos;||dencampanie||&apos;&quot;&apos; INTO aDoc FROM Campanii WHERE codcampanie = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Campanii&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE Campanii SET (
      CodCampanie,
      DenCampanie,
      Obiectiv,
      Target,
      DataInit, DataFin,
      CodMoneda,
      CodResponsabil,
      CostEstimat, VenitEstimat,
      CodSubunitate
    ) = (
      SELECT
        CodCampanie,
        DenCampanie,
        Obiectiv,
        Target,
        DataInit, DataFin,
        CodMoneda,
        CodResponsabil,
        CostEstimat, VenitEstimat,
        CodSubunitate
      FROM Tmp_Campanii
    )
    WHERE CodCampanie = RecId;
    DELETE FROM CampaniiCost
    WHERE
      CodCampanie = RecId AND
      CodCampanieCost NOT IN (SELECT CodCampanieCost FROM Tmp_CampaniiCost);
    for V_Rec in
      (SELECT * FROM Tmp_CampaniiCost ORDER BY IndexLocal)
    loop
      if nvl(V_Rec.CodCampanieCost, 0) &gt; 0 then
        UPDATE CampaniiCost SET
          CodDoc = V_Rec.CodDoc,
          TipDoc = V_Rec.TipDoc,
          IndexLocal = V_Rec.IndexLocal,
          NrDoc = v_rec.nrdoc,
          datadoc = v_rec.datadoc,
          prefixdoc = v_rec.prefixdoc,
          valdoc = v_rec.valdoc,
          codpart = v_rec.codpart
        WHERE CodCampanieCost = V_Rec.CodCampanieCost;
      else
        INSERT INTO CampaniiCost (
          CodCampanieCost, CodCampanie,
          CodDoc, TipDoc, IndexLocal,
          nrdoc, prefixdoc, datadoc, valdoc,
          codpart
        ) VALUES (
          Seq_CampaniiCost_CodCC.NextVal, RecId,
          V_Rec.CodDoc, V_Rec.TipDoc, V_Rec.IndexLocal,
          V_Rec.nrdoc, V_Rec.prefixdoc, V_Rec.datadoc, V_Rec.valdoc,
          v_rec.codpart
        );
      end if;
    end loop;
    DELETE FROM CampaniiVenit
    WHERE
      CodCampanie = RecId AND
      CodCampanieVenit NOT IN (SELECT CodCampanieVenit FROM Tmp_CampaniiVenit);
    for V_Rec in
      (SELECT * FROM Tmp_CampaniiVenit ORDER BY IndexLocal)
    loop
      if nvl(V_Rec.CodCampanieVenit, 0) &gt; 0 then
        UPDATE CampaniiVenit SET
          CodDoc = V_Rec.CodDoc,
          TipDoc = V_Rec.TipDoc,
          IndexLocal = V_Rec.IndexLocal,
          NrDoc = v_rec.nrdoc,
          datadoc = v_rec.datadoc,
          prefixdoc = v_rec.prefixdoc,
          valdoc = v_rec.valdoc,
          codpart = v_rec.codpart,
          valfact = v_rec.valfact
        WHERE CodCampanieVenit = V_Rec.CodCampanieVenit;
      else
        INSERT INTO CampaniiVenit (
          CodCampanieVenit, CodCampanie,
          CodDoc, TipDoc, IndexLocal,
          nrdoc, prefixdoc, datadoc, valdoc,
          codpart, valfact
        ) VALUES (
          Seq_CampaniiVenit_CodCV.NextVal, RecId,
          V_Rec.CodDoc, V_Rec.TipDoc, V_Rec.IndexLocal,
          v_rec.nrdoc, v_rec.prefixdoc, v_rec.datadoc, v_rec.valdoc,
          v_rec.codpart, v_rec.valfact
        );
      end if;
    end loop;
    DELETE FROM CampaniiPart
    WHERE
      CodCampanie = RecId AND
      CodCampaniePart NOT IN (SELECT CodCampaniePart FROM TMP_CampaniiPart);
    FOR V_Rec IN
      (SELECT * FROM TMP_CampaniiPart)
    LOOP
      IF NVL(V_Rec.CodCampaniePart, 0) &gt; 0 THEN
        UPDATE CampaniiPart SET
          CodPart = V_Rec.CodPart
        WHERE CodCampaniePart = V_Rec.CodCampaniePart;
      ELSE
        INSERT INTO CampaniiPart (
          CodCampaniePart,
          CodCampanie,
          CodPart
        ) VALUES (
          SEQ_CampaniiPart_CodCP.NextVal,
          RecId,
          V_Rec.CodPart
        );
      END IF;
    END LOOP;
  else  -- INSERT
    SELECT Seq_Campanii_CodCampanie.NextVal INTO RecId FROM DUAL;
    INSERT INTO Campanii (
      CodCampanie,
      DenCampanie,
      Obiectiv,
      Target,
      DataInit, DataFin,
      CodMoneda,
      CodResponsabil,
      CostEstimat, VenitEstimat,
      CodSubunitate
    )(
      SELECT
        RecId,
        DenCampanie,
        Obiectiv,
        Target,
        DataInit, DataFin,
        CodMoneda,
        CodResponsabil,
        CostEstimat, VenitEstimat,
        CodSubunitate
      FROM Tmp_Campanii
    );

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Campanie &quot;&apos;||dencampanie||&apos;&quot;&apos; INTO aDoc FROM Campanii WHERE codcampanie = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Campanii&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO CampaniiCost (
      CodCampanieCost, CodCampanie,
      CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc
    )(
      SELECT
        Seq_CampaniiCost_CodCC.NextVal, RecId,
        CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc
      FROM (
        SELECT CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc
        FROM Tmp_CampaniiCost ORDER BY IndexLocal
      )
    );
    INSERT INTO CampaniiVenit (
      CodCampanieVenit, CodCampanie,
      CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc, valfact
    )(
      SELECT
        Seq_CampaniiVenit_CodCV.NextVal, RecId,
        CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc, valfact
      FROM (
        SELECT CodDoc, TipDoc, IndexLocal,
      nrdoc, datadoc, prefixdoc, valdoc, valfact
        FROM Tmp_CampaniiVenit ORDER BY IndexLocal
      )
    );
    INSERT INTO CampaniiPart (
      CodCampaniePart, CodCampanie,
      CodPart
    )(
      SELECT
        SEQ_CampaniiPart_CodCP.NextVal, RecId,
        CodPart
      FROM (
        SELECT CodPart
        FROM TMP_CampaniiPart
      )
    );
  end if;
  NotifyModif(OPERATION, RECID, &apos;Campanii&apos;);
  COMMIT;
end;

PROCEDURE AdaugaDocMarketing(aCodCampanie in number, aCodDoc in number, aTipDoc in number, aCodPart in number, aForce in number, aExista out number, aDenCampanie out varchar2) is
  lCount number(20) := 0;
  lIndexLocal number(20) := 0;
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  -- stef NoteContabile poate merge pe venit sau costr asa ca fac trimitere cu semn schimbat la tipdoc in caz de cost sa pot face diferenta
  if aForce &lt;&gt; 1 then
    aDenCampanie := &apos;&apos;;
  -- stef NoteContabile poate merge pe venit sau costr asa ca fac trimitere cu semn schimbat la tipdoc in caz de cost sa pot face diferenta
    IF aTipDoc in (1, 2, 3, 4, 5, 6, 7, 24, 29, 30, 31, 33, -35, -19, -26, -21) THEN
      SELECT COUNT(*) INTO lCount FROM CampaniiCost WHERE CodDoc = aCodDoc AND TipDoc = abs(aTipDoc);
      SELECT NVL(MAX(IndexLocal), 0) INTO lIndexLocal FROM CampaniiCost WHERE CodCampanie = aCodCampanie;
      if lCount = 0 then
        aExista := lCount;
        INSERT INTO CampaniiCost (
          CodCampanieCost,
          CodCampanie,
          CodDoc,
          TipDoc,
          IndexLocal,
          CodPart
        ) VALUES (
          Seq_CampaniiCost_CodCC.NextVal,
          aCodCampanie,
          aCodDoc,
          Abs(aTipDoc),
          lIndexLocal + 1,
          aCodPart
        );
        COMMIT;
      else
        aExista := lCount;
        begin
          select string_agg(c.dencampanie||&apos;: &apos;||to_char(c.datainit,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||to_char(c.datafin,&apos;dd.mm.yyyy&apos;)) into aDenCampanie
          from campanii c
               inner join campaniicost cc on cc.codcampanie = c.codcampanie
          WHERE cc.CodDoc = aCodDoc AND cc.TipDoc = aTipDoc;
        exception when others then aDenCampanie := &apos;&apos;;
        end;  
      end if;
    END IF;
    IF aTipDoc IN (18, 19, 26, 35) THEN
      SELECT COUNT(*) INTO lCount FROM CampaniiVenit WHERE CodDoc = aCodDoc AND TipDoc = aTipDoc;
      SELECT NVL(MAX(IndexLocal), 0) INTO lIndexLocal FROM CampaniiVenit WHERE CodCampanie = aCodCampanie;
      if lCount = 0 then
        INSERT INTO CampaniiVenit (
          CodCampanieVenit,
          CodCampanie,
          CodDoc,
          TipDoc,
          IndexLocal,
          CodPart
        ) VALUES (
          Seq_CampaniiVenit_CodCV.NextVal,
          aCodCampanie,
          aCodDoc,
          aTipDoc,
          lIndexLocal + 1,
          aCodPart
        );
        COMMIT;
      else
        aExista := lCount;
        begin
          select string_agg(c.dencampanie||&apos;: &apos;||to_char(c.datainit,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||to_char(c.datafin,&apos;dd.mm.yyyy&apos;)) into aDenCampanie
          from campanii c
               inner join campaniivenit cc on cc.codcampanie = c.codcampanie
          WHERE cc.CodDoc = aCodDoc AND cc.TipDoc = aTipDoc;
        exception when others then aDenCampanie := &apos;&apos;;  
        end;
      END IF;
    END IF;
  else
    IF aTipDoc in (1, 2, 3, 4, 5, 6, 7, 24, 29, 30, 31, 33, -35) THEN
      delete FROM CampaniiCost WHERE CodDoc = aCodDoc AND TipDoc = aTipDoc;
      SELECT NVL(MAX(IndexLocal), 0) INTO lIndexLocal FROM CampaniiCost WHERE CodCampanie = aCodCampanie;
      INSERT INTO CampaniiCost (
        CodCampanieCost,
        CodCampanie,
        CodDoc,
        TipDoc,
        IndexLocal,
        CodPart
      ) VALUES (
        Seq_CampaniiCost_CodCC.NextVal,
        aCodCampanie,
        aCodDoc,
        Abs(aTipDoc),
        lIndexLocal + 1,
        aCodPart
      );
      COMMIT;
    END IF;
    IF aTipDoc IN (18, 19, 26, 35) THEN
      delete FROM CampaniiVenit WHERE CodDoc = aCodDoc AND TipDoc = aTipDoc;
      SELECT NVL(MAX(IndexLocal), 0) INTO lIndexLocal FROM CampaniiVenit WHERE CodCampanie = aCodCampanie;
      INSERT INTO CampaniiVenit (
        CodCampanieVenit,
        CodCampanie,
        CodDoc,
        TipDoc,
        IndexLocal,
        CodPart
      ) VALUES (
        Seq_CampaniiVenit_CodCV.NextVal,
        aCodCampanie,
        aCodDoc,
        aTipDoc,
        lIndexLocal + 1,
        aCodPart
      );
      COMMIT;
    END IF;
  end if;
END;

procedure StergeDocMarketing(aCodCampanie in number, aCodDoc in number, aTipDoc in number) is
  lCount number(20) := 0;
  PRAGMA AUTONOMOUS_TRANSACTION;
begin
  if aTipDoc in (1, 2, 3, 4, 5, 6, 7, 24, 29, 30, 31, 33, -35) then
    SELECT COUNT(*) INTO lCount
    FROM CampaniiCost
    WHERE
      CodCampanie = aCodCampanie AND
      CodDoc = aCodDoc AND
      TipDoc = Abs(aTipDoc);
    if lCount = 1 then
      DELETE FROM
        CampaniiCost
      WHERE
        CodCampanie = aCodCampanie AND
        CodDoc = aCodDoc AND
        TipDoc = Abs(aTipDoc);
      COMMIT;
    end if;
  end if;
  if aTipDoc IN (18, 19, 26, 35) then
    SELECT COUNT(*) INTO lCount
    FROM CampaniiVenit
    WHERE
      CodCampanie = aCodCampanie AND
      CodDoc = aCodDoc AND
      TipDoc = aTipDoc;
    if lCount = 1 then
      DELETE FROM
        CampaniiVenit
      WHERE
        CodCampanie = aCodCampanie AND
        CodDoc = aCodDoc AND
        TipDoc = aTipDoc;
      COMMIT;
    end if;
  end if;
end;

end PKG_CAMPANII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CANAMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>190EB3D1AD8B2C6D33846A3C857ED30A27FA71F3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CANAMED IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodCanamed INTO Tmp FROM CANAMED WHERE CodCanamed = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CANAMED1 WHERE CodCanamed = RecId ;
  DELETE FROM CANAMED  WHERE CodCanamed = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CANAMED FIELDS( CodCanamed ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
tmp number(20,7);
BEGIN
  INSERT INTO  TMP_CANAMED ( CodCanamed, DataLista, Obs )
    ( SELECT CodCanamed, DataLista, Obs
      FROM CANAMED WHERE CodCanamed = RecId ) ;

  INSERT INTO TMP_CANAMED1
  (CODCANAMED1,
   CODCANAMED, 
   CODCNPM,   
   CODCIM,    
   DENPRODUS, 
   FORMA,      
   CONCENTR,   
   FIRMA,      
   DCI,        
   AMBALAJ,
   GRUPA,      
   PRETPROD,
   PRETRID,   
   PRETAM,    
   STATUTFRM,
   STATUTANM
   )
   SELECT  
   CODCANAMED1,
   CODCANAMED, 
   CODCNPM,   
   CODCIM,    
   DENPRODUS, 
   FORMA,      
   CONCENTR,   
   FIRMA,      
   DCI,        
   AMBALAJ,
   GRUPA,      
   PRETPROD,
   PRETRID,   
   PRETAM,    
   STATUTFRM,
   STATUTANM
   FROM CANAMED1 WHERE CODCANAMED = RecId;
   
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodCanamed INTO RecId FROM TMP_CANAMED;
    UPDATE CANAMED SET ( DataLista, Obs )
       = ( SELECT DataLista, Obs
          FROM TMP_CANAMED )
      WHERE CodCanamed = RecId ;

    DELETE FROM CANAMED1 C1 where C1.CodCanamed = RecId and not exists (Select TMP.CodCanamed1 from TMP_CANAMED1 TMP WHERE TMP.CodCanamed1 = C1.CodCanamed1 );

    INSERT INTO CANAMED1 ( 
      CODCANAMED1,
      CODCANAMED, 
      CODCNPM,   
      CODCIM,    
      DENPRODUS, 
      FORMA,      
      CONCENTR,   
      FIRMA,      
      DCI,        
      AMBALAJ,
      GRUPA,      
      PRETPROD,
      PRETRID,   
      PRETAM,    
      STATUTFRM,
      STATUTANM )
    SELECT  
      SEQ_CANAMED1_CODCANAMED1.Nextval, 
      RecId,
      CODCNPM,   
      CODCIM,    
      DENPRODUS, 
      FORMA,      
      CONCENTR,   
      FIRMA,      
      DCI,        
      AMBALAJ,
      GRUPA,      
      PRETPROD,
      PRETRID,   
      PRETAM,    
      STATUTFRM,
      STATUTANM
    FROM TMP_CANAMED1 WHERE CodCanamed1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_CANAMED1 WHERE NVL(CodCanamed1,-1) &gt; 0 ORDER BY CodCanamed1 ) LOOP
       UPDATE CANAMED1
       SET
        CODCNPM   = v_Rec.CodCnpm,   
        CODCIM    = v_Rec.CODCIM,    
        DENPRODUS = v_Rec.DENPRODUS, 
        FORMA      = v_Rec.FORMA,      
        CONCENTR   = v_Rec.CONCENTR,   
        FIRMA      = v_Rec.FIRMA,      
        DCI        = v_Rec.DCI,        
        AMBALAJ    = v_Rec.AMBALAJ,
        GRUPA      = v_Rec.GRUPA,      
        PRETPROD  = v_Rec.PRETPROD,
        PRETRID   = v_Rec.PRETRID,   
        PRETAM    = v_Rec.PRETAM,    
        STATUTFRM = v_Rec.STATUTFRM,
        STATUTANM = v_Rec.STATUTANM
       WHERE CodCanamed1  = v_rec.CodCanamed1;
    END LOOP;
  ELSE 

  SELECT seq_canamed_codcanamed.NextVal INTO RecId FROM DUAL;
  INSERT INTO CANAMED ( CodCanamed, DataLista, Obs )
 ( SELECT  RecId, DataLista, Obs
     FROM TMP_CANAMED  ) ;

  INSERT INTO CANAMED1 ( 
      CODCANAMED1,
      CODCANAMED, 
      CODCNPM,   
      CODCIM,    
      DENPRODUS, 
      FORMA,      
      CONCENTR,   
      FIRMA,      
      DCI,        
      AMBALAJ,
      GRUPA,      
      PRETPROD,
      PRETRID,   
      PRETAM,    
      STATUTFRM,
      STATUTANM )
    SELECT  
      SEQ_CANAMED1_CODCANAMED1.Nextval, 
      RecId,
      CODCNPM,   
      CODCIM,    
      DENPRODUS, 
      FORMA,      
      CONCENTR,   
      FIRMA,      
      DCI,        
      AMBALAJ,
      GRUPA,      
      PRETPROD,
      PRETRID,   
      PRETAM,    
      STATUTFRM,
      STATUTANM
    FROM TMP_CANAMED1;

END IF;
  NotifyModif(Operation, RecId, &apos;CANAMED&apos;);
  COMMIT;
END;

end pkg_canamed; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA550C6859C8B4B25FBA021E817273E4667871FA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CANTAR IS

--CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_XX&apos;;
vSaveCantar number(5);

procedure CheckNewData
is
begin
  FOR V_REC in (SELECT T.*, C.CODCANTAR AS PRELUAT FROM TMP_CANTAR T LEFT JOIN CANTAR C ON T.ID_CANTARIRE = c.Id_Cantarire)
  LOOP
    IF V_rec.PRELUAT IS NULL THEN
      INSERT INTO CANTAR(CODCANTAR, 
                         CODOBIECT, 
                         FURNIZOR,
                         CLIENT,
                         ID_CANTARIRE,
                         TOTAL_KG,
                         TARA_KG,
                         NET_KG,
                         AN,
                         LUNA,
                         SUBUNITATEA,
                         DATACREARE,
                         ANULAT,
                         INDEXCANTAR,
                         USERID,
                         RETUR,
                         DESTINATIE,
                         TRANSPORTATOR,
                         NRVEHICOL,
                         NRREMORCA,
                         CANTDOC,
                         NRAVIZ,
                         SERIEAVIZ
                        )
                  VALUES(SEQ_CANTAR_CODCANTAR.NEXTVAL,
                         V_REC.CODOBIECT, 
                         V_REC.FURNIZOR,
                         V_REC.CLIENT,
                         V_REC.ID_CANTARIRE,
                         V_REC.TOTAL_KG,
                         V_REC.TARA_KG,
                         V_REC.NET_KG,
                         V_REC.AN,
                         V_REC.LUNA,
                         V_REC.SUBUNITATEA,
                         V_REC.DATACREARE,
                         V_REC.ANULAT,
                         V_REC.INDEXCANTAR,
                         V_REC.USERID,
                         V_REC.RETUR,
                         V_REC.DESTINATIE,
                         V_REC.TRANSPORTATOR,
                         V_REC.NRVEHICOL,
                         V_REC.NRREMORCA,
                         V_REC.CANTDOC,
                         V_REC.NRAVIZ,
                         V_REC.SERIEAVIZ
                        );
      
    END IF;  
  END LOOP;    
  COMMIT;
end;    



 PROCEDURE REFA_BLOCAJE_INITIALE
 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   FOR V_REC IN (SELECT * FROM TMP_DIN_CANTARIRI WHERE CODCANTAR IS NOT NULL)
   LOOP
     UPDATE CANTAR
     SET
       TIPDOC  = V_REC.TIPDOC,
       CODDOC1 = V_REC.CODDOC1
     WHERE
       CODCANTAR = V_REC.CODCANTAR;
   END LOOP;

   FOR V_REC IN (SELECT * FROM TMP_DIN_CANTARIRI WHERE CODBCAR  IS NOT NULL)
   LOOP
     UPDATE BCAR
     SET
       TIPDOC  = V_REC.TIPDOC,
       CODDOC1 = V_REC.CODDOC1
     WHERE
       CODBCAR = V_REC.CODBCAR;
   END LOOP;
   COMMIT;
 END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp          NUMBER(20);
  TMP_UserID   NUMBER(20);
  TMP_UserNAME VARCHAR2(30);
  CANTARIRE_BLOCATA EXCEPTION;
  PRAGMA EXCEPTION_INIT(CANTARIRE_BLOCATA, -20998);
BEGIN
  SELECT NVL(UserIDBlocaj, 0) INTO TMP_UserID FROM CANTAR WHERE CodCantar = RecID;
  IF TMP_UserID = PKG_GLOBALS.USERID OR TMP_UserID = 0 THEN
    SELECT CodCantar INTO TMP FROM CANTAR WHERE CodCantar = RecId FOR UPDATE NOWAIT;
  ELSE
    RAISE CANTARIRE_BLOCATA;
  END IF;
EXCEPTION
  WHEN CANTARIRE_BLOCATA THEN
    BEGIN
      SELECT NVL(UserName, &apos;.NEDEFINIT.&apos;) INTO TMP_UserNAME FROM TMP_Utilizator WHERE NVL(CodUtilizator, 0) = TMP_UserID;
    EXCEPTION
      WHEN OTHERS THEN TMP_UserNAME := &apos;.NEDEFINIT.&apos;;
    END;
    RAISE_APPLICATION_ERROR(-20998, &apos;Cantarirea selectata este blocata de utilizatorul &apos; || TMP_UserNAME || &apos; (ID=&apos; || TO_CHAR(TMP_UserID) || &apos;) !&apos;);
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_CANTAR FIELDS( CodCantar ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  oldCARNETDOC  NUMBER(20) := 0;
  oldNRDOC      NUMBER(20) := 0;
BEGIN
  SP_LOCKRECORD(RecId);
  SELECT Nvl(CARNETDOC,0), NRAVIZ INTO oldCARNETDOC, oldNRDOC FROM CANTAR WHERE  CodCantar = RecId;
  IF (oldCARNETDOC &lt;&gt; 0) AND (oldNRDOC &lt;&gt; 0) THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(oldCARNETDOC, oldNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(oldCARNETDOC);
  END IF;
  UPDATE CANTAR SET ANULAT = 1, CARNETDOC = 0 WHERE CodCantar = RecId;
  NotifyModif(2, RecId, &apos;CANTAR&apos;);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_CANTAR (
    CODCANTAR, CODOBIECT, TIPDOC, CODDOC1, TOTAL_KG, TARA_KG, NET_KG,
    AMB1_COD, AMB1_KG, AMB1_CANT, AMB1_RETURNABIL, AMB2_COD, AMB2_KG, AMB2_CANT, AMB2_RETURNABIL,
    AMB3_COD, AMB3_KG, AMB3_CANT, AMB3_RETURNABIL, AMB4_COD, AMB4_KG, AMB4_CANT, AMB4_RETURNABIL,
    PALET_KG, TRANSP1_COD, TRANSP1_KG, TRANSP1_CANT, TRANSP2_COD, TRANSP2_KG, TRANSP2_CANT,
    AN, LUNA, SUBUNITATEA, DATACREARE, ANULAT, INDEXCANTAR, RETUR, LOT, SERIE, IDCANTAR,
    DENOBIECT, AMB1_DEN, AMB2_DEN, AMB3_DEN, AMB4_DEN, TRANSP1_DEN, TRANSP2_DEN,
    FURNIZOR, NRAVIZ, DESTINATIE, CLIENT, GESTIUNE, SUBUNITATE,
    CARNETDOC, SERIADOC, ARECARNETDOC, CodCmd1, SerieTxt,
    AMB5_COD, AMB5_KG, AMB5_CANT, AMB5_RETURNABIL, AMB6_COD, AMB6_KG, AMB6_CANT, AMB6_RETURNABIL, ID_CANTARIRE)
  SELECT
    C.CODCANTAR, C.CODOBIECT, C.TIPDOC, C.CODDOC1, C.TOTAL_KG, C.TARA_KG, C.NET_KG,
    C.AMB1_COD, C.AMB1_KG, C.AMB1_CANT, C.AMB1_RETURNABIL, C.AMB2_COD, C.AMB2_KG, C.AMB2_CANT, C.AMB2_RETURNABIL,
    C.AMB3_COD, C.AMB3_KG, C.AMB3_CANT, C.AMB3_RETURNABIL, C.AMB4_COD, C.AMB4_KG, C.AMB4_CANT, C.AMB4_RETURNABIL,
    C.PALET_KG, C.TRANSP1_COD, C.TRANSP1_KG, C.TRANSP1_CANT, C.TRANSP2_COD, C.TRANSP2_KG, C.TRANSP2_CANT,
    C.AN, C.LUNA, C.SUBUNITATEA, C.DATACREARE, C.ANULAT, C.INDEXCANTAR, C.RETUR, S.SERIE LOT, C.SERIE, C.IDCANTAR,
    O.DENUMIRE, A1.DENUMIRE, A2.DENUMIRE, A3.DENUMIRE, A4.DENUMIRE, T1.DENUMIRE, T2.DENUMIRE,
    C.FURNIZOR, C.NRAVIZ, C.DESTINATIE, C.CLIENT, C.GESTIUNE, C.SUBUNITATE,
    C.CARNETDOC, C.SERIADOC, Decode(C.CARNETDOC,NULL,0,0,0,1), C.CodCmd1, S.Serie SerieTxt,
    C.AMB5_COD, C.AMB5_KG, C.AMB5_CANT, C.AMB5_RETURNABIL, C.AMB6_COD, C.AMB6_KG, C.AMB6_CANT, C.AMB6_RETURNABIL, ID_CANTARIRE
  FROM CANTAR C
    LEFT JOIN NARTOBJ O  ON O.CODOBIECT  = C.CODOBIECT
    LEFT JOIN NARTOBJ A1 ON A1.CODOBIECT = C.AMB1_COD
    LEFT JOIN NARTOBJ A2 ON A2.CODOBIECT = C.AMB2_COD
    LEFT JOIN NARTOBJ A3 ON A3.CODOBIECT = C.AMB3_COD
    LEFT JOIN NARTOBJ A4 ON A4.CODOBIECT = C.AMB4_COD
    LEFT JOIN NARTOBJ A5 ON A5.CODOBIECT = C.AMB5_COD
    LEFT JOIN NARTOBJ A6 ON A6.CODOBIECT = C.AMB6_COD
    LEFT JOIN NARTOBJ T1 ON T1.CODOBIECT = C.TRANSP1_COD
    LEFT JOIN NARTOBJ T2 ON T2.CODOBIECT = C.TRANSP2_COD
    LEFT JOIN NSERII  S  ON S.CODSERIE = C.SERIE
  WHERE CodCantar = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  lCodSerieNew  NUMBER(20);
  lCoSerieOld   NUMBER(20);
  lLotNew       VARCHAR2(30);
  lCodObiect    NUMBER(20);
  lCount        NUMBER(20);
  aCARNETDOC    NUMBER(20);
  aNRDOC        NUMBER(20);
  oldCARNETDOC  NUMBER(20) := 0;
  oldNRDOC      NUMBER(20) := 0;

BEGIN
  --DELETE TMP_MANEVRA_LISTE WHERE FILTRU = &apos;ONORCOM&apos; AND FILTRU1 = &apos;CODCANTAR&apos;;
  SELECT Nvl(CARNETDOC,0), NRAVIZ INTO aCARNETDOC, aNRDOC FROM TMP_CANTAR;
  
  SELECT LOT INTO lLotNew FROM TMP_CANTAR;
  SELECT coalesce(SERIE,0) INTO lCodSerieNew FROM TMP_CANTAR;
  SELECT CODOBIECT INTO lCodObiect FROM TMP_CANTAR;
  IF lLotNew IS NOT NULL THEN
    SELECT COUNT(*) INTO lCount FROM NSERII WHERE SERIE = lLotNew AND CodObiect = lCodObiect;
    IF lCount &lt;= 0 THEN
      SELECT SEQ_NSERII_CODSERIE.NextVal INTO lCodSerieNew FROM DUAL;
      INSERT INTO NSERII (CodSerie, Serie, CodObiect)
      VALUES (lCodSerieNew, lLotNew, lCodObiect);
    ELSE
      SELECT Max(CodSerie) INTO lCodSerieNew FROM NSERII WHERE SERIE = lLotNew AND CodObiect = lCodObiect;
    END IF;
  END IF;

  IF Operation = 0 THEN  -- UPDATE

    SELECT CodCantar INTO RecId FROM TMP_CANTAR;
    SELECT Nvl(CARNETDOC,0), NRAVIZ INTO oldCARNETDOC, oldNRDOC FROM CANTAR WHERE  CodCantar = RecId;
    IF (oldCARNETDOC &lt;&gt; aCARNETDOC) OR ((oldCARNETDOC &lt;&gt; 0) AND (oldNRDOC &lt;&gt; aNRDOC)) THEN
      PKG_CARNETEDOC.RELEASENUMARDOC(oldCARNETDOC, oldNRDOC);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(oldCARNETDOC);
    END IF;

    UPDATE CANTAR
    SET (   CODCANTAR, CODOBIECT, TIPDOC, CODDOC1,
            TOTAL_KG, TARA_KG, NET_KG,
            AMB1_COD, AMB1_KG, AMB1_CANT, AMB1_RETURNABIL,
            AMB2_COD, AMB2_KG, AMB2_CANT, AMB2_RETURNABIL,
            AMB3_COD, AMB3_KG, AMB3_CANT, AMB3_RETURNABIL,
            AMB4_COD, AMB4_KG, AMB4_CANT, AMB4_RETURNABIL,
            PALET_KG,
            TRANSP1_COD, TRANSP1_KG, TRANSP1_CANT,
            TRANSP2_COD, TRANSP2_KG, TRANSP2_CANT,
            USERIDBLOCAJ, ANULAT, INDEXCANTAR, RETUR, SERIE, IDCANTAR,
            FURNIZOR, NRAVIZ, Destinatie, Client, Gestiune, Subunitate,
            CARNETDOC, SERIADOC, CodCmd1,
            AMB5_COD, AMB5_KG, AMB5_CANT, AMB5_RETURNABIL,
            AMB6_COD, AMB6_KG, AMB6_CANT, AMB6_RETURNABIL, ID_CANTARIRE)
       =( SELECT
            CODCANTAR, CODOBIECT, TIPDOC, CODDOC1,
            Nvl(TOTAL_KG,0), Nvl(TARA_KG,0), Nvl(NET_KG,0),
            Nvl(AMB1_COD,0), Nvl(AMB1_KG,0), Nvl(AMB1_CANT,0), Nvl(AMB1_RETURNABIL,0),
            Nvl(AMB2_COD,0), Nvl(AMB2_KG,0), Nvl(AMB2_CANT,0), Nvl(AMB2_RETURNABIL,0),
            Nvl(AMB3_COD,0), Nvl(AMB3_KG,0), Nvl(AMB3_CANT,0), Nvl(AMB3_RETURNABIL,0),
            Nvl(AMB4_COD,0), Nvl(AMB4_KG,0), Nvl(AMB4_CANT,0), Nvl(AMB4_RETURNABIL,0),
            Nvl(PALET_KG,0),
            Nvl(TRANSP1_COD,0), Nvl(TRANSP1_KG,0), Nvl(TRANSP1_CANT,0),
            Nvl(TRANSP2_COD,0), Nvl(TRANSP2_KG,0), Nvl(TRANSP2_CANT,0),
            USERIDBLOCAJ, ANULAT, INDEXCANTAR, RETUR, lCodSerieNew, IDCANTAR,
            FURNIZOR, NRAVIZ, Destinatie, Client, Gestiune, Subunitate,
            CARNETDOC, SERIADOC, CodCmd1,
            Nvl(AMB5_COD,0), Nvl(AMB5_KG,0), Nvl(AMB5_CANT,0), Nvl(AMB5_RETURNABIL,0),
            Nvl(AMB6_COD,0), Nvl(AMB6_KG,0), Nvl(AMB6_CANT,0), Nvl(AMB6_RETURNABIL,0),
            ID_CANTARIRE
          FROM TMP_CANTAR)
    WHERE CodCantar = RecId;

  ELSE -- INSERT
    SELECT seq_CANTAR_CodCantar.NextVal INTO RecId FROM DUAL;

    INSERT INTO CANTAR (
      CODCANTAR, CODOBIECT, TIPDOC, CODDOC1,
      TOTAL_KG, TARA_KG, NET_KG,
      AMB1_COD, AMB1_KG, AMB1_CANT, AMB1_RETURNABIL,
      AMB2_COD, AMB2_KG, AMB2_CANT, AMB2_RETURNABIL,
      AMB3_COD, AMB3_KG, AMB3_CANT, AMB3_RETURNABIL,
      AMB4_COD, AMB4_KG, AMB4_CANT, AMB4_RETURNABIL,
      PALET_KG,
      TRANSP1_COD, TRANSP1_KG, TRANSP1_CANT,
      TRANSP2_COD, TRANSP2_KG, TRANSP2_CANT,
      AN, LUNA, SUBUNITATEA, USERID, DATACREARE, USERIDBLOCAJ, ANULAT, INDEXCANTAR, RETUR, SERIE, IDCANTAR,
      FURNIZOR, NRAVIZ, Destinatie, Client, Gestiune, Subunitate, CodCmd1,
      AMB5_COD, AMB5_KG, AMB5_CANT, AMB5_RETURNABIL,
      AMB6_COD, AMB6_KG, AMB6_CANT, AMB6_RETURNABIL, ID_CANTARIRE)
    SELECT
      RecId, CODOBIECT, TIPDOC, CODDOC1,
      Nvl(TOTAL_KG,0), Nvl(TARA_KG,0), Nvl(NET_KG,0),
      Nvl(AMB1_COD,0), Nvl(AMB1_KG,0), Nvl(AMB1_CANT,0), Nvl(AMB1_RETURNABIL,0),
      Nvl(AMB2_COD,0), Nvl(AMB2_KG,0), Nvl(AMB2_CANT,0), Nvl(AMB2_RETURNABIL,0),
      Nvl(AMB3_COD,0), Nvl(AMB3_KG,0), Nvl(AMB3_CANT,0), Nvl(AMB3_RETURNABIL,0),
      Nvl(AMB4_COD,0), Nvl(AMB4_KG,0), Nvl(AMB4_CANT,0), Nvl(AMB4_RETURNABIL,0),
      Nvl(PALET_KG,0),
      Nvl(TRANSP1_COD,0), Nvl(TRANSP1_KG,0), Nvl(TRANSP1_CANT,0),
      Nvl(TRANSP2_COD,0), Nvl(TRANSP2_KG,0), Nvl(TRANSP2_CANT,0),
      AN, LUNA, SUBUNITATEA, PKG_GLOBALS.USERID, SYSTIMESTAMP, USERIDBLOCAJ, ANULAT, INDEXCANTAR, RETUR, lCodSerieNew, IDCANTAR,
      FURNIZOR, NRAVIZ, Destinatie, Client, Gestiune, Subunitate, CodCmd1,
      Nvl(AMB5_COD,0), Nvl(AMB5_KG,0), Nvl(AMB5_CANT,0), Nvl(AMB5_RETURNABIL,0),
      Nvl(AMB6_COD,0), Nvl(AMB6_KG,0), Nvl(AMB6_CANT,0), Nvl(AMB6_RETURNABIL,0),
      ID_CANTARIRE
    FROM TMP_CANTAR;
    if vSaveCantar &gt; 0 then
      INSERT INTO TMP_MANEVRA_LISTE(FILTRU, FILTRU1, VALOARE1)
      VALUES (&apos;ONORCOM&apos;, &apos;CODCANTAR&apos;, TO_CHAR(RECID));
    end if;  
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;

  NotifyModif(Operation, RecId, &apos;CANTAR&apos;);
  COMMIT;
END;

PROCEDURE UPDATE_RECORDS(pTIPDOC IN NUMBER, pTMP_CODDOC1 IN NUMBER , pCODDOC1 IN NUMBER) IS
BEGIN
  UPDATE CANTAR
  SET CODDOC1 = pCODDOC1,
      USERIDBLOCAJ = null
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND TIPDOC = pTipDoc
    AND CODDOC1 = pTMP_CODDOC1;
END;

PROCEDURE LOCK_RECORD(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER) IS
BEGIN
  UPDATE
    CANTAR
  SET
    USERIDBLOCAJ = PKG_GLOBALS.USERID
  WHERE
    TIPDOC = pTipDoc AND CODDOC1 = pCODDOC1;
END;

PROCEDURE UNLOCK_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER) IS
BEGIN
  UPDATE CANTAR
  SET USERIDBLOCAJ = null
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND TIPDOC = pTipDoc
    AND CODDOC1 = pCODDOC1;
END;

PROCEDURE ANULEAZA_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER DEFAULT 0) IS
BEGIN
  IF NVL(pCODDOC1,0) = 0 THEN
    UPDATE CANTAR
    SET ANULAT = 1,
        CODDOC1 = NULL,
        USERIDBLOCAJ = NULL
    WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
      AND TIPDOC = pTipDoc
      AND CODDOC1 &lt; NVL(pCODDOC1,0);
  ELSE
    UPDATE CANTAR
    SET ANULAT = 1,
        CODDOC1 = NULL,
        USERIDBLOCAJ = NULL
    WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
      AND TIPDOC = pTipDoc
      AND CODDOC1 = NVL(pCODDOC1,0);
  END IF;
END;

PROCEDURE X_ELIBEREAZA_RECORDS(pTIPDOC IN NUMBER, pCODDOC1 IN NUMBER DEFAULT 0, pID_CANTARIRE IN VARCHAR2) IS
BEGIN
  IF NVL(pCODDOC1,0) = 0 THEN
    UPDATE CANTAR
    SET CODDOC1 = NULL,
        USERIDBLOCAJ = NULL
    WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
      AND TIPDOC = pTipDoc
      AND CODDOC1 &lt; NVL(pCODDOC1,0)
      AND ID_CANTARIRE = pID_CANTARIRE;
  ELSE
    UPDATE CANTAR
    SET USERIDBLOCAJ = NULL,
        CODDOC1 = NULL
    WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
      AND TIPDOC = pTipDoc
      AND CODDOC1 = NVL(pCODDOC1,0)
      AND (ID_CANTARIRE IS NULL OR ID_CANTARIRE = pID_CANTARIRE);
  END IF;
END;

PROCEDURE ANULEAZA_UNA(pCOD IN NUMBER) IS
BEGIN
   UPDATE CANTAR SET ANULAT = 1, USERIDBLOCAJ = null  WHERE CODCANTAR = pCOD;
END;

FUNCTION CANTARIT_AZI(aCodObiect IN NUMBER, aSubunitate in number, aDestinatie in number, aCodDest in number) RETURN NUMBER IS
  lCant NUMBER(20,7) := 0.0;

BEGIN
  SELECT SUM(Decode(Retur, 1, -1, 1) * Net_Kg) INTO lCant
  FROM (
          select Net_Kg,
                 Retur,
                 Case
                   when aDestinatie = 1 then Furnizor
                   when aDestinatie = 2 then Client
                   when aDestinatie = 3 or aDestinatie = 5 then Gestiune
                   when aDestinatie = 4 or aDestinatie = 6 then Subunitate
                 end CodDest
          FROM Cantar
          WHERE CodObiect = aCodObiect
            AND Destinatie = aDestinatie
            AND Subunitatea = aSubunitate
            AND Nvl(Anulat, 0) = 0
            AND Trunc(DataCreare) = Trunc(Sysdate)
       )
  where CodDest = aCodDest;

  RETURN lCant;
END;

FUNCTION CMDINT_AZI(aCodObiect IN NUMBER, aCodGest in number) RETURN NUMBER IS
  lCant NUMBER(20,7) := 0.0;
BEGIN
  SELECT SUM(Nvl(O.Masa, 0) * C1.CantAcceptat) INTO lCant
  FROM Comanda C
    INNER JOIN Comanda1 C1 ON C1.CodComanda = C.CodComanda
    INNER JOIN Nartobj O ON O.Codobiect = C1.CodObiect
  WHERE C.Anulat = 0 AND C.Operat = 1 AND C.TipDoc = 53 and C.Codgest = aCodGest
    AND C1.CodObiect = aCodObiect
    AND C.Subunitatea = PKG_GLOBALS.Subunitate
    AND Trunc(DataDoc) = Trunc(Sysdate);
  RETURN lCant;
END;


PROCEDURE CANTARIRI_PE_LOT(aData IN VARCHAR2, aDestinatie in number, aCodDest in number, aTipDoc IN NUMBER, aSUBUNITATE IN NUMBER, aCodObiect IN NUMBER DEFAULT 0) IS
  PRAGMA AUTONOMOUS_TRANSACTION;

IntrFCantCantarNIR varchar2(1);
BEGIN
  -- deblocheaza inregistrari ramase agatate
 /*  !!!!!!!!!!!
  UPDATE
    CANTAR
  SET
    UserIDBlocaj = NULL
  WHERE
    NVL(UserIDBlocaj, 0) = PKG_GLOBALS.UserID;
*/

 IntrFCantCantarNIR := &apos;0&apos;;
 BEGIN
   SELECT PKG_CATEGCONST.GetValConstanta(&apos;IntrFCantCantarNIR&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO IntrFCantCantarNIR FROM DUAL;
   EXCEPTION WHEN OTHERS THEN IntrFCantCantarNIR := &apos;0&apos;;
 END;




  -- blocheaza inregistrarile pentru preluare
  IF ADESTINATIE &lt;&gt; 7 THEN
  for v_rec in
  (
      SELECT CodCantar from
          (
          select CodCantar,
                 Case
                   when aDestinatie = 1 then Furnizor
                   when aDestinatie = 2 then Client
                   when aDestinatie = 3 or aDestinatie = 5 then Gestiune
                   when aDestinatie = 4 or aDestinatie = 6 then Subunitate
                   when aDestinatie = 7 then 0  
                 end CodDest,
                 codobiect
          FROM Cantar
          WHERE Destinatie  = aDestinatie
            AND NVL(CODDOC1, 0) = 0
            AND NVL(Anulat,  0) = 0
            AND NVL(UserIDBlocaj, 0) = 0
            AND ( Trunc(DataCreare) = to_date(aData,&apos;dd.mm.yyyy&apos;) 
                  or (aDestinatie = 1 and IntrFCantCantarNIR = &apos;1&apos;)
                )  
            AND NVL(Subunitatea, 1) = aSubunitate
          )
      where CodDest = aCodDest or (ACODOBIECT &gt; 0 and ACODOBIECT = CodObiect)
   )
  loop
    UPDATE CANTAR
    SET    UserIDBlocaj = PKG_GLOBALS.UserID,
           TipDoc       = aTipDoc
    WHERE CodCantar = v_rec.CodCantar;
  end loop;
  ELSE
    IF ACODDEST &gt; 0 THEN
      for v_rec in
      (
          SELECT CodCantar from
              (
              select CodCantar,
                     Gestiune CodDest,
                     codobiect
              FROM Cantar
              WHERE Destinatie  = aDestinatie 
                AND NVL(CODDOC1, 0) = 0
                AND NVL(Anulat,  0) = 0
                AND NVL(UserIDBlocaj, 0) = 0
                AND ( Trunc(DataCreare) = to_date(aData,&apos;dd.mm.yyyy&apos;) 
                    or 
                    (aDestinatie = 1 and IntrFCantCantarNIR = &apos;1&apos;)
                   )  
                AND NVL(Subunitatea, 1) = aSubunitate
              )
          where CodDest = aCodDest or (ACODOBIECT &gt; 0 and ACODOBIECT = CodObiect)
       )
      loop
        UPDATE CANTAR
        SET    UserIDBlocaj = PKG_GLOBALS.UserID,
               TipDoc       = aTipDoc
        WHERE CodCantar = v_rec.CodCantar;
      end loop;
    ELSE
      for v_rec in
      (
          SELECT CodCantar from
              (
              select CodCantar,
                     Gestiune CodDest
              FROM Cantar
              WHERE Destinatie  = aDestinatie 
                AND NVL(CODDOC1, 0) = 0
                AND NVL(Anulat,  0) = 0
                AND NVL(UserIDBlocaj, 0) = 0
                AND (Trunc(DataCreare) = to_date(aData,&apos;dd.mm.yyyy&apos;) 
                    or 
                    (aDestinatie = 1 and IntrFCantCantarNIR = &apos;1&apos;)
                   )  
                AND NVL(Subunitatea, 1) = aSubunitate AND
                (ACODOBIECT = 0 OR ACODOBIECT = CodObiect)
              )
       )
      loop
        UPDATE CANTAR
        SET    UserIDBlocaj = PKG_GLOBALS.UserID,
               TipDoc       = aTipDoc
        WHERE CodCantar = v_rec.CodCantar;
      end loop;
    END IF;  
  END IF;
  
  -- pregateste tabela temporara pentru preluare
  DELETE FROM TMP_CANTARIRI_PE_LOT;
  if acodobiect &gt; 0 then
    INSERT INTO TMP_CANTARIRI_PE_LOT
      (
        CodObiect,
        CodDoc1,
        DenObiect,
        Serie,
        NetKg,
        CodCmd1,
        ID_CANTARIRE,
        NRAVIZ,
        SERIEAVIZ,
        TRANSPORTATOR,
        NRVEHICOL,
        NRREMORCA
      )
      (
        SELECT
          CodObiect,
          0,
          DenObiect,
          Serie,
          NetKg,
          CodCmd1,
          ID_CANTARIRE,
          NRAVIZ,
          SERIEAVIZ,
          TRANSPORTATOR,
          NRVEHICOL,
          NRREMORCA
        FROM
        (
          SELECT
            C.CodObiect,
            A.Denumire AS DenObiect,
            NVL(C.Serie, 0) AS Serie,
            SUM(DECODE(C.Retur, 1, -1, 1) * C.Net_Kg) AS NetKg,
            C.CodCmd1,
            c.ID_CANTARIRE,
            c.NRAVIZ,
            c.SERIEAVIZ,
            c.TRANSPORTATOR,
            c.NRVEHICOL,
            c.NRREMORCA
          FROM
            CANTAR C
            INNER JOIN NARTOBJ A ON A.CodObiect = C.CodObiect
          WHERE
            NVL(C.UserIDBlocaj, 0) = PKG_GLOBALS.UserID
            AND NVL(CODDOC1, 0) = 0 -- !! ALTFEL LE ADUCE SI PE CELE VECHI
          GROUP BY
            C.CodObiect, A.Denumire, NVL(C.Serie, 0),
            C.CodCmd1,
            c.ID_CANTARIRE,
            c.NRAVIZ,
            c.SERIEAVIZ,
            c.TRANSPORTATOR,
            c.NRVEHICOL,
            c.NRREMORCA
        )
      );  
  else
    INSERT INTO TMP_CANTARIRI_PE_LOT
      (
        CodObiect,
        CodDoc1,
        DenObiect,
        Serie,
        NetKg,
        CodCmd1,
        ID_CANTARIRE,
        NRAVIZ,
        SERIEAVIZ,
        TRANSPORTATOR,
        NRVEHICOL,
        NRREMORCA
      )
      (
        SELECT
          CodObiect,
          0,
          DenObiect,
          Serie,
          NetKg,
          CodCmd1,
          ID_CANTARIRE,
          NRAVIZ,
          SERIEAVIZ,
          TRANSPORTATOR,
          NRVEHICOL,
          NRREMORCA
        FROM
        (
          SELECT
            C.CodObiect,
            A.Denumire AS DenObiect,
            NVL(C.Serie, 0) AS Serie,
            SUM(DECODE(C.Retur, 1, -1, 1) * C.Net_Kg) AS NetKg,
            C.CodCmd1,
            C.ID_CANTARIRE,
            C.NRAVIZ,
            C.SERIEAVIZ,
            C.TRANSPORTATOR,
            C.NRVEHICOL,
            C.NRREMORCA
          FROM
            CANTAR C
            INNER JOIN NARTOBJ A ON A.CodObiect = C.CodObiect
          WHERE
            NVL(C.UserIDBlocaj, 0) = PKG_GLOBALS.UserID
            AND NVL(CODDOC1, 0) = 0 -- !! ALTFEL LE ADUCE SI PE CELE VECHI
          GROUP BY
            C.CodObiect, A.Denumire, NVL(C.Serie, 0),
            C.CodCmd1,
            C.ID_CANTARIRE,
            C.NRAVIZ,
            C.SERIEAVIZ,
            C.TRANSPORTATOR,
            C.NRVEHICOL,
            C.NRREMORCA
        )
      );
  end if;
  DELETE FROM TMP_CANTARIRI_PE_LOT WHERE NetKg = 0;

  COMMIT;
END;

PROCEDURE UPDATE_CANTARIRI_PE_LOT(aCodDoc1 IN NUMBER, aCODOBIECT IN NUMBER, aSERIE IN NUMBER, pID_CANTARIRE IN VARCHAR2) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE CANTAR
      SET CodDoc1 = aCODDOC1
  WHERE
      NVL(UserIDBlocaj, 0) = PKG_GLOBALS.UserID
      AND CodObiect       = aCodObiect
      AND NVL(SERIE, 0) = aSERIE
      AND NVL(CODDOC1, 0) = 0 -- !! ALTFEL LE ADUCE SI MODIFICA SI PE CELE VECHI
      AND (ID_CANTARIRE IS NULL OR NVL(ID_CANTARIRE, &apos;&apos;) = pID_CANTARIRE);
  COMMIT;
END;

PROCEDURE ELIBEREAZA_ALL_USER_RECORDS IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE CANTAR
  SET CODDOC1 = NULL,
      USERIDBLOCAJ = NULL,
      TIPDOC = NULL
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID;
  COMMIT;
END;

PROCEDURE ELIBEREAZA_ON_SP_POSTRECORDS IS
BEGIN
  UPDATE CANTAR
  SET CODDOC1 = NULL,
      USERIDBLOCAJ = NULL,
      TIPDOC = NULL
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND NOT TIPDOC IN (18, 43, 44, 7);  --cantaririle asociate comenzilor in onorare comenzi trebuie sa se elbere la iesirea din macheta de onorare comenzi
END;

PROCEDURE ELIBEREAZA_NEW_USER_RECORDS IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE CANTAR
  SET CODDOC1 = NULL,
      USERIDBLOCAJ = NULL,
      TIPDOC = NULL
  WHERE
    USERIDBLOCAJ = PKG_GLOBALS.USERID
    AND CODDOC1 &lt; 0 ;
  COMMIT;
END;


PROCEDURE UNLOCK_ALL_USER_RECORDS IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE CANTAR
  SET USERIDBLOCAJ = NULL
  WHERE USERIDBLOCAJ = PKG_GLOBALS.USERID;
  COMMIT;
END;

PROCEDURE LOCK_RECORDS_TMPINTRARI1 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
pTIPDOC  NUMBER;
BEGIN
--   delete XYZ;
--   INSERT INTO XYZ(CODNIRSTOC) VALUES(-1);
   Select TipDoc into pTipDoc from TMP_INTRARI;
--   INSERT INTO XYZ(CODNIRSTOC) VALUES(pTipDoc);
   FOR V_REC IN (SELECT * FROM TMP_INTRARI1)
   LOOP
--   INSERT INTO XYZ(CODNIRSTOC) VALUES(V_REC.CODINTR1);
     UPDATE CANTAR SET USERIDBLOCAJ = PKG_GLOBALS.USERID
     WHERE TIPDOC = pTipDoc AND CODDOC1 = V_REC.CODINTR1;
   END LOOP;
  COMMIT;
END;

PROCEDURE LOCK_RECORDS_TMPIESIRI1 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
pTIPDOC  NUMBER;
BEGIN
  Select TipDoc into pTipDoc from TMP_IESIRI;
  FOR V_REC IN (SELECT * FROM TMP_IESIRI1)
  LOOP
    UPDATE CANTAR SET USERIDBLOCAJ = PKG_GLOBALS.USERID
    WHERE TIPDOC = pTipDoc AND CODDOC1 = V_REC.CODIES1;
  END LOOP;
  COMMIT;
END;

PROCEDURE LOCK_RECORDS_TMPTRANSF1 IS
  PRAGMA AUTONOMOUS_TRANSACTION;
pTIPDOC  NUMBER;
BEGIN
  Select TipDoc into pTipDoc from TMP_TRANSF;
  FOR V_REC IN (SELECT * FROM TMP_TRANSF1)
  LOOP
    UPDATE CANTAR SET USERIDBLOCAJ = PKG_GLOBALS.USERID
    WHERE TIPDOC = pTipDoc AND CODDOC1 = V_REC.CODTRANSF1;
  END LOOP;
  COMMIT;
END;

PROCEDURE SERVICE_UNLOCK_CANTAR IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE
    Cantar
  SET
    UserIdBlocaj = NULL,
    TipDoc = NULL,
    CodDoc1 = NULL
  WHERE
    NVL(CodDoc1, 0) &lt; 0;
  COMMIT;
END;

procedure LockNP(aCodCantar in number) is
begin
  update cantar set coddoc1 = -1, tipdoc = 7, UserIDBlocaj = pkg_globals.GETUSERID where codcantar = aCodCantar;
  commit;
end;  

procedure SetSalvare(aSaveCantar in number) is
begin
  vSaveCantar := aSaveCantar;
end;  

END PKG_CANTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CANTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51D285CC6400758D86BDABE0358909D9AFB2B9A9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CANTARE IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCANTAR INTO Tmp FROM CANTARE WHERE CODCANTAR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 DELETE FROM CANTARE WHERE CODCANTAR = RecId ;
  NotifyModif(2, RecId, &apos;CANTAR&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CANTARE FIELDS( CODCANTAR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_CANTARE(CODCANTAR, TIP, DENUMIRE, IP, DIREXPORT)
    ( SELECT CODCANTAR, TIP, DENUMIRE, IP, DIREXPORT
      FROM 
        CANTARE 
      WHERE 
       CODCANTAR = RecId 
    );

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CODCANTAR INTO RecId FROM TMP_CANTARE;

    UPDATE CANTARE
    SET
     (TIP, DENUMIRE, IP, DIREXPORT) = (SELECT TIP, DENUMIRE, IP, DIREXPORT FROM TMP_CANTARE)
    WHERE 
      CODCANTAR = RecId;

  ELSE  -- INSERT

    SELECT SEQ_CANTARE_CODCANTAR.NextVal INTO RecId FROM DUAL;
    INSERT INTO CANTARE (CODCANTAR, TIP, DENUMIRE, IP, DIREXPORT)
    SELECT RECID, TIP, DENUMIRE, IP, DIREXPORT FROM TMP_CANTARE;
  END IF;

  NotifyModif(Operation, RecId, &apos;CANTARE&apos;);
  COMMIT;

END;



end PKG_CANTARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CARDURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6853CB72A3CF3AAD9DB924CD5BDEAE1D5F91221E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CARDURI is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20); 
BEGIN 
  SELECT codcard INTO Tmp FROM carduri WHERE codcard = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN 
  SP_LOCKRECORD(RecId);
  DELETE FROM CARDURI WHERE CodCard = RecId;
  NotifyModif(2, RecId, &apos;CARDURI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN 
  INSERT INTO TMP_CARDURI(CodCard) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_CARDURI(CodCard, Simbol, Denumire, Obs) 
  SELECT CodCard, Simbol, Denumire, Obs
  FROM CARDURI WHERE CodCard = RecId; 
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE 
    SELECT CodCard INTO RecId FROM TMP_CARDURI;
    UPDATE CARDURI SET (Simbol, Denumire, Obs) 
       = ( SELECT Simbol, Denumire, Obs
          FROM TMP_CARDURI ) 
    WHERE CodCard = RecId; 
  ELSE  -- INSERT 
    SELECT seq_carduri_codcard.NextVal INTO RecId FROM DUAL; 
    INSERT INTO CARDURI(CodCard, Simbol, Denumire, Obs) 
    SELECT RecId, Simbol, Denumire, Obs
    FROM TMP_CARDURI; 
  END IF;
  NotifyModif(Operation, RecId, &apos;CARDURI&apos;);
  COMMIT;
END;

end PKG_CARDURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CARNETEDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84F0A12A5449E68BF17CC2746C256E53ECBACF3D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CARNETEDOC IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_8&apos;;

PROCEDURE SETCARNETTRANSF(ACODCARNET IN NUMBER) IS
BEGIN
  CARNETTRANSF := ACODCARNET;
END;

FUNCTION GETCARNETTRANSF RETURN NUMBER IS
BEGIN
  RETURN CARNETTRANSF;
END;

PROCEDURE SETCARNETLIVR(ACODCARNET IN NUMBER) IS
BEGIN
  CARNETLIVR := ACODCARNET;
END;

FUNCTION GETCARNETLIVR RETURN NUMBER IS
BEGIN
  RETURN CARNETLIVR;
END;

PROCEDURE SETMACHETACURENTA(MACHETA IN NUMBER)
IS
BEGIN
  MACHETACURENTA := MACHETA;
END;

FUNCTION GETMACHETACURENTA RETURN NUMBER
IS
BEGIN
  RETURN MACHETACURENTA;
END;

PROCEDURE PARCURGESIREFADOC(NUMETABLA VARCHAR2, CAMPCARNET VARCHAR2, CAMPNRDOC VARCHAR2)
IS
FILTRU VARCHAR2(100);
BEGIN
  FILTRU := &apos; AND COALESCE(D.INACTIV, 0) = 0 &apos;;
  EXECUTE IMMEDIATE
  &apos;BEGIN &apos;||
  &apos; FOR V_REC IN (SELECT T.* FROM &apos;|| NUMETABLA ||  &apos; T INNER JOIN DOCCARNETE D ON D.CODCARNET = T.&apos; || CAMPCARNET ||FILTRU||&apos; ORDER BY &apos; || CAMPCARNET || &apos;, &apos; || CAMPNRDOC || &apos; ) LOOP &apos;||
  &apos;    PKG_CARNETEDOC.SOLVENUMARDOC_EXT(V_REC.&apos; || CAMPCARNET || &apos;, V_REC.&apos; || CAMPNRDOC || &apos;);&apos;||
  &apos;  END LOOP; &apos;||
  &apos;END;&apos;;
END;

PROCEDURE UMPLE_TMP_NRDOC(NUMETABLA VARCHAR2, CAMPCARNET VARCHAR2, CAMPNRDOC VARCHAR2, ACODCARNET IN NUMBER, astartnr IN NUMBER, aendnr IN NUMBER) IS
  sSQL CLOB;
BEGIN
  IF  acodcarnet &gt; 0 THEN
    sSQL := &apos;INSERT INTO tmp_refacerecarnet_nrdoc (nrdoc) &apos;||chr(10)||
            &apos;SELECT T.&apos;||CAMPNRDOC||&apos; FROM &apos;||NUMETABLA||&apos; T &apos;||chr(10)||
            &apos;WHERE T.&apos;||CAMPCARNET||&apos; = &apos;||To_Char(aCodCarnet)||&apos; AND T.&apos;||CAMPNRDOC||&apos; BETWEEN &apos;||To_Char(aStartNr)||&apos; AND &apos;||To_Char(aEndNr);
    EXECUTE IMMEDIATE sSQL;
  END IF;
END;

PROCEDURE REFACERECARNET(aCodCarnet in number) IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_carnete&apos;;
  DELETE FROM DOCLOCK WHERE USERID IS NULL;

  IF  aCodCarnet &gt; 0
  THEN INSERT INTO tmp_refacerecarnet_carnete (codcarnet) SELECT codcarnet FROM DOCCARNETE WHERE CODCARNET = aCodCarnet;
  ELSE INSERT INTO tmp_refacerecarnet_carnete (codcarnet) SELECT codcarnet FROM DOCCARNETE WHERE COALESCE(INACTIV, 0) = 0;
  END IF;

  FOR vRec IN (
    SELECT DC.CodCarnet, DC.StartNr, DC.EndNR
    FROM DOCCARNETE DC INNER JOIN tmp_refacerecarnet_carnete tc ON TC.CodCarnet = DC.CodCarnet
  ) LOOP
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_nrdoc&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_intervale&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_freenr&apos;;

    INSERT INTO tmp_refacerecarnet_nrdoc(NrDoc) VALUES (vRec.StartNr - 1);
    -- PARCURG DOCUMENTE
    UMPLE_TMP_NRDOC(&apos;INTRARI&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;IESIRI&apos;      , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;IESIRIRETAIL&apos;, &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;LIVR&apos;        , &apos;CARNETLIVR&apos;  , &apos;NRLIVR&apos;  , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;NIR&apos;         , &apos;CARNETNIR&apos;   , &apos;NRNIR&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;COMPENS&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;TRANSF&apos;      , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;COMANDA&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;TREZOR&apos;      , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;TREZOR1&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;PACHETE&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;NC&apos;          , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;OFERTA&apos;      , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;IESIRI&apos;      , &apos;CARNETCERTIF&apos;, &apos;NRCERTIF&apos;, vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;LANSARE&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;BCAR&apos;        , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;RESTNP&apos;      , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;RAPORTP&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;CONTRACT&apos;    , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;NOTECREDIT&apos;  , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;NECESAR&apos;     , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;PLANIFPROD&apos;  , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;RECLAMATII&apos;  , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);
    UMPLE_TMP_NRDOC(&apos;FAZ&apos;         , &apos;CARNETDOC&apos;   , &apos;NRDOC&apos;   , vRec.CodCarnet, vRec.StartNr, vRec.EndNr);

    INSERT INTO tmp_refacerecarnet_intervale(IdGroup, NrMin, NrMax)
    SELECT idgroup, min(nrdoc) NrMin, max(nrdoc) NrMax
    FROM (SELECT nrdoc, nrdoc - Dense_rank() over (ORDER BY nrdoc) idgroup FROM tmp_refacerecarnet_nrdoc) ssub
    GROUP BY idgroup;

    INSERT INTO tmp_refacerecarnet_freenr (StartNr, EndNr, CodDocFree)
    SELECT b.StartNr, b.EndNr, c.CodDocFree
    FROM (
      SELECT StartNr, EndNr, ROW_NUMBER() OVER (ORDER BY StartNr) IdxLoc
      FROM (SELECT nrmax + 1 AS StartNr, COALESCE(LEAD(nrmin) OVER (ORDER BY idgroup) - 1, vRec.EndNr) AS EndNr FROM tmp_refacerecarnet_intervale ) a
      WHERE EndNr &gt;= StartNr
    ) b LEFT JOIN (
      SELECT coddocfree, ROW_NUMBER() OVER (ORDER BY coddocfree) IdxLoc FROM DOCFREE WHERE codcarnet = vRec.CodCarnet
    ) c ON c.IdxLoc = b.IdxLoc;

    UPDATE tmp_refacerecarnet_freenr
    SET CodDocFree = SEQ_DOCFREE_CODDOCFREE.NEXTVAL
    WHERE CodDocFree IS NULL;

    DELETE FROM DOCFREE WHERE CODCARNET = vRec.CodCarnet;
    INSERT INTO DOCFREE(CODDOCFREE, CODCARNET, STARTNR, ENDNR)
    SELECT CodDocFree, vRec.CodCarnet, StartNr, EndNr
    FROM tmp_refacerecarnet_freenr;

    UPDATE DOCCARNETE SET FREENR = (SELECT COALESCE(Sum(EndNr - StartNr + 1), 0) FROM tmp_refacerecarnet_freenr) WHERE CODCARNET = vRec.CodCarnet;
    COMMIT;
  END LOOP;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_carnete&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_nrdoc&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_intervale&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_refacerecarnet_freenr&apos;;
END;

PROCEDURE REFACERECARNETE IS
BEGIN
  FOR V_REC IN (SELECT * FROM DOCCARNETE WHERE INACTIV = 0)
  LOOP
    PKG_CARNETEDOC.REFACERECARNET(V_rec.Codcarnet);
  END LOOP;
END;

FUNCTION CANLOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER IS
  NR  NUMBER(10) := 0;
  Tmp NUMBER;
  PRAGMA AUTONOMOUS_TRANSACTION;
  Res  NUMBER(1);
BEGIN
  BEGIN
    SELECT CODCARNET INTO Tmp FROM DOCCARNETE WHERE CODCARNET = NVL(aCARNETDOC, 0) FOR UPDATE;
  EXCEPTION WHEN OTHERS THEN
    COMMIT;
    RETURN 0;
  END;

  UPDATE DOCCARNETE
  SET IN_UPDATE = 1
  WHERE CODCARNET = aCARNETDOC;

  SELECT COUNT(*) INTO NR FROM DOCLOCK
  WHERE
    CODCARNET  = aCARNETDOC
    AND USEDNO = TO_NUMBER(aNUMARDOC)
    AND (
          (USERID &lt;&gt; PKG_GLOBALS.USERID)OR
          (USERID = PKG_GLOBALS.USERID AND COALESCE(CONNINDEX, 0) &lt;&gt; PKG_GLOBALS.ConnectionIndex)
        );



  IF NR &gt; 0 THEN
    Res := 0;
  ELSE
    INSERT INTO DOCLOCK (CODDOCLOCK, CODCARNET, USEDNO, USERID, CONNINDEX)
    VALUES (SEQ_DOCLOCK_CODDOCLOCK.NEXTVAL, aCARNETDOC, TO_NUMBER(aNUMARDOC), PKG_GLOBALS.USERID, PKG_GLOBALS.CONNECTIONINDEX);

    Res := 1;

  END IF;

  UPDATE DOCCARNETE
  SET
    IN_UPDATE = 0
  WHERE
    CODCARNET = aCARNETDOC;
  COMMIT;
  RETURN Res;
END;

PROCEDURE LOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2)
IS
BEGIN
  INSERT INTO DOCLOCK (CODDOCLOCK, CODCARNET, USEDNO, USERID, CONNINDEX)
  VALUES (SEQ_DOCLOCK_CODDOCLOCK.NEXTVAL, aCARNETDOC, TO_NUMBER(aNUMARDOC), PKG_GLOBALS.USERID, PKG_GLOBALS.ConnectionIndex);
-- COMMIT-ul se face la nivel de tranzactie
END;

PROCEDURE UNLOCKNUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) IS
BEGIN
  DELETE FROM DOCLOCK
  WHERE CODCARNET = aCARNETDOC AND USEDNO = TO_NUMBER(aNUMARDOC) AND USERID = PKG_GLOBALS.USERID AND CONNINDEX = PKG_GLOBALS.CONNECTIONINDEX;
-- COMMIT-ul se face la nivel de tranzactie
END;

FUNCTION COUNTFREENR(aCODCARNET IN NUMBER) RETURN NUMBER
IS
NRFREE NUMBER(20) := 0;
BEGIN
  SELECT NVL(SUM(ENDNR - STARTNR + 1), 0) INTO NRFREE FROM DOCFREE WHERE CODCARNET = aCODCARNET;
  RETURN NRFREE;
END;

FUNCTION COUNTFREENRX RETURN NUMBER IS
  NRFREE NUMBER(20) := 0;
BEGIN
  SELECT NVL(SUM(ENDNR - STARTNR + 1), 0) INTO NRFREE FROM DOCFREEX;
  RETURN NRFREE;
END;

FUNCTION CARNETACTIV(aCODMACHETA IN NUMBER, aCODCARNET IN NUMBER) RETURN NUMBER IS
-- valideaza daca CARNETUL APARTINE MACHETEI SI DACA ESTE ACTIV
  FaraSalv NUMBER(1);
  NR NUMBER(10)  := 0;
  I  NUMBER (10) := 1;
BEGIN
-- VALIDEZ INTAI DACA CARNETUL TRECE TESTUL DE SUBUNITATE SI DEDICAT;
  SELECT COUNT(*) INTO NR
  FROM DOCCARNETE D
  WHERE CODCARNET = aCODCARNET
    AND NVL(SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
    AND ( (NVL(DEDICAT,0) = 0)
        OR
        (EXISTS (SELECT CODDOCUSERS FROM DOCUSERS WHERE CODUSER = PKG_GLOBALS.USERID AND  CODCARNET = D.CODCARNET ) )
      );

  IF NR = 0 THEN
    RETURN 0;
  END IF;

  BEGIN
    SELECT INACTIV INTO I FROM DOCCARNETE WHERE CODCARNET = aCODCARNET;
    EXCEPTION WHEN OTHERS THEN I := 1;
  END;

  IF I = 1 THEN
    RETURN 0;
  END IF;

  SELECT COUNT(*) INTO NR FROM DOCLINK WHERE CODCARNET = aCODCARNET AND CODMACHETA = aCODMACHETA;
  if NR &gt; 0 then
		Select Coalesce(FaraSalvare, 0) into FaraSalv FROM DOCCARNETE D WHERE CODCARNET = aCODCARNET;
		if FaraSalv = 1 then
			NR := -NR;
		end if;
	end if;
  RETURN NR;
END;


PROCEDURE UNLOCKDOCUMENTEMACHETA(aMACHETA IN NUMBER) IS
BEGIN
  DELETE FROM DOCLOCK
  WHERE CODCARNET IN (SELECT CODCARNET FROM DOCLINK WHERE CODMACHETA = aMACHETA)
    AND ((USERID = PKG_GLOBALS.USERID AND CONNINDEX = PKG_GLOBALS.CONNECTIONINDEX) OR USERID IS NULL);
END;

FUNCTION NUMARDISPONIBIL(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER IS
  DISPONIBIL NUMBER(10) := 0;
  BLOCAT     NUMBER(10) := 0;
BEGIN
  SELECT NVL(COUNT(*), 0) INTO BLOCAT FROM DOCLOCK
  WHERE
  CODCARNET = aCARNETDOC AND USEDNO = TO_NUMBER(aNUMARDOC); -- AND USERID &lt;&gt; PKG_GLOBALS.GETUSERID;

  IF BLOCAT = 0 THEN
    SELECT NVL(COUNT(*), 0) INTO DISPONIBIL FROM DOCFREE
    WHERE
    CODCARNET = aCARNETDOC AND TO_NUMBER(aNUMARDOC) &gt;= STARTNR AND TO_NUMBER(aNUMARDOC) &lt;= ENDNR;
  END IF;

  RETURN DISPONIBIL;
END;

-- nu stiu din ce motive functia de mai sus nu mai cointine testul pe userID
-- ca sa n-o parametrizez si sa bulesc o groaza de apeluri apare functie de mai jos care include testul
FUNCTION NUMARDISPONIBIL_EXT(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) RETURN NUMBER IS
  DISPONIBIL NUMBER(10) := 0;
  BLOCAT     NUMBER(10) := 0;
BEGIN
  SELECT NVL(COUNT(*), 0) INTO BLOCAT FROM DOCLOCK
  WHERE
  CODCARNET = aCARNETDOC AND USEDNO = TO_NUMBER(aNUMARDOC) AND USERID &lt;&gt; PKG_GLOBALS.GETUSERID;

  IF BLOCAT = 0 THEN
    SELECT NVL(COUNT(*), 0) INTO DISPONIBIL FROM DOCFREE
    WHERE
    CODCARNET = aCARNETDOC AND TO_NUMBER(aNUMARDOC) &gt;= STARTNR AND TO_NUMBER(aNUMARDOC) &lt;= ENDNR;
  END IF;

  RETURN DISPONIBIL;
END;


PROCEDURE SOLVENUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN VARCHAR2) IS
 Tmp Numeric;
BEGIN
  BEGIN
    SELECT CODCARNET INTO Tmp FROM DOCCARNETE WHERE CODCARNET = NVL(aCARNETDOC, 0) FOR UPDATE;
  EXCEPTION WHEN OTHERS THEN
    RETURN;
  END;

  UPDATE DOCCARNETE
  SET IN_UPDATE = 1
  WHERE CODCARNET = aCARNETDOC;

  FOR V_REC IN (SELECT * FROM DOCFREE WHERE CODCARNET = aCARNETDOC AND STARTNR &lt;= ENDNR ORDER BY STARTNR)
  LOOP
    IF V_REC.STARTNR = TO_NUMBER(aNUMARDOC) THEN BEGIN
      IF V_REC.STARTNR = V_REC.ENDNR THEN
        DELETE FROM DOCFREE WHERE CODDOCFREE = V_REC.CODDOCFREE;
        EXIT;
      ELSE
        UPDATE DOCFREE SET STARTNR = TO_NUMBER(aNUMARDOC) + 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;
        EXIT;
      END IF;
    END;
    ELSE
    IF V_REC.ENDNR = TO_NUMBER(aNUMARDOC) THEN
     BEGIN
       UPDATE DOCFREE SET ENDNR = ENDNR - 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;

       EXIT;
     END;
     ELSE
     IF TO_NUMBER(aNUMARDOC) &gt; V_REC.STARTNR AND  TO_NUMBER(aNUMARDOC) &lt; V_REC.ENDNR THEN
     BEGIN
       UPDATE DOCFREE SET ENDNR = TO_NUMBER(aNUMARDOC) - 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;

       INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR)
       VALUES (SEQ_DOCFREE_CODDOCFREE.NEXTVAL, aCARNETDOC, TO_NUMBER(aNUMARDOC) + 1, V_REC.ENDNR);

       EXIT;
     END;
     END IF;
    END IF;
    END IF;
  END LOOP;

  UPDATE DOCCARNETE SET FREENR = COUNTFREENR(aCARNETDOC) WHERE CODCARNET = aCARNETDOC;
  DELETE FROM DOCLOCK WHERE CODCARNET = aCARNETDOC AND USEDNO = TO_NUMBER(aNUMARDOC); 
--commit-ul se face in apelul functiei SOLVENUMARDOC
END;



PROCEDURE SOLVENUMARDOC_EXT(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER)
IS
BEGIN
  FOR V_REC IN ( SELECT /*+ INDEX(DF, IDX_DOCFREE_STARTNR) INDEX(DF, IDX_DOCFREE_ENDNR)  */  * FROM DOCFREE DF
	               WHERE CODCARNET = aCARNETDOC
								 AND STARTNR &lt;= ENDNR AND aNUMARDOC between STARTNR AND ENDNR ORDER BY STARTNR)
  LOOP
    IF V_REC.STARTNR = aNUMARDOC THEN BEGIN
      IF V_REC.STARTNR = V_REC.ENDNR THEN
        DELETE FROM DOCFREE WHERE CODDOCFREE = V_REC.CODDOCFREE;
        EXIT;
      ELSE
        UPDATE DOCFREE SET STARTNR = aNUMARDOC + 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;
        EXIT;
      END IF;
    END;
    ELSE
    IF V_REC.ENDNR = aNUMARDOC THEN
     BEGIN
       UPDATE DOCFREE SET ENDNR = ENDNR - 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;
       EXIT;
     END;
     ELSE
     IF aNUMARDOC &gt; V_REC.STARTNR AND aNUMARDOC &lt; V_REC.ENDNR THEN
     BEGIN
       UPDATE DOCFREE SET ENDNR = aNUMARDOC - 1 WHERE CODDOCFREE = V_REC.CODDOCFREE;
       INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR)
       VALUES (SEQ_DOCFREE_CODDOCFREE.NEXTVAL, aCARNETDOC, aNUMARDOC + 1, V_REC.ENDNR);
       EXIT;
     END;
     END IF;
    END IF;
    END IF;
  END LOOP;
END;

PROCEDURE SOLVENUMARDOC_EXTX(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER)
IS
BEGIN
  FOR V_REC IN ( SELECT /*+ INDEX(DF, IDX_DOCFREEX_STARTNR) INDEX(DF, IDX_DOCFREEX_ENDNR)  */  * FROM DOCFREEX DF
	               WHERE STARTNR &lt;= ENDNR AND aNUMARDOC between STARTNR AND ENDNR ORDER BY STARTNR)
  LOOP
    IF V_REC.STARTNR = aNUMARDOC THEN BEGIN
      IF V_REC.STARTNR = V_REC.ENDNR THEN
        DELETE FROM DOCFREEX WHERE STARTNR = V_REC.STARTNR;
        EXIT;
      ELSE
        UPDATE DOCFREEX SET STARTNR = aNUMARDOC + 1 WHERE STARTNR = V_REC.STARTNR;
        EXIT;
      END IF;
    END;
    ELSE
    IF V_REC.ENDNR = aNUMARDOC THEN
     BEGIN
       UPDATE DOCFREEX SET ENDNR = ENDNR - 1 WHERE ENDNR = V_REC.ENDNR;
       EXIT;
     END;
     ELSE
     IF aNUMARDOC &gt; V_REC.STARTNR AND aNUMARDOC &lt; V_REC.ENDNR THEN
     BEGIN
       UPDATE DOCFREEX SET ENDNR = aNUMARDOC - 1 WHERE STARTNR = V_REC.STARTNR;
       INSERT INTO DOCFREEX (STARTNR, ENDNR)
       VALUES (aNUMARDOC + 1, V_REC.ENDNR);
       EXIT;
     END;
     END IF;
    END IF;
    END IF;
  END LOOP;
  commit;
END;


PROCEDURE COMPACTEAZAINTERVALE(aCARNETDOC IN NUMBER)
IS
COD1 NUMBER(20) := 0;
COD2 NUMBER(20) := 0;
BEGIN
  LOOP
    BEGIN
      SELECT DF1, DF2 INTO COD1, COD2 FROM
      (
        SELECT D1.CODDOCFREE AS DF1, D1.STARTNR , D2.CODDOCFREE AS DF2
        FROM
          DOCFREE D1,
          DOCFREE D2
        WHERE
          D1.CODCARNET = aCARNETDOC
          AND D1.STARTNR &lt;= D1.ENDNR
          AND D2.STARTNR &lt;= D2.ENDNR
          AND D2.CODCARNET = aCARNETDOC
          AND D2.STARTNR = D1.ENDNR + 1
      )
      WHERE
      STARTNR =
      (SELECT MIN(STARTNR) FROM
          (SELECT DD1.STARTNR
          FROM
            DOCFREE DD1,
            DOCFREE DD2
          WHERE
            DD1.CODCARNET     = aCARNETDOC
            AND DD1.STARTNR  &lt;= DD1.ENDNR
            AND DD2.STARTNR  &lt;= DD2.ENDNR
            AND DD2.CODCARNET = aCARNETDOC
            AND DD2.STARTNR   = DD1.ENDNR + 1)
      );
       EXCEPTION WHEN OTHERS THEN BEGIN
         COD1 := 0; COD2 := 0;
       END;
     END;


    IF COD1 &lt;&gt; 0 AND COD2 &lt;&gt; 0 THEN
      UPDATE DOCFREE D1
      SET
        D1.ENDNR = (SELECT D2.ENDNR FROM DOCFREE D2 WHERE D2.CODDOCFREE = COD2)
      WHERE D1.CODDOCFREE = COD1;

      DELETE FROM DOCFREE WHERE CODDOCFREE = COD2;
    ELSE
      EXIT;
    END IF;


  END LOOP;
END;

PROCEDURE COMPACTEAZAINTERVALEX
IS
COD1 NUMBER(20) := 0;
COD2 NUMBER(20) := 0;
BEGIN
  LOOP
    BEGIN
      SELECT DF1, DF2 INTO COD1, COD2 FROM
      (
        SELECT D1.STARTNR AS DF1, D1.STARTNR , D2.STARTNR AS DF2
        FROM
          DOCFREEX D1,
          DOCFREEX D2
        WHERE
          D1.STARTNR &lt;= D1.ENDNR
          AND D2.STARTNR &lt;= D2.ENDNR
          AND D2.STARTNR = D1.ENDNR + 1
      )
      WHERE
      STARTNR =
      (SELECT MIN(STARTNR) FROM
          (SELECT DD1.STARTNR
          FROM
            DOCFREEX DD1,
            DOCFREEX DD2
          WHERE
            DD1.STARTNR  &lt;= DD1.ENDNR
            AND DD2.STARTNR  &lt;= DD2.ENDNR
            AND DD2.STARTNR   = DD1.ENDNR + 1)
      );
       EXCEPTION WHEN OTHERS THEN BEGIN
         COD1 := 0; COD2 := 0;
       END;
     END;

    IF COD1 &lt;&gt; 0 AND COD2 &lt;&gt; 0 THEN
      UPDATE DOCFREEX D1
      SET
        D1.ENDNR = (SELECT D2.ENDNR FROM DOCFREEX D2 WHERE D2.STARTNR = COD2)
      WHERE D1.STARTNR = COD1;

      DELETE FROM DOCFREE WHERE STARTNR = COD2;
    ELSE
      EXIT;
    END IF;
  END LOOP;
END;

PROCEDURE RELEASENUMARDOC(aCARNETDOC IN NUMBER, aNUMARDOC IN NUMBER) IS
  CAPATSTANGA   NUMBER(20) := 0;
  NRMAXINTERVAL NUMBER(20) := 0;
  CAPATDREAPTA  NUMBER(20) := 0;
  NRMININTERVAL NUMBER(20) := 0;
BEGIN
  IF aCARNETDOC &lt;&gt; 0 AND aNUMARDOC &lt;&gt; 0 THEN
    BEGIN
      SELECT CODDOCFREE, ENDNR   INTO CAPATSTANGA,  NRMAXINTERVAL FROM DOCFREE WHERE CODCARNET = aCARNETDOC AND STARTNR = aNUMARDOC + 1;
    EXCEPTION WHEN OTHERS THEN
      CAPATSTANGA := 0; NRMAXINTERVAL := 0;
    END;
    BEGIN
      SELECT CODDOCFREE, STARTNR INTO CAPATDREAPTA, NRMININTERVAL FROM DOCFREE WHERE CODCARNET = aCARNETDOC AND STARTNR &lt; aNUMARDOC AND ENDNR   = aNUMARDOC - 1;
    EXCEPTION WHEN OTHERS THEN
      CAPATDREAPTA := 0; NRMININTERVAL := 0;
    END;

    IF CAPATSTANGA &lt;&gt; 0 AND CAPATDREAPTA &lt;&gt; 0 THEN
      UPDATE DOCFREE SET STARTNR = NRMININTERVAL, ENDNR = NRMAXINTERVAL WHERE CODDOCFREE = CAPATSTANGA;
      DELETE FROM DOCFREE WHERE CODDOCFREE = CAPATDREAPTA;
    ELSIF CAPATSTANGA &lt;&gt; 0  THEN
      UPDATE DOCFREE SET STARTNR = aNUMARDOC WHERE CODDOCFREE = CAPATSTANGA;
    ELSIF CAPATDREAPTA &lt;&gt; 0 THEN
      UPDATE DOCFREE SET ENDNR = aNUMARDOC WHERE CODDOCFREE = CAPATDREAPTA;
    ELSE
      INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR) VALUES(SEQ_DOCFREE_CODDOCFREE.NEXTVAL, aCARNETDOC, aNUMARDOC, aNUMARDOC);
    END IF;

    UPDATE DOCCARNETE SET FREENR = COUNTFREENR(aCARNETDOC) WHERE CODCARNET = aCARNETDOC;
  END IF;
END;

FUNCTION GETCARNETFORMACHETA(aMACHETA IN NUMBER, aSubunitate IN NUMBER) RETURN NUMBER
IS
aCARNET  NUMBER(20) := 0;
NUMARDOC NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
   ( SELECT * FROM DOCCARNETE D
     WHERE
       D.INACTIV &lt;&gt; 1
			 AND
			 Coalesce(D.Farasalvare,0) = 0
       AND
       D.CODCARNET IN ( SELECT CODCARNET
                      FROM DOCLINK DL
                      WHERE DL.CODMACHETA = aMACHETA)
       AND ( (NVL(D.DEDICAT,0) = 0)
             OR
             (EXISTS (SELECT CODDOCUSERS FROM DOCUSERS WHERE CODUSER = PKG_GLOBALS.USERID AND  CODCARNET = D.CODCARNET ) )
           )
       AND
       NVL(D.SUBUNITATEA,1) = DECODE(aSubunitate, 1, NVL(D.SUBUNITATEA, 1), aSubunitate)
     ORDER BY D.CODCARNET DESC
   )
   LOOP
     BEGIN
       SELECT NVL(MIN(STARTNR), 0) INTO NUMARDOC FROM DOCFREE WHERE CODCARNET = V_REC.CODCARNET;
       EXCEPTION WHEN OTHERS THEN NUMARDOC := 0;
     END;
     IF NUMARDOC &lt;&gt; 0 THEN RETURN V_REC.CODCARNET;
     END IF;
   END LOOP;

   RETURN aCARNET;
END;

FUNCTION GETNEXTNRDOC(aCODCARNET IN NUMBER, SERIEDOC OUT VARCHAR2, SIMBOLDOC OUT VARCHAR2) RETURN VARCHAR2
IS
NUMARDOC NUMBER(20) := 0;
BLOCAT   NUMBER(20) := 0;
I        NUMBER(20);
BEGIN
  BEGIN
    SELECT NVL(SERIE, &apos;&apos;), NVL(SIMBOL, &apos;&apos;) INTO SERIEDOC, SIMBOLDOC FROM DOCCARNETE WHERE CODCARNET = aCODCARNET;
    EXCEPTION WHEN OTHERS THEN BEGIN SERIEDOC := &apos;&apos;; SIMBOLDOC := &apos;&apos;; END;
  END;
  FOR V_REC IN (SELECT * FROM DOCFREE WHERE CODCARNET = aCODCARNET ORDER BY STARTNR) LOOP
    I        := V_REC.STARTNR;
    WHILE I &lt;= V_REC.ENDNR LOOP
      BLOCAT := 0;
      SELECT NVL(COUNT(*), 0) INTO BLOCAT FROM DOCLOCK
      WHERE
      CODCARNET = aCODCARNET AND USEDNO = I;
      IF BLOCAT = 0 THEN
        RETURN I;
      END IF;
      I := I + 1;
    END LOOP;
  END LOOP;
  RETURN TO_CHAR(NUMARDOC);
END;


FUNCTION CARNETE_COMENZIONLINE(CodCarnetCurent IN NUMBER) RETURN NUMBER IS
  nr_carnete_co NUMBER(20) := 0;
BEGIN
  SELECT COUNT(*) INTO nr_carnete_co FROM DOCCARNETE WHERE CODCARNET &lt;&gt; CodCarnetCurent AND NVL(COMENZIONLINE, 0) = 1;
  RETURN nr_carnete_co;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCARNET INTO Tmp FROM DOCCARNETE WHERE CODCARNET = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_DOCCARNETE FIELDS (CODCARNET) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
  aDoc        VARCHAR2(100);
  aSubunitate NUMBER(20);
  aNrFolosite NUMBER(20);
BEGIN
  SELECT ENDNR - STARTNR + 1 - COALESCE(FREENR,0) NrFolosite
  INTO aNrFolosite
  FROM DOCCARNETE
  WHERE CODCARNET = RecId;

  IF aNrFolosite &gt; 0
  THEN RAISE_APPLICATION_ERROR(-30000, &apos;Carnet folosit in documente &apos;);
  END IF;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;carnet documente &apos; || DC.DENUMIRE || &apos; &apos; || DC.SIMBOL || &apos;/&apos; || DC.SERIE, dc.subunitatea
    INTO aDoc, aSubunitate
    FROM DOCCARNETE DC
    WHERE dc.codcarnet = RecId;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOCCARNETE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aSubunitate, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  SP_LOCKRECORD(RecId);
  DELETE FROM DOCLINK    WHERE CODCARNET = RecId;
  DELETE FROM DOCUSERS   WHERE CODCARNET = RecId;
  DELETE FROM DOCFREE    WHERE CODCARNET = RecId;
  DELETE FROM DOCLOCK    WHERE CODCARNET = RecId;

  DELETE FROM DOCCARNETE WHERE CODCARNET = RecId;

  NotifyModif(2, RecId, &apos;DOCCARNETE&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_DOCCARNETE
  (SELECT * FROM DOCCARNETE WHERE CODCARNET = RecId);

  INSERT INTO TMP_DOCLINK (
    CODDOCLINK, CODCARNET, CODMACHETA,
    DENMACHETA)
  SELECT
    CODDOCLINK, CODCARNET, CODMACHETA,
    CASE
      WHEN CODMACHETA = 503 THEN &apos;Certificat de calitate&apos;
      WHEN CODMACHETA &lt; 1000 THEN (SELECT Coalesce(NUMEEXT, &apos;&apos;) FROM TMP_MACHETE             WHERE CODMACHETA = D.CODMACHETA)
      ELSE                        (SELECT Coalesce(MIN(m.CAPTION) KEEP (DENSE_RANK FIRST ORDER BY m.PROG NULLS LAST, m.CODMAKETEPROPRII), &apos;&apos;) 
                                                                                   FROM WINMADMIN.MaketeProprii m 
                                                                                   WHERE m.IDDocument = D.CODMACHETA)
		END
  FROM DOCLINK D
  WHERE CODCARNET = RecId;

  UPDATE TMP_DOCLINK
  SET
   DENMACHETA = DENMACHETA || &apos;(autofacturare)&apos;
  WHERE
    CODMACHETA IN (1, 9);

  INSERT INTO TMP_DOCUSERS (CODDOCUSERS, CODCARNET, CODUSER, USERNAME)
  (SELECT
     CODDOCUSERS, CODCARNET, CODUSER,
     (SELECT t.USERNAME FROM Tmp_Utilizator t WHERE t.codutilizator = D.CODUSER) USERNAME
   FROM DOCUSERS D WHERE CODCARNET = RecId);

  INSERT INTO TMP_DOCFREE
  SELECT * FROM DOCFREE WHERE CODCARNET = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
  aDoc varchar2(100);
  aSubunitate number(20);
BEGIN

  IF OPERATION = 0 THEN  -- UPDATE

-- Master DOCCARNETE
    SELECT  CODCARNET INTO RecId FROM TMP_DOCCARNETE;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;carnet documente &apos; || DC.DENUMIRE || &apos; &apos; || DC.SIMBOL || &apos;/&apos; || DC.SERIE, dc.subunitatea
    INTO aDoc, aSubunitate
    FROM TMP_DOCCARNETE DC
    WHERE DC.codcarnet = RecId;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOCCARNETE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitate, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM DOCLINK  WHERE CODCARNET = RECID AND CODDOCLINK  NOT IN (SELECT CODDOCLINK  FROM TMP_DOCLINK);
  DELETE FROM DOCUSERS WHERE CODCARNET = RECID AND CODDOCUSERS NOT IN (SELECT CODDOCUSERS FROM TMP_DOCUSERS);
  DELETE FROM DOCFREE  WHERE CODCARNET = RECID AND CODDOCFREE  NOT IN (SELECT CODDOCFREE  FROM TMP_DOCFREE);

    -- DOCCARNETE
    UPDATE DOCCARNETE
    SET (SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA, STARTNRINI, DEDICAT, COMENZIONLINE, FARASALVARE, CODPOSTRETAIL, ALLSUBUNIT ) =
        (SELECT  SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA, STARTNRINI, DEDICAT, COMENZIONLINE, FARASALVARE, CODPOSTRETAIL, ALLSUBUNIT FROM TMP_DOCCARNETE)
    WHERE
    CODCARNET = RECID;


    -- DOCLINK
    FOR v_rec IN (SELECT * FROM TMP_DOCLINK) LOOP
      IF V_REC.CODDOCLINK &lt; 0 THEN
        INSERT INTO DOCLINK (CODDOCLINK, CODCARNET, CODMACHETA) VALUES
        (SEQ_DOCLINK_CODDOCLINK.NEXTVAL, RECID, V_REC.CODMACHETA);
      ELSE
        UPDATE DOCLINK
        SET
          CODCARNET  = V_REC.CODCARNET,
          CODMACHETA = V_REC.CODMACHETA
        WHERE CODDOCLINK = V_REC.CODDOCLINK;
      END IF;
    END LOOP;

    -- DOCUSERS
    FOR v_rec IN (SELECT * FROM TMP_DOCUSERS WHERE NVL(CODUSER,0) &gt; 0 )  LOOP
      IF V_REC.CODDOCUSERS &lt; 0 THEN
        INSERT INTO DOCUSERS (CODDOCUSERS, CODCARNET, CODUSER) VALUES
        (SEQ_DOCUSERS_CODDOCUSERS.NEXTVAL, RECID, V_REC.CODUSER);
      ELSE
        UPDATE DOCUSERS
        SET
          CODCARNET  = V_REC.CODCARNET,
          CODUSER    = V_REC.CODUSER
        WHERE CODDOCUSERS = V_REC.CODDOCUSERS;
      END IF;
    END LOOP;


    -- DOCFREE
    FOR v_rec IN (SELECT * FROM TMP_DOCFREE) LOOP
      IF V_REC.CODDOCFREE &lt; 0 THEN
        INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR) VALUES
        (SEQ_DOCFREE_CODDOCFREE.NEXTVAL, RECID, V_REC.STARTNR, V_REC.ENDNR);
      ELSE
        UPDATE DOCFREE
        SET
          CODCARNET = V_REC.CODCARNET,
          STARTNR   = V_REC.STARTNR,
          ENDNR     = V_REC.ENDNR
        WHERE CODDOCFREE = V_REC.CODDOCFREE;
      END IF;
    END LOOP;

  ELSE -- INSERT
    SELECT seq_DOCCARNETE_CODCARNET.NEXTVAL INTO RECID FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT  &apos;carnet documente &apos;||DC.DENUMIRE||&apos; &apos;||DC.SIMBOL||&apos;/&apos;||DC.SERIE,dc.subunitatea into aDoc,aSubunitate
      FROM TMP_DOCCARNETE DC ;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOCCARNETE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                       aSubunitate, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO DOCCARNETE (CODCARNET, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA, STARTNRINI, DEDICAT, COMENZIONLINE, FARASALVARE, CODPOSTRETAIL, ALLSUBUNIT)
    (SELECT  RECID, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA, STARTNRINI, DEDICAT, COMENZIONLINE, FARASALVARE, CODPOSTRETAIL, ALLSUBUNIT FROM TMP_DOCCARNETE);

    INSERT INTO DOCLINK (CODDOCLINK, CODCARNET, CODMACHETA)
    (SELECT SEQ_DOCLINK_CODDOCLINK.NEXTVAL, RECID, CODMACHETA FROM TMP_DOCLINK);

    INSERT INTO DOCUSERS (CODDOCUSERS, CODCARNET, CODUSER)
    (SELECT SEQ_DOCUSERS_CODDOCUSERS.NEXTVAL, RECID, CODUSER FROM TMP_DOCUSERS);

    INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR)
    (SELECT SEQ_DOCFREE_CODDOCFREE.NEXTVAL, RECID, STARTNR, ENDNR FROM TMP_DOCFREE);

  END IF;
  NotifyModif(Operation, RecId, &apos;DOCCARNETE&apos;);
  COMMIT;
END;

PROCEDURE GENEREAZA_CARNETE( aDEN       IN VARCHAR2,
                             aSIMBOL    IN VARCHAR2,
                             aSERIE     IN VARCHAR2,
                             STARTPAGE  IN NUMBER,
                             NRPAGINI   IN NUMBER,
                             NRCARNETE  IN NUMBER,
                             INDEXSERIE IN NUMBER
                           )
IS
  I           NUMBER(5);
  SP          NUMBER(20);
  ENDP        NUMBER(20);
  aCODCARNET  NUMBER(20);
  aSER        VARCHAR2(10);
begin
  i := 1;
  WHILE I &lt;= NRCARNETE LOOP
    SP   := STARTPAGE + (I - 1) * NRPAGINI;
    ENDP := SP + NRPAGINI - 1;
    aSER := aSERIE;
    IF INDEXSERIE = 1 THEN aSER := SUBSTR(aSER || TO_CHAR(I), 1, 10); END IF;

    aCODCARNET := SEQ_DOCCARNETE_CODCARNET.NEXTVAL;

    INSERT INTO DOCCARNETE(CODCARNET, DENUMIRE, SIMBOL, SERIE, STARTNR, ENDNR, FREENR, SUBUNITATEA)
    VALUES (aCODCARNET, aDEN, aSIMBOL, aSER, SP, ENDP, NRPAGINI, PKG_GLOBALS.GETSUBUNITATE_DOC);

    INSERT INTO DOCFREE(CODDOCFREE, CODCARNET, STARTNR, ENDNR)
    VALUES (SEQ_DOCFREE_CODDOCFREE.NEXTVAL, aCODCARNET, SP, ENDP);

    FOR V_REC_LINK IN (SELECT * FROM TMP_MANEVRA)
    LOOP
      INSERT INTO DOCLINK(CODDOCLINK, CODCARNET, CODMACHETA)
      VALUES (SEQ_DOCLINK_CODDOCLINK.NEXTVAL, aCODCARNET, V_REC_LINK.CODUNIC);
    END LOOP;


    I := I + 1;
  END LOOP;

  COMMIT;

end;


END PKG_CARNETEDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CASEOFFLINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD19895155AC9C1D5A197C8028FE3BA31B055FC9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CASEOFFLINE IS

PROCEDURE SP_EURO_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  DELETE FROM EURO WHERE CodCasa = RecId ;
  COMMIT;
END;

PROCEDURE SP_ZEURO_DELETERECORD( RecId IN NUMBER, Zet IN NUMBER, DataRaport IN DATE ) IS
BEGIN
  DELETE FROM ZEURO WHERE CodCasa = RecId AND Z = Zet AND DataZ = DataRaport;
  COMMIT;
END;

PROCEDURE SP_EURO_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  DELETE FROM TMP_EURO;
  INSERT INTO  TMP_EURO ( COD,
                          CODCASA,
                          PLU,
                          DEP,
                          TVACASA,
                          OBIECT,
                          GESTIUNE,
                          CONT,
                          TVA,
                          PRET,
                          STOC,
                          FARACTRL,
                          VANDUT,
                          BARCOD,
                          PLULINK,
                          DESCRIPTIV,
                          SERVICIU,
                          CANTAR,
                          STERS,
                          SELECTAT,
                          DEN_DEP,
                          DEN_TVA,
                          DEN_OBIECT,
                          DEN_GEST,
                          DEN_CONT,
                          DIFERENTA,
                          UM,                         
                          UM1,                         
                          UM2,                         
                          DEN_UM,                        
                          CODTVA,                        
                          PROCENT )
    ( SELECT              e.COD,
                          e.CODCASA,
                          e.PLU,
                          e.DEP,
                          e.TVACASA,
                          e.OBIECT,
                          e.GESTIUNE,
                          e.CONT,
                          e.TVA,
                          e.PRET,
                          e.STOC,
                          e.FARACTRL,
                          e.VANDUT,
                          e.BARCOD,
                          e.PLULINK,
                          e.DESCRIPTIV,
                          e.SERVICIU,
                          e.CANTAR,
                          e.STERS,
                          e.SELECTAT,
                          &apos;&apos;,
                          &apos;&apos;,
                          o.denumire,
                          g.den_gest,
                          c.den_ioart,
                          0,
                          a.UM,
                          a.UM1,
                          a.UM2,
                          UM.Den_Um1,
                          e.TVA,
                          TVAL.PROCENT
      FROM EURO e LEFT JOIN NARTOBJ o ON e.obiect = o.codobiect
                  LEFT JOIN NGEST g ON e.gestiune = g.codgest 
                  LEFT JOIN IOART c ON e.cont = c.codioart
                  INNER JOIN NART a ON o.codarticol = a.codarticol
                  INNER JOIN NUM1 UM ON a.um = UM.CODUM1
                  LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL
                  LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA 
                  Where e.codcasa = RecId);

  COMMIT;
END;

PROCEDURE SP_ZEURO_GOTORECORD( RecId IN NUMBER , ZET IN NUMBER , DataRaport IN DATE) IS -- RecId este codcasa (de marcat)
BEGIN
  DELETE FROM TMP_ZEURO;
  INSERT INTO  TMP_ZEURO (COD,       
                          CODCASA,   
                          PLU,       
                          DEP,       
                          OBIECT,    
                          GESTIUNE,  
                          CONT,      
                          TVA,       
                          PRET,      
                          STOC,      
                          VANDUT,    
                          CODMONETAR,
                          Z,
                          DataZ)         
    ( SELECT              COD,       
                          CODCASA,   
                          PLU,       
                          DEP,       
                          OBIECT,    
                          GESTIUNE,  
                          CONT,      
                          TVA,       
                          PRET,      
                          STOC,      
                          VANDUT,    
                          CODMONETAR,
                          Z,
                          DataZ         
      FROM ZEURO WHERE CodCasa = RecId AND Z = ZET AND DataZ = DataRaport) ;

  COMMIT;
END;


PROCEDURE SP_EURO_POSTRECORDS(Operation IN NUMBER, RecId IN NUMBER ) IS

BEGIN
  IF Operation = 0 THEN  -- UPDATE

    DELETE FROM EURO where CodCasa = RecId and Cod not in (Select cod from TMP_EURO);

    INSERT INTO EURO ( COD,
                       CODCASA,
                       PLU,
                       DEP,
                       TVACASA,
                       OBIECT,
                       GESTIUNE,
                       CONT,
                       TVA,
                       PRET,
                       STOC,
                       FARACTRL,
                       VANDUT,
                       BARCOD,
                       PLULINK,
                       DESCRIPTIV,
                       SERVICIU,
                       CANTAR,
                       STERS,
                       SELECTAT )
      SELECT  SEQ_EURO_COD.Nextval,
              RecId,
              PLU,
              DEP,
              TVACASA,
              OBIECT,
              GESTIUNE,
              CONT,
              TVA,
              PRET,
              STOC,
              FARACTRL,
              VANDUT,
              BARCOD,
              PLULINK,
              DESCRIPTIV,
              SERVICIU,
              CANTAR,
              STERS,
              SELECTAT
      FROM TMP_EURO WHERE cod &lt; 0;-- adaugam inregistrarile noi ;

    -- si facem update la cele care au ramas
    FOR v_rec IN ( SELECT * FROM TMP_EURO WHERE NVL(cod,-1) &gt; 0 ) LOOP
       UPDATE EURO
       SET
        PLU       = v_rec.PLU,
        DEP       = v_rec.dep,
        TVACASA   = v_rec.tvacasa,
        OBIECT    = v_rec.obiect,
        GESTIUNE  = v_rec.gestiune,
        CONT      = v_rec.cont,      
        TVA       = v_rec.tva,       
        PRET      = v_rec.pret,        
        STOC      = v_rec.stoc,        
        FARACTRL  = v_rec.faractrl,            
        VANDUT    = v_rec.vandut,          
        BARCOD    = v_rec.barcod,          
        PLULINK   = v_rec.plulink,           
        DESCRIPTIV= v_rec.descriptiv,              
        SERVICIU  = v_rec.serviciu,            
        CANTAR    = v_rec.cantar,          
        STERS     = v_rec.sters,         
        SELECTAT  = v_rec.selectat        
       WHERE COD  = v_rec.cod;
    END LOOP;
    COMMIT;
    
  ELSE  -- INSERT
  
  INSERT INTO  EURO ( COD,
                      CODCASA,
                      PLU,
                      DEP,
                      TVACASA,
                      OBIECT,
                      GESTIUNE,
                      CONT,
                      TVA,
                      PRET,
                      STOC,
                      FARACTRL,
                      VANDUT,
                      BARCOD,
                      PLULINK,
                      DESCRIPTIV,
                      SERVICIU,
                      CANTAR,
                      STERS,
                      SELECTAT )
     ( SELECT         seq_euro_cod.Nextval ,
                      CODCASA,
                      PLU,
                      DEP,
                      TVACASA,
                      OBIECT,
                      GESTIUNE,
                      CONT,
                      TVA,
                      PRET,
                      STOC,
                      FARACTRL,
                      VANDUT,
                      BARCOD,
                      PLULINK,
                      DESCRIPTIV,
                      SERVICIU,
                      CANTAR,
                      STERS,
                      SELECTAT
       FROM TMP_EURO );
  COMMIT;   
END IF;


END;

PROCEDURE SP_ZEURO_POSTRECORDS(Operation IN NUMBER, RecId IN NUMBER, Zet IN NUMBER,  DataRaport IN varchar2 ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    DELETE FROM ZEURO where CodCasa = RecId and DataZ = To_Date(DataRaport) and Z = Zet and Cod not in (Select Cod from TMP_ZEURO);

    INSERT INTO ZEURO (COD,       
                       CODCASA,   
                       PLU,       
                       DEP,       
                       OBIECT,    
                       GESTIUNE,  
                       CONT,      
                       TVA,       
                       PRET,      
                       STOC,      
                       VANDUT,    
                       CODMONETAR,
                       Z,
                       DataZ          )
      SELECT  SEQ_ZEURO_COD.Nextval,
              CODCASA,   
              PLU,       
              DEP,       
              OBIECT,    
              GESTIUNE,  
              CONT,      
              TVA,       
              PRET,      
              STOC,      
              VANDUT,    
              CODMONETAR,
              Z,
              DataZ         
      FROM TMP_ZEURO WHERE cod &lt; 0;-- adaugam inregistrarile noi ;

    -- si facem update la cele care au ramas
    FOR v_rec IN ( SELECT * FROM TMP_ZEURO WHERE NVL(cod,-1) &gt; 0 ) LOOP
       UPDATE ZEURO
       SET
        PLU        = v_rec.plu,       
        DEP        = v_rec.dep,       
        OBIECT     = v_rec.obiect,    
        GESTIUNE   = v_Rec.Gestiune,  
        CONT       = v_rec.cont,      
        TVA        = v_rec.tva,       
        PRET       = v_rec.pret,      
        STOC       = v_rec.stoc,      
        VANDUT     = v_rec.vandut,    
        CODMONETAR = v_rec.codmonetar,
        Z          = v_rec.z,
        DataZ      = v_rec.DataZ        
       WHERE COD = v_rec.cod;
    END LOOP;
    COMMIT;
    
  ELSE  -- INSERT
  
  INSERT INTO  ZEURO ( COD,       
                       CODCASA,   
                       PLU,       
                       DEP,       
                       OBIECT,    
                       GESTIUNE,  
                       CONT,      
                       TVA,       
                       PRET,      
                       STOC,      
                       VANDUT,    
                       CODMONETAR,
                       Z,
                       DataZ )
     ( SELECT          seq_zeuro_cod.Nextval ,
                       CODCASA,   
                       PLU,       
                       DEP,       
                       OBIECT,    
                       GESTIUNE,  
                       CONT,      
                       TVA,       
                       PRET,      
                       STOC,      
                       VANDUT,    
                       CODMONETAR,
                       Z,
                       DataZ
       FROM TMP_ZEURO );
  COMMIT;   
END IF;

END;

FUNCTION SP_ZEURO_GETNEXTZET(aCodCasa IN NUMBER, DataRaport in varchar2) RETURN NUMBER IS
NextZet Number(20);
BEGIN
  
  SELECT MAX(Z)+1 INTO NextZet FROM ZEURO WHERE CodCasa = aCodCasa AND DataZ = To_Date(DataRaport);
  RETURN NextZet;
  exception when others then begin
    NextZet := 0;
    return nextzet;
  end;
    
END;

end pkg_caseoffline; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E9190112FA870CFCF9C97554319868677ABDE2E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CASHFLOW is
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCASHFLOW INTO Tmp FROM CASHFLOW WHERE CODCASHFLOW = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM SOLDCASHFLOW WHERE CODCASHFLOW = RecId ;
 	DELETE FROM CURSCASHFLOW WHERE CODCASHFLOW = RecId ;
 	DELETE FROM CASHFLOW1 WHERE CODCASHFLOW = RecId ;
 	DELETE FROM CASHFLOW2 WHERE CODCASHFLOW = RecId ;
 	DELETE FROM CRONOCASHFLOW WHERE CODCASHFLOW = RecId ;
 	DELETE FROM CASHFLOW  WHERE CODCASHFLOW = RecId ;
  NotifyModif(2, RecId, &apos;CASHFLOW&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CASHFLOW FIELDS(CODCASHFLOW) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCODCONT NUMBER(20) := 0;
BEGIN
  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);
 
  INSERT INTO TMP_CASHFLOW 
 (
  CODCASHFLOW, 
  DATA, 
  CODBANKCONT, 
  VALOARE, 
  CARNETDOC, 
  NRDOC, 
  VALOAREDEREPARTIZAT, 
  AN, 
  LUNA, 
  CODMONEDA, 
  APROBAT, 
  ZILE,
  SUBUNITATEA
 )
  (SELECT 
   CODCASHFLOW, 
   DATA, 
   CODBANKCONT, 
   VALOARE, 
   CARNETDOC, 
   NRDOC, 
   VALOAREDEREPARTIZAT, 
   AN, 
   LUNA, 
   P.CODMONEDA, 
   APROBAT, 
   ZILE,
   SUBUNITATEA
   FROM
     CASHFLOW P
   WHERE
     P.CODCASHFLOW = RECID 
   );


   UPDATE TMP_CASHFLOW P
   SET
    SOLDCONT = CASE 
                 WHEN NVL(CODMONEDA, 0) = 0  THEN (SELECT SOLDLEI FROM V_SOLDURIBANCILUNA WHERE CODBANKCONT = P.CODBANKCONT) 
                 ELSE (SELECT SOLDVALUTA FROM V_SOLDURIBANCILUNA WHERE CODBANKCONT = P.CODBANKCONT)
               END;   

   INSERT INTO TMP_CASHFLOW1 
   (CODCASHFLOW1, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODOP1, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    Obs, Tip, TipStr, 
    DENCENTRUCOST, 
    DENNODANALIZA,
    SIMBOLCONT
   )
   (
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     I.PREFIXDOC,
    I.DATADOC,
     I. NRDOC,
     O.TERMEN,
    I.SUBUNITATEA,
    M.SIMBOL,
    P1.Obs, 0, &apos;Preluata&apos;,
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
    PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,I.AN*12+I.LUNA,O.Semnificatie)
   FROM
     CASHFLOW1 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     INTRARI I,
     NPART P,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
    AND O.SEMNIFICATIE = 100
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
    AND G.CODGENERAL  = O.CODGENERAL
    AND M.CODMONEDA   = G.MONEDA
    AND G.TIPDOC      = I.TIPDOC
    AND G.CODDOC      = I.CODINTR
    AND P.CODPART     = O.CODPART
    AND COALESCE(P1.TIP,0) = 0 
    UNION ALL
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     I.PREFIXDOC,
    I.DATADOC,
     I. NRDOC,
     O.TERMEN,
    I.SUBUNITATEA,
    M.SIMBOL,
    P1.Obs, 0, &apos;Preluata&apos;,  
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
    PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,I.AN*12+I.LUNA,O.Semnificatie)
   FROM
     CASHFLOW1 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     INTRARI I,
     DVI D,
     NPART P,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
    AND O.SEMNIFICATIE = 130
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
    AND G.CODGENERAL  = O.CODGENERAL
    AND M.CODMONEDA   = G.MONEDA
    AND G.TIPDOC      = I.TIPDOC
    AND G.CODDOC      = D.CODDVI
    AND I.CODINTR     = D.CODINTR
    AND P.CODPART     = O.CODPART
    AND COALESCE(P1.TIP,0) = 0 
    UNION ALL
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     &apos;NC&apos;, 
    NC.DATADOC,
     NC. NRDOC,
     O.TERMEN,
    NC.SUBUNITATEA,
    M.SIMBOL,
    P1.Obs, 0, &apos;Preluata&apos;, 
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
    PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,NC.AN*12+NC.LUNA,O.Semnificatie)
   FROM
     CASHFLOW1 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     NC NC,
     NC1 NC1,
     NPART P,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
    AND O.SEMNIFICATIE IN (1200, 1201)
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
    AND G.CODGENERAL  = O.CODGENERAL
    AND M.CODMONEDA   = G.MONEDA
    AND G.TIPDOC      = 35
    AND G.CODDOC      = NC1.CODNC1
    AND NC.CODNC      = NC1.CODNC
    AND P.CODPART     = O.CODPART
    AND COALESCE(P1.TIP,0) = 0
  UNION ALL
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     T1.DOC,
    T1.DATADOC,
     T1. NRDOC,
     O.TERMEN,
    T.SUBUNITATEA,
    M.SIMBOL,
    P1.Obs, 0, &apos;Preluata&apos;, 
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
    PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,T.AN*12+T.LUNA,O.Semnificatie)
   FROM
     CASHFLOW1 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     TREZOR1 T1,
     TREZOR  T,
     NPART P,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
    AND O.SEMNIFICATIE IN (410,500)
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
    AND G.CODGENERAL  = O.CODGENERAL
    AND M.CODMONEDA   = G.MONEDA
    AND G.TIPDOC      IN (29, 30, 31, 33)
    AND G.CODDOC      = T1.CODTREZOR1
    AND T.CODTREZOR   = T1.CODTREZOR
    AND P.CODPART     = O.CODPART
    AND COALESCE(P1.TIP,0) = 0
  ) 
  UNION ALL
  SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P1.CODPART, 
     P.DEN_PART,
     P1.DOC,
    P1.DATADOC,
     P1. NRDOC,
     P1.TERMEN,
    0,
    M.SIMBOL,
    P1.Obs, 1, &apos;Manuala&apos;, 
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
    PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,P.AN*12+P.LUNA,O.Semnificatie)
   FROM
     CASHFLOW1 P1
     INNER JOIN CASHFLOW P ON P.CODCASHFLOW = P1.CODCASHFLOW
     LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF
     LEFT JOIN CENTRECOST C ON C.CODCENTRU = O.CODCENTRU
     LEFT JOIN ANALIZANOD N ON N.CODANALIZANOD = O.CODANALIZANOD
     LEFT JOIN NPART P ON P.CODPART = P1.CODPART
     LEFT JOIN NMONEDE M ON M.CODMONEDA = P1.CODMONEDA
   WHERE
    P1.CODCASHFLOW = RECID
    AND P1.TIP = 1
  ;   

-- linii din operatiuni regulate
   INSERT INTO TMP_CASHFLOW1 
   (CODCASHFLOW1, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODOP1, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    TIP,OBS,TIPSTR
   )
   (
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     NULL, 
     SUBSTR(O.OBS, 1, 50),
     NULL,
    NULL,
     NULL,
     O1.TERMEN,
    O.SUBUNITATEA,
    M.SIMBOL,
    0,P1.OBS, &apos;Preluata&apos;
   FROM
     CASHFLOW1 P1,
     OPREG O,
     OPREG1 O1,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOP1, 0) &lt;&gt; 0 
    AND P1.CODOP1     = O1.CODOP1
    AND O1.CODOP      = O.CODOP
    AND M.CODMONEDA   = NVL(O.CODMONEDA, 0)
    AND COALESCE(P1.TIP,0) = 0
   ) ;   

-- linii din contracte
   INSERT INTO TMP_CASHFLOW1 
   (CODCASHFLOW1, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODCONTRACT2, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    TIP, OBS, TIPSTR, 
    DENCENTRUCOST, 
    DENNODANALIZA
   )
   (
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODCONTRACT2, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     C.PARTENER,
     P.DEN_PART,
     &apos;Contr.Leas&apos;,
     C2.DATA,
    C.NRDOC,
     C2.DATA,
    C.SUBUNITATEA,
    M.SIMBOL,
    0,P1.OBS, &apos;Preluata&apos;, 
    CASE WHEN CEN.CODCENTRU &gt; 0 THEN CEN.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END
   FROM
     CASHFLOW1 P1,
     CONTRACT C,
     CONTRACT2 C2,
     NMONEDE M,
     NPART P, 
     OBLIGPIF O
     LEFT JOIN CENTRECOST CEN ON O.CODCENTRU   = CEN.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODCONTRACT2, 0) &lt;&gt; 0 
    AND P1.CODCONTRACT2 = C2.CODCONTRACT2
    AND C2.CODCONTRACT = C.CODCONTRACT
    AND M.CODMONEDA   = NVL(C.MONEDA, 0)
    AND P.CODPART = C.PARTENER
    AND COALESCE(P1.TIP,0) = 0
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
   ) ;   

-- linii din note credit
   INSERT INTO TMP_CASHFLOW1 
   (CODCASHFLOW1, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODNCREDIT, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    TIP, OBS, TIPSTR,
    DENCENTRUCOST,
    DENNODANALIZA
   )
   (
   SELECT
    P1.CODCASHFLOW1, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODNCREDIT, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     NC.CODPART,
     P.DEN_PART,
     &apos;Nota credit&apos;,
     NULL,
    NULL,
     NC.DATASTOP,
    NC.SUBUNITATEA,
    M.SIMBOL,
    0, P1.OBS, &apos;Preluata&apos;, 
    CASE WHEN CEN.CODCENTRU &gt; 0 THEN CEN.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END
   FROM
     CASHFLOW1 P1
     LEFT JOIN OBLIGPIF O ON P1.CODOBLIGPIF = O.CODOBLIGPIF
     LEFT JOIN CENTRECOST CEN ON CEN.CODCENTRU = O.CODCENTRU
     LEFT JOIN ANALIZANOD N ON N.CODANALIZANOD = O.CODANALIZANOD,
     NOTECREDIT NC
     LEFT  OUTER JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2 
     LEFT  JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT 
     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0),
     NPART P
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODNCREDIT, 0) &lt;&gt; 0 
    AND P1.CODNCREDIT = NC.CODNCREDIT
    AND P.CODPART = NC.CODPART
    AND COALESCE(P1.TIP,0) = 0
   ) ;   

   INSERT INTO TMP_CASHFLOW2 
   (CODCASHFLOW2, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA, 
    CODOP1, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    OBS, TIP, TIPSTR, 
    DENCENTRUCOST, 
    DENNODANALIZA,
    SIMBOLCONT
   )
   (
   SELECT
     P1.CODCASHFLOW2, 
      P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
     P1.DATAPROPUSA,
     P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     I.PREFIXDOC,
     I.DATADOC,
     I. NRDOC,
     O.TERMEN,
     I.SUBUNITATEA,
     M.SIMBOL,
     P1.OBS, 0, &apos;Preluata&apos;, 
     CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
     CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
     PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,I.AN*12+I.LUNA,O.Semnificatie)
   FROM
     CASHFLOW2 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     IESIRI I,
     NPART P,
     NMONEDE M
   WHERE
     CODCASHFLOW = RECID
     AND NVL(P1.CODOBLIGPIF, 0) &gt; 0
     AND O.CODOBLIGPIF = P1.CODOBLIGPIF
     AND G.CODGENERAL  = O.CODGENERAL
     AND M.CODMONEDA   = G.MONEDA
     AND G.TIPDOC      = I.TIPDOC
     AND G.CODDOC      = I.CODIES
     AND P.CODPART     = O.CODPART
     AND COALESCE(P1.TIP,0) = 0
   UNION ALL
   SELECT
     P1.CODCASHFLOW2, 
      P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
     P1.DATAPROPUSA,
     P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     &apos;NC&apos;, 
     NC.DATADOC,
     NC. NRDOC,
     O.TERMEN,
     NC.SUBUNITATEA,
     M.SIMBOL,
     P1.OBS, 0, &apos;Preluata&apos;, 
     CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
     CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
     PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,NC.AN*12+NC.LUNA,O.Semnificatie)
   FROM
     CASHFLOW2 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     NC NC,
     NC1 NC1,
     NPART P,
     NMONEDE M
   WHERE
     CODCASHFLOW = RECID
     AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
     AND O.SEMNIFICATIE IN (1200, 1201)
     AND O.CODOBLIGPIF = P1.CODOBLIGPIF
     AND G.CODGENERAL  = O.CODGENERAL
     AND M.CODMONEDA   = G.MONEDA
     AND G.TIPDOC      = 35
     AND G.CODDOC      = NC1.CODNC1
     AND NC.CODNC      = NC1.CODNC
     AND P.CODPART     = O.CODPART
     AND COALESCE(P1.TIP,0) = 0
   UNION ALL
   SELECT
     P1.CODCASHFLOW2, 
      P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
     P1.DATAPROPUSA,
     P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     P.CODPART, 
     P.DEN_PART,
     T1.DOC,
     T1.DATADOC,
     T1. NRDOC,
     O.TERMEN,
     T.SUBUNITATEA,
     M.SIMBOL,
     P1.OBS, 0, &apos;Preluata&apos;, 
     CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
     CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END,
     PKG_LIST_BASE_UTILS.decode_iCont(O.Icont,O.CodPart,T.AN*12+T.LUNA,O.Semnificatie)
   FROM
     CASHFLOW2 P1,
     OBLIGPIF O
     LEFT JOIN CENTRECOST C ON O.CODCENTRU   = C.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     GENERAL G,
     TREZOR1 T1,
     TREZOR  T,
     NPART P,
     NMONEDE M
   WHERE
     CODCASHFLOW = RECID
     AND NVL(P1.CODOBLIGPIF, 0) &gt; 0 
     AND O.SEMNIFICATIE IN (310,600)
     AND O.CODOBLIGPIF = P1.CODOBLIGPIF
     AND G.CODGENERAL  = O.CODGENERAL
     AND M.CODMONEDA   = G.MONEDA
     AND G.TIPDOC      IN (29, 30, 31, 33)
     AND G.CODDOC      = T1.CODTREZOR1
     AND T.CODTREZOR   = T1.CODTREZOR
     AND P.CODPART     = O.CODPART
     AND COALESCE(P1.TIP,0) = 0
    ) ;   

  -- linii din operatiuni regulate
   INSERT INTO TMP_CASHFLOW2 
   (CODCASHFLOW2, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODOP1, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    OBS, TIP, TIPSTR
   )
   (
   SELECT
    P1.CODCASHFLOW2, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODOP1, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     NULL, 
     SUBSTR(O.OBS, 1, 50),
     NULL,
    NULL,
     NULL,
     O1.TERMEN,
    O.SUBUNITATEA,
    M.SIMBOL, P1.OBS, 0, &apos;Preluata&apos;
   FROM
     CASHFLOW2 P1,
     OPREG O,
     OPREG1 O1,
     NMONEDE M
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODOP1, 0) &lt;&gt; 0 
    AND P1.CODOP1     = O1.CODOP1
    AND O1.CODOP      = O.CODOP
    AND M.CODMONEDA   = NVL(O.CODMONEDA, 0)
    AND COALESCE(P1.TIP,0) = 0
   ) ;   

-- linii din contracte
   INSERT INTO TMP_CASHFLOW2 
   (CODCASHFLOW2, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODCONTRACT2, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    OBS, TIP, TIPSTR, 
    DENCENTRUCOST, 
    DENNODANALIZA
   )
   (
   SELECT
    P1.CODCASHFLOW2, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODCONTRACT2, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     C.PARTENER,
     P.DEN_PART,
     &apos;Contr.Abon&apos;,
     C.DATADOC,
    C.NRDOC,
     C2.DATA,
    C.SUBUNITATEA,
    M.SIMBOL,
    P1.OBS, 0, &apos;Preluata&apos;, 
    CASE WHEN CEN.CODCENTRU &gt; 0 THEN CEN.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END
   FROM
     CASHFLOW2 P1,
     CONTRACT C,
     CONTRACT2 C2,
     NMONEDE M,
     NPART P, 
     OBLIGPIF O
     LEFT JOIN CENTRECOST CEN ON O.CODCENTRU   = CEN.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODCONTRACT2, 0) &lt;&gt; 0 
    AND P1.CODCONTRACT2 = C2.CODCONTRACT2
    AND C2.CODCONTRACT = C.CODCONTRACT
    AND M.CODMONEDA   = NVL(C.MONEDA, 0)
    AND P.CODPART = C.PARTENER
    AND O.CODOBLIGPIF = P1.CODOBLIGPIF
    AND COALESCE(P1.TIP,0) = 0
   ) ;   

   INSERT INTO TMP_CASHFLOW2 
   (CODCASHFLOW2, 
    CODOBLIGPIF,
     VALOARE, 
     REST, 
     RESTCONV,
    DATAPROPUSA,
    CODNCREDIT, 
     CODMONEDA,
     INDEXLOCAL,
     CODPART, 
     DENPART,
     DOC,
    DATADOC,
     NRDOC,
     TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    OBS, TIP, TIPSTR, 
    DENCENTRUCOST, 
    DENNODANALIZA
   )
   (
   SELECT
    P1.CODCASHFLOW2, 
    P1.CODOBLIGPIF,
     P1.VALOARE, 
     P1.REST, 
     P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODNCREDIT, 
     P1.CODMONEDA,
     P1.INDEXLOCAL,
     NC.CODPART,
     P.DEN_PART,
     &apos;Nota credit&apos;,
     NULL,
    NULL,
     NC.DATASTOP,
    NC.SUBUNITATEA,
    M.SIMBOL,
    P1.OBS, 0, &apos;Preluata&apos;, 
    CASE WHEN CEN.CODCENTRU &gt; 0 THEN CEN.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END
   FROM
     CASHFLOW2 P1
     LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF
     LEFT JOIN CENTRECOST CEN ON O.CODCENTRU = CEN.CODCENTRU
     LEFT JOIN ANALIZANOD N ON O.CODANALIZANOD = N.CODANALIZANOD,
     NOTECREDIT NC
     LEFT  OUTER JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2 
     LEFT  JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT 
     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0),
     NPART P
   WHERE
    CODCASHFLOW = RECID
    AND NVL(P1.CODNCREDIT, 0) &lt;&gt; 0 
    AND P1.CODNCREDIT = NC.CODNCREDIT
    AND P.CODPART = NC.CODPART
    AND COALESCE(P1.TIP,0) = 0
   ) ;   

   INSERT INTO TMP_CASHFLOW2 
   (CODCASHFLOW2, 
    CODOBLIGPIF,
    VALOARE, 
    REST, 
    RESTCONV,
    DATAPROPUSA,
    CODNCREDIT, 
    CODMONEDA,
    INDEXLOCAL,
    CODPART, 
    DENPART,
    DOC,
    DATADOC,
    NRDOC,
    TERMEN,
    SUBUNITATEA,
    SIMBOLMONEDA,
    OBS, 
    TIP, TIPSTR, 
    DENCENTRUCOST, 
    DENNODANALIZA
   )
   (
   SELECT
    P1.CODCASHFLOW2, 
    P1.CODOBLIGPIF,
    P1.VALOARE, 
    P1.REST, 
    P1.RESTCONV,
    P1.DATAPROPUSA,
    P1.CODNCREDIT, 
    P1.CODMONEDA,
    P1.INDEXLOCAL,
    P1.CODPART,
    P.DEN_PART,
    P1.DOC,
    P1.DATADOC,
    P1.NRDOC,
    P1.TERMEN,
    0,
    M.SIMBOL,
    P1.OBS, 1, &apos;Manuala&apos;,
    CASE WHEN C.CODCENTRU &gt; 0 THEN C.DENUMIRE END, 
    CASE WHEN N.CODANALIZANOD &gt; 0 THEN N.DENNOD END    
   FROM
     CASHFLOW2 P1
     LEFT JOIN OBLIGPIF O ON P1.CODOBLIGPIF = O.CODOBLIGPIF
     LEFT JOIN CENTRECOST C ON C.CODCENTRU = O.CODCENTRU
     LEFT JOIN ANALIZANOD N ON N.CODANALIZANOD = O.CODANALIZANOD
     LEFT JOIN NMONEDE M ON M.CODMONEDA = P1.CODMONEDA
     LEFT JOIN NPART P ON P.CODPART = P1.CODPART
   WHERE
    CODCASHFLOW = RECID
    AND P1.TIP = 1
   ) ;

   INSERT INTO TMP_CURSCASHFLOW(CODCURS, CODCASHFLOW, CODMONEDA, CURS, SIMBOL)
   SELECT CC.CODCURS, CC.CODCASHFLOW, CC.CODMONEDA, CC.CURS,M.SIMBOL
   FROM 
     CURSCASHFLOW CC,
     NMONEDE M
   WHERE
     CC.CODCASHFLOW = RECID
     AND M.CODMONEDA = CC.CODMONEDA;  

   INSERT INTO TMP_CRONOCASHFLOW(CODCRONO, CODCASHFLOW, DATA, SOLD, INCASARI, PLATI, SOLDFINAL, DATAS)
   SELECT CODCRONO, CODCASHFLOW, DATA, SOLD, INCASARI, PLATI, SOLDFINAL, to_char(DATA, &apos;DD.MM.YYYY&apos;)
   FROM 
     CRONOCASHFLOW 
   WHERE
     CODCASHFLOW = RECID;

   INSERT INTO TMP_SOLDCASHFLOW(CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, SOLDCONV, SIMBOLBANCA, NRCONT, SIMBOLMONEDA) 
   SELECT
    SC.CODSOLD, 
    SC.CODCASHFLOW, SC.CODBANKCONT, SC.SOLD, SC.SOLDCONV, BK.SIMBOL, BC.NRCONT, M.SIMBOL 
   FROM 
     SOLDCASHFLOW SC,
     NBANKCONT BC,
     NBANK BK,
     NMONEDE M
   WHERE
     CODCASHFLOW = RECID
     AND BC.CODBANKCONT = SC.CODBANKCONT
     AND BK.CODBANK = BC.CODBANK
     AND M.CODMONEDA = BC.CODMONEDA;

   COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN
    SELECT  CODCASHFLOW INTO RECID FROM TMP_CASHFLOW;
 
    UPDATE CASHFLOW P
    SET
     (  DATA, 
        CODBANKCONT, 
        VALOARE, 
        VALOAREDEREPARTIZAT,
        APROBAT,
        ZILE,
        CODMONEDA,
        CARNETDOC, 
        NRDOC,
        AN, 
        LUNA
      )
      = (SELECT 
           DATA, 
           CODBANKCONT, 
           VALOARE, 
           VALOAREDEREPARTIZAT,
           APROBAT,
           ZILE,
           CODMONEDA,
           CARNETDOC, 
           NRDOC,
           AN, 
           LUNA
       FROM
         TMP_CASHFLOW TP
       )
    WHERE
      P.CODCASHFLOW = RECID;
      
   DELETE CASHFLOW1 P1
   WHERE
     CODCASHFLOW = RECID
     AND NOT EXISTS (SELECT CODCASHFLOW1 FROM TMP_CASHFLOW1 WHERE CODCASHFLOW1 = P1.CODCASHFLOW1);

   FOR V_REC IN (SELECT * FROM TMP_CASHFLOW1)
   LOOP
     IF V_REC.CODCASHFLOW1 &lt; 0 THEN
         INSERT INTO CASHFLOW1(CODCASHFLOW1, CODCASHFLOW, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA, CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA, INDEXLOCAL, 
                               DOC, NRDOC, DATADOC, TERMEN, CODPART, TIP, OBS)
         VALUES (SEQ_CASHFLOW1_CODCASHFLOW1.NEXTVAL, RECID, V_REC.CODOBLIGPIF, V_REC.VALOARE, V_REC.REST, V_REC.RESTCONV, V_REC.DATAPROPUSA,V_REC.CODOP1, V_REC.CODCONTRACT2, V_REC.CODNCREDIT, 
                 V_REC.CODMONEDA, V_REC.INDEXLOCAL,V_REC.DOC, V_REC.NRDOC, V_REC.DATADOC,
                 V_REC.TERMEN, V_REC.CODPART, V_REC.TIP, V_REC.OBS);
     ELSE
       UPDATE CASHFLOW1
       SET
         VALOARE     = V_REC.VALOARE,
         REST        = V_REC.REST,
         RESTCONV    = V_REC.RESTCONV,
         DATAPROPUSA = V_REC.DATAPROPUSA, 
         CODOP1      = V_REC.CODOP1,
         CODCONTRACT2= V_REC.CODCONTRACT2, 
         CODNCREDIT  = V_REC.CODNCREDIT,
         CODMONEDA   = V_REC.CODMONEDA,
         INDEXLOCAL  = V_REC.INDEXLOCAL,
         NRDOC       = V_REC.NRDOC,
         DATADOC     = V_REC.DATADOC,
         DOC         = V_REC.DOC,
         CODPART     = V_REC.CODPART,
         TERMEN      = V_REC.TERMEN,
         OBS         = V_REC.OBS,
         TIP         = V_REC.TIP
       WHERE
         CODCASHFLOW1 = V_REC.CODCASHFLOW1;
     END IF;
   END LOOP;   

   DELETE CASHFLOW2 P1
   WHERE
     CODCASHFLOW = RECID
     AND NOT EXISTS (SELECT CODCASHFLOW2 FROM TMP_CASHFLOW2 WHERE CODCASHFLOW2 = P1.CODCASHFLOW2);

   FOR V_REC IN (SELECT * FROM TMP_CASHFLOW2)
   LOOP
     IF V_REC.CODCASHFLOW2 &lt; 0 THEN
       INSERT INTO CASHFLOW2(CODCASHFLOW2, CODCASHFLOW, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA, CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA, INDEXLOCAL, DOC, NRDOC, DATADOC, TERMEN, CODPART, OBS, TIP)
       VALUES (SEQ_CASHFLOW2_CODCASHFLOW2.NEXTVAL, RECID, V_REC.CODOBLIGPIF, V_REC.VALOARE, V_REC.REST, V_REC.RESTCONV, V_REC.DATAPROPUSA, V_REC.CODOP1, V_REC.CODCONTRACT2, V_REC.CODNCREDIT, V_REC.CODMONEDA, V_REC.INDEXLOCAL,
               V_REC.DOC, V_REC.NRDOC, V_REC.DATADOC, V_REC.TERMEN, V_REC.CODPART, V_REC.OBS, V_REC.TIP);
     ELSE
       UPDATE CASHFLOW2
       SET
         VALOARE     = V_REC.VALOARE,
         REST        = V_REC.REST,
         RESTCONV    = V_REC.RESTCONV,
         DATAPROPUSA = V_REC.DATAPROPUSA, 
         CODOP1      = V_REC.CODOP1, 
         CODCONTRACT2= V_REC.CODCONTRACT2, 
         CODNCREDIT  = V_REC.CODNCREDIT,  
         CODMONEDA   = V_REC.CODMONEDA,
         INDEXLOCAL  = V_REC.INDEXLOCAL,
         DOC         = V_REC.DOC,
         NRDOC       = V_REC.NRDOC,
         DATADOC     = V_REC.DATADOC,
         TERMEN      = V_REC.TERMEN,
         CODPART     = V_REC.CODPART,
         OBS         = V_REC.OBS,
         TIP         = V_REC.TIP
       WHERE
        CODCASHFLOW2 = V_REC.CODCASHFLOW2;
     END IF;
   END LOOP;   

   FOR V_REC IN (SELECT * FROM TMP_CURSCASHFLOW)
   LOOP
     IF V_REC.CODCURS &lt; 0 THEN
       INSERT INTO CURSCASHFLOW (CODCURS, CODCASHFLOW, CODMONEDA, CURS)
       VALUES (SEQ_CURSCASHFLOW_CODCURS.NEXTVAL, RECID, V_REC.CODMONEDA, V_REC.CURS);
     ELSE
       UPDATE  CURSCASHFLOW
       SET
         CODMONEDA = V_REC.CODMONEDA,
         CURS      = V_REC.CURS
       WHERE
         CODCURS = V_REC.CODCURS; 
     END IF;
   END LOOP;
   
   DELETE SOLDCASHFLOW SC
   WHERE
     CODCASHFLOW = RECID
     AND NOT EXISTS (SELECT CODSOLD FROM TMP_SOLDCASHFLOW WHERE CODSOLD = SC.CODSOLD);

   FOR V_REC IN (SELECT * FROM TMP_SOLDCASHFLOW)
   LOOP
     IF V_REC.CODSOLD &lt; 0 THEN
       INSERT INTO SOLDCASHFLOW(CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, SOLDCONV)
       VALUES (SEQ_SOLDCASHFLOW_CODSOLD.NEXTVAL, RECID, V_REC.CODBANKCONT, V_REC.SOLD, V_REC.SOLDCONV);
     ELSE
       UPDATE SOLDCASHFLOW
       SET
        CODBANKCONT = V_REC.CODBANKCONT, 
        SOLD        = V_REC.SOLD, 
        SOLDCONV    = V_REC.SOLDCONV
       WHERE
        CODSOLD = V_REC.CODSOLD;
     END IF;
   END LOOP;   

   DELETE CRONOCASHFLOW SC
   WHERE
     CODCASHFLOW = RECID
     AND NOT EXISTS (SELECT CODCRONO FROM TMP_CRONOCASHFLOW WHERE CODCRONO = SC.CODCRONO);

   FOR V_REC IN (SELECT * FROM TMP_CRONOCASHFLOW)
   LOOP
     IF V_REC.CODCRONO &lt; 0 THEN
       INSERT INTO CRONOCASHFLOW(CODCRONO, CODCASHFLOW, DATA, SOLD, INCASARI, PLATI, SOLDFINAL)
       VALUES (SEQ_CRONOCASHFLOW_CODCRONO.NEXTVAL, RECID, V_REC.DATA, V_REC.SOLD, V_REC.INCASARI, V_REC.PLATI, V_REC.SOLDFINAL);
     ELSE
       UPDATE CRONOCASHFLOW
       SET
         DATA      = V_REC.DATA, 
         SOLD      = V_REC.SOLD, 
         INCASARI  = V_REC.INCASARI, 
         PLATI     = V_REC.PLATI, 
         SOLDFINAL = V_REC.SOLDFINAL
       WHERE
        CODCRONO = V_REC.CODCRONO;
     END IF;
   END LOOP;   
  ELSE  
    SELECT SEQ_CASHFLOW_CODCASHFLOW.Nextval INTO RecID From DUAL;

    INSERT INTO CASHFLOW(CODCASHFLOW, DATA, CODBANKCONT, VALOARE, CARNETDOC, NRDOC,
                         AN, LUNA, SUBUNITATEA, VALOAREDEREPARTIZAT, APROBAT, ZILE, CODMONEDA)
    SELECT RECID, DATA, CODBANKCONT, VALOARE, CARNETDOC, NRDOC,
           AN, LUNA, SUBUNITATEA, VALOAREDEREPARTIZAT, APROBAT, ZILE, CODMONEDA 
    FROM TMP_CASHFLOW;

    INSERT INTO CASHFLOW1(CODCASHFLOW1, CODCASHFLOW, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA, CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA, INDEXLOCAL,
                          DOC, NRDOC, DATADOC, TERMEN, CODPART, OBS, TIP)
    SELECT SEQ_CASHFLOW1_CODCASHFLOW1.NEXTVAL, RECID, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA, CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA,  INDEXLOCAL,
           DOC, NRDOC, DATADOC, TERMEN, CODPART, OBS, TIP
    FROM TMP_CASHFLOW1;

    INSERT INTO CASHFLOW2(CODCASHFLOW2, CODCASHFLOW, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA, CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA, INDEXLOCAL,
                          DOC, NRDOC, DATADOC, TERMEN, CODPART, OBS, TIP)
    SELECT SEQ_CASHFLOW2_CODCASHFLOW2.NEXTVAL, RECID, CODOBLIGPIF, VALOARE, REST, RESTCONV, DATAPROPUSA,CODOP1, CODCONTRACT2, CODNCREDIT, CODMONEDA,  INDEXLOCAL,
           DOC, NRDOC, DATADOC, TERMEN, CODPART, OBS, TIP
    FROM TMP_CASHFLOW2;

    INSERT INTO CURSCASHFLOW (CODCURS, CODCASHFLOW, CODMONEDA, CURS)
    SELECT SEQ_CURSCASHFLOW_CODCURS.NEXTVAL, RECID, CODMONEDA, CURS FROM TMP_CURSCASHFLOW;

    INSERT INTO SOLDCASHFLOW(CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, SOLDCONV)
    SELECT SEQ_SOLDCASHFLOW_CODSOLD.NEXTVAL, RECID,  CODBANKCONT, SOLD, SOLDCONV FROM TMP_SOLDCASHFLOW;

    INSERT INTO CRONOCASHFLOW(CODCRONO, CODCASHFLOW, DATA, SOLD, INCASARI, PLATI, SOLDFINAL)
    SELECT SEQ_CRONOCASHFLOW_CODCRONO.NEXTVAL, RECID,  DATA, SOLD, INCASARI, PLATI, SOLDFINAL FROM TMP_CRONOCASHFLOW;
  END IF;

  NotifyModif(Operation, RecId, &apos;CASHFLOW&apos;);
  COMMIT;
END;
end PKG_CASHFLOW; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CASTOT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4755256F072C5D433E0714032EC1FD2E57273759</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CASTOT is

PROCEDURE POST_TRANZACTIE
IS
BEGIN
  INSERT INTO CASTOT_UTILITY 
  SELECT * FROM TMP_CASTOT_UTILITY;

  COMMIT;  
END;    


PROCEDURE POST_TRANZACTIE_PREPAY
IS
BEGIN
  INSERT INTO CASTOT_PREPAY 
  SELECT * FROM TMP_CASTOT_PREPAY;

  COMMIT;  
END; 
end PKG_CASTOT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CATEGARTTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DE5264698B0DFACA0E976FB0DB815DCCBDA5E5A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_categartti IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCATEGARTTI INTO Tmp FROM CATEGARTTI WHERE CODCATEGARTTI = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM CATEGARTTI WHERE CODCATEGARTTI = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CATEGARTTI FIELDS(CODCATEGARTTI) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master CATEGARTTI
  INSERT INTO TMP_CATEGARTTI (codcategartti, denumire, simbolp, simboln, simbolp1, datastart, datastop)
  SELECT codcategartti, denumire, simbolp, simboln, simbolp1, datastart, datastop
  FROM CATEGARTTI
  WHERE codcategartti = RecId ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    -- Master CATEGARTTI
    UPDATE CATEGARTTI
    SET (codcategartti, denumire, simbolp, simboln, simbolp1, datastart, datastop) = (SELECT codcategartti, denumire, simbolp, simboln, simbolp1, datastart, datastop FROM TMP_CATEGARTTI)
    WHERE codcategartti = RecId ;
  ELSE  -- INSERT
    -- Master CATEGARTTI
    SELECT SEQ_CATEGARTTI_CODCATEGARTTI.NextVal INTO RecId FROM DUAL;
    INSERT INTO  CATEGARTTI (codcategartti, denumire, simbolp, simboln, simbolp1, datastart, datastop)
    SELECT RecId, denumire, simbolp, simboln, simbolp1, datastart, datastop
    FROM TMP_CATEGARTTI ;
  END IF;

  NotifyModif(Operation, RecId, &apos;CATEGARTTI&apos;);
  COMMIT;

END;

END PKG_CATEGARTTI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF7487995F030753F338785C2058600B401CE7CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CATEGCONST IS

  pGC_ALMin     NUMBER(5);
  pGC_ALMax     NUMBER(5);
  pGC_CodConst1 NUMBER(20);
  pGC_UserId    NUMBER(20);
  pGC_Result    VARCHAR2(300);

PROCEDURE CONST_TO_TMP_CONSTANTE(aSimbol in Varchar2) IS
S VARCHAR2(100);
AL number;
A number;
L number;
Cate Number;
begin
  S := UPPER(aSimbol);
  A := PKG_GLOBALS.GETANTEMP;
	L := PKG_GLOBALS.GETLUNATEMP;
	AL := A*12 + L;
  select Count(*) into Cate from TMP_CONSTANTE where AnLuna = AL and SIMBOL = S ;
  if Cate = 0 then
  	Insert into TMP_CONSTANTE (SIMBOL, VALOARE, ANLUNA) Values(S, NVL(pkg_categconst.GetValConstanta(S,A,L), &apos;0&apos;), AL);
  end if;
end;

FUNCTION VERIFICA_CONST_PE_GRUPUL(aDENGRUP IN VARCHAR2, aANLunaSTART in Number) RETURN NUMBER IS
  aCODCONSTLUNA NUMBER(20);
	MaxAnLuna number;
	aAnLuna number;
 BEGIN
   MaxAnLuna := 0;
	 FOR V_REC IN (SELECT * FROM TMP_UTILIZATOR WHERE UPPER(DENGRUP) = UPPER(aDENGRUP) ) --AND CODUTILIZATOR &lt;&gt; PKG_GLOBALS.USERID)
   LOOP
     FOR V_REC_CONSTLUNA IN (SELECT * FROM TMP_CONSTLUNAEXT)
     LOOP
       BEGIN
         SELECT
           Max(AnStart*12+LunaStart) INTO aAnLuna
         FROM
           CONSTLUNA
         WHERE
           CODCONST1     = V_REC_CONSTLUNA.CODCONST1
           AND USERID    = V_REC.CODUTILIZATOR;
        EXCEPTION WHEN OTHERS THEN aAnLuna := 0;
       END;

       IF aAnLuna &gt; 0 THEN
         if aAnLuna &gt; MaxAnLuna then
				   MaxAnLuna := aAnLuna;
				 end if;
       END IF;
     END LOOP;
   END LOOP;
	 Return MaxAnLuna;
 END;

PROCEDURE MULTIPLICA_CONST_PE_GRUPUL(aDENGRUP IN VARCHAR2) IS
  aCODCONSTLUNA NUMBER(20);
BEGIN
  FOR V_REC IN (
    SELECT *
    FROM TMP_UTILIZATOR
    WHERE UPPER(DENGRUP) = UPPER(aDENGRUP) AND CODUTILIZATOR &lt;&gt; PKG_GLOBALS.USERID
  ) LOOP
    FOR V_REC_CONSTLUNA IN (SELECT * FROM TMP_CONSTLUNAEXT)
    LOOP
      BEGIN
        SELECT CODCONSTLUNA INTO aCODCONSTLUNA
        FROM CONSTLUNA
        WHERE CODCONST1 = V_REC_CONSTLUNA.CODCONST1
          AND ANSTART   = V_REC_CONSTLUNA.ANSTART
          AND LUNASTART = V_REC_CONSTLUNA.LUNASTART
          AND USERID    = V_REC.CODUTILIZATOR;
      EXCEPTION
        WHEN OTHERS THEN aCODCONSTLUNA := 0;
      END;

      IF Coalesce(aCODCONSTLUNA, 0) = 0 THEN
        aCODCONSTLUNA := SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL;
        INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
        VALUES(aCODCONSTLUNA,  V_REC_CONSTLUNA.CODCONST1, V_REC_CONSTLUNA.ANSTART, V_REC_CONSTLUNA.LUNASTART, V_REC.CODUTILIZATOR);
      END IF;

      DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = aCODCONSTLUNA;
      DELETE FROM CONSTVAL    WHERE CODCONSTLUNA = aCODCONSTLUNA;

      FOR V_REC_COSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOSINI)
      LOOP
        INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
        VALUES(SEQ_CONSTVALPOS_COD.NEXTVAL, V_REC_COSTVALPOS.IDX, V_REC_COSTVALPOS.VALPOSIBILE, aCODCONSTLUNA);
      END LOOP;

      FOR V_REC_COSTVAL IN (SELECT * FROM TMP_CONSTVALINI)
      LOOP
        INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
        VALUES(V_REC_COSTVAL.VALOARE, aCODCONSTLUNA);
      END LOOP;
    END LOOP;
  END LOOP;
  PRC_AL_CHECK(&apos;CONSTLUNA&apos;);
END;

FUNCTION GETDENCONSTANTA(aSimbol in varchar2) return varchar2 IS
  DEN VARCHAR(100) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT DENUMIRE INTO DEN FROM CONST1 WHERE UPPER(SIMBOL) = UPPER(aSIMBOL);
  EXCEPTION
    WHEN OTHERS THEN DEN := &apos;&apos;;
  END;
  RETURN DEN;
END;

PROCEDURE SETTIPCATEGORIE(aTIP IN VARCHAR2) IS
BEGIN
  TIPCATEGORIE := aTIP;
END;

FUNCTION  GETTIPCATEGORIE RETURN VARCHAR2
IS
BEGIN
  RETURN TIPCATEGORIE;
END;

FUNCTION USERCORECT(aCODCONST1 IN NUMBER, aUserID IN NUMBER) RETURN NUMBER
IS
TIP VARCHAR(1) := &apos;G&apos;;
BEGIN
  BEGIN
    SELECT TIPCATEG INTO TIP FROM CATEGCONST WHERE CODCATEG = (SELECT CODCATEG FROM CONST1 WHERE CODCONST1 = aCODCONST1);
    EXCEPTION WHEN OTHERS THEN TIP := &apos;G&apos;;
  END;
  IF TIP = &apos;G&apos; THEN RETURN 1;
  ELSE BEGIN
   IF aUserID = PKG_GLOBALS.GETUSERID THEN RETURN 1;
                                      ELSE RETURN 0;
   END IF;

  END;
  END IF;
END;

FUNCTION GetCodConstBySimbol(aSimbol in varchar2) return number
IS
Cod Number(20) := 0;
BEGIN
  BEGIN
    SELECT CODCONST1 INTO COD FROM CONST1 WHERE UPPER(SIMBOL) = Upper(aSimbol);
     EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;
  RETURN COD;
END;

FUNCTION ESTECONTPENTRU(aCODCONT IN NUMBER, aSIMBOLCONST IN VARCHAR2) RETURN NUMBER IS
  aSIMBOL     VARCHAR2(200) := NULL;
  ESTE        NUMBER(10) := 0;
  anLunaLucru number(20);
BEGIN
  IF aCODCONT IS NULL
  THEN RETURN 0;
  END IF;

  BEGIN
    anLunaLucru := PKG_GLOBALS.GetANLUCRU * 12 + PKG_GLOBALS.GetLUNALUCRU;
    SELECT SIMBOL INTO aSIMBOL FROM NCONT WHERE CODCONT = aCODCONT;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF aSIMBOL IS NOT NULL THEN
    SELECT COUNT(*) INTO ESTE
    FROM (
      SELECT NC.SIMBOL
      FROM CONST1 C1
        LEFT JOIN CONSTLUNA CL ON CL.codconst1    = C1.codConst1
        LEFT JOIN CONSTVAL  CV ON cv.codconstluna = cL.codconstluna
        LEFT JOIN NCONT NC     ON NC.CODCONT      = NVL(CV.VALOARE, 0)
      WHERE UPPER(C1.SIMBOL) = UPPER(aSIMBOLCONST)
        AND anLunaLucru BETWEEN CL.ALSTART AND CL.ALSTOP
    )
    WHERE  INSTRB(aSIMBOL, SIMBOL, 1, 1) =  1 ;
  END IF;
  RETURN ESTE;
END;

FUNCTION ESTECONTPENTRU_ANLUNA(aCODCONT IN NUMBER, aSIMBOLCONST IN VARCHAR2, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER IS
  aSIMBOL VARCHAR2(200) := NULL;
  ESTE  NUMBER(10) := 0;
  anLunaLucru number(20);
BEGIN
 IF aCODCONT IS NULL THEN RETURN 0; END IF;

  BEGIN
    anLunaLucru := aAN * 12 + aLUNA;
    SELECT SIMBOL INTO aSIMBOL FROM NCONT WHERE CODCONT = aCODCONT;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF aSIMBOL IS NOT NULL THEN
    SELECT COUNT(*) INTO ESTE
    FROM (
      SELECT NC.SIMBOL
      FROM CONST1 C1
        LEFT JOIN CONSTLUNA CL ON CL.codconst1    = C1.codConst1
        LEFT JOIN CONSTVAL  CV ON cv.codconstluna = cL.codconstluna
        LEFT JOIN NCONT NC     ON NC.CODCONT      = NVL(CV.VALOARE, 0)
      WHERE UPPER(C1.simbol) = upper(aSIMBOLCONST)
        AND anLunaLucru BETWEEN CL.ALSTART AND CL.ALSTOP
    )
    WHERE  INSTRB(aSIMBOL, SIMBOL, 1, 1) =  1 ;
  END IF;
  RETURN ESTE;
END;

FUNCTION ESTEOBINV(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;COBINVENTAR&apos;);
END;

FUNCTION ESTESTOPAJ(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CSTOPAJSURSA&apos;);
END;

FUNCTION ESTEMIFIX(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CMIFIX&apos;);
END;

FUNCTION ESTEMIFIXLEASING(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CMIFIXLEASING&apos;);
END;

FUNCTION ESTEIMBUNATATIREMIFIX(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CIMBMIFIX&apos;);
END;

FUNCTION ESTEMFSaft(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CAMOMIFIXNC&apos;);
END;

FUNCTION ESTECUSTODIE(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CCUSTODIE&apos;);
END;

FUNCTION ESTEAMBALAJ(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CMATAMBALAJ&apos;);
END;

FUNCTION ESTEPRODUS(aCODCONT IN NUMBER) RETURN NUMBER IS
  este1 number;
  este2 number;
BEGIN
  este1 := ESTECONTPENTRU(aCODCONT, &apos;CSEMIFAB&apos;);
  este2 := ESTECONTPENTRU(aCODCONT, &apos;CPRODUSEANIMALE&apos;);
  if Este1 + Este2 &gt; 0
  then RETURN 1;
  else RETURN 0;
  end if;
END;

FUNCTION ESTEMATERIAL(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CMATERIALE&apos;);
END;

FUNCTION ESTECHELTAVANS(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CCONTCHELTAVANS&apos;);
END;

FUNCTION ESTEVENITAVANS(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;CCONTVENITAVANS&apos;);
END;

FUNCTION ESTEGRUPUSER(aCODCONT IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN ESTECONTPENTRU(aCODCONT, &apos;DOCGRUPUSERCURENT&apos;);
END;

FUNCTION ESTEUSERDINGRUP(aCODCONT IN NUMBER) RETURN NUMBER IS
Gr number(20);
BEGIN
  Select U.Codgruputilizator into GR from WinMAdmin.Utilizator U where U.Codutilizator = aCODCONT;
	RETURN ESTECONTPENTRU(Gr, &apos;DOCGRUPUSERCURENT&apos;);
END;


PROCEDURE UMPLE_TMP_CODCONT_CONST (
  ESTEOBINV             BOOLEAN DEFAULT FALSE,
  ESTEMIFIX             BOOLEAN DEFAULT FALSE,
  ESTEMIFIXLEASING      BOOLEAN DEFAULT FALSE,
  ESTEAMBALAJ           BOOLEAN DEFAULT FALSE,
  ESTEPRODUS            BOOLEAN DEFAULT FALSE,
  ESTEMATERIAL          BOOLEAN DEFAULT FALSE,
  ESTESTOPAJ            BOOLEAN DEFAULT FALSE,
  ESTECHELTAVANS        BOOLEAN DEFAULT FALSE,
  ESTECUSTODIE          BOOLEAN DEFAULT FALSE,
  ESTEIMBUNATATIREMIFIX BOOLEAN DEFAULT FALSE
) IS

  PROCEDURE ADD_FROM_CONST (pSimbol IN VARCHAR2, pCol IN VARCHAR2) IS
    sCont VARCHAR2(1000) := Trim(PKG_CATEGCONST.GetValConstanta(pSimbol, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU));
    sSql  CLOB;
  BEGIN
    IF sCont IS NOT NULL THEN
      sSQL := &apos;MERGE INTO TMP_CODCONT_CONST T&apos;||Chr(10)||
              &apos;USING (&apos;||Chr(10)||
              &apos;  WITH xrec (codcont) AS (&apos;||Chr(10)||
              &apos;    SELECT codcont FROM ncont WHERE codcont &lt;&gt; 0 AND codcont IN (&apos;||sCont||&apos;)&apos;||Chr(10)||
              &apos;    UNION ALL&apos;||Chr(10)||
              &apos;    SELECT c.codcont FROM xrec p, ncont c WHERE c.codparinte = p.codcont&apos;||Chr(10)||
              &apos;  )&apos;||Chr(10)||
              &apos;  SELECT codcont FROM xrec&apos;||Chr(10)||
              &apos;) R ON (R.codcont = t.codcont)&apos;||Chr(10)||
              &apos;WHEN MATCHED THEN UPDATE SET t.&apos;||pCol||&apos; = 1&apos;||Chr(10)||
              &apos;WHEN NOT MATCHED THEN INSERT (t.codcont, t.&apos;||pCol||&apos;) VALUES (r.codcont, 1)&apos;;

      EXECUTE IMMEDIATE sSQL;
    END IF;
  END;

BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CODCONT_CONST&apos;;

  BEGIN
    EXECUTE IMMEDIATE &apos;CREATE INDEX idx_tmp_codcont_const ON TMP_CODCONT_CONST (codcont)&apos;;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  IF ESTEOBINV             THEN ADD_FROM_CONST(&apos;COBINVENTAR&apos;,     &apos;ESTEOBINV&apos;);             END IF;
  IF ESTESTOPAJ            THEN ADD_FROM_CONST(&apos;CSTOPAJSURSA&apos;,    &apos;ESTESTOPAJ&apos;);            END IF;
  IF ESTEMIFIX             THEN ADD_FROM_CONST(&apos;CMIFIX&apos;,          &apos;ESTEMIFIX&apos;);             END IF;
  IF ESTEMIFIXLEASING      THEN ADD_FROM_CONST(&apos;CMIFIXLEASING&apos;,   &apos;ESTEMIFIXLEASING&apos;);      END IF;
  IF ESTEIMBUNATATIREMIFIX THEN ADD_FROM_CONST(&apos;CIMBMIFIX&apos;,       &apos;ESTEIMBUNATATIREMIFIX&apos;); END IF;
  IF ESTECUSTODIE          THEN ADD_FROM_CONST(&apos;CCUSTODIE&apos;,       &apos;ESTECUSTODIE&apos;);          END IF;
  IF ESTEAMBALAJ           THEN ADD_FROM_CONST(&apos;CMATAMBALAJ&apos;,     &apos;ESTEAMBALAJ&apos;);           END IF;
  IF ESTEPRODUS            THEN ADD_FROM_CONST(&apos;CSEMIFAB&apos;,        &apos;ESTEPRODUS&apos;);            END IF;
  IF ESTEPRODUS            THEN ADD_FROM_CONST(&apos;CPRODUSEANIMALE&apos;, &apos;ESTEPRODUS&apos;);            END IF;
  IF ESTEMATERIAL          THEN ADD_FROM_CONST(&apos;CMATERIALE&apos;,      &apos;ESTEMATERIAL&apos;);          END IF;
  IF ESTECHELTAVANS        THEN ADD_FROM_CONST(&apos;CCONTCHELTAVANS&apos;, &apos;ESTECHELTAVANS&apos;);        END IF;

  COMMIT;
END;


FUNCTION GetValConstantaInCursor (aSimbol IN VARCHAR2, An IN NUMBER, Luna IN NUMBER) RETURN Val_Ref_Cursor IS
  TmpCursor Val_Ref_Cursor;
  vAL       NUMBER;
BEGIN
  BEGIN
    SELECT Greatest(AnInitial*12+LunaInitiala,An*12+Luna) INTO vAL FROM firmaluni;
  EXCEPTION
    WHEN OTHERS THEN vAL := An*12+Luna;
  END;

  BEGIN
    OPEN  TmpCursor FOR
    SELECT CV.VALOARE
    FROM (
      SELECT CL.CODCONSTLUNA
      FROM CONST1 C1
        INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
        INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.SIMBOL) = UPPER(aSimbol)
        AND vAL BETWEEN CL.ALSTART AND CL.ALSTOP
        AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;G&apos; THEN 0 WHEN CT.TIPCATEG = &apos;U&apos; THEN PKG_GLOBALS.GETUSERID END
     ) C LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN TmpCursor;
END;

FUNCTION GetValConstanta(aSimbol IN VARCHAR2, An IN NUMBER, Luna IN NUMBER) RETURN VARCHAR2 IS
  vRes  VARCHAR2(32000) := &apos;&apos;; -- pot fi concatenari de liste de valori
  vAL   NUMBER;
BEGIN
  BEGIN
    SELECT Greatest(AnInitial*12+LunaInitiala,An*12+Luna) INTO vAL FROM firmaluni;
  EXCEPTION
    WHEN OTHERS THEN vAL := An*12+Luna;
  END;

  BEGIN
    SELECT LISTAGG(CV.VALOARE, &apos;,&apos;) WITHIN GROUP (ORDER BY CV.VALOARE) INTO vRes
    --SELECT STRING_AGG(CV.VALOARE) INTO vRes
    FROM (
      SELECT CL.CODCONSTLUNA
      FROM CONST1 C1
        INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
        INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = UPPER(aSimbol)
        AND vAL BETWEEN CL.ALSTART AND CL.ALSTOP
        AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;G&apos; THEN 0 WHEN CT.TIPCATEG = &apos;U&apos; THEN PKG_GLOBALS.GETUSERID END
     ) C LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN vRes;
END;


FUNCTION GetValConstantaExt(aSimbol IN VARCHAR2, An IN NUMBER, Luna IN NUMBER, aUserID IN NUMBER, aSkemaFirma IN VARCHAR2) RETURN VARCHAR2 IS
  vRes  VARCHAR2(32000) := &apos;&apos;; -- pot fi concatenari de liste de valori
  vAL   NUMBER;
  sir  VARCHAR2(32000);
BEGIN
  BEGIN
    VAL := An * 12 + Luna;
    sir :=  &apos;
    SELECT LISTAGG(CV.VALOARE, &apos;&apos;,&apos;&apos;) WITHIN GROUP (ORDER BY CV.VALOARE)
    FROM (
      SELECT CL.CODCONSTLUNA
      FROM &apos;|| askemaFirma || &apos;.CONST1 C1
        INNER JOIN &apos; || askemaFirma || &apos;.CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
        INNER JOIN &apos; || aSkemaFirma || &apos;.CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = UPPER(&apos;&apos;&apos; || aSimbol|| &apos;&apos;&apos;)
        AND &apos; || vAl ||&apos; BETWEEN CL.ALSTART AND CL.ALSTOP
        AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;&apos;G&apos;&apos; THEN 0 WHEN CT.TIPCATEG = &apos;&apos;U&apos;&apos; THEN &apos; || aUserID ||&apos; END
     ) C LEFT JOIN &apos; || aSkemaFirma ||&apos;.CONSTVAL CV ON cv.codconstluna = c.codconstluna&apos;;
    execute immediate sir into vRes;

    EXCEPTION WHEN OTHERS  THEN vRES := null;
  END;
  RETURN vRes;

END;



FUNCTION GetValConstByCode(aCode IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN VARCHAR2 IS
  vRes  VARCHAR2(300) := &apos;&apos;;
  vAL   NUMBER;
BEGIN
  BEGIN
    SELECT Greatest(AnInitial*12+LunaInitiala,An*12+Luna) INTO vAL FROM firmaluni;
  EXCEPTION
    WHEN OTHERS THEN vAL := An*12+Luna;
  END;

  BEGIN
    SELECT LISTAGG(CV.VALOARE, &apos;,&apos;) WITHIN GROUP (ORDER BY CV.VALOARE) INTO vRes
    --SELECT STRING_AGG(CV.VALOARE) INTO vRes
    FROM (
      SELECT CL.CODCONSTLUNA
      FROM CONST1 C1
        INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
        INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE C1.CodConst1 = aCode
        AND vAL BETWEEN CL.ALSTART AND CL.ALSTOP
        AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;G&apos; THEN 0 WHEN CT.TIPCATEG = &apos;U&apos; THEN PKG_GLOBALS.GETUSERID END
     ) C LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN vRes;
END;

PROCEDURE GetConst_Param(aSimbol IN VARCHAR2, aCodConst1 OUT NUMBER, aUserID OUT NUMBER) IS
  aTipCateg VARCHAR2(1);
BEGIN
  SELECT CodConst1, CT.TIPCATEG
  INTO  aCodConst1, aTipCateg
  FROM  CONST1 C1 INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
  WHERE UPPER(C1.simbol) = UPPER(aSimbol);

  aUserID := CASE WHEN aTipCateg = &apos;G&apos; THEN 0 WHEN aTipCateg = &apos;U&apos; THEN PKG_GLOBALS.GETUSERID END;
EXCEPTION
  WHEN OTHERS THEN
    aCodConst1 := -1;
    aUserID    := 0;
END;


FUNCTION  GetConst_Val_SiViitor  (aCodConst1 IN NUMBER, aUserID IN NUMBER, aAL IN NUMBER) RETURN VARCHAR2 IS
   rs    VARCHAR2(300);
BEGIN
    BEGIN
      SELECT LISTAGG(VALOARE, &apos;,&apos;) WITHIN GROUP (ORDER BY VALOARE) INTO rs
      FROM CONSTVAL
      WHERE codconstluna in (
           SELECT  CODCONSTLUNA
           FROM CONSTLUNA
           WHERE CodConst1 = aCodConst1
                 AND USERID    = aUserID
                 AND (ALStart &gt;=aAL or ALStop &gt;=aAL)
      );
    EXCEPTION
      WHEN OTHERS THEN rs := NULL;
    END;
    RETURN rs;
END;

FUNCTION  GetConst_Val  (aCodConst1 IN NUMBER, aUserID IN NUMBER, aAL IN NUMBER) RETURN VARCHAR2 IS
  vCCL  NUMBER(20);
BEGIN
  IF Coalesce(pGC_ALMin, -1) &gt; aAL OR Coalesce(pGC_ALMax, 99999) &lt; aAL OR Coalesce(pGC_CodConst1, -1) &lt;&gt; aCodConst1 OR Coalesce(pGC_UserID, -1) &lt;&gt; aUserID THEN
    pGC_ALMax     := aAL;
    pGC_ALMin     := aAL;
    pGC_CodConst1 := aCodConst1;
    pGC_UserID    := aUserID;

    BEGIN
      SELECT ALStart,   ALStop,    CODCONSTLUNA
      INTO   pGC_ALMin, pGC_ALMax, vCCL
      FROM CONSTLUNA
      WHERE CodConst1 = pGC_CodConst1
        AND USERID    = pGC_UserID
        AND aAL BETWEEN ALStart AND ALStop;

      SELECT LISTAGG(VALOARE, &apos;,&apos;) WITHIN GROUP (ORDER BY VALOARE) INTO pGC_Result
      FROM CONSTVAL
      WHERE codconstluna = vCCL;
    EXCEPTION
      WHEN OTHERS THEN pGC_Result := NULL;
    END;
  END IF;
  RETURN pGC_Result;
END;

PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
  tmp number(20);
BEGIN
  SELECT codcateg INTO tmp FROM categconst WHERE codcateg=recid FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD (RecId IN NUMBER)IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CATEGCONST WHERE CODCATEG=RECID;
  -- STEF 06.10.2014 -- Am anulat monitorizarea pe CATEGCONST fiindca se populeaza cu date in MARTOR (la utilizare WinMToolz) si verificare de structuri avem erori
  --NotifyModif(2, RecId, &apos;categconst&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_CATEGCONST FIELDS(codcateg) VALUES (0);
  COMMIT;
END;

FUNCTION GetValAfisByValoare(pSimbol IN VARCHAR2, pTIP IN NUMBER, pValoare IN VARCHAR2) RETURN VARCHAR2 IS
  vResult VARCHAR2(300);
BEGIN
  CASE pTIP
    WHEN  1 THEN SELECT N.SIMBOL                                     INTO vResult FROM NCONT N               WHERE N.CODCONT      = pValoare;
    WHEN  2 THEN SELECT N.SIMBOL                                     INTO vResult FROM NCONT N               WHERE N.CODCONT      = pValoare;
    WHEN  3 THEN SELECT SubStr(STRING_AGG(VALPOSIBILE),      1, 300) INTO vResult FROM (SELECT DISTINCT CVP.VALPOSIBILE FROM const1 c1 LEFT JOIN constluna cl on cl.codconst1 = c1.codconst1 LEFT JOIN constvalpos cvp on cvp.codconstluna = cl.codconstluna and cvp.idx = pValoare WHERE c1.simbol = pSimbol AND pkg_globals.AnLunaLucru BETWEEN cl.alstart AND cl.alstop) subs;
    WHEN  5 THEN SELECT Coalesce(T.DEN_TVA, &apos;&apos;)                      INTO vResult FROM NTVA T                WHERE T.CODTVA       = pValoare;
    WHEN  6 THEN SELECT B.SIMBOL || &apos;/&apos; || BC.NRCONT                 INTO vResult FROM NBANKCONT BC, NBANK B WHERE BC.CODBANKCONT = pValoare AND B.CODBANK = BC.CODBANK;
    WHEN  7 THEN SELECT BC.NRCONT                                    INTO vResult FROM NBANKCONT BC          WHERE BC.CODBANKCONT = pValoare;
    WHEN  9 THEN SELECT DEN_IOART                                    INTO vResult FROM IOART                 WHERE CODIOART       = pValoare;
    WHEN 10 THEN SELECT N.DENUMIRE                                   INTO vResult FROM NBANK N               WHERE N.CODBANK      = pValoare;
    WHEN 11 THEN SELECT DEN_MONEDA                                   INTO vResult FROM nmonede               WHERE CODMONEDA      = pValoare;
    WHEN 12 THEN vResult := pValoare;                       
    WHEN 13 THEN SELECT Coalesce(DEN_CATPRET, &apos;&apos;)                    INTO vResult FROM NCATPRET C            WHERE C.CODCATPRET   = pValoare;
    WHEN 17 THEN vResult := pValoare;
    WHEN 20 THEN SELECT SubStr(STRING_AGG(SIMBOL),           1, 300) INTO vResult FROM NCONT NC              WHERE NC.CODCONT     IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 22 THEN SELECT PKG_SELECTARTICOLE.GETDENOBIECTEXT(pValoare) INTO vResult FROM dual;
    WHEN 25 THEN SELECT SubStr(STRING_AGG(DENCRITERIU),      1, 300) INTO vResult FROM CRITERIIDISC          WHERE CODCRITERIU    IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 30 THEN vResult := pValoare;
    WHEN 40 THEN vResult := pValoare;
    WHEN 41 THEN SELECT SubStr(STRING_AGG(SIMBOL),           1, 300) INTO vResult FROM NMONEDE M             WHERE M.CODMONEDA    IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 42 THEN SELECT DEN_GEST                                     INTO vResult FROM NGEST                 WHERE CODGEST        = pValoare;
    WHEN 43 THEN SELECT SubStr(STRING_AGG(DENUMIRE),         1, 300) INTO vResult FROM NARTOBJ               WHERE CODOBIECT      IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 44 THEN vResult := pValoare;
    WHEN 45 THEN SELECT DENUMIRE                                     INTO vResult FROM RESTAURANTE           WHERE CODRESTAURANT  = pValoare;
    WHEN 46 THEN SELECT DENUMIRE                                     INTO vResult FROM NCASEMARCAT           WHERE CODCASEMARCAT  = pValoare;
    WHEN 47 THEN SELECT DENUMIRE                                     INTO vResult FROM POSTRETAIL            WHERE COD            = pValoare ;
    WHEN 48 THEN SELECT DEN_UM                                       INTO vResult FROM NUM                   WHERE CODUM          = pValoare;
    WHEN 49 THEN vResult := pValoare;                 
    WHEN 50 THEN SELECT DENUMIRE                                     INTO vResult FROM NATRIB                WHERE CODATRIBUT     = pValoare;
    WHEN 51 THEN SELECT DEN_IOPART                                   INTO vResult FROM IOPART                WHERE CODIOPART      = pValoare;
    WHEN 52 THEN SELECT DENLIMBA                                     INTO vResult FROM NLIMBA                WHERE CODLIMBA       = pValoare;
    WHEN 53 THEN SELECT SIMBOL                                       INTO vResult FROM MFCLASIF              WHERE CODCLASIF      = pValoare;
    WHEN 54 THEN SELECT SubStr(STRING_AGG(DENUMIRE),         1, 300) INTO vResult FROM NATRIB                WHERE CODATRIBUT     IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 55 THEN SELECT SubStr(STRING_AGG(USERNAME),         1, 300) INTO vResult FROM TMP_UTILIZATOR        WHERE CODUTILIZATOR  IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 56 THEN SELECT Coalesce(DEN_CLASEP, &apos;&apos;)                     INTO vResult FROM NCLASEP C             WHERE C.CODCLASEP    = pValoare;
    WHEN 57 THEN SELECT Coalesce(DENUMIRE, &apos;&apos;)                       INTO vResult FROM NLOCATII L            WHERE L.CODLOCATIE   = pValoare;
    WHEN 58 THEN  vResult := pValoare;             
    WHEN 59 THEN SELECT DEN_TAXA                                     INTO vResult FROM NTAXE                 WHERE CODTAXA        = pValoare;
    WHEN 60 THEN SELECT DENUMIRE                                     INTO vResult FROM NOPER                 WHERE CODOP          = pValoare;
    WHEN 61 THEN SELECT DENUMIRE                                     INTO vResult FROM TARIFEMAN             WHERE CODTARIF       = pValoare;
    WHEN 62 THEN SELECT SubStr(STRING_AGG(DEN_GEST),         1, 300) INTO vResult FROM NGEST G               WHERE G.CODGEST      IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 63 THEN SELECT SubStr(STRING_AGG(DEN_IOART),        1, 300) INTO vResult FROM IOART G               WHERE G.CODIOART     IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 64 THEN SELECT SubStr(STRING_AGG(DENUMIRE),         1, 300) INTO vResult FROM POSTRETAIL G          WHERE G.COD          IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 65 THEN SELECT L.Name                                       INTO vResult FROM WINMADMIN.LISTS L     WHERE L.CODLISTS     = pValoare;
    WHEN 66 THEN SELECT SubStr(STRING_AGG(DEN_CLASEA),       1, 300) INTO vResult FROM NCLASEA CLS           WHERE CLS.CODCLASEA  IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 67 THEN  vResult := pValoare;
    WHEN 68 THEN SELECT SubStr(STRING_AGG(DENUMIRE),         1, 300) INTO vResult FROM TIPCHELT T            WHERE T.CODTIPCHELT  IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 69 THEN SELECT SubStr(STRING_AGG(DEN_ANALIZA),      1, 300) INTO vResult FROM ANALIZA T             WHERE T.CODANALIZA   IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 70 THEN SELECT SubStr(STRING_AGG(DEN_CARSUPART),    1, 300) INTO vResult FROM NCARSUPART T          WHERE T.CODCARSUPART IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 71 THEN SELECT SubStr(STRING_AGG(T.DENGRUPUSER),    1, 300) INTO vResult FROM WINMADMIN.GRUPUSER T  WHERE T.CODGRUPUSER  IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 72 THEN vResult := pValoare;
    WHEN 74 THEN SELECT SubStr(STRING_AGG(DEN_SUBUNIT),      1, 300) INTO vResult FROM NSUBUNIT              WHERE CODSUBUNIT     IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 75 THEN SELECT NumePrenume(Nume, Prenume)                   INTO vResult FROM NPERS                 WHERE CODPERS        = pValoare;
    WHEN 76 THEN SELECT SubStr(STRING_AGG(DEN_PART),         1, 300) INTO vResult FROM NPART PART            WHERE PART.CODPART   IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 77 THEN SELECT SubStr(Denumire,                     1, 300) INTO vResult FROM SERVFACT S            WHERE S.CODSERVFACT  = pValoare;
    WHEN 78 THEN SELECT SubStr(STRING_AGG(DEN_CLASEAS),      1, 300) INTO vResult FROM NCLASEAS CLS          WHERE CLS.CODCLASEAS IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);
    WHEN 79 THEN SELECT DEN_EFCUSTOM                                 INTO vResult FROM EFCUSTOM              WHERE CODEFCUSTOM    = pValoare;
    WHEN 80 THEN vResult := pValoare;
    WHEN 82 THEN SELECT SubStr(STRING_AGG(DEN_CLASEAS),      1, 300) INTO vResult FROM NCLASEAS CLS          WHERE CLS.CODCLASEAS IN (Select regexp_substr(pValoare,&apos;[^,]+&apos;, 1,level) from dual connect by regexp_substr(pValoare,&apos;[^,]+&apos;, 1, level) is not null);    
    WHEN 83 THEN SELECT DENUMIRE                                     INTO vResult FROM TIPLUCRARISA          WHERE CODTIPLUCRARE  = pValoare;
    ELSE vResult := &apos; &apos;;
  END CASE;
  RETURN vResult;
END;

FUNCTION GetValAfis(pTIP IN NUMBER, pCodConstLuna IN NUMBER) RETURN VARCHAR2 IS
  vResult VARCHAR2(300);
BEGIN
  CASE pTIP
    WHEN  1 THEN SELECT N.SIMBOL                                    INTO vResult FROM NCONT N                      WHERE N.CODCONT      = (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN  2 THEN SELECT N.SIMBOL                                    INTO vResult FROM NCONT N                      WHERE N.CODCONT      = (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN  3 THEN SELECT SubStr(STRING_AGG(CVP.VALPOSIBILE), 1, 300) INTO vResult FROM CONSTVAL CV, CONSTVALPOS CVP WHERE CV.CODCONSTLUNA=  pCodConstLuna AND CVP.CODCONSTLUNA = CV.CODCONSTLUNA AND TO_CHAR(CVP.IDX, &apos;fm999999&apos;) = CV.VALOARE;  
    WHEN  5 THEN SELECT Coalesce(T.DEN_TVA, &apos;&apos;)                     INTO vResult FROM NTVA T                       WHERE T.CODTVA       =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN  6 THEN SELECT B.SIMBOL || &apos;/&apos; || BC.NRCONT                INTO vResult FROM NBANKCONT BC, NBANK B        WHERE BC.CODBANKCONT =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna) AND B.CODBANK = BC.CODBANK;
    WHEN  7 THEN SELECT BC.NRCONT                                   INTO vResult FROM NBANKCONT BC                 WHERE BC.CODBANKCONT =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN  9 THEN SELECT DEN_IOART                                   INTO vResult FROM IOART                        WHERE CODIOART       =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 10 THEN SELECT N.DENUMIRE                                  INTO vResult FROM NBANK N                      WHERE N.CODBANK      =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 11 THEN SELECT DEN_MONEDA                                  INTO vResult FROM nmonede                      WHERE CODMONEDA      =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 12 THEN SELECT valoare                                     INTO vResult FROM constval                     WHERE codconstluna   =  pCodConstLuna;
    WHEN 13 THEN SELECT Coalesce(DEN_CATPRET, &apos;&apos;)                   INTO vResult FROM NCATPRET C                   WHERE C.CODCATPRET   =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 17 THEN SELECT valoare                                     INTO vResult FROM constval                     WHERE codconstluna   =  pCodConstLuna;
    WHEN 20 THEN SELECT SubStr(STRING_AGG(SIMBOL),          1, 300) INTO vResult FROM NCONT NC                     WHERE NC.CODCONT     IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 22 THEN SELECT PKG_SELECTARTICOLE.GETDENOBIECTEXT(VALOARE) INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 25 THEN SELECT SubStr(STRING_AGG(DENCRITERIU),     1, 300) INTO vResult FROM CRITERIIDISC                 WHERE CODCRITERIU    IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 30 THEN SELECT VALOARE                                     INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 40 THEN SELECT VALOARE                                     INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 41 THEN SELECT SubStr(STRING_AGG(SIMBOL),          1, 300) INTO vResult FROM NMONEDE M                    WHERE M.CODMONEDA    IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 42 THEN SELECT DEN_GEST                                    INTO vResult FROM NGEST                        WHERE CODGEST        =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 43 THEN SELECT SubStr(STRING_AGG(DENUMIRE),        1, 300) INTO vResult FROM NARTOBJ                      WHERE CODOBIECT      IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 44 THEN SELECT valoare                                     INTO vResult FROM constval                     WHERE codconstluna   =  pCodConstLuna;
    WHEN 45 THEN SELECT DENUMIRE                                    INTO vResult FROM RESTAURANTE                  WHERE CODRESTAURANT  =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 46 THEN SELECT DENUMIRE                                    INTO vResult FROM NCASEMARCAT                  WHERE CODCASEMARCAT  =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 47 THEN SELECT DENUMIRE                                    INTO vResult FROM POSTRETAIL                   WHERE COD            =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 48 THEN SELECT DEN_UM                                      INTO vResult FROM NUM                          WHERE CODUM          =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 49 THEN SELECT VALOARE                                     INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 50 THEN SELECT DENUMIRE                                    INTO vResult FROM NATRIB                       WHERE CODATRIBUT     =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 51 THEN SELECT DEN_IOPART                                  INTO vResult FROM IOPART                       WHERE CODIOPART      =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 52 THEN SELECT DENLIMBA                                    INTO vResult FROM NLIMBA                       WHERE CODLIMBA       =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 53 THEN SELECT SIMBOL                                      INTO vResult FROM MFCLASIF                     WHERE CODCLASIF      =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 54 THEN SELECT SubStr(STRING_AGG(DENUMIRE),        1, 300) INTO vResult FROM NATRIB                       WHERE CODATRIBUT     IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 55 THEN SELECT SubStr(STRING_AGG(USERNAME),        1, 300) INTO vResult FROM TMP_UTILIZATOR               WHERE CODUTILIZATOR  IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 56 THEN SELECT Coalesce(DEN_CLASEP, &apos;&apos;)                    INTO vResult FROM NCLASEP C                    WHERE C.CODCLASEP    =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 57 THEN SELECT Coalesce(DENUMIRE, &apos;&apos;)                      INTO vResult FROM NLOCATII L                   WHERE L.CODLOCATIE   =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 58 THEN SELECT VALOARE                                     INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 59 THEN SELECT DEN_TAXA                                    INTO vResult FROM NTAXE                        WHERE CODTAXA        =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 60 THEN SELECT DENUMIRE                                    INTO vResult FROM NOPER                        WHERE CODOP          =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 61 THEN SELECT DENUMIRE                                    INTO vResult FROM TARIFEMAN                    WHERE CODTARIF       =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 62 THEN SELECT SubStr(STRING_AGG(DEN_GEST),        1, 300) INTO vResult FROM NGEST G                      WHERE G.CODGEST      IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 63 THEN SELECT SubStr(STRING_AGG(DEN_IOART),       1, 300) INTO vResult FROM IOART G                      WHERE G.CODIOART     IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 64 THEN SELECT SubStr(STRING_AGG(DENUMIRE),        1, 300) INTO vResult FROM POSTRETAIL G                 WHERE G.COD          IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 65 THEN SELECT L.Name                                      INTO vResult FROM WINMADMIN.LISTS L            WHERE CODLISTS       =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 66 THEN SELECT SubStr(STRING_AGG(DEN_CLASEA),      1, 300) INTO vResult FROM NCLASEA CLS                  WHERE CLS.CODCLASEA  IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 67 THEN SELECT VALOARE                                     INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 68 THEN SELECT SubStr(STRING_AGG(DENUMIRE),        1, 300) INTO vResult FROM TIPCHELT T                   WHERE T.CODTIPCHELT  IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 69 THEN SELECT SubStr(STRING_AGG(DEN_ANALIZA),     1, 300) INTO vResult FROM ANALIZA T                    WHERE T.CODANALIZA   IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 70 THEN SELECT SubStr(STRING_AGG(DEN_CARSUPART),   1, 300) INTO vResult FROM NCARSUPART T                 WHERE T.CODCARSUPART IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 71 THEN SELECT SubStr(STRING_AGG(T.DENGRUPUSER),   1, 300) INTO vResult FROM WINMADMIN.GRUPUSER T         WHERE T.CODGRUPUSER  IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 72 THEN SELECT SubStr(STRING_AGG(VALOARE),         1, 300) INTO vResult FROM CONSTVAL                     WHERE CODCONSTLUNA   =  pCodConstLuna;
    WHEN 74 THEN SELECT SubStr(STRING_AGG(DEN_SUBUNIT),     1, 300) INTO vResult FROM NSUBUNIT                     WHERE CODSUBUNIT     IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 75 THEN SELECT NumePrenume(Nume, Prenume)                  INTO vResult FROM NPERS                        WHERE CODPERS        =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 76 THEN SELECT SubStr(STRING_AGG(DEN_PART),        1, 300) INTO vResult FROM NPART PART                   WHERE PART.CODPART   IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 77 THEN SELECT SubStr(Denumire,                    1, 300) INTO vResult FROM SERVFACT S                   WHERE S.CODSERVFACT  =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 78 THEN SELECT SubStr(STRING_AGG(DEN_CLASEAS),     1, 300) INTO vResult FROM NCLASEAS CLS                 WHERE CLS.CODCLASEAS IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 79 THEN SELECT DEN_EFCUSTOM                                INTO vResult FROM EFCUSTOM                     WHERE CODEFCUSTOM    =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 80 THEN SELECT valoare                                     INTO vResult FROM constval                     WHERE codconstluna   =  pCodConstLuna;
    WHEN 81 THEN SELECT DENUMIRE                                    INTO vResult FROM DOCCARNETE                   WHERE CODCARNET     =  (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 82 THEN SELECT SubStr(STRING_AGG(DEN_CLASEAS),     1, 300) INTO vResult FROM NCLASEAS CLS                 WHERE CLS.CODCLASEAS IN (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    WHEN 83 THEN SELECT DENUMIRE                                    INTO vResult FROM TIPLUCRARISA                 WHERE CODTIPLUCRARE  = (SELECT VALOARE FROM CONSTVAL WHERE CODCONSTLUNA = pCodConstLuna);
    ELSE vResult := &apos; &apos;;
  END CASE;
  RETURN vResult;
END;

PROCEDURE SP_GOTORECORD (RecId IN NUMBER) IS
  aANSFARSIT   NUMBER(4);
  aLUNASFARSIT NUMBER(2);
  vUserId      NUMBER(20);
BEGIN
  --Master categconst
  INSERT INTO tmp_categconst(codcateg,denumire,indexlocal,tipcateg)
  SELECT codcateg,denumire,indexlocal,tipcateg
  FROM categconst
  WHERE codcateg=recid;

  SELECT CASE WHEN TIPCATEG = &apos;U&apos; THEN PKG_GLOBALS.USERID ELSE 0 END
  INTO   vUserId
  FROM TMP_CATEGCONST;

  --Detail const1
  INSERT INTO tmp_const1 (codconst1,codcateg,indexlocal,simbol,denumire,tip,descriere)
  SELECT codconst1,codcateg,indexlocal,simbol,denumire,tip,descriere
  FROM const1
  WHERE codcateg=recid;

  --Detail constluna
  FOR v_rec IN (
    --SELECT * FROM constluna WHERE codconst1 in (select codconst1 from tmp_const1) and UserCorect(CodConst1, UserID) = 1 )
    SELECT C1.TIP, CL.*
    FROM TMP_CONST1 C1 INNER JOIN CONSTLUNA  CL ON CL.CODCONST1 = C1.CODCONST1
    WHERE CL.USERID = vUserId
  ) LOOP
    INSERT INTO TMP_CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID, ALSTART, ALSTOP, VALAFIS)
    VALUES ( V_REC.CODCONSTLUNA, V_REC.CODCONST1, V_REC.ANSTART, V_REC.LUNASTART, V_REC.USERID, V_REC.ALSTART, V_REC.ALSTOP, pkg_categconst.GetValAfis(V_REC.TIP, V_REC.CODCONSTLUNA) );

    INSERT INTO TMP_CONSTVAL(VALOARE, CODCONSTLUNA)
    SELECT DISTINCT VALOARE,CODCONSTLUNA FROM CONSTVAL WHERE CODCONSTLUNA=V_REC.CODCONSTLUNA;

    INSERT INTO TMP_CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
    SELECT COD, IDX, VALPOSIBILE, CODCONSTLUNA FROM CONSTVALPOS WHERE CODCONSTLUNA=V_REC.CODCONSTLUNA;
  END LOOP;

  FOR VREC_CONST1 IN (
    SELECT CODCONST1 FROM TMP_CONST1
  ) LOOP
    aANSFARSIT   := 0;
    aLUNASFARSIT := 0;
    FOR V_REC IN (
      SELECT CODCONSTLUNA, ANSTART, LUNASTART
      FROM TMP_CONSTLUNA
      WHERE CODCONST1 = VREC_CONST1.CODCONST1
      ORDER BY ANSTART DESC, LUNASTART DESC
    ) LOOP
      IF (aANSFARSIT &lt;&gt; 0) AND (aLUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_CONSTLUNA
        SET ANSFARSIT   = aANSFARSIT,
            LUNASFARSIT = aLUNASFARSIT
         WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
      END IF;

      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
    END LOOP;
  END LOOP;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS (OPERATION IN NUMBER , RecId OUT NUMBER) IS
  TMP_COD   NUMBER(10);
  vUserId   NUMBER(20);
  vALLucru  NUMBER(5)   := PKG_GLOBALS.GetANLUCRU * 12 + PKG_GLOBALS.GetLUNALUCRU;
BEGIN
  IF OPERATION = 0 THEN --update
    SELECT CodCateg, CASE WHEN TIPCATEG = &apos;U&apos; THEN PKG_GLOBALS.USERID ELSE 0 END
    INTO   RecId,    vUserId
    FROM TMP_CATEGCONST;

    update const1 C1 set descriere = (Select T.descriere FROM tmp_const1 T WHERE T.CODCONST1 = C1.CODCONST1) WHERE CODCATEG = RECID;

    PRC_AL_REFRESH(&apos;TMP_CONSTLUNA&apos;, 0);
    -- CATEGCONST SI CONST1 SE ACTUALIZEAZA DOAR PRIN SERVICE
    -- Detail ConstLuna
    DELETE FROM CONSTVAL
    WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM CONST1 C1 INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1 WHERE C1.CODCATEG = RECID AND CL.USERID = vUserId);

    DELETE FROM CONSTVALPOS
    WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM CONST1 C1 INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1 WHERE C1.CODCATEG = RECID AND CL.USERID = vUserId);

    FOR V_REC IN (
      SELECT CL.CODCONSTLUNA
      FROM CONST1 C1 INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
      WHERE C1.CODCATEG = RECID
        AND CL.USERID = vUserId
        AND CODCONSTLUNA NOT IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA)
    ) LOOP
	    DELETE FROM CONSTLUNA WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
	  END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_CONSTLUNA) LOOP
      IF V_REC.CODCONSTLUNA &lt; 0 THEN
        SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO TMP_COD FROM DUAL;

        INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, UserID, ALSTART, ALSTOP)
        VALUES ( tmp_cod, v_rec.codconst1, v_rec.anstart, v_rec.lunastart, v_rec.UserID, v_rec.ALSTART, v_rec.ALSTOP);

        UPDATE TMP_CONSTVAL SET CODCONSTLUNA = TMP_COD WHERE CODCONSTLUNA = v_rec.CODCONSTLUNA;

        UPDATE TMP_CONSTVALPOS
        SET CODCONSTLUNA = TMP_COD,
            COD          = SEQ_CONSTVALPOS_COD.NEXTVAL
        WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
      ELSE
        UPDATE CONSTLUNA
        SET ALSTART = v_rec.ALSTART,
            ALSTOP  = v_rec.ALSTOP
        WHERE CODCONSTLUNA = v_rec.CODCONSTLUNA;
      END IF;
    END LOOP;

    INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
    SELECT VALOARE, CODCONSTLUNA
    FROM TMP_CONSTVAL;

    INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
    SELECT COD, IDX, VALPOSIBILE, CODCONSTLUNA
    FROM TMP_CONSTVALPOS;
  END IF;

  -- MODIFICARILE DE CONSTANTE POT DUCE LA RECALCULARI DE FLAGURI PE TEMPORARELE LUNARE (ex este mifix)
  -- DE ACEEA STERG LUNA_RECORDS_FLAGS;
  DELETE FROM LUNA_RECORDS_FLAGS;
  DELETE FROM TMP_CONTCHELTAVANS;

  INSERT INTO TMP_CONTCHELTAVANS
  SELECT CV.VALOARE
  FROM CONST1 C1
    LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
    LEFT JOIN CONSTVAL  CV ON cv.codconstluna = cL.codconstluna
  WHERE UPPER(C1.simbol) = &apos;CCONTCHELTAVANS&apos;
    AND vALLucru BETWEEN CL.ALSTART AND CL.ALSTOP;

  --STEF 06.10.2014 -- Am anulat monitorizarea pe CATEGCONST fiindca se populeaza cu date in MARTOR (la utilizare WinMToolz) si verificare de structuri avem erori
  --NotifyModif(Operation, RecId, &apos;categconst&apos;);
  PKG_GLOBALS.SETUSERDOC;
  COMMIT;
END;

PROCEDURE STERGE_CONSVAL_DUBLU IS
 PRAGMA AUTONOMOUS_TRANSACTION;

 vCOD  NUMBER(20);
 vVAL  VARCHAR2(300);
BEGIN
  FOR V_REC IN (
    SELECT CODCONSTLUNA, VALOARE, COUNT(1)
    FROM CONSTVAL
    GROUP BY CODCONSTLUNA, VALOARE
    HAVING COUNT(1) &gt; 1
  ) LOOP
    vCOD := V_REC.CODCONSTLUNA;
    vVAL := V_REC.VALOARE;
    DELETE FROM CONSTVAL WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA AND VALOARE = V_REC.VALOARE;
    INSERT INTO CONSTVAL(VALOARE,CODCONSTLUNA) VALUES (vVAL,vCOD);
  END LOOP;
  COMMIT;
END;

FUNCTION VERIFICA_CONST_PE_USERI RETURN NUMBER IS
  aCODCONSTLUNA NUMBER(20);
  MaxAnLuna number;
  aAnLuna number;
 BEGIN
   MaxAnLuna := 0;
   FOR V_REC IN (SELECT TC.CODUNIC AS CODUTILIZATOR FROM tmp_manevra TC )
   LOOP
     FOR V_REC_CONSTLUNA IN (SELECT * FROM TMP_CONSTLUNAEXT)
     LOOP
       BEGIN
         SELECT
           Max(AnStart*12+LunaStart) INTO aAnLuna
         FROM
           CONSTLUNA
         WHERE
           CODCONST1     = V_REC_CONSTLUNA.CODCONST1
           AND USERID    = V_REC.CODUTILIZATOR;
        EXCEPTION WHEN OTHERS THEN aAnLuna := 0;
       END;

       IF aAnLuna &gt; 0 THEN
         if aAnLuna &gt; MaxAnLuna then
           MaxAnLuna := aAnLuna;
         end if;
       END IF;
     END LOOP;
   END LOOP;
   Return MaxAnLuna;
 END;

PROCEDURE MULTIPLICA_CONST_PE_USERI IS
  aCODCONSTLUNA   NUMBER(20);
  codConstDirEFact    NUMBER(20);
  codConstDirETransp NUMBER(20);
  codConstDirSAFT     NUMBER(20);
  valConstDir             VARCHAR2(300);
  valConstDirNew      VARCHAR2(300);
  valConstDirOldStatus VARCHAR2(300);
  sePoateImporta      NUMBER(1);
  modifcStatusDecl    NUMBER(1);
  statusDeclFilenameNew VARCHAR2(250);
  nr                        NUMBER(5);
BEGIN
  codConstDirEFact     := GetCodConstBySimbol(&apos;EFactDirector&apos;);
  codConstDirETransp := GetCodConstBySimbol(&apos;ETranspDirector&apos;);
  codConstDirSAFT     := GetCodConstBySimbol(&apos;SAFTDirector&apos;);
  FOR V_REC IN (
    SELECT TC.CODUNIC AS CODUTILIZATOR, UPPER(ut.username) as USERNAME
    FROM tmp_manevra TC join winmadmin.utilizator ut on ut.codutilizator = tc.codunic
    WHERE TC.CODUNIC &lt;&gt; PKG_GLOBALS.USERID
  ) LOOP
    FOR V_REC_CONSTLUNA IN (SELECT * FROM TMP_CONSTLUNAEXT)
    LOOP
      sePoateImporta := 1;
      modifcStatusDecl := 0;
      BEGIN
        SELECT CODCONSTLUNA INTO aCODCONSTLUNA
        FROM CONSTLUNA
        WHERE CODCONST1 = V_REC_CONSTLUNA.CODCONST1
          AND ANSTART   = V_REC_CONSTLUNA.ANSTART
          AND LUNASTART = V_REC_CONSTLUNA.LUNASTART
          AND USERID    = V_REC.CODUTILIZATOR;
      EXCEPTION
        WHEN OTHERS THEN aCODCONSTLUNA := 0;
      END;
      -- verific daca sunt pe o constanta cu director lucru pt SPV (trebuie sa fie directoare diferite pt fiecare tip)
      IF (((codConstDirEFact &lt;&gt; 0) AND (codConstDirEFact = V_REC_CONSTLUNA.CODCONST1))
         OR ((codConstDirETransp &lt;&gt; 0) AND (codConstDirETransp = V_REC_CONSTLUNA.CODCONST1))
         OR ((codConstDirSAFT &lt;&gt; 0) AND (codConstDirSAFT = V_REC_CONSTLUNA.CODCONST1))) THEN
         BEGIN
            SELECT TCI.VALOARE INTO valConstDirNew
            FROM TMP_CONSTVALINI TCI
            WHERE TCI.CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
             IF (sePoateImporta = 1) and (codConstDirEFact &lt;&gt; 0)  and (V_REC_CONSTLUNA.CODCONST1 &lt;&gt; codConstDirEFact) THEN
                valConstDir := GetConst_Val_SiViitor(codConstDirEFact, V_REC.CODUTILIZATOR, V_REC_CONSTLUNA.ANSTART * 12 + V_REC_CONSTLUNA.LUNASTART);
                IF (valConstDir is not null) and (valConstDirNew is not null) AND  (InStr(valConstDir||&apos;,&apos;, valConstDirNew||&apos;,&apos;)&gt;0) THEN sePoateImporta := 0; END IF;
             END IF;
             IF (sePoateImporta = 1)  and (codConstDirETransp &lt;&gt; 0)  and (V_REC_CONSTLUNA.CODCONST1 &lt;&gt; codConstDirETransp) THEN
                valConstDir := GetConst_Val_SiViitor(codConstDirETransp, V_REC.CODUTILIZATOR, V_REC_CONSTLUNA.ANSTART * 12 + V_REC_CONSTLUNA.LUNASTART);
                if (valConstDir is not null) and (valConstDirNew is not null) and (InStr(valConstDir||&apos;,&apos;, valConstDirNew||&apos;,&apos;)&gt;0) then sePoateImporta := 0; END IF;
             END IF;
             IF (sePoateImporta = 1)  and (codConstDirSAFT &lt;&gt; 0)  and (V_REC_CONSTLUNA.CODCONST1 &lt;&gt; codConstDirSAFT) THEN
                valConstDir := GetConst_Val_SiViitor(codConstDirSAFT, V_REC.CODUTILIZATOR, V_REC_CONSTLUNA.ANSTART * 12 + V_REC_CONSTLUNA.LUNASTART);
                IF (valConstDir is not null) and (valConstDirNew is not null) AND  (InStr(valConstDir||&apos;,&apos;, valConstDirNew||&apos;,&apos;)&gt;0) THEN sePoateImporta := 0; END IF;
             END IF;
             IF (sePoateImporta = 1) and (codConstDirEFact = V_REC_CONSTLUNA.CODCONST1) THEN
                valConstDirOldStatus := GetConst_Val(codConstDirEFact, V_REC.CODUTILIZATOR, V_REC_CONSTLUNA.ANSTART * 12 + V_REC_CONSTLUNA.LUNASTART);
                IF (valConstDirOldStatus is not null)  THEN
                  valConstDirOldStatus := upper(valConstDirOldStatus);
                  modifcStatusDecl := 1;
                 END IF;
             END IF;
         EXCEPTION
            WHEN OTHERS THEN valConstDirNew := NULL;
         END;
      END IF;
      IF (sePoateImporta = 1) and (modifcStatusDecl = 1) and (valConstDirNew is not null) then
             IF (SubStr(valConstDirNew, -1) &lt;&gt; &apos;\&apos;) THEN
                valConstDirNew := valConstDirNew || &apos;\&apos;;
             END IF;
             update STATUSDECL SD
                    set Filename = valConstDirNew || SubStr(FILENAME, InStr(Upper(FILENAME), &apos;\&apos;||upper(PKG_GLOBALS.FIRMANAME)) + 1, 255)
            WHERE tipdoc in (1, 9, 19, 26)  and upper(username) = V_REC.USERNAME;
      END IF;
      IF (sePoateImporta = 1)  THEN
          IF Coalesce(aCODCONSTLUNA, 0) = 0 THEN
            aCODCONSTLUNA := SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL;
            INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
            VALUES(aCODCONSTLUNA,  V_REC_CONSTLUNA.CODCONST1, V_REC_CONSTLUNA.ANSTART, V_REC_CONSTLUNA.LUNASTART, V_REC.CODUTILIZATOR);
          END IF;

          DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = aCODCONSTLUNA;
          DELETE FROM CONSTVAL    WHERE CODCONSTLUNA = aCODCONSTLUNA;

          FOR V_REC_COSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOSINI)
          LOOP
            INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
            VALUES(SEQ_CONSTVALPOS_COD.NEXTVAL, V_REC_COSTVALPOS.IDX, V_REC_COSTVALPOS.VALPOSIBILE, aCODCONSTLUNA);
          END LOOP;

          FOR V_REC_COSTVAL IN (SELECT * FROM TMP_CONSTVALINI)
          LOOP
            INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
            VALUES(V_REC_COSTVAL.VALOARE, aCODCONSTLUNA);
          END LOOP;
        END IF;
    END LOOP;
  END LOOP;
  PRC_AL_CHECK(&apos;CONSTLUNA&apos;);
END;

END PKG_CATEGCONST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CATEGPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D2312BF0A208CA00A713F8C41E9A375B389A304</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CATEGPRET IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodCatPret INTO Tmp FROM NCATPRET WHERE CodCatPret = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(100);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;categ. pret &quot;&apos;||n.Den_Catpret||&apos;&quot;&apos; INTO aDoc
   FROM NCATPRET n where N.CODCATPRET = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NCATPRET&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;

  SP_LOCKRECORD(RecId);
	DELETE FROM NCATPRET WHERE CodCatPret = RecId ;
  NotifyModif(2, RecId, &apos;NCATPRET&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCATPRET FIELDS( CodCatPret ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCATPRET
  INSERT INTO  TMP_NCATPRET ( CodCatPret,den_catpret,tip,simbol, Procdinimplicit,SumaFixaImplicit, CODCATMASTER )
    ( SELECT CodCatPret,den_catpret,tip,simbol, Procdinimplicit, SumaFixaImplicit, CODCATMASTER
      FROM NCATPRET WHERE CodCatPret = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  
  aDoc VARCHAR2(100);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NCATPRET
    SELECT  CodCatPret INTO RecId FROM TMP_NCATPRET;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;categ. pret &quot;&apos;||n.Den_Catpret||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NCATPRET n where N.CODCATPRET = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NCATPRET&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;

    UPDATE NCATPRET SET ( den_catpret,tip,simbol, Procdinimplicit, SumaFixaImplicit, CODCATMASTER )
       = ( SELECT den_catpret,tip,simbol, Procdinimplicit, SumaFixaImplicit, CODCATMASTER
          FROM TMP_NCATPRET )
      WHERE CodCatPret = RecId ;

  ELSE  -- INSERT
-- Master NCATPRET
  SELECT seq_NCATPRET_CodCatPret.NextVal INTO RecId FROM DUAL;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;categ. pret &quot;&apos;||n.Den_Catpret||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NCATPRET n ;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NCATPRET&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;

  INSERT INTO  NCATPRET ( CodCatPret,den_catpret,tip,simbol, Procdinimplicit, SumaFixaImplicit, CODCATMASTER)
 ( SELECT  RecId ,den_catpret,tip,simbol, Procdinimplicit, SumaFixaImplicit, CODCATMASTER
     FROM TMP_NCATPRET  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;NCATPRET&apos;);
  COMMIT;
END;

FUNCTION CLONEAZA_CATEGORIA (aCodSursa  NUMBER ,NewName in varchar2) RETURN NUMBER  IS
ACODNOU NUMBER(20);
BEGIN
  SELECT SEQ_NCATPRET_CODCATPRET.NEXTVAL INTO ACODNOU FROM DUAL;
  
  INSERT INTO NCATPRET(CODCATPRET,DEN_CATPRET,TIP,SIMBOL)
   SELECT ACODNOU,NewName,TIP,SIMBOL FROM NCATPRET WHERE CODCATPRET = ACODSURSA;
  
  COMMIT;
  
  RETURN ACODNOU;
     
  
END;

PROCEDURE MODIFICA_PRET(CODNOU IN NUMBER, CODSURSA IN NUMBER, TIPMODIF IN NUMBER) IS
/*TIPMODIF = 0 =&gt; ADAUGA CODNOU PT ART CARE AU CODSURSA
TIPMODIF = 1 =&gt; INLOCUIESC CODSURSA CU CODNOU */
VCOD NUMBER(20);
CNT  NUMBER(20);
BEGIN
 IF TIPMODIF = 0 THEN
    FOR V_REC IN (SELECT P.* FROM PRETM P WHERE P.CODCATPRET = CODSURSA 
                 ) LOOP
      
      SELECT COUNT(*) INTO CNT FROM PRETM WHERE CODCATPRET  = CODNOU AND
                                                CODOBIECT   = V_REC.CODOBIECT AND
                                                SUBUNITATEA = V_REC.SUBUNITATEA;
           
      IF CNT = 0 THEN
        SELECT SEQ_PRETM_CODPRETM.NEXTVAL INTO VCOD FROM DUAL;
      
        INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA) VALUES
        (VCOD,V_REC.CODOBIECT,CODNOU,V_REC.LEI,V_REC.VALUTA,V_REC.MONEDA,0,V_REC.PROC,V_REC.INDEXLOCAL,V_REC.SUBUNITATEA);
      
        INSERT INTO PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
        SELECT 
          SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL, VCOD,CODAMB, LEI, VALUTA 
        FROM PRETMAMB WHERE CODPRETM = V_REC.CODPRETM;  
     END IF;
    END LOOP;
 END IF;
 
 IF TIPMODIF = 1 THEN
    FOR V_REC IN (SELECT P.* FROM PRETM P WHERE P.CODCATPRET = CODNOU 
                 ) LOOP
      
      SELECT COUNT(*) INTO CNT FROM PRETM WHERE CODCATPRET  = CODSURSA AND
                                                CODOBIECT   = V_REC.CODOBIECT AND
                                                SUBUNITATEA = V_REC.SUBUNITATEA;
           
      IF CNT = 0 THEN
        UPDATE PRETM P SET P.CODCATPRET = CODSURSA WHERE P.CODPRETM = V_REC.CODPRETM;
      END IF;
      
   END LOOP; 
 END IF;
 
 COMMIT;
END;


END pkg_CategPret; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>067D17E419809498386CA6449B25F501B6509032</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CENTRECOST IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20); 
BEGIN 
  SELECT codcentru INTO Tmp FROM centrecost WHERE codcentru = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN 
  SP_LOCKRECORD(RecId);
  -- nomCC --&gt; 517
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 517);
  DELETE FROM centrecostA  WHERE codcentru = RecId ;
  DELETE FROM centrecost  WHERE codcentru = RecId ;
  NotifyModif(2, RecId, &apos;centrecost&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN 
  INSERT INTO  TMP_centrecost FIELDS( codcentru ) VALUES (0) ;
  -- nomCC --&gt; 517
  PKG_CFGTABLES.EXT_INSERTRECORD(517); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN 
  INSERT INTO  TMP_centrecost ( codcentru, simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, TipAloc, Tip ) 
    ( SELECT codcentru, simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, NVL(TipAloc, 0), NVL(Tip, 0)
      FROM centrecost WHERE codcentru = RecId ) ; 

  INSERT INTO TMP_CentreCostA(CodCENTRUA,CodCENTRU,CODANALIZA,NODMAXIMANALIZA1,CODDESCRIPTOR)
   SELECT  EA.CodCENTRUA,EA.CodCENTRU,EA.CODANALIZA,EA.NODMAXIMANALIZA1,A1.CODDESCRIPTOR
   FROM CentreCostA EA LEFT JOIN ANALIZA1 A1 ON A1.CODANALIZA = EA.CODANALIZA 
   WHERE CodCENTRU = RECID AND
         NVL(A1.INDEXLOCAL,1) = NVL(EA.NODMAXIMANALIZA1,1);
                            
  -- nomCC --&gt; 517
  PKG_CFGTABLES.EXT_GOTORECORD(517);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  -- nomCC --&gt; 517
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (517);
  IF Operation = 0 THEN  -- UPDATE 

    SELECT  codcentru INTO RecId FROM TMP_centrecost;
    UPDATE centrecost SET ( simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, TipAloc, Tip ) 
       = ( SELECT simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, TipAloc, Tip
          FROM TMP_centrecost ) 
    WHERE codcentru = RecId ; 
      
    DELETE FROM CentreCostA EA WHERE EA.CodCENTRU = RECID AND NOT EXISTS ( SELECT CodCENTRUA FROM TMP_CentreCostA WHERE CodCENTRUA = EA.CodCENTRUA);
    
    FOR V_REC IN (SELECT * FROM TMP_CentreCostA WHERE CodCENTRUA &gt; 0 ) LOOP
     UPDATE CentreCostA EA SET
       EA.CodCENTRU       = V_REC.CodCENTRU,
       EA.CODANALIZA       = V_REC.CODANALIZA,
       EA.NODMAXIMANALIZA1 = V_REC.NODMAXIMANALIZA1
     WHERE EA.CodCENTRUA = V_REC.CodCENTRUA;  
    END LOOP;
    
    INSERT INTO CentreCostA (CodCENTRUA,CodCENTRU,CODANALIZA,NODMAXIMANALIZA1)
    SELECT SEQ_CentreCostA_CodCENTRUA.NEXTVAL,RECID,CODANALIZA,NODMAXIMANALIZA1 FROM TMP_CentreCostA WHERE CodCENTRUA &lt;= 0;
    

  ELSE  -- INSERT 
  
  SELECT seq_centrecost_codcentru.NextVal INTO RecId FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;centrecost&apos;, RecId);  
  INSERT INTO  centrecost ( codcentru, simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, TipAloc, Tip ) 
 ( SELECT  RecId , simbol, denumire, INACTIV, DOMENIU, AnStart, LunaStart, TIPCHELT, TipAloc, Tip
     FROM TMP_centrecost  ) ; 

    INSERT INTO CentreCostA(CodCENTRUA,CodCENTRU,CODANALIZA,NODMAXIMANALIZA1)
     SELECT SEQ_CentreCostA_CodCENTRUA.NEXTVAL,RECID,CODANALIZA,NODMAXIMANALIZA1 FROM TMP_CentreCostA;
END IF;
  -- nomCC --&gt; 517
  PKG_CFGTABLES.EXT_POSTRECORDS(517); 
  NotifyModif(Operation, RecId, &apos;centrecost&apos;);
  COMMIT;
END;  

end pkg_centrecost; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9F609484C11545158C9F24828229BB85FA7A08E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CERTIF IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodCertif INTO Tmp FROM CERTIF WHERE CodCertif = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);

  PKG_CFGTABLES.EXT_DELETERECORD (recId, 503);
 
  DELETE CERTIF WHERE CodCertif = RecId;
  
  NotifyModif(2, RecId, &apos;CERTIF&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(503);
  INSERT INTO TMP_CERTIF FIELDS( CodCertif ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(503);  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(503);
  INSERT INTO TMP_CERTIF 
    ( CodCertif, 
      NrCertif, 
      DataPrimire, 
      Fisier, 
      CodPart,
      CodObiect,
      CodSerie,
      NumeFisier,
      Ext,
      Subunitate,
      UserId,
      DataCreare,
      CodTara, 
      Provenienta, 
      Obs,
      TipPart,
      CodGest,
      DenObiect,
      Productie,
      CodProducator,
      CODEXTERN_OBJ,
      CODINTERN_OBJ,
      CARNETDOC,
      seriadoc,
      ARECARNETDOC )
  SELECT 
      C.CodCertif, 
      C.NrCertif, 
      C.DataPrimire, 
      C.Fisier, 
      C.CodPart,
      C.CodObiect,
      C.CodSerie,
      C.NumeFisier,
      C.Ext,
      C.Subunitate,
      C.UserId,
      C.DataCreare,
      C.CodTara, 
      C.Provenienta, 
      C.Obs,
      C.TipPart,
      C.CodGest,
      OBJ.Denumire,
      case 
        when C.TipPart = 3 then 1
        else 0
      end,
      OBJ.CODPRODUCATOR,
      obj.codextern,
      obj.codintern,
      CARNETDOC,
      seriadoc,
      case when Coalesce(C.CARNETDOC,0) = 0 then 0 else 1 end 
    FROM CERTIF C
    INNER JOIN NARTOBJ OBJ ON C.CodObiect = OBJ.CodObiect
    WHERE c.CodCertif = RecId;
   
  PKG_CFGTABLES.EXT_GOTORECORD(503);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aCARNETDOC NUMBER(20) := 0;
  aNRDOC     NUMBER(20) := 0;
  acount number(10);
BEGIN
  SELECT CARNETDOC INTO aCARNETDOC
  FROM TMP_CERTIF;
  if coalesce(aCARNETDOC,0) &lt;&gt; 0 then
      SELECT NrCertif INTO aNRDOC
      FROM TMP_CERTIF;
  end if;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (503);
  IF Operation = 0 THEN
    SELECT CodCertif INTO RecId FROM TMP_CERTIF;
    UPDATE CERTIF
    SET ( NrCertif, 
          DataPrimire, 
          Fisier, 
          CodPart,
          CodObiect,
          CodSerie,
          NumeFisier,
          Ext,
          CodTara, 
          Provenienta, 
          Obs,
          TipPart,
          CodGest,
          CARNETDOC,
          seriadoc )
     = (SELECT 
          NrCertif, 
          DataPrimire, 
          Fisier, 
          CodPart,
          CodObiect,
          CodSerie,
          NumeFisier,
          Ext,
          CodTara, 
          Provenienta, 
          Obs,
          case 
            when Productie = 1 then 3
            else 2
          end TipPart,
          CodGest,
          CARNETDOC,
          seriadoc
        FROM TMP_CERTIF )
    WHERE CodCertif = RecId;   
  ELSE  
    SELECT SEQ_CERTIF_CODCERTIF.Nextval INTO RecID From DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;CERTIF&apos;, RecId); 
    INSERT INTO CERTIF 
    ( CodCertif, 
      NrCertif, 
      DataPrimire, 
      Fisier, 
      CodPart,
      CodObiect,
      CodSerie,
      NumeFisier,
      Ext,
      Subunitate,
      UserId,
      DataCreare,
      CodTara, 
      Provenienta, 
      Obs,
      TipPart,
      CodGest,
      CARNETDOC,
      seriadoc )
    ( SELECT 
      RecID, 
      NrCertif, 
      DataPrimire, 
      Fisier, 
      CodPart,
      CodObiect,
      CodSerie,
      NumeFisier,
      Ext,
      Subunitate,
      pkg_globals.USERID,
      systimestamp,
      CodTara, 
      Provenienta, 
      Obs,
      case 
        when Productie = 1 then 3
        else 2
      end TipPart,
      CodGest,
      CARNETDOC,
      seriadoc
    FROM TMP_CERTIF );

    IF NVL(aCARNETDOC,0) &lt;&gt; 0 THEN
      PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
    END IF;
  END IF;
  PKG_CFGTABLES.EXT_POSTRECORDS(503);
  NotifyModif(Operation, RecId, &apos;CERTIF&apos;);
  COMMIT;
END; 

END pkg_certif;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CFGTABLES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A726ADCC497D9142F08A9C21E836B9932A4DFD16</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CFGTABLES IS

FUNCTION GETDISPLAY(aNomLink in number, aDisplay in varchar2, aCod in number) return varchar2 is
vDisplay varchar2(1000);
vTabla varchar2(50);
vCod varchar2(50);
begin
  vDisplay := &apos;&apos;;
  if aCod = 0 then return vDisplay; end if;
  if aNomLink = 1 then
    vTabla := &apos;nartobj&apos;;
    vCod := &apos;codobiect&apos;;
  end if;
  if aNomLink = 2 then
    vTabla := &apos;npart&apos;;
    vCod := &apos;codpart&apos;;
  end if;
  if aNomLink = 3 then
    vTabla := &apos;npers&apos;;
    vCod := &apos;codpers&apos;;
  end if;
  if aNomLink = 4 then
    vTabla := &apos;contract&apos;;
    vCod := &apos;codcontract&apos;;
  end if;
  if aNomLink = 5 then
    vTabla := &apos;nagenda&apos;;
    vCod := &apos;codagenda&apos;;
  end if;
  begin
    execute immediate &apos;select &apos;||Replace(aDisplay,&apos;;&apos;,&apos;||&apos;&apos;;&apos;&apos;||&apos;)||&apos; from &apos;||vTabla||&apos; where &apos;||vCod||&apos; = &apos;||aCod into vDisplay;
  exception when others then vDisplay := &apos;&apos;;
  end;
  return vDisplay;
end;

PROCEDURE TEST IS
BEGIN
  PKG_GLOBALS.SETUSERID(1268);
  PKG_GLOBALS.SETSUBUNITATE(2);
  PKG_GLOBALS.SETUSERNAME(&apos;FLORENTIN&apos;);
  CHECKMON(&apos;CODNARTOBJEXT&apos;,381,161);
END;

procedure CHECKMON(aFieldName in varchar2, aCodExt in number, aCodMaster in number) is
ADOC VARCHAR2(500);
ADATADOC DATE;
ACOUNT NUMBER(10);
ATIPDOC NUMBER(10);
OP VARCHAR2(1);
begin
  IF upper(aFieldName) = &apos;CODNARTOBJEXT&apos; THEN
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.GETUSERID,&apos;MON_73&apos;) THEN
      BEGIN
        SELECT &apos;Extensie articol: &apos;||DENUMIRE INTO ADOC FROM NARTOBJ WHERE CODOBIECT = ACODMASTER;
      EXCEPTION WHEN OTHERS THEN ADOC := &apos;&apos;;
      END;
      EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM NARTOBJEXT WHERE CODNARTOBJEXT = &apos;||TO_CHAR(ACODEXT) INTO ACOUNT;
      IF ACOUNT = 0 THEN OP := &apos;A&apos;; ELSE OP := &apos;M&apos;; END IF;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NARTOBJEXT&apos;, PKG_GLOBALS.USERNAME, OP, ACODMASTER, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, NULL, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  END IF;
  IF upper(aFieldName) = &apos;CODCOMANDC&apos; THEN
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.GETUSERID,&apos;MON_74&apos;) THEN
      BEGIN
        SELECT
          DATADOC,
          PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC
        INTO
          aDATADOC,
          ADOC
        FROM COMANDA WHERE CODCOMANDA = ACODMASTER;
      EXCEPTION WHEN OTHERS THEN ADOC := &apos;&apos;; ADATADOC := NULL;
      END;
      EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM COMANDC WHERE CODCOMANDC = &apos;||TO_CHAR(ACODEXT) INTO ACOUNT;
      IF ACOUNT = 0 THEN OP := &apos;A&apos;; ELSE OP := &apos;M&apos;; END IF;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDC&apos;, PKG_GLOBALS.USERNAME, OP, ACODMASTER, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, ADATADOC, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  END IF;
  IF upper(aFieldName) = &apos;CODTRANSFEXT&apos; THEN
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.GETUSERID,&apos;MON_75&apos;) THEN
      BEGIN
        SELECT
          DATADOC,
          PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC
        INTO
          aDATADOC,
          ADOC
        FROM TRANSF WHERE CODTRANSF = ACODMASTER;
      EXCEPTION WHEN OTHERS THEN ADOC := &apos;&apos;; ADATADOC := NULL;
      END;
      EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM TRANSFEXT WHERE CODTRANSFEXT = &apos;||TO_CHAR(ACODEXT) INTO ACOUNT;
      IF ACOUNT = 0 THEN OP := &apos;A&apos;; ELSE OP := &apos;M&apos;; END IF;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;TRANSFEXT&apos;, PKG_GLOBALS.USERNAME, OP, ACODMASTER, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, ADATADOC, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  END IF;
  IF upper(aFieldName) = &apos;CODMARIRIEXT&apos; THEN
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.GETUSERID,&apos;MON_76&apos;) THEN
      BEGIN
        SELECT
          DATADOC,
          PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
          TIPDOC
        INTO
          aDATADOC,
          ADOC,
          ATIPDOC
        FROM IESIRI WHERE CODIES = ACODMASTER;
      EXCEPTION WHEN OTHERS THEN ADOC := &apos;&apos;; ADATADOC := NULL; ATIPDOC := 0;
      END;
      IF ATIPDOC = 15 THEN
        EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM MARIRIEXT WHERE CODMARIRIEXT = &apos;||TO_CHAR(ACODEXT) INTO ACOUNT;
        IF ACOUNT = 0 THEN OP := &apos;A&apos;; ELSE OP := &apos;M&apos;; END IF;
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;MARIRIEXT&apos;, PKG_GLOBALS.USERNAME, OP, ACODMASTER, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, ADATADOC, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    END IF;
  END IF;
  IF upper(aFieldName) = &apos;CODINTRARIF&apos; THEN
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.GETUSERID,&apos;MON_77&apos;) THEN
      BEGIN
        SELECT
          DATADOC,
          PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
          TIPDOC
        INTO
          aDATADOC,
          ADOC,
          ATIPDOC
        FROM INTRARI WHERE CODINTR = ACODMASTER;
      EXCEPTION WHEN OTHERS THEN ADOC := &apos;&apos;; ADATADOC := NULL; ATIPDOC := 0;
      END;
      IF ATIPDOC = 1 THEN
        EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM INTRARIF WHERE CODINTRARIF = &apos;||TO_CHAR(ACODEXT) INTO ACOUNT;
        IF ACOUNT = 0 THEN OP := &apos;A&apos;; ELSE OP := &apos;M&apos;; END IF;
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARIF&apos;, PKG_GLOBALS.USERNAME, OP, ACODMASTER, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, ADATADOC, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    END IF;
  END IF;
end;

PROCEDURE SETTIPCONFIG(TIP IN NUMBER)
IS
BEGIN
  TIPCONFIG := TIP;
END;

PROCEDURE SETGRANTMODUL( NumeModul IN VARCHAR2, FIRMA IN VARCHAR2) IS
SIR VARCHAR2(100);
BEGIN
  SIR :=  &apos; GRANT SELECT, UPDATE, INSERT, DELETE ON &apos; || NUMEMODUL || &apos; TO  ROLE_&apos; || FIRMA || &apos;_OBJ&apos;;
  EXECUTE IMMEDIATE SIR;
END;

FUNCTION TESTCOPYCAMP(VALOARE IN VARCHAR2, TIPDEST IN VARCHAR2, MARIMEDEST IN NUMBER) RETURN VARCHAR2 IS
 NR NUMBER(20, 7) ;
 DATA DATE;
BEGIN
  IF TIPDEST = &apos;N&apos; THEN
    BEGIN
      NR := VALOARE;
      EXCEPTION WHEN OTHERS THEN RETURN NULL;
    END;
  END IF;

  IF TIPDEST IN (&apos;A&apos;, &apos;M&apos;) THEN
    RETURN SUBSTR(TO_CHAR(VALOARE), 1, MARIMEDEST);
  END IF;

  IF TIPDEST = &apos;D&apos; THEN
    BEGIN
      DATA := TO_DATE(VALOARE, &apos;DD.MM.YYYY&apos;);
      EXCEPTION WHEN OTHERS THEN RETURN NULL;
    END;
  END IF;

  RETURN VALOARE;
END;

PROCEDURE SETNUMEMODUL(aMODUL IN VARCHAR2)
IS
BEGIN
  NUMEMODUL := UPPER(aMODUL);
END;

FUNCTION GETCODMODUL (aTipConfig IN NUMBER, aMASTER IN VARCHAR2, aLinkKey IN VARCHAR2, aTipLink IN NUMBER, aDescriere IN VARCHAR2)   RETURN NUMBER
IS
 COD NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODCFGTABLE INTO COD FROM CFGTABLES C WHERE UPPER(C.NUMETABELA) = UPPER(NUMEMODUL);
    EXCEPTION WHEN OTHERS THEN COD := 0;
  END;
  IF COD = 0 THEN
    SELECT SEQ_CFGTABLES_CODCFGTABLE.NEXTVAL INTO COD FROM DUAL;
    IF aTIPCONFIG = 0 THEN
      INSERT INTO CFGTABLES(CODCFGTABLE, NUMETABELA, TIPCONFIG) VALUES(COD, NUMEMODUL, 0);
    ELSE
      INSERT INTO CFGTABLES(CODCFGTABLE, NUMETABELA, TIPCONFIG, MASTER, LINKKEY, TIPLINK, DESCRIERE) VALUES(COD, NUMEMODUL, aTipConfig, aMaster, aLinkKey, aTipLink, aDescriere );
    END IF;
    COMMIT;
  ELSE
    IF aTIPCONFIG = 1 THEN -- STRUCTURI PROPRII: POT MODIFICA UNELE INFORMATII
      UPDATE CFGTABLES
      SET
        LINKKEY   = aLinkKey,
        TIPLINK   = aTipLink,
        Descriere = aDescriere
      WHERE
        CODCFGTABLE = COD;
    END IF;
  END IF;

  RETURN COD;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
  NR NUMERIC(10);
BEGIN
  SELECT 0 INTO NR FROM DUAL;
END;

PROCEDURE SP_INSERTRECORD
 IS
  NR NUMERIC(10);
 BEGIN
   SELECT 0 INTO NR FROM DUAL;
 END;



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodCfgTable INTO Tmp FROM CFGTABLES WHERE CodCFGTABLE = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 aTip number(10);
 aNUMETABELA VARCHAR2(30) := &apos;&apos;;
BEGIN
  INSERT INTO TMP_CFGTABLES SELECT * FROM CFGTABLES WHERE CODCFGTABLE = RECID;
  INSERT INTO TMP_CFGTABLES1
  (CODCFGTABLE1, CODCFGTABLE, INDEXLOCAL, TMP,ToBeUPDATED, SQLOnChange, NUMECAMP, CAPTION, TIP, MARIME, ZECIMALE, ColWidth, Color, OBLIGATORIU, NOMLINK, LOOKUPDISPLAY, TIPFILTRUAFIS, FILTRUAFIS, HASTOTAL)
  SELECT CODCFGTABLE1, CODCFGTABLE, INDEXLOCAL, Coalesce(TMP, 0), Coalesce(ToBeUPDATED, 0), SQLOnChange, NUMECAMP, CAPTION, TIP, MARIME, ZECIMALE, ColWidth, Color, OBLIGATORIU, NVL(NOMLINK, 0),  LOOKUPDISPLAY, TIPFILTRUAFIS, FILTRUAFIS, HASTOTAL FROM CFGTABLES1 WHERE CODCFGTABLE = RECID;
     

  INSERT INTO TMP_CFGTABLES2
  SELECT * FROM CFGTABLES2 C2
  WHERE
    EXISTS (SELECT CODCFGTABLE1 FROM TMP_CFGTABLES1 WHERE CODCFGTABLE1 = C2.CODCFGTABLE1);

  UPDATE TMP_CFGTABLES1 C1
  SET
   VALPREDEF = DECODE((SELECT COUNT(*) FROM TMP_CFGTABLES2 WHERE CODCFGTABLE1 = C1.CODCFGTABLE1), 0, 0, 1);

  SELECT NUMETABELA INTO aNUMETABELA FROM TMP_CFGTABLES;

  IF aNUMETABELA IS NOT NULL AND LENGTH(aNUMETABELA) &gt; 0 THEN
  BEGIN
   FOR V_REC IN
   (SELECT * FROM TMP_CFGTABLES1)
   LOOP
     EXECUTE IMMEDIATE (&apos;UPDATE TMP_CFGTABLES1 SET REFERINTE = (SELECT COUNT(*) FROM &apos; || aNUMETABELA || &apos; WHERE &apos; || V_REC.NUMECAMP || &apos; IS NOT NULL) WHERE CODCFGTABLE1 =  &apos; || V_REC.CODCFGTABLE1);
   END LOOP;
   EXCEPTION WHEN OTHERS THEN NULL;
  END;

  END IF;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
VCOD NUMBER(20);
aSUPLIMSQL clob;
BEGIN
  SELECT CODCFGTABLE, SUPLIMSQL INTO RECID, aSUPLIMSQL FROM TMP_CFGTABLES;

  update CFGTABLES set SUPLIMSQL = aSUPLIMSQL where CODCFGTABLE = RECID;

  DELETE FROM CFGTABLES2 C2
  WHERE
      EXISTS (SELECT CODCFGTABLE1 FROM CFGTABLES1 WHERE CODCFGTABLE = RECID AND CODCFGTABLE1 = C2.CODCFGTABLE1)
  AND NOT EXISTS (SELECT CODCFGTABLE2 FROM TMP_CFGTABLES2 WHERE CODCFGTABLE2 = C2.CODCFGTABLE2);

  DELETE FROM CFGTABLES1 C1 WHERE CODCFGTABLE = RECID
  AND NOT EXISTS (SELECT CODCFGTABLE1 FROM  TMP_CFGTABLES1 WHERE CODCFGTABLE1 = C1.CODCFGTABLE1);


  FOR V_REC IN (SELECT * FROM TMP_CFGTABLES1)
  LOOP
    IF V_REC.CODCFGTABLE1 &lt; 0 THEN
      SELECT SEQ_CFGTABLES1_CODCFGTABLE1.NEXTVAL INTO VCOD FROM DUAL;

      UPDATE TMP_CFGTABLES2
      SET
       CODCFGTABLE1 = VCOD
      WHERE
       CODCFGTABLE1 = V_REC.CODCFGTABLE1;


      INSERT INTO CFGTABLES1(CODCFGTABLE1, CODCFGTABLE, INDEXLOCAL, NUMECAMP, CAPTION, TIP, MARIME, ZECIMALE, ColWidth, Color, OBLIGATORIU, NOMLINK, LOOKUPDISPLAY, TIPFILTRUAFIS, FILTRUAFIS, HASTOTAL, TMP,ToBeUPDATED, SQLOnChange)
      VALUES (VCOD, RECID, V_REC.INDEXLOCAL, TRIM(V_REC.NUMECAMP), V_REC.CAPTION, V_REC.TIP, V_REC.MARIME, V_REC.ZECIMALE, V_REC.ColWidth, V_REC.Color, V_REC.OBLIGATORIU, V_REC.NOMLINK, V_REC.LOOKUPDISPLAY, V_REC.TIPFILTRUAFIS, V_REC.FILTRUAFIS, V_REC.HASTOTAL, V_REC.TMP,V_REC.ToBeUPDATED, V_REC.SQLOnChange);
    ELSE
       UPDATE CFGTABLES1
       SET
         INDEXLOCAL    = V_REC.INDEXLOCAL,
         NUMECAMP      = TRIM(V_REC.NUMECAMP),
         CAPTION       = V_REC.CAPTION,
         TIP           = V_REC.TIP ,
         MARIME        = V_REC.MARIME,
         ZECIMALE      = V_REC.ZECIMALE,
         ColWidth      = V_REC.ColWidth,
         Color         = V_REC.Color,
         Obligatoriu   = V_REC.OBLIGATORIU,
         NOMLINK       = V_REC.NOMLINK,
         LOOKUPDISPLAY = V_REC.LOOKUPDISPLAY,
         TIPFILTRUAFIS = V_REC.TIPFILTRUAFIS,
         FILTRUAFIS    = V_REC.FILTRUAFIS,
         HASTOTAL      = V_REC.HASTOTAL,
         TMP           = V_REC.TMP,
				 ToBeUPDATED   = V_REC.ToBeUPDATED, 
				 SQLOnChange   = V_REC.SQLOnChange
       WHERE
         CODCFGTABLE1 = V_REC.CODCFGTABLE1;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_CFGTABLES2)
  LOOP
    IF V_REC.CODCFGTABLE2 &lt; 0 THEN
      INSERT INTO CFGTABLES2 (CODCFGTABLE2, CODCFGTABLE1, VALOARE)
      VALUES (SEQ_CFGTABLES2_CODCFGTABLE2.NEXTVAL, V_REC.CODCFGTABLE1, V_REC.VALOARE);
    ELSE

      UPDATE CFGTABLES2
      SET
       VALOARE = V_REC.VALOARE
      WHERE
       CODCFGTABLE2 = V_REC.CODCFGTABLE2;

    END IF;
  END LOOP;
END;

FUNCTION GET_EXT_SEQ_NAME(tableName IN VARCHAR2) RETURN VARCHAR IS
  codColumnName VARCHAR2(30);
  seqName             VARCHAR2(30);
BEGIN
  if tableName is null then
    return null;
  end if;
  codColumnName := &apos;COD&apos; || tableName;
  if upper(tableName) = &apos;OPORTUNITATIEXT&apos; then
    seqName             := &apos;SEQ_&apos; || tableName || &apos;_CODOEXT&apos; ;
  else
    if upper(tableName) = &apos;RECLAMATIIEXT&apos; then
      seqName             := &apos;SEQ_&apos; || tableName || &apos;_CODRECL&apos; ;
    else
      seqName             := &apos;SEQ_&apos; || tableName || &apos;_&apos; || codColumnName;
    end if;
  end if;
  return seqName;
END;

PROCEDURE CHECK_STRUCT_EXTENSIE_X_TIPDOC (pTipDoc IN NUMBER) IS
  tipDoc NUMBER(20);
  rc SYS_REFCURSOR;
  v_rec tmp_extcfgtable%ROWTYPE;
 
BEGIN
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  rc := get_cfgtable_by_tip_doc(tipDoc);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;
    CHECK_STRUCT_EXTENSIE(v_rec.nume_tabela, v_rec.link_key);
  end loop;
  CLOSE rc;
END;

FUNCTION GET_FIELD_TYPE (TIP IN VARCHAR2, ZECIMALE IN NUMBER, MARIME IN NUMBER) return VARCHAR2
IS
  vType VARCHAR2(1000);
BEGIN
  CASE
    WHEN TIP = &apos;N&apos; THEN vType := &apos;NUMBER(20,&apos; || TO_CHAR(COALESCE(ZECIMALE,0)) || &apos;)&apos;;
    WHEN TIP IN (&apos;A&apos;,&apos;M&apos;) THEN vType := &apos;VARCHAR2(&apos; || TO_CHAR(COALESCE(MARIME,0)) || &apos;)&apos;;
    ELSE vType :=&apos;DATE&apos;;
  END CASE;
  
  return &apos; &apos; || vType;       
       
END;

FUNCTION GET_EXT_SQL_TMP (tableName IN VARCHAR2) RETURN VARCHAR2
IS
  vSQL VARCHAR2(3200);
BEGIN
  BEGIN
    select cft.suplimsql into vSQL 
    from cfgtables cft 
    where upper(cft.numetabela) = upper(tableName);
  EXCEPTION
           WHEN OTHERS THEN vSQL := null;
  END;
  if (vSQL is not null) and (length(trim(vSQL)) = 0) then
    vSQL := null;
  end if;
  return vSQL;
  
END; 

function GET_EXT_FIELDS_FROM_TABLE (pTableName IN VARCHAR2, pCodColumnName IN VARCHAR2, pLinkKey IN VARCHAR2, pStartWithComma IN NUMBER DEFAULT 1) return VARCHAR2
IS
  sListCols VARCHAR2(3200);
BEGIN
  sListCols := &apos;&apos;;
  for v_colList in (select * from USER_TAB_COLS where  upper(TABLE_NAME) = upper(pTableName) and COLUMN_ID is not null order by column_id)
    loop
      if (coalesce(v_colList.Column_Name, &apos;&apos;) = &apos;&apos;)
        or (lower(v_colList.Column_Name)  = lower (pCodColumnName) )
        or (lower(v_colList.Column_Name)  = lower (pLinkKey) ) THEN
          continue;
        end if;
        IF sListCols IS NULL OR sListCols = &apos;&apos; THEN
           sListCols := v_colList.column_name;
        ELSE
           sListCols := sListCols || &apos;, &apos; || v_colList.column_name;
        END IF;
  end loop;
  IF (sListCols is not null) and (length(trim(sListCols)) &gt; 0) and (pStartWithComma &gt; 0) then
     sListCols := &apos;, &apos; || sListCols;  
  END IF;
  return trim(sListCols);
END; 

function GET_EXT_FIELDS (tableName IN VARCHAR2, isTemporary IN NUMBER) return VARCHAR2
IS
  vColumns VARCHAR2(3200):= &apos;&apos;;
  vOldSep  VARCHAR2(20);
BEGIN
  vOldSep := PKG_GLOBALS.SEP;
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);
  begin
    select string_agg(wt.numecamp) into vColumns from     
    (select ctbl1.numecamp
      from  cfgtables1  ctbl1
      join cfgtables ctbl
        on ctbl.codcfgtable = ctbl1.codcfgtable
      where upper(ctbl.numetabela) = upper(tableName)
           and coalesce(ctbl1.TMP, 0) = isTemporary
      ORDER BY ctbl1.INDEXLOCAL) wt;         
  exception
     when others then vColumns := &apos;&apos;; 
  end;   
     
  PKG_GLOBALS.SetSeparator(vOldSep);
  
  return trim(vColumns);
END;

function GET_EXT_TMP_FIELDS_WITH_TYPES (tableName IN VARCHAR2) return VARCHAR2
IS
  vColumns VARCHAR2(2500):= &apos;&apos;;
  nrTmpColumns NUMBER(10);
  vOldSep  VARCHAR2(20);
BEGIN
  vOldSep := PKG_GLOBALS.SEP;
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);
  
  select string_agg(ctbl1.numecamp || PKG_CFGTABLES.GET_FIELD_TYPE(ctbl1.Tip,ctbl1.Zecimale,ctbl1.Marime))  into vColumns
  from cfgtables1 ctbl1
  join cfgtables ctbl
    on ctbl.codcfgtable = ctbl1.codcfgtable
  where ctbl.numetabela = tableName
       and ctbl1.tmp = 1;
       
  PKG_GLOBALS.SetSeparator(vOldSep);
  return trim(vColumns);
END;

function GET_EXT_TMP_FIELDS_NUM (tableName IN VARCHAR2) return NUMBER
IS
  nrTmpColumns NUMBER(10);
BEGIN
  select count(*) into nrTmpColumns
  from cfgtables1 ctbl1
  join cfgtables ctbl
    on ctbl.codcfgtable = ctbl1.codcfgtable
  where ctbl.numetabela = tableName
       and ctbl1.tmp = 1;
      
  return nrTmpColumns;
END;

PROCEDURE CHECK_STRUCT_EXTENSIE (tableName IN VARCHAR2, linkKey IN VARCHAR2)
IS
  vPrefixSchema   VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  codColumnName   VARCHAR2(30);
  seqName         VARCHAR2(30);
  tmpTableName    VARCHAR2(30);
  tmpTableNameIni VARCHAR2(30);
  nrColoaneCod     NUMBER(10) := 0;
  nr              NUMBER(10) := 0;
  dt              VARCHAR2(100);
  sir             VARCHAR2(1000);
  separator       VARCHAR2(100);
  nr1             NUMBER(10) := 0;
  nrTmp           NUMBER(10) := 0;
  tmpColumnsWithTypes VARCHAR2(2500);
BEGIN
  codColumnName   := &apos;COD&apos; ||tableName;
  seqName         := GET_EXT_SEQ_NAME(tableName);
  tmpTableName    := &apos;TMP_&apos;||tableName;
  tmpTableNameIni := &apos;TMP_&apos;||tableName||&apos;_INI&apos;;
  
 IF PKG_LIST_STRUCT.TmpExists(tmpTableName) = 1 THEN 
   select count(*) into nrColoaneCod
      from user_tab_cols
      where TABLE_NAME =upper(tmpTableName)
          and (column_name = upper(codColumnName) or column_name = upper(linkKey))
          and COLUMN_ID is not null;
          
    if (nrColoaneCod &lt;&gt; 2) then
        execute immediate &apos;DROP TABLE &apos;||vPrefixSchema||tmpTableName;
    end if;
    nrColoaneCod := 0;
  end if; 
  IF PKG_LIST_STRUCT.TmpExists(tmpTableNameIni) = 1 THEN
    select count(*) into nrColoaneCod
      from user_tab_cols
      where TABLE_NAME =upper(tmpTableNameIni)
          and (column_name = upper(codColumnName) or column_name = upper(linkKey))
          and COLUMN_ID is not null;
          
    if (nrColoaneCod &lt;&gt; 2) then
        execute immediate &apos;DROP TABLE &apos;||vPrefixSchema||tmpTableNameIni;
    end if;      
    nrColoaneCod := 0;
  end if;      

  IF PKG_LIST_STRUCT.TmpExists(tableName) = 0 THEN
    execute immediate &apos;CREATE TABLE &apos;||vPrefixSchema||tableName||&apos;(&apos;||codColumnName|| &apos; NUMBER(20), &apos;||linkKey|| &apos; NUMBER(20) ) &apos;;
    PKG_CFGTABLES.SETGRANTMODUL(tableName, PKG_GLOBALS.FIRMANAME);
  end if;

  if PKG_LIST_STRUCT.TmpExists(tmpTableNameIni) = 0 THEN
    execute immediate &apos;CREATE GLOBAL TEMPORARY TABLE &apos;||vPrefixSchema||tmpTableNameIni||&apos;(&apos;||codColumnName||&apos; NUMBER(20), &apos;||linkKey||&apos; NUMBER(20) ) ON COMMIT PRESERVE ROWS &apos;;
    PKG_CFGTABLES.SETGRANTMODUL(tmpTableNameIni, PKG_GLOBALS.FIRMANAME);
  end if;

  select COUNT(*) INTO nr
  from USER_OBJECTS
  where OBJECT_NAME = seqName;

  if nr = 0 then
    PKG_REMAKE_SEQUENCES.REMAKE_SEQUENCE(tableName, codColumnName, seqName);
  end if;

  if PKG_LIST_STRUCT.TmpExists(tmpTableName) = 1 then
    select COUNT(*) INTO nr1 from USER_TAB_COLS where  TABLE_NAME = tableName and COLUMN_ID is not null;
    select COUNT(*) INTO nr  from USER_TAB_COLS where  TABLE_NAME = tmpTableName and COLUMN_ID is not null;
    if nr1 + GET_EXT_TMP_FIELDS_NUM(tableName) &lt;&gt; nr then
      execute immediate &apos;DROP TABLE &apos;||vPrefixSchema||tmpTableName;
    end if;
  end if;

  if PKG_LIST_STRUCT.TmpExists(tmpTableName) = 0 then
    sir := &apos;CREATE GLOBAL TEMPORARY TABLE &apos;||vPrefixSchema||tmpTableName||&apos;(&apos; ;
    select COUNT(*) INTO nr from USER_TAB_COLS where  TABLE_NAME = tableName AND COLUMN_ID IS NOT NULL;
    for v_rec in (select * from USER_TAB_COLS  where  TABLE_NAME = tableName and COLUMN_ID IS NOT NULL order by COLUMN_ID)
    loop
      if v_rec.DATA_TYPE = &apos;VARCHAR2&apos; then
        dt := &apos; VARCHAR2(&apos; || v_rec.DATA_LENGTH || &apos;) &apos;;
      else
        if v_rec.DATA_TYPE = &apos;DATE&apos; then
          dt := &apos; DATE &apos;;
        else
          dt := &apos; NUMBER(&apos; || v_rec.DATA_PRECISION || &apos;,&apos; || v_rec.DATA_SCALE || &apos;) &apos;;
        end if;
      end if;

      if v_rec.COLUMN_ID &lt; nr  then
        separator := &apos;, &apos;;
      else
        separator := &apos;&apos;;
      end if;

      dt := dt || separator;
      sir := sir || &apos; &apos; || v_rec.COLUMN_NAME || &apos; &apos; || dt;
    end loop;
    tmpColumnsWithTypes := GET_EXT_TMP_FIELDS_WITH_TYPES(tableName);
    
    if (length(tmpColumnsWithTypes) &gt; 0) then
       sir := sir || &apos;, &apos; || tmpColumnsWithTypes; 
    end if; 
    
    sir := sir || &apos; ) ON COMMIT PRESERVE ROWS &apos;;
   
    EXECUTE IMMEDIATE sir;
    PKG_CFGTABLES.SETGRANTMODUL(tmpTableName, PKG_GLOBALS.FIRMANAME);
  END IF;
END;

PROCEDURE EXT_UPDATE_COD_CORESP (pMasterTableName IN VARCHAR2, newCode IN NUMBER, oldCode IN NUMBER DEFAULT NULL) IS
  vMasterTableName VARCHAR2(30);
BEGIN
   if pMasterTableName is null then
     return;
   end if;
   vMasterTableName := upper(pMasterTableName);
   insert into tmp_ext_cod_coresp(nume_tabela_master, old_code, new_code)
          values (vMasterTableName, coalesce(oldCode,0), newCode);
END;

PROCEDURE EXT_POSTRECORDS_INIT (pTipDoc IN NUMBER) IS
  vTableName                    VARCHAR2(30);
  vPrefixSchema                 VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  vTmpTableName                 VARCHAR2(30);
  vTableNameWithSchema          VARCHAR2(255);
  vTmpTableNameWithSchema       VARCHAR2(255);
  vTmpMasterTableNameWithSchema VARCHAR2(255);
  cSQL                          CLOB;  
  tipDoc                        NUMBER(20);
  rc                            SYS_REFCURSOR;
  v_rec                         tmp_extcfgtable%ROWTYPE;
BEGIN
  DELETE FROM tmp_ext_cod_coresp;
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  rc := get_cfgtable_by_tip_doc(tipDoc);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;
    vTableName := v_rec.nume_tabela;
    if vTableName is null or v_rec.master_table is null 
    then continue;
    end if;
      vTmpTableName                 := &apos;TMP_&apos; || vTableName;
      vTableNameWithSchema          := vPrefixSchema||vTableName;
      vTmpTableNameWithSchema       := vPrefixSchema||vTmpTableName;
      vTmpMasterTableNameWithSchema := vPrefixSchema||&apos;TMP_&apos;||v_rec.master_table;
      IF (PKG_LIST_STRUCT.TmpExists(vTableName) = 1) AND (PKG_LIST_STRUCT.TmpExists(vTmpTableName) = 1) THEN
        -- sterg inregistrarile care nu mai exista in temporarul master
        cSQL := &apos;DELETE FROM &apos;||vTmpTableNameWithSchema||&apos; ext_tmp &apos;||
                &apos;WHERE ext_tmp.&apos;||v_rec.link_key||&apos; NOT IN (SELECT  master_tmp.&apos;||v_rec.link_key||&apos; FROM &apos;||vTmpMasterTableNameWithSchema||&apos; master_tmp) &apos;;
        EXECUTE IMMEDIATE cSQL;
      END IF;
  END LOOP;
  CLOSE rc;
END;

PROCEDURE EXT_INSERTRECORD (pTipDoc IN NUMBER) IS
  vTableName                    VARCHAR2(30);
  vPrefixSchema                 VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  vTmpTableName                 VARCHAR2(30);
  vtmpTableNameIni              VARCHAR2(30);
  vTmpTableNameWithSchema       VARCHAR2(255);
  vTmpTableNameIniWithSchema    VARCHAR2(255);
  tipDoc                        NUMBER(20);
  rc                            SYS_REFCURSOR;
  v_rec                         tmp_extcfgtable%ROWTYPE;
BEGIN
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  rc := get_cfgtable_by_tip_doc(tipDoc);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;
    vTableName := v_rec.nume_tabela;
    if vTableName is null or v_rec.master_table is null then 
      continue;
    end if;

    vTmpTableName              := &apos;TMP_&apos; || vTableName;
    vtmpTableNameIni           := &apos;TMP_&apos; || vTableName ||&apos;_INI&apos;;
    vTmpTableNameWithSchema    := vPrefixSchema||vTmpTableName;
    vTmpTableNameIniWithSchema := vPrefixSchema||vtmpTableNameIni;

    if (PKG_LIST_STRUCT.TmpExists(vTmpTableName) = 1) and (PKG_LIST_STRUCT.TmpExists(vtmpTableNameIni) = 1) THEN
      execute immediate &apos;DELETE FROM &apos; || vTmpTableNameWithSchema;
      execute immediate &apos;DELETE FROM &apos; || vTmpTableNameIniWithSchema;
    end if;
  end loop;
  CLOSE rc;
  commit;
END;

PROCEDURE EXT_GOTORECORD (pTipDoc IN NUMBER) IS
  vCodColumnName                VARCHAR2(30);
  vTableName                    VARCHAR2(30);
  vPrefixSchema                 VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  vTmpTableName                 VARCHAR2(30);
  vtmpTableNameIni              VARCHAR2(30);
  vTableNameWithSchema          VARCHAR2(255);
  vTmpTableNameWithSchema       VARCHAR2(255);
  vTmpTableNameIniWithSchema    VARCHAR2(255);
  vTmpMasterTableNameWithSchema VARCHAR2(255);
  tipDoc                        NUMBER(20);
  sListCols                     VARCHAR2(3200);
  sSQLTmpFieds                  VARCHAR2(3200);
  vExtTmpFields                 VARCHAR2(3200);
  columnsNotTemp                VARCHAR2(3200);
  rc                            SYS_REFCURSOR;
  v_rec tmp_extcfgtable%ROWTYPE;
BEGIN
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  rc := get_cfgtable_by_tip_doc(tipDoc);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;
    vTableName := v_rec.nume_tabela;
    if vTableName is null
      or v_rec.master_table is null then continue;
    end if;
    sListCols                     := &apos;&apos;;
    columnsNotTemp                := &apos;&apos;;
    vTmpTableName                 := &apos;TMP_&apos;||vTableName;
    vtmpTableNameIni              := &apos;TMP_&apos;||vTableName||&apos;_INI&apos;;
    vTableNameWithSchema          := vPrefixSchema||vTableName;
    vTmpTableNameWithSchema       := vPrefixSchema||vTmpTableName;
    vTmpTableNameIniWithSchema    := vPrefixSchema||vtmpTableNameIni;
    vTmpMasterTableNameWithSchema := vPrefixSchema||&apos;TMP_&apos;||v_rec.master_table;
    vCodColumnName := &apos;COD&apos; || vTableName;
    if (PKG_LIST_STRUCT.TmpExists(vTableName)       = 1) and 
        (PKG_LIST_STRUCT.TmpExists(vTmpTableName)    = 1) and 
        (PKG_LIST_STRUCT.TmpExists(vtmpTableNameIni) = 1) 
    THEN
      execute immediate &apos;DELETE FROM &apos; || vTmpTableNameWithSchema;
      execute immediate &apos;DELETE FROM &apos; || vTmpTableNameIniWithSchema;
      -- creez lista coloanelor pt insert
      for v_colList in (select * from USER_TAB_COLS where  TABLE_NAME = upper(vTableName) and COLUMN_ID is not null order by column_id)
      loop
        if (coalesce(v_colList.Column_Name, &apos;&apos;) = &apos;&apos;)
        or (lower(v_colList.Column_Name)  = lower (vCodColumnName) )
        or (lower(v_colList.Column_Name)  = lower (v_rec.link_key) )
        THEN
          continue;
        end if;
        sListCols := sListCols || &apos;, ext_t.&apos; || v_colList.Column_Name;
        columnsNotTemp := columnsNotTemp || &apos;, &apos; || v_colList.Column_Name;
      end loop;

      execute immediate
        &apos;INSERT INTO &apos; || vTmpTableNameWithSchema || &apos; (&apos; || vCodColumnName || &apos;, &apos; || v_rec.link_key || columnsNotTemp || &apos;) &apos;||
        &apos;SELECT coalesce (ext_t.&apos;||vCodColumnName||&apos; , (-1)*(10000+rownum)), master_t.&apos;|| v_rec.link_key || sListCols||&apos; &apos;||
        &apos;FROM &apos;|| vTableNameWithSchema ||&apos; ext_t &apos;||
        &apos;  RIGHT JOIN &apos;|| vTmpMasterTableNameWithSchema ||&apos; master_t on master_t.&apos;|| v_rec.link_key ||&apos; = ext_t.&apos; || v_rec.link_key;
        
      execute immediate 
        &apos;INSERT INTO &apos; || vTmpTableNameIniWithSchema || &apos; (&apos; || vCodColumnName ||&apos;,&apos;|| v_rec.link_key ||&apos;) &apos;||
        &apos;SELECT &apos; || vCodColumnName ||&apos;,&apos;|| v_rec.link_key ||&apos; from &apos; || vTmpTableNameWithSchema ;
        
      -- add data for tmp fields
      sSQLTmpFieds := GET_EXT_SQL_TMP(vTableName);
      IF sSQLTmpFieds IS NOT null THEN
         vExtTmpFields := GET_EXT_FIELDS(vTableName, 1);
         if(length(vExtTmpFields) &gt; 0) then
           execute immediate 
                   &apos;UPDATE &apos; || vTmpTableNameWithSchema || &apos; ext_tp &apos;||  
                           &apos; SET (&apos;|| vExtTmpFields ||&apos;) = (select &apos;|| vExtTmpFields 
                                                                    ||&apos; from (&apos;|| sSQLTmpFieds ||&apos;) tsql &apos; ||
                           &apos;                                            where ext_tp.&apos;||v_rec.link_key||&apos; = tsql.&apos;||v_rec.link_key||&apos;) &apos;;
         end if;          
      END IF;   
    end if;
  end loop;
  CLOSE rc;
END;

PROCEDURE EXT_POSTRECORDS (pTipDoc IN NUMBER, OPERATION IN NUMBER default 0) IS
  vCodColumnName                VARCHAR2(30);
  vTableName                    VARCHAR2(30);
  vPrefixSchema                 VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  vTmpTableName                 VARCHAR2(30);
  vtmpTableNameIni              VARCHAR2(30);
  vTableNameWithSchema          VARCHAR2(255);
  vTmpTableNameWithSchema       VARCHAR2(255);
  vTmpMasterTableNameWithSchema VARCHAR2(255);
  vTmpTableNameIniWithSchema    VARCHAR2(255);
  tipDoc                        NUMBER(20);
  rc                            SYS_REFCURSOR;
  v_rec                         tmp_extcfgtable%ROWTYPE;
  sListCols                     VARCHAR2(4000);
BEGIN
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  rc := get_cfgtable_by_tip_doc(tipDoc);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;
    vTableName := v_rec.nume_tabela;
    if vTableName is null
      or v_rec.master_table is null then continue;
    end if;

    vTmpTableName                 := &apos;TMP_&apos; || vTableName;
    vtmpTableNameIni              := &apos;TMP_&apos; || vTableName ||&apos;_INI&apos;;
    vTableNameWithSchema          := vPrefixSchema||vTableName;
    vTmpTableNameWithSchema       := vPrefixSchema||vTmpTableName;
    vTmpTableNameIniWithSchema    := vPrefixSchema||vtmpTableNameIni;
    vTmpMasterTableNameWithSchema := vPrefixSchema||&apos;TMP_&apos;||v_rec.master_table;
    vCodColumnName := &apos;COD&apos; || vTableName;
    sListCols := &apos;&apos;;
    if (PKG_LIST_STRUCT.TmpExists(vTableName) = 1) and 
      (PKG_LIST_STRUCT.TmpExists(vTmpTableName) = 1) 
    then
      --actualizez cod-urile de legatura
      execute immediate 
        &apos;UPDATE &apos;|| vTmpTableNameWithSchema || &apos; ext_t &apos;||
        &apos; SET &apos;|| v_rec.link_key ||&apos; = (select new_code from tmp_ext_cod_coresp ext_cc where upper(ext_cc.nume_tabela_master) = upper(&apos;&apos;&apos;||v_rec.master_table||&apos;&apos;&apos;) and ext_cc.old_code = coalesce(ext_t.&apos; || v_rec.link_key ||&apos;,0) ) &apos;||
        &apos; WHERE COALESCE (&apos;|| v_rec.link_key ||&apos; , 0) &lt;= 0&apos;;
        
        if (OPERATION = 0)  then
          -- sterg inregistrarile care nu mai sunt in temporar dar au fost initial (ar trebui sa fie cele sterse)
          EXECUTE IMMEDIATE &apos;DELETE FROM &apos;||vTableNameWithSchema || &apos; WHERE &apos; || vCodColumnName || &apos; IN (SELECT ini_t.&apos; || vCodColumnName || &apos; FROM &apos; || vTmpTableNameIniWithSchema || &apos; ini_t &apos; || 
                                                                                                              &apos;   LEFT JOIN &apos;|| vTmpTableNameWithSchema ||&apos; tmp &apos; ||
                                                                                                              &apos;      ON  ini_t.&apos; || vCodColumnName || &apos; = tmp.&apos; || vCodColumnName || 
                                                                                                              &apos;  WHERE tmp.&apos; || vCodColumnName ||&apos; IS NULL ) &apos; ;        
          --fac update pt inregistrarile existente
          sListCols := GET_EXT_FIELDS_FROM_TABLE(vTableName, vCodColumnName, v_rec.link_key, 0);
          if length(sListCols) &gt; 0 then 
            execute immediate 
              &apos;UPDATE &apos;|| vTableNameWithSchema || &apos; ext_t &apos;||
              &apos; SET (&apos;|| sListCols ||&apos;) = (select &apos;|| sListCols ||
                                                           &apos; from &apos;||vTmpTableNameWithSchema || &apos; ext_tmp &apos; ||
                                                           &apos; where ext_tmp.&apos; || vCodColumnName || &apos; = ext_t.&apos; || vCodColumnName || 
                                                           &apos;       and COALESCE ( ext_tmp.&apos;|| vCodColumnName || &apos; , 0) &gt;  0 ) &apos; ||
              &apos;  WHERE EXISTS (SELECT 1 FROM &apos;||vTmpTableNameWithSchema || &apos; ext_tmp where ext_tmp.&apos; || vCodColumnName || &apos; = ext_t.&apos; || vCodColumnName || &apos; and COALESCE ( ext_tmp.&apos;|| vCodColumnName || &apos; , 0) &gt;  0) &apos; ;
          end if;                  
          --sterg inregistrarile pt care am facut update .. cod &gt; 0       
          EXECUTE IMMEDIATE &apos;DELETE FROM &apos; || vTmpTableNameWithSchema || &apos; WHERE COALESCE(&apos;|| vCodColumnName || &apos; , 0) &gt; 0&apos;;
        end if;
      
        --actualizez codurile definitive
        execute immediate &apos;UPDATE &apos;|| vTmpTableNameWithSchema ||&apos; SET &apos;|| vCodColumnName ||&apos; = &apos;|| GET_EXT_SEQ_NAME(vTableName) ||&apos;.NEXTVAL WHERE COALESCE ( &apos;|| vCodColumnName || &apos; , 0) &lt;=  0 &apos;;
        -- copii din temporar
        execute immediate &apos;INSERT INTO &apos; || vTableNameWithSchema||&apos; SELECT &apos;||vCodColumnName||&apos;, &apos; || v_rec.link_key ||GET_EXT_FIELDS_FROM_TABLE(vTableName, vCodColumnName, v_rec.link_key) ||&apos; FROM &apos;||vTmpTableNameWithSchema;
        -- curat temorarul cu inregistrarile initiale
        execute immediate &apos;DELETE FROM &apos; || vTmpTableNameIniWithSchema;
      end if;
    end loop;
  CLOSE rc;
END;

FUNCTION EXT_GET_EQV_TIP_DOC(tipDoc IN NUMBER) RETURN NUMBER IS
  rTipDoc  NUMBER(20);
BEGIN
  CASE tipDoc
    WHEN 20 THEN rTipDoc := 19;
    WHEN 26 THEN rTipDoc := 19;
    WHEN 34 THEN rTipDoc := 27;
    WHEN 25 THEN rTipDoc := 10;
    -- mTargetClienti(65), mTargetFurnizori(98) --&gt; mTargetAgenti(17)
    WHEN 98 THEN rTipDoc := 17;
    WHEN 65 THEN rTipDoc := 17;
    --mColetDeRidicat(78), mColetCustodie(77), mColetIntern(86) --&gt; mColet (77)
    WHEN 78 THEN rTipDoc := 77;
    WHEN 86 THEN rTipDoc := 77;
   -- mCasa(29), mPers(33), mBancaCurent(30), mBancaCurs(31) --&gt; mTrezor (104)
    WHEN 29 THEN rTipDoc := 104;
    WHEN 30 THEN rTipDoc := 104;
    WHEN 31 THEN rTipDoc := 104;
    WHEN 33 THEN rTipDoc := 104;

    ELSE rTipDoc := tipDoc;
   END CASE;
   RETURN rTipDoc;
END;

PROCEDURE EXT_DELETERECORD (recId IN NUMBER, pTipDoc IN NUMBER) IS
  vTableNameParent VARCHAR2(30);
  vTableNameDetail VARCHAR2(30);
  vMasterTableName VARCHAR2(30);
  tipDoc NUMBER(20);
  rc SYS_REFCURSOR;
  rc_i SYS_REFCURSOR;
  v_rec        tmp_extcfgtable%ROWTYPE;
  v_recDetail  tmp_extcfgtable%ROWTYPE; 
BEGIN
  -- sterg extensiile legate la parent tip cfgSingleRecord si cfgMasterDetail
  tipDoc := EXT_GET_EQV_TIP_DOC(pTipDoc);
  
  rc := get_cfgtable_by_tip_doc(tipDoc, &apos;1,3&apos;);
  LOOP
    FETCH rc INTO v_rec;
    EXIT WHEN rc%NOTFOUND;

        if v_rec.nume_tabela is null
          or v_rec.link_key is null then continue;
        end if;
        vTableNameParent := v_rec.nume_tabela;
        if (PKG_LIST_STRUCT.TmpExists(vTableNameParent) = 1) then
              execute immediate &apos;DELETE FROM &apos; || vTableNameParent ||
                                           &apos; WHERE &apos; || v_rec.link_key || &apos; = to_char(&apos; || recId ||&apos;) &apos;;
        end if;
        -- sterg extensiile legate la linii tip cfgMultiRecord
          rc_i := get_cfgtable_by_tip_doc(tipDoc, &apos;2&apos;);
          LOOP
            FETCH rc_i INTO v_recDetail;
            EXIT WHEN rc_i%NOTFOUND;
                 if v_rec.nume_tabela is null
                      or v_rec.master_table is null
                      or v_rec.link_key is null then continue;
                  end if;
                   vTableNameDetail := v_recDetail.nume_tabela;
                   vMasterTableName := v_recDetail.master_table;
                   if (PKG_LIST_STRUCT.TmpExists(vTableNameDetail) = 1) then
                          execute immediate &apos;DELETE FROM &apos; || vTableNameDetail ||
                                                       &apos; WHERE &apos; || v_recDetail.link_key || &apos; in (select &apos; || v_recDetail.link_key ||
                                                       &apos;                                                            from &apos;|| vMasterTableName ||
                                                       &apos;                                                            where &apos; || v_rec.link_key || &apos; = to_char(&apos; || recId ||&apos;) ) &apos;;
                    end if;
          end loop;
          CLOSE rc_i;
   end loop;
   CLOSE rc;
END;

PROCEDURE CHECK_STRUCT_INI_EXT_ALL
IS
  vPrefixSchema    VARCHAR2(50)  := NULLIF(Trim(PKG_GLOBALS.FIRMANAME)||&apos;.&apos;, &apos;.&apos;);
  tmpTableNameIni  VARCHAR2(30);
  tmpTableName     VARCHAR2(30);
BEGIN
  for v_rec in (select * from tmp_extcfgtable cfg)
  loop
    tmpTableNameIni  := &apos;TMP_&apos; || v_rec.nume_tabela ||&apos;_INI&apos;;
    tmpTableName     := &apos;TMP_&apos; || v_rec.nume_tabela ;
    if PKG_LIST_STRUCT.TmpExists(tmpTableNameIni) = 0 THEN
      execute immediate &apos;CREATE GLOBAL TEMPORARY TABLE &apos;||vPrefixSchema||tmpTableNameIni||&apos;(COD&apos;||v_rec.nume_tabela || &apos; NUMBER(20), &apos;||v_rec.link_key|| &apos; NUMBER(20) ) ON COMMIT PRESERVE ROWS &apos;;
      PKG_CFGTABLES.SETGRANTMODUL(tmpTableNameIni, PKG_GLOBALS.FIRMANAME);
    else
      execute immediate &apos;DELETE FROM &apos;||vPrefixSchema||tmpTableNameIni;
    end if;
    if PKG_LIST_STRUCT.TmpExists(tmpTableName) = 1 THEN
      execute immediate &apos;DELETE FROM &apos;||vPrefixSchema||tmpTableName;
    end if;
  end loop;
END;

procedure Get_CFGActions(aTipDoc in number)
IS
BEGIN
  DELETE TMP_CFGActions;
	LocalTipDoc := aTipDoc;
  INSERT INTO TMP_CFGActions
  SELECT * FROM CFGActions WHERE TipDoc = aTipDoc;
  COMMIT;
END;

PROCEDURE POST_CFGActions
IS
  NR NUMBER;
  VCOD NUMBER;
BEGIN
    DELETE FROM CFGActions ACT 
		WHERE 
		ACT.TipDoc = LocalTipDoc 
		AND NOT EXISTS ( SELECT CodCFGActions FROM TMP_CFGActions TMP 
		                 WHERE TMP.CodCFGActions = ACT.CodCFGActions);

    FOR v_rec IN (SELECT * FROM TMP_CFGActions) LOOP
      IF NVL(v_rec.CodCFGActions, 0) &gt; 0 THEN
				UPDATE CFGActions
				SET
					tipDoc   = V_REC.tipDoc   ,
					tip      = V_REC.tip      ,
					Mesaj    = V_REC.Mesaj    ,
					sqlite   = V_REC.sqlite   ,
					Tipsql   = V_REC.Tipsql   , 
					ID       = V_REC.ID
				WHERE
					CODCFGActions = V_REC.CodCFGActions;
      ELSE
				INSERT INTO CFGActions( CodCFGActions, TipDoc, Tip, Mesaj, SQLite, Tipsql, ID)
				VALUES ( SEQ_CFGActions.NEXTVAL, V_REC.TipDoc, V_REC.Tip, V_REC.Mesaj, V_REC.SQLite, V_REC.Tipsql, V_REC.ID );
      END IF;
    END LOOP;
		
  COMMIT;
END;

procedure recreate_table(aTableName in varchar2) is
sSQL varchar2(10000);
sEXT varchar2(100);
begin
  if PKG_LIST_STRUCT.TmpExists(aTableName) = 1 then
    execute immediate &apos;drop table &apos;||aTableName;
  end if;  
  sSQL := &apos;CREATE TABLE &apos;||upper(aTableName)||&apos; (COD&apos;||aTableName||&apos; number(20), &apos;||LinkKey(UPPER(aTableName))||&apos; number(20)&apos;;
  for v_rec in 
  (
    select t1.numecamp, 
           substr(t1.tip,1,1) tip, 
           coalesce(t1.zecimale,0) zecimale,
           T1.MARIME
    from cfgtables t
         inner join cfgtables1 t1 on t.codcfgtable = t1.codcfgtable
    where UPPER(T.NUMETABELA) = UPPER(aTableName)
    order by t1.indexlocal
  ) loop
    sSQL := sSQL||&apos;, &apos;||v_rec.numecamp||&apos; &apos;;
    if v_rec.tip = &apos;N&apos; then 
      sEXT := &apos;number(20&apos;;
      if v_rec.zecimale &gt; 0 then
        sEXT := sEXT||&apos;,&apos;||to_char(v_rec.zecimale);
      end if;  
      sEXT := sEXT||&apos;)&apos;;
    else if v_rec.tip = &apos;A&apos; then 
      sEXT := &apos;VARCHAR2(&apos;;
      sEXT := sEXT||to_char(v_rec.marime);
      sEXT := sEXT||&apos;)&apos;;
    else if v_rec.tip = &apos;M&apos; then 
      sEXT := &apos;VARCHAR2(&apos;;
      sEXT := sEXT||to_char(v_rec.marime);
      sEXT := sEXT||&apos;)&apos;;
    else
      sEXT := &apos;DATE&apos;;
    end if;  
    end if;  
    end if;
    sSQL := sSQL||sEXT;  
  end loop;
  sSQL := sSQL||&apos;)&apos;;
  execute immediate sSQL;
end;

function LinkKey(aTableName in varchar2) return varchar2 is
rez varchar2(100);  
begin
  rez := 
  case 
    when aTableName = &apos;COMANDC&apos;     then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDC1&apos;    then &apos;CodComanda1&apos; 
    when aTableName = &apos;COMANDI&apos;     then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDI1&apos;    then &apos;CodComanda1&apos; 
    when aTableName = &apos;COMANDF&apos;     then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDF1&apos;    then &apos;CodComanda1&apos; 
    when aTableName = &apos;COMANDL&apos;     then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDL1&apos;    then &apos;CodComanda1&apos; 
    when aTableName = &apos;COMANDSA&apos;    then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDSA1&apos;   then &apos;CodComanda1&apos; 
    when aTableName = &apos;CMDSUBEXT&apos;   then &apos;CodComanda&apos;  
    when aTableName = &apos;CMDSUBEXT1&apos;  then &apos;CodComanda1&apos; 
    when aTableName = &apos;COMANDG&apos;     then &apos;CodComanda&apos;  
    when aTableName = &apos;COMANDG1&apos;    then &apos;CodComanda1&apos; 
    when aTableName = &apos;OFERTAEXT&apos;   then &apos;CodOferta&apos;   
    when aTableName = &apos;OFERTA1EXT&apos;  then &apos;CodOferta1&apos;  
    when aTableName = &apos;OFERTAFEXT&apos;  then &apos;CodOferta&apos;   
    when aTableName = &apos;OFERTAF1EXT&apos; then &apos;CodOferta1&apos;  
    when aTableName = &apos;CONTRACTF&apos;   then &apos;CodCONTRACT&apos; 
    when aTableName = &apos;CONTRACTF1&apos;  then &apos;CodCONTRACT1&apos;
    when aTableName = &apos;CONTRACTEXT&apos; then &apos;CodCONTRACT&apos; 
    when aTableName = &apos;CONTRACTC1&apos;  then &apos;CodCONTRACT1&apos;
    when aTableName = &apos;TARGETEXT&apos;   then &apos;CodTARGETAG&apos; 
    when aTableName = &apos;TARGET1EXT&apos;  then &apos;CodTARGETAG1&apos;
    when aTableName = &apos;INTRARIF&apos;    then &apos;CodIntr&apos;     
    when aTableName = &apos;INTRARIF1&apos;   then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRARIFA&apos;   then &apos;CodIntr&apos;     
    when aTableName = &apos;INTRARIFA1&apos;  then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRARIAE&apos;   then &apos;CodIntr&apos;     
    when aTableName = &apos;INTRARIAE1&apos;  then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRARICF&apos;   then &apos;CodIntr&apos;     
    when aTableName = &apos;INTRARICF1&apos;  then &apos;CodIntr1&apos;    
    when aTableName = &apos;INVOICEEXT&apos;  then &apos;CodIntr&apos;     
    when aTableName = &apos;INVOICE1EXT&apos; then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRAST&apos;     then &apos;CodIntr&apos;     
    when aTableName = &apos;INTR1AST&apos;    then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRFAST&apos;    then &apos;CodIntr&apos;     
    when aTableName = &apos;INTR1FAST&apos;   then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRPF&apos;      then &apos;CodIntr&apos;     
    when aTableName = &apos;INTR1PF&apos;     then &apos;CodIntr1&apos;    
    when aTableName = &apos;INTRSUB&apos;     then &apos;CodIntr&apos;     
    when aTableName = &apos;INTR1SUB&apos;    then &apos;CodIntr1&apos;    
    when aTableName = &apos;CERTIFC&apos;     then &apos;CodCertif&apos;   
    when aTableName = &apos;BCAREXT&apos;     then &apos;CodBCAR&apos;     
    when aTableName = &apos;IESIRIEXT&apos;   then &apos;CodIes&apos;      
    when aTableName = &apos;IESIRI1EXT&apos;  then &apos;CodIes1&apos;     
    when aTableName = &apos;PACHETEEXT&apos;  then &apos;CodPachete&apos;  
    when aTableName = &apos;TREZOREXT&apos;   then &apos;CodTrezor&apos;   
    when aTableName = &apos;TREZOR1EXT&apos;  then &apos;CodTrezor1&apos;  
    when aTableName = &apos;MONETAREXT&apos;  then &apos;CodIes&apos;      
    when aTableName = &apos;MONETAR1EXT&apos; then &apos;CodIes1&apos;     
    when aTableName = &apos;NSERTAREXT&apos;  then &apos;CodSertar&apos;   
    when aTableName = &apos;BANKCONTEXT&apos; then &apos;CODBANKCONT&apos; 
    when aTableName = &apos;PROIECTEXT&apos;  then &apos;CodProiect&apos;  
    when aTableName = &apos;RAPORTPDET&apos;  then &apos;CodRAportP&apos;  
    when aTableName = &apos;INTRARIP&apos;    then &apos;CodIntr&apos;     
    when aTableName = &apos;INTRARIP1&apos;   then &apos;CodIntr1&apos;    
    when aTableName = &apos;BONCONSEXT&apos;  then &apos;CodIes&apos;      
    when aTableName = &apos;BONCONS1EXT&apos; then &apos;CodIes1&apos;     
    when aTableName = &apos;IESSUB&apos;      then &apos;CodIes&apos;      
    when aTableName = &apos;IES1SUB&apos;     then &apos;CodIes1&apos;     
    when aTableName = &apos;IESBF&apos;       then &apos;CodIes&apos;     
    when aTableName = &apos;IES1BF&apos;      then &apos;CodIes1&apos;    
    when aTableName = &apos;DIMINEXT&apos;    then &apos;CodIes&apos;      
    when aTableName = &apos;DIMIN1EXT&apos;   then &apos;CodIes1&apos;     
    when aTableName = &apos;TRANSFEXT&apos;   then &apos;CodTransf&apos;   
    when aTableName = &apos;TRANSF1EXT&apos;  then &apos;CodTransf1&apos;  
    when aTableName = &apos;MARIRIEXT&apos;   then &apos;CodIes&apos;      
    when aTableName = &apos;MARIRI1EXT&apos;  then &apos;CodIes1&apos;     
    when aTableName = &apos;NARTOBJEXT&apos;  then &apos;CodObiect&apos;   
    when aTableName = &apos;NPARTDET&apos;    then &apos;CodPart&apos;     
    when aTableName = &apos;NPARTEXT&apos;    then &apos;CodPart&apos;     
    when aTableName = &apos;NAGENDAEXT&apos;  then &apos;CodAgenda&apos;   
    when aTableName = &apos;UTILAJEEXT&apos;  then &apos;CodUTILAJ&apos;    
    when aTableName = &apos;CENTREEXT&apos;   then &apos;CodCentru&apos;   
    when aTableName = &apos;NGESTEXT&apos;    then &apos;CodGest&apos;     
    when aTableName = &apos;NPERSEXT&apos;    then &apos;CodPers&apos;     
    when aTableName = &apos;NCONTEXT&apos;    then &apos;CodCont&apos;     
    when aTableName = &apos;NCONTSEXT&apos;   then &apos;CodConts&apos;    
    when aTableName = &apos;SETTASKEXT&apos;      then &apos;CodTask&apos;         
    when aTableName = &apos;NCEXT&apos;           then &apos;CodNC&apos;           
    when aTableName = &apos;NC1EXT&apos;          then &apos;CodNC1&apos;          
    when aTableName = &apos;FAZEXT&apos;          then &apos;CodFAZ&apos;          
    when aTableName = &apos;NPARCAUTEXT&apos;     then &apos;CODNPARCAUT&apos;     
    when aTableName = &apos;COMANDRAC&apos;       then &apos;CodComanda&apos;      
    when aTableName = &apos;COMANDRAC1&apos;      then &apos;CodComanda1&apos;     
    when aTableName = &apos;OPORTUNITATIEXT&apos; then &apos;CODOPORTUNITATE&apos; 
    when aTableName = &apos;PLATIEXT&apos;        then &apos;CODPLATA&apos;        
    when aTableName = &apos;MIFIX1EXT&apos;       then &apos;CODMIFIX1&apos;       
    when aTableName = &apos;CHELT1EXT&apos;       then &apos;CODCHELTAVANS1&apos;  
    when aTableName = &apos;VENIT1EXT&apos;       then &apos;CODCHELTAVANS1&apos;  
    when aTableName = &apos;RECLAMATIIEXT&apos;   then &apos;CodReclamatie&apos;   
    when aTableName = &apos;NCLASEAEXT&apos;      then &apos;CodClaseA&apos;       
    when aTableName = &apos;PRODCOMPEXT&apos;     then &apos;CodProdcomp&apos;
    when aTableName = &apos;LOCMUNCAEXT&apos;     then &apos;CodLoc&apos;
  end;          
  return rez;  
end;

function get_cfgtable_by_tip_doc(pTipDoc IN tmp_extcfgtable.tip_doc%TYPE,
                                          pStateList IN VARCHAR2 DEFAULT NULL) RETURN SYS_REFCURSOR IS
  rc SYS_REFCURSOR;
  sTipDoc VARCHAR2(2000);
BEGIN
  CASE pTipDoc
    WHEN 500 THEN sTipDoc := TO_CHAR(pTipDoc) || &apos;,520&apos;; -- la parteneri adaug si extensia de agenda
    ELSE sTipDoc := TO_CHAR(pTipDoc);
   END CASE; 
  OPEN rc FOR
    SELECT cfg.*
    FROM tmp_extcfgtable cfg 
    WHERE cfg.tip_doc IN (
      SELECT TO_NUMBER(REGEXP_SUBSTR(sTipDoc, &apos;[^,]+&apos;, 1, LEVEL))
      FROM dual
      CONNECT BY REGEXP_SUBSTR(sTipDoc, &apos;[^,]+&apos;, 1, LEVEL) IS NOT NULL
    ) AND (
             pStateList IS NULL
             OR cfg.state IN (
                 SELECT TO_NUMBER(REGEXP_SUBSTR(pStateList, &apos;[^,]+&apos;, 1, LEVEL))
                 FROM dual
                 CONNECT BY REGEXP_SUBSTR(pStateList, &apos;[^,]+&apos;, 1, LEVEL) IS NOT NULL)
             );
  
  RETURN rc;
END;

procedure ImportCfg is
aCod number(20);
aCod1 number(20);  
begin
  for v_rec in (select * from tmp_cfgtables_tmp) loop
    select seq_cfgtables_codcfgtable.nextval into aCod from dual;
    update tmp_cfgtables1_tmp set codcfgtable = aCod where codcfgtable = v_rec.codcfgtable;
    update tmp_cfgtables_tmp set codcfgtable = aCod where codcfgtable = v_rec.codcfgtable;
    insert into cfgtables
    (
      codcfgtable,
      numetabela,
      tipconfig,
      master,
      linkkey,
      tiplink,
      descriere,
      suplimsql
    )
    values
    (
      aCod,
      v_rec.numetabela,
      v_rec.tipconfig,
      v_rec.master,
      v_rec.linkkey,
      v_rec.tiplink,
      v_rec.descriere,
      v_rec.suplimsql
    );
  end loop;
  -- tmp_cfgtables este deja curatat si aici voi curata si 1 si 2
  delete tmp_cfgtables1_tmp where not codcfgtable in (select codcfgtable from tmp_cfgtables_tmp);
  for v_rec1 in (select * from tmp_cfgtables1_tmp) loop
    select seq_cfgtables1_codcfgtable1.nextval into aCod1 from dual;
    update tmp_cfgtables2_tmp set codcfgtable1 = aCod1 where codcfgtable1 = v_rec1.codcfgtable1;
    update tmp_cfgtables1_tmp set codcfgtable1 = aCod1 where codcfgtable1 = v_rec1.codcfgtable1;
    insert into cfgtables1(codcfgtable1,
                           codcfgtable,
                           indexlocal,
                           numecamp,
                           caption,
                           tip,
                           marime,
                           zecimale,
                           colwidth,
                           color,
                           obligatoriu,
                           nomlink,
                           lookupdisplay,
                           tipfiltruafis,
                           filtruafis,
                           hastotal,
                           tmp,
                           tobeupdated,
                           sqlonchange)
    values(
      aCod1,
      v_rec1.codcfgtable,
      v_rec1.indexlocal,
      v_rec1.numecamp,
      v_rec1.caption,
      v_rec1.tip,
      v_rec1.marime,
      v_rec1.zecimale,
      v_rec1.colwidth,
      v_rec1.color,
      v_rec1.obligatoriu,
      v_rec1.nomlink,
      v_rec1.lookupdisplay,
      v_rec1.tipfiltruafis,
      v_rec1.filtruafis,
      v_rec1.hastotal,
      v_rec1.tmp,
      v_rec1.tobeupdated,
      v_rec1.sqlonchange);
  end loop;
  delete tmp_cfgtables2_tmp where not codcfgtable1 in (select codcfgtable1 from tmp_cfgtables1_tmp);
  insert into cfgtables2(codcfgtable2,
                         codcfgtable1,
                         valoare)
  select
    seq_cfgtables2_codcfgtable2.nextval,
    codcfgtable1,
    valoare
  from tmp_cfgtables2_tmp;
  insert into cfgactions(codcfgactions,
                         tipdoc,
                         tipsql,
                         tip,
                         id,
                         sqlite,
                         mesaj)
  select
    seq_cfgactions.nextval,
    tipdoc,
    tipsql,
    tip,
    id,
    sqlite,
    mesaj
  from tmp_cfgactions_tmp;
  commit;
end;  

end PKG_CFGTABLES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24E5462B6FC008B95697A7D8826156AF2A848745</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CHELTAVANS IS

PROCEDURE SETTIPCHELTAVANS(ATIP IN NUMBER, aISVENIT IN NUMBER)
IS
BEGIN
  TIPCHELTAVANS := aTIP;
  VENITURI := aISVENIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  BEGIN
     CASE
       WHEN TIPCHELTAVANS = 0 THEN  
          SELECT CODINTR1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODINTR1 = RecId FOR UPDATE NOWAIT;
       WHEN TIPCHELTAVANS = 1 THEN 
          SELECT CODOBLIGPIF INTO Tmp FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = RecId FOR UPDATE NOWAIT;  
       WHEN TIPCHELTAVANS = 2 THEN 
          SELECT CODNC1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODNC1 = RecId FOR UPDATE NOWAIT;  
       WHEN TIPCHELTAVANS = 3 THEN   
          SELECT CODIES1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODIES1 = RecId FOR UPDATE NOWAIT;  
     END CASE;               
  
    EXCEPTION WHEN OTHERS THEN TMP := 0;

  END;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  NR NUMBER(10) := 0;
  aDoc varchar2(200);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (recId, case when coalesce(venituri,0) = 1 then 106 else 52 end);
  DELETE TMP_MANEVRA;

  FOR V_REC IN
  (SELECT
     CV.CODCHELTAVANS,
     CV1.CODCHELTAVANS1
   FROM
     CHELTAVANS1 CV1,
     CHELTAVANS CV
   WHERE
     RECID = ( CASE
                 WHEN TIPCHELTAVANS = 0 THEN CV.CODINTR1
                 WHEN TIPCHELTAVANS = 1 THEN CV.CODOBLIGPIF  
                 WHEN TIPCHELTAVANS = 2 THEN CV.CODNC1
                 WHEN TIPCHELTAVANS = 3 THEN CV.CODIES1  
                 ELSE -1
               END      
             )
     --CV.CODINTR1 = RECID
    AND CV.CODCHELTAVANS = CV1.CODCHELTAVANS
    AND CV1.ANSTART = PKG_GLOBALS.ANLUCRU AND LUNASTART = PKG_GLOBALS.LUNALUCRU
  )
  LOOP
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (V_REC.CODCHELTAVANS);
    DELETE CHELTAVANS1 WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
  END LOOP;

  FOR V_REC IN
   (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA )
  LOOP
    SELECT COUNT(*) INTO NR FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODUNIC;
    IF NR = 0 THEN
      DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_REC.CODUNIC;
--      DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = RECID;
    END IF;
  END LOOP;


  FOR V_REC IN
 (SELECT * FROM JURNAL J WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC in (52,106) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



  END LOOP;

  DELETE FROM JURNAL J   WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC in (52,106) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  DELETE FROM JURNAL1 J  WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC in (52,106) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;



  DELETE
  FROM
    CHELTAVANS AV
  WHERE
     RECID = ( CASE
                 WHEN TIPCHELTAVANS = 0 THEN AV.CODINTR1
                 WHEN TIPCHELTAVANS = 1 THEN AV.CODOBLIGPIF  
                 WHEN TIPCHELTAVANS = 2 THEN AV.CODNC1
                 WHEN TIPCHELTAVANS = 3 THEN AV.CODIES1  
                 ELSE -1
               END      
             )
    AND NVL((SELECT COUNT(*) FROM CHELTAVANS1 AV1 WHERE AV1.CODCHELTAVANS = AV.CODCHELTAVANS), 0) = 0;




  DELETE FROM  MASTERCHELTAVANS MAV
  WHERE
     RECID = ( CASE
                 WHEN TIPCHELTAVANS = 0 THEN CODINTR1
                 WHEN TIPCHELTAVANS = 1 THEN CODOBLIGPIF  
                 WHEN TIPCHELTAVANS = 2 THEN CODNC1
                 WHEN TIPCHELTAVANS = 3 THEN CODIES1  
                 ELSE -1
               END      
             )
    AND NVL((SELECT COUNT(*) FROM CHELTAVANS AV WHERE     
     RECID = ( CASE
                 WHEN TIPCHELTAVANS = 0 THEN CODINTR1
                 WHEN TIPCHELTAVANS = 1 THEN CODOBLIGPIF  
                 WHEN TIPCHELTAVANS = 2 THEN CODNC1
                 WHEN TIPCHELTAVANS = 3 THEN CODIES1  
                 ELSE -1
               END      
             )), 0) = 0;
    


/*

     IF TIPCHELTAVANS = 0 THEN 
       FOR V_RECINTR IN
       (SELECT I.CODINTR, CODINTR1
        FROM
          INTRARI  I,
          INTRARI1 I1
        WHERE
         I1.CODINTR1 = RECID  AND I.CODINTR = I1.CODINTR AND I.INITIALIZARI = 1) -- mereu in initializari amd doar legatura cu intrari sau iesiri
        LOOP
          DELETE FROM INTRARI1 WHERE CODINTR1 = V_RECINTR.CODINTR1;
          DELETE FROM INTRARI  WHERE CODINTR  = V_RECINTR.CODINTR;
        END LOOP;
     END IF;
     
     IF TIPCHELTAVANS = 3 THEN   
       FOR V_RECIES IN
       (SELECT I.CODIES, CODIES1
        FROM
          IESIRI  I,
          IESIRI1 I1
        WHERE
         I1.CODIES1 = RECID  AND I.CODIES = I1.CODIES AND I.INITIALIZARI = 1) -- mereu in initializari amd doar legatura cu intrari sau iesiri
        LOOP
          DELETE FROM IESIRI1 WHERE CODIES1 = V_RECIES.CODIES1;
          DELETE FROM IESIRI  WHERE CODIES  = V_RECIES.CODIES;
        END LOOP;
      END IF;
*/
--   END LOOP;


/*
  DELETE
  FROM
    MASTERCHELTAVANS MAV
  WHERE
    CODINTR1 = RECID AND NVL((SELECT COUNT(*) FROM CHELTAVANS AV WHERE AV.CODINTR1 = RECID), 0) = 0;
*/

  NotifyModif(2, RecId, &apos;MASTERCHELTAVANS&apos;);
  COMMIT;
END;



PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MASTERCHELTAVANS FIELDS(CODINTR1 ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(52); 
  PKG_CFGTABLES.EXT_INSERTRECORD(106); 
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  NR  NUMBER(7) := 0;
  aDATANOUA DATE := NULL;
	VC number;
  anLunaLucru     number;
  anInceput       number;
  lunaInceput     number;
  aTipDOC         number;
BEGIN

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  IF TIPCHELTAVANS = 0 THEN -- CODINTR1
    SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODINTR1 = RecId;
    IF RECID &gt; 0 AND NR = 0 THEN
      INSERT INTO MASTERCHELTAVANS (CODINTR1) VALUES (RECID);
    END IF;

    SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODINTR1 = RECID;
    IF RECID &gt; 0 AND NR = 0 THEN
          select 
            case when (extract(year from i.datadoc)*12+extract(month from i.datadoc)+1 &gt; anLunaLucru) then CASE WHEN extract(month from i.datadoc)+1 &gt; 12 THEN  extract(year from i.datadoc)+1 ELSE extract(year from i.datadoc) END
                                                                                                                      else PKG_GLOBALS.ANLUCRU end ,
            case when (extract(year from i.datadoc)*12+extract(month from i.datadoc)+1 &gt; anLunaLucru) then MOD(extract(month from i.datadoc)+1,12)
                                                                                                                      else PKG_GLOBALS.LUNALUCRU end 
            into anInceput, lunaInceput
          from INTRARI I
            join INTRARI1 I1 on I.CODINTR = I1.CODINTR
          where 
             I1.CODINTR1 = RECID;
          INSERT INTO CHELTAVANS (CODCHELTAVANS, 
                              CODINTR1, 
                              ANINCEPUT, 
                              LUNAINCEPUT, 
                              ISVENIT) 
                    VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, 
                            RECID, 
                            anInceput, 
                            lunaInceput, 
                            VENITURI);
    END IF;

    INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODINTR1 = RECID;

    INSERT INTO TMP_CHELTAVANS
    (CODCHELTAVANS,
     CODINTR1,
     ANINCEPUT,
     LUNAINCEPUT,
     CODIOART,
     CODGEST,
      DEN_GEST,
     CODSUBUNIT,
     NRDOC,
     DEN_PART,
     OBS,
     PREFIXDOC,
     SERIADOC,
     DATASTART,
     DATAEND,
     OBSERVATII,
     TIPINTERVAL, 
     ISVENIT,
     CODMIFIX)
     (SELECT
        CAV.CODCHELTAVANS,
        CAV.CODINTR1,
        CAV.ANINCEPUT,
        CAV.LUNAINCEPUT,
        CAV.CODIOART,
        G.CODGEST,
        G.DEN_GEST,
        I.SUBUNITATEA,
        I.NRDOC,
        P.DEN_PART,
        I1.OBS,
        I.PREFIXDOC,
        I.SERIADOC,
        CAV.DATASTART,
        CAV.DATAEND,
        CAV.OBSERVATII,
        0,  
        CAV.ISVENIT,
        CAV.CODMIFIX
      FROM
       CHELTAVANS CAV,
       INTRARI I,
       INTRARI1 I1
       LEFT OUTER JOIN NGEST G ON G.CODGEST = I1.GESTACT,
       NPART P
       WHERE
        CAV.CODINTR1 = RECID
        AND I1.CODINTR1 = RECID
        AND I.CODINTR = I1.CODINTR
        AND P.CODPART = I.PARTENER);
     ELSE
     IF TIPCHELTAVANS = 1 THEN --CODOBLIGPIF
       SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = RecId;
       IF RECID &gt; 0 AND NR = 0 THEN
         INSERT INTO MASTERCHELTAVANS (CODOBLIGPIF) VALUES (RECID);
       END IF;

       SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODOBLIGPIF = RECID;
       IF RECID &gt; 0 AND NR = 0 THEN
                 select 
                    case when (extract(year from t.datadoc)*12+extract(month from t.datadoc)+1 &gt; anLunaLucru) then CASE WHEN extract(month from t.datadoc)+1 &gt; 12 THEN  extract(year from t.datadoc)+1 ELSE extract(year from t.datadoc) END
                                                                                                                              else PKG_GLOBALS.ANLUCRU end ,
                    case when (extract(year from t.datadoc)*12+extract(month from t.datadoc)+1 &gt; anLunaLucru) then MOD(extract(month from t.datadoc)+1,12)
                                                                                                                              else PKG_GLOBALS.LUNALUCRU end 
                    into anInceput, lunaInceput
                  from          OBLIGPIF O
                      LEFT OUTER JOIN NGEST NG ON NG.CODGEST = O.CODGEST,
                      GENERAL G,
                      TREZOR1 T1,
                      TREZOR T
                   WHERE O.CODOBLIGPIF = RECID
                       AND G.CODGENERAL  = O.CODGENERAL
                       AND G.CODDOC      = T1.CODTREZOR1
                       AND T.CODTREZOR   = T1.CODTREZOR;

                  INSERT INTO CHELTAVANS (CODCHELTAVANS, 
                                CODOBLIGPIF, 
                                ANINCEPUT, 
                                LUNAINCEPUT, 
                                ISVENIT) 
                        VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, 
                                RECID, 
                                anInceput, 
                                lunaInceput, 
                                VENITURI);

       END IF;

       INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = RECID;

       INSERT INTO TMP_CHELTAVANS
       (CODCHELTAVANS,
        CODOBLIGPIF,
        ANINCEPUT,
        LUNAINCEPUT,
        CODIOART,
        CODGEST,
         DEN_GEST,
        CODSUBUNIT,
        NRDOC,
        OBS,
        PREFIXDOC,
        DATASTART,
        DATAEND,
        OBSERVATII,
        TIPINTERVAL,
        ISVENIT,
        CODMIFIX
        )
        (SELECT
           CAV.CODCHELTAVANS,
           CAV.CODOBLIGPIF,
           CAV.ANINCEPUT,
           CAV.LUNAINCEPUT,
           CAV.CODIOART,
           NG.CODGEST,
           NG.DEN_GEST,
           T.SUBUNITATEA,
           T1.NRDOC,
           T1.OBS,
           SUBSTR(T1.DOC, 1, 2),
           CAV.DATASTART,
           CAV.DATAEND,
           CAV.OBSERVATII,
           0,  
           CAV.ISVENIT,
           CAV.CODMIFIX
         FROM
          CHELTAVANS CAV,
          OBLIGPIF O
          LEFT OUTER JOIN NGEST NG ON NG.CODGEST = O.CODGEST,
          GENERAL G,
          TREZOR1 T1,
          TREZOR T
          WHERE
           CAV.CODOBLIGPIF   = RECID
           AND O.CODOBLIGPIF = RECID
           AND G.CODGENERAL  = O.CODGENERAL
           AND G.CODDOC      = T1.CODTREZOR1
           AND T.CODTREZOR   = T1.CODTREZOR
           );
     ELSE
      IF TIPCHELTAVANS = 3 THEN -- CODIES1
        SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODIES1 = RecId;
        IF RECID &gt; 0 AND NR = 0 THEN
          INSERT INTO MASTERCHELTAVANS (CODIES1) VALUES (RECID);
        END IF;

        SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODIES1 = RECID;
        IF RECID &gt; 0 AND NR = 0 THEN
            select 
                    case when (extract(year from i.datadoc)*12+extract(month from i.datadoc)+1 &gt; anLunaLucru) then CASE WHEN extract(month from i.datadoc)+1 &gt; 12 THEN  extract(year from i.datadoc)+1 ELSE extract(year from i.datadoc) END
                                                                                                                              else PKG_GLOBALS.ANLUCRU end ,
                    case when (extract(year from i.datadoc)*12+extract(month from i.datadoc)+1 &gt; anLunaLucru) then MOD(extract(month from i.datadoc)+1,12)
                                                                                                                              else PKG_GLOBALS.LUNALUCRU end 
                    into anInceput, lunaInceput
                  from  IESIRI I
                        join IESIRI1 I1 on I.CODIES= I1.CODIES
                   WHERE I1.CODIES1 = RECID;
           INSERT INTO CHELTAVANS (CODCHELTAVANS, 
                                  CODIES1, 
                                  ANINCEPUT, 
                                  LUNAINCEPUT, 
                                  ISVENIT) 
                    VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, 
                            RECID, 
                            anInceput, 
                            lunaInceput,
                            VENITURI);
         
        END IF;

        INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODIES1 = RECID;

        BEGIN
          SELECT TIPDOC INTO aTIPDOC FROM IESIRI I, IESIRI1 I1 WHERE I1.CODIES1 = RECID AND I1.CODIES = I.CODIES;
          EXCEPTION WHEN OTHERS THEN aTIPDOC := 0;
        END;
        IF NVL(aTIPDOC, 0) = 15 THEN
          INSERT INTO TMP_CHELTAVANS
            (CODCHELTAVANS,
             CODIES1,
             ANINCEPUT,
             LUNAINCEPUT,
             CODIOART,
             CODGEST,
              DEN_GEST,
             CODSUBUNIT,
             NRDOC,
             DEN_PART,
             OBS,
             PREFIXDOC,
             SERIADOC,
             DATASTART,
             DATAEND,
             OBSERVATII,
             TIPINTERVAL,
             ISVENIT,
             CODMIFIX)
           (SELECT
              CAV.CODCHELTAVANS,
              CAV.CODIES1,
              CAV.ANINCEPUT,
              CAV.LUNAINCEPUT,
              CAV.CODIOART,
              G.CODGEST,
              G.DEN_GEST,
              I.SUBUNITATEA,
              I.NRDOC,
              NULL,
              I1.OBS,
              I.PREFIXDOC,
              I.SERIADOC,
              CAV.DATASTART,
              CAV.DATAEND,
              CAV.OBSERVATII,
              0,  
              CAV.ISVENIT,
              CAV.CODMIFIX
            FROM
              CHELTAVANS CAV,
              IESIRI I,
              IESIRI1 I1
              LEFT JOIN (SELECT L1.CODIES1, NG.CODGEST, NG.DEN_GEST, NG.CODSUBUNIT 
                         FROM 
                           LIVR L, 
                           LIVR1 L1, 
                           NIRSTOC NS, 
                           NIR N, 
                           NGEST NG 
                         WHERE  
                           L.TIPLIVR = 15
                           AND  L1.CODLIVR = L.CODLIVR
                           AND NS.CODNIRSTOC = L1.CODNIRSTOC
                           AND N.CODNIR = NS.CODNIR
                           AND NG.CODGEST = N.GEST
                         ) G  ON G.CODIES1 = I1.CODIES1 AND ROWNUM = 1
            WHERE
              CAV.CODIES1 = RECID
              AND I1.CODIES1 = RECID
              AND I.CODIES= I1.CODIES
              );
        ELSE  
          INSERT INTO TMP_CHELTAVANS
          (CODCHELTAVANS,
           CODIES1,
           ANINCEPUT,
           LUNAINCEPUT,
           CODIOART,
           CODGEST,
            DEN_GEST,
           CODSUBUNIT,
           NRDOC,
           DEN_PART,
           OBS,
           PREFIXDOC,
           SERIADOC,
           DATASTART,
           DATAEND,
           OBSERVATII,
           TIPINTERVAL,
           ISVENIT,
           CODMIFIX)
           (SELECT
              CAV.CODCHELTAVANS,
              CAV.CODIES1,
              CAV.ANINCEPUT,
              CAV.LUNAINCEPUT,
              CAV.CODIOART,
              G.CODGEST,
              G.DEN_GEST,
              I.SUBUNITATEA,
              I.NRDOC,
              P.DEN_PART,
              I1.OBS,
              I.PREFIXDOC,
              I.SERIADOC,
              CAV.DATASTART,
              CAV.DATAEND,
              CAV.OBSERVATII,
              0,  
              CAV.ISVENIT,
              CAV.CODMIFIX
            FROM
             CHELTAVANS CAV,
             IESIRI I,
             IESIRI1 I1
             LEFT OUTER JOIN NGEST G ON G.CODGEST = I1.GESTACT,
             NPART P
             WHERE
              CAV.CODIES1 = RECID
              AND I1.CODIES1 = RECID
              AND I.CODIES= I1.CODIES
              AND P.CODPART = I.PARTENER);
          END IF;  
         ELSE -- legatura NC1
        SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODNC1 = RecId;
        IF RECID &gt; 0 AND NR = 0 THEN
          INSERT INTO MASTERCHELTAVANS (CODNC1) VALUES (RECID);
        END IF;

        SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODNC1 = RECID;
        IF RECID &gt; 0 AND NR = 0 THEN
          select 
                    case when (extract(year from n.datadoc)*12+extract(month from n.datadoc)+1 &gt; anLunaLucru) then CASE WHEN extract(month from n.datadoc)+1 &gt; 12 THEN  extract(year from n.datadoc)+1 ELSE extract(year from n.datadoc) END
                                                                                                                              else PKG_GLOBALS.ANLUCRU end ,
                    case when (extract(year from n.datadoc)*12+extract(month from n.datadoc)+1 &gt; anLunaLucru) then MOD(extract(month from n.datadoc)+1,12)
                                                                                                                              else PKG_GLOBALS.LUNALUCRU end 
                    into anInceput, lunaInceput
                  from  NC1 N1
                        LEFT OUTER JOIN NGEST NG ON NG.CODGEST = N1.CODGEST,
                        NC N
                WHERE N1.CODNC1 = RECID
                    AND N.CODNC   = N1.CODNC;
          INSERT INTO CHELTAVANS (CODCHELTAVANS, 
                                  CODNC1, 
                                  ANINCEPUT, 
                                  LUNAINCEPUT, 
                                  ISVENIT) 
                                VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, 
                                        RECID,
                                        anInceput, 
                                        lunaInceput,
                                        VENITURI);

        END IF;

        INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODNC1 = RECID;

        INSERT INTO TMP_CHELTAVANS
        (CODCHELTAVANS,
         CODNC1,
         ANINCEPUT,
         LUNAINCEPUT,
         CODIOART,
         CODGEST,
          DEN_GEST,
         CODSUBUNIT,
         NRDOC,
         OBS,
         PREFIXDOC,
         DATASTART,
         DATAEND,
         OBSERVATII,
         TIPINTERVAL,
         ISVENIT,
         CODMIFIX
         )
         (SELECT
            CAV.CODCHELTAVANS,
            CAV.CODNC1,
            CAV.ANINCEPUT,
            CAV.LUNAINCEPUT,
            CAV.CODIOART,
            NG.CODGEST,
            NG.DEN_GEST,
            N.SUBUNITATEA,
            N.NRDOC,
            N1.OBS,
            &apos;NC&apos;,
            CAV.DATASTART,
            CAV.DATAEND,
            CAV.OBSERVATII,
            0, 
            CAV.ISVENIT,
            CAV.CODMIFIX
          FROM
            CHELTAVANS CAV,
            NC1 N1
            LEFT OUTER JOIN NGEST NG ON NG.CODGEST = N1.CODGEST,
            NC N
          WHERE
            CAV.CODNC1    = RECID
            AND N1.CODNC1 = RECID
            AND N.CODNC   = N1.CODNC
            );
   END IF;
 END IF;
 END IF;


  INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD, CODAUTO, DATAENDNOUA, DATAENDBLOCATA,
                              CODGEST, CODCMDINT1, NRCMD, CENTRUBLOCAT, CODGESTBLOCAT, CODANALIZABLOCAT)
  SELECT AV1.CODCHELTAVANS1,AV1.CODCHELTAVANS,AV1.VALOARE,AV1.DURATAN,AV1.DURATAF,AV1.DFBLOCAT,AV1.ANSTART,AV1.LUNASTART,AV1.AMO,AV1.CODCENTRU,AV1.CODANALIZANOD,AV1.CODAUTO,AV1.DATAENDNOUA,AV1.DATAENDBLOCATA,
         AV1.CODGEST,AV1.CODCMDINT1,C.NRDOC, AV1.CENTRUBLOCAT, AV1.CODGESTBLOCAT, AV1.CODANALIZABLOCAT
  FROM CHELTAVANS1 AV1
       LEFT JOIN COMANDA1 C1 ON AV1.CODCMDINT1 = C1.CODCOMANDA1
       LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  WHERE AV1.ANSTART = PKG_GLOBALS.ANLUCRU AND AV1.LUNASTART = PKG_GLOBALS.LUNALUCRU
        AND EXISTS (SELECT AV.CODCHELTAVANS FROM TMP_CHELTAVANS AV WHERE AV.CODCHELTAVANS = AV1.CODCHELTAVANS);

	INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  J WHERE TIPDOC in (52,106) AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC)  AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 J WHERE TIPDOC in (52,106) AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

  DELETE TMP_RULAJ;
  DELETE TMP_MIFIX_INITIAL;
  INSERT INTO TMP_MIFIX_INITIAL (CODMIFIX) SELECT CODCHELTAVANS FROM TMP_CHELTAVANS;

  UPDATE TMP_CHELTAVANS
  SET
    TIPINTERVAL = 1
  WHERE
    DATASTART IS NOT NULL
    AND
  (
    DATAEND IS NOT NULL
    OR (SELECT COUNT(*) FROM TMP_CHELTAVANS1 WHERE DATAENDNOUA IS NOT NULL) &gt; 0
  );

  BEGIN
    SELECT DATAENDNOUA INTO aDATANOUA FROM TMP_CHELTAVANS1;
    EXCEPTION WHEN OTHERS THEN aDATANOUA := NULL;
  END;
  IF aDATANOUA IS NOT NULL THEN
    UPDATE TMP_CHELTAVANS
    SET
      DATAEND = aDATANOUA;
  END IF;

  UPDATE TMP_CHELTAVANS1 A1
  SET
    CODANALIZA = (SELECT CODANALIZA FROM ANALIZANOD N WHERE N.CODANALIZANOD = A1.CODANALIZANOD);
  PKG_CFGTABLES.EXT_GOTORECORD(case when coalesce(venituri,0) = 1 then 106 else 52 end);    
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  ACOD             NUMBER(20);
  NR               NUMBER(7) := 0;
  ORIGINAL_DATAEND DATE := NULL;
  vCOD             NUMBER(20);

BEGIN
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (case when coalesce(venituri,0) = 1 then 106 else 52 end);
  IF OPERATION = 0 THEN  -- UPDATE
    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS) LOOP
      IF V_REC.CODCHELTAVANS &lt; 0 THEN
        SELECT SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL INTO ACOD FROM DUAL;
        UPDATE TMP_CHELTAVANS1 SET CODCHELTAVANS = ACOD;
        UPDATE TMP_JURNAL  SET CODDOC = ACOD;
        UPDATE TMP_JURNAL1 SET CODDOC = ACOD;

        IF TIPCHELTAVANS = 0 THEN
          INSERT INTO CHELTAVANS (CODCHELTAVANS, CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT, CODMIFIX)
          VALUES (ACOD, RECID, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT,  V_REC.CODIOART, V_REC.DATASTART, V_REC.DATAEND, V_REC.OBSERVATII, VENITURI, V_REC.CODMIFIX);
        ELSE
         IF TIPCHELTAVANS = 1 THEN
           INSERT INTO CHELTAVANS (CODCHELTAVANS, CODOBLIGPIF, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT, CODMIFIX)
           VALUES (ACOD, RECID, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT,  V_REC.CODIOART, V_REC.DATASTART, V_REC.DATAEND, V_REC.OBSERVATII, VENITURI, V_REC.CODMIFIX);
         ELSE
         IF TIPCHELTAVANS = 3 THEN
           INSERT INTO CHELTAVANS (CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT, CODMIFIX)
           VALUES (ACOD, RECID, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT,  V_REC.CODIOART, V_REC.DATASTART, V_REC.DATAEND, V_REC.OBSERVATII, VENITURI, V_REC.CODMIFIX);
         ELSE
           INSERT INTO CHELTAVANS (CODCHELTAVANS, CODNC1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT, CODMIFIX)
           VALUES (ACOD, RECID, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT,  V_REC.CODIOART, V_REC.DATASTART, V_REC.DATAEND, V_REC.OBSERVATII, VENITURI, V_REC.CODMIFIX);
         END IF;
       END IF;
      END IF;
      ELSE


        UPDATE CHELTAVANS
        SET
          ANINCEPUT   = V_REC.ANINCEPUT,
          LUNAINCEPUT = V_REC.LUNAINCEPUT,
          CODIOART    = V_REC.CODIOART,
          DATASTART   = V_REC.DATASTART,
         -- DATAEND     = V_REC.DATAEND,
          OBSERVATII  = V_REC.OBSERVATII,
          CODMIFIX    = V_REC.CODMIFIX
        WHERE
         CODCHELTAVANS = V_REC.CODCHELTAVANS;

-- DISCUTIE MODIFICARE DATAEND
        BEGIN
          SELECT DATAEND INTO ORIGINAL_DATAEND FROM CHELTAVANS WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
          EXCEPTION WHEN OTHERS THEN ORIGINAL_DATAEND := NULL;
        END;


        SELECT COUNT(*) INTO NR
        FROM
          CHELTAVANS1
        WHERE
          CODCHELTAVANS = V_REC.CODCHELTAVANS
         AND ANSTART * 12 + LUNASTART &lt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


        IF ORIGINAL_DATAEND IS NOT NULL
           AND V_REC.DATAEND &lt;&gt; ORIGINAL_DATAEND
           AND NR = 0
        THEN
          UPDATE CHELTAVANS
          SET
            DATAEND = V_REC.DATAEND
          WHERE
            CODCHELTAVANS = V_REC.CODCHELTAVANS;
        END IF;

-- INCEPAND CU VERSIUNEA ASTA TIN DATAEND SI IN CHELTAVANS1 IN IDEEA CA SE SCHIMBA SI SE BLOCHEAZA
          UPDATE TMP_CHELTAVANS1
          SET
            DATAENDNOUA = V_REC.DATAEND
          WHERE
            CODCHELTAVANS = V_REC.CODCHELTAVANS;


      END IF;
    END LOOP;



    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1) LOOP
      IF V_REC.CODCHELTAVANS1 &lt; 0 THEN
        vCOD := SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;CHELTAVANS1&apos;, VCOD, V_REC.CODCHELTAVANS1);
        INSERT INTO CHELTAVANS1 (CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART,CODCENTRU, CODANALIZANOD, CODAUTO, DATAENDBLOCATA, DATAENDNOUA,
                                 CODGEST,CODCMDINT1, CENTRUBLOCAT, CODGESTBLOCAT,CODANALIZABLOCAT)
        VALUES (SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, V_REC.CODCHELTAVANS, V_REC.VALOARE, V_REC.DURATAN, V_REC.DURATAF, V_REC.DFBLOCAT, V_REC.AMO, V_REC.ANSTART, V_REC.LUNASTART,V_REC.CODCENTRU, V_REC.CODANALIZANOD, V_REC.CODAUTO, V_REC.DATAENDBLOCATA, V_REC.DATAENDNOUA,
                V_REC.CODGEST, V_REC.CODCMDINT1, V_REC.CENTRUBLOCAT, V_REC.CODGESTBLOCAT, V_REC.CODANALIZABLOCAT );
      ELSE
        UPDATE CHELTAVANS1
        SET
         VALOARE          = V_REC.VALOARE,
         DURATAN          = V_REC.DURATAN,
         DURATAF          = V_REC.DURATAF,
         DFBLOCAT         = V_REC.DFBLOCAT,
         AMO              = V_REC.AMO,
         ANSTART          = V_REC.ANSTART,
         LUNASTART        = V_REC.LUNASTART,
         CODCENTRU        = V_REC.CODCENTRU,
         CODANALIZANOD    = V_REC.CODANALIZANOD,
         CODAUTO          = V_REC.CODAUTO,
         DATAENDBLOCATA   = V_REC.DATAENDBLOCATA,
         DATAENDNOUA      = V_REC.DATAENDNOUA,
         CODGEST          = V_REC.CODGEST,
         CODCMDINT1       = V_REC.CODCMDINT1,
         CENTRUBLOCAT     = V_REC.CENTRUBLOCAT,
         CODGESTBLOCAT    = V_REC.CODGESTBLOCAT,
         CODANALIZABLOCAT = V_REC.CODANALIZABLOCAT
        WHERE
         CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
      END IF;
    END LOOP;
  END IF;

 -- DETAIL JURNALL1
  DELETE FROM JURNAL1 J1
  WHERE
    TIPDOC IN (52,106)
    AND AN = PKG_GLOBALS.ANLUCRU
    AND LUNA = PKG_GLOBALS.LUNALUCRU
    AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J1.CODDOC) AND NOT EXISTS
  ( SELECT CODJURNAL1 FROM TMP_JURNAL1 WHERE CODJURNAL1 = J1.CODJURNAL1);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET
      CODDOC       = V_REC.CODDOC,
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,

      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,

      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      CODCENTRU     = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT,
      DIRTY         = V_REC.DIRTY
    WHERE
      CODJURNAL1 = V_REC.CODJURNAL1;
   ELSE
     INSERT INTO JURNAL1
     (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
      CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD,
      ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,
      TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
      DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,
      DATADOC, DOCUMENT )
     VALUES
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,
      V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD,
      V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,
      V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
      V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA,
      V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD,
      V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;

  DELETE
  FROM
    JURNAL J
  WHERE
   TIPDOC IN (52,106)
   AND AN = PKG_GLOBALS.ANLUCRU
   AND LUNA = PKG_GLOBALS.LUNALUCRU
   AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J.CODDOC) AND NOT EXISTS
  (SELECT CODJURNAL FROM TMP_JURNAL WHERE CODJURNAL = J.CODJURNAL);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
   IF V_REC.CODJURNAL &gt; 0 THEN
    UPDATE JURNAL
    SET
      CODDOC     = V_REC.CODDOC,
      TIPDOC     = V_REC.TIPDOC,
      INDEXLOCAL = V_REC.INDEXLOCAL,
      CONTD      = V_REC.CONTD,
      CONTC      = V_REC.CONTC,
      GEST       = V_REC.GEST,
      VALOARE    = V_REC.VALOARE,
      VALOAREV   = V_REC.VALOAREV,
      OBS        = V_REC.OBS,
      AN         = V_REC.AN,
      LUNA       = V_REC.LUNA,
      SUBUNITATEA= V_REC.SUBUNITATEA,
      CODCENTRU  = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC    = V_REC.DATADOC,
      DOCUMENT   = V_REC.DOCUMENT
    WHERE
      CODJURNAL = V_REC.CODJURNAL;
   ELSE
   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA,
   CODCENTRU, CODANALIZANOD,
   DATADOC, DOCUMENT)
   VALUES
   ( SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA,
   V_REC.CODCENTRU, V_REC.CODANALIZANOD,
   V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;

-- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
    WHERE
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;
  END LOOP;

  IF TIPCHELTAVANS = 0 THEN
    SELECT CODINTR1 INTO RECID FROM TMP_MASTERCHELTAVANS;
  ELSE
    IF TIPCHELTAVANS = 1 THEN
      SELECT CODOBLIGPIF INTO RECID FROM TMP_MASTERCHELTAVANS;
    ELSE
      IF TIPCHELTAVANS = 3 THEN
        SELECT CODIES1 INTO RECID FROM TMP_MASTERCHELTAVANS;
      ELSE
        SELECT CODNC1 INTO RECID FROM TMP_MASTERCHELTAVANS;
      END IF;  
    END IF;
  END IF;
  PKG_GLOBALS.MARKDIRTYJURNAL;
  PKG_CFGTABLES.EXT_POSTRECORDS(case when coalesce(venituri,0) = 1 then 106 else 52 end); 
  NOTIFYMODIF(OPERATION, RECID, &apos;MASTERCHELTAVANS&apos;);
  COMMIT;
END;

PROCEDURE MAKE_TEMP_FOR_VIEWCHELTAVANS IS
  ATIPTVAMIXT VARCHAR2(10);
  NR          NUMBER(5);
  ANL         NUMBER(4);
  LUNAL       NUMBER(2);
  
BEGIN
  ANL   := PKG_GLOBALS.GETANLUCRU;
  LUNAL := PKG_GLOBALS.GETLUNALUCRU;
   
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CHELTAVANS_TREZOR&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CHELTAVANS_INTR&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CHELTAVANS_NC1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CHELTAVANS_SUB&apos;;

  -- STEF - TABELA CREATE PENTRU OPTIMIZARE - IN ANUMITE CONDITII FILTRAREA DUPA SUBUNITATE CREEAZA PROBLME CU CONDITIILE COMPUSE PLECAND DE LA PKG_GLOBALS.GETSUBUNITATE
  INSERT INTO TMP_CHELTAVANS_SUB (CODSUBUNIT)
  SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE WHERE COALESCE(CODSUBUNIT,1) = COALESCE(NULLIF(PKG_GLOBALS.GETSUBUNITATE, 1), CODSUBUNIT, 1);

  INSERT INTO TMP_CHELTAVANS_TREZOR(CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ)
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 100), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      0 AS CODINTR1, O.CODOBLIGPIF, 0 AS CODNC1, T1.DATADOC, T1.AN, T1.LUNA,
      CASE WHEN O.SEMNIFICATIE = 900 THEN &apos;DIRECT PE CHELTUIELI(TVA)&apos; ELSE &apos;DATORII, TAXE, IMPOZITE&apos; END AS DENUMIRE,
      NULL DEN_PART,
      COALESCE(O. VALOARE, 0) * COALESCE(NULLIF(G.CURS, 0), 1) - COALESCE(G.TVA, 0) AS VALOARE,
      CASE WHEN COALESCE(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE T.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, T1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM OBLIGPIF O
      INNER JOIN GENERAL G ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      INNER JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
      LEFT JOIN NGEST G ON G.CODGEST = O.CODGEST
      LEFT JOIN (
        SELECT NVL(CODOBLIGPIF, 0) AS REZOLVAT, CODOBLIGPIF, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM CHELTAVANS CAV, CHELTAVANS1 CAV1
        WHERE CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
          AND CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
      ) MAN ON  MAN.CODOBLIGPIF = O.CODOBLIGPIF
    WHERE O.SEMNIFICATIE IN (900, 950)
      AND O.ICONT IN (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS)
      AND T.OPERAT = 1 AND T1.ANULAT = 0
      AND T.AN * 12 + T.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE COALESCE(SUBUNITATEA,1) IN (SELECT CODSUBUNIT FROM TMP_CHELTAVANS_SUB);

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_CHELTAVANS_TREZOR CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS C INNER JOIN CHELTAVANS1 C1 ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODOBLIGPIF = CT.CODOBLIGPIF AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS C INNER JOIN CHELTAVANS1 C1 ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODOBLIGPIF = CT.CODOBLIGPIF AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  BEGIN
    SELECT PKG_CATEGCONST.GETVALCONSTANTA(&apos;TIPTVAMIXT100&apos;, ANL, LUNAL) INTO ATIPTVAMIXT FROM DUAL;
  EXCEPTION
    WHEN OTHERS THEN ATIPTVAMIXT := &apos;?&apos;;
  END;

  INSERT INTO TMP_CHELTAVANS_INTR(CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ )
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 100), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      I1.CODINTR1, 0 AS CODOBLIGPIF, 0 AS CODNC1, I.DATADOC, I.AN, I.LUNA, O.DENUMIRE, P.DEN_PART,
      ROUND (
        COALESCE(NULLIF(I.CURS, 0), 1) *
        CASE
          WHEN COALESCE(ATIPTVAMIXT, &apos;?&apos;) = &apos;2&apos; AND I.TIPDOC = 3 THEN I1.PU * I1.CANT - COALESCE(I1.TVA, 0)
          WHEN COALESCE(ATIPTVAMIXT, &apos;?&apos;) = &apos;2&apos;                  THEN I1.PU * I1.CANT
          WHEN I.TIPDOC = 3 AND I1.TVANEDED = 1                  THEN I1.PU * I1.CANT
          WHEN I.TIPDOC = 3 AND I1.TVANEDED = 3                  THEN I1.PU * I1.CANT - COALESCE(I1.TVA, 0) / 2
          WHEN I.TIPDOC = 3                                      THEN I1.PU * I1.CANT - COALESCE(I1.TVA, 0)
          WHEN I1.TVANEDED = 1                                   THEN I1.PU * I1.CANT + COALESCE(I1.TVA, 0)
          WHEN I1.TVANEDED = 3                                   THEN I1.PU * I1.CANT + COALESCE(I1.TVA, 0) / 2
          ELSE                                                        I1.PU * I1.CANT
        END, 2
      ) AS VALOARE,
      CASE WHEN COALESCE(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE I.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, I1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM INTRARI I
      INNER JOIN NPART P ON I.PARTENER  = P.CODPART
      INNER JOIN INTRARI1 I1 ON  I.CODINTR = I1.CODINTR
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
      LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
      LEFT JOIN (
        SELECT COALESCE(CODINTR1, 0) AS REZOLVAT, CODINTR1, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM CHELTAVANS CAV INNER JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
        WHERE CAV1.ANSTART = ANL AND CAV1.LUNASTART = LUNAL
      ) MAN ON  MAN.CODINTR1 = I1.CODINTR1
    WHERE I1.TIPLINIE   = &apos;S&apos;
      AND I1.CONTSERV IN (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS)
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN * 12 + I.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE 
    COALESCE(SUBUNITATEA,1) IN (SELECT CODSUBUNIT FROM TMP_CHELTAVANS_SUB);
    -- AND VALOARE &gt; 0;

  -- ANALIZA AVIZ / FACTURALAAVIZ SA VAD PE CARE DIN ELE LE ADUC
  FOR V_REC IN (
    SELECT CH.CODINTR1, IL.CODLINIEAVIZ
    FROM TMP_CHELTAVANS_INTR CH
      INNER JOIN INTRARI1 I1 ON CH.CODINTR1 = I1.CODINTR1
      INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR
      INNER JOIN INTRLINK IL ON IL.CODINTR1 = I1.CODINTR1
    WHERE I.TIPDOC = 9 AND CH.REZOLVAT = 0
  ) LOOP
    SELECT COUNT(1) INTO NR FROM TMP_CHELTAVANS_INTR WHERE CODINTR1 = V_REC.CODLINIEAVIZ AND REZOLVAT = 1;
    IF NR &gt; 0 THEN
      DELETE FROM TMP_CHELTAVANS_INTR WHERE CODINTR1 = V_REC.CODINTR1;
    END IF;

    SELECT COUNT(1) INTO NR
    FROM CHELTAVANS CA INNER JOIN CHELTAVANS1 CA1 ON CA1.CODCHELTAVANS = CA.CODCHELTAVANS
    WHERE CA.CODINTR1 = V_REC.CODLINIEAVIZ
      AND CA1.AMO &gt;= CA1.VALOARE;

    IF NR &gt; 0 THEN
      DELETE FROM TMP_CHELTAVANS_INTR WHERE CODINTR1 = V_REC.CODINTR1;
    END IF;
  END LOOP;

  FOR V_REC IN (
    SELECT CH.CODINTR1
    FROM TMP_CHELTAVANS_INTR CH
      INNER JOIN INTRARI1 I1 ON CH.CODINTR1 = I1.CODINTR1
      INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR
    WHERE I.TIPDOC = 2 AND CH.REZOLVAT = 0
  ) LOOP
    FOR V_REC_FA IN (SELECT CODINTR1 FROM INTRLINK IL WHERE IL.CODLINIEAVIZ = V_REC.CODINTR1)
    LOOP
      SELECT COUNT(1) INTO NR FROM TMP_CHELTAVANS_INTR WHERE CODINTR1 = V_REC_FA.CODINTR1 AND REZOLVAT = 1;

      IF NR &gt; 0 THEN
        DELETE FROM TMP_CHELTAVANS_INTR WHERE CODINTR1 = V_REC.CODINTR1;
      END IF;
    END LOOP;
  END LOOP;

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_CHELTAVANS_INTR CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODINTR1 = CT.CODINTR1 AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODINTR1 = CT.CODINTR1 AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  INSERT INTO TMP_CHELTAVANS_NC1(CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ )
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 100), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      0 AS CODINTR1, 0 AS CODOBLIGPIF, N1.CODNC1 , N.DATADOC, N.AN, N.LUNA, &apos;CHELT AVANS DIN NC &apos; AS DENUMIRE, P.DEN_PART,
      COALESCE(N1. VALOARE, 0) * COALESCE(NULLIF(N.CURS, 0), 1)  AS VALOARE,
      CASE WHEN COALESCE(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE N.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, N1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM NC1 N1
      INNER JOIN NC N ON N.CODNC = N1.CODNC
      LEFT JOIN NPART P ON P.CODPART = N.PART
      LEFT JOIN NGEST G ON G.CODGEST = N1.CODGEST
      LEFT JOIN (
        SELECT COALESCE(CODNC1, 0) AS REZOLVAT, CODNC1, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM CHELTAVANS CAV INNER JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
        WHERE CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
     ) MAN ON  MAN.CODNC1 = N1.CODNC1
  WHERE N1.CONTD IN (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS)
        AND COALESCE(N.SABLON, 0) = 0
    AND N.AN * 12 + N.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE COALESCE(SUBUNITATEA,1) IN (SELECT CODSUBUNIT FROM TMP_CHELTAVANS_SUB);

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_CHELTAVANS_NC1 CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODNC1 = CT.CODNC1 AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODNC1 = CT.CODNC1 AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  COMMIT;
END;

PROCEDURE MAKE_TEMP_FOR_VIEWVENITAVANS IS
  aTipTVAMixt VARCHAR2(10);
  NR          NUMBER(5);
  ANL         NUMBER(4);
  LUNAL       NUMBER(2);
  
BEGIN
  ANL   := PKG_GLOBALS.GETANLUCRU;
  LUNAL := PKG_GLOBALS.GETLUNALUCRU;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_VENITAVANS_TREZOR&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_VENITAVANS_IES&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_VENITAVANS_NC1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CHELTAVANS_SUB&apos;;

  -- stef - tabela create pentru optimizare - in anumite conditii filtrarea dupa subunitate creeaza problme cu conditiile compuse plecand de la PKG_GLOBALS.GETSUBUNITATE
  INSERT INTO TMP_CHELTAVANS_SUB (CODSUBUNIT)
  SELECT codsubunit FROM tmp_subunitdedicate WHERE Coalesce(codsubunit,1) = Coalesce(NullIF(PKG_GLOBALS.GETSUBUNITATE, 1), codsubunit, 1);


  INSERT INTO TMP_VENITAVANS_TREZOR(CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ)
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 100), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      0 AS CODINTR1, O.CODOBLIGPIF, 0 AS CODNC1, 0 AS CODIES1, T1.DATADOC, T1.AN, T1.LUNA,
      CASE WHEN O.SEMNIFICATIE = 901 THEN &apos;Direct pe venituri&apos; ELSE &apos;Imprumuturi si subventii&apos; END AS DENUMIRE,
      NULL DEN_PART,
      Coalesce(O. VALOARE, 0) * Coalesce(NullIF(G.CURS, 0), 1) - Coalesce(G.TVA, 0) AS VALOARE,
      CASE WHEN Coalesce(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE T.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, T1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM OBLIGPIF O
      INNER JOIN GENERAL G ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      INNER JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
      LEFT JOIN NGEST G ON G.CODGEST = O.CODGEST
      LEFT JOIN (
        SELECT NVL(CODOBLIGPIF, 0) AS REZOLVAT, CODOBLIGPIF, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM CHELTAVANS CAV, CHELTAVANS1 CAV1
        WHERE CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
          AND CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
      ) MAN ON  MAN.CODOBLIGPIF = O.CODOBLIGPIF
    WHERE O.SEMNIFICATIE IN (901, 951)
      AND O.ICONT IN (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS)
      AND T.OPERAT = 1 AND T1.ANULAT = 0
      AND T.AN * 12 + T.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE Coalesce(SUBUNITATEA,1) IN (SELECT codsubunit FROM TMP_CHELTAVANS_SUB);

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_VENITAVANS_TREZOR CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODOBLIGPIF = CT.CODOBLIGPIF AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODOBLIGPIF = CT.CODOBLIGPIF AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;TipTVAMixt100&apos;, ANL, LUNAL) INTO aTipTVAMixt from dual;
    EXCEPTION WHEN OTHERS THEN aTIPTVAMIXT := &apos;?&apos;;
  END;

  INSERT INTO TMP_VENITAVANS_IES(CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ)
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 90), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      0 AS CODINTR1, 0 AS CODOBLIGPIF, 0 AS CODNC1, I1.CODIES1, I.DATADOC, I.AN, I.LUNA, O.DENUMIRE, P.DEN_PART,
      ROUND(Coalesce(NullIF(I.CURS, 0), 1) * (I1.PU * I1.CANT), 2) AS VALOARE,
      CASE WHEN Coalesce(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE I.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, I1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM IESIRI I
      INNER JOIN NPART P ON I.TIPDOC IN (19, 20, 21, 26) AND I.PARTENER  = P.CODPART
      INNER JOIN IESIRI1 I1 ON  I.CODIES = I1.CODIES
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
      LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
      LEFT JOIN (
        SELECT NVL(CODIES1, 0) AS REZOLVAT, CODIES1, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM
          CHELTAVANS CAV,
          CHELTAVANS1 CAV1
        WHERE
          CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
          AND CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
          ) MAN ON  MAN.CODIES1 = I1.CODIES1
    WHERE I1.TIPLINIE   = &apos;S&apos;
      AND I1.CONTSERV IN (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS)
      AND I.OPERAT = 1 AND I.ANULAT = 0 
     AND I.AN * 12 + I.LUNA &lt;= ANL * 12 + LUNAL
     
    UNION ALL 
     
    SELECT -- mariri de stoc
      0 AS CODINTR1, 0 AS CODOBLIGPIF, 0 AS CODNC1, I1.CODIES1, I.DATADOC, I.AN, I.LUNA, O.DENUMIRE, NULL,
      ROUND(Coalesce(NullIF(I.CURS, 0), 1) * (I1.PU * I1.CANT), 2) AS VALOARE,
      CASE WHEN Coalesce(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE I.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, I1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON  I.CODIES = I1.CODIES
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
--      LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
      LEFT JOIN (SELECT L1.CODIES1, NG.CODGEST, NG.DEN_GEST, NG.CODSUBUNIT 
                 FROM 
                   LIVR L, 
                   LIVR1 L1, 
                   NIRSTOC NS, 
                   NIR N, 
                   NGEST NG 
                 WHERE  
                    L.TIPLIVR = 15
                   AND  L1.CODLIVR = L.CODLIVR
                   AND NS.CODNIRSTOC = L1.CODNIRSTOC
                   AND N.CODNIR = NS.CODNIR
                   AND NG.CODGEST = N.GEST
                   ) G  ON G.CODIES1 = I1.CODIES1 AND ROWNUM = 1
      LEFT JOIN (
        SELECT NVL(CODIES1, 0) AS REZOLVAT, CODIES1, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM
          CHELTAVANS CAV,
          CHELTAVANS1 CAV1
        WHERE
          CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
          AND CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
          ) MAN ON  MAN.CODIES1 = I1.CODIES1
    WHERE 
      I1.CONT IN (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS)
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 15
     AND I.AN * 12 + I.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE Coalesce(SUBUNITATEA,1) IN (SELECT codsubunit FROM TMP_CHELTAVANS_SUB);

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_VENITAVANS_IES CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODIES1 = CT.CODIES1 AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODIES1 = CT.CODIES1 AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  INSERT INTO TMP_VENITAVANS_NC1(CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, OBSCHELT, OBSDOC, DEN_GEST, CODGEST_REZ)
  SELECT CODINTR1, CODOBLIGPIF, CODNC1, CODIES1, DATADOC, AN, LUNA, DENUMIRE, DEN_PART, VALOARE, REZOLVAT, SUBSTRB(OBSCHELT,1, 100), SUBSTRB(OBSDOC,1, 100), SUBSTRB(DEN_GEST, 1, 100), CODGEST_REZ
  FROM (
    SELECT
      0 AS CODINTR1, 0 AS CODOBLIGPIF, N1.CODNC1 , 0 AS CODIES1, N.DATADOC, N.AN, N.LUNA, &apos;Venit avans din NC &apos; AS DENUMIRE, P.DEN_PART,
      Coalesce(N1. VALOARE, 0) * Coalesce(NullIF(N.CURS, 0), 1)  AS VALOARE,
      CASE WHEN Coalesce(REZOLVAT, 0) =  0 THEN  0 ELSE 1 END AS REZOLVAT,
      CASE WHEN NVL(G.CODGEST, 0) &lt;&gt; 0 THEN G.CODSUBUNIT ELSE N.SUBUNITATEA END SUBUNITATEA,
      OBSCHELT, N1.OBS AS OBSDOC, G.DEN_GEST, MAN.CODGEST_REZ
    FROM NC1 N1
      INNER JOIN NC N ON N.CODNC = N1.CODNC
      LEFT JOIN NPART P ON P.CODPART = N.PART
      LEFT JOIN NGEST G ON G.CODGEST = N1.CODGEST
      LEFT JOIN (
        SELECT Coalesce(CODNC1, 0) AS REZOLVAT, CODNC1, CAV.OBSERVATII AS OBSCHELT, CAV1.CODGEST AS CODGEST_REZ
        FROM CHELTAVANS CAV INNER JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
        WHERE CAV1.ANSTART   = ANL
          AND CAV1.LUNASTART = LUNAL
     ) MAN ON  MAN.CODNC1 = N1.CODNC1
    WHERE N1.CONTC IN (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS)
      AND COALESCE(N.SABLON, 0) = 0
      AND N.AN * 12 + N.LUNA &lt;= ANL * 12 + LUNAL
  )
  WHERE Coalesce(SUBUNITATEA,1) IN (SELECT codsubunit FROM TMP_CHELTAVANS_SUB);

  -- CERINTA SA DISPARA DIN VIEW CELE CARER S_AU AMORTIZAT IN LUNILE PRECEDENTE
  DELETE FROM TMP_VENITAVANS_NC1 CT
  WHERE     EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODNC1 = CT.CODNC1 AND C1.ANSTART * 12 + C1.LUNASTART &lt; ANL * 12 + LUNAL AND C1.AMO &gt;= C1.VALOARE)
    AND NOT EXISTS (SELECT 1 FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C1.CODCHELTAVANS = C.CODCHELTAVANS WHERE C.CODNC1 = CT.CODNC1 AND C1.ANSTART * 12 + C1.LUNASTART = ANL * 12 + LUNAL);

  COMMIT;
END;


end PKG_CHELTAVANS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CHELTAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B96469EFFE3241E930B1D6EC5701A0B27042869</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CHELTAVANS_INI IS
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20);
BEGIN
  BEGIN
    SELECT CODINTR1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODINTR1 = RecId FOR UPDATE NOWAIT;
    EXCEPTION WHEN OTHERS THEN TMP := 0;
  END;  
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  NR NUMBER(10) := 0;
  aDoc varchar2(200);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;  
  SP_LOCKRECORD(RecId);
  DELETE TMP_MANEVRA;
  
  FOR V_REC IN 
  (SELECT 
     CV.CODCHELTAVANS,   
     CV1.CODCHELTAVANS1   
   FROM 
     CHELTAVANS1 CV1, 
     CHELTAVANS CV 
   WHERE
    CV.CODINTR1 = RECID
    AND CV.CODCHELTAVANS = CV1.CODCHELTAVANS
  )
  LOOP
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (V_REC.CODCHELTAVANS);
    DELETE CHELTAVANS1 WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1; 
  END LOOP;
  
  FOR V_REC IN 
   (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA )
  LOOP
    DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_REC.CODUNIC;
  END LOOP;  

  DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = RECID;

 FOR V_RECINTR IN 
 (SELECT I.CODINTR, CODINTR1 
  FROM 
    INTRARI  I, 
    INTRARI1 I1
  WHERE
   I1.CODINTR1 = RECID  AND I.CODINTR = I1.CODINTR AND I.INITIALIZARI = 1)
  LOOP
    DELETE FROM INTRARI1 WHERE CODINTR1 = V_RECINTR.CODINTR1;
    DELETE FROM INTRARI  WHERE CODINTR  = V_RECINTR.CODINTR;
  END LOOP; 


  FOR V_REC IN 
 (SELECT * FROM JURNAL J WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 52 ) 
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  END LOOP;
   
  DELETE FROM JURNAL J   WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 52 ;  
  DELETE FROM JURNAL1 J  WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 52 ;  

  NotifyModif(2, RecId, &apos;MASTERCHELTAVANS&apos;);
  COMMIT;
END;



PROCEDURE SP_INSERTRECORD IS
BEGIN
  DELETE TMP_MIFIX_INITIAL;
  DELETE TMP_MASTERCHELTAVANS; 
  INSERT INTO  TMP_MASTERCHELTAVANS FIELDS(CODINTR1 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  NR  NUMBER(7) := 0;
BEGIN 
  IF RECID &gt; 0 THEN 
      SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE NVL(CODINTR1, 0) = RecId;
      
      IF RECID &gt; 0 AND NR = 0 THEN
        INSERT INTO MASTERCHELTAVANS (CODINTR1) VALUES (RECID);
      END IF;  

      SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODINTR1 = RECID;
      IF RECID &gt; 0 AND NR = 0 THEN
        INSERT INTO CHELTAVANS (CODCHELTAVANS, CODINTR1, ANINCEPUT, LUNAINCEPUT) VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, RECID, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
      END IF;  

      INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODINTR1 = RECID;  

      INSERT INTO TMP_CHELTAVANS
      (CODCHELTAVANS, 
       CODINTR1, 
       ANINCEPUT, 
       LUNAINCEPUT, 
       CODIOART, 
       CODGEST, 
        DEN_GEST, 
       CODSUBUNIT, 
       NRDOC, 
       DEN_PART, 
       OBS,
       CODPART,
       DATADOC,
       CODOBIECT,
       CONTSERV, 
       CODINTR,
       PREFIXDOC,
       SERIADOC,
       DATASTART,
       DATAEND,
       TIPINTERVAL,
       OBSERVATII
       )
       (SELECT 
          CAV.CODCHELTAVANS, 
          CAV.CODINTR1, 
          CAV.ANINCEPUT, 
          CAV.LUNAINCEPUT, 
          CAV.CODIOART,
          G.CODGEST,
          G.DEN_GEST,
          I.SUBUNITATEA,
          I.NRDOC,
          P.DEN_PART,
          I1.OBS,
          I.PARTENER,
          I.DATADOC,
          I1.CODOBIECT,
          I1.CONTSERV,
          I.CODINTR,
          I.PREFIXDOC,
          I.SERIADOC,
          CAV.DATASTART,
          CAV.DATAEND,
          0,
          CAV.OBSERVATII 
        FROM 
         CHELTAVANS CAV, 
         INTRARI I, 
         INTRARI1 I1
         LEFT OUTER JOIN NGEST G ON G.CODGEST = I1.GESTACT,
         NPART P
         WHERE 
          CAV.CODINTR1 = RECID
          AND I1.CODINTR1 = RECID
          AND I.CODINTR = I1.CODINTR
          AND P.CODPART = I.PARTENER);

      INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD)
      SELECT 
       CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD
       FROM CHELTAVANS1 AV1 WHERE ANSTART = PKG_GLOBALS.ANLUCRU AND LUNASTART = PKG_GLOBALS.LUNALUCRU AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);



      INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  J WHERE TIPDOC = 52 AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC)  AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
      INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 J WHERE TIPDOC = 52 AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

      DELETE TMP_RULAJ;



      DELETE TMP_MIFIX_INITIAL;
      INSERT INTO TMP_MIFIX_INITIAL (CODMIFIX) SELECT CODCHELTAVANS FROM TMP_CHELTAVANS;


      UPDATE TMP_CHELTAVANS
      SET
        TIPINTERVAL = 1
      WHERE
        DATASTART IS NOT NULL
        AND 
        DATAEND IS NOT NULL;

  END IF;
  COMMIT;
END;



PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  ACODINTR NUMBER(20); 
  ACOD     NUMBER(20); 
  ANI      NUMBER(5) := 0;
  LUNAI    NUMBER(2) := 0;
  NR       NUMBER(5) := 0;
BEGIN
  IF OPERATION = 0 THEN  -- UPDATE
    SELECT CODINTR1 INTO RECID FROM TMP_MASTERCHELTAVANS;  
    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS) LOOP
    
      UPDATE CHELTAVANS
      SET
        ANINCEPUT   = V_REC.ANINCEPUT,
        LUNAINCEPUT = V_REC.LUNAINCEPUT,
        CODIOART    = V_REC.CODIOART,
        DATASTART   = V_REC.DATASTART,
        DATAEND     = V_REC.DATAEND,
        OBSERVATII  = V_REC.OBSERVATII
      WHERE
       CODCHELTAVANS = V_REC.CODCHELTAVANS;
    
      UPDATE INTRARI
      SET
        PARTENER    = V_REC.CODPART,
        SUBUNITATEA = V_REC.CODSUBUNIT,
        NRDOC       = V_REC.NRDOC,
        DATADOC     = V_REC.DATADOC,
        SERIADOC    = V_REC.SERIADOC
      WHERE
        CODINTR = V_REC.CODINTR;
    
     UPDATE INTRARI1
     SET
       CODOBIECT = V_REC.CODOBIECT,
       GESTACT   = V_REC.CODGEST,
       CONTSERV  = V_REC.CONTSERV,
       CANT      = 1,
       OBS       = V_REC.OBS,
       PU        = (SELECT VALOARE FROM TMP_CHELTAVANS1)
     WHERE
       CODINTR1 = V_REC.CODINTR1;
    
    END LOOP;
  


    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1) LOOP

      UPDATE CHELTAVANS1
        SET
         VALOARE   = V_REC.VALOARE, 
         DURATAN   = V_REC.DURATAN, 
         DURATAF   = V_REC.DURATAF, 
         DFBLOCAT  = V_REC.DFBLOCAT, 
         AMO       = V_REC.AMO, 
         ANSTART   = V_REC.ANSTART, 
         LUNASTART = V_REC.LUNASTART
        WHERE
         CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
        
       UPDATE CHELTAVANS1
       SET 
         VALOARE = V_REC.VALOARE
       WHERE
        CODCHELTAVANS = V_REC.CODCHELTAVANS
        AND ANSTART * 12 + LUNASTART &gt; V_REC.ANSTART * 12 + V_REC.LUNASTART ;
    END LOOP;
  ELSE --INSERT  
  
     PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

     SELECT seq_INTRARI1_CODINTR1.NextVal INTO RecId FROM DUAL;
     SELECT seq_INTRARI_CODINTR.NextVal INTO aCODINTR FROM DUAL;
     
     INSERT INTO MASTERCHELTAVANS (CODINTR1) VALUES (RECID);
     INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, OPERAT, NRDOC, DATADOC, PARTENER, SUBUNITATEA, INITIALIZARI, AN, LUNA, SERIADOC, PREFIXDOC)
     (SELECT aCODINTR, 1, 0, 1, NRDOC, DATADOC, CODPART, CODSUBUNIT, 1, ANI, LUNAI, SERIADOC, &apos;F&apos; FROM TMP_CHELTAVANS); 
  
     INSERT INTO INTRARI1(CODINTR1, CODINTR, TIPLINIE, AN, LUNA, CONTSERV, GESTACT, CODOBIECT, PU, CANT, OBS)
     (SELECT RECID, aCODINTR, &apos;S&apos;, ANI, LUNAI, CONTSERV, CODGEST, CODOBIECT, (SELECT VALOARE FROM TMP_CHELTAVANS1), 1, OBS FROM TMP_CHELTAVANS); 
  

     SELECT SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL INTO ACOD FROM DUAL;
     UPDATE TMP_CHELTAVANS1 SET CODCHELTAVANS = ACOD;
     UPDATE TMP_JURNAL  SET CODDOC = aCOD, INDEXLOCAL = aCOD;
     UPDATE TMP_JURNAL1 SET CODDOC = aCOD, INDEXLOCAL = aCOD, IContBazaD = aCOD, IContBazaC = aCOD;
     
     
     INSERT INTO CHELTAVANS (CODCHELTAVANS, CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII)
     (SELECT ACOD, RECID, ANINCEPUT, LUNAINCEPUT,  CODIOART, DATASTART, DATAEND, OBSERVATII FROM TMP_CHELTAVANS);

      INSERT INTO CHELTAVANS1 (CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART)
     (SELECT SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART FROM TMP_CHELTAVANS1 );
  END IF;


 -- detail JURNAlL1
  DELETE FROM JURNAl1 J1
  WHERE 
    TIPDOC = 52 
    AND AN = PKG_GLOBALS.ANLUCRU 
    AND LUNA = PKG_GLOBALS.LUNALUCRU 
    AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J1.CODDOC) AND NOT EXISTS
  ( SELECT CODJURNAL1 FROM TMP_JURNAl1 WHERE CODJURNAL1 = J1.CODJURNAL1);
  
  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET 
      CODDOC       = V_REC.CODDOC,       
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,
  
      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,
  
      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA, 
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT
    WHERE 
      CODJURNAL1 = V_REC.CODJURNAl1; 
   ELSE
     INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT ) 
     VALUES 
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
   END IF; 
  END LOOP;
  
  DELETE  
  FROM 
    JURNAL J 
  WHERE 
   TIPDOC = 52 
   AND AN = PKG_GLOBALS.ANLUCRU 
   AND LUNA = PKG_GLOBALS.LUNALUCRU 
   AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J.CODDOC) AND NOT EXISTS 
  (SELECT CODJURNAL FROM TMP_JURNAL WHERE CODJURNAL = J.CODJURNAL);
  
  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
   IF V_REC.CODJURNAL &gt; 0 THEN
    UPDATE JURNAL
    SET  
      CODDOC     = V_REC.CODDOC,
      TIPDOC     = V_REC.TIPDOC, 
      INDEXLOCAL = V_REC.INDEXLOCAL, 
      CONTD      = V_REC.CONTD, 
      CONTC      = V_REC.CONTC,
      GEST       = V_REC.GEST,
      VALOARE    = V_REC.VALOARE, 
      VALOAREV   = V_REC.VALOAREV, 
      OBS        = V_REC.OBS, 
      AN         = V_REC.AN, 
      LUNA       = V_REC.LUNA,
      SUBUNITATEA= V_REC.SUBUNITATEA,
      DATADOC    = V_REC.DATADOC,
      DOCUMENT   = V_REC.DOCUMENT
    WHERE 
      CODJURNAL = V_REC.CODJURNAl; 
   ELSE
   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT)  
   VALUES
   ( SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
   END IF; 
  END LOOP;

-- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
  
    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;
 
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
    WHERE 
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  END LOOP;

  PKG_GLOBALS.MarkDirtyJurnal;
  NotifyModif(Operation, RecId, &apos;MASTERCHELTAVANS&apos;);  
  COMMIT;
END;  


end PKG_CHELTAVANS_INI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CHELTOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F06603F0426C0874704D2E44CDFF1F9054663A2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CHELTOPER is

   PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT codcheltoper
      INTO Tmp
      FROM cheltoper
     WHERE codcheltoper = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
  BEGIN
    SP_LOCKRECORD(RecId);
    DELETE FROM cheltoper1 WHERE codcheltoper = RecId;
    DELETE FROM cheltoper  WHERE codcheltoper = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO tmp_cheltoper FIELDS (codcheltoper) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
  BEGIN
    -- Master CHELTOPER
    INSERT INTO tmp_cheltoper
      (codcheltoper, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop)
      (SELECT codcheltoper, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop
         FROM cheltoper
        WHERE codcheltoper = RecId);
        
    -- DETAIL CHELTOPER1
    INSERT INTO tmp_cheltoper1
      (codcheltoper1,
       codcheltoper,
       codobiect,
       den_obiect,
       umsec,
       den_um,
       valoare,
       codextern,
       codintern,
       den_clasea)
      (SELECT co1.codcheltoper1,
                   co1.codcheltoper,
                   co1.codobiect,
                   nobj.denumire,
                   co1.umsec,
                   um1.den_um1,
                   co1.valoare,
                   nobj.codextern,
                   nobj.codintern,
                   cl.den_clasea
         FROM cheltoper1 co1
         join  nartobj nobj on  nobj.codobiect = co1.codobiect
         join num1 um1 on um1.codum1 = co1.umsec
         join nart art on art.codarticol = nobj.codarticol
         left join nclasea cl on cl.codclasea = art.clasa 
        WHERE co1.codcheltoper = RecId);
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    vCod NUMBER(20);
    an NUMBER(4);
    luna NUMBER(2);
    prevALStart NUMBER(10);
    nextALStart NUMBER(10);
    curALStart   NUMBER(10);
  BEGIN
    update TMP_CHELTOPER tch set tch.alstart = tch.lunastart + (tch.anstart * 12);
    select tch.anstart, tch.lunastart, tch.alstart into an, luna, curALStart from TMP_CHELTOPER tch;
    IF Operation = 0 THEN
      -- UPDATE
      -- Master CHELTOPER
      SELECT codcheltoper INTO RECID FROM TMP_CHELTOPER;

     
      UPDATE CHELTOPER
         SET (codcheltoper, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop) =
             (SELECT codcheltoper, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop
                FROM TMP_CHELTOPER)
       WHERE codcheltoper = RecId;

      DELETE FROM CHELTOPER1
       where codcheltoper = RecId
         and codcheltoper1 not in (Select ts0.codcheltoper1 from tmp_cheltoper1 ts0);

      UPDATE CHELTOPER1 s0
         SET (codcheltoper1, codcheltoper, codobiect, umsec, valoare) =
             (SELECT codcheltoper1, codcheltoper, codobiect, umsec, valoare
                FROM TMP_CHELTOPER1 ts
               WHERE ts.codcheltoper1 &gt; 0
                 and ts.codcheltoper1 = s0.codcheltoper1)
       WHERE s0.codcheltoper = RecId;

      for v_rec in (select * from TMP_CHELTOPER1 WHERE codcheltoper1 &lt; 0) loop
        select seq_cheltoper1_codcheltoper1.Nextval into vcod from dual;

        INSERT INTO CHELTOPER1
          (codcheltoper1, codcheltoper, codobiect, umsec, valoare)
        VALUES
          (vcod,
           RecId,
           v_rec.codobiect,
           v_rec.umsec,
           v_rec.valoare);
      end loop;
    ELSE
      -- INSERT
      SELECT seq_cheltoper_codcheltoper.NextVal INTO RecId FROM DUAL;
      -- Master CHELTOPER
      INSERT INTO CHELTOPER
        (codcheltoper, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop)
        (SELECT RecId, denumire, anstart, lunastart, anstop, lunastop, alstart, alstop FROM TMP_CHELTOPER);

      for v_rec in (select * from TMP_CHELTOPER1) loop
        select seq_cheltoper1_codcheltoper1.Nextval into vcod from dual;
        
        INSERT INTO CHELTOPER1
          (codcheltoper1, codcheltoper, codobiect, umsec, valoare)
        VALUES
          (vcod,
           RecId,
           v_rec.codobiect,
           v_rec.umsec,
           v_rec.valoare);
      end loop;
    END IF;
    begin
        select max(ch.alstart) into prevALStart from CHELTOPER ch where ch.alstart &lt; curALStart;
    exception 
      when others then prevALStart := null;
    end;
    begin
      select min(ch.alstart) into nextALStart from CHELTOPER ch where ch.alstart &gt; curALStart; 
    exception 
      when others then nextALStart := null;
    end;  
     if luna = 1 then 
        luna := 12;
        an   := an - 1;
     else 
        luna := luna-1;
     end if;
    if prevALStart is not null then
      UPDATE CHELTOPER ch
            set ch.lunastop = luna, ch.anstop = an, ch.alstop = an*12+luna 
       where ch.alstart = prevALStart;
    end if;
    if nextALStart is not null then
      select ch.anstart, ch.lunastart into an, luna from CHELTOPER ch where ch.alstart = nextALStart;
      if luna = 1 then 
          luna := 12;
          an   := an - 1;
       else 
          luna := luna-1;
       end if;
       UPDATE CHELTOPER ch
            set ch.lunastop = luna, ch.anstop = an, ch.alstop = an*12+luna 
       where ch.codcheltoper = RecId;
    end if;
    
    NotifyModif(Operation, RecId, &apos;CHELTOPER&apos;);
    COMMIT;
  END;
  
  

end PKG_CHELTOPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC77E26B99C36778D176AD44469028715DC1381A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEART IS

FUNCTION GetCodIdentParinte(aCodParinte in number) return varchar2 is
  aCodP number(20);
  aCodIdent varchar2(250);
BEGIN
  SELECT Coalesce(codparinte,0), CodIdent INTO aCodP, aCodIdent
  FROM nclasea
  WHERE CodClasea = aCodParinte;

  IF aCodP &gt; 0 THEN
    aCodIdent := GetCodIdentParinte(aCodP)||&apos;.&apos;||to_char(aCodParinte);
  END IF;
  RETURN aCodIdent;
end;

FUNCTION GetSimbolPred(aCodClasa in number, aNivel in number) return varchar2 is
i number(20);
aSimbol varchar2(50);
aCod number(20);
BEGIN
  if aNivel &lt;= 0 then
    begin
      select simbol into aSimbol from nclasea where codclasea = aCodClasa;
    exception when others then aSimbol := &apos;&apos;;
    end;
  else
    aCod := aCodClasa;
    for i in 1..aNivel loop
      begin
        select codparinte into aCod from nclasea where codclasea = aCod;
      exception when others then aCod := 0;
      end;
      if aCod = 0 then aSimbol := &apos;&apos;;
      else
        begin
          select simbol into aSimbol from nclasea where codclasea = aCod;
        exception when others then aSimbol := &apos;&apos;;
        end;
      end if;
    end loop;
  end if;

  RETURN aSimbol;
end;

PROCEDURE MakeCodIdent IS
BEGIN
  PRC_MakeCodIdent(&apos;NCLASEA&apos;,&apos;CODCLASEA&apos;);
END;

PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER)
IS
BEGIN
  CODCLASA_FILTRU_GENERATOR := aCODCLASA;
END;

FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF (ACODCLASA = 0)OR(CODCLASA_FILTRU_GENERATOR = 0) THEN  RETURN 1;
	ELSE
    IF CODCLASA_FILTRU_GENERATOR = aCODCLASA
      THEN RETURN 1;
      ELSE RETURN 0;
    END IF;
  END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseA INTO Tmp FROM NCLASEA WHERE CodClaseA = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomClaseA  --&gt; 526
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 526);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEA WHERE CodClaseA = RecId;
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEA WHERE CodClaseA = RecId;

  UPDATE NCLASEA SET NRANALITICE = NRANALITICE -1
  WHERE CodClaseA = CP;
  NotifyModif(2, RecId, &apos;NCLASEA&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEA FIELDS( CodClaseA ) VALUES (0) ;
  -- nomClaseA  --&gt; 526
  PKG_CFGTABLES.EXT_INSERTRECORD(526);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCLASEA
  INSERT INTO  TMP_NCLASEA ( CodClaseA,den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nranalitice,CodParinte,
                             nivel, CodIdent,VerListSuplAviz, DiscOfe )
    ( SELECT CodClaseA,den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nranalitice,CodParinte,
             lev, CodIdent, VerListSuplAviz, DiscOfe
      FROM V_NCLASEART WHERE CodClaseA = RecId );
  -- nomClaseA  --&gt; 526
  PKG_CFGTABLES.EXT_GOTORECORD(526);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  CP   NUMBER(20);
  vCodIdentParinte varchar2(250);
BEGIN
  SELECT nvl(CodParinte,0) INTO CP FROM TMP_NCLASEA;
  vCodIdentParinte := &apos;&apos;;
  if cp &gt; 0 then
    select CodIdent into vCodIdentParinte from nclasea where codclasea = cp;
  end if;
  -- nomClaseA  --&gt; 526
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (526);
  IF Operation = 0 THEN  -- UPDATE
    -- Master NCLASEA
    SELECT  CodClaseA INTO RecId FROM TMP_NCLASEA;

    UPDATE NCLASEA SET ( den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,CodIdent,VerListSuplAviz,
                         DiscOfe )
       = ( SELECT den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,CodIdent,VerListSuplAviz,
                  DiscOfe
          FROM TMP_NCLASEA )
      WHERE CodClaseA = RecId ;
  ELSE  -- INSERT
    -- Master NCLASEA
    SELECT seq_NCLASEA_CodClaseA.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NCLASEA&apos;, RecId);
    if cp &gt; 0 then
      select CodIdent into vCodIdentParinte from nclasea where codclasea = cp;
      vCodIdentParinte := vCodIdentParinte||&apos;.&apos;||to_char(RecId);
    else
      vCodIdentParinte := to_char(RecId);
    end if;

    INSERT INTO  NCLASEA ( CodClaseA,den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,CodIdent,VerListSuplAviz,
                           DiscOfe )
   ( SELECT  RecId ,den_clasea,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,vCodIdentParinte,VerListSuplAviz,
             DiscOfe
       FROM TMP_NCLASEA  ) ;
  END IF;

  UPDATE NCLASEA n1
  set NRANALITICE = (Select Count(*) from NClaseA n2 where n2.CodParinte = n1.CodClaseA)
  WHERE n1.CODCLASEA = CP;
  -- nomClaseA  --&gt; 526
  PKG_CFGTABLES.EXT_POSTRECORDS(526);
  NotifyModif(Operation, RecId, &apos;NCLASEA&apos;);
  COMMIT;
END;

END pkg_ClaseArt;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEARTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>354D8DD5FD3CDCDFC327D130EE5C644A7C444FD3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEARTS IS

FUNCTION IS_SUBCLAS_OF(aCLASA IN NUMBER, MASTERCLAS IN NUMBER) RETURN NUMBER
IS
 ISSUBCLAS NUMBER(1) := 0;

 aCLASACURENTA NUMBER(20) := 0;
 aCODPARINTE   NUMBER(20) := 0;
BEGIN
  IF nvl(aCLASA,0) = nvl(MASTERCLAS,0) THEN RETURN 1;
  ELSE
    aCLASACURENTA := nvl(aCLASA,0);
    SELECT NVL(CODPARINTE, 0), NVL(CODCLASEAS, 0) INTO aCODPARINTE, aCLASACURENTA FROM NCLASEAS WHERE CODCLASEAS = aCLASACURENTA;
    WHILE aCODPARINTE &lt;&gt; 0
    LOOP
       IF aCODPARINTE = nvl(MASTERCLAS,0) THEN RETURN 1;
       ELSE
         aCLASACURENTA := aCODPARINTE;
         SELECT NVL(CODPARINTE, 0) INTO aCODPARINTE FROM NCLASEAS WHERE CODCLASEAS = aCLASACURENTA;
       END IF;
    END LOOP;

  END IF;
  RETURN ISSUBCLAS;
END;

PROCEDURE MakeCodIdent IS
BEGIN
  PRC_MakeCodIdent(&apos;NCLASEAS&apos;,&apos;CODCLASEAS&apos;);
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseAS INTO Tmp FROM NCLASEAS WHERE CodClaseAS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEAS WHERE CodClaseAS = RecId;
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEAS WHERE CodClaseAS = RecId;

  UPDATE NCLASEAS SET NRANALITICE = NRANALITICE -1
  WHERE CodClaseAS = CP;
  NotifyModif(2, RecId, &apos;NCLASEAS&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEAS FIELDS( CodClaseAS ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCLASEAS
  INSERT INTO  TMP_NCLASEAS ( CodClaseAS,den_claseas,simbol,prefix,VerListSuplFact, VerListSuplToAll,nranalitice,CodParinte, nivel, Tip, CodIdent )
    ( SELECT CodClaseAS,den_claseas,simbol,prefix,VerListSuplFact, VerListSuplToAll,nranalitice,CodParinte, lev, Tip, CodIdent
      FROM V_NCLASEARTS WHERE CodClaseAS = RecId );

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  CP   NUMBER(20);
  vCodIdentParinte varchar2(250);
BEGIN
  SELECT nvl(CodParinte,0) INTO CP FROM TMP_NCLASEAS;
  vCodIdentParinte := &apos;&apos;;
  if cp &gt; 0 then
    select CodIdent into vCodIdentParinte from nclaseas where codclaseas = cp;
  end if;

  IF Operation = 0 THEN  -- UPDATE

-- Master NCLASEAS
    SELECT  CodClaseAS INTO RecId FROM TMP_NCLASEAS;

    UPDATE NCLASEAS SET ( den_claseaS,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,Tip,CodIdent )
       = ( SELECT den_claseaS,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,Tip,CodIdent
          FROM TMP_NCLASEAS )
      WHERE CodClaseAS = RecId ;

  ELSE  -- INSERT
-- Master NCLASEAS
    SELECT seq_NCLASEAS_CodClaseAS.NextVal INTO RecId FROM DUAL;

    if cp &gt; 0 then
      select CodIdent into vCodIdentParinte from nclaseas where codclaseas = cp;
      vCodIdentParinte := vCodIdentParinte||&apos;.&apos;||to_char(RecId);
    else
      vCodIdentParinte := to_char(RecId);
    end if;

    INSERT INTO  NCLASEAS ( CodClaseAS,den_claseaS,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,Tip,CodIdent )
    SELECT  RecId ,den_claseaS,simbol,prefix,VerListSuplFact, VerListSuplToAll,nivel,nranalitice,CodParinte,Tip,vCodIdentParinte
    FROM TMP_NCLASEAS;
  END IF;

  UPDATE NCLASEAS n1
  set NRANALITICE = (Select Count(*) from NCLASEAS n2 where n2.CodParinte = n1.CodClaseAS)
  WHERE n1.CodClaseAS = CP;
  NotifyModif(Operation, RecId, &apos;NCLASEAS&apos;);
  COMMIT;
END;

END pkg_ClaseArtS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E2CE459C5EEF7449083C547363CB24700E9A5ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEDISC is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseDisc INTO Tmp FROM NCLASEDISC WHERE CodClaseDisc = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEDISC WHERE CodClaseDisc = RecId;  
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEDISC WHERE CodClaseDisc = RecId;

  UPDATE NCLASEDISC SET NRANALITICE = NRANALITICE - 1 
  WHERE CodClaseDisc = CP;
  NotifyModif(2, RecId, &apos;NCLASEDISC&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEDISC FIELDS( CodClaseDISC ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCLASEG
  INSERT INTO  TMP_NCLASEDISC ( CodClaseDISC,Den_ClaseDISC,Simbol,Nivel,NrAnalitice,CodParinte )
    ( SELECT CodClaseDISC,Den_ClaseDISC,Simbol,Nivel,NrAnalitice,CodParinte
      FROM NCLASEDISC WHERE CodClaseDISC = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  CP NUMBER(20) := 0;
BEGIN
  IF Operation = 0 THEN  -- UPDATE


    SELECT  CodClaseDISC INTO RecId FROM TMP_NCLASEDISC;
    UPDATE NCLASEDISC SET ( Den_ClaseDISC, Simbol,Nivel,NrAnalitice,CodParinte )
       = ( SELECT Den_ClaseDISC,Simbol,Nivel,NrAnalitice,CodParinte
          FROM TMP_NCLASEDISC )
      WHERE CodClaseDISC = RecId ;

  ELSE  -- INSERT
  SELECT seq_NCLASEDISC_CodClaseDisC.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NCLASEDISC ( CodClaseDisc, Den_ClaseDisc,Simbol,Nivel,NrAnalitice,CodParinte )
 ( SELECT  RecId ,Den_ClaseDisc,Simbol,Nivel,NrAnalitice,CodParinte
     FROM TMP_NCLASEDISC  ) ;
  END IF;

  SELECT  CodParinte INTO CP FROM TMP_NCLASEDISC;

  UPDATE NCLASEDISC n1
  set NRANALITICE = (Select Count(*) from NClaseDISC n2 where n2.CodParinte = n1.CodClaseDISC)
  WHERE n1.CODCLASEDISC = CP;


  NotifyModif(Operation, RecId, &apos;NCLASEDISC&apos;);
  COMMIT;
END;



end PKG_CLASEDISC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6CD0A319AB4DDB3D17572819C80CDBC1334130F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEGEST IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseG INTO Tmp FROM NCLASEG WHERE CodClaseG = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEG WHERE CodClaseG = RecId;  
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEG WHERE CodClaseG = RecId;

  UPDATE NCLASEG SET NRANALITICE = NRANALITICE - 1 
  WHERE CodClaseG = CP;
  NotifyModif(2, RecId, &apos;NCLASEG&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEG FIELDS( CodClaseG ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCLASEG
  INSERT INTO  TMP_NCLASEG ( CodClaseG,Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte )
    ( SELECT CodClaseG,Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte
      FROM NCLASEG WHERE CodClaseG = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  CP NUMBER(20) := 0;
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NCLASEG
    SELECT  CodClaseG INTO RecId FROM TMP_NCLASEG;
    UPDATE NCLASEG SET ( Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte )
       = ( SELECT Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte
          FROM TMP_NCLASEG )
      WHERE CodClaseG = RecId ;

  ELSE  -- INSERT
-- Master NCLASEG
  SELECT seq_NCLASEG_CodClaseG.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NCLASEG ( CodClaseG,Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte )
 ( SELECT  RecId ,Den_ClaseG,Simbol,Nivel,NrAnalitice,CodParinte
     FROM TMP_NCLASEG  ) ;
  END IF;

  SELECT  CodParinte INTO CP FROM TMP_NCLASEG;

  UPDATE NCLASEG n1
  set NRANALITICE = (Select Count(*) from NClaseG n2 where n2.CodParinte = n1.CodClaseG)
  WHERE n1.CODCLASEG = CP;


  NotifyModif(Operation, RecId, &apos;NCLASEG&apos;);
  COMMIT;
END;



END pkg_ClaseGest; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE2BF25DC16D31E0F9A9F82257D928D094CCA767</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEINT is

PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER)
IS
BEGIN
  CODCLASA_FILTRU_GENERATOR := aCODCLASA;
END;

FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF (ACODCLASA = 0)OR(CODCLASA_FILTRU_GENERATOR = 0) THEN  RETURN 1;
	ELSE 	
    IF CODCLASA_FILTRU_GENERATOR = aCODCLASA  
      THEN RETURN 1;
      ELSE RETURN 0;
    END IF;
  END IF;    
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseInt INTO Tmp FROM NCLASEINT WHERE CodClaseInt = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEINT WHERE CodClaseInt = RecId;  
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEINT WHERE CodClaseInt = RecId;

  UPDATE NCLASEINT SET NRANALITICE = NRANALITICE -1
  WHERE CodClaseInt = CP;
  NotifyModif(2, RecId, &apos;NCLASEINI&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEINT FIELDS( CodClaseInt ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NCLASEINT ( CodClaseInt,den_claseint,simbol,prefix,nranalitice,CodParinte, nivel )
    ( SELECT CodClaseInt,den_claseint,simbol,prefix,nranalitice,CodParinte, lev
      FROM V_NCLASEINT WHERE CodClaseInt = RecId ) ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
CP   NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodClaseInt INTO RecId FROM TMP_NCLASEINT;

    UPDATE NCLASEINT SET ( den_claseint,simbol,prefix,nivel,nranalitice,CodParinte )
       = ( SELECT den_claseint,simbol,prefix,nivel,nranalitice,CodParinte
          FROM TMP_NCLASEINT )
      WHERE CodClaseInt = RecId ;
  ELSE  -- INSERT
    SELECT seq_NCLASEINT_CodClaseInt.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NCLASEINT (CodClaseInt,den_claseint,simbol,prefix,nivel,nranalitice,CodParinte)
    (SELECT  RecId,den_claseint,simbol,prefix,nivel,nranalitice,CodParinte
     FROM TMP_NCLASEINT) ;
  END IF;

  SELECT  CodParinte INTO CP FROM TMP_NCLASEINT;

  UPDATE NCLASEINT n1
  set NRANALITICE = (Select Count(*) from NClaseInt n2 where n2.CodParinte = n1.CodClaseInt)
  WHERE n1.CODCLASEINT = CP;
  NotifyModif(Operation, RecId, &apos;NCLASEINI&apos;);
  COMMIT;
END;

end PKG_CLASEINT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5477ED028CBEC4DDA3B865B9E4E0A5FF25705DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEMF is

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodClaseMF INTO Tmp FROM NCLASEMF WHERE CodClaseMF = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER)
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEMF WHERE CodClaseMF = RecId;
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEMF WHERE CodClaseMF = RecId;

  UPDATE NCLASEMF SET NRANALITICE = NRANALITICE -1
  WHERE CodClaseMF = CP;

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NCLASEMF FIELDS(CodClaseMF) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO  TMP_NCLASEMF( CodClaseMF,den_clasemf,simbol,prefix,nranalitice,CodParinte, nivel )
    ( SELECT CodClaseMF,den_clasemf,simbol,prefix,nranalitice,CodParinte, lev
      FROM V_NCLASEMF WHERE CodClaseMF = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
CP   NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodClaseMF INTO RecId FROM TMP_NCLASEMF;

    UPDATE NCLASEMF SET ( den_clasemf,simbol,prefix,nivel,nranalitice,CodParinte )
       = ( SELECT den_clasemf,simbol,prefix,nivel,nranalitice,CodParinte
          FROM TMP_NCLASEMF )
      WHERE CodClaseMF = RecId ;

  ELSE  -- INSERT

  SELECT seq_NCLASEMF_CodClaseMF.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NCLASEMF ( CodClaseMF,den_clasemf,simbol,prefix,nivel,nranalitice,CodParinte )
 ( SELECT  RecId ,den_clasemf,simbol,prefix,nivel,nranalitice,CodParinte
     FROM TMP_NCLASEMF  ) ;
  END IF;


  SELECT  CodParinte INTO CP FROM TMP_NCLASEMF;

  UPDATE NCLASEMF n1
  set NRANALITICE = (Select Count(*) from NClaseMF n2 where n2.CodParinte = n1.CodClaseMF)
  WHERE n1.CODCLASEMF = CP;
  COMMIT;
END;

end PKG_CLASEMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>900584AA10F6723FBFD2D0C5F9D700556EB60637</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEOP IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseOp INTO Tmp FROM NCLASEOP WHERE CodClaseOp = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NCLASEOP WHERE CodClaseOp = RecId ;
  NotifyModif(2, RecId, &apos;NCLASEOP&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEOP FIELDS( CodClaseOp ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_NCLASEOP ( CodClaseOp, Den_ClaseOp )
    ( SELECT CodClaseOp, Den_ClaseOp
      FROM NCLASEOP WHERE CodClaseOp = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

  SELECT CodClaseOp INTO RecId FROM TMP_NCLASEOP;

  UPDATE NCLASEOP SET ( Den_ClaseOp )
       = ( SELECT Den_ClaseOp
          FROM TMP_NCLASEOP )
      WHERE CodClaseOp = RecId ;

  ELSE  -- INSERT
  
  SELECT SEQ_NCLASEOP_CODCLASEOP.NextVal INTO RecId FROM DUAL;

  INSERT INTO  NCLASEOP ( CodClaseOp, Den_ClaseOp )
 ( SELECT  RecId, Den_ClaseOp
     FROM TMP_NCLASEOP  ) ;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;NCLASEOP&apos;);
  COMMIT;
END;

end pkg_claseop; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF3C33AC20C6EF28B9E55C9570C1A1B3685AF544</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEOPT is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseOpt INTO Tmp FROM NCLASEOPT WHERE CodClaseOpt = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NCLASEOPT WHERE CodClaseOpt = RecId ;
  NotifyModif(2, RecId, &apos;NCLASEOPT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NCLASEOPT FIELDS( CodClaseOpt ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_NCLASEOPT ( CodClaseOpt, Denumire )
    ( SELECT CodClaseOpt, Denumire
      FROM NCLASEOPT WHERE CodClaseOpt = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

  SELECT CodClaseOpt INTO RecId FROM TMP_NCLASEOPT;

  UPDATE NCLASEOPT SET ( Denumire )
       = ( SELECT Denumire
          FROM TMP_NCLASEOPT )
      WHERE CodClaseOpt = RecId ;

  ELSE  -- INSERT
  
  SELECT SEQ_NCLASEOPT_CODCLASEOPT.NextVal INTO RecId FROM DUAL;

  INSERT INTO  NCLASEOPT ( CodClaseOpt, Denumire )
 ( SELECT  RecId, Denumire
     FROM TMP_NCLASEOPT  ) ;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;NCLASEOPT&apos;);
  COMMIT;
END;  

end PKG_CLASEOPT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52C2FDF2E0C97EFA8FCC30729A4DCB33B37ADC3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEPART IS

function GetCodIdentParinte(acodparinte in number) return varchar2 is
aCodP number(20);
aCodIdent varchar2(250);
begin
  select nvl(codparinte,0), CodIdent into aCodP, aCodIdent
  from nclasep where codclasep = aCodParinte;

  if aCodP &gt; 0 then
    aCodIdent := GetCodIdentParinte(aCodP)||&apos;.&apos;||to_char(aCodParinte);
  end if;
  return aCodIdent;
end;

PROCEDURE MakeCodIdent IS
BEGIN
  PRC_MakeCodIdent(&apos;NCLASEP&apos;,&apos;CODCLASEP&apos;);
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseP INTO Tmp FROM NCLASEP WHERE CodClaseP = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
	BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEP WHERE CodClaseP = RecId;
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEP WHERE CodClaseP = RecId ;

  UPDATE NCLASEP SET NRANALITICE = NRANALITICE - 1
  WHERE CodClaseP = CP;
  NotifyModif(2, RecId, &apos;NCLASEP&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEP FIELDS( CodClaseP ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCLASEP
  INSERT INTO  TMP_NCLASEP ( CodClaseP,den_clasep,simbol,nivel,nranalitice,codparinte,codident )
    ( SELECT CodClaseP,den_clasep,simbol,nivel,nranalitice,codparinte,codident
      FROM NCLASEP WHERE CodClaseP = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  CP NUMBER(20);
  vCodIdentParinte varchar2(250);
BEGIN
  SELECT nvl(CodParinte,0) INTO CP FROM TMP_NCLASEP;
  vCodIdentParinte := &apos;&apos;;
  if cp &gt; 0 then
    select CodIdent into vCodIdentParinte from nclasep where codclasep = cp;
  end if;

  IF Operation = 0 THEN  -- UPDATE

-- Master NCLASEP
    SELECT  CodClaseP INTO RecId FROM TMP_NCLASEP;
    UPDATE NCLASEP SET ( den_clasep,simbol,nivel,nranalitice,codparinte,codident )
       = ( SELECT den_clasep,simbol,nivel,nranalitice,codparinte,codident
          FROM TMP_NCLASEP )
      WHERE CodClaseP = RecId ;

  ELSE  -- INSERT
-- Master NCLASEP
  SELECT seq_NCLASEP_CodClaseP.NextVal INTO RecId FROM DUAL;
  if cp &gt; 0 then
    select CodIdent into vCodIdentParinte from nclasep where codclasep = cp;
    vCodIdentParinte := vCodIdentParinte||&apos;.&apos;||to_char(RecId);
  else
    vCodIdentParinte := to_char(RecId);
  end if;

  INSERT INTO  NCLASEP ( CodClaseP,den_clasep,simbol,nivel,nranalitice,codparinte,codident )
 ( SELECT  RecId ,den_clasep,simbol,nivel,nranalitice,codparinte,vCodIdentParinte
     FROM TMP_NCLASEP  ) ;
  END IF;

  SELECT  CodParinte INTO CP FROM TMP_NCLASEP;

  UPDATE NCLASEP n1
  set NRANALITICE = (Select Count(*) from NClaseP n2 where n2.CodParinte = n1.CodClaseP)
  WHERE n1.CODCLASEP = CP;

  NotifyModif(Operation, RecId, &apos;NCLASEP&apos;);
  COMMIT;
END;

END pkg_ClasePart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLASEPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AD72833F944D8097E6A7BA58E6E01B82107A935</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLASEPROD IS

PROCEDURE SET_CODCLASA_FILTRU_GENERATOR(aCODCLASA IN NUMBER)
IS
 BEGIN
   CODCLASA_FILTRU_GENERATOR := aCODCLASA;
 END;

FUNCTION CODCLASA_FILTRU_VALID(aCODCLASA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF (ACODCLASA = 0)OR(CODCLASA_FILTRU_GENERATOR = 0) THEN  RETURN 1;
	ELSE 	
    IF CODCLASA_FILTRU_GENERATOR = aCODCLASA  
      THEN RETURN 1;
      ELSE RETURN 0;
    END IF;
  END IF;    
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClaseProd INTO Tmp FROM NCLASEPROD WHERE CodClaseProd = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  BEGIN
    SELECT NVL(CODPARINTE, 0) INTO CP FROM NCLASEPROD WHERE CodClaseProd = RecId;  
    EXCEPTION WHEN OTHERS THEN CP := 0;
  END;

  DELETE FROM NCLASEPROD WHERE CodClaseProd = RecId;

  UPDATE NCLASEPROD SET NRANALITICE = NRANALITICE -1
  WHERE CodClaseProd = CP;
  NotifyModif(2, RecId, &apos;NCLASEPROD&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCLASEPROD FIELDS( CodClaseProd ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NCLASEPROD ( CodClaseProd,den_claseprod,simbol,prefix,nranalitice,CodParinte, nivel )
    ( SELECT CodClaseProd,den_claseprod,simbol,prefix,nranalitice,CodParinte, lev
      FROM V_NCLASEPROD WHERE CodClaseProd = RecId ) ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
CP   NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodClaseProd INTO RecId FROM TMP_NCLASEPROD;

    UPDATE NCLASEPROD SET ( den_claseprod,simbol,prefix,nivel,nranalitice,CodParinte )
       = ( SELECT den_claseprod,simbol,prefix,nivel,nranalitice,CodParinte
          FROM TMP_NCLASEPROD )
      WHERE CodClaseProd = RecId ;

  ELSE  -- INSERT

  SELECT seq_NCLASEPROD_CodClasePROD.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NCLASEPROD ( CodClaseProd,den_claseprod,simbol,prefix,nivel,nranalitice,CodParinte )
 ( SELECT  RecId ,den_claseprod,simbol,prefix,nivel,nranalitice,CodParinte
     FROM TMP_NCLASEprod  ) ;
  END IF;


  SELECT  CodParinte INTO CP FROM TMP_NCLASEprod;

  UPDATE NCLASEprod n1
  set NRANALITICE = (Select Count(*) from NClaseprod n2 where n2.CodParinte = n1.CodClaseprod)
  WHERE n1.CODCLASEprod = CP;
  NotifyModif(Operation, RecId, &apos;NCLASEPROD&apos;);
  COMMIT;
END;

end pkg_claseprod; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CLEAN_DOCS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7C11A804A625D737864DE087039371DB31E740D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CLEAN_DOCS IS

PROCEDURE Dezactiv_constr IS
BEGIN

FOR v_rec IN (SELECT CONSTRAINT_name,table_name FROM user_constraints WHERE CONSTRAINT_TYPE = &apos;R&apos;)  LOOP
 EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||V_REC.TABLE_NAME||&apos; DISABLE CONSTRAINT &apos;||V_REC.CONSTRAINT_NAME;
END LOOP; 

END;

PROCEDURE Activ_constr IS
BEGIN
 
 FOR v_rec IN (SELECT CONSTRAINT_name,table_name FROM user_constraints WHERE CONSTRAINT_TYPE = &apos;R&apos; ) LOOP
 BEGIN
   EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||V_REC.TABLE_NAME||&apos; ENABLE CONSTRAINT &apos;||V_REC.CONSTRAINT_NAME;
  EXCEPTION WHEN OTHERS THEN
	  EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||V_REC.TABLE_NAME||&apos; ENABLE NOVALIDATE CONSTRAINT &apos;||V_REC.CONSTRAINT_NAME;
	END;	
END LOOP; 
END;

PROCEDURE Activ_constrPK IS
BEGIN
 
 FOR v_rec IN (SELECT CONSTRAINT_name,table_name FROM user_constraints WHERE CONSTRAINT_TYPE = &apos;P&apos; ) LOOP
 BEGIN
   EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||V_REC.TABLE_NAME||&apos; ENABLE CONSTRAINT &apos;||V_REC.CONSTRAINT_NAME;
  EXCEPTION WHEN OTHERS THEN
	  EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||V_REC.TABLE_NAME||&apos; ENABLE NOVALIDATE CONSTRAINT &apos;||V_REC.CONSTRAINT_NAME;
	END;	
END LOOP; 
END;

 --IESIRI
PROCEDURE clean_iesiri IS

BEGIN
FOR v_rec IN (SELECT  codies FROM iesiri WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU) LOOP
  BEGIN
    pkg_iesiri.SP_DELETERECORD(v_rec.codies);
  --EXCEPTION WHEN OTHERS THEN NULL;
  END;
END LOOP;

END;

--INTRARI

PROCEDURE clean_intrari IS
BEGIN
FOR v_rec IN (SELECT  codintr FROM intrari WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU) LOOP
  BEGIN
    pkg_intrari.SP_DELETERECORD(v_rec.codintr);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;
END LOOP;
END;

--TREZOR
PROCEDURE clean_trezor IS
BEGIN
FOR v_rec IN (SELECT  codtrezor FROM trezor WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU ) LOOP
  BEGIN
    pkg_trezor.SP_DELETERECORD(v_rec.codtrezor);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;
END LOOP;
END;

-- transf
PROCEDURE clean_transf IS
BEGIN
FOR v_rec IN (SELECT  codtransf FROM transf WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU ) LOOP
  BEGIN
   pkg_miscari_interne.SP_DELETERECORD(v_rec.codtransf);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;
END LOOP;
END;

-- NC 
PROCEDURE clean_nc IS
BEGIN
FOR v_rec IN (SELECT  codnc FROM nc WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU) LOOP
  BEGIN
  pkg_nc.SP_DELETERECORD(v_rec.codnc);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;
END LOOP;
END;

-- compens
PROCEDURE clean_compens IS
BEGIN
FOR v_rec IN (SELECT  codcompens FROM compens WHERE an*12+luna = pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU) LOOP
  BEGIN
  pkg_compensari.SP_DELETERECORD(v_rec.codcompens);
  EXCEPTION WHEN OTHERS THEN NULL;
	END;
END LOOP;
END;

PROCEDURE clean_all IS
BEGIN
  clean_iesiri;
  clean_intrari;
  clean_trezor;
  clean_transf;
  clean_nc;
  clean_compens;
END;

end pkg_clean_docs; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF32149218A3171E445EDE84CF3690C5F8DE854C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_COMANDA IS

  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_14&apos;;
  DoCommit boolean := true;
  PrelRezAut number := 0;
  MijlocTransportIni NUMBER(20);

  xValidAn             NUMBER;
  xValidLuna           NUMBER;
  xValidAL             NUMBER;
  xValidBancaSitV      NUMBER;
  xValidMonedaSitV     NUMBER;
  xValidMonedaAdaosMin NUMBER;
  xValidAdaosOrMarja   NUMBER;
  xValidAdaosValPret   NUMBER;

procedure UpdateDataStart(aCodComanda1 in number) is
begin
  for v_rec in (select dstart+ostart startd, codcmdprodman from gantt where codcomanda1 = acodcomanda1) loop
    update cmdprodman set datastart = v_rec.startd where codcmdprodman = v_rec.codcmdprodman;
  end loop;
  commit;
end;

procedure PREPARE_TMP_NARTCLI(aCodPart in number)
is
 aClaseP number(20);
begin
  delete from tmp_nartcli;
  insert into tmp_nartcli(
  codartcli,
  codobiect,
  codpart,
  denumire,
  codextern,
  umsec,
  codmoneda,
  pret,
  tipcodafisat,
  umcorelat,
  implicit,
  codlaclient,
  codclasep,
  codgama,
  codintern,
  obs,
  obs2,
  umsecimpdoc,
  duratatr,
  zilestoc,
  gln,
  idspecific
  )
  select
  codartcli,
  codobiect,
  codpart,
  denumire,
  codextern,
  umsec,
  codmoneda,
  pret,
  tipcodafisat,
  umcorelat,
  implicit,
  codlaclient,
  codclasep,
  codgama,
  codintern,
  obs,
  obs2,
  umsecimpdoc,
  duratatr,
  zilestoc,
  gln,
  idspecific
  from nartcli
  where codpart = aCodPart;

  BEGIN
    SELECT COALESCE(CODCLASA, 0) INTO aClaseP FROM NPART WHERE CODPART = aCODPART;
    EXCEPTION WHEN OTHERS THEN aClaseP := 0;
  END;

  if aClaseP &gt; 0 then
    insert into tmp_nartcli(
    codartcli,
    codobiect,
    codpart,
    denumire,
    codextern,
    umsec,
    codmoneda,
    pret,
    tipcodafisat,
    umcorelat,
    implicit,
    codlaclient,
    codclasep,
    codgama,
    codintern,
    obs,
    obs2,
    umsecimpdoc,
    duratatr,
    zilestoc,
    gln,
    idspecific
    )
    select
    cli.codartcli,
    cli.codobiect,
    cli.codpart,
    cli.denumire,
    cli.codextern,
    cli.umsec,
    cli.codmoneda,
    cli.pret,
    cli.tipcodafisat,
    cli.umcorelat,
    cli.implicit,
    cli.codlaclient,
    cli.codclasep,
    cli.codgama,
    cli.codintern,
    cli.obs,
    cli.obs2,
    cli.umsecimpdoc,
    cli.duratatr,
    cli.zilestoc,
    cli.gln,
    cli.idspecific
    from nartcli cli
         left join tmp_nartcli tmp on tmp.codobiect = cli.codobiect
    where cli.codclasep = aClaseP and tmp.codobiect is null;
  end if;



end;

procedure GETAWBCOMANDA(aCodComanda in number, aTipDoc in number, aCurier in number)
IS
BEGIN
  -- INITIAL A FOST GANDIT CA DETALIU LA COMANDA
  -- A APARUT CERINTA SA POATA FI DETALIU LA MAI MULTE TIPURI DE DOCUMENTE
  UPDATE AWBCOMANDA
  SET
    TIPDOC = 18
  WHERE
    TIPDOC IS NULL;

  DELETE TMP_AWBCOMANDA;
  INSERT INTO TMP_AWBCOMANDA(CODAWBCOMANDA, CODCOMANDA, CURIER, NUMAR, DOC, PDF,INFOSTADIU, POSTAT, DATAPOSTARE, TARIF, TVA, TIPDOC, SHIPMENTID, PARCELSID)
  SELECT
    CODAWBCOMANDA,
    CODCOMANDA,
    CURIER,
    NUMAR,
    DOC,
    PDF,
    INFOSTADIU,
    POSTAT,
    DATAPOSTARE,
    TARIF,
    TVA,
    TIPDOC,
    SHIPMENTID,
    PARCELSID
  FROM
    AWBCOMANDA
  WHERE
    CODCOMANDA = aCODCOMANDA
    AND TIPDOC = aTIPDOC
    AND CURIER = aCURIER;

  UPDATE TMP_AWBCOMANDA
  SET
    HASPDF = CASE
               WHEN NVL(LENGTH(PDF), 0) &gt; 0 THEN 1
               ELSE 0
             END;

  COMMIT;
END;

procedure POSTAWBCOMANDA(aCodComanda in number, aTipDoc in number, aCurier in number)
Is
aCod number(20);
begin
  IF pkg_categconst.GetValConstanta(&apos;AWBPENRI&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 THEN
    FOR V_REC IN (
      SELECT DISTINCT W.CODAWBCOMANDA, I.CODIES
      FROM AWBCOMANDA W
           LEFT JOIN PACHETE P ON W.CODCOMANDA = P.CODPACHETE AND W.TIPDOC = 78
           LEFT JOIN PACHETEOBJL PO ON PO.CODPACHETE = P.CODPACHETE
           LEFT JOIN PACHETEOBJLINK L ON L.CODPACHETEOBJL = PO.CODPACHETEOBJL
           LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
           LEFT JOIN IESIRI I ON I.CODIES = I1.CODIES
      WHERE
        W.CODCOMANDA = aCODCOMANDA
        AND W.TIPDOC = aTipDoc
        AND W.CURIER = aCURIER
        AND W.CODAWBCOMANDA NOT IN (SELECT CODAWBCOMANDA FROM TMP_AWBCOMANDA)
        and W.POSTAT = 1
    ) LOOP
      DELETE FROM AWBCOMANDA
      WHERE
        CODAWBCOMANDA = V_REC.CODAWBCOMANDA;
      UPDATE IESIRI SET NRI = NULL WHERE CODIES = V_REC.CODIES;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_AWBCOMANDA) LOOP
      IF V_REC.CODAWBCOMANDA &lt; 0 THEN
        select SEQ_AWBCOMANDA_CODAWBCOMANDA.NEXTVAL into aCod from dual;
        INSERT INTO AWBCOMANDA(CODAWBCOMANDA, CODCOMANDA, TIPDOC, CURIER, NUMAR, DOC, PDF, INFOSTADIU, POSTAT, DATAPOSTARE, TARIF, TVA, SHIPMENTID, PARCELSID)
        VALUES (aCod, V_REC.CODCOMANDA, V_REC.TIPDOC,V_REC.CURIER, V_REC.NUMAR, V_REC.DOC, V_REC.PDF, V_REC.INFOSTADIU, V_REC.POSTAT, V_REC.DATAPOSTARE, V_REC.TARIF, V_REC.TVA, V_REC.SHIPMENTID, V_REC.PARCELSID);
      ELSE
        aCod := v_rec.codawbcomanda;
        UPDATE AWBCOMANDA
        SET
          CURIER      = V_REC.CURIER,
          NUMAR       = V_REC.NUMAR,
          DOC         = V_REC.DOC,
          PDF         = V_REC.PDF,
          INFOSTADIU  = V_REC.INFOSTADIU,
          POSTAT      = V_REC.POSTAT,
          DATAPOSTARE = V_REC.DATAPOSTARE,
          TARIF       = V_REC.TARIF,
          PARCELSID   = V_REC.PARCELSID
        WHERE
          CODAWBCOMANDA = V_REC.CODAWBCOMANDA;
      END IF;
      IF V_REC.POSTAT = 1 THEN
      FOR V_TMP IN (
        SELECT DISTINCT W.CODAWBCOMANDA, I.CODIES, W.NUMAR
        FROM AWBCOMANDA W
             LEFT JOIN PACHETE P ON W.CODCOMANDA = P.CODPACHETE AND W.TIPDOC = 78
             LEFT JOIN PACHETEOBJL PO ON PO.CODPACHETE = P.CODPACHETE
             LEFT JOIN PACHETEOBJLINK L ON L.CODPACHETEOBJL = PO.CODPACHETEOBJL
             LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
             LEFT JOIN IESIRI I ON I.CODIES = I1.CODIES
        WHERE
          W.CODAWBCOMANDA = aCod
      ) LOOP
        UPDATE IESIRI SET NRI = V_TMP.NUMAR WHERE CODIES = V_TMP.CODIES;
      END LOOP;
      END IF;
    END LOOP;
  ELSE
    DELETE FROM AWBCOMANDA
    WHERE
      CODCOMANDA = aCODCOMANDA
      AND TIPDOC = aTipDoc
      AND CURIER = aCURIER
      AND CODAWBCOMANDA NOT IN (SELECT CODAWBCOMANDA FROM TMP_AWBCOMANDA);

    FOR V_REC IN (SELECT * FROM TMP_AWBCOMANDA) LOOP
      IF V_REC.CODAWBCOMANDA &lt; 0 THEN
        INSERT INTO AWBCOMANDA(CODAWBCOMANDA, CODCOMANDA, TIPDOC, CURIER, NUMAR, DOC, PDF, INFOSTADIU, POSTAT, DATAPOSTARE, TARIF, TVA, SHIPMENTID, PARCELSID)
        VALUES (SEQ_AWBCOMANDA_CODAWBCOMANDA.NEXTVAL, V_REC.CODCOMANDA, V_REC.TIPDOC,V_REC.CURIER, V_REC.NUMAR, V_REC.DOC, V_REC.PDF, V_REC.INFOSTADIU, V_REC.POSTAT, V_REC.DATAPOSTARE, V_REC.TARIF, V_REC.TVA, V_REC.SHIPMENTID, V_REC.PARCELSID);
      ELSE
        UPDATE AWBCOMANDA
        SET
          CURIER      = V_REC.CURIER,
          NUMAR       = V_REC.NUMAR,
          DOC         = V_REC.DOC,
          PDF         = V_REC.PDF,
          INFOSTADIU  = V_REC.INFOSTADIU,
          POSTAT      = V_REC.POSTAT,
          DATAPOSTARE = V_REC.DATAPOSTARE,
          TARIF       = V_REC.TARIF
        WHERE
          CODAWBCOMANDA = V_REC.CODAWBCOMANDA;
      END IF;
    END LOOP;
  END IF;

  COMMIT;
end;

PROCEDURE EMPTY_COMANDA_TEMPTABLES
IS
BEGIN
  Delete TMP_COMANDA1;
  Delete TMP_LIVRTOT;
  Delete TMP_LIVR1;
  Delete TMP_LIVR1_INITIAL;
  Delete TMP_LIVR;
  Delete TMP_CMDPRODMAT;
  Delete TMP_CMDPRODREZ;
  Delete TMP_LIVR_MAT;
  Delete TMP_LIVRTOT_MAT;
  Delete TMP_LIVR1_MAT;
  Delete TMP_LIVR1_MAT_INITIAL;
  Delete TMP_CMDLINK;
  Delete TMP_CMDLINK_INITIAL;
  Delete TMP_CMDLIVRLINK;
  Delete TMP_CMDLIVRLINK_INITIAL;
  Delete TMP_TERMENECMD;
  Delete TMP_NODECHIV;
  Delete TMP_VOUCHERCADOULINK;
  Delete TMP_VOUCHERCADOULINK_INI;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDC&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC_INI&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos;Delete TMP_COMANDC_INI&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL_INI&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL_INI&apos;;
  END IF;


--  Delete TMP_COMANDC;
--  Delete TMP_COMANDC1;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDC1&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1_INI&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos;Delete TMP_COMANDC1_INI&apos;;
  END IF;



  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL1&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL1_INI&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDRAC&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDRAC_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDRAC1&apos;;
  END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_COMANDRAC1_INI&apos;;
  END IF;

  Delete TMP_CMDPRODMAN;
  Delete TMP_STORNOCMDF;
  Delete TMP_STORNOCMDF_INI;
  Delete TMP_CMDAPROBARI;
--  Delete TMP_COMANDI1;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDI&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDI_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDI1&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDI1_INI&apos;;
   END IF;



  Delete TMP_PACHETEDLLINK;
  Delete TMP_PACHETEDLLINK_INITIAL;
  Delete TMP_RAC_REZ;
  Delete TMP_COMANDA1_INITIAL;
  Delete TMP_PRECMDLINK;
  Delete TMP_VOUCHERLINK;
  Delete TMP_NPARCSA;
  Delete TMP_AvarieCaroserie;
  Delete TMP_COMANDA2;
  Delete TMP_COMANDA3;
  Delete TMP_AvarieCaroserie1;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_COMANDL_INI&apos;;
   END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDG&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDG&apos;;
   END IF;
     IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDG_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDG_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDG1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDG1&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDG1_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDG1_INI&apos;;
   END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDF&apos;;
   END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDF_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDF1&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF1_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDF1_INI&apos;;
   END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDSA&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDSA&apos;;
   END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDSA_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDSA_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDSA1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDSA1&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDSA1_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_COMANDSA1_INI&apos;;
   END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_CMDSUBEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_CMDSUBEXT&apos;;
   END IF;
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_CMDSUBEXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_CMDSUBEXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_CMDSUBEXT1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_CMDSUBEXT1&apos;;
   END IF;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_CMDSUBEXT1_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_CMDSUBEXT1_INI&apos;;
   END IF;

--  Delete TMP_COMANDL;
  Delete TMP_COMANDA4;
  COMMIT;
END;


PROCEDURE MODIFICA_LINII_COMENZI
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_COMANDA1)
  LOOP
    UPDATE COMANDA1
    SET
      CODOBIECT    = v_rec.CODOBIECT,
      UMSEC        = v_rec.UMSEC,
      PU           = v_rec.PU / v_rec.Paritate,
      PRETORIG     = v_rec.PU / v_rec.Paritate,
--      CANTCOMANDAT = v_rec.CantComandat * v_rec.Paritate,
      CANTACCEPTAT = v_rec.CantAcceptat * v_rec.Paritate,
      RESTACCEPTAT = v_rec.CantAcceptat * v_rec.Paritate,
      GESTACT      = V_REC.GESTACT
    WHERE
      CODCOMANDA1 = V_REC.CODCOMANDA1;
  END LOOP;
  FOR V_REC IN (SELECT DISTINCT CODCOMANDA FROM TMP_COMANDA1)
  LOOP
     UPDATE COMANDA
     SET
       VALOARE = (SELECT SUM(PU * CANTACCEPTAT) FROM COMANDA1 WHERE CODCOMANDA = V_REC.CODCOMANDA)
     WHERE
       CODCOMANDA = V_REC.CODCOMANDA;
  END LOOP;
  COMMIT;

END;

PROCEDURE PREPARE_MAN_COMENZI_PRODUCTIE(aCODGEST IN NUMBER, ANLUNALUCRU IN NUMBER, aDataRef IN VARCHAR2, aNP IN NUMBER DEFAULT 0)
IS
NR NUMBER(20) := 0;
vPrelComInchise number(10);
vRestNegativ number(10);
vAn number(4);
vLuna number(2);
aCount number(10);
aUserID number(20);
BEGIN
  select count(*) into aCount from tmp_manevra_liste where filtru = &apos;CODCOMANDA&apos; and valoare1 = &apos;GENNP&apos;;
  vAn := pkg_globals.getANLUCRU;
  vLuna := pkg_globals.getLunaLUCRU;
  aUserID := PKG_GLOBALS.GETUSERID;

  vPrelComInchise := Nvl(pkg_categconst.GetValConstanta(&apos;PrelComInchise&apos; ,vAN,vluna),2);
  vRestNegativ := Nvl(pkg_categconst.GetValConstanta(&apos;BCSuplimRest&apos; ,vAN,vluna),2);

  delete manevra_unic where userid = auserid;
  if vPrelComInchise = 1 then
    if aCount = 0 then
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna - 1
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
    else
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna and
            exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODCOMANDA&apos; and tmp.valoare1 = &apos;GENNP&apos; and tmp.valoare = c1.codcomanda)
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna - 1 and
            exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODCOMANDA&apos; and tmp.valoare1 = &apos;GENNP&apos; and tmp.valoare = c1.codcomanda)
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
    end if;
  else if vPrelComInchise = 3 then
    if aCount = 0 then
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna - 1
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna + 1
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
    else
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna and
            exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODCOMANDA&apos; and tmp.valoare1 = &apos;GENNP&apos; and tmp.valoare = c1.codcomanda)
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna - 1 and
            exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODCOMANDA&apos; and tmp.valoare1 = &apos;GENNP&apos; and tmp.valoare = c1.codcomanda)
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
      MERGE INTO manevra_unic m
      USING (
      select distinct c1.codcomanda1 codunic
      from comanda1 c1
           inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
           inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.rest &lt;= 0 and i.an*12+i.luna = van*12+vluna + 1 and
            exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODCOMANDA&apos; and tmp.valoare1 = &apos;GENNP&apos; and tmp.valoare = c1.codcomanda)
      ) N
      ON (m.CODUNIC = N.CODUNIC AND M.USERID = aUSERID)
      WHEN NOT MATCHED THEN INSERT (CODUNIC, USERID)
      VALUES (N.CODUNIC, aUSERID);
    end if;
  end if; end if;

  DELETE MAN_COMANDA;
  if aCount = 0 then
    MERGE INTO man_comanda m
    USING
    (
      select distinct
        C.CODCOMANDA,C.TIPDOC,C.ANULAT,C.BLOCAT,C.OPERAT,C.PREFIXDOC,C.NRDOC,C.CARNETDOC,C.DATADOC,C.PARTENER,
        C.VALOARE,C.AN,C.LUNA,C.OBS,C.MONEDA,C.CODCONTRACT,C.CODCMDPARINTE,C.DELEGAT,C.AGENT,C.VALDISCOUNT,C.CODLOCATIE,
        C.SUBUNITATEA,C.CODFISCAL,C.USERID,C.DATACREARE,C.CODGEST,C.INCHISA,C.SUBUNITSURSA,C.SCADENTAV,C.SERIADOC,
        C.USERIDBLOCAJ,C.NRI,C.CODTRASEULIVR,C.ORDINELIVRARE,C.MIJLTRANSP,C.INSOTITOR,C.DISPLIVRARE,C.VERIFICAT,
        C.CODIES,C.FARATRANSPORT,C.PLATAPELOC,C.DATAINREG,C.FACTURABIL,C.CURS,C.SCHIMB,C.CODFORMATIE,C.IDIMPORT,
        C.LISTAT,C.FACTURA_APL_EXT,C.CODPERS_APL_EXT,C.LOT,C.NRTRANSP,C.CODIESAVANS,C.FARAFACTURA,C.DINONLINE,
        C.PRETCUAMANUNT,C.CODANALIZA,C.TIPTRANZACTIE,C.SUBUNITDEST,C.NRMAXAPROBARI,C.STADIUWMS,C.CODPERSC,C.MOTIVINCHIDERE,
        C.CODPARTCOMIS,C.TIPLIVRARE,C.MAJORARI,C.GRATIE,C.EXPORTKLG,C.EXPORTATKLG,C.MODINCHIDERE
      FROM
        COMANDA C,
        COMANDA1 C1
      WHERE
          C.CODGEST = aCODGEST
          AND C.TIPDOC = 53
          AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
          AND C1.CODCOMANDA = C.CODCOMANDA
          AND trunc(C.DATADOC) &lt;= TO_DATE(ADATAREF,&apos;DD.MM.YYYY&apos;)
          AND COALESCE(C.INCHISA,0) = 0
          AND C.OPERAT = 1 AND C.ANULAT = 0
    ) N
    ON (m.CODCOMANDA = N.CODCOMANDA)
    WHEN NOT MATCHED THEN INSERT
    (
      CODCOMANDA,TIPDOC,ANULAT,BLOCAT,OPERAT,PREFIXDOC,NRDOC,CARNETDOC,DATADOC,PARTENER,
      VALOARE,AN,LUNA,OBS,MONEDA,CODCONTRACT,CODCMDPARINTE,DELEGAT,AGENT,VALDISCOUNT,CODLOCATIE,
      SUBUNITATEA,CODFISCAL,USERID,DATACREARE,CODGEST,INCHISA,SUBUNITSURSA,SCADENTAV,SERIADOC,
      USERIDBLOCAJ,NRI,CODTRASEULIVR,ORDINELIVRARE,MIJLTRANSP,INSOTITOR,DISPLIVRARE,VERIFICAT,
      CODIES,FARATRANSPORT,PLATAPELOC,DATAINREG,FACTURABIL,CURS,SCHIMB,CODFORMATIE,IDIMPORT,
      LISTAT,FACTURA_APL_EXT,CODPERS_APL_EXT,LOT,NRTRANSP,CODIESAVANS,FARAFACTURA,DINONLINE,
      PRETCUAMANUNT,CODANALIZA,TIPTRANZACTIE,SUBUNITDEST,NRMAXAPROBARI,STADIUWMS,CODPERSC,MOTIVINCHIDERE,
      CODPARTCOMIS,TIPLIVRARE,MAJORARI,GRATIE,EXPORTKLG,EXPORTATKLG,MODINCHIDERE
    )
    VALUES
    (
      N.CODCOMANDA,N.TIPDOC,N.ANULAT,N.BLOCAT,N.OPERAT,N.PREFIXDOC,N.NRDOC,N.CARNETDOC,N.DATADOC,N.PARTENER,
      N.VALOARE,N.AN,N.LUNA,N.OBS,N.MONEDA,N.CODCONTRACT,N.CODCMDPARINTE,N.DELEGAT,N.AGENT,N.VALDISCOUNT,N.CODLOCATIE,
      N.SUBUNITATEA,N.CODFISCAL,N.USERID,N.DATACREARE,N.CODGEST,N.INCHISA,N.SUBUNITSURSA,N.SCADENTAV,N.SERIADOC,
      N.USERIDBLOCAJ,N.NRI,N.CODTRASEULIVR,N.ORDINELIVRARE,N.MIJLTRANSP,N.INSOTITOR,N.DISPLIVRARE,N.VERIFICAT,
      N.CODIES,N.FARATRANSPORT,N.PLATAPELOC,N.DATAINREG,N.FACTURABIL,N.CURS,N.SCHIMB,N.CODFORMATIE,N.IDIMPORT,
      N.LISTAT,N.FACTURA_APL_EXT,N.CODPERS_APL_EXT,N.LOT,N.NRTRANSP,N.CODIESAVANS,N.FARAFACTURA,N.DINONLINE,
      N.PRETCUAMANUNT,N.CODANALIZA,N.TIPTRANZACTIE,N.SUBUNITDEST,N.NRMAXAPROBARI,N.STADIUWMS,N.CODPERSC,N.MOTIVINCHIDERE,
      N.CODPARTCOMIS,N.TIPLIVRARE,N.MAJORARI,N.GRATIE,N.EXPORTKLG,N.EXPORTATKLG,N.MODINCHIDERE
    );
    MERGE INTO man_comanda m
    USING
    (
      select distinct
        C.CODCOMANDA,C.TIPDOC,C.ANULAT,C.BLOCAT,C.OPERAT,C.PREFIXDOC,C.NRDOC,C.CARNETDOC,C.DATADOC,C.PARTENER,
        C.VALOARE,C.AN,C.LUNA,C.OBS,C.MONEDA,C.CODCONTRACT,C.CODCMDPARINTE,C.DELEGAT,C.AGENT,C.VALDISCOUNT,C.CODLOCATIE,
        C.SUBUNITATEA,C.CODFISCAL,C.USERID,C.DATACREARE,C.CODGEST,C.INCHISA,C.SUBUNITSURSA,C.SCADENTAV,C.SERIADOC,
        C.USERIDBLOCAJ,C.NRI,C.CODTRASEULIVR,C.ORDINELIVRARE,C.MIJLTRANSP,C.INSOTITOR,C.DISPLIVRARE,C.VERIFICAT,
        C.CODIES,C.FARATRANSPORT,C.PLATAPELOC,C.DATAINREG,C.FACTURABIL,C.CURS,C.SCHIMB,C.CODFORMATIE,C.IDIMPORT,
        C.LISTAT,C.FACTURA_APL_EXT,C.CODPERS_APL_EXT,C.LOT,C.NRTRANSP,C.CODIESAVANS,C.FARAFACTURA,C.DINONLINE,
        C.PRETCUAMANUNT,C.CODANALIZA,C.TIPTRANZACTIE,C.SUBUNITDEST,C.NRMAXAPROBARI,C.STADIUWMS,C.CODPERSC,C.MOTIVINCHIDERE,
        C.CODPARTCOMIS,C.TIPLIVRARE,C.MAJORARI,C.GRATIE,C.EXPORTKLG,C.EXPORTATKLG,C.MODINCHIDERE
      FROM
        COMANDA C,
        COMANDA1 C1
      WHERE
          C.CODGEST = aCODGEST
          AND C.TIPDOC = 92 and (C.FaraFactura = 1 or C1.MODINCHIDERE = 2)
          AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
          AND C1.CODCOMANDA = C.CODCOMANDA
          AND trunc(C.DATADOC) &lt;= TO_DATE(ADATAREF,&apos;DD.MM.YYYY&apos;)
          AND COALESCE(C.INCHISA,0) = 0
          AND C.OPERAT = 1 AND C.ANULAT = 0
    ) N
    ON (m.CODCOMANDA = N.CODCOMANDA)
    WHEN NOT MATCHED THEN INSERT
    (
      CODCOMANDA,TIPDOC,ANULAT,BLOCAT,OPERAT,PREFIXDOC,NRDOC,CARNETDOC,DATADOC,PARTENER,
      VALOARE,AN,LUNA,OBS,MONEDA,CODCONTRACT,CODCMDPARINTE,DELEGAT,AGENT,VALDISCOUNT,CODLOCATIE,
      SUBUNITATEA,CODFISCAL,USERID,DATACREARE,CODGEST,INCHISA,SUBUNITSURSA,SCADENTAV,SERIADOC,
      USERIDBLOCAJ,NRI,CODTRASEULIVR,ORDINELIVRARE,MIJLTRANSP,INSOTITOR,DISPLIVRARE,VERIFICAT,
      CODIES,FARATRANSPORT,PLATAPELOC,DATAINREG,FACTURABIL,CURS,SCHIMB,CODFORMATIE,IDIMPORT,
      LISTAT,FACTURA_APL_EXT,CODPERS_APL_EXT,LOT,NRTRANSP,CODIESAVANS,FARAFACTURA,DINONLINE,
      PRETCUAMANUNT,CODANALIZA,TIPTRANZACTIE,SUBUNITDEST,NRMAXAPROBARI,STADIUWMS,CODPERSC,MOTIVINCHIDERE,
      CODPARTCOMIS,TIPLIVRARE,MAJORARI,GRATIE,EXPORTKLG,EXPORTATKLG,MODINCHIDERE
    )
    VALUES
    (
      N.CODCOMANDA,N.TIPDOC,N.ANULAT,N.BLOCAT,N.OPERAT,N.PREFIXDOC,N.NRDOC,N.CARNETDOC,N.DATADOC,N.PARTENER,
      N.VALOARE,N.AN,N.LUNA,N.OBS,N.MONEDA,N.CODCONTRACT,N.CODCMDPARINTE,N.DELEGAT,N.AGENT,N.VALDISCOUNT,N.CODLOCATIE,
      N.SUBUNITATEA,N.CODFISCAL,N.USERID,N.DATACREARE,N.CODGEST,N.INCHISA,N.SUBUNITSURSA,N.SCADENTAV,N.SERIADOC,
      N.USERIDBLOCAJ,N.NRI,N.CODTRASEULIVR,N.ORDINELIVRARE,N.MIJLTRANSP,N.INSOTITOR,N.DISPLIVRARE,N.VERIFICAT,
      N.CODIES,N.FARATRANSPORT,N.PLATAPELOC,N.DATAINREG,N.FACTURABIL,N.CURS,N.SCHIMB,N.CODFORMATIE,N.IDIMPORT,
      N.LISTAT,N.FACTURA_APL_EXT,N.CODPERS_APL_EXT,N.LOT,N.NRTRANSP,N.CODIESAVANS,N.FARAFACTURA,N.DINONLINE,
      N.PRETCUAMANUNT,N.CODANALIZA,N.TIPTRANZACTIE,N.SUBUNITDEST,N.NRMAXAPROBARI,N.STADIUWMS,N.CODPERSC,N.MOTIVINCHIDERE,
      N.CODPARTCOMIS,N.TIPLIVRARE,N.MAJORARI,N.GRATIE,N.EXPORTKLG,N.EXPORTATKLG,N.MODINCHIDERE
    );
  else
    MERGE INTO man_comanda m
    USING
    (
      select distinct
        C.CODCOMANDA,C.TIPDOC,C.ANULAT,C.BLOCAT,C.OPERAT,C.PREFIXDOC,C.NRDOC,C.CARNETDOC,C.DATADOC,C.PARTENER,
        C.VALOARE,C.AN,C.LUNA,C.OBS,C.MONEDA,C.CODCONTRACT,C.CODCMDPARINTE,C.DELEGAT,C.AGENT,C.VALDISCOUNT,C.CODLOCATIE,
        C.SUBUNITATEA,C.CODFISCAL,C.USERID,C.DATACREARE,C.CODGEST,C.INCHISA,C.SUBUNITSURSA,C.SCADENTAV,C.SERIADOC,
        C.USERIDBLOCAJ,C.NRI,C.CODTRASEULIVR,C.ORDINELIVRARE,C.MIJLTRANSP,C.INSOTITOR,C.DISPLIVRARE,C.VERIFICAT,
        C.CODIES,C.FARATRANSPORT,C.PLATAPELOC,C.DATAINREG,C.FACTURABIL,C.CURS,C.SCHIMB,C.CODFORMATIE,C.IDIMPORT,
        C.LISTAT,C.FACTURA_APL_EXT,C.CODPERS_APL_EXT,C.LOT,C.NRTRANSP,C.CODIESAVANS,C.FARAFACTURA,C.DINONLINE,
        C.PRETCUAMANUNT,C.CODANALIZA,C.TIPTRANZACTIE,C.SUBUNITDEST,C.NRMAXAPROBARI,C.STADIUWMS,C.CODPERSC,C.MOTIVINCHIDERE,
        C.CODPARTCOMIS,C.TIPLIVRARE,C.MAJORARI,C.GRATIE,C.EXPORTKLG,C.EXPORTATKLG,C.MODINCHIDERE
      FROM
        COMANDA C,
        COMANDA1 C1
      WHERE
          C.CODGEST = aCODGEST
          AND C.TIPDOC = 53
          AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
          AND C1.CODCOMANDA = C.CODCOMANDA
          AND trunc(C.DATADOC) &lt;= TO_DATE(ADATAREF,&apos;DD.MM.YYYY&apos;)
          AND COALESCE(C.INCHISA,0) = 0
          AND C.OPERAT = 1 AND C.ANULAT = 0 AND
          EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCOMANDA&apos; AND TMP.VALOARE1 = &apos;GENNP&apos; AND TMP.VALOARE = C1.CODCOMANDA)
    ) N
    ON (m.CODCOMANDA = N.CODCOMANDA)
    WHEN NOT MATCHED THEN INSERT
    (
      CODCOMANDA,TIPDOC,ANULAT,BLOCAT,OPERAT,PREFIXDOC,NRDOC,CARNETDOC,DATADOC,PARTENER,
      VALOARE,AN,LUNA,OBS,MONEDA,CODCONTRACT,CODCMDPARINTE,DELEGAT,AGENT,VALDISCOUNT,CODLOCATIE,
      SUBUNITATEA,CODFISCAL,USERID,DATACREARE,CODGEST,INCHISA,SUBUNITSURSA,SCADENTAV,SERIADOC,
      USERIDBLOCAJ,NRI,CODTRASEULIVR,ORDINELIVRARE,MIJLTRANSP,INSOTITOR,DISPLIVRARE,VERIFICAT,
      CODIES,FARATRANSPORT,PLATAPELOC,DATAINREG,FACTURABIL,CURS,SCHIMB,CODFORMATIE,IDIMPORT,
      LISTAT,FACTURA_APL_EXT,CODPERS_APL_EXT,LOT,NRTRANSP,CODIESAVANS,FARAFACTURA,DINONLINE,
      PRETCUAMANUNT,CODANALIZA,TIPTRANZACTIE,SUBUNITDEST,NRMAXAPROBARI,STADIUWMS,CODPERSC,MOTIVINCHIDERE,
      CODPARTCOMIS,TIPLIVRARE,MAJORARI,GRATIE,EXPORTKLG,EXPORTATKLG,MODINCHIDERE
    )
    VALUES
    (
      N.CODCOMANDA,N.TIPDOC,N.ANULAT,N.BLOCAT,N.OPERAT,N.PREFIXDOC,N.NRDOC,N.CARNETDOC,N.DATADOC,N.PARTENER,
      N.VALOARE,N.AN,N.LUNA,N.OBS,N.MONEDA,N.CODCONTRACT,N.CODCMDPARINTE,N.DELEGAT,N.AGENT,N.VALDISCOUNT,N.CODLOCATIE,
      N.SUBUNITATEA,N.CODFISCAL,N.USERID,N.DATACREARE,N.CODGEST,N.INCHISA,N.SUBUNITSURSA,N.SCADENTAV,N.SERIADOC,
      N.USERIDBLOCAJ,N.NRI,N.CODTRASEULIVR,N.ORDINELIVRARE,N.MIJLTRANSP,N.INSOTITOR,N.DISPLIVRARE,N.VERIFICAT,
      N.CODIES,N.FARATRANSPORT,N.PLATAPELOC,N.DATAINREG,N.FACTURABIL,N.CURS,N.SCHIMB,N.CODFORMATIE,N.IDIMPORT,
      N.LISTAT,N.FACTURA_APL_EXT,N.CODPERS_APL_EXT,N.LOT,N.NRTRANSP,N.CODIESAVANS,N.FARAFACTURA,N.DINONLINE,
      N.PRETCUAMANUNT,N.CODANALIZA,N.TIPTRANZACTIE,N.SUBUNITDEST,N.NRMAXAPROBARI,N.STADIUWMS,N.CODPERSC,N.MOTIVINCHIDERE,
      N.CODPARTCOMIS,N.TIPLIVRARE,N.MAJORARI,N.GRATIE,N.EXPORTKLG,N.EXPORTATKLG,N.MODINCHIDERE
    );
    MERGE INTO man_comanda m
    USING
    (
      select distinct
        C.CODCOMANDA,C.TIPDOC,C.ANULAT,C.BLOCAT,C.OPERAT,C.PREFIXDOC,C.NRDOC,C.CARNETDOC,C.DATADOC,C.PARTENER,
        C.VALOARE,C.AN,C.LUNA,C.OBS,C.MONEDA,C.CODCONTRACT,C.CODCMDPARINTE,C.DELEGAT,C.AGENT,C.VALDISCOUNT,C.CODLOCATIE,
        C.SUBUNITATEA,C.CODFISCAL,C.USERID,C.DATACREARE,C.CODGEST,C.INCHISA,C.SUBUNITSURSA,C.SCADENTAV,C.SERIADOC,
        C.USERIDBLOCAJ,C.NRI,C.CODTRASEULIVR,C.ORDINELIVRARE,C.MIJLTRANSP,C.INSOTITOR,C.DISPLIVRARE,C.VERIFICAT,
        C.CODIES,C.FARATRANSPORT,C.PLATAPELOC,C.DATAINREG,C.FACTURABIL,C.CURS,C.SCHIMB,C.CODFORMATIE,C.IDIMPORT,
        C.LISTAT,C.FACTURA_APL_EXT,C.CODPERS_APL_EXT,C.LOT,C.NRTRANSP,C.CODIESAVANS,C.FARAFACTURA,C.DINONLINE,
        C.PRETCUAMANUNT,C.CODANALIZA,C.TIPTRANZACTIE,C.SUBUNITDEST,C.NRMAXAPROBARI,C.STADIUWMS,C.CODPERSC,C.MOTIVINCHIDERE,
        C.CODPARTCOMIS,C.TIPLIVRARE,C.MAJORARI,C.GRATIE,C.EXPORTKLG,C.EXPORTATKLG,C.MODINCHIDERE
      FROM
        COMANDA C,
        COMANDA1 C1
      WHERE
          C.CODGEST = aCODGEST
          AND C.TIPDOC = 92 and (C.FaraFactura = 1 or C1.MODINCHIDERE = 2)
          AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
          AND C1.CODCOMANDA = C.CODCOMANDA
          AND trunc(C.DATADOC) &lt;= TO_DATE(ADATAREF,&apos;DD.MM.YYYY&apos;)
          AND COALESCE(C.INCHISA,0) = 0
          AND C.OPERAT = 1 AND C.ANULAT = 0 AND
          EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCOMANDA&apos; AND TMP.VALOARE1 = &apos;GENNP&apos; AND TMP.VALOARE = C1.CODCOMANDA)
    ) N
    ON (m.CODCOMANDA = N.CODCOMANDA)
    WHEN NOT MATCHED THEN INSERT
    (
      CODCOMANDA,TIPDOC,ANULAT,BLOCAT,OPERAT,PREFIXDOC,NRDOC,CARNETDOC,DATADOC,PARTENER,
      VALOARE,AN,LUNA,OBS,MONEDA,CODCONTRACT,CODCMDPARINTE,DELEGAT,AGENT,VALDISCOUNT,CODLOCATIE,
      SUBUNITATEA,CODFISCAL,USERID,DATACREARE,CODGEST,INCHISA,SUBUNITSURSA,SCADENTAV,SERIADOC,
      USERIDBLOCAJ,NRI,CODTRASEULIVR,ORDINELIVRARE,MIJLTRANSP,INSOTITOR,DISPLIVRARE,VERIFICAT,
      CODIES,FARATRANSPORT,PLATAPELOC,DATAINREG,FACTURABIL,CURS,SCHIMB,CODFORMATIE,IDIMPORT,
      LISTAT,FACTURA_APL_EXT,CODPERS_APL_EXT,LOT,NRTRANSP,CODIESAVANS,FARAFACTURA,DINONLINE,
      PRETCUAMANUNT,CODANALIZA,TIPTRANZACTIE,SUBUNITDEST,NRMAXAPROBARI,STADIUWMS,CODPERSC,MOTIVINCHIDERE,
      CODPARTCOMIS,TIPLIVRARE,MAJORARI,GRATIE,EXPORTKLG,EXPORTATKLG,MODINCHIDERE
    )
    VALUES
    (
      N.CODCOMANDA,N.TIPDOC,N.ANULAT,N.BLOCAT,N.OPERAT,N.PREFIXDOC,N.NRDOC,N.CARNETDOC,N.DATADOC,N.PARTENER,
      N.VALOARE,N.AN,N.LUNA,N.OBS,N.MONEDA,N.CODCONTRACT,N.CODCMDPARINTE,N.DELEGAT,N.AGENT,N.VALDISCOUNT,N.CODLOCATIE,
      N.SUBUNITATEA,N.CODFISCAL,N.USERID,N.DATACREARE,N.CODGEST,N.INCHISA,N.SUBUNITSURSA,N.SCADENTAV,N.SERIADOC,
      N.USERIDBLOCAJ,N.NRI,N.CODTRASEULIVR,N.ORDINELIVRARE,N.MIJLTRANSP,N.INSOTITOR,N.DISPLIVRARE,N.VERIFICAT,
      N.CODIES,N.FARATRANSPORT,N.PLATAPELOC,N.DATAINREG,N.FACTURABIL,N.CURS,N.SCHIMB,N.CODFORMATIE,N.IDIMPORT,
      N.LISTAT,N.FACTURA_APL_EXT,N.CODPERS_APL_EXT,N.LOT,N.NRTRANSP,N.CODIESAVANS,N.FARAFACTURA,N.DINONLINE,
      N.PRETCUAMANUNT,N.CODANALIZA,N.TIPTRANZACTIE,N.SUBUNITDEST,N.NRMAXAPROBARI,N.STADIUWMS,N.CODPERSC,N.MOTIVINCHIDERE,
      N.CODPARTCOMIS,N.TIPLIVRARE,N.MAJORARI,N.GRATIE,N.EXPORTKLG,N.EXPORTATKLG,N.MODINCHIDERE
    );
  end if;

  DELETE MAN_CMDPRODMAT;
  if aNP &gt; 0 then --sunt pe NP
    if vPrelComInchise in (1,3) then
      SELECT COUNT(*) INTO ACOUNT FROM manevra_unic where userid = auserid;
      IF ACOUNT &gt; 0 THEN
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              c1.codcomanda1 in (select codunic from manevra_unic where userid = auserid)
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              c1.codcomanda1 in (select codunic from manevra_unic where userid = auserid)
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
              (CMD.CODCMDPRODMAT IN( SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL))))
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
              (CMD.CODCMDPRODMAT IN(SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL))))
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
      ELSE
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              (
                (CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR
                ((CMD.REST &lt;= 0) AND (CMD.CODCMDPRODMAT IN(SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL) OR vRestNegativ = 1))
              )
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR
              ((CMD.REST &lt;= 0) AND (CMD.CODCMDPRODMAT IN(SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL) OR vRestNegativ = 1))
              )
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
      END IF;
      if vRestNegativ &lt;&gt; 1 then
        delete man_cmdprodmat where rest &lt;= 0 and tip = 1;
      end if;
    else
      MERGE INTO man_cmdprodmat m
      USING
      (
        select distinct
          CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
          CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
          CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
        FROM
          MAN_COMANDA C
          INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
          INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
          INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
      WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
            ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
            (CMD.CODCMDPRODMAT IN(SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL))))
      ) N
      ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
      WHEN NOT MATCHED THEN INSERT
      (
        M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
        M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
        M.CANTUM1,M.CODCOMANDA3,M.UMSEC
      )
      VALUES
      (
        N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
        N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
        N.CANTUM1,N.CODCOMANDA3,N.UMSEC
      );
      MERGE INTO man_cmdprodmat m
      USING
      (
        select distinct
          CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
          CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
          CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
        FROM
          MAN_COMANDA C
          INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
          INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
      WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
            ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
            (CMD.CODCMDPRODMAT IN(SELECT CODLINIECOMANDA FROM TMP_INTRPRODLINK_INITIAL))))
      ) N
      ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
      WHEN NOT MATCHED THEN INSERT
      (
        M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
        M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
        M.CANTUM1,M.CODCOMANDA3,M.UMSEC
      )
      VALUES
      (
        N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
        N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
        N.CANTUM1,N.CODCOMANDA3,N.UMSEC
      );
    end if;
  else-- sunt pe BC
    if vPrelComInchise in (1,3) then
      SELECT COUNT(*) INTO ACOUNT FROM manevra_unic where userid = auserid;
      IF ACOUNT &gt; 0 THEN
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              c1.codcomanda1 in (select codunic from manevra_unic where userid = auserid)
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              c1.codcomanda1 in (select codunic from manevra_unic where userid = auserid)
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
              (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL))))
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
              (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL))))
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
      ELSE
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
            INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
        WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
              (
                (CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR
                ((CMD.REST &lt;= 0) AND (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL) OR vRestNegativ = 1))
              )
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
        MERGE INTO man_cmdprodmat m
        USING
        (
          select distinct
            CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
            CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
            CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
          FROM
            MAN_COMANDA C
            INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
            INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
            INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
        WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
              ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR
              ((CMD.REST &lt;= 0) AND (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL) OR vRestNegativ = 1))
              )
        ) N
        ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
        WHEN NOT MATCHED THEN INSERT
        (
          M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
          M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
          M.CANTUM1,M.CODCOMANDA3,M.UMSEC
        )
        VALUES
        (
          N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
          N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
          N.CANTUM1,N.CODCOMANDA3,N.UMSEC
        );
      END IF;
      if vRestNegativ &lt;&gt; 1 then
        delete man_cmdprodmat where rest &lt;= 0 and tip = 1;
      end if;
    else
      MERGE INTO man_cmdprodmat m
      USING
      (
        select distinct
          CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
          CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
          CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
        FROM
          MAN_COMANDA C
          INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
          INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
          INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
      WHERE C.TipDoc &lt;&gt; 92 AND N.IMPLICIT = 1 AND
            ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
            (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL))))
      ) N
      ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
      WHEN NOT MATCHED THEN INSERT
      (
        M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
        M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
        M.CANTUM1,M.CODCOMANDA3,M.UMSEC
      )
      VALUES
      (
        N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
        N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
        N.CANTUM1,N.CODCOMANDA3,N.UMSEC
      );
      MERGE INTO man_cmdprodmat m
      USING
      (
        select distinct
          CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
          CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
          CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
        FROM
          MAN_COMANDA C
          INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
          INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN CMDPRODMAT MAT0 ON MAT0.CodComanda1 = C1.CodComanda1 AND MAT0.TIP = 0
      WHERE C.TipDoc &lt;&gt; 92 AND NOT EXISTS (SELECT PN.CODNORMA FROM PRODNORME PN WHERE PN.CODNORMA = C1.CODNORMA) AND
            ((CMD.REST &gt; 0  AND (MAT0.Rest &lt;&gt; 0 or c1.consum = 2)) OR ((CMD.REST = 0) AND
            (CMD.CODCMDPRODMAT IN( SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK_INITIAL))))
      ) N
      ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
      WHEN NOT MATCHED THEN INSERT
      (
        M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
        M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
        M.CANTUM1,M.CODCOMANDA3,M.UMSEC
      )
      VALUES
      (
        N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
        N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
        N.CANTUM1,N.CODCOMANDA3,N.UMSEC
      );
    end if;
  end if;

  SELECT COUNT(*) INTO NR FROM PRODNORME;
  IF NR &gt; 0 THEN
    MERGE INTO man_cmdprodmat m
    USING
    (
      select
        CMD.CODCMDPRODMAT CODCMDPRODMAT,
        C1.CODCOMANDA1 CODCOMANDA1,
        NM.CODOBIECT CODOBIECT,
        C1.CANTACCEPTAT/PC.CANT*NM.CANT CANT,
        NM.PRET PRET,
        C1.CANTACCEPTAT/PC.CANT*NM.CANT - nvl((select sum(l.cant) from iesprodlink l where l.codcmdprodmat = cmd.codcmdprodmat),0) rest,
        1 TIP,
        NM.D1 D1,
        NM.D2 D2,
        NM.D3 D3,
        NM.INDEXLOCAL INDEXLOCAL,
        0 REZIDUU,
        NM.CODMAT CODPRODMAT,
        C1.CANTACCEPTAT/PC.CANT*NM.CANTUM1 CANTUM1,
        NUM1.CODUM1 UMSEC
      from MAN_COMANDA C
           INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = C.CODCOMANDA
           INNER JOIN PRODNORME N ON N.CODNORMA = C1.CODNORMA
           INNER JOIN NORMEMAT NM ON NM.CODNORMA = N.CODNORMA
           INNER JOIN PRODCOMP PC ON N.CODPRODCOMP = PC.CODPRODCOMP
           INNER JOIN NARTOBJ OBJ ON NM.CODOBIECT = OBJ.CODOBIECT
           INNER JOIN NART ON OBJ.CodArticol = NART.CodArticol
           INNER JOIN NUM1 ON NART.UM = NUM1.CodUM  AND NUM1.SECUNDARA = 0
           INNER JOIN PRODMAT MAT ON NM.CODMAT = MAT.CODMAT
           INNER JOIN CMDPRODMAT CMD ON MAT.CODMAT = CMD.CODPRODMAT AND CMD.CODCOMANDA1 = C1.CODCOMANDA1
      where C1.CODNORMA &gt; 0 AND N.IMPLICIT = 0
    ) N
    ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
    WHEN NOT MATCHED THEN INSERT
    (
      M.CODCMDPRODMAT,
      M.CODCOMANDA1,
      M.CODOBIECT,
      M.CANT,
      M.PRET,
      M.REST,
      M.TIP,
      M.D1,
      M.D2,
      M.D3,
      M.INDEXLOCAL,
      M.REZIDUU,
      M.CODPRODMAT,
      M.CANTUM1,
      M.UMSEC
    )
    VALUES
    (
      N.CODCMDPRODMAT,
      N.CODCOMANDA1,
      N.CODOBIECT,
      N.CANT,
      N.PRET,
      N.REST,
      N.TIP,
      N.D1,
      N.D2,
      N.D3,
      N.INDEXLOCAL,
      N.REZIDUU,
      N.CODPRODMAT,
      N.CANTUM1,
      N.UMSEC
    );
    MERGE INTO man_cmdprodmat m
    USING
    (
      select
        CMD.CODCMDPRODMAT,CMD.CODCOMANDA1,CMD.CODOBIECT,CMD.CANT,CMD.PRET,CMD.REST,CMD.TIP,CMD.D1,CMD.D2,CMD.D3,
        CMD.INDEXLOCAL,CMD.REZIDUU,CMD.CODPRODMAT,CMD.PARITATEECHIV,CMD.TIPECHIV,CMD.CUMSEC,CMD.CCANT,CMD.CODCMDPRODMAN,
        CMD.CANTUM1,CMD.CODCOMANDA3,CMD.UMSEC
      FROM MAN_COMANDA C
           INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
           INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1 AND CMD.TIP = 0
           INNER JOIN PRODNORME N ON C1.CODNORMA = N.CODNORMA
      WHERE C1.CODNORMA &gt; 0 AND N.IMPLICIT = 0
    ) N
    ON (m.CODCMDPRODMAT = N.CODCMDPRODMAT)
    WHEN NOT MATCHED THEN INSERT
    (
      M.CODCMDPRODMAT,M.CODCOMANDA1,M.CODOBIECT,M.CANT,M.PRET,M.REST,M.TIP,M.D1,M.D2,M.D3,
      M.INDEXLOCAL,M.REZIDUU,M.CODPRODMAT,M.PARITATEECHIV,M.TIPECHIV,M.CUMSEC,M.CCANT,M.CODCMDPRODMAN,
      M.CANTUM1,M.CODCOMANDA3,M.UMSEC
    )
    VALUES
    (
      N.CODCMDPRODMAT,N.CODCOMANDA1,N.CODOBIECT,N.CANT,N.PRET,N.REST,N.TIP,N.D1,N.D2,N.D3,
      N.INDEXLOCAL,N.REZIDUU,N.CODPRODMAT,N.PARITATEECHIV,N.TIPECHIV,N.CUMSEC,N.CCANT,N.CODCMDPRODMAN,
      N.CANTUM1,N.CODCOMANDA3,N.UMSEC
    );
  END IF;

  INSERT INTO MAN_CMDPRODMAT
  SELECT DISTINCT
    codcomanda1,
    CODCOMANDA1,
    C1.CODOBIECT,
    CANTACCEPTAT,
    PU,
    RESTACCEPTAT,
    1,--TIP,
    C1.D1,
    C1.D2,
    C1.D3,
    CODCOMANDA1, --INDEXLOCAL
    0,--REZIDUU
    0,--CODPRODMAT
    1,--PARITATEECHIV
    0,--TIPECHIV
    UMSEC, --CUMSEC
    CANTACCEPTAT, --CCANT
    null,--CODCMDPRODMAN
    CANTUM1,
    0,--CODCOMANDA3
    UMSEC
   FROM MAN_COMANDA C
        INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA AND Coalesce(C1.Modinchidere,0)=2
        INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
        INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  WHERE C.TipDoc = 92 AND A.TIPARTICOL = &apos;0&apos;;

  DELETE TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCOMANDA&apos; AND TMP.VALOARE1 = &apos;GENNP&apos;;
  delete manevra_unic where userid = auserid;
END;

PROCEDURE PREPARE_MAN_COMENZI_CLIENTI(aCODPART IN NUMBER, ANLUNALUCRU IN NUMBER)
IS
  NR NUMBER(20) := 0;
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE MAN_COMANDA&apos;;
  INSERT INTO MAN_COMANDA
  SELECT DISTINCT C.*
  FROM
    COMANDA C,
    COMANDA1 C1
  WHERE
    PARTENER = aCODPART
    AND TIPDOC = 18
    AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
    AND C1.CODCOMANDA = C.CODCOMANDA
    AND (((C1.CANTACCEPTAT &gt; 0 AND C1.RESTACCEPTAT &gt; 0)OR(C1.CANTACCEPTAT &lt; 0 AND C1.RESTACCEPTAT &lt; 0))OR((C1.RESTACCEPTAT &lt;= 0)
          AND (C1.CODCOMANDA1 IN( SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL)))
        );

   SELECT COUNT(*) INTO NR FROM COMANDA WHERE TIPDOC = 94;
   IF NR &lt;&gt; 0 THEN
      INSERT INTO MAN_COMANDA
      SELECT DISTINCT C.*
      FROM
        COMANDA C,
        RAC_REZ R,
        COMANDA1 C1
      WHERE TIPDOC = 94
        AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
        AND R.CODCOMANDA = C.CODCOMANDA
        AND C1.CODCOMANDA = C.CODCOMANDA
        AND ( C.PARTENER = aCODPART OR R.CodSofer = aCODPART )
        AND (((C1.CANTACCEPTAT &gt; 0 AND C1.RESTACCEPTAT &gt; 0)OR(C1.CANTACCEPTAT &lt; 0 AND C1.RESTACCEPTAT &lt; 0))OR((C1.RESTACCEPTAT &lt;= 0)
              AND (C1.CODCOMANDA1 IN( SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL)))
            );

   END IF;

   SELECT COUNT(*) INTO NR FROM COMANDA WHERE TIPDOC = 92;
   IF NR &lt;&gt; 0 THEN
      INSERT INTO MAN_COMANDA
      SELECT DISTINCT C.*
      FROM
        COMANDA C
        LEFT JOIN COMANDA2 C2 ON C2.CODCOMANDA = C.CODCOMANDA,
        Comanda1 C1
      WHERE TIPDOC = 92
        AND C.AN * 12 + C.LUNA &lt;=  AnLunaLucru
        AND (C.Partener = aCODPART or Nvl(C2.Codpart,0) =  aCODPART)
        AND C1.CODCOMANDA = C.CODCOMANDA
        AND (((C1.CANTACCEPTAT &gt; 0 AND C1.RESTACCEPTAT &gt; 0)OR(C1.CANTACCEPTAT &lt; 0 AND C1.RESTACCEPTAT &lt; 0))OR((C1.RESTACCEPTAT &lt;= 0)
              AND (C1.CODCOMANDA1 IN( SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL)))
            );
   END IF;

END;

procedure AdaugaInObsCmd(aCodComanda in number, aCods in varchar2) is
crtObs varchar2(200);
aObs varchar2(2000);
begin
  begin
    select obs into crtObs from comanda where codcomanda = aCodComanda;
    execute immediate
      &apos;select
         string_agg(c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc)||&apos;&apos;(&apos;&apos;||p.den_part||&apos;&apos;)&apos;&apos;)
       from comanda c
            left join npart p on c.partener = p.codpart
       where c.codcomanda in (&apos;||aCods||&apos;) &apos; into aObs;
    crtObs := SUBSTR(crtObs||&apos;;&apos;||aObs, 1, 200);
    update comanda set obs = crtObs where codcomanda = aCodComanda;
  exception when others then return;
  end;
end;

procedure AdaugaInObsLinie(aCodComanda1 in number, aObs in varchar2) is
begin
  update comanda1 set
    obs = substr(obs||aObs, 1, 200)
  where codcomanda1 = aCodComanda1;
  commit;
end;

procedure UpdatePretPrjProd(aCodComanda1 in number, aPret in number, aCodReteta in number, aCodProiect in number) is
Tmp number(20);
aCodComanda number(20);
begin
  begin
    select CodComanda into aCodComanda from comanda1 where codcomanda1 = aCodComanda1;
  exception when others then aCodComanda := 0;
  end;
  if aCodComanda &gt; 0 then
    begin
      select CodComanda into Tmp from comanda where codcomanda = aCodComanda for update nowait;
      update Comanda1 set
        pu = aPret,
        CodReteta = aCodReteta,
        CodProiect = aCodProiect,
        Consum = case when aCodProiect &gt; 0 then 1 else 0 end,
        CuLansare = case when aCodProiect &gt; 0 then 1 else 0 end
      where codcomanda1 = aCodComanda1;
      commit;
    exception when others then Raise;
    end;
  end if;
end;

function ActualizeazaLinie(aCodComanda in number, aCodComanda1 in number, aCodObiect in number, aCodReteta in number, aCant in number) return number is
aIndexLocal number;
aDataDoc date;
Rez number(1);
vCant number(20,7);
vRest number(20,7);
aCount number;
begin
  Rez := 1;
  if aCodComanda1 = 0 then
    -- insert
    select max(c1.indexlocal) + 1 into aIndexLocal
    from comanda1 c1
    where c1.codcomanda = aCodComanda;

    select c.datadoc into aDataDoc
    from comanda c
    where c.codcomanda = aCodComanda;

    insert into comanda1 (CodComanda1,IndexLocal,CodObiect,CantComandat,CantAcceptat,
                          Termen,UMSec,CuLansare,CodReteta,Consum)
    select seq_comanda1_codcomanda1.nextval, aIndexLocal, aCodObiect, aCant, aCant,
           aDataDoc, num1.codum1, 1, aCodreteta, 1
    from nartobj obj
         inner join nart art on art.codarticol = obj.codarticol
         left join num1 on num1.codum = art.um and num1.secundara = 0
    where obj.codobiect = aCodObiect;

    insert into cmdprodman (codcmdprodman, codcomanda1, codman, nrop, codop, codloc, codtarif, tu, cant, rest,
                            valoare, codprodgest, indexlocal, DSV, Fix, Nivel, bps, tpi, obs, detalii)
    select seq_cmdprodman_codcmdprodman.nextval, acodcomanda1, PM.codman, PM.nrop, PM.codop, PM.codloc, PM.codtarif, PM.tu, aCant/PM.BPS, aCant/PM.BPS,
           PM.valoare, PM.codprodgest, PM.indexlocal, PM.DSV, PM.Fix, PM.Nivel, PM.bps, PM.tpi, PM.obs, PM.detalii
    FROM PRODMAN PM
         INNER JOIN PRODCOMP PC ON PC.CodProdComp = PM.CodProdComp
    WHERE PM.CODPRODCOMP = aCodReteta;

    insert into cmdprodmat(codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip,
                           indexlocal, reziduu, codprodmat, paritateechiv, tipechiv, cumsec, ccant)
    select seq_cmdprodmat_codcmdprodmat.nextval, aCodComanda1, obj.codobiect, aCant, (select pret from prodcomp where codprodcomp = aCodReteta), aCant, 0,
           0, 0, 0, 1, 0, num1.codum1, aCant
    from nartobj obj
         inner join nart art on art.codarticol = obj.codarticol
         left join num1 on num1.codum = art.um and num1.secundara = 0
    where obj.codobiect = aCodObiect;

    insert into cmdprodmat(codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip,
                           indexlocal, reziduu, codprodmat, paritateechiv, tipechiv, cumsec, ccant)
    select seq_cmdprodmat_codcmdprodmat.nextval, aCodComanda1, obj.codobiect, aCant, mat.pret, aCant, 1,
           0, 0, 0, 1, 0, num1.codum1, aCant
    from prodmat mat
         inner join nartobj obj on mat.codobiect = obj.codobiect
         inner join nart art on art.codarticol = obj.codarticol
         left join num1 on num1.codum = art.um and num1.secundara = 0
    where mat.codprodcomp = aCodReteta;

    insert into cmdprodmat(codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip,
                           indexlocal, reziduu, codprodmat, paritateechiv, tipechiv, cumsec, ccant)
    select seq_cmdprodmat_codcmdprodmat.nextval, aCodComanda1, obj.codobiect, aCant, mat.pret, aCant, 2,
           0, 0, 0, 1, 0, num1.codum1, aCant
    from prodrez mat
         inner join nartobj obj on mat.codobiect = obj.codobiect
         inner join nart art on art.codarticol = obj.codarticol
         left join num1 on num1.codum = art.um and num1.secundara = 0
    where mat.codprodcomp = aCodReteta;
  else
    select cant, rest into vCant, vRest
    from cmdprodmat
    where codcomanda1 = aCodComanda1 and tip = 0;
    if aCant = 0 then
      delete cmdprodmat where codcomanda1 = aCodComanda1;
      delete cmdprodman where codcomanda1 = aCodComanda1;
      delete comanda1 where codcomanda1 = aCodComanda1;

      select count(codcomanda1) into aCount from comanda1 where codcomanda = aCodComanda;
      if aCount = 0 then
        delete comanda where codcomanda = aCodComanda;
      end if;
    else
      if vCant - aCant &gt; vRest then
        Rez := 0;
      else
        update comanda1 set cantacceptat = aCant, cantcomandat = aCant where codcomanda1 = aCodComanda1;
        update cmdprodman set rest = rest - (Cant - aCant), cant = aCant where codcomanda1 = aCodComanda1;
        update cmdprodmat set rest = rest - (Cant - aCant), cant = aCant where codcomanda1 = aCodComanda1;
      end if;
    end if;
  end if;
  return Rez;
end;

function DinCmdCli(aCodComanda1 in number) return number is
aCodCmd1 number(20);
aTipDoc number(20);
begin
  begin
    select codliniecomanda into aCodCmd1
    from cmdlink
    where codcomanda1 = aCodComanda1;
  exception when others then
   aCodCmd1 := 0;
  end;

  if aCodCmd1 &gt; 0 then
    return DinCmdCli(aCodCmd1);
  else
    begin
      select c.tipdoc into aTipDoc
      from comanda1 c1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where c1.codcomanda1 = aCodComanda1;
    exception when others then
      aTipDoc := 0;
    end;
    if aTipDoc = 18 then
      return aCodComanda1;
    else
      return 0;
    end if;
  end if;
end;

function DinCmdCliFaraProiect(aCodComanda1 in number) return number is
aCodProiect number(20);
aCodCmd1 number(20);
begin
  begin
    select codliniecomanda into aCodCmd1
    from cmdlink
    where codcomanda1 = aCodComanda1;
  exception when others then
   aCodCmd1 := 0;
  end;

  if aCodCmd1 &gt; 0 then
    return DinCmdCliFaraProiect(aCodCmd1);
  else
    begin
      select nvl(c1.CodProiect,0) into aCodProiect
      from comanda1 c1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where c.tipdoc = 18 and c1.codcomanda1 = aCodComanda1;
    exception when others then
      aCodProiect := 0;
    end;
    if aCodProiect &gt; 0 then
      return 0;
    else
      return 1;
    end if;
  end if;
end;

FUNCTION INFO_STINGERE_COMANDA(aCODCOMANDA IN NUMBER) RETURN VARCHAR2
IS
  STARE VARCHAR2(1000) := &apos;&apos;;
  CANTACCEPTAT NUMBER(20, 7) := 0;
  RESTACCEPTAT NUMBER(20, 7) := 0;
  FACTURATE    NUMBER(20, 0) := 0;
  STORNATE     NUMBER(20, 0) := 0;
  AVIZATE      NUMBER(20, 0) := 0;
BEGIN
  SELECT NVL(SUM(CANTACCEPTAT), 0), NVL(SUM(RESTACCEPTAT), 0)  INTO CANTACCEPTAT, RESTACCEPTAT FROM COMANDA1 WHERE CODCOMANDA = aCODCOMANDA;
  IF RESTACCEPTAT = CANTACCEPTAT THEN RETURN &apos;Nefacturata&apos;;
  ELSE
    STORNATE := 0; FACTURATE := 0; AVIZATE := 0;
    FOR V_REC IN
    (
    SELECT
      CSTORNO.CODCOMANDA AS CODCMDSTORNO,
      CL.CANT AS CANTSTORNO,
      I.TIPDOC AS TIPDOCIES,
      IL.CANT AS CANTIES,
      ILFACTAV.CODIES1 AS CODIES1FACTAVIZ
    FROM
      COMANDA1 C1
      LEFT OUTER JOIN CMDLIVRLINK CL ON CL.CODLINIECOMANDA = C1.CODCOMANDA1
      LEFT OUTER JOIN COMANDA1 C1STORNO ON C1STORNO.CODCOMANDA1 = CL.CODCOMANDA1
      LEFT OUTER JOIN COMANDA  CSTORNO ON CSTORNO.CODCOMANDA = C1STORNO.CODCOMANDA AND CSTORNO.TIPDOC = 65
      LEFT OUTER JOIN IESLINK IL ON IL.CODLINIECOMANDA = C1.CODCOMANDA1
      LEFT OUTER JOIN IESIRI1  I1 ON I1.CODIES1 = IL.CODIES1
      LEFT OUTER JOIN IESIRI I ON I.CODIES = I1.CODIES
      LEFT OUTER JOIN IESLINK ILFACTAV ON ILFACTAV.CODLINIEAVIZ = I1.CODIES1 AND I.TIPDOC = 20
    WHERE
     C1.CODCOMANDA = aCODCOMANDA
    )
    LOOP
      IF NVL(V_REC.CODCMDSTORNO, 0) &lt;&gt; 0 AND  NVL(V_REC.CANTSTORNO, 0) &lt;&gt; 0 THEN STORNATE := STORNATE + 1;
      END IF;

      IF NVL(V_REC.TIPDOCIES  , 0) = 19 AND  NVL(V_REC.CANTIES, 0) &lt;&gt; 0 THEN FACTURATE := FACTURATE + 1;
      END IF;

      IF NVL(V_REC.TIPDOCIES  , 0) = 20 AND  NVL(V_REC.CANTIES, 0) &lt;&gt; 0 THEN
      BEGIN
         IF NVL(V_REC.CODIES1FACTAVIZ, 0) &lt;&gt; 0 THEN FACTURATE := FACTURATE + 1;
         ELSE
           AVIZATE := AVIZATE + 1;
         END IF;
      END;
      END IF;

    END LOOP;

    IF RESTACCEPTAT = 0 THEN
      STARE := &apos;Integral &apos;;
    ELSE
      STARE := &apos;Partial &apos;;
    END IF;

    IF FACTURATE &lt;&gt; 0 THEN STARE := STARE || &apos;facturata &apos;;
    END IF;

    IF STORNATE &lt;&gt; 0 THEN STARE := STARE || &apos;stornata &apos;;
    END IF;

    IF AVIZATE &lt;&gt; 0 THEN STARE := STARE || &apos;avizata &apos;;
    END IF;

  END IF;

  RETURN STARE;
END;

FUNCTION GET_GESTIUNI_COMANDA1(aCODCOMANDA IN NUMBER ) RETURN VARCHAR2
IS
 GESTIUNI VARCHAR2(2000) := &apos;&apos;;
BEGIN
  FOR V_REC IN (
    SELECT DEN_GEST
    FROM (
      SELECT GESTACT, Min(INDEXLOCAL) INDEXLOCAL
      FROM COMANDA1
      WHERE CODCOMANDA = aCODCOMANDA AND Coalesce(GESTACT, 0) &lt;&gt; 0
      GROUP BY GESTACT
    ) C1  LEFT JOIN NGEST G ON G.CODGEST = C1.GESTACT
    ORDER BY INDEXLOCAL
  ) LOOP
    IF COALESCE(Length(GESTIUNI),0) + Length(V_REC.DEN_GEST) &lt; 1998 THEN
      GESTIUNI := GESTIUNI || V_REC.DEN_GEST || &apos;;&apos;;
    ELSE
      GESTIUNI := GESTIUNI || &apos;...&apos;;
      EXIT;
    END IF;
  END LOOP;
  RETURN GESTIUNI;
END;

procedure ModificaRezervariCC(aCodComanda in number) is
acant NUMBER(20,7);
aTot NUMBER(20,7);
begin
  for v_rec in (select tmp.codcomanda1, nvl(tmp.cantacceptat, 0) tmpacc, c1.cantacceptat
                from comanda1 c1
                     left join tmp_comanda1 tmp on tmp.codcomanda1 = c1.codcomanda1
                where tmp.cantacceptat &lt; c1.cantacceptat and c1.codcomanda = acodcomanda) loop
    select sum(rest) into aTot from rezervats where codcomanda1f = v_rec.codcomanda1;
    if v_rec.tmpacc &gt; aTot then
      acant := 0;
    else
      acant := aTot - v_Rec.tmpacc;
    end if;
    for v_tmp in (select codrezervats, CodComanda1, Rest, CodObiect from rezervats where codcomanda1f = v_rec.codcomanda1) loop
      if aCant &gt; 0 then
        if aCant &gt; v_tmp.rest then
          delete from rezervats where codrezervats = v_tmp.Codrezervats;
          update rezervats
          set-- cantrezervat = cantrezervat + v_tmp.rest,
              rezervatini = rezervatini + v_tmp.rest,
              rest = rest + v_tmp.rest
          where codcomanda1 = v_tmp.codcomanda1 and nvl(codcomanda1f, 0) = 0 and CodObiect = v_tmp.CodObiect;
          aCant := aCant - v_tmp.rest;
        else
          update rezervats
          set --cantrezervat = cantrezervat - aCant,
              rezervatini = rezervatini - aCant,
              rest = rest - aCant
          where codrezervats = v_tmp.Codrezervats;
          update rezervats
          set --cantrezervat = cantrezervat + aCant,
              rezervatini = rezervatini + aCant,
              rest = rest + aCant
          where codcomanda1 = v_tmp.codcomanda1 and nvl(codcomanda1f, 0) = 0 and CodObiect = v_tmp.CodObiect;
          aCant := 0;
        end if;
      end if;
    end loop;

  end loop;
end;

PROCEDURE MUTA_REZERVARI_STORNO_OUT(CODCOMANDA1_SURSA IN NUMBER, CODCOMANDA1_DEST IN NUMBER, aCANT IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTMUTATA   NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTMUTATA := aCANT;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
     CODCOMANDA1 = CODCOMANDA1_SURSA
   )
   LOOP
     IF (V_REC.REST &gt; 0)AND(CANTMUTATA &gt; 0) THEN
       IF CANTMUTATA &lt;= V_REC.REST THEN
         CANTREZ := CANTMUTATA;
       ELSE
         CANTREZ := V_REC.REST;
       END IF;

       CANTMUTATA := CANTMUTATA - CANTREZ;

       IF CANTMUTATA = V_REC.REST THEN
         NEEDSTERGERE := 1;
       ELSE
         NEEDSTERGERE := 0;
       END IF;

       IF NEEDSTERGERE = 0 THEN
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = CANTREZERVAT - CANTREZ,
           REST         = REST         - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;
       ELSE
         DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;

       SELECT COUNT(*) INTO NR FROM REZERVATS
       WHERE
         CODNIRSTOC      = V_REC.CODNIRSTOC
         AND CODNIRSER   = V_REC.CODNIRSER
         AND CODCOMANDA1 =  CODCOMANDA1_DEST;
       IF NR = 0 THEN
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, REZERVATINI, UMSEC)
                      VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, CODCOMANDA1_DEST,  V_REC.CODNIRSTOC,  V_REC.CODNIRSER, 0, CANTREZ, V_REC.UMSEC);
       ELSE
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = 0,
           REST         = 0,
           REZERVATINI  = REZERVATINI +  CANTREZ
         WHERE
           CODNIRSTOC      = V_REC.CODNIRSTOC
           AND CODNIRSER   = V_REC.CODNIRSER
           AND CODCOMANDA1 = CODCOMANDA1_DEST;
        END IF;
     END IF;
   END LOOP;
END;


PROCEDURE MUTA_REZERVARI_STORNO_IN(CODCOMANDA1_SURSA IN NUMBER, CODCOMANDA1_DEST IN NUMBER, aCANT IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTMUTATA   NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTMUTATA := aCANT;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
     CODCOMANDA1 = CODCOMANDA1_SURSA
   )
   LOOP
     IF (V_REC.REZERVATINI &gt; 0)AND(CANTMUTATA &gt; 0) THEN
       IF CANTMUTATA &lt;= V_REC.REZERVATINI THEN
         CANTREZ := CANTMUTATA;
       ELSE
         CANTREZ := V_REC.REZERVATINI;
       END IF;

       CANTMUTATA := CANTMUTATA - CANTREZ;

       IF CANTMUTATA = V_REC.REZERVATINI THEN
         NEEDSTERGERE := 1;
       ELSE
         NEEDSTERGERE := 0;
       END IF;

       IF NEEDSTERGERE = 0 THEN
         UPDATE REZERVATS
         SET
           REZERVATINI = REZERVATINI - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;
       ELSE
         DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;

       SELECT COUNT(*) INTO NR FROM REZERVATS
       WHERE
         CODNIRSTOC      = V_REC.CODNIRSTOC
         AND CODNIRSER   = V_REC.CODNIRSER
         AND CODCOMANDA1 =  CODCOMANDA1_DEST;
       IF NR = 0 THEN
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC)
                      VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, CODCOMANDA1_DEST,  V_REC.CODNIRSTOC, V_REC.CODNIRSER, CANTREZ, V_REC.UMSEC);
       ELSE
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = CANTREZERVAT + CANTREZ,
           REST         = REST + CANTREZ
         WHERE
           CODNIRSTOC      = V_REC.CODNIRSTOC
           AND CODNIRSER   = V_REC.CODNIRSER
           AND CODCOMANDA1 = CODCOMANDA1_DEST;
        END IF;
     END IF;
   END LOOP;
END;


PROCEDURE PUNE_REZERVARI_STORNO
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_CMDLIVRLINK_INITIAL)
  LOOP
    MUTA_REZERVARI_STORNO_IN(V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA,  V_REC.CANT);
  END LOOP;
END;


PROCEDURE SCADE_REZERVARI_STORNO
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_CMDLIVRLINK)
  LOOP
    MUTA_REZERVARI_STORNO_OUT(V_REC.CODLINIECOMANDA, V_REC.CODCOMANDA1, V_REC.CANT);
  END LOOP;
END;


PROCEDURE INCHIDE_LINIE_COMANDA(aCODLINIECOMANDA IN NUMBER)
IS
  aCODCOMANDA  NUMBER(20) := 0;
  aDISPLIVRARE NUMBER(1) := 0;
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT CODCOMANDA INTO aCODCOMANDA FROM COMANDA1 WHERE  CODCOMANDA1 = aCODLINIECOMANDA;
    EXCEPTION WHEN OTHERS THEN aCODCOMANDA := 0;
  END;

  IF aCODCOMANDA &gt; 0 THEN
    BEGIN
      SELECT DISPLIVRARE INTO aDISPLIVRARE FROM COMANDA WHERE CODCOMANDA = aCODCOMANDA;
      EXCEPTION WHEN OTHERS THEN aDISPLIVRARE := 0;
    END;

    UPDATE COMANDA1 C1
    SET
      C1.CANTACCEPTAT = NVL((SELECT SUM(CANT) FROM IESLINK     WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) +
                        NVL((SELECT SUM(CANT) FROM CMDLIVRLINK WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) +
                        NVL((SELECT SUM(CANT) FROM TRANSFLINK  WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) ,
      C1.RESTACCEPTAT = 0
    WHERE C1.CODCOMANDA1 = aCODLINIECOMANDA;


    -- DACA COMANDA ESTE DE TIP DL INCHID SI COMENZILE CLIENT DE PE CARE S-AU PRELUAT CANTITATILE
    -- MODIFIC SI CANTITATEA PE PACHETEDLLINK PT A ACTUALIZA ULTERIOR SI PACHETUL
    IF aDISPLIVRARE = 1 THEN
      FOR V_REC IN (SELECT * FROM CMDLIVRLINK WHERE CODCOMANDA1 = aCODLINIECOMANDA)
      LOOP
        UPDATE COMANDA1 C1
        SET
          C1.CANTACCEPTAT = NVL((SELECT SUM(CANT) FROM IESLINK     WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) +
                            NVL((SELECT SUM(CANT) FROM CMDLIVRLINK WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) +
                            NVL((SELECT SUM(CANT) FROM TRANSFLINK  WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0) ,
          C1.RESTACCEPTAT = 0
        WHERE C1.CODCOMANDA1 = V_REC.CODLINIECOMANDA;
      END LOOP;
      UPDATE PACHETEDLLINK SET CANT = (SELECT CANTACCEPTAT FROM COMANDA1 WHERE CODCOMANDA1 = ACODLINIECOMANDA)
      WHERE CODCOMANDA1 = ACODLINIECOMANDA;
      FOR V_REC IN (SELECT * FROM PACHETEDLLINK WHERE CODCOMANDA1 = aCODLINIECOMANDA) LOOP
        UPDATE PACHETEOBJ POBJ
        SET
          REST = CANT - NVL((SELECT SUM(CANT) FROM PACHETELINK WHERE CODPACHETEOBJ = POBJ.CODPACHETEOBJ), 0) -
                        NVL((SELECT SUM(CANT) FROM PACHETEDLLINK WHERE CODPACHETEOBJ = POBJ.CODPACHETEOBJ), 0)
        WHERE POBJ.CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
      END LOOP;
    END IF;


    update comanda C 
    set 
      valoare = (select sum(cantacceptat * pu) from comanda1 c1 where c1.codcomanda = aCODCOMANDA) 
    where codcomanda = aCODCOMANDA;


    COMMIT;
  END IF;
END;


PROCEDURE INCHIDE_LINIE_COMANDA_FURN(aCODLINIECOMANDA IN NUMBER)
IS
  aCODCOMANDA  NUMBER(20) := 0;
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT CODCOMANDA INTO aCODCOMANDA FROM COMANDA1 WHERE  CODCOMANDA1 = aCODLINIECOMANDA;
    EXCEPTION WHEN OTHERS THEN aCODCOMANDA := 0;
  END;

  IF aCODCOMANDA &gt; 0 THEN

    UPDATE COMANDA1 C1
    SET
      C1.CANTACCEPTAT = NVL((SELECT SUM(CANT) FROM INTRLINK     WHERE CODLINIECOMANDA = C1.CODCOMANDA1), 0),
      C1.RESTACCEPTAT = 0
    WHERE C1.CODCOMANDA1 = aCODLINIECOMANDA;

    COMMIT;
  END IF;
END;


PROCEDURE SetCantInComand1(vCodComanda1 in number, vCant in number) is
  pragma autonomous_transaction;
  CantProd number(20,7);
  CantMat  number(20,7);
begin
  select cantacceptat into cantprod from comanda1 where codcomanda1 = vCodComanda1;

  update comanda1
  set
    restacceptat = case when restacceptat + vCant - cantacceptat &lt; 0 then 0 else restacceptat + vCant - cantacceptat end,
    cantacceptat = vCant
  where codcomanda1 = vCodComanda1;

  update cmdprodmat
  set
    rest = case when rest + vCant - cant &gt; 0 then rest + vCant - cant else 0 end,
    cant = vCant
  where codcomanda1 = vCodCOmanda1 and tip = 0;

  for v_rec in (select codcmdprodmat, cant, rest from cmdprodmat where codcomanda1 = vCodComanda1 and tip &gt; 0 ) loop
    CantMat := v_rec.cant * vCant/CantProd;
    update cmdprodmat
    set
      rest = case when rest + cantmat - cant &gt; 0 then rest + cantmat - cant else 0 end,
      cant = Cantmat
    where codcmdprodmat = v_rec.codcmdprodmat;
  end loop;

  commit;
end;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

PROCEDURE MUTA_REZERVARI(CODCOMANDA1_SURSA IN NUMBER, CODCOMANDA1_DEST IN NUMBER, aCANT IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTMUTATA   NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTMUTATA := aCANT;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
     CODCOMANDA1 = CODCOMANDA1_SURSA
   )
   LOOP
     IF (V_REC.REST &gt; 0)AND(CANTMUTATA &gt; 0) THEN
       IF CANTMUTATA &lt;= V_REC.REST THEN
         CANTREZ := CANTMUTATA;
       ELSE
         CANTREZ := V_REC.REST;
       END IF;

       CANTMUTATA := CANTMUTATA - CANTREZ;

       IF CANTMUTATA = V_REC.REST THEN
         NEEDSTERGERE := 1;
       ELSE
         NEEDSTERGERE := 0;
       END IF;

       IF NEEDSTERGERE = 0 THEN
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = CAN - CANTREZ,
           REST         = NVL(REST, 0)         - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;

         UPDATE TMP_LIVR1 SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = V_REC.CODCOMANDA1
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);

         UPDATE TMP_LIVR1_INITIAL SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = V_REC.CODCOMANDA1
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);
       ELSE
         UPDATE REZERVATS
         SET
           REST         = NVL(REST, 0)         - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;

         --DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;

       SELECT COUNT(*) INTO NR FROM REZERVATS
       WHERE
         CODNIRSTOC      = V_REC.CODNIRSTOC
         AND CODNIRSER   = V_REC.CODNIRSER
         AND CODCOMANDA1 =  CODCOMANDA1_DEST;
       IF NR = 0 THEN
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC)
                      VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, CODCOMANDA1_DEST,  V_REC.CODNIRSTOC,  V_REC.CODNIRSER, CANTREZ, V_REC.UMSEC);


         UPDATE TMP_LIVR1 SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = CODCOMANDA1_DEST
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);

         UPDATE TMP_LIVR1_INITIAL SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = CODCOMANDA1_DEST
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);



       ELSE
         UPDATE REZERVATS
         SET
--         CANTREZERVAT = CANTREZERVAT + CANTREZ,
           REST         = NVL(REST, 0)         + CANTREZ
         WHERE
           CODNIRSTOC      = V_REC.CODNIRSTOC
           AND CODNIRSER   = V_REC.CODNIRSER
           AND CODCOMANDA1 = CODCOMANDA1_DEST;

         UPDATE TMP_LIVR1 SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = CODCOMANDA1_DEST
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);

         UPDATE TMP_LIVR1_INITIAL SET OBS = &apos;*&apos;
         WHERE
           CODIES1 = CODCOMANDA1_DEST
           AND CODNIRSTOC = V_REC.CODNIRSTOC
           AND NVL(CODNIRSER, 0) = NVL(V_REC.CODNIRSER, 0);


        END IF;
     END IF;
   END LOOP;
END;

PROCEDURE MUTA_REZERVARI_OUT
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_CMDLIVRLINK)
  LOOP
    MUTA_REZERVARI(V_REC.CODLINIECOMANDA, V_REC.CODCOMANDA1, V_REC.CANT);
  END LOOP;
END;


PROCEDURE MUTA_REZERVARI_IN_EXT
IS
BEGIN
  -- REGLEAZA REZERVARILE DE PE COMANDA PRELUATE PE DISPLIVRARE
  FOR V_REC IN (SELECT
                  LK.CODLINIECOMANDA,
                  L1.CODNIRSTOC,
                  L1.CODNIRSER,
                  L1.CANT

                FROM
                  TMP_LIVR1_INITIAL L1,
                  TMP_CMDLIVRLINK_INITIAL LK
                WHERE
                  L1.CODIES1 = LK.CODCOMANDA1
               )
  LOOP
    UPDATE REZERVATS
    SET
      REST = REST + V_REC.CANT
    WHERE
      CODCOMANDA1 = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC = V_REC.CODNIRSTOC
      AND CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

END;



PROCEDURE MUTA_REZERVARI_OUT_EXT
IS
BEGIN
  -- REGLEAZA REZERVARILE DE PE COMANDA PRELUATE PE DISPLIVRARE
  FOR V_REC IN (SELECT
                  LK.CODLINIECOMANDA,
                  L1.CODNIRSTOC,
                  L1.CODNIRSER,
                  L1.CANT

                FROM
                  TMP_LIVR1 L1,
                  TMP_CMDLIVRLINK LK
                WHERE
                  L1.CODIES1 = LK.CODCOMANDA1
               )
  LOOP
    UPDATE REZERVATS
    SET
      REST =  CASE
               WHEN REST &gt;= V_REC.CANT THEN  REST - V_REC.CANT
               ELSE 0
              END
    WHERE
      CODCOMANDA1 = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC = V_REC.CODNIRSTOC
      AND CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

END;



PROCEDURE MUTA_REZERVARI_IN
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_CMDLIVRLINK_INITIAL)
  LOOP
    MUTA_REZERVARI(V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA,  V_REC.CANT);
  END LOOP;
END;



FUNCTION LIVRAT_DIN_REZERVAT(aCODCOMANDA1 IN NUMBER, aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(10, 7) := 0;
BEGIN
  SELECT
    SUM(L1.CANTREZERVAT) INTO TOTAL
  FROM
    LIVR1 L1,
    IESLINK IL,
    IESIRI1 I1,
    IESIRI  I
  WHERE
     L1.CODIES1 = IL.CODIES1
     AND IL.CODLINIECOMANDA = aCODCOMANDA1
     AND NVL(L1.CODNIRSTOC, 0) = NVL(aCODNIRSTOC, 0)
     AND NVL(L1.CODNIRSER, 0)  = NVL(aCODNIRSER, 0)
     AND IL.CODIES1  = I1.CODIES1
     AND I.CODIES = I1.CODIES
     AND I.OPERAT = 1 AND I.ANULAT = 0;
   RETURN TOTAL;
END;

FUNCTION sunt_mat_neconsumate(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
aTip NUMBER(20);
BEGIN
  select consum into aTip from comanda1 where codcomanda1 = aCODCOMANDA1;
  if aTip = 1 then
    BEGIN
      SELECT SUM(rest) INTO SUMA FROM cmdprodmat
      WHERE
      CODCOMANDA1 = aCODCOMANDA1
      AND Tip = 1;
      EXCEPTION WHEN OTHERS THEN SUMA := 0;
    END;
  end if;
  if aTip = 2 then
    BEGIN
      SELECT SUM(rest) INTO SUMA FROM cmdprodmat
      WHERE
      CODCOMANDA1 = aCODCOMANDA1
      AND Tip &lt;&gt; 2;
      EXCEPTION WHEN OTHERS THEN SUMA := 0;
    END;
  end if;
  RETURN SUMA;
END;

FUNCTION sunt_prod_neintrate(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
aTip NUMBER(20);
BEGIN
  select consum into aTip from comanda1 where codcomanda1 = aCODCOMANDA1;
  if aTip = 1 then
    BEGIN
      SELECT SUM(rest) INTO SUMA FROM cmdprodmat
      WHERE
      CODCOMANDA1 = aCODCOMANDA1
      AND (Tip = 2 OR Tip = 0);
      EXCEPTION WHEN OTHERS THEN SUMA := 0;
    END;
   end if;
   if aTip = 2 then
    BEGIN
      SELECT SUM(rest) INTO SUMA FROM cmdprodmat
      WHERE
      CODCOMANDA1 = aCODCOMANDA1
      AND Tip = 2;
      EXCEPTION WHEN OTHERS THEN SUMA := 0;
    END;
   end if;
  RETURN SUMA;
END;

FUNCTION AM_FACTURA_FURNIZOR_LA_COMANDA(aCODCOMANDA  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(CANT) INTO SUMA FROM INTRLINK
    WHERE
    CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = aCODCOMANDA);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;

FUNCTION LINIE_COMANDA_FURNIZOR_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM INTRLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;


FUNCTION AM_FACTURA_CLIENT_LA_COMANDA(aCODCOMANDA  IN NUMBER) RETURN NUMBER
IS
--NR NUMBER(20) := 0;
  SUMA NUMBER(20,7) := 0;
BEGIN
  BEGIN
--  SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM IESLINK
    SELECT SUM(CANT) INTO SUMA FROM IESLINK
    WHERE
    CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA);
    EXCEPTION WHEN OTHERS THEN SUMA  := 0;
  END;
  IF SUMA = 0 THEN
    BEGIN
  --  SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM IESLINK
      SELECT SUM(CANT) INTO SUMA FROM CMDLIVRLINK
      WHERE
      CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA);
      EXCEPTION WHEN OTHERS THEN SUMA  := 0;
    END;
  END IF;
  IF SUMA = 0 THEN
    BEGIN
      SELECT SUM(CANT) INTO SUMA FROM EMULARE1
      WHERE
      CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA);
      EXCEPTION WHEN OTHERS THEN SUMA  := 0;
    END;
  END IF;
  IF SUMA = 0 THEN
     SUMA  :=  AM_FACTURA_SOFER_LA_COMANDA(aCODCOMANDA);
  END IF;
  RETURN SUMA;
END;


FUNCTION AM_FACTURA_SOFER_LA_COMANDA(aCODCOMANDA  IN NUMBER) RETURN NUMBER
IS
--NR NUMBER(20) := 0;
  SUMA NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT SUM(CANT) INTO SUMA FROM IESLINK
    WHERE
    CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA and Nvl(CuLansare,0) = 2);
    EXCEPTION WHEN OTHERS THEN SUMA  := 0;
  END;
  IF SUMA = 0 THEN
    BEGIN
      SELECT SUM(CANT) INTO SUMA FROM EMULARE1
      WHERE
      CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA and Nvl(CuLansare,0) = 2);
      EXCEPTION WHEN OTHERS THEN SUMA  := 0;
    END;
  END IF;
  RETURN SUMA;
END;


FUNCTION AM_TRANSFER_LA_COMANDA_GEST(aCODCOMANDA  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
  SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM TRANSFLINK
    WHERE
    CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA =  aCODCOMANDA);
    EXCEPTION WHEN OTHERS THEN NR  := 0;
  END;
  RETURN NR;
END;


FUNCTION LINIE_COMANDA_CLIENT_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM IESLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM CMDLIVRLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  END IF;

  IF NR = 0 THEN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM CMDLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  END IF;


  RETURN NR;
END;

FUNCTION LINIE_COMANDA_INTERNA_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
NR1 NUMBER(20) := 0;
NR2 NUMBER(20) := 0;
NR3 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(L.CODCMDPRODMAT), 0) INTO NR1
    FROM IESPRODLINK L
         INNER JOIN CMDPRODMAT MAT ON L.CODCMDPRODMAT = MAT.CODCMDPRODMAT
         INNER JOIN IESIRI1 I1 ON L.CODIES1 = I1.CODIES1
         INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
    WHERE
    MAT.CODCOMANDA1 = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR1 := 0;
  END;
  BEGIN
    SELECT NVL(COUNT(L.CODLINIECOMANDA), 0) INTO NR2
    FROM INTRPRODLINK L
         INNER JOIN CMDPRODMAT MAT ON L.CODLINIECOMANDA = MAT.CODCMDPRODMAT
         INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1
         INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    WHERE
    MAT.CODCOMANDA1 = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR2 := 0;
  END;
  BEGIN
    SELECT NVL(COUNT(L.CODCMDPRODMAN), 0) INTO NR3
    FROM MANPRODLINK L
         INNER JOIN CMDPRODMAN MAN ON L.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN RAPORTP2 R2 ON R2.CODRAPORTP2 = L.CODRAPORTP2
         INNER JOIN RAPORTP1 R1 ON R1.CODRAPORTP1 = R2.CODRAPORTP1
         INNER JOIN RAPORTP0 R0 ON R0.CODRAPORTP0 = R1.CODRAPORTP0
         INNER JOIN RAPORTP R ON R.CODRAPORTP = R0.CODRAPORTP
    WHERE
    MAN.CODCOMANDA1 = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR3 := 0;
  END;
  RETURN NR1+NR2+NR3;
END;

FUNCTION LINIE_COMANDA_GEST_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM TRANSFLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;

FUNCTION LINIE_COMANDA_SUB_STINSA(aCODCOMANDA1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM CMDLIVRLINK
    WHERE
    CODLINIECOMANDA = aCODCOMANDA1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    BEGIN
      SELECT NVL(COUNT(CODLINIECOMANDA), 0) INTO NR FROM IESLINK
      WHERE
      CODLINIECOMANDA = aCODCOMANDA1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;
  RETURN NR;
END;

PROCEDURE SETPARTENERCOMANDA(aPart in NUMBER)
IS
BEGIN
  PartenerComanda := aPart;
END;

FUNCTION CONDITIE_PART_COMANDA(aPart in NUMBER) RETURN NUMBER
IS
BEGIN
  IF aPart = PartenerComanda THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
  TMP_UserID NUMBER(20);
  TMP_UserNAME VARCHAR2(30);
  --RESOURCE_BUSY EXCEPTION;
  --PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -54);
  COMANDA_BLOCATA EXCEPTION;
  PRAGMA EXCEPTION_INIT(COMANDA_BLOCATA, -20999);
BEGIN
  SELECT NVL(UserIDBlocaj, 0) INTO TMP_UserID FROM COMANDA WHERE CodComanda = RecID;
  IF TMP_UserID &lt;&gt; 0 and TMP_UserID &lt;&gt; PKG_GLOBALS.UserID THEN RAISE COMANDA_BLOCATA; END IF;
  SELECT CodComanda INTO Tmp FROM COMANDA WHERE CodComanda = RecId FOR UPDATE NOWAIT;
  EXCEPTION WHEN COMANDA_BLOCATA THEN BEGIN
    BEGIN
      SELECT NVL(UserName, &apos;.NEDEFINIT.&apos;) INTO TMP_UserNAME FROM TMP_Utilizator WHERE NVL(CodUtilizator, 0) = TMP_UserID;
      EXCEPTION WHEN OTHERS THEN TMP_UserNAME := &apos;.NEDEFINIT.&apos;;
    END;
    RAISE_APPLICATION_ERROR(-20999, &apos;| Comanda selectata este blocata de utilizatorul &apos; || TMP_UserNAME || &apos;| !&apos;);
  END;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  DELETE TMP_COMANDA1_INITIAL;

  delete tmp_inventcont;
  INSERT INTO TMP_COMANDA FIELDS( CodComanda ) VALUES (0) ;

  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(PKG_GLOBALS.GetTipComanda);
  PKG_CFGTABLES.EXT_INSERTRECORD(PKG_GLOBALS.GetTipComanda);
  if ( PKG_GLOBALS.GetTipComanda = 18 ) then
    PKG_CFGTABLES.EXT_INSERTRECORD(103);
  end if;
  COMMIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  TIPCOMANDA NUMBER(20);
  ACARNETDOC NUMBER (20);
  ANRDOC NUMBER (20);

  --aCodComanda1 NUMBER(20);
  --aCant NUMBER(20, 7);
  --aCodObiect NUMBER(20);
  aCodSubunit NUMBER(20);
  aDataDoc DATE;
  aDoc varchar2(200);
/*  EXISTACOMANDRAC1 NUMBER(10) := 0;
  EXISTACOMANDC1 NUMBER(10) := 0;
  EXISTACOMANDF1 NUMBER(10) := 0;
  EXISTACOMANDI1 NUMBER(10) := 0;
  EXISTACOMANDL1 NUMBER(10) := 0;*/
  aDISPLIVRARE   NUMBER(1)  := 0;
  aCodLinieCli   NUMBER(20);
  aTipTranzactie number(1);
  aMIJLTRANSP      Number(20);
  aCodGestIni      Number(20);
  aMaxCode         Number(20);
  aCurCode         Number(20);
  aTipPtExt          NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
   SELECT
    TIPDOC,
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;DATADOC,
    DISPLIVRARE,
    nvl(TIPTRANZACTIE,0)
  INTO
    TIPCOMANDA,
    ACARNETDOC,
    ANRDOC,
    aCodSubunit,
    aDataDoc,
    ADOC,
    ADISPLIVRARE,
    aTipTranzactie
  FROM
    COMANDA
  WHERE
    CODCOMANDA = RECID;
  if TIPCOMANDA = 18 and aDispLivrare = 1 then
    aTipPtExt := 103;
  else
    aTipPtExt := TIPCOMANDA;
  end if;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, aTipPtExt);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM PACKING3 P3 WHERE P3.CODPACKING2 IN
         (SELECT P2.CODPACKING2  FROM PACKING2 P2 WHERE P2.CODPACKING1 IN (SELECT P1.CODPACKING1
                                                                                             FROM PACKING P JOIN PACKING1 P1 ON P1.CODPACKING = P.CODPACKING
                                                                                             WHERE P.CODDOC = RECID AND P.TIPDOC = TIPCOMANDA));

  DELETE FROM PACKING2 P2 WHERE P2.CODPACKING1 IN (SELECT P1.CODPACKING1
                                                                                             FROM PACKING P JOIN PACKING1 P1 ON P1.CODPACKING = P.CODPACKING
                                                                                             WHERE P.CODDOC = RECID AND P.TIPDOC = TIPCOMANDA);
  DELETE FROM PACKING1 P1 WHERE P1.CODPACKING IN (SELECT P.CODPACKING FROM PACKING P WHERE P.CODDOC = RECID AND P.TIPDOC = TIPCOMANDA);
  DELETE FROM PACKING P WHERE P.CODDOC = RECID AND P.TIPDOC = TIPCOMANDA;

  DELETE TMP_COMANDA1;

  DELETE TMP_CMDLINK_INITIAL;
  INSERT INTO TMP_CMDLINK_INITIAL (CODCOMANDA1, CODLINIECOMANDA, CANT) SELECT *  FROM CMDLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

  DELETE TMP_PRECMDLINK_INITIAL;
  INSERT INTO TMP_PRECMDLINK_INITIAL (CODCOMANDA1, CODPRECOMANDA1, CANT) SELECT *  FROM PRECMDLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

  DELETE TMP_CMDLIVRLINK_INITIAL;
  INSERT INTO TMP_CMDLIVRLINK_INITIAL (CODCOMANDA1, CODLINIECOMANDA, CANT) SELECT *  FROM CMDLIVRLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

  UPDATE TMP_CMDLIVRLINK_INITIAL L
   SET
    TERMENCOMANDA =
   (SELECT C1.TERMEN
    FROM
    COMANDA1 C1 WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA);

  DELETE TMP_PLANIFLINK_INITIAL;
  INSERT INTO TMP_PLANIFLINK_INITIAL (CODCOMANDA1, CODSTARE1)
  select CODCOMANDA1, CODSTARE1
  from planiflink where codcomanda1 in (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

  DELETE TMP_LIVR1_INITIAL;
  INSERT INTO TMP_LIVR1_INITIAL(CODLIVR1,
                                CODIES1,
                                CODNIRSTOC,
                                CODNIRSER,
                                CANT
                                )
  SELECT CODREZERVATS,
         CODCOMANDA1,
         CODNIRSTOC,
         CODNIRSER,
         REST
  FROM
    REZERVATS R
  WHERE
    CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);


  if aDISPLIVRARE = 1 THEN
    DELETE TMP_PACHETEDLLINK_INITIAL;
    INSERT INTO TMP_PACHETEDLLINK_INITIAL(CODCOMANDA1, CODPACHETEOBJ, CANT)
    SELECT PL.CODCOMANDA1, PL.CODPACHETEOBJ, PL.CANT
    FROM PACHETEDLLINK PL
         INNER JOIN PACHETEOBJ POBJ ON POBJ.CODPACHETEOBJ = PL.CODPACHETEOBJ
    WHERE PL.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
  end if;

  DELETE STORNOCMDF WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

  IF aDISPLIVRARE = 1 THEN
    MUTA_REZERVARI_IN_EXT;
  END IF;

  IF TIPCOMANDA = 65 THEN
    PUNE_REZERVARI_STORNO;
  END IF;

  IF TIPCOMANDA = 53 THEN
    DELETE FROM NODECHIV  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

    for v_rec in (select codcomanda1 from tmp_cmdlink_initial) loop
        begin
          SELECT
            c1.codcomanda1 into aCodLinieCli
          FROM cmdlink l
               inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1
               inner join comanda c on c1.codcomanda = c.codcomanda
          where c.tipdoc in (18,43)
          START WITH l.codcomanda1 = v_Rec.CodComanda1
          CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1;
        exception when others then
          aCodLinieCli := 0;
        end;
      DELETE FROM CMDLINK  WHERE CODCOMANDA1 = v_rec.codcomanda1;
        if aCodLinieCli &gt; 0 then
          UPDATE COMANDA1 C1
          SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(cc1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 cc1 on l.codcomanda1 = cc1.codcomanda1
                             inner join comanda cc on cc1.codcomanda = cc.codcomanda
                        where cc1.CodObiect = C1.CodObiect
                        and cc.tipdoc = 53 AND cC.OPERAT = 1 AND cC.ANULAT = 0
                        START WITH l.codliniecomanda = aCodLinieCli
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )
          WHERE
          C1.CODCOMANDA1 = aCodLinieCli;
        END IF;
      END LOOP;
  else
    INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
    ( SELECT CODCOMANDA1 FROM COMANDA1
      WHERE CODCOMANDA1 IN
      (SELECT CL.CODLINIECOMANDA
       FROM
         CMDLINK CL
         LEFT OUTER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = CL.CODCOMANDA1
       WHERE C1.CODCOMANDA = RECID
      )
    );
    DELETE FROM NODECHIV  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
    DELETE FROM CMDLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
    DELETE FROM PRECMDLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
    DELETE FROM PLANIFLINK  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
    UPDATE COMANDA1 C1
    SET
    C1.RESTLANSAT = C1.Cantacceptat -
               ( SELECT NVL(SUM(CL.CANT), 0)
                 FROM
                   CMDLINK CL
                   LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = CL.CODCOMANDA1
                   LEFT OUTER JOIN COMANDA CC ON CC1.CODCOMANDA = CC.CODCOMANDA
                 WHERE
                 CL.CODLINIECOMANDA = C1.CODCOMANDA1
                 and cc1.CodObiect = C1.CodObiect
                 AND CC.OPERAT = 1 AND CC.ANULAT = 0
                )
    WHERE C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1);
  end if;

  DELETE FROM INTRLINK WHERE CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
  DELETE FROM IESLINK  WHERE CODLINIECOMANDA IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
  DELETE FROM VOUCHERLINK  WHERE Nvl(CODCmd,0) IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);
  DELETE FROM PACHETEDLLINK WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID);

/*  EXISTACOMANDL1 := PKG_LIST_STRUCT.TmpExists(&apos;COMANDL1&apos;);
  EXISTACOMANDC1 := PKG_LIST_STRUCT.TmpExists(&apos;COMANDC1&apos;);
  EXISTACOMANDRAC1 := PKG_LIST_STRUCT.TmpExists(&apos;COMANDRAC1&apos;);
  EXISTACOMANDF1 := PKG_LIST_STRUCT.TmpExists(&apos;COMANDF1&apos;);
  EXISTACOMANDI1 := PKG_LIST_STRUCT.TmpExists(&apos;COMANDI1&apos;);*/

  FOR V_REC IN (SELECT CODCOMANDA1, CODOBIECT FROM COMANDA1 WHERE CODCOMANDA = RECID) LOOP
    DELETE FROM IESPRODLINK WHERE CODCMDPRODMAT IN (SELECT CODCMDPRODMAT FROM CMDPRODMAT WHERE CODCOMANDA1 = V_REC.CODCOMANDA1);
    DELETE FROM MANPRODLINK WHERE CODCMDPRODMAN IN (SELECT CODCMDPRODMAN FROM CMDPRODMAN WHERE CODCOMANDA1 = V_REC.CODCOMANDA1);

/*    IF EXISTACOMANDC1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM COMANDC1 WHERE CODCOMANDA1 = &apos;|| V_REC.CODCOMANDA1;
    END IF;

    IF EXISTACOMANDRAC1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM COMANDRAC1 WHERE CODCOMANDA1 = &apos;|| V_REC.CODCOMANDA1;
    END IF;

    IF EXISTACOMANDL1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM COMANDL1 WHERE CODCOMANDA1 = &apos;|| V_REC.CODCOMANDA1;
    END IF;

    IF EXISTACOMANDF1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM COMANDF1 WHERE CODCOMANDA1 = &apos;|| V_REC.CODCOMANDA1;
    END IF;

    IF EXISTACOMANDI1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM COMANDI1 WHERE CODCOMANDA1 = &apos;|| V_REC.CODCOMANDA1;
    END IF;*/

    DELETE FROM CMDPRODMAT WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

    for v_rez in (select * from rezervats where codcomanda1f = v_rec.codcomanda1) loop
      delete rezervats where codrezervats = v_rez.codrezervats;
      if v_rec.codobiect &lt;&gt; v_rez.codobiect then
        update rezervats
        set
            rezervatini = rezervatini + v_rez.rest,
            rest = rest + v_rez.rest
        where codcomanda1 = v_rec.codcomanda1 and nvl(codcomanda1f, 0) = 0 and CodObiect = v_rez.CodObiect;
      end if;
    end loop;
    DELETE FROM REZERVATS WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

		for v_x in (SELECT CODCMDPRODMAN FROM CMDPRODMAN WHERE CODCOMANDA1 = V_REC.CODCOMANDA1) loop
       for V_Y in (SELECT CODGANTT FROM GANTT WHERE CODCMDPRODMAN = V_X.CODCMDPRODMAN) loop
   		   DELETE FROM GANTT1 WHERE CODGANTT = V_Y.CodGantt;
       end loop;
  	   DELETE FROM GANTT WHERE CODCMDPRODMAN = V_X.CODCMDPRODMAN;
    end loop;
		DELETE FROM CMDPRODMAN WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

    if TipComanda = 53 and aTipTranzactie = 1 then
      for v_tmp in (select u2c.codutilaj2c, u2c.codutilaj2
                    from utilaje2c u2c
                    where u2c.codcomanda1 = v_rec.codcomanda1) loop
        update utilaje2c
        set codcomanda1 = null
        where codutilaj2c = v_tmp.codutilaj2c;
      end loop;
    end if;
     DELETE FROM COMANDA1 WHERE CODCOMANDA1 = V_REC.CODCOMANDA1 ;
  END LOOP;

  IF aDISPLIVRARE = 1 THEN
    FOR V_REC IN (SELECT * FROM TMP_PACHETEDLLINK_INITIAL) LOOP
      UPDATE PACHETEOBJ POBJ
      SET REST = CANT - (SELECT NVL(SUM(PL.CANT),0)
                         FROM PACHETELINK PL
                         WHERE PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ)
      WHERE POBJ.CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
    END LOOP;
  END IF;

 /* IF PKG_LIST_STRUCT.TMPEXISTS(&apos;COMANDC&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM COMANDC WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;COMANDRAC&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM COMANDRAC WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;COMANDL&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM COMANDL WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;COMANDF&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM COMANDF WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;COMANDI&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM COMANDI WHERE CODCOMANDA = &apos; || RECID;
  END IF;
*/
  IF TIPCOMANDA in (94) THEN -- comanda RentACar
    DELETE NPARCCOM WHERE CodComanda = RecId ;
    update comanda2 set CodComanda = 0 WHERE CodComanda = RecId ;
    update comanda3 set CodComanda = 0 WHERE CodComanda = RecId ;
    DELETE AVARIECAROSERIE WHERE CodComanda = RecId ;
  END IF;
  IF TIPCOMANDA in (92) THEN -- comanda SA
    DELETE NPARCCOM WHERE CodComanda = RecId ;
    DELETE FROM CMDPRODMAT WHERE CODCOMANDA3 IN (SELECT CODCOMANDA3 FROM COMANDA3 WHERE CODCOMANDA = RecId);
    DELETE comanda2 WHERE CodComanda = RecId ;
    DELETE comanda3 WHERE CodComanda = RecId ;
    DELETE AVARIECAROSERIE WHERE CodComanda = RecId ;
  END IF;

  IF TIPCOMANDA in (92,94) THEN -- comanda RentACar
    update Comanda set Blocat = 0 where CodComanda = (Select CodComanda from RAC_REZ where CodRezervare = RecID And CodComanda &gt; 0 );
    update RAC_REZ set CodRezervare = 0, Predat = 0 where CodRezervare = RecID;

    DELETE FROM NPARC3 WHERE CODCMD IN  ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID);

    DELETE NPARC0 WHERE CODCMD = RecID;
    BEGIN
      Select CodNParcG, CodNParcAut, Nvl(CodGestIni,0) into aCurCode, aMIJLTRANSP, aCodGestIni  from NParcG where CodCmd = RECID;
    EXCEPTION
      WHEN Others THEN
        aCurCode    := 0;
    END;
    if aCurCode &gt; 0 then
      Select Max(CodNParcG) into aMaxCode from NParcG where CodCmd = RECID;
      if aCurCode = aMaxCode then
        update NPARCAUT set CODGEST = aCodGestINI where CodNParcAut = aMIJLTRANSP;
      end if;
      Delete NParcG where CODNPARCG = aCurCode;
    end if;

    DELETE RAC_REZ WHERE CodComanda = RecId ;
    update Voucher set CodCmd = -CodCmd where Nvl(CODCmd,0) = RecID;
  END IF;

  DELETE FROM COMANDA  WHERE CodComanda = RecId ;

  --IF TIPCOMANDA IN (8, 18) THEN
  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;

  DELETE FROM CMDLIVRLINK CL WHERE EXISTS (SELECT CODCOMANDA1 FROM TMP_CMDLIVRLINK_INITIAL WHERE CODCOMANDA1 = CL.CODCOMANDA1);

  UPDATE COMANDA1 C1
  SET
  C1.RESTACCEPTAT = C1.Cantacceptat -
             ( SELECT NVL(SUM(CL.CANT), 0)
               FROM
                 CMDLIVRLINK CL
                 LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = CL.CODCOMANDA1
                 LEFT OUTER JOIN COMANDA CC ON CC1.CODCOMANDA = CC.CODCOMANDA
               WHERE
               CL.CODLINIECOMANDA = C1.CODCOMANDA1
               AND CC.OPERAT = 1 AND CC.ANULAT = 0
              ) -
             (SELECT NVL(SUM(IL.CANT), 0)
              FROM
                IESLINK IL
                LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
              WHERE
                IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
              ) -
             (SELECT NVL(SUM(IL.CANT), 0)
              FROM
                INTRLINK IL
                LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                LEFT OUTER JOIN INTRARI   I ON I.CODINTR  = I1.CODINTR
              WHERE
                IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
              )
  WHERE
   C1.CODCOMANDA1 IN (SELECT CODLINIECOMANDA FROM TMP_CMDLIVRLINK_INITIAL);

  UPDATE PRECOMANDA1 PC1
  SET
    PC1.REST = (SELECT NVL(SUM(L.CANT),0)
                FROM PRECMDLINK L
                     INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
                     INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                WHERE L.CODPRECOMANDA1 = PC1.CODPRECOMANDA1 AND
                      NVL(C.ANULAT,0) = 0 AND C.OPERAT = 1
                )
  WHERE PC1.CODPRECOMANDA1 IN (SELECT CODPRECOMANDA1 FROM TMP_PRECMDLINK_INITIAL);

  DELETE FROM COMANDA4 WHERE CODCOMANDA = RECID;
  DELETE FROM TERMENECMD WHERE CODCOMANDA = RECID;
  DELETE FROM CMDAVANS    WHERE  CODCOMANDA = RECID;
  DELETE FROM CMDAPROBARI WHERE  CODDOC = RECID AND TIPDOC = TIPCOMANDA;

  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = TIPCOMANDA)or(CODDOCASOC = RECID AND TIPDOCASOC = TIPCOMANDA);
  DELETE FROM Reclamatii WHERE CODDOC = RECID AND TIPDOC = TIPCOMANDA;
  DELETE FROM VOUCHERCADOULINK WHERE CODDOC = RECID AND TIPDOC = TIPCOMANDA;



  NotifyModif(2, RecId, &apos;COMANDA&apos;);
  if DoCommit then
    COMMIT;
  end if;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aTip           NUMBER(10);
  aCurs          NUMBER(20,7);
  aVALOARE       NUMBER(20,7);
	aValMin        NUMBER(20,7);
	aValDoc        NUMBER(20,7);
  TIPPREFIX      NUMBER(10) := 0;
  aTipTranzactie NUMBER(10);
  TIPCOMANDA     NUMBER(20);
  aModulCereale  NUMBER := Nvl(pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),2);
  aPartRO        NUMBER := 0;
  aPart          NUMBER(20);
  aCodGest       NUMBER(20);
  aDISPLIVRARE   NUMBER(1) := 0;
  aind           number;
  aCodGrupa      number;
  Inch           number(1);
  aFaraTVA       number(1);
  UseBuget       NUMBER := Nvl(pkg_categconst.GetValConstanta(&apos;UseBuget&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),2);
  aAn            number(4);
  aLuna          number(2);
  aTipPtExt      NUMBER(10);
  aMoneda        NUMBER(20);
  aDataDoc       date;
  anLunaLucru    number;
  aRotEFact      number;
BEGIN
  delete tmp_inventcont;

   PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(PKG_GLOBALS.GetTipComanda);

  INSERT INTO TMP_COMANDA (
    CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC,
    PARTENER, CODGEST, SUBUNITSURSA, SCADENTAV, INCHISA, VALOARE, AN, LUNA, OBS, MONEDA, DispLivrare,Verificat, Facturabil, Curs,
    CODCONTRACT, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT, VALDISCOUNT, CODLOCATIE,SUBUNITATEA, CODFISCAL, NUMEDELEGAT,
    ARECARNETDOC, NRI, FARATRANSPORT, PLATAPELOC, CODIES, PRETPROMOAPLICAT,SCHIMB,CODFORMATIE, LISTAT,
    FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA,
    TIPCUSTODIE,
    UserID, Tiptranzactie, SUBUNITDEST, NRMAXAPROBARI,STADIUWMS,CODPERSC, MOTIVINCHIDERE, CODPARTCOMIS, TIPLIVRARE, MAJORARI, GRATIE,
    EXPORTKLG,
    EXPORTATKLG,
    MODINCHIDERE,
    PLATFORMA_ONLINE,REMORCA,ROTEFACT
)
  SELECT
    C.CODCOMANDA, ABS(C.TIPDOC) , C.ANULAT, C.BLOCAT, C.OPERAT, C.PREFIXDOC, C.NRDOC, C.CARNETDOC, C.SERIADOC, C.DATADOC,
    C.PARTENER, C.CODGEST, C.SUBUNITSURSA, C.SCADENTAV, C.INCHISA, C.VALOARE, C.AN, C.LUNA, C.OBS, C.MONEDA, C.DispLivrare,C.Verificat, C.Facturabil, C.Curs,
    C.CODCONTRACT, C.DELEGAT, c.CODTRASEULIVR, c.ORDINELIVRARE, c.INSOTITOR, c.MIJLTRANSP,C.AGENT, C.VALDISCOUNT, C.CODLOCATIE, C.SUBUNITATEA, C.CODFISCAL, Decode(C.TIPDOC,57,P.NUME||&apos; &apos;||P.PRENUME,D.DELEGAT),
    Decode(Nvl(C.CARNETDOC,0),0,0,1), C.NRI, C.FARATRANSPORT, C.PLATAPELOC, C.CODIES, 1,C.SCHIMB,C.CODFORMATIE, C.LISTAT,
    C.FACTURA_APL_EXT, C.CODPERS_APL_EXT, C.LOT, C.NRTRANSP, C.CODIESAVANS, C.FARAFACTURA, C.DINONLINE, C.PRETCUAMANUNT, C.CODANALIZA,
    CASE
      WHEN C.TIPDOC &lt;&gt; 57 THEN NULL
      WHEN Nvl(C.SUBUNITSURSA,0) &lt;&gt; 0 THEN 3
      WHEN Nvl(C.CODGEST,0) &lt;&gt; 0 THEN 2
      ELSE 1
    END TIPCUSTODIE,
    C.UserID, NVL(C.tiptranzactie,0), C.SUBUNITDEST, C.NRMAXAPROBARI,C.STADIUWMS,C.CODPERSC,
    C.MOTIVINCHIDERE,
    C.CODPARTCOMIS, C.TIPLIVRARE, C.MAJORARI, C.GRATIE, C.EXPORTKLG, C.EXPORTATKLG, C.MODINCHIDERE, C.PLATFORMA_ONLINE, C.REMORCA,coalesce(C.ROTEFACT,0)
  FROM COMANDA C
    LEFT JOIN NPERS    P ON P.CODPERS    = C.DELEGAT  -- Ambalaje custodie (tipdoc = 57) am legatura cu npers in loc de nparttr
    LEFT JOIN NPARTTR  D ON D.CODPARTTR  = C.DELEGAT
  WHERE C.CodComanda = RecId;

  BEGIN
    SELECT NVL(C.TipTranzactie,0), C.TipDoc, C.TipDoc, Case When Coalesce(C.Curs, 0) = 0 then 1 else C.Curs end, CASE WHEN Upper(Trim(F.CodFiscal)) LIKE &apos;RO%&apos; THEN 1 ELSE 0 END PartRO,
           C.PARTENER, C.CodGest, NVL(DISPLIVRARE, 0), NVL(MIJLTRANSP,0), C.AN, C.LUNA, c.datadoc, c.moneda, c.An * 12 + c.luna, c.rotefact
    INTO aTipTranzactie, TipComanda, atip, aCurs, aPartRO, aPart, aCodGest, aDISPLIVRARE, MijlocTransportIni, aAn, aLuna, aDataDoc, aMoneda, AnLunaLucru,
         aRotEFact
    FROM TMP_COMANDA C LEFT JOIN NPARTCODFISC F ON F.COD_CODFISCAL = C.CODFISCAL;
  EXCEPTION
    WHEN OTHERS THEN aTipTranzactie := 0; aTip := 0; aCurs := 1; aPartRO := 0;  MijlocTransportIni := 0; aDISPLIVRARE := 0;
  END;

  IF aTIP = 8 THEN
    BEGIN
      UPDATE TMP_COMANDA C
      SET
        SCADENTAC = (SELECT SCADENTAC FROM NPART P WHERE P.CODPART = C.PARTENER);

      EXCEPTION WHEN OTHERS THEN NULL;
    END;
  END IF;


  INSERT INTO TMP_COMANDA1 (
    CODCOMANDA1, CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,
    PU, PULei, prioritate, codpromo1, SubunitSursa, DataStart,
    CANTCOMANDAT, CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
    CULANSARE, UMCorelat, PUCorelat, CODCADOU, DENUMCorelat,
    RESTLANSAT, TERMEN, ANULAT, ADDIM, PROCDISC, OBS, PRETORIG,
    COEFDISCMAJ, CODCATPRET, SCADENTA, DENUM, VALOARE, PARITATE,
    PROCTVA,
    DENOBIECT, TIPLINIE, CONSUM, REZERVATINI, D1, D2, D3,
    RelatieUM1, TipSursa, CodSursa, CantUm1, AcceptUM1, TIPPLATA, CADOU, CADOULINK, PRETPROMO, UM1, CoefIndirecte,
--    CodObiectOrig,
    ParitateOrig, DenUM1,
    CODRETETA, TIPRETETA, Codproiect, TipLivrare, CODANALIZANOD, Nivel, Pozitie, Rezervari, ProdusPropriu, ROTUNJIRE,
    PARTENER, EXCEPTIONAL, TAXA, CODCONTRACT1, CODOFERTA1, PRETUM1, CONTRACT, PROMOTIE, GESTACT, CODCENTRU, FARANIVELAPROB,
    CODEXTERN, CODINTERN, CODNORMA, MODINCHIDERE, TERMENCONTRACT,
    CMDCLILANS, CMDINTLANS, CODMIFIX, TipLinieSA, CONTSERV, CODLINIEDOCIMP, TIPDOCIMP, DISCMANUAL, Dataincarcarii, CodVamal,
    Masa, PUMin, ValAdaos, ProcAdaos , ProcAdaos1, FURNIZOR, PUProd
  )
  SELECT
    c1.CODCOMANDA1,c1.CODCOMANDA, c1.INDEXLOCAL, c1.CODOBIECT, c1.UMSEC,
    c1.PU * u1.Paritate, c1.PU * u1.Paritate * aCurs,prioritate, C1.codpromo1, C1.SubunitSursa, C1.DataStart,
    c1.CANTCOMANDAT / u1.Paritate, c1.CANTACCEPTAT / u1.Paritate, c1.RESTACCEPTAT / u1.Paritate, c1.CANTRETURNAT / u1.Paritate,
    c1.CULANSARE, c1.UMCorelat, c1.PUCorelat, C1.CODCADOU, u2.Den_UM1,
    c1.RESTLANSAT / u1.Paritate, c1.TERMEN, c1.ANULAT, nvl(C1.ADDIM, 0), C1.PROCDISC, C1.OBS, C1.PRETORIG * u1.Paritate,
    C1.COEFDISCMAJ, C1.CODCATPRET, C1.SCADENTA, u1.Den_UM1,
    CASE
      WHEN aRotEFact = 1
      THEN ROUND(c1.CANTACCEPTAT * c1.PU, 2)
      ELSE c1.CANTACCEPTAT * c1.PU
    END VALOARE,
    u1.Paritate,
    CASE
      WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL AND aPartRO = 1 THEN 0
      ELSE
        Case when  aTip = 94 then PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,Extract(year from R.DataStart), Extract(Month from R.DataStart))
             else PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU)
        end
    END PROCTVA,
    O.DENUMIRE, DECODE(NVL(A.TIPARTICOL, 0), 0, &apos;=&apos;, 2, &apos;=&apos;, &apos;S&apos;), c1.CONSUM, c1.REZERVATINI / u1.Paritate, c1.d1, c1.d2, c1.d3,
    a.relatieum1, c1.tipsursa, c1.codsursa, c1.cantum1, c1.AcceptUM1, C1.TIPPLATA,C1.CADOU, C1.CADOULINK,  C1.PRETPROMO, a.um1, c1.CoefIndirecte,
    --c1.codobiect codobiectorig,
    1 paritateorig, UMSPEC.Den_Um DenUM1,
    c1.codreteta, 1, c1.Codproiect, c1.TipLivrare, c1.CODANALIZANOD, c1.Nivel, c1.Pozitie, &apos;Rezervari&apos;, O.Produspropriu,
    CASE
     WHEN aTIP = 8 THEN O.ROTUNJIRE
     ELSE O.ROTVALUTA
    END,
    PKG_LIST_BASE_UTILS.GetPartComCli(C1.CODCOMANDA1), C1.EXCEPTIONAL, TAXA, C1.CODCONTRACT1, C1.CODOFERTA1, C1.PRETUM1, CTR.NRDOC, O.PROMOTIE, C1.GESTACT, C1.CODCENTRU, O.FARANIVELAPROB,
    SUBSTR(O.CODEXTERN, 1, 80),
    SUBSTR(O.CODINTERN, 1, 80), C1.CODNORMA, NVL(C1.MODINCHIDERE, 0), C1.TERMENCONTRACT,
    (select count(*) from lansare l where l.codcmd1 = C1.CodComanda1),
    (select count(*) from cmdlink where codliniecomanda = c1.Codcomanda1),
    C1.CODMIFIX, C1.TipLinieSA, A.CONTSERVICIU, C1.CODLINIEDOCIMP, C1.TIPDOCIMP, C1.DISCMANUAL, C1.DataIncarcarii, SUBSTR(O.CODVAMAL, 1, 80),
    o.masa, o.PRETMINIM,
		Case when Coalesce(o.PRETMINIM, 0) = 0 then 0 else c1.Pu*Coalesce(C1.Coefdiscmaj,1)*aCurs - Coalesce(o.PRETMINIM, 0) end,
		Case when Coalesce(o.PRETMINIM, 0) = 0 then 0
		     else Round(100*(c1.Pu*Coalesce(C1.Coefdiscmaj,1)*aCurs - Coalesce(o.PRETMINIM, 0))/o.PRETMINIM, 2) end ,
		Case when Coalesce(c1.PU, 0) = 0 then 0 else Round(100*(c1.Pu*aCurs - Coalesce(o.PRETMINIM, 0))/(c1.Pu*aCurs), 2) end,
    C1.FURNIZOR, C1.PUProd
  FROM COMANDA1 c1
       INNER JOIN NartObj o on o.CodObiect  = c1.CodObiect
       INNER JOIN Nart a    on a.CodArticol = o.CodArticol
       INNER JOIN NUM1 u1 ON u1.CodUM1 = c1.UmSec
       LEFT JOIN Rac_REZ R ON R.codComanda = c1.codComanda
       LEFT JOIN contract1 ctr1 ON C1.codContract1 = ctr1.codContract1
       LEFT JOIN contract  ctr ON  ctr1.codContract = ctr.codContract
       LEFT JOIN NUM UMSPEC on a.um1 = UMSPEC.CODUM
       LEFT JOIN NUM1 u2 ON u2.CodUM1 = c1.UmCorelat
  WHERE c1.CodComanda = RecId
  ORDER BY c1.IndexLocal;

  if UseBuget = 1 and aTip = 8 then
    update tmp_comanda1 set soldbuget = PKG_PLATI.GetSoldBuget1(Codanalizanod, aAn, aLuna);
  end if;

  IF TIPCOMANDA IN (8,18) THEN
    for v_rec in (select c1.codcomanda1, cli.denumire, cli.codextern
                  from tmp_comanda1 c1
                       inner join nartcli cli on cli.codobiect = c1.codobiect
                  where cli.codpart = apart) loop
      update tmp_comanda1 set denlapart = v_rec.denumire, codexternlapart = v_rec.codextern where codcomanda1 = v_rec.codcomanda1;
    end loop;
    for v_rec in (select c1.codcomanda1, cli.denumire, cli.codextern
                  from tmp_comanda1 c1
                       inner join nartcli cli on cli.codobiect = c1.codobiect
                       inner join nclasep cls on cli.codclasep = cls.codclasep
                       inner join npart p on cls.codclasep = p.codclasa
                  where p.codpart = apart and cls.codclasep &gt; 0) loop
      update tmp_comanda1 set denlapart = v_rec.denumire, codexternlapart = v_rec.codextern where codcomanda1 = v_rec.codcomanda1;
    end loop;

		select Sum(PUMin * CANTACCEPTAT * Paritate), Sum(Pu *CoefDiscMaj* CANTACCEPTAT * aCurs) into  aValMin,  aValDoc
		from TMP_Comanda1 where Coalesce(PUMin, 0) &gt; 0;

    update TMP_Comanda
		set
		  ValMin    =  aValMin,
			ValAdaos  = aValDoc - aValMin,
      ProcAdaos = Case when Coalesce(aValMin,0) = 0 then 0 else Round(100*(aValDoc - aValMin)/aValMin, 2) end;

  END IF;

  -- la comenzi furnizori incarc datele pt mijloace fixe
  if aTip = 8 then
    UPDATE TMP_COMANDA1 SET
    ESTEIMBMF = PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(contserv)
    WHERE TIPLINIE = &apos;S&apos;;

    UPDATE TMP_COMANDA1 C1 SET
    INFOMF = (SELECT MF.NRINVENTAR||&apos;-&apos;||O.DENUMIRE
    FROM MIFIX MF
      INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = MF.CODMIFIX
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST NG ON N.GEST = NG.CODGEST
      INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
    WHERE MF.TIP = &apos;MF&apos;
      AND MF1.ANSTART * 12 +  MF1.LUNASTART = (select max(mf2.Anstart*12+mf2.LunaStart) from mifix1 mf2 where mf2.codmifix = mf1.codmifix)
      AND MF.CODMIFIX = C1.CODMIFIX)
    WHERE C1.CODMIFIX &gt; 0;
  end if;

  if aTip = 53 and PKG_GLOBALS.Directiva(&apos;ARAMIS&apos;) then
    update tmp_comanda1 set Lansari = 0;
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_luni = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_marti = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_miercuri = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_joi = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_vineri = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_sambata = tmp.codcomanda1);
    update tmp_comanda1 tmp set
      Lansari = Lansari + (select count(*) from lansz1 l1 where l1.codcmd1_duminica = tmp.codcomanda1);
  end if;

  UPDATE TMP_COMANDA1 C1
  SET
    REZERVAT    = NVL((SELECT SUM(REST) / PARITATE FROM REZERVATS WHERE CODCOMANDA1 = C1.CODCOMANDA1 AND NVL(C1.Codproiect,0) = 0 ),0),
    NECESAR     = NVL(RESTACCEPTAT, 0) - NVL((SELECT SUM(REST) / PARITATE FROM REZERVATS WHERE CODCOMANDA1 = C1.CODCOMANDA1 AND NVL(C1.Codproiect,0) = 0), 0),
    NECESARINI  = NVL(RESTACCEPTAT, 0),
    VALDISCOUNT = NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * NVL(PROCDISC, 0)/100,
    TVA         = NVL(VALOARE * PROCTVA / 100,0);
  -- detaliile comenzii de productie
  --if atip = 53 then
  if atip = 53 and aTipTranzactie = 1 then
    if pkg_utilaje.GETCODUTILAJ2C &gt; 0 then
      UPDATE TMP_COMANDA1 C1
      SET
        interventie = (select i.denumire
                       from utilaje2c u2c
                            inner join utilaje2 u2 on u2.codutilaj2 = u2c.codutilaj2
                            inner join ninterventiiauto i on i.codinterventiiauto = u2.interventie
                       where u2c.codutilaj2c = pkg_utilaje.GETCODUTILAJ2C
                      ),
        utilaj      = (select obj.denumire
                       from utilaje2c u2c
                            inner join utilaje u on u2c.codutilaj = u.codutilaj
                            inner join nartobj obj on u.codobiect = obj.codobiect
                       where u2c.codutilaj2c = pkg_utilaje.GETCODUTILAJ2C
                      ),
        codutilaj2c = pkg_utilaje.GETCODUTILAJ2C;
    else
      UPDATE TMP_COMANDA1 C1
      SET
        interventie = (select i.denumire
                       from utilaje2c u2c
                            inner join utilaje2 u2 on u2.codutilaj2 = u2c.codutilaj2
                            inner join ninterventiiauto i on i.codinterventiiauto = u2.interventie
                       where u2c.codcomanda1 = c1.codcomanda1
                      ),
        utilaj      = (select obj.denumire
                       from utilaje2c u2c
                            inner join utilaje u on u2c.codutilaj = u.codutilaj
                            inner join nartobj obj on u.codobiect = obj.codobiect
                       where u2c.codcomanda1 = c1.codcomanda1
                      ),
        codutilaj2c = (select u2c.codutilaj2c
                       from utilaje2c u2c
                       where u2c.codcomanda1 = c1.codcomanda1
                      );
    end if;
  end if;
  if atip = 18 and aDispLivrare = 0 then
    UPDATE TMP_COMANDA1 C1
      SET
        interventie = (select to_char(o.nrdoc)||&apos;/&apos;||to_char(o.dataoferta,&apos;dd.mm.yyyy&apos;)
                       from oferta1 o1
                            inner join oferta o on o.codoferta = o1.codoferta
                       where o1.codoferta1 = c1.codoferta1
                      );
  end if;

  if atip = 53 then
    update tmp_comanda1 tmp set
      rezcmdini = (select count(*) from rezervats where rest &lt;&gt; 0 and codcomanda1 = tmp.codcomanda1),
      restacceptat = (select cmd.rest from cmdprodmat cmd where cmd.codcomanda1 = tmp.codcomanda1 and cmd.tip = 0);
  end if;

  for v_rec in (select c1.codcomanda1, c1.consum, pc.codobiect, obj.denumire
                from comanda1 c1
                     INNER join prodcomp pc on c1.codreteta = pc.codprodcomp
                     INNER join nartobj obj on pc.codobiect = obj.codobiect
                where codcomanda = recid) loop
    insert into tmp_cmdprodmat
    ( codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip,
      D1, D2, D3, IndexLocal,
      den_obiect, denum, Umsec, PARITATE, reziduu, Codprodmat,
      ParitateEchiv, TipEchiv,
      CodObiectOrig,
      Den_Orig, ccant, cumsec, tipcomponent, codcmdprodman,
      relatieum1, um1, cantum1, CodProdGest,
      CodIntern, CodInternEkiv, CodExtern, CodExternEkiv, CodComanda3)
    select
      CM.codcmdprodmat, CM.codcomanda1, CM.codobiect, CM.cant, CM.pret, CM.Rest, CM.Tip,
      CM.D1, CM.D2, CM.D3, nvl(CM.Indexlocal, pm.indexlocal),
      OBJ.denumire, U1.den_um1, nvl(cm.umsec,U1.CODUM1), U1.Paritate, CM.reziduu, CodProdMat,
      CM.Paritateechiv, CM.Tipechiv,
      case when cm.tip = 0 then v_rec.codobiect when cm.tip = 2 then CM.codobiect else PM.CodObiect end,
      case when cm.tip = 0 then v_rec.denumire when cm.tip = 2 then obj.denumire else objmat.Denumire end, cm.ccant, cm.cumsec,
      case
        when cm.tip = 1 then &apos;Material&apos;
        when cm.tip = 2 then &apos;Articol rezultant&apos;
        when cm.tip = 0 then
          case when v_rec.consum = 2 then &apos;Material&apos;
          else &apos;Articol rezultant&apos;
          end
       end, cm.codcmdprodman,
       art.relatieum1, art.um1, cm.cantum1, pm.codprodgest,
       objmat.codintern, obj.codintern, objmat.codextern, obj.codextern, CM.CODCOMANDA3
     from CMDPRODMAT CM
          INNER JOIN NARTOBJ OBJ ON CM.CODOBIECT = OBJ.CODOBIECT
          INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
          INNER JOIN NUM1 U1 ON ART.UM = U1.CODUM AND U1.SECUNDARA = 0
          left join prodmat pm on pm.codmat = cm.codprodmat
          left join nartobj objmat on objmat.codobiect = pm.codobiect
     WHERE CM.CODCOMANDA1 = v_rec.codcomanda1;

     insert into tmp_cmdprodman (codcmdprodman, codcomanda1, codman, nrop, codop, codloc, codtarif, tu, cant,
                                 rest, valoare, codprodgest, indexlocal, DSV, Fix, Nivel, bps, tpi, obs, detalii, den_operatie, den_locmunca, Dificultate,
                                 tarif, DATASTART, orastart, codutilaj, utilaj, decalaj, coefbps)
     select m.codcmdprodman, m.codcomanda1, m.codman, m.nrop, m.codop, m.codloc, m.codtarif, m.tu, m.cant,
            m.rest, m.valoare, m.codprodgest, m.indexlocal, m.DSV, m.Fix, m.Nivel, m.bps, m.tpi, m.obs, m.detalii, op.denumire, lm.denumire,
            t.denumire, t1.tarif,trunc(M.DATASTART), to_char(m.datastart,&apos;hh24:mi&apos;), m.codcmdprodman, o.denumire, m.decalaj, coalesce(m.coefbps,pm.coefbps,1)
     from cmdprodman m
          inner join locmunca lm on lm.codloc = m.codloc
          inner join noper op on op.codop = m.codop
          left join prodman pm on pm.codman = m.codman
          left join tarifeman t on m.codtarif = t.codtarif
          left join tarifeman1 t1 on t1.codtarif = t.codtarif AND pkg_globals.AnLunaLucru BETWEEN t1.alstart AND t1.alstop
          left join utilaje u on u.codutilaj = m.codutilaj
          left join nartobj o on o.codobiect = u.codobiect
     where m.codcomanda1 = v_rec.codcomanda1;

  end loop;

  UPDATE TMP_CMDPRODMAT C1
  SET
    TIPLINIE = &apos;=&apos;,
    REZERVAT = (SELECT SUM(REST) / 1 FROM REZERVATS WHERE CODCMDPRODMAT = C1.CODCMDPRODMAT);

  insert into tmp_cmdprodmat
    ( codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip,
      D1, D2, D3, IndexLocal,
      den_obiect, denum, Umsec, PARITATE, reziduu, Codprodmat,
      ParitateEchiv, TipEchiv,
      CodObiectOrig,
      Den_Orig, ccant, cumsec, tipcomponent, codcmdprodman,
      relatieum1, um1, cantum1, CodProdGest,
      CodIntern, CodInternEkiv, Codextern, CodexternEkiv, CodComanda3)
    select
      CM.codcmdprodmat, CM.codcomanda1, CM.codobiect, CM.cant, CM.pret, CM.Rest, CM.Tip,
      CM.D1, CM.D2, CM.D3, CM.Indexlocal,
      OBJ.denumire, case when u1sa.codum1 &gt; 0 then u1sa.den_um1 else U1.den_um1 end, nvl(cm.umsec,U1.CODUM1), U1.Paritate, CM.reziduu, CodProdMat,
      CM.Paritateechiv, CM.Tipechiv,
      CASE WHEN OP1.CODOP1 &gt; 0 THEN objOP.CodObiect ELSE OBJ.CODOBIECT END,
      CASE WHEN OP1.CODOP1 &gt; 0 THEN objop.Denumire ELSE OBJ.DENUMIRE END, cm.ccant, cm.cumsec,
      &apos;Material&apos;,
      cm.codcmdprodman,
       art.relatieum1, art.um1, cm.cantum1, 0,
       obj.codintern, obj.codintern, obj.codextern, obj.codextern, CM.CODCOMANDA3
     from CMDPRODMAT CM
          INNER JOIN NARTOBJ OBJ ON CM.CODOBIECT = OBJ.CODOBIECT
          INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
          INNER JOIN NUM1 U1 ON ART.UM = U1.CODUM AND U1.SECUNDARA = 0
          LEFT  JOIN NOPER1 OP1 ON OP1.CODOP1 = CM.CODPRODMAT
          LEFT  JOIN NARTOBJ OBJOP ON OBJOP.CODOBIECT = OP1.CODOBIECT
          left  join num1 u1sa on u1sa.codum1 = cm.umsec
     WHERE CM.CODCOMANDA3 in (select codcomanda3 from comanda3 where codcomanda = recid);

    -- aValoare preia restul de predat al produsului
    if atip = 53 then
      -- aValoare preia restul de predat al produsului
      for v_rec in (select * from tmp_comanda1) loop
        begin
          select nvl(Cmd.Rest,0) into aValoare from tmp_cmdprodmat cmd where cmd.tip = 0 and cmd.codcomanda1 = v_rec.codcomanda1;
        exception when others then aValoare := 0;
        end;
        -- daca este predata integral atunci necesarul si necesarini se pune 0
        UPDATE TMP_CMDPRODMAT C1
        SET
          NECESAR    = case when aValoare = 0 and pkg_categconst.GetValConstanta(&apos;PrelComInchise&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) &lt;&gt; 1 then 0 else NVL(REST, 0) - NVL(REZERVAT, 0) end,
          NECESARINI = case when aValoare = 0 and pkg_categconst.GetValConstanta(&apos;PrelComInchise&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) &lt;&gt; 1 then 0 else NVL(REST, 0) end
        where c1.codcomanda1 = v_Rec.Codcomanda1;
      end loop;
    end if;
  --ELSE
    if atip &lt;&gt; 8 then
    INSERT INTO  TMP_PROIECTNOD
       (  CODPROIECTNOD, Codproiect, CANT, NODORIGINAL, POZITIE, CODRETETA, TIP, CODOBIECT,
          NECESAR, CodGest, DenUM, CODPRODMAT,
          UMSec, TotalRezolvat, DENUMIRE
       )
       ( SELECT PN.CODPROIECTNOD, PN.Codproiect, PN.CANT, PN.NODORIGINAL, PN.POZITIE, PN.CODRETETA, PN.TIP,PN.CodObiect,
                nvl(C1.cantacceptat/PN0.CANT * PN.CANT, 0), retete.CodGest, NUM.Den_Um, PN.CODPRODMAT,
                NUM1.CodUM1, nvl(C1.cantacceptat/PN0.CANT * PN.CANT, 0), OBJ.Denumire
         FROM COMANDA1 C1
              INNER JOIN PROIECT P ON P.Codproiect = C1.CodProiect
              INNER JOIN PROIECTNOD PN ON PN.Codproiect = P.CODPROIECT
              INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND nvl(PN0.NODORIGINAL, 0) = 0
              INNER JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
              LEFT JOIN NART ON OBJ.CODARTICOL = NART.CodARTICOL
              LEFT JOIN NUM ON NART.Um = NUM.CODUM
              LEFT JOIN NUM1 ON NUM.CODUM = NUM1.CODUM and NVL(NUM1.SECUNDARA, 0) = 0
              LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
              LEFT  JOIN (select RET.CodProdComp, PG.CodGest
                          from prodcomp ret
                               left join prodgest pg on pg.codprodcomp = ret.codprodcomp and pg.indexlocal = 1
                          ) retete on PN.Codreteta = retete.codprodcomp
         WHERE C1.Codcomanda = RecId);


 -- end if;

  INSERT INTO TMP_NODECHIV (CODCOMANDA1, CODPROIECTNOD, CODOBIECT, PARITATE, TIP, D1, D2, D3, CodTip, CodObiectOrig, nodoriginal, cantum1)
    (SELECT n.CODCOMANDA1, n.CODPROIECTNOD, n.CODOBIECT, n.PARITATE, n.TIP, n.D1, n.D2, n.D3, 0, p.CodObiect, p.nodoriginal, n.cantum1
     FROM NODECHIV n
          left outer join proiectnod p on p.CODPROIECTNOD= n.CODPROIECTNOD
     WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
    );
  end if;

  INSERT INTO TMP_CMDLINK(CODCOMANDA1, CODLINIECOMANDA, CANT)
    (SELECT
     CODCOMANDA1, CODLINIECOMANDA, CANT
     FROM
     CMDLINK L
     WHERE
     L.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
    );
  UPDATE TMP_CMDLINK L
   SET
   DATACOMANDA =
   (SELECT  C.DATADOC
    FROM
    COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA),
   TERMEN =
   (SELECT C1.TERMEN
    FROM
    COMANDA1 C1 WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA)
   ;
  DELETE TMP_CMDLINK_INITIAL;
  INSERT INTO TMP_CMDLINK_INITIAL(CODCOMANDA1, CODLINIECOMANDA, CANT) (SELECT CODCOMANDA1, CODLINIECOMANDA, CANT FROM TMP_CMDLINK);

  INSERT INTO TMP_PRECMDLINK(CODCOMANDA1, CODPRECOMANDA1, CANT)
    (SELECT
     CODCOMANDA1, CODPRECOMANDA1, CANT
     FROM
     PRECMDLINK L
     WHERE
     L.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
    );
  DELETE TMP_PRECMDLINK_INITIAL;
  INSERT INTO TMP_PRECMDLINK_INITIAL(CODCOMANDA1, CODPRECOMANDA1, CANT) (SELECT CODCOMANDA1, CODPRECOMANDA1, CANT FROM TMP_PRECMDLINK);

  INSERT INTO TMP_PLANIFLINK(CODCOMANDA1, CODSTARE1)
    (SELECT
     CODCOMANDA1, CODSTARE1
     FROM
     PLANIFLINK L
     WHERE
     L.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
    );

  INSERT INTO TMP_CMDLIVRLINK(CODCOMANDA1, CODLINIECOMANDA, CANT)
    (SELECT
     CODCOMANDA1, CODLINIECOMANDA, CANT
     FROM
     CMDLIVRLINK L
     WHERE
     L.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
    );
  UPDATE TMP_CMDLIVRLINK L
   SET
   DATACOMANDA =
   (SELECT  C.DATADOC
    FROM
    COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA),
    TERMENCOMANDA =
   (SELECT C1.TERMEN
    FROM
    COMANDA1 C1 WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA)
   ;
  DELETE TMP_CMDLIVRLINK_INITIAL;
  INSERT INTO TMP_CMDLIVRLINK_INITIAL(CODCOMANDA1, CODLINIECOMANDA, CANT, TERMENCOMANDA) (SELECT CODCOMANDA1, CODLINIECOMANDA, CANT, TERMENCOMANDA FROM TMP_CMDLIVRLINK);

  DELETE TMP_PACHETEDLLINK;
  DELETE TMP_PACHETEDLLINK_INITIAL;
  INSERT INTO TMP_PACHETEDLLINK (CODCOMANDA1, CODPACHETEOBJ, CANT)
  SELECT CODCOMANDA1, CODPACHETEOBJ, CANT
  FROM PACHETEDLLINK
  WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1);
  INSERT INTO TMP_PACHETEDLLINK_INITIAL
  SELECT * FROM TMP_PACHETEDLLINK;

/*
-- pregatest pentru calcul solduri
  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, ANPREC, LUNAPREC);
  PKG_GLOBALS.SETLUNAPRECEDENTA(ANPREC, LUNAPREC);
  PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(aCODPART);
*/
-- PREIAU DIN TMP_GENERAL MONEDA SI CURSUL + ALTE CAMPURI ADAUGATE
  UPDATE TMP_COMANDA C
  SET
  /*
    SOLDPART  =
    CASE
      WHEN C.TIPDOC = 8 THEN NVL((SELECT -1 * SUM(SOLDLEI) FROM V_SOLDPART WHERE CODPART = C.PARTENER), 0)
      WHEN C.TIPDOC IN (18,57) THEN NVL((SELECT      SUM(SOLDLEI) FROM V_SOLDPART WHERE CODPART = C.PARTENER), 0)
      ELSE 0
    END,
*/
    COLDISCPART =
    CASE
      WHEN C.TIPDOC = 18 THEN NVL((SELECT COLDISCOUNT  FROM NPART WHERE CODPART = C.PARTENER), 0)
      ELSE 0
    END,

    DISCOUNTPART =
    CASE
      WHEN C.TIPDOC = 18 THEN NVL((SELECT DISCOUNT  FROM NPART WHERE CODPART = C.PARTENER), 0)
      ELSE 0
    END;

-- REZERVARI STOC

  INSERT INTO TMP_LIVR(CODLIVR, CODIES) VALUES (-1, RECID);

    INSERT INTO TMP_LIVR1
       ( CODLIVR1,
         CODLIVR,
         CODIES1,
         CODNIRSTOC,
         PRETINREG,
         PRETACHIZ,
         CANT,
         CANTREZERVAT,
         CODNIRSER,
         UMSEC,
         PARITATE,
         DENUM,
         CODIOART,
         CODOBIECT,
         CODLIVRTOT,
         GEST,
         CODLOCATIE --folosesc codlocatie pentru linia de comanda furnizor din rezervarea fictiva
       )
       ( SELECT
           L1.CODREZERVATS,
           -1,
           L1.CODCOMANDA1,
           L1.CODNIRSTOC,
           case
             when ns.codnirstoc &gt; 0 then
                NS.PRET * U1.PARITATE / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMoneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataDoc)
             else
                COALESCE(NS.PRET,CF1.PU) * U1.PARITATE *
                PKG_LIST_BASE_UTILS.GETCURSREFERINTA(CF.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),CF.DATADOC)
                / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMoneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataDoc)
           end,
           case
             when ns.codnirstoc &gt; 0 then
                (NS.PRET - COALESCE(NS.ADAOS,0)) * U1.PARITATE / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMoneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataDoc)
             else
                COALESCE(NS.PRET,CF1.PU) * U1.PARITATE *
                PKG_LIST_BASE_UTILS.GETCURSREFERINTA(CF.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),CF.DATADOC)
                / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMoneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataDoc)
           end,
           L1.REST / U1.PARITATE,
           L1.REST / U1.PARITATE,
           L1.CODNIRSER,
           L1.UMSEC,
           U1.PARITATE,
           U1.DEN_UM1,
           NS.CODIOART,
           COALESCE(NS.CODOBIECT,C1.CODOBIECT),
           0,
           N.GEST,
           CASE WHEN NVL(L1.CODNIRSTOC,0) = 0 THEN L1.CODCOMANDA1F END
         FROM
           REZERVATS L1
           INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L1.CODCOMANDA1
           LEFT JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = L1.CODCOMANDA1F
           LEFT JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
           LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC AND NS.CODOBIECT = C1.CODOBIECT
           LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR,
           NUM1 U1
         WHERE
           NVL(CODCMDPRODMAT, 0) = 0
           AND EXISTS (SELECT CODCOMANDA1 FROM TMP_COMANDA1 WHERE CODCOMANDA1 = L1.CODCOMANDA1 and nvl(Codproiect,0) = 0)
           AND U1.CODUM1 = L1.UMSEC AND NOT (L1.REST = 0 AND L1.CODCOMANDA1F &gt; 0)
       );

  DELETE TMP_LIVRTOT;
  INSERT INTO TMP_LIVRTOT (
    CODLIVRTOT,
    CODLIVR,
    CODIESINT1,
    UMSEC,
    GEST,
    CODIOART,
    CODOBIECT,
    DENUM,
    PARITATE,
    DENGESTIOART,
    DIFPRET,
    ACCIZELATRANSFER,
    ARETVANEEX,
    MG,
    CONT,
    SUFIXTVANEEX,
    STOCREZOLVAT,
    CANT,
    PRETINREG,
    PRETACHIZ,
    CODCOMAND1ORIG
  )
  SELECT
    0,
    L1.CODLIVR,
    L1.CODIES1,
    L1.UMSEC,
    L1.GEST,
    L1.CODIOART,
    L1.CODOBIECT,
    L1.DENUM,
    L1.PARITATE,
    CASE WHEN COALESCE(L1.CODLOCATIE,0) = 0 THEN G.DEN_GEST||CHR(13)||IO.DEN_IOART ELSE C.PREFIXDOC||C.NRDOC||&apos;/&apos;||TO_CHAR(C.DATADOC,&apos;DD.MM.YYYY&apos;) END,
    IOALUNA.DIFPRET,
    IOALUNA.ACCIZELATRANSFER,
    IOALUNA.ARETVANEEX,
    IOALUNA.MG,
    IOALUNA.CONT,
    IOALUNA.TVANEEX,
    1,
    SUM(L1.CANTREZERVAT),
    SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    Coalesce(L1.CODLOCATIE,0)
  FROM TMP_LIVR1 L1
    LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.AnLunaLucru BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
    LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
    LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
    LEFT JOIN COMANDA1 C1 ON L1.CODLOCATIE = C1.CODCOMANDA1
    LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  GROUP BY
    0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC,
    L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE , G.DEN_GEST, IO.DEN_IOART, IOALUNA.DIFPRET,  IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG,
    IOALUNA.CONT,IOALUNA.TVANEEX,C.PREFIXDOC,C.NRDOC,C.DATADOC,Coalesce(L1.CODLOCATIE,0);

   IF RECID &gt; 0 THEN
     UPDATE TMP_LIVRTOT T
     SET
       CODLIVRTOT      = ROWNUM,
       CODLINIECOMANDA = CODIESINT1,
       ARETG           = (SELECT ARETG FROM NART A, NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT AND A.CODARTICOL = O.CODARTICOL),
       DENOBIECT       = (SELECT DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT), --PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
       INDEXMASTER     = (SELECT INDEXLOCAL FROM TMP_COMANDA1 WHERE CODCOMANDA1 = T.CODIESINT1),
       (UM1, UM2, RELATIEUM1, TIPSERIE)      = (SELECT UM1, UM2, RELATIEUM1, TIPSERIE FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
       PROCTVA         = PKG_SELECTARTICOLE.GETPROCENTTVA
                        (PKG_SELECTARTICOLE.GETArtOfObject(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);


  -- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
     UPDATE TMP_LIVR1 L1
     SET
       CODLIVRTOT = ( SELECT CODLIVRTOT FROM TMP_LIVRTOT
                      WHERE
                        NVL(CODLIVR,    0)   = NVL(L1.CODLIVR,  0) AND
                        NVL(CODIESINT1, 0)   = NVL(L1.CODIES1,  0) AND
                        NVL(UMSEC,      0)   = NVL(L1.UMSEC,    0) AND
                        NVL(PARITATE,   0)   = NVL(L1.PARITATE, 0) AND
                        NVL(GEST,       0)   = NVL(L1.GEST,     0) AND
                        NVL(CODIOART,   0)   = NVL(L1.CODIOART, 0) AND
                        NVL(CODCOMAND1ORIG,0) = NVL(L1.CODLOCATIE,0)
                    )
       ;
   END IF;

   UPDATE TMP_LIVR1 L1
   SET
     CODLINIECOMANDA = (SELECT CODLINIECOMANDA FROM TMP_LIVRTOT WHERE CODLIVRTOT = L1.CODLIVRTOT),
     TG              = (SELECT NVL(NSE.TG, NS.TG)
                        FROM
                          REZERVATS LL1
                          LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSER = LL1.CODNIRSER,
                          NIRSTOC NS
                        WHERE
                         LL1.CODREZERVATS = L1.CODLIVR1
                         AND NS.CODNIRSTOC = LL1.CODNIRSTOC
                        );



  DELETE TMP_LIVR1_INITIAL;
  INSERT INTO TMP_LIVR1_INITIAL SELECT * FROM TMP_LIVR1;



-- REZERVARI STOC MATERIALE

--  INSERT INTO TMP_LIVR_MAT(CODLIVR, CODIES) VALUES (-1, RECID);

  if aTip = 53 then
-- DETAIL LIVR1MAT
  INSERT INTO TMP_LIVR1_MAT
     ( CODLIVR1,
       CODLIVR,
       CODIES1,
       CODNIRSTOC,
       CANT,
       CANTREZERVAT,
       CODNIRSER,
       UMSEC,
       PARITATE,
       DENUM,
       CODIOART,
       CODOBIECT,
       CODLIVRTOT,
       GEST,
       CODLINIECOMANDA,
       CODCMDPRODMAT,
       CODLOCATIE
      )
     ( SELECT
         L1.CODREZERVATS,
--         -1,
         L1.CODCOMANDA1,
         L1.CODCMDPRODMAT,
         L1.CODNIRSTOC,
         L1.REST / U1.PARITATE,
         L1.REST / U1.PARITATE,
--         L1.REST / U1.PARITATE,
--         L1.REST / U1.PARITATE,
         L1.CODNIRSER,
         L1.UMSEC,
         U1.PARITATE,
         U1.DEN_UM1,
         NS.CODIOART,
         COALESCE(NS.CODOBIECT,L1.CODOBIECT),
         0,
         N.GEST,
         L1.CODCOMANDA1,
         L1.CODCMDPRODMAT,
         CASE WHEN NVL(L1.CODNIRSTOC,0) = 0 THEN L1.CODCOMANDA1F END
       FROM
         REZERVATS L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR,
         NUM1 U1
       WHERE
         NVL(CODCMDPRODMAT, 0) &lt;&gt; 0
         AND EXISTS (SELECT CODCMDPRODMAT FROM TMP_CMDPRODMAT WHERE CODCMDPRODMAT = L1.CODCMDPRODMAT)
         AND U1.CODUM1 = L1.UMSEC AND NOT (L1.REST = 0 AND L1.CODCOMANDA1F &gt; 0)
     );

  INSERT INTO TMP_LIVR_MAT(CODLIVR, CODIES) (SELECT DISTINCT CODLIVR, RECID FROM TMP_LIVR1_MAT);

  DELETE TMP_LIVRTOT_MAT;
  INSERT INTO TMP_LIVRTOT_MAT (
    CODLIVRTOT,
    CODLIVR,
    CODIESINT1,
    UMSEC,
    GEST,
    CODIOART,
    CODOBIECT,
    DENUM,
    PARITATE,
    CODLINIECOMANDA,
    DENGESTIOART,
    DIFPRET,
    ACCIZELATRANSFER,
    ARETVANEEX,
    MG,
    CONT,
    SUFIXTVANEEX,
    STOCREZOLVAT,
    CANT
  )
  SELECT
    0,
    L1.CODLIVR,
    L1.CODIES1,
    L1.UMSEC,
    L1.GEST,
    L1.CODIOART,
    L1.CODOBIECT,
    L1.DENUM,
    L1.PARITATE,
    L1.CODLINIECOMANDA,
    CASE WHEN nvl(L1.CODLOCATIE,0) = 0 THEN G.DEN_GEST||CHR(13)||IO.DEN_IOART ELSE C.PREFIXDOC||C.NRDOC||&apos;/&apos;||TO_CHAR(C.DATADOC,&apos;DD.MM.YYYY&apos;) END,
    IOALUNA.DIFPRET,
    IOALUNA.ACCIZELATRANSFER,
    IOALUNA.ARETVANEEX,
    IOALUNA.MG,
    IOALUNA.CONT,
    IOALUNA.TVANEEX,
    1,
    SUM(L1.CANTREZERVAT)
  FROM TMP_LIVR1_MAT L1
    LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.AnLunaLucru BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
    LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
    LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
    LEFT JOIN COMANDA1 C1 ON L1.CODLOCATIE = C1.CODCOMANDA1
    LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  GROUP BY
    0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC,
    L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE ,
    L1.CODLINIECOMANDA,
    G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET,  IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG,
    IOALUNA.CONT, IOALUNA.TVANEEX, L1.CODLOCATIE, C.PREFIXDOC, C.NRDOC, C.DATADOC;

   IF RECID &gt; 0 THEN
     UPDATE TMP_LIVRTOT_MAT T
     SET
       CODLIVRTOT      = ROWNUM,
       CODCMDPRODMAT   = CODIESINT1,
       DENOBIECT       = (SELECT DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT), --PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
       INDEXMASTER     = (SELECT INDEXLOCAL FROM TMP_IESIRI1 WHERE CODIES1 = T.CODIESINT1),
       (UM1, UM2, RELATIEUM1, TIPSERIE)      = (SELECT UM1, UM2, RELATIEUM1, TIPSERIE FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
       PROCTVA         = PKG_SELECTARTICOLE.GETPROCENTTVA
                        (PKG_SELECTARTICOLE.GETArtOfObject(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

     UPDATE TMP_LIVRTOT_MAT T
     SET
       CODCOMAND1LNK = (SELECT C1.CODCOMANDA1
                        FROM COMANDA1 C1
                             INNER JOIN CMDLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
                             INNER JOIN CMDPRODMAT P ON L.CODCOMANDA1 = P.CODCOMANDA1
                        WHERE P.CODCMDPRODMAT = T.CODCMDPRODMAT)
     WHERE EXISTS (SELECT C1.CODCOMANDA1
                   FROM COMANDA1 C1
                        INNER JOIN CMDLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
                        INNER JOIN CMDPRODMAT P ON L.CODCOMANDA1 = P.CODCOMANDA1
                   WHERE P.CODCMDPRODMAT = T.CODCMDPRODMAT);

  -- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
     UPDATE TMP_LIVR1_MAT L1
     SET
       CODLIVRTOT = ( SELECT CODLIVRTOT FROM TMP_LIVRTOT_MAT
                      WHERE
                        NVL(CODLIVR,    0)   = NVL(L1.CODLIVR,  0) AND
                        NVL(CODIESINT1, 0)   = NVL(L1.CODIES1,  0) AND
                        NVL(UMSEC,      0)   = NVL(L1.UMSEC,    0) AND
                        NVL(PARITATE,   0)   = NVL(L1.PARITATE, 0) AND
                        NVL(GEST,       0)   = NVL(L1.GEST,     0) AND
                        NVL(CODIOART,   0)   = NVL(L1.CODIOART, 0)
                    )
       ;
   END IF;


  DELETE TMP_LIVR1_MAT_INITIAL;
  INSERT INTO TMP_LIVR1_MAT_INITIAL SELECT * FROM TMP_LIVR1_MAT;
  --update TMP_LIVR1_MAT_INITIAL set cant = 0;
  UPDATE TMP_LIVRTOT_MAT LT
  SET
   (UM1, UM2, RELATIEUM1, TIPSERIE) = (SELECT UM1, UM2, RELATIEUM1, TIPSERIE FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(LT.CODOBIECT)),
   (D1, D2, D3) = (SELECT D1, D2, D3 FROM TMP_CMDPRODMAT WHERE CODCMDPRODMAT = LT.CODCMDPRODMAT);

  end if;
  UPDATE TMP_LIVRTOT LT
  SET
   (UM1, UM2, RELATIEUM1) = (SELECT UM1, UM2, RELATIEUM1 FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(LT.CODOBIECT)),
   (D1, D2, D3) = (SELECT D1, D2, D3 FROM TMP_COMANDA1 WHERE CODCOMANDA1 = LT.CODIESINT1);

    UPDATE TMP_COMANDA1 C1
    SET
      NRDOCLINK =
         (SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)||&apos;,&apos;||LPAD(CC1.IndexLocal, 3, &apos;0&apos;)
          FROM
           CMDLIVRLINK IL
           LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = IL.CODLINIECOMANDA
           LEFT OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
          WHERE
          IL.CODCOMANDA1 = C1.CODCOMANDA1
          )
    WHERE
      C1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);

    --am pus dupa ca sa nu-mi strice nrdoclinkul in cazul comenzilor de productie
    IF aTip in (53, 44) THEN -- LINII CE STING COMENZI
      UPDATE TMP_COMANDA1 C1
      SET
        NRDOCLINK =
           (SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)||&apos;,&apos;||LPAD(CC1.IndexLocal, 3, &apos;0&apos;)
            FROM
             CMDLINK IL
             LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = IL.CODLINIECOMANDA
             LEFT OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
            WHERE
            IL.CODCOMANDA1 = C1.CODCOMANDA1
            )
      WHERE
        C1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
    END IF;


  INSERT INTO TMP_TERMENECMD(CODTERMEN, CODCOMANDA, ZILE, PROCENT, TIPPLATA)
  SELECT   CODTERMEN, CODCOMANDA, ZILE, PROCENT, TIPPLATA FROM TERMENECMD WHERE CODCOMANDA = RECID
  ORDER BY ZILE;


  INSERT INTO TMP_CMDAPROBARI
  SELECT * FROM CMDAPROBARI WHERE CODDOC = RECID AND TIPDOC = TIPCOMANDA;

  BEGIN
    SELECT VALOARE INTO aVALOARE FROM TMP_COMANDA;
  EXCEPTION WHEN OTHERS THEN aValoare := 0;
  END;

  IF NVL(aVALOARE, 0) &lt;&gt; 0 THEN
    UPDATE TMP_TERMENECMD
    SET
     VALOARE = aVALOARE * PROCENT / 100;
  END IF;


   UPDATE TMP_LIVR1 L1
   SET
    SERIE = (SELECT S.SERIE FROM NIRSER NS, NSERII S WHERE NS.CODNIRSTOC = L1.CODNIRSTOC AND NS.CODNIRSER = L1.CODNIRSER AND S.CODSERIE = NS.CODSERIE);


  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
  END;

  IF TIPPREFIX = &apos;2&apos; THEN
    UPDATE TMP_COMANDA1 I1
    SET
      DENOBIECT = NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT
    WHERE
      I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
  ELSE
  IF TIPPREFIX = &apos;3&apos; THEN
    UPDATE TMP_COMANDA1 I1
    SET
      DENOBIECT = NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT
    WHERE
      I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
  ELSE
  IF TIPPREFIX = &apos;4&apos; THEN
    UPDATE TMP_COMANDA1 I1
    SET
      DENOBIECT = NVL((SELECT A.CODEXTERNART || A.SUFIXCODEXTERN FROM NART A, NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT AND A.CODARTICOL = O.CODARTICOL), &apos;&apos;) || &apos;;&apos; || DENOBIECT
    WHERE
      I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
  END IF;
  END IF;
  END IF;


   IF TIPPREFIX &lt;&gt; &apos;1&apos; THEN
     UPDATE TMP_LIVRTOT L1
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_COMANDA1 I1 WHERE I1.CODCOMANDA1 = L1.CODIESINT1);
   END IF;

  IF aTIP in (18,94) THEN
    UPDATE TMP_COMANDA C
    SET
     VALOAREAVANS =
     (
       SELECT SUM(O.REST) AS VALOARE
/* ?
        CASE
          WHEN G.SEMNIFICATIE = 210 THEN O.VALOARE
          ELSE -O.VALOARE
        END
       ) AS VALOARE
*/
       FROM
         IESIRI I,
         GENERAL G,
         OBLIGPIF O
       WHERE
         ((I.CODIES = C.CODIESAVANS)OR(EXISTS (SELECT CA.CODIESAVANS FROM CMDAVANS CA WHERE CA.CODIESAVANS = I.CODIES AND CA.CODCOMANDA = RECID)))
         AND G.CODDOC = I.CODIES
         AND G.TIPDOC = I.TIPDOC
         AND G.SEMNIFICATIE IN (210/*, 211 ? */)
         AND O.CODGENERAL = G.CODGENERAL
     );
  END IF;



 /* IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDC&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDC SELECT * FROM COMANDC WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDL&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDL SELECT * FROM COMANDL WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDC1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDC1 SELECT * FROM COMANDC1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDL1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDL1 SELECT * FROM COMANDL1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1) &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDRAC&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDRAC SELECT * FROM COMANDRAC WHERE CODCOMANDA = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDRAC1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDRAC1 SELECT * FROM COMANDRAC1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDI1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_COMANDI1 SELECT * FROM COMANDI1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1) &apos;;
  END IF;*/

   DELETE TMP_COMANDA1_INITIAL;
   INSERT INTO TMP_COMANDA1_INITIAL (CODCOMANDA1, CODCONTRACT1, CANTACCEPTAT, RESTACCEPTAT, PARITATE)
   SELECT CODCOMANDA1, CODCONTRACT1, CANTACCEPTAT, RESTACCEPTAT, PARITATE
   FROM
     TMP_COMANDA1;



  INSERT INTO TMP_STORNOCMDF
  SELECT * FROM STORNOCMDF WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1);

  DELETE TMP_STORNOCMDF_INI;
  INSERT INTO TMP_STORNOCMDF_INI  SELECT * FROM TMP_STORNOCMDF;

  UPDATE TMP_COMANDA1
  SET
    PUREAL =  NVL(PRETORIG, 0) * DECODE(NVL(COEFDISCMAJ, 1), 0, 1, NVL(COEFDISCMAJ, 1))
  WHERE
    TIPLINIE IN (&apos;=&apos;, &apos;S&apos;);


  IF aTIP = 18 THEN
    UPDATE TMP_COMANDA C
    SET
      SCADENTESETATEMANUAL = 1,
      GESTLIVRARESEDIU = (SELECT GESTLIVRARE FROM NAGENDA A WHERE A.CODAGENDA = C.CODLOCATIE);
  END IF;

  IF aTIP = 92 THEN
    UPDATE TMP_COMANDA1 CC1
    SET CC1.RESTLANSAT =
     (select Sum(Nvl(R.Deja,0) - Nvl(RR.Retur,0))
      from  Comanda1 C1
      left join ( select t1.CodComanda1, Sum(L1.Cant) Retur from  Transf1 t1
                  inner join Comanda1 C1 on C1.Codcomanda1 = t1.CodComanda1 and C1.CodComanda = RecID
                  inner join Livr L on L.CodTransf = t1.codtransf
                  inner join Livr1 L1 on L1.CodLivr = L.CodLivr and L1.CodIes1 = t1.codTransf1
                  inner join NIRSTOC ns on ns.CodNirStoc = L1.CodNirStoc
                  inner join NIR n on n.CodNIR = ns.codNIR and n.gest = aCodGest
                  group by t1.CodComanda1) RR on RR.CodComanda1 = C1.CodComanda1
      left join ( select t1.CodComanda1, Sum(ns.CantFurn) Deja from  Transf1 t1
                  inner join Comanda1 C1 on C1.Codcomanda1 = t1.CodComanda1 and C1.CodComanda = RecID
                  inner join NIRSTOC ns on ns.CodTransf1 = t1.codtransf1
                  inner join NIR n on n.CodNIR = ns.codNIR and n.gest = aCodGest
                  group by t1.CodComanda1) R on R.CodComanda1 = C1.CodComanda1
    where C1.CodComanda1 = CC1.CodComanda1
    Group by C1.CodComanda1);
    UPDATE TMP_COMANDA1 C1
    SET RESTCMD = NVL((Select Sum(Nvl(e1.Cant,0)) from Emulare1 e1
                                 inner join Emulare e on e.CodEmulare = e1.CodEmulare
                                 where Nvl(e.CODMONETAR,0) = 0 and e1.Codcomanda1 = C1.codcomanda1),0);
  END IF;
  IF aTIP = 94 THEN
    UPDATE TMP_COMANDA1 C1
    SET RESTLANSAT = NVL((
                          Select Sum(Nvl(e1.Cant,0)) from Emulare1 e1
                          inner join Emulare e on e.CodEmulare = e1.CodEmulare
                          left  join IesLink k on k.Codliniecomanda = e1.codcomanda1
                          where (Nvl(k.Codliniecomanda,0) = 0) and e1.Codcomanda1 = C1.codcomanda1
                         ),0);
    for v_1 in (Select CodComanda1, CodObiect from TMP_Comanda1) loop
        begin
          Select Nvl(Ind,0), CodGrupa into aInd, aCodGrupa from NEchiv where CodObiect = v_1.codobiect;
        EXCEPTION
          WHEN OTHERS THEN aInd := 0;
        END;
        update TMP_Comanda1 set ProdusPropriu = aInd, Lansari = aCodGrupa where CodComanda1 = v_1.CodComanda1;
    end loop;

    Insert into TMP_VOUCHERLINK
    (CodVLink, codvoucher, CodCmd, CodIes, valoare)
    (SELECT CodVLink, codvoucher, CodCmd, Null, valoare from VOUCHERLINK WHERE Nvl(CODCmd,0) IN (SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID));

    INSERT INTO  TMP_RAC_REZ
    (   CODRAC_REZ      ,
        CodComanda      ,
        TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        NumeDelegat1, NumeDelegat2,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, Diferente, ValV, codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        CODCCV          ,
        OBS_Contract    ,
        CodTIPASIG      ,
        Email           ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        RestClient      ,
        RestSofer       ,
        CodSofer, CodSofer1, CodSofer2, SursaClient,
        FaraTVA,
        Telefon         ,
        Zile            ,
        Ore
      )

    SELECT
        CODRAC_REZ      ,
        R.CodComanda      ,
        TipRezervare, R.DataStart, R.DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        D1.DELEGAT, D2.DELEGAT,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat,
        R.CodVoucher,
        0,
        V.Valoare,
        codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        (Select Count(*) from Rac_REZ where CodREZERVARE = RecID and CodComanda &gt; 0),
        OBS_Contract    ,
        CodTIPASIG      ,
        R.Email         ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        Round(X.RestClient,2)    ,
        Round(X.RestSofer,2)     ,
        CodSofer, CodSofer1, CodSofer2, SursaClient,
        R.FaraTVA,
        R.Telefon         ,
        Trunc(R.DataStop-R.DataStart) +
        Case when Round(24*(Round(R.DataStop-R.DataStart,5) - Trunc(R.DataStop-R.DataStart)),0) = 24 then 1 else 0 end,
        Case when Round(24*(Round(R.DataStop-R.DataStart,5) - Trunc(R.DataStop-R.DataStart)),0) = 24 then 0
        else Round(24*(Round(R.DataStop-R.DataStart,5) - Trunc(R.DataStop-R.DataStart)),0) end
    FROM RAC_REZ R
         left join NPARTTR D1 on R.CodDelegat1 = D1.Codparttr
         left join NPARTTR D2 on R.CodDelegat2 = D2.Codparttr
         left join Voucher V on V.Codvoucher = Nvl(R.CodVoucher,0)
         left join
         ( --rest de incasat
          select CodComanda,
                   Sum(Nvl(TotalClient,0)- Nvl(IncasClient,0)) RestClient,
                   Sum(Nvl(TotalSofer ,0)- Nvl(IncasSofer ,0)) RestSofer
          from(
          select CodComanda,
          Case When Cineplateste &lt;&gt;2 then Sum(Valoare) else 0 end IncasClient,
          Case When Cineplateste = 2 then Sum(Valoare) else 0 end IncasSofer,
          0 TotalClient, 0 TotalSofer
          from
          (
              select CodComanda, CinePlateste, Sum(PKG_LIST_BASE_UTILS.getStinsIes(Nvl(codies,0),CodComanda)/CursDoc) Valoare
              from
              (
              SELECT
                distinct C.CodComanda, E.CodIes, nvl(c1.Culansare,1) CinePlateste, case when coalesce(E.CursDoc,0) = 0 then 1 else e.cursdoc end CursDoc
              FROM comanda c
                  inner JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
                  LEFT  JOIN ieslink l ON l.codliniecomanda = c1.codcomanda1 AND Nvl(l.codies1,0) &lt;&gt; 0
                  LEFT  JOIN iesiri1 e1 ON e1.codies1 = l.codies1
                  LEFT  JOIN iesiri e ON e.codies = e1.codies and e.TipDoc &lt;&gt; 16
              ) group by CodComanda, CinePlateste
              union all
              select CodComanda, CinePlateste, Sum(PKG_LIST_BASE_UTILS.getStinsIes(Nvl(codies,0),CodComanda)/CursDoc) Valoare
              from
              (
              SELECT
                distinct C.CodComanda, E.CodIes, nvl(c1.Culansare,1) CinePlateste, case when coalesce(C.Curs,0) = 0 then 1 else c.curs end CursDoc
              FROM comanda c
                  inner JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
                  LEFT  JOIN ieslink l ON l.codliniecomanda = c1.codcomanda1 AND Nvl(l.codies1,0) &lt;&gt; 0
                  LEFT  JOIN iesiri1 e1 ON e1.codies1 = l.codies1
                  LEFT  JOIN iesiri e ON e.codies = e1.codies and e.TipDoc = 16
              ) group by CodComanda, CinePlateste
              union all
               Select C.CODCOMANDA, nvl(c1.Culansare,1) CinePlateste, Sum(e1.Cant*e1.Pret/case when coalesce(C.Curs,0) = 0 then 1 else c.curs end) Valoare
               from Emulare1 e1
               inner join Emulare e on e.CodEmulare = e1.CodEmulare
               inner join Comanda1 C1 on C1.Codcomanda1 = nvl(e1.codcomanda1,0)
               inner join Comanda C on C.Codcomanda = nvl(c1.codcomanda,0)
                     where Nvl(e.CODMONETAR,0) = 0 group by C.CodComanda, nvl(c1.Culansare,1)) group by CodComanda, CinePlateste
          union all
            SELECT   CodComanda, 0 IncasClient,  0 IncasSofer,
            valClientF + valClientcm  TotalClient, valsoferF + valsofercm TotalSofer
            FROM Rac_Rez) group by CodComanda
          ) X on X.CodComanda = R.CodComanda
    WHERE R.CodComanda = RECID;
  end if;

  IF (aTIP = 94)or((aTIP = 92) and pkg_globals.Directiva(&apos;_WMSA_&apos;)) THEN
    UPDATE TMP_COMANDA SET SCADENTESETATEMANUAL = 1;
    begin
       Select FaraTVA into aFaraTVA from Tmp_Rac_Rez;
      exception when others then aFaraTVA := 0;
     end;
     if aFaraTVA = 1 then
       Update TMP_Comanda1 set TVA = 0;
     end if;
     update TMP_COMANDA set ValTVA = Round((Select Sum(Nvl(TVA,0)*(1+Nvl(ProcDisc,0)/100)) from tmp_Comanda1),2);
     update TMP_COMANDA set DiscTVA = ValDiscount*ValTVA/Valoare where Nvl(Valoare,0) &lt;&gt; 0;
     update TMP_COMANDA set Valoare = Valoare + ValTVA, ValDiscount = ValDiscount + DiscTVA;
     select Valoare into aVALOARE from TMP_Comanda;
     UPDATE TMP_TERMENECMD SET VALOARE = aVALOARE * PROCENT / 100;
  end if;

 --Detail NPARCCOM
  IF aTIP in (92,94) THEN
      INSERT INTO  Tmp_NParcSA ( codnparccom, codcomanda, codnparcaut, Obs, kmbord,TipComSa,CategPret,
                                  DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari, tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep, DataAutRep,
                                  ParcPropriu, Inmatriculare, SerieAuto, Marca, Model, Culoare, Energie, DataFabr, NrOre, TipVehicul, KmBordE,
                                  Idrar, Anulatrar, Finalizatrar )
      SELECT PC.codnparccom, PC.codcomanda, PC.CodNParcAut, PC.Obs, PC.KMBord, PC.TipComSA, Coalesce(PC.CategPret,0),
             PC.DataInchiderii, PC.InmatrRom, PC.Inspectie, PC.PieseClient, PC.ProbaDrum, PC.Spalare, PC.DZ, PC.NivRezervor,
             PC.kmgarantie, PC.datagarantie, PC.Recomandari, PC.tipcomanda, PC.Asigurator, PC.Distanta, PC.AdresaSediu, PC.NrDosarDaune,
             PC.NrAutRep, PC.DataAutRep,
             A.Extern, A.Datainreg, A.Seriec , M.Marca, MD.Model, A.CuloareC, A.Sursae, A.Anf, PC.NrOre,NVL(A.Tipvehicul,0),
             PC.Kmborde, PC.IDRAR, PC.anulatrar, pc.finalizatrar
      FROM NPARCCOM PC
        LEFT JOIN NPARCAUT A on A.CODNPARCAUT = PC.CODNPARCAUT
        LEFT JOIN NMARCIAUTO M ON M.CODMARCIAUTO = A.MARCA
        LEFT JOIN NMODELEAUTO MD ON MD.CODMODELEAUTO = A.MODEL
      WHERE PC.CodComanda = RecId;

      INSERT INTO  TMP_COMANDA2 ( CODCOMANDA2,CODCOMANDA,CODLUCRARE,CODINTERVENTIE, OBS,CODPART,GARANTIE,CODLOCATIE,CODREZERVARE, ORE)
      SELECT CODCOMANDA2,CODCOMANDA,CODLUCRARE,CODINTERVENTIE, OBS,CODPART,GARANTIE,CODLOCATIE,CODREZERVARE, ORE FROM COMANDA2
      WHERE (CodComanda = RecId)or(CodRezervare = RecId) ;

      INSERT INTO  TMP_COMANDA3 ( CODCOMANDA3,CODCOMANDA2,CODCOMANDA1,CODCOMANDA,DURATA,CategPret,
                                  DURATAH,
                                  VALOARE,TARIF,DataStart,CODOPERATIE,CANT,PRET,OBS,TIP,EXECUTAT, CodRezervare,DATA,
																	TARIF0,TARIF1,TARIF2,TARIF3,TARIF4,TARIF5,TARIF6,TARIF7,TARIF8,TARIF9,
                                  CodIntr1_1, CodIntr1_2, CodIntr1_3, DocIntr_1, DocIntr_2, DocIntr_3, CodServ, CodLoc, Codprestatie)
      SELECT                      CODCOMANDA3,CODCOMANDA2,CODCOMANDA1,CODCOMANDA,C3.DURATA,Coalesce(C3.CategPret,0),
                                  Trunc(C3.DURATA/60) + (C3.DURATA - 60*Trunc(C3.DURATA/60))/60,
                                  VALOARE,C3.TARIF,DataStart,CODOPERATIE,CANT,PRET,OBS,C3.TIP,EXECUTAT, CodRezervare,DATA,
																	M.TARIF,M.TARIF1,M.TARIF2,M.TARIF3,M.TARIF4,M.TARIF5,M.TARIF6,M.TARIF7,M.TARIF8,M.TARIF9,
                                  CodIntr1_1, CodIntr1_2, CodIntr1_3,
                                  (select i1_1.prefixdoc||&apos; &apos;||i1_1.SeriaDoc||i1_1.NrDoc||&apos;/&apos;||i1_1.datadoc
                                   from intrari1 i1
                                   inner join intrari i1_1 on i1_1.codintr=i1.codintr
                                   where i1.codintr1 = CodIntr1_1)  DocIntr_1,
                                  (select i1_2.prefixdoc||&apos; &apos;||i1_2.SeriaDoc||i1_2.NrDoc||&apos;/&apos;||i1_2.datadoc
                                   from intrari1 i1
                                   inner join intrari i1_2 on i1_2.codintr=i1.codintr
                                   where i1.codintr1 = CodIntr1_2)  DocIntr_2,
                                  (select i1_3.prefixdoc||&apos; &apos;||i1_3.SeriaDoc||i1_3.NrDoc||&apos;/&apos;||i1_3.datadoc
                                   from intrari1 i1
                                   inner join intrari i1_3 on i1_3.codintr=i1.codintr
                                   where i1.codintr1 = CodIntr1_3) DocIntr_3,Op.CODSERVICIU, op.LOCMUNCA, c3.codprestatie
      FROM COMANDA3 C3
           left join NOper Op on Op.Codop = C3.CODOPERATIE
           left join Tarifeman1 M on M.CodTarif = Op.Codtarif and PKG_GLOBALS.ANLUCRU*12+PKG_GLOBALS.LUNALUCRU BETWEEN M.ALStart AND M.ALStop
      WHERE (CodComanda = RecId)or(CodRezervare = RecId) ;

      UPDATE TMP_COMANDA2 T2 SET VALOARE = (SELECT SUM(round(T3.VALOARE,2)) FROM TMP_COMANDA3 T3 WHERE T3.CODCOMANDA2 = T2.CODCOMANDA2);

      INSERT INTO  TMP_AVARIECAROSERIE ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
      SELECT CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y FROM AVARIECAROSERIE
      WHERE CodComanda = RecId and Nvl(Cand,1) &lt;&gt; 2;
      INSERT INTO  TMP_AVARIECAROSERIE1 ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
      SELECT CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y FROM AVARIECAROSERIE
      WHERE CodComanda = RecId and Nvl(Cand,1) = 2;

      insert into TMP_Comanda4
      ( Codcomanda4 ,
        Codcomanda3 ,
        Codcomanda2 ,
        Codpers     ,
        datastart   ,
        datastop    ,
        obs         ,
        codcomanda  ,
        eliberat, Ore    ,
        Nume)
      Select
        Codcomanda4 ,
        Codcomanda3 ,
        Codcomanda2 ,
        c4.CodPers  ,
        datastart   ,
        datastop    ,
        C4.obs      ,
        codcomanda  ,
        eliberat, Ore    ,
        p.Nume||&apos; &apos;||p.Prenume
      from Comanda4 c4
      left join NPers p on P.CodPers = C4.CodPers
      where CodComanda = RECID;
  end if;

  IF aDISPLIVRARE = 1 THEN
    FOR V_REC IN (SELECT LT.CODLIVRTOT, CL.CODLINIECOMANDA
                  FROM
                    TMP_LIVRTOT LT,
                    TMP_CMDLIVRLINK CL
                  WHERE
                    LT.CODIESINT1 = CL.CODCOMANDA1
                 )
    LOOP
      UPDATE TMP_LIVRTOT
      SET
        CODCOMAND1LNK = V_REC.CODLINIECOMANDA
      WHERE
        CODLIVRTOT = V_REC.CODLIVRTOT;
    END LOOP;

  END IF;

  if atip = 18 and aDispLivrare = 1 then
    aTipPtExt := 103;
  else
    aTipPtExt := aTip;
  end if;


  FOR V_REC IN
  (SELECT C1.CODCOMANDA1
    FROM
      TMP_COMANDA1 C1
      INNER JOIN  ( SELECT
                     DISTINCT CV.VALOARE
                   FROM
                      CONST1 C1
                      INNER JOIN
                      (SELECT CODCONST1, CODCONSTLUNA
                        FROM
                          CONSTLUNA WHERE
                          ALSTART &lt;= AnLunaLucru  AND ALSTOP &gt;= AnLunaLucru
                       ) CL   ON C1.CODCONST1 = CL.CODCONST1
                       INNER JOIN CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
                      WHERE
                        UPPER(SIMBOL) = &apos;ARTVOUCHERCADOU&apos;
                  ) VOUCHER ON VOUCHER.VALOARE = TO_CHAR(C1.CODOBIECT)
    )
    LOOP
      UPDATE TMP_COMANDA1
      SET
        VOUCHERCADOU = 1
      WHERE
        CODCOMANDA1 = V_REC.CODCOMANDA1;
    END LOOP;


  INSERT INTO TMP_VOUCHERCADOULINK(COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT)
  SELECT COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT
  FROM
    VOUCHERCADOULINK
  WHERE
    TIPDOC = aTIP
    AND CODDOC = RECID;

  DELETE TMP_VOUCHERCADOULINK_INI;

  INSERT INTO TMP_VOUCHERCADOULINK_INI(TIPOPERATIE, BARCODE) SELECT TIPOPERATIE, BARCODE FROM TMP_VOUCHERCADOULINK;


  PKG_CFGTABLES.EXT_GOTORECORD(aTipPtExt);
  COMMIT;
END;
/*
PROCEDURE  CurataCopii(aCodNod in number) is
begin
  for v_rec in (select CodProiectNod from tmp_nodechiv where NODORIGINAL = aCodNod ) loop
     CurataCopii(v_rec.CodProiectNod);
     Delete from tmp_nodechiv where CodProiectNod = v_rec.CodProiectNod;
  end loop;
end;

PROCEDURE  CurataNule(aCodNod in number) is
begin
  for v_rec in (select CodProiectNod, nvl(Paritate,0) Paritate from tmp_nodechiv where NODORIGINAL = aCodNod ) loop
    if v_rec.Paritate = 0 then
      CurataCopii(v_rec.CodProiectNod);
      Delete from tmp_nodechiv where CodProiectNod = v_rec.CodProiectNod;
    else
      CurataNule(v_rec.CodProiectNod);
    end if;
  end loop;
end;
*/

function GetLinieCom(aCodObj in Number, OBS in Varchar2, NewObs out varchar2) return number is
  aCodCmd1 NUMBER(20) := 0;
  aCodCmd  NUMBER(20);
  B             INTEGER     := 0;
  BB            INTEGER     := 0;

  NrCC          varchar2(20);

begin
  NewObs := Obs;
  B   := InStr(OBS, &apos;&lt;NRCC=&apos;);
  if B &gt; 0 then
    BB   := InStr(OBS, &apos;NRCC&gt;&apos;);
    if BB &gt; 0 then
      NRCC   := Substr(OBS,  B + 6,  BB  - (B + 6));
      begin
        select CodComanda  into aCodCmd from Comanda  where SeriaDoc||NrDoc = NRCC;
        select CodComanda1 into aCodCmd1 from Comanda1 where CodComanda = aCodCmd and CodObiect = aCodObj;
        NewObs := Substr(OBS,  1,  B - 1 )||Substr(OBS,  BB + 6, 400 );
      exception when others then
        aCodCmd1 := 0;
      end;
    end if;
  end if;
  Return aCodCmd1;
end;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod             NUMBER(20);
  vCodPack         NUMBER(20);
  vCodPack1         NUMBER(20);
  vCodPack2         NUMBER(20);
  vCodMan          NUMBER(20);
  vCodMat          NUMBER(20);
  TIPComanda       INTEGER := 0;
  NR               INTEGER := 0;
  aOperat          INTEGER := 0;
  aInchisa         INTEGER := 0;
  aAnuLat          INTEGER := 0;
  aCARNETDOC       NUMBER(20);
  aNRDOC           NUMBER(20);
  aDISPLIVRARE     INTEGER := 0;
  CodCMD1          Number(20);
  aCodLinieCli     NUMBER(20);
  aCodSubunit      NUMBER(20);
  aDataDoc         DATE;
  aDoc             VARCHAR2(200);
  aTipTranzactie    number(1);
--  aOldTipTranzactie number(1);
  aTipRezervare     number(1);
--  aOldTipRezervare  number(1);
  aPersDeblocare   Number(20);
  aMIJLTRANSP      Number(20);
  aCod             Number(20);
  aINTERVENTIE     Number(20);
  aValoare         Number;
  aValoare1         Number;
  aKmIn            Number;
  aCombIn          Number;
  aKmLast          Number;
  aAn              Number(4);
  aLuna            Number(4);
  aPERDURATA       Number;
  aPERKM           Number;
  aATENTIONAREZILE Number;
  aATENTIONAREKM   Number;
  aACCIDENTALA     Number;
  aCodSofer        Number;
  aCodSofer1       Number;
  aCodSofer2       Number;
  aCodClient       Number;
  aTipClient       Number;
  avalsoferf       NUMBER(20,7);
  avalsofercm      NUMBER(20,7);
  aCantRez         NUMBER(20,7);
  aDelegat         Number(20);
  aCodGestIni      Number(20);
  aCodGest         Number(20);
  aMaxCode         Number(20);
  aCurCode         Number(20);
  aCodNParcAut     Number(20);
  aPredat          Number(1);
  aStatus          Number(1);
  aData            Date;
  aCount           number(10);
  aCount1          number(10);
  aCantRezCli      NUMBER(20,7);
  CONSTOPERAT      INTEGER     := 0;
  ModifTerm        Number(1);
  TermenCalcCmdInt number(5);
  e_stergere_eronata EXCEPTION;
  aCntPack   Number(10);
  aTipPtExt    Number(10);
  PRAGMA exception_init( e_stergere_eronata, -20001 );
  CONSTOPERATFURN    INTEGER     := 0;
BEGIN
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADRESTNPNEOP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERAT  := 0;
  END;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;MODIFTERMCMDINT&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO ModifTerm FROM DUAL;
    EXCEPTION WHEN OTHERS THEN ModifTerm  := 0;
  END;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;TermenCalcCmdInt&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO TermenCalcCmdInt FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TermenCalcCmdInt  := 0;
  END;

  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADACCEPTATNEOPFURN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERATFURN FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERATFURN  := 0;
  END;


  SELECT
    TIPDOC,
    Partener,
    Delegat ,
    NVL(OPERAT,0),
    NVL(INCHISA,0),
    NVL(ANULAT,0),
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    DISPLIVRARE,
    NVL(TipTranzactie,0),
    NVL(CODSUPERVISOR,0),
    NVL(MIJLTRANSP,0),
    VALOARE,
    CodGest,
    An,Luna
  INTO
    TIPComanda,
    aCodClient,
    aDelegat ,
    aOperat,
    aInchisa,
    aAnulat,
    aCARNETDOC,
    aNRDOC,
    aCodSubunit,
    aDATADOC,
    ADOC,
    aDISPLIVRARE,
    aTipTranzactie,
    aPersDeblocare,
    aMIJLTRANSP,
    aValoare,
    aCodGest,
    aAn, aLUNA
  FROM TMP_COMANDA;
  if TIPComanda = 18 and aDispLivrare = 1 then
    aTipPtExt := 103;
  else
    aTipPtExt := TIPComanda;
  end if;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (aTipPtExt);
  IF tipcomanda = 94 THEN
    Update TMP_RAC_REZ set
       valsofercm  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1
                      where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 1),0),
       valsoferf   = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1
                      where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 0),0),
       valclientcm = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1
                      where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 1),0),
       valclientf  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1
                      where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 0),0);
  end if;

  if tipcomanda = 92 THEN
    delete tmp_iesprodlink;
    delete tmp_iesprodlink_initial;
    update TMP_Comanda1 set GestAct = aCodGest;
  end if;

  if tipcomanda = 8 then
    for v_rec in (select count(*), codstare1, codcomanda1
                  from tmp_planiflink
                  group by codstare1, codcomanda1
                  having count(*) &gt; 1
                 ) loop
      delete tmp_planiflink where codstare1 = v_rec.codstare1 and codcomanda1 = v_rec.codcomanda1;
      insert into tmp_planiflink (codcomanda1, codstare1)
      values (v_rec.codcomanda1, v_rec.codstare1);
    end loop;
  end if;

  UPDATE TMP_CMDLIVRLINK L
   SET
    TERMENCOMANDA =
   (SELECT C1.TERMEN
    FROM
    COMANDA1 C1 WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA)
   ;

  PKG_GLOBALS.SETMASTERID(aPersDeblocare);

  delete comanda1et c1et where codcomanda1 in (select codcomanda1 from comanda1 where codcomanda = (select codcomanda from tmp_comanda));

  Update TMP_COMANDA2 set CodNParcAut = aMIJLTRANSP;
  IF tipcomanda = 94 THEN -- comanda RentACar
    update TMP_COMANDA set CodGest = null where Nvl(CodGest,0) = 0;
  end if;
  if TIPComanda = 92 then --Service Auto
    Update Tmp_cmdprodmat set CodComanda1 = null where codcomanda1 = 0 or codcomanda1 not in  (SELECT CodComanda1 FROM TMP_COMANDA1);
    Update Tmp_Comanda3   set CodComanda1 = null where codcomanda1 not in  (SELECT CodComanda1 FROM TMP_COMANDA1);
  end if;

  -- stergeri de rezervari
  FOR V_REC IN (SELECT * FROM TMP_LIVR1_INITIAL)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_LIVR1 L1
    WHERE
      L1.CODIES1 = V_REC.CODIES1
      AND NVL(L1.CODNIRSTOC,0) = V_REC.CODNIRSTOC
      AND NVL(L1.CODNIRSER,0)  = V_REC.CODNIRSER
      AND NVL(L1.CODLOCATIE,0) = NVL(V_REC.CODLOCATIE,0);

    IF NR = 0 THEN
      DELETE FROM REZERVATS RS WHERE RS.CODREZERVATS = V_REC.CODLIVR1;
    END IF;
  END LOOP;

  update tmp_comanda1 set datastart = null where datastart = pkg_globals.DATA0;

  IF Operation = 0 THEN  -- UPDATE
    if tipcomanda = 8 then
      ModificaRezervariCC(RecId);
    end if;
    -- Master COMANDA
    SELECT CodComanda INTO RecId FROM TMP_COMANDA;

    if ModifTerm = 1 and tipcomanda = 18 then
      delete from tmp_manevra3;
      insert into tmp_manevra3(codunic,val)
      select c1.codcomanda1, t1.termen - c1.termen
      from comanda1 c1
           inner join tmp_comanda1 t1 on t1.codcomanda1 = c1.codcomanda1
      where c1.codcomanda = recid and c1.termen &lt;&gt; t1.termen;
    end if;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE COMANDA
    SET (   CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC, PARTENER, CODGEST,
            SUBUNITSURSA, SCADENTAV, INCHISA, VALOARE, AN, LUNA, OBS, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
            VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, DISPLIVRARE,Verificat, Facturabil, Curs,FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
            FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS,
            CODPERSC, MOTIVINCHIDERE, CODPARTCOMIS, TIPLIVRARE, MAJORARI, GRATIE, EXPORTKLG, MODINCHIDERE, PLATFORMA_ONLINE, REMORCA, ROTEFACT)
       =( SELECT
            CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC, PARTENER, CODGEST,
            SUBUNITSURSA, SCADENTAV, INCHISA, VALOARE, AN, LUNA, OBS, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
            VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, DISPLIVRARE,Verificat, Facturabil, NVL(Curs, 1), FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
            FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS,
            CODPERSC, MOTIVINCHIDERE, CODPARTCOMIS, TIPLIVRARE, MAJORARI, GRATIE, EXPORTKLG, MODINCHIDERE, PLATFORMA_ONLINE, REMORCA, ROTEFACT
          FROM TMP_COMANDA)
    WHERE CodComanda = RecId ;
    IF tipcomanda = 94 THEN -- comanda RentACar
      UPDATE RAC_REZ
      SET
       (
        TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        CODCCV          ,
        OBS_Contract    ,
        CodTIPASIG      ,
        Email           ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        CodSofer, CodSofer1, CodSofer2, SursaClient,
        FaraTVA,
        Telefon
        )
        =
        (SELECT
        TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        CODCCV          ,
        OBS_Contract    ,
        CodTIPASIG      ,
        Email           ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        CodSofer, CodSofer1, CodSofer2, SursaClient,
        FaraTVA,
        Telefon
        FROM TMP_RAC_REZ)
      WHERE
        CodComanda = RECID;

    end if;



-- detail VOUCHERCADOULINK

      DELETE FROM VOUCHERCADOULINK
      WHERE
        CODDOC = RECID
        AND TIPDOC = tipcomanda
        AND COD NOT IN (SELECT COD FROM TMP_VOUCHERCADOULINK);

      FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
      LOOP
        IF V_REC.COD &lt; 0 THEN
          INSERT INTO VOUCHERCADOULINK
          (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
          VALUES
          (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, tipcomanda, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
        ELSE
          UPDATE VOUCHERCADOULINK
          SET
            BARCODE     = V_REC.BARCODE,
            VALOARE     = V_REC.VALOARE,
            DATASTART   = V_REC.DATASTART,
            DATASTOP    = V_REC.DATASTOP,
            ZILEVALABIL = V_REC.ZILEVALABIL,
            CODOBIECT   = V_REC.CODOBIECT,
            POSTAT      = V_REC.POSTAT
          WHERE
            COD = V_REC.COD;
        END IF;
      END LOOP;





    IF tipcomanda  in (92,94) THEN -- comanda service auto
      begin
        select codnparccom into aCod  from Tmp_NParcSA;
        if aCod &lt; 0 then
          select Count(*) into aCod  from NPARCCOM where CodComanda = RecId;
          if aCod = 0 then
            INSERT INTO NPARCCOM (codnparccom, codcomanda, codnparcaut, Obs, kmbord,TipComSA,CategPret,
                                 DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum,
                                 Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari,
                                 tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep,
                                 DataAutRep, NrOre, KmBordE)
            SELECT seq_nparccom_codnparccom.NextVal, RecId, codnparcaut, Obs, kmbord, TipComSA,CategPret,
                                 DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum,
                                 Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari,
                                 tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep,
                                 DataAutRep, NrOre, KmBordE
            FROM Tmp_NParcSA;
          end if;
        end if;
        UPDATE NPARCCOM
        SET (
            codnparcaut, Obs, kmbord, CategPret, TipComSA, DataInchiderii, InmatrRom, Inspectie,
            PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari, tipcomanda, Asigurator, Distanta,
            AdresaSediu, NrDosarDaune,
            NrAutRep, DataAutRep, NrOre, KmBordE) =
        (SELECT
            codnparcaut, Obs, kmbord, CategPret, TipComSA, DataInchiderii, InmatrRom, Inspectie,
            PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari, tipcomanda, Asigurator, Distanta,
            AdresaSediu, NrDosarDaune,
            NrAutRep, DataAutRep, NrOre, KmBordE
         FROM Tmp_NParcSA )
        WHERE CodComanda = RecId ;
      exception when others then aCod := 0;
      end;

      DELETE FROM AVARIECAROSERIE WHERE CODAVARIE IN
      ( SELECT CODAVARIE FROM AVARIECAROSERIE WHERE CODCOMANDA = RECID AND CODAVARIE NOT IN
      (SELECT CODAVARIE FROM
        ( SELECT CODAVARIE FROM TMP_AVARIECAROSERIE union all SELECT CODAVARIE FROM TMP_AVARIECAROSERIE1))
      );

      for vx in (Select * from TMP_AVARIECAROSERIE) loop
        if vx.CODAVARIE &lt; 0 then
          INSERT INTO  AVARIECAROSERIE ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
          VALUES (Seq_Avariecaroserie_Codavarie.Nextval,RecID,vx.DEFECT,1,vx.X,vx.Y);
        else
           update AVARIECAROSERIE
          Set
            DEFECT  = vx.DEFECT,
            CAND    = 1,
            X       = vx.X,
            Y       = vx.Y
          where CODAVARIE = vx.CODAVARIE;
        end if;
      end loop;
      for vx in (Select * from TMP_AVARIECAROSERIE1) loop
        if vx.CODAVARIE &lt; 0 then
          INSERT INTO  AVARIECAROSERIE ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
          VALUES (Seq_Avariecaroserie_Codavarie.Nextval,RecID,vx.DEFECT,2,vx.X,vx.Y);
        else
           update AVARIECAROSERIE
          Set
            DEFECT  = vx.DEFECT,
            CAND    = 2,
            X       = vx.X,
            Y       = vx.Y
          where CODAVARIE = vx.CODAVARIE;
        end if;
      end loop;
    END IF; --end tipcomanda  in (92,94)
    if tipcomanda = 53 then
      delete lansare1 where codcmd1 in
        (SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
        (SELECT CODCOMANDA1 FROM TMP_CMDLINK)
        );

      delete tmp_manevra2;
      insert into tmp_manevra2(codunic)
      select codliniecomanda
      from cmdlink
      where CODCOMANDA1 IN
        ( SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
        (SELECT CODCOMANDA1 FROM TMP_CMDLINK)
        );
    end if;

    DELETE FROM CMDLINK WHERE CODCOMANDA1 IN
      ( SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_CMDLINK)
      );

    DELETE FROM VOUCHERLINK WHERE Nvl(CODCmd,0) IN
      ( SELECT CODComanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_COMANDA1)
      );

    DELETE FROM PRECMDLINK WHERE CODCOMANDA1 IN
      ( SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_PRECMDLINK)
      );

    DELETE FROM PLANIFLINK WHERE CODCOMANDA1 IN
      (SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_PLANIFLINK)
      );

    if TIPComanda = 53 then
      for v_rec in (select codunic codcomanda1 from tmp_manevra2) loop
        UPDATE COMANDA1 C1
        SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(cc1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 cc1 on l.codcomanda1 = cc1.codcomanda1
                             inner join comanda cc on cc1.codcomanda = cc.codcomanda
                        where cc1.CodObiect = C1.CodObiect
                        and cc.tipdoc = 53 AND cC.OPERAT = 1 AND cC.ANULAT = 0
                        START WITH l.codliniecomanda = v_rec.codcomanda1
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )
        WHERE
        C1.CODCOMANDA1 = v_rec.codcomanda1;
      end loop;
    end if;

    DELETE FROM CMDLIVRLINK WHERE CODCOMANDA1 IN
      ( SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_CMDLIVRLINK)
      );

    DELETE FROM STORNOCMDF WHERE CODCOMANDA1 IN
      ( SELECT CODCOmanda1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
      (SELECT CODCOMANDA1 FROM TMP_STORNOCMDF)
      );
    DELETE PACHETEDLLINK PL
    WHERE CODCOMANDA1 IN
    ( SELECT CODCOMANDA1 FROM COMANDA1 WHERE CODCOMANDA = RECID AND CODCOMANDA1 NOT IN
     (SELECT CODCOMANDA1 FROM TMP_PACHETEDLLINK)
    );

    -- DETAIL TMP_TERMENECMD
    DELETE FROM TERMENECMD T WHERE CODCOMANDA = RECID
    AND NOT EXISTS (SELECT CODTERMEN FROM TMP_TERMENECMD WHERE CODTERMEN = T.CODTERMEN);

    DELETE FROM CMDAPROBARI A WHERE CODDOC = RECID AND TIPDOC = TIPCOMANDA
    AND NOT EXISTS(SELECT COD FROM TMP_CMDAPROBARI WHERE COD = A.COD);

    FOR V_REC IN (SELECT * FROM TMP_CMDAPROBARI)
    LOOP
     IF V_REC.COD &lt; 0 THEN
        INSERT INTO CMDAPROBARI(COD,  CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
        VALUES (SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, TIPCOMANDA, V_REC.NIVEL, V_REC.STARE, V_REC.OBS, V_REC.USERID);

      ELSE
        UPDATE CMDAPROBARI
        SET
          NIVEL  = V_REC.NIVEL,
          STARE  = V_REC.STARE,
          USERID = V_REC.USERID,
          OBS    = V_REC.OBS
        WHERE
          COD = V_REC.COD;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TERMENECMD )
    LOOP
      IF V_REC.CODTERMEN &lt; 0 THEN
        INSERT INTO TERMENECMD(CODTERMEN, CODCOMANDA, ZILE, PROCENT, TIPPLATA)
        VALUES (SEQ_TERMENECMD_CODTERMEN.NEXTVAL, RECID, V_REC.ZILE, V_REC.PROCENT, V_REC.TIPPLATA);

      ELSE
        UPDATE TERMENECMD
        SET ZILE     = V_REC.ZILE,
            PROCENT  = V_REC.PROCENT,
            TIPPLATA = V_REC.TIPPLATA
        WHERE CODTERMEN = V_REC.CODTERMEN;

      END IF;
    END LOOP;
    -- Detail COMANDA1
    -- sterg intai copii CMDPRODMAT si CMDPRODREZ
    for v_rec in (select codCOMANDA1, codobiect from comanda1 WHERE CodComanda = RecID AND CodComanda1 NOT IN
                  (SELECT CodComanda1 FROM TMP_COMANDA1)) loop
      if TIPComanda = 92 then
        Update Tmp_cmdprodmat set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
        Update cmdprodmat     set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
        Update Tmp_comanda3   set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
        Update comanda3       set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
      else
        if TIPComanda = 94 then
          Update Tmp_comanda3   set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
          Update comanda3       set CodComanda1 = null where codcomanda1 = v_rec.codcomanda1;
        end if;
        delete cmdprodmat where codcomanda1 = v_rec.codcomanda1;
        delete cmdprodrez where codcomanda1 = v_rec.codcomanda1;
        delete cmdprodman where codcomanda1 = v_rec.codcomanda1;
        if TipComanda = 53 and aTipTranzactie = 1 then
          for v_tmp in (select u2c.codutilaj2c, u2c.codutilaj2
                        from utilaje2c u2c
                        where u2c.codcomanda1 = v_rec.codcomanda1) loop
            update utilaje2c
            set codcomanda1 = null
            where codutilaj2c = v_tmp.codutilaj2c;
          end loop;
          delete rezervats where codcomanda1 = v_rec.codcomanda1;
        end if;
      end if;
      for v_rez in (select * from rezervats where codcomanda1f = v_rec.codcomanda1) loop
        delete rezervats where codrezervats = v_rez.codrezervats;
        if v_rec.codobiect &lt;&gt; v_rez.codobiect then
          update rezervats
          set
              rezervatini = rezervatini + v_rez.rest,
              rest = rest + v_rez.rest
          where codcomanda1 = v_rec.codcomanda1 and nvl(codcomanda1f, 0) = 0 and CodObiect = v_rez.CodObiect;
        end if;
      end loop;
    end loop;

    DELETE FROM COMANDA1
    WHERE CodComanda = RecID
      AND CodComanda1 NOT IN (SELECT CodComanda1 FROM TMP_COMANDA1);


    FOR v_rec IN (SELECT TMP.*, INI.CANTACCEPTAT CANTINI
                  FROM TMP_COMANDA1 TMP
                       LEFT JOIN TMP_COMANDA1_INITIAL INI ON TMP.CODCOMANDA1 = INI.CODCOMANDA1
                  ORDER BY TMP.IndexLocal) LOOP
      IF TIPComanda = 53 then
        if (InStr(V_REC.OBS, &apos;&lt;NRCC=&apos;) &gt; 0) THEN
          select COUNT(*) into CODCMD1 from TMP_CMDLINK where CODCOMANDA1 = V_REC.CODCOMANDA1;
          if CodCmd1 = 0 then
            CODCMD1 := GetLinieCom(V_Rec.CodObiect, V_REC.OBS, V_REC.OBS);
            if CodCmd1 &gt; 0 then
              INSERT INTO TMP_CMDLINK (CODCOMANDA1, CODLINIECOMANDA, CANT)
              VALUES  (v_rec.CODCOMANDA1, CODCMD1,V_REC.CANTACCEPTAT);
            end if;
          end if;
        end if;
        if nvl(V_REC.CodReteta,0) = 0 and aOperat = 1 then
          V_REC.CodReteta := 1;
          V_REC.Consum    := 1;
          INSERT INTO TMP_CMDPRODMAT
          (CodCmdProdmat, codcomanda1, codobiect, cant, pret, rest,
           tip, d1, d2, d3, paritateechiv, TipEchiv, cumsec, ccant)
           values
          (-1, v_rec.codcomanda1, v_rec.codobiect, V_REC.CANTACCEPTAT, V_REC.pu, V_REC.CANTACCEPTAT,
           0, v_rec.d1, v_rec.d2, v_rec.d3, 1, 3, V_REC.UMSEC,V_REC.CANTACCEPTAT);
        end if;
      end if;
      IF NVL(v_rec.CodComanda1, -1) &gt; 0
      THEN
        UPDATE COMANDA1 SET
          INDEXLOCAL   = v_rec.INDEXLOCAL,
          CODOBIECT    = v_rec.CODOBIECT,
          UMSEC        = v_rec.UMSEC,
          UMCorelat    = v_rec.UMCorelat,
          PUCorelat    = v_rec.PUCorelat,
          CODCADOU     = V_REC.CODCADOU,
          PU           = v_rec.PU / v_rec.Paritate,
          prioritate   = v_rec.prioritate,
          CODPROMO1    = V_REC.CODPROMO1,
          SubunitSursa = V_REC.SubunitSursa,
          DataStart    = v_rec.DataStart,
          CANTCOMANDAT = v_rec.CantComandat * v_rec.Paritate,
          CANTACCEPTAT = v_rec.CantAcceptat * v_rec.Paritate,
          CANTRETURNAT = v_rec.CantReturnat * v_rec.Paritate,
          REZERVATINI  = v_rec.REZERVATINI * v_rec.Paritate,
          RESTACCEPTAT =
            CASE
              WHEN TIPComanda = 8 --AND aOperat = 1 AND aAnulat = 0 -- Comanda furnizori
              THEN v_rec.CantAcceptat * v_rec.Paritate -
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                  WHERE
                    IL.CODLINIECOMANDA = v_Rec.CodCOMANDA1 --AND I.OPERAT = 1 
                    AND PKG_IESIRI.CONDITIE_FACTURA_OPERATA(I.OPERAT, CONSTOPERATFURN) = 1
                    AND I.ANULAT = 0
                ) -
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    CMDLIVRLINK IL
                    LEFT OUTER JOIN COMANDA1 I1 ON I1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT OUTER JOIN COMANDA   I ON I.CODCOMANDA   = I1.CODCOMANDA
                  WHERE
                    IL.CODLINIECOMANDA = v_Rec.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                )

              WHEN TIPComanda = 43 --AND aOperat = 1 AND aAnulat = 0 -- Comanda GESTIUNI
              THEN v_rec.CantAcceptat * v_rec.Paritate -
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    TRANSFLINK IL
                    LEFT OUTER JOIN TRANSF1 I1 ON I1.CODTRANSF1 = IL.CODTRANSF1
                    LEFT OUTER JOIN TRANSF   I ON I.CODTRANSF   = I1.CODTRANSF
                  WHERE
                    IL.CODLINIECOMANDA = v_Rec.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                )
              WHEN TIPComanda IN (18, 44, 57, 60,92, 94)-- AND aOperat = 1 AND aAnulat = 0 -- Comanda clienti
              THEN v_rec.CantAcceptat * v_rec.Paritate -
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    IESLINK IL
                    LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                  WHERE
                    IL.CODLINIECOMANDA = v_Rec.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                ) -
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    CMDLIVRLINK IL
                    LEFT OUTER JOIN COMANDA1 I1 ON I1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT OUTER JOIN COMANDA   I ON I.CODCOMANDA   = I1.CODCOMANDA
                  WHERE
                    IL.CODLINIECOMANDA = v_Rec.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                )-
                ( -- comenzi clienti stinse prin bonconsum
                   SELECT NVL(SUM(I1.CANT), 0)
                  FROM
                    IESIRI1 I1,
                    IESIRI I
                  WHERE
                    I1.TIPDOCIMP = 18
                    AND I1.CODLINIEDOCIMP = V_REC.CODCOMANDA1
                    AND I.CODIES = I1.CODIES
                    AND I.TIPDOC = 24
                    AND I.OPERAT = 1
                    AND I.ANULAT = 0

                )


              ELSE 0
            END,
          CULANSARE    = v_rec.CuLansare,
          RESTLANSAT   = CASE
                           WHEN NVL(v_rec.restlansat, -999) = -999 THEN v_Rec.Restacceptat
                           ELSE v_rec.Restlansat
                         END,
          TERMEN       = v_rec.Termen,
          ANULAT       = v_rec.Anulat,
          ADDIM        = nvl(V_REC.ADDIM, 0),
          PROCDISC     = V_REC.PROCDISC,
          OBS          = V_REC.OBS,
          PRETORIG     = V_REC.PRETORIG / v_rec.Paritate,
          COEFDISCMAJ  = V_REC.COEFDISCMAJ,
          CODCATPRET   = V_REC.CODCATPRET,
          SCADENTA     = V_REC.SCADENTA,
          CONSUM       = v_rec.consum,
          d1           = v_rec.d1,
          d2           = v_rec.d2,
          d3           = v_rec.d3,
          TipSursa     = v_rec.tipsursa,
          CodSursa     = v_rec.codsursa,
          CantUM1      = v_rec.cantum1,
          AcceptUM1    = v_rec.AcceptUM1,
          TIPPLATA     = v_rec.TIPPLATA,
          CADOU        = v_rec.CADOU,
          CADOULINK    = v_rec.CADOULINK,
          PRETPROMO    = V_REC.PRETPROMO,
          CoefIndirecte= v_rec.coefindirecte,
          COdReteta    = v_Rec.Codreteta,
          CodProiect   = v_Rec.Codproiect,
          TipLivrare   = v_Rec.TipLivrare,
          CODANALIZANOD=V_REC.CODANALIZANOD,
          Nivel        = v_Rec.Nivel,
          Pozitie      = v_Rec.Pozitie,
          EXCEPTIONAL  = v_rec.EXCEPTIONAL,
          TAXA         = V_REC.TAXA,
          CODCONTRACT1 = V_REC.CODCONTRACT1,
          CODOFERTA1   = V_REC.CODOFERTA1,
          PRETUM1      = V_REC.PRETUM1,
          GESTACT      = V_REC.GESTACT,
          CODCENTRU    = V_REC.CODCENTRU,
          CODNORMA     = V_REC.CODNORMA,
          MODINCHIDERE = V_REC.MODINCHIDERE,
          TERMENCONTRACT   = V_REC.TERMENCONTRACT,
          CODMIFIX     = V_REC.CODMIFIX,
          TipLinieSA   = V_REC.TipLinieSA,
          CodLinieDocImp = v_rec.CodLinieDocImp,
          TipDocImp = v_rec.TipDocImp,
          DiscManual= v_rec.Discmanual,
          DataIncarcarii = v_rec.DataIncarcarii,
          FURNIZOR       = V_REC.FURNIZOR,
          PUProd         = V_REC.PUPROD
        WHERE CODCOMANDA1  = v_rec.CODCOMANDA1;

      ELSE
        SELECT seq_COMANDA1_CodComanda1.Nextval INTO VCOD from Dual;

        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;COMANDA1&apos;, VCOD, V_REC.CODCOMANDA1);
/*
        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDC1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDL1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
        END IF;


        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDRAC1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDI1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
        END IF;*/

        UPDATE TMP_LIVR1
        SET CODIES1 = VCOD
        WHERE CODIES1 = V_REC.CODCOMANDA1;

        UPDATE TMP_CMDLIVRLINK
        SET CODCOMANDA1 = VCOD
        WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

        UPDATE TMP_PACHETEDLLINK
        SET CODCOMANDA1 = VCOD
        WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

        UPDATE TMP_STORNOCMDF
        SET CODCOMANDA1 = VCOD
        WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

        UPDATE TMP_COMANDA3
        SET CODCOMANDA1 = VCOD
        WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;


        UPDATE TMP_LIVR1_MAT
        SET CODLIVR = VCOD
        WHERE CODLIVR = V_REC.CODCOMANDA1;

        -- update-ez si tmp_cmdprodmat si tmp_cmdprodrez
        UPDATE TMP_cmdprodmat
        SET CODcomanda1 = VCOD
        WHERE codcomanda1 = V_REC.CODCOMANDA1;

        UPDATE TMP_cmdprodman
        SET CODcomanda1 = VCOD
        WHERE codcomanda1 = V_REC.CODCOMANDA1;


        UPDATE TMP_PLANIFLINK SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

        --pe cazul comenzilor furnizori pe LANSARI completez CODCMDPRODMAT pt a face rezervarea de aprovizionare
        --LANSARI este folosit doar la ARAMIS la incarcarea comenzii
        if tipcomanda = 8 and v_rec.lansari &gt; 0 then
          for v_cmdint in (select m.codcomanda1
                           from cmdprodmat m
                           where m.codcmdprodmat = v_rec.lansari) loop
            insert into rezervats(codrezervats,
                                  codcomanda1,
                                  codnirstoc,
                                  codnirser,
                                  rest,
                                  umsec,
                                  codcmdprodmat,
                                  rezervatini,
                                  codobiect,
                                  codcomanda1f)
            values (seq_rezervats_codrezervats.nextval,
                    v_cmdint.codcomanda1,
                    0,
                    0,
                    v_rec.cantacceptat,
                    v_rec.umsec,
                    v_Rec.Lansari,
                    v_rec.cantacceptat,
                    v_rec.codobiect,
                    vcod);
          end loop;
        end if;

        INSERT INTO COMANDA1 (
          CODCOMANDA1,CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,PU,prioritate, CODPROMO1, SubunitSursa, DataStart,
          CANTCOMANDAT, CANTACCEPTAT, RESTACCEPTAT,
          CULANSARE, UMCorelat, PUCorelat, CODCADOU, RESTLANSAT, TERMEN, ANULAT, ADDIM,
          PROCDISC, OBS, PRETORIG, COEFDISCMAJ, CODCATPRET, SCADENTA, CONSUM,
          REZERVATINI, D1, D2, D3, TipSursa, CodSursa, CantUM1, AcceptUM1,
          TIPPLATA, CADOU,CADOULINK,  PRETPROMO, CoefIndirecte, codreteta, Codproiect, TipLivrare, CODANALIZANOD, nivel, pozitie, EXCEPTIONAL, TAXA, CODCONTRACT1,
          CODOFERTA1, PRETUM1, GESTACT, CODCENTRU, CODNORMA, MODINCHIDERE, TERMENCONTRACT, CODMIFIX, TipLinieSA, CodLinieDocImp, TipDocImp, DiscManual, Dataincarcarii,
          FURNIZOR, PUPROD)
        VALUES (
          vCod,  RecID, v_rec.INDEXLOCAL, v_rec.CODOBIECT, v_rec.UMSEC, v_rec.PU / v_rec.Paritate,v_rec.prioritate, V_REC.CODPROMO1, V_REC.SubunitSursa, v_rec.DataStart,
          v_rec.CANTCOMANDAT * v_rec.Paritate, v_rec.CANTACCEPTAT * v_rec.Paritate, v_rec.CANTACCEPTAT * v_rec.Paritate,
          v_rec.CULANSARE, v_rec.UMCorelat, v_rec.PUCorelat, V_REC.CODCADOU, v_rec.CANTACCEPTAT * v_rec.Paritate, v_rec.TERMEN, v_rec.ANULAT, nvl(V_REC.ADDIM, 0),
          V_REC.PROCDISC, V_REC.OBS, V_REC.PRETORIG  / v_rec.Paritate, V_REC.COEFDISCMAJ, V_REC.CODCATPRET, V_REC.SCADENTA, V_rec.consum,
          v_rec.REZERVATINI * v_rec.Paritate, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.tipsursa, v_rec.codsursa, v_rec.CantUM1, V_REC.AcceptUM1,
          V_REC.TIPPLATA, V_REC.CADOU, V_REC.CADOULINK, V_REC.PRETPROMO,  V_REC.Coefindirecte, v_rec.codreteta, v_rec.Codproiect, v_rec.TipLivrare, V_REC.CODANALIZANOD, v_rec.nivel, v_rec.pozitie,
          v_rec.EXCEPTIONAL, V_REC.TAXA, V_REC.CODCONTRACT1, V_REC.CODOFERTA1, V_REC.PRETUM1, V_REC.GESTACT, V_REC.CODCENTRU, V_REC.CODNORMA, V_REC.MODINCHIDERE, V_REC.TERMENCONTRACT,
          V_REC.CODMIFIX, V_REC.TipLinieSA, V_REC.CodLinieDocImp, V_REC.TipDocImp, V_REC.DiscManual, V_REC.DataIncarcarii,V_REC.FURNIZOR,V_REC.PUPROD
        );
        UPDATE TMP_VOUCHERLINK SET CODCMD = VCOD WHERE CODCMD = V_REC.CODCOMANDA1;
        UPDATE TMP_CMDLINK SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        UPDATE TMP_PRECMDLINK SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        update tmp_nodechiv set CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_CMDLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM CMDLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        IF NR = 0
        THEN INSERT INTO CMDLINK (CODCOMANDA1, CODLINIECOMANDA, CANT)
        VALUES  (V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA, V_REC.CANT);
        ELSE
        UPDATE CMDLINK
        SET
          CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
          CANT            = V_REC.CANT
        WHERE
          CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
      END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PRECMDLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM PRECMDLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        IF NR = 0
        THEN INSERT INTO PRECMDLINK (CODCOMANDA1, CODPRECOMANDA1, CANT)
        VALUES  (V_REC.CODCOMANDA1, V_REC.CODPRECOMANDA1, V_REC.CANT);
        ELSE
        UPDATE PRECMDLINK
        SET
          CODPRECOMANDA1 = V_REC.CODPRECOMANDA1,
          CANT           = V_REC.CANT
        WHERE
          CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
      END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PLANIFLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM PLANIFLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        IF NR = 0
        THEN INSERT INTO PLANIFLINK (CODCOMANDA1, CODSTARE1)
        VALUES  (V_REC.CODCOMANDA1, V_REC.CODSTARE1);
        ELSE
        UPDATE PLANIFLINK
        SET
          CODSTARE1 = V_REC.CODSTARE1
        WHERE
          CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
      END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PACHETEDLLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM PACHETEDLLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
        IF NR = 0
        THEN INSERT INTO PACHETEDLLINK (CODCOMANDA1, CODPACHETEOBJ, CANT)
        VALUES  (V_REC.CODCOMANDA1, V_REC.CODPACHETEOBJ, V_REC.CANT);
        ELSE
        UPDATE PACHETEDLLINK
        SET
          CODPACHETEOBJ   = V_REC.CODPACHETEOBJ,
          CANT            = V_REC.CANT
        WHERE
          CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
      END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_STORNOCMDF) LOOP
        IF V_REC.COD &lt; 0 THEN
          INSERT INTO STORNOCMDF(COD, CODCOMANDA1, CODLINIECOMANDA, CODINTR1, CANT)
           VALUES  (SEQ_STORNOCMDF_COD.NEXTVAL, V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA, V_REC.CODINTR1, V_REC.CANT);
        ELSE
          UPDATE STORNOCMDF
          SET
            CODCOMANDA1     = V_REC.CODCOMANDA1,
            CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
            CODINTR1        = V_REC.CODINTR1,
            CANT            = V_REC.CANT
          WHERE
            COD = V_REC.COD;
        END IF;
      END LOOP;

    IF TIPComanda &lt;&gt; 92 THEN
        delete cmdprodmat mat where mat.codcomanda1 in (select codcomanda1 from comanda1 where codcomanda = recId) and not exists
        (select tmp.codcmdprodmat from tmp_cmdprodmat tmp where tmp.codcmdprodmat = mat.codcmdprodmat);

        delete cmdprodman man where man.codcomanda1 in (select codcomanda1 from comanda1 where codcomanda = recId) and not exists
        (select tmp.codcmdprodman from tmp_cmdprodman tmp where tmp.codcmdprodman = man.codcmdprodman);

        for v_tmp in (select * from tmp_cmdprodman) loop
          if Nvl(v_tmp.codcmdprodman, 0) &gt; 0 then
            update cmdprodman set
              CODCOMANDA1   = v_tmp.CODCOMANDA1,
              CODMAN        = v_tmp.CODMAN,
              NROP          = v_tmp.NROP,
              CODOP         = v_tmp.CODOP,
              CODLOC        = v_tmp.CODLOC,
              CODTARIF      = v_tmp.CODTARIF,
              TU            = v_tmp.TU,
              cant          = v_tmp.cant,
              REST          = v_tmp.REST,
              VALOARE       = v_tmp.VALOARE,
              CODPRODGEST   = v_tmp.CODPRODGEST,
              INDEXLOCAL    = v_tmp.INDEXLOCAL,
              DSV           = v_tmp.DSV,
              Fix           = v_tmp.Fix,
              Nivel         = v_tmp.Nivel,
              BPS           = v_tmp.BPS,
              TPI           = v_tmp.TPI,
              OBS           = v_tmp.OBS,
              DETALII       = v_tmp.DETALII,
              DATASTART     = to_date(to_char(nvl(V_TMP.DATASTART, pkg_globals.DATA0),&apos;dd.mm.yyyy&apos;)||&apos; &apos;||v_tmp.orastart, &apos;dd.mm.yyyy hh24:mi&apos;),
              CODUTILAJ     = V_TMP.CODUTILAJ,
              DECALAJ       = V_TMP.DECALAJ,
              COEFBPS       = V_TMP.COEFBPS
            WHERE codcmdprodman = v_tmp.codcmdprodman;
          else
            select seq_cmdprodman_codcmdprodman.nextval into vCodMan from dual;
            update tmp_cmdprodmat set codcmdprodman = vCodMan where codcmdprodman = v_tmp.codcmdprodman;
            insert into cmdprodman
            (CODCMDPRODMAN,
             CODCOMANDA1,
             CODMAN,
             NROP,
             CODOP,
             CODLOC,
             CODTARIF,
             TU,
             cant,
             REST,
             VALOARE,
             CODPRODGEST,
             INDEXLOCAL,
             DSV, Fix, Nivel,
             BPS,
             TPI,
             OBS,
             DETALII,
             DATASTART,
             CODUTILAJ,
             DECALAJ,
             COEFBPS
            )
             values
            (vCODMAN,
             v_tmp.CODCOMANDA1,
             v_tmp.CODMAN,
             v_tmp.NROP,
             v_tmp.CODOP,
             v_tmp.CODLOC,
             v_tmp.CODTARIF,
             v_tmp.TU,
             v_tmp.cant,
             v_tmp.REST,
             v_tmp.VALOARE,
             v_tmp.CODPRODGEST,
             v_tmp.INDEXLOCAL,
             v_tmp.DSV, v_tmp.Fix, v_tmp.Nivel,
             v_tmp.BPS,
             v_tmp.TPI,
             v_tmp.OBS,
             v_tmp.DETALII,
             to_date(to_char(nvl(V_TMP.DATASTART, pkg_globals.DATA0),&apos;dd.mm.yyyy&apos;)||&apos; &apos;||v_tmp.orastart, &apos;dd.mm.yyyy hh24:mi&apos;),
             V_TMP.CODUTILAJ,
             V_TMP.DECALAJ,
             V_TMP.COEFBPS
            );
          end if;
        end loop;

        for v_tmp in (select * from tmp_cmdprodmat) loop
          if Nvl(v_tmp.codcmdprodmat, 0) &gt; 0 then
            --insert into xxx(xxx) values (&apos;+&apos;);
            update cmdprodmat set
              codcomanda1   = v_tmp.codcomanda1,
              codobiect     = v_tmp.codobiect,
              cant          = v_tmp.cant,
              pret          = v_tmp.pret,
              rest          = v_tmp.rest,
              tip           = v_tmp.tip,
              D1            = v_tmp.d1,
              D2            = v_tmp.d2,
              D3            = v_tmp.d3,
              IndexLocal    = v_tmp.IndexLocal,
              Reziduu       = v_tmp.reziduu,
              CodProdMat    = v_tmp.CodProdMat,
              ParitateEchiv = v_tmp.ParitateEchiv,
              TipEchiv      = v_tmp.TipEchiv,
              ccant         = v_tmp.ccant,
              cumsec        = v_tmp.cumsec,
              codcmdprodman = v_tmp.codcmdprodman,
              cantum1       = v_tmp.cantum1,
              umsec         = v_tmp.umsec,
              codcomanda3   = v_tmp.codcomanda3
            WHERE codcmdprodmat = v_tmp.codcmdprodmat and tip = v_tmp.tip;
          else
            --insert into xxx(xxx) values (&apos;-&apos;);
            select seq_cmdprodmat_codcmdprodmat.nextval into vCodMat from dual;
            UPDATE TMP_LIVR1_MAT
            SET
              CODIES1         = vCodMat,
              CODCMDPRODMAT   = vCodMat
            WHERE
              CODCMDPRODMAT = v_tmp.codcmdprodmat;

            insert into cmdprodmat
            (codcmdprodmat, codcomanda1, codobiect, cant, pret, rest,
             tip, d1, d2, d3, indexlocal, reziduu, Codprodmat,
             paritateechiv, tipechiv, ccant, cumsec, codcmdprodman,cantum1,umsec,codcomanda3)
             values
            (vCodMat, v_tmp.codcomanda1, v_tmp.codobiect, v_tmp.cant, v_tmp.pret, v_tmp.rest,
             v_tmp.tip, v_tmp.d1, v_tmp.d2, v_tmp.d3, v_tmp.indexlocal, v_tmp.reziduu, v_tmp.CodProdMat,
             v_tmp.paritateechiv, v_tmp.tipechiv, v_tmp.ccant, v_tmp.cumsec, v_tmp.codcmdprodman, v_tmp.cantum1,
             v_tmp.umsec,v_tmp.codcomanda3);
          end if;
        end loop;
    end if;

    FOR V_REC IN (SELECT * FROM TMP_LIVR1)
    LOOP
      SELECT COUNT(*) INTO NR FROM REZERVATS
      WHERE
        NVL(CODCOMANDA1, 0)    = NVL(V_REC.CODIES1,    0)
        AND NVL(CODNIRSTOC, 0) = NVL(V_REC.CODNIRSTOC, 0)
        AND NVL(CODNIRSER, 0)  = NVL(V_REC.CODNIRSER,  0)
        AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);

      IF NR &gt; 0 THEN
        UPDATE
          REZERVATS RS
        SET
          CODCOMANDA1  = V_REC.CODIES1,
          CODNIRSTOC   = V_REC.CODNIRSTOC,
          CODNIRSER    = V_REC.CODNIRSER,
--         CANTREZERVAT = V_REC.CANT * V_REC.PARITATE,
--         REST         = V_REC.CANT * V_REC.PARITATE - NVL(PKG_COMANDA.LIVRAT_DIN_REZERVAT(RS.CODCOMANDA1, RS.CODNIRSTOC, RS.CODNIRSER), 0),
         UMSEC        = V_REC.UMSEC
        WHERE
          NVL(CODCOMANDA1,    0) = NVL(V_REC.CODIES1,0)
          AND NVL(CODNIRSTOC, 0) = NVL(V_REC.CODNIRSTOC,0)
          AND NVL(CODNIRSER,   0) = NVL(V_REC.CODNIRSER,0)
          AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
      ELSE
        INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, UMSEC/*, REZERVATINI*/,CODCOMANDA1F)
                    VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODIES1, V_REC.CODNIRSTOC, V_REC.CODNIRSER,  V_REC.UMSEC /*,  V_REC.CANT * V_REC.PARITATE*/,V_REC.CODLOCATIE);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT T1.*, R.REST, T1.CANT - nvl(TT1.CANT,0) DIF, NVL(R.CODREZERVATS,0) CODREZERVATS
                  FROM TMP_LIVR1_MAT T1
                       INNER JOIN CMDPRODMAT MAT ON T1.CODCMDPRODMAT = MAT.CODCMDPRODMAT
                       LEFT JOIN (SELECT SUM(TI1.CANT) CANT, TI1.CODLIVR1 FROM TMP_LIVR1_MAT_INITIAL TI1 GROUP BY TI1.CODLIVR1) TT1 ON T1.CODLIVR1 = TT1.CODLIVR1
                       LEFT JOIN CMDLINK L ON L.CODCOMANDA1 = MAT.CODCOMANDA1
                       LEFT JOIN REZERVATS R ON R.CODCOMANDA1 = L.CODLINIECOMANDA AND R.CODNIRSTOC = T1.CODNIRSTOC
                                             AND NVL(R.CODNIRSER,0) = NVL(T1.CODNIRSER,0)
                  )
    LOOP
      SELECT COUNT(*) INTO NR FROM REZERVATS
      WHERE
        NVL(CODCOMANDA1, 0)    = NVL(V_REC.CODLIVR,    0)
        AND NVL(CODNIRSTOC, 0) = NVL(V_REC.CODNIRSTOC, 0)
        AND NVL(CODNIRSER, 0)  = NVL(V_REC.CODNIRSER,  0)
        AND NVL(CODCMDPRODMAT, 0) = NVL(V_REC.CODCMDPRODMAT,  0);

      IF NR = 0 THEN
        INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, UMSEC, CODCMDPRODMAT, REST, REZERVATINI)
                    VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODLIVR, V_REC.CODNIRSTOC, V_REC.CODNIRSER,  V_REC.UMSEC, V_REC.CODCMDPRODMAT,  V_REC.CANT * V_REC.PARITATE,  V_REC.CANT * V_REC.PARITATE);

      END IF;
      IF V_REC.CODREZERVATS &gt; 0 THEN
        IF V_REC.DIF &gt; 0 THEN
          IF V_REC.REST &gt; V_REC.DIF THEN
            UPDATE REZERVATS SET
              REST = REST - V_REC.DIF,
              REZERVATINI = REZERVATINI - V_REC.DIF
            WHERE CODREZERVATS = V_REC.CODREZERVATS;
          ELSE
            DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
          END IF;
        END IF;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT TMP.*, TMPI.CODCOMANDA1 CODINITIAL, TMPI.CANT CANTINI
                  FROM TMP_CMDLIVRLINK TMP
                       LEFT JOIN CMDLIVRLINK TMPI ON TMPI.CODCOMANDA1 = TMP.CODCOMANDA1)
    LOOP
      SELECT COUNT(*) INTO NR  FROM CMDLIVRLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      IF NR = 0 THEN
        INSERT INTO CMDLIVRLINK (CODCOMANDA1, CODLINIECOMANDA, CANT)
        VALUES (V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA,  V_REC.CANT);
        IF TIPCOMANDA = 66 THEN
          SELECT COUNT(*) INTO NR FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND CODNIRSTOC &gt; 0;
          IF NR = 1 THEN
            FOR V_TMP IN (SELECT CODREZERVATS, REST FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND NVL(CODNIRSTOC,0) = 0) LOOP
              UPDATE REZERVATS
              SET REST = CASE WHEN REST &gt; V_REC.CANT THEN REST - V_REC.CANT ELSE 0 END
              WHERE CODREZERVATS = V_TMP.CODREZERVATS;
            END LOOP;
          END IF;
        END IF;
      ELSE
        UPDATE CMDLIVRLINK
        SET
          CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
          CANT            = V_REC.CANT
        WHERE
          CODCOMANDA1 = V_REC.CODCOMANDA1;
        IF TIPCOMANDA = 66 THEN
          SELECT COUNT(*) INTO NR FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND CODNIRSTOC &gt; 0;
          IF NR = 1 AND V_REC.CANT &gt; V_REC.CANTINI THEN
            FOR V_TMP IN (SELECT CODREZERVATS, REST FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND CODNIRSTOC &gt; 0) LOOP
              UPDATE REZERVATS
              SET REST = CASE WHEN REST &gt; V_REC.CANT-V_REC.CANTINI THEN REST - (V_REC.CANT-V_REC.CANTINI) ELSE 0 END
              WHERE CODREZERVATS = V_TMP.CODREZERVATS;
            END LOOP;
          END IF;
        END IF;
      END IF;

    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_VOUCHERLINK)
    LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM VOUCHERLINK WHERE Nvl(CODCmd,0) = V_REC.CODCMD;
      IF NR = 0
      THEN INSERT INTO VOUCHERLINK (CodVLink, codvoucher, codCmd, valoare)
      VALUES  (SEQ_VOUCHERLINK_COD.Nextval, V_REC.codvoucher, V_REC.CODCmd, V_REC.Valoare);
      ELSE
      UPDATE VOUCHERLINK
      SET
        CODCmd  = V_REC.CODCmd,
        VALOARE = V_REC.VALOARE
      WHERE
        Nvl(CODCmd,0) = V_REC.CODCmd;
      END IF;



    END LOOP;

  ELSE -- INSERT

    SELECT seq_COMANDA_CodComanda.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;COMANDA&apos;, RecId);

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO COMANDA (
      CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC, PARTENER, CODGEST, SUBUNITSURSA,
      SCADENTAV, INCHISA, VALOARE, AN, LUNA, OBS, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
      VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, userid,datacreare, DISPLIVRARE,Verificat, Facturabil, Curs, FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
      FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS,
      CODPERSC, MOTIVINCHIDERE, CODPARTCOMIS, TIPLIVRARE, MAJORARI, GRATIE,   EXPORTKLG, MODINCHIDERE, PLATFORMA_ONLINE, REMORCA, ROTEFACT)
    SELECT
      RecId, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, DATADOC, PARTENER, CODGEST, SUBUNITSURSA,
      SCADENTAV, INCHISA, VALOARE, AN, LUNA, OBS, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
      VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, PKG_GLOBALS.USERID,SYSTIMESTAMP, DISPLIVRARE,Verificat, Facturabil, NVL(Curs, 1), FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
      FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS,
      CODPERSC, MOTIVINCHIDERE, CODPARTCOMIS, TIPLIVRARE, MAJORARI, GRATIE, EXPORTKLG, MODINCHIDERE, PLATFORMA_ONLINE, REMORCA, ROTEFACT
    FROM TMP_COMANDA;
    IF tipcomanda = 94 THEN -- comanda RentACar
      INSERT INTO RAC_REZ(
      CodRAC_REZ      ,
        CodComanda      ,
        TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        CODCCV          ,
        OBS_Contract    ,
        CodTIPASIG      ,
        Email           ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        CodSofer, CodSofer1, CodSofer2, SursaClient ,
        FaraTVA,
        Telefon
      )
      SELECT
      SEQ_RAC_REZ_COD.NextVal,
      RECID           ,
        TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
        NR_REF          ,
        CodCOMISIONAR   ,
        CodSediuComis, CODREZERVARE   ,
        CodLocalit_Prel ,
        ADRESA_PREL     ,
        CodLocalit_Livr ,
        ADRESA_LIVR     ,
        NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
        CodContr_PRELIVR,
        FactLunara     ,
        SUMAGARANTIE    ,
        CODCMDACCIDENT         ,
        NUME_CARD       ,
        EXPIRA_CARD     ,
        CODCCV          ,
        OBS_Contract    ,
        CodTIPASIG      ,
        Email           ,
        codinterventie  ,
        kmin            ,
        kmout           ,
        combin          ,
        combout         ,
        kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
        CodSofer, CodSofer1, CodSofer2, SursaClient ,
        FaraTVA,
        Telefon
      FROM TMP_RAC_REZ;
    END IF;

    IF TIPComanda  in (92,94) THEN -- comanda service auto
      begin
        select codnparccom into aCod  from Tmp_NParcSA;
        if aCod &lt; 0 then
          select Count(*) into aCod  from NPARCCOM where CodComanda = RecId;
          if aCod = 0 then
            INSERT INTO NPARCCOM (codnparccom, codcomanda, codnparcaut, Obs, kmbord,TipComSA,CategPret,
                                 DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum,
                                 Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari,
                                 tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep,
                                 DataAutRep, NrOre, KmBordE)
            SELECT seq_nparccom_codnparccom.NextVal, RecId, codnparcaut, Obs, kmbord, TipComSA,CategPret,
                                 DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum,
                                 Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari,
                                 tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep,
                                 DataAutRep, NrOre, KmBordE
            FROM Tmp_NParcSA;
          end if;
        end if;
        UPDATE NPARCCOM
        SET (codnparcaut, Obs, kmbord, TipComSA, CategPret, DataInchiderii, InmatrRom, Inspectie,
            PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari,
            tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune, NrAutRep, DataAutRep, NrOre,
            KmBordE) =
            (SELECT codnparcaut, Obs, kmbord, TipComSA, CategPret, DataInchiderii, InmatrRom, Inspectie,
                    PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, kmgarantie, datagarantie, Recomandari, tipcomanda, Asigurator, Distanta, AdresaSediu, NrDosarDaune,
                    NrAutRep, DataAutRep, NrOre, KmBordE
             FROM Tmp_NParcSA )
        WHERE CodComanda = RecId ;
      exception when others then aCod := 0;
      end;

      INSERT INTO  AVARIECAROSERIE ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
      SELECT Seq_Avariecaroserie_Codavarie.Nextval,RecID,DEFECT,1,X,Y from Tmp_Avariecaroserie;
      INSERT INTO  AVARIECAROSERIE ( CODAVARIE,CODCOMANDA,DEFECT,CAND,X,Y)
      SELECT Seq_Avariecaroserie_Codavarie.Nextval,RecID,DEFECT,2,X,Y from Tmp_Avariecaroserie1;
    END IF;

    FOR V_REC IN (SELECT * FROM TMP_COMANDA1)
    LOOP

      IF TIPComanda = 53 then
        if (InStr(V_REC.OBS, &apos;&lt;NRCC=&apos;) &gt; 0) THEN
          select COUNT(*) into CODCMD1 from TMP_CMDLINK where CODCOMANDA1 = V_REC.CODCOMANDA1;
          if CodCmd1 = 0 then
            CODCMD1 := GetLinieCom(V_Rec.CodObiect, V_REC.OBS, V_REC.OBS);
            if CodCmd1 &gt; 0 then
              INSERT INTO TMP_CMDLINK (CODCOMANDA1, CODLINIECOMANDA, CANT)
              VALUES  (v_rec.CODCOMANDA1, CODCMD1,V_REC.CANTACCEPTAT);
            end if;
          end if;
        end if;
        if nvl(V_REC.CodReteta,0) = 0 and aOperat = 1 then
          V_REC.CodReteta := 1;
          V_REC.Consum    := 1;
          INSERT INTO TMP_CMDPRODMAT
          (CodCmdProdmat, codcomanda1, codobiect, cant, pret, rest,
           tip, d1, d2, d3, paritateechiv, TipEchiv, cumsec, ccant, cantum1)
           values
          (-1, v_rec.codcomanda1, v_rec.codobiect, V_REC.CANTACCEPTAT, V_REC.pu, V_REC.CANTACCEPTAT,
           0, v_rec.d1, v_rec.d2, v_rec.d3, 1, 3, V_REC.UMSEC,V_REC.CANTACCEPTAT, v_rec.acceptum1);
        end if;
      end if;

      SELECT seq_COMANDA1_CodComanda1.Nextval INTO VCOD FROM DUAL;

      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;COMANDA1&apos;, VCOD, V_REC.CODCOMANDA1);

     /* IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDC1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
      END IF;

      IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDL1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
      END IF;


      IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDRAC1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
      END IF;

      IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDI1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
      END IF;

      IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF1&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_COMANDF1 SET CODCOMANDA1 = &apos; || VCOD || &apos; WHERE CODCOMANDA1 = &apos; || V_REC.CODCOMANDA1;
      END IF;*/

      UPDATE TMP_LIVR1
      SET    CODIES1 = VCOD
      WHERE  CODIES1 = V_REC.CODCOMANDA1;

      UPDATE TMP_CMDLIVRLINK
      SET    CODCOMANDA1 = VCOD
      WHERE  CODCOMANDA1 = V_REC.CODCOMANDA1;

      UPDATE TMP_PACHETEDLLINK
      SET CODCOMANDA1 = VCOD
      WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

      UPDATE TMP_COMANDA3
      SET CODCOMANDA1 = VCOD
      WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

      UPDATE TMP_STORNOCMDF
      SET
        CODCOMANDA1 = VCOD
      WHERE
        CODCOMANDA1 = V_REC.CODCOMANDA1;


      UPDATE TMP_LIVR1_MAT
      SET    CODLIVR = VCOD
      WHERE  CODLIVR = V_REC.CODCOMANDA1;

      UPDATE TMP_PLANIFLINK  SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

      --pe cazul comenzilor furnizori pe LANSARI completez CODCMDPRODMAT pt a face rezervarea de aprovizionare
      --LANSARI este folosit doar la ARAMIS la incarcarea comenzii
      if tipcomanda = 8 and v_rec.lansari &gt; 0 then
        for v_cmdint in (select m.codcomanda1
                         from cmdprodmat m
                         where m.codcmdprodmat = v_rec.lansari) loop
          insert into rezervats(codrezervats,
                                codcomanda1,
                                codnirstoc,
                                codnirser,
                                rest,
                                umsec,
                                codcmdprodmat,
                                rezervatini,
                                codobiect,
                                codcomanda1f)
          values (seq_rezervats_codrezervats.nextval,
                  v_cmdint.codcomanda1,
                  0,
                  0,
                  v_rec.cantacceptat,
                  v_rec.umsec,
                  v_Rec.Lansari,
                  v_rec.cantacceptat,
                  v_rec.codobiect,
                  vcod);
        end loop;
      end if;

      INSERT INTO COMANDA1 (
        CODCOMANDA1,CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,PU, CANTCOMANDAT,
        CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
        CULANSARE, UMCorelat, PUCorelat, CODCADOU, RESTLANSAT, TERMEN, ANULAT, ADDIM,prioritate, CODPROMO1, SubunitSursa, DataStart,
        PROCDISC, OBS, PRETORIG, COEFDISCMAJ, CODCATPRET, SCADENTA, CONSUM,
        REZERVATINI, D1, D2, D3, TipSursa, CodSursa, CantUM1, AcceptUM1,
        TIPPLATA, CADOU, CADOULINK, PRETPROMO, CoefIndirecte, codreteta, Codproiect, TipLivrare, CODANALIZANOD, nivel, pozitie, EXCEPTIONAL, TAXA, CODCONTRACT1,
        CODOFERTA1 ,PRETUM1, GESTACT, CODCENTRU, CODNORMA, MODINCHIDERE, TERMENCONTRACT, CODMIFIX, TipLinieSA, CodLinieDocImp, TipDocImp, DiscManual, Dataincarcarii,
        FURNIZOR, PUPROD )
      VALUES(
        vCod,  RecID, v_rec.INDEXLOCAL, v_rec.CODOBIECT, v_rec.UMSEC, v_rec.PU / v_rec.Paritate,
        v_rec.CANTCOMANDAT * v_rec.Paritate, v_rec.CANTACCEPTAT * v_rec.Paritate, v_rec.CANTACCEPTAT * v_rec.Paritate, v_rec.CANTRETURNAT * v_rec.Paritate,
        v_rec.CULANSARE, v_rec.UMCorelat, v_rec.PUCorelat, V_REC.CODCADOU, v_rec.CANTACCEPTAT * v_rec.Paritate, v_rec.TERMEN, v_rec.ANULAT, nvl(V_REC.ADDIM, 0),v_rec.prioritate, V_REC.CODPROMO1, V_REC.SubunitSursa, v_rec.DataStart,
        V_REC.PROCDISC, V_REC.OBS, V_REC.PRETORIG  / v_rec.Paritate, V_REC.COEFDISCMAJ, V_REC.CODCATPRET,   V_REC.SCADENTA, V_REC.CONSUM,
        v_rec.REZERVATINI * v_rec.Paritate, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.tipSursa, v_rec.CodSursa, v_rec.CantUM1, V_REC.AcceptUM1,
        V_REC.TIPPLATA, V_REC.CADOU, V_REC.CADOULINK,  V_REC.PRETPROMO, v_rec.CoefIndirecte, v_rec.codreteta, v_rec.Codproiect, v_rec.TipLivrare, V_REC.CODANALIZANOD, v_rec.nivel, v_rec.pozitie,
        v_rec.EXCEPTIONAL, V_REC.TAXA, V_REC.CODCONTRACT1, V_REC.CODOFERTA1, V_REC.PRETUM1, V_REC.GESTACT, V_REC.CODCENTRU, V_REC.CODNORMA, V_REC.MODINCHIDERE, V_REC.TERMENCONTRACT,
        V_REC.CODMIFIX, V_REC.TipLinieSA, V_REC.CodLinieDocImp, V_REC.TipDocImp, V_REC.DiscManual, V_REC.DataIncarcarii, V_REC.FURNIZOR, V_REC.PUPROD
      );

      update tmp_comanda1 set codcomanda1 = vcod where codcomanda1 = v_Rec.codcomanda1;
      -- update-ez si tmp_cmdprodmat
      UPDATE TMP_cmdprodmat
      SET CODcomanda1 = VCOD
      WHERE codcomanda1 = V_REC.CODCOMANDA1;

      UPDATE TMP_cmdprodman
      SET CODcomanda1 = VCOD
      WHERE codcomanda1 = V_REC.CODCOMANDA1;

      update tmp_nodechiv set CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      UPDATE TMP_CMDLINK  SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      UPDATE TMP_PRECMDLINK  SET CODCOMANDA1 = VCOD WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      UPDATE TMP_VOUCHERLINK  SET CODCmd = VCOD WHERE CODCmd = V_REC.CODCOMANDA1;

      update utilaje2c set codcomanda1 = vcod where codutilaj2c = v_rec.codutilaj2c;
    END LOOP;

    INSERT INTO TERMENECMD(CODTERMEN, CODCOMANDA, ZILE, PROCENT, TIPPLATA)
    SELECT SEQ_TERMENECMD_CODTERMEN.NEXTVAL, RECID, ZILE, PROCENT, TIPPLATA FROM TMP_TERMENECMD;

    INSERT INTO CMDAPROBARI(COD, CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
    SELECT SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, TIPCOMANDA, NIVEL, STARE, OBS, USERID FROM TMP_CMDAPROBARI;


    INSERT INTO CMDLINK    (CODCOMANDA1, CODLINIECOMANDA, CANT) (SELECT CODCOMANDA1, CODLINIECOMANDA, CANT FROM TMP_CMDLINK);
    INSERT INTO PRECMDLINK (CODCOMANDA1, CODPRECOMANDA1, CANT) (SELECT CODCOMANDA1, CODPRECOMANDA1, CANT FROM TMP_PRECMDLINK);

    FOR V_REC IN (SELECT * FROM TMP_CMDLIVRLINK) LOOP
      IF TIPCOMANDA = 66 THEN
        SELECT COUNT(*) INTO NR FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND CODNIRSTOC &gt; 0;
        IF NR = 1 THEN
          FOR V_TMP IN (SELECT CODREZERVATS, REST FROM REZERVATS WHERE CODCOMANDA1F = V_REC.CODLINIECOMANDA AND NVL(CODNIRSTOC,0) = 0) LOOP
            UPDATE REZERVATS
            SET REST = CASE WHEN REST &gt; V_REC.CANT THEN REST - V_REC.CANT ELSE 0 END
            WHERE CODREZERVATS = V_TMP.CODREZERVATS;
          END LOOP;
        END IF;
      END IF;
      INSERT INTO CMDLIVRLINK(CODCOMANDA1, CODLINIECOMANDA, CANT) VALUES(V_REC.CODCOMANDA1, V_REC.CODLINIECOMANDA, V_REC.CANT);
    END LOOP;
    INSERT INTO PLANIFLINK(CODCOMANDA1, CODSTARE1) (SELECT CODCOMANDA1, CODSTARE1 FROM TMP_PLANIFLINK);

    INSERT INTO VOUCHERLINK(CodVLink, codvoucher, codCmd, valoare) (SELECT SEQ_VOUCHERLINK_COD.Nextval, codvoucher, codCmd, valoare FROM TMP_VOUCHERLINK);

    INSERT INTO PACHETEDLLINK(CODCOMANDA1, CODPACHETEOBJ, CANT) (SELECT CODCOMANDA1, CODPACHETEOBJ, CANT FROM TMP_PACHETEDLLINK);

    INSERT INTO STORNOCMDF(COD, CODCOMANDA1, CODLINIECOMANDA, CODINTR1, CANT)
           (SELECT SEQ_STORNOCMDF_COD.NEXTVAL, CODCOMANDA1, CODLINIECOMANDA, CODINTR1, CANT FROM TMP_STORNOCMDF);


    FOR V_REC IN (SELECT * FROM TMP_LIVR1)
    LOOP
      SELECT COUNT(*) INTO NR FROM REZERVATS
      WHERE
        NVL(CODCOMANDA1, 0)    = NVL(V_REC.CODIES1,    0)
        AND NVL(CODNIRSTOC, 0) = NVL(V_REC.CODNIRSTOC, 0)
        AND NVL(CODNIRSER, 0)  = NVL(V_REC.CODNIRSER,  0)
        AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
      IF NR &gt; 0 THEN
          UPDATE
            REZERVATS RS
          SET
            CODCOMANDA1  = V_REC.CODIES1,
            CODNIRSTOC   = V_REC.CODNIRSTOC,
            CODNIRSER    = V_REC.CODNIRSER,
  --         CANTREZERVAT = V_REC.CANT * V_REC.PARITATE,
  --         REST         = V_REC.CANT * V_REC.PARITATE - NVL(PKG_COMANDA.LIVRAT_DIN_REZERVAT(RS.CODCOMANDA1, RS.CODNIRSTOC, RS.CODNIRSER), 0),
            UMSEC        = V_REC.UMSEC
          WHERE
            NVL(CODCOMANDA1,    0) = NVL(V_REC.CODIES1,    0)
            AND NVL(CODNIRSTOC, 0) = NVL(V_REC.CODNIRSTOC, 0)
            AND NVL(CODNIRSER,   0) = NVL(V_REC.CODNIRSER,  0)
            AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
        ELSE
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, UMSEC/*, REZERVATINI*/,CODCOMANDA1F)
          VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODIES1, V_REC.CODNIRSTOC, V_REC.CODNIRSER,  V_REC.UMSEC /*,  V_REC.CANT * V_REC.PARITATE*/, V_REC.CODLOCATIE);
        END IF;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
    LOOP
      INSERT INTO VOUCHERCADOULINK
        (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
        VALUES
        (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, TIPCOMANDA, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
    END LOOP;


    IF TIPComanda &lt;&gt; 92 THEN
    --if TIPCOMANDA = 53 then
    for v_tmp in (select * from tmp_cmdprodman) loop
      select seq_cmdprodman_codcmdprodman.nextval into vCodMan from dual;
      update tmp_cmdprodmat set codcmdprodman = vCodMan where codcmdprodman = v_tmp.codcmdprodman;

      insert into cmdprodman
      (CODCMDPRODMAN,
       CODCOMANDA1,
       CODMAN,
       NROP,
       CODOP,
       CODLOC,
       CODTARIF,
       TU,
       cant,
       REST,
       VALOARE,
       CODPRODGEST,
       INDEXLOCAL,
       DSV, Fix, Nivel,
       BPS,
       TPI,
       OBS,
       DETALII,
       DATASTART,
       CODUTILAJ,
       DECALAJ,
       COEFBPS
      )
      values
      (vCodMan,
       v_tmp.CODCOMANDA1,
       v_tmp.CODMAN,
       v_tmp.NROP,
       v_tmp.CODOP,
       v_tmp.CODLOC,
       v_tmp.CODTARIF,
       v_tmp.TU,
       v_tmp.cant,
       v_tmp.REST,
       v_tmp.VALOARE,
       v_tmp.CODPRODGEST,
       v_tmp.INDEXLOCAL,
       v_tmp.DSV, v_tmp.Fix, v_tmp.Nivel,
       v_tmp.BPS,
       v_tmp.TPI,
       v_tmp.OBS,
       v_tmp.DETALII,
       to_date(to_char(nvl(V_TMP.DATASTART, pkg_globals.DATA0),&apos;dd.mm.yyyy&apos;)||&apos; &apos;||v_tmp.orastart, &apos;dd.mm.yyyy hh24:mi&apos;),
       V_TMP.CODUTILAJ,
       V_TMP.DECALAJ,
       V_TMP.COEFBPS
      );
    end loop;

    for v_tmp in (select * from tmp_cmdprodmat) loop
      select seq_cmdprodmat_codcmdprodmat.nextval into vCodMat from dual;

      UPDATE TMP_LIVR1_MAT
      SET CODIES1         = vCodMat,
          CODCMDPRODMAT   = vCodMat
      WHERE CODCMDPRODMAT = v_tmp.codcmdprodmat;

      insert into cmdprodmat
      (codcmdprodmat, codcomanda1, codobiect, cant, pret, rest, tip, D1, D2, D3,
       IndexLocal, reziduu, COdProdMat, TipEchiv, ParitateEchiv, ccant, cumsec, codcmdprodman,
       cantum1, umsec, codcomanda3)
      values
      (vCodMat, v_tmp.codcomanda1, v_tmp.codobiect, v_tmp.cant, v_tmp.pret, v_tmp.rest, v_tmp.tip, v_tmp.D1, v_tmp.D2, v_tmp.D3,
       v_tmp.IndexLocal, v_tmp.Reziduu, v_tmp.CodProdMat, v_tmp.tipechiv, v_tmp.paritateechiv, v_tmp.ccant, v_tmp.cumsec, v_tmp.codcmdprodman,
       v_tmp.cantum1, v_tmp.umsec, v_tmp.codcomanda3);
      end loop;

      FOR V_REC IN (SELECT T1.*, R.REST, T1.CANT DIF, NVL(R.CODREZERVATS,0) CODREZERVATS
                    FROM TMP_LIVR1_MAT T1
                         INNER JOIN CMDPRODMAT MAT ON T1.CODCMDPRODMAT = MAT.CODCMDPRODMAT
                         LEFT JOIN CMDLINK L ON L.CODCOMANDA1 = MAT.CODCOMANDA1
                         LEFT JOIN REZERVATS R ON R.CODCOMANDA1 = L.CODLINIECOMANDA AND R.CODNIRSTOC = T1.CODNIRSTOC
                                               AND NVL(R.CODNIRSER,0) = NVL(T1.CODNIRSER,0)
                    )
      LOOP
        INSERT INTO REZERVATS
           (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, UMSEC, CODCMDPRODMAT, REST, REZERVATINI)
            VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODLIVR, V_REC.CODNIRSTOC, V_REC.CODNIRSER, V_REC.UMSEC, V_REC.CODCMDPRODMAT,V_REC.CANT * V_REC.PARITATE,  V_REC.CANT * V_REC.PARITATE);
        IF V_REC.CODREZERVATS &gt; 0 THEN
          IF V_REC.DIF &gt; 0 THEN
            IF V_REC.REST &gt; V_REC.DIF THEN
              UPDATE REZERVATS SET
                REST = REST - V_REC.DIF,
                REZERVATINI = REZERVATINI - V_REC.DIF
              WHERE CODREZERVATS = V_REC.CODREZERVATS;
            ELSE
              DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
            END IF;
          END IF;
        END IF;
      END LOOP;
    end if;

  END IF;

  aTipRezervare := 0;
  IF TIPComanda  = 94 THEN
    select TipRezervare into aTipRezervare from TMP_RAC_REZ;
  end if;
  if aTipRezervare = 5 then
    if aOperat &lt;&gt; 1 then
      DELETE FROM NPARC3 WHERE CODCMD IN ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID);
    else
      DELETE FROM NPARC3 WHERE
      CODCMD IN
      ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID AND CODCOMANDA2 NOT IN
      (SELECT CODCOMANDA2 FROM TMP_COMANDA2)
      );
    end if;
    DELETE FROM COMANDA2 WHERE
    CODCOMANDA2 IN
    ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID AND CODCOMANDA2 NOT IN
    (SELECT CODCOMANDA2 FROM TMP_COMANDA2)
    );

    select count(*) into aCount
    from comanda3;

    for v_rec in (
      select c3.codcomanda3
      from comanda3 c3
           left join tmp_comanda3 tmp on tmp.codcomanda3 = c3.codcomanda3
      where c3.codcomanda = recid and tmp.codcomanda3 is null
    ) loop
      delete comanda3 where codcomanda3 = v_rec.codcomanda3;
    end loop;

--    DELETE FROM COMANDA3 WHERE
--    CODCOMANDA3 IN
--    ( SELECT CODCOmanda3 FROM COMANDA3 WHERE CODCOMANDA = RECID AND CODCOMANDA3 NOT IN
--    (SELECT CODCOMANDA3 FROM TMP_COMANDA3)
--    );

    select count(*) into aCount1
    from comanda3;

    if aCount - aCount1 &gt; 20 then
      pkg_trigar.BAGA_IN_TRIGAR_MODIF(pkg_globals.GETUSERID, RecID, aCount, &apos;COMANDA3&apos;, &apos;CODCOMANDA3&apos;, &apos;stergere mare&apos;, to_char(aCount));
      raise_application_error(-20001,&apos;Stergere de inregistrari in COMANDA3 nejustificat de mare ! :&apos;||acount||&apos;-CodComanda: &apos;||RecId);
    end if;

    for vx in (Select * from TMP_COMANDA2) loop
      if vx.codcomanda2 &lt; 0 then
        SELECT SEQ_COMANDA1_CODCOMANDA2.Nextval INTO VCOD from Dual;
        INSERT INTO  COMANDA2 ( CODCOMANDA2,CODCOMANDA,CODLUCRARE,CODINTERVENTIE, OBS,CODPART,GARANTIE,CODLOCATIE,CODREZERVARE,CODNPARCAUT)
        VALUES (vCod,RecID,vx.CODLUCRARE,vx.CODINTERVENTIE, vx.OBS,vx.CODPART,vx.GARANTIE,vx.CODLOCATIE,vx.CODREZERVARE,aMIJLTRANSP);
        update TMP_COMANDA2 set CODCOMANDA2 = vCod where CODCOMANDA2 = vx.CODCOMANDA2;
        update TMP_COMANDA3 set CODCOMANDA2 = vCod where CODCOMANDA2 = vx.CODCOMANDA2;
      else
        update COMANDA2
        Set
          CODLUCRARE = vx.CODLUCRARE,
          CodComanda=RecID,
          CODREZERVARE=vx.CODREZERVARE,
          CODINTERVENTIE =vx.CODINTERVENTIE,
          CODLOCATIE = vx.CODLOCATIE,
          OBS        = vx.OBS,
          CODPART    = vx.CODPART,
          CODNPARCAUT= aMIJLTRANSP,
          Ore        = vx.Ore,
          GARANTIE   = vx.GARANTIE
        where CODCOMANDA2 = vx.CODCOMANDA2;
      end if;
    end loop;

    for vx in (Select * from TMP_COMANDA3) loop
      if vx.codcomanda3 &lt; 0 then
        INSERT INTO  COMANDA3
        ( CODCOMANDA3,CODCOMANDA2,CODOPERATIE,
        CANT,PRET,OBS,TIP,EXECUTAT,CODCOMANDA1,CODCOMANDA, DURATA,VALOARE,TARIF,CategPret,DataStart,CODREZERVARE,DATA, CodIntr1_1, CodIntr1_2, CodIntr1_3,
        codprestatie)
        VALUES
        (SEQ_COMANDA2_CODCOMANDA3.Nextval ,vx.CODCOMANDA2,vx.CODOPERATIE,
        vx.CANT,vx.PRET,vx.OBS,vx.TIP,vx.EXECUTAT,vx.CODCOMANDA1,RecID, vx.DURATA,vx.VALOARE,vx.TARIF,vx.CategPret,vx.DataStart,vx.CODREZERVARE,vx.DATA, vx.CodIntr1_1, vx.CodIntr1_2, vx.CodIntr1_3,
        vx.codprestatie);
      else
        update COMANDA3
        Set
          CODOPERATIE= vx.CODOPERATIE,
          CANT= vx.CANT,
          PRET= vx.PRET,
          DATA= vx.DATA,
          DATASTART= vx.DATASTART,
          OBS= vx.OBS,
          TIP= vx.TIP,
          DURATA     = vx.DURATA,
          VALOARE    = vx.VALOARE,
          TARIF      = vx.TARIF,
					CategPret  = vx.CategPret,
					CodComanda=RecID,
          CODCOMANDA1=vx.CODCOMANDA1,
          CODREZERVARE=vx.CODREZERVARE,
          EXECUTAT= vx.EXECUTAT,
          CodIntr1_1 = vx.CodIntr1_1,
          CodIntr1_2 = vx.CodIntr1_2,
          CodIntr1_3 = vx.CodIntr1_3,
          codprestatie = vx.codprestatie
        where CODCOMANDA3 = vx.CODCOMANDA3;
      end if;
    end loop;
  else
    DELETE FROM NPARC3 WHERE CODCMD IN ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID);
    update tmp_comanda2 set CodComanda = 0;
    update tmp_comanda3 set CodComanda = 0;

    update comanda2 set CodRezervare = 0 WHERE
    CODCOMANDA2 IN
    ( SELECT CODCOmanda2 FROM COMANDA2
      WHERE CODCOMANDA = RECID)
      AND CODCOMANDA2 NOT IN (SELECT CODCOMANDA2 FROM TMP_COMANDA2)
    AND CODCOMANDA = RECID;

    update comanda3 set CodRezervare = 0 WHERE
    CODCOMANDA3 IN
    ( SELECT CODCOmanda3 FROM COMANDA3
      WHERE CODCOMANDA = RECID) AND CODCOMANDA3 NOT IN (SELECT CODCOMANDA3 FROM TMP_COMANDA3)
    AND CODCOMANDA = RECID;

    DELETE FROM COMANDA4 WHERE
    CODCOMANDA4 IN
    ( SELECT CODCOmanda4 FROM COMANDA4 ) AND CODCOMANDA4 NOT IN
    (SELECT CODCOMANDA4 FROM TMP_COMANDA4)
    AND CODCOMANDA = RECID;

    for v_rec in ( SELECT CODCOmanda2 FROM COMANDA2
                   WHERE CODCOMANDA = RECID
                   AND CODCOMANDA2 NOT IN (SELECT CODCOMANDA2 FROM TMP_COMANDA2))
    loop
      DELETE FROM COMANDA2 WHERE CODCOMANDA2 = v_rec.CodComanda2;
      DELETE FROM COMANDA4 WHERE CODCOMANDA2 = v_rec.CodComanda2;
    end loop;

    for v_rec in ( SELECT CODCOmanda3 FROM COMANDA3
                   WHERE CODCOMANDA = RECID
                   AND CODCOMANDA3 NOT IN (SELECT CODCOMANDA3 FROM TMP_COMANDA3))
    loop
      DELETE FROM COMANDA3 WHERE CODCOMANDA3 = v_rec.CodComanda3;
      DELETE FROM COMANDA4 WHERE CODCOMANDA3 = v_rec.CodComanda3;
    end loop;

    for vx in (Select * from TMP_COMANDA2) loop
      if vx.codcomanda2 &lt;= 0 then
        SELECT SEQ_COMANDA1_CODCOMANDA2.Nextval INTO VCOD from Dual;
        INSERT INTO  COMANDA2 (
           CODCOMANDA2, CODCOMANDA, CODLUCRARE,  CODINTERVENTIE,    OBS,    CODPART,   GARANTIE,   CODLOCATIE,   CODREZERVARE,CODNPARCAUT, ORE)
        VALUES (
           vCod,        RECID,     vx.CODLUCRARE,vx.CODINTERVENTIE, vx.OBS,vx.CODPART,vx.GARANTIE,vx.CODLOCATIE,RecID,       aMIJLTRANSP, vx.ORE);
        update TMP_COMANDA2 set CODCOMANDA2 = vCod where CODCOMANDA2 = vx.CODCOMANDA2;
        update TMP_COMANDA3 set CODCOMANDA2 = vCod where CODCOMANDA2 = vx.CODCOMANDA2;
        INSERT INTO  COMANDA4
        (
        CODCOMANDA4,
        Codcomanda2 ,
        Codpers     ,
        DataStart   ,
        DataStop    ,
        eliberat, Ore    ,
        codcomanda
        )
        Select
        SEQ_COMANDA4_CODCOMANDA4.Nextval,
        vcod ,
        CodPers,
        DataStart   ,
        DataStop    ,
        eliberat, Ore    ,
        RECID
        from Tmp_Comanda4 where CodComanda2 = vx.codcomanda2;
      else
        update COMANDA2
        Set
          CODLUCRARE = vx.CODLUCRARE,
          CODINTERVENTIE = vx.CODINTERVENTIE,
          CODCOMANDA = RECID,
          CODREZERVARE=RecID,
          CODLOCATIE = vx.CODLOCATIE,
          OBS        = vx.OBS,
          CODPART    = vx.CODPART,
          CODNPARCAUT= aMIJLTRANSP,
          ORE        = vx.Ore,
          GARANTIE   = vx.GARANTIE
        where CODCOMANDA2 = vx.CODCOMANDA2;
        INSERT INTO  COMANDA4
        ( CODCOMANDA4,CODCOMANDA2,CODPERS,DataStart, DataStop, eliberat, Ore,CodComanda)
        Select SEQ_COMANDA4_CODCOMANDA4.Nextval, vx.codcomanda2 , CodPers, DataStart, DataStop, eliberat, Ore,RecID
        from Tmp_Comanda4 where CodComanda2 = vx.codcomanda2 and CodComanda4 &lt; 0;

        for vy in (Select * from TMP_Comanda4 where CodComanda2 = vx.CodComanda2 and CodComanda4 &gt; 0)
        loop
          update COMANDA4 set
            CODPERS   = vy.CodPers  ,
            DataStart = vy.DataStart,
            DataStop  = vy.DataStop,
            eliberat  = vy.eliberat,
            Ore       = vy.Ore
          where CodComanda4 = vy.CodComanda4;
        end loop;
      end if;
    end loop;

    for vx in (Select * from TMP_COMANDA3) loop
      if vx.codcomanda3 &lt;= 0 then
        SELECT SEQ_COMANDA2_CODCOMANDA3.Nextval INTO VCOD from Dual;
        if tipcomanda = 92 then
          update tmp_cmdprodmat set codcomanda3 = vcod where codcomanda3 = vx.codcomanda3;
        end if;
        INSERT INTO  COMANDA3
        ( CODCOMANDA3,CODCOMANDA2,CODOPERATIE,DURATA,VALOARE,TARIF,CategPret,DataStart,
        CANT,PRET,OBS,TIP,EXECUTAT,
        CODCOMANDA1,CODCOMANDA, CODREZERVARE,DATA, CodIntr1_1, CodIntr1_2, CodIntr1_3, codprestatie)
        VALUES
        (vcod ,vx.CODCOMANDA2,vx.CODOPERATIE,vx.DURATA,vx.VALOARE,vx.TARIF,vx.CategPret,vx.DataStart,
        vx.CANT,vx.PRET,vx.OBS,vx.TIP,vx.EXECUTAT,
        vx.CODCOMANDA1,RECID, RecID, vx.DATA, vx.CodIntr1_1, vx.CodIntr1_2, vx.CodIntr1_3, vx.codprestatie);

        INSERT INTO  COMANDA4
        (
        CODCOMANDA4,
        Codcomanda3 ,
        Codpers     ,
        DataStart   ,
        DataStop    ,
        eliberat, Ore    ,
        codcomanda
        )
        Select
        SEQ_COMANDA4_CODCOMANDA4.Nextval,
        vcod ,
        CodPers,
        DataStart   ,
        DataStop    ,
        eliberat, Ore    ,
        RECID
        from Tmp_Comanda4 where CodComanda3 = vx.codcomanda3;
      else
        update COMANDA3
        Set
          CODOPERATIE= vx.CODOPERATIE,
          CANT= vx.CANT,
          PRET= vx.PRET,
          DATA= vx.DATA,
          DATAStart= vx.DATAStart,
          OBS= vx.OBS,
          TIP= vx.TIP,
          DURATA     = vx.DURATA,
          VALOARE    = vx.VALOARE,
          TARIF      = vx.TARIF,
					CategPret  = vx.CategPret,
          CodComanda=RECID,
          CODCOMANDA1=vx.CODCOMANDA1,
          CODREZERVARE=RECID,
          EXECUTAT= vx.EXECUTAT,
          CodIntr1_1 = vx.CodIntr1_1,
          CodIntr1_2 = vx.CodIntr1_2,
          CodIntr1_3 = vx.CodIntr1_3,
          codprestatie = vx.codprestatie
        where CODCOMANDA3 = vx.CODCOMANDA3;

        INSERT INTO  COMANDA4
        ( CODCOMANDA4,CODCOMANDA3,CODPERS,DataStart, DataStop, eliberat, Ore,CodComanda)
        Select SEQ_COMANDA4_CODCOMANDA4.Nextval, vx.codcomanda3 , CodPers, DataStart, DataStop, eliberat, Ore,RecID
        from Tmp_Comanda4 where CodComanda3 = vx.codcomanda3 and CodComanda4 &lt; 0;

        for vy in (Select * from TMP_Comanda4 where CodComanda3 = vx.CodComanda3 and CodComanda4 &gt; 0)
        loop
          update COMANDA4 set
            CODPERS   = vy.CodPers  ,
            DataStart = vy.DataStart,
            DataStop  = vy.DataStop,
            eliberat  = vy.eliberat,
            Ore       = vy.Ore
          where CodComanda4 = vy.CodComanda4;
        end loop;

      end if;
    end loop;

    if TIPComanda  = 92 THEN

    delete cmdprodmat mat where mat.codcomanda3 in (select codcomanda3 from comanda3 where codcomanda = recId) and not exists
    (select tmp.codcmdprodmat from tmp_cmdprodmat tmp where tmp.codcmdprodmat = mat.codcmdprodmat);

    for v_tmp in (select * from tmp_cmdprodmat) loop
      if Nvl(v_tmp.codcmdprodmat, 0) &gt; 0 then
        --insert into xxx(xxx) values (&apos;+&apos;);
        update cmdprodmat set
          codcomanda1   = v_tmp.codcomanda1,
          codobiect     = v_tmp.codobiect,
          cant          = v_tmp.cant,
          pret          = v_tmp.pret,
          rest          = v_tmp.rest,
          tip           = v_tmp.tip,
          D1            = v_tmp.d1,
          D2            = v_tmp.d2,
          D3            = v_tmp.d3,
          IndexLocal    = v_tmp.IndexLocal,
          Reziduu       = v_tmp.reziduu,
          CodProdMat    = v_tmp.CodProdMat,
          ParitateEchiv = v_tmp.ParitateEchiv,
          TipEchiv      = v_tmp.TipEchiv,
          ccant         = v_tmp.ccant,
          cumsec        = v_tmp.cumsec,
          codcmdprodman = v_tmp.codcmdprodman,
          cantum1       = v_tmp.cantum1,
          umsec         = v_tmp.umsec,
          codcomanda3   = v_tmp.codcomanda3
        WHERE codcmdprodmat = v_tmp.codcmdprodmat and tip = v_tmp.tip;
      else
        --insert into xxx(xxx) values (&apos;-&apos;);
        select seq_cmdprodmat_codcmdprodmat.nextval into vCodMat from dual;
        insert into cmdprodmat
        (codcmdprodmat, codcomanda1, codobiect, cant, pret, rest,
         tip, d1, d2, d3, indexlocal, reziduu, Codprodmat,
         paritateechiv, tipechiv, ccant, cumsec, codcmdprodman,cantum1,umsec,codcomanda3)
         values
        (vCodMat, v_tmp.codcomanda1, v_tmp.codobiect, v_tmp.cant, v_tmp.pret, v_tmp.rest,
         v_tmp.tip, v_tmp.d1, v_tmp.d2, v_tmp.d3, v_tmp.indexlocal, v_tmp.reziduu, v_tmp.CodProdMat,
         v_tmp.paritateechiv, v_tmp.tipechiv, v_tmp.ccant, v_tmp.cumsec, v_tmp.codcmdprodman, v_tmp.cantum1,
         v_tmp.umsec,v_tmp.codcomanda3);
      end if;
    end loop;

    end if;
  end if;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

-- COMENZI CARE PRIN TMP_CMDLIVRLINK sting/storneaza alte comen
  UPDATE COMANDA1 C1
  SET
   C1.RESTACCEPTAT = C1.CANTACCEPTAT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  CMDLIVRLINK IL
                  LEFT OUTER JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                  LEFT OUTER JOIN COMANDA  II ON II.CODCOMANDA   = II1.CODCOMANDA
                 WHERE
                 IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                 ) -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IESLINK IL
                  LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                WHERE
                  IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
               ) -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                WHERE
                  IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
               )

  WHERE
  C1.CODCOMANDA1 IN
  (SELECT CODLINIECOMANDA FROM TMP_CMDLIVRLINK UNION SELECT CODLINIECOMANDA  FROM TMP_CMDLIVRLINK_INITIAL);

  UPDATE PACHETEOBJ POBJ
  SET
   REST = CANT -
          (SELECT NVL(SUM(PL.CANT), 0)
           FROM
            PACHETELINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          ) -
          (SELECT NVL(SUM(PL.CANT), 0)
           FROM
            PACHETEDLLINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          )
  WHERE
   EXISTS
   (
   SELECT UU.CODPACHETEOBJ FROM
   (SELECT CODPACHETEOBJ FROM TMP_PACHETEDLLINK UNION SELECT CODPACHETEOBJ FROM TMP_PACHETEDLLINK_INITIAL) UU
   WHERE
    UU.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
   );

  IF TIPCOMANDA = 53 THEN

    for v_rec in (select codcomanda1 from comanda1 where codcomanda = RecId) loop
      begin
        SELECT
          c1.codcomanda1 into aCodLinieCli
        FROM cmdlink l
             inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1
             inner join comanda c on c1.codcomanda = c.codcomanda
        where c.tipdoc = 18
        START WITH l.codcomanda1 = v_Rec.CodComanda1
        CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1;
      exception when others then
        aCodLinieCli := 0;
      end;

      if aCodLinieCli &gt; 0 then
        UPDATE COMANDA1 C1
        SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(cc1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 cc1 on l.codcomanda1 = cc1.codcomanda1
                             inner join comanda cc on cc1.codcomanda = cc.codcomanda
                        where cc1.CodObiect = C1.CodObiect
                        and cc.tipdoc = 53 AND cC.OPERAT = 1 AND cC.ANULAT = 0
                        START WITH l.codliniecomanda = aCodLinieCli
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )
        WHERE
        C1.CODCOMANDA1 = aCodLinieCli;
      END IF;
    END LOOP;

    for v_rec in (select cs1.codcomanda1, cs.tipdoc
                  from comanda1 c1
                       inner join cmdlink link on link.codcomanda1 = c1.codcomanda1
                       inner join comanda1 cs1 on link.codliniecomanda = cs1.codcomanda1
                       inner join comanda cs on cs1.codcomanda = cs.codcomanda
                  where c1.codcomanda = RecId and c1.CodObiect = cs1.CodObiect) loop
      if v_Rec.TipDoc &lt;&gt; 18 then
        UPDATE COMANDA1 C1
        SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(cc1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 cc1 on l.codcomanda1 = cc1.codcomanda1
                             inner join comanda cc on cc1.codcomanda = cc.codcomanda
                        where cc1.CodObiect = C1.CodObiect
                        and cc.tipdoc = 53 AND cC.OPERAT = 1 AND cC.ANULAT = 0
                        START WITH l.codliniecomanda = v_rec.codcomanda1
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )
        WHERE
        C1.CODCOMANDA1 = v_rec.codcomanda1;
      END IF;
    END LOOP;
  ELSE
    if tipcomanda = 18 then
      for v_rec in (select codcomanda1,CodObiect from comanda1 where codcomanda = recid) loop
        UPDATE COMANDA1 C1
          SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(cc1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 cc1 on l.codcomanda1 = cc1.codcomanda1
                             inner join comanda cc on cc1.codcomanda = cc.codcomanda
                        where cc1.CodObiect = C1.CodObiect
                        and cc.tipdoc = 53 AND cC.OPERAT = 1 AND cC.ANULAT = 0
                        START WITH l.codliniecomanda = v_rec.codcomanda1
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )
          WHERE
          C1.CODCOMANDA1 = v_rec.codcomanda1;
      end loop;
    else
      if tipcomanda = 92 then
        UPDATE COMANDA1 C1
        SET
         C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                     ( SELECT NVL(SUM(I1.CANT), 0)
                       FROM
                        IESIRI1 I1
                        INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
                        INNER JOIN IESLINK L ON L.CODIES1 = I1.CODIES1
                       WHERE
                       I.OPERAT = 1 AND I.ANULAT = 0 AND L.CODLINIECOMANDA = C1.CODCOMANDA1
                       AND I.TIPDOC = 24
                       )
        WHERE
        C1.CODCOMANDA1 IN
        (SELECT CODCOMANDA1 FROM COMANDA1 where codcomanda = recid and modinchidere = 2);
      else
        UPDATE COMANDA1 C1
        SET
         C1.RESTLANSAT = C1.CANTACCEPTAT -
                     ( SELECT NVL(SUM(IL.CANT), 0)
                       FROM
                        CMDLINK IL
                        LEFT OUTER JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                        LEFT OUTER JOIN COMANDA  II ON II.CODCOMANDA   = II1.CODCOMANDA
                       WHERE
                       IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND C1.CodObiect = II1.CodObiect AND II.OPERAT = 1 AND II.ANULAT = 0
                       )
        WHERE
        C1.CODCOMANDA1 IN
        (SELECT CODCOMANDA1 FROM COMANDA1 where codcomanda = recid);

        UPDATE PRECOMANDA1 C1
        SET
         C1.REST = C1.CANT -
                     ( SELECT NVL(SUM(IL.CANT), 0)
                       FROM
                        PRECMDLINK IL
                        INNER JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                        INNER JOIN COMANDA  II ON II.CODCOMANDA   = II1.CODCOMANDA
                       WHERE
                       IL.CODPRECOMANDA1 = C1.CODPRECOMANDA1 AND II.OPERAT = 1 AND II.ANULAT = 0
                       )
        WHERE
        C1.CODPRECOMANDA1 IN
        (SELECT CODPRECOMANDA1 FROM TMP_PRECMDLINK UNION ALL SELECT CODPRECOMANDA1 FROM TMP_PRECMDLINK_INITIAL);
      end if;
    end if;
  END IF;

  IF TIPCOMANDA = 53 THEN
    FOR V_REC IN (SELECT CMD.CODCMDPRODMAT
                  FROM CMDPRODMAT CMD
                       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = CMD.CODCOMANDA1
                  WHERE C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 where codcomanda = recid)
                        AND ((C1.Consum = 1 AND CMD.TIP = 1) OR (CMD.TIP &lt;&gt; 2 AND C1.Consum = 2)) )
                  LOOP

      UPDATE CMDPRODMAT MAT SET
      REST = CANT - (SELECT NVL(SUM(LINK.CANT), 0)
                     FROM IESPRODLINK LINK
                          INNER JOIN IESIRI1 I1 ON LINK.CODIES1 = I1.CODIES1
                          INNER JOIN IESIRI I ON I1.CODIES = I.CODIES
                     WHERE LINK.CODCMDPRODMAT = MAT.CODCMDPRODMAT AND I.ANULAT = 0)
      WHERE MAT.CODCMDPRODMAT = V_REC.CODCMDPRODMAT;

    END LOOP;

    FOR V_REC IN (SELECT CMD.CODCMDPRODMAT
                  FROM CMDPRODMAT CMD
                       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = CMD.CODCOMANDA1
                  WHERE C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM COMANDA1 where codcomanda = recid)
                        AND ((CMD.TIP = 2 AND C1.Consum = 2) OR (CMD.Tip &lt;&gt; 1 AND C1.Consum = 1)) )
                  LOOP

      UPDATE CMDPRODMAT MAT SET
      REST = CANT - (SELECT NVL(SUM(LINK.CANT), 0)
                     FROM INTRPRODLINK LINK
                          INNER JOIN INTRARI1 I1 ON LINK.CODINTR1 = I1.CODINTR1
                          INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR
                     WHERE LINK.CODLINIECOMANDA = MAT.CODCMDPRODMAT AND PKG_IESIRI.CONDITIE_FACTURA_OPERATA(I.OPERAT, CONSTOPERAT) = 1 AND I.ANULAT = 0)
      WHERE MAT.CODCMDPRODMAT = V_REC.CODCMDPRODMAT;

    END LOOP;

    for v_rec in (select cmd.codcmdprodman
                  from cmdprodman cmd
                       inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
                  where c1.codcomanda = recid ) loop

      update cmdprodman man set
      rest = cant - (select nvl(sum(link.cant), 0)
                     from manprodlink link
                          inner join raportp2 r2 on r2.codraportp2 = link.codraportp2
                          inner join raportp1 r1 on r1.codraportp1 = r2.codraportp1
                          inner join raportp r on r.codraportp = r1.codraportp
                     where link.codcmdprodman = v_rec.codcmdprodman)
      where man.codcmdprodman = v_rec.codcmdprodman;

    end loop;
  END IF;

  IF aDISPLIVRARE = 1 THEN
    MUTA_REZERVARI_IN_EXT;
    MUTA_REZERVARI_OUT_EXT;
  END IF;

  IF TIPCOMANDA = 65 THEN
    PUNE_REZERVARI_STORNO;
    SCADE_REZERVARI_STORNO;
  END IF;

  -- ACTUALIZARE REZERVARESTOC
  FOR V_REC IN (SELECT L1.CODIES1, NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC, NVL(L1.CODNIRSER,0)  AS CODNIRSER, L1.CANT, L1.PARITATE, L1.CODLOCATIE
                FROM TMP_LIVR1_INITIAL L1
                     INNER JOIN TMP_LIVR1 T1 ON
                     L1.CODIES1           = T1.CODIES1
                     AND L1.CODNIRSTOC        = T1.CODNIRSTOC
                     AND NVL(L1.CODNIRSER, 0) = T1.CODNIRSER
                     AND NVL(L1.CODLOCATIE,0) = NVL(T1.CODLOCATIE,0)
                WHERE NVL(L1.OBS, &apos;?&apos;) &lt;&gt; &apos;*&apos;
               )
  LOOP
    UPDATE REZERVATS
    SET REST = NVL(REST, 0) - V_REC.CANT * V_REC.PARITATE
    WHERE CODCOMANDA1       = V_REC.CODIES1
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
      AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
  END LOOP;


  FOR V_REC IN (SELECT L1.CODIES1, NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC, NVL(L1.CODNIRSER,0)  AS CODNIRSER, L1.CANT, L1.PARITATE, L1.CODLOCATIE FROM TMP_LIVR1 L1 WHERE NVL(OBS, &apos;?&apos;) &lt;&gt; &apos;*&apos;)
  LOOP
    UPDATE REZERVATS
    SET REST = NVL(REST, 0) + V_REC.CANT * V_REC.PARITATE
    WHERE CODCOMANDA1       = V_REC.CODIES1
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
      AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
  END LOOP;

  -- ACTUALIZARE REZERVARESTOC MATERIALE
  FOR V_REC IN ( SELECT L1.CODLINIECOMANDA, NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC, NVL(L1.CODNIRSER,0) AS CODNIRSER, L1.CANT, L1.PARITATE, L1.CODLOCATIE FROM TMP_LIVR1_MAT_INITIAL L1 inner join TMP_LIVR1_MAT T ON T.CODLIVR1 = L1.CODLIVR1 )
  LOOP
    UPDATE REZERVATS
    SET REST = NVL(REST, 0) - V_REC.CANT * V_REC.PARITATE
    WHERE CODCOMANDA1       = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
      AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
  END LOOP;

  FOR V_REC IN (SELECT L1.CODLINIECOMANDA, NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC, NVL(L1.CODNIRSER,0) AS CODNIRSER, L1.CANT, L1.PARITATE, L1.CODLOCATIE FROM TMP_LIVR1_MAT L1 inner join TMP_LIVR1_MAT_INITIAL T ON T.CODLIVR1 = L1.CODLIVR1)
  LOOP
    UPDATE REZERVATS
    SET REST = NVL(REST, 0) + V_REC.CANT * V_REC.PARITATE
    WHERE CODCOMANDA1       = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
      AND NVL(CODCOMANDA1F,0) = NVL(V_REC.CODLOCATIE,0);
  END LOOP;

  -- stergeri de rezervari MATERIALE
  FOR V_REC IN (SELECT * FROM TMP_LIVR1_MAT_INITIAL)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_LIVR1_MAT L1
    WHERE
      L1.CODLINIECOMANDA       = V_REC.CODLINIECOMANDA
      AND NVL(L1.CODNIRSTOC,0) = V_REC.CODNIRSTOC
      AND NVL(L1.CODNIRSER,0)   = V_REC.CODNIRSER
      AND NVL(L1.CODLOCATIE,0) = NVL(V_REC.CODLOCATIE,0);

    IF NR = 0 THEN
      DELETE FROM REZERVATS RS WHERE RS.CODREZERVATS = V_REC.CODLIVR1;
    END IF;
  END LOOP;

  --IF TIPCOMANDA IN (8, 18) THEN
  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;

  DELETE FROM Nodechiv NE WHERE exists (
  SELECT C1.CODComanda1 FROM COMANDA1 C1 where NE.CodComanda1 = C1.Codcomanda1 and codcomanda = recid);
  INSERT INTO NODECHIV ( CODCOMANDA1, CODPROIECTNOD, CODOBIECT, PARITATE, D1, D2, D3, TIP, cantum1)
                        ( SELECT CODCOMANDA1, CODPROIECTNOD, CODOBIECT, PARITATE, D1, D2, D3, TIP, cantum1 FROM TMP_NODECHIV);

  -- anularea si neoperarea sterge rezervarile
  if aOperat &lt;&gt; 1 or aAnulat = 1 then
    delete rezervats r where exists (select c1.codcomanda1 from comanda1 c1 where c1.codcomanda = ReciD and C1.CODCOMANDA1 = r.codcomanda1);
  end if;
  -- inchiderea sterge rezervarile exluzand comenzile preluate in monetare via emulare
  if aInchisa = 1 then
    for v_rec in (
      select c1.codcomanda1
      from comanda1 c1
        left join emulare1 e1 on e1.codcomanda1 = c1.codcomanda1
        left join emulare e on e1.codemulare = e.codemulare
      where c1.codcomanda = RecId
        and nvl(e.Preluat,0) = 0
    ) loop
      delete rezervats r where r.codcomanda1 = v_rec.codcomanda1;
      for v_link in (select l.codliniecomanda
                     from comanda1 c1
                          inner join comanda c on c.codcomanda = c1.codcomanda
                          inner join cmdlivrlink l on c1.codcomanda1 = l.codcomanda1
                          inner join comanda1 cc1 on l.codliniecomanda = cc1.codcomanda1
                          inner join comanda cc on cc.codcomanda = cc1.codcomanda
                     where c1.codcomanda1 = v_rec.codcomanda1 and c.tipdoc = 18 and c.displivrare = 1
                           and cc.tipdoc = 18 and coalesce(cc.displivrare,0) = 0) loop
        delete rezervats where codcomanda1 = v_link.codliniecomanda;
      end loop;
    end loop;
    if TipComanda = 8 then
      delete rezervats r
      where exists (select c1.codcomanda1 from comanda1 c1 where r.codcomanda1f = c1.codcomanda1 and c1.codcomanda = recid)
      and nvl(r.codnirstoc,0) = 0 and r.rest &lt;&gt; 0;
    end if;
  end if;

  if TipComanda = 53 and pkg_categconst.GetValConstanta(&apos;GenComanda1Et&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
    BagaInComanda1et(RecId);
  end if;
  IF tipcomanda = 94 then
    --e de schimbare de gestiune exploatare:1
    select Predat, TipRezervare, DataPred into aPredat, aTipRezervare, aData from TMP_RAC_REZ;
    aStatus := 0;
    BEGIN
      Select CodNParcG, Nvl(CodGestIni,0), Nvl(CodGest,0), NVL(Status,0)
      into   aCurCode,  aCodGestIni,       aCodGest,       aStatus
      from NParcG where CodCmd = RECID;
    EXCEPTION
      WHEN Others THEN
        aCurCode    := 0;
    END;
    if aOperat = 1 AND aMIJLTRANSP &gt; 0 AND aPredat = 1 and aTipTranzactie = 1 and aTipRezervare = 7 then
      Select CodGestDest  into aCodGest from TMP_RAC_REZ;
      if aCurCode = 0 then
        Select Inactiv  into aStatus from NParcAut where CodNparcAut = aMIJLTRANSP;
        insert into NPARCG (CODNPARCG, CODNPARCAUT, CODGEST, CODCMD, Status, Data)
                    Values (seq_NPARCG_CodNParcG.Nextval, aMIJLTRANSP, aCodGest, RecID, aStatus, aData);
        update NPARCAUT set CODGEST = aCodGest where CodNParcAut = aMIJLTRANSP;
      else
        Select Max(CodNParcG) into aMaxCode from NParcG where CodNParcAut = aMIJLTRANSP;
        update NParcG set CodGest = aCodGest, Data = aData where CodNParcG = aCurCode;
        if aCurCode = aMaxCode then
          update NPARCAUT set CODGEST = aCodGest where CodNParcAut = aMIJLTRANSP;
        end if;
      end if;
    else
      if aCurCode &gt; 0 then
        Delete NParcG where CODNPARCG = aCurCode;
        Select Max(CodNParcG) into aMaxCode from NParcG where CodNParcAut = MijlocTransportIni;
        Select CodGest  into aCodGestIni from NParcG where CodNParcG = aMaxCode;
        update NPARCAUT set CODGEST = aCodGestINI where CodNParcAut = MijlocTransportIni;
      end if;
    end if;
  end if;
  IF tipcomanda = 94 AND aOperat = 1 AND aPredat = 1 AND aMIJLTRANSP &gt; 0 THEN
    IF MijlocTransportIni &lt;&gt; aMijlTransp THEN
      DELETE FROM NPARC3 WHERE CODCMD IN  ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID);
      DELETE NPARC0 WHERE CODCMD = RecID;
    END IF;
    BEGIN
      SELECT KmIn, CombIn, nvl(CodInterventie,0) INTO aKmIn, aCombIn, aInterventie FROM TMP_RAC_REZ;
    EXCEPTION
      WHEN Others THEN
        aInterventie := 0;
        aCombIn      := 0;
        aKmIn        := 0;
    END;
    for vx in (Select CodInterventie, CodComanda2 from TMP_Comanda2 where Nvl(CodInterventie,0) &gt; 0) loop
      aInterventie := vx.CodInterventie;
      SELECT Nvl(PERDURATA,0),Nvl(PERKM,0),Nvl(ATENTIONAREZILE,0),Nvl(ATENTIONAREKM,0),Nvl(ACCIDENTALA,0)
      INTO   aPERDURATA,aPERKM,aATENTIONAREZILE,aATENTIONAREKM,aACCIDENTALA
      FROM ninterventiiauto
      WHERE CODINTERVENTIIAUTO = aINTERVENTIE;
      BEGIN
        SELECT CODNPARC3 INTO aCod FROM NPARC3 WHERE CODCMD = vx.CodComanda2;
      EXCEPTION WHEN others THEN
        aCod := 0;
      END;
      if aPERDURATA + aPERKM = 0 then aAccidentala := 1; end if;
      IF aAccidentala = 1 THEN
        if aCod &gt; 0 then Delete NParc3 where CODNPARC3 = aCod; end if;
      ELSE
        if aCod &gt; 0 then
          update NPARC3 set
            CodCMD     = vx.CodComanda2 ,
            Interventie= aInterventie,
            Valoare    = aValoare,
            KMU        = aKMin,
            DataU      = aData
          where CODNPARC3 = aCod;
        ELSE
          aCod := seq_NPARC3_CodNParc3.Nextval;
          insert into NPARC3 (
            CODNPARC3   ,
            COD         ,
            CodCMD      ,
            Interventie ,
            Valoare     ,
            KMU         ,
            DataU
            )
          Values(
            aCod,
            aMIJLTRANSP  ,
            vx.CodComanda2 ,
            aInterventie ,
            aValoare     ,
            aKMin        ,
            aData);
        end if;
        aValoare := null;
        aValoare1 := null;
        if aPERKM &gt; 0 then
           if aATENTIONAREKM &gt; 0 then aValoare1 := aKMin   + aPERKM - aATENTIONAREKM; end if;
           aValoare := aKMin   + aPERKM;
        end if;
        update NPARC3 set
          KMA        = aValoare1,
          DataA      = aData + aPERDURATA - aATENTIONAREZILE,
          KMV        = aValoare,
          DataV      = aData + aPERDURATA
        where CODNPARC3 = aCod;
      end if;
    end loop;
    if aKmIn &gt; 0 then
      BEGIN
        SELECT CODNPARC0 INTO aCod FROM NPARC0 WHERE CODCMD = RecID;
      EXCEPTION WHEN OTHERS THEN
        aCod := 0;
      END;
      IF aCod &gt; 0 THEN
        UPDATE NPARC0
        SET CodCMD   = RecID ,
            DATABORD = aData,
            KMBORD   = aKmIn,
            COMB     = aCombIn,
            AN       = aAn,
            LUNA     = aLuna,
            OBS      = aDoc
        WHERE CODNPARC0 = aCod;
      ELSE
        INSERT INTO NPARC0 (CODNPARC0, CODNPARCAUT, CodCMD, DATABORD, KMBORD, COMB, AN, LUNA, OBS)
        Values( seq_NPARC0_CodNParc0.Nextval, aMIJLTRANSP, RecID, aData, aKmIn, aCombIn, aAn, aLuna, aDoc );
      END IF;
    end if;
  elsif tipcomanda = 92 AND aOperat = 1 AND aMIJLTRANSP &gt; 0 THEN
    IF MijlocTransportIni &lt;&gt; aMijlTransp THEN
      DELETE NPARC0 WHERE CODCMD = RecID;
    END IF;
    BEGIN
      SELECT KmBord, NIVREZERVOR INTO aKmIn, aCombIn FROM Tmp_Nparcsa;
    EXCEPTION
      WHEN Others THEN
        aCombIn      := 0;
        aKmIn        := 0;
    END;
    if aKmIn &gt; 0 then
      BEGIN
        SELECT CODNPARC0 INTO aCod FROM NPARC0 WHERE CODCMD = RecID;
      EXCEPTION WHEN OTHERS THEN
        aCod := 0;
      END;
      IF aCod &gt; 0 THEN
        UPDATE NPARC0
        SET CodCMD   = RecID ,
            DATABORD = aDataDoc,
            KMBORD   = aKmIn,
            COMB     = aCombIn,
            AN       = aAn,
            LUNA     = aLuna,
            OBS      = aDoc
        WHERE CODNPARC0 = aCod;
      ELSE
        INSERT INTO NPARC0 (CODNPARC0, CODNPARCAUT, CodCMD, DATABORD, KMBORD, COMB, AN, LUNA, OBS)
        Values( seq_NPARC0_CodNParc0.Nextval, aMIJLTRANSP, RecID, aDataDoc, aKmIn, aCombIn, aAn, aLuna, aDoc );
      END IF;
    end if;
  else
    DELETE FROM NPARC3 WHERE CODCMD IN  ( SELECT CODCOmanda2 FROM COMANDA2 WHERE CODCOMANDA = RECID);
    delete NPARC0 where CODCMD = RecID;
  end if;

  IF tipcomanda = 92 THEN
    FOR V_REC IN (SELECT A.CLASA, C1.CODCOMANDA, SUM(COALESCE(L.VALOARE,0)) FACTURAT
                  FROM COMANDA1 C1
                       INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                       INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
                       INNER JOIN FACTSALINK L ON L.CODCOMANDA = C1.CODCOMANDA AND L.CODCLASEA = A.CLASA
                   WHERE C1.CODCOMANDA = RECID
                   GROUP BY A.CLASA, C1.CODCOMANDA
                 ) LOOP
      UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                            WHERE C1.CODOBIECT = O.CODOBIECT
                                                                  AND O.CODARTICOL = A.CODARTICOL
                                                                  AND A.CLASA = V_REC.CLASA
                                                                  AND A.TIPARTICOL = &apos;0&apos;
                                                           )
                                                    AND C1.CODCOMANDA = V_REC.CODCOMANDA AND C1.MODINCHIDERE = 2;
      UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                            WHERE C1.CODOBIECT = O.CODOBIECT
                                                                  AND O.CODARTICOL = A.CODARTICOL
                                                                  AND A.CLASA = V_REC.CLASA
                                                                  AND A.TIPARTICOL = &apos;1&apos;
                                                           )
                                                    AND C1.CODCOMANDA = V_REC.CODCOMANDA AND COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT;
      IF V_REC.FACTURAT &gt;= 0 THEN
        AVALOARE := V_REC.FACTURAT;
        FOR V_TMP IN (SELECT C1.CODCOMANDA1, C1.CANTACCEPTAT*C1.PU VALOARE
                      FROM COMANDA1 C1
                           INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                           INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
                      WHERE C1.CODCOMANDA = V_REC.CODCOMANDA AND A.CLASA = V_REC.CLASA
                            AND ((C1.MODINCHIDERE = 2 AND A.TIPARTICOL = &apos;0&apos;) OR (COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT AND A.TIPARTICOL = &apos;1&apos;))
                     ) LOOP
          IF AVALOARE &lt; V_TMP.VALOARE THEN
            UPDATE COMANDA1 SET CANTRETURNAT = AVALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
            AVALOARE := 0;
          ELSE
            UPDATE COMANDA1 SET CANTRETURNAT = V_TMP.VALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
            AVALOARE := AVALOARE - V_TMP.VALOARE;
          END IF;
          IF AVALOARE &lt;= 0 THEN EXIT; END IF;
        END LOOP;
      END IF;
    END LOOP;
  END IF;


/*  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDC&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDC WHERE CODCOMANDA =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDC SET CODCOMANDC = SEQ_COMANDC_CODCOMANDC.NEXTVAL  WHERE CODCOMANDC &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDC SET CODCOMANDA = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDC SELECT * FROM TMP_COMANDC &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDRAC&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDRAC WHERE CODCOMANDA =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDRAC SET CODCOMANDRAC = SEQ_COMANDRAC_CODCOMANDRAC.NEXTVAL  WHERE CODCOMANDRAC &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDRAC SET CODCOMANDA = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDRAC SELECT * FROM TMP_COMANDRAC &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDL&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDL WHERE CODCOMANDA =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDL SET CODCOMANDL = SEQ_COMANDL_CODCOMANDL.NEXTVAL  WHERE CODCOMANDL &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDL SET CODCOMANDA = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDL SELECT * FROM TMP_COMANDL &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDC1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDC1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDC1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1_INITIAL)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDC1 SET CODCOMANDC1 = SEQ_COMANDC1_CODCOMANDC1.NEXTVAL  WHERE CODCOMANDC1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDC1 SELECT * FROM TMP_COMANDC1 &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDL1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDL1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDL1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1_INITIAL)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDL1 SET CODCOMANDL1 = SEQ_COMANDL1_CODCOMANDL1.NEXTVAL  WHERE CODCOMANDL1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDL1 SELECT * FROM TMP_COMANDL1 &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDRAC1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDRAC1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDRAC1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1_INITIAL)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDRAC1 SET CODCOMANDRAC1 = SEQ_COMANDRAC1_CODCOMANDRAC1.NEXTVAL  WHERE CODCOMANDRAC1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDRAC1 SELECT * FROM TMP_COMANDRAC1 &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDI1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDI1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDI1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1_INITIAL)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDI1 SET CODCOMANDI1 = SEQ_COMANDI1_CODCOMANDI1.NEXTVAL  WHERE CODCOMANDI1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDI1 SELECT * FROM TMP_COMANDI1 &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_COMANDF1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM COMANDF1 WHERE CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1_INITIAL)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_COMANDF1 SET CODCOMANDF1 = SEQ_COMANDF1_CODCOMANDF1.NEXTVAL  WHERE CODCOMANDF1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO COMANDF1 SELECT * FROM TMP_COMANDF1&apos;;
  END IF;*/

  if PrelRezAut &gt; 0 and tipcomanda = 53 and pkg_categconst.GetValConstanta(&apos;CmdPPrelRezCmdC&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
    for v_rez in (select r.codobiect, r.rest, r.codrezervats, c1.codcomanda1, r.umsec, l.codliniecomanda codcomanda1c,
                         r.codnirstoc, nvl(r.codnirser,0) codnirser, mat.codcmdprodmat, mat.rest restmat
                  from comanda1 c1
                       inner join cmdlink l on c1.codcomanda1 = l.codcomanda1
                       inner join rezervats r on r.codcomanda1 = l.codliniecomanda
                       inner join cmdprodmat mat on mat.codcomanda1 = c1.codcomanda1 and mat.tip = 1
                  where c1.codcomanda = RECID and r.rest &gt; 0 and r.codobiect = mat.codobiect and r.codnirstoc &gt; 0
                  ) loop
      select coalesce(rest,0) into aCantRezCli from rezervats where codrezervats = v_rez.codrezervats;
      select count(*) into aCount
      from rezervats r
      where r.codcomanda1 = v_rez.codcomanda1 and r.codcmdprodmat = v_Rez.codcmdprodmat
            and r.codnirstoc = v_rez.codnirstoc and nvl(r.codnirser,0) = v_rez.codnirser;

      aCantRez := 0;
      begin
        select coalesce(sum(coalesce(r.rest,0)),0) into aCantRez
        from rezervats r
        where r.codcomanda1 = v_rez.codcomanda1 and r.codcmdprodmat = v_rez.codcmdprodmat
              and r.codnirstoc &gt; 0;
      exception when others then aCantRez := 0;
      end;

      if v_rez.restmat &gt; aCantRez then
        if aCount = 1 then
          if aCantRezCli &gt; v_rez.restmat - aCantRez then
            update rezervats r set rest = rest + v_rez.restmat - aCantRez
            where r.codcomanda1 = v_rez.codcomanda1 and r.codcmdprodmat = v_Rez.codcmdprodmat
                  and r.codnirstoc = v_rez.codnirstoc and nvl(r.codnirser,0) = v_rez.codnirser;
            update rezervats set rest = rest - (v_rez.restmat - aCantRez)
            where codrezervats = v_rez.codrezervats;
          else
            update rezervats r set rest = rest + aCantRezCli
            where r.codcomanda1 = v_rez.codcomanda1 and r.codcmdprodmat = v_Rez.codcmdprodmat
                  and r.codnirstoc = v_rez.codnirstoc and nvl(r.codnirser,0) = v_rez.codnirser;
            update rezervats set rest = 0
            where codrezervats = v_rez.codrezervats;
          end if;
        else if aCount = 0 then
          if aCantRezCli &gt; v_rez.restmat - aCantRez then
            insert into rezervats(codrezervats,codcomanda1,codnirstoc,codnirser,rest,umsec,codcmdprodmat,rezervatini)
            values (seq_rezervats_codrezervats.nextval,v_rez.codcomanda1,v_rez.codnirstoc,v_rez.codnirser,v_rez.restmat - aCantRez,v_rez.umsec,v_rez.codcmdprodmat,v_rez.restmat - aCantRez);
            update rezervats set rest = rest - (v_rez.restmat - aCantRez)
            where codrezervats = v_rez.codrezervats;
          else
            insert into rezervats(codrezervats,codcomanda1,codnirstoc,codnirser,rest,umsec,codcmdprodmat,rezervatini)
            values (seq_rezervats_codrezervats.nextval,v_rez.codcomanda1,v_rez.codnirstoc,v_rez.codnirser,aCantRezCli,v_rez.umsec,v_rez.codcmdprodmat,aCantRezCli);
            update rezervats set rest = 0
            where codrezervats = v_rez.codrezervats;
          end if;
        end if; end if;
      end if;
    end loop;
  end if;

  if ModifTerm = 1 and Operation = 0 and tipcomanda = 18 then
    for v_rec in (
      select l1.codcmd1 , m.val
      from lansare0 l0, lansare1 l1, tmp_manevra3 m
      where m.codunic = l0.codcmd1 and
            l1.codlansare = l0.codlansare
    ) loop
      update comanda1 set termen = termen + v_rec.val where codcomanda1 = v_rec.codcmd1;
    end loop;
  end if;

  PKG_CFGTABLES.EXT_POSTRECORDS(aTipPtExt, Operation);
  if DoCommit then
    COMMIT;
  end if;
  NotifyModif(Operation, RecId, &apos;COMANDA&apos;);
  if DoCommit then
    COMMIT;
  end if;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

procedure RescrieComanda1et is
vsql varchar2(500);
begin
  execute immediate &apos;drop SEQUENCE SEQ_COMANDA1ET_CODCOMANDA1ET&apos;;
  execute immediate &apos;create sequence SEQ_COMANDA1ET_CODCOMANDA1ET
            minvalue 1
            maxvalue 9999999999999999999999999999
            start with 101
            increment by 1
            nocache&apos;;
  delete comanda1et;

  for v_cmd in (select codcomanda from comanda where tipdoc = 53) loop
    pkg_comanda.BagaInComanda1et(v_cmd.codcomanda);
  end loop;
  commit;
end;

procedure BagaInComanda1et(RecId in number) is
vCodLaPartener varchar2(5);
vNrCli varchar2(5);
vCodObiect varchar2(6);
vIndexLocal varchar2(3);
begin
  for v_rec in (select c.nrdoc, c.datadoc, nvl(p.codintern,&apos;00000&apos;) codintern, to_char(nvl(cc.nrdoc,0)) nrcli,
                       to_char(c1.codobiect) codobiect, nvl(at1.codextern,&apos;000&apos;) coda1, nvl(at2.codextern,&apos;000&apos;) coda2, nvl(at3.codextern,&apos;000&apos;) coda3,
                       nvl(maxcolet.idx_maxim,0) idx_maxim,
                       c1.codcomanda1, to_char(cc1.indexlocal) indexlocal
                from comanda1 c1
                     inner join comanda c on c1.codcomanda = c.codcomanda
                     inner join nartobj obj on c1.codobiect = obj.codobiect
                     inner join nart art on art.codarticol = obj.codarticol
                     left join comanda1 cc1 on cc1.codcomanda1 = pkg_comanda.DinCmdCli(c1.codcomanda1)
                     left join comanda cc on cc1.codcomanda = cc.codcomanda
                     left join npart p on cc.partener = p.codpart
                     left join natrobj a1 on a1.codobiect = obj.codobiect and a1.indexlocal = 1
                     left join natrib1 at1 on a1.codvalatr = at1.codvalatr
                     left join natrobj a2 on a2.codobiect = obj.codobiect and a2.indexlocal = 2
                     left join natrib1 at2 on a2.codvalatr = at2.codvalatr
                     left join natrobj a3 on a3.codobiect = obj.codobiect and a3.indexlocal = 3
                     left join natrib1 at3 on a3.codvalatr = at3.codvalatr
                     left join (select max(indexlocal) idx_maxim, codobiect from nartobjcolet group by codobiect) maxcolet on maxcolet.codobiect = obj.codobiect
                where c1.codcomanda = RecId) loop
    if Length(v_rec.Codintern) = 5 then
      vCodLaPartener := v_rec.Codintern;
    else
      if Length(v_rec.Codintern) &lt; 5 then
        vCodLaPartener := LPAD(v_rec.Codintern, 5, &apos;0&apos;);
      else
        vCodLaPartener := SubStr(v_rec.codintern, 1, 5);
      end if;
    end if;

    if Length(v_rec.NrCli) = 5 then
      vNrCli := v_rec.NrCli;
    else
      if Length(v_rec.NrCli) &lt; 5 then
        vNrCli := LPAD(v_rec.NrCli, 5, &apos;0&apos;);
      else
        vNrCli := SubStr(v_rec.NrCli, 1, 5);
      end if;
    end if;

    if Length(v_rec.CodObiect) = 6 then
      vCodobiect := v_rec.Codobiect;
    else
      if Length(v_rec.Codobiect) &lt; 6 then
        vCodobiect := LPAD(v_rec.Codobiect, 6, &apos;0&apos;);
      else
        vCodobiect := SubStr(v_rec.Codobiect, 1, 6);
      end if;
    end if;

    if Length(v_rec.indexlocal) = 3 then
      vindexlocal := v_rec.indexlocal;
    else
      if Length(v_rec.indexlocal) &lt; 3 then
        vindexlocal := LPAD(v_rec.indexlocal, 3, &apos;0&apos;);
      else
        vindexlocal := SubStr(v_rec.indexlocal, 1, 3);
      end if;
    end if;

    if v_rec.idx_maxim &gt; 0 then
      for v_tmp in 1..v_rec.idx_maxim loop
        insert into comanda1et(codcomanda1et, codcomanda1, nrdoc, datadoc, codcolet)
        values (seq_comanda1et_codcomanda1et.nextval, v_rec.codcomanda1, v_rec.nrdoc, v_rec.datadoc,
                vCodLaPartener||vNrCli||vCodObiect||v_tmp||&apos;/&apos;||v_rec.idx_maxim||vindexlocal);
      end loop;
    else
      insert into comanda1et(codcomanda1et, codcomanda1, nrdoc, datadoc, codcolet)
      values (seq_comanda1et_codcomanda1et.nextval, v_rec.codcomanda1, v_rec.nrdoc, v_rec.datadoc,
              vCodLaPartener||vNrCli||vCodObiect||&apos;1/1&apos;||vindexlocal);
    end if;
  end loop;
end;

procedure GetInfoStocPeMat(pCodGest IN NUMBER DEFAULT 0) is
aStoc number(20,7);
aRezTot number(20,7);
vCodGest number(20);
begin
  vCodGest := coalesce(pCodGest,0);
  for v_rec in (select tmp.codcmdprodmat, tmp.codobiect, c.subunitatea
                from tmp_cmdprodmat tmp
                     inner join comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                     inner join comanda c on c.codcomanda = c1.codcomanda
                ) loop
    begin
      SELECT nvl(SUM(NS.REST),0) into aStoc
      FROM NIRSTOC NS
           INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
           INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST  AND (vCodGest = 0 OR NG.CODGEST = vCodGest)
           LEFT JOIN TMP_GESTDEDICATE TG ON TG.CODGEST = NIR.GEST
           LEFT OUTER JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART
      WHERE NS.REST &gt; 0 AND IOA.MG &lt;&gt; 5 AND NG.CODSUBUNIT = v_rec.subunitatea and ns.codobiect = v_rec.codobiect
            AND ( (vCodGest = 0 AND TG.CODGEST IS NOT NULL) OR (vCodGest &lt;&gt; 0) );
    exception when others  then aStoc := 0;
    end;
    begin
      SELECT nvl(SUM(R.REST),0) into aRezTot
      FROM REZERVATS R
           INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
           INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
           INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST  AND (vCodGest = 0 OR NG.CODGEST = vCodGest)
           LEFT JOIN TMP_GESTDEDICATE TG ON TG.CODGEST = NIR.GEST
      WHERE NS.CODOBIECT = v_rec.codobiect AND NG.CODSUBUNIT = v_rec.subunitatea
            AND ( (vCodGest = 0 AND TG.CODGEST IS NOT NULL) OR (vCodGest &lt;&gt; 0) );
    exception when others  then aRezTot := 0;
    end;
    update tmp_cmdprodmat set
      stoc = nvl(aStoc,0),
      AlteRezervari = nvl(aRezTot,0) - nvl(Rezervat,0),
      NecesarCalc = case when nvl(aStoc,0) - (nvl(aRezTot,0) - nvl(Rezervat,0)) - nvl(necesar,0) &gt; 0 then 0 else - (nvl(aStoc,0) - (nvl(aRezTot,0) - nvl(Rezervat,0)) - nvl(necesar,0)) end
    where codcmdprodmat = v_rec.codcmdprodmat;
  end loop;
  commit;
end;

procedure InchideComanda(aCodComanda in number) is pragma autonomous_transaction;
Tmp NUMBER(20);
begin
  SELECT CodComanda INTO Tmp FROM COMANDA WHERE CodComanda = aCodComanda FOR UPDATE NOWAIT;
  update Comanda set inchisa = 1 where codcomanda = acodcomanda;
  commit;
end;

function UpdateTermenComanda(aCodComanda1 in number, aTermen in varchar2) return number is
aCodComanda number(20);
aRez number(1);
begin
  aRez := 1;
  begin
    select codcomanda into aCodComanda from comanda1 where codcomanda1 = aCodComanda1;
  exception when others then aRez := 0;
  end;
  if aRez = 0 then return 0; end if;

  begin
    pkg_comanda.SP_LOCKRECORD(aCodComanda);
  exception when others then aRez := 0;
  end;
  if aRez = 0 then return 0; end if;

  begin
    update comanda1 set termen = to_date(aTermen, &apos;dd.mm.yyyy&apos;) where codcomanda1 = aCodComanda1;
    commit;
  exception when others then aRez := 0;
  end;

  return aRez;
end;

procedure CORECTIE_REZ_SA(acodcomanda1 in number, acant in number) is
acantrezt number(20,7);
acantrezi number(20,7);
adif number(20,7);
begin
  begin
    select nvl(sum(r.rest),0) into acantrezt
    from transf1 t1
         inner join transf t on t.codtransf = t1.codtransf
         inner join nir on nir.codtransf = t.codtransf
         inner join nirstoc ns on ns.codnir = nir.codnir and t1.codtransf1 = ns.codtransf1
         inner join rezervats r on ns.codnirstoc = r.codnirstoc
    where t1.codcomanda1 = acodcomanda1 and r.codcomanda1 = acodcomanda1 and t.operat = 1 and t.anulat = 0;
  exception when others then
    acantrezt := 0;
  end;
  begin
    select nvl(sum(r.rest),0) into acantrezi
    from rezervats r
    where r.codcomanda1 = acodcomanda1;
  exception when others then
    acantrezi := 0;
  end;
  acantrezi := acantrezi - acantrezt;
  adif := acant;
  if acantrezi = 0 then return; end if;
  if aCant &lt;= aCantRezi then
    for v_rec in (select r.codrezervats, r.rest
                  from rezervats r
                  where r.codcomanda1 = acodcomanda1 and not exists
                  (
                   select rr.codrezervats
                   from transf1 t1
                        inner join transf t on t.codtransf = t1.codtransf
                        inner join nir on nir.codtransf = t.codtransf
                        inner join nirstoc ns on ns.codnir = nir.codnir and t1.codtransf1 = ns.codtransf1
                        inner join rezervats rr on ns.codnirstoc = rr.codnirstoc
                   where t1.codcomanda1 = acodcomanda1 and rr.codcomanda1 = acodcomanda1 and t.operat = 1 and t.anulat = 0
                         and r.codrezervats = rr.codrezervats
                  )
                  ) loop
      if v_rec.rest &lt;= adif then
        delete rezervats where codrezervats = v_rec.codrezervats;
        adif := adif - v_rec.rest;
      else
        update rezervats set rest = rest - adif where codrezervats = v_rec.codrezervats;
        adif := 0;
      end if;
      if adif &lt;= 0 then Exit; end if;
    end loop;
  else
    for v_rec in (select r.codrezervats, r.rest
                  from rezervats r
                  where r.codcomanda1 = acodcomanda1
                  order by r.codrezervats
                  ) loop
      if v_rec.rest &lt;= adif then
        delete rezervats where codrezervats = v_rec.codrezervats;
        adif := adif - v_rec.rest;
      else
        update rezervats set rest = rest - adif where codrezervats = v_rec.codrezervats;
        adif := 0;
      end if;
      if adif &lt;= 0 then Exit; end if;
    end loop;
  end if;
  delete rezervats where codcomanda1 = acodcomanda1 and rest &lt;= 0;
end;

PROCEDURE Set_PrelRezAut(aPrelRezAut IN NUMBER) IS
BEGIN
  PrelRezAut := aPrelRezAut;
END;

PROCEDURE ValidSetConst   (pAn  NUMBER, pLuna NUMBER) IS
BEGIN
  xValidAn             := pAn;
  xValidLuna           := pLuna;
  xValidAL             := pAn*12+pLuna;
  xValidBancaSitV      := 0;
  xValidMonedaSitV     := 0;
  xValidMonedaAdaosMin := 0;
  xValidAdaosOrMarja   := 0;

  BEGIN xValidBancaSitV      := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,      pAn, pLuna); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN xValidMonedaSitV     := pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;,     pAn, pLuna); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN xValidMonedaAdaosMin := pkg_categconst.GetValConstanta(&apos;MonedaAdaosMin&apos;, pAn, pLuna); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN xValidAdaosOrMarja   := pkg_categconst.GetValConstanta(&apos;AdaosOrMarja&apos;,   pAn, pLuna); EXCEPTION WHEN OTHERS THEN NULL; END;
  BEGIN xValidAdaosValPret   := pkg_categconst.GetValConstanta(&apos;AdaosValPret&apos;,   pAn, pLuna); EXCEPTION WHEN OTHERS THEN NULL; END;
END;

FUNCTION ValidAdaosMinim (pCodComanda1 NUMBER) RETURN INTEGER IS
  vRESULT        INTEGER := 1;
  PRETV          NUMBER := 0;
  PUVV           NUMBER := 0;
  PUAV           NUMBER := 0;
  Adaos          NUMBER := 0;
  CursBanca      NUMBER := 1;
  CursDoc        NUMBER := 1;
  CursTransf     NUMBER := 1;
  PMin           NUMBER := 0;
  PUVV_min       VARCHAR2(20);
  MonedaAdaosMin NUMBER;
  MonedaDoc      NUMBER;
  vCodObiect     NUMBER;
  vAn            NUMBER;
  vLuna          NUMBER;
BEGIN
  SELECT C1.PU, C.Moneda,  C.Curs,  PKG_LIST_BASE_UTILS.GETCURSREFERINTA(xValidMonedaSitV, xValidBancaSitV, C.DataDoc), Coalesce(o.AdaosExceptie, 0), o.CodObiect
  INTO   PRETV, MonedaDoc, CursDoc, CursBanca                                                                         , PMin                        , vCodObiect
  FROM comanda1 c1
    LEFT JOIN comanda c ON c.codcomanda = c1.codcomanda
    LEFT JOIN nartobj o ON o.codobiect  = c1.codobiect
  WHERE CodComanda1 = pCodComanda1;

  IF PMin &lt;&gt; 0 THEN
    IF CursBanca = 0 THEN CursBanca  := 1; END IF;
    IF CursDoc   = 0 THEN CursDoc    := 1; END IF;
    CursTransf  := CursBanca;

    -- PretVanzare
    IF    MonedaDoc = 0 AND xValidMonedaAdaosMin = 2 THEN PUVV := PretV;
    ELSIF MonedaDoc = 0                              THEN PUVV := PretV / CursTransf;
    ELSIF                   xValidMonedaAdaosMin = 2 THEN PUVV := PretV * CursDoc;
    ELSE                                                  PUVV := PretV * CursDoc / CursBanca;
    END IF;

    -- PretAchiz, CodObiect etc.
    IF xValidAdaosValPret = 1 THEN
      SELECT PretReferinta INTO PUAV FROM NartObj1 WHERE CodObiect = vCodObiect AND xValidAL BETWEEN ALStart AND ALStop;
    ELSE
      SELECT
        CASE
          WHEN Sum(R.REST) = 0 THEN 0
          ELSE Sum(R.REST * (NS.PRET - COALESCE(NS.ADAOS,0))) / Sum(R.REST)
        END
      INTO PUAV
      FROM REZERVATS R
        LEFT JOIN COMANDA1 C1   ON C1.CODCOMANDA1 = R.CODCOMANDA1
        LEFT JOIN COMANDA  C    ON C.CODCOMANDA   = C1.CODCOMANDA
        LEFT JOIN NIRSTOC  NS   ON NS.CODNIRSTOC  = R.CODNIRSTOC AND NS.CODOBIECT = C1.CODOBIECT
        LEFT JOIN NIR      N    ON N.CODNIR       = NS.CODNIR
        LEFT JOIN IOART1   IOAL ON IOAL.CODIOART  = NS.CODIOART  AND C.AN*12+C.LUNA BETWEEN IOAL.ALStart AND IOAL.ALStop
      WHERE R.CODCOMANDA1 = pCodComanda1;
    END IF;

    -- Calcul Adaos
    IF    xValidAdaosOrMarja = 2 AND PUVV = 0 THEN Adaos := 0;
    ELSIF xValidAdaosOrMarja = 2              THEN Adaos := (1 - (PUAV / PUVV)) * 100;
    ELSIF                            PUAV = 0 THEN Adaos := 0;
    ELSE                                           Adaos := ((PUVV / PUAV) - 1) * 100;
    END IF;

--INSERT INTO x (test) VALUES (&apos;PretV -&gt; &apos;||PretV||&apos; / Adaos -&gt; &apos;||Adaos||&apos; / vCodObiect -&gt; &apos;||vCodObiect||&apos; / PUAV -&gt; &apos;||PUAV||&apos; / PUVV -&gt; &apos;||PUVV);

    -- Verificare depa¿ire adaos
    IF Adaos &lt; PMin THEN -- adaos invalid
      vRESULT := 0;
    END IF;
  END IF;

  RETURN vRESULT;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

END pkg_COMANDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_COMPARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>558821FA6B9D7A61FA0017DDDD243C7C1D771619</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_COMPARE IS

FUNCTION COMPARE(aCODJOB IN NUMBER) RETURN NUMBER
IS
aNr number := 0;
Count1 number := 0;
Count2 number := 0;
SQL1 varchar2(800);
SQL2 varchar2(800);
Insert1 varchar2(200);
Insert2 varchar2(200);
aCod number(20);
FirstCod number(20);
Zec number(20);
Err1 varchar2(20) := &apos;Err.Master&apos;;
Err2 varchar2(20) := &apos;Err.Slave&apos;;
Rez varchar2(20);

BEGIN
  delete TMP_JOBCORELREZ;
  delete JOBCORELREZ where CODCOREL in (Select CodCOREL from JOBCOREL where CODJOB = aCodJob);
  Insert1 := &apos;insert into TMP_Compare1(IDENTIFICATOR, Valoare) &apos;;
  Insert2 := &apos;insert into TMP_Compare2(IDENTIFICATOR, Valoare) &apos;;
  for v_rec in (select * from Jobcorel where CodJob = aCodJob) 
  loop
    zec := Nvl(V_REC.ZECIMALE, 0);
    if Zec &lt; 0 then Zec := 0; end if;
    if Zec &gt; 7 then Zec := 7; end if;
    aNr    := 0;
    Count1 := 0;
    Count2 := 0;

    delete TMP_Compare1;
    delete TMP_Compare2;
    if NVL(V_REC.LOOKUPFIELD11, &apos;?&apos;) = &apos;?&apos; then 
      SQL1 := Insert1||&apos;(select Trim(&apos;||V_REC.LOOKUPFIELD1||&apos;), Sum(&apos;||V_REC.VALDESCRIP1||&apos;) from &apos;||V_REC.Tabla1||&apos; group by &apos;||V_REC.LOOKUPFIELD1||&apos;)&apos;;
    else
      SQL1 := Insert1||&apos;(Select Trim(S)||&apos;||&apos;+&apos;||&apos;Trim(SS), SUMA FROM
                        (select &apos;||V_REC.LOOKUPFIELD1||&apos; S, &apos;||V_REC.LOOKUPFIELD11||&apos; SS, Sum(&apos;||V_REC.VALDESCRIP1||&apos;) SUMA from &apos;||V_REC.Tabla1||&apos; group by &apos;||V_REC.LOOKUPFIELD1||&apos;,&apos;||V_REC.LOOKUPFIELD11||&apos;))&apos;;
    end if;
    
    if NVL(V_REC.LOOKUPFIELD21, &apos;?&apos;) = &apos;?&apos; then 
      SQL2 := Insert2||&apos;(select Trim(&apos;||V_REC.LOOKUPFIELD2||&apos;), Sum(&apos;||V_REC.VALDESCRIP2||&apos;) from &apos;||V_REC.Tabla2||&apos; group by &apos;||V_REC.LOOKUPFIELD2||&apos;)&apos;;
    else
      SQL2 := Insert2||&apos;(Select Trim(S)||&apos;||&apos;+&apos;||&apos;Trim(SS), SUMA FROM
                        (select &apos;||V_REC.LOOKUPFIELD2||&apos; S, &apos;||V_REC.LOOKUPFIELD21||&apos; SS, Sum(&apos;||V_REC.VALDESCRIP2||&apos;) SUMA from &apos;||V_REC.Tabla2||&apos; group by &apos;||V_REC.LOOKUPFIELD2||&apos;,&apos;||V_REC.LOOKUPFIELD21||&apos;))&apos;;
    end if;
    select SEQ_JOBCORELREZ_CODCORELREZ.Nextval into FirstCod from dual; 

    BEGIN
      EXECUTE IMMEDIATE SQL1; 
      Select Count(*) into Count1 from TMP_Compare1;
      EXCEPTION WHEN OTHERS THEN aNR := 1;
    END;  
    if aNr = 0 then 
      BEGIN
        EXECUTE IMMEDIATE SQL2; 
        Select Count(*) into Count2 from TMP_Compare2;
        EXCEPTION WHEN OTHERS THEN aNR := 2;
      END;  
      if aNr = 0 AND Count1 &gt; 0 AND Count2 &gt; 0
      then 
/*
        INSERT INTO TMP_COMPARE1 (IDENTIFICATOR)
        (
        SELECT C2.IDENTIFICATOR FROM TMP_COMPARE2 C2
        WHERE
        NOT EXISTS (SELECT IDENTIFICATOR FROM TMP_COMPARE1 C1 WHERE C1.IDENTIFICATOR = C2.IDENTIFICATOR)
        );
*/    
        insert into JOBCORELREZ
          (CodCorelREZ, CodCorel, IDENTIFICATOR, Valoare1, Valoare2)
          (select SEQ_JOBCORELREZ_CODCORELREZ.Nextval,
                  V_REC.CodCorel,
                  C1.IDENTIFICATOR,
                  NVL(C1.Valoare, 0),
                  NVL(C2.Valoare, 0)
             from TMP_Compare1 C1
            left join TMP_Compare2 C2 on C1.IDENTIFICATOR = C2.IDENTIFICATOR
            where ROUND(NVL(C1.Valoare, 0) - NVL(C2.Valoare, 0), Zec) &lt;&gt; 0);
      end if;
    end if;
    if aNr = 0 then 
      if Count1 = 0 then 
        aNr := 3; 
        if Count2 = 0 then 
          Rez := &apos;Master &amp; Slave ZERO!&apos;;
        else
          Rez := &apos;Master ZERO!&apos;;
        end if; 
      else
        if Count2 = 0 then 
          Rez := &apos;Slave ZERO!&apos;;
          aNr := 3; 
        else
          Rez := &apos;DONE...&apos;;
          Select Count(*) into aNr from JOBCORELREZ where CodCorel = V_REC.CodCorel;
          if aNr &lt;&gt; 0 then aNr := 9; end if;
        end if; 
      end if; 
    else 
      if aNr = 1 then Rez := Err1; else Rez := Err2; end if;
    end if;
    insert into JOBCORELREZ (CodCorelREZ, CodCorel, IDENTIFICATOR) VALUES (FirstCod, V_REC.CodCorel, Rez);
    update JOBCOREL set STARE = aNR where CodCorel = V_REC.CodCorel;
  end loop;
 
  COMMIT;

  RETURN aNr;
END;

procedure debug is
n number;
begin
  n := Compare(288);
end;

end PKG_COMPARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_COMPENSARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>314B0DDCCECE08C9ED548619CE35446447FA958D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_COMPENSARI IS

CT_MONITOR constant varchar2(50) := &apos;MON_16&apos;;



PROCEDURE UPDATE_VALTRANZ_STINGERI(RECID IN NUMBER)
IS 
 BANCASITV   NUMBER(20) := 0;
 MONEDASITV  NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO BANCASITV  FROM DUAL;
    EXCEPTION WHEN OTHERS THEN BANCASITV := 0;
  END;  

  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO MONEDASITV FROM DUAL;
    EXCEPTION WHEN OTHERS THEN MONEDASITV := 0;
  END;  



  -- Volum tranzactii CLIENT
  FOR V_REC IN
  (
  SELECT 
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM 
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   IESIRI I
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC = 28
    AND G_STG.CODDOC = RECID
    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 200
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODIES
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZC = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE; 
  END LOOP;  

-- Volum tranzactii FURNIZORI
-- INTRARI
  FOR V_REC IN
  (
  SELECT 
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM 
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   INTRARI I
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC = 28
    AND G_STG.CODDOC = RECID
    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 100
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODINTR
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE; 
  END LOOP;  
  
  -- stingeri de DVI-uri
  FOR V_REC IN
  (
  SELECT 
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(D.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM 
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   DVI D
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC = 28
    AND G_STG.CODDOC    = RECID
    AND S.CODSTINSPIF   = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 130
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = 5
    AND GSTINS.CODDOC = D.CODDVI
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE; 
  END LOOP;  
  


END;


FUNCTION GET_INFO_FACTURA_LITIGIU(aCODOBLIGSTINGATOR IN NUMBER) RETURN VARCHAR2
IS
  aINFO VARCHAR2(100) := &apos;&apos;;
  aROOT NUMBER(20) := 0;
  aCODSTINS NUMBER(20) := 0;
BEGIN
   BEGIN 
      SELECT 
        S.CODSTINSPIF,
        M.SIMBOL || GETCURSLINIESTINSA(G.MONEDA, G.CURS) 
        INTO 
          aCODSTINS,
         aINFO                           
       FROM 
        STINGERE S,
        OBLIGPIF O,
        GENERAL G,
        COMPENS C,
        NMONEDE M
       WHERE
        S.CODSTINGATORPIF = aCODOBLIGSTINGATOR
        AND O.CODOBLIGPIF = S.CODSTINSPIF
        AND G.CODGENERAL = O.CODGENERAL
        AND C.CODCOMPENS = G.CODDOC
        AND M.CODMONEDA = NVL(G.MONEDA, 0);

        SELECT 
          I.PREFIXDOC || I.NRDOC || &apos;/&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || aINFO 
         INTO aINFO
        FROM 
        (
          SELECT
            OB.CODOBLIGPIF
          FROM OBLIGPIF  OB
            WHERE CONNECT_BY_ISLEAF = 1   
          START WITH CODOBLIGPIF = aCODSTINS
          CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
        ) O,
          OBLIGPIF F, 
          GENERAL GF, 
          IESIRI I 
        WHERE 
        F.CODOBLIGPIF = O.CODOBLIGPIF
        AND  GF.CODGENERAL = F.CODGENERAL
        AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC;
        
     EXCEPTION WHEN OTHERS THEN RETURN &apos;&apos;;   
        
   END;

   RETURN aINFO;
END;

FUNCTION GET_DATA_FACTURA_LITIGIU(aCODOBLIGSTINGATOR IN NUMBER) RETURN DATE
IS
  aINFO     DATE;
  aROOT     NUMBER(20) := 0;
  aCODSTINS NUMBER(20) := 0;
BEGIN
   BEGIN 
      SELECT 
        S.CODSTINSPIF
        INTO 
          aCODSTINS
       FROM 
        STINGERE S,
        OBLIGPIF O,
        GENERAL G,
        COMPENS C,
        NMONEDE M
       WHERE
        S.CODSTINGATORPIF = aCODOBLIGSTINGATOR
        AND O.CODOBLIGPIF = S.CODSTINSPIF
        AND G.CODGENERAL = O.CODGENERAL
        AND C.CODCOMPENS = G.CODDOC
        AND M.CODMONEDA = NVL(G.MONEDA, 0);

        SELECT 
           I.DATADOC INTO aINFO 
        FROM 
        (
          SELECT
            OB.CODOBLIGPIF
          FROM OBLIGPIF  OB
            WHERE CONNECT_BY_ISLEAF = 1   
          START WITH CODOBLIGPIF = aCODSTINS
          CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
        ) O,
          OBLIGPIF F, 
          GENERAL GF, 
          IESIRI I 
        WHERE 
          F.CODOBLIGPIF = O.CODOBLIGPIF
          AND  GF.CODGENERAL = F.CODGENERAL
          AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC;
        
     EXCEPTION WHEN OTHERS THEN RETURN &apos;&apos;;   
        
   END;

   RETURN aINFO;
END;




PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := aCARNET;
  NRDOC_I     := aNRDOC;
END;


FUNCTION SEMNCOMPENS(SEMNIFICATIE IN NUMBER, ICONT IN NUMBER ) RETURN NUMBER
IS
SEMN NUMBER (2) := 1;
BEGIN
  IF SEMNIFICATIE IN (1301, 1351) THEN
    SELECT 
      CASE
        WHEN SEMNIFICATIE = 1301 AND ICONT IN (2, 5, 8, 9, 15) THEN -1 
        WHEN SEMNIFICATIE = 1351 AND ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14, 18) THEN -1 
      ELSE 1 
    END INTO SEMN FROM DUAL;
  END IF;
  RETURN SEMN;  
END;



/*
FUNCTION GETCURSLINIEOBLIG(aCODGENERAL IN NUMBER) RETURN VARCHAR2
IS
aMONEDA NUMBER(20);
CURSTRANZ NUMBER(20, 7) := 1;

BEGIN
  BEGIN
    SELECT MONEDA, CURS INTO aMONEDA, CURSTRANZ FROM TMP_GENERAL WHERE CODGENERAL = aCODGENERAL;
    EXCEPTION WHEN OTHERS THEN RETURN &apos;&apos;; 
  END;
  IF aMONEDA = 0 THEN RETURN &apos;&apos;;
  ELSE
    RETURN &apos;/&apos; || CURSTRANZ;
  END IF;
END;
*/

FUNCTION GETCURSLINIESTINSA(aMONEDA IN NUMBER, aCURS IN NUMBER) RETURN VARCHAR2
IS
BEGIN
  IF aMONEDA = 0 THEN RETURN &apos;&apos;;
  ELSE
    RETURN &apos;/&apos; || TRANSLATE(aCURS, &apos;.&apos;, &apos;,&apos;);
  END IF;
END;




PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20); 
BEGIN 
  SELECT CODCOMPENS INTO Tmp FROM COMPENS 
  WHERE CODCOMPENS = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN 
  INSERT INTO TMP_COMPENS FIELDS( CODCOMPENS ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
aCARNETDOC NUMBER (20);
aNRDOC NUMBER (20);

 aCodSubunit NUMBER(20);
 aDataDoc DATE;
 aDoc varchar2(200);

BEGIN 
  PKG_GLOBALS.MarkDirtyJurnal;  
  SP_LOCKRECORD(RecId);
  SELECT CARNETDOC, NRDOC, SUBUNITATEA, DATADOC, &apos;PV&apos;||NRDOC||&apos;/&apos;||DATADOC INTO 
         aCARNETDOC, aNRDOC, aCodSubunit,aDataDoc,ADOC 
  FROM COMPENS WHERE CODCOMPENS = RecID;

 
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
  
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMPENS&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;
  
  DELETE TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF)
  (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN 
  (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 28 AND CODDOC = RecID)
  );

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF)
  SELECT CODSTINGERE, CODSTINSPIF FROM STINGERE WHERE CODSTINGATORPIF IN 
 (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF); 
  
-- ordinea de stergere trebuie pastrata pentru a nu viola un constraint
  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);  
  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF); 
  DELETE GENERAL WHERE TIPDOC = 28 AND CODDOC = RecID;
  DELETE FROM COMPENS WHERE CODCOMPENS = RecID;

  UPDATE OBLIGPIF O
  SET 
    REST =
      (
      CASE
        WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      END
      ),
    RESTTVA =
      (
        CASE
         WHEN VALOARE &gt;= 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0)  + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        END
       )
      
  WHERE 
    O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);  




  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 28) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV,
			RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
    WHERE 
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV,
			  RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			  RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS

      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV,
			RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS

    WHERE 
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV,
			  RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			  RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS

      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;
   
  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 28;  
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 28;   
	DELETE FROM TAXDECL WHERE CODDOC = RECID AND TIPDOC = 28;

  DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 28); 
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 28; 
	
  -- realoc numarul de document folosit
  PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);

  NotifyModif(2, RecId, &apos;COMPENS&apos;);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 I NUMBER(1) := 0;
 aDATADOC DATE;
 aCODSUBUNITSTINS  NUMBER (20) := 0;
 REGPROVIZ NUMBER(5) := 0;
 
BEGIN 
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  IF RECID &gt; 0 THEN
    
-- COMPENS
    INSERT INTO TMP_COMPENS (CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, 
                            VALDEBIT, VALCREDIT, SUBUNITATEA, CODGEST, CODCENTRU, AGENT,  TIPCOMPENS, UserID, CODANALIZA,  CodTipPartIncert, 
                            ExclusSAFT, Flags)
    SELECT CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, 
           0, 0, SUBUNITATEA, CODGEST, CODCENTRU, AGENT, TIPCOMPENS, UserID, CODANALIZA, CodTipPartIncert, 
           ExclusSAFT, Flags FROM COMPENS WHERE CODCOMPENS = RecID;
  
    BEGIN
      SELECT DATADOC INTO aDATADOC FROM TMP_COMPENS;
      EXCEPTION WHEN OTHERS THEN aDATADOC := TO_DATE(&apos;01.10.2000&apos;, &apos;dd.mm.yyyy&apos;);
    END;

--  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;));
    PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.LUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.ANLUCRU));
    


-- GENERAL
    INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
    SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG FROM GENERAL WHERE TIPDOC = 28 AND CODDOC = RecID;

    
    
-- OBLIGPIF    
-- pentru liniile ce reprezinta compensari pe DEBIT  folosesc ca temporar TMP_OBLIGPIF
-- pentru liniile ce reprezinta compensari pe CREDIT folosesc ca temporar TMP_OBLIGPIF_ASOCIAT

     INSERT INTO TMP_OBLIGPIF 
     (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION,CODCENTRU,CODANALIZANOD, DINCARETVA, TAXCODE) 
     SELECT * FROM
     (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, SEMNCOMPENS(O.SEMNIFICATIE, O.ICONT) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU, CODANALIZANOD, DINCARETVA, X.TaxCode
      FROM OBLIGPIF O 
      left join TAXDECL X on X.TipDoc = 28 and x.CodDoc = RecID and X.Coddoc1 = o.codobligpif
     WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL) AND SEMNIFICATIE IN (1300, 1301, 1302, 1303)
     )
     ORDER BY CODOBLIGPIF;
    

     INSERT INTO TMP_OBLIGPIF_ASOCIAT
     (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION, CODCENTRU,CODANALIZANOD, DINCARETVA, TAXCODE) 
     SELECT * FROM
      (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, SEMNCOMPENS(O.SEMNIFICATIE, O.ICONT) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU, CODANALIZANOD, DINCARETVA, x.TaxCode
     FROM OBLIGPIF O
     left join TAXDECL X on X.TipDoc = 28 and x.CodDoc = RecID and X.Coddoc1 = o.codobligpif
     WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL) AND SEMNIFICATIE IN (1350, 1351, 1352, 1353)
     )
     ORDER BY CODOBLIGPIF;
  
-- STINGERE       
-- pentru liniile ce reprezinta compensari pe DEBIT  folosesc TMP_STINGERE
-- pentru liniile ce reprezinta compensari pe CREDIT folosesc TMPSTINGERE_ASOCIAT
     INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
     (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));

     INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
     (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT));


       -- OBLIGPIF DEBIT
       BEGIN
         UPDATE TMP_OBLIGPIF OB 
         SET 
           SIMBOLCONT = 
              CASE 
                WHEN SEMNIFICATIE IN (1300, 1301, 1303) THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
                WHEN SEMNIFICATIE = 1302 THEN PKG_PLANCONTURI.GETSIMBOLCONT(OB.ICONT) 
              END,   
  
             CURS    = (SELECT DECODE(NVL(CURS, 0),
                                         0, 1,
                                         CURS
                                         )
                                         
                            FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),

             FARAREG    = (SELECT NVL(FARAREG, 0)
                           FROM 
                           TMP_GENERAL 
                             WHERE CODGENERAL = OB.CODGENERAL
                          ),
             TVA    = (SELECT NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),
  
  
             MONEDA       = NVL((SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
             SUMALEI      = CASE
                              WHEN OB.TIP = &apos;T&apos; THEN OB.DINCARETVA
                              ELSE ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6)
                            END ,
--             TVALEI       = ROUND((SELECT NVL(CURS, 1) * NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL) , 6),
             VALPROVIZION = ROUND(ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),
  
             CURSDOCSTINS = NVL(( SELECT NVL(GREG.CURS, G.CURS)  
                             FROM 
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                              LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),
  
             CURSISTORIC   = NVL(( SELECT G.CURS
                             FROM 
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),
  
             SEMNIFCODSTINS = NVL(( SELECT NVL(O.SEMNIFICATIE, 0)  
                             FROM 
                               STINGERE S 
                               LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0),

             DATADOC        = 
             ( CASE 
                 WHEN OB.SEMNIFICATIE = 1303 THEN 
                  (
                      SELECT
                          CASE
                           WHEN E.CODIES  IS NOT NULL THEN E.DATADOC
                           WHEN N.CODNC   IS NOT NULL THEN N.DATADOC
                          END AS X
                          FROM
                            OBLIGPIF O,
                            NMONEDE M,
                            GENERAL G
                            LEFT OUTER JOIN IESIRI  E ON E.TIPDOC = G.TIPDOC AND E.CODIES = G.CODDOC
                            LEFT OUTER JOIN NC1     N1 ON G.TIPDOC = 35 AND N1.CODNC1 = G.CODDOC
                            LEFT OUTER JOIN NC      N ON N1.CODNC = N.CODNC
                          WHERE
                           O.CODOBLIGPIF = OB.CODOBLIGASOCIAT
                           AND O.CODGENERAL = G.CODGENERAL
                           AND M.CODMONEDA = G.MONEDA
                )  
               -- PLATI INCASARI CU LEGATURA  
  
               /* PLATA FURN - FACTURI INTRARE*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN  (100, 110) 
                 THEN 
                 ( SELECT I.DATADOC 
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - DVI*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) = 130 
                 THEN 
                 ( SELECT D.DATADOC
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                     LEFT OUTER JOIN DVI D ON D.CODDVI    = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - FACTURI IESIRE IN ROSU*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (200, 210) 
                 THEN 
                 ( SELECT I.DATADOC
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN IESIRI I ON I.CODIES   = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - NOTE CONTABILE*/
                 WHEN OB.SEMNIFICATIE IN (1300) AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1200, 1201)
                 THEN 
                 ( SELECT N.DATADOC
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                     LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                     LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - OBLIGATII DIN ALTE COMPENSARI*/
                 WHEN OB.SEMNIFICATIE IN (1300) AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1301, 1351)
                 THEN 
                 ( SELECT C.DATADOC
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                     LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
                  
               /* PLATA* - INCASARE AVANS  */
               WHEN SEMNIFICATIE  = 1300 AND NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (410, 430)
               THEN 
               ( SELECT T.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF 
               )
                 ELSE NULL
               END),
             
/*             
                          ( CASE 
                              WHEN OB.SEMNIFICATIE = 1303 THEN 
                             (
                              SELECT
                                  CASE
                                   WHEN E.CODIES  IS NOT NULL THEN E.DATADOC
                                   WHEN N.CODNC   IS NOT NULL THEN N.DATADOC
                                  END AS X
                                  FROM
                                    OBLIGPIF O,
                                    GENERAL G
                                    LEFT OUTER JOIN IESIRI  E ON E.TIPDOC = G.TIPDOC AND E.CODIES = G.CODDOC
                                    LEFT OUTER JOIN NC1     N1 ON G.TIPDOC = 35 AND N1.CODNC1 = G.CODDOC
                                    LEFT OUTER JOIN NC      N ON N1.CODNC = N.CODNC
                                  WHERE
                                   O.CODOBLIGPIF = OB.CODOBLIGASOCIAT
                                   AND O.CODGENERAL = G.CODGENERAL
                             ) 
                             ELSE NULL
                            END),                 
*/
             
             DENDOCLEGATURA = 
             ( CASE 
  
               -- PLATI INCASARI FARA LEGATURA  
                 WHEN OB.SEMNIFICATIE = 1301 THEN &apos;Fara doc.legatura / &apos; || NVL((SELECT M.SIMBOL FROM NMONEDE M WHERE M.CODMONEDA = (SELECT MONEDA FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL)), &apos;lei&apos;)
                 WHEN OB.SEMNIFICATIE = 1302 THEN &apos;Direct pe cont / &apos;    || NVL((SELECT M.SIMBOL FROM NMONEDE M WHERE M.CODMONEDA = (SELECT MONEDA FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL)), &apos;lei&apos;)
                 WHEN OB.SEMNIFICATIE = 1303 THEN 
                 &apos;Litigiu &apos; || (
                                SELECT
                                    CASE
                                     WHEN E.CODIES  IS NOT NULL THEN E.PREFIXDOC || TO_CHAR(E.NRDOC) || &apos;/&apos; || TO_CHAR(E.DATADOC, &apos;DD.MM.YYYY&apos;) || &apos;/&apos; ||  M.SIMBOL
                                     WHEN N.CODNC   IS NOT NULL THEN &apos;NC&apos; || TO_CHAR(N.NRDOC) || &apos;/&apos; || TO_CHAR(N.DATADOC, &apos;DD.MM.YYYY&apos;) || &apos;/&apos; ||  M.SIMBOL
                                    END AS X
                                    FROM
                                      OBLIGPIF O,
                                      NMONEDE M,
                                      GENERAL G
                                      LEFT OUTER JOIN IESIRI  E ON E.TIPDOC = G.TIPDOC AND E.CODIES = G.CODDOC
                                      LEFT OUTER JOIN NC1     N1 ON G.TIPDOC = 35 AND N1.CODNC1 = G.CODDOC
                                      LEFT OUTER JOIN NC      N ON N1.CODNC = N.CODNC
                                    WHERE
                                     O.CODOBLIGPIF = OB.CODOBLIGASOCIAT
                                     AND O.CODGENERAL = G.CODGENERAL
                                     AND M.CODMONEDA = G.MONEDA
                                )  
               -- PLATI INCASARI CU LEGATURA  
  
               /* PLATA FURN - FACTURI INTRARE*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (100, 110) 
                 THEN 
                 ( SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, NVL(GREG.CURS, G.CURS))
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - DVI*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) = 130 
                 THEN 
                 ( SELECT &apos;DVOT&apos; || D.NRDOC || &apos;/&apos; || to_char(D.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, NVL(GREG.CURS, G.CURS))
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                     LEFT OUTER JOIN DVI D ON D.CODDVI    = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - FACTURI IESIRE IN ROSU*/
                 WHEN OB.SEMNIFICATIE  = 1300 AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS 
                      LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (200, 210) 
                 THEN 
                 ( SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS)
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN IESIRI I ON I.CODIES   = G.CODDOC
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - NOTE CONTABILE*/
                 WHEN OB.SEMNIFICATIE IN (1300) AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1200, 1201)
                 THEN 
                 ( SELECT &apos;NC&apos; || N.NRDOC || &apos;/&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, NVL(GREG.CURS, G.CURS))
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                     LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                     LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
               /* PLATA FURN - OBLIGATII DIN ALTE COMPENSARI*/
                 WHEN OB.SEMNIFICATIE IN (1300) AND 
                      NVL((SELECT OO.SEMNIFICATIE FROM 
                      STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                      WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1301, 1351)
                 THEN 
                 ( SELECT &apos;PV&apos; || C.NRDOC || &apos;/&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS)
                   FROM 
                     STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                     LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                     LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
                   WHERE
                     S.CODSTINGATORPIF = OB.CODOBLIGPIF
                  )
  
                  
               /* PLATA* - INCASARE AVANS  */
               WHEN SEMNIFICATIE  = 1300 AND NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (410, 430)
               THEN 
               ( SELECT T.DOC || T.NRDOC || &apos;/&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS)
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF 
               )
                  
                 ELSE &apos;???&apos;
               END
             );
          EXCEPTION WHEN OTHERS THEN I := 1;          
        END;  

      -- OBLIGPIF CREDIT
       UPDATE TMP_OBLIGPIF_ASOCIAT OB 
       SET 
         SIMBOLCONT = 
            CASE 
              WHEN SEMNIFICATIE IN (1350, 1351, 1303) THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
              WHEN SEMNIFICATIE = 1352 THEN PKG_PLANCONTURI.GETSIMBOLCONT(OB.ICONT) 
            END,   

           CURS   = (SELECT DECODE(NVL(CURS, 0),
                                       0, 1,
                                       CURS
                                       )
                                       
                          FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),



          FARAREG    = (SELECT NVL(FARAREG, 0)
                        FROM 
                        TMP_GENERAL 
                          WHERE CODGENERAL = OB.CODGENERAL
                       ),


           TVA    = (SELECT NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),


           MONEDA       = NVL((SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
--         SUMALEI      = ROUND(NVL((SELECT CURS  FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6),
           SUMALEI      = CASE
                            WHEN OB.TIP = &apos;T&apos; THEN OB.DINCARETVA
                            ELSE ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6)
                          END,
           VALPROVIZION = ROUND(ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),
--           TVALEI       = ROUND((SELECT NVL(CURS, 1) * NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL) , 6),
/*
           CURSDOCSTINS = NVL(( SELECT G.CURS 
                           FROM 
                             STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                             LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                           WHERE
                             S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0),
*/
             CURSDOCSTINS = NVL(( SELECT NVL(GREG.CURS, G.CURS)  
                             FROM 
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),

             CURSISTORIC = NVL(( SELECT G.CURS  
                             FROM 
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),

             SEMNIFCODSTINS = NVL(( SELECT NVL(O.SEMNIFICATIE, 0)  
                             FROM 
                               STINGERE S 
                               LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0),




           DATADOC = 
           ( CASE 

               WHEN OB.SEMNIFICATIE  = 1350 AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS 
                    LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (200, 210) 
               THEN 
               ( SELECT I.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                   LEFT OUTER JOIN IESIRI I ON I.CODIES      = G.CODDOC
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )

             /* INCASARE CLIENT - FACTURI INTRARE IN ROSU*/
               WHEN OB.SEMNIFICATIE  = 1350 AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS 
                    LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (100, 110) 
               THEN 
               ( SELECT I.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN INTRARI I ON I.CODINTR   = G.CODDOC
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )

                /* INCASARE CLIENT - OBLIGATII DIN NOTE CONTABILE*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1200, 1201)
               THEN 
               ( SELECT N.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                   LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )
                

                /* INCASARE CLIENT - OBLIGATII DIN ALTE COMPENSARI*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1301, 1351)
               THEN 
               ( SELECT C.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )

                /* STINGERE LITIGII*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1303)
               THEN 
               GET_DATA_FACTURA_LITIGIU(OB.CODOBLIGPIF)

               /* PLATA* - INCASARE AVANS  */
               WHEN SEMNIFICATIE  = 1350 AND NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (310, 330)
               THEN 
               ( SELECT T.DATADOC
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF 
               )
                
               ELSE NULL
             END
           ),


           DENDOCLEGATURA = 
           ( CASE 

             -- PLATI INCASARI FARA LEGATURA  
               WHEN OB.SEMNIFICATIE = 1351 THEN &apos;Fara doc.legatura / &apos; || NVL((SELECT M.SIMBOL FROM NMONEDE M WHERE M.CODMONEDA = (SELECT MONEDA FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL)), &apos;lei&apos;)
               WHEN OB.SEMNIFICATIE = 1352 THEN &apos;Direct pe cont / &apos;    || NVL((SELECT M.SIMBOL FROM NMONEDE M WHERE M.CODMONEDA = (SELECT MONEDA FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL)), &apos;lei&apos;)
             -- PLATI INCASARI CU LEGATURA  
             /* INCASARE CLIENT - FACTURI IESIRE*/
               WHEN OB.SEMNIFICATIE  = 1350 AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS 
                    LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (200, 210) 
               THEN 
               ( SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; ||  M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, NVL(GREG.CURS, G.CURS))
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                   LEFT OUTER JOIN IESIRI I ON I.CODIES      = G.CODDOC
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )

             /* INCASARE CLIENT - FACTURI INTRARE IN ROSU*/
               WHEN OB.SEMNIFICATIE  = 1350 AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS 
                    LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (100, 110) 
               THEN 
               ( SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS)
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN INTRARI I ON I.CODINTR   = G.CODDOC
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )

                /* INCASARE CLIENT - OBLIGATII DIN NOTE CONTABILE*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1200, 1201)
               THEN 
               ( SELECT &apos;NC&apos; || N.NRDOC || &apos;/&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, NVL(GREG.CURS, G.CURS))
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                   LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )
                
                /* INCASARE CLIENT - OBLIGATII DIN ALTE COMPENSARI*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1301, 1351)
               THEN 
               ( SELECT &apos;PV&apos; || C.NRDOC || &apos;/&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS)                 

                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF
                )


                /* STINGERE LITIGII*/
               WHEN OB.SEMNIFICATIE IN (1350) AND 
                    NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (1303)
               THEN 
               GET_INFO_FACTURA_LITIGIU(OB.CODOBLIGPIF)

               /* PLATA* - INCASARE AVANS  */
               WHEN SEMNIFICATIE  = 1350 AND NVL((SELECT OO.SEMNIFICATIE FROM 
                    STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                    WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) IN (310, 330, 410)
               THEN 
               ( SELECT T.DOC || T.NRDOC || &apos;/&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;/&apos; || M.SIMBOL || PKG_COMPENSARI.GETCURSLINIESTINSA(G.MONEDA, G.CURS) 
                 FROM 
                   STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                   LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL 
                   LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
                   LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
                 WHERE
                   S.CODSTINGATORPIF = OB.CODOBLIGPIF 
               )
                
               ELSE &apos;???&apos;
             END
           );
           

  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;RegProviz&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO REGPROVIZ  FROM DUAL;
    EXCEPTION WHEN OTHERS THEN REGPROVIZ := 2;
  END;  

  FOR V_REC IN (
    SELECT OB.* 
    FROM 
      TMP_OBLIGPIF_ASOCIAT OB,
      STINGERE S,
      OBLIGPIF O_STINS
    WHERE
      S.CODSTINGATORPIF = OB.CODOBLIGPIF
      AND S.CODSTINSPIF = O_STINS.CODOBLIGPIF
      AND O_STINS.SEMNIFICATIE = 1303
      ) 
    LOOP
      UPDATE TMP_OBLIGPIF_ASOCIAT 
      SET
        VALPROVIZION = CASE
                         WHEN REGPROVIZ = 1 THEN  ROUND(ROUND(NVL(V_REC.CURS, 1) * V_REC.VALOARE, 6) * V_REC.COEFPROVIZION, 6)
                         ELSE ROUND(ROUND(NVL(V_REC.CURSISTORIC, 1) * V_REC.VALOARE, 6) * V_REC.COEFPROVIZION, 6)                            
                       END  
      WHERE
        CODOBLIGPIF = V_REC.CODOBLIGPIF;  
    
    END LOOP;    




   UPDATE TMP_OBLIGPIF OB 
   SET 
     TVALEI       = ROUND((SELECT DECODE(NVL(OB.CURSDOCSTINS, 1), 0, 1, NVL(OB.CURSDOCSTINS, 1)) * NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL) , 6);


   FOR V_REC IN 
   (SELECT 
     O.CODOBLIGPIF, O_STINS.TERMEN
    FROM
      TMP_OBLIGPIF O,
      STINGERE S,
      OBLIGPIF O_STINS
    WHERE
      O.CODOBLIGPIF = S.CODSTINGATORPIF
      AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
    )
    LOOP
      UPDATE TMP_OBLIGPIF
      SET
        TERMEN = V_REC.TERMEN
      WHERE
        CODOBLIGPIF = V_REC.CODOBLIGPIF;  
    END LOOP;       
    
   FOR V_REC IN 
   (SELECT 
     O.CODOBLIGPIF, O_STINS.TERMEN
    FROM
      TMP_OBLIGPIF_ASOCIAT O,
      STINGERE S,
      OBLIGPIF O_STINS
    WHERE
      O.CODOBLIGPIF = S.CODSTINGATORPIF
      AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
    )
    LOOP
      UPDATE TMP_OBLIGPIF_ASOCIAT
      SET
        TERMEN = V_REC.TERMEN
      WHERE
        CODOBLIGPIF = V_REC.CODOBLIGPIF;  
    END LOOP;       


       

   UPDATE TMP_OBLIGPIF_ASOCIAT OB 
   SET 
     TVALEI       = ROUND((SELECT DECODE(NVL(OB.CURSDOCSTINS, 1), 0, 1, NVL(OB.CURSDOCSTINS, 1)) * NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL) , 6);


    UPDATE TMP_COMPENS SET
      VALDEBIT  = NVL((SELECT SUM(SUMALEI) FROM TMP_OBLIGPIF), 0),
      VALCREDIT = NVL((SELECT SUM(SUMALEI) FROM TMP_OBLIGPIF_ASOCIAT), 0);



   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 28 AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 28 AND CODDOC = RECID);

   DELETE TMP_RULAJ;



   FOR V_REC IN 
   (SELECT  
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM 
      TMP_STINGERE S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL  
   )LOOP
      aCODSUBUNITSTINS := 0;

      IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE             
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
          WHERE
            CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE 
      IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
          WHERE
            N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE 
      IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
          WHERE
            T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE 
      IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
          WHERE
            C.CODCOMPENS = V_REC.CODDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      END IF;  
      END IF;  
      END IF; 
      END IF; 
      END IF;           

      UPDATE TMP_STINGERE
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
    END LOOP;

   FOR V_REC IN 
   (SELECT  
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM 
      TMP_STINGERE_ASOCIAT S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL  
   )LOOP
      aCODSUBUNITSTINS := 0;

      IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE             
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
          WHERE
            CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE  
      IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
          WHERE
            N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE 
      IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
          WHERE
            T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      ELSE 
      IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
          WHERE
            C.CODCOMPENS = V_REC.CODDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;  
        END;   
      END IF;  
      END IF;  
      END IF; 
      END IF; 
      END IF;           

      UPDATE TMP_STINGERE_ASOCIAT
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
    END LOOP;




  -- memorez starea la intrare a stingerilor   
   DELETE TMP_STINGERE_INITIAL;
   INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE UNION SELECT * FROM TMP_STINGERE_ASOCIAT); 
  
  
   DELETE TMP_OBLIGPIF_INITIAL;
   INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF); 
   INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF_ASOCIAT); 
 
   
   
   COMMIT;
  END IF;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) 
IS
 vCOD      NUMBER(20);
 aCARNET   INTEGER := 0; 
 aNUMARDOC INTEGER := 0; 
 NR        INTEGER := 0; 

 aCodSubunit NUMBER(20);
 aDataDoc DATE;
 aDoc varchar2(200);
 TIPTERMEN VARCHAR2(10) := &apos;&apos;;

BEGIN

  SELECT CARNETDOC, NRDOC, SUBUNITATEA, DATADOC, &apos;PV&apos; || NRDOC || &apos;/&apos; || DATADOC
  INTO aCARNET, aNUMARDOC, aCodSubunit, aDataDoc, aDoc
  FROM TMP_COMPENS;
 
  if trunc(coalesce(adatadoc,to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;))) = to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;) then
    RAISE_APPLICATION_ERROR(-20997, &apos;Data eronata !&apos;);
    return;
  end if;

BEGIN
-- pe inregoistrarile care genereaza obligatii preiau centrul de cost din COMPENS

  UPDATE TMP_OBLIGPIF
  SET
   CODCENTRU = (SELECT CODCENTRU FROM TMP_COMPENS)
  WHERE 
    SEMNIFICATIE IN (1301, 1303, 1351); 
  
  UPDATE TMP_OBLIGPIF_ASOCIAT
  SET
   CODCENTRU = (SELECT CODCENTRU FROM TMP_COMPENS)
  WHERE 
    SEMNIFICATIE IN (1301, 1303, 1351); 

   TIPTERMEN :=  PKG_CATEGCONST.GetValConstanta(&apos;TermenCompens&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU); 
   IF TIPTERMEN = &apos;2&apos; THEN
     UPDATE TMP_OBLIGPIF_ASOCIAT
     SET
       TERMEN = (SELECT MAX(TERMEN) 
                 FROM 
                   TMP_STINGERE S,
                   OBLIGPIF OS
                 WHERE
                  S.CODSTINSPIF = OS.CODOBLIGPIF)
     WHERE
       SEMNIFICATIE = 1351;  


     UPDATE TMP_OBLIGPIF
     SET
       TERMEN = (SELECT MAX(TERMEN) 
                 FROM 
                   TMP_STINGERE_ASOCIAT S,
                   OBLIGPIF OS
                 WHERE
                  S.CODSTINSPIF = OS.CODOBLIGPIF)
     WHERE
       SEMNIFICATIE = 1301;  
   ELSE
     UPDATE TMP_OBLIGPIF 
     SET
       TERMEN = aDATADOC
     WHERE
       SEMNIFICATIE IN (1301, 1351) AND TERMEN is Null;  

     UPDATE TMP_OBLIGPIF_ASOCIAT 
     SET
       TERMEN = aDATADOC
     WHERE
       SEMNIFICATIE IN (1301, 1351) AND TERMEN is Null;  
   END IF;
  
  
  IF OPERATION = 0 THEN  -- UPDATE 
    SELECT CODCOMPENS INTO RecID FROM TMP_COMPENS;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    
     WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMPENS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
  END IF;

   -- sterg inregistrarile care au fost initial si acum nu mai exista; ORDINEA STERGERILOR E IMPORTANTA

    DELETE FROM STINGERE WHERE CODSTINGATORPIF IN 
    (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN 
     (SELECT CODGENERAL  FROM GENERAL  WHERE TIPDOC = 28 AND CODDOC = RecID) 
    )AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE UNION SELECT CODSTINGERE FROM TMP_STINGERE_ASOCIAT);

     
    DELETE FROM OBLIGPIF WHERE CODGENERAL IN 
    (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 28 AND CODDOC = RecID)AND
     CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF UNION SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT); 

    DELETE FROM GENERAL WHERE TIPDOC = 28 AND CODDOC = RecID AND CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

 -- COMPENS

    UPDATE COMPENS  
    SET 
    (DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, SUBUNITATEA, CODGEST, CODCENTRU, AGENT, TIPCOMPENS, CODANALIZA, CodTipPartIncert, 
     ExclusSAFT, Flags)
     = 
    (SELECT DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, SUBUNITATEA, CODGEST, CODCENTRU, AGENT, TIPCOMPENS, CODANALIZA, CodTipPartIncert, 
    ExclusSAFT,Flags  FROM TMP_COMPENS)
    WHERE CODCOMPENS = RecId ; 


    -- GENERAL
    FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
      IF v_rec.CODGENERAL &gt; 0  THEN 
        UPDATE GENERAL 
        SET
          TIPDOC       = v_rec.TIPDOC,
          CODDOC       = v_rec.CODDOC,
          MONEDA       = v_rec.MONEDA,
          CURS         = v_rec.CURS,
          TVA          = v_rec.TVA,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          FARAREG      = V_REC.FARAREG
        WHERE 
          CODGENERAL = v_rec.CODGENERAL;
      ELSE
        SELECT SEQ_GENERAL_CODGENERAL.NextVal INTO vCOD FROM DUAL;

        UPDATE TMP_OBLIGPIF O SET CODGENERAL = vCOD WHERE O.CODGENERAL = v_rec.CODGENERAL;

        UPDATE TMP_OBLIGPIF_ASOCIAT O SET CODGENERAL = vCOD WHERE O.CODGENERAL = v_rec.CODGENERAL;

        INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
        VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
      END IF; 
    END LOOP;



-- OBLIGPIF  -- DEBIT
     FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF) LOOP
       IF v_rec.CODOBLIGPIF &gt; 0  THEN
         UPDATE OBLIGPIF
         SET
           CODGENERAL         = v_rec.CODGENERAL,
           TERMEN             = v_rec.TERMEN,
           VALOARE            = SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, -- :1:2:3:4
           DINCARETVA         = SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * NVL(v_rec.DINCARETVA, 0),
           REST               = 

           CASE
             WHEN v_rec.SEMNIFICATIE IN (1300, 1302) THEN 0 -- linie care stinge sau Direct Pe Cont

             -- linii ce urmeaza a fi stinse 
             WHEN v_rec.SEMNIFICATIE IN (1301, 1303) AND SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE &gt; 0 
             THEN  SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
             
             WHEN v_rec.SEMNIFICATIE IN (1301, 1303) AND SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE &lt; 0 
             THEN  SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
             
           END,


           CODPART            = v_rec.CODPART,
           ICONT              = v_rec.ICONT,
           TIPPLATA           = v_rec.TIPPLATA,
           MAJORARI           = v_rec.MAJORARI,
           SEMNIFICATIE       = v_rec.SEMNIFICATIE,
           TIP                = v_rec.TIP,
           CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
           CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
           COEFPROVIZION      = Case
                                  when v_rec.SumaLei = 0 then 0
                                  else v_rec.VALPROVIZION / (SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.SUMALEI)
                                end,
           CODCENTRU          = V_REC.CODCENTRU,
           CODANALIZANOD      = V_rEC.Codanalizanod                                 
         WHERE 
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
       ELSE
         SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

         UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

         INSERT INTO OBLIGPIF 
         (CODOBLIGPIF, CODGENERAL, TERMEN, 
         VALOARE, 
         REST, 
         CODPART, ICONT, TIPPLATA, MAJORARI, 
         SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, 
         COEFPROVIZION,CODCENTRU,CODANALIZANOD, DINCARETVA)
         VALUES 
         (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, 
         SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, 
         CASE
           WHEN v_rec.SEMNIFICATIE IN (1300, 1302) THEN 0 -- linie care stinge sau Direct Pe Cont
           ELSE SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE  -- linii ce urmeaza a fi stinse 
         END,
         v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, 
         v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE,  v_rec.CODOBLIGASOCIAT,
         Case
           when v_rec.SumaLei = 0 then 0
           else v_rec.VALPROVIZION / (SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.SUMALEI)
         end,
         V_REC.CODCENTRU,V_REC.CODANALIZANOD, V_REC.DINCARETVA 
         );
       END IF;
     END LOOP;
     

-- OBLIGPIF  -- CREDIT
     FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF) LOOP
       IF v_rec.CODOBLIGPIF &gt; 0  THEN
         UPDATE OBLIGPIF
         SET
           CODGENERAL         = v_rec.CODGENERAL,
           TERMEN             = v_rec.TERMEN,
           VALOARE            = SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, 
           DINCARETVA         = SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * NVL(v_rec.DINCARETVA, 0),
           REST               = 

           CASE
             WHEN v_rec.SEMNIFICATIE IN (1350, 1352) THEN 0 -- linie care stinge sau Direct Pe Cont
             -- linii ce urmeaza a fi stinse 
             WHEN v_rec.SEMNIFICATIE IN (1351, 1353) AND SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE &gt; 0 
             THEN  SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
             
             WHEN v_rec.SEMNIFICATIE IN (1351, 1353) AND SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE &lt; 0 
             THEN  SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
           END,

           CODPART            = v_rec.CODPART,
           ICONT              = v_rec.ICONT,
           TIPPLATA           = v_rec.TIPPLATA,
           MAJORARI           = v_rec.MAJORARI,
           SEMNIFICATIE       = v_rec.SEMNIFICATIE,
           TIP                = v_rec.TIP,
           CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
           CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
           COEFPROVIZION      = v_rec.COEFPROVIZION,
           CODCENTRU          = V_REC.CODCENTRU,
           CODANALIZANOD      = V_rEC.CODANALIZANOD                                 
         WHERE 
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
       ELSE
         SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

         UPDATE TMP_STINGERE_ASOCIAT SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

         INSERT INTO OBLIGPIF 
         (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, CODCENTRU,CODANALIZANOD, DINCARETVA)
         VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, 

         SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, 

         CASE
           WHEN v_rec.SEMNIFICATIE IN (1350, 1352) THEN 0 -- linie care stinge sau Direct Pe Cont
           ELSE SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE  -- linii ce urmeaza a fi stinse 
         END,

         v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT,
         v_rec.COEFPROVIZION,
         V_REC.CODCENTRU,V_REC.CODANALIZANOD, V_REC.DINCARETVA
         );
       END IF;
     END LOOP;



    -- STINGERE -- DEBIT
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE 
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE 
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE);
      END IF;
    END LOOP; 
     


    -- STINGERE -- CREDIT
    FOR v_rec in (SELECT * FROM TMP_STINGERE_ASOCIAT) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE 
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE 
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE);
      END IF;
    END LOOP; 




-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = 28 AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET 
    CODDOC       = V_REC.CODDOC,       
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = V_REC.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE 
    CODJURNAL1 = V_REC.CODJURNAl1; 
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD ) 
   VALUES 
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,
   v_rec.CODANALIZANOD);
 END IF; 
END LOOP;
  


-- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 28 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);
    
    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET  
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC, 
        INDEXLOCAL = V_REC.INDEXLOCAL, 
        CONTD      = V_REC.CONTD, 
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE, 
        VALOAREV   = V_REC.VALOAREV, 
        VALOARE_IFRS  = V_REC.VALOARE_IFRS,
        VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
        OBS        = V_REC.OBS, 
        AN         = V_REC.AN, 
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = V_REC.CODCENTRU,  
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT,
        CODANALIZANOD = v_Rec.CODANALIZANOD   
      WHERE 
        CODJURNAL = V_REC.CODJURNAl; 
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)  
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,
     v_rec.CODANALIZANOD);
     END IF; 
    END LOOP;


  ELSE -- INSERT

    SELECT SEQ_COMPENS_CODCOMPENS.NextVal INTO RecID FROM DUAL;   

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      
       WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMPENS&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                        aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);  
    END IF;
    
    UPDATE TMP_GENERAL SET CODDOC = RecID;
    
    -- COMPENS
    INSERT INTO COMPENS ( CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, SUBUNITATEA,CODGEST, CODCENTRU, AGENT, TIPCOMPENS, USERID,DATACREARE, CODANALIZA, 
                        CodTipPartIncert, ExclusSAFT, Flags)   
    (SELECT RecId, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, SUBUNITATEA, CODGEST, CODCENTRU, AGENT, TIPCOMPENS, PKG_GLOBALS.USERID,systimestamp,CODANALIZA, 
            CodTipPartIncert, ExclusSAFT, Flags  FROM TMP_COMPENS); 

      -- GENERAL
    FOR v_rec IN (SELECT * FROM TMP_GENERAL)  LOOP
      SELECT SEQ_GENERAL_CODGENERAL.NextVal INTO vCOD FROM DUAL;

      UPDATE TMP_OBLIGPIF         SET CODGENERAL = vCOD WHERE CODGENERAL = v_rec.CODGENERAL;
      UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL = vCOD WHERE CODGENERAL = v_rec.CODGENERAL;

      INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
      VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
    END LOOP;

   
   
   -- OBLIGPIF - debit
    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF)  LOOP
      SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

      UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF 
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION,CODCENTRU,CODANALIZANOD, DINCARETVA)
      VALUES 
      (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, 
      
       SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, 

      CASE
        WHEN v_rec.SEMNIFICATIE IN (1300, 1302) THEN 0 -- linie care stinge sau Direct Pe Cont
        -- linii ce urmeaza a fi stinse 
        ELSE SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE 
 -- linii ce urmeaza a fi stinse 
      END,


        v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT,
         Case
           when v_rec.SumaLei = 0 then 0
           else v_rec.VALPROVIZION / (SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.SUMALEI)
         end,
        V_REC.CODCENTRU, 
        V_REC.CODANALIZANOD, 
        V_REC.DINCARETVA  
        ) ;
    END LOOP;


   -- OBLIGPIF - credit
    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF)  LOOP
      SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

      UPDATE TMP_STINGERE_ASOCIAT SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF 
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION,CODCENTRU,CODANALIZANOD, DINCARETVA)
      VALUES 
      (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, 
      
      SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE, 
      CASE
        WHEN v_rec.SEMNIFICATIE IN (1350, 1352) THEN 0 -- linie care stinge sau Direct Pe Cont
        ELSE SEMNCOMPENS(v_rec.SEMNIFICATIE, v_rec.ICONT ) * v_rec.VALOARE -- linii ce urmeaza a fi stinse 
      END,

       v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT,
       v_rec.COEFPROVIZION,
       V_REC.CODCENTRU,
       V_REC.CODANALIZANOD,
       V_REC.DINCARETVA
       );
    END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;   
      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE, V_REC.DINCARETVA);
    END LOOP;
    

   -- STINGERE -- credit
    FOR v_rec IN (SELECT * FROM TMP_STINGERE_ASOCIAT) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;   
      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE, V_REC.DINCARETVA);
    END LOOP;

    INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD ) 
    (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT,CODANALIZANOD FROM TMP_JURNAL1);



   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)  
   ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);

 END IF;

-- actualizez restul obligatiilor stinse de tranzactiile documentului salvat
  UPDATE OBLIGPIF O
  SET  
  REST =
    (
    CASE
      WHEN VALOARE &gt;= 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      WHEN VALOARE &lt; 0  THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
    END),
    RESTTVA =
      (
        CASE
         WHEN VALOARE &gt;= 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0)  + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        END
       )
  WHERE 
   O.CODOBLIGPIF IN 
   ( SELECT CODSTINSPIF FROM TMP_STINGERE 
     
     UNION 
     
     SELECT CODSTINSPIF FROM TMP_STINGERE_ASOCIAT 
     
     UNION 
     
     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );  



-- actualizare CARNETE DOCUMENTE
   IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(aCARNET &lt;&gt; CARNETDOC_I OR aNUMARDOC &lt;&gt; NRDOC_I)
   THEN
     PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
     PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
   END IF;
    
   PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNUMARDOC);
  

  -- ACTUALIZARE RULAJE CONTURI
   FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
   
     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;
  
     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
  		 RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
			 RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS
     WHERE 
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
  
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;
      
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
  		     RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
			     RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS

         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF; 

   END LOOP;

   PKG_SAFT.UpdateTaxDecl(4, RecId);
   PKG_GLOBALS.MarkDirtyJurnal;  
   UPDATE_VALTRANZ_STINGERI(RECID);
   NotifyModif(Operation, RecId, &apos;COMPENS&apos;);
   COMMIT;
	 
 EXCEPTION WHEN OTHERS THEN BEGIN
   ROLLBACK;
   RAISE;
 END;
END;
   
   
END;

end PKG_COMPENSARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONCURENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD9F3B5111AECF86987220151B9150B96E8FBDDE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_concurenti IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_51&apos;;

procedure SP_LockRecord(RecId in NUMBER) is
  Tmp NUMBER(20);
begin
  SELECT CodConcurent INTO Tmp FROM Concurenti WHERE CodConcurent = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Concurent &quot;&apos;||denconcurent||&apos;&quot;&apos; INTO aDoc FROM Concurenti WHERE codconcurent = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;Concurenti&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM Concurenti WHERE CodConcurent = RecId;
  NotifyModif(2, RecId, &apos;Concurenti&apos;);
  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_Concurenti FIELDS(CodConcurent) VALUES (0);
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
begin
  INSERT INTO Tmp_Concurenti (
    CodConcurent,
    DenConcurent
  )(
    SELECT
      CodConcurent,
      DenConcurent
    FROM Concurenti
    WHERE CodConcurent = RecId
  );
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
  aDoc varchar2(200);
begin
  if Operation = 0 then -- UPDATE
    SELECT CodConcurent INTO RecId FROM Tmp_Concurenti;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Concurent &quot;&apos;||denconcurent||&apos;&quot;&apos; INTO aDoc FROM Concurenti WHERE codconcurent = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Concurenti&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE Concurenti SET ( CodConcurent, DenConcurent ) = (SELECT CodConcurent, DenConcurent FROM Tmp_Concurenti)
    WHERE CodConcurent = RecId;
  ELSE  -- INSERT
    SELECT Seq_Concurenti_CodConcurent.NextVal INTO RecId FROM DUAL;
    INSERT INTO Concurenti ( CodConcurent, DenConcurent )
    SELECT RecId, DenConcurent
    FROM Tmp_Concurenti;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Concurent &quot;&apos;||denconcurent||&apos;&quot;&apos; INTO aDoc FROM Concurenti WHERE codconcurent = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Concurenti&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

  end if;
  NotifyModif(Operation, RecId, &apos;Concurenti&apos;);
  COMMIT;
end;

end PKG_CONCURENTI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONFIGART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28F39ECCB7FD54BB6DF043AD2E89F3C4ECD3DB76</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONFIGART IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_10&apos;;

PROCEDURE SET_CODIOART_FILTRU_GENERATOR(aCODIOART IN NUMBER)
IS
 BEGIN
   CODIOART_FILTRU_GENERATOR := aCODIOART;
 END;

FUNCTION CODIOART_FILTRU_VALID(aCODIOART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF (ACODIOART = 0)OR(CODIOART_FILTRU_GENERATOR = 0) THEN  RETURN 1;
	ELSE
    IF CODIOART_FILTRU_GENERATOR = aCODIOART
      THEN RETURN 1;
      ELSE RETURN 0;
    END IF;
  END IF;
END;


FUNCTION GETCODCARACTLUNA(aCODIOART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
aCODIOART1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODIOART1 INTO aCODIOART1
    FROM IOART1 I1
    WHERE I1.CODIOART = aCODIOART AND AN*12+LUNA BETWEEN I1.ALStart AND I1.ALStop;
  EXCEPTION
    WHEN OTHERS THEN aCODIOART1 := 0;
  END;
  RETURN aCODIOART1;
END;



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codioart INTO Tmp FROM IOART WHERE codioart = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila articole &quot;&apos;||den_ioart||&apos;&quot;&apos; into aDoc from ioart where codioart = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOART&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM IOART1    WHERE codioart = RecId ;
  DELETE FROM IOARTLINK WHERE codioart = RecId ;
  DELETE FROM IOART     WHERE codioart = RecId ;
  NotifyModif(2, RecId, &apos;IOART&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_IOART FIELDS( codioart ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aANSFARSIT NUMBER(4);
  aLUNASFARSIT NUMBER(2);
BEGIN
  -- Master IOART
  INSERT INTO  TMP_IOART ( codioart,den_ioart, SIMBOL, CODVANZARE )
  SELECT codioart, den_ioart, SIMBOL, CODVANZARE
  FROM IOART WHERE codioart = RecId;

  INSERT INTO TMP_IOARTLINK (CODIOARTLINK, CODIOART, CODIOARTECHIV, CODMACHETA, DENMACHETA)
  SELECT D.CODIOARTLINK, D.CODIOART, D.CODIOARTECHIV, D.CODMACHETA, Coalesce(M.NUMEEXT, &apos;&apos;)
  FROM IOARTLINK D LEFT JOIN TMP_MACHETE M ON M.CODMACHETA = D.CODMACHETA
  WHERE CODIOART = RecId;

  -- Detail IOART1
  INSERT INTO TMP_IOART1 ( codioart1,codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD )
  SELECT codioart1,codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD
  FROM IOART1
  WHERE codioart = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODIOART1, ANSTART, LUNASTART FROM TMP_IOART1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_IOART1
      SET ANSFARSIT   = aANSFARSIT,
          LUNASFARSIT = aLUNASFARSIT
       WHERE CODIOART1 = V_REC.CODIOART1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  aDoc varchar2(200);
BEGIN
  delete tmp_ioartlink where nvl(codmacheta,0) = 0 and nvl(codioartechiv,0) = 0;
  IF Operation = 0 THEN  -- UPDATE

  -- Master IOART
    SELECT  codioart INTO RecId FROM TMP_IOART;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
     select &apos;caracterizare contabila articole &quot;&apos;||den_ioart||&apos;&quot;&apos; into aDoc from ioart where codioart = recid;
     WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOART&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    DELETE FROM IOARTLINK WHERE CODIOART = RECID AND CODIOARTLINK NOT IN (SELECT CODIOARTLINK FROM TMP_IOARTLINK);

    -- DOCLINK
    FOR v_rec IN (SELECT * FROM TMP_IOARTLINK) LOOP
      IF V_REC.CODIOARTLINK &lt; 0 THEN
        INSERT INTO IOARTLINK (CODIOARTLINK, CODIOART, CODIOARTECHIV, CODMACHETA) VALUES
        (SEQ_IOARTLINK_CODIOARTLINK.NEXTVAL, RECID, V_REC.CODIOARTECHIV, V_REC.CODMACHETA);
      ELSE
        UPDATE IOARTLINK
        SET
          CODIOART   = V_REC.CODIOART,
          CODIOARTECHIV = V_REC.CODIOARTECHIV,
          CODMACHETA = V_REC.CODMACHETA
        WHERE
          CODIOARTLINK = V_REC.CODIOARTLINK;
      END IF;
    END LOOP;

    UPDATE IOART SET ( den_ioart, SIMBOL, CODVANZARE )
       = ( SELECT den_ioart, SIMBOL, CODVANZARE
          FROM TMP_IOART )
      WHERE codioart = RecId ;


-- Detail IOART1

    DELETE FROM IOART1 where CodIoArt = RecId and CodIoArt1 not in (Select CodIoArt1 from TMP_IOART1);

    INSERT INTO IOART1 ( codioart1,codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD )
      SELECT  seq_IOART1_codioart1.Nextval , RecId ,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD
      FROM TMP_IOART1 WHERE codioart1 &lt; 0;-- NVL(g_codioart1,0);

    FOR v_rec IN ( SELECT * FROM TMP_IOART1 WHERE NVL(codioart1,-1) &gt; 0 /* g_codioart1*/ ORDER BY codioart1 ) LOOP
       UPDATE IOART1
       SET
        cont             = v_rec.cont,
        diferente        = v_rec.diferente,
        cheltuieli       = v_rec.cheltuieli,
        venituri         = v_rec.venituri,
        plusinventar     = v_rec.plusinventar,
        minusinventar    = v_rec.minusinventar,
        chelttvacolectat = v_rec.chelttvacolectat,
        PROVIZION        = v_rec.PROVIZION,
        CHELTPROVIZION   = v_rec.CHELTPROVIZION,
        VENITPROVIZION   = v_rec.VENITPROVIZION,
        controtunjiri    = v_rec.controtunjiri,
        diverse          = v_rec.diverse,
        CUSTODIE         = V_REC.CUSTODIE,
        accizelatransfer = v_rec.accizelatransfer,
        descarcareg      = v_rec.descarcareg,
        contabgest       = v_rec.contabgest,
        baza             = v_rec.baza,
        difpret          = v_rec.difpret,
        aretvaneex       = v_rec.aretvaneex,
        tvaneex          = v_rec.tvaneex,
        PUSTANDARD       = v_rec.PUSTANDARD,
        mg               = v_rec.mg
       WHERE
         codioart1 = v_rec.codioart1;
    END LOOP;
  ELSE  -- INSERT

-- Master IOART
    SELECT seq_IOART_codioart.NextVal INTO RecId FROM DUAL;



    INSERT INTO  IOART ( codioart,den_ioart, SIMBOL, CODVANZARE )
    ( SELECT  RecId ,den_ioart, SIMBOL, CODVANZARE
      FROM TMP_IOART  ) ;
 -- Detail IOART1
    INSERT INTO  IOART1 ( codioart1,codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD )
       ( SELECT  seq_IOART1_codioart1.Nextval ,RecId,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,VENITPROVIZION,controtunjiri,diverse, CUSTODIE, accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,PUSTANDARD FROM TMP_IOART1 );


    INSERT INTO IOARTLINK (CODIOARTLINK, CODIOART, CODIOARTECHIV, CODMACHETA)
    (SELECT SEQ_IOARTLINK_CODIOARTLINK.NEXTVAL, RECID, CODIOARTECHIV, CODMACHETA FROM TMP_IOARTLINK);


  END IF;


  UPDATE LUNA_RECORDS_FLAGS SET IOART_FLG = 0, IOART_FLG_CONTA=0;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila articole &quot;&apos;||den_ioart||&apos;&quot;&apos; into aDoc from ioart where codioart = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOART&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  prc_al_refresh(&apos;ioart1&apos;, RecId);
  NotifyModif(Operation, RecId, &apos;IOART&apos;);
  COMMIT;
END;



END pkg_ConfigArt;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONFIGBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D929DEED96AD8B298D0209394D61E4D0DA9E53F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONFIGBANK IS

CT_MONITOR CONSTANT VARCHAR2(50):= &apos;MON_10&apos;;


FUNCTION CHECK_LEGATURA_CONST(aCODCONST1 IN NUMBER,
                              aCODCONT   IN NUMBER,
                              aINDEX     IN NUMBER,
                              aCODIOBANK IN NUMBER,
                              aANSTART    IN NUMBER,
                              aLUNASTART  IN NUMBER
                              ) RETURN NUMBER

IS
NEWCODCONST1   NUMBER(20) := 0;
aCODCONSTLUNA  NUMBER(20) := 0;
BEGIN
   NEWCODCONST1 := NVL(aCODCONST1, 0);
   IF NEWCODCONST1 = 0 THEN
     SELECT SEQ_CONST1_CODCONST1.NEXTVAL INTO NEWCODCONST1 FROM DUAL;
     INSERT INTO CONST1(CODCONST1, CODCATEG, INDEXLOCAL, SIMBOL, DENUMIRE, TIP)
     VALUES (NEWCODCONST1, 245, aINDEX, &apos;IOB&apos; || TO_CHAR(aCODIOBANK) || &apos;_&apos; || aINDEX, &apos;IOB&apos; || TO_CHAR(aCODIOBANK) || &apos;_&apos; || aINDEX, 2);

     SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO aCODCONSTLUNA FROM DUAL;
     INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
     VALUES(aCODCONSTLUNA, NEWCODCONST1, aANSTART, aLUNASTART, 0);

     INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
     VALUES (aCODCONT, aCODCONSTLUNA);

   ELSE
     BEGIN
       SELECT CODCONSTLUNA INTO aCODCONSTLUNA FROM CONSTLUNA
       WHERE
         CODCONST1     = NEWCODCONST1
         AND ANSTART   = aANSTART
         AND LUNASTART = aLUNASTART;
       EXCEPTION WHEN OTHERS THEN aCODCONSTLUNA := 0;
     END;
     IF aCODCONSTLUNA = 0 THEN
       SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO aCODCONSTLUNA FROM DUAL;
       INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
       VALUES(aCODCONSTLUNA, NEWCODCONST1, aANSTART, aLUNASTART, 0);

       INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
       VALUES (aCODCONT, aCODCONSTLUNA);
     ELSE
       UPDATE CONSTVAL
       SET
         VALOARE = aCODCONT
       WHERE
         CODCONSTLUNA = aCODCONSTLUNA;
     END IF;
   END IF;

   RETURN NEWCODCONST1;
END;



FUNCTION GetRecordIoBank(IoBankCod IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor IS
  tmpcursor Luna_Ref_Cursor;
BEGIN
  BEGIN
    OPEN tmpCursor FOR
    SELECT *
    FROM IoBank1 i1
    WHERE i1.CodIoBank = IoBankCod AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN OPEN tmpCursor FOR SELECT -1 FROM DUAL;
  END;

 RETURN tmpcursor;
END;

FUNCTION GETCODCARACTLUNA(aCODIoBank IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER IS
aCODIOBANK1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODIOBANK1 INTO aCODIOBANK1
    FROM IoBank1 i1
    WHERE i1.CodIoBank = aCODIoBank AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN aCODIOBANK1 := 0;
  END;
  RETURN aCODIOBANK1;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codiobank INTO Tmp FROM IOBANK WHERE codiobank = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(200);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila banci &quot;&apos;||den_iobank||&apos;&quot;&apos; into aDoc from ioBANK where codiobank = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOBANK&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
	DELETE FROM IOBANK1 WHERE codiobank = RecId ;
  DELETE FROM IOBANK  WHERE codiobank = RecId ;
  NotifyModif(2, RecId, &apos;IOBANK&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_IOBANK FIELDS( codiobank ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT NUMBER (4);
aLUNASFARSIT NUMBER (2);

BEGIN
-- Master IOBANK
  INSERT INTO  TMP_IOBANK ( codiobank,den_iobank )
    ( SELECT codiobank,den_iobank
      FROM IOBANK WHERE codiobank = RecId ) ;

-- Detail IOBANK1
  INSERT INTO  TMP_IOBANK1 (
    codiobank1,
    codiobank,
    cont,
    dobanda,
    comision,
    cheltuieliCV,
    venituriCV,
    anstart,
    lunastart,
    PCEC,
    PEFECTE,
    PEFECTEREM,
    ICEC,
    IEFECTE,
    IEFECTEREM
  )
  SELECT
    codiobank1,
    codiobank,
    cont,
    dobanda,
    comision,
    cheltuieliCV,
    venituriCV,
    anstart,
    lunastart,
    PCEC,
    PEFECTE,
    PEFECTEREM,
    ICEC,
    IEFECTE,
    IEFECTEREM
  FROM IOBANK1 WHERE codiobank = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODIOBANK1, ANSTART, LUNASTART FROM TMP_IOBANK1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_IOBANK1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODIOBANK1 = V_REC.CODIOBANK1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);

  ADOC VARCHAR2(200);
  aCODCONST1    NUMBER(20) := 0;
  aCODCONSTLUNA NUMBER(20) := 0;
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master IOBANK
    SELECT  codiobank INTO RecId FROM TMP_IOBANK;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila banci &quot;&apos;||den_iobank||&apos;&quot;&apos; into aDoc from ioBANK where codiobank = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOBANK&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

    UPDATE IOBANK SET ( den_iobank )
       = ( SELECT den_iobank
          FROM TMP_IOBANK )
      WHERE codiobank = RecId ;


-- Detail IOBANK1

    DELETE FROM IOBANK1 where CodIoBank = RecId and CodIoBAnk1 not in (Select CodIoBank1 from TMP_IOBank1);

-- pentru IOBANK-uri legate de constante verific legaturile


    INSERT INTO IOBANK1 ( codiobank1,codiobank,cont,dobanda,comision,cheltuieliCV,venituriCV, Anstart,lunastart, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM  )
      SELECT  seq_IOBANK1_codiobank1.Nextval , RecId ,cont,dobanda,comision,cheltuieliCV,venituriCV, anstart,lunastart, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM
--      FROM TMP_IOBANK1 WHERE codiobank1 &gt; NVL(g_codiobank1,0);
      FROM TMP_IOBANK1 WHERE codiobank1 &lt; 0;

--    FOR v_rec IN ( SELECT * FROM TMP_IOBANK1 WHERE NVL(codiobank1,-1) &lt;= g_codiobank1 ORDER BY codiobank1 ) LOOP
    FOR v_rec IN ( SELECT * FROM TMP_IOBANK1 WHERE NVL(codiobank1,-1) &gt; 0 ORDER BY codiobank1 ) LOOP
      UPDATE IOBANK1
      SET
        cont           = v_rec.cont,
        dobanda        = v_rec.dobanda,
        comision       = v_rec.comision,
        cheltuieliCV   = v_rec.cheltuieliCV,
        venituriCV     = v_rec.venituriCV,
        PCEC           = V_REC.PCEC,
        PEFECTE        = V_REC.PEFECTE,
        PEFECTEREM     = V_REC.PEFECTEREM,
        ICEC           = V_REC.ICEC,
        IEFECTE        = V_REC.IEFECTE,
        IEFECTEREM     = V_REC.IEFECTEREM
      WHERE codiobank1 = v_rec.codiobank1;
    END LOOP;
  ELSE  -- INSERT
-- Master IOBANK
  SELECT seq_IOBANK_codiobank.NextVal INTO RecId FROM DUAL;


  INSERT INTO  IOBANK ( codiobank,den_iobank )
 ( SELECT  RecId ,den_iobank
     FROM TMP_IOBANK  ) ;
-- Detail IOBANK1
  INSERT INTO  IOBANK1 ( codiobank1,codiobank,cont,dobanda,comision,cheltuieliCV,venituriCV,anstart,lunastart, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM  )
     ( SELECT  seq_IOBANK1_codiobank1.Nextval ,RecId,cont,dobanda,comision,cheltuieliCV,venituriCV,anstart,lunastart, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM  FROM TMP_IOBANK1 );

END IF;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila banci &quot;&apos;||den_iobank||&apos;&quot;&apos; into aDoc from ioBANK where codiobank = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOBANK&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  PRC_AL_REFRESH(&apos;IOBANK1&apos;, RECID);
  NotifyModif(Operation, RecId, &apos;IOBANK&apos;);
 COMMIT;

END;



END pkg_ConfigBank;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONFIGFILIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E174DE53C2371B564B04C2C7B44E1E698B151FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONFIGFILIAL IS

CT_MONITOR CONSTANT VARCHAR2(200) := &apos;MON_10&apos;;

FUNCTION GETCODCARACTLUNA(aCODIOFILIAL IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER
IS
aCODIOFILIAL1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODIOFILIAL1 INTO aCODIOFILIAL1
    FROM IOFILIAL1 i1
    WHERE i1.CODIOFILIAL = aCODIOFILIAL AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN aCODIOFILIAL1 := 0;
  END;
  RETURN aCODIOFILIAL1;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODIOFILIAL INTO Tmp FROM IOFILIAL WHERE CODIOFILIAL = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
ADOC VARCHAR2(200);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila subunitati &quot;&apos;||den_iofilial||&apos;&quot;&apos; into aDoc from iofilial where codiofilial = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOFILIAL&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
  DELETE FROM IOFILIAL1 WHERE CODIOFILIAL = RecId ;
  DELETE FROM IOFILIAL  WHERE CODIOFILIAL = RecId ;
  NotifyModif(2, RecId, &apos;IOFILIAL&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_IOFILIAL FIELDS( CODIOFILIAL ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 aANSFARSIT   NUMBER (4);
 aLUNASFARSIT NUMBER (2);
BEGIN
-- Master IOFILIAL
  INSERT INTO TMP_IOFILIAL (CODIOFILIAL, DEN_IOFILIAL )
    ( SELECT CODIOFILIAL, DEN_IOFILIAL
      FROM IOFILIAL WHERE CODIOFILIAL = RecId ) ;

-- Detail IOFILIAL1
  INSERT INTO TMP_IOFILIAL1 (CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART )
    ( SELECT CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART
      FROM IOFILIAL1 WHERE CODIOFILIAL = RecId );


  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODIOFILIAL1, ANSTART, LUNASTART FROM TMP_IOFILIAL1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_IOFILIAL1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODIOFILIAL1 = V_REC.CODIOFILIAL1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

  COMMIT;

END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn    INTEGER := 0;
  vLuna  INTEGER := 0;
  vCod   NUMBER(20);
  aDoc   varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master IOFILIAL
    SELECT CODIOFILIAL INTO RecId FROM TMP_IOFILIAL;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila subunitati &quot;&apos;||den_iofilial||&apos;&quot;&apos; into aDoc from iofilial where codiofilial = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOFILIAL&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

    UPDATE IOFILIAL SET ( DEN_IOFILIAL )
       = ( SELECT DEN_IOFILIAL FROM TMP_IOFILIAL )
      WHERE CODIOFILIAL = RecId ;


-- Detail IOFILIAL1

    DELETE FROM IOFILIAL1 WHERE CODIOFILIAL = RECID AND CODIOFILIAL1 NOT IN (SELECT CODIOFILIAL1 FROM TMP_IOFILIAL1);

    INSERT INTO IOFILIAL1 (CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART )
      SELECT SEQ_IOFILIAL1_CODIOFILIAL1.NEXTVAL, RecId, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART
      FROM TMP_IOFILIAL1 WHERE CODIOFILIAL1 &lt; 0;

    FOR V_REC IN ( SELECT * FROM TMP_IOFILIAL1 WHERE NVL(CODIOFILIAL1, -1) &gt; 0 ORDER BY codIOFILIAL1 ) LOOP
      UPDATE IOFILIAL1
      SET
        CONTDECONTARE    = v_rec.CONTDECONTARE ,
        CONTDECONTAREF   = v_rec.CONTDECONTAREF,
				ISFIRMA          = v_rec.ISFIRMA,
				CONTDECONTSERV   = v_rec.CONTDECONTSERV,
        CONTDECONTCB     = v_rec.CONTDECONTCB  ,
        CONTDECONTCMP    = v_rec.CONTDECONTCMP
      WHERE
      CODIOFILIAL1 = v_rec.CODIOFILIAL1;
    END LOOP;
  ELSE  -- INSERT


-- Master IOFILIAL
  SELECT SEQ_IOFILIAL_CODIOFILIAL.NEXTVAL INTO RecId FROM DUAL;


  INSERT INTO IOFILIAL( CODIOFILIAL, DEN_IOFILIAL )
 ( SELECT RecId, DEN_IOFILIAL  FROM TMP_IOFILIAL ) ;


-- Detail IOFILIAL1
  INSERT INTO IOFILIAL1(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART )
  ( SELECT  SEQ_IOFILIAL1_CODIOFILIAL1.NEXTVAL, RecId, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, ANSTART, LUNASTART FROM TMP_IOFILIAL1 );

END IF;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila subunitati &quot;&apos;||den_iofilial||&apos;&quot;&apos; into aDoc from iofilial where codiofilial = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOFILIAL&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  PRC_AL_REFRESH(&apos;IOFILIAL1&apos;, RECID);
  NotifyModif(Operation, RecId, &apos;IOFILIAL&apos;);
COMMIT;

END;

end PKG_CONFIGFILIAL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONFIGPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A31026EC5B56DC4C2E6BBCD2D16DA5E702F9B4ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONFIGPART IS

CT_MONITOR constant varchar2(50) :=&apos;MON_10&apos;;


PROCEDURE SET_IOPART_EDITAT(aCODPART IN NUMBER)
IS
BEGIN
  IOPART_EDITAT := aCODPART;
END;



FUNCTION COD_IOPART_EDITAT_VALID(aCODPART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF IOPART_EDITAT &lt;= 0 THEN RETURN 1;
  ELSE
    IF aCODPART = IOPART_EDITAT THEN RETURN 1;
                                ELSE RETURN 0;
    END IF;
  END IF;
END;


FUNCTION GetRecordIopart(IoPartCod IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor
IS
tmpcursor Luna_Ref_Cursor;
BEGIN
  BEGIN
    OPEN tmpCursor FOR
    SELECT *
    FROM IoPart1 i1
    WHERE i1.CodIoPart = IoPartCod AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN OPEN tmpCursor FOR SELECT -1 FROM DUAL;
  END;
  RETURN tmpcursor;
END;




FUNCTION GETCODCARACTLUNA(aCodIOPART IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER
IS
aCODIOPART1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODIOPART1 INTO aCODIOPART1 FROM IOPART1 I1
    WHERE i1.CodIoPart = aCodIOPART AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN aCODIOPART1 := 0;
  END;

 RETURN aCODIOPART1;

END;



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodIOPart INTO Tmp FROM IOPART WHERE CodIOPart = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
ADOC VARCHAR2(200);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila parteneri &quot;&apos;||den_iopart||&apos;&quot;&apos; into aDoc from iopart where codiopart = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPART&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
	DELETE FROM IOPART1 WHERE CodIOPart = RecId ;
  DELETE FROM IOPART  WHERE CodIOPart = RecId ;
  NotifyModif(2, RecId, &apos;IOPART&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_IOPART FIELDS( CodIOPart ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT NUMBER(4);
aLUNASFARSIT NUMBER(2);
BEGIN
-- Master IOPART
  INSERT INTO  TMP_IOPART ( CodIOPart,den_iopart, SIMBOL )
    ( SELECT CodIOPart,den_iopart, SIMBOL
      FROM IOPART WHERE CodIOPart = RecId ) ;

-- Detail IOPART1
  INSERT INTO TMP_IOPART1 (
    CodIOPart, ContFurnizor, CodIOPart1, ContClient, ContFurnAvans, ContClientAvans, ContFurnAviz, ContClientAviz, ContFurnMF, ContCreditD, ContDebitD, ContLitigii,
    ContFurnAvS, ContFurnAvIC, ContFurnAvIN, ContFurnLeas, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS,
    contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC,
    ContSuplimF1 , ContSuplimF2 , ContSuplimF3 , ContSuplimF4 , ContSuplimF5 , ContSuplimF6 , ContSuplimF7 , ContSuplimF8 , ContSuplimF9 , ContSuplimF10,
    ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20,
    ContSuplimF21, ContSuplimF22, ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
    ContSuplimC1 , ContSuplimC2 , ContSuplimC3 , ContSuplimC4 , ContSuplimC5 ,
    ContTerti,
    TvaNeexF, TvaNeexP, TvaNeexI, TvaNeexC,
    Tip, anstart, lunastart, alstart, alstop)
  SELECT
    CodIOPart, ContFurnizor, CodIOPart1, ContClient, ContFurnAvans, ContClientAvans, ContFurnAviz, ContClientAviz, ContFurnMF, ContCreditD, ContDebitD, ContLitigii,
    ContFurnAvS, ContFurnAvIC, ContFurnAvIN, ContFurnLeas, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS,
    contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC,
    ContSuplimF1 , ContSuplimF2 , ContSuplimF3 , ContSuplimF4 , ContSuplimF5 , ContSuplimF6 , ContSuplimF7 , ContSuplimF8 , ContSuplimF9 , ContSuplimF10,
    ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20,
    ContSuplimF21, ContSuplimF22, ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
    ContSuplimC1 , ContSuplimC2 , ContSuplimC3 , ContSuplimC4 , ContSuplimC5 ,
    ContTerti,
    TvaNeexF, TvaNeexP, TvaNeexI, TvaNeexC,
    Tip, anstart, lunastart, alstart, alstop
  FROM IOPART1
  WHERE CodIOPart = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODIOPART1, ANSTART, LUNASTART FROM TMP_IOPART1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_IOPART1
      SET ANSFARSIT   = aANSFARSIT, LUNASFARSIT = aLUNASFARSIT
      WHERE CODIOPART1 = V_REC.CODIOPART1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  aDoc varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master IOPART
    SELECT  CodIOPart INTO RecId FROM TMP_IOPART;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila parteneri &quot;&apos;||den_iopart||&apos;&quot;&apos; into aDoc from iopart where codiopart = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPART&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

    UPDATE IOPART SET ( den_iopart, SIMBOL )
       = ( SELECT den_iopart, SIMBOL
          FROM TMP_IOPART )
      WHERE CodIOPart = RecId ;


-- Detail IOPART1

--   insert into tmp
--   select to_char(CodIOPart1) || &apos;-&apos;|| to_char(g_CodIOPart1) || &apos;-&apos; || to_char(recid)
--   from TMP_IOPART1;


    DELETE FROM IOPART1 where CodIoPart = RecId and CodIoPart1 not in (Select CodIoPart1 from TMP_IOPART1);

    INSERT INTO IOPART1 ( CodIOPart,ContFurnizor,CodIOPart1,ContClient,ContFurnAvans,ContClientAvans,ContFurnAviz,ContClientAviz,ContFurnMF,ContCreditD,ContDebitD,ContLitigii,ContFurnAvS,ContFurnAvIC,ContFurnAvIN,
    ContFurnLeas,
    CONTNCRF,
    CONTNCRC,
    CONTCHELTAVANS,
    CONTVENITAVANS,
    contgarantieEF,
    contgarantieTF,
    contgarantieEC,
    contgarantieTC,
		ContSuplimF1 ,
		ContSuplimF2 ,
		ContSuplimF3 ,
		ContSuplimF4 ,
		ContSuplimF5 ,

    ContSuplimF6 ,
    ContSuplimF7 ,
    ContSuplimF8 ,
    ContSuplimF9 ,
    ContSuplimF10 ,
    ContSuplimF11 ,
    ContSuplimF12 ,
    ContSuplimF13 ,
    ContSuplimF14 ,
    ContSuplimF15 ,
    ContSuplimF16 ,
    ContSuplimF17 ,
    ContSuplimF18 ,
    ContSuplimF19 ,
    ContSuplimF20 ,
    ContSuplimF21 ,
    ContSuplimF22 ,
    ContSuplimF23 ,
    ContSuplimF24 ,
    ContSuplimF25 ,
    ContSuplimF26 ,
    ContSuplimF27 ,
    ContSuplimF28 ,
    ContSuplimF29 ,
    ContSuplimF30 ,



		ContSuplimC1 ,
		ContSuplimC2 ,
		ContSuplimC3 ,
		ContSuplimC4 ,
		ContSuplimC5 ,
    ContTerti,TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC,Tip,anstart,lunastart )
      SELECT  RecId ,ContFurnizor, seq_IOPART1_CodIOPart1.Nextval ,ContClient,ContFurnAvans,ContClientAvans,ContFurnAviz,ContClientAviz,ContFurnMF,ContCreditD,ContDebitD,ContLitigii,ContFurnAvS,ContFurnAvIC,ContFurnAvIN,
       ContFurnLeas,
       CONTNCRF,
       CONTNCRC,
       CONTCHELTAVANS,
       CONTVENITAVANS,
	  	 contgarantieEF,
			 contgarantieTF,
			 contgarantieEC,
			 contgarantieTC,
			ContSuplimF1 ,
			ContSuplimF2 ,
			ContSuplimF3 ,
			ContSuplimF4 ,
			ContSuplimF5 ,
      ContSuplimF6 ,
      ContSuplimF7 ,
      ContSuplimF8 ,
      ContSuplimF9 ,
      ContSuplimF10 ,
      ContSuplimF11 ,
      ContSuplimF12 ,
      ContSuplimF13 ,
      ContSuplimF14 ,
      ContSuplimF15 ,
      ContSuplimF16 ,
      ContSuplimF17 ,
      ContSuplimF18 ,
      ContSuplimF19 ,
      ContSuplimF20 ,
      ContSuplimF21 ,
      ContSuplimF22 ,
      ContSuplimF23 ,
      ContSuplimF24 ,
      ContSuplimF25 ,
      ContSuplimF26 ,
      ContSuplimF27 ,
      ContSuplimF28 ,
      ContSuplimF29 ,
      ContSuplimF30 ,


			ContSuplimC1 ,
			ContSuplimC2 ,
			ContSuplimC3 ,
			ContSuplimC4 ,
			ContSuplimC5 ,
       ContTerti,
       TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC,Tip,anstart,lunastart
--      FROM TMP_IOPART1 WHERE CodIOPart1 &gt; NVL(g_CodIOPart1,0);
      FROM TMP_IOPART1 WHERE CodIOPart1 &lt; 0;


--    FOR v_rec IN ( SELECT * FROM TMP_IOPART1 WHERE NVL(CodIOPart1,-1) &lt;= g_CodIOPart1 ORDER BY CodIOPart1 ) LOOP
    FOR v_rec IN ( SELECT * FROM TMP_IOPART1 WHERE NVL(CodIOPart1,-1) &gt; 0 ORDER BY CodIOPart1 ) LOOP
    UPDATE IOPART1
    SET
      ContFurnizor    = v_rec.ContFurnizor,
      ContClient      = v_rec.ContClient,
      ContFurnAvans   = v_rec.ContFurnAvans,
      ContClientAvans = v_rec.ContClientAvans,
      ContFurnAviz    = v_rec.ContFurnAviz,
      ContClientAviz  = v_rec.ContClientAviz,
      ContFurnMF      = v_rec.ContFurnMF,
      ContCreditD     = v_rec.ContCreditD,
      ContDebitD      = v_rec.ContDebitD,
      ContLitigii     = v_rec.ContLitigii,
      ContFurnAvS     = v_rec.ContFurnAvS,
      ContFurnAvIC    = v_rec.ContFurnAvIC,
      ContFurnAvIN    = v_rec.ContFurnAvIN,
      ContFurnLeas    = v_rec.ContFurnLeas,
      CONTNCRF        = V_REC.CONTNCRF,
      CONTNCRC        = V_REC.CONTNCRC,
      CONTCHELTAVANS  = V_REC.CONTCHELTAVANS,
      CONTVENITAVANS  = V_REC.CONTVENITAVANS,
      contgarantieEF  = V_REC.contgarantieEF,
      contgarantieTF  = V_REC.contgarantieTF,
      contgarantieEC  = V_REC.contgarantieEC,
      contgarantieTC  = V_REC.contgarantieTC,
			ContSuplimF1   = v_rec.ContSuplimF1,
			ContSuplimF2   = v_rec.ContSuplimF2,
			ContSuplimF3   = V_REC.ContSuplimF3,
			ContSuplimF4   = V_REC.ContSuplimF4,
			ContSuplimF5   = V_REC.ContSuplimF5,
			ContSuplimF6   = V_REC.ContSuplimF6,
			ContSuplimF7   = V_REC.ContSuplimF7,
			ContSuplimF8   = V_REC.ContSuplimF8,
			ContSuplimF9   = V_REC.ContSuplimF9,
			ContSuplimF10   = V_REC.ContSuplimF10,
			ContSuplimF11   = V_REC.ContSuplimF11,
			ContSuplimF12   = V_REC.ContSuplimF12,
			ContSuplimF13   = V_REC.ContSuplimF13,
			ContSuplimF14   = V_REC.ContSuplimF14,
			ContSuplimF15   = V_REC.ContSuplimF15,
			ContSuplimF16   = V_REC.ContSuplimF16,
			ContSuplimF17   = V_REC.ContSuplimF17,
			ContSuplimF18   = V_REC.ContSuplimF18,
			ContSuplimF19   = V_REC.ContSuplimF19,
			ContSuplimF20   = V_REC.ContSuplimF20,
			ContSuplimF21   = V_REC.ContSuplimF21,
			ContSuplimF22   = V_REC.ContSuplimF22,
			ContSuplimF23   = V_REC.ContSuplimF23,
			ContSuplimF24   = V_REC.ContSuplimF24,
			ContSuplimF25   = V_REC.ContSuplimF25,
			ContSuplimF26   = V_REC.ContSuplimF26,
			ContSuplimF27   = V_REC.ContSuplimF27,
			ContSuplimF28   = V_REC.ContSuplimF28,
			ContSuplimF29   = V_REC.ContSuplimF29,
			ContSuplimF30   = V_REC.ContSuplimF30,


			ContSuplimC1   = V_REC.ContSuplimC1,
			ContSuplimC2   = V_REC.ContSuplimC2,
			ContSuplimC3   = V_REC.ContSuplimC3,
			ContSuplimC4   = V_REC.ContSuplimC4,
			ContSuplimC5   = V_REC.ContSuplimC5,
      ContTerti       = v_rec.ContTerti,
      TvaNeexF        = v_rec.TvaNeexF,
      TvaNeexP        = v_rec.TvaNeexP,
      TvaNeexI        = v_rec.TvaNeexI,
      TvaNeexC        = v_rec.TvaNeexC,
      Tip             = v_rec.Tip
    WHERE CodIOPart1  = v_rec.CodIOPart1;
    END LOOP;

/*
    FOR v_rec IN ( SELECT * FROM TMP_IOPART1 WHERE NVL(CodIOPart1,-1) &lt;= g_CodIOPart1 ORDER BY CodIOPart1 ) LOOP
      SELECT  Decode(ContFurnizor,v_rec.ContFurnizor,0,1) + Decode(ContClient,v_rec.ContClient,0,1) + Decode(ContFurnAvans,v_rec.ContFurnAvans,0,1) + Decode(ContClientAvans,v_rec.ContClientAvans,0,1) + Decode(ContFurnAviz,v_rec.ContFurnAviz,0,1) + Decode(ContClientAviz,v_rec.ContClientAviz,0,1) + Decode(ContFurnMF,v_rec.ContFurnMF,0,1) + Decode(ContCreditD,v_rec.ContCreditD,0,1) + Decode(ContDebitD,v_rec.ContDebitD,0,1) + Decode(ContLitigii,v_rec.ContLitigii,0,1) + Decode(ContFurnAvS,v_rec.ContFurnAvS,0,1) + Decode(ContFurnAvIC,v_rec.ContFurnAvIC,0,1) + Decode(ContFurnAvIN,v_rec.ContFurnAvIN,0,1) + Decode(ContTerti,v_rec.ContTerti,0,1) + Decode(TvaNeexF, TvaNeexP, TvaNeexI,v_rec.TvaNeexF, TvaNeexP, TvaNeexI,0,1) + Decode(TvaNeexC,v_rec.TvaNeexC,0,1) + Decode(Tip,v_rec.Tip,0,1) ,anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM IOPART1 WHERE CodIOPart1 = NVL(v_rec.CodIOPart1,0);
       IF (vRecNo &gt; 0) THEN
         IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE IOPART1 SET ContFurnizor = v_rec.ContFurnizor,ContClient = v_rec.ContClient,ContFurnAvans = v_rec.ContFurnAvans,ContClientAvans = v_rec.ContClientAvans,ContFurnAviz = v_rec.ContFurnAviz,ContClientAviz = v_rec.ContClientAviz,ContFurnMF = v_rec.ContFurnMF,ContCreditD = v_rec.ContCreditD,ContDebitD = v_rec.ContDebitD,ContLitigii = v_rec.ContLitigii,ContFurnAvS = v_rec.ContFurnAvS,ContFurnAvIC = v_rec.ContFurnAvIC,ContFurnAvIN = v_rec.ContFurnAvIN,ContTerti = v_rec.ContTerti,TvaNeexF, TvaNeexP, TvaNeexI = v_rec.TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC = v_rec.TvaNeexC,Tip = v_rec.Tip WHERE CodIOPart1 = v_rec.CodIOPart1;
        ELSE
          INSERT INTO IOPART1 ( CodIOPart,ContFurnizor,CodIOPart1,ContClient,ContFurnAvans,ContClientAvans,ContFurnAviz,ContClientAviz,ContFurnMF,ContCreditD,ContDebitD,ContLitigii,ContFurnAvS,ContFurnAvIC,ContFurnAvIN,ContTerti,TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC,Tip,anstart,lunastart ) VALUES ( RecId,v_rec.ContFurnizor,Seq_IOPART1_CodIOPart1.NextVal,v_rec.ContClient,v_rec.ContFurnAvans,v_rec.ContClientAvans,v_rec.ContFurnAviz,v_rec.ContClientAviz,v_rec.ContFurnMF,v_rec.ContCreditD,v_rec.ContDebitD,v_rec.ContLitigii,v_rec.ContFurnAvS,v_rec.ContFurnAvIC,v_rec.ContFurnAvIN,v_rec.ContTerti,v_rec.TvaNeexF, TvaNeexP, TvaNeexI,v_rec.TvaNeexC,v_rec.Tip,v_rec.anstart,v_rec.lunastart );
        END IF;
      END IF;
    END LOOP;
*/

  ELSE  -- RAMURA INSERT
-- Master IOPART
--   insert into tmp values (&apos;ins&apos;);

  SELECT seq_IOPART_CodIOPart.NextVal INTO RecId FROM DUAL;


  INSERT INTO  IOPART ( CodIOPart,den_iopart, SIMBOL )
 ( SELECT  RecId ,den_iopart, SIMBOL  FROM TMP_IOPART  ) ;
-- Detail IOPART1
  INSERT INTO  IOPART1 ( CodIOPart,ContFurnizor,CodIOPart1,ContClient,ContFurnAvans,ContClientAvans,ContFurnAviz,ContClientAviz,ContFurnMF,ContCreditD,ContDebitD,ContLitigii,ContFurnAvS,ContFurnAvIC,ContFurnAvIN,
  ContFurnLeas,
  CONTNCRF,
  CONTNCRC,
  CONTCHELTAVANS,
  CONTVENITAVANS,
  contgarantieEF,
  contgarantieTF,
  contgarantieEC,
  contgarantieTC,
	ContSuplimF1,
	ContSuplimF2,
	ContSuplimF3,
	ContSuplimF4,
	ContSuplimF5,

  ContSuplimF6 ,
  ContSuplimF7 ,
  ContSuplimF8 ,
  ContSuplimF9 ,
  ContSuplimF10 ,
  ContSuplimF11 ,
  ContSuplimF12 ,
  ContSuplimF13 ,
  ContSuplimF14 ,
  ContSuplimF15 ,
  ContSuplimF16 ,
  ContSuplimF17 ,
  ContSuplimF18 ,
  ContSuplimF19 ,
  ContSuplimF20 ,
  ContSuplimF21 ,
  ContSuplimF22 ,
  ContSuplimF23 ,
  ContSuplimF24 ,
  ContSuplimF25 ,
  ContSuplimF26 ,
  ContSuplimF27 ,
  ContSuplimF28 ,
  ContSuplimF29 ,
  ContSuplimF30 ,





	ContSuplimC1,
	ContSuplimC2,
	ContSuplimC3,
	ContSuplimC4,
	ContSuplimC5,
  ContTerti,
  TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC,Tip,anstart,lunastart )
  ( SELECT RecId,ContFurnizor, seq_IOPART1_CodIOPart1.Nextval ,ContClient,ContFurnAvans,ContClientAvans,ContFurnAviz,ContClientAviz,ContFurnMF,ContCreditD,ContDebitD,ContLitigii,ContFurnAvS,ContFurnAvIC,ContFurnAvIN,
  ContFurnLeas,
  CONTNCRF,
  CONTNCRC,
  CONTCHELTAVANS,
  CONTVENITAVANS,
  contgarantieEF,
  contgarantieTF,
  contgarantieEC,
  contgarantieTC,
	ContSuplimF1,
	ContSuplimF2,
	ContSuplimF3,
	ContSuplimF4,
	ContSuplimF5,

  ContSuplimF6 ,
  ContSuplimF7 ,
  ContSuplimF8 ,
  ContSuplimF9 ,
  ContSuplimF10 ,
  ContSuplimF11 ,
  ContSuplimF12 ,
  ContSuplimF13 ,
  ContSuplimF14 ,
  ContSuplimF15 ,
  ContSuplimF16 ,
  ContSuplimF17 ,
  ContSuplimF18 ,
  ContSuplimF19 ,
  ContSuplimF20 ,
  ContSuplimF21 ,
  ContSuplimF22 ,
  ContSuplimF23 ,
  ContSuplimF24 ,
  ContSuplimF25 ,
  ContSuplimF26 ,
  ContSuplimF27 ,
  ContSuplimF28 ,
  ContSuplimF29 ,
  ContSuplimF30 ,


	ContSuplimC1,
	ContSuplimC2,
	ContSuplimC3,
	ContSuplimC4,
	ContSuplimC5,
  ContTerti,
  TvaNeexF, TvaNeexP, TvaNeexI,TvaNeexC,Tip,anstart,lunastart FROM TMP_IOPART1 );

END IF;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila parteneri &quot;&apos;||den_iopart||&apos;&quot;&apos; into aDoc from iopart where codiopart = recid ;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPART&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  PRC_AL_REFRESH(&apos;IOPART1&apos;, RECID);
  NotifyModif(Operation, RecId, &apos;IOPART&apos;);
COMMIT;

END;



END pkg_ConfigPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONFIGPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C17CD5C5950B6D7061777B00BE4B9241F81688F7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONFIGPERS IS

CT_MONITOR constant varchar2(50) :=&apos;MON_10&apos;;

FUNCTION GETRECORDIOPERS(IOPERSCOD IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN Luna_ref_cursor IS
tmpcursor Luna_Ref_Cursor;
BEGIN
  BEGIN
    OPEN tmpCursor FOR
    SELECT *
    FROM IoPers1 i1
    WHERE i1.CodIoPers = IoPersCod AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
  EXCEPTION WHEN OTHERS THEN OPEN tmpCursor FOR SELECT -1 FROM DUAL;
  END;

  RETURN tmpcursor;
END;

FUNCTION GETCODCARACTLUNA(aCODIOPERS IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER
IS
aCODIOPERS1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODIOPERS1 INTO aCODIOPERS1
    FROM IoPers1 i1
    WHERE i1.CodIoPers = aCODIoPers AND An * 12 + Luna BETWEEN i1.ALStart AND i1.ALStop;
    EXCEPTION WHEN OTHERS THEN aCODIOPERS1 := 0;
  END;

  RETURN aCODIOPERS1;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodIOPERS INTO Tmp FROM IOPERS WHERE CodIOPERS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
adoc varchar2(200);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila personal &quot;&apos;||den_iopers||&apos;&quot;&apos; into aDoc from iopers where codiopers = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPERS&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
	DELETE FROM IOPERS1 WHERE CodIOPERS = RecId ;
  DELETE FROM IOPERS  WHERE CodIOPERS = RecId ;
  NotifyModif(2, RecId, &apos;IOPERS&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_IOPERS FIELDS( CodIOPERS ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT   NUMBER(4);
aLUNASFARSIT NUMBER(2);

BEGIN
-- Master IOPERS
  INSERT INTO  TMP_IOPERS ( CodIOPERS,DEN_IOPERS )
    ( SELECT CodIOPERS,DEN_IOPERS
      FROM IOPERS WHERE CodIOPERS = RecId ) ;

-- Detail IOPERS1
  INSERT INTO TMP_IOPERS1
   (CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII,  CONTGARANTII, CONTALTERETINERI, CONTAVANS,
    CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT, ANSTART, LUNASTART)
   (SELECT  CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL,
    CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT,  ANSTART, LUNASTART FROM IOPERS1 WHERE  CodIOPERS = RecId )  ORDER BY CODIOPERS1;


  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODIOPERS1, ANSTART, LUNASTART FROM TMP_IOPERS1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_IOPERS1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODIOPERS1 = V_REC.CODIOPERS1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);

  adoc varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master IOPERS
    SELECT  CodIOPers INTO RecId FROM TMP_IOPERS;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila personal &quot;&apos;||den_iopers||&apos;&quot;&apos; into aDoc from iopers where codiopers = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPERS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;


    UPDATE IOPERS SET ( DEN_IOPERS )
       = ( SELECT DEN_IOPERS
          FROM TMP_IOPERS )
      WHERE CodIOPERS = RecId ;


-- Detail IOPERS1

--   insert into tmp
--   select to_char(CodIOPart1) || &apos;-&apos;|| to_char(g_CodIOPart1) || &apos;-&apos; || to_char(recid)
--   from TMP_IOPART1;


    DELETE FROM IOPERS1 where CodIoPers = RecId and CodIoPers1 not in (Select CodIoPers1 from TMP_IOPERS1);

    INSERT INTO IOPERS1
       (CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA,
        CONTECHIPAMENT, CONTIMPOZIT, ANSTART, LUNASTART)

        SELECT  SEQ_IOPERS1_CODIOPERS1.NextVal, RecID, CONTAVANSDECONT, CONTIMPUTATII,
        CONTGARANTII, CONTALTERETINERI, CONTAVANS,
        CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL,
        CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT,
       ANSTART, LUNASTART FROM TMP_IOPERS1 WHERE CODIOPERS1 &lt; 0;


--    FOR v_rec IN ( SELECT * FROM TMP_IOPART1 WHERE NVL(CodIOPart1,-1) &lt;= g_CodIOPart1 ORDER BY CodIOPart1 ) LOOP
    FOR v_rec IN ( SELECT * FROM TMP_IOPERS1 WHERE NVL(CODIOPERS1,-1) &gt; 0 ORDER BY CODIOPERS1 ) LOOP
    UPDATE IOPERS1
    SET
     CONTAVANSDECONT  = v_rec.CONTAVANSDECONT,
     CONTIMPUTATII    = v_rec.CONTIMPUTATII,
     CONTGARANTII     = v_rec.CONTGARANTII,
     CONTALTERETINERI = v_rec.CONTALTERETINERI,
     CONTAVANS        = v_rec.CONTAVANS,
     CONTLIKI         = v_rec.CONTLIKI,
     CONTNERIDICATE   = v_rec.CONTNERIDICATE,
     CONTBOALA        = v_rec.CONTBOALA,
     CONTPARTSAL      = v_rec.CONTPARTSAL,
     CONTNATURA       = v_rec.CONTNATURA,
     CONTECHIPAMENT   = v_rec.CONTECHIPAMENT,
     CONTIMPOZIT      = v_rec.CONTIMPOZIT
    WHERE CodIOPERS1  = v_rec.CODIOPERS1;
    END LOOP;


  ELSE  -- RAMURA INSERT
-- Master IOPERS
--   insert into tmp values (&apos;ins&apos;);

  SELECT seq_IOPERS_CodIOPERS.NextVal INTO RecId FROM DUAL;


  INSERT INTO  IOPERS ( CodIOPERS,DEN_IOPERS )
 ( SELECT  RecId ,DEN_IOPERS  FROM TMP_IOPERS  ) ;


-- Detail IOPERS1
  INSERT INTO IOPERS1
   (CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA,
    CONTECHIPAMENT, CONTIMPOZIT, ANSTART, LUNASTART)

    SELECT  SEQ_IOPERS1_CODIOPERS1.NextVal, RecID, CONTAVANSDECONT, CONTIMPUTATII,
    CONTGARANTII, CONTALTERETINERI, CONTAVANS,
    CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL,
    CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT,
   ANSTART, LUNASTART FROM TMP_IOPERS1;


END IF;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   select &apos;caracterizare contabila personal &quot;&apos;||den_iopers||&apos;&quot;&apos; into aDoc from iopers where codiopers = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;IOPERS&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    pkg_globals.SUBUNITATE, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  PRC_AL_REFRESH(&apos;IOPERS1&apos;, RECID);
  NotifyModif(Operation, RecId, &apos;IOPERS&apos;);
COMMIT;

END;



END pkg_ConfigPers;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONSTMASTER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B982D73385F8A0100E30B26E85664D5EB1F0167</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_constmaster IS





PROCEDURE CHECK_CONSTANTE_USER(aUserID IN NUMBER)
IS
NR NUMBER(20) := 0;
NEWCODCONSTLUNA NUMBER(20) := 0;
BEGIN
  DELETE TMP_CONSTLUNA;
  DELETE TMP_CONSTVALPOS;
  DELETE TMP_CONSTVAL;
  INSERT INTO TMP_CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
  (SELECT CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID FROM CONSTLUNA
  WHERE
    USERID = 0 AND
    CODCONST1 IN
    (SELECT CODCONST1 FROM CONST1 WHERE CODCATEG IN (SELECT CODCATEG FROM CATEGCONST WHERE TIPCATEG = &apos;U&apos;))
  );
  INSERT INTO TMP_CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA)
  (SELECT COD, IDX, VALPOSIBILE, CODCONSTLUNA FROM CONSTVALPOS WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA));


  INSERT INTO TMP_CONSTVAL (VALOARE, CODCONSTLUNA)
  (SELECT VALOARE, CODCONSTLUNA FROM CONSTVAL WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA));


  FOR Rec_Constluna IN (SELECT * FROM TMP_CONSTLUNA ) LOOP

    SELECT COUNT(*) INTO NR FROM CONSTLUNA
    WHERE
    CODCONST1 = Rec_COnstLuna.CODCONST1 AND USERID = aUserID;

    IF NR = 0 THEN -- NU AM DESCRIERE LA NIVEL DE LUNA PENTRU USER-ul curent

      SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO NEWCODCONSTLUNA FROM DUAL;

      -- CONSTLUNA
      INSERT INTO CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
      VALUES
      (NEWCODCONSTLUNA,
       Rec_ConstLuna.CODCONST1,
       CASE
         WHEN Rec_ConstLuna.ANSTART = 0 THEN PKG_GLOBALS.ANINITIAL
         ELSE Rec_ConstLuna.ANSTART
       END,
       CASE
         WHEN Rec_ConstLuna.LUNASTART = 0 THEN PKG_GLOBALS.LUNAINITIALA
         ELSE Rec_ConstLuna.LUNASTART
       END,
       aUSERID
       );

      -- CONSTVALPOS
      FOR Martor_REC_CONSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = Rec_Constluna.CODCONSTLUNA)
      LOOP
        INSERT INTO CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA)
               VALUES (SEQ_CONSTVALPOS_COD.NEXTVAL, Martor_REC_CONSTVALPOS.IDX, Martor_REC_CONSTVALPOS.VALPOSIBILE, NEWCODCONSTLUNA);
      END LOOP;

      -- CONSTVAL
      FOR Martor_REC_CONSTVAL IN (SELECT * FROM TMP_CONSTVAL WHERE CODCONSTLUNA = Rec_Constluna.CODCONSTLUNA)
      LOOP
        INSERT INTO CONSTVAL (VALOARE, CODCONSTLUNA)
               VALUES (Martor_REC_CONSTVAL.VALOARE, NEWCODCONSTLUNA);
      END LOOP;

    END IF;
  END LOOP;

  COMMIT;

END;




PROCEDURE FETCHDATA
IS
  aANSFARSIT NUMBER(5) := 0;
  aLUNASFARSIT number(2) := 0;
BEGIN

  FOR V_REC IN
  (SELECT * FROM TABLE(WINMADMIN.pkg_userfirme.UserByCodFirma(PKG_GLOBALS.CODFIRMA)))
  LOOP
    CHECK_CONSTANTE_USER(V_REC.CODUTILIZATOR);
  END LOOP;



  DELETE TMP_CONST1EXT;
  DELETE TMP_CONSTLUNAEXT;
  DELETE TMP_CONSTVAL;
  DELETE TMP_CONSTVALPOS;
  DELETE TMP_USERSCONST;

  INSERT INTO TMP_CONST1EXT (CODCONST1, CODCATEG, INDEXLOCAL, SIMBOL, DENUMIRE, TIP, DENCATEG)
  SELECT
    C1.CODCONST1,
    C1.CODCATEG,
    C1.INDEXLOCAL,
    C1.SIMBOL,
    C1.DENUMIRE,
    C1.TIP,
    CT.DENUMIRE
  FROM
    CONST1 C1,
    CATEGCONST CT
  WHERE
    CT.CODCATEG = C1.CODCATEG
    AND CT.TIPCATEG = &apos;U&apos;
    AND NVL(TIP, 0) &gt; 0;

  INSERT INTO TMP_CONSTLUNAEXT (
    CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID,
    VALAFIS,
    USERNAME)
  SELECT
    CL.CODCONSTLUNA, CL.CODCONST1, CL.ANSTART, CL.LUNASTART, CL.USERID,
    pkg_categconst.GetValAfis(c1.Tip, cl.CodConstLuna) VALAFIS,
    UPPER(WinMAdmin.Pkg_Userfirme.getUserName(cl.userid)) USERNAME
  FROM CONSTLUNA CL, TMP_CONST1EXT C1
  WHERE CL.CODCONST1 = C1.CODCONST1
    AND CL.USERID &gt; 0
    AND WinMAdmin.Pkg_Userfirme.getUserName(cl.userid) NOT LIKE &apos;%nedef%&apos;;

  INSERT INTO TMP_CONSTVAL
  SELECT * FROM CONSTVAL CV
  WHERE
    EXISTS (SELECT CODCONSTLUNA FROM TMP_CONSTLUNAEXT WHERE CODCONSTLUNA = CV.CODCONSTLUNA);

  INSERT INTO TMP_CONSTVALPOS(COD, IDX,VALPOSIBILE,CODCONSTLUNA)
  SELECT COD, IDX,VALPOSIBILE,CODCONSTLUNA FROM CONSTVALPOS CV
  WHERE
    EXISTS (SELECT CODCONSTLUNA FROM TMP_CONSTLUNAEXT WHERE CODCONSTLUNA = CV.CODCONSTLUNA);


  FOR V_REC_USER IN (SELECT DISTINCT USERID FROM TMP_CONSTLUNAEXT)
  LOOP
    FOR VREC_CONST1 IN (SELECT CODCONST1 FROM TMP_CONST1EXT) LOOP
      aANSFARSIT := 0; aLUNASFARSIT := 0;
      FOR V_REC IN (SELECT CODCONSTLUNA, ANSTART, LUNASTART FROM TMP_CONSTLUNAEXT WHERE CODCONST1 = VREC_CONST1.CODCONST1 AND USERID = V_REC_USER.USERID ORDER BY ANSTART * 12 + LUNASTART DESC)
      LOOP
        IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
          UPDATE TMP_CONSTLUNAEXT
          SET
            ANSFARSIT   = aANSFARSIT,
            LUNASFARSIT = aLUNASFARSIT
           WHERE
           CODCONSTLUNA = V_REC.CODCONSTLUNA;
        END IF;

        PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
      END LOOP;
    END LOOP;
  END LOOp;

  INSERT INTO TMP_USERSCONST(USERID, USERNAME)
  SELECT DISTINCT USERID,  USERNAME FROM TMP_CONSTLUNAEXT;


  DELETE TMP_CONSTLUNAINI;
  INSERT INTO TMP_CONSTLUNAINI
  SELECT CODCONSTLUNA FROM TMP_CONSTLUNAEXT;

  UPDATE TMP_USERSCONST U
  SET
    GRUPNAME = (SELECT WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(U.USERID) FROM DUAL);

  COMMIT;

END;


PROCEDURE POSTDATA
IS
  aCOD NUMBER(20);
BEGIN

  FOR V_REC IN
  (
   SELECT * FROM CONSTLUNA CL
   WHERE
     EXISTS (SELECT CODCONSTLUNA FROM TMP_CONSTLUNAINI WHERE CODCONSTLUNA = CL.CODCONSTLUNA)
     AND NOT EXISTS (SELECT CODCONSTLUNA FROM TMP_CONSTLUNAEXT WHERE CODCONSTLUNA = CL.CODCONSTLUNA)
   )
   LOOP
     DELETE FROM CONSTVAL    WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
     DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
     DELETE FROM CONSTLUNA   WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
   END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_CONSTLUNAEXT WHERE CODCONSTLUNA &lt; 0)
  LOOP
    SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO aCOD FROM DUAL;
    UPDATE TMP_CONSTVAL
    SET
      CODCONSTLUNA = aCOD
    WHERE
      CODCONSTLUNA = V_REC.CODCONSTLUNA;

    UPDATE TMP_CONSTVALPOS
    SET
      CODCONSTLUNA = aCOD
    WHERE
      CODCONSTLUNA = V_REC.CODCONSTLUNA;

    INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
    VALUES(aCOD, V_REC.CODCONST1, V_REC.ANSTART, V_REC.LUNASTART, V_REC.USERID);


   FOR V_REC_CONSTVAL IN (SELECT * FROM TMP_CONSTVAL WHERE CODCONSTLUNA = aCOD)
   LOOP
     INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
     VALUES (V_REC_CONSTVAL.VALOARE, V_REC_CONSTVAL.CODCONSTLUNA);
   END LOOP;


   FOR V_REC_CONSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = aCOD)
   LOOP
     INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
     VALUES (SEQ_CONSTVALPOS_COD.NEXTVAL, V_REC_CONSTVALPOS.IDX, V_REC_CONSTVALPOS.VALPOSIBILE, V_REC_CONSTVALPOS.CODCONSTLUNA) ;
   END LOOP;


  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_CONSTLUNAEXT WHERE CODCONSTLUNA &gt; 0)
  LOOP

    UPDATE CONSTLUNA
    SET
      ANSTART   = V_REC.ANSTART,
      LUNASTART = V_REC.LUNASTART
    WHERE
      CODCONSTLUNA = V_REC.CODCONSTLUNA;


  DELETE FROM CONSTVAL WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
   FOR V_REC_CONSTVAL IN (SELECT * FROM TMP_CONSTVAL WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA)
   LOOP
     INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
     VALUES (V_REC_CONSTVAL.VALOARE, V_REC_CONSTVAL.CODCONSTLUNA);
   END LOOP;


   DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
   FOR V_REC_CONSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA)
   LOOP
     INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
     VALUES (SEQ_CONSTVALPOS_COD.NEXTVAL, V_REC_CONSTVALPOS.IDX, V_REC_CONSTVALPOS.VALPOSIBILE, V_REC_CONSTVALPOS.CODCONSTLUNA) ;
   END LOOP;


  END LOOP;


  COMMIT;
END;


end PKG_CONSTMASTER;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D022750A7D7C21C8AA579DD8C8AFE02DD73D4230</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONTRACT IS

  pCadouTipDoc     NUMBER;
  pCadouCodObj     NUMBER;
  pCadouPart       NUMBER;
  pCadouLocatie    NUMBER;
  pCadouSubunit    NUMBER;
  pCadouCantObj    NUMBER;
  pCadouDataRef    DATE;

  pCadIntrCodObj   NUMBER;
  pCadIntrPart     NUMBER;
  pCadIntrLocatie  NUMBER;
  pCadIntrSubunit  NUMBER;
  pCadIntrDataRef  DATE;
  pCadIntrCantObj  NUMBER;
  pCadIntrCant     NUMBER;
  pCadIntrCod      NUMBER;
  pCadIntrZec      NUMBER;
  pCadIntrDen      VARCHAR2(200);

  pCadIesCodObj    NUMBER;
  pCadIesPart      NUMBER;
  pCadIesLocatie   NUMBER;
  pCadIesSubunit   NUMBER;
  pCadIesDataRef   DATE;
  pCadIesCantObj   NUMBER;
  pCadIesCant      NUMBER;
  pCadIesCod       NUMBER;
  pCadIesZec       NUMBER;
  pCadIesDen       VARCHAR2(200);

  vCadouCant       NUMBER;
  vCadouCod        NUMBER;

  pLinContract     NUMBER;
  pPretContract    NUMBER;
  pPjDiscContr     NUMBER;
  pAdDimContr      NUMBER;
  pC1Anexa         NUMBER;
  pC1DataStart     DATE;
  pC1DataStop      DATE;

  pLinTipDoc       NUMBER;
  pLinCodObiect    NUMBER;
  pLinPart         NUMBER;
  pLinLocatie      NUMBER;
  pLinSubunit      NUMBER;
  pLinDataRef      DATE;

  pAbTipPlafonVal  NUMBER;
  pAbTipPlafonAn   NUMBER;
  pAbTipPlafonLuna NUMBER;

  pContor_IdxCC1   NUMBER;
  pContor_DataR    DATE;
  pContor_DataIni  DATE;
  pContor_IdxIni   NUMBER;
  pContor_DataFin  DATE;
  pContor_IdxFin   NUMBER;

  CT_MONITOR      CONSTANT VARCHAR2(50) := &apos;MON_29&apos;;

PROCEDURE Test IS
BEGIN
  PKG_GLOBALS.SETUSERID(1); COMMIT;
  PKG_GLOBALS.SETSUBUNITATE(2); COMMIT;
  PKG_GLOBALS.SETLUNALUCRU(2019, 1);
  PKG_CONTRACT.SP_GOTORECORD(115);
END;

PROCEDURE MakeVenitInAvans(aCODCONTRACT2 IN NUMBER)
IS
  aCODIOVENIT NUMBER(20);
  aCODCHELTAVANS NUMBER(20);
BEGIN
  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;IoArtVenitAvansAbon&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0) INTO aCODIOVENIT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aCODIOVENIT := 0;
  END;

  FOR V_REC IN (
    SELECT
     I1.CODIES1,
     I.AN,
     I.LUNA,
     ROUND(Coalesce(NullIF(I.CURS, 0), 1) * (I1.PU * I1.CANT), 2) AS VALOARE,
     C2.DATA,
     C2.DATASTOP,
     --ROUND(MONTHS_BETWEEN(C2.DATASTOP, C2.DATA)) AS LUNI,
     C.PERFACT AS LUNI,
     C1.CODIOART
    FROM
      CONTRACT2 C2,
      IESIRI I,
      IESIRI1 I1,
      CONTRACT1 C1,
      CONTRACT C
    WHERE
      C2.CODCONTRACT2 = aCODCONTRACT2
      AND I.CODIES = C2.CODDOC
      AND I.TIPDOC = C2.TIPDOC
      AND I1.CODIES = I.CODIES
      AND I1.CONTSERV IN (SELECT CONTVENITAVANS FROM tmp_contvenitavans)
      AND I1.CODCONTRACT1 = C1.CODCONTRACT1
      AND C.CODCONTRACT = C2.CODCONTRACT
  ) LOOP
    IF Coalesce(aCODIOVENIT, 0) + Coalesce(V_REC.CODIOART, 0) &lt;&gt; 0 THEN
      aCODCHELTAVANS :=  SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL;
      INSERT INTO MASTERCHELTAVANS(CODIES1) VALUES (V_REC.CODIES1);

      INSERT INTO CHELTAVANS(CODCHELTAVANS, ANINCEPUT, LUNAINCEPUT,CODIOART,CODIES1,ISVENIT)
      VALUES ( aCODCHELTAVANS, EXTRACT(YEAR FROM V_REC.DATA), EXTRACT(MONTH FROM V_REC.DATA), Coalesce(NULLIF(aCODIOVENIT, 0), V_REC.CODIOART), V_REC.CODIES1, 1);

      INSERT INTO CHELTAVANS1( CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART )
      VALUES  (SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, aCODCHELTAVANS, V_REC.VALOARE, V_REC.LUNI, V_REC.LUNI, 1, V_REC.AN, V_REC.LUNA);

      INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, ContD, Contc)
      VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, aCODCHELTAVANS, 106, aCODCHELTAVANS, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 0, 0);

      INSERT INTO JURNAL1(CODJURNAL1, CODDOC, INDEXLOCAL, TIPDOC, AN, LUNA, DIRTY)
      VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, aCODCHELTAVANS, aCODCHELTAVANS, 106, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 1);

    END IF;
  END LOOP;
END;


function GetCodContract1Part(aCodObiect in number, aDataDoc in date, aCodPart in number) return number is
vCodContract1 number(20);
BEGIN
  BEGIN
    select Coalesce(c1.CodContract1,0) into vCodContract1
    from contract1 c1
         inner join contract c on c1.codcontract = c.codcontract
    where C1.codobiect = aCodObiect and C.Partener = aCodPart
          and Coalesce(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataDoc
          and Coalesce(c.tiparticol,0) = 0;
  EXCEPTION WHEN OTHERS THEN
    vCodContract1 := 0;
  END;

  if vCodContract1 = 0 THEN
    BEGIN
      select Coalesce(c1.CodContract1,0) into vCodContract1
      from contract1 c1
           inner join nart a on a.clasa = c1.codclasa
           inner join nartobj obj on obj.codarticol = a.codarticol
           inner join contract c on c1.codcontract = c.codcontract
      where obj.codobiect = aCodObiect and C.Partener = aCodPart
            and Coalesce(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataDoc
            and Coalesce(c.tiparticol,0) = 1;
    exception WHEN others THEN
      vCodContract1 := 0;
    END;
  END if;

  return vCodContract1;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodContract INTO Tmp FROM CONTRACT WHERE CodContract = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aCarnetDoc  NUMBER (20);
  aNrDoc      NUMBER (20);
  aCodSubunit NUMBER(20);
  aDataDoc    DATE;
  aDoc        VARCHAR2(200);
  aTipDoc     NUMBER(20);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);

  SELECT  CarnetDoc, NrDoc, Subunitatea, DataDoc, Decode(TipDoc,10,&apos;CcF&apos;,25,&apos;CfL&apos;,27,&apos;CcC&apos;,34,&apos;CcA&apos;)||NrDoc||&apos;/&apos;||DataDoc, TipDoc
  INTO    aCarnetDoc, aNrDoc, aCodSubunit, aDataDoc, aDoc, aTipDoc
  FROM    CONTRACT
  WHERE   CodContract = recId;

  PKG_CFGTABLES.EXT_DELETERECORD (recId, aTipDoc);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;CONTRACT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM CONTRACTT  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = RecId);
  DELETE FROM CONTRACTC  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = RecId);
  DELETE FROM CONTRACTX  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = RecId);
  DELETE FROM CONTRACTXX WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = RecId);
 	DELETE FROM CONTRACTV  WHERE CodContract = RecId ;
 	DELETE FROM CONTRACT2  WHERE CodContract = RecId ;
 	DELETE FROM CONTRACT1  WHERE CodContract = RecId ;
 	DELETE FROM CONTRACT0  WHERE CodContract = RecId ;
  DELETE FROM CONTRACT   WHERE CodContract = RecId ;
/*  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;CONTRACTEXT&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM CONTRACTEXT WHERE CODCONTRACT = &apos; || RECID;
  END IF;*/

  PKG_CARNETEDOC.RELEASENUMARDOC(aCarnetDoc, aNrDoc);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCarnetDoc);

  FOR V_REC IN (SELECT * FROM JURNAL J WHERE  J.CODDOC = RECID AND TIPDOC = 25 )
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  DELETE FROM EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 25);
  DELETE FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 25;

  DELETE FROM JURNAL J   WHERE  J.CODDOC = RECID AND TIPDOC = 25;
  DELETE FROM JURNAL1 J  WHERE  J.CODDOC = RECID AND TIPDOC = 25;
  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = aTipDoc)or(CODDOCASOC = RECID AND TIPDOCASOC = aTipDoc);

  DELETE FROM PACKING1 P1 WHERE P1.CODPACKING IN (SELECT P.CODPACKING FROM PACKING P WHERE P.CODDOC = RECID AND P.TIPDOC = aTipDoc);
  DELETE FROM PACKING P WHERE P.CODDOC = RECID AND P.TIPDOC = aTipDoc;
  NotifyModif(2, RecId, &apos;CONTRACT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CONTRACT FIELDS( CodContract ) VALUES (0) ;
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(27);
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(10);
  PKG_CFGTABLES.EXT_INSERTRECORD(27);
  PKG_CFGTABLES.EXT_INSERTRECORD(10);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aNR       NUMBER (20);
  aTipDoc   NUMBER (20);
  NullDate  Date := To_Date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;);
  Cate      NUMBER(10);
  kCereale  NUMBER(10);
  sqlInsert CLOB;
BEGIN
  begin
  SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;ModulCereale&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 2) INTO kCereale FROM DUAL;
  EXCEPTION WHEN OTHERS THEN kCereale := 2;
  end;

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  -- Master Contract
  INSERT INTO TMP_Contract (
    CodContract, TipDoc, Anulat, Blocat, Operat, Activ, CarnetDoc, SeriaDoc, NrDoc, DataDoc,
    DataStart, DataStop, TipContract, TipTarget, Partener, CodLocatie, CodFiscal, CodPersC,
    Moneda, PerTarget, NrLuni,
    TipPerFact,Majorari,GRATIE,
    PerFact, ZiFact, ProcMaj, PerCitire, ZiCitire, TranspPart,
    Obs, Subunitatea, An, Luna,
    UserId, DataCreare, Agent,
    CURS, AVANS, DOBANDA, TIPDOBANDA, CALCDOBANDA, REZIDUALA, REZIDUALASEPARAT,
    ASIGANUAL, LUNIGRATIE, GRATIEFARADOB, CodBanca, ProcMajCurs, AUTOPRELUNGIRE, LUNIPRELUNGIRE,
    TIPARTICOL, TIPUM, TipTargetV, Semnat, Explicatii, Stopaj, CASS, CodAnaliza,
    FactLei, PF,
    Cadru, Suma1, Discount1, Suma2, Discount2, Suma3, Discount3, Suma4, Discount4,
    NRI, MaxReplSimultane, MaxZileRepla, TipLivrare, Codgeneric, FactPretStandard,
    CREDITE_PLAFON, CREDITE_PU)
  SELECT
    C.CodContract, C.TipDoc, C.Anulat, C.Blocat, C.Operat, C.Activ, C.CarnetDoc, C.SeriaDoc, C.NrDoc, C.DataDoc,
    C.DataStart, C.DataStop, C.TipContract, C.TipTarget, Coalesce(C.Partener,0), C.CodLocatie, C.CodFiscal, C.CodPersC,
    C.Moneda, C.PerTarget, C.NrLuni,
    CASE WHEN C.TipPerFact IS NOT NULL THEN C.TipPerFact WHEN C.TipDoc = 34 THEN 0 END, C.MAJORARI, C.GRATIE,
    C.PerFact, C.ZiFact, C.ProcMaj, C.PerCitire, C.ZiCitire, C.TranspPart,
    C.Obs, C.Subunitatea, C.An, C.Luna,
    C.UserId, C.DataCreare, C.Agent,
    C.CURS, Coalesce(C.AVANS, 0), C.DOBANDA, C.TIPDOBANDA, C.CALCDOBANDA, C.REZIDUALA, C.REZIDUALASEPARAT,
    C.ASIGANUAL, C.LUNIGRATIE, C.GRATIEFARADOB, C.CodBanca, C.ProcMajCurs,C.AUTOPRELUNGIRE, C.LUNIPRELUNGIRE,
    Coalesce(C.TIPARTICOL,0), C.TIPUM, Coalesce(C.TipTargetV,0), Coalesce(C.Semnat,0),C.Explicatii, C.Stopaj, C.CASS, C.CodAnaliza,
    Coalesce(C.FactLei,0), P.Persoanafizica,
    CASE WHEN Coalesce(C.Partener,0) = 0 THEN 1 ELSE 0 END Cadru,
    C.Suma1, C.Discount1, C.Suma2, C.Discount2, C.Suma3, C.Discount3, C.Suma4, C.Discount4,
    C.NRI, C.MaxReplSimultane, C.MaxZileRepla, C.TipLivrare, C.CodGeneric, Coalesce(C.FactPretStandard,0),
    C.CREDITE_PLAFON, C.CREDITE_PU
  FROM Contract C LEFT JOIN NPART P ON P.CodPArt = Coalesce(C.Partener,0)
  WHERE C.CodContract = RecId;

  BEGIN
    SELECT TipDoc INTO aTipDoc
		FROM TMP_Contract;
  EXCEPTION WHEN OTHERS THEN
	  aTipDoc := 0;
  END;
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(aTipDoc);
  INSERT INTO  TMP_RAC_CATPX ( codrac_catp, codpartener, codsediu, codgest, codsubunitate, datastart, datastop, obs, codcontract)
  SELECT codrac_catp, codpartener, codsediu, codgest, codsubunitate, datastart, datastop, obs, codcontract
  FROM RAC_CATP C
  WHERE C.CodContract = RecId;

	-- Detail Contract1
  CheckRecoltaArenda(RecID, PKG_GLOBALS.ANLUCRU);
  INSERT INTO  TMP_Contract1 (
    CodContract1, CodContract, CodObiect, UMSec,
    Cant, Pret,
    ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare, Obs, GestAct, CodIoart, CODOFERTA1, TVA, VALTARGET,
    LIMITACADOU, CANTCADOU, CODCADOU, CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount,
    SEDIULIVRARE,
    Anexa, DataStart, DataStop,
    IndexLocal,
    TipDiscountT,TipDiscountC,TipDiscountT1,CodClasa,
    DISCTCUMULAT, DISCT, CODCONTR1CADRU, CodCentru,
    TipObiect,TipLinie,
    DenObiect, DenObiectSec, DenCadou, DenUM, Paritate,
    ProcTva,
    CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa,
    cantglobal, DataLivr, Stare, pretstandard, CantUnitar,
    PU, SEL, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF, CODANALIZANOD, IndexParinte,
    CODAUTO, UTILAJ,
		CodIntr, CodIes, CodAE, CodClaseA, Den_ClaseA, Densediulivrare,
    TaxaUscare, TaxaConditionare, CodIntern, CodExtern, CodGrupa, DEN_GRECHIV, PRET_VANZARE,
    nrDocIntr,
    nrDocIes, LUscare, LConditionare,
    D1, D2, D3, CantUM1, PretUM1, RelatieUM1, UM1, DenUM1,
    PARITATECREDIT
	)
  SELECT
    C1.CodContract1, C1.CodContract, C1.CodObiect, CASE WHEN Coalesce(C.TipArticol,0) = 1 THEN 0 ELSE Coalesce(C1.UMSec,0) END,
    C1.Cant / U.Paritate, Coalesce(C1.Pret * U.Paritate, 0),
    Coalesce(C1.ProcDisc,0), Coalesce(C1.AdDim,0), Coalesce(C1.CANTOPTIM,0), Coalesce(C1.ZileL,0), Coalesce(C1.ZileC,0), Coalesce(C1.Lansare,0), C1.Obs, Coalesce(C1.GestAct,0),
    Coalesce(C1.CodIOART,0),
    C1.CODOFERTA1,
    Coalesce(C1.TVA,0), Coalesce(C1.VALTARGET, 0),
    Coalesce(C1.LIMITACADOU,0), Coalesce(C1.CANTCADOU, 0), Coalesce(C1.CODCADOU,0), Coalesce(C1.Codobiectsec, 0), Coalesce(C1.Limitacadousec, 0), C1.Termenfix, Coalesce(c1.TipPret,0), Coalesce(c1.TipDiscount,0),
    CASE WHEN Coalesce(C1.SediuLivrare,0) &gt; 0 THEN C1.SediuLivrare ELSE Coalesce(C.CodLocatie,0) END SediuLivrare,
    Coalesce(C1.Anexa,0), Coalesce(C1.DataStart,NullDate), Coalesce(C1.DataStop,NullDate),
    Dense_Rank() OVER (PARTITION BY C1.CodContract ORDER BY Coalesce(C1.IndexLocal,C1.CodContract1) ASC) IndexLocal, -- Recompactare IndexLocal - in Exe ultimul IndexLocal = RowNumber (din cauza ca exista mai nou ordonare/filtrare)
    Coalesce(C1.TIPDISCOUNTT, 0),Coalesce(C1.TIPDISCOUNTC, 0),Coalesce(C1.TIPDISCOUNTT1, 0),Coalesce(C1.CodClasa, 0),
    Coalesce(C1.DISCTCUMULAT,0), Coalesce(C1.DISCT, 0), Coalesce(CODCONTR1CADRU,0), Coalesce(C1.CodCentru,0),
    Coalesce(C1.TipObiect,0), CASE WHEN A.TipArticol = &apos;0&apos; THEN &apos;=&apos; WHEN C1.TipObiect =1 THEN &apos;V&apos; ELSE &apos;S&apos; END,
    O.Denumire, CASE WHEN Coalesce(C1.CodObiectSec,0) = 0 and TipDoc = 10 and TipContract = 3 THEN &apos;...Plata numerar...&apos; ELSE Coalesce(OS.Denumire, &apos;-&apos;) END,
		Coalesce(CDO.Denumire,&apos;-&apos;), U.Den_UM1, Coalesce(U.Paritate,1),
    PKG_SELECTARTICOLE.GETPROCENTTVA(O.CodArticol, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) ProcTva,
    O.CodArticol, AC.Denumire, AC.CodExtern, AC.CodLaClient, Coalesce(C1.SumaFixa,0),
    C1.cantglobal, C1.DataLivr, Stare, pretstandard, CASE WHEN Coalesce(C1.Cantglobal,0) &lt;&gt; 0 THEN C1.Cant/C1.cantglobal ELSE 0 END / U.Paritate CantUnitar,
    Coalesce(C1.Pret * U.Paritate * (1 + Coalesce(C1.AdDim/ 100,0)), 0) PU, 0 SEL, C1.CODUTILAJ, C1.UTILAJ_TIP_INDEX, Coalesce(C1.VERIFUMA, 0), C1.PLAFONCANTF, C1.CODANALIZANOD, C1.IndexParinte,
    C1.CODAUTO, OU.DENUMIRE||&apos;;&apos;||UT.MODEL||&apos;;&apos;||UT.SERIEF||CASE WHEN C.TipDoc = 34 THEN &apos;/&apos;||To_Char(Coalesce(UI.TIP_INDEX, 0))||&apos;;&apos;||UI.DENUMIRE ELSE &apos;&apos; END,
		BonA.CodIntr, Fact.CodIes, AE.CodIes, CLA.CODCLASEA, CLA.DEN_CLASEA, SL.OBS,
    C1.TaxaUscare, C1.TaxaConditionare, O.CodIntern, O.CodExtern, ECH.CODGRUPA, grech.denumire AS DEN_GRECHIV, PMM.LEI AS PRETVANZARE,
    COALESCE(BonA.Prefixdoc,&apos;&apos;) ||CASE WHEN BonA.Prefixdoc IS NULL THEN &apos;&apos; ELSE &apos; &apos; END ||COALESCE(To_Char(BonA.Nrdoc),&apos;&apos;),
    CASE
      WHEN Fact.CodIes IS NOT NULL THEN COALESCE(Fact.Prefixdoc,&apos;&apos;)||CASE WHEN Fact.Prefixdoc IS NULL THEN &apos;&apos; ELSE &apos; &apos; END||COALESCE(To_Char(Fact.Nrdoc),&apos;&apos;)
      ELSE                              COALESCE(AE.Prefixdoc,&apos;&apos;)  ||CASE WHEN AE.Prefixdoc   IS NULL THEN &apos;&apos; ELSE &apos; &apos; END||COALESCE(To_Char(AE.Nrdoc),&apos;&apos;)
    END, c1.luscare, c1.lconditionare,
    c1.d1, c1.d2, c1.d3, c1.CantUM1, c1.PretUM1, a.RelatieUM1, a.UM1, U1.DEN_UM1,
    c1.PARITATECREDIT
  FROM Contract C
    INNER JOIN Contract1 C1 ON C1.CodContract = C.CodContract
    LEFT JOIN NArtObj O ON O.CodObiect = C1.CodObiect
    LEFT JOIN NArt A ON A.CodArticol = O.CodArticol
    LEFT JOIN NCLASEA CLA ON CLA.CODCLASEA = A.CLASA
    LEFT JOIN NUM1 U ON U.CodUM1 = CASE WHEN Coalesce(C.TipArticol,0) = 1 THEN 0 ELSE Coalesce(C1.UMSec,0) END
    LEFT JOIN NUM1 U1 ON U1.CODUM = A.UM1 AND U1.SECUNDARA = 0
    LEFT JOIN NArtCli AC ON AC.CodObiect = C1.CodObiect AND AC.CodPart = C.Partener
    LEFT JOIN NArtObj CDO ON CDO.CodObiect = C1.CodCadou
    LEFT JOIN NArtObj OS ON OS.CodObiect = C1.CodObiectSec
    LEFT JOIN UTILAJE UT ON UT.CODUTILAJ = C1.CODUTILAJ
    LEFT JOIN UTILAJETIPINDEX UI ON UI.CODUTILAJ = C1.CODUTILAJ AND UI.TIP_INDEX = C1.UTILAJ_TIP_INDEX
    LEFT JOIN NARTOBJ OU ON OU.CODOBIECT = UT.CODOBIECT
    LEFT JOIN NAGENDA SL ON SL.CODAGENDA = C1.SEDIULIVRARE
    LEFT JOIN NECHIV ECH ON ECH.CODOBIECT = O.CODOBIECT
    LEFT JOIN GRECHIV GRECH ON grech.codgrechiv = ECH.codgrupa
    LEFT JOIN (
      SELECT DISTINCT I1.CodContract1, I.Codintr, I.Prefixdoc, I.Nrdoc
      FROM Intrari1 I1 INNER JOIN Intrari I ON I.CodIntr = I1.CodIntr
		  WHERE I.TipFactura = 20 AND I.TipDoc = 4 AND I.CODCONTRACT = RecId
    ) BonA ON BonA.CodContract1 = C1.CodContract1 AND C.TipDoc = 10 AND C.TipContract = 3
    LEFT JOIN (
      SELECT DISTINCT I1.CodContract1, I.CodIes, I.Prefixdoc, I.Nrdoc
      FROM Iesiri1 I1 INNER JOIN Iesiri I ON I.CodIes = I1.CodIes
		  WHERE I.TipFactura = 20 AND I.TipDoc = 19 AND I.CODCONTRACT = RecId
    ) Fact ON Fact.CodContract1 = C1.CodContract1 AND C.TipDoc = 10 AND C.TipContract = 3
    LEFT JOIN (
      SELECT DISTINCT I1.CodContract1, I.CodIes, I.Prefixdoc, I.Nrdoc
      FROM Iesiri1 I1 INNER JOIN Iesiri I ON I.CodIes = I1.CodIes
		  WHERE I.TipFactura = 20 AND I.TipDoc = 20 AND I.CODCONTRACT = RecId
    ) AE ON AE.CodContract1 = C1.CodContract1 AND C.TipDoc = 10 AND C.TipContract = 3
     LEFT JOIN TMP_MANPRETM PMM ON  PMM.CODOBIECT = O.CODOBIECT
  WHERE C.CodContract = RecId;

  UPDATE TMP_Contract1
  SET Valoare = PU * CANT, valoptim = pu * cantoptim;

  -- Detail Contract0
  INSERT INTO  TMP_CONTRACT0 (
    CodContract0, CodContract, Data, Suma, Curs, TipLinie, OldCurs, Facturat, Dobanda,
    CodDoc, TipDoc,
    NrDoc, DataDoc  )
  SELECT
    C0.CodContract0, C0.CodContract, C0.Data, C0.Suma, C0.Curs, Coalesce(C0.TipLinie, 1), C0.OldCurs, C0.Facturat, C0.Dobanda,
    C0.CodDoc, C0.TipDoc,
    CASE
      WHEN (R.CodReg IS NOT NULL) THEN R.NrDoc
      WHEN (I.Codintr IS NOT NULL) THEN I.NrDoc
      ELSE C0.NrDoc
    END,
    CASE
      WHEN (R.CodReg IS NOT NULL) THEN R.DATADOC
      WHEN (I.Codintr IS NOT NULL) THEN I.DATADOC
      ELSE C0.DATADOC
    END
  FROM CONTRACT0 C0
    LEFT JOIN Intrari I ON I.CodIntr = C0.CodDoc AND I.TipDoc = C0.TipDoc
    LEFT JOIN Reg R     ON R.CodReg  = C0.CodDoc AND R.TipReg = C0.TipDoc
  WHERE C0.CodContract = RecId;

  -- Detail Contract2
  INSERT INTO  TMP_Contract2 (
    CodContract2, CodContract, Data, DataStop, Suma,
    DOBANDA, ASIGURARE, TOTAL,
    CodDoc,
    TipDoc,
    Suspendat,
    SediuLivrare,
    IndexLocal,
    Facturat,
    NrDoc,
    DataDoc,
    ValDoc,
    CodDocT,
    TipDocT,
    FacturatT,
    SubunitDoc  )
  SELECT
    C2.CodContract2, C2.CodContract, C2.Data, C2.DataStop, C2.Suma,
    C2.DOBANDA, C2.ASIGURARE, Coalesce(C2.Suma, 0) + Coalesce(C2.DOBANDA, 0) + Coalesce(C2.ASIGURARE, 0) TOTAL,
    Case
      WHEN Coalesce(c2.TipDoc,0) =  1 THEN I.Codintr
      WHEN Coalesce(c2.TipDoc,0) = 19 THEN E.CodIes
      WHEN Coalesce(c2.TipDoc,0) = 58 THEN NC.CodNCredit
      WHEN Coalesce(c2.TipDoc,0) = 59 THEN NC.CodNCredit
      ELSE Null
    END CodDoc,
    Case
      WHEN Coalesce(c2.TipDoc,0) =  1 THEN I.TipDoc
      WHEN Coalesce(c2.TipDoc,0) = 19 THEN E.TipDoc
      WHEN Coalesce(c2.TipDoc,0) = 58 THEN NC.TipDoc
      WHEN Coalesce(c2.TipDoc,0) = 59 THEN NC.TipDoc
      ELSE Null
    END TipDoc,
    C2.Suspendat,
    CASE WHEN Coalesce(C2.SediuLivrare,0) &gt; 0 THEN C2.SediuLivrare ELSE Coalesce(C.CodLocatie,0) END SediuLivrare,
    ROW_NUMBER() OVER (PARTITION BY C2.SediuLivrare ORDER BY C2.IndexLocal ASC) IndexLocal, -- Recompactare IndexLocal - in Exe ultimul IndexLocal = RowNumber
    CASE
      WHEN (Coalesce(c2.TipDoc,0) =  1 and Coalesce(c2.CodDoc,0) &gt;  0 and I.Codintr     is not null) THEN 1
      WHEN (Coalesce(c2.TipDoc,0) = 19 and Coalesce(c2.CodDoc,0) &gt;  0 and E.CodIEs      is not null) THEN 1
      WHEN (Coalesce(c2.TipDoc,0) = 58 and Coalesce(c2.CodDoc,0) &gt;  0 and NC.CodNCredit is not null) THEN 1
      WHEN (Coalesce(c2.TipDoc,0) = 59 and Coalesce(c2.CodDoc,0) &gt;  0 and NC.CodNCredit is not null) THEN 1
      WHEN (Coalesce(c2.TipDoc,0) =  0 and Coalesce(c2.CodDoc,0) =  0 and Coalesce(C2.NRDoc,0) &gt; 0)  THEN 1
      ELSE 0
    END Facturat,
    Case
      WHEN (Coalesce(c2.TipDoc,0) =  1 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN I.NrDoc
      WHEN (Coalesce(c2.TipDoc,0) = 19 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN E.NrDoc
      WHEN (Coalesce(c2.TipDoc,0) = 58 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN Null
      WHEN (Coalesce(c2.TipDoc,0) = 59 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN Null
      ELSE C2.nrdoc
    END NrDoc,
    Case
      WHEN (Coalesce(c2.TipDoc,0) =  1 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN I.DataDoc
      WHEN (Coalesce(c2.TipDoc,0) = 19 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN E.DataDoc
      WHEN (Coalesce(c2.TipDoc,0) = 58 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN Null
      WHEN (Coalesce(c2.TipDoc,0) = 59 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN Null
      ELSE c2.datadoc
    END DataDoc,
    Case
      WHEN (Coalesce(c2.TipDoc,0) =  1 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN I.ValDoc
      WHEN (Coalesce(c2.TipDoc,0) = 19 and Coalesce(c2.CodDoc,0) &gt;  0 ) THEN E.ValDoc
      ELSE Null
    END ValDoc,
    Case
      WHEN Coalesce(c2.TipDocT,0) =  18 THEN Cc.CodComanda
      ELSE Null
    END CodDocT,
    Case
      WHEN Coalesce(c2.TipDocT,0) =  18 THEN Cc.TipDoc
      ELSE Null
    END TipDocT,
    Case
      WHEN (Coalesce(c2.TipDoc,0) = 58 and Coalesce(c2.CodDocT,0) &gt;  0 and NCT.CodNCredit is not null) THEN 1
      WHEN (Coalesce(c2.TipDoc,0) = 59 and Coalesce(c2.CodDocT,0) &gt;  0 and NCT.CodNCredit is not null) THEN 1
      WHEN (Coalesce(c2.TipDocT,0)= 18 and Coalesce(c2.CodDocT,0) &gt;  0)                                THEN 1
      ELSE 0
    END FacturatT,
    SD.Den_Subunit SubunitDoc
  FROM Contract2 C2
    INNER JOIN Contract C ON C2.CODCONTRACT = C.Codcontract
    LEFT JOIN Iesiri  E ON E.CodIes  = C2.CodDoc AND E.TipDoc = C2.TipDoc
    LEFT JOIN Intrari I ON I.CodIntr = C2.CodDoc AND I.TipDoc = C2.TipDoc
    LEFT JOIN NoteCredit NC ON NC.CodNCredit = C2.CodDoc AND NC.TipDoc = C2.TipDoc
    LEFT JOIN NoteCredit NCT ON NCT.CodNCredit = C2.CodDocT AND NCT.TipDoc = C2.TipDocT
    LEFT JOIN Comanda Cc ON Cc.CodComanda  = C2.CodDocT AND CC.TipDoc = C2.TipDocT
    LEFT JOIN NSUBUNIT SD ON SD.CODSUBUNIT = Decode(c2.TipDoc,1,I.Subunitatea, 19, E.Subunitatea, 58, NC.Subunitatea, 59, NC.Subunitatea, 0)
  WHERE C2.CodContract = RecId;

  -- Detail ContractSedii
  INSERT INTO TMP_ContractSedii ( SediuLivrare, SediuOk, adresa )
  select sd.SediuLivrare, 1,
         locc.Den_Localit||&apos;, &apos;||GetAdresa(nag.SECTOR, nag.STRADA, nag.NR1, nag.NR2, nag.BLOC, nag.SCARA, nag.ETAJ, nag.APART, nag.codpostal)
  from (
      SELECT DISTINCT c.SediuLivrare, 1
      FROM TMP_Contract1 c
      UNION
      SELECT DISTINCT C2.SediuLivrare, 0
      FROM TMP_Contract2 C2
      WHERE C2.CodContract = RecId AND NOT C2.SediuLivrare IN (SELECT DISTINCT SediuLivrare FROM tmp_contract1 C1 WHERE C1.CodContract = RecId) ) sd
   LEFT JOIN NAGENDA   nag  ON nag.CODAGENDA   = sd.SediuLivrare
   LEFT  JOIN NLOCALIT locc ON locc.CODLOCALIT = nag.Codlocalit;

  -- Detail ContractV = Volum tranz
  INSERT INTO  TMP_ContractV (
    CodContractV, CodContract, Suma, Discount, ValDiscount, CodContract1,
    IndexLocal)
  SELECT
    CodContractV, CodContract, Suma, Discount, ValDiscount, Coalesce(CodContract1,0) CodContract1,
    ROW_NUMBER() OVER (PARTITION BY CodContract, Coalesce(CodContract1,0) ORDER BY Suma ASC) IndexLocal
  FROM ContractV
  WHERE CodContract = RecId;

  -- Detail ContractT = Termene
  INSERT INTO  TMP_ContractT ( CodContractT, CodContract1, Zile, Termenfix, Discount, ValDiscount, ProcValDoc, IndexLocal, Cumulat)
  SELECT CC.CodContractT, CC.CodContract1, cc.Zile, cc.Termenfix, cc.Discount, cc.ValDiscount, cc.ProcValDoc, ROW_NUMBER() OVER (PARTITION BY CC.CodContract1 ORDER BY Zile ASC), Coalesce(c1.disctcumulat,0)
  FROM CONTRACTT CC INNER JOIN TMP_CONTRACT1 C1 ON C1.CodContract1 = CC.CodContract1;

  -- DETAIL ContractC = cant
  INSERT INTO TMP_CONTRACTC (CodContractC, CodContract1, CantMin, Discount, ValDiscount, IndexLocal )
  SELECT CC.CodContractC, CC.CodContract1, CC.CantMin / U1.PARITATE, CC.Discount, CC.ValDiscount,
	       ROW_NUMBER() OVER (PARTITION BY CC.CodContract1 ORDER BY CC.CantMin DESC )
  FROM CONTRACTC CC
    INNER JOIN TMP_CONTRACT1 C1 ON C1.CodContract1 = CC.CodContract1
    INNER JOIN NUM1 U1 ON U1.CODUM1 = C1.UMSEC
	where C1.Tipdiscountc &lt;&gt; 3;

  INSERT INTO TMP_CONTRACTC (CodContractC, CodContract1, CantMin, Discount, ValDiscount, IndexLocal )
  SELECT CC.CodContractC, CC.CodContract1, CC.CantMin / U1.PARITATE, CC.Discount, CC.ValDiscount,
	       ROW_NUMBER() OVER (PARTITION BY CC.CodContract1 ORDER BY CC.CantMin ASC)
  FROM CONTRACTC CC
    INNER JOIN TMP_CONTRACT1 C1 ON C1.CodContract1 = CC.CodContract1
    INNER JOIN NUM1 U1 ON U1.CODUM1 = C1.UMSEC
	where C1.Tipdiscountc = 3;

  INSERT INTO TMP_CONTRACTC0 (CodContractC0, CodContract, CantMin, Discount, ValDiscount, IndexLocal )
  SELECT CC0.CodContractC0, CC0.CodContract, CC0.CantMin, CC0.Discount, CC0.ValDiscount,
	       ROW_NUMBER() OVER (PARTITION BY CC0.CodContract ORDER BY CC0.CantMin ASC)
  FROM CONTRACTC0 CC0
       INNER JOIN TMP_CONTRACT C ON C.CodContract = CC0.CodContract;

  -- DETAIL ContractX = parametri cereale
  IF kCereale = 1 THEN
    INSERT INTO TMP_CONTRACTX (CodCONTRACTX, CodContract1, Parametru, ValMin, ProcPU, CORECTIEPU, IndexLocal )
    SELECT CC.CodCONTRACTX, CC.CodContract1, CC.Parametru, CC.ValMin, CC.ProcPU, CC.CORECTIEPU, ROW_NUMBER() OVER (PARTITION BY CC.CodContract1 ORDER BY CC.ValMin ASC) IndexLocal
    FROM CONTRACTX CC INNER JOIN TMP_CONTRACT1 C1 ON C1.CodContract1 = CC.CodContract1;

    IF aTipDoc in (10,27) THEN
      INSERT INTO TMP_CONTRACTXX (CODCONTRACTXX, CODCONTRACT1, PARAMETRU, VALSTART, VALSTOP, ABATERE, STARTPROC, STARTCORECTIE, PROC, CORECTIE, GENERARE)
      SELECT XX.CODCONTRACTXX, XX.CODCONTRACT1, XX.PARAMETRU, XX.VALSTART, XX.VALSTOP, XX.ABATERE, XX.STARTPROC, XX.STARTCORECTIE, XX.PROC, XX.CORECTIE, XX.GENERARE
      FROM CONTRACTXX xx INNER JOIN TMP_CONTRACT1 C1 ON C1.CodContract1 = xx.CodContract1;

      FOR v_rec in (select codcontract1 from tmp_contract1) LOOP
        FOR aNr in 1..20 LOOP
          SELECT Count(*) into Cate from Tmp_Contractxx where Parametru = aNr and codcontract1 = v_rec.codcontract1;
          IF Cate = 0 THEN
            INSERT INTO  TMP_ContractXX (codcontractxx, CodContract1, Parametru, GENERARE)
            Values(-1, v_rec.codcontract1, aNr, 0);
          ELSE
            Select Count(*) into Cate from Tmp_Contractx where Parametru = aNr and codcontract1 = v_rec.codcontract1;
            if Cate &gt; 0 THEN
              update tmp_contractxx set generare = 1 where parametru = aNr and codcontract1 = v_rec.codcontract1;
            END if;
          END IF;
        END LOOP;
      END loop;
    END IF;
  END IF;

  -- Detail ContractL = Grafic livrare
  DELETE FROM TMP_ContractL;
  INSERT INTO TMP_ContractL (
    CodContract1, CodObiect, UMSec, Pret, ProcDisc, ZileL, ZileC, Lansare, Anexa, DataStart, DataStop,
    Obs, GestAct, CodIOArt, CODOFERTA1, TVA, TipPret, CodClasa, AdDim, CantOptim, CodCentru, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF, CODANALIZANOD, IndexParinte, CODAUTO,
    TipObiect, TipLinie, DenObiect, DenUM, Paritate, ProcTva, CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa, PU, IndexLocal, TermenFix,
    CantGlobal, Stare, PretStandard, Utilaj, CodClaseA, Den_ClaseA,
    DataLivr,
    SediuLivrare,
    CantUnitar, Cant, Valoare,
    CodIntr, CodIes, CodAE, CodIntern, CodExtern, CodGrupa, DEN_GRECHIV, PRET_VANZARE, valoptim,
    D1, D2, D3, CantUM1, PretUM1, RelatieUM1, UM1, DenUM1,
    PARITATECREDIT
  )
  SELECT
    Indexlocal, CodObiect, UMSec, Pret, ProcDisc, ZileL, ZileC, Lansare, Anexa, DataStart, DataStop,
    Obs, GestAct, CodIOArt, CODOFERTA1, TVA, TipPret, CodClasa, AdDim, CantOptim, CodCentru, CodUtilaj, UTILAJ_TIP_INDEX, VERIFUMA, PlafonCantF, CodAnalizaNod, IndexParinte, CodAuto,
    TipObiect, TipLinie, DenObiect, DenUM, Paritate, ProcTva, CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa, PU, IndexLocal, TermenFix,
    CantGlobal, Stare, PretStandard, Utilaj, CodClaseA, Den_ClaseA,
    CASE WHEN aTipDoc NOT IN (10,27) THEN DataLivrG     WHEN Min(DataLivr)     = Max(DataLivr)     THEN Min(DataLivr)     ELSE NULL END DataLivr,
    CASE WHEN aTipDoc NOT IN (10,27) THEN SediuLivrareG WHEN Min(SediuLivrare) = Max(SediuLivrare) THEN Min(SediuLivrare) ELSE NULL END SediuLivrare,
    SUM(CantUnitar) CantUnitar, SUM(Cant) Cant, SUM(Valoare) Valoare,
		MAX(CodIntr) CodIntr, MAX(CodIes) CodIes, MAX(CodAE) CodAE, CodIntern, CodExtern, CodGrupa, DEN_GRECHIV, PRET_VANZARE,
    sum(valoptim),
    D1, D2, D3, CantUM1, PretUM1, RelatieUM1, UM1, DenUM1,
    PARITATECREDIT
  FROM (
    SELECT
      CodObiect, UMSec, Pret, ProcDisc, ZileL, ZileC, Lansare, Anexa, NullIf(DataStart, NullDate) DataStart, NullIf(DataStop, NullDate) DataStop,
      Obs, GestAct, CodIOArt, CODOFERTA1,  TVA, TipPret, CodClasa, AdDim, CantOptim, CodCentru, CodUtilaj, UTILAJ_TIP_INDEX, VERIFUMA, PlafonCantF, CodAnalizaNod, IndexParinte, CodAuto,
      TipObiect, TipLinie, DenObiect, DenUM, Paritate, ProcTva, CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa, PU, IndexLocal, TermenFix,
      CantGlobal, Stare, PretStandard, Utilaj, CodClaseA, Den_ClaseA,
      CASE WHEN aTipDoc NOT IN (10,27) THEN DataLivr      ELSE NULL END DataLivrG,     DataLivr,
      CASE WHEN aTipDoc NOT IN (10,27) THEN SediuLivrare  ELSE NULL END SediuLivrareG, SediuLivrare,
      Coalesce(CantUnitar,0) CantUnitar, Coalesce(Cant,0) Cant, Coalesce(Cant,0) * Coalesce(PU,0) Valoare, Coalesce(Cantoptim,0) * Coalesce(PU,0) Valoptim,
		  Coalesce(CodIntr,0) CodIntr, Coalesce(CodIes,0) CodIes, Coalesce(CodAE,0) CodAE, CodIntern, CodExtern, CodGrupa, DEN_GRECHIV, PRET_VANZARE,
      D1, D2, D3, CantUM1, PretUM1, RelatieUM1, UM1, DenUM1,
      PARITATECREDIT
    FROM TMP_Contract1
  ) T
  GROUP BY
    CodObiect, UMSec, Pret, ProcDisc, ZileL, ZileC, Lansare, Anexa, DataStart, DataStop, D1, D2, D3, CantUM1, PretUM1, RelatieUM1, UM1, DenUM1,
    Obs, GestAct, CodIOArt, CODOFERTA1,  TVA, TipPret, CodClasa, AdDim, CantOptim, CodCentru, CodUtilaj, UTILAJ_TIP_INDEX, VERIFUMA, PlafonCantF, CodAnalizaNod, IndexParinte, CodAuto,
    TipObiect, TipLinie, DenObiect, DenUM, Paritate, ProcTva, CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa, PU, IndexLocal, TermenFix,
    CantGlobal, Stare, PretStandard, Utilaj, CodClaseA, Den_ClaseA, CodIntern, CodExtern, CodGrupa, DataLivrG, SediuLivrareG, DEN_GRECHIV, PRET_VANZARE,
    PARITATECREDIT;

  UPDATE TMP_Contract C
  SET FACTURAT  = (SELECT MAX(Coalesce(Facturat,0)) FROM TMP_Contract2 WHERE CodContract = C.CodContract),
      VALOARE   = (SELECT Sum(Valoare * (1 + Coalesce(ProcDisc,0) / 100)) + Sum(Coalesce(TVA, 0) * (1 + Coalesce(ProcDisc,0) / 100)) FROM TMP_Contract1 WHERE CodContract = C.CodContract),
      VALSIMPLU = (SELECT Sum(pret*cant) FROM TMP_Contract1 WHERE CodContract = C.CodContract),
      VALDISC   = (SELECT Sum(Valoare * Coalesce(ProcDisc,0) / 100) + Sum(Coalesce(TVA, 0) * Coalesce(ProcDisc,0) / 100) FROM TMP_Contract1 WHERE CodContract = C.CodContract),
      VALOPTIM  = (SELECT Sum(valoptim) FROM TMP_Contract1 WHERE CodContract = C.CodContract);
      --SOLDPART = Decode(C.TipDoc, 10, -1, 27, 1, 0 ) * (SELECT SUM(Coalesce(SOLDLEI,0)) FROM V_SOLDPART WHERE CODPART = C.PARTENER);

  -- Detail ContractDF/DC
  INSERT INTO  TMP_ContractDC (
    CodUnic,  CodDoc, TipFact, CodPart, TipDoc, NrDoc, DataDoc, Obs, ValDoc, TVADoc, Den_Subunit  )
  SELECT ROWNUM, DC.*
  FROM (
  SELECT
    I.CodIes, I.TipFactura, I.Partener, I.TipDoc, I.PREFIXDOC ||&apos; &apos; ||I.SeriaDoc || I.NrDoc, I.DataDoc, substrB(I.Obs, 1, 450), I.ValDoc, I.Tvadoc, S.Den_Subunit
  FROM Iesiri I
       INNER JOIN NSUBUNIT S ON S.CodSubunit = I.Subunitatea
  where I.CODCONTRACT = RecId
  UNION ALL
  SELECT
    I.CodIes, I.TipFactura, I.Partener, I.TipDoc, I.PREFIXDOC ||&apos; &apos; ||I.SeriaDoc || I.NrDoc, I.DataDoc, substrB(I.Obs, 1, 450), I.ValDoc, I.Tvadoc, S.Den_Subunit
  FROM Iesiri I
       INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
       INNER JOIN NSUBUNIT S ON S.CodSubunit = I.Subunitatea
  where I1.CODCONTRACT1 IN (SELECT CODCONTRACT1 FROM TMP_CONTRACT1)
        AND COALESCE(I.CODCONTRACT,0) = 0
    ) DC;
  INSERT INTO  TMP_ContractDC (
    CodUnic,  CodDoc, TipFact, CodPart, TipDoc, NrDoc, DataDoc, Obs, ValDoc, TVADoc, Den_Subunit  )
  SELECT
    RowNum, I.CodComanda, 0, I.Partener, I.TipDoc, I.PREFIXDOC ||&apos; &apos; ||I.SeriaDoc || I.NrDoc, I.DataDoc, substrB(I.Obs, 1, 450), I.Valoare, 0, S.Den_Subunit
  FROM Comanda I INNER JOIN NSUBUNIT S ON S.CodSubunit = I.Subunitatea
  where I.CODCONTRACT = RecId and (I.TipDoc = 18);

  INSERT INTO  TMP_ContractDF (
    CodUnic,  CodDoc, TipFact, CodPart, TipDoc, NrDoc, DataDoc, Obs, ValDoc, TVADoc, Den_Subunit  )
  SELECT
    RowNum, I.Codintr, I.TipFactura, I.Partener, I.TipDoc, I.PREFIXDOC ||&apos; &apos; ||I.SeriaDoc || I.NrDoc, I.DataDoc, I.Obs, I.ValDoc, I.Tvadoc, S.Den_Subunit
  FROM Intrari I INNER JOIN NSUBUNIT S ON S.CodSubunit = I.Subunitatea
  where I.CODCONTRACT = RecId;
  INSERT INTO  TMP_ContractDF (
    CodUnic,  CodDoc, TipFact, CodPart, TipDoc, NrDoc, DataDoc, Obs, ValDoc, TVADoc, Den_Subunit  )
  SELECT
    RowNum, I.CodComanda, 0, I.Partener, I.TipDoc, I.PREFIXDOC ||&apos; &apos; ||I.SeriaDoc || I.NrDoc, I.DataDoc, I.Obs, I.Valoare, 0, S.Den_Subunit
  FROM Comanda I INNER JOIN NSUBUNIT S ON S.CodSubunit = I.Subunitatea
  where I.CODCONTRACT = RecId and I.TipDoc = 8;

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;CONTRACTEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_CONTRACTEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM TMP_CONTRACTEXT &apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_CONTRACTEXT SELECT * FROM CONTRACTEXT WHERE CODCONTRACT = &apos;||RECID;
  END IF;*/

  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  J WHERE TIPDOC = 25 AND  J.CODDOC = RECID  AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 J WHERE TIPDOC = 25 AND J.CODDOC  = RECID  AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

  DELETE FROM TMP_RULAJ;

  PKG_CFGTABLES.EXT_GOTORECORD(aTipDoc);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo        INTEGER := 0;
  vCod          NUMBER(20);
  vCodPart      NUMBER(20);
  vTipContractV NUMBER(1);
  aCarnetDoc    NUMBER(20);
  aNrDoc        NUMBER(20);
  aCodSubunit   NUMBER(20);
  aTipDoc       NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
  NR            NUMBER(20);
  vTipArticol   NUMBER(1);
  vTipTarget    NUMBER(10);
  vUpdArtCli    NUMBER;
  aDataStart date;
  aDataStop  date;
  kCereale number(10);
  aCodLocatie   NUMBER(20);
  aCount        NUMBER(10);
  OldUtilaj     NUMBER(20);
  aCntPack   Number(10);
  vCodPack  NUMBER(20);
BEGIN
  BEGIN
    kCereale := To_Number(Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ModulCereale&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;2&apos;));
  EXCEPTION WHEN OTHERS THEN
    kCereale := 2;
  END;
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  SELECT CodContract, DataStart,	DataStop, TipDoc, Coalesce(Partener,0), CarnetDoc, NrDoc, Subunitatea,
         DataDoc, CASE TipDoc WHEN 10 THEN &apos;CcF&apos; WHEN 27 THEN &apos;CcC&apos; ELSE &apos;&apos; END||To_Char(NrDoc)||&apos;/&apos;||To_Char(DataDoc, &apos;dd.mm.yyyy&apos;),
         TipTargetV, Coalesce(TipArticol,0), PerFact, CodLocatie
  INTO   RecId, aDataStart,	aDataStop, aTipDoc, vCodPart, aCarnetDoc, aNrDoc, aCodSubunit,
         aDataDoc, aDoc,
         vTipContractV, vTipArticol, vTipTarget, aCodLocatie
  FROM TMP_Contract;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (aTipDoc);
  UPDATE TMP_Contract1 C1
  SET (
          CodObiect, UMSec, Pret, ProcDisc, ZileL, ZileC, Lansare, Anexa, DataStart, DataStop,
          Obs, GestAct, CodIOArt, CODOFERTA1, TVA, TipPret, CodClasa, AdDim, CantOptim, CodCentru,
          TipObiect, TipLinie, DenObiect, DenUM, Paritate, ProcTva, CodArticol, DenArtCli, CodExtCli, CodLaClient, SumaFixa, PU,
          cantglobal, Stare, pretstandard,
          DataLivr,
					TermenFix,
          SediuLivrare,
          Cant,
          Valoare,
          CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF, CODANALIZANOD, IndexParinte, CODAUTO,
          D1, D2, D3, CantUM1, PretUM1,
          PARITATECREDIT
      )
    = ( SELECT
          CL.CodObiect, CL.UMSec, CL.Pret, CL.ProcDisc, CL.ZileL, CL.ZileC, CL.Lansare, CL.Anexa, CL.DataStart, CL.DataStop,
          CL.Obs, CL.GestAct, CL.CodIOArt, CL.CODOFERTA1, CL.TVA, CL.TipPret, CL.CodClasa, CL.AdDim, CL.CantOptim, CL.CodCentru,
          CL.TipObiect, CL.TipLinie, CL.DenObiect, CL.DenUM, CL.Paritate, CL.ProcTva, CL.CodArticol, CL.DenArtCli, CL.CodExtCli, CL.CodLaClient, CL.SumaFixa, CL.PU,
          CL.cantglobal, Stare, pretstandard,
					CASE WHEN aTipDoc IN (10, 27) THEN C1.DataLivr     ELSE CL.DataLivr     END DataLivr,
					CL.TermenFix,
          CASE WHEN aTipDoc IN (10, 27) THEN C1.SediuLivrare ELSE CL.SediuLivrare END SediuLivrare,
          CASE WHEN aTipDoc IN (10, 27) THEN C1.Cant         ELSE CL.Cant         END Cant,
          CASE WHEN aTipDoc IN (10, 27) THEN C1.Valoare      ELSE CL.Valoare      END Valoare,
          CL.CODUTILAJ, CL.UTILAJ_TIP_INDEX, CL.VERIFUMA, CL.PLAFONCANTF, CL.CODANALIZANOD, CL.IndexParinte, CL.CODAUTO,
          CL.D1, CL.D2, CL.D3, CL.CantUM1, CL.PretUM1,
          CL.PARITATECREDIT
        FROM TMP_ContractL CL
        WHERE CL.Indexlocal = C1.Indexlocal
      );

  IF vTipArticol = 1 THEN  -- stef - pe clase de articole este despre valoare
    UPDATE TMP_Contract1 C1
    SET Cant     = 1,
        Paritate = 1,
        UMSEC    = 0;
  END IF;

  -- stef - 04.05.2017 au fost niste probleme cu sediile de livrare la schimvbarea partenerului sau import din alte contracte
  -- pentru un plus de control mai fac o verificare inainte de postare ca sediul de livrare de pe contract1/2 sa apartina partenerului de pe contract

  MERGE INTO tmp_contract1 c1
  USING (
    SELECT DISTINCT c1.codcontract1, c.codlocatie sediulivrare
    FROM tmp_contract c
      inner join tmp_contract1 c1 ON c1.codcontract = c.codcontract
      inner join nagenda ag ON ag.codagenda = c1.sediulivrare
    WHERE Coalesce(c1.sediulivrare,0) &lt;&gt; 0
      AND Coalesce(c.partener, 0) &lt;&gt; Coalesce(ag.codpart, 0)
  ) tc1 ON (tc1.codcontract1 = c1.codcontract1)
  WHEN MATCHED THEN UPDATE SET c1.sediulivrare = tc1.sediulivrare;

  MERGE INTO tmp_contract2 c2
  USING (
    SELECT DISTINCT c2.codcontract2, c.codlocatie sediulivrare
    FROM tmp_contract c
      inner join tmp_contract2 c2 ON c2.codcontract = c.codcontract
      inner join nagenda ag ON ag.codagenda = c2.sediulivrare
    WHERE Coalesce(c2.sediulivrare,0) &lt;&gt; 0
      AND Coalesce(c.partener, 0) &lt;&gt; Coalesce(ag.codpart, 0)
  ) tc2 ON (tc2.codcontract2 = c2.codcontract2)
  WHEN MATCHED THEN UPDATE SET c2.sediulivrare = tc2.sediulivrare;

  IF vTipContractV = 2
  THEN DELETE FROM TMP_CONTRACTV WHERE CODCONTRACT1 =  0;
  ELSE DELETE FROM TMP_CONTRACTV WHERE CODCONTRACT1 &lt;&gt; 0;
  END IF;

  IF Operation = 0 THEN  -- UPDATE

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;CONTRACT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    -- Master Contract
    UPDATE Contract
    SET  (CodContract, TipDoc, Anulat, Blocat, Operat, Activ, CarnetDoc, SeriaDoc, NrDoc, DataDoc,
          DataStart, DataStop, TipContract, TipTarget, Partener, CodLocatie, CodFiscal, CodPersC,
          Moneda, PerTarget, NrLuni, TipPerFact, MAJORARI, GRATIE, PerFact, ZiFact, ProcMaj, PerCitire, ZiCitire, TranspPart,
          Obs, Subunitatea, UserId, DataCreare, Agent,
          CURS, AVANS, DOBANDA, TIPDOBANDA, CALCDOBANDA, REZIDUALA, REZIDUALASEPARAT,
          ASIGANUAL, LUNIGRATIE, GRATIEFARADOB, CodBanca, ProcMajCurs,AUTOPRELUNGIRE, LUNIPRELUNGIRE, TIPARTICOL, TIPUM, TipTargetV, Semnat,Explicatii, Stopaj, CASS, CodAnaliza,
          FactLei, Suma1, Suma2, Suma3, Suma4, Discount1, Discount2, Discount3, Discount4, NRI, MaxReplSimultane, MaxZileRepla, TipLivrare, Codgeneric, FactPretStandard,
          CREDITE_PLAFON, CREDITE_PU)
       = (SELECT
            CodContract, TipDoc, Anulat, Blocat, Operat, Activ, CarnetDoc, SeriaDoc, NrDoc, DataDoc,
            DataStart, DataStop, TipContract, TipTarget, Partener, CodLocatie, CodFiscal, CodPersC,
            Moneda, PerTarget, NrLuni, TipPerFact, MAJORARI, GRATIE, PerFact, ZiFact, ProcMaj, PerCitire, ZiCitire, TranspPart,
            Obs, Subunitatea, UserId, DataCreare, Agent,
            CURS, AVANS, DOBANDA, TIPDOBANDA, CALCDOBANDA, REZIDUALA, REZIDUALASEPARAT,
            ASIGANUAL, LUNIGRATIE, GRATIEFARADOB, CodBanca, ProcMajCurs,AUTOPRELUNGIRE, LUNIPRELUNGIRE, TIPARTICOL, TIPUM, TipTargetV, Semnat, Explicatii, Stopaj, CASS, CodAnaliza,
            FactLei,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma1 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma2 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma3 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma4 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount1 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount2 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount3 ELSE null END,
            CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount4 ELSE null END,
            NRI, MaxReplSimultane, MaxZileRepla, TipLivrare, CodGeneric, Coalesce(FactPretStandard,0),
            CREDITE_PLAFON, CREDITE_PU
          FROM TMP_Contract )
    WHERE CodContract = RecId;

    -- Detail Contract1
    DELETE FROM ContractV
    WHERE CodContract = RecID AND CodContractV NOT IN (SELECT CodContractV FROM TMP_ContractV);

    DELETE FROM CONTRACTT
    WHERE CodContract1 IN (SELECT C1.CodContract1
                           FROM Contract1 C1 LEFT JOIN TMP_Contract1 TC1 ON TC1.CodContract1 = C1.CodContract1
                           WHERE C1.CodContract = RecID AND TC1.CodContract1 IS NULL);


    DELETE FROM CONTRACTC
    WHERE CodContract1 IN (SELECT C1.CodContract1
                           FROM Contract1 C1 LEFT JOIN TMP_Contract1 TC1 ON TC1.CodContract1 = C1.CodContract1
                           WHERE C1.CodContract = RecID AND TC1.CodContract1 IS NULL);

    if kCereale = 1 then
      DELETE FROM CONTRACTX
      WHERE CodContract1 IN (SELECT C1.CodContract1
                             FROM Contract1 C1 LEFT JOIN TMP_Contract1 TC1 ON TC1.CodContract1 = C1.CodContract1
                             WHERE C1.CodContract = RecID AND TC1.CodContract1 IS NULL);

      IF aTipDoc in (10,27) THEN
        DELETE FROM CONTRACTXX
        WHERE CodContract1 IN (SELECT C1.CodContract1
                               FROM Contract1 C1 LEFT JOIN TMP_Contract1 TC1 ON TC1.CodContract1 = C1.CodContract1
                               WHERE C1.CodContract = RecID AND TC1.CodContract1 IS NULL);
      END IF;
    end if;

    DELETE FROM Contract1 C1
    WHERE C1.CodContract = RecID
      AND NOT EXISTS (SELECT 1 FROM TMP_Contract1 TC1 WHERE TC1.CodContract1 = C1.CodContract1);

    FOR v_rec IN (
      SELECT
        CodContract1, CodContract, CodObiect, UmSec, Cant * Paritate Cant, Pret / Paritate Pret,
        ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
        LIMITACADOU, CANTCADOU, CODCADOU,
        CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount, SEDIULIVRARE,
        Anexa, DataStart, DataStop, TIPDISCOUNTT, TIPDISCOUNTC, SumaFixa, TIPDISCOUNTT1, CodClasa,
        cantglobal, DataLivr, Stare, pretstandard,
        DiscTCumulat, DiscT, CodContr1Cadru, CodCentru, TipObiect, Indexlocal, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF, CODANALIZANOD, IndexParinte, CODAUTO,
        TaxaUscare, TaxaConditionare,LUscare, LConditionare,D1, D2, D3, CantUM1, PretUM1,
        PARITATECREDIT
      FROM TMP_Contract1
      ORDER BY IndexLocal)
    LOOP
      DELETE FROM TMP_CONTRACTT WHERE CodContract1 = v_rec.CodContract1 AND Coalesce(CUMULAT,0) &lt;&gt; Coalesce(v_rec.DiscTCumulat,0);
      IF Coalesce(v_rec.CodContract1,0) &gt; 0 THEN
        BEGIN
          SELECT coalesce(codutilaj,0) INTO OldUtilaj FROM contract1 WHERE codcontract1 = v_rec.codcontract1;
        EXCEPTION
          WHEN OTHERS THEN OldUtilaj := -1;
        END;
        UPDATE Contract1
        SET    CodObiect        = v_rec.CodObiect,
               UMSec            = v_rec.UMSec,
               Cant             = v_rec.Cant,
               Pret             = v_rec.Pret,
               ProcDisc         = v_rec.ProcDisc,
               AdDim            = v_rec.AdDim,
               CANTOPTIM        = v_rec.CANTOPTIM,
               ZileL            = v_rec.ZileL,
               ZileC            = v_rec.ZileC,
               Lansare          = v_rec.Lansare,
               Obs              = v_rec.Obs,
               GestAct          = v_rec.GestAct,
               CodIOArt         = v_rec.CodIOArt,
               CODOFERTA1       = v_rec.CODOFERTA1,
               TVA              = v_rec.TVA,
               VALTARGET        = V_REC.VALTARGET,
               LIMITACADOU      = v_rec.LIMITACADOU,
               CANTCADOU        = v_rec.CANTCADOU  ,
               CODCADOU         = V_REC.CODCADOU   ,
               CODOBIECTSEC     = v_rec.CODOBIECTSEC,
               LIMITACADOUSEC   = v_rec.LIMITACADOUSEC,
               TERMENFIX        = v_rec.TERMENFIX,
               TIPPRET          = v_rec.TIPPRET,
               TipDiscount      = v_rec.TipDiscount,
               SEDIULIVRARE     = v_rec.SEDIULIVRARE,
               cantglobal       = v_rec.cantglobal,
							 Stare            = v_rec.Stare,
							 DataLivr         = v_rec.DataLivr,
							 pretstandard     = v_rec.pretstandard,
               Anexa            = v_rec.Anexa,
               DataStart        = v_rec.DataStart,
               DataStop         = v_rec.DataStop,
               TipDiscountT     = v_rec.TipDiscountT,
               TipDiscountC     = v_rec.TipDiscountC,
               SumaFixa         = v_rec.SumaFixa,
               TipDiscountT1    = v_rec.TipDiscountT1,
               CodClasa         = v_rec.CodClasa,
               DiscTCumulat     = Coalesce(v_Rec.DiscTCumulat, 0),
               DiscT            = Coalesce(v_Rec.DiscT, 0),
               CodContr1Cadru   = v_Rec.CodContr1Cadru,
               Indexlocal       = v_rec.Indexlocal,
               CodCentru        = v_Rec.CodCentru,
							 TipObiect        = v_rec.TipObiect,
               CODUTILAJ        = V_REC.CODUTILAJ,
               UTILAJ_TIP_INDEX = V_REC.UTILAJ_TIP_INDEX,
               VERIFUMA         = V_REC.VERIFUMA,
               PLAFONCANTF      = V_REC.PLAFONCANTF,
               CODANALIZANOD    = V_REC.CODANALIZANOD,
               IndexParinte     = V_REC.IndexParinte,
               CODAUTO          = V_REC.CODAUTO,
               TaxaUscare       = v_rec.TaxaUscare,
               TaxaConditionare = v_rec.taxaconditionare,
               LUscare          = v_rec.LUscare,
               D1               = v_rec.D1,
               D2               = v_rec.D2,
               D3               = v_rec.D3,
               CantUM1          = v_rec.CantUM1,
               PretUM1          = v_rec.PretUM1,
               LConditionare    = v_rec.Lconditionare,
               PARITATECREDIT   = v_rec.PARITATECREDIT
        WHERE  CodContract = RecID AND CodContract1 = v_rec.CodContract1;

        IF aTipDoc = 34 AND v_Rec.Codutilaj &gt; 0 AND OldUtilaj &lt;&gt; v_rec.codutilaj THEN
          aCount := 0;
          SELECT count(1) INTO aCount FROM utilaje1 WHERE codutilaj = v_rec.codutilaj;
          aCount := aCount + 1;
          UPDATE utilaje1 SET status_part = 3    WHERE codutilaj = oldutilaj       AND codpart = vcodpart;
          UPDATE utilaje  SET codpart = vcodpart WHERE codutilaj = v_rec.codutilaj;
          UPDATE utilaje1 SET status_part = 3    WHERE codutilaj = v_rec.codutilaj AND status_part = 2;
          INSERT INTO UTILAJE1( CODUTILAJ1, CODUTILAJ, NRCONTR, CARNETCONTR, STATUS_PART, STATUS_DEPO, CODPART, CODLOCATIE, DATA, USERID, DATACREARE, STATUS_SERVICE, INDEXLOCAL, ESTETIC)
          VALUES(seq_utilaje1_codutilaj1.nextval, v_rec.codutilaj, aNrDoc, aCarnetDoc, 2, 0, vCodPart, aCodLocatie, aDataStart, pkg_globals.GETUSERID, sysdate, 0, aCount, 0);
        END IF;

        DELETE FROM CONTRACTC C
        WHERE C.CodContract1 = v_rec.CodContract1
          AND NOT EXISTS (SELECT 1 FROM TMP_CONTRACTC TC WHERE TC.CodContract1 = C.CodContract1 AND TC.CodContractC = C.CodContractC);

        DELETE FROM CONTRACTT C
        WHERE C.CodContract1 = v_rec.CodContract1
          AND NOT EXISTS (SELECT 1 FROM TMP_CONTRACTT TC WHERE TC.CodContract1 = C.CodContract1 AND TC.CodContractT = C.CodContractT);

        if kCereale = 1 then
          DELETE FROM CONTRACTX C
          WHERE C.CodContract1 = v_rec.CodContract1
            AND NOT EXISTS (SELECT 1 FROM TMP_CONTRACTX TC WHERE TC.CodContract1 = C.CodContract1 AND TC.CodCONTRACTX = C.CodContractX);

          if aTipDoc in (10,27) THEN
            DELETE FROM CONTRACTXX C
            WHERE C.CodContract1 = v_rec.CodContract1
              AND NOT EXISTS (SELECT 1 FROM TMP_CONTRACTXX TC WHERE TC.CodContract1 = C.CodContract1 AND TC.CodCONTRACTXX = C.CodContractXX);
          END if;
        end if;

      ELSE
        vCod := seq_Contract1_CodContract1.NEXTVAL;
        UPDATE TMP_CONTRACTC  SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
        UPDATE TMP_CONTRACTT  SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
        UPDATE TMP_CONTRACTV  SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;Contract1&apos;, vCod,v_rec.CodContract1);
        IF kCereale = 1 THEN
          UPDATE TMP_CONTRACTX  SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
          IF aTipDoc in (10,27) THEN
            UPDATE TMP_CONTRACTXX SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
          END IF;
        END IF;

        INSERT INTO  Contract1(
          CodContract1, CodContract, CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
          Anexa, DataStart, DataStop, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
          LIMITACADOU,
          CANTCADOU  ,
          cantglobal, DataLivr, Stare, pretstandard,
          CODCADOU,CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount, SEDIULIVRARE,
          TipDiscountT, TipDiscountC, SumaFixa, TipDiscountT1, CodClasa,
          DiscTCumulat, DiscT, CodContr1Cadru, codCentru, TipObiect,Indexlocal, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA,
          PLAFONCANTF, CODANALIZANOD, IndexParinte, CODAUTO, TaxaUscare, Taxaconditionare, LUscare, Lconditionare,
          D1, D2, D3, CantUM1, PretUM1,
          PARITATECREDIT
        )
        VALUES (
          vCod, RecId, v_rec.CodObiect, v_rec.UMSec, v_rec.Cant, v_rec.Pret, v_rec.ProcDisc, v_rec.AdDim, v_rec.CANTOPTIM, v_rec.ZileL, v_rec.ZileC, v_rec.Lansare,
          v_rec.Anexa, v_rec.DataStart, v_rec.DataStop, v_rec.Obs, v_rec.GestAct, v_rec.CodIOArt, v_rec.CODOFERTA1, v_rec.TVA, V_REC.VALTARGET,
          v_rec.LIMITACADOU,
          v_rec.CANTCADOU  ,
          v_rec.cantglobal, v_rec.DataLivr, v_rec.Stare, v_rec.pretstandard,
          v_rec.CODCADOU,v_rec.CODOBIECTSEC, v_rec.LIMITACADOUSEC, v_rec.TERMENFIX, v_rec.TIPPRET, v_rec.TipDiscount, v_rec.SEDIULIVRARE,
          Coalesce(v_Rec.tipdiscountt, 0), Coalesce(v_Rec.tipdiscountc, 0), v_rec.SumaFixa, Coalesce(v_Rec.tipdiscountt1, 0), Coalesce(v_Rec.CodClasa, 0),
          Coalesce(v_Rec.DiscTCumulat, 0), Coalesce(v_Rec.DiscT, 0), v_Rec.CodContr1Cadru, v_Rec.CodCentru, v_rec.TipObiect, v_rec.Indexlocal, V_REC.CODUTILAJ, V_REC.UTILAJ_TIP_INDEX, V_REC.VERIFUMA,
          v_rec.PLAFONCANTF, v_rec.CODANALIZANOD, v_rec.IndexParinte, v_rec.CODAUTO, v_rec.TaxaUscare, v_rec.TaxaConditionare, v_rec.LUscare, v_rec.LConditionare,
          v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CantUM1, v_rec.PretUM1,
          v_rec.PARITATECREDIT
        );
        if aTipDoc = 34 then
          aCount := 0;
          select count(*) into aCount from utilaje1 where codutilaj = v_rec.codutilaj;
          aCount := aCount + 1;
          update utilaje set codpart = vcodpart where codutilaj = v_rec.codutilaj;
          update utilaje1 set status_part = 3 where codutilaj = v_rec.codutilaj and status_part = 2;
          insert into UTILAJE1(CODUTILAJ1, CODUTILAJ, NRCONTR, CARNETCONTR, STATUS_PART, STATUS_DEPO, CODPART, CODLOCATIE, DATA, USERID, DATACREARE, STATUS_SERVICE, INDEXLOCAL, ESTETIC)
          values(seq_utilaje1_codutilaj1.nextval, v_rec.codutilaj, aNrDoc, aCarnetDoc, 2, 0, vCodPart, aCodLocatie, aDataStart, pkg_globals.GETUSERID, sysdate, 0, aCount, 0);
        end if;
      END IF;
    END LOOP;

    -- Detail Contract2
    DELETE FROM Contract2
    WHERE CodContract = RecID AND CodContract2 NOT IN (SELECT CodContract2 FROM TMP_Contract2);

    FOR v_rec IN (SELECT * FROM TMP_Contract2 ORDER BY Data Asc) LOOP
      IF Coalesce(v_rec.CodContract2,0) &gt; 0 THEN
        UPDATE Contract2
        SET    Data         = v_rec.Data,
               DataStop     = v_rec.DataStop,
               Suma         = v_rec.Suma,
               DOBANDA      = v_rec.DOBANDA  ,
               ASIGURARE    = v_rec.ASIGURARE,
               CodDoc       = v_rec.CodDoc,
               TipDoc       = v_rec.TipDoc,
               Suspendat    = v_rec.Suspendat,
               SediuLivrare = v_rec.Sediulivrare,
               IndexLocal   = v_rec.Indexlocal,
               NrDoc        = v_rec.NrDoc,
               DataDoc      = v_Rec.Datadoc,
               CodDocT      = v_rec.CodDocT,
               TipDocT      = v_rec.TipDocT
        WHERE  CodContract  = RecID AND CodContract2 = v_rec.CodContract2;
      ELSE
        SELECT seq_Contract2_CodContract2.NEXTVAL INTO vCod from dual;
        INSERT INTO  Contract2 (CodContract2, CodContract, Data,  DataStop,  Suma, DOBANDA, ASIGURARE, CodDoc, TipDoc, Suspendat, SediuLivrare, IndexLocal, NrDoc, DataDoc, CodDocT, TipDocT)
        VALUES (vCod , RecId, v_rec.Data, v_rec.DataStop, v_rec.Suma, v_rec.DOBANDA, v_rec.ASIGURARE, v_rec.CodDoc, v_rec.TipDoc, v_rec.Suspendat, v_rec.SediuLivrare, v_rec.IndexLocal, v_Rec.NrDoc, v_Rec.DataDoc
               , v_rec.CodDocT, v_rec.TipDocT);
      END IF;
    END LOOP;

    -- Detail CONTRACT0
    DELETE FROM CONTRACT0
    WHERE CodContract = RecID AND CodContract0 NOT IN (SELECT CodContract0 FROM TMP_CONTRACT0);

    DELETE FROM CONTRACTC0 C0
    WHERE C0.CodContract = RECID
          AND NOT EXISTS (SELECT 1 FROM TMP_CONTRACTC0 TC0 WHERE TC0.CodContractC0 = C0.CodContractC0);

    FOR v_rec IN (SELECT * FROM TMP_ContractC0) LOOP
      IF Coalesce(v_rec.CodContractC0,0) &gt; 0 THEN
        UPDATE ContractC0
        SET CantMin     = V_REC.Cantmin,
            Discount    = V_REC.Discount,
            ValDiscount = V_REC.Valdiscount
        WHERE CodContractC0 = V_REC.CODCONTRACTC0;
      ELSE
        SELECT seq_ContractC0_CodContractC0.NEXTVAL INTO vCod from dual;
        INSERT INTO  ContractC0(Codcontractc0,
                                Codcontract,
                                Cantmin,
                                Discount,
                                Valdiscount)
        VALUES (vCod , RecId, V_REC.Cantmin, V_REC.Discount, V_REC.Valdiscount);
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_CONTRACT0 ORDER BY DATA Asc) LOOP
      IF Coalesce(v_rec.CodContract0,0) &gt; 0 THEN
        UPDATE CONTRACT0
        SET    Data       = v_rec.Data,
               Suma       = v_rec.Suma,
               Curs       = v_rec.Curs,
               TipLinie   = v_rec.TipLinie,
               OldCurs    = v_rec.OldCurs,
               CodDoc     = v_rec.CodDoc,
               TipDoc     = v_rec.TipDoc,
               Facturat   = v_rec.Facturat,
               Dobanda    = v_rec.Dobanda,
               NrDoc      = v_rec.nrdoc,
               DataDoc    = v_rec.DataDoc
        WHERE  CodContract = RecID AND CodContract0 = v_rec.CodContract0;
      ELSE
        SELECT seq_CONTRACT0_CodContract0.NEXTVAL INTO vCod from dual;
        INSERT INTO  CONTRACT0 (CodContract0, CodContract, Data, Curs, TipLinie, OldCurs, Suma, CodDoc, TipDoc, Facturat, Dobanda, NrDoc, DataDoc)
        VALUES (vCod, RecId, v_rec.Data, v_rec.Curs, v_rec.TipLinie, v_rec.OldCurs, v_rec.Suma, v_rec.CodDoc, v_rec.TipDoc, v_rec.Facturat, v_rec.Dobanda, v_rec.NrDoc, v_rec.DataDoc);
      END IF;
    END LOOP;

    -- Detail ContractV
    FOR v_rec IN (SELECT * FROM TMP_ContractV ORDER BY Suma DESC) LOOP
      IF Coalesce(v_rec.CodContractV,0) &gt; 0 THEN
        UPDATE ContractV
        SET    Suma         = v_rec.Suma,
               Discount     = v_rec.Discount,
               ValDiscount  = v_rec.ValDiscount,
               CodContract1 = v_rec.CodContract1
        WHERE  CodContract = RecID AND CodContractV = v_rec.CodContractV;
      ELSE
        SELECT seq_ContractV_CodContractV.nextval INTO vCod from dual;
        INSERT INTO  ContractV (CodContractV, CodContract, Suma, Discount, ValDiscount, CodContract1)
        VALUES (vCod, RecId, v_rec.Suma, v_rec.Discount, v_rec.ValDiscount, v_rec.CodContract1);
      END IF;
    END LOOP;

    -- Detail ContractT
    FOR v_rec IN (SELECT * FROM TMP_ContractT ORDER BY CodContract1 Asc, Zile Asc) LOOP
      IF Coalesce(v_rec.CodContractT,0) &gt; 0 THEN
        UPDATE ContractT
        SET    CodContract1 = v_rec.CodContract1,
               Zile         = v_rec.Zile,
               TermenFix    = v_rec.TermenFix,
               Discount     = v_rec.Discount,
               ValDiscount  = v_rec.ValDiscount,
               ProcValDoc   = v_rec.ProcValDoc
        WHERE  CodContractT = v_rec.CodContractT;
      ELSE
        SELECT seq_ContractT_CodContractT.NEXTVAL INTO vCod FROM dual;
        INSERT INTO  ContractT (CodContractT, CodContract1, Zile, TermenFix, Discount, Valdiscount, ProcValDoc)
        VALUES (vCod, v_rec.CodContract1, v_rec.Zile, v_rec.TermenFix, v_rec.Discount, v_rec.ValDiscount, v_rec.ProcValDoc);
      END IF;
    END LOOP;

    -- detail ContractC
    FOR v_rec IN (SELECT * FROM TMP_CONTRACTC ORDER BY CodContract1 Asc, CantMin Desc) LOOP
      IF Coalesce(v_rec.CodContractC,0) &gt; 0 THEN
        UPDATE CONTRACTC
        SET    CodContract1  = v_rec.CodContract1,
               CantMin       = v_rec.CantMin,
               Discount      = v_rec.Discount,
               ValDiscount   = v_rec.ValDiscount
        WHERE  CodContractC  = v_rec.CodContractC;

      ELSE
        SELECT seq_ContractC_CodContractC.NEXTVAL INTO vCod FROM dual;
        INSERT INTO CONTRACTC ( CodContractC, CodContract1, CantMin, Discount, ValDiscount)
        VALUES (vCOD, v_rec.CodContract1, v_rec.CantMin, v_rec.Discount, v_rec.ValDiscount) ;
      END IF;
    END LOOP;

    -- detail CONTRACTX
    if kCereale = 1 then
      FOR v_rec IN (SELECT * FROM TMP_CONTRACTX ORDER BY CodContract1 Asc, ValMin Desc) LOOP
        IF Coalesce(v_rec.CodCONTRACTX,0) &gt; 0 THEN
          UPDATE CONTRACTX
          SET    CodContract1  = v_rec.CodContract1,
                 ValMin        = v_rec.ValMin,
                 ProcPU        = v_rec.ProcPU,
                 CORECTIEPU    = v_rec.CORECTIEPU,
                 Parametru     = v_rec.Parametru
          WHERE  CodCONTRACTX  = v_rec.CodCONTRACTX;

        ELSE
          SELECT seq_CONTRACTX_CodCONTRACTX.NEXTVAL INTO vCod FROM dual;
          INSERT INTO CONTRACTX ( CodCONTRACTX, CodContract1, ValMin, ProcPU, CORECTIEPU, Parametru)
          VALUES (vCOD, v_rec.CodContract1, v_rec.ValMin, v_rec.ProcPU, v_rec.CORECTIEPU, v_rec.Parametru) ;
        END IF;
      END LOOP;

      if aTipDoc in (10,27) THEN
        FOR v_rec IN (SELECT * FROM TMP_CONTRACTXX ORDER BY CodContract1) LOOP
          IF Coalesce(v_rec.CodCONTRACTXX,0) &gt; 0 THEN
            UPDATE CONTRACTXX
            SET
              CODCONTRACT1  = V_REC.CODCONTRACT1,
              PARAMETRU     = V_REC.PARAMETRU,
              VALSTART      = V_REC.VALSTART,
              VALSTOP       = V_REC.VALSTOP,
              ABATERE       = V_REC.ABATERE,
              STARTPROC     = V_REC.STARTPROC,
              STARTCORECTIE = V_REC.STARTCORECTIE,
              PROC          = V_REC.PROC,
              CORECTIE      = V_REC.CORECTIE,
              GENERARE      = V_REC.GENERARE
            WHERE  CodCONTRACTXX  = v_rec.CodCONTRACTXX;
          ELSE
            SELECT seq_CONTRACTXX_CodCONTRACTXX.NEXTVAL INTO vCod FROM dual;
            INSERT INTO CONTRACTXX (
              CODCONTRACTXX,
              CODCONTRACT1,
              PARAMETRU,
              VALSTART,
              VALSTOP,
              ABATERE,
              STARTPROC,
              STARTCORECTIE,
              PROC,
              CORECTIE,
              GENERARE
            )
            VALUES (vCOD,
                    V_REC.CODCONTRACT1,
                    V_REC.PARAMETRU,
                    V_REC.VALSTART,
                    V_REC.VALSTOP,
                    V_REC.ABATERE,
                    V_REC.STARTPROC,
                    V_REC.STARTCORECTIE,
                    V_REC.PROC,
                    V_REC.CORECTIE,
                    V_REC.GENERARE   ) ;
          END IF;
        END LOOP;
      END if;
    end if;

    -- detail JURNAlL1

    DELETE FROM JURNAl1
    WHERE TIPDOC = 25
          AND CODDOC = RECID
          AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
          AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
    IF V_REC.CODJURNAL1 &gt; 0 THEN
      UPDATE JURNAL1
      SET
        CODDOC       = V_REC.CODDOC,
        TIPDOC       = V_REC.TIPDOC,
        INDEXLOCAL   = V_REC.INDEXLOCAL,

        CODBAZAD     = V_REC.CODBAZAD,
        ICONTBAZAD   = V_REC.ICONTBAZAD,
        TIPBAZAD     = V_REC.TIPBAZAD,
        CODBAZAC     = V_REC.CODBAZAC,
        ICONTBAZAC   = V_REC.ICONTBAZAC,
        TIPBAZAC     = V_REC.TIPBAZAC,

        CODDESCRD     = V_REC.CODDESCRD,
        ICONTD        = V_REC.ICONTD,
        TIPCONTD      = V_REC.TIPCONTD,
        ANALITICCONTD = V_REC.ANALITICCONTD,
        CODDESCRC     = V_REC.CODDESCRC,
        ICONTC        = V_REC.ICONTC,
        TIPCONTC      = V_REC.TIPCONTC,
        ANALITICCONTC = V_REC.ANALITICCONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        DIRTY         = V_REC.DIRTY,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        CODCENTRU     = v_rec.CODCENTRU,
        DATADOC       = V_REC.DATADOC,
        DOCUMENT      = V_REC.DOCUMENT
      WHERE
        CODJURNAL1 = V_REC.CODJURNAl1;
    ELSE
      INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
      VALUES
      (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
    END IF;
    END LOOP;

    -- detail JURNAL

    DELETE FROM JURNAL
    WHERE TIPDOC = 25
          AND CODDOC = RECID
          AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
          AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC,
        INDEXLOCAL = V_REC.INDEXLOCAL,
        CONTD      = V_REC.CONTD,
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE,
        VALOAREV   = V_REC.VALOAREV,
        OBS        = V_REC.OBS,
        AN         = V_REC.AN,
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = v_rec.CODCENTRU,
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT
      WHERE
        CODJURNAL = V_REC.CODJURNAl;
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
     END IF;
    END LOOP;
  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;CONTRACT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    -- Master Contract
    RecId := seq_Contract_CodContract.NextVal;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;Contract&apos;, RecId);

    INSERT INTO  Contract (
      CodContract, TipDoc, Anulat, Blocat, Operat, Activ, CarnetDoc, SeriaDoc, NrDoc, DataDoc,
      DataStart, DataStop, TipContract, TipTarget, Partener, CodLocatie, CodFiscal, CodPersC,
      Moneda, PerTarget, NrLuni, TipPerFact, Majorari, GRATIE, PerFact, ZiFact, ProcMaj, PerCitire, ZiCitire, TranspPart,
      Obs, Subunitatea, An, Luna, UserId, DataCreare, Agent,
      CURS, AVANS, DOBANDA, TIPDOBANDA, CALCDOBANDA, REZIDUALA, REZIDUALASEPARAT,
      ASIGANUAL, LUNIGRATIE, GRATIEFARADOB, CodBanca, ProcMajCurs,AUTOPRELUNGIRE, LUNIPRELUNGIRE, TIPARTICOL, TIPUM, TipTargetV, Semnat,Explicatii, Stopaj, CASS, CodAnaliza,
      FactLei, Suma1, Suma2, Suma3, Suma4, Discount1, Discount2, Discount3, Discount4, NRI, MaxReplSimultane, MaxZileRepla, TipLivrare, CodGeneric, FactPretStandard,
      CREDITE_PLAFON, CREDITE_PU)
    SELECT
      RecId, TipDoc, Anulat, Blocat, Operat, Activ, CarnetDoc, SeriaDoc, NrDoc, DataDoc,
      DataStart, DataStop, TipContract, TipTarget, Partener, CodLocatie, CodFiscal, CodPersC,
      Moneda, PerTarget, NrLuni, TipPerFact, Majorari, GRATIE, PerFact, ZiFact, ProcMaj, PerCitire, ZiCitire, TranspPart,
      Obs, Subunitatea, An, Luna, pkg_globals.UserId, SysTimeStamp, Agent,
      CURS, AVANS, DOBANDA, TIPDOBANDA, CALCDOBANDA, REZIDUALA, REZIDUALASEPARAT,
      ASIGANUAL, LUNIGRATIE, GRATIEFARADOB, CodBanca, ProcMajCurs, AUTOPRELUNGIRE, LUNIPRELUNGIRE, TIPARTICOL, TIPUM, TipTargetV, Semnat,Explicatii, Stopaj, CASS, CodAnaliza,
      FactLei,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma1 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma2 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma3 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Suma4 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount1 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount2 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount3 ELSE null END,
      CASE WHEN vTipTarget = 1 and vTipContractV in (0,1) THEN Discount4 ELSE null END,
      NRI, MaxReplSimultane, MaxZileRepla, TipLivrare, CodGeneric, Coalesce(FactPretStandard,0),
      CREDITE_PLAFON, CREDITE_PU
    FROM TMP_Contract;

    -- Detail Contract1
    SELECT COUNT(1) INTO vRecNo FROM TMP_Contract1;

    FOR v_rec IN (
      SELECT
        CodContract1, CodContract, CodObiect, UmSec, Cant * Paritate Cant, Pret / Paritate Pret,
        ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
        LIMITACADOU, CANTCADOU, CODCADOU,CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount, SEDIULIVRARE,
        Anexa, DataStart, DataStop, TipDiscountT, TipDiscountC, SumaFixa, TipDiscountT1, CodClasa,
        cantglobal, DataLivr, Stare, pretstandard,TipObiect,
        DiscTCumulat, DiscT, CodContr1Cadru, CodCentru, Indexlocal, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF,
        CODANALIZANOD, IndexParinte, CODAUTO, TaxaUscare, TaxaConditionare, LUscare, LConditionare,
        D1, D2, D3, CantUM1, PretUM1,
        PARITATECREDIT
      FROM TMP_Contract1
      ORDER BY IndexLocal)
    LOOP
      vCod := seq_Contract1_CodContract1.NEXTVAL;
      DELETE FROM TMP_CONTRACTT WHERE CodContract1 = v_rec.CodContract1 AND Coalesce(CUMULAT,0) &lt;&gt; Coalesce(v_rec.DiscTCumulat,0);
      UPDATE TMP_CONTRACTC SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
      UPDATE TMP_CONTRACTT SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
      UPDATE TMP_CONTRACTV SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;Contract1&apos;, vCod, v_rec.CodContract1);
      IF kCereale = 1 THEN
        UPDATE TMP_CONTRACTX SET CodContract1 = vCOD WHERE CodContract1 = v_rec.CodContract1;
        IF aTipDoc in (10,27) THEN
          UPDATE TMP_CONTRACTXX SET CODCONTRACT1 = VCOD WHERE CODCONTRACT1 = V_REC.CODCONTRACT1;
        END IF;
      END IF;

      INSERT INTO  Contract1 (
        CodContract1, CodContract, CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
        Anexa, DataStart, DataStop, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
        LIMITACADOU, CANTCADOU,
        cantglobal, DataLivr, Stare, pretstandard,
				CODCADOU, CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipObiect,TipDiscount, SEDIULIVRARE,
        TIPDISCOUNTT, TipDiscountC, SumaFixa, TIPDISCOUNTT1, CodClasa,
        DiscTCumulat, DiscT, CodContr1Cadru, CodCentru, Indexlocal, CODUTILAJ, UTILAJ_TIP_INDEX, VERIFUMA, PLAFONCANTF,
        CODANALIZANOD, IndexParinte, CODAUTO, TaxaUscare, TaxaConditionare, LUscare, LConditionare,
        D1, D2, D3, CantUM1, PretUM1,
        PARITATECREDIT)
      VALUES (
        vCod , RecId, v_rec.CodObiect, v_rec.UMSec, v_rec.Cant, v_rec.Pret, v_rec.ProcDisc, v_rec.AdDim, v_rec.CANTOPTIM, v_rec.ZileL, v_rec.ZileC, v_rec.Lansare,
        v_rec.Anexa, v_rec.DataStart, v_rec.DataStop, v_rec.Obs, v_rec.GestAct, v_rec.CodIOArt, v_rec.CODOFERTA1, v_rec.TVA, V_REC.VALTARGET,
        v_rec.LIMITACADOU, v_rec.CANTCADOU,
        v_rec.cantglobal, v_rec.DataLivr, v_rec.Stare, v_rec.pretstandard,
				v_rec.CODCADOU, v_rec.CODOBIECTSEC, v_rec.LIMITACADOUSEC, v_rec.TERMENFIX, v_rec.TIPPRET, v_rec.TipObiect,v_rec.TipDiscount, v_rec.SEDIULIVRARE,
        Coalesce(v_Rec.TipdiscountT, 0), Coalesce(v_Rec.TipdiscountC, 0), v_rec.SumaFixa, Coalesce(v_Rec.TipdiscountT1, 0), Coalesce(v_Rec.CodClasa, 0),
        Coalesce(v_Rec.DiscTCumulat, 0), Coalesce(v_Rec.DiscT, 0), v_rec.CodContr1Cadru, v_Rec.CodCentru, v_rec.Indexlocal, V_REC.CODUTILAJ, V_REC.UTILAJ_TIP_INDEX, V_REC.VERIFUMA, V_REC.PLAFONCANTF,
        v_rec.CODANALIZANOD, v_rec.IndexParinte, v_rec.CODAUTO, v_rec.TaxaUscare, v_rec.TaxaConditionare, v_rec.LUscare, v_rec.LConditionare,
        v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CantUM1, v_rec.PretUM1,
        v_rec.PARITATECREDIT);
      IF aTipDoc = 34 THEN
        aCount := 0;
        SELECT count(1) INTO aCount FROM utilaje1 WHERE codutilaj = v_rec.codutilaj;

        aCount := aCount + 1;
        UPDATE utilaje  SET codpart = vcodpart WHERE codutilaj = v_rec.codutilaj;
        UPDATE utilaje1 SET status_part = 3    WHERE codutilaj = v_rec.codutilaj AND status_part = 2;
        INSERT INTO UTILAJE1(CODUTILAJ1, CODUTILAJ, NRCONTR, CARNETCONTR, STATUS_PART, STATUS_DEPO, CODPART, CODLOCATIE, DATA, USERID, DATACREARE, STATUS_SERVICE, INDEXLOCAL, ESTETIC)
        VALUES(seq_utilaje1_codutilaj1.nextval, v_rec.codutilaj, aNrDoc, aCarnetDoc, 2, 0, vCodPart, aCodLocatie, aDataStart, pkg_globals.GETUSERID, sysdate, 0, aCount, 0);
      END IF;
    END LOOP;

    -- Detail Contract2
    SELECT COUNT(1) INTO vRecNo FROM TMP_Contract2;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_Contract2_CodContract2 increment by &apos;||vRecNo;
      select seq_Contract2_CodContract2.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_Contract2_CodContract2 increment by 1&apos;;
      INSERT INTO  Contract2 (
        CodContract2,
        CodContract, Data, DataStop, Suma, Dobanda, Asigurare, CodDoc, TipDoc, Suspendat, SediuLivrare, IndexLocal,
        NrDoc, DataDoc, CodDocT, TipDocT)
      SELECT
        vCod + ROW_NUMBER() OVER (ORDER BY Data ASC),
        RecId, Data, DataStop, Suma, Dobanda, Asigurare, CodDoc, TipDoc, Suspendat, SediuLivrare, IndexLocal,
        NrDoc, DataDoc, CodDocT, TipDocT
      FROM TMP_Contract2;
    END IF;

    -- Detail CONTRACT0
    select seq_CONTRACT0_CodContract0.nextval INTO vCod from dual;
    INSERT INTO  CONTRACT0 (
      CodContract0,
      CodContract, Data, Suma, Curs, TipLinie, OldCurs, CodDoc, TipDoc, Facturat, Dobanda, NrDoc, DataDoc)
    SELECT
      vCod,
      RecId, Data, Suma, Curs, TipLinie, OldCurs, CodDoc, TipDoc, Facturat, Dobanda, NrDoc, DataDoc
    FROM TMP_CONTRACT0;

    INSERT INTO  ContractC0(Codcontractc0,
                            Codcontract,
                            Cantmin,
                            Discount,
                            Valdiscount)
    select seq_contractc0_codcontractc0.nextval, RecId, Cantmin, Discount, Valdiscount
    from tmp_contractc0;

    -- Detail ContractV
    SELECT COUNT(1) INTO vRecNo FROM TMP_ContractV;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractV_CodContractV increment by &apos;||vRecNo;
      select seq_ContractV_CodContractV.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractV_CodContractV increment by 1&apos;;

      INSERT INTO  ContractV (CodContractV, CodContract, Suma, Discount, ValDiscount, CodContract1)
      SELECT vCod + ROW_NUMBER() OVER (ORDER BY Suma DESC), RecId, Suma, Discount, ValDiscount, CodContract1
      FROM TMP_ContractV;
    END IF;

    -- Detail ContractT
    SELECT COUNT(1) INTO vRecNo FROM TMP_ContractT;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractT_CodContractT increment by &apos;||vRecNo;
      select seq_ContractT_CodContractT.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractT_CodContractT increment by 1&apos;;

      INSERT INTO  ContractT (CodContractT, CodContract1, Zile, TermenFix, Discount, ValDiscount, ProcValDoc)
      SELECT vCod + ROW_NUMBER() OVER (ORDER BY CodContract1 ASC, Zile ASC), CodContract1, Zile, TermenFix, Discount, ValDiscount, ProcValDoc
      FROM TMP_ContractT;
    END IF;

    --Detalii ContractC
    SELECT COUNT(1) INTO vRecNo FROM TMP_ContractC;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractC_CodContractC increment by &apos;||vRecNo;
      select seq_ContractC_CodContractC.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_ContractC_CodContractC increment by 1&apos;;

      INSERT INTO  ContractC (CodContractC, CodContract1, CantMin, Discount, ValDiscount)
      SELECT vCod + ROW_NUMBER() OVER (ORDER BY CodContract1 ASC, CantMin DESC), CodContract1,  CantMin, Discount, ValDiscount
      FROM TMP_ContractC;
    END IF;

    if kCereale = 1 then
      if aTipDoc in (10,27) THEN
        --Detalii CONTRACTX
        SELECT COUNT(1) INTO vRecNo FROM TMP_CONTRACTX;

        IF vRecNo &gt; 0 THEN
          EXECUTE IMMEDIATE &apos;alter sequence seq_CONTRACTX_CodCONTRACTX increment by &apos;||vRecNo;
          select seq_CONTRACTX_CodCONTRACTX.nextval - vRecNo INTO vCod from dual;
          EXECUTE IMMEDIATE &apos;alter sequence seq_CONTRACTX_CodCONTRACTX increment by 1&apos;;

          INSERT INTO  CONTRACTX (CodCONTRACTX, CodContract1, ValMin, ProcPU, CORECTIEPU, Parametru)
          SELECT vCod + ROW_NUMBER() OVER (ORDER BY CodContract1 ASC, ValMin DESC), CodContract1,  ValMin, ProcPU, CORECTIEPU, Parametru
          FROM TMP_CONTRACTX;
        END IF;

        INSERT INTO CONTRACTXX (
              CODCONTRACTXX,
              CODCONTRACT1,
              PARAMETRU,
              VALSTART,
              VALSTOP,
              ABATERE,
              STARTPROC,
              STARTCORECTIE,
              PROC,
              CORECTIE,
              GENERARE
            )
        SELECT
          SEQ_CONTRACTXX_CODCONTRACTXX.NEXTVAL,
          CODCONTRACT1,
          PARAMETRU,
          VALSTART,
          VALSTOP,
          ABATERE,
          STARTPROC,
          STARTCORECTIE,
          PROC,
          CORECTIE,
          GENERARE
        FROM TMP_CONTRACTXX;
      END if;
    end if;

    INSERT INTO JURNAL1 (
      CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,
      TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
    SELECT
      SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,
      TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT
    FROM TMP_JURNAL1;

    INSERT INTO JURNAL(
      CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)
    SELECT
      SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT
    FROM TMP_JURNAL;
  END IF;


  -- Actualizare nartcli

  IF vCodPart &lt;&gt; 0 THEN
    vUpdArtCli := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;DetArtPartFromDoc&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 1);
    FOR v_rec IN (
      SELECT CodObiect, Max(DenArtCli) DenArtCli, Max(CodExtCli) CodExtCli, Max(CodLaClient) CodLaClient, Max(UMSec) UMSec
      FROM TMP_Contract1 GROUP BY CodObiect)
    LOOP
      PKG_NOM_ARTICOL.ACTUALIZEAZA_NARTCLI(v_rec.CodObiect, vCodPart, 0, v_rec.DenArtCli, v_rec.CodExtCli, v_rec.CodLaClient, v_rec.UMSec, 1, vUpdArtCli);
    END LOOP;
  END IF;

  -- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
    WHERE CODCONT = V_REC.CODCONT
      AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    IF Coalesce(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
      FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
      LOOP
        SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

        IF NR = 0 THEN
          INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
          VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
        END IF;

        UPDATE NCONTRULSUB
        SET
          RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
          RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
          RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
          RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
        WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;
    END IF;

  END LOOP;

  for V_Rec in (select * from TMP_RAC_CATPX) loop
		update RAC_CATP set
		codcontract = RecID
		where codrac_catp = v_rec.codrac_catp;
  END loop;

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;CONTRACTEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_CONTRACTEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM CONTRACTEXT WHERE CODCONTRACT =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_CONTRACTEXT SET CODCONTRACTEXT = SEQ_CONTRACTEXT_CODCONTRACTEXT.NEXTVAL WHERE CODCONTRACTEXT &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_CONTRACTEXT SET CODCONTRACT = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO CONTRACTEXT SELECT * FROM TMP_CONTRACTEXT &apos;;
  END IF;
*/
  PKG_CARNETEDOC.SOLVENUMARDOC(aCarnetDoc, aNrDoc);

  PKG_GLOBALS.MarkDirtyJurnal;
  
  PKG_CFGTABLES.EXT_POSTRECORDS(aTipDoc, Operation);
  COMMIT;
  NotifyModif(Operation, RecId, &apos;CONTRACT&apos;);
  commit;
END;

FUNCTION GETOBJCADOU( aTipDoc  IN NUMBER,
                      aCodObiect  IN NUMBER,
                      aPart IN NUMBER,
                      aDataRef IN VARCHAR2 ) RETURN VARCHAR2
IS
  aResult    VARCHAR2(200) := &apos;&apos;;
BEGIN
  IF aTipDoc IN (1,2,3,9) THEN
    BEGIN
      SELECT OBJ.DENUMIRE into aResult
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODCADOU
      WHERE C.Anulat = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 10
        AND C.Partener = aPart
        AND C1.Codobiect = aCodObiect
        AND Coalesce(C1.CodObiectSec, 0) = 0
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= aDataRef AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataRef
        AND RowNum = 1;
    EXCEPTION WHEN others THEN
      aResult := &apos;&apos;;
    END;
  ELSIF aTipDoc IN (19,20,21,26) THEN
    BEGIN
      SELECT OBJ.DENUMIRE into aResult
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODCADOU
      WHERE C.Anulat = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 27
        AND C.Partener = aPart
        AND C1.Codobiect = aCodObiect
        AND Coalesce(C1.CodObiectSec, 0) = 0
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= aDataRef AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataRef
        AND RowNum = 1;
    EXCEPTION WHEN others THEN
      aResult := &apos;&apos;;
    END;
  END IF;

  Return aResult;
END;

FUNCTION GETCANTCADOU(aTipDoc  IN NUMBER,
                      aCodDoc1  IN NUMBER,
                      aDataRef IN VARCHAR2 ) RETURN NUMBER
IS
  vCodObiect NUMBER(20);
  vPart      NUMBER(20);
  aResult    NUMBER(20) := 0;
  vCant      NUMBER(20, 7) := 0;
BEGIN
  IF aTipDoc IN (1,2,3,9) THEN

    SELECT i1.codobiect, i.Partener, i1.cant
    INTO vCodObiect, vPart, vCant
    FROM intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    WHERE i1.CodIntr1 = aCodDoc1;

    BEGIN
      SELECT Round(vCant/(c1.limitacadou*decode(Coalesce(num1.paritate, 0), 0,1,num1.paritate)), 0)*c1.cantcadou into aResult
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        INNER JOIN NUM1 on num1.codum1 = c1.umsec
      WHERE C.Anulat = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 10
        AND C.Partener = vPart
        AND C1.Codobiect = vCodObiect
        AND Coalesce(C1.CodObiectSec, 0) = 0
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= aDataRef AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataRef;
    exception WHEN others THEN
      aResult := 0;
    END;

  ELSIF aTipDoc IN (19,20,21,26) THEN

    SELECT i1.codobiect, i.Partener, i1.cant
    INTO vCodObiect, vPart, vCant
    FROM iesiri1 i1
         inner join iesiri i on i1.codies = i.codies
    WHERE i1.CodIes1 = aCodDoc1;

    BEGIN
      SELECT Round(vCant/(c1.limitacadou*decode(Coalesce(num1.paritate, 0), 0,1,num1.paritate)), 0)*c1.cantcadou into aResult
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        INNER JOIN NUM1 on num1.codum1 = c1.umsec
      WHERE
        C.Anulat = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 27
        AND C.Partener = vPart
        AND C1.Codobiect = vCodObiect
        AND Coalesce(C1.CodObiectSec, 0) = 0
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= aDataRef AND Coalesce(C1.DataStop,C.DataStop)  &gt;= aDataRef;
    EXCEPTION WHEN others THEN
      aResult := 0;
    END;
  END IF;

  Return aResult;
END;

FUNCTION CALCULEAZA_DISCT_DOC(aTipDoc  IN NUMBER,
                              aCodDoc  IN NUMBER,
                              aDataRef IN VARCHAR2,
                              aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER
IS
 TOTAL    NUMBER(20, 7) := 0;
 vDataDoc DATE;
 vPart    INTEGER;
 vValDoc  NUMBER;
BEGIN
  IF aRest IS NOT NULL AND aRest = 0 THEN
    RETURN 0;
  END IF;

  TOTAL := 0;

  IF aTipDoc IN (1,2,3,9) THEN
    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM intrari
    WHERE CodIntr = aCodDoc;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 10 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(to_date(aDataRef, &apos;dd.mm.yyyy&apos;) - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 0
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 10 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(to_date(aDataRef, &apos;dd.mm.yyyy&apos;) - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 1
        UNION ALL
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (SELECT Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= to_date(aDataRef, &apos;dd.mm.yyyy&apos;))
          AND C1.Tipdiscountt  = 1
          AND C1.Tipdiscountt1 = 0
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 10 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= to_date(aDataRef, &apos;dd.mm.yyyy&apos;))
          AND C1.Tipdiscountt  = 1
          AND C1.Tipdiscountt1 = 1
      )
      SELECT
        Coalesce(Sum (
          CASE
            WHEN d.tipdiscountt1 = 1 THEN i1.Cant * d.Disc
            ELSE (CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END * i1.Cant - CASE WHEN aTipDoc = 3 THEN i1.Tva ELSE 0 END) * d.Disc / 100
          END )
        ,0)
      INTO Total
      FROM intrari1 i1 INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codintr = aCodDoc;
    END IF;

  ELSIF aTipDoc IN (19,20,21,26) THEN

    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM iesiri
    WHERE CodIes = aCodDoc;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 27 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(to_date(aDataRef, &apos;dd.mm.yyyy&apos;) - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 0
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 27 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(to_date(aDataRef, &apos;dd.mm.yyyy&apos;) - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 1
        UNION ALL
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 27 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= to_date(aDataRef, &apos;dd.mm.yyyy&apos;))
          AND C1.Tipdiscountt = 1
          AND C1.Tipdiscountt1  = 0
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = 27 AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= to_date(aDataRef, &apos;dd.mm.yyyy&apos;))
          AND C1.Tipdiscountt = 1
          AND C1.Tipdiscountt1  = 1
      )
      SELECT
        Coalesce(Sum (
          CASE
            WHEN d.tipdiscountt1 = 1 THEN i1.Cant * d.Disc
            ELSE (CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END * i1.Cant + CASE WHEN aTipDoc = 22 THEN i1.Tva ELSE 0 END * i1.coefdiscmaj) * d.Disc / 100
          END )
        ,0)
      INTO Total
      FROM iesiri1 i1 INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codies = aCodDoc;
    END IF;
  END IF;

  IF Coalesce(vValDoc,0) = 0 THEN
    RETURN 0;
  END IF;

  IF aRest IS NOT NULL THEN
    TOTAL := TOTAL * aRest / vValDoc;
  END IF;

  RETURN TOTAL;
END;

FUNCTION CALCULEAZA_DISCT_LINIE(aTipDoc  IN NUMBER,
                                aCodDoc1 IN NUMBER,
                                aDataRef IN DATE)  RETURN NUMBER
IS
 TOTAL    NUMBER(20, 7) := 0;
 vDataDoc DATE;
 vPart    INTEGER;
 vValDoc  NUMBER;
 vCodObiect  NUMBER;
BEGIN
  TOTAL := 0;

  IF aTipDoc IN (1,2,3,9) THEN
    SELECT i.DataDoc, i1.pretorig * i1.coefdiscmaj * i1.cant, i.Partener, i1.codobiect
    INTO vDataDoc, vValDoc, vPart, vCodObiect
    FROM intrari i
         inner join intrari1 i1 on i.codintr = i1.codintr
    WHERE i1.CodIntr1 = aCodDoc1;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(aDataRef - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 0
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(aDataRef - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 1
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= vDataDoc)
          AND C1.Tipdiscountt  = 1
          AND C1.Tipdiscountt1 = 0
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= vDataDoc)
          AND C1.Tipdiscountt  = 1
          AND C1.Tipdiscountt1 = 1
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
      )
      SELECT
        case
          WHEN d.tipdiscountt = 0 and d.tipdiscountt1 = 0 THEN ((CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.Cant - Decode(aTipDoc,3,i1.Tva,0)) * d.Disc / 100
          WHEN d.tipdiscountt = 0 and d.tipdiscountt1 = 1 THEN (i1.Cant * d.Disc)
          WHEN d.tipdiscountt = 1 and d.tipdiscountt1 = 0 THEN ((CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.Cant - Decode(aTipDoc,3,i1.Tva,0)) * d.Disc / 100
          WHEN d.tipdiscountt = 1 and d.tipdiscountt1 = 1 THEN (i1.Cant * d.Disc)
        END
      INTO Total
      FROM intrari1 i1
           INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codintr1 = aCodDoc1 AND RowNum = 1;
    END IF;

  ELSIF aTipDoc IN (19,20,21,26) THEN

    SELECT i.DataDoc, i1.pretorig * i1.coefdiscmaj * i1.cant, i.Partener, i1.codobiect
    INTO vDataDoc, vValDoc, vPart, vCodObiect
    FROM iesiri i
         inner join iesiri1 i1 on i.codies = i1.codies
    WHERE i1.CodIes1 = aCodDoc1;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C1.CodObiect, CT.DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 27
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(aDataRef - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 0
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 27
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.Zile = (select min(zile) from contractt where codcontract1 = c1.codcontract1 and zile &gt;=(aDataRef - vDataDoc))
          AND C1.Tipdiscountt  = 0
          AND C1.Tipdiscountt1 = 1
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, DISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 27
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= vDataDoc)
          AND C1.Tipdiscountt = 1
          AND C1.Tipdiscountt1  = 0
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
        UNION ALL
        SELECT C1.CodObiect, CT.VALDISCOUNT DISC, C1.TIPDISCOUNTT1, C1.TIPDISCOUNTT, C1.TipDiscount, C1.PRET
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
          INNER JOIN ContractT CT ON CT.CodContract1 = C1.CodContract1
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 27
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
          AND CT.TERMENFIX = (select Min(termenfix) from contractt where codcontract1 = c1.codcontract1 and termenfix &gt;= vDataDoc)
          AND C1.Tipdiscountt = 1
          AND C1.Tipdiscountt1  = 1
          AND C1.CodObiect = vCodObiect
          AND RowNum = 1
      )
      SELECT
        case
          WHEN d.tipdiscountt = 0 and d.tipdiscountt1 = 0 THEN ((CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.Cant - Decode(aTipDoc,22,i1.Tva,0) * i1.coefdiscmaj) * d.Disc / 100
          WHEN d.tipdiscountt = 0 and d.tipdiscountt1 = 1 THEN (i1.Cant * d.Disc)
          WHEN d.tipdiscountt = 1 and d.tipdiscountt1 = 0 THEN ((CASE WHEN Coalesce(d.tipdiscount, 0) = 0 THEN i1.Pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.Cant - Decode(aTipDoc,22,i1.Tva,0) * i1.coefdiscmaj) * d.Disc / 100
          WHEN d.tipdiscountt = 1 and d.tipdiscountt1 = 1 THEN (i1.Cant * d.Disc)
        END
      INTO Total
      FROM iesiri1 i1
           INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codies1 = aCodDoc1 AND RowNum = 1;
    END IF;
  END IF;

  IF Coalesce(vValDoc,0) = 0 THEN
    RETURN 0;
  END IF;

  RETURN TOTAL;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION CALCULEAZA_DISCV_DOC(aTipDoc  IN NUMBER,
                              aCodDoc  IN NUMBER,
                              aDataRef IN DATE,
                              aValTotal IN NUMBER,
                              aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER
IS
 TOTAL    NUMBER(20, 7) := 0;
 vDataDoc DATE;
 vPart    INTEGER;
 vValDoc  NUMBER;
 vTipDisc NUMBER;
 VDisc    NUMBER;
BEGIN
  IF aRest IS NOT NULL AND aRest = 0 THEN
    RETURN 0;
  END IF;

  TOTAL := 0;

  IF aTipDoc IN (1,2,3,9) THEN
    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM intrari
    WHERE CodIntr = aCodDoc;

    SELECT
      CASE WHEN CV.DISCOUNT = 0 THEN CV.VALDISCOUNT ELSE CV.DISCOUNT END DISC,
      CASE WHEN CV.DISCOUNT = 0 THEN 1 ELSE 0 END TipDisc
      into vDisc, vTipDisc
    FROM Contract C
      INNER JOIN ContractV CV ON CV.CodContract = C.CodContract
    WHERE
      C.Anulat = 0
      AND C.Operat = 1
      AND C.Activ = 1
      AND C.TipDoc = 10
      AND C.Partener = vPart
      AND C.DataStart &lt;= vDataDoc AND C.DataStop  &gt;= vDataDoc
      AND CV.Suma = (select max(suma) from contractv where codcontract = c.codcontract and suma &lt;= aValTotal)
      AND RowNum = 1;

    if vtipdisc = 0 THEN
      Total := vDisc * aRest / 100;
    ELSE
      Total :=  vDisc * aRest / aValTotal;
    END if;

  ELSIF aTipDoc IN (19,20,21,26) THEN
    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM iesiri
    WHERE CodIes = aCodDoc;

    SELECT
      CASE WHEN CV.DISCOUNT = 0 THEN CV.VALDISCOUNT ELSE CV.DISCOUNT END DISC,
      CASE WHEN CV.DISCOUNT = 0 THEN 1 ELSE 0 END TipDisc
      into vDisc, vTipDisc
    FROM Contract C
      INNER JOIN ContractV CV ON CV.CodContract = C.CodContract
    WHERE
      C.Anulat = 0
      AND C.Operat = 1
      AND C.Activ = 1
      AND C.TipDoc = 27
      AND C.Partener = vPart
      AND C.DataStart &lt;= vDataDoc AND C.DataStop  &gt;= vDataDoc
      AND CV.Suma = (select max(suma) from contractv where codcontract = c.codcontract and suma &lt;= aValTotal)
      AND RowNum = 1;

    if vtipdisc = 0 THEN
      Total := vDisc * aRest / 100;
    ELSE
      Total :=  vDisc * aRest / aValTotal;
    END if;

  END IF;

  IF Coalesce(vValDoc,0) = 0 THEN
    RETURN 0;
  END IF;

  RETURN TOTAL;
END;

FUNCTION CALCULEAZA_DISCC_DOC( aTipDoc  IN NUMBER,
                              aCodDoc  IN NUMBER,
                              aDataRef IN DATE,
                              aRest    IN NUMBER DEFAULT NULL)  RETURN NUMBER
IS
  TOTAL    NUMBER(20, 7) := 0;
  vDataDoc DATE;
  vPart    INTEGER;
  vValDoc  NUMBER;
BEGIN
  IF aRest IS NOT NULL AND aRest = 0 THEN
    RETURN 0;
  END IF;

  TOTAL := 0;

  IF aTipDoc IN (1,2,3,9) THEN
    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM intrari
    WHERE CodIntr = aCodDoc;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C.CodContract, C1.CodObiect, c1.tipdiscount, c1.pret, c1.codcontract1
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 10
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
      )
      SELECT
        Sum (pkg_notecredit.GetDiscCant(i1.cant, (CASE WHEN Coalesce(d.tipdiscount,0) = 0 THEN i1.pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.cant, i1.cant, d.codcontract1, i1.pu))
      INTO Total
      FROM intrari1 i1
        INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codintr = aCodDoc;
    END IF;
  ELSIF aTipDoc IN (19,20,21,26) THEN

    SELECT DataDoc, ValDoc, Partener
    INTO vDataDoc, vValDoc, vPart
    FROM iesiri
    WHERE CodIes = aCodDoc;

    IF Coalesce(vValDoc,0) &lt;&gt; 0 THEN
      WITH D AS (
        SELECT C.CodContract, C1.CodObiect, c1.tipdiscount, c1.pret, c1.codcontract1
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
        WHERE
          C.Anulat = 0
          AND C.Operat = 1
          AND C.Activ = 1
          AND C.TipDoc = 27
          AND C.Partener = vPart
          AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
      )
      SELECT
        Sum (pkg_notecredit.GetDiscCant(i1.cant, (CASE WHEN Coalesce(d.tipdiscount,0) = 0 THEN i1.pretorig * i1.coefdiscmaj ELSE d.pret END) * i1.cant, i1.cant, d.codcontract1, i1.pu))
      INTO Total
      FROM iesiri1 i1
        INNER JOIN d ON d.CodObiect = i1.CodObiect
      WHERE i1.codies = aCodDoc;
    END IF;
  END IF;

  IF Coalesce(vValDoc,0) = 0 THEN
    RETURN 0;
  END IF;

  IF aRest IS NOT NULL THEN
    TOTAL := TOTAL * aRest / vValDoc;
  END IF;

  RETURN TOTAL;
END;

FUNCTION CALCULEAZA_DISCC_LINIE( aTipDoc  IN NUMBER,
                                aCodDoc1  IN NUMBER,
                                aDataRef IN DATE)  RETURN NUMBER
IS
  TOTAL    NUMBER(20, 7) := 0;
  vDataDoc DATE;
  vPart    INTEGER;
  vValDoc  NUMBER;
  vCodObiect NUMBER;
BEGIN
  TOTAL := 0;

  IF aTipDoc IN (1,2,3,9) THEN
    SELECT i.DataDoc, i1.pretorig * i1.coefdiscmaj * i1.cant, i.Partener, i1.codobiect
    INTO vDataDoc, vValDoc, vPart, vCodObiect
    FROM intrari i
         inner join intrari1 i1 on i.codintr = i1.codintr
    WHERE i1.CodIntr1 = aCodDoc1;

    WITH D AS (
      SELECT C.CodContract, C1.CodObiect, c1.tipdiscount, c1.pret, c1.codcontract1
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
      WHERE
        Coalesce(C.Anulat,0) = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 10
        AND C.Partener = vPart
        AND C1.CodObiect = vCodObiect
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
        AND RowNum = 1
    )
    SELECT
      sign(i1.cant)*pkg_notecredit.GetDiscCant(abs(i1.cant), (CASE WHEN Coalesce(d.tipdiscount,0) = 0 THEN i1.pretorig * i1.coefdiscmaj ELSE d.pret END)*i1.cant, abs(i1.cant), d.codcontract1, i1.pu)
    INTO Total
    FROM intrari1 i1
      INNER JOIN d ON d.CodObiect = i1.CodObiect
    WHERE i1.codintr1 = aCodDoc1;
  ELSIF aTipDoc IN (19,20,21,26) THEN

    SELECT i.DataDoc, i1.pretorig * i1.coefdiscmaj * i1.cant, i.Partener, i1.codobiect
    INTO vDataDoc, vValDoc, vPart, vCodObiect
    FROM iesiri i
         inner join iesiri1 i1 on i.codies = i1.codies
    WHERE i1.CodIes1 = aCodDoc1;

    WITH D AS (
      SELECT C.CodContract, C1.CodObiect, c1.tipdiscount, c1.pret, c1.codcontract1
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
      WHERE
        Coalesce(C.Anulat,0) = 0
        AND C.Operat = 1
        AND C.Activ = 1
        AND C.TipDoc = 27
        AND C.Partener = vPart
        AND C1.CodObiect = vCodObiect
        AND Coalesce(C1.DataStart,C.DataStart) &lt;= vDataDoc AND Coalesce(C1.DataStop,C.DataStop)  &gt;= vDataDoc
        AND RowNum = 1
    )
    SELECT
      sign(i1.cant)*pkg_notecredit.GetDiscCant(abs(i1.cant), (CASE WHEN Coalesce(d.tipdiscount,0) = 0 THEN i1.pretorig * i1.coefdiscmaj ELSE d.pret END)*i1.cant, abs(i1.cant), d.codcontract1, i1.pu)
    INTO Total
    FROM iesiri1 i1
      INNER JOIN d ON d.CodObiect = i1.CodObiect
    WHERE i1.codies1 = aCodDoc1;
  END IF;

  --IF Coalesce(vValDoc,0) = 0 THEN
    --RETURN 0;
  --END IF;

  RETURN TOTAL;
END;

PROCEDURE SIMULEAZA_DISCV(aDataStart IN DATE,
                          aDataStop  IN DATE,
                          aTip       IN NUMBER DEFAULT 0)-- 0 intrari si iesiri; 1 intrari; 2 iesiri
IS
  vArtDiscPrimTer   NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vArtDiscPrimVol   NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vArtDiscPrimCant  NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vArtPenPrim       NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vVolumTotal       NUMBER;
  vProcDisc         NUMBER;
  vValDisc          NUMBER;
  vDataStart        DATE;
  vDataStop         DATE;
  vLuniLista        NUMBER;
BEGIN
  if PKG_LIST_SELECTIEPROFIT.Extra3 then
    vLuniLista := extract(year from adatastop) * 12 + extract(month from adatastop) - extract(year from adatastart) * 12 - extract(month from adatastart) + 1;
    IF Coalesce(aTip,0) IN (0,1) THEN DELETE FROM TMP_INTRDISCV; END IF;
    IF Coalesce(aTip,0) IN (0,2) THEN DELETE FROM TMP_IESDISCV;  END IF;

    IF Coalesce(aTIP,0) IN (0,1) THEN
      FOR v_rec IN (
        SELECT
          C.CODCONTRACT, C.DATASTART, C.DATASTOP, Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
          Coalesce(C.TIPTARGETV,0) TIPTARGETV, C.SUBUNITATEA,
          extract(year from c.datastop) * 12 + extract(month from c.datastop)
          - extract(year from c.datastart) * 12 - extract(month from c.datastart) + 1 LuniContr
        FROM Contract C
        WHERE C.TipDoc = 10 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ IN (1,3)
          AND C.DataStart &lt;= aDataStop AND (C.DataStop &gt;= aDataStart OR Coalesce(aTip,0) = 0)
          AND EXISTS (SELECT 1 FROM ContractV CV WHERE cv.codcontract = c.codcontract)
      ) LOOP
        vDataStart := aDataStart;
        vDataStop  := aDataStop;
        IF v_rec.tiptargetv IN (0,1) THEN
          SELECT Coalesce(SUM(I1.Cant*I1.PU),0) INTO vVolumTotal
          FROM intrari i
            INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
          WHERE I.TipDoc IN (1,9)
            AND I.Anulat = 0 AND I.Operat = 1
            AND I.Partener = v_rec.Partener
            AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
            AND I.DataDoc BETWEEN vDataStart AND vDataStop
            AND I.Subunitatea = v_rec.Subunitatea
            AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
            AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
            AND (v_rec.tiptargetv = 0 OR I1.CodObiect IN (SELECT CODOBIECT FROM CONTRACT1 C1 WHERE CODCONTRACT = v_rec.CodContract));
          BEGIN
            SELECT
              Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
              Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
            INTO
              vProcDisc,
              vValDisc
            FROM ContractV CV
            WHERE CV.CodContract = v_rec.CodContract
              AND CV.SUMA &lt;= vVolumTotal;

            vValDisc := vValDisc  * vLuniLista / v_Rec.LuniContr;

            IF vProcDisc &lt;&gt; 0
            THEN vValDisc := vVolumTotal * vProcDisc / 100;
            END IF;

            IF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 0 THEN -- indiferent de articol
              INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              VALUES (v_rec.partener, v_rec.CodLocatie, 0, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
            ELSIF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 1 THEN -- mix articole
              INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              SELECT v_rec.partener, v_rec.CodLocatie, C1.codobiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea
              FROM Contract1 C1
              WHERE C1.CodContract = v_rec.CodContract;
            END IF;
          EXCEPTION
            WHEN OTHERS THEN NULL;
          END;
        ELSIF v_rec.tiptargetv = 2 THEN -- pe articole
          FOR v_rec2 IN (
            SELECT C1.CodContract1, I1.CodObiect, Coalesce(SUM(I1.Cant*I1.PU),0) VolumTotal
            FROM intrari i
              INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
              INNER JOIN (
                SELECT C1.CodContract1, C1.CodObiect
                FROM  Contract1 C1
                WHERE C1.CODCONTRACT = v_rec.CodContract
                  AND EXISTS (SELECT 1 FROM CONTRACTV CV WHERE CV.CODCONTRACT1 = C1.CodContract1)
              ) C1 ON C1.CodObiect = i1.CodObiect
            WHERE I.TipDoc IN (1,9)
              AND I.Anulat = 0 AND I.Operat = 1
              AND I.Partener = v_rec.Partener
              AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
              AND I.Subunitatea = v_rec.Subunitatea
              AND I.DataDoc BETWEEN vDataStart AND vDataStop
              AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
              AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
            GROUP BY C1.CodContract1, I1.CodObiect
          ) LOOP

            vVolumTotal := v_rec2.VolumTotal;

            BEGIN
              SELECT
                Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
              INTO
                vProcDisc,
                vValDisc
              FROM ContractV CV
              WHERE CV.CodContract1 = v_rec2.CodContract1
                AND CV.SUMA &lt;= vVolumTotal;

              vValDisc := vValDisc  * vLuniLista / v_Rec.LuniContr;

              IF vProcDisc &lt;&gt; 0
              THEN vValDisc := vVolumTotal * vProcDisc / 100;
              END IF;

              INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              VALUES (v_rec.partener, v_rec.CodLocatie, v_rec2.CodObiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
            EXCEPTION
              WHEN OTHERS THEN NULL;
            END;
          END LOOP;
        END IF;
      END LOOP;
    END IF;
    IF Coalesce(aTip,0) IN (0,2) THEN
      FOR v_rec IN (
        SELECT
          C.CODCONTRACT, C.DATASTART, C.DATASTOP, Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
          Coalesce(C.TIPTARGETV,0) TIPTARGETV, C.SUBUNITATEA,
          extract(year from c.datastop) * 12 + extract(month from c.datastop)
          - extract(year from c.datastart) * 12 - extract(month from c.datastart) + 1 LuniContr
        FROM Contract C
        WHERE C.TipDoc = 27 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ IN (1,3)
          AND C.DataStart &lt;= aDataStop AND C.DataStop  &gt;= aDataStart
          AND EXISTS (SELECT 1 FROM ContractV CV WHERE cv.codcontract = c.codcontract)
      ) LOOP
        vDataStart := aDataStart;
        vDataStop  := aDataStop;

        IF v_rec.tiptargetv IN (0,1) THEN
          SELECT Coalesce(SUM(I1.Cant*I1.PU),0) INTO vVolumTotal
          FROM iesiri i
            INNER JOIN iesiri1 I1 ON i.codies = i1.codies
          WHERE I.TipDoc IN (19,26)
            AND I.Anulat = 0 AND I.Operat = 1
            AND I.Partener = v_rec.Partener
            AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
            AND I.Subunitatea = v_rec.Subunitatea
            AND I.DataDoc BETWEEN vDataStart AND vDataStop
            AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
            AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
            AND (v_rec.tiptargetv = 0 OR I1.CodObiect IN (SELECT CODOBIECT FROM CONTRACT1 C1 WHERE CODCONTRACT = v_rec.CodContract));

          BEGIN
            SELECT
              Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
              Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
            INTO
              vProcDisc,
              vValDisc
            FROM ContractV CV
            WHERE CV.CodContract = v_rec.CodContract
              AND CV.SUMA &lt;= vVolumTotal;

            vValDisc := vValDisc  * vLuniLista / v_Rec.LuniContr;

            IF vProcDisc &lt;&gt; 0
            THEN vValDisc := vVolumTotal * vProcDisc / 100;
            END IF;

            IF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 0 THEN -- indiferent de articol
              INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              VALUES (v_rec.partener, v_rec.CodLocatie, 0, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
            ELSIF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 1 THEN -- mix articole
              INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              SELECT v_rec.partener, v_rec.CodLocatie, C1.codobiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea
              FROM Contract1 C1
              WHERE C1.CodContract = v_rec.CodContract;
            END IF;
          EXCEPTION
            WHEN OTHERS THEN NULL;
          END;
        ELSIF v_rec.tiptargetv = 2 THEN -- pe articole
          FOR v_rec2 IN (
            SELECT C1.CodContract1, I1.CodObiect, Coalesce(SUM(I1.Cant*I1.PU),0) VolumTotal
            FROM iesiri i
              INNER JOIN iesiri1 I1 ON i.codies = i1.codies
              INNER JOIN (
                SELECT C1.CodContract1, C1.CodObiect
                FROM  Contract1 C1
                WHERE C1.CODCONTRACT = v_rec.CodContract
                  AND EXISTS (SELECT 1 FROM CONTRACTV CV WHERE CV.CODCONTRACT1 = C1.CodContract1)
              ) C1 ON C1.CodObiect = i1.CodObiect
            WHERE I.TipDoc IN (19,26)
              AND I.Anulat = 0 AND I.Operat = 1
              AND I.Partener = v_rec.Partener
              AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
              AND I.Subunitatea = v_rec.Subunitatea
              AND I.DataDoc BETWEEN vDataStart AND vDataStop
              AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
              AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
            GROUP BY C1.CodContract1, I1.CodObiect
          ) LOOP

            vVolumTotal := v_rec2.VolumTotal;

            BEGIN
              SELECT
                Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
              INTO
                vProcDisc,
                vValDisc
              FROM ContractV CV
              WHERE CV.CodContract1 = v_rec2.CodContract1
                AND CV.SUMA &lt;= vVolumTotal;

              vValDisc := vValDisc  * vLuniLista / v_Rec.LuniContr;

              IF vProcDisc &lt;&gt; 0
              THEN vValDisc := vVolumTotal * vProcDisc / 100;
              END IF;

              INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
              VALUES (v_rec.partener, v_rec.CodLocatie, v_rec2.CodObiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
            EXCEPTION
              WHEN OTHERS THEN NULL;
            END;
          END LOOP;
        END IF;
      END LOOP;
    END IF;
  ELSE
    IF Coalesce(aTip,0) IN (0,1) THEN DELETE FROM TMP_INTRDISCV; END IF;
    IF Coalesce(aTip,0) IN (0,2) THEN DELETE FROM TMP_IESDISCV;  END IF;

    IF Coalesce(aTIP,0) IN (0,1) THEN
      FOR v_rec IN (
        SELECT
          C.CODCONTRACT, C.DATASTART, C.DATASTOP, Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
          Coalesce(C.TIPTARGETV,0) TIPTARGETV, C.SUBUNITATEA
        FROM Contract C
        WHERE C.TipDoc = 10 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ IN (1,3)
          AND C.DataStart &lt;= aDataStop AND (C.DataStop &gt;= aDataStart OR Coalesce(aTip,0) = 0)
          AND EXISTS (SELECT 1 FROM ContractV CV WHERE cv.codcontract = c.codcontract)
      ) LOOP
        vDataStart := v_rec.DataStart;
        LOOP
          IF v_rec.PERTARGET = 0
          THEN vDataStop := v_rec.DataStop;
          ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
          END IF;

          IF vDataStop &gt; v_rec.DataStop
          THEN vDataStop := v_rec.DataStop;
          END IF;

          IF v_rec.tiptargetv IN (0,1) THEN
            SELECT Coalesce(SUM(I1.Cant*I1.PU),0) INTO vVolumTotal
            FROM intrari i
              INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
            WHERE I.TipDoc IN (1,9)
              AND I.Anulat = 0 AND I.Operat = 1
              AND I.Partener = v_rec.Partener
              AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
              AND I.DataDoc BETWEEN vDataStart AND vDataStop
              AND I.Subunitatea = v_rec.Subunitatea
              AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
              AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
              AND (v_rec.tiptargetv = 0 OR I1.CodObiect IN (SELECT CODOBIECT FROM CONTRACT1 C1 WHERE CODCONTRACT = v_rec.CodContract));
            BEGIN
              SELECT
                Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
              INTO
                vProcDisc,
                vValDisc
              FROM ContractV CV
              WHERE CV.CodContract = v_rec.CodContract
                AND CV.SUMA &lt;= vVolumTotal;

              IF vProcDisc &lt;&gt; 0
              THEN vValDisc := vVolumTotal * vProcDisc / 100;
              END IF;

              IF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 0 THEN -- indiferent de articol
                INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                VALUES (v_rec.partener, v_rec.CodLocatie, 0, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
              ELSIF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 1 THEN -- mix articole
                INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                SELECT v_rec.partener, v_rec.CodLocatie, C1.codobiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea
                FROM Contract1 C1
                WHERE C1.CodContract = v_rec.CodContract;
              END IF;
            EXCEPTION
              WHEN OTHERS THEN NULL;
            END;
          ELSIF v_rec.tiptargetv = 2 THEN -- pe articole
            FOR v_rec2 IN (
              SELECT C1.CodContract1, I1.CodObiect, Coalesce(SUM(I1.Cant*I1.PU),0) VolumTotal
              FROM intrari i
                INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
                INNER JOIN (
                  SELECT C1.CodContract1, C1.CodObiect
                  FROM  Contract1 C1
                  WHERE C1.CODCONTRACT = v_rec.CodContract
                    AND EXISTS (SELECT 1 FROM CONTRACTV CV WHERE CV.CODCONTRACT1 = C1.CodContract1)
                ) C1 ON C1.CodObiect = i1.CodObiect
              WHERE I.TipDoc IN (1,9)
                AND I.Anulat = 0 AND I.Operat = 1
                AND I.Partener = v_rec.Partener
                AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
                AND I.Subunitatea = v_rec.Subunitatea
                AND I.DataDoc BETWEEN vDataStart AND vDataStop
                AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
                AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
              GROUP BY C1.CodContract1, I1.CodObiect
            ) LOOP

              vVolumTotal := v_rec2.VolumTotal;

              BEGIN
                SELECT
                  Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                  Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
                INTO
                  vProcDisc,
                  vValDisc
                FROM ContractV CV
                WHERE CV.CodContract1 = v_rec2.CodContract1
                  AND CV.SUMA &lt;= vVolumTotal;

                IF vProcDisc &lt;&gt; 0
                THEN vValDisc := vVolumTotal * vProcDisc / 100;
                END IF;

                INSERT INTO TMP_INTRDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                VALUES (v_rec.partener, v_rec.CodLocatie, v_rec2.CodObiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
              EXCEPTION
                WHEN OTHERS THEN NULL;
              END;
            END LOOP;
          END IF;
          vDataStart := vDataStop + 1;
          EXIT WHEN vDataStop = v_rec.DataStop;
        END LOOP;
      END LOOP;

    END IF;

    IF Coalesce(aTip,0) IN (0,2) THEN
      FOR v_rec IN (
        SELECT
          C.CODCONTRACT, C.DATASTART, C.DATASTOP, Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
          Coalesce(C.TIPTARGETV,0) TIPTARGETV, C.SUBUNITATEA
        FROM Contract C
        WHERE C.TipDoc = 27 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ IN (1,3)
          AND C.DataStart &lt;= aDataStop AND C.DataStop  &gt;= aDataStart
          AND EXISTS (SELECT 1 FROM ContractV CV WHERE cv.codcontract = c.codcontract)
      ) LOOP
        vDataStart := v_rec.DataStart;
        LOOP
          IF v_rec.PERTARGET = 0
          THEN vDataStop := v_rec.DataStop;
          ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
          END IF;

          IF vDataStop &gt; v_rec.DataStop
          THEN vDataStop := v_rec.DataStop;
          END IF;

          IF v_rec.tiptargetv IN (0,1) THEN
            SELECT Coalesce(SUM(I1.Cant*I1.PU),0) INTO vVolumTotal
            FROM iesiri i
              INNER JOIN iesiri1 I1 ON i.codies = i1.codies
            WHERE I.TipDoc IN (19,26)
              AND I.Anulat = 0 AND I.Operat = 1
              AND I.Partener = v_rec.Partener
              AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
              AND I.Subunitatea = v_rec.Subunitatea
              AND I.DataDoc BETWEEN vDataStart AND vDataStop
              AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
              AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
              AND (v_rec.tiptargetv = 0 OR I1.CodObiect IN (SELECT CODOBIECT FROM CONTRACT1 C1 WHERE CODCONTRACT = v_rec.CodContract));

            BEGIN
              SELECT
                Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
              INTO
                vProcDisc,
                vValDisc
              FROM ContractV CV
              WHERE CV.CodContract = v_rec.CodContract
                AND CV.SUMA &lt;= vVolumTotal;

              IF vProcDisc &lt;&gt; 0
              THEN vValDisc := vVolumTotal * vProcDisc / 100;
              END IF;

              IF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 0 THEN -- indiferent de articol
                INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                VALUES (v_rec.partener, v_rec.CodLocatie, 0, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
              ELSIF vValDisc &lt;&gt; 0 AND v_rec.tiptargetv = 1 THEN -- mix articole
                INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                SELECT v_rec.partener, v_rec.CodLocatie, C1.codobiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea
                FROM Contract1 C1
                WHERE C1.CodContract = v_rec.CodContract;
              END IF;
            EXCEPTION
              WHEN OTHERS THEN NULL;
            END;
          ELSIF v_rec.tiptargetv = 2 THEN -- pe articole
            FOR v_rec2 IN (
              SELECT C1.CodContract1, I1.CodObiect, Coalesce(SUM(I1.Cant*I1.PU),0) VolumTotal
              FROM iesiri i
                INNER JOIN iesiri1 I1 ON i.codies = i1.codies
                INNER JOIN (
                  SELECT C1.CodContract1, C1.CodObiect
                  FROM  Contract1 C1
                  WHERE C1.CODCONTRACT = v_rec.CodContract
                    AND EXISTS (SELECT 1 FROM CONTRACTV CV WHERE CV.CODCONTRACT1 = C1.CodContract1)
                ) C1 ON C1.CodObiect = i1.CodObiect
              WHERE I.TipDoc IN (19,26)
                AND I.Anulat = 0 AND I.Operat = 1
                AND I.Partener = v_rec.Partener
                AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
                AND I.Subunitatea = v_rec.Subunitatea
                AND I.DataDoc BETWEEN vDataStart AND vDataStop
                AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
                AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;
              GROUP BY C1.CodContract1, I1.CodObiect
            ) LOOP

              vVolumTotal := v_rec2.VolumTotal;

              BEGIN
                SELECT
                  Coalesce(Max(DISCOUNT)    KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ProcDisc,
                  Coalesce(Max(VALDISCOUNT) KEEP (DENSE_RANK LAST ORDER BY SUMA),0) ValDisc
                INTO
                  vProcDisc,
                  vValDisc
                FROM ContractV CV
                WHERE CV.CodContract1 = v_rec2.CodContract1
                  AND CV.SUMA &lt;= vVolumTotal;

                IF vProcDisc &lt;&gt; 0
                THEN vValDisc := vVolumTotal * vProcDisc / 100;
                END IF;

                INSERT INTO TMP_IESDISCV (PARTENER, LOCATIE, CODOBIECT, BAZA, DISC, DATASTART, DATASTOP, SUBUNITATEA)
                VALUES (v_rec.partener, v_rec.CodLocatie, v_rec2.CodObiect, vVolumTotal, vValDisc, vDataStart, vDataStop, v_rec.Subunitatea);
              EXCEPTION
                WHEN OTHERS THEN NULL;
              END;
            END LOOP;
          END IF;
          vDataStart := vDataStop + 1;
          EXIT WHEN vDataStop = v_rec.DataStop;
        END LOOP;
      END LOOP;
    END IF;
  END IF;
  COMMIT;
END;

PROCEDURE SIMULEAZA_DISCC(aDataStart IN DATE,
                          aDataStop  IN DATE,
                          aTip       IN NUMBER DEFAULT 0)-- 0 intrari si iesiri; 1 intrari; 2 iesiri
IS
--vArtDiscPrimTer   NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
--vArtDiscPrimVol   NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
--vArtDiscPrimCant  NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
--vArtPenPrim       NUMBER :=  Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vCantTot          NUMBER;
  vProcDisc         NUMBER;
  vValUnit          NUMBER;
  vDataStart        DATE;
  vDataStop         DATE;

  PROCEDURE SET_VALDISC(
    pCant         IN  NUMBER,
    pCodContract1 IN  NUMBER,
    pPjDisc       OUT NUMBER,
    pVDisc        OUT NUMBER
  ) IS
    vTipDisc INTEGER;
    vRest    NUMBER;
    vLastPj  NUMBER;
    vTot     NUMBER;
  BEGIN
    pPjDisc := 0;
    pVDisc  := 0;
    vTot    := 0;
    vRest   := pCant;
    IF pCant &lt;&gt; 0 THEN
      FOR vrec IN (
        SELECT c1.TipDiscountC, cc.CantMin, cc.Discount PjDisc, cc.ValDiscount VDisc
        FROM contract1 c1 INNER JOIN contractc cc ON cc.codcontract1 = c1.codcontract1
        WHERE c1.codcontract1 = pCodContract1 AND cc.cantmin &lt;= pCant
        ORDER BY cantmin DESC
      ) LOOP
        vTipDisc := vrec.TipDiscountC;
        IF vTipDisc = 0 THEN
          pPjDisc := vRec.PjDisc;
          EXIT;
        ELSIF vTipDisc = 1 THEN
          pVDisc  := vRec.VDisc;
          EXIT;
        ELSIF vTipDisc = 2 THEN
          vLastPj := vRec.PjDisc;
          vTot    := vTot + vLastPj*(vRest - vrec.CantMin);
          vRest   := vRest - vrec.CantMin;
        END IF;
      END LOOP;

      IF vTipDisc = 2 THEN
        vTot    := vTot + vLastPj*vRest;
        pPjDisc := vTot / pCant;
      END IF;
    END IF;
  END;


BEGIN
  IF Coalesce(aTip,0) IN (0,1) THEN DELETE FROM TMP_INTRDISCC; END IF;
  IF Coalesce(aTip,0) IN (0,2) THEN DELETE FROM TMP_IESDISCC;  END IF;

  IF Coalesce(aTip,0) IN (0,1) THEN
    FOR v_rec IN (
      SELECT
        C1.CODCONTRACT1, C1.TIPDISCOUNTC,
        Coalesce(C1.DATASTART, C.DATASTART) DATASTART, Coalesce(C1.DATASTOP,C.DATASTOP) DATASTOP,
        Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
        C1.CODOBIECT, C.SUBUNITATEA
      FROM Contract C
        INNER JOIN Contract1 C1 ON c1.codcontract = c.codcontract
      WHERE C.TipDoc = 10 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1
        AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataStop AND (Coalesce(C1.DATASTOP,C.DATASTOP) &gt;= aDataStart OR Coalesce(aTip,0) = 0)
        AND EXISTS (SELECT 1 FROM ContractC CC WHERE cc.codcontract1 = c1.codcontract1)
    ) LOOP
      vDataStart := v_rec.DataStart;
      LOOP
        IF v_rec.PERTARGET = 0
        THEN vDataStop := v_rec.DataStop;
        ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
        END IF;

        IF vDataStop &gt; v_rec.DataStop
        THEN vDataStop := v_rec.DataStop;
        END IF;

        SELECT Coalesce(SUM(I1.Cant),0) INTO vCantTot
        FROM intrari i
          INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
        WHERE I.TipDoc IN (1,9)
          AND I.Anulat = 0 AND I.Operat = 1
          AND I.Partener = v_rec.Partener
          AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
          AND I.Subunitatea = v_rec.Subunitatea
          AND I.DataDoc BETWEEN vDataStart AND vDataStop
          AND i1.CodObiect = v_rec.CodObiect;
          --AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
          --AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;

        SET_VALDISC(vCantTot, v_rec.CodContract1, vProcDisc, vValUnit);
        IF vProcDisc &lt;&gt; 0 OR vValUnit &lt;&gt; 0 THEN -- indiferent de articol
          INSERT INTO TMP_INTRDISCC (PARTENER, LOCATIE, CODOBIECT, PJDISC, DISCUNITAR, DATASTART, DATASTOP, SUBUNITATEA)
          VALUES (v_rec.partener, v_rec.CodLocatie, v_rec.CodObiect, vProcDisc, vValUnit, vDataStart, vDataStop, v_rec.Subunitatea);
        END IF;
        vDataStart := vDataStop + 1;
        EXIT WHEN vDataStop = v_rec.DataStop;
      END LOOP;
    END LOOP;

  END IF;

  IF Coalesce(aTip,0) IN (0,2) THEN
    FOR v_rec IN (
      SELECT
        C1.CODCONTRACT1, C1.TIPDISCOUNTC,
        Coalesce(C1.DATASTART, C.DATASTART) DATASTART, Coalesce(C1.DATASTOP,C.DATASTOP) DATASTOP,
        Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE,
        C1.CODOBIECT, C.SUBUNITATEA
      FROM Contract C
        INNER JOIN Contract1 C1 ON c1.codcontract = c.codcontract
      WHERE C.TipDoc = 27 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1
        AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataStop AND Coalesce(C1.DATASTOP,C.DATASTOP)  &gt;= aDataStart
        AND EXISTS (SELECT 1 FROM ContractC CC WHERE cc.codcontract1 = c1.codcontract1)
    ) LOOP
      vDataStart := v_rec.DataStart;
      LOOP
        IF v_rec.PERTARGET = 0
        THEN vDataStop := v_rec.DataStop;
        ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
        END IF;

        IF vDataStop &gt; v_rec.DataStop
        THEN vDataStop := v_rec.DataStop;
        END IF;

        SELECT Coalesce(SUM(I1.Cant),0) INTO vCantTot
        FROM iesiri i
          INNER JOIN iesiri1 I1 ON i.codies = i1.codies
        WHERE I.TipDoc IN (19,26)
          AND I.Anulat = 0 AND I.Operat = 1
          AND I.Partener = v_rec.Partener
          AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
          AND I.Subunitatea = v_rec.Subunitatea
          AND I.DataDoc BETWEEN vDataStart AND vDataStop
          AND i1.CodObiect = v_rec.CodObiect;
          --AND I1.CodObiect &lt;&gt; vArtDiscPrimTer AND I1.CodObiect &lt;&gt; vArtDiscPrimVol AND I1.CodObiect &lt;&gt; vArtDiscPrimCant AND I1.CodObiect &lt;&gt; vArtPenPrim
          --AND I1.TipLinie &lt;&gt; &apos;G&apos; AND I1.TipLinie &lt;&gt; &apos;T&apos;

        SET_VALDISC(vCantTot, v_rec.CodContract1, vProcDisc, vValUnit);
        IF vProcDisc &lt;&gt; 0 OR vValUnit &lt;&gt; 0 THEN -- indiferent de articol
          INSERT INTO TMP_IESDISCC (PARTENER, LOCATIE, CODOBIECT, PJDISC, DISCUNITAR, DATASTART, DATASTOP, SUBUNITATEA)
          VALUES (v_rec.partener, v_rec.CodLocatie, v_rec.CodObiect, vProcDisc, vValUnit, vDataStart, vDataStop, v_rec.Subunitatea);
        END IF;
        vDataStart := vDataStop + 1;
        EXIT WHEN vDataStop = v_rec.DataStop;
      END LOOP;
    END LOOP;

  END IF;
  COMMIT;
END;

PROCEDURE SIMULEAZA_CADOU(aDataStart IN DATE,
                          aDataStop  IN DATE,
                          aTip       IN NUMBER DEFAULT 0)-- 0 intrari si iesiri; 1 intrari; 2 iesiri
IS
  vCantTot          NUMBER;
  vCantSec          NUMBER;
  vCantCadou        NUMBER;
  vDataStart        DATE;
  vDataStop         DATE;
  vZecimale         NUMBER;

  FUNCTION ZecCount (pX NUMBER) RETURN NUMBER IS
    vAux  NUMBER;
    vZec  NUMBER;
  BEGIN
    vAux := pX;
    vZec := 0;
    WHILE vAux &gt; Trunc(vAux) LOOP
      vAux := vAux *10;
      vZec := vZec + 1;
    END LOOP;
    RETURN vZec;
  END;

BEGIN
  IF Coalesce(aTip,0) IN (0,1) THEN DELETE FROM TMP_INTRCADOU; END IF;
  IF Coalesce(aTip,0) IN (0,2) THEN DELETE FROM TMP_IESCADOU;  END IF;

  IF Coalesce(aTip,0) IN (0,1) THEN
    FOR v_rec IN (
      SELECT
        C1.CODCONTRACT1, C1.CODOBIECT, C1.LIMITACADOU, C1.CODCADOU, C1.CANTCADOU,
        Coalesce(C1.CODOBIECTSEC,0) CODOBIECTSEC, Coalesce(C1.LIMITACADOUSEC,0) LIMITACADOUSEC,
        Coalesce(C1.DATASTART, C.DATASTART) DATASTART, Coalesce(C1.DATASTOP,C.DATASTOP) DATASTOP,
        Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE, C.SUBUNITATEA
      FROM Contract C
        INNER JOIN Contract1 C1 ON c1.codcontract = c.codcontract
      WHERE C.TipDoc = 10 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1
        AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataStop AND (Coalesce(C1.DATASTOP,C.DATASTOP) &gt;= aDataStart OR Coalesce(aTip,0) = 0)
        AND Coalesce(C1.CodCadou,0) &gt; 0 AND Coalesce(C1.LimitaCadou,0) &gt; 0
    ) LOOP
      vDataStart := v_rec.DataStart;
      LOOP
        IF v_rec.PERTARGET = 0
        THEN vDataStop := v_rec.DataStop;
        ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
        END IF;

        IF vDataStop &gt; v_rec.DataStop
        THEN vDataStop := v_rec.DataStop;
        END IF;

        SELECT Coalesce(SUM(I1.Cant),0) INTO vCantTot
        FROM intrari i
          INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
        WHERE I.TipDoc IN (1,9)
          AND I.Anulat = 0 AND I.Operat = 1
          AND I.Partener = v_rec.Partener
          AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
          AND I.Subunitatea = v_rec.Subunitatea
          AND I.DataDoc BETWEEN vDataStart AND vDataStop
          AND i1.CodObiect = v_rec.CodObiect;

        vCantCadou := Round(vCantTot/v_rec.LimitaCadou)*v_rec.CantCadou;

        IF v_rec.CodObiectSec &gt; 0 AND v_rec.LimitaCadouSec &gt; 0 AND vCantCadou &gt; 0 THEN
          SELECT Coalesce(SUM(I1.Cant),0) INTO vCantSec
          FROM intrari i
            INNER JOIN intrari1 I1 ON i.codintr = i1.codintr
          WHERE I.TipDoc IN (1,9)
            AND I.Anulat = 0 AND I.Operat = 1
            AND I.Partener = v_rec.Partener
            AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
            AND I.Subunitatea = v_rec.Subunitatea
            AND I.DataDoc BETWEEN vDataStart AND vDataStop
            AND i1.CodObiect = v_rec.CodObiectSec;

          vCantCadou := Least(vCantCadou, Round(vCantSec/v_rec.LimitaCadouSec)*v_rec.CantCadou);
        END IF;

        IF vCantCadou &gt; 0 THEN
          vZecimale := ZecCount(v_rec.CantCadou);
          INSERT INTO TMP_INTRCADOU(
            PARTENER, LOCATIE, CODOBIECT, CANTOBIECT, CODCADOU, CANTCADOU, DATASTART, DATASTOP,
            SUBUNITATEA, ZECIMALE, DENCADOU)
          SELECT
            v_rec.Partener, v_rec.CodLocatie, v_rec.CodObiect, vCantTot, v_rec.Codcadou, vCantCadou, vDataStart, vDataStop,
            v_rec.Subunitatea, Greatest(vZecimale,UC.Zecimale), C.DENUMIRE
          FROM NARTOBJ C
            LEFT  JOIN NART AC ON AC.CODARTICOL = C.CodArticol
            LEFT  JOIN NUM  UC ON UC.CODUM      = AC.UM
          WHERE C.CodObiect = v_rec.CodCadou;
        END IF;
        vDataStart := vDataStop + 1;
        EXIT WHEN vDataStop = v_rec.DataStop;
      END LOOP;
    END LOOP;

  END IF;

  IF Coalesce(aTip,0) IN (0,2) THEN
    FOR v_rec IN (
      SELECT
        C1.CODCONTRACT1, C1.CODOBIECT, C1.LIMITACADOU, C1.CODCADOU, C1.CANTCADOU,
        Coalesce(C1.CODOBIECTSEC,0) CODOBIECTSEC, Coalesce(C1.LIMITACADOUSEC,0) LIMITACADOUSEC,
        Coalesce(C1.DATASTART, C.DATASTART) DATASTART, Coalesce(C1.DATASTOP,C.DATASTOP) DATASTOP,
        Coalesce(C.PERTARGET,0) PERTARGET, C.PARTENER, C.CODLOCATIE, C.SUBUNITATEA
      FROM Contract C
        INNER JOIN Contract1 C1 ON c1.codcontract = c.codcontract
      WHERE C.TipDoc = 27 AND C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1
        AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataStop AND Coalesce(C1.DATASTOP,C.DATASTOP)  &gt;= aDataStart
        AND Coalesce(C1.CodCadou,0) &gt; 0 AND Coalesce(C1.LimitaCadou,0) &gt; 0
    ) LOOP
      vDataStart := v_rec.DataStart;
      LOOP
        IF v_rec.PERTARGET = 0
        THEN vDataStop := v_rec.DataStop;
        ELSE vDataStop := Add_Months(vDataStart, v_rec.PERTARGET) - 1;
        END IF;

        IF vDataStop &gt; v_rec.DataStop
        THEN vDataStop := v_rec.DataStop;
        END IF;

        SELECT Coalesce(SUM(I1.Cant),0) INTO vCantTot
        FROM iesiri i
          INNER JOIN iesiri1 I1 ON i.codies = i1.codies
        WHERE I.TipDoc IN (19,26)
          AND I.Anulat = 0 AND I.Operat = 1
          AND I.Partener = v_rec.Partener
          AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
          AND I.Subunitatea = v_rec.Subunitatea
          AND I.DataDoc BETWEEN vDataStart AND vDataStop
          AND i1.CodObiect = v_rec.CodObiect;

        vCantCadou := Round(vCantTot/v_rec.LimitaCadou)*v_rec.CantCadou;

        IF v_rec.CodObiectSec &gt; 0 AND v_rec.LimitaCadouSec &gt; 0 AND vCantCadou &gt; 0 THEN
          SELECT Coalesce(SUM(I1.Cant),0) INTO vCantSec
          FROM iesiri i
            INNER JOIN iesiri1 I1 ON i.codies = i1.codies
          WHERE I.TipDoc IN (19,26)
            AND I.Anulat = 0 AND I.Operat = 1
            AND I.Partener = v_rec.Partener
            AND (v_rec.CodLocatie = 0 OR I.CodLocatie = v_rec.CodLocatie)
            AND I.Subunitatea = v_rec.Subunitatea
            AND I.DataDoc BETWEEN vDataStart AND vDataStop
            AND i1.CodObiect = v_rec.CodObiectSec;

          vCantCadou := Least(vCantCadou, Round(vCantSec/v_rec.LimitaCadouSec)*v_rec.CantCadou);
        END IF;

        IF vCantCadou &gt; 0 THEN
          vZecimale := ZecCount(v_rec.CantCadou);
          INSERT INTO TMP_IESCADOU (
            PARTENER, LOCATIE, CODOBIECT, CANTOBIECT, CODCADOU, CANTCADOU, DATASTART, DATASTOP,
            SUBUNITATEA, ZECIMALE, DENCADOU)
          SELECT
            v_rec.Partener, v_rec.CodLocatie, v_rec.CodObiect, vCantTot, v_rec.Codcadou, vCantCadou, vDataStart, vDataStop,
            v_rec.Subunitatea, Greatest(vZecimale,UC.Zecimale), C.DENUMIRE
          FROM NARTOBJ C
            LEFT  JOIN NART AC ON AC.CODARTICOL = C.CodArticol
            LEFT  JOIN NUM  UC ON UC.CODUM      = AC.UM
          WHERE C.CodObiect = v_rec.CodCadou;
        END IF;
        vDataStart := vDataStop + 1;
        EXIT WHEN vDataStop = v_rec.DataStop;
      END LOOP;
    END LOOP;

  END IF;
  COMMIT;
END;

PROCEDURE SIMCADOU_SET (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                        aCodObiect IN NUMBER,
                        aPart      IN NUMBER,
                        aLocatie   IN NUMBER,
                        aSubunit   IN NUMBER,
                        aDataRef   IN DATE ) IS
  pTipContr NUMBER := 0;
BEGIN
  IF aTip = 1 AND
     ( (Coalesce(pCadIntrCodObj,0) &lt;&gt; aCodObiect) OR (Coalesce(pCadIntrPart,0) &lt;&gt; aPart) OR (Coalesce(pCadIntrLocatie,0) &lt;&gt; aLocatie) OR
       (Coalesce(pCadIntrSubunit,0) &lt;&gt; aSubunit) OR (Coalesce(pCadIntrDataRef,aDataRef) &lt;&gt; aDataRef)
     )
  THEN
    pCadIntrCodObj  := aCodObiect;
    pCadIntrPart    := aPart;
    pCadIntrLocatie := aLocatie;
    pCadIntrSubunit := aSubunit;
    pCadIntrDataRef := aDataRef;
    pCadIntrCantObj := 0;
    pCadIntrCant    := 0;
    pCadIntrCod     := 0;
    pCadIntrZec     := 0;
    pCadIntrDen     := &apos;&apos;;

    FOR v_rec IN (
      SELECT CANTOBIECT, CODCADOU, CANTCADOU, ZECIMALE, DENCADOU
      FROM TMP_INTRCADOU
      WHERE PARTENER = pCadIntrPart
        AND SUBUNITATEA = pCadIntrSubunit
        AND CODOBIECT = pCadIntrCodObj
        AND (LOCATIE = 0 OR LOCATIE = pCadIntrLocatie)
        AND DATASTART &lt;= pCadIntrDataRef
        AND DATASTOP  &gt;= pCadIntrDataRef
      ORDER BY LOCATIE DESC
    ) LOOP
      pCadIntrCantObj := v_rec.CANTOBIECT;
      pCadIntrCant    := v_rec.CANTCADOU;
      pCadIntrCod     := v_rec.CODCADOU;
      pCadIntrZec     := v_rec.ZECIMALE;
      pCadIntrDen     := v_rec.DENCADOU;
      EXIT;
    END LOOP;
  END IF;

  IF aTip = 2 AND
     ( (Coalesce(pCadIesCodObj,0) &lt;&gt; aCodObiect) OR (Coalesce(pCadIesPart,0) &lt;&gt; aPart) OR (Coalesce(pCadIesLocatie,0) &lt;&gt; aLocatie) OR
       (Coalesce(pCadIesSubunit,0) &lt;&gt; aSubunit) OR (Coalesce(pCadIesDataRef,aDataRef) &lt;&gt; aDataRef)
     )
  THEN
    pCadIesCodObj  := aCodObiect;
    pCadIesPart    := aPart;
    pCadIesLocatie := aLocatie;
    pCadIesSubunit := aSubunit;
    pCadIesDataRef := aDataRef;
    pCadIesCantObj := 0;
    pCadIesCant    := 0;
    pCadIesCod     := 0;
    pCadIesZec     := 0;
    pCadIntrDen    := &apos;&apos;;

    FOR v_rec IN (
      SELECT CANTOBIECT, CODCADOU, CANTCADOU, ZECIMALE, DENCADOU
      FROM TMP_IESCADOU
      WHERE PARTENER = pCadIesPart
        AND SUBUNITATEA = pCadIesSubunit
        AND CODOBIECT = pCadIesCodObj
        AND (LOCATIE = 0 OR LOCATIE = pCadIesLocatie)
        AND DATASTART &lt;= pCadIesDataRef
        AND DATASTOP  &gt;= pCadIesDataRef
      ORDER BY LOCATIE DESC
    ) LOOP
      pCadIesCantObj := v_rec.CANTOBIECT;
      pCadIesCant    := v_rec.CANTCADOU;
      pCadIesCod     := v_rec.CODCADOU;
      pCadIesZec     := v_rec.ZECIMALE;
      pCadIesDen     := v_rec.DENCADOU;
      EXIT;
    END LOOP;
  END IF;

END;

FUNCTION  SIMCADOU_COD (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                        aCodObiect IN NUMBER,
                        aPart      IN NUMBER,
                        aLocatie   IN NUMBER,
                        aSubunit   IN NUMBER,
                        aDataRef   IN DATE  ) RETURN NUMBER IS
  vCod NUMBER;
BEGIN
  vCod := 0;
  IF aTip IN (1,2)
    AND aCodObiect IS NOT NULL
    AND aPart IS NOT NULL
    AND aLocatie IS NOT NULL
    AND aSubunit IS NOT NULL
    AND aDataRef IS NOT NULL
  THEN
    SIMCADOU_SET (aTip, aCodObiect, aPart, aLocatie, aSubunit, aDataRef);
    vCod := CASE aTip WHEN 1 THEN pCadIntrCod WHEN 2 THEN pCadIesCod ELSE 0 END;
  END IF;
  RETURN vCod;
END;

FUNCTION  SIMCADOU_DEN (aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                        aCodObiect IN NUMBER,
                        aPart      IN NUMBER,
                        aLocatie   IN NUMBER,
                        aSubunit   IN NUMBER,
                        aDataRef   IN DATE  ) RETURN VARCHAR2 IS
  vDen VARCHAR2(200);
BEGIN
  vDen := &apos;&apos;;
  IF aTip IN (1,2)
    AND aCodObiect IS NOT NULL
    AND aPart IS NOT NULL
    AND aLocatie IS NOT NULL
    AND aSubunit IS NOT NULL
    AND aDataRef IS NOT NULL
  THEN
    SIMCADOU_SET (aTip, aCodObiect, aPart, aLocatie, aSubunit, aDataRef);
    vDen := CASE aTip WHEN 1 THEN pCadIntrDen WHEN 2 THEN pCadIesDen ELSE NULL END;
  END IF;
  RETURN vDen;
END;

FUNCTION  SIMCADOU_CANT(aTip       IN NUMBER,-- 1 intrari ; 2 iesiri
                        aCodObiect IN NUMBER,
                        aPart      IN NUMBER,
                        aLocatie   IN NUMBER,
                        aSubunit   IN NUMBER,
                        aDataRef   IN DATE  ,
                        aCant      IN NUMBER) RETURN NUMBER IS
  vCant NUMBER;
BEGIN
  vCant := 0;
  IF aTip IN (1,2)
    AND aCodObiect IS NOT NULL
    AND aPart IS NOT NULL
    AND aLocatie IS NOT NULL
    AND aSubunit IS NOT NULL
    AND Coalesce(aCant,0) &lt;&gt; 0
    AND aDataRef IS NOT NULL
  THEN
    SIMCADOU_SET (aTip, aCodObiect, aPart, aLocatie, aSubunit, aDataRef);
    vCant := CASE
              WHEN aTip = 1 AND pCadIntrCantObj &lt;&gt; 0 THEN Round(pCadIntrCant*aCant/pCadIntrCantObj,pCadIntrZec)
              WHEN aTip = 2 AND pCadIesCantObj  &lt;&gt; 0 THEN Round(pCadIesCant *aCant/pCadIesCantObj ,pCadIesZec)
              ELSE 0
            END;
  END IF;
  RETURN vCant;
END;



PROCEDURE GETCADOU_SET  ( aTipDoc    IN NUMBER,
                          aCodObiect IN NUMBER,
                          aPart      IN NUMBER,
                          aLocatie   IN NUMBER,
                          aSubunit   IN NUMBER,
                          aCant      IN NUMBER,
                          aDataRef   IN DATE ) IS
  pTipContr NUMBER := 0;
BEGIN
  pCadouTipDoc  := aTipDoc;
  pCadouCodObj  := aCodObiect;
  pCadouPart    := aPart;
  pCadouLocatie := aLocatie;
  pCadouSubunit := aSubunit;
  pCadouCantObj := aCant;
  pCadouDataRef := aDataRef;

  IF    aTipDoc IN ( 1, 2, 3, 9) THEN pTipContr := 10;
  ELSIF aTipDoc IN (19,20,21,26) THEN pTipContr := 27;
  END IF;

  SELECT
    C1.CODCADOU,
    Round(aCant/C1.LIMITACADOU)*C1.CANTCADOU
  INTO
    vCadouCod,
    vCadouCant
  FROM Contract C
    INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
  WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = pTipContr
    AND C.Partener = aPart
    AND (C.CodLocatie = 0 OR C.CodLocatie = aLocatie)
    AND C.Subunitatea = aSubunit
    AND C1.Codobiect = aCodObiect
    AND Coalesce(C1.CodObiectSec, 0) = 0
    AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataRef AND Coalesce(C1.DATASTOP,C.DATASTOP) &gt;= aDataRef
    AND Coalesce(C1.CODCADOU,0) &lt;&gt; 0
    AND Coalesce(C1.LIMITACADOU,0) &lt;= aCant
    AND RowNum = 1;
EXCEPTION
  WHEN OTHERS THEN
    vCadouCant := 0;
    vCadouCod  := 0;
END;

FUNCTION  GETCADOU_COD  ( aTipDoc    IN NUMBER,
                          aCodObiect IN NUMBER,
                          aPart      IN NUMBER,
                          aLocatie   IN NUMBER,
                          aSubunit   IN NUMBER,
                          aCant      IN NUMBER,
                          aDataRef   IN DATE ) RETURN NUMBER
IS
BEGIN
  IF aTipDoc IS NULL OR aCodObiect IS NULL OR aPart IS NULL OR aLocatie IS NULL OR aSubunit IS NULL OR aCant IS NULL OR aDataRef IS NULL
  THEN RETURN 0;
  END IF;

  IF (Coalesce(pCadouTipDoc,0) &lt;&gt; aTipDoc) OR (Coalesce(pCadouCodObj,0) &lt;&gt; aCodObiect) OR (Coalesce(pCadouPart,0) &lt;&gt; aPart) OR
     (Coalesce(pCadouLocatie,0) &lt;&gt; aLocatie) OR (Coalesce(pCadouSubunit,0) &lt;&gt; aSubunit) OR (Coalesce(pCadouCantObj,0) &lt;&gt; aCant) OR
     (pCadouDataRef IS NULL) OR Coalesce(pCadouDataRef,aDataRef) &lt;&gt; aDataRef
  THEN GETCADOU_SET (aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aCant, aDataRef);
  END IF;
  RETURN vCadouCod;
END;

FUNCTION  GETCADOU_CANT ( aTipDoc    IN NUMBER,
                          aCodObiect IN NUMBER,
                          aPart      IN NUMBER,
                          aLocatie   IN NUMBER,
                          aSubunit   IN NUMBER,
                          aCant      IN NUMBER,
                          aDataRef   IN DATE ) RETURN NUMBER
IS
BEGIN
  IF aTipDoc IS NULL OR aCodObiect IS NULL OR aPart IS NULL OR aLocatie IS NULL OR aSubunit IS NULL OR aCant IS NULL OR aDataRef IS NULL
  THEN RETURN 0;
  END IF;

  IF (Coalesce(pCadouTipDoc,0) &lt;&gt; aTipDoc) OR (Coalesce(pCadouCodObj,0) &lt;&gt; aCodObiect) OR (Coalesce(pCadouPart,0) &lt;&gt; aPart) OR
     (Coalesce(pCadouLocatie,0) &lt;&gt; aLocatie) OR (Coalesce(pCadouSubunit,0) &lt;&gt; aSubunit) OR (Coalesce(pCadouCantObj,0) &lt;&gt; aCant) OR
     (pCadouDataRef IS NULL) OR Coalesce(pCadouDataRef,aDataRef) &lt;&gt; aDataRef
  THEN GETCADOU_SET (aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aCant, aDataRef);
  END IF;
  RETURN vCadouCant;
END;

FUNCTION GETLINCONTR (aTipDoc    IN NUMBER,
                      aCodObiect IN NUMBER,
                      aPart      IN NUMBER,
                      aLocatie   IN NUMBER,
                      aSubunit   IN NUMBER,
                      aDataRef   IN DATE )
RETURN NUMBER IS
  vD        DATE   := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);
  pTipContr NUMBER := 0;
BEGIN
  IF aTipDoc IS NULL OR aCodObiect IS NULL OR aPart IS NULL OR aLocatie IS NULL OR aSubunit IS NULL OR aDataRef IS NULL
  THEN RETURN 0;
  ELSIF (Coalesce(pLinTipDoc,0) &lt;&gt; aTipDoc) OR (Coalesce(pLinCodObiect,0) &lt;&gt; aCodObiect) OR (Coalesce(pLinPart,0) &lt;&gt; aPart) OR
        (Coalesce(pLinLocatie,0) &lt;&gt; aLocatie) OR (Coalesce(pLinSubunit,0) &lt;&gt; aSubunit) OR (Coalesce(pLinDataRef,vD) &lt;&gt; aDataRef)
  THEN
    pLinTipDoc    := aTipDoc;
    pLinCodObiect := aCodObiect;
    pLinPart      := aPart;
    pLinLocatie   := aLocatie;
    pLinSubunit   := aSubunit;
    pLinDataRef   := aDataRef;

    pLinContract  := 0;
    pPretContract := NULL;
    pPjDiscContr  := 0;
    pAdDimContr   := 0;
    pC1Anexa      := NULL;
    pC1DataStart  := NULL;
    pC1DataStop   := NULL;


    IF    aTipDoc IN ( 1, 2, 3, 9) THEN pTipContr := 10;
    ELSIF aTipDoc IN (19,20,21,26) THEN pTipContr := 27;
    END IF;

    SELECT C1.CodContract1, C1.Pret, Coalesce(C1.ProcDisc,0), Coalesce(C1.AdDim,0), C1.Anexa, C1.DataStart, C1.DataStop
    INTO pLinContract, pPretContract, pPjDiscContr, pAdDimContr, pC1Anexa, pC1DataStart, pC1DataStop
    FROM Contract C INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
    WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = pTipContr
      AND C.Partener = aPart
      AND (C.CodLocatie = 0 OR C.CodLocatie = aLocatie)
      AND C.Subunitatea = aSubunit
      AND C1.Codobiect = aCodObiect
      AND Coalesce(C1.CodObiectSec, 0) = 0
      AND Coalesce(C1.DATASTART, C.DATASTART) &lt;= aDataRef
      AND Coalesce(C1.DATASTOP,  C.DATASTOP)  &gt;= aDataRef
      AND ROWNUM = 1;
  END IF;
  RETURN pLinContract;
EXCEPTION
  WHEN No_Data_Found THEN RETURN 0;
  WHEN OTHERS        THEN RETURN 0;
END;

FUNCTION  GETPRET(aTipDoc    IN NUMBER,
                  aCodObiect IN NUMBER,
                  aPart      IN NUMBER,
                  aLocatie   IN NUMBER,
                  aSubunit   IN NUMBER,
                  aDataRef   IN DATE )
RETURN NUMBER IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN NULL;
  ELSE RETURN pPretContract;
  END IF;
END;

FUNCTION  GETPROCDISC(aTipDoc    IN NUMBER,
                      aCodObiect IN NUMBER,
                      aPart      IN NUMBER,
                      aLocatie   IN NUMBER,
                      aSubunit   IN NUMBER,
                      aDataRef   IN DATE )
RETURN NUMBER IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN 0;
  ELSE RETURN pPjDiscContr;
  END IF;
END;

FUNCTION  GETADDIM(aTipDoc    IN NUMBER,
                   aCodObiect IN NUMBER,
                   aPart      IN NUMBER,
                   aLocatie   IN NUMBER,
                   aSubunit   IN NUMBER,
                   aDataRef   IN DATE )
RETURN NUMBER IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN 0;
  ELSE RETURN pAdDimContr;
  END IF;
END;

FUNCTION  GETC1ANEXA(
  aTipDoc    IN NUMBER,
  aCodObiect IN NUMBER,
  aPart      IN NUMBER,
  aLocatie   IN NUMBER,
  aSubunit   IN NUMBER,
  aDataRef   IN DATE )
RETURN NUMBER IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN NULL;
  ELSE RETURN pC1Anexa;
  END IF;
END;

FUNCTION  GETC1DSTART(
  aTipDoc    IN NUMBER,
  aCodObiect IN NUMBER,
  aPart      IN NUMBER,
  aLocatie   IN NUMBER,
  aSubunit   IN NUMBER,
  aDataRef   IN DATE )
RETURN DATE IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN NULL;
  ELSE RETURN pC1DataStart;
  END IF;
END;

FUNCTION GETC1DSTOP(
  aTipDoc    IN NUMBER,
  aCodObiect IN NUMBER,
  aPart      IN NUMBER,
  aLocatie   IN NUMBER,
  aSubunit   IN NUMBER,
  aDataRef   IN DATE )
RETURN DATE IS
BEGIN
  IF GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef) = 0
  THEN RETURN NULL;
  ELSE RETURN pC1DataStop;
  END IF;
END;

FUNCTION  GETTERMEN(aTipDoc    IN NUMBER,
                    aCodObiect IN NUMBER,
                    aPart      IN NUMBER,
                    aLocatie   IN NUMBER,
                    aSubunit   IN NUMBER,
                    aDataRef   IN DATE )
RETURN termene_contract IS
  pCodContract1 NUMBER         := GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef);
  vIdx          NUMBER         := 0;
  vCumulat      NUMBER         := 0;
  vOk           BOOLEAN        := TRUE;
  vTip          VARCHAR2( 100) := &apos;&apos;;
  vTermen1      DATE           := NULL;
  vTermen2      DATE           := NULL;
  vTermen3      VARCHAR2(1000) := &apos;&apos;;
  vDisc1        NUMBER(20,7)   := NULL;
  vDisc2        NUMBER(20,7)   := NULL;
  vDisc3        VARCHAR2(1000) := &apos;&apos;;
  vAnexa        NUMBER(20)     := NULL;
  vDataStart    DATE           := NULL;
  vDataStop     DATE           := NULL;

BEGIN
  FOR vRec IN (
    SELECT
      c1.tipdiscountt, c1.tipdiscountt1, c1.disctcumulat,
      CASE WHEN c1.tipdiscountt = 0 THEN aDataRef + ct.zile ELSE ct.termenfix END termen,
      CASE
        WHEN c1.tipdiscountt1 = 0 THEN &apos;%&apos;
        WHEN c1.disctcumulat = 1  THEN &apos;/DOC&apos;
        ELSE &apos;/UM&apos;
      END tip,
      CASE
        WHEN c1.disctcumulat = 1 AND c1.tipdiscountt1 = 0 THEN c1.disct
        WHEN c1.disctcumulat = 1 THEN c1.disct
        WHEN c1.tipdiscountt1 = 0 THEN ct.discount
        ELSE ct.valdiscount
      END disc,
      c1.anexa, c1.datastart, c1.datastop
    FROM contract1 c1 INNER JOIN contractt ct ON ct.codcontract1 = c1.codcontract1
    WHERE c1.codcontract1 = pCodContract1
    ORDER BY CASE WHEN c1.tipdiscountt = 0 THEN aDataRef + ct.zile ELSE ct.termenfix END
  ) LOOP
    vCumulat := vRec.disctcumulat;
    vOk      := vRec.Termen &gt;= aDataRef;
    IF vOk THEN
      vTip       := vRec.Tip;
      vAnexa     := vRec.Anexa;
      vDataStart := vRec.DataStart;
      vDataStop  := vRec.DataStop;
      vIdx := vIdx + 1;
      IF vIdx &gt; 3 THEN
        vTermen3 := vTermen3||&apos;;&apos;;
        vDisc3   := vDisc3||&apos;;&apos;;
      END IF;
      IF vIdx = 1 THEN
        vTermen1 := vRec.termen;
        vDisc1   := vRec.disc;
      ELSIF vIdx = 2 THEN
        vTermen2 := vRec.termen;
        vDisc2   := vRec.disc;
      ELSE
        vTermen3 := vTermen3||To_Char(vRec.termen,&apos;dd.mm.yyyy&apos;);
        vDisc3   := vDisc3||vRec.disc;
      END IF;
    ELSE
      EXIT WHEN vCumulat = 1;
    END IF;
  END LOOP;
  RETURN termene_contract(vTip, vTermen1, vTermen2, vTermen3, vDisc1, vDisc2, vDisc3);
END;

FUNCTION  DISCMAXTERMEN (aTipDoc    IN NUMBER,
                          aCodObiect IN NUMBER,
                          aPart      IN NUMBER,
                          aLocatie   IN NUMBER,
                          aSubunit   IN NUMBER,
                          aDataRef   IN DATE  ,
                          aCant      IN NUMBER,
                          aPret      IN NUMBER )
RETURN NUMBER IS
  pCodContract1 NUMBER         := GETLINCONTR(aTipDoc, aCodObiect, aPart, aLocatie, aSubunit, aDataRef);
  vResult       NUMBER         := 0;
BEGIN
  SELECT
    Min(
      CASE
        WHEN c1.DiscTCumulat = 1 AND c1.TipDiscountT1 = 1 THEN aCant * DiscT
        WHEN c1.DiscTCumulat = 1 THEN aCant * aPret * c1.DiscT / 100
        WHEN c1.TipDiscountT1 = 1 THEN aCant * ct.valdiscount
        ELSE aCant * aPret * ct.discount / 100
      END
    )
  INTO vResult
  FROM contract1 c1 INNER JOIN contractt ct ON ct.codcontract1 = c1.codcontract1
  WHERE c1.codcontract1 = pCodContract1;
  RETURN Coalesce(vResult,0);
END;


FUNCTION  ContractVDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER IS
  vResult NUMBER := 0;
BEGIN
  SELECT
    Coalesce(Max(
      CASE
        WHEN A.IDX IS NULL                                THEN 1
        WHEN B.IDX IS NULL                                THEN 1
        WHEN Coalesce(A.SUMA,0)        &lt;&gt; Coalesce(B.SUMA,0)        THEN 1
        WHEN Coalesce(A.DISCOUNT,0)    &lt;&gt; Coalesce(B.DISCOUNT,0)    THEN 1
        WHEN Coalesce(A.VALDISCOUNT,0) &lt;&gt; Coalesce(B.VALDISCOUNT,0) THEN 1
        ELSE 0 END
    ),0)
  INTO vResult
  FROM (
    SELECT Row_Number() OVER (ORDER BY SUMA) IDX, SUMA, DISCOUNT, VALDISCOUNT
    FROM CONTRACTV
    WHERE CODCONTRACT1 = aCodContract1
  ) A
  FULL JOIN (
    SELECT Row_Number() OVER (ORDER BY SUMA) IDX, SUMA, DISCOUNT, VALDISCOUNT
    FROM CONTRACTV
    WHERE CODCONTRACT1 = bCodContract1
  ) B ON B.IDX = A.IDX;

  RETURN vResult;
END;

FUNCTION  ContractTDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER IS
  vResult NUMBER := 0;
  vD      DATE   := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);
BEGIN
  SELECT
    Coalesce(Max(
      CASE
        WHEN A.IDX IS NULL                                THEN 1
        WHEN B.IDX IS NULL                                THEN 1
        WHEN Coalesce(A.ZILE,0)        &lt;&gt; Coalesce(B.ZILE,0)        THEN 1
        WHEN Coalesce(A.DISCOUNT,0)    &lt;&gt; Coalesce(B.DISCOUNT,0)    THEN 1
        WHEN Coalesce(A.VALDISCOUNT,0) &lt;&gt; Coalesce(B.VALDISCOUNT,0) THEN 1
        WHEN Coalesce(A.TERMENFIX,vD)  &lt;&gt; Coalesce(B.TERMENFIX,vD)  THEN 1
        WHEN Coalesce(A.PROCVALDOC,0)  &lt;&gt; Coalesce(B.PROCVALDOC,0)  THEN 1

        ELSE 0 END
    ),0)
  INTO vResult
  FROM (
    SELECT Row_Number() OVER (ORDER BY ZILE, TERMENFIX) IDX, ZILE, DISCOUNT, VALDISCOUNT, TERMENFIX, PROCVALDOC
    FROM CONTRACTT
    WHERE CODCONTRACT1 = aCodContract1
  ) A
  FULL JOIN (
    SELECT Row_Number() OVER (ORDER BY ZILE, TERMENFIX) IDX, ZILE, DISCOUNT, VALDISCOUNT, TERMENFIX, PROCVALDOC
    FROM CONTRACTT
    WHERE CODCONTRACT1 = bCodContract1
  ) B ON B.IDX = A.IDX;

  RETURN vResult;
END;

FUNCTION  ContractCDiferit(aCodContract1 IN NUMBER, bCodContract1 IN NUMBER) RETURN NUMBER IS
  vResult NUMBER := 0;
BEGIN
  SELECT
    Coalesce(Max(
      CASE
        WHEN A.IDX IS NULL                                THEN 1
        WHEN B.IDX IS NULL                                THEN 1
        WHEN Coalesce(A.CANTMIN,0)     &lt;&gt; Coalesce(B.CANTMIN,0)     THEN 1
        WHEN Coalesce(A.DISCOUNT,0)    &lt;&gt; Coalesce(B.DISCOUNT,0)    THEN 1
        WHEN Coalesce(A.VALDISCOUNT,0) &lt;&gt; Coalesce(B.VALDISCOUNT,0) THEN 1
        ELSE 0 END
    ),0)
  INTO vResult
  FROM (
    SELECT Row_Number() OVER (ORDER BY CANTMIN) IDX, CANTMIN, DISCOUNT, VALDISCOUNT
    FROM CONTRACTC
    WHERE CODCONTRACT1 = aCodContract1
  ) A
  FULL JOIN (
    SELECT Row_Number() OVER (ORDER BY CANTMIN) IDX, CANTMIN, DISCOUNT, VALDISCOUNT
    FROM CONTRACTC
    WHERE CODCONTRACT1 = bCodContract1
  ) B ON B.IDX = A.IDX;

  RETURN vResult;
END;

FUNCTION  UPD_CONTRACTEDINCADRU (aCodCadru IN NUMBER) RETURN VARCHAR2 IS
  vEroare      NUMBER     := 0;
  vLastLocked  NUMBER(20) := 0;
  vLastBlocked NUMBER(20) := 0;
  vResult      VARCHAR2(4000);
  vD           DATE       := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);
  RES_BUSY     EXCEPTION;
  PRAGMA       EXCEPTION_INIT(RES_BUSY, -54);
  vCount       NUMBER     := 0;
  vCodIdx      NUMBER     := 0;
  vCodLastIdx  NUMBER     := 0;
  bFound       BOOLEAN;
BEGIN
  BEGIN
    SP_LOCKRECORD(aCodCadru);
  EXCEPTION
    WHEN RES_BUSY      THEN
      vEroare := 1;
      vResult := &apos;Contractul cadru este blocat pentru modificare&apos;;
    WHEN NO_DATA_FOUND THEN
      vEroare := 2;
      vResult := &apos;Contractul cadru a fost sters&apos;;
    WHEN OTHERS        THEN
      vEroare := SQLCODE;
      vResult := SQLERRM;
  END;

  IF vEroare = 0 THEN
    FOR vRec IN (
      SELECT
        C1.CodContract1, C.CodContract, C.NrDoc, C.DataDoc, C1.CodContr1Cadru,
        CASE
          WHEN Coalesce(CC1.codobiect,0)      &lt;&gt; Coalesce(C1.codobiect,0)                THEN 1
          WHEN Coalesce(CC1.umsec,0)          &lt;&gt; Coalesce(C1.umsec,0)                    THEN 1
          WHEN Coalesce(CC1.cant,0)           &lt;&gt; Coalesce(C1.cant,0)                     THEN 1
          WHEN Coalesce(CC1.pret,0)           &lt;&gt; Coalesce(C1.pret,0)                     THEN 1
          WHEN Coalesce(CC1.procdisc,0)       &lt;&gt; Coalesce(C1.procdisc,0)                 THEN 1
          WHEN Coalesce(CC1.addim,0)          &lt;&gt; Coalesce(C1.addim,0)                    THEN 1
          WHEN Coalesce(CC1.zilel,0)          &lt;&gt; Coalesce(C1.zilel,0)                    THEN 1
          WHEN Coalesce(CC1.zilec,0)          &lt;&gt; Coalesce(C1.zilec,0)                    THEN 1
          WHEN Coalesce(CC1.valtarget,0)      &lt;&gt; Coalesce(C1.valtarget,0)                THEN 1
          WHEN Coalesce(CC1.limitacadou,0)    &lt;&gt; Coalesce(C1.limitacadou,0)              THEN 1
          WHEN Coalesce(CC1.cantcadou,0)      &lt;&gt; Coalesce(C1.cantcadou,0)                THEN 1
          WHEN Coalesce(CC1.codcadou,0)       &lt;&gt; Coalesce(C1.codcadou,0)                 THEN 1
          WHEN Coalesce(CC1.codobiectsec,0)   &lt;&gt; Coalesce(C1.codcadou,0)                 THEN 1
          WHEN Coalesce(CC1.limitacadousec,0) &lt;&gt; Coalesce(C1.limitacadousec,0)           THEN 1
          WHEN Coalesce(CC1.termenfix,vD)     &lt;&gt; Coalesce(C1.termenfix,vD)               THEN 1
          WHEN Coalesce(CC1.tippret,0)        &lt;&gt; Coalesce(C1.tippret,0)                  THEN 1
          WHEN Coalesce(CC1.tipdiscount,0)    &lt;&gt; Coalesce(C1.tipdiscount,0)              THEN 1
          WHEN Coalesce(CC1.tipdiscountt,0)   &lt;&gt; Coalesce(C1.tipdiscountt,0)             THEN 1
          WHEN Coalesce(CC1.tipdiscountc,0)   &lt;&gt; Coalesce(C1.tipdiscountc,0)             THEN 1
          WHEN Coalesce(CC1.sumafixa,0)       &lt;&gt; Coalesce(C1.sumafixa,0)                 THEN 1
          WHEN Coalesce(CC1.tipdiscountt1,0)  &lt;&gt; Coalesce(C1.tipdiscountt1,0)            THEN 1
          WHEN Coalesce(CC1.codclasa,0)       &lt;&gt; Coalesce(C1.codclasa,0)                 THEN 1
          WHEN Coalesce(CC1.disctcumulat,0)   &lt;&gt; Coalesce(C1.disctcumulat,0)             THEN 1
          WHEN Coalesce(CC1.disct,0)          &lt;&gt; Coalesce(C1.disct,0)                    THEN 1
          WHEN Coalesce(CC1.DataStart,CC.DataStart) &gt; Coalesce(C1.DataStart,C.DataStart) THEN 1
          WHEN Coalesce(CC1.DataStop, CC.DataStop ) &lt; Coalesce(C1.DataStop ,C.DataStop)  THEN 1
          ELSE 0
        END DifContract1,
        CASE
          WHEN Coalesce(CC.tiptargetv,0) &lt;&gt; 2 AND Coalesce(C.tiptargetv,0) &lt;&gt; 2 THEN 0
          ELSE PKG_Contract.ContractVDiferit(CC1.CodContract1, C1.CodContract1)
        END DifContractV,
        CASE
          WHEN Coalesce(CC1.tipdiscountt,0)  &lt;&gt; Coalesce(C1.tipdiscountt,0)  THEN 1
          WHEN Coalesce(CC1.tipdiscountt1,0) &lt;&gt; Coalesce(C1.tipdiscountt1,0) THEN 1
          WHEN Coalesce(CC1.disctcumulat,0)  &lt;&gt; Coalesce(C1.disctcumulat,0)  THEN 1
          ELSE PKG_Contract.ContractTDiferit(CC1.CodContract1, C1.CodContract1)
        END DifContractT,
        CASE
          WHEN Coalesce(CC1.tipdiscountc,0)  &lt;&gt; Coalesce(C1.tipdiscountc,0)  THEN 1
          ELSE PKG_Contract.ContractCDiferit(CC1.CodContract1, C1.CodContract1)
        END DifContractC,
        cc1.codobiect new_codobiect, cc1.umsec new_umsec, cc1.cant new_cant, cc1.pret new_pret, cc1.procdisc new_procdisc, cc1.addim new_addim,
        cc1.zilel new_zilel, cc1.zilec new_zilec, cc1.valtarget new_valtarget, cc1.limitacadou new_limitacadou, cc1.cantcadou new_cantcadou, cc1.codcadou new_codcadou,
        cc1.codobiectsec new_codobiectsec, cc1.limitacadousec new_limitacadousec, cc1.termenfix new_termenfix, cc1.tippret new_tippret, cc1.tipdiscount new_tipdiscount,
        cc1.tipdiscountt new_tipdiscountt, cc1.tipdiscountc new_tipdiscountc, cc1.sumafixa new_sumafixa, cc1.tipdiscountt1 new_tipdiscountt1, cc1.codclasa new_codclasa,
        cc1.disctcumulat new_disctcumulat, cc1.disct new_disct,
        CASE
          WHEN Coalesce(CC1.DataStart, CC.DataStart) &gt; Coalesce(C1.DataStart, CC1.DataStart, CC.DataStart) THEN Coalesce(CC1.DataStart, CC.DataStart)
          WHEN Coalesce(CC1.DataStart, CC.DataStart) &gt; Coalesce(C.DataStart , CC1.DataStart, CC.DataStart) THEN Coalesce(CC1.DataStart, CC.DataStart)
          ELSE C1.DataStart
        END new_datastart,
        CASE
          WHEN Coalesce(CC1.DataStop, CC.DataStop) &lt; Coalesce(C1.DataStop, CC1.DataStop, CC.DataStop) THEN Coalesce(CC1.DataStop, CC.DataStop)
          WHEN Coalesce(CC1.DataStop, CC.DataStop) &lt; Coalesce(C.DataStop , CC1.DataStop, CC.DataStop) THEN Coalesce(CC1.DataStop, CC.DataStop)
          ELSE C1.DataStart
        END new_datastop
      FROM Contract C
        INNER JOIN Contract1 C1  ON C1.CodContract   = C.CodContract
        INNER JOIN Contract1 CC1 ON CC1.CodContract1 = C1.CodContr1Cadru
        INNER JOIN Contract  CC  ON CC.CodContract   = CC1.CodContract
      WHERE Coalesce(C.Semnat,0) = 0
        AND CC1.CodContract = aCodCadru
        AND Coalesce(CC1.DataStart, CC.DataStart) &lt;= C.DataStop
        AND Coalesce(CC1.DataStop,  CC.DataStop)  &gt;= C.DataStart
      ORDER BY C.CodContract, C1.CodContract1
    ) LOOP
      IF vRec.DifContract1 = 1 OR vRec.DifContractV = 1 OR vRec.DifContractT = 1 OR vRec.DifContractC = 1 THEN
        IF vRec.CodContract &lt;&gt; vLastLocked AND vRec.CodContract &lt;&gt; vLastBlocked THEN
          BEGIN
            SP_LOCKRECORD(vRec.CodContract);
            vLastLocked := vRec.CodContract;
            vCount      := vCount + 1;
          EXCEPTION
            WHEN Others THEN
              vResult      := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
              vLastBlocked :=  vRec.CodContract;
          END;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.DifContract1 = 1 THEN
          UPDATE Contract1
          SET codobiect      = vRec.new_codobiect,
              umsec          = vRec.new_umsec,
              cant           = vRec.new_cant,
              pret           = vRec.new_pret,
              procdisc       = vRec.new_procdisc,
              addim          = vRec.new_addim,
              zilel          = vRec.new_zilel,
              zilec          = vRec.new_zilec,
              valtarget      = vRec.new_valtarget,
              limitacadou    = vRec.new_limitacadou,
              cantcadou      = vRec.new_cantcadou,
              codcadou       = vRec.new_codcadou,
              codobiectsec   = vRec.new_codobiectsec,
              limitacadousec = vRec.new_limitacadousec,
              termenfix      = vRec.new_termenfix,
              tippret        = vRec.new_tippret,
              tipdiscount    = vRec.new_tipdiscount,
              tipdiscountt   = vRec.new_tipdiscountt,
              tipdiscountc   = vRec.new_tipdiscountc,
              sumafixa       = vRec.new_sumafixa,
              tipdiscountt1  = vRec.new_tipdiscountt1,
              codclasa       = vRec.new_codclasa,
              disctcumulat   = vRec.new_disctcumulat,
              disct          = vRec.new_disct,
              datastart      = vRec.new_datastart,
              datastop       = vRec.new_datastop
          WHERE CodContract1 = vRec.CodContract1;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.DifContractV = 1 THEN
          vCodIdx     := 0;
          vCodLastIdx := 0;
          bFound      := TRUE;
          FOR vRecV IN (
            SELECT suma, discount, valdiscount
            FROM ContractV
            WHERE CodContract1 = vRec.CodContr1Cadru
            ORDER BY SUMA
          ) LOOP

            IF bFound THEN
              SELECT Coalesce(Min(CodContractV),0) INTO vCodIdx
              FROM ContractV
              WHERE CodContract1 = vRec.CodContract1
                AND CodContractV &gt; vCodLastIdx;
            END IF;

            IF vCodIdx &gt; 0 THEN
              vCodLastIdx := vCodIdx;
              UPDATE ContractV
              SET   Suma        = vRecV.Suma,
                    Discount    = vRecV.Discount,
                    ValDiscount = vRecV.ValDiscount
              WHERE CodContractV = vCodIdx;
            ELSE
              bFound := FALSE;
              SELECT seq_ContractV_CodContractV.nextval INTO vCodLastIdx from dual;
              INSERT INTO  ContractV (CodContractV, CodContract, Suma, Discount, ValDiscount, CodContract1)
              VALUES (vCodLastIdx, vrec.CodContract, vRecV.Suma, vRecV.Discount, vRecV.ValDiscount, vRec.CodContract1);
            END IF;
          END LOOP;
          DELETE FROM ContractV WHERE CodContract1 = vRec.CodContract1 AND CodContractV &gt; vCodLastIdx;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.DifContractT = 1 THEN
          vCodIdx     := 0;
          vCodLastIdx := 0;
          bFound      := TRUE;
          FOR vRecT IN (
            SELECT zile, discount, valdiscount, termenfix, procvaldoc
            FROM ContractT
            WHERE CodContract1 = vRec.CodContr1Cadru
            ORDER BY Zile, TermenFix
          ) LOOP

            IF bFound THEN
              SELECT Coalesce(Min(CodContractT),0) INTO vCodIdx
              FROM ContractT
              WHERE CodContract1 = vRec.CodContract1
                AND CodContractT &gt; vCodLastIdx;
            END IF;

            IF vCodIdx &gt; 0 THEN
              vCodLastIdx := vCodIdx;
              UPDATE ContractT
              SET   Zile        = vRecT.Zile,
                    Discount    = vRecT.Discount,
                    ValDiscount = vRecT.ValDiscount,
                    TermenFix   = vRecT.TermenFix,
                    ProcValDoc  = vRecT.ProcValDoc
              WHERE CodContractT = vCodIdx;
            ELSE
              bFound := FALSE;
              SELECT seq_ContractT_CodContractT.nextval INTO vCodLastIdx from dual;
              INSERT INTO  ContractT (CodContractT, CodContract1, Zile, Discount, ValDiscount, TermenFix, ProcValDoc)
              VALUES (vCodLastIdx, vRec.CodContract1, vRecT.Zile, vRecT.Discount, vRecT.ValDiscount, vRecT.TermenFix, vRecT.ProcValDoc);
            END IF;
          END LOOP;
          DELETE FROM ContractT WHERE CodContract1 = vRec.CodContract1 AND CodContractT &gt; vCodLastIdx;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.DifContractC = 1 THEN
          vCodIdx     := 0;
          vCodLastIdx := 0;
          bFound      := TRUE;
          FOR vRecC IN (
            SELECT cantmin, discount, valdiscount
            FROM ContractC
            WHERE CodContract1 = vRec.CodContr1Cadru
            ORDER BY CantMin
          ) LOOP

            IF bFound THEN
              SELECT Coalesce(Min(CodContractC),0) INTO vCodIdx
              FROM ContractC
              WHERE CodContract1 = vRec.CodContract1
                AND CodContractC &gt; vCodLastIdx;
            END IF;

            IF vCodIdx &gt; 0 THEN
              vCodLastIdx := vCodIdx;
              UPDATE ContractC
              SET   CantMin     = vRecC.CantMin,
                    Discount    = vRecC.Discount,
                    ValDiscount = vRecC.ValDiscount
              WHERE CodContractC = vCodIdx;
            ELSE
              bFound := FALSE;
              SELECT seq_ContractC_CodContractC.nextval INTO vCodLastIdx from dual;
              INSERT INTO  ContractC (CodContractC, CodContract1, CantMin, Discount, ValDiscount)
              VALUES (vCodLastIdx, vrec.CodContract1, vRecC.CantMin, vRecC.Discount, vRecC.ValDiscount);
            END IF;
          END LOOP;
          DELETE FROM ContractC WHERE CodContract1 = vRec.CodContract1 AND CodContractc &gt; vCodLastIdx;
        END IF;

      END IF;
    END LOOP;

    IF vResult IS NOT NULL THEN
      vResult := &apos;Contracte ce nu au putut fi modificate : &apos;||SubStr(vResult,2);
    END IF;
    IF vCount = 1 THEN
      vResult := &apos;A fost modificat un contract. &apos;||vResult;
    ELSE
      vResult := &apos;Au fost modificate &apos;||vCount||&apos; contracte. &apos;||vResult;
    END IF;
    COMMIT;
    RETURN vResult;
  END IF;
END;

FUNCTION ADD_LINIEDINCADRU (aCodCadru1 IN NUMBER) RETURN VARCHAR2 IS
  vEroare      NUMBER     := 0;
  vLastLocked  NUMBER(20) := 0;
  vLastBlocked NUMBER(20) := 0;
  vResult      VARCHAR2(4000);
  vD           DATE       := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);
  RES_BUSY     EXCEPTION;
  PRAGMA       EXCEPTION_INIT(RES_BUSY, -54);
  vCount       NUMBER     := 0;
  vCodIdx      NUMBER     := 0;
  vCodLastIdx  NUMBER     := 0;
  bFound       BOOLEAN;

  vCodCadru    NUMBER;
  vDataStart   DATE;
  vDataStop    DATE;
  vCod         NUMBER;
BEGIN
  BEGIN
    SELECT C.CodContract, Coalesce(C1.DataStart, C.DataStart) DataStart, Coalesce(C1.DataStop, C.DataStop) DataStop
    INTO vCodCadru, vDataStart, vDataStop
    FROM Contract1 C1 INNER JOIN Contract C ON C.CodContract = C1.CodContract
    WHERE CodContract1 = aCodCadru1;

    SP_LOCKRECORD(vCodCadru);
  EXCEPTION
    WHEN RES_BUSY      THEN
      vEroare := 1;
      vResult := &apos;Contractul cadru este blocat pentru modificare&apos;;
    WHEN NO_DATA_FOUND THEN
      vEroare := 2;
      vResult := &apos;Linia din contractul cadru a fost stearsa&apos;;
    WHEN OTHERS        THEN
      vEroare := SQLCODE;
      vResult := SQLERRM;
  END;

  IF vEroare = 0 THEN
    FOR vRec IN (
      SELECT
        C.CodContract, C.NrDoc, C.DataDoc, C.DataStart, C.DataStop,
        Sum(Decode(CC1.CodContract1,aCodCadru1,1,0)) ExistLin,
        (SELECT Max(X.IndexLocal) FROM Contract1 X WHERE x.CodContract = C.CodContract)+1 Indexlocal
      FROM Contract1 CC1
        INNER JOIN Contract1 C1 ON C1.CodContr1Cadru = CC1.CodContract1
        INNER JOIN Contract C ON C.CodContract = C1.CodContract
      WHERE Coalesce(C.Semnat,0) = 0
        AND CC1.CodContract = vCodCadru
        AND C.DataStart &lt;= vDataStop
        AND C.DataStop  &gt;= vDataStart
      GROUP BY C.CodContract, C.NrDoc, C.DataDoc, C.DataStart, C.DataStop
      ORDER BY C.CodContract
    ) LOOP
      IF vRec.ExistLin = 0 THEN
        BEGIN
          SP_LOCKRECORD(vRec.CodContract);
          vCount := vCount + 1;

          SELECT seq_Contract1_CodContract1.NEXTVAL INTO vCod FROM dual;

          INSERT INTO  Contract1 (
            CodContract1, CodContract, DataStart, DataStop, Indexlocal,
            CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
            Anexa, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
            LIMITACADOU,
            CANTCADOU  ,
            CODCADOU,CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount, SEDIULIVRARE,
            TipDiscountT, TipDiscountC, SumaFixa, TipDiscountT1, CodClasa,
            DiscTCumulat, DiscT, CodContr1Cadru, CodCentru)
          SELECT
            vCod, vRec.CodContract, Greatest(vrec.DataStart, vDataStart), Least(vrec.DataStop, vDataStop), vrec.Indexlocal,
            CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
            Anexa, Obs, GestAct, CodIOArt, CODOFERTA1, TVA, VALTARGET,
            LIMITACADOU,
            CANTCADOU  ,
            CODCADOU,CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipDiscount, SEDIULIVRARE,
            TipDiscountT, TipDiscountC, SumaFixa, TipDiscountT1, CodClasa,
            DiscTCumulat, DiscT, aCodCadru1, CodCentru
          FROM Contract1
          WHERE CodContract1 = aCodCadru1;

          INSERT INTO ContractV(CodContractV, CodContract, CodContract1, Suma, Discount, ValDiscount)
          SELECT Seq_ContractV_CodContractV.nextval, vrec.CodContract, vCod, Suma, Discount, ValDiscount
          FROM ContractV
          WHERE CodContract1 = aCodCadru1;

          INSERT INTO ContractT(CodContractT, CodContract1, Zile, Discount, ValDiscount, TermenFix, ProcValDoc)
          SELECT Seq_ContractT_CodContractT.nextval, vCod, Zile, Discount, ValDiscount, TermenFix, ProcValDoc
          FROM ContractT
          WHERE CodContract1 = aCodCadru1;

          INSERT INTO ContractC(CodContractC, CodContract1, CantMin, Discount, ValDiscount)
          SELECT Seq_ContractC_CodContractC.nextval, vCod, CantMin, Discount, ValDiscount
          FROM ContractC
          WHERE CodContract1 = aCodCadru1;
        EXCEPTION
          WHEN Others THEN vResult := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
        END;

      END IF;
    END LOOP;

    IF vResult IS NOT NULL THEN
      vResult := &apos;Contracte ce nu au putut fi modificate : &apos;||SubStr(vResult,2);
    END IF;
    IF vCount = 1 THEN
      vResult := &apos;A fost modificat un contract. &apos;||vResult;
    ELSE
      vResult := &apos;Au fost modificate &apos;||vCount||&apos; contracte. &apos;||vResult;
    END IF;
    COMMIT;
    RETURN vResult;
  END IF;
END;

FUNCTION DEL_LINIEDINCADRU (aCodCadru1 IN NUMBER) RETURN VARCHAR2 IS
  vEroare      NUMBER     := 0;
  vLastLocked  NUMBER(20) := 0;
  vLastBlocked NUMBER(20) := 0;
  vResult      VARCHAR2(4000);
  vD           DATE       := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);
  RES_BUSY     EXCEPTION;
  PRAGMA       EXCEPTION_INIT(RES_BUSY, -54);
  vCount       NUMBER     := 0;
  vCodIdx      NUMBER     := 0;
  vCodLastIdx  NUMBER     := 0;
  bFound       BOOLEAN;

  vCodCadru    NUMBER;
  vDataStart   DATE;
  vDataStop    DATE;
  vCod         NUMBER;
BEGIN
  BEGIN
    SELECT C.CodContract, Coalesce(C1.DataStart, C.DataStart) DataStart, Coalesce(C1.DataStop, C.DataStop) DataStop
    INTO vCodCadru, vDataStart, vDataStop
    FROM Contract1 C1 INNER JOIN Contract C ON C.CodContract = C1.CodContract
    WHERE CodContract1 = aCodCadru1;

    SP_LOCKRECORD(vCodCadru);
  EXCEPTION
    WHEN RES_BUSY      THEN
      vEroare := 1;
      vResult := &apos;Contractul cadru este blocat pentru modificare&apos;;
    WHEN NO_DATA_FOUND THEN
      vEroare := 2;
      vResult := &apos;Linia din contractul cadru a fost stearsa&apos;;
    WHEN OTHERS        THEN
      vEroare := SQLCODE;
      vResult := SQLERRM;
  END;

  IF vEroare = 0 THEN
    FOR vRec IN (
      SELECT DISTINCT C.CodContract, C.NrDoc, C.DataDoc, C.DataStart, C.DataStop
      FROM Contract1 C1
        INNER JOIN Contract C ON C.CodContract = C1.CodContract
      WHERE Coalesce(C.Semnat,0) = 0
        AND C1.CodContr1Cadru = aCodCadru1
      ORDER BY C.CodContract
    ) LOOP
      BEGIN
        SP_LOCKRECORD(vRec.CodContract);
        vCount := vCount + 1;
        DELETE FROM ContractXX WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = vRec.CodContract AND CodContr1Cadru = aCodCadru1);
        DELETE FROM ContractC  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = vRec.CodContract AND CodContr1Cadru = aCodCadru1);
        DELETE FROM ContractT  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = vRec.CodContract AND CodContr1Cadru = aCodCadru1);
        DELETE FROM ContractV  WHERE CodContract1 IN (SELECT CodContract1 FROM CONTRACT1 WHERE CodContract = vRec.CodContract AND CodContr1Cadru = aCodCadru1);
        DELETE FROM Contract1  WHERE CodContract = vRec.CodContract AND CodContr1Cadru = aCodCadru1;
      EXCEPTION
        WHEN Others THEN vResult := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
      END;
    END LOOP;

    IF vResult IS NOT NULL THEN
      vResult := &apos;Contracte ce nu au putut fi modificate : &apos;||SubStr(vResult,2);
    END IF;
    IF vCount = 1 THEN
      vResult := &apos;A fost modificat un contract. &apos;||vResult;
    ELSE
      vResult := &apos;Au fost modificate &apos;||vCount||&apos; contracte. &apos;||vResult;
    END IF;
    COMMIT;
    RETURN vResult;
  END IF;
END;

PROCEDURE TMP_PROPAGACONDDISC (aCodContract1 IN NUMBER) IS
  vIndexLocal NUMBER := 0;
  vCount      NUMBER := 0;
  vCod        NUMBER := 0;
  vLast       NUMBER := 0;
  vIdx        NUMBER := 0;
  vCountV     NUMBER := 0;
  vCountT     NUMBER := 0;
  vCountC     NUMBER := 0;
BEGIN
  SELECT IndexLocal
  INTO vIndexLocal
  FROM TMP_Contract1
  WHERE CodContract1 = aCodContract1;

  UPDATE TMP_Contract1
  SET ( ValTarget, CantCadou, CodCadou, DenCadou, LimitaCadou, CodObiectSec, DenObiectSec, LimitaCadouSec, TipDiscount, TipDiscountT, TipDiscountC, TipDiscountT1, DiscTCumulat, DiscT) =
      (SELECT
        ValTarget, CantCadou, CodCadou, DenCadou, LimitaCadou, CodObiectSec, DenObiectSec, LimitaCadouSec, TipDiscount, TipDiscountT, TipDiscountC, TipDiscountT1, DiscTCumulat, DiscT
      FROM TMP_Contract1 WHERE CodContract1 = aCodContract1 )
  WHERE CodContract1 &lt;&gt; aCodContract1;

  UPDATE TMP_ContractL
  SET ( ProcDisc, ZileL, ZileC, TermenFix, TipPret, SumaFixa) = (SELECT ProcDisc, ZileL, ZileC, TermenFix, TipPret, SumaFixa FROM TMP_ContractL WHERE IndexLocal = vIndexLocal )
  WHERE IndexLocal &lt;&gt; vIndexLocal;

  vIdx := 0;
  FOR vRec IN ( SELECT ROWID FROM Tmp_ContractV WHERE CodContract1 = aCodContract1 /*AND vTipTargetV = 2*/ ORDER BY SUMA )
  LOOP
    vIdx := vIdx + 1;
    UPDATE Tmp_ContractV SET IndexLocal = vIdx WHERE ROWID = vRec.ROWID;
  END LOOP;
  vCountV := vIdx;

  vIdx := 0;
  FOR vRec IN ( SELECT ROWID FROM Tmp_ContractT  WHERE CodContract1 = aCodContract1 ORDER BY Zile, TermenFix )
  LOOP
    vIdx := vIdx + 1;
    UPDATE Tmp_ContractT SET IndexLocal = vIdx WHERE ROWID = vRec.ROWID;
  END LOOP;
  vCountT := vIdx;

  vIdx := 0;
  FOR vRec IN ( SELECT ROWID FROM Tmp_ContractC  WHERE CodContract1 = aCodContract1 ORDER BY CantMin )
  LOOP
    vIdx := vIdx + 1;
    UPDATE Tmp_ContractC SET IndexLocal = vIdx WHERE ROWID = vRec.ROWID;
  END LOOP;
  vCountC := vIdx;

  FOR vRec IN (
    SELECT CodContract, CodContract1
    FROM TMP_Contract1
    WHERE CodContract1 &lt;&gt; aCodContract1
    ORDER BY IndexLocal
  ) LOOP

    vIdx   := 0;
    DELETE FROM Tmp_ContractV WHERE CodContract1 = vRec.CodContract1 AND Coalesce(CodContractV,0) &lt;= 0;
    DELETE FROM Tmp_ContractV WHERE CodContract1 = vRec.CodContract1 AND ROWNUM &gt; vCountV;

    FOR vRecV IN ( SELECT ROWID FROM TMP_ContractV WHERE CodContract1 = vRec.CodContract1) LOOP
      vIdx := vIdx + 1;
      UPDATE TMP_ContractV
      SET (suma, discount, valdiscount, indexlocal) = (SELECT suma, discount, valdiscount, indexlocal FROM TMP_ContractV WHERE CodContract1 = aCodContract1 AND IndexLocal = vIdx)
      WHERE ROWID = vRecV.ROWID;
    END LOOP;

    IF vCountV &gt; vIdx THEN
      INSERT INTO TMP_ContractV (
        codcontractv, codcontract, suma, discount, valdiscount, codcontract1, indexlocal)
      SELECT
        0, vrec.codcontract, suma, discount, valdiscount, vrec.codcontract1, indexlocal
      FROM TMP_ContractV
      WHERE CodContract1 = aCodContract1 AND IndexLocal &gt; vIdx;
    END IF;

    vIdx   := 0;
    DELETE FROM Tmp_ContractT WHERE CodContract1 = vRec.CodContract1 AND Coalesce(CodContractT,0) &lt;= 0;
    DELETE FROM Tmp_ContractT WHERE CodContract1 = vRec.CodContract1 AND ROWNUM &gt; vCountT;

    FOR vRecT IN ( SELECT ROWID FROM TMP_ContractT WHERE CodContract1 = vRec.CodContract1) LOOP
      vIdx := vIdx + 1;
      UPDATE TMP_ContractT
      SET (zile, discount, valdiscount, termenfix, procvaldoc, indexlocal, cumulat) = (SELECT zile, discount, valdiscount, termenfix, procvaldoc, indexlocal, cumulat FROM TMP_ContractT WHERE CodContract1 = aCodContract1 AND IndexLocal = vIdx)
      WHERE ROWID = vRecT.ROWID;
    END LOOP;

    IF vCountT &gt; vIdx THEN
      INSERT INTO TMP_ContractT ( codcontractt, codcontract1, zile, discount, valdiscount, termenfix, procvaldoc, indexlocal, cumulat)
      SELECT 0, vrec.codcontract1, zile, discount, valdiscount, termenfix, procvaldoc, indexlocal, cumulat
      FROM TMP_ContractT
      WHERE CodContract1 = aCodContract1 AND IndexLocal &gt; vIdx;
    END IF;

    vIdx   := 0;
    DELETE FROM Tmp_ContractC WHERE CodContract1 = vRec.CodContract1 AND Coalesce(CodContractC,0) &lt;= 0;
    DELETE FROM Tmp_ContractC WHERE CodContract1 = vRec.CodContract1 AND ROWNUM &gt; vCountC;

    FOR vRecC IN ( SELECT ROWID FROM TMP_ContractC WHERE CodContract1 = vRec.CodContract1) LOOP
      vIdx := vIdx + 1;
      UPDATE TMP_ContractC
      SET (cantmin, discount, valdiscount, indexlocal) = (SELECT cantmin, discount, valdiscount, indexlocal FROM TMP_ContractC WHERE CodContract1 = aCodContract1 AND IndexLocal = vIdx)
      WHERE ROWID = vRecC.ROWID;
    END LOOP;

    IF vCountC &gt; vIdx THEN
      INSERT INTO TMP_ContractC ( codcontractc, codcontract1, cantmin, discount, valdiscount, indexlocal)
      SELECT 0, vrec.codcontract1, cantmin, discount, valdiscount, indexlocal
      FROM TMP_ContractC
      WHERE CodContract1 = aCodContract1 AND IndexLocal &gt; vIdx;
    END IF;
  END LOOP;
END;

PROCEDURE CoeficientZILE(
  pPrimaZi IN DATE, pUltimaZi IN DATE,
  pC1DataStart IN DATE, pC1DataStop IN DATE,
  pTipPret IN PLS_INTEGER,
  vCoef IN OUT NUMBER, vNrZile IN OUT PLS_INTEGER
) IS
  dDate1    DATE;
  dDate2    DATE;
  dLastDay  DATE;
  vNrZileF  NUMBER;
  vNrZileL  NUMBER;
BEGIN
  vCoef   := 0;
  vNrZile := 0;

  IF Coalesce(pC1DataStart,pPrimaZi) &gt; pPrimaZi
  THEN dDate1 := pC1DataStart;
  ELSE dDate1 := pPrimaZi;
  END IF;

  IF Coalesce(pC1DataStop,pUltimaZi) &lt; pUltimaZi
  THEN dDate2 := pC1DataStop;
  ELSE dDate2 := pUltimaZi;
  END IF;

  IF dDate2 &gt;= dDate1 THEN
    vNrZile := 1 + Round(dDate2 - dDate1);
    IF pTipPret IN (1, 3) THEN
      --1 -&gt; lunar      = relativ la nr.de zile facturabile din luna
      --3 -&gt; Cantitativ = cantitate lunara limitata
      WHILE dDate1 &lt;= dDate2 LOOP
        dLastDay := Last_Day(dDate1);
        IF pTipPret = 5 THEN
          vCoef := vCoef + 1;
        ELSE
          vNrZileL := EXTRACT (DAY FROM dLastDay);
          IF dDate2 &lt; dLastDay
          THEN vNrZileF := Round(dDate2   - dDate1) + 1;
          ELSE vNrZileF := Round(dLastDay - dDate1) + 1;
          END IF;
          vCoef := vCoef + vNrZileF/vNrZileL;
        END IF;
        dDate1 := dLastDay + 1;
      END loop;
    ELSIF pTipPret = 2 THEN --2 -&gt; zilnic = in functie de nr.de zile perioada facturata
      vCoef := 1 + Round(dDate2 - dDate1);
    ELSIF pTipPret = 4 THEN --4 -&gt; Pachet = cantitate per contract limitata
      vCoef := 1;
    ELSIF pTipPret = 5 THEN --5 -&gt; lunar fix = indiferent de nr.de zile facturabile din luna
      vCoef := Months_Between(Last_Day(dDate2)+1, Trunc(dDate1,&apos;mm&apos;));
    END IF;
  END if;
END;

FUNCTION ACTPRETABON  (aSubunit IN NUMBER, aMONEDA IN NUMBER, aTipC IN NUMBER, aAllPart IN NUMBER, aTipPer IN NUMBER, aDataRef IN VARCHAR2 ) RETURN VARCHAR2 IS
  vEroare      NUMBER     := 0;
  vLastLocked  NUMBER(20) := 0;
  vLastBlocked NUMBER(20) := 0;
  vLastCodC1   NUMBER(20) := 0;
  vRefCodC1    NUMBER(20) := 0;
  vSediuLivr   NUMBER(20) := 0;
  vDeFacturat  NUMBER(20) := 0;
  vResult      VARCHAR2(4000);
  RES_BUSY     EXCEPTION;
  PRAGMA       EXCEPTION_INIT(RES_BUSY, -54);
  vCount       NUMBER     := 0;
  vDif         NUMBER     := 0;
  vCoefZile    NUMBER     := 0;
  vNrZile      NUMBER     := 0;
  vDataRef     DATE       := To_Date(aDataRef,&apos;dd.mm.yyyy&apos;);
  dUltimaZi    DATE;
  dPrimaZi     DATE;
  vAn          NUMBER(4);
  vLuna        NUMBER(2);
BEGIN
  IF vEroare = 0 THEN
    IF    aTipC = 4 THEN
      vcount := 0;
      FOR vRec IN (
        SELECT C.CodContract, C.NrDoc,C.DataDOc
        FROM Contract C
        WHERE C.TipDoc = 34
          AND C.Moneda = aMoneda
          AND (aAllPArt = 1 OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T
                                      WHERE T.FILTRU = &apos;CODPART&apos; AND T.FILTRU1 = &apos;CODAGENDA&apos; AND TO_NUMBER(T.VALOARE) = C.PARTENER AND TO_NUMBER(T.VALOARE1) = C.CODLOCATIE
                                      )
              )
          AND aSubunit = Decode(aSubunit,1,1,C.Subunitatea)
          AND C.DataStop &gt;= vDataRef
          AND C.DataStart &gt;= CASE WHEN aTipPer = 2 THEN vDataRef ELSE C.DataStart END -- Contracte viitoare
          AND C.DataStart &lt;= CASE WHEN aTipPer = 1 THEN vDataRef ELSE C.DataStart END -- Contracte active
        ORDER BY C.CodContract )
      LOOP
        SELECT Max(CodContract1)        INTO vRefCodC1  FROM Contract1 WHERE CodContract  = vRec.CodContract;
        SELECT Coalesce(SediuLivrare,0) INTO vSediuLivr FROM Contract1 WHERE CodContract1 = vRefCodC1;

        SELECT
          Sum(CASE
                WHEN (Coalesce(c2.TipDoc,0) =  1 AND Coalesce(c2.CodDoc,0) &gt;  0 AND I.Codintr     IS NOT NULL) THEN 0
                WHEN (Coalesce(c2.TipDoc,0) = 19 AND Coalesce(c2.CodDoc,0) &gt;  0 AND E.CodIEs      IS NOT NULL) THEN 0
                WHEN (Coalesce(c2.TipDoc,0) = 58 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 0
                WHEN (Coalesce(c2.TipDoc,0) = 59 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 0
                WHEN (Coalesce(c2.TipDoc,0) =  0 AND Coalesce(c2.CodDoc,0) =  0 AND Coalesce(C2.NRDoc,0) &gt; 0)  THEN 0
                ELSE 1
              END) DeFacturat
        INTO vDeFacturat
        FROM Contract2 C2
          LEFT JOIN Iesiri  E ON E.CodIes  = C2.CodDoc AND E.TipDoc = C2.TipDoc
          LEFT JOIN Intrari I ON I.CodIntr = C2.CodDoc AND I.TipDoc = C2.TipDoc
          LEFT JOIN NoteCredit NC ON NC.CodNCredit = C2.CodDoc AND NC.TipDoc = C2.TipDoc
        WHERE C2.CodContract = vRec.CodContract AND Coalesce(C2.SediuLivrare,0) = vSediuLivr;

        IF vRec.CodContract &lt;&gt; vLastLocked AND vRec.CodContract &lt;&gt; vLastBlocked AND vDeFacturat &gt; 0 THEN
          BEGIN
            SP_LOCKRECORD(vRec.CodContract);
            vLastLocked := vRec.CodContract;
            vCount      := vCount + 1;
          EXCEPTION
            WHEN Others THEN
              vResult      := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
              vLastBlocked :=  vRec.CodContract;
          END;
        END IF;

        IF vRec.CodContract = vLastLocked THEN
          INSERT INTO Contract1(
            CodContract1, CodContract, SediuLivrare,
            CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, DataStart, DataStop, TipPret
          )
          SELECT
            seq_Contract1_CodContract1.NEXTVAL, C1.CodContract, vSediuLivr,
            TA.CodObiect, TA.UMSecN, TA.Cant, TA.Pret, TA.ProcDisc, TA.AdDim, TA.DataStart, Ta.DataStop, Ta.TipPret
          FROM Contract1 C1 CROSS JOIN TMP_ACTABON_ART TA
          WHERE C1.CodContract1 = vRefCodC1;

          FOR vRec2 IN (
            SELECT
              C.CodContract, C1.CodContract1, C2.CodContract2,
              C.NrDoc, C.DataDoc, C.PerFact, C.Avans,
              C.DataStart, C.DataStop, C2.Data C2Data, C2.DataStop C2DataStop,
              C1.DataStart C1DataStart, C1.DataStop C1DataStop, C1.TipPret C1TipPret,
              C1.Cant * (1+Coalesce(C1.PROCDISC,0)/100) * (1+Coalesce(C1.ADDIM,0)/100) * C1.Pret Valoare
            FROM Contract C
              INNER JOIN Contract1 C1 ON C1.CodContract = C.CodContract
              INNER JOIN TMP_ACTABON_ART TA ON TA.CodObiect = C1.CodObiect
              LEFT JOIN Contract2 C2 ON C2.CodContract = C.CodContract AND Coalesce(C2.SediuLivrare,0) = Coalesce(C1.SediuLivrare,0)
              LEFT JOIN Iesiri  E ON E.CodIes  = C2.CodDoc AND E.TipDoc = C2.TipDoc
              LEFT JOIN Intrari I ON I.CodIntr = C2.CodDoc AND I.TipDoc = C2.TipDoc
              LEFT JOIN NoteCredit NC ON NC.CodNCredit = C2.CodDoc AND NC.TipDoc = C2.TipDoc
            WHERE C.CodContract   = vRec.CodContract
              AND C1.CodContract1 &gt; vRefCodC1
              AND CASE
                    WHEN (Coalesce(c2.TipDoc,0) =  1 AND Coalesce(c2.CodDoc,0) &gt;  0 AND I.Codintr     IS NOT NULL) THEN 1
                    WHEN (Coalesce(c2.TipDoc,0) = 19 AND Coalesce(c2.CodDoc,0) &gt;  0 AND E.CodIEs      IS NOT NULL) THEN 1
                    WHEN (Coalesce(c2.TipDoc,0) = 58 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
                    WHEN (Coalesce(c2.TipDoc,0) = 59 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
                    WHEN (Coalesce(c2.TipDoc,0) =  0 AND Coalesce(c2.CodDoc,0) =  0 AND Coalesce(C2.NRDoc,0) &gt; 0)  THEN 1
                    ELSE 0
                  END = 0
          ) LOOP
            IF vRec2.C2DataStop IS NULL
            THEN dUltimaZi := Last_Day(vRec2.C2Data);
            ELSE dUltimaZi := vRec2.C2DataStop;
            END IF;

            dUltimaZi := Least(dUltimaZi, vRec2.DataStop);

            IF Coalesce(vRec2.Avans,0) = 0 THEN
              vAn   := EXTRACT(YEAR  FROM vRec2.C2Data);
              vLuna := EXTRACT(MONTH FROM vRec2.C2Data);
            ELSE
              vAn   := EXTRACT(YEAR  FROM dUltimaZi);
              vLuna := EXTRACT(MONTH FROM dUltimaZi);
            END IF;

            IF vRec2.PerFact &gt; 1 THEN
              IF vLuna &lt; vRec2.PerFact THEN
                vAn   := vAn - 1;
                vLuna := vLuna + 12;
              END IF;
              vLuna := vLuna + 1 - vRec2.PerFact;
            END IF;

            BEGIN
              dPrimaZi := Trunc(To_Date(To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;yyyymm&apos;), &apos;mm&apos;);
              dPrimaZi := Greatest(dPrimaZi, vRec2.DataStart);

              CoeficientZILE(dPrimaZi, dUltimaZi, vRec2.C1DataStart, vRec2.C1DataStop, vRec2.C1TipPret, vCoefZile, vNrZile);

              UPDATE Contract2 SET Suma = Suma + vRec2.Valoare * vCoefZile WHERE CodContract2 = vRec2.CodContract2;
            EXCEPTION
              WHEN others THEN null;
            END;
          END LOOP;
        END IF;
      END LOOP;
    ELSIF aTipC = 3 THEN
      vcount := 0;
      FOR vRec IN (
        SELECT
          C.CodContract, C1.CodContract1, C2.CodContract2, C.NrDoc, C.DataDoc, C.PerFact, C.Avans,
          C.DataStart, C.DataStop, C2.Data C2Data, C2.DataStop C2DataStop,
          C1.DataStart C1DataStart, C1.DataStop C1DataStop, C1.TipPret C1TipPret,
          C1.Cant * (1+Coalesce(C1.PROCDISC,0)/100) * (1+Coalesce(C1.ADDIM,0)/100) CoefValoare,
          C1.Pret, TA.CODOBIECTN, TA.UMSECN,
          CASE WHEN aTipC = 0 THEN TA.PRET ELSE C1.Pret*TA.COEF END PretNou,
          CASE
            WHEN (Coalesce(c2.TipDoc,0) =  1 AND Coalesce(c2.CodDoc,0) &gt;  0 AND I.Codintr     IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 19 AND Coalesce(c2.CodDoc,0) &gt;  0 AND E.CodIEs      IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 58 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 59 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) =  0 AND Coalesce(c2.CodDoc,0) =  0 AND Coalesce(C2.NRDoc,0) &gt; 0)  THEN 1
            ELSE 0
          END Facturat
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract = C.CodContract
          INNER JOIN TMP_ACTABON_ART TA ON TA.CodObiect = C1.CodObiect
          LEFT JOIN Contract2 C2 ON C2.CodContract = C.CodContract AND Coalesce(C2.SediuLivrare,0) = Coalesce(C1.SediuLivrare,0)
          LEFT JOIN Iesiri  E ON E.CodIes  = C2.CodDoc AND E.TipDoc = C2.TipDoc
          LEFT JOIN Intrari I ON I.CodIntr = C2.CodDoc AND I.TipDoc = C2.TipDoc
          LEFT JOIN NoteCredit NC ON NC.CodNCredit = C2.CodDoc AND NC.TipDoc = C2.TipDoc
        WHERE C.TipDoc = 34
          AND C.Moneda = aMoneda
          AND (aAllPArt = 1 OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T
                                      WHERE T.FILTRU = &apos;CODPART&apos; AND T.FILTRU1 = &apos;CODAGENDA&apos; AND TO_NUMBER(T.VALOARE) = C.PARTENER AND TO_NUMBER(T.VALOARE1) = C.CODLOCATIE
                                      )
              )
          AND aSubunit = Decode(aSubunit,1,1,C.Subunitatea)
          AND C.DataStop &gt;= vDataRef
          AND C.DataStart &gt;= CASE WHEN aTipPer = 2 THEN vDataRef ELSE C.DataStart END -- Contracte viitoare
          AND C.DataStart &lt;= CASE WHEN aTipPer = 1 THEN vDataRef ELSE C.DataStart END -- Contracte active
        ORDER BY C.CodContract, C1.CodContract1 )
      LOOP
        IF vRec.CodContract &lt;&gt; vLastLocked AND vRec.CodContract &lt;&gt; vLastBlocked AND vRec.Facturat = 0 THEN
          BEGIN
            SP_LOCKRECORD(vRec.CodContract);
            vLastLocked := vRec.CodContract;
            vCount      := vCount + 1;
          EXCEPTION
            WHEN Others THEN
              vResult      := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
              vLastBlocked :=  vRec.CodContract;
          END;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.CodContract1 &lt;&gt; vLastCodC1 AND vRec.Facturat = 0 THEN
          UPDATE Contract1 SET codobiect = vRec.CodObiectN, UMSEC = vRec.UMSECN WHERE CodContract1 = vrec.CodContract1;
          vLastCodC1 := vrec.CodContract1;
        END IF;
      END LOOP;
    ELSE
      FOR vRec IN (
        SELECT
          C.CodContract, C1.CodContract1, C2.CodContract2, C.NrDoc, C.DataDoc, C.PerFact, C.Avans,
          C.DataStart, C.DataStop, C2.Data C2Data, C2.DataStop C2DataStop,
          C1.DataStart C1DataStart, C1.DataStop C1DataStop, C1.TipPret C1TipPret,
          C1.Cant * (1+Coalesce(C1.PROCDISC,0)/100) * (1+Coalesce(C1.ADDIM,0)/100) CoefValoare,
          C1.Pret,
          CASE WHEN aTipC = 0 THEN TA.PRET ELSE C1.Pret*TA.COEF END PretNou,
          CASE
            WHEN (Coalesce(c2.TipDoc,0) =  1 AND Coalesce(c2.CodDoc,0) &gt;  0 AND I.Codintr     IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 19 AND Coalesce(c2.CodDoc,0) &gt;  0 AND E.CodIEs      IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 58 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) = 59 AND Coalesce(c2.CodDoc,0) &gt;  0 AND NC.CodNCredit IS NOT NULL) THEN 1
            WHEN (Coalesce(c2.TipDoc,0) =  0 AND Coalesce(c2.CodDoc,0) =  0 AND Coalesce(C2.NRDoc,0) &gt; 0)  THEN 1
            ELSE 0
          END Facturat
        FROM Contract C
          INNER JOIN Contract1 C1 ON C1.CodContract = C.CodContract
          INNER JOIN TMP_ACTABON_ART TA ON TA.CodObiect = C1.CodObiect
          LEFT JOIN Contract2 C2 ON C2.CodContract = C.CodContract AND Coalesce(C2.SediuLivrare,0) = Coalesce(C1.SediuLivrare,0)
          LEFT JOIN Iesiri  E ON E.CodIes  = C2.CodDoc AND E.TipDoc = C2.TipDoc
          LEFT JOIN Intrari I ON I.CodIntr = C2.CodDoc AND I.TipDoc = C2.TipDoc
          LEFT JOIN NoteCredit NC ON NC.CodNCredit = C2.CodDoc AND NC.TipDoc = C2.TipDoc
        WHERE C.TipDoc = 34
          AND C.Moneda = aMoneda
          AND (aAllPArt = 1 OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T
                                      WHERE T.FILTRU = &apos;CODPART&apos; AND T.FILTRU1 = &apos;CODAGENDA&apos; AND TO_NUMBER(T.VALOARE) = C.PARTENER AND TO_NUMBER(T.VALOARE1) = C.CODLOCATIE
                                      )
              )
          AND aSubunit = Decode(aSubunit,1,1,C.Subunitatea)
          AND C1.Pret &lt;&gt; Decode(aTipC,0,TA.PRET,C1.Pret*TA.COEF)
          AND C.DataStop &gt;= vDataRef
          AND C.DataStart &gt;= CASE WHEN aTipPer = 2 THEN vDataRef ELSE C.DataStart END -- Contracte viitoare
          AND C.DataStart &lt;= CASE WHEN aTipPer = 1 THEN vDataRef ELSE C.DataStart END -- Contracte active
        ORDER BY C.CodContract, C1.CodContract1 )
      LOOP
        IF vRec.CodContract &lt;&gt; vLastLocked AND vRec.CodContract &lt;&gt; vLastBlocked AND vRec.Facturat = 0 THEN
          BEGIN
            SP_LOCKRECORD(vRec.CodContract);
            vLastLocked := vRec.CodContract;
            vCount      := vCount + 1;
          EXCEPTION
            WHEN Others THEN
              vResult      := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
              vLastBlocked := vRec.CodContract;
          END;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.CodContract1 &lt;&gt; vLastCodC1 AND vRec.Facturat = 0 THEN
          UPDATE Contract1 SET Pret = vRec.PretNou WHERE CodContract1 = vrec.CodContract1;
          vDif       := vRec.CoefValoare * (vRec.PretNou - vRec.Pret);
          vLastCodC1 := vrec.CodContract1;
        END IF;

        IF vRec.CodContract = vLastLocked AND vRec.Facturat = 0 AND vRec.CodContract2 IS NOT NULL THEN

          IF vrec.C2DataStop IS NULL
          THEN dUltimaZi := Last_Day(vrec.C2Data);
          ELSE dUltimaZi := vrec.C2DataStop;
          END IF;

          dUltimaZi := Least(dUltimaZi, vrec.DataStop);

          IF Coalesce(vrec.Avans,0) = 0 THEN
            vAn   := EXTRACT(YEAR  FROM vRec.C2Data);
            vLuna := EXTRACT(MONTH FROM vRec.C2Data);
          ELSE
            vAn   := EXTRACT(YEAR  FROM dUltimaZi);
            vLuna := EXTRACT(MONTH FROM dUltimaZi);
          END IF;

          IF vrec.PerFact &gt; 1 THEN
            IF vLuna &lt; vRec.PerFact THEN
              vAn   := vAn - 1;
              vLuna := vLuna + 12;
            END IF;
            vLuna := vLuna + 1 - vRec.PerFact;
          END IF;

          BEGIN
            dPrimaZi := Trunc(To_Date(To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;yyyymm&apos;), &apos;mm&apos;);
            dPrimaZi := Greatest(dPrimaZi, vRec.DataStart);

            CoeficientZILE(dPrimaZi, dUltimaZi, vRec.C1DataStart, vRec.C1DataStop, vRec.C1TipPret, vCoefZile, vNrZile);

            UPDATE Contract2 SET Suma = Suma + vDif * vCoefZile WHERE CodContract2 = vrec.CodContract2;
          EXCEPTION WHEN others THEN null;
          END;
        END IF;
      END LOOP;
    END IF;

    IF vResult IS NOT NULL THEN
      vResult := &apos;Contracte ce nu au putut fi modificate : &apos;||SubStr(vResult,2);
    END IF;
    IF vCount = 1 THEN
      vResult := &apos;A fost modificat un contract. &apos;||vResult;
    ELSE
      vResult := &apos;Au fost modificate &apos;||vCount||&apos; contracte. &apos;||vResult;
    END IF;
    COMMIT;
    RETURN vResult;
  END IF;
END;

FUNCTION ACTPRETContr (aSubunit IN NUMBER, aMONEDA IN NUMBER, aTipC IN NUMBER, aTipDoc IN NUMBER, aTipObiect IN NUMBER, aAllPart IN NUMBER, aExpl in Varchar2) RETURN VARCHAR2 IS
  vEroare      NUMBER     := 0;
  vLastLocked  NUMBER(20) := 0;
  vLastBlocked NUMBER(20) := 0;
  vLastCodC1   NUMBER(20) := 0;
  vResult      VARCHAR2(4000);
  RES_BUSY     EXCEPTION;
  PRAGMA       EXCEPTION_INIT(RES_BUSY, -54);
  vCount       NUMBER     := 0;
  vDif         NUMBER     := 0;
  vDataRef     DATE       := To_Date(&apos;01.01.0001&apos;,&apos;dd.mm.yyyy&apos;);

  vFDALLucru   DATE;
  vLDALLucru   DATE;
BEGIN
  vFDALLucru := Trunc(To_Date( To_Char(PKG_GLOBALS.GETANLUCRU,&apos;0000&apos;)||To_Char(PKG_GLOBALS.GETLUNALUCRU,&apos;00&apos;), &apos;yyyymm&apos;),&apos;mm&apos;);
  vLDALLucru := Last_Day(vFDALLucru);

  IF vEroare = 0 THEN
    FOR vRec IN (
			SELECT C.CodContract, C1.CodContract1, C.NrDoc, C.DataDoc,
        CASE
          WHEN aTipC = 0 AND TA.PRET &lt;&gt; 0 THEN TA.PRET
          WHEN aTipC IN (1,3) THEN C1.Pret*TA.COEF
          WHEN aTipC IN (2,4) THEN C1.Pret+TA.COEF
          ELSE C1.Pret
        END Pret,
        CASE
          WHEN aTipC = 0 AND TA.COEF &lt;&gt; 0 THEN TA.COEF
          ELSE C1.PretStandard
        END PretStandard,
        CASE
          WHEN aTipC = 0 AND TA.CANT &lt;&gt; 0 THEN C1.CantGlobal * TA.CANT
          ELSE C1.Cant
        END Cant
      FROM Contract C
        INNER JOIN Contract1 C1 ON C1.CodContract = C.CodContract
        INNER JOIN TMP_ACTABON_ART TA ON TA.CodObiect = C1.CodObiect
      WHERE C.TipDoc = aTipDoc
        AND C.Moneda = aMoneda
        AND (aAllPArt = 1 OR C.Partener IN (SELECT CodUnic FROM TMP_MANEVRA))
        AND aSubunit = CASE WHEN aSubunit = 1 THEN 1 ELSE C.Subunitatea END
        AND C1.TipObiect = aTipObiect
        AND Coalesce(C1.DataStop,  C.Datastop)  &gt;= vFDALLucru
        AND Coalesce(C1.DataStart, C.Datastart) &lt;= vLDALLucru
		) LOOP
      IF vRec.CodContract &lt;&gt; vLastLocked THEN
        BEGIN
          SP_LOCKRECORD(vRec.CodContract);
          vLastLocked := vRec.CodContract;
          vCount      := vCount + 1;
        EXCEPTION
          WHEN Others THEN
            vResult      := vResult||&apos;,&apos;||to_char(vRec.NrDoc)||&apos;/&apos;||To_Char(vRec.DataDoc,&apos;dd.mm.yyyy&apos;);
        END;
      END IF;

      UPDATE Contract1
      SET Pret         = vRec.Pret,
          PretStandard = vRec.PretStandard,
          Cant         = vRec.CANT
      WHERE CodContract1 = vrec.CodContract1;

    END LOOP;

    IF vResult IS NOT NULL THEN
      vResult := &apos;Contracte ce nu au putut fi modificate : &apos;||SubStr(vResult,2);
    END IF;
    IF vCount = 1 THEN
      vResult := &apos;A fost modificat un contract. &apos;||vResult;
    ELSE
      vResult := &apos;Au fost modificate &apos;||vCount||&apos; contracte. &apos;||vResult;
    END IF;
    COMMIT;
    RETURN vResult;
  END IF;
END;


FUNCTION getComisioane(aCodPart IN NUMBER) return crsComisioane IS
  cResult crsComisioane;
  sSql VARCHAR2(10000);
  swith VARCHAR2(10000);
  vCodContract number(20);
  vTipTargetV number(1);
  vDataStart varchar2(10);
  vDataStop varchar2(10);
  vCountV number(10);
  vProcDiscV number(20,7);
  vSumaFixaDiscV number(20,7);

  KArtDiscAcTer       varchar2(1000) := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       number(20) := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      number(20) := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        number(20) := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC number(20) := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
BEGIN
  if pkg_globals.getsubunitate &gt; 1 THEN
    BEGIN
      select c.codcontract, Coalesce(c.tiptargetv,0), to_char(C.DataStart, &apos;dd.mm.yyyy&apos;), to_char(C.DataStop, &apos;dd.mm.yyyy&apos;)
      into vCodContract, vTipTargetV, vDataStart, vDataStop
      from contract c
      where C.partener = aCodPart
        and C.DataStart &lt;= sysdate AND C.DataStop &gt;= sysdate
        and c.subunitatea = pkg_globals.GETSUBUNITATE
        and c.operat = 1;
    exception WHEN others THEN
      vCodContract := 0;
      vTipTargetV  := 0;
    END;

    select count(*) into vCountV from contractv where codcontract = vCodContract;
    if vCountV = 1 THEN
      select Coalesce(discount,0) into vProcDiscV from contractv where codcontract = vCodContract;
      if vProcDiscV = 0 THEN
        select Coalesce(valdiscount,0) into vSumaFixaDiscV from contractv where codcontract = vCodContract;
      END if;
    ELSE
      vProcDiscV    := 0;
      vSumaFixaDiscV := 0;
    END if;

    if vCodContract &gt; 0 THEN
      if vTipTargetV = 0 THEN
        sSql := &apos;select den_part, prefixdoc, nrdoc, datadoc, valdoc, sum(valm) valcontr,&apos;;
        if vProcDiscV &lt;&gt; 0 THEN
          sSql := sSql||&apos;sum(valm)*&apos;||vProcDiscV||&apos;/100 discount &apos;||chr(13);
        ELSE
          sSql := sSql||vSumaFixaDiscV||&apos; discount &apos;||chr(13);
        END if;
        sSql := sSql||
                &apos; from (&apos;||chr(13)||
                &apos;select p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, CASE WHEN i.tipdoc = 21 THEN i.valdoc ELSE i.valdoc - i.tvadoc END valdoc, &apos;||chr(13)||
                &apos;       SUM(CASE WHEN i.tipdoc = 21 THEN (I1.Cant*i1.pretorig - I1.TVA) * Coalesce(I1.CoefDiscMaj,1) ELSE i1.cant * i1.pretorig * Coalesce(I1.CoefDiscMaj,1) END) ValM &apos;||chr(13)||
                &apos;FROM IESIRI I &apos;||chr(13)||
                &apos;     INNER JOIN iesiri1 I1 on i.codies = i1.codies &apos;||chr(13)||
                &apos;     inner join npart p on p.codpart = i.partener&apos;||chr(13)||
                &apos;where I.TipDoc IN (19, 21, 26) &apos;||chr(13)||
                &apos;  and i.PARTCUSTODIE = &apos;||aCodPart||chr(13)||
                &apos;  AND Coalesce(I.Anulat,0) = 0 and i.operat = 1 &apos;||chr(13)||
                &apos;  AND I1.CodObiect &gt; 0 &apos;||chr(13)||
                &apos;  AND i.datadoc between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataStop||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||chr(13)||
                &apos;  AND I1.CodObiect not in (&apos;||KArtDiscAcVol||&apos;, &apos;||KArtDiscAcCant||&apos;, &apos;||KArtPenAcTer||&apos;, &apos;||KArtDiscOffInvoiceC||&apos;) &apos;||chr(13)||
                &apos;  AND INSTR(&apos;||KArtDiscAcTer||&apos;,I1.CodObiect) = 0 &apos;||chr(13)||
                &apos;  AND I.Subunitatea = pkg_globals.getsubunitate &apos;||chr(13)||
                &apos;  AND NOT EXISTS (SELECT NC1.CODNCREDIT &apos;||chr(13)||
                &apos;                  FROM NOTECREDIT1 NC1 &apos;||chr(13)||
                &apos;                       INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT &apos;||chr(13)||
                &apos;                       LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT &apos;||chr(13)||
                &apos;                       LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = NC1.CODDOC &apos;||chr(13)||
                &apos;                       LEFT JOIN IESIRI II ON II1.CODIES = II.CODIES AND NC1.TIPDOC = II.TIPDOC &apos;||chr(13)||
                &apos;                  WHERE ((I.CODIES = NC1.CODDOC AND Coalesce(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1) OR (I.CODIES = II.CODIES AND (Coalesce(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))) &apos;||chr(13)||
                &apos;                        AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; )&apos;||chr(13)||
                &apos;group by p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, i.tipdoc, i.valdoc, i.tvadoc &apos;||chr(13)||
                &apos;  ) group by den_part, prefixdoc, nrdoc, datadoc, valdoc &apos;;
      ELSE if vTipTargetV in (1,2) THEN
        sSql := &apos;select den_part, prefixdoc, nrdoc, datadoc, valdoc, sum(valm) valcontr,&apos;;
        if vProcDiscV &lt;&gt; 0 THEN
          sSql := sSql||&apos;sum(valm)*&apos;||vProcDiscV||&apos;/100 discount &apos;||chr(13);
        ELSE
          sSql := sSql||vSumaFixaDiscV||&apos; discount &apos;||chr(13);
        END if;
        sSql := sSql||&apos; from (&apos;||chr(13)||
        &apos;select p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, CASE WHEN i.tipdoc = 21 THEN i.valdoc ELSE i.valdoc - i.tvadoc END valdoc, &apos;||chr(13)||
        &apos;       SUM(CASE WHEN Coalesce(c1.tipdiscount,0) = 0 THEN CASE WHEN i.tipdoc = 21 THEN (I1.Cant*i1.pretorig - I1.TVA) * Coalesce(I1.CoefDiscMaj,1) ELSE i1.cant * i1.pretorig * Coalesce(I1.CoefDiscMaj,1) END ELSE I1.Cant * C1.pret END) ValM &apos;||chr(13)||
        &apos;FROM IESIRI I &apos;||chr(13)||
        &apos;     INNER JOIN iesiri1 I1 on i.codies = i1.codies &apos;||chr(13)||
        &apos;     INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;||vCodContract||&apos;) &apos;||chr(13)||
        &apos;     inner join npart p on p.codpart = i.partener&apos;||chr(13)||
        &apos;where I.TipDoc IN (19, 21, 26) &apos;||chr(13)||
        &apos;  and i.PARTCUSTODIE = &apos;||aCodPart||chr(13)||
        &apos;  AND Coalesce(I.Anulat,0) = 0 and i.operat = 1 &apos;||chr(13)||
        &apos;  AND I1.CodObiect &gt; 0 &apos;||chr(13)||
        &apos;  AND i.datadoc between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataStop||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||chr(13)||
        &apos;  AND I1.CodObiect not in (&apos;||KArtDiscAcVol||&apos;, &apos;||KArtDiscAcCant||&apos;, &apos;||KArtPenAcTer||&apos;, &apos;||KArtDiscOffInvoiceC||&apos;) &apos;||chr(13)||
        &apos;  AND INSTR(&apos;||KArtDiscAcTer||&apos;,I1.CodObiect) = 0 &apos;||chr(13)||
        &apos;  AND I.Subunitatea = pkg_globals.getsubunitate&apos;||chr(13)||
        &apos;  and c1.codcontract = &apos;||vCodContract||chr(13)||
        &apos;  and NOT EXISTS (SELECT NC1.CODNCREDIT &apos;||chr(13)||
        &apos;                  FROM NOTECREDIT1 NC1 &apos;||chr(13)||
        &apos;                       INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT &apos;||chr(13)||
        &apos;                       LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT &apos;||chr(13)||
        &apos;                       LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = NC1.CODDOC &apos;||chr(13)||
        &apos;                       LEFT JOIN IESIRI II ON II1.CODIES = II.CODIES AND NC1.TIPDOC = II.TIPDOC &apos;||chr(13)||
        &apos;                  WHERE ((I.CODIES = NC1.CODDOC AND Coalesce(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1) OR (I.CODIES = II.CODIES AND (Coalesce(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))) &apos;||chr(13)||
        &apos;                        AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; )&apos;||chr(13)||
        &apos; group by p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, i.tipdoc, i.valdoc, i.tvadoc &apos;||chr(13)||
        &apos;  ) group by den_part, prefixdoc, nrdoc, datadoc, valdoc &apos;;
      END if; END if;
    ELSE
      sSql := &apos;select pkg_globals.getsubunitate den_subunit, p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, 0 valdoc, &apos;||chr(13)||
        &apos;      0 ValContr, 0 Discount &apos;||chr(13)||
        &apos;FROM IESIRI I &apos;||chr(13)||
        &apos;     INNER JOIN iesiri1 I1 on i.codies = i1.codies &apos;||chr(13)||
        &apos;     INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;||vCodContract||&apos;) &apos;||chr(13)||
        &apos;     inner join npart p on p.codpart = i.partener&apos;||chr(13)||
        &apos;where i.codies = -1&apos;;
    END if;
  ELSE
    sWith := &apos;with contr as (select c.codcontract, Coalesce(c.tiptargetv,0) tiptargetv, to_char(C.DataStart, &apos;&apos;dd.mm.yyyy&apos;&apos;) datastart, to_char(C.DataStop, &apos;&apos;dd.mm.yyyy&apos;&apos;) datastop, c.subunitatea, cv.procdisc, cv.valdisc
              from contract c
                   inner join (select cc.codcontract, Coalesce(ccv.discount,0) ProcDisc, Coalesce(ccv.valdiscount,0) ValDisc
                               from contract cc
                                    inner join contractv ccv on ccv.codcontract = cc.codcontract
                                    inner join (select count(*) cate, codcontract from contractv group by codcontract) nrcv on nrcv.codcontract = cc.codcontract
                               where nrcv.cate = 1
                                     and Cc.partener = &apos;||aCodPart||&apos;
                                     and Cc.DataStart &lt;= sysdate AND Cc.DataStop &gt;= sysdate
                                     and cc.operat = 1
                               union all
                               select cc.codcontract, 0 ProcDisc, 0 ValDisc
                               from contract cc
                                    inner join (select count(*) cate, codcontract from contractv group by codcontract) nrcv on nrcv.codcontract = cc.codcontract
                               where nrcv.cate &gt; 1
                                     and Cc.partener = &apos;||aCodPart||&apos;
                                     and Cc.DataStart &lt;= sysdate AND Cc.DataStop &gt;= sysdate
                                     and cc.operat = 1
                              ) cv on cv.codcontract = c.codcontract
                   inner join (select count(*) cate, cc.subunitatea
                               from contract cc
                               where Cc.partener = &apos;||aCodPart||&apos;
                                     and Cc.DataStart &lt;= sysdate AND Cc.DataStop &gt;= sysdate
                                     and cc.operat = 1
                               group by cc.subunitatea) nrc on nrc.subunitatea = c.subunitatea
                where C.partener = &apos;||aCodPart||&apos;
                    and C.DataStart &lt;= sysdate AND C.DataStop &gt;= sysdate
                    and nrc.cate = 1
                    and c.operat = 1
                union
                select 0 codcontract, 0 tiptargetv, &apos;&apos;&apos;&apos; datastart, &apos;&apos;&apos;&apos; datastop, nrc.subunitatea, 0 procdisc, 0 valdisc
                from (select count(*) cate, cc.subunitatea
                    from contract cc
                    where Cc.partener = &apos;||aCodPart||&apos;
                          and Cc.DataStart &lt;= sysdate AND Cc.DataStop &gt;= sysdate
                          and cc.operat = 1
                    group by cc.subunitatea
                    ) nrc
                where nrc.cate &gt; 1 )&apos;;
    sSql := &apos;select s.den_subunit, x.den_part, x.prefixdoc, x.nrdoc, x.datadoc, x.valdoc, 0 valcontr, 0 discount&apos;||chr(13)||
            &apos; from (&apos;||chr(13)||
            &apos;select i.subunitatea, p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, CASE WHEN i.tipdoc = 21 THEN i.valdoc ELSE i.valdoc - i.tvadoc END valdoc, &apos;||chr(13)||
            &apos;       SUM(CASE WHEN i.tipdoc = 21 THEN (I1.Cant*i1.pretorig - I1.TVA) * Coalesce(I1.CoefDiscMaj,1) ELSE i1.cant * i1.pretorig * Coalesce(I1.CoefDiscMaj,1) END) ValM &apos;||chr(13)||
            &apos;FROM IESIRI I &apos;||chr(13)||
            &apos;     INNER JOIN iesiri1 I1 on i.codies = i1.codies &apos;||chr(13)||
            &apos;     inner join npart p on p.codpart = i.partener&apos;||chr(13)||
            &apos;     inner join contr on contr.subunitatea = i.subunitatea&apos;||chr(13)||
            &apos;where I.TipDoc IN (19, 21, 26) &apos;||chr(13)||
            &apos;  and i.PARTCUSTODIE = &apos;||aCodPart||chr(13)||
            &apos;  AND Coalesce(I.Anulat,0) = 0 and i.operat = 1 &apos;||chr(13)||
            &apos;  AND I1.CodObiect &gt; 0 &apos;||chr(13)||
            &apos;  AND I1.CodObiect not in (&apos;||KArtDiscAcVol||&apos;, &apos;||KArtDiscAcCant||&apos;, &apos;||KArtPenAcTer||&apos;, &apos;||KArtDiscOffInvoiceC||&apos;) &apos;||chr(13)||
            &apos;  AND INSTR(&apos;||KArtDiscAcTer||&apos;,I1.CodObiect) = 0 &apos;||chr(13)||
            &apos;  AND contr.codcontract = 0 &apos;||chr(13)||
            &apos;  AND NOT EXISTS (SELECT NC1.CODNCREDIT &apos;||chr(13)||
            &apos;                  FROM NOTECREDIT1 NC1 &apos;||chr(13)||
            &apos;                       INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT &apos;||chr(13)||
            &apos;                       LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT &apos;||chr(13)||
            &apos;                       LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = NC1.CODDOC &apos;||chr(13)||
            &apos;                       LEFT JOIN IESIRI II ON II1.CODIES = II.CODIES AND NC1.TIPDOC = II.TIPDOC &apos;||chr(13)||
            &apos;                  WHERE ((I.CODIES = NC1.CODDOC AND Coalesce(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1) OR (I.CODIES = II.CODIES AND (Coalesce(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))) &apos;||chr(13)||
            &apos;                        AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; )&apos;||chr(13)||
            &apos;group by i.subunitatea, p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, i.tipdoc, i.valdoc, i.tvadoc &apos;||chr(13)||
            &apos;  ) x &apos;||chr(13)||
            &apos;    inner join contr on x.subunitatea = contr.subunitatea &apos;||chr(13)||
            &apos;    inner join nsubunit s on x.subunitatea = s.codsubunit &apos;||chr(13)||
            &apos;  where contr.codcontract = 0 &apos;||chr(13)||
            &apos;union all &apos;||chr(13)||
            &apos;select s.den_subunit, x.den_part, x.prefixdoc, x.nrdoc, x.datadoc, x.valdoc, x.valm valcontr, CASE WHEN contr.procdisc &lt;&gt; 0 THEN contr.procdisc*x.valm/100 ELSE contr.valdisc END  discount&apos;||chr(13)||
            &apos; from (&apos;||chr(13)||
            &apos;select i.subunitatea, p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, CASE WHEN i.tipdoc = 21 THEN i.valdoc ELSE i.valdoc - i.tvadoc END valdoc, &apos;||chr(13)||
            &apos;       SUM(CASE WHEN i.tipdoc = 21 THEN (I1.Cant*i1.pretorig - I1.TVA) * Coalesce(I1.CoefDiscMaj,1) ELSE i1.cant * i1.pretorig * Coalesce(I1.CoefDiscMaj,1) END) ValM &apos;||chr(13)||
            &apos;FROM IESIRI I &apos;||chr(13)||
            &apos;     INNER JOIN iesiri1 I1 on i.codies = i1.codies &apos;||chr(13)||
            &apos;     inner join npart p on p.codpart = i.partener&apos;||chr(13)||
            &apos;     inner join contr on contr.subunitatea = i.subunitatea&apos;||chr(13)||
            &apos;where I.TipDoc IN (19, 21, 26) &apos;||chr(13)||
            &apos;  and i.PARTCUSTODIE = &apos;||aCodPart||chr(13)||
            &apos;  AND Coalesce(I.Anulat,0) = 0 and i.operat = 1 &apos;||chr(13)||
            &apos;  AND I1.CodObiect &gt; 0 &apos;||chr(13)||
            --&apos;  AND i.datadoc between contr.datastart and contr.datastop &apos;||chr(13)||
            &apos;  AND I1.CodObiect not in (&apos;||KArtDiscAcVol||&apos;, &apos;||KArtDiscAcCant||&apos;, &apos;||KArtPenAcTer||&apos;, &apos;||KArtDiscOffInvoiceC||&apos;) &apos;||chr(13)||
            &apos;  AND INSTR(&apos;||KArtDiscAcTer||&apos;,I1.CodObiect) = 0 &apos;||chr(13)||
            &apos;  AND contr.codcontract &gt; 0 &apos;||chr(13)||
            &apos;  AND NOT EXISTS (SELECT NC1.CODNCREDIT &apos;||chr(13)||
            &apos;                  FROM NOTECREDIT1 NC1 &apos;||chr(13)||
            &apos;                       INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT &apos;||chr(13)||
            &apos;                       LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT &apos;||chr(13)||
            &apos;                       LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = NC1.CODDOC &apos;||chr(13)||
            &apos;                       LEFT JOIN IESIRI II ON II1.CODIES = II.CODIES AND NC1.TIPDOC = II.TIPDOC &apos;||chr(13)||
            &apos;                  WHERE ((I.CODIES = NC1.CODDOC AND Coalesce(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1) OR (I.CODIES = II.CODIES AND (Coalesce(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))) &apos;||chr(13)||
            &apos;                        AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; )&apos;||chr(13)||
            &apos;group by i.subunitatea, p.den_part, i.prefixdoc, i.nrdoc, i.datadoc, i.tipdoc, i.valdoc, i.tvadoc &apos;||chr(13)||
            &apos;  ) x &apos;||chr(13)||
            &apos;    inner join contr on x.subunitatea = contr.subunitatea &apos;||chr(13)||
            &apos;    inner join nsubunit s on x.subunitatea = s.codsubunit &apos;||chr(13)||
            &apos;  where contr.codcontract &gt; 0 &apos;;
  END if;

  OPEN cResult FOR swith||sSql;
  RETURN cResult;
END;

FUNCTION getCantContor(aCodContract1 IN NUMBER, aData IN DATE) RETURN NUMBER IS
  vDataAux         DATE;
  vDataStart       DATE;
  vDataMin         DATE;
  vDataBordInceput DATE;
  vDataBordSfarsit DATE;
  vRefDataBord     DATE;
  vLastIndexBord   NUMBER;
  vRefIndexBord    NUMBER;
  vCorectieIndex   NUMBER;
  vCoefPer         NUMBER;
  vZilePlf         NUMBER;
  vZileMax         NUMBER;
  vCodParinte      NUMBER(20);
  vCant            NUMBER(20,7)  := 0;
  vCantContr       NUMBER(20,7);
  vCodUtilaj       NUMBER(20);
  vIdxUtilaj       NUMBER(2);
  vTipUtilaj       NUMBER(1);
  vPlafonCantF     NUMBER(20,7);
  vTipPret         NUMBER(1);
  vPerFact         NUMBER(20);
  vCantContor      NUMBER;
  vContrPerContor  NUMBER;
  vCantPerContor   NUMBER;
  vAn              NUMBER := Extract(YEAR  FROM aData);
  vLuna            NUMBER := Extract(MONTH FROM aData);
BEGIN
  IF NOT ( Coalesce(pAbTipPlafonAn, -1) = vAn AND Coalesce(pAbTipPlafonLuna, -1) = vLuna ) THEN
    pAbTipPlafonAn   := vAn;
    pAbTipPlafonLuna := vLuna;
    pAbTipPlafonVal  := Coalesce(pkg_categconst.GetValConstanta(&apos;ContrAbTipPlafon&apos;, vAn, vLuna), &apos;2&apos;);
  END IF;

  SELECT
    C1.Cant,
    Coalesce(C1.CodUtilaj,0),
    Coalesce(C1.Utilaj_Tip_Index,0),
    Coalesce(C1.PlafonCantF,0),
    Coalesce(C1.TipPret, 1),
    C.PerFact,
    Coalesce(C1.DataStart,C.DataStart),
    CASE WHEN Coalesce(C1.IndexParinte, 0) &gt; 0 THEN (SELECT xC1.CodContract1 FROM Contract1 xC1 WHERE xC1.CodContract = C1.CodContract AND xC1.IndexLocal = C1.IndexParinte) ELSE NULL END
  INTO
    vCantContr,
    vCodUtilaj,
    vIdxUtilaj,
    vPlafonCantF,
    vTipPret,
    vPerFact,
    vDataStart,
    vCodParinte
  FROM Contract1 C1 INNER JOIN  Contract C ON c.codcontract = c1.codcontract
  WHERE C1.CodContract1 = aCodContract1;

  IF vCodParinte IS NULL THEN
    vDataMin := Add_Months(aData, -vPerFact) + 1;
    IF vDataMin &lt; vDataStart THEN
      vDataMin := vDataStart;
    END IF;

    IF vCodUtilaj = 0
    THEN
      vCant := vCantContr;
    ELSE
      SELECT Tip INTO vTipUtilaj FROM utilaje WHERE CodUtilaj = vCodUtilaj;

      SELECT Count(1),      Sum(Coalesce(Cant, 0))
      INTO vContrPerContor, vCantPerContor
      FROM Contract1 C1 INNER JOIN Contract C ON c.codcontract = c1.codcontract
      WHERE C1.CodUtilaj = vCodUtilaj
        AND Coalesce(C1.UTILAJ_TIP_INDEX, 0) = vIdxUtilaj
        AND aData BETWEEN Coalesce(C1.DataStart,C.DataStart) AND Coalesce(C1.DataStop, C.DataStop)
        AND C.Activ = 1 AND C.Operat = 1 AND C.Anulat = 0
        AND NOT EXISTS ( SELECT 1
                         FROM Contract2 C2
                         WHERE c2.codcontract = c.codcontract
                           AND Coalesce(C2.SediuLivrare,0) = Coalesce(C1.SediuLivrare,0)
                           AND aData BETWEEN Trunc(C2.DataStop, &apos;mm&apos;) AND C2.DataStop
                           AND Coalesce(C2.Suspendat,0) = 1
                       );

      vCantContor    := 0;
      vCorectieIndex := 0;
      FOR vRec IN (
        SELECT DataBord, Coalesce(IndexBord, 0) IndexBord, CorectieIndex
        FROM utilaje3
        WHERE CodUtilaj = vCodUtilaj AND Coalesce(TIP_INDEX, 0) = vIdxUtilaj AND DATABORD &lt;= aData
        ORDER BY DATABORD DESC
      ) LOOP
        IF vRefDataBord IS NOT NULL THEN
          vCantContor      := vCantContor + (vRefIndexBord - vRec.IndexBord);
        ELSE
          vDataBordSfarsit := vRec.DataBord;
          vLastIndexBord   := vRec.IndexBord;
        END IF;

        vRefDataBord  := vRec.DataBord;
        vRefIndexBord := vRec.IndexBord;

        EXIT WHEN vRec.DataBord &lt; vDataMin;
        vCorectieIndex := vCorectieIndex + Coalesce(vRec.CorectieIndex,0);
      END LOOP;

      IF    vRefIndexBord IS NULL
      THEN vDataBordInceput := vDataMin;
      ELSE vDataBordInceput := vRefDataBord;
      END IF;

      vCantContor := vCantContor - vCorectieIndex;

      IF vCantContor &gt; 0 THEN
        IF    Coalesce(vCantPerContor, 0)  &lt;&gt; 0 THEN vCant := vCantContor * vCantContr / vCantPerContor;
        ELSIF coalesce(vContrPerContor, 0) &lt;&gt; 0 THEN vCant := vCantContor              / vContrPerContor;
        ELSE                                         vCant := 0;
        END IF;

        IF    vTipPret = 1 --lunar = relativ la nr.de zile facturabile din luna
        OR    vTipPret = 3 --Cantitativ = cantitate lunara limitata
        THEN
          vCoefPer := 0;
          vDataAux := Trunc(vDataBordInceput, &apos;dd&apos;);
          WHILE vDataAux &lt; vDataBordSfarsit LOOP
            IF   Trunc(vDataAux, &apos;mm&apos;) = Trunc(vDataBordSfarsit, &apos;mm&apos;) THEN
              vZileMax := 1+Trunc(vDataBordSfarsit)  - Trunc(vDataAux,&apos;MM&apos;);
              vZilePlf := 1+Trunc(vDataBordSfarsit)  - Trunc(vDataAux);
            ELSE
              vZileMax := 1+Trunc(Last_Day(vDataAux))- Trunc(vDataAux,&apos;MM&apos;);
              vZilePlf := 1+Trunc(Last_Day(vDataAux))- Trunc(vDataAux);
            END IF;
            vCoefPer := vCoefPer + vZilePlf/vZileMax;
            vDataAux := Add_Months(Trunc(vDataAux,&apos;mm&apos;), 1);
          END LOOP;
        ELSIF vTipPret = 5 THEN --lunar fix = indiferent de nr.de zile facturabile din luna
          vCoefPer := 0;
          vDataAux := Trunc(vDataBordInceput, &apos;dd&apos;);
          WHILE vDataAux &lt; vDataBordSfarsit LOOP
            vCoefPer := vCoefPer + 1;
            vDataAux := Add_Months(vDataAux,1);
          END LOOP;
        ELSIF vTipPret = 2 THEN --zilnic = in functie de nr.de zile perioada facturata
          vCoefPer := vDataBordSfarsit - vDataBordInceput;
        ELSIF vTipPret = 4 THEN --Pachet = cantitate per contract limitata
          vCoefPer := 1;
        END IF;

        IF    pAbTipPlafonVal = 1 THEN -- cantitate minima de facturat
          vCant := Greatest(vCant, vCoefPer * vPlafonCantF);
        ELSIF pAbTipPlafonVal = 2 THEN -- cantitate inclusa in abonament
          vCant := vCant - vCoefPer * vPlafonCantF;
        END IF;
      ELSIF vTipUtilaj = 4 THEN
        vCant := vCantContr;
      END IF;

      IF vCant &lt; 0 THEN
        vCant := 0;
      END IF;

    END IF;
  ELSE
    vCant := vCant * PKG_CONTRACT.getCantContor(vCodParinte, aData);
  END IF;

  pContor_IdxCC1  := aCodContract1;
  pContor_DataR   := aData;
  pContor_DataIni := vDataBordInceput;
  pContor_IdxIni  := vRefIndexBord;
  pContor_DataFin := vDataBordSfarsit;
  pContor_IdxFin  := vLastIndexBord;

  RETURN vCant;
END;

PROCEDURE setCantContor(aCodContract1 IN NUMBER, aData IN DATE) IS
  vCNT  NUMBER;
  vCant NUMBER;
BEGIN
  SELECT Count(1) INTO vCNT
  FROM TMP_C1_CantContor
  WHERE CodContract1 = aCodContract1 AND DataRef = aData;

  IF vCNT = 0 THEN
    vCant := getCantContor(aCodContract1, aData);
    INSERT INTO TMP_C1_CantContor (CodContract1, DataRef, Cant, DataIni, IDXIni, DataFin, IDXFin)
    VALUES (pContor_IdxCC1, pContor_DataR, vCant, pContor_DataIni, pContor_IdxIni, pContor_DataFin, pContor_IdxFin);
  END IF;
END;

FUNCTION getCantExtra(aCodContract1 IN NUMBER, aData IN DATE) RETURN NUMBER IS
  vDataStart      DATE;
  vDataMin        DATE;
  vCodContract    NUMBER(20);
  vCant           NUMBER(20,7);
  vCantCom        NUMBER(20,7);
  vPerFact        NUMBER(20);
BEGIN
  SELECT C1.Cant, C.PerFact, C.CodContract, Coalesce(C1.DataStart,C.DataStart)
  INTO   vCant,   vPerFact,  vCodContract,  vDataStart
  FROM Contract1 C1 INNER JOIN  Contract C ON c.codcontract = c1.codcontract
  WHERE C1.CodContract1 = aCodContract1;

  vDataMin := Add_Months(aData, -vPerFact) + 1;
  IF vDataMin &lt; vDataStart THEN
    vDataMin := vDataStart;
  END IF;

  SELECT Coalesce(Sum(CASE WHEN c2.codcontract2 IS NULL THEN 1 ELSE -1 END*com1.cantacceptat),0)
  INTO   vCantCom
  FROM comanda1 com1
    INNER JOIN comanda com ON com.codcomanda = com1.codcomanda
    LEFT JOIN contract2 c2 ON c2.codcontract = vCodContract AND com.CodComanda  = C2.CodDocT AND COM.TipDoc = C2.TipDocT
  WHERE com1.codcontract1 = aCodContract1
    AND com.datadoc BETWEEN vDataMin AND aData;

  RETURN  CASE WHEN vCantCom &gt; vCant THEN vCantCom - vCant ELSE 0 END;
END;

FUNCTION ObsLuna(pCDataStart DATE, pC2DataStop DATE, pPerFact NUMBER) RETURN VARCHAR2 IS
  vNrLuni NUMBER;
  vAn1    NUMBER;
  vLuna1  NUMBER;
  vAn2    NUMBER;
  vLuna2  NUMBER;

  sRes    VARCHAR2(200);
BEGIN
  vAn2    := EXTRACT(YEAR  FROM pC2DataStop);
  vLuna2  := EXTRACT(MONTH FROM pC2DataStop);
  vAn1    := vAn2;
  vLuna1  := vLuna2;
  vNrLuni := pPerFact;
  IF vNrLuni = 0 THEN vNrLuni := 1; END IF;

  IF vNrLuni &gt; 1 THEN
    vAn1    := EXTRACT(YEAR  FROM pCDataStart);
    vLuna1  := EXTRACT(MONTH FROM pCDataStart);
    IF vAn1*12+vLuna1+vNrLuni-1 &lt; vAn2*12+vLuna2 THEN
      IF vLuna2 &gt;= vNrLuni THEN
        vLuna1 := vLuna2 + 1 - vNrLuni;
        vAn1   := vAn2;
      ELSE
        vLuna1 := vLuna2 + 13 - vNrLuni;
        vAn1   := vAn2 - 1;
      END IF;
    END IF;
  END IF;

  IF    (vAn1 &lt;&gt; vAn2) AND (vLuna1 &lt;&gt; vLuna2) THEN
    sRes := PKG_LIST_BASE_UTILS.decode_luna(vLuna1)||&apos; &apos;||vAn1||&apos; -&gt; &apos;||PKG_LIST_BASE_UTILS.decode_luna(vLuna2)||&apos; &apos;||vAn2;
  ELSIF (vAn1 =  vAn2) AND (vLuna1 &lt;&gt; vLuna2) THEN
    sRes := PKG_LIST_BASE_UTILS.decode_luna(vLuna1)||&apos; -&gt; &apos;||PKG_LIST_BASE_UTILS.decode_luna(vLuna2)||&apos; &apos;||vAn2;
  ELSE
    sRes := PKG_LIST_BASE_UTILS.decode_luna(vLuna2)||&apos; &apos;||vAn2;
  END IF;

  RETURN sRes;
END;

PROCEDURE SetTMPFactAb(
  pTipPrel NUMBER, sDataRef VARCHAR2, pTipDataRef NUMBER, pLocalit NUMBER,
  pClasa NUMBER, pAgent NUMBER, pIOArt NUMBER, pGest NUMBER, sDataFact VARCHAR2,
  pPersoanaFizica NUMBER, pTipSediu NUMBER,
  pTraseu NUMBER DEFAULT 0)
IS
  pBancaDef   NUMBER;
  pObsNrContr NUMBER;
  dDataRef    DATE;
  dDataFact   DATE;
  vAnLucru    NUMBER := PKG_GLOBALS.GetANLUCRU;
  vLunaLucru  NUMBER := PKG_GLOBALS.GetLUNALUCRU;
  vALLucru    NUMBER := vAnLucru*12+vLunaLucru;
  vSubunit    NUMBER := PKG_GLOBALS.GETSUBUNITATE;
BEGIN
  DELETE FROM TMP_GFA_CONTR;
  DELETE FROM TMP_GFA_CONTR1;

  pBancaDef   := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;BancaCursPUV&apos;,     vAnLucru, vLunaLucru), 0);
  pObsNrContr := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;FactAbObsNrContr&apos;, vAnLucru, vLunaLucru), 1);
  dDataRef    := To_Date(sDataRef,&apos;dd.mm.yyyy&apos;);
  dDataFact   := To_Date(sDataFact,&apos;dd.mm.yyyy&apos;);

  IF pTipPrel = 0 THEN
    INSERT INTO TMP_GFA_CONTR
    SELECT
      C2.CodContract, C2.CodContract2, C.NrDoc NrContr, C.Partener, C.Moneda, C.Agent, C2.Data Scadenta, C2.Suma Valoare, C.ProcMaj, I.CodIes CodDoc, I.TipDoc, I.CarnetDoc, I.NrDoc, I.SeriaDoc,
      P.Den_Part, MON.Simbol Simb_Mon, numeprenume(PAG.Nume,PAg.Prenume) Den_Agent, DECODE(I.CodIes, Null, 0, 1) Facturat, Coalesce(I.Operat,0) Operat,
      C.CodLocatie, C.CodFiscal, C.Subunitatea, J.Den_Judet, LOC.Den_Localit, AG.Strada, AG.Nr1, C.FactLei, C.DataDoc DataContr,
      Coalesce((SELECT p1.scadentav FROM Npart1 P1 WHERE P1.CodPart = P.CodPart AND vALLucru BETWEEN P1.ALStart AND P1.ALStop),P.SCADENTAV ) SCADENTAV,
      C.Obs, C.CodPersC, C2.DataStop, C.DataStart DStart,C.DataStop DStop, AG.CodAgenda SediuLivrare,
      CASE
        WHEN pObsNrContr = 1 THEN &apos;*Contr &apos;||C.NrDoc||&apos;/&apos;||To_char(C.DataDoc,&apos;dd.mm.yyyy&apos;)||&apos; &apos;||C.OBS
        WHEN pObsNrContr = 2 THEN C.OBS
        WHEN pObsNrContr = 3 THEN &apos;*Contr &apos;||C.NrDoc||&apos;/&apos;||To_char(C.DataDoc,&apos;dd.mm.yyyy&apos;)
        WHEN pObsNrContr = 4 THEN &apos;&apos;
      END||&apos; *&apos;||PKG_CONTRACT.OBSLUNA(C.DataStart, C2.DataStop, C.PerFact) ObsFact,
      B.CODBANK Banca, B.Denumire Den_Banca, 0 NrAuxFact, Coalesce(C.Curs,0) Curs, C.CodAnaliza, AG.Obs SediuLivrDen, TL.DENTRASEU, AG.POZTRASEU, T1.DENTRASEU, AG.POZTRASEU1,
      NULL DATASCADV, 0 ZILESCADV, C.PerFact, AGC.CodAgenda Contr_SedLivr, C.ProcMajCurs, C.Avans, C.ZiFact,
      getadresa(AG.sector, AG.strada, AG.nr1, AG.nr2, AG.bloc, AG.scara, AG.etaj, AG.apart, AG.codpostal), C.Explicatii, C.Credite_Plafon, C.Credite_PU  
    FROM CONTRACT2 C2
      INNER JOIN CONTRACT C    ON C.CodContract    = C2.CodContract
      INNER JOIN NMONEDE  MON  ON MON.CodMoneda    = C.Moneda
      INNER JOIN NPART    P    ON P.CodPart        = C.Partener
      LEFT  JOIN NPERS    PAG  ON PAG.CodPers      = C.Agent
      LEFT  JOIN IESIRI   I    ON I.CodIes         = C2.CodDoc AND I.TipDoc = C2.TipDoc
      LEFT  JOIN NAGENDA  AGC  ON AGC.CodAgenda    = CASE WHEN Coalesce(C2.SediuLivrare, 0) = 0 THEN Coalesce(C.CodLocatie,0) ELSE Coalesce(C2.SediuLivrare, 0) END
      LEFT  JOIN NAGENDA  AG   ON AG.CodAgenda     = CASE WHEN pTipSediu = 1 THEN Coalesce(AGC.CodCoresp, AGC.CodAgenda) ELSE AGC.CodAgenda END
      LEFT  JOIN NLOCALIT LOC  ON LOC.CODLOCALIT   = AG.CODLOCALIT
      LEFT  JOIN NJUDET   J    ON J.CODJUDET       = LOC.CODJUDET
      LEFT  JOIN NBANK    B    ON B.CODBANK        = CASE WHEN Coalesce(C.Moneda,0) = 0 THEN 0 WHEN Coalesce(C.CodBanca,0) = 0 THEN pBancaDef ELSE C.CodBanca END
      LEFT  JOIN TRASEULIVR TL ON TL.CODTRASEULIVR = AGC.CodTraseu
      LEFT  JOIN TRASEULIVR T1 ON T1.CODTRASEULIVR = AGC.CodTraseu1
    WHERE CASE WHEN pTipDataRef = 0 THEN C2.DataStop ELSE C2.Data END = dDataRef
      AND ((I.CodIes IS NULL) OR (I.DATADOC = dDataFact))
      AND C.Activ = 1 AND C.Operat = 1 AND C.Anulat = 0 AND Coalesce(C2.Suspendat,0) = 0
      AND C.TipDoc = 34
      AND CASE WHEN vSubunit = 1 THEN C.SUBUNITATEA             ELSE vSubunit END = C.SUBUNITATEA
      AND CASE WHEN pAgent   = 0 THEN Coalesce(C.AGENT      ,0) ELSE pAgent   END = Coalesce(C.AGENT,0)
      AND CASE WHEN pTraseu  = 0 THEN Coalesce(AGC.CodTraseu,0) ELSE pTraseu  END = Coalesce(AGC.CodTraseu,0)
      AND CASE WHEN pClasa   = 0 THEN Coalesce(P.CODCLASA   ,0) ELSE pClasa   END = Coalesce(P.CODCLASA,0)
      AND CASE WHEN pLocalit = 0 THEN Coalesce(AG.CODLOCALIT,0) ELSE pLocalit END = Coalesce(AG.CODLOCALIT,0)
      AND (P.PERSOANAFIZICA = pPersoanaFizica OR pPersoanaFizica = -1);

    INSERT INTO TMP_GFA_CONTR1
    SELECT
      T.CodContract, C1.CodContract1, T.CodContract2, C1.CODOBIECT, C1.UMSEC, NULL Cant,
      C1.Pret * UM.Paritate Pret, C1.Pret * UM.Paritate * (1 + Coalesce(C1.AdDim/100,0)) PU, C1.ADDIM, C1.ProcDisc,
      A.CodArticol, CASE WHEN A.TipArticol = 0 THEN &apos;=&apos; ELSE &apos;S&apos; END TipLinie, A.TipArticol, A.ContServiciu, O.Denumire DenObiect, UM.Den_UM1 DenUm, UM.Paritate, GEST.CodGest, IOA.CodIOART,
      PKG_SELECTARTICOLE.GETPROCENTTVA(O.CodArticol, vAnLucru, vLunaLucru) ProcTVA,
      IOA1.Mg, IOA1.DifPret, IOA1.AreTVANeex, A.RELATIEUM1, A.RELATIEUM2, C1.ZileC, C1.Obs, O.TermenPlata ZilePlata, C1.CodCentru, C1.TipPret, C1.DataStart, C1.DataStop,
      T.SediuLivrare,
      C1.CodAuto, C1.Cant*Coalesce(xC1.Cant,1)/UM.Paritate CantContract, 0 NrAuxFact, T.Valoare ValRata, C1.CodAnalizaNod, T.Contr_SedLivr, AGC.Obs Contr_SLDen,
      LOCC.Den_Localit||&apos; &apos;||GetAdresa(AGC.SECTOR, AGC.STRADA, AGC.NR1, AGC.NR2, AGC.BLOC, AGC.SCARA, AGC.ETAJ, AGC.APART, NULL) Contr_SLAdr,
      T.Scadenta ContorDataRef, NULL ContorDataIni, NULL ContorIdxIni, NULL ContorDataFin, NULL ContorIdxFin, 
      C1.ParitateCredit,  U.Serief||&apos;/&apos;||UI.DENUMIRE
    FROM TMP_GFA_CONTR T
      INNER JOIN CONTRACT       C    ON C.CodContract   = T.CodContract
      INNER JOIN CONTRACT1      C1   ON C1.CodContract  = T.CodContract AND Coalesce(NULLIF(C1.SediuLivrare,0),C.CodLocatie,0) = Coalesce(T.Contr_SedLivr,0)
      INNER JOIN NARTOBJ        O    ON O.CodObiect     = C1.CodObiect
      INNER JOIN NART           A    ON A.CodArticol    = O.CodArticol
      INNER JOIN NUM1           UM   ON UM.CodUM1       = C1.UMSec
      LEFT  JOIN NAGENDA        AG   ON AG.CodAgenda    = T.SediuLivrare
      LEFT  JOIN NAGENDA        AGC  ON AGC.CodAgenda   = T.Contr_SedLivr
      LEFT  JOIN NLOCALIT       LOCC ON LOCC.CODLOCALIT = AGC.CODLOCALIT
      LEFT  JOIN NARTIMPLICITE  AI   ON AI.CodArticol   = A.CodArticol AND AI.CodSubunit = T.Subunitatea
      LEFT  JOIN NARTOBJIMP     OI   ON OI.CodOBIECT    = O.CodOBIECT AND OI.CodSubunit = T.Subunitatea
      LEFT  JOIN NGEST          GEST ON GEST.CodGest    = CASE WHEN A.TipArticol &lt;&gt; 0 THEN C1.GESTACT WHEN pGest  = 0 THEN AI.GestImplicita ELSE pGest  END
      LEFT  JOIN IOART          IOA  ON IOA.CodIOArt    = CASE
                                                            WHEN Coalesce(C1.CodIOArt,0) &lt;&gt; 0 THEN C1.CodIOArt
                                                            WHEN A.TipArticol &lt;&gt; 0 THEN 0
                                                            WHEN pIOART = 0 THEN CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.ContImplicit ELSE COALESCE(OI.CONTIMPLICIT,0) END
                                                            ELSE pIOART
                                                          END
      LEFT  JOIN IOART1         IOA1 ON IOA1.CodIOArt   = IOA.CodIOArt AND  vALLucru BETWEEN IOA1.ALStart AND IOA1.ALStop
      LEFT  JOIN CONTRACT1      xC1  ON xC1.CodContract = T.CodContract AND xC1.IndexLocal = C1.IndexParinte
      LEFT  JOIN UTILAJE         U   ON U.CodUtilaj = C1.Codutilaj
      LEFT  JOIN UTILAJETIPINDEX UI  ON UI.CODUTILAJ = C1.CODUTILAJ AND UI.TIP_INDEX = C1.UTILAJ_TIP_INDEX
    WHERE  Coalesce(C1.TipPret,0) &lt;&gt; 3;

    FOR vRec IN (SELECT DISTINCT CodContract1, ContorDataRef FROM TMP_GFA_CONTR1)
    LOOP
      setCantContor(vRec.CodContract1, vRec.ContorDataRef);
    END LOOP;

    UPDATE TMP_GFA_CONTR1 a
    SET (        Cant,               ContorDataIni, ContorIdxIni, ContorDataFin, ContorIdxFin) =
        ( SELECT b.Cant/ a.Paritate, b.DataIni,     b.IdxIni,     b.DataFin,     b.IdxFin
          FROM TMP_C1_CantContor b
          WHERE b.CodContract1 = a.CodContract1
            AND b.DataRef      = a.ContorDataRef
        );

    --DELETE FROM TMP_GFA_CONTR1  WHERE CANT = 0;
    DELETE FROM TMP_GFA_CONTR1  WHERE CANT = 0 OR PU = 0;
    DELETE FROM TMP_GFA_CONTR C WHERE NOT EXISTS (SELECT 1 FROM TMP_GFA_CONTR1 C1 WHERE C1.CODCONTRACT = C.CODCONTRACT);
  ELSE
    INSERT INTO TMP_GFA_CONTR1
    SELECT
      C2.CodContract, C1.CodContract1, C2.CodContract2, C1.CODOBIECT, C1.UMSEC, Pkg_Contract.getCantExtra(C1.CodContract1,C2.Data) / UM.Paritate Cant,
      C1.Pret * UM.Paritate Pret, C1.Pret * UM.Paritate * (1 + Coalesce(C1.AdDim/100,0)) PU, C1.ADDIM, C1.ProcDisc,
      A.CodArticol, CASE WHEN A.TipArticol = 0 THEN &apos;=&apos; ELSE &apos;S&apos; END TipLinie, A.TipArticol, A.ContServiciu, O.Denumire DenObiect, UM.Den_UM1 DenUm, UM.Paritate, GEST.CodGest, IOA.CodIOART,
      PKG_SELECTARTICOLE.GETPROCENTTVA(O.CodArticol, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) ProcTVA,
      IOA1.Mg, IOA1.DifPret , IOA1.AreTVANeex, A.RELATIEUM1, A.RELATIEUM2, C1.ZileC, C1.Obs, O.TermenPlata ZilePlata, C1.CodCentru, C1.TipPret, C1.DataStart, C1.DataStop,
      CASE WHEN Coalesce(C2.SediuLivrare, 0) = 0 THEN Coalesce(C.CodLocatie,0) ELSE Coalesce(C2.SediuLivrare, 0) END SediuLivrare,
      C1.CodAuto, C1.Cant*Coalesce(xC1.Cant,1)/UM.Paritate CantContract, 0 NrAuxFact, C2.Suma ValRata, C1.CodAnalizaNod, AGC.CodAgenda Contr_SedLivr, AGC.Obs Contr_SLDen,
      LOCC.Den_Localit||&apos; &apos;||GetAdresa(AGC.SECTOR, AGC.STRADA, AGC.NR1, AGC.NR2, AGC.BLOC, AGC.SCARA, AGC.ETAJ, AGC.APART, NULL) Contr_SLAdr,
      NULL ContorDataRef, NULL ContorDataIni, NULL ContorIdxIni, NULL ContorDataFin, NULL ContorIdxFin, 
      C1.ParitateCredit,  U.Serief||&apos;/&apos;||UI.DENUMIRE
    FROM CONTRACT2 C2
      INNER JOIN CONTRACT       C    ON C.CodContract   = C2.CodContract
      INNER JOIN NPART          P    ON P.CodPart       = C.Partener
      INNER JOIN CONTRACT1      C1   ON C1.CodContract  = C2.CodContract AND Coalesce(C1.SediuLivrare,0) = Coalesce(C2.SediuLivrare,0)
      INNER JOIN NARTOBJ        O    ON O.CodObiect     = C1.CodObiect
      INNER JOIN NART           A    ON A.CodArticol    = O.CodArticol
      INNER JOIN NUM1           UM   ON UM.CodUM1       = C1.UMSec
      LEFT  JOIN COMANDA        CE   ON CE.CodComanda   = C2.CodDocT AND CE.TipDoc = C2.TipDocT
      LEFT  JOIN NAGENDA        AGC  ON AGC.CodAgenda   = CASE WHEN Coalesce(C2.SediuLivrare, 0) = 0 THEN Coalesce(C.CodLocatie,0) ELSE Coalesce(C2.SediuLivrare, 0) END
      LEFT  JOIN NAGENDA        AG   ON AG.CodAgenda    = CASE WHEN pTipSediu = 1 THEN Coalesce(AGC.CodCoresp, AGC.CodAgenda) ELSE AGC.CodAgenda END
      LEFT  JOIN NLOCALIT       LOCC ON LOCC.CODLOCALIT = AGC.CODLOCALIT
      LEFT  JOIN NARTIMPLICITE  AI   ON AI.CodArticol   = A.CodArticol AND AI.CodSubunit = C.Subunitatea
      LEFT  JOIN NARTOBJIMP     OI   ON OI.CodOBIECT    = O.CodOBIECT AND OI.CodSubunit = C.Subunitatea
      LEFT  JOIN NGEST          GEST ON GEST.CodGest    = CASE WHEN A.TipArticol &lt;&gt; 0 THEN C1.GESTACT WHEN pGest  = 0 THEN AI.GestImplicita ELSE pGest  END
      LEFT  JOIN IOART          IOA  ON IOA.CodIOArt    = CASE
                                                            WHEN Coalesce(C1.CodIOArt,0) &lt;&gt; 0 THEN C1.CodIOArt
                                                            WHEN A.TipArticol &lt;&gt; 0 THEN 0
                                                            WHEN pIOART = 0 THEN CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.ContImplicit ELSE COALESCE(OI.CONTIMPLICIT,0) END
                                                            ELSE pIOART
                                                          END
      LEFT  JOIN IOART1         IOA1 ON IOA1.CodIOArt   = IOA.CodIOArt AND  vALLucru BETWEEN IOA1.ALStart AND IOA1.ALStop
      LEFT  JOIN CONTRACT1      xC1  ON xC1.CodContract = C1.CodContract AND xC1.IndexLocal = C1.IndexParinte
      LEFT  JOIN UTILAJE        U    ON U.CodUtilaj = C1.Codutilaj
      LEFT  JOIN UTILAJETIPINDEX UI  ON UI.CODUTILAJ = C1.CODUTILAJ AND UI.TIP_INDEX = C1.UTILAJ_TIP_INDEX
    WHERE CASE WHEN pTipDataRef = 0 THEN C2.DataStop ELSE C2.Data END = dDataRef
      AND ((CE.CodComanda IS NULL) OR (CE.DATADOC = dDataFact AND CE.OPERAT = 1 AND CE.ANULAT = 0))
      AND C.Activ = 1 AND C.Operat = 1 AND C.Anulat = 0 AND Coalesce(C2.Suspendat,0) = 0
      AND C.TipDoc = 34
      AND CASE WHEN vSubunit = 1 THEN C.SUBUNITATEA             ELSE vSubunit END = C.SUBUNITATEA
      AND CASE WHEN pAgent   = 0 THEN Coalesce(C.AGENT      ,0) ELSE pAgent   END = Coalesce(C.AGENT,0)
      AND CASE WHEN pTraseu  = 0 THEN Coalesce(AGC.CodTraseu,0) ELSE pTraseu  END = Coalesce(AGC.CodTraseu,0)
      AND CASE WHEN pClasa   = 0 THEN Coalesce(P.CODCLASA   ,0) ELSE pClasa   END = Coalesce(P.CODCLASA,0)
      AND CASE WHEN pLocalit = 0 THEN Coalesce(AG.CODLOCALIT,0) ELSE pLocalit END = Coalesce(AG.CODLOCALIT,0)
      AND Coalesce(C1.TipPret,0) = 3 AND (P.PERSOANAFIZICA = pPersoanaFizica OR pPersoanaFizica = -1);

    --DELETE FROM TMP_GFA_CONTR1 WHERE CANT = 0;
    DELETE FROM TMP_GFA_CONTR1 WHERE CANT = 0 OR PU = 0;

    INSERT INTO TMP_GFA_CONTR
    SELECT
      C2.CodContract, C2.CodContract2, C.NrDoc NrContr, C.Partener, C.Moneda, C.Agent, C2.Data Scadenta, C2.Suma Valoare, C.ProcMaj, CE.CodComanda CodDoc, CE.TipDoc, CE.CarnetDoc, CE.NrDoc, CE.SeriaDoc,
      P.Den_Part, MON.Simbol Simb_Mon, numeprenume(PAG.Nume,PAg.Prenume) Den_Agent, DECODE(CE.CodComanda, Null, 0, 1) Facturat, Coalesce(CE.Operat,0) Operat,
      C.CodLocatie, C.CodFiscal, C.Subunitatea, J.Den_Judet, LOC.Den_Localit, AG.Strada, AG.Nr1, C.FactLei, C.DataDoc DataContr,
      Coalesce((SELECT p1.scadentav FROM Npart1 P1 WHERE P1.CodPart = P.CodPart AND vALLucru BETWEEN P1.ALStart AND P1.ALStop),P.SCADENTAV ) SCADENTAV,
      C.Obs, C.CodPersC, C2.DataStop, C.DataStart DStart,C.DataStop DStop, T.SediuLivrare,
      CASE WHEN pObsNrContr &lt;&gt; 2 THEN &apos;*Contr &apos;||C.NrDoc||&apos;/&apos;||To_char(C.DataDoc,&apos;dd.mm.yyyy&apos;) END||&apos; *&apos;||PKG_CONTRACT.OBSLUNA(C.DataStart, C2.DataStop, C.PerFact)||&apos; &apos;||C.Obs ObsFact,
      B.CODBANK Banca, B.Denumire Den_Banca, 0 NrAuxFact, Coalesce(C.Curs,0) Curs, C.CodAnaliza, AG.OBS SediuLivrDen, TL.DENTRASEU, AG.POZTRASEU, T1.DENTRASEU, AG.POZTRASEU1,
      NULL DATASCADV, 0 ZILESCADV, C.PerFact, T.Contr_SedLivr, C.ProcMajCurs, C.Avans, C.ZiFact,
      getadresa(AG.sector, AG.strada, AG.nr1, AG.nr2, AG.bloc, AG.scara, AG.etaj, AG.apart, AG.codpostal), C.explicatii, C.Credite_Plafon, C.Credite_PU
    FROM (SELECT DISTINCT CODCONTRACT, CODCONTRACT2, SEDIULIVRARE, Contr_SedLivr  FROM TMP_GFA_CONTR1) T
      LEFT  JOIN CONTRACT2 C2  ON C2.CodContract2 = T.CodContract2
      LEFT  JOIN CONTRACT C    ON C.CodContract   = T.CodContract
      LEFT  JOIN NMONEDE  MON  ON MON.CodMoneda   = C.Moneda
      LEFT  JOIN NPART    P    ON P.CodPart       = C.Partener
      LEFT  JOIN NPERS    PAG  ON PAG.CodPers     = C.Agent
      LEFT  JOIN COMANDA  CE   ON CE.CodComanda   = C2.CodDocT AND CE.TipDoc = C2.TipDocT
      LEFT  JOIN NAGENDA  AG   ON AG.CodAgenda    = T.SediuLivrare
      LEFT  JOIN NAGENDA  AGC  ON AGC.CodAgenda   = T.Contr_SedLivr
      LEFT  JOIN NLOCALIT LOC  ON LOC.CODLOCALIT  = AG.CODLOCALIT
      LEFT  JOIN NLOCALIT LOCC ON LOCC.CODLOCALIT = AGC.CODLOCALIT
      LEFT  JOIN NJUDET   J    ON J.CODJUDET      = LOC.CODJUDET
      LEFT  JOIN NBANK    B    ON B.CODBANK       = CASE WHEN Coalesce(C.Moneda,0) = 0 THEN 0 WHEN Coalesce(C.CodBanca,0) = 0 THEN pBancaDef ELSE C.CodBanca END
      LEFT  JOIN TRASEULIVR TL ON TL.CODTRASEULIVR = AG.CodTraseu
      LEFT  JOIN TRASEULIVR T1 ON T1.CODTRASEULIVR = AG.CodTraseu1;
  END IF;

  COMMIT;
END;

FUNCTION getNrContrGestArt(aCodContract1 IN NUMBER) RETURN NUMBER IS
  vDataStart      DATE;
  vDataStop       DATE;
  vCodObiect      NUMBER;
  vGestAct        NUMBER;
  vNrContrGestArt NUMBER := 0;
BEGIN
  SELECT C1.CodObiect, Coalesce(C1.GestAct,0),  Coalesce(C1.DataStart,C.DataStart), Coalesce(C1.DataStop, C.DataStop)
  INTO   vCodObiect,   vGestAct,                vDataStart,                         vDataStop
  FROM Contract1 C1 INNER JOIN  Contract C ON c.codcontract = c1.codcontract
  WHERE C1.CodContract1 = aCodContract1;

  IF vGestAct &lt;&gt; 0 THEN
    SELECT Count(1) INTO vNrContrGestArt
    FROM Contract1 C1 INNER JOIN Contract C ON c.codcontract = c1.codcontract
    WHERE C1.CodObiect = vCodObiect
      AND C1.GestAct = vGestAct
      AND vDataStart &lt;= Coalesce(C1.DataStop, C.DataStop)
      AND vDataStop  &gt;= Coalesce(C1.DataStart,C.DataStart);
  END IF;
  RETURN vNrContrGestArt;
END;

procedure CheckRecoltaArenda(aCodContract in number,  An in number) is
 aTipDoc number;
 aTipContract number;
 Arenda boolean;
 nr number;
 AnPrec number;
 AnStart number;
 AnStop number;
 Ind number;
begin
	select count(*) into nr
	from contract1 c1
	inner join contract c on c.codcontract = c1.codcontract
	where c.tipdoc=10 and c.tipcontract=3 and Nvl(c1.Anexa,0) = 0;
	if nr &gt; 0 then
		for v_rec in ( select codcontract, Extract(Year from DataStart) AnStart  from contract where TipDoc = 10 and TipContract= 3) loop
			Update Contract1 set Anexa = v_rec.AnStart where CodContract = v_rec.CodContract and Nvl(Anexa,0) = 0;
		end loop;
		commit;
	end if;

	BEGIN
    select TipDoc, TipContract, Extract(Year from DataStart), Extract(Year from  DataStop) into aTipDoc, aTipContract, AnStart, AnStop from Contract where CodContract = aCodContract;
	  Arenda := aTipDoc = 10 and aTipContract= 3;
  EXCEPTION WHEN OTHERS THEN
    Arenda := False;
  END;
	if Arenda and (An between AnStart and AnStop) then
		select count(*) into nr from contract1 where CodContract = aCodContract and Anexa = An ;
		if nr = 0 then
			BEGIN
				select Max(Anexa) into AnPrec from contract1 where CodContract = aCodContract;
				select Max(IndexLocal) into Ind from contract1 where CodContract = aCodContract;
			EXCEPTION WHEN OTHERS THEN
				AnPrec := 0;
			END;
			if AnPrec &gt; 0 then
				for v_rec in (select distinct IndexLocal from contract1 where CodContract = aCodContract and Anexa = AnPrec)
				loop
          Ind := Ind + 1;
					INSERT INTO  Contract1 (
						CodContract1, CodContract, CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
						Anexa, DataStart, DataStop, Obs, GestAct, CodIOArt, TVA, VALTARGET,
						LIMITACADOU, CANTCADOU,
						cantglobal, DataLivr, Stare, pretstandard,
						CODCADOU, CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipObiect, TipDiscount, SEDIULIVRARE,
						TIPDISCOUNTT, TipDiscountC, SumaFixa, TIPDISCOUNTT1, CodClasa,
						DiscTCumulat, DiscT, CodContr1Cadru, CodCentru,Indexlocal, CODUTILAJ, UTILAJ_TIP_INDEX, PLAFONCANTF, CODANALIZANOD, CODAUTO)
					SELECT
						seq_Contract1_CodContract1.NEXTVAL , CodContract, CodObiect, UMSec, Cant, Pret, ProcDisc, AdDim, CANTOPTIM, ZileL, ZileC, Lansare,
						AN, DataStart, DataStop, Obs, GestAct, CodIOArt, TVA, VALTARGET,
						LIMITACADOU, CANTCADOU,
						CantGlobal, DataLivr, Stare, pretstandard,
						CODCADOU, CODOBIECTSEC, LIMITACADOUSEC, TERMENFIX, TIPPRET, TipObiect,TipDiscount, SEDIULIVRARE,
						TipdiscountT, TipdiscountC, SumaFixa, TipdiscountT1, CodClasa,
						DiscTCumulat, DiscT, CodContr1Cadru, CodCentru, Ind, CODUTILAJ, UTILAJ_TIP_INDEX, PLAFONCANTF, CODANALIZANOD, CODAUTO
          FROM contract1
          WHERE CodContract = aCodContract and Anexa = AnPrec and IndexLocal = v_rec.Indexlocal;
        end loop;
      end if;
    end if;
  end if;
end;

END PKG_CONTRACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONTREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A1D73C4AC51670448A7D6320DB5A8D5A18145F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONTREP IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCONTREP INTO Tmp FROM NCONTREP WHERE CodContRep = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCODCONT NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
	SELECT CODCONT INTO aCODCONT FROM NCONTREP WHERE CODCONTREP = RECID;
  DELETE FROM NCONTREP  WHERE CODCONTREP = RECID;
  DELETE FROM NCONTREPSOLD WHERE CODPARINTE = aCODCONT;
  DELETE FROM NCONTREPRUL  WHERE CODPARINTE = aCODCONT;

  NotifyModif(2, RecId, &apos;NCONTREP&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCONTREP FIELDS( CODCONTREP ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aINDEX  NUMBER(10) := 0;
  NR      NUMBER(10) := 0;
BEGIN
-- Master NCONT
  INSERT INTO TMP_NCONTREP ( CODCONTREP, CODCONT, SIMBOL)
    ( SELECT NC.CODCONTREP, NC.CODCONT, C.SIMBOL  
      FROM NCONTREP NC
           LEFT JOIN NCONT C ON NC.CODCONT = C.CODCONT
      WHERE NC.CODCONTREP = RecId) ;

      
-- Detail NCONTSOLD
  INSERT INTO TMP_NCONTSOLD (CodContSold, SoldID, SoldIC, SoldVID, SoldVIC, SOLDI_IFRS, SOLDVI_IFRS,  CodCont, An, Luna )
    ( SELECT CodContSold, SoldID, SoldIC, SoldVID, SoldVIC,  SOLDI_IFRS, SOLDVI_IFRS, CodCont, An, Luna FROM NCONTSOLD WHERE CodCont IN (SELECT CODCONT FROM TMP_NCONTREP) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1 );


-- Detail NCONTRUL
  INSERT INTO TMP_NCONTRUL ( CodContRul,RulajPD,RulajPC,CodCont,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, RULAJP_IFRS,  RULAJVP_IFRS, An, Luna )
    (SELECT CodContRul,RulajPD,RulajPC,CodCont,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC,  RULAJP_IFRS,  RULAJVP_IFRS, An, Luna
     FROM NCONTRUL WHERE CodCont IN (SELECT CODCONT FROM TMP_NCONTREP) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU );
      
     
-- Detail NCONTREPSOLD
  INSERT INTO TMP_NCONTREPSOLD(CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SIMBOL)
     (SELECT * FROM
       (SELECT S.CODCONTREPSOLD, S.CODCONT, S.CODPARINTE, S.SOLDID, S.SOLDIC, S.SOLDVID, S.SOLDVIC, S.SOLDI_IFRS, S.SOLDVI_IFRS, C.SIMBOL 
        FROM NCONTREPSOLD S
             LEFT JOIN NCONT C ON C.CODCONT = S.CODCONT
        WHERE 
        S.CODPARINTE IN (SELECT CODCONT FROM TMP_NCONTREP)
       )
     ) ORDER BY SIMBOL;  


-- Detail NCONTREPRUL
  INSERT INTO TMP_NCONTREPRUL(CODCONTREPRUL, CODCONT, CODPARINTE, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS, SIMBOL)
    (SELECT * FROM
      (SELECT R.CODCONTREPRUL, R.CODCONT, R.CODPARINTE, R.RULAJPD, R.RULAJPC, R.RULAJVPD, R.RULAJVPC,  R.RULAJP_IFRS, R.RULAJVP_IFRS, C.SIMBOL
       FROM NCONTREPRUL R
            LEFT JOIN NCONT C ON C.CODCONT = R.CODCONT
       WHERE R.CODPARINTE IN (SELECT CODCONT FROM TMP_NCONTREP))
     ) ORDER BY SIMBOL;  




-- Detail NCONTRepRulSub
  INSERT INTO TMP_NCONTREPRULSUB (CODREPRULSUB, CODCONTREPRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,  RULAJP_IFRS, RULAJVP_IFRS, DENSUBUNIT)
  SELECT CODREPRULSUB, CODCONTREPRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS, S.DEN_SUBUNIT 
  FROM 
   NCONTREPRULSUB R,
   NSUBUNIT S
  WHERE 
  EXISTS (SELECT CODCONTREPRUL FROM TMP_NCONTREPRUL WHERE CODCONTREPRUL = R.CODCONTREPRUL)
  AND S.CODSUBUNIT = R.SUBUNITATEA;

-- Detail NCONTRepSoldSub
  INSERT INTO TMP_NCONTREPSOLDSUB (CODREPSOLDSUB, CODCONTREPSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, DENSUBUNIT)
  SELECT CODREPSOLDSUB, CODCONTREPSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, S.DEN_SUBUNIT 
  FROM 
   NCONTREPSOLDSUB R,
   NSUBUNIT S
  WHERE 
  EXISTS (SELECT CODCONTREPSOLD FROM TMP_NCONTREPSOLD WHERE CODCONTREPSOLD = R.CODCONTREPSOLD)
  AND S.CODSUBUNIT = R.SUBUNITATEA;



  DELETE TMP_NCONT_LUNA_1;
  PKG_INCHIDERI.MAKE_NCONT_LUNA(&apos;TMP_NCONT_LUNA_1&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    
  UPDATE TMP_NCONTREPRUL T
  SET ACTIV = (SELECT CODCONT FROM TMP_NCONT_LUNA_1 WHERE CODCONT = T.CODCONT);     

  UPDATE TMP_NCONTREPSOLD T
  SET ACTIV = (SELECT CODCONT FROM TMP_NCONT_LUNA_1 WHERE CODCONT = T.CODCONT);     


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
   NR NUMBER(10) := 0;
 aCOD NUMBER(20) := 0;
BEGIN
  IF Operation = 0 THEN  -- UPDATE
-- Master NCONTREP
    SELECT  CODCONTREP INTO RecId FROM TMP_NCONTREP;
    
-- DETAIL NCONTREPSOLD
-- actualizez si SOLDUL INITIAL AL ANALITICULUI
    FOR V_REC IN (SELECT * FROM TMP_NCONTREPSOLD) LOOP
      IF V_REC.CODCONTREPSOLD &lt; 0 THEN

        SELECT SEQ_NCONTREPSOLD_CODCONTREPS.NEXTVAL INTO aCOD FROM DUAL;

        UPDATE TMP_NCONTREPSOLDSUB
        SET
          CODCONTREPSOLD = aCOD
        WHERE
          CODCONTREPSOLD = V_REC.CODCONTREPSOLD;
          
        INSERT INTO NCONTREPSOLD (CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS) 
        VALUES (aCOD, V_REC.CODCONT,  V_REC.CODPARINTE,  V_REC.SOLDID,  V_REC.SOLDIC,  V_REC.SOLDVID, V_REC.SOLDVIC, V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS);

        INSERT INTO NCONTSOLD(CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, AN, LUNA)
        VALUES (SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, V_REC.CODCONT, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC, V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS, PKG_GLOBALS.ANLUCRU, 1);
      ELSE
 
        -- masuri de prevedere suplimentare 
        SELECT COUNT(*) INTO NR FROM NCONTSOLD WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1; 
        IF NR = 0 THEN 
          INSERT INTO NCONTSOLD(CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS,  AN, LUNA)
          VALUES (SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, V_REC.CODCONT, 0, 0, 0, 0, 0, 0,  PKG_GLOBALS.ANLUCRU, 1);
        END IF;

        UPDATE NCONTSOLD
        SET
          SOLDID      = V_REC.SOLDID,  
          SOLDIC      = V_REC.SOLDIC,  
          SOLDVID     = V_REC.SOLDVID,  
          SOLDVIC     = V_REC.SOLDVIC,  
          SOLDI_IFRS  = V_REC.SOLDI_IFRS,
          SOLDVI_IFRS = V_REC.SOLDVI_IFRS
        WHERE
          CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;



      --  NCONTREPSOLD
       -- masuri de prevedere suplimentare 
        SELECT COUNT(*) INTO NR FROM NCONTREPSOLD WHERE CODCONT = V_REC.CODCONT; 
        IF NR = 0 THEN 
          INSERT INTO NCONTREPSOLD(CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS)
          VALUES (SEQ_NCONTREPSOLD_CODCONTREPS.NEXTVAL, V_REC.CODCONT, V_REC.CODPARINTE, 0, 0, 0, 0, 0, 0);
        END IF;

        UPDATE NCONTREPSOLD
        SET
          SOLDID      = V_REC.SOLDID,  
          SOLDIC      = V_REC.SOLDIC,  
          SOLDVID     = V_REC.SOLDVID,  
          SOLDVIC     = V_REC.SOLDVIC,
          SOLDI_IFRS  = V_REC.SOLDI_IFRS,  
          SOLDVI_IFRS = V_REC.SOLDVI_IFRS
        WHERE
          CODCONT = V_REC.CODCONT;
      END IF;       
    END LOOP;
    
    

-- DETAIL NCONTREPRUL
-- actualizez si RULAJELE ANALITICULUI
    FOR V_REC IN (SELECT * FROM TMP_NCONTREPRUL) LOOP
    IF V_REC.CODCONTREPRUL &lt; 0 THEN
    
      SELECT SEQ_NCONTREPRUL_CODCONTREPRUL.NEXTVAL INTO aCOD FROM DUAL;
      UPDATE TMP_NCONTREPRULSUB
      SET
       CODCONTREPRUL = aCOD
      WHERE
       CODCONTREPRUL = V_REC.CODCONTREPRUL; 
      
    
      INSERT INTO NCONTREPRUL (CODCONTREPRUL, CODCONT, CODPARINTE, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS) 
      VALUES (aCOD, V_REC.CODCONT, V_REC.CODPARINTE, V_REC.RULAJPD, V_REC.RULAJPC, V_REC.RULAJVPD, V_REC.RULAJVPC, V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS);

      INSERT INTO NCONTRUL   (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJVP_IFRS,   RULAJC_IFRS, RULAJVC_IFRS, AN, LUNA) 
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT, V_REC.RULAJPD, V_REC.RULAJPC, 0, 0, V_REC.RULAJVPD, V_REC.RULAJVPC, 0, 0, V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);


    ELSE


      SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU; 

      IF NR = 0 THEN 
        INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJCD, RULAJCC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS, AN, LUNA) 
        VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL,  V_REC.CODCONT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
      END IF;

      UPDATE NCONTRUL
      SET
        RULAJPD  = V_REC.RULAJPD, 
        RULAJPC  = V_REC.RULAJPC, 
        RULAJVPD = V_REC.RULAJVPD, 
        RULAJVPC = V_REC.RULAJVPC,
        RULAJP_IFRS = V_REC.RULAJP_IFRS,
        RULAJVP_IFRS = V_REC.RULAJVP_IFRS
      WHERE
        CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;



    --  NCONTREPRUL
      SELECT COUNT(*) INTO NR FROM NCONTREPRUL WHERE CODCONT = V_REC.CODCONT; 
      IF NR = 0 THEN 
        INSERT INTO NCONTREPRUL (CODCONTREPRUL, CODCONT, CODPARINTE, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS) 
        VALUES (SEQ_NCONTREPRUL_CODCONTREPRUL.NEXTVAL, V_REC.CODCONT, V_REC.CODPARINTE, 0, 0, 0, 0, 0, 0);
      END IF;

      UPDATE NCONTREPRUL
      SET
        RULAJPD      = V_REC.RULAJPD, 
        RULAJPC      = V_REC.RULAJPC, 
        RULAJVPD     = V_REC.RULAJVPD, 
        RULAJVPC     = V_REC.RULAJVPC,
        RULAJP_IFRS  = V_REC.RULAJP_IFRS,
        RULAJVP_IFRS = V_REC.RULAJVP_IFRS
      WHERE
        CODCONT = V_REC.CODCONT;

    END IF;       
    END LOOP;


   FOR V_REC IN (SELECT * FROM TMP_NCONTREPSOLDSUB)
   LOOP
     IF V_REC.CODREPSOLDSUB &lt; 0 THEN
       INSERT INTO NCONTREPSOLDSUB(CODREPSOLDSUB, CODCONTREPSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS)
        VALUES (SEQ_NCONTREPSOLDSUB_COD.NEXTVAL, V_REC.CODCONTREPSOLD, V_REC.SUBUNITATEA, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC, V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS);
     ELSE
       UPDATE NCONTREPSOLDSUB
       SET
         SOLDID      = V_REC.SOLDID,
         SOLDIC      = V_REC.SOLDIC,
         SOLDVID     = V_REC.SOLDVID,
         SOLDVIC     = V_REC.SOLDVIC,
         SOLDI_IFRS  = V_REC.SOLDI_IFRS,
         SOLDVI_IFRS = V_REC.SOLDVI_IFRS
       WHERE
         CODREPSOLDSUB = V_REC.CODREPSOLDSUB;
     END IF;
   END LOOP;



   FOR V_REC IN (SELECT * FROM TMP_NCONTREPRULSUB)
   LOOP
     IF V_REC.CODREPRULSUB &lt; 0 THEN
       INSERT INTO NCONTREPRULSUB(CODREPRULSUB, CODCONTREPRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS)
        VALUES (SEQ_NCONTREPRULSUB_COD.NEXTVAL, V_REC.CODCONTREPRUL, V_REC.SUBUNITATEA, V_REC.RULAJPD, V_REC.RULAJPC, V_REC.RULAJVPD, V_REC.RULAJVPC, V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS);
     ELSE
       UPDATE NCONTREPRULSUB
       SET
         RULAJPD      = V_REC.RULAJPD,
         RULAJPC      = V_REC.RULAJPC,
         RULAJVPD     = V_REC.RULAJVPD,
         RULAJVPC     = V_REC.RULAJVPC,
         RULAJP_IFRS  = V_REC.RULAJP_IFRS, 
         RULAJVP_IFRS = V_REC.RULAJVP_IFRS
       WHERE
         CODREPRULSUB = V_REC.CODREPRULSUB;
     END IF;
   END LOOP;


  ELSE -- INSERT

-- MASTER NCONTREP

    SELECT SEQ_NCONTREP_CODCONTREP.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO NCONTREP (CODCONTREP, CODCONT) (SELECT RECID, CODCONT FROM TMP_NCONTREP);

-- DETAIL NCONTREPSOLD
   FOR V_REC IN (SELECT * FROM TMP_NCONTREPSOLD)
   LOOP
     SELECT SEQ_NCONTREPSOLD_CODCONTREPS.NEXTVAL INTO aCOD FROM DUAL;
     UPDATE TMP_NCONTREPSOLDSUB
     SET
       CODCONTREPSOLD = aCOD
      WHERE
        CODCONTREPSOLD = V_REC.CODCONTREPSOLD;

      INSERT INTO NCONTREPSOLD (CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS) 
      VALUES (aCOD, V_REC.CODCONT, V_REC.CODPARINTE, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC,  V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS);
   END LOOP;


    INSERT INTO NCONTSOLD(CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, AN, LUNA)
    (SELECT SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS,  PKG_GLOBALS.ANLUCRU, 1 FROM TMP_NCONTREPSOLD);

-- DETAIL NCONTREPRUL
    FOR V_REC IN (SELECT * FROM TMP_NCONTREPRUL)
    LOOP
      SELECT SEQ_NCONTREPRUL_CODCONTREPRUL.NEXTVAL INTO aCOD FROM DUAL;
      
      UPDATE TMP_NCONTREPRULSUB
      SET
       CODCONTREPRUL = aCOD
      WHERE
       CODCONTREPRUL = V_REC.CODCONTREPRUL;
       
      INSERT INTO NCONTREPRUL (CODCONTREPRUL, CODCONT, CODPARINTE, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS) 
                        VALUES(aCOD, V_REC.CODCONT, V_REC.CODPARINTE, V_REC.RULAJPD, V_REC.RULAJPC, V_REC.RULAJVPD, V_REC.RULAJVPC, V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS);

    END LOOP;
    
    
    
-- DETAIL NCONTREPSOLDSUB
    INSERT INTO NCONTREPSOLDSUB(CODREPSOLDSUB, CODCONTREPSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS)
    SELECT SEQ_NCONTREPSOLDSUB_COD.NEXTVAL, CODCONTREPSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,  SOLDI_IFRS, SOLDVI_IFRS FROM TMP_NCONTREPSOLDSUB;


-- DETAIL NCONTREPRULSUB
    INSERT INTO NCONTREPRULSUB(CODREPRULSUB, CODCONTREPRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS)
    SELECT SEQ_NCONTREPRULSUB_COD.NEXTVAL, CODCONTREPRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,  RULAJP_IFRS, RULAJVP_IFRS FROM TMP_NCONTREPRULSUB;


    INSERT INTO NCONTRUL   (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJVP_IFRS,  RULAJC_IFRS, RULAJVC_IFRS, AN, LUNA) 
    (SELECT SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, CODCONT, RULAJPD, RULAJPC, 0, 0, RULAJVPD, RULAJVPC, 0, 0, RULAJP_IFRS, RULAJVP_IFRS, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU FROM TMP_NCONTREPRUL);
    
  END IF;

  
  -- am updatat NCONTSOLD si NCONTRUL
  -- updatez detaliile la nivel de subunitati
  
   FOR V_REC IN
   (
   SELECT 
     RUL.CODCONTRUL,
     REPRULSUB.* 
   FROM
     NCONTREP REP,
     NCONTREPRUL REPRUL,
     NCONTREPRULSUB REPRULSUB,
     NCONTRUL RUL
   WHERE
    REP.CODCONTREP = RECID
    AND REPRUL.CODPARINTE = REP.CODCONT
    AND RUL.AN = PKG_GLOBALS.ANLUCRU
    AND RUL.LUNA = PKG_GLOBALS.LUNALUCRU
    AND RUL.CODCONT = REPRUL.CODCONT
    AND REPRULSUB.CODCONTREPRUL = REPRUL.CODCONTREPRUL
   )
   LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;
       UPDATE NCONTRULSUB
       SET
         RULAJPD      = V_REC.RULAJPD,
         RULAJPC      = V_REC.RULAJPC, 
         RULAJVPD     = V_REC.RULAJVPD,
         RULAJVPC     = V_REC.RULAJVPC,
         RULAJP_IFRS  = V_REC.RULAJP_IFRS, 
         RULAJVP_IFRS = V_REC.RULAJVP_IFRS
       WHERE
         CODCONTRUL = V_REC.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
   END LOOP;
 

   FOR V_REC IN
   (
   SELECT 
     SOLD.CODCONTSOLD,
     REPSOLDSUB.* 
   FROM
     NCONTREP REP,
     NCONTREPSOLD REPSOLD,
     NCONTREPSOLDSUB REPSOLDSUB,
     NCONTSOLD SOLD
   WHERE
    REP.CODCONTREP = RECID
    AND REPSOLD.CODPARINTE = REP.CODCONT
    AND SOLD.AN = PKG_GLOBALS.ANLUCRU
    AND SOLD.LUNA = 1
    AND SOLD.CODCONT = REPSOLD.CODCONT
    AND REPSOLDSUB.CODCONTREPSOLD = REPSOLD.CODCONTREPSOLD
   )
   LOOP
       SELECT COUNT(*) INTO NR FROM NCONTSOLDSUB WHERE CODCONTSOLD = V_REC.CODCONTSOLD AND SUBUNITATEA = V_REC.SUBUNITATEA;
       IF NR = 0 THEN
         INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SUBUNITATEA)
         VALUES
         (SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC.CODCONTSOLD,  0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTSOLDSUB
       SET
         SOLDID      = V_REC.SOLDID,
         SOLDIC      = V_REC.SOLDIC, 
         SOLDVID     = V_REC.SOLDVID,
         SOLDVIC     = V_REC.SOLDVIC, 
         SOLDI_IFRS  = V_REC.SOLDI_IFRS,
         SOLDVI_IFRS = V_REC.SOLDVI_IFRS
       WHERE
         CODCONTSOLD = V_REC.CODCONTSOLD AND SUBUNITATEA = V_REC.SUBUNITATEA;

   END LOOP;
 
  NotifyModif(Operation, RecId, &apos;NCONTREP&apos;);
  
  COMMIT;
END;  
END PKG_CONTREP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONTURIBANCI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAD6E97DE43467591981676DF8329FEC43DF9E4D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONTURIBANCI IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

PROCEDURE STERGE_TREZOR_DIN_SOLDBANCA(aCODBANKCONT NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN
  (
  SELECT T1.CODTREZOR, COUNT(*) AS NR FROM
    TREZOR T,
    TREZOR1 T1
  WHERE
    T1.INITIALIZARI = 1
    AND T1.CODTREZOR = T.CODTREZOR
    AND CODBANCA = aCODBANKCONT
    AND (SELECT COUNT(*) FROM GENERAL WHERE TIPDOC IN (29, 30, 31) AND CODDOC = T1.CODTREZOR1) = 0
  GROUP BY T1.CODTREZOR
  HAVING COUNT(*) = 1
 )
 LOOP
   DELETE FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR;
   DELETE FROM TREZOR  WHERE CODTREZOR = V_REC.CODTREZOR;
   COMMIT;
 END LOOP;
END;

PROCEDURE MAKE_CURS_BANKCONT_LUNA(aDATA IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_CURS_BANKCONT_LUNA;
  INSERT INTO TMP_CURS_BANKCONT_LUNA (CODBANKCONT, CURS)
  SELECT R1.CODBANKCONT, R.CURS
  FROM REG R, REGTREZOR1 R1
  WHERE R.TIPREG = 45
    AND R.DATADOC = (SELECT MAX(DATADOC) FROM REG R2
                     WHERE R2.TIPREG = 45 AND R2.CODMONEDA = R.CODMONEDA
                           AND R2.DATADOC &lt;= TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;) )
    AND R1.CODREG = R.CODREG;
END;

FUNCTION GET_O_CASA_IN_MONEDA(aMONEDA IN NUMBER) RETURN NUMBER IS
aCASA NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT MAX(CODBANKCONT) INTO aCASA FROM NBANKCONT WHERE CODBANK = 1 AND CODMONEDA = aMONEDA;
    EXCEPTION WHEN OTHERS THEN aCASA := 0;
  END;
  RETURN aCASA;
END;

FUNCTION GET_O_BANCA_IN_MONEDA(aMONEDA IN NUMBER) RETURN NUMBER IS
  oBANCA NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT MAX(CODBANKCONT) INTO oBANCA FROM NBANKCONT WHERE CODBANK &lt;&gt; 1 AND CODMONEDA = aMONEDA;
    EXCEPTION WHEN OTHERS THEN oBANCA := 0;
  END;
  RETURN oBANCA;
END;

PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER)
IS
BEGIN
  INITIALIZARI := FLAG;
END;

PROCEDURE SETBANCACURENTA(aCODBANCA IN NUMBER)
IS BEGIN
  BANCACURENTA := aCodBanca;
END;

FUNCTION GETBANCACURENTA RETURN NUMBER
IS
BEGIN
  RETURN BANCACURENTA;
END;

PROCEDURE SETCONTBANCACURENT(aCONTBANCA IN NUMBER)
IS BEGIN
  CONTBANCACURENT := aCONTBANCA;
END;

FUNCTION GETCONTBANCACURENT RETURN NUMBER
IS
BEGIN
  RETURN CONTBANCACURENT;
END;


FUNCTION GET_COD_NBANKCONT1(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER
IS
  CBANKCONT1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT NVL(CodBankCont1, 0) INTO CBANKCONT1 FROM NBANKCONT1 n1
    WHERE n1.CodBAnkCont = aCodBankCont AND aAn * 12 + aLuna BETWEEN n1.ALStart AND n1.ALStop;
  EXCEPTION WHEN OTHERS then CBANKCONT1 := -1;
  END;
  RETURN CBANKCONT1;
END;

FUNCTION GET_BANKCONT_COD_CARACT_LUNA(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER
IS
  aCODIoBank  Number(20)  := -1;
  aCODIoBank1 Number(20)  := -1;
BEGIN
  BEGIN
    SELECT NVL(CodIoBanca, 0) INTO aCodIoBank FROM NBankCont1 n1
    WHERE n1.CodBankCont = aCodBankCont AND aAn * 12 + aLuna BETWEEN n1.ALStart AND n1.ALStop;
  EXCEPTION WHEN OTHERS THEN aCodIoBank1 := -1;
  END;

  IF aCODIOBank &gt; 0 THEN
    BEGIN
      SELECT NVL(CodIoBank1, 0) INTO aCodIoBank1 FROM IoBank1 i1
      WHERE i1.CodIoBanK = aCodIoBank AND aAn * 12 + aLuna BETWEEN i1.ALStart AND i1.ALStop;
    EXCEPTION WHEN OTHERS then aCodIoBank1 := -1;
    END;
  END IF;
  RETURN aCODIoBank1;
END;

FUNCTION GET_RECORD_COD_CARACT_LUNA(aCodBankCont in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN  DESCR_CONT_LUNA_CURSOR
IS
  TMPCURSOR DESCR_CONT_LUNA_CURSOR;
  aCODIoBank  Number(20)  := -1;
BEGIN
  BEGIN
    SELECT NVL(CodIoBanca, 0) INTO aCodIoBank FROM NBankCont1 n1
    WHERE n1.CodBankCont = aCodBankCont AND aAn * 12 + aLuna BETWEEN n1.ALStart AND n1.ALStop;
  EXCEPTION WHEN OTHERS THEN aCODIOBANK := 0;
  END;

  IF aCODIOBank &gt; 0 THEN
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT *
      FROM IoBank1 i1
      WHERE i1.CodIoBanK = aCodIoBank AND aAn * 12 + aLuna BETWEEN i1.ALStart AND i1.ALStop;
    EXCEPTION WHEN OTHERS THEN OPEN tmpCursor FOR SELECT * FROM IOBANK1 WHERE 1=2;
    END;
  ELSE
    OPEN tmpCursor FOR SELECT * FROM IOBANK1 WHERE 1=2;
  END IF;
  RETURN TMPCURSOR;
END;


PROCEDURE SETCONT_SURSA_VIRAMENT(aCONT IN NUMBER)
IS
BEGIN
  CONT_SURSA_VIRAMENT := aCont;
END;

FUNCTION GETCONT_SURSA_VIRAMENT RETURN NUMBER
IS
BEGIN
  RETURN  CONT_SURSA_VIRAMENT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodBankCont INTO Tmp FROM NBANKCONT WHERE CodBankCont = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(100);
aSubunitate number(20);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;cont bancar &apos;||N.DEN_CONT||&apos;/&apos;||N.NRCONT,N.SUBUNITATEA INTO aDoc, aSubunitate
   FROM NBANKCONT n where N.CODBANKCONT = RECID;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANKCONT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     aSubunitate, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
   -- nomCasaBanca --&gt; 519;
   PKG_CFGTABLES.EXT_DELETERECORD (recId, 519);
	 DELETE FROM NBANKCONT1 WHERE CodBankCont = RecId ;
	 DELETE FROM NBANKSOLDLUNA WHERE CodBankCont = RecId ;
	 DELETE FROM NBANKCONT WHERE CodBankCont = RecId ;
  NotifyModif(2, RecId, &apos;NBANKCONT&apos;);
  COMMIT;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NBANKCONT FIELDS( CodBankCont ) VALUES (0) ;
  -- nomCasaBanca --&gt; 519
  PKG_CFGTABLES.EXT_INSERTRECORD(519);  
  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
ANPREC   NUMBER(5);
LUNAPREC NUMBER(2);
aANSFARSIT   NUMBER(4);
aLUNASFARSIT NUMBER(2);
aCURS        NUMBER(20, 7);

BEGIN
-- Master NBANKCONT
  INSERT INTO  TMP_NBANKCONT ( DataDeskis,DataInkis,CodBankCont,CodBank,Den_cont,CodLocalitate,NrCont,
                               CodMoneda,Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine )
    ( SELECT DataDeskis,DataInkis,CodBankCont,CodBank,Den_cont,CodLocalitate,NrCont,
                               CodMoneda,Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine
      FROM NBANKCONT WHERE CodBankCont = RecId ) ;

-- Detail NAGENDA
  INSERT INTO  TMP_NAGENDA (
    CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, LONGITUDINE, LATITUDINE, Obs2,
    ADRESA )
  SELECT
    CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT,CODPART,CODGEST,CODSUBUNIT, LONGITUDINE, LATITUDINE, Obs2,
    GETADRESA(SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL)
  FROM NAGENDA WHERE codbankcont = RecId ;

-- Detail NBANKCONT1
  INSERT INTO  TMP_NBANKCONT1 ( CODBANKCONT1,CODBANKCONT,CODIOBANCA,ANSTART,LUNASTART )
    ( SELECT CODBANKCONT1,CODBANKCONT,CODIOBANCA,ANSTART,LUNASTART
      FROM NBANKCONT1 WHERE CODBANKCONT = RecId);


  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODBANKCONT1, ANSTART, LUNASTART FROM TMP_NBANKCONT1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NBANKCONT1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODBANKCONT1 = V_REC.CODBANKCONT1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;


-- Detail NBANKSOLDLUNA

  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

  IF INITIALIZARI = 1 THEN
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANPREC, LUNAPREC);

    -- SUNT PE INITIALIZARI PREIAU SOLDUL LUNII ANTERIOARE CELEI INITIALE(CARE CONTINE SOLDUL INITIAL AL CONTULUI)
    INSERT INTO  TMP_NBANKSOLDLUNA ( CODBANKCONT, CODBANKSOLDLUNA, SOLDLEI, SOLDVALUTA, AN, LUNA, REGULARIZARE )
       ( SELECT CODBANKCONT, CODBANKSOLDLUNA, SOLDLEI, SOLDVALUTA, AN, LUNA, 0 FROM NBANKSOLDLUNA
         WHERE
           CODBANKCONT = RecId AND
           AN * 12 + LUNA = ANPREC * 12 + LUNAPREC
        );

    FOR V_REC IN (SELECT * FROM TMP_NBANKSOLDLUNA)
    LOOP
      BEGIN
      SELECT NVL(R.CURS, 0) INTO aCURS
      FROM
        REG R,
        REGTREZOR1 R1
      WHERE
        R.AN = ANPREC AND R.LUNA = LUNAPREC AND R.TIPREG = 45
        AND R.CODREG = R1.CODREG AND R1.CODBANKCONT = V_REC.CODBANKCONT;

       EXCEPTION WHEN OTHERS THEN aCURS := 0;
      END;

     IF aCURS &lt;&gt; 0 THEN
       UPDATE TMP_NBANKSOLDLUNA
       SET
         REGULARIZARE = 1,
         CURS         = aCURS
       WHERE
        CODBANKCONT = V_REC.CODBANKCONT;
     END IF;

    END LOOP;


  ELSE
    -- preiau soldurile din lunile diferite de cea curenta
      INSERT INTO  TMP_NBANKSOLDLUNA ( CODBANKCONT, CODBANKSOLDLUNA, SOLDLEI, SOLDVALUTA, AN, LUNA )
        ( SELECT CODBANKCONT, CODBANKSOLDLUNA, SOLDLEI, SOLDVALUTA, AN, LUNA FROM NBANKSOLDLUNA
          WHERE
          CODBANKCONT = RecId AND
          AN * 12 + LUNA &lt;&gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
        );

    -- inserez si soldul lunii curente (calculat dinamic)
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);
      PKG_CONTURIBANCI.SETCONTBANCACURENT(RecID);
      INSERT INTO TMP_NBANKSOLDLUNA ( CODBANKCONT, CODBANKSOLDLUNA, SOLDLEI, SOLDVALUTA, AN, LUNA )
        ( SELECT CODBANKCONT, 1, SOLDLEI, SOLDVALUTA, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU  FROM V_SOLDBANKLUNA
        );
  END IF;

-- Detail NPERSCONTACT
  INSERT INTO  TMP_NPERSCONTACT ( CODPERSC,NUME,PRENUME,TELEFON,EMAIL,FUNCTIE,DATANASTERE,RZONA,ID,TIP,CODBANKCONT,CODPART )
    ( SELECT CODPERSC,NUME,PRENUME,TELEFON,EMAIL,FUNCTIE,DATANASTERE,RZONA,ID,TIP,CODBANKCONT,CODPART
      FROM NPERSCONTACT WHERE codbankcont = RecId  ) ;



  -- nomCasaBanca --&gt; 519;
  PKG_CFGTABLES.EXT_GOTORECORD(519);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo     INTEGER := 0;
  vAn        INTEGER := 0;
  vLuna      INTEGER := 0;
  ANPREC     NUMBER(5);
  LUNAPREC   NUMBER(2);
  aCODMONEDA NUMBER(20);
  aCODBANK   NUMBER(20);
  aCODTREZOR NUMBER(20);
  aCODTREZOR1 NUMBER(20);
  aCODREG     NUMBER(20);
  aCURS       NUMBER(20, 7);
  NR          NUMBER(10) := 0;

aDoc varchar2(100);
aSubunitate number(20);

BEGIN
  -- nomCasaBanca --&gt; 519;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (519); 
  
  UPDATE TMP_NBANKCONT SET CREDIT = NULL WHERE CODBANK = 1; -- AM GASIT CASE CU CREDIT = 1 -- PROBABIL LA CREARE INAINTE SA BIFEZE CASA AU BIFAT CREDIT
  IF Operation = 0 THEN  -- UPDATE
    -- Master NBANKCONT
    SELECT  CodBankCont INTO RecId FROM TMP_NBANKCONT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT  &apos;cont bancar &apos;||N.DEN_CONT||&apos;/&apos;||N.NRCONT,N.SUBUNITATEA INTO aDoc, aSubunitate
      FROM tmp_NBANKCONT n where N.CODBANKcont = RECID;

      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANKCONT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitate, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NBANKCONT 
    SET  (        DataDeskis,DataInkis,CodBank,Den_cont,CodLocalitate,NrCont,
                  CodMoneda,Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine )
       = ( SELECT DataDeskis,DataInkis,CodBank,Den_cont,CodLocalitate,NrCont,
                  NVL(CodMoneda,0), Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine
          FROM TMP_NBANKCONT )
    WHERE CodBankCont = RecId ;

-- Detail NAGENDA
    DELETE FROM NAGENDA WHERE ( codbankcont = RecId AND codagenda NOT IN ( SELECT codagenda FROM TMP_NAGENDA WHERE NVL(codagenda,0) &lt;&gt; 0));

    INSERT INTO NAGENDA ( codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, longitudine, latitudine, Obs2)
    SELECT  seq_NAGENDA_codagenda.Nextval ,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km, RecId ,codpart,codgest,codsubunit, longitudine, latitudine, Obs2
    FROM TMP_NAGENDA WHERE codagenda &lt; 0 /*NVL(g_codagenda,0)*/;

    FOR v_rec IN ( SELECT * FROM TMP_NAGENDA WHERE NVL(codagenda,0) &gt; 0  ORDER BY codagenda ) LOOP
      SELECT count(*) INTO vRecNo FROM NAGENDA WHERE codagenda = NVL(v_rec.codagenda,0);
      IF(vRecNo=1) THEN
        UPDATE NAGENDA
        SET tip = v_rec.tip,
            codlocalit = v_rec.codlocalit,
            sediusocial = v_rec.sediusocial,
            telefon = v_rec.telefon,
            fax = v_rec.fax,
            email = v_rec.email,
            sector = v_rec.sector,
            strada = v_rec.strada,
            nr1 = v_rec.nr1,
            nr2 = v_rec.nr2,
            bloc = v_rec.bloc,
            scara = v_rec.scara,
            etaj = v_rec.etaj,
            apart = v_rec.apart,
            codpostal = v_rec.codpostal,
            km = v_rec.km,
            codbankcont = RecId ,
            codpart = v_rec.codpart,
            codgest = v_rec.codgest,
            codsubunit = v_rec.codsubunit,
            longitudine = v_rec.longitudine,
            latitudine = v_rec.latitudine,
            Obs2        = v_rec.Obs2
        WHERE codagenda = v_rec.codagenda;
      END IF;
    END LOOP;

-- Detail NBANKCONT1
    DELETE FROM NBANKCONT1
		WHERE CODBANKCONT = RECID and CODBANKCONT1 not in (SELECT CODBANKCONT1 FROM TMP_NBANKCONT1);

    INSERT INTO NBANKCONT1 ( codbankcont1,codbankcont,codIObanca,anstart,lunastart )
      SELECT  seq_NBANKCONT1_codbankcont1.Nextval , RecId ,codIObanca,anstart,lunastart
      FROM TMP_NBANKCONT1 WHERE codbankcont1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NBANKCONT1 WHERE NVL(codbankcont1,0) &gt; 0 ORDER BY codbankcont1 ) LOOP
      SELECT  Decode(codIObanca,v_rec.codIObanca,0,1) ,anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM NBANKCONT1 WHERE codbankcont1 = NVL(v_rec.codbankcont1,0);
       IF (vRecNo &gt; 0) THEN
         IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE NBANKCONT1 SET codIObanca = v_rec.codIObanca WHERE codbankcont1 = v_rec.codbankcont1;
        ELSE
          INSERT INTO NBANKCONT1 ( codbankcont1,codbankcont,codIObanca,anstart,lunastart ) VALUES ( Seq_NBANKCONT1_codbankcont1.NextVal,RecId,v_rec.codIObanca,v_rec.anstart,v_rec.lunastart );
        END IF;
      END IF;
    END LOOP;

-- Detail NPERSCONTACT

    DELETE FROM NPERSCONTACT WHERE ( codbankcont = RecId AND codpersc NOT IN ( SELECT codpersc FROM TMP_NPERSCONTACT WHERE NVL(codpersc,0) &lt;&gt; 0));

    INSERT INTO NPERSCONTACT ( codpersc,nume,prenume,telefon,email,functie,datanastere,rzona,id,tip,codbankcont,codpart )
      SELECT  seq_NPERSCONTACT_codpersc.Nextval ,nume,prenume,telefon,email,functie,datanastere,rzona,id,tip, RecId ,codpart
      FROM TMP_NPERSCONTACT WHERE codpersc &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_NPERSCONTACT WHERE NVL(codpersc,0) &gt; 0  ORDER BY codpersc ) LOOP
      SELECT count(*) INTO vRecNo FROM NPERSCONTACT WHERE codpersc = NVL(v_rec.codpersc,0);
      IF(vRecNo=1) THEN
        UPDATE NPERSCONTACT SET nume = v_rec.nume,prenume = v_rec.prenume,telefon = v_rec.telefon,email = v_rec.email,functie = v_rec.functie,datanastere = v_rec.datanastere,rzona = v_rec.rzona,id = v_rec.id,tip = v_rec.tip,codbankcont = RecId ,codpart = v_rec.codpart
        WHERE codpersc = v_rec.codpersc;
      END IF;
    END LOOP;


   IF INITIALIZARI = 1 THEN
     PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANPREC, LUNAPREC);

     FOR V_REC IN (SELECT * FROM TMP_NBANKSOLDLUNA) LOOP
       IF V_REC.CODBANKSOLDLUNA &lt; 0 THEN
         INSERT INTO NBANKSOLDLUNA(CODBANKSOLDLUNA, CODBANKCONT, SOLDLEI, SOLDVALUTA, AN, LUNA)
         VALUES (SEQ_NBANKSOLDLUNA_CODSOLDLUNA.NextVal, RecID, V_REC.SOLDLEI, V_REC.SOLDVALUTA, V_REC.AN, V_REC.LUNA);
       ELSE
         UPDATE NBANKSOLDLUNA
         SET
           SOLDLEI    = V_REC.SOLDLEI,
           SOLDVALUTA = V_REC.SOLDVALUTA
         WHERE
           CODBANKCONT = RecID AND AN = ANPREC AND LUNA = LUNAPREC;
       END IF;


      BEGIN
        SELECT CODMONEDA, CODBANK INTO aCODMONEDA, aCODBANK FROM NBANKCONT WHERE CODBANKCONT = V_REC.CODBANKCONT;
        EXCEPTION WHEN OTHERS THEN aCODMONEDA := 0;
      END;

      IF (aCODMONEDA &lt;&gt; 0)AND(V_REC.SOLDVALUTA &lt;&gt; 0) THEN
        SELECT COUNT(*) INTO NR FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR = T.CODTREZOR AND T1.INITIALIZARI = 1 AND T.CODBANCA = V_REC.CODBANKCONT AND T.AN = ANPREC AND T.LUNA = LUNAPREC;
        IF NR = 0 THEN
          SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL   INTO aCODTREZOR FROM DUAL;
          SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL INTO aCODTREZOR1 FROM DUAL;
          INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA)
          VALUES
          (aCODTREZOR,
           CASE
           WHEN aCODBANK = 1 THEN 29
           ELSE 30
           END,
           V_REC.CODBANKCONT,
           ANPREC,
           LUNAPREC
           );
           INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, CURS, INITIALIZARI, AN, LUNA)
            VALUES (aCODTREZOR1, aCODTREZOR, V_REC.SOLDLEI / V_REC.SOLDVALUTA, 1, ANPREC, LUNAPREC);
        END IF;

      END IF;


     END LOOP;
   END IF;


  ELSE  -- INSERT
  -- Master NBANKCONT
    SELECT seq_NBANKCONT_CodBankCont.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NBANKCONT&apos;, RecId); 

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;cont bancar &apos;||N.DEN_CONT||&apos;/&apos;||N.NRCONT,N.SUBUNITATEA INTO aDoc, aSubunitate
   FROM tmp_NBANKCONT n ;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NBANKCONT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     aSubunitate, null, aDoc,&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
END IF;


    INSERT INTO  NBANKCONT ( DataDeskis,DataInkis,CodBankCont,CodBank,Den_cont,CodLocalitate,NrCont,
                             CodMoneda,Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine )
   ( SELECT DataDeskis,DataInkis, RecId ,CodBank,Den_cont,CodLocalitate,NrCont,
                   NVL(CodMoneda, 0), Filiala, CREDIT, SUBUNITATEA, POS, POSID, CONTTVA, FARAREG, FARA_CASH_FLOW, Obs, implicitef, institpublice, ordine
       FROM TMP_NBANKCONT  ) ;
  -- Detail NAGENDA
    INSERT INTO  NAGENDA ( codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, longitudine, latitudine, Obs2 )
    SELECT  seq_NAGENDA_codagenda.Nextval ,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,RecId,codpart,codgest,codsubunit, longitudine, latitudine, Obs2
    FROM TMP_NAGENDA;

  -- Detail NBANKCONT1
    INSERT INTO  NBANKCONT1 ( codbankcont1,codbankcont,codIObanca,anstart,lunastart )
       ( SELECT  seq_NBANKCONT1_codbankcont1.Nextval ,RecId,codIObanca,anstart,lunastart FROM TMP_NBANKCONT1 );

  /*
  -- Detail NBANKCONT2
    INSERT INTO  NBANKCONT2 ( codbankcont,codbankcont2,soldlei,soldval,credit,anstart,lunastart )
       ( SELECT RecId, seq_NBANKCONT2_codbankcont2.Nextval ,soldlei,soldval,credit,anstart,lunastart FROM TMP_NBANKCONT2 );

  */
  -- Detail NPERSCONTACT
    INSERT INTO  NPERSCONTACT ( codpersc,nume,prenume,telefon,email,functie,datanastere,rzona,id,tip,codbankcont,codpart )
       ( SELECT  seq_NPERSCONTACT_codpersc.Nextval ,nume,prenume,telefon,email,functie,datanastere,rzona,id,tip,RecId,codpart FROM TMP_NPERSCONTACT );


  -- Detail NBANKSOLDLUNA
    IF INITIALIZARI = 1 THEN
      FOR V_REC IN (SELECT * FROM TMP_NBANKSOLDLUNA) LOOP
        IF V_REC.CODBANKSOLDLUNA &lt; 0 THEN
          INSERT INTO NBANKSOLDLUNA(CODBANKSOLDLUNA, CODBANKCONT, SOLDLEI, SOLDVALUTA, AN, LUNA)
          VALUES (SEQ_NBANKSOLDLUNA_CODSOLDLUNA.NextVal, RecID, V_REC.SOLDLEI, V_REC.SOLDVALUTA, V_REC.AN, V_REC.LUNA);
        END IF;


        BEGIN
          SELECT CODMONEDA, CODBANK INTO aCODMONEDA, aCODBANK FROM NBANKCONT WHERE CODBANKCONT = RECID;
          EXCEPTION WHEN OTHERS THEN aCODMONEDA := 0;
        END;

        IF (aCODMONEDA &lt;&gt; 0)AND(V_REC.SOLDVALUTA &lt;&gt; 0) THEN
          SELECT COUNT(*) INTO NR FROM TREZOR T, TREZOR1 T1 WHERE T1.CODTREZOR = T.CODTREZOR AND T1.INITIALIZARI = 1 AND T.CODBANCA = RECID AND T.AN = V_REC.AN AND T.LUNA = V_REC.LUNA;
          IF NR = 0 THEN
            SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL   INTO aCODTREZOR FROM DUAL;
            SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL INTO aCODTREZOR1 FROM DUAL;
            INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA)
            VALUES
            (aCODTREZOR,
             CASE
             WHEN aCODBANK = 1 THEN 29
             ELSE 30
             END,
             RECID,
             V_REC.AN,
             V_REC.LUNA
             );
             INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, CURS, INITIALIZARI, AN, LUNA)
             VALUES (aCODTREZOR1, aCODTREZOR, V_REC.SOLDLEI / V_REC.SOLDVALUTA, 1, V_REC.AN, V_REC.LUNA);
          END IF;

        END IF;


      END LOOP;
    END IF;

  END IF;



  BEGIN
    SELECT COUNT(*) INTO NR FROM TMP_CONTURIDEDICATE WHERE CODBANKCONT = RECID;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    INSERT INTO TMP_CONTURIDEDICATE (CODBANKCONT) VALUES (RECID);
  END IF;




-- VERIFIC DACA NU TREBUIE SA ACTUALIZAZ PE INITIALIZARI REGULARIZARI

  SELECT CODMONEDA  INTO aCODMONEDA FROM TMP_NBANKCONT;
  IF INITIALIZARI = 1 AND aCODMONEDA &gt; 0 THEN
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANPREC, LUNAPREC);

    FOR V_REC IN (SELECT * FROM TMP_NBANKSOLDLUNA) LOOP

      IF NVL(V_REC.REGULARIZARE, 0) = 0 THEN
        FOR V_RECREG IN
        (SELECT CODREGTREZOR1
         FROM
           REG R,
           REGTREZOR1 R1
         WHERE
          R.TIPREG = 45
          AND R.AN = ANPREC AND R.LUNA = LUNAPREC
          AND R1.CODREG = R.CODREG
          AND R1.CODBANKCONT = V_REC.CODBANKCONT
         )LOOP
            DELETE FROM REGTREZOR1 WHERE CODREGTREZOR1 = V_RECREG.CODREGTREZOR1;
          END LOOP;
      ELSE
        BEGIN
          SELECT NVL(CODREG, 0), NVL(CURS, 0) INTO aCODREG, aCURS
          FROM
            REG
          WHERE
            CODMONEDA = aCODMONEDA AND TIPREG = 45
            AND AN = ANPREC AND LUNA = LUNAPREC;
         EXCEPTION WHEN OTHERS THEN ACODREG := 0;
        END;

        IF aCODREG = 0 THEN
          SELECT SEQ_REG_CODREG.NEXTVAL INTO aCODREG FROM DUAL;
          INSERT INTO REG(CODREG, TIPREG, DATADOC, CODMONEDA, CURS, AN, LUNA)
          VALUES(aCODREG, 45, LAST_DAY(TO_DATE(&apos;01&apos; || &apos;.&apos; ||  TO_CHAR(LUNAPREC) || &apos;.&apos; || TO_CHAR(ANPREC), &apos;DD.MM.YYYY&apos;)), aCODMONEDA, V_REC.CURS, ANPREC, LUNAPREC);
        ELSE
          IF V_REC.CURS &lt;&gt; aCURS THEN
            UPDATE REG
            SET
              CURS  = V_REC.CURS
            WHERE
              CODREG = aCODREG;
          END IF;
        END IF;


        SELECT COUNT(*) INTO NR FROM REGTREZOR1 WHERE CODREG = aCODREG AND CODBANKCONT = V_REC.CODBANKCONT;

        IF NR = 0 THEN
          INSERT INTO REGTREZOR1(CODREGTREZOR1, CODREG, SOLDDOCVAL, SOLDDOC, SOLDDOCREG, CODBANKCONT)
          VALUES (SEQ_REGTREZOR1_CODREGTREZOR1.NEXTVAL, aCODREG, V_REC.SOLDVALUTA * V_REC.CURS, V_REC.SOLDVALUTA, V_REC.SOLDVALUTA * V_REC.CURS, RECID);
        END IF;
      END IF;
    END LOOP;
  END IF;

  PRC_AL_REFRESH(&apos;NBANKCONT1&apos;, RECID);
  -- nomCasaBanca --&gt; 519;
  PKG_CFGTABLES.EXT_POSTRECORDS(519); 
  NotifyModif(Operation, RecId, &apos;NBANKCONT&apos;);

  COMMIT;
END;



END pkg_ConturiBanci;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CONVERTSOLDPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3DDF5DC59C28BF4AF13CDC49690C3ABC7E86D895</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CONVERTSOLDPERS IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCONVERT INTO Tmp FROM CONVERTCURSPERS WHERE CODCONVERT = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CONVERTCURSPERS WHERE CODCONVERT = RECID;
  NotifyModif(2, RecId, &apos;CONVERTCURSPERS&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CONVERTCURSPERS  FIELDS( CODCONVERT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_CONVERTCURSPERS 
  (CODCONVERT, 
   CODPERS,
   ICONTPERS,
   MONEDA_IN,
   MONEDA_OUT,
   SOLDVALUTA_IN,
   SOLDLEI,
   SOLDVALUTA_OUT,
   CURSCONVERSIE,
   DATADOC,
   AN,
   LUNA,
   SIMBOLCONT,
   SUBUNITATEA,
   CURS_IN,
   OBS
   )
   SELECT  
     CODCONVERT, 
     CODPERS,
     ICONTPERS,
     MONEDA_IN,
     MONEDA_OUT,
     SOLDVALUTA_IN,
     SOLDLEI,
     SOLDVALUTA_OUT,
     CURSCONVERSIE,
     DATADOC,
     AN,
     LUNA,
     PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(CODPERS, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))),
     SUBUNITATEA,
     SOLDLEI / DECODE(NVL(SOLDVALUTA_IN, 0),  0, 1, SOLDVALUTA_IN),
     OBS
   FROM
     CONVERTCURSPERS 
   WHERE
     CODCONVERT = RECID; 
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CODCONVERT INTO RecId FROM TMP_CONVERTCURSPERS;
    UPDATE 
      CONVERTCURSPERS
    SET
    (
     CODPERS,
     ICONTPERS,
     MONEDA_IN,
     MONEDA_OUT,
     SOLDVALUTA_IN,
     SOLDLEI,
     SOLDVALUTA_OUT,
     CURSCONVERSIE,
     DATADOC,
     AN,
     LUNA,
     SUBUNITATEA,
     OBS
    ) = 
    (
     SELECT  
       CODPERS,
       ICONTPERS,
       MONEDA_IN,
       NVL(MONEDA_OUT,0),
       SOLDVALUTA_IN,
       SOLDLEI,
       SOLDVALUTA_OUT,
       CURSCONVERSIE,
       DATADOC,
       AN,
       LUNA,
       SUBUNITATEA,
       OBS
     FROM
       TMP_CONVERTCURSPERS
     ) 
    WHERE
      CODCONVERT = RECID;
  ELSE  -- INSERT
    SELECT Seq_Convertcurspers_Codconvert.Nextval INTO RecId FROM DUAL;
    INSERT INTO CONVERTCURSPERS 
    (
      CODCONVERT, 
      CODPERS,
      ICONTPERS,
      MONEDA_IN,
      MONEDA_OUT, 
      SOLDVALUTA_IN,
      SOLDLEI,
      SOLDVALUTA_OUT,
      CURSCONVERSIE,
      DATADOC,
      AN,
      LUNA,
      SUBUNITATEA,
      OBS
     )
    SELECT  
      RECID, 
      CODPERS,
      ICONTPERS,
      MONEDA_IN,
      NVL(MONEDA_OUT,0), 
      SOLDVALUTA_IN,
      SOLDLEI,
      SOLDVALUTA_OUT,
      CURSCONVERSIE,
      DATADOC,
      AN,
      LUNA,
      SUBUNITATEA,
      OBS
    FROM
      TMP_CONVERTCURSPERS; 
  END IF;
  NotifyModif(Operation, RecId, &apos;CONVERTCURSPERS&apos;);
  COMMIT;
END;

end PKG_CONVERTSOLDPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CREANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C936A57B93DCF8BC590FF48593D856D9B6644221</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CREANTE is

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodCreanta INTO Tmp FROM CREANTE WHERE CodCreanta = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CREANTE1 WHERE CODCREANTA = RecId;
  DELETE FROM CREANTE WHERE CODCREANTA = RecId;
  
  NotifyModif(2, RecId, &apos;CREANTE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_CREANTE(CODCREANTA) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
vDataMin date;  
BEGIN
  INSERT INTO TMP_CREANTE(CODCREANTA,
                          ANC,
                          LUNAC,
                          OBS)
  SELECT CODCREANTA,ANC,LUNAC,OBS
  FROM CREANTE
  WHERE CODCREANTA = RECID;
  
  INSERT INTO TMP_CREANTE1(CODCREANTA1,CODCREANTA,COD,CODCONT,INDEXLOCAL,DENUMIRE,
                           SIMBOL,CONTB,TIP,PER)
  SELECT C1.CODCREANTA1,C1.CODCREANTA,C1.COD,C1.CODCONT,C1.INDEXLOCAL,N.DENUMIRE,
         C.SIMBOL,N.CONTB,N.TIP,
         CASE 
           WHEN N.PERIOADAR = &apos;T&apos; THEN &apos;Trimestrial&apos; 
           WHEN N.PERIOADAR = &apos;L&apos; THEN &apos;Lunar&apos;
           WHEN N.PERIOADAR = &apos;S&apos; THEN &apos;Semestrial&apos;
         END    
  FROM CREANTE1 C1
       LEFT JOIN NCREANTE N ON N.COD = C1.COD
       LEFT JOIN NCONT C ON C.CODCONT = C1.CODCONT
  WHERE C1.CODCREANTA = RECID;
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODCREANTA INTO RecId FROM TMP_CREANTE;

    UPDATE CREANTE SET 
    ANC = (select ANC from TMP_CREANTE),
    LUNAC = (select LUNAC from TMP_CREANTE),
    OBS = (select obs from TMP_CREANTE)
    WHERE CODCREANTA = RecId;
    
    DELETE FROM CREANTE1 C1 WHERE C1.CODCREANTA = RECID AND NOT C1.CODCREANTA1 IN (SELECT CODCREANTA1 FROM TMP_CREANTE1);
    FOR V_REC IN (SELECT * FROM TMP_CREANTE1) LOOP
      IF V_REC.CODCREANTA1 &gt; 0 THEN
        UPDATE CREANTE1 SET
          INDEXLOCAL = V_REC.INDEXLOCAL, 
          COD        = V_REC.COD, 
          CODCONT    = V_REC.CODCONT
        WHERE CODCREANTA1 = V_REC.CODCREANTA1;
      ELSE 
        INSERT INTO CREANTE1(CODCREANTA1,CODCREANTA,COD,CODCONT,INDEXLOCAL)
        VALUES (SEQ_CREANTE1_CODCREANTA1.NEXTVAL, RECID, V_REC.COD, V_REC.CODCONT, V_REC.INDEXLOCAL); 
      END IF;
    END LOOP;
  ELSE  
    SELECT SEQ_CREANTE_CODCREANTA.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO CREANTE(CODCREANTA,ANC,LUNAC,OBS)
    SELECT RECID, ANC, LUNAC, OBS
    FROM TMP_CREANTE;
    
    INSERT INTO CREANTE1(CODCREANTA1,CODCREANTA,COD,CODCONT,INDEXLOCAL)
    SELECT SEQ_CREANTE1_CODCREANTA1.NEXTVAL, RECID, COD, CODCONT, INDEXLOCAL
    FROM TMP_CREANTE1;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;CREANTE&apos;);
  COMMIT;
END;

end PKG_CREANTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CRITERIIDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88B52AD6882AA0927E08C84E211736544DEF997C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CRITERIIDISCOUNT IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_71&apos;;

PROCEDURE SET_ISPUNCTAJ(FLAG IN NUMBER)
IS
BEGIN
 ISPUNCTAJ := FLAG;
END;

    
FUNCTION GETDISCINTERVALE(aCODDISCOUNT IN NUMBER) RETURN VARCHAR2
IS
  INFO VARCHAR2(3000) := &apos;&apos;;
  aCRITERIU NUMBER(20);
  aTIPINTERVAL NUMBER(10) := 0;
  aProcent varchar2(10);
BEGIN
  aProcent := &apos; %&apos;;
  IF ISPUNCTAJ = 1 THEN 
    aPROCENT := &apos; puncte &apos;;
  END IF;
  
  SELECT NVL(D.CODCRITERIU, 0), NVL(TIPINTERVAL, 0) INTO aCRITERIU, aTIPINTERVAL FROM DISCOUNT D, CRITERIIDISC C WHERE D.CODDISCOUNT = aCODDISCOUNT AND C.CODCRITERIU = D.CODCRITERIU;
  
  FOR v_rec IN (SELECT * FROM TMP_DISCINTERVAL  WHERE CODDISCOUNT = aCODDISCOUNT ORDER BY LIMINF, LIMSUP)
  LOOP
    IF aCRITERIU IN (3, 4, 5, 6, 7) OR aTIPINTERVAL &gt; 0 THEN 
      IF v_rec.LIMSUP IS NOT NULL THEN
--      IF v_rec.LIMSUP &lt;&gt; 0 THEN
        INFO := INFO || &apos;intre &apos; || LTRIM(TO_CHAR(v_rec.LIMINF, &apos;9,999,990.00&apos;)) || &apos; ... &apos; || LTRIM(TO_CHAR(v_rec.LIMSUP,&apos;9,999,990.00&apos;)) || 
        CASE
         WHEN  ISPUNCTAJ = 0 THEN  
          (
          CASE 
            WHEN v_rec.PROCENT &lt;= 0  THEN &apos; Discount &apos;
            ELSE &apos; Majorare &apos; 
          END
          ) 
         ELSE NULL 
        END || &apos; &apos; || LTRIM(TO_CHAR(abs(v_rec.PROCENT), &apos;9,999,990.00&apos;)) || aProcent || CHR(13);
      ELSE
        INFO := INFO || &apos;peste &apos; || LTRIM(TO_CHAR(v_rec.LIMINF, &apos;9,999,990.00&apos;)) || 
        CASE 
          WHEN  ISPUNCTAJ = 0 THEN  
          ( 
            CASE 
              WHEN v_rec.PROCENT &lt;= 0 THEN &apos; Discount &apos;
              ELSE &apos; Majorare &apos; 
            END
          )
        ELSE NULL
        END  || &apos; &apos; || LTRIM(TO_CHAR(abs(v_rec.PROCENT), &apos;9,999,990.00&apos;)) || aProcent || CHR(13);
      END IF;
    ELSE -- criterii definite de utilizator
      INFO := INFO ||
       CASE 
         WHEN ISPUNCTAJ = 0 THEN   
         (
         CASE 
           WHEN v_rec.PROCENT &lt;= 0 THEN &apos; Discount &apos; || CHR(13) 
           ELSE &apos; Majorare &apos; || CHR(13) 
         END
         )
        END || &apos; &apos; || LTRIM(TO_CHAR(abs(v_rec.PROCENT), &apos;9,999,990.00&apos;)) || aProcent || CHR(13);  
    END IF;  
  END LOOP;
  
  RETURN INFO;
END;


FUNCTION CONDITIE_OBJ_CLASA_GRUPA(aPECLASE IN NUMBER, aCODOBIECT IN NUMBER, aCODCLASA IN NUMBER,  aGRUPA IN VARCHAR2, OBIECTREAL IN VARCHAR2) RETURN NUMBER
IS 
BEGIN
  IF aPECLASE = 3 THEN RETURN 1;
  ELSE
  IF aPECLASE = 0 THEN 
    IF aCODOBIECT = TO_NUMBER(OBIECTREAL) THEN RETURN 1;
                                          ELSE RETURN 0;
    END IF;
  ELSE
  IF aPECLASE = 1 THEN 
    IF aCODCLASA = TO_NUMBER(OBIECTREAL) THEN RETURN 1;
                                         ELSE RETURN 0;
--    RETURN PKG_GLOBALS.IS_SUBCLAS_OF(TO_NUMBER(OBIECTREAL), aCODCLASA);
    END IF;
  ELSE
  IF aPECLASE = 2 THEN 
    IF TRIM(aGRUPA) = TRIM(OBIECTREAL) THEN RETURN 1;
                                       ELSE RETURN 0;
    END IF;
  END IF;  
  END IF;
  END IF;  
  END IF;
END;




 FUNCTION GET_CODDISCOUNT_FOR_CRITERIU
                            (aCODOBIECT IN NUMBER, 
                             aCODCRITERIU IN NUMBER,
                             aDATAREF IN VARCHAR2, 
                             aTIPSEDIU IN NUMBER
                             ) RETURN NUMBER
 IS 
   RESULT NUMBER(20)   := 0;
   aPECLASE   NUMBER(2) := 0;
   OBIECTREAL VARCHAR2(20);
   DATAREF    DATE;
   aTIPINTERVAL   NUMBER(5) := 0;
 BEGIN
   
   DATAREF  := TO_DATE(aDATAREF, &apos;dd.mm.yyyy&apos;);
   
   
   BEGIN
     SELECT NVL(PECLASE, 0), NVL(TIPINTERVAL, 0) INTO aPECLASE, aTIPINTERVAL FROM CRITERIIDISC WHERE CODCRITERIU = aCODCRITERIU;
     EXCEPTION WHEN OTHERS THEN aPECLASE := 0; aTipInterval := 0;
   END;
   
   IF aPECLASE = 2 THEN 
     OBIECTREAL := PKG_SELECTARTICOLE.GETGRUPAOBIECT(aCODOBIECT);
   ELSE 
   IF aPECLASE = 1 THEN 
     OBIECTREAL := TO_CHAR(PKG_SELECTARTICOLE.GETCLASAOFART(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCODOBIECT)));
   ELSE 
     OBIECTREAL := TO_CHAR(aCODOBIECT);
   END IF;
   END IF;   


   IF aPECLASE = 3 THEN
      FOR REC_DISCART IN
        (
         SELECT 
         D.* 
         FROM 
           DISCOUNT D,
           CRITERIIDISC1 C1,
           CRITERIIDISC C
         WHERE
            D.CODCRITERIU1 = C1.CODCRITERIU1
           AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
           AND C1.CODCRITERIU = aCODCRITERIU
           AND C.CODCRITERIU = aCODCRITERIU
           AND NVL(C.OFFINVOICE, 0)  = 0
           AND NVL(C1.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C1.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
           AND C1.DATASTART =
                   (SELECT MAX(DATASTART) FROM CRITERIIDISC1 C11
                      WHERE 
                       C11.CODCRITERIU = aCODCRITERIU
                   AND NVL(C11.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C11.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
                   AND DATASTART &lt;= DATAREF
                   )
       )            
      LOOP
        RESULT := REC_DISCART.CODDISCOUNT;
        RETURN RESULT;
      END LOOP;

   ELSE 
      FOR REC_DISCART IN
        (
         SELECT DA.* 
         FROM 
           DISCART DA,
           DISCOUNT D,
           CRITERIIDISC1 C1,
           CRITERIIDISC C
         WHERE
           CONDITIE_OBJ_CLASA_GRUPA(aPECLASE, CODOBIECT, CODCLASA, GRUPA, OBIECTREAL) = 1 
           AND DA.CODDISCOUNT = D.CODDISCOUNT
           AND D.CODCRITERIU1 = C1.CODCRITERIU1
           AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
           AND C1.CODCRITERIU = aCODCRITERIU
           AND C.CODCRITERIU  = aCODCRITERIU
           AND NVL(C.OFFINVOICE, 0)  = 0
           AND NVL(C1.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C1.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
           AND C1.DATASTART =
             		  (SELECT MAX(DATASTART) FROM CRITERIIDISC1 C11
             			   WHERE 
                       C11.CODCRITERIU = aCODCRITERIU
                   AND NVL(C11.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C11.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
                   AND DATASTART &lt;= DATAREF
                   )
       )            
      LOOP
        RESULT := REC_DISCART.CODDISCOUNT;
        RETURN RESULT;
      END LOOP;
   END IF;   
   RETURN RESULT;
 END; 




 FUNCTION ART_ARE_DISCOUNT(aCODOBIECT IN NUMBER, 
                           aCODCRITERIU IN NUMBER, 
                           aVALOARE IN NUMBER, 
                           aVALOARECLASA IN NUMBER, 
                           aTIPSEDIU IN NUMBER, 
                           aPROCENT OUT NUMBER) RETURN NUMBER
 IS 
   RESULT NUMBER(2)   := 0;
   aPECLASE     NUMBER(2) := 0;
   OBIECTREAL   VARCHAR2(20);
   aVAL         NUMBER(20, 7);
   aTIPINTERVAL NUMBER(5) := 0;
 BEGIN
   aPROCENT := 0; aVAL := aVALOARE;
   BEGIN
     SELECT NVL(PECLASE, 0), NVL(TIPINTERVAL, 0)  INTO aPECLASE, aTIPINTERVAL  FROM CRITERIIDISC WHERE CODCRITERIU = aCODCRITERIU;
     EXCEPTION WHEN OTHERS THEN aPECLASE := 0; aTipInterval := 0; 
   END;
   
   IF aPECLASE = 2 THEN 
     OBIECTREAL := PKG_SELECTARTICOLE.GETGRUPAOBIECT(aCODOBIECT);
     aVAL       := aVALOARECLASA;
   ELSE 
   IF aPECLASE = 1 THEN 
     OBIECTREAL := TO_CHAR(PKG_SELECTARTICOLE.GETCLASAOFART(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCODOBIECT)));
     aVAL       := aVALOARECLASA;
   ELSE 
     OBIECTREAL := TO_CHAR(aCODOBIECT);
   END IF;
   END IF;   



  IF aPECLASE = 3 THEN
     FOR REC_DISCART IN
       ( SELECT * FROM DISCOUNT 
         WHERE
          CODDISCOUNT IN  
          (
            SELECT 
             D.CODDISCOUNT 
            FROM 
              DISCOUNT D,
              CRITERIIDISC C 
            WHERE 
               D.CODCRITERIU  = aCODCRITERIU 
             AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
            AND C.CODCRITERIU = aCODCRITERIU 
            AND NVL(C.OFFINVOICE, 0) = 0 
            AND  NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
          )
        )
     LOOP
       RESULT := 1;
       FOR REC_DISCINTERVAL IN 
         (SELECT * FROM DISCINTERVAL WHERE CODDISCOUNT = REC_DISCART.CODDISCOUNT ORDER BY LIMINF, LIMSUP)
       LOOP
         IF aCODCRITERIU &gt; 7 AND aTIPINTERVAL = 0 THEN BEGIN
           aPROCENT := REC_DISCINTERVAL.PROCENT;
           RETURN RESULT;
         END;  
         ELSE
           IF REC_DISCINTERVAL.LIMSUP IS NULL --(REC_DISCINTERVAL.LIMSUP = 0) 
           THEN
             IF aVAL &gt; REC_DISCINTERVAL.LIMINF THEN BEGIN 
               aPROCENT := REC_DISCINTERVAL.PROCENT;
               RETURN RESULT;
             END;
             END IF;
           ELSE
             IF aVAL &gt; REC_DISCINTERVAL.LIMINF AND aVAL &lt;= REC_DISCINTERVAL.LIMSUP THEN 
             BEGIN
               aPROCENT := REC_DISCINTERVAL.PROCENT;
               RETURN RESULT;
             END;
             END IF;
           END IF; 
         END IF;
       END LOOP;   
     END LOOP;
  ELSE 
     FOR REC_DISCART IN
       ( SELECT * FROM DISCART 
         WHERE
           CONDITIE_OBJ_CLASA_GRUPA(aPECLASE, CODOBIECT, CODCLASA, GRUPA, OBIECTREAL) = 1 
          AND CODDISCOUNT IN  
          (
            SELECT D.CODDISCOUNT 
            FROM 
              DISCOUNT D,
              CRITERIIDISC C  
            WHERE 
             D.  CODCRITERIU = aCODCRITERIU 
             AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
             AND C.CODCRITERIU = aCODCRITERIU 
             AND NVL(C.OFFINVOICE, 0) = 0
             AND  NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
          )
        )
     LOOP
       RESULT := 1;
       FOR REC_DISCINTERVAL IN 
         (SELECT * FROM DISCINTERVAL WHERE CODDISCOUNT = REC_DISCART.CODDISCOUNT ORDER BY LIMINF, LIMSUP)
       LOOP
         IF aCODCRITERIU &gt; 7 THEN BEGIN
           aPROCENT := REC_DISCINTERVAL.PROCENT;
           RETURN RESULT;
         END;  
         ELSE
           IF REC_DISCINTERVAL.LIMSUP IS NULL --(REC_DISCINTERVAL.LIMSUP = 0) 
           THEN
             IF aVAL &gt; REC_DISCINTERVAL.LIMINF THEN BEGIN 
               aPROCENT := REC_DISCINTERVAL.PROCENT;
               RETURN RESULT;
             END;
             END IF;
           ELSE
             IF aVAL &gt; REC_DISCINTERVAL.LIMINF AND aVAL &lt;= REC_DISCINTERVAL.LIMSUP THEN 
             BEGIN
               aPROCENT := REC_DISCINTERVAL.PROCENT;
               RETURN RESULT;
             END;
             END IF;
           END IF; 
         END IF;
       END LOOP;   
     END LOOP;
   END IF;
   
   RETURN RESULT;
 END; 

 FUNCTION ART_ARE_DISCOUNT_EXT(aCODOBIECT IN NUMBER, 
                               aCODCRITERIU IN NUMBER, 
                               aVALOARE IN NUMBER, 
                               aVALOARECLASA IN NUMBER, 
                               aDATAREF IN VARCHAR2, 
                               aTIPSEDIU IN NUMBER, 
                               aPROCENT OUT NUMBER) RETURN NUMBER
 IS 
   RESULT NUMBER(2)   := 0;
   aPECLASE       NUMBER(2) := 0;
   OBIECTREAL     VARCHAR2(20);
   aVAL           NUMBER(20, 7);
   DATAREF        DATE;
   aTIPINTERVAL   NUMBER(5) := 0;
   STEP           NUMBER(5) := 0;
 BEGIN
   aPROCENT := 0; aVAL := aVALOARE;
   DATAREF  := TO_DATE(aDATAREF, &apos;dd.mm.yyyy&apos;);
   
   
   BEGIN
     SELECT NVL(PECLASE, 0), NVL(TIPINTERVAL, 0) INTO aPECLASE, aTIPINTERVAL FROM CRITERIIDISC WHERE CODCRITERIU = aCODCRITERIU;
     EXCEPTION WHEN OTHERS THEN aPECLASE := 0; aTipInterval := 0;
   END;
   
   IF aPECLASE = 2 THEN 
     OBIECTREAL := PKG_SELECTARTICOLE.GETGRUPAOBIECT(aCODOBIECT);
     aVAL       := aVALOARECLASA;
   ELSE 
   IF aPECLASE = 1 THEN 
     OBIECTREAL := TO_CHAR(PKG_SELECTARTICOLE.GETCLASAOFART(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCODOBIECT)));
     aVAL       := aVALOARECLASA;
   ELSE 
     OBIECTREAL := TO_CHAR(aCODOBIECT);
   END IF;
   END IF;   


   IF aPECLASE = 3 THEN
      FOR REC_DISCART IN
        (
         SELECT 
         D.* 
         FROM 
           DISCOUNT D,
           CRITERIIDISC1 C1,
           CRITERIIDISC C
         WHERE
            D.CODCRITERIU1 = C1.CODCRITERIU1
           AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
           AND C1.CODCRITERIU = aCODCRITERIU
           AND C.CODCRITERIU = aCODCRITERIU
           AND NVL(C.OFFINVOICE, 0)  = 0
           AND NVL(C1.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C1.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
           AND C1.DATASTART =
             		  (SELECT MAX(DATASTART) FROM CRITERIIDISC1 C11
             			   WHERE 
                       C11.CODCRITERIU = aCODCRITERIU
                   AND NVL(C11.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C11.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
                   AND DATASTART &lt;= DATAREF
                   )
       )            
      LOOP
        RESULT := 0;
        FOR REC_DISCINTERVAL IN 
          (SELECT * FROM DISCINTERVAL WHERE CODDISCOUNT = REC_DISCART.CODDISCOUNT ORDER BY LIMINF, LIMSUP)
        LOOP
          STEP := STEP + 1; 
          IF aCODCRITERIU &gt; 7 AND aTIPINTERVAL = 0 THEN BEGIN
            aPROCENT := REC_DISCINTERVAL.PROCENT;
            RETURN 1;
          END;  
          ELSE
            IF  REC_DISCINTERVAL.LIMSUP IS NULL --(REC_DISCINTERVAL.LIMSUP = 0) 
            THEN
              IF aVAL &gt; REC_DISCINTERVAL.LIMINF THEN BEGIN 
                aPROCENT := REC_DISCINTERVAL.PROCENT;
                RETURN 1;
              END;
              END IF;
            ELSE
              IF ((STEP = 1 AND aVAL &gt;= REC_DISCINTERVAL.LIMINF)OR(STEP &gt; 1 AND aVAL &gt; REC_DISCINTERVAL.LIMINF)) AND aVAL &lt;= REC_DISCINTERVAL.LIMSUP THEN 
              BEGIN
                aPROCENT := REC_DISCINTERVAL.PROCENT;
                RETURN 1;
              END;
              END IF;
            END IF; 
          END IF;
        END LOOP;   
      END LOOP;

   ELSE 
      FOR REC_DISCART IN
        (
         SELECT DA.* 
         FROM 
           DISCART DA,
           DISCOUNT D,
           CRITERIIDISC1 C1,
           CRITERIIDISC C
         WHERE
           CONDITIE_OBJ_CLASA_GRUPA(aPECLASE, CODOBIECT, CODCLASA, GRUPA, OBIECTREAL) = 1 
           AND DA.CODDISCOUNT = D.CODDISCOUNT
           AND D.CODCRITERIU1 = C1.CODCRITERIU1
           AND (NVL(D.CODTIPSEDIU, 0) = 0 OR NVL(D.CODTIPSEDIU, 0)= aTIPSEDIU)
           AND C1.CODCRITERIU = aCODCRITERIU
           AND C.CODCRITERIU  = aCODCRITERIU
           AND NVL(C.OFFINVOICE, 0)  = 0
           AND NVL(C1.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C1.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
           AND C1.DATASTART =
             		  (SELECT MAX(DATASTART) FROM CRITERIIDISC1 C11
             			   WHERE 
                       C11.CODCRITERIU = aCODCRITERIU
                   AND NVL(C11.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(C11.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
                   AND DATASTART &lt;= DATAREF
                   )
       )            
      LOOP
        RESULT := 0;
        FOR REC_DISCINTERVAL IN 
          (SELECT * FROM DISCINTERVAL WHERE CODDISCOUNT = REC_DISCART.CODDISCOUNT ORDER BY LIMINF, LIMSUP)
        LOOP
          STEP := STEP + 1;
          IF (aCODCRITERIU &gt; 7)AND(aTIPINTERVAL = 0) THEN BEGIN
            aPROCENT := REC_DISCINTERVAL.PROCENT;
            RETURN 1;
          END;  
          ELSE
            IF REC_DISCINTERVAL.LIMSUP IS NULL --(REC_DISCINTERVAL.LIMSUP = 0) 
            THEN
              IF aVAL &gt; REC_DISCINTERVAL.LIMINF THEN BEGIN 
                aPROCENT := REC_DISCINTERVAL.PROCENT;
                RETURN 1;
              END;
              END IF;
            ELSE
--            IF aVAL &gt; REC_DISCINTERVAL.LIMINF AND aVAL &lt;= REC_DISCINTERVAL.LIMSUP THEN 
              IF ((STEP = 1 AND aVAL &gt;= REC_DISCINTERVAL.LIMINF)OR(STEP &gt; 1 AND aVAL &gt; REC_DISCINTERVAL.LIMINF)) AND aVAL &lt;= REC_DISCINTERVAL.LIMSUP THEN 
              BEGIN
                aPROCENT := REC_DISCINTERVAL.PROCENT;
                RETURN 1;
              END;
              END IF;
            END IF; 
          END IF;
        END LOOP;   
      END LOOP;
   END IF;   
   RETURN RESULT;
 END; 



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodCriteriu INTO Tmp FROM CRITERIIDISC WHERE CodCriteriu = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDenCriteriu varchar2(40);  
BEGIN
  select dencriteriu into aDenCriteriu from CRITERIIDISC WHERE CodCriteriu = RecId;
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;CRITERIIDISC&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, null, aDenCriteriu, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  SP_LOCKRECORD(RecId);
  DELETE FROM DISCART WHERE CODDISCOUNT IN 
  ( SELECT  CODDISCOUNT FROM  DISCOUNT WHERE CODCRITERIU = RECID);
  
  DELETE FROM DISCEXCEPTII WHERE CODDISCOUNT IN 
  ( SELECT  CODDISCOUNT FROM  DISCOUNT WHERE CODCRITERIU = RECID);



  DELETE FROM DISCINTERVAL WHERE CODDISCOUNT IN 
  ( SELECT CODDISCOUNT FROM  DISCOUNT WHERE CODCRITERIU = RECID);
  
  DELETE FROM  DISCOUNT WHERE CODCRITERIU = RECID;

  DELETE FROM NPARTDISC    WHERE CODCATEGDISC = RECID;
  DELETE FROM CRITERIIDISC WHERE CodCriteriu  = RecId ;
  
  NotifyModif(2, RecId, &apos;CRITERIIDISC&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CRITERIIDISC FIELDS( CodCriteriu ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 
 vPECLASE NUMBER(10);
 vInd     NUMBER(10);
 vSubunit NUMBER(10);
 vData    DATE;
 
BEGIN
-- Master CRITERIIDISC
  INSERT INTO TMP_CRITERIIDISC ( CodCriteriu, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CUMULAT, OFFINVOICE, NIVEL, CLASA, TIPINTERVAL, PUNCTE )
    ( SELECT CodCriteriu, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, NVL(CUMULAT, 0), NVL(OFFINVOICE, 0), NVL(NIVEL, 0), CLASA, NVL(TIPINTERVAL, 0), PUNCTE 
      FROM CRITERIIDISC WHERE CodCriteriu = RecId 
    );
  
  BEGIN 
   SELECT NVL(PECLASE, 0) INTO vPECLASE  FROM TMP_CRITERIIDISC;  
   EXCEPTION WHEN OTHERS THEN vPECLASE := 0;
  END; 


  INSERT INTO TMP_CRITERIIDISC1(CODCRITERIU1, CODCRITERIU, DATASTART, SUBUNITATEA)
  SELECT CODCRITERIU1, CODCRITERIU, DATASTART, SUBUNITATEA FROM CRITERIIDISC1 
  WHERE 
  CODCRITERIU = RECID
  AND   NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE); 


-- Detail DISCOUNT
  INSERT INTO  TMP_DISCOUNT ( CodDiscount, CodCriteriu, SUBUNITATEA, DEN_SUBUNIT, CODCRITERIU1, CODTIPSEDIU)
    ( SELECT CodDiscount, CodCriteriu, SUBUNITATEA, SUB.DEN_SUBUNIT, CODCRITERIU1, CODTIPSEDIU  
    FROM 
      DISCOUNT D
      LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = D.SUBUNITATEA 
    WHERE 
      CodCriteriu = RecId  
      AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
      AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
    ) ;

-- Detail DISCINTERVAL
  INSERT INTO TMP_DISCINTERVAL ( CodDiscInterval, CodDiscount, LimInf, LimSup, Procent )
  (
   SELECT CodDiscInterval, CodDiscount, LimInf, LimSup, Procent 
    FROM DISCINTERVAL  WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT)
  );

-- Detail DISCART
  INSERT INTO TMP_DISCART ( CodDiscArt, CodDiscount, CodObiect, CODCLASA, GRUPA )
  (
   SELECT CodDiscArt, CodDiscount, CodObiect, CODCLASA, GRUPA
    FROM DISCART  WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT)
  );

-- Detail DISCEXCEPTII
  INSERT INTO TMP_DISCEXCEPTII( CodDiscExceptie, CodDiscount, CodObiect)
  (
   SELECT CodDiscExceptie, CodDiscount, CodObiect
    FROM DISCEXCEPTII  WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT)
  );


-- actualizez campul DISCOUNTINFO in TMP_DISCOUNT
  UPDATE TMP_DISCOUNT D SET DISCOUNTINFO = GETDISCINTERVALE(D.CODDISCOUNT);



-- actualizez campul DENARTICOL in TMP_DISCEXCEPTII
  UPDATE TMP_DISCEXCEPTII D 
  SET 
  (DENOBIECT, CODEXTERN, CODINTERN) =  
  (SELECT DENUMIRE, CODEXTERN, CODINTERN FROM NARTOBJ WHERE CODOBIECT = D.CODOBIECT);
   


-- actualizez campul DENARTICOL in TMP_DISCART
  UPDATE TMP_DISCART D 
  SET 
  DENOBIECT = 
  CASE 
    WHEN vPECLASE = 0 THEN  PKG_SELECTARTICOLE.GETDENOBIECTEXT(D.CODOBIECT) 
    WHEN vPECLASE = 2 THEN  GRUPA
    ELSE (SELECT DEN_CLASEA FROM NCLASEA WHERE CODCLASEA = D.CODCLASA)
  END,
  CODEXTERN = 
  CASE 
    WHEN vPECLASE = 0 THEN  (SELECT CODEXTERN FROM NARTOBJ WHERE CODOBIECT = D.CODOBIECT) 
    WHEN vPECLASE = 2 THEN  NULL
    ELSE (SELECT SIMBOL FROM NCLASEA WHERE CODCLASEA = D.CODCLASA)
  END,
  CODINTERN = 
  CASE 
    WHEN vPECLASE = 0 THEN  (SELECT CODINTERN FROM NARTOBJ WHERE CODOBIECT = D.CODOBIECT) 
    ELSE NULL
  END,
  CODCRITERIU1 = (SELECT CODCRITERIU1 FROM TMP_DISCOUNT WHERE CODDISCOUNT = D.CODDISCOUNT);

-- actualizez DataEnd 
  vInd     := 0;
  vSubunit := 0;
  FOR v_rec IN 
   (
     SELECT * FROM Criteriidisc1 
     WHERE CODCRITERIU = RECID
           AND 
           NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     order by SUBUNITATEA, DataStart  desc
   ) LOOP
     if vSubunit &lt;&gt; v_rec.Subunitatea then  vInd := 0; end if;
     if vInd &gt; 0 then 
       UPDATE Tmp_Criteriidisc1 SET DataEnd = TO_DATE(vDATA, &apos;dd.mm.yyyy&apos;) WHERE CODCRITERIU1 = v_rec.CODCRITERIU1;
     end if;
     vDATA  := TO_DATE(v_rec.DATASTART - 1, &apos;dd.mm.yyyy&apos;);
     vInd := vInd + 1;
     vSubunit := v_rec.Subunitatea;
  END LOOP;


  INSERT INTO TMP_NPARTDISC2(CODPARTDISC, CODPART, CODCATEGDISC, DEN_PART, CODCLASA) 
  SELECT 
    CODPARTDISC, 
    PD.CODPART, 
    PD.CODCATEGDISC,
    P.DEN_PART,
    CP.CODCLASEP 
  FROM 
    NPARTDISC PD,
    NPART P 
    LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA
  WHERE 
    PD.CODCATEGDISC = RECID
    AND P.CODPART = PD.CODPART;
    
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) 
IS
vCod NUMBER(20);
NR NUMBER(5);
I  NUMBER(5) := 0;
aDenCriteriu varchar2(40);
BEGIN
  select dencriteriu into aDenCriteriu from TMP_CRITERIIDISC;
  IF Operation = 0 THEN  -- UPDATE
    -- Master CRITERIIDISC
    SELECT CodCriteriu INTO RecId FROM TMP_CRITERIIDISC;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;CRITERIIDISC&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                        PKG_GLOBALS.GETSUBUNITATE, null, aDenCriteriu, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE CRITERIIDISC SET ( DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CUMULAT, OFFINVOICE, NIVEL, CLASA, TIPINTERVAL, PUNCTE )
       = ( SELECT DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CUMULAT, OFFINVOICE, NVL(NIVEL, 0), CLASA, TIPINTERVAL, PUNCTE
          FROM TMP_CRITERIIDISC )
    WHERE 
    CodCriteriu = RecId ;

    DELETE FROM NPARTDISC PD WHERE CODCATEGDISC = RECID AND NOT EXISTS (SELECT CODPARTDISC FROM TMP_NPARTDISC2 WHERE CODPARTDISC = PD.CODPARTDISC);

-- stergerile musai in ordinea asta  
   DELETE FROM DISCINTERVAL 
   WHERE 
   CODDISCOUNT IN 
   (SELECT CODDISCOUNT 
    FROM 
     DISCOUNT 
    WHERE 
     CODCRITERIU = RecID
     AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
   ) 
   AND CODDISCINTERVAL NOT IN (SELECT CODDISCINTERVAL FROM TMP_DISCINTERVAL);

   FOR V_REC IN (SELECT * FROM TMP_NPARTDISC2) LOOP
     IF V_REC.CODPARTDISC &lt; 0 THEN
       INSERT INTO NPARTDISC(CODPARTDISC, CODPART, CODCATEGDISC)
       VALUES (SEQ_NPARTDISC_CODPARTDISC.NEXTVAL, V_REC.CODPART, RECID);
     ELSE
       UPDATE NPARTDISC
       SET
         CODPART = V_REC.CODPART,
         CODCATEGDISC = RECID
       WHERE
         CODPARTDISC = V_REC.CODPARTDISC;
         
     END IF;
   END LOOP;

   DELETE FROM DISCART
   WHERE 
   CODDISCOUNT IN 
   (SELECT 
      CODDISCOUNT 
    FROM 
      DISCOUNT 
     WHERE 
     CODCRITERIU = RecID
     AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
    ) 
    AND cODDISCART NOT IN (SELECT CODDISCART FROM TMP_DISCART);


   DELETE FROM DISCEXCEPTII
   WHERE 
   CODDISCOUNT IN 
   (SELECT 
      CODDISCOUNT 
    FROM 
      DISCOUNT 
     WHERE 
     CODCRITERIU = RecID
     AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
    ) 
    AND CODDISCEXCEPTIE NOT IN (SELECT CODDISCEXCEPTIE FROM TMP_DISCEXCEPTII);


   DELETE FROM DISCOUNT 
   WHERE 
     CODCRITERIU = RecID 
     AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)

     AND CODDISCOUNT NOT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT);

   
   DELETE FROM CRITERIIDISC1
   WHERE 
     CODCRITERIU = RecID 
     AND NVL(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE) 
     AND NVL(SUBUNITATEA, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
     AND CODCRITERIU1 NOT IN (SELECT CODCRITERIU1 FROM TMP_CRITERIIDISC1);
   
   
   FOR V_REC IN (SELECT * FROM TMP_CRITERIIDISC1)
   LOOP
     IF V_REC.CODCRITERIU1 &lt; 0 THEN
       SELECT SEQ_CRITERIIDISC1_CODCRITERIU1.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_DISCOUNT
       SET
         CODCRITERIU1 = VCOD
       WHERE
         CODCRITERIU1 = V_REC.CODCRITERIU1;  
         
       INSERT INTO CRITERIIDISC1(CODCRITERIU1, CODCRITERIU, DATASTART, SUBUNITATEA)
       VALUES (VCOD, RECID, V_REC.DATASTART, V_REC.SUBUNITATEA);  
     ELSE
       UPDATE CRITERIIDISC1
       SET
         DATASTART = V_REC.DATASTART
       WHERE
        CODCRITERIU1 = V_REC.CODCRITERIU1;
     END IF;
   END LOOP;
   
   FOR v_rec IN (SELECT * FROM TMP_DISCOUNT) LOOP
   
     IF v_rec.CODDISCOUNT &lt; 0 THEN
       SELECT SEQ_DISCOUNT_CODDISCOUNT.NEXTVAL INTO VCOD FROM DUAL;
     
       UPDATE TMP_DISCINTERVAL SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;
     
       UPDATE TMP_DISCART SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;

       UPDATE TMP_DISCEXCEPTII SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;
       INSERT INTO DISCOUNT (CODDISCOUNT, CODCRITERIU, SUBUNITATEA, CODCRITERIU1, CODTIPSEDIU ) VALUES (vCod, RecID, V_REC.SUBUNITATEA, V_REC.CODCRITERIU1, V_REC.CODTIPSEDIU);
     ELSE
       VCOD := V_REC.CODDISCOUNT;
       UPDATE DISCOUNT 
       SET
        CODTIPSEDIU = V_REC.CODTIPSEDIU  
       WHERE
        CODDISCOUNT = V_REC.CODDISCOUNT;
    -- pe ramura de else nu am ce trata pentru ca nu am ce sa modific in DISCOUNT
     END IF;

    -- ma asigur ca daca limita superioara este 0 trebuie s-o pun null 
     SELECT COUNT(*) INTO NR FROM TMP_DISCINTERVAL WHERE CODDISCOUNT = VCOD;
     I := 0;
     FOR V_RECINTERVAL IN
     (
      SELECT * FROM TMP_DISCINTERVAL WHERE CODDISCOUNT = VCOD ORDER BY LIMINF, LIMSUP
     )
     LOOP
        I := I + 1;
        IF I = NR AND V_RECINTERVAL.LIMSUP = 0 THEN
          UPDATE TMP_DISCINTERVAL
          SET 
           LIMSUP = NULL
          WHERE
           CODDISCINTERVAL = V_RECINTERVAL.CODDISCINTERVAL; 
        END IF;
     END LOOP;

     
   END LOOP;
   

   -- Detaliu DISCINTERVAL
   FOR v_rec IN (SELECT * FROM TMP_DISCINTERVAL) LOOP
     IF v_Rec.CODDISCINTERVAL &lt; 0 THEN
       INSERT INTO DISCINTERVAL (CODDISCINTERVAL, CODDISCOUNT, LIMINF, LIMSUP, PROCENT)
       VALUES (SEQ_DISCINTERVAL_CODDISCINTERV.NEXTVAL, v_Rec.CODDISCOUNT,v_Rec.LIMINF,  v_Rec.LIMSUP, v_Rec.PROCENT); 
     ELSE
       UPDATE DISCINTERVAL
       SET
        LIMINF  = v_Rec.LIMINF,
        LIMSUP  = v_Rec.LIMSUP,
        PROCENT = v_Rec.PROCENT
       WHERE
        CODDISCINTERVAL = v_Rec.CODDISCINTERVAL;
     END IF;
   END LOOP;
   
   -- Detaliu DISCART
  
   FOR v_rec IN (SELECT * FROM TMP_DISCART) LOOP
     IF v_Rec.CODDISCART &lt; 0 THEN
       INSERT INTO DISCART (CODDISCART, CODDISCOUNT, CODOBIECT, CODCLASA, GRUPA)
       VALUES (SEQ_DISCART_CODDISCART.NEXTVAL, v_Rec.CODDISCOUNT, v_Rec.CODOBIECT, v_Rec.CODCLASA, V_REC.GRUPA); 
     ELSE
       UPDATE DISCART
       SET 
         CODOBIECT = v_Rec.CODOBIECT, 
         CODCLASA  = v_Rec.CODCLASA,
         GRUPA     = v_Rec.GRUPA
       WHERE 
         CODDISCART = v_Rec.CODDISCART;
     END IF;
   END LOOP;

   -- Detaliu DISCART
  
   FOR v_rec IN (SELECT * FROM TMP_DISCEXCEPTII) LOOP
     IF v_Rec.CODDISCEXCEPTIE &lt; 0 THEN
       INSERT INTO DISCEXCEPTII (CODDISCEXCEPTIE, CODDISCOUNT, CODOBIECT)
       VALUES (SEQ_DISCEXCEPTII_COD.NEXTVAL, v_Rec.CODDISCOUNT, v_Rec.CODOBIECT); 
     ELSE
       UPDATE DISCEXCEPTII
       SET 
         CODOBIECT = v_Rec.CODOBIECT 
       WHERE 
         CODDISCEXCEPTIE = v_Rec.CODDISCEXCEPTIE;
     END IF;
   END LOOP;



  ELSE  -- INSERT

   
    -- Master CRITERIIDISC
    SELECT Seq_CRITERIIDISC_CodCriteriu.NEXTVAL INTO RecId FROM DUAL;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;CRITERIIDISC&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                        PKG_GLOBALS.GETSUBUNITATE, null, aDenCriteriu, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    
   INSERT INTO NPARTDISC(CODPARTDISC, CODPART, CODCATEGDISC)
   SELECT SEQ_NPARTDISC_CODPARTDISC.NEXTVAL, CODPART, RECID FROM TMP_NPARTDISC2; 

    
    INSERT INTO CRITERIIDISC (CodCriteriu, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CUMULAT, OFFINVOICE, NIVEL, CLASA, TIPINTERVAL, PUNCTE)
    ( SELECT RecID, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CUMULAT, OFFINVOICE, NVL(NIVEL, 0), CLASA, TIPINTERVAL, PUNCTE FROM TMP_CRITERIIDISC);    

    FOR V_REC IN (SELECT * FROM TMP_CRITERIIDISC1)
    LOOP
       SELECT SEQ_CRITERIIDISC1_CODCRITERIU1.NEXTVAL INTO VCOD FROM DUAL;
   
       UPDATE TMP_DISCOUNT
       SET
         CODCRITERIU1 = VCOD
       WHERE
         CODCRITERIU1 = V_REC.CODCRITERIU1;  
         
       INSERT INTO CRITERIIDISC1(CODCRITERIU1, CODCRITERIU, DATASTART, SUBUNITATEA)
       VALUES (VCOD, RECID, V_REC.DATASTART, V_REC.SUBUNITATEA);  
    END LOOP;
    
    -- detaliu DISCOUNT
    FOR v_rec IN (SELECT * FROM TMP_DISCOUNT) LOOP
      SELECT SEQ_DISCOUNT_CODDISCOUNT.NEXTVAL INTO vCod FROM DUAL;

      UPDATE TMP_DISCINTERVAL SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;
      UPDATE TMP_DISCART      SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;
      UPDATE TMP_DISCEXCEPTII SET CODDISCOUNT = vCod WHERE CODDISCOUNT = v_Rec.CODDISCOUNT;
      
      INSERT INTO DISCOUNT (CODDISCOUNT, CODCRITERIU, SUBUNITATEA, CODCRITERIU1, CODTIPSEDIU) VALUES (vCod, RecID, V_REC.SUBUNITATEA, V_REC.CODCRITERIU1, V_REC.CODTIPSEDIU);

     -- ma asigur ca daca limita superioara este 0 trebuie s-o pun null 
      SELECT COUNT(*) INTO NR FROM TMP_DISCINTERVAL WHERE CODDISCOUNT = VCOD;
      I := 0;
      FOR V_RECINTERVAL IN
      (
       SELECT * FROM TMP_DISCINTERVAL WHERE CODDISCOUNT = VCOD ORDER BY LIMINF, LIMSUP
      )
      LOOP
         I := I + 1;
         IF I = NR AND V_RECINTERVAL.LIMSUP = 0 THEN
           UPDATE TMP_DISCINTERVAL
           SET 
            LIMSUP = NULL
           WHERE
            CODDISCINTERVAL = V_RECINTERVAL.CODDISCINTERVAL; 
         END IF;
      END LOOP;
    END LOOP;

    -- detaliu DISCINTERVAL
    INSERT INTO DISCINTERVAL (CODDISCINTERVAL, CODDISCOUNT, LIMINF, LIMSUP, PROCENT)
    (SELECT SEQ_DISCINTERVAL_CODDISCINTERV.NEXTVAL, CODDISCOUNT, LIMINF, LIMSUP, PROCENT FROM TMP_DISCINTERVAL); 

    -- detaliu DISCART
    INSERT INTO DISCART (CODDISCART, CODDISCOUNT, CODOBIECT, CODCLASA, GRUPA)
    (SELECT SEQ_DISCART_CODDISCART.NEXTVAL, CODDISCOUNT, CODOBIECT, CODCLASA, GRUPA FROM TMP_DISCART); 

    -- detaliu DISCEXCEPTII
    INSERT INTO DISCEXCEPTII (CODDISCEXCEPTIE, CODDISCOUNT, CODOBIECT)
    (SELECT SEQ_DISCEXCEPTII_COD.NEXTVAL, CODDISCOUNT, CODOBIECT FROM TMP_DISCEXCEPTII); 



  END IF;
  NotifyModif(Operation, RecId, &apos;CRITERIIDISC&apos;);
  COMMIT;
END;


PROCEDURE COPIE_DISCOUNT(aCODCRITERIU1 NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
  aCODCRITERIU1_NOU NUMBER(20);  
  aNEWCODDISC       NUMBER(20);
BEGIN
  FOR V_REC_CR IN (SELECT * FROM CRITERIIDISC1 WHERE CODCRITERIU1 = aCODCRITERIU1)
  LOOP  
    FOR V_REC_SUB IN (SELECT * FROM TMP_MANEVRA) LOOP
      BEGIN
        SELECT  CODCRITERIU1 INTO aCODCRITERIU1_NOU FROM CRITERIIDISC1     
        WHERE
          CODCRITERIU = V_REC_CR.CODCRITERIU
          AND DATASTART = V_REC_CR.DATASTART
          AND SUBUNITATEA = V_REC_SUB.CODUNIC;
        EXCEPTION WHEN OTHERS THEN aCODCRITERIU1_NOU := 0;  
      END;        
      
      IF aCODCRITERIU1_NOU = 0 THEN
        aCODCRITERIU1_NOU := SEQ_CRITERIIDISC1_CODCRITERIU1.NEXTVAL;
        INSERT INTO CRITERIIDISC1(CODCRITERIU1, CODCRITERIU, DATASTART, SUBUNITATEA)  
                    VALUES       (aCODCRITERIU1_NOU, V_REC_CR.CODCRITERIU, V_REC_CR.DATASTART, V_REC_SUB.CODUNIC);
      END IF;  

      FOR V_REC_OLDDISC IN (SELECT * FROM DISCOUNT WHERE CODCRITERIU1 = aCODCRITERIU1_NOU)
      LOOP
        DELETE FROM DISCINTERVAL WHERE CODDISCOUNT = V_REC_OLDDISC.CODDISCOUNT;
        DELETE FROM DISCART     WHERE CODDISCOUNT = V_REC_OLDDISC.CODDISCOUNT;
        DELETE FROM DISCOUNT    WHERE CODDISCOUNT = V_REC_OLDDISC.CODDISCOUNT;
      END LOOP;    
      
      FOR V_REC_NEWDISC IN (SELECT * FROM DISCOUNT WHERE CODCRITERIU1 = V_REC_CR.CODCRITERIU1)
      LOOP
        aNEWCODDISC := SEQ_DISCOUNT_CODDISCOUNT.NEXTVAL;
        INSERT INTO DISCOUNT(CODDISCOUNT, CODCRITERIU, SUBUNITATEA, CODCRITERIU1, CODTIPSEDIU)
        VALUES (aNEWCODDISC, V_REC_CR.CODCRITERIU, V_REC_SUB.CODUNIC, aCODCRITERIU1_NOU, V_REC_NEWDISC.CODTIPSEDIU);

        INSERT INTO DISCINTERVAL(CODDISCINTERVAL, CODDISCOUNT, LIMINF, LIMSUP, PROCENT)
        SELECT SEQ_DISCINTERVAL_CODDISCINTERV.NEXTVAL, aNEWCODDISC, LIMINF, LIMSUP, PROCENT
        FROM 
          DISCINTERVAL
        WHERE
          CODDISCOUNT = V_REC_NEWDISC.CODDISCOUNT;
          
        INSERT INTO DISCART (CODDISCART, CODDISCOUNT, CODOBIECT, CODCLASA, GRUPA) 
        SELECT SEQ_DISCART_CODDISCART.NEXTVAL, aNEWCODDISC, CODOBIECT, CODCLASA, GRUPA 
        FROM 
          DISCART
        WHERE
          CODDISCOUNT = V_REC_NEWDISC.CODDISCOUNT;
      END LOOP;      
    END LOOP;    
  END LOOP;  
  COMMIT;  
END;  

END pkg_CriteriiDiscount; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CUPLARE_FIRME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C038B40B9C2D2FB0E4FF3AE4062CF6EEE6E77EDF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CUPLARE_FIRME IS

FUNCTION GET_COD_FIRMA(aID IN VARCHAR2) RETURN NUMBER
IS 
aCOD NUMBER(20) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT COD INTO aCOD FROM FIRMECUPLATE WHERE ID = aID;
    EXCEPTION WHEN OTHERS THEN aCOD := 0;
  END;  
  IF aCOD = 0 THEN 
     SELECT SEQ_FIRMECUPLATE_COD.NEXTVAL INTO aCOD FROM DUAL;
     INSERT INTO FIRMECUPLATE (COD, ID) VALUES (aCOD, aID);
     COMMIT;
  END IF;
  RETURN aCOD;
END;

PROCEDURE SP_GETDATA
IS
BEGIN
  DELETE TMP_FIRMECUPLATE;
  DELETE TMP_NCONTFIRMECUPL;
  DELETE TMP_NCONTCOMUN;
  
  
  INSERT INTO TMP_FIRMECUPLATE(COD, ID) SELECT COD, ID FROM FIRMECUPLATE;
  
 -- INSERT INTO TMP_NCONTFIRMECUPL (CODUNIC, CODFIRMACUPL, CODCONT, CODCONTCOMUN)
 -- SELECT CODUNIC, CODFIRMACUPL, CODCONT, CODCONTCOMUN FROM NCONTFIRMECUPL;


  INSERT INTO TMP_NCONTFIRMECUPL SELECT * FROM NCONTFIRMECUPL;


  INSERT INTO TMP_NCONTCOMUN SELECT * FROM NCONTCOMUN;


  COMMIT;
END;

PROCEDURE SP_POSTDATA
IS
 aCOD NUMBER(20);
 NR NUMBER(20) := 0;
BEGIN
   
  FOR V_REC IN (SELECT * FROM TMP_FIRMECUPLATE WHERE COD &lt; 0 AND NVL(CUPLATA, 0) = 1)
  LOOP
    SELECT SEQ_FIRMECUPLATE_COD.NEXTVAL INTO aCOD FROM DUAL;

    UPDATE TMP_NCONTFIRMECUPL
    SET
      CODFIRMACUPL = aCOD
    WHERE
     CODFIRMACUPL = V_REC.COD;
      
    INSERT INTO FIRMECUPLATE (COD, ID) VALUES (aCod, V_REC.ID);
  END LOOP;
  
  
  DELETE FROM NCONTCOMUN CC 
  WHERE 
    NOT EXISTS (SELECT CODCONT FROM TMP_NCONTCOMUN WHERE CODCONT = CC.CODCONT);
  
 
 
 
-- la TMP_NPARTCOMUN alta logica in recodificari datorita lui CodParinte
 FOR V_REC IN (SELECT * FROM TMP_NCONTCOMUN WHERE CODCONT &lt; 0)
 LOOP
   SELECT SEQ_NCONTCOMUN_COD.NEXTVAL INTO aCOD FROM DUAL;

   UPDATE TMP_NCONTFIRMECUPL
   SET
    CODCONTCOMUN = aCOD
   WHERE 
     CODCONTCOMUN = V_REC.CODCONT; 


    UPDATE TMP_NCONTCOMUN 
    SET
     CODCONT = aCOD
    WHERE
     CODCONT = V_REC.CODCONT; 

    UPDATE TMP_NCONTCOMUN 
    SET
     CODPARINTE = aCOD
    WHERE
     CODPARINTE = V_REC.CODCONT; 

    
/*
   INSERT INTO NCONTCOMUN (CODUNIC, SIMBOL, CLASA, TIPCONT, BALSINT, NIVEL, SOLDID, SOLDVID, SOLDIC, SOLDVIC, RULAJPD, RULAJVPD, RULAJPC, RULAJVPC, RULAJCD, RULAJVCD, RULAJCC, RULAJVCC, CODPARINTE, DEN_CONT, NRANALITICE) 
   VALUES (aCOD, V_REC.SIMBOL, V_REC.CLASA, V_REC.TIPCONT, V_REC.BALSINT, V_REC.NIVEL, V_REC.SOLDID, V_REC.SOLDVID, V_REC.SOLDIC, V_REC.SOLDVIC, V_REC.RULAJPD, V_REC.RULAJVPD, V_REC.RULAJPC, V_REC.RULAJVPC, V_REC.RULAJCD, V_REC.RULAJVCD, V_REC.RULAJCC, V_REC.RULAJVCC, V_REC.CODPARINTE, V_REC.DEN_CONT, V_REC.NRANALITICE);
*/
 END LOOP; 
 

 FOR V_REC IN (SELECT * FROM TMP_NCONTCOMUN)
 LOOP

   BEGIN
     SELECT COUNT(*) INTO NR FROM NCONTCOMUN WHERE CODCONT = V_REC.CODCONT;
     EXCEPTION WHEN OTHERS THEN NR := 0;
   END ;
   
    
  IF NR = 0 THEN  
   INSERT INTO NCONTCOMUN (CODCONT, SIMBOL, CLASA, TIPCONT, BALSINT, NIVEL, SOLDID, SOLDVID, SOLDIC, SOLDVIC, RULAJPD, RULAJVPD, RULAJPC, RULAJVPC, RULAJCD, RULAJVCD, RULAJCC, RULAJVCC, CODPARINTE, DEN_CONT, NRANALITICE, VIZIBILBALANTA) 
   VALUES (V_REC.CODCONT, V_REC.SIMBOL, V_REC.CLASA, V_REC.TIPCONT, V_REC.BALSINT, V_REC.NIVEL, V_REC.SOLDID, V_REC.SOLDVID, V_REC.SOLDIC, V_REC.SOLDVIC, V_REC.RULAJPD, V_REC.RULAJVPD, V_REC.RULAJPC, V_REC.RULAJVPC, V_REC.RULAJCD, V_REC.RULAJVCD, V_REC.RULAJCC, V_REC.RULAJVCC, V_REC.CODPARINTE, V_REC.DEN_CONT, V_REC.NRANALITICE, V_REC.VIZIBILBALANTA);
  ELSE  
   UPDATE NCONTCOMUN
   SET
     SIMBOL         = V_REC.SIMBOL, 
     CLASA          = V_REC.CLASA,
     TIPCONT        = V_REC.TIPCONT, 
     BALSINT        = V_REC.BALSINT, 
     NIVEL          = V_REC.NIVEL,
     SOLDID         = V_REC.SOLDID, 
     SOLDVID        = V_REC.SOLDVID, 
     SOLDIC         = V_REC.SOLDIC ,
     SOLDVIC        = V_REC.SOLDVIC,   
     RULAJPD        = V_REC.RULAJPD,
     RULAJVPD       = V_REC.RULAJVPD,
     RULAJPC        = V_REC.RULAJPC,
     RULAJVPC       = V_REC.RULAJVPC,
     RULAJCD        = V_REC.RULAJCD,
     RULAJVCD       = V_REC.RULAJVCD,
     RULAJCC        = V_REC.RULAJCC,
     RULAJVCC       = V_REC.RULAJVCC,  
     CODPARINTE     = V_REC.CODPARINTE,
     DEN_CONT       = V_REC.DEN_CONT, 
     NRANALITICE    = V_REC.NRANALITICE,
     VIZIBILBALANTA = V_REC.VIZIBILBALANTA
   WHERE
     CODCONT = V_REC.CODCONT;  
  END IF; 
 END LOOP; 


  DELETE FROM NCONTFIRMECUPL C 
  WHERE 
   EXISTS (SELECT CODFIRMACUPL FROM TMP_FIRMECUPLATE WHERE NVL(CUPLATA, 0) = 1 AND CODFIRMACUPL = C.CODFIRMACUPL)
   AND NOT EXISTS (SELECT CODUNIC FROM TMP_NCONTFIRMECUPL T WHERE T.CODUNIC = C.CODUNIC);
  
  FOR V_REC IN (SELECT * FROM TMP_NCONTFIRMECUPL WHERE CODUNIC &lt; 0)
  LOOP
    INSERT INTO NCONTFIRMECUPL 
    (CODUNIC, CODFIRMACUPL, CODCONT, CODCONTCOMUN, SIMBOLCONTCOMUN, SIMBOL, CLASA, TIPCONT, BALSINT, NIVEL, SOLDID, SOLDVID, SOLDIC, SOLDVIC, RULAJPD, RULAJVPD, RULAJPC, RULAJVPC, RULAJCD, RULAJVCD, RULAJCC, RULAJVCC, CODPARINTE, DEN_CONT, NRANALITICE, VIZIBILBALANTA)
     VALUES (SEQ_NCONTFIRMECUPL_CODUNIC.NEXTVAL, V_REC.CODFIRMACUPL, V_REC.CODCONT, V_REC.CODCONTCOMUN, V_REC.SIMBOLCONTCOMUN, V_REC.SIMBOL, V_REC.CLASA, V_REC.TIPCONT, V_REC.BALSINT, V_REC.NIVEL, V_REC.SOLDID, V_REC.SOLDVID, V_REC.SOLDIC, V_REC.SOLDVIC, V_REC.RULAJPD, V_REC.RULAJVPD, V_REC.RULAJPC, V_REC.RULAJVPC, V_REC.RULAJCD, V_REC.RULAJVCD, V_REC.RULAJCC, V_REC.RULAJVCC, V_REC.CODPARINTE, V_REC.DEN_CONT, V_REC.NRANALITICE, V_REC.VIZIBILBALANTA);
  END LOOP;
  

  FOR V_REC IN (SELECT * FROM TMP_NCONTFIRMECUPL WHERE CODUNIC &gt; 0)
  LOOP
    UPDATE NCONTFIRMECUPL
    SET
     CODFIRMACUPL     = V_REC.CODFIRMACUPL,  
     CODCONT          = V_REC.CODCONT, 
     CODCONTCOMUN     = V_REC.CODCONTCOMUN,
     SIMBOLCONTCOMUN  = V_REC.SIMBOLCONTCOMUN,
     SIMBOL           = V_REC.SIMBOL, 
     CLASA            = V_REC.CLASA,
     TIPCONT          = V_REC.TIPCONT, 
     BALSINT          = V_REC.BALSINT, 
     NIVEL            = V_REC.NIVEL,
     SOLDID           = V_REC.SOLDID, 
     SOLDVID          = V_REC.SOLDVID, 
     SOLDIC           = V_REC.SOLDIC ,
     SOLDVIC          = V_REC.SOLDVIC,   
     RULAJPD          = V_REC.RULAJPD,
     RULAJVPD         = V_REC.RULAJVPD,
     RULAJPC          = V_REC.RULAJPC,
     RULAJVPC         = V_REC.RULAJVPC,
     RULAJCD          = V_REC.RULAJCD,
     RULAJVCD         = V_REC.RULAJVCD,
     RULAJCC          = V_REC.RULAJCC,
     RULAJVCC         = V_REC.RULAJVCC,  
     CODPARINTE       = V_REC.CODPARINTE,
     DEN_CONT         = V_REC.DEN_CONT, 
     NRANALITICE      = V_REC.NRANALITICE,
     VIZIBILBALANTA   = V_REC.VIZIBILBALANTA
    WHERE
     CODUNIC = V_REC.CODUNIC;  
  END LOOP;


    
    


  COMMIT;
  
END; 


end PKG_CUPLARE_FIRME; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CURSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29CE75ADCE8756803ACA669E9C779E0B147836C2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CURSURI IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodCurs INTO Tmp FROM CURSURI WHERE CodCurs = RecId FOR UPDATE NOWAIT;
END;
  
  
PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CURSURI1 WHERE CodCurs = RecId ;
  DELETE FROM CURSURI  WHERE CodCurs = RecId ;
  NotifyModif(2, RecId, &apos;CURSURI&apos;);
  COMMIT;
END;
  
PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_CURSURI FIELDS( CodCurs ) VALUES (0) ;
  COMMIT;
END;
  
PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master CURSURI
  INSERT INTO  TMP_CURSURI ( CodCurs, Den_Curs)
    ( SELECT CodCurs, Den_Curs
    FROM CURSURI WHERE CodCurs = RecId ) ;
  
  INSERT INTO  TMP_CURSURI1 ( CodCurs1,CodCurs,IndexLocal,CodTema  )
    ( SELECT CodCurs1,CodCurs,IndexLocal,CodTema
      FROM CURSURI1 WHERE CodCurs = RecId ) ;
  -- TMP_NPERSCURSX
  INSERT INTO TMP_NPERSCURSX (CODNPERSCURS, CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN)
     select -RowNum, CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN 
     from 
        (Select NP.CodPers, NP.CodCurs,
               avg(Nvl(NP.STARE,0)) Stare,
               avg(NP.Nota) nota,
               (Select max(NP1.Data) from NPERSCURS NP1 where NP1.CODCURS = NP.CodCurs) Data,
               (Select min(NP1.Data) from NPERSCURS NP1 where NP1.CODCURS = NP.CodCurs) DataPlan
        from NPERSCURS NP where NP.CodCURS = RecID GROUP BY NP.CodPers, NP.CodCurs);

  COMMIT;
END;
  
  
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodCurs INTO RecId FROM TMP_CURSURI;
    
    UPDATE CURSURI SET ( Den_Curs )
                       = ( SELECT Den_Curs FROM TMP_CURSURI )
    WHERE CodCurs = RecId ;
  
    DELETE FROM CURSURI1 where CodCurs = RecId and CodCurs1 not in (Select CodCurs1 from TMP_CURSURI1);
    FOR v_rec IN ( SELECT * FROM TMP_CURSURI1 WHERE CodCurs1 &gt; 0 ) LOOP
       UPDATE CURSURI1
       SET
        INDEXLOCAL  = V_REC.INDEXLOCAL, 
        CODTEMA     = V_REC.CODTEMA 
       WHERE CodCurs1  = v_rec.CodCurs1;
    END LOOP;

    INSERT INTO CURSURI1 
    ( CodCurs1, CodCurs, IndexLocal,CodTema)
    SELECT SEQ_CURSURI1_CodCurs1.Nextval , RecId , IndexLocal,CodTema
    FROM TMP_CURSURI1 WHERE CodCurs1 &lt; 0;

  
  ELSE  -- INSERT
 
    SELECT Seq_CURSURI_CodCurs.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO  CURSURI ( CodCurs, Den_Curs)
              ( SELECT  RecId , Den_Curs
                FROM Tmp_CURSURI ) ;

    INSERT INTO CURSURI1 
    ( CodCurs1, CodCurs, IndexLocal,CodTema)
    SELECT SEQ_CURSURI1_CodCurs1.Nextval , RecId , IndexLocal,CodTema
    FROM TMP_CURSURI1;

  END IF;
  NotifyModif(Operation, RecId, &apos;CURSURI&apos;);
  
  COMMIT;
  
END;



END PKG_CURSURI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CUSTODIEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD77582D8DEDFA28D8B01C8EC5A2C00EE70187C2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CUSTODIEINI IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodCUSTODIE INTO Tmp FROM CUSTODIEINI WHERE CodCustodie = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCODPART NUMBER(20, 0);
BEGIN
  SP_LOCKRECORD(RecId);
  SELECT CODPART INTO aCODPART FROM CUSTODIEINI WHERE CODCUSTODIE = RECID;

  DELETE CUSTODIEINI WHERE CodCustodie = RecId;

  FOR V_REC IN
 (SELECT CODIES FROM IESIRI I
   WHERE
     I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
     AND I.TIPDOC = 20
     AND NVL(I.CUSTODIE, 0) = 1
     AND I.PARTENER = aCODPART
  )
  LOOP
    DELETE FROM IESIRI1 WHERE CODIES = V_REC.CODIES;
    DELETE FROM IESIRI  WHERE CODIES = V_REC.CODIES;
  END LOOP;
  NotifyModif(2, RecId, &apos;CUSTODIEINI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_CUSTODIEINI FIELDS( CodCUSTODIE) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCODPART NUMBER(20) := 0;
BEGIN

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO TMP_CUSTODIEINI (CODCUSTODIE, CODPART)
  ( SELECT
     CODCUSTODIE,
     CODPART
    FROM
     CUSTODIEINI C
    WHERE CodCustodie = RecId
    );


  SELECT CODPART INTO aCODPART FROM TMP_CUSTODIEINI;

  INSERT INTO TMP_IESIRI
  (
   CODIES,
   TIPDOC,
   ANULAT,
   BLOCAT,
   OPERAT,
   PREFIXDOC,
   NRDOC,
   DATADOC,
   PARTENER,
   OBS,
   CODLOCATIE,
   SUBUNITATEA,
   MONEDA,
   CURS,
   AGENT
  )
  SELECT
    CODIES,
    TIPDOC,
    ANULAT,
    BLOCAT,
    OPERAT,
    PREFIXDOC,
    NRDOC,
    DATADOC,
    PARTENER,
    OBS,
    CODLOCATIE,
    SUBUNITATEA,
    MONEDA,
    CURS,
    AGENT
  FROM
    IESIRI I
  WHERE
    I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
    AND I.TIPDOC = 20
    AND NVL(I.CUSTODIE, 0) = 1
    AND I.PARTENER = aCODPART;

  INSERT INTO TMP_IESIRI1
    (CODIES1,  CODIES,    INDEXLOCAL,  TIPLINIE,       UMSEC,
     CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT,   CODOBIECT,   PRETORIG,       PU,
     CANT,     TVA,       CONT,        PROCDISC,       ADDIM,
     RESTFACT, PUMAXIMAL, GARANTIE,    DENUM,          VALOARE,
     PARITATE, PROCTVA,   CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS,
     CODOBIECTORIG,
     PARITATEORIG,
     CODIOARTCUST,
     CODTVA,
     CODACCIZE,
     CODTAXA1,
     CODTAXA2,
     CODCLASA,
     PUCORELAT,
     DENOBIECT
  )
  SELECT
    I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC,
    I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU, I1.MIFIX, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * NVL(U1.PARITATE,1),
    I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM,
    I1.RESTFACT,
    I1.PUMAXIMAL, I1.GARANTIE,
    CASE
      WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
      ELSE U1.DEN_UM1
    END,
    CASE
      WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
      ELSE I1.RESTFACT
    END,
    U1.PARITATE,
    CASE
      WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
      ELSE 0
    END,
    I1.CODOBLIGSTORNO,
    I1.CURSFACTURAAVANS,
    I1.COEFDISCMAJ, I1.OBS,
    I1.CODOBIECTORIG,
    I1.PARITATEORIG,
    I1.CODIOARTCUST,
    NART1LUNA.CODTVA,
    NART1LUNA.CODACCIZE,
    NART1LUNA.CODTAXA1,
    NART1LUNA.CODTAXA2,
    A.CLASA,
    I1.PUCORELAT,
    O.DENUMIRE
  FROM IESIRI1 I1
    LEFT JOIN NARTOBJ O       ON O.CODOBIECT  = I1.CODOBIECT
    LEFT JOIN NART A          ON A.CODARTICOL = O.CODARTICOL
    LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND PKG_GLOBALS.AnLunaLucru BETWEEN NART1LUNA.ALStart AND NART1LUNA.ALStop
    LEFT JOIN NUM1 U1         ON U1.CODUM1    = I1.UMSEC
  WHERE EXISTS (SELECT CODIES FROM TMP_IESIRI WHERE CODIES = I1.CODIES);

  UPDATE TMP_IESIRI1 I1
  SET
    CODLINIEDOCIMP = PKG_IESIRI.LINIEAVIZSTINSA_EXT(I1.CODIES1),
    DISPLIVR = (SELECT DIFPRET FROM TMP_IOART_LUNA WHERE CODIOART = I1.CODIOARTCUST);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 VCOD     NUMBER(20) := 0;
 ACODPART NUMBER(20) := 0;
 NR       NUMBER(20) := 0;
BEGIN
  SELECT CODPART INTO aCODPART FROM TMP_CUSTODIEINI;


  IF Operation = 0 THEN

    RecID := aCodPart;

    UPDATE CUSTODIEINI
    SET
      CODPART = (SELECT CODPART FROM TMP_CUSTODIEINI)
    WHERE
      CODCUSTODIE = RECID;

-- stergeri IESIRI1
      FOR V_REC IN
      (
        SELECT
         I1.CODIES1
        FROM
          IESIRI I,
          IESIRI1 I1
        WHERE
          I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
          AND I.TIPDOC = 20
          AND NVL(I.CUSTODIE, 0) = 1
          AND I.PARTENER = aCODPART
          AND I1.CODIES = I.CODIES
          AND NOT EXISTS (SELECT CODIES1 FROM TMP_IESIRI1 WHERE CODIES1 = I1.CODIES1)
       )
       LOOP
         DELETE FROM IESIRI1 WHERE CODIES1 = V_REC.CODIES1;
       END LOOP;

-- stergeri IESIRI
    DELETE
    FROM
      IESIRI I
    WHERE
      I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
      AND I.TIPDOC = 20
      AND NVL(I.CUSTODIE, 0) = 1
      AND I.PARTENER = aCODPART
      AND NOT EXISTS (SELECT CODIES FROM TMP_IESIRI WHERE CODIES = I.CODIES);



       FOR V_REC IN (SELECT * FROM TMP_IESIRI)
       LOOP
         IF V_REC.CODIES &gt; 0 THEN
           UPDATE IESIRI
           SET
             TIPDOC       = 20,
             MONEDA       = V_REC.MONEDA,
             CURS         = V_REC.CURS,
             NRDOC        = V_REC.NRDOC,
             DATADOC      = V_REC.DATADOC,
             CODLOCATIE   = V_REC.CODLOCATIE,
             OBS          = V_REC.OBS,
             SUBUNITATEA  = V_REC.SUBUNITATEA,
             PARTENER     = V_REC.PARTENER,
             CUSTODIE     = 1,
             INITIALIZARI = 1,
             VALDOC       = (SELECT SUM(VALOARE + TVA) FROM TMP_IESIRI1 WHERE CODIES = V_REC.CODIES),
             AGENT        = V_REC.AGENT
           WHERE
             CODIES = V_REC.CODIES;


           SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = V_REC.CODIES;
           IF NR = 0 THEN
              INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS)
              VALUES (SEQ_GENERAL_CODGENERAL.NEXTVAL, 20, V_REC.CODIES, V_REC.MONEDA, V_REC.CURS);
           ELSE
             UPDATE GENERAL
             SET
               MONEDA = V_REC.MONEDA,
               CURS   = V_REC.CURS
             WHERE
              TIPDOC = 20 AND CODDOC = V_REC.CODIES;
           END IF;
         ELSE
          SELECT SEQ_IESIRI_CODIES.NEXTVAL INTO VCOD FROM DUAL;
          UPDATE TMP_IESIRI1 I1
          SET
            CODIES = VCOD
          WHERE
           I1.CODIES = V_REC.CODIES;

          INSERT INTO IESIRI (CODIES,
                              PREFIXDOC,
                              TIPDOC,
                              ANULAT,
                              OPERAT,
                              PARTENER,
                              NRDOC,
                              MONEDA,
                              CURS,
                              OBS,
                              DATADOC,
                              CODLOCATIE,
                              SUBUNITATEA,
                              AN,
                              LUNA,
                              CUSTODIE,
                              INITIALIZARI,
                              VALDOC,
                              AGENT
                              )
                             VALUES
                             (VCOD,
                             &apos;AE&apos;,
                              20,
                              0,
                              1,
                              V_REC.PARTENER,
                              V_REC.NRDOC,
                              V_REC.MONEDA,
                              V_REC.CURS,
                              V_REC.OBS,
                              V_REC.DATADOC,
                              V_REC.CODLOCATIE,
                              V_REC.SUBUNITATEA,
                              V_REC.AN,
                              V_REC.LUNA,
                              V_REC.CUSTODIE,
                              1,
                              (SELECT SUM(VALOARE + TVA) FROM TMP_IESIRI1 WHERE CODIES = V_REC.CODIES),
                              V_REC.AGENT
                              );


          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS)
          VALUES (SEQ_GENERAL_CODGENERAL.NEXTVAL, 20, VCOD, V_REC.MONEDA, V_REC.CURS);

         END IF;
       END LOOP;

       FOR V_REC IN (SELECT * FROM TMP_IESIRI1)
       LOOP
         IF V_REC.CODIES1 &lt; 0 THEN
            SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO VCOD FROM DUAL;

            INSERT INTO IESIRI1
                ( CODIES1,
                  CODIES,
                  INDEXLOCAL,
                  TIPLINIE,
                  UMSEC,
                  CONTSERV,
                  CONTDISCOUNT,
                  CODCRITERIU,
                  MIFIX,
                  GESTACT,
                  CODOBIECT,
                  PRETORIG,
                  PU,
                  CANT,
                  TVA,
                  CONT,
                  PROCDISC,
                  ADDIM,
                  RESTFACT,
                  PUMAXIMAL,
                  TIPLIVRARE,
                  GARANTIE,
                  CODOBLIGSTORNO,
                  CURSFACTURAAVANS,
                  COEFDISCMAJ,
                  OBS,
                  CODOBIECTORIG,
                  PARITATEORIG,
                  CODIOARTCUST,
                  PUCORELAT )
            VALUES
                ( VCOD,
                  V_REC.CODIES,
                  V_REC.INDEXLOCAL,
                  V_REC.TIPLINIE,
                  V_REC.UMSEC,
                  V_REC.CONTSERV,
                  V_REC.CONTDISCOUNT,
                  V_REC.CODCRITERIU,
                  V_REC.MIFIX,
                  V_REC.GESTACT,
                  V_REC.CODOBIECT,
                  V_REC.PRETORIG,
                  V_REC.PU / NVL(V_REC.PARITATE,1),
                  V_REC.CANT * NVL(V_REC.PARITATE, 1),
                  V_REC.TVA,
                  V_REC.CONT,
                  V_REC.PROCDISC,
                  V_REC.ADDIM,
                  CASE
                    WHEN V_REC.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)  THEN V_REC.CANT * V_REC.PARITATE
                    WHEN V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;)  THEN V_REC.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
                    ELSE 0
                  END,
                  V_REC.PUMAXIMAL, V_REC.TIPLIVRARE, V_REC.GARANTIE, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS,
                  V_REC.COEFDISCMAJ,
                  V_REC.OBS,
                  V_REC.CODOBIECTORIG,
                  V_REC.PARITATEORIG,
                  V_REC.CODIOARTCUST,
                  V_REC.PUCORELAT
                 );
         ELSE
           UPDATE IESIRI1
           SET
             INDEXLOCAL   = V_REC.INDEXLOCAL,
             TIPLINIE     = V_REC.TIPLINIE,
             UMSEC        = V_REC.UMSEC,
             CONTSERV     = V_REC.CONTSERV,
             CODOBIECT    = V_REC.CODOBIECT,
             PRETORIG     = V_REC.PRETORIG,
             PUCORELAT    = V_REC.PUCORELAT,
             GESTACT      = V_REC.GESTACT,
             PU           = V_REC.PU / NVL(V_REC.PARITATE, 1),
             CANT         = V_REC.CANT * NVL(V_REC.PARITATE, 1),
             TVA          = V_REC.TVA,
             CONT         = V_REC.CONT,
             CODIOARTCUST = V_REC.CODIOARTCUST,
             RESTFACT     =
                 V_REC.Cant * V_REC.Paritate -
                   (SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                      IESLINK IL
                      LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                      LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                    WHERE
                      IL.CODLINIEAVIZ = V_REC.CodIES1 AND I.TIPDOC = 26 AND I.OPERAT = 1 AND I.ANULAT = 0
                   )
                  +
                 (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                  FROM
                    IESIRI1 AE1,
                    IESIRI  AE
                  WHERE
                    AE1.CODIES1STORNO = V_REC.CODIES1 AND AE.CODIES = AE1.CODIES
                    AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
                  )
           WHERE
             CODIES1 = V_REC.CODIES1;
         END IF;
       END LOOP;

  ELSE
    SELECT SEQ_CUSTODIEINI_CODCUSTODIE.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO CUSTODIEINI (CODCUSTODIE, CODPART)
    SELECT RECID, CODPART FROM  TMP_CUSTODIEINI;

    FOR V_REC IN (SELECT * FROM TMP_IESIRI)
    LOOP
      SELECT SEQ_IESIRI_CODIES.NEXTVAL INTO VCOD FROM DUAL;
      UPDATE TMP_IESIRI1 I1
      SET
        CODIES = VCOD
      WHERE
       I1.CODIES = V_REC.CODIES;

      INSERT INTO IESIRI (CODIES,
                          PREFIXDOC,
                          TIPDOC,
                          ANULAT,
                          OPERAT,
                          PARTENER,
                          NRDOC,
                          OBS,
                          DATADOC,
                          MONEDA,
                          CURS,
                          CODLOCATIE,
                          SUBUNITATEA,
                          AN,
                          LUNA,
                          CUSTODIE,
                          VALDOC,
                          INITIALIZARI,
                          AGENT
                          )
                         VALUES
                         (VCOD,
                         &apos;AE&apos;,
                          20,
                          0,
                          1,
                          V_REC.PARTENER,
                          V_REC.NRDOC,
                          V_REC.OBS,
                          V_REC.DATADOC,
                          V_REC.MONEDA,
                          V_REC.CURS,
                          V_REC.CODLOCATIE,
                          V_REC.SUBUNITATEA,
                          V_REC.AN,
                          V_REC.LUNA,
                          V_REC.CUSTODIE,
                          (SELECT SUM(VALOARE + TVA) FROM TMP_IESIRI1 WHERE CODIES = V_REC.CODIES),
                          1,
                          V_REC.AGENT

);


      INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS)
      VALUES (SEQ_GENERAL_CODGENERAL.NEXTVAL, 20, VCOD, V_REC.MONEDA, V_REC.CURS);
    END LOOP;

    FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1)
    LOOP
        SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO VCOD FROM DUAL;

        INSERT INTO IESIRI1
            ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG, PU,
              CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TIPLIVRARE, GARANTIE,  CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG, CODIOARTCUST, PUCORELAT )
        VALUES
            ( VCOD, V_RECIESIRI1.CODIES, V_RECIESIRI1.INDEXLOCAL,  V_RECIESIRI1.TIPLINIE,  V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT,
              V_RECIESIRI1.PRETORIG,  V_RECIESIRI1.PU / NVL(V_RECIESIRI1.PARITATE,1), V_RECIESIRI1.CANT * NVL(V_RECIESIRI1.PARITATE, 1),
              V_RECIESIRI1.TVA, V_RECIESIRI1.CONT, V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,

              CASE
                WHEN V_RECIESIRI1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)  THEN V_RECIESIRI1.CANT * V_RECIESIRI1.PARITATE
                WHEN V_RECIESIRI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;)  THEN V_RECIESIRI1.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
                ELSE 0
              END,
              V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG, V_RECIESIRI1.CODIOARTCUST, V_RECIESIRI1.PUCORELAT
             );
    END LOOP;

  END IF;
  NotifyModif(Operation, RecId, &apos;CUSTODIEINI&apos;);
  COMMIT;
END;
end PKG_CUSTODIEINI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_CUSTOMFORM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FCD26560E7F063C4AF48D972E3A3726102749782</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_CUSTOMFORM IS

PROCEDURE SAVE_TABLES IS
BEGIN
  FOR vRec IN (
    SELECT &apos;TMP_&apos;||MP.TBLMASTER  AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm                                        UNION ALL
    SELECT &apos;TMP_&apos;||MP.TBLDETAIL1 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL1, &apos;&apos;) IS NOT NULL UNION ALL
    SELECT &apos;TMP_&apos;||MP.TBLDETAIL2 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL2, &apos;&apos;) IS NOT NULL UNION ALL
    SELECT &apos;TMP_&apos;||MP.TBLDETAIL3 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL3, &apos;&apos;) IS NOT NULL UNION ALL
    SELECT &apos;TMP_CUSTOMFORM_COD&apos;  AS TAB_NAME FROM DUAL                                                                                                     UNION ALL
    SELECT &apos;TMP_CUSTOMFORM_TAB&apos;  AS TAB_NAME FROM DUAL
  ) LOOP
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP TABLE SAV_&apos;||vRec.TAB_NAME||&apos; PURGE&apos;;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
    BEGIN
      EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_&apos;||vRec.TAB_NAME||&apos; AS SELECT * FROM &apos;||vRec.TAB_NAME;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;
END;

PROCEDURE SetCodCustom(aCod in Number) IS
BEGIN
  CodCustomForm := aCod;
END;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER ) IS
  cSQL CLOB;
BEGIN
  SELECT &apos;SELECT &apos;||uc.COLUMN_NAME||&apos; FROM &apos;||MP.TBLMASTER||&apos; WHERE &apos;||uc.COLUMN_NAME||&apos; = &apos;||RecId||&apos; FOR UPDATE NOWAIT&apos;
  INTO cSQL
  FROM WINMADMIN.MAKETEPROPRII MP INNER JOIN user_tab_columns uc ON uc.TABLE_NAME = Upper(MP.TBLMASTER) AND uc.column_id = 1
  WHERE MP.CODMAKETEPROPRII = CodCustomForm;

  EXECUTE IMMEDIATE cSQL;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  vTab_Master VARCHAR(100);
BEGIN
  SELECT Upper(MP.TBLMASTER) INTO vTab_Master FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm;
  FOR vRec IN (
    WITH /*RECURSIVE*/ xM (TAB_NAME, COL_0, TAB_Master, COL_LINK, COND_JOIN, COND_JOINP, NIVEL) AS (
      SELECT
        Upper(MP.TBLMASTER) AS TAB_NAME, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_0, Upper(MP.TBLMASTER) AS TAB_Master, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_LINK,
        CAST(&apos;&apos; AS VARCHAR2(4000)) AS COND_JOIN, CAST(&apos;&apos; AS VARCHAR2(4000)) AS COND_JOINP, 1 AS NIVEL
      FROM WINMADMIN.MAKETEPROPRII MP
      WHERE CODMAKETEPROPRII = CodCustomForm
      UNION ALL
      SELECT
        Upper(MP.TAB_NAME), Upper(XM.COL_0), Upper(MP.TAB_Master), Upper(MP.COL_LINK),
        &apos; INNER JOIN &apos;||MP.TAB_MASTER||&apos; tj&apos;||(XM.NIVEL-1)||&apos; ON tj&apos;||(XM.NIVEL-1)||&apos;.&apos;||MP.COL_LINK||&apos; = tj&apos;||XM.NIVEL||&apos;.&apos;||MP.COL_LINK AS COND_JOIN, XM.COND_JOIN||XM.COND_JOINP, XM.NIVEL + 1
      FROM (
        SELECT MP.TBLDETAIL1 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL1 AS COL_PK, MP.TBLMASTER1 AS TAB_Master, MP.LINKKEY1 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL1, &apos;&apos;) IS NOT NULL UNION ALL
        SELECT MP.TBLDETAIL2 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL2 AS COL_PK, MP.TBLMASTER2 AS TAB_Master, MP.LINKKEY2 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL2, &apos;&apos;) IS NOT NULL UNION ALL
        SELECT MP.TBLDETAIL3 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL3 AS COL_PK, MP.TBLMASTER3 AS TAB_Master, MP.LINKKEY3 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL3, &apos;&apos;) IS NOT NULL
      ) MP INNER JOIN XM ON xM.TAB_NAME = Upper(MP.TAB_Master)
    )
    SELECT
      NIVEL,
      CASE
        WHEN NIVEL = 1 THEN &apos;DELETE FROM &apos;||TAB_NAME||&apos; WHERE &apos;||COL_0||&apos; = &apos;||To_Char(RecId)
        WHEN NIVEL = 2 THEN &apos;DELETE FROM &apos;||TAB_NAME||&apos; WHERE &apos;||COL_LINK||&apos; = &apos;||To_Char(RecId)
        ELSE &apos;DELETE FROM &apos;||TAB_NAME||&apos; WHERE &apos;||COL_LINK||&apos; IN (SELECT tj&apos;||To_Char(nivel-2)||&apos;.&apos;||COL_LINK||&apos; FROM &apos;||TAB_MASTER||&apos; tj&apos;||To_Char(nivel-2)||COND_JOINP||&apos; WHERE tj0.&apos;||COL_0||&apos; = &apos;||To_Char(RecId)||&apos;)&apos;
      END sqlDelete
    FROM xM
    ORDER BY NIVEL DESC
  ) LOOP
    EXECUTE IMMEDIATE vRec.sqlDelete;
  END LOOP;
  NotifyModif(2, RecId, vTab_Master);
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
  cSQL CLOB;
BEGIN
  SELECT &apos;INSERT INTO TMP_&apos;||MP.TBLMASTER||&apos;( &apos;||uc.COLUMN_NAME||&apos;) VALUES (0)&apos;
  INTO cSQL
  FROM WINMADMIN.MAKETEPROPRII MP INNER JOIN user_tab_columns uc ON uc.TABLE_NAME = Upper(MP.TBLMASTER) AND uc.column_id = 1
  WHERE MP.CODMAKETEPROPRII = CodCustomForm;

  EXECUTE IMMEDIATE cSQL;
  COMMIT;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER) IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SOLVENRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER) IS
BEGIN
  IF (CARNETDOC_I &lt;&gt; 0) AND (NRDOC_I &lt;&gt; 0) AND (aCARNET &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I) THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNRDOC);
	SETNRDOC_I(aCARNET, aNRDOC);
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  sTabFields    VARCHAR2(3200);
  sSQLTmpFields VARCHAR2(3200);
  sExtTmpFields VARCHAR2(3200);
  cInsert       CLOB;
  cUpdate       CLOB;
BEGIN
  FOR vRec IN (
    WITH /*RECURSIVE*/ xM (TAB_NAME, COL_PK, TAB_Master, COL_LINK, NIVEL) AS (
      SELECT Upper(MP.TBLMASTER) AS TAB_NAME, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_PK, Upper(MP.TBLMASTER) AS TAB_Master, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_LINK, 1 AS NIVEL FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm
      UNION ALL
      SELECT Upper(MP.TAB_NAME), Upper(MP.COL_PK), Upper(MP.TAB_Master), Upper(MP.COL_LINK), XM.NIVEL + 1
      FROM (
        SELECT MP.TBLDETAIL1 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL1 AS COL_PK, MP.TBLMASTER1 AS TAB_Master, MP.LINKKEY1 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL1, &apos;&apos;) IS NOT NULL UNION ALL
        SELECT MP.TBLDETAIL2 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL2 AS COL_PK, MP.TBLMASTER2 AS TAB_Master, MP.LINKKEY2 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL2, &apos;&apos;) IS NOT NULL UNION ALL
        SELECT MP.TBLDETAIL3 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL3 AS COL_PK, MP.TBLMASTER3 AS TAB_Master, MP.LINKKEY3 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL3, &apos;&apos;) IS NOT NULL
      ) MP INNER JOIN XM ON xM.TAB_NAME = Upper(MP.TAB_Master)
    )
    SELECT
      NIVEL, TAB_NAME, COL_PK,
      &apos; WHERE &apos;||CASE WHEN NIVEL = 1 THEN COL_PK||&apos; = &apos;||To_Char(RecId) ELSE COL_LINK||&apos; IN (SELECT &apos;||COL_LINK||&apos; FROM TMP_&apos;||TAB_Master||&apos;)&apos; END WhereInsert
    FROM xM
    ORDER BY NIVEL
  ) LOOP
    sTabFields := NULL;
    FOR vColList IN (
      SELECT TC.COLUMN_NAME
      FROM USER_TABLES T
        INNER JOIN USER_TABLES   TT  ON TT.TABLE_NAME  = &apos;TMP_&apos;||T.TABLE_NAME AND TT.TEMPORARY = &apos;Y&apos;
        INNER JOIN USER_TAB_COLS TC  ON TC.TABLE_NAME  = T.TABLE_NAME
        INNER JOIN USER_TAB_COLS TTC ON TTC.TABLE_NAME = TT.TABLE_NAME AND TTC.COLUMN_NAME = TC.COLUMN_NAME
      WHERE UPPER(T.TABLE_NAME) = vRec.TAB_NAME AND T.TEMPORARY = &apos;N&apos;
      ORDER BY TC.COLUMN_ID
    ) LOOP
      IF sTabFields IS NULL
      THEN sTabFields :=                   vColList.Column_Name;
      ELSE sTabFields := sTabFields||&apos;, &apos;||vColList.Column_Name;
      END IF;
    END LOOP;

    EXECUTE IMMEDIATE &apos;DELETE FROM TMP_&apos;||vRec.TAB_NAME;
    IF sTabFields IS NOT NULL THEN
      cInsert := &apos;INSERT INTO TMP_&apos;||vRec.TAB_NAME||&apos;(&apos;||sTabFields||&apos;) SELECT &apos;||sTabFields||&apos; FROM &apos;||vRec.TAB_NAME||vRec.WhereInsert;
      EXECUTE IMMEDIATE cInsert;

      sSQLTmpFields := PKG_CFGTABLES.GET_EXT_SQL_TMP(vRec.TAB_NAME);
      IF sSQLTmpFields IS NOT NULL THEN
        sExtTmpFields := PKG_CFGTABLES.GET_EXT_FIELDS(vRec.TAB_NAME, 1);
        IF Length(sExtTmpFields) &gt; 0 THEN
          cUpdate :=
            &apos;UPDATE TMP_&apos;||vRec.TAB_NAME||&apos; t &apos;||Chr(10)||
            &apos;SET (       &apos;||sExtTmpFields||&apos;) &apos;||Chr(10)||
            &apos;  = (SELECT &apos;||sExtTmpFields||Chr(10)||
            &apos;     FROM (&apos;||sSQLTmpFields||&apos;) s &apos;||Chr(10)||
            &apos;     WHERE s.&apos;||vRec.COL_PK||&apos; = t.&apos;||vRec.COL_PK||&apos;) &apos;;
          BEGIN
            EXECUTE IMMEDIATE cUpdate;
          EXCEPTION
            WHEN OTHERS THEN
              NULL;
              --insert into x(view_name, test) select &apos;PKG_CUSTOMFORM_&apos;||to_char(CURRENT_TIMESTAMP, &apos;YYYYMMDD_HH24MMSS&apos;), cUpdate from dual;
          END;
        END IF;
      END IF;
    END IF;
  END LOOP;

  FOR vRec IN (
    SELECT CFGT.NUMETABELA, CFGT.UPDATESQL 
    FROM (
      SELECT MP.TBLDETAIL1 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL1, &apos;&apos;) IS NOT NULL UNION ALL
      SELECT MP.TBLDETAIL2 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL2, &apos;&apos;) IS NOT NULL UNION ALL
      SELECT MP.TBLDETAIL3 AS TAB_NAME FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL3, &apos;&apos;) IS NOT NULL
    ) DETT INNER JOIN CFGTABLES CFGT ON CFGT.NUMETABELA = DETT.TAB_NAME
  ) LOOP
    BEGIN
      EXECUTE IMMEDIATE vRec.UPDATESQL;
    EXCEPTION WHEN OTHERS THEN 
      NULL;
    END;
  END LOOP;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vTab_Count  NUMBER;
  vTab_Master VARCHAR2(50);
  vCol_Master VARCHAR2(50);
BEGIN
  --PG - CREATE TMP FLAG &apos;TMP_CUSTOMFORM&apos;
  SELECT Upper(MP.TBLMASTER), &apos;COD&apos;||Upper(MP.TBLMASTER)
  INTO vTab_Master, vCol_Master
  FROM WINMADMIN.MAKETEPROPRII MP
  WHERE CODMAKETEPROPRII = CodCustomForm;

  DELETE FROM TMP_CUSTOMFORM_COD;
  DELETE FROM TMP_CUSTOMFORM_TAB;
  INSERT INTO TMP_CUSTOMFORM_TAB(TAB_NAME, TAB_MASTER, COL_PK, COL_LINK, NIVEL, TAB_IDX)
  WITH /*RECURSIVE*/ xM (TAB_NAME, COL_PK, TAB_Master, COL_LINK, NIVEL) AS (
    SELECT Upper(MP.TBLMASTER) AS TAB_NAME, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_PK, Upper(MP.TBLMASTER) AS TAB_Master, &apos;COD&apos;||Upper(MP.TBLMASTER) AS COL_LINK, 1 AS NIVEL FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm
    UNION ALL
    SELECT Upper(MP.TAB_NAME), Upper(MP.COL_PK), Upper(MP.TAB_Master), Upper(MP.COL_LINK), XM.NIVEL + 1
    FROM (
      SELECT MP.TBLDETAIL1 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL1 AS COL_PK, MP.TBLMASTER1 AS TAB_Master, MP.LINKKEY1 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL1, &apos;&apos;) IS NOT NULL UNION ALL
      SELECT MP.TBLDETAIL2 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL2 AS COL_PK, MP.TBLMASTER2 AS TAB_Master, MP.LINKKEY2 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL2, &apos;&apos;) IS NOT NULL UNION ALL
      SELECT MP.TBLDETAIL3 AS TAB_NAME, &apos;COD&apos;||MP.TBLDETAIL3 AS COL_PK, MP.TBLMASTER3 AS TAB_Master, MP.LINKKEY3 AS COL_LINK FROM WINMADMIN.MAKETEPROPRII MP WHERE CODMAKETEPROPRII = CodCustomForm AND NULLIF(TBLDETAIL3, &apos;&apos;) IS NOT NULL
    ) MP INNER JOIN XM ON xM.TAB_NAME = Upper(MP.TAB_Master)
  )
  SELECT TAB_NAME, TAB_MASTER, COL_PK, COL_LINK, NIVEL, Row_Number () OVER (ORDER BY NIVEL, TAB_NAME) AS TAB_IDX
  FROM xM;

  SELECT Count(1) INTO vTab_Count FROM TMP_CUSTOMFORM_TAB;

  IF Operation = 0 THEN  -- UPDATE
    EXECUTE IMMEDIATE &apos;SELECT &apos;||vCol_Master||&apos; FROM TMP_&apos;||vTab_Master INTO RecId;

    FOR vRec IN (
      SELECT
        TAB_NAME, TAB_MASTER, COL_PK, COL_LINK, NIVEL, TAB_IDX,
        &apos;INSERT INTO TMP_CUSTOMFORM_COD(TAB_NAME, COD_TMP, COD_TAB) SELECT &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos;, &apos;||COL_PK||&apos;, &apos;||COL_PK||&apos; FROM &apos;||
        CASE
          WHEN NIVEL = 1 THEN &apos;TMP_&apos;||TAB_NAME
          ELSE TAB_NAME||&apos; WHERE &apos;||COL_LINK||&apos; IN (SELECT COD_TMP FROM TMP_CUSTOMFORM_COD WHERE TAB_NAME = &apos;&apos;&apos;||TAB_MASTER||&apos;&apos;&apos;)&apos;
        END sqlInsert,
        &apos;UPDATE TMP_CUSTOMFORM_COD SET COD_TAB = 0 WHERE TAB_NAME = &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos; AND NOT COD_TMP IN (SELECT &apos;||COL_PK||&apos; FROM TMP_&apos;||TAB_NAME||&apos;)&apos; sqlUpdate
      FROM TMP_CUSTOMFORM_TAB
      ORDER BY TAB_IDX
    ) LOOP
      EXECUTE IMMEDIATE vRec.sqlInsert;
      EXECUTE IMMEDIATE vRec.sqlUpdate;
    END LOOP;

    FOR vRec IN (
      SELECT &apos;DELETE FROM &apos;||TAB_NAME||&apos; WHERE &apos;||COL_PK||&apos; IN (SELECT COD_TMP FROM TMP_CUSTOMFORM_COD WHERE COD_TMP &gt; 0 AND COD_TAB = 0 AND TAB_NAME = &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos;)&apos; sqlDelete
      FROM TMP_CUSTOMFORM_TAB
      WHERE NIVEL &gt; 1
      ORDER BY TAB_IDX DESC
    ) LOOP
      EXECUTE IMMEDIATE vRec.sqlDelete;
    END LOOP;
  END IF;

  DELETE FROM TMP_CUSTOMFORM_COD WHERE COD_TMP &gt; 0 AND COD_TAB = 0;
  FOR vRec IN (
    SELECT
      TAB_NAME, COL_PK,
      &apos;INSERT INTO TMP_CUSTOMFORM_COD(TAB_NAME, COD_TMP, COD_TAB) SELECT &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos;, &apos;||COL_PK||&apos;,  Seq_&apos;||TAB_NAME||&apos;_&apos;||COL_PK||&apos;.NextVal FROM TMP_&apos;||TAB_NAME||&apos; WHERE &apos;||COL_PK||&apos; &lt;= 0&apos; sqlInsert1,
      CASE
        WHEN NIVEL = 1
        THEN &apos;INSERT INTO &apos;||TAB_NAME||&apos;(&apos;||COL_PK||&apos;) SELECT COD_TAB FROM TMP_CUSTOMFORM_COD WHERE TAB_NAME = &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos; AND COD_TMP &lt;= 0&apos;
        ELSE &apos;INSERT INTO &apos;||TAB_NAME||&apos;(&apos;||COL_PK||&apos;, &apos;||COL_LINK||&apos;) SELECT A.COD_TAB, B.COD_TAB &apos;||Chr(10)||
             &apos;FROM TMP_CUSTOMFORM_COD A&apos;||Chr(10)||
             &apos;  INNER JOIN TMP_&apos;||TAB_NAME||&apos; TMP ON TMP.&apos;||COL_PK||&apos; = A.COD_TMP&apos;||Chr(10)||
             &apos;  INNER JOIN TMP_CUSTOMFORM_TAB CFT ON CFT.TAB_NAME = A.TAB_NAME&apos;||Chr(10)||
             &apos;  INNER JOIN TMP_CUSTOMFORM_COD B ON B.TAB_NAME = CFT.TAB_MASTER AND B.COD_TMP = TMP.&apos;||COL_LINK||Chr(10)||
             &apos;WHERE A.TAB_NAME = &apos;&apos;&apos;||TAB_NAME||&apos;&apos;&apos; AND A.COD_TMP &lt;= 0&apos;
      END sqlInsert2
    FROM TMP_CUSTOMFORM_TAB
    ORDER BY TAB_IDX
  ) LOOP
    EXECUTE IMMEDIATE vRec.sqlInsert1;
    EXECUTE IMMEDIATE vRec.sqlInsert2;
    UPDATE_FROM_TMP(vRec.TAB_NAME, vRec.COL_PK);
  END LOOP;

  SELECT COD_TAB INTO RecId FROM TMP_CUSTOMFORM_COD WHERE TAB_NAME = vTab_Master;
  --SAVE_TABLES;

  NotifyModif(Operation, RecId, vTab_Master);
  COMMIT;
END;

PROCEDURE UPDATE_FROM_TMP( pTabName IN VARCHAR2, pColName IN VARCHAR2 ) IS
  vUpdate CLOB;
  vCols1  CLOB;
  vCols2  CLOB;
BEGIN
  FOR vRec IN (
    SELECT COLUMN_ID, COLUMN_NAME
    FROM user_tab_columns
    WHERE table_name = pTabName AND COLUMN_ID &gt; 2
    ORDER BY COLUMN_ID
  ) LOOP
    IF vRec.COLUMN_ID = 3 THEN
      vCols1 :=         vRec.COLUMN_NAME;
      vCols2 := &apos;tmp.&apos;||vRec.COLUMN_NAME;
    ELSE
      vCols1 := vCols1||&apos;, &apos;||        vRec.COLUMN_NAME;
      vCols2 := vCols2||&apos;, &apos;||&apos;tmp.&apos;||vRec.COLUMN_NAME;
    END IF;
  END LOOP;

  IF vCols1 IS NOT NULL THEN
    vUpdate :=
      &apos;UPDATE &apos;||pTabName||&apos; TUPD &apos;||Chr(10)||
      &apos;SET (&apos;||vCols1||&apos;) = &apos;||Chr(10)||
      &apos;    (SELECT &apos;||vCols2||Chr(10)||
      &apos;     FROM TMP_CUSTOMFORM_COD CFC INNER JOIN TMP_&apos;||pTabName||&apos; TMP ON TMP.&apos;||pColName||&apos; = CFC.COD_TMP&apos;||Chr(10)||
      &apos;     WHERE CFC.TAB_NAME = &apos;&apos;&apos;||pTabName||&apos;&apos;&apos; AND CFC.COD_TAB = TUPD.&apos;||pColName||&apos;)&apos;||Chr(10)||
      &apos;WHERE TUPD.&apos;||pColName||&apos; IN (SELECT COD_TAB FROM TMP_CUSTOMFORM_COD WHERE TAB_NAME = &apos;&apos;&apos;||pTabName||&apos;&apos;&apos;)&apos;;
    EXECUTE IMMEDIATE vUpdate;
  END IF;
END;

END PKG_CUSTOMFORM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_D300</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29DDF5E5C474400221F8E9467714B7943E645159</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_D300 IS

PROCEDURE ETVA_GETRECORD( RecId IN NUMBER ) IS
BEGIN
  TRUNCATE_TABLE(&apos;TMP_ETVA&apos;)            ;
  TRUNCATE_TABLE(&apos;TMP_ETVA_LOCUINTE&apos;)   ;
  TRUNCATE_TABLE(&apos;TMP_ETVA_ETRANSPORT&apos;) ;
  TRUNCATE_TABLE(&apos;TMP_ETVA_AMEF&apos;)       ;
  TRUNCATE_TABLE(&apos;TMP_ETVA_VAMA_EXPORT&apos;);
  TRUNCATE_TABLE(&apos;TMP_ETVA_VAMA_IMPORT&apos;);
  TRUNCATE_TABLE(&apos;TMP_ETVA_390_394&apos;)    ;
  TRUNCATE_TABLE(&apos;TMP_ETVA_FACTURA_TVA&apos;);
  TRUNCATE_TABLE(&apos;TMP_ETVA_FACTURA&apos;)    ;

  INSERT INTO TMP_ETVA             SELECT * FROM  ETVA             WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_LOCUINTE    SELECT * FROM  ETVA_LOCUINTE    WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_ETRANSPORT  SELECT * FROM  ETVA_ETRANSPORT  WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_AMEF        SELECT * FROM  ETVA_AMEF        WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_VAMA_EXPORT SELECT * FROM  ETVA_VAMA_EXPORT WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_VAMA_IMPORT SELECT * FROM  ETVA_VAMA_IMPORT WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_390_394     SELECT * FROM  ETVA_390_394     WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_FACTURA_TVA SELECT * FROM  ETVA_FACTURA_TVA WHERE CodETVA = RecId;
  INSERT INTO TMP_ETVA_FACTURA     SELECT * FROM  ETVA_FACTURA     WHERE CodETVA = RecId;
  COMMIT;
END;

PROCEDURE ETVA_AppendRECORD( aId IN NUMBER ) IS
  RecF  number(20);
  RecId number(20) := aID;
BEGIN
  IF RecId = 0 THEN
    RecId := ETVA_COD.NextVal;
  ELSE
    DELETE FROM ETVA              WHERE CodETVA = RecId;
    DELETE FROM ETVA_LOCUINTE     WHERE CodETVA = RecId;
    DELETE FROM ETVA_ETRANSPORT   WHERE CodETVA = RecId;
    DELETE FROM ETVA_AMEF         WHERE CodETVA = RecId;
    DELETE FROM ETVA_VAMA_EXPORT  WHERE CodETVA = RecId;
    DELETE FROM ETVA_VAMA_IMPORT  WHERE CodETVA = RecId;
    DELETE FROM ETVA_390_394      WHERE CodETVA = RecId;
    DELETE FROM ETVA_FACTURA_TVA  WHERE CodETVA = RecId;
    DELETE FROM ETVA_FACTURA      WHERE CodETVA = RecId;
  END IF;

  UPDATE TMP_ETVA               SET CodETVA = RecId;
  UPDATE TMP_ETVA_LOCUINTE      SET CodETVA = RecId, CodETVA_LOCUINTE     = ETVA_LOCUINTE_COD.NextVal;
  UPDATE TMP_ETVA_ETRANSPORT    SET CodETVA = RecId, CodETVA_ETRANSPORT   = ETVA_ETRANSPORT_COD.NextVal;
  UPDATE TMP_ETVA_AMEF          SET CodETVA = RecId, CodETVA_AMEF         = ETVA_AMEF_COD.NextVal;
  UPDATE TMP_ETVA_VAMA_EXPORT   SET CodETVA = RecId, CodETVA_VAMA_EXPORT  = ETVA_VAMA_EXPORT_COD.NextVal;
  UPDATE TMP_ETVA_VAMA_IMPORT   SET CodETVA = RecId, CodETVA_VAMA_IMPORT  = ETVA_VAMA_IMPORT_COD.NextVal;
  UPDATE TMP_ETVA_390_394       SET CodETVA = RecId, CodETVA_390_394      = ETVA_390_394_COD.NextVal;
  UPDATE TMP_ETVA_FACTURA_TVA   SET CodETVA = RecId, CodETVA_FACTURA_TVA  = ETVA_FACTURA_TVA_COD.NextVal;

  FOR X IN (SELECT * FROM TMP_ETVA_FACTURA) LOOP
    RecF := ETVA_FACTURA_TVA_COD.NextVal;
    UPDATE TMP_ETVA_FACTURA       SET CodETVA = RecId, CODETVA_FACTURA = RecF WHERE CODETVA_FACTURA = X.CODETVA_FACTURA;
    UPDATE TMP_ETVA_FACTURA_TVA   SET CodETVA = RecId, CODETVA_FACTURA = RecF WHERE CODETVA_FACTURA = X.CODETVA_FACTURA;
  END LOOP;

  INSERT INTO ETVA             SELECT * FROM TMP_ETVA            ;
  INSERT INTO ETVA_LOCUINTE    SELECT * FROM TMP_ETVA_LOCUINTE   ;
  INSERT INTO ETVA_ETRANSPORT  SELECT * FROM TMP_ETVA_ETRANSPORT ;
  INSERT INTO ETVA_AMEF        SELECT * FROM TMP_ETVA_AMEF       ;
  INSERT INTO ETVA_VAMA_EXPORT SELECT * FROM TMP_ETVA_VAMA_EXPORT;
  INSERT INTO ETVA_VAMA_IMPORT SELECT * FROM TMP_ETVA_VAMA_IMPORT;
  INSERT INTO ETVA_390_394     SELECT * FROM TMP_ETVA_390_394    ;
  INSERT INTO ETVA_FACTURA_TVA SELECT * FROM TMP_ETVA_FACTURA_TVA;
  INSERT INTO ETVA_FACTURA     SELECT * FROM TMP_ETVA_FACTURA    ;

  COMMIT;
END;

procedure Get300(aAn in number, aLuna in number, aSubunit in number) IS
  RecID NUMBER(20);
BEGIN
  DELETE TMP_D300;
  BEGIN
    IF aSubunit = 0
    THEN SELECT Coalesce(CODD300, 0) INTO RecID FROM D300 WHERE Coalesce(eTVA, 0) = 1 AND AN = aAn and LUNAD = aLuna;
    ELSE SELECT Coalesce(CODD300, 0) INTO RecID FROM D300 WHERE Coalesce(eTVA, 0) = 1 AND AN = aAn and LUNAD = aLuna AND SUBUNITATEA = aSubunit;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN RecID := 0;
  END;
  IF RecId &gt; 0 THEN PKG_D300.SP_GOTORECORD( RecId); END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodD300 INTO Tmp FROM D300 WHERE CodD300 = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM D300  WHERE CodD300  = RecId ;
  NotifyModif(2, RecId, &apos;D300&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_D300 FIELDS( CodD300 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master D300
  INSERT INTO TMP_D300 (
    CODD300, SUBUNITATEA, AN, LUNAD, DEPUSREPREZ, BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
    CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, ETVA,
    V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
    V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
    V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
    V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
    V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
    V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
    V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
    T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
    T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
    V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT)
  SELECT
    CODD300, SUBUNITATEA, AN, LUNAD, DEPUSREPREZ, BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
    CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, COALESCE(ETVA,0),
    V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
    V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
    V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
    V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
    V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
    V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
    V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
    T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
    T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
    V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT
  FROM D300
  WHERE CodD300 = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vCod   NUMBER(20);
  vETVA  NUMBER(1);
  vSUBUNIT NUMBER(20);
  vAN    NUMBER(4);
  vLuna  NUMBER(2);
BEGIN
  BEGIN
    SELECT d3.etva, d3.subunitatea, d3.an, d3.lunad INTO vETVA, vSUBUNIT, vAN, vLuna FROM tmp_d300 d3;
  EXCEPTION
    WHEN others THEN vETVA := 0;
  END;
  IF vETVA = 1 THEN
     IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 THEN
        UPDATE D300 d3 SET etva = 0 WHERE d3.an = vAN and d3.lunad = vLuna and d3.subunitatea = vSUBUNIT;
     ELSE
        UPDATE D300 d3 SET etva = 0 WHERE d3.an = vAN and d3.lunad = vLuna;
     END IF;
  END IF;

  IF Operation = 0
  THEN  -- UPDATE
    -- Master D300
    SELECT  CodD300 INTO RecId FROM TMP_D300;

    UPDATE D300
    SET  (CODD300, SUBUNITATEA, AN, LUNAD, DEPUSREPREZ, BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
          CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, ETVA,
          V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
          V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
          V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
          V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
          V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
          V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
          V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
          T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
          T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
          V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT)
      =(SELECT
          CODD300, SUBUNITATEA, AN, LUNAD, Coalesce(DEPUSREPREZ, 0), BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
          CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, ETVA,
          V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
          V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
          V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
          V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
          V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
          V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
          V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
          T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
          T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
          V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT
        FROM TMP_D300 )
    WHERE CodD300 = RecId ;

  ELSE  -- INSERT
    -- Master D300
    RecId := seq_D300_CodD300.NextVal;

    INSERT INTO D300 (
      CODD300, SUBUNITATEA, AN, LUNAD, DEPUSREPREZ, BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
      CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, ETVA,
      V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
      V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
      V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
      V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
      V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
      V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
      V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
      T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
      T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
      V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT)
    SELECT
      RecId, SUBUNITATEA, AN, LUNAD, Coalesce(DEPUSREPREZ, 0), BIFA_INTERNE, NUME, PRENUME, FUNCTIA, OBS, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, BANCA, CONT,
      CAEN, TIP_DECONT, PRO_RATA, TEMEI, BIFA_CEREALE, BIFA_MOB, BIFA_DISP, BIFA_CONS, SOLICIT_RAMB, NR_EVID, ETVA,
      V_01_0, V_02_0, V_03_0, V_03_1, V_04_0, V_05_0, T_05_0, V_05_1, T_05_1, V_06_0, T_06_0, V_07_0, T_07_0, V_07_1, T_07_1, V_08_0, T_08_0,
      V_09_0, T_09_0, V_09_1, T_09_1, V_10_0, T_10_0, V_10_1, T_10_1, V_11_0, T_11_0, V_11_1, T_11_1,
      V_12_0, T_12_0, V_12_1, T_12_1, V_12_2, T_12_2, V_12_3, T_12_3, V_12_4, T_12_4, V_12_5, T_12_5,
      V_13_0, V_14_0, V_14_1, V_14_2, V_15_0, V_16_0, T_16_0, V_64_0, T_64_0, V_65_0, T_65_0, V_17_0, T_17_0,
      V_18_0, T_18_0, V_18_1, T_18_1, V_19_0, T_19_0, V_20_0, T_20_0, V_20_1, T_20_1, V_21_0, T_21_0,
      V_22_0, T_22_0, V_22_1, T_22_1, V_23_0, T_23_0, V_23_1, T_23_1, V_24_0, T_24_0,
      V_25_0, T_25_0, V_25_1, T_25_1, V_25_2, T_25_2, V_25_3, T_25_3, V_25_4, T_25_4, V_25_5, T_25_5,
      T_43_0, T_44_0, V_26_0, V_26_1, V_27_0, T_27_0, T_28_0, T_29_0, V_30_0, T_30_0, T_31_0, T_32_0,
      T_33_0, T_34_0, T_35_0, T_36_0, T_37_0, T_38_0, T_39_0, T_40_0, T_41_0, T_42_0,
      V_A, T_A, V_B, T_B, V_A1, T_A1, V_B1, T_B1, NR_FACTURI, BAZA, TVA, NR_FACTURI_P, BAZA_P, TVA_P, NR_FACTURI_E, BAZA_E, TVA_E, TOT_PRECEDENT, TOT_CURENT
    FROM TMP_D300;
  END IF;
  NotifyModif(Operation, RecId, &apos;D300&apos;);

  COMMIT;
END;

PROCEDURE UmpleAux(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER, pTip NUMBER) IS
  vDataIni DATE;
  vALIni   NUMBER;
  vLunaIni INTEGER;
  bSaveTMP BOOLEAN := FALSE;
BEGIN
  IF    pTip = 3/*anual      */ THEN vLunaIni := 1;
  ELSIF pTip = 2/*semestrial */ THEN vLunaIni := CASE WHEN pLuna &gt; 6 THEN 7 ELSE 1 END;
  ELSIF pTip = 1/*trimestrial*/ THEN vLunaIni := CASE WHEN pLuna &gt; 9 THEN 10 WHEN pLuna &gt; 6 THEN 7 WHEN pLuna &gt; 3 THEN 4 ELSE 1 END;
  ELSIF pTip = 0/*lunar      */ THEN vLunaIni := pLuna;
  END IF;

  vDataIni := To_Date( To_Char(pAn, &apos;fm0000&apos;)||To_Char(vLunaIni, &apos;fm00&apos;)||&apos;01&apos;, &apos;yyyymmdd&apos;);
  vALIni   := pAn*12+ vLunaIni;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_JV_D300&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_JC_D300&apos;;

  PKG_LIST_BASE_JURNVANZ.SetPerioada(pAn, pLuna, pTip, pSubunit);
  PKG_LIST_BASE_JURNVANZ.ProcessList(&apos;TMP_JV_D300&apos;);
  PKG_LIST_BASE_JURNCUMP.SetPerioada(pAn, pLuna, pTip, pSubunit);
  PKG_LIST_BASE_JURNCUMP.ProcessList(&apos;TMP_JC_D300&apos;);

  INSERT INTO TMP_AUX_D300(
    AUX_SUM,
    V_01_0,
    V_03_0,
    V_03_1,
    V_09_0,
    T_09_0,
    V_09_1,
    T_09_1,
    V_10_0,
    T_10_0,
    V_10_1,
    T_10_1,
    V_11_0,
    T_11_0,
    V_11_1,
    T_11_1,
    V_13_0,
    V_14_0,
    V_14_1,
    V_14_2,
    V_15_0,
    V_16_0,
    T_16_0,
    V_64_0,
    T_64_0,
    V_A,
    T_A,
    V_A1,
    T_A1
  )
  SELECT
    9 AUX_SUM,
    Round(Sum(Coalesce(JV.ART143AD,0))) V_01_0,
    Round(Sum(                            Coalesce(JV.ART143BC, 0) + Coalesce(JV.NONRO_DED,0)      + Coalesce(JV.NONRO_NONDED,0)                )) V_03_0,
    Round(Sum(CASE WHEN JV.UE = &apos;DA&apos; THEN Coalesce(JV.SERV143BC,0) + Coalesce(JV.SERV_NONRO_DED,0) + Coalesce(JV.SERV_NONRO_NONDED,0) ELSE 0 END)) V_03_1,
    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_MAX,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BMAX,0)))                                                       V_09_0,
    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_MAX,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TMAX,0)))                                                       T_09_0,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_REG3,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BREG3,0)))                                                      V_09_1,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_REG3,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TREG3,0)))                                                      T_09_1,

    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_MIN,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BMIN,0)))                                                       V_10_0,
    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_MIN,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TMIN,0)))                                                       T_10_0,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_REG4,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BREG4,0)))                                                      V_10_1,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_REG4,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TREG4,0)))                                                      T_10_1,

    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_MED,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BMED,0)))                                                       V_11_0,
    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_MED,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TMED,0)))                                                       T_11_0,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.BAZA_REG5,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_BREG5,0)))                                                      V_11_1,
    Round(Sum(
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 0
        WHEN pAn          &gt;  2025                                                                THEN 0
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.TVA_REG5,0)
      END
    )) + Round(Sum(Coalesce(JV.A_311_322_TREG5,0)))                                                      T_11_1,
    Round(Sum(CASE WHEN JV.NAV_TIPDOC &lt;= 9 THEN 0 WHEN JV.TI = &apos;DA&apos; THEN Coalesce(JV.RO_DED,0) ELSE 0 END)) V_13_0,
    Round(Sum(CASE WHEN JV.NAV_TIPDOC &lt;= 9 THEN 0 WHEN JV.TI = &apos;DA&apos; THEN 0 ELSE Coalesce(JV.RO_DED,0) END)) V_14_0,
    Round(Sum(CASE WHEN I.TIPTVA = 11 AND Coalesce(JV.ORDDOC, 1) = 1 THEN Coalesce(I.VALDOC,0) * Coalesce(NULLIF(I.Curs,0),1) ELSE 0 END)) V_14_1,
    Round(Sum(CASE WHEN I.TIPTVA = 12 AND Coalesce(JV.ORDDOC, 1) = 1 THEN Coalesce(I.VALDOC,0) * Coalesce(NULLIF(I.Curs,0),1) ELSE 0 END)) V_14_2,
    Round(Sum(
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        ELSE Coalesce(JV.RO_NONDED,0)
      END +
      CASE
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 0
        WHEN Coalesce(I.TIPTRANZACTIE,0) = 1 AND Coalesce(I.TIPTVA, 0) = 13 AND Coalesce(JV.ORDDOC, 1) = 1 THEN Coalesce(I.VALDOC,0) * Coalesce(NULLIF(I.Curs,0),1)
        ELSE 0
      END -- &quot;Scutite, fara drept de deducere, cf art. 292&quot; (TIPTRANZACTIE=1 si TIPTVA=13)
    )) V_15_0,
    Round(Sum(
      Coalesce(JV.BAZA_REGMIN, 0)+Coalesce(JV.BAZA_REGMAX, 0)+
      Coalesce(JV.BAZA_REG,    0)+Coalesce(JV.BAZA_REG2,   0)+
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 1
        WHEN pAn          &gt;  2025                                                                THEN 1
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 1
        ELSE 0
      END * ( Coalesce(JV.BAZA_REG3,0)+Coalesce(JV.BAZA_REG4,0)+Coalesce(JV.BAZA_REG5,0) )
    )) V_16_0,
    Round(Sum(
      Coalesce(JV.TVA_REGMIN, 0)+Coalesce(JV.TVA_REGMAX, 0)+
      Coalesce(JV.TVA_REG,    0)+Coalesce(JV.TVA_REG2,   0)+
      CASE
        WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                             THEN 1
        WHEN pAn          &gt;  2025                                                                THEN 1
        WHEN (Coalesce(I.DATADOC, JV.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JV.ANDOC*12+JV.LUNADOC) THEN 1
        ELSE 0
      END * ( Coalesce(JV.TVA_REG3,0)+Coalesce(JV.TVA_REG4,0)+Coalesce(JV.TVA_REG5,0) )
    )) T_16_0,
    Round(Sum(CASE WHEN pAn*12+pLuna &gt;= 2019*12+7 THEN Coalesce(JV.BAZA_SERV_278,0) ELSE 0 END)) B_64_0,
    Round(Sum(CASE WHEN pAn*12+pLuna &gt;= 2019*12+7 THEN Coalesce(JV.TVA_SERV_278 ,0) ELSE 0 END)) T_64_0,
    Round(Sum(Coalesce(JV.SOLDVAL,0) - Coalesce(JV.SOLDTVA,0))) V_A,
    Round(Sum(Coalesce(JV.SOLDTVA,0))) T_A,
    Round(
      Sum(
        CASE
          WHEN pAn*12+pLuna &lt; 6 + CASE WHEN Coalesce(I.Initializari, 0) = 1 THEN Extract(YEAR FROM I.DATADOC)*12+Extract(MONTH FROM I.DATADOC) ELSE JV.ANDOC*12+JV.LUNADOC END
          THEN Coalesce(JV.SOLDVAL,0) - Coalesce(JV.SOLDTVA,0)
          ELSE 0
        END
      )
    ) V_A1,
    Round(
      Sum(
        CASE
          WHEN pAn*12+pLuna &lt; 6 + CASE WHEN Coalesce(I.Initializari, 0) = 1 THEN Extract(YEAR FROM I.DATADOC)*12+Extract(MONTH FROM I.DATADOC) ELSE JV.ANDOC*12+JV.LUNADOC END
          THEN Coalesce(JV.SOLDTVA,0)
          ELSE 0
        END
      )
    ) T_A1
  FROM TMP_JV_D300 JV LEFT JOIN IESIRI I ON I.CODIES = JV.NAV_CODDOC AND I.TIPDOC = JV.NAV_TIPDOC;

  UPDATE TMP_AUX_D300
  SET (
      V_05_0,
      T_05_0,
      V_05_1,
      T_05_1,
      V_06_0,
      T_06_0,
      V_07_0,
      T_07_0,
      V_07_1,
      T_07_1,
      V_08_0,
      T_08_0,
      V_12_0,
      T_12_0,
      V_12_1,
      T_12_1,
      V_12_2,
      T_12_2,
      V_12_3,
      T_12_3,
      V_12_4,
      T_12_4,
      V_12_5,
      T_12_5,
      V_22_0,
      T_22_0,
      V_22_1,
      T_22_1,
      V_23_0,
      T_23_0,
      V_23_1,
      T_23_1,
      V_24_0,
      T_24_0,
      V_26_0,
      V_26_1,
      AUX_T_28_0,
      T_29_0,
      V_30_0,
      T_30_0,
      T_43_0,
      V_B,
      T_B,
      V_B1,
      T_B1
  ) =
  (
    SELECT
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0 ELSE Coalesce(JC.AICB_BAZA,0) END)) V_05_0,
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0 ELSE Coalesce(JC.AICB_TVA ,0) END)) T_05_0,
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0 WHEN JC.UE = &apos;DA&apos; THEN Coalesce(JC.AICB_BAZA,0) ELSE 0 END)) V_05_1,
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0 WHEN JC.UE = &apos;DA&apos; THEN Coalesce(JC.AICB_TVA ,0) ELSE 0 END)) T_05_1,
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN Coalesce(JC.AICB_BAZA,0) ELSE 0 END) ) V_06_0,
      Round(Sum(CASE WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN Coalesce(JC.AICB_TVA, 0) ELSE 0 END) ) T_06_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0
          ELSE
            Coalesce(JC.BS150_BAZA,0) +
            CASE
              WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)         THEN 1
              WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8 THEN 1-- presupunand ca valoare e pozitionata pe coloan care trebuie in Jurnalul de cumparari
              ELSE 0
            END * 
            (
              Coalesce(JC.BAZA_MAX,0)    + Coalesce(JC.BAZA_MIN,0)    + Coalesce(JC.BAZA_MED,0) +
              Coalesce(JC.BAZA_REGMAX,0) + Coalesce(JC.BAZA_REGMIN,0) +  
              Coalesce(JC.BAZA_REG,0)    + Coalesce(JC.BAZA_REG2,0)   + Coalesce(JC.BAZA_REG3,0) + Coalesce(JC.BAZA_REG4,0) + Coalesce(JC.BAZA_REG5,0)
            )
        END)
      ) V_07_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0
          ELSE
            Coalesce(JC.BS150_TVA, 0) +
            CASE
              WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)         THEN 1
              WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8 THEN 1-- presupunand ca valoare e pozitionata pe coloan care trebuie in Jurnalul de cumparari
              ELSE 0
            END * 
            (
              Coalesce(JC.TVA_MAX,0)    + Coalesce(JC.TVA_MIN,0)    + Coalesce(JC.TVA_MED,0) +
              Coalesce(JC.TVA_REGMAX,0) + Coalesce(JC.TVA_REGMIN,0) +  
              Coalesce(JC.TVA_REG,0)    + Coalesce(JC.TVA_REG2,0)   + Coalesce(JC.TVA_REG3,0) + Coalesce(JC.TVA_REG4,0) + Coalesce(JC.TVA_REG5,0)
            )
        END)
      ) T_07_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0
          WHEN JC.UE = &apos;DA&apos; THEN Coalesce(JC.BS150_BAZA,0)
          ELSE 0
        END)
      ) V_07_1,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN 0
          WHEN JC.UE = &apos;DA&apos; THEN Coalesce(JC.BS150_TVA ,0)
          ELSE 0
        END)
      ) T_07_1,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN
            Coalesce(JC.BS150_BAZA,0) +
            CASE
              WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)         THEN 1
              WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8 THEN 1-- presupunand ca valoare e pozitionata pe coloan care trebuie in Jurnalul de cumparari
              ELSE 0
            END * 
            (
              Coalesce(JC.BAZA_MAX,0)    + Coalesce(JC.BAZA_MIN,0)    + Coalesce(JC.BAZA_MED,0) +
              Coalesce(JC.BAZA_REGMAX,0) + Coalesce(JC.BAZA_REGMIN,0) +  
              Coalesce(JC.BAZA_REG,0)    + Coalesce(JC.BAZA_REG2,0)   + Coalesce(JC.BAZA_REG3,0) + Coalesce(JC.BAZA_REG4,0) + Coalesce(JC.BAZA_REG5,0)
            )
          ELSE 0
        END)
      ) V_08_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC) THEN
            Coalesce(JC.BS150_TVA, 0) +
            CASE
              WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)         THEN 1
              WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8 THEN 1-- presupunand ca valoare e pozitionata pe coloan care trebuie in Jurnalul de cumparari
              ELSE 0
            END * 
            (
              Coalesce(JC.TVA_MAX,0)    + Coalesce(JC.TVA_MIN,0)    + Coalesce(JC.TVA_MED,0) +
              Coalesce(JC.TVA_REGMAX,0) + Coalesce(JC.TVA_REGMIN,0) +  
              Coalesce(JC.TVA_REG,0)    + Coalesce(JC.TVA_REG2,0)   + Coalesce(JC.TVA_REG3,0) + Coalesce(JC.TVA_REG4,0) + Coalesce(JC.TVA_REG5,0)
            )
          ELSE 0
        END)
      ) T_08_0,
      Round(Sum(Coalesce(JC.BS160_BAZA,0))) V_12_0,
      Round(Sum(Coalesce(JC.BS160_TVA ,0))) T_12_0,
      Round(Sum(Coalesce(JC.BS160_BMAX,0))) V_12_1,
      Round(Sum(Coalesce(JC.BS160_TMAX,0))) T_12_1,
      Round(Sum(Coalesce(JC.BS160_BMIN,0))) V_12_2,
      Round(Sum(Coalesce(JC.BS160_TMIN,0))) T_12_2,
      CASE
          WHEN pAn*12+pLuna &lt; 2025*12+8
          THEN Round(Sum(Coalesce(JC.BS160_BMED, 0)))
          ELSE Round(Sum(Coalesce(JC.BS160_BREG3,0)))
      END V_12_3,
      CASE
          WHEN pAn*12+pLuna &lt; 2025*12+8
          THEN Round(Sum(Coalesce(JC.BS160_TMED, 0)))
          ELSE Round(Sum(Coalesce(JC.BS160_TREG3,0)))
      END T_12_3,
      Round(Sum(Coalesce(JC.BS160_BREG4,0))) V_12_4,
      Round(Sum(Coalesce(JC.BS160_TREG4,0))) T_12_4,
      Round(Sum(Coalesce(JC.BS160_BREG5,0))) V_12_5,
      Round(Sum(Coalesce(JC.BS160_TREG5,0))) T_12_5,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          ELSE Coalesce(JC.BAZA_MAX,0)
        END
      )) V_22_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          ELSE Coalesce(JC.TVA_MAX ,0)
        END
      )) T_22_0,
      Round(Sum(
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          ELSE Coalesce(JC.BAZA_REG3,0)
        END
      )) V_22_1,
      Round(Sum(
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.TVA_REG3 ,0)
        END
      )) T_22_1,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.BAZA_MIN,0)
        END
      )) V_23_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          ELSE Coalesce(JC.TVA_MIN ,0)
        END)
      ) T_23_0,
      Round(Sum(
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          ELSE Coalesce(JC.BAZA_REG4,0)
        END
      )) V_23_1,
      Round(Sum(
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.TVA_REG4 ,0)
        END
      )) T_23_1,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.BAZA_MED,0)
        END +
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.BAZA_REG5 ,0)
        END
      )) V_24_0,
      Round(Sum(
        CASE
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.TVA_MED ,0)
        END +
        CASE
          WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                       THEN 0
          WHEN pAn          &gt;  2025                                                          THEN 0
          WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni) AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
            AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni)  THEN 0
          WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                          THEN 0
          WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
          WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                   THEN 0
          ELSE Coalesce(JC.TVA_REG5 ,0)
        END
      )) T_24_0,
      Round(Sum(Coalesce(JC.TVA_0,0) + Coalesce(JC.AICB_SCUT,0) + Coalesce(JC.AICB_NEIMP,0))) V_26_0,
      Round(Sum(CASE WHEN JC.UE = &apos;DA&apos; THEN Coalesce(JC.AICS_SCUT,0) + Coalesce(JC.AICS_NEIMP,0) ELSE 0 END)) V_26_1,
      Round(
        Sum(
          Coalesce(JC.TVAN_MAX,0)+Coalesce(JC.TVAN_MIN,0) +Coalesce(JC.TVAN_MED,0) +Coalesce(JC.TVANPRORATA,0)+
          Coalesce(JC.TVAN_REG,0)+Coalesce(JC.TVAN_REG2,0)+Coalesce(JC.TVAN_REG3,0)+Coalesce(JC.TVAN_REG4,0)+Coalesce(JC.TVAN_REG5,0)
        )
      ) AUX_T_28_0,
      Round(Sum(Coalesce(JC.TVA_RET ,0))) T_29_0,
      Round(
        Sum(
          CASE
            WHEN JC.TVALAINC = &apos;DA&apos; AND Coalesce(JC.PLATADATA, vDataIni) &gt;= vDataIni           THEN 0
            WHEN JC.TI       = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                    THEN 0
            WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                  THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
            WHEN Coalesce(I.DATATVA, D.DATADOC, JC.DATADOC) &gt;= vDataIni                        
            THEN Coalesce(JC.BAZA_REGMAX,0) + Coalesce(JC.BAZA_REGMIN,0) + 
                 Coalesce(JC.BAZA_REG,   0) + Coalesce(JC.BAZA_REG2,  0)
            ELSE Coalesce(JC.BAZA_MAX,   0) + Coalesce(JC.BAZA_MIN,   0) + Coalesce(JC.BAZA_MED ,0) +
                 Coalesce(JC.BAZA_REGMAX,0) + Coalesce(JC.BAZA_REGMIN,0) + 
                 Coalesce(JC.BAZA_REG,   0) + Coalesce(JC.BAZA_REG2,  0)
          END+
          CASE
            WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                     THEN 1
            WHEN pAn          &gt;  2025                                                        THEN 1
            WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni)
             AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
             AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni) THEN 1
            WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                        THEN 1
            WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                THEN 1 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
            WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                 THEN 1
            ELSE 0
          END * ( Coalesce(JC.BAZA_REG3, 0) + Coalesce(JC.BAZA_REG4, 0) + Coalesce(JC.BAZA_REG5, 0) )
        )
      ) V_30_0,
      Round(
        Sum(
          CASE
            WHEN JC.TVALAINC = &apos;DA&apos; AND Coalesce(JC.PLATADATA, vDataIni) &gt;= vDataIni         THEN 0
            WHEN JC.TI       = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                  THEN 0
            WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                THEN 0 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
            WHEN Coalesce(I.DATATVA, D.DATADOC, JC.DATADOC) &gt;= vDataIni
            THEN Coalesce(JC.TVA_REGMAX,0) + Coalesce(JC.TVA_REGMIN,0) +  
                 Coalesce(JC.TVA_REG,   0) + Coalesce(JC.TVA_REG2,  0)
            ELSE Coalesce(JC.TVA_MAX,   0) + Coalesce(JC.TVA_MIN,   0) + Coalesce(JC.TVA_MED ,0) +
                 Coalesce(JC.TVA_REGMAX,0) + Coalesce(JC.TVA_REGMIN,0) +  
                 Coalesce(JC.TVA_REG,   0) + Coalesce(JC.TVA_REG2,  0)
          END+
          CASE
            WHEN pAn*12+pLuna &gt;= 2025*12+8 AND pTip &lt;&gt; 2                                     THEN 1
            WHEN pAn          &gt;  2025                                                        THEN 1
            WHEN (Coalesce(D.DATADOC, JC.DATADOC) &lt; vDataIni)
             AND (vALIni &lt;= JC.ANDOC*12+JC.LUNADOC)
             AND NOT (JC.TVALAINC  = &apos;DA&apos; AND COALESCE(JC.PLATADATA, vDataIni-1) &gt; vDataIni) THEN 1
            WHEN JC.TI = &apos;DA&apos; AND (JC.UE = &apos;NU&apos; OR JC.nav_tipdoc = 5)                        THEN 1
            WHEN Coalesce(I.TIPTRANZACTIE,0) = 2 AND Coalesce(I.TIPTVA,0) = 8                THEN 1 -- presupunand ca valoare e pozitionata pe coloana care trebuie in Jurnalul de cumparari
            WHEN COALESCE(JC.PLATADATA, vDataIni) &lt; vDataIni                                 THEN 1
            ELSE 0
          END * ( Coalesce(JC.TVA_REG3, 0) + Coalesce(JC.TVA_REG4, 0) + Coalesce(JC.TVA_REG5, 0) )
        )
      ) T_30_0,
      Round(Sum(Coalesce(JC.RS315_TVA,0))) T_43_0,
      Round(Sum(Coalesce(JC.SOLDVAL,0) - Coalesce(JC.SOLDTVA,0))) V_B,
      Round(Sum(Coalesce(JC.SOLDTVA,0))) T_B,
      Round(
        Sum(
          CASE
            WHEN pAn*12+pLuna &lt; 6 + CASE WHEN Coalesce(I.Initializari, 0) = 1 THEN Extract(YEAR FROM I.DATADOC)*12+Extract(MONTH FROM I.DATADOC) ELSE JC.ANDOC*12+JC.LUNADOC END
            THEN Coalesce(JC.SOLDVAL,0) - Coalesce(JC.SOLDTVA,0)
            ELSE 0
          END
        )
      ) V_B1,
      Round(
        Sum(
          CASE
            WHEN pAn*12+pLuna &lt; 6 + CASE WHEN Coalesce(I.Initializari, 0) = 1 THEN Extract(YEAR FROM I.DATADOC)*12+Extract(MONTH FROM I.DATADOC) ELSE JC.ANDOC*12+JC.LUNADOC END
            THEN Coalesce(JC.SOLDTVA,0)
            ELSE 0
          END
        )
      ) T_B1
    FROM TMP_JC_D300 JC
      LEFT JOIN INTRARI I ON I.CODINTR = JC.NAV_CODDOC AND I.TIPDOC = JC.NAV_TIPDOC
      LEFT JOIN DVI     D ON D.CODINTR = I.CODINTR
  )
  WHERE AUX_SUM = 9;

  UPDATE TMP_AUX_D300
  SET V_14_0 = Coalesce(V_14_0,0) + Coalesce(V_14_1,0) + Coalesce(V_14_2,0)
  WHERE AUX_SUM = 9;
  -- stef 17.02.2017 facut join cu intrari pentru cazul special I.TIPTRANZACTIE = 2 AND I.TIPTVA = 8 - revazut daca acest caz se muta pe alta coloana in JurnCump
  IF pAn*12+pLuna &lt; 2019*12+7 THEN
    UPDATE TMP_AUX_D300
    SET (TOT_PREC, TOT_CUR)  = (SELECT 0, 0 FROM DUAL)
    WHERE AUX_SUM = 9;
  ELSIF pSubunit IN (0, 1) THEN
    UPDATE TMP_AUX_D300
    SET TOT_PREC = (SELECT Coalesce(Round(Sum((VALDOC-TVADOC)*Coalesce(NULLIF(Curs,0),1))),0) FROM iesiri WHERE tiptranzactie = 2 AND tiptva = 9 AND an = pAn - 1)
    WHERE AUX_SUM = 9;
    UPDATE TMP_AUX_D300
    SET TOT_CUR  = (SELECT Coalesce(Round(Sum((VALDOC-TVADOC)*Coalesce(NULLIF(Curs,0),1))),0) FROM iesiri WHERE tiptranzactie = 2 AND tiptva = 9 AND an = pAn AND luna &lt;= pLuna)
    WHERE AUX_SUM = 9;
  ELSE
    UPDATE TMP_AUX_D300
    SET TOT_PREC = (SELECT Coalesce(Round(Sum((VALDOC-TVADOC)*Coalesce(NULLIF(Curs,0),1))),0) FROM iesiri WHERE tiptranzactie = 2 AND tiptva = 9 AND an = pAn - 1               AND subunitatea = pSubunit)
    WHERE AUX_SUM = 9;
    UPDATE TMP_AUX_D300
    SET TOT_CUR  = (SELECT Coalesce(Round(Sum((VALDOC-TVADOC)*Coalesce(NULLIF(Curs,0),1))),0) FROM iesiri WHERE tiptranzactie = 2 AND tiptva = 9 AND an = pAn AND luna &lt;= pLuna AND subunitatea = pSubunit)
    WHERE AUX_SUM = 9;
  END IF;

  UPDATE TMP_AUX_D300 SET AUX_SUM = 0 WHERE AUX_SUM = 9;

  IF bSaveTMP THEN
    FOR vRec IN (
      SELECT &apos;TMP_JV_D300&apos;  SURSA FROM DUAL UNION
      SELECT &apos;TMP_JC_D300&apos;  SURSA FROM DUAL UNION
      SELECT &apos;TMP_AUX_D300&apos; SURSA FROM DUAL
    ) LOOP
      BEGIN
        EXECUTE IMMEDIATE &apos;DROP TABLE SAV_&apos;||vRec.SURSA||&apos; PURGE&apos;;
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
      EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_&apos;||vRec.SURSA||&apos; AS SELECT * FROM &apos;||vRec.SURSA;
    END LOOP;
  END IF;

  COMMIT;
END;

PROCEDURE Generare(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER, pTip NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  pUsername  VARCHAR2(100);
  pAlteFirme VARCHAR2(3000);
  vCount     NUMERIC;
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_AUX_D300&apos;;
  UmpleAux(pSubunit, pAn, pLuna, pTip);

  pAlteFirme := pkg_categconst.GetValConstanta(&apos;AlteFirmeD394&apos;  ,pAn, pLuna);
  pAlteFirme := REPLACE(pAlteFirme,&apos; &apos;, &apos;&apos;);
  pAlteFirme := NULLIF(pAlteFirme, &apos;&apos;);
  IF pAlteFirme IS NOT NULL THEN
    SELECT USERNAME INTO pUSERNAME FROM user_users;

    pAlteFirme := Upper(pAlteFirme);
    pAlteFirme := &apos;,&apos;||pAlteFirme||&apos;,&apos;;
    Winmadmin.PKG_USERFIRME.POPULEAZA_D300_EXTERNE(pUSERNAME, pAlteFirme, pTip, pLuna, pAn, pSubunit);
  END IF;

  SELECT Count(1) INTO vCount FROM TMP_AUX_D300;
  IF vCount &gt; 1 THEN
    UPDATE TMP_AUX_D300 SET AUX_SUM = 1;
    INSERT INTO TMP_AUX_D300
    SELECT
      Sum(Coalesce(V_01_0,0)), Sum(Coalesce(V_03_0,0)), Sum(Coalesce(V_03_1,0)), Sum(Coalesce(V_05_0,0)), Sum(Coalesce(T_05_0,0)), Sum(Coalesce(V_05_1,0)), Sum(Coalesce(T_05_1,0)),
      Sum(Coalesce(V_06_0,0)), Sum(Coalesce(T_06_0,0)), Sum(Coalesce(V_07_0,0)), Sum(Coalesce(T_07_0,0)), Sum(Coalesce(V_07_1,0)), Sum(Coalesce(T_07_1,0)), Sum(Coalesce(V_08_0,0)), Sum(Coalesce(T_08_0,0)),
      Sum(Coalesce(V_09_0,0)), Sum(Coalesce(T_09_0,0)), Sum(Coalesce(V_09_1,0)), Sum(Coalesce(T_09_1,0)),
      Sum(Coalesce(V_10_0,0)), Sum(Coalesce(T_10_0,0)), Sum(Coalesce(V_10_1,0)), Sum(Coalesce(T_10_1,0)),
      Sum(Coalesce(V_11_0,0)), Sum(Coalesce(T_11_0,0)), Sum(Coalesce(V_11_1,0)), Sum(Coalesce(T_11_1,0)),
      Sum(Coalesce(V_12_0,0)), Sum(Coalesce(T_12_0,0)), Sum(Coalesce(V_12_1,0)), Sum(Coalesce(T_12_1,0)), Sum(Coalesce(V_12_2,0)), Sum(Coalesce(T_12_2,0)),
      Sum(Coalesce(V_12_3,0)), Sum(Coalesce(T_12_3,0)), Sum(Coalesce(V_12_4,0)), Sum(Coalesce(T_12_4,0)), Sum(Coalesce(V_12_5,0)), Sum(Coalesce(T_12_5,0)),
      Sum(Coalesce(V_13_0,0)), Sum(Coalesce(V_14_0,0)), Sum(Coalesce(V_14_1,0)), Sum(Coalesce(V_14_2,0)), Sum(Coalesce(V_15_0,0)), Sum(Coalesce(V_16_0,0)), Sum(Coalesce(T_16_0,0)),
      Sum(Coalesce(V_22_0,0)), Sum(Coalesce(T_22_0,0)), Sum(Coalesce(V_22_1,0)), Sum(Coalesce(T_22_1,0)),
      Sum(Coalesce(V_23_0,0)), Sum(Coalesce(T_23_0,0)), Sum(Coalesce(V_23_1,0)), Sum(Coalesce(T_23_1,0)),
      Sum(Coalesce(V_24_0,0)), Sum(Coalesce(T_24_0,0)), Sum(Coalesce(V_26_0,0)), Sum(Coalesce(V_26_1,0)),
      Sum(Coalesce(T_29_0,0)), Sum(Coalesce(V_30_0,0)), Sum(Coalesce(T_30_0,0)), Sum(Coalesce(T_43_0,0)), Sum(Coalesce(T_44_0,0)), Sum(Coalesce(V_64_0,0)), Sum(Coalesce(T_64_0,0)), Sum(Coalesce(AUX_T_28_0,0)),
      Sum(Coalesce(V_A,0)),    Sum(Coalesce(T_A,0)),    Sum(Coalesce(V_B,0)),    Sum(Coalesce(T_B,0)),    Sum(Coalesce(V_A1,0)),   Sum(Coalesce(T_A1,0)),   Sum(Coalesce(V_B1,0)),   Sum(Coalesce(T_B1,0)),
      Sum(Coalesce(TOT_PREC,0)), Sum(Coalesce(TOT_CUR,0)),
      0 AS AUX_SUM
    FROM TMP_AUX_D300
    WHERE AUX_SUM = 1;
    DELETE FROM TMP_AUX_D300 WHERE AUX_SUM = 1;

    COMMIT;
  END IF;
END;

END PKG_D300;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_D390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAADE130C824253A31F5D8D80FAEA31A55D266D4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_D390 IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodD390 INTO Tmp FROM D390 WHERE CodD390 = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM D390D WHERE CodD390  = RecId ;
  DELETE FROM D390O WHERE CodD390  = RecId ;
  DELETE FROM D390  WHERE CodD390  = RecId ;
  NotifyModif(2, RecId, &apos;D390&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_D390 FIELDS( CodD390 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master D390
  INSERT INTO TMP_D390 (
    CODD390, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
    NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS, GENERAT)
  SELECT
    CODD390, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
    NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS, 1
  FROM D390
  WHERE CodD390 = RecId;

  -- Detail D390O
  INSERT INTO TMP_D390O (CODD390O, CODD390, TIP, TARA, CODO, DENO, BAZA, OBS, CAZSPECIAL)
  SELECT CODD390O, CODD390, TIP, TARA, CODO, DENO, BAZA, OBS, CAZSPECIAL
  FROM D390O
  WHERE CodD390 = RecId;

  -- Detail D390D
  INSERT INTO  TMP_D390D (
    CODD390D, CODD390O, CODD390, IDXFIRMA, CODSURSA, TIPSURSA, DOC, MONEDADOC, TIP, BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL,
    TARA, CODO, DENO, TRANSFERBAZA, TRANSFERTIP)
  SELECT
    D.CODD390D, D.CODD390O, D.CODD390, D.IDXFIRMA, D.CODSURSA, D.TIPSURSA, D.DOC, D.MONEDADOC, D.TIP, D.BAZAVAL, D.CURS, D.BAZALEI, D.OBS, D.STERS, D.CAZSPECIAL,
    O.TARA, O.CODO, O.DENO, 0, &apos;?&apos;
  FROM D390O O INNER JOIN D390D D ON D.CODD390O = O.CODD390O
  WHERE O.CodD390 = RecId AND Coalesce(D.Sters,0) = 0;

  INSERT INTO  TMP_D390DX (
    CODD390D, CODD390O, CODD390, IDXFIRMA, CODSURSA, TIPSURSA, DOC, MONEDADOC, TIP, BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL,
    TARA, CODO, DENO, TRANSFERBAZA, TRANSFERTIP)
  SELECT
    D.CODD390D, D.CODD390O, D.CODD390, D.IDXFIRMA, D.CODSURSA, D.TIPSURSA, D.DOC, D.MONEDADOC, D.TIP, D.BAZAVAL, D.CURS, D.BAZALEI, D.OBS, D.STERS, D.CAZSPECIAL,
    O.TARA, O.CODO, O.DENO, 0, &apos;?&apos;
  FROM D390O O INNER JOIN D390D D ON D.CODD390O = O.CODD390O
  WHERE O.CodD390 = RecId AND Coalesce(D.Sters,0) = 1;

  -- Detail D390CA
  INSERT INTO TMP_D390CA (CODD390CA, CODD390, TARA_M1, COD_M1)
  SELECT CODD390CA, CODD390, TARA_M1, COD_M1
  FROM D390CA
  WHERE CodD390 = RecId;

  -- Detail D390CB
  INSERT INTO TMP_D390CB (CODD390CB, CODD390, TARA_M1, COD_M1, MOTIV, TARA_M2, COD_M2)
  SELECT CODD390CB, CODD390, TARA_M1, COD_M1, MOTIV, TARA_M2, COD_M2
  FROM D390CB
  WHERE CodD390 = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vCod   NUMBER(20);
BEGIN
  INSERT INTO TMP_D390D SELECT * FROM TMP_D390DX;

  IF Operation = 0
  THEN  -- UPDATE
    -- Master D390
    SELECT  CodD390 INTO RecId FROM TMP_D390;

    UPDATE D390
    SET  (CODD390, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
          NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS)
      =(SELECT
          CODD390, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
          NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS
        FROM TMP_D390 )
    WHERE CodD390 = RecId ;

    -- Detail D390O
    DELETE FROM D390D WHERE CodD390 = RecID AND CodD390D NOT IN (SELECT CodD390D FROM TMP_D390D);
    DELETE FROM D390O WHERE CodD390 = RecID AND CodD390O NOT IN (SELECT CodD390O FROM TMP_D390O);
    FOR v_rec IN (SELECT * FROM TMP_D390O ORDER BY CodD390O) LOOP
      IF Coalesce(v_rec.CodD390O,0) &gt; 0 THEN
        UPDATE D390O
        SET TIP        = v_rec.TIP ,
            TARA       = v_rec.TARA ,
            CODO       = v_rec.CODO,
            DENO       = v_rec.DENO,
            BAZA       = v_rec.BAZA,
            OBS        = v_rec.OBS,
            CAZSPECIAL = v_rec.CAZSPECIAL
        WHERE  CodD390O = v_rec.CodD390O;
      ELSE
        SELECT seq_D390O_CodD390O.NEXTVAL INTO vCod from dual;
        INSERT INTO D390O (CODD390O, CODD390, TIP, TARA, CODO, DENO, BAZA, OBS, CAZSPECIAL) VALUES (vCod, RecID, v_rec.TIP, v_rec.TARA, v_rec.CODO, v_rec.DENO, v_rec.BAZA, v_rec.OBS, v_rec.CAZSPECIAL);
        UPDATE TMP_D390D SET CodD390O = vCod, CODD390 = RecID WHERE CodD390O = v_rec.CodD390O;
      END IF;
    END LOOP;

    -- Detail D390D
    FOR v_rec IN (SELECT * FROM TMP_D390D ORDER BY CodD390D) LOOP
      IF Coalesce(v_rec.CodD390D,0) &gt; 0 THEN
        UPDATE D390D
        SET IDXFIRMA   = v_rec.IDXFIRMA,
            CODSURSA   = v_rec.CODSURSA,
            TIPSURSA   = v_rec.TIPSURSA,
            DOC        = v_rec.DOC,
            MONEDADOC  = v_rec.MONEDADOC,
            TIP        = v_rec.TIP,
            BAZAVAL    = v_rec.BAZAVAL,
            CURS       = v_rec.CURS,
            BAZALEI    = v_rec.BAZALEI,
            OBS        = v_rec.OBS,
            STERS      = v_rec.STERS,
            CAZSPECIAL = v_rec.CAZSPECIAL
        WHERE CodD390D = v_rec.CodD390D;
      ELSE
        SELECT seq_D390D_CodD390D.NEXTVAL INTO vCod from dual;
        INSERT INTO  D390D (
          CodD390D, CodD390O, CodD390,
          IDXFIRMA, CODSURSA, TIPSURSA, DOC, MONEDADOC, TIP, BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL)
        VALUES (
          vCod, v_rec.CODD390O, RecId,
          v_rec.IDXFIRMA, v_rec.CODSURSA, v_rec.TIPSURSA, v_rec.DOC, v_rec.MONEDADOC, v_rec.TIP, v_rec.BAZAVAL, v_rec.CURS, v_rec.BAZALEI, v_rec.OBS, v_rec.STERS, v_rec.CAZSPECIAL);
      END IF;
    END LOOP;

    -- Detail D390CA
    DELETE FROM D390CA WHERE CodD390 = RecID AND CodD390CA NOT IN (SELECT CodD390CA FROM TMP_D390CA);
    FOR v_rec IN (SELECT * FROM TMP_D390CA ORDER BY CodD390CA) LOOP
      IF Coalesce(v_rec.CodD390CA,0) &gt; 0 THEN
        UPDATE D390CA
        SET    TARA_M1 = v_rec.TARA_M1 ,
               COD_M1  = v_rec.COD_M1
        WHERE  CodD390CA = v_rec.CodD390CA;
      ELSE
        INSERT INTO D390CA (CODD390CA, CODD390, TARA_M1, COD_M1) VALUES (seq_D390CA_CodD390CA.NEXTVAL, RecID, v_rec.TARA_M1, v_rec.COD_M1);
      END IF;
    END LOOP;

    -- Detail D390CB
    DELETE FROM D390CB WHERE CodD390 = RecID AND CodD390CB NOT IN (SELECT CodD390CB FROM TMP_D390CB);
    FOR v_rec IN (SELECT * FROM TMP_D390CB ORDER BY CodD390CB) LOOP
      IF Coalesce(v_rec.CodD390CB,0) &gt; 0 THEN
        UPDATE D390CB
        SET    TARA_M1 = v_rec.TARA_M1,
               COD_M1  = v_rec.COD_M1,
               MOTIV   = v_rec.MOTIV,
               TARA_M2 = v_rec.TARA_M2,
               COD_M2  = v_rec.COD_M2
        WHERE  CodD390CB = v_rec.CodD390CB;
      ELSE
        INSERT INTO D390CB (CODD390CB, CODD390, TARA_M1, COD_M1, MOTIV, TARA_M2, COD_M2) VALUES (seq_D390CB_CodD390CB.NEXTVAL, RecID, v_rec.TARA_M1, v_rec.COD_M1, v_rec.MOTIV, v_rec.TARA_M2, v_rec.COD_M2);
      END IF;
    END LOOP;

  ELSE  -- INSERT
    -- Master D390
    SELECT seq_D390_CodD390.NextVal INTO RecId FROM DUAL;

    INSERT INTO D390 (
      CODD390, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
      NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS)
    SELECT
      RecId, TIPD390, SUBUNITATEA, AN, LUNAD, CISTVA, DENCONTRIB, DOMFISCCONTRIB, TEL, FAX, EMAIL, NRTOTOP, BAZAL, BAZAT, BAZAA, BAZAP, BAZAS, BAZAR, TOTALBAZA,
      NUME, PRENUME, FUNCTIA, OBS, NRFIRMECDS
    FROM TMP_D390;

    -- Detail D390O
    FOR v_rec IN (SELECT * FROM TMP_D390O ORDER BY CodD390O) LOOP
      SELECT seq_D390O_CodD390O.NEXTVAL INTO vCod from dual;
      INSERT INTO D390O (CODD390O, CODD390, TIP, TARA, CODO, DENO, BAZA, OBS, CAZSPECIAL) VALUES (vCod, RecID, v_rec.TIP, v_rec.TARA, v_rec.CODO, v_rec.DENO, v_rec.BAZA, v_rec.OBS, v_rec.CAZSPECIAL);
      UPDATE TMP_D390D SET CodD390O = vCod, CODD390 = RecID WHERE CodD390O = v_rec.CodD390O;
    END LOOP;

    -- Detail D390D
    INSERT INTO D390D (
      CodD390D, CodD390O, CodD390,
      IDXFIRMA, CODSURSA, TIPSURSA, DOC, MONEDADOC, TIP, BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL)
    SELECT
      seq_D390D_CodD390D.NEXTVAL, CODD390O, RecId,
      IDXFIRMA, CODSURSA, TIPSURSA, DOC, MONEDADOC, TIP, BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL
    FROM TMP_D390D;

    -- Detail D390CA
    INSERT INTO D390CA (CODD390CA, CODD390, TARA_M1, COD_M1)
    SELECT seq_D390CA_CodD390CA.NEXTVAL, RecID, TARA_M1, COD_M1
    FROM TMP_D390CA;

    -- Detail D390CB
    INSERT INTO D390CB (CODD390CB, CODD390, TARA_M1, COD_M1, MOTIV, TARA_M2, COD_M2)
    SELECT seq_D390CB_CodD390CB.NEXTVAL, RecID, TARA_M1, COD_M1, MOTIV, TARA_M2, COD_M2
    FROM TMP_D390CB;
  END IF;
  NotifyModif(Operation, RecId, &apos;D390&apos;);

  COMMIT;
END;

PROCEDURE Generare(pSubunit INTEGER, pAn INTEGER, pLuna INTEGER) IS
  vCodD390       INTEGER;
  vCDiscountNir  NUMBER(20);
  vCDiscountFact NUMBER(20);
  vModAplicProcD NUMBER(20);
  vISIVB         NUMBER(20);
  sServAICB      VARCHAR2(10000);
  sServLICB      VARCHAR2(10000);
  vPartIesD390   NUMBER(20);

  vCodD390O      NUMBER(20)     := 0;
  vDataIni DATE;
  vDataFin DATE;
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);

  vCDiscountNir  := Coalesce(pkg_categconst.GetValConstanta(&apos;CDiscountNir&apos;        ,pAn,pLuna),&apos;-1&apos;);
  vCDiscountFact := Coalesce(pkg_categconst.GetValConstanta(&apos;CDiscountFact&apos;       ,pAn,pLuna),&apos;-1&apos;);
  vModAplicProcD := Coalesce(pkg_categconst.GetValConstanta(&apos;ModAplicProcDisc&apos;    ,pAn,pLuna), &apos;1&apos;);
  vISIVB         := Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos; ,pAn,pLuna), &apos;2&apos;);
  sServAICB      := Coalesce(pkg_categconst.GetValConstanta(&apos;ServAICB&apos;            ,pAn,pLuna),&apos;-1&apos;);
  sServLICB      := Coalesce(pkg_categconst.GetValConstanta(&apos;ServLICB&apos;            ,pAn,pLuna),&apos;-1&apos;);
  vPartIesD390   := Coalesce(pkg_categconst.GetValConstanta(&apos;PartIesD390&apos;         ,pAn,pLuna), &apos;1&apos;);

  vDataIni := To_Date(&apos;01.&apos;||To_Char(pLuna,&apos;00&apos;)||&apos;.&apos;||To_Char(pAn,&apos;0000&apos;),&apos;dd.mm.yyyy&apos;);
  vDataFin := Last_Day(vDataIni);

  BEGIN
    SELECT CodD390 INTO vCodD390 FROM TMP_D390;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN vCodD390 := 0;
  END;

	DELETE FROM tmp_manevra;

	INSERT INTO tmp_manevra(codunic)
	SELECT codobiect
	FROM (
	  SELECT o.codobiect, 1 EXCL
		FROM 	nart a INNER JOIN nartobj o ON  o.codarticol = a.codarticol
		WHERE contserviciu IN (vCDiscountNir, vCDiscountFact)
		UNION
		SELECT codobiect, excl
    FROM (
      SELECT codobiect, Coalesce(d390exclus,0) excl, ROW_NUMBER() OVER (PARTITION BY codobiect ORDER BY anstart*12+lunastart DESC) IDX
			FROM nartobj1
			WHERE anstart * 12 + lunastart &lt;= pAn * 12 + pLuna
		) A_PG
		WHERE A_PG.IDX = 1
	) B_PG
	WHERE B_PG.EXCL = 1;

	DELETE FROM tmp_manevra2;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra2(codunic) SELECT codobiect FROM nartobj WHERE CODOBIECT IN (&apos;||sServAICB||&apos;)&apos;;
	DELETE FROM tmp_manevra3;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra3(codunic) SELECT codobiect FROM nartobj WHERE CODOBIECT IN (&apos;||sServLICB||&apos;)&apos;;

  -- golesc tabelele detaliu mai putin inregistrarile introduse manual
  DELETE FROM TMP_D390CA WHERE CodD390 = vCodD390;
  DELETE FROM TMP_D390CB WHERE CodD390 = vCodD390;
  DELETE FROM TMP_D390DX WHERE CodD390 = vCodD390;
  DELETE FROM TMP_D390D  WHERE CodD390 = vCodD390;
  DELETE FROM TMP_D390O  WHERE CodD390 = vCodD390;

--  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE STERR&apos;;
--  sterr_insert (&apos;vCDiscountNir, vCDiscountFact&apos;, vCDiscountNir||&apos;,&apos;||vCDiscountFact);
--  sterr_insert (&apos;vISIVB&apos;,vISIVB);
--  sterr_insert (&apos;pSubunit&apos;,pSubunit);
--  sterr_insert (&apos;vDataIni AND vDataFin&apos;,&apos;to_date(&apos;&apos;&apos;||To_Char(vDataIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||To_Char(vDataFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;);
--  sterr_insert (&apos;i.an = pAn AND i.luna = pLuna&apos;,&apos;i.an = &apos;||pAn||&apos; AND i.luna = &apos;||pLuna);
--  sterr_insert (&apos;sServAICB&apos;, sServAICB);
--  sterr_insert (&apos;vPartIesD390&apos;, vPartIesD390);

  -- stef din cauza rotunjirii pu i1.pretorig*Coalesce(i1.coefdiscmaj,1)*i1.cant -&gt; CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
  -- de revenit la cazul asta

  --Iesiri
  INSERT INTO TMP_D390D (
    CODD390D, CODD390O, CODD390, IDXFIRMA,
    CODSURSA, TIPSURSA, DOC, MONEDADOC,
    TIP,
    BAZAVAL, CURS, BAZALEI, OBS, STERS, CAZSPECIAL, TARA, CODO, DENO, TRANSFERBAZA, TRANSFERTIP)
  WITH x AS (
    SELECT
      i.codies coddoc, i.tipdoc,
      Max(CASE WHEN vPartIesD390 = 2 AND Coalesce(i.codparttert,0) &lt;&gt; 0 THEN i.codparttert ELSE i.partener END) Partener,
      Max(Coalesce(i.moneda,0)) moneda, Max(Coalesce(NULLIF(i.curs,0),1)) Curs, Max(I.Obs) Obs, Max(Coalesce(I.PrefixDoc,&apos;&apos;)||I.NrDoc||&apos;/&apos;||To_Char(I.DataDoc,&apos;dd.mm.yyyy&apos;)) Doc,
      Coalesce(D.TIP,0) Tip,
      Max(SubStr(Trim(COALESCE(cft.Codfiscal,cfd.Codfiscal,a.Codfiscal,cfi.Codfiscal)),1,2)) TARA,
      Max(Trim(SubStr(Trim(COALESCE(cft.Codfiscal,cfd.Codfiscal,a.Codfiscal,cfi.Codfiscal)),3))) CodO,
      CASE
        WHEN vISIVB = 1 AND Max(CASE WHEN ex.codunic IS NULL AND i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1 AND D.TIP =  1 THEN 1
        WHEN vISIVB = 1 AND Max(CASE WHEN ex.codunic IS NULL AND i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1 AND D.TIP &lt;&gt; 1 THEN 0
        ELSE Sum(CASE WHEN (ex.codunic IS NOT NULL) OR D.TIP = CASE WHEN licb.codunic IS NOT NULL THEN 2 WHEN i1.tiplinie = &apos;=&apos; THEN 2 ELSE 1 END THEN 0 ELSE 1 END)
      END NrLinii,
      CASE
        WHEN vISIVB = 1 AND MAX( Coalesce(ex.codunic,0) ) = 0 AND Max(CASE WHEN i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1
         AND NOT EXISTS (SELECT 1 FROM iesiri1 i1x WHERE i1x.codies = i.codies AND Coalesce(i1x.impozabil, 0) = 4)
        THEN Max(Coalesce(I.ValDoc,0)-Coalesce(I.TvaDoc,0))
        WHEN vISIVB = 1 AND MAX( Coalesce(ex.codunic,0) ) &gt; 0 AND Max(CASE WHEN i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1
        THEN Sum(
               CASE
                 WHEN D.Tip &lt;&gt; 1 THEN 0
                 WHEN (ex.codunic IS NOT NULL) AND NOT Coalesce(art.contserviciu, -2) IN (vCDiscountNir, vCDiscountFact) THEN 0
                 ELSE CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
               END
             )
        WHEN Max(CASE WHEN (ex.codunic IS NOT NULL) OR D.TIP = CASE WHEN licb.codunic IS NOT NULL THEN 2 WHEN i1.tiplinie = &apos;=&apos; THEN 2 ELSE 1 END THEN 1 ELSE 0 END) = 0
         AND NOT EXISTS (SELECT 1 FROM iesiri1 i1x WHERE i1x.codies = i.codies AND Coalesce(i1x.impozabil, 0) = 4)
        THEN Max(Coalesce(I.ValDoc,0)-Coalesce(I.TvaDoc,0))
        ELSE Sum(
               CASE
                 WHEN D.TIP = 1 AND Coalesce(art.contserviciu, -2) IN (vCDiscountNir, vCDiscountFact) THEN CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
                 WHEN D.TIP = CASE WHEN licb.codunic IS NOT NULL THEN 2 WHEN i1.tiplinie = &apos;=&apos; THEN 2 ELSE 1 END THEN 0
                 WHEN ex.codunic IS NOT NULL THEN 0
                 ELSE CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
               END
             )
      END BazaVal
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      INNER JOIN nagenda a ON a.Codagenda = i.Codlocatie
      INNER JOIN nlocalit l ON l.Codlocalit = a.Codlocalit
      INNER JOIN ntari n ON n.Codtara = l.Codtara
      LEFT JOIN nartobj obj ON obj.codobiect = i1.codobiect
      LEFT JOIN nart art ON art.codarticol = obj.codarticol
      LEFT JOIN npartCodfisc cfd ON cfd.Cod_Codfiscal = i.Codfiscal
      LEFT JOIN npartCodfisc cfi ON cfi.Codpart = i.partener AND cfi.principal = 1
      LEFT JOIN npartCodfisc cft ON cft.Codpart = i.codparttert AND cft.principal = 1 AND vPartIesD390 = 2
      LEFT JOIN tmp_manevra ex ON ex.codunic = i1.codobiect
      LEFT JOIN tmp_manevra3 licb ON licb.codunic = i1.codobiect AND i.tiptranzactie = 2 AND i1.tiplinie IN ( &apos;S&apos;, &apos;V&apos; )
      LEFT JOIN (SELECT 1 TIP FROM DUAL UNION SELECT 2 TIP FROM DUAL) D ON D.TIP = CASE WHEN I.TipTVA = 3 THEN 0 ELSE D.TIP END
    WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (19,22,26) AND i.tiptranzactie = 2 AND NOT (i.tiptva IN (1, 10))
      AND i.an = pAn AND i.luna = pLuna
      AND i.subunitatea = CASE WHEN pSubunit = 1 THEN i.subunitatea ELSE pSubunit END
      AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;) AND Coalesce(i1.impozabil, 0) &lt;&gt; 4
      AND (  SubStr(Trim(COALESCE(cft.Codfiscal,cfd.Codfiscal,a.Codfiscal,cfi.Codfiscal)),1,2) IN (&apos;AT&apos;,&apos;BE&apos;,&apos;BG&apos;,&apos;CZ&apos;,&apos;CY&apos;,&apos;DK&apos;,&apos;EE&apos;,&apos;EL&apos;,&apos;DE&apos;,&apos;FI&apos;,&apos;FR&apos;,&apos;GR&apos;,&apos;IE&apos;,&apos;IT&apos;,&apos;LV&apos;,&apos;LU&apos;,&apos;LT&apos;,&apos;MT&apos;,&apos;NL&apos;,&apos;PL&apos;,&apos;PT&apos;,&apos;SI&apos;,&apos;SK&apos;,&apos;ES&apos;,&apos;SE&apos;,&apos;HU&apos;,&apos;HR&apos;) OR
            (SubStr(Trim(COALESCE(cft.Codfiscal,cfd.Codfiscal,a.Codfiscal,cfi.Codfiscal)),1,2) = &apos;GB&apos; AND i.datadoc &lt; To_Date(&apos;01.01.2021&apos;,&apos;dd.mm.yyyy&apos;)) OR
            (SubStr(Trim(COALESCE(cft.Codfiscal,cfd.Codfiscal,a.Codfiscal,cfi.Codfiscal)),1,2) = &apos;XI&apos; AND i.datadoc &gt; To_Date(&apos;31.12.2020&apos;,&apos;dd.mm.yyyy&apos;))
          )
    GROUP BY i.codies, i.tipdoc, d.tip
    UNION ALL
    SELECT
      i.codintr coddoc, i.tipdoc,
      Max(i.partener) Partener,
      Max(Coalesce(i.moneda,0)) moneda, Max(Coalesce(NULLIF(i.curs,0),1)) Curs, Max(I.Obs) Obs, Max(Coalesce(I.PrefixDoc,&apos;&apos;)||I.NrDoc||&apos;/&apos;||To_Char(I.DataDoc,&apos;dd.mm.yyyy&apos;)) Doc,
      D.TIP,
      Max(SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2)) TARA,
      Max(Trim(SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),3))) CodO,
      CASE
        WHEN vISIVB = 1 AND Max(CASE WHEN ex.codunic IS NULL AND i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1 AND D.TIP =  3 THEN 1
        WHEN vISIVB = 1 AND Max(CASE WHEN ex.codunic IS NULL AND i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1 AND D.TIP &lt;&gt; 3 THEN 0
        ELSE Sum(CASE WHEN (ex.codunic IS NOT NULL) OR D.TIP = CASE WHEN aicb.codunic IS NOT NULL THEN 4 WHEN i1.tiplinie = &apos;=&apos; THEN 4 WHEN i1.tiplinie = &apos;S&apos; THEN 3 ELSE v.tip END THEN 0 ELSE 1 END)
      END NrLinii,
      CASE
        WHEN vISIVB = 1 AND MAX( Coalesce(ex.codunic,0) ) = 0 AND Max(CASE WHEN i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1
         AND NOT EXISTS (SELECT 1 FROM intrari1 i1x WHERE i1x.codintr = i.codintr AND Coalesce(i1x.impozabil, 0) = 4)
        THEN Max(Coalesce(I.ValDoc,0)-Coalesce(I.TvaDoc,0))
        WHEN vISIVB = 1 AND MAX( Coalesce(ex.codunic,0) ) &lt;&gt; 0 AND Max(CASE WHEN i1.tiplinie = &apos;=&apos; THEN 1 ELSE 0 END) = 1
        THEN Sum(
               CASE
                 WHEN D.TIP &lt;&gt; 3 THEN 0
                 WHEN (ex.codunic IS NOT NULL) AND NOT Coalesce(art.contserviciu, -2) IN (vCDiscountNir, vCDiscountFact) THEN 0
                 ELSE CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
               END
             )
        WHEN Max(CASE WHEN (ex.codunic IS NOT NULL) OR D.TIP = CASE WHEN aicb.codunic IS NOT NULL THEN 4 WHEN i1.tiplinie = &apos;=&apos; THEN 4 WHEN i1.tiplinie = &apos;S&apos; THEN 3 ELSE v.tip END THEN 1 ELSE 0 END) = 0
         AND NOT EXISTS (SELECT 1 FROM intrari1 i1x WHERE i1x.codintr = i.codintr AND Coalesce(i1x.impozabil, 0) = 4)
        THEN Max(Coalesce(I.ValDoc,0)-Coalesce(I.TvaDoc,0))
        ELSE Sum(
               CASE
                 WHEN D.TIP = 3 AND Coalesce(art.contserviciu, -2) IN (vCDiscountNir, vCDiscountFact) THEN CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
                 WHEN D.TIP = CASE WHEN aicb.codunic IS NOT NULL THEN 4 WHEN i1.tiplinie = &apos;=&apos; THEN 4 WHEN i1.tiplinie = &apos;S&apos; THEN 3 ELSE v.tip END THEN 0
                 WHEN ex.codunic IS NOT NULL THEN 0
                 ELSE CASE WHEN (1 + coalesce(i1.addim/100, 0)) = i1.coefdiscmaj THEN i1.pu ELSE i1.pretorig*Coalesce(i1.coefdiscmaj,1) END*i1.cant
               END
             )
      END BazaVal
    FROM intrari i
      INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
      LEFT JOIN nartobj obj ON obj.codobiect = i1.codobiect
      LEFT JOIN nart art ON art.codarticol = obj.codarticol
      LEFT JOIN nagenda sl ON sl.Codagenda = i.Codlocatie
      LEFT JOIN nagenda ss ON ss.CodPart = i.partener AND ss.SediuSocial BETWEEN 4 AND 7 AND Coalesce(ss.INACTIV, 0) = 0
      INNER JOIN nlocalit l ON l.Codlocalit = Coalesce(sl.Codlocalit, ss.Codlocalit)
      INNER JOIN ntari n ON n.Codtara = l.Codtara
      LEFT JOIN dvi ON dvi.codintr = i.codintr
      LEFT JOIN npartCodfisc cfd ON cfd.Cod_Codfiscal = i.Codfiscal
      LEFT JOIN npartCodfisc cfi ON cfi.Codpart = i.partener AND cfi.principal = 1
      LEFT JOIN tmp_manevra ex ON ex.codunic = i1.codobiect
      LEFT JOIN tmp_manevra2 aicb ON aicb.codunic = i1.codobiect AND i.tiptranzactie = 2 AND i1.tiplinie IN ( &apos;S&apos;, &apos;V&apos; )
      CROSS JOIN (SELECT 3 TIP FROM DUAL UNION SELECT 4 TIP FROM DUAL ) D
      LEFT JOIN (
        SELECT i.codintr, CASE WHEN Max(Coalesce(o.icont,0)) = 12 THEN 3 ELSE 4 END tip
        FROM intrari i
          INNER JOIN general g ON g.tipdoc = i.tipdoc AND g.coddoc = i.codintr
          INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
        WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,5,9) AND i.tiptranzactie = 2 AND NOT (i.tiptva IN (1, 8))
          AND i.datadoc BETWEEN vDataIni AND vDataFin
          AND i.subunitatea = CASE WHEN pSubunit = 1 THEN i.subunitatea ELSE pSubunit END
          AND G.SEMNIFICATIE IN (110,111)
        GROUP BY i.codintr
      ) V ON v.codintr = i.codintr
    WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,5,9) AND i.tiptranzactie = 2 AND NOT (i.tiptva IN (1, 8))
      AND i.datadoc BETWEEN vDataIni AND vDataFin
      AND i.subunitatea = CASE WHEN pSubunit = 1 THEN i.subunitatea ELSE pSubunit END
      AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;) AND Coalesce(i1.impozabil, 0) &lt;&gt; 4
      AND Coalesce(dvi.tipimport,0) = 0
      AND (  SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) IN (&apos;AT&apos;,&apos;BE&apos;,&apos;BG&apos;,&apos;CZ&apos;,&apos;CY&apos;,&apos;DK&apos;,&apos;EE&apos;,&apos;EL&apos;,&apos;DE&apos;,&apos;FI&apos;,&apos;FR&apos;,&apos;GR&apos;,&apos;IE&apos;,&apos;IT&apos;,&apos;LV&apos;,&apos;LU&apos;,&apos;LT&apos;,&apos;MT&apos;,&apos;NL&apos;,&apos;PL&apos;,&apos;PT&apos;,&apos;SI&apos;,&apos;SK&apos;,&apos;ES&apos;,&apos;SE&apos;,&apos;HU&apos;,&apos;HR&apos;) OR
            (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;GB&apos; AND i.datadoc &lt; To_Date(&apos;01.01.2021&apos;,&apos;dd.mm.yyyy&apos;)) OR
            (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;XI&apos; AND i.datadoc &gt; To_Date(&apos;31.12.2020&apos;,&apos;dd.mm.yyyy&apos;))
          )
    GROUP BY i.codintr, i.tipdoc, d.tip
  )
  SELECT
    0 CodD390D, -Dense_Rank() OVER (ORDER BY X.TARA, X.CodO, P.DEN_PART, X.TIP ) CodD390O, vCodD390, 0  IdxFirma,
    X.CodDoc, X.TipDoc, x.DOC, M.Simbol,
    CASE X.TIP WHEN 0 THEN &apos;T&apos; WHEN 1 THEN &apos;L&apos; WHEN 2 THEN &apos;P&apos; WHEN 3 THEN &apos;A&apos; WHEN 4 THEN &apos;S&apos; WHEN 5 THEN &apos;R&apos;END Tip,
    X.BazaVal, X.Curs, Round(X.BazaVal * X.Curs,2), X.Obs, 0 Sters, 0 CazSpecial, X.TARA, X.CodO, P.DEN_PART, 0, &apos;?&apos;
  FROM x
    INNER JOIN npart p ON p.Codpart = x.partener
    INNER JOIN nmonede m ON m.codmoneda = x.moneda
  WHERE x.NrLinii &gt; 0
  ORDER BY X.TARA, X.CodO, P.DEN_PART, X.TIP;

  UPDATE TMP_D390D T
  SET CAZSPECIAL = 1
  WHERE EXISTS (
          SELECT 1 
          FROM INTRARI1 I1 LEFT JOIN DVI1 D1 ON D1.CODINTR1 = I1.CODINTR1 
          WHERE I1.CODINTR = T.CODSURSA AND Coalesce(D1.TVA, I1.TVA, 0) &lt;&gt; 0 AND Coalesce(I1.COEFDISCMAJ, 1) &lt;&gt; 0 AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;)
        )
    AND TIPSURSA IN (1,5,9)
    AND BAZALEI = 0;

  UPDATE TMP_D390D T
  SET CAZSPECIAL = 1
  WHERE EXISTS (SELECT 1 FROM IESIRI1 I1 WHERE I1.CODIES = T.CODSURSA AND Coalesce(I1.TVA, 0) &lt;&gt; 0 AND Coalesce(I1.COEFDISCMAJ, 1) &lt;&gt; 0 AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;))
    AND TIPSURSA IN (19,22,26)
    AND BAZALEI = 0;

  INSERT INTO TMP_D390O (CODD390O, CODD390, TIP, TARA, CODO, DENO, BAZA, CAZSPECIAL)
  SELECT CODD390O, Max(CODD390), Max(TIP), Max(TARA), Max(CODO), Max(DENO), Sum(BAZALEI), Sum(CAZSPECIAL)
  FROM TMP_D390D
  GROUP BY CODD390O;

  IF pAn*12+pLuna &gt;= 2020*12+2 THEN
    INSERT INTO TMP_D390CA  (CODD390CA, CODD390, TARA_M1, COD_M1)
    SELECT 0 CodD390D, vCodD390 CodD390, SubStr(CodFiscal,1,2) TARA_M1, Trim(SubStr(CodFiscal,3)) COD_M1
    FROM (
      SELECT DISTINCT Upper(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal))) CodFiscal
      FROM iesiri i
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        LEFT JOIN nagenda sl ON sl.Codagenda = i.Codlocatie
        LEFT JOIN nagenda ss ON ss.CodPart = i.partener AND ss.SediuSocial BETWEEN 4 AND 7 AND Coalesce(ss.INACTIV, 0) = 0
        LEFT JOIN npartCodfisc cfd ON cfd.Cod_Codfiscal = i.Codfiscal
        LEFT JOIN npartCodfisc cfi ON cfi.Codpart = i.partener AND cfi.principal = 1
      WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc = 20 --AND i.tiptranzactie = 2 AND i.tiptva &lt;&gt; 8
        AND i.datadoc BETWEEN vDataIni AND vDataFin
        AND i.subunitatea = CASE WHEN pSubunit = 1 THEN i.subunitatea ELSE pSubunit END
        AND Coalesce(I.Custodie, 0) = 2
        AND i1.cant &gt; 0
        AND (  SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) IN (&apos;AT&apos;,&apos;BE&apos;,&apos;BG&apos;,&apos;CZ&apos;,&apos;CY&apos;,&apos;DK&apos;,&apos;EE&apos;,&apos;EL&apos;,&apos;DE&apos;,&apos;FI&apos;,&apos;FR&apos;,&apos;GR&apos;,&apos;IE&apos;,&apos;IT&apos;,&apos;LV&apos;,&apos;LU&apos;,&apos;LT&apos;,&apos;MT&apos;,&apos;NL&apos;,&apos;PL&apos;,&apos;PT&apos;,&apos;SI&apos;,&apos;SK&apos;,&apos;ES&apos;,&apos;SE&apos;,&apos;HU&apos;,&apos;HR&apos;) OR
              (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;GB&apos; AND i.datadoc &lt; To_Date(&apos;01.01.2021&apos;,&apos;dd.mm.yyyy&apos;)) OR
              (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;XI&apos; AND i.datadoc &gt; To_Date(&apos;31.12.2020&apos;,&apos;dd.mm.yyyy&apos;))
            )
    ) A_PG;

    INSERT INTO TMP_D390CB (CODD390CB, CODD390, TARA_M1, COD_M1, MOTIV)
    SELECT 0 CodD390D, vCodD390 CodD390, SubStr(CodFiscal,1,2) TARA_M1, Trim(SubStr(CodFiscal,3)) COD_M1, 1
    FROM (
      SELECT DISTINCT Upper(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal))) CodFiscal
      FROM iesiri i
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        LEFT JOIN nagenda sl ON sl.Codagenda = i.Codlocatie
        LEFT JOIN nagenda ss ON ss.CodPart = i.partener AND ss.SediuSocial BETWEEN 4 AND 7 AND Coalesce(ss.INACTIV, 0) = 0
        LEFT JOIN npartCodfisc cfd ON cfd.Cod_Codfiscal = i.Codfiscal
        LEFT JOIN npartCodfisc cfi ON cfi.Codpart = i.partener AND cfi.principal = 1
      WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc = 20 --AND i.tiptranzactie = 2 AND i.tiptva &lt;&gt; 8
        AND i.datadoc BETWEEN vDataIni AND vDataFin
        AND i.subunitatea = CASE WHEN pSubunit = 1 THEN i.subunitatea ELSE pSubunit END
        AND Coalesce(I.Custodie, 0) = 2
        AND i1.cant &lt; 0
        AND (  SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) IN (&apos;AT&apos;,&apos;BE&apos;,&apos;BG&apos;,&apos;CZ&apos;,&apos;CY&apos;,&apos;DK&apos;,&apos;EE&apos;,&apos;EL&apos;,&apos;DE&apos;,&apos;FI&apos;,&apos;FR&apos;,&apos;GR&apos;,&apos;IE&apos;,&apos;IT&apos;,&apos;LV&apos;,&apos;LU&apos;,&apos;LT&apos;,&apos;MT&apos;,&apos;NL&apos;,&apos;PL&apos;,&apos;PT&apos;,&apos;SI&apos;,&apos;SK&apos;,&apos;ES&apos;,&apos;SE&apos;,&apos;HU&apos;,&apos;HR&apos;) OR
              (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;GB&apos; AND i.datadoc &lt; To_Date(&apos;01.01.2021&apos;,&apos;dd.mm.yyyy&apos;)) OR
              (SubStr(Trim(COALESCE(cfd.Codfiscal,sl.Codfiscal,ss.Codfiscal,cfi.Codfiscal)),1,2) = &apos;XI&apos; AND i.datadoc &gt; To_Date(&apos;31.12.2020&apos;,&apos;dd.mm.yyyy&apos;))
            )
    ) A_PG;

  END IF;
END;

END PKG_D390;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_D394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EDCC052531989776059D08F5B60EBA447416C3B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_D394 IS

  vDataBonD394      DATE;
  vLimitaBonD394    NUMBER;
  vLimitaLeiBonD394 NUMBER;
  vBancaBonD394     NUMBER(20);
  vMonedaBonD394    NUMBER(20);

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODD394 INTO Tmp FROM D394 WHERE CodD394 = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);

 	DELETE FROM D394VC WHERE CodD394V IN (SELECT CodD394V FROM D394V WHERE CodD394 = RecId);
 	DELETE FROM D394CC WHERE CodD394C IN (SELECT CodD394C FROM D394C WHERE CodD394 = RecId);
 	DELETE FROM D394V  WHERE CodD394  = RecId ;
 	DELETE FROM D394C  WHERE CodD394  = RecId ;
 	DELETE FROM D394L  WHERE CodD394  = RecId ;
 	DELETE FROM D394A  WHERE CodD394  = RecId ;
  DELETE FROM D394   WHERE CodD394  = RecId ;

  NotifyModif(2, RecId, &apos;D394&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_D394 FIELDS( CodD394 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  -- Master D394
  INSERT INTO TMP_D394 (
    CodD394, TipD394,
    An, LunaD,
    CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
    CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
    NrTotFB,
    BazaLivr, TVALivr, BazaAchiz, TVAAchiz, BazaV, TVAV, BazaC, TVAC, BazaVC, TVAVC, BazaCC, TVACC,
    SumaControl,
    Subunitatea, Nume, Prenume, Functia, Centralizat, Tip, Semestru, Obs,
    NrFactL, NrFactA, NrFactV, NrFactC)
  SELECT
    CodD394, Nvl(TipD394, Decode(TIP,1,&apos;L&apos;,&apos;S&apos;)),
    An, Nvl(LunaD,CASE WHEN Tip = 1 THEN To_Number(Semestru) WHEN Semestru = &apos;S2&apos; THEN 12 ELSE 6 END),
    CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
    CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
    Nvl(NrTotFB,0),
    Nvl(BazaLivr,0), Nvl(TVALivr,0), Nvl(BazaAchiz,0), Nvl(TVAAchiz,0), Nvl(BazaV,0), Nvl(TVAV,0), Nvl(BazaC,0), Nvl(TVAC,0), Nvl(BazaVC,0), Nvl(TVAVC,0), Nvl(BazaCC,0), Nvl(TVACC,0),
    Nvl(SumaControl,0),
    Subunitatea, Nume, Prenume, Functia, Nvl(Centralizat,0), Tip, Semestru, Obs,
    NrFactL, NrFactA, NrFactV, NrFactC
  FROM D394
  WHERE CodD394 = RecId;

  -- Detail D394L
  INSERT INTO TMP_D394L (
    CodD394L, CodD394,
    TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact,
    RO)
  SELECT
    CodD394L, CodD394,
    TipOperatiune, PKG_D394.ExtrageNr(CISTVABFP), DenBFP, Baza, TVA, Generat, Trim(CFText), CodSursa, TipSursa, OBS, NrFact,
    CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END
  FROM D394L
  WHERE CodD394 = RecId;

  -- Detail D394A
  INSERT INTO  TMP_D394A (
    CodD394A, CodD394,
    TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact,
    RO)
  SELECT
    CodD394A, CodD394,
    TipOperatiune, PKG_D394.ExtrageNr(CISTVABFP), DenBFP, Baza, TVA, Generat, Trim(CFText), CodSursa, TipSursa, OBS, NrFact,
    CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END
  FROM D394A
  WHERE CodD394 = RecId;

  -- Detail D394V
  INSERT INTO TMP_D394V (
    CodD394V, CodD394,
    TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact,
    RO)
  SELECT
    CodD394V, CodD394,
    TipOperatiune, PKG_D394.ExtrageNr(CISTVABFP), DenBFP, Baza, TVA, Generat, Trim(CFText), CodSursa, TipSursa, OBS, NrFact,
    CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END
  FROM D394V
  WHERE CodD394 = RecId;

  -- Detail D394VC
  INSERT INTO TMP_D394VC (
    CodD394VC, CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, Obs)
  SELECT
    CodD394VC, CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, Obs
  FROM D394VC
  WHERE CodD394V IN (SELECT CodD394V FROM TMP_D394V);

  -- Detail D394C
  INSERT INTO  TMP_D394C (
    CodD394C, CodD394, TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact,
    RO)
  SELECT
    CodD394C, CodD394, TipOperatiune, PKG_D394.ExtrageNr(CISTVABFP), DenBFP, Baza, TVA, Generat, Trim(CFText), CodSursa, TipSursa, OBS, NrFact,
    CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END
  FROM D394C
  WHERE CodD394 = RecId;

  -- Detail D394CC
  INSERT INTO TMP_D394CC (
    CodD394CC, CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, Obs)
  SELECT
    CodD394CC, CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, Obs
  FROM D394CC
  WHERE CodD394C IN (SELECT CodD394C FROM TMP_D394C);

  COMMIT;

END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vCod   NUMBER(20);
BEGIN
  UPDATE TMP_D394A SET CFText = RO||CISTVABFP;
  UPDATE TMP_D394L SET CFText = RO||CISTVABFP;
  UPDATE TMP_D394C SET CFText = RO||CISTVABFP;
  UPDATE TMP_D394V SET CFText = RO||CISTVABFP;

  IF Operation = 0
  THEN  -- UPDATE
    -- Master D394
    SELECT  CodD394 INTO RecId FROM TMP_D394;

    UPDATE D394
    SET  (CodD394, TipD394, LunaD, An, CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
          CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
          NrTotFB, BazaLivr, TVALivr, BazaAchiz, TVAAchiz, BazaV, TVAV, BazaC, TVAC, BazaVC, TVAVC, BazaCC, TVACC,
          SumaControl, Subunitatea, Nume, Prenume, Functia, Centralizat, Tip, Semestru, Obs,
          NrFactL, NrFactA, NrFactV, NrFactC)
      =(SELECT
          CodD394, TipD394, LunaD, An, CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
          CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
          NrTotFB, BazaLivr, TVALivr, BazaAchiz, TVAAchiz, BazaV, TVAV, BazaC, TVAC, BazaVC, TVAVC, BazaCC, TVACC,
          SumaControl, Subunitatea, Nume, Prenume, Functia, Centralizat, Tip, Semestru, Obs,
          NrFactL, NrFactA, NrFactV, NrFactC
        FROM TMP_D394 )
    WHERE CodD394 = RecId ;

    -- Detail D394A
    DELETE FROM D394A
    WHERE CodD394 = RecID AND CodD394A NOT IN (SELECT CodD394A FROM TMP_D394A);

    FOR v_rec IN (SELECT * FROM TMP_D394A ORDER BY CodD394A) LOOP
      IF nvl(v_rec.codD394A,0) &gt; 0 THEN
        UPDATE D394A
        SET    TipOperatiune = v_rec.tipoperatiune ,
               CISTVABFP     = v_rec.cistvabfp ,
               DenBFP        = v_rec.denbfp,
               Baza          = v_rec.baza,
               TVA           = v_rec.tva,
               Generat       = v_rec.generat,
               CFText        = v_rec.cftext,
               CodSursa      = v_rec.codsursa,
               TipSursa      = v_rec.tipsursa,
               OBS           = v_rec.obs,
               NrFact        = v_rec.NrFact
        WHERE  CodD394 = RecID AND CodD394A = v_rec.CodD394A;
      ELSE
        select seq_D394A_CodD394A.nextval INTO vCod from dual;
        INSERT INTO  D394A (
          CodD394A, CodD394,
          TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
          Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
        VALUES (
          vCod , RecId,
          v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
          v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);
      END IF;
    END LOOP;

    -- Detail D394L
    DELETE FROM D394L
    WHERE CodD394 = RecID AND CodD394L NOT IN (SELECT CodD394L FROM TMP_D394L);

    FOR v_rec IN (SELECT * FROM TMP_D394L ORDER BY CodD394L) LOOP
      IF nvl(v_rec.codd394l,0) &gt; 0 THEN
        UPDATE D394L
        SET    TipOperatiune = v_rec.tipoperatiune ,
               CISTVABFP     = v_rec.cistvabfp ,
               DenBFP        = v_rec.denbfp,
               Baza          = v_rec.baza,
               TVA           = v_rec.tva,
               Generat       = v_rec.generat,
               CFText        = v_rec.cftext,
               CodSursa      = v_rec.codsursa,
               TipSursa      = v_rec.tipsursa,
               OBS           = v_rec.obs,
               NrFact        = v_rec.NrFact
        WHERE  CodD394 = RecID AND CodD394L = v_rec.Codd394l;
      ELSE
        select seq_D394L_CodD394L.nextval INTO vCod from dual;
        INSERT INTO  D394L (
          CodD394L, CodD394,
          TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
          Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
        VALUES (
          vCod , RecId,
          v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
          v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);
      END IF;
    END LOOP;

    -- Detail D394V
    DELETE FROM D394VC -- sterg toate inregistrarile pt ca la Centralizare se dau peste cap
    WHERE CodD394V IN (SELECT CodD394V FROM D394V WHERE CodD394 = RecID);

    DELETE FROM D394V
    WHERE CodD394 = RecID
      AND CodD394V NOT IN (SELECT CodD394V FROM TMP_D394V);

    FOR v_rec IN (SELECT * FROM TMP_D394V ORDER BY CodD394V) LOOP
      IF nvl(v_rec.CodD394V,0) &gt; 0 THEN
        UPDATE D394V
        SET    TipOperatiune = v_rec.tipoperatiune ,
               CISTVABFP     = v_rec.cistvabfp ,
               DenBFP        = v_rec.denbfp,
               Baza          = v_rec.baza,
               TVA           = v_rec.tva,
               Generat       = v_rec.generat,
               CFText        = v_rec.cftext,
               CodSursa      = v_rec.codsursa,
               TipSursa      = v_rec.tipsursa,
               OBS           = v_rec.obs,
               NrFact        = v_rec.NrFact
        WHERE  CodD394 = RecID AND CodD394V = v_rec.CodD394V;
      ELSE
        select seq_D394V_CodD394V.nextval INTO vCod from dual;
        INSERT INTO  D394V (
          CodD394V, CodD394,
          TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
          Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
        VALUES (
          vCod , RecId,
          v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
          v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);

        UPDATE TMP_D394VC SET CodD394V = vCod WHERE CodD394V = v_rec.CodD394V;
      END IF;
    END LOOP;

    INSERT INTO D394VC (
      CodD394VC,
      CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS)
    SELECT
      CASE
        WHEN NVL(CodD394VC,0) &gt; 0 THEN CodD394VC
        ELSE seq_D394VC_CodD394VC.NEXTVAL
      END,
      CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS
    FROM TMP_D394VC;

    -- Detail D394C
    DELETE FROM D394CC -- sterg toate inregistrarile pt ca la Centralizare se dau peste cap
    WHERE CodD394C IN (SELECT CodD394C FROM D394C WHERE CodD394 = RecID);

    DELETE FROM D394C
    WHERE CodD394 = RecID
      AND CodD394C NOT IN (SELECT CodD394C FROM TMP_D394C);

    FOR v_rec IN (SELECT * FROM TMP_D394C ORDER BY CodD394C) LOOP
      IF nvl(v_rec.CodD394C,0) &gt; 0 THEN
        UPDATE D394C
        SET    TipOperatiune = v_rec.tipoperatiune ,
               CISTVABFP     = v_rec.cistvabfp ,
               DenBFP        = v_rec.denbfp,
               Baza          = v_rec.baza,
               TVA           = v_rec.tva,
               Generat       = v_rec.generat,
               CFText        = v_rec.cftext,
               CodSursa      = v_rec.codsursa,
               TipSursa      = v_rec.tipsursa,
               OBS           = v_rec.obs,
               NrFact        = v_rec.NrFact
        WHERE  CodD394 = RecID AND CodD394C = v_rec.CodD394C;
      ELSE
        select seq_D394C_CodD394C.nextval INTO vCod from dual;
        INSERT INTO  D394C (
          CodD394C, CodD394,
          TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
          Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
        VALUES (
          vCod , RecId,
          v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
          v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);

        UPDATE TMP_D394CC SET CodD394C = vCod WHERE CodD394C = v_rec.CodD394C;
      END IF;
    END LOOP;

    INSERT INTO  D394CC ( CodD394CC, CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS)
    SELECT
      CASE
        WHEN NVL(CodD394CC,0) &gt; 0 THEN CodD394CC
        ELSE seq_D394CC_CodD394CC.NEXTVAL
      END,
      CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS
    FROM TMP_D394CC;
  ELSE  -- INSERT
    -- Master D394
    SELECT seq_D394_CodD394.NextVal INTO RecId FROM DUAL;

    INSERT INTO  D394 (
      CodD394, TipD394, LunaD, An, CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
      CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
      NrTotFB, BazaLivr, TVALivr, BazaAchiz, TVAAchiz, BazaV, TVAV, BazaC, TVAC, BazaVC, TVAVC, BazaCC, TVACC,
      SumaControl, Subunitatea, Nume, Prenume, Functia, Centralizat, Tip, Semestru, Obs,
      NrFactL, NrFactA, NrFactV, NrFactC)
    SELECT
      RecId, TipD394, LunaD, An, CISTVA, DenContrib, DomFiscContrib, Tel, Fax, EMail,
      CIFReprFisc, DenReprFisc, DomFiscReprFisc, TelReprFisc, FaxReprFisc, EMailReprFisc,
      NrTotFB, BazaLivr, TVALivr, BazaAchiz, TVAAchiz, BazaV, TVAV, BazaC, TVAC, BazaVC, TVAVC, BazaCC, TVACC,
      SumaControl, Subunitatea, Nume, Prenume, Functia, Centralizat, Tip, Semestru, Obs,
      NrFactL, NrFactA, NrFactV, NrFactC
    FROM TMP_D394;

    -- Detail D394A
    SELECT COUNT(1) INTO vRecNo FROM TMP_D394A;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394A_CodD394A increment by &apos;||vRecNo;
      select seq_D394A_CodD394A.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394A_CodD394A increment by 1&apos;;
      INSERT INTO  D394A (
        CodD394A, CodD394,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
      SELECT
        vCod + RowNum, RecId,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact
      FROM TMP_D394A;
    END IF;

    -- Detail D394L
    SELECT COUNT(1) INTO vRecNo FROM TMP_D394L;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394L_CodD394L increment by &apos;||vRecNo;
      select seq_D394L_CodD394L.nextval - vRecNo INTO vCod from dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394L_CodD394L increment by 1&apos;;
      INSERT INTO  D394L (
        CodD394L, CodD394,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
      SELECT
        vCod + RowNum, RecId,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, OBS, NrFact
      FROM TMP_D394L;
    END IF;

    -- Detail D394V
    FOR v_rec IN (SELECT * FROM TMP_D394V ORDER BY CodD394V) LOOP
      select seq_D394V_CodD394V.nextval INTO vCod from dual;
      INSERT INTO D394V (
        CodD394V, CodD394,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
        Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
      VALUES (
        vCod, RecId,
        v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
        v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);

      UPDATE TMP_D394VC SET CodD394V = vCod WHERE CodD394V = v_rec.CodD394V;
    END LOOP;

    SELECT COUNT(1) INTO vRecNo FROM TMP_D394VC;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394VC_CodD394VC increment by &apos;||vRecNo;
      select seq_D394VC_CodD394VC.nextval - vRecNo INTO vCod FROM dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394VC_CodD394VC increment by 1&apos;;
      INSERT INTO D394VC (CodD394VC, CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS)
      SELECT vCod + RowNum, CodD394V, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS
      FROM TMP_D394VC;
    END IF;

    -- Detail D394C
    FOR v_rec IN (SELECT * FROM TMP_D394C ORDER BY CodD394C) LOOP
      select seq_D394C_CodD394C.nextval INTO vCod from dual;
      INSERT INTO D394C (
        CodD394C, CodD394,
        TipOperatiune, CISTVABFP, DenBFP, Baza, TVA,
        Generat, CFText, CodSursa, TipSursa, OBS, NrFact)
      VALUES (
        vCod, RecId,
        v_rec.tipoperatiune, v_rec.cistvabfp , v_rec.denbfp, v_rec.baza, v_rec.tva,
        v_rec.generat, v_rec.cftext, v_rec.codsursa, v_rec.tipsursa, v_rec.obs, v_rec.NrFact);

      UPDATE TMP_D394CC SET CodD394C = vCod WHERE CodD394C = v_rec.CodD394C;
    END LOOP;

    SELECT COUNT(1) INTO vRecNo FROM TMP_D394CC;

    IF vRecNo &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394CC_CodD394CC increment by &apos;||vRecNo;
      select seq_D394CC_CodD394CC.nextval - vRecNo INTO vCod FROM dual;
      EXECUTE IMMEDIATE &apos;alter sequence seq_D394CC_CodD394CC increment by 1&apos;;
      INSERT INTO D394CC (CodD394CC, CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS)
      SELECT vCod + RowNum, CodD394C, DenProdus, CodNC, Baza, TVA, CodSursa1, OBS
      FROM TMP_D394CC;
    END IF;

  END IF;

  NotifyModif(Operation, RecId, &apos;D394&apos;);
  COMMIT;

END;

FUNCTION ExtrageNr (pSursa VARCHAR2) RETURN NUMBER IS
  vAux VARCHAR2(99) := &apos;&apos;;
BEGIN
  IF pSursa IS NOT NULL THEN
    FOR i IN 1..LENGTH(pSursa) LOOP
      IF SUBSTR(pSursa,i,1) BETWEEN &apos;0&apos; AND &apos;9&apos;
      THEN vAux := vAux ||SUBSTR(pSursa,i,1);
      END IF;
    END LOOP;
  END IF;
  RETURN vAux;
END;

FUNCTION ExtrageLit(pSursa VARCHAR2) RETURN VARCHAR2 IS
  vAux VARCHAR2(99) := &apos;&apos;;
BEGIN
  IF pSursa IS NOT NULL THEN
    FOR i IN 1..LENGTH(pSursa) LOOP
      IF Upper(SUBSTR(pSursa,i,1)) BETWEEN &apos;A&apos; AND &apos;Z&apos;
      THEN vAux := vAux ||SUBSTR(pSursa,i,1);
      END IF;
    END LOOP;
  END IF;
  RETURN vAux;
END;

FUNCTION ExtrageCFBon(pSursa VARCHAR2) RETURN VARCHAR2 IS
  vAux VARCHAR2(100) := &apos;&apos;;
  vPos NUMBER;
  vRes VARCHAR2(20);
  i    INTEGER;
BEGIN
  vAux := Upper(pSursa);

  LOOP
    vPos := InStr(vAux,&apos;RO&apos;);
    IF vPos &gt; 0 THEN
      vAux := Trim(SubStr(vAux, vPos + 2));
      IF SubStr(vAux,1,1) BETWEEN &apos;0&apos; AND &apos;9&apos;
      THEN
        i    := 0;
        vRes := &apos;RO&apos;;
        LOOP
          i := i+1;
          IF SubStr(vAux,i,1) BETWEEN &apos;0&apos; AND &apos;9&apos;
          THEN
            vRes := vRes ||SubStr(vAux,i,1);
          ELSE
            vAux := &apos;&apos;;
            EXIT;
          END IF;
        END LOOP;
      ELSE
        vPos := 0;
      END IF;
    ELSE
      vAux := &apos;&apos;;
    END IF;

    EXIT WHEN vAux IS NULL;
  END LOOP;

  RETURN vRes;
END;

FUNCTION LimitaBon (pData DATE) RETURN NUMBER IS
BEGIN
  IF pData &lt;&gt; Nvl(vDataBonD394,pData-1) THEN
    IF vDataBonD394 IS NULL OR Trunc(pDATA,&apos;MM&apos;) &lt;&gt; Trunc(vDataBonD394,&apos;MM&apos;) THEN
      vBancaBonD394  := Nvl(pkg_categconst.GetValConstanta(&apos;BancaBonD394&apos; , EXTRACT(YEAR FROM pDATA), EXTRACT (MONTH FROM pDATA)),0);
      vMonedaBonD394 := Nvl(pkg_categconst.GetValConstanta(&apos;MonedaBonD394&apos;, EXTRACT(YEAR FROM pDATA), EXTRACT (MONTH FROM pDATA)),0);
      vLimitaBonD394 := Nvl(pkg_categconst.GetValConstanta(&apos;LimitaBonD394&apos;, EXTRACT(YEAR FROM pDATA), EXTRACT (MONTH FROM pDATA)),0);
    END IF;

    IF vLimitaBonD394 &lt;&gt; 0 THEN
      SELECT Max(NVL(VALOARE* vLimitaBonD394, 0)) KEEP (Dense_Rank LAST ORDER BY N1.DATA) INTO vLimitaLeiBonD394
      FROM NMONEDE  N INNER JOIN NMONEDE1 N1 ON N1.CODMONEDA = N.CODMONEDA
      WHERE N.CODMONEDA = vMonedaBonD394
        AND N1.CODBANCA = vBancaBonD394
        AND N1.DATA &lt;= pData;
    ELSE
      vLimitaLeiBonD394 := 0;
    END IF;

    vDataBonD394 := pData;
  END IF;

  RETURN vLimitaLeiBonD394;
END;


PROCEDURE Generare( pSursa INTEGER, pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER) IS
  vLunaIni INTEGER;
  vLunaFin INTEGER;
  vDataIni DATE;
  vDataFin DATE;
  vCodD394 INTEGER;
BEGIN
  vLunaFin := pLuna;

  IF vLunaFin &gt; PKG_GLOBALS.GetLunaLucru AND pAn = PKG_GLOBALS.GetAnLucru
  THEN vLunaFin := PKG_GLOBALS.GetLunaLucru ;
  END IF;

  IF    pTip = 0 THEN vLunaIni := 1;
  ELSIF pTip = 1 THEN vLunaIni := CASE WHEN vLunaFin &gt; 6 THEN 7 ELSE 1 END;
  ELSIF pTip = 2 THEN vLunaIni := CASE WHEN vLunaFin &gt; 9 THEN 10 WHEN vLunaFin &gt; 6 THEN 7 WHEN vLunaFin &gt; 3 THEN 4 ELSE 1 END;
  ELSE                vLunaIni := vLunaFin;
  END IF;

  vDataIni := To_Date(&apos;01.&apos;||To_Char(vLunaIni,&apos;00&apos;)||&apos;.&apos;||To_Char(pAn,&apos;0000&apos;),&apos;dd.mm.yyyy&apos;);
  vDataFin := Last_Day(To_Date(To_Char(vLunaFin,&apos;00&apos;)||&apos;.&apos;||To_Char(pAn,&apos;0000&apos;),&apos;mm.yyyy&apos;));

  BEGIN
    SELECT CodD394 INTO vCodD394 FROM TMP_D394;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN vCodD394 := 0;
  END;

  -- golesc tabelele detaliu mai putin inregistrarile introduse manual
  DELETE FROM TMP_D394L  WHERE NVL(Generat,0) &lt;&gt; 4;
  DELETE FROM TMP_D394A  WHERE NVL(Generat,0) &lt;&gt; 4;
  DELETE FROM TMP_D394V  WHERE NVL(Generat,0) &lt;&gt; 4;
  DELETE FROM TMP_D394C  WHERE NVL(Generat,0) &lt;&gt; 4;
  DELETE FROM TMP_D394VC WHERE CODD394V NOT IN (SELECT CODD394V FROM TMP_D394V);
  DELETE FROM TMP_D394CC WHERE CODD394C NOT IN (SELECT CODD394C FROM TMP_D394C);

  -- Iesiri
  IF pSursa IN (0,2,3) THEN
    INSERT INTO TMP_D394L(
      CodD394L, CodD394, TipOperatiune,
      CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, NrFact)
    WITH IES AS (
      SELECT
        i.partener, p.den_part, COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal) codfiscal,
        SUM((CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END - Decode(I.TIPDOC,21,I1.TVA,0)) *(1+nvl(i1.procdisc,0)/100) * Decode(i.curs,NULL,1,0,1,i.curs)) BAZA,
        SUM(i1.tva*(1+nvl(i1.procdisc,0)/100) * Decode(i.curs,NULL,1,0,1,i.curs)) TVA, NVL(InfoCM,0) InfoCM, Count(DISTINCT i.codies) NrFact
      FROM iesiri i
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        INNER JOIN nagenda a ON a.codagenda = i.codlocatie
        INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
				INNER JOIN ntari n ON n.codtara = l.codtara
        INNER JOIN npart p ON p.codpart = i.partener
        LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
        LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
      WHERE (i.tipdoc IN (19,26) OR (i.tipdoc = 21 AND Nvl(i.factsimplif,0) = 1 AND i.valdoc &lt;= pkg_d394.LimitaBon(i.DataDoc)))
        AND i.operat = 1 AND i.anulat = 0
        AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
			  AND nvl(infoCM,0) = Decode(pSursa,0,1,3,nvl(infoCM,0),0)
        AND NVL(i.tiptva,0) &lt;&gt; 2
        AND upper(n.simbauto) = &apos;RO&apos;
        AND NOT ((i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;)) AND NVL(i1.contdiscount,0) = 0)
        AND NVL(i1.tva,0) &lt;&gt; 0
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND Nvl(p.persoanafizica,0) &lt;&gt; 1
      GROUP BY i.partener, p.den_part, nvl(infocm,0), cfd.codfiscal, a.codfiscal, cfi.codfiscal
    )
    SELECT
      0, vCodD394, &apos;L&apos;,
      PKG_D394.ExtrageNr(CODFISCAL), DEN_PART,  BAZA, TVA, CASE WHEN pSursa IN (0,3) THEN decode(Nvl(infocm,0),0,3,1) ELSE 3 END generat, Trim(CODFISCAL), NrFact
    FROM ies;
  END IF;

  IF pSursa IN (0,2,3) AND pAn &gt;= 2013 THEN--EMULARE TASTATURA
    INSERT INTO TMP_D394L(
      CodD394L, CodD394, TipOperatiune,
      CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, NrFact)
    WITH IES AS (
      SELECT
        DECODE(i.codpart,0,&apos;Bon casa de marcat&apos;,p.den_part) DEN_PART, COALESCE(a.codfiscal,cfi.codfiscal,i.codfiscal) codfiscal, sum(i1.cant * i1.pret - i1.tva) BAZA, sum(i1.tva) TVA,
        Count(DISTINCT i.codemulare) NrFact
      FROM (
        SELECT
          e.codemulare, e.codlocatie, pkg_d394.ExtrageCFBon(e.textnefiscal) codfiscal, Nvl(e.factsimplif,0) factsimplif, Nvl(e.codpart,0) codparte,
          CASE
            WHEN Nvl(e.codpart,0) &lt;&gt; 0 THEN e.CodPart
            ELSE (SELECT Max(xp.CodPart) FROM npartcodfisc xp WHERE xp.codfiscal = pkg_d394.ExtrageCFBon(e.textnefiscal))
          END codpart
        FROM emulare e
        WHERE e.codies IS NULL AND Nvl(e.tvatotal,0) &lt;&gt; 0
          AND e.valoare &lt;= pkg_d394.LimitaBon(e.DataBon)
          AND e.databon BETWEEN To_Date(To_Char(pAn,&apos;fm0000&apos;)||&apos;.&apos;||To_Char(vLunaIni,&apos;fm00&apos;),&apos;yyyy.mm&apos;) AND  Last_Day(To_Date(To_Char(pAn,&apos;fm0000&apos;)||&apos;.&apos;||To_Char(vLunaFin,&apos;fm00&apos;),&apos;yyyy.mm&apos;))
        ORDER BY e.DataBon
      ) i
        INNER JOIN emulare1 i1 ON i1.codemulare = i.codemulare
        LEFT JOIN nagenda a ON a.codagenda = i.codlocatie
        LEFT JOIN nlocalit l ON l.codlocalit = a.codlocalit
				LEFT JOIN ntari n ON n.codtara = l.codtara
        LEFT JOIN npart p ON p.codpart = i.codpart
        LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.codpart AND cfi.principal = 1
      WHERE (upper(n.simbauto) = &apos;RO&apos; OR a.codagenda IS NULL)
        AND (i.factsimplif = 1 OR (i.codparte = 0 AND i.codfiscal IS NOT NULL))
        AND NVL(i1.tva,0) &lt;&gt; 0
        AND Nvl(p.persoanafizica,0) &lt;&gt; 1
        AND TRIM(COALESCE(a.codfiscal,cfi.codfiscal,i.codfiscal)) IS NOT NULL
      GROUP BY DECODE(i.codpart,0,&apos;Bon casa de marcat&apos;,p.den_part), COALESCE(a.codfiscal,cfi.codfiscal,i.codfiscal)
    )
    SELECT
      0, vCodD394, &apos;L&apos;,
      PKG_D394.ExtrageNr(CODFISCAL), DEN_PART,  BAZA, TVA, 1 generat, Trim(CODFISCAL), NrFact
    FROM ies;
  END IF;

  IF pSursa IN (0,2,3) AND pAn &gt;= 2012 THEN
    INSERT INTO TMP_D394V (
      CodD394V, CodD394, TipOperatiune,
      CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, NrFact)
    WITH i AS (
      SELECT codies, tipdoc, partener, den_part, infocm, codfiscal, Sum(BAZA) BAZA, Sum(BAZA*coef_tva) TVA
      FROM (
        SELECT
          i.codies, i.tipdoc, i.partener, p.den_part, Nvl(i.infocm,0) infocm, COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal) codfiscal,
          i1.cant * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, Nvl(i1.coefdiscmaj,1), i1.valdiscpret)*Decode(i.curs,NULL,1,0,1,i.curs) BAZA,
          t1.procent / 100 coef_tva
        FROM iesiri i
          INNER JOIN iesiri1 i1 ON i1.codies = i.codies
          INNER JOIN nartobj o ON o.codobiect = Decode(i1.codobiectorig,NULL,i1.codobiect,0,i1.codobiect,i1.codobiectorig)
          INNER JOIN nagenda a ON a.codagenda = i.codlocatie
          INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
				  INNER JOIN ntari n ON n.codtara = l.codtara
          INNER JOIN npart p ON p.codpart = i.partener
          INNER JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.luna+i.an BETWEEN a1.ALStArt AND a1.ALStop
          INNER JOIN ntva1 t1 ON t1.codtva = a1.codtva        AND i.luna+i.an BETWEEN t1.ALStArt AND t1.ALStop
          LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
          LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
        WHERE (i.tipdoc IN (19,26) OR (i.tipdoc = 21 AND Nvl(i.factsimplif,0) = 1 AND i.valdoc &lt;= pkg_d394.LimitaBon(i.DataDoc)))
          AND i.operat = 1 AND i.anulat = 0
          AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
			    AND nvl(infoCM,0) = Decode(pSursa,0,1,3,nvl(infoCM,0),0)
          AND NVL(i.tiptva,0) = 2
          AND upper(n.simbauto) = &apos;RO&apos;
          AND NOT (i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;))
          AND (pSubunit = 1 OR i.subunitatea = pSubunit)
          AND Nvl(p.persoanafizica,0) &lt;&gt; 1
          AND t1.procent &lt;&gt; 0
      ) GROUP BY codies, tipdoc, partener, den_part, infocm, codfiscal
    )
    SELECT
      -Row_Number() OVER (ORDER BY codies), vCodD394, &apos;V&apos;,
      PKG_D394.ExtrageNr(CODFISCAL), DEN_PART,  BAZA, TVA, CASE WHEN pSursa IN (0,3) THEN decode(infocm,0,3,1) ELSE 3 END generat, Trim(CODFISCAL), codies, tipdoc, 1 NrFact
    FROM i;

    INSERT INTO TMP_D394VC (CodD394VC, CodD394V, DenProdus, CodNC, Baza, TVA)
    WITH x AS (
      SELECT
        0, t.CodD394V, TRIM(o.codd394) codd394,
        i1.cant * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, Nvl(i1.coefdiscmaj,1) , i1.valdiscpret)*Decode(i.curs,NULL,1,0,1,i.curs) BAZA,
        t1.procent / 100 coef_tva
      FROM TMP_D394V t
        INNER JOIN iesiri i ON i.codies = t.codsursa AND i.tipdoc = t.tipsursa
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        INNER JOIN nartobj o ON o.codobiect = Decode(i1.codobiectorig,NULL,i1.codobiect,0,i1.codobiect,i1.codobiectorig)
        INNER JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.luna+i.an BETWEEN a1.ALStart AND a1.ALStop
        INNER JOIN ntva1 t1 ON t1.codtva = a1.codtva        AND i.luna+i.an BETWEEN t1.ALStart AND t1.ALStop
      WHERE TRIM(o.codd394) IS NOT NULL
        AND t1.procent &lt;&gt; 0
    )
    SELECT 0, CodD394V, PKG_D394.DenCN(codd394), codd394, Sum(BAZA) BAZA, Sum(BAZA*COEF_TVA) TVA
    FROM x
    GROUP BY CodD394V, codd394;

    --DELETE TMP_D394VC WHERE DenProdus IS NULL;

  END IF;

  -- Trezorerie - livrari
  IF pSursa IN (1,3) THEN
    -- cand nu se completa t1.codpart
    INSERT INTO TMP_D394L (
      CodD394L, CodD394, TipOperatiune,
      CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, Obs, NrFact)
    SELECT
      0, vCodD394, &apos;L&apos;,
      PKG_D394.ExtrageNr( CASE WHEN INSTR(T1.OBS,&apos;/&apos;,1,2) = 0 THEN SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1) ELSE SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1,INSTR(T1.OBS,&apos;/&apos;,1,2)-INSTR(T1.OBS,&apos;/&apos;)-1) END ),
      SUBSTR(T1.OBS,1,INSTR(T1.OBS,&apos;/&apos;)-1),
      (T1.VALDOC - G.TVA) * Decode(g.curs,NULL,1,0,1,g.curs), G.TVA * Decode(g.curs,NULL,1,0,1,g.curs), 2,
      Trim(CASE WHEN INSTR(T1.OBS,&apos;/&apos;,1,2) = 0 THEN SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1) ELSE SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1,INSTR(T1.OBS,&apos;/&apos;,1,2)-INSTR(T1.OBS,&apos;/&apos;)-1) END),
      T1.DOC ||&apos; &apos;||T1.Nrdoc||&apos;/&apos;||T1.DATADOC, 1 NrFact
    FROM trezor t
      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
    WHERE t.tipdoc IN (29,33) AND t.operat = 1 AND t1.tiptranz = 1 AND t1.obiecttranz = 4
      AND t.an = pAn AND t.luna BETWEEN vLunaIni AND vLunaFin
      AND NVL(g.tva,0) &lt;&gt; 0
      AND t1.obs LIKE &apos;%/%&apos;
      AND (pSubunit = 1 OR t.subunitatea = pSubunit);

    -- cand se completeaza t1.codpart
    INSERT INTO TMP_D394L (
      CodD394L, CodD394, TipOperatiune, CISTVABFP, DenBFP,
      Baza, TVA, Generat, CFText, Obs, NrFact)
    SELECT
      0, vCodD394, &apos;L&apos;, PKG_D394.ExtrageNr(F.CODFISCAL), p.den_part,
      (T1.VALDOC - G.TVA) * Decode(g.curs,NULL,1,0,1,g.curs), G.TVA * Decode(g.curs,NULL,1,0,1,g.curs), 2, Trim(F.CODFISCAL), T1.DOC ||&apos; &apos;||T1.Nrdoc||&apos;/&apos;||T1.DATADOC, 1 NrFact
    FROM trezor t
      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
      INNER JOIN nagenda a ON a.codpart = t1.codpart AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0
      INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
			INNER JOIN ntari n ON n.codtara = l.codtara
      INNER JOIN npart p ON p.codpart = t1.codpart
      LEFT  JOIN npartcodfisc f ON f.codpart = t1.codpart AND f.principal = 1
    WHERE t.tipdoc IN (29,33) AND t.operat = 1 AND t1.tiptranz = 1 AND t1.obiecttranz = 4
      AND t.an = pAn AND t.luna BETWEEN vLunaIni AND vLunaFin
      AND NVL(g.tva,0) &lt;&gt; 0
      AND Nvl(p.persoanafizica,0) &lt;&gt; 1
      AND upper(n.simbauto) = &apos;RO&apos;
      AND (pSubunit = 1 OR t.subunitatea = pSubunit);
  END IF;

  -- Intrari
  IF pSursa IN (2,3) THEN
    INSERT INTO TMP_D394A (CodD394A, CodD394, TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, NrFact)
    WITH INTR AS (
      SELECT
        i.partener, p.den_part, COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal) codfiscal,
        SUM((CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END - Decode(I.TIPDOC,3,I1.TVA,0))* Decode(i.curs,NULL,1,0,1,i.curs)) BAZA,
        SUM(i1.tva * Decode(i.curs,NULL,1,0,1,i.curs)) TVA, Count(DISTINCT i.codintr) NrFact
      FROM intrari i
        INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
        INNER JOIN nagenda a ON a.codagenda = i.codlocatie
        INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
				INNER JOIN ntari n ON n.codtara = l.codtara
        INNER JOIN npart p ON p.codpart = i.partener
        LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
        LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
      WHERE (i.tipdoc IN (1,9) OR (i.tipdoc = 3 AND Nvl(i.factsimplif,0) = 1 AND i.valdoc &lt;= pkg_d394.LimitaBon(i.DataDoc)))
        AND i.operat = 1 AND i.anulat = 0
        AND i.datadoc BETWEEN vDataIni AND vDataFin
        AND i.an*12+i.luna &lt; 2016*12+7
        AND NVL(i.tiptva,0) &lt;&gt; 2
        AND upper(n.simbauto) = &apos;RO&apos;
        AND NOT ((i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;)) AND NVL(i1.contdiscount,0) = 0)
        AND NVL(i1.tva,0) &lt;&gt; 0
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND Nvl(p.persoanafizica,0) &lt;&gt; 1
      GROUP BY i.partener, p.den_part, cfd.codfiscal, a.codfiscal, cfi.codfiscal
    )
    SELECT 0, vCodD394, &apos;A&apos;, PKG_D394.ExtrageNr(CODFISCAL), DEN_PART, BAZA, TVA, 3, Trim(CODFISCAL), NrFact
    FROM intr;
  END IF;

  IF pSursa IN (2,3) AND pAn &gt;= 2012 THEN
    INSERT INTO TMP_D394C (
      CodD394C, CodD394, TipOperatiune,
      CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, CodSursa, TipSursa, NrFact)
    WITH INTR AS (
      SELECT
        i.codintr, i.tipdoc, i.partener, p.den_part, COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal) codfiscal,
        SUM((CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END - Decode(I.TIPDOC,3,I1.TVA,0)) * Decode(i.curs,NULL,1,0,1,i.curs)) BAZA,
        SUM(i1.tva * Decode(i.curs,NULL,1,0,1,i.curs)) TVA
      FROM intrari i
        INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
        INNER JOIN nagenda a ON a.codagenda = i.codlocatie
        INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
				INNER JOIN ntari n ON n.codtara = l.codtara
        INNER JOIN npart p ON p.codpart = i.partener
        LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
        LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
        LEFT JOIN nartobj o ON o.codobiect = Decode(i1.codobiectorig,NULL,i1.codobiect,0,i1.codobiect,i1.codobiectorig)
      WHERE (i.tipdoc IN (1,9) OR (i.tipdoc = 3 AND Nvl(i.factsimplif,0) = 1 AND i.valdoc &lt;= pkg_d394.LimitaBon(i.DataDoc)))
        AND i.operat = 1 AND i.anulat = 0
        AND i.datadoc BETWEEN vDataIni AND vDataFin
        AND i.an*12+i.luna &lt; 2016*12+7
        AND NVL(i.tiptva,0) = 2
        AND upper(n.simbauto) = &apos;RO&apos;
        AND NOT ((i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;)) AND NVL(i1.contdiscount,0) = 0)
        AND NVL(i1.tva,0) &lt;&gt; 0
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND Nvl(p.persoanafizica,0) &lt;&gt; 1
      GROUP BY i.codintr, i.tipdoc, i.partener, p.den_part, cfd.codfiscal, a.codfiscal, cfi.codfiscal
    )
    SELECT
      -Row_Number() OVER (ORDER BY codintr), vCodD394, &apos;C&apos;,
      PKG_D394.ExtrageNr(CODFISCAL), DEN_PART, BAZA, TVA, 3, Trim(CODFISCAL), codintr, tipdoc, 1 NrFact
    FROM intr;

    INSERT INTO TMP_D394CC (CodD394CC, CodD394C, DenProdus, CodNC, Baza, TVA)
    WITH x AS (
      SELECT
        t.CodD394C, TRIM(o.codd394) codd394,
        Decode(i.curs,NULL,1,0,1,i.curs) curs,
        (i1.cant * i1.pu) BAZA, i1.tva
      FROM TMP_D394C t
        INNER JOIN intrari i ON i.codintr = t.codsursa AND i.tipdoc = t.tipsursa
        INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
        INNER JOIN nartobj o ON o.codobiect = Decode(i1.codobiectorig,NULL,i1.codobiect,0,i1.codobiect,i1.codobiectorig)
      WHERE NVL(i1.tva,0) &lt;&gt; 0
        AND TRIM(o.codd394) IS NOT NULL
    )
    SELECT 0, CodD394C, PKG_D394.DenCN(codd394), codd394, Sum(baza * curs) BAZA, Sum(tva * curs) TVA
    FROM x
    GROUP BY CodD394C, codd394;

    --DELETE TMP_D394CC WHERE DenProdus IS NULL;
  END IF;

  -- Trezorerie - achizitii
  IF pSursa IN (1,3) THEN
    -- cand nu se completa t1.codpart
    INSERT INTO TMP_D394A (
      CodD394A, CodD394,
      TipOperatiune, CISTVABFP, DenBFP, Baza, TVA, Generat, CFText, Obs, NrFact)
    SELECT
      0, vCodD394, &apos;A&apos;,
      PKG_D394.ExtrageNr( CASE WHEN INSTR(T1.OBS,&apos;/&apos;,1,2) = 0 THEN SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1) ELSE SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1,INSTR(T1.OBS,&apos;/&apos;,1,2)-INSTR(T1.OBS,&apos;/&apos;)-1) END ),
      SUBSTR(T1.OBS,1,INSTR(T1.OBS,&apos;/&apos;)-1),
      (T1.VALDOC - G.TVA) * Decode(g.curs,NULL,1,0,1,g.curs), G.TVA * Decode(g.curs,NULL,1,0,1,g.curs), 2,
      Trim(CASE WHEN INSTR(T1.OBS,&apos;/&apos;,1,2) = 0 THEN SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1) ELSE SUBSTR(T1.OBS,INSTR(T1.OBS,&apos;/&apos;)+1,INSTR(T1.OBS,&apos;/&apos;,1,2)-INSTR(T1.OBS,&apos;/&apos;)-1) END),
      T1.DOC ||&apos; &apos;||T1.Nrdoc||&apos;/&apos;||T1.DATADOC, 1 NrFact
    FROM trezor t
      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
    WHERE t.tipdoc IN (29,33) AND t.operat = 1 AND t1.tiptranz = 0 AND t1.obiecttranz = 4
      AND t.an = pAn AND t.luna BETWEEN vLunaIni AND vLunaFin
      AND NVL(g.tva,0) &lt;&gt; 0
      AND Nvl(t1.codpart,0) = 0
      AND t1.obs LIKE &apos;%/%&apos;
      AND (pSubunit = 1 OR t.subunitatea = pSubunit);

    -- cand se completeaza t1.codpart
    INSERT INTO TMP_D394A (
      CodD394A, CodD394, TipOperatiune, CISTVABFP, DenBFP,
      Baza, TVA, Generat,
      CFText, Obs, NrFact)
    SELECT
      0, vCodD394, &apos;A&apos;, PKG_D394.ExtrageNr(F.CODFISCAL), p.den_part,
      (T1.VALDOC - G.TVA) * Decode(g.curs,NULL,1,0,1,g.curs), G.TVA * Decode(g.curs,NULL,1,0,1,g.curs), 2,
      Trim(F.CODFISCAL), T1.DOC ||&apos; &apos;||T1.Nrdoc||&apos;/&apos;||T1.DATADOC, 1 NrFact
    FROM trezor t
      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
      INNER JOIN nagenda a ON a.codpart = t1.codpart AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0
      INNER JOIN nlocalit l ON l.codlocalit = a.codlocalit
			INNER JOIN ntari n ON n.codtara = l.codtara
      INNER JOIN npart p ON p.codpart = t1.codpart
      LEFT  JOIN npartcodfisc f ON f.codpart = t1.codpart AND f.principal = 1
    WHERE t.tipdoc IN (29,33) AND t.operat = 1 AND t1.tiptranz = 0 AND t1.obiecttranz = 4
      AND t.an = pAn AND t.luna BETWEEN vLunaIni AND vLunaFin
      AND NVL(g.tva,0) &lt;&gt; 0
      AND Nvl(p.persoanafizica,0) &lt;&gt; 1
      AND upper(n.simbauto) = &apos;RO&apos;
      AND (pSubunit = 1 OR t.subunitatea = pSubunit);
  END IF;

  UPDATE TMP_D394A SET Ro = CASE WHEN Upper(SubStr(Trim(CFTEXT),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END;
  UPDATE TMP_D394L SET Ro = CASE WHEN Upper(SubStr(Trim(CFTEXT),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END;
  UPDATE TMP_D394C SET Ro = CASE WHEN Upper(SubStr(Trim(CFTEXT),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END;
  UPDATE TMP_D394V SET Ro = CASE WHEN Upper(SubStr(Trim(CFTEXT),1,2)) = &apos;RO&apos; THEN &apos;RO&apos; ELSE NULL END;
END;

PROCEDURE Centralizare IS
BEGIN
  -- Livrari
  UPDATE TMP_D394L SET TipOperatiune = &apos;X&apos; WHERE NVL(CISTVABFP,0) &lt;&gt; 0;

  INSERT INTO TMP_D394L (
    CodD394L, CodD394, TipOperatiune, CISTVABFP,
    DenBFP, Baza, TVA, Generat, CFText, NrFact, RO)
  SELECT
    MIN(CodD394L), MIN(CodD394), &apos;L&apos;, CISTVABFP,
    MAX(DenBFP), ROUND(SUM(Baza)), ROUND(SUM(Tva)), DECODE(COUNT(DISTINCT Generat),1,MIN(GENERAT)), MAX(CFTExt), Sum(Nvl(NrFact,0)), Max(RO)
  FROM TMP_D394L
  WHERE TipOperatiune = &apos;X&apos;
  GROUP BY CISTVABFP;

  DELETE TMP_D394L WHERE TipOperatiune = &apos;X&apos;;

  -- Achizitii
  UPDATE TMP_D394A SET TipOperatiune = &apos;X&apos; WHERE NVL(CISTVABFP,0) &lt;&gt; 0;

  INSERT INTO TMP_D394A (
    CodD394A, CodD394, TipOperatiune, CISTVABFP,
    DenBFP, Baza, TVA, Generat, CFText, NrFact, RO)
  SELECT
    MIN(CodD394A), MIN(CodD394), &apos;A&apos;, CISTVABFP,
    MIN(DenBFP), ROUND(SUM(Baza)), ROUND(SUM(Tva)), DECODE(COUNT(DISTINCT Generat),1,MIN(GENERAT)), MAX(CFTExt), Sum(Nvl(NrFact,0)), Max(RO)
  FROM TMP_D394A
  WHERE TipOperatiune = &apos;X&apos;
  GROUP BY CISTVABFP;

  DELETE TMP_D394A WHERE TipOperatiune = &apos;X&apos;;

  -- Livrari Taxare Inversa
  DELETE TMP_D394XC;

  INSERT INTO TMP_D394XC( CODD394XC, CODD394X, DENPRODUS, CODNC, BAZA, TVA, CODSURSA1, OBS, CISTVABFP)
  SELECT TC.CodD394VC, TC.CodD394V, TC.DENPRODUS, TC.CODNC, TC.BAZA, TC.TVA, TC.CODSURSA1, TC.OBS, T.CISTVABFP
  FROM TMP_D394VC TC
    INNER JOIN TMP_D394V T ON T.CODD394V = TC.CODD394V;

  UPDATE TMP_D394V SET TipOperatiune = &apos;X&apos; WHERE NVL(CISTVABFP,0) &lt;&gt; 0;

  INSERT INTO TMP_D394V (
    CodD394V, CodD394, TipOperatiune, CISTVABFP,
    DenBFP, Baza, TVA, Generat, CFText, NrFact, RO)
  SELECT
    MIN(CodD394V), MIN(CodD394), &apos;V&apos;, CISTVABFP,
    MAX(DenBFP), ROUND(SUM(Baza)), ROUND(SUM(Tva)), DECODE(COUNT(DISTINCT Generat),1,MIN(GENERAT)), MAX(CFTExt), Sum(Nvl(NrFact,0)), Max(RO)
  FROM TMP_D394V
  WHERE TipOperatiune = &apos;X&apos;
  GROUP BY CISTVABFP;

  DELETE TMP_D394V WHERE TipOperatiune = &apos;X&apos;;

  DELETE TMP_D394VC;

  INSERT INTO TMP_D394VC(
    CODD394VC,
    CODD394V,
    DENPRODUS, CODNC, BAZA, TVA)
  SELECT
    Min(TC.CodD394XC),
    (SELECT T.CodD394V FROM TMP_D394V T WHERE Nvl(T.CISTVABFP,&apos;#&apos;) = Nvl(TC.CISTVABFP,&apos;#&apos;)),
    TC.DENPRODUS, TC.CODNC, ROUND(SUM(TC.Baza)), ROUND(SUM(TC.Tva))
  FROM TMP_D394XC TC
  GROUP BY TC.CISTVABFP, TC.DENPRODUS, TC.CODNC;

  -- Achizitii Taxare Inversa
  DELETE TMP_D394XC;

  INSERT INTO TMP_D394XC( CODD394XC, CODD394X, DENPRODUS, CODNC, BAZA, TVA, CODSURSA1, OBS, CISTVABFP)
  SELECT TC.CodD394CC, TC.CodD394C, TC.DENPRODUS, TC.CODNC, TC.BAZA, TC.TVA, TC.CODSURSA1, TC.OBS, T.CISTVABFP
  FROM TMP_D394CC TC
    INNER JOIN TMP_D394C T ON T.CODD394C = TC.CODD394C;

  UPDATE TMP_D394C SET TipOperatiune = &apos;X&apos; WHERE NVL(CISTVABFP,0) &lt;&gt; 0;

  INSERT INTO TMP_D394C (
    CodD394C, CodD394, TipOperatiune, CISTVABFP,
    DenBFP, Baza, TVA, Generat, CFText, NrFact, RO)
  SELECT
    MIN(CodD394C), MIN(CodD394), &apos;C&apos;, CISTVABFP,
    MAX(DenBFP), ROUND(SUM(Baza)), ROUND(SUM(Tva)), DECODE(COUNT(DISTINCT Generat),1,MIN(GENERAT)), MAX(CFTExt), Sum(Nvl(NrFact,0)), Max(RO)
  FROM TMP_D394C
  WHERE TipOperatiune = &apos;X&apos;
  GROUP BY CISTVABFP;

  DELETE TMP_D394C WHERE TipOperatiune = &apos;X&apos;;

  DELETE TMP_D394CC;

  INSERT INTO TMP_D394CC(
    CODD394CC,
    CODD394C,
    DENPRODUS, CODNC, BAZA, TVA)
  SELECT
    Min(TC.CodD394XC),
    (SELECT T.CodD394C FROM TMP_D394C T WHERE Nvl(T.CISTVABFP,&apos;#&apos;) = Nvl(TC.CISTVABFP,&apos;#&apos;)),
    TC.DENPRODUS, TC.CODNC, ROUND(SUM(TC.Baza)), ROUND(SUM(TC.Tva))
  FROM TMP_D394XC TC
  GROUP BY TC.CISTVABFP, TC.DENPRODUS, TC.CODNC;
END;

FUNCTION DenCN (pCodCN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
  RETURN
    CASE REPLACE(pCodCN,&apos; &apos;)
      WHEN &apos;10011000&apos; THEN &apos;Grau dur&apos;
      WHEN &apos;10011100&apos; THEN &apos;Grau dur&apos; -- 25.X.2013
      WHEN &apos;10011900&apos; THEN &apos;Grau dur&apos; -- 25.X.2013

      WHEN &apos;10019010&apos; THEN &apos;Alac (Triticum spelta), destinat insamantarii&apos;
      WHEN &apos;10019110&apos; THEN &apos;Alac (Triticum spelta), destinat insamantarii&apos; -- 25.X.2013


      WHEN &apos;10019091&apos; THEN &apos;Grau comun destinat insamantarii&apos;
      WHEN &apos;10019120&apos; THEN &apos;Grau comun destinat insamantarii&apos; -- 25.X.2013

      WHEN &apos;10019099&apos; THEN &apos;Alt alac (Triticum spelta) si grau comun, nedestinate insamantarii&apos;
      WHEN &apos;10019900&apos; THEN &apos;Alt alac (Triticum spelta) si grau comun, nedestinate insamantarii&apos; -- 25.X.2013

      WHEN &apos;10020000&apos; THEN &apos;Secara&apos;
      WHEN     &apos;1002&apos; THEN &apos;Secara&apos; -- 25.X.2013


      WHEN   &apos;100300&apos; THEN &apos;Orz&apos;
      WHEN     &apos;1003&apos; THEN &apos;Orz&apos; -- 25.X.2013

      WHEN     &apos;1005&apos; THEN &apos;Porumb&apos;

      WHEN   &apos;120100&apos; THEN &apos;Boabe de soia, chiar sfaramate&apos;
      WHEN    &apos;12013&apos; THEN &apos;Boabe de soia, chiar sfaramate&apos; -- 25.X.2013

      WHEN     &apos;1205&apos; THEN &apos;Seminte de rapita sau de rapita salbatica, chiar sfaramate&apos;

      WHEN   &apos;120600&apos; THEN &apos;Seminte de floarea-soarelui, chiar sfaramate&apos;

      WHEN   &apos;121291&apos; THEN &apos;Sfecla de zahar&apos;

      ELSE NULL
    END;
END;

END PKG_D394;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_D39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64B204D69355740D28BB0BFDB907C5596D753825</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_D39416 IS

PROCEDURE UMPLE_REZ(pGenerare NUMBER) IS
BEGIN
  INSERT INTO TMP_D39416_REZ ( codd39416) SELECT codd39416 FROM TMP_D39416;

  UPDATE TMP_D39416_REZ
  SET (
          lf24, lb24, ltva24, af24, ab24, atva24, aif24, aib24, aitva24,
          lf21, lb21, ltva21, af21, ab21, atva21, aif21, aib21, aitva21,
          lf20, lb20, ltva20, af20, ab20, atva20, aif20, aib20, aitva20,
          lf19, lb19, ltva19, af19, ab19, atva19, aif19, aib19, aitva19,
          lf11, lb11, ltva11, af11, ab11, atva11, aif11, aib11, aitva11,
          lf9,  lb9,  ltva9,  af9,  ab9,  atva9,  aif9,  aib9,  aitva9,
          lf5,  lb5,  ltva5,  af5,  ab5,  atva5,  aif5,  aib5,  aitva5
      ) =
      ( SELECT
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib24,
          Sum(CASE WHEN PROCTVA = 24 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva24,

          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib21,
          Sum(CASE WHEN PROCTVA = 21 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva21,

          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib20,
          Sum(CASE WHEN PROCTVA = 20 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva20,

          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib19,
          Sum(CASE WHEN PROCTVA = 19 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva19,

          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib11,
          Sum(CASE WHEN PROCTVA = 11 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva11,

          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib9,
          Sum(CASE WHEN PROCTVA =  9 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva9,

          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 1      THEN f   ELSE 0 END) lf5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 1      THEN bi  ELSE 0 END) lb5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 1      THEN tva ELSE 0 END) ltva5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ IN (3,8) THEN f   ELSE 0 END) af5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ IN (3,8) THEN bi  ELSE 0 END) ab5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ IN (3,8) THEN tva ELSE 0 END) atva5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 4      THEN f   ELSE 0 END) aif5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 4      THEN bi  ELSE 0 END) aib5,
          Sum(CASE WHEN PROCTVA =  5 AND TIPTRANZ = 4      THEN tva ELSE 0 END) aitva5
        FROM (
          SELECT PROCTVA, TIPTRANZ, F, BI, TVA FROM  TMP_D39416RP WHERE ProcTVA &lt;&gt; 0 AND TipTranz IN (1, 3, 4, 8)
          UNION ALL
          SELECT PROCTVA, TIPTRANZ, F, BI, TVA FROM  TMP_D39416RN WHERE ProcTVA &lt;&gt; 0 AND TipTranz IN (1, 3, 4, 8)
          UNION ALL
          SELECT PROCTVA, TIPTRANZ, F, BI, TVA FROM  TMP_D39416UE WHERE ProcTVA &lt;&gt; 0 AND TipTranz IN (1, 3, 4, 8)
          UNION ALL
          SELECT PROCTVA, TIPTRANZ, F, BI, TVA FROM  TMP_D39416N  WHERE ProcTVA &lt;&gt; 0 AND TipTranz IN (1, 3, 4, 8)
        ) subs
      );

  UPDATE TMP_D39416_REZ
  SET ( incasari_ag, marja_ag, tva_ag ) =
      ( SELECT Sum (BI), Sum (Marja) + Sum (TVAMarja), Sum (TVAMarja)
        FROM (
          SELECT BI, Marja, TVAMarja FROM TMP_D39416RPS2 WHERE TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416RNS2 WHERE TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416UES2 WHERE TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416NS2  WHERE TipTranz = 2 AND RegScutire = 1
        ) subs
      );

  UPDATE TMP_D39416_REZ
  SET ( pret_vanzare, marja_antic, tva_antic ) =
      ( SELECT Sum (BI), Sum (Marja) + Sum (TVAMarja), Sum (TVAMarja)
        FROM (
          SELECT BI, Marja, TVAMarja FROM TMP_D39416RPS2 WHERE TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416RNS2 WHERE TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416UES2 WHERE TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM TMP_D39416NS2  WHERE TipTranz = 2 AND RegScutire = 2
        ) subs
      );

  UPDATE TMP_D39416_REZ
  SET costuri_ag     = incasari_ag  - marja_ag,
      pret_cumparare = pret_vanzare - marja_antic;

  UPDATE TMP_D39416_REZ
  SET ( G_BF, G_VAL_10, G_VAL_11)
      =
      ( SELECT
          Coalesce(Sum(CASE WHEN TipTranz = 10 THEN BF      ELSE 0 END),0),
          Coalesce(Sum(CASE WHEN TipTranz = 10 THEN VALOARE ELSE 0 END),0),
          Coalesce(Sum(CASE WHEN TipTranz = 11 THEN VALOARE ELSE 0 END),0)
        FROM TMP_D39416G
      );

  IF pGenerare = 1 THEN
    UPDATE TMP_D39416_REZ
    SET
      RPno        = ( SELECT Count (DISTINCT CUI) FROM TMP_D39416RPS2),
      RNno        = ( SELECT Count(1)             FROM TMP_D39416RNS2),
      UEno        = ( SELECT Count (DISTINCT CUI) FROM TMP_D39416UES2),
      NonUEno     = ( SELECT Count (DISTINCT CUI) FROM TMP_D39416NS2),
      SumaControl = ( SELECT Coalesce(Sum(LivrariB + AchizB + AchizIB),0) FROM TMP_D39416R  )+
                    ( SELECT Coalesce(Sum(BI),0) FROM TMP_D39416RN WHERE TipTranz = 1)+ --Livrari Neplatitori TVA
                    ( SELECT Coalesce(Sum(BI),0) FROM TMP_D39416UE WHERE TipTranz = 1)+ --Livrari UE
                    ( SELECT Coalesce(Sum(BI),0) FROM TMP_D39416UE WHERE TipTranz = 8)+ --Achizitii UE
                    ( SELECT Coalesce(Sum(BI),0) FROM TMP_D39416N  WHERE TipTranz = 1)+ --Livrari NonUE
                    ( SELECT Coalesce(Sum(BI),0) FROM TMP_D39416N  WHERE TipTranz = 8); --Achizitii NonUE

    UPDATE TMP_D39416_REZ
    SET OpEfectuate = CASE
                        WHEN RPno = 0 AND RNno = 0 AND UEno = 0 AND NonUEno = 0
                         AND NOT EXISTS (SELECT 1 FROM TMP_D39416RN0 WHERE Coalesce(L_PF_F,0) &lt;&gt; 0 OR Coalesce(LS_PF_F,0) &lt;&gt; 0)
                         AND NOT EXISTS (SELECT 1 FROM TMP_D39416G1  WHERE TipTranz IN (10, 11) )
                         AND NOT EXISTS (SELECT 1 FROM TMP_D39416I1 )
                        THEN 0
                        ELSE 1
                      END,
        SumaControl = SumaControl + RPno + RNno + UEno + NonUEno;

    UPDATE TMP_D39416_REZ
    SET PrsAfiliat = CASE WHEN EXISTS (SELECT 1 FROM TMP_D39416_GEN WHERE Coalesce(PERSAFILIATA, 0) = 1) THEN 1 ELSE 0 END;
  END IF;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I1R&apos;;
  INSERT INTO TMP_D39416I1R (
    CODD39416,
    BAZAFSLCOD24, TVAFSLCOD24,
    BAZAFSLCOD21, TVAFSLCOD21,
    BAZAFSLCOD20, TVAFSLCOD20,
    BAZAFSLCOD19, TVAFSLCOD19,
    BAZAFSLCOD11, TVAFSLCOD11,
    BAZAFSLCOD09, TVAFSLCOD09,
    BAZAFSLCOD05, TVAFSLCOD05,

    BAZAFSL24, TVAFSL24,
    BAZAFSL21, TVAFSL21,
    BAZAFSL20, TVAFSL20,
    BAZAFSL19, TVAFSL19,
    BAZAFSL11, TVAFSL11,
    BAZAFSL09, TVAFSL09,
    BAZAFSL05, TVAFSL05,

    BAZAFSA24, TVAFSA24,
    BAZAFSA21, TVAFSA21,
    BAZAFSA20, TVAFSA20,
    BAZAFSA19, TVAFSA19,
    BAZAFSA11, TVAFSA11,
    BAZAFSA09, TVAFSA09,
    BAZAFSA05, TVAFSA05,

    BAZAFSAI24, TVAFSAI24,
    BAZAFSAI21, TVAFSAI21,
    BAZAFSAI20, TVAFSAI20,
    BAZAFSAI19, TVAFSAI19,
    BAZAFSAI11, TVAFSAI11,
    BAZAFSAI09, TVAFSAI09,
    BAZAFSAI05, TVAFSAI05,

    BAZABFAI24, TVABFAI24,
    BAZABFAI21, TVABFAI21,
    BAZABFAI20, TVABFAI20,
    BAZABFAI19, TVABFAI19,
    BAZABFAI11, TVABFAI11,
    BAZABFAI09, TVABFAI09,
    BAZABFAI05, TVABFAI05,

    TVADED24,
    TVADED21,
    TVADED20,
    TVADED19,
    TVADED11,
    TVADED09,
    TVADED05,

    TVADEDI24,
    TVADEDI21,
    TVADEDI20,
    TVADEDI19,
    TVADEDI11,
    TVADEDI09,
    TVADEDI05,

    TVACOL24,
    TVACOL21,
    TVACOL20,
    TVACOL19,
    TVACOL11,
    TVACOL09,
    TVACOL05
    )
  SELECT
    codd39416,
    Sum(CASE WHEN PROCTVA = 24 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD24, Sum(CASE WHEN PROCTVA = 24 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD24,
    Sum(CASE WHEN PROCTVA = 21 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD21, Sum(CASE WHEN PROCTVA = 21 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD21,
    Sum(CASE WHEN PROCTVA = 20 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD20, Sum(CASE WHEN PROCTVA = 20 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD20,
    Sum(CASE WHEN PROCTVA = 19 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD19, Sum(CASE WHEN PROCTVA = 19 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD19,
    Sum(CASE WHEN PROCTVA = 11 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD11, Sum(CASE WHEN PROCTVA = 11 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD11,
    Sum(CASE WHEN PROCTVA = 09 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD09, Sum(CASE WHEN PROCTVA = 09 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD09,
    Sum(CASE WHEN PROCTVA = 05 THEN BAZAFSLCOD ELSE 0 END) BAZAFSLCOD05, Sum(CASE WHEN PROCTVA = 05 THEN TVAFSLCOD ELSE 0 END) TVAFSLCOD05,

    Sum(CASE WHEN PROCTVA = 24 THEN BAZAFSL    ELSE 0 END) BAZAFSL24,    Sum(CASE WHEN PROCTVA = 24 THEN TVAFSL    ELSE 0 END) TVAFSL24,
    Sum(CASE WHEN PROCTVA = 21 THEN BAZAFSL    ELSE 0 END) BAZAFSL21,    Sum(CASE WHEN PROCTVA = 21 THEN TVAFSL    ELSE 0 END) TVAFSL21,
    Sum(CASE WHEN PROCTVA = 20 THEN BAZAFSL    ELSE 0 END) BAZAFSL20,    Sum(CASE WHEN PROCTVA = 20 THEN TVAFSL    ELSE 0 END) TVAFSL20,
    Sum(CASE WHEN PROCTVA = 19 THEN BAZAFSL    ELSE 0 END) BAZAFSL19,    Sum(CASE WHEN PROCTVA = 19 THEN TVAFSL    ELSE 0 END) TVAFSL19,
    Sum(CASE WHEN PROCTVA = 11 THEN BAZAFSL    ELSE 0 END) BAZAFSL11,    Sum(CASE WHEN PROCTVA = 11 THEN TVAFSL    ELSE 0 END) TVAFSL11,
    Sum(CASE WHEN PROCTVA = 09 THEN BAZAFSL    ELSE 0 END) BAZAFSL09,    Sum(CASE WHEN PROCTVA = 09 THEN TVAFSL    ELSE 0 END) TVAFSL09,
    Sum(CASE WHEN PROCTVA = 05 THEN BAZAFSL    ELSE 0 END) BAZAFSL05,    Sum(CASE WHEN PROCTVA = 05 THEN TVAFSL    ELSE 0 END) TVAFSL05,

    Sum(CASE WHEN PROCTVA = 24 THEN BAZAFSA    ELSE 0 END) BAZAFSA24,    Sum(CASE WHEN PROCTVA = 24 THEN TVAFSA    ELSE 0 END) TVAFSA24,
    Sum(CASE WHEN PROCTVA = 21 THEN BAZAFSA    ELSE 0 END) BAZAFSA21,    Sum(CASE WHEN PROCTVA = 21 THEN TVAFSA    ELSE 0 END) TVAFSA21,
    Sum(CASE WHEN PROCTVA = 20 THEN BAZAFSA    ELSE 0 END) BAZAFSA20,    Sum(CASE WHEN PROCTVA = 20 THEN TVAFSA    ELSE 0 END) TVAFSA20,
    Sum(CASE WHEN PROCTVA = 19 THEN BAZAFSA    ELSE 0 END) BAZAFSA19,    Sum(CASE WHEN PROCTVA = 19 THEN TVAFSA    ELSE 0 END) TVAFSA19,
    Sum(CASE WHEN PROCTVA = 11 THEN BAZAFSA    ELSE 0 END) BAZAFSA11,    Sum(CASE WHEN PROCTVA = 11 THEN TVAFSA    ELSE 0 END) TVAFSA11,
    Sum(CASE WHEN PROCTVA = 09 THEN BAZAFSA    ELSE 0 END) BAZAFSA09,    Sum(CASE WHEN PROCTVA = 09 THEN TVAFSA    ELSE 0 END) TVAFSA09,
    Sum(CASE WHEN PROCTVA = 05 THEN BAZAFSA    ELSE 0 END) BAZAFSA05,    Sum(CASE WHEN PROCTVA = 05 THEN TVAFSA    ELSE 0 END) TVAFSA05,

    Sum(CASE WHEN PROCTVA = 24 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI24,   Sum(CASE WHEN PROCTVA = 24 THEN TVAFSAI   ELSE 0 END) TVAFSAI24,
    Sum(CASE WHEN PROCTVA = 21 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI21,   Sum(CASE WHEN PROCTVA = 21 THEN TVAFSAI   ELSE 0 END) TVAFSAI21,
    Sum(CASE WHEN PROCTVA = 20 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI20,   Sum(CASE WHEN PROCTVA = 20 THEN TVAFSAI   ELSE 0 END) TVAFSAI20,
    Sum(CASE WHEN PROCTVA = 19 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI19,   Sum(CASE WHEN PROCTVA = 19 THEN TVAFSAI   ELSE 0 END) TVAFSAI19,
    Sum(CASE WHEN PROCTVA = 11 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI11,   Sum(CASE WHEN PROCTVA = 11 THEN TVAFSAI   ELSE 0 END) TVAFSAI11,
    Sum(CASE WHEN PROCTVA = 09 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI09,   Sum(CASE WHEN PROCTVA = 09 THEN TVAFSAI   ELSE 0 END) TVAFSAI09,
    Sum(CASE WHEN PROCTVA = 05 THEN BAZAFSAI   ELSE 0 END) BAZAFSAI05,   Sum(CASE WHEN PROCTVA = 05 THEN TVAFSAI   ELSE 0 END) TVAFSAI05,

    Sum(CASE WHEN PROCTVA = 24 THEN BAZABFAI   ELSE 0 END) BAZABFAI24,   Sum(CASE WHEN PROCTVA = 24 THEN TVABFAI   ELSE 0 END) TVABFAI24,
    Sum(CASE WHEN PROCTVA = 21 THEN BAZABFAI   ELSE 0 END) BAZABFAI21,   Sum(CASE WHEN PROCTVA = 21 THEN TVABFAI   ELSE 0 END) TVABFAI21,
    Sum(CASE WHEN PROCTVA = 20 THEN BAZABFAI   ELSE 0 END) BAZABFAI20,   Sum(CASE WHEN PROCTVA = 20 THEN TVABFAI   ELSE 0 END) TVABFAI20,
    Sum(CASE WHEN PROCTVA = 19 THEN BAZABFAI   ELSE 0 END) BAZABFAI19,   Sum(CASE WHEN PROCTVA = 19 THEN TVABFAI   ELSE 0 END) TVABFAI19,
    Sum(CASE WHEN PROCTVA = 11 THEN BAZABFAI   ELSE 0 END) BAZABFAI11,   Sum(CASE WHEN PROCTVA = 11 THEN TVABFAI   ELSE 0 END) TVABFAI11,
    Sum(CASE WHEN PROCTVA = 09 THEN BAZABFAI   ELSE 0 END) BAZABFAI09,   Sum(CASE WHEN PROCTVA = 09 THEN TVABFAI   ELSE 0 END) TVABFAI09,
    Sum(CASE WHEN PROCTVA = 05 THEN BAZABFAI   ELSE 0 END) BAZABFAI05,   Sum(CASE WHEN PROCTVA = 05 THEN TVABFAI   ELSE 0 END) TVABFAI05,

    Sum(CASE WHEN PROCTVA = 24 THEN TVADED     ELSE 0 END) TVADED24,
    Sum(CASE WHEN PROCTVA = 21 THEN TVADED     ELSE 0 END) TVADED21,
    Sum(CASE WHEN PROCTVA = 20 THEN TVADED     ELSE 0 END) TVADED20,
    Sum(CASE WHEN PROCTVA = 19 THEN TVADED     ELSE 0 END) TVADED19,
    Sum(CASE WHEN PROCTVA = 11 THEN TVADED     ELSE 0 END) TVADED11,
    Sum(CASE WHEN PROCTVA = 09 THEN TVADED     ELSE 0 END) TVADED09,
    Sum(CASE WHEN PROCTVA = 05 THEN TVADED     ELSE 0 END) TVADED05,

    Sum(CASE WHEN PROCTVA = 24 THEN TVADEDI    ELSE 0 END) TVADEDI24,
    Sum(CASE WHEN PROCTVA = 21 THEN TVADEDI    ELSE 0 END) TVADEDI21,
    Sum(CASE WHEN PROCTVA = 20 THEN TVADEDI    ELSE 0 END) TVADEDI20,
    Sum(CASE WHEN PROCTVA = 19 THEN TVADEDI    ELSE 0 END) TVADEDI19,
    Sum(CASE WHEN PROCTVA = 11 THEN TVADEDI    ELSE 0 END) TVADEDI11,
    Sum(CASE WHEN PROCTVA = 09 THEN TVADEDI    ELSE 0 END) TVADEDI09,
    Sum(CASE WHEN PROCTVA = 05 THEN TVADEDI    ELSE 0 END) TVADEDI05,

    Sum(CASE WHEN PROCTVA = 24 THEN TVACOL     ELSE 0 END) TVACOL24,
    Sum(CASE WHEN PROCTVA = 21 THEN TVACOL     ELSE 0 END) TVACOL21,
    Sum(CASE WHEN PROCTVA = 20 THEN TVACOL     ELSE 0 END) TVACOL20,
    Sum(CASE WHEN PROCTVA = 19 THEN TVACOL     ELSE 0 END) TVACOL19,
    Sum(CASE WHEN PROCTVA = 11 THEN TVACOL     ELSE 0 END) TVACOL11,
    Sum(CASE WHEN PROCTVA = 09 THEN TVACOL     ELSE 0 END) TVACOL09,
    Sum(CASE WHEN PROCTVA = 05 THEN TVACOL     ELSE 0 END) TVACOL05
  FROM TMP_D39416I1
  GROUP BY codd39416;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I4C&apos;;

  INSERT INTO TMP_D39416I4C
  SELECT DISTINCT CODD39416, CAEN FROM TMP_D39416I4;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODD39416 INTO Tmp FROM D39416 WHERE CodD39416 = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);

  DELETE FROM d39416ns2  WHERE CodD39416  = RecId ;
  DELETE FROM d39416n    WHERE CodD39416  = RecId ;

  DELETE FROM d39416ues2 WHERE CodD39416  = RecId ;
  DELETE FROM d39416ue   WHERE CodD39416  = RecId ;

  DELETE FROM d39416i4   WHERE CodD39416  = RecId ;
  DELETE FROM d39416i3   WHERE CodD39416  = RecId ;
  DELETE FROM d39416i2   WHERE CodD39416  = RecId ;
  DELETE FROM d39416i2a  WHERE CodD39416  = RecId ;
  DELETE FROM d39416i1   WHERE CodD39416  = RecId ;
  DELETE FROM d39416i    WHERE CodD39416  = RecId ;

  DELETE FROM d39416g3   WHERE CodD39416  = RecId ;
  DELETE FROM d39416g2   WHERE CodD39416  = RecId ;
  DELETE FROM d39416g1   WHERE CodD39416  = RecId ;
  DELETE FROM d39416g    WHERE CodD39416  = RecId ;

  DELETE FROM d39416rns3 WHERE CodD39416  = RecId ;
  DELETE FROM d39416rns2 WHERE CodD39416  = RecId ;
  DELETE FROM d39416rn1  WHERE CodD39416  = RecId ;
  DELETE FROM d39416rn0  WHERE CodD39416  = RecId ;
  DELETE FROM d39416rn   WHERE CodD39416  = RecId ;

  DELETE FROM d39416rps3 WHERE CodD39416  = RecId ;
  DELETE FROM d39416rps2 WHERE CodD39416  = RecId ;
  DELETE FROM d39416rp1  WHERE CodD39416  = RecId ;
  DELETE FROM d39416rp   WHERE CodD39416  = RecId ;

  DELETE FROM d39416r    WHERE CodD39416  = RecId ;

  DELETE FROM d39416     WHERE CodD39416  = RecId ;

  NotifyModif(2, RecId, &apos;D39416&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_D39416 FIELDS( CodD39416 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master D39416
  INSERT INTO TMP_D39416 (
    codd39416, subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
    adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
    nerezident, prsafiliat, editmanual)
  SELECT
    codd39416, subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
    adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
    Coalesce(nerezident, 0), Coalesce(prsafiliat, 0), Coalesce(editmanual, 0)
  FROM D39416
  WHERE CodD39416 = RecId;

  -- Detail d39416r
  INSERT INTO TMP_D39416R (
    codd39416r, codd39416, proctva, livrarif, livrarib,
    livraritva, achizf, achizb, achiztva, achizif, achizib,
    achizitva)
  SELECT
    codd39416r, codd39416, proctva, livrarif, livrarib,
    livraritva, achizf, achizb, achiztva, achizif, achizib,
    achizitva
  FROM D39416R
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416RP (codd39416rp, codd39416, tiptranz, proctva, f, bi, tva)
  SELECT codd39416rp, codd39416, tiptranz, proctva, f, bi, tva
  FROM D39416RP
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416RP1 (codd39416rp1, codd39416, tiptranz, proctva, categtxinv, f, bi, tva)
  SELECT codd39416rp1, codd39416, tiptranz, proctva, categtxinv, f, bi, tva
  FROM D39416RP1
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416RPS2 (codd39416rps2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja, cuivalid)
  SELECT codd39416rps2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja, COALESCE(cuivalid,  cif_valid(cui))
  FROM D39416RPS2
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416RPS3 (codd39416rps3, codd39416, tiptranz, proctva, cui, categtxinv, codd394, f, bi, tva)
  SELECT codd39416rps3, codd39416, tiptranz, proctva, cui, categtxinv, codd394, f, bi, tva
  FROM D39416RPS3
  WHERE CodD39416 = RecId;

  -- Detail D39416RN
  INSERT INTO  TMP_D39416RN (codd39416rn, codd39416, tiptranz, proctva, tipdoc, f, bi, tva)
  SELECT codd39416rn, codd39416, tiptranz, proctva, tipdoc, f, bi, tva
  FROM D39416RN
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416RN0 (
    codd39416rn0, codd39416, l_pf_f,
    l_pf_bi24, l_pf_tva24, l_pf_bi21, l_pf_tva21, l_pf_bi20, l_pf_tva20, l_pf_bi19, l_pf_bi11, l_pf_tva11, l_pf_tva19, l_pf_bi9, l_pf_tva9, l_pf_bi5, l_pf_tva5,
    ls_pf_f, ls_pf_val)
  SELECT
    codd39416rn0, codd39416, l_pf_f,
    l_pf_bi24, l_pf_tva24, l_pf_bi21, l_pf_tva21, l_pf_bi20, l_pf_tva20, l_pf_bi19, l_pf_bi11, l_pf_tva11, l_pf_tva19, l_pf_bi9, l_pf_tva9, l_pf_bi5, l_pf_tva5,
    ls_pf_f, ls_pf_val
  FROM D39416RN0
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416RN1 (codd39416rn1, codd39416, tiptranz, proctva, tipdoc, categtxinv, f, valoare)
  SELECT codd39416rn1, codd39416, tiptranz, proctva, tipdoc, categtxinv, f, valoare
  FROM D39416RN1
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416RNS2 (
    codd39416rns2, codd39416, tiptranz, regscutire, proctva, cui, denp, codlocalit,
    strp, nrp, blp, app, tipdoc, f, bi, marja, tva, tvamarja, detp, cuivalid,
    locp, judp, tarap, sajudp)
  SELECT
    d2.codd39416rns2, d2.codd39416, d2.tiptranz, d2.regscutire, d2.proctva, d2.cui, d2.denp, d2.codlocalit,
    d2.strp, d2.nrp, d2.blp, d2.app, d2.tipdoc, d2.f, d2.bi, d2.marja, d2.tva, d2.tvamarja, d2.detp, d2.cuivalid,
    Coalesce(d2.locp, l.den_localit), Coalesce(d2.judp, To_Char(j.js,&apos;fm900&apos;)), Coalesce(d2.tarap, t.simbauto), Coalesce(d2.judp, j.simbauto)
  FROM D39416RNS2 D2
    LEFT JOIN nlocalit l ON l.codlocalit = d2.codlocalit
    LEFT JOIN njudet j ON j.codjudet = l.codjudet
    LEFT JOIN ntari t ON t.codtara = l.codtara
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416RNS3 (
    codd39416rns3, codd39416, codd39416rn1, codd39416rns2, f, valoare, codd394, tiptranz, tipdoc, categtxinv)
  SELECT
    d3.codd39416rns3, d3.codd39416, d3.codd39416rn1, d3.codd39416rns2, d3.f, d3.valoare, d3.codd394, d1.tiptranz, d1.tipdoc, d1.categtxinv
  FROM D39416RNS3 d3
    INNER JOIN D39416RN1 d1 ON d1.codd39416rn1 = d3.codd39416rn1
  WHERE d3.CodD39416 = RecId;

  -- Detail D39416UE
  INSERT INTO TMP_D39416UE (codd39416ue, codd39416, tiptranz, proctva, f, bi, tva)
  SELECT codd39416ue, codd39416, tiptranz, proctva, f, bi, tva
  FROM D39416UE
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416UES2 (codd39416ues2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja)
  SELECT codd39416ues2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja
  FROM D39416UES2
  WHERE CodD39416 = RecId;

  -- Detail D39416N
  INSERT INTO TMP_D39416N (codd39416n, codd39416, tiptranz, proctva, f, bi, tva)
  SELECT codd39416n, codd39416, tiptranz, proctva, f, bi, tva
  FROM D39416N
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416NS2 (codd39416ns2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja)
  SELECT codd39416ns2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja
  FROM D39416NS2
  WHERE CodD39416 = RecId;

  -- Detail D39416G
  INSERT INTO  TMP_D39416G (codd39416g, codd39416, tiptranz, bf, valoare)
  SELECT codd39416g, codd39416, tiptranz, bf, valoare
  FROM D39416G
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416G1 (codd39416g1, codd39416, tiptranz, proctva, bi, tva)
  SELECT codd39416g1, codd39416, tiptranz, proctva, bi, tva
  FROM D39416G1
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416G2 (codd39416g2, codd39416, tiptranz, luna, nramef, bf, valoare)
  SELECT codd39416g2, codd39416, tiptranz, luna, nramef, bf, valoare
  FROM D39416G2
  WHERE CodD39416 = RecId;

  INSERT INTO  TMP_D39416G3 (codd39416g3, codd39416, tiptranz, luna, proctva, bi, tva)
  SELECT codd39416g3, codd39416, tiptranz, luna, proctva, bi, tva
  FROM D39416G3
  WHERE CodD39416 = RecId;

  -- Detail D39416I
  INSERT INTO TMP_D39416I (
    codd39416i, codd39416,
    totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
    achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
    achizs24,   achizs21,   achizs20,   achizs19,   achizs11,   achizs9,   achizs5, importb, acinecorp, livraribi,
    livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
    prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
    livrariue, prestue, export, livinecorp, efectuat
  )
  SELECT
    codd39416i, codd39416,
    totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
    achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
    achizs24,   achizs21,   achizs20,   achizs19,   achizs21,   achizs9,   achizs5, importb, acinecorp, livraribi,
    livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
    prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
    livrariue, prestue, export, livinecorp, efectuat
  FROM D39416I
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416I1 (codd39416i1, codd39416, proctva, bazafslcod, tvafslcod, bazafsl, tvafsl, bazafsa, tvafsa, bazafsai, tvafsai, bazabfai, tvabfai, tvaded, tvadedi, tvacol)
  SELECT codd39416i1, codd39416, proctva, bazafslcod, tvafslcod, bazafsl, tvafsl, bazafsa, tvafsa, bazafsai, tvafsai, bazabfai, tvabfai, tvaded, tvadedi, tvacol
  FROM D39416I1
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416I2 (codd39416i2, codd39416, indexlocal, serie, startnr, endnr, numarf)
  SELECT codd39416i2, codd39416, indexlocal, serie, startnr, endnr, numarf
  FROM D39416I2
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416I2A (codd39416i2a, codd39416, indexlocal, serie, startnr, endnr, numarf)
  SELECT codd39416i2a, codd39416, indexlocal, serie, startnr, endnr, numarf
  FROM D39416I2A
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416I3 (codd39416i3, codd39416, tipfactura, serief, numarf, cui, denp, proctva, bi, tva)
  SELECT codd39416i3, codd39416, tipfactura, serief, numarf, cui, denp, proctva, bi, tva
  FROM D39416I3
  WHERE CodD39416 = RecId;

  INSERT INTO TMP_D39416I4 (codd39416i4, codd39416, caen, tipoper, proctva, valoare, tva)
  SELECT codd39416i4, codd39416, caen, tipoper, proctva, valoare, tva
  FROM D39416I4
  WHERE CodD39416 = RecId;

  UMPLE_REZ(0);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vEditManual NUMBER;
BEGIN
  DELETE FROM tmp_d39416rn1_aux;
  INSERT INTO tmp_d39416rn1_aux  SELECT seq_d39416rn1_codd39416rn1.NEXTVAL,   codd39416rn1  FROM tmp_d39416rn1  WHERE codd39416rn1  &lt; 0;
  DELETE FROM tmp_d39416rns2_aux;
  INSERT INTO tmp_d39416rns2_aux SELECT seq_d39416rns2_codd39416rns2.NEXTVAL, codd39416rns2 FROM tmp_d39416rns2 WHERE codd39416rns2 &lt; 0;
  DELETE FROM TMP_D39416I2A WHERE Nullif(Trim(SERIE),&apos;&apos;) IS NULL AND Coalesce(STARTNR,0) = 0 AND Coalesce(ENDNR,0) = 0;
  UPDATE TMP_D39416I2A SET NUMARF = ENDNR + 1 - STARTNR WHERE Coalesce(NUMARF,0) = 0 AND Coalesce(STARTNR,0) &lt;&gt; 0 AND Coalesce(ENDNR,0) &lt;&gt; 0;

  SELECT Coalesce(editmanual, 0)
  INTO vEditManual
  FROM TMP_D39416;

  IF vEditManual = 1 THEN -- editare manual Sectiunile G si I (verificare coerenta date)
    -- Tabele Sectiunea G
    UPDATE TMP_D39416G3 SET BI = Round(Coalesce(BI,0)), TVA = Round(Coalesce(TVA,0));

    DELETE FROM TMP_D39416G3     WHERE COALESCE(BI,0) = 0 AND COALESCE(TVA, 0) = 0;
    DELETE FROM TMP_D39416G2 TG2 WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G3 TG3 WHERE TG3.TIPTRANZ = TG2.TIPTRANZ AND TG3.LUNA = TG2.LUNA) AND Coalesce(NRAMEF, 0) = 0 AND Coalesce(BF, 0) = 0;
    DELETE FROM TMP_D39416G1 TG1 WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G3 TG3 WHERE TG3.TIPTRANZ = TG1.TIPTRANZ AND TG3.PROCTVA = TG1.PROCTVA);

    UPDATE TMP_D39416G2 TG2 SET (VALOARE) = (SELECT Coalesce(Sum(TG3.BI+TG3.TVA),0)                   FROM TMP_D39416G3 TG3 WHERE TG3.TIPTRANZ = TG2.TIPTRANZ AND TG3.LUNA = TG2.LUNA);
    UPDATE TMP_D39416G1 TG1 SET (BI, TVA) = (SELECT Coalesce(Sum(TG3.BI),0), Coalesce(Sum(TG3.TVA),0) FROM TMP_D39416G3 TG3 WHERE TG3.TIPTRANZ = TG1.TIPTRANZ AND TG3.PROCTVA = TG1.PROCTVA);

    INSERT INTO TMP_D39416G2
    SELECT 0, 0, TIPTRANZ, LUNA, 0, 0, Sum(TG3.BI+TG3.TVA)
    FROM TMP_D39416G3 TG3
    WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G2 xTG WHERE TG3.TIPTRANZ = xTG.TIPTRANZ AND TG3.LUNA = xTG.LUNA)
    GROUP BY TIPTRANZ, LUNA;

    INSERT INTO TMP_D39416G1
    SELECT 0, 0, TIPTRANZ, PROCTVA, Sum(TG3.BI), Sum(TG3.TVA)
    FROM TMP_D39416G3 TG3
    WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G1 xTG WHERE TG3.TIPTRANZ = xTG.TIPTRANZ AND TG3.PROCTVA = xTG.PROCTVA)
    GROUP BY TIPTRANZ, PROCTVA;

    DELETE FROM TMP_D39416G TG WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G TG2 WHERE TG2.TIPTRANZ = TG.TIPTRANZ);
    UPDATE TMP_D39416G TG SET (BF, VALOARE) = (SELECT Coalesce(Sum(TG2.BF),0), Coalesce(Sum(TG2.VALOARE),0) FROM TMP_D39416G2 TG2 WHERE TG2.TIPTRANZ = TG.TIPTRANZ);

    INSERT INTO TMP_D39416G
    SELECT 0, 0, TIPTRANZ, Sum(TG2.BF), Sum(TG2.VALOARE)
    FROM TMP_D39416G2 TG2
    WHERE NOT EXISTS (SELECT 1 FROM TMP_D39416G xTG WHERE TG2.TIPTRANZ = xTG.TIPTRANZ)
    GROUP BY TIPTRANZ;

    -- Tabele Sectiunea I
  END IF;

  IF Operation = 0 THEN  -- UPDATE
    -- Master D39416
    SELECT  CodD39416 INTO RecId FROM TMP_D39416;

    UPDATE D39416
    SET  (subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
          adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
          nerezident, prsafiliat, editmanual)
      =(SELECT
          subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
          adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
          nerezident, prsafiliat, editmanual
        FROM TMP_D39416 )
    WHERE CodD39416 = RecId ;

    -- Detail D39416R
    DELETE FROM D39416R WHERE CodD39416 = RecID AND CodD39416r NOT IN (SELECT CodD39416r FROM TMP_D39416R WHERE CodD39416r &gt; 0);

    UPDATE D39416R d
    SET(       proctva,   livrarif,   livrarib,   livraritva,   achizf,   achizb,   achiztva,   achizif,   achizib,   achizitva) =
       (SELECT t.proctva, t.livrarif, t.livrarib, t.livraritva, t.achizf, t.achizb, t.achiztva, t.achizif, t.achizib, t.achizitva FROM TMP_D39416R T WHERE T.CodD39416 = RecID AND T.CodD39416r = D.CodD39416r)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416R (codd39416r,       codd39416, proctva,   livrarif,   livrarib,   livraritva,   achizf,   achizb,   achiztva,   achizif,   achizib,   achizitva)
    SELECT seq_d39416r_codd39416r.nextval, RecId,     t.proctva, t.livrarif, t.livrarib, t.livraritva, t.achizf, t.achizb, t.achiztva, t.achizif, t.achizib, t.achizitva
    FROM TMP_D39416R T
    WHERE T.CodD39416r &lt;= 0;

    DELETE FROM D39416RP WHERE CodD39416 = RecID AND CodD39416rp NOT IN (SELECT CodD39416rp FROM TMP_D39416RP WHERE CodD39416rp &gt; 0);

    UPDATE D39416RP d
    SET(       tiptranz,   proctva,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.f, t.bi, t.tva FROM TMP_D39416RP T WHERE T.CodD39416rp = D.CodD39416rp)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RP (codd39416rp,       codd39416, tiptranz,   proctva,   f,   bi,   tva)
    SELECT seq_d39416rp_codd39416rp.nextval, RecId,     t.tiptranz, t.proctva, t.f, t.bi, t.tva
    FROM TMP_D39416RP T
    WHERE T.CodD39416rp &lt;= 0;

    DELETE FROM D39416RP1 WHERE CodD39416 = RecID AND CodD39416rp1 NOT IN (SELECT CodD39416rp1 FROM TMP_D39416RP1 WHERE CodD39416rp1 &gt; 0);

    UPDATE D39416RP1 d
    SET(       tiptranz,   proctva,   categtxinv,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.categtxinv, t.f, t.bi, t.tva FROM TMP_D39416RP1 T WHERE T.CodD39416rp1 = D.CodD39416rp1)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RP1 (codd39416rp1,       codd39416, tiptranz,   proctva,   categtxinv,   f,   bi,   tva)
    SELECT seq_d39416rp1_codd39416rp1.nextval, RecId,     t.tiptranz, t.proctva, t.categtxinv, t.f, t.bi, t.tva
    FROM TMP_D39416RP1 T
    WHERE T.CodD39416rp1 &lt;= 0;

    DELETE FROM D39416RPS2 WHERE CodD39416 = RecID AND CodD39416rps2 NOT IN (SELECT CodD39416rps2 FROM TMP_D39416RPS2 WHERE CodD39416rps2 &gt; 0);

    UPDATE D39416RPS2 d
    SET(       tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja,   cuivalid) =
       (SELECT t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja, t.cuivalid FROM TMP_D39416RPS2 T WHERE T.CodD39416rps2 = D.CodD39416rps2)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RPS2 (codd39416rps2,       codd39416, tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja,   cuivalid)
    SELECT seq_d39416rps2_codd39416rps2.nextval, RecId,     t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja, t.cuivalid
    FROM TMP_D39416RPS2 T
    WHERE T.CodD39416rps2 &lt;= 0;

    DELETE FROM D39416RPS3 WHERE CodD39416 = RecID AND CodD39416rps3 NOT IN (SELECT CodD39416rps3 FROM TMP_D39416RPS3 WHERE CodD39416rps3 &gt; 0);

    UPDATE D39416RPS3 d
    SET(       tiptranz,   proctva,   cui,   categtxinv,   codd394,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.cui, t.categtxinv, t.codd394, t.f, t.bi, t.tva FROM TMP_D39416RPS3 T WHERE T.CodD39416rps3 = D.CodD39416rps3)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RPS3 (CodD39416rps3,       codd39416, tiptranz,   proctva,   cui,   categtxinv,   codd394,   f,   bi,   tva)
    SELECT seq_d39416rps3_codd39416rps3.nextval, RecId,     t.tiptranz, t.proctva, t.cui, t.categtxinv, t.codd394, t.f, t.bi, t.tva
    FROM TMP_D39416RPS3 T
    WHERE T.CodD39416rps3 &lt;= 0;

    -- Detail D39416RN
    DELETE FROM D39416RN WHERE CodD39416 = RecID AND CodD39416RN NOT IN (SELECT CodD39416rn FROM TMP_D39416RN WHERE CodD39416RN &gt; 0);

    UPDATE D39416RN d
    SET(       tiptranz,   proctva,   tipdoc,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.tipdoc, t.f, t.bi, t.tva FROM TMP_D39416RN T WHERE T.CodD39416RN = D.CodD39416RN)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RN (CodD39416RN,       codd39416, tiptranz,   proctva,   tipdoc,   f,   bi,   tva)
    SELECT seq_d39416rn_codd39416rn.nextval, RecId,     t.tiptranz, t.proctva, t.tipdoc, t.f, t.bi, t.tva
    FROM TMP_D39416RN T
    WHERE T.CodD39416RN &lt;= 0;

    DELETE FROM D39416RN0 WHERE CodD39416 = RecID AND CodD39416rn0 NOT IN (SELECT CodD39416rn0 FROM TMP_D39416RN0 WHERE CodD39416rn0 &gt; 0);

    UPDATE D39416RN0 d
    SET(  l_pf_f,
          l_pf_bi24,   l_pf_tva24,   l_pf_bi21,   l_pf_tva21,   l_pf_bi20,   l_pf_tva20,   l_pf_bi19,   l_pf_tva19,   l_pf_bi11,   l_pf_tva11,   l_pf_bi9,   l_pf_tva9,   l_pf_bi5,   l_pf_tva5,
          ls_pf_f, ls_pf_val) =
       (SELECT
          t.l_pf_f,
          t.l_pf_bi24, t.l_pf_tva24, t.l_pf_bi21, t.l_pf_tva21, t.l_pf_bi20, t.l_pf_tva20, t.l_pf_bi19, t.l_pf_tva19, t.l_pf_bi11, t.l_pf_tva11, t.l_pf_bi9, t.l_pf_tva9, t.l_pf_bi5, t.l_pf_tva5,
          t.ls_pf_f, t.ls_pf_val
        FROM TMP_D39416RN0 T WHERE T.CodD39416rn0 = D.CodD39416rn0)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RN0 (
      CodD39416rn0, codd39416, l_pf_f,
      l_pf_bi24,   l_pf_tva24,   l_pf_bi21,   l_pf_tva21,   l_pf_bi20,   l_pf_tva20,   l_pf_bi19,   l_pf_tva19,   l_pf_bi9,   l_pf_tva11,   l_pf_bi11,   l_pf_tva9,   l_pf_bi5,   l_pf_tva5,
      ls_pf_f,   ls_pf_val)
    SELECT
      seq_d39416rn0_codd39416rn0.nextval, RecId, t.l_pf_f,
      t.l_pf_bi24, t.l_pf_tva24, t.l_pf_bi21, t.l_pf_tva21, t.l_pf_bi20, t.l_pf_tva20, t.l_pf_bi19, t.l_pf_tva19, t.l_pf_bi9, t.l_pf_tva11, t.l_pf_bi11, t.l_pf_tva9, t.l_pf_bi5, t.l_pf_tva5,
      t.ls_pf_f, t.ls_pf_val
    FROM TMP_D39416RN0 T
    WHERE T.CodD39416rn0 &lt;= 0;

    DELETE FROM D39416RN1 WHERE CodD39416 = RecID AND CodD39416rn1 NOT IN (SELECT CodD39416rn1 FROM TMP_D39416RN1 WHERE CodD39416rn1 &gt; 0);

    UPDATE D39416RN1 d
    SET(       tiptranz,   proctva,   tipdoc,   categtxinv,   f,   valoare) =
       (SELECT t.tiptranz, t.proctva, t.tipdoc, t.categtxinv, t.f, t.valoare FROM TMP_D39416RN1 T WHERE t.codd39416rn1 = d.CodD39416rn1)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RN1 (CodD39416rn1,   codd39416, tiptranz,   proctva,   tipdoc,   categtxinv,   f,   valoare)
    SELECT                 a.codd39416rn1, RecId,     t.tiptranz, t.proctva, t.tipdoc, t.categtxinv, t.f, t.valoare
    FROM TMP_D39416RN1_AUX A LEFT JOIN TMP_D39416RN1 T ON t.codd39416rn1 = a.oldcod;

    DELETE FROM D39416RNS2 WHERE CodD39416 = RecID AND CodD39416rns2 NOT IN (SELECT CodD39416rns2 FROM TMP_D39416RNS2 WHERE CodD39416rns2 &gt; 0);

    UPDATE D39416RNS2 d
    SET(        tiptranz,   regscutire,   proctva,   cui,   denp,   codlocalit,   strp,   nrp,   blp,   app,    tipdoc,   f,   bi,   marja,  tva,   tvamarja,   detp,   cuivalid,   locp,   judp,   tarap,   sajudp) =
       ( SELECT t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.codlocalit, t.strp, t.nrp, t.blp, t.app, t.tipdoc, t.f, t.bi, t.marja, t.tva, t.tvamarja, t.detp, t.cuivalid, t.locp, t.judp, t.tarap, t.sajudp
         FROM TMP_D39416RNS2 T
         WHERE T.codd39416rns2 = D.codd39416rns2
       )
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RNS2 (CodD39416rns2,  codd39416, tiptranz,   regscutire,   proctva,   cui,   denp,   codlocalit,   strp,   nrp,   blp,   app,    tipdoc,   f,   bi,   marja,  tva,   tvamarja,   detp,   cuivalid,   locp,   judp,   tarap,   sajudp)
    SELECT                 a.codd39416rns2, RecId,     t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.codlocalit, t.strp, t.nrp, t.blp, t.app, t.tipdoc, t.f, t.bi, t.marja, t.tva, t.tvamarja, t.detp, t.cuivalid, t.locp, t.judp, t.tarap, t.sajudp
    FROM TMP_D39416RNS2_AUX A LEFT JOIN TMP_D39416RNS2 T ON t.codd39416rns2 = a.oldcod;

    DELETE FROM D39416RNS3 WHERE CodD39416 = RecID AND CodD39416rns3 NOT IN (SELECT CodD39416rns3 FROM TMP_D39416RNS3 WHERE CodD39416rns3 &gt; 0);

    UPDATE D39416RNS3 d
    SET(        codd39416rn1,                              codd39416rns2,                               f,   valoare,   codd394) =
       ( SELECT Coalesce(a1.codd39416rn1, t.codd39416rn1), Coalesce(a2.codd39416rns2, t.codd39416rns2), t.f, t.valoare, t.codd394
         FROM TMP_D39416RNS3 T
           LEFT JOIN TMP_D39416RN1_AUX  A1 ON a1.oldcod = t.codd39416rn1
           LEFT JOIN TMP_D39416RNS2_AUX A2 ON a2.oldcod = t.codd39416rns2
         WHERE t.CodD39416rns3 = d.CodD39416rns3
       )
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416RNS3 (CodD39416rns3,       codd39416, codd39416rn1,                              codd39416rns2,                               f,   valoare,   codd394)
    SELECT seq_d39416rns3_codd39416rns3.nextval, RecId,     Coalesce(a1.codd39416rn1, t.codd39416rn1), Coalesce(a2.codd39416rns2, t.codd39416rns2), t.f, t.valoare, t.codd394
    FROM TMP_D39416RNS3 T
      LEFT JOIN TMP_D39416RN1_AUX  A1 ON a1.oldcod = t.codd39416rn1
      LEFT JOIN TMP_D39416RNS2_AUX A2 ON a2.oldcod = t.codd39416rns2
    WHERE T.CodD39416rns3 &lt;= 0;

    -- Detail D39416UE
    DELETE FROM D39416UE WHERE CodD39416 = RecID AND CodD39416ue NOT IN (SELECT CodD39416ue FROM TMP_D39416UE WHERE CodD39416ue &gt; 0);

    UPDATE D39416UE d
    SET(       tiptranz,   proctva,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.f, t.bi, t.tva FROM TMP_D39416UE T WHERE T.CodD39416ue = D.CodD39416ue)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416UE (CodD39416ue,       codd39416, tiptranz,   proctva,   f,   bi,   tva)
    SELECT seq_d39416ue_codd39416ue.nextval, RecId,     t.tiptranz, t.proctva, t.f, t.bi, t.tva
    FROM TMP_D39416UE T
    WHERE T.CodD39416ue &lt;= 0;

    DELETE FROM D39416UES2 WHERE CodD39416 = RecID AND CodD39416ues2 NOT IN (SELECT CodD39416ues2 FROM TMP_D39416UES2 WHERE CodD39416ues2 &gt; 0);

    UPDATE D39416UES2 d
    SET(       tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja) =
       (SELECT t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja FROM TMP_D39416UES2 T WHERE T.CodD39416ues2 = D.CodD39416ues2)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416UES2 (CodD39416ues2,       codd39416, tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja)
    SELECT seq_d39416ues2_codd39416ues2.nextval, RecId,     t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja
    FROM TMP_D39416UES2 T
    WHERE T.CodD39416ues2 &lt;= 0;

    -- Detail D39416N
    DELETE FROM D39416N WHERE CodD39416 = RecID AND CodD39416n NOT IN (SELECT CodD39416n FROM TMP_D39416N WHERE CodD39416n &gt; 0);

    UPDATE D39416N d
    SET(       tiptranz,   proctva,   f,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.f, t.bi, t.tva FROM TMP_D39416N T WHERE T.CodD39416 = RecID AND T.CodD39416n = D.CodD39416n)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416N (CodD39416n,       codd39416, tiptranz,   proctva,   f,   bi,   tva)
    SELECT seq_d39416n_codd39416n.nextval, RecId,     t.tiptranz, t.proctva, t.f, t.bi, t.tva
    FROM TMP_D39416N T
    WHERE T.CodD39416n &lt;= 0;

    DELETE FROM D39416NS2 WHERE CodD39416 = RecID AND CodD39416ns2 NOT IN (SELECT CodD39416ns2 FROM TMP_D39416NS2 WHERE CodD39416ns2 &gt; 0);

    UPDATE D39416NS2 d
    SET(       tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja) =
       (SELECT t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja FROM TMP_D39416NS2 T WHERE T.CodD39416ns2 = D.CodD39416ns2)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416NS2 (CodD39416ns2,       codd39416, tiptranz,   regscutire,   proctva,   cui,   denp,   f,   bi,   marja,   tva,   tvamarja)
    SELECT seq_d39416ns2_codd39416ns2.nextval, RecId,     t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp, t.f, t.bi, t.marja, t.tva, t.tvamarja
    FROM TMP_D39416NS2 T
    WHERE T.CodD39416ns2 &lt;= 0;

    -- Detail D39416G
    DELETE FROM D39416G WHERE CodD39416 = RecID AND CodD39416G NOT IN (SELECT CodD39416G FROM TMP_D39416G WHERE CodD39416G &gt; 0);

    UPDATE D39416G d
    SET(       tiptranz,   bf,   valoare) =
       (SELECT t.tiptranz, t.bf, t.valoare FROM TMP_D39416G T WHERE T.CodD39416 = RecID AND T.CodD39416G = D.CodD39416G)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416G (CodD39416G,       codd39416, tiptranz,   bf,   valoare)
    SELECT seq_d39416g_codd39416g.nextval, RecId,     t.tiptranz, t.bf, t.valoare
    FROM TMP_D39416G T
    WHERE T.CodD39416G &lt;= 0;

    DELETE FROM D39416G1 WHERE CodD39416 = RecID AND CodD39416G1 NOT IN (SELECT CodD39416G1 FROM TMP_D39416G1 WHERE CodD39416G1 &gt; 0);

    UPDATE D39416G1 d
    SET(       tiptranz,   proctva,   bi,   tva) =
       (SELECT t.tiptranz, t.proctva, t.bi, t.tva FROM TMP_D39416G1 T WHERE T.CodD39416G1 = D.CodD39416G1)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416G1 (CodD39416G1,       codd39416, tiptranz,   proctva,   bi,   tva)
    SELECT seq_d39416g1_codd39416g1.nextval, RecId,     t.tiptranz, t.proctva, t.bi, t.tva
    FROM TMP_D39416G1 T
    WHERE T.CodD39416G1 &lt;= 0;

    DELETE FROM D39416G2 WHERE CodD39416 = RecID AND CodD39416G2 NOT IN (SELECT CodD39416G2 FROM TMP_D39416G2 WHERE CodD39416G2 &gt; 0);

    UPDATE D39416G2 d
    SET(       tiptranz,   luna,   nramef,   bf,   valoare) =
       (SELECT t.tiptranz, t.luna, t.nramef, t.bf, t.valoare FROM TMP_D39416G2 T WHERE T.CodD39416G2 = D.CodD39416G2)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416G2 (CodD39416G2,       codd39416, tiptranz,   luna,   nramef,   bf,   valoare)
    SELECT seq_d39416g2_codd39416g2.nextval, RecId,     t.tiptranz, t.luna, t.nramef, t.bf, t.valoare
    FROM TMP_D39416G2 T
    WHERE T.CodD39416G2 &lt;= 0;

    DELETE FROM D39416G3 WHERE CodD39416 = RecID AND CodD39416G3 NOT IN (SELECT CodD39416G3 FROM TMP_D39416G3 WHERE CodD39416G3 &gt; 0);

    UPDATE D39416G3 d
    SET(       tiptranz,   luna,   proctva,   bi,   tva) =
       (SELECT t.tiptranz, t.luna, t.proctva, t.bi, t.tva FROM TMP_D39416G3 T WHERE T.CodD39416G3 = D.CodD39416G3)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416G3 (CodD39416G3,       codd39416, tiptranz,   luna,   proctva,   bi,   tva)
    SELECT seq_d39416g3_codd39416g3.nextval, RecId,     t.tiptranz, t.luna, t.proctva, t.bi, t.tva
    FROM TMP_D39416G3 T
    WHERE T.CodD39416G3 &lt;= 0;

    -- Detail D39416I
    DELETE FROM D39416I WHERE CodD39416 = RecID AND CodD39416I NOT IN (SELECT CodD39416I FROM TMP_D39416I WHERE CodD39416I &gt; 0);

    UPDATE D39416I d
    SET (
            totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
            achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
            achizs24,   achizs21,   achizs20,   achizs19,   achizs11,   achizs9,   achizs5, importb, acinecorp, livraribi,
            livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
            prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
            livrariue, prestue, export, livinecorp, efectuat
       ) =
       (
          SELECT
            t.totalfact, t.totalfactben, t.totalfactterti, t.solicit, t.achizpe, t.achizcr, t.achizcb, t.achizci, t.achiza,
            t.achizb24,   t.achizb21,   t.achizb20,   t.achizb19,   t.achizb11,   t.achizb9,   t.achizb5,
            t.achizs24,   t.achizs21,   t.achizs20,   t.achizs19,   t.achizs11,   t.achizs9,   t.achizs5, t.importb, t.acinecorp, t.livraribi,
            t.livrarib24, t.livrarib21, t.livrarib20, t.livrarib19, t.livrarib11, t.livrarib9, t.livrarib5, t.livrarib0, t.livrariti,
            t.prest24,    t.prest21,    t.prest20,    t.prest19,    t.prest11,    t.prest9,    t.prest5,    t.prest0,
            t.livrariue, t.prestue, t.export, t.livinecorp, t.efectuat
          FROM TMP_D39416I T
          WHERE T.CodD39416I = D.CodD39416I
       )
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I (
      codd39416i, codd39416,
      totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
      achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
      achizs24,   achizs21,   achizs20,   achizs19,   achizs11,   achizs9,   achizs5, importb, acinecorp, livraribi,
      livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
      prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
      livrariue, prestue, export, livinecorp, efectuat
    )
    SELECT
      seq_d39416i_codd39416i.NEXTVAL, RecId,
      t.totalfact, t.totalfactben, t.totalfactterti, t.solicit, t.achizpe, t.achizcr, t.achizcb, t.achizci, t.achiza,
      t.achizb24,   t.achizb21,   t.achizb20,   t.achizb19,   t.achizb11,   t.achizb9,   t.achizb5,
      t.achizs24,   t.achizs21,   t.achizs20,   t.achizs19,   t.achizs11,   t.achizs9,   t.achizs5, t.importb, t.acinecorp, t.livraribi,
      t.livrarib24, t.livrarib21, t.livrarib20, t.livrarib19, t.livrarib11, t.livrarib9, t.livrarib5, t.livrarib0, t.livrariti,
      t.prest24,    t.prest21,    t.prest20,    t.prest19,    t.prest11,    t.prest9,    t.prest5,    t.prest0,
      t.livrariue, t.prestue, t.export, t.livinecorp, t.efectuat
    FROM TMP_D39416I T
    WHERE T.CodD39416I &lt;= 0;

    DELETE FROM D39416I1 WHERE CodD39416 = RecID AND CodD39416I1 NOT IN (SELECT CodD39416I1 FROM TMP_D39416I1 WHERE CodD39416I1 &gt; 0);

    UPDATE D39416I1 d
    SET(       proctva,   bazafslcod,   tvafslcod,   bazafsl,   tvafsl,   bazafsa,   tvafsa,   bazafsai,   tvafsai,   bazabfai,   tvabfai,   tvaded,   tvadedi,   tvacol) =
       (SELECT t.proctva, t.bazafslcod, t.tvafslcod, t.bazafsl, t.tvafsl, t.bazafsa, t.tvafsa, t.bazafsai, t.tvafsai, t.bazabfai, t.tvabfai, t.tvaded, t.tvadedi, t.tvacol FROM TMP_D39416I1 T WHERE T.CodD39416I1 = D.CodD39416I1)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I1 (CodD39416I1,       codd39416, proctva,   bazafslcod,   tvafslcod,   bazafsl,   tvafsl,   bazafsa,   tvafsa,   bazafsai,   tvafsai,   bazabfai,   tvabfai,   tvaded,   tvadedi,   tvacol)
    SELECT seq_d39416i1_codd39416i1.nextval, RecId,     t.proctva, t.bazafslcod, t.tvafslcod, t.bazafsl, t.tvafsl, t.bazafsa, t.tvafsa, t.bazafsai, t.tvafsai, t.bazabfai, t.tvabfai, t.tvaded, t.tvadedi, t.tvacol
    FROM TMP_D39416I1 T
    WHERE T.CodD39416I1 &lt;= 0;

    DELETE FROM D39416I2A WHERE CodD39416 = RecID AND CodD39416I2A NOT IN (SELECT CodD39416I2A FROM TMP_D39416I2A WHERE CodD39416I2A &gt; 0);

    UPDATE D39416I2A d
    SET(       indexlocal,   serie,   startnr,   endnr,   numarf) =
       (SELECT t.indexlocal, t.serie, t.startnr, t.endnr, t.numarf FROM TMP_D39416I2A T WHERE T.CodD39416I2A = D.CodD39416I2A)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I2A (CodD39416I2A,       codd39416, indexlocal,   serie,   startnr,   endnr,   numarf)
    SELECT seq_d39416i2a_codd39416i2a.nextval, RecId,     t.indexlocal, t.serie, t.startnr, t.endnr, t.numarf
    FROM TMP_D39416I2A T
    WHERE T.CodD39416I2A &lt;= 0;

    DELETE FROM D39416I2 WHERE CodD39416 = RecID AND CodD39416I2 NOT IN (SELECT CodD39416I2 FROM TMP_D39416I2 WHERE CodD39416I2 &gt; 0);

    UPDATE D39416I2 d
    SET(       indexlocal,   serie,   startnr,   endnr,   numarf) =
       (SELECT t.indexlocal, t.serie, t.startnr, t.endnr, t.numarf FROM TMP_D39416I2 T WHERE T.CodD39416I2 = D.CodD39416I2)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I2 (CodD39416I2,       codd39416, indexlocal,   serie,   startnr,   endnr,   numarf)
    SELECT seq_d39416i2_codd39416i2.nextval, RecId,     t.indexlocal, t.serie, t.startnr, t.endnr, t.numarf
    FROM TMP_D39416I2 T
    WHERE T.CodD39416I2 &lt;= 0;

    DELETE FROM D39416I3 WHERE CodD39416 = RecID AND CodD39416I3 NOT IN (SELECT CodD39416I3 FROM TMP_D39416I3 WHERE CodD39416I3 &gt; 0);

    UPDATE D39416I3 d
    SET(       tipfactura,   serief,   numarf,   cui,   denp,   proctva,   bi,   tva) =
       (SELECT t.tipfactura, t.serief, t.numarf, t.cui, t.denp, t.proctva, t.bi, t.tva FROM TMP_D39416I3 T WHERE T.CodD39416I3 = D.CodD39416I3)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I3 (CodD39416I3,       codd39416, tipfactura,   serief,   numarf,   cui,   denp,   proctva,   bi,   tva)
    SELECT seq_d39416i3_codd39416i3.nextval, RecId,     t.tipfactura, t.serief, t.numarf, t.cui, t.denp, t.proctva, t.bi, t.tva
    FROM TMP_D39416I3 T
    WHERE T.CodD39416I3 &lt;= 0;

    DELETE FROM D39416I4 WHERE CodD39416 = RecID AND CodD39416I4 NOT IN (SELECT CodD39416I4 FROM TMP_D39416I4 WHERE CodD39416I4 &gt; 0);

    UPDATE D39416I4 d
    SET(       caen,   tipoper,   proctva,   valoare,   tva) =
       (SELECT t.caen, t.tipoper, t.proctva, t.valoare, t.tva FROM TMP_D39416I4 T WHERE T.CodD39416I4 = D.CodD39416I4)
    WHERE D.CodD39416 = RecID;

    INSERT INTO D39416I4 (CodD39416I4,       codd39416, caen,   tipoper,   proctva,   valoare,   tva)
    SELECT seq_d39416i4_codd39416i4.nextval, RecId,     t.caen, t.tipoper, t.proctva, t.valoare, t.tva
    FROM TMP_D39416I4 T
    WHERE T.CodD39416I4 &lt;= 0;
  ELSE  -- INSERT
    -- Master D39416
    RecId := seq_d39416_codd39416.NEXTVAL;

    INSERT INTO D39416 (
      codd39416, subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
      adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
      nerezident, prsafiliat, editmanual)
    SELECT
      RecId, subunitatea, lunad, an, tipd, tipi, deni, codi, functiei, calitatei, cui, den, caen, adresa, telefon, fax, email, cifr, denr, calitater,
      adresar, telefonr, faxr, emailr, tvaincas, opefectuate, acordaccesp, acordaccesc, sumacontrol, rpno, rnno, ueno, nonueno, opefcfgen, dataxmlvalid, obs,
      nerezident, prsafiliat, editmanual
    FROM TMP_D39416;

    -- Detail D39416R
    INSERT INTO D39416R (codd39416r, codd39416, proctva, livrarif, livrarib, livraritva, achizf, achizb, achiztva, achizif, achizib, achizitva)
    SELECT seq_d39416r_codd39416r.NEXTVAL, RecId, td.proctva, td.livrarif, td.livrarib, td.livraritva, td.achizf, td.achizb, td.achiztva, td.achizif, td.achizib, td.achizitva
    FROM TMP_D39416R TD;

    INSERT INTO D39416RP (codd39416rp, codd39416, tiptranz, proctva, f, bi, tva)
    SELECT seq_d39416rp_codd39416rp.NEXTVAL, RecId, td.tiptranz, td.proctva, td.f, td.bi, td.tva
    FROM TMP_D39416RP TD;

    INSERT INTO D39416RP1 (codd39416rp1, codd39416, tiptranz, proctva, categtxinv, f, bi, tva)
    SELECT seq_d39416rp1_codd39416rp1.NEXTVAL, RecId, td.tiptranz, td.proctva, td.categtxinv, td.f, td.bi, td.tva
    FROM TMP_D39416RP1 TD;

    INSERT INTO D39416RPS2(codd39416rps2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja, cuivalid)
    SELECT seq_d39416rps2_codd39416rps2.NEXTVAL, RecID, td.tiptranz, td.regscutire, td.proctva, td.cui, td.denp, td.f, td.bi, td.marja, td.tva, td.tvamarja, td.cuivalid
    FROM TMP_D39416RPS2 TD;

    INSERT INTO D39416RPS3 (codd39416rps3, codd39416, tiptranz, proctva, cui, categtxinv, codd394, f, bi, tva)
    SELECT seq_d39416rps3_codd39416rps3.NEXTVAL, RecID, td.tiptranz, td.proctva, td.cui, td.categtxinv, td.codd394, td.f, td.bi, td.tva
    FROM TMP_D39416RPS3 TD;

    -- Detail D39416RN
    INSERT INTO D39416RN (codd39416rn, codd39416, tiptranz, proctva, tipdoc, f, bi, tva)
    SELECT seq_d39416rn_codd39416rn.NEXTVAL, RecId, tiptranz, proctva, tipdoc, f, bi, tva
    FROM TMP_D39416RN;

    INSERT INTO D39416RN0 (
      codd39416rn0, codd39416, l_pf_f,
      l_pf_bi24, l_pf_tva24, l_pf_bi21, l_pf_tva21, l_pf_bi20, l_pf_tva20, l_pf_bi19, l_pf_tva19, l_pf_bi11, l_pf_tva11, l_pf_bi9, l_pf_tva9, l_pf_bi5, l_pf_tva5,
      ls_pf_f, ls_pf_val )
    SELECT
      seq_d39416rn0_codd39416rn0.NEXTVAL, RecId, l_pf_f,
      l_pf_bi24, l_pf_tva24, l_pf_bi21, l_pf_tva21, l_pf_bi20, l_pf_tva20, l_pf_bi19, l_pf_tva19, l_pf_bi11, l_pf_tva11, l_pf_bi9, l_pf_tva9, l_pf_bi5, l_pf_tva5,
      ls_pf_f, ls_pf_val
    FROM TMP_D39416RN0;

    INSERT INTO D39416RN1 (codd39416rn1, codd39416, tiptranz, proctva, tipdoc, categtxinv, f, valoare)
    SELECT Coalesce(a.codd39416rn1, td.codd39416rn1), RecId, td.tiptranz, td.proctva, td.tipdoc, td.categtxinv, td.f, td.valoare
    FROM TMP_D39416RN1 TD LEFT JOIN TMP_D39416RN1_AUX A ON a.oldcod = td.codd39416rn1;

    INSERT INTO D39416RNS2 (
      codd39416rns2, codd39416,
      tiptranz, regscutire, proctva, cui, denp, codlocalit, strp, nrp, blp, app,  tipdoc, f, bi, marja, tva, tvamarja, detp, cuivalid,
      locp, judp, tarap, sajudp)
    SELECT
      Coalesce(a.codd39416rns2, td.codd39416rns2), RecId,
      td.tiptranz, td.regscutire, td.proctva, td.cui, td.denp, td.codlocalit, td.strp, td.nrp, td.blp, td.app, td.tipdoc, td.f, td.bi, td.marja, td.tva, td.tvamarja, td.detp, td.cuivalid,
      td.locp, td.judp, td.tarap, td.sajudp
    FROM TMP_D39416RNS2 TD LEFT JOIN TMP_D39416RNS2_AUX A ON a.oldcod = td.codd39416rns2;

    INSERT INTO D39416RNS3 (codd39416rns3, codd39416, codd39416rn1, codd39416rns2, f, valoare, codd394)
    SELECT seq_d39416rns3_codd39416rns3.NEXTVAL, RecId, Coalesce(a1.codd39416rn1,td.codd39416rn1), Coalesce(a2.codd39416rns2,td.codd39416rns2), td.f, td.valoare, td.codd394
    FROM TMP_D39416RNS3 TD
      LEFT JOIN TMP_D39416RN1_AUX  A1 ON a1.oldcod = td.codd39416rn1
      LEFT JOIN TMP_D39416RNS2_AUX A2 ON a2.oldcod = td.codd39416rns2;

    -- Detail D39416UE
    INSERT INTO D39416UE (codd39416ue, codd39416, tiptranz, proctva, f, bi, tva)
    SELECT seq_d39416ue_codd39416ue.NEXTVAL, RecId, td.tiptranz, td.proctva, td.f, td.bi, td.tva
    FROM TMP_D39416UE TD;

    INSERT INTO D39416UES2 (codd39416ues2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja)
    SELECT seq_d39416ues2_codd39416ues2.NEXTVAL, RecId, td.tiptranz, td.regscutire, td.proctva, td.cui, td.denp, td.f, td.bi, td.marja, td.tva, td.tvamarja
    FROM TMP_D39416UES2 TD;

    -- Detail D39416N
    INSERT INTO D39416N (codd39416n, codd39416, tiptranz, proctva, f, bi, tva)
    SELECT seq_d39416n_codd39416n.NEXTVAL, RecId, td.tiptranz, td.proctva, td.f, td.bi, td.tva
    FROM TMP_D39416N TD;

    INSERT INTO D39416NS2 (codd39416ns2, codd39416, tiptranz, regscutire, proctva, cui, denp, f, bi, marja, tva, tvamarja)
    SELECT seq_d39416ns2_codd39416ns2.NEXTVAL, RecId, td.tiptranz, td.regscutire, td.proctva, td.cui, td.denp, td.f, td.bi, td.marja, td.tva, td.tvamarja
    FROM TMP_D39416NS2 TD;

    -- Detail D39416G
    INSERT INTO D39416G (codd39416g, codd39416, tiptranz, bf, valoare)
    SELECT seq_d39416g_codd39416g.NEXTVAL, RecId, td.tiptranz, td.bf, td.valoare
    FROM TMP_D39416G TD;

    INSERT INTO D39416G1 (codd39416g1, codd39416, tiptranz, proctva, bi, tva)
    SELECT seq_d39416g1_codd39416g1.NEXTVAL, RecId, td.tiptranz, td.proctva, td.bi, td.tva
    FROM TMP_D39416G1 TD;

    INSERT INTO D39416G2 (codd39416g2, codd39416, tiptranz, luna, nramef, bf, valoare)
    SELECT seq_d39416g2_codd39416g2.NEXTVAL, RecId, td.tiptranz, td.luna, td.nramef, td.bf, td.valoare
    FROM TMP_D39416G2 TD;

    INSERT INTO D39416G3 (codd39416g3, codd39416, tiptranz, luna, proctva, bi, tva)
    SELECT seq_d39416g3_codd39416g3.NEXTVAL, RecId, td.tiptranz, td.luna, td.proctva, td.bi, td.tva
    FROM TMP_D39416G3 TD;

    -- Detail D39416I
    DELETE FROM D39416I WHERE CodD39416 = RecID AND CodD39416I NOT IN (SELECT CodD39416I FROM TMP_D39416I WHERE CodD39416I &gt; 0);

    INSERT INTO D39416I (
      codd39416i, codd39416,
      totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
      achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
      achizs24,   achizs21,   achizs20,   achizs19,   achizs11,   achizs9,   achizs5, importb, acinecorp, livraribi,
      livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
      prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
      livrariue, prestue, export, livinecorp, efectuat
    )
    SELECT
      seq_d39416i_codd39416i.NEXTVAL, RecId,
      totalfact, totalfactben, totalfactterti, solicit, achizpe, achizcr, achizcb, achizci, achiza,
      achizb24,   achizb21,   achizb20,   achizb19,   achizb11,   achizb9,   achizb5,
      achizs24,   achizs21,   achizs20,   achizs19,   achizs11,   achizs9,   achizs5, importb, acinecorp, livraribi,
      livrarib24, livrarib21, livrarib20, livrarib19, livrarib11, livrarib9, livrarib5, livrarib0, livrariti,
      prest24,    prest21,    prest20,    prest19,    prest11,    prest9,    prest5,    prest0,
      livrariue, prestue, export, livinecorp, efectuat
    FROM TMP_D39416I;

    INSERT INTO D39416I1 (codD39416I1, codd39416, proctva, bazafslcod, tvafslcod, bazafsl, tvafsl, bazafsa, tvafsa, bazafsai, tvafsai, bazabfai, tvabfai, tvaded, tvadedi, tvacol)
    SELECT seq_d39416i1_codd39416i1.NEXTVAL, RecId, td.proctva, td.bazafslcod, td.tvafslcod, td.bazafsl, td.tvafsl, td.bazafsa, td.tvafsa, td.bazafsai, td.tvafsai, td.bazabfai, td.tvabfai, td.tvaded, td.tvadedi, td.tvacol
    FROM TMP_D39416I1 TD;

    INSERT INTO D39416I2A (codD39416I2A, codd39416, indexlocal, serie, startnr, endnr, numarf)
    SELECT seq_d39416i2a_codd39416i2a.NEXTVAL, RecId, td.indexlocal, td.serie, td.startnr, td.endnr, td.numarf
    FROM TMP_D39416I2A TD;

    INSERT INTO D39416I2 (codD39416I2, codd39416, indexlocal, serie, startnr, endnr, numarf)
    SELECT seq_d39416i2_codd39416i2.NEXTVAL, RecId, td.indexlocal, td.serie, td.startnr, td.endnr, td.numarf
    FROM TMP_D39416I2 TD;

    INSERT INTO D39416I3 (codD39416I3, codd39416, tipfactura, serief, numarf, cui, denp, proctva, bi, tva)
    SELECT seq_d39416i3_codd39416i3.NEXTVAL, RecId, td.tipfactura, td.serief, td.numarf, td.cui, td.denp, td.proctva, td.bi, td.tva
    FROM TMP_D39416I3 TD;

    INSERT INTO D39416I4 (codD39416I4, codd39416, caen, tipoper, proctva, valoare, tva)
    SELECT seq_d39416i4_codd39416i4.NEXTVAL, RecId, td.caen, td.tipoper, td.proctva, td.valoare, td.tva
    FROM TMP_D39416I4 TD;
  END IF;

  NotifyModif(Operation, RecId, &apos;D39416&apos;);
  COMMIT;
END;

PROCEDURE UmpleGEN( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER, pLei BOOLEAN DEFAULT FALSE) IS
  vLunaIni           INTEGER;
  vLunaFin           INTEGER;
  vD394StartNrFact   NUMBER(1);
  vLunaStartAnContab NUMBER(2);
  vAnContab          NUMBER(4);
  dD394StartNrFact   DATE;
  vArtFactMajorari   NUMBER(20);
  sCImbMifix         VARCHAR2(10000);
  vTVA0FaraJurnal    VARCHAR2(10000);
  vNrArtFaraJurnal   NUMBER(20);

  vCarnetNullStart   NUMBER(20);
  vCarnetNullEnd     NUMBER(20);

  TYPE t_rec IS RECORD ( CARNETDOC NUMBER(20), STARTNR NUMBER(20));
  TYPE t_tab IS TABLE OF t_rec;
  fetch_tab t_tab;

  CURSOR s_cur IS
    SELECT
      t.CARNETDOC,
      CASE
        WHEN t.tipdoc IN (1,3,4,5,9) THEN (SELECT Min(NrDoc) FROM intrari i WHERE Coalesce(i.CARNETDOC, 0) = t.CARNETDOC AND i.datadoc &gt;= dD394StartNrFact)
        ELSE                              (SELECT Min(NrDoc) FROM iesiri i  WHERE Coalesce(i.CARNETDOC, 0) = t.CARNETDOC AND i.datadoc &gt;= dD394StartNrFact)
      END NrDoc
    FROM (SELECT CARNETDOC, Min(TipDoc) TipDoc FROM tmp_d39416i2g GROUP BY CARNETDOC) t;

BEGIN
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);

  vLunaFin := pLuna;

  IF PKG_GLOBALS.GetLunaLucru IS NOT NULL AND vLunaFin &gt; PKG_GLOBALS.GetLunaLucru AND pAn = PKG_GLOBALS.GetAnLucru THEN
    vLunaFin := PKG_GLOBALS.GetLunaLucru ;
  END IF;

  IF    pTip = 0 THEN vLunaIni := 1;
  ELSIF pTip = 1 THEN vLunaIni := CASE WHEN vLunaFin &gt; 6 THEN 7 ELSE 1 END;
  ELSIF pTip = 2 THEN vLunaIni := CASE WHEN vLunaFin &gt; 9 THEN 10 WHEN vLunaFin &gt; 6 THEN 7 WHEN vLunaFin &gt; 3 THEN 4 ELSE 1 END;
  ELSE                vLunaIni := vLunaFin;
  END IF;

  UMPLE_TMP_CONST_PROCTVA(pAn*12+vLunaFin);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416_GEN&apos;;
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTAXE1&apos;);

  vD394StartNrFact := Coalesce(pkg_categconst.GetValConstanta(&apos;D394StartNrFact&apos;, pAn, vLunaFin), &apos;1&apos;);
  vArtFactMajorari := Coalesce(pkg_categconst.GetValConstanta(&apos;ArtFactMajorari&apos;, pAn, vLunaFin), &apos;0&apos;);
  sCImbMifix       := Coalesce(pkg_categconst.GetValConstanta(&apos;CImbMifix&apos;,       pAn, vLunaFin),&apos;-1&apos;);
  vTVA0FaraJurnal  := Coalesce(pkg_categconst.GetValConstanta(&apos;TVA0FaraJurnal&apos;,  pAn, vLunaFin),&apos;-1&apos;);

  DELETE FROM tmp_manevra2;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra2 SELECT codcont FROM ncont WHERE codcont IN (&apos;||sCImbMifix||&apos;)&apos;;

  DELETE FROM tmp_manevra3;
  vNrArtFaraJurnal := 0;
  IF vTVA0FaraJurnal &lt;&gt; &apos;-1&apos; THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra3(CODUNIC) SELECT DISTINCT CodArticol FROM NART1 WHERE CodTva IN (&apos;||vTVA0FaraJurnal||&apos;) AND ALSTART &lt;= &apos;||To_Char(pAn*12+vLunaFin)||&apos;AND ALSTOP &gt;= &apos;||To_Char(pAn*12+vLunaIni);
    SELECT Count(1) INTO vNrArtFaraJurnal FROM tmp_manevra3;
  END IF;

  --intrari
  INSERT INTO TMP_D39416_GEN
  WITH I AS (
    SELECT
      i.tipdoc, i.codintr, i.an, i.luna, i.operat, i.anulat, i.datadoc AS data, i.nrdoc, i.carnetdoc, i.TipTva, i.TipTranzactie, i.valdoc,
      Coalesce(i.tvaincasare_f, 0) AS tvainc_f,
      CASE
        WHEN i.tipdoc = 3 THEN 1
        ELSE Coalesce(i.factsimplif,0)
      END AS factsimplif, Coalesce(i.autofacturare, 0) AS AutoFact, p.codpart, Coalesce(p.tvalaincasare, 0) AS tvainc_p,
      CASE WHEN i.curs IS NULL THEN 1 WHEN i.curs = 0 THEN 1 ELSE i.curs END AS curs,
      Upper(REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\W+&apos;, &apos;&apos;)) AS CUI,
      REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\D+&apos;, &apos;&apos;) AS CUI_NR,
      p.den_part denp, Coalesce(p.persoanafizica,0) persfizica,
      l.codlocalit, a.strada AS strp, a.nr1 AS nrp, a.bloc AS blp, a.apart AS app,
      CASE WHEN Coalesce(Upper(t.simbauto), &apos;X&apos;) = &apos;RO&apos; THEN 1 ELSE Coalesce(t.statcomunitar, 0) END AS stat_ue, Coalesce(Upper(t.simbauto), &apos;X&apos;) AS simbauto,
      l.den_localit AS locp, To_Char(j.js,&apos;fm900&apos;) AS judp, t.simbauto AS tarap, j.simbauto AS sajudp, I.RotEFact
    FROM intrari i
      LEFT JOIN npart        p   ON p.codpart         = i.partener
      LEFT JOIN nagenda      a   ON a.codagenda       = i.codlocatie
      LEFT JOIN nlocalit     l   ON l.codlocalit      = a.codlocalit
      LEFT JOIN njudet       j   ON j.codjudet        = l.codjudet
		  LEFT JOIN ntari        t   ON t.codtara         = l.codtara
      LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
      LEFT JOIN npartcodfisc cfi ON cfi.codpart       = i.partener AND cfi.principal = 1
      LEFT JOIN nsubunit     sub ON sub.codsubunit    = i.subunitatea
    WHERE i.tipdoc IN (1,3,4,5,9)
      AND i.operat = 1 AND i.anulat = 0
      AND Coalesce(i.tiptranzactie, 0) &lt;&gt; 5
      --AND NOT ( Coalesce(i.factsimplif,0) = 0 AND i.tipdoc = 3)
      AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
      AND (pSubunit = 1 OR i.subunitatea = pSubunit)
      AND Coalesce(i.tipfactura,0) &lt;&gt; 2               -- Exclus BCA
      AND NOT (i.tipdoc = 4 AND i.tiptranzactie = 11) -- Exclus Arenda de la Persoane Fizice
      AND NOT (i.tipdoc = 1 AND i.TipTranzactie = 4 ) -- Exclus Factura de transport taxabila pe alt DVI
      AND Coalesce(SUB.NoEconomicActiv, 0) = 0
      AND ((COALESCE(I.INITIALIZARI, 0) = 0) OR EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODINTR AND G.TIPDOC = I.TIPDOC))
  ),
  I1 AS (
    SELECT
      i.tipdoc, i.codintr AS coddoc, i1.codintr1 AS coddoc1, i1.indexlocal, i.an, i.luna, Coalesce(oas.codobiect, o.codobiect) AS codobiect,
      CASE
        WHEN i.factsimplif = 1                                                                                            THEN &apos;I&apos; -- Facturi SIMPLIFICATE
        WHEN i.tipdoc = 5  AND i1.tiplinie = &apos;S&apos; AND EXISTS(SELECT 1 FROM tmp_manevra2 t2 WHERE t2.codunic = i1.contserv) THEN &apos;0&apos;
        WHEN i.tipdoc = 5                                                                                                 THEN &apos;F&apos; -- NonUE
        WHEN i.tipdoc = 4                                                                                                 THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.PersFizica = 1                                                                                             THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.CUI IS NULL                                                                                                THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.CUI = i.CUI_NR  AND i.stat_ue = 1                                                                          THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.tipdoc IN (1,9) AND SubStr(i.CUI,1,2) = &apos;RO&apos;                                                               THEN &apos;C&apos; -- Platitori de TVA
        WHEN i.stat_ue = 1 AND i.TipTva = 8 AND i.TipTranzactie = 2                                                       THEN &apos;E&apos; -- UE
        WHEN i.stat_ue = 0 AND i1.tiplinie = &apos;S&apos; AND EXISTS(SELECT 1 FROM tmp_manevra2 t2 WHERE t2.codunic = i1.contserv) THEN &apos;0&apos;
        WHEN stat_ue = 0                                                                                                  THEN &apos;F&apos; -- NonUE
      END AS SECTIUNE,
      i.cui, i.denp,
      CASE
        WHEN Length(i.CUI) &gt; 12 AND i.CUI = i.CUI_NR THEN 1
        ELSE i.persfizica
      END AS persfizica,
      i.codlocalit, i.strp, i.nrp, i.blp, i.app,
      CASE
        WHEN i.factsimplif = 1                                                                                 THEN 0
        WHEN i.stat_ue = 0     AND i.TipTva = 2                  AND i.TipTranzactie = 3 AND i1.tiplinie = &apos;S&apos; THEN 8
        WHEN i.stat_ue = 0     AND Coalesce(i1.impozabil, 0) = 3 AND i.TipTranzactie = 3 AND i1.tiplinie = &apos;S&apos; THEN 8
        WHEN i.tipdoc =     4                                                                                  THEN 9
        WHEN i.PersFizica = 1                                                                                  THEN 9
        WHEN i.CUI IS NULL                                                                                     THEN 9
        WHEN i.CUI = i.CUI_NR  AND i.stat_ue = 1                                                               THEN 9
        WHEN i.stat_ue = 1     AND i.TipTva = 8                  AND i.TipTranzactie = 2                       THEN 8
        WHEN i.tipdoc IN (1,9) AND i.TipTva = 2                                                                THEN 8
        WHEN i.tipdoc IN (1,9) AND Coalesce(i1.impozabil, 0) = 3                                               THEN 8
        WHEN i.tipdoc IN (1,9) AND i.TipTva IN (6, 7)            AND i.tvainc_f = 1                            THEN 6
        WHEN i.tipdoc IN (1,9) AND i.TipTva IN (6, 7)            AND i.tvainc_f = 0                            THEN 5
        WHEN i.tipdoc IN (1,9)                                   AND i.tvainc_f = 1                            THEN 4
        WHEN i.tipdoc IN (1,9)                                   AND i.tvainc_f = 0                            THEN 3
      END AS TipTranz,
      CASE
        WHEN i.TipTva = 7 AND i.tvainc_f = 1 THEN 2
        WHEN i.TipTva = 6 AND i.tvainc_f = 1 THEN 1
        ELSE 0
      END AS RegScutire,
      CASE
        WHEN Coalesce(i1.coefdiscmaj,1) = 1 + Coalesce(i1.addim/100, 0) THEN i1.cant * i1.pu
        ELSE i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)
      END +
      CASE
        WHEN Coalesce(tax1.codservfact,0) = 0 THEN 0
        WHEN i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1) = 0 THEN 0
        WHEN Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(tax1.codservfact,0)) = 0 THEN 0
        ELSE  (
                SELECT Coalesce(Sum(xi1.cant * xi1.pu),0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(tax1.codservfact,0)
                  AND t3.codunic IS NULL
              ) * i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)
                / Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(tax1.codservfact,0))
      END +
      CASE
        WHEN Coalesce(tax2.codservfact,0) = 0 THEN 0
        WHEN i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1) = 0 THEN 0
        WHEN Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(tax2.codservfact,0)) = 0 THEN 0
        ELSE  (
                SELECT Coalesce(Sum(xi1.cant * xi1.pu),0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(tax2.codservfact,0)
                  AND t3.codunic IS NULL
              ) * i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)
                / Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(tax2.codservfact,0))
      END +
      CASE
        WHEN Coalesce(acci.codservfact,0) = 0 THEN 0
        WHEN i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1) = 0 THEN 0
        WHEN Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(acci.codservfact,0)) = 0 THEN 0
        ELSE  (
                SELECT Coalesce(Sum(xi1.cant * xi1.pu),0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(acci.codservfact,0)
                  AND t3.codunic IS NULL
              ) * i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)
                / Sum(i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)) OVER (PARTITION BY i.codintr, Coalesce(acci.codservfact,0))
      END
      AS baza,
      CASE
        WHEN Coalesce(i.tiptva, 0) = 9 THEN 0
        WHEN i.tipdoc = 5              THEN dvi1.tva/i.curs
        WHEN i1.tva = 0                THEN 0
        WHEN i1.pu  = 0                THEN 0
        ELSE  (i1.tva * Coalesce(i1.coefdiscmaj,1) * i1.pretorig / i1.pu)
      END +
      CASE
        WHEN Coalesce(i.tiptva, 0) = 9        THEN 0
        WHEN Coalesce(tax1.codservfact,0) = 0 THEN 0
        WHEN i1.tva = 0                       THEN 0
        WHEN i1.pu  = 0                       THEN 0
        WHEN Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(tax1.codservfact,0)) = 0 THEN 0
        ELSE (
                SELECT Coalesce(Sum( CASE WHEN xi1.pu = 0 THEN 0 ELSE xi1.tva * Coalesce(xi1.coefdiscmaj,1) * xi1.pretorig / xi1.pu END), 0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(tax1.codservfact,0)
                  AND t3.codunic IS NULL
             ) *(i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu)
               / Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(tax1.codservfact,0))
      END +
      CASE
        WHEN Coalesce(i.tiptva, 0) = 9        THEN 0
        WHEN Coalesce(tax2.codservfact,0) = 0 THEN 0
        WHEN i1.tva = 0                       THEN 0
        WHEN i1.pu  = 0                       THEN 0
        WHEN Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(tax2.codservfact,0)) = 0 THEN 0
        ELSE (
                SELECT Coalesce(Sum( CASE WHEN xi1.pu = 0 THEN 0 ELSE xi1.tva * Coalesce(xi1.coefdiscmaj,1) * xi1.pretorig / xi1.pu END), 0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(tax2.codservfact,0)
                  AND t3.codunic IS NULL
             ) *(i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu)
               / Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(tax2.codservfact,0))
      END +
      CASE
        WHEN Coalesce(i.tiptva, 0) = 9        THEN 0
        WHEN Coalesce(acci.codservfact,0) = 0 THEN 0
        WHEN i1.tva = 0                       THEN 0
        WHEN i1.pu  = 0                       THEN 0
        WHEN Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(acci.codservfact,0)) = 0 THEN 0
        ELSE (
                SELECT Coalesce(Sum( CASE WHEN xi1.pu = 0 THEN 0 ELSE xi1.tva * Coalesce(xi1.coefdiscmaj,1) * xi1.pretorig / xi1.pu END), 0)
                FROM   intrari1 xi1
                  LEFT JOIN nartobj o ON o.codobiect = xi1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
                WHERE xi1.codintr = i.codintr AND COALESCE(xi1.taxa,0) IN (1, 2, 3) AND COALESCE(xi1.tva,0) &lt;&gt; 0
                  AND xi1.codobiect = Coalesce(acci.codservfact,0)
                  AND t3.codunic IS NULL
             ) *(i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu)
               / Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva  * i1.pretorig * Coalesce(i1.coefdiscmaj,1) / i1.pu END) OVER (PARTITION BY i.codintr, Coalesce(acci.codservfact,0))
      END
      AS tva,
      CASE
        WHEN Coalesce(i.tiptva, 0) = 9
        THEN 0
        ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, pAn, vLunaFin, I1.CANT, I1.PU, CASE WHEN I.TIPDOC = 5 THEN DVI1.TVA/I.CURS ELSE I1.TVA END, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT)
      END AS ProcTva,
      i.curs,
      CASE
        WHEN i.TipTva = 2                  THEN cti.CodP
        WHEN Coalesce(i1.impozabil, 0) = 3 THEN cti.CodP
        WHEN i1.tiplinie = &apos;=&apos;             THEN cti.Codn_Stoc
        ELSE                                    cti.Codn_Serv
      END AS categtxinv,
      CASE
        WHEN i.TipTva = 2                  AND cti.simbolp = 21 THEN Coalesce(oas.codd394, o.codd394)
        WHEN Coalesce(i1.impozabil, 0) = 3 AND cti.simbolp = 21 THEN Coalesce(oas.codd394, o.codd394)
        WHEN i.TipTva = 2                                       THEN To_Char(cti.simbolp)
        WHEN Coalesce(i1.impozabil, 0) = 3                      THEN To_Char(cti.simbolp)
        WHEN cti.simboln = 21                                   THEN Coalesce(oas.codd394, o.codd394)
        ELSE                                                         To_Char(cti.simboln)
      END AS codd394,
      i.codpart, 0 F, i.CUI_NR, i.DATA,
      CASE
        WHEN SubStr(i.CUI,1,2) = &apos;RO&apos; AND i.PersFizica = 0 THEN NULL -- am gasit CIF cu RO Valid marca ca Persoana fizica  - nu stiu ce sa faca in acest caz - autocorectie DA/NU?
        WHEN i.SimbAuto &lt;&gt; &apos;RO&apos;                            THEN 7 -- Partener strain neverificabil
        WHEN i.PersFizica = 1                              THEN 6
        WHEN i.CUI IS NULL                                 THEN 6
        WHEN i.CUI = i.CUI_NR AND Length(i.CUI) &gt; 12       THEN 6
      END CUIVALID,
      CASE
        WHEN i.tipdoc = 4 THEN Greatest(2,Coalesce(i.TipTranzactie,7)-5)
        ELSE 1
      END AS tipdocRN,
      i.stat_ue, 0 exceptie_d,
      CASE
        WHEN i.factsimplif = 0             THEN 0
        WHEN i.CUI IS NULL                 THEN 0
        WHEN i.CUI_NR IS NULL              THEN 0
        WHEN SubStr(i.CUI,1,2) &lt;&gt; &apos;RO&apos;     THEN 0
        WHEN i.TipDoc = 3 AND tvainc_p = 1 THEN 14
        WHEN i.TipDoc = 3                  THEN 15
        WHEN i.tvainc_f = 1                THEN 14
        ELSE                                    13
      END AS TipI1,
      0 AS nrbonuri, i.AutoFact, i.operat, 0 anulat,
      CASE
        WHEN i.AutoFact = 1 AND Round(i.valdoc,2) &lt; 0 THEN -4 -- storno emise in numele furnizorului
        WHEN i.AutoFact = 1                           THEN  4 -- emise in numele furnizorului
        ELSE                                                9 -- nu se ia in calcul
      END AS TipFactura,
      i.carnetdoc, i.nrdoc,
      i.locp, i.judp, i.tarap, i.sajudp,
      CASE WHEN i.PersFizica = 3 THEN 1 ELSE 0 END AS persafiliata,
      i1.cant, i1.pu
    FROM I
      INNER JOIN intrari1    i1   ON i1.codintr        = i.codintr
      LEFT JOIN dvi1              ON dvi1.codintr1     = i1.codintr1
      LEFT JOIN nartobj      o    ON o.codobiect       = i1.codobiect
      LEFT JOIN nartobj      oas  ON oas.codobiect     = i1.codobiectorig
      LEFT JOIN categartti   cti  ON cti.CodCategArtTI = Coalesce(oas.CodCategArtTI, o.CodCategArtTI, 0)
      LEFT JOIN nart1        art1 ON art1.codarticol   = o.codarticol   AND i.an*12+i.luna BETWEEN art1.alstart AND art1.alstop
      LEFT JOIN ntva1        tva1 ON tva1.codtva       = art1.codtva    AND i.an*12+i.luna BETWEEN tva1.alstart AND tva1.alstop
      LEFT JOIN ntaxe1       tax1 ON tax1.codtaxa      = art1.codtaxa1  AND i.an*12+i.luna BETWEEN tax1.alstart AND tax1.alstop
      LEFT JOIN ntaxe1       tax2 ON tax2.codtaxa      = art1.codtaxa2  AND i.an*12+i.luna BETWEEN tax2.alstart AND tax2.alstop
      LEFT JOIN ntaxe1       acci ON acci.codtaxa      = art1.codaccize AND i.an*12+i.luna BETWEEN acci.alstart AND acci.alstop
      LEFT JOIN tmp_manevra3 t3   ON t3.codunic        = o.codarticol --articole conform const TVA0FaraJurnal
    WHERE i1.tiplinie IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) AND t3.codunic IS NULL
      --AND i1.cant*i1.pu &lt;&gt; 0
      AND COALESCE(i1.taxa, 0) = 0
      AND NOT Coalesce(i1.impozabil, 0) IN (2, 4)
  )
  SELECT
    TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, CODOBIECT, SECTIUNE, CUI, DENP, PERSFIZICA, CODLOCALIT, STRP, NRP, BLP, APP, TIPTRANZ, REGSCUTIRE,
    BAZA, TVA, PROCTVA, CURS, CATEGTXINV, CODD394, CODPART, F, CUI_NR, DATA, CUIVALID, TIPDOCRN, STAT_UE, EXCEPTIE_D, TIPI1, NRBONURI, AUTOFACT, OPERAT, ANULAT, TIPFACTURA, CARNETDOC, NRDOC,
    LOCP, JUDP, TARAP, SAJUDP, PERSAFILIATA
  FROM I1
  WHERE i1.cant*i1.pu &lt;&gt; 0 OR i1.proctva &lt;&gt; 0;

  DELETE FROM TMP_D39416_GEN WHERE SECTIUNE = &apos;0&apos;;
  UPDATE TMP_D39416_GEN SET BAZA = BAZA - TVA WHERE TipDoc = 3;

  --iesiri
  INSERT INTO TMP_D39416_GEN
  WITH I AS  (
    SELECT
      i.tipdoc, i.codies, i.an, i.luna, i.operat, i.anulat, i.datadoc AS data, i.nrdoc, i.carnetdoc, i.TipTva, i.TipTranzactie,
      Coalesce(i.factsimplif,0) AS factsimplif, p.codpart, i.Emisadeclient, i.valdoc,
      CASE WHEN i.curs IS NULL THEN 1 WHEN i.curs = 0 THEN 1 ELSE i.curs END AS curs,
      Upper(REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\W+&apos;, &apos;&apos;)) AS CUI,
      REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\D+&apos;, &apos;&apos;) AS CUI_NR,
      p.den_part AS denp, Coalesce(p.persoanafizica,0) AS persfizica, l.codlocalit, a.strada AS strp, a.nr1 AS nrp, a.bloc AS blp, a.apart AS app,
      CASE WHEN Coalesce(Upper(t.simbauto), &apos;X&apos;) = &apos;RO&apos; THEN 1 ELSE Coalesce(t.statcomunitar, 0) END AS stat_ue, Coalesce(Upper(t.simbauto), &apos;X&apos;) AS simbauto,
      l.den_localit AS locp, To_Char(j.js,&apos;fm900&apos;) AS judp, t.simbauto AS tarap, j.simbauto AS sajudp,
      CASE WHEN i.TipTranzactie = 4 THEN 1 ELSE 0 END AS AutoFact, I.RotEFact
    FROM iesiri i
      LEFT JOIN npart        p   ON p.codpart         = i.partener
      LEFT JOIN nagenda      a   ON a.codagenda       = i.codlocatie
      LEFT JOIN nlocalit     l   ON l.codlocalit      = a.codlocalit
      LEFT JOIN njudet       j   ON j.codjudet        = l.codjudet
		  LEFT JOIN ntari        t   ON t.codtara         = l.codtara
      LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
      LEFT JOIN npartcodfisc cfi ON cfi.codpart       = i.partener AND cfi.principal = 1
      LEFT JOIN nsubunit     sub ON sub.codsubunit    = i.subunitatea
    WHERE i.tipdoc IN (19,26)
      AND i.operat = 1 AND i.anulat = 0
      AND Coalesce(i.tiptranzactie, 0) &lt;&gt; 5
      AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
      AND (pSubunit = 1 OR i.subunitatea = pSubunit)
      AND i.TipTva IN (1, 2, 4, 7, 8, 9)
      AND Coalesce(SUB.NoEconomicActiv, 0) = 0
      AND Coalesce(i.TipFactura,0) &lt;&gt; 15
      AND ((COALESCE(I.INITIALIZARI, 0) = 0) OR EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC))
  ),
  I1 AS (
    SELECT
      i.tipdoc, i.codies AS coddoc, i1.codies1 AS coddoc1, i1.indexlocal, i.an, i.luna, Coalesce(oas.codobiect, o.codobiect) AS codobiect,
      CASE
        WHEN i.AutoFact = 1                       THEN &apos;X&apos; -- Facturi AUTOFACTURATE
        WHEN i.factsimplif = 1                    THEN &apos;I&apos; -- Facturi SIMPLIFICATE
        WHEN i.PersFizica = 1                     THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.CUI IS NULL                        THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN i.CUI = i.CUI_NR AND i.stat_ue = 1   THEN &apos;D&apos; -- Neplatitori de TVA
        WHEN SubStr(i.CUI,1,2) = &apos;RO&apos;             THEN &apos;C&apos; -- Platitori de TVA
        WHEN i.stat_ue = 0                        THEN &apos;F&apos; -- NonUE
        WHEN i.stat_ue = 1                        THEN &apos;E&apos; -- UE
        ELSE                                           &apos;D&apos; -- Neplatitori de TVA - cui invalida sa apara in Declaratie sa se poata face corectia
      END AS SECTIUNE,
      i.cui, i.denp,
      CASE
        WHEN Length(i.CUI) &gt; 12 AND i.CUI = i.CUI_NR THEN 1
        ELSE i.persfizica
      END persfizica,
      i.codlocalit, i.strp, i.nrp, i.blp, i.app,
      CASE
        WHEN i.TipTva = 2                  AND i.tiptranzactie &lt;&gt; 2 THEN 7
        WHEN Coalesce(i1.impozabil, 0) = 3 AND i.tiptranzactie &lt;&gt; 2 THEN 7
        WHEN i.TipTva IN (7, 8)                                     THEN 2
        WHEN i.TipTva = 9                  AND i.tiptranzactie =  2 THEN 1
        WHEN i.TipTva = 4                  AND i.tiptranzactie =  3 THEN 1
        WHEN Coalesce(i1.impozabil, 0) = 3                          THEN 1
        WHEN i.TipTva = 2                                           THEN 1
        WHEN i.TipTva = 1                                           THEN 1
      END AS TipTranz,
      CASE
        WHEN i.TipTva = 8 THEN 2
        WHEN i.TipTva = 7 THEN 1
        ELSE 0
      END AS RegScutire,
      CASE
        WHEN Coalesce(i1.coefdiscmaj,1) = 1 + Coalesce(i1.addim/100, 0) THEN i1.cant * i1.pu
        ELSE i1.cant * i1.pretorig * Coalesce(i1.coefdiscmaj,1)
        -- comentat pentru a rezolva tichetul 58455
--      END +
--      CASE
--        WHEN i1.cant*i1.pu = 0                                          THEN 0
--        WHEN NOT i.TipTva IN (7, 8)                                     THEN 0
--        WHEN Coalesce(i1.coefdiscmaj,1) = 1 + Coalesce(i1.addim/100, 0) THEN Coalesce(i1.tva, 0)
--        ELSE                                                                 Coalesce(i1.tva, 0) * Coalesce(i1.coefdiscmaj,1) * i1.pretorig / i1.pu
      END AS baza,
      CASE
        WHEN i.TipTva = 2                  AND i.tiptranzactie &lt;&gt; 2     THEN 0
        WHEN Coalesce(i1.impozabil, 0) = 3 AND i.tiptranzactie &lt;&gt; 2     THEN 0
        WHEN COALESCE(i1.cant*i1.pu, 0) = 0                             THEN 0
        WHEN Coalesce(i1.coefdiscmaj,1) = 1 + Coalesce(i1.addim/100, 0) THEN Coalesce(i1.tva, 0)
        ELSE                                                                 Coalesce(i1.tva, 0) * Coalesce(i1.coefdiscmaj,1) * i1.pretorig / i1.pu
      END AS tva,
      CASE
        WHEN i.TipTva = 2                  AND i.tiptranzactie &lt;&gt; 2                THEN 0
        WHEN Coalesce(i1.impozabil, 0) = 3 AND i.tiptranzactie &lt;&gt; 2                THEN 0
        WHEN i.TipTva = 4                  AND i.tiptranzactie =  3 AND I1.TVA = 0 THEN 0
        ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, pAn, vLunaFin, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT)
      END AS ProcTva,
      i.curs,
      CASE
        WHEN i.TipTva = 2                  THEN cti.CodP
        WHEN Coalesce(i1.impozabil, 0) = 3 THEN cti.CodP
        WHEN i1.tiplinie = &apos;=&apos;             THEN cti.Codn_Stoc
        ELSE                                    cti.Codn_Serv
      END AS categtxinv,
      CASE
        WHEN i.TipTva = 2                  AND cti.simbolp = 21 THEN Coalesce(oas.codd394, o.codd394)
        WHEN Coalesce(i1.impozabil, 0) = 3 AND cti.simbolp = 21 THEN Coalesce(oas.codd394, o.codd394)
        WHEN i.TipTva = 2                                       THEN To_Char(cti.simbolp)
        WHEN Coalesce(i1.impozabil, 0) = 3                      THEN To_Char(cti.simbolp)
        WHEN cti.simboln = 21                                   THEN Coalesce(oas.codd394, o.codd394)
        ELSE                                                         To_Char(cti.simboln)
      END AS codd394,
      i.codpart, 0 AS F, i.CUI_NR, i.DATA,
      CASE
        WHEN SubStr(i.CUI,1,2) = &apos;RO&apos; AND i.PersFizica = 0 THEN NULL -- am gasit CIF cu RO Valid marca ca Persoana fizica  - nu stiu ce sa faca in acest caz - autocorectie DA/NU?
        WHEN i.SimbAuto &lt;&gt; &apos;RO&apos;                            THEN 7 -- Partener strain neverificabil
        WHEN i.PersFizica = 1                              THEN 6
        WHEN i.CUI IS NULL                                 THEN 6
        WHEN i.CUI = i.CUI_NR AND Length(i.CUI) &gt; 12       THEN 6
      END AS CUIVALID,
      NULL AS tipdocRN,
      i.stat_ue, 0 AS exceptie_d,
      CASE
        WHEN i.factsimplif = 0         THEN 0
        WHEN i.CUI IS NULL             THEN 12
        WHEN i.CUI_NR IS NULL          THEN 12
        WHEN i.CUI = i.CUI_NR          THEN 12
        WHEN SubStr(i.CUI,1,2) = &apos;RO&apos;  THEN 11
        ELSE                                0
      END AS TipI1,
      0 AS nrbonuri, i.AutoFact, i.operat, i.anulat,
      CASE
        WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 2 THEN  6 -- emise de terti in numele persoanei impozabile
        WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 1 THEN  5 -- emise de beneficiari in numele persoanei impozabile
        --WHEN i.TipTranzactie = 4 AND Round(i.valdoc,2) &lt; 0  THEN -3 -- AUTOFACTURARE
        WHEN i.TipTranzactie = 4                              THEN  3 -- AUTOFACTURARE
        WHEN i.tipdoc IN (19, 26) AND Round(i.valdoc,2) &lt; 0   THEN  1 -- STORNATA
        ELSE                                                        0 -- ALTE FACTURI UTILIZATE
      END AS TipFactura,
      i.carnetdoc, i.nrdoc,
      i.locp, i.judp, i.tarap, i.sajudp,
      CASE WHEN i.PersFizica = 3 THEN 1 ELSE 0 END AS persafiliata,
      i1.cant, i1.pu
    FROM i
      INNER JOIN iesiri1     i1   ON i1.codies         = i.codies
      LEFT JOIN nartobj      o    ON o.codobiect       = i1.codobiect
      LEFT JOIN nartobj      oas  ON oas.codobiect     = i1.codobiectorig
      LEFT JOIN categartti   cti  ON cti.CodCategArtTI = Coalesce(oas.CodCategArtTI, o.CodCategArtTI, 0)
      LEFT JOIN nart1        art1 ON art1.codarticol   = o.codarticol   AND i.an*12+i.luna BETWEEN art1.alstart AND art1.alstop
      LEFT JOIN ntva1        tva1 ON tva1.codtva       = art1.codtva    AND i.an*12+i.luna BETWEEN tva1.alstart AND tva1.alstop
      LEFT JOIN tmp_manevra3 t3   ON t3.codunic        = o.codarticol --articole conform const TVA0FaraJurnal
    WHERE i1.tiplinie IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) AND t3.codunic IS NULL
      AND NOT Coalesce(i1.impozabil, 0) IN (2, 4)
      AND Coalesce(i1.codobiect, -1) &lt;&gt; vArtFactMajorari
      --AND i1.cant*i1.pu &lt;&gt; 0
  )
  SELECT
    TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, CODOBIECT, SECTIUNE, CUI, DENP, PERSFIZICA, CODLOCALIT, STRP, NRP, BLP, APP, TIPTRANZ, REGSCUTIRE,
    BAZA, TVA, PROCTVA, CURS, CATEGTXINV, CODD394, CODPART, F, CUI_NR, DATA, CUIVALID, TIPDOCRN, STAT_UE, EXCEPTIE_D, TIPI1, NRBONURI, AUTOFACT, OPERAT, ANULAT, TIPFACTURA, CARNETDOC, NRDOC,
    LOCP, JUDP, TARAP, SAJUDP, PERSAFILIATA
  FROM I1
  WHERE i1.cant*i1.pu &lt;&gt; 0 OR i1.proctva &lt;&gt; 0;

  IF  pAn*12+pLuna &lt; 2016*12+10 THEN
    DELETE FROM TMP_D39416_GEN WHERE NOT SECTIUNE = &apos;C&apos;;
  ELSE
    INSERT INTO TMP_D39416_GEN  ( TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, BAZA, TVA, PROCTVA, CURS, DATA, NRBONURI, AUTOFACT, TIPFACTURA )
    SELECT tipdoc, codies, codies1, indexlocal, an, luna, sectiune, TipTranz, baza, tva, ProcTva, 1 curs, data, 0 nrbonuri, 0 AutoFact, 9 TipFactura
    FROM (
      SELECT
        i.tipdoc, i.codies, i1.codies1, i1.indexlocal, i.an, i.luna, &apos;G&apos; AS SECTIUNE, i.DataDoc AS DATA, 11 TipTranz,
        CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE (i1.cant*i1.pu - i1.tva) * Coalesce(i1.coefdiscmaj,1)*i1.pretorig/i1.pu END baza,
        CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE i1.tva                   * Coalesce(i1.coefdiscmaj,1)*i1.pretorig/i1.pu END tva,
        PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, pAn, vLunaFin, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT) ProcTva
      FROM iesiri i
        INNER JOIN iesiri1 i1   ON i1.codies       = i.codies
        LEFT JOIN nsubunit sub  ON sub.codsubunit  = i.subunitatea
        LEFT JOIN nartobj  o    ON o.codobiect     = i1.codobiect
        LEFT JOIN nart1    art1 ON art1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN art1.alstart AND art1.alstop
        LEFT JOIN ntva1    tva1 ON tva1.codtva     = art1.codtva  AND i.an*12+i.luna BETWEEN tva1.alstart AND tva1.alstop
      WHERE i.tipdoc IN (21) AND i.operat = 1 AND i.anulat = 0 AND Coalesce(i.factsimplif, 0) = 0
        AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND i1.tiplinie IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;)
        AND i1.cant*i1.pu &lt;&gt; 0
        AND i1.tva &lt;&gt; 0
        AND Coalesce(SUB.NoEconomicActiv, 0) = 0
        AND ((COALESCE(I.INITIALIZARI, 0) = 0) OR EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC))
    ) subsel
    --WHERE tva &lt;&gt; 0 AND baza &lt;&gt; 0;
    WHERE proctva &lt;&gt; 0 AND baza &lt;&gt; 0;

    FOR vRec IN (
      SELECT DISTINCT i.codies 
      FROM iesiri i
        INNER JOIN iesiri1 i1   ON i1.codies       = i.codies
      WHERE i.tipdoc IN (16) AND i.operat = 1 AND i.anulat = 0 AND Coalesce(i.factsimplif, 0) = 0
        AND Coalesce(i.NumarBonuri,0) - Coalesce(i.NrInfoCM,0) - Coalesce(i.NrIncasIm,0) - Coalesce(i.NrIncasUlt,0) &lt;&gt; 0
        AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND BITAND(i.Flags, 1) =  0
    ) LOOP
      PKG_IESIRI.SetValFin(vRec.CodIes, 0);
    END LOOP;

    INSERT INTO TMP_D39416_GEN  (
      TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, BAZA, TVA, PROCTVA, CURS, DATA,
      NRBONURI,
      AUTOFACT, TIPFACTURA )
    SELECT
      tipdoc, codies, codies1, indexlocal, an, luna, sectiune, TipTranz, baza, tva, ProcTva, 1 curs, data,
      CASE WHEN Row_Number() OVER (PARTITION BY codies ORDER BY codies1) &gt; 1 THEN 0 ELSE nrbonuri END nrbonuri,
      0 AutoFact, 9 TipFactura
    FROM (
      SELECT
        tipdoc, codies, codies1, indexlocal, an, luna, &apos;G&apos; SECTIUNE, DATA, 10 TipTranz,
        ValLin - TVALin baza, TVALin tva,
        NRBONURI, ProcTva
      FROM (
        SELECT
          i.tipdoc, i.codies, i.an, i.luna, i.DataDoc AS DATA,
          i1.codies1, i1.tiplinie, i1.indexlocal, i1.codobiect, i1.contserv, Coalesce(I1.TVAFIN, I1.TVA, 0) TVALin, Coalesce(I1.VALFIN,i1.pu * i1.cant, 0) ValLin, Coalesce(i1.valdiscpret, 0) valdiscpret,
          Coalesce(i.NumarBonuri,0) - Coalesce(i.NrInfoCM,0) - Coalesce(i.NrIncasIm,0) - Coalesce(i.NrIncasUlt,0) NRBONURI,
          Coalesce(i.ValDiscount, 0) ValDiscount, Sum(Coalesce(i1.valdiscpret, 0)) OVER (PARTITION BY i.codies) ValDiscLin,
          PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, pAn, vLunaFin, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT) ProcTva
        FROM iesiri i
          INNER JOIN iesiri1 i1   ON i1.codies       = i.codies
          LEFT JOIN nsubunit sub  ON sub.codsubunit  = i.subunitatea
          LEFT JOIN nartobj  o    ON o.codobiect     = i1.codobiect
          LEFT JOIN nart1    art1 ON art1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN art1.alstart AND art1.alstop
          LEFT JOIN ntva1    tva1 ON tva1.codtva     = art1.codtva  AND i.an*12+i.luna BETWEEN tva1.alstart AND tva1.alstop
        WHERE i.tipdoc IN (16) AND i.operat = 1 AND i.anulat = 0 AND Coalesce(i.factsimplif, 0) = 0
          AND Coalesce(i.NumarBonuri,0) - Coalesce(i.NrInfoCM,0) - Coalesce(i.NrIncasIm,0) - Coalesce(i.NrIncasUlt,0) &lt;&gt; 0
          AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
          AND (pSubunit = 1 OR i.subunitatea = pSubunit)
          AND Coalesce(SUB.NoEconomicActiv, 0) = 0
          AND ((COALESCE(I.INITIALIZARI, 0) = 0) OR EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC))
      ) sela
      WHERE TVALin &lt;&gt; 0 AND ValLin &lt;&gt; 0 AND tiplinie IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;)
        AND NOT CodObiect IN (SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasUlterior&apos;  ,pAn,vLunaFin),&apos;0&apos;) FROM dual )
    ) selb
    --WHERE tva &lt;&gt; 0 AND baza &lt;&gt; 0;
    WHERE proctva &lt;&gt; 0 AND baza &lt;&gt; 0;

    INSERT INTO TMP_D39416_GEN  ( TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, BAZA, TVA, PROCTVA, CURS, DATA, NRBONURI, AUTOFACT, TIPFACTURA )
    SELECT
      i.tipdoc, i.codies, 0 codies1, 0 indexlocal, i.an, i.luna, &apos;G&apos; SECTIUNE,
      10 TipTranz,
      - (tm.valoare - tm.tva) baza,
      - tm.tva,
      Coalesce(
        tva1.PROCENT,
        PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, 2025, 8, 1, TM.VALOARE, TM.TVA, 0, -1, I.ROTEFACT)
      ) ProcTva,
      1 curs, i.DataDoc AS DATA,
      0 NRBONURI,
      0 AutoFact,
      9 TipFactura
    FROM iesiri i
      INNER JOIN tvamonetar tm   ON tm.codies      = i.codies
      LEFT JOIN  ntva1      tva1 ON tva1.codtva    = tm.codtva  AND i.an*12+i.luna BETWEEN tva1.alstart AND tva1.alstop
      LEFT JOIN  nsubunit   sub  ON sub.codsubunit = i.subunitatea
    WHERE i.tipdoc IN (16) AND i.operat = 1 AND i.anulat = 0 AND Coalesce(i.factsimplif, 0) = 0
      AND Coalesce(NumarBonuri,0) - Coalesce(NrInfoCM,0) - Coalesce(NrIncasIm,0) - Coalesce(NrIncasUlt,0) &lt;&gt; 0
      AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
      AND (pSubunit = 1 OR i.subunitatea = pSubunit)
      AND tm.valoare - tm.tva &lt;&gt; 0
      AND tm.tva &lt;&gt; 0
      AND Coalesce(SUB.NoEconomicActiv, 0) = 0
      AND ((COALESCE(I.INITIALIZARI, 0) = 0) OR EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC));

    INSERT INTO TMP_D39416_GEN  ( TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, TIPI1, BAZA, TVA, PROCTVA, CURS, DATA, NRBONURI, AUTOFACT, TIPFACTURA )
    SELECT tipdoc, codtrezor, codtrezor1, indexlocal, an, luna, sectiune, TipTranz, TipI1, baza, tva, tva*100/baza ProcTva, curs, data, 0 nrbonuri, 0 AutoFact, 9 TipFactura
    FROM (
      SELECT
        t.tipdoc, t1.codtrezor, t1.codtrezor1, t1.indexlocal, t.an, t.luna,
        CASE
          WHEN t1.tiptranz = 1 THEN &apos;G&apos;
          WHEN t1.tiptranz = 0 THEN &apos;I&apos;
        END SECTIUNE,
        t.DataDoc AS DATA,
        CASE
          WHEN t1.tiptranz = 1 THEN 11
          WHEN t1.tiptranz = 0 THEN 0
        END TipTranz,
        CASE
          WHEN t1.tiptranz = 1 THEN 0
          WHEN t1.tiptranz = 0 THEN 15
        END TipI1,
        CASE WHEN g.curs IS NULL THEN 1 WHEN g.curs = 0 THEN 1 ELSE g.curs END curs,
        o.valoare - g.tva baza,
        g.tva
      FROM trezor1 t1
        INNER JOIN trezor   t   ON t1.codtrezor   = t.codtrezor
        INNER JOIN general  g   ON g.coddoc       = t1.codtrezor1 AND g.tipdoc = t.tipdoc
        INNER JOIN obligpif o   ON o.codgeneral   = g.codgeneral
        LEFT  JOIN nsubunit sub ON sub.codsubunit = t.subunitatea
      WHERE t1.anulat = 0 AND t.operat = 1
        AND t1.obiecttranz = 4
        AND t1.tiptranz IN (0, 1)
        AND t1.an = pAn AND t1.luna BETWEEN vLunaIni AND vLunaFin
        AND (pSubunit = 1 OR t.subunitatea = pSubunit)
        AND g.tva &lt;&gt; 0
        AND Coalesce(SUB.NoEconomicActiv, 0) = 0
    ) subsel
    WHERE baza &lt;&gt; 0;

    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_JV_D300&apos;;
    PKG_LIST_BASE_JURNVANZ.SetPerioada(
      pAn                  =&gt; pAn,
      pLuna                =&gt; pLuna,
      pTip                 =&gt; CASE pTip WHEN 0 THEN 3 WHEN 1 THEN 2 WHEN 2 THEN 1 ELSE 0 END,
      pSubunit             =&gt; CASE pSubunit WHEN 1 THEN 0 ELSE pSubunit END,
      pExclNoEconomicActiv =&gt; TRUE
    );
    PKG_LIST_BASE_JURNVANZ.ProcessList(&apos;TMP_JV_D300&apos;);

    INSERT INTO TMP_D39416_GEN  (
      TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, BAZA, TVA,
      PROCTVA,
      CURS, DATA, TIPI1, AUTOFACT, TIPFACTURA )
    SELECT
      tipdoc, coddoc, coddoc1, indexlocal, an, luna, sectiune, TipTranz, baza, INCTVA tva,
      --CASE WHEN baza = 0 THEN (SELECT PKG_SELECTARTICOLE.GETPROCENTTVA(O.CodArticol, SUBSEL.An, SUBSEL.Luna) FROM iesiri1 i1 INNER JOIN nartobj o ON o.codobiect = i1.codobiect WHERE i1.codies1 = subsel.CODDOC1) ELSE tva*100/baza END ProcTva,
      ProcTva,
      1 curs, data, TIPI1, 0 AutoFact, 9 TipFactura
    FROM (
      SELECT
        t.NAV_TIPDOC tipdoc, t.NAV_CODDOC coddoc, t.NAV_CODDOC1 CODDOC1, t.ORDDOC indexlocal, t.andoc an, t.lunadoc luna, &apos;I&apos; AS SECTIUNE, t.DataDoc AS DATA, 0 TipTranz,
        23 TIPI1,
        CASE L.SIMBOL
          WHEN &apos;PROCTVAMED&apos;  THEN T.BAZA_MED  WHEN &apos;PROCTVAMIN&apos;  THEN T.BAZA_MIN  WHEN &apos;PROCTVAMAX&apos;  THEN T.BAZA_MAX
          WHEN &apos;PROCTVAREG&apos;  THEN T.BAZA_REG  WHEN &apos;PROCTVAREG2&apos; THEN T.BAZA_REG2
          WHEN &apos;PROCTVAREG3&apos; THEN T.BAZA_REG3 WHEN &apos;PROCTVAREG4&apos; THEN T.BAZA_REG4 WHEN &apos;PROCTVAREG5&apos; THEN T.BAZA_REG5
        END baza,
        CASE L.SIMBOL
          WHEN &apos;PROCTVAMED&apos;  THEN T.TVA_MED   WHEN &apos;PROCTVAMIN&apos;  THEN T.TVA_MIN   WHEN &apos;PROCTVAMAX&apos;  THEN T.TVA_MAX
          WHEN &apos;PROCTVAREG&apos;  THEN T.TVA_REG   WHEN &apos;PROCTVAREG2&apos; THEN T.TVA_REG2
          WHEN &apos;PROCTVAREG3&apos; THEN T.TVA_REG3  WHEN &apos;PROCTVAREG4&apos; THEN T.TVA_REG4  WHEN &apos;PROCTVAREG5&apos; THEN T.TVA_REG5
        END tva,
        T.INCTVA * CASE L.TIP WHEN 1 THEN T.TVA_MED WHEN 2 THEN T.TVA_MIN WHEN 3 THEN T.TVA_MAX WHEN 4 THEN T.TVA_REG WHEN 5 THEN T.TVA_REG2 END/(T.TVA_MAX + T.TVA_MED + T.TVA_MIN + T.TVA_REG + T.TVA_REG2) INCTVA,
        L.ProcTva
      FROM TMP_JV_D300 T CROSS JOIN TMP_CONST_PROCTVA L
      WHERE T.TVALAINC = &apos;DA&apos; AND T.INCTVA &lt;&gt; 0
        AND CASE L.SIMBOL WHEN &apos;PROCTVAMED&apos; THEN T.TVA_MED WHEN &apos;PROCTVAMIN&apos; THEN T.TVA_MIN WHEN &apos;PROCTVAMAX&apos; THEN T.TVA_MAX WHEN &apos;PROCTVAREG&apos; THEN T.TVA_REG WHEN &apos;PROCTVAREG2&apos; THEN T.TVA_REG2  END &lt;&gt; 0
        AND (T.TVA_MAX + T.TVA_MED + T.TVA_MIN + T.TVA_REG + T.TVA_REG2) &lt;&gt; 0
    ) subsel;

    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_JC_D300&apos;;
    PKG_LIST_BASE_JURNCUMP.SetPerioada(
      pAn                  =&gt; pAn,
      pLuna                =&gt; pLuna,
      pTip                 =&gt; CASE pTip WHEN 0 THEN 3 WHEN 1 THEN 2 WHEN 2 THEN 1 ELSE 0 END,
      pSubunit             =&gt; CASE pSubunit WHEN 1 THEN 0 ELSE pSubunit END,
      pExclNoEconomicActiv =&gt; TRUE
    );
    PKG_LIST_BASE_JURNCUMP.ProcessList(&apos;TMP_JC_D300&apos;);

    INSERT INTO TMP_D39416_GEN  (
      TIPDOC, CODDOC, CODDOC1, INDEXLOCAL, AN, LUNA, SECTIUNE, TIPTRANZ, BAZA, TVA, PROCTVA, CURS, DATA,
      TIPI1,
      AUTOFACT, TIPFACTURA )
    SELECT
      tipdoc, coddoc, coddoc1, indexlocal, an, luna, &apos;I&apos; sectiune, 0 TipTranz, baza, platatva*tva/tvatot AS tva, /*tva*100/baza*/ ProcTva, 1 curs, data,
      CASE
        WHEN
          initializari = 1 AND
          Coalesce(
            (
              SELECT Max(r.tvalaincasare) KEEP (Dense_Rank LAST ORDER BY Coalesce(r.data_sfarsit, r.data_inceput), R.ID)
              FROM WINMADMIN.RTVAI_ISTORIC R
              WHERE R.COD_FISCAL = REGEXP_REPLACE(codfiscal,&apos;\D+&apos;, &apos;&apos;) AND Coalesce(r.data_sfarsit, r.data_inceput) &lt;= data
            ), tvaincasare, 0) = 1
        THEN 22
        WHEN tvaincasare_f = 1 THEN 22
        ELSE 21
      END TIPI1,
      0 AutoFact, 9 TipFactura
    FROM (
      -- facturi fara SplitTVA
      SELECT
        t.NAV_TIPDOC tipdoc, t.NAV_CODDOC coddoc, t.NAV_CODDOC1 CODDOC1, t.ORDDOC indexlocal, t.andoc an, t.lunadoc luna, t.DataDoc AS DATA,
        Coalesce(i.initializari, 0) initializari, t.codfiscal, i.tvaincasare, Coalesce(i.tvaincasare_f, 0) tvaincasare_f, l.ProcTva,
        CASE L.SIMBOL
          WHEN &apos;PROCTVAMED&apos;  THEN T.BAZA_MED  WHEN &apos;PROCTVAMIN&apos;  THEN T.BAZA_MIN  WHEN &apos;PROCTVAMAX&apos;  THEN T.BAZA_MAX
          WHEN &apos;PROCTVAREG&apos;  THEN T.BAZA_REG  WHEN &apos;PROCTVAREG2&apos; THEN T.BAZA_REG2
          WHEN &apos;PROCTVAREG3&apos; THEN T.BAZA_REG3 WHEN &apos;PROCTVAREG4&apos; THEN T.BAZA_REG4 WHEN &apos;PROCTVAREG5&apos; THEN T.BAZA_REG5
        END baza,
        CASE L.SIMBOL
          WHEN &apos;PROCTVAMED&apos;  THEN T.TVA_MED   WHEN &apos;PROCTVAMIN&apos;  THEN T.TVA_MIN   WHEN &apos;PROCTVAMAX&apos;  THEN T.TVA_MAX
          WHEN &apos;PROCTVAREG&apos;  THEN T.TVA_REG   WHEN &apos;PROCTVAREG2&apos; THEN T.TVA_REG2
          WHEN &apos;PROCTVAREG3&apos; THEN T.TVA_REG3  WHEN &apos;PROCTVAREG4&apos; THEN T.TVA_REG4  WHEN &apos;PROCTVAREG5&apos; THEN T.TVA_REG5
        END tva,
        T.TVA_MAX + T.TVA_MED + T.TVA_MIN + T.TVA_REG + T.TVA_REG2 + T.TVA_REG3 + T.TVA_REG4 + T.TVA_REG5 tvatot,
        T.PLATATVA
      FROM TMP_JC_D300 T
        INNER JOIN INTRARI I ON I.CODINTR = T.NAV_CODDOC AND I.TIPDOC = T.NAV_TIPDOC
        CROSS JOIN TMP_CONST_PROCTVA L
      WHERE T.TVALAINC = &apos;DA&apos; AND Coalesce(I.SPLITTVA, 0) = 0
      UNION ALL
      -- facturi cu SplitTVA
      SELECT
        t.NAV_TIPDOC tipdoc, t.NAV_CODDOC coddoc, t.NAV_CODDOC1 CODDOC1, Min(t.ORDDOC) indexlocal, t.andoc an, t.lunadoc luna, t.DataDoc AS DATA,
        Coalesce(i.initializari, 0) initializari, t.codfiscal, i.tvaincasare, Coalesce(i.tvaincasare_f, 0) tvaincasare_f, l.ProcTva,
        Sum(
          CASE L.SIMBOL
            WHEN &apos;PROCTVAMED&apos;  THEN T.BAZA_MED  WHEN &apos;PROCTVAMIN&apos;  THEN T.BAZA_MIN  WHEN &apos;PROCTVAMAX&apos;  THEN T.BAZA_MAX
            WHEN &apos;PROCTVAREG&apos;  THEN T.BAZA_REG  WHEN &apos;PROCTVAREG2&apos; THEN T.BAZA_REG2
            WHEN &apos;PROCTVAREG3&apos; THEN T.BAZA_REG3 WHEN &apos;PROCTVAREG4&apos; THEN T.BAZA_REG4 WHEN &apos;PROCTVAREG5&apos; THEN T.BAZA_REG5
          END
        ) baza,
        Sum(
          CASE L.SIMBOL
            WHEN &apos;PROCTVAMED&apos;  THEN T.TVA_MED   WHEN &apos;PROCTVAMIN&apos;  THEN T.TVA_MIN   WHEN &apos;PROCTVAMAX&apos;  THEN T.TVA_MAX
            WHEN &apos;PROCTVAREG&apos;  THEN T.TVA_REG   WHEN &apos;PROCTVAREG2&apos; THEN T.TVA_REG2
            WHEN &apos;PROCTVAREG3&apos; THEN T.TVA_REG3  WHEN &apos;PROCTVAREG4&apos; THEN T.TVA_REG4  WHEN &apos;PROCTVAREG5&apos; THEN T.TVA_REG5
          END
        ) tva,
        Sum(T.TVA_MAX + T.TVA_MED + T.TVA_MIN + T.TVA_REG + T.TVA_REG2 + T.TVA_REG3 + T.TVA_REG4 + T.TVA_REG5) TVATOT,
        Sum(T.PLATATVA) PLATATVA
      FROM TMP_JC_D300 T
        INNER JOIN INTRARI I ON I.CODINTR = T.NAV_CODDOC AND I.TIPDOC = T.NAV_TIPDOC
        CROSS JOIN TMP_CONST_PROCTVA L
      WHERE T.TVALAINC = &apos;DA&apos; AND Coalesce(I.SPLITTVA, 0) = 1
      GROUP BY
        t.NAV_TIPDOC, t.NAV_CODDOC, t.NAV_CODDOC1, t.andoc, t.lunadoc, t.DataDoc,
        Coalesce(i.initializari, 0), t.codfiscal, i.tvaincasare, Coalesce(i.tvaincasare_f, 0), l.ProcTva
    ) subsel
    WHERE baza &lt;&gt; 0 AND tva &lt;&gt; 0 AND tvatot &lt;&gt; 0 AND platatva &lt;&gt; 0;
  END IF;

  IF pAn*12+vLunaFin &gt;= 2025*12+8 THEN
    UPDATE TMP_D39416_GEN T
    SET proctva = CASE
                    WHEN TipTranz = 2 THEN  0
                    WHEN proctva &gt; 23.5 THEN 24
                    WHEN proctva &gt; 20.5 THEN 21
                    WHEN proctva &gt; 19.5 THEN 20
                    WHEN proctva &gt; 15   THEN 19
                    WHEN proctva &gt; 10   THEN 11
                    WHEN proctva &gt;  7   THEN  9
                    WHEN proctva &gt;  0   THEN  5
                    ELSE 0
                  END;
  ELSE
    UPDATE TMP_D39416_GEN T
    SET proctva = CASE
                    WHEN TipTranz = 2 THEN  0
                    WHEN proctva &gt; 22   THEN 24
                    WHEN proctva &gt; 19.5 THEN 20
                    WHEN proctva &gt; 14   THEN 19
                    WHEN proctva &gt;  7   THEN  9
                    WHEN proctva &gt;  0   THEN  5
                    ELSE 0
                  END;
  END IF;
  UPDATE TMP_D39416_GEN T
  SET cui     = UPPER(cui),
      codd394 = CASE
                  WHEN Coalesce(codd394,&apos;0&apos;) &lt;&gt; &apos;0&apos; THEN codd394
                  WHEN Coalesce(CATEGTXINV,0) = 0   THEN codd394
                  WHEN SECTIUNE = &apos;C&apos; THEN (SELECT To_Char(C.SimbolP) FROM CategArtTI C WHERE C.CODCATEGARTTI = T.CATEGTXINV)
                  WHEN SECTIUNE = &apos;D&apos; THEN (SELECT To_Char(C.SimbolN) FROM CategArtTI C WHERE C.CODCATEGARTTI = T.CATEGTXINV)
                  ELSE codd394
                END;

  DELETE FROM TMP_D39416_GEN T WHERE SECTIUNE IN (&apos;D&apos;)      AND     Coalesce(TipTranz,0) IN (1)    AND ProcTVA = 0;--TVA = 0;
  DELETE FROM TMP_D39416_GEN T WHERE SECTIUNE IN (&apos;E&apos;, &apos;F&apos;) AND NOT Coalesce(TipTranz,0) IN (1,2,8);
  DELETE FROM TMP_D39416_GEN T WHERE SECTIUNE IN (&apos;E&apos;, &apos;F&apos;) AND     Coalesce(TipTranz,0) IN (1,8)  AND ProcTVA = 0;--TVA = 0;
  DELETE FROM TMP_D39416_GEN T WHERE SECTIUNE IN (&apos;G&apos;)      AND NOT Coalesce(TipTranz,0) IN (10,11);
  DELETE FROM TMP_D39416_GEN T WHERE SECTIUNE IN (&apos;I&apos;)      AND TipI1 = 0;

  IF pAn = 2016 AND pLuna &gt;= 10 THEN
    MERGE INTO TMP_D39416_GEN T
    USING (
      SELECT tipdoc, coddoc
      FROM TMP_D39416_GEN
      WHERE SECTIUNE = &apos;D&apos; AND TipTranz IN (1, 2) AND PersFizica = 1
      GROUP BY TIPDOC, CODDOC
      HAVING Abs(Sum((baza+tva)*curs)) &lt;= 10000
    ) TG ON (tg.tipdoc = t.tipdoc AND tg.coddoc = t.coddoc)
    WHEN matched THEN UPDATE SET t.exceptie_d = 1;
  END IF;

  UPDATE TMP_D39416_GEN T
  SET CUIVALID = COALESCE((SELECT CASE A.CONTRIBUABIL WHEN 1 THEN 2 WHEN 0 THEN 3 WHEN -1 THEN 4 END FROM D39416_ANAF A WHERE A.CUI = T.CUI_NR AND A.DATA = T.DATA), cif_valid(cui))
  WHERE T.SECTIUNE IN (&apos;C&apos;,&apos;D&apos;) AND T.PersFizica &lt;&gt; 1 AND T.CUI IS NOT NULL AND T.CUIVALID IS NULL;

  UPDATE TMP_D39416_GEN
  SET CUIVALID = CASE WHEN CNP_VALID(cui) = 1 THEN 5 ELSE 6 END
  WHERE SECTIUNE IN (&apos;D&apos;) AND CUIVALID = 6 AND Length(cui) = 13;

  MERGE INTO TMP_D39416_GEN T1
  USING (
    SELECT Max(xROWID) KEEP (Dense_Rank First ORDER BY Abs(TVA) DESC, Abs(BAZA) DESC) xROWID
    FROM (
      SELECT
        tipdoc, coddoc, proctva,
        Max(ROWID) KEEP (Dense_Rank First ORDER BY Abs(Coalesce(TVA, 0)) DESC, Abs(Coalesce(BAZA, 0)) DESC, IndexLocal, CodDoc1) xROWID,
        Sum(Coalesce(TVA, 0)) TVA, Sum(Coalesce(BAZA, 0)) BAZA
      FROM TMP_D39416_GEN
      WHERE SECTIUNE IN (&apos;C&apos;, &apos;D&apos;, &apos;E&apos;, &apos;F&apos;) -- AM avut probleme cu documentele de la sectiunea I aduse din jurnalele de vanzari/cumparari
      GROUP BY tipdoc, coddoc, proctva
    )
    GROUP BY tipdoc, coddoc
  ) T2 ON (T1.ROWID = T2.xROWID)
  WHEN MATCHED THEN UPDATE SET T1.F = 1;

  IF pLEI THEN
    UPDATE TMP_D39416_GEN
    SET BAZA = BAZA*CURS,
        TVA  = TVA *CURS;

    UPDATE TMP_D39416_GEN
    SET CURS = 1;
  END IF;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I2G&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I4AUX&apos;;

  IF  pAn*12+pLuna &gt;= 2016*12+10 THEN

    INSERT INTO tmp_d39416i2g (
      tipdoc, coddoc, luna, carnetdoc, nrdoc, tipfactura,
      cui,
      denp,
      serie, startnr, endnr)
    SELECT DISTINCT
      t.tipdoc, t.coddoc, t.luna, Coalesce(t.carnetdoc, 0) carnetdoc, t.nrdoc, Abs(t.tipfactura),
      CASE
        WHEN t.tipfactura = 5 THEN t.cui_nr
        WHEN t.tipfactura = 6 THEN (SELECT REGEXP_REPLACE(cfi.codfiscal,&apos;\D+&apos;, &apos;&apos;) FROM npartcodfisc cfi WHERE cfi.codpart = i.codparttert AND cfi.principal = 1)
      END cui,
      CASE
        WHEN t.tipfactura = 5 THEN t.denp
        WHEN t.tipfactura = 6 THEN (SELECT p.den_part FROM npart p WHERE p.codpart = i.codparttert)
      END denp,
      dc.serie, dc.startnr, dc.endnr
    FROM TMP_D39416_GEN t
      LEFT JOIN DOCCARNETE DC ON DC.CodCarnet = t.CarnetDoc
      LEFT JOIN IESIRI     I  ON I.CODIES = T.CODDOC AND I.TIPDOC = T.TIPDOC
    WHERE T.Sectiune IN (&apos;C&apos;,&apos;D&apos;,&apos;E&apos;,&apos;F&apos;,&apos;X&apos;) AND T.TIPFACTURA &lt;&gt; 9
      --AND NOT (T.SECTIUNE = &apos;C&apos; AND T.TVA = 0 AND Coalesce(I.TVADISCOUNT, 0) = 0 AND T.TIPTRANZ IN (1,3,4,8));
      AND NOT (T.SECTIUNE = &apos;C&apos; AND T.PROCTVA = 0 AND Coalesce(I.TVADISCOUNT, 0) = 0 AND T.TIPTRANZ IN (1,3,4,8));

    INSERT INTO tmp_d39416i2g (
      tipdoc, coddoc, luna, carnetdoc, nrdoc, tipfactura,
      cui,
      denp,
      serie, startnr, endnr)
    SELECT DISTINCT
      t.tipdoc, t.coddoc, t.luna, Coalesce(t.carnetdoc, 0) carnetdoc, t.nrdoc, 1 tipfactura,
      NULL cui,
      NULL denp,
      dc.serie, dc.startnr, dc.endnr
    FROM TMP_D39416_GEN t
      INNER JOIN DOCCARNETE DC ON DC.CodCarnet = t.CarnetDoc
    WHERE T.Sectiune IN (&apos;C&apos;,&apos;D&apos;,&apos;E&apos;,&apos;F&apos;,&apos;X&apos;) AND T.TIPFACTURA &lt; 0 -- Storno care se incadreaza si in alte categorii (AUTOFACTURATE)
      --AND NOT (T.SECTIUNE = &apos;C&apos; AND T.TVA = 0 AND T.TIPTRANZ IN (1,3,4,8));
      AND NOT (T.SECTIUNE = &apos;C&apos; AND T.PROCTVA = 0 AND T.TIPTRANZ IN (1,3,4,8));

    INSERT INTO tmp_d39416i2g (
      tipdoc, coddoc, luna, carnetdoc, nrdoc,
      tipfactura,
      cui,
      denp,
      serie, startnr, endnr)
    SELECT
      tipdoc, coddoc, luna, carnetdoc, nrdoc,
      tipfactura,
      cui,
      denp,
      serie, startnr, endnr
    FROM (
      SELECT
        i.tipdoc, i.codies coddoc, i.luna, Coalesce(i.carnetdoc, 0) carnetdoc, i.nrdoc,
        CASE
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 2 THEN  6 -- emise de terti in numele persoanei impozabile
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 1 THEN  5 -- emise de beneficiari in numele persoanei impozabile
          WHEN i.TipTranzactie = 4                              THEN  3 -- AUTOFACTURARE
          WHEN vNrArtFaraJurnal = 0                             THEN  0 -- ALTE FACTURI UTILIZATE
          WHEN EXISTS (
                SELECT 1
                FROM iesiri1 i1
                  INNER JOIN nartobj o ON o.codobiect = i1.codobiect
                  LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol
                WHERE i1.codies = i.codies AND t3.codunic IS NULL
              )                                                 THEN  0 -- ALTE FACTURI UTILIZATE
          ELSE                                                       99 -- FACTURI - TVA0FaraJurnal
        END TipFactura,
        CASE
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 2 THEN (SELECT REGEXP_REPLACE(cfi.codfiscal,&apos;\D+&apos;, &apos;&apos;) FROM npartcodfisc cfi WHERE cfi.codpart = i.codparttert AND cfi.principal = 1)
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 1 THEN
            COALESCE (
              (SELECT REGEXP_REPLACE(cfd.codfiscal,&apos;\D+&apos;, &apos;&apos;) FROM npartcodfisc cfd WHERE cfd.cod_codfiscal = i.codfiscal),
              (SELECT REGEXP_REPLACE(a.codfiscal  ,&apos;\D+&apos;, &apos;&apos;) FROM nagenda a        WHERE a.codagenda = i.codlocatie),
              (SELECT REGEXP_REPLACE(cfi.codfiscal,&apos;\D+&apos;, &apos;&apos;) FROM npartcodfisc cfi WHERE cfi.codpart = i.partener AND cfi.principal = 1)
            )
        END cui,
        CASE
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 2 THEN (SELECT p.den_part FROM npart p WHERE p.codpart = i.codparttert)
          WHEN i.tipdoc IN (19, 22, 26) AND i.Emisadeclient = 1 THEN (SELECT p.den_part FROM npart p WHERE p.codpart = i.partener)
        END denp,
        dc.serie, dc.startnr, dc.endnr
      FROM iesiri i
        LEFT JOIN DOCCARNETE DC ON DC.CodCarnet = i.CarnetDoc
        LEFT JOIN nsubunit sub ON sub.codsubunit = i.subunitatea
      WHERE i.tipdoc IN (19, 22, 26)
        AND i.operat = 1 AND i.anulat = 0
        --AND i.valdoc = 0
        AND (i.valdoc = 0 OR i.tvadoc = 0)
        AND Coalesce(i.tiptranzactie, 0) &lt;&gt; 5
        AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
        AND (pSubunit = 1 OR i.subunitatea = pSubunit)
        AND Coalesce(SUB.NoEconomicActiv, 0) = 0
        AND Coalesce(i.TipFactura,0) &lt;&gt; 15
        AND i.TipTva IN (1, 2, 4, 7, 8, 9)
        AND NOT (i.TipTranzactie = 3 AND i.TipTva = 1 AND i.tvadoc = 0) -- Export                  -&gt; cu taxare normala si TVA 0
        AND NOT (i.TipTranzactie = 3 AND i.TipTva = 4)                  -- Export                  -&gt; locul livrarii/prestarii in afara Romaniei
        AND NOT (i.TipTranzactie = 2 AND i.TipTva = 1 AND i.tvadoc = 0) -- Livrare intracomunitara -&gt; cu taxare normala si TVA 0
        AND NOT (i.TipTranzactie = 2 AND i.TipTva = 2)                  -- Livrare intracomunitara -&gt; taxare inversa
        AND NOT (i.TipTranzactie = 2 AND i.TipTva = 4)                  -- Livrare intracomunitara -&gt; locul livrarii/prestarii in afara Romaniei
        AND NOT EXISTS (SELECT 1 FROM TMP_D39416_GEN t WHERE t.coddoc = i.codies AND t.tipdoc = i.tipdoc)
    ) subsel
    WHERE TipFactura &lt;&gt; 99;

    -- stef 28.11.2017 caz mai special pentru anulate fara linii
    INSERT INTO tmp_d39416i2g (
      tipdoc, coddoc, luna, carnetdoc, nrdoc, tipfactura,
      serie, startnr, endnr)
    SELECT
      i.tipdoc, i.codies, i.luna, Coalesce(i.carnetdoc, 0) carnetdoc, i.nrdoc, 2 TipFactura,
      dc.serie, dc.startnr, dc.endnr
    FROM iesiri i
      LEFT JOIN DOCCARNETE DC ON DC.CodCarnet = i.CarnetDoc
      LEFT JOIN nsubunit sub ON sub.codsubunit = i.subunitatea
    WHERE i.tipdoc IN (19, 26)
      AND i.anulat = 1
      AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
      AND (pSubunit = 1 OR i.subunitatea = pSubunit)
      AND Coalesce(SUB.NoEconomicActiv, 0) = 0
      AND NOT EXISTS (SELECT 1 FROM IESIRI1 I1 WHERE i1.codies = i.codies);

    INSERT INTO tmp_d39416i2g (
      tipdoc, coddoc, luna, carnetdoc, nrdoc, tipfactura,
      serie, startnr, endnr)
    SELECT
      i.tipdoc, i.codies, i.luna, Coalesce(i.carnetdoc, 0) carnetdoc, i.nrdoc, 2 TipFactura,
      dc.serie, dc.startnr, dc.endnr
    FROM (
      SELECT DISTINCT codies
      FROM (
        SELECT
          i.codies,
          CASE
            WHEN i.AutoFact =1                        THEN &apos;X&apos; -- Facturi AUTOFACTURATE
            WHEN i.factsimplif = 1                    THEN &apos;I&apos; -- Facturi SIMPLIFICATE
            WHEN i.PersFizica = 1                     THEN &apos;D&apos; -- Neplatitori de TVA
            WHEN i.CUI IS NULL                        THEN &apos;D&apos; -- Neplatitori de TVA
            WHEN i.CUI = i.CUI_NR AND i.stat_ue = 1   THEN &apos;D&apos; -- Neplatitori de TVA
            WHEN SubStr(i.CUI,1,2) = &apos;RO&apos;             THEN &apos;C&apos; -- Platitori de TVA
            WHEN i.stat_ue = 1                        THEN &apos;E&apos; -- UE
            WHEN i.stat_ue = 0                        THEN &apos;F&apos; -- NonUE
          END SECTIUNE,
          CASE
            WHEN i.TipTva = 1                         THEN 1
            WHEN i.tiptranzactie = 2 AND i.TipTva = 2 THEN 1
            WHEN i.TipTva IN (7, 8)                   THEN 2
            WHEN i.TipTva = 2                         THEN 7
          END TipTranz,
          CASE
            WHEN i.TipTva = 2 AND i.tiptranzactie &lt;&gt; 2 THEN 0
            WHEN i1.cant*i1.pu = 0 THEN 0
            ELSE i1.tva * Coalesce(i1.coefdiscmaj,1) * i1.pretorig / i1.pu
          END tva
        FROM (
          SELECT
            i.codies, i.TipTva, i.TipTranzactie,
            Coalesce(i.factsimplif,0) factsimplif,
            Upper(REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\W+&apos;, &apos;&apos;)) CUI,
            REGEXP_REPLACE(COALESCE(cfd.codfiscal,a.codfiscal,cfi.codfiscal),&apos;\D+&apos;, &apos;&apos;) CUI_NR,
            Coalesce(p.persoanafizica,0) persfizica,
            coalesce(t.statcomunitar, 0) stat_ue,
            CASE WHEN i.TipTranzactie = 4 THEN 1 ELSE 0 END AutoFact
          FROM iesiri i
            LEFT JOIN npart p ON p.codpart = i.partener
            LEFT JOIN nagenda a ON a.codagenda = i.codlocatie
            LEFT JOIN nlocalit l ON l.codlocalit = a.codlocalit
            LEFT JOIN njudet j ON j.codjudet = l.codjudet
		        LEFT JOIN ntari t ON t.codtara = l.codtara
            LEFT JOIN npartcodfisc cfd ON cfd.cod_codfiscal = i.codfiscal
            LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
            LEFT JOIN nsubunit sub ON sub.codsubunit = i.subunitatea
          WHERE i.tipdoc IN (19,26)
            AND i.anulat = 1
            AND i.an = pAn AND i.luna BETWEEN vLunaIni AND vLunaFin
            AND (pSubunit = 1 OR i.subunitatea = pSubunit)
            AND i.TipTva IN (1, 2, 7, 8)
            AND Coalesce(SUB.NoEconomicActiv, 0) = 0
        ) i
          INNER JOIN iesiri1 i1 ON i1.codies = i.codies
          INNER JOIN nartobj o ON o.codobiect = i1.codobiect
          LEFT JOIN tmp_manevra3 t3 ON t3.codunic = o.codarticol --articole conform const TVA0FaraJurnal
        WHERE i1.tiplinie IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) AND t3.codunic IS NULL
          --AND i1.cant*i1.pu &lt;&gt; 0
      )
      WHERE NOT ( SECTIUNE IN (&apos;E&apos;, &apos;F&apos;) AND     Coalesce(TipTranz,0) IN (1  ) AND TVA = 0 )
        AND NOT ( SECTIUNE IN (&apos;E&apos;, &apos;F&apos;) AND NOT Coalesce(TipTranz,0) IN (1,2)  )
    ) tmp
      INNER JOIN iesiri i ON i.codies = tmp.codies
      LEFT  JOIN DOCCARNETE DC ON DC.CodCarnet = i.CarnetDoc
      LEFT  JOIN nsubunit sub ON sub.codsubunit = i.subunitatea;

      BEGIN
        SELECT Min(NrDoc), Max(NrDoc) INTO vCarnetNullStart, vCarnetNullEnd FROM TMP_D39416I2G WHERE CARNETDOC = 0;
        UPDATE TMP_D39416I2G SET STARTNR = vCarnetNullStart, ENDNR = vCarnetNullEnd WHERE CARNETDOC = 0;
      EXCEPTION WHEN No_Data_Found THEN
        NULL;
      END;

      IF    vD394StartNrFact = 2 THEN
        dD394StartNrFact := To_Date(&apos;01.01.&apos;||To_Char(pAn,&apos;fm0000&apos;), &apos;dd.mm.yyyy&apos;);
      ELSIF vD394StartNrFact = 3 THEN
        vLunaStartAnContab := Coalesce(pkg_categconst.GetValConstanta(&apos;LunaStartAnContab&apos;, pAn, vLunaFin),&apos;1&apos;);

        IF vLunaStartAnContab &gt; vLunaIni
        THEN vAnContab := pAn-1;
        ELSE vAnContab := pAn;
        END IF;

        dD394StartNrFact := To_Date(&apos;01.&apos;||To_Char(vLunaStartAnContab,&apos;fm00&apos;)||&apos;.&apos;||To_Char(vAnContab,&apos;fm0000&apos;), &apos;dd.mm.yyyy&apos;);
      END IF;

      IF dD394StartNrFact IS NOT NULL THEN
        OPEN s_cur;
        LOOP
          FETCH s_cur BULK COLLECT INTO fetch_tab LIMIT 100;
          FORALL i IN 1..fetch_tab.COUNT UPDATE tmp_d39416i2g SET STARTNR = fetch_tab(i).STARTNR WHERE CARNETDOC = fetch_tab(i).CARNETDOC;
          EXIT WHEN s_cur%NOTFOUND;
        END LOOP;
        CLOSE s_cur;
      END IF;

    IF pAn = 2016 THEN
      UPDATE tmp_d39416i2g SET startnr = NULL;
    END IF;

    INSERT INTO tmp_d39416i4aux (tipdoc, coddoc, coddoc1, codcaensec, tipoper, cantcaen, cantlin, baza, tva, proctva)
    SELECT t.tipdoc, t.coddoc, t.coddoc1, g.codcaensec, 1 TipOper, l1.cant cantcaen, i1.cant cantlin, t.baza*t.curs, t.tva*t.curs, t.proctva
    FROM TMP_D39416_GEN t
      INNER JOIN iesiri1 i1 ON i1.codies1 = t.coddoc1
      INNER JOIN livr1   l1 ON l1.codies1 = t.coddoc1
      INNER JOIN livr    l  ON l.codlivr = l1.codlivr AND l.codies = t.coddoc AND l.tiplivr = t.tipdoc
      LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN nir     n  ON n.codnir = ns.codnir
      LEFT  JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
      LEFT  JOIN ngest   g  ON g.codgest = Coalesce(lv.gest, n.gest)
    WHERE t.TipDoc IN (16, 19, 21)
      AND i1.tiplinie = &apos;=&apos;
      AND Coalesce(g.codcaensec, 0) &lt;&gt; 0
      AND NOT (t.TipDoc = 16 AND Coalesce(lv.codioart, ns.codioart) IN (SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ContIncasareFactura&apos;  ,pAn,pLuna),&apos;0&apos;) FROM dual)) ;

    INSERT INTO tmp_d39416i4aux (tipdoc, coddoc, coddoc1, codcaensec, tipoper, cantcaen, cantlin, baza, tva, proctva)
    SELECT t.tipdoc, t.coddoc, t.coddoc1, g.codcaensec, 1 TipOper, l1.cant*i1.cant/ae1.cant cantcaen, i1.cant cantlin, t.baza*t.curs, t.tva*t.curs, t.proctva
    FROM TMP_D39416_GEN t
      INNER JOIN iesiri1 i1   ON i1.codies1 = t.coddoc1
      INNER JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      INNER JOIN iesiri1 ae1  ON ae1.codies1 = ilae.codlinieaviz
      INNER JOIN iesiri  ae   ON ae.codies = ae1.codies
      INNER JOIN livr    l    ON l.codies = ae.codies AND l.tiplivr = ae.tipdoc
      INNER JOIN livr1   l1   ON l1.codlivr = l.codlivr AND l1.codies1 = ae1.codies1
      LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv   ON lv.codlivr1 = l1.codlivr1
      LEFT  JOIN nir     n    ON n.codnir = ns.codnir
      LEFT  JOIN ngest   g    ON g.codgest = Coalesce(lv.gest, n.gest)
    WHERE t.TipDoc IN (26)
      AND i1.tiplinie = &apos;=&apos;
      AND Coalesce(g.codcaensec, 0) &lt;&gt; 0;

    INSERT INTO tmp_d39416i4aux (tipdoc, coddoc, coddoc1, codcaensec, tipoper, cantcaen, cantlin, baza, tva, proctva)
    SELECT t.tipdoc, t.coddoc, t.coddoc1, g.codcaensec, 2 TipOper, i1.cant cantcaen, i1.cant cantlin, t.baza*t.curs, t.tva*t.curs, t.proctva
    FROM TMP_D39416_GEN t
      INNER JOIN iesiri1 i1 ON i1.codies1 = t.coddoc1
      LEFT JOIN ngest g ON g.codgest = i1.gestact
    WHERE t.TipDoc IN (16, 19, 21, 26)
      AND i1.tiplinie &lt;&gt; &apos;=&apos;
      AND Coalesce(g.codcaensec, 0) &lt;&gt; 0;
  END IF;
END;

PROCEDURE CuratareANAF IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM D39416_ANAF WHERE CONTRIBUABIL = -1;
  COMMIT;
END;

PROCEDURE ExtraANAF IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416_ANAF&apos;;

  INSERT INTO TMP_D39416_ANAF (CUI, DATA, CONTRIBUABIL, STARE)
  SELECT DISTINCT T.CUI_NR, T.DATA, Max(CASE WHEN T.SECTIUNE = &apos;C&apos; THEN 1 ELSE 0 END) CONTRIBUABIL, 0 AS STARE
  FROM TMP_D39416_GEN T
  WHERE T.CUIVALID = 1
    AND T.CUI_NR &lt;= 2147483647 -- STEF 23.04.2021 Se pare ca Validarea pe ANAF e limitata la INT32 -&gt; 2^10-1
    AND NOT EXISTS(SELECT 1 FROM D39416_ANAF A WHERE T.CUI_NR = A.CUI AND T.DATA = A.DATA)
  GROUP BY T.CUI_NR, T.DATA;
END;

PROCEDURE CuiANAF (pCui VARCHAR2, pData VARCHAR2) IS
  sCUI  VARCHAR2(30);
  nCUI  VARCHAR2(30);
  dData DATE;
BEGIN
  DELETE FROM TMP_D39416_ANAF;
  dData := To_Date(pData, &apos;dd.mm.yyyy&apos;);
  sCUI  := Upper(REGEXP_REPLACE(pCui,&apos;\W+&apos;, &apos;&apos;));
  nCui  := REGEXP_REPLACE(sCUI,&apos;\D+&apos;, &apos;&apos;);
  IF CASE WHEN nCui IS NULL THEN 0 WHEN SubStr(sCUI,1,2) = &apos;RO&apos; OR sCUI = nCui THEN cif_valid(nCui) ELSE 0 END = 1 AND pData &lt;= Trunc(SYSDATE)
  THEN
    INSERT INTO TMP_D39416_ANAF (CUI, DATA, CONTRIBUABIL, STARE)
    SELECT C.CUI, C.DATA, A.CONTRIBUABIL, CASE WHEN A.CONTRIBUABIL IS NULL THEN 0 ELSE 1 END STARE
    FROM (SELECT nCui CUI, dData DATA FROM DUAL) C LEFT JOIN D39416_ANAF A ON A.CUI = C.CUI AND A.DATA = C.DATA;
  END IF;
END;

PROCEDURE Append_D39416_ANAF_Autonom(pCUI NUMBER, pDATA DATE, pCONTRIBUABIL NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO D39416_ANAF (CUI, DATA, CONTRIBUABIL) VALUES (pCUI, pDATA, pCONTRIBUABIL);
  COMMIT;
END;

PROCEDURE DoneANAF IS
  vCount INTEGER;
BEGIN
  -- pe PG ar trebui sa mearga insert direct ca nu e nevoie de tranzactie Autonoma (adica nu e nevoie de modificare)
  FOR vRec IN (
    SELECT T.CUI, T.DATA, T.CONTRIBUABIL
    FROM TMP_D39416_ANAF T
    WHERE STARE = 1 AND NOT EXISTS(SELECT 1 FROM D39416_ANAF A WHERE T.CUI = A.CUI AND T.DATA = A.DATA)
  ) LOOP
    Append_D39416_ANAF_Autonom(vRec.CUI, vRec.DATA, vRec.CONTRIBUABIL);
  END LOOP;
END;

PROCEDURE ActualizGEN IS
BEGIN
  UPDATE TMP_D39416_GEN T
  SET CUIVALID = Coalesce((SELECT CASE A.CONTRIBUABIL WHEN 1 THEN 2 WHEN 0 THEN 3 WHEN -1 THEN 4 END FROM D39416_ANAF A WHERE A.CUI = T.CUI_NR AND A.DATA = T.DATA), T.CUIVALID);
END;

PROCEDURE GOLESTE_TMP IS
BEGIN

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I4&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I3&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I2A&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416I&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416G3&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416G2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416G1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416G&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416UES2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416UE&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416NS2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416N&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RNS3&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RNS2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RN1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RN0&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RN&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RPS3&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RPS2&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RP1&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416RP&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416R&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_D39416_REZ&apos;;

END;

FUNCTION  GET_VAL_ACHIZ (pTipDoc IN NUMBER, pCodDoc IN NUMBER, pCodDoc1  IN NUMBER) RETURN NUMBER IS
  vVal NUMBER;
BEGIN
  IF pTipDoc = 19 THEN
    SELECT Sum( l1.cant * Coalesce ( lv.pretachiz, ns.pret - Coalesce(ns.adaos,0),0 ) )
    INTO vVal
    FROM livr l
      INNER JOIN livr1   l1 ON l1.codlivr = l.codlivr
      LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
    WHERE l.tiplivr = pTipDoc AND l.CodIes = pCodDoc AND l1.CodIes1 = pCodDoc1;
  ELSIF pTipDoc = 26 THEN
    SELECT Sum( l1.cant * Coalesce ( lv.pretachiz, ns.pret - Coalesce(ns.adaos,0),0 ) ) * Max(i1.cant) / Sum(l1.cant)
    INTO vVal
    FROM iesiri1 i1
      INNER JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      INNER JOIN iesiri1 ae1  ON ae1.codies1 = ilae.codlinieaviz
      INNER JOIN iesiri  ae   ON ae.codies = ae1.codies
      INNER JOIN livr    l    ON l.codies = ae.codies AND l.tiplivr = ae.tipdoc
      INNER JOIN livr1   l1   ON l1.codlivr = l.codlivr AND l1.codies1 = ae1.codies1
      LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv   ON lv.codlivr1 = l1.codlivr1
    WHERE i1.CodIes1 = pCodDoc1;
  END IF;
  RETURN Coalesce(vVal,0);
END;

PROCEDURE Generare( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER, pPas INTEGER DEFAULT 0, pNerezident INTEGER DEFAULT 0) IS
  vCodD39416     INTEGER;
  vPas           INTEGER;
  pUsername      VARCHAR2(100);
  pAlteFirmeD394 VARCHAR2(3000);
  bSaveTMP       BOOLEAN := FALSE;
BEGIN
  vPas := Coalesce(pPas,0);-- stef - firedac-ul chiar daca am DEFAULT 0 trimite tot NULL
  IF vPas IN (0, 1) THEN
    UmpleGEN(
      pTip        =&gt; pTip,
      pLuna       =&gt; pLuna,
      pAn         =&gt; pAn,
      pSubunit    =&gt; pSubunit,
      pLei        =&gt; TRUE
    );

    pAlteFirmeD394 := pkg_categconst.GetValConstanta(&apos;AlteFirmeD394&apos;  ,pAn, pLuna);
    pAlteFirmeD394 := REPLACE(pAlteFirmeD394,&apos; &apos;, &apos;&apos;);
    pAlteFirmeD394 := NULLIF(pAlteFirmeD394, &apos;&apos;);
    IF pAlteFirmeD394 IS NOT NULL THEN
      SELECT USERNAME INTO pUSERNAME FROM user_users;

      pAlteFirmeD394 := Upper(pAlteFirmeD394);
      pAlteFirmeD394 := &apos;,&apos;||pAlteFirmeD394||&apos;,&apos;;
      Winmadmin.PKG_USERFIRME.POPULEAZA_D39416_EXTERNE(pUSERNAME, pAlteFirmeD394, pTip, pLuna, pAn, pSubunit);
    END IF;

    -- Cf. ANAF limitat la 75 de caractere in D394, iar in Baza noastra de date limita e de 100 caractere
    --UPDATE TMP_D39416_GEN SET STRP = SUBSTR(STRP,1,75) WHERE Length(STRP) &gt; 75;
    UPDATE TMP_D39416_GEN SET STRP = CAST(STRP AS VARCHAR2(75)) WHERE LengthB(STRP) &gt; 75 ; -- schimbat in CAST deoarece exista riscul caracterelor multi-byte (cu diacritice)
--BEGIN EXECUTE IMMEDIATE &apos;DROP   TABLE SAV_TMP_D39416_GEN PURGE&apos;                           EXCEPTION WHEN OTHERS THEN NULL; END;
--BEGIN EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_TMP_D39416_GEN AS SELECT * FROM TMP_D39416_GEN&apos; EXCEPTION WHEN OTHERS THEN NULL; END;
  END IF;

  IF vPas IN (0, 2) THEN
    IF vPas = 2 THEN
      UPDATE TMP_D39416_GEN T
      SET CUIVALID = COALESCE((SELECT CASE A.CONTRIBUABIL WHEN 1 THEN 2 WHEN 0 THEN 3 WHEN -1 THEN 4 END FROM D39416_ANAF A WHERE A.CUI = T.CUI_NR AND A.DATA = T.DATA), T.CUIVALID)
      WHERE T.SECTIUNE IN (&apos;C&apos;,&apos;D&apos;) AND T.PersFizica &lt;&gt; 1 AND T.CUI IS NOT NULL AND T.CUIVALID = 1;
    END IF;

    IF bSaveTMP THEN
      FOR vRec IN (
        SELECT &apos;TMP_D39416_GEN&apos; SURSA FROM DUAL
      ) LOOP
        BEGIN
          EXECUTE IMMEDIATE &apos;DROP TABLE SAV_&apos;||vRec.SURSA||&apos; PURGE&apos;;
        EXCEPTION
          WHEN OTHERS THEN NULL;
        END;
        EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_&apos;||vRec.SURSA||&apos; AS SELECT * FROM &apos;||vRec.SURSA;
      END LOOP;
    END IF;

    BEGIN
      SELECT CodD39416 INTO vCodD39416 FROM TMP_D39416;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN vCodD39416 := 0;
    END;

    GOLESTE_TMP;

    INSERT INTO TMP_D39416RPS2 (
      codd39416rps2, codd39416,
      tiptranz, regscutire, proctva, cui, denp,
      f, bi, marja, tva, tvamarja,
      cuivalid)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, regscutire, proctva, cui), vCodD39416,
      tiptranz, regscutire, proctva, cui, Min(denp),
      Sum(F) F, Round(Sum(BI)) BI, Round(Sum(Marja)) Marja, Round(Sum(TVA)) TVA, Round(Sum(TvaMarja)) TvaMarja,
      Max(cuivalid) cuivalid
    FROM (
      SELECT
        t.tipdoc, t.coddoc, t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp,
        t.F, t.BAZA + CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END AS BI,
        CASE WHEN t.tiptranz = 2 THEN t.BAZA - PKG_D39416.GET_VAL_ACHIZ (t.tipdoc, t.coddoc, t.coddoc1) ELSE 0 END Marja,
        CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END TvaMarja,
        CASE WHEN t.tiptranz = 2 THEN 0 ELSE t.TVA END TVA,
        t.cuivalid
      FROM TMP_D39416_GEN t
      WHERE t.SECTIUNE = &apos;C&apos;
        AND NOT (t.proctva = 0 AND t.tiptranz IN (1,3,4,8))
    ) subs
    GROUP BY tiptranz, regscutire, proctva, cui;

    INSERT INTO TMP_D39416RP (
      codd39416rp, codd39416,
      tiptranz, proctva,
      f, bi, tva)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, proctva), vCodD39416,
      tiptranz, proctva,
      Sum(f) f, Round(Sum(bi)) bi, Round(Sum(tva)) tva
    FROM TMP_D39416RPS2
    GROUP BY tiptranz, proctva;

    INSERT INTO TMP_D39416RPS3 (
      codd39416rps3, codd39416,
      tiptranz, proctva, cui, categtxinv, codd394,
      f, bi, tva
    )
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, proctva, cui, categtxinv, codd394), vCodD39416,
      tiptranz, proctva, cui, categtxinv, codd394,
      Sum(F) F, Round(Sum(bi)) bi, Round(Sum(tva)) tva
    FROM (
      SELECT
        t.tiptranz, t.proctva, t.cui, t.categtxinv, t.codd394,
        t.F, t.BAZA AS BI, t.TVA AS TVA
      FROM TMP_D39416_GEN t
      WHERE t.SECTIUNE = &apos;C&apos;
        AND NOT (t.proctva = 0 AND t.tiptranz IN (1,3,4,8))
        AND t.categtxinv IS NOT NULL
        AND t.tiptranz IN (7,8)
    ) subs
    GROUP BY tiptranz, proctva, cui, categtxinv, codd394;

    INSERT INTO TMP_D39416RP1 (
      codd39416rp1, codd39416,
      tiptranz, proctva, categtxinv,
      f, bi, tva)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, proctva, categtxinv), vCodD39416,
      tiptranz, proctva, categtxinv,
      Sum(f) f, Sum(bi) bi, Sum(tva) tva
    FROM TMP_D39416RPS3
    GROUP BY tiptranz, proctva, categtxinv;

    INSERT INTO TMP_D39416R (
      codd39416r, codd39416,
      proctva,
      livrarif,
      livrarib,
      livraritva,
      achizf,
      achizb,
      achiztva,
      achizif,
      achizib,
      achizitva)
    SELECT
      -Row_Number() OVER (ORDER BY proctva), vCodD39416,
      proctva,
      Sum(CASE WHEN TipTranz IN (1)   THEN f   ELSE 0 END) LivrariF,
      Sum(CASE WHEN TipTranz IN (1)   THEN bi  ELSE 0 END) LivrariB,
      Sum(CASE WHEN TipTranz IN (1)   THEN tva ELSE 0 END) LivrariTVA,
      Sum(CASE WHEN TipTranz IN (3,8) THEN f   ELSE 0 END) AchizF,
      Sum(CASE WHEN TipTranz IN (3,8) THEN bi  ELSE 0 END) AchizB,
      Sum(CASE WHEN TipTranz IN (3,8) THEN tva ELSE 0 END) AchizTVA,
      Sum(CASE WHEN TipTranz IN (4)   THEN f   ELSE 0 END) AchizIF,
      Sum(CASE WHEN TipTranz IN (4)   THEN bi  ELSE 0 END) AchizIB,
      Sum(CASE WHEN TipTranz IN (4)   THEN tva ELSE 0 END) AchizITVA
    FROM TMP_D39416RP
    GROUP BY proctva;

    INSERT INTO TMP_D39416RNS2 (
      codd39416rns2, codd39416,
      tiptranz, regscutire, proctva, cui, denp, codlocalit, strp, nrp, blp, app, tipdoc,
      f, bi, marja, tva, tvamarja,
      cuivalid,
      locp, judp, tarap, sajudp)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, regscutire, proctva, cui, denp, locp, judp, tarap, strp, nrp, blp, app, tipdocrn), vCodD39416,
      tiptranz, regscutire, proctva, cui, denp, Max(codlocalit), strp, nrp, blp, app, tipdocrn,
      Sum(F) F, Round(Sum(BI)) BI, Round(Sum(Marja)) Marja, Round(Sum(TVA)) TVA, Round(Sum(TvaMarja)) TvaMarja,
      Max(cuivalid) cuivalid,
      locp, judp, tarap, Max(sajudp)
    FROM (
      SELECT
        t.tipdoc, t.coddoc, t.tiptranz, t.regscutire, CASE WHEN t.tiptranz = 9 THEN 0 ELSE t.proctva END proctva,
        t.cui, t.denp, t.codlocalit, t.strp, t.nrp, t.blp, t.app, t.tipdocrn,
        t.F, t.BAZA + CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END AS BI,
        CASE WHEN t.tiptranz = 2 THEN t.BAZA - PKG_D39416.GET_VAL_ACHIZ (t.tipdoc, t.coddoc, t.coddoc1) ELSE 0 END Marja,
        CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END TvaMarja,
        CASE WHEN t.tiptranz = 2 THEN 0 ELSE t.TVA END TVA,
        t.cuivalid,
        t.locp, t.judp, t.tarap, t.sajudp
      FROM TMP_D39416_GEN t
      WHERE t.SECTIUNE = &apos;D&apos; AND t.tiptranz IN (1,2,9) AND t.exceptie_d = 0
    ) subs
    GROUP BY tiptranz, regscutire, proctva, cui, denp, locp, judp, tarap, strp, nrp, blp, app, tipdocrn;

    INSERT INTO TMP_D39416RN0 (
      codd39416rn0, codd39416,
      l_pf_f,
      l_pf_bi24, l_pf_tva24,
      l_pf_bi21, l_pf_tva21,
      l_pf_bi20, l_pf_tva20,
      l_pf_bi19, l_pf_tva19,
      l_pf_bi11, l_pf_tva11,
      l_pf_bi9,  l_pf_tva9,
      l_pf_bi5,  l_pf_tva5,
      ls_pf_f, ls_pf_val
    )
    SELECT
      -1, vCodD39416,
      Sum(CASE WHEN tiptranz = 1 THEN f ELSE 0 END) l_pf_f,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 24 THEN baza ELSE 0 END)) l_pf_bi24, Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 24 THEN tva ELSE 0 END)) l_pf_tva24,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 21 THEN baza ELSE 0 END)) l_pf_bi21, Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 21 THEN tva ELSE 0 END)) l_pf_tva21,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 20 THEN baza ELSE 0 END)) l_pf_bi20, Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 20 THEN tva ELSE 0 END)) l_pf_tva20,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 19 THEN baza ELSE 0 END)) l_pf_bi19, Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 19 THEN tva ELSE 0 END)) l_pf_tva19,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 11 THEN baza ELSE 0 END)) l_pf_bi11, Round(Sum(CASE WHEN tiptranz = 1 AND proctva = 11 THEN tva ELSE 0 END)) l_pf_tva11,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva =  9 THEN baza ELSE 0 END)) l_pf_bi9 , Round(Sum(CASE WHEN tiptranz = 1 AND proctva =  9 THEN tva ELSE 0 END)) l_pf_tva9 ,
      Round(Sum(CASE WHEN tiptranz = 1 AND proctva =  5 THEN baza ELSE 0 END)) l_pf_bi5 , Round(Sum(CASE WHEN tiptranz = 1 AND proctva =  5 THEN tva ELSE 0 END)) l_pf_tva5 ,
      Round(Sum(CASE WHEN tiptranz = 2 THEN f ELSE 0 END)) ls_pf_f, Round(Sum(CASE WHEN tiptranz = 2 THEN baza+tva ELSE 0 END)) ls_pf_val
    FROM TMP_D39416_GEN
    WHERE SECTIUNE = &apos;D&apos; AND tiptranz IN (1, 2) AND PersFizica = 1 AND exceptie_d = 1;

    INSERT INTO TMP_D39416RN1 (
      codd39416rn1, codd39416,
      tiptranz, proctva, tipdoc, categtxinv,
      f, valoare
    )
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, tipdoc, categtxinv), vCodD39416,
      tiptranz, 0 proctva, tipdoc, categtxinv,
      Sum(F) F, Round(Sum(bi)) valoare
    FROM (
      SELECT
        tiptranz, tipdocrn tipdoc, categtxinv,
        F, BAZA AS BI
      FROM TMP_D39416_GEN
      WHERE SECTIUNE = &apos;D&apos; AND Coalesce(categtxinv,0) &lt;&gt; 0 AND tiptranz IN (9) AND PersFizica = 1 AND exceptie_d = 0
    ) subs
    GROUP BY tiptranz, tipdoc, categtxinv;

    INSERT INTO TMP_D39416RNS3 (
      codd39416rns3, codd39416, codd39416rn1, codd39416rns2, codd394,
      f, valoare,
      tiptranz, tipdoc, categtxinv
    )
    SELECT
      -Row_Number() OVER (ORDER BY codd39416rn1 DESC, codd39416rns2 DESC), vCodD39416, codd39416rn1, codd39416rns2, codd394,
      Sum(F) F, Round(Sum(bi)) Valoare,
      Min(tiptranz), Min(tipdoc), Min(categtxinv)
    FROM (
      SELECT
        TRN1.codd39416rn1, TRNS2.codd39416rns2, TG.codd394,
        TG.F, TG.BAZA AS BI,
        TG.tiptranz, TRN1.tipdoc, TG.categtxinv
      FROM TMP_D39416_GEN TG
        LEFT JOIN TMP_D39416RNS2 TRNS2 ON TRNS2.tiptranz              = TG.tiptranz               AND
                                          Coalesce(TRNS2.cui  ,&apos; &apos;)   = Coalesce(TG.cui   ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.denp ,&apos; &apos;)   = Coalesce(TG.denp  ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.locp ,&apos; &apos;)   = Coalesce(TG.locp  ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.judp ,&apos; &apos;)   = Coalesce(TG.judp  ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.tarap,&apos; &apos;)   = Coalesce(TG.tarap ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.strp ,&apos; &apos;)   = Coalesce(TG.strp  ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.nrp  ,&apos; &apos;)   = Coalesce(TG.nrp   ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.blp  ,&apos; &apos;)   = Coalesce(TG.blp   ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.app  ,&apos; &apos;)   = Coalesce(TG.app   ,&apos; &apos;)   AND
                                          Coalesce(TRNS2.tipdoc, 0)   = Coalesce(TG.tipdocrn,0)
        LEFT JOIN TMP_D39416RN1  TRN1  ON TRN1.tiptranz               = TG.tiptranz               AND
                                          Coalesce(TRN1.tipdoc,0)     = Coalesce(TG.tipdocrn,0)   AND
                                          Coalesce(TRN1.categtxinv,0) = Coalesce(TG.categtxinv,0)
      WHERE tg.SECTIUNE = &apos;D&apos; AND Coalesce(tg.categtxinv,0) &lt;&gt; 0 AND tg.tiptranz IN (9) AND tg.PersFizica = 1 AND exceptie_d = 0
    ) subs
    GROUP BY codd39416rn1, codd39416rns2, codd394;

    -- stef 21.12.2016 Probleme rotunjiri D39416RN1 achizitii
    UPDATE TMP_D39416RN1 RN1 SET VALOARE = (SELECT Sum(Valoare) FROM TMP_D39416RNS3 RNS3 WHERE RNS3.CODD39416RN1 = RN1.CODD39416RN1);

    INSERT INTO TMP_D39416RN (
      codd39416rn, codd39416,
      tiptranz, proctva, tipdoc,
      f, bi, tva)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, proctva, tipdoc), vCodD39416,
      tiptranz, proctva, tipdoc,
      Sum(f) f, Round(Sum(bi)) bi, Round(Sum(tva)) tva
    FROM TMP_D39416RNS2
    GROUP BY tiptranz, proctva, tipdoc;

    INSERT INTO TMP_D39416UES2 (
      codd39416ues2, codd39416,
      tiptranz, regscutire, proctva, cui, denp,
      f, bi, marja, tva, tvamarja )
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, regscutire, proctva, cui), vCodD39416,
      tiptranz, regscutire, proctva, cui, Min(denp),
      Sum(F) F, Round(Sum(BI)) BI, Round(Sum(Marja)) Marja, Round(Sum(TVA)) TVA, Round(Sum(TvaMarja)) TvaMarja
    FROM (
      SELECT
        t.tipdoc, t.coddoc, t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp,
        t.F, t.BAZA + CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END AS BI,
        CASE WHEN t.tiptranz = 2 THEN t.BAZA - PKG_D39416.GET_VAL_ACHIZ (t.tipdoc, t.coddoc, t.coddoc1) ELSE 0 END Marja,
        CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END TvaMarja,
        CASE WHEN t.tiptranz = 2 THEN 0 ELSE t.TVA END TVA
      FROM TMP_D39416_GEN t
      WHERE SECTIUNE = &apos;E&apos;
    ) subs
    GROUP BY tiptranz, regscutire, proctva, cui;

    INSERT INTO TMP_D39416UE (
      codd39416ue, codd39416,
      tiptranz, proctva,
      f, bi, tva)
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, proctva), vCodD39416,
      tiptranz, proctva,
      Sum(f) f, Round(Sum(bi)) bi, Round(Sum(tva)) tva
    FROM TMP_D39416UES2
    GROUP BY tiptranz, proctva;

    INSERT INTO TMP_D39416NS2 (
      codd39416ns2, codd39416,
      tiptranz, regscutire, proctva, cui, denp,
      f, bi, marja, tva, tvamarja )
    SELECT
      -Row_Number() OVER (ORDER BY tiptranz, regscutire, proctva, cui), vCodD39416,
      tiptranz, regscutire, proctva, cui, Min(denp),
      Sum(F) F, Round(Sum(BI)) BI, Round(Sum(Marja)) Marja, Round(Sum(TVA)) TVA, Round(Sum(TvaMarja)) TvaMarja
    FROM (
      SELECT
        t.tipdoc, t.coddoc, t.tiptranz, t.regscutire, t.proctva, t.cui, t.denp,
        t.F, t.BAZA + CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END AS BI,
        CASE WHEN t.tiptranz = 2 THEN t.BAZA - PKG_D39416.GET_VAL_ACHIZ (t.tipdoc, t.coddoc, t.coddoc1) ELSE 0 END Marja,
        CASE WHEN t.tiptranz = 2 THEN t.TVA ELSE 0 END TvaMarja,
        CASE WHEN t.tiptranz = 2 THEN 0 ELSE t.TVA END TVA
      FROM TMP_D39416_GEN t
      WHERE SECTIUNE = &apos;F&apos;
    ) subs
    GROUP BY tiptranz, regscutire, proctva, cui;

    INSERT INTO TMP_D39416N (codd39416n, codd39416, tiptranz, proctva, f, bi, tva)
    SELECT -Row_Number() OVER (ORDER BY tiptranz, proctva), vCodD39416, tiptranz, proctva, Sum(f) f, Round(Sum(bi)) bi, Round(Sum(tva)) tva
    FROM TMP_D39416NS2
    GROUP BY tiptranz, proctva;

    INSERT INTO TMP_D39416G3
    SELECT -Row_Number() OVER (ORDER BY tiptranz, luna, proctva), vCodD39416, tiptranz, luna, proctva, Round(Sum(BAZA)) bi, Round(Sum(TVA)) tva
    FROM TMP_D39416_GEN
    WHERE SECTIUNE = &apos;G&apos;
    GROUP BY tiptranz, luna, proctva;

    INSERT INTO TMP_D39416G1
    SELECT -Row_Number() OVER (ORDER BY tiptranz, proctva), vCodD39416, tiptranz, proctva, Sum(bi) bi, Sum(TVA) tva
    FROM TMP_D39416G3
    GROUP BY tiptranz, proctva;

    INSERT INTO TMP_D39416G2
    SELECT -Row_Number() OVER (ORDER BY tiptranz, luna), vCodD39416, tiptranz, luna, 0 nramef, Sum(bf) bf, Sum(bi+tva) valoare
    FROM (
      SELECT tiptranz, luna, proctva, Sum(nrbonuri) bf, Round(Sum(BAZA)) bi, Round(Sum(TVA)) tva
      FROM TMP_D39416_GEN
      WHERE SECTIUNE = &apos;G&apos;
      GROUP BY tiptranz, luna, proctva
    ) subs
    GROUP BY tiptranz, luna;

    INSERT INTO TMP_D39416G
    SELECT -Row_Number() OVER (ORDER BY tiptranz), vCodD39416, tiptranz, Sum(bf) bf, Sum(valoare) valoare
    FROM TMP_D39416G2
    GROUP BY tiptranz;

    INSERT INTO TMP_D39416I1
    SELECT
      -Row_Number() OVER (ORDER BY proctva), vCodD39416, proctva,
      Round(Sum(CASE WHEN TipI1 = 11 THEN BAZA ELSE 0 END)) bazafslcod, Round(Sum(CASE WHEN TipI1 = 11 THEN TVA ELSE 0 END)) tvafslcod,
      Round(Sum(CASE WHEN TipI1 = 12 THEN BAZA ELSE 0 END)) bazafsl,    Round(Sum(CASE WHEN TipI1 = 12 THEN TVA ELSE 0 END)) tvafsl,
      Round(Sum(CASE WHEN TipI1 = 13 THEN BAZA ELSE 0 END)) bazafsa,    Round(Sum(CASE WHEN TipI1 = 13 THEN TVA ELSE 0 END)) tvafsa,
      Round(Sum(CASE WHEN TipI1 = 14 THEN BAZA ELSE 0 END)) bazafsai,   Round(Sum(CASE WHEN TipI1 = 14 THEN TVA ELSE 0 END)) tvafsai,
      Round(Sum(CASE WHEN TipI1 = 15 THEN BAZA ELSE 0 END)) bazabfai,   Round(Sum(CASE WHEN TipI1 = 15 THEN TVA ELSE 0 END)) tvabfai,
      Round(Sum(CASE WHEN TipI1 = 21 THEN TVA  ELSE 0 END)) tvaded,
      Round(Sum(CASE WHEN TipI1 = 22 THEN TVA  ELSE 0 END)) tvadedi,
      Round(Sum(CASE WHEN TipI1 = 23 THEN TVA  ELSE 0 END)) tvacol
    FROM TMP_D39416_GEN
    WHERE SECTIUNE = &apos;I&apos;
    GROUP BY PROCTVA;

    INSERT INTO TMP_D39416I2
    SELECT
      -Row_Number() OVER (ORDER BY g.carnetdoc, g.serie, g.grup), vCodD39416,
      Row_Number() OVER (ORDER BY g.carnetdoc, g.serie, g.grup) indexlocal,
      g.serie, Min(nrdoc) NrStart, Max(nrdoc) NrEnd, Max(nrdoc) + 1 - Min(nrdoc) NumarF
    FROM (
      SELECT
        t.carnetdoc, t.serie, t.tipfactura, t.cui, t.denp,
        --t.nrdoc - ROW_NUMBER() OVER (PARTITION BY t.carnetdoc, t.serie ORDER BY t.nrdoc) grup,
        t.nrdoc - DENSE_RANK() OVER (PARTITION BY t.carnetdoc, t.serie ORDER BY t.nrdoc) grup,
        t.nrdoc
      FROM tmp_d39416i2g t
      WHERE NOT t.tipfactura IN (5,6)
      ORDER BY t.carnetdoc, t.serie, t.nrdoc
    ) G
    GROUP BY g.carnetdoc, g.serie, g.grup;

    IF pNerezident = 0 THEN
      INSERT INTO TMP_D39416I2A
      SELECT
        -Row_Number() OVER (ORDER BY d.serie), vCodD39416,
        Row_Number()  OVER (ORDER BY d.serie) indexlocal,
        d.serie, d.startnr, d.endnr, d.endnr - d.startnr + 1 numarf
      FROM (
        SELECT serie, Coalesce(Min(startnr), Min(nrdoc)) startnr, Max(endnr) endnr
        FROM tmp_d39416i2g
        GROUP BY serie
      ) d;
    ELSE
      INSERT INTO TMP_D39416I2A
      SELECT CODD39416I2, CODD39416, INDEXLOCAL, SERIE, STARTNR, ENDNR, NUMARF
      FROM TMP_D39416I2;
    END IF;

    INSERT INTO TMP_D39416I3(
      codd39416i3, codd39416,
      tipfactura, serief, numarf, cui, denp,
      proctva, bi, tva
    )
    SELECT
      -Row_Number() OVER (ORDER BY d.tipfactura, d.serie, d.cui, d.denp, d.nrdoc), vCodD39416,
      d.tipfactura, d.serie serief, d.nrdoc numarf, d.cui, d.denp,
      ta.proctva, ta.bi, ta.tva
    FROM tmp_d39416i2g d
      LEFT JOIN (
        SELECT TIPDOC, CODDOC, PROCTVA, Sum(BAZA) BI, Sum(TVA) TVA
        FROM TMP_D39416_GEN
        WHERE SECTIUNE = &apos;X&apos;
        GROUP BY TIPDOC, CODDOC, PROCTVA
      ) ta ON ta.coddoc = d.coddoc AND ta.tipdoc = d.tipdoc
    WHERE tipfactura &lt;&gt; 0;

    INSERT INTO TMP_D39416I4(
      codd39416i4, codd39416,
      CAEN, TIPOPER, PROCTVA,
      VALOARE, TVA
    )
    SELECT
      -Row_Number() OVER (ORDER BY c.caen, d.tipoper, d.proctva), vCodD39416,
      c.caen, d.tipoper, d.proctva,
      Sum(d.baza*d.cantcaen/d.cantlin), Sum(d.tva*d.cantcaen/d.cantlin)
    FROM tmp_d39416i4aux d INNER JOIN caensec c ON c.codcaensec = d.codcaensec
    WHERE d.cantlin &lt;&gt; 0
      AND d.proctva &lt;&gt; 0
    GROUP BY c.caen, d.tipoper, d.proctva;

    INSERT INTO tmp_d39416i (codd39416i, codd39416) SELECT -1, vCodD39416 FROM DUAL;

    UPDATE tmp_d39416i
    SET totalfact      = (SELECT Coalesce(Sum(numarf),0) FROM TMP_D39416I2),
        totalfactben   = (SELECT Count(1) FROM TMP_D39416I3 WHERE TipFactura = 5),
        totalfactterti = (SELECT Count(1) FROM TMP_D39416I3 WHERE TipFactura = 6);

    UMPLE_REZ(1);
  END IF;
END;

PROCEDURE UmpleXML( pCodD39416 IN NUMBER ) IS
  vSistemTVA    NUMBER(1);
  vSolicit      NUMBER(1);
  vOPEfectuate  NUMBER(1);
  vVer          NUMBER(1);
  vAux          NUMBER(1);
  vAL           NUMBER(5);
BEGIN

/*
TipTranz
1 	- (L) livrari/prestari de servicii;
2 	- (LS) livrari/prestari de servicii la care se aplica regimul special de calcul a TVA-ului la marja de profit;
3 	- (A) achizitii de bunuri si servicii de la persoane care aplica TVA normal;
4 	- (AI) achizitii de bunuri si servicii de la persoane care aplica TVA la incasare;
5 	- (AS) achizitii de bunuri si servicii servicii la care se aplica regimul special de calcul a TVA-ului la marja de profit si aplica TVA normal;
6 	- (ASI) achizitii de bunuri si servicii servicii la care se aplica regimul special de calcul a TVA-ului la marja de profit si aplica TVA la incasare;
7  	- (V) livrari/prestari de servicii cu taxare inversa;
8 	- (C) achizitii de bunuri si servicii cu taxare inversa;
9 	- (N) achizitii de bunuri si servicii de la neplatitori de TVA;
10 	- (I1) incasari cu utilizare de AMEF;
11 	- (I2) incasari omise de la utilizare de AMEF;
*/

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_det1_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_fact_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_info_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_list_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_op1_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_op11_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_op2_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_rez1_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_rez2_xml&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_d39416_serf_xml&apos;;

  SELECT TVAIncas, OPEfectuate, AN*12+LUNAD INTO vSistemTVA, vOPEfectuate, vAL
  FROM D39416
  WHERE codd39416 = pCodD39416;

  IF    vAL &gt;=2025*12+8 then vVer := 5;
  ELSIF vAL &gt;=2022*12+4 then vVer := 4;
  ELSE                       vVer := 3;
  END IF;

  INSERT INTO tmp_d39416_info_xml (nrCui1, nrCui2, nrCui3, nrCui4)
  SELECT
    RPno nrCui1, RNno nrCui2, UEno nrCui3, NonUEno nrCui4
  FROM D39416
  WHERE codd39416 = pCodD39416;

  UPDATE tmp_d39416_info_xml SET (nr_BF_i1, incasari_i1 ) = (SELECT COALESCE(Sum(BF),0), COALESCE( Sum(Valoare),0) FROM D39416G WHERE codd39416 = pCodD39416 AND TipTranz = 10);
  UPDATE tmp_d39416_info_xml SET (incasari_i2 ) = (SELECT COALESCE(Sum(Valoare), 0) FROM D39416G WHERE codd39416 = pCodD39416 AND TipTranz = 11);
  UPDATE tmp_d39416_info_xml
  SET (nrFacturi_terti, nrFacturi_benef, nrFacturi, Solicit) =
      (SELECT COALESCE(Sum(TotalFactTerti),0), COALESCE(Sum(TotalFactBen),0), COALESCE(Sum(TotalFact),0), COALESCE(Sum(Solicit),0) FROM D39416I WHERE codd39416 = pCodD39416);

  UPDATE tmp_d39416_info_xml
  SET (nrFacturiL_PF, nrFacturiLS_PF, val_LS_PF) = (SELECT COALESCE(Sum(l_pf_f),0), COALESCE(Sum(ls_pf_f),0), COALESCE(Sum(ls_pf_val),0) FROM D39416RN0 WHERE codd39416 = pCodD39416);

  UPDATE tmp_d39416_info_xml
  SET ( tvaDedAI24, tvaDedAI21, tvaDedAI20, tvaDedAI19, tvaDedAI11, tvaDedAI9, tvaDedAI5 ) =
      ( SELECT
          COALESCE(Sum(CASE WHEN ProcTVA = 24 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA = 21 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA = 20 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA = 19 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA = 11 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA =  9 THEN TVADedI ELSE 0 END),0),
          COALESCE(Sum(CASE WHEN ProcTVA =  5 THEN TVADedI ELSE 0 END),0)
        FROM D39416I1
        WHERE codd39416 = pCodD39416);

  IF vSistemTVA = 1 THEN
    UPDATE tmp_d39416_info_xml
    SET ( tvaDed24, tvaDed21, tvaDed19, tvaDed20, tvaDed11, tvaDed9, tvaDed5,
          tvaCol24, tvaCol21, tvaCol19, tvaCol20, tvaCol11, tvaCol9, tvaCol5
        ) =
        ( SELECT
            COALESCE(Sum(CASE WHEN ProcTVA = 24 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 21 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 19 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 20 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 11 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA =  9 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA =  5 THEN TVADed ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 24 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 21 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 19 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 20 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA = 11 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA =  9 THEN TVACol ELSE 0 END),0),
            COALESCE(Sum(CASE WHEN ProcTVA =  5 THEN TVACol ELSE 0 END),0)
          FROM D39416I1
          WHERE codd39416 = pCodD39416);
  END IF;

  UPDATE tmp_d39416_info_xml
  SET ( incasari_ag, marja_ag, tva_ag ) =
      ( SELECT Sum (BI), Sum (Marja) + Sum (TVAMarja), Sum (TVAMarja)
        FROM (
          SELECT BI, Marja, TVAMarja FROM D39416RPS2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416RNS2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416UES2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 1 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416NS2  WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 1
        ) subs
      );

  UPDATE tmp_d39416_info_xml
  SET ( pret_vanzare, marja_antic, tva_antic ) =
      ( SELECT Sum (BI), Sum (Marja) + Sum (TVAMarja), Sum (TVAMarja)
        FROM (
          SELECT BI, Marja, TVAMarja FROM D39416RPS2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416RNS2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416UES2 WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 2 UNION ALL
          SELECT BI, Marja, TVAMarja FROM D39416NS2  WHERE codd39416 = pCodD39416 AND TipTranz = 2 AND RegScutire = 2
        ) subs
      );

  UPDATE tmp_d39416_info_xml
  SET costuri_ag     = incasari_ag  - marja_ag,
      pret_cumparare = pret_vanzare - marja_antic;

  SELECT solicit INTO vSolicit FROM tmp_d39416_info_xml;

  IF vSolicit = 1 THEN
    UPDATE tmp_d39416_info_xml
    SET (   achizitiiPE, achizitiiCR, achizitiiCB, achizitiiCI, achizitiiA,
            achizitiiB24, achizitiiB21, achizitiiB20, achizitiiB19, achizitiiB11, achizitiiB9, achizitiiB5,
            achizitiiS24, achizitiiS21, achizitiiS20, achizitiiS19, achizitiiS11, achizitiiS9, achizitiiS5,
            importB, acINecorp,
            livrariBI, BUN24, BUN21, BUN20, BUN19, BUN11, BUN9, BUN5, valoareScutit,
            BunTI, Prest24, Prest21, Prest20, Prest19, Prest11, Prest9, Prest5, PrestScutit,
            LIntra, PrestIntra, Export, livINecorp,
            efectuat
        ) =
        ( SELECT
            Coalesce(AchizPE,0),  Coalesce(AchizCR,0),  Coalesce(AchizCB,0),  Coalesce(AchizCI,0), Coalesce(AchizA,0),
            Coalesce(AchizB24,0), Coalesce(AchizB21,0), Coalesce(AchizB20,0), Coalesce(AchizB19,0), Coalesce(AchizB11,0), Coalesce(AchizB9,0), Coalesce(AchizB5,0),
            Coalesce(AchizS24,0), Coalesce(AchizS21,0), Coalesce(AchizS20,0), Coalesce(AchizS19,0), Coalesce(AchizS11,0), Coalesce(AchizS9,0), Coalesce(AchizS5,0),
            Coalesce(ImportB,0),  Coalesce(AcINecorp,0),
            Coalesce(LivrariBI,0), Coalesce(LivrariB24,0), Coalesce(LivrariB21,0), Coalesce(LivrariB20,0), Coalesce(LivrariB19,0), Coalesce(LivrariB11,0), Coalesce(LivrariB9,0), Coalesce(LivrariB5,0), Coalesce(LivrariB0,0),
            Coalesce(LivrariTI,0), Coalesce(Prest24,0), Coalesce(Prest21,0), Coalesce(Prest20,0), Coalesce(Prest19,0), Coalesce(Prest11,0), Coalesce(Prest9,0), Coalesce(Prest5,0), Coalesce(Prest0,0),
            Coalesce(LivrariUE,0), Coalesce(PrestUE,0), Coalesce(Export,0), Coalesce(LivINecorp,0),
            Coalesce(Efectuat,0)
          FROM D39416I
          WHERE codd39416 = pCodD39416
        );

    --UPDATE tmp_d39416_info_xml
    --SET efectuat = CASE
    --                 WHEN livrariBI+BUN24+BUN20+BUN19+BUN9+BUN5+valoareScutit+BunTI+Prest24+Prest20+Prest19+Prest9+Prest5+PrestScutit+LIntra+PrestIntra+Export &gt; 0 THEN 1
    --                 ELSE 0
    --               END;
  END IF;

  IF vOPEfectuate &gt; 0 THEN
    INSERT INTO tmp_d39416_rez1_xml
    SELECT
      tip_partener, cota,
      CASE WHEN cota &lt;&gt; 0                                                      THEN SUM(CASE WHEN tiptranz      = 1 THEN F   ELSE 0 END) END AS facturiL,
      CASE WHEN cota &lt;&gt; 0                                                      THEN SUM(CASE WHEN tiptranz      = 1 THEN BI  ELSE 0 END) END AS bazaL,
      CASE WHEN cota &lt;&gt; 0                                                      THEN SUM(CASE WHEN tiptranz      = 1 THEN TVA ELSE 0 END) END AS tvaL,
      CASE WHEN cota  = 0                       AND Coalesce(document_N,1) = 1 THEN SUM(CASE WHEN tiptranz      = 2 THEN F   ELSE 0 END) END AS facturiLS,
      CASE WHEN cota  = 0                       AND Coalesce(document_N,1) = 1 THEN SUM(CASE WHEN tiptranz      = 2 THEN BI  ELSE 0 END) END AS bazaLS,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 3 THEN F   ELSE 0 END) END AS facturiA,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 3 THEN BI  ELSE 0 END) END AS bazaA,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 3 THEN TVA ELSE 0 END) END AS tvaA,
      CASE WHEN               tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 4 THEN F   ELSE 0 END) END AS facturiAI,
      CASE WHEN               tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 4 THEN BI  ELSE 0 END) END AS bazaAI,
      CASE WHEN               tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 4 THEN TVA ELSE 0 END) END AS tvaAI,
      CASE WHEN               tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz IN (5,6) THEN F   ELSE 0 END) END AS facturiAS,
      CASE WHEN               tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz IN (5,6) THEN BI  ELSE 0 END) END AS bazaAS,
      CASE WHEN cota  = 0 AND tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 7 THEN F   ELSE 0 END) END AS facturiV,
      CASE WHEN cota  = 0 AND tip_partener  = 1                                THEN SUM(CASE WHEN tiptranz      = 7 THEN BI  ELSE 0 END) END AS bazaV,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener &lt;&gt; 2                                THEN SUM(CASE WHEN tiptranz      = 8 THEN F   ELSE 0 END) END AS facturiC,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener &lt;&gt; 2                                THEN SUM(CASE WHEN tiptranz      = 8 THEN BI  ELSE 0 END) END AS bazaC,
      CASE WHEN cota &lt;&gt; 0 AND tip_partener &lt;&gt; 2                                THEN SUM(CASE WHEN tiptranz      = 8 THEN TVA ELSE 0 END) END AS tvaC,
      CASE WHEN cota  = 0 AND tip_partener  = 2                                THEN SUM(CASE WHEN tiptranz      = 9 THEN F   ELSE 0 END) END AS facturiN,
      CASE WHEN cota  = 0 AND tip_partener  = 2                                THEN Coalesce(document_N,1)                               END AS document_N,
      CASE WHEN cota  = 0 AND tip_partener  = 2                                THEN SUM(CASE WHEN tiptranz      = 9 THEN BI  ELSE 0 END) END AS bazaN
    FROM  (
      SELECT 1 AS tip_partener, ProcTVA AS COTA, NULL   document_N, tiptranz, f, bi, tva FROM D39416RP WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT 2 AS tip_partener, ProcTVA AS COTA, TipDoc document_N, tiptranz, f, bi, tva FROM D39416RN WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT 3 AS tip_partener, ProcTVA AS COTA, NULL   document_N, tiptranz, f, bi, tva FROM D39416UE WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT 4 AS tip_partener, ProcTVA AS COTA, NULL   document_N, tiptranz, f, bi, tva FROM D39416N  WHERE codd39416 = pCodD39416
    ) subs
    GROUP BY tip_partener, cota, Coalesce(document_N,1);

    UPDATE tmp_d39416_rez1_xml
    SET facturiAI = CASE WHEN facturiAI = 0 AND (tip_partener &lt;&gt; 1 OR cota =  0) THEN NULL ELSE facturiAI END,
        facturiAS = CASE WHEN facturiAS = 0 AND (tip_partener &lt;&gt; 1 OR cota &lt;&gt; 0) THEN NULL ELSE facturiAS END,
        facturiV  = CASE WHEN facturiV  = 0 AND (tip_partener &lt;&gt; 1 OR cota &lt;&gt; 0) THEN NULL ELSE facturiV  END;

    UPDATE tmp_d39416_rez1_xml
    SET bazaAI = CASE WHEN facturiAI IS NULL THEN NULL ELSE bazaAI END,
        tvaAI  = CASE WHEN facturiAI IS NULL THEN NULL ELSE tvaAI  END,
        bazaAS = CASE WHEN facturiAS IS NULL THEN NULL ELSE bazaAS END,
        bazaV  = CASE WHEN facturiV  IS NULL THEN NULL ELSE bazaV  END;

    INSERT INTO tmp_d39416_det1_xml
    SELECT
      tip_partener, cota, document_n, bun,
      CASE WHEN tip_partener = 1 AND cota =  0 THEN Sum(CASE WHEN TipTranz = 7 THEN F   ELSE 0 END) ELSE NULL END nrlivv,
      CASE WHEN tip_partener = 1 AND cota =  0 THEN Sum(CASE WHEN TipTranz = 7 THEN BI  ELSE 0 END) ELSE NULL END bazalivv,
      CASE WHEN tip_partener = 1 AND cota &lt;&gt; 0 THEN Sum(CASE WHEN TipTranz = 8 THEN F   ELSE 0 END) ELSE NULL END nrachizc,
      CASE WHEN tip_partener = 1 AND cota &lt;&gt; 0 THEN Sum(CASE WHEN TipTranz = 8 THEN BI  ELSE 0 END) ELSE NULL END bazaachizc,
      CASE WHEN tip_partener = 1 AND cota &lt;&gt; 0 THEN Sum(CASE WHEN TipTranz = 8 THEN TVA ELSE 0 END) ELSE NULL END tvaachizc,
      CASE WHEN tip_partener = 2               THEN Sum(CASE WHEN TipTranz = 9 THEN F   ELSE 0 END) ELSE NULL END nrn,
      CASE WHEN tip_partener = 2               THEN Sum(CASE WHEN TipTranz = 9 THEN BI  ELSE 0 END) ELSE NULL END valn
    FROM  (
      SELECT 1 AS tip_partener, D.ProcTVA as cota, NULL     document_N, D.tiptranz, C.SIMBOLP AS bun, D.f, D.bi, D.tva
      FROM D39416RP1 D INNER JOIN CategArtTI C ON C.CodCategArtTI = D.CategTxInv
      WHERE codd39416 = pCodD39416 AND D.TipTranz IN (7, 8) AND C.SIMBOLP &lt;&gt; 0
        -- AND ((D.TipTranz = 7 AND D.ProcTVA = 0) OR (D.TipTranz = 8 AND D.ProcTVA &lt;&gt; 0)) --am avut probleme ca apareau lini cu 0 pentru D.TipTranz = 8 AND D.ProcTVA = 0
        -- las sa dea eroare d394 fiindca e o eroare de operare si sa o caute
      UNION ALL
      SELECT 2 AS tip_partener, D.ProcTVA as cota, D.TipDoc document_N, D.tiptranz, C.SIMBOLN AS bun, D.f, D.valoare AS bi, 0 AS tva
      FROM D39416RN1 D INNER JOIN CategArtTI C ON C.CodCategArtTI = D.CategTxInv WHERE codd39416 = pCodD39416 AND D.TipTranz IN (9) AND C.SIMBOLN &lt;&gt; 0
    ) subs
    GROUP BY tip_partener, cota, document_N, bun;

    IF vVer = 5
    THEN vAux := 7;
    ELSE vAux := 5;
    END IF;

    INSERT INTO tmp_d39416_rez2_xml
    SELECT
      cota,
      Sum(bazafslcod), Sum(tvafslcod), Sum(bazafsl), Sum(tvafsl), Sum(bazafsa), Sum(tvafsa), Sum(bazafsai), Sum(tvafsai), Sum(bazabfai), Sum(tvabfai),
      Sum(nrFacturiL), Sum(bazaL), Sum(tvaL),
      Sum(nrFacturiA), Sum(bazaA), Sum(tvaA),
      Sum(nrFacturiAI), Sum(bazaAI), Sum(tvaAI),
      Sum(baza_incasari_i1), Sum(tva_incasari_i1), Sum(baza_incasari_i2), Sum(tva_incasari_i2),
      Sum(bazaL_PF), Sum(tvaL_PF)
    FROM  (
      SELECT
        ProcTVA as cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        livrarif AS nrFacturiL, livrarib AS bazaL, livraritva AS tvaL,
        achizf AS nrFacturiA, achizb AS bazaA, achiztva AS tvaA,
        achizif AS nrFacturiAI, achizib AS bazaAI, achizitva AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 AS bazaL_PF, 0 AS tvaL_PF
      FROM D39416R WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        ProcTVA as cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        CASE WHEN TipTranz = 1 THEN F ELSE 0 END nrFacturiL, CASE WHEN TipTranz = 1 THEN BI ELSE 0 END bazaL, CASE WHEN TipTranz = 1 THEN TVA ELSE 0 END AS tvaL,
        0 AS nrFacturiA, 0 AS bazaA, 0 AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 bazaL_PF, 0 tvaL_PF
      FROM D39416RN WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        CASE l.nr
          WHEN 1 THEN 24 WHEN 2 THEN 20 WHEN 3 THEN 19 WHEN 4 THEN 9 WHEN 5 THEN 5
          WHEN 6 THEN 21 WHEN 7 THEN 11 -- De la Ver 5
        END AS cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        0 AS nrFacturiL, 0 AS bazaL, 0 AS tvaL,
        0 AS nrFacturiA, 0 AS bazaA, 0 AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        CASE l.nr
          WHEN 1 THEN d.l_pf_bi24 WHEN 2 THEN d.l_pf_bi20 WHEN 3 THEN d.l_pf_bi19 WHEN 4 THEN d.l_pf_bi9 WHEN 5 THEN d.l_pf_bi5
          WHEN 6 THEN d.l_pf_bi21 WHEN 7 THEN d.l_pf_bi11 -- De la Ver 5
        END AS bazaL_PF,
        CASE l.nr
          WHEN 1 THEN d.l_pf_tva24 WHEN 2 THEN d.l_pf_tva20 WHEN 3 THEN d.l_pf_tva19 WHEN 4 THEN d.l_pf_tva9 WHEN 5 THEN d.l_pf_tva5
          WHEN 6 THEN d.l_pf_tva21 WHEN 7 THEN d.l_pf_tva11 -- De la Ver 5
        END AS tvaL_PF
      FROM D39416RN0 D CROSS JOIN (SELECT LEVEL nr FROM dual CONNECT BY LEVEL &lt;= vAux) L
      WHERE d.codd39416 = pCodD39416
        AND CASE l.nr WHEN 1 THEN d.l_pf_bi24  WHEN 2 THEN d.l_pf_bi20  WHEN 3 THEN d.l_pf_bi19  WHEN 4 THEN d.l_pf_bi9  WHEN 5 THEN d.l_pf_bi5  END &lt;&gt; 0
        AND CASE l.nr WHEN 1 THEN d.l_pf_tva24 WHEN 2 THEN d.l_pf_tva20 WHEN 3 THEN d.l_pf_tva19 WHEN 4 THEN d.l_pf_tva9 WHEN 5 THEN d.l_pf_tva5 END &lt;&gt; 0
      UNION ALL
      SELECT
        ProcTVA as cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        CASE WHEN TipTranz = 1 THEN F ELSE 0 END nrFacturiL, CASE WHEN TipTranz = 1 THEN BI ELSE 0 END bazaL, CASE WHEN TipTranz = 1 THEN TVA ELSE 0 END AS tvaL,
        CASE WHEN TipTranz = 8 THEN F ELSE 0 END nrFacturiA, CASE WHEN TipTranz = 8 THEN BI ELSE 0 END bazaA, CASE WHEN TipTranz = 8 THEN TVA ELSE 0 END AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 bazaL_PF, 0 tvaL_PF
      FROM D39416UE WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        ProcTVA as cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        CASE WHEN TipTranz = 1 THEN F ELSE 0 END nrFacturiL, CASE WHEN TipTranz = 1 THEN BI ELSE 0 END bazaL, CASE WHEN TipTranz = 1 THEN TVA ELSE 0 END AS tvaL,
        CASE WHEN TipTranz = 8 THEN F ELSE 0 END nrFacturiA, CASE WHEN TipTranz = 8 THEN BI ELSE 0 END bazaA, CASE WHEN TipTranz = 8 THEN TVA ELSE 0 END AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 bazaL_PF, 0 tvaL_PF
      FROM D39416N WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        ProcTVA as cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        0 AS nrFacturiL, 0 AS bazaL, 0 AS tvaL,
        0 AS nrFacturiA, 0 AS bazaA, 0 AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        CASE WHEN TipTranz = 10 THEN bi ELSE 0 END AS baza_incasari_i1, CASE WHEN TipTranz = 10 THEN tva ELSE 0 END AS tva_incasari_i1,
        CASE WHEN TipTranz = 11 THEN bi ELSE 0 END AS baza_incasari_i2, CASE WHEN TipTranz = 11 THEN tva ELSE 0 END AS tva_incasari_i2,
        0 AS bazaL_PF, 0 AS tvaL_PF
      FROM D39416G1 WHERE codd39416 = pCodD39416 AND TipTranz IN (10, 11)
      UNION ALL
      SELECT
        ProcTVA as cota,
        bazafslcod, tvafslcod, bazafsl, tvafsl, bazafsa, tvafsa, bazafsai, tvafsai, bazabfai, tvabfai,
        0 AS nrFacturiL, 0 AS bazaL, 0 AS tvaL,
        0 AS nrFacturiA, 0 AS bazaA, 0 AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 AS bazaL_PF, 0 AS tvaL_PF
      FROM D39416I1 WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        CASE l.nr
          WHEN 1 THEN 24 WHEN 2 THEN 20 WHEN 3 THEN 19 WHEN 4 THEN 9 WHEN 5 THEN 5
          WHEN 6 THEN 21 WHEN 7 THEN 11 -- De la Ver 5
        END AS cota,
        0 AS bazafslcod, 0 AS tvafslcod, 0 AS bazafsl, 0 AS tvafsl, 0 AS bazafsa, 0 AS tvafsa, 0 AS bazafsai, 0 AS tvafsai, 0 AS bazabfai, 0 AS tvabfai,
        0 AS nrFacturiL, 0 AS bazaL, 0 AS tvaL,
        0 AS nrFacturiA, 0 AS bazaA, 0 AS tvaA,
        0 AS nrFacturiAI, 0 AS bazaAI, 0 AS tvaAI,
        0 AS baza_incasari_i1, 0 AS tva_incasari_i1,
        0 AS baza_incasari_i2, 0 AS tva_incasari_i2,
        0 AS bazaL_PF, 0 AS tvaL_PF
      FROM (SELECT LEVEL AS NR FROM DUAL CONNECT BY LEVEL &lt;= vAux) l
    ) subs
    WHERE Coalesce(COTA, 0) &lt;&gt; 0
    GROUP BY cota;

    INSERT INTO tmp_d39416_op1_xml
    SELECT
      Row_Number() OVER (ORDER BY tip_partener, TipTranz, cuip, denp, tarap, locp, judp, strp, nrp, blp, app, detp, tip_document, cota),
      TipTranz,
      CASE
        WHEN TipTranz = 1 THEN &apos;L&apos;
        WHEN TipTranz = 2 THEN &apos;LS&apos;
        WHEN TipTranz = 3 THEN &apos;A&apos;
        WHEN TipTranz = 4 THEN &apos;AI&apos;
        WHEN TipTranz = 5 THEN &apos;AS&apos;
        WHEN TipTranz = 7 THEN &apos;V&apos;
        WHEN TipTranz = 8 THEN &apos;C&apos;
        WHEN TipTranz = 9 THEN &apos;N&apos;
      END Tip,
      tip_partener, cota,
      cuip, denp, tarap, locp, judp, strp, nrp, blp, app, detp, tip_document,
      nrfact, COALESCE(baza, 0) baza,
      CASE
        WHEN tva = 0 AND NOT TipTranz IN (1, 3, 4, 8) THEN NULL
        ELSE tva
      END tva
    FROM  (
      SELECT
        TipTranz,
        1 AS tip_partener, ProcTVA as cota,
        REGEXP_REPLACE(cui,&apos;\D+&apos;, &apos;&apos;) AS cuip, denp, NULL AS tarap, NULL AS locp, NULL AS judp,
        NULL AS strp, NULL AS nrp, NULL AS blp, NULL AS app, NULL AS detp, NULL AS tip_document,
        f AS nrfact, bi AS baza, tva AS tva
      FROM D39416RPS2
      WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        TipTranz,
        2 AS tip_partener, ProcTVA as cota,
        cui AS cuip, denp, NULL AS tarap, NULL AS locp, NULL AS judp,
        NULL AS strp, NULL AS nrp, NULL AS blp, NULL AS app, NULL AS detp, tipdoc AS tip_document,
        f AS nrfact, bi AS baza, tva AS tva
      FROM D39416RNS2
      WHERE codd39416 = pCodD39416 AND NOT (cuivalid IN (6,7) OR cui IS NULL)
      UNION ALL
      SELECT
        TipTranz,
        2 AS tip_partener, d2.ProcTVA as cota,
        NULL AS cuip, d2.denp, COALESCE(d2.tarap, t.simbauto) AS tarap, COALESCE(d2.locp, l.den_localit) AS locp, Coalesce(d2.judp, To_Char(j.js,&apos;fm900&apos;)) AS judp,
        Trim(d2.strp) strp, Trim(d2.nrp) nrp, Trim(d2.blp) blp, Trim(d2.app) app, Trim(d2.detp) detp, d2.tipdoc AS tip_document,
        d2.f AS nrfact, d2.bi AS baza, d2.tva
      FROM D39416RNS2 D2
        LEFT JOIN nlocalit l ON l.codlocalit = d2.codlocalit
        LEFT JOIN njudet j ON j.codjudet = l.codjudet
        LEFT JOIN ntari t ON t.codtara = l.codtara
      WHERE d2.codd39416 = pCodD39416 AND (cuivalid IN (6,7) OR cui IS NULL)
      UNION ALL
      SELECT
        TipTranz,
        3 AS tip_partener, ProcTVA as cota,
        REGEXP_REPLACE(cui,&apos;\D+&apos;, &apos;&apos;,1,1) AS cuip, denp, NULL AS tarap, NULL AS locp, NULL AS judp, NULL AS strp, NULL AS nrp, NULL AS blp, NULL AS app, NULL AS detp, NULL AS tip_document,
        f AS nrfact, bi AS baza, tva
      FROM D39416UES2
      WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        TipTranz,
        4 AS tip_partener, ProcTVA as cota,
        REGEXP_REPLACE(cui,&apos;\D+&apos;, &apos;&apos;,1,1) AS cuip, denp, NULL AS tarap, NULL AS locp, NULL AS judp, NULL AS strp, NULL AS nrp, NULL AS blp, NULL AS app, NULL AS detp, NULL AS tip_document,
        f AS nrfact, bi AS baza, tva
      FROM D39416NS2
      WHERE codd39416 = pCodD39416
    ) subs;

    INSERT INTO tmp_d39416_op11_xml
    SELECT idx_op1, nrfactpr, codpr, bazapr, tvapr
    FROM (
      SELECT
        d.tiptranz,
        ( SELECT Min(idx_op1)
          FROM tmp_d39416_op1_xml t
          WHERE t.tip_partener = 1 AND t.cota = d.proctva
            AND t.TipTranz = d.tiptranz
            AND t.cuip = REGEXP_REPLACE(d.cui,&apos;\D+&apos;, &apos;&apos;)
        ) idx_op1,
        f AS nrFactPR, codd394 AS codpr, bi AS bazaPR, CASE WHEN TipTranz = 7 THEN NULL ELSE tva END AS tvaPR
      FROM D39416RPS3 D
      WHERE D.codd39416 = pCodD39416
      UNION ALL
      SELECT
        p2.tiptranz,
        ( SELECT Min(td.idx_op1)
          FROM tmp_d39416_op1_xml td
          WHERE td.tip_partener = 2 AND td.cota = p2.proctva
            AND td.TipTranz = p2.tiptranz
            AND Coalesce(td.cuip,  &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid &lt;&gt; 6 THEN REGEXP_REPLACE(p2.cui,&apos;\D+&apos;, &apos;&apos;) END, &apos; &apos;)
            AND Coalesce(td.denp,  &apos; &apos;) = Coalesce(p2.denp, &apos; &apos;)
            AND Coalesce(td.tarap, &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN COALESCE(p2.tarap, t.simbauto)           END, &apos; &apos;)
            AND Coalesce(td.locp,  &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN COALESCE(p2.locp, l.den_localit)         END, &apos; &apos;)
            AND Coalesce(td.judp,  &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN COALESCE(p2.judp, To_Char(j.js,&apos;fm900&apos;)) END, &apos; &apos;)
            AND Coalesce(td.strp,  &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN Trim(p2.strp)                            END, &apos; &apos;)
            AND Coalesce(td.nrp,   &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN Trim(p2.nrp)                             END, &apos; &apos;)
            AND Coalesce(td.blp,   &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN Trim(p2.blp)                             END, &apos; &apos;)
            AND Coalesce(td.app,   &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN Trim(p2.app)                             END, &apos; &apos;)
            AND Coalesce(td.detp,  &apos; &apos;) = Coalesce(CASE WHEN p2.cuivalid  = 6 OR p2.cui IS NULL THEN Trim(p2.detp)                            END, &apos; &apos;)
            AND Coalesce(td.tip_document, 0) = Coalesce(p2.tipdoc, 0)
        ) idx_op1,
        D.f AS nrFactPR, Coalesce(D.codd394, To_Char(C.SIMBOLN)) AS codpr, D.valoare AS bazaPR, NULL tvaPR
      FROM D39416RNS3 D
        INNER JOIN D39416RN1  P1 ON P1.CODD39416RN1  = D.CODD39416RN1
        INNER JOIN D39416RNS2 P2 ON P2.CODD39416RNS2 = D.CODD39416RNS2
        INNER JOIN CategArtTI C  ON C.CodCategArtTI  = P1.CategTxInv
        LEFT  JOIN nlocalit   l  ON l.codlocalit     = P2.codlocalit
        LEFT  JOIN njudet     j  ON j.codjudet       = l.codjudet
        LEFT  JOIN ntari      t  ON t.codtara        = l.codtara
      WHERE D.codd39416 = pCodD39416
    ) subs;
    --WHERE idx_op1 IS NOT NULL;

    INSERT INTO tmp_d39416_op2_xml (
      TIP_OP2, LUNA, NRAMEF, NRBF, TOTAL, BAZA21, TVA21, BAZA20, TVA20, BAZA19, TVA19, BAZA11, TVA11, BAZA9, TVA9, BAZA5, TVA5
    )
    SELECT
      CASE WHEN TIPTRANZ = 10 THEN &apos;I1&apos; ELSE &apos;I2&apos; END, LUNA,
      CASE WHEN TIPTRANZ = 10 THEN Sum(NRAMEF) END NRAMEF,
      CASE WHEN TIPTRANZ = 10 THEN Sum(BF)     END NRBF,
      Sum(valoare),
      Sum(BAZA21), Sum(TVA21),
      Sum(BAZA20), Sum(TVA20),
      Sum(BAZA19), Sum(TVA19),
      Sum(BAZA11), Sum(TVA11),
      Sum(BAZA9) , Sum(TVA9),
      Sum(BAZA5) , Sum(TVA5)
    FROM (
      SELECT
        TIPTRANZ, LUNA,
        NRAMEF, Coalesce(BF, 0) BF, Coalesce(VALOARE, 0) VALOARE,
        0 BAZA21, 0 TVA21,
        0 BAZA20, 0 TVA20,
        0 BAZA19, 0 TVA19,
        0 BAZA11, 0 TVA11,
        0 BAZA9 , 0 TVA9,
        0 BAZA5 , 0 TVA5
      FROM D39416G2
      WHERE codd39416 = pCodD39416
      UNION ALL
      SELECT
        TIPTRANZ, LUNA,
        0 NRAMEF, 0 BF, 0 VALOARE,
        CASE WHEN PROCTVA = 21 THEN BI ELSE 0 END BAZA21, CASE WHEN PROCTVA = 21 THEN TVA ELSE 0 END TVA21,
        CASE WHEN PROCTVA = 20 THEN BI ELSE 0 END BAZA20, CASE WHEN PROCTVA = 20 THEN TVA ELSE 0 END TVA20,
        CASE WHEN PROCTVA = 19 THEN BI ELSE 0 END BAZA19, CASE WHEN PROCTVA = 19 THEN TVA ELSE 0 END TVA19,
        CASE WHEN PROCTVA = 11 THEN BI ELSE 0 END BAZA21, CASE WHEN PROCTVA = 11 THEN TVA ELSE 0 END TVA11,
        CASE WHEN PROCTVA =  9 THEN BI ELSE 0 END BAZA9 , CASE WHEN PROCTVA =  9 THEN TVA ELSE 0 END TVA9,
        CASE WHEN PROCTVA =  5 THEN BI ELSE 0 END BAZA5 , CASE WHEN PROCTVA =  5 THEN TVA ELSE 0 END TVA5
      FROM D39416G3
      WHERE codd39416 = pCodD39416
    ) subs
    GROUP BY TIPTRANZ, LUNA;

    --E: op2 (2) eroare regula: R245.1: atributul total 0 si suma baza20 + baza19 + baza9 + baza5 0 nu pot fi egale cu zero
    DELETE FROM tmp_d39416_op2_xml WHERE TOTAL = 0 AND TIP_OP2 = &apos;I2&apos;;

    INSERT INTO tmp_d39416_serf_xml (tip, seriei, nri, nrf, den, cui)
    SELECT  1, serie, startnr, endnr, NULL, null
    FROM D39416I2A D
    WHERE D.codd39416 = pCodD39416;

    INSERT INTO tmp_d39416_serf_xml (tip, seriei, nri, nrf, den, cui)
    SELECT  2, serie, startnr, endnr, NULL, null
    FROM D39416I2 D
    WHERE D.codd39416 = pCodD39416;

    INSERT INTO tmp_d39416_serf_xml (
      tip,
      seriei, nri, nrf, den, cui)
    SELECT
      CASE WHEN tipfactura = 6 THEN 4 ELSE 3 END,
      serief, numarf, numarf, denp, cui
    FROM D39416I3 D
    WHERE D.codd39416 = pCodD39416 AND tipfactura IN (5,6);

    INSERT INTO tmp_d39416_list_xml(caen, cota, operat, valoare, tva)
    SELECT caen, proctva, tipoper, valoare, tva
    FROM D39416I4 D
    WHERE D.codd39416 = pCodD39416;

    INSERT INTO tmp_d39416_fact_xml(
      tip_factura, serie, nr,
      baza24, tva24,
      baza21, tva21,
      baza20, tva20,
      baza19, tva19,
      baza11, tva11,
      baza9,  tva9,
      baza5,  tva5
    )
    SELECT
      tipfactura, serief, numarf,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 24 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 24 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 21 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 21 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 20 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 20 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 19 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 19 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 11 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva = 11 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva =  9 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva =  9 THEN tva ELSE 0 END) END,
      CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva =  5 THEN bi  ELSE 0 END) END, CASE WHEN tipfactura = 3 THEN Sum(CASE WHEN proctva =  5 THEN tva ELSE 0 END) END
    FROM D39416I3 D
    WHERE D.codd39416 = pCodD39416 AND d.tipfactura IN (1,2,3,4)
    GROUP BY d.tipfactura, d.serief, d.numarf;
  END IF;

END;

END PKG_D39416;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DECODE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>932AF4970C33A24EF7AFBA42E66B864D4B8A0D5A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DECODE IS

FUNCTION DODECODE(TABLENAME IN VARCHAR2, LOOKUPFIELD IN VARCHAR2, LOOKUPDISPLAY IN VARCHAR2, COD IN NUMBER) RETURN VARCHAR2
IS
INFO VARCHAR2(2000) := &apos;?&apos;;
BEGIN
  BEGIN
    EXECUTE IMMEDIATE &apos;SELECT &apos;|| LOOKUPDISPLAY || &apos; FROM &apos; || TABLENAME || &apos; WHERE &apos; || LOOKUPFIELD || &apos; = &apos; || COD INTO INFO; 
    EXCEPTION WHEN OTHERS THEN INFO := &apos;?&apos;;
  END;  
  RETURN INFO;
END;

end PKG_DECODE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DELEGATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EE1B48685B6D5A4DB529295CFD0672BD11C7DBA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DELEGATI IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_78&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODPARTTR INTO TMP FROM NPARTTR WHERE CODPARTTR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(100);  
BEGIN
  SP_LOCKRECORD(RecId);
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT substr(delegat,100) INTO aDoc FROM nparttr WHERE Codparttr = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARTTR&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
	DELETE FROM NPARTTR WHERE CODPARTTR = RECID;
  NotifyModif(2, RecId, &apos;NPARTTR&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NPARTTR_2 FIELDS(CODPARTTR) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NPARTTR_2(CODPARTTR, 
                           CODPART, 
                           DELEGAT, 
                           CNP, 
                           DOC, 
                           SERIEDOC, 
                           NRDOC, 
                           permis,
                           nrpass, OBS, 
                           codtara, adresa, CodLocalit, Telefon,
                           ELIBERAT,MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, CODPERS, CODAUTO, IMPLICIT
                           )
                           
  SELECT  CODPARTTR,
          CODPART, 
          DELEGAT, 
          CNP, 
          DOC, 
          SERIEDOC, 
          NRDOC, 
          permis,
          nrpass, OBS, 
          codtara,adresa, CodLocalit, Telefon,
          ELIBERAT,MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, CODPERS, CODAUTO, IMPLICIT
  FROM NPARTTR WHERE CODPARTTR = RECID;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aCODPART NUMBER(20);
  NR NUMBER(5) := 0;
  aDoc        varchar2(100);
BEGIN
  SELECT CODPART INTO aCODPART FROM TMP_NPARTTR_2;

-- ** VERIFICARE INAINTE DE A INCEPE POSTARILE ** 
-- deoarece am constrangere NPART - NPARTTR pe coloana CODPART,
-- atunci cand am delegat propriu (CODPART=0) trebuie sa verific daca am inregistrare
-- cu cod zero in NPART

  IF aCODPART = 0 THEN
    SELECT COUNT(*) INTO NR FROM NPART WHERE CodPART = 0;
    IF Nr = 0 THEN
      INSERT INTO NPART (CodPART, DEN_PART) VALUES (0, &apos;... nedefinit ...&apos;);
    END IF;
  END IF;
 
  IF OPERATION = 0 THEN  -- UPDATE
    SELECT CODPARTTR INTO RecId FROM TMP_NPARTTR_2;
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT substr(delegat,100) INTO aDoc FROM TMP_NPARTTR_2;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARTTR&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NPARTTR SET 
    ( CODPART, DELEGAT, CNP, OBS, 
      permis, nrpass, codtara,adresa, CodLocalit, Telefon,
		  DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, IMPLICIT, CODPERS, CODAUTO)
       = ( SELECT CODPART, DELEGAT, CNP, OBS, 
                  permis, nrpass, codtara,adresa, CodLocalit, Telefon,
			            DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, IMPLICIT, CODPERS, CODAUTO
          FROM TMP_NPARTTR_2 )
    WHERE CODPARTTR = RECID;
  ELSE  -- INSERT
  SELECT SEQ_NPARTTR_CODPARTTR.NEXTVAL INTO RecId FROM DUAL;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT substr(delegat,100) INTO aDoc FROM TMP_NPARTTR_2;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARTTR&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO NPARTTR 
  ( CODPARTTR, CODPART, DELEGAT, CNP, OBS,       
	  permis, nrpass, codtara,adresa, CodLocalit,Telefon,
    DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, IMPLICIT, CODPERS, CODAUTO)
  (SELECT 
	  RECID, CODPART, DELEGAT, CNP, OBS, 
	  permis, nrpass, codtara,adresa, CodLocalit, Telefon,
		DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, IMPLICIT, CODPERS, CODAUTO FROM TMP_NPARTTR_2);
  END IF;

  NotifyModif(Operation, RecId, &apos;NPARTTR&apos;);
  COMMIT;
END;

END PKG_DELEGATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44BA8DDA1A428589FDEBCA8E830FB97386F64CC5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DESCRIPTORI IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODDESCRIPTOR INTO Tmp FROM DESCRIPTORI WHERE CODDESCRIPTOR = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM DESCRIPTORI1 WHERE CODDESCRIPTOR = RecId ;
  DELETE FROM DESCRIPTORI WHERE CODDESCRIPTOR = RecId ;
  NotifyModif(2, RecId, &apos;DESCRIPTORI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DESCRIPTORI FIELDS( CODDESCRIPTOR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  INSERT INTO  TMP_DESCRIPTORI ( CODDESCRIPTOR,DEN_DESCRIPTOR,SIMBOL,TIP)
     SELECT CODDESCRIPTOR,DEN_DESCRIPTOR,SIMBOL,TIP FROM DESCRIPTORI WHERE CODDESCRIPTOR = RecId  ;

  INSERT INTO TMP_DESCRIPTORI1(CODDESCRIPTOR1,CODDESCRIPTOR,VALOARE,CODASOCIAT)
   SELECT CODDESCRIPTOR1,CODDESCRIPTOR,VALOARE,CODASOCIAT FROM DESCRIPTORI1 WHERE CODDESCRIPTOR = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS

BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CODDESCRIPTOR INTO RecId FROM TMP_DESCRIPTORI;

    UPDATE DESCRIPTORI SET ( DEN_DESCRIPTOR,SIMBOL,TIP )
       = ( SELECT DEN_DESCRIPTOR,SIMBOL,TIP  FROM TMP_DESCRIPTORI )
      WHERE CODDESCRIPTOR = RecId ;


    DELETE FROM DESCRIPTORI1 where CODDESCRIPTOR = RecId and CODDESCRIPTOR1 not in (Select CODDESCRIPTOR1 from TMP_DESCRIPTORI1);

    INSERT INTO DESCRIPTORI1 ( CODDESCRIPTOR1,CODDESCRIPTOR,VALOARE,CODASOCIAT )
      SELECT SEQ_DESCRIPT1_CODDESCRIPTOR1.Nextval , RecId ,VALOARE,CODASOCIAT
      FROM TMP_DESCRIPTORI1 WHERE CODDESCRIPTOR1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_DESCRIPTORI1 WHERE NVL(CODDESCRIPTOR1,-1) &gt; 0 ORDER BY CODDESCRIPTOR1 ) LOOP
       UPDATE DESCRIPTORI1
       SET
        VALOARE    = V_REC.VALOARE,
        CODASOCIAT = V_REC.CODASOCIAT
       WHERE CODDESCRIPTOR1  = v_rec.CODDESCRIPTOR1;
    END LOOP;
  ELSE  -- INSERT

  SELECT SEQ_DESCRIP_CODDESCRIPTOR.NextVal INTO RecId FROM DUAL;

  INSERT INTO  DESCRIPTORI ( CODDESCRIPTOR,DEN_DESCRIPTOR,SIMBOL,TIP)
  SELECT  RecId, DEN_DESCRIPTOR,SIMBOL,TIP  FROM TMP_DESCRIPTORI   ;


  INSERT INTO  DESCRIPTORI1(CODDESCRIPTOR1,CODDESCRIPTOR,VALOARE,CODASOCIAT)
      SELECT  SEQ_DESCRIPT1_CODDESCRIPTOR1.Nextval ,RecId,VALOARE,CODASOCIAT FROM TMP_DESCRIPTORI1 ;

END IF;
  NotifyModif(Operation, RecId, &apos;DESCRIPTORI&apos;);
  COMMIT;
END;

FUNCTION  GetDenAsociat (pTip IN NUMBER, pCodAsociat IN NUMBER) RETURN VARCHAR2
IS
  sDenAsociat VARCHAR2(200) := &apos;&apos;;
BEGIN
  CASE pTip
    WHEN   2 THEN SELECT DEN_CONT           INTO sDenAsociat FROM NCONT     WHERE CODCONT     = pCodAsociat;
    WHEN  11 THEN SELECT DEN_MONEDA         INTO sDenAsociat FROM NMONEDE   WHERE CODMONEDA   = pCodAsociat;
    WHEN  22 THEN SELECT DENUMIRE           INTO sDenAsociat FROM NARTOBJ   WHERE CODOBIECT   = pCodAsociat;
    WHEN  50 THEN SELECT NUME||&apos; &apos;||PRENUME INTO sDenAsociat FROM NPERS     WHERE CODPERS     = pCodAsociat;
    WHEN  60 THEN SELECT DEN_PART           INTO sDenAsociat FROM NPART     WHERE CODPART     = pCodAsociat;
    WHEN  70 THEN SELECT DEN_SUBUNIT        INTO sDenAsociat FROM NSUBUNIT  WHERE CODSUBUNIT  = pCodAsociat;
    WHEN  80 THEN SELECT DEN_TARA           INTO sDenAsociat FROM NTARI     WHERE CODTARA     = pCodAsociat;
    WHEN  81 THEN SELECT DEN_JUDET          INTO sDenAsociat FROM NJUDET    WHERE CODJUDET    = pCodAsociat;
    WHEN  82 THEN SELECT DEN_LOCALIT        INTO sDenAsociat FROM NLOCALIT  WHERE CODLOCALIT  = pCodAsociat;
    WHEN  85 THEN SELECT DEN_ACTIVIT        INTO sDenAsociat FROM NACTIVIT  WHERE CODACTIVIT  = pCodAsociat;
    WHEN  90 THEN SELECT DEN_FORMATIE       INTO sDenAsociat FROM FORMATII  WHERE CODFORMATIE = pCodAsociat;
    WHEN 100 THEN SELECT DEN_CLASEA         INTO sDenAsociat FROM NCLASEA   WHERE CODCLASEA   = pCodAsociat;
    WHEN 101 THEN SELECT NOBJ.DENUMIRE||&apos; &apos;|| 
                    CASE WHEN u.MODEL IS NOT NULL THEN u.MODEL
                                                ELSE &apos;&apos; END ||
                    CASE WHEN u.SERIEF IS NOT NULL THEN CASE WHEN u.MODEL IS NOT NULL THEN &apos;;&apos;||u.SERIEF
                                                           ELSE u.SERIEF END
                         ELSE &apos;&apos; END INTO sDenAsociat 
                    FROM UTILAJE u JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = U.CODOBIECT 
                    WHERE CODUTILAJ   = pCodAsociat;
    ELSE NULL;
  END CASE;

  RETURN sDenAsociat;
END;



end PKG_DESCRIPTORI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DESTINATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F886B09F2560458535D7DF6F5479F652FFEC2028</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_destinatii is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codDestinatie INTO Tmp FROM destinatii WHERE codDestinatie = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM destinatii WHERE codDestinatie = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_destinatii FIELDS( codDestinatie ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_destinatii 
	(  codDestinatie      ,
  numedestinatie     ,
  PENTRU             ,
  SEZON              ,
  ARTICOL            ,
  ACTIVITATE            
	)
	SELECT 
  codDestinatie      ,
  numedestinatie     ,
  PENTRU             ,
  SEZON              ,
  ARTICOL            ,
  ACTIVITATE             
  FROM destinatii WHERE codDestinatie = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT codDestinatie INTO RECID FROM TMP_destinatii;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE destinatii
    SET
     (
  numedestinatie     ,
  PENTRU             ,
  SEZON              ,
  ARTICOL            ,
  ACTIVITATE  
			)
			= 
			(SELECT
  numedestinatie     ,
  PENTRU             ,
  SEZON              ,
  ARTICOL            ,
  ACTIVITATE 
		FROM TMP_destinatii)
    WHERE codDestinatie = RECID;

ELSE  -- INSERT
    SELECT SEQ_destinatii_codDestinatie.NextVal INTO RecId FROM DUAL;
    INSERT INTO destinatii(
  codDestinatie      ,
  numedestinatie     ,
  PENTRU             ,
  SEZON              ,
  ARTICOL            ,
  ACTIVITATE 
    )
    SELECT 
  	RECID   , 
      numedestinatie     ,
       PENTRU             ,
        SEZON              ,
        ARTICOL            ,
        ACTIVITATE  
		FROM TMP_destinatii;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;destinatii&apos;);
  COMMIT;
 
END;


end PKG_destinatii; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DETALIIET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C352D1EC2118E6F6BD8AC945B4CE10CE9F1E8482</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DETALIIET IS

gCodDoc number(20);
gTipDoc number(20);
gTipTranz number(20);
gTipET   number(20);

procedure getTipLocIncDesc(aTipDoc             in number,
                           aStatIntracomunitar in number,
                           aSimbAuto           in Varchar2,
                           aTipET              in number,
                           aTipLocInc          out number,
                           aTipLocDesc         out number,
                           aStatIntracomunitar2 in number,
                           aSimbAuto2           in Varchar2
) is
begin
  case
    when (aTipDoc in (1, 2, 5)) and (coalesce(aStatIntracomunitar, 0) = 1) and
         upper(aSimbAuto) &lt;&gt; &apos;RO&apos; then
      if aTipET in (99991, 99992, 99995) then
        aTipLocInc  := 2;
        aTipLocDesc := 1;
      else
        aTipLocInc  := 2;
        aTipLocDesc := 1;
      end if;
    when (aTipDoc in (2, 5)) and (coalesce(aStatIntracomunitar, 0) &lt;&gt; 1) and
         upper(aSimbAuto) &lt;&gt; &apos;RO&apos; then
      aTipLocInc  := 3;
      aTipLocDesc := 1;
    when (aTipDoc in (-19, 19, 20)) and
         (coalesce(aStatIntracomunitar, 0) = 1) and
         upper(aSimbAuto) &lt;&gt; &apos;RO&apos; then
      if aTipET in (99993, 99994, 99996) then
        aTipLocInc  := 1;
        aTipLocDesc := 2;
      else
        aTipLocInc  := 1;
        aTipLocDesc := 2;
      end if;
    when (aTipDoc in (-19, 19, 20)) and
         (coalesce(aStatIntracomunitar, 0) &lt;&gt; 1) and
         upper(aSimbAuto) &lt;&gt; &apos;RO&apos; then
      aTipLocInc  := 1;
      aTipLocDesc := 3;
     when (aTipDoc in (23)) then
       if (coalesce(aStatIntracomunitar, 0) = 1) and (upper(aSimbAuto) &lt;&gt; &apos;RO&apos;) then
          aTipLocDesc := 2;
       else if (coalesce(aStatIntracomunitar, 0) &lt;&gt; 1) and (upper(aSimbAuto) &lt;&gt; &apos;RO&apos;) then 
               aTipLocDesc := 3;    
             else 
               aTipLocDesc := 1;
             end if;  
       end if;
       if (coalesce(aStatIntracomunitar2, 0) = 1) and (upper(aSimbAuto2) &lt;&gt; &apos;RO&apos;) then
          aTipLocInc := 2;
       else if (coalesce(aStatIntracomunitar2, 0) &lt;&gt; 1) and (upper(aSimbAuto2) &lt;&gt; &apos;RO&apos;) then 
               aTipLocInc := 3;    
            else 
               aTipLocInc := 1;
            end if;   
       end if;
    else
      aTipLocInc  := 1;
      aTipLocDesc := 1;
  end case;
end;

PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number,  aTipET in number, aCodDetaliu  out number, aTipTranzactie in number default null ) is
  vCodLocDest number(20);
  vAdresaDest varchar2(150);
  vCodLocInc number(20);
  vAdresaInc varchar2(150);
  
  vCodLocDestUpd number(20);
  vAdresaDestUpd varchar2(150);
  vCodLocIncUpd number(20);
  vAdresaIncUpd varchar2(150);
  
  vSimbAuto varchar2(3);
  
  vIsStorno number(1);
  
  vNrTransp VARCHAR2(30);
  
  vStatIntracomunitar number(1);
  vTipET    number(6);
  vTipLocInc number(5);
  vTipLocDesc number(5);
  vStatIntracomunitar2 number(1);
  vSimbAuto2 varchar2(3);

begin
  gCodDoc := aCodDoc;
  gTipDoc := aTipDoc;
  gTipTranz := aTipTranzactie;
  vIsStorno := -1;
	gTipET    := aTipET;

  
  BEGIN
    SELECT CODDETALIU into aCODDETALIU FROM DETALIIET
    WHERE
      CODDOC = aCODDOC
      AND TIPDOC = aTIPDOC;
    EXCEPTION WHEN OTHERS THEN
      aCODDETALIU := 0;    
  END;  
  vSimbAuto := &apos;&apos;;
  vNrTransp  := null;
  IF aCodDetaliu = 0 THEN
    vStatIntracomunitar2 := null;
    vSimbAuto2 := null;     
    case 
      when gTipDoc in (19,20) then 
                             select  
                             case when (i.tiptranzactie in (2,3) and i.tipdoc = 19)
                                                   or (i.tipdoc = 20 and upper(t.simbauto) &lt;&gt; &apos;RO&apos;)   then null else locc_desc.codlocalit end,  
                             case when (i.tiptranzactie in (2,3) and i.tipdoc = 19)
                                                   or (i.tipdoc = 20 and upper(t.simbauto) &lt;&gt; &apos;RO&apos;)  then null 
                                                       else substr(GetAdresa(nag_desc.SECTOR, nag_desc.STRADA, nag_desc.NR1, nag_desc.NR2, nag_desc.BLOC, nag_desc.SCARA, nag_desc.ETAJ, nag_desc.APART, nag_desc.codpostal) ,1,150) end,
                             locc_inc.codlocalit ,  
                             substr(GetAdresa(nag_inc.SECTOR, nag_inc.STRADA, nag_inc.NR1, nag_inc.NR2, nag_inc.BLOC, nag_inc.SCARA, nag_inc.ETAJ, nag_inc.APART, nag_inc.codpostal) ,1,150),
                             case when i1s.cant &gt;= 0 then 0 else 1 end,
                             t.simbauto, i.nrtransp, t.statcomunitar, i.tipet 
                             into vCodLocDest, vAdresaDest, vCodLocInc, vAdresaInc, vIsStorno, vSimbAuto, vNrTransp, vStatIntracomunitar, vTipET
                             from iesiri i  
                                  left join (select i1.codies, sum(i1.cant) as cant from iesiri1 i1 group by i1.codies) i1s on i1s.codies = i.codies
                                  left join nagenda nag_desc on nag_desc.codagenda = i.codlocatie 
                                  left join nagenda nag_inc on nag_inc.codsubunit = i.subunitatea
                                  left join nlocalit locc_desc on locc_desc.codlocalit = nag_desc.codlocalit
                                  left join nlocalit locc_inc on locc_inc.codlocalit = nag_inc.codlocalit
                                  left join ntari t on t.codtara = locc_desc.codtara
                             where i.codies = gCodDoc;
       when gTipDoc in (-19) then 
                             select  
                              locc_desc.codlocalit,  
                              substr(GetAdresa(nag_desc.SECTOR, nag_desc.STRADA, nag_desc.NR1, nag_desc.NR2, nag_desc.BLOC, nag_desc.SCARA, nag_desc.ETAJ, nag_desc.APART, nag_desc.codpostal) ,1,150),
                             locc_inc.codlocalit ,  
                             substr(GetAdresa(nag_inc.SECTOR, nag_inc.STRADA, nag_inc.NR1, nag_inc.NR2, nag_inc.BLOC, nag_inc.SCARA, nag_inc.ETAJ, nag_inc.APART, nag_inc.codpostal) ,1,150),
                             case when i1s.cant &gt;= 0 then 0 else 1 end,
                             t.simbauto, i.nrtransp, t.statcomunitar, i.tipet 
                             into vCodLocDest, vAdresaDest, vCodLocInc, vAdresaInc, vIsStorno, vSimbAuto, vNrTransp, vStatIntracomunitar, vTipET
                             from iesiriretail i  
                                  left join (select i1.CODIESRETAIL, sum(i1.cant) as cant from iesiri1retail i1 group by i1.CODIESRETAIL) i1s on i1s.CODIESRETAIL = i.CODIESRETAIL
                                  left join NSEDIIPARTRETAIL nag_desc on nag_desc.CODSEDIU = i.CODSEDIURETAIL 
                                  left join nagenda nag_inc on nag_inc.codsubunit = i.subunitatea
                                  left join nlocalit locc_desc on locc_desc.codlocalit = nag_desc.codlocalit
                                  left join nlocalit locc_inc on locc_inc.codlocalit = nag_inc.codlocalit
                                  left join ntari t on t.codtara = locc_desc.codtara
                             where i.CODIESRETAIL = gCodDoc;                             
       when gTipDoc in (23) then
                             select  locc_desc.codlocalit ,  
                             substr(GetAdresa(nag_desc.SECTOR, nag_desc.STRADA, nag_desc.NR1, nag_desc.NR2, nag_desc.BLOC, nag_desc.SCARA, nag_desc.ETAJ, nag_desc.APART, nag_desc.codpostal) ,1,150),
                             locc_inc.codlocalit ,  
                             substr(GetAdresa(nag_inc.SECTOR, nag_inc.STRADA, nag_inc.NR1, nag_inc.NR2, nag_inc.BLOC, nag_inc.SCARA, nag_inc.ETAJ, nag_inc.APART, nag_inc.codpostal) ,1,150),
                             case when i1s.cant &gt;= 0 then 0 else 1 end, i.nrtransp, t.statcomunitar, t.simbauto, i.tipet, t2.statcomunitar, t2.simbauto  
                             into vCodLocDest, vAdresaDest, vCodLocInc, vAdresaInc, vIsStorno, vNrTransp, vStatIntracomunitar, vSimbAuto, vTipET, vStatIntracomunitar2, vSimbAuto2
                             from iesiri i 
                                  left join (select i1.codies, sum(i1.cant) as cant from iesiri1 i1 group by i1.codies) i1s on i1s.codies = i.codies
                                  left join nagenda nag_desc on nag_desc.codsubunit = i.codsubunit and nag_desc.tip = 8 
                                  left join nagenda nag_inc on nag_inc.codsubunit = i.subunitatea and nag_inc.tip = 8
                                  left join nlocalit locc_desc on locc_desc.codlocalit = nag_desc.codlocalit
                                  left join nlocalit locc_inc on locc_inc.codlocalit = nag_inc.codlocalit
                                  left join ntari t on t.codtara = locc_desc.codtara
                                  left join ntari t2 on t2.codtara = locc_inc.codtara
                             where i.codies = gCodDoc;
       when gTipDoc in (1,2,5) then
                             select  locc_desc.codlocalit ,  
                             substr(GetAdresa(nag_desc.SECTOR, nag_desc.STRADA, nag_desc.NR1, nag_desc.NR2, nag_desc.BLOC, nag_desc.SCARA, nag_desc.ETAJ, nag_desc.APART, nag_desc.codpostal) ,1,150),
                             null ,  
                             null, t.statcomunitar, t.simbauto, i.tipet  
                             into vCodLocDest, vAdresaDest, vCodLocInc, vAdresaInc, vStatIntracomunitar, vSimbAuto, vTipET
                             from intrari i 
                                  left join nagenda nag_desc on nag_desc.codsubunit = i.subunitatea
                                  left join nagenda nag_inc on nag_inc.codagenda = i.codlocatie 
                                  left join nlocalit locc_inc on locc_inc.codlocalit = nag_inc.codlocalit
                                  left join nlocalit locc_desc on locc_desc.codlocalit = nag_desc.codlocalit
                                  left join ntari t on t.codtara = locc_inc.codtara
                             where i.codintr = gCodDoc;
      when gTipDoc in (12) then 
                             select  
                             locc_desc.codlocalit,  
                             substr(GetAdresa(nag_desc.SECTOR, nag_desc.STRADA, nag_desc.NR1, nag_desc.NR2, nag_desc.BLOC, nag_desc.SCARA, nag_desc.ETAJ, nag_desc.APART, nag_desc.codpostal) ,1,150),
                             locc_inc.codlocalit ,  
                             substr(GetAdresa(nag_inc.SECTOR, nag_inc.STRADA, nag_inc.NR1, nag_inc.NR2, nag_inc.BLOC, nag_inc.SCARA, nag_inc.ETAJ, nag_inc.APART, nag_inc.codpostal) ,1,150),
                             case when t1s.cant &gt;= 0 then 0 else 1 end, t.statcomunitar, t.simbauto, t.tipet
                             into vCodLocDest, vAdresaDest, vCodLocInc, vAdresaInc, vIsStorno, vStatIntracomunitar, vSimbAuto, vTipET
                             from transf t 
                                  left join (select t1.codtransf, sum(t1.cant) as cant from transf1 t1 group by t1.codtransf) t1s on t1s.codtransf = t.codtransf 
                                  left join nagenda nag_desc on nag_desc.codgest  = t.codgestcmd 
                                  left join nagenda nag_inc on nag_inc.codsubunit = t.subunitatea
                                  left join nlocalit locc_desc on locc_desc.codlocalit = nag_desc.codlocalit
                                  left join nlocalit locc_inc on locc_inc.codlocalit = nag_inc.codlocalit
                                  left join ntari t on t.codtara = locc_desc.codtara
                             where t.codtransf = gCodDoc;
        else  vCodLocDest := null;
                vAdresaDest  := null;
                vCodLocInc   :=  null; 
                vAdresaInc    := null;   
                vNrTransp     := null; 
                vStatIntracomunitar2 := null;
                vSimbAuto2 := null;               
    end case;
    
    getTipLocIncDesc(gTipDoc, vStatIntracomunitar, vSimbAuto, vTipET, vTipLocInc, vTipLocDesc, vStatIntracomunitar2, vSimbAuto2);
     
    vCodLocDestUpd := vCodLocDest;
    vAdresaDestUpd  := vAdresaDest;
    vCodLocIncUpd   := vCodLocInc;
    vAdresaIncUpd    := vAdresaInc;   
    if vIsStorno = 1 then 
      case 
           when gTipDoc in (12,23) then
                 vCodLocDestUpd := vCodLocInc;
                 vAdresaDestUpd  := vAdresaInc;
                 vCodLocIncUpd   := vCodLocDest;
                 vAdresaIncUpd    := vAdresaDest;
            when gTipDoc in (19,20) and upper(vSimbAuto) = &apos;RO&apos; then 
                 vCodLocDestUpd := vCodLocInc;
                 vAdresaDestUpd  := vAdresaInc;
                 vCodLocIncUpd   := vCodLocDest;
                 vAdresaIncUpd    := vAdresaDest;     
           else 
                 vCodLocDestUpd := vCodLocDest;
                 vAdresaDestUpd  := vAdresaDest;
                 vCodLocIncUpd   := vCodLocInc;
                 vAdresaIncUpd    := vAdresaInc;
      end case;
      
    end if;
    
    aCODDETALIU := SEQ_DETALIIET_CODDETALIU.NEXTVAL;
    INSERT INTO DETALIIET(CODDETALIU, CODDOC, TIPDOC, DATATRANSPORT, CODLOCDESC, ADRESADESC, CODLOCINC, ADRESAINC, NRAUTO, TIPLOCINC, TIPLOCDESC )
    VALUES(aCODDETALIU, aCodDoc, aTipDoc, TRUNC(SYSDATE), vCodLocDestUpd, vAdresaDestUpd, vCodLocIncUpd, vAdresaIncUpd,substr(trim(vNrTransp),1,15), vTipLocInc, vTipLocDesc);
  END IF; 
end;

procedure updateDetalii(aCodDoc in number , aTipDoc in number) is
  vStatIntracomunitar number(1);
  vSimbAuto varchar2(3);
  vTipET    number(6);
  vTipLocInc number(5);
  vTipLocDesc number(5);
  vStatIntracomunitar2 number(1);
  vSimbAuto2 varchar2(3);
begin
  vStatIntracomunitar2 := null;
  vSimbAuto2 := null;
  case 
    when aTipDoc in (19, 20) then 
                                          select
                                             t.statcomunitar,
                                             t.simbauto,
                                             i.tipet
                                           into vStatIntracomunitar, vSimbAuto, vTipET 
                                           from iesiri i 
                                                left join nagenda nag on nag.codagenda = i.codlocatie 
                                                left join nlocalit locc on locc.codlocalit = nag.codlocalit
                                                left join ntari t on t.codtara = locc.codtara
                                           where i.codies = aCodDoc;
    when aTipDoc in (-19) then 
                                          select
                                             t.statcomunitar,
                                             t.simbauto,
                                             i.tipet
                                           into vStatIntracomunitar, vSimbAuto, vTipET 
                                           from iesiriretail i 
                                                left join NSEDIIPARTRETAIL nag on nag.CODSEDIU = i.CODSEDIURETAIL
                                                left join nlocalit locc on locc.codlocalit = nag.codlocalit
                                                left join ntari t on t.codtara = locc.codtara
                                           where i.codiesretail = aCodDoc;                                           
    when aTipDoc in (23) then 
                                          select
                                             t.statcomunitar,
                                             t.simbauto,
                                             i.tipet,
                                             t2.statcomunitar,
                                             t2.simbauto
                                           into vStatIntracomunitar, vSimbAuto, vTipET, vStatIntracomunitar2, vSimbAuto2
                                           from iesiri i 
                                                left join nagenda nag on nag.codsubunit = i.codsubunit 
                                                left join nlocalit locc on locc.codlocalit = nag.codlocalit
                                                left join ntari t on t.codtara = locc.codtara
                                                left join nagenda nag2 on nag2.codsubunit = i.subunitatea 
                                                left join nlocalit locc2 on locc2.codlocalit = nag2.codlocalit
                                                left join ntari t2 on t2.codtara = locc2.codtara
                                                
                                           where i.codies = aCodDoc;
                                              
    when aTipDoc in (1, 2, 5) then
                                         select
                                           t.statcomunitar,
                                           t.simbauto,
                                           i.tipet
                                         into vStatIntracomunitar, vSimbAuto, vTipET
                                         from intrari i 
                                              left join nagenda nag on nag.codagenda = i.codlocatie 
                                              left join nlocalit locc on locc.codlocalit = nag.codlocalit
                                              left join ntari t on t.codtara = locc.codtara
                                         where i.codintr = aCodDoc;
    else 
      vStatIntracomunitar := null;
      vSimbAuto := null;
      vTipET   := null;
      vStatIntracomunitar2 := null;
      vSimbAuto2 := null;
    end case;
    getTipLocIncDesc(aTipDoc, vStatIntracomunitar, vSimbAuto, vTipET, vTipLocInc, vTipLocDesc, vStatIntracomunitar2, vSimbAuto2); 
    update tmp_detaliiet d
       set STATCOMUNITAR  = vStatIntracomunitar,
           SIMBAUTO       = vSimbAuto,
           tipet          = vTipET,
           STATCOMUNITAR2 = vStatIntracomunitar2,
           SIMBAUTO2      = vSimbAuto2;
    update tmp_detaliiet d set tiplocinc = vTipLocInc, tiplocdesc = vTipLocDesc where d.tiplocinc is null or d.tiplocdesc is null;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
begin
  
  if gTipDoc in (1,2,3,4,5,6,7,9) then
      pkg_intrari.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (14,15,16,19,20,21,22,23,24,26) then
      pkg_iesiri.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (12,13) then
      pkg_miscari_interne.SP_LOCKRECORD(gCodDoc);
  end if;

END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  execute immediate
  &apos; delete from detaliiET d where &apos;||
    &apos; d.coddoc = &apos;||gCodDoc||&apos; and d.tipdoc = &apos;||gTipDoc ;
    
  NotifyModif(2, RecId, &apos;DETALIIET&apos;);
  COMMIT;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO tmp_detaliiET(coddetaliu) VALUES (0);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
BEGIN
   insert into tmp_detaliiET(coddetaliu,
                                        coddoc,
                                        tipdoc,
                                        codLocInc,
                                        adresaInc,
                                        datatransport,
                                        codLocDesc,
                                        adresaDesc,
                                        codPTF,
                                        codptfdesc,
                                        codBV, 
                                        CodPartTR, 
                                        nrauto,
                                        nrremorca1,
                                        nrremorca2,
                                        tiptranzactie,
                                        codpartretailtr,
                                        greutate_bruta,
                                        tiplocinc,
                                        tiplocdesc,
                                        uit, TipET, Tipmediu, Coddetaliu1, IDIncarcare, Stare
																				)
    select  det.coddetaliu,
            det.coddoc,
            det.tipdoc,
            det.codLocInc,
            det.adresaInc,
            det.datatransport,
            det.codLocDesc,
            det.adresaDesc,
            det.codPTF,
            det.codptfdesc,
            det.codBV, 
            det.CodPartTR, 
            det.nrauto,
            det.nrremorca1,
            det.nrremorca2,
            gTipTranz,
            det.codpartretailtr,
            det.greutate_bruta,
            det.tiplocinc,
            det.tiplocdesc,
            stdl.uit, gTipET, stdl.Tipmediu, stdl.IDDescarcare, stdl.IDIncarcare, stdl.Stare
    from 
      detaliiET det
    left join statusdecl stdl on stdl.coddoc = det.coddoc and stdl.tipdoc = det.tipdoc+100   
    where 
      coddetaliu = recid;--coddoc = gCodDoc and tipdoc = gTipDoc;
     
   updateDetalii(gCodDoc,  gTipDoc);   
   
   insert into tmp_detaliiET1(  CODDETALIUET1,
                                CODDETALIUET  ,  
                                DATATRANSPORT ,
                                NRAUTO        ,
                                NRREMORCA1    ,
                                NRREMORCA2    ,
                                OBS )
                        select  CODDETALIUET1,
                                CODDETALIUET  ,  
                                DATATRANSPORT ,
                                NRAUTO        ,
                                NRREMORCA1    ,
                                NRREMORCA2    ,
                                OBS 
    from 
      detaliiET1 
    where 
      CODDETALIUET = recid;
   
   commit;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
NR number;
BEGIN		
   IF Operation = 0 THEN  -- UPDATE
   Select CodDetaliu into RecID from Tmp_Detaliiet;
 	 UPDATE DETALIIET
		 SET
			(codLocInc  , 
			adresaInc   , 
			datatransport     , 
			codLocDesc  , 
			adresaDesc  ,
			codPTF      ,
      codptfdesc , 
			codBV,
      CodPartTR, 
      nrauto,
      nrremorca1,
      nrremorca2,
      codpartretailtr,
      greutate_bruta,
      tiplocinc,
      tiplocdesc       ) = 
		 (Select
			codLocInc  , 
			adresaInc   , 
			datatransport     , 
			codLocDesc  , 
			adresaDesc  , 
			codPTF      ,
      codptfdesc ,  
			codBV,
      CodPartTR, 
      nrauto,
      nrremorca1,
      nrremorca2,
      codpartretailtr,
      greutate_bruta,
      tiplocinc,
      tiplocdesc         
     FROM 
       TMP_DETALIIET
      )
     WHERE
       coddetaliu =  RecID;
       
    DELETE FROM DetaliiET1
       where CODDETALIUET = RecId
         and CODDETALIUET1 not in (Select ts0.CODDETALIUET1 from TMP_DETALIIET1 ts0);
   
     update DetaliiET1 dt
           set (  CODDETALIUET1,
                  CODDETALIUET  ,  
                  DATATRANSPORT ,
                  NRAUTO        ,
                  NRREMORCA1    ,
                  NRREMORCA2    ,
                  OBS ) =
            (select  CODDETALIUET1,
                    CODDETALIUET  ,  
                    DATATRANSPORT ,
                    NRAUTO        ,
                    NRREMORCA1    ,
                    NRREMORCA2    ,
                    OBS 
             from TMP_DETALIIET1 tdt 
             WHERE tdt.CODDETALIUET1 &gt; 0 and tdt.CODDETALIUET1 = dt.CODDETALIUET1)
       WHERE dt.CODDETALIUET = RecId;
       
       insert into DetaliiET1 dt ( CODDETALIUET1,
                                   CODDETALIUET  ,  
                                   DATATRANSPORT ,
                                   NRAUTO        ,
                                   NRREMORCA1    ,
                                   NRREMORCA2    ,
                                   OBS )
            (select  SEQ_DETALIIET1_CODDETALIUET1.Nextval,
                    CODDETALIUET  ,  
                    DATATRANSPORT ,
                    NRAUTO        ,
                    NRREMORCA1    ,
                    NRREMORCA2    ,
                    OBS 
             from TMP_DETALIIET1 tdt 
             WHERE tdt.CODDETALIUET1 &lt; 0 );
  
    ELSE  -- INSERT
      RecID := SEQ_DETALIIET_CODDETALIU.Nextval; 
      INSERT INTO DETALIIET  (  coddetaliu,
                                             coddoc,
                                             tipdoc,
                                             codLocInc,
                                             adresaInc,
                                             datatransport,
                                             codLocDesc,
                                             adresaDesc,
                                             codPTF,
                                             codptfdesc , 
                                             codBV, 
                                             CodPartTR, 
                                             nrauto,
                                             nrremorca1,
                                             nrremorca2,
                                             codpartretailtr,
                                             greutate_bruta,
                                             tiplocinc,
                                             tiplocdesc   )
      SELECT RecID ,
                                           gCodDoc,
                                           gTipDoc,
                                           codLocInc,
                                           adresaInc,
                                           datatransport,
                                           codLocDesc,
                                           adresaDesc,
                                           codPTF,
                                           codptfdesc , 
                                           codBV,
                                           CodPartTR,
                                           nrauto,
                                           nrremorca1,
                                           nrremorca2,
                                           codpartretailtr,
                                           greutate_bruta,
                                           tiplocinc,
                                           tiplocdesc  
      FROM TMP_detaliiET;
       insert into DetaliiET1 dt ( CODDETALIUET1,
                             CODDETALIUET  ,  
                             DATATRANSPORT ,
                             NRAUTO        ,
                             NRREMORCA1    ,
                             NRREMORCA2    ,
                             OBS )
      (select  SEQ_DETALIIET1_CODDETALIUET1.Nextval,
              RecID  ,  
              DATATRANSPORT ,
              NRAUTO        ,
              NRREMORCA1    ,
              NRREMORCA2    ,
              OBS 
       from TMP_DETALIIET1 tdt 
       WHERE tdt.CODDETALIUET1 &lt; 0 );

    END IF;
  for v in (Select distinct CODUNIC from tmp_Manevra) loop
   Select Count(*) into Nr from Detaliiet where CodDoc = V.CodUnic and TipDoc = gTipDoc;
   IF Nr = 0 THEN SET_VARIABILE(v.codunic, gTipDoc, RecID, gTipTranz); END IF;
	 UPDATE DETALIIET
		 SET
			(codLocInc  , 
			adresaInc   , 
			datatransport     , 
			codPTF      , 
      codptfdesc ,
			codBV,
       CodPartTR, 
      nrauto,
      nrremorca1,
      nrremorca2,
      codpartretailtr,
      greutate_bruta,
      tiplocinc,
      tiplocdesc         ) = 
		 (Select
			codLocInc  , 
			adresaInc   , 
			datatransport     , 
			codPTF      ,
      codptfdesc , 
			codBV,
      CodPartTR, 
      nrauto,
      nrremorca1,
      nrremorca2,
      codpartretailtr,
      greutate_bruta,
      tiplocinc,
      tiplocdesc       
     FROM 
       TMP_DETALIIET
      )
     WHERE
       CodDoc = V.CODUNIC and TipDoc = gTipDoc;
	end loop;
  NotifyModif(Operation, RecId, &apos;detaliiET&apos;);    
  commit;
END;

end PKG_DETALIIET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DIFICULTATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03DD67D6D674F8A85BA2EC9FEB0B8F1FDA6655DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DIFICULTATI IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodDif INTO Tmp FROM DIFICULTATI WHERE CodDif = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM DIFICULTATI WHERE CodDif = RecId ;
  NotifyModif(2, RecId, &apos;DIFICULTATI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_DIFICULTATI FIELDS( CodDif ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_DIFICULTATI ( CodDif, Denumire )
    ( SELECT CodDif, Denumire
      FROM DIFICULTATI WHERE CodDif = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

  SELECT CodDif INTO RecId FROM TMP_DIFICULTATI;

  UPDATE DIFICULTATI SET ( Denumire )
       = ( SELECT Denumire
          FROM TMP_DIFICULTATI )
      WHERE CodDif = RecId ;

  ELSE  -- INSERT
  
  SELECT SEQ_DIFICULTATI_CODDIF.NextVal INTO RecId FROM DUAL;

  INSERT INTO DIFICULTATI ( CodDif, Denumire )
 ( SELECT  RecId, Denumire
     FROM TMP_DIFICULTATI  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;DIFICULTATI&apos;);
  
  COMMIT;
END;

end pkg_dificultati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DIFPRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6109430552F88131BFCA13296E942A5953DF3599</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DIFPRETPROD IS

procedure MarkDirty_DifPretPRod is
  nr number;
begin
  for v_rec in (select CodDIFPretPROD from DIFPretPROD where AN*12+Luna = PKG_GLOBALS.ANLUNALUCRU) loop
     select Count(*) into nr 
     from DIFPRETPROD1 pn1
          inner join comanda1 c1 on pn1.CodCOMANDA1   = c1.codcomanda1
          inner join nartobj obj on obj.codobiect = c1.codobiect  
          inner join Tmp_Nartobj_Luna obj1 on obj1.codobiect = c1.codobiect  
          inner join NirStoc Ns   on  pn1.codNirStoc = Ns.codNirStoc
     where pn1.CODDIFPretPROD = v_rec.CODDIFPretPROD and 
           (Round(pn1.DifPret - (Nvl(obj1.ValMat,0) + (2-Nvl(obj1.TipPret,1))*(Nvl(obj1.ValMan,0) + Nvl(obj1.ValRegie,0)) - NS.Pret),2) &lt;&gt; 0); 
     if Nr &gt; 0 then 
       update JURNAL1 set Dirty = 1 
       where TipDoc = 80 and CodDoc = v_rec.codDIFPretPROD;
     end if;
  end loop; 
end;

function InregValida(Tabla in varchar2, CodSubunit in number, CodGest in number, Key in number) return number is 
aCount number(10);
sSQL varchar2(500);
AnLuna number(10);
begin
  AnLuna := PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU;
  -- daca exista o inregistrare cu codgest = 0 atunci alta nu mai este posibila
  sSQL := &apos;select count(*) from &apos;||Tabla||&apos; where subunitatea = &apos;||CodSubunit||&apos; and An*12+Luna = &apos;||AnLuna||&apos; and nvl(CodGest,0) = 0 and COD&apos;||Tabla||&apos; &lt;&gt; &apos;||Key;
  EXECUTE IMMEDIATE sSQL into aCount;
  if aCount &gt; 0 then return 0; end if;
  -- nu exsta inregistrarea globala cu gestiune nedefinita
  if CodGest = 0 then
    -- gestiuni globale
    -- caut o inregistare, daca exista atunci nu este posibil
    sSQL := &apos;select count(*) from &apos;||Tabla||&apos; where subunitatea = &apos;||CodSubunit||&apos; and An*12+Luna = &apos;||AnLuna||&apos; and COD&apos;||Tabla||&apos; &lt;&gt; &apos;||Key;
    EXECUTE IMMEDIATE sSQL into aCount;
    if aCount &gt; 0 then return 0; end if;
  else
    --caut inregistrarea exact pereche
    sSQL := &apos;select count(*) from &apos;||Tabla||&apos; where subunitatea = &apos;||CodSubunit||&apos; and An*12+Luna = &apos;||AnLuna||&apos; and CodGest = &apos;||CodGest||&apos; and COD&apos;||Tabla||&apos; &lt;&gt; &apos;||Key;
    EXECUTE IMMEDIATE sSQL into aCount;
    if aCount &gt; 0 then return 0; end if;
  end if;
  return 1;
end;

PROCEDURE MAKE_STOCINITIAL_LUNA(aAN IN NUMBER, aLUNA IN NUMBER)
IS
AnLunaPrec number(20);
BEGIN
  AnLunaPrec := aAn*12+aLuna - 1;
  DELETE TMP_NIR_LA_DATA;
  INSERT INTO TMP_NIR_LA_DATA (CODOBIECT, CANTNIR)
  SELECT 
    NL.CODNIRSTOC,
    NL.REST 
  FROM NIRLUNA NL
       INNER JOIN NIRSTOC1 NS1 ON NL.CODNIRSTOC = NS1.CODNIRSTOC
  WHERE NL.AN*12+NL.LUNA = ANLUNAPREC AND NS1.TIPDOC = 7 AND NS1.CODCOMANDA1 &gt; 0;  
END;

PROCEDURE MAKE_MISCARI_IN_LUNA(aAN IN NUMBER, aLUNA IN NUMBER)
IS 
BEGIN
  DELETE TMP_NIR_IN_INTERVALUL;
  INSERT INTO TMP_NIR_IN_INTERVALUL (CODOBIECT, CANTNIR)
  SELECT 
    CODNIRSTOC,
    SUM(CANTNIR) AS CANTNIR
  FROM
    (
    SELECT 
      NS.CODNIRSTOC,
      CANTNIR,
      CASE
        WHEN N.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
        WHEN N.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
        WHEN N.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
      END 
      ANLUNA 
    FROM
      NIRSTOC NS,
      NIR N
      LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
      LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES
    WHERE  
      NS.CODNIR    = N.CODNIR
      AND N.TIPNIR = 7
    )  
  WHERE
    ANLUNA = aAN * 12 + aLUNA
  GROUP BY CODNIRSTOC;

  INSERT INTO TMP_NIR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT 
    ns1.CODNIRSTOC,
    SUM(ns.CANTNIR) AS CANTNIR
  FROM
    NIRSTOC1 ns1
    inner join TMP_NIR_IN_INTERVALUL tni on tni.codobiect = ns1.codnirstocorig 
    inner join NirStoc ns on ns.codnirstoc = ns1.codnirstoc
  where 
    ns1.codnirstocorig &lt;&gt; ns1.codnirstoc and ns1.tipdoc = 7 and ns1.codcomanda1 &gt; 0
  GROUP BY ns1.CODNIRSTOC;
   

   DELETE TMP_LIVR_IN_INTERVALUL;
   INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
   SELECT 
     CODNIRSTOC,
     SUM(CANT) AS CANT
   FROM
   (select 
     codnirstoc,
     cant 
   from  
   (  
   SELECT 
     L1.CODNIRSTOC,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END CANT,  
     CASE
       WHEN L.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
       WHEN L.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
       WHEN L.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
     END ANLUNA 
   FROM
     TMP_NIR_IN_INTERVALUL TMP,
     LIVR1 L1,
     LIVR L
     LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR
     LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
     LEFT OUTER JOIN IESIRI E ON E.CODIES    = L.CODIES
   WHERE
     TMP.CODOBIECT = L1.CODNIRSTOC  
     AND L1.CODLIVR = L.CODLIVR
   )
   WHERE
    ANLUNA = aAN * 12 + aLUNA
   union all
   SELECT 
     CODNIRSTOC,
     CANT 
   FROM
   (  
   SELECT 
     L1.CODNIRSTOC,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END 
      CANT,  
     CASE
       WHEN L.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
       WHEN L.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
       WHEN L.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
     END ANLUNA 
   FROM
     TMP_NIR_LA_DATA TMP,
     LIVR1 L1,
     LIVR L
     LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR
     LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
     LEFT OUTER JOIN IESIRI E ON E.CODIES    = L.CODIES
   WHERE
     TMP.CODOBIECT = L1.CODNIRSTOC  
     AND L1.CODLIVR = L.CODLIVR
   )
   WHERE
     ANLUNA = aAN * 12 + aLUNA
   )  
   GROUP BY CODNIRSTOC;
END;

PROCEDURE MAKE_MISCARI_BalantaStoc(aAN IN NUMBER, aLUNA IN NUMBER)
IS 
BEGIN
  DELETE TMP_NIR_IN_INTERVALUL;
  DELETE TMP_LIVR_IN_INTERVALUL;

  INSERT INTO TMP_NIR_IN_INTERVALUL (CODOBIECT, CANTNIR)
  SELECT 
    CODNIRSTOC,
    SUM(CANTNIR) AS CANTNIR
  FROM
    (
    SELECT 
      NS.CODNIRSTOC,
      CANTNIR,
      CASE
        WHEN N.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
        WHEN N.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
        WHEN N.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
      END 
      ANLUNA 
    FROM
      NIRSTOC NS
      inner join TMP_BALANTA_STOC bs on bs.CodObiect = ns.CodNirstoc,
      NIR N
      LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
      LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES
    WHERE  
      NS.CODNIR    = N.CODNIR
      AND N.TIPNIR = 7
    )  
  WHERE
    ANLUNA &lt;= aAN * 12 + aLUNA
  GROUP BY CODNIRSTOC;


  INSERT INTO TMP_NIR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT 
    CODNIRSTOC,
    SUM(CANTNIR) AS CANTNIR
  FROM
    (
      SELECT 
        ns1.CODNIRSTOC,
        ns.CANTNIR,
        CASE
          WHEN N.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
          WHEN N.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
          WHEN N.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
        END 
        ANLUNA 
      FROM
        NIRSTOC1 ns1
        inner join TMP_NIR_IN_INTERVALUL tni on tni.codobiect = ns1.codnirstocorig 
        inner join NirStoc ns on ns.codnirstoc = ns1.codnirstoc,
        NIR N
        LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
        LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
        LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES
      WHERE  
        NS.CODNIR    = N.CODNIR 
        and ns1.codnirstocorig &lt;&gt; ns1.codnirstoc and ns1.tipdoc = 7 and ns1.codcomanda1 &gt; 0
    )
  where 
    ANLUNA &lt;= aAN * 12 + aLUNA
  GROUP BY CODNIRSTOC;
   

   INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
   SELECT 
     CODNIRSTOC,
     SUM(CANT) AS CANT
   FROM
   (  
   SELECT 
     L1.CODNIRSTOC,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END CANT,  
     CASE
       WHEN L.CODINTR IS NOT NULL THEN I.AN * 12 + I.LUNA 
       WHEN L.CODTRANSF IS NOT NULL THEN T.AN * 12 + T.LUNA 
       WHEN L.CODIES IS NOT NULL THEN E.AN * 12 + E.LUNA 
     END ANLUNA 
   FROM
     TMP_NIR_IN_INTERVALUL TMP,
     LIVR1 L1,
     LIVR L
     LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR
     LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
     LEFT OUTER JOIN IESIRI E ON E.CODIES    = L.CODIES
   WHERE
     TMP.CODOBIECT = L1.CODNIRSTOC  
     AND L1.CODLIVR = L.CODLIVR
   )
   WHERE
    ANLUNA &lt;= aAN * 12 + aLUNA
   GROUP BY CODNIRSTOC;
END;

PROCEDURE Get_Records_DifPretProd(aGest in number, aSubunitate in number, aAN IN NUMBER, aLUNA IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_BALANTA_STOC;
  MAKE_STOCINITIAL_LUNA(aAN, aLUNA);
  MAKE_MISCARI_IN_LUNA(aAN, aLUNA);
  
  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_LA_DATA N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, N.CANTNIR, 0, 0);

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, 0, N.CANTNIR,  0)
  WHEN     MATCHED THEN UPDATE SET SD.INTRARI = N.CANTNIR; 
  
  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = N.CANTNIR; 
--aici e pregatite codnirstoc-urile
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA; 
  
  MAKE_MISCARI_BalantaStoc(aAN, aLUNA);
  delete TMP_BALANTA_STOC bs where Nvl(bs.stocinitial,0) = 0 and Nvl(bs.Intrari,0) = 0 and Nvl(bs.iesiri,0) = 0;

  insert into tmp_DIFPRETPROD1
  (CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC, 
   DifPret, 
   CODCENTRU, CODANALIZANOD, DIRTY, 
   Curent,
   AnLuna, 
   INTRARI, IESIRI, 
   XDIFPRET,   XCODCENTRU, XCODANALIZANOD, XCurent, XINTRARI, XIESIRI,
   PRET, PretReal, 
   NRDOC, DATADOC, CodGest, Codioart, CodObiect, DENUMIRE)
  (
   select 
   -RowNum , 0, NS1.CodCOMANDA1, BS.CodObiect,  
   Nvl(obj1.ValMat,0) + (2-Nvl(obj1.TipPret,1))*(Nvl(obj1.ValMan,0) + Nvl(obj1.ValRegie,0)) - NS.Pret,
   0, 0, 0, 
   Case when Nvl(BS.StocInitial,0) = 0 then 1 else 0  end,
   aAn*12+aLuna, 
   tns.Cantnir, tl.Cantnir, 
   DP0.DIFPRET,   DP0.CODCENTRU, DP0.CODANALIZANOD, DP0.Curent, DP0.INTRARI, DP0.IESIRI,
   NS.Pret, Nvl(obj1.ValMat,0) + (2-Nvl(obj1.TipPret,1))*(Nvl(obj1.ValMan,0) + Nvl(obj1.ValRegie,0)),
   c.nrdoc, c.datadoc, C.CodGest, Ns.Codioart, c1.CodObiect, obj.denumire
   from TMP_BALANTA_STOC BS
        inner join TMP_NIR_IN_INTERVALUL tns on tns.codobiect = bs.codobiect
        inner join NirStoc1 Ns1 on BS.codObiect = Ns1.codNirStoc
        inner join NirStoc Ns  on  BS.codObiect = Ns.codNirStoc
        INNER JOIN NIR N ON N.CODNIR = Ns.CODNIR
        inner join comanda1 c1 on NS1.CodCOMANDA1   = c1.codcomanda1
        inner join comanda   c on c1.codcomanda = c.codcomanda
        inner join nartobj obj on obj.codobiect = c1.codobiect  
        inner join Tmp_Nartobj_Luna obj1 on obj1.codobiect = c1.codobiect  
        left join DIFPRETPROD1 DP0 on DP0.CodCOMANDA1=C1.codcomanda1 and DP0.CodNirStoc=Ns.CodNirStoc and DP0.AnLuna=aAn*12+aLuna-1
        LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
        left  join TMP_LIVR_IN_INTERVALUL tl on tl.codobiect = bs.codobiect
   where (C.Subunitatea = aSubunitate) and (aGest = 0 or aGest = C.CODGEST)
   );
  delete tmp_DIFPRETPROD1 where PretReal = 0 or Difpret = 0 or (Round(Difpret*Intrari,2)=0 and Round(Difpret*Iesiri,2)=0);
  COMMIT;  
  
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT codDIFPRETPROD INTO Tmp FROM DIFPRETPROD WHERE codDIFPRETPROD = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;  
  SP_LOCKRECORD(RecId);

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 80) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;
   
  DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 80); 
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 80; 

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 80;  
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 80;   

	DELETE FROM DIFPRETPROD1 WHERE codDIFPRETPROD = RecId ;
  DELETE FROM DIFPRETPROD  WHERE codDIFPRETPROD = RecId ;
  NotifyModif(2, RecId, &apos;DIFPRETPROD&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DIFPRETPROD FIELDS( codDIFPRETPROD ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
nr number;
BEGIN

  INSERT INTO  TMP_DIFPRETPROD(CodDIFPRETPROD, An, Luna, Obs, OPERAT, Subunitatea, CodGest)
    ( SELECT CodDIFPRETPROD, An, Luna, Obs, 1, Subunitatea, CodGest
      FROM DIFPRETPROD WHERE codDIFPRETPROD = RecId );

  insert into tmp_DIFPRETPROD1
  (  CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC, DifPret, CODCENTRU, CODANALIZANOD, DIRTY, 
     Curent, AnLuna, INTRARI, IESIRI, 
     XDIFPRET,   XCODCENTRU, XCODANALIZANOD, XCurent, XINTRARI, XIESIRI,
     PRET, 
     PretReal, 
     NRDOC, DATADOC, CodGest, Codioart, CodObiect, DENUMIRE)
  (
   select DP1.codDIFPRETPROD1,DP1.codDIFPRETPROD,DP1.CodCOMANDA1,DP1.CODNIRSTOC, DP1.DifPret,DP1.CODCENTRU, DP1.CODANALIZANOD,DP1.DIRTY, 
          DP1.Curent, DP1.AnLuna, DP1.INTRARI, DP1.IESIRI, 
          DP0.DIFPRET,   DP0.CODCENTRU, DP0.CODANALIZANOD, DP0.Curent, DP0.INTRARI, DP0.IESIRI,
          NS.Pret, 
          Nvl(obj1.ValMat,0) + (2-Nvl(obj1.TipPret,1))*(Nvl(obj1.ValMan,0) + Nvl(obj1.ValRegie,0)),
          c.nrdoc, c.datadoc, C.CodGest, Ns.Codioart, c1.CodObiect, obj.denumire
   from DIFPRETPROD1 DP1
        inner join comanda1 c1 on DP1.CodCOMANDA1   = c1.codcomanda1
        inner join comanda   c on c1.codcomanda = c.codcomanda
        inner join nartobj obj on obj.codobiect = c1.codobiect  
        inner join Tmp_Nartobj_Luna obj1 on obj1.codobiect = c1.codobiect  
        inner join NirStoc Ns   on  DP1.codNirStoc = Ns.codNirStoc
        left join DIFPRETPROD1 DP0 on DP0.CodCOMANDA1=DP1.codcomanda1 and DP0.CodNirStoc=DP1.CodNirStoc and DP0.AnLuna=DP1.AnLuna-1
   where DP1.codDIFPRETPROD = recid);

   update tmp_DIFPRETPROD1 set Dirty = 1 
   where Round(DifPret - (PretReal - Pret),2) &lt;&gt; 0;

   select Count(*) into nr from tmp_DIFPRETPROD1 where Nvl(Dirty,0) = 1; 

   if Nr &gt; 0 then 
     update tmp_DIFPRETPROD set OPERAT = 0;
   end if;

   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 80 AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 80 AND CODDOC = RECID);

   DELETE TMP_RULAJ;


  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 VcOD NUMBER(20);
 NR   NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  codDIFPRETPROD INTO RecId FROM TMP_DIFPRETPROD;
    
    UPDATE DIFPRETPROD SET ( An, Luna, Obs, OPERAT, Subunitatea, CodGest )
       = ( SELECT An, Luna, Obs, 1, Subunitatea, CodGest
          FROM TMP_DIFPRETPROD )
      WHERE codDIFPRETPROD = RecId;
    
    DELETE FROM DIFPRETPROD1
    WHERE CodDIFPRETPROD = RecID
      AND CodDIFPRETPROD1 NOT IN (SELECT CodDIFPRETPROD1 FROM TMP_DIFPRETPROD1);

    FOR v_rec IN (SELECT * FROM TMP_DIFPRETPROD1) LOOP
      IF NVL(v_rec.CodDIFPRETPROD1, 0) &gt; 0
      THEN
        UPDATE DIFPRETPROD1 SET
          CodCOMANDA1    = V_REC.CodCOMANDA1,
          CODNIRSTOC     = V_REC.CODNIRSTOC, 
          DifPret        = V_REC.PretReal - V_REC.Pret,
          CODCENTRU      = v_rec.CODCENTRU,      
          CODANALIZANOD  = V_REC.CODANALIZANOD,                     
          Curent         = V_REC.Curent,
          AnLuna         = v_rec.AnLuna, 
          INTRARI        = v_rec.INTRARI, 
          IESIRI         = v_rec.IESIRI,
          DIRTY          = 0 
        WHERE CODDIFPRETPROD1  = v_rec.CODDIFPRETPROD1;
      ELSE
        SELECT seq_DPP1_CodDIFPRETPROD1.NEXTVAL INTO vCod FROM dual;

        INSERT INTO  DIFPRETPROD1 (
          CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC, DifPret, CODCENTRU, CODANALIZANOD, Curent, AnLuna, INTRARI, IESIRI, DIRTY
        )
        VALUES (
          vCod , RecId, V_REC.CodCOMANDA1, V_REC.CODNIRSTOC, V_REC.PretReal - V_REC.Pret, v_rec.CODCENTRU, v_rec.CODANALIZANOD, v_rec.Curent, v_rec.AnLuna, v_rec.INTRARI, v_rec.IESIRI, 0
        );
      END IF;
    END LOOP;  


-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = 80 AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET 
    CODDOC       = V_REC.CODDOC,       
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,      
    CODANALIZANOD = v_rec.CODANALIZANOD,      
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT
  WHERE 
    CODJURNAL1 = V_REC.CODJURNAl1; 
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT ) 
   VALUES 
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD, V_REC.DATADOC, V_REC.DOCUMENT);
 END IF; 
END LOOP;
  


-- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 80 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);
    
    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET  
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC, 
        INDEXLOCAL = V_REC.INDEXLOCAL, 
        CONTD      = V_REC.CONTD, 
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE, 
        VALOAREV   = V_REC.VALOAREV, 
        OBS        = V_REC.OBS, 
        AN         = V_REC.AN, 
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = v_rec.CODCENTRU,      
        CODANALIZANOD  = V_REC.CODANALIZANOD,                     
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT   
      WHERE 
        CODJURNAL = V_REC.CODJURNAl; 
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT)  
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD,V_REC.DATADOC, V_REC.DOCUMENT);
     END IF; 
    END LOOP;
  ELSE  -- INSERT

    SELECT seq_DPP_CodDIFPRETPROD.NextVal INTO RecId FROM DUAL;

    INSERT INTO DIFPRETPROD 
      (CodDIFPRETPROD, An, Luna, Obs, OPERAT, Subunitatea, CodGest)
    SELECT
      RECID, An, Luna, Obs, 1, Subunitatea, CodGest
    FROM TMP_DIFPRETPROD;

    FOR V_REC IN (SELECT * FROM TMP_DIFPRETPROD1)
    LOOP
      SELECT seq_DPP1_CodDIFPRETPROD1.Nextval INTO VCOD FROM DUAL;

      INSERT INTO  DIFPRETPROD1 (
        CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC, DifPret, CODCENTRU, CODANALIZANOD, Curent, AnLuna, INTRARI, IESIRI, DIRTY
      )
      VALUES (
        vCod , RecId, V_REC.CodCOMANDA1, V_REC.CODNIRSTOC, V_REC.PretReal - V_REC.Pret, v_rec.CODCENTRU, v_rec.CODANALIZANOD, v_rec.Curent, v_rec.AnLuna, v_rec.INTRARI, v_rec.IESIRI, 0
      );

    END LOOP;


    INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT ) 
    (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC,DOCUMENT FROM TMP_JURNAL1);



   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT)  
   ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT FROM TMP_JURNAL);

    
  END IF;



  -- ACTUALIZARE RULAJE CONTURI
   FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
   
     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;
  
     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
     WHERE 
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
  
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;
      
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF; 

   END LOOP;


  PKG_GLOBALS.MarkDirtyJurnal; 
  NotifyModif(Operation, RecId, &apos;DIFPRETPROD&apos;); 
  COMMIT;
END;

end pkg_DIFPRETPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0489919E0BC4DDE4FCFCAC9B5F12A592E94CE9A9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DINTRASTAT IS

PROCEDURE UmpleGEN(pAn INTEGER, pLuna INTEGER, pSubunit INTEGER) IS
  vIntrastatLohn    NUMBER(1) := Coalesce(pkg_categconst.GetValConstanta(&apos;IntrastatLohn&apos;,    pAn, pLuna),&apos;2&apos;);
  vArtServTransport NUMBER(20):= Coalesce(pkg_categconst.GetValConstanta(&apos;ArtServTransport&apos;, pAn, pLuna),&apos;0&apos;);
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DINTRASTAT_GEN&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DINTRASTAT_TRANSP&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_INTRASTAT_NC_OBJ&apos;;

  INSERT INTO TMP_INTRASTAT_NC_OBJ (
    COD, CODPARINTE, CODBUNIC, CN, DEN_EN, DEN_RO, SU, NIVEL, AREFII,
    CODOBIECT)
  SELECT
    CN8.COD, CN8.CODPARINTE, CN8.CODBUNIC, CN8.CN, CN8.DEN_EN, CN8.DEN_RO, CN8.SU, CN8.NIVEL, CN8.AREFII,
    O.CODOBIECT
  FROM nartobj o INNER JOIN winmadmin.intrastat_nc cn8 ON cn8.cn = Trim(o.codvamal);

  INSERT INTO TMP_DINTRASTAT_GEN
  SELECT
    i.tipdoc, i.codintr coddoc, i1.codintr1 coddoc1, i1.indexlocal, i.Partener, i1.codobiect, 1 TipOper, cn8.cn Cn8Code,
    i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1) InvoiceValue,
    CASE
      WHEN dvi1.coddvi1 IS NOT NULL THEN (
        SELECT Coalesce(Sum(Coalesce(NS.Supliment,0)),0)
        FROM nirstoc ns inner join nir n ON n.codnir = ns.codnir
        WHERE ns.coddvi1 = dvi1.coddvi1 AND n.codintr = i1.codintr AND n.tipnir = i.tipdoc
      ) + i1.cant*(Coalesce(dvi1.pretimport,0) - Coalesce(dvi1.pretoriginal,0))
      WHEN i1.cant &gt; 0 AND i.tipdoc = 9 THEN (
        SELECT Coalesce(Sum(Coalesce(NS.Supliment*i1.cant/ae1.cant,0)),0)
        FROM intrlink il
          INNER JOIN intrari1 ae1 ON ae1.codintr1 = il.codlinieaviz
          INNER JOIN intrari ae ON ae.codintr = ae1.codintr
          INNER JOIN nir n ON n.codintr = ae.codintr AND n.tipnir = ae.tipdoc
          INNER JOIN nirstoc ns ON ns.codnir = n.codnir AND ns.codintr1 = ae1.codintr1
        WHERE il.codintr1= i1.codintr1 AND ae1.cant &lt;&gt; 0
      )
      WHEN i1.cant &gt; 0 THEN (
        SELECT Coalesce(Sum(Coalesce(NS.Supliment,0)),0)
        FROM nirstoc ns inner join nir n ON n.codnir = ns.codnir
        WHERE ns.codintr1 = i1.codintr1 AND n.codintr = i1.codintr AND n.tipnir = i.tipdoc
      )
      ELSE 0
    END StatisticalValue,
    i1.cant * CASE WHEN u.tipum = 1 THEN u.coef ELSE o.masa END NetMass,
    SubStr(nin.simbol,1,1) NatureOfTransactionACode, CASE WHEN InStr(nin.simbol,&apos;.&apos;) = 2 THEN nin.simbol END NatureOfTransactionBCode,
    nid.simbol DeliveryTermsCode,
    SubStr(nit.simbol,1, InStr(nit.simbol,&apos;.&apos;)-1) ModeOfTransportCode,
    Coalesce(
      CASE WHEN Coalesce(o.produspropriu,0) = 2 THEN &apos;RO&apos; ELSE Upper(Trim(torig.SIMBAUTO)) END,
      ( SELECT Max(Upper(Trim(t.SIMBAUTO)))
        FROM nir n
          INNER JOIN nirstoc ns ON ns.codnir = n.codnir
          INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
          INNER JOIN certif c ON c.codcertif = nser.codcertif
          INNER JOIN ntari t ON t.codtara = c.codtara
        WHERE n.codintr = i.codintr AND n.tipnir = i.tipdoc
          AND ns.codintr1 = i1.codintr1
      )
    ) CountryOfOrigin,
    cn8.SU SupplUnitCode, i1.cant/usu.paritate QtyInSupplUnits,
    CASE WHEN SubStr(nin.simbol,1,1) = &apos;2&apos; THEN Upper(Trim(tsub.simbauto)) ELSE Upper(Trim(tliv.simbauto)) END CountryOfConsignment,
    CASE WHEN SubStr(nin.simbol,1,1) = &apos;2&apos; THEN Upper(Trim(tliv.simbauto)) ELSE NULL                       END CountryOfDestination,
    CASE WHEN SubStr(nin.simbol,1,1) = &apos;2&apos; THEN Upper(Trim(tsoc.simbauto)) ELSE NULL                       END PartnerCountryCode,
    CASE WHEN SubStr(nin.simbol,1,1) = &apos;2&apos; THEN Upper(Trim(cf.codfiscal))  ELSE NULL                       END PartnerVatNr
  FROM intrari i
    INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    INNER JOIN nagenda sliv ON sliv.CodAgenda = i.CodLocatie
    INNER JOIN tmp_intrastat_nc_obj cn8 ON cn8.codobiect = i1.codobiect
    LEFT  JOIN nartobj o ON o.codobiect = i1.codobiect
    INNER JOIN num1 u1 ON u1.codum1 = i1.umsec
    INNER JOIN num u ON u.codum = u1.codum
    LEFT JOIN num1 usu ON usu.codum = u1.codum AND usu.den_intrastat = cn8.su
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN nagenda sprod ON sprod.codpart = prod.codpart AND sprod.sediusocial BETWEEN 4 AND 7 AND Coalesce(sprod.inactiv, 0) = 0
    LEFT JOIN nlocalit lprod ON lprod.codlocalit = Coalesce(sprod.codlocalit, 0)
    LEFT JOIN ntari torig ON torig.codtara = Coalesce(NullIf(o.taraorigine, 0), lprod.codtara, 0)
    LEFT JOIN nlocalit lliv ON lliv.codlocalit = sliv.codlocalit
    LEFT JOIN ntari tliv ON tliv.codtara = lliv.codtara
    LEFT JOIN nintrastat nin ON nin.codnintrastat = i.naturatranz
    LEFT JOIN nintrastat nid ON nid.codnintrastat = i.tiplivrare
    LEFT JOIN nintrastat nit ON nit.codnintrastat = i.modtransp
    LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
    LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = Coalesce(ssoc.codlocalit, 0)
    LEFT JOIN ntari tsoc ON tsoc.codtara = Coalesce(lsoc.codtara, 0)
    LEFT JOIN npartcodfisc cf ON cf.cod_codfiscal = i.codfiscal
    LEFT JOIN nagenda ssub ON ssub.codsubunit = i.subunitatea
    LEFT JOIN nlocalit lsub ON lsub.codlocalit = Coalesce(ssub.codlocalit, 0)
    LEFT JOIN ntari tsub ON tsub.codtara = Coalesce(lsub.codtara, 0)
    LEFT JOIN dvi ON dvi.codintr = i.codintr
    LEFT JOIN dvi1 ON dvi1.coddvi = dvi.coddvi AND dvi1.codintr1 = i1.codintr1
  WHERE i.operat = 1 AND i.anulat = 0
    AND i.an = pAn AND i.luna = pLuna
    AND Coalesce(tliv.statcomunitar, 0) = 1 AND Coalesce(Upper(tliv.simbauto), &apos;X&apos;) &lt;&gt; &apos;RO&apos;
    --AND i.valdoc &lt;&gt; 0
    AND i.tipdoc IN (1,2,3,4,5,9)
    AND CASE
          WHEN i.tipdoc = 9 AND Coalesce(i.tipfactura,  0) = 9 THEN 1
          WHEN i.tipdoc = 2 AND Coalesce(i.tipfactura,  0) = 9 THEN 0
          WHEN i.tipdoc = 2 AND Coalesce(dvi.tipimport, 0) = 0 THEN 1
          ELSE 0
        END = 0
    AND (pSubunit = 1 OR i.subunitatea = pSubunit);

  IF vArtServTransport &lt;&gt; 0 THEN
    INSERT INTO TMP_DINTRASTAT_TRANSP(TIPDOC, CODDOC, VALTRANSP)
    SELECT i.tipdoc, i.codies, Sum(i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1))
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      LEFT  JOIN nartobj o ON o.codobiect = i1.codobiect
      LEFT  JOIN nagenda sliv ON sliv.CodAgenda = i.CodLocatie
      LEFT  JOIN nlocalit lliv ON lliv.codlocalit = sliv.codlocalit
      LEFT  JOIN ntari tliv ON tliv.codtara = lliv.codtara
    WHERE i1.codobiect = vArtServTransport AND i1.tiplinie = &apos;S&apos; AND o.codvamal IS NULL
      AND i.operat = 1 AND i.anulat = 0
      AND i.an = pAn AND i.luna = pLuna
      AND Coalesce(tliv.statcomunitar, 0) = 1 AND Coalesce(Upper(tliv.simbauto), &apos;X&apos;) &lt;&gt; &apos;RO&apos;
      AND i.tipdoc IN (19,20,26)
      --AND i.valdoc &lt;&gt; 0
      AND NOT(i.tipdoc = 20 AND Coalesce(i.custodie, 0) = 0)
      AND NOT(i.tipdoc = 26 AND EXISTS (SELECT 1 FROM ieslink ilae INNER JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz INNER JOIN iesiri ae ON ae.codies = ae1.codies WHERE ilae.codies1 = i1.codies1 AND Coalesce(ae.custodie, 0) = 1) )
      AND (pSubunit = 1 OR i.subunitatea = pSubunit)
    GROUP BY i.tipdoc, i.codies;
  END IF;

  INSERT INTO TMP_DINTRASTAT_GEN
  SELECT
    i.tipdoc, i.codies coddoc, i1.codies1 coddoc1, i1.indexlocal, i.Partener, i1.codobiect, 2 TipOper, cn8.cn Cn8Code,
    i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1) InvoiceValue,
    CASE
      WHEN Coalesce(tt.valtransp,0) = 0 THEN 0
      WHEN Sum(i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1)) OVER (PARTITION BY i.tipdoc, i.codies) = 0 THEN 0
      ELSE tt.valtransp*i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1) / Sum(i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*Coalesce(NULLIF(i.curs,0),1)) OVER (PARTITION BY i.tipdoc, i.codies)
    END StatisticalValue,
    i1.cant * CASE WHEN u.tipum = 1 THEN u.coef ELSE o.masa END NetMass,
    SubStr(nin.simbol,1,1) NatureOfTransactionACode, CASE WHEN InStr(nin.simbol,&apos;.&apos;) = 2 THEN nin.simbol END NatureOfTransactionBCode,
    nid.simbol DeliveryTermsCode,
    SubStr(nit.simbol,1, InStr(nit.simbol,&apos;.&apos;)-1) ModeOfTransportCode,
    Coalesce(
      CASE WHEN Coalesce(o.produspropriu,0) = 2 THEN &apos;RO&apos; ELSE Upper(Trim(torig.SIMBAUTO)) END,
      ( SELECT Max(Upper(Trim(t.SIMBAUTO)))
        FROM livr l
          INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
          INNER JOIN nirser nser ON nser.codnirstoc = l1.codnirstoc
          INNER JOIN certif c ON c.codcertif = nser.codcertif
          INNER JOIN ntari t ON t.codtara = c.codtara
        WHERE l.codies = i.codies AND l.tiplivr = i.tipdoc
          AND l1.codies1 = i1.codies1
      )
    ) CountryOfOrigin,
    cn8.SU SupplUnitCode, i1.cant/usu.paritate QtyInSupplUnits,
    Upper(Trim(tsub.simbauto)) CountryOfConsignment,
    Upper(Trim(tliv.simbauto)) CountryOfDestination,
    Upper(Trim(tsoc.simbauto)) PartnerCountryCode,
    Upper(Trim(cf.codfiscal))  PartnerVatNr
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN nagenda sliv ON sliv.CodAgenda = i.CodLocatie
    INNER JOIN tmp_intrastat_nc_obj cn8 ON cn8.codobiect = i1.codobiect
    LEFT  JOIN nartobj o ON o.codobiect = i1.codobiect
    INNER JOIN num1 u1 ON u1.codum1 = i1.umsec
    INNER JOIN num u ON u.codum = u1.codum
    LEFT JOIN num1 usu ON usu.codum = u1.codum AND usu.den_intrastat = cn8.su
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN nagenda sprod ON sprod.codpart = prod.codpart AND sprod.sediusocial BETWEEN 4 AND 7 AND Coalesce(sprod.inactiv, 0) = 0
    LEFT JOIN nlocalit lprod ON lprod.codlocalit = Coalesce(sprod.codlocalit, 0)
    LEFT JOIN ntari torig ON torig.codtara = Coalesce(NullIf(o.taraorigine, 0), lprod.codtara, 0)
    LEFT JOIN nlocalit lliv ON lliv.codlocalit = sliv.codlocalit
    LEFT JOIN ntari tliv ON tliv.codtara = lliv.codtara
    LEFT JOIN nintrastat nin ON nin.codnintrastat = i.naturatranz
    LEFT JOIN nintrastat nid ON nid.codnintrastat = i.tiplivrare
    LEFT JOIN nintrastat nit ON nit.codnintrastat = i.modtransp
    LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
    LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = Coalesce(ssoc.codlocalit, 0)
    LEFT JOIN ntari tsoc ON tsoc.codtara = Coalesce(lsoc.codtara, 0)
    LEFT JOIN npartcodfisc cf ON cf.cod_codfiscal = i.codfiscal
    LEFT JOIN nagenda ssub ON ssub.codsubunit = i.subunitatea
    LEFT JOIN nlocalit lsub ON lsub.codlocalit = Coalesce(ssub.codlocalit, 0)
    LEFT JOIN ntari tsub ON tsub.codtara = Coalesce(lsub.codtara, 0)
    LEFT JOIN tmp_dintrastat_transp tt ON tt.tipdoc = i.tipdoc AND tt.coddoc = i.codies
  WHERE i.operat = 1 AND i.anulat = 0
    AND i.an = pAn AND i.luna = pLuna
    AND i.tipdoc IN (19,20,26)
    AND Coalesce(tliv.statcomunitar, 0) = 1 AND Coalesce(Upper(tliv.simbauto), &apos;X&apos;) &lt;&gt; &apos;RO&apos;
    --AND i.valdoc &lt;&gt; 0
    AND NOT(i.tipdoc = 20 AND Coalesce(i.custodie, 0) = 0)
    AND NOT(i.tipdoc = 26 AND EXISTS (SELECT 1 FROM ieslink ilae INNER JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz INNER JOIN iesiri ae ON ae.codies = ae1.codies WHERE ilae.codies1 = i1.codies1 AND Coalesce(ae.custodie, 0) = 1) )
    AND (pSubunit = 1 OR i.subunitatea = pSubunit)
    AND Coalesce(i.exclusintrastat, 0) &lt;&gt; 1;

  IF vIntrastatLohn = 1 THEN
    UPDATE TMP_DINTRASTAT_GEN TMP
    SET
      InvoiceValue =
      InvoiceValue + Coalesce((
        SELECT
          Sum(Coalesce(
            l1.cant*
            (
              SELECT Coalesce(Sum(inmat1.pu * lmat1.cant*Coalesce(inmat.curs,1)), 0)
              FROM intrprodlink intl
                INNER JOIN cmdprodmat cmdp ON cmdp.codcmdprodmat = intl.codliniecomanda AND cmdp.tip=0
                INNER JOIN iesiri1 imat1 ON imat1.codcmdint1 = cmdp.codcomanda1
                INNER JOIN iesiri imat ON imat.codies=imat1.codies AND imat.tipdoc=24 AND imat.operat = 1 AND imat.anulat = 0
                INNER JOIN livr lmat ON lmat.codies=imat.codies AND lmat.tiplivr=imat.tipdoc
                INNER JOIN livr1 lmat1 ON lmat1.codlivr=lmat.codlivr AND imat1.codies1=lmat1.codies1
                INNER JOIN nirstoc nsmat ON nsmat.codnirstoc = lmat1.codnirstoc
                LEFT  JOIN nirstoc nsmatx ON nsmatx.codnirstoc = nsmat.codnirstocparinte
                LEFT  JOIN intrari1 inmat1 ON inmat1.codintr1= Coalesce(nsmat.codintr1,nsmatx.codintr1)
                LEFT  JOIN intrari inmat ON inmat.codintr=inmat1.codintr AND inmat.operat = 1 AND inmat.anulat = 0
                LEFT  JOIN dvi ON dvi.codintr=inmat.codintr
              WHERE intl.codintr1 = intr1.codintr1 AND Coalesce(dvi.tipimport,0) = 1
            )/
            ( SELECT NullIF(Sum(xintr1.cant), 0)
              FROM intrprodlink xintl
                INNER JOIN intrari1 xintr1 ON xintr1.codintr1 =  xintl.codintr1
                INNER JOIN intrari xintr ON xintr.codintr =  xintr1.codintr AND xintr.operat = 1 AND xintr.anulat = 0
              WHERE xintl.codliniecomanda=intl.codliniecomanda
            ), 0))
        FROM iesiri1 i1
          INNER JOIN iesiri i ON i.codies = i1.codies
          INNER JOIN livr1 l1 ON l1.codies1 = i1.codies1
          INNER JOIN livr l ON l1.codlivr=l.codlivr AND l.codies = i1.codies
          INNER JOIN nirstoc ns ON ns.codnirstoc=l1.codnirstoc
          INNER JOIN intrari1 intr1 ON intr1.codintr1=ns.codintr1
          INNER JOIN intrprodlink intl ON intl.codintr1=intr1.codintr1
        WHERE i1.codies1 = tmp.coddoc1
          AND i.tiptranzactie=(CASE WHEN i.tipdoc=19 THEN 2 ELSE 1 END)
          AND ns.tipdocachiz=7
      ), 0)
    WHERE TMP.TipOper = 2
      AND TMP.TipDoc IN (19,20);
  END IF;

  UPDATE TMP_DINTRASTAT_GEN SET STATISTICALVALUE = InvoiceValue + Coalesce(STATISTICALVALUE, 0);

  UPDATE TMP_DINTRASTAT_GEN
  SET   PartnerVatNr = Trim(SubStr(PartnerVatNr, Length(PartnerCountryCode) + 1))
  WHERE PartnerCountryCode IS NOT NULL
    AND Substr(PartnerVatNr,1,Length(PartnerCountryCode)) = PartnerCountryCode;

  UPDATE TMP_DINTRASTAT_GEN
  SET   CountryOfOrigin = CountryOfConsignment
  WHERE CountryOfOrigin      IS NULL
    AND CountryOfConsignment IS NOT NULL;

  UPDATE TMP_DINTRASTAT_GEN
  SET TIPOPER          = CASE WHEN TIPOPER = 1 THEN 2 ELSE 1 END,
      InvoiceValue     = - InvoiceValue,
      StatisticalValue = - StatisticalValue,
      NetMass          = - NetMass,
      QtyInSupplUnits  = - QtyInSupplUnits
  WHERE NATUREOFTRANSACTIONACODE = &apos;2&apos;;

  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodDIntrastat INTO Tmp FROM DIntrastat WHERE CodDIntrastat = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM DIntrastatA  WHERE CodDIntrastat  = RecId ;
  DELETE FROM DIntrastatD  WHERE CodDIntrastat  = RecId ;
  DELETE FROM DIntrastat   WHERE CodDIntrastat  = RecId ;
  NotifyModif(2, RecId, &apos;DIntrastat&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_DIntrastat ( CodDIntrastat ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master DIntrastat
  INSERT INTO TMP_DIntrastat (
    CODDINTRASTAT, SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
    DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS )
  SELECT
    CODDINTRASTAT, SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
    DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS
  FROM DIntrastat
  WHERE CodDIntrastat = RecId;

  INSERT INTO TMP_DIntrastatA (
    CODDINTRASTATA, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
    NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
    COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT )
  SELECT
    CODDINTRASTATA, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
    NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
    COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT
  FROM DIntrastatA
  WHERE CodDIntrastat = RecId;

  INSERT INTO TMP_DIntrastatD (
    CODDINTRASTATD, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
    NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
    COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR )
  SELECT
    CODDINTRASTATD, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
    NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
    COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR
  FROM DIntrastatD
  WHERE CodDIntrastat = RecId;

  UPDATE TMP_DIntrastat SET (INVOICEVALUE_A, STATISTICALVALUE_A, NETMASS_A) = (SELECT Sum(INVOICEVALUE), Sum(STATISTICALVALUE), Sum(NETMASS) FROM TMP_DIntrastatA);
  UPDATE TMP_DIntrastat SET (INVOICEVALUE_D, STATISTICALVALUE_D, NETMASS_D) = (SELECT Sum(INVOICEVALUE), Sum(STATISTICALVALUE), Sum(NETMASS) FROM TMP_DIntrastatD);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  UPDATE TMP_DIntrastat
  SET VATNR    = Upper(VATNR),
      DTPVATNR = Upper(DTPVATNR);

  UPDATE TMP_DIntrastatA
  SET COUNTRYOFORIGIN      = Trim(Upper(COUNTRYOFORIGIN)),
      COUNTRYOFCONSIGNMENT = Trim(Upper(COUNTRYOFCONSIGNMENT));

  UPDATE TMP_DIntrastatD
  SET COUNTRYOFORIGIN      = Trim(Upper(COUNTRYOFORIGIN)),
      COUNTRYOFDESTINATION = Trim(Upper(COUNTRYOFDESTINATION)),
      PARTNERCOUNTRYCODE   = Trim(Upper(PARTNERCOUNTRYCODE)),
      PARTNERVATNR         = Trim(Upper(PARTNERVATNR));

  UPDATE TMP_DIntrastatD
  SET   PartnerVatNr = Trim(SubStr(PartnerVatNr, Length(PartnerCountryCode) + 1))
  WHERE PartnerCountryCode IS NOT NULL
    AND Substr(PartnerVatNr,1,Length(PartnerCountryCode)) = PartnerCountryCode;

  IF Operation = 0
  THEN  -- UPDATE
    -- Master DIntrastat
    SELECT  CodDIntrastat INTO RecId FROM TMP_DIntrastat;

    UPDATE DIntrastat
    SET  (SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
          DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS )
      =(SELECT
          SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
          DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS
        FROM TMP_DIntrastat )
    WHERE CodDIntrastat = RecId ;

    -- Detaliu DIntrastatA
    DELETE FROM DIntrastatA WHERE CODDINTRASTAT = RecID AND CODDINTRASTATA NOT IN (SELECT CODDINTRASTATA FROM TMP_DIntrastatA);

    UPDATE DIntrastatA D
    SET (   CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
            COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT ) =
        ( SELECT
            T.CN8CODE, T.INVOICEVALUE, T.STATISTICALVALUE, T.NETMASS, T.NATUREOFTRANSACTIONACODE, T.NATUREOFTRANSACTIONBCODE, T.DELIVERYTERMSCODE, T.MODEOFTRANSPORTCODE,
            T.COUNTRYOFORIGIN, T.SUPPLUNITCODE, T.QTYINSUPPLUNITS, T.COUNTRYOFCONSIGNMENT
          FROM TMP_DIntrastatA T
          WHERE T.CODDINTRASTATA = D.CODDINTRASTATA
        )
    WHERE D.CodDIntrastat = RecId ;

    INSERT INTO DIntrastatA (
      CODDINTRASTATA, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT )
    SELECT
      SEQ_DINTRASTATA_CODDINTRASTATA.NextVal, RecId, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT
    FROM TMP_DIntrastatA
    WHERE CODDINTRASTATA &lt;= 0;

    -- Detaliu DIntrastatD
    DELETE FROM DIntrastatD WHERE CODDINTRASTAT = RecID AND CODDINTRASTATD NOT IN (SELECT CODDINTRASTATD FROM TMP_DIntrastatD);

    UPDATE DIntrastatD D
    SET (   CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
            COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR ) =
        ( SELECT
            T.CN8CODE, T.INVOICEVALUE, T.STATISTICALVALUE, T.NETMASS, T.NATUREOFTRANSACTIONACODE, T.NATUREOFTRANSACTIONBCODE, T.DELIVERYTERMSCODE, T.MODEOFTRANSPORTCODE,
            T.COUNTRYOFORIGIN, T.SUPPLUNITCODE, T.QTYINSUPPLUNITS, T.COUNTRYOFDESTINATION, T.PARTNERCOUNTRYCODE, T.PARTNERVATNR
          FROM TMP_DIntrastatD T
          WHERE T.CODDINTRASTATD = D.CODDINTRASTATD
        )
    WHERE D.CodDIntrastat = RecId ;

    INSERT INTO DIntrastatD (
      CODDINTRASTATD, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR )
    SELECT
      SEQ_DINTRASTATD_CODDINTRASTATD.NextVal, RecId, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR
    FROM TMP_DIntrastatD
    WHERE CODDINTRASTATD &lt;= 0;
  ELSE  -- INSERT
    -- Master DIntrastat
    SELECT SEQ_DINTRASTAT_CODDINTRASTAT.NextVal INTO RecId FROM DUAL;

    INSERT INTO DIntrastat (
      CODDINTRASTAT, SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
      DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS )
    SELECT
      RecId, SUBUNITATEA, AN, LUNAD, TIPA, TIPD, VATNR, FIRMNAME, CPLASTNAME, CPFIRSTNAME, CPPOSITION, CPPHONE, CPFAX, CPEMAIL,
      DTP, DTPVATNR, DTPFIRMNAME, DTPSTREET, DTPSTREETNUMBER, DTPBLOCK, DTPSTAIRS, DTPAPARTMENT, DTPCODLOCALIT, DTPPOSTALCODE, OBS
    FROM TMP_DIntrastat;

    -- Detaliu DIntrastatA
    INSERT INTO DIntrastatA (
      CODDINTRASTATA, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT )
    SELECT
      SEQ_DINTRASTATA_CODDINTRASTATA.NextVal, RecId, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFCONSIGNMENT
    FROM TMP_DIntrastatA;

    -- Detaliu DIntrastatD
    INSERT INTO DIntrastatD (
      CODDINTRASTATD, CODDINTRASTAT, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR )
    SELECT
      SEQ_DINTRASTATD_CODDINTRASTATD.NextVal, RecId, CN8CODE, INVOICEVALUE, STATISTICALVALUE, NETMASS,
      NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE,
      COUNTRYOFORIGIN, SUPPLUNITCODE, QTYINSUPPLUNITS, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR
    FROM TMP_DIntrastatD;
  END IF;
  NotifyModif(Operation, RecId, &apos;DIntrastat&apos;);

  COMMIT;
END;

PROCEDURE Generare(pAn INTEGER, pLuna INTEGER, pSubunit INTEGER) IS
  vCodD       INTEGER;
BEGIN
  BEGIN
    SELECT vCodD INTO vCodD FROM TMP_DINTRASTAT;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN vCodD := 0;
  END;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DINTRASTATA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DINTRASTATD&apos;;

  UmpleGEN(pAn, pLuna, pSubunit);

  INSERT INTO TMP_DINTRASTATA (
    CODDINTRASTATA, CODDINTRASTAT,
    CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFCONSIGNMENT,
    INVOICEVALUE, STATISTICALVALUE, NETMASS, QTYINSUPPLUNITS
  )
  SELECT
    0 CODDINTRASTATA, vCodD CODDINTRASTAT,
    CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFCONSIGNMENT,
    Round(Sum(INVOICEVALUE)), Round(Sum(STATISTICALVALUE)), Round(Sum(NETMASS)), Round(Sum(QTYINSUPPLUNITS))
  FROM  TMP_DINTRASTAT_GEN
  WHERE TIPOPER = 1
  GROUP BY CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFCONSIGNMENT;

  INSERT INTO TMP_DINTRASTATD (
    CODDINTRASTATD, CODDINTRASTAT,
    CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR,
    INVOICEVALUE, STATISTICALVALUE, NETMASS, QTYINSUPPLUNITS
  )
  SELECT
    0 CODDINTRASTATD, vCodD CODDINTRASTAT,
    CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR,
    Round(Sum(INVOICEVALUE)), Round(Sum(STATISTICALVALUE)), Round(Sum(NETMASS)), Round(Sum(QTYINSUPPLUNITS))
  FROM  TMP_DINTRASTAT_GEN
  WHERE TIPOPER = 2
  GROUP BY CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR;

  UPDATE TMP_DIntrastat SET (INVOICEVALUE_A, STATISTICALVALUE_A, NETMASS_A) = (SELECT Sum(INVOICEVALUE), Sum(STATISTICALVALUE), Sum(NETMASS) FROM TMP_DIntrastatA);
  UPDATE TMP_DIntrastat SET (INVOICEVALUE_D, STATISTICALVALUE_D, NETMASS_D) = (SELECT Sum(INVOICEVALUE), Sum(STATISTICALVALUE), Sum(NETMASS) FROM TMP_DIntrastatD);
END;

PROCEDURE UmpleXML(pCodIntrastat NUMBER, pTipOper IN NUMBER, pTip IN NUMBER, pExtinsa IN NUMBER ) IS
  vValid NUMBER(5);
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_dintrastat_xmlh&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_dintrastat_xmld&apos;;

  INSERT INTO tmp_dintrastat_xmlh
  SELECT
    LPad(REGEXP_REPLACE(VatNr,&apos;\D+&apos;, &apos;&apos;), 10,&apos;0&apos;)||&apos;_&apos;||CASE pTipOper WHEN 1 THEN &apos;A&apos; ELSE &apos;D&apos; END|| CASE pTIp WHEN 0 THEN &apos;N&apos; WHEN 2 THEN &apos;R&apos; END||&apos;_&apos;||AN||LUNAD FileName,
    CASE
      --  2 -- CUI companie invalid!
      WHEN CIF_VALID(REGEXP_REPLACE(D.VatNr,&apos;\D+&apos;, &apos;&apos;)) = 0
      THEN   2
      --  3 -- Denumire companie necompletata!
      WHEN TRIM(D.FirmName)    IS NULL
      THEN   3
      --  4 -- Pozitie persoana de contact necompletata!
      WHEN TRIM(D.CPPOSITION)  IS NULL
      THEN   4
      --  5 -- Nume persoana de contact necompletat!
      WHEN TRIM(D.CPLASTNAME)  IS NULL
      THEN   5
      --  6 -- Prenume persoana de contact necompletat!
      WHEN TRIM(D.CPFIRSTNAME) IS NULL
      THEN   6
      --  7 -- CUI tert invalid!
      WHEN Coalesce(D.DTP, 0) = 1 AND CIF_VALID(REGEXP_REPLACE(D.DTPVatNr,&apos;\D+&apos;, &apos;&apos;)) = 0
      THEN   7
      --  8 -- Denumire tert necompletata!
      WHEN Coalesce(D.DTP, 0) = 1 AND TRIM(D.DTPFirmName) IS NULL
      THEN   8
      --  9 -- Cod localitate tert invalid (SIRUTA)!
      WHEN Coalesce(D.DTP, 0) = 1 AND Coalesce(L.SIRUTA, 0) = 0
      THEN   9
      -- 10  -- Exista linii fara Tara Origine!
      WHEN pTipOper = 1
       AND EXISTS (SELECT 1 FROM DINTRASTATA DA WHERE DA.CodDIntrastat = D.CodDIntrastat AND Trim(DA.COUNTRYOFORIGIN) IS NULL)
      THEN  10
      WHEN pTipOper = 2
       AND EXISTS (SELECT 1 FROM DINTRASTATD DD WHERE DD.CodDIntrastat = D.CodDIntrastat AND Trim(DD.COUNTRYOFORIGIN) IS NULL)
       THEN  10
      --13 -- QTYINSUPPLUNITS - eronat
      WHEN pTipOper = 1
       AND EXISTS (SELECT 1 FROM DINTRASTATA DA WHERE DA.CodDIntrastat = D.CodDIntrastat AND DA.SUPPLUNITCODE IS NOT NULL AND DA.QTYINSUPPLUNITS IS NULL )
      THEN  13
      WHEN pTipOper = 2
       AND EXISTS (SELECT 1 FROM DINTRASTATD DD WHERE DD.CodDIntrastat = D.CodDIntrastat AND DD.SUPPLUNITCODE IS NOT NULL AND DD.QTYINSUPPLUNITS IS NULL )
      THEN  13
      --101 -- avertisment lipsa InCoTerms, Mod transport sau Natura tranzactiei
      WHEN pTipOper = 1
       AND EXISTS ( SELECT 1 FROM DINTRASTATA DA WHERE DA.CodDIntrastat = D.CodDIntrastat AND (DA.NATUREOFTRANSACTIONACODE IS NULL OR DA.DELIVERYTERMSCODE IS NULL OR DA.MODEOFTRANSPORTCODE IS NULL) )
      THEN 101
      WHEN pTipOper = 2
       AND EXISTS ( SELECT 1 FROM DINTRASTATD DD WHERE DD.CodDIntrastat = D.CodDIntrastat AND (DD.NATUREOFTRANSACTIONACODE IS NULL OR DD.DELIVERYTERMSCODE IS NULL OR DD.MODEOFTRANSPORTCODE IS NULL) )
      THEN 101
      -- 111 -- NATUREOFTRANSACTIONACODE - avertisment (transformat 11 eronat -&gt; 111 avertisment)
      WHEN pTipOper = 1
       AND EXISTS (SELECT 1 FROM DINTRASTATA DA WHERE DA.CodDIntrastat = D.CodDIntrastat AND DA.NATUREOFTRANSACTIONACODE &lt;&gt; &apos;2&apos; AND DA.InvoiceValue &lt; 0 )
      THEN 111
      WHEN pTipOper = 2
       AND EXISTS (SELECT 1 FROM DINTRASTATD DD WHERE DD.CodDIntrastat = D.CodDIntrastat AND DD.NATUREOFTRANSACTIONACODE &lt;&gt; &apos;2&apos; AND DD.InvoiceValue &lt; 0 )
      THEN 111
      ELSE 1
    END Valid,
    CASE
      WHEN pTipOper = 1 AND  pTip = 0 THEN &apos;InsNillArrival&apos;
      WHEN pTipOper = 2 AND  pTip = 0 THEN &apos;InsNillDispatch&apos;
      WHEN pTipOper = 1 AND  pTip = 1 THEN &apos;InsNewArrival&apos;
      WHEN pTipOper = 2 AND  pTip = 1 THEN &apos;InsNewDispatch&apos;
      WHEN pTipOper = 1 AND  pTip = 2 THEN &apos;InsRevisedArrival&apos;
      WHEN pTipOper = 2 AND  pTip = 2 THEN &apos;InsRevisedDispatch&apos;
    END RootName,
    --InsCodeVersions
    --&apos;2021&apos; CountryVer, &apos;2021&apos; EuCountryVer, To_Char(D.An, &apos;fm0000&apos;) CnVer, &apos;2005&apos; ModeOfTransportVer, &apos;2021&apos; DeliveryTermsVer, &apos;2010&apos; NatureOfTransactionAVer, &apos;2010&apos; NatureOfTransactionBVer, &apos;1&apos; CountyVer, &apos;06/2006&apos; LocalityVer, &apos;1&apos; UnitVer,
    &apos;2022&apos; CountryVer, &apos;2022&apos; EuCountryVer, To_Char(D.An, &apos;fm0000&apos;) CnVer, &apos;2005&apos; ModeOfTransportVer, &apos;2021&apos; DeliveryTermsVer, &apos;2022&apos; NatureOfTransactionAVer, &apos;2022&apos; NatureOfTransactionBVer, &apos;1&apos; CountyVer, &apos;06/2006&apos; LocalityVer, &apos;1&apos; UnitVer,
    --InsDeclarationHeader
    LPad(REGEXP_REPLACE(VatNr,&apos;\D+&apos;, &apos;&apos;), 10,&apos;0&apos;) VatNr, FirmName, To_Char(AN,&apos;fm0000&apos;)||&apos;-&apos;||To_Char(LunaD,&apos;fm00&apos;) RefPeriod, To_Char(CURRENT_TIMESTAMP, &apos;YYYY-MM-DD&quot;T&quot;HH24:MI:SS.FF3&apos;)||SESSIONTIMEZONE CreateDt,
    --ContactPerson
    D.CPLASTNAME LastName, D.CPFIRSTNAME FirstName, D.CPEMAIL Email, D.CPPHONE Phone, D.CPFAX Fax, D.CPPOSITION Position,
    --DTPDetails
    DTP,
    LPad(REGEXP_REPLACE(DTPVatNr,&apos;\D+&apos;, &apos;&apos;), 10,&apos;0&apos;) DTPVatNr, D.DTPFirmName,
    --DTPAddress
    DTPSTREET Street, DTPSTREETNUMBER StreetNumber, DTPBLOCK Block, DTPSTAIRS Stairs, DTPAPARTMENT Apartment, L.SIRUTA LocalityCode, J.JS CountyCode, DTPPOSTALCODE PostalCode
  FROM DINTRASTAT D
    LEFT JOIN NLOCALIT L ON L.CodLocalit = D.DTPCODLOCALIT
    LEFT JOIN NJUDET   J ON J.CodJudet   = L.CODJUDET
  WHERE D.CodDIntrastat = pCodIntrastat;

  BEGIN
    SELECT VALID INTO vValid FROM tmp_dintrastat_xmlh;
  EXCEPTION
    WHEN OTHERS THEN vValid := 0;
  END;

  IF (vValid = 1) OR (vValid &gt; 100) THEN
    IF pTipOper = 1 THEN
      INSERT INTO tmp_dintrastat_xmld
      SELECT
        &apos;InsArrivalItem&apos; NumeNod, Cn8Code, Sum(InvoiceValue) InvoiceValue, Sum(CASE WHEN pExtinsa = 1 THEN Coalesce(StatisticalValue,0) ELSE NULL END)  StatisticalValue, Sum(NetMass) NetMass,
        NatureOfTransactionACode, NatureOfTransactionBCode, DeliveryTermsCode, ModeOfTransportCode, CountryOfOrigin, SupplUnitCode, Sum(QtyInSupplUnits) QtyInSupplUnits,
        CountryOfConsignment, CAST (NULL AS VARCHAR2(3)) CountryOfDestination, CAST (NULL AS VARCHAR2(3)) PartnerCountryCode, CAST (NULL AS VARCHAR2(3)) PartnerVatNr
      FROM DINTRASTATA
      WHERE CodDIntrastat = pCodIntrastat
      GROUP BY CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFCONSIGNMENT
      HAVING Sum(InvoiceValue) &lt;&gt; 0;
    ELSE
      INSERT INTO tmp_dintrastat_xmld
      SELECT
        &apos;InsDispatchItem&apos; NumeNod, Cn8Code, Sum(InvoiceValue) InvoiceValue, Sum(CASE WHEN pExtinsa = 1 THEN Coalesce(StatisticalValue,0) ELSE NULL END) StatisticalValue, Sum(NetMass) NetMass,
        NatureOfTransactionACode, NatureOfTransactionBCode, DeliveryTermsCode, ModeOfTransportCode, CountryOfOrigin, SupplUnitCode, Sum(QtyInSupplUnits) QtyInSupplUnits,
        CAST (NULL AS VARCHAR2(3)) CountryOfConsignment, CountryOfDestination, PartnerCountryCode, PartnerVatNr
      FROM DINTRASTATD D
      WHERE CodDIntrastat = pCodIntrastat
      GROUP BY CN8CODE, NATUREOFTRANSACTIONACODE, NATUREOFTRANSACTIONBCODE, DELIVERYTERMSCODE, MODEOFTRANSPORTCODE, COUNTRYOFORIGIN, SUPPLUNITCODE, COUNTRYOFDESTINATION, PARTNERCOUNTRYCODE, PARTNERVATNR
      HAVING Sum(InvoiceValue) &lt;&gt; 0;
    END IF;
  END IF;

  COMMIT;
END;

END PKG_DINTRASTAT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DISTANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11CEEF8D07612E4E9F2BE026F9EEA009C83FB5DE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DISTANTA is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodDistanta INTO Tmp FROM DISTANTA WHERE CodDistanta = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM DISTANTA WHERE CodDistanta = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DISTANTA FIELDS( CodDistanta ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_DISTANTA 
    (  CODDISTANTA,     
       CODGEST_START,   
       CODGEST_STOP,    
       CODLOCALIT_START,
       CODLOCALIT_STOP, 
       KM,              
       MONEDA,          
       VALOARE
     )         
	SELECT 
       CODDISTANTA,     
       CODGEST_START,   
       CODGEST_STOP,    
       CODLOCALIT_START,
       CODLOCALIT_STOP, 
       KM,              
       MONEDA,          
       VALOARE
  FROM DISTANTA  
  WHERE CodDistanta = RECID;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodDistanta INTO RECID FROM TMP_DISTANTA;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE DISTANTA
    SET
     ( CODDISTANTA,     
       CODGEST_START,   
       CODGEST_STOP,    
       CODLOCALIT_START,
       CODLOCALIT_STOP, 
       KM,              
       MONEDA,          
       VALOARE
     )
			= 
     ( SELECT 
         CODDISTANTA,     
         CODGEST_START,   
         CODGEST_STOP,    
         CODLOCALIT_START,
         CODLOCALIT_STOP, 
         KM,              
         MONEDA,          
         VALOARE
     FROM TMP_DISTANTA)
     WHERE CodDistanta = RECID;
  
 

ELSE  -- INSERT
    SELECT SEQ_DISTANTA_CODDISTANTA.NextVal INTO RecId FROM DUAL;
    INSERT INTO DISTANTA( 
      CODDISTANTA,     
      CODGEST_START,   
      CODGEST_STOP,    
      CODLOCALIT_START,
      CODLOCALIT_STOP, 
      KM,              
      MONEDA,          
      VALOARE
      )    
    SELECT 
  		RECID   , 
      CODGEST_START,   
      CODGEST_STOP,    
      CODLOCALIT_START,
      CODLOCALIT_STOP, 
      KM,              
      MONEDA,          
      VALOARE
		FROM TMP_DISTANTA; 
  END IF;
 NotifyModif(Operation, RecId, &apos;DISTANTA&apos;);
COMMIT;
 
END; 


end PKG_DISTANTA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76A2BCE38A47445331883DA4D9648B34B57E37CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DISTRIB IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_12&apos;;

function GetSoldPartLaData(vCodPart in number, vData in varchar) return number is
begin
  return 0;
end;

procedure GENTASKURI(vCod in number) is
RECID NUMBER(20);  
RECIDSEC NUMBER(20);
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
  if TaskFirma = 1 then 
		for v_rec in (select tr.dentraseu, to_date(LPAD(to_char(d.zi), 2, &apos;0&apos;)||&apos;.&apos;||LPAD(to_char(d.luna), 2, &apos;0&apos;)||&apos;.&apos;||to_char(d.an), &apos;dd.mm.yyyy&apos;) data, ut.username,
												 part.den_part, d2.codpart, p.obs
									from distrib d
											 inner join distrib1 d1 on d.coddistrib = d1.coddistrib
											 inner join distrib2 d2 on d2.coddistrib= d.coddistrib and d2.coddistrib1 = d1.coddistrib1
											 inner join traseulivr tr on tr.codtraseulivr = d1.codtraseu
											 inner join npart part on part.codpart = d2.codpart
											 left  join npers p on p.codpers = d1.codpers
											 left  join tmp_utilizator ut on p.logonname = ut.codutilizator
									where d.coddistrib = vCod     
									) loop
			SELECT Seq_SETTASK_CODTASK.NextVal INTO RecId FROM DUAL;
			INSERT INTO SETTASK 
			 (
				CODTASK,
				DESTINATAR,
				EXECUTANT,
				USERNAME,
				TERMEN,
				DATATASK,
				PROIECT,
				MESAJCATRE,
				codpart,
				codfirma)
			VALUES
			(
			 RecId, 
			 substr(v_rec.den_part,1,30),
			 substr(v_rec.username,1,30),
			 substr(pkg_globals.GETUSERNAME,1,30),
			 v_rec.data,
			 v_rec.data,
			 substrb(v_rec.dentraseu||&apos; &apos;||to_char(v_rec.data, &apos;dd.mm.yyyy&apos;)||&apos; &apos;||v_rec.obs,1,50),
			 substr(v_rec.username,1,30),
			 v_rec.codpart,
			 pkg_globals.GETCODFIRMA
			);
			commit;
			SELECT SEQ_SETTASKLOG_CODLOG.NextVal INTO RecIdSec FROM DUAL;
			pkg_settask.BagaInTaskLog(RecIdSec, RecId, SysDate, pkg_globals.GETUSERNAME,v_rec.USERNAME);
		end loop;                   
	else
    		for v_rec in (select tr.dentraseu, to_date(LPAD(to_char(d.zi), 2, &apos;0&apos;)||&apos;.&apos;||LPAD(to_char(d.luna), 2, &apos;0&apos;)||&apos;.&apos;||to_char(d.an), &apos;dd.mm.yyyy&apos;) data, ut.username,
												 part.den_part, d2.codpart, p.obs
									from distrib d
											 inner join distrib1 d1 on d.coddistrib = d1.coddistrib
											 inner join distrib2 d2 on d2.coddistrib= d.coddistrib and d2.coddistrib1 = d1.coddistrib1
											 inner join traseulivr tr on tr.codtraseulivr = d1.codtraseu
											 inner join npart part on part.codpart = d2.codpart
											 left  join npers p on p.codpers = d1.codpers
											 left  join tmp_utilizator ut on p.logonname = ut.codutilizator
									where d.coddistrib = vCod     
									) loop
			SELECT WINMADMIN.PKG_USERFIRME.getSeqNextVal(&apos;Seq_SETTASK_CODTASK&apos;) INTO RecId FROM DUAL;
			INSERT INTO WINMADMIN.SETTASK 
			 (
				CODTASK,
				DESTINATAR,
				EXECUTANT,
				USERNAME,
				TERMEN,
				DATATASK,
				PROIECT,
				MESAJCATRE,
				codpart,
				codfirma)
			VALUES
			(
			 RecId, 
			 substr(v_rec.den_part,1,30),
			 substr(v_rec.username,1,30),
			 substr(pkg_globals.GETUSERNAME,1,30),
			 v_rec.data,
			 v_rec.data,
			 substrb(v_rec.dentraseu||&apos; &apos;||to_char(v_rec.data, &apos;dd.mm.yyyy&apos;)||&apos; &apos;||v_rec.obs,1,50),
			 substr(v_rec.username,1,30),
			 v_rec.codpart,
			 pkg_globals.GETCODFIRMA
			);
			commit;
			SELECT WINMADMIN.PKG_USERFIRME.getSeqNextVal(&apos;WINMADMIN.SEQ_SETTASKLOG_CODLOG&apos;) INTO RecIdSec FROM DUAL;
			winmadmin.pkg_settask.BagaInTaskLog(RecIdSec, RecId, SysDate, pkg_globals.GETUSERNAME,v_rec.USERNAME);
		end loop;                   
 	end if;
end;  

procedure GENTASK(vDen_Part in varchar2, vExecutant in varchar2, vData in varchar2, vProiect in varchar2, vCodPart in number) is
RECID NUMBER(20);  
RECIDSEC NUMBER(20);
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
  if TaskFirma = 1 then 
		SELECT Seq_SETTASK_CODTASK.NextVal INTO RecId FROM DUAL;
		INSERT INTO SETTASK 
		 (
			CODTASK,
			DESTINATAR,
			EXECUTANT,
			USERNAME,
			TERMEN,
			DATATASK,
			PROIECT,
			MESAJCATRE,
			codpart,
			codfirma)
		VALUES
		(
		 RecId, 
		 vDen_part,
		 vExecutant,
		 substr(pkg_globals.GETUSERNAME,1,30),
		 to_date(vdata,&apos;dd.mm.yyyy&apos;),
		 to_date(vdata,&apos;dd.mm.yyyy&apos;),
		 vProiect,
		 vExecutant,
		 vCodpart,
		 pkg_globals.GETCODFIRMA
		);
		commit;
		SELECT SEQ_SETTASKLOG_CODLOG.NEXTVAL INTO RecIdSec FROM DUAL;
		pkg_settask.BagaInTaskLog(RecIdSec, RecId, SysDate, pkg_globals.GETUSERNAME,vExecutant);
	else
    SELECT WINMADMIN.PKG_USERFIRME.getSeqNextVal(&apos;Seq_SETTASK_CODTASK&apos;) INTO RecId FROM DUAL;
		INSERT INTO WINMADMIN.SETTASK 
		 (
			CODTASK,
			DESTINATAR,
			EXECUTANT,
			USERNAME,
			TERMEN,
			DATATASK,
			PROIECT,
			MESAJCATRE,
			codpart,
			codfirma)
		VALUES
		(
		 RecId, 
		 vDen_part,
		 vExecutant,
		 substr(pkg_globals.GETUSERNAME,1,30),
		 to_date(vdata,&apos;dd.mm.yyyy&apos;),
		 to_date(vdata,&apos;dd.mm.yyyy&apos;),
		 vProiect,
		 vExecutant,
		 vCodpart,
		 pkg_globals.GETCODFIRMA
		);
		commit;
		SELECT WINMADMIN.PKG_USERFIRME.getSeqNextVal(&apos;WINMADMIN.SEQ_SETTASKLOG_CODLOG&apos;) INTO RecIdSec FROM DUAL;
		winmadmin.pkg_settask.BagaInTaskLog(RecIdSec, RecId, SysDate, pkg_globals.GETUSERNAME,vExecutant);
  end if;
end;

procedure UpdateDistributieOnLuna(vAn IN NUMBER, vLuna IN NUMBER) is
azi date;
aCount number(10);
begin
  azi := to_date(&apos;01.&apos;||to_char(vLuna, &apos;99&apos;)||&apos;.&apos;||to_char(vAn), &apos;DD.MM.YYYY&apos;);
  while azi &lt;= last_day(to_date(&apos;01.&apos;||to_char(vLuna, &apos;99&apos;)||&apos;.&apos;||to_char(vAn), &apos;DD.MM.YYYY&apos;)) loop
    select count(*) into aCount 
    from distrib 
    where an = extract(YEAR FROM azi)
          and luna = extract(MONTH FROM azi)
          and zi = extract(DAY FROM azi)
          and subunitatea = pkg_globals.GETSUBUNITATE;
    if aCount = 0 then      
      insert into distrib(coddistrib, an, luna, zi, subunitatea) values 
      (seq_distrib_coddistrib.nextval, extract(YEAR FROM azi), extract(MONTH FROM azi), extract(DAY FROM azi), pkg_globals.getsubunitate);
    end if;  
    azi := azi + 1;
  end loop;
  commit;
end;

procedure UpdateDistributie is
azi date;
anini number(4); 
anfin number(4);
lunaini number(2); 
lunafin number(2);
aCount number(10);
begin
  --delete x;
  select aninitial into anini from firmaluni;
  select anmaxim into anfin from firmaluni;
  select lunainitiala into lunaini from firmaluni;
  select lunamaxima into lunafin from firmaluni;
  azi := to_date(&apos;01.&apos;||to_char(lunaini, &apos;99&apos;)||&apos;.&apos;||to_char(anini), &apos;DD.MM.YYYY&apos;);
  while azi &lt;= last_day(to_date(&apos;01.&apos;||to_char(lunafin, &apos;99&apos;)||&apos;.&apos;||to_char(anfin), &apos;DD.MM.YYYY&apos;)) loop
    select count(*) into aCount 
    from distrib 
    where an = extract(YEAR FROM azi)
          and luna = extract(MONTH FROM azi)
          and zi = extract(DAY FROM azi)
          and subunitatea = pkg_globals.GETSUBUNITATE;
    if aCount = 0 then      
      insert into distrib(coddistrib, an, luna, zi, subunitatea) values 
      (seq_distrib_coddistrib.nextval, extract(YEAR FROM azi), extract(MONTH FROM azi), extract(DAY FROM azi), pkg_globals.getsubunitate);
    end if;  
    azi := azi + 1;
  end loop;
  commit;
end;

procedure ExportTrasee(RecId in number) is
aCod number(20);
begin
  for v_rec in (select d.coddistrib
                from distrib d
                     inner join (select * from tmp_manevra_liste where filtru = &apos;DATA&apos;) tmp on d.zi = to_number(SubStr(tmp.valoare,1,2)) 
                                                                                            and d.luna = to_number(SubStr(tmp.valoare,4,2))
                                                                                            and d.an = to_number(SubStr(tmp.valoare,7,4))
                where d.coddistrib &lt;&gt; recid) loop
    delete distrib1 where coddistrib = v_rec.coddistrib;
    delete distrib2 where coddistrib = v_rec.coddistrib;
    delete distrib3 where coddistrib = v_rec.coddistrib;            
    for v_tmp in (select * from distrib1 where coddistrib = recid) loop
      select seq_distrib1_coddistrib1.nextval into aCod from dual;
      insert into distrib1 (coddistrib1, coddistrib, codpers, codauto, codtraseu)
      values (aCod, v_rec.coddistrib, v_tmp.codpers, v_tmp.codauto, v_tmp.codtraseu);
      
      insert into distrib2 (coddistrib2, coddistrib, coddistrib1, codagenda, sold, poztraseu, den_part, obs, adresa, den_judet, den_localit, codpart)
      select seq_distrib2_coddistrib2.nextval, v_rec.coddistrib, aCod, codagenda, sold, poztraseu, den_part, obs, adresa, den_judet, den_localit, codpart
      from distrib2 where coddistrib = recid and coddistrib1 = v_tmp.coddistrib1;
    end loop;  
  end loop;
  commit;                   
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodDistrib INTO Tmp FROM DISTRIB WHERE CodDistrib = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM DISTRIB1 WHERE CodDistrib = RecId;
  DELETE FROM DISTRIB  WHERE CodDistrib = RecId;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DISTRIB FIELDS( CodDistrib ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aDate date;
BEGIN
    
    INSERT INTO TMP_DISTRIB ( CODDISTRIB,                           
                              AN,                         
                              LUNA,                         
                              ZI,SUBUNITATEA)
                     ( select CODDISTRIB,                           
                              AN,                         
                              LUNA,                         
                              ZI, SUBUNITATEA
                         FROM DISTRIB 
                         WHERE CodDistrib = RecId ) ;
  
  select to_date(to_char(zi, &apos;99&apos;)||&apos;.&apos;||to_char(luna, &apos;99&apos;)||&apos;.&apos;||to_char(an), &apos;DD.MM.YYYY&apos;) into aDate from tmp_distrib;

  INSERT INTO TMP_DISTRIB1 ( CODDISTRIB1,                           
                             CODDISTRIB,                         
                             CODPERS,                         
                             CODAUTO,                         
                             CODTRASEU,
                             DenPers,
                             NrInreg,
                             DenTraseu )                        
                    ( select D1.CODDISTRIB1,                           
                             D1.CODDISTRIB,                         
                             D1.CODPERS,                         
                             D1.CODAUTO,                         
                             D1.CODTRASEU,
                             P.Nume||&apos; &apos;||P.Prenume,
                             A.NRINREG,
                             TL.DENTRASEU
                         FROM DISTRIB1 D1 
                              INNER JOIN NPERS P ON NVL(P.CodPers, 0) = D1.CODPERS
                              INNER JOIN TRASEULIVR TL ON NVL(D1.CODTRASEU, 0) = TL.CODTRASEULIVR
                              INNER JOIN NPARCAUT A ON NVL(D1.CODAUTO, 0) = A.CODNPARCAUT
                         WHERE CodDistrib = RecId );

  INSERT INTO TMP_DISTRIB2 (CODDISTRIB2,                             
                            CODDISTRIB,
                            CODDISTRIB1,                         
                            CODAGENDA,                         
                            SOLD,
                            poztraseu,
                            den_part,
                            obs,
                            adresa,
                            den_judet,
                            den_localit,
                            codpart)
                   ( SELECT CODDISTRIB2,                             
                            CODDISTRIB,
                            CODDISTRIB1,                         
                            CODAGENDA,                         
                            SOLD,
                            poztraseu,
                            den_part,
                            obs,
                            adresa,
                            den_judet,
                            den_localit,
                            codpart
                       FROM DISTRIB2 
                       WHERE CODDISTRIB = RecId );
                       
  insert into tmp_distrib3(coddistrib3, coddistrib, coddistrib1, coddistrib2, doc, prefixdoc, nrdoc
                           , datadoc, valreal, restreal, termen, zilescadente, simbolcont, den_subunit)             
  select coddistrib3, coddistrib, coddistrib1, coddistrib2, doc, prefixdoc, nrdoc
         , datadoc, valreal, restreal, termen, zilescadente, simbolcont, den_subunit
  from distrib3 where coddistrib = RecId;       
  
  insert into tmp_distrib_fact(coddistribfact, 
                               codies, 
                               prefixdoc, 
                               nrdoc, 
                               datadoc,
                               den_part, 
                               valdoc, 
                               den_pers, 
                               seriedoc, 
                               simbolmoneda,
                               ora,
                               CodPers,
                               Sediu,
                               Traseu)
                        select RowNum, 
                               i.codies, 
                               i.prefixdoc, 
                               i.nrdoc, 
                               i.datainreg,
                               p.den_part, 
                               i.valdoc, 
                               PERS.nume||&apos; &apos;||PERS.prenume, 
                               c.serie, 
                               m.simbol,
                               case 
                                 when EXTRACT(HOUR FROM i.datainreg) &lt; 10 then &apos;0&apos;||to_char(EXTRACT(HOUR FROM i.datainreg))
                                 else to_char(EXTRACT(HOUR FROM i.datainreg))
                               end||&apos;:&apos;||
                               case
                                 when EXTRACT(MINUTE FROM i.datainreg) &lt; 10 then &apos;0&apos;||to_char(EXTRACT(MINUTE FROM i.datainreg))
                                 else to_char(EXTRACT(MINUTE FROM i.datainreg))
                               end||&apos;:&apos;||
                               case 
                                 when EXTRACT(SECOND FROM i.datainreg) &lt; 10 then &apos;0&apos;||to_char(EXTRACT(SECOND FROM i.datainreg))
                                 else to_char(EXTRACT(SECOND FROM i.datainreg))
                               end,
                               PERS.CodPers,
                               ag.obs,
                               tr.dentraseu
                        from iesiri i       
                             inner join npart p on i.partener = p.codpart
                             inner join npers PERS on i.agent = PERS.codpers
                             inner join tmp_distrib1 d1 on PERS.codpers = d1.codpers
                             inner join doccarnete c on i.carnetdoc = c.codcarnet
                             left join nmonede m on i.moneda = m.codmoneda
                             left join nagenda ag on i.codlocatie = ag.codagenda
                             left join traseulivr tr on tr.codtraseulivr = ag.codtraseu
                        where i.datadoc = adate and i.subunitatea = pkg_globals.GETSUBUNITATE;
  
  insert into tmp_distrib_inc(coddistribinc, 
                               codtrezor1, 
                               prefixdoc, 
                               nrdoc, 
                               datadoc,
                               den_part, 
                               valdoc, 
                               den_pers, 
                               seriedoc, 
                               simbolmoneda,
                               ora,
                               CodPers,
                               sediu,
                               traseu)
                        select RowNum, 
                               t1.codtrezor1, 
                               t1.doc, 
                               t1.nrdoc, 
                               t1.datadoc,
                               p.den_part, 
                               t1.valdoc, 
                               PERS.nume||&apos; &apos;||PERS.prenume, 
                               c.serie, 
                               M.simbol,
                               EXTRACT(HOUR FROM t.datainreg)||&apos;:&apos;||EXTRACT(MINUTE FROM t.datainreg)||&apos;:&apos;||EXTRACT(SECOND FROM t.datainreg),
                               t1.Agent,
                               ag.obs,
                               tr.dentraseu
                        from trezor1 t1       
                             inner join trezor t on t1.codtrezor = t.codtrezor
                             inner join npart p on t1.codpart = p.codpart
                             inner join npers PERS on t1.Agent = PERS.codpers
                             inner join tmp_distrib1 d1 on PERS.codpers = d1.codpers
                             left join doccarnete c on t1.carnetdoc = c.codcarnet
                             LEFT OUTER JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
                             LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA     = B.CODMONEDA
                             left join nagenda ag on t1.codlocatie = ag.codagenda
                             left join traseulivr tr on tr.codtraseulivr = ag.codtraseu
                        where t1.Agent &gt; 0 and T.tipdoc = 29 and t1.datadoc = adate  and t.subunitatea = pkg_globals.GETSUBUNITATE
                        UNION ALL
                        select RowNum, 
                               t1.codtrezor1, 
                               t1.doc, 
                               t1.nrdoc, 
                               t1.datadoc,
                               p.den_part, 
                               t1.valdoc, 
                               pers.nume||&apos; &apos;||pers.prenume, 
                               c.serie, 
                               M.simbol,
                               EXTRACT(HOUR FROM t.datainreg)||&apos;:&apos;||EXTRACT(MINUTE FROM t.datainreg)||&apos;:&apos;||EXTRACT(SECOND FROM t.datainreg),
                               t.Agent Codpers,
                               ag.obs,
                               tr.dentraseu
                        from trezor1 t1       
                             inner join trezor t on t1.codtrezor = t.codtrezor
                             inner join npart p on t1.codpart = p.codpart
                             inner join npers pers on t.agent = pers.codpers
                             inner join tmp_distrib1 d1 on pers.codpers = d1.codpers
                             left join doccarnete c on t1.carnetdoc = c.codcarnet
                             LEFT OUTER JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
                             LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA     = B.CODMONEDA
                             left join nagenda ag on t1.codlocatie = ag.codagenda
                             left join traseulivr tr on tr.codtraseulivr = ag.codtraseu
                        where nvl(t1.Agent, 0) = 0 and t.agent &gt; 0 and T.tipdoc = 29 and t1.datadoc = adate  and t.subunitatea = pkg_globals.GETSUBUNITATE
                        UNION ALL
                        select RowNum, 
                               t1.codtrezor1, 
                               t1.doc, 
                               t1.nrdoc, 
                               t1.datadoc,
                               p.den_part, 
                               stingere.valoare, 
                               pers.nume||&apos; &apos;||pers.prenume, 
                               c.serie, 
                               M.simbol,
                               EXTRACT(HOUR FROM t.datainreg)||&apos;:&apos;||EXTRACT(MINUTE FROM t.datainreg)||&apos;:&apos;||EXTRACT(SECOND FROM t.datainreg),
                               i.Agent Codpers,
                               ag.obs,
                               tr.dentraseu
                        from trezor1 t1       
                             inner join trezor t on t1.codtrezor = t.codtrezor
                             inner join npart p on t1.codpart = p.codpart
                             inner join general gst on t1.codtrezor1 = gst.coddoc and t.tipdoc = gst.tipdoc
                             inner join obligpif ostingator on gst.codgeneral = ostingator.codgeneral
                             inner join stingere on stingere.codstingatorpif = ostingator.codobligpif
                             inner join obligpif ostins on stingere.codstinspif = ostins.codobligpif
                             inner join general gss on ostins.codgeneral = gss.codgeneral
                             inner join iesiri i on gss.coddoc = i.codies and gss.tipdoc = i.tipdoc
                             inner join npers pers on i.agent = pers.codpers
                             inner join tmp_distrib1 d1 on pers.codpers = d1.codpers
                             left join doccarnete c on t1.carnetdoc = c.codcarnet
                             LEFT OUTER JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
                             LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA     = B.CODMONEDA
                             left join nagenda ag on t1.codlocatie = ag.codagenda
                             left join traseulivr tr on tr.codtraseulivr = ag.codtraseu
                        where NVL(t1.Agent, 0) = 0 and nvl(t.agent, 0) = 0  
                              and T.tipdoc = 29 and t1.datadoc = adate  and t.subunitatea = pkg_globals.GETSUBUNITATE;
                        
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aCodDistrib1 number(20);
aCodDistrib2 number(20);
aCodUser number(20);
aCodSubunit number(20);
aDataDoc date;
BEGIN
  
  IF Operation = 0 THEN  -- UPDATE
  
    select Subunitatea into aCodSubunit from tmp_distrib;
    select to_date(zi||&apos;.&apos;||luna||&apos;.&apos;||an, &apos;DD.MM.YYYY&apos;) into aDataDoc from tmp_distrib;
    
    SELECT CodDistrib INTO RecId FROM TMP_DISTRIB;
    
    select NVL(USERID, 0) into aCodUser from Distrib where CodDistrib = RecId;
    if aCodUser = 0 then
      update distrib set
        USERID     = pkg_globals.USERID,
        DATACREARE = systimestamp
      where coddistrib = RecId;
      
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
      THEN

           WINMADMIN.PKG_USERFIRME.PostLog(&apos;DISTRIB&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                           RECID,PKG_GLOBALS.FIRMANAME,
                                           aCodSubunit, aDataDoc, to_char(aDataDoc),&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    else 
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
      THEN
         WINMADMIN.PKG_USERFIRME.PostLog(&apos;DISTRIB&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;,
                                           RECID,PKG_GLOBALS.FIRMANAME,
                                           aCodSubunit, aDataDoc, to_char(aDataDoc),&apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    end if;  

    DELETE FROM DISTRIB1 where CodDistrib = RecId and CodDistrib1 not in (Select CodDistrib1 from TMP_DISTRIB1);
    FOR v_rec IN ( SELECT * FROM TMP_DISTRIB1 ) LOOP
      if v_Rec.Coddistrib1 &gt; 0 then
       UPDATE DISTRIB1
       SET
         CODPERS   = v_rec.CODPERS,                         
         CODAUTO   = v_Rec.CODAUTO,                         
         CODTRASEU = v_rec.CODTRASEU
       WHERE CodDistrib1  = v_rec.CodDistrib1;
      else
        select seq_distrib1_coddistrib1.nextval into aCodDistrib1 from dual;
        
        update tmp_distrib2 set 
        coddistrib1 = aCodDistrib1 
        where coddistrib1 = v_rec.coddistrib1;
        
        update tmp_distrib3 set 
        coddistrib1 = aCodDistrib1 
        where coddistrib1 = v_rec.coddistrib1;
        
        insert into distrib1 (coddistrib1, coddistrib, codpers, codauto, codtraseu)
        values (aCodDistrib1, RecId, v_rec.codpers, v_rec.codauto, v_rec.codtraseu);
      end if; 
    END LOOP;
    
    delete from distrib2 where coddistrib = RecId;
    for v_rec in (select * from tmp_distrib2) loop
      select seq_distrib2_coddistrib2.nextval into aCodDistrib2 from dual;
      update tmp_distrib3 
      set coddistrib2 = aCodDistrib2
      where coddistrib2 = v_rec.coddistrib2;
      
      insert into distrib2 (coddistrib2, coddistrib, coddistrib1, codagenda, sold, poztraseu,
                            den_part, obs, adresa, den_judet, den_localit, codpart)
      values (acoddistrib2, v_rec.coddistrib, v_rec.coddistrib1, v_rec.codagenda, v_rec.sold, v_rec.poztraseu,
                            v_rec.den_part, v_rec.obs, v_rec.adresa, v_rec.den_judet, v_rec.den_localit, v_rec.codpart);
    end loop;
    
    delete from distrib3 where coddistrib = RecId;
    insert into distrib3 (coddistrib3, coddistrib, coddistrib1, coddistrib2, doc, prefixdoc, nrdoc, datadoc, valreal
                          , restreal, termen, zilescadente, simbolcont, den_subunit) 
    select seq_distrib3_coddistrib3.nextval, RecId, coddistrib1, coddistrib2, doc, prefixdoc, nrdoc, datadoc, valreal
                          , restreal, termen, zilescadente, simbolcont, den_subunit from tmp_distrib3;
    
  ELSE

  SELECT Seq_distrib_Coddistrib.NextVal INTO RecId FROM DUAL;
  INSERT INTO DISTRIB ( CODDISTRIB,                           
                        AN,                         
                        LUNA,                         
                        ZI)
               ( select RecId,                           
                        AN,                         
                        LUNA,                         
                        ZI
                   FROM TMP_DISTRIB );
    
  END IF;
  
  COMMIT;
END;  

end pkg_distrib; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DISTRIBCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30ADE3F7F1A1C90A769ADC0C80C06BD8E32F0EA6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DISTRIBCHELT IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodDISTRIBCHELT INTO Tmp FROM DISTRIBCHELT WHERE CODDISTRIBCHELT = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;  
  SP_LOCKRECORD(RecId);
  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 76) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;
   
  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 76;  
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 76;   
  DELETE FROM DISTRIBCHELT2 WHERE  CODDISTRIBCHELT = RecId;
  DELETE FROM DISTRIBCHELT1 WHERE  CODDISTRIBCHELT = RecId;
  DELETE FROM DISTRIBCHELT WHERE  CODDISTRIBCHELT  = RecId;
  NotifyModif(2, RecId, &apos;DISTRIBCHELT&apos;);
  COMMIT; 
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_DISTRIBCHELT FIELDS( CODDISTRIBCHELT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
ANLUNA_START number(10);
NR           number(20);
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO TMP_DISTRIBCHELT (CODDISTRIBCHELT,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU)
  SELECT CODDISTRIBCHELT,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU FROM DISTRIBCHELT WHERE CodDISTRIBCHELT = RECID;
 
  INSERT INTO TMP_DISTRIBCHELT1 (CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT, BUTON) 
  SELECT 
    PCF.CodDISTRIBCHELT1, 
    PCF.CodDISTRIBCHELT, 
    PCF.INDEXLOCAL, 
    PCF.CODNEST, 
    PCF.VAL, 
    NS.CODCONTD, 
    NS.CODCONTC, 
    NS.CODCENTRU, 
    NS.CODGEST, 
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20), 
    Substr(CREDIT.SIMBOL,1,20),
    &apos;   1&apos;
  FROM DISTRIBCHELT1 PCF
       LEFT JOIN NESTJURNAL NS ON PCF.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCF.CodDISTRIBCHELT = RECID;
 
  INSERT INTO TMP_DISTRIBCHELT2 
   (CodDISTRIBCHELT2, 
    CodDISTRIBCHELT1, 
    CodDISTRIBCHELT, 
    INDEXLOCAL,CODGEST,CODCENTRU,OBS,PROCENT,DENGEST,CENTRU)
  SELECT 
    PCF.CodDISTRIBCHELT2, 
    PCF.CodDISTRIBCHELT1, 
    PCF.CodDISTRIBCHELT, 
    PCF.INDEXLOCAL,PCF.CODGEST,PCF.CODCENTRU,PCF.OBS,PCF.PROCENT,
    Substr(G.DEN_GEST,1,30),  CC.Simbol
  FROM DISTRIBCHELT2 PCF
       LEFT JOIN NGEST G ON G.CODGEST = PCF.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = PCF.CODCENTRU
  WHERE PCF.CodDISTRIBCHELT = RECID;

  for v_rec in (select CodDISTRIBCHELT1 from Tmp_DISTRIBCHELT1) loop
     Select Count(*) into Nr from TMP_DISTRIBCHELT2 where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;
     if Nvl(Nr,0) &gt; 0 then 
       Update Tmp_DISTRIBCHELT1 
         set Buton = &apos;ü&apos;, 
             Total = (select Sum(nvl(Procent,0)) from TMP_DISTRIBCHELT2 where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1)
       where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1; 
     end if;
  end loop;     
  
  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 76 AND CODDOC = RECID);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 76 AND CODDOC = RECID);
  DELETE TMP_RULAJ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aNest number(20);
aCod  number(20);
Nr    number(20);
BEGIN
 
  IF OPERATION = 0 THEN
  
    SELECT CodDISTRIBCHELT INTO RECID FROM TMP_DISTRIBCHELT;
    
    UPDATE DISTRIBCHELT 
    SET (TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU) = 
    (SELECT TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU
     FROM TMP_DISTRIBCHELT)
     WHERE CodDISTRIBCHELT = RECID;    
    
    DELETE FROM DISTRIBCHELT2 WHERE CodDISTRIBCHELT = RECID AND CodDISTRIBCHELT2 NOT IN (SELECT CodDISTRIBCHELT2 FROM TMP_DISTRIBCHELT2);
    DELETE FROM DISTRIBCHELT1 WHERE CodDISTRIBCHELT = RECID AND CodDISTRIBCHELT1 NOT IN (SELECT CodDISTRIBCHELT1 FROM TMP_DISTRIBCHELT1);
    FOR V_REC IN (SELECT * FROM TMP_DISTRIBCHELT1) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;
      IF v_rec.CodDISTRIBCHELT1 &gt; 0 then
        UPDATE DISTRIBCHELT1 SET 
          CODNEST = aNEST,
          VAL     = V_REC.VAL  
        WHERE CodDISTRIBCHELT1 = V_REC.CodDISTRIBCHELT1; 
      else 
        select seq_DISTRIBCHELT1_CodDC1.nextval into aCod from dual; 
        update TMP_DISTRIBCHELT2 set CodDISTRIBCHELT1 = aCod where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;

        insert into DISTRIBCHELT1 (CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, codnest, val)
        values (aCod, recid, v_rec.INDEXLOCAL, anest, v_Rec.val);
      end if;  
    END LOOP;  

    FOR V_REC IN (SELECT * FROM TMP_DISTRIBCHELT2) LOOP
      IF v_rec.CodDISTRIBCHELT2 &gt; 0 then
        UPDATE DISTRIBCHELT2 SET 
          INDEXLOCAL = V_REC.INDEXLOCAL, 
          CODGEST = V_REC.CODGEST,
          CODCENTRU = V_REC.CODCENTRU,
          PROCENT   = V_REC.PROCENT  
        WHERE CodDISTRIBCHELT2 = V_REC.CodDISTRIBCHELT2; 
      else 
        insert into DISTRIBCHELT2 (CodDISTRIBCHELT2, CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, codgest, procent, CodCentru)
        values (seq_DISTRIBCHELT2_CodDC2.nextval, v_Rec.CodDISTRIBCHELT1, recid, v_rec.INDEXLOCAL, v_Rec.CodGest, v_Rec.procent, v_rec.CodCentru);
      end if;  
    END LOOP;  
-- detail JURNAlL1

    DELETE FROM JURNAl1 WHERE TIPDOC = 76 AND CODDOC = RECID AND CODJURNAL1 NOT IN
    (SELECT CODJURNAL1 FROM TMP_JURNAl1);
    
    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
     IF V_REC.CODJURNAL1 &gt; 0 THEN
      UPDATE JURNAL1
      SET 
        CODDOC       = V_REC.CODDOC,       
        TIPDOC       = V_REC.TIPDOC,
        INDEXLOCAL   = V_REC.INDEXLOCAL,
    
        CODBAZAD     = V_REC.CODBAZAD,
        ICONTBAZAD   = V_REC.ICONTBAZAD,
        TIPBAZAD     = V_REC.TIPBAZAD,
        CODBAZAC     = V_REC.CODBAZAC,
        ICONTBAZAC   = V_REC.ICONTBAZAC,
        TIPBAZAC     = V_REC.TIPBAZAC,
    
        CODDESCRD     = V_REC.CODDESCRD,
        ICONTD        = V_REC.ICONTD,
        TIPCONTD      = V_REC.TIPCONTD,
        ANALITICCONTD = V_REC.ANALITICCONTD,
        CODDESCRC     = V_REC.CODDESCRC,
        ICONTC        = V_REC.ICONTC,
        TIPCONTC      = V_REC.TIPCONTC,
        ANALITICCONTC = V_REC.ANALITICCONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        DIRTY         = V_REC.DIRTY,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        CODCENTRU     = V_REC.CODCENTRU,
        DATADOC       = V_REC.DATADOC,
        DOCUMENT      = V_REC.DOCUMENT
      WHERE 
        CODJURNAL1 = V_REC.CODJURNAl1; 
     ELSE
       INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT ) 
       VALUES 
       (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
     END IF; 
    END LOOP;
      
    
    
    -- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 76 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);
    
    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET  
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC, 
        INDEXLOCAL = V_REC.INDEXLOCAL, 
        CONTD      = V_REC.CONTD, 
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE, 
        VALOAREV   = V_REC.VALOAREV, 
        OBS        = V_REC.OBS, 
        AN         = V_REC.AN, 
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = V_REC.CODCENTRU,  
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT   
      WHERE 
        CODJURNAL = V_REC.CODJURNAl; 
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)  
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
     END IF; 
    END LOOP;
  
  ELSE -- INSERT
  
  SELECT SEQ_DISTRIBCHELT_CodDC.NEXTVAL INTO RECID FROM DUAL;
  
  INSERT INTO DISTRIBCHELT (CodDISTRIBCHELT, TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU)
  SELECT RECID,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,sysdate,BLOCAT,OPERAT,FAZA,CODGEST,COEFPROD,CODCENTRU FROM TMP_DISTRIBCHELT;
  
  FOR V_REC IN (SELECT * FROM TMP_DISTRIBCHELT1) LOOP
    aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); 

    select seq_DISTRIBCHELT1_CodDC1.nextval into aCod from dual; 
    update TMP_DISTRIBCHELT2 set CodDISTRIBCHELT1 = aCod where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;

    insert into DISTRIBCHELT1 (CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, codnest, val)
    values (aCod, recid, v_rec.INDEXLOCAL, anest, v_Rec.val);
  END LOOP;  

  insert into DISTRIBCHELT2 (
    CodDISTRIBCHELT2, 
    CodDISTRIBCHELT1, 
    CodDISTRIBCHELT, 
    INDEXLOCAL, 
    codgest, 
    CodCentru,
    procent)
  SELECT 
    seq_DISTRIBCHELT2_CodDC2.nextval, 
    CodDISTRIBCHELT1, 
    recid, 
    INDEXLOCAL, 
    codgest, 
    CodCentru,
    procent
  FROM TMP_DISTRIBCHELT2;

  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT ) 
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT FROM TMP_JURNAL1);



 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)  
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT FROM TMP_JURNAL);

   
 END IF;

 -- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
   
     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;
  
     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
     WHERE 
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  
     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
  
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;
      
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF; 
  
  END LOOP;
 
  PKG_GLOBALS.MarkDirtyJurnal; 
  NotifyModif(Operation, RecId, &apos;DISTRIBCHELT&apos;); 
COMMIT; 
EXCEPTION WHEN OTHERS THEN 
  ROLLBACK;
  RAISE;
END;  

end PKG_DISTRIBCHELT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DOCSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F195D2FA020B4FB1FBD3057BBFB14C2C920EE25</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DOCSUPLIM IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodDocSuplim INTO Tmp FROM DOCSUPLIM WHERE CodDocSuplim = RecId FOR UPDATE NOWAIT;
END;
  
  
PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM DOCSUPLIM1 WHERE CodDocSuplim = RecId ;
  DELETE FROM DOCSUPLIM  WHERE CodDocSuplim = RecId ;

  DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 11); 
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 11; 

  NotifyModif(2, RecId, &apos;DOCSUPLIM&apos;);
  COMMIT;
END;
  
PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DOCSUPLIM FIELDS( CodDocSuplim ) VALUES (0) ;
  COMMIT;
END;
  
PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master DOCSUPLIM
  INSERT INTO  TMP_DOCSUPLIM ( CODDOCSUPLIM, TIPDOC,DENDOC, NRDOC, DATADOC,AN, LUNA, SUBUNITATEA,USERID, DATACREARE)
    ( SELECT CODDOCSUPLIM, TIPDOC,DENDOC, NRDOC,DATADOC,AN, LUNA, SUBUNITATEA,USERID, DATACREARE
    FROM DOCSUPLIM WHERE CODDOCSUPLIM = RecId ) ;
  
  INSERT INTO  TMP_DOCSUPLIM1 ( CodDocSuplim1,CodDocSuplim,DenLinie,Valoare,ValoareV)
    ( SELECT CodDocSuplim1,CodDocSuplim,DenLinie,Valoare,ValoareV
      FROM DOCSUPLIM1 WHERE CODDOCSUPLIM = RecId ) ;

  COMMIT;
END;
  
  
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodDocSuplim INTO RecId FROM TMP_DOCSUPLIM;
    
    UPDATE Docsuplim SET ( TIPDOC, DENDOC, NRDOC,DATADOC )
                       = ( SELECT TIPDOC,DENDOC, NRDOC,DATADOC FROM TMP_DOCSUPLIM )
    WHERE CodDocSuplim = RecId ;
  
    DELETE FROM DOCSUPLIM1 where CODDOCSUPLIM = RecId and CODDOCSUPLIM1 not in (Select CODDOCSUPLIM1 from TMP_DOCSUPLIM1);
    FOR v_rec IN ( SELECT * FROM TMP_DOCSUPLIM1 WHERE CODDOCSUPLIM1 &gt; 0 ) LOOP
       UPDATE DOCSUPLIM1
       SET
        DENLINIE  = V_REC.DENLINIE, 
        VALOARE   = V_REC.VALOARE , 
        VALOAREV  = V_REC.VALOAREV
       WHERE CODDOCSUPLIM1  = v_rec.CODDOCSUPLIM1;
    END LOOP;

    INSERT INTO DOCSUPLIM1 
    ( CodDOCSUPLIM1, CodDOCSUPLIM, DENLINIE, VALOARE, VALOAREV)
    SELECT SEQ_DOCSUPLIM1_CODDOCSUPLIM1.Nextval , RecId , DENLINIE, VALOARE, VALOAREV
    FROM TMP_DOCSUPLIM1 WHERE CODDOCSUPLIM1 &lt; 0;

  
  ELSE  -- INSERT
 
    SELECT Seq_Docsuplim_Coddocsuplim.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO  Docsuplim ( CODDOCSUPLIM, TIPDOC,DENDOC, NRDOC,DATADOC,AN, LUNA, SUBUNITATEA, USERID, DATACREARE)
              ( SELECT  RecId , TIPDOC,DENDOC, NRDOC,DATADOC,AN, LUNA, SUBUNITATEA, pkg_globals.USERID, systimestamp
                FROM Tmp_Docsuplim ) ;

    INSERT INTO DOCSUPLIM1 
    ( CodDOCSUPLIM1, CodDOCSUPLIM, DENLINIE, VALOARE, VALOAREV)
    SELECT SEQ_DOCSUPLIM1_CODDOCSUPLIM1.Nextval , RecId , DENLINIE, VALOARE, VALOAREV
    FROM TMP_DOCSUPLIM1;

  END IF;
  NotifyModif(Operation, RecId, &apos;DOCSUPLIM&apos;);
  
  COMMIT;
  
END;



END PKG_DOCSUPLIM; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DOCUMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F1E49AC723D50DE704CB116BEA82E90F2542098</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DOCUMENTE IS

gCodDoc number(20);
gTipDoc number(20);
gOwner  varchar2(50);

PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number ,aOwner in varchar2) is
BEGIN
  gCodDoc := aCodDoc;
  gTipDoc := aTipDoc;
  gOwner  := upper(aOwner) ;
END;

PROCEDURE ACTUALIZARE_X_NUMEFISIER(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2) IS
  vCNT NUMBER;
BEGIN
  SELECT Count(1) INTO vCNT 
  FROM DOCUMENTE d 
  WHERE d.CODDOC = aCodDoc 
       AND d.TIPDOC = aTipDoc 
       AND Coalesce(d.TIPDOCUMENT, 0) = Coalesce(aTipDocument, 0)
       AND d.filename = aNumeFisier;
  IF vCNT = 0 THEN 
    INSERT INTO DOCUMENTE ( coddocument     ,  coddoc,  tipdoc,  filename  ,  tipdocument, userid               , datacreare)
    VALUES(seq_documente_coddocument.Nextval, aCodDoc, aTipDoc, aNumeFisier, aTipDocument, pkg_globals.GETUSERID, SYSDATE);
  END IF;         
END;

PROCEDURE ACTUALIZARE(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2) IS
  vCNT NUMBER;
BEGIN
  ACT_COND_UPDATE(aCodDoc, aTipDoc, aTipDocument, aNumeFisier, 1); 
END;

PROCEDURE ACT_COND_UPDATE(aCodDoc IN NUMBER , aTipDoc IN NUMBER , aTipDocument IN NUMBER , aNumeFisier IN VARCHAR2, forceUpdate IN NUMBER DEFAULT 1) IS
  vCNT NUMBER;
BEGIN
  SELECT Count(1) INTO vCNT FROM DOCUMENTE WHERE CODDOC = aCodDoc AND TIPDOC = aTipDoc AND Coalesce(TIPDOCUMENT, 0) = Coalesce(aTipDocument, 0);
  IF vCNT = 0 THEN 
    INSERT INTO DOCUMENTE ( coddocument     ,  coddoc,  tipdoc,  filename  ,  tipdocument, userid               , datacreare)
    VALUES(seq_documente_coddocument.Nextval, aCodDoc, aTipDoc, aNumeFisier, aTipDocument, pkg_globals.GETUSERID, SYSDATE);
  ELSE IF (forceUpdate = 1) THEN
          UPDATE DOCUMENTE
          SET filename =  aNumeFisier, datacreare = Sysdate, UserID = pkg_globals.GETUSERID 
          WHERE CODDOC = aCodDoc AND TIPDOC = aTipDoc AND Coalesce(TIPDOCUMENT, 0) = Coalesce(aTipDocument, 0);
       END IF;
  END IF;
  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  TMP NUMBER(20);
  TaskFirma number(1);
begin
   SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	 INTO TaskFirma from dual;
  if gTipDoc in (1,2,3,4,5,6,7,9) then
      pkg_intrari.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (14,15,16,19,20,21,22,23,24,26) then
      pkg_iesiri.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (12,13) then
      pkg_miscari_interne.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (8,18,43,44,53) then
     pkg_comanda.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (10, 25, 27, 34) then
     pkg_contract.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (29,30,31,33) then
     pkg_trezor.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (28) then
     pkg_compensari.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (45,46,47) then
     Pkg_Regpart.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc = 54 then
    if TaskFirma = 1 then winmadmin.pkg_settask.SP_LOCKRECORD(gCodDoc);
		                 else pkg_settask.SP_LOCKRECORD(gCodDoc); end if;
  end if;

  if gTipDoc in (63) then
     PKG_RAPORTP.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (97) then
     PKG_Reclamatii.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc in (99) then
     PKG_Voucher.SP_LOCKRECORD(gCodDoc);
  end if;

  if gTipDoc = 500 then
    pkg_nompart.SP_LOCKRECORD(gCodDoc);
  end if;
  if gTipDoc = 501 then
    pkg_nom_articol.SP_LOCKRECORD(gCodDoc);
  end if;
  if gTipDoc = 502 then
    pkg_nompers.SP_LOCKRECORD(gCodDoc);
  end if;
  if gTipDoc = 508 then
    pkg_utilaje.SP_LOCKRECORD(gCodDoc);
  end if;
  if gTipDoc = 516 then
    select codutilaj20 into TMP from utilaje20 where codutilaj20 = gCodDoc for update nowait;
  end if;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  execute immediate
  &apos; delete from &apos;||gOwner||&apos;.documente d where &apos;||
    &apos; d.coddoc = &apos;||gCodDoc||&apos; and d.tipdoc = &apos;||gTipDoc ;

  NotifyModif(2, RecId, &apos;DOCUMENTE&apos;);
  COMMIT;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_DOCUMENTE(CODDOCUMENT) VALUES (0);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
BEGIN
  if gOwner = &apos;WINMADMIN&apos; then
--    insert into tmp_masterDoc(Cod, Coddosar) values (101,0);

    insert into tmp_documente(coddocument,coddoc,tipdoc,filename,doc,obs,USERID, DATACREARE,CODDOSAR,EXTERN,incarcat,marime)
    select coddocument,coddoc,tipdoc,filename,doc,obs,USERID, DATACREARE, 0/*CODDOSAR*/, CASE when doc is null then 2 else 1 end,1,round(dbms_lob.getlength(doc)/1024,2)
    from WINMADMIN.documente where coddoc = gCodDoc and tipdoc = gTipDoc;

  else
--    insert into tmp_masterDoc(Cod, Coddosar) values (101,0);

    insert into tmp_documente(coddocument,coddoc,tipdoc,filename,doc,obs,CODDEPOZIT, TIPDOCUMENT, USERID, DATACREARE,CODDOSAR,EXTERN,incarcat,marime,expefact)
    select coddocument,coddoc,tipdoc,filename,doc,obs,CODDEPOZIT, TIPDOCUMENT, USERID, DATACREARE, CODDOSAR, CASE when doc is null then 2 else 1 end,1,round(dbms_lob.getlength(doc)/1024,2),expEfact
    from documente where coddoc = gCodDoc and tipdoc = gTipDoc;

/* a zis Miki sa nu mai folosim tabla MasterDoc

   for v_rec in (select CodDosar from tmp_documente) loop
      if nvl(v_rec.CodDosar,0) &gt; 0 then
        update tmp_masterdoc set CodDosar = v_rec.CodDosar;
      end if;
    end loop;
*/
  end if;
  commit;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
STR VARCHAR2(1000);
aCodDosar number;
BEGIN
   update TMP_DOCUMENTE set Doc = null where Extern = 2;
  if gOwner = &apos;WINMADMIN&apos; then
    IF Operation = 0 THEN  -- UPDATE
      DELETE FROM WINMADMIN.DOCUMENTE where coddoc = gCodDoc and tipdoc = gTipDoc and CODDOCUMENT not in (Select CODDOCUMENT from TMP_DOCUMENTE);
      INSERT INTO WINMADMIN.DOCUMENTE
      ( coddocument,coddoc,tipdoc,filename,doc,obs, userid,datacreare) --,CodDosar )
      SELECT WINMADMIN.seq_documente_coddocument.Nextval , gCodDoc,gTipDoc, filename,doc,obs, pkg_globals.GETUSERID,sysdate--, aCodDosar
      FROM TMP_DOCUMENTE WHERE CODDOCUMENT &lt; 0;

      FOR v_rec IN ( SELECT * FROM TMP_DOCUMENTE WHERE CODDOCUMENT &gt; 0 ) LOOP
         UPDATE WINMADMIN.DOCUMENTE
         SET
          filename  = V_REC.filename ,
          doc       = V_REC.doc      ,
--					CODDEPOZIT, TIPDOCUMENT= V_REC.CODDEPOZIT, TIPDOCUMENT,
          obs       = V_REC.obs
--          CodDosar  = aCodDosar
         WHERE CODDOCUMENT  = v_rec.CODDOCUMENT;
      END LOOP;

    ELSE  -- INSERT
      INSERT INTO WINMADMIN.DOCUMENTE
      ( coddocument,coddoc,tipdoc,filename,doc,obs, userid,datacreare)--,CodDosar )
      SELECT WINMADMIN.seq_documente_coddocument.Nextval , gCodDoc,gTipDoc, filename,doc,obs, pkg_globals.GETUSERID,sysdate--, aCodDosar
      FROM TMP_DOCUMENTE;
    END IF;
  else
/*
    begin
      Select CodDosar into aCodDosar from TMP_MasterDoc;
    exception when others then aCodDosar := 0;
    end;
*/
    update Tmp_Documente set DataCreare = sysdate where DataCreare is null;

    IF Operation = 0 THEN  -- UPDATE
      DELETE FROM DOCUMENTE where coddoc = gCodDoc and tipdoc = gTipDoc and CODDOCUMENT not in (Select CODDOCUMENT from TMP_DOCUMENTE);
      INSERT INTO DOCUMENTE
      ( coddocument,coddoc,tipdoc,filename,doc,obs, CODDEPOZIT, TIPDOCUMENT, userid,datacreare,CodDosar,expefact )
      SELECT seq_documente_coddocument.Nextval , gCodDoc,gTipDoc, filename,doc,obs, CODDEPOZIT, TIPDOCUMENT, pkg_globals.GETUSERID,DataCreare, CodDosar,expefact
      FROM TMP_DOCUMENTE WHERE CODDOCUMENT &lt; 0;

      FOR v_rec IN ( SELECT * FROM TMP_DOCUMENTE WHERE CODDOCUMENT &gt; 0 ) LOOP
         UPDATE DOCUMENTE
         SET
          filename  = V_REC.filename ,
          doc       = V_REC.doc      ,
          obs       = V_REC.obs      ,
					CODDEPOZIT= V_REC.CODDEPOZIT,
					TIPDOCUMENT= V_REC.TIPDOCUMENT,
          datacreare = V_REC.datacreare,
					CodDosar  = V_REC.CodDosar,
          expefact  = v_rec.expefact
         WHERE CODDOCUMENT  = v_rec.CODDOCUMENT;
      END LOOP;

    ELSE  -- INSERT
      INSERT INTO DOCUMENTE
      ( coddocument,coddoc,tipdoc,filename,doc,obs, CODDEPOZIT, TIPDOCUMENT, userid,datacreare,CodDosar,expefact )
      SELECT seq_documente_coddocument.Nextval , gCodDoc,gTipDoc, filename,doc,obs, CODDEPOZIT, TIPDOCUMENT, pkg_globals.GETUSERID,datacreare, CodDosar,expefact
      FROM TMP_DOCUMENTE;
    END IF;
  end if;
  NotifyModif(Operation, RecId, &apos;DOCUMENTE&apos;);
  commit;
END;

end PKG_DOCUMENTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DOMENIIACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6967F6C6ADA9268571837AE21039DC0263F75BFC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_domeniiact is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_58&apos;;

procedure SP_LockRecord(RecId in NUMBER) is
  Tmp NUMBER(20);
begin
  SELECT CodDomeniuAct INTO Tmp FROM DomeniiAct WHERE CodDomeniuAct = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
  aDoc varchar2(250);
begin
  SP_LockRecord(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Domeniu de activitate &quot;&apos;||dendomeniuact||&apos;&quot;&apos; INTO aDoc FROM DomeniiAct WHERE coddomeniuact = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;DomeniiAct&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM DomeniiAct WHERE CodDomeniuAct = RecId;
  NotifyModif(2, RecId, &apos;DomeniiAct&apos;);
  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_DomeniiAct FIELDS(CodDomeniuAct) VALUES (0);
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
begin
  INSERT INTO Tmp_DomeniiAct (
    CodDomeniuAct,
    DenDomeniuAct,
    CodCAEN
  )(
    SELECT
      CodDomeniuAct,
      DenDomeniuAct,
      CodCAEN
    FROM DomeniiAct
    WHERE CodDomeniuAct = RecId
  );
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
  aDoc varchar2(250);
begin
  if Operation = 0 then -- UPDATE
    SELECT CodDomeniuAct INTO RecId FROM Tmp_DomeniiAct;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Domeniu de activitate &quot;&apos;||dendomeniuact||&apos;&quot;&apos; INTO aDoc FROM DomeniiAct WHERE coddomeniuact = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DomeniiAct&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    UPDATE DomeniiAct SET (
      CodDomeniuAct,
      DenDomeniuAct,
      CodCAEN
    ) = (
      SELECT
        CodDomeniuAct,
        DenDomeniuAct,
        CodCAEN
      FROM Tmp_DomeniiAct
    )
    WHERE CodDomeniuAct = RecId;
  else -- INSERT
    SELECT Seq_DomeniiAct_CodDomeniuAct.NextVal INTO RecId FROM DUAL;
    INSERT INTO DomeniiAct (
      CodDomeniuAct,
      DenDomeniuAct,
      CodCAEN
    )(
      SELECT
        RecId,
        DenDomeniuAct,
        CodCAEN
      FROM Tmp_DomeniiAct
    );
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Domeniu de activitate &quot;&apos;||dendomeniuact||&apos;&quot;&apos; INTO aDoc FROM DomeniiAct WHERE coddomeniuact = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DomeniiAct&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end if;
  NotifyModif(Operation, RecId, &apos;DomeniiAct&apos;);
  COMMIT;
end;

end PKG_DOMENIIACT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DOSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8772C353D70D39C121B5035251EEAFE034BA18C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_dosare IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_50&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODDOSAR INTO Tmp FROM DOSARE WHERE CODDOSAR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Dosar &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM DOSARE WHERE coddosar = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOSARE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

 	DELETE FROM DOSARE WHERE CODDOSAR = RecId ;
  NotifyModif(2, RecId, &apos;DOSARE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DOSARE FIELDS( CODDOSAR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_DOSARE SELECT * FROM DOSARE WHERE CODDOSAR = RECID;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODDOSAR INTO RECID FROM TMP_DOSARE;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Dosar &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM DOSARE WHERE coddosar = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOSARE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE DOSARE
    SET (DENUMIRE, DULAP, RAFT, TIP) = (SELECT DENUMIRE, DULAP, RAFT, TIP FROM TMP_DOSARE)
    WHERE CODDOSAR = RECID;
  ELSE  -- INSERT
    SELECT SEQ_DOSARE_CODDOSAR.NextVal INTO RecId FROM DUAL;
    INSERT INTO DOSARE(CODDOSAR, DENUMIRE, DULAP, RAFT, TIP)
    SELECT RECID, DENUMIRE, DULAP, RAFT, TIP FROM TMP_DOSARE;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Dosar &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM DOSARE WHERE coddosar = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DOSARE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  END IF;

  NotifyModif(Operation, RecId, &apos;DOSARE&apos;);
  COMMIT;

END;


end PKG_DOSARE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCE891D9606243326DADC5710F678E3C65644E73</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DPROFIT is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_67&apos;;

function INCHID711CU121(vAn in number, vLuna in number, vSimbol in varchar2, vTipProfit in number) return number is
sSelect varchar2(10000);
vRez number(20,7);  
vLunaIni number(2);
begin
  --if vTipProfit = 2 then vLunaIni := 1; else vLunaIni := vLuna - 2; end if;
  vLunaIni := 1;
  vRez := 0; 
  sSelect := &apos;
  WITH
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||vAn||&apos;*12+&apos;||vLuna||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;&apos;||vSimbol||&apos;&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0) - nvl(credit,0)) from (
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||vAn||&apos;*12+&apos;||vLunaIni||&apos; AND &apos;||vAn||&apos;*12+&apos;||vLuna||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||vAn||&apos;*12+&apos;||vLunaIni||&apos; AND &apos;||vAn||&apos;*12+&apos;||vLuna||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin
    insert into x(test) values (sselect);  
    execute immediate sSelect into vRez;
    execute immediate &apos;commit&apos;;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODDPROFIT INTO Tmp FROM DPROFIT WHERE CodDProfit = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
aCodSubunit NUMBER(20);
aDataDoc DATE;
aDoc varchar2(200);  
BEGIN
  SP_LOCKRECORD(RecId);

  SELECT
    SUBUNITATEA,
    to_date(to_char(DATACREARE,&apos;DD.MM.YYYY HH24:MI:SS&apos;), &apos;DD.MM.YYYY HH24:MI:SS&apos;),
    &apos;An:&apos;||An||&apos;, Trim:&apos;||Trimestru
  INTO
    aCodSubunit,
    aDataDoc,
    ADOC
  FROM
    DPROFIT
  WHERE
    CODDPROFIT = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;DPROFIT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM DPROFITV WHERE CODDPROFIT = RECID;
  DELETE FROM DPROFITC WHERE CODDPROFIT = RECID;
  DELETE FROM DPROFIT WHERE CODDPROFIT = RECID;

  NotifyModif(2, RecId, &apos;DPROFIT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_DPROFIT FIELDS(CODDPROFIT) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_DPROFIT (CODDPROFIT, TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
                           CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
                           IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
                           TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
                           ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
                           USERID, DATACREARE,TRIMESTRUT)
  SELECT CODDPROFIT, TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
         CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
         IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
         TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
         ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
         USERID, DATACREARE,TRIMESTRUT
  FROM DPROFIT WHERE CODDPROFIT = RECID;       

  INSERT INTO TMP_DPROFITV (CODDPROFITV, CODDPROFIT, CODCONT, RULAJ, VENITURI, SUMA, SIMBOL, DEN_CONT, TIPCONT)
  SELECT D.CODDPROFITV, D.CODDPROFIT, D.CODCONT, D.RULAJ, D.VENITURI, D.SUMA, C.SIMBOL, C.DEN_CONT, DECODE(C.TIPCONT,0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;)
  FROM DPROFITV D
       INNER JOIN NCONT C ON C.CODCONT = D.CODCONT
  WHERE D.CODDPROFIT = RECID;

  INSERT INTO TMP_DPROFITC (CODDPROFITC, CODDPROFIT, CODCONT, RULAJ, CHELTUIELI, SUMA, SIMBOL, DEN_CONT, TIPCONT)
  SELECT D.CODDPROFITC, D.CODDPROFIT, D.CODCONT, D.RULAJ, D.CHELTUIELI, D.SUMA, C.SIMBOL, C.DEN_CONT, DECODE(C.TIPCONT,0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;)
  FROM DPROFITC D
       INNER JOIN NCONT C ON C.CODCONT = D.CODCONT  
  WHERE D.CODDPROFIT = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
vCod   NUMBER(20);
aCodSubunit NUMBER(20);
aDataDoc DATE;
aDoc varchar2(200);
aDataCreare timestamp(6);
BEGIN
  IF Operation = 0
  THEN  
    SELECT CODDPROFIT INTO RecId FROM TMP_DPROFIT;
    SELECT
      SUBUNITATEA,
      to_date(to_char(DATACREARE,&apos;DD.MM.YYYY HH24:MI:SS&apos;), &apos;DD.MM.YYYY HH24:MI:SS&apos;),
      &apos;An:&apos;||An||&apos;, Trim:&apos;||Trimestru
    INTO
      aCodSubunit,
      aDataDoc,
      ADOC
    FROM
      TMP_DPROFIT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DPROFIT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE DPROFIT
    SET (TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
         CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
         IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
         TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
         ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
         TRIMESTRUT)
      =(SELECT
          TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
          CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
          IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
          TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
          ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
          TRIMESTRUT
        FROM TMP_DPROFIT )
    WHERE CODDPROFIT = RecId;

    DELETE FROM DPROFITV
    WHERE CODDPROFIT = RecID AND CODDPROFITV NOT IN (SELECT CODDPROFITV FROM TMP_DPROFITV);

    FOR v_rec IN (SELECT * FROM TMP_DPROFITV ORDER BY CODDPROFITV) LOOP
      IF nvl(v_rec.CODDPROFITV, 0) &gt; 0 THEN
        UPDATE DPROFITV
        SET 
          CODCONT  = V_REC.CODCONT, 
          RULAJ    = V_REC.RULAJ, 
          VENITURI = V_REC.VENITURI, 
          SUMA     = V_REC.SUMA
        WHERE CODDPROFIT = RecID AND CODDPROFITV = v_rec.CODDPROFITV;
      ELSE
        select SEQ_DPROFITV_CODDPROFITV.nextval INTO vCod from dual;
        INSERT INTO DPROFITV (CODDPROFITV, CODDPROFIT, CODCONT, RULAJ, VENITURI, SUMA)
        VALUES (vCod, RecId, V_REC.CODCONT, V_REC.RULAJ, V_REC.VENITURI, V_REC.SUMA);
      END IF;
    END LOOP;

    DELETE FROM DPROFITC
    WHERE CODDPROFIT = RecID AND CODDPROFITC NOT IN (SELECT CODDPROFITC FROM TMP_DPROFITC);

    FOR v_rec IN (SELECT * FROM TMP_DPROFITC ORDER BY CODDPROFITC) LOOP
      IF nvl(v_rec.CODDPROFITC, 0) &gt; 0 THEN
        UPDATE DPROFITC
        SET 
          CODCONT  = V_REC.CODCONT, 
          RULAJ    = V_REC.RULAJ, 
          CHELTUIELI = V_REC.CHELTUIELI, 
          SUMA     = V_REC.SUMA
        WHERE CODDPROFIT = RecID AND CODDPROFITC = v_rec.CODDPROFITC;
      ELSE
        select SEQ_DPROFITC_CODDPROFITC.nextval INTO vCod from dual;
        INSERT INTO DPROFITC (CODDPROFITC, CODDPROFIT, CODCONT, RULAJ, CHELTUIELI, SUMA)
        VALUES (vCod, RecId, V_REC.CODCONT, V_REC.RULAJ, V_REC.CHELTUIELI, V_REC.SUMA);
      END IF;
    END LOOP;
  ELSE  -- INSERT
    SELECT SEQ_DPROFIT_CODDPROFIT.NextVal INTO RecId FROM DUAL;
    
    aDataCreare := SysDate;
    SELECT
      SUBUNITATEA,
      to_date(to_char(DATACREARE,&apos;DD.MM.YYYY HH24:MI:SS&apos;), &apos;DD.MM.YYYY HH24:MI:SS&apos;),
      &apos;An:&apos;||An||&apos;, Trim:&apos;||Trimestru
    INTO
      aCodSubunit,
      aDataDoc,
      ADOC
    FROM
      TMP_DPROFIT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;DPROFIT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO DPROFIT (CODDPROFIT, TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
                         CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
                         IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
                         TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
                         ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
                         USERID, DATACREARE,TRIMESTRUT)
    SELECT RECID, TIPPROFIT, TIPAN, CODNC, ELEMSIMVENIT, ELEMSIMCHELT, DEDUCERI, DEDREZLEG, DEDPROFITR, DEDALTE,
           CHELTAFVENIT, CHELTPRADM, CHELTPRNEDED, PIERDERE, PROFITCONTA, PROFITIMPOZ, SUMAMAX, CHELTSPONSOR,  
           IMPOZITPROFIT, IMPOZITPROFITD, AN, TRIMESTRU, TOTALRULAJV, TOTALVENITURI, TOTALSUMEV, TOTALRULAJC,   
           TOTALCHELT, TOTALSUMEC, OBS, SUBUNITATEA, AMOFISC, CHELTDOBPREC, PROVFISC, CREDITFISCEXT, IMPPROFREINV,
           ALTESCUTIRI, CIFRAAFACERI, CREDITFISCAL, IMPOZITPROFITC, IMPPROFDIF, ANGENERARE, LUNAGENERARE, SPONSORREPORT,
           PKG_GLOBALS.GETUSERID, aDataCreare,TRIMESTRUT
    FROM TMP_DPROFIT;

    INSERT INTO DPROFITV (CODDPROFITV, CODDPROFIT, CODCONT, RULAJ, VENITURI, SUMA)
    SELECT SEQ_DPROFITV_CODDPROFITV.NEXTVAL, RecId, CODCONT, RULAJ, VENITURI, SUMA FROM TMP_DPROFITV;

    INSERT INTO DPROFITC (CODDPROFITC, CODDPROFIT, CODCONT, RULAJ, CHELTUIELI, SUMA)
    SELECT SEQ_DPROFITC_CODDPROFITC.NEXTVAL, RecId, CODCONT, RULAJ, CHELTUIELI, SUMA FROM TMP_DPROFITC;
  END IF;

  NotifyModif(Operation, RecId, &apos;DPROFIT&apos;);
  COMMIT;
END;  

end PKG_DPROFIT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_DVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB72BE1C974C68D4F3A538C4743CD79B87CFB155</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_DVI IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_41&apos;;


PROCEDURE CHECK_MODICANT_DVILAAVIZ(aCODDVI IN NUMBER)
IS
  DIF NUMBER(20, 7);
  aCANT NUMBER(20, 7);
BEGIN
  FOR V_REC IN
  (
    SELECT
      I.CURS,
      I1.CANT AS CANTDVI,
      IA.CODINTR AS CODAVIZ,
      IA.CODINTR1 AS CODLINIEAVIZ,
      IA.CANT AS CANTAVIZ
    FROM
      INTRARI I,
      INTRARI1 I1,
      INTRLINK IL,
      INTRARI1 IA
    WHERE
      I.CODINTR = aCODDVI
      AND I1.CODINTR = aCODDVI
      AND IL.CODINTR1 = I1.CODINTR1
      AND IL.CODLINIEAVIZ = IA.CODINTR1
      AND I1.CANT &lt;&gt; IA.CANT
  )
  LOOP
    UPDATE INTRARI1
    SET
      CANT = V_REC.CANTDVI
    WHERE
      CODINTR1 = V_REC.CODLINIEAVIZ;

     PKG_Jurnal.setDirtyDVIAE(V_REC.CODLINIEAVIZ, V_REC.CURS);


    UPDATE INTRARI
    SET
      VALDOC = (SELECT SUM(CANT * PU) FROM INTRARI1 WHERE CODINTR = V_REC.CODAVIZ)
    WHERE
      CODINTR = V_REC.CODAVIZ;

    IF V_REC.CANTDVI &gt; V_REC.CANTAVIZ THEN
      UPDATE NIRSTOC
      SET
        CANTFURN = CANTFURN +  V_REC.CANTDVI - V_REC.CANTAVIZ
      WHERE
        CODNIRSTOC = (SELECT MIN(CODNIRSTOC) FROM NIRSTOC WHERE CODINTR1 = V_REC.CODLINIEAVIZ);
    ELSE
      DIF := V_REC.CANTAVIZ - V_REC.CANTDVI;
      FOR V_REC_S IN (SELECT * FROM NIRSTOC WHERE CODINTR1 = V_REC.CODLINIEAVIZ)
      LOOP
         IF V_REC_S.CANTFURN &gt;= DIF THEN
             aCANT := DIF;
         ELSE
            aCANT := V_REC_S.CANTFURN;
         END IF;
         UPDATE NIRSTOC
         SET
           CANTFURN = CANTFURN - aCANT
         WHERE
           CODNIRSTOC = V_REC_S.CODNIRSTOC;

          DIF := DIF - aCANT;
          IF DIF &lt;= 0 THEN
            EXIT;
          END IF;
      END LOOP;
    END IF;
  END LOOP;

END;

PROCEDURE SOLVE_OBINV(aCODINTR IN NUMBER, aCODCLASIF IN NUMBER )
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
BEGIN
  CODCLASIF_MASTER := aCODCLASIF;
  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       PRET,
       REST
      FROM
        NIRSTOC NS,
        NIR N,
        TMP_IOART_LUNA IOLUNA
      WHERE
        N.CODINTR = aCODINTR
        AND NS.CODNIR = N.CODNIR
        AND IOLUNA.CODIOART = NS.CODIOART
        AND IOLUNA.ESTEOBINV &gt; 0
     )
   LOOP
     SELECT NVL(SUM(CANT), 0) INTO REZOLVAT
     FROM MIFIX1 MF
     WHERE MF.CODNIRSTOC = V_REC.CODNIRSTOC
       AND MF.ANSTART * 12 + MF.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


     IF REZOLVAT &lt; V_REC.REST THEN
       BEGIN
         SELECT NVL(CODCLASIF, 0) INTO CODCLASIF_MASTER FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN CODCLASIF_MASTER := 0;
       END;

       IF CODCLASIF_MASTER = 0 THEN CODCLASIF_MASTER := aCODCLASIF;
       END IF;

       BEGIN
         SELECT DURATA INTO aDURATAN FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
       END;


       IF aDURATAN &gt; 0 THEN

         SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         IF NR = 0 THEN
           INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN)
           VALUES (V_REC.CODNIRSTOC, CODCLASIF_MASTER, aDURATAN);
         END IF;

         SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

         INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE )
         VALUES (aCODMIFIX, &apos;OI&apos;, PKG_MIFIX.GetNextNrInv(&apos;OI&apos;), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

         INSERT INTO MIFIX1(CODMIFIX1,
                            CODMIFIX,
                            CODNIRSTOC,
                            PRET,
                            CANT,
                            CODCLASIF,
                            TIPAMO,
                            STARE,
                            DURATAN,
                            GRADU,
                            DURATAF,
                            AMO,
                            DFBLOCAT,
                            ANSTART,
                            LUNASTART,
                            DFBLOCAT_F,
                            DFBLOCAT_G)
         VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
                aCODMIFIX,
                V_REC.CODNIRSTOC,
                V_REC.PRET,
                V_REC.REST - REZOLVAT,
                CODCLASIF_MASTER,
                1,
                1,
                aDURATAN,
                100,
                0,
                (V_REC.REST - REZOLVAT) * V_REC.PRET,
                1,
                PKG_GLOBALS.ANLUCRU,
                PKG_GLOBALS.LUNALUCRU,
                1,
                1);

       END IF;
     END IF;


   END LOOP;
   COMMIT;

END;



PROCEDURE SP_POSTRECORDS_FROM_IMPORT (RECID OUT NUMBER ) IS
  VCOD NUMBER(20);
  TIPINTR INTEGER := 0;
  NR INTEGER := 0;
  AOPERAT INTEGER := 0;
  AANULAT INTEGER := 0;

  OLDCARNETNIR NUMBER(20) := 0;
  OLDNRNIR     NUMBER(20) := 0;
  OLDCARNETLIVR NUMBER(20) := 0;
  OLDNRLIVR     NUMBER(20) := 0;
  ACODSERIE    NUMBER(20) := 0;
  ACODPART     NUMBER(20) := 0;
  NOMSERIE    VARCHAR2(75);


BEGIN
  SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO RECID FROM DUAL;
  SELECT TipDoc into TIPINTR from TMP_INTRARI;

  INSERT INTO  INTRARI
   (CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, CODFISCAL, MONEDA, CURS,userid,datacreare, TIPTRANZACTIE, ExclusPlata, DataTVA, FaraReg, TVAIncasare, CodAnaliza,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, MODTRANSP)
   ( SELECT RECID,  TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, CODFISCAL, MONEDA, CURS, pkg_globals.userid,systimestamp, TIPTRANZACTIE, ExclusPlata, DataTVA, FaraReg, TVAIncasare, CodAnaliza,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, MODTRANSP
     FROM TMP_INTRARI) ;


  UPDATE TMP_GENERAL SET CODDOC = RECID WHERE SEMNIFICATIE IN (100, 110, 140, 111);

-- Detail INTRARI1
  FOR v_rec IN ( SELECT * FROM TMP_INTRARI1 ORDER BY IndexLocal ) LOOP

    SELECT seq_INTRARI1_CodIntr1.Nextval INTO vCOD FROM DUAL;

    INSERT INTO INTRARI1 (
      CodIntr1, CodIntr, IndexLocal,TipLinie,Umsec,An,Luna,ContServ, CONTDISCOUNT, GestAct,CodObiect,
      PretOrig,PU,Cant,TVA, AdDim,
      RestFact,
      NrCertif,COEFDISCMAJ, TG,PUMaximal, PROCADAOS, PURidicata, CODOBLIGSTORNO, CURSFACTURAAVANS,
      CodAnalizaNod, CodCentru, CodNImob)
    VALUES (
      vCod, RecId, v_Rec.IndexLocal,  v_Rec.TipLinie,  v_Rec.Umsec,  v_Rec.An,  v_Rec.Luna,  v_Rec.ContServ, V_REC.CONTDISCOUNT, v_Rec.GestAct,  v_Rec.CodObiect,
      v_Rec.PretOrig / NVL(v_Rec.Paritate, 1), v_Rec.PU / NVL(v_Rec.Paritate, 1),  v_Rec.Cant * NVL(v_Rec.Paritate, 1), v_Rec.TVA, v_rec.AdDim,
      CASE
        WHEN TIPINTR = 2 AND v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND aOperat = 1 AND aAnulat = 0 THEN v_Rec.Cant * v_Rec.Paritate
        WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
        ELSE 0
      END,
      v_Rec.NrCertif, V_REC.COEFDISCMAJ,  v_Rec.TG,  v_Rec.PUMaximal, V_REC.PROCADAOS, v_Rec.PURidicata, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS,
      v_Rec.codanalizanod, v_rec.codcentru, v_rec.CodNImob
    );

    UPDATE TMP_DVI1     SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CodIntr1;
    UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_INTRARI1 SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CodIntr1;

  END LOOP;



-- detail DVI
 FOR V_REC IN (SELECT * FROM TMP_DVI) LOOP
   SELECT SEQ_DVI_CODDVI.NEXTVAL INTO VCOD FROM DUAL;
   UPDATE TMP_DVI1 SET CODDVI = VCOD;
   UPDATE TMP_GENERAL SET CODDOC = VCOD WHERE SEMNIFICATIE = 130;

   INSERT INTO DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE,
   FISAVAMA, TAXEPECHELT, TipRepSuplim, ValSuplim, ContSuplim, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA, ExclusPlata, FaraReg, TVAIncasare )
   VALUES
   (VCOD, RECID, V_REC.CODVAMA, V_REC.NRDOC, V_REC.DATADOC, V_REC.CONTCHELT, V_REC.CONTTVA, V_REC.TAXEINCLUSE,
    V_REC.FISAVAMA, V_REC.TAXEPECHELT, V_REC.TipRepSuplim, V_REC.ValSuplim, V_REC.ContSuplim, V_REC.OBS, V_REC.TIPIMPORT, V_REC.VALDOCVAMA, V_REC.TVADOCVAMA, v_rec.ExclusPlata, V_REC.FaraReg, v_rec.TVAIncasare);
 END LOOP;

-- detail DVI1
 FOR V_REC IN (SELECT * FROM TMP_DVI1 ORDER BY INDEXLOCAL) LOOP
   SELECT SEQ_DVI1_CODDVI1.NEXTVAL INTO VCOD FROM DUAL;
   update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.coddvi1;
   UPDATE TMP_NIRSTOC SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
   UPDATE TMP_LIVR1   SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
   UPDATE TMP_DVI1    SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;

   INSERT INTO DVI1(CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, VALOARETAXA)
   VALUES (VCOD, V_REC.CODDVI, V_REC.CODINTR1, V_REC.TIPLINIE, V_REC.INDEXLOCAL,
           V_REC.PRETIMPORT / NVL(V_REC.PARITATE, 1),
           V_REC.PUMAXIMAL / NVL(V_REC.PARITATE, 1),
           V_REC.CONTDISCOUNT,
           V_REC.PRETVALUTA / NVL(V_REC.PARITATE, 1),
           V_REC.PRETORIGINAL,
           V_REC.TVA,
           V_REC.UMSEC,
           V_REC.ADDIM,
           V_REC.CODOBIECT,
           V_REC.CANT * NVL(V_REC.PARITATE, 1),
           CASE
             WHEN V_REC.TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) THEN V_REC.VALOARE
             ELSE 0
           END
   );
 END LOOP;



-- Detail GENERAL -- MUSAI DUPA DVI PENTRU CA CODDOC = CODDVI LA INREGISTRARI CU SEMNIFICATIE = 130
   FOR V_REC IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;

     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS,  TVA, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg)
     VALUES (VCOD, TIPINTR, V_REC.CODDOC, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS,  v_rec.TVA, V_REC.PROCTVAAVANS, v_rec.ExclusPlata, v_rec.DataTVA, V_REC.FaraReg);

   END LOOP;

-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
     UPDATE TMP_INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODANALIZANOD)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 111 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA, V_REC.CODCENTRU, V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0),
    v_rec.codanalizanod );
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;




 INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT )(SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);

-- Detail NIR
  FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP
    SELECT seq_NIR_CodNIR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO NIR (CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest, v_rec.Obs, v_rec.TipNIR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_NIRSTOC SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
    UPDATE TMP_NIR     SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
  END LOOP;


-- Detail NIRSTOC
  FOR v_rec IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CodNIRSTOC ) LOOP
    IF V_REC.CODNIRSTOC &lt; 0 THEN
      SELECT seq_NIRSTOC_CodNirStoc.Nextval INTO vCod from DUAL;
    ELSE
      VCOD := V_REC.CODNIRSTOC;
    END IF;


    INSERT INTO NIRSTOC( CodNirStoc, CodNir, CodIntr1, CODDVI1, CantNir, CANTFURN, Umsec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE, Adaos, TVA, TipSerie, CodLivr1, Rest, ProcentAdaos,
    SUPLIMENT, SuplNeded,
    TG,
    PUMAXIMAL,
    FURN,
    DATAACHIZ,
    TIPDOCACHIZ,
    DISCLIKISTOC,
    SERIELOT,
    PUVAL )
    VALUES
    (vCOD, v_rec.CodNir, v_rec.CodIntr1, v_rec.CODDVI1, v_rec.CantNir * v_rec.Paritate, v_rec.CANTFURN * v_rec.Paritate, v_Rec.UmSec,  v_rec.CodObiect,  nvl(v_rec.CodIoArt, 0),  v_rec.Pret / v_rec.Paritate,  v_rec.Rotlei, v_REC.ROTVALUTA, V_REC.CODLOCATIE, v_rec.Adaos/ v_rec.Paritate,  v_rec.TVA,
     v_rec.TipSerie,  v_rec.CodLivr1, PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
     v_rec.ProcentAdaos, v_rec.Supliment, v_rec.SuplNeded,
     (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
     (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
      aCODPART,
     (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR),
      5,
      V_REC.DISCLIKISTOC,
      V_REC.SERIELOT,
      V_REC.PUVAL);

/*
    INSERT INTO  NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CODDVI1, CantNir, CANTFURN, UmSec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE,Adaos, TVA, TipSerie, CodLivr1, Rest, ProcentAdaos, SUPLIMENT,
    TG, PUMAXIMAL)
    VALUES
    (vCod, v_Rec.CodNir, v_Rec.CodIntr1, V_REC.CODDVI1, v_Rec.CantNir * v_Rec.Paritate,  v_Rec.CANTFURN * v_Rec.Paritate, v_Rec.Umsec, v_Rec.CodObiect, nvl(v_Rec.CodIoArt, 0), v_Rec.Pret / v_Rec.Paritate, v_Rec.RotLei, v_rec.ROTVALUTA, V_REC.CODLOCATIE, v_Rec.Adaos, v_Rec.TVA, v_Rec.TipSerie, v_Rec.CodLivr1,

      PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
      v_Rec.ProcentAdaos, V_REC.SUPLIMENT,
     (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
     (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1))
      );
*/
    UPDATE TMP_NIR1 SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;


  END LOOP;
-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;


    IF V_REC.CODNIRSER &lt; 0 THEN  SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;
    ELSE
    VCOD := V_REC.CODNIRSER;
    END IF;

    INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2, 
                                               RESTUM1, RESTUM2, OBS, CodCertif, DATAPROD, STARE, TG, DATAPROD1, TG1) VALUES
    (VCOD, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2,  
                                               V_REC.CANTUM1, V_REC.CANTUM2, V_REC.OBS, V_REC.CodCertif, V_REC.DATAPROD, V_REC.STARE, V_REC.TG, V_REC.DATAPROD1, V_REC.TG1);
  END LOOP;

-- LIVR
  FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP
    SELECT seq_LIVR_CodLIVR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO LIVR (CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLIVR, Obs, TipLIVR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR, v_rec.DataLivr, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_LIVR1 SET CODLIVR = vCod WHERE CODLIVR = v_rec.CODLIVR;
  END LOOP;

-- LIVR1
   INSERT INTO LIVR1
   (CodLivr1, CodLivr, CodIes1, CodIntr1, CODDVI1, CodNirStoc, Cant, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec)
   (SELECT  seq_LIVR1_CodLivr1.Nextval, CodLivr, CodIes1, CodIntr1, CODDVI1, CodNirStoc,  Cant * Paritate, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec from TMP_LIVR1);


-- actualizez stocurile din care livrez

   UPDATE NIRSTOC NS SET REST = PKG_INTRARI.GET_REST_STOC(NS.CodNir, NS.CodNirStoc, NS.CantNIR)
   WHERE
   NS.CodNirStoc in (SELECT CodNirStoc FROM TMP_LIVR1);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
     NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1);


  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD FROM TMP_JURNAL1);



  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);




UPDATE COMANDA1 c1
SET
 c1.RestAcceptat = c1.CantAcceptat -
             ( SELECT NVL(SUM(IL.CANT), 0)
               FROM
                INTRLINK IL
                LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
               WHERE
               IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
               )
WHERE
c1.CodComanda1 IN (SELECT CODLINIECOMANDA FROM TMP_INTRLINK UNION SELECT CODLINIECOMANDA  FROM TMP_INTRLINK_INITIAL);



FOR V_REC IN (SELECT * FROM LIVR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;


FOR V_REC IN (SELECT * FROM NIR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
END LOOP;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 END LOOP;



-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
  UPDATE OBLIGPIF O
  SET
   REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE

     UNION ALL

     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );


COMMIT;



END;


FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;

FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF; 
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0); 
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;


FUNCTION TOTAL_COUNT_SEMNIF_VAMA(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGVAMA_INITIAL WHERE SEMNIFICATIE = aSEMNIF; 
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;



FUNCTION TOTAL_COUNT_ICONT_VAMA(aICONT IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGVAMA_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;


FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT VALOARE INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;


FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;


FUNCTION TOTAL_VALOARE_ICONT_VAMA(aICONT IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT VALOARE INTO TOTAL FROM TMP_OBLIGVAMA_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;

FUNCTION TOTAL_VALOARE_SEMNIF_VAMA(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGVAMA_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_INTRARI FIELDS( CODINTR ) VALUES (0) ;
  -- mIntraridinImport --&gt; 5
  PKG_CFGTABLES.EXT_INSERTRECORD(5);  
  COMMIT;
END;


PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
TMP NUMBER(20);
BEGIN
  SELECT CODINTR INTO TMP FROM INTRARI WHERE CODINTR = RECID FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
 TIPINTR NUMBER(20);
 aTIPFACTURA NUMBER(20) := 0;
 aCodSubunit     NUMBER(20);
 aDataDoc        DATE;
 aDoc            VARCHAR2(200);
 TotSosit        number(20,7);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  -- mIntraridinImport --&gt; 5
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 5);
	SELECT TIPDOC, TIPFACTURA, SUBUNITATEA,  datadoc, prefixdoc||nrdoc||&apos;/&apos;||datadoc
  INTO TIPINTR, aTIPFACTURA,aCodSubunit,aDataDoc,aDoc
  FROM INTRARI WHERE CODINTR = RECID;

  DELETE FROM TAXDECL WHERE TipDoc = TIPINTR and CODDOC = RECID;
  DELETE FROM DetaliiET1 et1 
              where et1.coddetaliuet in (select et.coddetaliu 
                                           from detaliiet et  
                                           WHERE et.TipDoc = TIPINTR and et.CODDOC = RECID);
  DELETE FROM DetaliiET  WHERE TipDoc = TIPINTR and CODDOC = RECID;
  DELETE FROM STATUSDECL WHERE TipDoc = 100+TIPINTR and CODDOC = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    --WINMADMIN.PKG_USERFIRME.PostLog(&apos;DVI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
-- MEMOREZ LIVRARILE CARE VOR FI STERSE

  /*DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CodUnic)
  SELECT codnirstoc FROM NIRSTOC WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID);
  for v_rec in (select * from tmp_manevra) loop
    insert into tmp_manevra(codunic)
    select ns11.codnirstoc
    from nirstoc1 ns1
         inner join nirstoc1 ns11 on ns1.codcomanda1 = ns11.codcomanda1
    where ns1.codcomanda1 &gt; 0 and ns1.codnirstoc = v_rec.codunic;
  end loop;
  pkg_pretprod.SetDirtyStructura;*/

  FOR V_NS IN
    (
     SELECT
       IL.CODLINIECOMANDA CODCOMANDA1F,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NUM1.PARITATE
     FROM
       NIRSTOC NS
       INNER JOIN NUM1 on ns.umsec = NUM1.CODUM1
       LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRLINK IL
       INNER JOIN DVI1 ON IL.CODINTR1 = DVI1.CODINTR1
     WHERE
       DVI1.CODDVI1 = NS.CODDVI1
       and ns.CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID)
       )
  loop
       TotSosit := V_NS.CantNIR;
       if TotSosit &lt;&gt; 0 then
         for v_Rez in ( select CodRezervatS, CodComanda1, CodObiect, UMSec, REZERVATINI Folosit  from  RezervatS
                        where CODCOMANDA1F = v_NS.CODCOMANDA1F
                              AND CodNIRStoc = V_NS.CodNIRStoc
                              AND CodNIRSer  = V_NS.CodNIRSer
                        order By CodComanda1 asc)
         loop
           if TotSosit &lt;&gt; 0 then
             if TotSosit &lt; v_REZ.Folosit then
               update REZERVATS set Rest = Rest + TotSosit
                                where CODCOMANDA1F    = v_NS.CODCOMANDA1F
                                      AND CodObiect   = v_REZ.CodObiect
                                      AND CodComanda1 = v_REZ.CodComanda1
                                      AND CodNIRStoc  = 0;
               TotSosit := 0;
             else
               TotSosit := TotSosit - v_REZ.Folosit ;
               update REZERVATS set Rest = Rest + v_REZ.Folosit
                                where CODCOMANDA1F    = v_NS.CODCOMANDA1F
                                      AND CodObiect   = v_REZ.CodObiect
                                      AND CodComanda1 = v_REZ.CodComanda1
                                      AND CodNIRStoc  = 0;
             end if;
           end if;
         end loop;
       end if;
  end loop;

  FOR V_REC IN
  (
    SELECT CODNIRSER FROM NIRSER WHERE
    CODNIRSTOC IN ( SELECT CODNIRSTOC FROM NIRSTOC
                    WHERE CODNIR IN ( SELECT CODNIR FROM NIR
                                      WHERE CODINTR = RECID))
   )
  LOOP
    DELETE FROM REZERVATS WHERE CODNIRSER = V_REC.CODNIRSER AND NVL(CODCOMANDA1F,0) &gt; 0;
  END LOOP;

  FOR V_REC IN
  (
    SELECT CODNIRSTOC FROM NIRSTOC WHERE
    CODNIR IN ( SELECT CODNIR FROM NIR
                WHERE CODINTR = RECID)
  )
  LOOP
    DELETE FROM REZERVATS WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND NVL(CODCOMANDA1F,0) &gt; 0;
  end loop;

  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CODUNIC)
  (SELECT CODNIRSTOC FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID));

  -- MEMOREZ CODURILE DE COMENZI FURNIZORI STINSE DE INTRLINK-URILE CARE VOR FI STERSE
   DELETE TMP_COMANDA1;
   INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
   ( SELECT CODLINIECOMANDA FROM INTRLINK IL WHERE IL.CODINTR1 IN
    (SELECT I1.CODINTR1 FROM INTRARI1 I1 WHERE CODINTR=RECID AND I1.CODINTR1 = IL.CODINTR1)
   );



  DELETE TMP_LIVR1;

  INSERT INTO TMP_LIVR1(CODLIVR1)
  SELECT CODLIVR1 FROM LIVR1 L1
  WHERE
   CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID);


  DELETE FROM LIVRVAL  WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM LIVR1 L1 WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);



-- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
  FOR V_REC IN (SELECT * FROM LIVR WHERE  CODINTR = RECID)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
  END LOOP;

  DELETE FROM LIVR     WHERE CODINTR = RECID ;


  DELETE FROM NIR1
  WHERE
  CODNIRSTOC IN
  (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID)
  ) ;

  DELETE FROM NIRSER
  WHERE
  CODNIRSTOC IN
  (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID)
  ) ;



  DELETE FROM NIRSERLUNA
  WHERE
  CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID));

  DELETE FROM NIRLUNA
  WHERE
  CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID));


  -- LA STERGERE DIN NIRSTOC STERG SI MIJLOACE FIXE
/*
  DELETE TMP_MIFIX;
  FOR V_REC IN (SELECT * FROM NIRSTOC  WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID))
  LOOP
    FOR V_REC_MF IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC)
    LOOP
      INSERT INTO TMP_MIFIX (CODMIFIX) VALUES (V_REC_MF.CODMIFIX);
      DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC_MF.CODMIFIX1;
    END LOOP;
    DELETE FROM MIFIX WHERE CODMIFIX IN (SELECT CODMIFIX FROM TMP_MIFIX);


    DELETE FROM MASTERMIFIX  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;
*/


  delete from nirstoc1 where codnirstoc IN (SELECT CODNIRSTOC FROM NIRSTOC  WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID));
  DELETE FROM NIRSTOC  WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID) ;

  DELETE FROM DVI1     WHERE CODDVI IN (SELECT CODDVI FROM DVI WHERE CODINTR = RECID) ;


-- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
  FOR V_REC IN (SELECT * FROM NIR WHERE  CODINTR = RECID)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
  END LOOP;

  DELETE FROM NIR      WHERE CODINTR = RECID ;


  DELETE TMP_INTRLINK;
  IF aTIPFACTURA = 10 THEN
    INSERT INTO TMP_INTRLINK (CODLINIEAVIZ)
    SELECT CODLINIEAVIZ FROM INTRLINK WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = RECID);
  END IF;

  DELETE FROM INTRLINK WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = RECID);



  FOR V_REC IN (SELECT * FROM INTRARI1 WHERE CODINTR = RECID)
  LOOP
     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1)
     LOOP
       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC = 52) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;


          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
              RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;


         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
              RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;


       END LOOP;



       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1;

     DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1 ;


  END LOOP;

  IF aTIPFACTURA = 10 THEN
      UPDATE INTRARI1 I1
      SET
       I1.RestFact = i1.Cant -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIEAVIZ = I1.CodINTR1
                   AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10))
                   AND II.OPERAT = 1
                   AND II.ANULAT = 0
                 ) +
                 (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                  FROM
                    INTRARI1 AE1,
                    INTRARI  AE
                  WHERE
                    AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                   AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0)
      WHERE
       I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND I1.CODINTR1 IN (SELECT CODLINIEAVIZ FROM TMP_INTRLINK);
  END IF;


  -- ObligPIF + GENERAL + STINGERE -- MUSAI INAINTE DE DVI
  DELETE TMP_OBLIGPIF;

  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF, CODGENERAL)
  (SELECT CODOBLIGPIF, CODGENERAL FROM OBLIGPIF WHERE CODGENERAL IN
    (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR AND SEMNIFICATIE IN (100, 110, 111, 140))
   );

  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF, CODGENERAL)
  (SELECT CODOBLIGPIF, CODGENERAL FROM OBLIGPIF WHERE
    CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE CODDOC IN (SELECT CODDVI FROM DVI WHERE CODINTR = RECID) AND TIPDOC = TIPINTR AND SEMNIFICATIE = 130)
    );



  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF)
  SELECT CODSTINGERE, CODSTINSPIF FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

-- ordinea de stergere trebuie pastrata pentru a nu viola un constraint
  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);

  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);


  FOR V_REC IN
  (SELECT CODGENERAL FROM GENERAL G
   WHERE
    EXISTS (SELECT CODGENERAL FROM TMP_OBLIGPIF WHERE CODGENERAL = G.CODGENERAL)
   )
   LOOP
      DELETE FROM GENERAL
      WHERE
       CODGENERAL = V_REC.CODGENERAL;

       FOR V_RECREG IN
       (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
       LOOP
         UPDATE JURNAL1
         SET
           DIRTY = 1
         WHERE
           TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
       END LOOP;
   END LOOP;

/*
  DELETE FROM GENERAL
  WHERE
  CODGENERAL IN (SELECT CODGENERAL FROM TMP_OBLIGPIF) ;
*/

 UPDATE OBLIGPIF O
  SET
    REST =
      (CASE
         WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END)
  WHERE
    O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);




  DELETE FROM DVI      WHERE CODINTR = RECID ;

  DELETE FROM INTRARI  WHERE CODINTR = RECID ;

  -- REALOC IN DOCFREE NUMARUL DE DOCUMENT STERS
/*
  PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
*/


-- REACTUALIZEZ STOCURILE IMPLICATE IN STERGEREA INTRARILOR IN ROSU
  UPDATE NIRSTOC NS SET REST = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR)
  WHERE NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);

  UPDATE NIRSER NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM2)
  WHERE
  NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);


 --  AM STERS FACTURI CARE STING COMENZI; REACTUALIZEZ RESTUL PE COMENZI
    UPDATE COMANDA1 C1
    SET
     C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
    C1.CODCOMANDA1 IN
    (SELECT CODCOMANDA1 FROM TMP_COMANDA1);


   FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = TIPINTR;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = TIPINTR;

  DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPINTR);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPINTR;

  NotifyModif(2, RecId, &apos;INTRARI&apos;);
  COMMIT;
END;



PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
	TIPINTR      NUMBER(18);
	aTIPFACTURA NUMBER(20) := 0;
	VALOBLIGFURN NUMBER (20, 7);
	VALOBLIGVAMA NUMBER (20, 7);
	aDATAINVOICE DATE;
	aDATADOCVAMA DATE;
	LUNAREF      PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
	IOPART1REC   IOPART1 % ROWTYPE;
	ACODPART     NUMBER(20, 0) := 0;
	ACODVAMA     NUMBER(20, 0) := 0;
	TIPPREFIX    VARCHAR2(10);
	aZileTVAINCASARE INTEGER := 0;
	aDATADOC DATE;
	ADATAREF DATE;
BEGIN
  -- MASTER INTRARI

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA; -- :1:2:3:4 nu stiu cine-a pus asta si pentru ce i-a trebuit :5:6:7
  DELETE TMP_MANEVRA;
  INSERT INTO  TMP_INTRARI

    (CODINTR,   TIPDOC, ANULAT, BLOCAT,  OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ,
     CARNETDOC, VALDOC, TVADOC, MAJORARI, AN,    LUNA,      OBS,   SATELIT, COMPLEX, ProRata, CODCONTRACT, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, CODFISCAL, MONEDA, CURS, TIPTRANZACTIE, NRI, ExclusPlata, DataTVA, FaraReg, TVAIncasare, TIPFACTURA, UserID, CodAnaliza, STADIUWMS,
     PARTCOMUNITAR,
     SIMBAUTOTARA,
     DATAREFSCAD, SCADENTESETATEMANUAL, CODLOCATIE,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, UIT,
     ET_IDINCARCARE, ET_IDDESCARCARE, ET_TIPMEDIU, ET_STATUS,   
     is_etransp, MODTRANSP,
     DELEGAT,
     NUMEDELEGAT,
     CODAUTO,NRTRANSP)
    (SELECT
     CODINTR,   I.TIPDOC, ANULAT, BLOCAT,  OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ,
     CARNETDOC, VALDOC, TVADOC, MAJORARI, I.AN,    I.LUNA,      I.OBS,   SATELIT, COMPLEX, ProRata, CODCONTRACT, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, I.CODFISCAL, MONEDA, CURS, TIPTRANZACTIE, NRI, ExclusPlata, DataTVA, FaraReg, TVAIncasare, TIPFACTURA , UserID, CodAnaliza, STADIUWMS,
     T.STATCOMUNITAR,
     T.SIMBAUTO,
     NVL(DATAREFSCAD,DATADOC), 1, CODLOCATIE,TIPLIVRARE, NATURATRANZ, Coalesce(TipSAFT, 0), Coalesce(TipET,0), UIT, 
     ET.IDINCARCARE, ET.IDDESCARCARE, ET.TIPMEDIU, Coalesce(ET.STARE,&apos;?&apos;), 
     is_etransp, MODTRANSP,
     I.DELEGAT,
     COALESCE((SELECT DELEGAT FROM NPARTTR WHERE CODPARTTR = I.DELEGAT), &apos;&apos;),
     I.CODAUTO,I.NRTRANSP
     FROM INTRARI I
  	 LEFT OUTER JOIN NAGENDA  A ON A.CODAGENDA  = I.CODLOCATIE
		 LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
		 LEFT OUTER JOIN NTARI    T ON T.CODTARA    = L.CODTARA
		 LEFT OUTER JOIN StatusDecl ET ON ET.CodDoc = I.CodIntr and ET.TipDoc = 100+I.TipDoc
		 WHERE CODINTR = RECID ) ;

  BEGIN
    SELECT DATADOC INTO aDATAINVOICE FROM TMP_INTRARI;
    EXCEPTION WHEN OTHERS THEN aDATAINVOICE := TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;);
  END;


   IF RECID &gt; 0 THEN
     BEGIN
       SELECT  PARTENER, CURS, DATAREFSCAD INTO aCODPART, CURS_IN, ADATAREF FROM TMP_INTRARI;
       EXCEPTION WHEN OTHERS THEN aCODPART := 0;
     END;
   END IF;

  INSERT INTO TMP_DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TipRepSuplim, ValSuplim, ContSuplim, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA, ExclusPlata, FaraReg, TVAIncasare, SERIADOC)
  SELECT CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TipRepSuplim, ValSuplim, ContSuplim, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA, ExclusPlata, FaraReg, TVAIncasare, SERIADOC
  FROM DVI WHERE CODINTR = RECID;

  BEGIN
    SELECT DATADOC INTO aDATADOCVAMA FROM TMP_DVI;
    EXCEPTION WHEN OTHERS THEN aDATADOCVAMA := TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;);
  END;


   IF RECID &gt; 0 THEN
     BEGIN
       SELECT  CODVAMA INTO aCODVAMA FROM TMP_DVI;
       EXCEPTION WHEN OTHERS THEN aCODVAMA := 0;
     END;
   END IF;

  DELETE INTRARI1_MAN;
  INSERT INTO INTRARI1_MAN (SELECT * FROM INTRARI1 WHERE CODINTR = RECID);

  INSERT INTO  TMP_INTRARI1 (
    CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA,
    CONTSERV, CONTDISCOUNT, GESTACT, CODOBIECT, PRETORIG, PU,
    CANT, TVA, ADDIM,
    RESTFACT, NRCERTIF, COEFDISCMAJ, TG, PUMAXIMAL, PURIDICATA, PROCADAOS, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS,
    DENUM,
    VALOARE,
    PARITATE,
    PROCTVA,
    GESTIMPLICITA, CERTIFICAT, ARETG, CODTVA, CODACCIZE, CODACCIZEDVI, CODTAXA1, CODTAXA2, TIPPRETMAX, DENOBIECT, CODMIFIX,
    CODCENTRU, OBS, CODANALIZANOD, CODEXTERN, CODINTERN, PRELUAT, CODNIMOB, CMDINT, CODCMDINT1, GESTPRODAVIZSUB, CODAUTO, CODVAMAL, TAXCODE)
  SELECT
    I1.CODINTR1, I1.CODINTR, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.AN, I1.LUNA,
    I1.CONTSERV, I1.CONTDISCOUNT, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG * NVL(U1.PARITATE, 1), I1.PU * NVL(U1.PARITATE, 1),
    I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.ADDIM,
    I1.RESTFACT, I1.NRCERTIF, I1.COEFDISCMAJ,  I1.TG, I1.PUMAXIMAL, I1.PURIDICATA, I1.PROCADAOS, I1.FURNAVIZSUBUNIT,  I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
    CASE
      WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
      ELSE U1.DEN_UM1
    END,
    CASE
      WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
      ELSE I1.RESTFACT
    END,
    U1.PARITATE,
    CASE
      WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
      ELSE 0
    END,
    A.GESTIMPLICITA, A.CERTIFICAT, A.ARETG, NART1LUNA.CODTVA,
    NART1LUNA.CODACCIZE,
    NART1LUNA.CODACCIZEDVI,
		NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, NARTOBJ1LUNA.TIPPRETMAX, O.DENUMIRE, I1.CODMIFIX,
    I1.CODCENTRU, I1.OBS, I1.Codanalizanod, O.CODEXTERN, O.CODINTERN, I1.PRELUAT, I1.CODNIMOB,
		c.nrdoc, I1.CODCMDINT1, I1.GESTPRODAVIZSUB, I1.CODAUTO, O.Codvamal, X.TAXCODE
  FROM INTRARI1_MAN I1
    LEFT JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
    LEFT JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
    LEFT JOIN comanda1 c1 ON i1.codcmdint1 = c1.codcomanda1
    LEFT JOIN comanda   c ON c1.codcomanda = c.codcomanda
    LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
    LEFT JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
    LEFT JOIN TMP_NARTOBJ_LUNA  NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
		LEFT JOIN TAXDECL X ON X.TipDoc = 5 and X.CODDOC = RecID and X.Coddoc1 = I1.CodIntr1
  WHERE I1.CODINTR = RECID
  ORDER BY I1.INDEXLOCAL;



    UPDATE TMP_INTRARI1 I1
      SET
      NRDOCLINK =
      CASE
        WHEN NVL(CODOBLIGSTORNO, 0) = 0  THEN &apos;Avans &apos;
        WHEN NVL(CODOBLIGSTORNO, 0) &lt;&gt; 0 THEN &apos;Storno &apos; ||
          NVL((
            SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; ||  TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
            FROM
            TMP_STINGERE S,
            OBLIGPIF O,
            GENERAL G,
            INTRARI I
            WHERE
            S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND
            S.CODSTINSPIF     =  O.CODOBLIGPIF AND
            G.CODGENERAL = O.CODGENERAL AND
            I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC), &apos;&apos;)
      END
    WHERE
    TIPLINIE = &apos;V&apos;;


   INSERT INTO TMP_DVI1
   (CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA,
	 TVANEDED, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, PARITATE, PROCTVA, VALOARE, DENUM, GESTIMPLICITA, CODANALIZANOD,
    CODINTERN,CODEXTERN)
   SELECT
   D1.CODDVI1, D1.CODDVI, D1.CODINTR1, D1.TIPLINIE, D1.INDEXLOCAL, D1.PRETIMPORT * NVL(U1.PARITATE, 1), D1.PUMAXIMAL * NVL(U1.PARITATE, 1), D1.CONTDISCOUNT, D1.PRETVALUTA * NVL(U1.PARITATE, 1),
	 D1.TVANEDED, D1.PRETORIGINAL, D1.TVA, D1.UMSEC, D1.ADDIM,
   D1.CODOBIECT,
   D1.CANT/ NVL(U1.PARITATE, 1),
   U1.PARITATE,
   CASE
     WHEN D1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(D1.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
     ELSE 0
   END,

   CASE
     WHEN D1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PRETIMPORT * D1.CANT
     ELSE VALOARETAXA
   END,
   CASE
     WHEN D1.TIPLINIE IN (&apos;A&apos;, &apos;X&apos;, &apos;C&apos;) THEN &apos;%&apos;
     ELSE U1.DEN_UM1
   END,
   CASE
     WHEN D1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN (SELECT GESTIMPLICITA FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(D1.CODOBIECT))
     ELSE 0
   END,
   I1.CODANALIZANOD,
   OBJ.CODINTERN,OBJ.CODEXTERN
   FROM
     DVI1 D1
     LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1 = D1.UMSEC
     LEFT OUTER JOIN INTRARI1 I1 ON D1.CODINTR1 = I1.CODINTR1
     LEFT OUTER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = D1.CODOBIECT
   WHERE
   CODDVI IN (SELECT CODDVI FROM TMP_DVI)
   ORDER BY INDEXLOCAL ;

   UPDATE TMP_INTRARI1
   SET
     DENOBIECT = CASE
                   WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) = 0 AND CANT &lt;= 0 THEN &apos;Discount distribuit pe grupul de articole precedent&apos;
                   WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) = 0 AND CANT  &gt; 0 THEN &apos;Majorare distribuita pe grupul de articole precedent&apos;

                   WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount direct pe cont (de grup)&apos;
                   WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de grup)&apos;

                   WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) = 0  AND CANT &lt;= 0 THEN &apos;Discount distribuit pe toate articolele precedente&apos;
                   WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) = 0  AND CANT  &gt; 0 THEN &apos;Majorare distribuita pe toate articolele precedente&apos;


                   WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount direct pe cont (de total)&apos;
                   WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de total)&apos;
                 END,
     NRDOCLINK = CASE
                   WHEN NVL(CONTDISCOUNT, 0) &lt;&gt; 0 THEN PKG_PLANCONTURI.GETSIMBOLCONT(NVL(CONTDISCOUNT, 0))
                   ELSE &apos;&apos;
                 END
   WHERE
     TIPLINIE IN (&apos;G&apos;, &apos;T&apos;);



   UPDATE TMP_INTRARI1 I1
   SET
     SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;,
     ESTEIMBMF      = (SELECT PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(I1.CONTSERV) FROM DUAL),
     INFOMF         = CASE
                        WHEN NVL(I1.CODMIFIX, 0) &lt;&gt; 0 THEN
                          (SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE FROM
                            MIFIX MF,
                            MIFIX1 MF1,
                            NIRSTOC NS,
                            NARTOBJ O
                           WHERE
                             MF.CODMIFIX = I1.CODMIFIX
                             AND MF.CODMIFIX = MF1.CODMIFIX
                             AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                             AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                             AND O.CODOBIECT = NS.CODOBIECT)
                         WHEN NVL(I1.CODOBIECTORIG, 0) &lt;&gt; 0 THEN (SELECT DENUMIRE FROM NARTOBJ WHERE CODOBIECT = I1.CODOBIECTORIG)
                         ELSE NULL
                       END

   WHERE
     UPPER(TIPLINIE) IN (&apos;S&apos;, &apos;V&apos;);


  IF RECID &gt; 0 THEN
    SELECT TIPDOC, TIPFACTURA INTO TIPINTR, aTIPFACTURA FROM TMP_INTRARI;


   IF aTIPFACTURA = 10 THEN

       UPDATE TMP_INTRARI1 I1
       SET NRDOCLINK = (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
                        FROM
                          INTRLINK IL
                          LEFT OUTER JOIN INTRARI1 II1 ON II1.CodINTR1 = IL.CODLINIEAVIZ
                          LEFT OUTER JOIN INTRARI  II ON II.CodINTR    = II1.CODINTR
                        WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND IL.CODINTR1 = I1.CODINTR1
                        );


   ELSE
     -- LINII CE STING COMENZI
      UPDATE TMP_INTRARI1 I1
      SET NRDOCLINK =( SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                      FROM
                        INTRLINK IL
                        LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = IL.CODLINIECOMANDA
                        LEFT OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
                      WHERE IL.CODINTR1 = I1.CODINTR1)
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
     END IF;

  END IF;




  UPDATE TMP_DVI1 D1
  SET
    DENOBIECT  = CASE
                   WHEN TIPLINIE = &apos;X&apos; THEN &apos;Taxa vamala&apos;
                   WHEN TIPLINIE = &apos;A&apos; THEN &apos;Accize in vama&apos;
                   WHEN TIPLINIE = &apos;C&apos; THEN &apos;Comision vamal&apos;
                   ELSE NVL((SELECT DENOBIECT FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), &apos;&apos;)
                  END,
    TG         = (SELECT TG FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = D1.CODINTR1),
    INFOSUPLIM = CASE
                   WHEN TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) AND CONTDISCOUNT &lt;&gt; 0 THEN PKG_PLANCONTURI.GETSIMBOLCONT(CONTDISCOUNT)
                 END,
   PROCADAOS   = NVL((SELECT PROCADAOS FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), 0),
   (MASA, VOLUM) =  (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = D1.CODOBIECT),
   (CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODACCIZEDVI, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO ) =
   (SELECT CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODACCIZEDVI, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = D1.CODINTR1);

 -- GENERAL
 INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg)
 (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg FROM GENERAL WHERE CODDOC = RECID AND TIPDOC = TIPINTR AND SEMNIFICATIE &lt;&gt; 130); -- OBLIGATIILE FATA DE FURNIZOR + AVANS

 INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ExclusPlata, DataTVA, FaraReg)
 (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ExclusPlata, DataTVA, FaraReg FROM GENERAL WHERE TIPDOC = TIPINTR AND CODDOC IN (SELECT CODDVI FROM TMP_DVI) AND SEMNIFICATIE = 130); -- OBLIGATIILE FATA DE VAMA


-- PREIAU DIN TMP_GENERAL MONEDA SI CURSUL
  UPDATE TMP_INTRARI I
  SET
    SCADENTAC = NVL((SELECT SCADENTAC FROM NPART WHERE CODPART = I.PARTENER), 0);


-- OBLIGPIF
 INSERT INTO TMP_OBLIGPIF
 (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODANALIZANOD, ZILE)
 (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP, 
     CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODANALIZANOD, TRUNC(TERMEN - aDATAREF) 
 FROM 
   OBLIGPIF 
 WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));



-- PUN PROCENTE IN OBLIGPIF -- versiune cu totalizare pe ICONT
/*
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, ICONT, VALOARE)
  SELECT COUNT(*), ICONT, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (100, 110, 140) GROUP BY ICONT  ;

  UPDATE TMP_OBLIGPIF O
  SET
    ZILE  = TRUNC(TERMEN - aDATAREF),
    PROCENT =
     (
       CASE
         WHEN TOTAL_VALOARE_ICONT(O.ICONT) = 0  THEN 100 / TOTAL_COUNT_ICONT(O.ICONT)
         WHEN TOTAL_VALOARE_ICONT(O.ICONT) &lt;&gt; 0 THEN 100 * VALOARE / TOTAL_VALOARE_ICONT(O.ICONT)
       END
     )
  WHERE
  SEMNIFICATIE IN (100, 110, 140);
*/

  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, SEMNIFICATIE, VALOARE)
  SELECT COUNT(*), SEMNIFICATIE, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (100, 110,  140) GROUP BY SEMNIFICATIE ;

 
  UPDATE TMP_OBLIGPIF O
  SET
    CURS = (SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL),
    PROCENT =
      (
    CASE
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) = 0  THEN 100 / TOTAL_COUNT_SEMNIF(O.SEMNIFICATIE)
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) &lt;&gt; 0 THEN 100 * O.VALOARE /  TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE)
    END
    ) 
   WHERE
    SEMNIFICATIE IN (100, 110, 140);


  UPDATE TMP_OBLIGPIF O
  SET
    PROCTVAAVANS = (SELECT PROCTVAAVANS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL)
  WHERE
  SEMNIFICATIE IN (110);


  DELETE TMP_OBLIGVAMA_INITIAL;
  /* varianta cu totalizare pe icont
  INSERT INTO TMP_OBLIGVAMA_INITIAL(CODOBLIGPIF, ICONT, VALOARE)
  SELECT COUNT(*), ICONT, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (130) GROUP BY ICONT  ;

  UPDATE TMP_OBLIGPIF O
  SET
    ZILE    =
    CASE
      WHEN TO_CHAR(aDATADOCVAMA, &apos;dd.mm.yyyy&apos;) &lt;&gt; &apos;01.01.1900&apos; THEN TRUNC(TERMEN - aDATADOCVAMA)
      ELSE 0
    END,
    PROCENT =
   (
    CASE
      WHEN TOTAL_VALOARE_ICONT_VAMA(O.ICONT) = 0  THEN 100 / TOTAL_COUNT_ICONT_VAMA(O.ICONT)
      WHEN TOTAL_VALOARE_ICONT_VAMA(O.ICONT) &lt;&gt; 0 THEN 100 * VALOARE / TOTAL_VALOARE_ICONT_VAMA(O.ICONT)
    END
    )
  WHERE
  SEMNIFICATIE IN (130);
*/
 
  -- varianta cu totalizare pe semnif
  INSERT INTO TMP_OBLIGVAMA_INITIAL(CODOBLIGPIF, SEMNIFICATIE, VALOARE)
  SELECT COUNT(*), SEMNIFICATIE, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (130) GROUP BY SEMNIFICATIE ;


  UPDATE TMP_OBLIGPIF O
  SET
    ZILE    =
    CASE
      WHEN TO_CHAR(aDATADOCVAMA, &apos;dd.mm.yyyy&apos;) &lt;&gt; &apos;01.01.1900&apos; THEN TRUNC(TERMEN - aDATADOCVAMA)
      ELSE 0
    END,
    CURS = (SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL),
    PROCENT =
   (
    CASE
      WHEN TOTAL_VALOARE_SEMNIF_VAMA(O.SEMNIFICATIE) = 0  THEN 100 / TOTAL_COUNT_SEMNIF_VAMA(O.SEMNIFICATIE)
      WHEN TOTAL_VALOARE_SEMNIF_VAMA(O.SEMNIFICATIE) &lt;&gt; 0 THEN 100 * VALOARE / TOTAL_VALOARE_SEMNIF_VAMA(O.SEMNIFICATIE)
    END
    )
  WHERE
  SEMNIFICATIE IN (130);



 -- STINGERE
 INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
 (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));

 -- memorez starea la intrare a obligatiilor necesara la interfata STORNO FACTURA
   DELETE TMP_OBLIGPIF_INITIAL;
   INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF);
   DELETE TMP_STINGERE_INITIAL;
   INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE);



  -- DETAIL INTRLINK
 INSERT INTO TMP_INTRLINK
 (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT)
 (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT
 FROM
 INTRLINK L
 WHERE
 L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1)
);

 IF aTIPFACTURA = 10 THEN
   UPDATE TMP_INTRLINK L
    SET
      (MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, DATAAVIZ) =
      (SELECT
        G.MONEDA,
        NVL(GREG.CURS, G.CURS),
        S.PU,
        S.CANT,
        S.TVA,
        I.DATADOC
       FROM
         INTRARI1 S,
         GENERAL G
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL,
         INTRARI I
      WHERE
        S.CODINTR1 = L.CODLINIEAVIZ AND  G.CODDOC = S.CODINTR AND I.CODINTR= S.CODINTR AND G.TIPDOC = 2 AND G.SEMNIFICATIE = 140/*AVIZ INTRARE*/)
    ;
 END IF;

-- DETAIL NIR
  INSERT INTO  TMP_NIR (
    CODNIR, CODINTR, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT, VALOARE )
  SELECT
    N.CODNIR, N.CODINTR, N.CARNETNIR, N.NRNIR, N.DATANIR, N.GEST, N.OBS, N.TIPNIR, N.ANULAT, N.BLOCAT, N.OPERAT,
    (SELECT SUM(NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
  FROM NIR N
  WHERE N.CODINTR = RECID;

  DELETE NIRSTOC_MAN;
  INSERT INTO NIRSTOC_MAN
  SELECT * FROM NIRSTOC NS WHERE EXISTS (SELECT CODNIR FROM TMP_NIR WHERE CODNIR = NS.CODNIR);

-- DETAIL NIRSTOC
  INSERT INTO  TMP_NIRSTOC(
    CODNIRSTOC, CODNIR, CODINTR1, CODDVI1, CANTNIR, UMSEC, CODOBIECT, CODIOART, PRET, ROTLEI,
    ROTVALUTA, CODLOCATIE, CANTUM1, CANTUM2, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, PROCENTADAOS, SUPLIMENT,SuplNeded,
    D1, D2, D3,PUVAL, TG,
    DENUM, PARITATE, VALOARE, CANTFURN, MG, DIFPRET, ARETVANEEX, PUSTANDARD, PRETACHIZ, PROCTVA,
    DISCLIKISTOC,
    SERIELOT,
    DENOBIECT,
    PRETREFERINTA,
    CONT,
    CODINTERN,
    CODEXTERN,
    FURN,
    DATAACHIZ,
    TIPDOCACHIZ,
    EUDR_RN,
    EUDR_VN)
  SELECT
    NS.CODNIRSTOC, NS.CODNIR,  NS.CODINTR1, NS.CODDVI1, NS.CANTNIR / U1.PARITATE,
    NS.UMSEC, NS.CODOBIECT, NS.CODIOART, NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA,
    NS.CODLOCATIE, NS.CANTUM1, NS.CANTUM2,
    NS.ADAOS * U1.PARITATE, NS.TVA, NS.TIPSERIE, NS.CODLIVR1, NS.REST, NS.PROCENTADAOS,
    NS.SUPLIMENT,NS.SuplNeded,  NS.D1, NS.D2, NS.D3, NS.PUVAL, NS.TG,
    U1.DEN_UM1, U1.PARITATE,
    NS.CANTNIR * NS.PRET,
    NS.CANTFURN / U1.PARITATE,
    IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.PUSTANDARD,
    D1.PretImport,
    PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
    NS.DISCLIKISTOC,
    NS.SERIELOT,
    O.DENUMIRE,
    O1.PRETREFERINTA,
    IOALUNA.CONT,
    O.CODINTERN,
    O.CODEXTERN,
    NS.FURN,
    NS.DATAACHIZ,
    NS.TIPDOCACHIZ,
    NS.EUDR_RN,
    NS.EUDR_VN
  FROM NIRSTOC_MAN NS
    LEFT JOIN TMP_IOART_LUNA IOALUNA ON IOALUNA.CODIOART = NS.CODIOART
    LEFT JOIN DVI1 D1 ON D1.CODDVI1  = NS.CODDVI1
    LEFT JOIN NARTOBJ   O ON O.CODOBIECT  = NS.CODOBIECT
    LEFT JOIN TMP_NARTOBJ_LUNA O1 ON O1.CODOBIECT = O.CODOBIECT
    LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
    INNER JOIN NUM1 U1 ON U1.CODUM1 = NS.UMSEC
  WHERE NS.CODNIR IN (SELECT CODNIR FROM TMP_NIR);

   insert into tmp_nirstoc1
   select ns1.*
   from nirstoc1 ns1
   where exists (select tmp.codnirstoc from tmp_nirstoc tmp where tmp.codnirstoc = ns1.codnirstoc);

-- DETAIL NIRSER
    INSERT INTO TMP_NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, 
                                                                      OBS, CodCertif, DATAPROD, STARE, TG, SERIE, NRCERTIF, DATAPROD1, TG1)
    (SELECT NS.CODNIRSER, NS.CODNIRSTOC, NS.CODSERIE, NS.CANTNIR, NS.CANTUM1, NS.CANTUM2,
             NS.OBS, NS.CodCertif, NS.DATAPROD, NS.STARE, NS.TG,  (SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), C.NRCERTIF, DATAPROD1, TG1
     FROM NIRSER NS
          LEFT JOIN CERTIF C ON NS.CODCERTIF = C.CODCERTIF
     WHERE NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC));

-- DETAIL LIVR
  INSERT INTO  TMP_LIVR
    ( CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    ( SELECT
      CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
      FROM LIVR WHERE CODINTR = RECID) ;

-- DETAIL LIVR1
/*
  INSERT INTO  TMP_LIVR1
     ( CODLIVR1, CODLIVR, CODDVI1, CODNIRSTOC, CANT, CODNIRSER, PMP, UMSEC,
       DENUM, PARITATE, GEST, CODIOART, CODOBIECT, CODLIVRTOT )
     ( SELECT
         L1.CODLIVR1, L1.CODLIVR, L1.CODDVI1, L1.CODNIRSTOC, L1.CANT / U1.PARITATE, L1.CODNIRSER,
         L1.PMP, L1.UMSEC, U1.DEN_UM1, U1.PARITATE, N.GEST, NS.CODIOART, NS.CODOBIECT, 0
       FROM
         LIVR1 L1 LEFT OUTER JOIN  NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
         LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR,
         NUM1 U1
       WHERE
         L.CODINTR  = RECID AND
         U1.CODUM1  = L1.UMSEC
     );
*/

  INSERT INTO  TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODDVI1,
       CODNIRSTOC,
       CANT,
       CANTUM1,
       CANTUM2,
       CODNIRSER,
       PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC,
       UMSEC,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODDVI1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CANTUM1,
         L1.CANTUM2,
         L1.CODNIRSER,
         L1.PMP, L1.PMPDOC, L1.PMPVALUTA,L1.PMPVALUTADOC,
         L1.UMSEC,
         U1.DEN_UM1,
         U1.PARITATE,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,


         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,

        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER))
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         L.CODINTR  = RECID AND U1.CODUM1 = L1.UMSEC
     );

/*
-- DETAIL LIVRTOT
  DELETE TMP_LIVRTOT;
  INSERT INTO TMP_LIVRTOT
   (CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC,  GEST, CODIOART, CODOBIECT, DENUM, PARITATE, DENGESTIOART, STOCREZOLVAT, CANT)
  SELECT * FROM
     ( SELECT
         0, L1.CODLIVR, L1.CODDVI1, L1.UMSEC,  N.GEST, NS.CODIOART, NS.CODOBIECT,
         U1.DEN_UM1, U1.PARITATE, G.DEN_GEST || CHR(13) || IO.DEN_IOART, 1, SUM(L1.CANT / U1.PARITATE
     )
       FROM
         LIVR1 L1 LEFT OUTER JOIN  NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
         LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR,
         NUM1 U1,
         NGEST G,
         IOART IO
       WHERE
         L.CODINTR   = RECID AND
         U1.CODUM1   = L1.UMSEC  AND
         N.GEST      = G.CODGEST AND
         NS.CODIOART = IO.CODIOART
       GROUP BY
         0, L1.CODLIVR, L1.CODDVI1, NS.CODOBIECT, L1.UMSEC,
         N.GEST, NS.CODIOART,  U1.DEN_UM1, U1.PARITATE , G.DEN_GEST || CHR(13) || IO.DEN_IOART
     )
   ORDER BY CODLIVR, CODDVI1;


   UPDATE TMP_LIVRTOT T
   SET
   CODLIVRTOT = ROWNUM,
   DENOBIECT  = PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT);


-- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
    UPDATE TMP_LIVR1 L1 SET CODLIVRTOT =
    ( SELECT CODLIVRTOT FROM TMP_LIVRTOT
      WHERE
        CODLIVR    = L1.CODLIVR  AND
        CODIESINT1 = L1.CODDVI1  AND
        UMSEC      = L1.UMSEC    AND
        PARITATE   = L1.PARITATE AND
        GEST       = L1.GEST     AND
        CODIOART   = L1.CODIOART
     );

*/


-- PARITATEA PRETURILOR DIN LIVRVAL ESTE CEA DIN TMP_LIVR1
   UPDATE TMP_LIVRVAL LV
   SET
     PRETINREG = PRETINREG * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1),
     PRETACHIZ = PRETACHIZ * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1);

-- Detail LIVRTOT
  DELETE TMP_LIVRTOT;

  INSERT INTO TMP_LIVRTOT
   (CODLIVRTOT,
   CODLIVR,
   CODIESINT1,
   UMSEC,
   GEST,
   CODIOART,
   CODOBIECT,
   DENUM,
   PARITATE,
   DENGESTIOART,
   DIFPRET,
   ARETVANEEX,
   MG,
   CONT,
   STOCREZOLVAT,
   CANT,
   PRETINREG,
   PRETACHIZ,
   PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC)

  SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODDVI1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         1,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PRETACHIZ * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMP       * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPDOC    * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTA * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTADOC * L1.CANT) / SUM(L1.CANT)
       FROM TMP_LIVR1 L1
         LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
         LEFT OUTER JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
         LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
       WHERE
         L.CODINTR = RECID
       GROUP BY
         0, L1.CODLIVR, L1.CODDVI1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE , G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT
     )
  ORDER BY CODLIVR, CODDVI1;


   UPDATE TMP_LIVRTOT T SET
   CODLIVRTOT            = ROWNUM,
   DENOBIECT             = (SELECT DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT), --PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
-- INDEXMASTER = (SELECT INDEXLOCAL FROM TMP_TRANSF1 WHERE CODTRANSF1 = T.CODIESINT1),
  (UM1, UM2, RELATIEUM1) = (SELECT UM1, UM2, RELATIEUM1 FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   GESTIMPLICITA         = (SELECT GESTIMPLICITA FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   PROCTVA               = PKG_SELECTARTICOLE.GETPROCENTTVA
                         (PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);



-- FAC LEGATURA INTRE LIVR1 si LIVRTOT
   UPDATE TMP_LIVR1 l1 SET CodLivrTot =
    ( SELECT CodLivrTot FROM TMP_LIVRTOT
      WHERE
        CODLIVR    = l1.CODLIVR  AND
        CODIESINT1 = l1.CODDVI1  AND
        UMSEC      = l1.UMSEC    AND
        Paritate   = l1.Paritate AND
        GEST       = l1.GEST     AND
        CODIOART   = l1.CODIOART
     );


-- DETAIL TMP_LIVRVAL;
   INSERT INTO TMP_LIVRVAL SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);


-- PENTRU DISTRIBUIRE VALORI SUPLIMENTARE PREIAU MASA SI VOLUM
   UPDATE TMP_NIRSTOC NS
   SET
     INDEXMASTER   = (SELECT INDEXLOCAL FROM TMP_DVI1 WHERE CODDVI1 = NS.CODDVI1),
     (UM1, UM2, RELATIEUM1, RELATIEUM2)      = (SELECT NVL(UM1, 0), NVL(UM2, 0), NVL(RELATIEUM1, 0), NVL(RELATIEUM2, 0) FROM NART A WHERE A.CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(NS.CODOBIECT)),
     (MASA, VOLUM) =  (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = NS.CODOBIECT),
     PRETINITIAL     = PRET,
     ADAOSINITIAL    = ADAOS,
     CODIOARTINITIAL = CODIOART;


-- MEMOREZ STAREA LA INTRARE A LIVRARILOR
     DELETE TMP_LIVR1_INITIAL;
     INSERT INTO TMP_LIVR1_INITIAL (SELECT * FROM TMP_LIVR1);

     DELETE TMP_INTRLINK_INITIAL;
     INSERT INTO TMP_INTRLINK_INITIAL(CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);




-- PREIAU CARACTERIZAREA CONTABILA VALABILA PE LUNA DE LUCRU A PARTENERULUI DE PE INVOICE
   DELETE TMP_IOPARTDOC;

   LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(aCODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   LOOP
     FETCH LUNAREF INTO IOPART1REC;
     EXIT WHEN LUNAREF%NOTFOUND;
     IF IOPART1REC.CODIOPART1 &gt; 0 THEN
         INSERT INTO TMP_IOPARTDOC
         ( CODPART,
           CODIOPART1,
           CODIOPART,
           CONTFURNIZOR,
           CONTCLIENT,
           CONTFURNAVANS,
           CONTCLIENTAVANS,
           CONTFURNAVIZ,
           CONTCLIENTAVIZ,
           CONTFURNMF,
           CONTCREDITD,
           CONTDEBITD,
           CONTLITIGII,
           CONTFURNAVS,
           CONTFURNAVIC,
           CONTFURNAVIN,
           CONTTERTI,
						CONTFURNLEAS,
						CONTNCRF,
						CONTNCRC,
						CONTCHELTAVANS,
						CONTVENITAVANS,
						contgarantieEF   ,
						contgarantieTF   ,
						contgarantieEC   ,
						contgarantieTC   ,
						ContSuplimF1,
						ContSuplimF2,
						ContSuplimF3,
						ContSuplimF4,
						ContSuplimF5,
						ContSuplimC1,
						ContSuplimC2,
						ContSuplimC3,
						ContSuplimC4,
						ContSuplimC5,
           TvaNeexF, TvaNeexP, TvaNeexI,
           TVANEEXC,
           TIP
           )
           VALUES
           (aCODPART,
            IOPART1REC.CODIOPART1,
            IOPART1REC.CODIOPART,
            IOPART1REC.CONTFURNIZOR,
            IOPART1REC.CONTCLIENT,
            IOPART1REC.CONTFURNAVANS,
            IOPART1REC.CONTCLIENTAVANS,
            IOPART1REC.CONTFURNAVIZ,
            IOPART1REC.CONTCLIENTAVIZ,
            IOPART1REC.CONTFURNMF,
            IOPART1REC.CONTCREDITD,
            IOPART1REC.CONTDEBITD,
            IOPART1REC.CONTLITIGII,
            IOPART1REC.CONTFURNAVS,
            IOPART1REC.CONTFURNAVIC,
            IOPART1REC.CONTFURNAVIN,
            IOPART1REC.CONTTERTI,
						IOPART1REC.CONTFURNLEAS,
            IOPART1REC.CONTNCRF,
            IOPART1REC.CONTNCRC,
            IOPART1REC.CONTCHELTAVANS,
            IOPART1REC.CONTVENITAVANS,
            IOPART1REC.contgarantieEF   ,
            IOPART1REC.contgarantieTF   ,
            IOPART1REC.contgarantieEC   ,
            IOPART1REC.contgarantieTC   ,
            IOPART1REC.ContSuplimF1,
            IOPART1REC.ContSuplimF2,
            IOPART1REC.ContSuplimF3,
            IOPART1REC.ContSuplimF4,
            IOPART1REC.ContSuplimF5,
            IOPART1REC.ContSuplimC1,
            IOPART1REC.ContSuplimC2,
						IOPART1REC.ContSuplimC3,
            IOPART1REC.ContSuplimC4,
            IOPART1REC.ContSuplimC5,
            IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
            IOPART1REC.TVANEEXC,
            IOPART1REC.TIP
           );
     END IF;
   END LOOP;





   -- PREIAU CARACTERIZAREA CONTABILA VALABILA PE LUNA DE LUCRU A VAMEI DE PE DVI
   DELETE TMP_IOPARTVAMA;

       LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(aCODVAMA, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
       LOOP
         FETCH LUNAREF INTO IOPART1REC;
         EXIT WHEN LUNAREF%NOTFOUND;
         IF IOPART1REC.CODIOPART1 &gt; 0 THEN
             INSERT INTO TMP_IOPARTVAMA
             ( CODPART,
               CODIOPART1,
               CODIOPART,
               CONTFURNIZOR,
               CONTCLIENT,
               CONTFURNAVANS,
               CONTCLIENTAVANS,
               CONTFURNAVIZ,
               CONTCLIENTAVIZ,
               CONTFURNMF,
               CONTCREDITD,
               CONTDEBITD,
               CONTLITIGII,
               CONTFURNAVS,
               CONTFURNAVIC,
               CONTFURNAVIN,
               CONTTERTI,
               TvaNeexF, TvaNeexP, TvaNeexI,
               TVANEEXC,
               TIP
               )
               VALUES
               (aCODPART,
                IOPART1REC.CODIOPART1,
                IOPART1REC.CODIOPART,
                IOPART1REC.CONTFURNIZOR,
                IOPART1REC.CONTCLIENT,
                IOPART1REC.CONTFURNAVANS,
                IOPART1REC.CONTCLIENTAVANS,
                IOPART1REC.CONTFURNAVIZ,
                IOPART1REC.CONTCLIENTAVIZ,
                IOPART1REC.CONTFURNMF,
                IOPART1REC.CONTCREDITD,
                IOPART1REC.CONTDEBITD,
                IOPART1REC.CONTLITIGII,
                IOPART1REC.CONTFURNAVS,
                IOPART1REC.CONTFURNAVIC,
                IOPART1REC.CONTFURNAVIN,
                IOPART1REC.CONTTERTI,
                IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
                IOPART1REC.TVANEEXC,
                IOPART1REC.TIP
               );
         END IF;
       END LOOP;



   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = TIPINTR AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = TIPINTR AND CODDOC = RECID);

   DELETE TMP_RULAJ;

   UPDATE TMP_INTRLINK L
   SET
     DATACOMANDA =
     (SELECT  C.DATADOC
      FROM
      COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA)
     ;

   UPDATE TMP_DVI
   SET VALTOTALA =
      CASE
       WHEN TAXEINCLUSE = 0 THEN (SELECT NVL(SUM(VALOARE), 0) FROM TMP_DVI1)
       ELSE (SELECT NVL(SUM(VALOARE), 0) FROM TMP_DVI1 WHERE TIPLINIE IN (&apos;=&apos;, &apos;S&apos;))
      END;


   UPDATE TMP_NIRSER NSE
    SET
      PARITATE = NVL((SELECT PARITATE FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC),1),
      CANTNIR  = CANTNIR / NVL((SELECT PARITATE FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC),1);



   BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
     EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
   END;

   IF TIPPREFIX = &apos;2&apos; THEN
     UPDATE TMP_INTRARI1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
   ELSE
   IF TIPPREFIX = &apos;3&apos; THEN
     UPDATE TMP_INTRARI1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
   END IF;
   END IF;




   IF TIPPREFIX &lt;&gt; &apos;1&apos; THEN

     UPDATE TMP_DVI1 D1
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = D1.CODINTR1);


     UPDATE TMP_LIVR1 L1
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = L1.CODINTR1);


     UPDATE TMP_NIRSTOC NS
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_DVI1 I1 WHERE I1.CODDVI1 = NS.CODDVI1);


   END IF;


-- PREIAU DE PE COMENZI D1..D3
  FOR V_REC IN
  (SELECT I1.CODINTR1, C1.D1, C1.D2, C1.D3
   FROM TMP_INTRARI1 I1,
    TMP_INTRLINK IL,
    COMANDA1 C1
   WHERE
    IL.CODINTR1 = I1.CODINTR1
    AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
   )
   LOOP
     UPDATE
       TMP_INTRARI1
     SET
       D1 = V_REC.D1,
       D2 = V_REC.D2,
       D3 = V_REC.D3
     WHERE
      CODINTR1 = V_REC.CODINTR1;

     UPDATE
       TMP_DVI1
     SET
       D1 = V_REC.D1,
       D2 = V_REC.D2,
       D3 = V_REC.D3
     WHERE
      CODINTR1 = V_REC.CODINTR1;

   END LOOP;

-- PENTRU INREGISTRARILE CARE NU VIN DE PE COMENZI PUN PE INTRARI1 D1..D3 IMPLICITE DIN NART
  FOR V_REC IN
  (SELECT I1.CODINTR1, A.D1, A.D2, A.D3
   FROM
    TMP_INTRARI1 I1,
    NARTOBJ O,
    NART A
   WHERE
     TIPLINIE = &apos;=&apos;
     AND NOT EXISTS (SELECT CODINTR1 FROM TMP_INTRLINK     WHERE CODINTR1 = I1.CODINTR1)
     AND NOT EXISTS (SELECT CODINTR1 FROM TMP_INTRPRODLINK WHERE CODINTR1 = I1.CODINTR1)
     AND O.CODOBIECT  = I1.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
  )
  LOOP
    UPDATE TMP_INTRARI1
    SET
     D1 = V_REC.D1,
     D2 = V_REC.D2,
     D3 = V_REC.D3
    WHERE
     CODINTR1 = V_REC.CODINTR1;

    UPDATE TMP_DVI1
    SET
     D1 = V_REC.D1,
     D2 = V_REC.D2,
     D3 = V_REC.D3
    WHERE
     CODINTR1 = V_REC.CODINTR1;


  END LOOP;

  UPDATE
    TMP_INTRARI1 I1
  SET
    I1.CantUM2 = (SELECT SUM(B.NetKg) FROM BCAR B WHERE B.TipDoc = TIPINTR AND B.CodDoc1 = I1.CodIntr1)
	WHERE
    I1.PRELUAT = 2;
    
  -- mIntraridinImport --&gt; 5  
  PKG_CFGTABLES.EXT_GOTORECORD(5);

  COMMIT;
END;




PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
  aVALOARE NUMBER(20, 7);
  NRMIFIX  NUMBER(5);

  VCOD NUMBER(20);
  TIPINTR INTEGER := 0;
  NR INTEGER := 0;
  AOPERAT INTEGER := 0;
  AANULAT INTEGER := 0;

  OLDCARNETNIR NUMBER(20) := 0;
  OLDNRNIR     NUMBER(20) := 0;

  OLDCARNETLIVR NUMBER(20) := 0;
  OLDNRLIVR     NUMBER(20) := 0;

  ACODSERIE     NUMBER(20) := 0;
  ACODPART      NUMBER(20) := 0;
  ACODMONEDA    NUMBER(20) := 0;
  ACURS         NUMBER(20, 7) := 0;
  aTIPFACTURA   NUMBER(20) := 0;

  NOMSERIE VARCHAR2(75);

  LockStocFaraCertif varchar2(3);

  aSubunitatea number(20);
  aDataDoc date;
  aDoc varchar2(200);
  aTVAINCASARE     INTEGER := 0;
  aTipImport integer := 0;
  aTIPDOCNirStoc1 integer;
  aCodDVI NUMBER(20);
  aCodComanda1 number(20);
  TotSosit number(20,7);
  aAn integer;
  aLuna integer;
  aCount number;
	TIPTRANZ     NUMBER(18);
	
BEGIN
BEGIN
  SELECT
    TIPDOC,TipTranzactie,
    OPERAT,
    ANULAT,
    PARTENER,
    MONEDA,
    CURS,
    TIPFACTURA,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    NVL(TVAINCASARE, 0),
    AN,
    LUNA
  INTO
    TIPINTR, TipTranz, 
    AOPERAT,
    AANULAT,
    ACODPART,
    aCODMONEDA,
    aCURS,
    aTIPFACTURA,
    aSUBUNITATEA,
    aDataDoc,
    adoc,
    aTVAINCASARE,
    aAn,
    aLuna
  FROM
  TMP_INTRARI;
  
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (TIPINTR);
  
  aTipImport := 0;
  if TIPINTR = 5 then
    BEGIN
      select Nvl(TipImport,0) into aTipImport from TMP_DVI;
      EXCEPTION WHEN OTHERS THEN aTipImport := 0;
    END;
  end if;
  aTIPDOCNirStoc1 := TIPIntr - 2*TIPIntr*aTipImport;

  delete tmp_manevra;
  insert into tmp_manevra(codunic)
  select ns11.codnirstoc
  from nirstoc ns
       inner join nir on nir.codnir = ns.codnir
       inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
       inner join nirstoc1 ns11 on ns11.codcomanda1 = ns1.codcomanda1
  where nir.codintr = recid and ns1.codcomanda1 &gt; 0
  union
  select ns1.codnirstoc
  from nirstoc ns
       inner join nir on nir.codnir = ns.codnir
       inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
  where nir.codintr = recid and nvl(ns1.codcomanda1,0) = 0
  union
  select ns11.codnirstoc
  from tmp_nirstoc tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
       inner join nirstoc1 ns11 on ns11.codcomanda1 = ns1.codcomanda1
  where ns1.codcomanda1 &gt; 0 and tmp.codnirstoc &gt; 0
  union
  select ns1.codnirstoc
  from tmp_nirstoc tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
  where nvl(ns1.codcomanda1,0) = 0 and tmp.codnirstoc &gt; 0;

   IF aTVAINCASARE = 0 THEN
     UPDATE TMP_GENERAL
     SET
       DATATVA = NULL
     WHERE
      SEMNIFICATIE IN  (100, 130);
   ELSE
     UPDATE TMP_GENERAL
     SET
       DATATVA = aDATADOC
     WHERE
      SEMNIFICATIE  IN (100, 130);
   END IF;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
    delete tmp_manevra_intr1;
  end if;

  IF OPERATION = 0 THEN  -- UPDATE
    -- MASTER INTRARI
    SELECT  CODINTR INTO RECID FROM TMP_INTRARI;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      --WINMADMIN.PKG_USERFIRME.PostLog(&apos;DVI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE INTRARI
    SET
    (TIPDOC,
     ANULAT,
     BLOCAT,
     OPERAT,
     PREFIXDOC,
     NRDOC,
     SERIADOC,
     DATADOC,
     PARTENER,
     NRAVIZ,
     CARNETDOC,
     VALDOC,
     TVADOC,
     MAJORARI,
     AN,
     LUNA,
     OBS,
     SATELIT,
     COMPLEX,
     ProRata,
     CODCONTRACT,
     CONTSUPLIM,
     VALSUPLIM,
     TIPREPSUPLIM,
     TIPTVA,
     SUBUNITATEA,
     CODFISCAL,
     MONEDA,
     CURS,
     TIPTRANZACTIE,
     NRI,
     ExclusPlata, DataTVA,
     FaraReg, TVAIncasare,
     TIPFACTURA,
     CODANALIZA,
     STADIUWMS,
     DATAREFSCAD,
     CODLOCATIE,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, is_etransp, MODTRANSP,
     DELEGAT, CODAUTO,NRTRANSP  ) =
   (SELECT
     TIPDOC,
     ANULAT,
     BLOCAT,
     OPERAT,
     PREFIXDOC,
     NRDOC,
     SERIADOC,
     DATADOC,
     PARTENER,
     NRAVIZ,
     CARNETDOC,
     VALDOC,
     TVADOC,
     MAJORARI,
     AN,
     LUNA,
     OBS,
     SATELIT,
     COMPLEX,
     ProRata,
     CODCONTRACT,
     CONTSUPLIM,
     VALSUPLIM,
     TIPREPSUPLIM,
     TIPTVA,
     SUBUNITATEA,
     CODFISCAL,
     MONEDA,
     CURS,
     TIPTRANZACTIE,
     NRI,
     ExclusPlata, DataTVA,
     FaraReg, TVAIncasare,
     TIPFACTURA,
     CODANALIZA,
     STADIUWMS,
     DATAREFSCAD,
     CODLOCATIE,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, is_eTransp, MODTRANSP,
     DELEGAT, CODAUTO,NRTRANSP  FROM TMP_INTRARI)
    WHERE CODINTR = RECID ;


-- GENERAL + OBLIGPIF
   DELETE FROM OBLIGPIF
   WHERE
   CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR AND SEMNIFICATIE IN (100, 110, 111, 140)) AND
   CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

   DELETE FROM OBLIGPIF
   WHERE
   CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE CODDOC IN (SELECT CODDVI FROM DVI WHERE CODINTR = RECID) AND TIPDOC = TIPINTR AND SEMNIFICATIE = 130) AND
   CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

   DELETE FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR AND SEMNIFICATIE IN (100, 110, 111, 140) AND
   CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

   DELETE FROM GENERAL WHERE TIPDOC = TIPINTR AND SEMNIFICATIE = 130 AND CODDOC IN (SELECT CODDVI FROM DVI WHERE CODINTR = RECID) AND
   CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

   DELETE FROM STINGERE WHERE CODSTINGERE IN
   (SELECT CODSTINGERE FROM TMP_STINGERE_INITIAL WHERE CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE));


-- Detail INTRLINK
    DELETE FROM INTRLINK WHERE CODINTR1 IN
    ( SELECT CODINTR1 FROM INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN (SELECT CodIntr1 FROM TMP_INTRLINK)
     );

-- Detail INTRARI1
    for v_rec in (select * from INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN
                  (SELECT CodIntr1 FROM TMP_INTRARI1)
                  ) loop
      if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
         pkg_miscari_interne.SetDoCommit(False);
         for v_mf in (select t.codtransf
                      from intrari1 i1
                           inner join imbmifixlink l on l.codintr1 = i1.codintr1
                           inner join transf1 t1 on t1.codtransf1 = l.codtransf1
                           inner join transf t on t.codtransf = t1.codtransf
                      where i1.codintr = recid and i1.codintr1 not in (SELECT CodIntr1 FROM TMP_INTRARI1)
                      ) loop
           pkg_miscari_interne.SP_DELETERECORD(v_mf.codtransf);
         end loop;
         pkg_miscari_interne.SetDoCommit(True);
       end if;
       DELETE FROM INTRARI1 WHERE CodIntr1 = v_rec.codintr1;
       DELETE FROM TAXDECL  WHERE TipDoc = TIPINTR and CODDOC1 = V_REC.CODINTR1;
    end loop;

    FOR v_rec IN (SELECT * FROM TMP_INTRARI1  ORDER BY IndexLocal) LOOP
      IF NVL(v_rec.CodIntr1, 0) &gt; 0 THEN
        UPDATE INTRARI1 SET
           IndexLocal = v_rec.IndexLocal,
           TipLinie   = v_rec.TipLinie,
           UmSec      = v_rec.UmSec,
           An         = v_rec.An,
           Luna       = v_rec.Luna,
           ContServ   = v_rec.ContServ,
           CONTDISCOUNT = v_rec.CONTDISCOUNT,
           GestAct    = v_rec.GestAct,
           CodObiect  = v_rec.CodObiect,
           PretOrig   = v_rec.PretOrig / NVL(v_rec.Paritate, 1),
           PU         = v_rec.PU   / NVL(v_rec.Paritate, 1),
           Cant       = v_rec.Cant * NVL(v_rec.Paritate, 1),
           TVA        = v_rec.TVA,
           AdDim      = v_rec.AdDim,
           Preluat    = V_REC.Preluat,
           CODOBLIGSTORNO   = v_rec.CODOBLIGSTORNO,
           CURSFACTURAAVANS = v_rec.CURSFACTURAAVANS,

--!!!!           RestFact   = 0,
           RestFact   =
           CASE
             WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT la liniile de discount
             ELSE 0
           END,
           NrCertif    = v_rec.NrCertif,
           COEFDISCMAJ = v_rec.COEFDISCMAJ,
           TG         = v_rec.TG,
           PUMaximal  = v_rec.PUMaximal,
           PROCADAOS  = v_rec.PROCADAOS,
           PURidicata = v_rec.PURidicata,
           CODMIFIX   = V_REC.CODMIFIX,
           OBS        = V_REC.OBS,
           CODCENTRU  = V_Rec.Codcentru,
           RestIMBMF   =
           CASE
             WHEN v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND aOperat = 1 AND aAnulat = 0
             THEN v_rec.Cant * v_rec.PU * aCURS -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                IL.CODINTR1 = v_Rec.CodINTR1 AND T.OPERAT = 1 AND T.ANULAT = 0
               )
             ELSE 0
           END,
           CODANALIZANOD = v_rec.CODANALIZANOD,
           CODNIMOB      = v_rec.CODNIMOB,
           CODCMDINT1    = V_REC.CODCMDINT1,
           GESTPRODAVIZSUB = V_REC.GESTPRODAVIZSUB,
           CODAUTO         = V_REC.CODAUTO
        WHERE
           CodIntr1   = v_rec.CodIntr1;
        if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
          for v_mf in (select nsp.pret + i1.cant * i1.pu * aCurs ValNou, ns.pret ValVechi, t1.codtransf1, ns.codnirstoc,
                              t.codtransf, t.tipdoc
                       from intrari1 i1
                            inner join imbmifixlink l on l.codintr1 = i1.codintr1
                            inner join transf1 t1 on t1.codtransf1 = l.codtransf1
                            inner join transf t on t.codtransf = t1.codtransf
                            inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                            inner join nirstoc nsp on nsp.codnirstoc = ns.codnirstocparinte
                       where i1.codintr = recid and i1.codintr1 = v_rec.codintr1
                       ) loop
            if v_mf.valnou &lt;&gt; v_mf.valvechi then
              update transf1 set pu = v_mf.valnou where codtransf1 = v_mf.codtransf1;
              update transf set valdoc = v_mf.valnou where codtransf = v_mf.codtransf;
              update nirstoc set pret = v_mf.valnou where codnirstoc = v_mf.codnirstoc;
              update jurnal1 set dirty = 1 where coddoc = v_mf.codtransf and tipdoc = v_mf.tipdoc;
              PKG_Jurnal.setDirtyNirStoc(V_MF.CODNIRSTOC, V_MF.ValNou, &apos;0&apos;, 0);
            end if;
          end loop;
        end if;
     ELSE
       SELECT seq_INTRARI1_CodIntr1.Nextval INTO VCOD from Dual;
       
       PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI1&apos;, vCOD, v_Rec.Codintr1);
       
       if v_Rec.Tiplinie = &apos;S&apos; and pkg_categconst.ESTEIMBUNATATIREMIFIX(v_rec.contserv) &gt; 0 and
           PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
          for v_xxx in (select mfix1.codnirstoc
                        from mifix1 mfix1
                        where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
            insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
            values(vCod, v_xxx.codnirstoc, v_rec.cant * v_rec.pu * aCurs);
            exit;
          end loop;
        end if;

       INSERT INTO INTRARI1
       ( CodIntr1, CodIntr, IndexLocal, TipLinie, Umsec, An, Luna, ContServ,
         CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA,
         AdDim, RestFact,NrCertif, COEFDISCMAJ, TG,
         PUMaximal, PROCADAOS, PURidicata, CODOBLIGSTORNO, CURSFACTURAAVANS,
         CODMIFIX, CODCENTRU, RESTIMBMF, Obs, CODANALIZANOD, PRELUAT, CODNIMOB, CODCMDINT1, GESTPRODAVIZSUB, CODAUTO)
       VALUES
       ( vCod,  RecID, v_rec.IndexLocal , v_rec.TipLinie,  v_rec.Umsec,  v_rec.An,  v_rec.Luna,  v_rec.ContServ,
         V_REC.CONTDISCOUNT, v_rec.GestAct,  v_rec.CodObiect,  v_rec.PretOrig  /  NVL(v_rec.Paritate, 1),  v_rec.PU /  NVL(v_rec.Paritate, 1), v_rec.Cant *  NVL(v_rec.Paritate, 1),  v_rec.TVA,
         v_rec.AdDim,
         (CASE
            WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
            ELSE v_rec.Cant *  v_rec.Paritate
          END),
         v_rec.NrCertif, V_REC.COEFDISCMAJ,  v_rec.TG,
         v_rec.PUMaximal, V_REC.PROCADAOS,  v_rec.PURidicata, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS,
         V_REC.CODMIFIX, V_REC.CODCENTRU,
         CASE
           WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 THEN V_REC.PU * V_REC.CANT * aCURS
           ELSE 0
         END, V_rec.Obs, v_Rec.CODANALIZANOD, V_REC.PRELUAT, V_REC.CODNIMOB, V_REC.CODCMDINT1, V_REC.GESTPRODAVIZSUB, V_REC.CODAUTO
         );

       UPDATE TMP_DVI1 SET CODINTR1 = VCOD WHERE CODINTR1 = v_rec.CODINTR1;

       UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
       UPDATE TMP_INTRARI1 SET CODINTR1 = VCOD WHERE CODINTR1 = v_rec.CODINTR1;


     END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_INTRLINK) LOOP
    SELECT NVL(COUNT(*), 0) INTO NR  FROM INTRLINK WHERE CODINTR1 = v_rec.CODINTR1;
    IF NR = 0  THEN
      INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT)
      VALUES  (v_rec.CODINTR1, v_rec.CODLINIECOMANDA, v_rec.CODLINIEAVIZ, v_rec.CANT);
    ELSE
      UPDATE INTRLINK
      SET
        CODINTR1        = v_Rec.CODINTR1,
        CODLINIECOMANDA = v_rec.CODLINIECOMANDA,
        CODLINIEAVIZ    = v_Rec.CODLINIEAVIZ,
        CANT            = v_Rec.Cant
      WHERE CODINTR1 = v_rec.CODINTR1;
    END IF;
  END LOOP;


-- DVI1
 DELETE FROM DVI1 WHERE CODDVI IN (SELECT CODDVI FROM DVI WHERE CODINTR = RECID) AND CODDVI1 NOT IN (SELECT CODDVI1 FROM TMP_DVI1);

-- DVI
 DELETE FROM DVI WHERE CODINTR = RECID AND CODDVI NOT IN (SELECT CODDVI FROM TMP_DVI);

 FOR V_REC IN (SELECT * FROM TMP_DVI) LOOP
   IF NVL(v_rec.CODDVI, 0) &gt; 0 THEN
     UPDATE DVI
     SET
       CODINTR           = RECID,
       CODVAMA           = V_REC.CODVAMA,
       NRDOC             = V_REC.NRDOC,
       DATADOC           = V_REC.DATADOC,
       CONTCHELT         = V_REC.CONTCHELT,
       CONTTVA           = V_REC.CONTTVA,
       TAXEINCLUSE       = V_REC.TAXEINCLUSE,
       FISAVAMA          = V_REC.FISAVAMA,
       TAXEPECHELT       = V_REC.TAXEPECHELT,
       TipRepSuplim      = V_REC. TipRepSuplim,
       ValSuplim         = V_REC.ValSuplim,
       ContSuplim        = V_REC.ContSuplim,
       OBS               = V_REC.OBS,
       TIPIMPORT         = V_REC.TIPIMPORT,
       VALDOCVAMA        = V_REC.VALDOCVAMA,
       TVADOCVAMA        = V_REC.TVADOCVAMA,
       ExclusPlata       = v_rec.ExclusPlata, 
       FaraReg           = V_REC.FaraReg,
       TVAIncasare       = v_rec.TVAIncasare,
       SeriaDoc          = V_REC.Seriadoc
     WHERE CODDVI = V_REC.CODDVI;
   ELSE
     SELECT SEQ_DVI_CODDVI.NEXTVAL INTO VCOD FROM DUAL;

     UPDATE TMP_DVI1 SET CODDVI = VCOD;
     UPDATE TMP_GENERAL SET CODDOC = VCOD WHERE SEMNIFICATIE = 130;


     INSERT INTO DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE,
     FISAVAMA, TAXEPECHELT, TipRepSuplim, ValSuplim, ContSuplim, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA, ExclusPlata, FaraReg, TVAIncasare, SeriaDoc)
     VALUES
     (VCOD, RECID, V_REC.CODVAMA, V_REC.NRDOC, V_REC.DATADOC, V_REC.CONTCHELT, V_REC.CONTTVA, V_REC.TAXEINCLUSE,
      V_REC.FISAVAMA, V_REC.TAXEPECHELT, V_REC.TipRepSuplim, V_REC.ValSuplim, V_REC.ContSuplim, V_REC.OBS, V_REC.TIPIMPORT, V_REC.VALDOCVAMA,
      V_REC.TVADOCVAMA, v_rec.ExclusPlata, V_REC.FaraReg, v_rec.TVAIncasare, v_rec.SeriaDoc);
   END IF;

 END LOOP;

 FOR V_REC IN (SELECT * FROM TMP_DVI1 ORDER BY INDEXLOCAL) LOOP
   IF NVL(V_REC.CODDVI1, 0) &gt; 0 THEN
     UPDATE DVI1
     SET
       CODDVI       = V_REC.CODDVI,
       CODINTR1     = V_REC.CODINTR1,
       TIPLINIE     = V_REC.TIPLINIE,
       INDEXLOCAL   = V_REC.INDEXLOCAL,
       CANT         = V_REC.CANT * NVL(V_REC.PARITATE, 1),
       PRETIMPORT   = V_REC.PRETIMPORT / NVL(V_REC.PARITATE, 1),
       PUMAXIMAL    = V_REC.PUMAXIMAL / NVL(V_REC.PARITATE, 1),
       CONTDISCOUNT = V_REC.CONTDISCOUNT,
       PRETVALUTA   = V_REC.PRETVALUTA / NVL(V_REC.PARITATE, 1),
       PRETORIGINAL = V_REC.PRETORIGINAL,
       TVANEDED     = V_REC.TVANEDED,
       TVA          = V_REC.TVA,
       UMSEC        = V_REC.UMSEC,
       ADDIM        = V_REC.ADDIM,
       CODOBIECT    = V_REC.CODOBIECT,
       VALOARETAXA  = CASE
                        WHEN V_REC.TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) THEN V_REC.VALOARE
                        ELSE 0
                      END
     WHERE
       CODDVI1 = V_REC.CODDVI1;
   ELSE
     SELECT SEQ_DVI1_CODDVI1.NEXTVAL INTO VCOD FROM DUAL;
     update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.coddvi1;
     UPDATE TMP_NIRSTOC SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
     UPDATE TMP_LIVR1   SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
     UPDATE TMP_DVI1    SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;

     INSERT INTO DVI1(CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA, TVANEDED, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, VALOARETAXA)
     VALUES
     (VCOD, V_REC.CODDVI, V_REC.CODINTR1, V_REC.TIPLINIE, V_REC.INDEXLOCAL,
      V_REC.PRETIMPORT / NVL(V_REC.PARITATE, 1),
      V_REC.PUMAXIMAL / NVL(V_REC.PARITATE, 1),
      V_REC.CONTDISCOUNT,
      V_REC.PRETVALUTA / NVL(V_REC.PARITATE, 1),
      V_REC.TVANEDED, V_REC.PRETORIGINAL,
      V_REC.TVA,
      V_REC.UMSEC,
      V_REC.ADDIM,
      V_REC.CODOBIECT,
      V_REC.CANT * NVL(V_REC.PARITATE, 1),
      CASE
        WHEN V_REC.TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) THEN V_REC.VALOARE
        ELSE 0
      END
    );
   END IF;
 END LOOP;


-- Detail GENERAL -- MUSAI DUPA DVI PENTRU CA CODDOC = CODDVI LA INREGISTRARI CU SEMNIFICATIE = 130
 FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
    IF NVL(v_rec.CODGENERAL, 0) &gt; 0  THEN
      UPDATE GENERAL G
      SET
        TIPDOC       = v_rec.TIPDOC,
        CODDOC       = v_rec.CODDOC,
        MONEDA       = v_rec.MONEDA,
        CURS         = v_rec.CURS,
        SEMNIFICATIE = v_rec.SEMNIFICATIE,
        ICONTAVANS   = v_rec.ICONTAVANS,
        PROCTVAAVANS = v_rec.PROCTVAAVANS,
        TVA          = v_rec.TVA,
        ExclusPlata  = v_rec.ExclusPlata, 
        DataTVA      = v_rec.DataTVA,
        FaraReg      = v_rec.FaraReg
      WHERE
      G.CODGENERAL = v_rec.CODGENERAL;
    ELSE
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO VCOD from Dual;
     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg )
     VALUES (VCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.SEMNIFICATIE, v_rec.ICONTAVANS,V_REC.PROCTVAAVANS,  v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA, v_rec.FaraReg);

     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD  WHERE CODGENERAL = v_Rec.CODGENERAL;

    END IF;
 END LOOP;

-- Detail OBLIGPIF
    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF) LOOP
      IF NVL(v_rec.CODOBLIGPIF, 0) &gt; 0 THEN
        UPDATE OBLIGPIF
        SET
          CODGENERAL   = v_rec.CODGENERAL,
          TERMEN       = v_rec.TERMEN,
          VALOARE      = NVL(v_rec.VALOARE, 0),
          REST         =
           (
            CASE
              WHEN V_REC.SEMNIFICATIE =  111 THEN NULL
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 111 AND v_rec.VALOARE &gt; 0 THEN v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 111 AND v_rec.VALOARE &lt; 0 THEN v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
            END),

          CODPART      = v_rec.CODPART,
          ICONT        = v_rec.ICONT,
          TIPPLATA     = v_rec.TIPPLATA,
          CODCENTRU    = V_REC.CODCENTRU,
          MAJORARI     = v_rec.MAJORARI,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          TIP          = v_rec.TIP,
          CODANALIZANOD= v_rec.CODANALIZANOD
        WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;
      ELSE
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
        UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;


        --  TMP_INTRARI1 este deja postat; trebuie sa sincronizez cu originalul UPDATE TMP_INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;
        UPDATE INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODINTR = RECID AND CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

        INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP,CODANALIZANOD)
        VALUES (VCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, V_REC.CODCENTRU, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP,v_rec.CODANALIZANOD);
      END IF;
    END LOOP;

    -- STINGERE
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE);
      END IF;
    END LOOP;


-- nir-uri
  DELETE FROM NIRSER WHERE
  CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID)) AND
  CODNIRSER NOT IN ( SELECT CodNirSer FROM TMP_NIRSER);


  FOR V_REC IN (SELECT CODNIRSTOC
                FROM NIRSTOC WHERE
                CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID) and
                CODNIRSTOC NOT IN ( SELECT CodNirStoc FROM TMP_NIRSTOC) ) LOOP
    DELETE NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE REZERVATS WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  delete from nirstoc1 where codnirstoc in
  (select codnirstoc FROM NIRSTOC WHERE
  CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID) and
  CODNIRSTOC NOT IN ( SELECT CodNirStoc FROM TMP_NIRSTOC));

-- inainte de steregere din LIVR reactivez numerele
  FOR V_REC IN (SELECT * FROM NIR  WHERE ( CodIntr = RecId AND CodNIR NOT IN ( SELECT  CodNIR FROM TMP_NIR )))
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
  END LOOP;

  DELETE FROM NIR WHERE ( CodIntr = RecId AND CodNIR NOT IN ( SELECT  CodNIR FROM TMP_NIR ));

  FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP
    IF (NVL(v_Rec.CodNIR,0) &lt; 0) THEN
      BEGIN
        SELECT seq_NIR_CodNIR.Nextval into vcod FROM DUAL;
        INSERT INTO NIR ( CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat,Operat )
        VALUES (vCod, RecId,   v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest,      v_rec.Obs, v_rec.TipNIR, v_rec.Anulat, v_rec.Blocat,  v_rec.Operat );


        UPDATE TMP_NIRSTOC SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
        UPDATE TMP_NIR     SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
      END;
    ELSE
      BEGIN
        -- verific daca s-au schimbat CARNETELE de DOCUMENTE
        SELECT NVL(CARNETNIR, 0), NVL(NRNIR, 0) INTO OLDCARNETNIR, OLDNRNIR FROM NIR
        WHERE
        NVL(CodNIR,0) = NVL(v_rec.CodNIR,0);

        IF (OLDCARNETNIR &lt;&gt; 0)AND(OLDNRNIR &lt;&gt; 0)AND(V_REC.CARNETNIR &lt;&gt; OLDCARNETNIR OR V_REC.NRNIR &lt;&gt; OLDNRNIR)
        THEN
          PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETNIR, OLDNRNIR);
          PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETNIR);
        END IF;


        UPDATE NIR
        SET
          CarnetNIR = v_rec.CarnetNIR,
          NRNIR     = v_rec.NRNIR,
          DataNIR   = v_rec.DataNIR,
          Gest      = v_rec.Gest,
          Obs       = v_rec.Obs,
          TipNIR    = v_rec.TipNIR,
          Anulat    = v_rec.Anulat,
          Blocat    = v_rec.Blocat,
          Operat    = v_rec.Operat
        WHERE NVL(CodNIR,0) = NVL(v_rec.CodNIR,0);
      END;
    END IF;
  END LOOP;


-- Detail NIRSTOC

  FOR v_rec IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CodNirStoc ) LOOP

   IF v_rec.CODNIRSTOC &gt; 0  THEN
     UPDATE NIRSTOC SET
        CodNir       = v_rec.CodNir,
        CodIntr1     = v_rec.CodIntr1,
        CODDVI1      = v_rec.CODDVI1,
        CantNir      = v_rec.CantNir * v_rec.Paritate,
        CANTFURN     = v_rec.CANTFURN * v_rec.Paritate,
        UmSec        = v_rec.UmSec,
        CodObiect    = v_rec.CodObiect,
        CodIoArt     = nvl(v_rec.CodIoArt, 0),
--      Pret         = v_rec.Pret / v_rec.Paritate,
        Pret         = ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
        RotLei       = v_rec.RotLei,
        RotValuta    = v_rec.RotValuta,
        CODLOCATIE   = V_REC.CODLOCATIE,
        CANTUM1      = V_REC.CANTUM1,
        CANTUM2      = V_REC.CANTUM2,
        Adaos        = nvl(v_rec.Adaos, 0) / v_rec.Paritate,
        TVA          = v_rec.TVA,
        TipSerie     = v_rec.TipSerie,
        DISCLIKISTOC = v_rec.DISCLIKISTOC,
        SERIELOT     = V_REC.SERIELOT,
        CodLivr1     = v_rec.CodLivr1,
        Rest         = PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
        RestUM1      = PKG_INTRARI.GET_REST_STOC_UM1(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM1),
        RestUM2      = PKG_INTRARI.GET_REST_STOC_UM2(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM2),
        ProcentAdaos = v_rec.ProcentAdaos,
        Supliment    = v_rec.Supliment,
        SuplNeded    = v_rec.SuplNeded,
        TG           = (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
        PUMAXIMAL    = (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
        FURN         = aCODPART,
        DATAACHIZ    = (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR),
        TIPDOCACHIZ   = 5,
        D1            = v_rec.D1,
        D2            = v_rec.D2,
        D3            = v_rec.D3,
        PUVAL         = V_REC.PUVAL,
        EUDR_RN       = V_REC.EUDR_RN,
        EUDR_VN       = V_REC.EUDR_VN 
     WHERE CodNirStoc = v_rec.CodNirStoc ;

     aCodComanda1 := 0;


     FOR V_REC_COPII IN (SELECT * FROM NIRSTOC1 NS1 WHERE CODNIRSTOCORIG &lt;&gt; CODNIRSTOC AND CODNIRSTOCORIG = v_rec.CodNirSToc)
     loop
       UPDATE NIRSTOC
       SET
         EUDR_RN = V_REC.EUDR_RN,
         EUDR_VN = V_REC.EUDR_VN
       WHERE
         CODNIRSTOC = V_REC_COPII.CODNIRSTOC;  
     end loop;     



     update nirstoc1
     set
       pretmat = ROUND(v_rec.Pret / v_rec.Paritate, pkg_intrari.ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - nvl(v_rec.Adaos, 0) / v_rec.Paritate,
       Dinstoc = 1,
       tipdoc = aTIPDOCNirStoc1,
       CodComanda1 = aCodComanda1,
       dirty = 0
     where codnirstoc = v_rec.codnirstoc;


-- VERIFIF MODIFICARE PRET  MIFIX

       BEGIN
         SELECT COUNT(*) INTO NRMIFIX FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN NRMIFIX :=0;
       END;

       IF NRMIFIX &gt; 0 THEN
         aVALOARE :=  v_rec.Pret / v_rec.Paritate;

         FOR V_MIFIX1 IN
         (SELECT *
          FROM
            MIFIX1 MF1
          WHERE
            MF1.CODNIRSTOC = V_REC.CODNIRSTOC
            AND PRET &lt;&gt; aVALOARE
         )
         LOOP
           UPDATE MIFIX1
           SET
             PRET = aVALOARE
           WHERE
             CODMIFIX1 = V_MIFIX1.CODMIFIX1;


           UPDATE FISAMF
           SET
             PRETI = aVALOARE
           WHERE
             CODMIFIX = V_MIFIX1.CODMIFIX
             AND CODOPERATIE = 1;


           UPDATE JURNAL1
           SET
             DIRTY = 1
           WHERE
             CODDOC     = V_MIFIX1.CODMIFIX
             AND TIPDOC = 36
             AND AN * 12 + LUNA &gt;= V_MIFIX1.ANSTART * 12 +  V_MIFIX1.LUNASTART;
         END LOOP;
       END IF;

   ELSE
    SELECT seq_NIRSTOC_CodNirStoc.NEXTVAL INTO VCOD FROM DUAL;

    UPDATE TMP_NIR1 SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

    INSERT INTO NIRSTOC( CodNirStoc, CodNir, CodIntr1, CODDVI1, CantNir, CANTFURN, Umsec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, RESTUM1, RESTUM2,
    ProcentAdaos, SUPLIMENT,SuplNeded,
    D1,
    D2,
    D3,PUVAL,
    TG,
    PUMAXIMAL,
    FURN,
    DATAACHIZ,
    DISCLIKISTOC,
    SERIELOT,
    TIPDOCACHIZ,
    EUDR_RN,
    EUDR_VN )
    VALUES
    (vCOD, v_rec.CodNir, v_rec.CodIntr1, v_rec.CODDVI1, v_rec.CantNir * v_rec.Paritate, v_rec.CANTFURN * v_rec.Paritate, v_Rec.UmSec,  v_rec.CodObiect,  nvl(v_rec.CodIoArt, 0),
   -- v_rec.Pret / v_rec.Paritate,
    ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
    v_rec.Rotlei, v_REC.ROTVALUTA, V_REC.CODLOCATIE, V_REC.CANTUM1, V_REC.CANTUM2, v_rec.Adaos/ v_rec.Paritate,  v_rec.TVA,
     v_rec.TipSerie,  v_rec.CodLivr1,
     PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
     PKG_INTRARI.GET_REST_STOC_UM1(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM1),
     PKG_INTRARI.GET_REST_STOC_UM2(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM2),
     v_rec.ProcentAdaos, v_rec.Supliment,v_rec.SuplNeded,
     v_rec.D1,
     v_rec.D2,
     v_rec.D3,V_REC.PUVAL,
     (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
     (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
      aCODPART,
     (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR),
      V_REC.DISCLIKISTOC,
      V_REC.SERIELOT,
      5,
      V_REC.EUDR_RN,
      V_REC.EUDR_VN
      );

      INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      VALUES (vCod, pkg_list_base_utils.GETCODNIRSTOC_ORIG(vCod), aTIPDOCNirStoc1,
              CASE WHEN aTIPDOCNirStoc1 &lt; 0 THEN 0 ELSE ROUND(v_rec.Pret / v_rec.Paritate, pkg_intrari.ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - NVL(v_rec.Adaos, 0)/ v_rec.Paritate END,
              0, 1, 0);
   END IF;
  END LOOP;

-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP
    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;

    IF V_REC.CODNIRSER &lt; 0 THEN
      INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2, 
                                                                                   RESTUM1, RESTUM2, OBS, CodCertif, DATAPROD, STARE, TG, DATAPROD1, TG1) VALUES
      (SEQ_NIRSER_CODNIRSER.NEXTVAL, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, 
                                     V_REC.CANTUM2, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.OBS, V_REC.CodCertif, V_REC.DATAPROD, V_REC.STARE, V_REC.TG,  V_REC.DATAPROD1,  V_REC.TG1);
    ELSE
      UPDATE NIRSER
      SET
        CODNIRSER  = V_REC.CODNIRSER,
        CODNIRSTOC = V_REC.CODNIRSTOC,
        CODSERIE   = aCODSERIE,
        CANTNIR    = V_REC.CANTNIR * V_REC.PARITATE,
        CANTUM1    = V_REC.CANTUM1,
        CANTUM2    = V_REC.CANTUM2,
        OBS        = V_REC.Obs,
        Codcertif  = V_REC.Codcertif,
        DATAPROD   = V_REC.DATAPROD,
        STARE      = V_REC.STARE,
        TG         = V_REC.TG,
        DATAPROD1   = V_REC.DATAPROD1,
        TG1         = V_REC.TG1,
        REST       = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantNir * V_REC.PARITATE),
        RESTUM1    = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM1),
        RESTUM2    = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM2)
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    END IF;
  END LOOP;

-- Detail LIVR
    /* ATENTIE LA ORDINEA STERGERILOR DIN DETALII */


    DELETE LIVRVAL WHERE CODLIVR1 IN
    ( SELECT CODLIVR1 FROM LIVR1 WHERE
      CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID) AND
      CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1)
    );


    DELETE FROM LIVR1 WHERE
    CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID) and
    CODLIVR1 NOT IN ( SELECT CodLIVR1 FROM TMP_LIVR1);



-- inainte de steregere din LIVR reactivez numerele
    FOR V_REC IN (SELECT * FROM LIVR  WHERE ( CodIntr = RecId AND CodLIVR NOT IN ( SELECT  CodLIVR FROM TMP_LIVR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC     (V_REC.CARNETLIVR, V_REC.NRLIVR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
    END LOOP;

    DELETE FROM LIVR WHERE ( CodIntr = RecId AND CodLIVR NOT IN ( SELECT  CodLIVR FROM TMP_LIVR ));



    FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP

      IF (NVL(v_Rec.CodLIVR,0) &lt; 0 ) THEN
        BEGIN
          SELECT seq_LIVR_CodLIVR.Nextval into vcod FROM DUAL;

          INSERT INTO LIVR ( CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLivr, Obs, TipLivr, Anulat, Blocat, Operat )
          VALUES ( vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR,
                   v_rec.DataLIVR, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat, v_rec.Blocat,  v_rec.Operat );


          UPDATE TMP_LIVR1 SET CODLIVR = vCod  WHERE CODLIVR = v_rec.CODLIVR;

        END;
      ELSE
        BEGIN
          -- verific daca s-au schimbat CARNETELE de DOCUMENTE
          SELECT NVL(CARNETLIVR, 0), NVL(NRLIVR, 0) INTO OLDCARNETLIVR, OLDNRLIVR FROM LIVR
          WHERE
          NVL(CodLIVR,0) = NVL(v_rec.CodLIVR,0);

          IF (OLDCARNETLIVR &lt;&gt; 0)AND(OLDNRLIVR &lt;&gt; 0)AND(V_REC.CARNETLIVR &lt;&gt; OLDCARNETLIVR OR V_REC.NRLIVR &lt;&gt; OLDNRLIVR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETLIVR, OLDNRLIVR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETLIVR);
          END IF;


          UPDATE LIVR
          SET
            CarnetLIVR = v_rec.CarnetLIVR,
            NRLIVR     = v_rec.NRLIVR,
            DataLIVR   = v_rec.DataLIVR,
            Obs        = v_rec.Obs,
            TipLIVR    = v_rec.TipLIVR,
            Anulat    = v_rec.Anulat,
            Blocat    = v_rec.Blocat,
            Operat    = v_rec.Operat
          WHERE NVL(CodLIVR,0) = NVL(v_rec.CodLIVR,0);
        END;
      END IF;
    END LOOP;


-- Detail Livr1

-- stergerea celor ce au disparut e rezolvata mai sus

   FOR v_rec IN (SELECT * FROM TMP_LIVR1 ORDER BY CodLivr, CodIntr1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
        PRETINREG = PRETINREG / V_REC.PARITATE,
        PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;



     IF NVL(v_rec.CodLivr1, 0) &gt; 0 THEN
        UPDATE LIVR1 SET
          CodLivr    =  v_rec.CodLivr,
          CodIntr1   =  v_rec.CodIntr1,
          CodDVI1    =  v_rec.CodDVI1,
          CodNirStoc =  v_rec.CodNirStoc,
          Cant       =  v_rec.Cant * v_Rec.Paritate,
          CantUM1    =  v_rec.CantUM1,
          CantUM2    =  v_rec.CantUM2,
          UmSec      =  v_rec.UmSec
        WHERE
          CodLivr1 = v_rec.CodLivr1;
     ELSE
       SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

       INSERT INTO LIVR1
       (CodLivr1, CodLivr, CodIes1, CodIntr1, CodDVI1, CodNirStoc, Cant, CantUM1, CantUM2, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec)
       VALUES
       ( VCOD, v_Rec.CodLivr, v_Rec.CodIes1, v_Rec.CodIntr1, v_Rec.CODDVI1, v_Rec.CodNirStoc,
         v_Rec.Cant * v_Rec.Paritate, v_Rec.CantUM1, v_Rec.CantUM2,
         v_Rec.CodNirSer, v_Rec.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA,V_REC.PMPVALUTADOC, v_Rec.UmSec );
     END IF;
   END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_LIVRVAL) LOOP
      IF V_REC.CODLIVRVAL &lt; 0 THEN
        INSERT INTO LIVRVAL(CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
        VALUES (SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,  V_REC.CODLIVR1, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.GEST, V_REC.PRETINREG, V_REC.PRETACHIZ, V_REC.TVANEEX);
      ELSE
        UPDATE LIVRVAL
        SET
          CODLIVR1   = V_REC.CODLIVR1,
          CODOBIECT  = V_REC.CODOBIECT,
          CODIOART   = V_REC.CODIOART,
          GEST       = V_REC.GEST,
          PRETINREG  = V_REC.PRETINREG ,
          PRETACHIZ  = V_REC.PRETACHIZ ,
          TVANEEX    = V_REC.TVANEEX
        WHERE
          CODLIVRVAL = V_REC.CODLIVRVAL;
      END IF;
    END LOOP;



 UPDATE NIRSTOC NS
 SET
   REST    = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
   RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
   RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
 WHERE NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1 UNION SELECT CodNirStoc FROM TMP_LIVR1_INITIAL);

 UPDATE NIRSER NS
 SET
   REST    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
   RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
   RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
 WHERE
 NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1 UNION SELECT CodNirStoc FROM TMP_LIVR1_INITIAL);


-- detail JURNAlL1
DELETE FROM JURNAl1 WHERE TIPDOC = TIPINTR AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOAREGRUP   = v_rec.VALOAREGRUP,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = v_rec.CODANALIZANOD
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT, v_rec.CODANALIZANOD);
 END IF;
END LOOP;


-- detail JURNAL
DELETE FROM JURNAL WHERE TIPDOC = TIPINTR AND CODDOC = RECID AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC      = V_REC.CODDOC,
    TIPDOC      = V_REC.TIPDOC,
    INDEXLOCAL  = V_REC.INDEXLOCAL,
    CONTD       = V_REC.CONTD,
    CONTC       = V_REC.CONTC,
    GEST        = V_REC.GEST,
    VALOARE     = V_REC.VALOARE,
    VALOAREV    = V_REC.VALOAREV,
    VALOAREGRUP = v_rec.VALOAREGRUP,
    OBS         = V_REC.OBS,
    AN          = V_REC.AN,
    LUNA        = V_REC.LUNA,
    SUBUNITATEA = V_REC.SUBUNITATEA,
    CODCENTRU   = v_rec.CODCENTRU,
    DATADOC     = V_REC.DATADOC,
    DOCUMENT    = V_REC.DOCUMENT,
    CODANALIZANOD = v_rec.CODANALIZANOD
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, RECID, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,v_rec.CODANALIZANOD);
 END IF;
END LOOP;



ELSE -- INSERT
  SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO RECID FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI&apos;, RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    --WINMADMIN.PKG_USERFIRME.PostLog(&apos;DVI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO  INTRARI
   (CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, ProRata, CODCONTRACT, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, CODFISCAL, MONEDA, CURS,userid,datacreare, TIPTRANZACTIE, NRI, ExclusPlata, DataTVA, FaraReg, TVAIncasare, TIPFACTURA, CODANALIZA, STADIUWMS,
   DATAREFSCAD, CODLOCATIE,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, is_etransp, MODTRANSP, DELEGAT,CODAUTO,NRTRANSP)
   ( SELECT RECID,  TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, SERIADOC, DATADOC, PARTENER, NRAVIZ, CARNETDOC, VALDOC, TVADOC, MAJORARI, AN, LUNA, OBS, SATELIT, COMPLEX, ProRata, CODCONTRACT, CONTSUPLIM, VALSUPLIM, TIPREPSUPLIM, TIPTVA, SUBUNITATEA, CODFISCAL, MONEDA, CURS, pkg_globals.userid,systimestamp, TIPTRANZACTIE, NRI, ExclusPlata, DataTVA, FaraReg, TVAIncasare, TIPFACTURA, CODANALIZA, STADIUWMS,
            DATAREFSCAD, CODLOCATIE,TIPLIVRARE, NATURATRANZ, TipSAFT, TipET, is_eTransp, MODTRANSP, DELEGAT,CODAUTO,NRTRANSP
     FROM TMP_INTRARI) ;


  UPDATE TMP_GENERAL SET CODDOC = RECID WHERE SEMNIFICATIE IN (100, 110, 111, 140);

-- Detail INTRARI1
  FOR v_rec IN ( SELECT * FROM TMP_INTRARI1 ORDER BY IndexLocal ) LOOP

    SELECT seq_INTRARI1_CodIntr1.Nextval INTO vCOD FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI1&apos;, vCOD, v_Rec.Codintr1);

    if v_Rec.Tiplinie = &apos;S&apos; and pkg_categconst.ESTEIMBUNATATIREMIFIX(v_rec.contserv) &gt; 0 and
       PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
      for v_xxx in (select mfix1.codnirstoc
                    from mifix1 mfix1
                    where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
        insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
        values(vCod, v_xxx.codnirstoc, v_rec.cant * v_rec.pu * aCurs);
        exit;
      end loop;
    end if;

    INSERT INTO INTRARI1 ( CodIntr1, CodIntr, IndexLocal,TipLinie,Umsec,An,Luna,ContServ, CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA, AdDim,RestFact,NrCertif, COEFDISCMAJ, TG,PUMaximal, PROCADAOS, PURidicata, CODOBLIGSTORNO, CURSFACTURAAVANS, CODMIFIX, CODCENTRU, RESTIMBMF, OBS,CODANALIZANOD, PRELUAT, CODNIMOB,
                           CODCMDINT1, GESTPRODAVIZSUB, CODAUTO)
    VALUES
     ( vCod, RecId, v_Rec.IndexLocal,  v_Rec.TipLinie,  v_Rec.Umsec,  v_Rec.An,  v_Rec.Luna,  v_Rec.ContServ, V_REC.CONTDISCOUNT, v_Rec.GestAct,  v_Rec.CodObiect,
       v_Rec.PretOrig / NVL(v_Rec.Paritate, 1), v_Rec.PU / NVL(v_Rec.Paritate, 1),  v_Rec.Cant * NVL(v_Rec.Paritate, 1), v_Rec.TVA, v_rec.AdDim,

       CASE
         WHEN TIPINTR = 2 AND v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND aOperat = 1 AND aAnulat = 0 THEN v_Rec.Cant * v_Rec.Paritate
         WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
         ELSE 0
       END,
       v_Rec.NrCertif, V_REC.COEFDISCMAJ,  v_Rec.TG,  v_Rec.PUMaximal, V_REC.PROCADAOS, v_Rec.PURidicata, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS,
       V_REC.CODMIFIX, V_REC.CODCENTRU,
       CASE
         WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 THEN V_REC.PU * V_REC.CANT * aCURS
         ELSE 0
       END,
       V_REC.obs,
       v_rec.CODANALIZANOD,
       V_REC.PRELUAT, V_REC.CODNIMOB, V_REC.CODCMDINT1, V_REC.GESTPRODAVIZSUB, V_REC.CODAUTO
     );

    UPDATE TMP_DVI1     SET CODINTR1  = vCod WHERE CODINTR1 = v_rec.CodIntr1;
    UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_INTRARI1 SET CODINTR1  = vCod WHERE CODINTR1 = v_rec.CodIntr1;

  END LOOP;



-- detail DVI
 FOR V_REC IN (SELECT * FROM TMP_DVI) LOOP
   SELECT SEQ_DVI_CODDVI.NEXTVAL INTO VCOD FROM DUAL;
   UPDATE TMP_DVI1 SET CODDVI = VCOD;
   UPDATE TMP_GENERAL SET CODDOC = VCOD WHERE SEMNIFICATIE = 130;

   INSERT INTO DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE,
   FISAVAMA, TAXEPECHELT, TipRepSuplim, ValSuplim, ContSuplim, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA, ExclusPlata, FaraReg, TVAIncasare, SeriaDoc)
   VALUES
   (VCOD, RECID, V_REC.CODVAMA, V_REC.NRDOC, V_REC.DATADOC, V_REC.CONTCHELT, V_REC.CONTTVA, V_REC.TAXEINCLUSE,
    V_REC.FISAVAMA, V_REC.TAXEPECHELT, V_REC.TipRepSuplim, V_REC.ValSuplim, V_REC.ContSuplim, V_REC.OBS, V_REC.TIPIMPORT, V_REC.VALDOCVAMA, V_REC.TVADOCVAMA, v_rec.ExclusPlata, V_REC.FaraReg, 
    v_rec.TVAIncasare, v_rec.Seriadoc);
 END LOOP;

-- detail DVI1
 FOR V_REC IN (SELECT * FROM TMP_DVI1 ORDER BY INDEXLOCAL) LOOP
   SELECT SEQ_DVI1_CODDVI1.NEXTVAL INTO VCOD FROM DUAL;
   update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.coddvi1;
   UPDATE TMP_NIRSTOC SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
   UPDATE TMP_LIVR1   SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;
   UPDATE TMP_DVI1    SET CODDVI1 = VCOD WHERE CODDVI1 = V_REC.CODDVI1;

   INSERT INTO DVI1(CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA, TVANEDED, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, VALOARETAXA)
   VALUES (VCOD, V_REC.CODDVI, V_REC.CODINTR1, V_REC.TIPLINIE, V_REC.INDEXLOCAL,
           V_REC.PRETIMPORT / NVL(V_REC.PARITATE, 1),
           V_REC.PUMAXIMAL / NVL(V_REC.PARITATE, 1),
           V_REC.CONTDISCOUNT,
           V_REC.PRETVALUTA / NVL(V_REC.PARITATE, 1),
           V_REC.TVANEDED,
           V_REC.PRETORIGINAL,
           V_REC.TVA,
           V_REC.UMSEC,
           V_REC.ADDIM,
           V_REC.CODOBIECT,
           V_REC.CANT * NVL(V_REC.PARITATE, 1),
           CASE
             WHEN V_REC.TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) THEN V_REC.VALOARE
             ELSE 0
           END
   );
 END LOOP;



-- Detail GENERAL -- MUSAI DUPA DVI PENTRU CA CODDOC = CODDVI LA INREGISTRARI CU SEMNIFICATIE = 130
   FOR V_REC IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;

     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS,  TVA, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg)
     VALUES (VCOD, TIPINTR, V_REC.CODDOC, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS,  v_rec.TVA, V_REC.PROCTVAAVANS, v_rec.ExclusPlata, v_rec.DataTVA, V_REC.FaraReg);

   END LOOP;

-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
      --  TMP_INTRARI1 este deja postat; trebuie sa sincronizez cu originalul UPDATE TMP_INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;
     UPDATE INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODINTR = RECID AND CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT,CODANALIZANOD)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 111 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA,V_REC.CODCENTRU, V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0),v_rec.CODANALIZANOD );
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;




 INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT )(SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);

-- Detail NIR
  FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP
    SELECT seq_NIR_CodNIR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO NIR (CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest, v_rec.Obs, v_rec.TipNIR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_NIRSTOC SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
    UPDATE TMP_NIR     SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
  END LOOP;


-- Detail NIRSTOC
  FOR v_rec IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CodNIRSTOC ) LOOP
    SELECT seq_NIRSTOC_CodNirStoc.Nextval INTO vCod from DUAL;

    INSERT INTO NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CODDVI1, CantNir, CANTFURN, Umsec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, RESTUM1, RESTUM2, ProcentAdaos,
    SUPLIMENT,SuplNeded,
    TG,
    PUMAXIMAL,
    FURN,
    DATAACHIZ,
    TIPDOCACHIZ,
    DISCLIKISTOC,
    SERIELOT,
    D1,
    D2,
    D3,
    PUVAL,
    EUDR_RN,    
    EUDR_VN    
    )
    VALUES
    (vCOD, v_rec.CodNir, v_rec.CodIntr1, v_rec.CODDVI1, v_rec.CantNir * v_rec.Paritate, v_rec.CANTFURN * v_rec.Paritate, v_Rec.UmSec,  v_rec.CodObiect,  nvl(v_rec.CodIoArt, 0),
    --v_rec.Pret / v_rec.Paritate,
    ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
    v_rec.Rotlei, v_REC.ROTVALUTA, V_REC.CODLOCATIE, V_REC.CANTUM1, V_REC.CANTUM2, v_rec.Adaos/ v_rec.Paritate,  v_rec.TVA,
     v_rec.TipSerie,  v_rec.CodLivr1,
     PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, vCOD, v_rec.CantNir * v_rec.Paritate),
     PKG_INTRARI.GET_REST_STOC_UM1(v_Rec.CodNir,vCOD, v_rec.CantUM1),
     PKG_INTRARI.GET_REST_STOC_UM2(v_Rec.CodNir, vCOD, v_rec.CantUM2),
     v_rec.ProcentAdaos, v_rec.Supliment,v_rec.SuplNeded,
     (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
     (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
      aCODPART,
     (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR),
      5,
      V_REC.DISCLIKISTOC,
      V_REC.SERIELOT,
      V_REC.D1,
      V_REC.D2,
      V_REC.D3,
      V_REC.PUVAL,
      V_REC.EUDR_RN,    
      V_REC.EUDR_VN    
      );

      INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      VALUES (vCod, pkg_list_base_utils.GETCODNIRSTOC_ORIG(vCod), aTIPDOCNirStoc1,
              CASE WHEN aTIPDOCNirStoc1 &lt; 0 THEN 0 ELSE ROUND(v_rec.Pret / v_rec.Paritate, pkg_intrari.ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - NVL(v_rec.Adaos, 0)/ v_rec.Paritate END,
              0, 1, 0);
/*
    INSERT INTO  NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CODDVI1, CantNir, CANTFURN, UmSec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE,Adaos, TVA, TipSerie, CodLivr1, Rest, ProcentAdaos, SUPLIMENT,
    TG, PUMAXIMAL)
    VALUES
    (vCod, v_Rec.CodNir, v_Rec.CodIntr1, V_REC.CODDVI1, v_Rec.CantNir * v_Rec.Paritate,  v_Rec.CANTFURN * v_Rec.Paritate, v_Rec.Umsec, v_Rec.CodObiect, nvl(v_Rec.CodIoArt, 0), v_Rec.Pret / v_Rec.Paritate, v_Rec.RotLei, v_rec.ROTVALUTA, V_REC.CODLOCATIE, v_Rec.Adaos, v_Rec.TVA, v_Rec.TipSerie, v_Rec.CodLivr1,

      PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
      v_Rec.ProcentAdaos, V_REC.SUPLIMENT,
     (SELECT TG FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1)),
     (SELECT PUMAXIMAL FROM TMP_INTRARI1 WHERE CODINTR1 = (SELECT CODINTR1 FROM TMP_DVI1 WHERE CODDVI1 = V_REC.CODDVI1))
      );
*/
    UPDATE TMP_NIR1    SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    UPDATE TMP_NIRSER  SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    UPDATE TMP_NIRSTOC SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;


  END LOOP;
-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;

    INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2,
                                                                                  RESTUM1, RESTUM2, OBS, CodCertif, DATAPROD, STARE, TG, DATAPROD1, TG1) VALUES
    (SEQ_NIRSER_CODNIRSER.NEXTVAL, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1,
                                                      V_REC.CANTUM2, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.OBS, V_REC.CodCertif, V_REC.DATAPROD, V_REC.STARE, V_REC.TG,  V_REC.DATAPROD1, V_REC.TG1);
  END LOOP;

-- LIVR
  FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP
    SELECT seq_LIVR_CodLIVR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO LIVR (CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLIVR, Obs, TipLIVR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR, v_rec.DataLivr, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_LIVR1 SET CODLIVR = vCod WHERE CODLIVR = v_rec.CODLIVR;
  END LOOP;

-- LIVR1
/*
   INSERT INTO LIVR1
   (CodLivr1, CodLivr, CodIes1, CodIntr1, CODDVI1, CodNirStoc, Cant, CantUM1, CantUM2, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec)
   (SELECT  seq_LIVR1_CodLivr1.Nextval, CodLivr, CodIes1, CodIntr1, CODDVI1, CodNirStoc,  Cant * Paritate, CantUM1, CantUM2, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec from TMP_LIVR1);
*/
-- LIVR1
   FOR V_REC IN (SELECT * FROM TMP_LIVR1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;


     SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;


     INSERT INTO LIVR1 (CODLIVR1, CODLIVR, CODIES1, CODINTR1,  CODDVI1, CODNIRSTOC, CANT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2)
     VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODDVI1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC, V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2 );
   END LOOP;

   INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
   SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;

-- actualizez stocurile din care livrez

   UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC(NS.CodNir, NS.CodNirStoc, NS.CantNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CodNir, NS.CodNirStoc, NS.CantUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CodNir, NS.CodNirStoc, NS.CantUM2)
   WHERE
   NS.CodNirStoc in (SELECT CodNirStoc FROM TMP_LIVR1);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
     NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1);


  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL1);



  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);


END IF;

  pkg_pretprod.SetDirtyStructura;

UPDATE COMANDA1 c1
SET
 c1.RestAcceptat = c1.CantAcceptat -
             ( SELECT NVL(SUM(IL.CANT), 0)
               FROM
                INTRLINK IL
                LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
               WHERE
               IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
               )
WHERE
c1.CodComanda1 IN (SELECT CODLINIECOMANDA FROM TMP_INTRLINK UNION SELECT CODLINIECOMANDA  FROM TMP_INTRLINK_INITIAL);



FOR V_REC IN (SELECT * FROM LIVR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;


FOR V_REC IN (SELECT * FROM NIR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
END LOOP;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;
 END LOOP;



-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
  UPDATE OBLIGPIF O
  SET
   REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE

     UNION ALL

     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );


  IF aTIPFACTURA = 10 THEN
    UPDATE INTRARI1 I1
    SET
     I1.RestFact = i1.Cant -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIEAVIZ = I1.CodINTR1 AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10) ) AND II.OPERAT = 1 AND II.ANULAT = 0
                   )+
                   (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                    FROM
                      INTRARI1 AE1,
                      INTRARI  AE
                    WHERE
                      AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                     AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0)
    WHERE
    I1.CodINTR1 IN
    (SELECT CODLINIEAVIZ FROM TMP_INTRLINK UNION SELECT CODLINIEAVIZ FROM TMP_INTRLINK_INITIAL);
  END IF;

  IF aCODMONEDA &lt;&gt; 0 THEN
    FOR V_REC IN
    (
      SELECT
        G.CODGENERAL,
        OL.VALOARE AS VAL_IN,
        O.VALOARE  AS VAL_OUT
      FROM
         TMP_OBLIGPIF_INITIAL OL
         LEFT OUTER JOIN TMP_OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF,
         GENERAL       G
      WHERE
        G.CODGENERAL = OL.CODGENERAL
     )
     LOOP
       IF (V_REC.VAL_IN &lt;&gt; V_REC.VAL_OUT)OR(CURS_IN &lt;&gt; aCURS) THEN
         FOR V_RECREG IN
         (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
         LOOP
           UPDATE JURNAL1
           SET
             DIRTY = 1
           WHERE
             TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
         END LOOP;
       END IF;
     END LOOP;
  END IF;

  IF aTIPFACTURA = 10 THEN
-- actualizez modif pu fact la aviz
   FOR V_REC IN ( SELECT CodLinieAviz FROM Tmp_Intrlink WHERE ActualizPret = 1 )
    LOOP
      PKG_Jurnal.setDirtyDVIAE(V_REC.CODLINIEAVIZ, aCurs);
    END LOOP;
  ELSE
-- actualizez modif pret nirstoc
    FOR V_REC IN ( SELECT CodNirStoc, Pret FROM Tmp_NIRSTOC WHERE ActualizPret = 1 )
     LOOP
       PKG_Jurnal.setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.Pret, &apos;0&apos;, 0);
     END LOOP;
  END IF;

  --pun la loc rezervari initiale
  FOR V_REC IN
  (
    SELECT CODNIRSER FROM NIRSER WHERE
    CODNIRSTOC IN ( SELECT CODNIRSTOC FROM NIRSTOC
                    WHERE CODNIR IN ( SELECT CODNIR FROM NIR
                                      WHERE CODINTR = RECID))
   )
  LOOP
    DELETE FROM REZERVATS WHERE CODNIRSER = V_REC.CODNIRSER AND NVL(CODCOMANDA1F,0) &gt; 0;
  END LOOP;

  FOR V_REC IN
  (
    SELECT CODNIRSTOC FROM NIRSTOC WHERE
    CODNIR IN ( SELECT CODNIR FROM NIR
                WHERE CODINTR = RECID)
  )
  LOOP
    DELETE FROM REZERVATS WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND NVL(CODCOMANDA1F,0) &gt; 0;
  end loop;

  for v_linkini in ( select CODLINIECOMANDA, CodIntr1 from tmp_intrlink_initial) loop
    -- pentru toate liniile comanda furnizor de pe acest document
    UPDATE REZERVATS set Rest = RezervatINI
    where CODCOMANDA1F = v_linkIni.CODLINIECOMANDA
          AND CodNIRStoc = 0;
    for v_link in ( select CodIntr1, CODLINIECOMANDA from IntrLink
                    where CODLINIECOMANDA = v_linkini.CODLINIECOMANDA
                          AND CODINTR1 &lt;&gt; v_linkini.CODINTR1
                   )
    loop
      begin
        select Sum(CantNIR) into TotSosit
        from (
              SELECT
                CASE WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0) ELSE  NVL(NS.CANTNIR, 0) END CANTNIR
              FROM
                NIRSTOC NS
                INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                LEFT JOIN DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
                LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
              WHERE
                DVI1.CODINTR1 = v_link.Codintr1 AND NIR.OPERAT = 1
             );
      EXCEPTION WHEN OTHERS THEN TotSosit := 0;
      end;
       -- in TotSosit am total cant sosita pt cererea
      if TotSosit &lt;&gt; 0 then
        for v_Rez in ( select R.CodRezervatS, R.REST, R.REZERVATINI
                       from  RezervatS R, Intrari1 I1
                       where I1.CodIntr1 = v_Link.Codintr1
                             AND R.CODCOMANDA1F = v_link.CODLINIECOMANDA
                             AND R.CODObiect    = I1.CODObiect
                             AND R.CodNIRStoc   = 0
                       order By CodComanda1 desc)
        loop
          if TotSosit &lt;&gt; 0 then
            if TotSosit &lt; v_REZ.REST then
              update REZERVATS set Rest = Rest - TotSosit where CodRezervats = v_Rez.CodRezervatS;
              TotSosit := 0;
            else
              TotSosit := TotSosit - v_REZ.REST ;
              update REZERVATS set Rest = 0 where CodRezervats = v_Rez.CodRezervatS;
            end if;
          end if;
        end loop;
      end if;
    end loop;
  end loop;

  for v_link in ( select CODLINIECOMANDA, CodIntr1 from tmp_intrlink)
  loop -- pentru toate liniile comanda furnizor de pe acest document
    for v_NS in (
                 SELECT
                   NS.Codnirstoc, NVL(NSE.CodNIRSer,0) CodNIRSer , NS.CodObiect,
                   CASE WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0) ELSE  NVL(NS.CANTNIR, 0) END CANTNIR,
                   U1.Paritate
                 FROM NIRSTOC NS
                      INNER JOIN NUM1 U1 ON U1.CODUM1 = NS.UMSEC 
                      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                      LEFT JOIN DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
                      LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
                 WHERE DVI1.CODINTR1 = v_link.Codintr1 AND NIR.OPERAT = 1
                )
    loop
      -- in TotSosit am total cant sosita pt cererea
      TotSosit := V_NS.CantNIR;
      if TotSosit &lt;&gt; 0 then
        for v_Rez in ( select R.CodRezervatS, R.CodComanda1, R.CodObiect, R.UMSec, R.REST, R.REZERVATINI
                       from  RezervatS R
                       where R.CODCOMANDA1F     = v_link.CODLINIECOMANDA
                             AND R.CODObiect    = v_NS.CODObiect
                             AND R.CodNIRStoc   = 0
                       order By R.CodComanda1 asc)
        loop
          if TotSosit &lt;&gt; 0 then
            if TotSosit &lt; v_REZ.REST then
              update REZERVATS set Rest = Rest - TotSosit where CodRezervats = v_Rez.CodRezervatS;
              begin
                Select Count(*) into Nr from Rezervats
                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                      AND CODComanda1  = v_REZ.CODComanda1
                      AND CodNIRStoc   = v_NS.CodNIRStoc
                      AND CodNIRSer    = v_NS.CodNIRSer;
              EXCEPTION WHEN OTHERS THEN Nr := 0;
              end;
              if NR = 0 then
                INSERT INTO REZERVATS
                 ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                   REST, REZERVATINI,
                   UMSEC, codcomanda1f, codobiect)
                VALUES
                 ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                   TotSosit, TotSosit,
                   v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect);
              else
                UPDATE REZERVATS
                SET REST = REST + TotSosit, REZERVATINI = REZERVATINI + TotSosit
                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                      AND CODComanda1  = v_REZ.CODComanda1
                      AND CodNIRStoc   = v_NS.CodNIRStoc
                      AND CodNIRSer    = v_NS.CodNIRSer;
              end if;
              TotSosit := 0;
            else
              TotSosit := TotSosit - v_REZ.REST ;
              update REZERVATS set Rest = 0 where CodRezervats = v_Rez.CodRezervatS;

              begin
                Select Count(*) into Nr from Rezervats
                       where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                             AND CODComanda1  = v_REZ.CODComanda1
                             AND CodNIRStoc   = v_NS.CodNIRStoc
                             AND CodNIRSer    = v_NS.CodNIRSer;
                EXCEPTION WHEN OTHERS THEN Nr := 0;
              end;
              if NR = 0 then
                INSERT INTO REZERVATS
                 ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                   REST, REZERVATINI,
                   UMSEC, codcomanda1f, codobiect)
                VALUES
                 ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                  v_REZ.REST, v_REZ.REST,
                  v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect);
              else
                UPDATE REZERVATS
                SET REST = REST + v_REZ.REST, REZERVATINI = REZERVATINI + v_REZ.REST
                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                            AND CODComanda1  = v_REZ.CODComanda1
                            AND CodNIRStoc   = v_NS.CodNIRStoc
                            AND CodNIRSer    = v_NS.CodNIRSer;
              end if;
            end if;
          end if;
        end loop;
      end if;
    end loop;
  end loop;

   LockStocFaraCertif := &apos;2&apos;;
   BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;LockStocFaraCertif&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO LockStocFaraCertif FROM DUAL;
     EXCEPTION WHEN OTHERS THEN LockStocFaraCertif := &apos;2&apos;;
   END;

   IF LockStocFaraCertif = &apos;1&apos; THEN
     FOR V_REC IN
     (SELECT NSE.CODNIRSER
      FROM
        TMP_NIRSTOC NS,
        NIRSER NSE,
        NARTOBJ O,
        NART A
      WHERE
        NSE.CODNIRSTOC   = NS.CODNIRSTOC
        AND O.CODOBIECT  = NS.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
        AND NVL(A.MUSAICALITATE, 0) = 1
        AND NVL(NSE.CODCERTIF, 0) = 0
     )
     LOOP
       UPDATE NIRSER
       SET
         STARE = 4
       WHERE
         CODNIRSER = V_REC.CODNIRSER;
     END LOOP;
   END IF;



  PKG_GLOBALS.MarkDirtyJurnal;
  NotifyModif(Operation, RecId, &apos;INTRARI&apos;);

  IF aTIPFACTURA = 10 THEN
    CHECK_MODICANT_DVILAAVIZ(RECID);
  END IF;

  IF aOPERAT = 0 THEN
    DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIntr);
    DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIntr;
  END IF;
	
  PKG_SAFT.UpdateTaxDecl(0, RecId);
  
  
  DELETE FROM GENERAL G
  WHERE
    TIPDOC = TIPINTR
    AND CODDOC = RECID
    AND (SELECT COUNT(*) FROM OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL) = 0;

  
  PKG_CFGTABLES.EXT_POSTRECORDS(TIPIntr, OPERATION);
  
  COMMIT;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    commit;
    begin
      select count(*) into aCount from tmp_manevra_intr1;
    exception when others then
      aCount := 0;
    end;
    commit;
    if aCount &gt; 0 then pkg_intrari.GenereazaModificareDePretMifix(aDataDoc, aAn, aLuna, aSubunitatea); end if;
  end if;

  EXCEPTION WHEN OTHERS THEN BEGIN
    ROLLBACK;
    RAISE;
  END;
END;
END;


END PKG_DVI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EDITCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7043D9D0D5EB74800E5D1DE41FDA0345A947D22</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EDITCONST IS
PROCEDURE SP_GOTORECORD (RecId IN NUMBER) IS
BEGIN
 --MASTER CATEGCONST
 INSERT INTO TMP_CATEGCONST(CODCATEG,DENUMIRE,INDEXLOCAL,TIPCATEG)
 
   
 (SELECT CODCATEG,DENUMIRE,INDEXLOCAL,DECODE ( TIPCATEG, &apos;U&apos;,&apos;Utilizator&apos;,
                                                         &apos;G&apos;,&apos;General&apos;
                                                                              
                                              )  
   FROM CATEGCONST WHERE CODCATEG=RECID) ORDER BY DENUMIRE;
 
 -- DETAIL CONST1
 INSERT INTO TMP_CONST1 (CODCONST1,CODCATEG,INDEXLOCAL,SIMBOL,DENUMIRE,TIP)
 (SELECT CODCONST1,CODCATEG,INDEXLOCAL,SIMBOL,DENUMIRE,TIP FROM CONST1 WHERE CODCATEG=RECID)ORDER BY DENUMIRE;
  
 -- DETAIL CONSTLUNA
 INSERT INTO TMP_CONSTLUNA (CODCONSTLUNA,CODCONST1,ANSTART,LUNASTART,USERID)
        (SELECT CODCONSTLUNA,CODCONST1,ANSTART,LUNASTART,USERID FROM CONSTLUNA WHERE CODCONST1 IN ( SELECT CODCONST1 FROM TMP_CONST1))ORDER BY ANSTART,LUNASTART DESC;
 
-- DETAIL CONSTVALPOS   
  INSERT INTO TMP_CONSTVALPOS (IDX,VALPOSIBILE,CODCONSTLUNA,COD)
         (SELECT IDX,VALPOSIBILE,CODCONSTLUNA,COD FROM CONSTVALPOS WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM TMP_CONSTLUNA CL , TMP_CONST1 C1 
                                                                                           WHERE CL.CODCONST1=C1.CODCONST1  ))ORDER BY IDX;
  

	INSERT INTO TMP_CONSTVAL (VALOARE,CODCONSTLUNA)
         (SELECT VALOARE,CODCONSTLUNA FROM CONSTVAL WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM TMP_CONSTLUNA CL , TMP_CONST1 C1 
                                                                            WHERE CL.CODCONST1=C1.CODCONST1  ));
COMMIT;
 
END;
PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
 TMP NUMBER(10);
 BEGIN
 SELECT CODCATEG INTO TMP FROM CATEGCONST  WHERE CODCATEG=RECID FOR UPDATE NOWAIT; 
 END; 
 
PROCEDURE SP_DELETERECORD (RecId IN NUMBER) IS
BEGIN
 SP_LOCKRECORD(RecId);
 DELETE FROM CONSTVALPOS WHERE COD IN(SELECT COD FROM CONSTVALPOS WHERE
                                                  CODCONSTLUNA IN(SELECT CODCONSTLUNA FROM CONSTLUNA 
                                                                   WHERE CODCONST1 IN (SELECT CODCONST1 FROM CONST1 WHERE CODCATEG=RECID)
                                                                  )
                                                 );                         
                                                 
 DELETE FROM CONSTVAL WHERE CODCONSTLUNA IN(SELECT CODCONSTLUNA FROM CONSTLUNA 
                                                                   WHERE CODCONST1 IN (SELECT CODCONST1 FROM CONST1 WHERE CODCATEG=RECID)
                                                                  );
 
 DELETE FROM CONSTLUNA WHERE CODCONSTLUNA IN( SELECT CODCONSTLUNA FROM CONSTLUNA 
                                             WHERE CODCONST1 IN( SELECT CODCONST1 FROM CONST1 WHERE CODCATEG=RECID)
                                             ); 
                                                                                      
                                             
 DELETE FROM CONST1 WHERE CODCATEG =RECID;
 DELETE FROM CATEGCONST WHERE CODCATEG=RECID ;
 NotifyModif(2, RecId, &apos;CATEGCONST&apos;);
 COMMIT;
END;
PROCEDURE SP_INSERTRECORD IS
BEGIN
 INSERT INTO TMP_CATEGCONST FIELDS (CODCATEG) VALUES (0);
 COMMIT;
END;
PROCEDURE SP_POSTRECORDS (Operation IN NUMBER, RecId OUT NUMBER)IS
V_CODCONST1 NUMBER (10);
V_CODCONSTLUNA NUMBER(10);
TEST_CODCONST1 NUMBER (10):=0;
TEST_CODCONSTLUNA NUMBER (10):=0;
BEGIN
 IF OPERATION=0 THEN -- UPDATE
 --MASTER CATEGCONST
   
   SELECT CODCATEG INTO RECID FROM TMP_CATEGCONST;
   UPDATE CATEGCONST SET (DENUMIRE,INDEXLOCAL,TIPCATEG )=
  (SELECT DENUMIRE,INDEXLOCAL,DECODE ( TIPCATEG, &apos;Utilizator&apos;,&apos;U&apos;,
                                                 &apos;General&apos;,&apos;G&apos;
                                                                              
                                      )  
   
   FROM TMP_CATEGCONST) WHERE CODCATEG=RECID;
--------------------------------STREG INREGISTRARI DIN DETALII---------------------------------
--DETAIL CONSTVALPOS                                                        
   DELETE FROM CONSTVALPOS WHERE COD IN (SELECT CVP.COD FROM CONSTVALPOS CVP,CONSTLUNA CL,CONST1 C1 WHERE
                                           CVP.CODCONSTLUNA=CL.CODCONSTLUNA AND
                                           CL.CODCONST1=C1.CODCONST1 AND
                                           C1.CODCATEG=RECID AND
                                           CVP.COD NOT IN (SELECT COD FROM TMP_CONSTVALPOS)
                                         );
  
 -- DETAIL CONSTLUNA 
              --sterg intai detaliile din constvalpos
   DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM CONSTLUNA CL,CONST1 C1 WHERE
                                                    CL.CODCONST1=C1.CODCONST1 AND
                                                    C1.CODCATEG=RECID AND
                                                    CL.CODCONSTLUNA NOT IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA)
                                                  );
   DELETE FROM CONSTVAL WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM CONSTLUNA CL,CONST1 C1 WHERE
                                                    CL.CODCONST1=C1.CODCONST1 AND
                                                    C1.CODCATEG=RECID AND
                                                    CL.CODCONSTLUNA NOT IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA)
                                                  ); 
              --sterg din constluna               
   DELETE FROM CONSTLUNA WHERE CODCONSTLUNA IN  (SELECT CL.CODCONSTLUNA FROM CONSTLUNA CL,CONST1 C1 WHERE
                                                    CL.CODCONST1=C1.CODCONST1 AND
                                                    C1.CODCATEG=RECID AND
                                                    CL.CODCONSTLUNA NOT IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA)
                                                  );  
                                                                                                                         
   
-- DETAIL CONST1
         -- sterg detaliile din constvalpos
   DELETE FROM CONSTVALPOS WHERE COD IN (SELECT CVP.COD FROM CONSTVALPOS CVP,CONSTLUNA CL,CONST1 C1 WHERE
                                                  CVP.CODCONSTLUNA=CL.CODCONSTLUNA AND
                                                  CL.CODCONST1=C1.CODCONST1 AND
                                                  C1.CODCATEG=RECID AND
                                                  C1.CODCONST1 NOT IN (SELECT CODCONST1 FROM TMP_CONST1)
                              );
   DELETE FROM CONSTVAL WHERE CODCONSTLUNA IN ( SELECT CVP.COD FROM CONSTVALPOS CVP,CONSTLUNA CL,CONST1 C1 WHERE
                                                  CVP.CODCONSTLUNA=CL.CODCONSTLUNA AND
                                                  CL.CODCONST1=C1.CODCONST1 AND
                                                  C1.CODCATEG=RECID AND
                                                  C1.CODCONST1 NOT IN (SELECT CODCONST1 FROM TMP_CONST1)
                              );
        -- sterg detalii din constluna                      
   DELETE FROM CONSTLUNA WHERE CODCONSTLUNA IN (SELECT CL.CODCONSTLUNA FROM CONSTLUNA CL,CONST1 C1 WHERE
                                                       CL.CODCONST1=C1.CODCONST1 AND
                                                       C1.CODCATEG=RECID AND
                                                       C1.CODCONST1 NOT IN (SELECT CODCONST1 FROM TMP_CONST1)
                                                  );
        -- sterg din const1                                                                        
   DELETE FROM CONST1 WHERE (CODCATEG=RECID AND CODCONST1 NOT IN (SELECT CODCONST1 FROM TMP_CONST1));
   
   
-----------------------------INSEREZ INREGISTRARILE NOI IN DETALII---------------------------------------------
-- DETAIL CONST1 &amp; CONSTLUNA $ CONSTVALPOS  
  
SELECT COUNT (CODCONST1) INTO TEST_CODCONST1 FROM TMP_CONST1 WHERE CODCONST1 &lt; 0;
SELECT COUNT (CODCONSTLUNA) INTO TEST_CODCONSTLUNA FROM TMP_CONSTLUNA WHERE CODCONSTLUNA &lt; 0;
IF TEST_CODCONST1 &gt; 0 THEN
 FOR V_REC IN (SELECT * FROM TMP_CONST1 WHERE CODCONST1 &lt; 0) LOOP
    SELECT SEQ_CONST1_CODCONST1.NEXTVAL INTO V_CODCONST1 FROM DUAL;
        
        INSERT INTO CONST1(CODCONST1,CODCATEG,INDEXLOCAL,SIMBOL,DENUMIRE,TIP) VALUES
        (V_CODCONST1,RECID,V_REC.INDEXLOCAL,V_REC.SIMBOL,V_REC.DENUMIRE,V_REC.TIP);          
     
     FOR V_REC1 IN (SELECT * FROM TMP_CONSTLUNA  WHERE CODCONSTLUNA &lt; 0 AND TMP_CONSTLUNA.CODCONST1=V_REC.CODCONST1) LOOP
        
        SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO V_CODCONSTLUNA FROM DUAL;
         
         INSERT INTO CONSTLUNA(CODCONSTLUNA,CODCONST1,ANSTART,LUNASTART,USERID) VALUES
          (V_CODCONSTLUNA,V_CODCONST1,V_REC1.ANSTART,V_REC1.LUNASTART,V_REC1.USERID);
         
         INSERT INTO CONSTVALPOS (COD,IDX,VALPOSIBILE,CODCONSTLUNA) 
         (SELECT SEQ_CONSTVALPOS_COD.NEXTVAL,IDX,VALPOSIBILE,V_CODCONSTLUNA FROM TMP_CONSTVALPOS WHERE COD &lt; 0 AND CODCONSTLUNA=V_REC1.CODCONSTLUNA); 
           
         
         INSERT INTO CONSTVAL (VALOARE,CODCONSTLUNA)
          (SELECT VALOARE, V_CODCONSTLUNA  FROM TMP_CONSTVAL WHERE  CODCONSTLUNA = V_REC1.CODCONSTLUNA 
           ); 
           
     END LOOP;
  
 END LOOP;
END IF;
  IF TEST_CODCONSTLUNA &gt; 0 AND TEST_CODCONST1 =0 THEN  
    FOR V_REC1 IN (SELECT * FROM TMP_CONSTLUNA  WHERE CODCONSTLUNA &lt; 0 ) LOOP
        
        SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO V_CODCONSTLUNA FROM DUAL;
         
         INSERT INTO CONSTLUNA(CODCONSTLUNA,CODCONST1,ANSTART,LUNASTART,USERID) VALUES
          (V_CODCONSTLUNA,V_REC1.CODCONST1,V_REC1.ANSTART,V_REC1.LUNASTART,V_REC1.USERID);
         
         INSERT INTO CONSTVALPOS (COD,IDX,VALPOSIBILE,CODCONSTLUNA) 
         (SELECT SEQ_CONSTVALPOS_COD.NEXTVAL,IDX,VALPOSIBILE,V_CODCONSTLUNA FROM TMP_CONSTVALPOS WHERE COD &lt; 0 AND CODCONSTLUNA=V_REC1.CODCONSTLUNA); 
         
         INSERT INTO CONSTVAL (VALOARE,CODCONSTLUNA)
          (SELECT VALOARE, V_CODCONSTLUNA  FROM TMP_CONSTVAL WHERE  CODCONSTLUNA = V_REC1.CODCONSTLUNA 
           ); 
         
     END LOOP;
 END IF;
 IF TEST_CODCONSTLUNA = 0 AND TEST_CODCONST1 = 0 THEN
     
     INSERT INTO CONSTVALPOS(COD,IDX,VALPOSIBILE,CODCONSTLUNA)
     (SELECT SEQ_CONSTVALPOS_COD.NEXTVAL,IDX,VALPOSIBILE,CODCONSTLUNA FROM TMP_CONSTVALPOS WHERE COD &lt; 0);
      
     INSERT INTO CONSTVAL (VALOARE,CODCONSTLUNA)
          (SELECT VALOARE, CODCONSTLUNA  FROM TMP_CONSTVAL WHERE CODCONSTLUNA IN ((SELECT CODCONSTLUNA  FROM TMP_CONSTVAL)minus(select codconstluna from constval)) 
           ); 
    
 END IF; 
 
 
           
----------------------------------------------UPDATE-------------------------------------------------------
 
-- DETAIL CONST1
        
   FOR V_REC IN (SELECT * FROM TMP_CONST1 WHERE NVL(CODCATEG,0) &gt; 0) LOOP
          UPDATE CONST1 SET 
                 CODCATEG   = V_REC.CODCATEG,
                 INDEXLOCAL = V_REC.INDEXLOCAL,
                 SIMBOL     = V_REC.SIMBOL,
                 DENUMIRE   = V_REC.DENUMIRE,
                 TIP        = V_REC.TIP
          WHERE V_REC.CODCONST1=CODCONST1;   
   END LOOP;
   
--DETAIL CONSTLUNA
          
          
   FOR V_REC IN (SELECT * FROM TMP_CONSTLUNA WHERE CODCONSTLUNA &gt; 0 ) LOOP
          UPDATE CONSTLUNA SET
                 ANSTART   = V_REC.ANSTART,
                 LUNASTART = V_REC.LUNASTART
          WHERE CODCONSTLUNA = V_REC.CODCONSTLUNA;
   END LOOP; 
               
               
-- DETAIL  CONSTVALPOS                
   FOR V_REC IN (SELECT * FROM TMP_CONSTVALPOS WHERE COD &gt; 0)LOOP                                    
          UPDATE CONSTVALPOS SET
                 IDX = V_REC.IDX,
                 VALPOSIBILE= V_REC.VALPOSIBILE
           WHERE COD=V_REC.COD;
   END LOOP;      
  
   FOR V_REC IN (SELECT * FROM TMP_CONSTVAL) LOOP
            UPDATE CONSTVAL SET
                   VALOARE =V_REC.VALOARE
            WHERE CODCONSTLUNA=V_REC.CODCONSTLUNA;
   END LOOP;                     
  
 
 ELSE --INSERT
 
 --MASTER CATEGCONST
 --insert into t(text)(select codCONST1 from tmp_CONST1);commit;
 SELECT SEQ_CATEGCONST_CODCATEG.NEXTVAL INTO RECID FROM DUAL;
 INSERT INTO CATEGCONST(CODCATEG,DENUMIRE,INDEXLOCAL,TIPCATEG)
 (SELECT RECID,DENUMIRE,INDEXLOCAL,DECODE ( TIPCATEG, &apos;Utilizator&apos;,&apos;U&apos;,
                                                      &apos;General&apos;,&apos;G&apos;
                                                                              
                                                                     )  
  
  FROM TMP_CATEGCONST);
  
-- DETAIL CONST1,CONSTLUNA &amp; CONSTVALPOS
 
  
 FOR V_REC IN (SELECT CODCONST1,CODCATEG,INDEXLOCAL,SIMBOL,DENUMIRE,TIP FROM TMP_CONST1 WHERE CODCONST1 &lt; 0)LOOP
     
     SELECT SEQ_CONST1_CODCONST1.NEXTVAL INTO V_CODCONST1 FROM DUAL;
     INSERT INTO CONST1(CODCONST1,CODCATEG,INDEXLOCAL,SIMBOL,DENUMIRE,TIP) VALUES
                       (V_CODCONST1,RECID,V_REC.INDEXLOCAL,V_REC.SIMBOL,V_REC.DENUMIRE,V_REC.TIP);
    
       CASE V_REC.TIP
            WHEN 3 THEN
               FOR V_REC1 IN (SELECT * FROM TMP_CONSTLUNA  WHERE CODCONSTLUNA &lt; 0 AND TMP_CONSTLUNA.CODCONST1=V_REC.CODCONST1) LOOP
        
                   SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO V_CODCONSTLUNA FROM DUAL;
         
                   INSERT INTO CONSTLUNA(CODCONSTLUNA,CODCONST1,ANSTART,LUNASTART,USERID) VALUES
                   (V_CODCONSTLUNA,V_CODCONST1,V_REC1.ANSTART,V_REC1.LUNASTART,V_REC1.USERID);
         
                   INSERT INTO CONSTVALPOS (COD,IDX,VALPOSIBILE,CODCONSTLUNA) 
                   (SELECT SEQ_CONSTVALPOS_COD.NEXTVAL,IDX,VALPOSIBILE,V_CODCONSTLUNA FROM TMP_CONSTVALPOS WHERE COD &lt; 0 AND CODCONSTLUNA=V_REC1.CODCONSTLUNA); 
           
                   INSERT INTO CONSTVAL  (VALOARE,CODCONSTLUNA)
                   (SELECT VALOARE,V_CODCONSTLUNA FROM TMP_CONSTVAL WHERE CODCONSTLUNA=V_REC1.CODCONSTLUNA);
                  
                                
               END LOOP;
            ELSE NULL;
       END CASE;
 END LOOP;
 
END IF;         
NotifyModif(Operation, RecId, &apos;CATEGCONST&apos;);
COMMIT;
END;
  
  
PROCEDURE SET_V_CODCONSTLUNA_ACTIV (COD IN NUMBER) IS
BEGIN
     PKG_EDITCONST.V_CODCONSTLUNA_ACTIV :=COD;
END;   
 
PROCEDURE SET_V_CODCONST1_ACTIV (COD IN NUMBER)  IS
BEGIN
     PKG_EDITCONST.V_CODCONST1_ACTIV :=COD;
END;
end PKG_EDITCONST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EFCUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA53A82C2CC456FD75192083A268AAAEB206D8B4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EFCustom is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodEFCustom INTO Tmp FROM EFCUSTOM WHERE CodEFCustom = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM EFCUSTOM WHERE CodEFCustom = RecId ;

	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EFCUSTOM FIELDS( CodEFCustom ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  INSERT INTO  TMP_EFCUSTOM (CodEFCustom,DEN_EFCUSTOM,SQLCAMPURI,SQLCAMPURI1)
  SELECT E.CodEFCustom,E.DEN_EFCUSTOM,E.SQLCAMPURI, E.SQLCAMPURI1
  FROM EFCUSTOM E
  WHERE E.CodEFCustom = RecId ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodEFCustom INTO RECID FROM TMP_EFCUSTOM;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE EFCUSTOM
    SET (DEN_EFCUSTOM,SQLCAMPURI,SQLCAMPURI1)= (SELECT E.DEN_EFCUSTOM,E.SQLCAMPURI,E.SQLCAMPURI1 FROM TMP_EFCUSTOM E)
    WHERE CodEFCustom = RecId;

   
	ELSE  -- INSERT
		SELECT SEQ_EFCUSTOM_CODEFCustom.NextVal INTO RecId FROM DUAL;
			INSERT INTO EFCUSTOM(CodEFCustom,DEN_EFCUSTOM,SQLCAMPURI,SQLCAMPURI1 )
			SELECT RecId,E.DEN_EFCUSTOM,E.SQLCAMPURI,E.SQLCAMPURI1
		FROM TMP_EFCUSTOM E;

  END IF; 
  NotifyModif(Operation, RecId, &apos;EFCustom&apos;);
  COMMIT;
END;

PROCEDURE ACTUAL_EFCUSTOM IS
  iFound number(20) := 0;
  CODA NUMBER(20);
BEGIN
  MERGE INTO EFACT_CUSTOM A
  USING TMP_EFCUSTOM TMP ON (upper(A.DEN_EFCUSTOM) = upper(TMP.DEN_EFCUSTOM))
  WHEN MATCHED THEN
    UPDATE SET
      A.SQLCAMPURI    = TMP.SQLCAMPURI,
      A.SQLCAMPURI1   = TMP.SQLCAMPURI1
  WHEN NOT MATCHED THEN
    INSERT (A.CODEFACTC,A.DEN_EFCUSTOM,A.SQLCAMPURI,A.SQLCAMPURI1) VALUES (SEQ_EFACT_CUSTOM_CODEFACTC.NEXTVAL,TMP.DEN_EFCUSTOM,TMP.SQLCAMPURI,TMP.SQLCAMPURI1);
  COMMIT;
END;

end PKG_EFCustom; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>142F68472FF6B5C51BD6220C1A95CA44D57158B7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ELEMBUGET is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CODELEMBUGET INTO Tmp FROM ELEMBUGET WHERE CODELEMBUGET = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM ELEMBUGET1 WHERE CODELEMBUGET = RECID;
  DELETE FROM ELEMBUGET  WHERE CODELEMBUGET = RECID;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_ELEMBUGET FIELDS(CODELEMBUGET) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_ELEMBUGET(CODELEMBUGET, ELEMENT, SIMBOL, TIP, FUNCTIE)
  SELECT CODELEMBUGET, ELEMENT, SIMBOL, TIP, FUNCTIE
  FROM ELEMBUGET
  WHERE CODELEMBUGET = RECID;
  
  INSERT INTO TMP_ELEMBUGET1(CODELEMBUGET1, CODELEMBUGET, CODCLASEA, DEN_CLASEA)
  SELECT E1.CODELEMBUGET1, E1.CODELEMBUGET, E1.CODCLASEA, CLS.DEN_CLASEA
  FROM ELEMBUGET1 E1
       LEFT JOIN NCLASEA CLS ON E1.CODCLASEA = CLS.CODCLASEA
  WHERE CODELEMBUGET = RECID;
  
  INSERT INTO TMP_ELEMBUGET2(
    CODELEMBUGET2, CODELEMBUGET, AN, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,
    S11, S12, S13, S14, S15, S16, S17, S18, S19, S20,
    S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, 
    S31, S32, S33, S34, S35, S36, S37, S38, S39, S40,
    S41, S42, S43, S44, S45, S46, S47, S48, S49, S50,
    S51, S52, S53
  )
  SELECT CODELEMBUGET2, CODELEMBUGET, AN, 
    S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,
    S11, S12, S13, S14, S15, S16, S17, S18, S19, S20,
    S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, 
    S31, S32, S33, S34, S35, S36, S37, S38, S39, S40,
    S41, S42, S43, S44, S45, S46, S47, S48, S49, S50,
    S51, S52, S53
  FROM ELEMBUGET2  
  WHERE CODELEMBUGET = RECID;
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
VCOD NUMBER(20);
BEGIN
  IF Operation = 0 THEN -- UPDATE
    select CODELEMBUGET into RECID from TMP_ELEMBUGET;
    
    UPDATE ELEMBUGET
    SET (ELEMENT, SIMBOL, TIP, FUNCTIE)
    =
    (SELECT ELEMENT, SIMBOL, TIP, FUNCTIE
    FROM TMP_ELEMBUGET)
    WHERE CODELEMBUGET = RECID;
    
    DELETE ELEMBUGET1 E1 WHERE E1.CODELEMBUGET = RECID AND NOT EXISTS (SELECT TMP.CODELEMBUGET1 FROM TMP_ELEMBUGET1 TMP WHERE TMP.CODELEMBUGET1 = E1.CODELEMBUGET1);
    FOR V_REC IN (SELECT * FROM TMP_ELEMBUGET1) LOOP
      IF V_REC.CODELEMBUGET1 &gt; 0 THEN
        UPDATE ELEMBUGET1
        SET
          CODCLASEA = v_rec.codclasea
        WHERE CODELEMBUGET1 = V_REC.CODELEMBUGET1;
      ELSE
        INSERT INTO ELEMBUGET1(
          CODELEMBUGET1, CODELEMBUGET, CODCLASEA
        )
        VALUES ( 
          SEQ_ELEMBUGET1_CODELEMBUGET1.NEXTVAL, RECID, V_REC.CODCLASEA
        );
      END IF;
    END LOOP;
    
    DELETE ELEMBUGET2 E2 WHERE E2.CODELEMBUGET = RECID AND NOT EXISTS (SELECT TMP.CODELEMBUGET2 FROM TMP_ELEMBUGET2 TMP WHERE TMP.CODELEMBUGET2 = E2.CODELEMBUGET2);
    FOR V_REC IN (SELECT * FROM TMP_ELEMBUGET2) LOOP
      IF V_REC.CODELEMBUGET2 &gt; 0 THEN
        UPDATE ELEMBUGET2
        SET
          AN = V_REC.AN, 
          S1 = V_REC.S1 , S2 = V_REC.S2 , S3 = V_REC.S3 , S4 = V_REC.S4 , S5 = V_REC.S5 , S6 = V_REC.S6 , S7 = V_REC.S7 , S8 = V_REC.S8 , S9 = V_REC.S9 , S10= V_REC.S10,
          S11= V_REC.S11, S12= V_REC.S12, S13= V_REC.S13, S14= V_REC.S14, S15= V_REC.S15, S16= V_REC.S16, S17= V_REC.S17, S18= V_REC.S18, S19= V_REC.S19, S20= V_REC.S20,
          S21= V_REC.S21, S22= V_REC.S22, S23= V_REC.S23, S24= V_REC.S24, S25= V_REC.S25, S26= V_REC.S26, S27= V_REC.S27, S28= V_REC.S28, S29= V_REC.S29, S30= V_REC.S30, 
          S31= V_REC.S31, S32= V_REC.S32, S33= V_REC.S33, S34= V_REC.S34, S35= V_REC.S35, S36= V_REC.S36, S37= V_REC.S37, S38= V_REC.S38, S39= V_REC.S39, S40= V_REC.S40,
          S41= V_REC.S41, S42= V_REC.S42, S43= V_REC.S43, S44= V_REC.S44, S45= V_REC.S45, S46= V_REC.S46, S47= V_REC.S47, S48= V_REC.S48, S49= V_REC.S49, S50= V_REC.S50,
          S51= V_REC.S51, S52= V_REC.S52, S53= V_REC.S53
        WHERE CODELEMBUGET2 = V_REC.CODELEMBUGET2;  
      ELSE
        INSERT INTO ELEMBUGET2(
          CODELEMBUGET2, CODELEMBUGET, AN, 
          S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,
          S11, S12, S13, S14, S15, S16, S17, S18, S19, S20,
          S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, 
          S31, S32, S33, S34, S35, S36, S37, S38, S39, S40,
          S41, S42, S43, S44, S45, S46, S47, S48, S49, S50,
          S51, S52, S53
        )
        VALUES ( 
          SEQ_ELEMBUGET2_CODELEMBUGET2.NEXTVAL, RECID, V_REC.AN, 
          V_REC.S1, V_REC.S2, V_REC.S3, V_REC.S4, V_REC.S5, V_REC.S6, V_REC.S7, V_REC.S8, V_REC.S9, V_REC.S10,
          V_REC.S11, V_REC.S12, V_REC.S13, V_REC.S14, V_REC.S15, V_REC.S16, V_REC.S17, V_REC.S18, V_REC.S19, V_REC.S20,
          V_REC.S21, V_REC.S22, V_REC.S23, V_REC.S24, V_REC.S25, V_REC.S26, V_REC.S27, V_REC.S28, V_REC.S29, V_REC.S30, 
          V_REC.S31, V_REC.S32, V_REC.S33, V_REC.S34, V_REC.S35, V_REC.S36, V_REC.S37, V_REC.S38, V_REC.S39, V_REC.S40,
          V_REC.S41, V_REC.S42, V_REC.S43, V_REC.S44, V_REC.S45, V_REC.S46, V_REC.S47, V_REC.S48, V_REC.S49, V_REC.S50,
          V_REC.S51, V_REC.S52, V_REC.S53 
        );
      END IF;
    END LOOP;
    
  ELSE  -- INSERT
    SELECT SEQ_ELEMBUGET_CODELEMBUGET.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO ELEMBUGET(CODELEMBUGET, ELEMENT, SIMBOL, TIP, FUNCTIE)
    SELECT RECID, ELEMENT, SIMBOL, TIP, FUNCTIE
    FROM TMP_ELEMBUGET;
    
    INSERT INTO ELEMBUGET1(CODELEMBUGET1, CODELEMBUGET, CODCLASEA)
    SELECT SEQ_ELEMBUGET1_CODELEMBUGET1.NEXTVAL, RECID, CODCLASEA
    FROM TMP_ELEMBUGET1;
    
    INSERT INTO ELEMBUGET2(
      CODELEMBUGET2, CODELEMBUGET, AN, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,
      S11, S12, S13, S14, S15, S16, S17, S18, S19, S20,
      S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, 
      S31, S32, S33, S34, S35, S36, S37, S38, S39, S40,
      S41, S42, S43, S44, S45, S46, S47, S48, S49, S50,
      S51, S52, S53
    )
    SELECT SEQ_ELEMBUGET2_CODELEMBUGET2.NEXTVAL, RECID, AN, 
      S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,
      S11, S12, S13, S14, S15, S16, S17, S18, S19, S20,
      S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, 
      S31, S32, S33, S34, S35, S36, S37, S38, S39, S40,
      S41, S42, S43, S44, S45, S46, S47, S48, S49, S50,
      S51, S52, S53
    FROM TMP_ELEMBUGET2;
  END IF;
  
  COMMIT;
END;  

end PKG_ELEMBUGET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4920D7ED4F1339F18309796E0BC4D4FC1C4F2F9F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ELEMENTE IS

G_SIMBOL     VARCHAR2(100) := &apos;?&apos;;
G_TIPDOC     NUMBER(20)    := -1;
G_CODANALIZA NUMBER(20)    := -1;
G_TIPCONT    NUMBER(1)     := -1;

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  TMP NUMBER(20);
 BEGIN
  SELECT CODELEMENT INTO TMP FROM ELEMENTE WHERE CODELEMENT = RECID FOR UPDATE NOWAIT;
 END;

 PROCEDURE SP_INSERTRECORD IS
 BEGIN
  INSERT INTO TMP_ELEMENTE(CODELEMENT) VALUES(0);
  COMMIT;
 END;

 PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
 BEGIN
  SP_LOCKRECORD(RECID);
  DELETE FROM ELEMENTEC EC WHERE EXISTS
   (SELECT EM.CODELEMENTM  FROM ELEMENTEM EM WHERE EM.CODELEMENT = RECID AND EM.CODELEMENTM = EC.CODELEMENTM);
  DELETE FROM ELEMENTEM WHERE CODELEMENT = RECID;
  DELETE FROM ELEMENTEA WHERE CODELEMENT = RECID;
  DELETE FROM ELEMENTE  WHERE CODELEMENT = RECID;
  NotifyModif(2, RecId, &apos;ELEMENTE&apos;);
  COMMIT;
 END;

 PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  BEGIN
  INSERT INTO TMP_ELEMENTE(CODELEMENT,DEN_ELEMENT,TIP,CV,Simbol, CODDESCRIPTORBAZA)
   SELECT CODELEMENT,DEN_ELEMENT,TIP,CV,Simbol,CODDESCRIPTORBAZA FROM ELEMENTE WHERE CODELEMENT = RECID;

  INSERT INTO TMP_ELEMENTEA(CODELEMENTA,CODELEMENT,CODANALIZA,NODMAXIMANALIZA1,CODDESCRIPTOR)
   SELECT  EA.CODELEMENTA,EA.CODELEMENT,EA.CODANALIZA,EA.NODMAXIMANALIZA1,A1.CODDESCRIPTOR
   FROM ELEMENTEA EA LEFT JOIN ANALIZA1 A1 ON A1.CODANALIZA = EA.CODANALIZA
   WHERE CODELEMENT = RECID AND
         NVL(A1.INDEXLOCAL,1) = NVL(EA.NODMAXIMANALIZA1,1);

  INSERT INTO TMP_ELEMENTEM(CODELEMENTM,CODELEMENT,TIPDOC,DENTIPMAKETA)
   SELECT CODELEMENTM,CODELEMENT,TIPDOC,M.NUMEEXT
   FROM ELEMENTEM EM INNER JOIN TMP_MACHETE M ON EM.TIPDOC = M.CODMACHETA
   WHERE EM.CODELEMENT = RECID;

  INSERT INTO TMP_ELEMENTEC(CODELEMENTC,CODELEMENTM,MASCA)
  SELECT EC.CODELEMENTC,EC.CODELEMENTM,EC.MASCA FROM ELEMENTEC EC WHERE EXISTS
    (SELECT EM.CODELEMENTM  FROM ELEMENTEM EM WHERE EM.CODELEMENT = RECID AND EM.CODELEMENTM = EC.CODELEMENTM);

  COMMIT;
 END;

 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ) IS
 TMP NUMBER(20);
 BEGIN
   IF OPERATION = 0 THEN --UPDATE
    SELECT CODELEMENT INTO RECID FROM TMP_ELEMENTE;

    UPDATE ELEMENTE SET (DEN_ELEMENT,TIP,CV,Simbol,CODDESCRIPTORBAZA) =
      ( SELECT DEN_ELEMENT,TIP,CV,Simbol,CODDESCRIPTORBAZA FROM TMP_ELEMENTE)
    WHERE CODELEMENT = RECID;

    DELETE FROM ELEMENTEA EA WHERE EA.CODELEMENT = RECID AND NOT EXISTS ( SELECT CODELEMENTA FROM TMP_ELEMENTEA WHERE CODELEMENTA = EA.CODELEMENTA);

    FOR V_REC IN (SELECT *  FROM ELEMENTEM EM
                     WHERE EM.CODELEMENT = RECID
                      AND NOT EXISTS (SELECT CODELEMENTM FROM TMP_ELEMENTEM WHERE CODELEMENTM = EM.CODELEMENTM)
                 ) LOOP
       DELETE FROM ELEMENTEC WHERE CODELEMENTM = V_REC.CODELEMENTM ;
       DELETE FROM ELEMENTEM WHERE CODELEMENTM = V_REC.CODELEMENTM;
    END LOOP;


    DELETE FROM ELEMENTEC WHERE CODELEMENTC NOT IN (SELECT EC.CODELEMENTC FROM TMP_ELEMENTEC EC ) AND
                                CODELEMENTM IN (SELECT CODELEMENTM FROM TMP_ELEMENTEM);


    INSERT INTO ELEMENTEA (CODELEMENTA,CODELEMENT,CODANALIZA,NODMAXIMANALIZA1)
    SELECT SEQ_ELEMENTEA_CODELEMENTA.NEXTVAL,RECID,CODANALIZA,NODMAXIMANALIZA1 FROM TMP_ELEMENTEA WHERE CODELEMENTA &lt;= 0;

    FOR V_REC IN (SELECT * FROM TMP_ELEMENTEM ) LOOP

      IF V_REC.CODELEMENTM &lt;= 0 THEN
       INSERT INTO ELEMENTEM(CODELEMENTM,CODELEMENT,TIPDOC) VALUES
        (SEQ_ELEMENTEM_CODELEMENTM.NEXTVAL,RECID,V_REC.TIPDOC);

      INSERT INTO ELEMENTEC(CODELEMENTC,CODELEMENTM,MASCA)
      SELECT SEQ_ELEMENTEC_CODELEMENTC.NEXTVAL,SEQ_ELEMENTEM_CODELEMENTM.CURRVAL,MASCA
      FROM TMP_ELEMENTEC
      WHERE CODELEMENTC &lt;= 0 AND CODELEMENTM = V_REC.CODELEMENTM;

     ELSE

      INSERT INTO ELEMENTEC(CODELEMENTC,CODELEMENTM,MASCA)
      SELECT SEQ_ELEMENTEC_CODELEMENTC.NEXTVAL,V_REC.CODELEMENTM,MASCA
      FROM TMP_ELEMENTEC
      WHERE CODELEMENTC &lt;= 0 AND CODELEMENTM = V_REC.CODELEMENTM;

     END IF;

    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_ELEMENTEA WHERE CODELEMENTA &gt; 0 ) LOOP
     UPDATE ELEMENTEA EA SET
       EA.CODELEMENT       = V_REC.CODELEMENT,
       EA.CODANALIZA       = V_REC.CODANALIZA,
       EA.NODMAXIMANALIZA1 = V_REC.NODMAXIMANALIZA1
     WHERE EA.CODELEMENTA = V_REC.CODELEMENTA;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_ELEMENTEM WHERE CODELEMENTM &gt; 0 ) LOOP
     UPDATE ELEMENTEM EM SET
      EM.CODELEMENT = V_REC.CODELEMENT,
      EM.TIPDOC     = V_REC.TIPDOC
     WHERE EM.CODELEMENTM = V_REC.CODELEMENTM;

     FOR V_REC1 IN (SELECT * FROM TMP_ELEMENTEC  WHERE CODELEMENTM = V_REC.CODELEMENTM) LOOP
      UPDATE ELEMENTEC EC SET
       EC.CODELEMENTM = V_REC.CODELEMENTM,
       EC.MASCA      = V_REC1.MASCA
      WHERE EC.CODELEMENTC = V_REC1.CODELEMENTC ;
     END LOOP;

    END LOOP;

   ELSE -- INSERT

    SELECT SEQ_ELEMENTE_CODELEMENT.NEXTVAL INTO RECID FROM DUAL;

    INSERT INTO ELEMENTE(CODELEMENT,DEN_ELEMENT,TIP,CV,SIMBOL,CODDESCRIPTORBAZA)
     SELECT RECID,DEN_ELEMENT,TIP,CV,Simbol,CODDESCRIPTORBAZA FROM TMP_ELEMENTE;

    INSERT INTO ELEMENTEA(CODELEMENTA,CODELEMENT,CODANALIZA,NODMAXIMANALIZA1)
     SELECT SEQ_ELEMENTEA_CODELEMENTA.NEXTVAL,RECID,CODANALIZA,NODMAXIMANALIZA1 FROM TMP_ELEMENTEA;

    FOR V_REC IN (SELECT * FROM TMP_ELEMENTEM)  LOOP
     INSERT INTO ELEMENTEM(CODELEMENTM,CODELEMENT,TIPDOC) VALUES
       (SEQ_ELEMENTEM_CODELEMENTM.NEXTVAL,RECID,V_REC.TIPDOC);

     INSERT INTO ELEMENTEC(CODELEMENTC,CODELEMENTM,MASCA)
      SELECT SEQ_ELEMENTEC_CODELEMENTC.NEXTVAL, SEQ_ELEMENTEM_CODELEMENTM.CURRVAL,MASCA
      FROM TMP_ELEMENTEC WHERE CODELEMENTM = V_REC.CODELEMENTM;
    END LOOP;

   END IF;
   NotifyModif(Operation, RecId, &apos;ELEMENTE&apos;);
  COMMIT;
 END;

FUNCTION DECODE_DESCRIPT1(ATIP IN NUMBER) RETURN VARCHAR2 IS
sResult VARCHAR2(100) := &apos;?&apos;;
BEGIN

     sResult := CASE aTip
                     WHEN   0 THEN &apos;Diverse&apos;
                     WHEN   2 THEN &apos;Conturi&apos;
                     WHEN  11 THEN &apos;Monede&apos;
                     WHEN  22 THEN &apos;Articole&apos;
                     WHEN  50 THEN &apos;Personal&apos;
                     WHEN  60 THEN &apos;Parteneri&apos;
                     WHEN  70 THEN &apos;Subunitati&apos;
                     WHEN  75 THEN &apos;Parc auto&apos;
                     WHEN  80 THEN &apos;Tari&apos;
                     WHEN  81 THEN &apos;Judete&apos;
                     WHEN  82 THEN &apos;Orase&apos;
                     WHEN  85 THEN &apos;Activitati&apos;
                     WHEN  90 THEN &apos;Formatii&apos;
                     WHEN 100 THEN &apos;Clase articole&apos;
               END;
 RETURN sResult;
END;

FUNCTION VALIDEAZA_MASCA_CONT(MASCA IN VARCHAR2) RETURN BOOLEAN IS
bResult BOOLEAN := FALSE;
cnt number(20);
BEGIN
  IF MASCA = &apos;*&apos; THEN
   RETURN TRUE;
  END IF;

 select count(*) into cnt from ncont where UPPER(simbol) like UPPER(masca||&apos;%&apos;);
 return (cnt &gt; 0);

END;

PROCEDURE SET_VALORI_ANALIZA (ASIMBOL IN VARCHAR2, ATIPDOC IN NUMBER, ACODANALIZA IN NUMBER, ATIPCONT IN NUMBER ) IS
BEGIN
  G_SIMBOL     := ASIMBOL;
  G_TIPDOC     := ATIPDOC;
  G_CODANALIZA := ACODANALIZA;
  G_TIPCONT    := ATIPCONT;
END;

FUNCTION GET_SIMBOL RETURN VARCHAR2 IS
BEGIN
  RETURN G_SIMBOL;
END;

FUNCTION GET_TIPDOC RETURN NUMBER IS
BEGIN
  RETURN G_TIPDOC;
END;

FUNCTION GET_CODANALIZA RETURN NUMBER IS
BEGIN
  RETURN G_CODANALIZA;
END;

FUNCTION GET_TIPCONT RETURN NUMBER IS
BEGIN
  RETURN G_TIPCONT;
END;

end PKG_ELEMENTE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC69EA8263ADBC69107D64136B95FF965A8342ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_emulare IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_9&apos;;


  PROCEDURE POSBANCAR_GOTORECORDS(aUserID IN NUMBER )
  IS
  BEGIN
    DELETE TMP_POSBANCAR;
    INSERT INTO TMP_POSBANCAR(CODPOSBANCAR, INDEXLOCAL, TIPPOS, PORTSERIAL, IP, INACTIV, USERID, REMOTE, IPSERVERPOS, PORTSERVERPOS, DENUMIRE)
    SELECT 
      CODPOSBANCAR, 
      INDEXLOCAL, 
      TIPPOS, 
      PORTSERIAL, 
      IP, 
      INACTIV, 
      USERID, 
      REMOTE, 
      IPSERVERPOS, 
      PORTSERVERPOS, 
      CASE
        WHEN TIPPOS = 1 THEN &apos;Pos BRD Ingenico&apos; 
        WHEN TIPPOS = 3 THEN &apos;Pos Transilvania&apos; 
        WHEN TIPPOS = 4 THEN &apos;Pos Unicredit&apos; 
        WHEN TIPPOS = 5 THEN &apos;Pos BRD HyperCom&apos; 
        WHEN TIPPOS = 6 THEN &apos;Pos Verifone&apos; 
        WHEN TIPPOS = 7 THEN &apos;Pos Viva Wallet&apos; 
       ELSE &apos;?&apos;   
      END    
    FROM  
      POSBANCAR
    WHERE
      USERID = aUSERID;  
      COMMIT;
  END;    


  PROCEDURE POSBANCAR_POSTRECORDS(aUserID IN NUMBER )
  IS
  BEGIN
    DELETE POSBANCAR WHERE USERID = aUserID;
    INSERT INTO POSBANCAR( CODPOSBANCAR, INDEXLOCAL, TIPPOS, PORTSERIAL, IP, INACTIV,  USERID, REMOTE, IPSERVERPOS, PORTSERVERPOS)
    SELECT CODPOSBANCAR, INDEXLOCAL, TIPPOS, PORTSERIAL, IP, INACTIV, USERID, REMOTE, IPSERVERPOS, PORTSERVERPOS FROM TMP_POSBANCAR;
    COMMIT;
  END;    




  PROCEDURE STERGEINCASARI (aCODEMUL IN NUMBER)
  IS
    aCODIES NUMBER(20);
    aCODTREZOR NUMBER(20);
    NR NUMBER;
  BEGIN
    BEGIN
      SELECT NVL(CODIES, 0) INTO aCODIES FROM EMULARE WHERE CODEMULARE = aCODEMUL;  
      EXCEPTION WHEN OTHERS THEN aCODIES := 0;
      
    END;
  
    IF aCODIES &gt; 0 THEN
      BEGIN
          select 
            T1.CODTREZOR INTO aCODTREZOR
          from 
            GENERAL G,
            OBLIGPIF O,
            STINGERE S,
            OBLIGPIF O_STINGATOR,
            GENERAL G_STINGATOR,
            TREZOR1 T1
          WHERE
             G.TIPDOC = 19
             AND G.CODDOC = aCODIES
             AND O.CODGENERAL = G.CODGENERAL
             AND S.CODSTINSPIF = O.CODOBLIGPIF
             AND S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF
             AND G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
             AND G_STINGATOR.TIPDOC IN (29, 30, 31)
             AND T1.CODTREZOR1 = G_STINGATOR.CODDOC;


         EXCEPTION WHEN OTHERS THEN aCODTREZOR := 0;    
             
       END;  


  
        IF aCODTREZOR &gt; 0  THEN
          
          SELECT COUNT(*) INTO NR FROM TREZOR1 WHERE CODTREZOR = aCODTREZOR;
          IF NR = 1 THEN 
             PKG_TREZOR.SP_DELETERECORD(aCODTREZOR);
            END IF;    
        END IF;  


     PKG_IESIRI.SP_DELETERECORD(aCODIES);
     UPDATE EMULARE
     SET
       CODIES = NULL
     WHERE
       CODEMULARE = aCODEMUL;
    END IF;  
    COMMIT;
  END;    


  FUNCTION GETTIPCASAMARCAT(aCODCASAMARCAT IN NUMBER) RETURN NUMBER
  IS
  aTIPCASA NUMBER(5) := 0;
  BEGIN
    BEGIN
      SELECT NVL(TIP, 0) INTO aTIPCASA FROM NCASEMARCAT WHERE CODCASEMARCAT = aCODCASAMARCAT;
      EXCEPTION WHEN OTHERS THEN aTIPCASA := 0;
    END;
    RETURN aTIPCASA;
  END;

 PROCEDURE SET_BONURI_PRELUATE(aCODMONETAR IN NUMBER)
 IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   UPDATE EMULARE E
   SET
     PRELUAT    = 1,
     CODMONETAR = aCODMONETAR
   WHERE
     EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = E.CODEMULARE);

   FOR V_REC IN 
   (SELECT CODIES, CODMONETAR 
    FROM 
      EMULARE E 
    WHERE
      NVL(CODIES, 0) &lt;&gt; 0
      AND EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = E.CODEMULARE)
      
   )
   LOOP
     UPDATE IESIRI
     SET
       CODMONETAR = V_REC.CODMONETAR
     WHERE
       CODIES = V_REC.CODIES;  
   END LOOP;       
  
   COMMIT;
 END;

 PROCEDURE GET_FROM_STOC_BY_CODBARE(CODBARE VARCHAR2, TIPCOD IN NUMBER)
 IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   DELETE TMP_EMUL_CODBARE;
   DELETE TMP_EMUL_CODBARE_AMB;

   IF TIPCOD = 2 THEN
     INSERT INTO TMP_EMUL_CODBARE(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST)
     SELECT
        NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
     FROM
       NIRSTOC NS, NARTOBJ O, NART A
     WHERE
       NS.CODOBIECT = O.CODOBIECT AND NS.REST &lt;&gt; 0 AND TRIM(O.CODINTERN) = CODBARE AND A.CODARTICOL = O.CODARTICOL
     UNION ALL
     SELECT
        NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
     FROM
       CODINTALT OA,
       NIRSTOC NS,
       NARTOBJ O,
       NART A
     WHERE
       NS.CODOBIECT = OA.CODOBIECT AND NS.REST &lt;&gt; 0 AND TRIM(OA.CODINTERN) = CODBARE AND OA.CODOBIECT = O.CODOBIECT AND A.CODARTICOL = O.CODARTICOL;
   ELSE
     INSERT INTO TMP_EMUL_CODBARE(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST)
     SELECT
        NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
     FROM
       NIRSTOC NS, NARTOBJ O, NART A
     WHERE
       NS.CODOBIECT = O.CODOBIECT AND NS.REST &lt;&gt; 0 AND TRIM(O.CODEXTERN) = CODBARE AND A.CODARTICOL = O.CODARTICOL
     UNION ALL
     SELECT
        NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
     FROM
       CODEXTALT OA,
       NIRSTOC NS,
       NARTOBJ O,
       NART A
     WHERE
       NS.CODOBIECT = OA.CODOBIECT AND NS.REST &lt;&gt; 0 AND TRIM(OA.CODEXTERN) = CODBARE AND OA.CODOBIECT = O.CODOBIECT AND A.CODARTICOL = O.CODARTICOL;
   END IF;


   IF TIPCOD = 2 THEN
     INSERT INTO TMP_EMUL_CODBARE_AMB(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST, UMAMBALARE)
     SELECT
        NS.CODOBIECT,
        A.CODARTICOL,
        NS.CODIOART,
        NS.PRET,
        NS.CODNIR,
        NS.REST,
        AMB.UMSEC
     FROM
       NIRSTOC NS,
       NARTAMB AMB,
       NARTOBJ O,
       NART A
     WHERE
       TRIM(AMB.CODINTERN) = CODBARE
       AND AMB.CODOBIECT = O.CODOBIECT
       AND NS.CODOBIECT = O.CODOBIECT
       AND NS.REST &lt;&gt; 0
       AND A.CODARTICOL = O.CODARTICOL;
   ELSE
     INSERT INTO TMP_EMUL_CODBARE_AMB(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST, UMAMBALARE)
     SELECT
        NS.CODOBIECT,
        A.CODARTICOL,
        NS.CODIOART,
        NS.PRET,
        NS.CODNIR,
        NS.REST,
        AMB.UMSEC
     FROM
       NIRSTOC NS,
       NARTAMB AMB,
       NARTOBJ O,
       NART A
     WHERE
       TRIM(AMB.CODEXTERN) = CODBARE
       AND AMB.CODOBIECT = O.CODOBIECT
       AND NS.CODOBIECT = O.CODOBIECT
       AND NS.REST &lt;&gt; 0
       AND A.CODARTICOL = O.CODARTICOL;
   END IF;



   COMMIT;
 END;


 PROCEDURE GET_FROM_STOC_BY_CODBARE_EXT(CODBARE VARCHAR2, TIPCOD IN NUMBER)
 IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   DELETE TMP_EMUL_CODBARE;
   IF TIPCOD = 2 THEN
     INSERT INTO TMP_EMUL_CODBARE(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST)
       SELECT
          NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
       FROM
         NIRSTOC NS, NARTOBJ O, NART A
       WHERE
         NS.CODOBIECT = O.CODOBIECT
         AND NS.REST &lt;&gt; 0
         AND (O.CODINTERN = CODBARE OR UPPER(O.DENUMIRE) LIKE &apos;%&apos; || UPPER(CODBARE) || &apos;%&apos;)
         AND A.CODARTICOL = O.CODARTICOL;
    ELSE
     INSERT INTO TMP_EMUL_CODBARE(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST)
       SELECT
          NS.CODOBIECT, A.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
       FROM
         NIRSTOC NS, NARTOBJ O, NART A
       WHERE
         NS.CODOBIECT = O.CODOBIECT
         AND NS.REST &lt;&gt; 0
         AND (O.CODEXTERN = CODBARE OR UPPER(O.DENUMIRE) LIKE &apos;%&apos; || UPPER(CODBARE) || &apos;%&apos;)
         AND A.CODARTICOL = O.CODARTICOL;
    END IF;
   COMMIT;
 END;


PROCEDURE GET_FROM_STOC_BY_CODOBIECT(aCODOBIECT IN NUMBER)
 IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   DELETE TMP_EMUL_CODBARE;
   INSERT INTO TMP_EMUL_CODBARE(CODOBIECT, CODARTICOL, CODIOART, PRETNIRSTOC, CODNIR, REST)
     SELECT
        NS.CODOBIECT, O.CODARTICOL, NS.CODIOART, NS.PRET, NS.CODNIR, NS.REST
     FROM
       NIRSTOC NS, NARTOBJ O
     WHERE
       NS.CODOBIECT = aCODOBIECT
       AND NS.REST &lt;&gt; 0
       AND NS.CODOBIECT = O.CODOBIECT;
   COMMIT;
 END;
  


 PROCEDURE LOCKNRBON(aCODCASAMARCAT IN NUMBER, aNRBON IN NUMBER)
 IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 NR NUMBER(10) := 0;
 BEGIN
   SELECT COUNT(*) INTO NR FROM NRBONLOCK 
   WHERE 
     USERID = PKG_GLOBALS.USERID 
     AND CODCASAMARCAT = aCODCASAMARCAT
     AND COALESCE(CONNINDEX, 0) = COALESCE(PKG_GLOBALS.ConnectionIndex, 0);
   IF NR = 0 THEN
     INSERT INTO NRBONLOCK (CODCASAMARCAT, USERID,USEDNO, CONNINDEX) VALUES(aCODCASAMARCAT, PKG_GLOBALS.USERID, aNRBON, PKG_GLOBALS.ConnectionIndex);
   ELSE
     UPDATE NRBONLOCK
     SET
       USEDNO = aNRBON
     WHERE
       USERID = PKG_GLOBALS.USERID 
       AND CODCASAMARCAT = aCODCASAMARCAT 
       AND COALESCE(CONNINDEX, 0) = COALESCE(PKG_GLOBALS.ConnectionIndex, 0);
   END IF;
   COMMIT;
 END;

 FUNCTION GETNEXTNRBON(aCODCASAMARCAT IN NUMBER, aDATABON VARCHAR2) RETURN NUMBER
 IS
  LASTNR NUMBER(20) := 0;
  DDataBon Date;
 BEGIN
   ddatabon := to_date(aDataBon, &apos;dd.mm.yyyy&apos;);
   SELECT MAX(NVL(NRBON, 0))  INTO LASTNR
   FROM
   (
   SELECT NVL(MAX(USEDNO), 0)AS NRBON
   FROM
     NRBONLOCK
   WHERE
    CODCASAMARCAT = aCODCASAMARCAT

   UNION ALL

   SELECT NVL(MAX(NRBON), 0) AS NRBON
   FROM
     EMULARE
   WHERE
    CODCASAMARCAT = aCODCASAMARCAT AND DATABON = DDATABON-- DATABON = TO_DATE(aDATABON, &apos;dd.mm.yyyy&apos;)
   );
   RETURN LASTNR + 1;
 END;


  PROCEDURE UNLOCKNRBON
  IS
   PRAGMA AUTONOMOUS_TRANSACTION;
  BEGIN
    DELETE FROM NRBONLOCK 
    WHERE 
      (USERID = PKG_GLOBALS.USERID AND COALESCE(CONNINDEX, 0) = COALESCE(PKG_GLOBALS.ConnectionIndex, 0)) OR USERID IS NULL;
    COMMIT;
  END;


PROCEDURE SETGESTIUNICASA(aCODCASADEMARCAT IN NUMBER)
IS
BEGIN
  DELETE TMP_GEST_CASA;
  INSERT INTO TMP_GEST_CASA(SELECT CODGESTIUNE FROM NCASEMARCAT1 WHERE CODCASEMARCAT = aCODCASADEMARCAT);
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodEmulare INTO Tmp FROM EMULARE WHERE CodEmulare = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
CODPARTOUT     NUMBER(20) := 0;
aCODPOSTRETAIL NUMBER(20) := 0;
aCodSubunit    NUMBER(20);
aDataDoc       DATE;
aDoc           VARCHAR2(200);
BEGIN
  SP_LOCKRECORD(RecId);

	SELECT c.subunitatea, e.databon, e.nrbon||&apos;/&apos;||e.databon
  INTO aCodSubunit, aDataDoc, aDoc
  FROM EMULARE  E INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
  WHERE E.CODEMULARE = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;EMULARE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

-- PUNCTE PE VALOARE
  BEGIN
    SELECT NVL(CODPART, 0)       INTO CODPARTOUT FROM EMULARE WHERE CODEMULARE = RECID;
    SELECT NVL(CODPOSTRETAIL, 0) INTO aCODPOSTRETAIL FROM EMULARE WHERE CODEMULARE = RECID;
    EXCEPTION WHEN OTHERS THEN CODPARTOUT := 0; aCODPOSTRETAIL := 0;
  END;

  IF CODPARTOUT &lt;&gt; 0 THEN
    DELETE FROM PARTPUNCTE
    WHERE
     CODPART = CODPARTOUT
     AND CODEMULARE = RecId
     AND CODPOSTRETAIL = aCODPOSTRETAIL;
  END IF;


  DELETE FROM EMULSTINGERI WHERE CODEMULARE = RECID;
 	DELETE FROM EMULARE1     WHERE CodEmulare = RecId ;
  DELETE FROM EMULARE2     WHERE CodEmulare = RecId ;
  DELETE FROM TRANSACARD   WHERE CodEmulare = RecId ;

  DELETE FROM VOUCHERCADOULINK WHERE CODDOC = RECID AND TIPDOC = 64;


  DELETE FROM EMULPUNCTEUSED WHERE CodEmulare = RecId ;


  DELETE FROM EMULARE  WHERE CodEmulare = RecId ;
  NotifyModif(2, RecId, &apos;EMULARE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EMULARE FIELDS( CodEmulare ) VALUES (0) ;
  CODPARTIN := 0;

  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aCODIES      NUMBER(20) := 0;
  NR           NUMBER(5)  := 0;
  
  aAN          number(4);
  aLuna        number(2);
  anLunaLucru  number(5);         
BEGIN
  INSERT INTO  TMP_EMULARE ( CodEmulare, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, CODIES, CODPART, CODPERS,  INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, OBS, TEXTNEFISCAL, FACTSIMPLIF, IDBON, FACTURARE, CODCATPRETPART, TIPCATPRETPART,
                             DELEGAT, EXCLUSDISCOUNT, INFODELEGAT, FACTANULAT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL,
                             VALVALUTA )
    ( SELECT CodEmulare, NrBon, DataBon, Valoare, ValoareDiscount, E.Listat, Preluat, CodCasaMarcat, TVATOTAL, E.TVADISCOUNT, E.TIPCASAMARCAT, E.CODIES, E.CODPART, E.CODPERS,  INCASARECLIENT, CODPOSTRETAIL, E.CODAECUSTODIE, E.CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, E.OBS, TEXTNEFISCAL, E.FACTSIMPLIF, IDBON,FACTURARE,
             P.CODCATEGPRET, CAT.TIP, E.DELEGAT, E.EXCLUSDISCOUNT, D.DELEGAT, I.ANULAT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL,
             VALVALUTA
      FROM
        EMULARE E
        LEFT OUTER JOIN NPART P ON P.CODPART = E.CODPART
        LEFT OUTER JOIN NCATPRET CAT ON CAT.CODCATPRET = P.CODCATEGPRET
        LEFT JOIN NPARTTR D ON D.CODPARTTR = E.DELEGAT
        LEFT JOIN IESIRI I ON E.CODIES = I.CODIES
      WHERE
        CodEmulare = RecId ) ;
    --returo    64 ---- tipdoc emulare
    insert into TMP_RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
     select  rs.CODRETUROSTINS,
                rs.CODRETURO,
                rs.CODDOC,
                rs.TIPDOC,
                rs.VALOARE,
                rs.STARTEDAT,
                rs.VOUCHERBARCODE
     from RETUROSTINS rs where rs.tipdoc = 64 and rs.coddoc = RecId;

  BEGIN
    SELECT NVL(CODIES, 0), extract(year from databon), extract(month from databon) INTO aCODIES, aAN, aLUNA FROM TMP_EMULARE;
    EXCEPTION WHEN OTHERS THEN aCODIES := 0; aAn := 0; aLuna :=0;
  END;

  AnLunaLucru := aAN * 12 + aLuna;

  INSERT INTO TMP_EMULSTINGERI (CODEMULSTINGERE, CODEMULARE, CODOBLIGPIF, VALOARE, TIPDOCSTINS, SEMNIFDOCSTINS)
  SELECT
    ES.CODEMULSTINGERE,
    ES.CODEMULARE,
    ES.CODOBLIGPIF,
    ES.VALOARE,
    G.TIPDOC,
    G.SEMNIFICATIE
   FROM
     EMULSTINGERI ES,
     OBLIGPIF O,
     GENERAL G
   WHERE
     ES.CODEMULARE = RECID
     AND O.CODOBLIGPIF = ES.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL;

/*
  IF aCODIES &lt;&gt; 0 THEN
    SELECT COUNT(*) INTO NR FROM IESIRI WHERE CODIES = aCODIES;
    IF NR = 0 THEN
      UPDATE TMP_EMULARE
      SET
        CODIES = 0;
    END IF;
  END IF;
*/
  UPDATE TMP_EMULARE E
  SET
   INFOFACTURA = (SELECT TO_CHAR(NRDOC) || &apos;/&apos; || TO_CHAR(DATADOC, &apos;DD.MM.YYYY&apos;) FROM IESIRI WHERE CODIES = E.CODIES),
   INFOCLIENT  = CASE
                   WHEN NVL(E.CODPART, 0)      &lt;&gt; 0 THEN (SELECT DEN_PART FROM NPART P WHERE P.CODPART = E.CODPART)
                   WHEN NVL(E.CODPARTRETAIL, 0) &lt;&gt; 0 THEN (SELECT DENUMIRE FROM NPARTRETAIL PR WHERE PR.CODPARTRETAIL = E.CODPARTRETAIL)
                 END;                   

  INSERT INTO TMP_EMULARE1
  (  CodEmulare1,
     CodEmulare,
     CodObiect,
     IndexLocal,
     PretArt,
     Pret,
     Cant,
     UmSec,
     DENUM,
     Discount,
     TVA,
     CODGEST,
     CODIOART,
     PRETNIRSTOC,
     TIPLINIE,
     PROCTVA,
     PARITATE,
     DENOBIECT,
     CODEXTERN,
     CODINTERN,
     VALOARE,
     CODEMULSTINGERE,
     CONTSERV,
     FARASTOC,
     CODCOMANDA1,
     TIPLIVRARE,
     CADOU,
     PRETPROMO,
     CODGESTORIG,
     CODNIRSTOCREZ,
     CODNIRSERREZ,
     DISCMANUAL,
     PROMOTIE,
     CODCLASA,
     CODSERIE,
     CODTRANSF1,
     PRETNEPROMO,
     PROMOTIONAT,
     FORCEPROMO,
     INFOPROMO,
     INFOPROMODISC,
     CODPROMO1,
     PROCTVABON,
     TAXA,
     CODEMUL1AVANS
    )
    ( SELECT
       CodEmulare1,
       CodEmulare,
       E1.CodObiect,
       E1.IndexLocal,
       PretArt * u1.Paritate,
       Pret * u1.Paritate,
       Cant /  u1.Paritate,
       UmSec,
       U1.DEN_UM1,
       Discount,
       TVA,
       CODGEST,
       CODIOART,
       PRETNIRSTOC,
       TIPLINIE,
       COALESCE(PROCTVABON, PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)),
       U1.PARITATE,
       O.DENUMIRE,
       O.CODEXTERN,
       O.CODINTERN,
       PRET * CANT,
       CODEMULSTINGERE,
       CONTSERV,
       E1.FARASTOC,
       CODCOMANDA1,
       TIPLIVRARE,
       CADOU,
       PRETPROMO,
       CODGESTORIG,
       CODNIRSTOCREZ,
       CODNIRSERREZ,
       DISCMANUAL,
       O.PROMOTIE,
       A.CLASA,
       E1.CODSERIE,
       E1.CODTRANSF1,
       E1.PRETNEPROMO,
       E1.PROMOTIONAT,
       E1.FORCEPROMO,
       E1.INFOPROMO,
       E1.INFOPROMODISC,
       E1.CODPROMO1,
       E1.PROCTVABON,
       E1.TAXA,
       E1.CODEMUL1AVANS
      FROM
         EMULARE1 E1
         left outer join NartObj o on o.CodObiect  = E1.CodObiect
         left outer join Nart a    on a.CodArticol = o.CodArticol,
         NUM1 u1
      WHERE
         CodEmulare = RecId AND  u1.CodUM1 = E1.UmSec
       ) ORDER BY INDEXLOCAL ;

  INSERT INTO  TMP_EMULARE2 ( CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD )
    ( SELECT CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD FROM EMULARE2 WHERE CodEmulare = RecId );


  INSERT INTO TMP_EMULSTINGERI_INITIAL SELECT * FROM TMP_EMULSTINGERI;

  UPDATE TMP_EMULSTINGERI ES
  SET
   INFO =  CASE
             WHEN ES.TIPDOCSTINS = 35 THEN (SELECT &apos;NC&apos; || TO_CHAR(NC.NRDOC) || &apos;/&apos; || TO_CHAR(NC.DATADOC, &apos;dd.mm.yyyy&apos;) FROM NC NC, NC1 NC1, GENERAL G, OBLIGPIF O WHERE O.CODOBLIGPIF = ES.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL AND NC1.CODNC1 = G.CODDOC AND NC.CODNC = NC1.CODNC)
             ELSE (SELECT I.PREFIXDOC || TO_CHAR(I.NRDOC) || &apos;/&apos; || TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;) FROM IESIRI I, GENERAL G, OBLIGPIF O WHERE O.CODOBLIGPIF = ES.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL AND I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC)
           END  ;



   FOR V_REC IN (SELECT * FROM TMP_EMULARE1 WHERE NVL(CODEMULSTINGERE, 0) &lt;&gt; 0)
   LOOP
     UPDATE TMP_EMULARE1 E1
     SET
       DENOBIECT = DENOBIECT || &apos;/&apos; || NVL((SELECT INFO FROM TMP_EMULSTINGERI WHERE CODEMULSTINGERE = E1.CODEMULSTINGERE), &apos;&apos;)
     WHERE
       CODEMULARE1 = V_REC.CODEMULARE1;
   END LOOP;

   BEGIN
     SELECT NVL(CODPART, 0) INTO CODPARTIN FROM TMP_EMULARE;
     EXCEPTION WHEN OTHERS THEN CODPARTIN := 0;
   END;


   INSERT INTO TMP_EMULPUNCTEUSED(COD, CODEMULARE, CODPUNCTAJ, PUNCTEUSED, VALACORDATA, INFOPUNCTAJ)
   SELECT
     E.COD, E.CODEMULARE, E.CODPUNCTAJ, E.PUNCTEUSED, E.VALACORDATA, P.DENUMIRE
   FROM
    EMULPUNCTEUSED E
    LEFT OUTER JOIN PUNCTAJE P ON P.CODPUNCTAJ = E.CODPUNCTAJ
   WHERE
    CODEMULARE = RECID;


  UPDATE TMP_EMULARE
  SET
   (TOTALPUNCTEUSED, TOTALVALPUNCTE) = (SELECT NVL(SUM(PUNCTEUSED),0), NVL(SUM(VALACORDATA),0) FROM TMP_EMULPUNCTEUSED);


  FOR V_REC IN (SELECT * FROM TMP_EMULARE1 WHERE NVL(CODCOMANDA1, 0)+ NVL(CODTRANSF1, 0) &lt;&gt; 0)
  LOOP
    UPDATE TMP_EMULARE1 E1
    SET
     NRDOCLINK = CASE 
                   WHEN NVL(CODCOMANDA1, 0) &lt;&gt; 0 THEN (SELECT &apos;Cc &apos; || TO_CHAR(NRDOC) FROM COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = E1.CODCOMANDA1 AND C1.CODCOMANDA = C.CODCOMANDA)
                   WHEN NVL(CODTRANSF1, 0) &lt;&gt; 0 THEN  (SELECT &apos;NT &apos; || TO_CHAR(NRDOC) FROM TRANSF1 T1, TRANSF T WHERE T1.CODTRANSF1 = E1.CODTRANSF1 AND T1.CODTRANSF = T.CODTRANSF)
                  END 
    WHERE
      CODEMULARE1 = E1.CODEMULARE1;
  END LOOP;

  INSERT INTO TMP_TRANSACARD SELECT * FROM TRANSACARD WHERE CODEMULARE = RECID;

  FOR V_REC IN
  (SELECT E1.CODEMULARE1 
    FROM 
      TMP_EMULARE1 E1 
      INNER JOIN  ( SELECT 
                     DISTINCT CV.VALOARE 
                   FROM 
                      CONST1 C1 
                      INNER JOIN 
                      (SELECT CODCONST1, CODCONSTLUNA 
                        FROM 
                          CONSTLUNA WHERE 
                          ALSTART &lt;= AnLunaLucru  AND ALSTOP &gt;= AnLunaLucru
                       ) CL   ON C1.CODCONST1 = CL.CODCONST1 
                       INNER JOIN CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA 
                      WHERE  
                        UPPER(SIMBOL) = &apos;ARTVOUCHERCADOU&apos;
                  ) VOUCHER ON VOUCHER.VALOARE = TO_CHAR(E1.CODOBIECT)
    )
    LOOP
      UPDATE TMP_EMULARE1
      SET
        VOUCHERCADOU = 1
      WHERE
        CODEMULARE1 = V_REC.CODEMULARE1;  
    END LOOP;                  


  INSERT INTO TMP_VOUCHERCADOULINK(COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT)
  SELECT COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT
  FROM
    VOUCHERCADOULINK
  WHERE
    TIPDOC = 64
    AND CODDOC = RECID;  
  
  DELETE TMP_VOUCHERCADOULINK_INI;
  
  INSERT INTO TMP_VOUCHERCADOULINK_INI(TIPOPERATIE, BARCODE) SELECT TIPOPERATIE, BARCODE FROM TMP_VOUCHERCADOULINK;


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  VCOD           NUMBER(10);
  CODPARTOUT     NUMBER(20) := 0;
  aCODPOSTRETAIL NUMBER(20) := 0;
  aCODPART       NUMBER(20) := 0;
  VALBON         NUMBER(20, 7) := 0;
  aDATABON       DATE;
  NR             NUMBER(20)    := 0;
  VALPUNCTE      NUMBER(20, 7) := 0;
  aPUNCTEUSED    NUMBER(20)    := 0;
  aVALPUNCTEUSED NUMBER(20, 7) := 0;
  aCodSubunit    NUMBER(20);
  aDataDoc       DATE;
  aDoc           VARCHAR2(200);
  aFIDELIZARE    NUMBER(1) := 0;
  aCODIESRETAIL  NUMBER(20);
  aCODPARTRETAIL NUMBER(20);
  aOBS           VARCHAR2(100);
  aFACTURARE     NUMBER;
  StergRezCMDInchisa VARCHAR2(10);
  
BEGIN
/*  
  INSERT INTO TMP_EMULARE1 E1
  SELECT * FROM TMP_EMULARE1_BACKUP E1B 
  WHERE
    E1B.INDEXLOCAL NOT IN (SELECT INDEXLOCAL FROM TMP_EMULARE1); 
    
*/


	SELECT c.subunitatea, e.databon, e.nrbon||&apos;/&apos;||e.databon, CODIESRETAIL, OBS, FACTURARE, NVL(CODPARTRETAIL, 0), NVL(CODPART, 0)
  INTO aCodSubunit, aDataDoc, aDoc, aCODIESRETAIL, aOBS, aFACTURARE, aCODPARTRETAIL, aCODPART 
  FROM TMP_EMULARE  E INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat;

  StergRezCMDInchisa :=  NVL(pkg_categconst.GetValConstanta(&apos;StergRezCMDInchisa&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;) ;
  

  BEGIN
    SELECT NVL(FIDELIZARE, 0) INTO aFIDELIZARE

    FROM
      TMP_EMULARE E,
      NPART P
    WHERE
      E.CODPART = P.CODPART;
    EXCEPTION WHEN OTHERS THEN aFIDELIZARE := 0;
  END;


  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodEmulare INTO RecId FROM TMP_EMULARE;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;EMULARE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    
    UPDATE EMULARE SET ( NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, DATALISTARE, CODPART, CODPERS, CODIES, INCASARECLIENT,  CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, OBS, TEXTNEFISCAL, FACTSIMPLIF, IDBON, FACTURARE,
                         DELEGAT, EXCLUSDISCOUNT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL, VALVALUTA)
       = ( SELECT NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, DATALISTARE, CODPART, CODPERS,  CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, OBS, TEXTNEFISCAL, FACTSIMPLIF, IDBON, FACTURARE,
                  DELEGAT, EXCLUSDISCOUNT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL, VALVALUTA
          FROM TMP_EMULARE )
    WHERE
      CodEmulare = RecId ;

    DELETE FROM EMULARE1 where CodEmulare = RecId and CodEmulare1 not in (Select CodEmulare1 from TMP_EMULARE1);
    --returo    64 ---- tipdoc emulare
    DELETE FROM RETUROSTINS where tipdoc = 64 
                                                      and coddoc = RecId
                                                      and CODRETUROSTINS not in (Select CODRETUROSTINS from TMP_RETUROSTINS);


  DELETE
  FROM
    EMULSTINGERI ES
  WHERE
    CODEMULARE = RECID AND NOT EXISTS (SELECT CODEMULSTINGERE FROM TMP_EMULSTINGERI WHERE CODEMULSTINGERE = ES.CODEMULSTINGERE);


   FOR V_REC IN (SELECT * FROM TMP_EMULSTINGERI )
   LOOP
     IF V_REC.CODEMULSTINGERE &lt; 0 THEN
       SELECT SEQ_EMULSTINGERI_COD.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_EMULARE1
       SET
         CODEMULSTINGERE = VCOD
       WHERE
         CODEMULSTINGERE = V_REC.CODEMULSTINGERE;

       INSERT INTO EMULSTINGERI(CODEMULSTINGERE, CODEMULARE, CODOBLIGPIF, VALOARE)
       VALUES
       (VCOD, RECID, V_REC.CODOBLIGPIF, V_REC.VALOARE);
     ELSE
       UPDATE EMULSTINGERI
       SET
         CODOBLIGPIF = V_REC.CODOBLIGPIF,
         VALOARE     = V_REC.VALOARE
       WHERE
        CODEMULSTINGERE = V_REC.CODEMULSTINGERE;
     END IF;
   END LOOP;


    INSERT INTO EMULARE1
    ( CodEmulare1,
      CodEmulare,
      CodObiect,
      INDEXLOCAL,
      PretArt,
      Pret,
      Cant  ,
      UmSec,
      Discount,
      TIPLINIE,
      TVA,
      CODGEST,
      CODIOART,
      PRETNIRSTOC,
      CONTSERV,
      FARASTOC,
      CODCOMANDA1,
      TIPLIVRARE,
      CADOU,
      PRETPROMO,
      CODGESTORIG,
      CODNIRSTOCREZ,
      CODNIRSERREZ,
      DISCMANUAL,
      CODEMULSTINGERE,
      CODSERIE,
      CODTRANSF1,
      PRETNEPROMO,
      PROMOTIONAT,
      FORCEPROMO,
      INFOPROMO,
      INFOPROMODISC,
      CODPROMO1,
      PROCTVABON,
      TAXA,
      CODEMUL1AVANS
 )
      SELECT
       SEQ_EMULARE1_CODEMULARE1.Nextval ,
       RecId ,
       CodObiect,
       INDEXLOCAL,
       PretArt / PARITATE,
       Pret / PARITATE,
       Cant * PARITATE,
       UmSec,
       Discount,
       TIPLINIE,
       TVA,
       CODGEST,
       CODIOART,
       PRETNIRSTOC,
       CONTSERV,
       FARASTOC,
       CODCOMANDA1,
       TIPLIVRARE,
       CADOU,
       PRETPROMO,
       CODGESTORIG,
       CODNIRSTOCREZ,
       CODNIRSERREZ,
       DISCMANUAL,
       CODEMULSTINGERE,
       CODSERIE,
       CODTRANSF1,
       PRETNEPROMO,
       PROMOTIONAT,
       FORCEPROMO,
       INFOPROMO,
       INFOPROMODISC,
       CODPROMO1,
       PROCTVABON,
       TAXA,
       CODEMUL1AVANS
      FROM
       TMP_EMULARE1 WHERE CodEmulare1 &lt; 0;-- adaugam inregistrarile noi ;
      --returo 
       insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  SEQ_RETUROSTINS_CODRETUROSTINS.Nextval,
                  rs.CODRETURO,
                  RecId,
                  64,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs where rs.CODRETUROSTINS &lt; 0;
       
       FOR v_rec IN ( SELECT * FROM TMP_RETUROSTINS WHERE NVL(CODRETUROSTINS,-1) &gt; 0 ORDER BY CODRETUROSTINS ) LOOP
           update RETUROSTINS 
            set CODRETURO            = v_rec.CODRETURO,
                  CODDOC                 = v_rec.CODDOC,
                  TIPDOC                   = v_rec.TIPDOC,
                  VALOARE                 = v_rec.VALOARE,
                  STARTEDAT              = v_rec.STARTEDAT,
                  VOUCHERBARCODE  = v_rec.VOUCHERBARCODE
             WHERE
                   CODRETUROSTINS  = v_rec.CODRETUROSTINS;                  
                  
       END LOOP;  
    -- si facem update la cele care au ramas
    FOR v_rec IN ( SELECT * FROM TMP_EMULARE1 WHERE NVL(CodEmulare1,-1) &gt; 0 ORDER BY CodEmulare1 ) LOOP
       UPDATE EMULARE1
       SET
        CodEmulare       = v_rec.CodEmulare,
        CodObiect        = v_rec.CodObiect,
        INDEXLOCAL       = v_rec.INDEXLOCAL,
        PretArt          = v_rec.PretArt / V_REC.PARITATE,
        Pret             = v_rec.Pret / V_REC.PARITATE,
        Cant             = v_rec.Cant * V_REC.PARITATE,
        UmSec            = v_rec.UmSec,
        Discount         = v_rec.Discount,
        TVA              = v_rec.TVA,
        TIPLINIE         = v_rec.TIPLINIE,
        CODGEST          = V_REC.CODGEST,
        CODIOART         = V_REC.CODIOART,
        PRETNIRSTOC      = V_REC.PRETNIRSTOC,
        CONTSERV         = V_REC.CONTSERV,
        FARASTOC         = V_REC.FARASTOC,
        CODCOMANDA1      = V_REC.CODCOMANDA1,
        TIPLIVRARE       = V_REC.TIPLIVRARE,
        CADOU            = V_REC.CADOU,
        PRETPROMO        = V_REC.PRETPROMO,
        CODGESTORIG      = V_REC.CODGESTORIG,
        CODNIRSTOCREZ    = V_REC.CODNIRSTOCREZ,
        CODNIRSERREZ     = V_REC.CODNIRSERREZ,
        DISCMANUAL       = V_REC.DISCMANUAL,
        CODEMULSTINGERE  = V_REC.CODEMULSTINGERE,
        CODSERIE         = V_REC.CODSERIE,
        CODTRANSF1       = V_REC.CODTRANSF1,
        PRETNEPROMO      = V_REC.PRETNEPROMO,
        PROMOTIONAT      = V_REC.PROMOTIONAT,
        FORCEPROMO       = V_REC.FORCEPROMO,
        INFOPROMO        = V_REC.INFOPROMO,
        INFOPROMODISC    = V_REC.INFOPROMODISC,
        CODPROMO1        = V_REC.CODPROMO1,
        PROCTVABON       = V_REC.PROCTVABON,
        TAXA             = V_REC.TAXA,
        CODEMUL1AVANS    = V_REC.CODEMUL1AVANS
       WHERE
         CodEmulare1  = v_rec.CodEmulare1;
    END LOOP;

    DELETE FROM EMULARE2 where CodEmulare = RecId and CodEmulare2 not in (Select CodEmulare2 from TMP_EMULARE1);
    DELETE FROM TRANSACARD where CodEmulare = RecId and CodTRANSACARD not in (Select CODTRANSACARD from TMP_TRANSACARD);

    INSERT INTO EMULARE2 ( CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD )
      SELECT  SEQ_EMULARE2_CODEMULARE2.Nextval , RecId , TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD
      FROM TMP_EMULARE2 WHERE CodEmulare2 &lt; 0;-- adaugam inregistrarile noi ;


    INSERT INTO TRANSACARD (CODTRANSACARD,CODEMULARE, VALOARE)
      SELECT SEQ_TRANSACARD_CODTRANSACARD.Nextval , RecId , Valoare
      FROM 
        TMP_TRANSACARD 
     WHERE 
       CODTRANSACARD &lt; 0;-- adaugam inregistrarile noi ;

    -- si facem update la cele care au ramas
    FOR v_rec IN ( SELECT * FROM TMP_EMULARE2 WHERE NVL(CodEmulare2,-1) &gt; 0 ) LOOP
       UPDATE EMULARE2
       SET
        CodEmulare       = v_rec.CodEmulare,
        TipPlata         = v_rec.TipPlata,
        CODBANKCONT      = V_REc.CODBANKCONT,
        Valoare          = v_rec.Valoare,
        Denumire         = v_rec.Denumire,
        CODCARD          = V_REC.CODCARD
       WHERE
         CodEmulare2  = v_rec.CodEmulare2;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TRANSACARD WHERE CODTRANSACARD &gt; 0)
    LOOP
      UPDATE TRANSACARD
      SET
        VALOARE = V_REC.VALOARE
      WHERE
        CODTRANSACARD = V_REC.CODTRANSACARD;
    END LOOP;    


-- detail VOUCHERCADOULINK

      DELETE FROM VOUCHERCADOULINK 
      WHERE
        CODDOC = RECID
        AND TIPDOC = 64
        AND COD NOT IN (SELECT COD FROM TMP_VOUCHERCADOULINK);

      FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
      LOOP
        IF V_REC.COD &lt; 0 THEN
          INSERT INTO VOUCHERCADOULINK
          (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
          VALUES
          (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, 64, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
        ELSE
          UPDATE VOUCHERCADOULINK
          SET
            BARCODE     = V_REC.BARCODE, 
            VALOARE     = V_REC.VALOARE,
            DATASTART   = V_REC.DATASTART,
            DATASTOP    = V_REC.DATASTOP,
            ZILEVALABIL = V_REC.ZILEVALABIL,
            CODOBIECT   = V_REC.CODOBIECT,
            POSTAT      = V_REC.POSTAT
          WHERE
            COD = V_REC.COD;
        END IF;    
      END LOOP;      

    FOR V_REC IN
   (
    SELECT *
    FROM
      EMULPUNCTEUSED
    WHERE
      CODEMULARE = RECID
      AND COD NOT IN (SELECT COD FROM TMP_EMULPUNCTEUSED)
    )
    LOOP
      DELETE FROM PARTPUNCTE WHERE CODPUNCTAJ = V_REC.CODPUNCTAJ AND CODEMULARE = V_REC.CODEMULARE AND PUNCTE &lt; 0;
      DELETE FROM EMULPUNCTEUSED WHERE COD = V_REC.COD;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_EMULPUNCTEUSED)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO EMULPUNCTEUSED(COD, CODEMULARE, CODPUNCTAJ, PUNCTEUSED, VALACORDATA)
        VALUES (SEQ_EMULPUNCTEUSED_COD.NEXTVAL, RECID, V_REC.CODPUNCTAJ, V_REC.PUNCTEUSED, V_REC.VALACORDATA);
      ELSE
        UPDATE EMULPUNCTEUSED
        SET
          PUNCTEUSED  = V_REC.PUNCTEUSED,
          VALACORDATA = V_REC.VALACORDATA
        WHERE
         COD = V_REC.COD;
      END IF;
    END LOOP;


  ELSE  -- INSERT
-- Master Nautom
    SELECT seq_emulare_codemulare.NextVal INTO RecId FROM DUAL;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;EMULARE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    
    INSERT INTO  EMULARE ( CodEmulare, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, USERID, DATACREARE, DATALISTARE, CODPART, CODPERS,  CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, OBS, TEXTNEFISCAL, FACTSIMPLIF, IDBON, FACTURARE,
                           DELEGAT, EXCLUSDISCOUNT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL, VALVALUTA )
   ( SELECT  RecId, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, PKG_GLOBALS.USERID, SYSTIMESTAMP, DATALISTARE, CODPART, CODPERS,  CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CodPartComis, CODPARTRETAILCOMIS, CODAGENT, OBS, TEXTNEFISCAL, FACTSIMPLIF, IDBON, FACTURARE,
             DELEGAT, EXCLUSDISCOUNT, CODPARTRETAIL, CODIESRETAIL, CODSEDIURETAIL, PUNCTECUMUL, VALPUNCTECUMUL, DELEGATRETAIL, VALVALUTA
     FROM TMP_EMULARE  ) ;


/*
    INSERT INTO EMULSTINGERI (CODEMULSTINGERE, CODEMULARE, CODOBLIGPIF, VALOARE)
    SELECT SEQ_EMULSTINGERI_COD.NEXTVAL, RECID, CODOBLIGPIF, VALOARE FROM TMP_EMULSTINGERI;
*/


   FOR V_REC IN (SELECT * FROM TMP_EMULSTINGERI )
   LOOP
       SELECT SEQ_EMULSTINGERI_COD.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_EMULARE1
       SET
         CODEMULSTINGERE = VCOD
       WHERE
         CODEMULSTINGERE = V_REC.CODEMULSTINGERE;

       INSERT INTO EMULSTINGERI(CODEMULSTINGERE, CODEMULARE, CODOBLIGPIF, VALOARE)
       VALUES
       (VCOD, RECID, V_REC.CODOBLIGPIF, V_REC.VALOARE);
   END LOOP;



    INSERT INTO EMULARE1
    ( CodEmulare1,
      CodEmulare,
      CodObiect,
      INDEXLOCAL,
      PretArt,
      Pret,
      Cant  ,
      UmSec,
      Discount,
      TIPLINIE,
      TVA,
      CODGEST,
      CODIOART,
      PRETNIRSTOC,
      CONTSERV,
      FARASTOC,
      CODCOMANDA1,
      TIPLIVRARE,
      CADOU,
      PRETPROMO,
      CODGESTORIG,
      CODNIRSTOCREZ,
      CODNIRSERREZ,
      DISCMANUAL,
      CODEMULSTINGERE,
      CODSERIE,
      CODTRANSF1,
      PRETNEPROMO,
      PROMOTIONAT,
      FORCEPROMO,
      INFOPROMO,
      INFOPROMODISC,
      CODPROMO1,
      PROCTVABON,
      TAXA,
      CODEMUL1AVANS
 )
      SELECT
       SEQ_EMULARE1_CODEMULARE1.Nextval ,
       RecId ,
       CodObiect,
       INDEXLOCAL,
       PretArt / PARITATE,
       Pret / PARITATE,
       Cant * PARITATE,
       UmSec,
       Discount,
       TIPLINIE,
       TVA,
       CODGEST,
       CODIOART,
       PRETNIRSTOC,
       CONTSERV,
       FARASTOC,
       CODCOMANDA1,
       TIPLIVRARE,
       CADOU,
       PRETPROMO,
       CODGESTORIG,
       CODNIRSTOCREZ,
       CODNIRSERREZ,
       DISCMANUAL,
       CODEMULSTINGERE,
       CODSERIE,
       CODTRANSF1,
       PRETNEPROMO,
       PROMOTIONAT,
       FORCEPROMO,
       INFOPROMO,
       INFOPROMODISC,
       CODPROMO1,
       PROCTVABON,
       TAXA,
       CODEMUL1AVANS
      FROM
       TMP_EMULARE1;
       
       insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  SEQ_RETUROSTINS_CODRETUROSTINS.Nextval,
                  rs.CODRETURO,
                  RecId ,
                  64,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs ;
       
    INSERT INTO EMULARE2 ( CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD )
      SELECT  SEQ_EMULARE2_CODEMULARE2.Nextval , RecId, TipPlata, Valoare, Denumire, CODBANKCONT, CODCARD
      FROM TMP_EMULARE2 ;

    INSERT INTO TRANSACARD (CODTRANSACARD,CODEMULARE, VALOARE)
      SELECT SEQ_TRANSACARD_CODTRANSACARD.Nextval , RecId , Valoare
      FROM 
        TMP_TRANSACARD;


    FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
    LOOP
      INSERT INTO VOUCHERCADOULINK 
        (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
        VALUES
        (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, 64, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
    END LOOP;


     INSERT INTO EMULPUNCTEUSED(COD, CODEMULARE, CODPUNCTAJ, PUNCTEUSED, VALACORDATA)
     SELECT SEQ_EMULPUNCTEUSED_COD.NEXTVAL, RECID, CODPUNCTAJ, PUNCTEUSED, VALACORDATA FROM TMP_EMULPUNCTEUSED;


  END IF;

-- PUNCTE PE VALOARE
  SELECT NVL(CODPART, 0)       INTO CODPARTOUT FROM TMP_EMULARE;
  SELECT NVL(CODPOSTRETAIL, 0) INTO aCODPOSTRETAIL FROM TMP_EMULARE;
  SELECT NVL(VALOARE, 0) INTO VALBON FROM TMP_EMULARE;
  SELECT DATABON   INTO aDATABON FROM TMP_EMULARE;

  IF (CODPARTIN &lt;&gt; 0)AND(CODPARTIN &lt;&gt; CODPARTOUT) THEN
    DELETE FROM PARTPUNCTE
    WHERE
      CODPART = CODPARTIN AND CODEMULARE = RECID;
  END IF;

  IF (CODPARTOUT &gt; 0)AND(aFIDELIZARE = 1) THEN

    FOR V_REC IN
   (
    SELECT P.CODPUNCTAJ, NVL(PUNCTE, 0) * TRUNC(VALBON / LIMITAVAL) AS PUNCTE
    FROM
      PUNCTAJVALDOC PV,
      PUNCTAJE P
    WHERE
      PV.CODPUNCTAJ = P.CODPUNCTAJ
      AND P.TIP = 1
      AND P.DATASTART &lt;= aDATABON
      AND P.DATAEND   &gt;= aDATABON
      AND PV.LIMITAVAL &lt;&gt; 0
   )
   LOOP
     IF V_REC.PUNCTE = 0 THEN
       DELETE FROM PARTPUNCTE PP
       WHERE
         CODPART        = CODPARTOUT
         AND CODEMULARE = RECID
         AND CODPUNCTAJ = V_REC.CODPUNCTAJ
         AND NVL(CODPOSTRETAIL, 0) = aCODPOSTRETAIL
         AND PUNCTE &gt; 0;
     ELSE
      BEGIN
         SELECT
           VALACORDATA * V_REC.PUNCTE / PUNCTE INTO VALPUNCTE
         FROM
           PUNCTEUSE
         WHERE
           CODPUNCTAJ = V_REC.CODPUNCTAJ
           AND NVL(PUNCTE, 0) &gt; 0
           AND ROWNUM = 1;
         EXCEPTION WHEN OTHERS THEN VALPUNCTE := 0;       
       END;
       SELECT COUNT(*) INTO NR
       FROM
         PARTPUNCTE PP
       WHERE
         CODEMULARE = RECID
         AND CODPART = CODPARTOUT
         AND NVL(CODPOSTRETAIL, 0) = aCODPOSTRETAIL
         AND CODPUNCTAJ = V_REC.CODPUNCTAJ
         AND PUNCTE &gt; 0;


       IF NR = 0 THEN
         INSERT INTO PARTPUNCTE(COD, CODPART, DATA, CODEMULARE, PUNCTE, CODPUNCTAJ, VALOARE, CODPOSTRETAIL)
         VALUES (SEQ_PARTPUNCTE_COD.NEXTVAL, CODPARTOUT, aDATABON, RECID, V_REC.PUNCTE, V_REC.CODPUNCTAJ, VALPUNCTE, aCODPOSTRETAIL);
       ELSE
         UPDATE PARTPUNCTE
         SET
           PUNCTE  = V_REC.PUNCTE,
           VALOARE = VALPUNCTE
         WHERE
           CODEMULARE     = RECID
           AND CODPART    = CODPARTOUT
           AND CODPUNCTAJ = V_REC.CODPUNCTAJ
           AND PUNCTE &gt; 0
           AND NVL(CODPOSTRETAIL, 0) = aCODPOSTRETAIL;
       END IF;
     END IF;
   END LOOP;

  END IF;


  -- STORNARE PUNCTE PRELUATE PE BONUL CURENT;
  IF aFIDELIZARE = 1 THEN
    DELETE FROM PARTPUNCTE PP
    WHERE
      CODPART        = CODPARTOUT
      AND CODEMULARE = RECID
      AND NVL(CODPOSTRETAIL, 0) = aCODPOSTRETAIL
      AND PUNCTE &lt; 0;

    FOR V_REC IN (SELECT * FROM TMP_EMULPUNCTEUSED) LOOP
      INSERT INTO PARTPUNCTE
      (COD,
       CODPART,
       DATA,
       CODEMULARE,
       CODPUNCTAJ,
       PUNCTE,
       VALOARE,
       CODPOSTRETAIL
      )
      VALUES
      (SEQ_PARTPUNCTE_COD.NEXTVAL,
       CODPARTOUT,
       aDATABON,
       RECID,
       V_REC.CODPUNCTAJ,
      -V_REC.PUNCTEUSED,
      -V_REC.VALACORDATA,
      aCODPOSTRETAIL);
    END LOOP;
  END IF;


  IF NVL(pkg_categconst.GetValConstanta(&apos;BonInchidCMD&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;1&apos;)  &lt;&gt; &apos;2&apos; THEN
    FOR V_REC IN 
      ( SELECT DISTINCT C1.CODCOMANDA 
        FROM TMP_EMULARE1 E1, COMANDA1 C1, COMANDA C 
        WHERE NVL(E1.CODCOMANDA1, 0) &lt;&gt; 0 AND E1.CODCOMANDA1 = C1.CODCOMANDA1 
              AND C.CODCOMANDA = C1.CODCOMANDA AND not C.TipDoc in (92) )
    LOOP
      UPDATE COMANDA
      SET
        INCHISA = 1
      WHERE
        CODCOMANDA = V_REC.CODCOMANDA;
    END LOOP;
  ELSE
     FOR V_REC IN
     (  
      SELECT CODCOMANDA FROM
      (
        SELECT 
          CMD.CODCOMANDA,
          (SELECT COUNT(*) FROM COMANDA1 WHERE CODCOMANDA = CMD.CODCOMANDA) AS LINIICMD,
          (SELECT COUNT(*) FROM EMULARE1 EE1,  COMANDA1 CC1 WHERE EE1.CODCOMANDA1 = CC1.CODCOMANDA1 AND CC1.CODCOMANDA = CMD.CODCOMANDA) AS LINIIBON
        FROM
        (
        select distinct codcomanda
        from
          TMP_emulare1 e1,
          comanda1 c1
        where
          COALESCE(E1.CODCOMANDA1, 0) &lt;&gt; 0
          and e1.codcomanda1 = c1.codcomanda1 
        ) CMD
      )
      WHERE
        LINIICMD = LINIIBON
     )   
     LOOP
      UPDATE COMANDA
      SET
        INCHISA = 1
      WHERE
        CODCOMANDA = V_REC.CODCOMANDA;
     END LOOP;  
    
  END IF;

/*
  IF StergRezCMDInchisa = &apos;1&apos; THEN
  FOR V_REC IN (SELECT DISTINCT CODCOMANDA1 FROM TMP_EMULARE1 WHERE NVL(CODCOMANDA1, 0) &lt;&gt; 0 )
  LOOP
    DELETE FROM REZERVATS WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
  END LOOP;
  END IF;  
*/  
  IF StergRezCMDInchisa = &apos;1&apos; THEN
      FOR V_REC IN 
        (
         SELECT 
           DISTINCT C2.CODCOMANDA1
         FROM 
           TMP_EMULARE1 E1, 
           COMANDA1 C1, 
           Comanda1 C2
         WHERE
           E1.CODCOMANDA1 = C1.CODCOMANDA1
           AND C1.CODCOMANDA = C2.CODCOMANDA   
         )   
      LOOP
        DELETE FROM REZERVATS WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      END LOOP;
  END IF;  
  
  

  IF NVL(aFACTURARE, 0) = 1 THEN
    UPDATE IESIRIRETAIL 
    SET
      OBS = aOBS,
      CODPARTRETAIL = CASE
                        WHEN aCODPARTRETAIL &lt;&gt; 0 THEN aCODPARTRETAIL
                        ELSE CODPARTRETAIL
                      END,     
      PARTENER      = CASE
                        WHEN aCODPART &lt;&gt; 0 THEN aCODPART
                        ELSE PARTENER
                      END     
    WHERE
      CODIESRETAIL = aCODIESRETAIL ;
  END IF;   
  
  UPDATE EMULARE1
  SET 
    CODPOSTRETAIL = aCODPOSTRETAIL
  WHERE
    CODEMULARE = RECID;  
  

  UPDATE EMULARE2
  SET 
    CODPOSTRETAIL = aCODPOSTRETAIL
  WHERE
    CODEMULARE = RECID;  


  NotifyModif(Operation, RecId, &apos;EMULARE&apos;);
  COMMIT;
END;

end pkg_emulare; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ESTIMARIPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54B8B0EB2E8671FD7889FE6D7A5C4DD1081095FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ESTIMARIPROD IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_66&apos;;
vCodEstimareProd1 number(20);
vSaptamana number(10);
vAn number(4);
vStoc number(20,7);

procedure setvstoc (valoare in number) is
begin
  vStoc := valoare;
end;

procedure execute_sql_prod(sAn in varchar2, sSaptamana in varchar2, vVal in number, vCod in number, vDepasire in number) is
begin
  if vDepasire = 1 then
    execute immediate &apos;update tmp_estimariprod1 set depasire = nvl(depasire,0) + &apos;||vVal||&apos; where codobiect = &apos;||vCod;
  else
    execute immediate &apos;update tmp_estimariprod1 set val_&apos;||sAn||sSaptamana||&apos; = nvl(val_&apos;||sAn||sSaptamana||&apos;,0) + &apos;||vVal||&apos; where codobiect = &apos;||vCod;
  end if;
end;

procedure CalcValScadente(aAnImport in number, aAnF in number, aSaptamana in number, aScadenta in number, aCodObiect in number, AnCurent in number default 1) is
sWeek number(10);
scadAn number(4);
sAn varchar2(4);
sSaptamana varchar2(10);
vVal number(20,7);
begin
  if NVL(AnCurent,1) = 1 then
    execute immediate &apos;select nvl(pret,0) * nvl(C&apos;||aSaptamana||&apos;,0) from tmp_estimariprod1 where codobiect = &apos;||aCodObiect into vVal;
    if vVal &gt; 0 then
      select to_number(to_char(Trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + aSaptamana * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
      select to_number(to_char(Trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + aSaptamana * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
      if scadAn = aAnImport and sWeek = 1 then
        sAn := &apos;N&apos;;
        sSaptamana := sWeek;
        pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 0);
      else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 0);
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 0);
          else
            pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 1);
          end if;
        end if;
      end if;
    end if;
  else
    execute immediate &apos;select nvl(pret,0) * nvl(N&apos;||aSaptamana||&apos;,0) from tmp_estimariprod1 where codobiect = &apos;||aCodObiect into vVal;

    if vVal &gt; 0 then
      select to_number(to_char(Trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + aSaptamana * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
      select to_number(to_char(Trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + aSaptamana * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
      if scadAn = aAnF and sWeek = 1 then
        sAn := &apos;N&apos;;
        sSaptamana := &apos;53&apos;;
        pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 1);
      else
        if scadAn = aAnF then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 0);
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 0);
          else
            pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, aCodObiect, 1);
          end if;
        end if;
      end if;
    end if;
  end if;
end;

procedure UMPLE_NEC_PROD(aSubunitate in number, aCodEstimareProd1 in number, aSaptamana in number, aAnImport in number, aAnF in number) is
sSQL varchar2(10000);
aScadenta number(20);
aCodObiect number(20);
aCoefUM number(20,7);
aStocOptim number(20,7);
begin
  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA(CODUNIC)
  SELECT CODOBIECT FROM TMP_ESTIMARIPROD1 where codestimareprod1 = aCodEstimareProd1;

  begin
    select nvl(obj.TERMENPLATA,0), tmp.codobiect into aScadenta, aCodObiect
    from tmp_estimariprod1 tmp
         inner join nartobj obj on obj.codobiect = tmp.codobiect
    where tmp.codestimareprod1 = aCodEstimareProd1;
  exception when others then
    aScadenta := 0;
  end;

  update TMP_estimariprod1 es1
  set
    pret = (select lei from pretm where codobiect = es1.codobiect and subunitatea = aSubunitate and implicit = 1),
    scadenta = aScadenta
  WHERE CODESTIMAREPROD1 = aCodEstimareProd1;

  if aScadenta &gt; 0 then
    for iter in 1..53 loop
      pkg_estimariprod.CalcValScadente(trunc(aAnImport), trunc(aAnF), trunc(iter), trunc(aScadenta), aCodObiect);
    end loop;

    if aAnImport &lt; aAnF then
      for iter in 1..53 loop
        pkg_estimariprod.CalcValScadente(trunc(aAnImport), trunc(aAnF), trunc(iter), trunc(aScadenta), aCodObiect, 0);
      end loop;
    end if;
  else
    for iter in 1..53 loop
      sSQL := &apos;declare
                 sWeek number(10);
                 scadAn number(4);
                 sAn varchar2(4);
                 sSaptamana varchar2(10);
                 vVal number(20,7);
               begin
                 select nvl(pret,0) * nvl(N&apos;||iter||&apos;,0) into vVal from tmp_estimariprod1 where codobiect = &apos;||aCodObiect||&apos;;
                 if vVal &gt; 0 then
                   sAn := &apos;&apos;N&apos;&apos;;
                   sSaptamana := &apos;&apos;&apos;||iter||&apos;&apos;&apos;;
                   pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, &apos;||aCodObiect||&apos;, 0);
                 end if;
               end;&apos;;
      execute immediate sSQL;
    end loop;
    for iter in 1..53 loop
      sSQL := &apos;declare
                 sWeek number(10);
                 scadAn number(4);
                 sAn varchar2(4);
                 sSaptamana varchar2(10);
                 vVal number(20,7);
               begin
                 select nvl(pret,0) * nvl(C&apos;||iter||&apos;,0) into vVal from tmp_estimariprod1 where codobiect = &apos;||aCodObiect||&apos;;
                 if vVal &gt; 0 then
                   sAn := &apos;&apos;C&apos;&apos;;
                   sSaptamana := &apos;&apos;&apos;||iter||&apos;&apos;&apos;;
                   pkg_estimariprod.execute_sql_prod(sAn, sSaptamana, vVal, &apos;||aCodObiect||&apos;, 0);
                 end if;
               end;&apos;;
      execute immediate sSQL;
    end loop;
  end if;

  delete TMP_ESTIMARIPROD1N;
  INSERT INTO TMP_ESTIMARIPROD1N (
    CodEstimareProd1N, CodEstimareProd, CODOBIECT,
    STOC, STOCOPTIM, COEFUM)
  with stocm as (
    SELECT
      NS.CODOBIECT,
      sum(CASE
            WHEN NS.TIPSERIE &gt; 0 THEN  ROUND( NSE.REST, 10)
            ELSE ROUND( NS.REST, 10)
          END
          ) AS STOC
    FROM NIRSTOC NS
      LEFT JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = NS.CODIOART AND pkg_globals.AnLunaLucru BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
    WHERE NS.REST &gt; 0
      AND NOT IOALUNA.MG IN (3, 5)
      AND EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = NS.CODOBIECT)
    group by ns.codobiect
  )
  SELECT
    aCodEstimareProd1, E1N.CodEstimareProd, E1N.CODOBIECT,
    nvl(StocM.STOC,0), nvl(os.STOCMED,0), nvl(num.COEF,1)
  FROM TMP_ESTIMARIPROD1 e1n
       inner join nartobj obj on e1n.codobiect = obj.codobiect
       inner join nart on nart.codarticol = obj.codarticol
       inner join num on nart.um = num.codum
       left join nartobjsubunit os on os.codobiect = obj.codobiect
                                      and ( os.codgest is null or os.codgest = 0)
                                      and os.subunitate = aSubunitate
       LEFT JOIN StocM ON StocM.CODOBIECT = E1N.CODOBIECT
  where e1n.codestimareprod1 = aCodEstimareProd1;

  select decode(nvl(coefum,1),0,1,nvl(coefum,1)), nvl(stocoptim,0), nvl(stoc,0) into aCoefUm, aStocOptim, vStoc from tmp_estimariprod1n where codestimareprod1n = aCodEstimareProd1;

   for iter in 1..53 loop
     sSQL := &apos;declare vVal number(20,7);
              begin
                select 1 / &apos;||aCoefUM||&apos; * nvl(c&apos;||iter||&apos;,0) into vVal from tmp_estimariprod1 where codestimareprod1 = &apos;||aCodEstimareProd1||&apos;;
                if &apos;||aSaptamana||&apos; &lt;= &apos;||iter||&apos; then
                  if &apos;||vStoc||&apos; - vVal &lt; &apos;||astocoptim||&apos; then
                    update tmp_estimariprod1n set nec_c&apos;||iter||&apos; = &apos;||astocoptim||&apos; - (&apos;||vStoc||&apos; - vVal) where codestimareprod1n = &apos;||acodestimareprod1||&apos;;
                    pkg_estimariprod.setvstoc(&apos;||astocoptim||&apos;);
                  else
                    update tmp_estimariprod1n set nec_c&apos;||iter||&apos; = 0 where codestimareprod1n = &apos;||acodestimareprod1||&apos;;
                    pkg_estimariprod.setvstoc(&apos;||vstoc||&apos; - vVal);
                  end if;
                end if;
              end;&apos;;

     execute immediate sSQL;
   end loop;

   for iter in 1..53 loop
     sSQL := &apos;declare vVal number(20,7);
              begin
                select 1 / &apos;||aCoefUM||&apos; * nvl(n&apos;||iter||&apos;,0) into vVal from tmp_estimariprod1 where codestimareprod1 = &apos;||aCodEstimareProd1||&apos;;
                if &apos;||vStoc||&apos; - vVal &lt; &apos;||astocoptim||&apos; then
                  update tmp_estimariprod1n set nec_n&apos;||iter||&apos; = &apos;||astocoptim||&apos; - (&apos;||vStoc||&apos; - vVal) where codestimareprod1n = &apos;||acodestimareprod1||&apos;;
                  pkg_estimariprod.setvstoc(&apos;||astocoptim||&apos;);
                else
                  update tmp_estimariprod1n set nec_n&apos;||iter||&apos; = 0 where codestimareprod1n = &apos;||acodestimareprod1||&apos;;
                  pkg_estimariprod.setvstoc(&apos;||vstoc||&apos; - vVal);
                end if;
              end;&apos;;

     execute immediate sSQL;
   end loop;

   for v_rec in (select * from tmp_estimariprod1n) loop
     update tmp_estimariprod1 set stoc = v_rec.stoc where codestimareprod1 = v_rec.codestimareprod1n;
     update tmp_estimariprod1 set stocoptim = v_rec.stocoptim where codestimareprod1 = v_rec.codestimareprod1n;
     update tmp_estimariprod1 set coefum = v_rec.coefum where codestimareprod1 = v_rec.codestimareprod1n;
     update tmp_estimariprod1 set
       NEC_C1 =v_rec.NEC_C1 , NEC_C2 =v_rec.NEC_C2 , NEC_C3 =v_rec.NEC_C3 , NEC_C4 =v_rec.NEC_C4 , NEC_C5 =v_rec.NEC_C5 , NEC_C6 =v_rec.NEC_C6 , NEC_C7 =v_rec.NEC_C7 , NEC_C8 =v_rec.NEC_C8 , NEC_C9 =v_rec.NEC_C9 ,
       NEC_C10=v_rec.NEC_C10, NEC_C11=v_rec.NEC_C11, NEC_C12=v_rec.NEC_C12, NEC_C13=v_rec.NEC_C13, NEC_C14=v_rec.NEC_C14, NEC_C15=v_rec.NEC_C15, NEC_C16=v_rec.NEC_C16, NEC_C17=v_rec.NEC_C17, NEC_C18=v_rec.NEC_C18, NEC_C19=v_rec.NEC_C19,
       NEC_C20=v_rec.NEC_C20, NEC_C21=v_rec.NEC_C21, NEC_C22=v_rec.NEC_C22, NEC_C23=v_rec.NEC_C23, NEC_C24=v_rec.NEC_C24, NEC_C25=v_rec.NEC_C25, NEC_C26=v_rec.NEC_C26, NEC_C27=v_rec.NEC_C27, NEC_C28=v_rec.NEC_C28, NEC_C29=v_rec.NEC_C29,
       NEC_C30=v_rec.NEC_C30, NEC_C31=v_rec.NEC_C31, NEC_C32=v_rec.NEC_C32, NEC_C33=v_rec.NEC_C33, NEC_C34=v_rec.NEC_C34, NEC_C35=v_rec.NEC_C35, NEC_C36=v_rec.NEC_C36, NEC_C37=v_rec.NEC_C37, NEC_C38=v_rec.NEC_C38, NEC_C39=v_rec.NEC_C39,
       NEC_C40=v_rec.NEC_C40, NEC_C41=v_rec.NEC_C41, NEC_C42=v_rec.NEC_C42, NEC_C43=v_rec.NEC_C43, NEC_C44=v_rec.NEC_C44, NEC_C45=v_rec.NEC_C45, NEC_C46=v_rec.NEC_C46, NEC_C47=v_rec.NEC_C47, NEC_C48=v_rec.NEC_C48, NEC_C49=v_rec.NEC_C49,
       NEC_C50=v_rec.NEC_C50, NEC_C51=v_rec.NEC_C51, NEC_C52=v_rec.NEC_C52,
       NEC_N1 =v_rec.NEC_N1 , NEC_N2 =v_rec.NEC_N2 , NEC_N3 =v_rec.NEC_N3 , NEC_N4 =v_rec.NEC_N4 , NEC_N5 =v_rec.NEC_N5 , NEC_N6 =v_rec.NEC_N6 , NEC_N7 =v_rec.NEC_N7 , NEC_N8 =v_rec.NEC_N8 , NEC_N9 =v_rec.NEC_N9 ,
       NEC_N10=v_rec.NEC_N10, NEC_N11=v_rec.NEC_N11, NEC_N12=v_rec.NEC_N12, NEC_N13=v_rec.NEC_N13, NEC_N14=v_rec.NEC_N14, NEC_N15=v_rec.NEC_N15, NEC_N16=v_rec.NEC_N16, NEC_N17=v_rec.NEC_N17, NEC_N18=v_rec.NEC_N18, NEC_N19=v_rec.NEC_N19,
       NEC_N20=v_rec.NEC_N20, NEC_N21=v_rec.NEC_N21, NEC_N22=v_rec.NEC_N22, NEC_N23=v_rec.NEC_N23, NEC_N24=v_rec.NEC_N24, NEC_N25=v_rec.NEC_N25, NEC_N26=v_rec.NEC_N26, NEC_N27=v_rec.NEC_N27, NEC_N28=v_rec.NEC_N28, NEC_N29=v_rec.NEC_N29,
       NEC_N30=v_rec.NEC_N30, NEC_N31=v_rec.NEC_N31, NEC_N32=v_rec.NEC_N32, NEC_N33=v_rec.NEC_N33, NEC_N34=v_rec.NEC_N34, NEC_N35=v_rec.NEC_N35, NEC_N36=v_rec.NEC_N36, NEC_N37=v_rec.NEC_N37, NEC_N38=v_rec.NEC_N38, NEC_N39=v_rec.NEC_N39,
       NEC_N40=v_rec.NEC_N40, NEC_N41=v_rec.NEC_N41, NEC_N42=v_rec.NEC_N42, NEC_N43=v_rec.NEC_N43, NEC_N44=v_rec.NEC_N44, NEC_N45=v_rec.NEC_N45, NEC_N46=v_rec.NEC_N46, NEC_N47=v_rec.NEC_N47, NEC_N48=v_rec.NEC_N48, NEC_N49=v_rec.NEC_N49,
       NEC_N50=v_rec.NEC_N50, NEC_N51=v_rec.NEC_N51, NEC_N52=v_rec.NEC_N52, NEC_C53=v_rec.NEC_C53, NEC_N53=v_rec.NEC_N53
     where codestimareprod1 = v_rec.codestimareprod1n;
   end loop;
end;

procedure SetParams(aCodEstimareProd1 in number, aSaptamana in number, aAn in number, CuRefresh in number default 0) is
begin
  vCodEstimareProd1 := aCodEstimareProd1;
  vSaptamana := aSaptamana;
  vAn := aAn;
  if NVL(CuRefresh,0) = 1 and vCodEstimareProd1 &gt; 0 then
    RefreshNod;
  end if;
end;

PROCEDURE RefreshNod IS
aCodEstimareProd number(20);
aRecId number(20);
aSubunitatea number(20);
aAn number(4);
aLuna number(2);
BEGIN
  aRecId := vCodEstimareProd1;
  select codestimareprod into aCodEstimareProd
  from estimariprod1 where codestimareprod1 = aRecId;

  select subunitatea, an, luna into aSubunitatea, aAn, aLuna from estimariprod where codestimareprod = aCodEstimareProd;

  delete tmp_estimarinod;
  INSERT INTO TMP_ESTIMARINOD(CODESTIMARENOD,
                              CODESTIMAREPROD,
                              CODESTIMAREPROD1,
                              CANT,
                              NODORIGINAL,
                              POZITIE,
                              CODRETETA,
                              TIP,
                              CODOBIECT,
                              INDEXPARINTE,
                              CODPRODMAT,
                              NIVEL,
                              ORDINE,
                              CODPROIECTNOD,
                              VERSIUNE,
                              CANTPRODRETETA,
                              CANTMATRETETA,
                              NECESAR,
                              Saptamana,
                              AN,
                              denumire)
  SELECT
    nod.CODESTIMARENOD,
    nod.CODESTIMAREPROD,
    nod.CODESTIMAREPROD1,
    nod.CANT,
    nod.NODORIGINAL,
    nod.POZITIE,
    nod.CODRETETA,
    nod.TIP,
    nod.CODOBIECT,
    nod.INDEXPARINTE,
    nod.CODPRODMAT,
    nod.NIVEL,
    nod.ORDINE,
    nod.CODPROIECTNOD,
    nod.VERSIUNE,
    nod.CANTPRODRETETA,
    nod.CANTMATRETETA,
    nod.NECESAR,
    nod.SAPTAMANA,
    AN,
    obj.denumire
  FROM ESTIMARINOD nod
       inner join nartobj obj on obj.codobiect = nod.codobiect
  WHERE CODESTIMAREPROD1 = aRECID;

  COMMIT;
END;

procedure BagaMateriale(aNodOriginal in number, aCodProdComp in number, aNivel in number,
                        aCodEstimareProd1 in number, aCodEstimareProd in number, aObservatii in varchar2, aSaptamana in number, aAn in number, aCant in number) is
aCodEstimareNod number(20);
aCodEstimareNodOrig number(20);
begin
  for v_tmp in (select mat.codobiect,
                       case when nvl(mat.tip,3) &lt;= 2 then nvl(pc.codprodcomp,0) else 0 end codprodcomp,
                       mat.cant, mat.codmat, mat.indexlocal,
                       case when nvl(mat.tip,3) &lt;= 2 then 1 else 3 end Tip,
                       aObservatii||&apos;.&apos;||LPAD(to_char(mat.IndexLocal), 2, &apos;0&apos;) Observatii,
                       prod.cant lotoptim, mat.cant cantmat
                from prodmat mat
                     inner join prodcomp prod on prod.codprodcomp = mat.codprodcomp
                     left join prodcomp pc on pc.codobiect = mat.codobiect and pc.implicit = 1 and mat.tip &lt;= 2
                where mat.codprodcomp = aCodProdComp
                order by mat.indexlocal
               ) loop

    select seq_estimarinod_codestimarenod.nextval into aCodEstimareNod from dual;
    insert into estimarinod_c1(codestimarenod, codestimareprod1, codestimareprod, cant, nodoriginal, pozitie, tip, codobiect, indexparinte, codprodmat,
                            nivel, ordine, versiune, cantprodreteta, cantmatreteta, necesar, saptamana, an)
    values (aCodEstimareNod, aCodEstimareProd1, aCodEstimareProd, v_tmp.cant, aNodOriginal, v_tmp.indexlocal, v_tmp.tip,
            v_tmp.codobiect, v_tmp.Observatii, v_tmp.codmat, aNivel, v_tmp.indexlocal, 0, v_tmp.cant, v_tmp.cantmat, aCant/v_tmp.lotoptim * v_tmp.cant,
            aSaptamana, aAn);
    if v_tmp.Tip = 1 then
      select seq_estimarinod_codestimarenod.nextval into aCodEstimareNodOrig from dual;
      insert into estimarinod_c1(codestimarenod, codestimareprod1, codestimareprod, cant, nodoriginal, pozitie, tip, codobiect, indexparinte, codprodmat,
                              nivel, ordine, versiune, cantprodreteta, cantmatreteta, necesar, codreteta, saptamana, an)
      values (aCodEstimareNodOrig, aCodEstimareProd1, aCodEstimareProd, v_tmp.cant, aCodEstimareNod, v_tmp.indexlocal, v_tmp.tip,
              v_tmp.codobiect, v_tmp.Observatii, v_tmp.codmat, aNivel, v_tmp.indexlocal, 1, v_tmp.cant, v_tmp.cantmat, aCant/v_tmp.lotoptim * v_tmp.cant, v_tmp.codprodcomp,
              aSaptamana, aAn);
      if v_tmp.CodProdComp &gt; 0 then
        pkg_estimariprod.BagaMateriale(aCodEstimareNodOrig, v_tmp.CodProdComp, aNivel + 1, aCodEstimareProd1, aCodEstimareProd, v_tmp.observatii, aSaptamana, aAn, aCant/v_tmp.lotoptim * v_tmp.cant);
      end if;
    end if;
  end loop;
end;

function GENSTRUCT(vCodEstimareProd1 in number) return number is
Rez number;
acodestimareprod number(20);
vAnImport number(4);
aCodEstimareNod number(20);
aCodEstimareNodOrig number(20);
begin
  begin
    select es.AnImport, es1.codestimareprod into vAnImport, acodestimareprod
    from estimariprod es
         inner join estimariprod1 es1 on es.codestimareprod = es1.codestimareprod
    where es1.codestimareprod1 = vCodEstimareProd1;
  exception when others then vAnImport := 0;
  end;

  Rez := 0;
  if vAnImport &gt; 0 then
    for v_rec in (select p1.codobiect, p1.codestimareprod1,
                         p1n.NEC_C1, p1n.nec_C2, p1n.nec_C3, p1n.nec_C4, p1n.nec_C5, p1n.nec_C6, p1n.nec_C7, p1n.nec_C8, p1n.nec_C9,
                         p1n.nec_C10, p1n.nec_C11, p1n.nec_C12, p1n.nec_C13, p1n.nec_C14, p1n.nec_C15, p1n.nec_C16, p1n.nec_C17, p1n.nec_C18, p1n.nec_C19,
                         p1n.nec_C20, p1n.nec_C21, p1n.nec_C22, p1n.nec_C23, p1n.nec_C24, p1n.nec_C25, p1n.nec_C26, p1n.nec_C27, p1n.nec_C28, p1n.nec_C29,
                         p1n.nec_C30, p1n.nec_C31, p1n.nec_C32, p1n.nec_C33, p1n.nec_C34, p1n.nec_C35, p1n.nec_C36, p1n.nec_C37, p1n.nec_C38, p1n.nec_C39,
                         p1n.nec_C40, p1n.nec_C41, p1n.nec_C42, p1n.nec_C43, p1n.nec_C44, p1n.nec_C45, p1n.nec_C46, p1n.nec_C47, p1n.nec_C48, p1n.nec_C49,
                         p1n.nec_C50, p1n.nec_C51, p1n.nec_C52,
                         p1n.nec_N1,  p1n.nec_N2,  p1n.nec_N3,  p1n.nec_N4,  p1n.nec_N5,  p1n.nec_N6,  p1n.nec_N7,  p1n.nec_N8,  p1n.nec_N9,
                         p1n.nec_N10, p1n.nec_N11, p1n.nec_N12, p1n.nec_N13, p1n.nec_N14, p1n.nec_N15, p1n.nec_N16, p1n.nec_N17, p1n.nec_N18, p1n.nec_N19,
                         p1n.nec_N20, p1n.nec_N21, p1n.nec_N22, p1n.nec_N23, p1n.nec_N24, p1n.nec_N25, p1n.nec_N26, p1n.nec_N27, p1n.nec_N28, p1n.nec_N29,
                         p1n.nec_N30, p1n.nec_N31, p1n.nec_N32, p1n.nec_N33, p1n.nec_N34, p1n.nec_N35, p1n.nec_N36, p1n.nec_N37, p1n.nec_N38, p1n.nec_N39,
                         p1n.nec_N40, p1n.nec_N41, p1n.nec_N42, p1n.nec_N43, p1n.nec_N44, p1n.nec_N45, p1n.nec_N46, p1n.nec_N47, p1n.nec_N48, p1n.nec_N49,
                         p1n.nec_N50, p1n.nec_N51, p1n.nec_N52, p1n.nec_C53, p1n.nec_N53,
                         pc.codprodcomp, pc.cant
                  from estimariprod1n p1n
                       inner join estimariprod1 p1 on p1.codobiect = p1n.codobiect and p1.codestimareprod = acodestimareprod
                       inner join prodcomp pc on pc.codobiect = p1.codobiect and pc.implicit = 1
                  where p1.codestimareprod1 = vCodEstimareProd1 and p1n.codestimareprod = acodestimareprod) loop

      delete estimarinod_c1;
      select seq_estimarinod_codestimarenod.nextval into aCodEstimareNod from dual;
      insert into estimarinod_c1(codestimarenod, codestimareprod1, codestimareprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte,
                              necesar, cant, cantmatreteta, cantprodreteta, Saptamana, An)
      values (aCodEstimareNod, V_REC.CODestimareprod1, acodestimareprod, 0, V_REC.CODobiect, 0, 0, 1, 0, &apos;.00&apos;,
              V_REC.Cant, V_REC.Cant, 0, 0, 0, 0);

      select seq_estimarinod_codestimarenod.nextval into aCodEstimareNodOrig from dual;
      insert into estimarinod_c1(codestimarenod, codestimareprod1, codestimareprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte,
                              necesar, cant, cantmatreteta, cantprodreteta, codreteta, Saptamana, An)
      values (aCodEstimareNodOrig, V_REC.CODestimareprod1, acodestimareprod, aCodEstimareNod, V_REC.CODobiect, 0, 0, 1, 1, &apos;.00&apos;,
              V_REC.Cant, V_REC.Cant, 0, 0, V_REC.CODprodcomp, 0, 0);
      pkg_estimariprod.BagaMateriale(aCodEstimareNodOrig, V_REC.CodProdcomp, 1, V_REC.CODestimareprod1, aCodEstimareProd, &apos;.00&apos;, 1, vAnImport, v_Rec.cant);

      insert into estimarinod select * from estimarinod_c1;
      select count(*) into Rez from estimarinod_c1 where versiune = 1 and tip = 1 and codreteta = 0;
    end loop;
  end if;

  commit;

  return Rez;
end;

procedure CalculeazaNecesar(aCodEstimareProd1m in number, aSaptamana in number) is
aStoc number(20,7);
aStocOptim number(20,7);
begin
  for v_rec in (select codestimareprod1m,
                  nvl(C1 ,0) C1 , nvl(C2 ,0) C2 , nvl(C3 ,0) C3 , nvl(C4 ,0) C4 , nvl(C5 ,0) C5  , nvl(C6 ,0) C6  , nvl(C7 ,0) C7  , nvl(C8 ,0) C8  , nvl(C9 ,0) C9  ,
                  nvl(C10,0) C10, nvl(C11,0) C11, nvl(C12,0) C12, nvl(C13,0) C13, nvl(C14,0) C14 , nvl(C15,0) C15 , nvl(C16,0) C16 , nvl(C17,0) C17 , nvl(C18,0) C18 , nvl(C19,0) C19,
                  nvl(C20,0) C20, nvl(C21,0) C21, nvl(C22,0) C22, nvl(C23,0) C23, nvl(C24,0) C24 , nvl(C25,0) C25 , nvl(C26,0) C26 , nvl(C27,0) C27 , nvl(C28,0) C28 , nvl(C29,0) C29,
                  nvl(C30,0) C30, nvl(C31,0) C31, nvl(C32,0) C32, nvl(C33,0) C33, nvl(C34,0) C34 , nvl(C35,0) C35 , nvl(C36,0) C36 , nvl(C37,0) C37 , nvl(C38,0) C38 , nvl(C39,0) C39,
                  nvl(C40,0) C40, nvl(C41,0) C41, nvl(C42,0) C42, nvl(C43,0) C43, nvl(C44,0) C44 , nvl(C45,0) C45 , nvl(C46,0) C46 , nvl(C47,0) C47 , nvl(C48,0) C48 , nvl(C49,0) C49,
                  nvl(C50,0) C50, nvl(C51,0) C51, nvl(C52,0) C52,
                  nvl(N1 ,0) N1 , nvl(N2 ,0) N2 , nvl(N3 ,0) N3 , nvl(N4 ,0) N4 , nvl(N5 ,0) N5  , nvl(N6 ,0) N6  , nvl(N7 ,0) N7  , nvl(N8 ,0) N8  , nvl(N9 ,0) N9  ,
                  nvl(N10,0) N10, nvl(N11,0) N11, nvl(N12,0) N12, nvl(N13,0) N13, nvl(N14,0) N14 , nvl(N15,0) N15 , nvl(N16,0) N16 , nvl(N17,0) N17 , nvl(N18,0) N18 , nvl(N19,0) N19,
                  nvl(N20,0) N20, nvl(N21,0) N21, nvl(N22,0) N22, nvl(N23,0) N23, nvl(N24,0) N24 , nvl(N25,0) N25 , nvl(N26,0) N26 , nvl(N27,0) N27 , nvl(N28,0) N28 , nvl(N29,0) N29,
                  nvl(N30,0) N30, nvl(N31,0) N31, nvl(N32,0) N32, nvl(N33,0) N33, nvl(N34,0) N34 , nvl(N35,0) N35 , nvl(N36,0) N36 , nvl(N37,0) N37 , nvl(N38,0) N38 , nvl(N39,0) N39,
                  nvl(N40,0) N40, nvl(N41,0) N41, nvl(N42,0) N42, nvl(N43,0) N43, nvl(N44,0) N44 , nvl(N45,0) N45 , nvl(N46,0) N46 , nvl(N47,0) N47 , nvl(N48,0) N48 , nvl(N49,0) N49,
                  nvl(N50,0) N50, nvl(N51,0) N51, nvl(N52,0) N52, nvl(C53,0) C53, nvl(N53,0) N53,
                  nvl(CF_C1 ,0) CF_C1 , nvl(CF_C2 ,0) CF_C2 , nvl(CF_C3 ,0) CF_C3 , nvl(CF_C4 ,0) CF_C4 , nvl(CF_C5 ,0) CF_C5 , nvl(CF_C6 ,0) CF_C6 , nvl(CF_C7 ,0) CF_C7 , nvl(CF_C8 ,0) CF_C8 , nvl(CF_C9 ,0) CF_C9 ,
                  nvl(CF_C10,0) CF_C10, nvl(CF_C11,0) CF_C11, nvl(CF_C12,0) CF_C12, nvl(CF_C13,0) CF_C13, nvl(CF_C14,0) CF_C14, nvl(CF_C15,0) CF_C15, nvl(CF_C16,0) CF_C16, nvl(CF_C17,0) CF_C17, nvl(CF_C18,0) CF_C18, nvl(CF_C19,0) CF_C19,
                  nvl(CF_C20,0) CF_C20, nvl(CF_C21,0) CF_C21, nvl(CF_C22,0) CF_C22, nvl(CF_C23,0) CF_C23, nvl(CF_C24,0) CF_C24, nvl(CF_C25,0) CF_C25, nvl(CF_C26,0) CF_C26, nvl(CF_C27,0) CF_C27, nvl(CF_C28,0) CF_C28, nvl(CF_C29,0) CF_C29,
                  nvl(CF_C30,0) CF_C30, nvl(CF_C31,0) CF_C31, nvl(CF_C32,0) CF_C32, nvl(CF_C33,0) CF_C33, nvl(CF_C34,0) CF_C34, nvl(CF_C35,0) CF_C35, nvl(CF_C36,0) CF_C36, nvl(CF_C37,0) CF_C37, nvl(CF_C38,0) CF_C38, nvl(CF_C39,0) CF_C39,
                  nvl(CF_C40,0) CF_C40, nvl(CF_C41,0) CF_C41, nvl(CF_C42,0) CF_C42, nvl(CF_C43,0) CF_C43, nvl(CF_C44,0) CF_C44, nvl(CF_C45,0) CF_C45, nvl(CF_C46,0) CF_C46, nvl(CF_C47,0) CF_C47, nvl(CF_C48,0) CF_C48, nvl(CF_C49,0) CF_C49,
                  nvl(CF_C50,0) CF_C50, nvl(CF_C51,0) CF_C51, nvl(CF_C52,0) CF_C52,
                  nvl(CF_N1 ,0) CF_N1 , nvl(CF_N2 ,0) CF_N2 , nvl(CF_N3 ,0) CF_N3 , nvl(CF_N4 ,0) CF_N4 , nvl(CF_N5 ,0) CF_N5 , nvl(CF_N6 ,0) CF_N6 , nvl( CF_N7,0) CF_N7,  nvl(CF_N8 ,0) CF_N8 , nvl(CF_N9 ,0) CF_N9 ,
                  nvl(CF_N10,0) CF_N10, nvl(CF_N11,0) CF_N11, nvl(CF_N12,0) CF_N12, nvl(CF_N13,0) CF_N13, nvl(CF_N14,0) CF_N14, nvl(CF_N15,0) CF_N15, nvl(CF_N16,0) CF_N16, nvl(CF_N17,0) CF_N17, nvl(CF_N18,0) CF_N18, nvl(CF_N19,0) CF_N19,
                  nvl(CF_N20,0) CF_N20, nvl(CF_N21,0) CF_N21, nvl(CF_N22,0) CF_N22, nvl(CF_N23,0) CF_N23, nvl(CF_N24,0) CF_N24, nvl(CF_N25,0) CF_N25, nvl(CF_N26,0) CF_N26, nvl(CF_N27,0) CF_N27, nvl(CF_N28,0) CF_N28, nvl(CF_N29,0) CF_N29,
                  nvl(CF_N30,0) CF_N30, nvl(CF_N31,0) CF_N31, nvl(CF_N32,0) CF_N32, nvl(CF_N33,0) CF_N33, nvl(CF_N34,0) CF_N34, nvl(CF_N35,0) CF_N35, nvl(CF_N36,0) CF_N36, nvl(CF_N37,0) CF_N37, nvl(CF_N38,0) CF_N38, nvl(CF_N39,0) CF_N39,
                  nvl(CF_N40,0) CF_N40, nvl(CF_N41,0) CF_N41, nvl(CF_N42,0) CF_N42, nvl(CF_N43,0) CF_N43, nvl(CF_N44,0) CF_N44, nvl(CF_N45,0) CF_N45, nvl(CF_N46,0) CF_N46, nvl(CF_N47,0) CF_N47, nvl(CF_N48,0) CF_N48, nvl(CF_N49,0) CF_N49,
                  nvl(CF_N50,0) CF_N50, nvl(CF_N51,0) CF_N51, nvl(CF_N52,0) CF_N52, nvl(CF_C53,0) CF_C53, nvl(CF_N53,0) CF_N53,
                  nvl(STOC,0) STOC, nvl(STOCOPTIM,0) STOCOPTIM, nvl(pret,0) pret, nvl(scadenta,0) scadenta
                from estimariprod1m
                where codestimareprod1m = aCodEstimareProd1m) loop
    aStoc := v_rec.stoc;
    aStocOptim := v_rec.Stocoptim;
    if aSaptamana &lt;= 1 then
      if v_rec.cf_c1 + aStoc - v_rec.c1 &lt; aStocoptim then
        update estimariprod1m set nec_c1 = aStocoptim - (v_rec.cf_c1 + aStoc - v_rec.c1) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c1 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c1 + aStoc - v_rec.C1;
      end if;
    end if;
    if aSaptamana &lt;= 2 then
      if v_rec.cf_c2 + aStoc - v_rec.c2 &lt; aStocoptim then
        update estimariprod1m set nec_c2 = aStocoptim - (v_rec.cf_c2 + aStoc - v_rec.c2) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c2 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c2 + aStoc - v_rec.C2;
      end if;
    end if;
    if aSaptamana &lt;= 3 then
      if v_rec.cf_c3 + aStoc - v_rec.c3 &lt; aStocoptim then
        update estimariprod1m set nec_c3 = aStocoptim - (v_rec.cf_c3 + aStoc - v_rec.c3) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c3 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c3 + aStoc - v_rec.C3;
      end if;
    end if;
    if aSaptamana &lt;= 4 then
      if v_rec.cf_c4 + aStoc - v_rec.c4 &lt; aStocoptim then
        update estimariprod1m set nec_c4 = aStocoptim - (v_rec.cf_c4 + aStoc - v_rec.c4) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c4 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c4 + aStoc - v_rec.C4;
      end if;
    end if;
    if aSaptamana &lt;= 5 then
      if v_rec.cf_c5 + aStoc - v_rec.c5 &lt; aStocoptim then
        update estimariprod1m set nec_c5 = aStocoptim - (v_rec.cf_c5 + aStoc - v_rec.c5) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c5 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c5 + aStoc - v_rec.C5;
      end if;
    end if;
    if aSaptamana &lt;= 6 then
      if v_rec.cf_c6 + aStoc - v_rec.c6 &lt; aStocoptim then
        update estimariprod1m set nec_c6 = aStocoptim - (v_rec.cf_c6 + aStoc - v_rec.c6) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c6 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c6 + aStoc - v_rec.C6;
      end if;
    end if;
    if aSaptamana &lt;= 7 then
      if v_rec.cf_c7 + aStoc - v_rec.c7 &lt; aStocoptim then
        update estimariprod1m set nec_c7 = aStocoptim - (v_rec.cf_c7 + aStoc - v_rec.c7) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c7 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c7 + aStoc - v_rec.C7;
      end if;
    end if;
    if aSaptamana &lt;= 8 then
      if v_rec.cf_c8 + aStoc - v_rec.c8 &lt; aStocoptim then
        update estimariprod1m set nec_c8 = aStocoptim - (v_rec.cf_c8 + aStoc - v_rec.c8) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c8 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c8 + aStoc - v_rec.C8;
      end if;
    end if;
    if aSaptamana &lt;= 9 then
      if v_rec.cf_c9 + aStoc - v_rec.c9 &lt; aStocoptim then
        update estimariprod1m set nec_c9 = aStocoptim - (v_rec.cf_c9 + aStoc - v_rec.c9) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c9 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c9 + aStoc - v_rec.C9;
      end if;
    end if;
    if aSaptamana &lt;= 10 then
      if v_rec.cf_c10 + aStoc - v_rec.c10 &lt; aStocoptim then
        update estimariprod1m set nec_c10 = aStocoptim - (v_rec.cf_c10 + aStoc - v_rec.c10) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c10 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c10 + aStoc - v_rec.C10;
      end if;
    end if;
    if aSaptamana &lt;= 11 then
      if v_rec.cf_c11 + aStoc - v_rec.c11 &lt; aStocoptim then
        update estimariprod1m set nec_c11 = aStocoptim - (v_rec.cf_c11 + aStoc - v_rec.c11) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c11 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c11 + aStoc - v_rec.C11;
      end if;
    end if;
    if aSaptamana &lt;= 12 then
      if v_rec.cf_c12 + aStoc - v_rec.c12 &lt; aStocoptim then
        update estimariprod1m set nec_c12 = aStocoptim - (v_rec.cf_c12 + aStoc - v_rec.c12) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c12 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c12 + aStoc - v_rec.C12;
      end if;
    end if;
    if aSaptamana &lt;= 13 then
      if v_rec.cf_c13 + aStoc - v_rec.c13 &lt; aStocoptim then
        update estimariprod1m set nec_c13 = aStocoptim - (v_rec.cf_c13 + aStoc - v_rec.c13) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c13 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c13 + aStoc - v_rec.C13;
      end if;
    end if;
    if aSaptamana &lt;= 14 then
      if v_rec.cf_c14 + aStoc - v_rec.c14 &lt; aStocoptim then
        update estimariprod1m set nec_c14 = aStocoptim - (v_rec.cf_c14 + aStoc - v_rec.c14) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c14 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c14 + aStoc - v_rec.C14;
      end if;
    end if;
    if aSaptamana &lt;= 15 then
      if v_rec.cf_c15 + aStoc - v_rec.c15 &lt; aStocoptim then
        update estimariprod1m set nec_c15 = aStocoptim - (v_rec.cf_c15 + aStoc - v_rec.c15) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c15 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c15 + aStoc - v_rec.C15;
      end if;
    end if;
    if aSaptamana &lt;= 16 then
      if v_rec.cf_c16 + aStoc - v_rec.c16 &lt; aStocoptim then
        update estimariprod1m set nec_c16 = aStocoptim - (v_rec.cf_c16 + aStoc - v_rec.c16) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c16 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c16 + aStoc - v_rec.C16;
      end if;
    end if;
    if aSaptamana &lt;= 17 then
      if v_rec.cf_c17 + aStoc - v_rec.c17 &lt; aStocoptim then
        update estimariprod1m set nec_c17 = aStocoptim - (v_rec.cf_c17 + aStoc - v_rec.c17) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c17 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c17 + aStoc - v_rec.C17;
      end if;
    end if;
    if aSaptamana &lt;= 18 then
      if v_rec.cf_c18 + aStoc - v_rec.c18 &lt; aStocoptim then
        update estimariprod1m set nec_c18 = aStocoptim - (v_rec.cf_c18 + aStoc - v_rec.c18) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c18 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c18 + aStoc - v_rec.C18;
      end if;
    end if;
    if aSaptamana &lt;= 19 then
      if v_rec.cf_c19 + aStoc - v_rec.c19 &lt; aStocoptim then
        update estimariprod1m set nec_c19 = aStocoptim - (v_rec.cf_c19 + aStoc - v_rec.c19) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c19 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c19 + aStoc - v_rec.C19;
      end if;
    end if;
    if aSaptamana &lt;= 20 then
      if v_rec.cf_c20 + aStoc - v_rec.c20 &lt; aStocoptim then
        update estimariprod1m set nec_c20 = aStocoptim - (v_rec.cf_c20 + aStoc - v_rec.c20) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c20 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c20 + aStoc - v_rec.C20;
      end if;
    end if;
    if aSaptamana &lt;= 21 then
      if v_rec.cf_c21 + aStoc - v_rec.c21 &lt; aStocoptim then
        update estimariprod1m set nec_c21 = aStocoptim - (v_rec.cf_c21 + aStoc - v_rec.c21) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c21 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c21 + aStoc - v_rec.C21;
      end if;
    end if;
    if aSaptamana &lt;= 22 then
      if v_rec.cf_c22 + aStoc - v_rec.c22 &lt; aStocoptim then
        update estimariprod1m set nec_c22 = aStocoptim - (v_rec.cf_c22 + aStoc - v_rec.c22) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c22 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c22 + aStoc - v_rec.C22;
      end if;
    end if;
    if aSaptamana &lt;= 23 then
      if v_rec.cf_c23 + aStoc - v_rec.c23 &lt; aStocoptim then
        update estimariprod1m set nec_c23 = aStocoptim - (v_rec.cf_c23 + aStoc - v_rec.c23) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c23 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c23 + aStoc - v_rec.C23;
      end if;
    end if;
    if aSaptamana &lt;= 24 then
      if v_rec.cf_c24 + aStoc - v_rec.c24 &lt; aStocoptim then
        update estimariprod1m set nec_c24 = aStocoptim - (v_rec.cf_c24 + aStoc - v_rec.c24) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c24 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c24 + aStoc - v_rec.C24;
      end if;
    end if;
    if aSaptamana &lt;= 25 then
      if v_rec.cf_c25 + aStoc - v_rec.c25 &lt; aStocoptim then
        update estimariprod1m set nec_c25 = aStocoptim - (v_rec.cf_c25 + aStoc - v_rec.c25) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c25 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c25 + aStoc - v_rec.C25;
      end if;
    end if;
    if aSaptamana &lt;= 26 then
      if v_rec.cf_c26 + aStoc - v_rec.c26 &lt; aStocoptim then
        update estimariprod1m set nec_c26 = aStocoptim - (v_rec.cf_c26 + aStoc - v_rec.c26) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c26 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c26 + aStoc - v_rec.C26;
      end if;
    end if;
    if aSaptamana &lt;= 27 then
      if v_rec.cf_c27 + aStoc - v_rec.c27 &lt; aStocoptim then
        update estimariprod1m set nec_c27 = aStocoptim - (v_rec.cf_c27 + aStoc - v_rec.c27) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c27 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c27 + aStoc - v_rec.C27;
      end if;
    end if;
    if aSaptamana &lt;= 28 then
      if v_rec.cf_c28 + aStoc - v_rec.c28 &lt; aStocoptim then
        update estimariprod1m set nec_c28 = aStocoptim - (v_rec.cf_c28 + aStoc - v_rec.c28) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c28 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c28 + aStoc - v_rec.C28;
      end if;
    end if;
    if aSaptamana &lt;= 29 then
      if v_rec.cf_c29 + aStoc - v_rec.c29 &lt; aStocoptim then
        update estimariprod1m set nec_c29 = aStocoptim - (v_rec.cf_c29 + aStoc - v_rec.c29) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c29 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c29 + aStoc - v_rec.C29;
      end if;
    end if;
    if aSaptamana &lt;= 30 then
      if v_rec.cf_c30 + aStoc - v_rec.c30 &lt; aStocoptim then
        update estimariprod1m set nec_c30 = aStocoptim - (v_rec.cf_c30 + aStoc - v_rec.c30) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c30 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c30 + aStoc - v_rec.C30;
      end if;
    end if;
    if aSaptamana &lt;= 31 then
      if v_rec.cf_c31 + aStoc - v_rec.c31 &lt; aStocoptim then
        update estimariprod1m set nec_c31 = aStocoptim - (v_rec.cf_c31 + aStoc - v_rec.c31) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c31 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c31 + aStoc - v_rec.C31;
      end if;
    end if;
    if aSaptamana &lt;= 32 then
      if v_rec.cf_c32 + aStoc - v_rec.c32 &lt; aStocoptim then
        update estimariprod1m set nec_c32 = aStocoptim - (v_rec.cf_c32 + aStoc - v_rec.c32) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c32 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c32 + aStoc - v_rec.C32;
      end if;
    end if;
    if aSaptamana &lt;= 33 then
      if v_rec.cf_c33 + aStoc - v_rec.c33 &lt; aStocoptim then
        update estimariprod1m set nec_c33 = aStocoptim - (v_rec.cf_c33 + aStoc - v_rec.c33) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c33 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c33 + aStoc - v_rec.C33;
      end if;
    end if;
    if aSaptamana &lt;= 34 then
      if v_rec.cf_c34 + aStoc - v_rec.c34 &lt; aStocoptim then
        update estimariprod1m set nec_c34 = aStocoptim - (v_rec.cf_c34 + aStoc - v_rec.c34) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c34 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c34 + aStoc - v_rec.C34;
      end if;
    end if;
    if aSaptamana &lt;= 35 then
      if v_rec.cf_c35 + aStoc - v_rec.c35 &lt; aStocoptim then
        update estimariprod1m set nec_c35 = aStocoptim - (v_rec.cf_c35 + aStoc - v_rec.c35) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c35 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c35 + aStoc - v_rec.C35;
      end if;
    end if;
    if aSaptamana &lt;= 36 then
      if v_rec.cf_c36 + aStoc - v_rec.c36 &lt; aStocoptim then
        update estimariprod1m set nec_c36 = aStocoptim - (v_rec.cf_c36 + aStoc - v_rec.c36) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c36 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c36 + aStoc - v_rec.C36;
      end if;
    end if;
    if aSaptamana &lt;= 37 then
      if v_rec.cf_c37 + aStoc - v_rec.c37 &lt; aStocoptim then
        update estimariprod1m set nec_c37 = aStocoptim - (v_rec.cf_c37 + aStoc - v_rec.c37) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c37 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c37 + aStoc - v_rec.C37;
      end if;
    end if;
    if aSaptamana &lt;= 38 then
      if v_rec.cf_c38 + aStoc - v_rec.c38 &lt; aStocoptim then
        update estimariprod1m set nec_c38 = aStocoptim - (v_rec.cf_c38 + aStoc - v_rec.c38) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c38 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c38 + aStoc - v_rec.C38;
      end if;
    end if;
    if aSaptamana &lt;= 39 then
      if v_rec.cf_c39 + aStoc - v_rec.c39 &lt; aStocoptim then
        update estimariprod1m set nec_c39 = aStocoptim - (v_rec.cf_c39 + aStoc - v_rec.c39) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c39 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c39 + aStoc - v_rec.C39;
      end if;
    end if;
    if aSaptamana &lt;= 40 then
      if v_rec.cf_c40 + aStoc - v_rec.c40 &lt; aStocoptim then
        update estimariprod1m set nec_c40 = aStocoptim - (v_rec.cf_c40 + aStoc - v_rec.c40) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c40 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c40 + aStoc - v_rec.C40;
      end if;
    end if;
    if aSaptamana &lt;= 41 then
      if v_rec.cf_c41 + aStoc - v_rec.c41 &lt; aStocoptim then
        update estimariprod1m set nec_c41 = aStocoptim - (v_rec.cf_c41 + aStoc - v_rec.c41) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c41 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c41 + aStoc - v_rec.C41;
      end if;
    end if;
    if aSaptamana &lt;= 42 then
      if v_rec.cf_c42 + aStoc - v_rec.c42 &lt; aStocoptim then
        update estimariprod1m set nec_c42 = aStocoptim - (v_rec.cf_c42 + aStoc - v_rec.c42) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c42 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c42 + aStoc - v_rec.C42;
      end if;
    end if;
    if aSaptamana &lt;= 43 then
      if v_rec.cf_c43 + aStoc - v_rec.c43 &lt; aStocoptim then
        update estimariprod1m set nec_c43 = aStocoptim - (v_rec.cf_c43 + aStoc - v_rec.c43) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c43 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c43 + aStoc - v_rec.C43;
      end if;
    end if;
    if aSaptamana &lt;= 44 then
      if v_rec.cf_c44 + aStoc - v_rec.c44 &lt; aStocoptim then
        update estimariprod1m set nec_c44 = aStocoptim - (v_rec.cf_c44 + aStoc - v_rec.c44) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c44 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c44 + aStoc - v_rec.C44;
      end if;
    end if;
    if aSaptamana &lt;= 45 then
      if v_rec.cf_c45 + aStoc - v_rec.c45 &lt; aStocoptim then
        update estimariprod1m set nec_c45 = aStocoptim - (v_rec.cf_c45 + aStoc - v_rec.c45) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c45 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c45 + aStoc - v_rec.C45;
      end if;
    end if;
    if aSaptamana &lt;= 46 then
      if v_rec.cf_c46 + aStoc - v_rec.c46 &lt; aStocoptim then
        update estimariprod1m set nec_c46 = aStocoptim - (v_rec.cf_c46 + aStoc - v_rec.c46) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c46 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c46 + aStoc - v_rec.C46;
      end if;
    end if;
    if aSaptamana &lt;= 47 then
      if v_rec.cf_c47 + aStoc - v_rec.c47 &lt; aStocoptim then
        update estimariprod1m set nec_c47 = aStocoptim - (v_rec.cf_c47 + aStoc - v_rec.c47) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c47 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c47 + aStoc - v_rec.C47;
      end if;
    end if;
    if aSaptamana &lt;= 48 then
      if v_rec.cf_c48 + aStoc - v_rec.c48 &lt; aStocoptim then
        update estimariprod1m set nec_c48 = aStocoptim - (v_rec.cf_c48 + aStoc - v_rec.c48) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c48 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c48 + aStoc - v_rec.C48;
      end if;
    end if;
    if aSaptamana &lt;= 49 then
      if v_rec.cf_c49 + aStoc - v_rec.c49 &lt; aStocoptim then
        update estimariprod1m set nec_c49 = aStocoptim - (v_rec.cf_c49 + aStoc - v_rec.c49) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c49 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c49 + aStoc - v_rec.C49;
      end if;
    end if;
    if aSaptamana &lt;= 50 then
      if v_rec.cf_c50 + aStoc - v_rec.c50 &lt; aStocoptim then
        update estimariprod1m set nec_c50 = aStocoptim - (v_rec.cf_c50 + aStoc - v_rec.c50) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c50 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c50 + aStoc - v_rec.C50;
      end if;
    end if;
    if aSaptamana &lt;= 51 then
      if v_rec.cf_c51 + aStoc - v_rec.c51 &lt; aStocoptim then
        update estimariprod1m set nec_c51 = aStocoptim - (v_rec.cf_c51 + aStoc - v_rec.c51) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c51 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c51 + aStoc - v_rec.C51;
      end if;
    end if;
    if aSaptamana &lt;= 52 then
      if v_rec.cf_c52 + aStoc - v_rec.c52 &lt; aStocoptim then
        update estimariprod1m set nec_c52 = aStocoptim - (v_rec.cf_c52 + aStoc - v_rec.c52) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c52 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c52 + aStoc - v_rec.C52;
      end if;
    end if;
    if aSaptamana &lt;= 53 then
      if v_rec.cf_c53 + aStoc - v_rec.c53 &lt; aStocoptim then
        update estimariprod1m set nec_c53 = aStocoptim - (v_rec.cf_c53 + aStoc - v_rec.c53) where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := aStocoptim;
      else
        update estimariprod1m set nec_c53 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
        aStoc := v_rec.cf_c53 + aStoc - v_rec.C53;
      end if;
    end if;
    if v_rec.cf_n1 + aStoc - v_rec.n1 &lt; aStocoptim then
      update estimariprod1m set nec_n1 = aStocoptim - (v_rec.cf_n1 + aStoc - v_rec.n1) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n1 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n1 + aStoc - v_rec.n1;
    end if;
    if v_rec.cf_n2 + aStoc - v_rec.n2 &lt; aStocoptim then
      update estimariprod1m set nec_n2 = aStocoptim - (v_rec.cf_n2 + aStoc - v_rec.n2) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n2 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n2 + aStoc - v_rec.n2;
    end if;
    if v_rec.cf_n3 + aStoc - v_rec.n3 &lt; aStocoptim then
      update estimariprod1m set nec_n3 = aStocoptim - (v_rec.cf_n3 + aStoc - v_rec.n3) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n3 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n3 + aStoc - v_rec.n3;
    end if;
    if v_rec.cf_n4 + aStoc - v_rec.n4 &lt; aStocoptim then
      update estimariprod1m set nec_n4 = aStocoptim - (v_rec.cf_n4 + aStoc - v_rec.n4) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n4 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n4 + aStoc - v_rec.n4;
    end if;
    if v_rec.cf_n5 + aStoc - v_rec.n5 &lt; aStocoptim then
      update estimariprod1m set nec_n5 = aStocoptim - (v_rec.cf_n5 + aStoc - v_rec.n5) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n5 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n5 + aStoc - v_rec.n5;
    end if;
    if v_rec.cf_n6 + aStoc - v_rec.n6 &lt; aStocoptim then
      update estimariprod1m set nec_n6 = aStocoptim - (v_rec.cf_n6 + aStoc - v_rec.n6) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n6 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n6 + aStoc - v_rec.n6;
    end if;
    if v_rec.cf_n7 + aStoc - v_rec.n7 &lt; aStocoptim then
      update estimariprod1m set nec_n7 = aStocoptim - (v_rec.cf_n7 + aStoc - v_rec.n7) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n7 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n7 + aStoc - v_rec.n7;
    end if;
    if v_rec.cf_n8 + aStoc - v_rec.n8 &lt; aStocoptim then
      update estimariprod1m set nec_n8 = aStocoptim - (v_rec.cf_n8 + aStoc - v_rec.n8) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n8 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n8 + aStoc - v_rec.n8;
    end if;
    if v_rec.cf_n9 + aStoc - v_rec.n9 &lt; aStocoptim then
      update estimariprod1m set nec_n9 = aStocoptim - (v_rec.cf_n9 + aStoc - v_rec.n9) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n9 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n9 + aStoc - v_rec.n9;
    end if;
    if v_rec.cf_n10 + aStoc - v_rec.n10 &lt; aStocoptim then
      update estimariprod1m set nec_n10 = aStocoptim - (v_rec.cf_n10 + aStoc - v_rec.n10) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n10 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n10 + aStoc - v_rec.n10;
    end if;
    if v_rec.cf_n11 + aStoc - v_rec.n11 &lt; aStocoptim then
      update estimariprod1m set nec_n11 = aStocoptim - (v_rec.cf_n11 + aStoc - v_rec.n11) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n11 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n11 + aStoc - v_rec.n11;
    end if;
    if v_rec.cf_n12 + aStoc - v_rec.n12 &lt; aStocoptim then
      update estimariprod1m set nec_n12 = aStocoptim - (v_rec.cf_n12 + aStoc - v_rec.n12) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n12 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n12 + aStoc - v_rec.n12;
    end if;
    if v_rec.cf_n13 + aStoc - v_rec.n13 &lt; aStocoptim then
      update estimariprod1m set nec_n13 = aStocoptim - (v_rec.cf_n13 + aStoc - v_rec.n13) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n13 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n13 + aStoc - v_rec.n13;
    end if;
    if v_rec.cf_n14 + aStoc - v_rec.n14 &lt; aStocoptim then
      update estimariprod1m set nec_n14 = aStocoptim - (v_rec.cf_n14 + aStoc - v_rec.n14) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n14 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n14 + aStoc - v_rec.n14;
    end if;
    if v_rec.cf_n15 + aStoc - v_rec.n15 &lt; aStocoptim then
      update estimariprod1m set nec_n15 = aStocoptim - (v_rec.cf_n15 + aStoc - v_rec.n15) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n15 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n15 + aStoc - v_rec.n15;
    end if;
    if v_rec.cf_n16 + aStoc - v_rec.n16 &lt; aStocoptim then
      update estimariprod1m set nec_n16 = aStocoptim - (v_rec.cf_n16 + aStoc - v_rec.n16) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n16 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n16 + aStoc - v_rec.n16;
    end if;
    if v_rec.cf_n17 + aStoc - v_rec.n17 &lt; aStocoptim then
      update estimariprod1m set nec_n17 = aStocoptim - (v_rec.cf_n17 + aStoc - v_rec.n17) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n17 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n17 + aStoc - v_rec.n17;
    end if;
    if v_rec.cf_n18 + aStoc - v_rec.n18 &lt; aStocoptim then
      update estimariprod1m set nec_n18 = aStocoptim - (v_rec.cf_n18 + aStoc - v_rec.n18) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n18 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n18 + aStoc - v_rec.n18;
    end if;
    if v_rec.cf_n19 + aStoc - v_rec.n19 &lt; aStocoptim then
      update estimariprod1m set nec_n19 = aStocoptim - (v_rec.cf_n19 + aStoc - v_rec.n19) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n19 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n19 + aStoc - v_rec.n19;
    end if;
    if v_rec.cf_n20 + aStoc - v_rec.n20 &lt; aStocoptim then
      update estimariprod1m set nec_n20 = aStocoptim - (v_rec.cf_n20 + aStoc - v_rec.n20) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n20 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n20 + aStoc - v_rec.n20;
    end if;
    if v_rec.cf_n21 + aStoc - v_rec.n21 &lt; aStocoptim then
      update estimariprod1m set nec_n21 = aStocoptim - (v_rec.cf_n21 + aStoc - v_rec.n21) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n21 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n21 + aStoc - v_rec.n21;
    end if;
    if v_rec.cf_n22 + aStoc - v_rec.n22 &lt; aStocoptim then
      update estimariprod1m set nec_n22 = aStocoptim - (v_rec.cf_n22 + aStoc - v_rec.n22) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n22 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n22 + aStoc - v_rec.n22;
    end if;
    if v_rec.cf_n23 + aStoc - v_rec.n23 &lt; aStocoptim then
      update estimariprod1m set nec_n23 = aStocoptim - (v_rec.cf_n23 + aStoc - v_rec.n23) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n23 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n23 + aStoc - v_rec.n23;
    end if;
    if v_rec.cf_n24 + aStoc - v_rec.n24 &lt; aStocoptim then
      update estimariprod1m set nec_n24 = aStocoptim - (v_rec.cf_n24 + aStoc - v_rec.n24) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n24 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n24 + aStoc - v_rec.n24;
    end if;
    if v_rec.cf_n25 + aStoc - v_rec.n25 &lt; aStocoptim then
      update estimariprod1m set nec_n25 = aStocoptim - (v_rec.cf_n25 + aStoc - v_rec.n25) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n25 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n25 + aStoc - v_rec.n25;
    end if;
    if v_rec.cf_n26 + aStoc - v_rec.n26 &lt; aStocoptim then
      update estimariprod1m set nec_n26 = aStocoptim - (v_rec.cf_n26 + aStoc - v_rec.n26) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n26 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n26 + aStoc - v_rec.n26;
    end if;
    if v_rec.cf_n27 + aStoc - v_rec.n27 &lt; aStocoptim then
      update estimariprod1m set nec_n27 = aStocoptim - (v_rec.cf_n27 + aStoc - v_rec.n27) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n27 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n27 + aStoc - v_rec.n27;
    end if;
    if v_rec.cf_n28 + aStoc - v_rec.n28 &lt; aStocoptim then
      update estimariprod1m set nec_n28 = aStocoptim - (v_rec.cf_n28 + aStoc - v_rec.n28) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n28 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n28 + aStoc - v_rec.n28;
    end if;
    if v_rec.cf_n29 + aStoc - v_rec.n29 &lt; aStocoptim then
      update estimariprod1m set nec_n29 = aStocoptim - (v_rec.cf_n29 + aStoc - v_rec.n29) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n29 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n29 + aStoc - v_rec.n29;
    end if;
    if v_rec.cf_n30 + aStoc - v_rec.n30 &lt; aStocoptim then
      update estimariprod1m set nec_n30 = aStocoptim - (v_rec.cf_n30 + aStoc - v_rec.n30) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n30 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n30 + aStoc - v_rec.n30;
    end if;
    if v_rec.cf_n31 + aStoc - v_rec.n31 &lt; aStocoptim then
      update estimariprod1m set nec_n31 = aStocoptim - (v_rec.cf_n31 + aStoc - v_rec.n31) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n31 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n31 + aStoc - v_rec.n31;
    end if;
    if v_rec.cf_n32 + aStoc - v_rec.n32 &lt; aStocoptim then
      update estimariprod1m set nec_n32 = aStocoptim - (v_rec.cf_n32 + aStoc - v_rec.n32) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n32 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n32 + aStoc - v_rec.n32;
    end if;
    if v_rec.cf_n33 + aStoc - v_rec.n33 &lt; aStocoptim then
      update estimariprod1m set nec_n33 = aStocoptim - (v_rec.cf_n33 + aStoc - v_rec.n33) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n33 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n33 + aStoc - v_rec.n33;
    end if;
    if v_rec.cf_n34 + aStoc - v_rec.n34 &lt; aStocoptim then
      update estimariprod1m set nec_n34 = aStocoptim - (v_rec.cf_n34 + aStoc - v_rec.n34) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n34 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n34 + aStoc - v_rec.n34;
    end if;
    if v_rec.cf_n35 + aStoc - v_rec.n35 &lt; aStocoptim then
      update estimariprod1m set nec_n35 = aStocoptim - (v_rec.cf_n35 + aStoc - v_rec.n35) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n35 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n35 + aStoc - v_rec.n35;
    end if;
    if v_rec.cf_n36 + aStoc - v_rec.n36 &lt; aStocoptim then
      update estimariprod1m set nec_n36 = aStocoptim - (v_rec.cf_n36 + aStoc - v_rec.n36) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n36 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n36 + aStoc - v_rec.n36;
    end if;
    if v_rec.cf_n37 + aStoc - v_rec.n37 &lt; aStocoptim then
      update estimariprod1m set nec_n37 = aStocoptim - (v_rec.cf_n37 + aStoc - v_rec.n37) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n37 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n37 + aStoc - v_rec.n37;
    end if;
    if v_rec.cf_n38 + aStoc - v_rec.n38 &lt; aStocoptim then
      update estimariprod1m set nec_n38 = aStocoptim - (v_rec.cf_n38 + aStoc - v_rec.n38) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n38 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n38 + aStoc - v_rec.n38;
    end if;
    if v_rec.cf_n39 + aStoc - v_rec.n39 &lt; aStocoptim then
      update estimariprod1m set nec_n39 = aStocoptim - (v_rec.cf_n39 + aStoc - v_rec.n39) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n39 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n39 + aStoc - v_rec.n39;
    end if;
    if v_rec.cf_n40 + aStoc - v_rec.n40 &lt; aStocoptim then
      update estimariprod1m set nec_n40 = aStocoptim - (v_rec.cf_n40 + aStoc - v_rec.n40) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n40 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n40 + aStoc - v_rec.n40;
    end if;
    if v_rec.cf_n41 + aStoc - v_rec.n41 &lt; aStocoptim then
      update estimariprod1m set nec_n41 = aStocoptim - (v_rec.cf_n41 + aStoc - v_rec.n41) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n41 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n41 + aStoc - v_rec.n41;
    end if;
    if v_rec.cf_n42 + aStoc - v_rec.n42 &lt; aStocoptim then
      update estimariprod1m set nec_n42 = aStocoptim - (v_rec.cf_n42 + aStoc - v_rec.n42) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n42 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n42 + aStoc - v_rec.n42;
    end if;
    if v_rec.cf_n43 + aStoc - v_rec.n43 &lt; aStocoptim then
      update estimariprod1m set nec_n43 = aStocoptim - (v_rec.cf_n43 + aStoc - v_rec.n43) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n43 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n43 + aStoc - v_rec.n43;
    end if;
    if v_rec.cf_n44 + aStoc - v_rec.n44 &lt; aStocoptim then
      update estimariprod1m set nec_n44 = aStocoptim - (v_rec.cf_n44 + aStoc - v_rec.n44) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n44 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n44 + aStoc - v_rec.n44;
    end if;
    if v_rec.cf_n45 + aStoc - v_rec.n45 &lt; aStocoptim then
      update estimariprod1m set nec_n45 = aStocoptim - (v_rec.cf_n45 + aStoc - v_rec.n45) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n45 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n45 + aStoc - v_rec.n45;
    end if;
    if v_rec.cf_n46 + aStoc - v_rec.n46 &lt; aStocoptim then
      update estimariprod1m set nec_n46 = aStocoptim - (v_rec.cf_n46 + aStoc - v_rec.n46) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n46 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n46 + aStoc - v_rec.n46;
    end if;
    if v_rec.cf_n47 + aStoc - v_rec.n47 &lt; aStocoptim then
      update estimariprod1m set nec_n47 = aStocoptim - (v_rec.cf_n47 + aStoc - v_rec.n47) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n47 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n47 + aStoc - v_rec.n47;
    end if;
    if v_rec.cf_n48 + aStoc - v_rec.n48 &lt; aStocoptim then
      update estimariprod1m set nec_n48 = aStocoptim - (v_rec.cf_n48 + aStoc - v_rec.n48) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n48 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n48 + aStoc - v_rec.n48;
    end if;
    if v_rec.cf_n49 + aStoc - v_rec.n49 &lt; aStocoptim then
      update estimariprod1m set nec_n49 = aStocoptim - (v_rec.cf_n49 + aStoc - v_rec.n49) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n49 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n49 + aStoc - v_rec.n49;
    end if;
    if v_rec.cf_n50 + aStoc - v_rec.n50 &lt; aStocoptim then
      update estimariprod1m set nec_n50 = aStocoptim - (v_rec.cf_n50 + aStoc - v_rec.n50) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n50 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n50 + aStoc - v_rec.n50;
    end if;
    if v_rec.cf_n51 + aStoc - v_rec.n51 &lt; aStocoptim then
      update estimariprod1m set nec_n51 = aStocoptim - (v_rec.cf_n51 + aStoc - v_rec.n51) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n51 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n51 + aStoc - v_rec.n51;
    end if;
    if v_rec.cf_n52 + aStoc - v_rec.n52 &lt; aStocoptim then
      update estimariprod1m set nec_n52 = aStocoptim - (v_rec.cf_n52 + aStoc - v_rec.n52) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n52 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n52 + aStoc - v_rec.n52;
    end if;
    if v_rec.cf_n53 + aStoc - v_rec.n53 &lt; aStocoptim then
      update estimariprod1m set nec_n53 = aStocoptim - (v_rec.cf_n53 + aStoc - v_rec.n53) where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := aStocoptim;
    else
      update estimariprod1m set nec_n53 = 0 where codestimareprod1m = v_rec.codestimareprod1m;
      aStoc := v_rec.cf_n53 + aStoc - v_rec.n53;
    end if;
  end loop;
  commit;
end;

procedure AduCmdF(aSaptamana in number, aSaptamanaF in number, aAnImport in number, aAnF in number, aCodEstimareProd1m in number, aSubunitatea in number) is
sSQL varchar2(5000);
iter number(10);
begin
  if aSaptamana = 1 then
    update estimariprod1m p1m
    set
      cf_c1 =
             (select sum(c1.restacceptat)
              from comanda1 c1
                   inner join comanda c on c1.codcomanda = c.codcomanda
              where C1.CodObiect = p1m.codobiect and
                    c1.termen &lt;= iso_week_to_date(aanimport, 1) + 6 and
                    nvl(c.Anulat,0) = 0 and c.tipdoc = 8 and c.subunitatea = aSubunitatea and nvl(c.inchisa,0) = 0
              )
    where p1m.codestimareprod1m = aCodestimareProd1m;
  end if;

  for iter in 2..53 loop
    sSQL := &apos;begin
              if &apos;||(aSaptamana + aAnImport * 53)||&apos; &lt;= &apos;||(iter + aAnImport * 53)||&apos; and &apos;||(2 + aAnImport * 53)||&apos; &lt;= &apos;||(aSaptamanaF + aAnF * 53)||&apos; then
                if &apos;||aSaptamana||&apos; = &apos;||iter||&apos; then
                  update estimariprod1m p1m
                  set
                    cf_c&apos;||iter||&apos; =
                           (select sum(c1.restacceptat)
                            from comanda1 c1
                                 inner join comanda c on c1.codcomanda = c.codcomanda
                            where C1.CodObiect = p1m.codobiect and
                                  c1.termen &lt;= iso_week_to_date(&apos;||aAnImport||&apos;, &apos;||iter||&apos;) + 6 and
                                  nvl(c.Anulat,0) = 0 and c.tipdoc = 8 and c.subunitatea = &apos;||aSubunitatea||&apos; and nvl(c.inchisa,0) = 0
                            )
                  where p1m.codestimareprod1m = &apos;||aCodestimareProd1m||&apos;;
                else
                  update estimariprod1m p1m
                  set
                    cf_c&apos;||iter||&apos; =
                           (select sum(c1.restacceptat)
                            from comanda1 c1
                                 inner join comanda c on c1.codcomanda = c.codcomanda
                            where C1.CodObiect = p1m.codobiect and
                                  c1.termen between iso_week_to_date(&apos;||aAnImport||&apos;, &apos;||iter||&apos;)
                                  and iso_week_to_date(&apos;||aAnImport||&apos;, &apos;||iter||&apos;) + 6 and
                                  nvl(c.Anulat,0) = 0 and c.tipdoc = 8 and c.subunitatea = &apos;||aSubunitatea||&apos; and nvl(c.inchisa,0) = 0
                            )
                  where p1m.codestimareprod1m = &apos;||aCodestimareProd1m||&apos;;
                end if;
              end if;
            end;&apos;;
    execute immediate sSQL;
  end loop;

  if aAnF &gt; aAnImport then
    for iter in 1..53 loop
      sSQL := &apos;begin
                 if &apos;||(iter + aAnF * 53)||&apos; &lt;= &apos;||(aSaptamanaF + aAnF * 53)||&apos; then
                   update estimariprod1m p1m
                   set
                     cf_n&apos;||iter||&apos; =
                            (select sum(c1.restacceptat)
                             from comanda1 c1
                                  inner join comanda c on c1.codcomanda = c.codcomanda
                             where C1.CodObiect = p1m.codobiect and
                                   c1.termen between iso_week_to_date(&apos;||aAnF||&apos;, &apos;||iter||&apos;)
                                   and iso_week_to_date(&apos;||aAnF||&apos;, &apos;||iter||&apos;) + 6 and
                                   nvl(c.Anulat,0) = 0 and c.tipdoc = 8 and c.subunitatea = &apos;||aSubunitatea||&apos; and nvl(c.inchisa,0) = 0
                             )
                   where p1m.codestimareprod1m = &apos;||aCodestimareProd1m||&apos;;
                 end if;
               end;&apos;;
      execute immediate sSQL;
    end loop;
  end if;

  commit;
end;

procedure CalculValori(aCodEstimareProd1m in number, aAnImport in number, aAnF in number) is
aScadenta number(10);
sWeek number(5);
scadAn number(4);
sAn varchar2(1);
sSaptamana varchar2(10);
sSQL varchar2(1000);
iter number(10);
begin
    FOR V_TMP IN (SELECT
                    nvl(pret,0) * nvl(nec_c1 ,0) val_C1,
                    nvl(pret,0) * nvl(nec_c2 ,0) val_C2,
                    nvl(pret,0) * nvl(nec_c3 ,0) val_C3,
                    nvl(pret,0) * nvl(nec_c4 ,0) val_C4,
                    nvl(pret,0) * nvl(nec_c5 ,0) val_C5,
                    nvl(pret,0) * nvl(nec_c6 ,0) val_C6,
                    nvl(pret,0) * nvl(nec_c7 ,0) val_C7,
                    nvl(pret,0) * nvl(nec_c8 ,0) val_C8,
                    nvl(pret,0) * nvl(nec_c9 ,0) val_C9,
                    nvl(pret,0) * nvl(nec_c10,0) val_C10,
                    nvl(pret,0) * nvl(nec_c11,0) val_C11,
                    nvl(pret,0) * nvl(nec_c12,0) val_C12,
                    nvl(pret,0) * nvl(nec_c13,0) val_C13,
                    nvl(pret,0) * nvl(nec_c14,0) val_C14,
                    nvl(pret,0) * nvl(nec_c15,0) val_C15,
                    nvl(pret,0) * nvl(nec_c16,0) val_C16,
                    nvl(pret,0) * nvl(nec_c17,0) val_C17,
                    nvl(pret,0) * nvl(nec_c18,0) val_C18,
                    nvl(pret,0) * nvl(nec_c19,0) val_C19,
                    nvl(pret,0) * nvl(nec_c20,0) val_C20,
                    nvl(pret,0) * nvl(nec_c21,0) val_C21,
                    nvl(pret,0) * nvl(nec_c22,0) val_C22,
                    nvl(pret,0) * nvl(nec_c23,0) val_C23,
                    nvl(pret,0) * nvl(nec_c24,0) val_C24,
                    nvl(pret,0) * nvl(nec_c25,0) val_C25,
                    nvl(pret,0) * nvl(nec_c26,0) val_C26,
                    nvl(pret,0) * nvl(nec_c27,0) val_C27,
                    nvl(pret,0) * nvl(nec_c28,0) val_C28,
                    nvl(pret,0) * nvl(nec_c29,0) val_C29,
                    nvl(pret,0) * nvl(nec_c30,0) val_C30,
                    nvl(pret,0) * nvl(nec_c31,0) val_C31,
                    nvl(pret,0) * nvl(nec_c32,0) val_C32,
                    nvl(pret,0) * nvl(nec_c33,0) val_C33,
                    nvl(pret,0) * nvl(nec_c34,0) val_C34,
                    nvl(pret,0) * nvl(nec_c35,0) val_C35,
                    nvl(pret,0) * nvl(nec_c36,0) val_C36,
                    nvl(pret,0) * nvl(nec_c37,0) val_C37,
                    nvl(pret,0) * nvl(nec_c38,0) val_C38,
                    nvl(pret,0) * nvl(nec_c39,0) val_C39,
                    nvl(pret,0) * nvl(nec_c40,0) val_C40,
                    nvl(pret,0) * nvl(nec_c41,0) val_C41,
                    nvl(pret,0) * nvl(nec_c42,0) val_C42,
                    nvl(pret,0) * nvl(nec_c43,0) val_C43,
                    nvl(pret,0) * nvl(nec_c44,0) val_C44,
                    nvl(pret,0) * nvl(nec_c45,0) val_C45,
                    nvl(pret,0) * nvl(nec_c46,0) val_C46,
                    nvl(pret,0) * nvl(nec_c47,0) val_C47,
                    nvl(pret,0) * nvl(nec_c48,0) val_C48,
                    nvl(pret,0) * nvl(nec_c49,0) val_C49,
                    nvl(pret,0) * nvl(nec_c50,0) val_C50,
                    nvl(pret,0) * nvl(nec_c51,0) val_C51,
                    nvl(pret,0) * nvl(nec_c52,0) val_C52,
                    nvl(pret,0) * nvl(nec_C53,0) val_C53,
                    nvl(pret,0) * nvl(nec_n1 ,0) val_n1,
                    nvl(pret,0) * nvl(nec_n2 ,0) val_N2,
                    nvl(pret,0) * nvl(nec_n3 ,0) val_N3,
                    nvl(pret,0) * nvl(nec_n4 ,0) val_N4,
                    nvl(pret,0) * nvl(nec_n5 ,0) val_N5,
                    nvl(pret,0) * nvl(nec_n6 ,0) val_N6,
                    nvl(pret,0) * nvl(nec_n7 ,0) val_N7,
                    nvl(pret,0) * nvl(nec_n8 ,0) val_N8,
                    nvl(pret,0) * nvl(nec_n9 ,0) val_N9,
                    nvl(pret,0) * nvl(nec_n10,0) val_n10,
                    nvl(pret,0) * nvl(nec_n11,0) val_n11,
                    nvl(pret,0) * nvl(nec_n12,0) val_N12,
                    nvl(pret,0) * nvl(nec_n13,0) val_N13,
                    nvl(pret,0) * nvl(nec_n14,0) val_N14,
                    nvl(pret,0) * nvl(nec_n15,0) val_N15,
                    nvl(pret,0) * nvl(nec_n16,0) val_N16,
                    nvl(pret,0) * nvl(nec_n17,0) val_N17,
                    nvl(pret,0) * nvl(nec_n18,0) val_N18,
                    nvl(pret,0) * nvl(nec_n19,0) val_N19,
                    nvl(pret,0) * nvl(nec_n20,0) val_n20,
                    nvl(pret,0) * nvl(nec_n21,0) val_n21,
                    nvl(pret,0) * nvl(nec_n22,0) val_N22,
                    nvl(pret,0) * nvl(nec_n23,0) val_N23,
                    nvl(pret,0) * nvl(nec_n24,0) val_N24,
                    nvl(pret,0) * nvl(nec_n25,0) val_N25,
                    nvl(pret,0) * nvl(nec_n26,0) val_N26,
                    nvl(pret,0) * nvl(nec_n27,0) val_N27,
                    nvl(pret,0) * nvl(nec_n28,0) val_N28,
                    nvl(pret,0) * nvl(nec_n29,0) val_N29,
                    nvl(pret,0) * nvl(nec_n30,0) val_n30,
                    nvl(pret,0) * nvl(nec_n31,0) val_n31,
                    nvl(pret,0) * nvl(nec_n32,0) val_N32,
                    nvl(pret,0) * nvl(nec_n33,0) val_N33,
                    nvl(pret,0) * nvl(nec_n34,0) val_N34,
                    nvl(pret,0) * nvl(nec_n35,0) val_N35,
                    nvl(pret,0) * nvl(nec_n36,0) val_N36,
                    nvl(pret,0) * nvl(nec_n37,0) val_N37,
                    nvl(pret,0) * nvl(nec_n38,0) val_N38,
                    nvl(pret,0) * nvl(nec_n39,0) val_N39,
                    nvl(pret,0) * nvl(nec_n40,0) val_n40,
                    nvl(pret,0) * nvl(nec_n41,0) val_n41,
                    nvl(pret,0) * nvl(nec_n42,0) val_N42,
                    nvl(pret,0) * nvl(nec_n43,0) val_N43,
                    nvl(pret,0) * nvl(nec_n44,0) val_N44,
                    nvl(pret,0) * nvl(nec_n45,0) val_N45,
                    nvl(pret,0) * nvl(nec_n46,0) val_N46,
                    nvl(pret,0) * nvl(nec_n47,0) val_N47,
                    nvl(pret,0) * nvl(nec_n48,0) val_N48,
                    nvl(pret,0) * nvl(nec_n49,0) val_N49,
                    nvl(pret,0) * nvl(nec_n50,0) val_n50,
                    nvl(pret,0) * nvl(nec_n51,0) val_n51,
                    nvl(pret,0) * nvl(nec_n52,0) val_n52,
                    nvl(pret,0) * nvl(nec_n53,0) val_n53,
                    Scadenta
                  FROM ESTIMARIPROD1M
                  WHERE CODESTIMAREPROD1M = aCODESTIMAREPROD1M) LOOP
      aScadenta := nvl(v_tmp.Scadenta,0);
      if aScadenta = 0 then
        sSQL := &apos;update estimariprod1m set val_C1 = &apos;||v_tmp.val_c1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C2 = &apos;||v_tmp.val_c2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C3 = &apos;||v_tmp.val_c3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C4 = &apos;||v_tmp.val_c4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C5 = &apos;||v_tmp.val_c5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C6 = &apos;||v_tmp.val_c6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C7 = &apos;||v_tmp.val_c7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C8 = &apos;||v_tmp.val_c8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C9 = &apos;||v_tmp.val_c9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C10 = &apos;||v_tmp.val_c10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C11 = &apos;||v_tmp.val_c11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C12 = &apos;||v_tmp.val_c12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C13 = &apos;||v_tmp.val_c13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C14 = &apos;||v_tmp.val_c14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C15 = &apos;||v_tmp.val_c15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C16 = &apos;||v_tmp.val_c16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C17 = &apos;||v_tmp.val_c17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C18 = &apos;||v_tmp.val_c18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C19 = &apos;||v_tmp.val_c19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C20 = &apos;||v_tmp.val_c20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C21 = &apos;||v_tmp.val_c21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C22 = &apos;||v_tmp.val_c22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C23 = &apos;||v_tmp.val_c23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C24 = &apos;||v_tmp.val_c24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C25 = &apos;||v_tmp.val_c25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C26 = &apos;||v_tmp.val_c26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C27 = &apos;||v_tmp.val_c27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C28 = &apos;||v_tmp.val_c28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C29 = &apos;||v_tmp.val_c29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C30 = &apos;||v_tmp.val_c30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C31 = &apos;||v_tmp.val_c31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C32 = &apos;||v_tmp.val_c32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C33 = &apos;||v_tmp.val_c33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C34 = &apos;||v_tmp.val_c34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C35 = &apos;||v_tmp.val_c35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C36 = &apos;||v_tmp.val_c36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C37 = &apos;||v_tmp.val_c37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C38 = &apos;||v_tmp.val_c38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C39 = &apos;||v_tmp.val_c39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C40 = &apos;||v_tmp.val_c40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C41 = &apos;||v_tmp.val_c41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C42 = &apos;||v_tmp.val_c42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C43 = &apos;||v_tmp.val_c43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C44 = &apos;||v_tmp.val_c44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C45 = &apos;||v_tmp.val_c45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C46 = &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C47 = &apos;||v_tmp.val_c47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C48 = &apos;||v_tmp.val_c48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C49 = &apos;||v_tmp.val_c49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C50 = &apos;||v_tmp.val_c50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C51 = &apos;||v_tmp.val_c51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C52 = &apos;||v_tmp.val_c52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set val_C53 = &apos;||v_tmp.val_c53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N1 = &apos;||v_tmp.VAL_N1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N2 = &apos;||v_tmp.VAL_N2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N3 = &apos;||v_tmp.VAL_N3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N4 = &apos;||v_tmp.VAL_N4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N5 = &apos;||v_tmp.VAL_N5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N6 = &apos;||v_tmp.VAL_N6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N7 = &apos;||v_tmp.VAL_N7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N8 = &apos;||v_tmp.VAL_N8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N9 = &apos;||v_tmp.VAL_N9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N10 = &apos;||v_tmp.VAL_N10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N11 = &apos;||v_tmp.VAL_N11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N12 = &apos;||v_tmp.VAL_N12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N13 = &apos;||v_tmp.VAL_N13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N14 = &apos;||v_tmp.VAL_N14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N15 = &apos;||v_tmp.VAL_N15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N16 = &apos;||v_tmp.VAL_N16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N17 = &apos;||v_tmp.VAL_N17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N18 = &apos;||v_tmp.VAL_N18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N19 = &apos;||v_tmp.VAL_N19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N20 = &apos;||v_tmp.VAL_N20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N21 = &apos;||v_tmp.VAL_N21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N22 = &apos;||v_tmp.VAL_N22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N23 = &apos;||v_tmp.VAL_N23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N24 = &apos;||v_tmp.VAL_N24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N25 = &apos;||v_tmp.VAL_N25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N26 = &apos;||v_tmp.VAL_N26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N27 = &apos;||v_tmp.VAL_N27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N28 = &apos;||v_tmp.VAL_N28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N29 = &apos;||v_tmp.VAL_N29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N30 = &apos;||v_tmp.VAL_N30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N31 = &apos;||v_tmp.VAL_N31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N32 = &apos;||v_tmp.VAL_N32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N33 = &apos;||v_tmp.VAL_N33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N34 = &apos;||v_tmp.VAL_N34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N35 = &apos;||v_tmp.VAL_N35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N36 = &apos;||v_tmp.VAL_N36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N37 = &apos;||v_tmp.VAL_N37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N38 = &apos;||v_tmp.VAL_N38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N39 = &apos;||v_tmp.VAL_N39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N40 = &apos;||v_tmp.VAL_N40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N41 = &apos;||v_tmp.VAL_N41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N42 = &apos;||v_tmp.VAL_N42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N43 = &apos;||v_tmp.VAL_N43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N44 = &apos;||v_tmp.VAL_N44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N45 = &apos;||v_tmp.VAL_N45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N46 = &apos;||v_tmp.VAL_N46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N47 = &apos;||v_tmp.VAL_N47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N48 = &apos;||v_tmp.VAL_N48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N49 = &apos;||v_tmp.VAL_N49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N50 = &apos;||v_tmp.VAL_N50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N51 = &apos;||v_tmp.VAL_N51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N52 = &apos;||v_tmp.VAL_N52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
        sSQL := &apos;update estimariprod1m set VAL_N53 = &apos;||v_tmp.VAL_N53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
        execute immediate sSQL;
      else
      if v_tmp.val_c1 &gt; 0 then
        select to_number(to_char(Trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 1 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(Trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 1 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c2 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 2 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 2 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c3 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 3 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 3 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c4 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 4 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 4 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c5 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 5 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 5 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c6 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 6 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 6 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c7 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 7 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 7 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c8 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 8 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 8 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c9 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 9 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 9 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c10 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 10 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 10 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c11 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 11 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 11 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c12 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 12 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 12 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c13 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 13 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 13 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c14 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 14 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 14 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c15 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 15 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 15 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c16 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 16 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 16 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c17 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 17 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 17 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c18 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 18 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 18 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c19 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 19 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 19 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c20 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 20 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 20 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c21 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 21 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 21 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c22 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 22 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 22 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c23 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 23 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 23 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c24 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 24 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 24 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c25 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 25 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 25 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c26 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 26 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 26 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c27 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 27 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 27 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c28 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 28 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 28 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c29 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 29 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 29 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c30 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 30 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 30 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c31 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 31 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 31 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c32 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 32 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 32 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c33 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 33 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 33 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c34 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 34 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 34 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c35 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 35 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 35 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c36 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 36 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 36 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c37 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 37 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 37 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c38 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 38 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 38 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c39 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 39 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 39 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c40 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 40 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 40 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c41 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 41 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 41 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c42 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 42 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 42 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c43 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 43 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 43 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c44 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 44 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 44 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c45 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 45 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 45 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c46 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 46 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 46 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c47 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 47 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 47 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c48 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 48 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 48 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c49 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 49 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 49 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c50 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 50 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 50 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c51 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 51 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 51 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c52 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 52 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 52 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;
      if v_tmp.val_c53 &gt; 0 then
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 53 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
        select to_number(to_char(trunc(To_date(to_char(aAnImport)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 53 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
        if scadAn = aAnImport and sWeek = 1 then
          sAn := &apos;N&apos;;
          sSaptamana := sWeek;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
        if scadAn &lt;= aAnF then
          if scadAn = aAnImport then
            sAn := &apos;C&apos;;
            sSaptamana := sWeek;
          else
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
          end if;
          sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
          execute immediate sSQL;
        else
          if scadAn = aAnF + 1 and sWeek &lt;= 15 then
            sAn := &apos;T&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_c53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_c53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          end if;
        end if;
        end if;
      end if;

      if aAnImport &lt; aAnF then
        if v_tmp.val_n1 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 1 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 1 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if aScadenta &gt; 6 and scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n1||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n2 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 2 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 2 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n2||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n3 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 3 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 3 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n3||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n4 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 4 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 4 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n4||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n5 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 5 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 5 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n5||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n6 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 6 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 6 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n6||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n7 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 7 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 7 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n7||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n8 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 8 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 8 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n8||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n9 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 9 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 9 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n9||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n10 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 10 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 10 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n10||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n11 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 11 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 11 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n11||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n12 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 12 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 12 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n12||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n13 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 13 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 13 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n13||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n14 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 14 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 14 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n14||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n15 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 15 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 15 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n15||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n16 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 16 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 16 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n16||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n17 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 17 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 17 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n17||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n18 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 18 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 18 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n18||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n19 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 19 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 19 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n19||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n20 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 20 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 20 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n20||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n21 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 21 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 21 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n21||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n22 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 22 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 22 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n22||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n23 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 23 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 23 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n23||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n24 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 24 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 24 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n24||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n25 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 25 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 25 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n25||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n26 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 26 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 26 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n26||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n27 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 27 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 27 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n27||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n28 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 28 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 28 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n28||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n29 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 29 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 29 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n29||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n30 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 30 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 30 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n30||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n31 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 31 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 31 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n31||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n32 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 32 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 32 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n32||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n33 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 33 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 33 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n33||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n34 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 34 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 34 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n34||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n35 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 35 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 35 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n35||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n36 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 36 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 36 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n36||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n37 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 37 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 37 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n37||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n38 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 38 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 38 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n38||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n39 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 39 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 39 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n39||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n40 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 40 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 40 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n40||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n41 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 41 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 41 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n41||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n42 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 42 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 42 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n42||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n43 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 43 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 43 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n43||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n44 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 44 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 44 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n44||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n45 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 45 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 45 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n45||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n46 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 46 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 46 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n46||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n47 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 47 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 47 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n47||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n48 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 48 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 48 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n48||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n49 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 49 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 49 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n49||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n50 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 50 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 50 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n50||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n51 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 51 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 51 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n51||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n52 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 52 * 7 - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) + 52 * 7 - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n52||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
        if v_tmp.val_n53 &gt; 0 then
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) - 1 + aScadenta, &apos;IW&apos;)) into sWeek from dual;
          select to_number(to_char(trunc(To_date(to_char(aAnF)||&apos;0107&apos;,&apos;YYYYMMDD&apos;),&apos;IYYY&apos;) - 1 + aScadenta, &apos;iyyy&apos;)) into scadAn from dual;
          if scadAn = aAnF and sWeek = 1 then
            sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
          if scadAn = aAnF then
            sAn := &apos;N&apos;;
            sSaptamana := sWeek;
            sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
            execute immediate sSQL;
          else
            if scadAn = aAnF + 1 and sWeek &lt;= 15 then
              sAn := &apos;T&apos;;
              sSaptamana := sWeek;
              sSQL := &apos;update estimariprod1m set val_&apos;||sAn||sSaptamana||&apos; =  &apos;||v_tmp.val_n53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            else
              sSQL := &apos;update estimariprod1m set depasire = nvl(depasire,0) + &apos;||v_tmp.val_n53||&apos; where codestimareprod1m = &apos;||acodestimareprod1m;
              execute immediate sSQL;
            end if;
          end if;
          end if;
        end if;
      end if;
      end if;
    END LOOP;
end;

procedure ClearMatStruct(aCodEstimareProd in number) is
begin
  delete estimarinod where codestimareprod = aCodEstimareProd;
  delete estimariprod1m where codestimareprod = aCodEstimareProd;
  commit;
end;

procedure UpdateAchiz(aCodEstimareProd1m in number, sdata in varchar2, aCodOferta in number) is
adata date;
apret number(20,7);
ascadenta number(10);
aAnImport number(4);
aAnF number(4);
aSaptamana number(2);
aSaptamanaF number(2);
aSubunitatea number(20);
begin
  adata := to_date(sdata, &apos;dd.mm.yyyy&apos;);
  begin
    select nvl(p.scadentac,0), pkg_oferta.GetCodOferta1PretMinPart(o.codobiect, adata, acodoferta), e.animport, e.anf, e.saptamana, e.saptamanaf, e.subunitatea
    into ascadenta, apret, aAnImport, aAnF, aSaptamana, aSaptamanaF, aSubunitatea
    from estimariprod1m m
         inner join estimariprod e on e.codestimareprod = m.codestimareprod
         inner join nartobj o on m.codobiect = o.codobiect
         left join npart p on p.codpart = o.codproducator
    where m.codestimareprod1m = acodestimareprod1m;
    update estimariprod1m set pret = apret, scadenta = ascadenta where codestimareprod1m = acodestimareprod1m;
  exception when others then
    null;
  end;
  commit;
  update estimariprod1m
  set
    (val_C1 , val_C2,  val_C3, val_C4,  val_C5,  val_C6,  val_C7,  val_C8,  val_C9,
     val_C10, val_C11, val_C12, val_C13, val_C14, val_C15, val_C16, val_C17, val_C18, val_C19,
     val_C20, val_C21, val_C22, val_C23, val_C24, val_C25, val_C26, val_C27, val_C28, val_C29,
     val_C30, val_C31, val_C32, val_C33, val_C34, val_C35, val_C36, val_C37, val_C38, val_C39,
     val_C40, val_C41, val_C42, val_C43, val_C44, val_C45, val_C46, val_C47, val_C48, val_C49,
     val_C50, val_C51, val_C52,
     val_N1 ,  val_N2, val_N3 , val_N4,  val_N5, val_N6,   val_N7,  val_N8,  val_N9,
     val_N10, val_N11, val_N12, val_N13, val_N14, val_N15, val_N16, val_N17, val_N18, val_N19,
     val_N20, val_N21, val_N22, val_N23, val_N24, val_N25, val_N26, val_N27, val_N28, val_N29,
     val_N30, val_N31, val_N32, val_N33, val_N34, val_N35, val_N36, val_N37, val_N38, val_N39,
     val_N40, val_N41, val_N42, val_N43, val_N44, val_N45, val_N46, val_N47, val_N48, val_N49,
     val_N50, val_N51, val_N52, val_C53, val_N53)
   =
   (select 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0
  from dual)
  where codestimareprod1m = acodestimareprod1m;

  AduCmdF(aSaptamana, aSaptamanaF, aAnImport, aAnF, aCodEstimareProd1m, aSubunitatea);
  CalculeazaNecesar(aCodEstimareProd1m, aSaptamana);
  CalculValori(aCodEstimareProd1m, aAnImport, aAnF);
  Commit;
end;

procedure UMPLEIOART1OFE(aAn in number, aLuna in number,aCodOferta in number) IS
BEGIN
  PRC_AL_CHECK(&apos;IOART1&apos;);

  delete oferta1_man;
  insert into oferta1_man(codobiect,pret)
  select o1.codobiect, o1.pret
  from oferta1 o1 inner join oferta o on o.codoferta = o1.codoferta
  where o.CodOferta = aCodOferta;
  commit;
END;

procedure CentralizeazaMat(aCodestimareProd1 in number, aAn in number, aLuna in number, aSubunitatea in number, sData in varchar2, aCodOferta in number, aCodEstimareProd in number) is
aData date;
sSQL varchar2(30000);
iter number(10);
begin
  aData := to_date(sData, &apos;DD.MM.YYYY&apos;);

  delete estimarinod_c2;
  insert into estimarinod_c2(codestimareprod, codobiect)
  select distinct e.codestimareprod, e.codobiect
  from estimarinod e
  where e.codestimareprod1 = aCodEstimareProd1 and e.codobiect &gt; 0
        and not exists (select ee.codestimarenod from estimarinod ee where ee.codestimareprod1 = aCodEstimareProd1 and e.codestimarenod = ee.nodoriginal);

  MERGE INTO ESTIMARIPROD1M M
  USING (
    SELECT
      OBJ.CODESTIMAREPROD, OBJ.CODOBIECT, objs.stocmed stocoptim, num.coef coefum, p.scadentac Scadenta,
      o1.pret, stoc.cant
    FROM estimarinod_c2 Obj
      inner join nartobj o on obj.codobiect = o.codobiect
      inner join nart art on art.codarticol = o.codarticol
      inner join num on num.codum = art.um
      left join npart p on p.codpart = o.codproducator
      left join nartobjsubunit objs on obj.codobiect = objs.codobiect
                                    and ( objs.codgest is null or objs.codgest = 0)
                                    and objs.subunitate = aSubunitatea
      left join oferta1_man o1 on o1.codobiect = obj.codobiect
      left join (
        SELECT
          ns.codobiect,
          Sum(CASE WHEN NS.TIPSERIE &gt; 0 THEN  ROUND( NSE.REST, 10) ELSE ROUND( NS.REST, 10) END) cant
        FROM estimarinod_c2 Obj
          INNER JOIN NIRSTOC NS ON NS.CODOBIECT = obj.codobiect
          INNER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = NS.CODIOART AND aAn * 12 + aLuna BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
          LEFT  JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
        WHERE NS.REST &gt; 0
          AND IOALUNA.MG NOT IN (3,5)
        GROUP BY ns.codobiect
      ) stoc on stoc.codobiect = o.codobiect
    ) N ON (N.CODOBIECT = M.CODOBIECT and N.CODESTIMAREPROD = M.CODESTIMAREPROD)
    WHEN NOT MATCHED THEN
      INSERT (CodEstimareProd1M, CodEstimareProd, CODOBIECT, stocoptim, coefum, Scadenta, Pret, Stoc)
      VALUES (seq_estprod1m_codestprod1m.nextval, aCodEstimareProd, N.CODOBIECT, N.stocoptim, N.coefum, N.Scadenta, N.Pret, N.Cant);

    sSQL := &apos;begin
               merge into estimariprod1m m
               USING (
                      SELECT
                        sum(nvl(n.nec_c1,0) / e0.necesar * e.necesar) necesar1,
                        sum(nvl(n.nec_c2,0) / e0.necesar * e.necesar) necesar2,
                        sum(nvl(n.nec_c3,0) / e0.necesar * e.necesar) necesar3,
                        sum(nvl(n.nec_c4,0) / e0.necesar * e.necesar) necesar4,
                        sum(nvl(n.nec_c5,0) / e0.necesar * e.necesar) necesar5,
                        sum(nvl(n.nec_c6,0) / e0.necesar * e.necesar) necesar6,
                        sum(nvl(n.nec_c7,0) / e0.necesar * e.necesar) necesar7,
                        sum(nvl(n.nec_c8,0) / e0.necesar * e.necesar) necesar8,
                        sum(nvl(n.nec_c9,0) / e0.necesar * e.necesar) necesar9,
                        sum(nvl(n.nec_c10,0) / e0.necesar * e.necesar) necesar10,
                        sum(nvl(n.nec_c11,0) / e0.necesar * e.necesar) necesar11,
                        sum(nvl(n.nec_c12,0) / e0.necesar * e.necesar) necesar12,
                        sum(nvl(n.nec_c13,0) / e0.necesar * e.necesar) necesar13,
                        sum(nvl(n.nec_c14,0) / e0.necesar * e.necesar) necesar14,
                        sum(nvl(n.nec_c15,0) / e0.necesar * e.necesar) necesar15,
                        sum(nvl(n.nec_c16,0) / e0.necesar * e.necesar) necesar16,
                        sum(nvl(n.nec_c17,0) / e0.necesar * e.necesar) necesar17,
                        sum(nvl(n.nec_c18,0) / e0.necesar * e.necesar) necesar18,
                        sum(nvl(n.nec_c19,0) / e0.necesar * e.necesar) necesar19,
                        sum(nvl(n.nec_c20,0) / e0.necesar * e.necesar) necesar20,
                        sum(nvl(n.nec_c21,0) / e0.necesar * e.necesar) necesar21,
                        sum(nvl(n.nec_c22,0) / e0.necesar * e.necesar) necesar22,
                        sum(nvl(n.nec_c23,0) / e0.necesar * e.necesar) necesar23,
                        sum(nvl(n.nec_c24,0) / e0.necesar * e.necesar) necesar24,
                        sum(nvl(n.nec_c25,0) / e0.necesar * e.necesar) necesar25,
                        sum(nvl(n.nec_c26,0) / e0.necesar * e.necesar) necesar26,
                        sum(nvl(n.nec_c27,0) / e0.necesar * e.necesar) necesar27,
                        sum(nvl(n.nec_c28,0) / e0.necesar * e.necesar) necesar28,
                        sum(nvl(n.nec_c29,0) / e0.necesar * e.necesar) necesar29,
                        sum(nvl(n.nec_c30,0) / e0.necesar * e.necesar) necesar30,
                        sum(nvl(n.nec_c31,0) / e0.necesar * e.necesar) necesar31,
                        sum(nvl(n.nec_c32,0) / e0.necesar * e.necesar) necesar32,
                        sum(nvl(n.nec_c33,0) / e0.necesar * e.necesar) necesar33,
                        sum(nvl(n.nec_c34,0) / e0.necesar * e.necesar) necesar34,
                        sum(nvl(n.nec_c35,0) / e0.necesar * e.necesar) necesar35,
                        sum(nvl(n.nec_c36,0) / e0.necesar * e.necesar) necesar36,
                        sum(nvl(n.nec_c37,0) / e0.necesar * e.necesar) necesar37,
                        sum(nvl(n.nec_c38,0) / e0.necesar * e.necesar) necesar38,
                        sum(nvl(n.nec_c39,0) / e0.necesar * e.necesar) necesar39,
                        sum(nvl(n.nec_c40,0) / e0.necesar * e.necesar) necesar40,
                        sum(nvl(n.nec_c41,0) / e0.necesar * e.necesar) necesar41,
                        sum(nvl(n.nec_c42,0) / e0.necesar * e.necesar) necesar42,
                        sum(nvl(n.nec_c43,0) / e0.necesar * e.necesar) necesar43,
                        sum(nvl(n.nec_c44,0) / e0.necesar * e.necesar) necesar44,
                        sum(nvl(n.nec_c45,0) / e0.necesar * e.necesar) necesar45,
                        sum(nvl(n.nec_c46,0) / e0.necesar * e.necesar) necesar46,
                        sum(nvl(n.nec_c47,0) / e0.necesar * e.necesar) necesar47,
                        sum(nvl(n.nec_c48,0) / e0.necesar * e.necesar) necesar48,
                        sum(nvl(n.nec_c49,0) / e0.necesar * e.necesar) necesar49,
                        sum(nvl(n.nec_c50,0) / e0.necesar * e.necesar) necesar50,
                        sum(nvl(n.nec_c51,0) / e0.necesar * e.necesar) necesar51,
                        sum(nvl(n.nec_c52,0) / e0.necesar * e.necesar) necesar52,
                        sum(nvl(n.nec_c53,0) / e0.necesar * e.necesar) necesar53,
                        e.codestimareprod, e.codobiect
                      FROM estimarinod e
                           inner join estimariprod1 e1 on e1.codestimareprod1 = e.codestimareprod1
                           inner join estimariprod1n n on n.codobiect = e1.codobiect and n.codestimareprod = e1.codestimareprod
                           inner join estimarinod e0 on e0.codestimareprod1 = e.codestimareprod1 and e0.nodoriginal = 0
                      where e.codestimareprod1 = &apos;||aCodEstimareProd1||&apos;
                      group by e.codestimareprod, e.codobiect
                      ) N
               ON (N.CODOBIECT = M.CODOBIECT and N.CODESTIMAREPROD = M.CODESTIMAREPROD)
               WHEN MATCHED THEN UPDATE
               SET
                 C1 = nvl(C1,0) + N.NECESAR1,
                 C2 = nvl(C2,0) + N.NECESAR2,
                 C3 = nvl(C3,0) + N.NECESAR3,
                 C4 = nvl(C4,0) + N.NECESAR4,
                 C5 = nvl(C5,0) + N.NECESAR5,
                 C6 = nvl(C6,0) + N.NECESAR6,
                 C7 = nvl(C7,0) + N.NECESAR7,
                 C8 = nvl(C8,0) + N.NECESAR8,
                 C9 = nvl(C9,0) + N.NECESAR9,
                 C10 = nvl(C10,0) + N.NECESAR10,
                 C11 = nvl(C11,0) + N.NECESAR11,
                 C12 = nvl(C12,0) + N.NECESAR12,
                 C13 = nvl(C13,0) + N.NECESAR13,
                 C14 = nvl(C14,0) + N.NECESAR14,
                 C15 = nvl(C15,0) + N.NECESAR15,
                 C16 = nvl(C16,0) + N.NECESAR16,
                 C17 = nvl(C17,0) + N.NECESAR17,
                 C18 = nvl(C18,0) + N.NECESAR18,
                 C19 = nvl(C19,0) + N.NECESAR19,
                 C20 = nvl(C20,0) + N.NECESAR20,
                 C21 = nvl(C21,0) + N.NECESAR21,
                 C22 = nvl(C22,0) + N.NECESAR22,
                 C23 = nvl(C23,0) + N.NECESAR23,
                 C24 = nvl(C24,0) + N.NECESAR24,
                 C25 = nvl(C25,0) + N.NECESAR25,
                 C26 = nvl(C26,0) + N.NECESAR26,
                 C27 = nvl(C27,0) + N.NECESAR27,
                 C28 = nvl(C28,0) + N.NECESAR28,
                 C29 = nvl(C29,0) + N.NECESAR29,
                 C30 = nvl(C30,0) + N.NECESAR30,
                 C31 = nvl(C31,0) + N.NECESAR31,
                 C32 = nvl(C32,0) + N.NECESAR32,
                 C33 = nvl(C33,0) + N.NECESAR33,
                 C34 = nvl(C34,0) + N.NECESAR34,
                 C35 = nvl(C35,0) + N.NECESAR35,
                 C36 = nvl(C36,0) + N.NECESAR36,
                 C37 = nvl(C37,0) + N.NECESAR37,
                 C38 = nvl(C38,0) + N.NECESAR38,
                 C39 = nvl(C39,0) + N.NECESAR39,
                 C40 = nvl(C40,0) + N.NECESAR40,
                 C41 = nvl(C41,0) + N.NECESAR41,
                 C42 = nvl(C42,0) + N.NECESAR42,
                 C43 = nvl(C43,0) + N.NECESAR43,
                 C44 = nvl(C44,0) + N.NECESAR44,
                 C45 = nvl(C45,0) + N.NECESAR45,
                 C46 = nvl(C46,0) + N.NECESAR46,
                 C47 = nvl(C47,0) + N.NECESAR47,
                 C48 = nvl(C48,0) + N.NECESAR48,
                 C49 = nvl(C49,0) + N.NECESAR49,
                 C50 = nvl(C50,0) + N.NECESAR50,
                 C51 = nvl(C51,0) + N.NECESAR51,
                 C52 = nvl(C52,0) + N.NECESAR52,
                 C53 = nvl(C53,0) + N.NECESAR53;
             end;&apos;;
    execute immediate sSQL;
    sSQL := &apos;begin
               merge into estimariprod1m m
               USING (
                      SELECT
                        sum(nvl(n.nec_n1,0) / e0.necesar * e.necesar) necesar1,
                        sum(nvl(n.nec_n2,0) / e0.necesar * e.necesar) necesar2,
                        sum(nvl(n.nec_n3,0) / e0.necesar * e.necesar) necesar3,
                        sum(nvl(n.nec_n4,0) / e0.necesar * e.necesar) necesar4,
                        sum(nvl(n.nec_n5,0) / e0.necesar * e.necesar) necesar5,
                        sum(nvl(n.nec_n6,0) / e0.necesar * e.necesar) necesar6,
                        sum(nvl(n.nec_n7,0) / e0.necesar * e.necesar) necesar7,
                        sum(nvl(n.nec_n8,0) / e0.necesar * e.necesar) necesar8,
                        sum(nvl(n.nec_n9,0) / e0.necesar * e.necesar) necesar9,
                        sum(nvl(n.nec_n10,0) / e0.necesar * e.necesar) necesar10,
                        sum(nvl(n.nec_n11,0) / e0.necesar * e.necesar) necesar11,
                        sum(nvl(n.nec_n12,0) / e0.necesar * e.necesar) necesar12,
                        sum(nvl(n.nec_n13,0) / e0.necesar * e.necesar) necesar13,
                        sum(nvl(n.nec_n14,0) / e0.necesar * e.necesar) necesar14,
                        sum(nvl(n.nec_n15,0) / e0.necesar * e.necesar) necesar15,
                        sum(nvl(n.nec_n16,0) / e0.necesar * e.necesar) necesar16,
                        sum(nvl(n.nec_n17,0) / e0.necesar * e.necesar) necesar17,
                        sum(nvl(n.nec_n18,0) / e0.necesar * e.necesar) necesar18,
                        sum(nvl(n.nec_n19,0) / e0.necesar * e.necesar) necesar19,
                        sum(nvl(n.nec_n20,0) / e0.necesar * e.necesar) necesar20,
                        sum(nvl(n.nec_n21,0) / e0.necesar * e.necesar) necesar21,
                        sum(nvl(n.nec_n22,0) / e0.necesar * e.necesar) necesar22,
                        sum(nvl(n.nec_n23,0) / e0.necesar * e.necesar) necesar23,
                        sum(nvl(n.nec_n24,0) / e0.necesar * e.necesar) necesar24,
                        sum(nvl(n.nec_n25,0) / e0.necesar * e.necesar) necesar25,
                        sum(nvl(n.nec_n26,0) / e0.necesar * e.necesar) necesar26,
                        sum(nvl(n.nec_n27,0) / e0.necesar * e.necesar) necesar27,
                        sum(nvl(n.nec_n28,0) / e0.necesar * e.necesar) necesar28,
                        sum(nvl(n.nec_n29,0) / e0.necesar * e.necesar) necesar29,
                        sum(nvl(n.nec_n30,0) / e0.necesar * e.necesar) necesar30,
                        sum(nvl(n.nec_n31,0) / e0.necesar * e.necesar) necesar31,
                        sum(nvl(n.nec_n32,0) / e0.necesar * e.necesar) necesar32,
                        sum(nvl(n.nec_n33,0) / e0.necesar * e.necesar) necesar33,
                        sum(nvl(n.nec_n34,0) / e0.necesar * e.necesar) necesar34,
                        sum(nvl(n.nec_n35,0) / e0.necesar * e.necesar) necesar35,
                        sum(nvl(n.nec_n36,0) / e0.necesar * e.necesar) necesar36,
                        sum(nvl(n.nec_n37,0) / e0.necesar * e.necesar) necesar37,
                        sum(nvl(n.nec_n38,0) / e0.necesar * e.necesar) necesar38,
                        sum(nvl(n.nec_n39,0) / e0.necesar * e.necesar) necesar39,
                        sum(nvl(n.nec_n40,0) / e0.necesar * e.necesar) necesar40,
                        sum(nvl(n.nec_n41,0) / e0.necesar * e.necesar) necesar41,
                        sum(nvl(n.nec_n42,0) / e0.necesar * e.necesar) necesar42,
                        sum(nvl(n.nec_n43,0) / e0.necesar * e.necesar) necesar43,
                        sum(nvl(n.nec_n44,0) / e0.necesar * e.necesar) necesar44,
                        sum(nvl(n.nec_n45,0) / e0.necesar * e.necesar) necesar45,
                        sum(nvl(n.nec_n46,0) / e0.necesar * e.necesar) necesar46,
                        sum(nvl(n.nec_n47,0) / e0.necesar * e.necesar) necesar47,
                        sum(nvl(n.nec_n48,0) / e0.necesar * e.necesar) necesar48,
                        sum(nvl(n.nec_n49,0) / e0.necesar * e.necesar) necesar49,
                        sum(nvl(n.nec_n50,0) / e0.necesar * e.necesar) necesar50,
                        sum(nvl(n.nec_n51,0) / e0.necesar * e.necesar) necesar51,
                        sum(nvl(n.nec_n52,0) / e0.necesar * e.necesar) necesar52,
                        sum(nvl(n.nec_n53,0) / e0.necesar * e.necesar) necesar53,
                        e.codestimareprod, e.codobiect
                      FROM estimarinod e
                           inner join estimariprod1 e1 on e1.codestimareprod1 = e.codestimareprod1
                           inner join estimariprod1n n on n.codobiect = e1.codobiect and n.codestimareprod = e1.codestimareprod
                           inner join estimarinod e0 on e0.codestimareprod1 = e1.codestimareprod1 and e0.nodoriginal = 0
                      where e.codestimareprod1 = &apos;||aCodEstimareProd1||&apos;
                      group by e.codestimareprod, e.codobiect
                      ) N
               ON (N.CODOBIECT = M.CODOBIECT and N.CODESTIMAREPROD = M.CODESTIMAREPROD)
               WHEN MATCHED THEN UPDATE
               SET
                 n1  = nvl(n1,0) + N.NECESAR1,
                 n2  = nvl(n2,0) + N.NECESAR2,
                 n3  = nvl(n3,0) + N.NECESAR3,
                 n4  = nvl(n4,0) + N.NECESAR4,
                 n5  = nvl(n5,0) + N.NECESAR5,
                 n6  = nvl(n6,0) + N.NECESAR6,
                 n7  = nvl(n7,0) + N.NECESAR7,
                 n8  = nvl(n8,0) + N.NECESAR8,
                 n9  = nvl(n9,0) + N.NECESAR9,
                 n10 = nvl(n10,0) + N.NECESAR10,
                 n11 = nvl(n11,0) + N.NECESAR11,
                 n12 = nvl(n12,0) + N.NECESAR12,
                 n13 = nvl(n13,0) + N.NECESAR13,
                 n14 = nvl(n14,0) + N.NECESAR14,
                 n15 = nvl(n15,0) + N.NECESAR15,
                 n16 = nvl(n16,0) + N.NECESAR16,
                 n17 = nvl(n17,0) + N.NECESAR17,
                 n18 = nvl(n18,0) + N.NECESAR18,
                 n19 = nvl(n19,0) + N.NECESAR19,
                 n20 = nvl(n20,0) + N.NECESAR20,
                 n21 = nvl(n21,0) + N.NECESAR21,
                 n22 = nvl(n22,0) + N.NECESAR22,
                 n23 = nvl(n23,0) + N.NECESAR23,
                 n24 = nvl(n24,0) + N.NECESAR24,
                 n25 = nvl(n25,0) + N.NECESAR25,
                 n26 = nvl(n26,0) + N.NECESAR26,
                 n27 = nvl(n27,0) + N.NECESAR27,
                 n28 = nvl(n28,0) + N.NECESAR28,
                 n29 = nvl(n29,0) + N.NECESAR29,
                 n30 = nvl(n30,0) + N.NECESAR30,
                 n31 = nvl(n31,0) + N.NECESAR31,
                 n32 = nvl(n32,0) + N.NECESAR32,
                 n33 = nvl(n33,0) + N.NECESAR33,
                 n34 = nvl(n34,0) + N.NECESAR34,
                 n35 = nvl(n35,0) + N.NECESAR35,
                 n36 = nvl(n36,0) + N.NECESAR36,
                 n37 = nvl(n37,0) + N.NECESAR37,
                 n38 = nvl(n38,0) + N.NECESAR38,
                 n39 = nvl(n39,0) + N.NECESAR39,
                 n40 = nvl(n40,0) + N.NECESAR40,
                 n41 = nvl(n41,0) + N.NECESAR41,
                 n42 = nvl(n42,0) + N.NECESAR42,
                 n43 = nvl(n43,0) + N.NECESAR43,
                 n44 = nvl(n44,0) + N.NECESAR44,
                 n45 = nvl(n45,0) + N.NECESAR45,
                 n46 = nvl(n46,0) + N.NECESAR46,
                 n47 = nvl(n47,0) + N.NECESAR47,
                 n48 = nvl(n48,0) + N.NECESAR48,
                 n49 = nvl(n49,0) + N.NECESAR49,
                 n50 = nvl(n50,0) + N.NECESAR50,
                 n51 = nvl(n51,0) + N.NECESAR51,
                 n52 = nvl(n52,0) + N.NECESAR52,
                 n53 = nvl(n53,0) + N.NECESAR53;
             end;&apos;;
    execute immediate sSQL;
  commit;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CODESTIMAREPROD1 INTO Tmp FROM ESTIMARIPROD1 WHERE CODESTIMAREPROD1 = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodSubunit NUMBER(20);
aDataDoc DATE;
aDoc varchar2(200);
vRecId number(20);
BEGIN
  SP_LOCKRECORD(RecId);
  select codestimareprod into vRecId
  from estimariprod1 where codestimareprod1 = RecId;

  SELECT
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;DATADOC
  INTO
    ACARNETDOC,
    ANRDOC,
    aCodSubunit,
    aDataDoc,
    ADOC
  FROM
    ESTIMARIPROD
  WHERE
    CODESTIMAREPROD = vRECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;ESTIMARIPROD&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM ESTIMARINOD WHERE CODESTIMAREPROD = vRECID;
  DELETE FROM ESTIMARIPROD1 WHERE CODESTIMAREPROD = vRecId;
  DELETE FROM ESTIMARIPROD1N WHERE CODESTIMAREPROD = vRecId;
  DELETE FROM ESTIMARIPROD1M WHERE CODESTIMAREPROD = vRecId;
  DELETE FROM ESTIMARIPROD WHERE CODESTIMAREPROD = vRecId;

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_ESTIMARIPROD FIELDS(CODESTIMAREPROD) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
aCodEstimareProd number(20);
aRecId number(20);
aSubunitatea number(20);
aAn number(4);
aLuna number(2);
BEGIN
  if vCodEstimareProd1 &gt; 0 then
    aRecId := vCodEstimareProd1;
    select codestimareprod into aCodEstimareProd
    from estimariprod1 where codestimareprod1 = aRecId;
  else
    aRecId := RecId;
    select codestimareprod into aCodEstimareProd
    from estimariprod1 where codestimareprod1 = aRecId;
  end if;

  select subunitatea, an, luna into aSubunitatea, aAn, aLuna from estimariprod where codestimareprod = aCodEstimareProd;

  delete TMP_ESTIMARIPROD;
  INSERT INTO TMP_ESTIMARIPROD(CODESTIMAREPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS,
                               ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
                               SERIADOC, PREFIXDOC, DATASTART, DATASTOP, ANIMPORT, SAPTAMANAF, ANF,CODOFERTA)
  SELECT CODESTIMAREPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS,
         ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
         SERIADOC, PREFIXDOC,
         iso_week_to_date(animport, saptamana),
         iso_week_to_date(animport, saptamana) + 6,
         ANIMPORT, SAPTAMANAF, ANF,CODOFERTA
  FROM ESTIMARIPROD
  WHERE CODESTIMAREPROD = aCodEstimareProd;

  INSERT INTO TMP_ESTIMARIPROD1 (
    CodEstimareProd1, CodEstimareProd, CODOBIECT,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
    C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
    C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
    C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
    C50, C51, C52,
    N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
    N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
    N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
    N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
    N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
    N50, N51, N52, C53, N53,
    val_C1 ,  val_C2,  val_C3, val_C4,  val_C5,  val_C6,  val_C7,  val_C8,  val_C9,
    val_C10, val_C11, val_C12, val_C13, val_C14, val_C15, val_C16, val_C17, val_C18, val_C19,
    val_C20, val_C21, val_C22, val_C23, val_C24, val_C25, val_C26, val_C27, val_C28, val_C29,
    val_C30, val_C31, val_C32, val_C33, val_C34, val_C35, val_C36, val_C37, val_C38, val_C39,
    val_C40, val_C41, val_C42, val_C43, val_C44, val_C45, val_C46, val_C47, val_C48, val_C49,
    val_C50, val_C51, val_C52,
    val_N1 ,  val_N2, val_N3 , val_N4,  val_N5, val_N6,   val_N7,  val_N8,  val_N9,
    val_N10, val_N11, val_N12, val_N13, val_N14, val_N15, val_N16, val_N17, val_N18, val_N19,
    val_N20, val_N21, val_N22, val_N23, val_N24, val_N25, val_N26, val_N27, val_N28, val_N29,
    val_N30, val_N31, val_N32, val_N33, val_N34, val_N35, val_N36, val_N37, val_N38, val_N39,
    val_N40, val_N41, val_N42, val_N43, val_N44, val_N45, val_N46, val_N47, val_N48, val_N49,
    val_N50, val_N51, val_N52, val_C53, val_N53,
    DEPASIRE,
    val_T1 ,  val_T2, val_T3 , val_T4,  val_T5, val_T6,   val_T7,  val_T8,  val_T9,
    val_T10, val_T11, val_T12, val_T13, val_T14, val_T15,
    Pret, Scadenta,
    DENUMIRE, CODEXTERN, CODINTERN, DENUM, DEN_CLASEAS,
    NEC_C1, NEC_C2, NEC_C3, NEC_C4, NEC_C5, NEC_C6, NEC_C7, NEC_C8, NEC_C9,
    NEC_C10, NEC_C11, NEC_C12, NEC_C13, NEC_C14, NEC_C15, NEC_C16, NEC_C17, NEC_C18, NEC_C19,
    NEC_C20, NEC_C21, NEC_C22, NEC_C23, NEC_C24, NEC_C25, NEC_C26, NEC_C27, NEC_C28, NEC_C29,
    NEC_C30, NEC_C31, NEC_C32, NEC_C33, NEC_C34, NEC_C35, NEC_C36, NEC_C37, NEC_C38, NEC_C39,
    NEC_C40, NEC_C41, NEC_C42, NEC_C43, NEC_C44, NEC_C45, NEC_C46, NEC_C47, NEC_C48, NEC_C49,
    NEC_C50, NEC_C51, NEC_C52,
    NEC_N1,  NEC_N2,  NEC_N3,  NEC_N4,  NEC_N5,  NEC_N6,  NEC_N7,  NEC_N8,  NEC_N9,
    NEC_N10, NEC_N11, NEC_N12, NEC_N13, NEC_N14, NEC_N15, NEC_N16, NEC_N17, NEC_N18, NEC_N19,
    NEC_N20, NEC_N21, NEC_N22, NEC_N23, NEC_N24, NEC_N25, NEC_N26, NEC_N27, NEC_N28, NEC_N29,
    NEC_N30, NEC_N31, NEC_N32, NEC_N33, NEC_N34, NEC_N35, NEC_N36, NEC_N37, NEC_N38, NEC_N39,
    NEC_N40, NEC_N41, NEC_N42, NEC_N43, NEC_N44, NEC_N45, NEC_N46, NEC_N47, NEC_N48, NEC_N49,
    NEC_N50, NEC_N51, NEC_N52, NEC_C53, NEC_N53,
    STOC, STOCOPTIM, COEFUM)
  SELECT
    E1.CodEstimareProd1, E1.CodEstimareProd, E1.CODOBIECT,
    E1.C1, E1.C2, E1.C3, E1.C4, E1.C5, E1.C6, E1.C7, E1.C8, E1.C9,
    E1.C10, E1.C11, E1.C12, E1.C13, E1.C14, E1.C15, E1.C16, E1.C17, E1.C18, E1.C19,
    E1.C20, E1.C21, E1.C22, E1.C23, E1.C24, E1.C25, E1.C26, E1.C27, E1.C28, E1.C29,
    E1.C30, E1.C31, E1.C32, E1.C33, E1.C34, E1.C35, E1.C36, E1.C37, E1.C38, E1.C39,
    E1.C40, E1.C41, E1.C42, E1.C43, E1.C44, E1.C45, E1.C46, E1.C47, E1.C48, E1.C49,
    E1.C50, E1.C51, E1.C52,
    E1.N1, E1.N2, E1.N3, E1.N4, E1.N5, E1.N6, E1.N7, E1.N8, E1.N9,
    E1.N10, E1.N11, E1.N12, E1.N13, E1.N14, E1.N15, E1.N16, E1.N17, E1.N18, E1.N19,
    E1.N20, E1.N21, E1.N22, E1.N23, E1.N24, E1.N25, E1.N26, E1.N27, E1.N28, E1.N29,
    E1.N30, E1.N31, E1.N32, E1.N33, E1.N34, E1.N35, E1.N36, E1.N37, E1.N38, E1.N39,
    E1.N40, E1.N41, E1.N42, E1.N43, E1.N44, E1.N45, E1.N46, E1.N47, E1.N48, E1.N49,
    E1.N50, E1.N51, E1.N52, E1.C53, E1.N53,
    E1.val_C1 , E1.val_C2,  E1.val_C3,  E1.val_C4,  E1.val_C5,  E1.val_C6,  E1.val_C7,  E1.val_C8,  E1.val_C9,
    E1.val_C10, E1.val_C11, E1.val_C12, E1.val_C13, E1.val_C14, E1.val_C15, E1.val_C16, E1.val_C17, E1.val_C18, E1.val_C19,
    E1.val_C20, E1.val_C21, E1.val_C22, E1.val_C23, E1.val_C24, E1.val_C25, E1.val_C26, E1.val_C27, E1.val_C28, E1.val_C29,
    E1.val_C30, E1.val_C31, E1.val_C32, E1.val_C33, E1.val_C34, E1.val_C35, E1.val_C36, E1.val_C37, E1.val_C38, E1.val_C39,
    E1.val_C40, E1.val_C41, E1.val_C42, E1.val_C43, E1.val_C44, E1.val_C45, E1.val_C46, E1.val_C47, E1.val_C48, E1.val_C49,
    E1.val_C50, E1.val_C51, E1.val_C52,
    E1.val_N1 , E1.val_N2,  E1.val_N3,  E1.val_N4,  E1.val_N5,  E1.val_N6,  E1. val_N7, E1. val_N8, E1.val_N9,
    E1.val_N10, E1.val_N11, E1.val_N12, E1.val_N13, E1.val_N14, E1.val_N15, E1.val_N16, E1.val_N17, E1.val_N18, E1.val_N19,
    E1.val_N20, E1.val_N21, E1.val_N22, E1.val_N23, E1.val_N24, E1.val_N25, E1.val_N26, E1.val_N27, E1.val_N28, E1.val_N29,
    E1.val_N30, E1.val_N31, E1.val_N32, E1.val_N33, E1.val_N34, E1.val_N35, E1.val_N36, E1.val_N37, E1.val_N38, E1.val_N39,
    E1.val_N40, E1.val_N41, E1.val_N42, E1.val_N43, E1.val_N44, E1.val_N45, E1.val_N46, E1.val_N47, E1.val_N48, E1.val_N49,
    E1.val_N50, E1.val_N51, E1.val_N52, E1.val_C53, E1.val_N53,
    E1.DEPASIRE,
    E1.val_T1 , E1.val_T2,  E1.val_T3,  E1.val_T4,  E1.val_T5,  E1.val_T6,  E1. val_T7, E1. val_T8, E1.val_T9,
    E1.val_T10, E1.val_T11, E1.val_T12, E1.val_T13, E1.val_T14, E1.val_T15,
    E1.Pret, E1.Scadenta,
    OBJ.DENUMIRE, OBJ.CODEXTERN, OBJ.CODINTERN, UM.DEN_UM, CLS.DEN_CLASEAS,
    E1N.NEC_C1, E1N.NEC_C2, E1N.NEC_C3, E1N.NEC_C4, E1N.NEC_C5, E1N.NEC_C6, E1N.NEC_C7, E1N.NEC_C8, E1N.NEC_C9,
    E1N.NEC_C10, E1N.NEC_C11, E1N.NEC_C12, E1N.NEC_C13, E1N.NEC_C14, E1N.NEC_C15, E1N.NEC_C16, E1N.NEC_C17, E1N.NEC_C18, E1N.NEC_C19,
    E1N.NEC_C20, E1N.NEC_C21, E1N.NEC_C22, E1N.NEC_C23, E1N.NEC_C24, E1N.NEC_C25, E1N.NEC_C26, E1N.NEC_C27, E1N.NEC_C28, E1N.NEC_C29,
    E1N.NEC_C30, E1N.NEC_C31, E1N.NEC_C32, E1N.NEC_C33, E1N.NEC_C34, E1N.NEC_C35, E1N.NEC_C36, E1N.NEC_C37, E1N.NEC_C38, E1N.NEC_C39,
    E1N.NEC_C40, E1N.NEC_C41, E1N.NEC_C42, E1N.NEC_C43, E1N.NEC_C44, E1N.NEC_C45, E1N.NEC_C46, E1N.NEC_C47, E1N.NEC_C48, E1N.NEC_C49,
    E1N.NEC_C50, E1N.NEC_C51, E1N.NEC_C52,
    E1N.NEC_N1,  E1N.NEC_N2,  E1N.NEC_N3,  E1N.NEC_N4,  E1N.NEC_N5,  E1N.NEC_N6,  E1N.NEC_N7,  E1N.NEC_N8,  E1N.NEC_N9,
    E1N.NEC_N10, E1N.NEC_N11, E1N.NEC_N12, E1N.NEC_N13, E1N.NEC_N14, E1N.NEC_N15, E1N.NEC_N16, E1N.NEC_N17, E1N.NEC_N18, E1N.NEC_N19,
    E1N.NEC_N20, E1N.NEC_N21, E1N.NEC_N22, E1N.NEC_N23, E1N.NEC_N24, E1N.NEC_N25, E1N.NEC_N26, E1N.NEC_N27, E1N.NEC_N28, E1N.NEC_N29,
    E1N.NEC_N30, E1N.NEC_N31, E1N.NEC_N32, E1N.NEC_N33, E1N.NEC_N34, E1N.NEC_N35, E1N.NEC_N36, E1N.NEC_N37, E1N.NEC_N38, E1N.NEC_N39,
    E1N.NEC_N40, E1N.NEC_N41, E1N.NEC_N42, E1N.NEC_N43, E1N.NEC_N44, E1N.NEC_N45, E1N.NEC_N46, E1N.NEC_N47, E1N.NEC_N48, E1N.NEC_N49,
    E1N.NEC_N50, E1N.NEC_N51, E1N.NEC_N52, E1N.NEC_C53, E1N.NEC_N53,
    E1N.STOC, E1N.STOCOPTIM, E1N.COEFUM
  FROM ESTIMARIPROD1 E1
       INNER JOIN ESTIMARIPROD1N E1N ON E1N.CODOBIECT = E1.CODOBIECT AND E1N.CODESTIMAREPROD = E1.CODESTIMAREPROD
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = E1.CODOBIECT
       INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
       INNER JOIN NUM UM ON UM.CODUM = ART.UM
       LEFT JOIN NCLASEAS CLS ON CLS.CODCLASEAS = ART.CLASASTATIST
  WHERE E1.CODESTIMAREPROD1 = aRecId;

  insert into tmp_estimariprod1vt (
    CodEstimareProd,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
    C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
    C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
    C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
    C50, C51, C52,
    DEPASIRE,
    N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
    N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
    N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
    N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
    N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
    N50, N51, N52, C53, N53,
    T1,  T2,  T3,  T4,  T5,  T6,  T7,  T8,  T9,
    T10, T11, T12, T13, T14, T15
  )
  select
    CodEstimareProd,
    SUM(nvl(val_C1,0)),  SUM(nvl(val_C2 ,0)), SUM(nvl(val_C3 ,0)), SUM(nvl(val_C4 ,0)), SUM(nvl(val_C5 ,0)), SUM(nvl(val_C6 ,0)), SUM(nvl(val_C7 ,0)), SUM(nvl(val_C8 ,0)), SUM(nvl(val_C9 ,0)),
    SUM(nvl(val_C10,0)), SUM(nvl(val_C11,0)), SUM(nvl(val_C12,0)), SUM(nvl(val_C13,0)), SUM(nvl(val_C14,0)), SUM(nvl(val_C15,0)), SUM(nvl(val_C16,0)), SUM(nvl(val_C17,0)), SUM(nvl(val_C18,0)), SUM(nvl(val_C19,0)),
    SUM(nvl(val_C20,0)), SUM(nvl(val_C21,0)), SUM(nvl(val_C22,0)), SUM(nvl(val_C23,0)), SUM(nvl(val_C24,0)), SUM(nvl(val_C25,0)), SUM(nvl(val_C26,0)), SUM(nvl(val_C27,0)), SUM(nvl(val_C28,0)), SUM(nvl(val_C29,0)),
    SUM(nvl(val_C30,0)), SUM(nvl(val_C31,0)), SUM(nvl(val_C32,0)), SUM(nvl(val_C33,0)), SUM(nvl(val_C34,0)), SUM(nvl(val_C35,0)), SUM(nvl(val_C36,0)), SUM(nvl(val_C37,0)), SUM(nvl(val_C38,0)), SUM(nvl(val_C39,0)),
    SUM(nvl(val_C40,0)), SUM(nvl(val_C41,0)), SUM(nvl(val_C42,0)), SUM(nvl(val_C43,0)), SUM(nvl(val_C44,0)), SUM(nvl(val_C45,0)), SUM(nvl(val_C46,0)), SUM(nvl(val_C47,0)), SUM(nvl(val_C48,0)), SUM(nvl(val_C49,0)),
    SUM(nvl(val_C50,0)), SUM(nvl(val_C51,0)), SUM(nvl(val_C52,0)),
    SUM(nvl(DEPASIRE,0)),
    SUM(nvl(val_N1 ,0)), SUM(nvl(val_N2 ,0)), SUM(nvl(val_N3 ,0)), SUM(nvl(val_N4 ,0)), SUM(nvl(val_N5 ,0)), SUM(nvl(val_N6 ,0)), SUM(nvl(val_N7 ,0)), SUM(nvl(val_N8 ,0)), SUM(nvl(val_N9 ,0)),
    SUM(nvl(val_N10,0)), SUM(nvl(val_N11,0)), SUM(nvl(val_N12,0)), SUM(nvl(val_N13,0)), SUM(nvl(val_N14,0)), SUM(nvl(val_N15,0)), SUM(nvl(val_N16,0)), SUM(nvl(val_N17,0)), SUM(nvl(val_N18,0)), SUM(nvl(val_N19,0)),
    SUM(nvl(val_N20,0)), SUM(nvl(val_N21,0)), SUM(nvl(val_N22,0)), SUM(nvl(val_N23,0)), SUM(nvl(val_N24,0)), SUM(nvl(val_N25,0)), SUM(nvl(val_N26,0)), SUM(nvl(val_N27,0)), SUM(nvl(val_N28,0)), SUM(nvl(val_N29,0)),
    SUM(nvl(val_N30,0)), SUM(nvl(val_N31,0)), SUM(nvl(val_N32,0)), SUM(nvl(val_N33,0)), SUM(nvl(val_N34,0)), SUM(nvl(val_N35,0)), SUM(nvl(val_N36,0)), SUM(nvl(val_N37,0)), SUM(nvl(val_N38,0)), SUM(nvl(val_N39,0)),
    SUM(nvl(val_N40,0)), SUM(nvl(val_N41,0)), SUM(nvl(val_N42,0)), SUM(nvl(val_N43,0)), SUM(nvl(val_N44,0)), SUM(nvl(val_N45,0)), SUM(nvl(val_N46,0)), SUM(nvl(val_N47,0)), SUM(nvl(val_N48,0)), SUM(nvl(val_N49,0)),
    SUM(nvl(val_N50,0)), SUM(nvl(val_N51,0)), SUM(nvl(val_N52,0)), SUM(nvl(val_C53,0)), SUM(nvl(val_N53,0)),
    SUM(NVL(val_T1 ,0)), SUM(NVL(val_T2 ,0)), SUM(NVL(val_T3 ,0)), SUM(NVL(val_T4 ,0)), SUM(NVL(val_T5 ,0)), SUM(NVL(val_T6 ,0)), SUM(NVL(val_T7 ,0)), SUM(NVL(val_T8 ,0)), SUM(NVL(val_T9 ,0)),
    SUM(NVL(val_T10,0)), SUM(NVL(val_T11,0)), SUM(NVL(val_T12,0)), SUM(NVL(val_T13,0)), SUM(NVL(val_T14,0)), SUM(NVL(val_T15,0))
  from estimariprod1
  where codestimareprod = acodestimareprod
  group by codestimareprod;

  update tmp_estimariprod1vt set
  total = C1+ C2+ C3+ C4+ C5+ C6+ C7+ C8+ C9+
          C10+ C11+ C12+ C13+ C14+ C15+ C16+ C17+ C18+ C19+
          C20+ C21+ C22+ C23+ C24+ C25+ C26+ C27+ C28+ C29+
          C30+ C31+ C32+ C33+ C34+ C35+ C36+ C37+ C38+ C39+
          C40+ C41+ C42+ C43+ C44+ C45+ C46+ C47+ C48+ C49+
          C50+ C51+ C52+
          N1+  N2+  N3+  N4+  N5+  N6+  N7+  N8+  N9+
          N10+ N11+ N12+ N13+ N14+ N15+ N16+ N17+ N18+ N19+
          N20+ N21+ N22+ N23+ N24+ N25+ N26+ N27+ N28+ N29+
          N30+ N31+ N32+ N33+ N34+ N35+ N36+ N37+ N38+ N39+
          N40+ N41+ N42+ N43+ N44+ N45+ N46+ N47+ N48+ N49+
          N50+ N51+ N52+ C53+ N53 + DEPASIRE +
          T1+  T2+  T3+  T4+  T5+  T6+  T7+  T8+  T9+
          T10+ T11+ T12+ T13+ T14+ T15
          ;

  INSERT INTO TMP_ESTIMARIPROD1M (
    CodEstimareProd1M, CodEstimareProd, CODOBIECT,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
    C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
    C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
    C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
    C50, C51, C52,
    N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
    N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
    N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
    N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
    N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
    N50, N51, N52, C53, N53,
    NEC_C1, NEC_C2, NEC_C3, NEC_C4, NEC_C5, NEC_C6, NEC_C7, NEC_C8, NEC_C9,
    NEC_C10, NEC_C11, NEC_C12, NEC_C13, NEC_C14, NEC_C15, NEC_C16, NEC_C17, NEC_C18, NEC_C19,
    NEC_C20, NEC_C21, NEC_C22, NEC_C23, NEC_C24, NEC_C25, NEC_C26, NEC_C27, NEC_C28, NEC_C29,
    NEC_C30, NEC_C31, NEC_C32, NEC_C33, NEC_C34, NEC_C35, NEC_C36, NEC_C37, NEC_C38, NEC_C39,
    NEC_C40, NEC_C41, NEC_C42, NEC_C43, NEC_C44, NEC_C45, NEC_C46, NEC_C47, NEC_C48, NEC_C49,
    NEC_C50, NEC_C51, NEC_C52,
    NEC_N1,  NEC_N2,  NEC_N3,  NEC_N4,  NEC_N5,  NEC_N6,  NEC_N7,  NEC_N8,  NEC_N9,
    NEC_N10, NEC_N11, NEC_N12, NEC_N13, NEC_N14, NEC_N15, NEC_N16, NEC_N17, NEC_N18, NEC_N19,
    NEC_N20, NEC_N21, NEC_N22, NEC_N23, NEC_N24, NEC_N25, NEC_N26, NEC_N27, NEC_N28, NEC_N29,
    NEC_N30, NEC_N31, NEC_N32, NEC_N33, NEC_N34, NEC_N35, NEC_N36, NEC_N37, NEC_N38, NEC_N39,
    NEC_N40, NEC_N41, NEC_N42, NEC_N43, NEC_N44, NEC_N45, NEC_N46, NEC_N47, NEC_N48, NEC_N49,
    NEC_N50, NEC_N51, NEC_N52, NEC_C53, NEC_N53,
    CF_C1, CF_C2, CF_C3, CF_C4, CF_C5, CF_C6, CF_C7, CF_C8, CF_C9,
    CF_C10, CF_C11, CF_C12, CF_C13, CF_C14, CF_C15, CF_C16, CF_C17, CF_C18, CF_C19,
    CF_C20, CF_C21, CF_C22, CF_C23, CF_C24, CF_C25, CF_C26, CF_C27, CF_C28, CF_C29,
    CF_C30, CF_C31, CF_C32, CF_C33, CF_C34, CF_C35, CF_C36, CF_C37, CF_C38, CF_C39,
    CF_C40, CF_C41, CF_C42, CF_C43, CF_C44, CF_C45, CF_C46, CF_C47, CF_C48, CF_C49,
    CF_C50, CF_C51, CF_C52,
    CF_N1,  CF_N2,  CF_N3,  CF_N4,  CF_N5,  CF_N6,  CF_N7,  CF_N8,  CF_N9,
    CF_N10, CF_N11, CF_N12, CF_N13, CF_N14, CF_N15, CF_N16, CF_N17, CF_N18, CF_N19,
    CF_N20, CF_N21, CF_N22, CF_N23, CF_N24, CF_N25, CF_N26, CF_N27, CF_N28, CF_N29,
    CF_N30, CF_N31, CF_N32, CF_N33, CF_N34, CF_N35, CF_N36, CF_N37, CF_N38, CF_N39,
    CF_N40, CF_N41, CF_N42, CF_N43, CF_N44, CF_N45, CF_N46, CF_N47, CF_N48, CF_N49,
    CF_N50, CF_N51, CF_N52, CF_C53, CF_N53,
    val_C1 ,  val_C2,  val_C3, val_C4,  val_C5,  val_C6,  val_C7,  val_C8,  val_C9,
    val_C10, val_C11, val_C12, val_C13, val_C14, val_C15, val_C16, val_C17, val_C18, val_C19,
    val_C20, val_C21, val_C22, val_C23, val_C24, val_C25, val_C26, val_C27, val_C28, val_C29,
    val_C30, val_C31, val_C32, val_C33, val_C34, val_C35, val_C36, val_C37, val_C38, val_C39,
    val_C40, val_C41, val_C42, val_C43, val_C44, val_C45, val_C46, val_C47, val_C48, val_C49,
    val_C50, val_C51, val_C52,
    val_N1 ,  val_N2, val_N3 , val_N4,  val_N5, val_N6,   val_N7,  val_N8,  val_N9,
    val_N10, val_N11, val_N12, val_N13, val_N14, val_N15, val_N16, val_N17, val_N18, val_N19,
    val_N20, val_N21, val_N22, val_N23, val_N24, val_N25, val_N26, val_N27, val_N28, val_N29,
    val_N30, val_N31, val_N32, val_N33, val_N34, val_N35, val_N36, val_N37, val_N38, val_N39,
    val_N40, val_N41, val_N42, val_N43, val_N44, val_N45, val_N46, val_N47, val_N48, val_N49,
    val_N50, val_N51, val_N52, val_C53, val_N53,
    val_T1 ,  val_T2, val_T3 , val_T4,  val_T5, val_T6,   val_T7,  val_T8,  val_T9,
    val_T10, val_T11, val_T12, val_T13, val_T14, val_T15,
    DEPASIRE,
    PRET, SCADENTA,
    STOC, STOCOPTIM, DENUMIRE, DEN_UM, SIMBOL, DEN_PART, CODEXTERN, COEFUM)
  SELECT
    E1N.CodEstimareProd1M, E1N.CodEstimareProd, E1N.CODOBIECT,
    E1N.C1, E1N.C2, E1N.C3, E1N.C4, E1N.C5, E1N.C6, E1N.C7, E1N.C8, E1N.C9,
    E1N.C10, E1N.C11, E1N.C12, E1N.C13, E1N.C14, E1N.C15, E1N.C16, E1N.C17, E1N.C18, E1N.C19,
    E1N.C20, E1N.C21, E1N.C22, E1N.C23, E1N.C24, E1N.C25, E1N.C26, E1N.C27, E1N.C28, E1N.C29,
    E1N.C30, E1N.C31, E1N.C32, E1N.C33, E1N.C34, E1N.C35, E1N.C36, E1N.C37, E1N.C38, E1N.C39,
    E1N.C40, E1N.C41, E1N.C42, E1N.C43, E1N.C44, E1N.C45, E1N.C46, E1N.C47, E1N.C48, E1N.C49,
    E1N.C50, E1N.C51, E1N.C52,
    E1N.N1,  E1N.N2,  E1N.N3,  E1N.N4,  E1N.N5,  E1N.N6,  E1N.N7,  E1N.N8,  E1N.N9,
    E1N.N10, E1N.N11, E1N.N12, E1N.N13, E1N.N14, E1N.N15, E1N.N16, E1N.N17, E1N.N18, E1N.N19,
    E1N.N20, E1N.N21, E1N.N22, E1N.N23, E1N.N24, E1N.N25, E1N.N26, E1N.N27, E1N.N28, E1N.N29,
    E1N.N30, E1N.N31, E1N.N32, E1N.N33, E1N.N34, E1N.N35, E1N.N36, E1N.N37, E1N.N38, E1N.N39,
    E1N.N40, E1N.N41, E1N.N42, E1N.N43, E1N.N44, E1N.N45, E1N.N46, E1N.N47, E1N.N48, E1N.N49,
    E1N.N50, E1N.N51, E1N.N52, E1N.C53, E1N.N53,
    E1N.NEC_C1, E1N.NEC_C2, E1N.NEC_C3, E1N.NEC_C4, E1N.NEC_C5, E1N.NEC_C6, E1N.NEC_C7, E1N.NEC_C8, E1N.NEC_C9,
    E1N.NEC_C10, E1N.NEC_C11, E1N.NEC_C12, E1N.NEC_C13, E1N.NEC_C14, E1N.NEC_C15, E1N.NEC_C16, E1N.NEC_C17, E1N.NEC_C18, E1N.NEC_C19,
    E1N.NEC_C20, E1N.NEC_C21, E1N.NEC_C22, E1N.NEC_C23, E1N.NEC_C24, E1N.NEC_C25, E1N.NEC_C26, E1N.NEC_C27, E1N.NEC_C28, E1N.NEC_C29,
    E1N.NEC_C30, E1N.NEC_C31, E1N.NEC_C32, E1N.NEC_C33, E1N.NEC_C34, E1N.NEC_C35, E1N.NEC_C36, E1N.NEC_C37, E1N.NEC_C38, E1N.NEC_C39,
    E1N.NEC_C40, E1N.NEC_C41, E1N.NEC_C42, E1N.NEC_C43, E1N.NEC_C44, E1N.NEC_C45, E1N.NEC_C46, E1N.NEC_C47, E1N.NEC_C48, E1N.NEC_C49,
    E1N.NEC_C50, E1N.NEC_C51, E1N.NEC_C52,
    E1N.NEC_N1,  E1N.NEC_N2,  E1N.NEC_N3,  E1N.NEC_N4,  E1N.NEC_N5,  E1N.NEC_N6,  E1N.NEC_N7,  E1N.NEC_N8,  E1N.NEC_N9,
    E1N.NEC_N10, E1N.NEC_N11, E1N.NEC_N12, E1N.NEC_N13, E1N.NEC_N14, E1N.NEC_N15, E1N.NEC_N16, E1N.NEC_N17, E1N.NEC_N18, E1N.NEC_N19,
    E1N.NEC_N20, E1N.NEC_N21, E1N.NEC_N22, E1N.NEC_N23, E1N.NEC_N24, E1N.NEC_N25, E1N.NEC_N26, E1N.NEC_N27, E1N.NEC_N28, E1N.NEC_N29,
    E1N.NEC_N30, E1N.NEC_N31, E1N.NEC_N32, E1N.NEC_N33, E1N.NEC_N34, E1N.NEC_N35, E1N.NEC_N36, E1N.NEC_N37, E1N.NEC_N38, E1N.NEC_N39,
    E1N.NEC_N40, E1N.NEC_N41, E1N.NEC_N42, E1N.NEC_N43, E1N.NEC_N44, E1N.NEC_N45, E1N.NEC_N46, E1N.NEC_N47, E1N.NEC_N48, E1N.NEC_N49,
    E1N.NEC_N50, E1N.NEC_N51, E1N.NEC_N52, E1N.NEC_C53, E1N.NEC_N53,
    E1N.CF_C1, E1N.CF_C2, E1N.CF_C3, E1N.CF_C4, E1N.CF_C5, E1N.CF_C6, E1N.CF_C7, E1N.CF_C8, E1N.CF_C9,
    E1N.CF_C10, E1N.CF_C11, E1N.CF_C12, E1N.CF_C13, E1N.CF_C14, E1N.CF_C15, E1N.CF_C16, E1N.CF_C17, E1N.CF_C18, E1N.CF_C19,
    E1N.CF_C20, E1N.CF_C21, E1N.CF_C22, E1N.CF_C23, E1N.CF_C24, E1N.CF_C25, E1N.CF_C26, E1N.CF_C27, E1N.CF_C28, E1N.CF_C29,
    E1N.CF_C30, E1N.CF_C31, E1N.CF_C32, E1N.CF_C33, E1N.CF_C34, E1N.CF_C35, E1N.CF_C36, E1N.CF_C37, E1N.CF_C38, E1N.CF_C39,
    E1N.CF_C40, E1N.CF_C41, E1N.CF_C42, E1N.CF_C43, E1N.CF_C44, E1N.CF_C45, E1N.CF_C46, E1N.CF_C47, E1N.CF_C48, E1N.CF_C49,
    E1N.CF_C50, E1N.CF_C51, E1N.CF_C52,
    E1N.CF_N1,  E1N.CF_N2,  E1N.CF_N3,  E1N.CF_N4,  E1N.CF_N5,  E1N.CF_N6,  E1N.CF_N7,  E1N.CF_N8,  E1N.CF_N9,
    E1N.CF_N10, E1N.CF_N11, E1N.CF_N12, E1N.CF_N13, E1N.CF_N14, E1N.CF_N15, E1N.CF_N16, E1N.CF_N17, E1N.CF_N18, E1N.CF_N19,
    E1N.CF_N20, E1N.CF_N21, E1N.CF_N22, E1N.CF_N23, E1N.CF_N24, E1N.CF_N25, E1N.CF_N26, E1N.CF_N27, E1N.CF_N28, E1N.CF_N29,
    E1N.CF_N30, E1N.CF_N31, E1N.CF_N32, E1N.CF_N33, E1N.CF_N34, E1N.CF_N35, E1N.CF_N36, E1N.CF_N37, E1N.CF_N38, E1N.CF_N39,
    E1N.CF_N40, E1N.CF_N41, E1N.CF_N42, E1N.CF_N43, E1N.CF_N44, E1N.CF_N45, E1N.CF_N46, E1N.CF_N47, E1N.CF_N48, E1N.CF_N49,
    E1N.CF_N50, E1N.CF_N51, E1N.CF_N52, E1N.CF_C53, E1N.CF_N53,
    E1N.val_C1 , E1N.val_C2,  E1N.val_C3,  E1N.val_C4,  E1N.val_C5,  E1N.val_C6,  E1N.val_C7,  E1N.val_C8,  E1N.val_C9,
    E1N.val_C10, E1N.val_C11, E1N.val_C12, E1N.val_C13, E1N.val_C14, E1N.val_C15, E1N.val_C16, E1N.val_C17, E1N.val_C18, E1N.val_C19,
    E1N.val_C20, E1N.val_C21, E1N.val_C22, E1N.val_C23, E1N.val_C24, E1N.val_C25, E1N.val_C26, E1N.val_C27, E1N.val_C28, E1N.val_C29,
    E1N.val_C30, E1N.val_C31, E1N.val_C32, E1N.val_C33, E1N.val_C34, E1N.val_C35, E1N.val_C36, E1N.val_C37, E1N.val_C38, E1N.val_C39,
    E1N.val_C40, E1N.val_C41, E1N.val_C42, E1N.val_C43, E1N.val_C44, E1N.val_C45, E1N.val_C46, E1N.val_C47, E1N.val_C48, E1N.val_C49,
    E1N.val_C50, E1N.val_C51, E1N.val_C52,
    E1N.val_N1 , E1N.val_N2,  E1N.val_N3,  E1N.val_N4,  E1N.val_N5,  E1N.val_N6,  E1N. val_N7, E1N. val_N8, E1N.val_N9,
    E1N.val_N10, E1N.val_N11, E1N.val_N12, E1N.val_N13, E1N.val_N14, E1N.val_N15, E1N.val_N16, E1N.val_N17, E1N.val_N18, E1N.val_N19,
    E1N.val_N20, E1N.val_N21, E1N.val_N22, E1N.val_N23, E1N.val_N24, E1N.val_N25, E1N.val_N26, E1N.val_N27, E1N.val_N28, E1N.val_N29,
    E1N.val_N30, E1N.val_N31, E1N.val_N32, E1N.val_N33, E1N.val_N34, E1N.val_N35, E1N.val_N36, E1N.val_N37, E1N.val_N38, E1N.val_N39,
    E1N.val_N40, E1N.val_N41, E1N.val_N42, E1N.val_N43, E1N.val_N44, E1N.val_N45, E1N.val_N46, E1N.val_N47, E1N.val_N48, E1N.val_N49,
    E1N.val_N50, E1N.val_N51, E1N.val_N52, E1N.val_C53, E1N.val_N53,
    E1N.val_T1 , E1N.val_T2,  E1N.val_T3,  E1N.val_T4,  E1N.val_T5,  E1N.val_T6,  E1N. val_T7, E1N. val_T8, E1N.val_T9,
    E1N.val_T10, E1N.val_T11, E1N.val_T12, E1N.val_T13, E1N.val_T14, E1N.val_T15,
    E1N.DEPASIRE,
    E1N.Pret, E1N.Scadenta,
    E1N.STOC, E1N.STOCOPTIM, OBJ.DENUMIRE, NUM.DEN_UM, CC.SIMBOL, P.DEN_PART, OBJ.CODEXTERN, E1N.COEFUM
  FROM ESTIMARIPROD1M E1N
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = E1N.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NUM ON NUM.CODUM = ART.UM
    LEFT JOIN NPART P ON P.CODPART = OBJ.CODPRODUCATOR
    LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = aSubunitatea
    LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = aSubunitatea
    LEFT JOIN (
      SELECT ioa1.codioart, c.simbol
      FROM IOART1 IOA1 LEFT JOIN NCONT C ON C.CODCONT = IOA1.CONT
      WHERE aAn * 12 + aLuna BETWEEN IOA1.ALStart AND IOA1.ALStop
    ) cc on cc.codioart = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN imp.contimplicit ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
  WHERE CODESTIMAREPROD = aCodEstimareProd;

  insert into tmp_estimariprod1mvt (
    CodEstimareProd,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
    C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
    C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
    C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
    C50, C51, C52,
    N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
    N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
    N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
    N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
    N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
    N50, N51, N52, C53, N53,
    DEPASIRE,
    T1,  T2,  T3,  T4,  T5,  T6,  T7,  T8,  T9,
    T10, T11, T12, T13, T14, T15
  )
  select
    CodEstimareProd,
    SUM(nvl(val_C1 ,0)), SUM(nvl(val_C2 ,0)), SUM(nvl(val_C3 ,0)), SUM(nvl(val_C4 ,0)), SUM(nvl(val_C5 ,0)), SUM(nvl(val_C6 ,0)), SUM(nvl(val_C7 ,0)), SUM(nvl(val_C8 ,0)), SUM(nvl(val_C9 ,0)),
    SUM(nvl(val_C10,0)), SUM(nvl(val_C11,0)), SUM(nvl(val_C12,0)), SUM(nvl(val_C13,0)), SUM(nvl(val_C14,0)), SUM(nvl(val_C15,0)), SUM(nvl(val_C16,0)), SUM(nvl(val_C17,0)), SUM(nvl(val_C18,0)), SUM(nvl(val_C19,0)),
    SUM(nvl(val_C20,0)), SUM(nvl(val_C21,0)), SUM(nvl(val_C22,0)), SUM(nvl(val_C23,0)), SUM(nvl(val_C24,0)), SUM(nvl(val_C25,0)), SUM(nvl(val_C26,0)), SUM(nvl(val_C27,0)), SUM(nvl(val_C28,0)), SUM(nvl(val_C29,0)),
    SUM(nvl(val_C30,0)), SUM(nvl(val_C31,0)), SUM(nvl(val_C32,0)), SUM(nvl(val_C33,0)), SUM(nvl(val_C34,0)), SUM(nvl(val_C35,0)), SUM(nvl(val_C36,0)), SUM(nvl(val_C37,0)), SUM(nvl(val_C38,0)), SUM(nvl(val_C39,0)),
    SUM(nvl(val_C40,0)), SUM(nvl(val_C41,0)), SUM(nvl(val_C42,0)), SUM(nvl(val_C43,0)), SUM(nvl(val_C44,0)), SUM(nvl(val_C45,0)), SUM(nvl(val_C46,0)), SUM(nvl(val_C47,0)), SUM(nvl(val_C48,0)), SUM(nvl(val_C49,0)),
    SUM(nvl(val_C50,0)), SUM(nvl(val_C51,0)), SUM(nvl(val_C52,0)),
    SUM(nvl(val_N1 ,0)), SUM(nvl(val_N2 ,0)), SUM(nvl(val_N3 ,0)), SUM(nvl(val_N4 ,0)), SUM(nvl(val_N5 ,0)), SUM(nvl(val_N6 ,0)), SUM(nvl(val_N7 ,0)), SUM(nvl(val_N8 ,0)), SUM(nvl(val_N9 ,0)),
    SUM(nvl(val_N10,0)), SUM(nvl(val_N11,0)), SUM(nvl(val_N12,0)), SUM(nvl(val_N13,0)), SUM(nvl(val_N14,0)), SUM(nvl(val_N15,0)), SUM(nvl(val_N16,0)), SUM(nvl(val_N17,0)), SUM(nvl(val_N18,0)), SUM(nvl(val_N19,0)),
    SUM(nvl(val_N20,0)), SUM(nvl(val_N21,0)), SUM(nvl(val_N22,0)), SUM(nvl(val_N23,0)), SUM(nvl(val_N24,0)), SUM(nvl(val_N25,0)), SUM(nvl(val_N26,0)), SUM(nvl(val_N27,0)), SUM(nvl(val_N28,0)), SUM(nvl(val_N29,0)),
    SUM(nvl(val_N30,0)), SUM(nvl(val_N31,0)), SUM(nvl(val_N32,0)), SUM(nvl(val_N33,0)), SUM(nvl(val_N34,0)), SUM(nvl(val_N35,0)), SUM(nvl(val_N36,0)), SUM(nvl(val_N37,0)), SUM(nvl(val_N38,0)), SUM(nvl(val_N39,0)),
    SUM(nvl(val_N40,0)), SUM(nvl(val_N41,0)), SUM(nvl(val_N42,0)), SUM(nvl(val_N43,0)), SUM(nvl(val_N44,0)), SUM(nvl(val_N45,0)), SUM(nvl(val_N46,0)), SUM(nvl(val_N47,0)), SUM(nvl(val_N48,0)), SUM(nvl(val_N49,0)),
    SUM(nvl(val_N50,0)), SUM(nvl(val_N51,0)), SUM(nvl(val_N52,0)), SUM(nvl(val_C53,0)), SUM(nvl(val_N53,0)),
    SUM(nvl(DEPASIRE,0)),
    SUM(NVL(val_T1 ,0)), SUM(NVL(val_T2 ,0)), SUM(NVL(val_T3 ,0)), SUM(NVL(val_T4 ,0)), SUM(NVL(val_T5 ,0)), SUM(NVL(val_T6 ,0)), SUM(NVL(val_T7 ,0)), SUM(NVL(val_T8 ,0)), SUM(NVL(val_T9 ,0)),
    SUM(NVL(val_T10,0)), SUM(NVL(val_T11,0)), SUM(NVL(val_T12,0)), SUM(NVL(val_T13,0)), SUM(NVL(val_T14,0)), SUM(NVL(val_T15,0))
  from tmp_estimariprod1m
  group by codestimareprod;

  update tmp_estimariprod1mvt set
  total = C1+ C2+ C3+ C4+ C5+ C6+ C7+ C8+ C9+
          C10+ C11+ C12+ C13+ C14+ C15+ C16+ C17+ C18+ C19+
          C20+ C21+ C22+ C23+ C24+ C25+ C26+ C27+ C28+ C29+
          C30+ C31+ C32+ C33+ C34+ C35+ C36+ C37+ C38+ C39+
          C40+ C41+ C42+ C43+ C44+ C45+ C46+ C47+ C48+ C49+
          C50+ C51+ C52+
          N1+  N2+  N3+  N4+  N5+  N6+  N7+  N8+  N9+
          N10+ N11+ N12+ N13+ N14+ N15+ N16+ N17+ N18+ N19+
          N20+ N21+ N22+ N23+ N24+ N25+ N26+ N27+ N28+ N29+
          N30+ N31+ N32+ N33+ N34+ N35+ N36+ N37+ N38+ N39+
          N40+ N41+ N42+ N43+ N44+ N45+ N46+ N47+ N48+ N49+
          N50+ N51+ N52+ C53+ N53 +
          DEPASIRE +
          T1+  T2+  T3+  T4+  T5+  T6+  T7+  T8+  T9+
          T10+ T11+ T12+ T13+ T14+ T15
          ;

  INSERT INTO TMP_ESTIMARINOD(CODESTIMARENOD,
                              CODESTIMAREPROD,
                              CODESTIMAREPROD1,
                              CANT,
                              NODORIGINAL,
                              POZITIE,
                              CODRETETA,
                              TIP,
                              CODOBIECT,
                              INDEXPARINTE,
                              CODPRODMAT,
                              NIVEL,
                              ORDINE,
                              CODPROIECTNOD,
                              VERSIUNE,
                              CANTPRODRETETA,
                              CANTMATRETETA,
                              NECESAR,
                              Saptamana,
                              AN,
                              denumire)
  SELECT
    nod.CODESTIMARENOD,
    nod.CODESTIMAREPROD,
    nod.CODESTIMAREPROD1,
    nod.CANT,
    nod.NODORIGINAL,
    nod.POZITIE,
    nod.CODRETETA,
    nod.TIP,
    nod.CODOBIECT,
    nod.INDEXPARINTE,
    nod.CODPRODMAT,
    nod.NIVEL,
    nod.ORDINE,
    nod.CODPROIECTNOD,
    nod.VERSIUNE,
    nod.CANTPRODRETETA,
    nod.CANTMATRETETA,
    nod.NECESAR,
    nod.SAPTAMANA,
    AN,
    obj.denumire
  FROM ESTIMARINOD nod
       inner join nartobj obj on obj.codobiect = nod.codobiect
  WHERE CODESTIMAREPROD1 = aRECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
VCOD NUMBER(20);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodSubunit NUMBER(20);
aDataDoc DATE;
aDoc varchar2(200);
vCodES number(20);
BEGIN
  SELECT
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;DATADOC
  INTO
    ACARNETDOC,
    ANRDOC,
    aCodSubunit,
    aDataDoc,
    ADOC
  FROM
    TMP_ESTIMARIPROD;

  IF Operation = 0 THEN -- UPDATE
    SELECT CODESTIMAREPROD1 INTO RECID FROM TMP_ESTIMARIPROD1;
    select CODESTIMAREPROD INTO vCodES FROM TMP_ESTIMARIPROD1;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;ESTIMARIPROD&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE ESTIMARIPROD
    SET (AN, LUNA, SUBUNITATEA, OBS,
         ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
         SERIADOC, PREFIXDOC, ANIMPORT, SAPTAMANAF, ANF, CODOFERTA)
    =
    (SELECT AN, LUNA, SUBUNITATEA, OBS,
           ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
           SERIADOC, PREFIXDOC, ANIMPORT, SAPTAMANAF, ANF, CODOFERTA
    FROM TMP_ESTIMARIPROD)
    WHERE CODESTIMAREPROD = vCodES;

    DELETE ESTIMARIPROD1 ES WHERE ES.CODESTIMAREPROD1 = RECID AND NOT EXISTS (SELECT TMP.CODESTIMAREPROD1 FROM TMP_ESTIMARIPROD1 TMP WHERE TMP.CODESTIMAREPROD1 = ES.CODESTIMAREPROD1);
    FOR V_REC IN (SELECT * FROM TMP_ESTIMARIPROD1) LOOP
      IF V_REC.CODESTIMAREPROD1 &gt; 0 THEN
        UPDATE ESTIMARIPROD1
        SET
          CODOBIECT = V_REC.CODOBIECT,
          C1 = V_REC.C1, C2 = V_REC.C2, C3 = V_REC.C3, C4 = V_REC.C4, C5 = V_REC.C5, C6 = V_REC.C6, C7 = V_REC.C7, C8 = V_REC.C8, C9 = V_REC.C9,
          C10 = V_REC.C10, C11 = V_REC.C11, C12 = V_REC.C12, C13 = V_REC.C13, C14 = V_REC.C14, C15 = V_REC.C15, C16 = V_REC.C16, C17 = V_REC.C17, C18 = V_REC.C18, C19 = V_REC.C19,
          C20 = V_REC.C20, C21 = V_REC.C21, C22 = V_REC.C22, C23 = V_REC.C23, C24 = V_REC.C24, C25 = V_REC.C25, C26 = V_REC.C26, C27 = V_REC.C27, C28 = V_REC.C28, C29 = V_REC.C29,
          C30 = V_REC.C30, C31 = V_REC.C31, C32 = V_REC.C32, C33 = V_REC.C33, C34 = V_REC.C34, C35 = V_REC.C35, C36 = V_REC.C36, C37 = V_REC.C37, C38 = V_REC.C38, C39 = V_REC.C39,
          C40 = V_REC.C40, C41 = V_REC.C41, C42 = V_REC.C42, C43 = V_REC.C43, C44 = V_REC.C44, C45 = V_REC.C45, C46 = V_REC.C46, C47 = V_REC.C47, C48 = V_REC.C48, C49 = V_REC.C49,
          C50 = V_REC.C50, C51 = V_REC.C51, C52 = V_REC.C52,
          N1 = V_REC.N1,  N2 = V_REC.N2,  N3 = V_REC.N3,  N4 = V_REC.N4,  N5 = V_REC.N5,  N6 = V_REC.N6,  N7 = V_REC.N7,  N8 = V_REC.N8,  N9 = V_REC.N9,
          N10 = V_REC.N10, N11 = V_REC.N11, N12 = V_REC.N12, N13 = V_REC.N13, N14 = V_REC.N14, N15 = V_REC.N15, N16 = V_REC.N16, N17 = V_REC.N17, N18 = V_REC.N18, N19 = V_REC.N19,
          N20 = V_REC.N20, N21 = V_REC.N21, N22 = V_REC.N22, N23 = V_REC.N23, N24 = V_REC.N24, N25 = V_REC.N25, N26 = V_REC.N26, N27 = V_REC.N27, N28 = V_REC.N28, N29 = V_REC.N29,
          N30 = V_REC.N30, N31 = V_REC.N31, N32 = V_REC.N32, N33 = V_REC.N33, N34 = V_REC.N34, N35 = V_REC.N35, N36 = V_REC.N36, N37 = V_REC.N37, N38 = V_REC.N38, N39 = V_REC.N39,
          N40 = V_REC.N40, N41 = V_REC.N41, N42 = V_REC.N42, N43 = V_REC.N43, N44 = V_REC.N44, N45 = V_REC.N45, N46 = V_REC.N46, N47 = V_REC.N47, N48 = V_REC.N48, N49 = V_REC.N49,
          N50 = V_REC.N50, N51 = V_REC.N51, N52 = V_REC.N52, C53 = V_REC.C53, N53 = V_REC.N53,
          VAL_C1  = V_REC.VAL_C1,  VAL_C2  = V_REC.VAL_C2,  VAL_C3  = V_REC.VAL_C3,  VAL_C4  = V_REC.VAL_C4,  VAL_C5  = V_REC.VAL_C5,  VAL_C6  = V_REC.VAL_C6,  VAL_C7  = V_REC.VAL_C7,  VAL_C8  = V_REC.VAL_C8,  VAL_C9  = V_REC.VAL_C9,
          VAL_C10 = V_REC.VAL_C10, VAL_C11 = V_REC.VAL_C11, VAL_C12 = V_REC.VAL_C12, VAL_C13 = V_REC.VAL_C13, VAL_C14 = V_REC.VAL_C14, VAL_C15 = V_REC.VAL_C15, VAL_C16 = V_REC.VAL_C16, VAL_C17 = V_REC.VAL_C17, VAL_C18 = V_REC.VAL_C18, VAL_C19 = V_REC.VAL_C19,
          VAL_C20 = V_REC.VAL_C20, VAL_C21 = V_REC.VAL_C21, VAL_C22 = V_REC.VAL_C22, VAL_C23 = V_REC.VAL_C23, VAL_C24 = V_REC.VAL_C24, VAL_C25 = V_REC.VAL_C25, VAL_C26 = V_REC.VAL_C26, VAL_C27 = V_REC.VAL_C27, VAL_C28 = V_REC.VAL_C28, VAL_C29 = V_REC.VAL_C29,
          VAL_C30 = V_REC.VAL_C30, VAL_C31 = V_REC.VAL_C31, VAL_C32 = V_REC.VAL_C32, VAL_C33 = V_REC.VAL_C33, VAL_C34 = V_REC.VAL_C34, VAL_C35 = V_REC.VAL_C35, VAL_C36 = V_REC.VAL_C36, VAL_C37 = V_REC.VAL_C37, VAL_C38 = V_REC.VAL_C38, VAL_C39 = V_REC.VAL_C39,
          VAL_C40 = V_REC.VAL_C40, VAL_C41 = V_REC.VAL_C41, VAL_C42 = V_REC.VAL_C42, VAL_C43 = V_REC.VAL_C43, VAL_C44 = V_REC.VAL_C44, VAL_C45 = V_REC.VAL_C45, VAL_C46 = V_REC.VAL_C46, VAL_C47 = V_REC.VAL_C47, VAL_C48 = V_REC.VAL_C48, VAL_C49 = V_REC.VAL_C49,
          VAL_C50 = V_REC.VAL_C50, VAL_C51 = V_REC.VAL_C51, VAL_C52 = V_REC.VAL_C52,
          VAL_N1  = V_REC.VAL_N1,  VAL_N2  = V_REC.VAL_N2,  VAL_N3  = V_REC.VAL_N3,  VAL_N4  = V_REC.VAL_N4,  VAL_N5 = V_REC.VAL_N5,   VAL_N6  = V_REC.VAL_N6,  VAL_N7  = V_REC.VAL_N7,  VAL_N8  = V_REC.VAL_N8,  VAL_N9  = V_REC.VAL_N9,
          VAL_N10 = V_REC.VAL_N10, VAL_N11 = V_REC.VAL_N11, VAL_N12 = V_REC.VAL_N12, VAL_N13 = V_REC.VAL_N13, VAL_N14 = V_REC.VAL_N14, VAL_N15 = V_REC.VAL_N15, VAL_N16 = V_REC.VAL_N16, VAL_N17 = V_REC.VAL_N17, VAL_N18 = V_REC.VAL_N18, VAL_N19 = V_REC.VAL_N19,
          VAL_N20 = V_REC.VAL_N20, VAL_N21 = V_REC.VAL_N21, VAL_N22 = V_REC.VAL_N22, VAL_N23 = V_REC.VAL_N23, VAL_N24 = V_REC.VAL_N24, VAL_N25 = V_REC.VAL_N25, VAL_N26 = V_REC.VAL_N26, VAL_N27 = V_REC.VAL_N27, VAL_N28 = V_REC.VAL_N28, VAL_N29 = V_REC.VAL_N29,
          VAL_N30 = V_REC.VAL_N30, VAL_N31 = V_REC.VAL_N31, VAL_N32 = V_REC.VAL_N32, VAL_N33 = V_REC.VAL_N33, VAL_N34 = V_REC.VAL_N34, VAL_N35 = V_REC.VAL_N35, VAL_N36 = V_REC.VAL_N36, VAL_N37 = V_REC.VAL_N37, VAL_N38 = V_REC.VAL_N38, VAL_N39 = V_REC.VAL_N39,
          VAL_N40 = V_REC.VAL_N40, VAL_N41 = V_REC.VAL_N41, VAL_N42 = V_REC.VAL_N42, VAL_N43 = V_REC.VAL_N43, VAL_N44 = V_REC.VAL_N44, VAL_N45 = V_REC.VAL_N45, VAL_N46 = V_REC.VAL_N46, VAL_N47 = V_REC.VAL_N47, VAL_N48 = V_REC.VAL_N48, VAL_N49 = V_REC.VAL_N49,
          VAL_N50 = V_REC.VAL_N50, VAL_N51 = V_REC.VAL_N51, VAL_N52 = V_REC.VAL_N52, VAL_C53 = V_REC.VAL_C53, VAL_N53 = V_REC.VAL_N53,
          DEPASIRE = V_REC.DEPASIRE,
          VAL_T1  = V_REC.VAL_T1,  VAL_T2  = V_REC.VAL_T2,  VAL_T3  = V_REC.VAL_T3,  VAL_T4  = V_REC.VAL_T4,  VAL_T5 = V_REC.VAL_T5,   VAL_T6  = V_REC.VAL_T6,  VAL_T7  = V_REC.VAL_T7,  VAL_T8  = V_REC.VAL_T8,  VAL_T9  = V_REC.VAL_T9,
          VAL_T10 = V_REC.VAL_T10, VAL_T11 = V_REC.VAL_T11, VAL_T12 = V_REC.VAL_T12, VAL_T13 = V_REC.VAL_T13, VAL_T14 = V_REC.VAL_T14, VAL_T15 = V_REC.VAL_T15,
          PRET = V_REC.PRET, SCADENTA = V_REC.SCADENTA
        WHERE CODESTIMAREPROD1 = V_REC.CODESTIMAREPROD1;
      ELSE
        SELECT SEQ_ESTIMARIPROD1_CODESTPROD1.NEXTVAL INTO VCOD FROM DUAL;
        UPDATE TMP_ESTIMARINOD
        SET
          CODESTIMAREPROD1 = VCOD
        WHERE CODESTIMAREPROD1 = V_REC.CODESTIMAREPROD1;

        INSERT INTO ESTIMARIPROD1(
          CodEstimareProd1, CodEstimareProd, CODOBIECT,
          C1, C2, C3, C4, C5, C6, C7, C8, C9,
          C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
          C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
          C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
          C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
          C50, C51, C52,
          N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
          N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
          N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
          N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
          N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
          N50, N51, N52, C53, N53,
          val_C1 ,  val_C2,  val_C3, val_C4,  val_C5,  val_C6,  val_C7,  val_C8,  val_C9,
          val_C10, val_C11, val_C12, val_C13, val_C14, val_C15, val_C16, val_C17, val_C18, val_C19,
          val_C20, val_C21, val_C22, val_C23, val_C24, val_C25, val_C26, val_C27, val_C28, val_C29,
          val_C30, val_C31, val_C32, val_C33, val_C34, val_C35, val_C36, val_C37, val_C38, val_C39,
          val_C40, val_C41, val_C42, val_C43, val_C44, val_C45, val_C46, val_C47, val_C48, val_C49,
          val_C50, val_C51, val_C52,
          val_N1 ,  val_N2, val_N3 , val_N4,  val_N5, val_N6,   val_N7,  val_N8,  val_N9,
          val_N10, val_N11, val_N12, val_N13, val_N14, val_N15, val_N16, val_N17, val_N18, val_N19,
          val_N20, val_N21, val_N22, val_N23, val_N24, val_N25, val_N26, val_N27, val_N28, val_N29,
          val_N30, val_N31, val_N32, val_N33, val_N34, val_N35, val_N36, val_N37, val_N38, val_N39,
          val_N40, val_N41, val_N42, val_N43, val_N44, val_N45, val_N46, val_N47, val_N48, val_N49,
          val_N50, val_N51, val_N52, val_C53, val_N53,
          DEPASIRE,
          val_T1 ,  val_T2, val_T3 , val_T4,  val_T5, val_T6,   val_T7,  val_T8,  val_T9,
          val_T10, val_T11, val_T12, val_T13, val_T14, val_T15,
          PRET, SCADENTA )
        VALUES (
          VCOD, vCodES, V_REC.CODOBIECT,
          V_REC.C1, V_REC.C2, V_REC.C3, V_REC.C4, V_REC.C5, V_REC.C6, V_REC.C7, V_REC.C8, V_REC.C9,
          V_REC.C10, V_REC.C11, V_REC.C12, V_REC.C13, V_REC.C14, V_REC.C15, V_REC.C16, V_REC.C17, V_REC.C18, V_REC.C19,
          V_REC.C20, V_REC.C21, V_REC.C22, V_REC.C23, V_REC.C24, V_REC.C25, V_REC.C26, V_REC.C27, V_REC.C28, V_REC.C29,
          V_REC.C30, V_REC.C31, V_REC.C32, V_REC.C33, V_REC.C34, V_REC.C35, V_REC.C36, V_REC.C37, V_REC.C38, V_REC.C39,
          V_REC.C40, V_REC.C41, V_REC.C42, V_REC.C43, V_REC.C44, V_REC.C45, V_REC.C46, V_REC.C47, V_REC.C48, V_REC.C49,
          V_REC.C50, V_REC.C51, V_REC.C52,
          V_REC.N1,  V_REC.N2,  V_REC.N3,  V_REC.N4,  V_REC.N5,  V_REC.N6,  V_REC.N7,  V_REC.N8,  V_REC.N9,
          V_REC.N10, V_REC.N11, V_REC.N12, V_REC.N13, V_REC.N14, V_REC.N15, V_REC.N16, V_REC.N17, V_REC.N18, V_REC.N19,
          V_REC.N20, V_REC.N21, V_REC.N22, V_REC.N23, V_REC.N24, V_REC.N25, V_REC.N26, V_REC.N27, V_REC.N28, V_REC.N29,
          V_REC.N30, V_REC.N31, V_REC.N32, V_REC.N33, V_REC.N34, V_REC.N35, V_REC.N36, V_REC.N37, V_REC.N38, V_REC.N39,
          V_REC.N40, V_REC.N41, V_REC.N42, V_REC.N43, V_REC.N44, V_REC.N45, V_REC.N46, V_REC.N47, V_REC.N48, V_REC.N49,
          V_REC.N50, V_REC.N51, V_REC.N52, V_REC.C53, V_REC.N53,
          V_REC.val_C1 , V_REC.val_C2,  V_REC.val_C3,  V_REC.val_C4,  V_REC.val_C5,  V_REC.val_C6,  V_REC.val_C7,  V_REC.val_C8,  V_REC.val_C9,
          V_REC.val_C10, V_REC.val_C11, V_REC.val_C12, V_REC.val_C13, V_REC.val_C14, V_REC.val_C15, V_REC.val_C16, V_REC.val_C17, V_REC.val_C18, V_REC.val_C19,
          V_REC.val_C20, V_REC.val_C21, V_REC.val_C22, V_REC.val_C23, V_REC.val_C24, V_REC.val_C25, V_REC.val_C26, V_REC.val_C27, V_REC.val_C28, V_REC.val_C29,
          V_REC.val_C30, V_REC.val_C31, V_REC.val_C32, V_REC.val_C33, V_REC.val_C34, V_REC.val_C35, V_REC.val_C36, V_REC.val_C37, V_REC.val_C38, V_REC.val_C39,
          V_REC.val_C40, V_REC.val_C41, V_REC.val_C42, V_REC.val_C43, V_REC.val_C44, V_REC.val_C45, V_REC.val_C46, V_REC.val_C47, V_REC.val_C48, V_REC.val_C49,
          V_REC.val_C50, V_REC.val_C51, V_REC.val_C52,
          V_REC.val_N1 , V_REC.val_N2,  V_REC.val_N3 , V_REC.val_N4,  V_REC.val_N5,  V_REC.val_N6,  V_REC.val_N7,  V_REC.val_N8,  V_REC.val_N9,
          V_REC.val_N10, V_REC.val_N11, V_REC.val_N12, V_REC.val_N13, V_REC.val_N14, V_REC.val_N15, V_REC.val_N16, V_REC.val_N17, V_REC.val_N18, V_REC.val_N19,
          V_REC.val_N20, V_REC.val_N21, V_REC.val_N22, V_REC.val_N23, V_REC.val_N24, V_REC.val_N25, V_REC.val_N26, V_REC.val_N27, V_REC.val_N28, V_REC.val_N29,
          V_REC.val_N30, V_REC.val_N31, V_REC.val_N32, V_REC.val_N33, V_REC.val_N34, V_REC.val_N35, V_REC.val_N36, V_REC.val_N37, V_REC.val_N38, V_REC.val_N39,
          V_REC.val_N40, V_REC.val_N41, V_REC.val_N42, V_REC.val_N43, V_REC.val_N44, V_REC.val_N45, V_REC.val_N46, V_REC.val_N47, V_REC.val_N48, V_REC.val_N49,
          V_REC.val_N50, V_REC.val_N51, V_REC.val_N52, V_REC.val_C53, V_REC.val_N53,
          V_rEC.Depasire,
          V_REC.val_T1 , V_REC.val_T2,  V_REC.val_T3 , V_REC.val_T4,  V_REC.val_T5,  V_REC.val_T6,  V_REC.val_T7,  V_REC.val_T8,  V_REC.val_T9,
          V_REC.val_T10, V_REC.val_T11, V_REC.val_T12, V_REC.val_T13, V_REC.val_T14, V_REC.val_T15,
          V_REC.PRET, V_REC.SCADENTA);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_ESTIMARIPROD1) LOOP
      IF V_REC.CODESTIMAREPROD1 &gt; 0 THEN
        UPDATE ESTIMARIPROD1N
        SET
          CODOBIECT = V_REC.CODOBIECT,
          NEC_C1  = V_REC.NEC_C1,  NEC_C2  = V_REC.NEC_C2,  NEC_C3  = V_REC.NEC_C3,  NEC_C4  = V_REC.NEC_C4,  NEC_C5  = V_REC.NEC_C5,  NEC_C6  = V_REC.NEC_C6,  NEC_C7  = V_REC.NEC_C7,  NEC_C8  = V_REC.NEC_C8,  NEC_C9  = V_REC.NEC_C9,
          NEC_C10 = V_REC.NEC_C10, NEC_C11 = V_REC.NEC_C11, NEC_C12 = V_REC.NEC_C12, NEC_C13 = V_REC.NEC_C13, NEC_C14 = V_REC.NEC_C14, NEC_C15 = V_REC.NEC_C15, NEC_C16 = V_REC.NEC_C16, NEC_C17 = V_REC.NEC_C17, NEC_C18 = V_REC.NEC_C18, NEC_C19 = V_REC.NEC_C19,
          NEC_C20 = V_REC.NEC_C20, NEC_C21 = V_REC.NEC_C21, NEC_C22 = V_REC.NEC_C22, NEC_C23 = V_REC.NEC_C23, NEC_C24 = V_REC.NEC_C24, NEC_C25 = V_REC.NEC_C25, NEC_C26 = V_REC.NEC_C26, NEC_C27 = V_REC.NEC_C27, NEC_C28 = V_REC.NEC_C28, NEC_C29 = V_REC.NEC_C29,
          NEC_C30 = V_REC.NEC_C30, NEC_C31 = V_REC.NEC_C31, NEC_C32 = V_REC.NEC_C32, NEC_C33 = V_REC.NEC_C33, NEC_C34 = V_REC.NEC_C34, NEC_C35 = V_REC.NEC_C35, NEC_C36 = V_REC.NEC_C36, NEC_C37 = V_REC.NEC_C37, NEC_C38 = V_REC.NEC_C38, NEC_C39 = V_REC.NEC_C39,
          NEC_C40 = V_REC.NEC_C40, NEC_C41 = V_REC.NEC_C41, NEC_C42 = V_REC.NEC_C42, NEC_C43 = V_REC.NEC_C43, NEC_C44 = V_REC.NEC_C44, NEC_C45 = V_REC.NEC_C45, NEC_C46 = V_REC.NEC_C46, NEC_C47 = V_REC.NEC_C47, NEC_C48 = V_REC.NEC_C48, NEC_C49 = V_REC.NEC_C49,
          NEC_C50 = V_REC.NEC_C50, NEC_C51 = V_REC.NEC_C51, NEC_C52 = V_REC.NEC_C52,
          NEC_N1  = V_REC.NEC_N1,  NEC_N2  = V_REC.NEC_N2,  NEC_N3  = V_REC.NEC_N3,  NEC_N4  = V_REC.NEC_N4,  NEC_N5  = V_REC.NEC_N5,  NEC_N6  = V_REC.NEC_N6,  NEC_N7  = V_REC.NEC_N7,  NEC_N8  = V_REC.NEC_N8,  NEC_N9  = V_REC.NEC_N9,
          NEC_N10 = V_REC.NEC_N10, NEC_N11 = V_REC.NEC_N11, NEC_N12 = V_REC.NEC_N12, NEC_N13 = V_REC.NEC_N13, NEC_N14 = V_REC.NEC_N14, NEC_N15 = V_REC.NEC_N15, NEC_N16 = V_REC.NEC_N16, NEC_N17 = V_REC.NEC_N17, NEC_N18 = V_REC.NEC_N18, NEC_N19 = V_REC.NEC_N19,
          NEC_N20 = V_REC.NEC_N20, NEC_N21 = V_REC.NEC_N21, NEC_N22 = V_REC.NEC_N22, NEC_N23 = V_REC.NEC_N23, NEC_N24 = V_REC.NEC_N24, NEC_N25 = V_REC.NEC_N25, NEC_N26 = V_REC.NEC_N26, NEC_N27 = V_REC.NEC_N27, NEC_N28 = V_REC.NEC_N28, NEC_N29 = V_REC.NEC_N29,
          NEC_N30 = V_REC.NEC_N30, NEC_N31 = V_REC.NEC_N31, NEC_N32 = V_REC.NEC_N32, NEC_N33 = V_REC.NEC_N33, NEC_N34 = V_REC.NEC_N34, NEC_N35 = V_REC.NEC_N35, NEC_N36 = V_REC.NEC_N36, NEC_N37 = V_REC.NEC_N37, NEC_N38 = V_REC.NEC_N38, NEC_N39 = V_REC.NEC_N39,
          NEC_N40 = V_REC.NEC_N40, NEC_N41 = V_REC.NEC_N41, NEC_N42 = V_REC.NEC_N42, NEC_N43 = V_REC.NEC_N43, NEC_N44 = V_REC.NEC_N44, NEC_N45 = V_REC.NEC_N45, NEC_N46 = V_REC.NEC_N46, NEC_N47 = V_REC.NEC_N47, NEC_N48 = V_REC.NEC_N48, NEC_N49 = V_REC.NEC_N49,
          NEC_N50 = V_REC.NEC_N50, NEC_N51 = V_REC.NEC_N51, NEC_N52 = V_REC.NEC_N52, NEC_C53 = V_REC.NEC_C53, NEC_N53 = V_REC.NEC_N53,
          STOC = V_REC.STOC, COEFUM = V_REC.COEFUM, STOCOPTIM = V_REC.STOCOPTIM
        WHERE CODESTIMAREPROD = vCodES AND CODOBIECT = (SELECT CODOBIECT FROM ESTIMARIPROD1 WHERE CODESTIMAREPROD1 = RECID);
      ELSE
        SELECT SEQ_ESTPROD1N_CODESTPROD1N.NEXTVAL INTO VCOD FROM DUAL;

        INSERT INTO ESTIMARIPROD1N(
          CodEstimareProd1N, CodEstimareProd, CODOBIECT,
          NEC_C1,  NEC_C2,  NEC_C3,  NEC_C4,  NEC_C5,  NEC_C6,  NEC_C7,  NEC_C8,  NEC_C9,
          NEC_C10, NEC_C11, NEC_C12, NEC_C13, NEC_C14, NEC_C15, NEC_C16, NEC_C17, NEC_C18, NEC_C19,
          NEC_C20, NEC_C21, NEC_C22, NEC_C23, NEC_C24, NEC_C25, NEC_C26, NEC_C27, NEC_C28, NEC_C29,
          NEC_C30, NEC_C31, NEC_C32, NEC_C33, NEC_C34, NEC_C35, NEC_C36, NEC_C37, NEC_C38, NEC_C39,
          NEC_C40, NEC_C41, NEC_C42, NEC_C43, NEC_C44, NEC_C45, NEC_C46, NEC_C47, NEC_C48, NEC_C49,
          NEC_C50, NEC_C51, NEC_C52,
          NEC_N1,  NEC_N2,  NEC_N3,  NEC_N4,  NEC_N5,  NEC_N6,  NEC_N7,  NEC_N8,  NEC_N9,
          NEC_N10, NEC_N11, NEC_N12, NEC_N13, NEC_N14, NEC_N15, NEC_N16, NEC_N17, NEC_N18, NEC_N19,
          NEC_N20, NEC_N21, NEC_N22, NEC_N23, NEC_N24, NEC_N25, NEC_N26, NEC_N27, NEC_N28, NEC_N29,
          NEC_N30, NEC_N31, NEC_N32, NEC_N33, NEC_N34, NEC_N35, NEC_N36, NEC_N37, NEC_N38, NEC_N39,
          NEC_N40, NEC_N41, NEC_N42, NEC_N43, NEC_N44, NEC_N45, NEC_N46, NEC_N47, NEC_N48, NEC_N49,
          NEC_N50, NEC_N51, NEC_N52, NEC_C53, NEC_N53,
          STOC, STOCOPTIM, COEFUM )
        VALUES (
          VCOD, vCodES, V_REC.CODOBIECT,
          V_REC.NEC_C1,  V_REC.NEC_C2,  V_REC.NEC_C3,  V_REC.NEC_C4,  V_REC.NEC_C5,  V_REC.NEC_C6,  V_REC.NEC_C7,  V_REC.NEC_C8,  V_REC.NEC_C9,
          V_REC.NEC_C10, V_REC.NEC_C11, V_REC.NEC_C12, V_REC.NEC_C13, V_REC.NEC_C14, V_REC.NEC_C15, V_REC.NEC_C16, V_REC.NEC_C17, V_REC.NEC_C18, V_REC.NEC_C19,
          V_REC.NEC_C20, V_REC.NEC_C21, V_REC.NEC_C22, V_REC.NEC_C23, V_REC.NEC_C24, V_REC.NEC_C25, V_REC.NEC_C26, V_REC.NEC_C27, V_REC.NEC_C28, V_REC.NEC_C29,
          V_REC.NEC_C30, V_REC.NEC_C31, V_REC.NEC_C32, V_REC.NEC_C33, V_REC.NEC_C34, V_REC.NEC_C35, V_REC.NEC_C36, V_REC.NEC_C37, V_REC.NEC_C38, V_REC.NEC_C39,
          V_REC.NEC_C40, V_REC.NEC_C41, V_REC.NEC_C42, V_REC.NEC_C43, V_REC.NEC_C44, V_REC.NEC_C45, V_REC.NEC_C46, V_REC.NEC_C47, V_REC.NEC_C48, V_REC.NEC_C49,
          V_REC.NEC_C50, V_REC.NEC_C51, V_REC.NEC_C52,
          V_REC.NEC_N1,  V_REC.NEC_N2,  V_REC.NEC_N3,  V_REC.NEC_N4,  V_REC.NEC_N5,  V_REC.NEC_N6,  V_REC.NEC_N7,  V_REC.NEC_N8,  V_REC.NEC_N9,
          V_REC.NEC_N10, V_REC.NEC_N11, V_REC.NEC_N12, V_REC.NEC_N13, V_REC.NEC_N14, V_REC.NEC_N15, V_REC.NEC_N16, V_REC.NEC_N17, V_REC.NEC_N18, V_REC.NEC_N19,
          V_REC.NEC_N20, V_REC.NEC_N21, V_REC.NEC_N22, V_REC.NEC_N23, V_REC.NEC_N24, V_REC.NEC_N25, V_REC.NEC_N26, V_REC.NEC_N27, V_REC.NEC_N28, V_REC.NEC_N29,
          V_REC.NEC_N30, V_REC.NEC_N31, V_REC.NEC_N32, V_REC.NEC_N33, V_REC.NEC_N34, V_REC.NEC_N35, V_REC.NEC_N36, V_REC.NEC_N37, V_REC.NEC_N38, V_REC.NEC_N39,
          V_REC.NEC_N40, V_REC.NEC_N41, V_REC.NEC_N42, V_REC.NEC_N43, V_REC.NEC_N44, V_REC.NEC_N45, V_REC.NEC_N46, V_REC.NEC_N47, V_REC.NEC_N48, V_REC.NEC_N49,
          V_REC.NEC_N50, V_REC.NEC_N51, V_REC.NEC_N52, V_REC.NEC_C53, V_REC.NEC_N53,
          V_REC.STOC, V_REC.STOCOPTIM, V_REC.COEFUM);
      END IF;
    END LOOP;

    DELETE ESTIMARINOD ES WHERE ES.CODESTIMAREPROD = RECID AND NOT EXISTS (SELECT TMP.CODESTIMARENOD FROM TMP_ESTIMARINOD TMP WHERE TMP.CODESTIMARENOD = ES.CODESTIMARENOD);
    FOR V_REC IN (SELECT * FROM TMP_ESTIMARINOD) LOOP
      IF V_REC.CODESTIMARENOD &gt; 0 THEN
        UPDATE ESTIMARINOD
        SET
          CANT            = V_REC.CANT,
          NODORIGINAL     = V_REC.NODORIGINAL,
          POZITIE         = V_REC.POZITIE,
          CODRETETA       = V_REC.CODRETETA,
          TIP             = V_REC.TIP,
          CODOBIECT       = V_REC.CODOBIECT,
          INDEXPARINTE    = V_REC.INDEXPARINTE,
          CODPRODMAT      = V_REC.CODPRODMAT,
          NIVEL           = V_REC.NIVEL,
          ORDINE          = V_REC.ORDINE,
          CODPROIECTNOD   = V_REC.CODPROIECTNOD,
          VERSIUNE        = V_REC.VERSIUNE,
          CANTPRODRETETA  = V_REC.CANTPRODRETETA,
          CANTMATRETETA   = V_REC.CANTMATRETETA,
          NECESAR         = V_REC.NECESAR,
          SAPTAMANA       = V_REC.SAPTAMANA,
          AN              = V_REC.AN
        WHERE CODESTIMARENOD = V_REC.CODESTIMARENOD;
      ELSE
        INSERT INTO ESTIMARINOD(
          CODESTIMARENOD,
          CODESTIMAREPROD,
          CODESTIMAREPROD1,
          CANT,
          NODORIGINAL,
          POZITIE,
          CODRETETA,
          TIP,
          CODOBIECT,
          INDEXPARINTE,
          CODPRODMAT,
          NIVEL,
          ORDINE,
          CODPROIECTNOD,
          VERSIUNE,
          CANTPRODRETETA,
          CANTMATRETETA,
          NECESAR,
          SAPTAMANA,
          AN)
        VALUES (
          SEQ_ESTIMARINOD_CODESTIMARENOD.NEXTVAL,
          vCodES,
          V_REC.CODESTIMAREPROD1,
          V_REC.CANT,
          V_REC.NODORIGINAL,
          V_REC.POZITIE,
          V_REC.CODRETETA,
          V_REC.TIP,
          V_REC.CODOBIECT,
          V_REC.INDEXPARINTE,
          V_REC.CODPRODMAT,
          V_REC.NIVEL,
          V_REC.ORDINE,
          V_REC.CODPROIECTNOD,
          V_REC.VERSIUNE,
          V_REC.CANTPRODRETETA,
          V_REC.CANTMATRETETA,
          V_REC.NECESAR,
          V_REC.SAPTAMANA,
          V_REC.AN);
      END IF;
    END LOOP;
  ELSE  -- INSERT
    SELECT SEQ_ESTIMARIPROD_CODESTPROD.NEXTVAL INTO RECID FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;ESTIMARIPROD&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO ESTIMARIPROD(CODESTIMAREPROD, AN, LUNA, SUBUNITATEA, USERID, DATACREARE, OBS,
                         ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
                         SERIADOC, PREFIXDOC, ANIMPORT, SAPTAMANAF, ANF)
    SELECT RECID, AN, LUNA, SUBUNITATEA, pkg_globals.GETUSERID, sysdate, OBS,
           ANULAT, BLOCAT, OPERAT, SAPTAMANA, NRDOC, DATADOC, CARNETDOC,
           SERIADOC, PREFIXDOC, ANIMPORT, SAPTAMANAF, ANF
    FROM TMP_ESTIMARIPROD;

    FOR V_REC IN (SELECT * FROM TMP_ESTIMARIPROD1) LOOP
      SELECT SEQ_ESTIMARIPROD1_CODESTPROD1.NEXTVAL INTO VCOD FROM DUAL;
      UPDATE TMP_ESTIMARINOD
      SET
        CODESTIMAREPROD1 = VCOD
      WHERE CODESTIMAREPROD1 = V_REC.CODESTIMAREPROD1;

      INSERT INTO ESTIMARIPROD1 (
        CodEstimareProd1, CodEstimareProd, CODOBIECT,
        C1, C2, C3, C4, C5, C6, C7, C8, C9,
        C10, C11, C12, C13, C14, C15, C16, C17, C18, C19,
        C20, C21, C22, C23, C24, C25, C26, C27, C28, C29,
        C30, C31, C32, C33, C34, C35, C36, C37, C38, C39,
        C40, C41, C42, C43, C44, C45, C46, C47, C48, C49,
        C50, C51, C52,
        N1,  N2,  N3,  N4,  N5,  N6,  N7,  N8,  N9,
        N10, N11, N12, N13, N14, N15, N16, N17, N18, N19,
        N20, N21, N22, N23, N24, N25, N26, N27, N28, N29,
        N30, N31, N32, N33, N34, N35, N36, N37, N38, N39,
        N40, N41, N42, N43, N44, N45, N46, N47, N48, N49,
        N50, N51, N52, C53, N53,
        val_C1 ,  val_C2,  val_C3, val_C4,  val_C5,  val_C6,  val_C7,  val_C8,  val_C9,
        val_C10, val_C11, val_C12, val_C13, val_C14, val_C15, val_C16, val_C17, val_C18, val_C19,
        val_C20, val_C21, val_C22, val_C23, val_C24, val_C25, val_C26, val_C27, val_C28, val_C29,
        val_C30, val_C31, val_C32, val_C33, val_C34, val_C35, val_C36, val_C37, val_C38, val_C39,
        val_C40, val_C41, val_C42, val_C43, val_C44, val_C45, val_C46, val_C47, val_C48, val_C49,
        val_C50, val_C51, val_C52,
        val_N1 ,  val_N2, val_N3 , val_N4,  val_N5, val_N6,   val_N7,  val_N8,  val_N9,
        val_N10, val_N11, val_N12, val_N13, val_N14, val_N15, val_N16, val_N17, val_N18, val_N19,
        val_N20, val_N21, val_N22, val_N23, val_N24, val_N25, val_N26, val_N27, val_N28, val_N29,
        val_N30, val_N31, val_N32, val_N33, val_N34, val_N35, val_N36, val_N37, val_N38, val_N39,
        val_N40, val_N41, val_N42, val_N43, val_N44, val_N45, val_N46, val_N47, val_N48, val_N49,
        val_N50, val_N51, val_N52, val_C53, val_N53,
        DEPASIRE,
        val_T1 ,  val_T2, val_T3 , val_T4,  val_T5, val_T6,   val_T7,  val_T8,  val_T9,
        val_T10, val_T11, val_T12, val_T13, val_T14, val_T15,
        PRET, SCADENTA)
      VALUES
        (VCOD, RECID, V_REC.CODOBIECT,
        V_REC.C1,  V_REC.C2,  V_REC.C3,  V_REC.C4,  V_REC.C5,  V_REC.C6,  V_REC.C7,  V_REC.C8,  V_REC.C9,
        V_REC.C10, V_REC.C11, V_REC.C12, V_REC.C13, V_REC.C14, V_REC.C15, V_REC.C16, V_REC.C17, V_REC.C18, V_REC.C19,
        V_REC.C20, V_REC.C21, V_REC.C22, V_REC.C23, V_REC.C24, V_REC.C25, V_REC.C26, V_REC.C27, V_REC.C28, V_REC.C29,
        V_REC.C30, V_REC.C31, V_REC.C32, V_REC.C33, V_REC.C34, V_REC.C35, V_REC.C36, V_REC.C37, V_REC.C38, V_REC.C39,
        V_REC.C40, V_REC.C41, V_REC.C42, V_REC.C43, V_REC.C44, V_REC.C45, V_REC.C46, V_REC.C47, V_REC.C48, V_REC.C49,
        V_REC.C50, V_REC.C51, V_REC.C52,
        V_REC.N1,  V_REC.N2,  V_REC.N3,  V_REC.N4,  V_REC.N5,  V_REC.N6,  V_REC.N7,  V_REC.N8,  V_REC.N9,
        V_REC.N10, V_REC.N11, V_REC.N12, V_REC.N13, V_REC.N14, V_REC.N15, V_REC.N16, V_REC.N17, V_REC.N18, V_REC.N19,
        V_REC.N20, V_REC.N21, V_REC.N22, V_REC.N23, V_REC.N24, V_REC.N25, V_REC.N26, V_REC.N27, V_REC.N28, V_REC.N29,
        V_REC.N30, V_REC.N31, V_REC.N32, V_REC.N33, V_REC.N34, V_REC.N35, V_REC.N36, V_REC.N37, V_REC.N38, V_REC.N39,
        V_REC.N40, V_REC.N41, V_REC.N42, V_REC.N43, V_REC.N44, V_REC.N45, V_REC.N46, V_REC.N47, V_REC.N48, V_REC.N49,
        V_REC.N50, V_REC.N51, V_REC.N52, V_REC.C53, V_REC.N53,
        V_REC.val_C1 , V_REC.val_C2,  V_REC.val_C3,  V_REC.val_C4,  V_REC.val_C5,  V_REC.val_C6,  V_REC.val_C7,  V_REC.val_C8,  V_REC.val_C9,
        V_REC.val_C10, V_REC.val_C11, V_REC.val_C12, V_REC.val_C13, V_REC.val_C14, V_REC.val_C15, V_REC.val_C16, V_REC.val_C17, V_REC.val_C18, V_REC.val_C19,
        V_REC.val_C20, V_REC.val_C21, V_REC.val_C22, V_REC.val_C23, V_REC.val_C24, V_REC.val_C25, V_REC.val_C26, V_REC.val_C27, V_REC.val_C28, V_REC.val_C29,
        V_REC.val_C30, V_REC.val_C31, V_REC.val_C32, V_REC.val_C33, V_REC.val_C34, V_REC.val_C35, V_REC.val_C36, V_REC.val_C37, V_REC.val_C38, V_REC.val_C39,
        V_REC.val_C40, V_REC.val_C41, V_REC.val_C42, V_REC.val_C43, V_REC.val_C44, V_REC.val_C45, V_REC.val_C46, V_REC.val_C47, V_REC.val_C48, V_REC.val_C49,
        V_REC.val_C50, V_REC.val_C51, V_REC.val_C52,
        V_REC.val_N1 , V_REC.val_N2,  V_REC.val_N3 , V_REC.val_N4,  V_REC.val_N5,  V_REC.val_N6,  V_REC.val_N7,  V_REC.val_N8,  V_REC.val_N9,
        V_REC.val_N10, V_REC.val_N11, V_REC.val_N12, V_REC.val_N13, V_REC.val_N14, V_REC.val_N15, V_REC.val_N16, V_REC.val_N17, V_REC.val_N18, V_REC.val_N19,
        V_REC.val_N20, V_REC.val_N21, V_REC.val_N22, V_REC.val_N23, V_REC.val_N24, V_REC.val_N25, V_REC.val_N26, V_REC.val_N27, V_REC.val_N28, V_REC.val_N29,
        V_REC.val_N30, V_REC.val_N31, V_REC.val_N32, V_REC.val_N33, V_REC.val_N34, V_REC.val_N35, V_REC.val_N36, V_REC.val_N37, V_REC.val_N38, V_REC.val_N39,
        V_REC.val_N40, V_REC.val_N41, V_REC.val_N42, V_REC.val_N43, V_REC.val_N44, V_REC.val_N45, V_REC.val_N46, V_REC.val_N47, V_REC.val_N48, V_REC.val_N49,
        V_REC.val_N50, V_REC.val_N51, V_REC.val_N52, V_REC.val_C53, V_REC.val_N53,
        V_REC.DEPASIRE,
        V_REC.val_T1 , V_REC.val_T2,  V_REC.val_T3 , V_REC.val_T4,  V_REC.val_T5,  V_REC.val_T6,  V_REC.val_T7,  V_REC.val_T8,  V_REC.val_T9,
        V_REC.val_T10, V_REC.val_T11, V_REC.val_T12, V_REC.val_T13, V_REC.val_T14, V_REC.val_T15,
        V_REC.PRET, V_REC.SCADENTA);
    END LOOP;

    INSERT INTO ESTIMARIPROD1N (
      CodEstimareProd1N, CodEstimareProd, CODOBIECT,
      NEC_C1,  NEC_C2,  NEC_C3,  NEC_C4,  NEC_C5,  NEC_C6,  NEC_C7,  NEC_C8,  NEC_C9,
      NEC_C10, NEC_C11, NEC_C12, NEC_C13, NEC_C14, NEC_C15, NEC_C16, NEC_C17, NEC_C18, NEC_C19,
      NEC_C20, NEC_C21, NEC_C22, NEC_C23, NEC_C24, NEC_C25, NEC_C26, NEC_C27, NEC_C28, NEC_C29,
      NEC_C30, NEC_C31, NEC_C32, NEC_C33, NEC_C34, NEC_C35, NEC_C36, NEC_C37, NEC_C38, NEC_C39,
      NEC_C40, NEC_C41, NEC_C42, NEC_C43, NEC_C44, NEC_C45, NEC_C46, NEC_C47, NEC_C48, NEC_C49,
      NEC_C50, NEC_C51, NEC_C52,
      NEC_N1,  NEC_N2,  NEC_N3,  NEC_N4,  NEC_N5,  NEC_N6,  NEC_N7,  NEC_N8,  NEC_N9,
      NEC_N10, NEC_N11, NEC_N12, NEC_N13, NEC_N14, NEC_N15, NEC_N16, NEC_N17, NEC_N18, NEC_N19,
      NEC_N20, NEC_N21, NEC_N22, NEC_N23, NEC_N24, NEC_N25, NEC_N26, NEC_N27, NEC_N28, NEC_N29,
      NEC_N30, NEC_N31, NEC_N32, NEC_N33, NEC_N34, NEC_N35, NEC_N36, NEC_N37, NEC_N38, NEC_N39,
      NEC_N40, NEC_N41, NEC_N42, NEC_N43, NEC_N44, NEC_N45, NEC_N46, NEC_N47, NEC_N48, NEC_N49,
      NEC_N50, NEC_N51, NEC_N52, NEC_C53, NEC_N53,
      STOC, STOCOPTIM, COEFUM)
    SELECT
      SEQ_ESTPROD1N_CODESTPROD1N.NEXTVAL, RECID, E1N.CODOBIECT,
      E1N.NEC_C1,  E1N.NEC_C2,  E1N.NEC_C3,  E1N.NEC_C4,  E1N.NEC_C5,  E1N.NEC_C6,  E1N.NEC_C7,  E1N.NEC_C8,  E1N.NEC_C9,
      E1N.NEC_C10, E1N.NEC_C11, E1N.NEC_C12, E1N.NEC_C13, E1N.NEC_C14, E1N.NEC_C15, E1N.NEC_C16, E1N.NEC_C17, E1N.NEC_C18, E1N.NEC_C19,
      E1N.NEC_C20, E1N.NEC_C21, E1N.NEC_C22, E1N.NEC_C23, E1N.NEC_C24, E1N.NEC_C25, E1N.NEC_C26, E1N.NEC_C27, E1N.NEC_C28, E1N.NEC_C29,
      E1N.NEC_C30, E1N.NEC_C31, E1N.NEC_C32, E1N.NEC_C33, E1N.NEC_C34, E1N.NEC_C35, E1N.NEC_C36, E1N.NEC_C37, E1N.NEC_C38, E1N.NEC_C39,
      E1N.NEC_C40, E1N.NEC_C41, E1N.NEC_C42, E1N.NEC_C43, E1N.NEC_C44, E1N.NEC_C45, E1N.NEC_C46, E1N.NEC_C47, E1N.NEC_C48, E1N.NEC_C49,
      E1N.NEC_C50, E1N.NEC_C51, E1N.NEC_C52,
      E1N.NEC_N1,  E1N.NEC_N2,  E1N.NEC_N3,  E1N.NEC_N4,  E1N.NEC_N5,  E1N.NEC_N6,  E1N.NEC_N7,  E1N.NEC_N8,  E1N.NEC_N9,
      E1N.NEC_N10, E1N.NEC_N11, E1N.NEC_N12, E1N.NEC_N13, E1N.NEC_N14, E1N.NEC_N15, E1N.NEC_N16, E1N.NEC_N17, E1N.NEC_N18, E1N.NEC_N19,
      E1N.NEC_N20, E1N.NEC_N21, E1N.NEC_N22, E1N.NEC_N23, E1N.NEC_N24, E1N.NEC_N25, E1N.NEC_N26, E1N.NEC_N27, E1N.NEC_N28, E1N.NEC_N29,
      E1N.NEC_N30, E1N.NEC_N31, E1N.NEC_N32, E1N.NEC_N33, E1N.NEC_N34, E1N.NEC_N35, E1N.NEC_N36, E1N.NEC_N37, E1N.NEC_N38, E1N.NEC_N39,
      E1N.NEC_N40, E1N.NEC_N41, E1N.NEC_N42, E1N.NEC_N43, E1N.NEC_N44, E1N.NEC_N45, E1N.NEC_N46, E1N.NEC_N47, E1N.NEC_N48, E1N.NEC_N49,
      E1N.NEC_N50, E1N.NEC_N51, E1N.NEC_N52, E1N.NEC_C53, E1N.NEC_N53,
      E1N.STOC, E1N.STOCOPTIM, E1N.COEFUM
    FROM TMP_ESTIMARIPROD1 E1N;

    INSERT INTO ESTIMARINOD(
          CODESTIMARENOD,
          CODESTIMAREPROD,
          CODESTIMAREPROD1,
          CANT,
          NODORIGINAL,
          POZITIE,
          CODRETETA,
          TIP,
          CODOBIECT,
          INDEXPARINTE,
          CODPRODMAT,
          NIVEL,
          ORDINE,
          CODPROIECTNOD,
          VERSIUNE,
          CANTPRODRETETA,
          CANTMATRETETA,
          NECESAR,
          SAPTAMANA,
          AN)
        select
          SEQ_ESTIMARINOD_CODESTIMARENOD.NEXTVAL,
          RECID,
          CODESTIMAREPROD1,
          CANT,
          NODORIGINAL,
          POZITIE,
          CODRETETA,
          TIP,
          CODOBIECT,
          INDEXPARINTE,
          CODPRODMAT,
          NIVEL,
          ORDINE,
          CODPROIECTNOD,
          VERSIUNE,
          CANTPRODRETETA,
          CANTMATRETETA,
          NECESAR,
          SAPTAMANA,
          AN
        from tmp_estimarinod;

    select min(CodEstimareProd1) into RecId
    from EstimariProd1
    where CodEstimareProd = RecId;
  END IF;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
   PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
 END IF;

  NotifyModif(Operation, RecId, &apos;ESTIMARI&apos;);
  COMMIT;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

end PKG_ESTIMARIPROD;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EUDR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8500BCB76B23BBD50498AF52B4667BD9B4918EC6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EUDR is

procedure UpdateNPLinkIntr(aCodIntr in number) is
begin
  for v_rec in (
    select l1.codlivr1, ns.codnirstoc
    from intrari1 i1
         inner join iesiri1 ies1 on ies1.codcmdint1 = i1.codcmdint1
         inner join nartobj o on o.codobiect = ies1.codobiect
         inner join tmp_manevra_liste t on t.filtru = &apos;CODBC&apos; and t.valoare = ies1.codies
         inner join livr l on l.codies = ies1.codies
         inner join livr1 l1 on l1.codlivr = l.codlivr and ies1.codies1 = l1.codies1
         inner join nir n on n.codintr = i1.codintr
         inner join nirstoc ns on ns.codintr1 = i1.codintr1 and ns.codnir = n.codnir
    where i1.codintr = aCodIntr
  ) loop
    insert into nplink(codlivr1, codnirstoc)
    values (v_rec.codlivr1, v_rec.codnirstoc);
  end loop;
  commit;
end;  

procedure UpdatePeZi(aRN_OLD in varchar2, aVN_OLD in varchar2, aRN in varchar2, aVN in varchar2, aDataDoc in varchar2) is
begin
  for v_rec in (
    select ns.codnirstoc
    from nirstoc ns
         INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
         INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
         INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1 AND I1.CODINTR = I.CODINTR
         INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
    WHERE I.DATADOC = TO_DATE(aDataDoc, &apos;dd.mm.yyyy&apos;) AND O.PRODUSPROPRIU = 2
          AND I.TIPDOC = 7 AND I.OPERAT = 1 AND coalesce(NS.EUDR_RN,&apos;?&apos;) = coalesce(aRN_OLD,&apos;?&apos;) AND coalesce(NS.EUDR_VN,&apos;?&apos;) = coalesce(aVN_OLD,&apos;?&apos;)
  ) loop
    update nirstoc ns set EUDR_RN = aRN, EUDR_VN = aVN
    where ns.codnirstoc in  (select ns1.codnirstoc from nirstoc1 ns1 where ns1.codnirstocorig = v_rec.codnirstoc);
  end loop;
  commit;
end;  

end PKG_EUDR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F61347BF2B6E9B2754D7B30E281C6C854B5D86D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EvalS is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodEvalS INTO Tmp FROM EvalS WHERE CodEvalS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM EvalS WHERE CodEvalS = RecId ;
 	DELETE FROM EvalSEv WHERE CodEvalS = RecId ;
 	DELETE FROM EvalSTes WHERE CodEvalS = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EvalS FIELDS( CodEvalS ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  INSERT INTO  TMP_EvalS ( CodEvalS, CodIdentEvalS, den_evaluare)
	 (SELECT E.CodEvalS, E.CodIdentEvalS, I.Nume      
    FROM EvalS E 
    Inner join IdentEvalS I on I.CodIdentEvalS = E. CODIDENTEVALS 
    WHERE CodEvalS = RECID);

 INSERT INTO  TMP_EvalSEv 
	(
    CodEvalSEv, 
    CodEvalS,
    CodEvaluator,
    Den_evaluator   
	)
	SELECT 
    EV.CodEvalSEv, 
    EV.CodEvalS,
    EV.CODEVALUATOR,
    E.NUME
  FROM EvalSEv EV 
  LEFT JOIN Evaluatori E on E.CodEvaluator = EV.CodEvaluator
  WHERE CodEvalS = RECID;



 INSERT INTO  TMP_EvalSTes 
	(
    CodEvalSTes, 
    CodEvalS,
    CodTes,
    Den_Tes   
	)
	SELECT 
    EV.CodEvalSTes, 
    EV.CodEvalS,
    EV.CODTes,
    T.Denumire
  FROM EvalSTes EV 
  LEFT JOIN Tesaturi T on T.CodTesatura = EV.CodTes 
  WHERE CodEvalS = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodEvalS INTO RECID FROM TMP_EvalS;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE EvalS
    SET
     (
           CodIdentEvalS,Den_Evaluare    
			)
			= 
			(SELECT
          E.CodIdentEvalS,I.Nume    
		FROM TMP_EvalS E
    Left join IdentEvalS I on I.Codidentevals = E.CodIdentEvalS)
    WHERE CodEvalS = RECID;

    DELETE FROM EvalSev 
		where CODEvalS = RecID 
		and CodEvalSEv not in (Select CODEvalSEv from Tmp_EvalSEv);

		for v_rec in (select * from Tmp_EvalSEv) loop
      if V_Rec.CodEvalSEv &lt; 0 then 
				INSERT INTO EvalSEv
					( 
              CodEvalSEv, 
              CodEvalS, 
              CodEvaluator
					)
					Values 
					( SEQ_EvalSEv_CodEvalSEv.Nextval,
						RecId ,
 						V_REC.CODEvaluator                  
          );
	    else 
				UPDATE EvalSEv
				SET 
					CODEvalS = V_REC.CODEvalS
				WHERE CodEvalSEv  = v_rec.CodEvalSEv;
	    end if;
	  end loop;

    DELETE FROM EvalSTes 
		where CODEvalS = RecID 
		and CodEvalSTes not in (Select CODEvalSTes from Tmp_EvalSTes);

		for v_rec in (select * from Tmp_EvalSTes) loop
      if V_Rec.CodEvalSTes &lt; 0 then 
				INSERT INTO EvalSTes
					( 
              CodEvalSTes, 
              CodEvalS, 
              CodTes
					)
					Values 
					( SEQ_EvalSTes_CodEvalSTes.Nextval,
						RecId ,
 						V_REC.CODTes                  
          );
	    else 
				UPDATE EvalSTes
				SET 
					CODEvalS = V_REC.CODEvalS
				WHERE CodEvalSTes  = v_rec.CodEvalSTes;
	    end if;
	  end loop;

ELSE  -- INSERT
    SELECT SEQ_EvalS_CodEvalS.NextVal INTO RecId FROM DUAL;
    INSERT INTO EvalS(
        CodEvalS, 
        CodIdentEvalS,
        Den_Evaluare    
    )
    SELECT 
  	RECID   , 
    E.CodIdentEvalS,
    I.Nume    
		FROM TMP_EvalS E
    Left join IdentEvalS I on I.Codidentevals = E.CodIdentEvalS;

   INSERT INTO EvalSEv (CodEvalSEv, CodEvalS, CodEvaluator)
        (SELECT SEQ_EvalSEv_CodEvalSEv.NEXTVAL, RECID,CodEvaluator FROM TMP_EvalSEv);


   INSERT INTO EvalSTes (CodEvalSTes, CodEvalS, CodTes)
        (SELECT SEQ_EvalSTes_CodEvalSTes.NEXTVAL, RECID,CodTes FROM TMP_EvalSTes);

  END IF; 
  NotifyModif(Operation, RecId, &apos;EvalS&apos;);
  COMMIT;
 
END;


end PKG_EvalS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EVALUARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E00E2F106CD4763FB76AC4E675E02B5DAECA2518</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EVALUARI is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodEVALUARE INTO Tmp FROM EVALUARI WHERE CodEVALUARE = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM EVALUARI WHERE CodEVALUARE = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EVALUARI FIELDS( CodEVALUARE ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_EVALUARI 
	(  CODEVALUARE   ,                         
     DATAORA,
     rundaevaluare,
     nrevaluatori ,
     nresantioane ,
     CodEvaluator,    
     codTesatura,
     codDestinatie,
     NUMETESATURA,
     obs,  
     numeevaluator, 
     NUMEDESTINATIE
		)
	SELECT 
     E.CODEVALUARE   ,                         
     E.DATAORA,
     E.rundaevaluare,
     E.nrevaluatori ,
     E.nresantioane ,
     E.CODevaluator,    
     E.codtesatura,
     E.coddestinatie,
     T.Denumire NUMETESATURA,  
     E.obs,
     Ev.NUME numeevaluator, 
     D.NumeDestinatie NUMEDESTINATIE
  FROM EVALUARI E
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie
  WHERE E.CodEVALUARE = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodEVALUARE INTO RECID FROM TMP_EVALUARI;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE EVALUARI
    SET
     (
     DATAORA,
     rundaevaluare,
     nrevaluatori ,
     nresantioane ,
     CodEvaluator,    
     codTesatura,
     codDestinatie,
     NUMETESATURA,
     obs

			)
			= 
			(SELECT 
     DATAORA,
     rundaevaluare,
     nrevaluatori ,
     nresantioane ,
     CodEvaluator,    
     codTesatura,
     codDestinatie,
     NUMETESATURA,
     obs
			FROM TMP_EVALUARI)
    WHERE
      CodEVALUARE = RECID;

ELSE  -- INSERT
    SELECT SEQ_EVALUARI_CODEVALUARE.NextVal INTO RecId FROM DUAL;
    INSERT INTO EVALUARI(
      CODEVALUARE   ,                         
     DATAORA,
     rundaevaluare,
     nrevaluatori ,
     nresantioane ,
     CodEvaluator,    
     codTesatura,
     codDestinatie,
     NUMETESATURA,
     obs
                   )
    SELECT 
  		RECID   , 
     DATAORA,
     rundaevaluare,
     nrevaluatori ,
     nresantioane ,
     CodEvaluator,    
     codTesatura,
     codDestinatie,
     NUMETESATURA,
     obs
		FROM TMP_EVALUARI;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;EVALUARI&apos;);
  COMMIT;
 
END;


end PKG_EVALUARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EVALUATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BE9B41255D00497F60E83A2958F469513E91ABB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EVALUATORI is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codevaluator INTO Tmp FROM EVALUATORI WHERE codevaluator = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM EVALUATORI WHERE codevaluator = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EVALUATORI FIELDS( codevaluator ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_EVALUATORI 
	(codEvaluator ,
  NUME            , 
  ORDINE           
	)
	SELECT 
codEvaluator ,
  NUME            , 
  ORDINE            
  FROM EVALUATORI WHERE codevaluator = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT codevaluator INTO RECID FROM TMP_EVALUATORI;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE EVALUATORI
    SET
     (
       NUME  , 
       ORDINE            
			)
			= 
			(SELECT
        NUME, 
        ORDINE
		FROM TMP_EVALUATORI)
    WHERE codevaluator = RECID;

ELSE  -- INSERT
    SELECT SEQ_EVALUATORI_codevaluator.NextVal INTO RecId FROM DUAL;
    INSERT INTO EVALUATORI(
     codEvaluator ,
     NUME  , 
     ORDINE
    )
    SELECT 
  	RECID   , 
     NUME  , 
     ORDINE 
		FROM TMP_EVALUATORI;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;EVALUATORI&apos;);
  COMMIT;
 
END;


end PKG_EVALUATORI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBED95B36AC78D687F924807306B8403B1D26C52</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EVIDENTAMF is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_64&apos;;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CODMIFIX INTO Tmp FROM EVIDENTAMF WHERE CODMIFIX = RecId;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RecId);

  /*SELECT B.DATACREARE, B.SUBUNITATEA, M.NRINVENTAR
  INTO ADATADOC, aCodSubunit, aDoc
  FROM BUGETMF B
       LEFT JOIN MIFIX M ON M.CODMIFIX = B.CODMIFIX
  WHERE CODBUGETMF = RecID;*/
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_EVIDENTAMF(CODMIFIX) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
aCount number;
NR NUMBER;
BEGIN
  begin
    select count(*) into aCount from evidentamf where codmifix = recid;
  exception when others then aCount := 0;
  end;

  if aCount = 0 then
    insert into evidentamf(codmifix) values(recid);
  end if;

  IF pkg_categconst.GetValConstanta(&apos;UseRezervaReev&apos;,pkg_globals.anlucru,pkg_globals.lunalucru) = &apos;1&apos; THEN

  INSERT INTO TMP_EVIDENTAMF(CODMIFIX, CODOBIECT, CODGEST, CODCENTRU, CODIOART, CODCLASIF,
                             CODPART1, CODPART2, CODPART3,
                             DENUMIRE, DATASTART, DEN_IOART, TIPAMORTIZARE, STARE, DEN_CLASIF,
                             DURATANORMATA, DURATAF, VALINTRARE, VALNETACONTA, VALNETACONTA_L, VALNETACURENTA, AMOCUMUL,
                             VALREEVAL,
                             ASIGURATOR, VALASIGURATA, NRINVENTAR, DEN_GEST, DEN_CENTRU,Umsec,Cant,PU,TIPSERIE,
                             CODNIRSTOC,DATAACHIZ,ADAOS,CONT,DIFPRET,MG,CODMIFIX1,CODSTARE,DEN_UM1,ARETVANEEX,PARITATE,
                             LASTCODNIRSTOC, LASTPU, LASTCODGEST, LASTCODIOART, SUBUNITATEA, TIPAMO, DFBLOCAT, STARECURENTA,
                             DATALASTINTR, ANLASTINTR, LUNALASTINTR, RESPONSABIL,CODNIRSER, CODSERIE)
  SELECT MFIX.CODMIFIX, OBJ.CODOBIECT, G.CODGEST, CC.CODCENTRU, IOA.CODIOART, CLS.CODCLASIF,
         EV.CODPART1, EV.CODPART2, EV.CODPART3,
         OBJ.DENUMIRE, ev.datastart, IOA.DEN_IOART,
         CASE
           WHEN MFIX1.TIPAMO = 1 THEN &apos;Liniara&apos;
           WHEN MFIX1.TIPAMO = 2 THEN &apos;Accelerata&apos;
           WHEN MFIX1.TIPAMO = 3 THEN &apos;Degresiva 1&apos;
           WHEN MFIX1.TIPAMO = 4 THEN &apos;Degresiva 2&apos;
         END,
         CASE
           WHEN MFIX1.STARE = 1 THEN &apos;In curs de amortizare&apos;
           WHEN MFIX1.STARE = 2 THEN &apos;Trecut in conservare&apos;
           WHEN MFIX1.STARE = 3 THEN &apos;Casat in luna curenta&apos;
           WHEN MFIX1.STARE = 4 THEN &apos;Vandut in luna curenta&apos;
           WHEN MFIX1.STARE = 5 THEN &apos;Imobilizare in curs&apos;
         END,
         CLS.DENUMIRE, MFIX1.DURATAN * 12, MFIX1.DURATAF, NS.Pret VALINTRARE,
         NS.Pret -
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end VALNETACONTA,
         case
           when MFIXL.STARE IN (3,4) THEN 0
           ELSE
             NSL.Pret -
             case
               when MFIXL.TIPREEVAL = 1 THEN 0
               else
                 case
                   when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIXL.STARE = 1 then
                     case
                       when MFIX1.DurataF = 0 then MFIX1.AMO
                       else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                     end
                   else MFIXL.AMO
                 end
             end
         END VALNETACONTA_L,
         NS.Pret -
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end +
         NVL(MFIX1.REZERVA,0) +
         CASE
           WHEN mfix1.DataReeval IS NULL THEN 0
           WHEN NVL(mfix1.TipReeval,0) = 0 THEN (mfix1.Pret - nvl(mfix1.amo,0)) - (mfix1.PretVechi - mfix1.AmoVechi)
           WHEN mfix1.IncludRata = 1 THEN mfix1.Pret - mfix1.PretVechi + nvl(mfix1.amo,0) + nvl(j1.valoare,0)
           ELSE mfix1.Pret - mfix1.PretVechi
         END VALNETACURENTA,
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end,
         NVL(MFIX1.REZERVA,0) +
         CASE
           WHEN mfix1.DataReeval IS NULL THEN 0
           WHEN NVL(mfix1.TipReeval,0) = 0 THEN (mfix1.Pret - nvl(mfix1.amo,0)) - (mfix1.PretVechi - mfix1.AmoVechi)
           WHEN mfix1.IncludRata = 1 THEN mfix1.Pret - mfix1.PretVechi + nvl(mfix1.amo,0) + nvl(j1.valoare,0)
           ELSE mfix1.Pret - mfix1.PretVechi
         END VALREEVAL,
         P.DEN_PART, A1.VALASIG, MFIX.NRINVENTAR, G.DEN_GEST, CC.DENUMIRE, ns.umsec,
         mfix1.cant,
         ns.pret,ns.tipserie,
         NS.CODNIRSTOC,NS.DATAACHIZ,NS.ADAOS,IOA1.CONT,IOA1.DIFPRET,IOA1.MG,MFIX1.CODMIFIX1, MFIX1.STARE, UM1.DEN_UM1,IOA1.ARETVANEEX,
         NVL(UM1.PARITATE,1) PARITATE, NS.CODNIRSTOC, NS.PRET, NIR.GEST, NS.CODIOART, G.CODSUBUNIT, MFIX1.TIPAMO, MFIX1.DFBLOCAT,
         MFIXL.STARE STARECURENTA, (SELECT MAX(DATAOPERATIE) FROM FISAMF WHERE CODMIFIX = MFIX.CODMIFIX) DATALASTINTR, MFIXL.ANSTART ANLASTINTR, MFIXL.LUNASTART LUNALASTINTR,
         RP.NUME||&apos; &apos;||RP.PRENUME, nse.codnirser, NSE.CODSERIE
  FROM evidentamf EV
    INNER JOIN MIFIX MFIX ON EV.CODMIFIX = MFIX.CODMIFIX
    INNER JOIN MIFIX1 MFIX1 ON MFIX.CODMIFIX = MFIX1.CODMIFIX AND MFIX1.ANSTART = PKG_GLOBALS.GetANLUCRU AND MFIX1.LUNASTART = PKG_GLOBALS.LUNALUCRU
    INNER JOIN MIFIX1 MFIXL ON MFIX.CODMIFIX = MFIXL.CODMIFIX
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MFIX1.CODNIRSTOC
    INNER JOIN NIRSTOC NSL ON NSL.CODNIRSTOC = MFIXL.CODNIRSTOC
    INNER JOIN MASTERMIFIX MST ON MST.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON NIR.GEST = G.CODGEST
    INNER JOIN IOART IOA ON NS.CODIOART = IOA.CODIOART
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = IOA.CODIOART AND PKG_GLOBALS.AnLunaLucru BETWEEN IOA1.ALStart AND IOA1.ALStop
    INNER JOIN NUM1 UM1 ON UM1.CODUM1 = NS.UMSEC
    LEFT JOIN jurnal1 j1 ON j1.indexlocal = mfix1.codmifix AND j1.tipdoc = 36 AND j1.icontd = 4 AND j1.icontc = 10 AND j1.an*12+j1.luna = mfix1.anstart*12+mfix1.lunastart
    LEFT JOIN MFCLASIF CLS ON CLS.CODCLASIF = MST.CODCLASIF
    LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
    LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = MFIX1.CODCENTRU
    LEFT JOIN ASIGURARI1 A1 ON A1.CODMIFIX = MFIX.CODMIFIX
    LEFT JOIN ASIGURARI A ON A.CODASIGURARE = A1.CODASIGURARE
    LEFT JOIN NPART P ON A.CODPART = P.CODPART
    LEFT JOIN NPERS RP ON RP.CODPERS = MFIX1.CODPERS
    LEFT JOIN NIRSER NSE ON MFIX1.CODNIRSER = NSE.CODNIRSER AND NSE.CODNIRSTOC = NS.CODNIRSTOC
  WHERE EV.CODMIFIX = RECID
    AND MFIXL.ANSTART * 12 + MFIXL.LUNASTART = (SELECT MAX(MF2.ANSTART*12+MF2.LUNASTART) FROM MIFIX1 MF2 WHERE MF2.CODMIFIX = MFIX.CODMIFIX);

  else
    INSERT INTO TMP_EVIDENTAMF(CODMIFIX, CODOBIECT, CODGEST, CODCENTRU, CODIOART, CODCLASIF,
                             CODPART1, CODPART2, CODPART3,
                             DENUMIRE, DATASTART, DEN_IOART, TIPAMORTIZARE, STARE, DEN_CLASIF,
                             DURATANORMATA, DURATAF, VALINTRARE, VALNETACONTA, VALNETACONTA_L, VALNETACURENTA, AMOCUMUL,
                             VALREEVAL,
                             ASIGURATOR, VALASIGURATA, NRINVENTAR, DEN_GEST, DEN_CENTRU,Umsec,Cant,PU,TIPSERIE,
                             CODNIRSTOC,DATAACHIZ,ADAOS,CONT,DIFPRET,MG,CODMIFIX1,CODSTARE,DEN_UM1,ARETVANEEX,PARITATE,
                             LASTCODNIRSTOC, LASTPU, LASTCODGEST, LASTCODIOART, SUBUNITATEA, TIPAMO, DFBLOCAT, STARECURENTA,
                             DATALASTINTR, ANLASTINTR, LUNALASTINTR, RESPONSABIL, CODNIRSER, CODSERIE)
  SELECT MFIX.CODMIFIX, OBJ.CODOBIECT, G.CODGEST, CC.CODCENTRU, IOA.CODIOART, CLS.CODCLASIF,
         EV.CODPART1, EV.CODPART2, EV.CODPART3,
         OBJ.DENUMIRE, ev.datastart, IOA.DEN_IOART,
         CASE
           WHEN MFIX1.TIPAMO = 1 THEN &apos;Liniara&apos;
           WHEN MFIX1.TIPAMO = 2 THEN &apos;Accelerata&apos;
           WHEN MFIX1.TIPAMO = 3 THEN &apos;Degresiva 1&apos;
           WHEN MFIX1.TIPAMO = 4 THEN &apos;Degresiva 2&apos;
         END,
         CASE
           WHEN MFIX1.STARE = 1 THEN &apos;In curs de amortizare&apos;
           WHEN MFIX1.STARE = 2 THEN &apos;Trecut in conservare&apos;
           WHEN MFIX1.STARE = 3 THEN &apos;Casat in luna curenta&apos;
           WHEN MFIX1.STARE = 4 THEN &apos;Vandut in luna curenta&apos;
           WHEN MFIX1.STARE = 5 THEN &apos;Imobilizare in curs&apos;
         END,
         CLS.DENUMIRE, MFIX1.DURATAN, MFIX1.DURATAF, NS.Pret VALINTRARE,
         NS.Pret -
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end VALNETACONTA,
         case
           when MFIXL.STARE IN (3,4) THEN 0
           ELSE
             NSL.Pret -
             case
               when MFIXL.TIPREEVAL = 1 THEN 0
               else
                 case
                   when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIXL.STARE = 1 then
                     case
                       when MFIX1.DurataF = 0 then MFIX1.AMO
                       else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                     end
                   else MFIXL.AMO
                 end
             end
         END VALNETACONTA_L,
         NS.Pret -
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end + NVL(MFIX1.REZERVA,0) VALNETACURENTA,
         case
           when MFIX1.TIPREEVAL = 1 THEN 0
           else
             case
               when MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then
                 case
                   when MFIX1.DurataF = 0 then MFIX1.AMO
                   else MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
                 end
               else MFIX1.AMO
             end
         end AMOCUMUL,
         NVL(MFIX1.REZERVA,0) VALREEVAL,
         P.DEN_PART, A1.VALASIG, MFIX.NRINVENTAR, G.DEN_GEST, CC.DENUMIRE, ns.umsec,
         mfix1.cant,
         ns.pret,ns.tipserie,
         NS.CODNIRSTOC,NS.DATAACHIZ,NS.ADAOS,IOA1.CONT,IOA1.DIFPRET,IOA1.MG,MFIX1.CODMIFIX1, MFIX1.STARE, UM1.DEN_UM1,IOA1.ARETVANEEX,
         NVL(UM1.PARITATE,1) PARITATE, NS.CODNIRSTOC, NS.PRET, NIR.GEST, NS.CODIOART, G.CODSUBUNIT, MFIX1.TIPAMO, MFIX1.DFBLOCAT,
         MFIXL.STARE STARECURENTA, (SELECT MAX(DATAOPERATIE) FROM FISAMF WHERE CODMIFIX = MFIX.CODMIFIX) DATALASTINTR, MFIXL.ANSTART ANLASTINTR, MFIXL.LUNASTART LUNALASTINTR,
         RP.NUME||&apos; &apos;||RP.PRENUME, NSE.CODNIRSER, NSE.CODSERIE
  FROM evidentamf EV
    INNER JOIN MIFIX MFIX ON EV.CODMIFIX = MFIX.CODMIFIX
    INNER JOIN MIFIX1 MFIX1 ON MFIX.CODMIFIX = MFIX1.CODMIFIX AND MFIX1.ANSTART = PKG_GLOBALS.GetANLUCRU AND MFIX1.LUNASTART = PKG_GLOBALS.LUNALUCRU
    INNER JOIN MIFIX1 MFIXL ON MFIX.CODMIFIX = MFIXL.CODMIFIX
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MFIX1.CODNIRSTOC
    INNER JOIN NIRSTOC NSL ON NSL.CODNIRSTOC = MFIXL.CODNIRSTOC
    INNER JOIN MASTERMIFIX MST ON MST.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON NIR.GEST = G.CODGEST
    INNER JOIN IOART IOA ON NS.CODIOART = IOA.CODIOART
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = IOA.CODIOART AND PKG_GLOBALS.AnLunaLucru BETWEEN IOA1.ALStart AND IOA1.ALStop
    INNER JOIN NUM1 UM1 ON UM1.CODUM1 = NS.UMSEC
    LEFT JOIN MFCLASIF CLS ON CLS.CODCLASIF = MST.CODCLASIF
    LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
    LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = MFIX1.CODCENTRU
    LEFT JOIN ASIGURARI1 A1 ON A1.CODMIFIX = MFIX.CODMIFIX
    LEFT JOIN ASIGURARI A ON A.CODASIGURARE = A1.CODASIGURARE
    LEFT JOIN NPART P ON A.CODPART = P.CODPART
    LEFT JOIN NPERS RP ON RP.CODPERS = MFIX1.CODPERS
    LEFT JOIN NIRSER NSE ON MFIX1.CODNIRSER = NSE.CODNIRSER AND NSE.CODNIRSTOC = NS.CODNIRSTOC
  WHERE EV.CODMIFIX = RECID
    AND MFIXL.ANSTART * 12 + MFIXL.LUNASTART = (SELECT MAX(MF2.ANSTART*12+MF2.LUNASTART) FROM MIFIX1 MF2 WHERE MF2.CODMIFIX = MFIX.CODMIFIX);
  end if;

  insert into tmp_mifix1(codmifix1,codmifix,codnirstoc,pret,cant,codclasif,tipamo,stare,duratan,gradu,durataf,amo,neutil,
                         dfblocat,codpers,anstart,lunastart,codnirser,tipreeval,datareeval,includrata,amovechi,pretvechi,
                         neutilvechi,codpart,codlocatie,codanalizanod,codcentru,duratanf,durataff,amof,duratang,duratafg,
                         amog,dfblocat_f,dfblocat_g,pretinitial,rezerva,rezervablocat,codsablon,amoblocat,centrublocat,
                         codclasifblocat,codpersblocat,nodanalizablocat,codauto,amorezerva,amorblocat,amofblocat,amogblocat
                        )
  select codmifix1,codmifix,codnirstoc,pret,cant,codclasif,tipamo,stare,duratan,gradu,durataf,amo,neutil,
         dfblocat,codpers,anstart,lunastart,codnirser,tipreeval,datareeval,includrata,amovechi,pretvechi,
         neutilvechi,codpart,codlocatie,codanalizanod,codcentru,duratanf,durataff,amof,duratang,duratafg,
         amog,dfblocat_f,dfblocat_g,pretinitial,rezerva,rezervablocat,codsablon,amoblocat,centrublocat,
         codclasifblocat,codpersblocat,nodanalizablocat,codauto,amorezerva,amorblocat,amofblocat,amogblocat
  from mifix1 mf1
  where exists (select ev.codmifix1 from tmp_evidentamf ev where ev.codmifix1 = mf1.codmifix1);

  insert into tmp_mastermifix(
    CODNIRSTOC,
    CODCLASIF,
    DURATAN,
    DURATANF,
    DURATANG,
    CODANALIZA,
    CODCLASIFBLOCAT
  )
  select
    CODNIRSTOC,
    CODCLASIF,
    DURATAN,
    DURATANF,
    DURATANG,
    CODANALIZA,
    CODCLASIFBLOCAT
  from mastermifix mm
  where exists (select tmp.codnirstoc from tmp_mifix1 tmp where tmp.codnirstoc = mm.codnirstoc);

  INSERT INTO
    TMP_MIFIX
    (CODMIFIX,
     TIP,
     NRINVENTAR,
     ANINTRARE,
     LUNAINTRARE,
     CODMIFIX1,
     CODNIRSTOC,
     PRET,
     CANT,
     CODCLASIF,
     TIPAMO,
     STARE,
     DURATAN,
     GRADU,
     DURATAF,
     AMO,
     NEUTIL,
     DFBLOCAT,
     CODPERS,
     CODNIRSER,
     ANSTART,
     LUNASTART,
     CODIOART,
     CODGEST,
     SERIE,
     TIPREEVAL,
     DATAREEVAL,
     INCLUDRATA,
     AMOVECHI,
     PRETVECHI,
     NEUTILVECHI,
     SUBUNITATEA,
     DENUMIRE,
     CODPART,
     CODLOCATIE,
     CODAnalizaNod, CODSablon, CODCENTRU,
     OBS,
     DURATANF,
     DURATAFF,
     AMOF,
     DURATANG,
     DURATAFG,
     AMOG,
     ANINTRAREG,
     LUNAINTRAREG,
     DFBlocat_F,
     DFBlocat_G,
     REZERVA,
     REZERVABLOCAT,
     SERIEINV,
     AMOBLOCAT,
     CODMIFIXIMB,
     CENTRUBLOCAT,
     CODCLASIFBLOCAT,
     CODPERSBLOCAT,
     NODANALIZABLOCAT,
     CODAUTO,
     AMOREZERVA,
     AMORBLOCAT,
     AMOFBLOCAT,
     AMOGBLOCAT,
     PRETINITIAL,
     CODLOCATIESTOC
     )

   SELECT * FROM
   (
     (SELECT
        MF. CODMIFIX,
        MF.TIP,
        NRINVENTAR,
        ANINTRARE,
        LUNAINTRARE,
        MF1.CODMIFIX1,
        MF1.CODNIRSTOC,
        MF1.PRET,
        MF1.CANT,
        MF1.CODCLASIF,
        MF1.TIPAMO,
        MF1.STARE,
        MF1.DURATAN,
        MF1.GRADU,
        MF1.DURATAF,
        MF1.AMO,
        MF1.NEUTIL,
        MF1.DFBLOCAT,
        MF1.CODPERS,
        MF1.CODNIRSER,
        MF1.ANSTART,
        MF1.LUNASTART,
        NS.CODIOART,
        N.GEST,
        SER.SERIE,
        MF1.TIPREEVAL,
        MF1.DATAREEVAL,
        MF1.INCLUDRATA,
        MF1.AMOVECHI,
        MF1.PRETVECHI,
        MF1.NEUTILVECHI,
        G.CODSUBUNIT,
        O.DENUMIRE,
        MF1.CODPART,
        MF1.CODLOCATIE,
        MF1.CODAnalizaNod, MF1.CODSablon, MF1.CODCENTRU,
        MF.OBS,
        MF1.DURATANF,
        MF1.DURATAFF,
        MF1.AMOF,
        MF1.DURATANG,
        MF1.DURATAFG,
        MF1.AMOG,
        MF.ANINTRAREG,
        MF.LUNAINTRAREG,
        MF1.DFBLOCAT_F,
        MF1.DFBLOCAT_G,
        MF1.REZERVA,
        MF1.REZERVABLOCAT,
        MF.SERIEINV,
        MF1.AMOBLOCAT,
        MF.CODMIFIXIMB,
        MF1.CENTRUBLOCAT,
        MF1.CODCLASIFBLOCAT,
        MF1.CODPERSBLOCAT,
        MF1.NODANALIZABLOCAT,
        MF1.CODAUTO,
        MF1.AMOREZERVA,
        MF1.AMORBLOCAT,
        MF1.AMOFBLOCAT,
        MF1.AMOGBLOCAT,
        MF1.PRETINITIAL,
        NS.CODLOCATIE CODLOCATIESTOC
      FROM
        MIFIX MF,
        MIFIX1 MF1
        INNER JOIN TMP_MIFIX1 TMP ON TMP.CODMIFIX1 = MF1.CODMIFIX1
        LEFT OUTER JOIN NIRSTOC NS   ON NS.CODNIRSTOC  = MF1.CODNIRSTOC
        LEFT OUTER JOIN NIR     N    ON N.CODNIR       = NS.CODNIR
        LEFT OUTER JOIN NGEST   G    ON G.CODGEST      = N.GEST
        LEFT OUTER JOIN NIRSER  NSER ON NSER.CODNIRSER = MF1.CODNIRSER
        LEFT OUTER JOIN NSERII  SER  ON SER.CODSERIE   = NSER.CODSERIE,
        NARTOBJ O
      WHERE
        MF.CODMIFIX = MF1.CODMIFIX
        AND O.CODOBIECT = NS.CODOBIECT
      )
    ORDER BY NRINVENTAR
    );

   UPDATE TMP_MIFIX M
   SET
    CODTMPMIFIX = ROWNUM,
    DENLOCATIE  = (SELECT OBS FROM NAGENDA WHERE CODAGENDA = M.CODLOCATIE),
    INFOMFIMB   = PKG_MIFIX.GetINFOMFIMB(M.CODMIFIXIMB);

   SELECT COUNT(*) INTO NR FROM TMP_MASTERMIFIX WHERE CODCLASIF IS NOT NULL;
   IF NR = 0 THEN
     UPDATE TMP_MASTERMIFIX TMP SET CODCLASIF = (SELECT MIN(M.CODCLASIF) FROM TMP_MIFIX M WHERE M.CODNIRSTOC = TMP.CODNIRSTOC);
   END IF;

   SELECT COUNT(*) INTO NR FROM TMP_MASTERMIFIX WHERE DURATAN IS NOT NULL;
   IF NR = 0 THEN
     UPDATE TMP_MASTERMIFIX TMP
     SET
     (DURATAN, DURATANF, DURATANG) = (SELECT MIN(M.DURATAN), MIN(M.DURATANF), MIN(M.DURATANG) FROM TMP_MIFIX M WHERE M.CODNIRSTOC = TMP.CODNIRSTOC);
   END IF;

   UPDATE TMP_MASTERMIFIX TMP
   SET
   CODCLASIFBLOCAT = (SELECT MIN(NVL(M.CODCLASIFBLOCAT, 0)) FROM TMP_MIFIX M WHERE M.CODNIRSTOC = TMP.CODNIRSTOC);

  UPDATE TMP_EVIDENTAMF SET
  VALINTRARE = 0
  WHERE VALINTRARE IS NULL;

  UPDATE TMP_EVIDENTAMF SET
  AMOCUMUL = 0
  WHERE AMOCUMUL IS NULL;

  UPDATE TMP_EVIDENTAMF SET
  VALNETACONTA = 0
  WHERE VALNETACONTA IS NULL;

  UPDATE TMP_EVIDENTAMF SET
  VALREEVAL = 0
  WHERE VALREEVAL IS NULL;

  UPDATE TMP_EVIDENTAMF SET
  VALNETACURENTA = 0
  WHERE VALNETACURENTA IS NULL;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);
BEGIN
  SELECT E.DATASTART, E.SUBUNITATEA, E.NRINVENTAR
  INTO ADATADOC, aCodSubunit, aDoc
  FROM TMP_EVIDENTAMF E;

  IF Operation = 0 THEN  -- UPDATE
    SELECT CODMIFIX INTO RecId FROM TMP_EVIDENTAMF;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;EVIDENTAMF&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE EVIDENTAMF SET (CODPART1, CODPART2, CODPART3, DATASTART) =
    (SELECT CODPART1, CODPART2, CODPART3, DATASTART FROM TMP_EVIDENTAMF)
    WHERE CODMIFIX = RecId;

    for v_rec in (select mfix1.codmifix1, mfix1.dfblocat old_dfblocat, tmp.dfblocat, tmp.durataf
                  from tmp_evidentamf tmp
                       inner join mifix1 mfix1 on tmp.codmifix1 = mfix1.codmifix1
                 ) loop
      if v_rec.old_dfblocat &lt;&gt; v_rec.dfblocat and v_rec.dfblocat = 1 then
        update mifix1 set dfblocat = v_rec.dfblocat, durataf = v_rec.durataf where codmifix1 = v_rec.codmifix1;
      end if;
    end loop;
  ELSE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;EVIDENTAMF&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE EVIDENTAMF SET (CODPART1, CODPART2, CODPART3, DATASTART) =
    (SELECT CODPART1, CODPART2, CODPART3, DATASTART FROM TMP_EVIDENTAMF)
    WHERE CODMIFIX = RecId;

    for v_rec in (select mfix1.codmifix1, mfix1.dfblocat old_dfblocat, tmp.dfblocat, tmp.durataf
                  from tmp_evidentamf tmp
                       inner join mifix1 mfix1 on tmp.codmifix1 = mfix1.codmifix1
                 ) loop
      if v_rec.old_dfblocat &lt;&gt; v_rec.dfblocat and v_rec.dfblocat = 1 then
        update mifix1 set dfblocat = v_rec.dfblocat, durataf = v_rec.durataf where codmifix1 = v_rec.codmifix1;
      end if;
    end loop;
  END IF;
  COMMIT;
END;

PROCEDURE SOLVE_MIFIX(aCODTRANSF IN NUMBER, aCODMIFIX IN NUMBER)
IS
  NR NUMBER(10) := 0;
BEGIN
  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       CODNIRSTOCPARINTE,
       PRET,
       REST,
       AN,
       LUNA
      FROM
        NIRSTOC NS,
        NIR N,
        TRANSF T
      WHERE
        N.CODTRANSF = aCODTRANSF
        AND NS.CODNIR = N.CODNIR
        AND T.CODTRANSF = N.CODTRANSF
     )
  LOOP
    SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    IF NR = 0 THEN
      INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA)
      SELECT V_REC.CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA
      FROM MASTERMIFIX
      WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE;
    ELSE
      UPDATE MASTERMIFIX SET
      (CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA)
      = (SELECT CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE)
      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;
    UPDATE MIFIX1 SET CODNIRSTOC = V_REC.CODNIRSTOC
    WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE and CODMIFIX = aCodMifix
          AND ANSTART * 12 + LUNASTART &gt;= V_REC.AN * 12 + V_REC.LUNA;
  END LOOP;
  COMMIT;
END;

end PKG_EVIDENTAMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>214EACA1C6CC6520B0191C9A28D7A6E9659BD030</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_expert IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_79&apos;;

PROCEDURE DEL_FaraLegatura IS
BEGIN
  for X in 
    (
    select e.CodExpert 
    from Expert e 
    inner join (
      Select CodIes CodDoc, TipDoc from Iesiri where Coalesce(Operat,0) = 0
      union all
      Select CodIntr CodDoc, TipDoc from Intrari where Coalesce(Operat,0) = 0
      union all
      Select CodTransf CodDoc, TipDoc from Transf where Coalesce(Operat,0) = 0) Neop on e.CodDoc = Neop.CodDoc and e.tipdoc = Neop.TipDoc
    ) 
  loop	
    delete from Expert  E   where X.CodExpert  = E.CodExpert;
    delete from Expert1 E  where X.CodExpert   = E.CodExpert;
	end loop;

  for X in (select * from v_expertdefecte where AreJurn = 0)
  loop  
    for Y in 
      ( select E1.CodExpert1, E1.CodExpert
        from Expert1 e1, Expert e  
        WHERE E.CodExpert= X.CodExpert and E1.CodExpert = E.CodExpert
        and E1.INDEXJURN = X.INDEXLOCAL and  E1.GESTJURN = X.GEST and  E1.SUBUNITJURN = X.SUBUNITATEA and  E1.CONTD= X.CONTD 
        and E1.CONTC= X.CONTC and  E1.CODCENTRU= X.CODCENTRU and  E1.ANALIZANODJURN = X.CODANALIZANOD)
    loop
      delete from Expert1 E1 where Y.CodExpert1 = E1.CodExpert1;
    end loop;
	end loop;

  for X in 
		(
		select e.CodExpert 
		from Expert e 
		left join (select distinct CodExpert from expert1) e1 on e1.CodExpert = e.CodExpert
		where e1.CodExpert is null
		)
  loop	
    delete from Expert E  where X.CodExpert  = E.CodExpert;
	end loop;

  for X in 
		(
		select e1.CodExpert1 
		from Expert1 e1 
		left join (select CodExpert from expert) e on e.CodExpert = e1.CodExpert
		where e.CodExpert is null
		)
  loop	
    delete from Expert1 E1  where X.CodExpert1  = E1.CodExpert1;
	end loop;

  commit;
END;

PROCEDURE DEL_Defecte IS
BEGIN
  for X in (select * from v_expertdefecte where AreExp = 1 and DifJurn = 1)
  loop	
		for Y in 
			( select E1.CodExpert1, E1.CodExpert
			  from Expert1 e1, Expert e  
			  WHERE E.CodExpert= X.CodExpert and E1.CodExpert = E.CodExpert
			  and E1.INDEXJURN = X.INDEXLOCAL and  E1.GESTJURN = X.GEST and  E1.SUBUNITJURN = X.SUBUNITATEA and  E1.CONTD= X.CONTD 
				and E1.CONTC= X.CONTC and  E1.CODCENTRU= X.CODCENTRU and  E1.ANALIZANODJURN = X.CODANALIZANOD)
		loop
      delete from Expert1 E1 where Y.CodExpert1 = E1.CodExpert1;
		end loop;
	end loop;

  for X in 
		(
		select e.CodExpert 
		from Expert e 
		left join (select distinct CodExpert from expert1) e1 on e1.CodExpert = e.CodExpert
		where e1.CodExpert is null
		)
  loop	
    delete from Expert E  where X.CodExpert  = E.CodExpert;
	end loop;

  for X in 
		(
		select e1.CodExpert1 
		from Expert1 e1 
		left join (select CodExpert from expert) e on e.CodExpert = e1.CodExpert
		where e.CodExpert is null
		)
  loop	
    delete from Expert1 E1  where X.CodExpert1  = E1.CodExpert1;
	end loop;

  commit;
END;

PROCEDURE SETCODANALIZA(aCODANALIZA IN NUMBER)
IS
BEGIN
  CODANALIZA := aCODANALIZA;
END;

FUNCTION GETCODANALIZA RETURN NUMBER
IS
BEGIN
  RETURN CODANALIZA;
END;

PROCEDURE SETTIPANALIZA(aTIPANALIZA IN NUMBER)
IS
BEGIN
  TIPANALIZA := aTIPANALIZA;
END;

FUNCTION GETTIPANALIZA RETURN NUMBER
IS
BEGIN
  RETURN TIPANALIZA;
END;

FUNCTION  GET_DEN_NOD (aCODNOD IN NUMBER) RETURN VARCHAR2
IS
 aDEN VARCHAR2(200) := &apos;&apos;;
BEGIN
  BEGIN
   SELECT CALEA into aDen
   FROM ( SELECT X.CODANALIZANOD,
                 SYS_CONNECT_BY_PATH(X.VALOARE,&apos;»&apos;) CALEA
          FROM  ( SELECT AN.CODANALIZANOD,AN.NODPARINTE,D1.VALOARE
                  FROM ANALIZANOD AN  LEFT JOIN
                       DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
                 )X
          START WITH X.NODPARINTE = 0
          CONNECT BY PRIOR X.CODANALIZANOD = X.NODPARINTE
        ) WHERE CODANALIZANOD = aCODNOD;

    EXCEPTION WHEN OTHERS THEN aDEN := &apos;????&apos;;
  END;
  RETURN aDEN;
END;

FUNCTION  GET_DEN_DOC (CODDOC IN NUMBER, TIPDOC IN NUMBER, INDEXLOCAL IN NUMBER) RETURN VARCHAR2
IS
 aDEN VARCHAR2(200) := &apos;fara document&apos;;
BEGIN
   If TIPDOC in (1, 2, 3, 4, 5, 6, 7, 9) THEN Select x.PrefixDoc ||&apos;.&apos;|| x.SERIADOC || x.NrDoc || &apos; / &apos; || x.DataDoc into aDen from Intrari x where x.CODIntr = CodDoc; END IF;
   If TIPDOC in (8, 18, 94) THEN Select x.PrefixDoc ||&apos;.&apos;|| x.SERIADOC || x.NrDoc || &apos; / &apos; || x.DataDoc into aDen from Comanda x where x.CODComanda = CodDoc; END IF;
   If TIPDOC in (12, 13) THEN Select x.PrefixDoc ||&apos;.&apos;|| x.NrDoc || &apos; / &apos; || x.DataDoc  into aDen from Transf x where x.CODTransf = CodDoc; END IF;
   If TIPDOC in (14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 26) THEN Select x.PrefixDoc ||&apos;.&apos;|| x.SERIADOC || x.NrDoc || &apos; / &apos; || x.DataDoc  into aDen from Iesiri x where x.CODIes = CodDoc; END IF;
   If TIPDOC = 28 THEN Select &apos;PV&apos; || x.NrDoc  || &apos; / &apos; || x.DataDoc into aDen from Compens x where x.CODCOMPENS = CodDoc; END IF;
   If TIPDOC in (29, 30, 31, 33) THEN Select x.Doc ||&apos;.&apos;|| x.NrDoc || &apos; / &apos; || x.DataDoc  into aDen from Trezor1 x where x.CODTrezor1 = IndexLocal; END IF;
   If TIPDOC = 35 THEN Select &apos;NC&apos; || x.NrDoc || &apos; / &apos; || x.DataDoc  into aDen from NC x where x.CODNC = CodDoc; END IF;
   If TIPDOC in (10, 27) THEN Select x.SERIADOC || x.NrDoc || &apos; / &apos; || x.DataDoc into aDen from CONTRACT x where x.CODContract = CodDoc; END IF;
   If TIPDOC = 36 THEN aDen := &apos;Nifix&apos; ; End if;
   If TIPDOC = 37 THEN aDen := &apos;Sal&apos;; End if;
   If TIPDOC = 45 THEN aDen := &apos;RegularBank&apos;; End if;
   If TIPDOC = 46 THEN aDen := &apos;RegularPart&apos;; End if;
   If TIPDOC = 47 THEN aDen := &apos;RegularPers&apos;; End if;
   If TIPDOC = 52 THEN aDen := &apos;CheltuieliInAvans&apos;; End if;
   RETURN aDEN;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodEXPERT INTO Tmp FROM EXPERT WHERE CodEXPERT = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc varchar2(250);
BEGIN
  SP_LOCKRECORD(RecId);
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Expert &quot;&apos;||codexpert||&apos;&quot;&apos; INTO aDoc FROM Expert WHERE codexpert = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;Expert&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE FROM EXPERT1 WHERE CodEXPERT = RecId;
  DELETE FROM EXPERT  WHERE CodEXPERT = RecId;
  NotifyModif(2, RecId, &apos;EXPERT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_EXPERT FIELDS( CodEXPERT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aDate   date;
aCodDoc Number(20);
aTipDoc Number(3);
aAn     Number(4);
aLuna   Number(2);
Nr      Number;
AnLunaExpertizare number(20);

BEGIN
    INSERT INTO TMP_EXPERT (
                              CODEXPERT   ,
                              CODDOC      ,
                              TIPDOC      ,
                              AN          ,
                              LUNA        ,
                              SUBUNITATEA ,
                              USERID      ,
                              DATACREARE  ,
                              CodAnaliza  ,
                              CodAnalizaNod ,
                              DenDoc      ,
                              DIRTY
                            )
                     ( select
                              E.CODEXPERT   ,
                              E.CODDOC      ,
                              E.TIPDOC      ,
                              E.AN          ,
                              E.LUNA        ,
                              E.SUBUNITATEA ,
                              E.USERID      ,
                              E.DATACREARE  ,
                              CodAnaliza    ,
                              0             ,
                              &apos;?&apos;           , --PKG_EXPERT.GET_DEN_DOC(E.CODDOC, E.TIPDOC),
                              DIRTY
                         FROM EXPERT E
                         WHERE E.CodEXPERT = RecId ) ;

  SELECT AN*12+Luna into AnLunaExpertizare FROM TMP_EXPERT;
  BEGIN
    select CODDOC, TIPDOC  into  aCODDOC, aTIPDOC FROM TMP_EXPERT WHERE CodEXPERT = RecId ;
  EXCEPTION
    WHEN OTHERS THEN aCODDOC := 0; aTIPDOC := 0;
  END;

  INSERT INTO TMP_EXPERT1 ( CODEXPERT1,
                            CODEXPERT,
                            INDEXLOCAL     ,
                            IndexJurn      ,
                            GestJurn       ,
                            SubunitJurn    ,
                            CONTD          ,
                            CONTC          ,
                            VALOARE        ,
                            VALOAREV       ,
                            TIPCONT        ,
                            CODELEMENT, CODCENTRU, ANALIZANODJURN, CODDOC, TIPDOC     ,
                            CODDESCRIPTOR1 ,
                            CODANALIZANOD  ,
                            CODANALIZA     ,
                            SimbolCont     ,
                            DenElement     ,
                            DenAnalizaNod  ,
                            Buton
                          )
                    ( select
                            E1.CODEXPERT1,
                            E1.CODEXPERT,
                            E1.INDEXLOCAL     ,
                            E1.IndexJurn      ,
                            E1.GestJurn       ,
                            E1.SubunitJurn    ,
                            E1.CONTD          ,
                            E1.CONTC          ,
                            E1.VALOARE        ,
                            E1.VALOAREV       ,
                            E1.TIPCONT        ,
                            E1.CODELEMENT, nvl(E1.CODCENTRU,0), nvl(E1.ANALIZANODJURN,0), aCODDOC, aTIPDOC     ,
                            E1.CODDESCRIPTOR1 ,
                            E1.CODANALIZANOD  ,
                            E1.CODANALIZA     ,
                            CASE WHEN E1.TIPCONT = 0 THEN CD.Simbol ELSE CC.SIMBOL END,
                            EL.Den_Element|| chr(13) ||D1.Valoare,
                            A.Den_Analiza|| chr(13) ||PKG_EXPERT.GET_DEN_NOD(E1.CODANALIZANOD),
                            &apos;=&apos;
                         FROM EXPERT1 E1
                              LEFT JOIN NCONT CD ON CD.CODCONT = E1.CONTD
                              LEFT JOIN NCONT CC ON CC.CODCONT = E1.CONTC
                              LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = E1.CODANALIZANOD
                              LEFT JOIN ANALIZA A ON AN.CODANALIZA = A.CODANALIZA
                              LEFT JOIN ELEMENTE EL ON EL.CODELEMENT = E1.CODELEMENT
                              LEFT JOIN DESCRIPTORI1 D1 ON D1.CODDescriptor1 = E1.CODDescriptor1
                         WHERE E1.CodEXPERT = RecId );
   for v_rec in (select * from Tmp_Expert1) loop
     if aTipDoc = 11 then --expert
       select Count(*) into Nr from DOCSUPLIM1 J where
              J.CODDOCSUPLIM =V_REC.CODDOC AND
              J.CODDOCSUPLIM1=V_REC.INDEXJURN;
    else
       select Count(*) into Nr from Jurnal J where
				      J.AN*12+J.Luna = AnLunaExpertizare AND
              J.CODDOC=V_REC.CODDOC AND
              J.TIPDOC=V_REC.TIPDOC AND
              J.CONTD=V_REC.CONTD AND
              J.CONTC=V_REC.CONTC AND
              J.INDEXLOCAL=V_REC.INDEXJURN AND
              J.GEST=V_REC.GESTJURN AND
              J.CODCENTRU=V_REC.CODCENTRU AND
              nvl(J.CODANALIZANOD,0)=nvl(V_REC.ANALIZANODJURN,0) AND
              J.SUBUNITATEA =V_REC.SUBUNITJURN;
    end if;
    if Nvl(Nr ,0) = 0 then Update TMP_Expert1 set Buton = &apos;?&apos; where CodExpert1 = v_rec.codexpert1; end if;
  end loop;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aCodEXPERT1 number(20);
aCodUser number(20);
aCodSubunit number(20);
aCodAnaliza number(20);
aCodExpert number(20);
aDataDoc date;
AnLunaExpertizare number(20);
aDoc varchar2(200);
BEGIN
  SELECT AN*12+Luna into AnLunaExpertizare FROM TMP_EXPERT;
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodEXPERT  INTO RecId FROM TMP_EXPERT;
    SELECT CodANALIZA INTO aCODANALIZA FROM TMP_EXPERT;
    
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Expert &quot;&apos;||codexpert||&apos;&quot;&apos; INTO aDoc FROM Expert WHERE codexpert = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Expert&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE EXPERT SET DIRTY = 0, CodAnaliza = aCodAnaliza where codEXPERT = RecId;

    select NVL(USERID, 0) into aCodUser from EXPERT where CodEXPERT = RecId;

    if aCodUser = 0 then
      update EXPERT set
        USERID     = pkg_globals.USERID,
        DATACREARE = systimestamp
      where codEXPERT = RecId;
    end if;


    DELETE FROM EXPERT1 where CodEXPERT = RecId and CodEXPERT1 not in (Select CodEXPERT1 from TMP_EXPERT1);
    FOR v_rec IN ( SELECT * FROM TMP_EXPERT1 ) LOOP
      if v_Rec.CodEXPERT1 &gt; 0 then
       UPDATE EXPERT1
       SET
          INDEXLOCAL     = v_rec.INDEXLOCAL     ,
          IndexJurn      = v_Rec.IndexJurn      ,
          GestJurn       = v_rec.GestJurn       ,
          SubunitJurn    = v_rec.SubunitJurn    ,
          CONTD          = v_Rec.CONTD          ,
          CONTC          = v_rec.CONTC          ,
          VALOARE        = v_rec.VALOARE        ,
          VALOAREV       = v_Rec.VALOAREV       ,
          TIPCONT        = v_rec.TIPCONT        ,
          CODELEMENT     = v_rec.CODELEMENT     ,
          CODCENTRU      = v_rec.CODCENTRU,
          ANALIZANODJURN = v_rec.ANALIZANODJURN      ,
          CODDESCRIPTOR1 = v_rec.CODDESCRIPTOR1 ,
          CODANALIZA     = v_Rec.CODANALIZA     ,
          CODANALIZANOD  = v_Rec.CODANALIZANOD
       WHERE CodEXPERT1  = v_rec.CodEXPERT1;
      else
        select seq_EXPERT1_codEXPERT1.nextval into aCodEXPERT1 from dual;

        insert into EXPERT1
           (
            CODEXPERT1      ,
            CODEXPERT       ,
            INDEXLOCAL      ,
            IndexJurn       ,
            GestJurn        ,
            SubunitJurn     ,
            CONTD           ,
            CONTC           ,
            VALOARE         ,
            VALOAREV        ,
            TIPCONT         ,
            CODELEMENT, CODCENTRU, ANALIZANODJURN,
            CODDESCRIPTOR1  ,
            CODANALIZA      ,
            CODANALIZANOD
           )
        values
           (
            aCodEXPERT1           ,
            RecId                 ,
            v_rec.INDEXLOCAL      ,
            v_Rec.IndexJurn      ,
            v_rec.GestJurn       ,
            v_rec.SubunitJurn    ,
            v_Rec.CONTD          ,
            v_rec.CONTC          ,
            v_rec.VALOARE        ,
            v_Rec.VALOAREV       ,
            v_rec.TIPCONT        ,
            v_Rec.CODELEMENT     ,
            v_rec.CODCENTRU      ,
            v_rec.ANALIZANODJURN ,
            v_rec.CODDESCRIPTOR1  ,
            v_Rec.CODANALIZA     ,
            v_Rec.CODANALIZANOD
           );
      end if;
    END LOOP;

  ELSE
    Select Count(*) into RecID from Tmp_Expert1;
    if RecID = 0 then
      SELECT Seq_EXPERT_CodEXPERT.NextVal INTO RecId FROM DUAL;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      aDoc := &apos;Expert &quot;&apos;||RecId||&apos;&quot;&apos;;
			WINMADMIN.PKG_USERFIRME.PostLog(&apos;Expert&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, &apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
      INSERT INTO  EXPERT
        (
          CODEXPERT   ,
          CODDOC      ,
          TIPDOC      ,
          AN          ,
          LUNA        ,
          SUBUNITATEA ,
          CODANALIZA  ,
          USERID      , DATACREARE  ,    DIRTY
        )
      SELECT
          RecId        ,
          CODDOC,
          TIPDOC,
          AN           ,
          LUNA         ,
          SUBUNITATEA  ,
          CODANALIZA   ,
          pkg_globals.USERID,  systimestamp,   0 -- not Dirty
      FROM TMP_EXPERT;
    end if;
    for v_Docs in (select distinct CodDoc, TipDoc, CODANALIZA from Tmp_Expert1) loop
      BEGIN
        select CodExpert into RecId 
				FROM EXPERT 
				WHERE 
				AN*12+Luna = AnLunaExpertizare
				AND CODDOC = V_Docs.CodDoc 
				AND TIPDOC = V_Docs.TIPDOC 
				and CODANALIZA = v_Docs.CODANALIZA;
      EXCEPTION
        WHEN OTHERS THEN RecID := 0;
      END;
      aCodExpert := RecId;
      if RecID = 0 then
        SELECT Seq_EXPERT_CodEXPERT.NextVal INTO RecId FROM DUAL;

        INSERT INTO  EXPERT
          (
            CODEXPERT   ,
            CODDOC      ,
            TIPDOC      ,
            AN          ,
            LUNA        ,
            SUBUNITATEA ,
            CODANALIZA  ,
            USERID      , DATACREARE  ,    DIRTY
          )
        SELECT
            RecId        ,
            v_Docs.CODDOC,
            v_Docs.TIPDOC,
            AN           ,
            LUNA         ,
            SUBUNITATEA  ,
            V_Docs.CODANALIZA   ,
            pkg_globals.USERID,  systimestamp,   0 -- not Dirty
        FROM TMP_EXPERT;
      end if;


      insert into EXPERT1
         (
          CODEXPERT1      ,
          CODEXPERT       ,
          INDEXLOCAL      ,
          IndexJurn       ,
          GestJurn        ,
          SubunitJurn     ,
          CONTD           ,
          CONTC           ,
          VALOARE         ,
          VALOAREV        ,
          TIPCONT         ,
          CODELEMENT, CODCENTRU, ANALIZANODJURN,
          CODDESCRIPTOR1  ,
          CODANALIZA      ,
          CODANALIZANOD
         )
      SELECT

          seq_EXPERT1_codEXPERT1.nextval,
          RecId                 ,
          INDEXLOCAL      ,
          IndexJurn       ,
          GestJurn        ,
          SubunitJurn     ,
          CONTD           ,
          CONTC           ,
          VALOARE         ,
          VALOAREV        ,
          TIPCONT         ,
          CODELEMENT, CODCENTRU, ANALIZANODJURN,
          CODDESCRIPTOR1  ,
          CODANALIZA      ,
          CODANALIZANOD
          FROM TMP_EXPERT1 WHERE CODDOC = V_Docs.CodDoc AND TIPDOC = V_Docs.TIPDOC;
    end loop;
  END IF;
  NotifyModif(Operation, RecId, &apos;EXPERT&apos;);
  COMMIT;
END;

end pkg_EXPERT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EXPORTEDI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B316A3BE214A2A899FF5079B1A508FA895B8ED56</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EXPORTEDI IS

  vExpEdiCodIes         NUMBER(20);
  vDocXChangeDocType    NUMBER(1);
  vTecNetDocType        NUMBER(1);
  vTecNetRefNumber      VARCHAR2(255);
  vTecNetRefDate        VARCHAR2(10);
  vEdiNetDocType        NUMBER(1);
  vEdiNetRefNumber      VARCHAR2(255);
  vEdiNetRefDate        DATE;
  vEdiNetRetAnnNumber   VARCHAR2(255);
  vEdiNetRetAnnDate     DATE;
  vExpSupDocType        NUMBER(1);
  vExpSupRefSerie       VARCHAR2(20);
  vExpSupRefNumber      VARCHAR2(255);
  vExpSupRefDate        VARCHAR2(10);
  vReceiveAdviceNumber  VARCHAR2(255);
  vReceiveAdviceDate    VARCHAR2(10);

  vOrderNumber          VARCHAR2(255);
  vOrderDate            VARCHAR2(25);
  vDespatchNumber       VARCHAR2(255);
  vDespatchDate         VARCHAR2(10);
  vBillingRef           VARCHAR2(50);
  vBillingRefDate       VARCHAR2(10);

  pModAplicProcDisc     NUMBER;

FUNCTION  GetIDLaClient(pPartTip NUMBER, pCodIes NUMBER) RETURN VARCHAR2 IS
  vCnt    NUMBER  := 0;
  vResult VARCHAR2(100);
BEGIN
  IF pPartTip IN (4, 5) THEN
    SELECT Count(1), Max(idspecific)
    INTO vCnt, vResult
    FROM (
      SELECT DISTINCT ac.idspecific
      FROM (
        SELECT PKG_LIST_BASE_UTILS.GetCodArtCli(i1.codobiect, i.partener, p.codclasa) codartcli
        FROM iesiri i
          INNER JOIN npart   p  ON p.codpart = i.partener
          INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        WHERE i.codies = pCodIes
      ) s1 INNER JOIN nartcli ac ON ac.codartcli = s1.codartcli
    ) s2;
  END IF;

  IF vCnt &lt;&gt; 1
  THEN vResult := &apos;&apos;;
  END IF;

  RETURN vResult;
END;

FUNCTION  GetGLNLaClient(pPartTip NUMBER, pCodIes NUMBER) RETURN VARCHAR2 IS
  vCnt    NUMBER  := 0;
  vResult VARCHAR2(100);
BEGIN
  IF pPartTip IN (5) THEN
    SELECT Count(1), Max(gln)
    INTO vCnt, vResult
    FROM (
      SELECT DISTINCT ac.gln
      FROM (
        SELECT PKG_LIST_BASE_UTILS.GetCodArtCli(i1.codobiect, i.partener, p.codclasa) codartcli
        FROM iesiri i
          INNER JOIN npart   p  ON p.codpart = i.partener
          INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        WHERE i.codies = pCodIes
      ) s1 INNER JOIN nartcli ac ON ac.codartcli = s1.codartcli
    ) s2;
  END IF;

  IF vCnt &lt;&gt; 1
  THEN vResult := &apos;&apos;;
  END IF;

  RETURN vResult;
END;

PROCEDURE SetXMLDocXChangeData(
  pCodIes NUMBER, pDocType NUMBER,
  pComNumber  VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
  pAENumber   VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL,
  pBillingRef VARCHAR2 DEFAULT NULL, pBFDate  VARCHAR2 DEFAULT NULL,
  pNIRNumber  VARCHAR2 DEFAULT NULL, pNIRDate VARCHAR2 DEFAULT NULL
) IS
  sComDate VARCHAR2(10);
  sAEDate  VARCHAR2(10);
  sBFDate  VARCHAR2(10);
  sNIRDate VARCHAR2(10);
BEGIN
  vExpEdiCodIes      := pCodIes;
  IF Coalesce(pDocType, 0) &gt; 1
  THEN vDocXChangeDocType := pDocType;
  ELSE vDocXChangeDocType := 1;
  END IF;

  BEGIN
    sComDate := To_Char( To_Date ( pComDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sComDate := NULL;
  END;

  IF sComDate IS NULL OR pComNumber IS NULL THEN
    vOrderNumber := NULL;
    vOrderDate   := NULL;
  ELSE
    vOrderNumber := pComNumber;
    vOrderDate   := sComDate;
  END IF;

  BEGIN
    sAEDate := To_Char( To_Date ( pAEDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sAEDate := NULL;
  END;

  IF sAEDate IS NULL OR pAENumber IS NULL THEN
    vDespatchNumber := NULL;
    vDespatchDate   := NULL;
  ELSE
    vDespatchNumber := pAENumber;
    vDespatchDate   := sAEDate;
  END IF;

  vBillingRef := pBillingRef;
  BEGIN
    sBFDate := To_Char( To_Date ( pBFDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sBFDate := NULL;
  END;

  IF vBillingRef IS NULL THEN
    vBillingRefDate := NULL;
  ELSE
    vBillingRefDate := sBFDate;
  END IF;

  BEGIN
    sNIRDate := To_Char( To_Date ( pNIRDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sNIRDate := NULL;
  END;

  IF sNIRDate IS NULL OR pNIRNumber IS NULL THEN
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
  ELSE
    vReceiveAdviceNumber := pNirNumber;
    vReceiveAdviceDate   := sNirDate;
  END IF;
END;

PROCEDURE SetXMLDocTecNetData(
  pCodIes NUMBER, pDocType NUMBER,
  pRefNumber VARCHAR2 DEFAULT NULL, pRefDate VARCHAR2 DEFAULT NULL,
  pNirNumber VARCHAR2 DEFAULT NULL, pNirDate VARCHAR2 DEFAULT NULL,
  pComNumber VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
  pAENumber  VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL
) IS
  sNirDate VARCHAR2(10);
  sComDate VARCHAR2(10);
  sAEDate  VARCHAR2(10);
BEGIN
  vExpEdiCodIes    := pCodIes;
  vTecNetDocType   := pDocType;

  IF Coalesce(pDocType,0) &gt; 2 THEN
    vTecNetRefNumber   := pRefNumber;
    BEGIN
      vTecNetRefDate   := To_Char( To_Date ( pRefDate, &apos;dd.mm.yyyy&apos;), &apos;dd/mm/yyyy&apos;);
    EXCEPTION
      WHEN OTHERS THEN vTecNetRefDate := NULL;
    END;
  ELSE
    vTecNetRefNumber   := NULL;
    vTecNetRefDate     := NULL;
  END IF;

  BEGIN
    sNirDate := To_Char( To_Date ( pNirDate, &apos;dd.mm.yyyy&apos;) , &apos;dd/mm/yyyy&apos;);
  EXCEPTION
    WHEN OTHERS THEN sNirDate := NULL;
  END;

  IF sNirDate IS NULL OR pNirNumber IS NULL THEN
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
  ELSE
    vReceiveAdviceNumber := pNirNumber;
    vReceiveAdviceDate   := sNirDate;
  END IF;

  BEGIN
    sComDate := To_Char( To_Date ( pComDate, &apos;dd.mm.yyyy&apos;) , &apos;dd/mm/yyyy&apos;);
  EXCEPTION
    WHEN OTHERS THEN sComDate := NULL;
  END;

  IF sComDate IS NULL OR pComNumber IS NULL THEN
    vOrderNumber := NULL;
    vOrderDate   := NULL;
  ELSE
    vOrderNumber := pComNumber;
    vOrderDate   := sComDate;
  END IF;

  BEGIN
    sAEDate := To_Char( To_Date ( pAEDate, &apos;dd.mm.yyyy&apos;) , &apos;dd/mm/yyyy&apos;);
  EXCEPTION
    WHEN OTHERS THEN sAEDate := NULL;
  END;

  IF sAEDate IS NULL OR pAENumber IS NULL THEN
    vDespatchNumber := NULL;
    vDespatchDate   := NULL;
  ELSE
    vDespatchNumber := pAENumber;
    vDespatchDate   := sAEDate;
  END IF;
END;

PROCEDURE SetXMLDocEdiNetData    (
  pCodIes NUMBER, pDocType NUMBER,
  pRefNumber    VARCHAR2 DEFAULT NULL, pRefDate    VARCHAR2 DEFAULT NULL,
  pComNumber    VARCHAR2 DEFAULT NULL, pComDate    VARCHAR2 DEFAULT NULL,
  pNirNumber    VARCHAR2 DEFAULT NULL, pNirDate    VARCHAR2 DEFAULT NULL,
  pRetAnnNumber VARCHAR2 DEFAULT NULL, pRetAnnDate VARCHAR2 DEFAULT NULL
) IS
  sNirDate VARCHAR2(10);
  sComDate VARCHAR2(25);
BEGIN
  vExpEdiCodIes    := pCodIes;
  vEdiNetDocType   := pDocType;

  IF Coalesce(pDocType,0) &gt; 2 THEN
    vEdiNetRefNumber   := pRefNumber;
    IF pRefDate IS NOT NULL THEN
      vEdiNetRefDate   := To_Date ( pRefDate, &apos;dd.mm.yyyy&apos;);
    END IF;
  ELSE
    vEdiNetRefNumber   := NULL;
    vEdiNetRefDate     := NULL;
  END IF;

  BEGIN
    sNirDate := To_Char( To_Date ( pNirDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sNirDate := NULL;
  END;

  IF sNirDate IS NULL OR pNirNumber IS NULL THEN
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
  ELSE
    vReceiveAdviceNumber := pNirNumber;
    vReceiveAdviceDate   := sNirDate;
  END IF;

  BEGIN
    sComDate := To_Char( To_Date ( pComDate, &apos;dd.mm.yyyy&apos;), &apos;yyyy-mm-dd&apos;)||&apos;T00:00:00&apos;;
  EXCEPTION
    WHEN OTHERS THEN sComDate := NULL;
  END;

  IF sComDate IS NULL OR pComNumber IS NULL THEN
    vOrderNumber := NULL;
    vOrderDate   := NULL;
  ELSE
    vOrderNumber := pComNumber;
    vOrderDate   := sComDate;
  END IF;

  IF NULLIF(pRetAnnNumber, &apos;&apos;) IS NULL OR NULLIF(pRetAnnDate, &apos;&apos;) IS NULL THEN
    vEdiNetRetAnnNumber := NULL;
    vEdiNetRetAnnDate   := NULL;
  ELSE
    vEdiNetRetAnnNumber := pRetAnnNumber;
    vEdiNetRetAnnDate   := To_Date ( pRetAnnDate, &apos;dd.mm.yyyy&apos;);
  END IF;
END;

PROCEDURE SetExpertSupplierData(
  pCodIes NUMBER, pDocType NUMBER,
  pRefSerie  VARCHAR2 DEFAULT NULL,
  pRefNumber VARCHAR2 DEFAULT NULL, pRefDate VARCHAR2 DEFAULT NULL,
  pNirNumber VARCHAR2 DEFAULT NULL, pNirDate VARCHAR2 DEFAULT NULL,
  pComNumber VARCHAR2 DEFAULT NULL, pComDate VARCHAR2 DEFAULT NULL,
  pAENumber  VARCHAR2 DEFAULT NULL, pAEDate  VARCHAR2 DEFAULT NULL
) IS
  sNirDate VARCHAR2(10);
  sComDate VARCHAR2(10);
  sAEDate  VARCHAR2(10);
BEGIN
  vExpEdiCodIes    := pCodIes;
  vExpSupDocType   := pDocType;

  IF Coalesce(pDocType,0) &gt; 2 THEN
    vExpSupRefNumber  := pRefNumber;
    IF pRefDate IS NOT NULL THEN
      vExpSupRefDate  := To_Char( To_Date ( pRefDate, &apos;dd.mm.yyyy&apos;), &apos;yyyy-mm-dd&apos;);
      vExpSupRefSerie := pRefSerie;
    END IF;
  ELSE
    vExpSupRefSerie   := NULL;
    vExpSupRefNumber  := NULL;
    vExpSupRefDate    := NULL;
  END IF;

  BEGIN
    sNirDate := To_Char( To_Date ( pNirDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sNirDate := NULL;
  END;

  IF sNirDate IS NULL OR pNirNumber IS NULL THEN
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
  ELSE
    vReceiveAdviceNumber := pNirNumber;
    vReceiveAdviceDate   := sNirDate;
  END IF;

  BEGIN
    sComDate := To_Char( To_Date ( pComDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sComDate := NULL;
  END;

  IF sComDate IS NULL OR pComNumber IS NULL THEN
    vOrderNumber := NULL;
    vOrderDate   := NULL;
  ELSE
    vOrderNumber := pComNumber;
    vOrderDate   := sComDate;
  END IF;

  BEGIN
    sAEDate := To_Char( To_Date ( pAEDate, &apos;dd.mm.yyyy&apos;) , &apos;yyyy-mm-dd&apos;);
  EXCEPTION
    WHEN OTHERS THEN sAEDate := NULL;
  END;

  IF sAEDate IS NULL OR pAENumber IS NULL THEN
    vDespatchNumber := NULL;
    vDespatchDate   := NULL;
  ELSE
    vDespatchNumber := pAENumber;
    vDespatchDate   := sAEDate;
  END IF;
END;

PROCEDURE PrepFirmaAdr(pCodIes  NUMBER) IS
  vSubunitatea NUMBER(20);
  vCNT         NUMBER(10);
  vAn          NUMBER(4) := pkg_globals.ANLUCRU;
  vLuna        NUMBER(2) := pkg_globals.LUNALUCRU;
BEGIN
  IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, vAn, vLuna) = 1 THEN
    SELECT Subunitatea INTO vSubunitatea FROM iesiri        WHERE CodIes     = pCodIes;
    SELECT Count(1)    INTO vCNT         FROM TMP_FIRMA_ADR WHERE CodSubunit = vSubunitatea;
    IF vCNT &lt;&gt; 1 THEN
      DELETE FROM TMP_FIRMA_ADR;
      INSERT INTO TMP_FIRMA_ADR(
        CODSUBUNIT, DENFIRMA, CODFISCAL, NRJ, PERSFIZ,
        DENTARA, SIMBTARA, DENJUDET, SIMBJUDET, DENLOCALIT,
        CODPOSTAL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, AP, SECTOR,
        TELEFON1, TELEFON2, FAX, EMAIL,
        NUMEADMIN, PRENUMEADMIN, CAPITALS,
        CODBANKCONT)
      SELECT
        s.CodSubunit, s.den_subunit AS DENFIRMA, s.cif AS CODFISCAL, S.RegCom NRJ, 0 AS PERSFIZ,
        t.den_tara AS DENTARA, t.simbauto AS SIMBTARA, j.Den_Judet AS DENJUDET, j.SimbAuto AS SIMBJUDET, l.den_localit AS DENLOCALIT,
        a.codpostal, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart AS AP, A.SECTOR,
        a.telefon AS TELEFON1, NULL AS TELEFON2, a.fax, A.EMAIL,
        F.NUMEADMIN, F.PRENUMEADMIN, s.CAPITAL_SOCIAL AS CAPITALS,
        COALESCE(S.CODBANKCONT, CAST(pkg_categconst.GetValConstanta(&apos;BancaImplicita&apos;, vAn, vLuna) AS NUMBER)) AS CODBANKCONT
      FROM NSUBUNIT S
        LEFT JOIN NAGENDA   A   ON a.CodSubunit    = S.CodSubunit
        LEFT JOIN NLOCALIT  L   ON l.CodLocalit    = a.CodLocalit
        LEFT JOIN NJUDET    J   ON j.CodJudet      = l.CodJudet
        LEFT JOIN NTARI     T   ON t.CodTara       = l.CodTara
        CROSS JOIN TABLE(winmadmin.pkg_userfirme.FirmaAdr(pkg_globals.getcodfirma)) f
      WHERE S.CodSubunit = vSubunitatea;
    END IF;
  ELSE
    SELECT Count(1) INTO vCNT FROM TMP_FIRMA_ADR WHERE CODSUBUNIT = 1;
    IF vCNT &lt;&gt; 1 THEN
      DELETE FROM TMP_FIRMA_ADR;
      INSERT INTO TMP_FIRMA_ADR(
        CODSUBUNIT, DENFIRMA, CODFISCAL, NRJ, PERSFIZ,
        DENTARA, SIMBTARA, DENJUDET, SIMBJUDET, DENLOCALIT,
        CODPOSTAL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, AP, SECTOR,
        TELEFON1, TELEFON2, FAX, EMAIL,
        NUMEADMIN, PRENUMEADMIN, CAPITALS,
        CODBANKCONT)
      SELECT
        1 AS CODSUBUNIT, DENFIRMA, CODFISCAL, NRJ, PERSFIZ,
        DENTARA, SIMBTARA, DENJUDET, SIMBJUDET, DENLOCALIT,
        CODPOSTAL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, AP, SECTOR,
        TELEFON1, TELEFON2, FAX, EMAIL,
        NUMEADMIN, PRENUMEADMIN, CAPITALS,
        CAST(pkg_categconst.GetValConstanta(&apos;BancaImplicita&apos;, vAn, vLuna) AS NUMBER) AS CODBANKCONT
      FROM TABLE(winmadmin.pkg_userfirme.FirmaAdr(pkg_globals.getcodfirma));
    END IF;
  END IF;
END;

PROCEDURE PrepXMLDocXChange(pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) IS
  vTipDoc           NUMBER(5);
  vCodPart          NUMBER(20);
  vClasaPart        NUMBER(20);
  vIDLaClient       VARCHAR2(100);
  vGLNLaClient      VARCHAR2(100);
  vNrLinii          NUMBER(5);
  vEdiExpTip        NUMBER(5);
  fbc_NrCont        VARCHAR2(30);
  lfb_den_localit   VARCHAR2(50);
  jfb_simbauto      VARCHAR2(2);
  fb_denumire       VARCHAR2(50);
  sType             VARCHAR2(100);
  pTecNetComNRI     NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos;    ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
  pDocXChangeTipUM  NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;DocXChangeTipUM&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
  pModAplicProcDisc NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;ModAplicProcDisc&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 1) ;
BEGIN
  PrepFirmaAdr(pCodIes);
  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vDocXChangeDocType   := 1;
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
    vDespatchNumber      := NULL;
    vDespatchDate        := NULL;
    vBillingRef          := NULL;
    vBillingRefDate      := NULL;
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
  END IF;

  SELECT TipDoc,  p.codpart, p.codclasa, sliv.edi_exptip, pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies), pkg_exportedi.GetGLNLaClient(sliv.edi_parttip, i.codies)
  INTO   vTipDoc, vCodPart,  vClasaPart, vEdiExpTip,      vIDLaClient                                            , vGLNLaClient
  FROM iesiri i
    LEFT JOIN npart   p    ON p.codpart      = i.partener
    LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes
    AND Coalesce(sliv.edi_exptip,0) IN (1,4,6,7,8)
    AND Coalesce(sliv.edi_parttip,0) &gt; 0
    AND Coalesce(sliv.edi_objtip,0) &gt; 0
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;);
  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  IF vTipDoc = 20 THEN -- DESADV
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DOCXCHANGE_DESADV_H&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DOCXCHANGE_DESADV_L&apos;;

    INSERT INTO TMP_DOCXCHANGE_DESADV_L
    SELECT
      Row_Number() OVER (ORDER BY i1.indexlocal, i1.codies1)      L_ID                          ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:ID
      NULL                                                        L_UUID                        ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:UUID
      SubStr(I1.Obs,1,200)                                        L_Note                        ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:Note
      NULL                                                        L_LineStatusCode              ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:LineStatusCode
      REPLACE(
        TO_CHAR(
          I1.CANT/Coalesce(U1.PARITATE, 1),
          &apos;fm9999999990D0099&apos;
        ), &apos;,&apos;,&apos;.&apos;
      )                                                           L_DeliveredCANT               ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:DeliveredQuantity
      Substr(
        Coalesce(
          CASE
            WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
            WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
            WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
          END,U1.DEN_EANCOM,U1.Den_UM1
        ),1,3
      )                                                           L_DeliveredCANTx              ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:DeliveredQuantity@UnitCode
      NULL                                                        L_BackorderCANT               ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:BackorderQuantity
      NULL                                                        L_BackorderReason             ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:BackorderReason
      NULL                                                        L_OutstandingCANT             ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:OutstandingQuantity
      NULL                                                        L_OutstandingReason           ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:OutstandingReason
      NULL                                                        L_OversupplyCANT              ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:OversupplyQuantity
      NULL                                                        L_OversupplyReason            ,--ubl:DespatchAdvice/cac:DespatchLine/cbc:OversupplyReason
      COM1.IndexLocal                                             L_OLR_LineID                  ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cbc:LineID
      NULL                                                        L_OLR_SalesOrderLineID        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cbc:SalesOrderLineID
      NULL                                                        L_OLR_UUID                    ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cbc:UUID
      NULL                                                        L_OLR_LineStatusCode          ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cbc:LineStatusCode
      CASE
        WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
        ELSE CASE WHEN Coalesce(sliv.edi_exptip,0) = 4 AND pTecNetComNRI &lt;&gt; 1 THEN COM.SeriaDOC END||
             CASE WHEN pTecNetComNRI = 1 THEN Coalesce(LTrim(COM.NRI,&apos; 0&apos;),To_Char(COM.NrDoc)) ELSE To_Char(COM.NrDOC) END
      END                                                         L_OLR_ORD_ID                  ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cac:OrderReference/cbc:ID
      NULL                                                        L_OLR_ORD_SalesOrderID        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cac:OrderReference/cbc:SalesOrderID
      NULL                                                        L_OLR_ORD_UUID                ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cac:OrderReference/cbc:UUID
      CASE
        WHEN vOrderNumber   IS NOT NULL THEN vOrderDate
        WHEN com.codcomanda IS NOT NULL THEN To_Char(COM.DataDoc, &apos;yyyy-mm-dd&apos;)
        ELSE NULL
      END                                                         L_OLR_ORD_ID_IssueDate        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:OrderLineReference/cac:OrderReference/cbc:IssueDate
      O.Denumire                                                  L_I_Description               ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:Description
      NULL                                                        L_I_PackCANT                  ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:PackQuantity
      NULL                                                        L_I_PackSizeNumeric           ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:PackSizeNumeric
      NULL                                                        L_I_CatalogueIndicator        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:CatalogueIndicator
      NULL                                                        L_I_Name                      ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:Name
      NULL                                                        L_I_HazardousRiskIndicator    ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:HazardousRiskIndicator
      NULL                                                        L_I_AdInformation             ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:AdditionalInformation
      NULL                                                        L_I_Keyword                   ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:Keyword
      NULL                                                        L_I_BrandName                 ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:BrandName
      NULL                                                        L_I_ModelName                 ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cbc:ModelName
      CASE sliv.edi_objtip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      END                                                         L_I_II1_ID                    ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:BuyersItemIdentification/cbc:ID
      SubStr(O.CodIntern,1,20)                                    L_I_II2_ID                    ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:SellersItemIdentification/cbc:ID
      SubStr(
        CASE sliv.edi_objtip2
          WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
          WHEN 2 THEN ac.codextern
          WHEN 3 THEN o.codextern
          WHEN 4 THEN o.codintern
          WHEN 5 THEN o.codvamal
          WHEN 6 THEN To_Char(o.codplu)
          WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
          WHEN 8 THEN ac.codlaclient
          WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
          ELSE O.CodExtern
        END, 1,20)                                                L_I_II3_ID                    ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:StandardItemIdentification/cbc:ID
      NULL                                                        L_I_II_ManufactureDate        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cbc:ManufactureDate
      NULL                                                        L_I_II_ManufactureTime        ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cbc:ManufactureTime
      NULL                                                        L_I_II_BestBeforeDate         ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cbc:BestBeforeDate
      NULL                                                        L_I_II_SerialID               ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cbc:SerialID
      NULL                                                        L_I_II_LI_LotNumberID         ,--ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cac:LotIdentification/cbc:LotNumberID
      NULL                                                        L_I_II_LI_ExpiryDate           --ubl:DespatchAdvice/cac:DespatchLine/cac:Item/cac:ItemInstance/cac:LotIdentification/cbc:ExpiryDate
    FROM TMP_EDI_IES1 ti1
      LEFT JOIN iesiri i ON i.codies = ti1.codies
      LEFT JOIN npart p ON p.codpart = i.partener
      LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
      LEFT JOIN iesiri1 i1 ON i1.codies1 = ti1.codies1
      LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
      LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
      LEFT JOIN nart a ON a.codarticol = o.codarticol
      LEFT JOIN num1 ud ON ud.codum1 = i1.umsec
      LEFT JOIN num1 u1 ON u1.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN u1.codum1-ud.codum1 ELSE u1.secundara END = 0
      LEFT JOIN nartcli ac ON ac.codartcli = ti1.codartcli
      LEFT JOIN ieslink ilc ON ilc.codies1 = i1.codies1 AND ilc.codliniecomanda IS NOT NULL
      LEFT JOIN cmdlivrlink cl ON cl.codcomanda1 = ilc.codliniecomanda
      LEFT JOIN comanda1 com1 ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
      LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda
    ORDER BY i1.indexlocal, i1.codies1;

    SELECT
      count(1),
      CASE
        WHEN vOrderNumber IS NOT NULL              THEN vOrderNumber
        WHEN Max(L_OLR_ORD_ID) = Min(L_OLR_ORD_ID) THEN Min(L_OLR_ORD_ID)
        ELSE NULL
      END,
      CASE
        WHEN vOrderNumber IS NOT NULL              THEN vOrderDate
        WHEN Max(L_OLR_ORD_ID) = Min(L_OLR_ORD_ID) THEN Min(L_OLR_ORD_ID_IssueDate)
        ELSE NULL
      END
    INTO
      vNrLinii,
      vOrderNumber,
      vOrderDate
    FROM TMP_DOCXCHANGE_DESADV_L;

    IF vOrderNumber IS NOT NULL AND vEdiExpTip = 8 THEN
      UPDATE  TMP_DOCXCHANGE_DESADV_L
      SET L_OLR_ORD_ID = NULL , L_OLR_ORD_ID_IssueDate = NULL;
    END IF;

    INSERT INTO TMP_DOCXCHANGE_DESADV_H
    SELECT
      CASE
        WHEN Nullif(sliv.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
        ELSE sliv.EDI_SUBDIREXP||&apos;\&apos;
      END||
      &apos;DESADV_&apos;||I.CodIes||&apos;_VAT_&apos;||Coalesce(f.Codfiscal,&apos;0&apos;)     FileName                      ,--
      CASE
        WHEN sliv.edi_exptip = 7 THEN &apos;&apos;
        ELSE Coalesce(I.SeriaDoc, &apos;&apos;)
      END||To_Char(I.Nrdoc)                                       H_ID                          ,--ubl:DespatchAdvice/cbc:ID
      CAST(&apos;false&apos;    AS VARCHAR2(10))                            H_CopyIndicator               ,--ubl:DespatchAdvice/cbc:CopyIndicator
      NULL                                                        H_UUID                        ,--ubl:DespatchAdvice/cbc:UUID
      To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                            H_IssueDate                   ,--ubl:DespatchAdvice/cbc:IssueDate
      CAST(&apos;00:00:00&apos; AS VARCHAR2(10))                            H_IssueTime                   ,--ubl:DespatchAdvice/cbc:IssueTime
      CAST(&apos;351&apos;      AS VARCHAR2(10))                            H_DocumentStatusCode          ,--ubl:DespatchAdvice/cbc:DocumentStatusCode
      NULL                                                        H_DespatchAdviceTypeCode      ,--ubl:DespatchAdvice/cbc:DespatchAdviceTypeCode
      SubStr(I.Obs,1,200)                                         H_Note                        ,--ubl:DespatchAdvice/cbc:Note
      vNrLinii                                                    H_LineCountNumeric            ,--ubl:DespatchAdvice/cbc:LineCountNumeric
      vOrderNumber                                                H_ORD_ID                      ,--ubl:DespatchAdvice/cac:OrderReference/cbc:ID
      NULL                                                        H_ORD_SalesOrderID            ,--ubl:DespatchAdvice/cac:OrderReference/cbc:SalesOrderID
      NULL                                                        H_ORD_UUID                    ,--ubl:DespatchAdvice/cac:OrderReference/cbc:UUID
      vOrderDate                                                  H_ORD_IssueDate               ,--ubl:DespatchAdvice/cac:OrderReference/cbc:IssueDate
      CASE
        WHEN sliv.edi_parttip = 1 THEN sliv.edi_partid
        WHEN sliv.edi_parttip = 2 THEN f.codfiscal
        WHEN sliv.edi_parttip = 3 THEN sliv.gln
        ELSE                           vIDLaClient
      END                                                         H_DSP_CustAAID                ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cbc:CustomerAssignedAccountID
      ssub.gln                                                    H_DSP_P_EndpointID            ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cbc:EndpointID
      &apos;GLN&apos;                                                       H_DSP_P_EndpointIDx           ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cbc:EndpointID@schemeID
      f.codfiscal                                                 H_DSP_P_PI_ID                 ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID
      f.DenFirma                                                  H_DSP_P_PN_Name               ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyName/cbc:Name
      f.strada                                                    H_DSP_P_PA_StreetName         ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:StreetName
      CAST (
        CASE
          WHEN f.sector IS NOT NULL THEN &apos;SECTOR &apos;||f.sector
          ELSE NULL
        END AS VARCHAR2(100)
      )                                                           H_DSP_P_PA_AdStrName          ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName
      NULL                                                        H_DSP_P_PA_BuildingName       ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:BuildingName
			f.NR1||
			CASE
				WHEN Length(f.NR1||f.NR2) = 0             THEN &apos;-&apos;
				WHEN Length(f.NR1||f.NR2) &gt; Length(f.NR1) THEN &apos;-&apos;
				ELSE &apos;&apos;
			END ||
			f.NR2                                                       H_DSP_P_PA_BuildingNumber     ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber
      f.DenLocalit||
      CASE
        WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||f.simbjudet
        ELSE &apos;&apos;
      END                                                         H_DSP_P_PA_CityName           ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:CityName
      f.codpostal                                                 H_DSP_P_PA_PostalZone         ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:PostalZone
      f.denjudet                                                  H_DSP_P_PA_CountrySubentity   ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cbc:CountrySubentity
      NULL                                                        H_DSP_P_PA_AL_Line            ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line
      &apos;RO&apos;                                                        H_DSP_P_PA_C_IdCode           ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode
      NULL                                                        H_DSP_P_PTS_RegName           ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName
      NULL                                                        H_DSP_P_PTS_CompID            ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID
      NULL                                                        H_DSP_P_PTS_ExemptionReason   ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:ExemptionReason
      NULL                                                        H_DSP_P_PTS_TS_ID             ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID
      NULL                                                        H_DSP_P_PTS_TS_TaxTypeCode    ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:TaxTypeCode
      NULL                                                        H_DSP_P_C_Name                ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:Contact/cbc:Name
      NULL                                                        H_DSP_P_C_Telephone           ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:Contact/cbc:Telephone
      NULL                                                        H_DSP_P_C_Telefax             ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:Contact/cbc:Telefax
      NULL                                                        H_DSP_P_C_EMail               ,--ubl:DespatchAdvice/cac:DespatchSupplierParty/cac:Party/cac:Contact/cbc:ElectronicMail
      NULL                                                        H_DCP_CustAAID                ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cbc:CustomerAssignedAccountID
			sliv.gln                                                    H_DCP_P_EndpointID            ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cbc:EndpointID
      &apos;GLN&apos;                                                       H_DCP_P_EndpointIDx           ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cbc:EndpointID@schemeID
      pcf.codfiscal                                               H_DCP_P_PI_ID                 ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID
      p.Den_Part                                                  H_DCP_P_PN_Name               ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyName/cbc:Name
      sliv.strada                                                 H_DCP_P_PA_StrName            ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName
      CAST(
        CASE
          WHEN sliv.sector IS NOT NULL THEN &apos;SECTOR &apos;||sliv.sector
          ELSE NULL
        END AS VARCHAR2(100)
      )                                                           H_DCP_P_PA_AdStrName          ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName
      NULL                                                        H_DCP_P_PA_BuildingName       ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingName
      sliv.NR1||
			CASE
				WHEN Length(sliv.NR1||sliv.NR2) = 0                THEN &apos;-&apos;
				WHEN Length(sliv.NR1||sliv.NR2) &gt; Length(sliv.NR1) THEN &apos;-&apos;
				ELSE &apos;&apos;
			END ||
			sliv.NR2                                                    H_DCP_P_PA_BuildingNumber     ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber
      lliv.den_localit||
      CASE
        WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jliv.simbauto
        ELSE &apos;&apos;
      END                                                         H_DCP_P_PA_CityName           ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName
      sliv.codpostal                                              H_DCP_P_PA_PostalZone         ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone
      jliv.den_judet                                              H_DCP_P_PA_CountrySubentity   ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cbc:CountrySubentity
      NULL                                                        H_DCP_P_PA_AL_Line            ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line
      tliv.simbauto                                               H_DCP_P_PA_C_IdCode           ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode
      NULL                                                        H_DCP_P_PTS_RegName           ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName
      NULL                                                        H_DCP_P_PTS_CompID            ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID
      NULL                                                        H_DCP_P_PTS_ExemptionReason   ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:ExemptionReason
      NULL                                                        H_DCP_P_PTS_TS_ID             ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID
      NULL                                                        H_DCP_P_PTS_TS_TaxTypeCode    ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:TaxTypeCode
      NULL                                                        H_DCP_P_C_Name                ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:Contact/cbc:Name
      NULL                                                        H_DCP_P_C_Telephone           ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:Contact/cbc:Telephone
      NULL                                                        H_DCP_P_C_Telefax             ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:Contact/cbc:Telefax
      NULL                                                        H_DCP_P_C_EMail               ,--ubl:DespatchAdvice/cac:DeliveryCustomerParty/cac:Party/cac:Contact/cbc:ElectronicMail
      NULL                                                        H_BCP_CustAAID                ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cbc:CustomerAssignedAccountID
			ssoc.gln                                                    H_BCP_P_EndpointID            ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cbc:EndpointID
      &apos;GLN&apos;                                                       H_BCP_P_EndpointIDx           ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cbc:EndpointID@schemeID
      pcf.codfiscal                                               H_BCP_P_PI_ID                 ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID
      p.Den_Part                                                  H_BCP_P_PN_Name               ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyName/cbc:Name
      ssoc.strada                                                 H_BCP_P_PA_StrName            ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName
      CAST(
        CASE
          WHEN ssoc.sector IS NOT NULL THEN &apos;SECTOR &apos;||ssoc.sector
          ELSE NULL
        END AS VARCHAR2(100)
      )                                                           H_BCP_P_PA_AdStrName          ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName
      NULL                                                        H_BCP_P_PA_BuildingName       ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingName
			ssoc.NR1||
			CASE
				WHEN Length(ssoc.NR1||sliv.NR2) = 0                THEN &apos;-&apos;
				WHEN Length(ssoc.NR1||sliv.NR2) &gt; Length(sliv.NR1) THEN &apos;-&apos;
				ELSE &apos;&apos;
			END ||
			ssoc.NR2                                                    H_BCP_P_PA_BuildingNumber     ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber
      lsoc.den_localit||
      CASE
        WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jsoc.simbauto
        ELSE &apos;&apos;
      END                                                         H_BCP_P_PA_CityName           ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName
      ssoc.codpostal                                              H_BCP_P_PA_PostalZone         ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone
      jsoc.den_judet                                              H_BCP_P_PA_CountrySubentity   ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cbc:CountrySubentity
      NULL                                                        H_BCP_P_PA_AL_Line            ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line
      tsoc.simbauto                                               H_BCP_P_PA_C_IdCode           ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode
      NULL                                                        H_BCP_P_PTS_RegName           ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName
      NULL                                                        H_BCP_P_PTS_CompID            ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID
      NULL                                                        H_BCP_P_PTS_ExemptionReason   ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:ExemptionReason
      NULL                                                        H_BCP_P_PTS_TS_ID             ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID
      NULL                                                        H_BCP_P_PTS_TS_TaxTypeCode    ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:TaxTypeCode
      NULL                                                        H_BCP_P_C_Name                ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:Contact/cbc:Name
      NULL                                                        H_BCP_P_C_Telephone           ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:Contact/cbc:Telephone
      NULL                                                        H_BCP_P_C_Telefax             ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:Contact/cbc:Telefax
      NULL                                                        H_BCP_P_C_EMail               ,--ubl:DespatchAdvice/cac:BuyerCustomerParty/cac:Party/cac:Contact/cbc:ElectronicMail
      CASE
				WHEN sliv.edi_parttip = 1 THEN sliv.edi_partid
				WHEN sliv.edi_parttip = 2 THEN f.codfiscal
				WHEN sliv.edi_parttip = 3 THEN sliv.gln
				ELSE                           vIDLaClient
			END                                                         H_SSP_CustAAID                ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cbc:CustomerAssignedAccountID
      ssub.gln                                                    H_SSP_P_EndpointID            ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cbc:EndpointID
      &apos;GLN&apos;                                                       H_SSP_P_EndpointIDx           ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cbc:EndpointID@schemeID
      f.codfiscal                                                 H_SSP_P_PI_ID                 ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID
      f.DenFirma                                                  H_SSP_P_PN_Name               ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyName/cbc:Name
      f.strada                                                    H_SSP_P_PA_StrName            ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:StreetName
      CAST (
        CASE
          WHEN f.sector IS NOT NULL THEN &apos;SECTOR &apos;||f.sector
          ELSE NULL
        END AS VARCHAR2(100)
      )                                                           H_SSP_P_PA_AdStrName          ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName
      NULL                                                        H_SSP_P_PA_BuildingName       ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:BuildingName
			f.NR1||
			CASE
				WHEN Length(f.NR1||f.NR2) = 0             THEN &apos;-&apos;
				WHEN Length(f.NR1||f.NR2) &gt; Length(f.NR1) THEN &apos;-&apos;
				ELSE &apos;&apos;
			END ||
			f.NR2                                                       H_SSP_P_PA_BuildingNumber     ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber
      f.DenLocalit||
      CASE
        WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||f.simbjudet
        ELSE &apos;&apos;
      END                                                         H_SSP_P_PA_CityName           ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:CityName
      f.codpostal                                                 H_SSP_P_PA_PostalZone         ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:PostalZone
      f.denjudet                                                  H_SSP_P_PA_CountrySubentity   ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cbc:CountrySubentity
      NULL                                                        H_SSP_P_PA_AL_Line            ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line
      &apos;RO&apos;                                                        H_SSP_P_PA_C_IdCode           ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode
      NULL                                                        H_SSP_P_PTS_RegName           ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName
      NULL                                                        H_SSP_P_PTS_CompID            ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID
      NULL                                                        H_SSP_P_PTS_ExemptionReason   ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:ExemptionReason
      NULL                                                        H_SSP_P_PTS_TS_ID             ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID
      NULL                                                        H_SSP_P_PTS_TS_TaxTypeCode    ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:TaxTypeCode
      NULL                                                        H_SSP_P_C_Name                ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:Contact/cbc:Name
      NULL                                                        H_SSP_P_C_Telephone           ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:Contact/cbc:Telephone
      NULL                                                        H_SSP_P_C_Telefax             ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:Contact/cbc:Telefax
      NULL                                                        H_SSP_P_C_EMail               ,--ubl:DespatchAdvice/cac:SellerSupplierParty/cac:Party/cac:Contact/cbc:ElectronicMail
      NULL                                                        H_OCP_CustAAID                ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cbc:CustomerAssignedAccountID
      NULL                                                        H_OCP_P_EndpointID            ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cbc:EndpointID
      NULL                                                        H_OCP_P_EndpointIDx           ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cbc:EndpointID@schemeID
      NULL                                                        H_OCP_P_PI_ID                 ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID
      NULL                                                        H_OCP_P_PN_Name               ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyName/cbc:Name
      NULL                                                        H_OCP_P_PA_StrName            ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:StreetName
      NULL                                                        H_OCP_P_PA_AdStrName          ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:AdditionalStreetName
      NULL                                                        H_OCP_P_PA_BuildingName       ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingName
      NULL                                                        H_OCP_P_PA_BuildingNumber     ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:BuildingNumber
      NULL                                                        H_OCP_P_PA_CityName           ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:CityName
      NULL                                                        H_OCP_P_PA_PostalZone         ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:PostalZone
      NULL                                                        H_OCP_P_PA_CountrySubentity   ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cbc:CountrySubentity
      NULL                                                        H_OCP_P_PA_AL_Line            ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cac:AddressLine/cbc:Line
      NULL                                                        H_OCP_P_PA_C_IdCode           ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode
      NULL                                                        H_OCP_P_PTS_RegName           ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName
      NULL                                                        H_OCP_P_PTS_CompID            ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID
      NULL                                                        H_OCP_P_PTS_ExemptionReason   ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:ExemptionReason
      NULL                                                        H_OCP_P_PTS_TS_ID             ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID
      NULL                                                        H_OCP_P_PTS_TS_TaxTypeCode    ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:TaxTypeCode
      NULL                                                        H_OCP_P_C_Name                ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:Contact/cbc:Name
      NULL                                                        H_OCP_P_C_Telephone           ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:Contact/cbc:Telephone
      NULL                                                        H_OCP_P_C_Telefax             ,--ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:Contact/cbc:Telefax
      NULL                                                        H_OCP_P_C_EMail                --ubl:DespatchAdvice/cac:OriginatorCustomerParty/cac:Party/cac:Contact/cbc:ElectronicMail
    FROM iesiri i
      CROSS JOIN TMP_FIRMA_ADR f
      INNER JOIN npart p ON p.codpart = i.partener
      INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
      LEFT JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
      LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
      LEFT JOIN npartcodfisc pcf ON pcf.cod_codfiscal = i.codfiscal

      LEFT JOIN nlocalit lliv ON lliv.codlocalit = sliv.codlocalit
      LEFT JOIN ntari tliv ON tliv.codtara = lliv.codtara
      LEFT JOIN njudet jliv ON jliv.codjudet = lliv.codjudet

      LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
      LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
      LEFT JOIN njudet jsoc ON jsoc.codjudet = lsoc.codjudet

      LEFT JOIN nagenda ssub ON ssub.codsubunit = i.subunitatea

      LEFT JOIN npartb pbc ON pbc.codpart = p.codpart AND pbc.implicit = 1
      LEFT JOIN nbank pb ON pb.codbank = pbc.codbank
      LEFT JOIN nlocalit lpb ON lpb.codlocalit = pbc.codlocalit
      LEFT JOIN njudet jpb ON jpb.codjudet = lpb.codjudet
    WHERE i.codies = pCodIes
      AND Coalesce(sliv.edi_exptip,0) IN (4,6,7,8)
      AND Coalesce(sliv.edi_parttip,0) &gt; 0
      AND Coalesce(sliv.edi_objtip,0) &gt; 0;

    INSERT INTO TMP_DOCXCHANGE_DESADV_S
    SELECT
      L.NRLIVR                                                    S_ID                          ,--ubl:DespatchAdvice/cac:Shipment/cbc:ID
      To_Char(L.DataLivr, &apos;yyyy-mm-dd&apos;)                           S_D_ActualDeliveryDate        ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cbc:ActualDeliveryDate
      NULL                                                        S_D_ActualDeliveryTime        ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cbc:ActualDeliveryTime
      NULL                                                        S_D_DA_StrName                ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:StreetName
      NULL                                                        S_D_DA_AdStrName              ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:AdditionalStreetName
      NULL                                                        S_D_DA_BuildingName           ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:BuildingName
      NULL                                                        S_D_DA_BuildingNumber         ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:BuildingNumber
      NULL                                                        S_D_DA_CityName               ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:CityName
      NULL                                                        S_D_DA_PostalZone             ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:PostalZone
      NULL                                                        S_D_DA_CountrySubentity       ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cbc:CountrySubentity
      NULL                                                        S_D_DA_AL_Line                ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cac:AddressLine/cbc:Line
      NULL                                                        S_D_DA_C_IdCode               ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:DeliveryAddress/cac:Country/cbc:IdentificationCode
      To_Char(L.DataLivr, &apos;yyyy-mm-dd&apos;)                           S_D_RDP_StartDate             ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:RequestedDeliveryPeriod/cbc:StartDate
      NULL                                                        S_D_RDP_StartTime             ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:RequestedDeliveryPeriod/cbc:StartTime
      NULL                                                        S_D_RDP_EndDate               ,--ubl:DespatchAdvice/cac:Shipment/cac:Delivery/cac:RequestedDeliveryPeriod/cbc:EndDate
      NULL                                                        S_D_RDP_EndTime                --ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:PackagingTypeCode
    FROM iesiri i
      INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
      INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    WHERE i.codies = pCodIes
      AND Coalesce(sliv.edi_exptip,0) IN (4,6,7,8)
      AND Coalesce(sliv.edi_parttip,0) &gt; 0
      AND Coalesce(sliv.edi_objtip,0) &gt; 0;

    -- nu stiu inca ce date vor fi aici
--    INSERT INTO TMP_DOCXCHANGE_DESADV_SC
--      NULL                                                        S_C_ID                         --ubl:DespatchAdvice/cac:Shipment/cac:Consignment/cbc:ID
--    FROM iesiri i
--      INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
--    WHERE i.codies = pCodIes
--      AND Coalesce(sliv.edi_exptip,0) IN (4,6,7,8)
--      AND Coalesce(sliv.edi_parttip,0) &gt; 0
--      AND Coalesce(sliv.edi_objtip,0) &gt; 0;

    INSERT INTO TMP_DOCXCHANGE_DESADV_ST
   SELECT
      NULL                                                        S_THU_ID                      ,--ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:ID
      CASE WHEN edi_exptip &lt;&gt; 8 THEN TO_CHAR(Sum(CANT_UA),&apos;fm9999999990&apos;)
                                     ELSE NULL END                S_THU_Quantity                ,--ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:Quantity
      NULL                                                        S_THU_RMI                     ,--ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:ReturnableMaterialIndicator
      NULL                                                        S_THU_PackageLevelCode        ,--ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:PackageLevelCode
      CASE WHEN edi_exptip &lt;&gt; 8 THEN DEN_UA ELSE NULL END         S_THU_PackagingTypeCode        --ubl:DespatchAdvice/cac:Shipment/cac:TransportHandlingUnit/cbc:PackagingTypeCode
    FROM (
      SELECT
        Ceil(I1.CANT/Coalesce(UA1.PARITATE, 1)) CANT_UA,
        Substr(
          Coalesce(
            CASE
              WHEN sliv.edi_denum = 1 THEN UA1.DEN_EANCOM
              WHEN sliv.edi_denum = 2 THEN UA1.DEN_UM1
              WHEN sliv.edi_denum = 3 THEN UA1.CODEXTERN
            END,UA1.DEN_EANCOM, UA1.Den_UM1
          ),1,3
        ) DEN_UA,
        sliv.edi_exptip edi_exptip
      FROM iesiri i
        INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
        inner join iesiri1 i1   ON i1.codies      = i.codies
        INNER JOIN nartobj o    ON o.codobiect    = i1.codobiect
        INNER JOIN num1 ua1     ON ua1.codum1     = o.umambalare
      WHERE i.codies = pCodIes
        AND Coalesce(sliv.edi_exptip,0) IN (4,6,7,8)
        AND Coalesce(sliv.edi_parttip,0) &gt; 0
        AND Coalesce(sliv.edi_objtip,0)  &gt; 0
    ) a_pg
    GROUP BY DEN_UA, edi_exptip;

    COMMIT;
   -- DESADV
  ELSE --INVOICE
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DOCXCHANGE&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DocXChange_TAX&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DocXChange_AC&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DocXChange_AC_XML&apos;;

    IF Coalesce(vDocXChangeDocType,1) = 1 THEN
      SELECT
        CASE WHEN Count(1) &gt; 0 THEN 4 ELSE 2 END,
        CASE WHEN Count(1) &gt; 0 THEN Max(s.NrDoc)                          KEEP (Dense_Rank last ORDER BY i1.codies1 ASC) END,
        CASE WHEN Count(1) &gt; 0 THEN Max(To_Char(S.DataDoc, &apos;yyyy-mm-dd&apos;)) KEEP (Dense_Rank last ORDER BY i1.codies1 ASC) END
      INTO
        vDocXChangeDocType,
        vBillingRef,
        vBillingRefDate
      FROM iesiri1 i1
        INNER JOIN iesiri1 s1 ON s1.codies1 = CASE
                                                WHEN Coalesce(i1.codies1storno,0) &lt;&gt; 0                                                  THEN Coalesce(i1.codies1storno,0)
                                                WHEN Coalesce(i1.tipdocimp, 0) IN (19, 20, 26) AND Coalesce(i1.codliniedocimp, 0 ) &lt;&gt; 0 THEN i1.codliniedocimp
                                              END
        INNER JOIN iesiri s ON s.codies = s1.codies
      WHERE i1.codies =  pCodIes;
    END IF;

    SELECT fbc.nrcont, lfb.den_localit, fb.denumire, jfb.simbauto
    INTO   fbc_NrCont, lfb_den_localit, fb_denumire, jfb_simbauto
    FROM TMP_FIRMA_ADR f
      LEFT JOIN nbankcont fbc ON fbc.codbankcont = f.codbankcont
      LEFT JOIN nbank     fb  ON fb.codbank      = fbc.codbank
      LEFT JOIN nlocalit  lfb ON lfb.codlocalit  = fbc.codlocalitate
      LEFT JOIN njudet    jfb ON jfb.codjudet    = lfb.codjudet;

    IF vDocXChangeDocType = 4
    THEN sType := &apos;storno&apos;;
    ELSE sType := &apos;&apos;;
    END IF;

    INSERT INTO TMP_DOCXCHANGE
    SELECT
      CASE
        WHEN Nullif(sliv.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
        ELSE sliv.EDI_SUBDIREXP||&apos;\&apos;
      END||
      CASE
        WHEN sliv.edi_exptip IN (4, 6, 7, 8)
        THEN &apos;INVOIC_&apos;||To_Char(I.CodIes)||sType||&apos;_VAT_&apos;||Coalesce(f.Codfiscal,&apos;0&apos;)
        ELSE To_Char(SYSTIMESTAMP,&apos;yyyymmddhh24missff4&apos;)||&apos;_&apos;||Coalesce(f.Codfiscal,&apos;0&apos;)
      END                                                                                                                             FileName,
      CASE
        WHEN sliv.edi_exptip = 7 THEN &apos;FMF&apos;
        ELSE NULL
      END                                                                                                                             Invoice00a,--CustomizationID
      NULL                                                                                                                            Invoice00b,--ProfileID
      NULL                                                                                                                            Invoice00c,--UUID
      --Trim(Coalesce(CASE WHEN sliv.edi_exptip &lt;&gt; 7 THEN i.seriadoc END, &apos;&apos;)||&apos; &apos;||To_Char(I.NrDoc))                                   Invoice01, --ID
      Trim(Coalesce(i.seriadoc, &apos;&apos;)||&apos; &apos;||To_Char(I.NrDoc))                                                                           Invoice01, --ID
      NULL                                                                                                                            Invoice01b,--ReceiverID  *** CARREFOUR
      &apos;FALSE&apos;                                                                                                                         Invoice02, --CopyIndicator
      To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                                                                                                Invoice03, --IssueDate
      NULL                                                                                                                            Invoice03b,--IssueTime
      CASE vDocXChangeDocType
        WHEN 4 THEN &apos;381&apos; --storno
        WHEN 3 THEN &apos;384&apos; --corectie
        WHEN 2 THEN &apos;380&apos; --normal
      END                                                                                                                             Invoice04, --InvoiceTypeCode
      SubStr(I.Obs,1,200)                                                                                                             Invoice05, --Note
      &apos;RON&apos;                                                                                                                           Invoice06, --DocumentCurrencyCode
      &apos;RON&apos;                                                                                                                           Invoice07, --TaxCurrencyCode
      &apos;RON&apos;                                                                                                                           Invoice08, --PricingCurrencyCode
      &apos;RON&apos;                                                                                                                           Invoice09, --PaymentCurrencyCode
      &apos;RON&apos;                                                                                                                           Invoice10, --PaymentAlternativeCurrencyCode
      Count(DISTINCT i1.codies1) OVER (PARTITION BY i1.codies)                                                                        Invoice11, --LineCountNumeric
      CASE
        WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
        ELSE Max( CASE WHEN Coalesce(sliv.edi_exptip,0) = 4 AND pTecNetComNRI &lt;&gt; 1 THEN COM.SeriaDOC END||
                  CASE WHEN pTecNetComNRI = 1 THEN Coalesce(LTrim(COM.NRI,&apos; 0&apos;),To_Char(COM.NrDoc)) ELSE To_Char(COM.NrDOC) END
                )
            KEEP (Dense_Rank FIRST ORDER BY com.codcomanda) OVER (PARTITION BY i.codies)
      END                                                                                                                             Invoice12a,--OrderReference.ID
                                                                                                                                                 --OrderReference *** CARREFOUR
      CASE
        WHEN vOrderNumber IS NOT NULL THEN vOrderDate
        ELSE Max(CASE WHEN com.codcomanda IS NOT NULL THEN To_Char(COM.DataDoc, &apos;yyyy-mm-dd&apos;) END) KEEP (Dense_Rank FIRST ORDER BY com.codcomanda) OVER (PARTITION BY i.codies)
      END                                                                                                                             Invoice12b,--OrderReference.IssueDate
      vBillingRef                                                                                                                     Invoice13a,--BillingReference.ID
      vBillingRefDate                                                                                                                 Invoice13b,--BillingReference.IssueDate
      CASE
        WHEN sliv.edi_exptip = 1 AND vDespatchNumber IS NOT NULL THEN vDespatchNumber||&apos;/&apos;||vDespatchDate --*** CARREFOUR
        WHEN vDespatchNumber IS NOT NULL THEN vDespatchNumber
        WHEN sliv.edi_exptip = 1 THEN Max(CASE WHEN ae.codies IS NOT NULL THEN AE.SeriaDOC||AE.NrDOC||&apos;/&apos;||To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;) END) OVER (PARTITION BY i.codies) --*** CARREFOUR
        ELSE Max(AE.SeriaDOC||To_Char(AE.NrDOC)) KEEP (Dense_Rank FIRST ORDER BY ae.codies) OVER (PARTITION BY i.codies)
      END                                                                                                                             Invoice14a,--DespatchDocumentReference.ID
                                                                                                                                                 --DespatchDocumentReference *** CARREFOUR
      CASE
        WHEN vDespatchNumber IS NOT NULL THEN vDespatchDate
        ELSE Max(CASE WHEN ae.codies IS NOT NULL THEN To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;) END)  KEEP (Dense_Rank FIRST ORDER BY ae.codies) OVER (PARTITION BY i.codies)
      END                                                                                                                             Invoice14b,--DespatchDocumentReference.IssueDate
      Coalesce(vReceiveAdviceNumber, i.NrNir)                                                                                         Invoice15a,--ReceiptDocumentReference.ID
      Coalesce(vReceiveAdviceDate  , To_Char(i.DataNir, &apos;yyyy-mm-dd&apos;))                                                                Invoice15b,--ReceiptDocumentReference.IssueDate
      NULL                                                                                                                            Invoice16a,--StatementDocumentReference.ID
      NULL                                                                                                                            Invoice16b,--StatementDocumentReference.IssueDate
      NULL                                                                                                                            Invoice17a,--OriginatorDocumentReference.ID
      NULL                                                                                                                            Invoice17b,--OriginatorDocumentReference.IssueDate
      NULL                                                                                                                            Invoice18a,--ContractDocumentReference.ID
      NULL                                                                                                                            Invoice18b,--ContractDocumentReference.IssueDate
      NULL                                                                                                                            Invoice19a,--AdditionalDocumentReference.ID
      NULL                                                                                                                            Invoice19b,--AdditionalDocumentReference.IssueDate
      CASE
        WHEN sliv.edi_parttip = 1 THEN sliv.edi_partid
        WHEN sliv.edi_parttip = 2 THEN f.codfiscal
        WHEN sliv.edi_parttip = 3 THEN sliv.gln
        ELSE                           vIDLaClient
      END                                                                                                                             ASP01,     --AccountingSupplierParty.CustomerAssignedAccountID
                                                                                                                                                 --SupplierReceiverCode *** CARREFOUR
      NULL                                                                                                                            ASP02,     --AccountingSupplierParty.AdditionalAccountID
      f.codfiscal                                                                                                                     ASP03,     --AccountingSupplierParty.Party.PartyIdentification
                                                                                                                                                 --AccountingSupplierParty.Identification  *** CARREFOUR
      f.DenFirma                                                                                                                      ASP04,     --AccountingSupplierParty.Party.PartyName
                                                                                                                                                 --AccountingSupplierParty.Name *** CARREFOUR
      NULL                                                                                                                            ASP_ADR01, --AccountingSupplierParty.Party.PostalAddress.Postbox
                                                                                                                                                 --AccountingSupplierParty.Address.Postbox *** CARREFOUR
      f.strada                                                                                                                        ASP_ADR02, --AccountingSupplierParty.Party.PostalAddress.StreetName
                                                                                                                                                 --AccountingSupplierParty.Address.StreetName *** CARREFOUR
      CASE
        WHEN f.sector IS NOT NULL THEN &apos;SECTOR &apos;||f.sector
        ELSE CAST(NULL AS VARCHAR2(100))
      END                                                                                                                             ASP_ADR03, --AccountingSupplierParty.Party.PostalAddress.AdditionalStreetName
                                                                                                                                                 --AccountingSupplierParty.Address.AdditionalStreetName *** CARREFOUR
      f.NR1||
      CASE
        WHEN Length(f.NR1||f.NR2) = 0             THEN &apos;-&apos;
        WHEN Length(f.NR1||f.NR2) &gt; Length(f.NR1) THEN &apos;-&apos;
        ELSE &apos;&apos;
      END ||
      f.NR2                                                                                                                           ASP_ADR04, --AccountingSupplierParty.Party.PostalAddress.BuildingNumber
                                                                                                                                                 --AccountingSupplierParty.Address.BuildingNumber *** CARREFOUR

      f.DenLocalit||CASE WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||f.simbjudet ELSE &apos;&apos; END                                                  ASP_ADR05, --AccountingSupplierParty.Party.PostalAddress.CityName
                                                                                                                                                 --AccountingSupplierParty.Address.CityName *** CARREFOUR
      f.codpostal                                                                                                                     ASP_ADR06, --AccountingSupplierParty.Party.PostalAddress.PostalZone
                                                                                                                                                 --AccountingSupplierParty.Address.PostalZone *** CARREFOUR
      f.denjudet                                                                                                                      ASP_ADR07, --AccountingSupplierParty.Party.PostalAddress.CountrySubentity
      CASE WHEN sliv.edi_exptip = 8 THEN &apos;&apos; ELSE f.simbjudet END                                                                      ASP_ADR08, --AccountingSupplierParty.Party.PostalAddress.CountrySubentityCode
      &apos;RO&apos;                                                                                                                            ASP_ADR09, --AccountingSupplierParty.Party.PostalAddress.Country.IdentificationCode
      CASE WHEN sliv.edi_parttip = 5 THEN vGLNLaClient ELSE ssub.GLN END                                                              ASP_ADR10, --AccountingSupplierParty.Party.PostalAddress.LocationCoordinate
      f.NrJ                                                                                                                           ASP_PLE01, --AccountingSupplierParty.Party.PartyLegalEntity.CompanyID
      TO_CHAR(f.CapitalS,&apos;fm9999999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                     ASP_PLE02, --AccountingSupplierParty.Party.PartyLegalEntity.CorporateStockAmount
      &apos;RON&apos;                                                                                                                           ASP_PLE03, --AccountingSupplierParty.Party.PartyLegalEntity.CorporateStockAmount@currencyID

      pcf.codfiscal                                                                                                                   ACP01,     --AccountingCustomerParty.Party.PartyIdentification
                                                                                                                                                 --AccountingCustomerParty.Identification *** CARREFOUR
      p.Den_Part                                                                                                                      ACP02,     --AccountingCustomerParty.Party.PartyName
                                                                                                                                                 --AccountingCustomerParty.Name *** CARREFOUR
      NULL                                                                                                                            ACP_ADR01, --AccountingCustomerParty.Party.PostalAddress.Postbox
                                                                                                                                                 --AccountingCustomerParty.Address.Postbox *** CARREFOUR
      ssoc.strada                                                                                                                     ACP_ADR02, --AccountingCustomerParty.Party.PostalAddress.StreetName
                                                                                                                                                 --AccountingCustomerParty.Address.StreetName *** CARREFOUR
      CASE
        WHEN ssoc.sector IS NOT NULL THEN &apos;SECTOR &apos;||ssoc.sector
        ELSE CAST(NULL AS VARCHAR2(100))
      END                                                                                                                             ACP_ADR03, --AccountingCustomerParty.Party.PostalAddress.AdditionalStreetName
                                                                                                                                                 --AccountingCustomerParty.Address.AdditionalStreetName *** CARREFOUR
      ssoc.NR1||
      CASE
        WHEN Length(ssoc.NR1||ssoc.NR2) = 0                THEN &apos;-&apos;
        WHEN Length(ssoc.NR1||ssoc.NR2) &gt; Length(ssoc.NR1) THEN &apos;-&apos;
        ELSE &apos;&apos;
      END ||
      ssoc.NR2                                                                                                                        ACP_ADR04, --AccountingCustomerParty.Party.PostalAddress.BuildingNumber
                                                                                                                                                 --AccountingCustomerParty.Address.BuildingNumber *** CARREFOUR
      lsoc.den_localit||CASE WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jsoc.simbauto ELSE &apos;&apos; END                                            ACP_ADR05, --AccountingCustomerParty.Party.PostalAddress.CityName
                                                                                                                                                 --AccountingCustomerParty.Address.CityName *** CARREFOUR
      ssoc.codpostal                                                                                                                  ACP_ADR06, --AccountingCustomerParty.Party.PostalAddress.PostalZone
                                                                                                                                                 --AccountingCustomerParty.Address.PostalZone *** CARREFOUR
      jsoc.den_judet                                                                                                                  ACP_ADR07, --AccountingCustomerParty.Party.PostalAddress.CountrySubentity
      CASE WHEN sliv.edi_exptip = 8 THEN &apos;&apos; ELSE jsoc.simbauto END                                                                    ACP_ADR08, --AccountingCustomerParty.Party.PostalAddress.CountrySubentityCode
      tsoc.simbauto                                                                                                                   ACP_ADR09, --AccountingCustomerParty.Party.PostalAddress.Country.IdentificationCode
      ssoc.GLN                                                                                                                        ACP_ADR10, --AccountingCustomerParty.Party.PostalAddress.LocationCoordinate
      p.RegCom                                                                                                                        ACP_PLE01, --AccountingCustomerParty.Party.PartyLegalEntity.CompanyID
      NULL                                                                                                                            ACP_PLE02, --AccountingCustomerParty.Party.PartyLegalEntity.CorporateStockAmount
      NULL                                                                                                                            ACP_PLE03, --AccountingCustomerParty.Party.PartyLegalEntity.CorporateStockAmount@currencyID
      CASE
        WHEN vDespatchNumber IS NOT NULL THEN vDespatchDate
        WHEN i.tipdoc IN (19,20) THEN To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)
        ELSE Max(CASE WHEN ae.codies IS NOT NULL THEN To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;) END)  KEEP (Dense_Rank FIRST ORDER BY ae.codies) OVER (PARTITION BY i.codies)
      END                                                                                                                             DEL01,     --Delivery.ActualDeliveryDate
      sliv.GLN                                                                                                                        DEL_LOC01, --Delivery.DeliveryLocation.ID
                                                                                                                                                 --AccountingCustomerParty.PhysicalLocation *** CARREFOUR
      sliv.OBS                                                                                                                        DEL_LOC02, --Delivery.DeliveryLocation.Description
      sliv.GLN                                                                                                                        DEL_LOC03, --Delivery.DeliveryLocation.LocationCoordinate
      NULL                                                                                                                            DEL_ADR01, --Delivery.DeliveryLocation.LocationAddress.Postbox
      sliv.strada                                                                                                                     DEL_ADR02, --Delivery.DeliveryLocation.LocationAddress.StreetName
      CASE
        WHEN sliv.sector IS NOT NULL THEN &apos;SECTOR &apos;||sliv.sector
        ELSE CAST(NULL AS VARCHAR2(100))
      END                                                                                                                             DEL_ADR03, --Delivery.DeliveryLocation.LocationAddress.AdditionalStreetName
      sliv.NR1||
      CASE
        WHEN Length(sliv.NR1||sliv.NR2) = 0                THEN &apos;-&apos;
        WHEN Length(sliv.NR1||sliv.NR2) &gt; Length(sliv.NR1) THEN &apos;-&apos;
        ELSE &apos;&apos;
      END ||
      sliv.NR2                                                                                                                        DEL_ADR04, --Delivery.DeliveryLocation.LocationAddress.BuildingNumber
      lliv.den_localit||CASE WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jliv.simbauto ELSE &apos;&apos; END                                            DEL_ADR05, --Delivery.DeliveryLocation.LocationAddress.CityName
      sliv.codpostal                                                                                                                  DEL_ADR06, --Delivery.DeliveryLocation.LocationAddress.PostalZone
      jliv.den_judet                                                                                                                  DEL_ADR07, --Delivery.DeliveryLocation.LocationAddress.CountrySubentity
      CASE WHEN sliv.edi_exptip = 8 THEN &apos;&apos; ELSE jliv.simbauto END                                                                    DEL_ADR08, --Delivery.DeliveryLocation.LocationAddress.CountrySubentityCode
      tliv.simbauto                                                                                                                   DEL_ADR09, --Delivery.DeliveryLocation.LocationAddress.Country.IdentificationCode
      &apos;42&apos;                                                                                                                            PM1,       --PaymentMeans.PaymentMeansCode
      ( SELECT To_Char(Min(O.Termen), &apos;yyyy-mm-dd&apos;)
        FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
        WHERE g.coddoc = i.codies AND g.tipdoc = i.tipdoc
          AND g.semnificatie &lt;&gt; 240
      )                                                                                                                               PM2,       --PaymentMeans.PaymentDueDate
                                                                                                                                                 --DueDate *** CARREFOUR
      pbc.contbanca                                                                                                                   PM3a,      --PaymentMeans.PayerFinancialAccount.ID
                                                                                                                                                 --AccountingCustomerParty.FinancialAccount *** CARREFOUR
      &apos;RON&apos;                                                                                                                           PM3b,      --PaymentMeans.PayerFinancialAccount.CurrencyCode
      pb.denumire                                                                                                                     PM3c,      --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.Name
      pb.codswift                                                                                                                     PM3d,      --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.ID
      NULL                                                                                                                            PM3_ADR01, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.Postbox
      NULL                                                                                                                            PM3_ADR02, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.StreetName
      NULL                                                                                                                            PM3_ADR03, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.AdditionalStreetName
      NULL                                                                                                                            PM3_ADR04, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.BuildingNumber
      lpb.den_localit||CASE WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jpb.simbauto ELSE &apos;&apos; END                                              PM3_ADR05, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.CityName
      NULL                                                                                                                            PM3_ADR06, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.PostalZone
      jpb.den_judet                                                                                                                   PM3_ADR07, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.CountrySubentity
      CASE WHEN sliv.edi_exptip = 8 THEN &apos;&apos; ELSE jpb.simbauto END                                                                     PM3_ADR08, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.CountrySubentityCode
      &apos;RO&apos;                                                                                                                            PM3_ADR09, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.Country.IdentificationCode
      NULL                                                                                                                            PM3_ADR10, --PaymentMeans.PayerFinancialAccount.FinancialInstitutionBranch.PostalAddress.LocationCoordinate
      fbc_NrCont                                                                                                                      PM4a,      --PaymentMeans.PayeeFinancialAccount.ID
                                                                                                                                                 --AccountingSupplierParty.FinancialAccount *** CARREFOUR
      &apos;RON&apos;                                                                                                                           PM4b,      --PaymentMeans.PayeeFinancialAccount.CurrencyCode
      fb_denumire                                                                                                                     PM4c,      --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.FinancialInstitution.Name
      NULL                                                                                                                            PM4_ADR01, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.Postbox
      NULL                                                                                                                            PM4_ADR02, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.StreetName
      NULL                                                                                                                            PM4_ADR03, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.AdditionalStreetName
      NULL                                                                                                                            PM4_ADR04, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.BuildingNumber
      lfb_den_localit||CASE WHEN sliv.edi_exptip = 8 THEN &apos;, &apos;||jfb_simbauto ELSE &apos;&apos; END                                              PM4_ADR05, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.CityName
      NULL                                                                                                                            PM4_ADR06, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.PostalZone
      NULL                                                                                                                            PM4_ADR07, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.CountrySubentity
      CASE WHEN sliv.edi_exptip = 8 THEN &apos;&apos; ELSE jfb_simbauto END                                                                     PM4_ADR08, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.CountrySubentityCode
      &apos;RO&apos;                                                                                                                            PM4_ADR09, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.Country.IdentificationCode
      NULL                                                                                                                            PM4_ADR10, --PaymentMeans.PayeeFinancialAccount.FinancialInstitutionBranch.PostalAddress.LocationCoordinate
      NULL                                                                                                                            PT1,       --PaymentTerms.ID
      NULL                                                                                                                            PT2,       --PaymentTerms.PaymentMeansID
      NULL                                                                                                                            PT3,       --PaymentTerms.PrepaidPaymentReferenceID
      NULL                                                                                                                            PT4,       --PaymentTerms.Note
      NULL                                                                                                                            PT5,       --PaymentTerms.ReferenceEventCode
      NULL                                                                                                                            PT6,       --PaymentTerms.SettlementDiscountPercent
      NULL                                                                                                                            PT7,       --PaymentTerms.PenaltySurchargePercent
      NULL                                                                                                                            PT8,       --PaymentTerms.Amount
      NULL                                                                                                                            PT9a,      --PaymentTerms.SettlementPeriod.StartDate
      NULL                                                                                                                            PT9b,      --PaymentTerms.SettlementPeriod.StartTime
      NULL                                                                                                                            PT9c,      --PaymentTerms.SettlementPeriod.EndDate
      NULL                                                                                                                            PT9d,      --PaymentTerms.SettlementPeriod.EndTime
      (
        SELECT To_Char(Min(Trunc(O.Termen-I.DataDoc)))
        FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
        WHERE g.coddoc = i.codies AND g.tipdoc = i.tipdoc
          AND g.semnificatie &lt;&gt; 240
      )                                                                                                                               PT9e,      --PaymentTerms.SettlementPeriod.DurationMeasure
      &apos;D&apos;                                                                                                                             PT9f,      --PaymentTerms.SettlementPeriod.DescriptionCode
      NULL                                                                                                                            PT9g,      --PaymentTerms.SettlementPeriod.Description
      NULL                                                                                                                            PER01,     --PaymentExchangeRate.SouorceCurrencyCode
      NULL                                                                                                                            PER02,     --PaymentExchangeRate.SourceCurrencyBaseRate
      NULL                                                                                                                            PER03,     --PaymentExchangeRate.TargetCurrencyCode
      NULL                                                                                                                            PER04,     --PaymentExchangeRate.TargetCurrencyBaseRate
      NULL                                                                                                                            PER05,     --PaymentExchangeRate.ExchangeMarketID
      NULL                                                                                                                            PER06,     --PaymentExchangeRate.CalculationRate
      NULL                                                                                                                            PER07,     --PaymentExchangeRate.MathematicOperatorCode
      NULL                                                                                                                            PER08,     --PaymentExchangeRate.Date
      NULL                                                                                                                            PER09,     --PaymentExchangeRate.ForeignExchangeContract
      --To_Char(CASE WHEN I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;, &apos;R&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL,I.AN,I.LUNA) ELSE 0 END)
      TO_CHAR(
        CASE
          WHEN I1.TAXA = 3 THEN T1.PROCENT
          ELSE PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
        END
      )                                                                                                                               Tax01,     --TaxTotal.TaxSubtotal.Percent
                                                                                                                                                 --VATRate *** CARREFOUR
      TO_CHAR(I.TvaDoc,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                            Tax02,     --TaxTotal.TaxAmount
                                                                                                                                                 --TotalVAT
      NULL                                                                                                                            Tax02b,    --TaxTotal.RoundingAmount
      NULL                                                                                                                            Tax02c,    --TaxTotal.TaxEvidenceIndicator
      TO_CHAR(
        CASE
          WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)-Round(I.TvaDoc,2)
          ELSE Round(I.ValDoc-I.TvaDoc,2)
        END,
        &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           Tax03,     --LegalMonetaryTotal.TaxExclusiveAmount
                                                                                                                                                 --TotalWoVAT
      TO_CHAR(
        CASE
          WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
          ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
        END,
        &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           Tax04,     --LegalMonetaryTotal.TaxInclusiveAmount
                                                                                                                                                 --TotalInclVAT
      NULL                                                                                                                            TST03,     --TaxTotal.TaxSubtotal.CalculationSequenceNumeric
      NULL                                                                                                                            TST04,     --TaxTotal.TaxSubtotal.TransactionCurrencyTaxAmount
      NULL                                                                                                                            TST06,     --TaxTotal.TaxSubtotal.BaseUnitMeasure
      NULL                                                                                                                            TST07,     --TaxTotal.TaxSubtotal.PerUnitAmount
      NULL                                                                                                                            TST08,     --TaxTotal.TaxSubtotal.TierRange
      NULL                                                                                                                            TST09,     --TaxTotal.TaxSubtotal.TierRatePercent
      NULL                                                                                                                            TST10,     --TaxTotal.TaxSubtotal.TaxCategory.ID
      NULL                                                                                                                            TST11,     --TaxTotal.TaxSubtotal.TaxCategory.Name
      NULL                                                                                                                            TST12,     --TaxTotal.TaxSubtotal.TaxCategory.Percent
      TO_CHAR(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*Coalesce(U1.PARITATE,1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)    TST13,     --TaxTotal.TaxSubtotal.TaxCategory.BaseUnitMeasure     **pt MegaImage
      NULL                                                                                                                            TST14,     --TaxTotal.TaxSubtotal.TaxCategory.PerUnitAmount
      NULL                                                                                                                            TST15,     --TaxTotal.TaxSubtotal.TaxCategory.TaxExemptionReasonCode
      NULL                                                                                                                            TST16,     --TaxTotal.TaxSubtotal.TaxCategory.TaxExemptionReason
      NULL                                                                                                                            TST17,     --TaxTotal.TaxSubtotal.TaxCategory.TierRange
      NULL                                                                                                                            TST18,     --TaxTotal.TaxSubtotal.TaxCategory.TierRatePercent
      &apos;7&apos;                                                                                                                             TST19,     --TaxTotal.TaxSubtotal.TaxCategory.TaxScheme.ID
      NULL                                                                                                                            TST20,     --TaxTotal.TaxSubtotal.TaxCategory.TaxScheme.schemeID
      CASE
        WHEN
          CASE
            WHEN I1.TAXA = 3 THEN T1.PROCENT
            ELSE PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
          END = 0
        THEN &apos;E&apos;
        ELSE &apos;S&apos;
      END                                                                                                                             TST21,     --TaxTotal.TaxSubtotal.TaxCategory.TaxScheme.Name
      &apos;VAT&apos;                                                                                                                           TST22,     --TaxTotal.TaxSubtotal.TaxCategory.TaxScheme.TaxTypeCode
      &apos;RON&apos;                                                                                                                           TST23,     --TaxTotal.TaxSubtotal.TaxCategory.TaxScheme.CurrencyCode
      NULL                                                                                                                            LMT01,     --LegalMonetaryTotal.LineExtensionAmount
      NULL                                                                                                                            LMT04,     --LegalMonetaryTotal.AllowanceTotalAmount
      NULL                                                                                                                            LMT05,     --LegalMonetaryTotal.ChargeTotalAmount
      NULL                                                                                                                            LMT06,     --LegalMonetaryTotal.PrepaidAmount
      NULL                                                                                                                            LMT07,     --LegalMonetaryTotal.PayableRoundingAmount
      NULL                                                                                                                            LMT08,     --LegalMonetaryTotal.PayableAmount
      i1.codies1                                                                                                                      CodIes1,
      Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          Line01,    --ID
                                                                                                                                                 --Line_ID *** CARREFOUR
      SubStr(I1.Obs,1,200)                                                                                                            Line02,    --Note
                                                                                                                                                 --Line_Note *** CARREFOUR
      Substr(
        Coalesce(
          CASE
            WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
            WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
            WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
          END,U1.DEN_EANCOM,U1.Den_UM1
        ),1,3
      )                                                                                                                               Line03a,   --InvoicedQuantity/@unitCode
                                                                                                                                                 --DeliveryUnit
      TO_CHAR(I1.CANT/Coalesce(U1.PARITATE, 1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                  Line03b,   --InvoicedQuantity
      TO_CHAR(I1.PU*Coalesce(U1.PARITATE,1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                     Line03c,   --Price.PriceAmount
                                                                                                                                                 --ItemPrice
      &apos;1&apos;                                                                                                                             Line03d,   --BaseQuantity
      &apos;AAB&apos;                                                                                                                           Line03e,   --PriceTypeCode
      TO_CHAR(
        CASE
          WHEN I1.PU = 0 THEN 0
          ELSE (I1.PU-I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1))*100/I1.PU
        END , &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                   Line04a,   --Discount *** CARREFOUR
      TO_CHAR(0,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                 Line04b,   --Allowance *** CARREFOUR
      TO_CHAR(I1.CANT*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1),&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                      Line05a,   --LineExtensionAmount
      TO_CHAR((I1.CANT*I1.PU+I1.TVA) * CASE WHEN I1.PU = 0 THEN 0 ELSE I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU END,
              &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                     Line05b,   --TaxInclusiveAmount
      TO_CHAR(I1.TVA * CASE WHEN I1.PU = 0 THEN 0 ELSE I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU END,
              &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                     Line05c,   --TaxTotal.TaxAmount
                                                                                                                                                 --TaxTotal *** CARREFOUR
      NULL                                                                                                                            Line05d,   --TaxPointDate
      &apos;MCH&apos;                                                                                                                           Line05e,   --AccountingCostCode
      NULL                                                                                                                            Line05f,   --AccountingCost
      &apos;false&apos;                                                                                                                         Line05g,   --FreeOfChargeIndicator
      CASE
        WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
        ELSE CASE WHEN Coalesce(sliv.edi_exptip,0) = 4 AND pTecNetComNRI &lt;&gt; 1 THEN COM.SeriaDOC END||
            CASE WHEN pTecNetComNRI = 1 THEN Coalesce(LTrim(COM.NRI,&apos; 0&apos;),To_Char(COM.NrDoc)) ELSE To_Char(COM.NrDOC) END
      END                                                                                                                             LineD01a,  --OrderLineReference.ID
      CASE
        WHEN vOrderNumber   IS NOT NULL THEN vOrderDate
        WHEN com.codcomanda IS NOT NULL THEN To_Char(COM.DataDoc, &apos;yyyy-mm-dd&apos;)
      END                                                                                                                             LineD01b,  --OrderLineReference.IssueDate
      CASE
        WHEN sliv.edi_exptip = 1 AND vDespatchNumber IS NOT NULL THEN vDespatchNumber||&apos;/&apos;||vDespatchDate --*** CARREFOUR
        WHEN vDespatchNumber IS NOT NULL THEN vDespatchNumber
        WHEN sliv.edi_exptip = 1 THEN CASE WHEN ae.codies IS NOT NULL THEN AE.SeriaDOC||AE.NrDOC||&apos;/&apos;||To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;) END
        ELSE AE.SeriaDOC||To_Char(AE.NrDOC)
      END                                                                                                                             LineD02a,  --DispatchLineReference.ID
      CASE
        WHEN vDespatchNumber IS NOT NULL THEN vDespatchDate
        ELSE CASE WHEN ae.codies IS NOT NULL THEN To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;) END
      END                                                                                                                             LineD02b,  --DispatchLineReference.IssueDate
      Coalesce(vReceiveAdviceNumber, i.NrNir)                                                                                         LineD03a,  --ReceiptLineReference.ID
      Coalesce(vReceiveAdviceDate  , To_Char(i.DataNir, &apos;yyyy-mm-dd&apos;))                                                                LineD03b,  --ReceiptLineReference.IssueDate
      vBillingRef                                                                                                                     LineD04a,  --BillingReference.ID
      vBillingRefDate                                                                                                                 LineD04b,  --BillingReference.IssueDate
      NULL                                                                                                                            LineD05a,  --DocumentReference.ID
      NULL                                                                                                                            LineD05b,  --DocumentReference.IssueDate
      O.Denumire                                                                                                                      Line06,    --Item.Description
                                                                                                                                                 --ItemDescription *** CARREFOUR
      CASE sliv.edi_objtip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      END                                                                                                                             Line06a,   --Item.BuyersItemIdentification.ID
                                                                                                                                                 --StandardItemIdentification *** CARREFOUR
      SubStr(O.CodIntern,1,20)                                                                                                        Line06b,   --Item.SellersItemIdentification.ID
                                                                                                                                                 --SellersItemIdentification *** CARREFOUR
      SubStr(
        CASE sliv.edi_objtip2
          WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
          WHEN 2 THEN ac.codextern
          WHEN 3 THEN o.codextern
          WHEN 4 THEN o.codintern
          WHEN 5 THEN o.codvamal
          WHEN 6 THEN To_Char(o.codplu)
          WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
          WHEN 8 THEN ac.codlaclient
          WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
          ELSE O.CodExtern
        END, 1,20)                                                                                                                    Line06c,   --Item.StandardItemIdentification.ID
      CASE
        WHEN sliv.edi_exptip = 6 THEN &apos;ReturnableMaterialIndicator:false&apos;
        ELSE NULL
      END                                                                                                                             Line06d,   --Item.AdditionalInformation ???  *** MEGA IMAGE
      CASE
        WHEN sliv.edi_exptip = 6 THEN &apos;1&apos;
        ELSE NULL
      END                                                                                                                             Line06e    --Item.PackSizeNumeric  ??? *** MEGA IMAGE  (Real 3 Zecimale) -- Units number per box
    FROM TMP_EDI_IES1 ti1
      CROSS JOIN TMP_FIRMA_ADR f
      LEFT JOIN iesiri i ON i.codies = ti1.codies
      LEFT JOIN npart p ON p.codpart = i.partener
      LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
      LEFT JOIN iesiri1 i1 ON i1.codies1 = ti1.codies1
      LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
      LEFT JOIN npartcodfisc pcf ON pcf.cod_codfiscal = i.codfiscal
      LEFT JOIN nlocalit lliv ON lliv.codlocalit = sliv.codlocalit
      LEFT JOIN ntari tliv ON tliv.codtara = lliv.codtara
      LEFT JOIN njudet jliv ON jliv.codjudet = lliv.codjudet
      LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
      LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
      LEFT JOIN njudet jsoc ON jsoc.codjudet = lsoc.codjudet
      LEFT JOIN nagenda ssub ON ssub.codsubunit = i.subunitatea
      LEFT JOIN npartb pbc ON pbc.codpart = p.codpart AND pbc.implicit = 1
      LEFT JOIN nbank pb ON pb.codbank = pbc.codbank
      LEFT JOIN nlocalit lpb ON lpb.codlocalit = pbc.codlocalit
      LEFT JOIN njudet jpb ON jpb.codjudet = lpb.codjudet
      LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
      LEFT JOIN nart a ON a.codarticol = o.codarticol
      LEFT JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT JOIN ntva1 t1 ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      LEFT JOIN num1 ud ON ud.codum1 = i1.umsec
      LEFT JOIN num1 u1 ON u1.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN u1.codum1-ud.codum1 ELSE u1.secundara END = 0
      LEFT JOIN nartcli ac ON ac.codartcli = ti1.codartcli
      LEFT JOIN ieslink ilae ON ilae.codies1 = CASE -- stef 30.01.2017 - unilever cere sa se aduca avizul aferent facturii stornate
                                                WHEN                                               Coalesce(i1.codies1storno ,0) &lt;&gt; 0 THEN i1.codies1storno
                                                WHEN Coalesce(i1.tipdocimp, 0) IN (19, 20, 26) AND Coalesce(i1.codliniedocimp,0) &lt;&gt; 0 THEN i1.codliniedocimp
                                                ELSE i1.codies1
                                              END
                            AND ilae.codlinieaviz IS NOT NULL
      LEFT JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz
      LEFT JOIN iesiri ae ON ae.codies = ae1.codies
      LEFT JOIN ieslink ilc ON ilc.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilc.codliniecomanda IS NOT NULL
      LEFT JOIN cmdlivrlink cl ON cl.codcomanda1 = ilc.codliniecomanda
      LEFT JOIN comanda1 com1 ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
      LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda
      LEFT JOIN contract1 contr1 ON contr1.codcontract1 = COALESCE(ae1.codcontract1, i1.codcontract1)
      LEFT JOIN contract contr ON contr.codcontract = COALESCE(i.codcontract, ae.codcontract, com.codcontract, contr1.codcontract);

    --                 TaxSubtotal                                    -&gt; Base amount without taxes by VAT percentage
    --TaxSubtotal01 -&gt; TaxSubtotal.TaxableAmount                      -&gt; The net amount to which the tax percent (rate) is applied to calculate the tax amount. ISO 4217
    --TaxSubtotal02 -&gt; TaxSubtotal.TaxAmount                          -&gt; The amount of this tax subtotal. ISO 4217
    --TaxSubtotal03 -&gt; TaxSubtotal.CalculationSequenceNumeric         -&gt; The number of this tax subtotal in the sequence of subtotals corresponding to the order in which multiple taxes are applied. If all taxes are applied to the same taxable amount (i.e., their order of application is inconsequential), then CalculationSequenceNumeric is 1 for all tax subtotals applied to a given amount.
    --TaxSubtotal04 -&gt; TaxSubtotal.TransactionCurrencyTaxAmount       -&gt; The amount of this tax subtotal, expressed in the currency used for invoicing. ISO 4217
    --TaxSubtotal05 -&gt; TaxSubtotal.Percent                            -&gt; The tax rate of the tax category applied to this tax subtotal, expressed as a percentage.
    --TaxSubtotal06 -&gt; TaxSubtotal.BaseUnitMeasure                    -&gt; The unit of measure on which the tax calculation is based
    --TaxSubtotal07 -&gt; TaxSubtotal.PerUnitAmount                      -&gt; Where a tax is applied at a certain rate per unit, the rate per unit applied. ISO 4217
    --TaxSubtotal08 -&gt; TaxSubtotal.TierRange                          -&gt; Where a tax is tiered, the range of taxable amounts that determines the rate of tax applicable to this tax subtotal.
    --TaxSubtotal09 -&gt; TaxSubtotal.TierRatePercent                    -&gt; Where a tax is tiered, the tax rate that applies within a specified range of taxable amounts for this tax subtotal.
    --TaxSubtotal10 -&gt; TaxSubtotal.TaxCategory.ID                     -&gt; Tax code. UN/ECE 5305
    --TaxSubtotal11 -&gt; TaxSubtotal.TaxCategory.Name                   -&gt; Wording of the special tax
    --TaxSubtotal12 -&gt; TaxSubtotal.TaxCategory.Percent                -&gt; Tax percent
    --TaxSubtotal13 -&gt; TaxSubtotal.TaxCategory.BaseUnitMeasure        -&gt; Where a tax is applied at a certain rate per unit, the measure of units on which the tax calculation is based.
    --TaxSubtotal14 -&gt; TaxSubtotal.TaxCategory.PerUnitAmount          -&gt; Where a tax is applied at a certain rate per unit, the rate per unit applied. ISO 4217
    --TaxSubtotal15 -&gt; TaxSubtotal.TaxCategory.TaxExemptionReasonCode -&gt; The reason for tax being exempted expressed as a code.
    --TaxSubtotal16 -&gt; TaxSubtotal.TaxCategory.TaxExemptionReason     -&gt; The reason for tax being exempted.
    --TaxSubtotal17 -&gt; TaxSubtotal.TaxCategory.TierRange              -&gt; Where a tax is tiered, the range of tiers applied in the calculation of the tax subtotal for the tax category.
    --TaxSubtotal18 -&gt; TaxSubtotal.TaxCategory.TierRatePercent        -&gt; Where a tax is tiered, the rate of tax applied to the range of tiers in the calculation of the tax subtotal for the tax category.
    --TaxSubtotal19 -&gt; TaxSubtotal.TaxCategory.TaxScheme.ID           -&gt; Identifies the tax scheme. UN/ECE 5153
    --TaxSubtotal20 -&gt; TaxSubtotal.TaxCategory.TaxScheme.schemeID     -&gt;
    --TaxSubtotal21 -&gt; TaxSubtotal.TaxCategory.TaxScheme.Name         -&gt; The name of the tax scheme.
    --TaxSubtotal22 -&gt; TaxSubtotal.TaxCategory.TaxScheme.TaxTypeCode  -&gt; An identifier for the tax type.
    --TaxSubtotal23 -&gt; TaxSubtotal.TaxCategory.TaxScheme.CurrencyCode -&gt; The currency in which the tax is collected and reported, expressed as a code.
    --                 TaxSubtotal.TaxCategory.TaxScheme.JurisdictionRegionAddress =&gt; PostalAddressType
    INSERT INTO TMP_DocXChange_TAX
    SELECT
      TO_CHAR(Sum(TaxableAmount),&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) TaxSubtotal01, --TaxSubtotal.TaxableAmount
      TO_CHAR(Sum(TaxAmount)    ,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) TaxSubtotal02, --TaxSubtotal.TaxAmount
      NULL                                                                           TaxSubtotal03, --TaxSubtotal.CalculationSequenceNumeric
      NULL                                                                           TaxSubtotal04, --TaxSubtotal.TransactionCurrencyTaxAmount
      TO_CHAR(Procent)                                                               TaxSubtotal05, --TaxSubtotal.Percent
      NULL                                                                           TaxSubtotal06, --TaxSubtotal.BaseUnitMeasure
      NULL                                                                           TaxSubtotal07, --TaxSubtotal.PerUnitAmount
      NULL                                                                           TaxSubtotal08, --TaxSubtotal.TierRange
      NULL                                                                           TaxSubtotal09, --TaxSubtotal.TierRatePercent
      NULL                                                                           TaxSubtotal10, --TaxSubtotal.TaxCategory.ID
      NULL                                                                           TaxSubtotal11, --TaxSubtotal.TaxCategory.Name
      NULL                                                                           TaxSubtotal12, --TaxSubtotal.TaxCategory.Percent
      NULL                                                                           TaxSubtotal13, --TaxSubtotal.TaxCategory.BaseUnitMeasure
      NULL                                                                           TaxSubtotal14, --TaxSubtotal.TaxCategory.PerUnitAmount
      TaxExemptionReasonCode                                                         TaxSubtotal15, --TaxSubtotal.TaxCategory.TaxExemptionReasonCode
      TaxExemptionReason                                                             TaxSubtotal16, --TaxSubtotal.TaxCategory.TaxExemptionReason
      NULL                                                                           TaxSubtotal17, --TaxSubtotal.TaxCategory.TierRange
      NULL                                                                           TaxSubtotal18, --TaxSubtotal.TaxCategory.TierRatePercent
      &apos;7&apos;                                                                            TaxSubtotal19, --TaxSubtotal.TaxCategory.TaxScheme.ID
      NULL                                                                           TaxSubtotal20, --TaxSubtotal.TaxCategory.TaxScheme.schemeID
      CASE
        WHEN Procent = 0 THEN &apos;E&apos;
        ELSE                  &apos;S&apos;
      END                                                                            TaxSubtotal21, --TaxSubtotal.TaxCategory.TaxScheme.Name
      &apos;VAT&apos;                                                                          TaxSubtotal22, --TaxSubtotal.TaxCategory.TaxScheme.TaxTypeCode
      &apos;RON&apos;                                                                          TaxSubtotal23  --TaxSubtotal.TaxCategory.TaxScheme.CurrencyCode
    FROM (
      SELECT
        I1.CANT*I1.PU * CASE WHEN I1.PU = 0 THEN 0 ELSE I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU END TaxableAmount,
        I1.TVA * CASE WHEN I1.PU = 0 THEN 0 ELSE I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU END TaxAmount,
        CASE WHEN i1.taxa = 3 AND T1.PROCENT = 0 THEN &apos;VATEX-EU-O&apos; END TaxExemptionReasonCode,
        CASE WHEN i1.taxa = 3 AND T1.PROCENT = 0 THEN &apos;SGR&apos;        END TaxExemptionReason,
        CASE
          WHEN i1.taxa = 3 THEN T1.PROCENT
          ELSE PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
        END Procent
      FROM iesiri i
        INNER JOIN iesiri1 i1 ON i1.codies     = i.codies
        LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
        LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE i.codies = pCodIes
        AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)
    ) subs
    GROUP BY Procent, TaxExemptionReasonCode, TaxExemptionReason;

    --AC01 /invoice:DXInvoice/AllowanceCharge/ID                           -&gt; discount 1/taxa 2
    --AC02 /invoice:DXInvoice/AllowanceCharge/ChargeIndicator              -&gt; discount &quot;false&quot;/taxa &quot;true&quot;
    --AC03 /invoice:DXInvoice/AllowanceCharge/AllowanceChargeReasonCode    -&gt; cod discount/taxa (SGR)
    --AC04 /invoice:DXInvoice/AllowanceCharge/AllowanceChargeReason        -&gt; discount/taxa (Discount, Taxa verde, Garantie retur)
    --AC05 /invoice:DXInvoice/AllowanceCharge/MultiplierFactorNumeric      -&gt; procent discount (null taxe)
    --AC06 /invoice:DXInvoice/AllowanceCharge/PrepaidIndicator             -&gt; *Indicates whether the Allowance Charge is prepaid (true) or not (false)
    --AC07 /invoice:DXInvoice/AllowanceCharge/SequenceNumeric              -&gt; ordinea de aplicare a discount-ului/taxei.
    --   (Carrefour/Artima/Supeco accepta numai un singur discount per linie). 1
    --   (Carrefour/Artima/Supeco accepta o taxa cumulativa pe linie - taxa verde, taxa de ulei, exclusiv TVA)
    --AC08 /invoice:DXInvoice/AllowanceCharge/Amount                       -&gt; Valoare totala a discountului/taxe pe linie
    --     /invoice:DXInvoice/AllowanceCharge/Amount/@currencyID           -&gt; Moneda RON
    --AC09 /invoice:DXInvoice/AllowanceCharge/BaseAmount                   -&gt; Valoarea totala la care se aplic discountul/i1.codobiect
    --     /invoice:DXInvoice/AllowanceCharge/BaseAmount/@currencyID       -&gt; Moneda RON
    --AC10 /invoice:DXInvoice/AllowanceCharge/AccountingCostCode           -&gt; *The buyer&apos;s accounting code as applied to the Allowance Charge
    --AC11 /invoice:DXInvoice/AllowanceCharge/AccountingCost               -&gt; *The accounting cost centre used by the buyer to account for this allowance or charge, expressed as text
    --AC12 /invoice:DXInvoice/AllowanceCharge/PerUnitAmount                -&gt; Valoarea unitara a discountului/taxei
    INSERT INTO TMP_DocXChange_AC
    SELECT i1.codies1, &apos;1&apos;, &apos;false&apos;, NULL, &apos;Discount&apos;, -procdisc, NULL, i1.indexlocal, -i1.PU*i1.CANT*procdisc/100, i1.PU*i1.CANT, NULL, NULL, -i1.PU*Coalesce(U1.PARITATE,1)*i1.procdisc/100
    FROM iesiri1 i1
      LEFT JOIN num1 ud ON ud.codum1 = i1.umsec
      LEFT JOIN num1 u1 ON u1.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN u1.codum1-ud.codum1 ELSE u1.secundara END = 0
    WHERE i1.codies1 = pCodIes AND Coalesce(procdisc, 0) &lt;&gt; 0;

    INSERT INTO TMP_DocXChange_AC
    SELECT i1.codies1, &apos;1&apos;, &apos;true&apos;,
      CASE WHEN t1.procent = 0 THEN &apos;SGR&apos;            ELSE &apos;&apos;           END,
      CASE WHEN t1.procent = 0 THEN &apos;Garantie retur&apos; ELSE &apos;Taxa verde&apos; END,
      i1.cant, NULL, NULL, i1.cant*i1.pu, NULL, NULL, NULL, i1.pu
    FROM iesiri1 i1
      INNER JOIN iesiri  i  ON i.codies      = i1.codies
      LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
      LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    WHERE i1.codies = pCodIes AND i1.taxa = 3;

    INSERT INTO TMP_DocXChange_AC
    WITH
      x AS (
        SELECT
          i1a.codies1, i1d.codies1 codiesd, Row_Number() OVER (PARTITION BY i1a.codies1 ORDER BY i1d.indexlocal) Idx,
          CASE pModAplicProcDisc WHEN 2 THEN i1a.pu   ELSE i1a.pu*i1a.cant END pu,
          CASE pModAplicProcDisc WHEN 2 THEN i1a.cant ELSE 1               END cant,
          i1a.cant cantum,
          i1d.cant proc, Coalesce(cd.codcriteriu,0) CodCriteriu, Coalesce(cd.cumulat,0) cumulat,
          CASE WHEN cd.codcriteriu IS NULL THEN Coalesce(i1d.ContDiscount,0) ELSE 0 END ContDiscount
        FROM iesiri1 i1a
          INNER JOIN iesiri1 i1d ON i1d.codies = i1a.codies AND i1d.tiplinie IN (&apos;G&apos;,&apos;T&apos;) AND i1a.indexlocal &lt; i1d.indexlocal
          LEFT JOIN  criteriidisc cd ON cd.codcriteriu = i1d.codcriteriu
        WHERE i1a.codies = pCodIes
          AND i1a.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;)
          AND CASE
                WHEN i1d.tiplinie &lt;&gt; &apos;G&apos; THEN 0
                WHEN (SELECT Max(x.indexlocal) FROM iesiri1 x WHERE x.codies = i1a.codies AND x.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;) AND x.indexlocal &gt;= i1a.indexlocal AND x.indexlocal &lt;  i1d.indexlocal) &gt;
                    (SELECT Min(y.indexlocal) FROM iesiri1 y WHERE y.codies = i1a.codies AND y.tiplinie     IN (&apos;G&apos;,&apos;T&apos;) AND y.indexlocal &gt;  i1a.indexlocal AND y.indexlocal &lt;= i1d.indexlocal)
                THEN 1
                ELSE 0
              END = 0
        ORDER BY i1d.indexlocal),
      y (codies1, codcriteriu, contdiscount, idx, proc, cumulat, cantum, bd, d, d0, d1, d2) AS (
        SELECT
          x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat, x.cantum,
          x.cant * x.pu bd,
          x.cant * x.pu*x.proc/100 d,
          CASE x.cumulat WHEN 0 THEN x.pu*x.proc/100 ELSE 0 END d0,
          CASE x.cumulat WHEN 1 THEN x.pu*x.proc/100 ELSE 0 END d1,
          CASE x.cumulat WHEN 2 THEN x.pu*x.proc/100 ELSE 0 END d2
        FROM x
        WHERE idx=1
        UNION ALL
        SELECT
          x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat, x.cantum,
          x.cant * CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2 WHEN 1 THEN x.pu WHEN 2 THEN x.pu+y.d0+y.d1 ELSE 0 END bd,
          x.cant * CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2 WHEN 1 THEN x.pu WHEN 2 THEN x.pu+y.d0+y.d1 ELSE 0 END*x.proc/100 d,
          y.d0 +   CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2 ELSE 0 END*x.proc/100 d0,
          y.d1 +   CASE x.cumulat WHEN 1 THEN x.pu                ELSE 0 END*x.proc/100 d1,
          y.d2 +   CASE x.cumulat WHEN 2 THEN x.pu+y.d0+y.d1      ELSE 0 END*x.proc/100 d2
        FROM y INNER JOIN x ON x.codies1 = y.codies1 AND x.idx = y.idx + 1)
    SELECT i1.codies1, &apos;1&apos;, &apos;false&apos;, NULL, &apos;Discount&apos;, -y.proc, NULL, i1.indexlocal, -y.d, y.bd, NULL, NULL, -y.d/y.cantum/Coalesce(U1.PARITATE,1)
    FROM y
      INNER JOIN IESIRI1 I1 ON i1.codies1 = y.codies1
      LEFT JOIN num1 ud ON ud.codum1 = i1.umsec
      LEFT JOIN num1 u1 ON u1.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN u1.codum1-ud.codum1 ELSE u1.secundara END = 0;

    INSERT INTO TMP_DocXChange_AC_XML
    SELECT
      CodIes1,
      AC01,                                                                    --AllowanceCharge/ID
      AC02,                                                                    --AllowanceCharge/ChargeIndicator
      AC03,                                                                    --AllowanceCharge/AllowanceChargeReasonCode
      AC04,                                                                    --AllowanceCharge/AllowanceChargeReason
      TO_CHAR(AC05,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) AC05, --AllowanceCharge/MultiplierFactorNumeric
      AC06,                                                                    --AllowanceCharge/PrepaidIndicator
      Row_Number() Over (PARTITION BY CodIes1 ORDER BY AC07)             AC07, --AllowanceCharge/SequenceNumeric
      TO_CHAR(AC08,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) AC08, --AllowanceCharge/Amount
      TO_CHAR(AC09,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) AC09, --AllowanceCharge/BaseAmount
      AC10,                                                                    --AllowanceCharge/AccountingCostCode
      AC11,                                                                    --AllowanceCharge/AccountingCost
      TO_CHAR(AC12,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) AC12  --AllowanceCharge/PerUnitAmount
    FROM TMP_DocXChange_AC;

  --INVOICE
  END IF;
END;

PROCEDURE PrepXMLDesAdvTecNet(pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) IS
  pTecNetComNRI NUMBER;
  pTecNetTipUM  NUMBER;

  DC_SERIE      VARCHAR2(20);
  M_SIMBOL      VARCHAR2(3);
  vCodPart      NUMBER(20);
  vClasaPart    NUMBER(20);
  vIDLaClient   VARCHAR2(100);
  vGLNLaClient  VARCHAR2(100);
BEGIN
  PrepFirmaAdr(pCodIes);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DESADVTECNET&apos;;

  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
  END IF;

  pTecNetComNRI  := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;) ;
  pTecNetTipUM   := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetTipUM&apos;  ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;1&apos;) ;

  SELECT
    p.codpart,
    p.codclasa,
    dc.serie,
    SubStr(M.SIMBOL,1,3),
    pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies),
    pkg_exportedi.GetGLNLaClient(sliv.edi_parttip, i.codies)
  INTO
    vCodPart,
    vClasaPart,
    DC_SERIE,
    M_SIMBOL,
    vIDLaClient,
    vGLNLaClient
  FROM iesiri i
    LEFT JOIN npart        p    ON p.codpart      = i.partener
    LEFT JOIN nmonede      m    ON m.codmoneda    = Coalesce(i.moneda,0)
    LEFT JOIN doccarnete   dc   ON dc.codcarnet   = i.carnetdoc
    LEFT JOIN nagenda      sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes
    AND Coalesce(sliv.edi_exptip,0) = 2
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;);

  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  INSERT INTO TMP_DESADVTECNET
  SELECT
    CASE
      WHEN Nullif(slivr.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
      ELSE slivr.EDI_SUBDIREXP||&apos;\&apos;
    END||
    Coalesce(pcf.codfiscal,p.den_part)||&apos;_&apos;||To_Char(I.DataDoc,&apos;yyyymmdd&apos;)||&apos;_&apos;||I.NrDoc||&apos;_&apos;||Coalesce(f.Codfiscal,f.denfirma)     FileName,
    To_Char(I.NrDoc)                                                                                                                Invoice01,--DocNumber
    To_Char(I.DataDoc, &apos;dd/mm/yyyy&apos;)                                                                                                Invoice02,--DocDate
    DC_SERIE                                                                                                                        Invoice03,--ExtDocNumber -&gt; seria si nr tipizat
    To_Char(I.DataDoc, &apos;dd/mm/yyyy&apos;)                                                                                                Invoice04,--DeliveryDate
    CASE
      WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
      WHEN pTecNetComNRI = 1
      THEN Max(Coalesce(COM.NRI,To_Char(COM.NrDoc))) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
      ELSE Max(To_Char(COM.NrDoc))                   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice05,--OrderNumber -&gt; Comanda
    CASE
      WHEN vOrderDate IS NOT NULL THEN vOrderDate
      ELSE Max(To_Char(COM.DataDoc, &apos;dd/mm/yyyy&apos;))   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice06,--OrderDate
    COALESCE(ssoc.GLN, slivr.GLN)                                                                                                   Invoice07,--GlnBuyer
    CASE WHEN slivr.edi_parttip = 5 THEN vGLNLaClient ELSE ss.gln END                                                               Invoice08,--GlnSupplier
    slivr.GLN                                                                                                                       Invoice09,--GlnDeliveryPoint
    &apos;1&apos;                                                                                                                             Invoice10,--Numberofpacking
    &apos;201&apos;                                                                                                                           Invoice11,--Typeofpacking
    CASE
      WHEN Coalesce(slivr.edi_parttip,0) = 0 THEN ss.gln
      WHEN slivr.edi_parttip = 1 THEN slivr.edi_partid
      WHEN slivr.edi_parttip = 2 THEN f.codfiscal
      WHEN slivr.edi_parttip = 3 THEN slivr.gln
      ELSE                            vIDLaClient
    END                                                                                                                             Invoice12,--BuyerCodeAsSupplierNo -&gt; Camp de identificare a vanzatorului
    To_Char(I.NrDoc)                                                                                                                Invoice13,--DeliveryNoteNumber
    To_Char(I.DataDoc, &apos;dd/mm/yyyy&apos;)                                                                                                Invoice14,--DespatchDate
    m_simbol                                                                                                                        Invoice15,--CurrencyEancom -&gt; Moneda document
    Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          InvLine01,--LineNo
    CASE slivr.edi_objtip
      WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
      WHEN 2 THEN ac.codextern
      WHEN 3 THEN o.codextern
      WHEN 4 THEN o.codintern
      WHEN 5 THEN o.codvamal
      WHEN 6 THEN To_Char(o.codplu)
      WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      WHEN 8 THEN ac.codlaclient
      WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = um.codum1)
    END                                                                                                                             InvLine02,--Gtin -&gt; Cod EAN
    CASE slivr.edi_objtip
      WHEN 2 THEN Coalesce(ac.CodLaClient,ac.CodExtern)
      ELSE Coalesce(ac.CodExtern,ac.CodLaClient)
    END                                                                                                                             InvLine03,--BuyerCode -&gt; Codul intern al cumparatorului
    O.CodIntern                                                                                                                     InvLine04,--SellerCode -&gt; Codul intern al vanzatorului
    NULL                                                                                                                            InvLine05,--ExpiryDate
    Coalesce(AC.Denumire, O.Denumire)                                                                                               InvLine06,--ProductName
    TO_CHAR(I1.CANT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                  InvLine07,--DespatchQuantity
    TO_CHAR(I1.CANT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                  InvLine08,--OrderedQuantity
    TO_CHAR(U1.PARITATE,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                       InvLine09,--NumberOfSubunitsInUnit-&gt;Numarul de unitati de vanzare in bax
    TO_CHAR(I1.PU*Coalesce(UM.PARITATE,1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                     InvLine10,--GrossPrice
    TO_CHAR((I1.PU-I1.PRETORIG*I1.COEFDISCMAJ)*Coalesce(UM.PARITATE,1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)        InvLine11,--ItemDiscountAmount
    TO_CHAR(I1.PRETORIG*I1.COEFDISCMAJ*Coalesce(UM.PARITATE,1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                InvLine12,--NetPrice
    NULL                                                                                                                            InvLine13,--BatchNumber
    Upper(
      Coalesce(
        CASE
          WHEN slivr.edi_denum = 1 THEN UM.DEN_EANCOM
          WHEN slivr.edi_denum = 2 THEN UM.DEN_UM1
          WHEN slivr.edi_denum = 3 THEN UM.CODEXTERN
        END,UM.DEN_EANCOM,UM.Den_UM1
      )
    )                                                                                                                               InvLine14,--UMEancom
    NULL                                                                                                                            InvLine15,--ShippingContainerCode??
    NULL                                                                                                                            InvLine16,--GrossWeight
    NULL                                                                                                                            InvLine17,--Height
    NULL                                                                                                                            InvLine18,--NetWeight
    NULL                                                                                                                            InvLine19,--Volumeoftheconsignment
    NULL                                                                                                                            InvLine20,--BestBeforeDate
    NULL                                                                                                                            InvLine21,--DeliveryPlaceProduct
    NULL                                                                                                                            InvLine22,--VariableWeight
    TO_CHAR(
      PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
    )                                                                                                                               InvLine23,--VatPrc
    TO_CHAR(
      CASE WHEN I1.CANT = 0 THEN I1.TVA ELSE I1.TVA/I1.CANT*Coalesce(UM.PARITATE,1) END
      ,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               InvLine24,--VatValue
    -- Linii pentru validare Export
    CASE WHEN vTecNetDocType = 3 THEN 0 ELSE Min(Coalesce(i1.Cant,0))      OVER (PARTITION BY i.codies) END                         MinCant,
    CASE WHEN vTecNetDocType = 3 THEN 0 ELSE Max(Coalesce(i1.Cant,0))      OVER (PARTITION BY i.codies) END                         MaxCant,
    Max(
      CASE
        WHEN Upper(
               Coalesce(
                 CASE
                   WHEN slivr.edi_denum = 1 THEN UM.DEN_EANCOM
                   WHEN slivr.edi_denum = 2 THEN UM.DEN_UM1
                   WHEN slivr.edi_denum = 3 THEN UM.CODEXTERN
                 END,UM.DEN_EANCOM,UM.Den_UM1
               )
             ) IN (&apos;PCE&apos;,&apos;KGM&apos;,&apos;LTR&apos;)
        THEN 0
        ELSE 1
      END
    ) OVER (PARTITION BY i.codies)                                                                                                  UMEancomErr
  FROM TMP_EDI_IES1 ti1
    CROSS JOIN TMP_FIRMA_ADR f
    LEFT JOIN iesiri       i      ON i.codies = ti1.codies
    LEFT JOIN iesiri1      i1     ON i1.codies1 = ti1.codies1
    LEFT JOIN nagenda      slivr  ON slivr.codagenda = i.codlocatie
    LEFT JOIN nagenda      ssoc   ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN npart        p      ON p.codpart = i.partener
    LEFT JOIN npartcodfisc pcf    ON pcf.cod_codfiscal = i.codfiscal
    LEFT JOIN nartobj      o      ON o.codobiect = i1.codobiect
    LEFT JOIN nart         a      ON a.codarticol = o.codarticol
    LEFT JOIN nart1        a1     ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
    LEFT JOIN ntva1        t1     ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    LEFT JOIN num1         u1     ON u1.codum1 = i1.umsec
    LEFT JOIN num1         um     ON um.codum = u1.codum AND CASE pTecNetTipUM WHEN 2 THEN um.codum1-u1.codum1 ELSE um.secundara END = 0
    LEFT JOIN nartcli      ac     ON ac.codartcli = ti1.codartcli
    LEFT JOIN ieslink      ilc    ON ilc.codies1 = i1.codies1 AND ilc.codliniecomanda IS NOT NULL
    LEFT JOIN cmdlivrlink  cl     ON cl.codcomanda1 = ilc.codliniecomanda
    LEFT JOIN comanda1     com1   ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
    LEFT JOIN comanda      com    ON com.codcomanda = com1.codcomanda
    LEFT JOIN nagenda      ss     ON ss.codsubunit = i.subunitatea
  ORDER BY i1.indexlocal, i1.codies1;

  -- InvLine15 este obligatoriu si daca nu e completat incercam sa generam un cod SSCC din GlnSupplier
  UPDATE TMP_DESADVTECNET
  SET InvLine15 = RPad(Invoice08, 17, &apos;0&apos;)||GET_CHECK_DIGIT(RPad(Invoice08, 17, &apos;0&apos;))
  WHERE InvLine15 IS NULL;

  COMMIT;
END;

FUNCTION GetXMLDocTecNetData(pCodIes NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal IS
  crsResult     crsGlobal;
  pTecNetComNRI NUMBER;
  pTecNetTipUM  NUMBER;

  DC_SERIE      VARCHAR2(20);
  M_SIMBOL      VARCHAR2(3);

  vTotalWoVAT   NUMBER(20, 2);
  vTotalLinii   NUMBER(20, 2);
  vDif          NUMBER(20,4);
  vOldLVal      NUMBER(20,4);
  vNewLVal      NUMBER(20,4);
  vLineCor      NUMBER(20,4);
  vLoopCount    NUMBER(5);

  vCodPart      NUMBER(20);
  vClasaPart    NUMBER(20);
  vIDLaClient   VARCHAR2(100);
  vGLNLaClient  VARCHAR2(100);
  cDocNrCuSerie NUMBER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;TECNETDocNumberSerie&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;));
BEGIN
  PrepFirmaAdr(pCodIes);
  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vTecNetDocType       := 0;
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
    vDespatchNumber      := NULL;
    vDespatchDate        := NULL;
  END IF;

  pTecNetComNRI  := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;) ;
  pTecNetTipUM   := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetTipUM&apos;  ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;1&apos;) ;

  SELECT
    DC.SERIE,
    SubStr(M.SIMBOL,1,3),
    CASE WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)-Round(I.TvaDoc,2) ELSE Round(I.ValDoc-I.TvaDoc,2) END,
    p.codpart,
    p.codclasa,
    pkg_exportedi.GetIDLaClient (sliv.edi_parttip, i.codies),
    pkg_exportedi.GetGLNLaClient(sliv.edi_parttip, i.codies)
  INTO
    DC_SERIE,
    M_SIMBOL,
    vTotalWoVAT,
    vCodPart,
    vClasaPart,
    vIDLaClient,
    vGLNLaClient
  FROM iesiri i
    LEFT JOIN nmonede    m    ON m.codmoneda    = Coalesce(i.moneda,0)
    LEFT JOIN doccarnete dc   ON dc.codcarnet   = i.carnetdoc
    LEFT JOIN npart      p    ON p.codpart      = i.partener
    LEFT JOIN nagenda    sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_TECNETL&apos;;
  INSERT INTO TMP_TECNETL(
    CODIES1,
    LineNo,
    Cant,
    GrossPrice,
    ItemDiscountAmount,
    NetPrice,
    NetPriceCorection,
    CodObiect
  )
  SELECT
    I1.CODIES1,
    ROW_NUMBER() OVER (ORDER BY i1.indexlocal, i1.codies1)              AS LineNo,
    Round(I1.CANT/Coalesce(UM.PARITATE,1), 4)                           AS Cant,
    Round(I1.PU*Coalesce(UM.PARITATE,1), 4)                             AS GrossPrice,
    Round((I1.PU-I1.PRETORIG*I1.COEFDISCMAJ)*Coalesce(UM.PARITATE,1),4) AS ItemDiscountAmount,
    Round(I1.PRETORIG*I1.COEFDISCMAJ*Coalesce(UM.PARITATE,1),4)         AS NetPrice,
    0                                                                   AS NetPriceCorection,
    I1.CodObiect
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    LEFT JOIN num1     u1 ON u1.codum1 = i1.umsec
    LEFT JOIN num1     um ON um.codum  = u1.codum AND CASE pTecNetTipUM WHEN 2 THEN um.codum1-u1.codum1 ELSE um.secundara END = 0
  WHERE i.codies = pCodIes
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;);
  UPDATE TMP_TECNETL SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  vLoopCount := 0;
  LOOP
    vLoopCount := vLoopCount + 1;
    SELECT Sum( Round((NetPrice+NetPriceCorection)*Cant,2)) INTO vTotalLinii FROM TMP_TECNETL;
    IF (vTotalWoVAT = vTotalLinii) OR vLoopCount &gt; 10 THEN -- incerc maxim 10 pasi sa corectez preturile
      EXIT;
    ELSE
      vDif  := vTotalWoVAT - vTotalLinii;
      FOR vRec IN (
        SELECT CODIES1, CANT, NETPRICE, NETPRICECORECTION FROM TMP_TECNETL ORDER BY LineNo
      ) LOOP
        vOldLVal := Round(vRec.CANT * (vRec.NETPRICE + vRec.NETPRICECORECTION), 2);
        vLineCor := Trunc(vDif / vRec.CANT, 4);
        vNewLVal := Round(vRec.CANT * (vRec.NETPRICE + vRec.NETPRICECORECTION + vLineCor), 2);
        IF vNewLVal &lt;&gt; vOldLVal THEN
          UPDATE TMP_TECNETL SET NETPRICECORECTION = NETPRICECORECTION + vLineCor WHERE CODIES1 = vRec.CODIES1 ;
          vDif := vDif + vOldLVal - vNewLVal ;
        END IF;
        IF vDif = 0 THEN
          EXIT;
        END IF;
      END LOOP;
    END IF;
    EXIT;
  END LOOP;

  UPDATE TMP_TECNETL
  SET NetPrice = NetPrice + NetPriceCorection, ItemDiscountAmount = ItemDiscountAmount + NetPriceCorection
  WHERE NetPriceCorection &lt;&gt; 0;

  OPEN crsResult FOR
  SELECT
    CASE
      WHEN Nullif(slivr.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
      ELSE slivr.EDI_SUBDIREXP||&apos;\&apos;
    END||
    Coalesce(pcf.codfiscal,p.den_part)||&apos;_&apos;||
    To_Char(I.DataDoc,&apos;yyyymmdd&apos;)||&apos;_&apos;||To_Char(I.NrDoc)||&apos;_&apos;||
    Coalesce(f.Codfiscal,f.denfirma)                                                                                                FileName,
    Trim(Coalesce(CASE cDocNrCuSerie WHEN 1 THEN i.seriadoc END, &apos;&apos;)||&apos; &apos;||To_Char(I.NrDoc))                                        Invoice01,--DocNumber
    To_Char(I.DataDoc, &apos;dd/mm/yyyy&apos;)                                                                                                Invoice02,--DocDate
    DC_SERIE                                                                                                                        Invoice03,--ExtDocNumber -&gt; seria si nr tipizat
    CASE
      WHEN vTecNetDocType &gt;= 2 THEN To_Char(vTecNetDocType, &apos;fm0&apos;)
      WHEN STORN.CODIES IS NOT NULL THEN &apos;4&apos;
      ELSE &apos;2&apos;
    END                                                                                                                             Invoice04,--DocType
    CASE
      WHEN vTecNetDocType &gt; 2 THEN vTecNetRefNumber
      WHEN vTecNetDocType = 2 THEN CAST(NULL AS VARCHAR2(255))
      WHEN STORN.CODIES IS NOT NULL THEN To_Char(Storn.NrDoc)
      ELSE CAST(NULL AS VARCHAR2(255))
    END                                                                                                                             Invoice05,--RefferedInvoiceNumber -&gt; factura corectata
    CASE
      WHEN vTecNetDocType &gt; 2 THEN vTecNetRefDate
      WHEN vTecNetDocType = 2 THEN CAST(NULL AS VARCHAR2(10))
      WHEN STORN.CODIES IS NOT NULL THEN To_Char(Storn.DataDoc, &apos;dd/mm/yyyy&apos;)
      ELSE CAST(NULL AS VARCHAR2(10))
    END                                                                                                                             Invoice06,--RefferedInvoiceDate
    Coalesce(vReceiveAdviceNumber, i.NrNir)                                                                                         Invoice07,--ReceiveAdviceNumber -&gt; Numarul NIR-ului destinatie
    Coalesce(vReceiveAdviceDate  , To_Char(i.DataNir, &apos;dd/mm/yyyy&apos;))                                                                Invoice08,--ReceiveAdviceDate
    CASE
      WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
      WHEN pTecNetComNRI = 1
      THEN Max(Coalesce(COM.NRI,To_Char(COM.NrDoc))) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
      ELSE Max(To_Char(COM.NrDoc))                   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice09,--OrderNumber -&gt; Comanda
    CASE
      WHEN vOrderDate IS NOT NULL THEN vOrderDate
      ELSE Max(To_Char(COM.DataDoc, &apos;dd/mm/yyyy&apos;))   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice10,--OrderDate
    CASE
      WHEN vDespatchNumber IS NOT NULL THEN vDespatchNumber
      ELSE Max(To_Char(AE.NrDoc))                    KEEP (DENSE_RANK LAST ORDER BY Coalesce(AE.CodIes     ,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice11,--DespatchAdviceNumber -&gt; Aviz de Expeditie
    CASE
      WHEN vDespatchdate IS NOT NULL THEN vDespatchDate
      ELSE Max(To_Char(AE.DataDoc, &apos;dd/mm/yyyy&apos;))    KEEP (DENSE_RANK LAST ORDER BY Coalesce(AE.CodIes     ,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             Invoice12,--DespatchAdviceDate
    COALESCE(ssoc.GLN, slivr.GLN)                                                                                                   Invoice13,--GlnBuyer
    CASE WHEN slivr.edi_parttip = 5 THEN vGLNLaClient ELSE ss.gln END                                                               Invoice14,--GlnSupplier
    slivr.GLN                                                                                                                       Invoice15,--GlnDeliveryPoint
    CASE
      WHEN Coalesce(slivr.edi_parttip,0) = 0 THEN ss.gln
      WHEN slivr.edi_parttip = 1 THEN slivr.edi_partid
      WHEN slivr.edi_parttip = 2 THEN f.codfiscal
      WHEN slivr.edi_parttip = 3 THEN slivr.gln
      ELSE                            vIDLaClient
    END                                                                                                                             Invoice16,--BuyerCodeAsSupplierNo -&gt; Camp de identificare a vanzatorului
    f.codfiscal                                                                                                                     Invoice17,--SupplierVatNumber -&gt; CUI furnizor
    m_simbol                                                                                                                        Invoice18,--CurrencyEancom -&gt; Moneda document
    SubStr(I.OBS,1,255)                                                                                                             Invoice19,--FreeTextMutuallyDefined -&gt; Max.255 car - Text liber
    NULL                                                                                                                            Invoice20,--FreeTextRegulatoryInfo  -&gt; Max.255 car - Mentiuni obligatorii conform Codului Fiscal
    ( SELECT To_Char( Coalesce (Min(O.Termen), I.DataDoc) , &apos;dd/mm/yyyy&apos;)
      FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      WHERE g.coddoc = i.codies AND g.tipdoc = i.tipdoc
        AND g.semnificatie &lt;&gt; 240
    )                                                                                                                               Invoice21,--DueDate
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)-Round(I.TvaDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)
      END,
      &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           Invoice22,--TotalWoVAT
    TO_CHAR(I.TvaDoc,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                            Invoice23,--TotalVAT
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
      END,
      &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           Invoice24,--TotalInclVAT
    DEL.DELegat                                                                                                                     Invoice25,--Delegate
    DEL.CNP ||&apos;/&apos;||DEL.SERIedoc||DEL.NRdoc                                                                                          Invoice26,--DelegateIdent -&gt; CNP/Buletin delegat
    DEL.Obs                                                                                                                         Invoice27,--TransportType -&gt; Transportatorul
    DEL.NRTRANSP                                                                                                                    Invoice28,--TransportIdent-&gt; Identificare transportator
    TNL.LINENO                                                                                                                      InvLine01,--LineNo
    CASE slivr.edi_objtip
      WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
      WHEN 2 THEN ac.codextern
      WHEN 3 THEN o.codextern
      WHEN 4 THEN o.codintern
      WHEN 5 THEN o.codvamal
      WHEN 6 THEN To_Char(o.codplu)
      WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      WHEN 8 THEN ac.codlaclient
      WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = um.codum1)
    END                                                                                                                             InvLine02,--Gtin -&gt; Cod EAN
    CASE slivr.edi_objtip
      WHEN 2 THEN Coalesce(ac.CodLaClient,ac.CodExtern)
      ELSE Coalesce(ac.CodExtern,ac.CodLaClient)
    END                                                                                                                             InvLine03,--BuyerCode -&gt; Codul intern al cumparatorului
    O.CodIntern                                                                                                                     InvLine04,--SellerCode -&gt; Codul intern al vanzatorului
    Upper(
      Coalesce(
        CASE
          WHEN slivr.edi_denum = 1 THEN UM.DEN_EANCOM
          WHEN slivr.edi_denum = 2 THEN UM.DEN_UM1
          WHEN slivr.edi_denum = 3 THEN UM.CODEXTERN
        END,UM.DEN_EANCOM,UM.Den_UM1
      )
    )                                                                                                                               InvLine05,--UMEancom
    &apos;false&apos;                                                                                                                         InvLine06,--ReturnPackage -&gt; ambalaj returnabil true/false
    Coalesce(AC.Denumire, O.Denumire)                                                                                               InvLine07,--ProductName
    TO_CHAR(TNL.CANT,               &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine08,--DeliveredQuantity
    TO_CHAR(TNL.CANT,               &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine09,--InvoicedQuantity
    TO_CHAR(U1.PARITATE,            &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine10,--NumberOfSubunitsInUnit-&gt;Numarul de unitati de vanzare in bax
    TO_CHAR(TNL.GROSSPRICE,         &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine11,--GrossPrice
    TO_CHAR(TNL.ITEMDISCOUNTAMOUNT, &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine12,--ItemDiscountAmount
    TO_CHAR(TNL.NETPRICE,           &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                           InvLine13,--NetPrice
    &apos;0.00&apos;                                                                                                                          InvLine14,--EcoTaxAmount
    &apos;0.00&apos;                                                                                                                          InvLine15,--EnvTaxAmount
    TO_CHAR(
      PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
    )                                                                                                                               InvLine16,--VatPrc
    -- Linii pentru validare Export
    CASE WHEN vTecNetDocType = 3 THEN 0 ELSE Min(Coalesce(i1.Cant,0))      OVER (PARTITION BY i.codies) END                         MinCant,
    CASE WHEN vTecNetDocType = 3 THEN 0 ELSE Max(Coalesce(i1.Cant,0))      OVER (PARTITION BY i.codies) END                         MaxCant,
    CASE WHEN vTecNetDocType &gt; 0 THEN 0 ELSE Min(Coalesce(storn.codies,0)) OVER (PARTITION BY i.codies) END                         MinCodStorn,
    CASE WHEN vTecNetDocType &gt; 0 THEN 0 ELSE Max(Coalesce(storn.codies,0)) OVER (PARTITION BY i.codies) END                         MaxCodStorn,
    Max(
      CASE
        WHEN Upper(
               Coalesce(
                 CASE
                   WHEN slivr.edi_denum = 1 THEN UM.DEN_EANCOM
                   WHEN slivr.edi_denum = 2 THEN UM.DEN_UM1
                   WHEN slivr.edi_denum = 3 THEN UM.CODEXTERN
                 END,UM.DEN_EANCOM,UM.Den_UM1
               )
             ) IN (&apos;PCE&apos;,&apos;KGM&apos;,&apos;LTR&apos;)
        THEN 0
        ELSE 1
      END
    ) OVER (PARTITION BY i.codies)                                                                                                  UMEancomErr
  FROM iesiri i
    CROSS JOIN TMP_FIRMA_ADR f
    INNER JOIN iesiri1     i1     ON i1.codies = i.codies
    INNER JOIN nagenda     slivr  ON slivr.codagenda = i.codlocatie
    LEFT JOIN TMP_TECNETL  tnl    ON tnl.codies1 = i1.codies1
    LEFT JOIN nagenda      ssoc   ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN nparttr      del    ON del.codparttr = i.delegat
    LEFT JOIN npart        p      ON p.codpart = i.partener
    LEFT JOIN npartcodfisc pcf    ON pcf.cod_codfiscal = i.codfiscal
    LEFT JOIN nartobj      o      ON o.codobiect = i1.codobiect
    LEFT JOIN nart         a      ON a.codarticol = o.codarticol
    LEFT JOIN nart1        a1     ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
    LEFT JOIN ntva1        t1     ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    LEFT JOIN num1         u1     ON u1.codum1 = i1.umsec
    LEFT JOIN num1         um     ON um.codum = u1.codum AND CASE pTecNetTipUM WHEN 2 THEN um.codum1 - u1.codum1 ELSE um.secundara END = 0
    LEFT JOIN nartcli      ac     ON ac.codartcli = tnl.codartcli
    LEFT JOIN ieslink      ilae   ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
    LEFT JOIN iesiri1      ae1    ON ae1.codies1 = ilae.codlinieaviz
    LEFT JOIN iesiri       ae     ON ae.codies = ae1.codies
    LEFT JOIN ieslink      ilc    ON ilc.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilc.codliniecomanda IS NOT NULL
    LEFT JOIN cmdlivrlink  cl     ON cl.codcomanda1 = ilc.codliniecomanda
    LEFT JOIN comanda1     com1   ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
    LEFT JOIN comanda      com    ON com.codcomanda = com1.codcomanda
    LEFT JOIN nagenda      ss     ON ss.codsubunit = i.subunitatea
    LEFT JOIN iesiri1      storn1 ON storn1.codies1 = CASE
                                                        WHEN                                               Coalesce(i1.codies1storno ,0) &lt;&gt; 0 THEN i1.codies1storno
                                                        WHEN Coalesce(i1.tipdocimp, 0) IN (19, 20, 26) AND Coalesce(i1.codliniedocimp,0) &lt;&gt; 0 THEN i1.codliniedocimp
                                                      END
    LEFT JOIN stingere     sstorn ON sstorn.codstingatorpif = i1.codobligstorno
    LEFT JOIN obligpif     ostorn ON ostorn.codobligpif = sstorn.codstinspif
    LEFT JOIN general      gstorn ON gstorn.codgeneral = ostorn.codgeneral AND gstorn.tipdoc = i.tipdoc
    LEFT JOIN iesiri       storn  ON storn.codies = Coalesce(storn1.codies, gstorn.coddoc)
  WHERE i.codies = pCodIes
    AND Coalesce(slivr.edi_exptip,0) = 2
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)
  ORDER BY i1.indexlocal, i1.codies1;

 Return crsResult;
END;

PROCEDURE PrepXMLDocEdiNet(pCodIes NUMBER, pBULK NUMBER DEFAULT 0) IS
  vCodComanda       NUMBER(20);
  vCodLivr          NUMBER(20);
  vNrLivr           NUMBER(20);
  vDataLivr         DATE;
  vIDLaClient       VARCHAR2(100);
  vEdi_ExpCumul     NUMBER;
  vEdi_ObjTip       NUMBER;
  vEdi_DenUM        NUMBER;
  vCodPart          NUMBER;
  vCodClasaP        NUMBER;
  vTipIes           NUMBER;
  vAn               NUMBER;
  vLuna             NUMBER;
  vDataDoc          DATE;
  pTecNetComNRI     NUMBER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos;    ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;));
  cEDINETDocIdSerie NUMBER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;EDINETDocIdSerie&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;));
BEGIN
  PrepFirmaAdr(pCodIes);
  --PG--CALL create_wm_temps_flag(&apos;TMP_EDINET&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDINET_H&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDINET_D&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDINET_S&apos;;

  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vEdiNetDocType       := 1;
    vEdiNetRefNumber     := NULL;
    vEdiNetRefDate       := NULL;
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
  END IF;

  SELECT pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies)
  INTO   vIDLaClient
  FROM iesiri i INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  IF Coalesce(vEdiNetDocType,1) = 1 THEN
    SELECT
      CASE Count(DISTINCT s.codies) WHEN 0 THEN 2 WHEN 1 THEN 4                     ELSE -4   END,
      CASE Count(DISTINCT s.codies)               WHEN 1 THEN To_Char(Max(S.NrDoc)) ELSE &apos;&apos;   END,
      CASE Count(DISTINCT s.codies)               WHEN 1 THEN Max(S.DataDoc)        ELSE NULL END
    INTO
      vEdiNetDocType,
      vEdiNetRefNumber,
      vEdiNetRefDate
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies    = i.codies
      LEFT  JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL AND i.tipdoc = 26
      LEFT  JOIN iesiri1 ae1  ON ae1.codies1  = ilae.codlinieaviz
      LEFT  JOIN iesiri1 s1   ON s1.codies1   = CASE
                                                  WHEN                                                Coalesce(AE1.CODIES1STORNO ,0) &lt;&gt; 0 THEN AE1.CODIES1STORNO
                                                  WHEN                                                Coalesce(I1.CODIES1STORNO  ,0) &lt;&gt; 0 THEN I1.CODIES1STORNO
                                                  WHEN Coalesce(AE1.TIPDOCIMP, 0) IN (19, 20, 26) AND Coalesce(AE1.CODLINIEDOCIMP,0) &lt;&gt; 0 THEN AE1.CODLINIEDOCIMP
                                                  WHEN Coalesce(I1.TIPDOCIMP,  0) IN (19, 20, 26) AND Coalesce(I1.CODLINIEDOCIMP ,0) &lt;&gt; 0 THEN I1.CODLINIEDOCIMP
                                                END
      LEFT  JOIN iesiri s ON s.codies = s1.codies
    WHERE i.codies = pCodIes AND s.codies IS NOT NULL;
  END IF;

  SELECT
    CASE WHEN Max(Coalesce(ae.codies, 0)) = 0 THEN Max(Coalesce(l.CodLivr, 0)) ELSE -1 END,
    Max(ae.nrdoc)   KEEP (DENSE_RANK LAST ORDER BY Coalesce(ae.codies, 0)),
    Max(ae.datadoc) KEEP (DENSE_RANK LAST ORDER BY Coalesce(ae.codies, 0)),
    CASE WHEN Max(Coalesce(c1.codcomanda, 0)) = Min(Coalesce(c1.codcomanda, 0)) THEN Max(Coalesce(c1.codcomanda, 0)) ELSE 0 END
  INTO
    vCodLivr,
    vNrLivr,
    vDataLivr,
    vCodComanda
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
    LEFT JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz
    LEFT JOIN iesiri ae ON ae.codies = ae1.codies
    LEFT JOIN livr l ON l.codies = Coalesce(ae.codies, i.codies) AND l.tiplivr = Coalesce(ae.tipdoc, i.tipdoc)
    LEFT JOIN ieslink ilc ON ilc.codies1 = Coalesce(ae1.codies1, i1.codies1) AND ilc.codliniecomanda IS NOT NULL
    LEFT JOIN cmdlivrlink cl ON cl.codcomanda1 = ilc.codliniecomanda
    LEFT JOIN comanda1 c1 ON c1.codcomanda1 = Coalesce(cl.codliniecomanda, ilc.codliniecomanda)
  WHERE i.codies = pCodIes AND NOT i1.tiplinie IN (&apos;G&apos;, &apos;T&apos;);

  IF vCodComanda &gt; 0 AND vOrderNumber IS NULL AND vOrderDate IS NULL THEN
    SELECT Coalesce(CASE WHEN pTecNetComNRI = 1 THEN NRI END, To_Char(NrDoc)), To_Char(DataDoc, &apos;yyyy-mm-dd&apos;)||&apos;T00:00:00&apos;
    INTO vOrderNumber, vOrderDate
    FROM Comanda
    WHERE CodComanda = vCodComanda;
  END IF;

  IF vCodLivr &gt; 0 THEN
    SELECT NrLivr, DataLivr
    INTO vNrLivr, vDataLivr
    FROM livr
    WHERE CodLivr = vCodLivr;
  END IF;

  INSERT INTO TMP_EDINET_H
  SELECT
    CASE WHEN Nullif(slivr.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos; ELSE slivr.EDI_SUBDIREXP||&apos;\&apos; END||
    To_Char(I.NrDoc)||To_Char(I.DataDoc, &apos;yyyymmdd&apos;)||&apos;_&apos;||SUB.CIF                                                                  FileName,
    Trim(Coalesce(CASE cEDINETDocIdSerie WHEN 1 THEN i.seriadoc END, &apos;&apos;)||&apos; &apos;||To_Char(I.NrDoc))                                    H01,--InvoiceNumber
    To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                                                                                                H02,--Date
    To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                                                                                                H03,--InvoiceIssueDate
    To_Char(Coalesce(O.Termen, I.DataDoc), &apos;yyyy-mm-dd&apos;)                                                                            H04,--InvoiceDueDate
    Trunc(Coalesce(O.Termen, I.DataDoc)) - Trunc(I.DataDoc)                                                                         H05,--PaymentTerms
    &apos;3&apos;                                                                                                                             H06,--PaymentTermsQualifier (3 = fixed date)
    &apos;42&apos;                                                                                                                            H07,--PaymentMethod -&gt; Code
    &apos;Transfer bancar&apos;                                                                                                               H08,--PaymentMethod -&gt; Description
    SubStr(M.SIMBOL,1,3)                                                                                                            H09,--InvoiceCurrencyCoded
    CASE WHEN Abs(vEdiNetDocType) = 3 THEN &apos;C&apos; ELSE &apos;O&apos; END                                                                         H10,--InvoicePurposeCoded  (C-corrected, O-commercial)
    CASE WHEN Abs(vEdiNetDocType) = 4 THEN &apos;R&apos; ELSE &apos;O&apos; END                                                                         H11,--DocumentRole         (O-original,  A-Storno, R-retur.old - revenit)
    SubStr(I.OBS,1,1000)                                                                                                            H12,--Comment              (Max.1000 car)
    CASE WHEN vEdiNetDocType &gt; 2 THEN vEdiNetRefNumber END                                                                          H13,--RefInvoiceNumber
    CASE WHEN vEdiNetDocType &gt; 2 THEN To_Char(vEdiNetRefDate, &apos;yyyy-mm-dd&apos;) END                                                     H14,--RefInvoiceDate
    CASE WHEN Abs(vEdiNetDocType) = 4 THEN &apos;RETURN&apos; END                                                                             H15,--InvType
    vOrderNumber                                                                                                                    O01,--OrderParty -&gt; BuyerOrderNumber
    vOrderDate                                                                                                                      O02,--OrderParty -&gt; BuyerOrderDate
    CASE WHEN vCodLivr &lt;&gt; 0 THEN To_Char(vDataLivr, &apos;YYYY-MM-DD&quot;T&quot;hh:mm:ss&apos;) END                                                    L01,--DeliveryParty -&gt; DeliveryDate
    CASE WHEN vCodLivr &lt;&gt; 0 THEN To_Char(vNrLivr) END                                                                               L02,--DeliveryParty -&gt; DeliveryDocumentNumber
    CASE WHEN vCodLivr &lt;&gt; 0 THEN To_Char(vDataLivr, &apos;yyyy-mm-dd&apos;) END                                                               L03,--DeliveryParty -&gt; DeliveryDocumentDate
    Coalesce(vReceiveAdviceNumber, i.NrNir)                                                                                         R01,--ReceivingAdviceParty -&gt; ReceivingAdviceNumber
    Coalesce(vReceiveAdviceDate  , To_Char(i.DataNir, &apos;yyyy-mm-dd&apos;))                                                                R02,--ReceivingAdviceParty -&gt; ReceivingAdviceDate
    ssoc.GLN                                                                                                                        C01,--BuyerParty -&gt; ILN
    pcf.codfiscal                                                                                                                   C02,--BuyerParty -&gt; TaxID
    p.den_part                                                                                                                      C03,--BuyerParty -&gt; Name
    ssoc.strada                                                                                                                     C04,--BuyerParty -&gt; Street
    ssoc.nr1                                                                                                                        C05,--BuyerParty -&gt; HouseNumber
    ssoc.codpostal                                                                                                                  C06,--BuyerParty -&gt; PostalCode
    lsoc.den_localit                                                                                                                C07,--BuyerParty -&gt; City
    tsoc.simbauto                                                                                                                   C08,--BuyerParty -&gt; Country

    ssoc.GLN                                                                                                                        F01,--InvoiceeParty -&gt; ILN
    p.den_part                                                                                                                      F02,--InvoiceeParty -&gt; Name
    ssoc.strada                                                                                                                     F03,--InvoiceeParty -&gt; Street
    ssoc.nr1                                                                                                                        F04,--InvoiceeParty -&gt; HouseNumber
    ssoc.codpostal                                                                                                                  F05,--InvoiceeParty -&gt; PostalCode
    lsoc.den_localit                                                                                                                F06,--InvoiceeParty -&gt; City
    tsoc.simbauto                                                                                                                   F07,--InvoiceeParty -&gt; Country
/*
    sfact.GLN                                                                                                                       F01,--InvoiceeParty -&gt; ILN
    sfact.obs                                                                                                                       F02,--InvoiceeParty -&gt; Name
    sfact.strada                                                                                                                    F03,--InvoiceeParty -&gt; Street
    sfact.nr1                                                                                                                       F04,--InvoiceeParty -&gt; HouseNumber
    sfact.codpostal                                                                                                                 F05,--InvoiceeParty -&gt; PostalCode
    lfact.den_localit                                                                                                               F06,--InvoiceeParty -&gt; City
    tfact.simbauto                                                                                                                  F07,--InvoiceeParty -&gt; Country
*/
    slivr.GLN                                                                                                                       D01,--ShipToParty -&gt; ILN
    slivr.obs                                                                                                                       D02,--ShipToParty -&gt; Name
    slivr.strada                                                                                                                    D03,--ShipToParty -&gt; Street
    slivr.nr1                                                                                                                       D04,--ShipToParty -&gt; HouseNumber
    slivr.codpostal                                                                                                                 D05,--ShipToParty -&gt; PostalCode
    llivr.den_localit                                                                                                               D06,--ShipToParty -&gt; City
    tlivr.simbauto                                                                                                                  D07,--ShipToParty -&gt; Country

    ssub.GLN                                                                                                                        V01,--SellerParty -&gt; ILN
    CASE
      WHEN Coalesce(slivr.edi_parttip,0) = 0 THEN ssoc.gln
      WHEN slivr.edi_parttip = 1 THEN slivr.edi_partid
      WHEN slivr.edi_parttip = 2 THEN f.codfiscal
      WHEN slivr.edi_parttip = 3 THEN slivr.gln
      ELSE vIDLaClient
    END                                                                                                                             V02,--SellerParty -&gt; BuyerSellerID
    f.Codfiscal                                                                                                                     V03,--SellerParty -&gt; TaxID
    f.nrj                                                                                                                           V04,--SellerParty -&gt; OperPermission
    fcont.nrcont                                                                                                                    V05,--SellerParty -&gt; BankAccount
    f.denfirma                                                                                                                      V06,--SellerParty -&gt; BankAccountOwner
    fbank.denumire                                                                                                                  V07,--SellerParty -&gt; BankName
    f.denfirma                                                                                                                      V08,--SellerParty -&gt; Name
    f.strada                                                                                                                        V09,--SellerParty -&gt; Street
    f.nr1                                                                                                                           V10,--SellerParty -&gt; HouseNumber
    f.codpostal                                                                                                                     V11,--SellerParty -&gt; PostalCode
    f.denlocalit                                                                                                                    V12,--SellerParty -&gt; City
    f.simbtara                                                                                                                      V13,--SellerParty -&gt; Country
    CAST(NULL AS VARCHAR2(100))                                                                                                     V14,--SellerParty -&gt; FiscalNumber
    f.capitals                                                                                                                      V15,--SellerParty -&gt; RegisteredCapitalReference
    --NumePrenume(f.numeadmin,f.prenumeadmin)
    CAST(NULL AS VARCHAR2(100))                                                                                                     VC1,--SellerParty -&gt; Contact -&gt; Person
    --f.telefon1
    CAST(NULL AS VARCHAR2(100))                                                                                                     VC2,--SellerParty -&gt; Contact -&gt; Tel

    ssub.GLN                                                                                                                        E01,--ShipFromParty -&gt; ILN
    f.denfirma                                                                                                                      E02,--ShipFromParty -&gt; Name
    ssub.strada                                                                                                                     E03,--ShipFromParty -&gt; Street
    ssub.nr1                                                                                                                        E04,--ShipFromParty -&gt; HouseNumber
    ssub.codpostal                                                                                                                  E05,--ShipFromParty -&gt; PostalCode
    lsub.den_localit                                                                                                                E06,--ShipFromParty -&gt; City
    tsub.simbauto                                                                                                                   E07 --ShipFromParty -&gt; Country
  FROM IESIRI I
    CROSS JOIN TMP_FIRMA_ADR F
    LEFT JOIN NMONEDE      M     ON M.CODMONEDA       = Coalesce(I.MONEDA,0)
    LEFT JOIN NPART        P     ON P.CODPART         = I.PARTENER
    LEFT JOIN NPARTCODFISC PCF   ON PCF.COD_CODFISCAL = I.CODFISCAL

    LEFT JOIN NAGENDA      SLIVR ON SLIVR.CODAGENDA   = I.CODLOCATIE
    LEFT JOIN NLOCALIT     LLIVR ON LLIVR.CODLOCALIT  = SLIVR.CODLOCALIT
    LEFT JOIN NJUDET       JLIVR ON JLIVR.CODJUDET    = LLIVR.CODJUDET
    LEFT JOIN NTARI        TLIVR ON TLIVR.CODTARA     = LLIVR.CODTARA

    LEFT JOIN NAGENDA      SSOC  ON SSOC.CODPART      = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT     LSOC  ON LSOC.CODLOCALIT   = SSOC.CODLOCALIT
    LEFT JOIN NJUDET       JSOC  ON JSOC.CODJUDET     = LSOC.CODJUDET
    LEFT JOIN NTARI        TSOC  ON TSOC.CODTARA      = LSOC.CODTARA

    LEFT JOIN NAGENDA      SFACT ON SFACT.CODAGENDA   = CASE WHEN SLIVR.SEDIUSOCIAL = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SEDIUSOCIAL IN (3,7) THEN SLIVR.CODAGENDA ELSE SSOC.CODAGENDA END
    LEFT JOIN NLOCALIT     LFACT ON LFACT.CODLOCALIT  = SFACT.CODLOCALIT
    LEFT JOIN NJUDET       JFACT ON JFACT.CODJUDET    = LFACT.CODJUDET
    LEFT JOIN NTARI        TFACT ON TFACT.CODTARA     = LFACT.CODTARA

    LEFT JOIN NSUBUNIT     SUB   ON SUB.CODSUBUNIT    = I.SUBUNITATEA
    LEFT JOIN NAGENDA      SSUB  ON SSUB.CODSUBUNIT   = I.SUBUNITATEA
    LEFT JOIN NLOCALIT     LSUB  ON LSUB.CODLOCALIT   = SSUB.CODLOCALIT
    LEFT JOIN NTARI        TSUB  ON TSUB.CODTARA      = LSUB.CODTARA

    LEFT JOIN NBANKCONT    FCONT ON FCONT.CODBANKCONT = F.CODBANKCONT
    LEFT JOIN NBANK        FBANK ON FBANK.CODBANK     = FCONT.CODBANK
    --LEFT JOIN NBANKCONT    CSUB  ON CSUB.CODBANKCONT  = SUB.CODBANKCONT
    --LEFT JOIN NBANK        BSUB  ON BSUB.CODBANK      = CSUB.CODBANK

    LEFT JOIN GENERAL      G     ON G.TIPDOC          = I.TIPDOC AND G.CODDOC = I.CODIES AND g.semnificatie &lt;&gt; 240
    LEFT JOIN OBLIGPIF     O     ON O.CODGENERAL      = G.CODGENERAL AND G.SEMNIFICATIE &lt;&gt; 240
  WHERE i.codies = pCodIes AND Coalesce(slivr.edi_exptip,0) = 3;

  SELECT l.Edi_ObjTip, Coalesce(l.Edi_ExpCumul,0), Coalesce(l.Edi_DenUM,0), i.Partener, p.codclasa, i.TipDoc, i.An, i.Luna, i.DataDoc
  INTO vEdi_ObjTip, vEdi_ExpCumul, vEdi_DenUM, vCodPart, vCodClasaP, vTipIes, vAn, vLuna, vDataDoc
  FROM IESIRI I
    INNER JOIN NAGENDA L ON L.CODAGENDA = I.CODLOCATIE
    LEFT  JOIN NPART   P ON P.CODPART   = I.PARTENER
  WHERE i.codies = pCodIes;

  DELETE FROM TMP_EDINET1;

  IF vEdi_ExpCumul = 1 THEN
    INSERT INTO TMP_EDINET1 (CodIes1, CANT, VAL, TVA, PROCTVA, NrLinii, CODOBIECT)
    SELECT Min(Codies1), Sum(CANT), Sum(CANT*PU), Sum(TVA), PROCTVA, Count(1) NrLinii, CODOBIECT
    FROM (
      SELECT
        I1.CODOBIECT, I1.UMSEC, I1.PRETORIG, I1.PU, I1.ADDIM, I1.PROCDISC,
        PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1) PROCTVA,
        I1.Codies1, I1.CANT, I1.TVA
      FROM IESIRI1 I1
        INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
        LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
        LEFT JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT JOIN ntva1 t1 ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE i1.codies = pCodIes
    ) subs
    GROUP BY CODOBIECT, UMSEC, PRETORIG, PU, ADDIM, PROCDISC, PROCTVA;
  ELSE
    INSERT INTO TMP_EDINET1 (CodIes1, IndexLocal, CANT, VAL, TVA, PROCTVA, NrLinii, CODOBIECT, TAXA)
    SELECT
      I1.Codies1, Row_Number() Over ( ORDER BY I1.IndexLocal ASC), I1.CANT, I1.CANT*I1.PU VAL, I1.TVA,
      CASE
        WHEN I1.TAXA = 3 THEN T1.PROCENT
        ELSE PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
      END PROCTVA,
      1 NrLinii, I1.CODOBIECT, I1.TAXA
    FROM IESIRI1 I1
      INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
      LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
      LEFT JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT JOIN ntva1 t1 ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    WHERE i1.codies = pCodIes;

    UPDATE TMP_EDINET1 T
    SET (CODPARINTE) = (SELECT xt.CodIes1 FROM TMP_EDINET1 xT WHERE xT.IndexLocal = T.IndexLocal - 1 AND COALESCE(xT.Taxa, 0) = 0 )
    WHERE TAXA = 3 AND PROCTVA &lt;&gt; 0; -- TAXA DE MEDIU

    UPDATE TMP_EDINET1 T SET NRLINII = 0 WHERE Coalesce(CODPARINTE, 0) &gt; 0;
  END IF;
  UPDATE TMP_EDINET1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vCodClasaP);

  IF vTipIes = 26 THEN
    UPDATE TMP_EDINET1 T
    SET T.CodLivr =
        ( SELECT Max(l.CodLivr)
          FROM ieslink ilae
            INNER JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz
            INNER JOIN iesiri ae ON ae.codies = ae1.codies
            INNER JOIN livr l ON L.Codies = ae.CodIes AND L.TipLivr = ae.TipDoc
            INNER JOIN Livr1 L1 ON L1.Codlivr = L.CodLivr AND L1.Codies1 = ae1.codies1
          WHERE ilae.codies1 = t.codies1
        );
  ELSE
    UPDATE TMP_EDINET1 T
    SET T.CodLivr =
        ( SELECT Max(l.CodLivr)
          FROM Livr L INNER JOIN Livr1 L1 ON L1.Codlivr = L.CodLivr
          WHERE L.Codies = pCodIes AND L.TipLivr = vTipIes
            AND L1.Codies1 = T.Codies1
        );
  END IF;
  IF vAn*12+vLuna &gt;= 2025*12+8 THEN
    UPDATE TMP_EDINET1 T
    SET TaxCategoryCoded =  CASE
                              --EDInet Invoice XML [v.3.0]
                              WHEN ProcTva = 21                                                    THEN &apos;7D&apos; --Cota normala de TVA incepand cu 01.08.2025
                              WHEN ProcTva = 11                                                    THEN &apos;7W&apos; --Cota redusa de TVA incepand cu 01.08.2025

                              WHEN ProcTva = 24                                                    THEN &apos;G6&apos; --Regularizari achizitii bunuri si servicii  TVA 24%
                              WHEN ProcTva = 20                                                    THEN &apos;2S&apos; --Regularizari achizitii bunuri si servicii  TVA 20%
                              WHEN ProcTva = 19 AND vDataDoc &lt;= To_Date(&apos;31.07.2025&apos;,&apos;DD.MM.YYYY&apos;) THEN &apos;3D&apos; --Nu se mai foloseste pt doc emise dupa data de 31.07.2025
                              WHEN ProcTva =  9 AND vDataDoc &lt;= To_Date(&apos;31.07.2025&apos;,&apos;DD.MM.YYYY&apos;) THEN &apos;W7&apos; --Nu se mai foloseste pt doc emise dupa data de 31.07.2025
                              WHEN ProcTva =  5 AND vDataDoc &lt;= To_Date(&apos;31.07.2025&apos;,&apos;DD.MM.YYYY&apos;) THEN &apos;W8&apos; --Nu se mai foloseste pt doc emise dupa data de 31.07.2025
                              WHEN ProcTva =  0 AND vDataDoc &lt;= To_Date(&apos;31.07.2025&apos;,&apos;DD.MM.YYYY&apos;) THEN &apos;3M&apos; --Nu se mai foloseste pt doc emise dupa data de 31.07.2025
                              WHEN ProcTva = 19                                                    THEN &apos;3S&apos; --Regularizari achizitii bunuri si servicii  TVA 19%
                              WHEN ProcTva =  9                                                    THEN &apos;W6&apos; --Regularizari achizitii bunuri si servicii  TVA 9%
                              WHEN ProcTva =  5                                                    THEN &apos;WA&apos; --Regularizari achizitii bunuri si servicii  TVA 5%
                              WHEN ProcTva =  0                                                    THEN &apos;2M&apos; --Merchandise purchases from RO start 01.01.2016
                              --EDInet Invoice XML [v.2.0]
                              WHEN ProcTva =  0                                                    THEN &apos;E&apos; --Except from tax
                              WHEN ProcTva &lt;&gt; 0                                                    THEN &apos;S&apos; --Standard rate
                            END;
  ELSE
    UPDATE TMP_EDINET1 T
    SET TaxCategoryCoded =  CASE
                              --EDInet Invoice XML [v.3.0]
                              WHEN ProcTva = 24                 THEN &apos;D1&apos; --Merchandise purchases from RO stop  31.12.2015
                              WHEN ProcTva = 20                 THEN &apos;2D&apos; --Merchandise purchases from RO start 01.01.2016
                              WHEN ProcTva =  9                 THEN &apos;W7&apos; --Merchandise purchases from RO
                              WHEN ProcTva =  0 AND vAN &lt;  2016 THEN &apos;P3&apos; --Merchandise purchases from RO stop  31.12.2015
                              WHEN ProcTva =  0                 THEN &apos;2M&apos; --Merchandise purchases from RO start 01.01.2016
                              --EDInet Invoice XML [v.2.0]
                              WHEN ProcTva =  0                 THEN &apos;E&apos; --Except from tax
                              WHEN ProcTva &lt;&gt; 0                 THEN &apos;S&apos; --Standard rate
                            END;
  END IF;

  INSERT INTO TMP_EDINET_D
  SELECT
    Row_Number() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          D01,--Item -&gt; ItemNum
    CASE vEdi_ObjTip
      WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
      WHEN 2 THEN ac.codextern
      WHEN 3 THEN o.codextern
      WHEN 4 THEN o.codintern
      WHEN 5 THEN o.codvamal
      WHEN 6 THEN To_Char(o.codplu)
      WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      WHEN 8 THEN ac.codlaclient
      WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
    END                                                                                                                             D02,--Item -&gt; EAN
    Coalesce(
      ac.codlaclient,
      CASE vEdi_ObjTip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      END
    )                                                                                                                               D03,--Item -&gt; BuyerItemID
    o.codintern                                                                                                                     D04,--Item -&gt; SellerItemID
    o.codvamal                                                                                                                      D05,--Item -&gt; CustomTariffNumber
    &apos;CU&apos;                                                                                                                            D06,--Item -&gt; ProductIdentifierExt (RC/bun returnabil, CU/unitate comerciala)
    &apos;1&apos;                                                                                                                             D07,--Item -&gt; PacketContentQuantity
    CAST(NULL AS VARCHAR2(100))                                                                                                     D08,--Item -&gt; PackageType (Tip ambalaj: CT-cutie carton RC- bun returnabil
    TO_CHAR(TEN1.CANT/Coalesce(U1.PARITATE, 1),&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                D09,--Item -&gt; QuantityValue
    TEN1.TaxCategoryCoded                                                                                                           D10,--Item -&gt; TaxCategoryCoded
    TO_CHAR(TEN1.ProcTva)                                                                                                           D11,--Item -&gt; TaxPercent
    TO_CHAR(TEN1.TVA         ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                 D12,--Item -&gt; TaxAmount
    CASE
      WHEN ENV1.CODPARINTE IS NOT NULL THEN ENV1.TaxCategoryCoded
      WHEN TV1.CODTAXA     IS NOT NULL THEN TEN1.TaxCategoryCoded
      WHEN TV2.CODTAXA     IS NOT NULL THEN TEN1.TaxCategoryCoded
    END                                                                                                                             DE1,--Item -&gt; EnvTaxCategoryCoded
    TO_CHAR(
      CASE
        WHEN ENV1.CODPARINTE IS NOT NULL THEN ENV1.ProcTva
        WHEN TV1.CODTAXA     IS NOT NULL THEN TEN1.ProcTva
        WHEN TV2.CODTAXA     IS NOT NULL THEN TEN1.ProcTva
      END
    )                                                                                                                               DE2,--Item -&gt; EnvTaxPercent
    TO_CHAR(
      CASE
        WHEN ENV1.CODPARINTE IS NOT NULL THEN ENV1.VAL+ENV1.Tva
        WHEN TV1.CODTAXA     IS NOT NULL THEN Round(TV1.VALOARE*(1+TEN1.ProcTVA/100),4)*TEN1.CANT
        WHEN TV2.CODTAXA     IS NOT NULL THEN Round(TV2.VALOARE*(1+TEN1.ProcTva/100),4)*TEN1.CANT
      END, &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               DE3,--Item -&gt; EnvTaxAmount
    TO_CHAR(TEN1.VAL+TEN1.Tva,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                 D13,--Item -&gt; MonetaryGrossValue
    TO_CHAR(TEN1.VAL         ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                 D14,--Item -&gt; MonetaryNetValue
    TO_CHAR(TEN1.VAL         ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                 D15,--Item -&gt; MonetaryAmountPayable
    Upper(
      Coalesce(
        CASE
          WHEN vEdi_DenUM = 1 THEN U1.DEN_EANCOM
          WHEN vEdi_DenUM = 2 THEN U1.DEN_UM1
          WHEN vEdi_DenUM = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      )
    )                                                                                                                               D16,--Item -&gt; UnitOfMeasure
    Upper(
      Coalesce(
        CASE
          WHEN vEdi_DenUM = 1 THEN U1.DEN_EANCOM
          WHEN vEdi_DenUM = 2 THEN U1.DEN_UM1
          WHEN vEdi_DenUM = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      )
    )                                                                                                                               D17,--Item -&gt; UnitOfMeasureXCBL
    Upper(
      Coalesce(
        CASE
          WHEN vEdi_DenUM = 1 THEN U1.DEN_EANCOM
          WHEN vEdi_DenUM = 2 THEN U1.DEN_UM1
          WHEN vEdi_DenUM = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      )
    )                                                                                                                               D18,--Item -&gt; PackUnitOfMeasure
    TO_CHAR(
      ( I1.PU -
        CASE
          WHEN ENV1.CODPARINTE IS NOT NULL THEN 0
          -- Tichet 63752 - nu se doreste scadere taxei din pret
          --WHEN TV1.CODTAXA     IS NOT NULL THEN Coalesce(TV1.VALOARE, 0)
          --WHEN TV2.CODTAXA     IS NOT NULL THEN Coalesce(TV2.VALOARE, 0)
          ELSE 0
        END
      ) * Coalesce(U1.PARITATE, 1),
      &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               D19,--Item -&gt; UnitPriceValue
    TO_CHAR(
      ( I1.PU+(TEN1.Tva/TEN1.CANT) -
        CASE
          WHEN ENV1.CODPARINTE IS NOT NULL THEN 0
          -- Tichet 63752 - nu se doreste scadere taxei din pret
          --WHEN TV1.CODTAXA     IS NOT NULL THEN Coalesce(Round(TV1.VALOARE*(1+TEN1.ProcTva/100),4), 0)
          --WHEN TV2.CODTAXA     IS NOT NULL THEN Coalesce(Round(TV2.VALOARE*(1+TEN1.ProcTva/100),4), 0)
          ELSE 0
        END
      ) * Coalesce(U1.PARITATE, 1),
      &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               D20,--Item -&gt; UnitPriceValueGross
    Substr(O.Denumire,1,35)                                                                                                         D21,--Item -&gt; Name
    Coalesce(vOrderNumber, CASE WHEN pTecNetComNRI = 1 THEN Com.NRI END, To_Char(Com.NrDoc))                                        D22,--Item -&gt; Order -&gt; BuyerOrderNumber
    Coalesce(vOrderDate  , To_Char(Com.DataDoc, &apos;YYYY-MM-DD&quot;T&quot;hh:mm:ss&apos;) )                                                          D23,--Item -&gt; Order -&gt; BuyerOrderDate
    To_Char(L.DataLivr, &apos;YYYY-MM-DD&quot;T&quot;hh:mm:ss&apos;)                                                                                    D24,--Item -&gt; DeliveryDetail -&gt; DeliveryDate
    To_Char(L.NrLivr)                                                                                                               D25,--Item -&gt; DeliveryDetail -&gt; DeliveryDocumentNumber
    COALESCE(        CASE WHEN Abs(vEdiNetDocType) = 4 THEN vEdiNetRetAnnNumber END, To_Char(AE.NrDoc))                             D26,--Item -&gt; ReturnsAnnouncement -&gt; RetAnnNumber
    To_Char(COALESCE(CASE WHEN Abs(vEdiNetDocType) = 4 THEN vEdiNetRetAnnDate   END, AE.DataDoc), &apos;YYYY-MM-DD&quot;T&quot;hh:mm:ss&apos;)          D27 --Item -&gt; ReturnsAnnouncement -&gt; RetAnnDate
  FROM TMP_EDINET1 TEN1
    LEFT JOIN TMP_EDINET1 ENV1  ON ENV1.CODPARINTE  = TEN1.CODIES1
    LEFT JOIN IESIRI1     I1    ON I1.CODIES1       = TEN1.CODIES1
    LEFT JOIN IESIRI      I     ON I.CODIES         = I1.CODIES
    LEFT JOIN NARTOBJ     O     ON O.CODOBIECT      = I1.CODOBIECT
    LEFT JOIN NART        A     ON A.CODARTICOL     = O.CODARTICOL
    LEFT JOIN NART1       A1    ON A1.CODARTICOL    = O.CODARTICOL AND I.AN*12+I.LUNA BETWEEN A1.ALSTART  AND A1.ALSTOP
    LEFT JOIN NTAXE1      TV1   ON TV1.CODTAXA      = A1.CODTAXA1  AND I.AN*12+I.LUNA BETWEEN TV1.ALSTART AND TV1.ALSTOP
                               AND COALESCE(TV1.JVANZ, 0) = 1      AND COALESCE(TV1.FACTURABIL, 0) = 0
                               AND COALESCE(TV1.LACEAPLIC, 0) = 7  AND COALESCE(TV1.VALOARE, 0) &lt;&gt; 0
    LEFT JOIN NTAXE1      TV2   ON TV2.CODTAXA      = A1.CODTAXA2  AND I.AN*12+I.LUNA BETWEEN TV2.ALSTART AND TV2.ALSTOP
                               AND COALESCE(TV2.JVANZ, 0) = 1      AND COALESCE(TV2.FACTURABIL, 0) = 0
                               AND COALESCE(TV2.LACEAPLIC, 0) = 7  AND COALESCE(TV2.VALOARE, 0) &lt;&gt; 0
    LEFT JOIN NARTCLI     AC    ON AC.CODARTCLI     = TEN1.CODARTCLI
    LEFT JOIN NUM1        U1    ON U1.CODUM1        = I1.UMSEC
    LEFT JOIN IESLINK     ILAE  ON ILAE.CODIES1     = I1.CODIES1 AND ILAE.CODLINIEAVIZ IS NOT NULL
    LEFT JOIN IESIRI1     AE1   ON AE1.CODIES1      = ILAE.CODLINIEAVIZ
    LEFT JOIN IESIRI      AE    ON AE.CODIES        = AE1.CODIES
    LEFT JOIN IESIRI1     S1    ON S1.CODIES1       = CASE
                                                        WHEN                                                Coalesce(AE1.CODIES1STORNO ,0) &lt;&gt; 0 THEN AE1.CODIES1STORNO
                                                        WHEN                                                Coalesce(I1.CODIES1STORNO  ,0) &lt;&gt; 0 THEN I1.CODIES1STORNO
                                                        WHEN Coalesce(AE1.TIPDOCIMP, 0) IN (19, 20, 26) AND Coalesce(AE1.CODLINIEDOCIMP,0) &lt;&gt; 0 THEN AE1.CODLINIEDOCIMP
                                                        WHEN Coalesce(I1.TIPDOCIMP,  0) IN (19, 20, 26) AND Coalesce(I1.CODLINIEDOCIMP ,0) &lt;&gt; 0 THEN I1.CODLINIEDOCIMP
                                                      END
                               AND vEdiNetDocType   &lt;&gt; 4
--    LEFT JOIN IESIRI      S     ON S.CODIES         = S1.CODIES
    LEFT JOIN IESLINK     ILSAE ON ILSAE.CODIES1    = S1.CODIES1 AND ILSAE.CODLINIEAVIZ IS NOT NULL
    LEFT JOIN IESIRI1     SAE1  ON SAE1.CODIES1     = ILSAE.CODLINIEAVIZ
    LEFT JOIN IESLINK     ILCOM ON ILCOM.CODIES1    = Coalesce(ILSAE.CODLINIEAVIZ, S1.CODIES1, AE1.CODIES1, I1.CODIES1) AND ILCOM.CODLINIECOMANDA IS NOT NULL
    LEFT JOIN CMDLIVRLINK COML  ON COML.CODCOMANDA1 = ILCOM.CODLINIECOMANDA
    LEFT JOIN COMANDA1    COM1  ON COM1.CODCOMANDA1 = COALESCE(COML.CODLINIECOMANDA, ILCOM.CODLINIECOMANDA)
    LEFT JOIN COMANDA     COM   ON COM.CODCOMANDA   = COM1.CODCOMANDA
    LEFT JOIN LIVR        L     ON L.CODLIVR        = TEN1.CodLivr
  WHERE Coalesce(TEN1.CodParinte, 0) = 0
  ORDER BY i1.indexlocal, i1.codies1;

  INSERT INTO TMP_EDINET_S
  SELECT
    To_Char(NumberOfLines)                                                         S01,--NumberOfLines
    TO_CHAR(ValDoc-TvaDoc ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S02,--NetValue
    TO_CHAR(TvaDoc        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S03,--TaxValue
    TO_CHAR(NetDoc        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S04,--TaxableValue
    TO_CHAR(ValDoc        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S05,--GrossValue
    TaxCategoryCoded                                                               S06,--TaxSummary -&gt; Tax -&gt; TaxCategoryCoded
    To_Char(ProcTVA)                                                               S07,--TaxSummary -&gt; Tax -&gt; TaxPercent
    TO_CHAR(LinNet        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S08,--TaxSummary -&gt; Tax -&gt; TaxNettoAmount
    TO_CHAR(LinNet        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S09,--TaxSummary -&gt; Tax -&gt; TaxableAmount
    TO_CHAR(LinTva        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S10,--TaxSummary -&gt; Tax -&gt; TaxAmount
    TO_CHAR(LinNet+LinTva ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S11,--TaxSummary -&gt; Tax -&gt; TaxGrossAmount
    TO_CHAR(EnvVal        ,&apos;fm9999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)  S12 --TaxSummary -&gt; Tax -&gt; EnvTaxAmount
  FROM (
    SELECT
      TaxCategoryCoded, ProcTVA,
      Max(NumberOfLines) NumberOfLines,
      Max(ValDoc) ValDoc, Max(TvaDoc) TvaDoc, Round(Max(NetDoc),2) NetDoc,
      Round(Sum(LinNet),2) LinNet, Round(Sum(LinTva),2) LinTva,
      Round(Sum(EnvVal),2) EnvVal
    FROM (
      SELECT
        i.tipdoc,
        Sum(nrlinii) OVER (PARTITION BY i.codies) NumberOfLines,
        CASE WHEN i.tipdoc = 26 THEN Round(i.ValDoc,2) ELSE Round(i.ValDoc - i.TVADoc,2) + Round(i.TVADoc,2) END valdoc, Round(i.tvadoc,2) tvadoc,
        Sum(i1.pu*ten1.cant) OVER (PARTITION BY i.codies) NetDoc,
        TEN1.TaxCategoryCoded, TEN1.ProcTVA,
        CASE
          WHEN COALESCE(TEN1.CODPARINTE, 0) &lt;&gt; 0 THEN 0
          WHEN COALESCE(TV1.CODTAXA, 0)     &lt;&gt; 0 THEN TEN1.VAL - TV1.VALOARE
          WHEN COALESCE(TV2.CODTAXA, 0)     &lt;&gt; 0 THEN TEN1.VAL - TV2.VALOARE
          ELSE TEN1.VAL
        END LinNet,
        CASE
          WHEN COALESCE(TEN1.CODPARINTE, 0) &lt;&gt; 0 THEN 0
          WHEN COALESCE(TV1.CODTAXA, 0)     &lt;&gt; 0 THEN TEN1.TVA - Round(TV1.VALOARE*TEN1.ProcTVA/100,4)
          WHEN COALESCE(TV2.CODTAXA, 0)     &lt;&gt; 0 THEN TEN1.TVA - Round(TV2.VALOARE*TEN1.ProcTVA/100,4)
          ELSE TEN1.TVA
        END LinTva,
        CASE
          WHEN COALESCE(TEN1.CODPARINTE, 0) &gt; 0 THEN TEN1.VAL + TEN1.TVA
          WHEN COALESCE(TV1.CODTAXA, 0)     &lt;&gt; 0 THEN Round(TV1.VALOARE*(1+TEN1.ProcTVA/100),4)*TEN1.CANT
          WHEN COALESCE(TV2.CODTAXA, 0)     &lt;&gt; 0 THEN Round(TV2.VALOARE*(1+TEN1.ProcTVA/100),4)*TEN1.CANT
          ELSE 0
        END EnvVal
      FROM TMP_EDINET1 TEN1
        INNER JOIN IESIRI1 I1  ON I1.CODIES1       = TEN1.CODIES1
        INNER JOIN IESIRI  I   ON I.CODIES         = I1.CODIES
        INNER JOIN NAGENDA L   ON L.CODAGENDA      = I.CODLOCATIE
        LEFT JOIN  NARTOBJ O   ON O.CODOBIECT      = I1.CODOBIECT
        LEFT JOIN  NART    A   ON A.CODARTICOL     = O.CODARTICOL
        LEFT JOIN  NART1   A1  ON A1.CODARTICOL    = O.CODARTICOL AND I.AN*12+I.LUNA BETWEEN A1.ALSTART  AND A1.ALSTOP
        LEFT JOIN  NTVA1   T1  ON T1.CODTVA        = A1.CODTVA    AND I.AN*12+I.LUNA BETWEEN T1.ALSTART  AND T1.ALSTOP
        LEFT JOIN  NTAXE1  TV1 ON TV1.CODTAXA      = A1.CODTAXA1  AND I.AN*12+I.LUNA BETWEEN TV1.ALSTART AND TV1.ALSTOP
                              AND COALESCE(TV1.JVANZ, 0) = 1      AND COALESCE(TV1.FACTURABIL, 0) = 0
                              AND COALESCE(TV1.LACEAPLIC, 0) = 7  AND COALESCE(TV1.VALOARE, 0) &lt;&gt; 0
        LEFT JOIN  NTAXE1  TV2 ON TV2.CODTAXA      = A1.CODTAXA2  AND I.AN*12+I.LUNA BETWEEN TV2.ALSTART AND TV2.ALSTOP
                              AND COALESCE(TV2.JVANZ, 0) = 1      AND COALESCE(TV2.FACTURABIL, 0) = 0
                              AND COALESCE(TV2.LACEAPLIC, 0) = 7  AND COALESCE(TV2.VALOARE, 0) &lt;&gt; 0
      WHERE i.codies = pCodIes
    ) subs1
    GROUP BY TaxCategoryCoded, ProcTVA
  ) subs2;
END;

PROCEDURE PrepXMLDesAdvEdiNet(pCodIes  NUMBER, pBULK NUMBER DEFAULT 0) IS
  vCodPart             NUMBER(20);
  vClasaPart           NUMBER(20);
  vIDLaClient          VARCHAR2(100);
  pTecNetComNRI        NUMBER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos;       ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;));
  pEdiNetAEComDocIdTip NUMBER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;EdiNetAEComDocIdTip&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;2&apos;));
BEGIN
  PrepFirmaAdr(pCodIes);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DESADVEDINET_H&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DESADVEDINET_P&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DESADVEDINET_L&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DESADVEDINET_S&apos;;

  SELECT p.codpart, p.codclasa, pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies)
  INTO   vCodPart,  vClasaPart, vIDLaClient
  FROM iesiri i
    LEFT JOIN npart   p    ON p.codpart      = i.partener
    LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes AND i.tipdoc = 20 AND Coalesce(sliv.edi_exptip,0) = 3;
  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  INSERT INTO TMP_DESADVEDINET_H
  SELECT
    CASE
      WHEN Nullif(slivr.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
      ELSE slivr.EDI_SUBDIREXP||&apos;\&apos;
    END||
    To_Char(I.NrDoc)||To_Char(I.DataDoc, &apos;YYYYMMDD&apos;)||&apos;_&apos;||Coalesce(SUB.CIF, &apos;&apos;)                                                    FileName,
    To_Char(I.NrDoc)                                                                                                                H01,--DesadvNumber
    To_Char(I.DataDoc, &apos;YYYY-MM-DD&apos;)                                                                                                H02,--DesadvDate
    To_Char((SELECT Max(L.DATALIVR) FROM LIVR L WHERE L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC), &apos;yyyy-mm-dd&apos;)                  H03,--PlannedDeliveryDate
    SubStr(I.OBS,1,2000)                                                                                                            H04,--Comment (Max.2000 car)
    NULL                                                                                                                            D01,--DeliveryDetails -&gt; TermsOfDelivery
    NULL                                                                                                                            D02,--DeliveryDetails -&gt; Description
    NULL                                                                                                                            T01,--TransportDetails -&gt; TransportModeCode
    NULL                                                                                                                            T02,--TransportDetails -&gt; MeansOfTransport -&gt; Identyfication
    NULL                                                                                                                            T03,--TransportDetails -&gt; MeansOfTransport -&gt; Ownership
    NULL                                                                                                                            T04,--TransportDetails -&gt; MeansOfTransport -&gt; Nationality
    Coalesce(CASE WHEN pEdiNetAEComDocIdTip = 1 THEN COM.SeriaDoc END,&apos;&apos;)||
    Coalesce(CASE WHEN pTecNetComNRI        = 1 THEN Com.NRI      END, To_Char(Com.NrDoc))                                          R01,--ReferenceDocs -&gt; OrderAtBuyer -&gt; DocID
    To_Char(Com.DataDoc, &apos;YYYY-MM-DD&apos;)                                                                                              R02,--ReferenceDocs -&gt; OrderAtBuyer -&gt; DocDate
    NULL /*To_Char(L.NrLivr)*/                                                                                                      R03,--ReferenceDocs -&gt; DeliveryDocument -&gt; DocID
    NULL /*To_Char(L.DataLivr, &apos;YYYY-MM-DD&apos;)*/                                                                                      R04,--ReferenceDocs -&gt; DeliveryDocument -&gt; DocDate
    NULL                                                                                                                            R05,--ReferenceDocs -&gt; TransportDocument -&gt; DocID
    NULL                                                                                                                            R06,--ReferenceDocs -&gt; TransportDocument -&gt; DocDate
    p.den_part                                                                                                                      P01,--BuyerParty -&gt; Name
    ssoc.GLN                                                                                                                        P02,--BuyerParty -&gt; ILN
    pcf.codfiscal                                                                                                                   P03,--BuyerParty -&gt; TaxID
    NULL                                                                                                                            P04,--BuyerParty -&gt; IDInSupplierSys
    lsoc.den_localit                                                                                                                P05,--BuyerParty -&gt; AddressDetails -&gt; City
    ssoc.codpostal                                                                                                                  P06,--BuyerParty -&gt; AddressDetails -&gt; PostalCode
    ssoc.strada                                                                                                                     P07,--BuyerParty -&gt; AddressDetails -&gt; Street
    ssoc.nr1                                                                                                                        P08,--BuyerParty -&gt; AddressDetails -&gt; HouseNumber
    tsoc.simbauto                                                                                                                   P09,--BuyerParty -&gt; AddressDetails -&gt; CountryCode
    slivr.obs                                                                                                                       P10,--ShipToParty -&gt; Name
    slivr.GLN                                                                                                                       P11,--ShipToParty -&gt; ILN
    slivr.codfiscal                                                                                                                 P12,--ShipToParty -&gt; TaxID
    NULL                                                                                                                            P13,--ShipToParty -&gt; IDInSupplierSys
    llivr.den_localit                                                                                                               P14,--ShipToParty -&gt; AddressDetails -&gt; City
    slivr.codpostal                                                                                                                 P15,--ShipToParty -&gt; AddressDetails -&gt; PostalCode
    slivr.strada                                                                                                                    P16,--ShipToParty -&gt; AddressDetails -&gt; Street
    slivr.nr1                                                                                                                       P17,--ShipToParty -&gt; AddressDetails -&gt; HouseNumber
    tlivr.simbauto                                                                                                                  P18,--ShipToParty -&gt; AddressDetails -&gt; CountryCode
    f.denfirma                                                                                                                      P19,--SellerParty -&gt; Name
    ssub.GLN                                                                                                                        P20,--SellerParty -&gt; ILN
    f.Codfiscal                                                                                                                     P21,--SellerParty -&gt; TaxID
    CASE
      WHEN Coalesce(slivr.edi_parttip, 0) = 0 THEN Coalesce(p.codextern,ssub.GLN)
      WHEN slivr.edi_parttip              = 1 THEN slivr.edi_partid
      WHEN slivr.edi_parttip              = 2 THEN f.codfiscal
      WHEN slivr.edi_parttip              = 3 THEN slivr.gln
      ELSE                                         vIDLaClient
    END                                                                                                                             P22,--SellerParty -&gt; IDInBuyerSys
    f.denlocalit                                                                                                                    P23,--SellerParty -&gt; AddressDetails -&gt; City
    f.codpostal                                                                                                                     P24,--SellerParty -&gt; AddressDetails -&gt; PostalCode
    f.strada                                                                                                                        P25,--SellerParty -&gt; AddressDetails -&gt; Street
    f.nr1                                                                                                                           P26,--SellerParty -&gt; AddressDetails -&gt; HouseNumber
    f.simbtara                                                                                                                      P27,--SellerParty -&gt; AddressDetails -&gt; CountryCode
    f.denfirma                                                                                                                      P28,--ShipFromParty -&gt; Name
    ssub.GLN                                                                                                                        P29,--ShipFromParty -&gt; ILN
    ssub.Codfiscal                                                                                                                  P30,--ShipFromParty -&gt; TaxID
    NULL                                                                                                                            P31,--ShipFromParty -&gt; IDInSupplierSys
    NULL                                                                                                                            P32,--ShipFromParty -&gt; IDInBuyerSys
    lsub.den_localit                                                                                                                P33,--ShipFromParty -&gt; AddressDetails -&gt; City
    ssub.codpostal                                                                                                                  P34,--ShipFromParty -&gt; AddressDetails -&gt; PostalCode
    ssub.strada                                                                                                                     P35,--ShipFromParty -&gt; AddressDetails -&gt; Street
    ssub.nr1                                                                                                                        P36,--ShipFromParty -&gt; AddressDetails -&gt; HouseNumber
    tsub.simbauto                                                                                                                   P37,--ShipFromParty -&gt; AddressDetails -&gt; CountryCode
    NULL                                                                                                                            P38,--ForwarderParty -&gt; Name
    NULL                                                                                                                            P39,--ForwarderParty -&gt; ILN
    NULL                                                                                                                            P40,--ForwarderParty -&gt; IDInSupplierSys
    NULL                                                                                                                            P41,--ForwarderParty -&gt; IDInBuyerSys
    NULL                                                                                                                            P42,--SellerHeadquartersParty -&gt; Name
    NULL                                                                                                                            P43,--SellerHeadquartersParty -&gt; ILN
    NULL                                                                                                                            P44,--SellerHeadquartersParty -&gt; TaxID
    NULL                                                                                                                            P45,--SellerHeadquartersParty -&gt; IDInSupplierSys
    NULL                                                                                                                            P46,--SellerHeadquartersParty -&gt; IDInBuyerSys
    NULL                                                                                                                            P47,--SellerHeadquartersParty -&gt; AddressDetails -&gt; City
    NULL                                                                                                                            P48,--SellerHeadquartersParty -&gt; AddressDetails -&gt; PostalCode
    NULL                                                                                                                            P49,--SellerHeadquartersParty -&gt; AddressDetails -&gt; Street
    NULL                                                                                                                            P50,--SellerHeadquartersParty -&gt; AddressDetails -&gt; HouseNumber
    NULL                                                                                                                            P51,--SellerHeadquartersParty -&gt; AddressDetails -&gt; CountryCode
    NULL                                                                                                                            P52,--SellerHeadquartersParty -&gt; DefaultContact -&gt; Person
    NULL                                                                                                                            P53,--SellerHeadquartersParty -&gt; DefaultContact -&gt; Tel
    NULL                                                                                                                            P54,--SellerHeadquartersParty -&gt; DefaultContact -&gt; Fax
    NULL                                                                                                                            P55,--SellerHeadquartersParty -&gt; DefaultContact -&gt; EMail
    NULL                                                                                                                            P56,--ConsigneeParty -&gt; Name
    NULL                                                                                                                            P57,--ConsigneeParty -&gt; ILN
    NULL                                                                                                                            P58,--ConsigneeParty -&gt; IDInBuyerSys
    NULL                                                                                                                            P59,--ConsigneeParty -&gt; AddressDetails -&gt; City
    NULL                                                                                                                            P60,--ConsigneeParty -&gt; AddressDetails -&gt; PostalCode
    NULL                                                                                                                            P61,--ConsigneeParty -&gt; AddressDetails -&gt; Street
    NULL                                                                                                                            P62,--ConsigneeParty -&gt; AddressDetails -&gt; HouseNumber
    NULL                                                                                                                            P63 --ConsigneeParty -&gt; AddressDetails -&gt; CountryCode
  FROM IESIRI I
    CROSS JOIN TMP_FIRMA_ADR F
    LEFT JOIN NMONEDE      M     ON M.CODMONEDA       = Coalesce(I.MONEDA,0)
    LEFT JOIN NPART        P     ON P.CODPART         = I.PARTENER
    LEFT JOIN NPARTCODFISC PCF   ON PCF.COD_CODFISCAL = I.CODFISCAL

    LEFT JOIN NAGENDA      SLIVR ON SLIVR.CODAGENDA   = I.CODLOCATIE
    LEFT JOIN NLOCALIT     LLIVR ON LLIVR.CODLOCALIT  = SLIVR.CODLOCALIT
    LEFT JOIN NJUDET       JLIVR ON JLIVR.CODJUDET    = LLIVR.CODJUDET
    LEFT JOIN NTARI        TLIVR ON TLIVR.CODTARA     = LLIVR.CODTARA

    LEFT JOIN NAGENDA      SSOC  ON SSOC.CODPART      = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT     LSOC  ON LSOC.CODLOCALIT   = SSOC.CODLOCALIT
    LEFT JOIN NJUDET       JSOC  ON JSOC.CODJUDET     = LSOC.CODJUDET
    LEFT JOIN NTARI        TSOC  ON TSOC.CODTARA      = LSOC.CODTARA

    LEFT JOIN NSUBUNIT     SUB   ON SUB.CODSUBUNIT    = I.SUBUNITATEA
    LEFT JOIN NAGENDA      SSUB  ON SSUB.CODSUBUNIT   = I.SUBUNITATEA
    LEFT JOIN NLOCALIT     LSUB  ON LSUB.CODLOCALIT   = SSUB.CODLOCALIT
    LEFT JOIN NTARI        TSUB  ON TSUB.CODTARA      = LSUB.CODTARA

    LEFT JOIN (
      SELECT I1.CODIES, Max(COM1.CODCOMANDA) CODCOMANDA
      FROM IESIRI1 I1
        INNER JOIN IESLINK ILCOM ON ILCOM.CODIES1 = I1.CODIES1 AND ILCOM.CODLINIECOMANDA IS NOT NULL
        LEFT JOIN CMDLIVRLINK   COML  ON COML.CODCOMANDA1 = ILCOM.CODLINIECOMANDA
        LEFT JOIN COMANDA1      COM1  ON COM1.CODCOMANDA1 = COALESCE(COML.CODLINIECOMANDA, ILCOM.CODLINIECOMANDA)
      WHERE i1.codies = pCodIes
      GROUP BY I1.CODIES
    )                      COM1  ON COM1.CODIES       = I.CODIES

    LEFT JOIN (
      SELECT Row_Number() OVER (ORDER BY datalivr desc, nrlivr desc, codlivr desc) NrCrt, CodIes, NrLivr, DataLivr
      FROM LIVR
      WHERE CodIes = pCodIes AND tiplivr = 20
    )                      L     ON L.CODIES          = I.CODIES AND L.NRCrt = 1

    LEFT JOIN  COMANDA     COM   ON COM.CODCOMANDA    = COM1.CODCOMANDA
  WHERE i.codies = pCodIes AND i.tipdoc = 20 AND Coalesce(slivr.edi_exptip,0) = 3;

  INSERT INTO TMP_DESADVEDINET_P
  SELECT
    NrCrt                                                                                                                           P01,--Packaging -&gt; StructureLevelId
    NULL                                                                                                                            P02,--Packaging -&gt; ParentStructureLevelId
    REPLACE(TO_CHAR(CantUMP,&apos;fm9999999990D0099&apos;), &apos;,&apos;, &apos;.&apos;)                                                                         P03,--Packaging -&gt; PackageIdentification -&gt; PackageQuantity
    TypeUMP                                                                                                                         P04,--Packaging -&gt; PackageIdentification -&gt; PackageType
    NULL                                                                                                                            P05,--Packaging -&gt; PackageIdentification -&gt; Description
    NULL                                                                                                                            P06,--Packaging -&gt; PackageIdentification -&gt; GTIN
    NULL                                                                                                                            P07 --Packaging -&gt; PackageIdentification -&gt; SSCC
  FROM (
    SELECT Row_Number() OVER (ORDER BY TypeUMP) NrCrt, TypeUMP, Ceil(Sum(CantUMP)) AS CantUMP
    FROM (
      SELECT
        Row_Number() OVER (PARTITION BY i1.codies1 ORDER BY aa.codamb NULLS LAST, up.codextern NULLS LAST) IdxTypeUM,
        i.codies, i1.cant/up.paritate CantUMP, up.codextern TypeUMP
      FROM IESIRI I
        INNER JOIN NAGENDA L  ON L.CODAGENDA  = I.CODLOCATIE
        INNER JOIN IESIRI1 I1 ON I1.CODIES    = I.CODIES
        LEFT JOIN  NUM1    U1 ON U1.CODUM1    = I1.UMSEC
        LEFT JOIN  NUM1    UP ON UP.CODUM     = U1.CODUM     AND Upper(UP.OBS) = &apos;PACKAGING_EDINET&apos;
        LEFT JOIN  NARTAMB AA ON AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = UP.CODUM1
      WHERE i.codies = pCodIes
    ) asub
    WHERE IdxTypeUM = 1
    GROUP BY TypeUMP
  ) bsub
  WHERE NOT (bsub.NrCrt &gt; 1 AND TypeUMP IS NULL);

  INSERT INTO TMP_DESADVEDINET_L
  SELECT
    Row_Number() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          D01,--Item -&gt; ItemNum
    CASE l.edi_objtip
      WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
      WHEN 2 THEN ac.codextern
      WHEN 3 THEN o.codextern
      WHEN 4 THEN o.codintern
      WHEN 5 THEN o.codvamal
      WHEN 6 THEN To_Char(o.codplu)
      WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      WHEN 8 THEN ac.codlaclient
      WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
    END                                                                                                                             D02,--Item -&gt; EAN
    Coalesce(
      ac.codlaclient,
      CASE l.edi_objtip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      END
    )                                                                                                                               D03,--Item -&gt; BuyerItemID
    o.codintern                                                                                                                     D04,--Item -&gt; SellerItemID
    &apos;1&apos;                                                                                                                             D05,--Item -&gt; PacketContentQuantity
    REPLACE(TO_CHAR(I1.CANT/Coalesce(U1.PARITATE, 1),&apos;fm9999999990D0099&apos;), &apos;,&apos;, &apos;.&apos;)                                                D06,--Item -&gt; QuantityValue
    Upper(
      Coalesce(
        CASE
          WHEN l.edi_denum = 1 THEN U1.DEN_EANCOM
          WHEN l.edi_denum = 2 THEN U1.DEN_UM1
          WHEN l.edi_denum = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      )
    )                                                                                                                               D07,--Item -&gt; UnitOfMeasure
    NULL                                                                                                                            D08,--Item -&gt; ChangeReasonCode
    Substr(O.Denumire,1,500)                                                                                                        D09,--Item -&gt; Name
    NULL                                                                                                                            D10,--Item -&gt; Description
    REPLACE(TO_CHAR(Coalesce(COM1.CANTCOMANDAT,0)/Coalesce(U1.PARITATE, 1),&apos;fm9999999990D0099&apos;), &apos;,&apos;, &apos;.&apos;)                          D11,--Item -&gt; OrderedQuantity
    To_Char(
      (
        SELECT Max(L.DATALIVR)
        FROM LIVR L INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        WHERE L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC AND L1.CODIES1 = I1.CODIES1
      )
      , &apos;YYYY-MM-DD&apos;
    )                                                                                                                               D12,--Item -&gt; DeliveryDate
    SubStr(I1.OBS,1,2000)                                                                                                           D13,--Item -&gt; Comment
    NULL                                                                                                                            D14,--Item -&gt; ActionRequestCode
    NULL                                                                                                                            D15,--Item -&gt; BestBeforeDate
    NULL                                                                                                                            D16,--Item -&gt; HandlingInstructions
    Coalesce(CASE WHEN pEdiNetAEComDocIdTip = 1 THEN COM.SeriaDoc END,&apos;&apos;)||
    Coalesce(CASE WHEN pTecNetComNRI        = 1 THEN Com.NRI      END, To_Char(Com.NrDoc))                                          D17,--Item -&gt; ReferenceDocs -&gt; OrderAtBuyer -&gt; DocID
    To_Char(Com.DataDoc, &apos;YYYY-MM-DD&apos;)                                                                                              D18,--Item -&gt; ReferenceDocs -&gt; OrderAtBuyer -&gt; DocDate
    NULL /*To_Char(LIV.NrLivr) */                                                                                                   D19,--Item -&gt; ReferenceDocs -&gt; DeliveryDocument -&gt; DocID
    NULL /*To_Char(LIV.DataLivr, &apos;YYYY-MM-DD&apos;) */                                                                                   D20 --Item -&gt; ReferenceDocs -&gt; DeliveryDocument -&gt; DocDate
  FROM TMP_EDI_IES1 TI1
    LEFT JOIN IESIRI      I     ON I.CODIES         = TI1.CODIES
    LEFT JOIN NAGENDA     L     ON L.CODAGENDA      = I.CODLOCATIE
    LEFT JOIN IESIRI1     I1    ON I1.CODIES1       = TI1.CODIES1
    LEFT JOIN NARTOBJ     O     ON O.CODOBIECT      = I1.CODOBIECT
    LEFT JOIN NART        A     ON A.CODARTICOL     = O.CODARTICOL
    LEFT JOIN NPART       P     ON P.CODPART        = I.PARTENER
    LEFT JOIN NARTCLI     AC    ON AC.CODARTCLI     = TI1.CODARTCLI
    LEFT JOIN NUM1        U1    ON U1.CODUM1        = I1.UMSEC
    LEFT JOIN IESLINK     ILCOM ON ILCOM.CODIES1    = I1.CODIES1 AND ILCOM.CODLINIECOMANDA IS NOT NULL
    LEFT JOIN CMDLIVRLINK COML  ON COML.CODCOMANDA1 = ILCOM.CODLINIECOMANDA
    LEFT JOIN COMANDA1    COM1  ON COM1.CODCOMANDA1 = COALESCE(COML.CODLINIECOMANDA, ILCOM.CODLINIECOMANDA)
    LEFT JOIN COMANDA     COM   ON COM.CODCOMANDA   = COM1.CODCOMANDA
  ORDER BY i1.indexlocal, i1.codies1;

  INSERT INTO TMP_DESADVEDINET_S
  SELECT
    NULL                                                                                                                            S01,--DesadvSummary -&gt; TotalShippedQuantity
    NULL                                                                                                                            S02,--DesadvSummary -&gt; TotalGrossWeight
    NULL                                                                                                                            S03 --DesadvSummary -&gt; TotalWeightUnitOfMeasure
  FROM DUAL;

  COMMIT;
END;

FUNCTION GetXMLDocExpertSupplier(pCodIes NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal IS
  crsResult        crsGlobal;
  vCodPart         NUMBER(20);
  vClasaPart       NUMBER(20);
  vIDLaClient      VARCHAR2(100);
  vGLNLaClient     VARCHAR2(100);
  pDocXChangeTipUM NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;DocXChangeTipUM&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
  pTecNetComNRI    NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos;    ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
BEGIN
  PrepFirmaAdr(pCodIes);
  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vExpSupDocType       := 0;
    vReceiveAdviceNumber := NULL;
    vReceiveAdviceDate   := NULL;
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
    vDespatchNumber      := NULL;
    vDespatchDate        := NULL;
  END IF;

  SELECT p.codpart, p.codclasa, pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies), pkg_exportedi.GetGLNLaClient(sliv.edi_parttip, i.codies)
  INTO   vCodPart,  vClasaPart, vIDLaClient                                            , vGLNLaClient
  FROM iesiri i
    LEFT JOIN npart   p    ON p.codpart      = i.partener
    LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes
    AND Coalesce(sliv.edi_exptip,0) = 5
    AND Coalesce(sliv.edi_parttip,0) &gt; 0
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;);
  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  OPEN crsResult FOR
  WITH loc AS (
    SELECT l.codlocalit, l.den_localit, j.den_judet, t.simbauto t_simbauto
    FROM nlocalit l
      LEFT JOIN njudet j ON j.codjudet = l.codjudet
      LEFT JOIN ntari  t ON t.codtara = l.codtara
  )
  SELECT
    CASE
      WHEN Nullif(sliv.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
      ELSE sliv.EDI_SUBDIREXP||&apos;\&apos;
    END||
    Coalesce(pcf.codfiscal,p.den_part)||&apos;_&apos;||To_Char(I.DataDoc,&apos;yyyymmdd&apos;)||&apos;_&apos;||I.NrDoc||&apos;_&apos;||Coalesce(f.Codfiscal,f.denfirma)     FileName,
    &apos;2.0&apos;                                                                                                                           Ver, --*Version
    --Header
    To_Char(I.NrDoc)                                                                                                                H01a,--*InvoiceNumber
    To_Char(I.SeriaDoc)                                                                                                             H01b,--*InvoiceSeries
    To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                                                                                                H01c,--*InvoiceDate
    Coalesce(vReceiveAdviceNumber, i.NrNir)                                                                                         H02a,--*ReceptionNumber
    Coalesce(vReceiveAdviceDate  , To_Char(i.DataNir, &apos;yyyy-mm-dd&apos;))                                                                H02b,--*ReceptionDate
    CASE
      WHEN vDespatchNumber IS NOT NULL THEN vDespatchNumber
      ELSE Max(To_Char(AE.NrDoc))                  KEEP (DENSE_RANK LAST ORDER BY Coalesce(AE.CodIes,0))      OVER (PARTITION BY i1.codies)
    END                                                                                                                             H03a,---DeliveryNumber
    CASE
      WHEN vDespatchdate IS NOT NULL THEN vDespatchdate
      ELSE Max(To_Char(AE.DataDoc, &apos;yyyy-mm-dd&apos;))  KEEP (DENSE_RANK LAST ORDER BY Coalesce(AE.CodIes,0))      OVER (PARTITION BY i1.codies)
    END                                                                                                                             H03b,---DeliveryNumber
    CASE
      WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
      WHEN pTecNetComNRI = 1
      THEN Max(Coalesce(COM.NRI,To_Char(COM.NrDoc))) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
      ELSE Max(To_Char(COM.NrDoc))                   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             H04a,--*OrderNumber
    CASE
      WHEN vOrderDate IS NOT NULL THEN vOrderDate
      ELSE Max(To_Char(COM.DataDoc, &apos;yyyy-mm-dd&apos;)) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             H04b,--*OrderDate
    CASE
      WHEN vExpSupDocType = 4 THEN &apos;S&apos;
      WHEN vExpSupDocType = 3 THEN &apos;C&apos;
      WHEN vExpSupDocType = 2 THEN &apos;O&apos;
      WHEN ST.CODIES IS NOT NULL THEN &apos;S&apos;
      ELSE &apos;O&apos;
    END                                                                                                                             H05, --*DocumentType
    0                                                                                                                               H06, ---TestIndicator
    &apos;42&apos;                                                                                                                            H07, --*PaymentType
    SubStr(M.SIMBOL,1,3)                                                                                                            H08, --*Currency
    CASE WHEN Coalesce(i.tvaincasare,0) = 1 THEN &apos;TVA LA INCASARE&apos; END                                                              H09, ---Remarks
    &apos;&apos;                                                                                                                              H10, ---AdditionalDocNumber
    CASE
      WHEN vExpSupDocType &gt; 2 THEN vExpSupRefNumber
      WHEN vExpSupDocType = 2 THEN CAST(NULL AS VARCHAR2(255))
      WHEN ST.CODIES IS NOT NULL THEN To_Char(ST.NRDOC)
      ELSE NULL
    END                                                                                                                             H11a,---ReferenceInvoiceNumber
    CASE
      WHEN vExpSupDocType &gt; 2 THEN vExpSupRefSerie
      WHEN vExpSupDocType = 2 THEN CAST(NULL AS VARCHAR2(20))
      WHEN ST.CODIES IS NOT NULL THEN ST.SERIADOC
      ELSE NULL
    END                                                                                                                             H11b,---ReferenceInvoiceSeries
    CASE
      WHEN vExpSupDocType &gt; 2 THEN vExpSupRefDate
      WHEN vExpSupDocType = 2 THEN CAST(NULL AS VARCHAR2(10))
      WHEN ST.CODIES IS NOT NULL THEN To_Char(ST.DataDoc, &apos;yyyy-mm-dd&apos;)
      ELSE NULL
    END                                                                                                                             H11c,---ReferenceInvoiceDate
    ( SELECT To_Char(Coalesce(Min(O.Termen),I.DataDoc),&apos;yyyy-mm-dd&apos;)
      FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      WHERE g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 240
    )                                                                                                                               H12, ---PaymentDueDate
    DEL.DELegat                                                                                                                     H13a,---InvoiceDelegate
    DEL.CNP ||&apos;/&apos;||DEL.SERIedoc||DEL.NRdoc                                                                                          H13b,---InvoiceDelegateIdentification
    DEL.Obs                                                                                                                         H13c,---DeliveryType
    DEL.NRTRANSP                                                                                                                    H13d,---DeliveryIdentification
    ssoc.GLN                                                                                                                        H14a,--*Buyer/GLN
    pcf.codfiscal                                                                                                                   H14b,--*Buyer/VAT
    p.RegCom                                                                                                                        H14c,--*Buyer/RegNo
    p.Den_Part                                                                                                                      H14d,--*Buyer/Name
    GetAdresa(ssoc.sector, ssoc.strada, ssoc.nr1, ssoc.nr2, ssoc.bloc, ssoc.scara, ssoc.etaj, ssoc.apart, NULL)                     H14e,--*Buyer/Address
    Upper(lsoc.Den_Localit)||&apos;, &apos;||InitCap(lsoc.den_judet)                                                                          H14f,--*Buyer/Town
    ssoc.CodPostal                                                                                                                  H14g,--*Buyer/PostalCode
    lsoc.t_SimbAuto                                                                                                                 H14h,--*Buyer/CountryCode
    pbc.ContBanca                                                                                                                   H14i,--*Buyer/IBAN
    Coalesce(CASE WHEN sliv.edi_parttip = 5 THEN vGLNLaClient END,ssub.GLN)                                                         H15a,--*Seller/GLN
    f.codfiscal                                                                                                                     H15b,--*Seller/VAT
    f.nrj                                                                                                                           H15c,--*Seller/RegNo
    f.DenFirma                                                                                                                      H15d,--*Seller/Name
    GetAdresa(f.sector, f.strada, f.nr1, f.nr2, f.bloc, f.scara, f.etaj, f.ap, NULL)                                                H15e,--*Seller/Address
    Upper(f.DenLocalit)||&apos;, &apos;||InitCap(f.denjudet)                                                                                  H15f,--*Seller/Town
    f.CodPostal                                                                                                                     H15g,--*Seller/PostalCode
    f.SimbTara                                                                                                                      H15h,--*Seller/CountryCode
    CASE
      WHEN sliv.edi_parttip = 1 THEN sliv.edi_partid
      WHEN sliv.edi_parttip = 2 THEN f.codfiscal
      WHEN sliv.edi_parttip = 3 THEN sliv.gln
      ELSE                           vIDLaClient
    END                                                                                                                             H15i,--*Seller/BuyerInternalCode  -&gt;  (5 caractere) DA Codul intern la furnizor
    fbc.nrcont                                                                                                                      H15j,--*Seller/IBAN
    f.CapitalS                                                                                                                      H15k,--*Seller/RegisteredCapital
    sliv.GLN                                                                                                                        H16a,--*Delivery/GLN
    sliv.Obs                                                                                                                        H16b,--*Delivery/Name
    GetAdresa(sliv.sector, sliv.strada, sliv.nr1, sliv.nr2, sliv.bloc, sliv.scara, sliv.etaj, sliv.apart, NULL)                     H16c,--*Delivery/Address
    Upper(lliv.Den_Localit)||&apos;, &apos;||InitCap(lliv.den_judet)                                                                          H16d,--*Delivery/Town
    sliv.CodPostal                                                                                                                  H16e,--*Delivery/PostalCode
    lliv.t_SimbAuto                                                                                                                 H16f,--*Delivery/CountryCode
    --Lines
    Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          L01a,--*Line/LineNumber
    CASE Coalesce(sliv.edi_expean,0)
      WHEN 1 THEN ac.CodLaClient
      WHEN 2 THEN ac.CodExtern
      WHEN 3 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      ELSE o.CodExtern
    END                                                                                                                             L02a,--*Line/EAN
    o.Denumire                                                                                                                      L02b,--*Line/ArticleName
    Trim (
      CASE sliv.edi_objtip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        ELSE Coalesce(ac.CodExtern,ac.CodLaClient)
      END)                                                                                                                          L02c,--*Line/BuyerItemCode
    SubStr(Trim (
      CASE sliv.edi_objtip2
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        ELSE ac.CodLaClient
      END), 1,11)                                                                                                                   L02d,---Line/BuyerAdditionalItemCode
    o.CodIntern                                                                                                                     L02e,--*Line/SupplierItemCode
    TO_CHAR(COM1.CANTCOMANDAT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                        L03a,---Line/QuantityOrder
    TO_CHAR(I1.CANT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                  L03b,---Line/QuantityReception
    TO_CHAR(I1.CANT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                  L03c,--*Line/QuantityInvoice
    Upper(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN UM.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN UM.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN UM.CODEXTERN
        END,UM.DEN_EANCOM,UM.Den_UM1
      )
    )                                                                                                                               L04a,--*Line/UnitOfMeasure
    TO_CHAR(CASE WHEN UM.Den_EanCom IS NULL THEN UM.PARITATE ELSE 1 END,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)       L05a,--*Line/PackingUnit
    TO_CHAR(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*Coalesce(UM.PARITATE,1), &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)   L05b,--*Line/PackUnitPrice
    TO_CHAR(
      I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*CASE WHEN UM.Den_EanCom IS NULL THEN 1 ELSE UM.PARITATE END,
      &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               L06a,---Line/UnitPrice
    CASE --S = standard rate, E = exempt from tax, Z = zero tax
      WHEN COALESCE(I1.TVA, 0) &lt;&gt; 0 THEN &apos;S&apos;
      WHEN I1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;,&apos;R&apos;) AND PKG_LIST_BASE_UTILS.getTipTVA0(I1.codobiect,I.an,I.luna) = 2 THEN &apos;E&apos;
      ELSE &apos;Z&apos;
    END                                                                                                                             L07a,--*Line/TaxType
    CASE --VAT = value added tax, ENV = green tax, OTH = other tax
      WHEN PKG_LIST_BASE_UTILS.isGreenTax(I1.codobiect, i1.TipLinie, I.an,I.luna) = 1 THEN &apos;ENV&apos;
      ELSE &apos;VAT&apos;
    END                                                                                                                             L07b,--*Line/TaxReason
    TO_CHAR(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*I1.CANT,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                      L07c,--*Line/TotalPriceNoTax
    TO_CHAR(
      PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)
    )                                                                                                                               L07d,--*Line/TaxRate
    TO_CHAR(
      CASE
        WHEN I1.PU = 0 THEN 0
        ELSE I1.TVA*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU
      END, &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               L07e,--*Line/Tax
    TO_CHAR(
      CASE
        WHEN I1.PU = 0 THEN 0
        ELSE (I1.PU*I1.CANT+I1.TVA)*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU
      END, &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               L07f,--*Line/TotalPriceIncludingTax
    TO_CHAR(
      (I1.PU-I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1))*Coalesce(UM.PARITATE,1),
      &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                                                                               L07g,---Line/DiscountNoVat
    NULL                                                                                                                            L07h,---Line/EcoTax
    NULL                                                                                                                            L07i,---Line/GreenTax
    &apos;0&apos;                                                                                                                             L08a,---Line/ReturnablePackage   0/1
    --Summary
    Count(1) OVER (PARTITION BY i1.codies)                                                                                          S01a,--*Lines
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)-Round(I.TvaDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)
      END,
      &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           S02a,--*TotalPriceNoTax
    TO_CHAR(I.TvaDoc,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                            S02b,--*TotalTax
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
      END,
      &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                           S02c,--*TotalIncludingTax
    -- Linii pentru validare Export
    Min(Coalesce(st.codies,0)) OVER (PARTITION BY i.codies)                                                                         MinCodStorn,
    Max(Coalesce(st.codies,0)) OVER (PARTITION BY i.codies)                                                                         MaxCodStorn,
    Max(
      CASE
        WHEN Upper(
               Coalesce(
                 CASE
                   WHEN sliv.edi_denum = 1 THEN UM.DEN_EANCOM
                   WHEN sliv.edi_denum = 2 THEN UM.DEN_UM1
                   WHEN sliv.edi_denum = 3 THEN UM.CODEXTERN
                 END,UM.DEN_EANCOM,UM.Den_UM1
               )
             ) IN (&apos;PCE&apos;,&apos;KGM&apos;)
        THEN 0
        ELSE 1
      END
    ) OVER (PARTITION BY i.codies)                                                                                                  UMEancomErr
  FROM TMP_EDI_IES1 ti1
    CROSS JOIN TMP_FIRMA_ADR f
    LEFT  JOIN iesiri       i    ON i.codies   = ti1.codies
    LEFT  JOIN iesiri1      i1   ON i1.codies1 = ti1.codies1
    LEFT  JOIN nmonede      m    ON m.codmoneda = Coalesce(i.moneda,0)
    LEFT  JOIN npart        p    ON p.codpart = i.partener
    LEFT  JOIN nagenda      sliv ON sliv.codagenda = i.codlocatie
    LEFT  JOIN loc          lliv ON lliv.codlocalit = sliv.codlocalit --compromis sa nu crape pentru pre multe joinuri pe 11.0.1
    LEFT  JOIN nagenda      ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
    LEFT  JOIN loc          lsoc ON lsoc.codlocalit = ssoc.codlocalit --compromis sa nu crape pentru pre multe joinuri pe 11.0.1
    LEFT  JOIN nagenda      ssub ON ssub.codsubunit = i.subunitatea
    LEFT  JOIN npartcodfisc pcf  ON pcf.cod_codfiscal = i.codfiscal
    LEFT  JOIN nparttr      del  ON del.codparttr = i.delegat
    LEFT  JOIN npartb       pbc  ON pbc.codpart = p.codpart AND pbc.implicit = 1
    LEFT  JOIN nbank        pb   ON pb.codbank = pbc.codbank
    LEFT  JOIN nlocalit     lpb  ON lpb.codlocalit = pbc.codlocalit
    LEFT  JOIN nartobj      o    ON o.codobiect = i1.codobiect
    LEFT  JOIN nart         a    ON a.codarticol = o.codarticol
    LEFT  JOIN nart1        a1   ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
    LEFT  JOIN ntva1        t1   ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    LEFT  JOIN num1         ud   ON ud.codum1 = i1.umsec
    LEFT  JOIN num1         um   ON um.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN um.codum1-ud.codum1 ELSE um.secundara END = 0
    LEFT  JOIN nartcli      ac   ON ac.codartcli = ti1.codartcli
    LEFT  JOIN ieslink      ila  ON ila.codies1 = i1.codies1 AND ila.codlinieaviz IS NOT NULL
    LEFT  JOIN iesiri1      ae1  ON ae1.codies1 = ila.codlinieaviz
    LEFT  JOIN iesiri       ae   ON ae.codies = ae1.codies
    LEFT  JOIN ieslink      ilc  ON ilc.codies1 = Coalesce(ila.codlinieaviz, i1.codies1) AND ilc.codliniecomanda IS NOT NULL
    LEFT  JOIN cmdlivrlink  cl   ON cl.codcomanda1 = ilc.codliniecomanda
    LEFT  JOIN comanda1     com1 ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
    LEFT  JOIN comanda      com  ON com.codcomanda = com1.codcomanda
    LEFT  JOIN nbankcont    fbc  ON fbc.codbankcont = f.codbankcont
    LEFT  JOIN nbank        fb   ON fb.codbank = fbc.codbank
    LEFT  JOIN nlocalit     lfb  ON lfb.codlocalit = fbc.codlocalitate
    LEFT  JOIN iesiri1      st1  ON st1.codies1 = CASE
                                                    WHEN                                               Coalesce(i1.codies1storno ,0) &lt;&gt; 0 THEN i1.codies1storno
                                                    WHEN Coalesce(i1.tipdocimp, 0) IN (19, 20, 26) AND Coalesce(i1.codliniedocimp,0) &lt;&gt; 0 THEN i1.codliniedocimp
                                                  END
    LEFT  JOIN iesiri       st   ON st.codies = st1.codies
  ORDER BY i1.indexlocal, i1.codies1;

 Return crsResult;
END;

FUNCTION GetXMLDocExpertSupplierT(pCodIes NUMBER) RETURN crsGlobal IS
  crsResult crsGlobal;
BEGIN
  OPEN crsResult FOR
  SELECT
    --TaxSummary
    TaxType                                                                               T01,--*TaxLine/TaxType
    TaxReason                                                                             T02,--*TaxLine/TaxReason
    TO_CHAR(TaxRate                 , &apos;fm9999999990&apos;   , &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) T03,--*TaxLine/TaxRate
    TO_CHAR(Sum(TotalPriceNoTax)    , &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) T04,--*TaxLine/TotalPriceNoTax
    TO_CHAR(Sum(TotalTax)           , &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) T05,--*TaxLine/TotalTax
    TO_CHAR(Sum(TotalIncludingTax)  , &apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) T06 --*TaxLine/TotalIncludingTax
  FROM (
    SELECT
      CASE --S = standard rate, E = exempt from tax, Z = zero tax
        WHEN COALESCE(I1.TVA, 0) &lt;&gt; 0 THEN &apos;S&apos;
        WHEN I1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;,&apos;R&apos;) AND PKG_LIST_BASE_UTILS.getTipTVA0(I1.codobiect,I.an,I.luna) = 2 THEN &apos;E&apos;
        ELSE &apos;Z&apos;
      END                                                                                                                         TaxType,
      CASE --VAT = value added tax, ENV = green tax, OTH = other tax
        WHEN PKG_LIST_BASE_UTILS.isGreenTax(I1.codobiect, i1.TipLinie, I.an,I.luna) = 1 THEN &apos;ENV&apos;
        ELSE &apos;VAT&apos;
      END                                                                                                                         TaxReason,
      PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1) TaxRate,
      Round(I1.PU*I1.CANT, 2)                                                                                                     TotalPriceNoTax,
      Round(I1.TVA, 2)                                                                                                            TotalTax,
      Round(I1.PU*I1.CANT+I1.TVA, 2)                                                                                              TotalIncludingTax
    FROM iesiri1 i1
      INNER JOIN iesiri i ON i.codies = i1.codies
      LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
      LEFT JOIN nart1 a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT JOIN ntva1 t1 ON t1.codtva = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
    WHERE i1.codies = pCodIes
      AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)
  )
  GROUP BY TaxRate, TaxType, TaxReason
  ORDER BY TaxRate, TaxType, TaxReason;

  Return crsResult;
END;

FUNCTION GetXMLDesAdvExpertSuppl(pCodIes NUMBER, pBULK NUMBER DEFAULT 0) RETURN crsGlobal IS
  crsResult        crsGlobal;
  vCodPart         NUMBER(20);
  vClasaPart       NUMBER(20);
  vIDLaClient      VARCHAR2(100);
  pDocXChangeTipUM NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;DocXChangeTipUM&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
  pTecNetComNRI    NUMBER := Coalesce(pkg_categconst.GetValConstanta(&apos;TecNetComNRI&apos;    ,pkg_globals.ANLUCRU,pkg_globals.lunalucru), 2) ;
BEGIN
  PrepFirmaAdr(pCodIes);
  IF Coalesce(vExpEdiCodIes,0) &lt;&gt; pCodIes OR pBULK = 1 THEN
    vExpSupDocType       := 0;
    vOrderNumber         := NULL;
    vOrderDate           := NULL;
    vDespatchNumber      := NULL;
    vDespatchDate        := NULL;
  END IF;

  SELECT p.codpart, p.codclasa, pkg_exportedi.GetIDLaClient(sliv.edi_parttip, i.codies)
  INTO   vCodPart,  vClasaPart, vIDLaClient
  FROM iesiri i
    LEFT JOIN npart   p    ON p.codpart      = i.partener
    LEFT JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes
    AND Coalesce(sliv.edi_exptip,0) = 5
    AND Coalesce(sliv.edi_parttip,0) &gt; 0
    AND i1.tiplinie IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;);
  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  OPEN crsResult FOR
  SELECT
    CASE
      WHEN Nullif(sliv.EDI_SUBDIREXP, &apos;&apos;) IS NULL THEN &apos;&apos;
      ELSE sliv.EDI_SUBDIREXP||&apos;\&apos;
    END||
    Coalesce(pcf.codfiscal,p.den_part)||&apos;_&apos;||To_Char(I.DataDoc,&apos;yyyymmdd&apos;)||&apos;_&apos;||I.NrDoc||&apos;_&apos;||Coalesce(f.Codfiscal,f.denfirma)     FileName,
    &apos;2.0&apos;                                                                                                                           Ver, --*Version
    --Header
    To_Char(I.DataDoc, &apos;yyyy-mm-dd&apos;)                                                                                                H01a,--*DocumentDate
    CASE
      WHEN vDespatchNumber IS NOT NULL THEN vDespatchNumber
      ELSE To_Char(I.NrDoc)
    END                                                                                                                             H01b,--*DeliveryNumber
    CASE
      WHEN vDespatchdate IS NOT NULL THEN vDespatchdate
      ELSE To_Char((SELECT Max(L.DataLivr) FROM LIVR L WHERE L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC), &apos;yyyy-mm-dd&apos;)
    END                                                                                                                             H01c,--*DeliveryDate
    CASE
      WHEN vOrderNumber IS NOT NULL THEN vOrderNumber
      WHEN pTecNetComNRI = 1
      THEN Max(Coalesce(COM.NRI,To_Char(COM.NrDoc))) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
      ELSE Max(To_Char(COM.NrDoc))                   KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             H02a,--*OrderNumber
    CASE
      WHEN vOrderDate IS NOT NULL THEN vOrderDate
      ELSE Max(To_Char(COM.DataDoc, &apos;yyyy-mm-dd&apos;)) KEEP (DENSE_RANK LAST ORDER BY Coalesce(COM.CodComanda,0)) OVER (PARTITION BY i1.codies)
    END                                                                                                                             H02b,--*OrderDate
    CASE
      WHEN vExpSupDocType = 4 THEN &apos;R&apos;
      WHEN vExpSupDocType = 3 THEN &apos;C&apos;
      WHEN vExpSupDocType = 2 THEN &apos;O&apos;
      WHEN ST.CODIES IS NOT NULL THEN &apos;C&apos;
      ELSE &apos;O&apos;
    END                                                                                                                             H03, --*DocumentType
    0                                                                                                                               H04, --*TestIndicator
    ssoc.GLN                                                                                                                        H05a,--*Buyer/GLN
    ssub.GLN                                                                                                                        H06a,--*Seller/GLN
    CASE
      WHEN sliv.edi_parttip = 1 THEN sliv.edi_partid
      WHEN sliv.edi_parttip = 2 THEN f.codfiscal
      WHEN sliv.edi_parttip = 3 THEN sliv.gln
      ELSE                           vIDLaClient
    END                                                                                                                             H06b,--*Seller/BuyerInternalCode
    sliv.GLN                                                                                                                        H07a,--*Delivery/GLN
    sfac.GLN                                                                                                                        H08a,--*Invoicee/GLN
    --Lines
    --Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1)                                                                          L01a,--*Line/LineNumber
    Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1, p2.codpacking2, COALESCE(NSER.TG, NS.TG), SER.Serie)                     L01a,--*Line/LineNumber
    CASE Coalesce(sliv.edi_expean,0)
      WHEN 1 THEN ac.CodLaClient
      WHEN 2 THEN ac.CodExtern
      WHEN 3 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
      ELSE o.CodExtern
    END                                                                                                                             L02a,--*Line/EAN
    o.Denumire                                                                                                                      L02b,--*Line/ArticleName
    Trim (
      CASE sliv.edi_objtip
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        ELSE Coalesce(ac.CodExtern,ac.CodLaClient)
      END)                                                                                                                          L02c,--*Line/BuyerItemCode
    SubStr(Trim (
      CASE sliv.edi_objtip2
        WHEN 1 THEN (SELECT Max(ge.cod) FROM nechiv e LEFT JOIN grechiv ge ON ge.codgrechiv = e.codgrupa WHERE e.codobiect = o.codobiect)
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN o.codextern
        WHEN 4 THEN o.codintern
        WHEN 5 THEN o.codvamal
        WHEN 6 THEN To_Char(o.codplu)
        WHEN 7 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        WHEN 8 THEN ac.codlaclient
        WHEN 9 THEN (SELECT Max(aa.CodExtern) FROM NARTAMB aa WHERE aa.codobiect = o.codobiect AND aa.umsec = i1.umsec)
        ELSE ac.CodLaClient
      END), 1,11)                                                                                                                   L02d,---Line/BuyerAdditionalItemCode
    o.CodIntern                                                                                                                     L02e,--*Line/SupplierItemCode
    NULL                                                                                                                            L02f,--*Line/SupplierItemCodeVariant
    TO_CHAR(COM1.CANTCOMANDAT/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                        L03a,---Line/QuantityOrder
    TO_CHAR(Coalesce(P3.CANT, I1.CANT)/Coalesce(UM.PARITATE,1) ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)               L03b,--*Line/QuantityDelivery
    Upper(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN UM.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN UM.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN UM.CODEXTERN
        END,UM.DEN_EANCOM,UM.Den_UM1
      )
    )                                                                                                                               L04a,--*Line/UnitOfMeasure
    TO_CHAR(CASE WHEN UM.Den_EanCom IS NULL THEN UM.PARITATE ELSE 1 END,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)       L04b,--*Line/PackingUnit
    TO_CHAR(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*Coalesce(UM.PARITATE,1),
            &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                   L04c,--*Line/Price
    TO_CHAR(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*CASE WHEN UM.Den_EanCom IS NULL THEN 1 ELSE UM.PARITATE END,
            &apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)                                                                   L04d,---Line/UnitNetPrice
    &apos;CU&apos;                                                                                                                            L05a,--*Line/ArticleType
    NULL                                                                                                                            L05b,--*Line/FreeGoods
    NULL                                                                                                                            L05c,--*Line/ExpiryDate
    To_Char(COALESCE(NSER.TG, NS.TG), &apos;yyyy-mm-dd&apos;)                                                                                 L05d,--*Line/BestBeforeDate
    NULL                                                                                                                            L05e,--*Line/ReasonActionCode
    SER.Serie                                                                                                                       L05f,--*Line/BatchNo
    Coalesce(P2.SSCC, GET_CODE_SCCC(o.CodIntern))                                                                                   L05g,--*Line/SSCC
    NULL                                                                                                                            L06a,--*Line/VendorOrderNo
    NULL                                                                                                                            L06b,--*Line/VendorOrderNoPos
    NULL                                                                                                                            L06c,--*Line/VendorDespatchNo
    NULL                                                                                                                            L06d,--*Line/VendorDespatchNoPos
    NULL                                                                                                                            L07a,--*Line/CustomerOrderNo
    NULL                                                                                                                            L07b,--*Line/CustomerOrderNoPos
    NULL                                                                                                                            L08a,--*Line/DeliveryPackageType
    NULL                                                                                                                            L08b,--*Line/NoOfDeliveryPackages
    NULL                                                                                                                            L08c,--*Line/PackageWeight
    NULL                                                                                                                            L08d,--*Line/PackageLenght
    NULL                                                                                                                            L08e,--*Line/PackageHeight
    NULL                                                                                                                            L08f,--*Line/PackageWidth
    NULL                                                                                                                            L08g,--*Line/PackageVolume
    NULL                                                                                                                            L09a,--*Line/MaxStackability
    --Summary
    --Count(1) OVER (PARTITION BY i1.codies)                                                                                          S01a,--*Lines
    Count(1) OVER (PARTITION BY i1.codies, p2.codpacking2, COALESCE(NSER.TG, NS.TG), SER.Serie)                                     S01a,--*Lines

    -- Linii pentru validare Export
    Min(Coalesce(st.codies,0)) OVER (PARTITION BY i.codies)                                                                         MinCodStorn,
    Max(Coalesce(st.codies,0)) OVER (PARTITION BY i.codies)                                                                         MaxCodStorn,
    Max(
      CASE
        WHEN Upper(
               Coalesce(
                 CASE
                   WHEN sliv.edi_denum = 1 THEN UM.DEN_EANCOM
                   WHEN sliv.edi_denum = 2 THEN UM.DEN_UM1
                   WHEN sliv.edi_denum = 3 THEN UM.CODEXTERN
                 END,UM.DEN_EANCOM,UM.Den_UM1
               )
             ) IN (&apos;PCE&apos;,&apos;KGM&apos;)
        THEN 0
        ELSE 1
      END
    ) OVER (PARTITION BY i.codies)                                                                                                  UMEancomErr
  FROM TMP_EDI_IES1 ti1
    CROSS JOIN TMP_FIRMA_ADR f
    LEFT  JOIN iesiri       i    ON i.codies = ti1.codies
    LEFT  JOIN iesiri1      i1   ON i1.codies1 = ti1.codies1
    LEFT  JOIN nmonede      m    ON m.codmoneda = Coalesce(i.moneda,0)
    LEFT  JOIN npart        p    ON p.codpart = i.partener
    LEFT  JOIN npartcodfisc pcf  ON pcf.cod_codfiscal = i.codfiscal
    LEFT  JOIN nagenda      sliv ON sliv.codagenda = i.codlocatie
    LEFT  JOIN nagenda      ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial BETWEEN 4 AND 7 AND Coalesce(ssoc.inactiv, 0) = 0
    LEFT  JOIN nagenda      sfac ON sfac.codagenda = CASE WHEN sliv.sediusocial = 1 THEN sliv.codcoresp WHEN sliv.sediusocial IN (3,7) THEN sliv.codagenda ELSE 0 END
    LEFT  JOIN nagenda      ssub ON ssub.codsubunit = i.subunitatea
    LEFT  JOIN nartobj      o    ON o.codobiect = i1.codobiect
    LEFT  JOIN nart         a    ON a.codarticol = o.codarticol
    LEFT  JOIN num1         ud   ON ud.codum1 = i1.umsec
    LEFT  JOIN num1         um   ON um.codum = ud.codum AND CASE pDocXChangeTipUM WHEN 2 THEN um.codum1-ud.codum1 ELSE um.secundara END = 0
    LEFT  JOIN nartcli      ac   ON ac.codartcli = ti1.codartcli
    LEFT  JOIN ieslink      ilc  ON ilc.codies1 = i1.codies1 AND ilc.codliniecomanda IS NOT NULL
    LEFT  JOIN cmdlivrlink  cl   ON cl.codcomanda1 = ilc.codliniecomanda
    LEFT  JOIN comanda1     com1 ON com1.codcomanda1 = COALESCE(cl.codliniecomanda, ilc.codliniecomanda)
    LEFT  JOIN comanda      com  ON com.codcomanda = com1.codcomanda

    LEFT  JOIN comanda1     dl1  ON dl1.codcomanda1 = ilc.codliniecomanda
    LEFT  JOIN comanda      dl   ON dl.codcomanda = dl1.codcomanda and dl.displivrare = 1
    LEFT  JOIN packing      p    ON p.coddoc = dl.codcomanda AND p.tipdoc = dl.tipdoc
    LEFT  JOIN packing1     p1   ON p1.coddoc1 = dl1.codcomanda1 and p1.codpacking = p.codpacking
    LEFT  JOIN packing2     p2   ON p2.codpacking1 = p1.codpacking1
    LEFT  JOIN packing3     p3   on p3.codpacking2 = p2.codpacking2
    LEFT  JOIN rezervats    rs   ON rs.codrezervats = p3.codrezervats
    LEFT  JOIN nirstoc      ns   ON ns.codnirstoc = rs.codnirstoc
    LEFT  JOIN nirser       nser ON nser.codnirser = rs.codnirser
    LEFT  JOIN nserii       ser  ON ser.codserie = nser.codserie

    LEFT  JOIN iesiri1      st1  ON st1.codies1 = CASE
                                                    WHEN Coalesce(i1.codies1storno,0) &lt;&gt; 0 THEN Coalesce(i1.codies1storno,0)
                                                    WHEN Coalesce(i1.tipdocimp, 0) IN (19, 20, 26) AND Coalesce(i1.codliniedocimp, 0 ) &lt;&gt; 0 THEN i1.codliniedocimp
                                                  END
    LEFT  JOIN iesiri       st   ON st.codies = st1.codies
  ORDER BY i1.indexlocal, i1.codies1;

  Return crsResult;
END;

PROCEDURE SetXMLIATAData_LINEDR(pCodIes NUMBER, pIDRType VARCHAR2, pValFieldI1 VARCHAR2, pValFieldI VARCHAR2) IS
  vCntFieldI1 PLS_INTEGER;
  vCntFieldI  PLS_INTEGER;
  vOrd1       PLS_INTEGER;
  sVal        VARCHAR2(200);
  sJoinI1EXT  VARCHAR2(500);
  SJOINIEXT   VARCHAR2(500);
  cSql        CLOB;
BEGIN
  SELECT Count(1)  INTO vCntFieldI1 FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;IESIRI1EXT&apos; AND COLUMN_NAME = pValFieldI1;
  SELECT Count(1)  INTO vCntFieldI  FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;IESIRIEXT&apos;  AND COLUMN_NAME = pValFieldI;
  SELECT Max(ORD1) INTO vOrd1       FROM TMP_IATA_LINEDR;
  vOrd1 := Coalesce(vOrd1, 0) + 1;

  IF vCntFieldI1 &gt; 0 OR vCntFieldI &gt; 0 THEN
    IF     vCntFieldI1 = 0 THEN
      sVal := &apos;IE.&apos;||pValFieldI;
    ELSIF  vCntFieldI = 0 THEN
      sVal := &apos;I1E.&apos;||pValFieldI1;
    ELSE
      sVal := &apos;Coalesce(I1E.&apos;||pValFieldI1||&apos;, IE.&apos;||pValFieldI||&apos;)&apos;;
    END IF;

    IF vCntFieldI1 &gt; 0 THEN
      sJoinI1EXT :=&apos;
          LEFT  JOIN IESIRI1EXT I1E ON I1E.CODIES1  = AE1.CODIES1&apos;;
    END IF;

    IF vCntFieldI &gt; 0 THEN
      SJOINIEXT :=&apos;
          LEFT  JOIN IESIRIEXT   IE ON IE.CODIES    = AE.CODIES&apos;;
    END IF;

    BEGIN
      EXECUTE IMMEDIATE&apos;
        INSERT INTO TMP_IATA_LINEDR
        SELECT
          I1.CODIES1,
          :vOrd1     AS ORD1,
          &apos;||sVal||&apos; AS LDR01 ,--120/ItemDeliveryReferenceValue
          :pIDRType  AS LDR01A --121/ItemDeliveryReferenceType
        FROM IESIRI I
          INNER JOIN IESIRI1     I1 ON I1.CODIES    = I.CODIES
          LEFT  JOIN IESLINK   ILAE ON ILAE.CODIES1 = I1.CODIES1 AND ILAE.CODLINIEAVIZ IS NOT NULL
          LEFT  JOIN IESIRI1    AE1 ON AE1.CODIES1  = Coalesce(ILAE.CODLINIEAVIZ, I1.CODIES1) &apos;||
          sJoinI1EXT ||&apos;
          LEFT  JOIN IESIRI      AE ON AE.CODIES    = AE1.CODIES &apos;||
          sJoinIEXT ||&apos;
        WHERE I.CODIES = :pCodIes&apos;
      USING vOrd1, pIDRType, pCodIes;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;
END;

PROCEDURE SetXMLIATAData(pCodIes NUMBER) IS
  vCodPart      NUMBER(20);
  vClasaPart    NUMBER(20);
  dDueDate      DATE;
  vDueDays      NUMBER(10);
BEGIN
  PrepFirmaAdr(pCodIes);
  --PG--CALL create_wm_temps_flag(&apos;TMP_IATA&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IH&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_ITD&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IPT&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IRV&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IN&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IID&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_IIDCF&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_ITAX&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_SI&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_SIID&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_SIIDCF&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_SITAX&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_SIFN&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINE&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINEQ&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINEDR&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINET&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINERLD&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_LINERGD&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_PROD&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IATA_TAX&apos;;

  SELECT p.codpart, p.codclasa INTO vCodPart, vClasaPart
  FROM iesiri i LEFT JOIN npart p ON p.codpart = i.partener
  WHERE i.codies = pCodIes;

  SELECT
    Max( Greatest(Coalesce(O.TERMEN,I.DATADOC)          ,I.DATADOC)) AS TERMEN,
    Max( Greatest(Coalesce(Trunc(O.TERMEN-I.DATADOC), 0),0        )) AS ZILE
  INTO
    dDueDate,
    vDueDays
  FROM IESIRI I
    LEFT JOIN GENERAL  G ON G.TIPDOC     = I.TIPDOC AND G.CODDOC = I.CODIES
    LEFT JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
  WHERE i.codies = pCodIes;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_EDI_IES1&apos;;
  INSERT INTO TMP_EDI_IES1(CODIES1, CODIES, CODOBIECT)
  SELECT i1.codies1, i1.codies, i1.codobiect
  FROM iesiri i
    INNER JOIN nagenda sliv ON sliv.codagenda = i.codlocatie
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE i.codies = pCodIes;
  UPDATE TMP_EDI_IES1 SET CODARTCLI = PKG_LIST_BASE_UTILS.GetCodArtCli(CodObiect, vCodPart,  vClasaPart);

  INSERT INTO TMP_IATA_IH
  SELECT
    I.CODIES,
    pcf.codfiscal||&apos;_&apos;||To_Char(I.DataDoc,&apos;yyyymmdd&apos;)||&apos;_&apos;||I.NrDoc             AS DENXML,
    To_Char(I.DATACREARE,&apos;YYYYMMDDHH24MISS&apos;)                                    AS ITH01  ,--004/InvoiceTransmissionId
    To_Char(I.DATACREARE,&apos;YYYY-MM-DD&apos;)||&apos;T&apos;||To_Char(I.DATACREARE,&apos;HH24:MI:SS&apos;) AS ITH02  ,--005/InvoiceCreationDate                / DATE YYYY-MM-DDThh:mm:ss
    &apos;3.1.0&apos;                                                                     AS ITH03  ,--006/Version
    NULL                                                                        AS ITH04  ,--007/TransmissionID
    NULL                                                                        AS ITH05  ,--008/IssuingOrganizationID
    NULL                                                                        AS ITH06  ,--009/ReceivingOrganizationID
    NULL                                                                        AS ITH07  ,--010/TestFlag
    p.codextern                                                                 AS IH01   ,--015/CustomerEntityID
    slivr.edi_partid                                                            AS IH02   ,--016/IssuingEntityID
    f.denfirma                                                                  AS IH03   ,--017/IssuingEntityName
    NULL                                                                        AS IH04   ,--018/IssuingEntityAffiliateName
    NULL                                                                        AS IH05   ,--019/InvoiceEntityAffiliateNotes
    I.SeriaDoc||To_Char(I.Nrdoc)                                                AS IH06   ,--020/InvoiceNumber
    To_Char(I.DataDoc,&apos;YYYY-MM-DD&apos;)                                             AS IH07   ,--021/InvoiceIssueDate                   / DATE YYYY-MM-DD
    &apos;INV&apos;                                                                       AS IH08   ,--022/InvoiceType
    &apos;FI&apos;                                                                        AS IH08A  ,--023/InvoiceTransactionType
    slivr.IDSediu                                                               AS IH09   ,--024/InvoiceDeliveryLocation
    tlivr.SimbAuto                                                              AS IH10   ,--025/InvoiceDeliveryCountryCode
    NULL                                                                        AS IH11   ,--026/InvoicePaymentTermsType
    NULL                                                                        AS IH12   ,--027/InvoicePaymentTermsDateBasis
    NULL                                                                        AS IH13   ,--028/InvoicePaymentTermsDiscountPercent / NUMERIC 18,6
    NULL                                                                        AS IH14   ,--029/InvoicePaymentTermsDiscountDueDate / DATE YYYY-MM-DD
    To_Char(dDueDate,&apos;YYYY-MM-DD&apos;)                                              AS IH15   ,--030/InvoicePaymentTermsNetDueDate      / DATE YYYY-MM-DD
    To_Char(vDueDays)                                                           AS IH16   ,--031/InvoicePaymentTermsNetDueDays      / NUMERIC 10
    NULL                                                                        AS IH19   ,--035/TaxInvoiceNumber
    NULL                                                                        AS IH20   ,--036/TaxPointDate                       / DATE YYYY-MM-DD DDThh:mm:ss
    NULL                                                                        AS IH21   ,--037/InvoiceTaxClause
    SubStr(M.SIMBOL,1,3)                                                        AS IH22   ,--038/InvoiceCurrencyCode
    NULL                                                                        AS IH23   ,--039/InvoiceCurrencyCodeLocal
    &apos;M&apos;                                                                         AS IHCC01 ,--041/ConversionMechanism
    SubStr(MT.SIMBOL,1,3)                                                       AS IHCC02 ,--042/CurrencyFrom
    &apos;1&apos;                                                                         AS IHCC02A,--043/FactorFrom                         / NUMERIC 9
    SubStr(M.SIMBOL,1,3)                                                        AS IHCC03 ,--044/CurrencyTo
    &apos;1&apos;                                                                         AS IHCC03A,--045/FactorTo                           / NUMERIC 9
    TO_CHAR(
      Coalesce(NullIF(I.CURS,0), 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                           AS IHCC04 ,--046/ExchangeRate                       / NUMERIC 18,6
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
      END,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                           AS IH24   ,--047/InvoiceTotalAmount                 / NUMERIC 18,2
    NULL                                                                        AS IH25   ,--048/InvoiceTotalAmountLocal            / NUMERIC 18,2
    TO_CHAR(
      Round(I.ValDiscount,2),
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                           AS IH26   ,--049/InvoiceDiscountAmount              / NUMERIC 18,2
    NULL                                                                        AS IH27   ,--050/InvoiceDiscountAmountLocal         / NUMERIC 18,2

    NULL                                                                        AS IS01   ,--222/InvoiceLineCount                   / NUMERIC 18
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
      END,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                           AS IS02   ,--223/TotalInvoiceLineAmount             / NUMERIC 18,2
    NULL                                                                        AS IS03   ,--224/TotalInvoiceLineAmountLocal        / NUMERIC 18,2
    TO_CHAR(
      Round(I.TvaDoc,2),
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                                           AS IS04   ,--225/TotalInvoiceTaxAmount              / NUMERIC 18,2
    NULL                                                                        AS IS05   ,--226/TotalInvoiceTaxAmountLocal         / NUMERIC 18,2
    1                                                                           AS ITS01   --228/InvoiceMessageCount                / NUMERIC 6
  FROM IESIRI I
    CROSS JOIN TMP_FIRMA_ADR   F
    INNER JOIN NPART           P ON P.CODPART = I.PARTENER
    LEFT  JOIN NPARTCODFISC  PCF ON PCF.COD_CODFISCAL = I.CODFISCAL
    INNER JOIN NAGENDA     SLIVR ON SLIVR.CODAGENDA   = I.CODLOCATIE
    LEFT  JOIN NLOCALIT    LLIVR ON LLIVR.CODLOCALIT  = SLIVR.CODLOCALIT
    LEFT  JOIN NJUDET      JLIVR ON JLIVR.CODJUDET    = LLIVR.CODJUDET
    LEFT  JOIN NTARI       TLIVR ON TLIVR.CODTARA     = LLIVR.CODTARA
    LEFT  JOIN NMONEDE        M  ON M.CODMONEDA       = Coalesce(I.MONEDA,0)
    LEFT  JOIN NMONEDE        MT ON MT.CODMONEDA      = Coalesce(I.MONEDATRANSF,0)
  WHERE I.CODIES = pCodIes;

  --TMP_IATA_ITD&apos;;
  --TMP_IATA_IPT&apos;;
  --TMP_IATA_IRV&apos;;
  --TMP_IATA_IN&apos;;

  INSERT INTO TMP_IATA_IID
  SELECT
    I.CODIES,
    1                          AS ORD1,
    &apos;II&apos;                       AS IID01,--053/InvoiceIDType
    f.Codfiscal                AS IID02,--054/InvoiceIDVATRegistrationNumber
    f.DenFirma                 AS IID03,--055/InvoiceIDName1
    NULL                       AS IID04,--056/InvoiceIDName2
    GetAdresa(
      NULL, f.strada, f.NR1, f.NR2, NULL, NULL, NULL, NULL, NULL
    )                          AS IID05,--057/InvoiceIDStreet1
    NULL                       AS IID06,--058/InvoiceIDStreet2
    f.DenLocalit               AS IID07,--059/InvoiceIDCity
    f.denjudet                 AS IID08,--060/InvoiceIDState
    &apos;RO&apos;                       AS IID09,--061/InvoiceIDCountryCode
    f.codpostal                AS IID10 --062/InvoiceIDPostalCode
  FROM IESIRI I CROSS JOIN TMP_FIRMA_ADR F
  WHERE I.CODIES = pCodIes;

  INSERT INTO TMP_IATA_IID
  SELECT
    I.CODIES,
    2                              AS ORD1,
    &apos;BT&apos;                           AS IID01,--053/InvoiceIDType
    SFACT.Codfiscal                AS IID02,--054/InvoiceIDVATRegistrationNumber
    p.Den_Part                     AS IID03,--055/InvoiceIDName1
    NULL                           AS IID04,--056/InvoiceIDName2
    GetAdresa(
      NULL, SFACT.strada, SFACT.NR1, SFACT.NR2, NULL, NULL, NULL, NULL, NULL
    )                              AS IID05,--057/InvoiceIDStreet1
    NULL                           AS IID06,--058/InvoiceIDStreet2
    LFACT.DEN_LOCALIT              AS IID07,--059/InvoiceIDCity
    JFACT.DEN_JUDET                AS IID08,--060/InvoiceIDState
    TFACT.SIMBAUTO                 AS IID09,--061/InvoiceIDCountryCode
    SFACT.codpostal                AS IID10 --062/InvoiceIDPostalCode
  FROM IESIRI I
    INNER JOIN NPART       P ON P.CODPART = I.PARTENER
    LEFT JOIN NAGENDA  SLIVR ON SLIVR.CODAGENDA   = I.CODLOCATIE
    LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT  = SLIVR.CODLOCALIT
    LEFT JOIN NJUDET   JLIVR ON JLIVR.CODJUDET    = LLIVR.CODJUDET
    LEFT JOIN NTARI    TLIVR ON TLIVR.CODTARA     = LLIVR.CODTARA

    LEFT JOIN NAGENDA  SSOC  ON SSOC.CODPART      = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LSOC  ON LSOC.CODLOCALIT   = SSOC.CODLOCALIT
    LEFT JOIN NJUDET   JSOC  ON JSOC.CODJUDET     = LSOC.CODJUDET
    LEFT JOIN NTARI    TSOC  ON TSOC.CODTARA      = LSOC.CODTARA

    LEFT JOIN NAGENDA  SFACT ON SFACT.CODAGENDA   = CASE WHEN SLIVR.SEDIUSOCIAL = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SEDIUSOCIAL IN (3,7) THEN SLIVR.CODAGENDA ELSE SSOC.CODAGENDA END
    LEFT JOIN NLOCALIT LFACT ON LFACT.CODLOCALIT  = SFACT.CODLOCALIT
    LEFT JOIN NJUDET   JFACT ON JFACT.CODJUDET    = LFACT.CODJUDET
    LEFT JOIN NTARI    TFACT ON TFACT.CODTARA     = LFACT.CODTARA
  WHERE I.CODIES = pCodIes;

  INSERT INTO TMP_IATA_IID
  SELECT
    I.CODIES,
    3                              AS ORD1,
    &apos;ST&apos;                           AS IID01,--053/InvoiceIDType
    SLIVR.Codfiscal                AS IID02,--054/InvoiceIDVATRegistrationNumber
    SLIVR.OBS                      AS IID03,--055/InvoiceIDName1
    NULL                           AS IID04,--056/InvoiceIDName2
    GetAdresa(
      NULL, SLIVR.strada, SLIVR.NR1, SLIVR.NR2, NULL, NULL, NULL, NULL, NULL
    )                              AS IID05,--057/InvoiceIDStreet1
    NULL                           AS IID06,--058/InvoiceIDStreet2
    LLIVR.DEN_LOCALIT              AS IID07,--059/InvoiceIDCity
    JLIVR.DEN_JUDET                AS IID08,--060/InvoiceIDState
    TLIVR.SIMBAUTO                 AS IID09,--061/InvoiceIDCountryCode
    SLIVR.codpostal                AS IID10 --062/InvoiceIDPostalCode
  FROM IESIRI I
    INNER JOIN NPART       P ON P.CODPART         = I.PARTENER
    LEFT JOIN NAGENDA  SLIVR ON SLIVR.CODAGENDA   = I.CODLOCATIE
    LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT  = SLIVR.CODLOCALIT
    LEFT JOIN NJUDET   JLIVR ON JLIVR.CODJUDET    = LLIVR.CODJUDET
    LEFT JOIN NTARI    TLIVR ON TLIVR.CODTARA     = LLIVR.CODTARA
  WHERE I.CODIES = pCodIes;

  INSERT INTO TMP_IATA_SI
  SELECT
    CODIES,
    1                                            AS ORD1,
    I.SeriaDoc||To_Char(I.Nrdoc)                 AS SI01    ,--076/SubInvoiceNumber
    To_Char(I.DataDoc,&apos;YYYY-MM-DD&apos;)||&apos;T00:00:00&apos; AS SI02    ,--077/SubInvoiceIssueDate
    SubStr(M.SIMBOL,1,3)                         AS SI03    ,--078/SubInvoiceCurrencyCode
    NULL                                         AS SI04    ,--079/SubInvoiceCurrencyCodeLocal
    &apos;M&apos;                                          AS SICC01  ,--081/ConversionMechanism
    SubStr(MT.SIMBOL,1,3)                        AS SICC02  ,--082/CurrencyFrom
    &apos;1&apos;                                          AS SICC02A ,--083/FactorFrom
    SubStr(M.SIMBOL,1,3)                         AS SICC03  ,--084/CurrencyTo
    &apos;1&apos;                                          AS SICC03A ,--085/FactorTo
    TO_CHAR(
      Coalesce(NullIF(I.CURS,0), 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                            AS SICC04  ,--086/ExchangeRate
    TO_CHAR(
      CASE
        WHEN I.TIPDOC = 26 THEN Round(I.ValDoc,2)
        ELSE Round(I.ValDoc-I.TvaDoc,2)+Round(I.TvaDoc,2)
      END,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                            AS SI05    ,--087/SubInvoiceTotalAmount
    NULL                                         AS SI06     --088/SubInvoiceTotalAmountLocal
  FROM IESIRI I
    LEFT  JOIN NMONEDE        M  ON M.CODMONEDA       = Coalesce(I.MONEDA,0)
    LEFT  JOIN NMONEDE        MT ON MT.CODMONEDA      = Coalesce(I.MONEDATRANSF,0)
  WHERE I.CODIES = pCodIes;

  INSERT INTO TMP_IATA_LINE
  SELECT
    I1.CODIES,
    1 AS ORD1,
    I1.CODIES1,
    Dense_Rank() OVER (ORDER BY i1.indexlocal, i1.codies1)  AS L01 ,--114/ItemNumber
    NULL                                                    AS L02 ,--122/ItemTaxInvoiceNumber
    IH.IH09                                                 AS L03 ,--123/ItemDeliveryLocation
    NULL                                                    AS L04 ,--134/ItemDescription
    TO_CHAR(
      CASE WHEN I1.PU = 0 THEN 0 ELSE (I1.PU*I1.CANT+I1.TVA)*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU END,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                       AS L05 ,--135/ItemInvoiceAmount
    NULL                                                    AS L06  --136/ItemInvoiceAmountLocal
  FROM IESIRI1 I1
    LEFT JOIN NUM1        U1 ON U1.CODUM1 = I1.UMSEC
    LEFT JOIN TMP_IATA_IH IH ON IH.CodIes = I1.CODIES
  WHERE I1.CODIES = pCodIes;

  --TMP_IATA_LINEQ;
  INSERT INTO TMP_IATA_LINEQ
  SELECT
    I1.CODIES1,
    LVL.NR AS ORD1,
    CASE
      WHEN LVL.NR = 1 THEN &apos;DL&apos;
      ELSE &apos;IN&apos;
    END                                                     AS LQ01 ,--116/ItemQuantityType
    &apos;NT&apos;                                                    AS LQ02 ,--117/ItemQuantityFlag
    TO_CHAR(
      I1.CANT/Coalesce(U1.PARITATE, 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                                       AS LQ03 ,--118/ItemQuantityQty
    SubStr(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      ),1,3
    )                                                       AS LQ04  --119/ItemQuantityUOM
  FROM IESIRI1 I1
    LEFT JOIN NUM1    U1   ON U1.CODUM1 = I1.UMSEC
    LEFT JOIN IESIRI  I    ON I.CODIES = I1.CODIES
    LEFT JOIN NAGENDA SLIV ON SLIV.CODAGENDA = I.CODLOCATIE
    CROSS JOIN (SELECT LEVEL NR FROM DUAL CONNECT BY LEVEL &lt;= 1) LVL
  WHERE I1.CODIES = pCodIes;
  --  AND CASE WHEN TIPLINIE &lt;&gt; &apos;=&apos; AND LVL.NR = 2 THEN 0 ELSE 1 END = 1;

  SetXMLIATAData_LINEDR(pCodIes, &apos;ARN&apos;, &apos;NRAERONAVA&apos;, &apos;NRAERONAVA&apos;);
  SetXMLIATAData_LINEDR(pCodIes, &apos;FNO&apos;, &apos;NRZBOR&apos;,     &apos;NRZBOR&apos;);

  --TMP_IATA_LINET
--  INSERT INTO TMP_IATA_LINET
--  SELECT
--    I1.CODIES,
--    1 AS ORD1,
--    NULL                                                    AS LT01,--125/ItemTransportationType
--    NULL                                                    AS LT02,--126/ItemTransportationRouting
--    NULL                                                    AS LT03,--127/ItemTransportationReferenceCode
--    NULL                                                    AS LT04,--128/ItemTransportationReferenceValue
--    NULL                                                    AS LT05 --129/ItemTransportationAmount
--  FROM IESIRI1 I1
--    LEFT JOIN NUM1 U1 ON U1.CODUM1 = I1.UMSEC
--  WHERE I1.CODIES = pCodIes;

  INSERT INTO TMP_IATA_LINERLD
  SELECT
    I1.CODIES1,
    1 AS ORD1,
    To_Char(AE.DATADOC,&apos;YYYY-MM-DD&apos;)||&apos;T00:00:00&apos; AS LRLD01 ,--130/ItemReferenceLocalDate
    &apos;DTA&apos;                                         AS LRLD01A --131/ItemReferenceDateTypes
  FROM IESIRI I
    INNER JOIN IESIRI1 I1   ON I1.CODIES    = I.CODIES
    LEFT  JOIN IESLINK ILAE ON ILAE.CODIES1 = I1.CODIES1 AND ILAE.CODLINIEAVIZ IS NOT NULL
    LEFT  JOIN IESIRI1 AE1  ON AE1.CODIES1  = Coalesce(ILAE.CODLINIEAVIZ, I1.CODIES1)
    LEFT  JOIN IESIRI  AE   ON AE.CODIES    = AE1.CODIES
  WHERE I.CODIES = pCodIes;

  --TMP_IATA_LINERGD;

  INSERT INTO TMP_IATA_PROD--SubItemProduct
  SELECT
    I1.CODIES1,
    1                                               AS ORD1,
    AC.CODEXTERN                                    AS P01   ,--139/SubItemProductID
    CASE
      WHEN I1.TIPLINIE = &apos;=&apos; THEN &apos;PRDT&apos;
      WHEN I1.TIPLINIE = &apos;S&apos; THEN &apos;FEE&apos;
      ELSE &apos;OTHR&apos;
    END                                             AS P01A  ,--140/SubItemProductIDQualifier
    SubStr(O.DENUMIRE,1,80)                         AS P02   ,--141/SubItemDescription
    &apos;UR&apos;                                            AS P03   ,--142/SubItemPricingUnitRateType
    TO_CHAR(
      I1.PU*Coalesce(U1.PARITATE,1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P04   ,--143/SubItemPricingUnitRate    / NUMERIC 18,6
    Substr(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      ),1,3
    )                                               AS P05   ,--144/SubItemPricingUOM
    TO_CHAR(
      Coalesce(U1.PARITATE, 1),
      &apos;fm999999999999999990D099999&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P06   ,--145/SubItemPricingUOMFactor   / NUMERIC 18,6
    SubStr(M.SIMBOL,1,3)                            AS P07   ,--146/SubItemPricingCurrencyCode
    TO_CHAR(
      (I1.PU*I1.CANT+I1.TVA)*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P08   ,--147/SubItemPricingAmount      / NUMERIC 18,2
    &apos;M&apos;                                             AS PCC01 ,--149/ConversionMechanism
    SubStr(MT.SIMBOL,1,3)                           AS PCC02 ,--150/CurrencyFrom
    &apos;1&apos;                                             AS PCC02A,--151/FactorFrom                / NUMERIC 9
    SubStr(M.SIMBOL,1,3)                            AS PCC03 ,--152/CurrencyTo
    &apos;1&apos;                                             AS PCC03A,--153/FactorTo                  / NUMERIC 9
    TO_CHAR(
      Coalesce(NullIF(I.CURS,0), 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS PCC04 ,--154/ExchangeRate              / NUMERIC 18,6
    Substr(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      ),1,3
    )                                               AS P09   ,--155/SubItemInvoiceUOM
--    TO_CHAR(
--      I1.CANT/Coalesce(U1.PARITATE, 1),
--      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
--    )
    NULL                                             AS P10   ,--156/SubItemInvoiceUOMFactor   / NUMERIC 18,6
    TO_CHAR(
      I1.CANT/Coalesce(U1.PARITATE, 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P11   ,--158/SubItemInvoiceQuantity    / NUMERIC 18,6
    &apos;DL&apos;                                            AS P12   ,--159/SubItemQuantityType
    &apos;NT&apos;                                            AS P13   ,--160/SubItemQuantityFlag
    TO_CHAR(
      I1.PU*Coalesce(U1.PARITATE,1),
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P14   ,--161/SubItemInvoiceUnitRate    / NUMERIC 18,6
    TO_CHAR(
      (I1.PU*I1.CANT+I1.TVA)*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS P15   ,--162/SubItemInvoiceAmount      / NUMERIC 18,2
    NULL                                            AS P16    --163/SubItemInvoiceAmountLocal / NUMERIC 18,2
  FROM TMP_EDI_IES1 TI1
    LEFT JOIN IESIRI  I    ON I.CODIES       = TI1.CODIES
    LEFT JOIN IESIRI1 I1   ON I1.CODIES1     = TI1.CODIES1
    LEFT JOIN NPART   P    ON P.CODPART      = I.PARTENER
    LEFT JOIN NAGENDA SLIV ON SLIV.CODAGENDA = I.CODLOCATIE
    LEFT JOIN NUM1    U1   ON U1.CODUM1      = I1.UMSEC
    LEFT JOIN NARTCLI AC   ON AC.CODARTCLI   = TI1.CODARTCLI
    LEFT JOIN NARTOBJ O    ON O.CODOBIECT    = I1.CODOBIECT
    LEFT JOIN NMONEDE M    ON M.CODMONEDA    = Coalesce(I.MONEDA,0)
    LEFT JOIN NMONEDE MT   ON MT.CODMONEDA   = Coalesce(I.MONEDATRANSF,0)
  WHERE I1.CODIES = pCodIes;

  INSERT INTO TMP_IATA_TAX--SubItemProduct
  SELECT
    I1.CODIES1,
    1                                               AS ORDPROD,
    1                                               AS ORDTAX,
    &apos;VAT&apos;                                           AS T01,    --165/SubItemTaxType (atribut)
    NULL                                            AS T02,    --166/SubItemTaxDescription
    NULL                                            AS T03,    --167/SubItemTaxCategoryCode
    NULL                                            AS T04,    --168/SubItemTaxLocalJurisdictionTaxBasis (G/N)
    NULL                                            AS T05,    --169/SubItemTaxJurisdictionCodeQualifier
    NULL                                            AS T06,    --170/SubItemTaxJurisdictionCode
    &apos;P&apos;                                             AS T07,    --171/SubItemTaxRateType
    SubStr(M.SIMBOL,1,3)                            AS T08,    --172/SubItemTaxPricingCurrencyCode
    &apos;M&apos;                                             AS T09,    --174/ConversionMechanism (M/D)
    SubStr(MT.SIMBOL,1,3)                           AS T10,    --175/CurrencyFrom
    &apos;1&apos;                                             AS T10A,   --176/FactorFrom (atribut)
    SubStr(M.SIMBOL,1,3)                            AS T11,    --177/CurrencyTo
    &apos;1&apos;                                             AS T11A,   --178/FactorTo (atribut)
    TO_CHAR(
      Coalesce(NullIF(I.CURS,0), 1),
      &apos;fm999999999999999990D000099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS T12,    --179/ExchangeRate
    NULL                                            AS T13,    --180/SubItemTaxPricingUOM
    NULL                                            AS T14,    --181/SubItemTaxPricingUOMFactor
    NULL                                            AS T15,    --182/SubItemTaxPricingRate
    TO_CHAR(
      I1.TVA*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS T16,    --183/SubItemTaxPricingAmount
    Substr(
      Coalesce(
        CASE
          WHEN sliv.edi_denum = 1 THEN U1.DEN_EANCOM
          WHEN sliv.edi_denum = 2 THEN U1.DEN_UM1
          WHEN sliv.edi_denum = 3 THEN U1.CODEXTERN
        END,U1.DEN_EANCOM,U1.Den_UM1
      ),1,3
    )                                               AS T17,    --184/SubItemTaxInvoiceUOM
    NULL                                            AS T18,    --185/SubItemTaxInvoiceUOMFactor
    NULL                                            AS T19,    --186/SubItemTaxInvoiceUnitRate
    NULL                                            AS TQ_A1,  --188/SubItemTaxInvoiceQuantity
    NULL                                            AS TQ_A2,  --189/SubItemTaxQuantityType (DL/IN)
    NULL                                            AS TQ_B1,  --188/SubItemTaxInvoiceQuantity
    NULL                                            AS TQ_B2,  --189/SubItemTaxQuantityType (DL/IN)
    TO_CHAR(
      I1.TVA*I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)/I1.PU,
      &apos;fm999999999999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;
    )                                               AS T20,    --190/SubItemTaxInvoiceAmount
    NULL                                            AS T21,    --191/SubItemTaxInvoiceAmountLocal
    NULL                                            AS T22,    --192/SubItemTaxIndicator (O/I)
    NULL                                            AS ST01,   --194/SubTaxType (atribut)
    NULL                                            AS ST02,   --195/SubTaxDescription
    NULL                                            AS ST03,   --196/SubTaxCategoryCode
    NULL                                            AS ST04,   --197/SubTaxLocalJurisdictionTaxBasis
    NULL                                            AS ST05,   --198/SubTaxJurisdictionCodeQualifier
    NULL                                            AS ST06,   --199/SubTaxJurisdictionCode
    NULL                                            AS ST07,   --200/SubTaxRateType
    NULL                                            AS ST08,   --201/SubTaxPricingCurrencyCode
    NULL                                            AS ST09,   --203/ConversionMechanism
    NULL                                            AS ST10,   --204/CurrencyFrom
    NULL                                            AS ST10A,  --205/FactorFrom
    NULL                                            AS ST11,   --206/CurrencyTo
    NULL                                            AS ST11A,  --207/FactorTo
    NULL                                            AS ST12,   --208/ExchangeRate
    NULL                                            AS ST13,   --209/SubTaxPricingUOM
    NULL                                            AS ST14,   --210/SubTaxPricingUOMFactor
    NULL                                            AS ST15,   --211/SubTaxPricingRate
    NULL                                            AS ST16,   --212/SubTaxPricingAmount
    NULL                                            AS ST17,   --213/SubTaxInvoiceUOM
    NULL                                            AS ST18,   --214/SubTaxInvoiceUOMFactor
    NULL                                            AS ST19,   --215/SubTaxInvoiceUnitRate
    NULL                                            AS STQ_A1, --217/SubTaxInvoiceQuantity 1
    NULL                                            AS STQ_A2, --218/SubTaxQuantityType 1
    NULL                                            AS STQ_B1, --217/SubTaxInvoiceQuantity 2
    NULL                                            AS STQ_B2, --218/SubTaxQuantityType 2
    NULL                                            AS ST20,   --219/SubTaxInvoiceAmount
    NULL                                            AS ST21    --220/SubTaxInvoiceAmountLocal
  FROM TMP_EDI_IES1 TI1
    LEFT JOIN IESIRI  I    ON I.CODIES       = TI1.CODIES
    LEFT JOIN IESIRI1 I1   ON I1.CODIES1     = TI1.CODIES1
    LEFT JOIN NPART   P    ON P.CODPART      = I.PARTENER
    LEFT JOIN NAGENDA SLIV ON SLIV.CODAGENDA = I.CODLOCATIE
    LEFT JOIN NUM1    U1   ON U1.CODUM1      = I1.UMSEC
    LEFT JOIN NARTCLI AC   ON AC.CODARTCLI   = TI1.CODARTCLI
    LEFT JOIN NARTOBJ O    ON O.CODOBIECT    = I1.CODOBIECT
    LEFT JOIN NMONEDE M    ON M.CODMONEDA    = Coalesce(I.MONEDA,0)
    LEFT JOIN NMONEDE MT   ON MT.CODMONEDA   = Coalesce(I.MONEDATRANSF,0)
  WHERE I1.CODIES = pCodIes
    AND I1.TVA &lt;&gt; 0;

  UPDATE TMP_IATA_IH IH SET IS01 = (SELECT Count(1) FROM TMP_IATA_LINE L  WHERE L.CODIES = IH.CODIES);
  COMMIT;
END;

END pkg_exportedi;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_EXP_HENKEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A02A5B9B07A68458129CF4F79333A19A6548F929</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_EXP_HENKEL IS

  vDataIni DATE;
  vDataFin DATE;
  cDataFin DATE;

PROCEDURE UMPLE_TMP(
  sDataIni IN VARCHAR2,
  sDataFin IN VARCHAR2)
IS
  pExpHenkelCodifIes NUMBER;
BEGIN
  vDataIni := To_Date(sDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin := To_Date(sDataFin,&apos;dd.mm.yyyy&apos;);

  pExpHenkelCodifIes := pkg_categconst.GetValConstanta(&apos;ExpHenkelCodifIes&apos;,pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU);
  pExpHenkelCodifIes := Coalesce(pExpHenkelCodifIes, 1) ;

  DELETE TMP_EXPH_PURCHASE;
  DELETE TMP_EXPH_SALES;
  DELETE TMP_EXPH_STOCK;
  DELETE TMP_EXPH_PAYMENTS;
  DELETE TMP_EXPH_COMPOSEDPRODUCTS;

  INSERT INTO TMP_EXPH_PURCHASE(
    startdate, enddate,
    internalhid, datadoc, nrdoc, serialno,
    locationcode,
    amounth, vath, amountwithvath,
    invoiceduedate,
    internaldetid, internalitemcode, itemcode, itemname,
    qtty,
    amountdet,
    vatdet,
    amountwithvatdet )
  SELECT
    To_Char(vDataIni, &apos;yyyymmdd&apos;) startdate, To_Char(vDataFin,&apos;yyyymmdd&apos;) enddate,
    i.codintr internalhid, To_Char(i.DataDoc, &apos;yyyymmdd&apos;) datadoc, i.nrdoc, i.seriadoc serialno,
    --scf.codfiscal locationcode,
    s.den_subunit locationcode,
    --g.simbol locationcode,
    i.valdoc - i.tvadoc amounth, i.tvadoc vath, i.valdoc amountwithvath,
    (SELECT Max(TO_CHAR(O.TERMEN,&apos;yyyymmdd&apos;)) FROM GENERAL G INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL WHERE G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODINTR) invoiceduedate,
    i1.codintr1 internaldetid, i1.codobiect internalitemcode, o.codextern itemcode, o.denumire itemname,
    ns.cantnir,
    Coalesce( (i1.pu-CASE WHEN i.tipdoc = 3 THEN i1.tva/i1.cant ELSE 0 END)*ns.cantnir, 0) amountdet,
    Coalesce( i1.tva*ns.cantnir/i1.cant, 0) vatdet,
    Coalesce( (i1.pu+CASE WHEN i.tipdoc = 3 THEN 0 ELSE i1.tva/i1.cant END)*ns.cantnir, 0) amountwithvatdet
  FROM intrari i
    INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    INNER JOIN nartobj o ON o.codobiect = i1.codobiect
    INNER JOIN nart a ON a.codarticol = o.codarticol
    INNER JOIN nclaseas cs ON cs.codclaseas = a.clasastatist
    INNER JOIN npart p ON p.codpart = i.partener
    INNER JOIN nirstoc ns ON ns.codintr1 = i1.codintr1
    INNER JOIN nir n ON n.codnir = ns.codnir AND n.codintr = i.codintr AND n.tipnir = i.tipdoc
    --LEFT  JOIN ngest g ON g.codgest = n.gest
    LEFT  JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT  JOIN nsubunit s ON s.codsubunit = i.subunitatea
    LEFT  JOIN nagenda sl ON sl.codsubunit = i.subunitatea
    LEFT  JOIN npartcodfisc scf ON scf.cod_codfiscal = sl.cod_codfiscal
    LEFT  JOIN npers ag ON ag.codpers = i.agent
    LEFT  JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
    --LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial between 4 and 7 AND NVL(ssoc.inactiv, 0) = 0
    --LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
    --LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
    LEFT  JOIN nagenda slivr ON slivr.codagenda = i.codlocatie
    LEFT  JOIN nlocalit llivr ON llivr.codlocalit = slivr.codlocalit
    LEFT  JOIN njudet jlivr ON jlivr.codjudet = Coalesce(llivr.codjudet, 0)
    LEFT  JOIN npartcodfisc cflivr ON cflivr.cod_codfiscal = slivr.cod_codfiscal
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,2,5)
    AND i.datadoc BETWEEN vDataIni AND vDataFin
    AND Upper(p.den_part) LIKE &apos;%HENKEL%&apos;
    AND i1.cant &lt;&gt; 0;

  INSERT INTO TMP_EXPH_SALES(
    startdate, enddate,
    internalhid, datadoc, nrdoc, serialno,
    locationcode,
    amounth, vath, amountwithvath,
    invoiceduedate,
    agentname, agentpin,
    clientcode, clientname, clientfiscalregistration, clientlocationinternalid,
    clientlocationname, clientlocationcode,
    clientlocationaddress,
    clientlocationcity, clientlocationcounty, clientcategory,
    internaldetid,
    internalitemcode, itemcode, itemname,
    qtty,
    amountdet,
    vatdet,
    amountwithvatdet )
  SELECT
    To_Char(vDataIni, &apos;yyyymmdd&apos;) startdate, To_Char(vDataFin,&apos;yyyymmdd&apos;) enddate,
    i.codies internalhid, To_Char(i.DataDoc, &apos;yyyymmdd&apos;) datadoc, i.nrdoc, i.seriadoc serialno,
    --scf.codfiscal locationcode,
    s.den_subunit locationcode,
    --g.simbol locationcode,
    i.valdoc - i.tvadoc amounth, i.tvadoc vath, i.valdoc amountwithvath,
    (SELECT Max(TO_CHAR(O.TERMEN,&apos;yyyymmdd&apos;)) FROM GENERAL G INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL WHERE G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODIES) invoiceduedate,
    NumePrenume(AG.NUME,AG.PRENUME) agentname, AG.CNP agentpin,
    p.codpart clientcode, CASE WHEN p.codpart = 0 THEN &apos;fara client&apos; ELSE p.den_part END clientname, cfi.codfiscal clientfiscalregistration, Coalesce(i.CodLocatie, 0) clientlocationinternalid,
    slivr.obs clientlocationname, cflivr.codfiscal clientlocationcode,
    GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) clientlocationaddress,
    llivr.den_localit clientlocationcity, CASE WHEN Coalesce(slivr.sector, 0) = 0 THEN jlivr.den_judet ELSE To_Char(slivr.sector) END clientlocationcounty, cp.den_clasep clientcategory,
    CASE
      WHEN pExpHenkelCodifIes = 3 THEN To_Char(i1.codies1)||LPad(To_Char(l1.codlivr1), 20, &apos;0&apos;)
      WHEN pExpHenkelCodifIes = 2 THEN To_Char(l1.codlivr1)
      ELSE                             To_Char(i1.codies1)
    END internaldetid,
    i1.codobiect internalitemcode, o.codextern itemcode, o.denumire itemname,
    l1.cant,
    Coalesce( CASE WHEN i1.pu = 0 THEN 0 ELSE (i1.pu-CASE WHEN i.tipdoc IN (16,21) THEN i1.tva/i1.cant ELSE 0 END)*l1.cant*i1.coefdiscmaj*i1.pretorig/i1.pu END, 0) amountdet,
    Coalesce( i1.tva*l1.cant/i1.cant, 0) vatdet,
    Coalesce( CASE WHEN i1.pu = 0 THEN 0 ELSE (i1.pu+CASE WHEN i.tipdoc IN (16,21) THEN 0 ELSE i1.tva/i1.cant END)*l1.cant*i1.coefdiscmaj*i1.pretorig/i1.pu END, 0) amountwithvatdet
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN nartobj o ON o.codobiect = i1.codobiect
    INNER JOIN nart a ON a.codarticol = o.codarticol
    INNER JOIN nclaseas cs ON cs.codclaseas = a.clasastatist
    INNER JOIN npart p ON p.codpart = Coalesce(i.partener, 0)
    INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codies1 = i1.codies1 AND l1.codlivr = l.codlivr
    --LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
    --LEFT  JOIN nir n ON n.codnir = ns.codnir
    --LEFT  JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
    --LEFT  JOIN ngest g ON g.codgest = Coalesce(n.gest, lv.gest)
    LEFT  JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT  JOIN nsubunit s ON s.codsubunit = i.subunitatea
    --LEFT  JOIN nagenda sl ON sl.codsubunit = i.subunitatea
    --LEFT  JOIN npartcodfisc scf ON scf.cod_codfiscal = sl.cod_codfiscal
    LEFT  JOIN npers ag ON ag.codpers = i.agent
    LEFT  JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
    --LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial between 4 and 7 AND NVL(ssoc.inactiv, 0) = 0
    --LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
    --LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
    LEFT  JOIN nagenda slivr ON slivr.codagenda = i.codlocatie
    LEFT  JOIN nlocalit llivr ON llivr.codlocalit = slivr.codlocalit
    LEFT  JOIN njudet jlivr ON jlivr.codjudet = Coalesce(llivr.codjudet, 0)
    LEFT  JOIN npartcodfisc cflivr ON cflivr.cod_codfiscal = slivr.cod_codfiscal
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (16,19,20,21,22)
    AND i.datadoc BETWEEN vDataIni AND vDataFin
    AND Upper(cs.den_claseas) LIKE &apos;%HENKEL%&apos;
    AND i1.cant &lt;&gt; 0;

  INSERT INTO TMP_EXPH_STOCK(
    startdate, enddate,
    internalitemcode, itemcode, itemname,
    qtty, stockdate,
    locationcode,
    stockvalue )
  SELECT
    To_Char(vDataIni, &apos;yyyymmdd&apos;) startdate, To_Char(vDataFin,&apos;yyyymmdd&apos;) enddate,
    o.CodObiect internalitemcode,  o.codextern itemcode, o.denumire itemname,
    Sum(ns.rest) qtty, To_Char(Sysdate, &apos;yyyymmdd&apos;) stockdate,
    --scf.codfiscal locationcode,
    s.den_subunit locationcode,
    --g.simbol locationcode,
    Sum(ns.pret*ns.rest) stockvalue
  FROM nirstoc ns
    INNER JOIN nartobj o ON o.codobiect = ns.codobiect
    INNER JOIN nart a ON a.codarticol = o.codarticol
    INNER JOIN nclaseas cs ON cs.codclaseas = a.clasastatist
    LEFT  JOIN nir n ON n.codnir = ns.codnir
    LEFT  JOIN ngest g ON g.codgest = n.gest
    LEFT  JOIN nsubunit s ON s.codsubunit = g.codsubunit
    LEFT  JOIN nagenda sl ON sl.codsubunit = s.codsubunit
    LEFT  JOIN npartcodfisc scf ON scf.cod_codfiscal = sl.cod_codfiscal
  WHERE ns.rest &lt;&gt; 0
    AND Upper(cs.den_claseas) LIKE &apos;%HENKEL%&apos;
  GROUP BY o.CodObiect, o.codextern, o.denumire, s.den_subunit;

  INSERT INTO TMP_EXPH_PAYMENTS(
    startdate, enddate,
    paymentnumber, paymentinternalid, salesinvoiceinternalhid,
    paymentvalue, paymentdate )
  SELECT
    To_Char(vDataIni, &apos;yyyymmdd&apos;) startdate, To_Char(vDataFin,&apos;yyyymmdd&apos;) enddate,
    nrdoc paymentnumber, codtrezor1 paymentinternalid, codies salesinvoiceinternalhid,
    valstins*valhenkel/valdestins paymentvalue, To_Char(datadoc, &apos;yyyymmdd&apos;) paymentdate
  FROM (
    SELECT
      t1.nrdoc, t1.datadoc, t1.codtrezor1, i.codies,
      s.valoare valstins,
      os.valoare valdestins,
      i.valdoc,
      ( SELECT Coalesce(Sum(CASE WHEN i1.pu = 0 THEN 0 ELSE (i1.pu*i1.cant+CASE WHEN i.tipdoc IN (16,21) THEN 0 ELSE i1.tva END)*i1.coefdiscmaj*i1.pretorig/i1.pu END ),0)
        FROM iesiri1 i1
          INNER JOIN nartobj o ON o.codobiect = i1.codobiect
          INNER JOIN nart a ON a.codarticol = o.codarticol
          INNER JOIN nclaseas cs ON cs.codclaseas = a.clasastatist
        WHERE i1.codies = i.codies
          AND Upper(cs.den_claseas) LIKE &apos;%HENKEL%&apos;
      ) valhenkel
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1 AND g.semnificatie IN (400,420,750,751)
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
      INNER JOIN general gs ON gs.codgeneral = os.codgeneral
      INNER JOIN iesiri i ON i.codies = gs.coddoc AND i.tipdoc = gs.tipdoc
    WHERE T.TIPDOC IN (29,30,31)
      AND t1.datadoc BETWEEN vDataIni AND vDataFin
      AND os.valoare&lt;&gt;0
  )
  WHERE valhenkel &lt;&gt; 0;

  INSERT INTO TMP_EXPH_COMPOSEDPRODUCTS(
    COMPOSEDINTERNALITEMCODE, COMPOSEDITEMCODE,
    INTERNALITEMCODE, COMPONENTCODE,
    QTTY, PERCENT
  )
  SELECT
    P.CODOBIECT COMPOSEDINTERNALITEMCODE, OP.CODEXTERN COMPOSEDITEMCODE,
    M.CODOBIECT INTERNALITEMCODE, OM.CODEXTERN COMPONENTCODE,
    M.CANT, Round(M.CANT*100/Sum(M.CANT) OVER (PARTITION BY P.CODPRODCOMP),2) PERCENT
  FROM PRODCOMP P
    INNER JOIN PRODMAT M ON M.CODPRODCOMP = P.CODPRODCOMP
    INNER JOIN NARTOBJ OP ON OP.CODOBIECT = P.CODOBIECT
    INNER JOIN NARTOBJ OM ON OM.CODOBIECT = M.CODOBIECT
    INNER JOIN NART AP ON AP.CODARTICOL = OP.CODARTICOL
    INNER JOIN NCLASEAS CLSS ON CLSS.CODCLASEAS = AP.CLASASTATIST
  WHERE COALESCE(M.CANT,0) &gt; 0 AND Upper(CLSS.den_claseas) LIKE &apos;%HENKEL%&apos;;

  COMMIT;

END;

PROCEDURE AUX_TMP(
  sTMP      IN  VARCHAR2,
  sHeader   OUT VARCHAR2,
  sFooter   OUT VARCHAR2,
  sFileName OUT VARCHAR2
) IS
  vTMP     VARCHAR2(100) := Upper(sTMP);
  vCount   INTEGER;
BEGIN
  sFileName := vTMP||&apos;.csv&apos;;
  sFooter   := &apos;&apos;;
  IF Upper(vTMP) = &apos;PURCHASE&apos; THEN
    sHeader :=
      &apos;&quot;StartDate&quot;;&quot;EndDate&quot;;&quot;InternalHid&quot;;&quot;Date&quot;;&quot;Number&quot;;&quot;SerialNo&quot;;&quot;LocationCode&quot;;&quot;AmountH&quot;;&quot;VATH&quot;;&quot;AmountWithVATH&quot;;&quot;InvoiceDueDate&quot;;&quot;InternalDetId&quot;;&apos;||
      &apos;&quot;InternalItemcode&quot;;&quot;ItemCode&quot;;&quot;ItemName&quot;;&quot;Qtty&quot;;&quot;AmountDet&quot;;&quot;VATDet&quot;;&quot;AmountWithVATDet&quot;&apos;;
  ELSIF Upper(vTMP) = &apos;SALES&apos; THEN
    sHeader :=
      &apos;&quot;StartDate&quot;;&quot;EndDate&quot;;&quot;InternalHid&quot;;&quot;Date&quot;;&quot;Number&quot;;&quot;SerialNo&quot;;&quot;LocationCode&quot;;&quot;AmountH&quot;;&quot;VATH&quot;;&quot;AmountWithVATH&quot;;&quot;InvoiceDueDate&quot;;&quot;AgentName&quot;;&quot;AgentPIN&quot;;&apos;||
      &apos;&quot;ClientCode&quot;;&quot;ClientName&quot;;&quot;ClientFiscalRegistration&quot;;&quot;ClientLocationInternalId&quot;;&quot;ClientLocationName&quot;;&quot;ClientLocationCode&quot;;&quot;ClientLocationAddress&quot;;&apos;||
      &apos;&quot;ClientLocationCity&quot;;&quot;ClientLocationCounty&quot;;&quot;ClientCategory&quot;;&quot;InternalDetId&quot;;&quot;InternalItemCode&quot;;&quot;ItemCode&quot;;&quot;ItemName&quot;;&quot;Qtty&quot;;&quot;AmountDet&quot;;&quot;VATDet&quot;;&quot;AmountWithVATDet&quot;&apos;;
  ELSIF Upper(vTMP) = &apos;STOCK&apos; THEN
    sHeader :=
      &apos;&quot;StartDate&quot;;&quot;EndDate&quot;;&quot;InternalItemCode&quot;;&quot;ItemCode&quot;;&quot;ItemName&quot;;&quot;Qtty&quot;;&quot;StockDate&quot;;&quot;LocationCode&quot;;&quot;StockValue&quot;&apos;;
  ELSIF Upper(vTMP) = &apos;PAYMENTS&apos; THEN
    sHeader :=
      &apos;&quot;StartDate&quot;;&quot;EndDate&quot;;&quot;PaymentNumber&quot;;&quot;PaymentInternalId&quot;;&quot;SalesInvoiceInternalHId&quot;;&quot;PaymentValue&quot;;&quot;PaymentDate&quot;&apos;;
  ELSIF Upper(vTMP) = &apos;COMPOSEDPRODUCTS&apos; THEN
    sHeader :=
      &apos;&quot;ComposedInternalItemCode&quot;;&quot;ComposedItemCode&quot;;&quot;InternalItemCode&quot;;&quot;ComponentCode&quot;;&quot;Qtty&quot;;&quot;Percent&quot;&apos;;
  END If;
END;

FUNCTION getCursorTmp(pTMP IN  VARCHAR2) RETURN SYS_REFCURSOR IS
  cResult SYS_REFCURSOR;
BEGIN
  IF Upper(pTMP) = &apos;PURCHASE&apos; THEN
    OPEN cResult FOR
      SELECT
        &apos;&quot;&apos;||startdate||&apos;&quot;;&quot;&apos;||enddate||&apos;&quot;;&quot;&apos;||internalhid||&apos;&quot;;&quot;&apos;||datadoc||&apos;&quot;;&quot;&apos;||nrdoc||&apos;&quot;;&quot;&apos;||serialno||&apos;&quot;;&quot;&apos;||locationcode||&apos;&quot;;&apos;||
        TO_CHAR(amounth         ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(vath            ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountwithvath  ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&quot;&apos;||
        invoiceduedate||&apos;&quot;;&quot;&apos;||internaldetid||&apos;&quot;;&quot;&apos;||internalitemcode||&apos;&quot;;&quot;&apos;||itemcode||&apos;&quot;;&quot;&apos;||itemname||&apos;&quot;;&apos;||
        TO_CHAR(qtty            ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountdet       ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(vatdet          ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountwithvatdet,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) linie
      FROM TMP_EXPH_PURCHASE;
  ELSIF Upper(pTMP) = &apos;SALES&apos; THEN
    OPEN cResult FOR
      SELECT
        &apos;&quot;&apos;||startdate||&apos;&quot;;&quot;&apos;||enddate||&apos;&quot;;&quot;&apos;||internalhid||&apos;&quot;;&quot;&apos;||datadoc||&apos;&quot;;&quot;&apos;||nrdoc||&apos;&quot;;&quot;&apos;||serialno||&apos;&quot;;&quot;&apos;||locationcode||&apos;&quot;;&apos;||
        TO_CHAR(amounth         ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(vath            ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountwithvath  ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&quot;&apos;||
        invoiceduedate||&apos;&quot;;&quot;&apos;||agentname||&apos;&quot;;&quot;&apos;||agentpin||&apos;&quot;;&quot;&apos;||clientcode||&apos;&quot;;&quot;&apos;||clientname||&apos;&quot;;&quot;&apos;||clientfiscalregistration||&apos;&quot;;&quot;&apos;||clientlocationinternalid||&apos;&quot;;&quot;&apos;||
        clientlocationname||&apos;&quot;;&quot;&apos;||clientlocationcode||&apos;&quot;;&quot;&apos;||clientlocationaddress||&apos;&quot;;&quot;&apos;||clientlocationcity||&apos;&quot;;&quot;&apos;||clientlocationcounty||&apos;&quot;;&quot;&apos;||clientcategory||&apos;&quot;;&quot;&apos;||
        internaldetid||&apos;&quot;;&quot;&apos;||internalitemcode||&apos;&quot;;&quot;&apos;||itemcode||&apos;&quot;;&quot;&apos;||itemname||&apos;&quot;;&apos;||
        TO_CHAR(qtty            ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountdet       ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(vatdet          ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(amountwithvatdet,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) linie
      FROM TMP_EXPH_SALES;
  ELSIF Upper(pTMP) = &apos;STOCK&apos; THEN
    OPEN cResult FOR
      SELECT
        &apos;&quot;&apos;||startdate||&apos;&quot;;&quot;&apos;||enddate||&apos;&quot;;&quot;&apos;||internalitemcode||&apos;&quot;;&quot;&apos;||itemcode||&apos;&quot;;&quot;&apos;||itemname||&apos;&quot;;&apos;||
        TO_CHAR(qtty            ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&quot;&apos;||
        stockdate||&apos;&quot;;&quot;&apos;||locationcode||&apos;&quot;;&apos;||
        TO_CHAR(stockvalue,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) linie
      FROM TMP_EXPH_STOCK;
  ELSIF Upper(pTMP) = &apos;PAYMENTS&apos; THEN
    OPEN cResult FOR
      SELECT
        &apos;&quot;&apos;||startdate||&apos;&quot;;&quot;&apos;||enddate||&apos;&quot;;&quot;&apos;||paymentnumber||&apos;&quot;;&quot;&apos;||paymentinternalid||&apos;&quot;;&quot;&apos;||salesinvoiceinternalhid||&apos;&quot;;&apos;||
        TO_CHAR(paymentvalue,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&quot;&apos;||paymentdate||&apos;&quot;&apos; linie
    FROM TMP_EXPH_PAYMENTS;
  ELSIF Upper(pTMP) = &apos;COMPOSEDPRODUCTS&apos; THEN
    OPEN cResult FOR
      SELECT
        &apos;&quot;&apos;||composedinternalitemcode||&apos;&quot;;&quot;&apos;||composeditemcode||&apos;&quot;;&quot;&apos;||internalitemcode||&apos;&quot;;&quot;&apos;||componentcode||&apos;&quot;;&apos;||
        TO_CHAR(qtty   ,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)||&apos;;&apos;||
        TO_CHAR(percent,&apos;fm9999999990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;) linie
      FROM TMP_EXPH_COMPOSEDPRODUCTS;
  END If;

  RETURN cResult;
END;

PROCEDURE expCursor(pTMP IN VARCHAR2) IS
  sHeader   VARCHAR2(1000);
  sFooter   VARCHAR2(1000);
  sFileName VARCHAR2(1000);
  vCusor    SYS_REFCURSOR;
  vLinie    VARCHAR2 (32767);
  L_HANDLER UTL_FILE.FILE_TYPE;
BEGIN
  AUX_TMP(pTmp, sHeader, sFooter, sFileName);
  L_HANDLER := UTL_FILE.FOPEN(&apos;EXP_HENKEL&apos;, sFileName, &apos;W&apos;);
  UTL_FILE.PUTF(L_HANDLER, sHeader);
  vCusor := getCursorTmp(pTMP);
  LOOP
    FETCH vCusor INTO vLinie;
    EXIT WHEN vCusor%NOTFOUND;
    UTL_FILE.NEW_LINE(L_HANDLER, 1);
    UTL_FILE.PUTF(L_HANDLER, vLinie);
  END LOOP;
  CLOSE vCusor;
  UTL_FILE.FCLOSE(L_HANDLER);
END;

PROCEDURE EXPORT IS
  sHeader   VARCHAR2(1000);
  sFileName VARCHAR2(1000);
  vFirstCol INTEGER;
  sTmp      VARCHAR2(100);
BEGIN
--CREATE DIRECTORY EXP_HENKEL AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_HENKEL TO **USER**;
  expCursor(&apos;Purchase&apos;);
  expCursor(&apos;Sales&apos;);
  expCursor(&apos;Stock&apos;);
  expCursor(&apos;Payments&apos;);
  expCursor(&apos;ComposedProducts&apos;);
END;

PROCEDURE EXPORT_ZILNIC IS
  vData     DATE      := Trunc(SYSDATE);
  vAn       NUMBER(4) := EXTRACT(YEAR  FROM vDATA);
  vLuna     NUMBER(2) := EXTRACT(MONTH FROM vDATA);
BEGIN
  PKG_GLOBALS.SetLunaLucru(vAn, vLuna);
  UMPLE_TMP(To_Char(vData,&apos;dd.mm.yyyy&apos;), To_Char(vData,&apos;dd.mm.yyyy&apos;));
  EXPORT;
END;

PROCEDURE EXPORT_LUNAR IS
  vDataIni  DATE      := Trunc(Add_Months(SYSDATE,-1),&apos;MM&apos;);
  vDataFin  DATE      := Last_Day(vDataIni);
  vAn       NUMBER(4) := EXTRACT(YEAR  FROM vDataIni);
  vLuna     NUMBER(2) := EXTRACT(MONTH FROM vDataIni);
BEGIN
  PKG_GLOBALS.SetLunaLucru(vAn, vLuna);
  UMPLE_TMP(To_Char(vDataIni,&apos;dd.mm.yyyy&apos;), To_Char(vDataFin,&apos;dd.mm.yyyy&apos;));
  EXPORT;
END;

PROCEDURE EXPORT_15ZILE IS
  vDataIni  DATE      := Trunc(SYSDATE)-15;
  vDataFin  DATE      := Trunc(SYSDATE);
  vAn       NUMBER(4) := EXTRACT(YEAR  FROM vDataIni);
  vLuna     NUMBER(2) := EXTRACT(MONTH FROM vDataIni);
BEGIN
  PKG_GLOBALS.SetLunaLucru(vAn, vLuna);
  UMPLE_TMP(To_Char(vDataIni,&apos;dd.mm.yyyy&apos;), To_Char(vDataFin,&apos;dd.mm.yyyy&apos;));
  EXPORT;
END;

END pkg_exp_henkel;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C1ED299EEAB55DA1DFC653CACE4DAFBA7772A30</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FAZ IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_9999&apos;;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodFAZ INTO Tmp FROM FAZ WHERE CodFAZ = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCodSubunit   NUMBER(20);
aDataDoc      DATE;
aDoc          VARCHAR2(200);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodAuto NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 89);
  SELECT
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    CARNETDOC,
    NRDOC,
    CODAUTO
  INTO
    aCodSubunit,
    aDATADOC,
    ADOC,
    ACARNETDOC,
    ANRDOC,
    ACODAUTO
  FROM FAZ WHERE CODFAZ = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;FAZ&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM FAZINTR WHERE CodFAZ = RecId;
  DELETE FROM FAZ3 WHERE CodFAZ = RecId;
  DELETE FROM FAZ2 WHERE CodFAZ = RecId;
  DELETE FROM FAZ1 WHERE CodFAZ = RecId;
  DELETE FROM FAZ0 WHERE CodFAZ = RecId;
  DELETE FROM FAZ WHERE CodFAZ = RecId;
  
  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;
  
  -- actualizez automat citirea pe masina
  DELETE NPARC0 WHERE CODNPARCAUT = ACODAUTO AND TRUNC(DATABORD) = TRUNC(ADATADOC);
  
  NotifyModif(2, RecId, &apos;FAZ&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_FAZ FIELDS(CodFAZ) VALUES (0);
  PKG_CFGTABLES.EXT_INSERTRECORD(89);  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
sSQL varchar2(5000);
sComb varchar2(1000);
BEGIN
  INSERT INTO TMP_FAZ (
    CODFAZ, CARNETDOC, SERIADOC, PREFIXDOC, NRDOC, DATADOC, OPERAT, BLOCAT, ANULAT, USERID, DATACREARE,
    SUBUNITATEA, CODAUTO, CODPERS, DIAGRAMA, ALIMPOMPA, ALIMBCF, ALIMAVANS, KMPLECARE, KMSOSIRE, KMN,
    CSARCINA, CSARCINAR, CSTART, CIMOTOR, CCURSE, CRAER, CIARNA, OREREGIE, OREACORD, OREN, TONES, ORES,
    TSTART, TIMOTOR, TCURSE, RAER, PARCURSN, REZERVORPLECARE, CODFAZS, AN,
    LUNA, CONSUM, REZERVORCALC, REZERVOR, OBS, TIPPARCURS, CODAUTO1, CODAUTO2, PARCURSR1,
    PARCURSR2, PARCURS1, PARCURS2, T1, T2, ECHIV1, ECHIV2, CODGRAUTO, PARCURSB, PARCURSM, PARCURSO, B, M, O,
    ECHIVB, ECHIVM, ECHIVO, TIPAERODIN, NRREM, PARCURSAERO, AEROSR, ECHIVAERO, ECHIVINST,
    Denumire, NrInreg, Marca, Alimtotal, KmParcurs, AUTO_TIP, AUTO_MASAU, AUTO_TIPINCARC, CMM, DIFREZERVOR,
    CODINTR, INTRARE, CODIES, CODTREZOR, BC, DECONT,PUTERE, R1_TIPINCARC,R2_TIPINCARC,CONSSTAT,CONSSTATH, TECHIVGRUPA, TPARCURS, CONSUMMEDIU)
  SELECT FAZ.CODFAZ, FAZ.CARNETDOC, FAZ.SERIADOC, FAZ.PREFIXDOC, FAZ.NRDOC, FAZ.DATADOC, FAZ.OPERAT, FAZ.BLOCAT, FAZ.ANULAT, FAZ.USERID, FAZ.DATACREARE,
    FAZ.SUBUNITATEA, FAZ.CODAUTO, FAZ.CODPERS, FAZ.DIAGRAMA, FAZ.ALIMPOMPA, FAZ.ALIMBCF, FAZ.ALIMAVANS, FAZ.KMPLECARE, FAZ.KMSOSIRE, FAZ.KMN,
    FAZ.CSARCINA, FAZ.CSARCINAR, FAZ.CSTART, FAZ.CIMOTOR, FAZ.CCURSE, FAZ.CRAER, FAZ.CIARNA, FAZ.OREREGIE, FAZ.OREACORD, FAZ.OREN, FAZ.TONES, FAZ.ORES,
    FAZ.TSTART, FAZ.TIMOTOR, FAZ.TCURSE, FAZ.RAER, FAZ.PARCURSN, FAZ.REZERVORPLECARE, FAZ.CODFAZS, FAZ.AN,
    FAZ.LUNA, FAZ.CONSUM, FAZ.REZERVORCALC, FAZ.REZERVOR, FAZ.OBS, FAZ.TIPPARCURS, FAZ.CODAUTO1, FAZ.CODAUTO2, FAZ.PARCURSR1,
    FAZ.PARCURSR2, FAZ.PARCURS1, FAZ.PARCURS2, FAZ.T1, FAZ.T2, FAZ.ECHIV1, FAZ.ECHIV2, FAZ.CODGRAUTO, FAZ.PARCURSB, FAZ.PARCURSM, FAZ.PARCURSO, FAZ.B, FAZ.M, FAZ.O,
    FAZ.ECHIVB, FAZ.ECHIVM, FAZ.ECHIVO, FAZ.TIPAERODIN, FAZ.NRREM, FAZ.PARCURSAERO, FAZ.AEROSR, FAZ.ECHIVAERO, FAZ.ECHIVINST,
    OBJ.DENUMIRE, AUTO.NRINREG, P.MARCA, nvl(FAZ.Alimpompa,0) + nvl(FAZ.ALIMBCF,0) + nvl(FAZ.ALIMAVANS,0), 
    case 
      when nvl(KmSosire,0) - nvl(KmPlecare,0) &lt; 0  then 0
      else nvl(KmSosire,0) - nvl(KmPlecare,0)
    end, AUTO.TIP, AUTO.MASAU, AUTO.TIPINCARC, FAZ.CMM, FAZ.REZERVORCALC - FAZ.REZERVOR,
    NVL(I.CODINTR,0), CASE WHEN I.CODINTR &gt; 0 THEN I.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC ELSE NULL END,
    NVL(BC.CODIES,0), NVL(T.CODTREZOR,0), 
    CASE WHEN BC.CODIES &gt; 0 THEN BC.PREFIXDOC||&apos; &apos;||BC.NRDOC||&apos;/&apos;||BC.DATADOC ELSE NULL END,
    CASE WHEN T.CODTREZOR &gt; 0 THEN CASE WHEN TRIM(T.NUMEDOC) = &apos;&apos; THEN TO_CHAR(T.DATADOC,&apos;DD.MM.YYYY&apos;) ELSE T.NUMEDOC END ELSE NULL END,AUTO.PUTERE,
    case 
      WHEN NVL(R1.TIPINCARC,0) = 1 THEN &apos;Marfa&apos;
      WHEN NVL(R1.TIPINCARC,0) = 2 THEN &apos;Persoane&apos;
      WHEN NVL(R1.TIPINCARC,0) = 3 THEN &apos;Mixta&apos;
    end,
    case 
      WHEN NVL(R2.TIPINCARC,0) = 1 THEN &apos;Marfa&apos;
      WHEN NVL(R2.TIPINCARC,0) = 2 THEN &apos;Persoane&apos;
      WHEN NVL(R2.TIPINCARC,0) = 3 THEN &apos;Mixta&apos;
       END , coalesce (FAZ.CONSSTAT, AUTO.CONSSTATH * FAZ.ORES), AUTO.CONSSTATH, FAZ.PARCURSB + FAZ.PARCURSM + FAZ.PARCURSO, FAZ.ECHIV1 + FAZ.ECHIV2, 
      CASE
        WHEN COALESCE (FAZ.KmSosire, 0) - COALESCE (FAZ.KmPlecare, 0) = 0 THEN 0
          ELSE (COALESCE (FAZ.RezervorPlecare, 0) + COALESCE (FAZ.Alimpompa, 0) + COALESCE (FAZ.ALIMBCF, 0) + COALESCE (FAZ.ALIMAVANS, 0) - COALESCE (FAZ.Rezervor, 0)) * 100 / (COALESCE (FAZ.KmSosire, 0) - COALESCE (FAZ.KmPlecare, 0)) - COALESCE(AUTO.CONSSTATH, 0) * COALESCE(FAZ.ORES, 0)
      END
    FROM FAZ
       INNER JOIN NPARCAUT AUTO ON AUTO.CODNPARCAUT = FAZ.CODAUTO
       INNER JOIN NARTOBJ OBJ ON AUTO.CODART = OBJ.CODOBIECT
       LEFT JOIN NPERS P ON P.CODPERS = FAZ.CODPERS
       LEFT JOIN INTRARI I ON FAZ.CODINTR = I.CODINTR
       LEFT JOIN IESIRI BC ON BC.CODIES = FAZ.CODIES
       LEFT JOIN TREZOR T ON FAZ.CODTREZOR = T.CODTREZOR
       LEFT JOIN NPARCAUT R1 ON R1.CODNPARCAUT = FAZ.CODAUTO1
       LEFT JOIN NPARCAUT R2 ON R2.CODNPARCAUT = FAZ.CODAUTO2
  WHERE CODFAZ = RECID;
  
  INSERT INTO TMP_FAZ0 (CODFAZ0, CODFAZ, INDEXLOCAL, CODPERS, KMSOSIRE, DATAPLECARE, SOFER, KMPLECARE,
                        CODPART, TIPDOC, NRDOC, RUTA, TIPTRANSPORT, CANT, KMINC, KMGOL, OBS, CODANALIZANOD, KM)
  SELECT FAZ0.CODFAZ0, FAZ0.CODFAZ, FAZ0.INDEXLOCAL, FAZ0.CODPERS, FAZ0.KMSOSIRE, FAZ0.DATAPLECARE, P.NUME||&apos; &apos;||P.PRENUME, FAZ0.KMPLECARE,
         FAZ0.CODPART, FAZ0.TIPDOC, FAZ0.NRDOC, FAZ0.RUTA, FAZ0.TIPTRANSPORT, FAZ0.CANT, FAZ0.KMINC, FAZ0.KMGOL, FAZ0.OBS, FAZ0.CODANALIZANOD,
         FAZ0.KMSOSIRE - FAZ0.KMPLECARE
  FROM FAZ0
       INNER JOIN NPERS P ON FAZ0.CODPERS = P.CODPERS
  WHERE FAZ0.CODFAZ = RECID;
  
  INSERT INTO TMP_FAZ1 (CODFAZ1, CODFAZ, INDEXLOCAL, KM, INCARCAT, TIPSURSA, CATDRUM, COEF, KMECHIV, DENCATDRUM, CODFAZ0)
  SELECT FAZ1.CODFAZ1, FAZ1.CODFAZ, FAZ1.INDEXLOCAL, FAZ1.KM, FAZ1.INCARCAT, FAZ1.TIPSURSA, FAZ1.CATDRUM, FAZ1.COEF, 
         case when FAZ1.COEF &lt;&gt; 0 then FAZ1.KM * FAZ1.Coef else null end,
         GR.DENUMIRE, FAZ1.CODFAZ0
  FROM FAZ1 
       INNER JOIN GRUPEDRUM GR ON GR.CODGRUPA = FAZ1.CATDRUM
  WHERE CODFAZ = RECID;

  update tmp_faz 
  set
    RestSpecificat = KmParcurs - (select nvl(sum(km),0) from tmp_faz1),
    TKM = (select nvl(sum(km * coef),0) from tmp_faz1), 
    TKMPLIN = (select nvl(sum(km * coef),0) from tmp_faz1 where incarcat = 1), 
    TKMGOL = (select nvl(sum(km * coef),0) from tmp_faz1 where incarcat = 0);

  INSERT INTO TMP_FAZ2 (CODFAZ2, CODFAZ, INDEXLOCAL, CODINSTAUTO, CANT, SPOR, PARCURSECHIV)
  SELECT CODFAZ2, CODFAZ, INDEXLOCAL, CODINSTAUTO, CANT, SPOR, CANT * SPOR
  FROM FAZ2 WHERE CODFAZ = RECID;
  
  update tmp_faz 
  set
    tKmSpor = (select nvl(sum(nvl(parcursechiv,0)),0) from tmp_faz2);
  
  update tmp_faz
  set
    tKmTot = tKm + nvl(tKmSpor,0);  
  
  INSERT INTO TMP_FAZ3 (CODFAZ3, CODFAZ, INDEXLOCAL, CODTRASEU, PARCURGERI, KMTRASEU, OPRIRI, DURATA, DENTRASEU, TOTALKM,
                        ORE, MINUTE)
  SELECT F3.CODFAZ3, F3.CODFAZ, F3.INDEXLOCAL, F3.CODTRASEU, F3.PARCURGERI, F3.KMTRASEU, 
         F3.Parcurgeri * T.OPRIRI, TO_CHAR(T.ORE * F3.Parcurgeri) + TRUNC(T.MINUTE * F3.PARCURGERI / 60)||&apos;:&apos;||
         LPAD(to_char(MOD(T.MINUTE * F3.PARCURGERI,60)), 2, &apos;0&apos;), T.DENTRASEU,
         F3.Parcurgeri * F3.KMTRASEU,
         T.ORE, T.MINUTE
  FROM FAZ3 F3
       INNER JOIN TRASEULIVR T ON T.CODTRASEULIVR = F3.CODTRASEU
  WHERE F3.CODFAZ = RECID;
  
  update tmp_faz set
  tr_totalkm = (select nvl(sum(totalkm),0) from tmp_faz3),
  tr_totalopriri = (select nvl(sum(opriri),0) from tmp_faz3),
  tr_durata = TO_CHAR((select nvl(sum((ORE * Parcurgeri) + TRUNC(MINUTE * PARCURGERI / 60)),0) from tmp_faz3))||&apos;:&apos;||
              LPAD(to_char(MOD((select sum(MINUTE * PARCURGERI) from tmp_faz3),60)), 2, &apos;0&apos;);
  
  insert into tmp_fazintr(codfazintr, codfaz, indexlocal, coddoc, tipdoc, doc, cantcomb, altefaz, cantintr, articol)
  select fazi.codfazintr, fazi.codfaz, fazi.indexlocal, fazi.coddoc, fazi.tipdoc, i.prefixdoc||&apos; &apos;||i.nrdoc||&apos;/&apos;||to_char(i.datadoc,&apos;dd.mm.yyyy&apos;),fazi.cantcomb,
         (select nvl(sum(fi.cantcomb),0)
          from fazintr fi
               inner join intrari1 ii1 on fi.coddoc = ii1.codintr1
               inner join intrari ii on ii1.codintr = ii.codintr and fi.tipdoc = ii.tipdoc
          where ii1.codintr1 = i1.codintr1 and i.tipdoc = ii.tipdoc and fi.codfaz &lt;&gt; recid
          ), i1.cant, obj.denumire           
  from fazintr fazi
       inner join intrari1 i1 on i1.codintr1 = fazi.coddoc
       inner join intrari i on i.codintr = i1.codintr and i.tipdoc = fazi.tipdoc
       inner join nartobj obj on obj.codobiect = i1.codobiect
  where fazi.codfaz = RecId;
  
  update tmp_fazintr set rest = cantintr - cantcomb - altefaz; 
  update tmp_fazintr set rest = 0 where rest &lt; 0;
  
  /*pkg_globals.SetSeparator(&apos;,&apos;);
  begin
    select pkg_categconst.getvalconstanta(&apos;ARTSTOCCOMBUSTIBIL&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) 
    into sComb 
    from dual;
  exception when others then
    sComb := &apos;0&apos;;
  end;  
              
  sSQL := &apos;update tmp_fazintr fazi 
           set
           cantcomb = (select sum(i1.cant) 
                       from intrari i
                            inner join intrari1 i1 on i.codintr = i1.codintr
                       where fazi.coddoc = i.codintr and fazi.tipdoc = i.tipdoc and
                             i1.codobiect in (&apos;||sComb||&apos;)     
                       )&apos;;
  execute immediate sSQL;*/
  PKG_CFGTABLES.EXT_GOTORECORD(89);
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aCARNETDOC    NUMBER(20);
aNRDOC        NUMBER(20);
aCodSubunit   NUMBER(20);
aDataDoc      DATE;
aDoc          VARCHAR2(200);
aCod          NUMBER(20);
aCodAuto      NUMBER(20);
aObs          VARCHAR2(150);
BEGIN
  SELECT
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    CODAUTO
  INTO
    aCARNETDOC,
    aNRDOC,
    aCodSubunit,
    aDATADOC,
    ADOC,
    ACODAUTO
  FROM TMP_FAZ;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (89); 
  IF OPERATION = 0 THEN  -- UPDATE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;FAZ&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT CodFAZ INTO RecId FROM TMP_FAZ;

    UPDATE FAZ SET (CARNETDOC, SERIADOC, PREFIXDOC, NRDOC, DATADOC, OPERAT, BLOCAT, ANULAT,
                    SUBUNITATEA, CODAUTO, CODPERS, DIAGRAMA, ALIMPOMPA, ALIMBCF, ALIMAVANS, KMPLECARE, KMSOSIRE, KMN,
                    CSARCINA, CSARCINAR, CSTART, CIMOTOR, CCURSE, CRAER, CIARNA, OREREGIE, OREACORD, OREN, TONES, ORES,
                    TSTART, TIMOTOR, TCURSE, RAER, PARCURSN, REZERVORPLECARE, CODFAZS, AN,
                    LUNA, CONSUM, REZERVORCALC, REZERVOR, OBS, TIPPARCURS, CODBC, CODDECONT, CODAUTO1, CODAUTO2, PARCURSR1,
                    PARCURSR2, PARCURS1, PARCURS2, T1, T2, ECHIV1, ECHIV2, CODGRAUTO, PARCURSB, PARCURSM, PARCURSO, B, M, O,
                    ECHIVB, ECHIVM, ECHIVO, TIPAERODIN, NRREM, PARCURSAERO, AEROSR, ECHIVAERO, ECHIVINST, CODINTR, CMM, CODIES,
                    CONSSTAT)
    =
           (SELECT CARNETDOC, SERIADOC, PREFIXDOC, NRDOC, DATADOC, OPERAT, BLOCAT, ANULAT,
                   SUBUNITATEA, CODAUTO, CODPERS, DIAGRAMA, ALIMPOMPA, ALIMBCF, ALIMAVANS, KMPLECARE, KMSOSIRE, KMN,
                   CSARCINA, CSARCINAR, CSTART, CIMOTOR, CCURSE, CRAER, CIARNA, OREREGIE, OREACORD, OREN, TONES, ORES,
                   TSTART, TIMOTOR, TCURSE, RAER, PARCURSN, REZERVORPLECARE, CODFAZS, AN,
                   LUNA, CONSUM, REZERVORCALC, REZERVOR, OBS, TIPPARCURS, CODBC, CODDECONT, CODAUTO1, CODAUTO2, PARCURSR1,
                   PARCURSR2, PARCURS1, PARCURS2, T1, T2, ECHIV1, ECHIV2, CODGRAUTO, PARCURSB, PARCURSM, PARCURSO, B, M, O,
                   ECHIVB, ECHIVM, ECHIVO, TIPAERODIN, NRREM, PARCURSAERO, AEROSR, ECHIVAERO, ECHIVINST, CODINTR, CMM, CODIES,
                   CONSSTAT 
            FROM TMP_FAZ )
    WHERE CodFAZ = RecId;

    DELETE FROM FAZ0 WHERE CodFAZ = RecId and CodFAZ0 not in (Select CodFAZ0 from TMP_FAZ0);
    FOR v_rec IN (SELECT * FROM TMP_FAZ0 ORDER BY CodFAZ0) LOOP -- update pentru cele ramase
      IF V_REC.CODFAZ0 &lt;= 0 THEN
        SELECT SEQ_FAZ0_CODFAZ0.NEXTVAL INTO ACOD FROM DUAL;
        UPDATE TMP_FAZ1 SET CODFAZ0 = ACOD WHERE CODFAZ0 = V_REC.CODFAZ0;
        INSERT INTO FAZ0 (CODFAZ0, CODFAZ, INDEXLOCAL, CODPERS, KMSOSIRE, DATAPLECARE, KMPLECARE,
                          CODPART, TIPDOC, NRDOC, RUTA, TIPTRANSPORT, CANT, KMINC, KMGOL, OBS, CODANALIZANOD)
        VALUES (ACOD, RECID, V_REC.INDEXLOCAL, V_REC.CODPERS, V_REC.KMSOSIRE, V_REC.DATAPLECARE, V_REC.KMPLECARE,
                V_REC.CODPART, V_REC.TIPDOC, V_REC.NRDOC, V_REC.RUTA, V_REC.TIPTRANSPORT, V_REC.CANT, V_REC.KMINC, V_REC.KMGOL, V_REC.OBS,
                V_REC.CODANALIZANOD);
      ELSE
        UPDATE FAZ0
        SET
          CODPERS     = V_REC.CODPERS,
          INDEXLOCAL  = V_REC.INDEXLOCAL, 
          KMSOSIRE    = V_REC.KMSOSIRE, 
          DATAPLECARE = V_REC.DATAPLECARE,
          KMPLECARE   = V_REC.KMPLECARE,
          CODPART     = V_REC.CODPART, 
          TIPDOC      = V_REC.TIPDOC, 
          NRDOC       = V_REC.NRDOC, 
          RUTA        = V_REC.RUTA, 
          TIPTRANSPORT = V_REC.TIPTRANSPORT, 
          CANT        = V_REC.CANT, 
          KMINC       = V_REC.KMINC, 
          KMGOL       = V_REC.KMGOL,
          OBS         = V_REC.OBS,
          CODANALIZANOD = V_REC.CODANALIZANOD
        WHERE CodFAZ0 = v_rec.CodFAZ0;
      END IF;
    END LOOP;

    DELETE FROM FAZ1 WHERE CodFAZ = RecId and CodFAZ1 not in (Select CodFAZ1 from TMP_FAZ1);
    FOR v_rec IN (SELECT * FROM TMP_FAZ1 ORDER BY CodFAZ1) LOOP -- update pentru cele ramase
      IF V_REC.CODFAZ1 &lt;= 0 THEN
        INSERT INTO FAZ1 (CODFAZ1, CODFAZ, INDEXLOCAL, KM, INCARCAT, TIPSURSA, CATDRUM, COEF, CODFAZ0)
        VALUES (SEQ_FAZ1_CODFAZ1.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.KM, nvl(V_REC.INCARCAT,0), V_REC.TIPSURSA, V_REC.CATDRUM, V_REC.COEF,
                V_REC.CODFAZ0);
      ELSE
        UPDATE FAZ1
        SET
          INDEXLOCAL = V_REC.INDEXLOCAL,
          KM         = V_REC.KM,
          INCARCAT   = nvl(V_REC.INCARCAT,0),
          TIPSURSA   = V_REC.TIPSURSA,
          CATDRUM    = V_REC.CATDRUM,
          COEF       = V_REC.COEF,
          CODFAZ0    = V_REC.CODFAZ0
        WHERE CodFAZ1 = v_rec.CodFAZ1;
      END IF;
    END LOOP;

    DELETE FROM FAZ2 WHERE CodFAZ = RecId and CodFAZ2 not in (Select CodFAZ2 from TMP_FAZ2);
    FOR v_rec IN (SELECT * FROM TMP_FAZ2 ORDER BY CodFAZ2) LOOP -- update pentru cele ramase
      IF V_REC.CODFAZ2 &lt;= 0 THEN
        INSERT INTO FAZ2 (CODFAZ2, CODFAZ, INDEXLOCAL, CODINSTAUTO, CANT, SPOR)
        VALUES (SEQ_FAZ2_CODFAZ2.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.CODINSTAUTO, V_REC.CANT, V_REC.SPOR);
      ELSE
        UPDATE FAZ2
        SET
          INDEXLOCAL   = V_REC.INDEXLOCAL,
          CODINSTAUTO  = V_REC.CODINSTAUTO,
          CANT         = V_REC.CANT,
          SPOR         = V_REC.SPOR
        WHERE CodFAZ2 = v_rec.CodFAZ2;
      END IF;
    END LOOP;

    DELETE FROM FAZ3 WHERE CodFAZ = RecId and CodFAZ3 not in (Select CodFAZ3 from TMP_FAZ3);
    FOR v_rec IN (SELECT * FROM TMP_FAZ3 ORDER BY CodFAZ3) LOOP -- update pentru cele ramase
      IF V_REC.CODFAZ3 &lt;= 0 THEN
        INSERT INTO FAZ3 (CODFAZ3, CODFAZ, INDEXLOCAL, CODTRASEU, PARCURGERI, KMTRASEU)
        VALUES (SEQ_FAZ3_CODFAZ3.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.CODTRASEU, V_REC.PARCURGERI, V_REC.KMTRASEU);
      ELSE
        UPDATE FAZ3
        SET
          INDEXLOCAL = V_REC.INDEXLOCAL,
          CODTRASEU  = V_REC.CODTRASEU,
          PARCURGERI = V_REC.PARCURGERI,
          KMTRASEU   = V_REC.KMTRASEU
        WHERE CodFAZ3 = v_rec.CodFAZ3;
      END IF;
    END LOOP;
    
    DELETE FROM FAZINTR WHERE CODFAZ = RECID AND CODFAZINTR NOT IN (SELECT CODFAZINTR FROM TMP_FAZINTR);
    FOR V_REC IN (SELECT * FROM TMP_FAZINTR ORDER BY CODFAZINTR) LOOP
      IF V_REC.CODFAZINTR &lt;= 0 THEN
        INSERT INTO FAZINTR (CODFAZINTR, CODFAZ, INDEXLOCAL, CODDOC, TIPDOC, CANTCOMB)
        VALUES (SEQ_FAZINTR_CODFAZINTR.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.CANTCOMB);
      ELSE
        UPDATE FAZINTR 
        SET
          INDEXLOCAL = V_REC.INDEXLOCAL, 
          CODDOC     = V_REC.CODDOC, 
          TIPDOC     = V_REC.TIPDOC,
          CANTCOMB   = V_REC.CANTCOMB
        WHERE CODFAZINTR = V_REC.CODFAZINTR;  
      END IF;
    END LOOP;
    
  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;FAZ&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT SEQ_FAZ_CodFAZ.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;FAZ&apos;, RecId);
    INSERT INTO FAZ (
      CODFAZ, CARNETDOC, SERIADOC, PREFIXDOC, NRDOC, DATADOC, OPERAT, BLOCAT, ANULAT, USERID, DATACREARE,
      SUBUNITATEA, CODAUTO, CODPERS, DIAGRAMA, ALIMPOMPA, ALIMBCF, ALIMAVANS, KMPLECARE, KMSOSIRE, KMN,
      CSARCINA, CSARCINAR, CSTART, CIMOTOR, CCURSE, CRAER, CIARNA, OREREGIE, OREACORD, OREN, TONES, ORES,
      TSTART, TIMOTOR, TCURSE, RAER, PARCURSN, REZERVORPLECARE, CODFAZS, AN,
      LUNA, CONSUM, REZERVORCALC, REZERVOR, OBS, TIPPARCURS, CODBC, CODDECONT, CODAUTO1, CODAUTO2, PARCURSR1,
      PARCURSR2, PARCURS1, PARCURS2, T1, T2, ECHIV1, ECHIV2, CODGRAUTO, PARCURSB, PARCURSM, PARCURSO, B, M, O,
      ECHIVB, ECHIVM, ECHIVO, TIPAERODIN, NRREM, PARCURSAERO, AEROSR, ECHIVAERO, ECHIVINST, CODINTR, CMM, CODIES,
      CONSSTAT)
    SELECT RECID, CARNETDOC, SERIADOC, PREFIXDOC, NRDOC, DATADOC, OPERAT, BLOCAT, ANULAT, PKG_GLOBALS.GETUSERID, SYSDATE,
      SUBUNITATEA, CODAUTO, CODPERS, DIAGRAMA, ALIMPOMPA, ALIMBCF, ALIMAVANS, KMPLECARE, KMSOSIRE, KMN,
      CSARCINA, CSARCINAR, CSTART, CIMOTOR, CCURSE, CRAER, CIARNA, OREREGIE, OREACORD, OREN, TONES, ORES,
      TSTART, TIMOTOR, TCURSE, RAER, PARCURSN, REZERVORPLECARE, CODFAZS, AN,
      LUNA, CONSUM, REZERVORCALC, REZERVOR, OBS, TIPPARCURS, CODBC, CODDECONT, CODAUTO1, CODAUTO2, PARCURSR1,
      PARCURSR2, PARCURS1, PARCURS2, T1, T2, ECHIV1, ECHIV2, CODGRAUTO, PARCURSB, PARCURSM, PARCURSO, B, M, O,
      ECHIVB, ECHIVM, ECHIVO, TIPAERODIN, NRREM, PARCURSAERO, AEROSR, ECHIVAERO, ECHIVINST, CODINTR, CMM, CODIES,
      CONSSTAT
    FROM TMP_FAZ;

    FOR V_REC IN (SELECT * FROM TMP_FAZ0) LOOP
      SELECT SEQ_FAZ0_CODFAZ0.NEXTVAL INTO ACOD FROM DUAL;
      UPDATE TMP_FAZ1 SET CODFAZ0 = ACOD WHERE CODFAZ0 = V_REC.CODFAZ0;
      INSERT INTO FAZ0 (CODFAZ0, CODFAZ, INDEXLOCAL, CODPERS, KMSOSIRE, DATAPLECARE, KMPLECARE,
                        CODPART, TIPDOC, NRDOC, RUTA, TIPTRANSPORT, CANT, KMINC, KMGOL, OBS, CODANALIZANOD)
      values(ACOD, RECID, V_REC.INDEXLOCAL, V_REC.CODPERS, V_REC.KMSOSIRE, V_REC.DATAPLECARE, V_REC.KMPLECARE,
             V_REC.CODPART, V_REC.TIPDOC, V_REC.NRDOC, V_REC.RUTA, V_REC.TIPTRANSPORT, V_REC.CANT, V_REC.KMINC, V_REC.KMGOL, V_REC.OBS,
             V_REC.CODANALIZANOD);
    END LOOP;  

    INSERT INTO FAZ1 (CODFAZ1, CODFAZ, INDEXLOCAL, KM, INCARCAT, TIPSURSA, CATDRUM, COEF, CODFAZ0)
    SELECT SEQ_FAZ1_CODFAZ1.NEXTVAL, RECID, INDEXLOCAL, KM, nvl(INCARCAT,0), TIPSURSA, CATDRUM, COEF, CODFAZ0
    FROM TMP_FAZ1;

    INSERT INTO FAZ2 (CODFAZ2, CODFAZ, INDEXLOCAL, CODINSTAUTO, CANT, SPOR)
    SELECT SEQ_FAZ2_CODFAZ2.NEXTVAL, RECID, INDEXLOCAL, CODINSTAUTO, CANT, SPOR
    FROM TMP_FAZ2;

    INSERT INTO FAZ3 (CODFAZ3, CODFAZ, INDEXLOCAL, CODTRASEU, PARCURGERI, KMTRASEU)
    SELECT SEQ_FAZ3_CODFAZ3.NEXTVAL, RECID, INDEXLOCAL, CODTRASEU, PARCURGERI, KMTRASEU
    FROM TMP_FAZ3;
    
    INSERT INTO FAZINTR (CODFAZINTR, CODFAZ, INDEXLOCAL, CODDOC, TIPDOC, CANTCOMB)
    SELECT SEQ_FAZINTR_CODFAZINTR.NEXTVAL, RECID, INDEXLOCAL, CODDOC, TIPDOC, CANTCOMB
    FROM TMP_FAZINTR;
  END IF;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;
  NotifyModif(Operation, RecId, &apos;FAZ&apos;);
  
  -- actualizez automat citirea pe masina
  for v_rec in (select * from faz0 where codfaz = recid) loop
    BEGIN
      SELECT OBS INTO AOBS FROM NPARC0 WHERE CODNPARCAUT = ACODAUTO AND TRUNC(DATABORD) = TRUNC(v_rec.dataplecare) and codpers = V_REC.CODPERS;
    EXCEPTION WHEN OTHERS THEN AOBS := V_REC.OBS;
    END;
    
    DELETE NPARC0 WHERE CODNPARCAUT = ACODAUTO AND TRUNC(DATABORD) = TRUNC(v_rec.dataplecare) and codpers = V_REC.CODPERS;
    INSERT INTO NPARC0(CODNPARC0,
                       CODNPARCAUT,
                       DATABORD,
                       KMBORD,
                       AN,
                       LUNA,
                       OBS,
                       CODPERS,
                       CODFAZ)
    VALUES (
      SEQ_NPARC0_CODNPARC0.NEXTVAL,
      ACODAUTO,
      TRUNC(v_rec.dataplecare),
      V_REC.KMSOSIRE,
      EXTRACT(YEAR FROM v_rec.dataplecare),
      EXTRACT(MONTH FROM v_rec.dataplecare),
      AOBS,
      V_REC.CODPERS,
      RECID
    ); 
  end loop;
  PKG_CFGTABLES.EXT_POSTRECORDS(89); 
  COMMIT;
END;

PROCEDURE CORELAREFAZ1 IS
ACOD NUMBER(20);  
BEGIN
  FOR V_REC IN (SELECT DISTINCT FAZ.CODFAZ, A.SOFER, FAZ.KMPLECARE, FAZ.KMSOSIRE, FAZ.DATADOC
                FROM FAZ
                     INNER JOIN NPARCAUT A ON FAZ.CODAUTO = A.CODNPARCAUT
                WHERE (SELECT COUNT(*) FROM FAZ0 WHERE FAZ0.CODFAZ = FAZ.CODFAZ) = 0
                      AND
                      (SELECT COUNT(*) FROM FAZ1 WHERE FAZ1.CODFAZ = FAZ.CODFAZ) &gt; 0
               ) LOOP
    SELECT SEQ_FAZ0_CODFAZ0.NEXTVAL INTO ACOD FROM DUAL;
    UPDATE FAZ1 SET CODFAZ0 = ACOD WHERE CODFAZ = V_REC.CODFAZ;
    INSERT INTO FAZ0(CODFAZ0, CODFAZ, INDEXLOCAL, KMPLECARE, KMSOSIRE, DATAPLECARE, CODPERS)
    VALUES (ACOD, V_REC.CODFAZ, 1, V_REC.KMPLECARE, V_REC.KMSOSIRE, V_REC.DATADOC, V_REC.SOFER);
  END LOOP;
  COMMIT;
END;

end PKG_FAZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FISAEVALP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30EA92292400EC307C34097C18ADA314DBE764B0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FisaEvalP is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodFisa INTO Tmp FROM FisaEvalP WHERE CodFisa = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM FisaEvalP WHERE CodFisa = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_FisaEvalP FIELDS( CodFisa ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_FisaEvalP 
	(  CodFisa   ,                         
     CodEvaluare,  
     CR ,            
     EN ,            
     MT ,            
     FR ,            
     SG ,            
     NA ,            
     AN ,            
     UG ,
     NUMETESATURA,  
     rundaevaluare,
     codevaluator,  
     codtesatura,   
     coddestinatie, 
     numeevaluator, 
     NUMEDESTINATIE
	)
	SELECT 
     FP.CodFisa   ,                         
     FP.CodEvaluare,  
     FP.CR ,            
     FP.EN ,            
     FP.MT ,            
     FP.FR ,            
     FP.SG ,            
     FP.NA ,            
     FP.AN ,            
     FP.UG ,
     T.Denumire NUMETESATURA,  
     E.rundaevaluare,
     E.codevaluator,  
     E.codtesatura,   
     E.coddestinatie, 
     Ev.NUME numeevaluator, 
     D.NumeDestinatie NUMEDESTINATIE
  FROM FisaEvalP FP
  inner join evaluari E on E.Codevaluare=FP.Codevaluare
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie            
  WHERE CodFisa = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodFisa INTO RECID FROM TMP_FisaEvalP;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE FisaEvalP
    SET
     (
     CodEvaluare,  
     CR ,            
     EN ,            
     MT ,            
     FR ,            
     SG ,            
     NA ,            
     AN ,            
     UG,
     NUMETESATURA             
			)
			= 
			(SELECT
     CodEvaluare,  
     CR ,            
     EN ,            
     MT ,            
     FR ,            
     SG ,            
     NA ,            
     AN ,            
     UG ,
     NUMETESATURA            
		FROM TMP_FisaEvalP)
    WHERE CodFisa = RECID;

ELSE  -- INSERT
    SELECT SEQ_FisaEvalP_CodFisa.NextVal INTO RecId FROM DUAL;
    INSERT INTO FisaEvalP(
     CodFisa   ,                         
     CodEvaluare,  
     CR ,            
     EN ,            
     MT ,            
     FR ,            
     SG ,            
     NA ,            
     AN ,            
     UG ,
     NUMETESATURA            
    )
    SELECT 
  	RECID   , 
     CodEvaluare, 
     CR ,            
     EN ,            
     MT ,            
     FR ,            
     SG ,            
     NA ,            
     AN ,            
     UG ,
     NUMETESATURA            
		FROM TMP_FisaEvalP;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;FisaEvalP&apos;);
  COMMIT;
 
END;


end PKG_FisaEvalP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FISAEVALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C05CF0D04FA1D2711933089A1EC3D6B1331F83FA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FisaEvalT is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodFisa INTO Tmp FROM FisaEvalT WHERE CodFisa = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM FisaEvalT WHERE CodFisa = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_FisaEvalT FIELDS( CodFisa ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_FisaEvalT 
	(  CodFisa   ,                         
     CodEvaluare, 
     NOTA,
     NUMETESATURA,
     rundaevaluare,
     codevaluator,  
     codtesatura,   
     coddestinatie, 
     numeevaluator, 
     NUMEDESTINATIE             
	)
	SELECT 
     FT.CodFisa   ,                         
     FT.CodEvaluare, 
     FT.NOTA,
     T.Denumire NUMETESATURA,  
     E.rundaevaluare,
     E.codevaluator,  
     E.codtesatura,   
     E.coddestinatie, 
     Ev.NUME numeevaluator, 
     D.NumeDestinatie NUMEDESTINATIE
  FROM FisaEvalT FT
  inner join evaluari E on E.Codevaluare=FT.Codevaluare
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie 
  WHERE CodFisa = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodFisa INTO RECID FROM TMP_FisaEvalT;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE FisaEvalT
    SET
     (
     CodEvaluare, 
     NOTA,
     NUMETESATURA             
			)
			= 
			(SELECT
     CodEvaluare, 
     NOTA,
     NUMETESATURA             
		FROM TMP_FisaEvalT)
    WHERE CodFisa = RECID;

ELSE  -- INSERT
    SELECT SEQ_FisaEvalT_CodFisa.NextVal INTO RecId FROM DUAL;
    INSERT INTO FisaEvalT(
     CodFisa   ,                         
     CodEvaluare, 
     NOTA,
     NUMETESATURA
    )
    SELECT 
  	RECID   , 
     CodEvaluare, 
     NOTA,
     NUMETESATURA  
		FROM TMP_FisaEvalT;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;FisaEvalT&apos;);
  COMMIT;
 
END;


end PKG_FisaEvalT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FISATEH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D8DAF1DFECDE68797C192AA10C5A8A15053AE8A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_fisateh IS

PROCEDURE SetBlacare(aCodFisaSup in number, Blocaj in number) IS
PRAGMA AUTONOMOUS_TRANSACTION;
begin
  update fisasup set blocat = Blocaj where codfisasup = aCodFisaSup;
  commit;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP1 NUMBER(20) := 0;
TMP2 NUMBER(20) := 0;
BEGIN
  SELECT FT.CodFisaTeh, FS.CodFisaSup INTO Tmp1, Tmp2
  FROM FISATEH FT
       INNER JOIN FISASUP FS ON FT.CODFISASUP = FS.CODFISASUP
  WHERE CodFisaTeh = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  delete FISAMAND FMD where exists (select FM.CodFisaMan from FISAMAN FM where FM.CodFisaMan = FMD.CodFisaMan and FM.CodFisaTeh = RecId);
  delete FISASDV FSDV where exists (select FM.codfisaman from FISAMAN FM where FM.CodFisaMan = FSDV.CodFisaMan and FM.CodFisaTeh = RecId);
  delete FISAMAN where CodFisaTeh = RecId;
  delete FISAREZ where CodFisaTeh = RecId;
  delete FISATEH where CodFisaTeh = RecId;
  NotifyModif(2, RecId, &apos;FISATEH&apos;);
  commit;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  insert into TMP_FISATEH FIELDS( CodFisaTeh ) values (0) ;
  commit;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  insert into TMP_FISATEH (CodFisaTeh, CodFisaSup, Intocmita, Datafisa, Finalizata, Blocata)
  (select CodFisaTeh, CodFisaSup, Intocmita, Datafisa, Finalizata, Blocata from FISATEH where CodFisaTeh = RecId);

  insert into TMP_FISAMAN (CodFisaMan, CodTraseu, NrOp, CodOp, CodLocM, CodDif, DSV, TPI, TU, BPS, Final, Blocat, CodFisaTeh)
  (select CodFisaMan, CodTraseu, NrOp, CodOp, CodLocM, CodDif, DSV, TPI, TU, BPS, Final, Blocat, CodFisaTeh from FISAMAN where CodFisaTeh = RecId);

  insert into TMP_FISAMAND (CodFisaManD, CodFisaMan, CodOp, CodDif, TPI, TU)
  (select FMD.CodFisaManD, FMD.CodFisaMan, FMD.CodOp, FMD.CodDif, FMD.TPI, FMD.TU
   from FISAMAND FMD where exists (select FM.CodFisaMan from FISAMAN FM where FMD.CODFISAMAN = FM.CODFISAMAN and FM.CodFIsaTeh = RecId));

  insert into TMP_FISASDV (CodFisaSDV, CodFisaMan, IndexLocal, CodSDV, CodGeneric, Cant, Pret)
  (select FSDV.CodFisaSDV, FSDV.CodFisaMan, FSDV.IndexLocal, FSDV.CodSDV, FSDV.CodGeneric, FSDV.Cant, FSDV.Pret
   from FISASDV FSDV where exists (select FM.CodFisaMan from FISAMAN FM where FSDV.CODFISAMAN = FM.CODFISAMAN and FM.CodFIsaTeh = RecId));

  insert into TMP_FISAREZ (CODFISAREZ, CODTRASEU, CODPREZ, CODGENERIC, CANT, UMSEC, PRET, CODFISATEH)
  (select CODFISAREZ, CODTRASEU, CODPREZ, CODGENERIC, CANT, UMSEC, PRET, CODFISATEH from FISAREZ where CodFisaTeh = RecId);

  insert into TMP_PROIECT (CODPROIECT, CODOBIECTPROD, VERSIUNE, PROCESARE, Den_Procesare)
  (select P.CodProiect, P.CodObiectProd, P.Versiune, P.Procesare, case when P.Procesare = 1 then &apos;Agregare&apos; else &apos;Dezagregare&apos; end
   from FISATEH FT
        INNER join FISASUP FS on FT.CODFISASUP = FS.CODFISASUP
        INNER JOIN PROIECTNOD PN on fs.codproiectnod = pn.codproiectnod
        inner join PROIECT P on PN.CODPROIECT = P.CODPROIECT
   where FT.CodFisaTeh = RecId);

  insert into tmp_fisasup (codfisasup, codproiectnod, codobiectnod, identificator, obs)
  (select fs.codfisasup, fs.codproiectnod, fs.codobiectnod, fs.identificator, fs.obs
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
   where ft.codfisateh = RecId);

  insert into tmp_traseu (codtraseu, codfisasup, indexlocal, pozt, executant, clasateh)
  (select t.codtraseu, t.codfisasup, t.indexlocal, t.pozt, t.executant, t.clasateh
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
        inner join traseu t on fs.codfisasup = t.codfisasup
   where ft.codfisateh = RecId);

  insert into tmp_fisamat (codfisainf, codfisasup, poznom, codobiectinf, codgeneric, cantinsup,
                           umsec, pret, dimt, complex, material, codfisapro, umdimt, consumator, masa)
  (select fi.codfisainf, fi.codfisasup, fi.poznom, fi.codobiectinf, fi.codgeneric, fi.cantinsup,
          fi.umsec, fi.pret, fi.dimt, fi.complex, fi.material, fi.codfisapro, fi.umdimt, fi.consumator, fi.masa
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
        inner join fisainf fi on fs.codfisasup = fi.codfisasup
   where ft.codfisateh = RecId and fi.complex = 2);

  insert into tmp_fisainf (codfisainf, codfisasup, poznom, codobiectinf, codgeneric, cantinsup,
                           umsec, pret, dimt, complex, material, codfisapro, umdimt, consumator, masa)
  (select fi.codfisainf, fi.codfisasup, fi.poznom, fi.codobiectinf, fi.codgeneric, fi.cantinsup,
          fi.umsec, fi.pret, fi.dimt, fi.complex, fi.material, fi.codfisapro, fi.umdimt, fi.consumator, fi.masa
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
        inner join fisainf fi on fs.codfisasup = fi.codfisapro
   where ft.codfisateh = RecId and nvl(fi.codfisasup, 0) &gt; 0 );

  insert into tmp_fisainfmat (codfisainf, codfisasup, poznom, codobiectinf, codgeneric, cantinsup,
                           umsec, pret, dimt, complex, material, codfisapro, umdimt, consumator, masa)
  (select fi.codfisainf, fi.codfisasup, fi.poznom, fi.codobiectinf, fi.codgeneric, fi.cantinsup,
          fi.umsec, fi.pret, fi.dimt, fi.complex, fi.material, fi.codfisapro, fi.umdimt, fi.consumator, fi.masa
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
        inner join fisainf fi on fs.codfisasup = fi.codfisapro
   where ft.codfisateh = RecId and nvl(fi.codfisasup, 0) = 0 );

  insert into tmp_fisasupmat (codfisasup, codproiectnod, codobiectnod, identificator, datadocumentatie,arhiva
    , obs, proiectant, nivel, blocat)
  (select fs.codfisasup, fs.codproiectnod, fs.codobiectnod, fs.identificator, fs.datadocumentatie, fs.arhiva
    , fs.obs, fs.proiectant, fs.nivel, fs.blocat
   from fisateh ft
        inner join fisasup fs on ft.codfisasup = fs.codfisasup
        inner join fisainf fi on fs.codfisasup = fi.codfisasup
   where ft.codfisateh = RecId and fi.complex = 2);
  commit;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aCod number(20);
aCodProiect number(20);
aCodFisaSup number(20);
aTip number(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodFisateh into RecId from tmp_fisateh;
    SELECT CodProiect INTO aCodProiect FROM Tmp_Proiect;
    select CodFisaSup into aCOdFisaSup from tmp_fisasup;
    select nvl(FI.Complex, 0) into aTip
    from fisateh ft
         inner join fisasup fs on ft.codfisasup = fs.codfisasup
         inner join fisainf fi on fs.codfisasup = fi.codfisapro
    where nvl(fi.codfisasup, 0) &gt; 0;

    update FisaTeh set
      (codfisasup, Intocmita, DataFisa, Finalizata, Blocata) =
      (select CodFisaSup, Intocmita, DataFisa, Finalizata, Blocata from Tmp_Fisateh) where CodFisaTeh = RecId;


    UPDATE Proiect SET ( CodVersiune,
                         CodObiectProd,
                         Versiune,
                         Procesare)
              = ( SELECT CodVersiune,
                         CodObiectProd,
                         Versiune,
                         case
                           when Den_Procesare = &apos;Agregare&apos; then 1
                           else 2
                         end Procesare
                 FROM TMP_PROIECT )
                 WHERE CodProiect = aCodProiect;

    update fisasup set (codfisasup, codproiectnod, codobiectnod, identificator, obs) =
    (select codfisasup, codproiectnod, codobiectnod, identificator, obs from tmp_fisasup) where codfisasup = aCodFisaSup;

    delete from traseu t where
    exists (select fs.codfisasup from fisasup fs where fs.codfisasup = t.codfisasup and fs.Codfisasup = aCodFisaSup)
    and
    not exists (select tmp_t.codtraseu from tmp_traseu tmp_t where tmp_t.codtraseu = t.codtraseu);

    for v_rec in (select * from tmp_traseu order by codtraseu) loop
      if v_rec.codtraseu &gt; 0 then
        update traseu
        set
          INDEXLOCAL = v_rec.indexlocal,
          POZT       = v_Rec.Pozt,
          EXECUTANT  = v_Rec.Executant,
          CLASATEH   = v_Rec.Executant
        where codtraseu = v_rec.codtraseu;
      else
        select seq_traseu_codtraseu.nextval into aCod from dual;
        update tmp_fisaman set codtraseu = aCod where codtraseu = v_rec.codtraseu;
        update tmp_fisarez set codtraseu = aCod where codtraseu = v_rec.codtraseu;
        insert into traseu (CODTRASEU,
                      CODFISASUP,
                      INDEXLOCAL,
                      POZT,
                      EXECUTANT,
                      CLASATEH)
        values (aCod,
                v_rec.CODFISASUP,
                v_rec.INDEXLOCAL,
                v_rec.POZT,
                v_rec.EXECUTANT,
                v_rec.CLASATEH);
      end if;
    end loop;

    /*if aTip = 0 then
      delete proiectnod pn where exists (select fs.codfisasup from fisasup fs where pn.codproiectnod = fs.codfisasup and
      exists (select fi.codfisainf from
    else

    end if;*/


  ELSE  -- INSERT

  SELECT seq_proiect_codproiect.NextVal INTO RecId FROM DUAL;
  INSERT INTO proiect ( CodProiect,
                        CodVersiune,
                        CodObiectProd,
                        Versiune,
                        Intocmita,
                        DataProiect,
                        Clasa,
                        Procesare,
                        Complex,
                        activ,
                        Finalizat,
                        Blocat )
               ( SELECT RecId,
                        CodVersiune,
                        CodObiectProd,
                        Versiune,
                        Intocmita,
                        DataProiect,
                        Clasa,
                        case
                           when Den_Procesare = &apos;Agregare&apos; then 1
                           else 2
                         end Procesare,
                        Complex,
                        activ,
                        Finalizat,
                        Blocat
                FROM TMP_PROIECT ) ;

  for v_rec in (select codproiectnod from tmp_proiectnod) loop
    select Seq_Proiectnod_Codproiectnod.Nextval into aCod from dual;
    update tmp_proiectnod set codproiectnod = aCod where codproiectnod = v_rec.codproiectnod;
    update tmp_fisasup set codproiectnod = aCod where codproiectnod = v_rec.codproiectnod;
  end loop;
  INSERT INTO PROIECTNOD ( CODPROIECTNOD,
                           CODPROIECT,
                           CANT,
                           NODORIGINAL )
                  ( SELECT CODPROIECTNOD,
                           RecId,
                           CANT,
                           NODORIGINAL
                    FROM TMP_PROIECTNOD);

  for v_rec in (select codfisasup from tmp_fisasup) loop
    select seq_fisasup_codfisasup.nextval into aCod from dual;
    update tmp_fisasup set codfisasup = aCod where codfisasup = v_rec.codfisasup;
    update tmp_fisainf set codfisasup = aCod where codfisasup = v_rec.codfisasup;
    update tmp_fisainf set codfisapro = aCod where codfisapro = v_rec.codfisasup;
    update tmp_fisainfmat set codfisapro = aCod where codfisapro = v_rec.codfisasup;
    update tmp_traseu set codfisasup = aCod where codfisasup = v_rec.codfisasup;
  end loop;
  INSERT INTO FISASUP ( CODFISASUP,
                        CODPROIECTNOD,
                        CODOBIECTNOD,
                        IDENTIFICATOR,
                        DATADOCUMENTATIE,
                        ARHIVA,
                        OBS,
                        PROIECTANT,
                        NIVEL )
                (SELECT CODFISASUP,
                        CODPROIECTNOD,
                        CODOBIECTNOD,
                        IDENTIFICATOR,
                        DATADOCUMENTATIE,
                        ARHIVA,
                        OBS,
                        PROIECTANT,
                        NIVEL
                  FROM TMP_FISASUP);

  insert into tmp_fisainf (CODFISAINF,
                       CODFISASUP,
                       POZNOM,
                       CODOBIECTINF,
                       CODGENERIC,
                       CANTINSUP,
                       UMSEC,
                       PRET,
                       DIMT,
                       COMPLEX,
                       MATERIAL,
                       CODFISAPRO,
                       UMDIMT,
                       CONSUMATOR,
                       MASA)
              (select CODFISAINF,
                       CODFISASUP,
                       POZNOM,
                       CODOBIECTINF,
                       CODGENERIC,
                       CANTINSUP,
                       UMSEC,
                       PRET,
                       DIMT,
                       COMPLEX,
                       MATERIAL,
                       CODFISAPRO,
                       UMDIMT,
                       CONSUMATOR,
                       MASA
                 from tmp_fisainfmat);

  INSERT INTO FISAINF (CODFISAINF,
                       CODFISASUP,
                       POZNOM,
                       CODOBIECTINF,
                       CODGENERIC,
                       CANTINSUP,
                       UMSEC,
                       PRET,
                       DIMT,
                       COMPLEX,
                       MATERIAL,
                       CODFISAPRO,
                       UMDIMT,
                       CONSUMATOR,
                       MASA)
               (SELECT SEQ_FISAINF_CODFISAINF.NEXTVAL,
                       CODFISASUP,
                       POZNOM,
                       CODOBIECTINF,
                       CODGENERIC,
                       CANTINSUP,
                       UMSEC,
                       PRET,
                       DIMT,
                       COMPLEX,
                       MATERIAL,
                       CODFISAPRO,
                       UMDIMT,
                       CONSUMATOR,
                       MASA
                 FROM TMP_FISAINF);

  INSERT INTO TRASEU (CODTRASEU,
                      CODFISASUP,
                      INDEXLOCAL,
                      POZT,
                      EXECUTANT,
                      CLASATEH)
              (SELECT SEQ_TRASEU_CODTRASEU.NEXTVAL,
                      CODFISASUP,
                      INDEXLOCAL,
                      POZT,
                      EXECUTANT,
                      CLASATEH
                FROM TMP_TRASEU);

END IF;
NotifyModif(Operation, RecId, &apos;FISATEH&apos;);
COMMIT;
end;


end pkg_fisateh;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FORMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D70BF6AC063CFA5F1858223613CE7B35EE93B65</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_formatii IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODFORMATIE INTO Tmp FROM FORMATII WHERE CODFORMATIE = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM FORMATII1 WHERE CodFormatie = RecId ;
  DELETE FROM OREPONTAJ WHERE CodFormatie = RecId ;
  DELETE FROM FORMATII WHERE CodFormatie = RecId ;
  NotifyModif(2, RecId, &apos;FORMATII&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_FORMATII FIELDS( CodFormatie ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_Formatii ( CodFormatie, Den_Formatie, Simbol,codgest )
  SELECT CodFormatie, Den_Formatie, Simbol,codgest
  FROM Formatii
  WHERE CodFormatie = RecId;

  INSERT INTO TMP_Formatii1 ( CodFormatie1, CodFormatie, LocMunca, IndexLocal, Den_LocMunca )
  SELECT f1.CodFormatie1, f1.CodFormatie, f1.LocMunca, Row_Number() OVER (ORDER BY f1.CodFormatie1 ASC), lm.denumire
  FROM Formatii1 f1 INNER JOIN locmunca lm ON lm.codloc = f1.locmunca
  WHERE f1.CodFormatie = RecId;

  INSERT INTO TMP_OrePontaj (CODFORMATIE, CODPERS, ORE, SALAR, AN, LUNA, NumePrenume)
  SELECT o.CODFORMATIE, o.CODPERS, o.ORE, o.SALAR, o.AN, o.LUNA, p.Nume||&apos;;&apos;||p.Prenume
  from OREPONTAJ o inner join npers p on p.codpers = o.codpers
  WHERE o.CodFormatie = RecId and o.An*12 + o.luna = pkg_globals.AnLunaLucru ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodFormatie INTO RecId FROM TMP_Formatii;

    UPDATE FORMATII
    SET ( Den_Formatie,simbol,codgest ) = ( SELECT Den_Formatie, Simbol,codgest FROM TMP_Formatii )
    WHERE CodFormatie = RecId;

    DELETE FROM FORMATII1
    WHERE CodFormatie = RecID
      AND CodFormatie1 NOT IN (SELECT CodFormatie1 FROM TMP_FORMATII1);

    FOR v_rec IN (SELECT * FROM TMP_FORMATII1 ORDER BY IndexLocal) LOOP
      IF NVL(v_rec.CodFormatie1, 0) &gt; 0 THEN
        UPDATE FORMATII1
        SET LOCMUNCA = v_rec.LocMunca
        WHERE CodFormatie1 = v_rec.CodFormatie1;
      ELSE
        INSERT INTO FORMATII1 (CODFORMATIE1, CODFORMATIE, LOCMUNCA)
        VALUES (seq_Formatii1_CodFormatie1.nextval, RecId, v_Rec.LocMunca);
      END IF;
    END LOOP;

    DELETE FROM OREPONTAJ
    WHERE CodFormatie = RecID and An*12 + luna = pkg_globals.AnLunaLucru
      AND CodPERS NOT IN (SELECT CodPers FROM TMP_OREPONTAJ);

    FOR v_rec IN (SELECT * FROM TMP_OREPONTAJ) LOOP
      IF NVL(v_rec.An, 0) &gt; 0 THEN
        UPDATE OREPONTAJ
        SET SALAR = v_rec.SALAR, ORE = v_rec.ore
        WHERE CodFormatie = v_rec.CodFormatie and CodPers = v_rec.CodPers and An*12 + luna = pkg_globals.AnLunaLucru ;
      ELSE
        INSERT INTO OREPONTAJ (CODFORMATIE, CODPERS, ORE, SALAR, AN, LUNA)
        VALUES (RecId, v_Rec.CodPers, v_rec.Ore, v_rec.Salar, pkg_globals.GetAnLucru, pkg_globals.GetLunaLucru);
      END IF;
    END LOOP;

  ELSE  -- INSERT

    SELECT SEQ_FORMATII_CODFORMATIE.NextVal INTO RecId FROM DUAL;

    INSERT INTO  Formatii ( CodFormatie, Den_Formatie, simbol,codgest )
    SELECT  RecId, Den_Formatie, Simbol,codgest
    FROM TMP_Formatii;

    INSERT INTO FORMATII1 (CODFORMATIE1, CODFORMATIE, LOCMUNCA)
    SELECT seq_Formatii1_CodFormatie1.nextval, RecId, LocMunca
    FROM (SELECT LocMunca FROM TMP_Formatii1 ORDER BY IndexLOcal);

    INSERT INTO OREPONTAJ (CODFORMATIE, CODPERS, ORE, SALAR, AN, LUNA)
    SELECT RecId, CodPers, Ore, Salar, pkg_globals.GetAnLucru, pkg_globals.GetLunaLucru
    FROM Tmp_Orepontaj;

  END IF;
  NotifyModif(Operation, RecId, &apos;FORMATII&apos;);

  COMMIT;
END;
end PKG_FORMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FORMATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F10A884536E6C1FD16195588931F72581F50881E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_formatori IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodFORMATOR INTO Tmp FROM FORMATORI WHERE CodFORMATOR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM FORMATORI WHERE CodFORMATOR = RecId ;
  NotifyModif(2, RecId, &apos;FORMATORI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_FORMATORI FIELDS( CodFORMATOR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master FORMATORI
  INSERT INTO  TMP_FORMATORI ( CodFORMATOR,den_FORMATOR, EMAIL, CodPers, Telefon )
    ( SELECT CodFORMATOR,Den_FORMATOR,EMAIL, CodPers, Telefon
      FROM FORMATORI WHERE CodFORMATOR = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
-- Master FORMATORI
    SELECT CodFORMATOR INTO RecId FROM TMP_FORMATORI;

    UPDATE FORMATORI
    SET ( Den_FORMATOR, EMAIL, CodPers, Telefon )
      = ( SELECT Den_FORMATOR,EMAIL, CodPers, Telefon FROM TMP_FORMATORI )
    WHERE CodFORMATOR = RecId ;

  ELSE  -- INSERT
-- Master FORMATORI
    SELECT seq_FORMATORI_CodFORMATOR.NextVal INTO RecId FROM DUAL;

    INSERT INTO  FORMATORI ( CodFORMATOR,Den_FORMATOR, EMAIL, CodPers, Telefon )
                           ( SELECT  RecId ,Den_FORMATOR, EMAIL, CodPers, Telefon
                             FROM TMP_FORMATORI  ) ;
  END IF;

  NotifyModif(Operation, RecId, &apos;FORMATORI&apos;);
  COMMIT;

END;



END PKG_FORMATORI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUNCTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57AAF02318D1E2FDF4D3BDD27D62D6DCCCFFAE13</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_functii IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodFunctie INTO Tmp FROM FUNCTII WHERE CodFunctie = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM FUNCTII1 WHERE CodFunctie = RecId ;
  DELETE FROM FUNCTII  WHERE CodFunctie = RecId ;
  NotifyModif(2, RecId, &apos;FUNCTII&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_FUNCTII FIELDS( CodFunctie ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master CURSURI
  INSERT INTO  TMP_FUNCTII ( CodFunctie, Denumire, CodExtern )
    ( SELECT CodFunctie, Denumire, CodExtern
    FROM FUNCTII WHERE CodFunctie = RecId ) ;

  INSERT INTO  TMP_FUNCTII1 ( CodFunctie1, CodFunctie,IndexLocal,CodCurs, CodTema )
    ( SELECT CodFunctie1, CodFunctie,IndexLocal,CodCurs, CodTema
      FROM FUNCTII1 WHERE CodFunctie = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodFunctie INTO RecId FROM TMP_FUNCTII;

    UPDATE FUNCTII SET ( Denumire )
                       = ( SELECT Denumire FROM TMP_FUNCTII )
    WHERE CodFunctie = RecId ;

    DELETE FROM FUNCTII1 where CodFunctie = RecId and CodFunctie1 not in (Select CodFunctie1 from TMP_FUNCTII1);
    FOR v_rec IN ( SELECT * FROM TMP_FUNCTII1 WHERE CodFunctie1 &gt; 0 ) LOOP
       UPDATE FUNCTII1
       SET
            INDEXLOCAL  = V_REC.INDEXLOCAL,
            CODCURS     = V_REC.CODCURS,
            CODTEMA     = V_REC.CODTEMA
       WHERE CodFunctie1  = v_rec.CodFunctie1;
    END LOOP;

    INSERT INTO FUNCTII1
    ( CodFunctie1, CodFunctie, IndexLocal,CodCurs, CodTema)
    SELECT SEQ_FUNCTII1_CodFunctie1.Nextval , RecId , IndexLocal, CodCurs, CodTema
    FROM TMP_FUNCTII1 WHERE CodFunctie1 &lt; 0;


  ELSE  -- INSERT

    SELECT Seq_FUNCTII_CodFunctie.NextVal INTO RecId FROM DUAL;

    INSERT INTO  FUNCTII ( CodFunctie, Denumire, CodExtern )
              ( SELECT  RecId , Denumire, CodExtern
                FROM Tmp_FUNCTII ) ;

    INSERT INTO FUNCTII1
    ( CodFunctie1, CodFunctie, IndexLocal,CodCurs, CodTema)
    SELECT SEQ_FUNCTII1_CodFunctie1.Nextval , RecId , IndexLocal, CodCurs, CodTema
    FROM TMP_FUNCTII1;

  END IF;
  NotifyModif(Operation, RecId, &apos;FUNCTII&apos;);
  COMMIT;

END;



END PKG_FUNCTII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF4D2C16CBCEEC66E72D3375ADF1A9B724A95CAC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FUZART IS

FUNCTION GET_CODEXTERN(art IN NUMBER) RETURN VARCHAR2 IS
  codext VARCHAR2(20);
BEGIN
  -- Functioneaza doar in cazul articolelor fara atribute
  -- sau cu atribute nedefinite unde coresopondenta Aticol:Obiect este 1:1
  SELECT Coalesce(CodExtern, &apos;..nedefinit..&apos;) INTO codext FROM NARTOBJ WHERE CodArticol = art;
  RETURN codext;
  EXCEPTION WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
END;

FUNCTION GET_PRODUCATOR(art IN NUMBER) RETURN VARCHAR2 IS
  prod VARCHAR2(50);
BEGIN
  SELECT Coalesce(NP.Den_Part, &apos;..nedefinit..&apos;) INTO prod FROM NPART NP
  LEFT OUTER JOIN NARTOBJ NAO ON NAO.CodProducator = NP.CodPart
  WHERE NAO.CodArticol = art;
  RETURN prod;
  EXCEPTION WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
END;

FUNCTION VER_ARTSERV(artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER IS
  tip_init VARCHAR2(1);
  tip_fin VARCHAR2(1);
BEGIN
  SELECT TipArticol INTO tip_init FROM NART WHERE CodArticol = artinit;
  SELECT TipArticol INTO tip_fin  FROM NART WHERE CodArticol = artfin;
  IF tip_init &lt;&gt; tip_fin THEN RETURN 1; ELSE RETURN 0; END IF;
EXCEPTION
  WHEN OTHERS THEN RETURN 1;
END;

FUNCTION VER_TIPSERIE(artinit IN NUMBER, artfin NUMBER) RETURN NUMBER IS
  tip_init NUMBER(1);
  tip_fin NUMBER(1);
BEGIN
  -- NART
  -- TipSerie = 0 -&gt; articol fara serie
  -- TipSerie = 1 -&gt; articol cu serie pe bucata
  -- TipSerie = 2 -&gt; articol cu serie pe lot
  SELECT Coalesce(TipSerie, 0) INTO tip_init FROM NART WHERE CodArticol = artinit;
  SELECT Coalesce(TipSerie, 0) INTO tip_fin  FROM NART WHERE CodArticol = artfin;
  IF tip_init = 0 AND tip_fin = 0 THEN RETURN 0; END IF; -- OK
  IF tip_init = 0 AND tip_fin = 1 THEN RETURN 1; END IF; -- NOT OK
  IF tip_init = 0 AND tip_fin = 2 THEN RETURN 2; END IF; -- NOT OK
  IF tip_init = 1 AND tip_fin = 0 THEN RETURN 0; END IF; -- OK
  IF tip_init = 1 AND tip_fin = 1 THEN RETURN 0; END IF; -- OK
  IF tip_init = 1 AND tip_fin = 2 THEN RETURN 3; END IF; -- OK :1:2:3
  IF tip_init = 2 AND tip_fin = 0 THEN RETURN 0; END IF; -- OK
  IF tip_init = 2 AND tip_fin = 1 THEN RETURN 4; END IF; -- NOT OK
  IF tip_init = 2 AND tip_fin = 2 THEN RETURN 0; END IF; -- OK
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION VER_UM(artinit IN NUMBER, artfin NUMBER) RETURN NUMBER IS
  UM_init   NUMBER(20);
  UM1_init  NUMBER(20);
  UM2_init  NUMBER(20);
  UM_fin    NUMBER(20);
  UM1_fin   NUMBER(20);
  UM2_fin   NUMBER(20);
BEGIN
  -- NART
  SELECT Coalesce(UM,0), Coalesce(UM1,0), Coalesce(UM2,0) INTO UM_init, UM1_init, UM2_init FROM NART WHERE CodArticol = artinit;
  SELECT Coalesce(UM,0), Coalesce(UM1,0), Coalesce(UM2,0) INTO UM_fin,  UM1_fin,  UM2_fin  FROM NART WHERE CodArticol = artfin;

  IF    UM_init  &lt;&gt; UM_fin  THEN RETURN 1;
  ELSIF UM1_init &lt;&gt; UM1_fin THEN RETURN 2;
  ELSIF UM2_init &lt;&gt; UM2_fin THEN RETURN 3;
  ELSE  RETURN 0;
  END IF;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

-- FUZIONARE OBIECTE --
PROCEDURE FUZ_OBJ(co_init IN NUMBER, co_fin IN NUMBER) IS
  TYPE   t_urec IS RECORD(fraza_sql VARCHAR2(3000));
  TYPE   t_utab IS TABLE OF t_urec;
  t_upd  t_utab;
  t_del  t_utab;

  TYPE   t_pstab IS TABLE OF PMPLUNA%ROWTYPE INDEX BY PLS_INTEGER;
  t_pmps t_pstab;

  TYPE   t_patab IS TABLE OF PMP_ALL_LUNA%ROWTYPE INDEX BY PLS_INTEGER;
  t_pmpa t_patab;

  i      PLS_INTEGER;
BEGIN
  --LISTA COLOANE CODOBIECT -- trebuiesc verificate manual caci exista cazuri naspa cum ar fi CODOBIECTTRAD care e cheie primara pentru alta tabela si nu poate fi facut update
  --SELECT STRING_AGG(DISTINCT &apos;&apos;&apos;&apos;||C.COLUMN_NAME||&apos;&apos;&apos;&apos;)
  --FROM USER_TABLES T INNER JOIN USER_TAB_COLUMNS C ON C.TABLE_NAME = T.TABLE_NAME
  --WHERE T.TEMPORARY = &apos;N&apos;
  --  AND C.COLUMN_NAME LIKE &apos;CODOBIECT%&apos;
  --  AND C.COLUMN_NAME NOT IN (&apos;CODOBIECT1&apos;, &apos;CODOBIECTTRAD&apos;)
  --  AND T.TABLE_NAME  NOT IN (&apos;NARTOBJ&apos;, &apos;NARTOBJ1&apos;, &apos;PRETM&apos;, &apos;PMPLUNA&apos;, &apos;PMP_ALL_LUNA&apos;) -- TABELE CARE SE PROCESEAZA DIFERIT
  --  AND SubStr(T.TABLE_NAME,1,8) &lt;&gt; &apos;MANEVRA_&apos;
  --  AND SubStr(T.TABLE_NAME,1,4) &lt;&gt; &apos;TMP_&apos;

  SELECT &apos;DELETE nartcli WHERE RowId = &apos;&apos;&apos;||artcli_id||&apos;&apos;&apos;&apos;
  BULK COLLECT INTO t_del
  FROM (
    SELECT ROWID artcli_id, codobiect,  Count(1) OVER (PARTITION BY codpart) NrInreg
    FROM nartcli
    WHERE codobiect IN (co_init, co_fin)
  )
  WHERE NrInreg &gt; 1 AND codobiect = co_init;

  IF t_del.FIRST IS NOT NULL THEN
    FOR i IN t_del.FIRST..t_del.LAST LOOP
      EXECUTE IMMEDIATE t_del(i).fraza_sql;
    END LOOP;
  END IF;

  -- golesc NESTED TABLE pt orice eventualitate
  t_del := t_utab(NULL);

  SELECT &apos;DELETE nartobjtrad WHERE RowId = &apos;&apos;&apos;||objtradt_id||&apos;&apos;&apos;&apos; -- sterg traducerile de obiecte pet care se pot creea duplicate
  BULK COLLECT INTO t_del
  FROM (
    SELECT ROWID objtradt_id, CodObiect, Count(1) OVER (PARTITION BY codlimba) NrInreg
    FROM nartobjtrad
    WHERE codobiect IN (co_init, co_fin)
  )
  WHERE NrInreg &gt; 1 AND codobiect = co_init;

  IF t_del.FIRST IS NOT NULL THEN
    FOR i IN t_del.FIRST..t_del.LAST LOOP
      EXECUTE IMMEDIATE t_del(i).fraza_sql;
    END LOOP;
  END IF;

  -- golesc NESTED TABLE pt orice eventualitate
  t_del := t_utab(NULL);

  DELETE nechiv
  WHERE codobiect = co_init AND EXISTS (SELECT codechiv FROM nechiv WHERE codobiect = co_fin);

  SELECT &apos;UPDATE &apos;||T.TABLE_NAME||&apos; SET &apos;||C.COLUMN_NAME||&apos; = :1 WHERE &apos;||C.COLUMN_NAME||&apos; = :2&apos;
  BULK COLLECT INTO t_upd
  FROM USER_TABLES T INNER JOIN USER_TAB_COLUMNS C ON C.TABLE_NAME = T.TABLE_NAME
  WHERE T.TEMPORARY = &apos;N&apos;
    AND C.COLUMN_NAME IN (&apos;CODOBIECT&apos;,&apos;CODOBIECTASOC&apos;,&apos;CODOBIECTASOCSEC&apos;,&apos;CODOBIECTGENERIC&apos;,&apos;CODOBIECTINF&apos;,&apos;CODOBIECTNOD&apos;,&apos;CODOBIECTOPT&apos;,&apos;CODOBIECTORIG&apos;,&apos;CODOBIECTPROD&apos;,&apos;CODOBIECTRETURN&apos;,&apos;CODOBIECTSEC&apos;)
    AND T.TABLE_NAME NOT IN (&apos;NARTOBJ&apos;, &apos;NARTOBJIMP&apos;, &apos;NARTOBJ1&apos;, &apos;NATROBJ&apos;, &apos;NARTOBJATR&apos;, &apos;NARTOBJEXT&apos;, &apos;NARTOBJSUBUNIT&apos;, &apos;PRETM&apos;, &apos;PMPLUNA&apos;, &apos;PMP_ALL_LUNA&apos;) -- TABELE CARE SE PROCESEZA DIFERIT
    AND SubStr(T.TABLE_NAME,1,8) &lt;&gt; &apos;MANEVRA_&apos;
    AND SubStr(T.TABLE_NAME,1,4) &lt;&gt; &apos;TMP_&apos;
    AND C.DATA_TYPE = &apos;NUMBER&apos;
    --AND T.NUM_ROWS &gt; 0
  ORDER BY T.TABLE_NAME, C.COLUMN_NAME;
  --STEF LA NAIBA nu ma pot baza pe NUM_ROW
  --Nota ORACLE -&gt; ALL_TABLES -&gt; NUM_ROWS* Number of rows in the table:
  --Columns marked with an asterisk (*) are populated only if you collect statistics on the table with the ANALYZE statement or the DBMS_STATS package.
  
  --caz particular pt inventare
  --inainte de a face update-ul preiau inventarele care contin ambele obiecte implicate
  delete tmp_manevra;
  execute immediate &apos;insert into tmp_manevra(codunic) &apos;||chr(13)||
                    &apos;select distinct i.codinventar &apos;||chr(13)||
                    &apos;from inventar i &apos;||chr(13)||
                    &apos;where exists (select x1.codinventar1 from inventar1 x1 where x1.codinventar = i.codinventar and x1.codobiect = &apos;||co_init||&apos;)&apos;||chr(13)||
                    &apos;      and exists (select x1.codinventar1 from inventar1 x1 where x1.codinventar = i.codinventar and x1.codobiect = &apos;||co_fin||&apos;)&apos;;
  
  IF t_upd.FIRST IS NOT NULL THEN
    FOR i IN t_upd.FIRST..t_upd.LAST LOOP
      EXECUTE IMMEDIATE t_upd(i).fraza_sql USING co_fin, co_init;
    END LOOP;
  END IF;
  
  -- dupa inlocuire procesez inventarele implicate
  for v_Rec in (
    select count(*), i1.codobiect, coalesce(i1.codserie,0) codserie, i1.expirare, coalesce(i1.codlocatie,0) codlocatie, i1.codinventar, min(i1.codinventar1) codinventar1
    from inventar i
         inner join inventar1 i1 on i1.codinventar = i.codinventar
         inner join tmp_manevra t on t.codunic = i.codinventar
    group by i1.codobiect, coalesce(i1.codserie,0), i1.expirare, coalesce(i1.codlocatie,0), i1.codinventar
    having count(*) &gt; 1
  ) loop
    for v_tmp in (select * from inventar1 
                  where codobiect = v_rec.codobiect 
                        and codinventar = v_Rec.Codinventar
                        and coalesce(codserie,0) = v_rec.codserie
                        and coalesce(expirare,to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;)) = coalesce(v_rec.expirare,to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;))
                        and coalesce(codlocatie,0) = v_rec.codlocatie
                        and codinventar1 &lt;&gt; v_rec.codinventar1
                 ) loop
      update inventstoc set codinventar1 = v_rec.codinventar1 where codinventar1 = v_tmp.codinventar1;
      update inventrez set codinventar1 = v_rec.codinventar1 where codinventar1 = v_tmp.codinventar1;
      update inventar1 
      set 
        scriptic = scriptic + v_tmp.scriptic,
        scripticum1 = scripticum1 + v_tmp.scripticum1,
        scripticum2 = scripticum2 + v_tmp.scripticum2,
        faptic = faptic + v_tmp.faptic,
        fapticum1 = fapticum1 + v_tmp.fapticum1,
        fapticum2 = fapticum2 + v_tmp.fapticum2,
        rezolvat = case when rezolvat = 1 then 1 else v_tmp.rezolvat end
      where codinventar1 = v_rec.codinventar1;
      delete inventar1 where codinventar1 = v_tmp.codinventar1;
    end loop;
  end loop;
  
  -- golesc NESTED TABLE pt orice eventualitate
  t_upd := t_utab(NULL);

  -- stef tabele cu coloana codobiect cu denumire nestandardizata care nu apar in sql-ul anterior
  UPDATE PRODSDV          SET CODGENERIC  = co_fin WHERE CODGENERIC  = co_init;
  UPDATE PRODSDV          SET CODSDV      = co_fin WHERE CODSDV      = co_init;
  UPDATE EURO             SET OBIECT      = co_fin WHERE OBIECT      = co_init;
  UPDATE NPARC1           SET ART         = co_fin WHERE ART         = co_init;
  UPDATE NPARCAUT         SET CODART      = co_fin WHERE CODART      = co_init;
  UPDATE NINTERVENTIIAUTO SET SERVICIU    = co_fin WHERE SERVICIU    = co_init;
  UPDATE NOPER            SET CODSERVICIU = co_fin WHERE CODSERVICIU = co_init;

  -- stef fuzionare articole din constante
  SELECT
    CASE
      WHEN NrInreg &gt; 1
      THEN &apos;DELETE constval WHERE rowid = &apos;&apos;&apos;||constval_id||&apos;&apos;&apos;&apos;
      ELSE &apos;UPDATE constval SET valoare = &apos;&apos;&apos;||To_Char(co_fin)||&apos;&apos;&apos; WHERE rowid = &apos;&apos;&apos;||constval_id||&apos;&apos;&apos;&apos;
    END
  BULK COLLECT INTO t_upd
  FROM (
    SELECT cv.rowid constval_id, cv.valoare, Count(1) OVER (PARTITION BY c1.codconst1, cl.anstart, cl.lunastart) NrInreg
    FROM constluna cl
      INNER JOIN constval cv ON cv.codconstluna = cl.codconstluna
      INNER join const1 c1 ON c1.codconst1 = cl.codconst1
    WHERE c1.tip IN (22, 43)
      AND cv.valoare IN ( To_Char(co_init), To_Char(co_fin) )
  )
  WHERE valoare = To_Char(co_init);

  IF t_upd.FIRST IS NOT NULL THEN
    FOR i IN t_upd.FIRST..t_upd.LAST LOOP
      EXECUTE IMMEDIATE t_upd(i).fraza_sql;
    END LOOP;
  END IF;

  -- golesc NESTED TABLE pt orice eventualitate
  t_upd := t_utab(NULL);

  SELECT Min(codpmpluna), co_fin codobiect, codsubunit, Sum(cantintr), Sum(valintr), Sum(rest), an, luna, Sum(valvaluta)
  BULK COLLECT INTO t_pmps
  FROM PMPLUNA
  WHERE CODOBIECT IN (co_init, co_fin)
  GROUP BY codsubunit, an, luna;

  IF t_pmps.FIRST IS NOT NULL THEN
    DELETE PMPLUNA WHERE CODOBIECT IN (co_init, co_fin);
    FORALL i IN t_pmps.first .. t_pmps.last INSERT INTO PMPLUNA VALUES t_pmps(i);
  END IF;

  -- golesc NESTED TABLE pt orice eventualitate
  SELECT * BULK COLLECT INTO t_pmps FROM PMPLUNA WHERE 1 = 2;

  SELECT Min(codpmp_all_luna), co_fin codobiect, Sum(cantintr), Sum(valintr), Sum(rest), an, luna, Sum(valvaluta)
  BULK COLLECT INTO t_pmpa
  FROM PMP_ALL_LUNA
  WHERE CODOBIECT IN (co_init, co_fin)
  GROUP BY an, luna;

  IF t_pmpa.FIRST IS NOT NULL THEN
    DELETE PMP_ALL_LUNA WHERE CODOBIECT IN (co_init, co_fin);
    FORALL i IN t_pmpa.first .. t_pmpa.last INSERT INTO PMP_ALL_LUNA VALUES t_pmpa(i);
  END IF;

  -- golesc NESTED TABLE pt orice eventualitate
  SELECT * BULK COLLECT INTO t_pmpa FROM PMP_ALL_LUNA WHERE 1 = 2;

  -- PRETM: CodObiect
  DELETE FROM PRETM WHERE CodObiect = co_init;
  -- NARTOBJATR: CodObiect
  IF pkg_list_struct.TmpExists(&apos;NARTOBJATR&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE NARTOBJATR WHERE CODOBIECT = :1&apos; USING co_init;
  END IF;
  -- NARTOBJEXT: CodObiect
  IF pkg_list_struct.TmpExists(&apos;NARTOBJEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE NARTOBJEXT WHERE CODOBIECT = :1&apos; USING co_init;
  END IF;
  -- NATROBJ: CodObiect
  DELETE FROM NATROBJ WHERE CodObiect = co_init;
  -- NATROBJ: CodObiect
  DELETE FROM NARTOBJSUBUNIT WHERE CodObiect = co_init;
  -- NARTOBJ1: CodObiect
  DELETE FROM NARTOBJ1 WHERE CodObiect = co_init;
  -- NARTOBJ: CodObiect, CodArticol
  DELETE FROM NARTOBJIMP WHERE CodObiect = co_init;
  DELETE FROM NARTOBJ WHERE CodObiect = co_init;
END;

-- FUZIONARE ARTICOLE --
FUNCTION FUZ_ART_ATRIB_NEDEF(artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER IS
  co_init NUMBER(20);
  co_fin  NUMBER(20);
BEGIN
  SELECT CodObiect INTO co_init FROM NARTOBJ WHERE CodArticol = artinit;
  SELECT CodObiect INTO co_fin  FROM NARTOBJ WHERE CodArticol = artfin;
  FUZ_OBJ(co_init, co_fin);
  -- NARTDIM: CodArticol
  DELETE FROM NARTDIM WHERE CodArticol = artinit;
  -- NARTIMPLICITE: CodArticol
  DELETE FROM NARTIMPLICITE WHERE CodArticol = artinit;
  -- NARTATR: CodArticol
  UPDATE NARTATR SET CodArticol = artfin WHERE CodArticol = artinit;
  -- NART1: CodArticol
  DELETE FROM NART1 WHERE CodArticol = artinit;
  -- NART: CodArticol
  DELETE FROM NART WHERE CodArticol = artinit;

  COMMIT;
  RETURN 1;
END;

FUNCTION FUZ_ART_ATRIB_DEF(artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER IS
  co_init NUMBER(20);
  co_fin NUMBER(20);
BEGIN
  SELECT Coalesce(CodObiect, 0) INTO co_init FROM NARTOBJ WHERE CodArticol = artinit;
  SELECT Coalesce(CodObiect, 0) INTO co_fin  FROM NARTOBJ WHERE CodArticol = artfin;
  -- TO BE CONTINUED...
  DELETE FROM NARTOBJIMP WHERE CodObiect in (select codobiect from nartobj where codarticol = artinit);
  commit;
  RETURN 0;
END;

FUNCTION FUZ_ART_SUB(artinit IN NUMBER, artfin IN NUMBER) RETURN NUMBER IS
  atr_init NUMBER(20);
  atr_fin  NUMBER(20);
  val_init NUMBER(20);
  val_fin  NUMBER(20);
  val_ret  NUMBER(1) := 0;
BEGIN
  -- cazuri:
  -- 1. art. fara atrib. -&gt; art. fara atrib.
  -- 2. art. fara atrib. -&gt;  art. cu atrib. (nedef.)
  -- 3. art. cu atrib. (nedef.) -&gt; art. fara atrib.
  -- 4. art. cu atrib. (nedef.) -&gt; art. cu atrib. (nedef.)
  -- alte cazuri:
  -- 6. art. cu atrib. (def.) -&gt; art. fara atrib.
  -- 7. art. fara atrib. -&gt; art. cu atrib. (def.)
  -- 8. art. cu atribute (def.) -&gt; art. cu atribute (def.)
  SELECT COUNT(*) INTO atr_init FROM NARTATR WHERE CodArticol = artinit;
  SELECT COUNT(*) INTO atr_fin  FROM NARTATR WHERE CodArticol = artfin;
  SELECT COUNT(*) INTO val_init
  FROM
    NART AR
    INNER JOIN NARTATR ARAT ON ARAT.CodArticol = AR.CodArticol
    LEFT OUTER JOIN NATROBJ ATO ON ATO.CodArtAtr = ARAT.CodArtAtr
    LEFT OUTER JOIN NARTOBJ ARO ON ARO.CodObiect = ATO.CodObiect
  WHERE ARAT.CodArticol = artinit;
  SELECT COUNT(*) INTO val_fin
  FROM
    NART AR
    INNER JOIN NARTATR ARAT ON ARAT.CodArticol = AR.CodArticol
    LEFT OUTER JOIN NATROBJ ATO ON ATO.CodArtAtr = ARAT.CodArtAtr
    LEFT OUTER JOIN NARTOBJ ARO ON ARO.CodObiect = ATO.CodObiect
  WHERE AR.CodArticol = artfin;
  -- TODO: nu lasa sa se fuzioneze un aticol de tip serviciu cu unul de tip stoc sau invers!!!
  IF
    (atr_init = 0 AND val_init = 0 AND atr_fin = 0 AND val_fin = 0) OR -- fara atribute -&gt; fara atribute
    (atr_init = 0 AND val_init = 0 AND atr_fin &gt; 0 AND val_fin = 0) OR -- fara atribute -&gt; cu atribute nedefinite
    (atr_init &gt; 0 AND val_init = 0 AND atr_fin = 0 AND val_fin = 0) OR -- cu atribute nedefinite -&gt; fara atribute
    (atr_init &gt; 0 AND val_init = 0 AND atr_fin &gt; 0 AND val_fin = 0)    -- cu atribute nedefinite -&gt; cu atribute nedefinite
  THEN
    val_ret := FUZ_ART_ATRIB_NEDEF(artinit, artfin);
  END IF;

  IF
    (atr_init &gt; 0 AND val_init &gt; 0 AND atr_fin = 0 AND val_fin = 0) OR -- cu atribute   -&gt; fara atribute
    (atr_init = 0 AND val_init = 0 AND atr_fin &gt; 0 AND val_fin &gt; 0) OR -- fara atribute -&gt; cu atribute
    (atr_init &gt; 0 AND val_init &gt; 0 AND atr_fin &gt; 0 AND val_fin &gt; 0)     -- cu atribute   -&gt; cu atribute
  THEN
    -- TODO: nu este inca implementat!!!
    val_ret := FUZ_ART_ATRIB_DEF(artinit, artfin);
  END IF;
    COMMIT;
  RETURN val_ret;
END;

FUNCTION FUZ_ART_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) RETURN NUMBER IS
  atr_init NUMBER(20);
  atr_fin  NUMBER(20);
  val_init NUMBER(20);
  val_fin  NUMBER(20);

  nro_init NUMBER(20);
  nro_fin  NUMBER(20);
  obj_init NUMBER(20);
  obj_fin  NUMBER(20);

  val_ret  NUMBER(1) := 0;
  bAtribOK BOOLEAN;
BEGIN
  FOR reg_fuzart IN (
    SELECT
      FA.ROWID FUZART_ROWID,
      FA.CodArtInit, FA.CodArtFin, FA.CodExternInit, FA.CodExternFin,
      FA.ProdInit, FA.ProdFin,
      NAI.Den_Articol DenArtInit, NAF.Den_Articol DenArtFin
    FROM FUZART FA
      INNER JOIN NART NAI ON NAI.CodArticol = FA.CodArtInit
      INNER JOIN NART NAF ON NAF.CodArticol = FA.CodArtFin
    WHERE FA.UserID = p_userid AND FA.UserStr = p_userstr AND FA.Data IS NULL
  ) LOOP
    SELECT COUNT(*), Min(CodObiect) INTO nro_init, obj_init FROM NARTOBJ WHERE CodArticol = reg_fuzart.CodArtInit;
    SELECT COUNT(*), Min(CodObiect) INTO nro_fin , obj_fin  FROM NARTOBJ WHERE CodArticol = reg_fuzart.CodArtFin;

    SELECT COUNT(*) INTO atr_init FROM NARTATR WHERE CodArticol = reg_fuzart.CodArtInit;
    SELECT COUNT(*) INTO atr_fin  FROM NARTATR WHERE CodArticol = reg_fuzart.CodArtFin;

    SELECT COUNT(*) INTO val_init
    FROM NART AR
      INNER JOIN NARTATR ARAT ON ARAT.CodArticol = AR.CodArticol
      LEFT OUTER JOIN NATROBJ ATO ON ATO.CodArtAtr = ARAT.CodArtAtr
      LEFT OUTER JOIN NARTOBJ ARO ON ARO.CodObiect = ATO.CodObiect
    WHERE ARAT.CodArticol = reg_fuzart.CodArtinit;

    SELECT COUNT(*) INTO val_fin
    FROM NART AR
      INNER JOIN NARTATR ARAT ON ARAT.CodArticol = AR.CodArticol
      LEFT OUTER JOIN NATROBJ ATO ON ATO.CodArtAtr = ARAT.CodArtAtr
      LEFT OUTER JOIN NARTOBJ ARO ON ARO.CodObiect = ATO.CodObiect
    WHERE AR.CodArticol = reg_fuzart.CodArtFin;

    bAtribOK := (atr_init = 0 AND val_init = 0 AND atr_fin = 0 AND val_fin = 0) OR -- fara atribute -&gt; fara atribute
                (atr_init = 0 AND val_init = 0 AND atr_fin &gt; 0 AND val_fin = 0) OR -- fara atribute -&gt; cu atribute nedefinite
                (atr_init &gt; 0 AND val_init = 0 AND atr_fin = 0 AND val_fin = 0) OR -- cu atribute nedefinite -&gt; fara atribute
                (atr_init &gt; 0 AND val_init = 0 AND atr_fin &gt; 0 AND val_fin = 0);   -- cu atribute nedefinite -&gt; cu atribute nedefinite

    IF  bAtribOK
    AND (nro_init = 1 AND nro_fin = 1) -- fuzionarea se face practic la nivel de obiect si deocamdata se face doar pt articolele care au un singur obiect asociat
    THEN
      val_ret := FUZ_ART_SUB(reg_fuzart.CodArtInit, reg_fuzart.CodArtFin);
      UPDATE FUZART SET
        Data = SYSDATE,
        InfoInit = &apos;NumeArt = &apos;||reg_fuzart.DenArtInit||&apos;, Producator = &apos;||reg_fuzart.ProdInit||&apos;, CodExt = &apos;||reg_fuzart.CodExternInit||&apos;, CodObiect = &apos;||obj_init,
        InfoFin  = &apos;NumeArt = &apos;||reg_fuzart.DenArtFin ||&apos;, Producator = &apos;||reg_fuzart.ProdFin ||&apos;, CodExt = &apos;||reg_fuzart.CodExternFin ||&apos;, CodObiect = &apos;||obj_fin
      WHERE ROWID = reg_fuzart.FUZART_ROWID;
    END IF;

  END LOOP;
  COMMIT;
  RETURN val_ret;
END;

FUNCTION FUZ_OBJ_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) RETURN NUMBER IS
  bFuz       BOOLEAN;
  val_ret    NUMBER(1) := 0;
  DenObjInit VARCHAR2(200);
  DenObjFin  VARCHAR2(200);
	aCodArt    number(20);
	Cate       Number;
BEGIN
  FOR reg_fuzart IN (
    SELECT ROWID FUZART_ROWID, FA.CodObjInit, FA.CodObjFin, FA.CodExternInit, FA.CodExternFin, FA.ProdInit, FA.ProdFin
    FROM FUZART FA
    WHERE FA.UserID = p_userid AND FA.UserStr = p_userstr AND FA.Data IS NULL
  ) LOOP
    BEGIN
      bFuz := TRUE;
      SELECT CodArticol, Denumire INTO aCodArt, DenObjInit FROM NARTOBJ WHERE CodObiect = reg_fuzart.CodObjInit;
      SELECT             Denumire INTO          DenObjFin  FROM NARTOBJ WHERE CodObiect = reg_fuzart.CodObjFin;
    EXCEPTION WHEN No_Data_Found THEN
      bFuz := FALSE;
    END;

    IF bFuz THEN
      DELETE FROM nartobjimp WHERE codobiect = reg_fuzart.CodObjInit;
      FUZ_OBJ(reg_fuzart.CodObjInit, reg_fuzart.CodObjFin);
      SELECT Count(1) INTO Cate FROM NartObj WHERE CodArticol = aCodArt;
			IF Cate = 0 THEN
        DELETE FROM NARTDIM WHERE CodArticol = aCodArt;
        DELETE FROM NARTATR WHERE CodArticol = aCodArt;
        DELETE FROM NART1   WHERE CodArticol = aCodArt;
        DELETE FROM NART    WHERE CodArticol = aCodArt;
			END IF;
      val_ret := 1;
      UPDATE FUZART
      SET Data     = SYSDATE,
          InfoInit = &apos;NumeObj = &apos;||DenObjInit,
          InfoFin  = &apos;NumeObj = &apos;||DenObjFin
      WHERE ROWID = reg_fuzart.FUZART_ROWID;
    ELSE -- unul din obiecte nu mai exista
      DELETE FUZART WHERE ROWID = reg_fuzart.FUZART_ROWID;
    END IF;
		COMMIT;
  END LOOP;
  RETURN val_ret;
END;

PROCEDURE CLR_TMP IS
BEGIN
  DELETE FROM TMP_FUZART;
  COMMIT;
END;

PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_FUZART;
  INSERT INTO TMP_FUZART (CodArtInit, CodArtFin, CodObjInit, CodObjFin, CodExternInit, CodExternFin, ProdInit, ProdFin, CODINTERNINIT, CODINTERNFIN)
  SELECT CodArtInit, CodArtFin, Coalesce(CodObjInit,-1), Coalesce(CodObjFin,-1), CodExternInit, CodExternFin, ProdInit, ProdFin, CODINTERNINIT, CODINTERNFIN
  FROM FUZART
  WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  COMMIT;
END;

PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM FUZART WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  INSERT INTO FUZART (CodArtInit, CodArtFin, CodObjInit, CodObjFin, CodExternInit, CodExternFin, ProdInit, ProdFin, UserID, UserStr, Data, CODINTERNINIT, CODINTERNFIN)
  SELECT CodArtInit, CodArtFin, CodObjInit, CodObjFin, CodExternInit, CodExternFin, ProdInit, ProdFin, p_userid, p_userstr, NULL, CODINTERNINIT, CODINTERNFIN
  FROM TMP_FUZART;
  COMMIT;
END;

PROCEDURE SWITCH_FUZ(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_FUZART;
  DELETE FROM FUZART WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  COMMIT;
END;

FUNCTION GET_CRS_GEN_FUZIONARE_CODEXT(p_nr_inreg IN NUMBER DEFAULT 0)
  RETURN sys_refcursor IS
  rf_cur      sys_refcursor;
  aNumarInreg NUMERIC;
BEGIN
  aNumarInreg := case
                  when p_nr_inreg is null then
                    0
                  else
                    p_nr_inreg
                end;
  OPEN rf_cur FOR
    select nobj_sel.codobiect,
--            nobj_sel.codarticol,
--            nobj_sel.denumire,
          nobj_sel.codextern,
          nobj_sel.codintern,
          nobj_sel.codproducator,
          dense_rank() over(partition by nobj_sel.codextern order by codobiect) as ord_fin
      from (select nobj.codobiect,
                  nobj.codarticol,
                  nobj.denumire,
                  nobj.codextern,
                  nobj.codintern,
                  nobj.codproducator,
                  dense_rank() over(order by nobj.codextern) nrl
              from (select obj.codobiect,
                          obj.codarticol,
                          obj.denumire,
                          obj.codextern,
                          obj.codintern,
                          obj.codproducator,
                          count(*) over(partition by obj.codextern) as cnt
                      from nartobj obj
                    where obj.codextern is not null
                      and not exists
                                    (select null
                                              from inventar1 inv1
                                              join inventar inv
                                                on inv.codinventar = inv1.codinventar1
                                            where coalesce(inv.blocat, 0) = 0
                                              and inv1.codobiect = obj.codobiect)
                            ) nobj
            where nobj.cnt &gt; 1) nobj_sel
    WHERE (1 = CASE
            WHEN aNumarInreg = 0 THEN
              1
            ELSE
              0
          END)
        OR (nobj_sel.nrl &lt;= aNumarInreg)
    ORDER BY nobj_sel.codextern, ord_fin;
RETURN rf_cur;
END;

FUNCTION GET_CRS_GEN_FUZIONARE_CODINT(p_nr_inreg IN NUMBER DEFAULT 0)
  RETURN sys_refcursor IS
  rf_cur      sys_refcursor;
  aNumarInreg NUMERIC;
BEGIN
  aNumarInreg := case
                  when p_nr_inreg is null then
                    0
                  else
                    p_nr_inreg
                end;
  OPEN rf_cur FOR
    select nobj_sel.codobiect,
--            nobj_sel.codarticol,
--            nobj_sel.denumire,
          nobj_sel.codextern,
          nobj_sel.codintern,
          nobj_sel.codproducator,
          dense_rank() over(partition by nobj_sel.codintern order by codobiect) as ord_fin
      from (select nobj.codobiect,
                  nobj.codarticol,
                  nobj.denumire,
                  nobj.codextern,
                  nobj.codintern,
                  nobj.codproducator,
                  dense_rank() over(order by nobj.codintern) nrl
              from (select obj.codobiect,
                          obj.codarticol,
                          obj.denumire,
                          obj.codextern,
                          obj.codintern,
                          obj.codproducator,
                          count(*) over(partition by obj.codintern) as cnt
                      from nartobj obj
                    where obj.codintern is not null
                      and not exists
                                        (select null
                                                  from inventar1 inv1
                                                  join inventar inv
                                                    on inv.codinventar = inv1.codinventar1
                                                where coalesce(inv.blocat, 0) = 0
                                                  and inv1.codobiect = obj.codobiect)
                              ) nobj
            where nobj.cnt &gt; 1) nobj_sel
    WHERE (1 = CASE
            WHEN aNumarInreg = 0 THEN
              1
            ELSE
              0
          END)
        OR (nobj_sel.nrl &lt;= aNumarInreg)
    ORDER BY nobj_sel.codintern, ord_fin;
RETURN rf_cur;
END;

PROCEDURE GENERARE_LISTA_FUZIONARE(p_userid            IN NUMBER,
                                    p_userstr           IN VARCHAR2,
                                    p_criteriu_filtrare IN NUMBER DEFAULT 0,
                                    p_nr_inreg          IN NUMBER DEFAULT 0) IS
  data_cursor   sys_refcursor;
  crs_CODOBJ     NARTOBJ.Codobiect%TYPE;
  aCODOBJFIN     NARTOBJ.Codobiect%TYPE;
  crs_PROD          NARTOBJ.Codproducator%TYPE;
  aPRODFIN          NARTOBJ.Codproducator%TYPE;
  crs_CodIntern    NARTOBJ.CODINTERN%TYPE;
  aCODINTFIN       NARTOBJ.CODINTERN%TYPE;
  crs_CodExtern    NARTOBJ.CODEXTERN%TYPE;
  aCODEXTERNFIN NARTOBJ.CODEXTERN%TYPE;
  crs_OrdFin    NUMBER;
BEGIN
  -- 0 - criteriu cod fiscal principal pj
  -- 1 - criteriu codextern pj
  -- 2 - telefon sediu social pj
  case p_criteriu_filtrare
    when 0 then
      data_cursor := GET_CRS_GEN_FUZIONARE_CODEXT(p_nr_inreg);
    when 1 then
      data_cursor := GET_CRS_GEN_FUZIONARE_CODINT(p_nr_inreg);
  END CASE;
  LOOP
    FETCH data_cursor
      INTO crs_CODOBJ, crs_CodExtern, crs_CodIntern, crs_PROD, crs_OrdFin;
    EXIT WHEN data_cursor%notfound;
    IF crs_OrdFin = 1 THEN
      aCODOBJFIN       := crs_CODOBJ;
      aCODEXTERNFIN := crs_CodExtern;
      aCODINTFIN        := crs_CodIntern;
      aPRODFIN            := crs_PROD;
    ELSE
      INSERT INTO FUZART
        (CODARTINIT,
          CODARTFIN,
          CODOBJINIT,
          CODOBJFIN,
          CODEXTERNINIT,
          CODEXTERNFIN,
          CODINTERNINIT,
          CODINTERNFIN,
          PRODINIT,
          PRODFIN,
          USERID,
          USERSTR)
      VALUES
        (0,
          0,
          crs_CODOBJ,
          aCODOBJFIN,
          crs_CodExtern,
          aCODEXTERNFIN,
          crs_CodIntern,
          aCODINTFIN,
          crs_PROD,
          aPRODFIN,
          p_userid,
          p_userstr);
    END IF;
  END LOOP;
  CLOSE data_cursor;
  commit;
END;


END PKG_FUZART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>110E4C6D56920296E8D1450A0382F3D52B315278</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FUZAUTO is

PROCEDURE FUZ_AUTO_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  FOR reg_fuzauto IN (
    SELECT F.CodAutoInit, F.CodAutoFin, AI.Nrinreg AutoIni, AF.Nrinreg AS AutoFin
    FROM FUZAUTO F
      INNER JOIN NPARCAUT AI ON AI.CodNParcAut = F.CodAutoInit
      INNER JOIN NPARCAUT AF ON AF.CodNParcAut = F.CodAutoFin
    WHERE F.UserID = p_userid AND F.UserStr = p_userstr AND F.Data IS NULL
  ) LOOP
    
    MERGE INTO NPARC0 Z 
    USING (select p0.DATABORD as DATABORD, p0.KMBORD as KMBORD, p0.AN as an, p0.LUNA as luna, p0.OBS as obs, p0.CODPERS as codpers, p0.CODFAZ as codfaz, p0.CODCMD as codcmd, p0.COMB as comb      
           from nparc0 p0
           where p0.codnparcaut = reg_fuzauto.codautoinit
          ) N
    ON (Z.DATABORD = N.DATABORD and Z.AN = N.AN AND Z.LUNA = N.LUNA)
    WHEN NOT MATCHED THEN INSERT (CODNPARC0, CODNPARCAUT, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd)
                                  VALUES 
                                 (SEQ_NPARC0_CODNPARC0.NEXTVAL, reg_fuzauto.codautofin, N.databord, N.kmbord, N.an, N.luna, N.obs, n.codpers, n.codfaz, n.comb, n.codcmd);
  
    MERGE INTO NPARC1 Z 
    USING (select Art as art, Cant as cant, pozitie as Pozitie, BordInstal as bordinstal, atentie as atentie, codpart as codpart, montat as Montat, 
                  anotimp as Anotimp, adancime as ADANCIME, latime as LATIME, inaltime as INALTIME, diametru as DIAMETRU, gama as GAMA, runflat as RUNFLAT, 
                  suv as SUV, offroad as OFFROAD, xl as XL, ms as MS, obs as OBS, seria as Seria, dot as DOT, borddem as BordDem, codnirstoc as Codnirstoc, codnirser as Codnirser
           from nparc1
           where cod = reg_fuzauto.codautoinit
          ) N
    ON (Z.art = N.art and Z.cant = N.cant and Z.pozitie = N.pozitie AND Z.bordinstal = N.bordinstal)
    WHEN NOT MATCHED THEN INSERT (CodNParc1, Cod, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, ADANCIME, LATIME, 
                                  INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, MS, OBS, Seria, DOT, BordDem, Codnirstoc, Codnirser)
                                  VALUES 
                                 (seq_nparc1_CodNParc1.Nextval, reg_fuzauto.codautofin, n.Art, n.Cant, n.Pozitie, n.BordInstal, n.atentie,n.codpart,n.Montat, n.Anotimp, n.ADANCIME, n.LATIME, 
                                  n.INALTIME, n.DIAMETRU, n.GAMA, n.RUNFLAT, n.SUV, n.OFFROAD, n.XL, n.MS, n.OBS, n.Seria, n.DOT, n.BordDem, n.Codnirstoc, n.Codnirser);
  
    MERGE INTO NPARC2 Z 
    USING (select Doc as doc, SN as sn, Eliberat as eliberat, Expira as expira, atentie as atentie, Obs as obs, Valoare as valoare, CodIntr1 as codintr1, Denumire as denumire
           from nparc2
           where cod = reg_fuzauto.codautoinit
          ) N
    ON (Z.doc = N.doc and Z.sn = N.sn and Z.eliberat = N.eliberat AND Z.expira = N.expira)
    WHEN NOT MATCHED THEN INSERT (CodNParc2, Cod, Doc, SN, Eliberat, Expira, atentie, Obs, Valoare, CodIntr1, Denumire)
                                  VALUES 
                                 (seq_nparc2_CodNParc2.Nextval, reg_fuzauto.codautofin, n.Doc, n.SN, n.Eliberat, n.Expira, n.atentie, n.Obs, n.Valoare, n.CodIntr1, n.Denumire);
    
    
    MERGE INTO NPARC3 Z 
    USING (select Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare
           from nparc3
           where cod = reg_fuzauto.codautoinit
          ) N
    ON (Z.interventie = N.interventie and Z.valoare = N.valoare and Z.datau = N.datau AND Z.kmu = N.kmu)
    WHEN NOT MATCHED THEN INSERT (CodNParc3, Cod, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare)
                                  VALUES 
                                 (seq_nparc3_CodNParc3.Nextval, reg_fuzauto.codautofin, n.Interventie, n.DataU, n.KmU, n.DataV, n.KmV, n.DataA, n.KMA, n.CodCMD, n.Valoare);
    
    MERGE INTO NPARCCOM Z 
    USING (select CODCOMANDA as codcomanda,CODNPARCAUT as codnparcaut,KMBORD as kmbord,TIPCOMSA as tipcomsa,DATAINCHIDERII as datainchiderii,INMATRROM as inmatrrom,
                  INSPECTIE as inspectie,PIESECLIENT as pieseclient,PROBADRUM as probadrum,  
                  SPALARE as spalare,DZ as dz,NIVREZERVOR as nivrezervor,NRDOSARDAUNE as nrdosardaune,NRAUTREP as nrautrep,DATAAUTREP as DATAAUTREP,
                  KMGARANTIE as KMGARANTIE,DATAGARANTIE as DATAGARANTIE,TIPCOMANDA as TIPCOMANDA,ASIGURATOR as ASIGURATOR,DISTANTA as DISTANTA,
                  ADRESASEDIU as ADRESASEDIU,OBS as OBS,RECOMANDARI as RECOMANDARI,NRORE as NRORE
           from nparccom
           where codnparcaut = reg_fuzauto.codautoinit
          ) N
    ON (Z.codcomanda = N.codcomanda and Z.kmbord = N.kmbord and Z.tipcomanda = N.tipcomanda)
    WHEN NOT MATCHED THEN INSERT (CODNPARCCOM,CODCOMANDA,CODNPARCAUT,KMBORD,TIPCOMSA,DATAINCHIDERII,INMATRROM,INSPECTIE,PIESECLIENT,PROBADRUM,  
                                  SPALARE,DZ,NIVREZERVOR,NRDOSARDAUNE,NRAUTREP,DATAAUTREP,KMGARANTIE,DATAGARANTIE,TIPCOMANDA,ASIGURATOR,DISTANTA,
                                  ADRESASEDIU,OBS,RECOMANDARI,NRORE)
                                  VALUES 
                                 (seq_nparc3_CodNParc3.Nextval,N.CODCOMANDA, reg_fuzauto.codautofin,N.KMBORD,N.TIPCOMSA,N.DATAINCHIDERII,N.INMATRROM,N.INSPECTIE,N.PIESECLIENT,N.PROBADRUM,  
                                  N.SPALARE,N.DZ,N.NIVREZERVOR,N.NRDOSARDAUNE,N.NRAUTREP,N.DATAAUTREP,N.KMGARANTIE,N.DATAGARANTIE,N.TIPCOMANDA,N.ASIGURATOR,N.DISTANTA,
                                  N.ADRESASEDIU,N.OBS,N.RECOMANDARI,N.NRORE);
                                  
    MERGE INTO NPARCG Z 
    USING (select CODGESTINI AS CODGESTINI,CODGEST AS CODGEST,CODCMD AS CODCMD,STATUS AS STATUS,DATA AS DATA
           from nparcG
           where codnparcaut = reg_fuzauto.codautoinit
          ) N
    ON (Z.codcmd = N.codcmd and Z.CODGESTINI = N.CODGESTINI and Z.CODGEST = N.CODGEST)
    WHEN NOT MATCHED THEN INSERT (CODNPARCG,CODNPARCAUT,CODGESTINI,CODGEST,CODCMD,STATUS,DATA)
                                  VALUES 
                                 (SEQ_NPARCG_CODNPARCG.Nextval, reg_fuzauto.codautofin,N.CODGESTINI,N.CODGEST,N.CODCMD,N.STATUS,N.DATA);
    
    UPDATE COMANDA2     SET CODNPARCAUT = reg_fuzauto.codautofin WHERE CODNPARCAUT = reg_fuzauto.codautoinit;
    UPDATE OBLIGPIF     SET CODNPARCAUT = reg_fuzauto.codautofin WHERE CODNPARCAUT = reg_fuzauto.codautoinit;
    UPDATE OFERTA       SET CODNPARCAUT = reg_fuzauto.codautofin WHERE CODNPARCAUT = reg_fuzauto.codautoinit;
    UPDATE TRANSF1      SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE MIFIX1       SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE INTRARI1     SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE RAC_TRANSFER SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE TRANSF       SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE NPARTTR      SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE IESIRI1      SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE NC1          SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE BCAR         SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE UTILAJE2     SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE FAZ          SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE DISTRIB1     SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE IESIRI       SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE CONTRACT1    SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE MIFIX1_SIMULARE SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE RAC_CARS     SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE RAC_AUTO     SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE CHELTAVANS1  SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE INTRARI      SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE SPLITCHELT1  SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    UPDATE RAC_AUTO_CEN SET CODAUTO = reg_fuzauto.codautofin WHERE CODAUTO = reg_fuzauto.codautoinit;
    
    UPDATE TRANSF         SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini;
    UPDATE IESIRI         SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE INTRARI        SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE COMANDA        SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE NDELEGATRETAIL SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE IESIRIRETAIL   SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE BCAR           SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    UPDATE NPARTTR        SET NRTRANSP = REG_FUZAUTO.AUTOFIN WHERE NRTRANSP = reg_fuzauto.autoini; 
    
    PKG_NOM_PARCAUT.SP_DELETERECORD(reg_fuzauto.codautoinit);
    
    UPDATE FUZAUTO
    SET
      Data = SYSDATE,
      InfoInit = &apos;CodAuto = &apos;||TO_CHAR(reg_fuzauto.CodAutoInit)||&apos;, Nr.Inreg. = &apos;||reg_fuzauto.AutoIni,
      InfoFin  = &apos;CodAuto = &apos;||TO_CHAR(reg_fuzauto.CodAutoFin) ||&apos;, Nr.Inreg. = &apos;||reg_fuzauto.AutoFin
    WHERE CodAutoInit = reg_fuzauto.CodAutoInit
      AND CodAutoFin = reg_fuzauto.CodAutoFin
      AND UserID = p_userid
      AND UserStr = p_userstr
      AND Data IS NULL;
  END LOOP;
  COMMIT;
END;

PROCEDURE CLR_TMP IS
BEGIN
  DELETE FROM TMP_FUZAUTO;
  COMMIT;
END;

PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_FUZAUTO;

  INSERT INTO TMP_FUZAUTO (CodAutoInit, CodAutoFin)
  SELECT CodAutoInit, CodAutoFin
  FROM FUZAUTO
  WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;

  COMMIT;
END;

PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM FUZAUTO WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;

  INSERT INTO FUZAUTO (CodAutoInit, CodAutoFin, UserID, UserStr, Data)
  SELECT CodAutoInit, CodAutoFin, p_userid, p_userstr, NULL
  FROM TMP_FUZAUTO;

  COMMIT;
END;    

end PKG_FUZAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5B1C3CC48E86ADF9CE2EA168EE7A335172309FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_fuzgest IS

	FUNCTION GET_SUBUNIT(gest IN NUMBER) RETURN VARCHAR2 IS
	  den_subunitate VARCHAR2(30);
	BEGIN
	  SELECT NVL(NS.Den_Subunit, &apos;..nedefinit..&apos;) INTO den_subunitate
		FROM NSUBUNIT NS
		LEFT OUTER JOIN NGEST NG ON NG.CodSubunit = NS.CodSubunit
		WHERE CodGest = gest;
		RETURN den_subunitate;
		EXCEPTION WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
	END;

	FUNCTION VER_SUBUNIT(gestinit IN NUMBER, gestfin IN NUMBER) RETURN NUMBER IS
	  subunit_init NUMBER(20);
		subunit_fin NUMBER(20);
	BEGIN
	  SELECT NVL(CODSUBUNIT, 0) INTO subunit_init FROM NGEST WHERE CodGest = gestinit;
		SELECT NVL(CODSUBUNIT, 0) INTO subunit_fin FROM NGEST WHERE CodGest = gestfin;
		IF subunit_init = subunit_fin THEN RETURN 0; ELSE RETURN 1; END IF;
		EXCEPTION WHEN OTHERS THEN RETURN 0;
	END;

	FUNCTION FUZ_GEST_SUB(gestinit IN NUMBER, gestfin IN NUMBER) RETURN BOOLEAN IS
  NR NUMBER(20);
  BEGIN

	  --SAVEPOINT FUZGEST;

  	-- EMULARE1
	  UPDATE EMULARE1 SET CodGest = gestfin WHERE CodGest = gestinit;
		-- EURO
		UPDATE EURO SET Gestiune = gestfin WHERE Gestiune = gestinit;
		-- IESIRI1
		UPDATE IESIRI1 SET GestAct = gestfin WHERE GestAct = gestinit;
		-- IESIRI
		UPDATE IESIRI SET CodGestProd = gestfin WHERE CodGestProd = gestinit;
		-- INTRARI1
		UPDATE INTRARI1 SET GestAct = gestfin WHERE GestAct = gestinit;
		-- INTRARI
		UPDATE INTRARI SET CodGestProd = gestfin WHERE CodGestProd = gestinit;
		-- INVENTAR
		UPDATE INVENTAR SET Gestiune = gestfin WHERE Gestiune = gestinit;
		-- INVENTLOC
		-- CodLocatie nu, vezi NLOCATII
		-- JURNAL
		UPDATE JURNAL SET Gest = gestfin WHERE Gest = gestinit;
		-- JURNAL1
		UPDATE JURNAL1 SET Gest = gestfin WHERE Gest = gestinit;
		-- LIVRVAL
		UPDATE LIVRVAL SET Gest = gestfin WHERE Gest = gestinit;
		-- NAGENDA
		DELETE FROM NAGENDA WHERE CodGest = gestinit;
		-- NART
		UPDATE NART SET GestImplicita = gestfin WHERE GestImplicita = gestinit;
		-- NARTIMPLICITE
		-- CodLocatie nu, vezi NLOCATII
		UPDATE NARTIMPLICITE SET GestImplicita = gestfin WHERE GestImplicita = gestinit;
		-- NC1
		UPDATE NC1 SET CodGest = gestfin WHERE CodGest = gestinit;
		-- NCASEMARCAT1
		UPDATE NCASEMARCAT1 SET CodGestiune = gestfin WHERE CodGestiune = gestinit;
		-- NIR
		UPDATE NIR SET Gest = gestfin WHERE Gest = gestinit;
		-- NIRSTOC
		-- CodLocatie nu, vezi NLOCATII
		UPDATE NIRSTOC SET CodGestProd = gestfin WHERE CodGestProd = gestinit;
		-- OBLIGPIF
		UPDATE OBLIGPIF SET CodGest = gestfin WHERE CodGest = gestinit;
		-- STOCINI
		UPDATE STOCINI SET CodGest = gestfin WHERE CodGest = gestinit;

    SELECT NVL(MIN(CODSTOCINI), 0) INTO NR FROM STOCINI WHERE CODGEST = GESTFIN;

    IF NR &gt; 0 THEN
      DELETE FROM STOCINI WHERE CODGEST = GESTFIN AND CODSTOCINI &gt; NR;
    END IF;

		-- STOCVALINI
		UPDATE STOCVALINI SET Gest = gestfin WHERE Gest = gestinit;
		-- STOCVALLUNA
		UPDATE STOCVALLUNA SET Gest = gestfin WHERE Gest = gestinit;
		-- TRANSF
		UPDATE TRANSF SET CodGestCmd = gestfin WHERE CodGestCmd = gestinit;
		-- NLOCATII
		UPDATE NLOCATII SET CodGest = gestfin WHERE CodGest = gestinit;
    -- NGEST1: Clasa 9
    DELETE FROM NGEST1 WHERE CodGest = gestinit;
    -- PRODGEST: Retete articole compuse, Traseu tehnologic
    UPDATE PRODGEST SET CodGest = gestfin WHERE CodGest = gestinit;
    -- FORMATII
    UPDATE FORMATII SET CodGest = gestfin WHERE CodGest = gestinit;
    -- COMPENS
    UPDATE COMPENS SET CodGest = gestfin WHERE CodGest = gestinit;
    -- COMANDA
    UPDATE COMANDA SET CodGest = gestfin WHERE CodGest = gestinit;
    -- RAC_REZ
    UPDATE RAC_REZ SET CodGestSursa = gestfin WHERE CodGestSursa = gestinit;
    UPDATE RAC_REZ SET CodGestDest  = gestfin WHERE CodGestDest  = gestinit;
		-- NGEST
		DELETE FROM NGEST WHERE CodGest = gestinit;
   	COMMIT;
    RETURN TRUE;

		--EXCEPTION WHEN OTHERS THEN
		--BEGIN
		  --ROLLBACK TO FUZGEST;
			--RETURN FALSE;
		--END;
  END;

  FUNCTION CLASA9OK(gest IN NUMBER) RETURN BOOLEAN IS
    lClasa9 NUMBER(20);
  BEGIN
    SELECT
      COUNT(*)
    INTO
      lClasa9
    FROM
      NGEST1
    WHERE
      CodGest = gest AND
      (
         NVL(CHELTUIELI, 0) &gt; 0 OR
         NVL(CHELTUIELIAUX, 0) &gt; 0 OR
         NVL(CHELTUIELIIND, 0) &gt; 0 OR
         NVL(CHELTUIELIADMIN, 0) &gt; 0 OR
         NVL(CHELTUIELIDESF, 0) &gt; 0 OR
         NVL(VENITURI, 0) &gt; 0 OR
         NVL(VENITURIK, 0) &gt; 0
      );
    IF lClasa9 &gt; 0 THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END;

  FUNCTION VER_CLASA9(gestinit IN NUMBER, gestfin IN NUMBER) RETURN NUMBER IS
    lClasa9InitOK BOOLEAN;
    lClasa9FinOK  BOOLEAN;
  BEGIN
    lClasa9InitOK := CLASA9OK(gestinit);
    lClasa9FinOK := CLASA9OK(gestfin);
    IF lClasa9InitOK AND lClasa9FinOK THEN
      RETURN 0;
    ELSE
      RETURN 1;
    END IF;
  END;

	PROCEDURE FUZ_GEST_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
    lClasa9InitOK BOOLEAN;
    lClasa9FinOK  BOOLEAN;
	BEGIN
		FOR reg_fuzgest IN (
      SELECT FG.CodGestInit, FG.CodGestFin, FG.SubunitInit, FG.SubunitFin, NGI.Den_Gest AS DenGestInit, NGF.Den_Gest AS DenGestFin
			FROM FUZGEST FG
				INNER JOIN NGEST NGI ON NGI.CodGest = FG.CodGestInit
				INNER JOIN NGEST NGF ON NGF.CodGest = FG.CodGestFin
			WHERE FG.UserID = p_userid AND FG.UserStr = p_userstr AND FG.Data IS NULL
    ) LOOP
      lClasa9InitOK := CLASA9OK(reg_fuzgest.CodGestInit);
      lClasa9FinOK  := CLASA9OK(reg_fuzgest.CodGestFin);
      IF lClasa9InitOK AND lClasa9FinOK THEN
		    IF FUZ_GEST_SUB(reg_fuzgest.CodGestInit, reg_fuzgest.CodGestFin) THEN
			    UPDATE FUZGEST
  			  SET
	  			  Data = SYSDATE,
		  	    InfoInit = &apos;CodGest = &apos;||TO_CHAR(reg_fuzgest.CodGestInit)||&apos;, DenGest = &apos;||reg_fuzgest.DenGestInit||&apos;, DenSubunit = &apos;||reg_fuzgest.SubunitInit,
			  	  InfoFin  = &apos;CodGest = &apos;||TO_CHAR(reg_fuzgest.CodGestFin) ||&apos;, DenGest = &apos;||reg_fuzgest.DenGestFin ||&apos;, DenSubunit = &apos;||reg_fuzgest.SubunitFin
			    WHERE CodGestInit = reg_fuzgest.CodGestInit
            AND CodGestFin = reg_fuzgest.CodGestFin
            AND UserID = p_userid
            AND UserStr = p_userstr
            AND Data IS NULL;
        END IF;
      END IF;
    END LOOP;
		COMMIT;
	END;

	PROCEDURE CLR_TMP IS
	BEGIN
	  DELETE FROM TMP_FUZGEST;
		COMMIT;
	END;

	PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
	BEGIN
	  DELETE FROM TMP_FUZGEST;

	  INSERT INTO TMP_FUZGEST (CodGestInit, CodGestFin, SubunitInit, SubunitFin)
    SELECT CodGestInit, CodGestFin, SubunitInit, SubunitFin
		FROM FUZGEST
		WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;

		COMMIT;
	END;

	PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
	BEGIN
		DELETE FROM FUZGEST WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;

		INSERT INTO FUZGEST (CodGestInit, CodGestFin, SubunitInit, SubunitFin, UserID, UserStr, Data)
		SELECT CodGestInit, CodGestFin, SubunitInit, SubunitFin, p_userid, p_userstr, NULL
    FROM TMP_FUZGEST;
		
    COMMIT;
	END;

END PKG_FUZGEST;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E541F99DCEE2BF75A0AB359E53FF2845E65ED0E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FUZLOCALIT IS

  FUNCTION GET_SIMBAUTO(localit IN NUMBER) RETURN VARCHAR2 IS
	  simb_auto VARCHAR2(2);
	BEGIN
	  SELECT NVL(NJ.SimbAuto, &apos;--&apos;) INTO simb_auto FROM NJUDET NJ
		LEFT OUTER JOIN NLOCALIT NL ON NL.CodJudet = NJ.CodJudet
		WHERE NL.CodLocalit = localit;		
		RETURN simb_auto;
		EXCEPTION WHEN OTHERS THEN RETURN &apos;--&apos;;
	END;
	
	FUNCTION GET_DENSUP(localit IN NUMBER) RETURN VARCHAR2 IS
	  den_sup VARCHAR2(50);
	BEGIN
	  SELECT NVL(DenSup, &apos;..nedefinit..&apos;) INTO den_sup FROM NLOCALIT WHERE CodLocalit = localit;
		RETURN den_sup;
		EXCEPTION WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
	END;

  PROCEDURE FUZ_LOCALIT_SUB(localitinit IN NUMBER, localitfin IN NUMBER) IS
  BEGIN
	  /*SAVEPOINT SAVEPOINT_FUZLOCALIT;
		BEGIN*/
			-- NAGENDA: schimb
			UPDATE NAGENDA SET CodLocalit = localitfin WHERE CodLocalit = localitinit;
			-- NPARTB: schimb
			UPDATE NPARTB SET CodLocalit = localitfin WHERE CodLocalit = localitinit;
			-- NPERS: schimb
			UPDATE NPERS SET LocNastere = localitfin WHERE LocNastere = localitinit;
			UPDATE NPERS SET LocalitN = localitfin WHERE LocalitN = localitinit;
			-- NGEST: legatura se face prin NAGENDA
			-- NSUBUNIT: legatura se face prin NAGENDA
			-- NBANK: :1:2:3
			-- NBANKCONT: schimb
			UPDATE NBANKCONT SET CodLocalitate = localitfin WHERE CodLocalitate = localitinit;
			-- NLOCALIT: sterg
			DELETE FROM NLOCALIT WHERE CodLocalit = localitinit;
   		COMMIT;	  
		/*END;
		EXCEPTION WHEN OTHERS THEN
		BEGIN
		  ROLLBACK TO SAVEPOINT_FUZLOCALIT;
			RETURN 0;
		END;*/
  END;
	
	PROCEDURE FUZ_LOCALIT_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
	BEGIN
		FOR reg_fuzlocalit IN
		  (SELECT
				 FL.CodLocalitInit, FL.CodLocalitFin,
				 FL.SimbAutoInit, FL.SimbAutoFin,
				 FL.DenSupInit, FL.DenSupFin,
				 NLI.Den_Localit AS DenLocalitInit, NLF.Den_Localit AS DenLocalitFin
			 FROM
				 FUZLOCALIT FL
				 INNER JOIN NLOCALIT NLI ON NLI.CodLocalit = FL.CodLocalitInit
				 INNER JOIN NLOCALIT NLF ON NLF.CodLocalit = FL.CodLocalitFin
			 WHERE
				 FL.UserID = p_userid AND
				 FL.UserStr = p_userstr AND
				 FL.Data IS NULL)
    LOOP
		  FUZ_LOCALIT_SUB(reg_fuzlocalit.CodLocalitInit, reg_fuzlocalit.CodLocalitFin);
			UPDATE FUZLOCALIT
			SET
				Data = SYSDATE,
				InfoInit = &apos;CodLocalit = &apos; || TO_CHAR(reg_fuzlocalit.CodLocalitInit) ||
				           &apos;, DenLocalit = &apos; || reg_fuzlocalit.DenLocalitInit ||
									 &apos;, CodAuto = &apos; || reg_fuzlocalit.SimbAutoInit ||
									 &apos;, DenSup = &apos; || reg_fuzlocalit.DenSupInit,
				InfoFin = &apos;CodLocalit = &apos; || TO_CHAR(reg_fuzlocalit.CodLocalitFin) ||
				          &apos;, DenLocalit = &apos; || reg_fuzlocalit.DenLocalitFin ||
									&apos;, CodAuto = &apos; || reg_fuzlocalit.SimbAutoFin ||
									&apos;, DenSup = &apos; || reg_fuzlocalit.DenSupFin
			WHERE
				CodLocalitInit = reg_fuzlocalit.CodLocalitInit AND
				CodLocalitFin = reg_fuzlocalit.CodLocalitFin AND
				UserID = p_userid AND
				UserStr = p_userstr AND
				Data IS NULL;
    END LOOP;
	END;
	
	PROCEDURE CLR_TMP IS
	BEGIN
	  DELETE FROM TMP_FUZLOCALIT;
		COMMIT;
	END;
	
	PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
	BEGIN
	  DELETE FROM TMP_FUZLOCALIT;
	  INSERT INTO TMP_FUZLOCALIT
		  (CodLocalitInit, CodLocalitFin, SimbAutoInit, SimbAutoFin, DenSupInit, DenSupFin)
			(SELECT CodLocalitInit, CodLocalitFin, SimbAutoInit, SimbAutoFin, DenSupInit, DenSupFin
			 FROM FUZLOCALIT
			 WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL);
		COMMIT;
	END;
	
	PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
	BEGIN		
		DELETE FROM FUZLOCALIT WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
		INSERT INTO FUZLOCALIT
		  (CodLocalitInit, CodLocalitFin, SimbAutoInit, SimbAutoFin, DenSupInit, DenSupFin, /*InfoInit, InfoFin,*/ UserID, UserStr, Data)
			(SELECT
			   TFL.CodLocalitInit, TFL.CodLocalitFin,
				 NJI.SimbAuto AS SimbAutoInit, NJF.SimbAuto AS SimbAutoFin,
				 NLI.DenSup AS DenSupInit, NLF.DenSup AS DenSupFin,
				 /*&apos;&apos;, &apos;&apos;,*/
  			 p_userid, p_userstr,
	  		 NULL
			 FROM TMP_FUZLOCALIT TFL
			 INNER JOIN NLOCALIT NLI ON NLI.CodLocalit = TFL.CodLocalitInit
			 INNER JOIN NLOCALIT NLF ON NLF.CodLocalit = TFL.Codlocalitfin
			 LEFT OUTER JOIN NJUDET NJI ON NJI.CodJudet = NLI.CodJudet
			 LEFT OUTER JOIN NJUDET NJF ON NJF.CodJudet = NLF.CodJudet);
		COMMIT;
	END;
    
END PKG_FUZLOCALIT; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFD52638034D298DD03F3FCFED386CAA890F5226</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FUZPART IS

FUNCTION GET_CODFISC(codpartener IN NUMBER) RETURN VARCHAR2 IS
  cod_fiscal VARCHAR2(15);
BEGIN
  SELECT Coalesce(CodFiscal, &apos;..nedefinit..&apos;) INTO cod_fiscal FROM NPARTCODFISC WHERE CodPart = codpartener;
  RETURN cod_fiscal;
EXCEPTION
  WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
END;

FUNCTION TEST_CODFISC(codpartener IN NUMBER) RETURN NUMBER IS
  nr_codfisc NUMBER(20) := 0;
BEGIN
  SELECT COUNT(Coalesce(CodFiscal, &apos;..nedefinit..&apos;)) INTO nr_codfisc FROM NPARTCODFISC WHERE CodPart = codpartener;
  RETURN nr_codfisc;
EXCEPTION
  WHEN OTHERS THEN RETURN - 1;
END;

FUNCTION FUZ_PART_SUB(codinit IN NUMBER, codfin IN NUMBER) RETURN BOOLEAN IS
  cntinit     NUMBER(20);
  cntfin      NUMBER(20);
  cntstocini  NUMBER(20);
  cntsocial   NUMBER(20);
  tippartinit NUMBER(2);
  tippartfin  NUMBER(2);
  partfinluna NUMBER(20);
  vImplicit   NUMBER(1);
BEGIN
  SAVEPOINT FUZPART;

  -- NPART1: sterge tot ce are CodPart = codinit
  DELETE FROM NPART1 WHERE CodPart = codinit;
  -- NPARTB: trec tot ce are CodPart = codinit la codfin
  --         nu dublez CodBank + CodLocalit + ContBanca
  SELECT COUNT(1) INTO cntinit FROM NPARTB WHERE CodPart = codinit;
  SELECT COUNT(1) INTO cntfin  FROM NPARTB WHERE CodPart = codfin AND CodPart &lt;&gt; codinit;

  SELECT CASE WHEN COUNT(1) &gt; 0 THEN 0 ELSE NULL END INTO vImplicit FROM NPARTB WHERE CodPart = codfin AND Coalesce(Implicit, 0) = 1;

  IF cntinit &gt; 0 AND cntfin = 0 THEN
    UPDATE NPARTB SET CodPart = codfin WHERE CodPart = codinit;
  END IF;
  IF cntinit &gt; 0 AND cntfin &gt; 0 THEN
    FOR reg_init IN (
      SELECT CodPartB, CodBank, Coalesce(CodLocalit, 0) AS CodLocalit, Coalesce(ContBanca, &apos;0&apos;) AS ContBanca
      FROM NPARTB
      WHERE CodPart = codinit
    ) LOOP
      FOR reg_fin IN (
        SELECT CodPartB, CodBank, Coalesce(CodLocalit, 0) AS CodLocalit, Coalesce(ContBanca, &apos;0&apos;) AS ContBanca
        FROM NPARTB
        WHERE CodPart = codfin AND CodPart &lt;&gt; codinit
      ) LOOP
        IF  reg_fin.CodBank    = reg_init.CodBank
        AND reg_fin.CodLocalit = reg_init.CodLocalit
        AND reg_fin.ContBanca  = reg_init.ContBanca
        THEN DELETE FROM NPARTB WHERE CodPartB = reg_init.CodPartB;
        ELSE UPDATE NPARTB SET CodPart = codfin, Implicit = Coalesce(vimplicit, Implicit, 0) WHERE CodPartB = reg_init.CodPartB;
        END IF;
      END LOOP;
    END LOOP;
  END IF;
  -- NAGENDA: trec tot de la CodPart = codinit la codfin
  --           SediuSocial ramane doar ala de la codfin
  --          nu dublez Tip, CodLocalit, Sector, Strada, Nr1, Nr2, Bloc, Scara, Etaj, Apart, CodAgent
  SELECT COUNT(1) INTO cntinit   FROM NAGENDA WHERE CodPart = codinit;
  SELECT COUNT(1) INTO cntfin    FROM NAGENDA WHERE CodPart = codfin AND CodPart &lt;&gt; codinit;
  SELECT COUNT(1) INTO cntsocial FROM NAGENDA WHERE CodPart = codfin AND CodPart &lt;&gt; codinit AND SediuSocial IN (4, 5, 6, 7);
  IF cntinit &gt; 0 AND cntfin = 0 THEN
    UPDATE NAGENDA SET CodPart = codfin WHERE CodPart = codinit;
  END IF;
  IF cntinit &gt; 0 AND cntfin &gt; 0 THEN
    FOR reg_init IN (
      SELECT
        CodAgenda, CodPart, SediuSocial,
        Coalesce(CodLocalit, 0) AS CodLocalit, Coalesce(Sector, 0) AS Sector, Coalesce(Strada, &apos; &apos;) AS Strada,
        Coalesce(Nr1, 0) AS Nr1, Coalesce(Nr2, &apos;0&apos;) AS Nr2,
        Coalesce(Bloc, &apos;0&apos;) AS Bloc, Coalesce(Scara, &apos;0&apos;) AS Scara, Coalesce(Etaj, &apos;0&apos;) AS Etaj, Coalesce(Apart, &apos;0&apos;) AS Apart,
        Coalesce(CodAgent, 0) AS CodAgent
      FROM NAGENDA
      WHERE CodPart = codinit
    ) LOOP
      FOR reg_fin IN (
        SELECT
          CodAgenda, CodPart, SediuSocial,
          Coalesce(CodLocalit, 0) AS CodLocalit, Coalesce(Sector, 0) AS Sector, Coalesce(Strada, &apos; &apos;) AS Strada,
          Coalesce(Nr1, 0) AS Nr1, Coalesce(Nr2, &apos;0&apos;) AS Nr2,
          Coalesce(Bloc, &apos;0&apos;) AS Bloc, Coalesce(Scara, &apos;0&apos;) AS Scara, Coalesce(Etaj, &apos;0&apos;) AS Etaj, Coalesce(Apart, &apos;0&apos;) AS Apart,
          Coalesce(CodAgent, 0) AS CodAgent
        FROM NAGENDA
        WHERE CodPart = codfin
          AND CodPart &lt;&gt; codinit
      ) LOOP
        IF  reg_fin.CodLocalit = reg_init.CodLocalit
        AND reg_fin.Sector     = reg_init.Sector
        AND reg_fin.Strada     = reg_init.Strada
        AND reg_fin.Nr1        = reg_init.Nr1
        AND reg_fin.Nr2        = reg_init.Nr2
        AND reg_fin.Bloc       = reg_init.Bloc
        AND reg_fin.Scara      = reg_init.Scara
        AND reg_fin.Etaj       = reg_init.Etaj
        AND reg_fin.Apart      = reg_init.Apart
        AND reg_fin.CodAgent   = reg_init.CodAgent
        THEN
          -- UPDATE CodLocatie in FK-TABLES!!! NIRSTOC, COMANDA, IESIRI, INTRARI, BCAR
          UPDATE NIRSTOC SET CodLocatie = reg_fin.CodAgenda WHERE Furn        = reg_init.CodPart AND CodLocatie = reg_init.CodAgenda;
          UPDATE COMANDA SET CodLocatie = reg_fin.CodAgenda WHERE Partener    = reg_init.CodPart AND CodLocatie = reg_init.CodAgenda;
          UPDATE IESIRI  SET CodLocatie = reg_fin.CodAgenda WHERE Partener    = reg_init.CodPart AND CodLocatie = reg_init.CodAgenda;
          UPDATE INTRARI SET CodLocatie = reg_fin.CodAgenda WHERE Partener    = reg_init.CodPart AND CodLocatie = reg_init.CodAgenda;
          UPDATE BCAR    SET CodSediu   = reg_fin.CodAgenda WHERE CodPartener = reg_init.CodPart AND CodSediu   = reg_init.CodAgenda;
          UPDATE OFERTA  SET CodLocatie = reg_fin.CodAgenda WHERE Partener    = reg_init.CodPart AND CodLocatie = reg_init.CodAgenda;
          DELETE FROM NAGENDA WHERE CodAgenda = reg_init.CodAgenda;
        ELSE
          IF cntsocial &gt; 0 THEN
            -- pentru baze de date cu probleme
            UPDATE NAGENDA SET CodPart = reg_fin.CodPart, SediuSocial = 1                        WHERE CodAgenda = reg_init.CodAgenda AND Coalesce(SediuSocial, 0) = 0;
            -- nu e nevoie sa transferam si propietatea ca sediul e de tip SOCIAL
            UPDATE NAGENDA SET CodPart = reg_fin.CodPart                                         WHERE CodAgenda = reg_init.CodAgenda AND Coalesce(SediuSocial, 0) IN (1, 2, 3, 9);
            UPDATE NAGENDA SET CodPart = reg_fin.CodPart, SediuSocial = 3                        WHERE CodAgenda = reg_init.CodAgenda AND Coalesce(SediuSocial, 0) IN (4);
            UPDATE NAGENDA SET CodPart = reg_fin.CodPart, SediuSocial = reg_init.SediuSocial - 4 WHERE CodAgenda = reg_init.CodAgenda AND Coalesce(SediuSocial, 0) IN (5, 6, 7);
          ELSE
            -- e nevoie sa transferam si SEDIUL SOCIAL, oricare ar fi el...
            UPDATE NAGENDA SET CodPart = reg_fin.CodPart                                         WHERE CodAgenda = reg_init.CodAgenda;
          END IF;
        END IF;
      END LOOP;
    END LOOP;
  END IF;
  -- NPARTDISC: sterg tot ce are CodPart = codinit
  DELETE FROM NPARTDISC WHERE CodPart = codinit;
  -- NPARTCODFISC: pentru a nu avea probleme in documenete part fin le preia si pe cele de la part init cu verificare sa nu fie mai multe principale
  SELECT COUNT(1) INTO cntinit FROM NPARTCODFISC WHERE CodPart = codinit AND Principal = 1;
  SELECT COUNT(1) INTO cntfin  FROM NPARTCODFISC WHERE CodPart = codfin  AND Principal = 1 AND CodPart &lt;&gt; codinit;
  IF cntinit &gt; 0 AND cntfin &gt; 0 THEN
    UPDATE NPARTCODFISC SET Principal = 0 WHERE CodPart = codinit;
  END IF;
  UPDATE NPARTCODFISC SET CodPart = codfin WHERE CodPart = codinit;
  -- NPERSCONTACT: sterg tot ce are CodPart = codinit
  DELETE FROM NPERSCONTACT WHERE CodPart = codinit;
  -- NPARTTR: trec tot de la CodPart = codinit la codfin
  --          nu dublez CNP + MijlTransp + NrTransp
  SELECT COUNT(1) INTO cntinit FROM NPARTTR WHERE CodPart = codinit;
  SELECT COUNT(1) INTO cntfin  FROM NPARTTR WHERE CodPart = codfin AND CodPart &lt;&gt; codinit;

  SELECT CASE WHEN COUNT(1) &gt; 0 THEN 0 ELSE NULL END INTO vImplicit FROM NPARTTR WHERE CodPart = codfin AND Coalesce(Implicit, 0) = 1;

  IF cntinit &gt; 0 AND cntfin = 0 THEN
    UPDATE NPARTTR SET CodPart = codfin WHERE CodPart = codinit;
  END IF;
  IF cntinit &gt; 0 AND cntfin &gt; 0 THEN
    FOR reg_init IN (
      SELECT CodPartTR, CodPart, Coalesce(CNP, &apos;0&apos;) AS CNP, Coalesce(MijlTransp, &apos;0&apos;) AS MijlTransp, Coalesce(NrTransp, &apos;0&apos;) AS NrTransp
      FROM NPARTTR
      WHERE CodPart = codinit
    ) LOOP
      FOR reg_fin IN (
        SELECT CodPartTR, CodPart, Coalesce(CNP, &apos;0&apos;) AS CNP, Coalesce(MijlTransp, &apos;0&apos;) AS MijlTransp, Coalesce(NrTransp, &apos;0&apos;) AS NrTransp
        FROM NPARTTR
        WHERE CodPart = codfin AND CodPart &lt;&gt; codinit
      ) LOOP
        IF reg_fin.CNP = reg_init.CNP AND reg_fin.MijlTransp = reg_init.MijlTransp AND reg_fin.NrTransp = reg_init.NrTransp THEN
          DELETE FROM NPARTTR WHERE CodPartTR = reg_init.CodPartTR;
        ELSE
          UPDATE NPARTTR SET CodPart = reg_fin.CodPart, Implicit = Coalesce(vimplicit, Implicit, 0) WHERE CodPartTR = reg_init.CodPartTR;
        END IF;
      END LOOP;
    END LOOP;
  END IF;
  -- NARTCLI: trec tot de la CodPart = codinit la codfin
  --          nu dublez CodObiect
  --          CodMoneda
  SELECT COUNT(1) INTO cntinit FROM NARTCLI WHERE CodPart = codinit;
  SELECT COUNT(1) INTO cntfin  FROM NARTCLI WHERE CodPart = codfin AND CodPart &lt;&gt; codinit;
  IF cntinit &gt; 0 AND cntfin = 0 THEN
    UPDATE NARTCLI SET CodPart = codfin WHERE CodPart = codinit;
  END IF;
  IF cntinit &gt; 0 AND cntfin &gt; 0 THEN
    FOR reg_init IN (SELECT CodArtCli, CodPart, CodObiect FROM NARTCLI WHERE CodPart = codinit) LOOP
      FOR reg_fin IN (SELECT CodArtCli, CodPart, CodObiect FROM NARTCLI WHERE CodPart = codfin AND CodPart &lt;&gt; codinit) LOOP
        SELECT CASE WHEN COUNT(1) &gt; 0 THEN 0 ELSE NULL END INTO vImplicit
        FROM NARTCLI
        WHERE CodPart   = codfin
          AND CodObiect = reg_init.CodObiect
          AND Coalesce(Implicit, 0) = 1;
        IF reg_init.CodObiect = reg_fin.CodObiect THEN
          DELETE FROM NARTCLI WHERE CodArtCli = reg_init.CodArtCli;
        ELSE
          UPDATE NARTCLI SET CodPart = reg_fin.CodPart, Implicit = Coalesce(vimplicit, Implicit, 0) WHERE CodArtCli = reg_init.CodArtCli;
        END IF;
      END LOOP;
    END LOOP;
  END IF;
  -- SOLDINI: sterg tot ce are CodPart = codini daca exista SAU pun CodPart pe codfin
  --          Mai jos in NPARTSOLDLUNA trec tot de la CodPart = codini la codfin,
  --          astfel incat soldul initial al part. codini nu se pierde...
  SELECT COUNT(1) INTO cntstocini FROM SOLDINI WHERE CodPart = codfin;
  IF cntstocini &gt; 0 THEN
    -- exista codfin in SOLDINI, nu am nevoie de intrari multiple
    DELETE FROM SOLDINI WHERE CodPart = codinit;
  ELSE
    -- nu exista codfin in SOLDINI trebuie schimbat codinit in codfin
    UPDATE SOLDINI SET CodPart = codfin WHERE CodPart = codinit;
  END IF;
  UPDATE NIRSTOC  SET Furn            = codfin WHERE Furn            = codinit;
  UPDATE COMPENS  SET PartD           = codfin WHERE PartD           = codinit;
  UPDATE COMPENS  SET PartC           = codfin WHERE PartC           = codinit;
  UPDATE OBLIGPIF SET CodPart         = codfin WHERE CodPart         = codinit AND NOT (Semnificatie IN (800, 801, 1100, 1101)) ;
  UPDATE TREZOR1  SET CodPart         = codfin WHERE CodPart         = codinit AND ( (TipTranz IN (0,1) AND ObiectTranz IN (0,1)) OR Initializari = 1 );
  UPDATE COMANDA  SET Partener        = codfin WHERE Partener        = codinit;
  UPDATE RAC_REZ  SET CodPartExt      = codfin WHERE CodPartExt      = codinit;
  UPDATE RAC_REZ  SET CodSofer        = codfin WHERE CodSofer        = codinit;
  UPDATE RAC_REZ  SET CodSofer1       = codfin WHERE CodSofer1       = codinit;
  UPDATE RAC_REZ  SET CodSofer2       = codfin WHERE CodSofer2       = codinit;
  UPDATE DVI      SET CodVama         = codfin WHERE CodVama         = codinit;
  UPDATE IESIRI   SET Partener        = codfin WHERE Partener        = codinit;
  UPDATE INTRARI  SET Partener        = codfin WHERE Partener        = codinit;
  UPDATE INTRARI  SET Transportator   = codfin WHERE Transportator   = codinit;
  UPDATE RESTNP   SET CODPART         = codfin WHERE CODPART         = codinit;
  UPDATE BCAR     SET CodPartener     = codfin WHERE CodPartener     = codinit;
  UPDATE INTRARI1 SET FurnAvizSubunit = codfin WHERE FurnAvizSubunit = codinit;
  UPDATE NOTECREDIT SET CodPart       = codfin WHERE CodPart         = codinit;
  UPDATE OFERTA   SET Partener        = codfin WHERE Partener        = codinit;

  -- refac NPARTSOLDLUNA si NPARTSOLDLUNASUB, ele contin date agregate la nivel de ICONT
  FOR F_PARTINIT IN (SELECT * FROM NPARTSOLDLUNA WHERE CodPart = codinit) LOOP
    SELECT COUNT(1) INTO partfinluna
    FROM NPARTSOLDLUNA
    WHERE CodPart   = codfin
      AND An        = F_PARTINIT.An
      AND Luna      = F_PARTINIT.Luna
      AND CodMoneda = F_PARTINIT.CodMoneda
      AND ICont     = F_PARTINIT.ICont;
    IF partfinluna = 1 THEN
      UPDATE NPARTSOLDLUNA
      SET SoldLei    = SoldLei    + F_PARTINIT.SoldLei,
          SoldValuta = SoldValuta + F_PARTINIT.SoldValuta
      WHERE CodPart   = codfin
        AND An        = F_PARTINIT.An
        AND Luna      = F_PARTINIT.Luna
        AND CodMoneda = F_PARTINIT.CodMoneda
        AND ICont     = F_PARTINIT.ICont;
      DELETE FROM NPARTSOLDLUNA WHERE CodPartSoldLuna = F_PARTINIT.CodPartSoldLuna;
    ELSE
      UPDATE NPARTSOLDLUNA SET CodPart = codfin WHERE CodPart = F_PARTINIT.CodPart;
    END IF;
  END LOOP;
  FOR F_PARTINITSUB IN (SELECT * FROM NPARTSOLDLUNASUB WHERE CodPart = codinit) LOOP
    SELECT COUNT(1) INTO partfinluna
    FROM NPARTSOLDLUNASUB
    WHERE CodPart     = codfin
      AND An          = F_PARTINITSUB.An
      AND Luna        = F_PARTINITSUB.Luna
      AND CodMoneda   = F_PARTINITSUB.CodMoneda
      AND ICont       = F_PARTINITSUB.ICont
      AND Subunitatea = F_PARTINITSUB.Subunitatea;
    IF partfinluna = 1 THEN
      UPDATE NPARTSOLDLUNASUB
      SET SoldLei    = SoldLei    + F_PARTINITSUB.SoldLei,
          SoldValuta = SoldValuta + F_PARTINITSUB.SoldValuta
      WHERE CodPart     = codfin
        AND An          = F_PARTINITSUB.An
        AND Luna        = F_PARTINITSUB.Luna
        AND CodMoneda   = F_PARTINITSUB.CodMoneda
        AND ICont       = F_PARTINITSUB.ICont
        AND Subunitatea = F_PARTINITSUB.Subunitatea;

      DELETE FROM NPARTSOLDLUNASUB WHERE CodPartSoldLunaSub = F_PARTINITSUB.CodPartSoldLunaSub;
    ELSE
      UPDATE NPARTSOLDLUNASUB SET CodPart = codfin WHERE CodPart = F_PARTINITSUB.CodPart;
    END IF;
  END LOOP;
  UPDATE NC        SET Part          = codfin WHERE Part          = codinit;
  UPDATE OFERTA    SET Partener      = codfin WHERE Partener      = codinit;
  UPDATE CONTRACT  SET Partener      = codfin WHERE Partener      = codinit;
  UPDATE NARTCLI   SET CodPart       = codfin WHERE CodPart       = codinit;
  UPDATE NARTOBJ   SET CodProducator = codfin WHERE CodProducator = codinit;
  UPDATE PROMOPART SET Partener      = codfin WHERE Partener      = codinit;
  -- NPART: sterge tot ce are CodPart = codinit
  --        transfera si caracterizarea partenerului: intern/extern/producator/asigurator auto
  --         FARA SA DISTRUGA CARACTERIZAREA EXISTENTA!!!
  SELECT Coalesce(TipPartener, 0) INTO tippartinit FROM NPART WHERE CodPart = codinit;
  SELECT Coalesce(TipPartener, 0) INTO tippartfin  FROM NPART WHERE CodPart = codfin;
  CASE tippartinit
    WHEN 1 THEN -- intern
      UPDATE NPART SET TipPartener = tippartfin + 1  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (0, 4, 8, 14);
    WHEN 2 THEN -- extern
      UPDATE NPART SET TipPartener = tippartfin + 2  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (0, 4, 8, 14);
    WHEN 4 THEN -- producator
      UPDATE NPART SET TipPartener = tippartfin + 4  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (0, 1, 2, 8);
    WHEN 5 THEN -- intern/producator
      UPDATE NPART SET TipPartener = tippartfin + 4  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2, 8);
      UPDATE NPART SET TipPartener = 5               WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    WHEN 6 THEN -- extern/producator
      UPDATE NPART SET TipPartener = tippartfin + 4  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2, 8);
      UPDATE NPART SET TipPartener = 6               WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    WHEN 8 THEN -- asigurator
      UPDATE NPART SET TipPartener = tippartfin + 8  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (0, 1, 2, 4);
    WHEN 9 THEN -- intern/asigurator
      UPDATE NPART SET TipPartener = tippartfin + 8  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2, 4);
      UPDATE NPART SET TipPartener = 9               WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    WHEN 10 THEN -- extern/asigurator
      UPDATE NPART SET TipPartener = tippartfin + 8  WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2, 4);
      UPDATE NPART SET TipPartener = 10              WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    WHEN 14 THEN -- producator/asigurator
      UPDATE NPART SET TipPartener = tippartfin + 14 WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (0, 1, 2);
    WHEN 15 THEN -- intern/producator/asigurator
      UPDATE NPART SET TipPartener = tippartfin + 14 WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2);
      UPDATE NPART SET TipPartener = 15              WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    WHEN 16 THEN -- extern/producator/asigurator
      UPDATE NPART SET TipPartener = tippartfin + 14 WHERE CodPart = codfin AND Coalesce(TipPartener, 0) IN (1, 2);
      UPDATE NPART SET TipPartener = 16              WHERE CodPart = codfin AND Coalesce(TipPartener, 0) = 0;
    ELSE
      NULL;
  END CASE;
  DELETE FROM NPART WHERE CodPart = codinit;
  COMMIT;
  RETURN TRUE;
EXCEPTION
  WHEN OTHERS THEN
    BEGIN
      ROLLBACK TO FUZPART;
      RETURN FALSE;
    END;
END;

FUNCTION FUZ_LOC_SUB(
  codpart IN NUMBER,
  locinit IN NUMBER,
  locfin  IN NUMBER
) RETURN BOOLEAN IS
  sediusocinit NUMBER(1);
  sediusocfin  NUMBER(1);
BEGIN
  SAVEPOINT FUZLOC;
  -- NPART: nu fac nimic
  -- NPART1: nu fac nimic
  -- NPARTB: nu fac nimic
  -- NAGENDA: sterg tot ce are CodPart = codpart
  -- UPDATE CodLocatie in FK-TABLES!!! NIRSTOC, COMANDA, IESIRI, INTRARI
  -- Atentie la SediuSocial, sa nu dispara...
  UPDATE NIRSTOC SET CodLocatie = locfin WHERE Furn        = codpart AND CodLocatie = locinit;
  UPDATE COMANDA SET CodLocatie = locfin WHERE Partener    = codpart AND CodLocatie = locinit;
  UPDATE IESIRI  SET CodLocatie = locfin WHERE Partener    = codpart AND CodLocatie = locinit;
  UPDATE INTRARI SET CodLocatie = locfin WHERE Partener    = codpart AND CodLocatie = locinit;
  UPDATE BCAR    SET CodSediu   = locfin WHERE CodPartener = codpart AND CodSediu   = locinit;
  UPDATE OFERTA  SET CodLocatie = locfin WHERE Partener    = codpart AND CodLocatie = locinit;

  SELECT SediuSocial INTO sediusocinit FROM NAGENDA WHERE CodAgenda = locinit;
  SELECT SediuSocial INTO sediusocfin  FROM NAGENDA WHERE CodAgenda = locfin;
  DELETE FROM NAGENDA WHERE CodAgenda = locinit;
  IF sediusocinit &gt; 3 AND sediusocfin &lt; 4 THEN
    UPDATE NAGENDA SET SediuSocial = sediusocinit WHERE CodAgenda = locfin;
  END IF;
  -- NPARTDISC: nu fac nimic
  -- NPARTCODFISC: nu fac nimic
  -- NPERSCONTACT: nu fac nimic
  -- NPARTTR: nu fac nimic
  -- NARTCLI: nu fac nimic
  -- SOLDINI: nu fac nimic
  -- NIRSTOC: trec tot de la CodLocatie = locinit la locfin pentru CodPart = codpart
  UPDATE NIRSTOC SET CodLocatie = locfin WHERE Furn = codpart AND CodLocatie = locinit;
  -- COMPENS: nu fac nimic
  -- OBLIGPIF: nu fac nimic
  -- TREZOR1: nu fac nimic
  -- COMANDA: trec tot de la CodLocatie = locinit la locfin pentur Partener = codpart
  UPDATE COMANDA SET CodLocatie = locfin WHERE Partener = codpart AND CodLocatie = locinit;
  -- DVI: nu fac nimic
  -- IESIRI: trec tot de la CodLocatie = locinit la locfin pentru Partener = codpart
  UPDATE IESIRI SET CodLocatie = locfin WHERE Partener = codpart AND CodLocatie = locinit;
  -- INTRARI: trec tot de la CodLocatie = locinit la locfin pentru Partener = codpart
  UPDATE INTRARI SET CodLocatie = locfin WHERE Partener = codpart AND CodLocatie = locinit;
  -- NC: nu fac nimic
  -- NARTOBJ: nu fac nimic
  -- NLOCATII: sterg
  DELETE FROM NLOCATII WHERE CodLocatie = locinit;
  COMMIT;
  RETURN TRUE;
EXCEPTION
  WHEN OTHERS THEN
    BEGIN
      ROLLBACK TO FUZLOC;
      RETURN FALSE;
    END;
END;

PROCEDURE FUZ_PART_MAIN(p_codinit IN NUMBER, p_codfin IN NUMBER, p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  l_deninit  VARCHAR2(100);
  l_denfin   VARCHAR2(100);
  l_extinit  VARCHAR2(50);
  l_extfin   VARCHAR2(50);
  l_locinit  VARCHAR2(50);
  l_locfin   VARCHAR2(50);
  l_fiscinit VARCHAR2(75);
  l_fiscfin  VARCHAR2(75);

  b_OK BOOLEAN;
BEGIN
  b_OK := TRUE;
  BEGIN
    SELECT Coalesce(FP.CodExtInit, &apos;&apos;), Coalesce(FP.CodFiscInit, &apos;&apos;), Coalesce(FP.LocalitInit, &apos;&apos;), Coalesce(NPI.Den_Part, &apos;&apos;), Coalesce(FP.CodExtFin, &apos;&apos;), Coalesce(FP.CodFiscFin, &apos;&apos;), Coalesce(FP.LocalitFin, &apos;&apos;), Coalesce(NPF.Den_Part, &apos;&apos;)
    INTO   l_extinit,                   l_fiscinit,                   l_locinit,                    l_deninit,                  l_extfin,                   l_fiscfin,                   l_locfin,                    l_denfin
    FROM FUZPART FP
      INNER JOIN NPART NPI ON NPI.CodPart = FP.CodPartInit
      INNER JOIN NPART NPF ON NPF.CodPart = FP.CodPartFin
    WHERE FP.UserID      = p_userid
      AND FP.UserStr     = p_userstr
      AND FP.CodPartInit = p_codinit
      AND FP.CodPartFin  = p_codfin
      AND FP.Data IS NULL
      AND ROWNUM = 1; -- STEF - pentru orice eventualitate - deocamdata nu pare bine controlata duplicarea conditiilor in macheta
  EXCEPTION
    WHEN OTHERS THEN
      b_OK := FALSE;
  END;

  IF b_OK THEN
    IF FUZ_PART_SUB(p_codinit, p_codfin) -- this is where the magic happens
    THEN
      UPDATE FUZPART
      SET Data     = SYSDATE,
          InfoInit = &apos;CodPart = &apos;||TO_CHAR(p_codinit, &apos;fm9999999999&apos;)||&apos;, &apos;||&apos;DenPart = &apos;||l_deninit||&apos;, &apos;||&apos;CodFisc = &apos;||l_fiscinit||&apos;, &apos;||&apos;CodExt = &apos;||l_extinit||&apos;, &apos;||&apos;Localit = &apos;|| l_locinit,
          InfoFin  = &apos;CodPart = &apos;||TO_CHAR(p_codfin, &apos;fm9999999999&apos;) ||&apos;, &apos;||&apos;DenPart = &apos;||l_denfin ||&apos;, &apos;||&apos;CodFisc = &apos;||l_fiscinit||&apos;, &apos;||&apos;CodExt = &apos;||l_extinit||&apos;, &apos;||&apos;Localit = &apos;|| l_locinit
      WHERE CodPartInit = p_codinit
        AND CodPartFin  = p_codfin
        AND CodLocInit  = -1
        AND CodLocFin   = -1
        AND UserID      = p_userid
        AND UserStr     = p_userstr
        AND Data IS NULL;
    END IF;
    COMMIT;
  END if;
END;

PROCEDURE FUZ_LOC_MAIN(p_codinit IN NUMBER, p_codfin IN NUMBER, p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  l_deninit  VARCHAR2(100);
  l_denfin   VARCHAR2(100);
  l_extinit  VARCHAR2(25);
  l_extfin   VARCHAR2(25);
  l_locinit  VARCHAR2(50);
  l_locfin   VARCHAR2(50);
  l_partinit NUMBER(20);
  l_partfin  NUMBER(20);
  b_OK       BOOLEAN;
BEGIN
  b_OK := TRUE;
  BEGIN
    SELECT Coalesce(CodPartInit, 0), Coalesce(FP.CodExtInit, &apos;&apos;), Coalesce(NPI.Den_Part, &apos;&apos;), Coalesce(NAI.Obs, &apos;&apos;), Coalesce(FP.CodPartFin, 0), Coalesce(FP.CodExtFin, &apos;&apos;), Coalesce(NPF.Den_Part, &apos;&apos;), Coalesce(NAF.Obs, &apos;&apos;)
    INTO  l_partinit,                l_extinit,                   l_deninit,                  l_locinit,             l_partfin,                  l_extfin,                   l_denfin,                   l_locfin
    FROM FUZPART FP
      INNER JOIN NPART   NPI ON NPI.CodPart   = FP.CodPartInit
      INNER JOIN NPART   NPF ON NPF.CodPart   = FP.Codpartfin
      INNER JOIN NAGENDA NAI ON NAI.CodAgenda = FP.CodLocInit
      INNER JOIN NAGENDA NAF ON NAF.CodAgenda = FP.CodLocFin
    WHERE FP.UserID     = p_userid
      AND FP.UserStr    = p_userstr
      AND FP.CodLocInit = p_codinit
      AND FP.CodLocFin  = p_codfin
      AND FP.Data IS NULL
      AND ROWNUM = 1; -- STEF - pentru orice eventualitate - deocamdata nu pare bine controlata duplicarea conditiilor in macheta
  EXCEPTION
    WHEN OTHERS THEN
      b_OK := FALSE;
  END;

  IF b_OK THEN
    IF FUZ_LOC_SUB(l_partinit, p_codinit, p_codfin) THEN
      UPDATE FUZPART
      SET Data     = SYSDATE,
          InfoInit = &apos;CodPart = &apos;||TO_CHAR(l_partinit)||&apos;, &apos;||&apos;DenPart = &apos;||l_deninit||&apos;, &apos;||&apos;CodExt = &apos;||l_extinit||&apos;, &apos;||&apos;CodLoc = &apos;||TO_CHAR(p_codinit)||&apos;, &apos;||&apos;DenLoc = &apos;|| l_locinit,
          InfoFin  = &apos;CodPart = &apos;||TO_CHAR(l_partfin) ||&apos;, &apos;||&apos;DenPart = &apos;||l_denfin ||&apos;, &apos;||&apos;CodExt = &apos;||l_extfin ||&apos;, &apos;||&apos;CodLoc = &apos;||TO_CHAR(p_codfin) ||&apos;, &apos;||&apos;DenLoc = &apos;|| l_locfin
      WHERE CodPartInit = l_partinit
        AND CodPartFin  = l_partinit
        AND CodLocInit  = p_codinit
        AND CodLocFin   = p_codfin
        AND UserID      = p_userid
        AND UserStr     = p_userstr
        AND Data IS NULL;
    END IF;
    COMMIT;
  END IF;
END;

PROCEDURE CLR_TMP IS
BEGIN
  DELETE FROM TMP_FUZPART;
  COMMIT;
END;

PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_FUZPART;
  INSERT INTO TMP_FUZPART (CodPartInit, CodPartFin, CodLocInit, CodLocFin, CodFiscInit, CodFiscFin, CODEXTINIT, CODEXTFIN, LOCALITINIT, LOCALITFIN, TELEFONINIT, TELEFONFIN)
  SELECT                   CodPartInit, CodPartFin, CodLocInit, CodLocFin, CodFiscInit, CodFiscFin, CODEXTINIT, CODEXTFIN, LOCALITINIT, LOCALITFIN, TELEFONINIT, TELEFONFIN
  FROM FUZPART
  WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  COMMIT;
END;

PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  den_localit_init VARCHAR2(50);
  den_localit_fin  VARCHAR2(50);
BEGIN
  DELETE FROM FUZPART WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  FOR reg_fuz IN (
    SELECT TFP.CodPartInit, TFP.CodPartFin, TFP.CodLocInit, TFP.CodLocFin, PFI.CodFiscal AS CodFiscInit, PFF.CodFiscal AS CodFiscFin, PI.CodExtern AS CodExtInit, PF.CodExtern AS CodExtFin
    FROM TMP_FUZPART TFP
      LEFT JOIN NPART        PI  ON PI.CodPart  = TFP.CodPartInit
      LEFT JOIN NPART        PF  ON PF.CodPart  = TFP.CodPartFin
      LEFT JOIN NPARTCODFISC PFI ON PFI.CodPart = TFP.CodPartInit AND PFI.Principal = 1
      LEFT JOIN NPARTCODFISC PFF ON PFF.CodPart = TFP.CodPartFin  AND PFF.Principal = 1
  ) LOOP
    BEGIN
      SELECT Coalesce(NL.Den_Localit, &apos;..nedefinit..&apos;) INTO den_localit_init
      FROM NLOCALIT NL LEFT JOIN NAGENDA NA ON NA.CodLocalit = NL.CodLocalit
      WHERE NA.CodPart = reg_fuz.CodPartInit AND NA.SediuSocial IN (4, 5, 6, 7) AND Coalesce(NA.Inactiv, 0) = 0;
    EXCEPTION
      WHEN OTHERS THEN den_localit_init := &apos;..nedefinit..&apos;;
    END;
    BEGIN
      SELECT Coalesce(NL.Den_Localit, &apos;..nedefinit..&apos;) INTO den_localit_fin
      FROM NLOCALIT NL LEFT JOIN NAGENDA NA ON NA.CodLocalit = NL.CodLocalit
      WHERE NA.CodPart = reg_fuz.CodPartFin AND NA.SediuSocial IN (4, 5, 6, 7) AND Coalesce(NA.Inactiv, 0) = 0;
    EXCEPTION
      WHEN OTHERS THEN den_localit_fin := &apos;..nedefinit..&apos;;
    END;
    INSERT INTO FUZPART (CodPartInit, CodPartFin, CodLocInit, CodLocFin, CodFiscInit, CodFiscFin, CodExtInit, CodExtFin, LocalitInit, LocalitFin, UserID, UserStr)
    VALUES (reg_fuz.CodPartInit, reg_fuz.CodPartFin, reg_fuz.CodLocInit, reg_fuz.CodLocFin, reg_fuz.CodFiscInit, reg_fuz.CodFiscFin, reg_fuz.CodExtInit, reg_fuz.CodExtFin, den_localit_init, den_localit_fin,  p_userid, p_userstr);
  END LOOP;
  COMMIT;
END;

PROCEDURE SWITCH_FUZ(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
BEGIN
  DELETE FROM TMP_FUZPART;
  DELETE FROM FUZPART
  WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
  COMMIT;
END;

PROCEDURE GENERARE_LISTA_FUZIONARE(p_userid IN NUMBER, p_userstr IN VARCHAR2, p_criteriu_filtrare IN NUMBER DEFAULT 0, p_nr_inreg IN NUMBER DEFAULT 0) IS
  aNumarInreg   NUMERIC      := Coalesce(p_nr_inreg, 0);
  cSQL          CLOB;
  vFuzPartLast  VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;FuzPartLast&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),&apos;2&apos;);
BEGIN
  -- 0 - criteriu cod fiscal principal pj
  -- 1 - criteriu codextern pj
  -- 2 - telefon sediu social pj
  cSQL :=
  &apos;INSERT INTO FUZPART (CODPARTINIT, CODPARTFIN, CODLOCINIT, CODLOCFIN, CODEXTINIT,  CODEXTFIN,   CODFISCINIT, CODFISCFIN,  TELEFONINIT, TELEFONFIN, USERID,  USERSTR)
  WITH dbl AS (
    SELECT codpart, codfiscal, codextern, telefon, sCUI, ord, Dense_Rank() OVER (ORDER BY SimbTara, MatchString) NrI
    FROM (
      SELECT
        codpart, codfiscal, codextern, telefon, sCUI, SimbTara, MatchString,
        Count(1)     OVER (PARTITION BY SimbTara, MatchString)                  cnt,
        Row_Number() OVER (PARTITION BY SimbTara, MatchString ORDER BY codpart &apos;||CASE WHEN vFuzPartLast = &apos;1&apos; THEN &apos; DESC &apos; ELSE &apos; ASC &apos; END||&apos;) ord
      FROM (
        SELECT
          codpart, codfiscal, codextern, telefon, sCUI,
          COALESCE(SimbTara, CASE WHEN Length(regexp_replace(SubStr(sCUI,1,2), &apos;&apos;[[:digit:]]&apos;&apos;, &apos;&apos;&apos;&apos;)) = 2 THEN SubStr(sCUI,1,2) END) AS SimbTara,
          NULLIF(&apos;||CASE p_criteriu_filtrare
                      WHEN 0 then &apos;regexp_replace(codfiscal, &apos;&apos;[^[:digit:]]&apos;&apos;, &apos;&apos;&apos;&apos;)&apos;
                      WHEN 1 then &apos;regexp_replace(codextern, &apos;&apos;\W+&apos;&apos;, &apos;&apos;&apos;&apos;)&apos;
                      WHEN 2 then &apos;regexp_replace(telefon, &apos;&apos;[^[:digit:]]&apos;&apos;, &apos;&apos;&apos;&apos;)&apos;
                    END||&apos;, &apos;&apos;&apos;&apos;) MatchString
        FROM (
          SELECT
            np.codpart, npcf.codfiscal, np.codextern, nag.telefon,
            Upper(REGEXP_REPLACE(npcf.codfiscal,&apos;&apos;\W+&apos;&apos;, &apos;&apos;&apos;&apos;)) AS sCUI,
            NULLIF(Upper(t.simbauto), &apos;&apos;&apos;&apos;) AS SimbTara
          FROM npart np
            LEFT JOIN npartcodfisc npcf ON np.codpart   = npcf.codpart   AND npcf.principal = 1
            LEFT JOIN nagenda      nag  ON np.codpart   = nag.codpart    AND nag.sediusocial = 7
            LEFT JOIN nlocalit     l    ON l.codlocalit = nag.codlocalit
            LEFT JOIN ntari        t    ON t.codtara    = l.codtara
          WHERE np.persoanafizica = 0
        ) subA
      ) subB
      WHERE SimbTara    IS NOT NULL
        AND MatchString IS NOT NULL &apos;||CASE p_criteriu_filtrare WHEN 2 THEN &apos; AND Length(MatchString) &gt;= 4 &apos; ELSE &apos;&apos; END||&apos;
    ) subC
    WHERE cnt &gt; 1
  )      --(CODPARTINIT, CODPARTFIN, CODLOCINIT, CODLOCFIN, CODEXTINIT,  CODEXTFIN,   CODFISCINIT, CODFISCFIN,  TELEFONINIT, TELEFONFIN, USERID,  USERSTR)
  SELECT    b.codpart,   a.codpart,  -1,         -1,        b.codextern, a.codextern, b.codfiscal, a.codfiscal, b.telefon,   a.telefon,  :userid, :userstr
  FROM dbl A LEFT JOIN dbl B ON b.NrI = a.NrI AND b.ORD = 1
  WHERE a.ord &gt; 1&apos;||CASE WHEN aNumarInreg = 0 THEN &apos;&apos; ELSE &apos; AND a.NrI &lt;= &apos;||To_Char(aNumarInreg) END;
  EXECUTE IMMEDIATE cSQL USING p_userid, p_userstr;
  COMMIT;
END;

END PKG_FUZPART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_FUZPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F066B3F6C59546840134D063AFBDBCB3C217CC35</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_FUZPERS IS

	FUNCTION GET_SUBUNIT(pers IN NUMBER) RETURN VARCHAR2 IS
    den_subunitate VARCHAR2(30);
  BEGIN
    SELECT NVL(NS.Den_Subunit, &apos;..nedefinit..&apos;) INTO den_subunitate
    FROM NSUBUNIT NS
    LEFT OUTER JOIN NPERS NP ON NP.CodSubunit = NS.CodSubunit
    WHERE NP.CodPers = pers;
    RETURN den_subunitate;
    EXCEPTION WHEN OTHERS THEN RETURN &apos;..nedefinit..&apos;;
	END;

  FUNCTION VER_SUBUNIT(persinit IN NUMBER, persfin IN NUMBER) RETURN NUMBER IS
	  subunit_init NUMBER(20);
		subunit_fin NUMBER(20);
  BEGIN
    SELECT NVL(CODSUBUNIT, 0) INTO subunit_init FROM NPERS WHERE CodPers = persinit;
    SELECT NVL(CODSUBUNIT, 0) INTO subunit_fin FROM NPERS WHERE CodPers = persfin;
    IF subunit_init = subunit_fin THEN RETURN 0; ELSE RETURN 1; END IF;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  FUNCTION FUZ_PERS_SUB(persinit IN NUMBER, persfin IN NUMBER) RETURN BOOLEAN IS
    lCodPartTr_old NUMBER(20);
    lCodPartTr_new NUMBER(20);
    lCount         NUMBER(20);
  BEGIN

    SAVEPOINT FUZPERS;

    -------------------------------------
    -- structuri gasite din intamplare --
    -------------------------------------

    -- DISTRIB1
    UPDATE Distrib1 SET CodPers = persfin WHERE CodPers = persinit;

    -- OSPATARI
    UPDATE Ospatari SET CodPers = persfin WHERE CodPers = persinit;

    -- PLANCURS
    UPDATE PlanCurs SET CodPers = persfin WHERE CodPers = persinit;

    -- SALI
    UPDATE Sali SET CodPers = persfin WHERE CodPers = persinit;

    -- STOCINI
    UPDATE StocIni SET CodPers = persfin WHERE CodPers = persinit;

    -- OBLIGPIF (CodPart = CodPers cand Semnificatie = 800, 801, 1100, 1101)
    UPDATE ObligPIF SET CodPart = persfin WHERE CodPart = persinit AND Semnificatie IN (1100, 1101);
    ------------------------------------------------
    -- de aici iau la puricat machetele in Delphi --
    ------------------------------------------------

    -- Daca da eroare ca returneaza mai mult de o inregistrare atunci au asignat in mod ilogic mai multi delegati aceleiasi persoane
    -- NPARTTR:NPERS ar trebui sa fie 1:1
    BEGIN
      SELECT CodPartTr INTO lCodPartTr_new FROM NPartTr WHERE CodPers = persfin;
      SELECT CodPartTr INTO lCodPartTr_old FROM NPartTr WHERE CodPers = persinit;
      EXCEPTION WHEN NO_DATA_FOUND THEN BEGIN
        lCodPartTr_new := 0;
        lCodPartTr_old := 0;
      END;
    END;

    -- NGEST (Gestionar)
    UPDATE NGest SET CodGestionar = persfin WHERE CodGestionar = persinit;

    -- INTRARI (Expeditie = Delegat) -&gt; NPARTTR (CodPers &lt;&gt; 0 pentru delegatii firmei curente, CodPers = 0 pentru delegatii clientului)
    -- TRANSF  (Delegat = Delegat)   -&gt; NPARTTR (CodPers)
    IF (lCodPartTr_new &gt; 0) AND (lCodPartTr_old &gt; 0) THEN
      UPDATE Intrari SET Delegat = lCodPartTr_new WHERE Delegat = lCodPartTr_old;
      UPDATE Transf  SET Delegat = lCodPartTr_new WHERE Delegat = lCodPartTr_old;
    END IF;
    DELETE FROM NPartTr WHERE CodPers = persinit;

    -- INVENTAR (Responsabil)
    UPDATE Inventar SET Responsabil = persfin WHERE Responsabil = persinit;

    -- IESIRI (Persoana care consuma = CodPers)
    -- IESIRI (Agent = Agent, Delegat = Delegat + CodPers in anumite cazuri) -&gt; NPARTTR (CodPers)
    UPDATE Iesiri SET CodPers = persfin WHERE CodPers = persinit;
    UPDATE Iesiri SET Agent   = persfin WHERE Agent   = persinit;
    IF (lCodPartTr_new &gt; 0) AND (lCodPartTr_old &gt; 0) THEN
      UPDATE Iesiri SET Delegat = lCodPartTr_new WHERE Delegat = lCodPartTr_old;
    END IF;

    -- MONETARE (Agent = Agent)
    UPDATE Iesiri1 SET CodAgentEmulare  = persfin WHERE CodAgentEmulare   = persinit;

    -- EMULARE (Miscari interne: Operator = CodPers)
    -- EMULARE (Agent = CodAgent)
    UPDATE Emulare SET CodPers = persfin WHERE CodPers = persinit;
    UPDATE Emulare SET CodAgent = persfin WHERE CodAgent = persinit;

    -- EMULARERETAIL
    UPDATE EmulareRetail SET CodPers = persfin WHERE CodPers = persinit;
    UPDATE EmulareRetail SET CodAgent = persfin WHERE CodAgent = persinit;

    -- MIFIX1 (Imobilizari - Rezolvare mijloace fixe din stoc: Responsabil = CodPers)
    UPDATE MiFix1 SET CodPers = persfin WHERE CodPers = persinit;

    -- UTILAJE2P (Imobilizari - Nomenclator Utilaje: Angajat = CodPers)
    UPDATE Utilaje2P SET CodPers = persfin WHERE CodPers = persinit;

    -- TREZOR (Agent = CodPers)
    UPDATE Trezor SET Agent = persfin WHERE Agent = persinit;

    -- TREZOR1 (Agent = CodPers)
    UPDATE Trezor1 SET Agent   = persfin WHERE Agent   = persinit;
    UPDATE Trezor1 SET CodPart = persfin WHERE CodPart = persinit AND ObiectTranz = 2;

    -- TREZOR (Justificare avans decont: Persoana = CodBanca = CodPers cand TipDoc = 33)
    UPDATE Trezor SET CodBanca = persfin WHERE CodBanca = persinit AND TipDoc = 33;

    -- COMPENS (Agent incasator = Agent = CodPers)
    UPDATE Compens SET Agent = persfin WHERE agent = persinit;

    -- REGPERS1
    UPDATE RegPers1 SET CodPers = persfin WHERE CodPers = persinit;

    -- CONVERTCURSPERS
    UPDATE ConvertCursPers SET CodPers = persfin WHERE CodPers = persinit;

    -- SOLDPERSINI
    -- Daca exista CodPers = persfin atunci sterg CodPers = persinit, fiind necesara doar o inregistrare
    -- Mai jos refac NPersSoldLuna si NPersSoldLunaSub
    SELECT COUNT(*) INTO lCount FROM SoldPersIni WHERE CodPers = persfin;
    IF lCount &gt; 0 THEN
      DELETE FROM SoldPersIni WHERE CodPers = persinit;
    ELSE
      UPDATE SoldPersIni SET CodPers = persfin WHERE CodPers = persinit;
    END IF;

    -- NPERSSOLDLUNA si NPERSSOLDLUNASUB
    -- Refac NPersSoldLuna si NPersSoldLunaSub, contin date agregate la nivel de ICont
    FOR fPersInit IN
      (SELECT * FROM NPersSoldLuna WHERE CodPers = persinit)
    LOOP
      SELECT COUNT(*) INTO lCount FROM NPersSoldLuna
      WHERE
        CodPers = persfin AND
        An = fPersInit.An AND Luna = fPersInit.Luna AND
        CodMoneda = fPersInit.CodMoneda AND
        ICont = fPersInit.ICont;
      IF lCount = 1 THEN
        UPDATE NPersSoldLuna
        SET
          SoldLei = SoldLei + fPersInit.SoldLei,
          SoldValuta = SoldValuta + fPersInit.SoldValuta
        WHERE
          CodPers = persfin AND
          An = fPersInit.An AND Luna = fPersInit.Luna AND
          CodMoneda = fPersInit.CodMoneda AND
          ICont = fPersInit.ICont;
        DELETE FROM NPersSoldLuna WHERE CodPers = fPersInit.CodPersSoldLuna;
      ELSE
        UPDATE NPersSoldLuna SET CodPers = persfin WHERE CodPers = fPersInit.CodPers;
      END IF;
    END LOOP;
    FOR fPersInitSub IN
      (SELECT * FROM NPersSoldLunaSub WHERE CodPers = persinit)
    LOOP
      SELECT COUNT(*) INTO lCount FROM NPersSoldLunaSub
      WHERE
        CodPers = persfin AND
        An = fPersInitSub.An AND Luna = fPersInitSub.Luna AND
        CodMoneda = fPersInitSub.CodMoneda AND
        ICont = fPersInitSub.ICont AND
        Subunitatea = fPersInitSub.Subunitatea;
      IF lCount = 1 THEN
        UPDATE NPersSoldLunaSub
        SET
          SoldLei = SoldLei + fPersInitSub.SoldLei,
          SoldValuta = SoldValuta + fPersInitSub.SoldValuta
        WHERE
          CodPers = persfin AND
          An = fPersInitSub.An AND Luna = fPersInitSub.Luna AND
          CodMoneda = fPersInitSub.CodMoneda AND
          ICont = fPersInitSub.ICont AND
          Subunitatea = fPersInitSub.Subunitatea;
        DELETE FROM NPersSoldLunaSub WHERE CodPersSoldLunaSub = fPersInitSub.CodPersSoldLunaSub;
      ELSE
        UPDATE NPersSoldLUnaSub SET CodPers = persfin WHERE CodPers = fPersInitSub.CodPers;
      END IF;
    END LOOP;

    -- NPARCAUT (Sofer = CodPers)
    UPDATE NParcAut SET Sofer = persfin WHERE Sofer = persinit;

    -- COMANDA (Delegat = CodPers, Agent = CodPers)
    UPDATE Comanda SET Delegat = persfin WHERE Delegat = persinit;
    UPDATE Comanda SET Agent   = persfin WHERE Agent   = persinit;

    -- COMANDA :4:5:6
    UPDATE Comanda SET CodPers_APL_EXT = persfin WHERE CodPers_APL_EXT = persinit;
    UPDATE Comanda SET Insotitor       = persfin WHERE Insotitor       = persinit;

    -- TARGETAG (Agent = CodPers)
    UPDATE TargetAg SET Agent = persfin WHERE Agent = persinit;

    -- BCAR (CodDelegat) -&gt; NPARTTR (CodPers)
    IF (lCodPartTr_new &gt; 0) AND (lCodPartTr_old &gt; 0) THEN
      UPDATE BCAR SET CodDelegat = lCodPartTr_new WHERE CodDelegat = lCodPartTr_old;
    END IF;

    -- OFERTA (Agent = CodPers)
    UPDATE Oferta SET Agent = persfin WHERE Agent = persinit;

    -- CONTRACT (Agent = CodPers)
    UPDATE Contract SET Agent = persfin WHERE Agent = persinit;

    -- RAPORTP1 (Angajat = CodPers)
    UPDATE RaportP1 SET Angajat = persfin WHERE Angajat = persinit;

    -- OREPONTAJ (Pontaj: CodPers)
    UPDATE OrePontaj SET CodPers = persfin WHERE CodPers = persinit;

    -- DESCRIPTORI1 (CodAsociat = CodPest cand in DESCRIPTORI Tip = 50 = Personal)
    FOR fDescriptori IN
      (SELECT * FROM Descriptori WHERE Tip = 50)
    LOOP
      UPDATE Descriptori1 SET CodAsociat = persfin WHERE CodAsociat = persinit AND CodDescriptor = fDescriptori.CodDescriptor;
    END LOOP;

    -- NC1
    UPDATE NC1 SET Agent = persfin WHERE Agent = persinit;

    -- NPERSCVLOCM
    UPDATE NPersCVLocM SET CodPers = persfin WHERE CodPers = persinit;

    -- NPERSCVPAS
    UPDATE NPersCVPas SET CodPers = persfin WHERE CodPers = persinit;

    -- NPERSCVSCOL
    UPDATE NPersCVScol SET CodPers = persfin WHERE CodPers = persinit;

    -- NPERSCVSKIL
    UPDATE NPersCVSkil SET CodPers = persfin WHERE CodPers = persinit;

    -- NPERS1
    --UPDATE NPers1 SET CodPers = persfin WHERE CodPers = persinit;
    DELETE FROM NPers1 WHERE CodPers = persinit;

    -- NPERS
    DELETE FROM NPERS  WHERE CodPers = persinit;

    COMMIT;
    RETURN TRUE;

    EXCEPTION WHEN OTHERS THEN
    BEGIN
      ROLLBACK TO FUZPERS;
      RETURN FALSE;
    END;
  END;

  PROCEDURE FUZ_PERS_MAIN(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  BEGIN
    FOR reg_fuzpers IN
      (SELECT
         FP.CodPersInit, FP.CodPersFin,
         FP.SubunitInit, FP.SubunitFin,
         NPI.Prenume || &apos; &apos; || NPI.Nume AS DenPersInit, NPF.Prenume || &apos; &apos; || NPF.Nume AS DenPersFin
       FROM
         FUZPERS FP
         INNER JOIN NPERS NPI ON NPI.CodPers = FP.CodPersInit
         INNER JOIN NPERS NPF ON NPF.CodPers = FP.CodPersFin
       WHERE
         FP.UserID = p_userid AND
         FP.UserStr = p_userstr AND
         FP.Data IS NULL)
    LOOP
      IF FUZ_PERS_SUB(reg_fuzpers.CodPersInit, reg_fuzpers.CodPersFin) THEN
        UPDATE FUZPERS
        SET
          Data = SYSDATE,
          InfoInit = &apos;CodPers = &apos; || TO_CHAR(reg_fuzpers.CodPersInit) ||
                     &apos;, DenPers = &apos; || reg_fuzpers.DenPersInit ||
                     &apos;, DenSubunit = &apos; || reg_fuzpers.SubunitInit,
          InfoFin = &apos;CodPers = &apos; || TO_CHAR(reg_fuzpers.CodPersFin) ||
                    &apos;, DenPers = &apos; || reg_fuzpers.DenPersFin ||
                    &apos;, DenSubunit = &apos; || reg_fuzpers.SubunitFin
        WHERE
          CodPersInit = reg_fuzpers.CodPersInit AND
          CodPersFin = reg_fuzpers.CodPersFin AND
          UserID = p_userid AND
          UserStr = p_userstr AND
          Data IS NULL;
      END IF;
    END LOOP;
    COMMIT;
  END;

  PROCEDURE CLR_TMP IS
  BEGIN
    DELETE FROM TMP_FUZPERS;
    COMMIT;
  END;

  PROCEDURE GET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  BEGIN
    DELETE FROM TMP_FUZPERS;
    INSERT INTO TMP_FUZPERS
      (CodPersInit, CodPersFin, SubunitInit, SubunitFin)
      (SELECT CodPersInit, CodPersFin, SubunitInit, SubunitFin
       FROM FUZPERS
       WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL);
    COMMIT;
  END;

  PROCEDURE SET_TMP(p_userid IN NUMBER, p_userstr IN VARCHAR2) IS
  BEGIN
    DELETE FROM FUZPERS WHERE UserID = p_userid AND UserStr = p_userstr AND Data IS NULL;
    INSERT INTO FUZPERS
      (CodPersInit, CodPersFin, SubunitInit, SubunitFin, /*InfoInit, InfoFin,*/ UserID, UserStr, Data)
      (SELECT CodPersInit, CodPersFin, SubunitInit, SubunitFin, /*&apos;&apos;, &apos;&apos;,*/ p_userid, p_userstr, NULL
       FROM TMP_FUZPERS);
    COMMIT;
  END;

END PKG_FUZPERS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GAMEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96B944D93713AD1153479A83308FF07B8AE3309E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GAMEART is

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodGama INTO Tmp FROM NGameArt WHERE CodGama = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NGAMEART WHERE CodGama = RecId;
  NotifyModif(2, RecId, &apos;NGAMEART&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NGAMEART FIELDS(CodGama) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_NGAMEART 
  (SELECT * FROM NGAMEART WHERE CodGama = RecId);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
BEGIN
  IF Operation = 0 THEN -- UPDATE
    SELECT CodGama INTO RecId FROM TMP_NGAMEART;
    UPDATE NGAMEART
    SET 
      Denumire = (SELECT Denumire FROM TMP_NGAMEART)
    WHERE 
      CodGama = RecId;
  ELSE  -- INSERT
    SELECT SEQ_NGAMEART_CODGAMA.NextVal INTO RecId FROM DUAL;
    INSERT INTO NGAMEART (CodGama, Denumire)
    (SELECT RecId, Denumire FROM TMP_NGameArt);
  END IF;
  NotifyModif(Operation, RecId, &apos;NGAMEART&apos;);
  COMMIT;
END;


end PKG_GAMEART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GENCMDF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8973BD9D8FA8D86BE30E0989051C065991EB81B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GENCMDF is

procedure PreiaDate(aCodPart in number, acodlocatie in number default 0) is
begin
  insert into tmp_aproviz_part(denumire,
                               codextern,
                               codintern,
                               denlaclient,
                               codexterncli,
                               sediu,
                               stocmin,
                               stocmax,
                               stoc,
                               codobiect,
                               codlocatie,
                               pret)
  SELECT o.denumire, o.codextern, o.codintern, cli.denumire denlaclient, cli.codextern, 
         ag.obs sediu, coalesce(os.stocmin,o.stocmin,0) stocmin, coalesce(os.stocmax,o.stocmax,0) stocmax, 0 Stoc, o.codobiect, ag.codagenda,
         cast(0 as number(20,7))
  FROM
    nartobj o
    left join nartobjsubunit os on os.codobiect = o.codobiect and os.subunitate = pkg_globals.GETSUBUNITATE,
    nartcli cli, nagenda ag 
  WHERE
    o.codobiect = cli.codobiect
    and (acodlocatie = 0 or ag.codagenda = acodlocatie)
    and cli.codpart = aCodPart
    and ag.codpart = aCodPart;
  commit;  
end;  

procedure SalvareDate is
aCount number(20);  
begin
  for v_rec in (select codexterncli,codlocatie,stocmin,stocmax from tmp_aproviz_part) loop
    select count(*) into acount from stocmpart where codextern = v_rec.codexterncli and codlocatie = v_rec.codlocatie;
    if acount = 0 then 
      insert into stocmpart(codlocatie,
                            codextern,
                            stocmin,
                            stocmax)
      values (v_rec.codlocatie,v_rec.codexterncli,v_rec.stocmin,v_rec.stocmax);                      
    else
      update stocmpart set
      stocmin = v_rec.stocmin,
      stocmax = v_rec.stocmax
      where codextern = v_rec.codexterncli and codlocatie = v_rec.codlocatie;
    end if;
  end loop;
  commit;
end;

procedure ClearTemp is
begin
  delete tmp_aproviz_part;
  commit;
end;  

end PKG_GENCMDF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GENERARE_CODURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91201F2DEE2B04910B206C1B229B3BAF65EE0523</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GENERARE_CODURI IS

-- IDSEDIU
PROCEDURE UNLOCK_IDSEDIU(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM IDSEDIULOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_IDSEDIU(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM IDSEDIULOCK
  WHERE 
   IDSEDIU   = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO IDSEDIULOCK (COD, IDSEDIU, USERID)
    VALUES (SEQ_IDSEDIULOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_IDSEDIU(aUSERID IN NUMBER) RETURN VARCHAR2
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
BEGIN
 GATA := 0; 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(IDSEDIU), 0) + 1 INTO NEXTCOD
  FROM
  (
    SELECT NVL(MAX(TO_NUMBER(IDSEDIU)), 0) AS IDSEDIU
    FROM 
      NAGENDA
    WHERE 
      PKG_GLOBALS.ISNUMERIC(IDSEDIU) = 1
    UNION ALL
    SELECT NVL(MAX(TO_NUMBER(IDSEDIU)), 0) AS IDSEDIU
    FROM 
      IDSEDIULOCK 
  );
  IF CAN_LOCK_IDSEDIU(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN TO_CHAR(NEXTCOD);
  END IF;
  END LOOP;
END;




-- parteneri 
-- CODINTERN
PROCEDURE UNLOCK_CODINTERN_PART(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CODINTPARTLOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_CODINTERN_PART(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CODINTPARTLOCK
  WHERE 
   CODINTERN   = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO CODINTPARTLOCK (COD, CODINTERN, USERID)
    VALUES (SEQ_CODINTPARTLOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_CODINTERN_PART(aUSERID IN NUMBER) RETURN VARCHAR2
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
BEGIN
 GATA := 0; 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(CODINTERN), 0) + 1 INTO NEXTCOD
  FROM
  (
    SELECT NVL(MAX(TO_NUMBER(CODINTERN)), 0) AS CODINTERN
    FROM 
      NPART 
    WHERE 
      PKG_GLOBALS.ISNUMERIC(CODINTERN) = 1
    UNION ALL
    SELECT NVL(MAX(TO_NUMBER(CODINTERN)), 0) AS CODINTERN
    FROM 
      CODINTPARTLOCK 
  );
  IF CAN_LOCK_CODINTERN_PART(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN TO_CHAR(NEXTCOD);
  END IF;
  END LOOP;
END;

-- parteneri 
-- CODEXTERN
PROCEDURE UNLOCK_CODEXTERN_PART(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CODEXTPARTLOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_CODEXTERN_PART(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CODEXTPARTLOCK
  WHERE 
   CODEXTERN   = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO CODEXTPARTLOCK (COD, CODEXTERN, USERID)
    VALUES (SEQ_CODEXTPARTLOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_CODEXTERN_PART(aUSERID IN NUMBER) RETURN NUMBER
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
BEGIN
 GATA := 0; 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(CODEXTERN), 0) + 1 INTO NEXTCOD
  FROM
  (
    SELECT NVL(MAX(TO_NUMBER(CODEXTERN)), 0) AS CODEXTERN
    FROM 
      NPART 
    WHERE 
      PKG_GLOBALS.ISNUMERIC(CODEXTERN) = 1

    UNION ALL

    SELECT NVL(MAX(TO_NUMBER(CODEXTERN)), 0) AS CODEXTERN
    FROM 
      CODEXTPARTLOCK 
  );
  IF CAN_LOCK_CODEXTERN_PART(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN NEXTCOD;
  END IF;
  END LOOP;
END;




-- ARTICOLE
-- COD EXTERN
PROCEDURE UNLOCK_CODEXTERN_ART(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CODEXTARTLOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_CODEXTERN_ART(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CODEXTARTLOCK
  WHERE 
   CODEXTERN   = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO CODEXTARTLOCK (COD, CODEXTERN, USERID)
    VALUES (SEQ_CODEXTARTLOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_CODEXTERN_ART(aUSERID IN NUMBER) RETURN NUMBER
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
  CODEXTSTART VARCHAR2(20) := &apos;0&apos;;
BEGIN
 GATA := 0; 

 BEGIN
   SELECT PKG_CATEGCONST.GetValConstanta(&apos;CodExtArtStart&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO   CODEXTSTART FROM DUAL;
   EXCEPTION WHEN OTHERS THEN CODEXTSTART := &apos;0&apos;; 
 END;  

 IF PKG_GLOBALS.ISNUMERIC(CODEXTSTART) = 0 THEN
   CODEXTSTART := &apos;0&apos;;
 END IF;
 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(CODEXTERN), 0) + 1 INTO NEXTCOD
  FROM
  (
    SELECT TO_NUMBER(NVL(CODEXTSTART, 0)) - 1 AS CODEXTERN FROM DUAL
    UNION ALL     

    SELECT NVL(MAX(TO_NUMBER(CODEXTERN)), 0) AS CODEXTERN
    FROM 
      NARTOBJ
    WHERE 
      PKG_GLOBALS.ISNUMERIC(CODEXTERN) = 1

    UNION ALL

    SELECT NVL(MAX(TO_NUMBER(CODEXTERN)), 0) AS CODEXTERN
    FROM 
      CODEXTARTLOCK 
  );
  IF CAN_LOCK_CODEXTERN_ART(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN NEXTCOD;
  END IF;
  
  END LOOP;
  
END;


-- ARTICOLE
-- COD INTERN
PROCEDURE UNLOCK_CODINTERN_ART(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CODINTARTLOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_CODINTERN_ART(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CODINTARTLOCK
  WHERE 
   CODINTERN   = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO CODINTARTLOCK (COD, CODINTERN, USERID)
    VALUES (SEQ_CODINTARTLOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_CODINTERN_ART(aUSERID IN NUMBER) RETURN NUMBER
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
  CODINTSTART VARCHAR2(20) := &apos;0&apos;;
BEGIN
 GATA := 0; 

 BEGIN
   SELECT PKG_CATEGCONST.GetValConstanta(&apos;CodIntArtStart&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO   CODINTSTART FROM DUAL;
   EXCEPTION WHEN OTHERS THEN CODINTSTART := &apos;0&apos;; 
 END;  

 IF PKG_GLOBALS.ISNUMERIC(CODINTSTART) = 0 THEN
   CODINTSTART := &apos;0&apos;;
 END IF;
 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(CODINTERN), 0) + 1 INTO NEXTCOD
  FROM
  (
    SELECT TO_NUMBER(NVL(CODINTSTART, 0)) - 1 AS CODINTERN FROM DUAL
    UNION ALL     

    SELECT NVL(MAX(TO_NUMBER(CODINTERN)), 0) AS CODINTERN
    FROM 
      NARTOBJ
    WHERE 
      PKG_GLOBALS.ISNUMERIC(CODINTERN) = 1

    UNION ALL

    SELECT NVL(MAX(TO_NUMBER(CODINTERN)), 0) AS CODINTERN
    FROM 
      CODINTARTLOCK 
  );
  IF CAN_LOCK_CODINTERN_ART(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN NEXTCOD;
  END IF;
  
  END LOOP;
  
END;


-- GENERARE ALL
-- ARTICOLE
PROCEDURE GEN_ALL_ART_CODEXTERN_UNIC(aUSERID IN NUMBER)
IS 
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_NARTOBJ;

  INSERT INTO TMP_NARTOBJ(CODOBIECT, CODEXTERN) VALUES (0, NULL);
  INSERT INTO TMP_NARTOBJ(CODOBIECT, CODEXTERN) 
  SELECT CODOBIECT, PKG_GENERARE_CODURI.GET_NEXT_CODEXTERN_ART(aUSERID) 
  FROM 
    NARTOBJ
  WHERE
   CODEXTERN IS NULL AND CODOBIECT &lt;&gt; 0;
  
  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ)
  LOOP
    UPDATE NARTOBJ
    SET
      CODEXTERN = V_REC.CODEXTERN
    WHERE
      CODOBIECT = V_REC.CODOBIECT and CODOBIECT &lt;&gt; 0;  
  END LOOP;     
  COMMIT; 
  UNLOCK_CODEXTERN_ART(aUSERID);
END;


PROCEDURE GEN_ALL_ART_CODINTERN_UNIC(aUSERID IN NUMBER)
IS 
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_NARTOBJ;

  INSERT INTO TMP_NARTOBJ(CODOBIECT, CODINTERN) VALUES (0, NULL);
  INSERT INTO TMP_NARTOBJ(CODOBIECT, CODINTERN) 
  SELECT CODOBIECT, PKG_GENERARE_CODURI.GET_NEXT_CODINTERN_ART(aUSERID) 
  FROM 
    NARTOBJ
  WHERE
   CODINTERN IS NULL AND CODOBIECT &lt;&gt; 0;
  
  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ)
  LOOP
    UPDATE NARTOBJ
    SET
      CODINTERN = V_REC.CODINTERN
    WHERE
      CODOBIECT = V_REC.CODOBIECT and CODOBIECT &lt;&gt; 0;  
  END LOOP;     
  COMMIT; 
  UNLOCK_CODINTERN_ART(aUSERID);

END;



-- GENERARE ALL
-- PARTENERI
PROCEDURE GEN_ALL_PART_CODEXTERN_UNIC(aUSERID IN NUMBER)
IS 
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_NPART;

  INSERT INTO TMP_NPART(CODPART, CODEXTERN) VALUES (0, NULL);
  INSERT INTO TMP_NPART(CODPART, CODEXTERN) 
  SELECT CODPART, PKG_GENERARE_CODURI.GET_NEXT_CODEXTERN_PART(aUSERID) 
  FROM 
    NPART
  WHERE
   CODEXTERN IS NULL AND CODPART &lt;&gt; 0;
  
  FOR V_REC IN (SELECT * FROM TMP_NPART)
  LOOP
    UPDATE NPART
    SET
      CODEXTERN = V_REC.CODEXTERN
    WHERE
      CODPART = V_REC.CODPART AND CODPART &lt;&gt; 0;  
  END LOOP;     
  COMMIT; 
  UNLOCK_CODEXTERN_PART(aUSERID);
END;


PROCEDURE GEN_ALL_PART_CODINTERN_UNIC(aUSERID IN NUMBER)
IS 
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_NPART;
  
  INSERT INTO TMP_NPART(CODPART, CODEXTERN) VALUES (0, NULL);
  INSERT INTO TMP_NPART(CODPART, CODINTERN) 
  SELECT CODPART, PKG_GENERARE_CODURI.GET_NEXT_CODINTERN_PART(aUSERID) 
  FROM 
    NPART
  WHERE
   CODINTERN IS NULL AND CODPART &lt;&gt; 0;
  
  FOR V_REC IN (SELECT * FROM TMP_NPART)
  LOOP
    UPDATE NPART
    SET
      CODINTERN = V_REC.CODINTERN
    WHERE
      CODPART = V_REC.CODPART and CODPART &lt;&gt; 0;  
  END LOOP;     
  COMMIT; 
  UNLOCK_CODINTERN_PART(aUSERID);
END;



PROCEDURE UPDATE_CODEXTERN_ART_FROM_TMP
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ)
  LOOP
    UPDATE NARTOBJ
    SET
      CODEXTERN = V_REC.CODEXTERN
    WHERE
      CODOBIECT = V_REC.CODOBIECT; 
  END LOOP;
  COMMIT;
END;

PROCEDURE UPDATE_CODINTERN_ART_FROM_TMP
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ)
  LOOP
    UPDATE NARTOBJ
    SET
     CODINTERN = V_REC.CODINTERN
    WHERE
      CODOBIECT = V_REC.CODOBIECT; 
  END LOOP;
  COMMIT;
END;


-- MARCA PERSONAL
PROCEDURE UNLOCK_MARCA_PERS(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM MARCALOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;

FUNCTION CAN_LOCK_MARCA_PERS(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM MARCALOCK
  WHERE 
   MARCA    = aCOD;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO MARCALOCK (COD, MARCA, USERID)
    VALUES (SEQ_MARCALOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;

FUNCTION GET_NEXT_MARCA_PERS(aUSERID IN NUMBER) RETURN NUMBER
IS
  NEXTCOD NUMBER(30) := 0;
  GATA NUMBER(5);
BEGIN
 GATA := 0; 

 
 WHILE GATA = 0 LOOP
  SELECT NVL(MAX(MARCA), 0) + 1 INTO NEXTCOD
  FROM
  (

    SELECT NVL(MAX(TO_NUMBER(MARCA)), 0) AS MARCA
    FROM 
      NPERS
    WHERE 
      PKG_GLOBALS.ISNUMERIC(MARCA) = 1

    UNION ALL

    SELECT NVL(MAX(TO_NUMBER(MARCA)), 0) AS MARCA
    FROM 
      MARCALOCK
  );
  IF CAN_LOCK_MARCA_PERS(NEXTCOD, aUSERID) = 1 THEN
    GATA := 1;
    RETURN NEXTCOD;
  END IF;
  
  END LOOP;
  
END;



end PKG_GENERARE_CODURI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GENNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AAF0953A8F0C8375130187264A7CEB20D5DB1B5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GENNP is

procedure ClearMan is
aUserID number(20);
begin
  aUserID := PKG_GLOBALS.GETUSERID;
  delete TMP_GENNP_CMDMAN where UserID = aUserID;
  delete TMP_GENNP_CMD1 where UserID = aUserID;
  commit;
end;

procedure ClearCrs is
aUserID number(20);
begin
  aUserID := PKG_GLOBALS.GETUSERID;
  delete TMP_GENNP_CRS where UserID = aUserID;
  commit;
end;

procedure UpdateCmd1DinMan is
begin
  insert into TMP_GENNP_CMD1(CODCOMANDA1,USERID)
  select distinct MAN.codcomanda1,PKG_GLOBALS.GETUSERID
  from TMP_GENNP_CMDMAN TMP
       INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = TMP.CODCMDPRODMAN
  where tmp.userid = pkg_globals.getuserid;
  COMMIT;
end;

procedure ActualizeazaCmd1(aCodProgramF1 in number,
                           aCodComanda1 in number,
                           aCodObiect in number,
                           aPrioritate in number,
                           aCodGest in number,
                           aCodPers in number,
                           aCodFormatie in number,
                           aSchimb in number,
                           aTermen in varchar2,
                           aCant in number,
                           aUserID in number,
                           aRebut in number) is
oData date;
begin
  begin
    oData := to_date(aTermen, &apos;dd.mm.yyyy&apos;);
  exception when others then oData := null;
  end;

  MERGE INTO TMP_GENNP_CMD1 TMP
  USING (
    SELECT aCodProgramF1 CODPROGRAMF1,
           aCodComanda1 CODCOMANDA1,
           aCodObiect CODOBIECT,
           aPrioritate PRIORITATE,
           aCodGest CODGEST,
           aCodPers CODPERS,
           aCodFormatie CODFORMATIE,
           aSchimb SCHIMB,
           oData TERMEN,
           aCant CANT,
           aUserID USERID,
           aRebut REBUT
    FROM DUAL
        ) V
  ON (TMP.CODPROGRAMF1 = V.CODPROGRAMF1 AND TMP.USERID = V.USERID AND TMP.CODCOMANDA1 = V.CODCOMANDA1)
  WHEN MATCHED THEN UPDATE SET TMP.CANT = NVL(TMP.CANT,0) + V.CANT
  WHEN NOT MATCHED THEN INSERT (TMP.CODPROGRAMF1,TMP.CODCOMANDA1,TMP.CODOBIECT,TMP.PRIORITATE,TMP.CODGEST,TMP.CODPERS,TMP.CODFORMATIE,TMP.SCHIMB,TMP.TERMEN,TMP.CANT,TMP.USERID,TMP.REBUT)
                        VALUES (V.CODPROGRAMF1,V.CODCOMANDA1,V.CODOBIECT,V.PRIORITATE,V.CODGEST,V.CODPERS,V.CODFORMATIE,V.SCHIMB,V.TERMEN,V.CANT,V.USERID,V.REBUT);
  COMMIT;
end;

procedure ActualizeazaCmdMan(aCodCmdProdMan in number, aCant in number, aUserID in number) is
begin
  MERGE INTO TMP_GENNP_CMDMAN TMP
  USING (
    SELECT aCodCmdProdMan CODCMDPRODMAN, aCant CANT, aUserID USERID
    FROM DUAL
        ) V
  ON (TMP.CODCMDPRODMAN = V.CODCMDPRODMAN and TMP.USERID = V.USERID)
  WHEN MATCHED THEN UPDATE SET TMP.CANT = NVL(TMP.CANT,0) + V.CANT
  WHEN NOT MATCHED THEN INSERT (TMP.CODCMDPRODMAN,TMP.CANT,TMP.USERID)
                        VALUES (V.CODCMDPRODMAN,V.CANT,V.USERID);
  COMMIT;
end;

procedure ClearTemps is
begin
  delete TMP_GENNP_ART;
  delete TMP_GENNP_REZ;
  delete TMP_GENNP_MAN;
  delete TMP_GENNP_MAT;
  delete TMP_GENNP_MATC;
  commit;
end;

procedure GetCrsArt is
aUserID number(20);
aRapOrdMan NUMBER(10);
aPrelPretNP NUMBER(10);
begin
  aUserID := PKG_GLOBALS.GETUSERID;
  aRapOrdMan := pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru);
  aPrelPretNP := pkg_categconst.GetValConstanta(&apos;PrelPretNP&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru);
  IF aRapOrdMan = 1 THEN
    insert into TMP_GENNP_ART (
      CODINTR1,CODCOMANDA1,NRDOC,CODOBIECT,DENUMIRE,CODEXTERN,PRIORITATE,DURATAR,DURATA,TERMEN,UMSEC,PROGRAMAT,
      PROGRAMAT_P,PU,REALIZAT,REALIZAT_P,PREDAT,PREDAT_P,UM1,DEN_UMS,D1,D2,D3,RAPORTAT,RAPORTAT_P,REBUT,REBUT_P,
      RAPORTATUM1,RELATIEUM1,UM,PARITATE,DEN_UM1,TIPSERIE,CODFISA,AVIZAT,AREFISA,FISAMAS,PRET,PRET_P,CODCMDPRODMAT,
      CODPROGRAMF1,MASA,CODGESTNIR,CODLOCNIR,CODIOARTNIR,GESTNIR,GESTLOCCONT,LOCATIENIR,IOARTNIR,CODFORMATIE,SCHIMB,
      DONE,CODPERS,CODANALIZANOD,DEN_ANGAJAT,INCHISA,CODCOMANDA,CARNETNIR,DATADOC,CODGEST,PREDATTOT,PREDATTOT_P,RESTPF,
      CODRETETA,TOTAL,TOTALUM1,UTILAJ,ORASTART,NRSCHIMBURI,ORESCHIMB,OREPEZI,TIPARTICOL,OBSCLI,NRDOCCLI,CODINTERN,FROMPP,
      CONSUM, R_PREDAT
      )
    WITH FISA AS (SELECT PC.CODPRODCOMP, COUNT(PM.CODPRODMAS) NR
                  FROM PRODCOMP PC
                       INNER JOIN PRODMAS PM ON PC.CODPRODCOMP = PM.CODPRODCOMP
                  GROUP BY PC.CODPRODCOMP
                 )
    SELECT
      - RowNum CodIntr1,
      C1.CODCOMANDA1,
      ROUND(C.NRDOC + c1.indexlocal / 100, 3),
      C1.CODOBIECT,
      OBJ.DENUMIRE,
      OBJ.CODEXTERN,
      C1.NIVEL PRIORITATE,
      PC.DURATA DURATAR,
      0 DURATA,
      C1.TERMEN,
      C1.UMSEC,
      C1.CANTACCEPTAT PROGRAMAT,
      C1.CANTACCEPTAT PROGRAMAT_P,
      C1.PU,
      RZ.CANT REALIZAT,
      RZ.CANT REALIZAT_P,
      CASE WHEN C1.CONSUM = 2 THEN CS.CANT ELSE PR.CANT END PREDAT,
      CASE WHEN C1.CONSUM = 2 THEN CS.CANT ELSE PR.CANT END PREDAT_P,
      ART.UM1,
      UMS.DEN_UM Den_UMs,
      C1.D1,
      C1.D2,
      C1.D3,
      0 RAPORTAT,
      0 RAPORTAT_P,
      0 REBUT,
      0 REBUT_P,
      0 RAPORTATUM1,
      ART.RELATIEUM1,
      ART.UM,
      NUM1.PARITATE,
      NUM1.DEN_UM1,
      ART.TIPSERIE,
      0 CodFisa,
      0 Avizat,
      FISA.NR AreFisa,
      &apos;                       &apos; FisaMas,
      CASE WHEN aPrelPretNP = 2 THEN PC.PRET ELSE C1.PU END PRET,
      CASE WHEN aPrelPretNP = 2 THEN PC.PRET ELSE C1.PU END PRET_P,
      CMD.CODCMDPRODMAT,
      0 CODPROGRAMF1,
      OBJ.MASA Masa,
      nvl(ARTIMP.GESTIMPLICITA,0) CODGESTNIR,
      nvl(ARTIMP.LOCATIEIMPLICITA,0) CODLOCNIR,
      Nvl(IOANIR.CODIOArt,0) CODIOARTNIR,
      GNIR.DEN_GEST GESTNIR,
      GNIR.DEN_GEST||&apos;, &apos;||LOCNIR.DENUMIRE||CHR(13)||Nvl(IOANIR.DEN_IOART,&apos;?&apos;) AS GESTLOCCONT,
      LOCNIR.DENUMIRE LOCATIENIR,
      Nvl(IOANIR.DEN_IOART,&apos;?&apos;) IOARTNIR,
      C.CODFORMATIE,
      C.SCHIMB,
      0 DONE,
      0 CODPERS,
      C1.CodAnalizaNod,
      PERS.Nume||chr(13)||PERS.prenume Den_Angajat,
      NVL(C.INCHISA,0) INCHISA,
      C.CodComanda,
      0 CarnetNir,
      C.DataDoc,
      C.CodGest,
      PR.CANT PredatTot,
      PR.CANT PredatTot_P,
      nvl(PF.CANT,0) RESTPF,
      C1.CODRETETA,
      CMD.CANT Total,
      CMD.CANTUM1 TotalUM1,
      OBJU.DENUMIRE UTILAJ,
      G.ORASTART,
      G.NRSCHIMBURI,
      G.ORESCHIMB,
      case when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) &gt; 24 then 24 when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) = 0 then 24 else NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) end OrePeZi,
      ART.TIPARTICOL,
      CLI1.OBS OBSCLI,
      ROUND(CLI.NRDOC + CLI1.indexlocal / 100, 3) NRDOCCLI,
      OBJ.CODINTERN,
      0 AS FROMPP,
      C1.CONSUM,
      coalesce(R_PR.CANT,0)
    FROM TMP_GENNP_CMD1 PF1
      INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 0
      INNER JOIN NUM1 ON C1.UMSEC = NUM1.CODUM1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN NARTOBJ OBJ ON C1.CODOBIECT = OBJ.CODOBIECT
      INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
      INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
      INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
      LEFT JOIN COMANDA1 CLI1 ON CLI1.CODCOMANDA1 = PKG_COMANDA.DINCMDCLI(C1.CODCOMANDA1)
      LEFT JOIN COMANDA CLI ON CLI.CODCOMANDA = CLI1.CODCOMANDA
      LEFT JOIN NUM UMS ON UMS.CODUM = ART.UM1
      LEFT JOIN UTILAJE2C U2C ON C1.CODCOMANDA1 = U2C.CODCOMANDA1
      LEFT JOIN UTILAJE U ON U2C.CODUTILAJ = U.CODUTILAJ
      LEFT JOIN NARTOBJ OBJU ON U.CODOBIECT = OBJU.CODOBIECT
      LEFT JOIN NARTIMPLICITE ARTIMP ON ART.CODARTICOL = ARTIMP.CODARTICOL AND ARTIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NGEST GNIR ON NVL(ARTIMP.GESTIMPLICITA, 0) = GNIR.CODGEST
      LEFT JOIN NLOCATII LOCNIR ON NVL(ARTIMP.LOCATIEIMPLICITA, 0) = LOCNIR.CODLOCATIE
      LEFT JOIN NPERS PERS ON PF1.codcomanda1-pf1.codcomanda1  = PERS.CODPERS
      LEFT JOIN ioart IOANIR ON CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(ARTIMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END = IOANIR.CODIOART
      LEFT JOIN TMP_GENNP_CRS CS ON CS.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND CS.TIP = 1 AND CS.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 3 AND RZ.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND PR.TIP = 2 AND PR.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS R_PR ON R_PR.CODCMDPRODMAT = CMD.CODCOMANDA1 AND R_PR.TIP = 12 AND R_PR.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PF ON PF.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND ((PF1.CODPROGRAMF1 &gt; 0 AND PF.CODPROGRAMF1 = PF1.CODPROGRAMF1) OR NVL(PF1.CODPROGRAMF1,0) = 0)
                                    AND PF.TIP = 4 AND PF.USERID = aUserID
      LEFT JOIN FISA ON PC.CODPRODCOMP = FISA.CODPRODCOMP
    WHERE PF1.USERID = aUserID;
  ELSE
    insert into TMP_GENNP_ART (
      CODINTR1,CODCOMANDA1,NRDOC,CODOBIECT,DENUMIRE,CODEXTERN,PRIORITATE,DURATAR,DURATA,TERMEN,UMSEC,PROGRAMAT,
      PROGRAMAT_P,PU,REALIZAT,REALIZAT_P,PREDAT,PREDAT_P,UM1,DEN_UMS,D1,D2,D3,RAPORTAT,RAPORTAT_P,REBUT,REBUT_P,
      RAPORTATUM1,RELATIEUM1,UM,PARITATE,DEN_UM1,TIPSERIE,CODFISA,AVIZAT,AREFISA,FISAMAS,PRET,PRET_P,CODCMDPRODMAT,
      CODPROGRAMF1,MASA,CODGESTNIR,CODLOCNIR,CODIOARTNIR,GESTNIR,GESTLOCCONT,LOCATIENIR,IOARTNIR,CODFORMATIE,SCHIMB,
      DONE,CODPERS,CODANALIZANOD,DEN_ANGAJAT,INCHISA,CODCOMANDA,CARNETNIR,DATADOC,CODGEST,PREDATTOT,PREDATTOT_P,RESTPF,
      CODRETETA,TOTAL,TOTALUM1,UTILAJ,ORASTART,NRSCHIMBURI,ORESCHIMB,OREPEZI,TIPARTICOL,OBSCLI,NRDOCCLI,CODINTERN,FROMPP,
      CONSUM, R_PREDAT
      )
    WITH FISA AS (SELECT PC.CODPRODCOMP, COUNT(PM.CODPRODMAS) NR
                  FROM PRODCOMP PC
                       INNER JOIN PRODMAS PM ON PC.CODPRODCOMP = PM.CODPRODCOMP
                  GROUP BY PC.CODPRODCOMP
                 )
    SELECT
      - RowNum CodIntr1,
      C1.CODCOMANDA1,
      ROUND(C.NRDOC + C1.indexlocal / 100, 3),
      C1.CODOBIECT,
      OBJ.DENUMIRE,
      OBJ.CODEXTERN,
      PF1.PRIORITATE,
      PC.DURATA DURATAR,
      0 DURATA,
      PF1.TERMEN,
      C1.UMSEC,
      case when PF1.CODPROGRAMF1 &gt; 0 then PFF1.CANTPROGRAMAT else C1.CANTACCEPTAT end PROGRAMAT,
      case when PF1.CODPROGRAMF1 &gt; 0 then PFF1.CANTPROGRAMAT else C1.CANTACCEPTAT end PROGRAMAT_P,
      C1.PU,
      case when PF1.CODPROGRAMF1 &gt; 0 then 0 else RZ.CANT end REALIZAT,
      case when PF1.CODPROGRAMF1 &gt; 0 then 0 else RZ.CANT end REALIZAT_P,
      case when PF1.CODPROGRAMF1 &gt; 0 then PFF1.CANTPROGRAMAT - nvl(PF.CANT,0) else CASE WHEN C1.CONSUM = 2 THEN CS.CANT ELSE PR.CANT END END PREDAT,
      case when PF1.CODPROGRAMF1 &gt; 0 then PFF1.CANTPROGRAMAT - nvl(PF.CANT,0) else CASE WHEN C1.CONSUM = 2 THEN CS.CANT ELSE PR.CANT END END PREDAT_P,
      ART.UM1,
      UMS.DEN_UM Den_UMs,
      C1.D1,
      C1.D2,
      C1.D3,
      0 RAPORTAT,
      0 RAPORTAT_P,
      0 REBUT,
      0 REBUT_P,
      0 RAPORTATUM1,
      ART.RELATIEUM1,
      ART.UM,
      NUM1.PARITATE,
      NUM1.DEN_UM1,
      ART.TIPSERIE,
      0 CodFisa,
      0 Avizat,
      FISA.NR AreFisa,
      &apos;                       &apos; FisaMas,
      CASE WHEN aPrelPretNP = 2 THEN PC.PRET ELSE C1.PU END PRET,
      CASE WHEN aPrelPretNP = 2 THEN PC.PRET ELSE C1.PU END PRET_P,
      CMD.CODCMDPRODMAT,
      PF1.CODPROGRAMF1,
      OBJ.MASA Masa,
      nvl(ARTIMP.GESTIMPLICITA,0) CODGESTNIR,
      nvl(ARTIMP.LOCATIEIMPLICITA,0) CODLOCNIR,
      Nvl(IOANIR.CODIOArt,0) CODIOARTNIR,
      GNIR.DEN_GEST GESTNIR,
      GNIR.DEN_GEST||&apos;, &apos;||LOCNIR.DENUMIRE||CHR(13)||Nvl(IOANIR.DEN_IOART,&apos;?&apos;) AS GESTLOCCONT,
      LOCNIR.DENUMIRE LOCATIENIR,
      Nvl(IOANIR.DEN_IOART,&apos;?&apos;) IOARTNIR,
      PF1.CODFORMATIE,
      PF1.SCHIMB,
      0 DONE,
      PF1.CodPers,
      C1.CodAnalizaNod,
      PERS.Nume||chr(13)||PERS.prenume Den_Angajat,
      NVL(C.INCHISA,0) INCHISA,
      C.CodComanda,
      0 CarnetNir,
      C.DataDoc,
      PF1.CODGEST,
      PR.CANT PredatTot,
      PR.CANT PredatTot_P,
      nvl(PF.CANT,0) RESTPF,
      C1.CODRETETA,
      CMD.CANT Total,
      CMD.CANTUM1 TotalUM1,
      OBJU.DENUMIRE UTILAJ,
      G.ORASTART,
      G.NRSCHIMBURI,
      G.ORESCHIMB,
      case when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) &gt; 24 then 24 when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) = 0 then 24 else NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) end OrePeZi,
      ART.TIPARTICOL,
      CLI1.OBS OBSCLI,
      ROUND(CLI.NRDOC + CLI1.indexlocal / 100, 3) NRDOCCLI,
      OBJ.CODINTERN,
      0 AS FROMPP,
      C1.CONSUM,
      coalesce(R_PR.CANT,0)
    FROM TMP_GENNP_CMD1 PF1
      INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 0
      INNER JOIN NUM1 ON C1.UMSEC = NUM1.CODUM1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN NARTOBJ OBJ ON C1.CODOBIECT = OBJ.CODOBIECT
      INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
      INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
      INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
      LEFT JOIN PROGRAMF1 PFF1 ON PFF1.CODPROGRAMF1 = PF1.CODPROGRAMF1
      LEFT JOIN COMANDA1 CLI1 ON CLI1.CODCOMANDA1 = PKG_COMANDA.DINCMDCLI(C1.CODCOMANDA1)
      LEFT JOIN COMANDA CLI ON CLI.CODCOMANDA = CLI1.CODCOMANDA
      LEFT JOIN NUM UMS ON UMS.CODUM = ART.UM1
      LEFT JOIN UTILAJE2C U2C ON C1.CODCOMANDA1 = U2C.CODCOMANDA1
      LEFT JOIN UTILAJE U ON U2C.CODUTILAJ = U.CODUTILAJ
      LEFT JOIN NARTOBJ OBJU ON U.CODOBIECT = OBJU.CODOBIECT
      LEFT JOIN NARTIMPLICITE ARTIMP ON ART.CODARTICOL = ARTIMP.CODARTICOL AND ARTIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NGEST GNIR ON NVL(ARTIMP.GESTIMPLICITA, 0) = GNIR.CODGEST
      LEFT JOIN NLOCATII LOCNIR ON NVL(ARTIMP.LOCATIEIMPLICITA, 0) = LOCNIR.CODLOCATIE
      LEFT JOIN NPERS PERS ON NVL(PF1.CODPERS, 0) = PERS.CODPERS
      LEFT JOIN ioart IOANIR ON CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(ARTIMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END = IOANIR.CODIOART
      LEFT JOIN TMP_GENNP_CRS CS ON CS.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND CS.TIP = 1 AND CS.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 3 AND RZ.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND PR.TIP = 2 AND PR.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PF ON PF.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND ((PF1.CODPROGRAMF1 &gt; 0 AND PF.CODPROGRAMF1 = PF1.CODPROGRAMF1) OR NVL(PF1.CODPROGRAMF1,0) = 0)
                                    AND PF.TIP = 4 AND PF.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS R_PR ON R_PR.CODCMDPRODMAT = CMD.CODCOMANDA1 AND R_PR.TIP = 12 AND R_PR.USERID = aUserID
      LEFT JOIN FISA ON PC.CODPRODCOMP = FISA.CODPRODCOMP
    WHERE PF1.USERID = aUserID;
  END IF;
  COMMIT;
end;

procedure GetCrsRez is
aUserID number(20);
aRapOrdMan number(10);
begin
  aUserID := PKG_GLOBALS.GETUSERID;
  aRapOrdMan := pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru);
  if aRapOrdMan = 1 then
    insert into TMP_GENNP_REZ
    SELECT
      - RowNum CodIntr1,
      C1.CODCOMANDA1,
      ROUND(C.NRDOC + C1.indexlocal / 100, 3),
      CMD.CODOBIECT,
      OBJ.DENUMIRE,
      OBJ.CODEXTERN,
      C1.NIVEL PRIORITATE,
      PC.DURATA DURATAR,
      0 DURATA,
      C1.TERMEN,
      C1.UMSEC,
      0 PROGRAMAT,
      ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
      RZ.CANT REALIZAT,
      PR.CANT PREDAT,
      ART.UM1,
      C1.D1,
      C1.D2,
      C1.D3,
      0 RAPORTAT,
      0 RAPORTATUM1,
      ART.RELATIEUM1,
      NUM1.PARITATE,
      NUM1.DEN_UM1,
      ART.TIPSERIE,
      nvl(OBJ1.PRETREFERINTA,cmd.pret) PRET,
      CMD.CODCMDPRODMAT,
      0 CODPROGRAMF1,
      OBJ.MASA * NUM1.Paritate Masa,
      nvl(ARTIMP.GESTIMPLICITA,0) CODGESTNIR,
      nvl(ARTIMP.LOCATIEIMPLICITA,0) CODLOCNIR,
      Nvl(IOANIR.CODIOArt,0) CODIOARTNIR,
      GNIR.DEN_GEST GESTNIR,
      GNIR.DEN_GEST || &apos;, &apos; || LOCNIR.DENUMIRE || CHR(13) || Nvl(IOANIR.DEN_IOART,&apos;?&apos;) AS GESTLOCCONT,
      LOCNIR.DENUMIRE LOCATIENIR,
      Nvl(IOANIR.DEN_IOART,&apos;?&apos;) IOARTNIR,
      C.CODGEST,
      C.CODFORMATIE,
      C.SCHIMB,
      0 DONE, 0 CodPers, C1.CodAnalizaNod, &apos;##???????????????????????????????????????????????????????????????????????????&apos; Den_Angajat, NVL(C.INCHISA,0) INCHISA,
      C.CodComanda, 0 CarnetNir, CMD.CANT TOTAL, CMD.CANTUM1 TOTALUM1
    FROM TMP_GENNP_CMD1 PF1
      INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 2
      INNER JOIN NUM1 ON C1.UMSEC = NUM1.CODUM1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
      INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
      INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
      LEFT JOIN TMP_NARTOBJ_LUNA OBJ1 ON OBJ1.CODOBIECT = OBJ.CODOBIECT
      LEFT JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA, 0) = 0
      LEFT JOIN NARTIMPLICITE ARTIMP ON ART.CODARTICOL = ARTIMP.CODARTICOL AND ARTIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NGEST GNIR ON NVL(ARTIMP.GESTIMPLICITA, 0) = GNIR.CODGEST
      LEFT JOIN NLOCATII LOCNIR ON NVL(ARTIMP.LOCATIEIMPLICITA, 0) = LOCNIR.CODLOCATIE
      LEFT JOIN ioart IOANIR ON CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(ARTIMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END = IOANIR.CODIOART
      LEFT JOIN TMP_GENNP_CRS RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 3 AND RZ.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND PR.TIP = 2 AND PR.USERID = aUserID
    WHERE PF1.USERID = aUserID;
  else
    insert into TMP_GENNP_REZ
    SELECT
      - RowNum CodIntr1,
      C1.CODCOMANDA1,
      ROUND(C.NRDOC + C1.indexlocal / 100, 3),
      CMD.CODOBIECT,
      OBJ.DENUMIRE,
      OBJ.CODEXTERN,
      PF1.PRIORITATE,
      PC.DURATA DURATAR,
      0 DURATA,
      PF1.TERMEN,
      C1.UMSEC,
      0 PROGRAMAT,
      ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
      RZ.CANT REALIZAT,
      PR.CANT PREDAT,
      ART.UM1,
      C1.D1,
      C1.D2,
      C1.D3,
      0 RAPORTAT,
      0 RAPORTATUM1,
      ART.RELATIEUM1,
      NUM1.PARITATE,
      NUM1.DEN_UM1,
      ART.TIPSERIE,
      nvl(OBJ1.PRETREFERINTA,cmd.pret) PRET,
      CMD.CODCMDPRODMAT,
      nvl(PF1.CODPROGRAMF1,0) CODPROGRAMF1,
      OBJ.MASA * NUM1.Paritate Masa,
      nvl(ARTIMP.GESTIMPLICITA,0) CODGESTNIR,
      nvl(ARTIMP.LOCATIEIMPLICITA,0) CODLOCNIR,
      Nvl(IOANIR.CODIOArt,0) CODIOARTNIR,
      GNIR.DEN_GEST GESTNIR,
      GNIR.DEN_GEST || &apos;, &apos; || LOCNIR.DENUMIRE || CHR(13) || Nvl(IOANIR.DEN_IOART,&apos;?&apos;) AS GESTLOCCONT,
      LOCNIR.DENUMIRE LOCATIENIR,
      Nvl(IOANIR.DEN_IOART,&apos;?&apos;) IOARTNIR,
      PF1.CODGEST,
      PF1.CODFORMATIE,
      PF1.SCHIMB,
      0 DONE, 0 CodPers, C1.CodAnalizaNod, &apos;##???????????????????????????????????????????????????????????????????????????&apos; Den_Angajat, NVL(C.INCHISA,0) INCHISA,
      C.CodComanda, 0 CarnetNir, CMD.CANT TOTAL, CMD.CANTUM1 TOTALUM1
    FROM TMP_GENNP_CMD1 PF1
      INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 2
      INNER JOIN NUM1 ON C1.UMSEC = NUM1.CODUM1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
      INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
      INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
      LEFT JOIN TMP_NARTOBJ_LUNA OBJ1 ON OBJ1.CODOBIECT = OBJ.CODOBIECT
      LEFT JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA, 0) = 0
      LEFT JOIN NARTIMPLICITE ARTIMP ON ART.CODARTICOL = ARTIMP.CODARTICOL AND ARTIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
      LEFT JOIN NGEST GNIR ON NVL(ARTIMP.GESTIMPLICITA, 0) = GNIR.CODGEST
      LEFT JOIN NLOCATII LOCNIR ON NVL(ARTIMP.LOCATIEIMPLICITA, 0) = LOCNIR.CODLOCATIE
      LEFT JOIN ioart IOANIR ON CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(ARTIMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END = IOANIR.CODIOART
      LEFT JOIN TMP_GENNP_CRS RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 3 AND RZ.USERID = aUserID
      LEFT JOIN TMP_GENNP_CRS PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND PR.TIP = 2 AND PR.USERID = aUserID
    WHERE PF1.USERID = aUserID;
  end if;
  COMMIT;
end;

procedure GetCrsMan(vDataRap in varchar2) is
aUserID number(20);
begin
  aUserID := PKG_GLOBALS.GETUSERID;
  if pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
    insert into TMP_GENNP_MAN
    SELECT
      C1.CODCOMANDA1,OP.CodOp,T1.CODTARIF,OP.DENUMIRE DEN_OP,T.DENUMIRE DEN_TARIF,round(T1.TARIF, 2) TARIF,
      round( case when PC.CANT &lt;&gt; 1 THEN PFMAN.CANT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PFMAN.CANT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0)
                                    ELSE NVL(MAN.TPI, 0) + PFMAN.CANT * nvl(MAN.TU, 0) END / 60, 2) ORETOTAL,0 ORE,
      round( case when PC.CANT &lt;&gt; 1 THEN PFMAN.CANT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0)
                                    ELSE PFMAN.CANT * nvl(MAN.TU, 0) END * T1.TARIF / 60 , 2) VALOARE,
      round( case when PC.CANT &lt;&gt; 1 THEN round(MAN.CANT, 2)
                                    ELSE round(MAN.CANT, 2) END , 2) TOTAL,0 UNITAR,C.DataDoc,PR.CANT REALIZAT,
      0 ProdRebutate,round( case when PC.CANT &lt;&gt; 1 THEN round(PFMAN.CANT, 2)
                                                   ELSE round(PFMAN.CANT, 2) END , 2) PROGRAMAT,0 CODPERS,&apos;...nedefinit...&apos; Den_angajat,0 MARCA,
      0 RAPORTAT,G.ORASTART,G.NRSCHIMBURI,G.ORESCHIMB,
      case when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) &gt; 24 then 24 when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) = 0 then 24 else NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) end OrePeZi,
      C.CODGEST,C.CODFORMATIE,C.SCHIMB,MAN.CODMAN,round(MAN.TU/60, 2) TU,MAN.TU TUMIN,NVL(MAN.BPS,1) BPS,
      MAN.CODCMDPRODMAN,case when coalesce(MAN.DETALII,0) = 0 then 0 else coalesce(MAN.DETALII,0) - 1 end Detalii,MAN.NROP,vDataRap||&apos; 00:00&apos; DataStartC,vDataRap||&apos; 00:00&apos; DataStopC,
      to_date(vDataRap, &apos;dd.mm.yyyy&apos;) DataStart,to_date(vDataRap, &apos;dd.mm.yyyy&apos;) DataStop,0 Rebutate,0 Refacute,0 CodProgramF1,
      MINMAXOP.LastOp,MINMAXOP.FirstOp,MAXDET.DetLastOp - 1 DetLastOp,nvl(REXEC.CANT,0) PreluatAltele, MAN.CODLOC, coalesce(man.obs,pman.obs)
    FROM TMP_GENNP_CMDMAN PFMAN
      INNER JOIN CMDPRODMAN MAN ON PFMAN.CODCMDPRODMAN = MAN.CODCMDPRODMAN
      INNER JOIN (SELECT MIN(NROP) FIRSTOP, MAX(NROP) LASTOP, CODCOMANDA1 FROM CMDPRODMAN GROUP BY CODCOMANDA1) MINMAXOP ON MINMAXOP.CODCOMANDA1 = MAN.CODCOMANDA1
      INNER JOIN (SELECT MAX(DETALII) DETLASTOP, NROP, CODCOMANDA1 FROM CMDPRODMAN GROUP BY NROP, CODCOMANDA1) MAXDET ON MAXDET.NROP = MINMAXOP.LASTOP AND MAXDET.CODCOMANDA1 = MINMAXOP.CODCOMANDA1
      INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN PRODMAN PMAN ON MAN.CODMAN = PMAN.CODMAN
      INNER JOIN PRODCOMP PC ON PMAN.CODPRODCOMP = PC.CODPRODCOMP
      INNER JOIN PRODGEST PG ON PMAN.CODPRODGEST = PG.CODPRODGEST
      INNER JOIN NGEST G ON PG.CODGEST = G.CODGEST
      INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
      INNER JOIN Tarifeman1 T1 ON T1.CODTARIF = MAN.CODTARIF AND PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALStart AND T1.ALStop
      INNER JOIN TARIFEMAN T ON T1.CODTARIF = T.CODTARIF
      LEFT JOIN (select PFMAN.CODCMDPRODMAN, sum(PFMAN.cant) cant, NVL(RAPPF.CANT,0) RAP
                 from PROGRAMFMAN PFMAN
                      inner join PROGRAMF PF on PF.CodProgramF = PFMAN.CodProgramF
                      inner join PROGRAMF1 PF1 on PF1.CodProgramF = PF.CodProgramF
                      inner join COMANDA1 C1 on PF1.CodCOMANDA1 = C1.CodCOMANDA1
                      inner join CMDPRODMAN MAN on MAN.CodCOMANDA1 = C1.CodCOMANDA1 AND MAN.CODCMDPRODMAN = PFMAN.CODCMDPRODMAN
                      inner join TMP_GENNP_CMDMAN TMP ON TMP.CODCMDPRODMAN = MAN.CODCMDPRODMAN
                      LEFT JOIN (SELECT CMD.CODCMDPRODMAN, SUM(CMD.CANT - nvl(R2.Rebut,0)) CANT, CMD.CODPROGRAMF1
                                 FROM MANPRODLINK CMD
                                      INNER JOIN RAPORTP2 R2 ON CMD.CODRAPORTP2 = R2.CODRAPORTP2
                                      INNER JOIN RAPORTP1 R1 ON R1.CODRAPORTP1  = R2.CODRAPORTP1
                                      INNER JOIN RAPORTP R ON R1.CODRAPORTP  = R.CODRAPORTP
                                 where cmd.codprogramf1 &gt; 0
                                 GROUP BY CMD.CODCMDPRODMAN,CMD.CODPROGRAMF1
                                 ) RAPPF ON RAPPF.CODPROGRAMF1 = PF1.CODPROGRAMF1 AND RAPPF.CODCMDPRODMAN = PFMAN.CODCMDPRODMAN
                 where PF.Operat = 1 AND TMP.USERID = aUserID
                 group by PFMAN.CODCMDPRODMAN,NVL(RAPPF.CANT,0)) REXEC ON REXEC.CODCMDPRODMAN = MAN.CODCMDPRODMAN
      LEFT JOIN TMP_GENNP_CRS PR ON MAN.CODCMDPRODMAN = PR.CODCMDPRODMAT AND PR.TIP = 6 AND PR.USERID = aUserID
    where PFMAN.USERID = aUserID;
  else
    insert into TMP_GENNP_MAN
    SELECT
      C1.CODCOMANDA1,OP.CodOp,T1.CODTARIF,OP.DENUMIRE DEN_OP,T.DENUMIRE DEN_TARIF,round(T1.TARIF, 2) TARIF,
      round( case when COALESCE(PC.CANT,1) &lt;&gt; 1 THEN PF1.CANT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0)
                  ELSE NVL(MAN.TPI, 0) + PF1.CANT * nvl(MAN.TU, 0) END / 60, 2) ORETOTAL,
      0 ORE,
      round( case when COALESCE(PC.CANT,1) &lt;&gt; 1 THEN PF1.CANT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0)
                  ELSE PF1.CANT * nvl(MAN.TU, 0) END * T1.TARIF / 60 , 2) VALOARE,
      man.cant TOTAL,
      0 UNITAR, C.DataDoc,
      PR.CANT REALIZAT, 0 ProdRebutate,
      man.cant PROGRAMAT, PF1.CODPERS, PERS.NUME||&apos; &apos;||PERS.PRENUME Den_angajat, PERS.MARCA,
      0 RAPORTAT, G.ORASTART, G.NRSCHIMBURI, G.ORESCHIMB,
      case when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) &gt; 24 then 24 when NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) = 0 then 24 else NVL(G.NRSCHIMBURI,0) * NVL(G.ORESCHIMB,0) end OrePeZi,
      PF1.CODGEST, PF1.CODFORMATIE, PF1.SCHIMB, MAN.CODMAN, round(MAN.TU/60, 2) TU, MAN.TU TUMIN, NVL(MAN.BPS,1) BPS, MAN.CODCMDPRODMAN, case when coalesce(MAN.DETALII,0) = 0 then 0 else coalesce(MAN.DETALII,0) - 1 end Detalii, MAN.NROP,
      vDataRap||&apos; 00:00&apos; DataStartC,
      vDataRap||&apos; 00:00&apos; DataStopC,
      to_date(vDataRap, &apos;dd.mm.yyyy&apos;) DataStart,
      to_date(vDataRap, &apos;dd.mm.yyyy&apos;) DataStop, 0 Rebutate, 0 Refacute, PF1.CodProgramF1,
      0 LastOp, 0 FirstOp, 0 DetLastOp, 0 PRELUATALTE, MAN.CODLOC, coalesce(man.obs,pman.obs)
    FROM TMP_GENNP_CMD1 PF1
      INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
      INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
      INNER JOIN Tarifeman1 T1 ON T1.CODTARIF = MAN.CODTARIF AND PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALStart AND T1.ALStop
      INNER JOIN TARIFEMAN T ON T1.CODTARIF = T.CODTARIF
      LEFT JOIN PRODMAN PMAN ON MAN.CODMAN = PMAN.CODMAN
      LEFT JOIN PRODCOMP PC ON PMAN.CODPRODCOMP = PC.CODPRODCOMP
      LEFT JOIN PRODGEST PG ON PMAN.CODPRODGEST = PG.CODPRODGEST
      LEFT JOIN NGEST G ON COALESCE(PG.CODGEST,C.CODGEST) = G.CODGEST
      LEFT JOIN TMP_GENNP_CRS PR ON MAN.CODCMDPRODMAN = PR.CODCMDPRODMAT AND PR.CODPROGRAMF1 = PF1.CODPROGRAMF1 AND PR.TIP = 6 AND PR.USERID = aUserID
      LEFT JOIN NPERS PERS ON PERS.CODPERS = PF1.CODPERS
    where PF1.USERID = aUserID;
  end if;
  COMMIT;
end;

procedure GetCrsMat(FromPF in NUMBER) is
aUserID number(20);
FlagPF number(1);
cNormaCons number(20);
aCount number(10);
begin
  cNormaCons := pkg_categconst.GetValConstanta(&apos;NormaCons&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru);
  aUserID := PKG_GLOBALS.GETUSERID;
  FlagPF := FROMPF;

  if cNormaCons = 1 then
    delete tmp_cmdprodmat;
    for v_rec in
      (
      select COALESCE(CMD.CODCMDPRODMAT,0) CODCMDPRODMAT, TMP.CODCOMANDA1, NM.CODOBIECT,
             C1.CANTACCEPTAT/PC.CANT*NM.CANT CANT, NM.PRET, NM.D1, NM.D2, NM.D3,
             NM.INDEXLOCAL, NM.CODMAT CODPRODMAT, C1.CANTACCEPTAT/PC.CANT*NM.CANTUM1 CANTUM1, NUM1.CODUM1 UMSEC
      from TMP_GENNP_CMD1 TMP
           INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = TMP.CODCOMANDA1
           INNER JOIN PRODNORME N ON N.CODNORMA = C1.CODNORMA
           INNER JOIN NORMEMAT NM ON NM.CODNORMA = N.CODNORMA
           INNER JOIN PRODCOMP PC ON N.CODPRODCOMP = PC.CODPRODCOMP
           INNER JOIN NARTOBJ OBJ ON NM.CODOBIECT = OBJ.CODOBIECT
           INNER JOIN NART ON OBJ.CodArticol = NART.CodArticol
           INNER JOIN NUM1 ON NART.UM = NUM1.CodUM  AND NUM1.SECUNDARA = 0
           LEFT  JOIN PRODMAT MAT ON NM.CODMAT = MAT.CODMAT
           LEFT  JOIN CMDPRODMAT CMD ON MAT.CODMAT = CMD.CODPRODMAT AND CMD.CODCOMANDA1 = C1.CODCOMANDA1
      where TMP.USERID = AUSERID AND C1.CODNORMA &gt; 0 AND COALESCE(N.IMPLICIT,0) = 0
      )
    LOOP
      insert into tmp_cmdprodmat
      (
        CODCMDPRODMAT,
        CODCOMANDA1,
        CODOBIECT,
        CANT,
        PRET,
        REST,
        TIP,
        D1,
        D2,
        D3,
        INDEXLOCAL,
        CODPRODMAT,
        CANTUM1,
        UMSEC
      )
      values (
        V_REC.CODCMDPRODMAT,
        V_REC.CODCOMANDA1,
        V_REC.CODOBIECT,
        V_REC.CANT,
        V_REC.PRET,
        V_REC.CANT,
        1,
        V_REC.D1,
        V_REC.D2,
        V_REC.D3,
        V_REC.INDEXLOCAL,
        V_REC.CODPRODMAT,
        V_REC.CANTUM1,
        V_REC.UMSEC
      );
      update TMP_GENNP_CMD1 set rebut = 1 WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      COMMIT;
    END LOOP;

    select count(*) into aCount from tmp_cmdprodmat;

    if pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
      IF ACOUNT &gt; 0 THEN
        insert into TMP_GENNP_MAT
        SELECT
          - RowNum CodIes1,
          CMD.CODCOMANDA1,
          CMD.CODOBIECT,
          OBJ.DENUMIRE,
          OBJ.CODEXTERN,
          OBJ.CODINTERN,
          U1.CODUM1 UMSEC,
          CMD.CANT TOTAL,
          CMD.CANTUM1 TOTALUM1,
          CMD.CANT TOTAL_P,
          0 PROGRAMAT,
          0 PROGRAMAT_P,
          ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
          ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
          RZ.CANT REALIZAT,
          RZ.CANT REALIZAT_P,
          PR.CANT CONSUMAT,
          PR.CANT CONSUMAT_P,
          UA1.CodUM1 UM1,
          CMD.D1,
          CMD.D2,
          CMD.D3,
          0 RAPORTAT,
          0 RAPORTAT_P,
          0 RAPORTATUM1,
          ART.RELATIEUM1,
          ART.UM,
          U1.PARITATE,
          ART.TIPSERIE,
          CMD.CODCMDPRODMAT,
          CMD.CODCMDPRODMAN,
          C1.TERMEN,
          0 CODPROGRAMF1,
          ART.TIPARTICOL,
          U1.DEN_UM1,
          CMD.Pret,
          CMD.Pret Pret_P,
          case when CMD.CODCMDPRODMAT &gt; 0 then 0 else 1 end Supliment,
          ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
          ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
          ROUND(NVL(STOCT.CANT,0),
          NVL(U1.ZECIMALE,0)) STOCT,
          NVL(MAT.TIP,3) TIP,
          ROUND(C.NRDOC + C1.indexlocal / 100, 3),
          case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
          0 Echivalenta,
          0 CantEchivalata,
          &apos;NU&apos; EchivString,
          C.CodComanda,
          POBJ.CODARTICOL,
          ppobj.denumire den_produs,
          GIMP.CODGEST,
          C.CODFORMATIE,
          C.SCHIMB,
          IOIMP.CODIOART,
          LIMP.CODLOCATIE, LIMP.Denumire DenLocatie,
          GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
          CLS.DEN_CLASEA,
          UM1.Den_UM Den_UM_1,
          UM2.Den_UM Den_UM_2,
          Tr.Cant Transferat,
          nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
          COALESCE(U1.ZECIMALE,2)
        FROM (SELECT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID AND REBUT = 1) PF1
          INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
          INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
          INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
          INNER JOIN TMP_CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
          INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
          INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
          INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
          INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
          INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
          LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
          LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                     from PRODMAT PM
                          left join PRODMATECHIV PE on pe.codmat = pm.codmat
                     GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
          LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                     from transf1 t1
                          inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                          INNER JOIN TMP_GENNP_CMD1 PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                     WHERE PF1.USERID = AUSERID
                     GROUP BY t1.codcomanda1, t1.codobiect
                    ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
          LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
          LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
          LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
          LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
          LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
          LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
          LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
          LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
          LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
          LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
          LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = -1 AND USERID = AUSERID)
                    RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
          LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 1 AND USERID = AUSERID)
                    PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT
          LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                    STOC ON STOC.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                    STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                    NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                    REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6;
      END IF;

      insert into TMP_GENNP_MAT
      SELECT
        - RowNum CodIes1,
        CMD.CODCOMANDA1,
        CMD.CODOBIECT,
        OBJ.DENUMIRE,
        OBJ.CODEXTERN,
        OBJ.CODINTERN,
        U1.CODUM1 UMSEC,
        CMD.CANT TOTAL,
        CMD.CANTUM1 TOTALUM1,
        CMD.CANT TOTAL_P,
        0 PROGRAMAT,
        0 PROGRAMAT_P,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
        RZ.CANT REALIZAT,
        RZ.CANT REALIZAT_P,
        PR.CANT CONSUMAT,
        PR.CANT CONSUMAT_P,
        UA1.CodUM1 UM1,
        CMD.D1,
        CMD.D2,
        CMD.D3,
        0 RAPORTAT,
        0 RAPORTAT_P,
        0 RAPORTATUM1,
        ART.RELATIEUM1,
        ART.UM,
        U1.PARITATE,
        ART.TIPSERIE,
        CMD.CODCMDPRODMAT,
        CMD.CODCMDPRODMAN,
        C1.TERMEN,
        0 CODPROGRAMF1,
        ART.TIPARTICOL,
        U1.DEN_UM1,
        CMD.Pret,
        CMD.Pret Pret_P,
        0 Supliment,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
        ROUND(NVL(STOCT.CANT,0),
        NVL(U1.ZECIMALE,0)) STOCT,
        NVL(MAT.TIP,3) TIP,
        ROUND(C.NRDOC + C1.indexlocal / 100, 3),
        case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
        0 Echivalenta,
        0 CantEchivalata,
        &apos;NU&apos; EchivString,
        C.CodComanda,
        POBJ.CODARTICOL,
        ppobj.denumire den_produs,
        GIMP.CODGEST,
        C.CODFORMATIE,
        C.SCHIMB,
        IOIMP.CODIOART,
        LIMP.CODLOCATIE, LIMP.Denumire DenLocatie,
        GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
        CLS.DEN_CLASEA,
        UM1.Den_UM Den_UM_1,
        UM2.Den_UM Den_UM_2,
        Tr.Cant Transferat,
        nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
        COALESCE(U1.ZECIMALE,2)
      FROM (SELECT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID AND REBUT = 0) PF1
        INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
        INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
        INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
        INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
        INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
        INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
        INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
        INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
        INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
        INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
        LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
        LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                   from PRODMAT PM
                        left join PRODMATECHIV PE on pe.codmat = pm.codmat
                   GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
        LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                   from transf1 t1
                        inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                        INNER JOIN TMP_GENNP_CMD1 PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                   WHERE PF1.USERID = AUSERID
                   GROUP BY t1.codcomanda1, t1.codobiect
                  ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
        LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
        LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
        LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
        LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
        LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
        LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
        LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
        LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = -1 AND USERID = AUSERID)
                  RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 1 AND USERID = AUSERID)
                  PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                  STOC ON STOC.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                  STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                  NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                  REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
      where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6;
    else
      IF ACOUNT &gt; 0 THEN
        insert into TMP_GENNP_MAT
        SELECT
          - RowNum CodIes1,
          CMD.CODCOMANDA1,
          CMD.CODOBIECT,
          OBJ.DENUMIRE,
          OBJ.CODEXTERN,
          OBJ.CODINTERN,
          U1.CODUM1 UMSEC,
          case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL,
          case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANTUM1 else CMD.CANTUM1 end TOTALUM1,
          case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL_P,
          0 PROGRAMAT,
          0 PROGRAMAT_P,
          ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
          ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
          RZ.CANT REALIZAT,
          RZ.CANT REALIZAT_P,
          PR.CANT CONSUMAT,
          PR.CANT CONSUMAT_P,
          UA1.CodUM1 UM1,
          CMD.D1,
          CMD.D2,
          CMD.D3,
          0 RAPORTAT,
          0 RAPORTAT_P,
          0 RAPORTATUM1,
          ART.RELATIEUM1,
          ART.UM,
          U1.PARITATE,
          ART.TIPSERIE,
          CMD.CODCMDPRODMAT,
          CMD.CODCMDPRODMAN,
          PF1.TERMEN,
          PF1.CODPROGRAMF1,
          ART.TIPARTICOL,
          U1.DEN_UM1,
          CMD.Pret,
          CMD.Pret Pret_P,
          case when CMD.CODCMDPRODMAT &gt; 0 then 0 else 1 end Supliment,
          ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
          ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
          ROUND(NVL(STOCT.CANT,0),
          NVL(U1.ZECIMALE,0)) STOCT,
          case when coalesce(obj.produspropriu,0) = 0 then 3 else NVL(MAT.TIP,3) end TIP,
          ROUND(C.NRDOC + C1.indexlocal / 100, 3),
          case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
          0 Echivalenta,
          0 CantEchivalata,
          &apos;NU&apos; EchivString,
          C.CodComanda,
          POBJ.CODARTICOL,
          ppobj.denumire den_produs,
          GIMP.CODGEST,
          C.CODFORMATIE,
          C.SCHIMB,
          IOIMP.CODIOART,
          LIMP.CODLOCATIE,
          LIMP.Denumire,
          GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
          CLS.DEN_CLASEA,
          UM1.Den_UM Den_UM_1,
          UM2.Den_UM Den_UM_2,
          Tr.Cant Transferat,
          nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
          COALESCE(U1.ZECIMALE,2)
        FROM (SELECT CODCOMANDA1,CODPROGRAMF1,TERMEN,CANT FROM TMP_GENNP_CMD1 WHERE USERID = aUserID AND REBUT = 1) PF1
          INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
          INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
          INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
          INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
          INNER JOIN TMP_CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
          INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
          INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
          INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
          INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
          INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
          LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
          LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                     from PRODMAT PM
                          left join PRODMATECHIV PE on pe.codmat = pm.codmat
                     GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
          LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                     from transf1 t1
                          inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                          INNER JOIN (SELECT DISTINCT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID) PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                     GROUP BY t1.codcomanda1, t1.codobiect
                    ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
          LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
          LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
          LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
          LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
          LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
          LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
          LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
          LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
          LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
          LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
          LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = -11 AND USERID = AUSERID)
                    RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(RZ.CODPROGRAMF1,0)
          LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = 11 AND USERID = AUSERID)
                    PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(PR.CODPROGRAMF1,0)
          LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                    STOC ON STOC.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                    STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                    NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
          LEFT JOIN (SELECT CODCMDPRODMAT,CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                    REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6;
      END IF;

      insert into TMP_GENNP_MAT
      SELECT
        - RowNum CodIes1,
        CMD.CODCOMANDA1,
        CMD.CODOBIECT,
        OBJ.DENUMIRE,
        OBJ.CODEXTERN,
        OBJ.CODINTERN,
        U1.CODUM1 UMSEC,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANTUM1 else CMD.CANTUM1 end TOTALUM1,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL_P,
        0 PROGRAMAT,
        0 PROGRAMAT_P,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
        RZ.CANT REALIZAT,
        RZ.CANT REALIZAT_P,
        PR.CANT CONSUMAT,
        PR.CANT CONSUMAT_P,
        UA1.CodUM1 UM1,
        CMD.D1,
        CMD.D2,
        CMD.D3,
        0 RAPORTAT,
        0 RAPORTAT_P,
        0 RAPORTATUM1,
        ART.RELATIEUM1,
        ART.UM,
        U1.PARITATE,
        ART.TIPSERIE,
        CMD.CODCMDPRODMAT,
        CMD.CODCMDPRODMAN,
        PF1.TERMEN,
        PF1.CODPROGRAMF1,
        ART.TIPARTICOL,
        U1.DEN_UM1,
        CMD.Pret,
        CMD.Pret Pret_P,
        0 Supliment,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
        ROUND(NVL(STOCT.CANT,0),
        NVL(U1.ZECIMALE,0)) STOCT,
        NVL(MAT.TIP,3) TIP,
        ROUND(C.NRDOC + C1.indexlocal / 100, 3),
        case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
        0 Echivalenta,
        0 CantEchivalata,
        &apos;NU&apos; EchivString,
        C.CodComanda,
        POBJ.CODARTICOL,
        ppobj.denumire den_produs,
        GIMP.CODGEST,
        C.CODFORMATIE,
        C.SCHIMB,
        IOIMP.CODIOART,
        LIMP.CODLOCATIE,
        LIMP.Denumire,
        GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
        CLS.DEN_CLASEA,
        UM1.Den_UM Den_UM_1,
        UM2.Den_UM Den_UM_2,
        Tr.Cant Transferat,
        nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
        COALESCE(U1.ZECIMALE,2)
      FROM (SELECT CODCOMANDA1,CODPROGRAMF1,TERMEN,CANT FROM TMP_GENNP_CMD1 WHERE USERID = aUserID AND REBUT = 0) PF1
        INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
        INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
        INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
        INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
        INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
        INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
        INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
        INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
        INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
        INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
        LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
        LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                   from PRODMAT PM
                        left join PRODMATECHIV PE on pe.codmat = pm.codmat
                   GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
        LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                   from transf1 t1
                        inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                        INNER JOIN (SELECT DISTINCT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID) PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                   GROUP BY t1.codcomanda1, t1.codobiect
                  ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
        LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
        LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
        LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
        LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
        LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
        LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
        LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
        LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = -11 AND USERID = AUSERID)
                  RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(RZ.CODPROGRAMF1,0)
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = 11 AND USERID = AUSERID)
                  PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(PR.CODPROGRAMF1,0)
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                  STOC ON STOC.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                  STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                  NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                  REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
      where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6;
    end if;
    delete tmp_cmdprodmat;
    update TMP_GENNP_CMD1 set rebut = 0;
  else
    if pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
      insert into TMP_GENNP_MAT
      SELECT
        - RowNum CodIes1,
        CMD.CODCOMANDA1,
        CMD.CODOBIECT,
        OBJ.DENUMIRE,
        OBJ.CODEXTERN,
        OBJ.CODINTERN,
        U1.CODUM1 UMSEC,
        CMD.CANT TOTAL,
        CMD.CANTUM1 TOTALUM1,
        CMD.CANT TOTAL_P,
        0 PROGRAMAT,
        0 PROGRAMAT_P,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
        RZ.CANT REALIZAT,
        RZ.CANT REALIZAT_P,
        PR.CANT CONSUMAT,
        PR.CANT CONSUMAT_P,
        UA1.CodUM1 UM1,
        CMD.D1,
        CMD.D2,
        CMD.D3,
        0 RAPORTAT,
        0 RAPORTAT_P,
        0 RAPORTATUM1,
        ART.RELATIEUM1,
        ART.UM,
        U1.PARITATE,
        ART.TIPSERIE,
        CMD.CODCMDPRODMAT,
        CMD.CODCMDPRODMAN,
        C1.TERMEN,
        0 CODPROGRAMF1,
        ART.TIPARTICOL,
        U1.DEN_UM1,
        CMD.Pret,
        CMD.Pret Pret_P,
        0 Supliment,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
        ROUND(NVL(STOCT.CANT,0),
        NVL(U1.ZECIMALE,0)) STOCT,
        NVL(MAT.TIP,3) TIP,
        ROUND(C.NRDOC + C1.indexlocal / 100, 3),
        case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
        0 Echivalenta,
        0 CantEchivalata,
        &apos;NU&apos; EchivString,
        C.CodComanda,
        POBJ.CODARTICOL,
        ppobj.denumire den_produs,
        GIMP.CODGEST,
        C.CODFORMATIE,
        C.SCHIMB,
        IOIMP.CODIOART,
        LIMP.CODLOCATIE, LIMP.Denumire DenLocatie,
        GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
        CLS.DEN_CLASEA,
        UM1.Den_UM Den_UM_1,
        UM2.Den_UM Den_UM_2,
        Tr.Cant Transferat,
        nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
        COALESCE(U1.ZECIMALE,2)
      FROM (SELECT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID) PF1
        INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
        INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
        INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
        INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
        INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
        INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
        INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
        INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
        INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
        INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
        LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
        LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                   from PRODMAT PM
                        left join PRODMATECHIV PE on pe.codmat = pm.codmat
                   GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
        LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                   from transf1 t1
                        inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                        INNER JOIN TMP_GENNP_CMD1 PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                   WHERE PF1.USERID = AUSERID
                   GROUP BY t1.codcomanda1, t1.codobiect
                  ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
        LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
        LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
        LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
        LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
        LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
        LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
        LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
        LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = -1 AND USERID = AUSERID)
                  RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 1 AND USERID = AUSERID)
                  PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                  STOC ON STOC.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                  STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT, CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                  NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODCMDPRODMAT, CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                  REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
      where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6;
    else
      insert into TMP_GENNP_MAT
      SELECT
        - RowNum CodIes1,
        CMD.CODCOMANDA1,
        CMD.CODOBIECT,
        OBJ.DENUMIRE,
        OBJ.CODEXTERN,
        OBJ.CODINTERN,
        U1.CODUM1 UMSEC,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANTUM1 else CMD.CANTUM1 end TOTALUM1,
        case when FlagPF = 1 then PF1.CANT / C1.CANTACCEPTAT * CMD.CANT else CMD.CANT end TOTAL_P,
        0 PROGRAMAT,
        0 PROGRAMAT_P,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR,
        ROUND(CMD.CANT/C1.CANTACCEPTAT,7) UNITAR_P,
        RZ.CANT REALIZAT,
        RZ.CANT REALIZAT_P,
        PR.CANT CONSUMAT,
        PR.CANT CONSUMAT_P,
        UA1.CodUM1 UM1,
        CMD.D1,
        CMD.D2,
        CMD.D3,
        0 RAPORTAT,
        0 RAPORTAT_P,
        0 RAPORTATUM1,
        ART.RELATIEUM1,
        ART.UM,
        U1.PARITATE,
        ART.TIPSERIE,
        CMD.CODCMDPRODMAT,
        CMD.CODCMDPRODMAN,
        PF1.TERMEN,
        PF1.CODPROGRAMF1,
        ART.TIPARTICOL,
        U1.DEN_UM1,
        CMD.Pret,
        CMD.Pret Pret_P,
        0 Supliment,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
        ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC_P,
        ROUND(NVL(STOCT.CANT,0),
        NVL(U1.ZECIMALE,0)) STOCT,
        NVL(MAT.TIP,3) TIP,
        ROUND(C.NRDOC + C1.indexlocal / 100, 3),
        case when MECHIV.Nr &gt; 0 then MAT.CODMAT else 0 end MATECHIV,
        0 Echivalenta,
        0 CantEchivalata,
        &apos;NU&apos; EchivString,
        C.CodComanda,
        POBJ.CODARTICOL,
        ppobj.denumire den_produs,
        GIMP.CODGEST,
        C.CODFORMATIE,
        C.SCHIMB,
        IOIMP.CODIOART,
        LIMP.CODLOCATIE,
        LIMP.Denumire,
        GIMP.DEN_GEST ||&apos;,&apos;||LIMP.DENUMIRE||chr(13)||IOIMP.Den_IOArt GestLocCont,
        CLS.DEN_CLASEA,
        UM1.Den_UM Den_UM_1,
        UM2.Den_UM Den_UM_2,
        Tr.Cant Transferat,
        nvl(ART.ParitateD1,1)*nvl(ART.ParitateD2,1)*nvl(ART.ParitateD3,1) ParitateDuri,
        COALESCE(U1.ZECIMALE,2)
      FROM (SELECT CODCOMANDA1,CODPROGRAMF1,TERMEN,CANT FROM TMP_GENNP_CMD1 WHERE USERID = aUserID) PF1
        INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
        INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
        INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
        INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
        INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1 AND CMD.CANT &gt; 0
        INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
        INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
        INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
        INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
        INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
        LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
        LEFT JOIN (select count(pe.codmatechiv) Nr, PM.CODMAT
                   from PRODMAT PM
                        left join PRODMATECHIV PE on pe.codmat = pm.codmat
                   GROUP BY Pm.CODMAT) MECHIV ON MECHIV.CODMAT = MAT.CODMAT
        LEFT JOIN (select sum(ns.rest) Cant, t1.codcomanda1, t1.codobiect
                   from transf1 t1
                        inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                        INNER JOIN (SELECT DISTINCT CODCOMANDA1 FROM TMP_GENNP_CMD1 WHERE USERID = AUSERID) PF1 ON PF1.CODCOMANDA1 = T1.CODCOMANDA1
                   GROUP BY t1.codcomanda1, t1.codobiect
                  ) tr ON tr.codcomanda1 = c1.codcomanda1 and cmd.codobiect = tr.codobiect
        LEFT JOIN NUM1 UA1 ON UA1.CODUM = ART.UM1 AND NVL(UA1.SECUNDARA,0) = 0
        LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
        LEFT JOIN NGEST GPF1 ON GPF1.CODGEST = C.CODGEST
        LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
        LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
        LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
        LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
        LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
        LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = -11 AND USERID = AUSERID)
                  RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(RZ.CODPROGRAMF1,0)
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT,CODPROGRAMF1 FROM TMP_GENNP_CRS WHERE TIP = 11 AND USERID = AUSERID)
                  PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND COALESCE(PF1.CODPROGRAMF1,0) = COALESCE(PR.CODPROGRAMF1,0)
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 7 AND USERID = AUSERID)
                  STOC ON STOC.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 8 AND USERID = AUSERID)
                  STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODOBIECT,CANT FROM TMP_GENNP_CRS WHERE TIP = 9 AND USERID = AUSERID)
                  NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT
        LEFT JOIN (SELECT CODCMDPRODMAT,CANT FROM TMP_GENNP_CRS WHERE TIP = 10 AND USERID = AUSERID)
                  REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
      where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect) and coalesce(mat.tip,3)&lt;&gt;6 ;
    end if;
  end if;
  COMMIT;
end;

procedure GetCrsMatC is
AUSERID NUMBER(20);
begin
  AUSERID := PKG_GLOBALS.GETUSERID;
  INSERT INTO TMP_GENNP_MATC
  SELECT
    0 CODCOMANDA1,
    CMD.CODOBIECT,
    OBJ.DENUMIRE,
    OBJ.CODEXTERN,
    U1.CODUM1 UMSEC,
    sum(CMD.CANT) TOTAL,
    0 PROGRAMAT,
    sum(nvl(RZ.CANT,0)) REALIZAT,
    sum(nvl(PR.CANT,0)) CONSUMAT,
    ART.UM1,
    0 RAPORTAT,
    0 TRANSFER,
    ART.UM,
    U1.PARITATE,
    ART.TIPSERIE,
    ART.TIPARTICOL,
    U1.DEN_UM1 DEN_UM1,
    ROUND(NVL(STOC.CANT,0) - NVL(NSREZ.CANT,0) + NVL(REZ.CANT,0),NVL(U1.ZECIMALE,0)) STOC,
    ROUND(NVL(STOCT.CANT,0),NVL(U1.ZECIMALE,0)) STOCT,
    0 CODOBIECTEKIV,
    &apos;...nedefinit...&apos; DENUMIREEKIV,
    0 CantEkiv,
    0 StocEkiv,
    0 StocTEkiv,
    COALESCE(U1.ZECIMALE,2)
  FROM (select distinct codcomanda1 from TMP_GENNP_CMD1 where USERID = AUSERID) PF1
    INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
    INNER JOIN NARTOBJ POBJ ON C1.CODOBIECT = POBJ.CODOBIECT
    INNER JOIN NART PA ON POBJ.CODARTICOL = PA.CODARTICOL
    INNER JOIN NARTOBJ PPOBJ ON PA.CODARTICOL = PPOBJ.CODARTICOL
    INNER JOIN CMDPRODMAT CMD ON C1.CODCOMANDA1 = CMD.CODCOMANDA1 AND CMD.TIP = 1
    INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    INNER JOIN NARTOBJ OBJ ON CMD.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
    INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
    INNER JOIN NUM1 U1 ON U1.CODUM = ART.UM AND NVL(U1.SECUNDARA,0) = 0
    LEFT JOIN PRODMAT MAT ON MAT.CODMAT = CMD.CODPRODMAT
    LEFT JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
    LEFT JOIN NARTOBJIMP OIMP ON OBJ.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pkg_globals.GETSUBUNITATE
    LEFT JOIN NGEST GIMP ON GIMP.CODGEST = nvl(IMP.GESTIMPLICITA,0)
    LEFT JOIN IOART IOIMP ON IOIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT, 0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
    LEFT JOIN NLOCATII LIMP ON LIMP.CODLOCATIE = nvl(IMP.LOCATIEIMPLICITA,0)
    LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA
    LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
    LEFT JOIN NUM UM2 ON ART.UM2 = UM2.CODUM
    LEFT JOIN TMP_GENNP_CRS RZ ON RZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = -11 AND RZ.USERID = AUSERID
    LEFT JOIN TMP_GENNP_CRS PR ON PR.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 11 AND RZ.USERID = AUSERID
    LEFT JOIN TMP_GENNP_CRS STOC ON STOC.CODOBIECT = CMD.CODOBIECT AND RZ.TIP = 7 AND RZ.USERID = AUSERID
    LEFT JOIN TMP_GENNP_CRS STOCT ON STOCT.CODOBIECT = CMD.CODOBIECT AND RZ.TIP = 8 AND RZ.USERID = AUSERID
    LEFT JOIN TMP_GENNP_CRS NSREZ ON NSREZ.CODOBIECT = CMD.CODOBIECT AND RZ.TIP = 9 AND RZ.USERID = AUSERID
    LEFT JOIN TMP_GENNP_CRS REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT AND RZ.TIP = 10 AND RZ.USERID = AUSERID
  where not exists (select atro.codobiect from natrobj atro where atro.codobiect = ppobj.codobiect)
  group by
    CMD.CODOBIECT,
    OBJ.DENUMIRE,
    OBJ.CODEXTERN,
    U1.CODUM1,
    ART.UM1,
    ART.UM,
    U1.PARITATE,
    ART.TIPSERIE,
    ART.TIPARTICOL,
    U1.DEN_UM1,
    NVL(STOC.CANT,0), NVL(NSREZ.CANT,0), NVL(REZ.CANT,0), NVL(STOCT.CANT,0), NVL(U1.ZECIMALE,0), COALESCE(U1.ZECIMALE,2);
  COMMIT;
end;

procedure UmpleTemporare(aCodGest in number, aCodGestT in number) is
aUserID number(20);
begin
  --DELETE TMP_IOART_LUNA_F;
  --INSERT INTO TMP_IOART_LUNA_F SELECT * FROM TMP_IOART_LUNA;
  aUserID := PKG_GLOBALS.GETUSERID;
  DELETE TMP_GENNP_CRS WHERE USERID = aUserID;
  DELETE TMP_MANEVRA;

  insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
  SELECT CMD.CODCMDPRODMAT, SUM(I1.CANT) CANT, aUserID, 3--predari neoperate
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1 and nvl(CMD.TIP,0) = 0
       INNER JOIN INTRPRODLINK L ON L.CODLINIECOMANDA = CMD.CODCMDPRODMAT
       INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L.CODINTR1
       INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE NVL(I.OPERAT, 0) = 0 AND NVL(I.ANULAT, 0) = 0 AND I.TIPTRANZACTIE &lt;&gt; 9
  GROUP BY CMD.CODCMDPRODMAT;
  commit;

  insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
  SELECT CMD.CODCMDPRODMAT, SUM(I1.CANT) CANT, aUserID, 2--predari operate
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1 and nvl(CMD.TIP,0) = 0
       INNER JOIN INTRPRODLINK L ON L.CODLINIECOMANDA = CMD.CODCMDPRODMAT
       INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L.CODINTR1
       INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0 AND I.TIPTRANZACTIE &lt;&gt; 9
  GROUP BY CMD.CODCMDPRODMAT;
  commit;

  insert into tmp_gennp_crs(codprogramf1,codcmdprodmat, cant, userid, tip)
  SELECT NVL(PF1.CODPROGRAMF1,0) CODPROGRAMF1, CMD.CODCMDPRODMAT, SUM(F1.CANTPROGRAMAT
                                                                      - NVL((SELECT SUM(LL.CANT) FROM INTRPRODLINK LL WHERE LL.CODPROGRAMF1 = F1.CODPROGRAMF1),0)
                                                                      ) REST, aUserID, 4--programf
  FROM (select CODCOMANDA1,CODPROGRAMF1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
     INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1
     LEFT JOIN PROGRAMF1 F1 ON F1.CODCOMANDA1 = CMD.CODCOMANDA1 AND ((NVL(PF1.CODPROGRAMF1,0) &gt; 0 AND PF1.CODPROGRAMF1 = F1.CODPROGRAMF1) OR NVL(PF1.CODPROGRAMF1,0) = 0)
  GROUP BY CMD.CODCMDPRODMAT,NVL(PF1.CODPROGRAMF1,0);
  commit;

  insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
  SELECT CMD.CODCMDPRODMAT, SUM(L.CANT) CANT, aUserID, 1--consum operat
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1
       INNER JOIN IESPRODLINK L ON L.CODCMDPRODMAT = CMD.CODCMDPRODMAT
       INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
       INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0
  GROUP BY CMD.CODCMDPRODMAT;
  commit;

  insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
  SELECT CMD.CODCMDPRODMAT, SUM(L.CANT) CANT, aUserID, -1--consum neoperat
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1
       INNER JOIN IESPRODLINK L ON L.CODCMDPRODMAT = CMD.CODCMDPRODMAT
       INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
       INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE NVL(I.OPERAT, 0) = 0 AND NVL(I.ANULAT, 0) = 0
  GROUP BY CMD.CODCMDPRODMAT;
  commit;

  insert into tmp_gennp_crs(codprogramf1,codcmdprodmat, cant, userid, tip)
  SELECT 0, CMD1.CODCOMANDA1, SUM(I1.CANT) CANT, aUserID, 12--rebuturi
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) CMD1
       INNER JOIN INTRARI1 I1 ON I1.CODCMDINT1 = CMD1.CODCOMANDA1
       INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0 AND I.TIPTRANZACTIE = 9
  GROUP BY CMD1.CODCOMANDA1;
  commit;

  insert into tmp_gennp_crs(codprogramf1,codcmdprodmat, cant, userid, tip)
  SELECT NVL(L.CODPROGRAMF1,0) CODPROGRAMF1, CMD.CODCMDPRODMAT, SUM(L.CANT) CANT, aUserID, 11--consum operat
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1
       INNER JOIN IESPRODLINK L ON L.CODCMDPRODMAT = CMD.CODCMDPRODMAT
       INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
       INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0
  GROUP BY CMD.CODCMDPRODMAT, NVL(L.CODPROGRAMF1,0);
  commit;

  insert into tmp_gennp_crs(codprogramf1,codcmdprodmat, cant, userid, tip)
  SELECT NVL(L.CODPROGRAMF1,0) CODPROGRAMF1, CMD.CODCMDPRODMAT, SUM(L.CANT) CANT, aUserID, -11--consum neoperat
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON PF1.CODCOMANDA1 = CMD.CODCOMANDA1
       INNER JOIN IESPRODLINK L ON L.CODCMDPRODMAT = CMD.CODCMDPRODMAT
       INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
       INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE NVL(I.OPERAT, 0) = 0 AND NVL(I.ANULAT, 0) = 0
  GROUP BY CMD.CODCMDPRODMAT, NVL(L.CODPROGRAMF1,0);
  commit;

  /*INSERT INTO TMP_MANEVRA(CODUNIC)
  select distinct cmd.codobiect
  from TMP_GENNP_CMD1 TMP
       INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = TMP.CODCOMANDA1
  WHERE CMD.TIP = 1 AND TMP.USERID = aUserID;
  commit;*/

  insert into tmp_gennp_crs(codobiect, userid, tip)
  select distinct cmd.codobiect, aUserID, 5--obiecte unice
  from (select * from TMP_GENNP_CMD1 where USERID = aUserID) TMP
       INNER JOIN (select * from CMDPRODMAT where tip = 1) CMD ON CMD.CODCOMANDA1 = TMP.CODCOMANDA1;

  if pkg_categconst.GetValConstanta(&apos;RapOrdMan&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 then
    insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
    SELECT CMD.CODCMDPRODMAN, SUM(CMD.CANT - nvl(R2.Rebut,0)) CANT, aUserID, 6--raportari manopera
    FROM TMP_GENNP_CMDMAN MAN
         INNER JOIN MANPRODLINK CMD ON MAN.CODCMDPRODMAN = CMD.CODCMDPRODMAN
         INNER JOIN RAPORTP2 R2 ON CMD.CODRAPORTP2 = R2.CODRAPORTP2
         INNER JOIN RAPORTP1 R1 ON R1.CODRAPORTP1  = R2.CODRAPORTP1
         INNER JOIN RAPORTP R ON R1.CODRAPORTP  = R.CODRAPORTP
    GROUP BY CMD.CODCMDPRODMAN;
  else
    insert into tmp_gennp_crs(codprogramf1,codcmdprodmat, cant, userid, tip)
    SELECT CMD.CODPROGRAMF1, CMD.CODCMDPRODMAN, SUM(CMD.CANT - nvl(R2.Rebut,0)) CANT, aUserID, 6--raportari manopera
    FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = PF1.CODCOMANDA1
         INNER JOIN MANPRODLINK CMD ON MAN.CODCMDPRODMAN = CMD.CODCMDPRODMAN
         INNER JOIN RAPORTP2 R2 ON CMD.CODRAPORTP2 = R2.CODRAPORTP2
         INNER JOIN RAPORTP1 R1 ON R1.CODRAPORTP1  = R2.CODRAPORTP1
         INNER JOIN RAPORTP R ON R1.CODRAPORTP  = R.CODRAPORTP
    GROUP BY CMD.CODCMDPRODMAN, CMD.CODPROGRAMF1;
  end if;
  commit;

  /*MERGE INTO tmp_gennp_crs TMP
  USING (
         SELECT NS.CODNIRSTOC, NS.CODOBIECT, NS.REST CANT, aUserID USERID, 7 TIP --stoc in sectie
         FROM tmp_gennp_crs TMP
              INNER JOIN NIRSTOC NS ON NS.CODOBIECT = TMP.CODOBIECT AND NS.REST &gt; 0
              INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR AND NIR.Gest = aCodGest
              INNER JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART AND IOA.MG &lt;&gt; 5
         WHERE TMP.USERID = AUSERID AND TMP.TIP = 5
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = V.USERID AND TMP.TIP = V.TIP)
  WHEN MATCHED THEN UPDATE SET TMP.CANT = NVL(TMP.CANT,0) + V.CANT
  WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.CANT,TMP.USERID,TMP.TIP)
                        VALUES (V.CODOBIECT,V.CANT,V.USERID,V.TIP);*/

  insert into tmp_gennp_crs(codobiect, cant, userid, tip)
  SELECT TMP.CODOBIECT, SUM(NS.REST), aUserID, 7 --stoc in sectie
  FROM (
        SELECT CODOBIECT
        FROM TMP_GENNP_CRS WHERE userid = aUserID AND codobiect IS NOT null AND tip = 5
       ) TMP
    INNER JOIN NIRSTOC NS ON NS.CODOBIECT = TMP.CODOBIECT AND NS.REST &gt; 0
    LEFT  JOIN NIR ON NIR.CODNIR = NS.CODNIR
    LEFT  JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART
  WHERE Coalesce(NIR.Gest, 0) = aCodGest AND Coalesce(IOA.MG,0) &lt;&gt; 5
  GROUP BY TMP.CODOBIECT;
  commit;

  insert into tmp_gennp_crs(codobiect, cant, userid, tip)
  SELECT NS.CODOBIECT, SUM(NS.REST), aUserID, 8 --stoc in gestiunea de transfer
  FROM (
        SELECT CODOBIECT
        FROM TMP_GENNP_CRS WHERE userid = aUserID AND codobiect IS NOT null AND tip = 5
       ) TMP
       INNER JOIN NIRSTOC NS ON TMP.CODOBIECT = NS.CODOBIECT AND NS.REST &gt; 0
       INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR AND NIR.Gest = aCodGestT
       INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
       INNER JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART AND IOA.MG &lt;&gt; 5
  GROUP BY NS.CODOBIECT;
  commit;

  insert into tmp_gennp_crs(codobiect, cant, userid, tip)
  SELECT NS.CODOBIECT,SUM(R.REST), aUserID, 9 --rezervari totale
  FROM (
        SELECT CODOBIECT
        FROM TMP_GENNP_CRS WHERE userid = aUserID AND codobiect IS NOT null AND tip = 5
       ) TMP
       INNER JOIN NIRSTOC NS ON NS.CODOBIECT = TMP.CODOBIECT AND NS.REST &gt; 0
       INNER JOIN REZERVATS R ON NS.CODNIRSTOC = R.CODNIRSTOC AND R.REST &gt; 0
       INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR AND NIR.GEST = ACODGEST
  GROUP BY NS.CODOBIECT;
  commit;

  insert into tmp_gennp_crs(codcmdprodmat, cant, userid, tip)
  SELECT R.CODCMDPRODMAT, SUM(R.REST), aUserID, 10--rezervari pe materiale
  FROM (select CODCOMANDA1 from TMP_GENNP_CMD1 where USERID = aUserID) PF1
       INNER JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = PF1.CODCOMANDA1
       INNER JOIN REZERVATS R ON CMD.CODCMDPRODMAT = R.CODCMDPRODMAT AND R.REST &gt; 0
  GROUP BY R.CODCMDPRODMAT;

  commit;
end;

procedure CORECTIETERMENI is
aCount number(10);
begin
  select count(*) into aCount from comanda1 where to_char(termen,&apos;dd.mm.yyyy&apos;) = &apos;00.00.0000&apos;;
  if aCount &gt; 0 then
    update comanda1 set termen = null where to_char(termen,&apos;dd.mm.yyyy&apos;) = &apos;00.00.0000&apos;;
    commit;
  end if;
end;

end PKG_GENNP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GLOBALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D843ABDB36AF5B2281F8F33E41A6815A767734B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GLOBALS IS
  -- pentru pkg_pmp
  PMPCodIes     NUMBER(20);
  PMPCodIntr    NUMBER(20);
  PMPCodTransf  NUMBER(20);

function NrZileLibere(data1 in varchar2, data2 in varchar2) return number is
acount number(10);
odata date;
zi number(1);
begin
  acount := 0;
  odata := to_date(data1,&apos;dd.mm.yyyy&apos;);
  while odata &lt;= to_date(data2,&apos;dd.mm.yyyy&apos;) loop
    select to_char(odata, &apos;D&apos;) into zi from dual;
    if zi &lt;&gt; 6 and zi &lt;&gt; 7 then
      acount := acount + 1;
    end if;
    odata := odata + 1;
  end loop;
  return acount;
end;

procedure setparams_inventar(aCodInventar in number) is
aLunaPrec NUMBER(2);
aLunaLucru NUMBER(2);
aAnPrec NUMBER(4);
aAnLucru NUMBER(4);
BEGIN
  aAnLucru := PKG_GLOBALS.GetANLUCRU;
  aLunaLucru := PKG_GLOBALS.GetLUNALUCRU;
  PKG_GLOBALS.SetLunaTemp(aAnLucru, aLunaLucru);

  vCodInventar := aCodInventar;
  select Gestiune, DataInventar, 1, ITipCont, IClase, IClaseS, IProd
  into vCodGest, vDataInventar, vToateArt, vToateCont, vToateClasele, vToateClaseleS, vToateProd
  from Inventar where CodInventar = aCodInventar;

  DELETE TMP_MANEVRA_LISTE;

  if vToateCont &lt;&gt; 1 then
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE)
    SELECT &apos;CODIOART&apos;, CODTIPCONT
    FROM INVENTCONT IC
         inner join IOART IO on ic.codtipcont = io.codioart
         INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND aANLUCRU*12+aLunaLUCRU BETWEEN IO1.ALStart AND IO1.ALStop
    WHERE io1.mg &lt;&gt; 5
      AND CODINVENTAR = aCodInventar;
  end if;

  if vToateClasele &lt;&gt; 1 then
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE)
    SELECT &apos;CODCLASEA&apos;, CODCLASEA
    FROM INVENTCLASE
    WHERE CODINVENTAR = aCodInventar;
  end if;

  if vToateClaseleS &lt;&gt; 1 then
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE)
    SELECT &apos;CODCLASEAS&apos;, CODCLASEAS
    FROM INVENTCLASES
    WHERE CODINVENTAR = aCodInventar;
  end if;

  if vToateProd &lt;&gt; 1 then
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE)
    SELECT &apos;CODPART&apos;, CODPART
    FROM INVENTPROD
    WHERE CODINVENTAR = aCodInventar;
  end if;

  if aLunaLucru = 1 then
    aLunaPrec := 12;
    aAnPrec   := aAnLucru - 1;
  else
    aLunaPrec := aLunaLucru - 1;
    aAnPrec   := aAnLucru;
  end if;
  PKG_GLOBALS.SetLunaPRECEDENTA(aAnPrec, aLunaPrec);
  commit;
END;

FUNCTION GETCODINVENTAR RETURN NUMBER IS
BEGIN
  RETURN vCodInventar;
END;

FUNCTION isToateArt RETURN NUMBER IS
BEGIN
  RETURN vToateArt;
END;

FUNCTION isToateClasele RETURN NUMBER IS
BEGIN
  RETURN vToateClasele;
END;

FUNCTION isToateClaseleS RETURN NUMBER IS
BEGIN
  RETURN vToateClaseleS;
END;

FUNCTION isToateProd RETURN NUMBER IS
BEGIN
  RETURN vToateProd;
END;

FUNCTION isToateConturile RETURN NUMBER IS
BEGIN
  RETURN vToateCont;
END;

FUNCTION GETCODGEST RETURN NUMBER IS
BEGIN
  RETURN vCodGest;
END;

FUNCTION GETDATAINVENTAR RETURN DATE IS
BEGIN
  RETURN vDataInventar;
END;

procedure SetDataDeAzi(oData in varchar2) is
begin
  DATADEAZI := TO_DATE(oData, &apos;DD.MM.YYYY&apos;);
end;

function GetDataDeAzi return date is
begin
  return DATADEAZI;
end;

PROCEDURE MEMO_MODIFICARE_PRET(aCODOBIECT IN NUMBER, aCODSUBUNIT IN NUMBER)
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
     O.CODOBIECT,
     PM.LEI AS PRETNOU,
     PM.CODCATPRET
    FROM
      PRETM PM,
      NARTOBJ O,
      NART A,
      NCATPRET CP
    WHERE
      PM.SUBUNITATEA    = aCodSubunit
      AND PM.CODOBIECT  = aCODOBIECT
      AND O.CODOBIECT   = aCODOBIECT
      AND A.CODARTICOL  = O.CODARTICOL
--      AND PM.IMPLICIT   = 1
      AND PM.CODCATPRET = CP.CODCATPRET
      AND CP.TIP IN (1, 2)
  )
  LOOP
    INSERT INTO MODIFICARIPRET(CODMODIF, CODOBIECT, CODCATPRET, PRETNOU, DATA, SUBUNITATEA)
    VALUES(Seq_Modificaripret_Codmodif.Nextval, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.PRETNOU, SYSDATE, aCODSUBUNIT);
  END LOOP;
END;

PROCEDURE SETDEBUGMODE(aMode in boolean) IS
BEGIN
  IF aMode
  THEN DEBUGMODE := 1;
  ELSE DEBUGMODE := 0;
  END IF;
END;

FUNCTION ISDEBUGMODE RETURN NUMBER IS
BEGIN
  RETURN DEBUGMODE;
END;

PROCEDURE RELEASE_ALL_STOCLOCK_EMUL_EXT IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM STOCLOCKEMUL WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) OR USERID IS NULL;
  COMMIT;
END;

PROCEDURE RELEASE_STOC_EMULEDITAT_EXT IS
   PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM EMULEDITAT WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID FROM TMP_PKG_GLOBALS X));
  COMMIT;
END;

PROCEDURE SetPretPentruRetail(TipPret in number) IS
BEGIN
  PretPentruRetail := TipPret;
END;

FUNCTION GetSeparatorAdancime RETURN CHAR IS
  aSep Char;
BEGIN
  SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;SEPARATORDEADANCIME&apos;, ANLUCRU, LUNALUCRU), &apos;0&apos;) INTO aSep FROM dual;
  IF Length(aSep) &gt; 1 THEN aSep := InStrB(aSep, 1, 1); END IF;
  IF Length(aSep) = 0 THEN aSep := &apos;.&apos;; END IF;
  RETURN aSep;
END;

PROCEDURE ResetAllRecordsLunaFlags IS
BEGIN
  MERGE INTO LUNA_RECORDS_FLAGS FLG
  USING (SELECT pkg_globals.GETUSERID userid, 0 NART_FLG, 0 NARTOBJ_FLG, 0 IOART_FLG, 0 NTVA_FLG, 0 NTAXE_FLG, 0 TARIFE_FLG, 0 PRETM_FLG, 0 IOPART_FLG, 0 IOFILIAL_FLG, 0 IOBANK_FLG, 0 IOPERS_FLG,
      0 NART_FLG_CONTA,
      0 NARTOBJ_FLG_CONTA,
      0 IOART_FLG_CONTA,
      0 NTVA_FLG_CONTA,
      0 NTAXE_FLG_CONTA,
      0 IOPART_FLG_CONTA,
      0 IOPERS_FLG_CONTA,
      0 IOFILIAL_FLG_CONTA,
      0 IOBANK_FLG_CONTA,
      0 NGEST1_FLG_CONTA,
      0 NPART1_FLG_CONTA,
      0 NPERS1_FLG_CONTA,
      0 NBANK1_FLG_CONTA
   FROM dual) a
  ON (a.userid = FLG.userid)
  WHEN     MATCHED THEN UPDATE SET
    FLG.NART_FLG     = a.NART_FLG         ,
    FLG.NARTOBJ_FLG  = a.NARTOBJ_FLG      ,
    FLG.IOART_FLG    = a.IOART_FLG        ,
    FLG.NTVA_FLG     = a.NTVA_FLG         ,
    FLG.NTAXE_FLG    = a.NTAXE_FLG        ,
    FLG.TARIFE_FLG   = a.TARIFE_FLG       ,
    FLG.PRETM_FLG    = a.PRETM_FLG        ,
    FLG.IOPART_FLG   = a.IOPART_FLG       ,
    FLG.IOFILIAL_FLG = a.IOFILIAL_FLG     ,
    FLG.IOBANK_FLG   = a.IOBANK_FLG       ,
    FLG.IOPERS_FLG   = a.IOPERS_FLG      ,
    FLG.NART_FLG_CONTA = a.NART_FLG_CONTA,
    FLG.NARTOBJ_FLG_CONTA  = a.NARTOBJ_FLG_CONTA,
    FLG.IOART_FLG_CONTA    = a.IOART_FLG_CONTA,
    FLG.NTVA_FLG_CONTA     = a.NTVA_FLG_CONTA,
    FLG.NTAXE_FLG_CONTA    = a.NTAXE_FLG_CONTA,
    FLG.IOPART_FLG_CONTA   = a.IOPART_FLG_CONTA,
    FLG.IOPERS_FLG_CONTA   = a.IOPERS_FLG_CONTA,
    FLG.IOFILIAL_FLG_CONTA = a.IOFILIAL_FLG_CONTA,
    FLG.IOBANK_FLG_CONTA   = a.IOBANK_FLG_CONTA,
    FLG.NGEST1_FLG_CONTA   = a.NGEST1_FLG_CONTA,
    FLG.NPART1_FLG_CONTA   = a.NPART1_FLG_CONTA,
    FLG.NPERS1_FLG_CONTA   = a.NPERS1_FLG_CONTA,
    FLG.NBANK1_FLG_CONTA   = a.NBANK1_FLG_CONTA
  WHEN NOT MATCHED THEN
    INSERT (FLG.USERID,  FLG.NART_FLG, FLG.NARTOBJ_FLG, FLG.IOART_FLG, FLG.NTVA_FLG, FLG.NTAXE_FLG, FLG.TARIFE_FLG, FLG.PRETM_FLG, FLG.IOPART_FLG, FLG.IOFILIAL_FLG, FLG.IOBANK_FLG, FLG.IOPERS_FLG,
            FLG.NART_FLG_CONTA,
            FLG.NARTOBJ_FLG_CONTA,
            FLG.IOART_FLG_CONTA,
            FLG.NTVA_FLG_CONTA,
            FLG.NTAXE_FLG_CONTA,
            FLG.IOPART_FLG_CONTA,
            FLG.IOPERS_FLG_CONTA,
            FLG.IOFILIAL_FLG_CONTA,
            FLG.IOBANK_FLG_CONTA,
            FLG.NGEST1_FLG_CONTA,
            FLG.NPART1_FLG_CONTA,
            FLG.NPERS1_FLG_CONTA,
            FLG.NBANK1_FLG_CONTA
          )
    VALUES (pkg_globals.getuserid, a.NART_FLG,   a.NARTOBJ_FLG,   a.IOART_FLG,   a.NTVA_FLG,   a.NTAXE_FLG,   a.TARIFE_FLG,   a.PRETM_FLG,   a.IOPART_FLG,   a.IOFILIAL_FLG,   a.IOBANK_FLG,   a.IOPERS_FLG,
    A.NART_FLG_CONTA,
    A.NARTOBJ_FLG_CONTA,
    A.IOART_FLG_CONTA,
    A.NTVA_FLG_CONTA,
    A.NTAXE_FLG_CONTA,
    A.IOPART_FLG_CONTA,
    A.IOPERS_FLG_CONTA,
    A.IOFILIAL_FLG_CONTA,
    A.IOBANK_FLG_CONTA,
    A.NGEST1_FLG_CONTA,
    A.NPART1_FLG_CONTA,
    A.NPERS1_FLG_CONTA,
    A.NBANK1_FLG_CONTA
    );
END;

PROCEDURE SET_DREPT_SALARIZARE(aDrept in boolean) IS
BEGIN
  IF ADREPT
  THEN DREPTSALARIZARE := 1;
  ELSE DREPTSALARIZARE := 0;
  END IF;
END;

FUNCTION GET_DREPT_SALARIZARE RETURN NUMBER IS
BEGIN
  RETURN DREPTSALARIZARE;
END;

PROCEDURE SETLIMBADENART IS
BEGIN
  BEGIN
    --SELECT TO_NUMBER(Coalesce(pkg_categconst.GetValConstanta(&apos;LIMBADENART&apos;, ANLUCRU, LUNALUCRU), &apos;0&apos;)) INTO CODLIMBADENART from dual;
    CODLIMBADENART := TO_NUMBER(Coalesce(pkg_categconst.GetValConstanta(&apos;LIMBADENART&apos;, ANLUCRU, LUNALUCRU), &apos;0&apos;));
  EXCEPTION
    WHEN OTHERS THEN CODLIMBADENART := 0;
  END;
END;

FUNCTION GETLIMBADENART return NUMBER IS
BEGIN
  RETURN CODLIMBADENART;
END;

FUNCTION IS_SUBCLAS_OF(aCLASA IN NUMBER, MASTERCLAS IN NUMBER) RETURN NUMBER
IS
 ISSUBCLAS     NUMBER(1) := 0;
 aCLASACURENTA NUMBER(20) := 0;
 aCODPARINTE   NUMBER(20) := 0;
BEGIN
  IF Coalesce(aCLASA,0) = Coalesce(MASTERCLAS,0) THEN RETURN 1;
  ELSE
    aCLASACURENTA := Coalesce(aCLASA,0);
    SELECT Coalesce(CODPARINTE, 0), Coalesce(CODCLASEA, 0) INTO aCODPARINTE, aCLASACURENTA FROM NCLASEA WHERE CODCLASEA = aCLASACURENTA;
    WHILE aCODPARINTE &lt;&gt; 0
    LOOP
       IF aCODPARINTE = Coalesce(MASTERCLAS,0) THEN RETURN 1;
       ELSE
         aCLASACURENTA := aCODPARINTE;
         SELECT Coalesce(CODPARINTE, 0) INTO aCODPARINTE FROM NCLASEA WHERE CODCLASEA = aCLASACURENTA;
       END IF;
    END LOOP;

  END IF;
  RETURN ISSUBCLAS;
END;

PROCEDURE SET_LUNA_START_AN_CONTABIL(aLUNA IN NUMBER) IS
BEGIN
  LUNA_START_AN_CONTABIL := aLUNA;
END;

FUNCTION GET_LUNA_START_AN_CONTABIL RETURN NUMBER IS
 aLUNA NUMBER(5);
BEGIN
  SELECT DECODE(Coalesce(LUNA_START_AN_CONTABIL, 1), 0, 1, Coalesce(LUNA_START_AN_CONTABIL, 1)) INTO aLUNA FROM DUAL;
  RETURN aLUNA;
END;

FUNCTION GET_AN_SOLDCONT_INI RETURN NUMBER
IS
  aAN   NUMBER(5);
  aLUNA NUMBER(2);
BEGIN
  aAN     := ANLUCRU;
  aLUNA   := /*GET_LUNA_START_AN_CONTABIL*/ 1;
  IF LUNALUCRU &lt; aLUNA THEN aAN := aAN - 1; END IF;

  IF Coalesce(aAN, 0)  = 0 THEN aAN := ANLUCRU; END IF;

  RETURN aAN;
END;

FUNCTION  ANLUNAAVIZOK(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN NUMBER
IS
aAN NUMBER(5);
aLUNA NUMBER(2);
BEGIN
  IF aTIPDOC IN (2, 20) THEN
    IF aTIPDOC = 2 THEN
      BEGIN
       SELECT AN, LUNA INTO aAN, aLUNA FROM INTRARI WHERE CODINTR = aCODDOC;
       EXCEPTION WHEN OTHERS THEN aAN := 0; ALUNA := 0;
      END;
    ELSE
      BEGIN
       SELECT AN, LUNA INTO aAN, aLUNA FROM IESIRI WHERE CODIES = aCODDOC;
       EXCEPTION WHEN OTHERS THEN aAN := 0; ALUNA := 0;
      END;
    END IF;

    IF aAN * 12 + aLUNA &lt;= PKG_GLOBALS.ANPRECEDENT * 12 + PKG_GLOBALS.LUNAPRECEDENTA THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  ELSE
    RETURN 1;
  END IF;
END;

procedure SetPMPCodDocs(aCodIntr in number, aCodIes in number, aCodTransf in number ) IS
begin
  PMPCodIes    := aCodIes    ;
  PMPCodIntr   := aCodIntr   ;
  PMPCodTransf := aCodTransf ;
end;

FUNCTION GetPMPCodIes  RETURN NUMBER IS
BEGIN
 RETURN PMPCodIes  ;
END;

FUNCTION GetPMPCodIntr   RETURN NUMBER IS
BEGIN
 RETURN PMPCodIntr  ;
END;

FUNCTION GetPMPCodTransf   RETURN NUMBER IS
BEGIN
 RETURN PMPCodTransf  ;
END;


FUNCTION ISNUMERIC (P_STRING_VALUE IN VARCHAR2) RETURN NUMBER
IS
 TEST_VALUE NUMERIC;
BEGIN
--  TEST_VALUE := TO_NUMBER (P_STRING_VALUE, &apos;999999999999999999999999999999&apos;);
--  RETURN 1;
   IF regexp_replace(P_STRING_VALUE, &apos;[^0-9]&apos;, &apos;&apos;)= P_STRING_VALUE THEN RETURN 1;
   ELSE
     RETURN 0;
   END IF;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;



PROCEDURE SETPARAMS_CUSTOM(aListID IN NUMBER, aListVER IN NUMBER) IS
BEGIN
  BEGIN
    SELECT
      data1,
      data2,
      an1,
      luna1,
      an2,
      luna2,
      int1data1,
      int1data2,
      int1an1,
      int1luna1,
      int1an2,
      int1luna2,
      int2data1,
      int2data2,
      int2an1,
      int2luna1,
      int2an2,
      int2luna2,
      int3data1,
      int3data2,
      int3an1,
      int3luna1,
      int3an2,
      int3luna2,
      int4data1,
      int4data2,
      int4an1,
      int4luna1,
      int4an2,
      int4luna2,
      int5data1,
      int5data2,
      int5an1,
      int5luna1,
      int5an2,
      int5luna2,
      val1,
      val2,
      val3,
      val4,
      val5
    INTO
      lstDATASTART,
      lstDATASTOP ,
      lstANSTART  ,
      lstLUNASTART,
      lstANSTOP   ,
      lstLUNASTOP,
      lstDATASTART1,
      lstDATASTOP1 ,
      lstANSTART1  ,
      lstLUNASTART1,
      lstANSTOP1   ,
      lstLUNASTOP1,
      lstDATASTART2,
      lstDATASTOP2 ,
      lstANSTART2  ,
      lstLUNASTART2,
      lstANSTOP2   ,
      lstLUNASTOP2,
      lstDATASTART3,
      lstDATASTOP3 ,
      lstANSTART3  ,
      lstLUNASTART3,
      lstANSTOP3,
      lstLUNASTOP3,
      lstDATASTART4,
      lstDATASTOP4,
      lstANSTART4,
      lstLUNASTART4,
      lstANSTOP4   ,
      lstLUNASTOP4,
      lstDATASTART5,
      lstDATASTOP5,
      lstANSTART5,
      lstLUNASTART5,
      lstANSTOP5,
      lstLUNASTOP5,
      lstVal1,
      lstVal2,
      lstVal3,
      lstVal4,
      lstVal5
    FROM paramliste
    WHERE UserID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) and listid = alistid and listver = alistver;
  EXCEPTION
    WHEN OTHERS THEN
      lstDATASTART      := DATA0;
      lstDATASTOP       := DATA0;
      lstANSTART        := 0;
      lstANSTOP         := 0;
      lstLUNASTART      := 0;
      lstLUNASTOP       := 0;
  END;
END;

FUNCTION DATASTART       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART;
END;

FUNCTION DATASTOP        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP ;
END;

FUNCTION ANSTART         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART  ;
END;

FUNCTION ANSTOP          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP   ;
END;

FUNCTION LUNASTART       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART;
END;

FUNCTION LUNASTOP        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP ;
END;

FUNCTION ANLUNASTART         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART*12 + lstLunaStart ;
END;

FUNCTION ANLUNASTOP          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP*12 + lstLunaStop ;
END;
--interval 1
FUNCTION DATASTARTInterval1       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART1;
END;

FUNCTION DATASTOPInterval1        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP1 ;
END;

FUNCTION ANSTARTInterval1         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART1  ;
END;

FUNCTION ANSTOPInterval1          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP1   ;
END;

FUNCTION LUNASTARTInterval1       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART1;
END;

FUNCTION LUNASTOPInterval1        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP1 ;
END;

FUNCTION ANLUNASTARTInterval1        RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART1*12 + lstLunaStart1 ;
END;

FUNCTION ANLUNASTOPInterval1          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP1*12 + lstLunaStop1 ;
END;
--interval2
FUNCTION DATASTARTInterval2       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART2;
END;

FUNCTION DATASTOPInterval2        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP2 ;
END;

FUNCTION ANSTARTInterval2         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART2  ;
END;

FUNCTION ANSTOPInterval2          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP2   ;
END;

FUNCTION LUNASTARTInterval2       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART2;
END;

FUNCTION LUNASTOPInterval2        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP2 ;
END;

FUNCTION ANLUNASTARTInterval2        RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART2*12 + lstLunaStart2 ;
END;

FUNCTION ANLUNASTOPInterval2          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP2*12 + lstLunaStop2 ;
END;
--interval3
FUNCTION DATASTARTInterval3       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART3;
END;

FUNCTION DATASTOPInterval3        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP3 ;
END;

FUNCTION ANSTARTInterval3         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART3  ;
END;

FUNCTION ANSTOPInterval3          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP3;
END;

FUNCTION LUNASTARTInterval3       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART3;
END;

FUNCTION LUNASTOPInterval3        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP3;
END;

FUNCTION ANLUNASTARTInterval3        RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART3*12 + lstLunaStart3;
END;

FUNCTION ANLUNASTOPInterval3          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP3*12 + lstLunaStop3 ;
END;
--interval4
FUNCTION DATASTARTInterval4       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART4;
END;

FUNCTION DATASTOPInterval4        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP4 ;
END;

FUNCTION ANSTARTInterval4         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART4;
END;

FUNCTION ANSTOPInterval4          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP4;
END;

FUNCTION LUNASTARTInterval4       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART4;
END;

FUNCTION LUNASTOPInterval4        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP4 ;
END;

FUNCTION ANLUNASTARTInterval4        RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART4*12 + lstLunaStart4;
END;

FUNCTION ANLUNASTOPInterval4          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP4*12 + lstLunaStop4 ;
END;
--interval5
FUNCTION DATASTARTInterval5       RETURN DATE IS
BEGIN
  RETURN  lstDATASTART5;
END;

FUNCTION DATASTOPInterval5        RETURN DATE IS
BEGIN
  RETURN  lstDATASTOP5;
END;

FUNCTION ANSTARTInterval5         RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART5;
END;

FUNCTION ANSTOPInterval5          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP5   ;
END;

FUNCTION LUNASTARTInterval5       RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTART5;
END;

FUNCTION LUNASTOPInterval5        RETURN NUMBER IS
BEGIN
  RETURN  lstLUNASTOP5;
END;

FUNCTION ANLUNASTARTInterval5        RETURN NUMBER IS
BEGIN
  RETURN  lstANSTART5*12 + lstLunaStart5;
END;

FUNCTION ANLUNASTOPInterval5          RETURN NUMBER IS
BEGIN
  RETURN  lstANSTOP5*12 + lstLunaStop5;
END;
--gata intervale
PROCEDURE SETCODFIRMA(aCODFIRMA IN NUMBER)
IS --PRAGMA AUTONOMOUS_TRANSACTION;
NR NUMBER;
BEGIN
  CODFIRMA := aCODFIRMA;

  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (FIRMAID) VALUES (aCODFIRMA);
  ELSE
    UPDATE TMP_PKG_GLOBALS SET FIRMAID = aCODFIRMA;
  END IF;

/*  UPDATE TMP_PKG_GLOBALS SET FIRMAID = aCODFIRMA;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (FIRMAID) VALUES (aCODFIRMA);
  end if;
*/
  --commit;
END;


FUNCTION GETCODFIRMA RETURN NUMBER
IS
BEGIN
  RETURN CODFIRMA;
END;



PROCEDURE CHECK_ARTICOLE_FARA_OBIECT0
IS
 aCOD  NUMBER(20);
 aAN   NUMBER(5);
 aLUNA NUMBER(2);
BEGIN
FOR V_REC IN
(
SELECT *
FROM
  NART A
WHERE
 (
  SELECT COUNT(*)
  FROM
    NARTOBJ O
  WHERE
    CODARTICOL = A.CODARTICOL
    AND
    (SELECT COUNT(*) FROM NATROBJ WHERE CODOBIECT = O.CODOBIECT) = 0
   ) = 0
)
LOOP
  SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO aCOD FROM DUAL;
  SELECT ANINITIAL, LUNAINITIALA INTO aAN, aLUNA FROM FIRMALUNI;

  INSERT INTO NARTOBJ(CODOBIECT, CODARTICOL, DENUMIRE)
  VALUES (aCOD, V_REC.CODARTICOL, V_REC.DEN_ARTICOL);

  INSERT INTO NARTOBJ1(CODOBIECT1, CODOBIECT, ANSTART, LUNASTART)
  VALUES (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, aCOD, aAN, aLUNA);

  prc_al_refresh(&apos;NARTOBJ1&apos;, aCOD);
END LOOP ;
COMMIT;
END;

FUNCTION GETDATASOLDBANCI RETURN DATE
IS
BEGIN
  RETURN DATASOLDBANCI;
END;


FUNCTION GETUSERNAME RETURN VARCHAR2 IS
BEGIN
 RETURN USERNAME;
END;

PROCEDURE MAKE_IOPART_LUNA
IS
BEGIN
  DELETE FROM TMP_IOPartLuna;
  INSERT INTO TMP_IOPartLuna (
    CODPART, CODPART1, DEN_PART, CODIOPART, CODIOPART1, DEN_IOPART,
    CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ,
    CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN,
    CONTTERTI,
    CONTFURNLEAS,
    CONTNCRF, CONTNCRC,
    contcheltavans, contvenitavans,
    contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC,
    ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5,
    ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5,
    TIP
  )
  SELECT
    n.codpart, n1.codpart1, n.den_part, Coalesce(n1.codiopart, 0) codiopart, io1.codiopart1, io.den_iopart,
    io1.contfurnizor, io1.contclient, io1.contfurnavans, io1.contclientavans, io1.contfurnaviz, io1.contclientaviz,
    io1.contfurnmf, io1.contcreditd, io1.contdebitd, io1.contlitigii, io1.contfurnavs, io1.contfurnavic, io1.contfurnavin,
    io1.contterti,
    IO1.CONTFURNLEAS,
    IO1.CONTNCRF, IO1.CONTNCRC,
    io1.contcheltavans, io1.contvenitavans,
    io1.contgarantieEF, io1.contgarantieTF, io1.contgarantieEC, io1.contgarantieTC,
    io1.ContSuplimF1, io1.ContSuplimF2, io1.ContSuplimF3, io1.ContSuplimF4, io1.ContSuplimF5,
    io1.ContSuplimC1, io1.ContSuplimC2, io1.ContSuplimC3, io1.ContSuplimC4, io1.ContSuplimC5,
    io1.tip
  FROM npart n
    CROSS JOIN TMP_PKG_GLOBALS TG
    LEFT JOIN npart1 n1 ON n.codpart = n1.codpart AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN n1.ALStart AND n1.ALStop
    LEFT JOIN iopart io ON Coalesce(n1.codiopart, 0) = Coalesce(io.codiopart, 0)
    LEFT JOIN iopart1 io1 ON io.codiopart = io1.codiopart AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN io1.ALStart AND io1.ALStop;

END;



FUNCTION DOCINTRARE_ARE_STOC_IN_LUNA(aCODDOC IN NUMBER, aTIPDOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER
IS
  NR NUMBER(20) := 0;
  ARESTOC NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  (
  SELECT
    NS.CODNIRSTOC
  FROM
    NIRSTOC NS,
    NIR N,
    INTRARI I
  WHERE
    N.CODNIR      = NS.CODNIR
    AND N.TIPNIR  = aTIPDOC
    AND I.CODINTR = aCODDOC
    AND I.AN * 12 + I.LUNA &lt;= aAN * 12 + aLUNA
    AND N.CODINTR = aCODDOC
  )
  LOOP
    SELECT COUNT(*) INTO NR FROM NIRLUNA
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC
      AND AN   = aAN
      AND LUNA = aLUNA
      AND REST &lt;&gt; 0;
    IF NR &gt; 0 THEN RETURN NR;
    ELSE
      ARESTOC := ARESTOC + NR;
    END IF;
  END LOOP;
  RETURN ARESTOC;
END;



FUNCTION DOCINTRARE_ARE_SOLD_IN_LUNA(aCODDOC IN NUMBER, aTIPDOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER
IS
  NR NUMBER(20) := 0;
  ARESOLD NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  (
  SELECT
    O.CODOBLIGPIF
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I
  WHERE
    G.CODGENERAL = O.CODGENERAL
    AND G.TIPDOC = aTIPDOC
    AND G.CODDOC = aCODDOC
    AND I.CODINTR = aCODDOC
    AND I.AN * 12 + I.LUNA &lt;= aAN * 12 + aLUNA
  )
  LOOP
    SELECT COUNT(*) INTO NR FROM OBLIGPIFLUNA
    WHERE
      CODOBLIGPIF = V_REC.CODOBLIGPIF
      AND AN   = aAN
      AND LUNA = aLUNA
      AND REST &lt;&gt; 0;
    IF NR &gt; 0 THEN RETURN NR;
    ELSE
      ARESOLD := ARESOLD + NR;
    END IF;
  END LOOP;
  RETURN ARESOLD;
END;

--OldStyle JurnRefac
PROCEDURE CLEAR_JURNREFAC_FLG
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM JURNREFAC;
  COMMIT;
END;

PROCEDURE SET_JURNREFAC_FLG(FLAG NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF FLAG = 0 THEN
    DELETE FROM JURNREFAC JR WHERE JR.USERID = Coalesce(((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), 0);
  ELSE
    INSERT INTO JURNREFAC (USERID) VALUES (Coalesce(((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), 0));
  END IF;
  COMMIT;
END;
--NewStyle JurnRefac

PROCEDURE MarkDirtyJurnal
IS
BEGIN
  DELETE FROM DIRTYJURNAL where AnLuna = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
END;

PROCEDURE ClearDirtyJurnal
IS
PRAGMA AUTONOMOUS_TRANSACTION;
Cate number;
BEGIN
  SELECT COUNT(*) into Cate FROM DIRTYJURNAL where AnLuna = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  if Cate = 0 then
    INSERT INTO DirtyJurnal(ANLUNA) Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS;
  end if;
  COMMIT;
END;

function  DIRTYJURNAL_COUNT return number
IS
Cate number;
BEGIN
  SELECT COUNT(*) into Cate FROM JURNAL1 where Dirty &gt; 0 and An*12 + Luna = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  if Cate &gt; 0 then
    Return Cate;
  else
    SELECT COUNT(*) into Cate FROM DIRTYJURNAL where AnLuna = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
    if Cate &gt; 0 then
      Return 0;
    else
      RETURN 1;
    end if;
  end if;
END;



PROCEDURE ClearFlag_RefacereJurnal(Unu in number)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  if Unu = 1 then
     DELETE FROM JURNREFAC where UserId = Coalesce(((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), 0) ;
  else
     DELETE FROM JURNREFAC;
  end if;
  COMMIT;
END;

function  Flag_OK_RefacereJurnal(aTip in number) return number
is
PRAGMA AUTONOMOUS_TRANSACTION;
x number;
begin
  update JURNREFAC set ANLUNA=(Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) , TIP=aTip where UserID=((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X));
--  x:= SQL%rowcount;
  if SQL%rowcount = 0 then
    INSERT INTO JURNREFAC (USERID, ANLUNA, TIP) VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)),(Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) , aTip);
  end if;
  COMMIT;

  if aTip = 0
  then   --Conta
    SELECT COUNT(*) into X FROM JURNREFAC WHERE USERID &lt;&gt; ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND ANLUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  else  --Document
    SELECT COUNT(*) into X  FROM JURNREFAC WHERE TIP = 0 AND USERID &lt;&gt; ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND ANLUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  end if;
  if X &gt; 0 then
    DELETE FROM JURNREFAC where UserId = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X));
    COMMIT;
  end if;
  Return X;
end;

-- START BLOCARE COMENZI STINSE--
PROCEDURE LOCK_CANTSTINSA_CMD(aCODLINIECOMANDA IN NUMBER, aCODLINIESTINGATOARE IN NUMBER, aCANT IN NUMBER)
IS
NR NUMBER(10) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CMDCANTLOCK
  WHERE
  USERID =((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODLINIECOMANDA =  aCODLINIECOMANDA AND
  CODLINIESTINGATOARE = aCODLINIESTINGATOARE;

  IF NR = 0 THEN
    INSERT INTO CMDCANTLOCK (CODLINIECOMANDA, CODLINIESTINGATOARE, CANT, USERID)
    VALUES (aCODLINIECOMANDA, aCODLINIESTINGATOARE, aCANT, ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)));
  ELSE
    UPDATE CMDCANTLOCK
    SET
      CANT = aCANT
    WHERE
      USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODLINIECOMANDA =  aCODLINIECOMANDA AND CODLINIESTINGATOARE = aCODLINIESTINGATOARE;
 END IF;
 COMMIT;
END;

PROCEDURE UNLOCK_CANTSTINSA_CMD(aCODLINIECOMANDA IN NUMBER, aCODLINIESTINGATOARE IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  CMDCANTLOCK
  WHERE
   USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
   AND CODLINIECOMANDA = aCODLINIECOMANDA
   AND CODLINIESTINGATOARE = aCODLINIESTINGATOARE;
  COMMIT;
END;

PROCEDURE RELEASE_ALL_CMDCANTLOCK
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CMDCANTLOCK
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) OR USERID IS NULL;
  COMMIT;
END;


PROCEDURE LOCK_CANTSTINSA_AVIZ(aCODLINIEAVIZ IN NUMBER, aCODLINIEFACT IN NUMBER, aTIPAVIZ IN NUMBER, aCANT IN NUMBER)
IS
NR NUMBER(10) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM AVIZCANTLOCK
  WHERE
  USERID =((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
  AND CODLINIEAVIZ =  aCODLINIEAVIZ
  AND CODLINIEFACT = aCODLINIEFACT
  AND TIPAVIZ = aTIPAVIZ;



  IF NR = 0 THEN
    INSERT INTO AVIZCANTLOCK (CODLINIEAVIZ, CODLINIEFACT, TIPAVIZ, CANT, USERID)
    VALUES (aCODLINIEAVIZ, aCODLINIEFACT, aTIPAVIZ, aCANT, ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)));
  ELSE
    UPDATE AVIZCANTLOCK
    SET
      CANT = aCANT
    WHERE
      USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
      AND CODLINIEAVIZ =  aCODLINIEAVIZ
      AND CODLINIEFACT = aCODLINIEFACT
      AND TIPAVIZ = aTIPAVIZ;
 END IF;
 COMMIT;
END;

PROCEDURE UNLOCK_CANTSTINSA_AVIZ(aCODLINIEAVIZ IN NUMBER, aCODLINIEFACT IN NUMBER, aTIPAVIZ IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  AVIZCANTLOCK
  WHERE
   USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
   AND CODLINIEAVIZ = aCODLINIEAVIZ
   AND CODLINIEFACT = aCODLINIEFACT
   AND TIPAVIZ = aTIPAVIZ;
  COMMIT;
END;


PROCEDURE RELEASE_ALL_AVIZCANTLOCK(aTIPAVIZ IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM AVIZCANTLOCK
  WHERE
   USERID =((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND TIPAVIZ = aTIPAVIZ;
  COMMIT;
END;



FUNCTION GET_CANTCMD_REALA(aCODLINIECOMANDA IN NUMBER) RETURN NUMBER
IS
 CANTREAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT
      Coalesce(RESTACCEPTAT, 0) -
      Coalesce((SELECT SUM(CANT) FROM CMDCANTLOCK C WHERE CODLINIECOMANDA = aCODLINIECOMANDA AND C.USERID &lt;&gt; ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))), 0)
    INTO
      CANTREAL
    FROM
      COMANDA1 WHERE CODCOMANDA1 = aCODLINIECOMANDA;
    EXCEPTION WHEN OTHERS THEN CANTREAL := 0;
  END;
  RETURN CANTREAL;
END;


FUNCTION CANTCMD_PRELUATA_ALTI_USERI(aCODLINIECOMANDA IN NUMBER) RETURN NUMBER
IS
 CANTPREL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(CANT) INTO CANTPREL FROM CMDCANTLOCK C WHERE CODLINIECOMANDA = aCODLINIECOMANDA AND C.USERID &lt;&gt; ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X));
    EXCEPTION WHEN OTHERS THEN CANTPREL := 0;
  END;
  RETURN CANTPREL;
END;

-- END BLOCARE COMENZI STINSE--



-- START BLOCARE OBLIGATII STINSE --
PROCEDURE LOCK_VALSTINSA_OBLIGPIF(aCODOBLIGPIF IN NUMBER, aCODOBLIGSTINGATOR IN NUMBER, aVALOARE IN NUMBER)
IS
NR NUMBER(10) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM OBLIGPIFLOCK WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODOBLIGPIF =  aCODOBLIGPIF AND CODSTINGATORPIF = aCODOBLIGSTINGATOR;
  IF NR = 0 THEN
    INSERT INTO OBLIGPIFLOCK (USERID, CODOBLIGPIF, CODSTINGATORPIF, VALOARE) VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), aCODOBLIGPIF, aCODOBLIGSTINGATOR, aVALOARE);
  ELSE
    UPDATE OBLIGPIFLOCK
    SET
      VALOARE = aVALOARE
    WHERE
      USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODOBLIGPIF =  aCODOBLIGPIF AND CODSTINGATORPIF = aCODOBLIGSTINGATOR;
 END IF;
 COMMIT;
END;


PROCEDURE UNLOCK_VALSTINSA_OBLIGPIF(aCODOBLIGPIF IN NUMBER, aCODOBLIGSTINGATOR IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  OBLIGPIFLOCK
  WHERE
   USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODOBLIGPIF =  aCODOBLIGPIF AND CODSTINGATORPIF = aCODOBLIGSTINGATOR;
   COMMIT;
END;



PROCEDURE RELEASE_ALL_OBLIGPIFLOCK
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM OBLIGPIFLOCK
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) OR USERID IS NULL;
  COMMIT;
END;

-- END BLOCARE OBLIGATII STINSE --

PROCEDURE SET_EXE_VERSION (AVER VARCHAR2) IS
NR NUMBER;
BEGIN
  EXE_VERSION := AVER;


  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (exeversion) VALUES (AVER);
  ELSE
    update TMP_PKG_GLOBALS  set exeversion = AVER;
  END IF;


/*
  update TMP_PKG_GLOBALS  set exeversion = AVER;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (exeversion) VALUES (AVER);
  end if;
*/
END;

FUNCTION GET_EXE_VERSION RETURN VARCHAR2 IS
BEGIN
  RETURN EXE_VERSION;
END;


PROCEDURE GetCodObiect IS
BEGIN
DELETE CERTIF WHERE CODOBIECT = 0;
DELETE FROM proiect  WHERE codproiect  = 0;
DELETE FROM prodcomp WHERE codprodcomp = 0;
DELETE FROM prodcomp WHERE codprodcomp = 1;
DELETE FROM nartobj  WHERE codobiect   = 0;
DELETE FROM tabimpcod t WHERE t.tabname = &apos;NARTOBJ&apos;;

INSERT INTO tabimpcod(imptabname,imppkval,tabname,tabpkval,impcolval)
 SELECT t.imptabname,t.imppkval,&apos;NARTOBJ&apos;,
                     (SELECT codobiect FROM nartobj obj WHERE obj.codarticol = t.TABPKVAL),t.impcolval
FROM Tabimpcod t
WHERE t.Tabname = &apos;NART&apos;;
COMMIT;
END;

FUNCTION DEL_INTRARE_DOCS(pAN IN NUMBER, pLUNASTART IN NUMBER, pLUNASTOP IN NUMBER) RETURN NUMBER
IS
  Ok NUMBER := 1;
BEGIN
  BEGIN
-- NIR1
  delete from nir1 where codnirstoc in (select codnirstoc from nirstoc where codnir in (select codnir from nir where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP))
                                    );
-- NIRSER
  delete from nirser where codnirstoc in (select codnirstoc from nirstoc where codnir in (select codnir from nir where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP))
                                    );


--NIRSTOC
  delete from nirstoc where codnir in (select codnir from nir where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP)
                                    );

  delete from nirstoc where codintr1 in (select codintr1 from intrari1 where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP)
                                    );
  delete from nirstoc where coddvi1 in (select coddvi1 from dvi1 where coddvi in
                                    (select coddvi from dvi where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP)
                                    ));

--OBLIGPIF
  delete from obligpif where codgeneral in (select codgeneral from general where coddoc in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP)
                                    );

--DVI1
  delete from dvi1 where coddvi in (select coddvi from dvi where codintr in
                                    (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP)
                                    );
--DVI
  delete from dvi where codintr in (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP);

--NIR
  delete from nir where codintr in (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP);

--INTRARI1
  delete from intrari1 where codintr in (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP);

--GENERAL
  delete from general where coddoc in (select codintr from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP);

--INTRARI
  delete from intrari where an = pAn and luna between pLUNASTART and pLUNASTOP;

  COMMIT;
  Ok := 1;
  EXCEPTION WHEN OTHERS THEN Ok := 0;
  END;
  RETURN Ok;
END;


FUNCTION GETPREFIXDOC(aTIPDOC IN NUMBER) RETURN VARCHAR2
IS
 aPREFIX VARCHAR2(2) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT PREFIX INTO aPREFIX FROM TMP_MACHETE WHERE CODMACHETA = aTIPDOC;
    EXCEPTION WHEN OTHERS THEN aPREFIX := &apos;&apos;;
  END;
  RETURN aPREFIX;
END;

FUNCTION GET_COD_ECHIVALENT_ORACLE(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2) RETURN NUMBER
IS
 CODORACLE NUMBER(20) := -1;
BEGIN
  BEGIN
    IF (Coalesce(KODPDX,-1) &gt; -1) THEN
      SELECT
        TABPKVAL INTO CODORACLE FROM TABIMPCOD
      WHERE
        IMPTABNAME = NUMETABELAPDX AND
        IMPPKVAL   = KODPDX AND
        TABNAME    =  NUMETABELAORACLE;
    ELSIF (Coalesce(COLVALPDX,-1) &gt; -1) THEN
      SELECT
        TABPKVAL INTO CODORACLE FROM TABIMPCOD
      WHERE
        IMPTABNAME = NUMETABELAPDX AND
        IMPCOLVAL   = COLVALPDX AND
        TABNAME    =  NUMETABELAORACLE;
    END IF;
    EXCEPTION WHEN OTHERS THEN CODORACLE := -1;
  END;
  RETURN CODORACLE;
END;


FUNCTION GET_COD_ECHIVALENT_ORACLE_WM(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, aSUBUNIT IN NUMBER) RETURN NUMBER
IS
 CODORACLE NUMBER(20) := -1;
BEGIN
  BEGIN
    IF (Coalesce(KODPDX,-1) &gt; -1) THEN
      SELECT
        TABPKVAL INTO CODORACLE FROM TABIMPCODWM
      WHERE
        IMPTABNAME  = NUMETABELAPDX AND
        IMPPKVAL    = KODPDX AND
        TABNAME     =  NUMETABELAORACLE AND
        SUBUNITATEA = aSUBUNIT;
    ELSIF (Coalesce(COLVALPDX,-1) &gt; -1) THEN
      SELECT
        TABPKVAL INTO CODORACLE FROM TABIMPCODWM
      WHERE
        IMPTABNAME = NUMETABELAPDX AND
        IMPCOLVAL   = COLVALPDX AND
        TABNAME    =  NUMETABELAORACLE AND
        SUBUNITATEA = aSUBUNIT;

    END IF;
    EXCEPTION WHEN OTHERS THEN CODORACLE := -1;
  END;
  RETURN CODORACLE;
END;

PROCEDURE UPDATE_COD_ECHIVALENT_ORACLE(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, KODORACLE IN NUMBER)
IS
 NR NUMBER := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT COUNT(*) INTO NR FROM TABIMPCOD
    WHERE
      IMPTABNAME = NUMETABELAPDX AND
      IMPPKVAL   = KODPDX;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR &lt;&gt; 0 THEN
    UPDATE TABIMPCOD
    SET
      IMPCOLVAL = COLVALPDX,
      TABNAME  = NUMETABELAORACLE,
      TABPKVAL =   KODORACLE
    WHERE
      IMPTABNAME = NUMETABELAPDX AND
      IMPPKVAL   = KODPDX;

  ELSE
    INSERT INTO TABIMPCOD (IMPTABNAME, IMPPKVAL, IMPCOLVAL, TABNAME, TABPKVAL)
                   VALUES (NUMETABELAPDX,  KODPDX, COLVALPDX, NUMETABELAORACLE, KODORACLE);
  END IF;
  COMMIT;
END;



PROCEDURE UPDATE_COD_ECHIV_ORACLE_WM(NUMETABELAPDX IN VARCHAR2, KODPDX IN NUMBER, COLVALPDX IN NUMBER, NUMETABELAORACLE IN VARCHAR2, KODORACLE IN NUMBER, aSUBUNIT IN NUMBER)
IS
 NR NUMBER := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT COUNT(*) INTO NR FROM TABIMPCODWM
    WHERE
      IMPTABNAME  = NUMETABELAPDX AND
      IMPPKVAL    = KODPDX AND
      SUBUNITATEA = aSUBUNIT;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR &lt;&gt; 0 THEN
    UPDATE TABIMPCODWM
    SET
      IMPCOLVAL   = COLVALPDX,
      TABNAME     = NUMETABELAORACLE,
      TABPKVAL    =  KODORACLE,
      SUBUNITATEA = aSUBUNIT
    WHERE
      IMPTABNAME = NUMETABELAPDX AND
      IMPPKVAL   = KODPDX;

  ELSE
    INSERT INTO TABIMPCODWM (IMPTABNAME, IMPPKVAL, IMPCOLVAL, TABNAME, TABPKVAL, SUBUNITATEA)
                   VALUES (NUMETABELAPDX,  KODPDX, COLVALPDX, NUMETABELAORACLE, KODORACLE, aSUBUNIT);
  END IF;
  COMMIT;
END;



 FUNCTION GET_SEQ_NEXTVAL(sSEQ IN VARCHAR2) RETURN NUMBER
 IS
 val NUMBER := 0;
 BEGIN
    BEGIN
      EXECUTE IMMEDIATE &apos;SELECT &apos; || sSEQ ||&apos;.NEXTVAL FROM DUAL &apos;INTO VAL;
      EXCEPTION WHEN OTHERS THEN VAL := 0;
    END;
    RETURN val;
 END;

PROCEDURE set_CODCANAMED(aCod IN NUMBER) IS
BEGIN
 CODCANAMED := aCod;
END;

FUNCTION Get_CODCANAMED RETURN NUMBER IS
BEGIN
 RETURN CODCANAMED;
END;

PROCEDURE SET_RECID_DOC_LISTARE( pRECID IN NUMBER) IS
BEGIN
 OLDRECID_DOC_LISTARE := RECID_DOC_LISTARE;
 RECID_DOC_LISTARE := pRECID;
END;

PROCEDURE Restore_OLDRECID_DOC_LISTARE IS
BEGIN
 RECID_DOC_LISTARE := OLDRECID_DOC_LISTARE;
END;

FUNCTION GET_RECID_DOC_LISTARE RETURN NUMBER IS
BEGIN
 RETURN RECID_DOC_LISTARE;
END;

PROCEDURE SET_FILTRARE_STOC_VAL(FILTRARE IN NUMBER)
IS
BEGIN
  FILTRARE_STOC_VAL := FILTRARE ;
END;

PROCEDURE SET_VALORI_FILTRU_STOC_VAL(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER, aDATALIMITA IN VARCHAR2)
IS
BEGIN
  FILTRU_GEST_STOCVAL       := aGEST;
  FILTRU_CODIOART_STOCVAL   := aCODIOART;
  FILTRU_PROCTVA_STOCVAL    := aPROCTVA;
  FILTRU_DATALIMITA_STOCVAL := Substr(aDATALIMITA,1,10);
END;

FUNCTION FILTRU_STOCVAL_TRANZACTII_OK(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER, aDATADOC IN DATE) RETURN NUMBER
IS
BEGIN
  IF FILTRARE_STOC_VAL = 0 THEN RETURN 1;
  ELSE
    IF FILTRU_GEST_STOCVAL     = aGEST AND
       FILTRU_CODIOART_STOCVAL = aCODIOART AND
       FILTRU_PROCTVA_STOCVAL  = aPROCTVA AND
       TO_DATE(FILTRU_DATALIMITA_STOCVAL, &apos;dd.mm.yyyy&apos;)  &gt;= aDATADOC
       THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  END IF;
END;


FUNCTION FILTRU_STOCVAL_LUNAPREC_OK(aGEST IN NUMBER, aCODIOART IN NUMBER, aPROCTVA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF FILTRARE_STOC_VAL = 0 THEN RETURN 1;
  ELSE
    IF FILTRU_GEST_STOCVAL     = aGEST AND
       FILTRU_CODIOART_STOCVAL = aCODIOART AND
       FILTRU_PROCTVA_STOCVAL  = aPROCTVA THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  END IF;
END;


PROCEDURE UPDATe_mesaj_avarie(pID IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION ;
BEGIN
UPDATE mesaje SET tip_Mesaj = 0 WHERE idmesaj = pID;
COMMIT;
END;


FUNCTION check_messages (tip OUT NUMBER,cnt OUT NUMBER,idmess OUT NUMBER) RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION ;
sResult VARCHAR2(1000):=&apos;&apos;;
BEGIN
 BEGIN

 SELECT m.tip_mesaj,m.text,m.idmesaj INTO tip,sResult,idmess
 FROM mesaje m
 WHERE upper(m.usern) = upper(username) AND tip_mesaj &gt;= 1 AND rownum =1;
 EXCEPTION WHEN OTHERS THEN
 sResult := &apos;&apos;;
  END;
 IF Coalesce(sResult,&apos;-1&apos;) =&apos;-1&apos; THEN
  SELECT COUNT(*) INTO cnt FROM mesaje WHERE tip_mesaj = 0 ;
 END IF;
 UPDATE mesaje SET tip_Mesaj = 0 WHERE idmesaj = Coalesce(idmess,0);
 COMMIT;
 RETURN sResult;

END;

PROCEDURE SET_TIPDOC_IMPORTAT(aTIPDOC IN NUMBER)
IS
BEGIN
  TIPDOCIMPORTAT := aTIPDOC;
END;

FUNCTION  GET_TIPDOC_IMPORTAT RETURN NUMBER
IS
BEGIN
  RETURN TIPDOCIMPORTAT;
END;


PROCEDURE SetAnLunaBlocata(An in number, Luna in number) is
NR NUMBER;
begin
 update firmaluni set
        anblocat = an,
        lunablocata = luna;
 commit;

  pkg_globals.ANBLOCAT := an;
  pkg_globals.LUNABLOCATA := luna;



  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (AnBlocat, LunaBlocata) VALUES (an , luna);
  ELSE
    update TMP_PKG_GLOBALS  set AnBlocat = an , LunaBlocata = luna;
  END IF;


/*
  update TMP_PKG_GLOBALS  set AnBlocat = an , LunaBlocata = luna;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (AnBlocat, LunaBlocata) VALUES (an , luna);
  end if;
*/
end;

function  getAnBlocat return number is
 iResult number(4);
begin
 select Coalesce(anblocat,0) into iResult from firmaluni;
 return iResult;
end;

function  getLunaBlocata return number is
 iResult number(2);
begin
 select Coalesce(lunablocata,0) into iResult from firmaluni;
 return iResult;
end;


 PROCEDURE SETSUBUNITATE_DOC (asubunitate NUMBER)
 IS
 BEGIN
   SUBUNITATE_DOC := ASUBUNITATE;
 END;

  FUNCTION  GETSUBUNITATE_DOC  RETURN NUMBER
  IS
  BEGIN
    RETURN SUBUNITATE_DOC ;
  END;

 FUNCTION SUBUNITATEDOC_VALIDA(ASUBUNITATE IN NUMBER) RETURN NUMBER
 IS
 BEGIN
   IF SUBUNITATE_DOC &lt;= 1 THEN RETURN 1;
   ELSE
     IF ASUBUNITATE = SUBUNITATE_DOC THEN RETURN 1;
                                     ELSE RETURN 0;
     END IF;
   END IF;
 END;


FUNCTION GETDATACALCULSTOC RETURN DATE
IS
BEGIN
  RETURN DATACALCULSTOC;
END;



FUNCTION GETDATASOLDPART RETURN DATE
IS
BEGIN
  RETURN DATASOLDPART;
END;




FUNCTION GET_STOC_REAL_EMUL(aCODOBIECT IN NUMBER,
                            aCODGEST IN NUMBER,
                            aCODIOART IN NUMBER,
                            aPRET IN NUMBER) RETURN NUMBER
IS
 STOC         NUMBER(20, 7) := 0;
 STOCBLOCAT   NUMBER(20, 7) := 0;
 STOCEMULARE1 NUMBER(20, 7) := 0;
 REZERVARI    NUMBER(20, 7) := 0;
BEGIN

  SELECT SUM(CANT) INTO STOC FROM
  (
  SELECT Coalesce(SUM(REST - Coalesce(SL.CANT, 0)), 0) AS CANT
   FROM
     NIRSTOC NS
     LEFT JOIN STOCLOCK SL ON SL.CODNIRSTOC = NS.CODNIRSTOC,
     NIR N
   WHERE
     N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = aCODOBIECT
     AND N.GEST       = aCODGEST
     AND NS.CODIOART  = aCODIOART
     AND Coalesce(NS.PRET, 0)      = aPRET
  UNION ALL
  SELECT -Coalesce(SUM(R.REST), 0) AS CANT
   FROM
     REZERVATS R,
     NIRSTOC NS,
     NIR N
   WHERE
     R.CODNIRSTOC = NS.CODNIRSTOC
     AND N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = aCODOBIECT
     AND N.GEST       = aCODGEST
     AND NS.CODIOART  = aCODIOART
     AND Coalesce(NS.PRET, 0) = aPRET
    UNION ALL
     SELECT -Coalesce(SUM(CANT), 0) AS CANT
     FROM STOCLOCKEMUL
      WHERE
        CODOBIECT     = aCODOBIECT
        AND CODGEST   = aCODGEST
        AND CODIOART  = aCODIOART
        AND PRET      = aPRET
     UNION ALL
     SELECT -Coalesce(SUM(CANT), 0) AS CANT
      FROM
       EMULARE1 E1,
       EMULARE E
      WHERE
        Coalesce(E.PRELUAT, 0) = 0
        AND Coalesce(E.FACTURARE, 0) = 0
        AND NOT EXISTS(SELECT CODEMULARE FROM EMULEDITAT WHERE CODEMULARE = E.CODEMULARE)
        AND E1.CODEMULARE = E.CODEMULARE
        AND CODOBIECT     = aCODOBIECT
        AND CODGEST       = aCODGEST
        AND CODIOART      = aCODIOART
        AND PRETNIRSTOC   = aPRET
 );

 RETURN NVL(STOC, 0);



/*

 BEGIN
  SELECT Coalesce(SUM(REST - Coalesce(SL.CANT, 0)), 0)  INTO STOC
   FROM
     NIRSTOC NS
     LEFT JOIN STOCLOCK SL ON SL.CODNIRSTOC = NS.CODNIRSTOC,
     NIR N
   WHERE
     N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = aCODOBIECT
     AND N.GEST       = aCODGEST
     AND NS.CODIOART  = aCODIOART
     AND Coalesce(NS.PRET, 0)      = aPRET;
     EXCEPTION WHEN OTHERS THEN STOC := 0;
  END;

 BEGIN
   SELECT Coalesce(SUM(R.REST), 0) INTO REZERVARI
   FROM
     REZERVATS R,
     NIRSTOC NS,
     NIR N
   WHERE
     R.CODNIRSTOC = NS.CODNIRSTOC
     AND N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = aCODOBIECT
     AND N.GEST       = aCODGEST
     AND NS.CODIOART  = aCODIOART
     AND Coalesce(NS.PRET, 0)      = aPRET
    ;
     EXCEPTION WHEN OTHERS THEN REZERVARI := 0;
  END;

  BEGIN
      SELECT Coalesce(SUM(CANT), 0) INTO STOCBLOCAT FROM STOCLOCKEMUL
      WHERE
        CODOBIECT     = aCODOBIECT
        AND CODGEST   = aCODGEST
        AND CODIOART  = aCODIOART
        AND PRET      = aPRET;
     EXCEPTION WHEN OTHERS THEN STOCBLOCAT := 0;
  END;


  BEGIN
      SELECT Coalesce(SUM(CANT), 0) INTO STOCEMULARE1
      FROM
       EMULARE1 E1,
       EMULARE E
      WHERE
        Coalesce(E.PRELUAT, 0) = 0
        AND Coalesce(E.FACTURARE, 0) = 0
        AND NOT EXISTS(SELECT CODEMULARE FROM EMULEDITAT WHERE CODEMULARE = E.CODEMULARE)
        AND E1.CODEMULARE = E.CODEMULARE
        AND CODOBIECT     = aCODOBIECT
        AND CODGEST       = aCODGEST
        AND CODIOART      = aCODIOART
        AND PRETNIRSTOC   = aPRET;
     EXCEPTION WHEN OTHERS THEN STOCEMULARE1 := 0;
  END;

  RETURN STOC - STOCBLOCAT - STOCEMULARE1 - REZERVARI;
*/
END;

FUNCTION GET_STOC_REAL_EMUL_CUMULAT(aCODOBIECT IN NUMBER,
                            aCODGEST IN NUMBER,
                            aCODIOART IN NUMBER
                            ) RETURN NUMBER
IS
 STOC         NUMBER(20, 7) := 0;
 STOCBLOCAT   NUMBER(20, 7) := 0;
 STOCEMULARE1 NUMBER(20, 7) := 0;
 FILTRUCODIOART VARCHAR2(100);
BEGIN
   IF aCODIOART &lt;&gt; 0 THEN
     FILTRUCODIOART := &apos; AND CODIOART = &apos; || aCODIOART;
   ELSE
     FILTRUCODIOART := &apos;&apos;;
   END IF;

   EXECUTE IMMEDIATE
   &apos;SELECT SUM(STOC)  FROM
   (
   SELECT Coalesce(SUM(REST), 0) AS STOC
   FROM
     NIRSTOC NS, NIR N
   WHERE
     N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = &apos; || aCODOBIECT || &apos;
     AND N.GEST       = &apos; || aCODGEST ||
     FILTRUCODIOART  || &apos;

   UNION ALL

   SELECT -Coalesce(SUM(CANT), 0) AS STOC FROM STOCLOCKEMUL
   WHERE
     CODOBIECT     = &apos; || aCODOBIECT || &apos;
     AND CODGEST   = &apos; || aCODGEST ||
     FiltruCodIoArt || &apos;

   UNION ALL

   SELECT -Coalesce(SUM(CANT), 0) AS STOC
   FROM
       EMULARE1 E1,
       EMULARE E
   WHERE
        Coalesce(E.PRELUAT, 0) = 0
        AND Coalesce(E.FACTURARE, 0) = 0
        AND NOT EXISTS(SELECT CODEMULARE FROM EMULEDITAT WHERE CODEMULARE = E.CODEMULARE)
        AND E1.CODEMULARE = E.CODEMULARE
        AND CODOBIECT     = &apos; || aCODOBIECT || &apos;
        AND CODGEST       = &apos; || aCODGEST ||
        FiltruCodIoArt  || &apos;
)&apos; INTO STOC;
  RETURN NVL(STOC, 0);
END;




/*
FUNCTION GET_STOC_REAL_EMUL_CUMULAT(aCODOBIECT IN NUMBER,
                            aCODGEST IN NUMBER,
                            aCODIOART IN NUMBER
                            ) RETURN NUMBER
IS
 STOC         NUMBER(20, 7) := 0;
 STOCBLOCAT   NUMBER(20, 7) := 0;
 STOCEMULARE1 NUMBER(20, 7) := 0;
BEGIN
   SELECT SUM(STOC) INTO STOC FROM
   (
   SELECT Coalesce(SUM(REST), 0) AS STOC
   FROM
     NIRSTOC NS, NIR N
   WHERE
     N.CODNIR = NS.CODNIR
     AND NS.CODOBIECT = aCODOBIECT
     AND N.GEST       = aCODGEST
     AND NS.CODIOART  = aCODIOART

   UNION ALL

   SELECT Coalesce(SUM(CANT), 0) AS STOC FROM STOCLOCKEMUL
   WHERE
     CODOBIECT     = aCODOBIECT
     AND CODGEST   = aCODGEST
     AND CODIOART  = aCODIOART

   UNION ALL

   SELECT Coalesce(SUM(CANT), 0) AS STOC
   FROM
       EMULARE1 E1,
       EMULARE E
   WHERE
        Coalesce(E.PRELUAT, 0) = 0
        AND Coalesce(E.FACTURARE, 0) = 0
        AND NOT EXISTS(SELECT CODEMULARE FROM EMULEDITAT WHERE CODEMULARE = E.CODEMULARE)
        AND E1.CODEMULARE = E.CODEMULARE
        AND CODOBIECT     = aCODOBIECT
        AND CODGEST       = aCODGEST
        AND CODIOART      = aCODIOART
);
  RETURN NVL(STOC, 0);
END;
*/
PROCEDURE LOCK_STOC_EMULEDITAT(aCODEMULARE IN NUMBER)
IS
BEGIN
  INSERT INTO STOCLOCKEMUL (USERID, CODEMULARE1, CODOBIECT, CODGEST, CODIOART, PRET, CANT)
  SELECT X.USERID,  E.CODEMULARE1, E.CODOBIECT, E.CODGEST, E.CODIOART, E.PRETNIRSTOC, E.CANT
  FROM
    EMULARE1 E, TMP_PKG_GLOBALS X
  WHERE
   CODEMULARE = aCODEMULARE AND TIPLINIE =&apos;=&apos;;

  INSERT INTO EMULEDITAT (USERID, CODEMULARE) VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), aCODEMULARE);
END;

PROCEDURE RELEASE_STOC_EMULEDITAT
IS
BEGIN
  DELETE FROM EMULEDITAT WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X));
END;

PROCEDURE LOCK_STOC_CANT_EMUL(aCODEMULARE1 IN NUMBER,
                              aCODOBIECT   IN NUMBER,
                              aCODGEST     IN NUMBER,
                              aCODIOART    IN NUMBER,
                              aPRET        IN NUMBER,
                              aCANT        IN NUMBER)
IS
NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM STOCLOCKEMUL
  WHERE
    USERID          = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
    AND CODEMULARE1 = aCODEMULARE1;

  IF NR = 0 THEN
    INSERT INTO STOCLOCKEMUL (USERID, CODEMULARE1, CODOBIECT, CODGEST, CODIOART, PRET, CANT)
          VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), aCODEMULARE1, aCODOBIECT, aCODGEST, aCODIOART, aPRET, aCANT);
  ELSE
    UPDATE STOCLOCKEMUL
    SET
      CANT      = aCANT,
      CODOBIECT = aCODOBIECT,
      CODGEST   = aCODGEST,
      CODIOART  = aCODIOART,
      PRET      = aPRET
    WHERE
      USERID        = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X))
      AND CODEMULARE1 = aCODEMULARE1;
 END IF;

END;


PROCEDURE UNLOCK_STOC_CANT_EMUL( aCODEMULARE1 IN NUMBER)
IS
BEGIN
   DELETE STOCLOCKEMUL WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODEMULARE1 = aCODEMULARE1;
END;



PROCEDURE RELEASE_ALL_STOCLOCK_EMUL
IS
BEGIN
  DELETE FROM  STOCLOCKEMUL
  WHERE
  USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X) OR USERID IS NULL;
END;


FUNCTION GET_STOC_REAL(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER) RETURN NUMBER
IS
 STOCREAL NUMBER(20, 7) := 0;
BEGIN
  IF aCODNIRSER &lt;&gt; 0 THEN
    BEGIN
      SELECT
      Coalesce(NSE.REST
          - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER = NSE.CODNIRSER), 0)
          , 0)

      INTO STOCREAL
      FROM
        NIRSER NSE
      WHERE
        NSE.CODNIRSER = aCODNIRSER;
      EXCEPTION WHEN OTHERS THEN STOCREAL := 0;
    END;
  ELSE
    BEGIN
      SELECT Coalesce(NS.REST - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NS.CODNIRSTOC) , 0), 0) INTO STOCREAL
      FROM
        NIRSTOC NS
      WHERE
        NS.CODNIRSTOC = aCODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN STOCREAL := 0;
    END;
  END IF;

  RETURN STOCREAL;
END;



FUNCTION GET_STOC_REAL_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, IGNOR_REZERVARI IN NUMBER DEFAULT 0 ) RETURN NUMBER
IS
 STOCREAL NUMBER(20, 7) := 0;
BEGIN
  IF aCODNIRSER &lt;&gt; 0 THEN
    BEGIN
      SELECT
      Coalesce(NSE.REST
          - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER = NSE.CODNIRSER), 0)
          -
          CASE
            WHEN Coalesce(IGNOR_REZERVARI, 0) = 1 THEN 0
            ELSE Coalesce((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSER = NSE.CODNIRSER), 0)
          END, 0
          )

      INTO STOCREAL
      FROM
        NIRSER NSE
      WHERE
        NSE.CODNIRSER = aCODNIRSER;
      EXCEPTION WHEN OTHERS THEN STOCREAL := 0;
    END;
  ELSE
    BEGIN
      SELECT Coalesce(NS.REST
      - Coalesce((SELECT SUM(CANT) FROM STOCLOCK  WHERE CODNIRSTOC = NS.CODNIRSTOC) , 0)
      -
       CASE
         WHEN Coalesce(IGNOR_REZERVARI, 0) = 1 THEN 0
         ELSE Coalesce((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSTOC = NS.CODNIRSTOC) , 0)
       END, 0) INTO STOCREAL
      FROM
        NIRSTOC NS
      WHERE
        NS.CODNIRSTOC = aCODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN STOCREAL := 0;
    END;
  END IF;

  RETURN STOCREAL;
END;


PROCEDURE LOCK_STOC_CANT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER)
IS
NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM STOCLOCK WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;
  IF NR = 0 THEN
    INSERT INTO STOCLOCK (USERID, CODNIRSTOC, CODNIRSER, CANT) VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), aCODNIRSTOC, aCODNIRSER, aCANT);
  ELSE
    UPDATE STOCLOCK
    SET
      CANT = CANT + aCANT
    WHERE
   USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;
 END IF;
END;


PROCEDURE UNLOCK_STOC_CANT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER)
IS
BEGIN
  UPDATE STOCLOCK
  SET
    CANT = CANT - aCANT
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;

  DELETE FROM  STOCLOCK
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CANT = 0;
END;



PROCEDURE RELEASE_ALL_STOCLOCK
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  STOCLOCK
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) OR USERID IS NULL;
  COMMIT;
END;


PROCEDURE RELEASE_ALL_STOCLOCK_GEST
IS
 --PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN
  (
    SELECT
      NS.CODNIRSTOC, SL.USERID
    from
      stoclock sl,
      nirstoc ns,
      nir n,
      TMP_PRELAUTOMAT_CODGEST G
    where
      sl.userid = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) OR SL.USERID IS NULL
      and sl.codnirstoc = ns.codnirstoc
      and n.codnir = ns.codnir
      and n.gest = G.CODGEST
   )
   LOOP
     DELETE FROM STOCLOCK WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
   END LOOP;

  --COMMIT;
END;

procedure ResetJobOk is
nr number;
begin
  update VERSION set JobOk = 1;
  Select Count(*) into Nr from MACHETE where CodMacheta = 106;
  if Nr = 0 then
     Delete from MACHETE;
     Insert into MACHETE select * from TMP_MACHETE;
  end if;
  commit;
end;

FUNCTION GETFIRMAVERSION(aJobOk out number) RETURN NUMBER
IS
VER NUMBER(20, 5) := 0.0;
NR number;
MAxMak number;
BEGIN
  BEGIN
    SELECT VERSION, Coalesce(JobOk,0) INTO VER, aJobOk FROM VERSION;
    Select Max(CodMacheta) into MaxMak from TMP_MACHETE;
    Select Count(*) into Nr from MACHETE where CodMacheta = MAxMak;
    if Nvl(Nr,0) = 0 then
      Delete from MACHETE;
      Insert into MACHETE select * from TMP_MACHETE;
      Commit;
    end if;
    EXCEPTION WHEN OTHERS THEN VER := 0; aJobOk := 0;
  END;
  RETURN VER;
END;

PROCEDURE SETFIRMAVERSION(VER IN NUMBER)
IS
NR NUMBER(5) := 0;
BEGIN
  BEGIN
    SELECT COUNT(*) INTO NR FROM VERSION;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR = 0 THEN
    INSERT INTO VERSION (VERSION) VALUES(VER);
  ELSE
    UPDATE VERSION SET VERSION = VER;
  END IF;
END;




PROCEDURE SETUSERNAME(aUSERNAME IN VARCHAR2)
IS
 NR NUMBER;
BEGIN
  USERNAME := aUSERNAME;



  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (USERNAME) VALUES (aUSERNAME);
  ELSE
    update TMP_PKG_GLOBALS  set USERNAME = aUSERNAME;
  END IF;

/*
  update TMP_PKG_GLOBALS  set USERNAME = aUSERNAME;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (USERNAME) VALUES (aUSERNAME);
  end if;
*/
  WINMADMIN.PKG_MESAJE.SETUSERNAME(aUSERNAME);
END;

PROCEDURE SETFIRMANAME(aFIRMANAME IN VARCHAR2)
IS
NR NUMBER;
BEGIN
  FIRMANAME := aFIRMANAME;

  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
     insert into TMP_PKG_GLOBALS (FIRMANAME) VALUES (aFIRMANAME);
  ELSE
    update TMP_PKG_GLOBALS  set FirmaName = aFIRMANAME;
  END IF;


/*
  update TMP_PKG_GLOBALS  set FirmaName = aFIRMANAME;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (FIRMANAME) VALUES (aFIRMANAME);
  end if;
*/

END;

PROCEDURE SETFIRMA_LONG_NAME(aFIRMA_LONG_NAME IN VARCHAR2)
IS
BEGIN
  FIRMA_LONG_NAME := aFIRMA_LONG_NAME;
END;


FUNCTION GETFIRMA_ID RETURN VARCHAR2
IS
BEGIN
  RETURN  FIRMA_ID ;
END;

PROCEDURE SETFIRMA_ID(aFIRMA_ID IN VARCHAR2)
IS
NR NUMBER;
BEGIN
  FIRMA_ID := aFIRMA_ID;


  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
     insert into TMP_PKG_GLOBALS (FIRMANAME) VALUES (aFIRMA_ID);
  ELSE
    update TMP_PKG_GLOBALS  set FIRMAID = aFIRMA_ID;
  END IF;


/*
  update TMP_PKG_GLOBALS  set FIRMAID = aFIRMA_ID;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (FIRMAID) VALUES (aFIRMA_ID);
  end if;
*/
END;


/*
PROCEDURE CREATE_TEMPORARY_TABLE(SURSA_TABLE_NAME IN VARCHAR2, DEST_TABLE_NAME IN VARCHAR2)
IS
NUMEFIRMA VARCHAR2(20) := &apos;WMGABI&apos;;
ANTET     VARCHAR2(100);
FOOTER    VARCHAR2(100) := &apos;ON COMMIT PRESERVE ROWS&apos;;
STRUCT    VARCHAR2(1000);
NR_COL    NUMBER(10) := 0;
I         NUMBER(10) := 0;
BEGIN
  ANTET := &apos;CREATE GLOBAL TEMPORARY TABLE &quot;&apos; || DEST_TABLE_NAME || &apos;&quot;&apos; || chr(13);

  STRUCT := &apos;( &apos;;

  SELECT COUNT(*) INTO NR_COL FROM ALL_TAB_COLUMNS WHERE OWNER = NUMEFIRMA AND TABLE_NAME = SURSA_TABLE_NAME;
  I := 0;
  FOR V_REC IN (SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE FROM ALL_TAB_COLUMNS
  WHERE
  OWNER = NUMEFIRMA AND TABLE_NAME = SURSA_TABLE_NAME)
  LOOP
    I := I + 1;
    STRUCT := STRUCT || &apos;&quot;&apos; || V_REC.COLUMN_NAME || &apos;&quot; &apos; || V_REC.DATA_TYPE ||
    CASE
      WHEN V_REC.DATA_TYPE = &apos;NUMBER&apos;   THEN &apos;(&apos; || V_REC.DATA_PRECISION || &apos;,&apos; || V_REC.DATA_SCALE || &apos;)&apos;
      WHEN V_REC.DATA_TYPE = &apos;VARCHAR2&apos; THEN &apos;(&apos; || V_REC.DATA_LENGTH || &apos;)&apos;
      ELSE &apos;&apos;
    END;

    IF I &lt; NR_COL THEN STRUCT := STRUCT || &apos;,&apos; || CHR(13);
    END IF;

  END LOOP;

 STRUCT := STRUCT || &apos;)&apos; || CHR(13);


  EXECUTE IMMEDIATE (ANTET || STRUCT || FOOTER);
--  INSERT INTO T (TEXT) VALUES (ANTET || STRUCT || FOOTER);

END;
*/

FUNCTION GET_SEMNIFICATIE_OBLIG(aTIPDOC IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aTIPDOC &lt; 19 THEN RETURN 100;
  ELSE RETURN 200;
  END IF;
END;

FUNCTION GET_REST_PLATA_DOC(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN NUMBER
IS
 RESTPLATA   NUMBER(20, 7) := 0;
 INSERTAR    NUMBER(20, 7) := 0;
 SEMNIFOBLIG NUMBER(10);
BEGIN
  SEMNIFOBLIG := GET_SEMNIFICATIE_OBLIG(aTIPDOC);
  BEGIN
    SELECT SUM(REST - Coalesce(DINCARETVA, 0) +  Coalesce(RESTTVA, 0)) INTO RESTPLATA FROM OBLIGPIF WHERE CODGENERAL IN
    (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = aCODDOC AND TIPDOC = aTIPDOC AND SEMNIFICATIE = SEMNIFOBLIG);
    EXCEPTION WHEN OTHERS THEN RESTPLATA := 0;
  END;

  BEGIN
    SELECT Coalesce(SUM(S1.VALOARE), 0) INTO INSERTAR
    FROM
      OBLIGPIF O,
      NSERTAR1 S1,
      NSERTAR S
    WHERE
    O.CODGENERAL IN
    (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = aCODDOC AND TIPDOC = aTIPDOC AND SEMNIFICATIE = SEMNIFOBLIG)
    AND S1.CODOBLIGPIF = O.CODOBLIGPIF
    AND S.CODSERTAR = S1.CODSERTAR
    AND Coalesce(S.DEPUS, 0) = 0;
    EXCEPTION WHEN OTHERS THEN INSERTAR := 0;
  END;



  RETURN RESTPLATA - INSERTAR;
END;

FUNCTION GETMASTER_OR_USERID return Number IS
ID number;
BEGIN
  ID := Coalesce(MASTERID,0);
  if ID = 0 then ID := UserID; end if;
  MASTERID := null;
  RETURN ID;
END;

procedure SETMASTERID(aUserID IN NUMBER)
is
begin
  begin
    Select LOGONNAME into MASTERID from NPers where CodPers = aUserID;
  exception when others then MASTERID := 0;
  end;
end;


procedure SetConnectionIndex(aConnIndex IN NUMBER)
is
begin
  ConnectionIndex := aConnIndex;
end;

FUNCTION GETConnectionIndex return Number IS
BEGIN
  RETURN ConnectionIndex;
END;


FUNCTION GETUSERID return Number IS
BEGIN
  RETURN USERID;
END;
procedure SETUSERID(aUserID IN NUMBER)
is
NR NUMBER;
begin
  USERID := aUserID;


  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS; --WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (UserID) VALUES (aUserID);
  ELSE
    update TMP_PKG_GLOBALS  set UserID = aUserID;
  END IF;


/*
  update TMP_PKG_GLOBALS  set UserID = aUserID;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (UserID) VALUES (aUserID);
  end if;
*/
  DELETE FROM LUNA_RECORDS_FLAGS F
  WHERE Coalesce(F.USERID, 0) = Coalesce((Select /*+ cardinality(X,1) */ USERID FROM TMP_PKG_GLOBALS X), 0);  -- Stef 05.12.2016 - am pus Max deoarece apare la joburi ORA-01427
end;


function  GETSUBUNITATE return Number
is
begin
  RETURN SUBUNITATE;
end;


procedure SETSUBUNITATE(aSUBUNITATE IN NUMBER)
is
  NR NUMBER;
begin
  SUBUNITATE := aSUBUNITATE;


  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (SUBUNITATE) VALUES (aSUBUNITATE);
  ELSE
    update TMP_PKG_GLOBALS  set Subunitate = aSUBUNITATE;
  END IF;


/*
  update TMP_PKG_GLOBALS  set Subunitate = aSUBUNITATE;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (SUBUNITATE) VALUES (aSUBUNITATE);
  end if;
*/
end;


FUNCTION GETANINITIAL RETURN NUMBER
IS
BEGIN
  RETURN AnInitial;
END;


FUNCTION GETLUNAINITIALA RETURN NUMBER
IS
BEGIN
  RETURN LunaInitiala;
END;





function  GETANLUCRU return Number
is
begin
  RETURN ANLUCRU;
end;

function  GETLUNALUCRU return Number
is
begin
  RETURN LUNALUCRU;
end;

procedure getAnLunaBlocata(an out number,luna out number) is
BEGIN
  SELECT Coalesce(anblocat,0),Coalesce(lunablocata,0) into an, luna from firmaluni;
END;

PROCEDURE DropExpressionIndex is
BEGIN
  Execute immediate &apos;DROP INDEX IDX_CONST1_SIMBOL&apos;;
  Execute immediate &apos;DROP INDEX IDX_CONSTLUNA_ANLUNA&apos;;
  Execute immediate &apos;DROP INDEX IDX_CONSTVAL_VALOARE&apos;;
  Execute immediate &apos;DROP INDEX IDX_NART1_ANLUNA&apos;;
  Execute immediate &apos;DROP INDEX IDX_NARTOBJ1_ANLUNA&apos;;
  Execute immediate &apos;DROP INDEX IDX_NTAXE1_ANLUNA&apos;;
  Execute immediate &apos;DROP INDEX IDX_NTVA1_ANLUNA&apos;;
  Execute immediate &apos;DROP INDEX IDX_IOART1_ANLUNA&apos;;
END;

PROCEDURE SetLunaLucru_SIMPLA(An in Number, Luna in Number) IS
 NR     NUMBER;
 vAn    NUMBER := An ;
 vLuna  NUMBER := Luna;
 vAL    NUMBER := vAn * 12 + vLuna;
 vAlMin NUMBER;
 vAlMax NUMBER;
BEGIN
  -- stef mecanism de verificare sa nu pot seta in afara intervalui de luni al firmei
  SELECT ANINITIAL*12+LUNAINITIALA, ANMAXIM*12+LUNAMAXIMA INTO vAlMin , vAlMax FROM FIRMALUNI;
  IF vAL &lt; vAlMin THEN SELECT ANINITIAL, LUNAINITIALA INTO vAn, vLuna FROM FIRMALUNI; END IF;
  IF vAL &gt; vAlMax THEN SELECT ANMAXIM,   LUNAMAXIMA   INTO vAn, vLuna FROM FIRMALUNI; END IF;

  ANLUCRU   := vAn;
  LunaLUCRU := vLuna;

  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0
  THEN INSERT INTO TMP_PKG_GLOBALS (AnLucru,LunaLucru) VALUES (vAn,vLuna);
  ELSE UPDATE TMP_PKG_GLOBALS  SET AnLucru = vAn, LunaLucru = vLuna;
  END IF;
END;

PROCEDURE SETUSERDOC
IS
N number;
BEGIN
  FOR V_REC IN (
    SELECT CV.VALOARE
    FROM CONST1 C1
      CROSS JOIN TMP_PKG_GLOBALS TG
      INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
      INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1 AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN CL.ALStart AND CL.ALStop
      LEFT JOIN CONSTVAL CV ON cv.codconstluna = cl.codconstluna
    WHERE UPPER(C1.simbol) = &apos;DOCGRUPUSERCURENT&apos; AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;G&apos; THEN 0 WHEN CT.TIPCATEG = &apos;U&apos; THEN TG.USERID END
  ) LOOP
    for X_Rec in (Select U.Codutilizator from WinMADMIN.Utilizator U where U.Codgruputilizator = Coalesce(V_REC.VALOARE, &apos;0&apos;))
    loop
      SELECT Count(CODUTILIZATOR) INTO N FROM TMP_USERDOC WHERE CODUTILIZATOR = X_REC.Codutilizator;
      if N = 0 then
        INSERT INTO TMP_USERDOC (CODUTILIZATOR) VALUES (X_REC.Codutilizator);
      end if;
    end loop;
  END LOOP   ;
  FOR V_REC IN (
    SELECT CV.VALOARE
    FROM CONST1 C1
      CROSS JOIN TMP_PKG_GLOBALS TG
      INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
      INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1 AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN CL.ALStart AND CL.ALStop
      LEFT JOIN CONSTVAL CV ON cv.codconstluna = cl.codconstluna
    WHERE UPPER(C1.simbol) = &apos;DOCUSERS&apos; AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;G&apos; THEN 0 WHEN CT.TIPCATEG = &apos;U&apos; THEN TG.USERID END
  ) LOOP
    SELECT Count(CODUTILIZATOR) INTO N FROM TMP_USERDOC WHERE CODUTILIZATOR = Coalesce(V_REC.VALOARE, &apos;0&apos;);
    if N = 0 then
      INSERT INTO TMP_USERDOC (CODUTILIZATOR) VALUES (Coalesce(V_REC.VALOARE, &apos;0&apos;));
    end if;
  END LOOP   ;
  if N &gt; 0 then
    SELECT Count(CODUTILIZATOR) INTO N FROM TMP_USERDOC WHERE CODUTILIZATOR = USERID;
    if N = 0 then
      INSERT INTO TMP_USERDOC (CODUTILIZATOR) VALUES (USERID);
    end if;
  end if;
END;

PROCEDURE RESET_TMP_CONTCHELTAVANS
IS --PRAGMA AUTONOMOUS_TRANSACTION;
  ExpressionIndex_Err NUMBER := 0;
BEGIN
  DELETE FROM TMP_CONTCHELTAVANS;
  BEGIN
    INSERT INTO TMP_CONTCHELTAVANS
    SELECT CV.VALOARE
    FROM (
      SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
      FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = &apos;CCONTCHELTAVANS&apos;
        AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
    ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
    WHERE c.ALIdx = 1;
  EXCEPTION
    WHEN OTHERS THEN ExpressionIndex_Err := 1;
  END;

  IF ExpressionIndex_Err = 1 THEN
    DropExpressionIndex;

    INSERT INTO TMP_CONTCHELTAVANS
    SELECT CV.VALOARE
    FROM (
      SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
      FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = &apos;CCONTCHELTAVANS&apos;
        AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
    ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
    WHERE c.ALIdx = 1;
  END IF;

  --COMMIT;
END;

PROCEDURE RESET_TMP_CONTVENITAVANS
IS --PRAGMA AUTONOMOUS_TRANSACTION;
  ExpressionIndex_Err NUMBER := 0;
BEGIN
  DELETE FROM TMP_CONTVENITAVANS;
  BEGIN
    INSERT INTO TMP_CONTVENITAVANS
    SELECT CV.VALOARE
    FROM (
      SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
      FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = &apos;CCONTVENITAVANS&apos;
        AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
    ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
    WHERE c.ALIdx = 1;
  EXCEPTION
    WHEN OTHERS THEN ExpressionIndex_Err := 1;
  END;

  IF ExpressionIndex_Err = 1 THEN
    DropExpressionIndex;

    INSERT INTO TMP_CONTVENITAVANS
    SELECT CV.VALOARE
    FROM (
      SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
      FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      WHERE UPPER(C1.simbol) = &apos;CCONTVENITAVANS&apos;
        AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
    ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
    WHERE c.ALIdx = 1;
  END IF;

  --COMMIT;
END;

PROCEDURE RESET_TMP_CONTMIFIX IS
BEGIN
  DELETE FROM TMP_CONTMIFIX;
  INSERT INTO TMP_CONTMIFIX
  SELECT DISTINCT N2.CODCONT
  FROM NCONT N1, NCONT N2
  WHERE INSTRB(N2.SIMBOL, N1.SIMBOL, 1, 1) =  1
    AND TO_CHAR(N1.CODCONT) IN (
      SELECT CV.VALOARE
      FROM (
        SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
        FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        WHERE UPPER(C1.simbol) = &apos;CMIFIX&apos;
          AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
      ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
      WHERE c.ALIdx = 1
    );
END;

PROCEDURE RESET_TMP_CONTOBINV IS
BEGIN
  DELETE FROM TMP_CONTOBINV;
  INSERT INTO TMP_CONTOBINV
  SELECT DISTINCT N2.CODCONT
  FROM NCONT N1, NCONT N2
  WHERE INSTRB(N2.SIMBOL, N1.SIMBOL, 1, 1) =  1
    AND TO_CHAR(N1.CODCONT) IN (
      SELECT CV.VALOARE
      FROM (
        SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
        FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        WHERE UPPER(C1.simbol) = &apos;COBINVENTAR&apos;
          AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
      ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
      WHERE c.ALIdx = 1
    );
END;

PROCEDURE RESET_TMP_CONTCUSTODIE IS
BEGIN
  DELETE FROM TMP_CONTCUSTODIE;
  INSERT INTO TMP_CONTCUSTODIE
  SELECT DISTINCT N2.CODCONT
  FROM NCONT N1, NCONT N2
  WHERE INSTRB(N2.SIMBOL, N1.SIMBOL, 1, 1) =  1
    AND TO_CHAR(N1.CODCONT) IN (
      SELECT CV.VALOARE
      FROM (
        SELECT codconstluna, ROW_NUMBER() OVER (ORDER BY ANSTART DESC, LUNASTART DESC) ALIdx
        FROM CONST1 C1 LEFT JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        WHERE UPPER(C1.simbol) = &apos;CCUSTODIE&apos;
          AND CL.ANSTART*12+CL.LUNASTART &lt;= (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS X)
      ) c LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
      WHERE c.ALIdx = 1
    );
END;

PROCEDURE SetLunaLucru(An in Number, Luna in Number, EsteMaster in number default 0)
IS PRAGMA AUTONOMOUS_TRANSACTION;
  NR     NUMBER;
  vAn    NUMBER := An ;
  vLuna  NUMBER := Luna;
  vAL    NUMBER := vAn * 12 + vLuna;
  vAlMin NUMBER;
  vAlMax NUMBER;
BEGIN
  -- stef mecanism de verificare sa nu pot seta in afara intervalui de luni al firmei
  SELECT ANINITIAL*12+LUNAINITIALA, ANMAXIM*12+LUNAMAXIMA INTO vAlMin , vAlMax FROM FIRMALUNI;
  IF vAL &lt; vAlMin THEN SELECT ANINITIAL, LUNAINITIALA INTO vAn, vLuna FROM FIRMALUNI; END IF;
  IF vAL &gt; vAlMax THEN SELECT ANMAXIM,   LUNAMAXIMA   INTO vAn, vLuna FROM FIRMALUNI; END IF;

  ANLUCRU   := vAn;
  LunaLUCRU := vLuna;

  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;

  IF NR = 0
  THEN INSERT INTO TMP_PKG_GLOBALS (AnLucru,LunaLucru) VALUES (vAn,vLuna);
  ELSE UPDATE TMP_PKG_GLOBALS  SET AnLucru = vAn, LunaLucru = vLuna;
  END IF;

  DELETE FROM LUNA_RECORDS_FLAGS F WHERE Coalesce(F.USERID, 0) = Coalesce((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X), 0);

  DEFAZAJ_AVIZ_IN  := -1;
  DEFAZAJ_AVIZ_Out := -1;

  RESET_TMP_CONTCHELTAVANS;
  RESET_TMP_CONTVENITAVANS;

  SETLIMBADENART;
  SETUSERDOC;

  RESET_TMP_CONTMIFIX;
  RESET_TMP_CONTOBINV;
  RESET_TMP_CONTCUSTODIE;

  COMMIT;
  -- functia de mai joc contine commit !!!
  WINMADMIN.PKG_USERFIRME.setlunalucru(PKG_GLOBALS.UserID, vAn, vLuna, EsteMaster);
END;

PROCEDURE SetLunaLucruAplOnline(An in Number, Luna in Number, EsteMaster in number default 0)
IS PRAGMA AUTONOMOUS_TRANSACTION;
  NR NUMBER;
BEGIN
  ANLUCRU   := An;
  LunaLUCRU := Luna;

  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;

  IF NR = 0
  THEN INSERT INTO TMP_PKG_GLOBALS (AnLucru,LunaLucru) VALUES (An,Luna);
  ELSE UPDATE TMP_PKG_GLOBALS  SET AnLucru = An, LunaLucru = Luna;
  END IF;

  DELETE FROM LUNA_RECORDS_FLAGS F WHERE Coalesce(F.USERID, 0) = Coalesce((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X), 0);

  DEFAZAJ_AVIZ_IN  := -1;
  DEFAZAJ_AVIZ_Out := -1;

  RESET_TMP_CONTCHELTAVANS;

  COMMIT;

  -- functia de mai joc contine commit !!!
  WINMADMIN.PKG_USERFIRME.setlunalucru(pkg_globals.USERID, an, luna, EsteMaster);
END;

FUNCTION AnLunaLucru return Number IS
BEGIN
  Return AnLucru * 12 + LunaLucru;
END;

PROCEDURE SetLunaTemp(An in Number, Luna in Number) IS
BEGIN
  ANTEMP   := An;
  LunaTEMP := Luna;
END;

FUNCTION  GETANTEMP return NUMBER is
BEGIN
  RETURN ANTEMP;
END;

FUNCTION  GETLUNATEMP return Number
is
begin
  RETURN LUNATEMP;
end;

procedure SetLunaPRECEDENTA(An in Number, Luna in Number)
  is
NR NUMBER;
begin
  ANPRECEDENT   := An;
  LunaPRECEDENTA := Luna;


  SELECT COUNT(*) INTO NR FROM TMP_PKG_GLOBALS WHERE ROWNUM = 1;
  IF NR = 0 THEN
    insert into TMP_PKG_GLOBALS (AnPrec,LunaPrec) VALUES (An,Luna);
  ELSE
    update TMP_PKG_GLOBALS  set AnPrec = An, LunaPrec = Luna;
  END IF;

/*
  update TMP_PKG_GLOBALS  set AnPrec = An, LunaPrec = Luna;
  if sql%rowcount = 0 then
    insert into TMP_PKG_GLOBALS (AnPrec,LunaPrec) VALUES (An,Luna);
  end if;
*/
end;


function  GETANPRECEDENT return Number
is
begin
  RETURN ANPRECEDENT;
end;

function  GETLUNAPRECEDENTA return Number
is
begin
  RETURN LUNAPRECEDENTA;
end;

function  GET_ZECIMALE_AMORTIZARE return Number
is
begin
  if ZECIMALE_AMORTIZARE = -1 then
    BEGIN
       SELECT Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ZecimaleAmo&apos;, (Select /*+ cardinality(X,1) */ ANLUCRU from TMP_PKG_GLOBALS), (Select /*+ cardinality(X,1) */ LunaLUCRU from TMP_PKG_GLOBALS)), &apos;0&apos;) INTO ZECIMALE_AMORTIZARE FROM DUAL;
       EXCEPTION WHEN OTHERS THEN ZECIMALE_AMORTIZARE := 2;
    END;
  end if;
  RETURN ZECIMALE_AMORTIZARE;
end;

function  GET_DEFAZAJ_AVIZ_IN return Number
is
begin
  if DEFAZAJ_AVIZ_IN = -1 then
    BEGIN
       SELECT Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;DefazajAvizIn&apos;, (Select /*+ cardinality(X,1) */ ANLUCRU from TMP_PKG_GLOBALS), (Select /*+ cardinality(X,1) */ LunaLUCRU from TMP_PKG_GLOBALS)), &apos;0&apos;) INTO DEFAZAJ_AVIZ_IN FROM DUAL;
       EXCEPTION WHEN OTHERS THEN DEFAZAJ_AVIZ_IN := 0;
    END;
  end if;
  RETURN DEFAZAJ_AVIZ_IN;
end;

function  GET_DEFAZAJ_AVIZ_OUT return Number
is
begin
  if DEFAZAJ_AVIZ_OUT = -1 then
    BEGIN
       SELECT Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;DefazajAvizOut&apos;, (Select /*+ cardinality(X,1) */ ANLUCRU from TMP_PKG_GLOBALS), (Select /*+ cardinality(X,1) */ LunaLUCRU from TMP_PKG_GLOBALS)),&apos;0&apos;) INTO DEFAZAJ_AVIZ_OUT FROM DUAL;
       EXCEPTION WHEN OTHERS THEN DEFAZAJ_AVIZ_OUT := 0;
    END;
  end if;
  RETURN DEFAZAJ_AVIZ_OUT;
end;

procedure SetSeparator(aSep in VarChar2)
is begin
  SEP := aSep;
end;

procedure SetTipIntrare(aTip in Number)
is begin
  TipIntrare := aTip;
end;

procedure SetTipIesire(aTip in Number)
is begin
  TipIesire := aTip;
end;

procedure SetTipComanda(aTip in Number)
is begin
  TipComanda := aTip;
end;

procedure SetTipOferta(aTip in Number)
is begin
  TipOferta := aTip;
end;

procedure SetTipPromotie(aTip in Number)
is begin
  TipPromotie := aTip;
end;

procedure SetTipContract(aTip in Number)
is begin
  TipContract := aTip;
end;

procedure SetTipMiscareInterna(aTip in Number)
is begin
  TipMiscareInterna := aTip;
end;

procedure SetTipDocCasaBanca(aTip in Number, aCod in number default 0)
is begin
  TipDocCasaBanca := aTip;
  CodDocCasaBanca := aCod;
end;

function GetCodDocCasaBanca return Number
is begin
  Return Coalesce(CodDocCasaBanca, 0);
end;

function GetTipIntrare return Number
is begin
  Return Coalesce(TipIntrare, 0);
end;

function GetTipDocCasaBanca return Number
is begin
  Return Coalesce(TipDocCasaBanca, 0);
end;

function GetTipComanda return Number
is begin
  Return Coalesce(TipComanda, 0);
end;

function GetTipOferta return Number
is begin
  Return Coalesce(TipOferta, 0);
end;

function GetTipPromotie return Number
is begin
  Return Coalesce(TipPromotie, 0);
end;

function GetTipContract return Number
is begin
  Return Coalesce(TipContract, 0);
end;

function GetTipIesire return Number
is begin
  Return Coalesce(TipIesire, 0);
end;

function GetTipMiscareInterna return Number
is begin
  Return Coalesce(TipMiscareInterna, 0);
end;

PROCEDURE CLEARTABLE(TableName varchar2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  EXECUTE IMMEDIATE &apos;BEGIN DELETE &apos; || TABLENAME ||&apos;; END;&apos;;
  COMMIT;
END;

PROCEDURE CLEAR_TABLE_AND_COMMIT(TableName varchar2)
IS
BEGIN
   EXECUTE IMMEDIATE &apos;begin delete &apos; || TableName ||&apos;; end;&apos;;
  COMMIT;
END;



 procedure CALCULEAZA_LUNA_PRECEDENTA(An IN Number, Luna IN Number, NewAn OUT NUMBER, NewLUNA OUT NUMBER)
 IS
 BEGIN
   IF LUNA = 1 THEN
     NEWAN   := AN -1;
     NEWLUNA := 12;
   ELSE
     NEWAN   := AN ;
     NEWLUNA := LUNA - 1;
   END IF;
 END;


 procedure CALCULEAZA_LUNA_URMATOARE(An IN Number, Luna IN Number, NewAn OUT NUMBER, NewLUNA OUT NUMBER)
 IS
 BEGIN
   IF LUNA = 12 THEN
     NEWAN   := AN + 1;
     NEWLUNA := 1;
   ELSE
     NEWAN   := AN ;
     NEWLUNA := LUNA + 1;
   END IF;
 END;


FUNCTION GET_CONT_CONTABIL_OBLIG(SEMNIF IN NUMBER,COL_IDX IN NUMBER, CODIO IN NUMBER ) RETURN NUMBER IS
  DEN_COL     VARCHAR2(50) := &apos;&apos;;
  NUMETABLA   VARCHAR2(50) := &apos;&apos;;
  DEN_COL_COD VARCHAR2(50) := &apos;&apos;;
  aCODCONT    NUMBER  (20) :=  0;
BEGIN
  IF SEMNIF in (1100, 1101) THEN
    NUMETABLA   := &apos;IOPERS1&apos;;
    DEN_COL_COD := &apos;CODIOPERS1&apos;;
  ELSIF SEMNIF = 1000 THEN
    NUMETABLA   := &apos;IOBANK1&apos;;
    DEN_COL_COD := &apos;CODIOBANK1&apos;;
  ELSE
    NUMETABLA   := &apos;IOPART1&apos;;
    DEN_COL_COD := &apos;CODIOPART1&apos;;
  END IF;

  BEGIN
    SELECT  Coalesce(T.COLUMN_NAME, &apos;&apos;)
    INTO DEN_COL
    FROM USER_TAB_COLUMNS T
    WHERE T.COLUMN_ID = COL_IDX + 1 and TABLE_NAME = NUMETABLA;
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

  BEGIN
    EXECUTE IMMEDIATE &apos;SELECT &apos;|| DEN_COL || &apos; FROM &apos; || NUMETABLA  || &apos; i1 WHERE &apos; || DEN_COL_COD || &apos; = &apos; || CODIO INTO aCODCONT;
  EXCEPTION
    WHEN OTHERS THEN RETURN 0;
  END;

  RETURN aCODCONT;
END;

PROCEDURE CKECK_CONST_DATELUNA(aCODCONST1 IN NUMBER, aUSERID IN NUMBER, NRACT IN OUT NUMBER) IS
  NR                NUMBER := 0;
  NewCodConstLuna   NUMBER(20);
  aCONSTLUNAMARTOR  NUMBER(20)    := 0;
  aVALOAREMARTOR    VARCHAR2(300) := NULL;

  ANINI             NUMBER(20)    := 0;
  LUNAINI           NUMBER(20)    := 0;
BEGIN
  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO ANINI, LUNAINI FROM FIRMALUNI;
  EXCEPTION
    WHEN OTHERS THEN
      ANINI   := 0;
      LUNAINI := 0;
  END;

  IF ANINI &lt;&gt; 0 AND LUNAINI &lt;&gt; 0 THEN
    FOR Martor_Rec_Constluna IN (SELECT * FROM TMP_CONSTLUNA WHERE CODCONST1 = aCODCONST1) LOOP
      SELECT COUNT(*) INTO NR FROM CONSTLUNA
      WHERE CODCONST1 = aCODCONST1 AND USERID = aUSERID;

      IF NR = 0 THEN -- NU AM DESCRIERE LA NIVEL DE LUNA
        NRACT           := NRACT + 1;
        NewCodConstLuna := SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL;

        -- CONSTLUNA
        INSERT INTO CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
        VALUES (
          NewCodConstLuna,
          Martor_Rec_ConstLuna.CODCONST1,
          CASE WHEN Martor_Rec_ConstLuna.ANSTART   = 0 THEN ANINI   ELSE Martor_Rec_ConstLuna.ANSTART   END,
          CASE WHEN Martor_Rec_ConstLuna.LUNASTART = 0 THEN LUNAINI ELSE Martor_Rec_ConstLuna.LUNASTART END,
          aUSERID
        );

        -- CONSTVALPOS
        FOR Martor_REC_CONSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = Martor_Rec_Constluna.CODCONSTLUNA) LOOP
          INSERT INTO CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA) VALUES (SEQ_CONSTVALPOS_COD.NEXTVAL, Martor_REC_CONSTVALPOS.IDX, Martor_REC_CONSTVALPOS.VALPOSIBILE, NewCodConstLuna);
        END LOOP;

        -- CONSTVAL
        FOR Martor_REC_CONSTVAL IN (SELECT * FROM TMP_CONSTVAL WHERE CODCONSTLUNA = Martor_Rec_Constluna.CODCONSTLUNA) LOOP
          INSERT INTO CONSTVAL (VALOARE, CODCONSTLUNA) VALUES (Martor_REC_CONSTVAL.VALOARE, NewCodConstLuna);
        END LOOP;

        IF aCODCONST1 = 4791 THEN -- constanta 3124 a fost rupta in doua (a aparut si 4791) preiau valoarea din cea veche
          BEGIN
            SELECT codconstluna INTO aCONSTLUNAMARTOR
            FROM CONSTLUNA CL
            WHERE codconst1 = 3124 AND ANSTART * 12 + LUNASTART BETWEEN CL.ALStart AND CL.ALStop;
          EXCEPTION
            WHEN OTHERS THEN aCONSTLUNAMARTOR := 0;
          END;
          IF aCONSTLUNAMARTOR &gt; 0 THEN
            BEGIN
              SELECT VALOARE INTO aVALOAREMARTOR FROM CONSTVAL WHERE CODCONSTLUNA = aCONSTLUNAMARTOR;
            EXCEPTION
              WHEN OTHERS THEN aVALOAREMARTOR := NULL;
            END;
            IF aVALOAREMARTOR IS NOT NULL THEN
              UPDATE CONSTVAL SET VALOARE = aVALOAREMARTOR WHERE CODCONSTLUNA = NewCodConstLuna;
            END IF;
          END IF;
        END IF;
      ELSE -- am descrieri la nivel de luna; reintroduc de pe martor valorile din constvalpos
      -- am o descriere care trebuie impusa dintr-o anumita luna; o introduc;
        IF Martor_Rec_Constluna.ANSTART &lt;&gt; 0 AND Martor_Rec_Constluna.LUNASTART &lt;&gt; 0 THEN
          SELECT COUNT(*) INTO NR FROM CONSTLUNA  WHERE CODCONST1 =  aCODCONST1 AND ANSTART * 12 + LUNASTART = Martor_Rec_Constluna.ANSTART * 12 + Martor_Rec_Constluna.LUNASTART;

          IF NR = 0 THEN
            NRACT           := NRACT + 1;
            NewCodConstLuna := SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL;
            INSERT INTO CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID) VALUES (NewCodConstLuna, Martor_Rec_ConstLuna.CODCONST1, Martor_Rec_ConstLuna.ANSTART, Martor_Rec_ConstLuna.LUNASTART, aUSERID );

            -- CONSTVAL
            FOR Martor_REC_CONSTVAL IN (SELECT * FROM TMP_CONSTVAL WHERE CODCONSTLUNA = Martor_Rec_Constluna.CODCONSTLUNA) LOOP
              INSERT INTO CONSTVAL (VALOARE, CODCONSTLUNA) VALUES (Martor_REC_CONSTVAL.VALOARE, NewCodConstLuna);
            END LOOP;

            IF aCODCONST1 = 4791 THEN -- constanta 3121 a fost rupta in doua (a aparut si 4791)
              BEGIN
                SELECT codconstluna INTO aCONSTLUNAMARTOR
                FROM CONSTLUNA CL
                WHERE codconst1 = 3124 AND ANSTART * 12 + LUNASTART BETWEEN CL.ALStart AND CL.ALStop;
              EXCEPTION
                WHEN OTHERS THEN aCONSTLUNAMARTOR := 0;
              END;
              IF aCONSTLUNAMARTOR &gt; 0 THEN
                BEGIN
                  SELECT VALOARE INTO aVALOAREMARTOR FROM CONSTVAL WHERE CODCONSTLUNA = aCONSTLUNAMARTOR;
                EXCEPTION
                  WHEN OTHERS THEN aVALOAREMARTOR := NULL;
                END;
                IF aVALOAREMARTOR IS NOT NULL THEN
                  UPDATE CONSTVAL SET VALOARE = aVALOAREMARTOR WHERE CODCONSTLUNA = NewCodConstLuna;
                END IF;
              END IF;
            END IF;
          END IF;
        END IF;

        FOR REC_CONSTLUNA IN (
          SELECT * FROM CONSTLUNA  WHERE
          CODCONST1 =  aCODCONST1 AND  ANSTART * 12 + LUNASTART &gt;= Martor_Rec_Constluna.ANSTART * 12 + Martor_Rec_Constluna.LUNASTART
          AND userid = AUSERID
        ) LOOP
          -- CONSTVALPOS
          DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA = REC_CONSTLUNA.CODCONSTLUNA;

          FOR Martor_REC_CONSTVALPOS IN (SELECT * FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = Martor_Rec_Constluna.CODCONSTLUNA)
          LOOP
            INSERT INTO CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA)
            VALUES (SEQ_CONSTVALPOS_COD.NEXTVAL, Martor_REC_CONSTVALPOS.IDX, Martor_REC_CONSTVALPOS.VALPOSIBILE, REC_CONSTLUNA.CODCONSTLUNA);
          END LOOP;
        END LOOP;
      END IF;
    END LOOP; -- tmp_constluna
    COMMIT;
  END IF;
END;

-- VERIFICA DACA EXISTA CONSTANTE DE TIP USER CARE NU AU FOST ASIGNATE USER-ului Curent
PROCEDURE CHECK_CONSTANTE_USER IS
  vUserID NUMBER(18);
BEGIN
  SELECT /*+ cardinality(X,1) */ USERID INTO vUserID FROM TMP_PKG_GLOBALS X;
  CONST_USER_CHECK (vUserID);
END;

PROCEDURE GETINFOVALCONST IS
BEGIN
  UPDATE INFOACTUALCONST I
  SET VALOARE = (SELECT Min(pkg_categconst.GetValAfis(C1.TIP, CL.CODCONSTLUNA)) FROM CONSTLUNA CL, CONST1 C1 WHERE CL.CODCONST1 = I.CODCONST1 AND C1.CODCONST1 = I.CODCONST1 AND Coalesce(CL.USERID,0) = 0)
  WHERE I.TIPOPER = &apos;A&apos;;

  COMMIT;
END;

FUNCTION ACTUALCONST RETURN NUMBER IS
  NRACT    NUMBER := 0;
  NR       NUMBER := 0;
  ACT      NUMBER := 0;
  vUserId  NUMBER := PKG_GLOBALS.UserID;
BEGIN
  DELETE FROM INFOACTUALCONST; -- SCRIU AICI CONSTANTELE CARE AU FOST ADAUGATE CA SA LE AFISEZ IN MAKETA;

  -- STERG CONSTANTELE CARE NU MAI SUNT IN MARTOR;
  FOR V_REC IN (
    SELECT CODCONST1, DENUMIRE, SIMBOL, INDEXLOCAL
    FROM CONST1
    WHERE CODCONST1 NOT IN (SELECT CODCONST1 FROM TMP_CONST1) AND CODCATEG &lt;&gt; 245
  ) LOOP
    INSERT INTO INFOACTUALCONST(CODCONST1,DENCONST,SIMBOL,INDEXCONST,TIPOPER) VALUES (V_REC.CODCONST1 ,V_REC.DENUMIRE, V_REC.SIMBOL, V_REC.INDEXLOCAL, &apos;S&apos;);
    DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM CONSTLUNA WHERE CODCONST1 = V_REC.CODCONST1);
    DELETE FROM CONSTVAL    WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM CONSTLUNA WHERE CODCONST1 = V_REC.CODCONST1);
    DELETE FROM CONSTLUNA   WHERE CODCONST1 = V_REC.CODCONST1;
    DELETE FROM CONST1      WHERE CODCONST1 = V_REC.CODCONST1;
  END LOOP;
  DELETE FROM CATEGCONST WHERE CODCATEG NOT IN (SELECT CODCATEG FROM TMP_CATEGCONST);

  FOR V_REC_CC IN (
    SELECT
      TCC.CODCATEG, TCC.DENUMIRE, TCC.INDEXLOCAL, TCC.TIPCATEG,
      CASE
        WHEN CC.CODCATEG IS NULL             THEN 1 -- adauga
        WHEN CC.DENUMIRE   &lt;&gt; TCC.DENUMIRE   THEN 2 -- modifica
        WHEN CC.INDEXLOCAL &lt;&gt; TCC.INDEXLOCAL THEN 2 -- modifica
        WHEN CC.TIPCATEG   &lt;&gt; TCC.TIPCATEG   THEN 2 -- modifica
        ELSE 0
      END MODIF
    FROM TMP_CATEGCONST TCC LEFT JOIN CATEGCONST CC ON CC.CODCATEG = TCC.CODCATEG
  ) LOOP
    IF    V_REC_CC.MODIF = 1 THEN
      NRACT := NRACT + 1;
      INSERT INTO CATEGCONST (CODCATEG, DENUMIRE, INDEXLOCAL, TIPCATEG) VALUES (V_REC_CC.CODCATEG, V_REC_CC.DENUMIRE, V_REC_CC.INDEXLOCAL, V_REC_CC.TIPCATEG);
    ELSIF V_REC_CC.MODIF = 2 THEN
      NRACT := NRACT + 1;
      UPDATE CATEGCONST
      SET DENUMIRE   = V_REC_CC.DENUMIRE,
          INDEXLOCAL = V_REC_CC.INDEXLOCAL,
          TIPCATEG   = V_REC_CC.TIPCATEG
      WHERE CODCATEG = V_REC_CC.CODCATEG;
    END IF;

    FOR V_REC_C1 IN (
      SELECT
        TC1.CODCONST1, TC1.CODCATEG, TC1.INDEXLOCAL, TC1.SIMBOL, TC1.DENUMIRE, TC1.TIP, TC1.DESCRIERE,
        CASE
          WHEN C1.CODCONST1 IS NULL                                                                               THEN 1 -- adauga
          WHEN C1.CODCATEG                  &lt;&gt; TC1.CODCATEG                                                       THEN 2 -- modifica
          WHEN Coalesce(C1.INDEXLOCAL, &apos; &apos;) &lt;&gt; Coalesce(TC1.INDEXLOCAL, &apos; &apos;)                                      THEN 2 -- modifica
          WHEN C1.SIMBOL                    &lt;&gt; TC1.SIMBOL                                                         THEN 2 -- modifica
          WHEN C1.DENUMIRE                  &lt;&gt; TC1.DENUMIRE                                                       THEN 2 -- modifica
          WHEN Coalesce(C1.TIP, 0)          &lt;&gt; Coalesce(TC1.TIP, 0)                                               THEN 2 -- modifica
          WHEN dbms_lob.compare(Coalesce(C1.DESCRIERE, EMPTY_CLOB()), Coalesce(TC1.DESCRIERE, EMPTY_CLOB())) &lt;&gt; 0 THEN 2 -- modifica
          ELSE 0
        END MODIF
      FROM TMP_CONST1 TC1 LEFT JOIN CONST1 C1 ON C1.CODCONST1 = TC1.CODCONST1
      WHERE TC1.CODCATEG = V_REC_CC.CODCATEG
    ) LOOP
      IF    V_REC_C1.MODIF = 1 THEN
        NRACT := NRACT + 1;
        INSERT INTO CONST1 (CODCONST1, CODCATEG, INDEXLOCAL, SIMBOL, DENUMIRE, TIP) VALUES (V_REC_C1.CODCONST1, V_REC_C1.CODCATEG, V_REC_C1.INDEXLOCAL, V_REC_C1.SIMBOL, V_REC_C1.DENUMIRE, V_REC_C1.TIP);
        INSERT INTO INFOACTUALCONST(CODCONST1, DENCONST, SIMBOL, INDEXCONST, TIPCONST, TIPOPER) VALUES(V_REC_C1.CODCONST1, V_REC_C1.DENUMIRE, V_REC_C1.Simbol, V_REC_C1.INDEXLOCAL, V_REC_C1.Tip, &apos;A&apos;);
      ELSIF V_REC_C1.MODIF = 2 THEN
        NRACT := NRACT + 1;
        UPDATE CONST1
        SET CODCATEG   = V_REC_C1.CODCATEG,
            INDEXLOCAL = V_REC_C1.INDEXLOCAL,
            SIMBOL     = V_REC_C1.SIMBOL,
            DENUMIRE   = V_REC_C1.DENUMIRE,
            TIP        = V_REC_C1.TIP,
            DESCRIERE  = V_REC_C1.DESCRIERE
        WHERE CODCONST1 = V_REC_C1.CODCONST1;
      END IF;

      CKECK_CONST_DATELUNA(V_REC_C1.CODCONST1, 0, NRACT); -- constantele utilizator trebuie sa aiba si o inregistrare MARTOR (userID=0)
      IF V_REC_CC.TIPCATEG = &apos;U&apos; AND vUserID IS NOT NULL THEN
        CKECK_CONST_DATELUNA(V_REC_C1.CODCONST1, vUserID, NRACT);
      END IF;
    END LOOP; -- tmp_const1
  END LOOP; -- tmp_categconst

  PRC_AL_CHECK(&apos;CONSTLUNA&apos;);
  COMMIT;

  GETINFOVALCONST;
  PKG_CATEGCONST.STERGE_CONSVAL_DUBLU;

  RETURN NRACT;
END;

PROCEDURE PUT_LINE(LINE IN VARCHAR2) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO INPUTBUFFER VALUES (LINE);
  COMMIT;
END;

PROCEDURE PUT_INFO(pINFOLINE IN VARCHAR2, pDETALII CLOB) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO INFOBUFFER VALUES (CURRENT_TIMESTAMP, pINFOLINE, pDETALII);
  COMMIT;
END;


FUNCTION  GetUnitar(V IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN (100 + V) / 100;
END;

PROCEDURE RECALCUL_DISCMAJ_IES(aCODIES IN NUMBER) IS
  DISCOUNT            NUMBER(20, 7) ;
  DISCOUNTT           NUMBER(20, 7) ;
  DISCOUNTTOT         NUMBER(20, 7) ;
  PROCCUMULATGRUP     NUMBER(20, 7) ;
  PROCCUMULATTOTAL    NUMBER(20, 7) ;
  DISCAPLICAT         NUMBER(20, 7) ;
  DISCTOTAPLICAT      NUMBER(20, 7) ;
  DISCAPLICATLINIE    NUMBER(20, 7) ;
  aCUMULAT            NUMBER(10) := 0;
  NEEDAPLICARE        NUMBER(1) := 0;
  DISCNETAPLICATGRUP  NUMBER(20, 7) ;
  DISCNETAPLICATTOTAL NUMBER(20, 7) ;

  Cursor crs is SELECT * FROM  IESIRI1 WHERE CODIES = aCODIES ORDER BY INDEXLOCAL DESC;
  V_REC crs%rowtype;
BEGIN
  OPEN CRS;
  DISCOUNTT := 1;  DISCTOTAPLICAT := 1; DiscNetAplicatTotal := 1;  ProcCumulatTotal := 0;
  FETCH CRS INTO V_REC ;
  WHILE CRS%FOUND
  LOOP
    EXIT WHEN CRS%NOTFOUND;

    DISCOUNT := 1; DISCAPLICAT := 1; ProcCumulatGrup := 0; DiscNetAplicatGrup := 1;
    WHILE V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CRS%FOUND
    LOOP
      NEEDAPLICARE := 1;

      IF Coalesce(V_REC.CODCRITERIU, 0) &lt;&gt; 0 THEN
        SELECT Coalesce(CUMULAT, 0) INTO aCUMULAT FROM CRITERIIDISC  WHERE CODCRITERIU = V_REC.CODCRITERIU;
        IF aCUMULAT = 0
          THEN NEEDAPLICARE := 0;
        END IF;
      END IF;

      IF NEEDAPLICARE = 1 THEN
        IF V_REC.TIPLINIE = &apos;T&apos; THEN
          PROCCUMULATTOTAL    := PROCCUMULATTOTAL + V_REC.CANT;
          DISCNETAPLICATTOTAL := GETUNITAR(PROCCUMULATTOTAL);
        ELSE
          PROCCUMULATGRUP    := PROCCUMULATGRUP + V_REC.CANT;
          DISCNETAPLICATGRUP := GETUNITAR(PROCCUMULATGRUP);
        END IF;
      ELSE
        IF V_REC.TIPLINIE = &apos;T&apos; THEN DISCTOTAPLICAT := DISCTOTAPLICAT * GETUNITAR(V_REC.CANT);
                                ELSE DISCAPLICAT    := DISCAPLICAT    * GETUNITAR(V_REC.CANT);
        END IF;
      END IF;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;

    WHILE V_REC.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;)AND CRS%FOUND
    LOOP
      DISCOUNTTOT := DISCOUNTT * DISCOUNT * GETUNITAR(Coalesce(V_REC.ADDIM, 0));
      DISCAPLICATLINIE := DISCTOTAPLICAT * DISCAPLICAT * DISCNETAPLICATTOTAL * DISCNETAPLICATGRUP;
      IF Coalesce(V_REC.PROCDISC, 0) &lt;&gt; 0 THEN DISCAPLICATLINIE := DISCAPLICATLINIE + Coalesce(V_REC.PROCDISC, 0) / 100;
      END IF;
      DISCAPLICATLINIE := DISCAPLICATLINIE * GETUNITAR(Coalesce(V_REC.ADDIM, 0));

      UPDATE IESIRI1
      SET
        COEFDISCMAJ = DISCAPLICATLINIE
      WHERE
        CODIES1 = V_REC.CODIES1;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;
  END LOOP;
  CLOSE CRS;
END;

FUNCTION GET_DISC_IES1(aCODIES1 IN NUMBER, aCodIes IN NUMBER, aCodCriteriu IN NUMBER) RETURN NUMBER IS
  DISCOUNT            NUMBER(20, 7) ;
  DISCOUNTT           NUMBER(20, 7) ;
  DISCOUNTTOT         NUMBER(20, 7) ;
  PROCCUMULATGRUP     NUMBER(20, 7) ;
  PROCCUMULATTOTAL    NUMBER(20, 7) ;
  DISCAPLICAT         NUMBER(20, 7) ;
  DISCTOTAPLICAT      NUMBER(20, 7) ;
  DISCAPLICATLINIE    NUMBER(20, 7) ;
  DISCAPLICATLINIEF   NUMBER(20, 7) ;
  aCUMULAT            NUMBER(10) := 0;
  NEEDAPLICARE        NUMBER(1) := 0;
  DISCNETAPLICATGRUP  NUMBER(20, 7) ;
  DISCNETAPLICATTOTAL NUMBER(20, 7) ;

  Cursor crs is SELECT * FROM IESIRI1 WHERE CODIES = aCODIES ORDER BY INDEXLOCAL DESC;
  V_REC crs%rowtype;
BEGIN
  OPEN CRS;
  DISCOUNTT := 1;  DISCTOTAPLICAT := 1; DiscNetAplicatTotal := 1;  ProcCumulatTotal := 0;
  FETCH CRS INTO V_REC;
  WHILE CRS%FOUND
  LOOP
    EXIT WHEN CRS%NOTFOUND;

    DISCOUNT := 1; DISCAPLICAT := 1; ProcCumulatGrup := 0; DiscNetAplicatGrup := 1;
    WHILE V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CRS%FOUND
    LOOP
      IF Coalesce(V_REC.CODCRITERIU, 0) = aCodCriteriu THEN
        NEEDAPLICARE := 1;


        SELECT Coalesce(CUMULAT, 0) INTO aCUMULAT FROM CRITERIIDISC  WHERE CODCRITERIU = V_REC.CODCRITERIU;
        IF aCUMULAT = 0
          THEN NEEDAPLICARE := 0;
        END IF;

        IF NEEDAPLICARE = 1 THEN
          IF V_REC.TIPLINIE = &apos;T&apos; THEN
            PROCCUMULATTOTAL    := PROCCUMULATTOTAL + V_REC.CANT;
            DISCNETAPLICATTOTAL := GETUNITAR(PROCCUMULATTOTAL);
          ELSE
            PROCCUMULATGRUP    := PROCCUMULATGRUP + V_REC.CANT;
            DISCNETAPLICATGRUP := GETUNITAR(PROCCUMULATGRUP);
          END IF;
        ELSE
          IF V_REC.TIPLINIE = &apos;T&apos; THEN DISCTOTAPLICAT := DISCTOTAPLICAT * GETUNITAR(V_REC.CANT);
                                  ELSE DISCAPLICAT    := DISCAPLICAT    * GETUNITAR(V_REC.CANT);
          END IF;
        END IF;
      END IF;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;

    WHILE V_REC.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) AND CRS%FOUND
    LOOP
      if V_REC.CODIES1 = aCodIes1 THEN
        DISCOUNTTOT := DISCOUNTT * DISCOUNT;
        DISCAPLICATLINIE := DISCTOTAPLICAT * DISCAPLICAT;
        DISCAPLICATLINIE := (1-DISCAPLICATLINIE)*v_rec.pu*v_Rec.cant*(100+coalesce(v_Rec.procdisc,0))/100;
        DISCAPLICATLINIEF := DISCNETAPLICATTOTAL * DISCNETAPLICATGRUP;
        DISCAPLICATLINIEF := DISCAPLICATLINIE + (1-DISCAPLICATLINIEF)*v_rec.pretorig*v_Rec.cant;
      END IF;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;
  END LOOP;
  CLOSE CRS;
  RETURN DISCAPLICATLINIEF;
END;

PROCEDURE RECALCUL_AVARIE_INTR(aCODINTR IN NUMBER)
IS
  vDISCOUNT            NUMBER(20, 7) ;
  vDISCOUNTT           NUMBER(20, 7) ;
  vDISCOUNTTOT         NUMBER(20, 7) ;
  vPROCCUMULATGRUP     NUMBER(20, 7) ;
  vPROCCUMULATTOTAL    NUMBER(20, 7) ;
  vDISCAPLICAT         NUMBER(20, 7) ;
  vDISCTOTAPLICAT      NUMBER(20, 7) ;
  vDISCAPLICATLINIE    NUMBER(20, 7) ;
  vDISCNETAPLICATGRUP  NUMBER(20, 7) ;
  vDISCNETAPLICATTOTAL NUMBER(20, 7) ;

  -- folosite pentru refacere PRETORIG
  xDISCOUNT            NUMBER(20, 7) ;
  xDISCOUNTT           NUMBER(20, 7) ;
  xDISCOUNTTOT         NUMBER(20, 7) ;
  xPROCCUMULATGRUP     NUMBER(20, 7) ;
  xPROCCUMULATTOTAL    NUMBER(20, 7) ;
  xDISCAPLICAT         NUMBER(20, 7) ;
  xDISCTOTAPLICAT      NUMBER(20, 7) ;
  xDISCAPLICATLINIE    NUMBER(20, 7) ;
  xDISCNETAPLICATGRUP  NUMBER(20, 7) ;
  xDISCNETAPLICATTOTAL NUMBER(20, 7) ;

  Cursor crs is SELECT * FROM INTRARI1 WHERE CODINTR = aCODINTR ORDER BY INDEXLOCAL DESC;
  V_REC crs%rowtype;
BEGIN
  OPEN CRS;
  vDISCOUNTT := 1;  vDISCTOTAPLICAT := 1; vDiscNetAplicatTotal := 1; vProcCumulatTotal := 0;
  xDISCOUNTT := 1;  xDISCTOTAPLICAT := 1; xDiscNetAplicatTotal := 1; xProcCumulatTotal := 0;
  FETCH CRS INTO V_REC ;
  WHILE CRS%FOUND
  LOOP
    EXIT WHEN CRS%NOTFOUND;

    vDISCOUNT := 1; vDISCAPLICAT := 1; vProcCumulatGrup := 0; vDiscNetAplicatGrup := 1;
    xDISCOUNT := 1; xDISCAPLICAT := 1; xProcCumulatGrup := 0; xDiscNetAplicatGrup := 1;
    WHILE V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CRS%FOUND
    LOOP
      IF V_REC.TIPLINIE = &apos;T&apos; THEN
        vPROCCUMULATTOTAL    := vPROCCUMULATTOTAL + V_REC.CANT;
        vDISCNETAPLICATTOTAL := GETUNITAR(vPROCCUMULATTOTAL);
      ELSE
        vPROCCUMULATGRUP     := vPROCCUMULATGRUP + V_REC.CANT;
        vDISCNETAPLICATGRUP  := GETUNITAR(vPROCCUMULATGRUP);
      END IF;

      IF Coalesce(V_REC.CONTDISCOUNT, 0) = 0 AND V_REC.TIPLINIE = &apos;T&apos; THEN
        xPROCCUMULATTOTAL    := xPROCCUMULATTOTAL + V_REC.CANT;
        xDISCNETAPLICATTOTAL := GETUNITAR(xPROCCUMULATTOTAL);
      ELSIF Coalesce(V_REC.CONTDISCOUNT, 0) = 0 THEN
        xPROCCUMULATGRUP     := xPROCCUMULATGRUP + V_REC.CANT;
        xDISCNETAPLICATGRUP  := GETUNITAR(xPROCCUMULATGRUP);
      END IF;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;

    WHILE V_REC.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;)AND CRS%FOUND
    LOOP
      vDISCOUNTTOT      := vDISCOUNTT * vDISCOUNT * GETUNITAR(Coalesce(V_REC.ADDIM, 0));
      vDISCAPLICATLINIE := vDISCTOTAPLICAT * vDISCAPLICAT * vDISCNETAPLICATTOTAL * vDISCNETAPLICATGRUP;

      xDISCOUNTTOT      := xDISCOUNTT * xDISCOUNT * GETUNITAR(Coalesce(V_REC.ADDIM, 0));
      xDISCAPLICATLINIE := xDISCTOTAPLICAT * xDISCAPLICAT * xDISCNETAPLICATTOTAL * xDISCNETAPLICATGRUP;

      IF Coalesce(V_REC.PROCADAOS, 0) &lt;&gt; 0 THEN
        vDISCAPLICATLINIE := vDISCAPLICATLINIE + Coalesce(V_REC.PROCADAOS, 0) / 100;
        xDISCAPLICATLINIE := xDISCAPLICATLINIE + Coalesce(V_REC.PROCADAOS, 0) / 100;
      END IF;

      vDISCAPLICATLINIE := vDISCAPLICATLINIE * GETUNITAR(Coalesce(V_REC.ADDIM, 0));
      xDISCAPLICATLINIE := xDISCAPLICATLINIE * GETUNITAR(Coalesce(V_REC.ADDIM, 0));

      UPDATE INTRARI1
      SET COEFDISCMAJ = vDISCAPLICATLINIE
      WHERE CODINTR1  = V_REC.CODINTR1;

      IF xDISCAPLICATLINIE &lt;&gt; 1 AND xDISCAPLICATLINIE &lt;&gt; 0 THEN
        UPDATE INTRARI1
        SET PRETORIG = PU/xDISCAPLICATLINIE
        WHERE CODINTR1  = V_REC.CODINTR1;-- AND PRETORIG = PU;
      END IF;

      FETCH CRS INTO V_REC;
      EXIT WHEN CRS%NOTFOUND;
    END LOOP;
  END LOOP;
  CLOSE CRS;
END;

PROCEDURE SET_DIMENSIUNI_NIRSTOC(aCODOBIECT IN NUMBER, aD1 IN NUMBER, aD2 IN NUMBER, aD3 IN NUMBER)
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
     NS.CODNIRSTOC
    FROM
      NIRSTOC NS
    WHERE
      NS.CODOBIECT     = aCODOBIECT
      AND Coalesce(NS.D1, 0) + Coalesce(NS.D2, 0) + Coalesce(NS.D2, 0) = 0
  )
  LOOP
    UPDATE NIRSTOC
    SET
      D1 = aD1,
      D2 = aD2,
      D3 = aD3
    WHERE
     CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  FOR V_REC IN
  (
   SELECT
     NS.CODNIRSTOC,
     NS.CANTNIR,
     NS.D1,
     NS.D2,
     NS.D3,
     A.RELATIEUM1,
     A.UM1,
     CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
     CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
     CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
   FROM
     NIRSTOC NS,
     NARTOBJ O,
     NART A
   WHERE
     Coalesce(NS.D1, 0) +  Coalesce(NS.D2, 0) + Coalesce(NS.D3, 0) &lt;&gt; 0
     AND Coalesce(NS.CANTUM1, 0) = 0
     AND NS.CODOBIECT       = aCODOBIECT
     AND O.CODOBIECT        = NS.CODOBIECT
     AND A.CODARTICOL       = O.CODARTICOL
     AND Coalesce(A.RELATIEUM1, 0) &lt;&gt; 0
   )
   LOOP
     UPDATE NIRSTOC
     SET
      CANTUM1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANTNIR, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
   END LOOP;

  FOR V_REC IN
  (
   SELECT
     NSE.CODNIRSER,
     NSE.CANTNIR,
     NS.D1,
     NS.D2,
     NS.D3,
     A.RELATIEUM1,
     A.UM1,
     CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
     CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
     CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
   FROM
     NIRSTOC NS,
     NIRSER NSE,
     NARTOBJ O,
     NART A
   WHERE
     Coalesce(NS.D1, 0) +  Coalesce(NS.D2, 0) + Coalesce(NS.D3, 0) &lt;&gt; 0
     AND NSE.CODNIRSTOC = NS.CODNIRSTOC
     AND Coalesce(NSE.CANTUM1, 0) = 0
     AND NS.CODOBIECT       = aCODOBIECT
     AND O.CODOBIECT        = NS.CODOBIECT
     AND A.CODARTICOL       = O.CODARTICOL
     AND Coalesce(A.RELATIEUM1, 0) &lt;&gt; 0
   )
   LOOP
     UPDATE NIRSER
     SET
      CANTUM1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANTNIR, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
     WHERE
       CODNIRSER = V_REC.CODNIRSER;

   END LOOP;

  FOR V_REC IN
  (
   SELECT
     L1.CODLIVR1,
     L1.CANT,
     NS.D1,
     NS.D2,
     NS.D3,
     A.RELATIEUM1,
     U1.ZECIMALE,
     A.UM1,
     CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
     CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
     CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
   FROM
     LIVR1 L1,
     NIRSTOC NS,
     NARTOBJ O,
     NART A,
     NUM1 U1
   WHERE
     L1.CODNIRSTOC    = NS.CODNIRSTOC
     AND NS.CODOBIECT = aCODOBIECT
     AND Coalesce(NS.D1, 0) +  Coalesce(NS.D2, 0) + Coalesce(NS.D3, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND Coalesce(A.RELATIEUM1, 0) &lt;&gt; 0
     AND U1.CODUM1 = L1.UMSEC
   )
  LOOP
     UPDATE LIVR1
     SET
      CANTUM1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
     WHERE
       CODLIVR1  = V_REC.CODLIVR1;
  END LOOP;

-- COMAND1
  FOR V_REC IN
  (
    SELECT
     C1.CODCOMANDA1
    FROM
      COMANDA1 C1
    WHERE
      C1.CODOBIECT     = aCODOBIECT
      AND Coalesce(C1.D1, 0) + Coalesce(C1.D2, 0) + Coalesce(C1.D3, 0) = 0
  )
  LOOP
    UPDATE COMANDA1
    SET
      D1 = aD1,
      D2 = aD2,
      D3 = aD3
    WHERE
     CODCOMANDA1 = V_REC.CODCOMANDA1;
  END LOOP;

  FOR V_REC IN
  (
    SELECT
      C1.CODCOMANDA1,
      C1.CANTACCEPTAT,
      C1.CANTCOMANDAT,
      C1.D1,
      C1.D2,
      C1.D3,
      A.RELATIEUM1,
      A.UM1,
      CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
      CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
      CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
    FROM
      COMANDA1 C1,
      NARTOBJ O,
      NART A
    WHERE
      Coalesce(C1.D1, 0) +  Coalesce(C1.D2, 0) + Coalesce(C1.D3, 0) &lt;&gt; 0
      AND Coalesce(C1.CANTUM1, 0) = 0
      AND C1.CODOBIECT       = aCODOBIECT
      AND O.CODOBIECT        = C1.CODOBIECT
      AND A.CODARTICOL       = O.CODARTICOL
      AND Coalesce(A.RELATIEUM1, 0) &lt;&gt; 0
   )
   LOOP
     UPDATE COMANDA1
     SET
       ACCEPTUM1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANTACCEPTAT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3),
       CANTUM1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANTCOMANDAT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
     WHERE
       CODCOMANDA1 = V_REC.CODCOMANDA1;
   END LOOP;

   SET_DIMENSIUNI_PRODCOMP(aCODOBIECT, aD1, aD2, aD3);
--  COMMIT;
END;

PROCEDURE SET_DIMENSIUNI_PRODCOMP(aCODOBIECT IN NUMBER, aD1 IN NUMBER, aD2 IN NUMBER, aD3 IN NUMBER)
IS
tmp number(20);
BEGIN
  for v_rec in (select pc.codprodcomp, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc,
                       a.relatieum1, a.um1,PC.CANT,A.D1,A.D2,A.D3,
                       CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
                       CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
                       CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
                from prodcomp pc
                     inner join nartobj o on o.codobiect = pc.codobiect
                     inner join nart a on o.codarticol = a.codarticol
                where pc.codobiect = aCODOBIECT and a.relatieum1 &gt; 0) loop
    begin
      SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_37&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;

      update prodcomp pc
      set
        D1 = aD1,
        D2 = aD2,
        D3 = aD3
      where pc.codprodcomp = v_Rec.Codprodcomp;

      update prodcomp pc set
      cantum1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
      where codprodcomp = v_rec.codprodcomp;

      NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
      commit;
    exception when others then rollback;
    end;
  end loop;
  for v_rec in (select pm.codprodcomp, pm.codmat, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc,
                       a.relatieum1,PM.CANT,A.D1,A.D2,A.D3,A.UM1,
                       CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
                       CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
                       CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
                from prodmat pm
                     inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                     inner join nartobj o on o.codobiect = pc.codobiect
                     inner join nartobj om on om.codobiect = pm.codobiect
                     inner join nart a on a.codarticol = om.codarticol
                where pm.codobiect = aCODOBIECT) loop
    begin
      SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_37&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      update prodmat pc
      set
        D1 = aD1,
        D2 = aD2,
        D3 = aD3
      where codmat = v_rec.codmat;
      update prodmat pc set
      cantum1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
      where codmat = v_rec.codmat;
      NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
      commit;
    exception when others then rollback;
    end;
  end loop;
  for v_rec in (select pm.codprodcomp, pm.codrez, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc,
                       a.relatieum1,PM.CANT,A.D1,A.D2,A.D3,A.UM1,
                       CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
                       CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
                       CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
                from prodrez pm
                     inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                     inner join nartobj o on o.codobiect = pc.codobiect
                     inner join nartobj om on om.codobiect = pm.codobiect
                     inner join nart a on a.codarticol = om.codarticol
                where pm.codobiect = aCODOBIECT) loop
    begin
      SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_37&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      update prodrez pc
      set
        D1 = aD1,
        D2 = aD2,
        D3 = aD3
      where codrez = v_rec.codrez;
      update prodrez pc set
      cantum1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
      where codrez = v_rec.codrez;
      NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
      commit;
    exception when others then rollback;
    end;
  end loop;
  for v_rec in (select pm.codprodcomp, pm.codnormemat, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc,
                       a.relatieum1,PM.CANT,A.D1,A.D2,A.D3,A.UM1,
                       CASE WHEN COALESCE(A.PARITATED1,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED1,1) END COEFD1,
                       CASE WHEN COALESCE(A.PARITATED2,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED2,1) END COEFD2,
                       CASE WHEN COALESCE(A.PARITATED3,1) = 0 THEN 1 ELSE COALESCE(A.PARITATED3,1) END COEFD3
                from normemat pm
                     inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                     inner join nartobj o on o.codobiect = pc.codobiect
                     inner join nartobj om on om.codobiect = pm.codobiect
                     inner join nart a on a.codarticol = om.codarticol
                where pm.codobiect = aCODOBIECT) loop
    begin
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_37&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
      update normemat pc
      set
        D1 = aD1,
        D2 = aD2,
        D3 = aD3
      where codnormemat = v_rec.codnormemat;
      update normemat pc set
      cantum1 = pkg_um.GetSpecificCantUM1(V_REC.um1, 0, 0, 0, V_REC.relatieum1, V_REC.d1, V_REC.d2, V_REC.d3, V_REC.CANT, V_REC.COEFD1*V_REC.COEFD2*V_REC.COEFD3)
      where codnormemat = v_rec.codnormemat;
      NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
      commit;
    exception when others then rollback;
    end;
  end loop;
END;

FUNCTION ACCES_LA_GESTIUNEA(aGEST IN NUMBER) RETURN NUMBER
IS
 aCODSUBUNIT NUMBER(20) := 0;
BEGIN
  IF aGEST = 0 THEN  RETURN 1;
  ELSE
    IF pkg_nomgest.GESTIUNE_DEDICATA(aGEST) =  0 THEN RETURN 0;
    ELSE
      BEGIN
        SELECT Coalesce(CODSUBUNIT, 0) INTO aCODSUBUNIT FROM NGEST WHERE CODGEST = aGEST;
        EXCEPTION WHEN OTHERS THEN  aCODSUBUNIT := 0;
      END;
      IF aCODSUBUNIT = 0 THEN RETURN 1;
      ELSE
        RETURN PKG_GLOBALS.SUBUNITATEDOC_VALIDA(acodsubunit);
      END IF;
    END IF;
  END IF;
END;

FUNCTION ACCES_LA_GESTIUNEA_EXT(aGEST IN NUMBER) RETURN NUMBER
IS
 aCODSUBUNIT NUMBER(20) := 0;
 aNR         NUMBER(5)  := 0;
BEGIN
  IF aGEST = 0 THEN  RETURN 1;
  ELSE
    IF pkg_nomgest.GESTIUNE_DEDICATA(aGEST) =  0 THEN RETURN 0;
    ELSE
      BEGIN
        SELECT Coalesce(CODSUBUNIT, 0) INTO aCODSUBUNIT FROM NGEST WHERE CODGEST = aGEST;
        EXCEPTION WHEN OTHERS THEN  aCODSUBUNIT := 0;
      END;
      IF aCODSUBUNIT = 0 THEN RETURN 1;
      ELSE
        SELECT COUNT(*) INTO aNR FROM TMP_SUBUNITDEDICATE;
        IF aNR = 0 THEN  RETURN 1;
        ELSE
          SELECT COUNT(*) INTO aNR FROM TMP_SUBUNITDEDICATE WHERE CODSUBUNIT = aCODSUBUNIT;
          RETURN aNR;
        END IF;
      END IF;
    END IF;
  END IF;
END;


FUNCTION STARE_APROBARI(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURN VARCHAR2
IS
  aSTARE         VARCHAR2(50) := &apos;Nefinalizata&apos;;
  INFOAPROBARE   VARCHAR2(50) := NULL;
  INFORESPINGERE VARCHAR2(50) := NULL;
BEGIN
  FOR V_REC IN (SELECT * FROM CMDAPROBARI WHERE TIPDOC = aTIPDOC AND CODDOC = aCODDOC ORDER BY NIVEL )
  LOOP
    IF Coalesce(V_REC.STARE, 0) = 1 THEN INFOAPROBARE := &apos;Aprobata pana la nivel &apos; || TO_CHAR(V_REC.NIVEL);
    ELSE
      IF Coalesce(V_REC.STARE, 0) = 2 THEN INFORESPINGERE := &apos;Respinsa de nivelul &apos; || TO_CHAR(V_REC.NIVEL);
    ELSE
      IF Coalesce(V_REC.STARE, 0) = 3 THEN INFORESPINGERE := &apos;Reanalizare (nivel &apos; || TO_CHAR(V_REC.NIVEL) || &apos;)&apos;;    END IF;
    END IF;
    END IF;
  END LOOP;

  IF INFORESPINGERE IS NOT NULL THEN aSTARE := INFORESPINGERE;
  ELSE
  IF INFOAPROBARE IS NOT NULL THEN aSTARE := INFOAPROBARE;
  END IF;
  END IF;


  RETURN aSTARE;

END;

procedure StartEvolutie(aID in number, aUserID in number, aTotal in number, aActiune in varchar2) is pragma autonomous_transaction;
nr number;
begin
  select count(*) into nr from evolutie where userid = aUSERID and ID = aID;
  if nr = 0 then
    insert into evolutie(ID, userid, total, Actiune) values (aID, aUserID, aTotal, UPPER(aActiune));
  else
    Update evolutie
    set total = aTotal, Curent = 0, Actiune = aActiune
    where UserID = aUserID and ID = aID;
  end if;
  Commit;
end;

procedure SetEvolutie(aID in number, aUserID in number, aCurent in number) is pragma autonomous_transaction;
begin
  Update evolutie
  set Curent = aCurent
  where UserID = aUserID and ID = aID;
  Commit;
end;

procedure GetEvolutie(aID in number, aUserID in number, aTotal out number, aFacute out number) is
begin
  begin
    Select total, Curent into aTotal, aFacute from Evolutie where UserID = aUserID and ID = aID;
  exception when others then
    aTotal := 0;
    aFacute := 0;
  end;
end;

PROCEDURE GET_LAST_MODI_PRET(aCODNIRSTOC_IN   IN NUMBER,
                             aCODNIRSER_IN    IN NUMBER,
                             aCODNIRSTOC_OUT OUT NUMBER,
                             aCODNIRSER_OUT  OUT NUMBER,
                             aPRET_OUT       OUT NUMBER,
                             aADAOS_OUT      OUT NUMBER
                            )
IS
 aCODNIRSTOC_MAN NUMBER(20) := 0;
 aCODNIRSER_MAN  NUMBER(20) := 0;
 aCODNS          NUMBER(20) := 0;
 aCODNSE         NUMBER(20) := 0;
 aPRET           NUMBER(20, 7) := 0;
 aADAOS          NUMBER(20, 7) := 0;
BEGIN
  aCODNIRSTOC_MAN := aCODNIRSTOC_IN;
  aCODNIRSER_MAN  := aCODNIRSER_IN;
  aCODNIRSTOC_OUT := 0;
  aCODNIRSER_OUT  := 0;

   WHILE aCODNIRSTOC_MAN &gt; 0 LOOP
   BEGIN
      select
        NS.CODNIRSTOC,
        NSE.CODNIRSER
      INTO
        aCODNS,
        aCODNSE
      FROM
        livr1 L1,
        livr L,
        NIRSTOC NS
        LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
        NIR N
      WHERE
        L1.codnirstoc             = aCODNIRSTOC_MAN
        AND Coalesce(L1.CODNIRSER, 0)  = aCODNIRSER_MAN
        AND L.CODLIVR             = L1.CODLIVR
        AND L.TIPLIVR             = 13
        AND NS.CODLIVR1           = L1.CODLIVR1
        AND N.CODNIR              = NS.CODNIR
        AND N.CODTRANSF           = L.CODTRANSF
        AND N.TIPNIR              = L.TIPLIVR;
        EXCEPTION WHEN OTHERS THEN aCODNS := 0; aCODNSE := 0;
      END;
      IF aCODNS = 0 THEN
        aCODNIRSTOC_OUT  := aCODNIRSTOC_MAN;
        aCODNIRSER_OUT   := aCODNIRSER_MAN;
        aCODNIRSTOC_MAN  := 0;
        aCODNIRSER_MAN   := 0;
      ELSE
        aCODNIRSTOC_MAN := aCODNS;
        aCODNIRSER_MAN  := aCODNSE;
      END IF;
   END LOOP;

   BEGIN
     SELECT PRET, ADAOS INTO aPRET, aADAOS FROM NIRSTOC WHERE CODNIRSTOC = aCODNIRSTOC_OUT;
     EXCEPTION WHEN OTHERS THEN aPRET := 0; aADAOS := 0;
   END;
   aPRET_OUT   := aPRET;
   aADAOS_OUT  := aADAOS;
END;

procedure SetDirectiva(oDirectiva in varchar2) is pragma autonomous_transaction;
vCount number;
begin
  begin
    select count(*) into vCount from tmp_directive where Upper(oDirectiva) = directiva;
  exception when others then vCount := 0;
  end;
  if vCount = 0 then
    insert into tmp_directive(directiva) values(Upper(oDirectiva));
    commit;
  end if;
end;

function Directiva(oDirectiva in varchar2) return boolean is
vCount number;
begin
  begin
    select count(*) into vCount from tmp_directive where Upper(oDirectiva) = directiva;
  exception when others then vCount := 0;
  end;

  return (vCount &gt; 0);
end;


procedure clear_x is pragma autonomous_transaction;
begin
  delete x;
  commit;
end;

procedure baga_in_x(ceva in varchar2) is pragma autonomous_transaction;
begin
  insert into x(test) values(ceva);
  commit;
end;

function testParamListe return number is
an   number;
luna number;
begin
  PKG_GLOBALS.SetUserID(1289);
  PKG_GLOBALS.SETPARAMS_CUSTOM(40006, 0);
  An := PKG_GLOBALS.ANSTART;
  Luna := PKG_GLOBALS.LUNASTART ;
  return an*12+luna;
end;

FUNCTION GETSERIINIRSTOC(aCODNIRSTOC IN NUMBER) RETURN VARCHAR2 IS
  SERII VARCHAR2(32000) := &apos; &apos;;
BEGIN
  SELECT
    --listagg(SERIE || &apos;=&apos; || TO_CHAR(REST), &apos;, &apos;) within group (ORDER BY SERIE)  INTO SERII
    string_agg(SERIE || &apos;=&apos; || TO_CHAR(REST)) INTO SERII
  FROM (
    SELECT CODNIRSTOC, SERIE, SUM(NSE.REST) AS REST
    FROM NIRSER NSE, NSERII SER
    WHERE NSE.CODNIRSTOC = aCODNIRSTOC
      AND SER.CODSERIE = NSE.CODSERIE
      AND NSE.REST &gt; 0
    GROUP BY CODNIRSTOC, SERIE
  ) x
  GROUP BY CODNIRSTOC;

  RETURN SERII;
END;


FUNCTION GETSERIINIRNEOPERAT(aCODNIRSTOC IN NUMBER) RETURN VARCHAR2 IS
  SERII VARCHAR2(32000) := &apos; &apos;;
BEGIN
  SELECT
    --listagg(SERIE || &apos;=&apos; || TO_CHAR(REST), &apos;, &apos;) within group (ORDER BY SERIE)  INTO SERII
    string_agg(SERIE || &apos;=&apos; || TO_CHAR(REST)) INTO SERII
  FROM (
    SELECT CODNIRSTOC, SERIE, SUM(NSE.CANTNIR) AS REST
    FROM NIRSER NSE, NSERII SER
    WHERE NSE.CODNIRSTOC = aCODNIRSTOC
      AND SER.CODSERIE = NSE.CODSERIE
      AND NSE.CANTNIR &gt; 0
    GROUP BY CODNIRSTOC, SERIE
  ) x
  GROUP BY CODNIRSTOC;

  RETURN SERII;
END;

PROCEDURE LOCK_STOC_CANT_BULK IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN ( SELECT * FROM TMP_STOCLOCK_BULK)
  LOOP
    UPDATE STOCLOCK
    SET CANT = CANT + V_REC.CANT
    WHERE USERID = V_REC.USERID AND CODNIRSTOC =  V_REC.CODNIRSTOC AND CODNIRSER = V_REC.CODNIRSER;
    IF SQL%ROWCOUNT = 0 THEN
      INSERT INTO STOCLOCK (USERID, CODNIRSTOC, CODNIRSER, CANT) VALUES (V_REC.USERID, V_REC.CODNIRSTOC, V_REC.CODNIRSER, V_REC.CANT);
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE UNLOCK_STOC_CANT_BULK IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_STOCLOCK_BULK)
  LOOP
    UPDATE STOCLOCK
    SET CANT = CANT - V_REC.CANT
    WHERE USERID = V_REC.USERID AND CODNIRSTOC =  V_REC.CODNIRSTOC AND CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

  DELETE FROM  STOCLOCK WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CANT = 0;
  COMMIT;
END;

PROCEDURE LOCK_STOC_CANT_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM STOCLOCK WHERE USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;
  IF NR = 0 THEN
    INSERT INTO STOCLOCK (USERID, CODNIRSTOC, CODNIRSER, CANT) VALUES (((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)), aCODNIRSTOC, aCODNIRSER, aCANT);
  ELSE
    UPDATE STOCLOCK
    SET
      CANT = CANT + aCANT
    WHERE
   USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;
 END IF;
 COMMIT;
END;


PROCEDURE UNLOCK_STOC_CANT_EXT(aCODNIRSTOC IN NUMBER, aCODNIRSER IN NUMBER, aCANT IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE STOCLOCK
  SET
    CANT = CANT - aCANT
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CODNIRSTOC =  aCODNIRSTOC AND CODNIRSER = aCODNIRSER;

  DELETE FROM  STOCLOCK
  WHERE
  USERID = ((Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X)) AND CANT = 0;
  COMMIT;
END;

procedure CheckDebugMode(aSQL in CLOB, aListID in number, aListVer in number) is
begin
  if ISDEBUGMODE = 1 then
    insert into debug_liste(userid, sql_lista, listid, listver, sql_time)
    select getuserid, aSQL, aListID, aListVer, CURRENT_TIMESTAMP from dual;
    commit;
  end if;
end;

procedure ClearDebugListe is
begin
  delete debug_liste where userid = getuserid;
  commit;
end;

FUNCTION BITOR (x IN NUMBER, y IN NUMBER) RETURN NUMBER AS
BEGIN
  RETURN (x + y - BITAND(x, y));
END;

PROCEDURE SetDocExportatEdi (pTipDoc IN NUMBER, pCodDoc IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF Coalesce(pTipDoc, 0) &lt;&gt; 0 AND Coalesce(pCodDoc, 0) &lt;&gt; 0 THEN
    MERGE INTO docextra a
    USING ( SELECT pTipDoc TipDoc, pCodDoc CodDoc, 1 export_edi, systimestamp export_edi_data FROM dual) b
    ON (a.TipDoc = b.TipDoc AND a.CodDoc = b.CodDoc)
    WHEN MATCHED THEN UPDATE SET a.export_edi = b.export_edi, a.export_edi_data = b.export_edi_data
    WHEN NOT MATCHED THEN INSERT (a.TipDoc, a.CodDoc, a.export_edi, a.export_edi_data) VALUES (b.TipDoc, b.CodDoc, b.export_edi, b.export_edi_data);

    COMMIT;
  END IF;
END;

FUNCTION GetPretPentruRetail RETURN NUMBER IS
BEGIN
  RETURN Coalesce(PretPentruRetail, 0);
END;

FUNCTION valoareNumeric1     RETURN NUMBER IS
BEGIN
  RETURN  TO_NUMBER(lstVal1) ;
  EXCEPTION
    WHEN value_error THEN
       RETURN NULL;
END;

FUNCTION valoareNumeric2     RETURN NUMBER IS
BEGIN
  RETURN  TO_NUMBER(lstVal2) ;
    EXCEPTION
    WHEN value_error THEN
       RETURN NULL;
END;

FUNCTION valoareNumeric3     RETURN NUMBER IS
BEGIN
  RETURN  TO_NUMBER(lstVal3) ;
    EXCEPTION
    WHEN value_error THEN
       RETURN NULL;
END;

FUNCTION valoareNumeric4     RETURN NUMBER IS
BEGIN
  RETURN  TO_NUMBER(lstVal4) ;
    EXCEPTION
    WHEN value_error THEN
       RETURN NULL;
END;

FUNCTION valoareNumeric5     RETURN NUMBER IS
BEGIN
  RETURN  TO_NUMBER(lstVal5) ;
    EXCEPTION
    WHEN value_error THEN
       RETURN NULL;
END;

FUNCTION valoareChar1           RETURN VARCHAR IS
BEGIN
  RETURN  lstVal1 ;
END;

FUNCTION valoareChar2           RETURN VARCHAR IS
BEGIN
  RETURN lstVal2;
END;

FUNCTION valoareChar3           RETURN VARCHAR IS
BEGIN
  RETURN lstVal3;
END;

FUNCTION valoareChar4           RETURN VARCHAR IS
BEGIN
  RETURN lstVal4;
END;

FUNCTION valoareChar5           RETURN VARCHAR IS
BEGIN
  RETURN lstVal5;
END;

PROCEDURE PrepareTest(S IN NUMBER, A IN NUMBER, L IN NUMBER) IS
begin
  pkg_globals.setuserid(1); commit;
  pkg_globals.setsubunitate(S); commit;
  pkg_globals.setlunalucru(A, L);
  pkg_stoc_generare_facturi.make_config_luna;
end;


end  PKG_GLOBALS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GRECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E4EB881069930E25C32A5723B0538B00E9C941C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_grechiv IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodGrEchiv INTO Tmp FROM GRECHIV WHERE CodGrEchiv = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NECHIV WHERE CODGRUPA = RecId ;
  DELETE FROM GRECHIV WHERE CodGrEchiv = RecId ;
  NotifyModif(2, RecId, &apos;GRECHIV&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_GRECHIV FIELDS( CodGrEchiv ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_GRECHIV ( CodGrEchiv, Denumire, Cod, Ind, Info )
    ( SELECT CodGrEchiv, Denumire, Cod, Ind, Info
      FROM GRECHIV WHERE CodGrEchiv = RecId ) ;

  INSERT INTO TMP_NECHIV
   (CODECHIV, CODOBIECT, PARITATE, CODGRUPA,Generic, Ind, INDEXLOCAL,
   DEN_UM,
   DENOBIECTECHIV,zecimale,
   CODEXTERN, CODINTERN, CODCATALOG)

   (SELECT CODECHIV, O.CODOBIECT, PARITATE, CODGRUPA,nvl(Generic,0), Ind, INDEXLOCAL,
           (SELECT DEN_UM FROM NUM WHERE CODUM = (SELECT UM FROM NART WHERE CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = E.CODOBIECT))),
           (SELECT DENUMIRE FROM NARTOBJ WHERE CODOBIECT = E.CODOBIECT),
           (SELECT ZECIMALE FROM NUM WHERE CODUM = (SELECT UM FROM NART WHERE CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = E.CODOBIECT))),
           O.CODEXTERN,
           O.CODINTERN,
           A.CODEXTERNART
    FROM
       NECHIV E,
       NARTOBJ O,
       NART A
    WHERE
      E.CODGRUPA = RecId
      AND E.CODOBIECT = O.CODOBIECT
      AND O.CODARTICOL = A.CODARTICOL
     );

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo    INTEGER := 0;
  vCodEchiv INTEGER;
  vInd      INTEGER;
BEGIN
	SELECT CodGrEchiv, Ind INTO RecId, vInd FROM TMP_GRECHIV;
	Update TMP_NECHIV set Ind = vInd;
  IF Operation = 0 THEN  -- UPDATE

    UPDATE GRECHIV
    SET ( Denumire, Cod, Ind, Info ) = ( SELECT Denumire, Cod, Ind, Info FROM TMP_GRECHIV )
    WHERE CodGrEchiv = RecId ;

    -- Detail NEchiv
    DELETE FROM NECHIV
    WHERE CodGrupa = RecId
      AND CodEchiv NOT IN (SELECT CodEchiv FROM TMP_NECHIV WHERE NVL(CodEchiv,0) &lt;&gt; 0);

    FOR v_rec IN ( SELECT * FROM TMP_NECHIV ORDER BY CodEchiv DESC)
    LOOP
      IF v_rec.CodEchiv &gt; 0 THEN
        UPDATE NECHIV
        SET CodGrupa  = RecId ,
            Paritate  = v_rec.Paritate,
            Codobiect = v_rec.Codobiect,
            Generic   = nvl(v_rec.Generic,0),
            Ind       = v_rec.Ind,
            INDEXLOCAL = V_REC.INDEXLOCAL
        WHERE CodEchiv = v_rec.CodEchiv;
      ELSE
        UPDATE NECHIV
        SET CodGrupa  = RecId ,
            Paritate  = v_rec.Paritate
        WHERE Codobiect = v_rec.Codobiect
        RETURNING Count(CodEchiv) INTO vRecNo;

        IF vRecNo = 0 THEN
          INSERT INTO NECHIV ( CODECHIV, CODOBIECT, PARITATE, CodGrupa,Generic, Ind, INDEXLOCAL )
          SELECT seq_NECHIV_CodEchiv.Nextval, v_rec.Codobiect, v_rec.Paritate, RecId, nvl(v_rec.Generic, 0),v_rec.Ind, V_REC.INDEXLOCAL
          FROM dual;
       /* ELSIF vRecNo &gt; 1 THEN -- nu ar trebuii sa ajunga aici -- curata duplicate
          SELECT Min(CodEchiv) INTO vCodEchiv FROM NECHIV WHERE Codobiect = v_rec.Codobiect;
          DELETE NECHIV WHERE Codobiect = v_rec.Codobiect AND CodEchiv &gt; vCodEchiv;*/
        END IF;

      END IF;
    END LOOP;

  ELSE  -- INSERT

    SELECT SEQ_GRECHIV_CODGRECHIV.NextVal INTO RecId FROM DUAL;

    INSERT INTO  GRECHIV ( CodGrEchiv, Denumire, Cod, Ind, Info )
    SELECT  RecId, Denumire, Cod, Ind, Info FROM TMP_GRECHIV;

    -- Detail NEchiv
    --INSERT INTO NECHIV ( CODECHIV, CODOBIECT, PARITATE, CodGrupa )
    --SELECT  seq_NECHIV_CodEchiv.Nextval, CODOBIECT, PARITATE, RecId FROM TMP_NECHIV;
    FOR v_rec IN ( SELECT * FROM TMP_NECHIV ORDER BY CodEchiv DESC)
    LOOP
      UPDATE NECHIV
      SET CodGrupa  = RecId ,
          Paritate  = v_rec.Paritate ,
          Generic   = v_rec.Generic, 
          Ind       = v_rec.Ind,
          INDEXLOCAL = V_REC.INDEXLOCAL
      WHERE Codobiect = v_rec.Codobiect
      RETURNING Count(CodEchiv) INTO vRecNo;

      IF vRecNo = 0 THEN
        INSERT INTO NECHIV ( CODECHIV, CODOBIECT, PARITATE, CodGrupa, Generic, Ind, INDEXLOCAL )
        SELECT seq_NECHIV_CodEchiv.Nextval, v_rec.Codobiect, v_rec.Paritate, RecId, nvl(v_rec.Generic, 0),V_REC.Ind, V_REC.INDEXLOCAL
        FROM dual;
    /*  ELSIF vRecNo &gt; 1 THEN -- nu ar trebuii sa ajunga aici -- curata duplicate
        SELECT Min(CodEchiv) INTO vCodEchiv FROM NECHIV WHERE Codobiect = v_rec.Codobiect;
        DELETE NECHIV WHERE Codobiect = v_rec.Codobiect AND CodEchiv &gt; vCodEchiv;*/
      END IF;
    END LOOP;
  END IF;
  NotifyModif(Operation, RecId, &apos;GRECHIV&apos;);
  COMMIT;
END;


PROCEDURE GET_INFO_PARITATI(ACODOBIECT IN NUMBER,APARITATE OUT NUMBER,APARITATE_Generic OUT NUMBER, ADENUMIRE OUT VARCHAR2, ADENUM OUT VARCHAR2) IS
acodGrupa number(20);
BEGIN
 BEGIN
   SELECT E.PARITATE,NOBJ.DENUMIRE,U.DEN_UM,E.CODGRUPA INTO APARITATE,ADENUMIRE,ADENUM,acodGrupa
   FROM NECHIV E  INNER JOIN NARTOBJ NOBJ ON E.CODOBIECT = NOBJ.CODOBIECT
                  INNER JOIN NART N ON N.CODARTICOL = NOBJ.CODARTICOL
                  INNER JOIN NUM U ON U.CODUM = N.UM
   WHERE E.CODOBIECT = ACODOBIECT;
 EXCEPTION WHEN OTHERS THEN
   APARITATE := -1 ;
   ADENUMIRE := &apos;?&apos;;
   ADENUM    := &apos;?&apos;;
 END;

 BEGIN
   SELECT E.PARITATE INTO APARITATE_Generic
   FROM  NECHIV E
   WHERE E.CODGRUPA = ACODGRUPA AND  E.Generic = 1;
 EXCEPTION WHEN OTHERS THEN
  APARITATE_Generic := -1;
 END;


END;


FUNCTION GET_DENOBIECT_Generic(ACodGrupa  in number) return varchar2 is
SRESULT VARCHAR2(300);
BEGIN
  BEGIN
/*    SELECT  OBJ.DENUMIRE INTO SRESULT FROM
      NECHIV E INNER JOIN NECHIV GEN ON E.CODGRUPA = GEN.CODGRUPA
               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = GEN.CODOBIECT
    WHERE E.CODOBIECT = aCodObiect AND GEN.Generic, Ind = 1 ;  */
   SELECT OBJ.DENUMIRE INTO SRESULT FROM
      NECHIV E INNER JOIN NARTOBJ OBJ ON E.CODOBIECT = OBJ.CODOBIECT
   WHERE E.CODGRUPA = ACodGrupa AND E.Generic = 1 ;
  EXCEPTION WHEN OTHERS THEN
    SRESULT :=&apos;?&apos;;
  END;


RETURN SRESULT;
END;
end pkg_grechiv;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_GRUPEDRUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC3E1D3F2E572E17AF370E3C4E8B023C1ACC69A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_GRUPEDRUM is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodGrupa INTO Tmp FROM GRUPEDRUM WHERE CODGRUPA = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM GRUPEDRUM WHERE CODGRUPA = RecId ;
  NotifyModif(2, RECID, &apos;GRUPEDRUM&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_GRUPEDRUM (CODGRUPA) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_GRUPEDRUM(CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
  SELECT CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE
  FROM GRUPEDRUM WHERE CODGRUPA = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODGRUPA INTO RecId FROM TMP_GRUPEDRUM;
    UPDATE GRUPEDRUM SET (DENUMIRE, SIMBOL, COEF, DESCRIERE)
    = ( SELECT DENUMIRE, SIMBOL, COEF, DESCRIERE
        FROM TMP_GRUPEDRUM )
    WHERE CODGRUPA = RecId ;

  ELSE  -- INSERT
    SELECT SEQ_GRUPEDRUM_CODGRUPA.NextVal INTO RecId FROM DUAL;
    INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
    SELECT RECID, DENUMIRE, SIMBOL, COEF, DESCRIERE
    FROM TMP_GRUPEDRUM;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;GRUPEDRUM&apos;);  

  COMMIT;
END;

end PKG_GRUPEDRUM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IDENTEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A9AB90B4985BA1E667F5EF12C38CFD14AF42D07</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_IdentEvalS is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodIdentEvalS INTO Tmp FROM IdentEvalS WHERE CodIdentEvalS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM IdentEvalS WHERE CodIdentEvalS = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_IdentEvalS FIELDS( CodIdentEvalS ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_IdentEvalS 
	(
   CodIdentEvalS , 
   Nume, 
   DataOra, 
   NrEvaluatori, 
   NrEsantioane
	)
	SELECT 
   CodIdentEvalS , 
   Nume, 
   DataOra, 
   NrEvaluatori, 
   NrEsantioane
  FROM IdentEvalS WHERE CodIdentEvalS = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodIdentEvalS INTO RECID FROM TMP_IdentEvalS;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE IdentEvalS
    SET
     (
        Nume, 
        DataOra, 
        NrEvaluatori, 
        NrEsantioane
			)
			= 
			(SELECT
       Nume, 
       DataOra, 
       NrEvaluatori, 
       NrEsantioane
		FROM TMP_IdentEvalS)
    WHERE CodIdentEvalS = RECID;

ELSE  -- INSERT
    SELECT SEQ_IdentEvalS_CodIdentEvalS.NextVal INTO RecId FROM DUAL;
    INSERT INTO IdentEvalS(
       CodIdentEvalS , 
       Nume, 
       DataOra, 
       NrEvaluatori, 
       NrEsantioane
    )
    SELECT 
  	   RECID   , 
       Nume, 
       DataOra, 
       NrEvaluatori, 
       NrEsantioane
		FROM TMP_IdentEvalS;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;IdentEvalS&apos;);
  COMMIT;
 
END;


end PKG_IdentEvalS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9457869A9E796092841972B12D9A4BEAA6D91519</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_IESIRI IS

DoCommit boolean := true;
CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_12&apos;;
ConstSelUtilaj INTEGER := 0;


PROCEDURE CHECK_MODIF_CARACT_MIFIX(aCODIES IN NUMBER)
IS
BEGIN
   FOR V_REC IN
   (
    SELECT
      LIV_MINUS.DATALIVR,
      I1.CODIES1,
      L_MINUS.CANT AS CANT_MINUS,
      L_MINUS.CODNIRSTOC AS CODNIRSTOC_MINUS,
      L_MINUS.CODNIRSER AS CODNIRSER_MINUS,
      L_PLUS.CANT AS CANT_PLUS,
      L_PLUS.CODNIRSTOC AS CODNIRSTOC_PLUS,
      L_PLUS.CODNIRSER AS CODNIRSER_PLUS,
      N.GEST,
      I.NRDOC
    FROM
      IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
      INNER JOIN LIVR1 L_MINUS ON  L_MINUS.CODIES1 = I1.CODIES1 AND L_MINUS.CANT &lt; 0
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L_MINUS.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
      INNER JOIN LIVR LIV_MINUS ON LIV_MINUS.CODLIVR = L_MINUS.CODLIVR AND LIV_MINUS.CODIES = I.CODIES
      INNER JOIN LIVR1 L_PLUS  ON  L_PLUS.CODIES1 = I1.CODIES1 AND L_PLUS.CANT &gt; 0
      INNER JOIN LIVR LIV_PLUS ON LIV_PLUS.CODLIVR = L_PLUS.CODLIVR AND LIV_PLUS.CODIES = I.CODIES
    WHERE
      I.CODIES = aCODIES
      AND TIPDOC = 15
      AND TIPTRANZACTIE = 2
      AND L_MINUS.CANT = -1
    )
    LOOP
      IF COALESCE(V_REC.CODNIRSER_MINUS, 0) &lt;&gt; 0 THEN -- articol cu serie
        FOR V_REC_M IN
       (SELECT *
        FROM
          MIFIX1 M1
        WHERE
          M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
          AND M1.CODNIRSTOC = V_REC.CODNIRSTOC_MINUS
          AND M1.CODNIRSER = V_REC.CODNIRSER_MINUS)
        LOOP
          UPDATE MIFIX1
          SET
            CODNIRSTOC = V_REC.CODNIRSTOC_PLUS,
            CODNIRSER  = V_REC.CODNIRSER_PLUS,
            CANT       = 1
          WHERE CODMIFIX1 = V_REC_M.CODMIFIX1;

          INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, CODDOC1, TIPDOC)
          VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC_M.CODMIFIX, 2, V_REC.DATALIVR, V_REC.GEST, V_REC.GEST, V_REC_M.PRET, V_REC_M.PRET, &apos;PV&apos;, V_REC.NRDOC, 1, V_REC.CODIES1, 15);

          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            CODDOC = V_REC_M.CODMIFIX
            AND TIPDOC = 36;

        END LOOP;
      ELSE
        FOR V_REC_M IN
       (SELECT *
        FROM
          MIFIX1 M1
        WHERE
          M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
          AND M1.CODNIRSTOC = V_REC.CODNIRSTOC_MINUS
          AND COALESCE(M1.CODNIRSER, 0) = 0
          AND ROWNUM = 1
         )
        LOOP
          UPDATE MIFIX1
          SET
            CODNIRSTOC = V_REC.CODNIRSTOC_PLUS,
            CODNIRSER  = V_REC.CODNIRSER_PLUS,
            CANT = 1
          WHERE
            CODMIFIX1 = V_REC_M.CODMIFIX1;

          INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, CODDOC1, TIPDOC)
          VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC_M.CODMIFIX, 1, V_REC.DATALIVR, V_REC.GEST, V_REC.GEST, V_REC_M.PRET, V_REC_M.PRET, &apos;PV&apos;, V_REC.NRDOC, 1, V_REC.CODIES1, 15);

          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            CODDOC = V_REC_M.CODMIFIX
            AND TIPDOC = 36;
        END LOOP;
      END IF;
    END LOOP;
END;

procedure GetEFACTURA(aCodIes in number, aTipIes in number)
IS
BEGIN
  DELETE TMP_StatusDecl;
  INSERT INTO TMP_StatusDecl
  SELECT * FROM StatusDecl WHERE CODDOC = aCODIES and TipDoc = aTipIes;
  COMMIT;
END;

PROCEDURE POSTEFACTURA
IS
  NR NUMBER;
  VCOD NUMBER;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_StatusDecl)
  LOOP
    SELECT COUNT(*) INTO NR FROM StatusDecl WHERE CODDOC = V_REC.CODDoc and TipDOC = V_REC.TipDoc ;
    IF NR = 0 THEN
      INSERT INTO StatusDecl( CodStatusDecl, CODDoc, TipDoc, IDINCARCARE, IDDESCARCARE, DATAINCARCARE, STARE,TIPMEDIU,
                              UserName, An, Luna, CompName, FileName ,MESAJE, CIF, SERIE_CERTIF, UIT)
      VALUES ( SEQ_StatusDecl.NEXTVAL, V_REC.CODDoc, V_REC.TipDoc, V_REC.IDINCARCARE, V_REC.IDDESCARCARE, V_REC.DATAINCARCARE, V_REC.STARE, V_REC.TIPMEDIU,
               V_REC.UserName, V_REC.An, V_REC.Luna, V_REC.CompName, V_REC.FileName, V_REC.MESAJE, V_REC.CIF, V_REC.SERIE_CERTIF, V_REC.UIT );
    ELSE
      UPDATE StatusDecl
      SET
       IDINCARCARE     = V_REC.IDINCARCARE,
       IDDESCARCARE    = V_REC.IDDESCARCARE,
       DATAINCARCARE   = V_REC.DATAINCARCARE,
       STARE           = V_REC.STARE     ,
       TIPMEDIU        = V_REC.TIPMEDIU  ,
       UserName        = V_REC.UserName  ,
       An              = V_REC.An        ,
       Luna            = V_REC.Luna      ,
       CompName        = V_REC.CompName ,
       FileName        = V_REC.FileName ,
       MESAJE          = V_REC.MESAJE,
       CIF             = V_REC.CIF,
       SERIE_CERTIF    = V_REC.SERIE_CERTIF,
       UIT             = V_REC.UIT
      WHERE
        CODDOC = V_REC.CODDoc and TipDOC = V_REC.TipDoc ;
    END IF;
    if (V_REC.TIPMEDIU = 2)and(Coalesce(V_REC.IDINCARCARE,&apos;?&apos;) &lt;&gt; &apos;?&apos;)and(V_REC.STARE = &apos;ok&apos; or V_REC.STARE = &apos;downloaded&apos;) then
      update Iesiri set Blocat = 1 where CodIes = v_rec.CodDoc and TipDoc = v_rec.Tipdoc;
    end if;
    if v_rec.stare = &apos;XML&apos; then
      for v_ies in (select CODIES FROM IESIRI WHERE CODIES = V_REC.CODDoc and TipDOC = V_REC.TipDoc) loop
        NotifyModif(3, V_ies.CODies, &apos;IESIRI&apos;);
      end loop;
    end if;
  END LOOP;
  COMMIT;
END;

PROCEDURE STERGE_STINGERI_TREZOR(aCODIES NUMBER)
IS
  NR NUMBER;
  aCODTREZOR NUMBER := 0;
BEGIN
FOR V_REC IN
(
select S.CODSTINGERE, S.VALOARE, O_S.CODGENERAL, O_S.CODOBLIGPIF, G_S.CODDOC
From
  GENERAL G,
  OBLIGPIF O
  LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
  LEFT JOIN OBLIGPIF O_S ON O_S.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL G_S ON G_S.CODGENERAL = O_S.CODGENERAL
WHERE
  G.TIPDOC IN( 19, 26)
  AND G.CODDOC = aCODIES
  AND O.CODGENERAL = G.CODGENERAL
)
LOOP
  DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;
  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  DELETE FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;
  SELECT COUNT(*) INTO NR FROM GENERAL  WHERE CODDOC = V_REC.CODDOC AND TIPDOC IN (29,30, 31);
  BEGIN
   SELECT CODTREZOR INTO aCODTREZOR FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;
   EXCEPTION WHEN OTHERS THEN
     aCODTREZOR := 0;
  END;

  UPDATE JURNAL1
  SET
    DIRTY = 1
  WHERE
    TIPDOC IN (29, 30, 31)
    AND CODDOC = aCODTREZOR;


  IF NR = 0 THEN
    DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;
  ELSE
    UPDATE TREZOR1
    SET
      VALDOC = VALDOC - V_REC.VALOARE
    WHERE
      CODTREZOR1 = V_REC.CODDOC;

  END IF;

  IF aCODTREZOR &lt;&gt; 0 THEN
    SELECT COUNT(*) INTO NR FROM TREZOR1 WHERE CODTREZOR = aCODTREZOR;
    IF NR = 0 THEN
      DELETE FROM TREZOR WHERE CODTREZOR = aCODTREZOR;
      DELETE FROM JURNAL1
      WHERE
        TIPDOC IN (29, 30, 31)
        AND CODDOC = aCODTREZOR;

      DELETE FROM JURNAL
      WHERE
        TIPDOC IN (29, 30, 31)
        AND CODDOC = aCODTREZOR;

    END IF;

  END IF;



END LOOP;
COMMIT;
END;

FUNCTION PRETVANZARE(TIPIES IN NUMBER, ROT IN NUMBER, PRET IN NUMBER, PARITATE IN NUMBER, OPERATIE IN NUMBER) RETURN NUMBER IS
  vPretV NUMERIC(20,7);
BEGIN
  vPretV := CASE
              WHEN OPERATIE = 0
              THEN PRET * PARITATE
              ELSE PRET / PARITATE
            END;

  IF PARITATE &lt;&gt; 1 AND ROT &gt; 0 AND TIPIES IN (19, 20, 21,26)  THEN
    vPretV := PKG_PRETURI.WMROTOPRET(ROT, vPretV);
  END IF;
  RETURN vPretV;
END;

procedure Test_GOTO
IS
BEGIN
  PKG_GLOBALS.SETUSERID(1); COMMIT;
  PKG_GLOBALS.setsubunitate(2); COMMIT;
  PKG_GLOBALS.SetLunaLucru(2019, 12);
  PKG_STOC_GENERARE_FACTURI.make_config_luna;
  PKG_IESIRI.SP_GOTORECORD(2189738);
END;




PROCEDURE CHECK_STERGERI_NIR(aCODIES NUMBER) IS
BEGIN
  FOR V_REC IN (
    SELECT CODNIRSTOC, CODINTR1, LIVRARI FROM
    (SELECT CODNIRSTOC, CODINTR1, COUNT(CODLIVR1) AS LIVRARI
    FROM
    (
    select NS.CODNIRSTOC, NS.CODINTR1, L1.CODLIVR1
    from
      nir n,
      nirstoc ns
      left join livr1 l1 on l1.codnirstoc = ns.codnirstoc
    where
      N.CODIES = aCODIES
      AND n.codnir = ns.codnir
    )
    GROUP BY CODNIRSTOC, CODINTR1
    )
    WHERE
      LIVRARI = 0
  ) LOOP
    DELETE FROM NIRSER WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1;
  END LOOP;

  FOR V_REC IN (
    SELECT CODNIR, CODINTR, COUNT(CODNIRSTOC) AS STOCURI
    FROM
    (
    select N.CODNIR, CODINTR, NS.CODNIRSTOC
    from
      nir N
      LEFT JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
    WHERE
      N.CODIES = aCODIES
    )
    GROUP BY CODNIR, CODINTR
    HAVING COUNT(CODNIRSTOC) = 0
  ) LOOP
      DELETE FROM NIR WHERE CODNIR = V_REC.CODNIR;
      DELETE FROM INTRARI WHERE CODINTR = V_REC.CODINTR;
    END LOOP;
END;





/*
PROCEDURE CHECK_STERGERI_NIR(aCODIES NUMBER) IS
BEGIN
  FOR V_REC IN (
    SELECT CODNIRSTOC, LIVRARI FROM
    (SELECT CODNIRSTOC, COUNT(CODLIVR1) AS LIVRARI
    FROM
    (
    select NS.CODNIRSTOC, L1.CODLIVR1
    from
      nir n,
      nirstoc ns
      left join livr1 l1 on l1.codnirstoc = ns.codnirstoc
    where
      N.CODIES = aCODIES
      AND n.codnir = ns.codnir
    )
    GROUP BY CODNIRSTOC
    )
    WHERE
      LIVRARI = 0
  ) LOOP
    DELETE FROM NIRSER WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  FOR V_REC IN (
    SELECT CODNIR, COUNT(CODNIRSTOC) AS STOCURI
    FROM
    (
    select N.CODNIR, NS.CODNIRSTOC
    from
      nir N
      LEFT JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
    WHERE
      N.CODIES = aCODIES
    )
    GROUP BY CODNIR
    HAVING COUNT(CODNIRSTOC) = 0
  ) LOOP
    DELETE FROM NIR WHERE
    CODNIR = V_REC.CODNIR;
  END LOOP;
END;
*/

PROCEDURE REFA_CENTRALIZARI_PE_MONETAR(aCODMONETAR IN NUMBER)
IS
BEGIN


  FOR V_REC IN
   (SELECT M.CODIES AS CODMONETAR
   FROM
     IESIRI M
  WHERE
    M.CODIES = aCODMONETAR
  )
  LOOP
    DELETE FROM TVAMONETAR WHERE CODIES = V_REC.CODMONETAR;
    UPDATE IESIRI
    SET
      NRINCASIM  = 0,
      NRINFOCM   = 0,
      NRINCASULT = 0
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP;




  FOR V_REC IN
  (
  SELECT
    I.CODMONETAR,
    COUNT(*) AS NRInfoCM
  FROM
    IESIRI I
  WHERE
    nvl(I.codmonetar, 0)= aCODMONETAR
    AND  nvl(I.infocm, 0) = 1
  GROUP BY I.CODMONETAR
  )
  LOOP
    UPDATE IESIRI
    SET
      NRINFOCM = V_REC.NRINFOCM
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP  ;

  FOR V_REC IN
  (
  SELECT
    I.CODMONETAR,
    COUNT(*) AS NRIncasIm
  FROM
    IESIRI I
  WHERE
    nvl(I.codmonetar, 0) = aCODMONETAR
    AND nvl(I.TIPFACTURA, 0) = 7
  GROUP BY I.CODMONETAR
  )
  LOOP
    UPDATE IESIRI
    SET
      NRINCASIM = V_REC.NRINCASIM
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP  ;

  FOR V_REC IN
  (
  SELECT
    CODMONETAR,
    COUNT(*) AS NRINCASULT
  FROM
  (
  SELECT DISTINCT
     E.CODMONETAR,
     E.CODEMULARE
   FROM
    EMULSTINGERI ES,
    EMULARE E
   WHERE
   (SELECT COUNT(*) FROM EMULARE1 E1 WHERE E1.CODEMULARE = ES.CODEMULARE AND NVL(E1.CODEMULSTINGERE, 0)=0 )=0
   AND E.CODEMULARE = ES.CODEMULARE
   AND EXTRACT(YEAR FROM E.DATABON)  = PKG_GLOBALS.ANLUCRU
   AND EXTRACT(MONTH FROM E.DATABON) = PKG_GLOBALS.LUNALUCRU
  )
  GROUP BY CODMONETAR
  )
  LOOP
      UPDATE IESIRI
    SET
      NRINCASULT = V_REC.NRINCASULT
    WHERE
      CODIES = V_REC.CODMONETAR;

  END LOOP;

/* MUTAT LA INCEPUT
  FOR V_REC IN
   (SELECT DISTINCT I.CODMONETAR
   FROM
     IESIRI I,
     IESIRI M
  WHERE
    NVL(I.CODMONETAR, 0) &lt;&gt; 0
    AND I.CODMONETAR = M.CODIES
    AND (NVL(I.INFOCM, 0) = 1 OR NVL(I.TIPFACTURA, 0) = 7)
    AND M.AN   = PKG_GLOBALS.ANLUCRU
    AND M.LUNA = PKG_GLOBALS.LUNALUCRU
  )
  LOOP
    DELETE FROM TVAMONETAR WHERE CODIES = V_REC.CODMONETAR;
  END LOOP;
*/



  FOR V_REC IN
  (
  SELECT
    CODMONETAR,
    PROCENT,
    CODTVA,
    SUM(VALOARE) AS VALOARE,
    SUM(TVA) AS TVA
  FROM
  (
  SELECT
    I.CODMONETAR,
    TAL.PROCENT,
    AL.CODTVA,
--    (I1.CANT * I1.PU + I1.TVA) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 ) AS VALOARE,
--    I1.TVA * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 ) AS TVA
    CASE
      WHEN NVL(I1.COEFDISCMAJ, 1) = 1 AND ABS(NVL(I1.PROCDISC, 0)) + ABS(NVL(I1.PROCDISC, 0)) &lt;&gt; 0
          THEN (I1.CANT * I1.PRETORIG + TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100 ) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 )
      WHEN NVL(I1.COEFDISCMAJ, 1) &lt;&gt; 1 THEN (I1.CANT * I1.PRETORIG + TAL.PROCENT *(I1.CANT * I1.PRETORIG)/ 100) * I1.COEFDISCMAJ
      ELSE I1.CANT * I1.PU + I1.TVA
    END AS VALOARE,
    CASE
      WHEN NVL(I1.COEFDISCMAJ, 1) = 1 AND ABS(NVL(I1.PROCDISC, 0)) + ABS(NVL(I1.PROCDISC, 0)) &lt;&gt; 0
          THEN (TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 )
      WHEN NVL(I1.COEFDISCMAJ, 1) &lt;&gt; 1 THEN (TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100) * I1.COEFDISCMAJ
      ELSE I1.TVA
    END AS TVA
  FROM
     IESIRI I,
     IESIRI1 I1,
     NARTOBJ O,
     TMP_NART_LUNA AL,
     TMP_NTVA_LUNA TAL
  WHERE
    NVL(I.CODMONETAR, 0) =  aCODMONETAR
    AND (NVL(I.INFOCM, 0) = 1 OR NVL(I.TIPFACTURA, 0) = 7)
    AND I.CODIES = I1.CODIES
    AND I1.CODOBIECT = O.CODOBIECT
    AND AL.CODARTICOL = O.CODARTICOL
    AND AL.CODTVA = TAL.CODTVA
    )
  GROUP BY CODMONETAR, PROCENT, CODTVA
  )
  LOOP
    INSERT INTO TVAMONETAR(CODTVAMONETAR, CODIES, CODTVA, VALOARE, TVA)
    VALUES (SEQ_TVAMONETAR_CODTVAMONETAR.NEXTVAL, V_REC.CODMONETAR,V_REC.CODTVA,  V_REC.VALOARE, V_REC.TVA);

  END LOOP;
END;



PROCEDURE ANULEAZA_FACTURA(aCODIES IN NUMBER)
IS
BEGIN
  UPDATE IESIRI
  SET
    ANULAT = 1,
    OPERAT = 0,
    BLOCAT = 0
  WHERE
    CODIES = aCODIES;

  FOR V_REC IN (SELECT L1.* FROM LIVR1 L1, LIVR L WHERE L.CODIES = aCODIES AND L1.CODLIVR = L.CODLIVR)
  LOOP
    UPDATE NIRSTOC  SET REST = REST + V_REC.CANT
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;

    DELETE FROM LIVR1 WHERE CODLIVR1 = V_REC.CODLIVR1;
  END LOOP;

  DELETE FROM LIVR WHERE CODIES = aCODIES;

  FOR V_REC IN (SELECT * FROM GENERAL G WHERE G.CODDOC  = aCODIES AND G.TIPDOC = 19)
  LOOP
    DELETE FROM OBLIGPIF WHERE CODGENERAL = V_REC.CODGENERAL;
    DELETE FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

  UPDATE JURNAL1
  SET
     DIRTY = 1
  WHERE
    TIPDOC = 19 AND CODDOC = aCODIES;
  COMMIT;
END;

PROCEDURE PREPARE_AVIZE_CLIENTI(aCODPART IN NUMBER, ANLUNALUCRU IN NUMBER)
IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE MAN_IESIRI&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE MAN_IESIRI1&apos;;


  INSERT INTO MAN_IESIRI
  SELECT II.*
  FROM
    IESIRI II WHERE
  EXISTS
  (
  SELECT &apos;X&apos;
  FROM
    IESIRI I,
    IESIRI1 I1
    LEFT JOIN TMP_IESLINK_INITIAL IL_INI ON IL_INI.CODLINIEAVIZ = I1.CODIES1
  WHERE
    PARTENER = aCODPART
    AND I1.CODIES = I.CODIES
    AND I.AN * 12 + I.LUNA &lt;=  AnLunaLucru
    AND TIPDOC = 20
    AND I1.TIPLINIE &lt;&gt; &apos;T&apos;
    AND I1.TIPLINIE &lt;&gt; &apos;G&apos;
    AND NVL(I1.CODIES1STORNO, 0) = 0
    AND NVL(I1.CUSTODIEINTRARE, 0) = 0
    AND ((I1.RESTFACT &lt;&gt; 0) OR ((I1.RESTFACT = 0) AND  NVL(IL_INI.CODLINIEAVIZ, 0) &lt;&gt; 0))
    AND II.CODIES = I.CODIES
  );

  INSERT INTO MAN_IESIRI1
  SELECT * FROM IESIRI1 I1 WHERE EXISTS (SELECT CODIES FROM MAN_IESIRI MI WHERE MI.CODIES = I1.CODIES );

END;

PROCEDURE REFA_CENTRALIZARI_PE_MONETARE
IS
BEGIN


  FOR V_REC IN
   (SELECT M.CODIES AS CODMONETAR
   FROM
     IESIRI M
  WHERE
    M.TIPDOC = 16
    AND M.AN   = PKG_GLOBALS.ANLUCRU
    AND M.LUNA = PKG_GLOBALS.LUNALUCRU
  )
  LOOP
    DELETE FROM TVAMONETAR WHERE CODIES = V_REC.CODMONETAR;
    UPDATE IESIRI
    SET
      NRINCASIM  = 0,
      NRINFOCM   = 0,
      NRINCASULT = 0
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP;




  FOR V_REC IN
  (
  SELECT
    I.CODMONETAR,
    COUNT(*) AS NRInfoCM
  FROM
    IESIRI I,
    IESIRI M
  WHERE
    nvl(I.codmonetar, 0) &lt;&gt; 0
    AND I.CODMONETAR = M.CODIES
    AND  nvl(I.infocm, 0) = 1
    AND M.AN = PKG_GLOBALS.ANLUCRU
    AND M.LUNA = PKG_GLOBALS.LUNALUCRU
  GROUP BY I.CODMONETAR
  )
  LOOP
    UPDATE IESIRI
    SET
      NRINFOCM = V_REC.NRINFOCM
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP  ;

  FOR V_REC IN
  (
  SELECT
    I.CODMONETAR,
    COUNT(*) AS NRIncasIm
  FROM
    IESIRI I,
    IESIRI M
  WHERE
    nvl(I.codmonetar, 0) &lt;&gt; 0
    AND M.CODIES = I.CODMONETAR
    AND nvl(I.TIPFACTURA, 0) = 7
    AND M.AN = PKG_GLOBALS.ANLUCRU AND M.LUNA = PKG_GLOBALS.LUNALUCRU
  GROUP BY I.CODMONETAR
  )
  LOOP
    UPDATE IESIRI
    SET
      NRINCASIM = V_REC.NRINCASIM
    WHERE
      CODIES = V_REC.CODMONETAR;
  END LOOP  ;

  FOR V_REC IN
  (
  SELECT
    CODMONETAR,
    COUNT(*) AS NRINCASULT
  FROM
  (
  SELECT DISTINCT
     E.CODMONETAR,
     E.CODEMULARE
   FROM
    EMULSTINGERI ES,
    EMULARE E
   WHERE
   (SELECT COUNT(*) FROM EMULARE1 E1 WHERE E1.CODEMULARE = ES.CODEMULARE AND NVL(E1.CODEMULSTINGERE, 0)=0 )=0
   AND E.CODEMULARE = ES.CODEMULARE
   AND EXTRACT(YEAR FROM E.DATABON)  = PKG_GLOBALS.ANLUCRU
   AND EXTRACT(MONTH FROM E.DATABON) = PKG_GLOBALS.LUNALUCRU
  )
  GROUP BY CODMONETAR
  )
  LOOP
      UPDATE IESIRI
    SET
      NRINCASULT = V_REC.NRINCASULT
    WHERE
      CODIES = V_REC.CODMONETAR;

  END LOOP;

/* MUTAT LA INCEPUT
  FOR V_REC IN
   (SELECT DISTINCT I.CODMONETAR
   FROM
     IESIRI I,
     IESIRI M
  WHERE
    NVL(I.CODMONETAR, 0) &lt;&gt; 0
    AND I.CODMONETAR = M.CODIES
    AND (NVL(I.INFOCM, 0) = 1 OR NVL(I.TIPFACTURA, 0) = 7)
    AND M.AN   = PKG_GLOBALS.ANLUCRU
    AND M.LUNA = PKG_GLOBALS.LUNALUCRU
  )
  LOOP
    DELETE FROM TVAMONETAR WHERE CODIES = V_REC.CODMONETAR;
  END LOOP;
*/



  FOR V_REC IN
  (
  SELECT
    CODMONETAR,
    PROCENT,
    CODTVA,
    SUM(VALOARE) AS VALOARE,
    SUM(TVA) AS TVA
  FROM
  (
  SELECT
    I.CODMONETAR,
    TAL.PROCENT,
    AL.CODTVA,
--    (I1.CANT * I1.PU + I1.TVA) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 ) AS VALOARE,
--    I1.TVA * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 ) AS TVA
    CASE
      WHEN NVL(I1.COEFDISCMAJ, 1) = 1 AND ABS(NVL(I1.PROCDISC, 0)) + ABS(NVL(I1.PROCDISC, 0)) &lt;&gt; 0
          THEN (I1.CANT * I1.PRETORIG + TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100 ) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 )
      WHEN NVL(I1.COEFDISCMAJ, 1) &lt;&gt; 1 THEN (I1.CANT * I1.PRETORIG + TAL.PROCENT *(I1.CANT * I1.PRETORIG)/ 100) * I1.COEFDISCMAJ
      ELSE I1.CANT * I1.PU + I1.TVA
    END AS VALOARE,
    CASE
      WHEN NVL(I1.COEFDISCMAJ, 1) = 1 AND ABS(NVL(I1.PROCDISC, 0)) + ABS(NVL(I1.PROCDISC, 0)) &lt;&gt; 0
          THEN (TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100) * ((100 - ABS(NVL(I1.PROCDISC, 0))) / 100 ) * ((100 - ABS(NVL(I1.ADDIM, 0))) / 100 )
      WHEN NVL(I1.COEFDISCMAJ, 1) &lt;&gt; 1 THEN (TAL.PROCENT *(I1.CANT * I1.PRETORIG) / 100) * I1.COEFDISCMAJ
      ELSE I1.TVA
    END AS TVA
  FROM
     IESIRI I,
     IESIRI M,
     IESIRI1 I1,
     NARTOBJ O,
     TMP_NART_LUNA AL,
     TMP_NTVA_LUNA TAL
  WHERE
    NVL(I.CODMONETAR, 0) &lt;&gt; 0
    AND I.CODMONETAR = M.CODIES
    AND (NVL(I.INFOCM, 0) = 1 OR NVL(I.TIPFACTURA, 0) = 7)
    AND I.CODIES = I1.CODIES
    AND I1.CODOBIECT = O.CODOBIECT
    AND AL.CODARTICOL = O.CODARTICOL
    AND AL.CODTVA = TAL.CODTVA
    AND M.AN = PKG_GLOBALS.ANLUCRU AND M.LUNA = PKG_GLOBALS.LUNALUCRU)
  GROUP BY CODMONETAR, PROCENT, CODTVA
  )
  LOOP
    INSERT INTO TVAMONETAR(CODTVAMONETAR, CODIES, CODTVA, VALOARE, TVA)
    VALUES (SEQ_TVAMONETAR_CODTVAMONETAR.NEXTVAL, V_REC.CODMONETAR,V_REC.CODTVA,  V_REC.VALOARE, V_REC.TVA);

  END LOOP;
END;


FUNCTION GETPROCTVALINIE(aCODLINIEDOCIMP IN NUMBER, PROCTVAIMPLICIT IN NUMBER) RETURN NUMBER
IS
 aPROCTVA NUMBER(20, 7 );
 aAN      NUMBER(5);
 aLUNA    NUMBER(2);
 ANINI    NUMBER(5);
 LUNAINI  NUMBER(2);
BEGIN
  aPROCTVA := PROCTVAIMPLICIT;

  BEGIN
  SELECT
    I.AN, I.LUNA INTO aAN, aLUNA
  FROM
    IESIRI1 I1,
    IESIRI I,
    NARTOBJ O
  WHERE
    I1.CODIES1 = aCODLINIEDOCIMP
    AND I1.CODOBIECT = O.CODOBIECT
    AND I.CODIES = I1.CODIES;
    EXCEPTION WHEN OTHERS THEN aAN := 0; aLUNA := 0;
  END;

  SELECT ANINITIAL, LUNAINITIALA INTO ANINI, LUNAINI FROM FIRMALUNI;

  IF aAN * 12 + aLUNA &lt; ANINI * 12 + LUNAINI  THEN
    aAN := ANINI; aLUNA := LUNAINI;
  END IF;



  BEGIN
  SELECT
    PKG_SELECTARTICOLE.GETPROCENTTVA(O.CODARTICOL, aAN, aLUNA) INTO aProcTVA
  FROM
    IESIRI1 I1,
    IESIRI I,
    NARTOBJ O
  WHERE
    I1.CODIES1 = aCODLINIEDOCIMP
    AND I1.CODOBIECT = O.CODOBIECT
    AND I.CODIES = I1.CODIES;
    EXCEPTION WHEN OTHERS THEN aPROCTVA := PROCTVAIMPLICIT;
  END;

  RETURN aPROCTVA;
END;

PROCEDURE Actualizeaza_CodContract1 IS
  vDataDoc   DATE;
  vCodContr  NUMBER(20);
  vDataStart DATE;
  vDataStop  DATE;
BEGIN
  SELECT c.codcontract, c.datastart, c.datastop, i.datadoc
  INTO   vCodContr,     vDataStart,  vDataStop,  vDataDoc
  FROM tmp_iesiri i LEFT JOIN contract c ON c.codcontract = i.codcontract;

  IF vCodContr IS NOT NULL THEN
    UPDATE tmp_iesiri1 i1
    SET i1.codcontract1 =
        (
          SELECT Max(C1.CodContract1) KEEP (Dense_Rank Last ORDER BY Nvl(C1.DataStart,vDataStart))
          FROM Contract1 C1
          WHERE C1.CodContract = vCodContr
            AND c1.codobiect = i1.codobiect
            AND Nvl(C1.DataStart,vDataStart) &lt;= vDataDoc
            AND Nvl(C1.DataStop,vDataStop) &gt;= vDataDoc
        )
    WHERE Nvl(i1.codcontract1,0) = 0 AND I1.tiplinie IN (&apos;=&apos;,&apos;S&apos;);
  END IF;
EXCEPTION
  WHEN OTHERS THEN NULL;
END;

PROCEDURE Repara_TMP_Iesiri_OBS IS
-- doar pentru Oracle - din cauza caracterelor Multibyte pana reusim sa modificam OBS -&gt; NVARCHAR2
BEGIN
  UPDATE TMP_IESIRI
  SET OBS = CASE
              WHEN LengthB(obs) &lt;= 500 THEN Obs
              WHEN InStrB(obs, &apos;&lt;EF&apos;) = 0 THEN SubStrB(OBS, 1, 500)
              ELSE SubStrB(OBS, 1, Greatest(0, 500 - LengthB(SubStrB(OBS, InStrB(obs, &apos;&lt;EF&apos;))), 0)) || SubStrB(OBS, InStrB(obs, &apos;&lt;EF&apos;))
            END
  WHERE LengthB(OBS) &gt; 500;
END;

PROCEDURE CHECK_COERENTA_NIRNOU_MF(aCODDOC IN NUMBER, aTIPDOC IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN
  (
  SELECT
    MF1.codmifix1,
    MF1.codmifix,
    MF1.pret,
    ns.pret AS PRETNIRSTOC,
    MF1.ANSTART,
    MF1.LUNASTART
  FROM
    NIRSTOC NS, NIR N, MIFIX1 MF1
  WHERE
    N.CODIES = aCODDOC
    AND N.TIPNIR = aTIPDOC
    AND NS.CODNIR = N.CODNIR
    AND MF1.CODNIRSTOC = NS.CODNIRSTOC
    AND MF1.ANSTART * 12 + MF1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12  + PKG_GLOBALS.LUNALUCRU
    AND MF1.PRET &lt;&gt; NS.PRET
   )
   LOOP
     UPDATE MIFIX1
     SET
       PRET = V_REC.PRETNIRSTOC
     WHERE
       CODMIFIX1 = V_REC.CODMIFIX1;

     UPDATE JURNAL1
     SET
       DIRTY = 1
     WHERE
       TIPDOC = 36 AND CODDOC = V_REC.CODMIFIX AND AN = V_REC.ANSTART AND LUNA = V_REC.LUNASTART;
   END LOOP;
   COMMIT;
END;

PROCEDURE SOLVE_OBINV(aCODIES IN NUMBER, aCODCLASIF IN NUMBER )
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
  aTIPAMO   NUMBER(1);
BEGIN
  CODCLASIF_MASTER := aCODCLASIF;
  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipAmoOI&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipAmo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aTIPAMO := 1;
  END;



  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       PRET,
       REST
      FROM
        NIRSTOC NS,
        NIR N,
        TMP_IOART_LUNA IOLUNA
      WHERE
        N.CODIES = aCODIES
        AND NS.CODNIR = N.CODNIR
        AND IOLUNA.CODIOART = NS.CODIOART
        AND IOLUNA.ESTEOBINV &gt; 0
     )
   LOOP
     SELECT NVL(SUM(CANT), 0) INTO REZOLVAT
     FROM
       MIFIX1 MF
     WHERE
       MF.CODNIRSTOC = V_REC.CODNIRSTOC
       AND MF.ANSTART * 12 + MF.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


     IF REZOLVAT &lt; V_REC.REST THEN
       BEGIN
         SELECT NVL(CODCLASIF, 0) INTO CODCLASIF_MASTER FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN CODCLASIF_MASTER := 0;
       END;

       IF CODCLASIF_MASTER = 0 THEN CODCLASIF_MASTER := aCODCLASIF;
       END IF;

       BEGIN
         SELECT DURATA INTO aDURATAN FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
       END;


       IF aDURATAN &gt; 0 THEN

         SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         IF NR = 0 THEN
           INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN)
           VALUES (V_REC.CODNIRSTOC, CODCLASIF_MASTER, aDURATAN);
         END IF;

         SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

         INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE )
         VALUES (aCODMIFIX, &apos;OI&apos;, PKG_MIFIX.GetNextNrInv(&apos;OI&apos;), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

         INSERT INTO MIFIX1(CODMIFIX1,
                            CODMIFIX,
                            CODNIRSTOC,
                            PRET,
                            CANT,
                            CODCLASIF,
                            TIPAMO,
                            STARE,
                            DURATAN,
                            GRADU,
                            DURATAF,
                            AMO,
                            DFBLOCAT,
                            ANSTART,
                            LUNASTART,
                            DFBLOCAT_F,
                            DFBLOCAT_G)
         VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
                aCODMIFIX,
                V_REC.CODNIRSTOC,
                V_REC.PRET,
                V_REC.REST - REZOLVAT,
                CODCLASIF_MASTER,
                aTIPAMO,
                1,
                aDURATAN,
                100,
                0,
                (V_REC.REST - REZOLVAT) * V_REC.PRET,
                1,
                PKG_GLOBALS.ANLUCRU,
                PKG_GLOBALS.LUNALUCRU,
                1,
                1);

       END IF;
     END IF;


   END LOOP;
   COMMIT;

END;

PROCEDURE SOLVE_DIMINUARE_OBINV(aCODIES IN NUMBER )
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
BEGIN
  FOR V_REC IN (
    SELECT
       NS.CODNIRSTOC
      FROM
        LIVR L,
        LIVR1 L1,
        NIRSTOC NS,
        TMP_IOART_LUNA IOLUNA
      WHERE
        L.CODIES = aCODIES
        AND L1.CODLIVR = L.CODLIVR
        AND NS.CODNIRSTOC = L1.CODNIRSTOC
        AND IOLUNA.CODIOART = NS.CODIOART
        AND NS.REST = 0
        AND IOLUNA.ESTEOBINV &gt; 0
     )
   LOOP
      FOR V_REC_MF IN
       (
           SELECT CODMIFIX1
           FROM
             MIFIX1 MF
           WHERE
             MF.CODNIRSTOC = V_REC.CODNIRSTOC
             AND MF.STARE &lt;&gt; 3
             AND MF.ANSTART * 12 + MF.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU

       )
      LOOP
         UPDATE MIFIX1
         SET
           STARE = 3
         WHERE
           CODMIFIX1 = V_REC_MF.CODMIFIX1;
      END LOOP;
   END LOOP;
   COMMIT;
END;



PROCEDURE MAKE_LIVRARI_AVIZE
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_LIVR1_MAT;
  DELETE TMP_LIVRTOT_MAT;

  INSERT INTO TMP_LIVR1_MAT
     ( CODLIVR1,
       CODLIVR,
       CODIES1,
       CODNIRSTOC,
       CANT,
       CODNIRSER,
       PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC,
       UMSEC,
       CANTUM1,
       CANTUM2,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CODOBIECT,
       CODLIVRTOT,
       PRETINREG,
       PRETACHIZ,
       TVANEEX,
       CANTREZERVAT,
       CODPRODCOMP,
       CodCertif,
       CONTINTERMED,
       CODGESTORIG, CODPROIECT,
       PROVIZION,
       BLOCATUM1,
       TIPSERIE,
       CODSERIE
      )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODIES1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CODNIRSER,
         L1.PMP, L1.PMPDOC, L1.PMPVALUTA,L1.PMPVALUTADOC,
         L1.UMSEC,
         L1.CANTUM1,
         L1.CANTUM2,
         U1.DEN_UM1,
         U1.PARITATE,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,
         0,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NVL(NS.ADAOS, 0)) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,
         L1.CANTREZERVAT / U1.PARITATE,
         L1.CODPRODCOMP,
         L1.Codcertif,
         L1.CONTINTERMED,
         L1.CODGESTORIG,
         L1.CODPROIECT,
         NS.PROVIZION,
         L1.BLOCATUM1,
         NS.TIPSERIE,
        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         L.TIPLIVR = 20
         AND L1.CODIES1 IN (SELECT CODUNIC FROM TMP_MANEVRA)
         AND U1.CODUM1 = L1.UMSEC
     );

  INSERT INTO TMP_LIVRTOT_MAT
   (CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC,  GEST, CODIOART, CONTINTERMED,CODPROIECT, CODOBIECT, DENUM, PARITATE, DENGESTIOART, DIFPRET, ACCIZELATRANSFER, ARETVANEEX, MG, CONT, SUFIXTVANEEX, CODPRODCOMP, STOCREZOLVAT, CANT, PRETINREG, PRETACHIZ, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC)

  SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODIES1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),
         NVL(L1.CODPROIECT, 0),
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ACCIZELATRANSFER,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         L1.CODPRODCOMP,
         1,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMP       * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPDOC    * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPVALUTA * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPVALUTADOC * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT))

--       SUM(L1.PRETINREG * L1.CANT) / SUM(L1.CANT),
--       SUM(L1.PRETACHIZ * L1.CANT) / SUM(L1.CANT)
       FROM TMP_LIVR1_MAT L1
         LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
         LEFT JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
         LEFT JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT JOIN IOART IO ON IO.CODIOART = L1.CODIOART
       GROUP BY
         0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),
         NVL(L1.CODPROIECT, 0),
         L1.DENUM,
         L1.PARITATE ,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET,  IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG,
         IOALUNA.CONT, IOALUNA.TVANEEX, L1.CODPRODCOMP
     )
  ORDER BY CODLIVR, CODIES1;

     UPDATE TMP_LIVRTOT_MAT T
     SET
       CODLIVRTOT      = ROWNUM,
       ARETG           = (SELECT ARETG FROM NART A, NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT AND A.CODARTICOL = O.CODARTICOL),
       (UM1, UM2, RELATIEUM1, TIPSERIE) = (SELECT UM1, UM2, RELATIEUM1, TIPSERIE FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
       PROCTVA         = PKG_SELECTARTICOLE.GETPROCENTTVA
                      (PKG_SELECTARTICOLE.GETArtOfObject(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);



     UPDATE TMP_LIVR1_MAT L1
     SET
       CODLIVRTOT = ( SELECT CODLIVRTOT FROM TMP_LIVRTOT_MAT
                      WHERE
                        NVL(CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
                        NVL(CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
                        NVL(UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
                        NVL(PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
                        NVL(GEST, 0)         = NVL(L1.GEST, 0)     AND
                        NVL(CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
                        NVL(CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0)
                    ),
        ADAOS  = PRETINREG - PRETACHIZ,
        (PROCENTADAOS, D1, D2, D3)   = (SELECT PROCENTADAOS, D1, D2, D3 FROM NIRSTOC WHERE CODNIRSTOC = L1.CODNIRSTOC),
       (TG, DATAACHIZ) = (SELECT NVL(NSE.TG, NS.TG), NS.DATAACHIZ
                        FROM
                          LIVR1 LL1
                          LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSER = LL1.CODNIRSER,
                          NIRSTOC NS
                        WHERE
                         LL1.CODLIVR1 = L1.CODLIVR1
                         AND NS.CODNIRSTOC = LL1.CODNIRSTOC
                        );


COMMIT;
END;



PROCEDURE Service_Preluat IS
aNR number;
begin
  update Iesiri1 set preluat = 0;

  update Iesiri set TipFactura = 0 where TipFactura = 8;
  for v_rec in
    ( select distinct I.CodIes
      from CANTAR C
           inner join Iesiri1 I1 on I1.CodIes1 = C.CodDoc1
           inner join Iesiri I on I.CodIes = I1.CodIes and I.TipDoc = C.TipDoc
    ) loop
    update Iesiri set TipFactura = 8 where CodIes = v_Rec.CodIes;
  end loop;
  for v_rec in
    ( select i1.CodIes1 CodDoc1, I.TipDoc
      from Iesiri1 i1
           inner join Iesiri I on I.CodIes = I1.CodIes
           where I.TipFactura = 8
    ) loop
    select Count(*) into aNR from CANTAR where TipDoc = v_rec.TipDoc and CodDoc1 = v_Rec.CodDoc1;
    if aNr &gt; 0  then
      update Iesiri1 set preluat = 1 where CodIes1 = v_Rec.CodDoc1;
    end if;
  end loop;

  update Iesiri set TipFactura = 0 where TipFactura = 11;
  for v_rec in
    ( select distinct I.CodIes
      from BCAR B
           inner join Iesiri1 I1 on I1.CodIes1 = B.CodDoc1
           inner join Iesiri I on I.CodIes = I1.CodIes and I.TipDoc = B.TipDoc
    ) loop
    update Iesiri set TipFactura = 11 where CodIes = v_Rec.CodIes;
  end loop;
  for v_rec in
    ( select i1.CodIes1 CodDoc1, I.TipDoc
      from Iesiri1 i1
           inner join Iesiri I on I.CodIes = I1.CodIes
           where I.TipFactura = 11
    ) loop
    select Count(*) into aNR from BCAR where TipDoc = v_rec.TipDoc and CodDoc1 = v_Rec.CodDoc1;
    if aNr &gt; 0  then
      update Iesiri1 set preluat = 2 where CodIes1 = v_Rec.CodDoc1;
    end if;
  end loop;

  commit;
end;

FUNCTION CONDITIE_FACTURA_OPERATA(aOPERAT IN NUMBER, aConstValue in NUMBER) RETURN NUMBER
IS
BEGIN
  IF aCONSTVALUE = 1 THEN RETURN 1;
  ELSE
    RETURN aOPERAT;
  END IF;
END;

PROCEDURE PREIA_ATASAMENTE_COMENZI(aCODDOC IN NUMBER, aTIPDOC IN NUMBER)
IS
 NR NUMBER(5) := 0;
BEGIN
  FOR V_REC IN
  (
  SELECT DISTINCT D.CODDOCUMENT, D.FILENAME, D.OBS
  FROM
    IESIRI I,
    IESIRI1 I1,
    IESLINK IL,
    COMANDA1 C1,
    COMANDA C,
    DOCUMENTE D
  WHERE
    I.CODIES = aCODDOC
    AND I1.CODIES = I.CODIES
    AND IL.CODIES1 = I1.CODIES1
    AND C1.CODCOMANDA1 = IL.CODLINIECOMANDA
    AND C.CODCOMANDA = C1.CODCOMANDA
    AND D.TIPDOC = C.TIPDOC
    AND D.CODDOC = C.CODCOMANDA
  )
  LOOP
    SELECT COUNT(*) INTO NR FROM DOCUMENTE WHERE TIPDOC = aTIPDOC AND CODDOC = aCODDOC AND FILENAME = V_REC.FILENAME;
    IF NR = 0 THEN
      INSERT INTO DOCUMENTE(CODDOCUMENT, CODDOC, TIPDOC, FILENAME, DOC, OBS)
      SELECT SEQ_DOCUMENTE_CODDOCUMENT.NEXTVAL, aCODDOC, aTIPDOC, V_REC.FILENAME, (SELECT DOC FROM DOCUMENTE WHERE CODDOCUMENT = V_REC.CODDOCUMENT), V_REC.OBS FROM DUAL;
    END IF;
  END LOOP;
  COMMIT;
END;



PROCEDURE CHECK_REZERVARI_CLONARE_IN
IS
BEGIN
FOR V_REC IN
(
  SELECT
   L1MINUS.CODNIRSTOC AS CODNIRSTOC_MINUS,
   L1MINUS.CODNIRSER  AS CODNIRSER_MINUS,
   L1PLUS.CODNIRSTOC AS CODNIRSTOC_PLUS,
   L1PLUS.CODNIRSER  AS CODNIRSER_PLUS,
   L1PLUS.CANT
  FROM
  (
  SELECT
  CODIES1
  FROM
   IESIRI1_MAN I1
  WHERE
   NVL(CANT, 0) = 0
   AND (SELECT COUNT(*) FROM TMP_LIVR1_INITIAL L1 WHERE  L1.CODIES1 = I1.CODIES1 AND L1.CANT &lt; 0)  =
       (SELECT COUNT(*) FROM TMP_LIVR1_INITIAL L1 WHERE  L1.CODIES1 = I1.CODIES1 AND L1.CANT &gt; 0)
  )I1STORNO,
   TMP_LIVR1_INITIAL L1PLUS,
   TMP_LIVR1_INITIAL L1MINUS
  WHERE
   L1PLUS.CANT &gt; 0 AND L1PLUS.CODIES1 = I1STORNO.CODIES1
   AND  L1MINUS.CANT &lt; 0 AND L1MINUS.CODIES1 = I1STORNO.CODIES1
)
LOOP
 PKG_MISCARI_INTERNE.CHECK_REZERVARI(V_REC.CODNIRSTOC_PLUS,
                                     V_REC.CODNIRSER_PLUS,
                                     V_REC.CODNIRSTOC_MINUS,
                                     V_REC.CODNIRSER_MINUS,
                                     V_REC.CANT
                                    );

END LOOP;


END;


PROCEDURE CHECK_REZERVARI_CLONARE_OUT
IS
BEGIN
FOR V_REC IN
(
  SELECT
   L1MINUS.CODNIRSTOC AS CODNIRSTOC_MINUS,
   L1MINUS.CODNIRSER  AS CODNIRSER_MINUS,
   L1PLUS.CODNIRSTOC AS CODNIRSTOC_PLUS,
   L1PLUS.CODNIRSER  AS CODNIRSER_PLUS,
   L1PLUS.CANT
  FROM
  (
  SELECT
  CODIES1
  FROM
   TMP_IESIRI1 I1
  WHERE
   NVL(CANT, 0) = 0
   AND (SELECT COUNT(*) FROM TMP_LIVR1_INITIAL L1 WHERE  L1.CODIES1 = I1.CODIES1 AND L1.CANT &lt; 0)  =
       (SELECT COUNT(*) FROM TMP_LIVR1_INITIAL L1 WHERE  L1.CODIES1 = I1.CODIES1 AND L1.CANT &gt; 0)
  )I1STORNO,
   TMP_LIVR1 L1PLUS,
   TMP_LIVR1 L1MINUS
  WHERE
   L1PLUS.CANT &gt; 0 AND L1PLUS.CODIES1 = I1STORNO.CODIES1
   AND  L1MINUS.CANT &lt; 0 AND L1MINUS.CODIES1 = I1STORNO.CODIES1
)
LOOP
 PKG_MISCARI_INTERNE.CHECK_REZERVARI(V_REC.CODNIRSTOC_MINUS,
                                     V_REC.CODNIRSER_MINUS,
                                     V_REC.CODNIRSTOC_PLUS,
                                     V_REC.CODNIRSER_PLUS,
                                     V_REC.CANT
                                    );

END LOOP;


END;

function GetLinieComInt(CodObiect  in NUMBER, OBS in Varchar2, NewObs out varchar2) return number is
  aCodCmd1 NUMBER(20) := 0;
  aCodCmd  NUMBER(20);
  aCodObj  NUMBER(20);
  B             INTEGER     := 0;
  BB            INTEGER     := 0;
  BBB           INTEGER     := 0;
  Cate          INTEGER     := 0;

  NrX           varchar2(20);
  CODCMD1       NUMBER;
  NrCC          varchar2(20);
  CodObj        varchar2(30);
begin
  NewObs := Obs;
  B   := InStr(OBS, &apos;&lt;PU&gt;&apos;);
  if B &gt; 0 then
    NewObs := Substr(NewObs,  1,  B - 1 )||Substr(NewObs,  B + 4, 400 );
  end if;

  if CodObiect = 0 then
    B   := InStr(NewObs, &apos;&lt;OBJ=&apos;);
    if B = 0 then Return 0; end if;
    BB   := InStr(NewObs, &apos;OBJ&gt;&apos;);
    if BB = 0 then Return 0; end if;
    CODOBJ := Substr(NewOBS, B + 5, BB - (B + 5));
    begin
      select CodObiect into aCodObj from NArtObj  where CodExtern = CodObj;
      NewObs := Substr(NewObs,  1,  B - 1 )||Substr(NewObs,  BB + 4, 400 );
    exception when others then
      aCodObj := 0;
    end;
  else
    aCodObj := CodObiect;
  end if;

  if aCodObj = 0 then Return 0; end if;

  B   := InStr(NewObs, &apos;&lt;NRCC=&apos;);
  if B = 0 then
    B   := InStr(NewObs, &apos;&lt;NRCI=&apos;);
    if B = 0 then Return 0; else NRX := &apos;NRCI&apos;; end if;
  else
    NRX := &apos;NRCC&apos;;
  end if;

  BB   := InStr(NewObs, NRX||&apos;&gt;&apos;);
  if BB = 0 then Return 0; end if;
  NRCC := Substr(NewOBS, B + 6, BB - (B + 6));
  begin
    select CodComanda  into aCodCmd from Comanda  where SeriaDoc||NrDoc = NRCC;
    select CodComanda1 into aCodCmd1 from Comanda1 where CodComanda = aCodCmd and CodObiect = aCodObj;
    if NRX = &apos;NRCC&apos; then
      select nvl(L.CodComanda1, 0) into aCodCmd1 from CmdLink L where L.CodLinieComanda = aCodCmd1;
    end if;
    NewObs := Substr(NewObs,  1,  B - 1 )||Substr(NewObs,  BB + 5, 400 );
  exception when others then
    aCodCmd1 := 0;
  end;
  Return aCodCmd1;
end;


function GetLinieComCli(aCODCOMANDA1 in number) return number is
aCodCmd1 NUMBER(20);
begin
  begin
      select distinct nvl(L.CodCmd1, 0) into aCodCmd1
      from lansare1 L1
           inner join lansare L on L1.CodLansare = L.CodLansare
      where L1.CodCmd1 = aCodComanda1;
  exception when others then
    aCodCmd1 := 0;
  end;
  if aCodCmd1 = 0 then
    Return aCODCOMANDA1;
  else
    Return aCodCmd1;
  end if;
end;


PROCEDURE DISTRIBUIE_DIFERENTA_FACTURA(aCODIES IN NUMBER, DIFERENTE IN NUMBER)
IS
  PRAGMA AUTONOMOUS_TRANSACTION;

  aTVADOC NUMBER(20, 7) := 0;
  TVANOU  NUMBER(20, 7) := 0;
  aTIPDOC NUMBER(5)     := 0;
  aCODGENERAL NUMBER(20);
  aVALDOC     NUMBER(20, 7);
  NR          NUMBER(5);
  aINFOCM     NUMBER(1);
  aTIPFACTURA NUMBER(10);

BEGIN
  BEGIN
    SELECT
       NVL(TVADOC, 0),
       TIPDOC,
       NVL(INFOCM, 0),
       NVL(TIPFACTURA, 0)
    INTO
      aTVADOC,
      aTIPDOC,
      aINFOCM,
      aTIPFACTURA
    FROM
      IESIRI WHERE CODIES = aCODIES;
    EXCEPTION WHEN OTHERS THEN aTVADOC := 0; aTIPDOC := 0;
  END;

  IF aTVADOC &lt;&gt; 0 THEN
    FOR V_REC IN (SELECT * FROM IESIRI1 WHERE CODIES = aCODIES)
    LOOP
      TVANOU := V_REC.TVA + (V_REC.TVA / aTVADOC) * DIFERENTE;
      UPDATE IESIRI1
      SET
        TVA = TVANOU
      WHERE
        CODIES1 = V_REC.CODIES1;
    END LOOP;

    UPDATE IESIRI
    SET
      VALDOC = VALDOC + DIFERENTE,
      TVADOC = TVADOC + DIFERENTE
    WHERE
      CODIES = aCODIES;

    BEGIN
      SELECT CODGENERAL INTO aCODGENERAL FROM GENERAL WHERE TIPDOC = 19 AND CODDOC = aCODIES AND SEMNIFICATIE = 200 AND ROWNUM = 1;
      EXCEPTION WHEN OTHERS THEN aCODGENERAL := 0;
    END;

    IF aCODGENERAL &lt;&gt; 0 AND aTIPFACTURA &lt;&gt; 7 AND aINFOCM = 0       THEN
      SELECT COUNT(*) INTO NR FROM OBLIGPIF WHERE CODGENERAL = aCODGENERAL;
      IF NR = 1 THEN
          SELECT ROUND(VALDOC - TVADOC, 2) + ROUND(TVADOC, 2) INTO aVALDOC FROM IESIRI WHERE CODIES = aCODIES;
          UPDATE OBLIGPIF
          SET
            VALOARE = aVALDOC,
            REST = aVALDOC
          WHERE
            CODGENERAL = aCODGENERAL;
      END IF;
    END IF;

    UPDATE JURNAL1
    SET
      DIRTY = 1
    WHERE
      TIPDOC = aTIPDOC
      AND CODDOC = aCODIES;

    COMMIT;
  END IF;
END;



PROCEDURE EMPTY_IESIRI_TEMPTABLES
IS
BEGIN
   Delete TMP_IESIRI1;
   Delete TMP_LIVR;
   Delete TMP_LIVR1;
   Delete TMP_LIVRTOT;
   Delete TMP_LIVR1_INITIAL;
   Delete TMP_IESLINK;
   Delete TMP_IESLINK_INITIAL;
   Delete TMP_GENERAL;
   Delete TMP_OBLIGPIF;
   Delete TMP_LIVRVAL;
   Delete TMP_LIVRVAL_INITIAL;
   Delete TMP_INTRARI;
   Delete TMP_NIR;
   Delete TMP_NIRSTOC;
   Delete TMP_NIRSTOC_INITIAL;
   Delete TMP_INTRARI1;
   Delete TMP_NIRSER;
   Delete TMP_IOPARTDOC;
   Delete TMP_STINGERE;
   Delete TMP_OBLIGPIF_INITIAL;
   Delete TMP_STINGERE_INITIAL;
   Delete TMP_JURNAL1;
   Delete TMP_JURNAL;
   Delete TMP_RULAJ;
   Delete TMP_MODURIPLATI;
   Delete TMP_MODPLATA2;
   Delete TMP_IESVALLINK;
   Delete TMP_IESVALLINK_INITIAL;
   Delete TMP_IESPRODLINK;
   Delete TMP_IESPRODLINK_INITIAL;
   Delete IESIRI1_MAN;
   Delete TMP_NIRSTOC1;
   Delete TMP_IESDISC;
   Delete TMP_DISCMONETAR;
   Delete TMP_IESPUNCTE;
   Delete TMP_FACTSALINK;
   Delete TMP_VOUCHERCADOULINK;
   Delete TMP_VOUCHERCADOULINK_INI;
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRIEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_IESIRIEXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_IESIRI1EXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAREXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_MONETAREXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_MONETAR1EXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONSEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_BONCONSEXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_BONCONS1EXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESBF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IESBF&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IES1BF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IES1BF&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_DIMINEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_DIMINEXT&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_DIMIN1EXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_DIMIN1EXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MARIRIEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_MARIRIEXT&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MARIRI1EXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_MARIRI1EXT&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESSUB&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IESSUB&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IES1SUB&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IES1SUB&apos;;
   END IF;

   -- tmp ini
   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRIEXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_IESIRIEXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_IESIRI1EXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAREXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_MONETAREXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_MONETAR1EXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONSEXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_BONCONSEXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete TMP_BONCONS1EXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESBF_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IESBF_INI&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IES1BF_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IES1BF_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_DIMINEXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_DIMINEXT_INI&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_DIMIN1EXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_DIMIN1EXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MARIRIEXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_MARIRIEXT_INI&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_MARIRI1EXT_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_MARIRI1EXT_INI&apos;;
   END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESSUB_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IESSUB_INI&apos;;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_IES1SUB_INI&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;Delete from TMP_IES1SUB_INI&apos;;
   END IF;


   Delete TMP_Dezasamblari;
   Delete TMP_PACHETELINK;
   Delete TMP_PACHETELINK_INITIAL;
   Delete TMP_PACHETEOBJLINK;
   Delete TMP_PACHETEOBJLINK_I;
   Delete TMP_MONETARLINK;
   Delete TMP_TVAMONETAR;

   Delete TMP_CMDAVANS;

   COMMIT;
END;


PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RECID OUT NUMBER ) IS
   VCOD          NUMBER(20);
   NR            NUMBER(20);
   TIPIES        INTEGER     := 0;
   AOPERAT       INTEGER     := 0;
   AANULAT       INTEGER     := 0;
   ACARNET       INTEGER     := 0;
   ANUMARDOC     NUMBER(20)  := 0;
   OLDCARNETLIVR NUMBER(20)  := 0;
   OLDNRLIVR     NUMBER(20)  := 0;
   vCODNIRSTOC   NUMBER(20)  := 0;
   vCODNIR       NUMBER(20)  := 0;
   vCODINTR      NUMBER(20)  := 0;
   vCODINTR1     NUMBER(20)  := 0;
   vCODNIRSER    NUMBER(20)  := 0;
   aCODSERIE     VARCHAR(30) := &apos;&apos;;
   NOMSERIE      VARCHAR(75) := &apos;&apos;;
BEGIN
  Actualizeaza_CodContract1;
  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  Repara_TMP_Iesiri_OBS;
  SELECT TIPDOC, OPERAT, ANULAT, CARNETDOC, NRDOC INTO TIPIES, AOPERAT, AANULAT, ACARNET, ANUMARDOC FROM TMP_IESIRI;

  -- MASTER IESIRI

  SELECT SEQ_IESIRI_CODIES.NEXTVAL INTO RECID FROM DUAL;

  INSERT INTO IESIRI (
    CODIES, TIPDOC,  ANULAT,   BLOCAT, OPERAT, PREFIXDOC, RotEFact, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
    NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE,   DELEGAT, AGENT, MAJORARI,
    OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED, TIPTVA, COMISION,
    SUBUNITATEA, MONEDA, CURS, MIJLTRANSP, LISTAT, CUSTODIE, FARATRANSPORT, StareRestituire, INFOCM, NRTRANSP, userid,datacreare,
    CARNETCERTIF, NRCERTIF, SERIACERTIF, IDIMPORT, ExclusPlata, ExclusIntrastat, PROCTVADOC, FaraReg, TVAIncasare, DataTVA, TipET
  )
  SELECT RECID,TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, RotEFact, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
    NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, MAJORARI,
    OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED, TIPTVA, COMISION, SUBUNITATEA, MONEDA, CURS,
    MIJLTRANSP, LISTAT, CUSTODIE, FARATRANSPORT, StareRestituire, INFOCM, NRTRANSP, pkg_globals.USERID,systimestamp,
    CARNETCERTIF, NRCERTIF, SERIACERTIF, IDIMPORT, ExclusPlata, ExclusIntrastat, PROCTVADOC, FaraReg, TVAIncasare, DataTVA, TipET
  FROM TMP_IESIRI;

-- detail GENERAL
   FOR v_rec IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT SEQ_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;
     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, TVA, ExclusPlata,  DataTVA, FaraReg)
     VALUES
     (VCOD, TIPIES, RecID, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS, V_REC.PROCTVAAVANS, v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA,
      v_rec.FaraReg);
   END LOOP;

-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     IF V_REC.CODOBLIGPIF &lt; 0
       THEN  SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
       ELSE VCOD := V_REC.CODOBLIGPIF;
     END IF;

     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
     UPDATE TMP_IESIRI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODANALIZANOD)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 211 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA,V_REC.CODCENTRU,  V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0), V_REC.CODANALIZANOD);
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;



  FOR V_REC IN ( SELECT * FROM TMP_IESIRI1 ORDER BY INDEXLOCAL ) LOOP
-- DETAIL IESIRI1
    SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO VCOD FROM DUAL;
    update tmp_jurnal1 set indexlocal = vcod where indexlocal = v_Rec.Codies1;

    INSERT INTO IESIRI1
        (
          CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT, PRETORIG, PU,
          CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT,
          PUMaximal, AdMax,
          TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG,
          PARITATEORIG, CodOferta1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat, PRETPROMO, TIPPLATA
          )
    VALUES
        (
          VCOD, RECID, V_REC.INDEXLOCAL,  V_REC.TIPLINIE,  V_REC.UMSEC,  V_REC.CONTSERV,  V_REC.CONTDISCOUNT, V_REC.CODCRITERIU, V_REC.MIFIX, V_REC.ZILE,  V_REC.ZILECMD, V_REC.GESTACT,  V_REC.CODOBIECT,
          V_REC.PRETORIG / NVL(V_REC.PARITATE,1),  V_REC.PU / NVL(V_REC.PARITATE,1), V_REC.CANT * NVL(V_REC.PARITATE, 1),
          V_REC.TVA, V_REC.CONT, V_REC.PROCDISC, V_REC.ADDIM,
          CASE
            WHEN V_REC.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND TIPIES = 20 AND AOPERAT = 1 AND AANULAT = 0 THEN V_REC.CANT * V_REC.PARITATE
            WHEN V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_REC.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
            ELSE 0
          END,
          V_REC.PUMaximal, V_REC.AdMax,
          V_REC.TipLivrare, V_REC.GARANTIE, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS, V_REC.COEFDISCMAJ, V_REC.OBS, V_REC.CODOBIECTORIG,
          V_REC.PARITATEORIG, V_REC.CodOferta1, V_REC.CADOU,V_REC.TAXA, V_REC.TERMENCONTRACT, V_REC.CADOULINK, V_REC.CODIOARTCUST,v_rec.UMCorelat, v_rec.CANTCorelat, v_rec.PUCorelat,  V_REC.PRETPROMO, V_REC.TIPPLATA
        );
    UPDATE TMP_LIVR1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
    UPDATE TMP_IESLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

-- IESLINK
  INSERT INTO IESLINK(CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_IESLINK);

-- INAINTE DE LIVRARI REZOLV IESIRILE IN ROSU PENTRU A AVEA APOI DE UNDE LIVRA
-- IESIRI IN ROSU : RECODIFICARI
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC) LOOP

    IF V_REC.CODNIRSTOC &lt; 0
    THEN SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
    ELSE vCODNIRSTOC := V_REC.CODNIRSTOC;
    END IF;

    UPDATE TMP_NIRSTOC SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    UPDATE TMP_NIRSER  SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    UPDATE TMP_LIVR1   SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_INTRARI) LOOP
    SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
    UPDATE TMP_INTRARI  SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
    UPDATE TMP_NIR SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
    UPDATE TMP_INTRARI1 SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_INTRARI1) LOOP
    SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
    UPDATE TMP_INTRARI1 SET CODINTR1 = vCODINTR1 WHERE CODINTR1 = V_REC.CODINTR1;
    UPDATE TMP_NIRSTOC  SET CODINTR1  = vCODINTR1 WHERE CODINTR1 = V_REC.CODINTR1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NIR) LOOP
    SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
    UPDATE TMP_NIR SET CODNIR = vCODNIR WHERE CODNIR = V_REC.CODNIR;
    UPDATE TMP_NIRSTOC  SET CODNIR = vCODNIR WHERE CODNIR = V_REC.CODNIR;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP
    IF V_REC.CODNIRSER &lt; 0
      THEN SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCODNIRSER FROM DUAL;
      ELSE vCODNIRSER := V_REC.CODNIRSER;
    END IF;

    UPDATE TMP_LIVR1  SET CODNIRSER = vCODNIRSER WHERE CODNIRSER = V_REC.CODNIRSER;
    UPDATE TMP_NIRSER SET CODNIRSER = vCODNIRSER WHERE CODNIRSER = V_REC.CODNIRSER;

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, NVL((SELECT CODOBIECT FROM TMP_NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC), 0));

        UPDATE TMP_NIRSER SET CODSERIE = aCODSERIE WHERE CODNIRSER = VCODNIRSER;
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      --verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;
  END LOOP;

-- IESIRI IN ROSU : SCRIERE IN BAZA DE DATE
   INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, ExclusPlata, FaraReg, TVAIncasare)
   SELECT  CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, ExclusPlata, FaraReg, TVAIncasare FROM TMP_INTRARI;

   INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, CodOferta1)
   SELECT CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG /  NVL(PARITATE, 1), PU /  NVL(PARITATE, 1), 0, TG, CodOferta1
   FROM TMP_INTRARI1;

   INSERT INTO NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
   SELECT CODNIR, CODINTR, RECID, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT FROM TMP_NIR;


   INSERT INTO NIRSTOC
   (
     CODNIRSTOC,
     CODNIR,
     CODINTR1,
     CANTNIR,
     REST,
     UMSEC,
     CODOBIECT,
     CODIOART,
     PRET,
     ADAOS,
     TVA,
     TIPSERIE,
     CODLOCATIE,
     TG,
     PUMaximal, AdMax,
     FURN,
     DATAACHIZ,
     TIPDOCACHIZ,
     PUVAL
   )
   (
   SELECT
     CODNIRSTOC,
     CODNIR,
     CODINTR1,
     CANTNIR,
     REST,
     UMSEC,
     CODOBIECT,
     CODIOART,
     PRET /  NVL(PARITATE, 1),
     ADAOS /  NVL(PARITATE, 1),
     TVA,
     TIPSERIE,
     CODLOCATIE,
     TG,
     PUMaximal, AdMax,
     FURN,
     DATAACHIZ,
     TIPDOCACHIZ,
     PUVAL
     FROM
       TMP_NIRSTOC
    );

   /*INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
   SELECT NS.CODNIRSTOC, NS.CODNIRSTOC, nir.TIPNIR, PRET/NVL(PARITATE, 1)-ADAOS/NVL(PARITATE, 1),0, 1, 0
   FROM TMP_NIRSTOC NS
        inner join tmp_nir nir on nir.codnir = ns.codnir;*/

   INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, OBS, TG)
   SELECT CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, OBS, TG FROM TMP_NIRSER;


-- LIVR
  FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP
    SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

    INSERT INTO LIVR (CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    VALUES (VCOD, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR, V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

    UPDATE TMP_LIVR1 SET CODLIVR = VCOD WHERE CODLIVR = V_REC.CODLIVR;
  END LOOP;





-- LIVR1
   FOR V_REC IN (SELECT * FROM TMP_LIVR1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;


     SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;


     INSERT INTO LIVR1 (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTREZERVAT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2)
     VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CANTREZERVAT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA,V_REC.PMPVALUTADOC, V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2 );
   END LOOP;

   INSERT INTO MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
         (SELECT SEQ_MODURIPLATI_CODMODPLATA.NEXTVAL, RECID, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA FROM TMP_MODURIPLATI);


   INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
   SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;


   DELETE TMP_MANEVRA;
   INSERT INTO TMP_MANEVRA SELECT CODNIRSTOC FROM TMP_LIVR1;

   UPDATE NIRSTOC NS SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);


   UPDATE NIRSER NS
   SET
      REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
      RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
      RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);

   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODANALIZANOD )
   (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODANALIZANOD FROM TMP_JURNAL1);



   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODANALIZANOD)
  ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, DATADOC, CODANALIZANOD FROM TMP_JURNAL);



IF TIPIES = 26 THEN
-- SUNT PE FACTURA LA AVIZ ; ACTUALIZEZ AVIZELE STINSE
    UPDATE IESIRI1 I1
    SET
/*
     I1.RESTFACT = I1.CANT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                     IESLINK IL
                     LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                     LEFT OUTER JOIN IESIRI  II ON II.CODIES    = II1.CODIES
                   WHERE
                     IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
*/
    I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                   IESLINK IL
                   LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                   LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26 AND II.OPERAT = 1 AND II.ANULAT = 0
                ) +
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  IESIRI1 AE1,
                  IESIRI  AE
                WHERE
                  AE1.CODIES1STORNO =I1.CODIES1 AND AE.CODIES = AE1.CODIES
                 AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
    WHERE
     I1.CODIES1 IN
     (SELECT CODLINIEAVIZ FROM TMP_IESLINK UNION SELECT CODLINIEAVIZ FROM TMP_IESLINK_INITIAL);
ELSE -- ACTUALIZEZ RESTULACCEPTAT DE PE COMENZI CLIENTI
  IF TIPIES IN (16, 19, 20, 23) THEN
    UPDATE COMANDA1 C1
    SET
     C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    IESLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                   WHERE
                   IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   ) -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    CMDLIVRLINK IL
                    LEFT OUTER JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT OUTER JOIN COMANDA  II ON II.CODCOMANDA    = II1.CODCOMANDA
                   WHERE
                   IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )

    WHERE
    C1.CODCOMANDA1 IN
    (SELECT CODLINIECOMANDA FROM TMP_IESLINK UNION SELECT CODLINIECOMANDA  FROM TMP_IESLINK_INITIAL);
  END IF;
END IF;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 END LOOP;


-- ACTUALIZARE CARNETE DOCUMENTE
/*
IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNET &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
THEN
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
END IF;
*/

PKG_CARNETEDOC.SOLVENUMARDOC(ACARNET, ANUMARDOC);


FOR V_REC IN (SELECT * FROM LIVR WHERE  CODIES = RECID)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;




-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
UPDATE OBLIGPIF O
SET
  REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
WHERE
 O.CODOBLIGPIF IN
 ( SELECT CODSTINSPIF FROM TMP_STINGERE

   UNION ALL

   SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
 );



COMMIT;
END;


FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT VALOARE INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;

FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;



FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;


FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0);
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;



-- NECESARA LA STERGERI IESIRI IN ROSU : VERIFICA CATE LIVRARI SUNT FACUTE DIN NIR-urile PROVENITE DE PE DOCUMENTUL DE IESIRE IN ROSU
-- SUNT EXCLUSE LIVRARILE DE PE DOCUMENTUL ANALIZAT
FUNCTION NR_LIVRARI_DIN_IESIRIINROSU(aCODIES IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(*), 0) INTO NR FROM LIVR1
    WHERE
      CODNIRSTOC IN
      (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODIES = aCODIES AND TIPNIR = aTIPIES)) AND
      CODLIVR1 NOT IN (SELECT CODLIVR1 FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = aCODIES));
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;

FUNCTION STOC_NEG_LA_STERGERE_LIVR_ROSU(aCODIES IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER
IS
 STOCNEG NUMBER(5) := 0;
 NR      NUMBER(5) := 0;
BEGIN
  IF aTIPIES = 15 THEN NR := 1;
  ELSE
    SELECT COUNT(*) INTO NR
    FROM
      LIVR1 L1,
      LIVR L
    WHERE
      L1.CANT &lt; 0 AND L1.CODLIVR = L.CODLIVR
      AND L.TIPLIVR = aTIPIES AND L.CODIES = aCODIES;
   END IF;
   IF NR = 0 THEN RETURN 0; END IF;

   FOR V_REC IN
   (
        SELECT
        NS.CODNIRSTOC,
        NS.CANTNIR,
        ALTELIVR.CANTIES,
        LIVRCURENT.CANTDOCCURENT
      FROM
      (
        SELECT
          L1.CODNIRSTOC,
          SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTDOCCURENT
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
         L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR = aTIPIES AND L.CODIES = aCODIES
        GROUP BY
         L1.CODNIRSTOC
      ) LIVRCURENT,
       (SELECT
         CODNIRSTOC,
         SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTIES
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
          L1.CODLIVR = L.CODLIVR
          AND NOT (L.TIPLIVR = aTIPIES AND L.CODIES = aCODIES)
        GROUP BY CODNIRSTOC
       ) ALTELIVR,
       NIRSTOC NS
      WHERE
       NS.CODNIRSTOC = LIVRCURENT.CODNIRSTOC
       AND  LIVRCURENT.CODNIRSTOC = ALTELIVR.CODNIRSTOC
   ) LOOP
        IF V_REC.CANTNIR &lt; V_REC.CANTIES THEN RETURN 1; END IF;
     END LOOP;

  RETURN STOCNEG;
END;


FUNCTION STOC_NEG_LASTERGERE_LIVR1_ROSU(aCODLIVR1 IN NUMBER, aTIPIES IN NUMBER) RETURN NUMBER
IS
 STOCNEG NUMBER(5) := 0;
 NR      NUMBER(5) := 0;
BEGIN
  IF aTIPIES = 15 THEN NR := 1;
  ELSE
    SELECT COUNT(*) INTO NR
    FROM
      LIVR1 L1,
      LIVR L
    WHERE
      L1.CANT &lt; 0 AND L1.CODLIVR = L.CODLIVR
      AND L.TIPLIVR = aTIPIES AND L1.CODLIVR1 = aCODLIVR1;
   END IF;
   IF NR = 0 THEN RETURN 0; END IF;

   FOR V_REC IN
   (
        SELECT
        NS.CODNIRSTOC,
        NS.CANTNIR,
        ALTELIVR.CANTIES,
        LIVRCURENT.CANTDOCCURENT
      FROM
      (
        SELECT
          L1.CODNIRSTOC,
          SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTDOCCURENT
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
         L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR = aTIPIES AND L1.CODLIVR1 = aCODLIVR1
        GROUP BY
         L1.CODNIRSTOC
      ) LIVRCURENT,
       (SELECT
         CODNIRSTOC,
         SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTIES
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
          L1.CODLIVR = L.CODLIVR
          AND NOT (L.TIPLIVR = aTIPIES AND L1.CODLIVR1 = aCODLIVR1)
        GROUP BY CODNIRSTOC
       ) ALTELIVR,
       NIRSTOC NS
      WHERE
       NS.CODNIRSTOC = LIVRCURENT.CODNIRSTOC
       AND  LIVRCURENT.CODNIRSTOC = ALTELIVR.CODNIRSTOC
   ) LOOP
        IF V_REC.CANTNIR &lt; V_REC.CANTIES THEN RETURN 1; END IF;
     END LOOP;

  RETURN STOCNEG;
END;


-- NECESARA LA VALIDARE MODIFICARI CANTITATE NIR PROVENIT DIN IESIRE IN ROSU, PENTRU A NU AJUNGE LA STOCNEGATIV
-- SUNT EXCLUSE LIVRARILE DE PE DOCUMENTUL ANALIZAT
FUNCTION SUMA_LIVRARI_DIN_NIR_IESROSU(aCODNIRSTOC IN NUMBER, aCODIES IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc
    AND CODLIVR1 NOT IN (SELECT CODLIVR1 FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = aCODIES));
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;

FUNCTION SUMA_MARIRI_LA_NIR_IESROSU(aCODNIRSTOC IN NUMBER, aCODIES IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc
    AND CODLIVR1 NOT IN (SELECT CODLIVR1 FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = aCODIES));
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


PROCEDURE SETDATADOC(aZI in Number, aLuna in Number, aAn in Number) IS
BEGIN
  vDATADOC := To_Date(To_Char(aZi)||&apos;.&apos;||to_Char(aLuna)||&apos;.&apos;||to_Char(aAn), &apos;DD.MM.YYYY&apos;);
END;

FUNCTION  GETDATADOC RETURN DATE IS
BEGIN
  RETURN vDATADOC;
END;

PROCEDURE SETPARTENERAVIZ(APART IN NUMBER)
IS
BEGIN
  PARTENERAVIZ := APART;
END;



PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER, aNRCERTIF IN NUMBER, aCARNETCERTIF IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
  CARNETDOC_C := ACARNETCERTIF;
  NRDOC_C     := ANRCERTIF;
END;

PROCEDURE REZOLVA_CARNET_CERTIF(ACARNETDOC IN NUMBER, ANRDOC IN NUMBER, ACODIES IN NUMBER) IS
AOLDCARNET NUMBER(20);
AOLDNRDOC  NUMBER(20);
BEGIN
  SELECT CARNETCERTIF, NRCERTIF INTO AOLDCARNET, AOLDNRDOC FROM IESIRI WHERE CODIES = ACODIES;
  IF (AOLDCARNET &lt;&gt; 0)AND(AOLDNRDOC &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; AOLDCARNET OR AOLDNRDOC &lt;&gt; ANRDOC)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(AOLDCARNET, AOLDNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(AOLDCARNET);
  END IF;

  if coalesce(ACARNETDOC,0) &gt; 0 then
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  end if;
  COMMIT;
END;

FUNCTION CONDITIE_PART_AVIZ(APART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF APART = PARTENERAVIZ THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;


FUNCTION AMFACTURALAAVIZ(CODAVIZ  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 0) := 0;
BEGIN
  BEGIN
    SELECT NVL(SUM(ABS(CANT)), 0) INTO SUMA FROM IESLINK
    WHERE
    CODLINIEAVIZ IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = CODAVIZ);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;

  IF NVL(SUMA, 0) = 0 THEN
  BEGIN
    SELECT COUNT(*) INTO SUMA FROM IESIRI1
    WHERE
    CODIES1STORNO IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = CODAVIZ);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  END IF;

  RETURN SUMA;
END;

FUNCTION LINIEAVIZSTINSA(ACODIES1 IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIEAVIZ), 0) INTO NR FROM IESLINK
    WHERE
    CODLINIEAVIZ = ACODIES1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR = 0 THEN
    BEGIN
      SELECT NVL(COUNT(CODIES1STORNO), 0) INTO NR FROM IESIRI1
      WHERE
      CODIES1STORNO = ACODIES1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;

  RETURN NR;
END;

FUNCTION LINIEAVIZSTINSA_EXT(ACODIES1 IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIEAVIZ), 0) INTO NR
    FROM
      IESLINK IL,
      IESIRI1 I1,
      IESIRI I
    WHERE
    CODLINIEAVIZ = ACODIES1
    AND IL.CODIES1 = I1.CODIES1
    AND I.CODIES = I1.CODIES
    AND NVL(I.ANULAT, 0) = 0;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR = 0 THEN
    BEGIN
      SELECT NVL(COUNT(CODIES1STORNO), 0) INTO NR
      FROM
        IESIRI1 I1,
        IESIRI I
      WHERE
      I1.CODIES1STORNO = ACODIES1
      AND I.CODIES = I1.CODIES
      AND NVL(I.ANULAT, 0) = 0;

      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;

  RETURN NR;
END;


PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
  TMP NUMBER(20);
BEGIN
  SELECT CODIES INTO TMP FROM IESIRI WHERE CODIES = RECID FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
  TIPIES        NUMBER(20);
  ACARNETDOC    NUMBER(20);
  ANRDOC        NUMBER(20);
  aCodSubunit   NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
  REZERVCMDORIG NUMBER(10) := 0;
  aTIPTVA       NUMBER(20);
/*  EXISTAIESIRI  NUMBER(10) := 0;
  EXISTAIESIRI1 NUMBER(10) := 0;*/
  CONSTOPERAT   NUMBER(10) := 0;
  aCURS         NUMBER(20, 7) := 1;
  StornoAvize   varchar2(20);
  InchidLinieCmd VARCHAR2(1);
  canDeleteXVoucher NUMBER(1);
  existingCodReturo NUMBER(20);
  existingVoucherCode VARCHAR2(100);
  voucherIsUsed NUMBER(1);
  aValoare      NUMBER(20,7);
BEGIN
  canDeleteXVoucher := 0;
  IF RECID = 0 THEN RETURN;
  END IF;


  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);

  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADACCEPTATNEOP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERAT  := 0;
  END;


  SELECT
   TIPDOC,
   CARNETDOC,
   NRDOC,
   subunitatea,
   datadoc,
   prefixdoc||nrdoc||&apos;/&apos;||datadoc,
   TIPTVA,
   CURS
 INTO
   TIPIES,
   ACARNETDOC,
   ANRDOC,
   aCodSubunit,
   aDataDoc,
   aDoc,
   aTIPTVA,
   aCURS
  FROM
    IESIRI
 WHERE CODIES = RECID;

 BEGIN
   SELECT rt.codreturo, rt.voucherbarcode, rt.is_used into existingCodReturo, existingVoucherCode, voucherIsUsed
   FROM RETURO rt
   WHERE TIPDOC = TIPIES and CODDOC = RECID;
 EXCEPTION
   WHEN OTHERS THEN existingCodReturo := -1;
 END;
 if (existingCodReturo = -1) then
   canDeleteXVoucher := 1;
 else
   if AccesGranted(pkg_globals.GETUSERID,&apos;MODIFMARIRESGR&apos;) &gt; 0 then
     if (voucherIsUsed is null) or (voucherIsUsed = 0) then  canDeleteXVoucher := 1; end if;
   else
     if (existingVoucherCode is null) or (length(existingVoucherCode) = 0) then  canDeleteXVoucher := 1; end if;
   end if;
 end if;

 if (canDeleteXVoucher = 0) then
   RAISE_APPLICATION_ERROR(-20200, &apos;Exista voucher generat! Nu se poate sterge documentul.&apos;);
 end if;


 PKG_CFGTABLES.EXT_DELETERECORD (recId, TIPIES);

 DELETE FROM TAXDECL    WHERE TipDoc = TIPIES and CODDOC = RECID;
 DELETE FROM STATUSDECL WHERE TipDoc in (TIPIES,100+TIPIES) and CODDOC = RECID;
 DELETE FROM DetaliiET1 et1
              where et1.coddetaliuet in (select et.coddetaliu
                                           from detaliiet et
                                           WHERE et.TipDoc = TIPIES and et.CODDOC = RECID);
 DELETE FROM DetaliiET  WHERE TipDoc = TIPIES and CODDOC = RECID;

 DELETE FROM RETURO WHERE TIPDOC = TIPIES and CODDOC = RECID;

-- legaturi venituri in avans
  FOR V_REC IN (SELECT * FROM IESIRI1 WHERE CODIES = RECID)
  LOOP
     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODIES1 = V_REC.CODIES1)
     LOOP
       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC = 106) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;


          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
              RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;


         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
              RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;
       END LOOP;

       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 106;
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 106;
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODIES1 = V_REC.CODIES1;
   END LOOP;


  if tipies = 24 then
    delete tmp_manevra2;
    insert into tmp_manevra2(codunic)
    select distinct ns.codnirstoc
      from livr1 l1
           inner join livr l on l1.codlivr = l.codlivr
           inner join iesiri1 i1 on i1.codies1 = l1.codies1 and i1.codcmdint1 &gt; 0
           inner join iesiri i on i.codies = l.codies and i1.codies = i.codies
           inner join intrari1 intr1 on intr1.codcmdint1 = i1.codcmdint1
           inner join nirstoc ns on ns.codintr1 = intr1.codintr1
      where i.codies = recid and ns.codnirstoc &gt; 0;
  end if;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;IESIRI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;


/*  EXISTAIESIRI  := PKG_LIST_STRUCT.TMPEXISTS(&apos;IESIRIEXT&apos;);
  EXISTAIESIRI1 := PKG_LIST_STRUCT.TMPEXISTS(&apos;IESIRI1EXT&apos;);*/

  -- MEMOREZ LIVRARILE CARE VOR FI STERSE
  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CODUNIC)
  (SELECT CODNIRSTOC FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = RECID));

  -- MEMOREZ CODURILE DE AVIZE STINSE DE IESLINK-URILE CARE VOR FI STERSE
  DELETE TMP_IESIRI1;
  IF TIPIES = 26 THEN
    INSERT INTO TMP_IESIRI1 (CODIES1)
    SELECT CODIES1 FROM IESIRI1
    WHERE CODIES1 IN (SELECT IL.CODLINIEAVIZ FROM IESLINK IL LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1 WHERE I1.CODIES = RECID);
  ELSIF TIPIES IN (16, 19, 20, 21, 23) THEN
    DELETE TMP_COMANDA1;
    INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
    SELECT CODLINIECOMANDA FROM IESLINK IL
    WHERE IL.CODIES1 IN (SELECT I1.CODIES1 FROM IESIRI1 I1 WHERE CODIES=RECID AND I1.CODIES1 = IL.CODIES1);

    -- MEMOREZ IN IESIRI1_MAN CODURI DE AVIZE STORNATE;
    DELETE IESIRI1_MAN;
    INSERT INTO IESIRI1_MAN (CODIES1, CODIES1STORNO) SELECT CODIES1, CODIES1STORNO FROM IESIRI1 WHERE CODIES = RECID;
    IF TIPIES = 19 THEN
      DELETE TMP_COMANDA;
      INSERT INTO TMP_COMANDA (CODCOMANDA, CODCONTRACT)
      SELECT CODCOMANDA, CODCLASEA FROM FACTSALINK WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
    END IF;
  ELSIF TIPIES IN (24) THEN
    DELETE TMP_COMANDA1;
    INSERT INTO TMP_COMANDA1 (CODCOMANDA)
    SELECT CODCMDPRODMAT FROM IESPRODLINK IL
    WHERE IL.CODIES1 IN (SELECT I1.CODIES1 FROM IESIRI1 I1 WHERE CODIES=RECID AND I1.CODIES1 = IL.CODIES1);
    INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
    SELECT CODLINIECOMANDA FROM IESLINK IL
    WHERE IL.CODIES1 IN (SELECT I1.CODIES1 FROM IESIRI1 I1 WHERE CODIES=RECID AND I1.CODIES1 = IL.CODIES1);
    INSERT INTO TMP_IESIRI1 (CODIES1, codcmdint1)
    SELECT CODIES1,codcmdint1 FROM IESIRI1 WHERE CODIES = RECID;
  END IF;

  -- LIVRARI

  -- modificari pt mifix
  for v_rec in (select f.codfisamf, nvl(mfix2.stare,1) stare_ante, mfix1.codmifix1, i.an, i.luna,
                       mfix1.codmifix
                from iesiri i
                     inner join iesiri1 i1 on i.codies = i1.codies
                     inner join livr l on i.codies = l.codies
                     inner join livr1 l1 on l1.codies1 = i1.codies1 and l1.codlivr = l.codlivr
                     inner join nirstoc ns on ns.codnirstoc = l1.codnirstoc
                     inner join mifix1 mfix1 on mfix1.codnirstoc = ns.codnirstoc
                     inner join fisamf f on f.codmifix = mfix1.codmifix and f.coddoc1 = i1.codies1 and f.tipdoc = i.tipdoc
                     left join mifix1 mfix2 on mfix2.codmifix = mfix1.codmifix and mfix2.anstart*12+mfix2.lunastart = mfix1.anstart*12+mfix1.lunastart-1
                where i.codies = recid
                ) loop
    delete fisamf where codfisamf = v_rec.codfisamf;
    update mifix1 set stare = v_rec.stare_ante where codmifix1 = v_rec.codmifix1;
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= v_rec.an*12+v_rec.luna;
  end loop;
  if TIPIES = 14 THEN
    for v_rec in (select nvl(mfix2.stare,1) stare_ante, mfix1.codmifix1, i.an, i.luna, mfix1.codmifix
                  from iesiri i
                       inner join iesiri1 i1 on i.codies = i1.codies
                       inner join livr l on i.codies = l.codies
                       inner join livr1 l1 on l1.codies1 = i1.codies1 and l1.codlivr = l.codlivr
                       inner join nirstoc ns on ns.codnirstoc = l1.codnirstoc
                       inner join mifix1 mfix1 on mfix1.codnirstoc = ns.codnirstoc
                       inner join mifix mfix on mfix.codmifix = mfix1.codmifix
                       left join mifix1 mfix2 on mfix2.codmifix = mfix1.codmifix and mfix2.anstart*12+mfix2.lunastart = mfix1.anstart*12+mfix1.lunastart-1
                  where i.codies = recid and mfix.tip = &apos;OI&apos;
                  ) loop
      update mifix1 set stare = v_rec.stare_ante where codmifix1 = v_rec.codmifix1;
      update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= v_rec.an*12+v_rec.luna;
    end loop;
  END IF;


  DELETE TMP_LIVR1;

  INSERT INTO TMP_LIVR1 ( CODLIVR1, CODIES1, CODNIRSTOC, CANT, CODNIRSER, CANTREZERVAT )
  SELECT CODLIVR1, CODIES1, CODNIRSTOC, CANT, CODNIRSER, CANTREZERVAT
  FROM LIVR1 L1
  WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = RECID);

  DELETE TMP_LIVR1_INITIAL;
  INSERT INTO TMP_LIVR1_INITIAL SELECT * FROM TMP_LIVR1;

  DELETE TMP_LIVRVAL_INITIAL;
  INSERT INTO TMP_LIVRVAL_INITIAL(CODLIVRVAL,CODLIVR1) SELECT CODLIVRVAL,CODLIVR1 FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

  DELETE FROM NPLINK   WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM LIVRVAL  WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM LIVR1 L1 WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

  DELETE FROM DEZASAMBLARI1 WHERE CODLIVR1 in (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM DEZASAMBLARI  WHERE CODLIVR1 in (SELECT CODLIVR1 FROM TMP_LIVR1);

  -- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
  FOR V_REC IN (SELECT * FROM LIVR WHERE  CODIES = RECID)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
  END LOOP;

  DELETE FROM LIVR WHERE CODIES = RECID;

  DELETE TVAMONETAR WHERE CODIES = RECID;

  DELETE FROM IESPUNCTE WHERE CODIES = RECID;

  DELETE TMP_IESLINK_INITIAL;
  INSERT INTO TMP_IESLINK_INITIAL
  (
   CODIES1,
   CODLINIECOMANDA,
   CODLINIEAVIZ,
   CANT,
   CODCOMAND1ORIG
  )
   SELECT
     CODIES1,
     CODLINIECOMANDA,
     CODLINIEAVIZ,
     CANT,
     NVL((SELECT CODLINIECOMANDA FROM CMDLIVRLINK K WHERE K.CODCOMANDA1 = L.CODLINIECOMANDA AND ROWNUM = 1), 0)
   FROM
     IESLINK L
   WHERE
     CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);

  DELETE TMP_IESPRODLINK_INITIAL;
  INSERT INTO TMP_IESPRODLINK_INITIAL(CODIES1, CODCMDPRODMAT, CANT, CODLINIECOMANDA)
  SELECT IL.CODIES1, IL.CODCMDPRODMAT, IL.CANT, CMP.CODCOMANDA1
  FROM IESPRODLINK IL LEFT JOIN CMDPRODMAT CMP ON CMP.CODCMDPRODMAT = IL.CODCMDPRODMAT
  WHERE IL.CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  if pkg_globals.Directiva(&apos;_WMSA_&apos;) then
    update tmp_iesprodlink_initial set codliniecomanda = codcmdprodmat;-- pt SA codcmdprodmat este codcomanda1
  end if;

  DELETE TMP_PACHETELINK_INITIAL;
  INSERT INTO TMP_PACHETELINK_INITIAL(CODIES1, CODPACHETEOBJ, CANT)
  SELECT PL.CODIES1, PL.CODPACHETEOBJ, PL.CANT
  FROM PACHETELINK PL
       INNER JOIN PACHETEOBJ POBJ ON POBJ.CODPACHETEOBJ = PL.CODPACHETEOBJ
  WHERE PL.CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);

  DELETE TMP_PACHETEOBJLINK_I;
  INSERT INTO TMP_PACHETEOBJLINK_I(CODIES1, CODPACHETEOBJL, CANT)
  SELECT PL.CODIES1, PL.CODPACHETEOBJL, PL.CANT
  FROM PACHETEOBJLINK PL
       INNER JOIN PACHETEOBJL POBJL ON POBJL.CODPACHETEOBJL = PL.CODPACHETEOBJL
  WHERE PL.CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);

  IF TIPIES= 26  THEN
-- INCERC SA REFAC PRELURILE DE PE AVIZELE STINSE DE FACT LA AVIZ

    DELETE TMP_IESLINK;
    INSERT INTO TMP_IESLINK (CODLINIEAVIZ)

    SELECT IL.CODLINIEAVIZ
    FROM
     IESLINK IL,
     IESIRI1 I1,
     IESIRI1 I1AE
    WHERE
      I1.CODIES = RECID
      AND IL.CODIES1   = I1.CODIES1
      AND I1AE.CODIES1 = IL.CODLINIEAVIZ
      AND I1AE.PU       &lt;&gt; I1.PU;
  END IF;


  DELETE FROM IESLINK  WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  DELETE FROM IESLINK  WHERE CODLINIEAVIZ IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  --insert into tmp_iesprodlink_initial(codies1, codcmdprodmat, cant, codliniecomanda) select * FROM IESPRODLINK WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  DELETE FROM IESPRODLINK WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  DELETE PACHETELINK WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  DELETE PACHETEOBJLINK WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);
  DELETE FROM FACTSALINK  WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID);

  -- REACTUALIZEZ RESTURI VALORICE FARA DESCARCARE
  FOR V_REC IN (SELECT * FROM IESVALLINK WHERE CODIES1 IS NOT NULL AND CODIES1 IN (SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID))
  LOOP
    DELETE FROM IESVALLINK WHERE CODIES1 = V_REC.CODIES1;
    UPDATE LIVR1 L1
    SET L1.RESTIESVAL = L1.CANT -
              (SELECT NVL(SUM(IL.CANT), 0)
              FROM
                IESVALLINK IL
                LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
              WHERE
                IL.CODLIVR1 = L1.CODLIVR1 AND
                IL.CODIES1 = I1.CODIES1   AND
                I.CODIES = I1.CODIES      AND
                I.OPERAT = 1 AND I.ANULAT = 0
              )
    WHERE CODLIVR1 = V_REC.CODLIVR1;
  END LOOP;


  -- REACTUALIZEZ RESTURI ARTICOLE COMPUSE VALORICE FARA DESCARCARE
  FOR V_REC IN (SELECT * FROM IESVALLINK WHERE CODIES1 IS NULL AND CODIES = RECID)
  LOOP
    DELETE FROM IESVALLINK WHERE CODIES = RECID;
    UPDATE LIVR1 L1
    SET L1.RESTIESVAL = L1.CANT -
              (SELECT NVL(SUM(IL.CANT), 0)
              FROM
                IESVALLINK IL,
                IESIRI I
              WHERE
                IL.CODIES1 IS NULL
                AND IL.CODLIVR1 = L1.CODLIVR1
                AND IL.CODIES = I.CODIES
                AND I.OPERAT = 1 AND I.ANULAT = 0
              )
    WHERE CODLIVR1 = V_REC.CODLIVR1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM IESIRI1 WHERE CodIES = RecId)
  LOOP
    UPDATE CANTAR  SET TipDoc = NULL, CodDoc1 = NULL           WHERE TipDoc    = TIPIES AND CodDoc1        = V_REC.CodIes1;
    UPDATE BCAR    SET TipDoc = NULL, CodDoc1 = NULL           WHERE TipDoc    = TIPIES AND CodDoc1        = V_REC.CodIes1;
    UPDATE IESIRI1 SET TIPDOCIMP = NULL, CODLINIEDOCIMP = NULL WHERE TipDocIMP = TIPIES AND CodLinieDocIMP = V_REC.CodIes1;

/*    IF EXISTAIESIRI1 &gt; 0 THEN
       EXECUTE IMMEDIATE &apos;DELETE FROM IESIRI1EXT WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;
    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;MONETAR1EXT&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM MONETAR1EXT WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;

    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;DIMIN1EXT&apos;)  = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM DIMIN1EXT WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;

    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;MARIRI1EXT&apos;)  = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM MARIRI1EXT WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;

    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;BONCONS1EXT&apos;)  = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM BONCONS1EXT WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;

    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;IES1SUB&apos;)  = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM IES1SUB WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;

    IF PKG_LIST_STRUCT.TMPEXISTS(&apos;IES1BF&apos;)  = 1 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM IES1BF WHERE CODIES1 = &apos;|| V_REC.CODIES1;
    END IF;*/


  END LOOP;
/*
  IF EXISTAIESIRI &gt; 0 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM IESIRIEXT WHERE CODIES = &apos;|| RECID;
  END IF;


   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;MONETAREXT&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM MONETAREXT WHERE CODIES = &apos;|| RECID;
   END IF;

   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;DIMINEXT&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM DIMINEXT WHERE CODIES = &apos;|| RECID;
   END IF;

   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;MARIRIEXT&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM MARIRIEXT WHERE CODIES = &apos;|| RECID;
   END IF;

   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;BONCONSEXT&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM BONCONSEXT WHERE CODIES = &apos;|| RECID;
   END IF;

   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;IESSUB&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM IESSUB WHERE CODIES = &apos;||RECID;
   END IF;

   IF PKG_LIST_STRUCT.TMPEXISTS(&apos;IESBF&apos;)  = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM IESBF WHERE CODIES = &apos;||RECID;
   END IF;*/



  DELETE FROM IESDISC  WHERE CODIES = RECID;
  DELETE FROM IESIRI1  WHERE CODIES = RECID ;
  DELETE FROM IESIRI   WHERE CODIES = RECID ;


  IF TIPIES = 26 THEN
-- INCERC SA REFAC PRELURILE DE PE AVIZELE STINSE DE FACT LA AVIZ

    StornoAvize := &apos;2&apos;;
    SELECT pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO StornoAvize from dual;


    DELETE TMP_JURNAL_MAN;
    FOR V_REC IN (SELECT * FROM TMP_IESLINK)
    LOOP
      PKG_Jurnal.setDirtyIesAE(V_REC.CODLINIEAVIZ, aCurs);
      INSERT INTO TMP_JURNAL_MAN(CODDOC, TIPDOC) VALUES(V_REC.CODLINIEAVIZ, 26);

      IF StornoAvize = &apos;1&apos; THEN
        FOR V_REC_STORNO IN (SELECT I1.CODIES1, I1A.PU AS PRETNOU FROM IESIRI1 I1, IESIRI I, IESIRI1 I1A
                             WHERE
                               I.TIPDOC = 20
                               AND I1.CODIES = I.CODIES
                               AND I1.CODIES1STORNO = V_REC.CODLINIEAVIZ
                               AND I1.CANT &lt; 0
                               AND I1A.CODIES1 = V_REC.CODLINIEAVIZ
                            )
        LOOP
          PKG_Jurnal.setDirtyIesAE_Storno(V_REC_Storno.CODIES1, V_REC_Storno.PRETNOU, aCurs);
        END LOOP;
      END IF;
    END LOOP;
  END IF;


  -- REALOC IN DOCFREE NUMARUL DE DOCUMENT STERS
  IF TIPIES IN (14, 15, 16, 19, 20, 21, 22, 23, 24, 26) and COALESCE(aCARNETDOC, 0) &gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
  END IF;

  -- ObligPIF + GENERAL + STINGERE

  DELETE TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF)
  (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN
     (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPIES)
   );

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF)
  SELECT CODSTINGERE, CODSTINSPIF FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

-- ordinea de stergere trebuie pastrata pentru a nu viola un constraint
  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);
  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);
--  DELETE FROM GENERAL  WHERE CODDOC = RecID AND TIPDOC = TIPIES;

  FOR V_REC IN (SELECT CODGENERAL FROM GENERAL G WHERE CODDOC = RecID AND TIPDOC = TIPIES)
  LOOP
    DELETE FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;

    FOR V_RECREG IN (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
    LOOP
      UPDATE JURNAL1
      SET DIRTY = 1
      WHERE TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
    END LOOP;
  END LOOP;


  UPDATE OBLIGPIF O
  SET
    REST =
      (CASE
         WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END),
    RESTTVA =
      (CASE
         WHEN VALOARE &gt; 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0) + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END)

  WHERE O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);

-- REACTUALIZEZ STOCURILE IMPLICATE IN STERGERE

  UPDATE NIRSTOC NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
  WHERE NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);

  UPDATE NIRSER NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM2)
  WHERE NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);

  -- CURAT SI IESIRILE IN ROSU
  FOR V_RECNIR IN (SELECT * FROM NIR WHERE TIPNIR = TIPIES AND CODIES = RECID) LOOP

    FOR V_RECNIRSTOC IN (SELECT * FROM NIRSTOC WHERE CODNIR = V_RECNIR.CODNIR) LOOP
      DELETE FROM NIRSER   WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
      DELETE FROM NIRSTOC  WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
      DELETE FROM REZERVATS WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
      DELETE FROM NIRSTOC1 WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
    END LOOP;

    DELETE FROM NIR      WHERE CODNIR = V_RECNIR.CODNIR;
    DELETE FROM INTRARI1 WHERE CODINTR = V_RECNIR.CODINTR;
    DELETE FROM INTRARI  WHERE CODINTR = V_RECNIR.CODINTR;
  END LOOP;

  -- AM STERS FACTURA LA AVIZ; ACTUALIZEZ RESTURILE PE AVIZE
  IF TIPIES = 26 THEN
    UPDATE IESIRI1 I1
    SET
    I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                   IESLINK IL
                   LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                   LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26 AND II.OPERAT = 1 AND II.ANULAT = 0
                 AND IL.CODLINIEAVIZ IN (SELECT CODIES1 FROM TMP_IESIRI1)
                ) +
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  IESIRI1 AE1,
                  IESIRI  AE
                WHERE
                  AE1.CODIES1STORNO =I1.CODIES1 AND AE.CODIES = AE1.CODIES
                  AND  AE1.CODIES1STORNO IN (SELECT CODIES1 FROM TMP_IESIRI1)
                  AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
    WHERE I1.CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);
  ELSIF TIPIES IN (14, 16, 19, 20, 21, 23) THEN
    --  AM STERS FACTURI CARE STING COMENZI; REACTUALIZEZ RESTUL PE COMENZI
    UPDATE COMANDA1 C1
    SET
      C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                  ( SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                    IESLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                    WHERE
                    IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTOPERAT) = 1 AND II.ANULAT = 0
                    ) -
                ( SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                  CMDLIVRLINK IL
                  LEFT OUTER JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                  LEFT OUTER JOIN COMANDA  II ON II.CODCOMANDA    = II1.CODCOMANDA
                  WHERE
                  IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                  )
    WHERE C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1);

    --efectul invers al constatei FACTBLOCKCMD
    IF TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;FACTBLOCKCMD&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) = 1 and
       TIPIES IN (19, 20, 21, 23) THEN
      UPDATE COMANDA C SET BLOCAT = 0 WHERE EXISTS (SELECT C1.CODCOMANDA FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND
                                                    C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1));
    END IF;
    IF TIPIES = 19 THEN
      FOR V_REC IN (SELECT A.CLASA, T.CODCOMANDA, COALESCE(FACT.VALOARE,0) FACTURAT
                    FROM TMP_COMANDA T
                         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = T.CODCOMANDA
                         INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                         INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL AND A.CLASA = T.CODCONTRACT
                         LEFT  JOIN (SELECT SUM(VALOARE) VALOARE, CODCLASEA, CODCOMANDA
                                     FROM FACTSALINK
                                     GROUP BY CODCLASEA, CODCOMANDA
                                    ) FACT ON FACT.CODCLASEA = A.CLASA AND FACT.CODCOMANDA = T.CODCOMANDA
                   ) LOOP
        UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                              WHERE C1.CODOBIECT = O.CODOBIECT
                                                                    AND O.CODARTICOL = A.CODARTICOL
                                                                    AND A.CLASA = V_REC.CLASA
                                                                    AND A.TIPARTICOL = &apos;0&apos;
                                                             )
                                                      AND C1.CODCOMANDA = V_REC.CODCOMANDA AND C1.MODINCHIDERE = 2;
        UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                              WHERE C1.CODOBIECT = O.CODOBIECT
                                                                    AND O.CODARTICOL = A.CODARTICOL
                                                                    AND A.CLASA = V_REC.CLASA
                                                                    AND A.TIPARTICOL = &apos;1&apos;
                                                             )
                                                      AND C1.CODCOMANDA = V_REC.CODCOMANDA AND COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT;
        IF V_REC.FACTURAT &gt;= 0 THEN
          AVALOARE := V_REC.FACTURAT;
          FOR V_TMP IN (SELECT C1.CODCOMANDA1, C1.CANTACCEPTAT*C1.PU VALOARE
                        FROM COMANDA1 C1
                             INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                             INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
                        WHERE C1.CODCOMANDA = V_REC.CODCOMANDA AND A.CLASA = V_REC.CLASA
                              AND ((C1.MODINCHIDERE = 2 AND A.TIPARTICOL = &apos;0&apos;) OR (COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT AND A.TIPARTICOL = &apos;1&apos;))
                       ) LOOP
            IF AVALOARE &lt; V_TMP.VALOARE THEN
              UPDATE COMANDA1 SET CANTRETURNAT = AVALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
              AVALOARE := 0;
            ELSE
              UPDATE COMANDA1 SET CANTRETURNAT = V_TMP.VALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
              AVALOARE := AVALOARE - V_TMP.VALOARE;
            END IF;
            IF AVALOARE &lt;= 0 THEN EXIT; END IF;
          END LOOP;
        END IF;
      END LOOP;
    END IF;
  ELSIF TIPIES IN (24) THEN
    --  AM STERS FACTURI CARE STING COMENZI; REACTUALIZEZ RESTUL PE COMENZI

    UPDATE COMANDA1 C1
    SET
      C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                  ( SELECT COALESCE(SUM(IL.CANT), 0)
                    FROM
                    IESLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                    WHERE
                    IL.CODLINIECOMANDA = C1.CODCOMANDA1 AND II.ANULAT = 0
                    )
    WHERE C1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1 where codcomanda1 &gt; 0) AND C1.MODINCHIDERE = 2;

    UPDATE CMDPRODMAT C1
    SET
      C1.REST = C1.CANT -
                  ( SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                    IESPRODLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                    WHERE
                    IL.CODCMDPRODMAT = C1.CODCMDPRODMAT  AND II.OPERAT = 1 AND II.ANULAT = 0
                    )
    WHERE C1.CODCMDPRODMAT IN (SELECT CODCOMANDA FROM TMP_COMANDA1 where codcomanda &gt; 0);
    for v_rec in (select c1.codcomanda1
                  from comanda1 c1
                       inner join comanda c on c.codcomanda = c1.codcomanda
                       inner join tmp_iesiri1 i1 on c1.codcomanda1 = i1.codcmdint1
                  where c.tipdoc = 92 and c1.modinchidere = 2
                  ) loop
      update comanda1 c1
      set
      restacceptat = cantacceptat -
      (select nvl(sum(i1.cant),0)
       from iesiri1 i1
            inner join iesiri i on i.codies = i1.codies
       where i1.codcmdint1 = v_rec.codcomanda1 and i.tipdoc = 24
       )
       where codcomanda1 = v_rec.codcomanda1;
    end loop;
  END IF;


  IF TIPIES = 20 THEN -- REACTUALIZEZ RESTURI AVIZE STORNATE
    UPDATE IESIRI1 I1
    SET
      I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                   IESLINK IL
                   LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                   LEFT OUTER JOIN IESIRI  II  ON II.CODIES   = II1.CODIES
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26 AND II.OPERAT = 1 AND II.ANULAT = 0
                ) +
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  IESIRI1 AE1,
                  IESIRI  AE
                WHERE
                  AE1.CODIES1STORNO =I1.CODIES1 AND AE.CODIES = AE1.CODIES
                 AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
    WHERE EXISTS (SELECT CODIES1STORNO FROM IESIRI1_MAN WHERE CODIES1STORNO = I1.CODIES1);
  END IF;

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = TIPIES) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  -- ACTUALIZARE REZERVARESTOC
  FOR V_REC IN (
    SELECT
      IL.CODLINIECOMANDA,
      NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
      NVL(L1.CODNIRSER,0)  AS CODNIRSER,
      CASE WHEN COALESCE(LV.CODLIVRVAL,0) = 0 THEN L1.CANTREZERVAT ELSE L1.CANT END CANTREZERVAT
    FROM TMP_LIVR1_INITIAL L1
         LEFT JOIN TMP_LIVRVAL_INITIAL LV ON LV.CODLIVR1 = L1.CODLIVR1,
         TMP_IESLINK_INITIAL IL
    WHERE L1.CODIES1 = IL.CODIES1
  )
  LOOP
    UPDATE REZERVATS
    SET
--      CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT,
      REST         = REST         + COALESCE(V_REC.CANTREZERVAT,0)
    WHERE CODCOMANDA1       = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
  END LOOP;

-- CAZ DEPACO : REZERVARILE SUNT PE CODCOMAND1ORIG
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;REZERVCMDORIG&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO REZERVCMDORIG FROM DUAL;
    EXCEPTION WHEN OTHERS THEN REZERVCMDORIG := 0;
  END;

  IF REZERVCMDORIG = 1 THEN
    FOR V_REC IN (
      SELECT
        IL.CODCOMAND1ORIG,
        NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
        NVL(L1.CODNIRSER,0)  AS CODNIRSER,
        L1.CANTREZERVAT
      FROM
        TMP_LIVR1_INITIAL L1,
        TMP_IESLINK_INITIAL IL
      WHERE L1.CODIES1 = IL.CODIES1
    )
    LOOP
      UPDATE REZERVATS
      SET
--        CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT,
        REST         = REST         + V_REC.CANTREZERVAT
      WHERE CODCOMANDA1       = V_REC.CODCOMAND1ORIG
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
    END LOOP;
  END IF;


  -- ACTUALIZARE REZERVARESTOC MATERIALE
  FOR V_REC IN (
    SELECT
      GetLinieComCli(IL.CODLINIECOMANDA) CODLINIECOMANDA,
      NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
      NVL(L1.CODNIRSER,0) AS CODNIRSER,
      L1.CANTREZERVAT
    FROM
      TMP_LIVR1_INITIAL L1,
      TMP_IESPRODLINK_INITIAL IL
    WHERE L1.CODIES1 = IL.CODIES1
  )
  LOOP
    UPDATE REZERVATS
    SET
--      CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT,
      REST         = REST         + V_REC.CANTREZERVAT
    WHERE CODCOMANDA1       = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_PACHETELINK_INITIAL) LOOP
    UPDATE PACHETEOBJ POBJ
    SET REST = CANT - COALESCE((SELECT NVL(SUM(PL.CANT),0)
                       FROM PACHETELINK PL
                       WHERE PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ),0)
    WHERE POBJ.CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_PACHETEOBJLINK_I) LOOP
    UPDATE PACHETEOBJL POBJ
    SET REST = CANT - COALESCE((SELECT NVL(SUM(PL.CANT),0)
                       FROM PACHETEOBJLINK PL
                       WHERE PL.CODPACHETEOBJL = POBJ.CODPACHETEOBJL),0)
    WHERE POBJ.CODPACHETEOBJL = V_REC.CODPACHETEOBJL;
  END LOOP;

/*
FOR V_REC IN
(SELECT * FROM REZERVATS RS
 WHERE
   EXISTS (SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL WHERE CODLINIECOMANDA = RS.CODCOMANDA1)
 )
 LOOP
   UPDATE REZERVATS RS
   SET
     REST = CANTREZERVAT - NVL(PKG_COMANDA.LIVRAT_DIN_REZERVAT(RS.CODCOMANDA1, RS.CODNIRSTOC, RS.CODNIRSER), 0)
   WHERE
     CODREZERVATS = V_REC.CODREZERVATS;
 END LOOP;
*/

  DELETE FROM MODURIPLATI WHERE CODIES = RECID;
  DELETE FROM MODPLATA2 WHERE CODIES = RECID;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = TIPIES;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = TIPIES;

  IF TIPIES = 19 THEN
    UPDATE CONTRACT2
    SET CODDOC  = NULL,
        TIPDOC  = NULL,
        NRDOC   = NULL,
        DATADOC = NULL
    WHERE CODDOC = RecID AND TIPDOC = TIPIES;
  END IF;

  UPDATE EMULARE
  SET CODIES = NULL
  WHERE CODIES = RECID;

  UPDATE EMULARE
  SET CODMONETAR = NULL,
      PRELUAT    = 0
  WHERE CODMONETAR = RECID;

  UPDATE IESIRI
  SET
    CODMONETAR = NULL
  WHERE
    CODMONETAR = RECID;

  UPDATE COMANDA
  SET
    CODIESAVANS = NULL
  WHERE
    CODIESAVANS = RECID;

  DELETE FROM CMDAVANS WHERE CODIESAVANS = RECID;

  IF (TIPIES = 15)AND(NVL(aTIPTVA, 0) = 1) THEN
    INSERT INTO IESIRI1_MAN(CODIES1) SELECT CODIES1 FROM TMP_IESIRI1;
    CHECK_REZERVARI_CLONARE_IN;
  END IF;

  if tipies = 24 then
    delete tmp_manevra;
    insert into tmp_manevra(codunic) select codunic from tmp_manevra2;
    pkg_pretprod.SetDirtyStructura;
  end if;

  -- FUNCTIONARE CONSTANTA InchidLinieCmd
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;InchidLinieCmd&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO InchidLinieCmd FROM DUAL;
    EXCEPTION WHEN OTHERS THEN InchidLinieCmd := &apos;0&apos;;
  END;
  IF InchidLinieCmd = &apos;1&apos; THEN
    FOR V_REC IN (SELECT C1.CODCOMANDA1, NVL(PKLINK.CODPACHETEOBJ,0) CODPACHETEOBJ, C1.CANTCOMANDAT
                  FROM TMP_IESLINK_INITIAL IL
                       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = IL.CODLINIECOMANDA
                       INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
                       LEFT JOIN PACHETEDLLINK PKLINK ON PKLINK.CODCOMANDA1 = C1.CODCOMANDA1
                  WHERE C.TIPDOC = 18 AND C.DISPLIVRARE = 1) LOOP
      UPDATE COMANDA1 SET CANTACCEPTAT = V_REC.CANTCOMANDAT WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      IF V_REC.CODPACHETEOBJ &gt; 0 THEN
        UPDATE PACHETEDLLINK SET CANT = V_REC.CANTCOMANDAT WHERE CODCOMANDA1 = V_REC.CODCOMANDA1 AND CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
        UPDATE PACHETEOBJ SET REST = CANT - NVL((SELECT SUM(CANT) FROM PACHETELINK WHERE CODPACHETEOBJ = V_REC.CODPACHETEOBJ),0)
                                          - NVL((SELECT SUM(CANT) FROM PACHETEDLLINK WHERE CODPACHETEOBJ = V_REC.CODPACHETEOBJ),0)
        WHERE CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
      END IF;
    END LOOP;
  END IF;


  DELETE FROM IESPUNCTE WHERE CODIES = RECID;

  DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIes);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIes;

  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = TIPIes)or(CODDOCASOC = RECID AND TIPDOCASOC = TIPIes);
  DELETE FROM Reclamatii WHERE CODDOC = RECID AND TIPDOC = TIPIes;

  DELETE TMP_LIVR1;

  DELETE FROM VOUCHERCADOULINK WHERE TIPDOC = TIPIES AND CODDOC = RECID;

  NotifyModif(2, RecId, &apos;IESIRI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN

  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(PKG_GLOBALS.GetTipIesire);
  PKG_CFGTABLES.EXT_INSERTRECORD(PKG_GLOBALS.GetTipIesire);
  INSERT INTO  TMP_IESIRI FIELDS( CODIES, CONTDISCOUNT ) VALUES (0, 0) ;

  --asta cu ContDiscount ZERO e o smecherie pentru monetare, ca sa corectez inregistrari contabile
  -- nu schimba
  COMMIT;
END;

PROCEDURE SetValFin(RecId IN NUMBER, pForce IN NUMBER DEFAULT 0) IS
  vTipDoc NUMBER;
  vFlags  NUMBER;
  notOK   BOOLEAN;
BEGIN
  SELECT Coalesce(Flags, 0), TipDoc INTO vFlags, vTipDoc FROM IESIRI WHERE CodIes = RecId;
  IF vTipDoc IN (16, 19, 21, 26) THEN
    notOK := (BITAND(vFlags, Flag_SetValFin) =  0);

    IF pForce = 1 OR notOK THEN
      IF vTipDoc = 16 THEN
        MONETARE_CALC_DISCLIN(RecId);
        UPDATE IESIRI1 I1 SET (VALFIN, TVAFIN) = (SELECT DI.LINVAL+DI.DISCVAL, DI.LINTVA+DI.DISCTVA FROM TMP_MON_DISCLIN DI WHERE DI.CODIES1 = I1.CODIES1) WHERE I1.CODIES = RecId;
      ELSE
        IESIRI_CALC_DISCLIN(RecId);
        UPDATE IESIRI1 I1 SET (VALFIN, TVAFIN) = (SELECT DI.LINVAL+DI.DISCVAL, DI.LINTVA+DI.DISCTVA FROM TMP_IES_DISCLIN DI WHERE DI.CODIES1 = I1.CODIES1) WHERE I1.CODIES = RecId AND NOT I1.TIPLINIE IN (&apos;G&apos;,&apos;T&apos;);
      END IF;
    END IF;

    IF notOK THEN
      vFlags := vFlags + Flag_SetValFin;
      UPDATE IESIRI SET FLAGS = vFlags WHERE CodIes = RecId;
    END IF;
  END IF;
END;

PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
  TIPIES               NUMBER(20);
  TIPTRANZ             NUMBER(20);
  aCODPART             NUMBER(20);
  ANPREC               NUMBER(5);
  LUNAPREC             NUMBER(2);
  aRotEFact            NUMBER(1);
  aDATADOC             DATE;
  vCount               number;
  LUNAREF              PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
  IOPART1REC           IOPART1 % ROWTYPE;
  aCODSUBUNITSTINS     NUMBER(20);
  TIPPREFIX            VARCHAR2(20);
  aCODLinieComanda     NUMBER(20);
  aTotDiscOffInvoiceF  number(20,7);
  aTotDiscOffInvoiceC  number(20,7);
  aContIncasareFactura varchar2(10);
  pAn                  NUMBER(5);
  pLuna                NUMBER(5);
  part_car_luna        NUMBER;
  AnLunaLucru          NUMBER;
BEGIN
  --MASTER IESIRI

  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(PKG_GLOBALS.GetTipIesire);

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  --asta e inainte de TMP_Iesiri
  INSERT INTO Tmp_Iesdisc (CODIESDISC, CODIES, CODDISCOUNT, OFFINVOICE, PROCENT, CodObiect, DenObiect, Valoare, CodCategDisc, Cumulat)
  SELECT i.CODIESDISC, i.CODIES, i.CODDISCOUNT, i.OFFINVOICE, i.PROCENT, i.CodObiect, O.Denumire, i.Valoare, d.CODCRITERIU, C.Cumulat
  FROM IesDisc i, Discount D, CriteriiDisc C, NArtObj O
  WHERE CODIES = RECID and D.CodDiscount = i.CodDiscount and O.CodObiect = Nvl(i.CodObiect,0) and D.CODCRITERIU = C.CODCRITERIU;

  BEGIN
    SELECT Sum(Nvl(Procent, 0)) INTO aTotDiscOffInvoiceC FROM Tmp_Iesdisc WHERE OffInvoice = 2;
  EXCEPTION
    WHEN OTHERS THEN aTotDiscOffInvoiceC := 0;
  END;

  BEGIN
    SELECT Sum(Nvl(Procent, 0)) INTO aTotDiscOffInvoiceF FROM Tmp_Iesdisc WHERE OffInvoice = 3;
  EXCEPTION
    WHEN OTHERS THEN aTotDiscOffInvoiceF := 0;
  END;

  -- asta de sus e inainte de TMP_Iesiri
  INSERT INTO TMP_IESIRI (
    CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
    NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED, TIPTVA, COMISION, NUMEDELEGAT,
    PARTENERCOMUNITAR, simbautotara, SUBUNITATEA,
    MONEDA, CURS, MIJLTRANSP, LISTAT, CUSTODIE, FARATRANSPORT,StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, SCADENTESETATEMANUAL, DISCOUNTPART, COLDISCPART, MONEDATRANSF, NRI, CONTSUPLIM,
    CARNETCERTIF, NRCERTIF, SERIACERTIF, LISTATCERTIF, ExclusPlata, ExclusIntrastat,PROCTVADOC, FaraReg, TVAIncasare, DataTVA, UserID, CODANALIZA, CODCONTRACT, FACTSIMPLIF, TRANSPORTATOR, CodPartTERT, CODAECUSTODIE,
    TotDiscOffInvoiceF,TotDiscOffInvoiceC, MAJORARICLIENT, STADIUWMS, CODMONETAR, NUMARBONURI, EMISADECLIENT, NRINFOCM, NRINCASULT, NRINCASIM,TIPLIVRARE, NATURATRANZ, MODTRANSP, SPLITTVA, GRATIE,
    TipSAFT, RotEFact, FLAGS, iddescarcare, valdocefact,CODTVASERV, PROCTVAOSS,CODCONTTVAOSS,
    EF_IDINCARCARE, EF_IDDESCARCARE,  EF_TIPMEDIU, EF_Status, Is_ETRANSP, TipET,  UIT, ET_IDINCARCARE, ET_IDDESCARCARE, ET_TIPMEDIU, ET_STATUS, NOACCIZE, NRNIR, DATANIR, PLATFORMA_ONLINE,
    REMORCA, PROIECT, CONTRACT, COMANDA
    )
  SELECT
    CODIES, I.TIPDOC, ANULAT, I.BLOCAT, OPERAT, PREFIXDOC, I.CODBANKCONT, I.TIPCASAMARCAT, I.TIPTRANZACTIE, CARNETDOC,
    NRDOC, DATADOC, PARTENER, I.CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, I.MAJORARI, I.OBS, I.AN, I.LUNA, I.CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED, TIPTVA, COMISION,
    NVL((SELECT SUBSTR(DELEGAT,1, 50) FROM NPARTTR WHERE CODPARTTR = I.DELEGAT), &apos;&apos;),
    T.STATCOMUNITAR, Coalesce(T.SIMBAUTO, &apos;RO&apos;), I.SUBUNITATEA,
    I.MONEDA, I.CURS, I.MIJLTRANSP, I.LISTAT,  I.CUSTODIE, I.FARATRANSPORT,I.StareRestituire, I.IDIMPORT,  I.TIPCHELT, I.CODPERSC, I.INFOCM, I.CURSDOC,  I.NRTRANSP, 1, P.DISCOUNT, P.COLDISCOUNT, I.MONEDATRANSF, I.NRI, I.CONTSUPLIM,
    CARNETCERTIF, NRCERTIF, SERIACERTIF, LISTATCERTIF, I.ExclusPlata, I.ExclusIntrastat, I.PROCTVADOC, I.FaraReg, I.TVAIncasare, DataTVA, I.UserID, I.CODANALIZA, CODCONTRACT, FACTSIMPLIF, I.TRANSPORTATOR, I.CodPartTERT, CODAECUSTODIE,
    aTotDiscOffInvoiceF, aTotDiscOffInvoiceC, P.MAJORARI, I.STADIUWMS, I.CODMONETAR, I.NUMARBONURI, I.EMISADECLIENT, I.NRINFOCM, I.NRINCASULT, I.NRINCASIM,I.TIPLIVRARE, i.NATURATRANZ, i.MODTRANSP, I.SPLITTVA, I.GRATIE,
    Coalesce(I.TipSAFT, 0), Coalesce(RotEFact, 0), Coalesce(FLAGS, 0), I.iddescarcare, I.valdocefact,I.CODTVASERV, PROCTVAOSS,tsr1.codcont,
    E.IDINCARCARE, E.IDDESCARCARE,  E.TIPMEDIU, Coalesce(E.STARE,&apos;?&apos;),
    Is_ETRANSP,
    TipET, ET.UIT, ET.IDINCARCARE, ET.IDDESCARCARE, ET.TIPMEDIU, Coalesce(ET.STARE,&apos;?&apos;), coalesce(I.Noaccize,0), I.NRNIR, I.DATANIR, I.PLATFORMA_ONLINE,
    I.REMORCA, I.PROIECT, I.CONTRACT, I.COMANDA
  FROM IESIRI I
    LEFT JOIN NPART    P ON P.CODPART    = I.PARTENER
    LEFT JOIN NAGENDA  A ON A.CODAGENDA = I.CODLOCATIE
    LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT JOIN NTARI    T ON T.CODTARA    = L.CODTARA
    LEFT JOIN StatusDecl E ON E.CodDoc = I.CodIes and E.TipDoc = I.TipDoc
    LEFT JOIN StatusDecl ET ON ET.CodDoc = I.CodIes and ET.TipDoc = 100 + I.TipDoc
    LEFT JOIN tvaserv1 tsr1 on tsr1.codtvaserv = I.Codtvaserv
                                                                 and (i.an*12+i.luna) BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
  WHERE CODIES = RECID;

  BEGIN
    SELECT DATADOC, CURS, PARTENER, TIPDOC, TIPTRANZACTIE, An, Luna, RotEFact, AN * 12 + LUNA
    INTO   aDATADOC, CURS_IN, aCODPART, TIPIES, TIPTRANZ, pAn, pLuna, aRotEFact, AnLunaLucru FROM TMP_IESIRI;
    EXCEPTION WHEN OTHERS THEN aDATADOC := TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;);
  END;

  INSERT INTO TMP_MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
  SELECT * FROM MODURIPLATI WHERE CODIES = RECID;

  INSERT INTO TMP_MODPLATA2(CODMODPLATA2, CODIES, CODCARD, VALOARE, SIMBOL, DENUMIRE)
  SELECT MP2.CODMODPLATA2, MP2.CODIES, MP2.CODCARD, MP2.VALOARE, C.SIMBOL, C.DENUMIRE
  FROM
    MODPLATA2 MP2
    LEFT JOIN CARDURI C ON C.CODCARD = MP2.CODCARD
  WHERE CODIES = RECID;

  INSERT INTO TMP_DISCMONETAR(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
  SELECT CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT FROM DISCMONETAR WHERE CODIES = RECID;

  INSERT INTO TMP_IESPUNCTE(CODIESPUNCTE, CODIES, PUNCTEDOC, PUNCTEANULATE, PUNCTESTINSE, BLOCAT)
  SELECT CODIESPUNCTE, CODIES, PUNCTEDOC, PUNCTEANULATE, PUNCTESTINSE, BLOCAT FROM IESPUNCTE WHERE CODIES = RECID;

  INSERT INTO TMP_TVAMONETAR (CODTVAMONETAR, CODIES, CODTVA, VALOARE, TVA, PROCENT, BONURI)
  SELECT T.CODTVAMONETAR, T.CODIES, T.CODTVA, T.VALOARE, T.TVA, TL.PROCENT, T.BONURI
  FROM TVAMONETAR T, TMP_NTVA_LUNA TL
  WHERE T.CODIES = RECID
    AND T.CODTVA = TL.CODTVA
  ORDER BY TL.PROCENT;

  DELETE IESIRI1_MAN;
  INSERT INTO IESIRI1_MAN SELECT * FROM IESIRI1 WHERE CODIES = RECID;

  part_car_luna := PKG_NOMPART.GET_PART_COD_CARACT_LUNA(aCODPART, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);

  INSERT INTO TMP_IESIRI1 (
    CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT,
    PRETORIG,
    PU,
    CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMaximal, AdMax, GARANTIE,
    DENUM,
    DENUMCORELAT,
    VALOARE,
    PARITATE,
    PROCTVA,
    CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG,
    CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, CODCLASA, DENOBIECT, ROTUNJIRE,
    CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,
    PRETPROMO, TIPPLATA,CODCENTRU, CODCADOU, CODOBLIGMONETAR,
    COEFUM_CANTAR,
    PROMOTIE, CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CUSTODIEINTRARE, CODAUTO, CMDINT, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT, CODAGENTEMULARE, CODPROMO1,
    CODCONTRACT1, VALDISCPRET, Preluat, CODMIFIX, CONTRACT, CODEXTERN, CODINTERN,
    PUREAL,
    DENCLASA, UM1, RELATIEUM1, ICONTPART, CANTCONSTATAT, DISCMANUAL, CODUTILAJ,
    SIMBOLIOPART,
    D1,D2,D3,CantUM1, COSTTRANSPORT, PRETUM1, IMPOZABIL, UM2, CODSERIE, CODPARTCOMISEMUL, VALFIN, TVAFIN, TAXCODE, CODVAMAL, CODCPV, RISCFISCAL)
  SELECT
    I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU, I1.MIFIX, I1.ZILE, I1.ZILECMD, I1.GESTACT, I1.CODOBIECT,
    PKG_IESIRI.PRETVANZARE(TIPIES, Coalesce(O.ROTVALUTA, 0), I1.PRETORIG, Coalesce(U1.PARITATE,1), 0) AS PRETORIG,
    PKG_IESIRI.PRETVANZARE(TIPIES, Coalesce(O.ROTVALUTA, 0), I1.PU,       Coalesce(U1.PARITATE,1), 0) AS PU,
    I1.CANT/Coalesce(U1.PARITATE, 1) CANT, I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM, I1.RESTFACT, I1.PUMaximal, I1.AdMax, I1.GARANTIE,
    CASE WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos; ELSE U1.DEN_UM1 END DENUM,
    CASE WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos; ELSE U2.DEN_UM1 END DENUMCORELAT,
    CASE
      WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN
        CASE
          WHEN aRotEFact = 1
          THEN ROUND((I1.CANT/Coalesce(U1.PARITATE,1)) * PKG_IESIRI.PRETVANZARE(TIPIES, Coalesce(O.ROTVALUTA, 0), I1.PU, Coalesce(U1.PARITATE,1), 0), 2)
          ELSE       (I1.CANT/Coalesce(U1.PARITATE,1)) * PKG_IESIRI.PRETVANZARE(TIPIES, Coalesce(O.ROTVALUTA, 0), I1.PU, Coalesce(U1.PARITATE,1), 0)
        END
      ELSE I1.RESTFACT
    END VALOARE,
    Coalesce(U1.PARITATE,1) PARITATE,
    CASE WHEN I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;,&apos;R&apos;) THEN Coalesce(TVALUNA.PROCENT, 0) ELSE 0 END PROCTVA,
    I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS, I1.COEFDISCMAJ, I1.OBS, I1.CODOBIECTORIG, I1.PARITATEORIG,
    NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, A.CLASA, O.DENUMIRE, O.ROTVALUTA,
    I1.CODLIVR1PRODVAL, I1.CODIES1STORNO, I1.CODOFERTA1, I1.CADOU,I1.TAXA, I1.TERMENCONTRACT, I1.CADOULINK, I1.CODIOARTCUST, I1.UMCorelat, I1.CANTCorelat, I1.PUCorelat,
    I1.PRETPROMO, I1.TIPPLATA, I1.CODCENTRU, I1.CODCADOU, I1.CODOBLIGMONETAR,
    CASE WHEN Coalesce(u.tipum,0) = 1 THEN u.coef ELSE 0 END COEFUM_CANTAR,
    O.PROMOTIE, I1.CODLINIEDOCIMP, I1.TIPDOCIMP, I1.CODCMDINT1, I1.CUSTODIEINTRARE, I1.CODAUTO, C.NRDOC, I1.CODANALIZANOD, I1.D1D3BCS, I1.CODOBLIGMAJORAT, I1.CODAGENTEMULARE, I1.CODPROMO1,
    I1.CODCONTRACT1, I1.VALDISCPRET, I1.Preluat, I1.CODMIFIX, CONTR.NRDOC, O.CODEXTERN, O.CODINTERN,
    CASE
       WHEN TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN
         PKG_IESIRI.PRETVANZARE(TIPIES, Coalesce(O.ROTVALUTA, 0), Coalesce(I1.PRETORIG, 0) * Coalesce(I1.COEFDISCMAJ, 0),       Coalesce(U1.PARITATE,1), 0)
       ELSE NULL
    END,
    SUBSTR(CLA.DEN_CLASEA, 1, 50) DENCLASA, A.UM1, A.RELATIEUM1, I1.ICONTPART, I1.CANTCONSTATAT, I1.DISCMANUAL, I1.CODUTILAJ,
    I1_SP.SIMBOLIOPART,
    I1.D1, I1.D2, I1.D3, I1.CantUM1, I1.COSTTRANSPORT,I1.PRETUM1, I1.IMPOZABIL, A.UM2, I1.CODSERIE, I1.CODPARTCOMISEMUL, I1.VALFIN, I1.TVAFIN,
    X.TAXCODE,
    O.CODVAMAL, O.CODCPV, COALESCE(A.RISCFISCAL,0)
  FROM IESIRI1_MAN I1
    LEFT JOIN (
      SELECT
        I1_AUX.ICONTPART,
        CASE
          WHEN TIPIES IN (19, 20, 21, 22, 26)
          THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG( 0, I1_AUX.ICONTPART, part_car_luna))
          ELSE NULL
        END SIMBOLIOPART
      FROM (SELECT DISTINCT I1.ICONTPART FROM IESIRI1_MAN I1 WHERE I1.CODIES = RECID) I1_AUX
    )                       I1_SP     ON I1_SP.ICONTPART = i1.ICONTPART
    LEFT JOIN NARTOBJ       O         ON O.CODOBIECT   = I1.CODOBIECT
    LEFT JOIN NART          A         ON A.CODARTICOL  = O.CODARTICOL
    LEFT  JOIN NArt1 AL ON AL.CODARTICOL = A.CODARTICOL AND AnLunaLucru BETWEEN AL.ALStart AND AL.ALStop
    LEFT JOIN NCLASEA       CLA       ON CLA.CODCLASEA = A.CLASA
    LEFT JOIN NUM1          U1        ON U1.CODUM1 = I1.UMSEC
    LEFT JOIN NUM1          U2        ON U2.CODUM1 = I1.UMCORELAT
    LEFT JOIN NUM           U         ON U.CODUM   = A.UM
    LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
    LEFT JOIN TMP_NTVA_LUNA TVALUNA   ON NART1LUNA.CODTVA     = TVALUNA.CODTVA
    LEFT JOIN comanda1      c1        ON i1.codcmdint1 = c1.codcomanda1
    LEFT JOIN comanda       c         ON c1.codcomanda = c.codcomanda
    LEFT JOIN CONTRACT1     CONTR1    ON I1.CODCONTRACT1   = CONTR1.CODCONTRACT1
    LEFT JOIN CONTRACT      CONTR     ON CONTR.CODCONTRACT = CONTR1.CODCONTRACT
    LEFT JOIN TAXDECL       X         ON TipIes &lt;&gt; 16 and X.TipDoc = TipIes and X.CODDOC = RecID and X.Coddoc1 = I1.CodIes1
  WHERE I1.CODIES = RECID
  ORDER BY I1.INDEXLOCAL;

  IF TipIes = 16 THEN
    UPDATE TMP_IESIRI1 TI1
    SET TI1.TAXCODE =
        (
          SELECT
            Case
            WHEN I1.Taxa in (3,4,5) then 310324
		        WHEN Coalesce(AL.TaxCode, 0) &gt; 0 then AL.TaxCode
		        else
						( SELECT Max(TD.TaxCode)
              FROM TAXDECL TD
              WHERE TD.TipDoc = 16 AND TD.CODDOC = I.CodIes AND Coalesce(TD.TaxCode, 0) &gt; 0
                AND TD.Coddoc1 = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TI1.PROCTVA, I.ROTEFACT, 1)
            )
  		      END
        FROM IESIRI I
					INNER JOIN Iesiri1 i1 ON I1.CodIes   = I.CodIes
          LEFT JOIN NARTOBJ       O         ON O.CODOBIECT   = I1.CODOBIECT
          LEFT JOIN NART          A         ON A.CODARTICOL  = O.CODARTICOL
          LEFT  JOIN NArt1 AL ON AL.CODARTICOL = A.CODARTICOL AND AnLunaLucru BETWEEN AL.ALStart AND AL.ALStop
          WHERE I1.CodIes1 = TI1.CodIes1
        );
  END IF;

  UPDATE TMP_IESIRI1 TI1 SET TI1.TipLivrare = (SELECT I1.TipLivrare FROM IESIRI1 I1 WHERE I1.CODIES1 = TI1.CODIES1);

  UPDATE TMP_IESIRI1 I1
  SET DENOBIECT = CASE
                    WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;G&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount pe grupul de articole precedente&apos;
                    WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;G&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de grup)&apos;

                    WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;T&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount pe toate articole precedente&apos;
                    WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;T&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de total)&apos;

                    WHEN NVL(CODCRITERIU, 0) = 2 AND TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &lt;=0 THEN &apos;Discount client &apos;
                    WHEN /* NVL(CODCRITERIU, 0)  IN  (3, 4, 5, 6, 7, 8, 9, 10) AND */ TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &lt;=0 THEN &apos;Discount: &apos; || NVL((SELECT DENCRITERIU FROM CRITERIIDISC WHERE CODCRITERIU = I1.CODCRITERIU), &apos;&apos;)
                    WHEN /* NVL(CODCRITERIU, 0)  IN  (3, 4, 5, 6, 7, 8, 9, 10) AND */ TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &gt; 0 THEN &apos;Majorare : &apos; || NVL((SELECT DENCRITERIU FROM CRITERIIDISC WHERE CODCRITERIU = I1.CODCRITERIU), &apos;&apos;)
                  END,
      SIMBOLCONTSERV = CASE WHEN CONTDISCOUNT &lt;&gt; 0 THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTDISCOUNT) || &apos;)&apos; ELSE &apos;&apos; END
  WHERE TIPLINIE IN (&apos;G&apos;, &apos;T&apos;);

  UPDATE TMP_IESIRI1 I1
  SET SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;
  WHERE TIPLINIE IN (&apos;S&apos;, &apos;V&apos;, &apos;R&apos;);

  UPDATE TMP_IESIRI1 I1
  SET
    INFOMF     = CASE
                   WHEN Coalesce(I1.CODMIFIX, 0) = 0 THEN NULL
                   ELSE (  SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE
                          FROM MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NARTOBJ O
                          WHERE MF.CODMIFIX = I1.CODMIFIX
                            AND MF.CODMIFIX = MF1.CODMIFIX
                            AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                            AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                            AND O.CODOBIECT = NS.CODOBIECT
                        )
                 END,
    I1.INFOBCAR = (SELECT NRDOC || &apos;/&apos; || TO_CHAR(datadoc, &apos;DD.MM.YYYY&apos;) FROM BCAR WHERE CODDOC1 = I1.CODIES1 AND TIPDOC = TIPIES AND ROWNUM = 1)
  WHERE TIPLINIE IN (&apos;=&apos;);

  UPDATE TMP_IESIRI1 I1
  SET UTILAJ =  CASE
                  WHEN NVL(I1.CODUTILAJ, 0)   &lt;&gt; 0 THEN (SELECT O.DENUMIRE||&apos;;&apos;||U.MODEL||&apos;;&apos;||U.SERIEF FROM UTILAJE U, NARTOBJ O WHERE U.CODUTILAJ = I1.CODUTILAJ AND U.CODOBIECT = O.CODOBIECT )
                  WHEN NVL(I1.CODCONTRACT1,0) &lt;&gt; 0 THEN (SELECT O.DENUMIRE||&apos;;&apos;||U.MODEL||&apos;;&apos;||U.SERIEF FROM CONTRACT1 C1, NARTOBJ O, UTILAJE U WHERE C1.CODCONTRACT1 = I1.CODCONTRACT1 AND C1.CODUTILAJ = U.CODUTILAJ AND U.CODOBIECT = O.CODOBIECT)
                  ELSE NULL
                END
  WHERE TIPLINIE IN (&apos;=&apos;,&apos;S&apos;);

/*
  IF PKG_LIST_STRUCT.TmpExists(&apos;IESIRIEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRIEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_IESIRIEXT SELECT * FROM IESIRIEXT WHERE CODIES = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;IESIRI1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_IESIRI1EXT SELECT * FROM IESIRI1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;MONETAREXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAREXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_MONETAREXT SELECT * FROM MONETAREXT WHERE CODIES = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;MONETAR1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_MONETAR1EXT SELECT * FROM MONETAR1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;BONCONSEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONSEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_BONCONSEXT SELECT * FROM BONCONSEXT WHERE CODIES = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;BONCONS1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_BONCONS1EXT SELECT * FROM BONCONS1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1) &apos;;
  END IF;
*/


  IF RECID &gt; 0 THEN
    SELECT TIPDOC, PARTENER  INTO TIPIES, aCODPART FROM TMP_IESIRI;

    IF  TIPIES = 26 THEN
      UPDATE TMP_IESIRI1 I1
      SET NRDOCLINK = (
        SELECT II.PREFIXDOC || &apos; &apos; || II.SERIADOC || TO_CHAR(II.NRDOC)
        FROM IESLINK IL
          LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODLINIEAVIZ
          LEFT OUTER JOIN IESIRI  II ON II.CODIES    = II1.CODIES
        WHERE IL.CODIES1 = I1.CODIES1)
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
    ELSIF TIPIES IN (16, 19, 20, 23) THEN -- LINII CE STING COMENZI
      UPDATE TMP_IESIRI1 I1
      SET NRDOCLINK = ( SELECT CC.PREFIXDOC || &apos; &apos; || CC.SERIADOC || TO_CHAR(CC.NRDOC)
                        FROM IESLINK IL
                          LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = IL.CODLINIECOMANDA
                          LEFT OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
                        WHERE IL.CODIES1 = I1.CODIES1
                      )
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
    ELSIF TIPIES = 14 THEN
      -- LINII DE PE DIMINUARI CE STING IESIRI VALORICE

     FOR V_REC IN
       (SELECT
          I1.CODIES1,
          L.CODIES,
          L.CODTRANSF,
          I.PREFIXDOC AS PREFIXIES,
          I.NRDOC AS NRDOCIES,
          T.PREFIXDOC AS PREFIXTRANSF,
          T.NRDOC AS NRDOCTRANSF
        FROM
          TMP_IESIRI1 I1,
          IESVALLINK IL
          LEFT  JOIN LIVR1 L1 ON L1.CODLIVR1   = IL.CODLIVR1
          LEFT  JOIN LIVR  L  ON L.CODLIVR     = L1.CODLIVR
          LEFT  JOIN IESIRI I  ON I.CODIES     = L.CODIES
          LEFT  JOIN TRANSF T  ON T.CODTRANSF  = L.CODTRANSF
        WHERE
          I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(I1.CODLIVR1PRODVAL, 0) = 0
          AND IL.CODIES1 IS NOT NULL AND IL.CODIES1 = I1.CODIES1
        )
     LOOP
       UPDATE TMP_IESIRI1
       SET
         NRDOCLINK =  CASE
                            WHEN NVL(V_REC.CODIES,    0) &lt;&gt; 0 THEN V_REC.PREFIXIES || TO_CHAR(V_REC.NRDOCIES)
                            WHEN NVL(V_REC.CODTRANSF, 0) &lt;&gt; 0 THEN V_REC.PREFIXTRANSF || TO_CHAR(V_REC.NRDOCTRANSF)
                            ELSE NULL
                      END
       WHERE
         CODIES1 = V_REC.CODIES1;

     END LOOP;

/*
      UPDATE TMP_IESIRI1 I1
      SET NRDOCLINK = ( SELECT
                          CASE
                            WHEN NVL(L.CODIES,    0) &lt;&gt; 0 THEN I.PREFIXDOC || TO_CHAR(I.NRDOC)
                            WHEN NVL(L.CODTRANSF, 0) &lt;&gt; 0 THEN T.PREFIXDOC || TO_CHAR(T.NRDOC)
                            ELSE NULL
                          END
                        FROM IESVALLINK IL
                          LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1   = IL.CODLIVR1
                          LEFT OUTER JOIN LIVR  L  ON L.CODLIVR     = L1.CODLIVR
                          LEFT OUTER JOIN IESIRI I  ON I.CODIES     = L.CODIES
                          LEFT OUTER JOIN TRANSF T  ON T.CODTRANSF  = L.CODTRANSF
                        WHERE IL.CODIES1 IS NOT NULL AND IL.CODIES1 = I1.CODIES1
                      )
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(I1.CODLIVR1PRODVAL, 0) = 0;
*/
      -- LINII DE PE DIMINUARI CE STING ARTICOLE COMPLEXE VALORICE
      UPDATE TMP_IESIRI1 I1
      SET NRDOCLINK = ( SELECT I.PREFIXDOC || TO_CHAR(I.NRDOC) FROM LIVR1 L1, LIVR L, IESIRI I WHERE L1.CODLIVR1 = I1.CODLIVR1PRODVAL AND L.CODLIVR = L1.CODLIVR AND I.CODIES   = L.CODIES )
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(I1.CODLIVR1PRODVAL, 0) &lt;&gt; 0;
    ELSE
      -- LINII DE PE ALTE DOCUMENTE DE IESIRE CE STING ARTICOLE COMPLEXE VALORICE
      UPDATE TMP_IESIRI1 I1
      SET NRDOCLINK = ( SELECT I.PREFIXDOC || TO_CHAR(I.NRDOC)
                        FROM IESVALLINK IL
                          LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1 = IL.CODLIVR1
                          LEFT OUTER JOIN LIVR  L  ON L.CODLIVR = L1.CODLIVR
                          LEFT OUTER JOIN IESIRI I  ON I.CODIES   = L.CODIES
                        WHERE IL.CODIES1 IS NULL
                          AND IL.CODIES = RECID
                          AND IL.CODLIVR1  = I1.CODLIVR1PRODVAL
                          AND ROWNUM = 1
                      )
      WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
    END IF;
  END IF;

  if TIPIES = 19 THEN
    FOR V_REC IN (SELECT TMP.CODIES1, C.CODCENTRALIZARE
                  FROM TMP_IESIRI1 TMP
                       INNER JOIN NOTECREDITFACT F ON F.CODDOC1 = TMP.CODIES1
                       INNER JOIN CENTRALIZARENC C ON C.CODNCREDIT = F.CODNCREDIT AND C.CODOBIECT = TMP.CODOBIECT AND TMP.PROCTVA = C.PROCTVA
                  WHERE F.TIPDOC = 19 AND
                  (
                   TMP.CODOBIECT &lt;&gt; TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAcTer&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) AND C.CODOBIECTASOC = TMP.CODOBIECTORIG
                   OR
                   TMP.CODOBIECT = TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAcTer&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) AND C.CODOBIECTASOC = TMP.CODOBLIGSTORNO
                  )
                 ) LOOP
      UPDATE TMP_IESIRI1 SET CODCENTRALIZARE = V_REC.CODCENTRALIZARE WHERE CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  IF TIPIES = 24 THEN
    UPDATE TMP_IESIRI1 I1
    SET NRDOCLINK = ( SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                      FROM IESPRODLINK IL
                        LEFT OUTER JOIN CMDPRODMAT MAT ON IL.CODCMDPRODMAT = MAT.CODCMDPRODMAT
                        LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = MAT.CODCOMANDA1
                        LEFT OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
                      WHERE IL.CODIES1 = I1.CODIES1
                    )
    WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)
      AND NVL(I1.CODLIVR1PRODVAL, 0) = 0; -- altfel AFECTEAZA LINIILE CE STING IESIRI VALORICE SI CARE SUNT TRATATE MAI SUS

    FOR V_REC IN (SELECT L.CODIES1, C.NRDOC  -- bonuri de consum de pe comenzi clienti
                 FROM
                   IESLINK L,
                   IESIRI1 I1,
                   COMANDA1 C1,
                   COMANDA C
                 WHERE
                   C.TIPDOC = 18
                   AND L.CODLINIECOMANDA = C1.CODCOMANDA1
                   AND C1.MODINCHIDERE = 3
                   AND C.CODCOMANDA = C1.CODCOMANDA
                   AND I1.CODIES1 = L.CODIES1
                   AND I1.CODIES = RECID
                  )
    LOOP
      UPDATE TMP_IESIRI1
      SET
        NRDOCLINK = &apos;Cc&apos; ||  TO_CHAR(V_REC.NRDOC)
      WHERE
        CODIES1 = V_REC.CODIES1;
    END LOOP;
    FOR V_REC IN (SELECT L.CODIES1, C.NRDOC, C.PREFIXDOC  -- bonuri de consum de pe comenzi service auto
                 FROM
                   IESLINK L,
                   IESIRI1 I1,
                   COMANDA1 C1,
                   COMANDA C
                 WHERE
                   C.TIPDOC = 92
                   AND L.CODLINIECOMANDA = C1.CODCOMANDA1
                   AND C1.MODINCHIDERE = 2
                   AND C.CODCOMANDA = C1.CODCOMANDA
                   AND I1.CODIES1 = L.CODIES1
                   AND I1.CODIES = RECID
                  )
    LOOP
      UPDATE TMP_IESIRI1
      SET
        NRDOCLINK = V_REC.PREFIXDOC||TO_CHAR(V_REC.NRDOC)
      WHERE
        CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  -- GENERAL
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg
  FROM GENERAL
  WHERE CODDOC = RECID AND TIPDOC = TIPIES;

  -- pregatest pentru calcul solduri
  --  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  --  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, ANPREC, LUNAPREC);
  --  PKG_GLOBALS.SETLUNAPRECEDENTA(ANPREC, LUNAPREC);
  --  PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(aCODPART);

  -- PREIAU DIN TMP_GENERAL MONEDA SI CURSUL
  UPDATE TMP_IESIRI I
  SET
    SCADENTAV    = NVL((SELECT SCADENTAV FROM NPART WHERE CODPART = I.PARTENER), 0),
    DiscountPart = (SELECT NVL(P_LUNA.DISCOUNT, P.DISCOUNT) AS DISCOUNT
                    FROM NPART P LEFT JOIN NPART1 P_LUNA ON P_LUNA.CODPART = P.CODPART AND PKG_GLOBALS.AnLunaLucru BETWEEN P_LUNA.ALStart AND P_LUNA.ALStop
                    WHERE P.CODPART = i.Partener
                    ),
    COLDISCPART  = (SELECT COLDISCPART FROM NPART WHERE CODPART = I.PARTENER);

  -- OBLIGPIF
  INSERT INTO TMP_OBLIGPIF (
    CODOBLIGPIF,CODGENERAL,TERMEN, VALOARE,REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODCENTRU,
    ZILE,
    CODANALIZANOD, DINCARETVA, RESTTVA)
  SELECT
    O.CODOBLIGPIF,
    O.CODGENERAL,
    O.TERMEN,
    O.VALOARE,
    O.REST,
    O.CODPART,
    O.ICONT,
    O.TIPPLATA,
    O.MAJORARI,
    O.SEMNIFICATIE,
    O.TIP,
    O.CONTBANKTRANZACTIE,
    O.CODOBLIGASOCIAT,
    NVL(O.CODCENTRU, 0),
    CASE WHEN TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;) &lt;&gt; &apos;01.01.1900&apos; THEN TRUNC(TERMEN - aDATADOC) ELSE 0 END,
    O.CODANALIZANOD,
    O.DINCARETVA,
    O.RESTTVA
  FROM
    TMP_GENERAL G
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL;
--  WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL);

  -- pun Procent in OBLIGPIF -- varianta cu ICONT
  /*
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, ICONT, VALOARE)
  SELECT COUNT(*), ICONT, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (200, 210, 240) GROUP BY ICONT  ;

  UPDATE TMP_OBLIGPIF O
  SET
    PROCTVAAVANS = (SELECT PROCTVAAVANS FROM TMP_GENERAL G WHERE G.CODGENERAL = O.CODGENERAL),
    PROCENT = CASE
                WHEN TOTAL_VALOARE_ICONT(O.ICONT) = 0  THEN 100 / TOTAL_COUNT_ICONT(O.ICONT)
                WHEN TOTAL_VALOARE_ICONT(O.ICONT) &lt;&gt; 0 THEN 100 * VALOARE / TOTAL_VALOARE_ICONT(O.ICONT)
              END
  WHERE SEMNIFICATIE IN (200, 210, 220, 240);
*/

-- pun Procent in OBLIGPIF -- versiune cu grupare pe semnif
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, SEMNIFICATIE, VALOARE)
  SELECT COUNT(*), SEMNIFICATIE, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (200, 210, 220, 240) GROUP BY SEMNIFICATIE ;


  UPDATE TMP_OBLIGPIF O
  SET
    PROCTVAAVANS = (SELECT PROCTVAAVANS FROM TMP_GENERAL G WHERE G.CODGENERAL = O.CODGENERAL),
    PROCENT =
      (
    CASE
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) = 0  THEN 100 / TOTAL_COUNT_SEMNIF(O.SEMNIFICATIE)
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) &lt;&gt; 0 THEN 100 * O.VALOARE /  TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE)
    END
    )
   WHERE
    SEMNIFICATIE IN (200, 210, 220, 240);



  UPDATE TMP_OBLIGPIF O
  SET (TVA, CURS) = (SELECT TVA, CURS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL);

  -- STINGERE
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE
  WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

  -- memorez starea la intrare a obligatiilor necesara la interfata STORNO FACTURA
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF);
  DELETE TMP_STINGERE_INITIAL;
  INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE);

  -- DETAIL IESLINK
  INSERT INTO TMP_IESLINK(CODIES1,  CODLINIECOMANDA, CODLINIEAVIZ, CANT)
  SELECT CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT
  FROM IESLINK L
  WHERE L.CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);

  DELETE TMP_PACHETEOBJLINK;
  DELETE TMP_PACHETEOBJLINK_I;
  INSERT INTO TMP_PACHETEOBJLINK(CODIES1,  CODPACHETEOBJL, CANT)
  SELECT CODIES1, CODPACHETEOBJL, CANT
  FROM PACHETEOBJLINK L
  WHERE L.CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);
  INSERT INTO TMP_PACHETEOBJLINK_I SELECT * FROM TMP_PACHETEOBJLINK;

  INSERT INTO TMP_IESPRODLINK(CODIES1,  CODCMDPRODMAT, CANT, CODPROGRAMF1)
  SELECT CODIES1,  CODCMDPRODMAT, CANT, CODPROGRAMF1
  FROM IESPRODLINK L
  WHERE L.CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);

  DELETE TMP_FACTSALINK;
  DELETE TMP_FACTSALINK_INITIAL;
  INSERT INTO TMP_FACTSALINK(CODIES1,
                             CODCOMANDA,
                             CODCLASEA,
                             VALOARE)
  SELECT CODIES1,
         CODCOMANDA,
         CODCLASEA,
         VALOARE
  FROM FACTSALINK WHERE CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);
  INSERT INTO TMP_FACTSALINK_INITIAL SELECT * FROM TMP_FACTSALINK;

  DELETE TMP_PACHETELINK;
  DELETE TMP_PACHETELINK_INITIAL;
  INSERT INTO TMP_PACHETELINK (CODIES1, CODPACHETEOBJ, CANT)
  SELECT CODIES1, CODPACHETEOBJ, CANT
  FROM PACHETELINK
  WHERE CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);
  INSERT INTO TMP_PACHETELINK_INITIAL
  SELECT * FROM TMP_PACHETELINK;

  IF TIPIES = 26 THEN
    UPDATE TMP_IESLINK L
    SET
      (        MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, DATAAVIZ, CUSTODIE, SUBUNITAVIZ, PROCDISCAVIZ, TIPTVAAVIZ, FLAGS) =
      ( SELECT G.MONEDA, NVL(GREG.CURS, G.CURS), S.PU, S.CANT, S.TVA, I.DATADOC, I.CUSTODIE, I.SUBUNITATEA, S.PROCDISC, I.TIPTVA, I.FLAGS
        FROM IESIRI1 S
          INNER JOIN IESIRI I ON I.CODIES = S.CODIES
          LEFT JOIN GENERAL G ON G.CODDOC = S.CODIES AND G.TIPDOC = 20
          LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
        WHERE S.CODIES1 = L.CODLINIEAVIZ
          AND ROWNUM = 1
      ) ;
  END IF;

  UPDATE TMP_IESLINK L
  SET
    DATACOMANDA = (SELECT  C.DATADOC FROM COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA),
    CODCOMAND1ORIG = NVL((SELECT CODLINIECOMANDA FROM CMDLIVRLINK K WHERE K.CODCOMANDA1 = L.CODLINIECOMANDA AND ROWNUM = 1), 0) ;

  UPDATE TMP_IESPRODLINK L
  SET
    (DATACOMANDA, CODLINIECOMANDA) =
    ( SELECT C.DATADOC, C1.CODCOMANDA1
      FROM CMDPRODMAT CPM, COMANDA1 C1, COMANDA C
      WHERE CPM.CODCMDPRODMAT = L.CODCMDPRODMAT AND CPM.CODCOMANDA1 = C1.CODCOMANDA1 AND C1.CODCOMANDA = C.CODCOMANDA
    );

  IF pkg_globals.Directiva(&apos;_WMSA_&apos;) THEN
    UPDATE tmp_iesprodlink SET codliniecomanda = codcmdprodmat;-- pt SA codcmdprodmat este codcomanda1
  END IF;

  -- DETAIL IESVALLINK VALKORICE FARA DESCARCARE
  INSERT INTO TMP_IESVALLINK(CODIES1,  CODLIVR1, CANT, TIPLINK)
  SELECT CODIES1, CODLIVR1, CANT, TIPLINK
  FROM IESVALLINK L
  WHERE L.CODIES1 IN (SELECT CODIES1 FROM TMP_IESIRI1);

  -- DETAIL IESVALLINK ARTICOLE COMPLEXE FARA DESCARCARE
  INSERT INTO TMP_IESVALLINK(CODLIVR1, CANT, CODIES, TIPLINK)
  SELECT CODLIVR1, CANT, CODIES, TIPLINK
  FROM IESVALLINK L
  WHERE L.CODIES = RECID;

  UPDATE TMP_IESVALLINK IESVAL
  SET
    DATADOC =
    ( SELECT
        CASE
          WHEN NVL(L.CODIES, 0)    &lt;&gt; 0 THEN I.DATADOC
          WHEN NVL(L.CODTRANSF, 0) &lt;&gt; 0 THEN T.DATADOC
          ELSE NULL
        END
      FROM LIVR1 L1
        INNER JOIN LIVR L ON L1.CODLIVR = L.CODLIVR
        LEFT OUTER JOIN IESIRI I  ON I.CODIES    = L.CODIES
        LEFT OUTER JOIN TRANSF T  ON T.CODTRANSF = L.CODTRANSF
      WHERE L1.CODLIVR1 = IESVAL.CODLIVR1
    ) ;


  UPDATE TMP_IESVALLINK IESVAL
  SET
    PRET =
    ( SELECT
        CASE
          WHEN NVL(L.CODIES, 0)    &lt;&gt; 0 THEN I1.PU
          WHEN NVL(L.CODTRANSF, 0) &lt;&gt; 0 THEN T1.PU
          ELSE NULL
        END
      FROM LIVR1 L1
        INNER JOIN LIVR L ON L1.CODLIVR = L.CODLIVR
        LEFT JOIN IESIRI1 I1  ON I1.CODIES1    = L1.CODIES1
        LEFT JOIN TRANSF1 T1  ON T1.CODTRANSF1 = L1.CODIES1
      WHERE L1.CODLIVR1 = IESVAL.CODLIVR1
    )
    WHERE
      IESVAL.TIPLINK = 14 ;


  INSERT INTO TMP_IESVALLINK_INITIAL SELECT * FROM TMP_IESVALLINK;

  -- DETAIL LIVR
  INSERT INTO TMP_LIVR ( CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
  SELECT CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
  FROM LIVR
  WHERE CODIES = RECID;

  -- DETAIL LIVR1
  INSERT INTO TMP_LIVR1 (
    CODLIVR1, CODLIVR, CODIES1, CODNIRSTOC, CANT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2, DENUM, PARITATE,
    GEST,
    CODIOART,
    CODOBIECT,
    CODLIVRTOT,
    PRETINREG,
    PRETACHIZ,
    TVANEEX,
    CANTREZERVAT, CODPRODCOMP, CodCertif, CONTINTERMED, CODGESTORIG, CODPROIECT, PROVIZION, BLOCATUM1, TIPSERIE, CODSERIE, SERIE, FURN,
    RESTIESVAL)
  SELECT
    L1.CODLIVR1, L1.CODLIVR, L1.CODIES1, L1.CODNIRSTOC, L1.CANT / U1.PARITATE, L1.CODNIRSER, L1.PMP, L1.PMPDOC, L1.PMPVALUTA,L1.PMPVALUTADOC, L1.UMSEC, L1.CANTUM1, L1.CANTUM2, U1.DEN_UM1, U1.PARITATE,
    CASE WHEN LV.CODLIVR1 IS NULL THEN N.GEST ELSE LV.GEST END,
    CASE WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART ELSE LV.CODIOART END,
    CASE WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT ELSE LV.CODOBIECT END,
    0,
    CASE WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE ELSE LV.PRETINREG * U1.PARITATE END,
    CASE WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NVL(NS.ADAOS, 0)) * U1.PARITATE ELSE LV.PRETACHIZ * U1.PARITATE END,
    CASE WHEN LV.CODLIVR1 IS NULL THEN NS.TVA ELSE LV.TVANEEX END,
    L1.CANTREZERVAT / U1.PARITATE, L1.CODPRODCOMP, L1.Codcertif, L1.CONTINTERMED, L1.CODGESTORIG, L1.CODPROIECT, NS.PROVIZION, L1.BLOCATUM1, NS.TIPSERIE, NSE.CODSERIE, SER.SERIE,
    NS.FURN,L1.RESTIESVAL
  FROM LIVR1 L1
    INNER JOIN NUM1   U1  ON U1.CODUM1     = L1.UMSEC
    LEFT JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN NIRSER  NSE ON NSE.CODNIRSER = L1.CODNIRSER
    LEFT JOIN NSERII  SER ON SER.CODSERIE  = NSE.CODSERIE
    LEFT JOIN LIVRVAL LV  ON LV.CODLIVR1   = L1.CODLIVR1
    LEFT JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
    LEFT JOIN LIVR    L   ON L.CODLIVR     = L1.CODLIVR
  WHERE L.CODIES  = RECID;


  FOR V_REC IN (SELECT * FROM (select codies1, sum(NVL(CANTUM2, 0)) as cantum2 from tmp_livr1 group by codies1) WHERE CANTUM2 &lt;&gt; 0)
  LOOP
    UPDATE TMP_IESIRI1
    SET
      CANTUM2 = V_REC.CANTUM2
    WHERE
      CODIES1 = V_REC.CODIES1;
  END LOOP;

  --DETAIL LIVRTOT
  DELETE TMP_LIVRTOT;

  INSERT INTO TMP_LIVRTOT (
    CODLIVRTOT, CODLIVR, CODIESINT1, UMSEC,  GEST, CODIOART, CONTINTERMED,CODPROIECT, CODOBIECT, DENUM, PARITATE,
    DENGESTIOART,
    DIFPRET, ACCIZELATRANSFER, ARETVANEEX, MG, CONT, SUFIXTVANEEX, CODPRODCOMP, STOCREZOLVAT, CANT,
    PRETINREG,
    PRETACHIZ,
    PMP,
    PMPDOC,
    PMPVALUTA,
    PMPVALUTADOC,
    CANTUM2)
  SELECT
    0, L1.CODLIVR, L1.CODIES1, L1.UMSEC, L1.GEST, L1.CODIOART, NVL(L1.CONTINTERMED, 0), NVL(L1.CODPROIECT, 0), L1.CODOBIECT, L1.DENUM, L1.PARITATE,
    G.DEN_GEST || CHR(13) || IO.DEN_IOART,
    IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, L1.CODPRODCOMP, 1, SUM(L1.CANT ),
    SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PMP       * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PMPDOC    * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PMPVALUTA * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(L1.PMPVALUTADOC * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
    SUM(COALESCE(L1.CANTUM2,0))
  FROM TMP_LIVR1 L1
    LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALStart AND IOALUNA.ALStop
    LEFT OUTER JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
    LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
    LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
  WHERE L.CODIES    = RECID
  GROUP BY
    0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC, L1.GEST, L1.CODIOART, NVL(L1.CONTINTERMED, 0), NVL(L1.CODPROIECT, 0), L1.DENUM, L1.PARITATE ,
    G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET,  IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT, IOALUNA.TVANEEX, L1.CODPRODCOMP
  ORDER BY L1.CODLIVR, L1.CODIES1;

  IF RECID &gt; 0 THEN
    UPDATE TMP_LIVRTOT T
    SET CODLIVRTOT = ROWNUM;

    FOR V_REC IN (
      SELECT T.CODLIVRTOT, A.ARETG, A.UM1, A.UM2, A.RELATIEUM1, A.TIPSERIE, O.DENUMIRE, O.CODEXTERN, O.CODINTERN,
             I1.INDEXLOCAL, I1.NRDOCLINK, I1.CANTUM2, I1.PROCTVA, IL.CODLINIECOMANDA, IL.CODCOMAND1ORIG, TMP.CODCMDPRODMAT
      FROM TMP_LIVRTOT T
        INNER JOIN TMP_IESIRI1 I1 ON T.CODIESINT1 = I1.CODIES1
        INNER JOIN NARTOBJ O ON I1.CODOBIECT = O.CODOBIECT
        INNER JOIN NART A ON O.CODARTICOL = A.CODARTICOL
        LEFT JOIN TMP_IESLINK IL ON IL.CODIES1 = I1.CODIES1
        LEFT JOIN TMP_IESPRODLINK TMP ON TMP.CODIES1 = I1.CODIES1
    ) LOOP
      UPDATE TMP_LIVRTOT
      SET
        ARETG           = V_REC.ARETG,
        DENOBIECT       = V_REC.DENUMIRE,
        CODEXTERN       = V_REC.CODEXTERN,
        CODINTERN       = V_REC.CODINTERN,
        INDEXMASTER     = V_REC.INDEXLOCAL,
        UM1             = V_REC.UM1,
        UM2             = V_REC.UM2,
        CANTUM2         = V_REC.CANTUM2,
        RELATIEUM1      = V_REC.RELATIEUM1,
        TIPSERIE        = V_REC.TIPSERIE,
        CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
        CODCOMAND1ORIG  = V_REC.CODCOMAND1ORIG,
        NRDOCLINK       = V_REC.NRDOCLINK,
        PROCTVA         = V_REC.PROCTVA,
        CODCMDPRODMAT   = V_REC.CODCMDPRODMAT
      WHERE CODLIVRTOT = V_REC.CODLIVRTOT;
    END LOOP;

    IF TipIES = 24 THEN
      UPDATE TMP_LIVRTOT T
      SET CODLINIECOMANDA = ( SELECT CODLINIECOMANDA FROM TMP_IESPRODLINK IL, TMP_IESIRI1 I1 WHERE I1.CODIES1 = T.CODIESINT1 AND IL.CODIES1 = I1.CODIES1);

      UPDATE TMP_LIVRTOT T
      SET CODCOMAND1ORIG = NVL((SELECT DISTINCT L.CodCmd1 FROM lansare1 L1 INNER join lansare L on L1.CodLansare = L.CodLansare WHERE L1.CodCmd1 = T.CODLINIECOMANDA), T.CODLINIECOMANDA);

      UPDATE TMP_LIVRTOT T
      SET CODCOMAND1ORIG = NVL((SELECT CODLINIECOMANDA FROM TMP_IESLINK IL, TMP_IESIRI1 I1 WHERE I1.CODIES1 = T.CODIESINT1 AND IL.CODIES1 = I1.CODIES1), T.CODLINIECOMANDA);
    ELSE
      UPDATE TMP_LIVRTOT
      SET CODCOMAND1ORIG = CODLINIECOMANDA;
    END IF;

    -- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
    FOR V_REC IN
    (SELECT
      LT.CODLIVRTOT,
      L1.CODLIVR1,
      LT.CODLINIECOMANDA,
      LT.PROCTVA
     FROM
       TMP_LIVRTOT LT,
       TMP_LIVR1 L1
     WHERE
        NVL(LT.CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
        NVL(LT.CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
        NVL(LT.UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
        NVL(LT.PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
        NVL(LT.GEST, 0)         = NVL(L1.GEST, 0)     AND
        NVL(LT.CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
        NVL(LT.CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0) AND
        NVL(LT.CODOBIECT, 0)    = NVL(L1.CODOBIECT, 0)and -- stupid insa vin baze de date cu incoerente intre codobiect din iesiri1 si livr1
        NVL(LT.CODPRODCOMP, 0)  = NVL(L1.CODPRODCOMP, 0)
     )
     LOOP
       UPDATE TMP_LIVR1
       SET
         CODLIVRTOT = V_REC.CODLIVRTOT,
         CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
         PROCTVA = V_REC.PROCTVA
       WHERE
         CODLIVR1 = V_REC.CODLIVR1;
     END LOOP;



    UPDATE TMP_LIVR1 L1
    SET
      ADAOS  = PRETINREG - PRETACHIZ,
     (PROCENTADAOS, D1, D2, D3) = (SELECT PROCENTADAOS, D1, D2, D3 FROM NIRSTOC WHERE CODNIRSTOC = L1.CODNIRSTOC),
     (TG, DATAACHIZ) = (  SELECT NVL(NSE.TG, NS.TG), NS.DATAACHIZ
                          FROM LIVR1 LL1
                            INNER JOIN  NIRSTOC NS ON NS.CODNIRSTOC = LL1.CODNIRSTOC
                            LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSER = LL1.CODNIRSER
                          WHERE LL1.CODLIVR1 = L1.CODLIVR1
                        );



/*    UPDATE TMP_LIVR1 L1
    SET
      CODLIVRTOT = (  SELECT CODLIVRTOT FROM TMP_LIVRTOT
                      WHERE
                        NVL(CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
                        NVL(CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
                        NVL(UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
                        NVL(PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
                        NVL(GEST, 0)         = NVL(L1.GEST, 0)     AND
                        NVL(CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
                        NVL(CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0) AND
                        NVL(CODPRODCOMP, 0)  = NVL(L1.CODPRODCOMP, 0)
                    ),
      ADAOS  = PRETINREG - PRETACHIZ,
     (PROCENTADAOS, D1, D2, D3) = (SELECT PROCENTADAOS, D1, D2, D3 FROM NIRSTOC WHERE CODNIRSTOC = L1.CODNIRSTOC),
     (TG, DATAACHIZ) = (  SELECT NVL(NSE.TG, NS.TG), NS.DATAACHIZ
                          FROM LIVR1 LL1
                            INNER JOIN  NIRSTOC NS ON NS.CODNIRSTOC = LL1.CODNIRSTOC
                            LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSER = LL1.CODNIRSER
                          WHERE LL1.CODLIVR1 = L1.CODLIVR1
                        );*/
  END IF;

/*  MUTATA MAI SUS
  UPDATE TMP_LIVR1 L1
  SET CODLINIECOMANDA = (SELECT CODLINIECOMANDA FROM TMP_LIVRTOT WHERE CODLIVRTOT = L1.CODLIVRTOT AND ROWNUM &lt;=1);
*/
  -- DETAIL TMP_LIVRVAL;
  INSERT INTO TMP_LIVRVAL SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

  -- PARITATEA PRETURILOR DIN LIVRVAL ESTE CEA DIN TMP_LIVR1
  UPDATE TMP_LIVRVAL LV
  SET
    PRETINREG = PRETINREG * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1),
    PRETACHIZ = PRETACHIZ * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1);

  -- MEMOREZ STAREA LA INTRARE A LIVRARILOR
  DELETE TMP_LIVR1_INITIAL;
  INSERT INTO TMP_LIVR1_INITIAL (SELECT * FROM TMP_LIVR1);

  DELETE TMP_IESLINK_INITIAL;
  INSERT INTO TMP_IESLINK_INITIAL (CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODCOMAND1ORIG) SELECT CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODCOMAND1ORIG FROM TMP_IESLINK;

  DELETE TMP_IESPRODLINK_INITIAL;
  INSERT INTO TMP_IESPRODLINK_INITIAL SELECT * FROM TMP_IESPRODLINK;

  DELETE TMP_LIVRVAL_INITIAL;
  INSERT INTO TMP_LIVRVAL_INITIAL(CODLIVRVAL,CODLIVR1) SELECT CODLIVRVAL,CODLIVR1 FROM TMP_LIVRVAL;

  -- TABELE PENTRU NIR-uri NOI LA IESIRE IN ROSU
  DELETE TMP_INTRARI;
  DELETE TMP_INTRARI1;
  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;
  DELETE TMP_NIRSER;

  INSERT INTO TMP_NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
  SELECT CODNIR, CODINTR, RECID, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT
  FROM NIR WHERE TIPNIR = TIPIES AND CODIES = RECID;

  INSERT INTO TMP_INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA)
  SELECT  CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA
  FROM INTRARI  WHERE CODINTR IN (SELECT CODINTR FROM TMP_NIR);

  INSERT INTO TMP_INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PARITATE, CodOferta1, CODCENTRU, CODANALIZANOD)
  SELECT CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG  * NVL(U1.PARITATE, 1), PU * NVL(U1.PARITATE, 1), 0, TG, U1.PARITATE, I1.CodOferta1, I1.CODCENTRU, I1.CODANALIZANOD
  FROM INTRARI1 I1, NUM1 U1
  WHERE U1.CODUM1 = I1.UMSEC AND CODINTR IN (SELECT CODINTR FROM TMP_NIR);

  INSERT INTO TMP_NIRSTOC (
    CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, CANTUM1, CANTUM2, REST, UMSEC, CODOBIECT, CODIOART,
    PRET, ADAOS, PUMaximal, AdMax,
    TVA, TIPSERIE, CODLOCATIE, FURN, DATAACHIZ, TG, TIPDOCACHIZ, PARITATE, DIFPRET, ARETVANEEX, PUSTANDARD, MG, D1, D2, D3, PUVAL, CODGESTPROD, SERIELOT, PROVIZION, CANTFURN)
  SELECT
    CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, CANTUM1, CANTUM2, REST, UMSEC, CODOBIECT, NS.CODIOART,
    PRET  * NVL(U1.PARITATE, 1), ADAOS * NVL(U1.PARITATE, 1), PUMaximal, AdMax * NVL(U1.PARITATE, 1),
    TVA, TIPSERIE, CODLOCATIE, FURN, DATAACHIZ, TG, TIPDOCACHIZ, U1.PARITATE, IOA.DIFPRET, IOA.ARETVANEEX, IOA.PUSTANDARD, IOA.MG, D1, D2, D3, NS.PUVAL, NS.CODGESTPROD, NS.SERIELOT, NS.PROVIZION, NS.CANTFURN
  FROM NIRSTOC NS, NUM1 U1, TMP_IOART_LUNA IOA
  WHERE U1.CODUM1 = NS.UMSEC
    AND CODNIR IN (SELECT CODNIR FROM TMP_NIR)
    AND IOA.CODIOART = NS.CODIOART;

  INSERT INTO TMP_NIRSTOC1
  SELECT NS1.*
  FROM NIRSTOC1 NS1
  WHERE EXISTS (SELECT NS.CODNIRSTOC FROM TMP_NIRSTOC NS WHERE NS.CODNIRSTOC = NS1.CODNIRSTOC);

  INSERT INTO TMP_NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, REST, RESTUM1, RESTUM2, OBS, TG, SERIE, CODCERTIF, DATAPROD, Stare, CODPRODUCATOR)
  SELECT CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, REST, RESTUM1, RESTUM2, OBS, TG, (SELECT SERIE FROM NSERII WHERE CODSERIE = N.CODSERIE), CODCERTIF, DATAPROD, Stare,
         CODPRODUCATOR
  FROM NIRSER N WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC);

  -- PREIAU CARACTERIZAREA CONTABILA VALABILA PE LUNA DE LUCRU A PARTENERULUI DE PE FACTURA
  DELETE TMP_IOPARTDOC;

  IF TIPIES IN (19, 20, 21, 22, 26) AND aCODPART &lt;&gt; 0  THEN
    LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(aCODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    LOOP
      FETCH LUNAREF INTO IOPART1REC;
      EXIT WHEN LUNAREF%NOTFOUND;
      IF IOPART1REC.CODIOPART1 &gt; 0 THEN
        INSERT INTO TMP_IOPARTDOC (
          CODPART, CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ,
          CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI,
          CONTCHELTAVANS, CONTVENITAVANS, CONTGARANTIEEF, CONTGARANTIETF, CONTGARANTIEEC, CONTGARANTIETC,
          ContSuplimF1 , ContSuplimF2 , ContSuplimF3 , ContSuplimF4 , ContSuplimF5 ,
          ContSuplimC1 , ContSuplimC2 , ContSuplimC3 , ContSuplimC4 , ContSuplimC5 ,
          TvaNeexF, TvaNeexP, TvaNeexI, TVANEEXC, TIP
        )
        VALUES (
          aCODPART, IOPART1REC.CODIOPART1, IOPART1REC.CODIOPART, IOPART1REC.CONTFURNIZOR, IOPART1REC.CONTCLIENT, IOPART1REC.CONTFURNAVANS, IOPART1REC.CONTCLIENTAVANS, IOPART1REC.CONTFURNAVIZ, IOPART1REC.CONTCLIENTAVIZ,
          IOPART1REC.CONTFURNMF, IOPART1REC.CONTCREDITD, IOPART1REC.CONTDEBITD, IOPART1REC.CONTLITIGII, IOPART1REC.CONTFURNAVS, IOPART1REC.CONTFURNAVIC, IOPART1REC.CONTFURNAVIN, IOPART1REC.CONTTERTI,
            IOPART1REC.CONTCHELTAVANS, IOPART1REC.CONTVENITAVANS, IOPART1REC.CONTGARANTIEEF, IOPART1REC.CONTGARANTIETF, IOPART1REC.CONTGARANTIEEC, IOPART1REC.CONTGARANTIETC,
            IOPART1REC.ContSuplimF1 , IOPART1REC.ContSuplimF2 , IOPART1REC.ContSuplimF3 , IOPART1REC.ContSuplimF4 , IOPART1REC.ContSuplimF5 ,
            IOPART1REC.ContSuplimC1 , IOPART1REC.ContSuplimC2 , IOPART1REC.ContSuplimC3 , IOPART1REC.ContSuplimC4 , IOPART1REC.ContSuplimC5 ,
            IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI, IOPART1REC.TVANEEXC, IOPART1REC.TIP
        );
      END IF;
    END LOOP;
  END IF;

  --INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = TIPIES AND CODDOC = RECID);
  --INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = TIPIES AND CODDOC = RECID);
  INSERT INTO TMP_JURNAL  (SELECT /*+ INDEX(j, IDX_JURNAL_CODDOC) */   * FROM JURNAL J   WHERE TIPDOC = TIPIES AND CODDOC = RECID);
  INSERT INTO TMP_JURNAL1 (SELECT /*+ INDEX(j1, IDX_JURNAL1_CODDOC) */ * FROM JURNAL1 J1 WHERE TIPDOC = TIPIES AND CODDOC = RECID);

  DELETE TMP_RULAJ;

  UPDATE TMP_IESIRI1 I1
  SET
    NRDOCLINK =
    CASE
      WHEN NVL(CODOBLIGSTORNO, 0) = 0  THEN &apos;Avans &apos;
      WHEN NVL(CODOBLIGSTORNO, 0) &lt;&gt; 0 THEN &apos;Storno &apos; ||
           NVL((
            SELECT I.PREFIXDOC||I.NRDOC||&apos;/&apos;||TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
            FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G, IESIRI I
            WHERE S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND S.CODSTINSPIF =  O.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL AND I.TIPDOC = G.TIPDOC AND I.CODIES = G.CODDOC), &apos;&apos;)
    END
  WHERE TIPLINIE = &apos;V&apos;;

  UPDATE TMP_IESIRI1 I1
  SET
    NRDOCLINK =
    CASE
      WHEN NVL(CODOBLIGSTORNO, 0) = 0  THEN &apos;Garantie &apos;
      WHEN NVL(CODOBLIGSTORNO, 0) &lt;&gt; 0 THEN &apos;Storno garantie&apos; ||
           NVL((
            SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; ||  TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
            FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G, IESIRI I
            WHERE S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND S.CODSTINSPIF =  O.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL AND I.TIPDOC = G.TIPDOC AND I.CODIES = G.CODDOC), &apos;&apos;)
    END
  WHERE TIPLINIE = &apos;R&apos;;

/* MULATA MAI SUS
  IF RECID &gt; 0 THEN
    UPDATE TMP_LIVR1 L1
    SET PROCTVA = (SELECT PROCTVA FROM TMP_LIVRTOT WHERE CODLIVRTOT = L1.CODLIVRTOT);
  END IF;
*/

  DELETE TMP_NIRSTOCINI;
  INSERT INTO TMP_NIRSTOCINI (CODNIRSTOC)  SELECT CODNIRSTOC FROM TMP_NIRSTOC;

  FOR V_REC IN ( SELECT I1.CODIES1, C1.D1, C1.D2, C1.D3 FROM TMP_IESIRI1 I1, TMP_IESPRODLINK IL, COMANDA1 C1 WHERE IL.CODIES1 = I1.CODIES1 AND C1.CODCOMANDA1 = IL.CODLINIECOMANDA)
  LOOP
    UPDATE TMP_IESIRI1
    SET
      D1 = CASE WHEN D1 IS NULL THEN V_REC.D1 ELSE D1 END,
      D2 = CASE WHEN D2 IS NULL THEN V_REC.D2 ELSE D2 END,
      D3 = CASE WHEN D3 IS NULL THEN V_REC.D3 ELSE D3 END
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  FOR V_REC IN ( SELECT I1.CODIES1, C1.D1, C1.D2, C1.D3 FROM TMP_IESIRI1 I1, TMP_IESLINK IL, COMANDA1 C1 WHERE IL.CODIES1 = I1.CODIES1 AND IL.CODLINIECOMANDA = C1.CODCOMANDA1 )
  LOOP
    UPDATE TMP_IESIRI1
    SET
      D1 = CASE WHEN D1 IS NULL THEN V_REC.D1 ELSE D1 END,
      D2 = CASE WHEN D2 IS NULL THEN V_REC.D2 ELSE D2 END,
      D3 = CASE WHEN D3 IS NULL THEN V_REC.D3 ELSE D3 END
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  -- LINIILE DE MAI SUS PUN IN TMP_IESIRI1 D1..D3 venite de pe comenzi;
  -- PENTRU LINIILE PROVENITE DIN IMPORT BCS trebuie sa fac acelasi lucru

  FOR V_REC IN ( SELECT I1.CODIES1, L1.D1, L1.D2, L1.D3 FROM TMP_IESIRI1 I1, TMP_LIVR1 L1 WHERE NVL(I1.D1D3BCS, 0) &gt; 0 AND I1.CODIES1 = L1.CODIES1 )
  LOOP
    UPDATE TMP_IESIRI1
    SET
      D1 = CASE WHEN D1 IS NULL THEN V_REC.D1 ELSE D1 END,
      D2 = CASE WHEN D2 IS NULL THEN V_REC.D2 ELSE D2 END,
      D3 = CASE WHEN D3 IS NULL THEN V_REC.D3 ELSE D3 END
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  FOR V_REC IN (SELECT CODIES1, D1, D2, D3 FROM TMP_IESIRI1 WHERE NVL(D1, 0) + NVL(D2, 0) + NVL(D3, 0) &lt;&gt; 0)
  LOOP
    UPDATE TMP_LIVRTOT
    SET
      D1 = V_REC.D1,
      D2 = V_REC.D2,
      D3 = V_REC.D3
    WHERE CODIESINT1 = V_REC.CODIES1;
  END LOOP;

  FOR V_REC IN (SELECT S.CODSTINGERE, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL )
  LOOP
    aCODSUBUNITSTINS := 0;
    IF V_REC.SEMNIFICATIE IN (210) THEN
      BEGIN
        SELECT SUBUNITATEA INTO aCODSUBUNITSTINS
        FROM IESIRI
        WHERE CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
      EXCEPTION
        WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
      END;

      UPDATE TMP_STINGERE
      SET CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE CODSTINGERE = V_REC.CODSTINGERE;
    END IF;
  END LOOP;


  UPDATE TMP_IESIRI1 I1
  SET DENOBIECTORIG = (SELECT DENUMIRE FROM NARTOBJ WHERE CODOBIECT = I1.CODOBIECTORIG)
  WHERE I1.CODOBIECTORIG &gt; 0;

  IF TIPIES = 20 THEN
    UPDATE TMP_IESIRI1 I1
    SET NRDOCLINK = &apos;Storno AE&apos; || (SELECT AE.NRDOC FROM IESIRI1 AE1, IESIRI AE WHERE AE1.CODIES1 = I1.CODIES1STORNO AND AE.CODIES = AE1.CODIES)
    WHERE NVL(I1.CODIES1STORNO, 0) &lt;&gt; 0;
  END IF;

  IF TIPIES = 16 THEN
    FOR V_REC IN (
      SELECT
        S.CODSTINGATORPIF,
        CASE WHEN G.TIPDOC IN (19, 26) THEN &apos;F&apos; ELSE &apos;NC&apos; END AS PREFIXDOC,
        CASE WHEN G.TIPDOC IN (19, 26) THEN (SELECT NRDOC FROM IESIRI I WHERE I.CODIES = G.CODDOC) ELSE (SELECT NC.NRDOC FROM NC1, NC WHERE NC1.CODNC1 = G.CODDOC AND NC.CODNC = NC1.CODNC) END AS NRDOC,
        CASE WHEN G.TIPDOC IN (19, 26) THEN (SELECT DATADOC FROM IESIRI I WHERE I.CODIES = G.CODDOC) ELSE (SELECT NC.DATADOC FROM NC1, NC WHERE NC1.CODNC1 = G.CODDOC AND NC.CODNC = NC1.CODNC) END AS DATADOC,
        P.DEN_PART
      FROM TMP_STINGERE S, OBLIGPIF O, GENERAL G, NPART P
      WHERE S.CODSTINSPIF    = O.CODOBLIGPIF
        AND G.CODGENERAL = O.CODGENERAL
        AND P.CODPART    = O.CODPART
    ) LOOP
      UPDATE TMP_OBLIGPIF
      SET DENDOCLEGATURA = V_REC.DEN_PART   || &apos;: &apos; || V_REC.PREFIXDOC  || V_REC.NRDOC      || &apos;/&apos;  || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;)
      WHERE CODOBLIGPIF = V_REC.CODSTINGATORPIF;
    END LOOP;
  END IF;

  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
  EXCEPTION
    WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
  END;

  IF TIPPREFIX = &apos;2&apos; THEN
    UPDATE TMP_IESIRI1 I1
    SET DENOBIECT = SUBSTR(NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
    WHERE I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;);
  ELSIF TIPPREFIX = &apos;3&apos; THEN
    UPDATE TMP_IESIRI1 I1
    SET DENOBIECT = SUBSTR(NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
    WHERE I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;);
  ELSIF TIPPREFIX = &apos;4&apos; THEN
    UPDATE TMP_COMANDA1 I1
    SET DENOBIECT = NVL((SELECT A.CODEXTERNART || A.SUFIXCODEXTERN FROM NART A, NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT AND A.CODARTICOL = O.CODARTICOL), &apos;&apos;) || &apos;;&apos; || DENOBIECT
    WHERE I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
  END IF;

  IF TIPPREFIX &lt;&gt; &apos;1&apos; THEN
    UPDATE TMP_LIVRTOT L1
    SET DENOBIECT = (SELECT DENOBIECT FROM TMP_IESIRI1 I1 WHERE I1.CODIES1 = L1.CODIESINT1);
  END IF;

  IF TIPIES IN (19, 20) THEN
    FOR V_REC IN (
      SELECT I1.CODIES1
      FROM TMP_IESIRI1 I1, TMP_IESLINK IL, COMANDA1 C1, COMANDA C
      WHERE IL.CODIES1 = I1.CODIES1
        AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
        AND C.CODCOMANDA = C1.CODCOMANDA
        AND C.TIPDOC = 18 AND C.DISPLIVRARE = 1
    ) LOOP
      UPDATE TMP_IESIRI1
      SET DISPLIVR = 1
      WHERE CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  IF TIPIES = 26 THEN
    UPDATE TMP_IESIRI1 I1
    SET
    CUSTODIE = (SELECT CUSTODIE FROM TMP_IESLINK IL WHERE IL.CODIES1 = I1.CODIES1);
  END IF;

  UPDATE TMP_NIRSTOC NS
  SET
    (MASA, VOLUM)    = (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = NS.CODOBIECT),
    (UM1, UM2, RELATIEUM1, RELATIEUM2) = (SELECT NVL(UM1, 0), NVL(UM2, 0), NVL(RELATIEUM1, 0), NVL(RELATIEUM2, 0) FROM NART A WHERE A.CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(NS.CODOBIECT)),
    PRETINITIAL     = PRET,
    ADAOSINITIAL    = ADAOS,
    CODIOARTINITIAL = CODIOART;

  FOR V_REC IN (
    SELECT I1.CODIES1, I.PREFIXDOC, I.NRDOC
    FROM TMP_IESIRI1 I1, OBLIGPIF O, GENERAL G, IESIRI I
    WHERE NVL(I1.CODOBLIGMAJORAT, 0) &lt;&gt; 0
      AND I1.CODOBLIGMAJORAT = O.CODOBLIGPIF
      AND G.CODGENERAL = O.CODGENERAL
      AND G.TIPDOC = I.TIPDOC
      AND G.CODDOC = I.CODIES
  ) LOOP
    UPDATE TMP_IESIRI1
    SET NRDOCLINK = V_REC.PREFIXDOC || &apos;/&apos; || TO_CHAR(V_REC.NRDOC)
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  DELETE TMP_DIN_CANTARIRI;
  INSERT INTO TMP_DIN_CANTARIRI(CODCANTAR, TIPDOC, CODDOC1)
  SELECT CODCANTAR, TIPDOC, CODDOC1
  FROM CANTAR
  WHERE TIPDOC = TIPIES
    AND CODDOC1 IN (SELECT CODIES1 FROM TMP_IESIRI1);

  INSERT INTO TMP_DIN_CANTARIRI(CODBCAR, TIPDOC, CODDOC1)
  SELECT CODBCAR, TIPDOC, CODDOC1
  FROM BCAR
  WHERE TIPDOC = TIPIES
    AND CODDOC1 IN (SELECT CODIES1 FROM TMP_IESIRI1);

  -- CERINTA UNILEVER - GESTIUNEA IMPLICITA DE LIVRARE SA VINA SETATA DE PE COMANDA
  FOR V_REC IN (SELECT I1.CODIES1, C1.GESTACT FROM TMP_IESLINK IL, TMP_IESIRI1 I1, COMANDA1 C1 WHERE IL.CODIES1 = I1.CODIES1 AND IL.CODLINIECOMANDA = C1.CODCOMANDA1 AND NVL(C1.GESTACT, 0) &lt;&gt; 0 AND I1.TIPLINIE = &apos;=&apos; )
  LOOP
    UPDATE TMP_IESIRI1
    SET GESTIMPLICITA = V_REC.GESTACT
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  FOR V_REC IN (SELECT CODIES1, TIPDOCIMP, CODLINIEDOCIMP FROM TMP_IESIRI1 WHERE NVL(TIPDOCIMP, 0) IN (19, 20, 24, 26) AND NVL(CODLINIEDOCIMP, 0 ) &lt;&gt; 0)
  LOOP
    UPDATE TMP_IESIRI1
    SET INFODOCRETUR = (SELECT I.PREFIXDOC || TO_CHAR(I.NRDOC) || &apos;/&apos; || TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;) FROM IESIRI1 I1, IESIRI I WHERE I1.CODIES1 = V_REC.CODLINIEDOCIMP AND I.CODIES = I1.CODIES)
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  FOR V_REC IN (SELECT CODIES1, TIPDOCIMP, CODLINIEDOCIMP FROM TMP_IESIRI1 WHERE NVL(TIPDOCIMP, 0) IN (1, 2, 3, 4, 5) AND NVL(CODLINIEDOCIMP, 0 ) &lt;&gt; 0)
  LOOP
    UPDATE TMP_IESIRI1
    SET INFODOCRETUR = (SELECT I.PREFIXDOC || TO_CHAR(I.NRDOC) || &apos;/&apos; || TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;) FROM INTRARI1 I1, INTRARI I WHERE I1.CODINTR1 = V_REC.CODLINIEDOCIMP AND I.CODINTR = I1.CODINTR)
    WHERE CODIES1 = V_REC.CODIES1;
  END LOOP;

  IF TIPIES = 24 THEN
    INSERT INTO TMP_DEZASAMBLARI( codLivr1, codNIRSTOC, valoare, rest, inchisa )
    SELECT T.codLivr1, T.codNIRSTOC, T.valoare, T.valoare - Nvl(T1.Valoare,0), T.Inchisa
    FROM Dezasamblari T
      LEFT JOIN (
        Select CodLivr1, Sum(Nvl(Valoare, 0)) Valoare from Dezasamblari1 where CodLivr1 IN (SELECT CODLivr1 FROM TMP_LIVR1) group by CODLivr1
      ) T1 ON T1.CODLivr1 = T.CODLivr1
    WHERE T.CODLivr1  IN (SELECT CODLivr1 FROM TMP_LIVR1);

    Select Count(*) into vCount from TMP_DEZASAMBLARI;

    IF vCount &gt; 0 THEN
      UPDATE tmp_iesiri set DEZAGREGARE = 1;
    END IF;
    update tmp_iesiri1 i1
    set
      denobiectorig = (
      select o.denumire
      from comanda1 c1
           inner join nartobj o on o.codobiect = c1.codobiect
      where i1.codcmdint1 = c1.codcomanda1
      )
    where i1.codcmdint1 &gt; 0;
  END IF;

  UPDATE TMP_IESIRI I
  SET GESTLIVRARESEDIU = (SELECT GESTLIVRARE FROM NAGENDA A WHERE A.CODAGENDA = I.CODLOCATIE);

  BEGIN
    select count(*) into vCount from inventar where recid = marire or recid = diminuare;
  EXCEPTION
    WHEN OTHERS THEN vCount := 0;
  END;

  IF TipIes = 15 and vCount &gt; 0 THEN
    for v_rec in (
      select i1.codies1, ns.d1, ns.d2, ns.d3
      from tmp_iesiri1 i1
        inner join tmp_iesiri i on i.codies = i1.codies
        inner join tmp_livr1 l1 on l1.codies1 = i1.codies1
        inner join tmp_livr l on l1.codlivr = l.codlivr and l.codies = i.codies
        inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
        inner join nir on nir.codies = i.codies and nir.codnir = ns.codnir
    ) loop
      update tmp_iesiri1 set d1 = v_rec.d1, d2 = v_rec.d2, d3 = v_rec.d3 where codies1 = v_rec.codies1;
    end loop;
  end if;

  -- ARTICOLELE CU UM1 CARE nu au dimensiuni provenite de pe diverse cratchi,
  -- le initializez cu D-urile implicite
    UPDATE TMP_IESIRI1 I1
    SET (       D1,   D2,   D3) =
        (SELECT A.D1, A.D2, A.D3 FROM NARTOBJ O INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL WHERE O.CODOBIECT = I1.CODOBIECT)
    WHERE Coalesce( UM1, 0) &lt;&gt; 0
      AND Coalesce( RELATIEUM1, 0) &lt;&gt; 0
      AND Coalesce( D1, 0) = 0
      AND Coalesce( D2, 0) = 0
      AND Coalesce( D3, 0) = 0;

    UPDATE TMP_IESIRI1 I1
    SET (       D1,    D2,    D3) =
        (SELECT L1.D1, L1.D2, L1.D3 FROM TMP_LIVR1 L1 WHERE I1.CODIES1 = L1.CODIES1 AND ROWNUM = 1)
    WHERE Coalesce( UM1, 0) &lt;&gt; 0
      AND Coalesce( RELATIEUM1, 0) &lt;&gt; 0
      AND Coalesce( D1, 0) = 0
      AND Coalesce( D2, 0) = 0
      AND Coalesce( D3, 0) = 0
      AND Codies1 IN (SELECT DISTINCT CodIes1 FROM TMP_LIVR1 WHERE Coalesce(D1, 0) &lt;&gt; 0 OR Coalesce(D2, 0) &lt;&gt; 0 OR Coalesce(D3, 0) &lt;&gt; 0 );

  UPDATE TMP_IESIRI1 I1
  SET CANTUM1 = CASE WHEN CANTUM1 IS NULL THEN (SELECT ROUND(SUM(NVL(CANTUM1, 0)), 7) FROM TMP_LIVR1 L1 WHERE L1.CODIES1 = I1.CODIES1) ELSE CANTUM1 END;

  IF TIPIES = 23 THEN -- iesiri catre subunitati : la IESLINK-urile directe catre comenzi client nu trebuie sa scad RESTACCEPTAT
    FOR V_REC IN (SELECT L.CODIES1, I1.CANT FROM TMP_IESLINK L, TMP_IESIRI1 I1, COMANDA1 C1, COMANDA C WHERE L.CODLINIECOMANDA = C1.CODCOMANDA1 AND C.CODCOMANDA = C1.CODCOMANDA AND C.TIPDOC = 18 AND I1.CODIES1 = L.CODIES1)
    LOOP
      UPDATE TMP_IESLINK
      SET CANT = V_REC.CANT
      WHERE CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  -- proc TVA la retururi
  IF TIPIES IN (19, 20, 21, 22, 26) THEN
    FOR V_REC IN (SELECT * FROM TMP_IESIRI1 WHERE TIPLINIE = &apos;=&apos; AND CANT &lt; 0 AND NVL(CODLINIEDOCIMP, 0) &lt;&gt; 0 AND NVL(TIPDOCIMP, 0) IN (19, 20, 21, 22, 26) )
    LOOP
      UPDATE TMP_IESIRI1
      SET PROCTVA = GETPROCTVALINIE(CODLINIEDOCIMP, V_REC.PROCTVA)
      WHERE CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  IF TIPIES = 16 THEN
      INSERT INTO TMP_MONETARLINK(CODMONETAR, CODFACTURA, NRFACTURA, DATAFACTURA, VALOARE, DEN_PART, CODFISCAL, OBS)
      SELECT RECID, I.CODIES, I.NRDOC, I.DATADOC, I.VALDOC, P.DEN_PART, CF.CODFISCAL, CASE WHEN NVL(I.INFOCM, 0) = 1 THEN &apos;InfoCM&apos; ELSE &apos;IncasIm&apos; END
      FROM IESIRI I
        INNER JOIN NPART P ON I.PARTENER = P.CODPART
        LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL
      WHERE I.CODMONETAR IS NOT NULL AND I.CODMONETAR = RECID; -- pe PG coalesce e fff lent
   END IF;

  DELETE TMP_MONETARLINK_INI;
  INSERT INTO TMP_MONETARLINK_INI SELECT * FROM TMP_MONETARLINK;

  DELETE TMP_NIRSTOC_INITIAL;
  INSERT INTO TMP_NIRSTOC_INITIAL SELECT * FROM TMP_NIRSTOC;



  IF TIPIES = 19 THEN
      aContIncasareFactura := PKG_CATEGCONST.GetValConstanta(&apos;ContIncasareFactura&apos;, PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU);

      FOR V_REC IN ( SELECT CODIESINT1 FROM TMP_LIVRTOT WHERE CODIOART = aContIncasareFactura)
      LOOP
        UPDATE TMP_IESIRI1
        SET UTILAJ = &apos;*&apos;
        WHERE CODIES1 = V_REC.CODIESINT1;
      END LOOP;
  END IF;
  INSERT INTO TMP_CMDAVANS SELECT * FROM CMDAVANS WHERE CODIESAVANS = RECID;



  FOR V_REC IN
  (SELECT I1.CODIES1
    FROM
      TMP_IESIRI1 I1
      INNER JOIN  ( SELECT
                     DISTINCT CV.VALOARE
                   FROM
                      CONST1 C1
                      INNER JOIN
                      (SELECT CODCONST1, CODCONSTLUNA
                        FROM
                          CONSTLUNA WHERE
                          ALSTART &lt;= AnLunaLucru  AND ALSTOP &gt;= AnLunaLucru
                       ) CL   ON C1.CODCONST1 = CL.CODCONST1
                       INNER JOIN CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
                      WHERE
                        UPPER(SIMBOL) = &apos;ARTVOUCHERCADOU&apos;
                  ) VOUCHER ON VOUCHER.VALOARE = TO_CHAR(I1.CODOBIECT)
    )
    LOOP
      UPDATE TMP_IESIRI1
      SET
        VOUCHERCADOU = 1
      WHERE
        CODIES1 = V_REC.CODIES1;
    END LOOP;


  INSERT INTO TMP_VOUCHERCADOULINK(COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT)
  SELECT COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART, DATASTOP, ZILEVALABIL, CODOBIECT, POSTAT
  FROM
    VOUCHERCADOULINK
  WHERE
    TIPDOC = TIPIES
    AND CODDOC = RECID;

  DELETE TMP_VOUCHERCADOULINK_INI;

  INSERT INTO TMP_VOUCHERCADOULINK_INI(TIPOPERATIE, BARCODE) SELECT TIPOPERATIE, BARCODE FROM TMP_VOUCHERCADOULINK;

  PKG_CFGTABLES.EXT_GOTORECORD(TIPIES);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
  VCOD          NUMBER(20);
  fNR           NUMBER(20);
  TIPIES        INTEGER     := 0;
  TIPTRANZ      INTEGER     := 0;
  AOPERAT       INTEGER     := 0;
  AANULAT       INTEGER     := 0;
  ACARNET       INTEGER     := 0;
  ANUMARDOC     INTEGER     := 0;
  ACARNETCERTIF INTEGER     := 0;
  ANUMARCERTIF  INTEGER     := 0;
  OLDCARNETLIVR NUMBER(20)  := 0;
  OLDNRLIVR     NUMBER(20)  := 0;
  vCODNIRSTOC   NUMBER(20)  := 0;
  vCODNIR       NUMBER(20)  := 0;
  vCODINTR      NUMBER(20)  := 0;
  vCODINTR1     NUMBER(20)  := 0;
  vCODNIRSER    NUMBER(20)  := 0;
  aCODSERIE     VARCHAR(30) := &apos;&apos;;
  NOMSERIE      VARCHAR(75) := &apos;&apos;;
  ACODMONEDA    INTEGER     := 0;
  ACURS         NUMBER(20, 7) := 1;
  REZERVCMDORIG NUMBER(20) := 0;
  aTIPTVA       INTEGER     := 0;
  aCODPART      NUMBER(20)  := 0;
  AutoColet     NUMBER(1);

  CONSTOPERAT   INTEGER     := 0;
  NR            NUMBER(20);
  CODCMD1       NUMBER(20);

  IESPRELATAS number(1) := 0;
  aCodSubunit number(20);
  aDataDoc date;
  aDoc varchar2(200);
  aCodInventar number(20);
  ATVAINCASARE  INTEGER     := 0;
  aDATATVA     DATE;
  aZILETVAINCASARE INTEGER     := 0;
  StornoAvize   varchar2(20);
  AEXCLUSPLATA   NUMBER(1) := 0;
  aCountBCAR number(20);
  aDelegat number(20);
  aPartGest number(20);

  aTIPIES  NUMBER(10);
  NRCHELT  NUMBER(10);
  aVALOARE NUMBER(20, 7);
  aRest    NUMBER(20, 7);

  PRET_IMB_MF   NUMBER(20, 7);
  VAL_ACHIZ_MF NUMBER(20, 7);
  CANT_IMB_MF  NUMBER(20, 7);
  aValT number(20,7);
  sNUMEDELEGAT varchar2(100);
  OldPU number(20,7);
  oldcodcontract1 number(20);
  oldcodcontract number(20);
  aCodContract number(20);
--  MasaMin number(20,7);
--  ValoareMin number(20,7);
--  Exista_ET number;
BEGIN
BEGIN
  begin
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SELUTILAJIES&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO ConstSelUtilaj FROM DUAL;
  exception when others then ConstSelUtilaj := 2;
  end;
  ClearManevraPtUtilaje;
  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  Repara_TMP_Iesiri_OBS;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADACCEPTATNEOP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERAT  := 0;
  END;
  DELETE TMP_LINIICODIF;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;IESPRELATAS&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO IESPRELATAS FROM DUAL;
    EXCEPTION WHEN OTHERS THEN IESPRELATAS := 0;
  END;

  SELECT
     TMP.TIPDOC, TMP.TipTranzactie,
     TMP.OPERAT,
     TMP.ANULAT,
     TMP.CARNETDOC,
     TMP.NRDOC,
     TMP.NRCERTIF,
     TMP.CARNETCERTIF,
     TMP.SUBUNITATEA,
     TMP.DATADOC,
     TMP.PREFIXDOC||TMP.NRDOC||&apos;/&apos;||TMP.DATADOC,
     TMP.MONEDA,
     TMP.CURS,
     TMP.TIPTVA,
     TMP.PARTENER,
     nvl(p.musaicolet,0),
     NVL(TMP.TVAINCASARE, 0),
     TMP.DATATVA,
     NVL(TMP.EXCLUSPLATA, 0),
     tmp.delegat,
     case when tmp.tipdoc = 24 then tmp.codgestprod else tmp.partener end,
     tmp.valdoc,
     coalesce(tmp.codcontract,0)
  INTO
     TIPIES, TipTranz,
     AOPERAT,
     AANULAT,
     ACARNET,
     ANUMARDOC ,
     ANUMARCERTIF,
     ACARNETCERTIF,
     aCodSubunit,
     aDataDoc,
     ADOC,
     aCODMONEDA,
     aCURS,
     aTIPTVA,
     aCODPART,
     AutoColet,
     aTVAIncasare,
     aDATATVA,
     aEXCLUSPLATA,
     aDelegat,
     aPartGest,
     aValT,
     aCodContract
  FROM TMP_IESIRI TMP
    LEFT JOIN npart p ON tmp.partener = p.codpart;

  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (TIPIES);

  IF TIPIES = 23 THEN -- iesiri catre subunitati : la IESLINK-urile directe catre comenzi client nu trebuie sa scad RESTACCEPTAT
    FOR V_REC IN (
      SELECT L.CODIES1
      FROM TMP_IESLINK L, COMANDA1 C1, COMANDA C
      WHERE L.CODLINIECOMANDA = C1.CODCOMANDA1 AND C.CODCOMANDA = C1.CODCOMANDA AND C.TIPDOC = 18
    ) LOOP
      UPDATE TMP_IESLINK
      SET CANT = 0
      WHERE CODIES1 = V_REC.CODIES1;
    END LOOP;
  END IF;

  UPDATE TMP_GENERAL
  SET EXCLUSPLATA = aEXCLUSPLATA;

  IF tipies = 24 THEN
    DELETE tmp_manevra;
    INSERT INTO tmp_manevra(codunic)
    SELECT DISTINCT CODNIRSTOC
    FROM (
      SELECT NVL(ns.codnirstoc, 0) AS CODNIRSTOC
      FROM
        tmp_livr1 l1
        inner join tmp_iesiri1 i1 on i1.codies1 = l1.codies1 and i1.codcmdint1 &gt; 0
        inner join intrari1 intr1 on intr1.codcmdint1 = i1.codcmdint1
        inner join nirstoc ns on ns.codintr1 = intr1.codintr1
      UNION
      SELECT NVL(ns.codnirstoc, 0) AS CODNIRSTOC
      FROM livr1 l1
           inner join livr l on l1.codlivr = l.codlivr
           inner join iesiri1 i1 on i1.codies1 = l1.codies1 and i1.codcmdint1 &gt; 0
           inner join iesiri i on i.codies = l.codies and i1.codies = i.codies
           inner join intrari1 intr1 on intr1.codcmdint1 = i1.codcmdint1
           inner join nirstoc ns on ns.codintr1 = intr1.codintr1
      WHERE i.codies = recid
    )
    WHERE CODNIRSTOC &gt; 0;
  END IF;

 IF TIPIES IN (19, 20, 26) THEN
 UPDATE TMP_GENERAL
 SET DATATVA = NVL(aDATATVA, aDATADOC)
 WHERE SEMNIFICATIE = 200;
 END IF;



  -- din adaugare poz.noi in stoc si renuntari este posibil sa ramana niruri fara detalii;
  FOR V_REC IN (SELECT * FROM TMP_NIR WHERE CODNIR &lt; 0 )
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NIRSTOC WHERE CODNIR = V_REC.CODNIR;
    IF NR = 0 THEN
      DELETE FROM TMP_INTRARI WHERE CODINTR = V_REC.CODINTR;
      DELETE FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR;
    END IF;
  END LOOP;

  aCountBCAR := 0;
  IF OPERATION = 0 THEN  -- UPDATE
    -- MASTER IESIRI
    select count(1) into aCountBCAR
    from tmp_iesiri1 i1
         inner join bcar b on i1.codies1 = b.coddoc1 and b.tipdoc = tipies
    where (aDelegat &lt;&gt; b.coddelegat or aPartGest &lt;&gt; b.codpartener) and i1.codies1 &gt; 0;

    SELECT CODIES INTO RECID FROM TMP_IESIRI;

    CheckOldUtilaje(RecId);

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;IESIRI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE IESIRI
    SET
     (  CODIES, TIPDOC,  ANULAT,  BLOCAT,   OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC, Is_ETransp,
        NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE,  VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
        ACCIZE, DELEGAT,  AGENT, MAJORARI,  OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, TIPCONSUMATOR, CODAUTO,
        PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION, MONEDA, CURS, MIJLTRANSP, LISTAT,
        CUSTODIE, FARATRANSPORT,StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC,  NRTRANSP, MONEDATRANSF, NRI, CONTSUPLIM,
        DATAINREG, CARNETCERTIF, NRCERTIF, SERIACERTIF, ExclusPlata, ExclusIntrastat, PROCTVADOC, FaraReg, TVAIncasare, DataTVA, CODANALIZA, CODCONTRACT, FACTSIMPLIF,
        TRANSPORTATOR, iddescarcare, valdocefact,CodPArtTERT, CODAECUSTODIE, STADIUWMS, CODMONETAR, NUMARBONURI, EMISADECLIENT, NRINFOCM, NRINCASULT, NRINCASIM,TIPLIVRARE, NATURATRANZ, MODTRANSP, SPLITTVA, GRATIE, TipSAFT, RotEFact, CODTVASERV, PROCTVAOSS, TipET, NOACCIZE,
        NRNIR, DATANIR, PLATFORMA_ONLINE, REMORCA, PROIECT, CONTRACT, COMANDA, FLAGS) =
     (SELECT
        RECID, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC, IS_ETRANSP,
        NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
        ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, TIPCONSUMATOR, CODAUTO,
        PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION, MONEDA, CURS, MIJLTRANSP, LISTAT,
        CUSTODIE, FARATRANSPORT,StareRestituire, IDIMPORT,  TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, MONEDATRANSF, NRI, CONTSUPLIM,
        DATAINREG, CARNETCERTIF, NRCERTIF, SERIACERTIF, ExclusPlata, ExclusIntrastat,PROCTVADOC, FaraReg, TVAIncasare, DataTVA, CODANALIZA, CODCONTRACT, FACTSIMPLIF,
        TRANSPORTATOR, iddescarcare, valdocefact,CodPArtTERT, CODAECUSTODIE, STADIUWMS, CODMONETAR, NUMARBONURI, EMISADECLIENT, NRINFOCM, NRINCASULT, NRINCASIM,TIPLIVRARE, NATURATRANZ, MODTRANSP, SPLITTVA, GRATIE, TipSAFT, RotEFact,  CODTVASERV, PROCTVAOSS, TipET, NOACCIZE,
        NRNIR, DATANIR, PLATFORMA_ONLINE, REMORCA, PROIECT, CONTRACT, COMANDA, FLAGS
      FROM TMP_IESIRI
     )
    WHERE CODIES = RECID;

    -- DETALIU MODPLATA


      UPDATE TMP_IESPUNCTE
      SET
        CODIES = RECID;

      FOR V_REC IN (SELECT * FROM TMP_IESPUNCTE)
      LOOP
        IF V_REC.CODIESPUNCTE &lt; 0 THEN
          INSERT INTO IESPUNCTE(CODIESPUNCTE, CODIES, PUNCTEDOC)
          VALUES(SEQ_IESPUNCTE_CODIESPUNCTE.NEXTVAL, V_REC.CODIES, V_REC.PUNCTEDOC);
        ELSE
          UPDATE IESPUNCTE
          SET
            PUNCTEDOC = V_REC.PUNCTEDOC
          WHERE
            CODIESPUNCTE = V_REC.CODIESPUNCTE;
        END IF;
      END LOOP;



    DELETE FROM MODURIPLATI WHERE CODIES = RECID AND CODMODPLATA NOT IN (SELECT CODMODPLATA FROM TMP_MODURIPLATI);

    FOR V_REC IN (SELECT * FROM TMP_MODURIPLATI)
    LOOP
      IF V_REC.CODMODPLATA &lt; 0 THEN
        INSERT INTO MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
          VALUES (SEQ_MODURIPLATI_CODMODPLATA.NEXTVAL, RECID, V_REC.TIPPLATA, V_REC.CODBANKCONT, V_REC.VALOARE, V_REC.DENMODPLATA);
      ELSE
        UPDATE MODURIPLATI
        SET
          TIPPLATA    = V_REC.TIPPLATA,
          CODBANKCONT = V_REC.CODBANKCONT,
          VALOARE     = V_REC.VALOARE,
          DENMODPLATA = V_REC.DENMODPLATA
        WHERE
          CODMODPLATA = V_REC.CODMODPLATA;
      END IF;
    END LOOP;

    DELETE FROM MODPLATA2 WHERE CODIES = RECID AND CODMODPLATA2 NOT IN (SELECT CODMODPLATA2 FROM TMP_MODPLATA2);

    FOR V_REC IN (SELECT * FROM TMP_MODPLATA2)
    LOOP
      IF V_REC.CODMODPLATA2 &lt; 0 THEN
        INSERT INTO MODPLATA2(CODMODPLATA2, CODIES, CODCARD, VALOARE)
          VALUES (SEQ_MODPLATA2_CODMODPLATA2.NEXTVAL, RECID, V_REC.CODCARD, V_REC.VALOARE);
      ELSE
        UPDATE MODPLATA2
        SET
          VALOARE     = V_REC.VALOARE
        WHERE
          CODMODPLATA2 = V_REC.CODMODPLATA2;
      END IF;
    END LOOP;

    -- DETALIU DISCMONETAR
    DELETE TMP_DISCMONETAR WHERE NVL(DISCOUNT, 0) + NVL(TVADISCOUNT, 0) = 0;

    DELETE FROM DISCMONETAR WHERE CODIES = RECID AND CODDISCMONETAR NOT IN (SELECT CODDISCMONETAR FROM TMP_DISCMONETAR);

    FOR V_REC IN (SELECT * FROM TMP_DISCMONETAR)
    LOOP
      IF V_REC.CODDISCMONETAR &lt; 0 THEN
        INSERT INTO DISCMONETAR(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
          VALUES (SEQ_DISCMONETAR_CODDISCMONETAR.NEXTVAL, RECID, V_REC.PROCTVA, V_REC.DISCOUNT, V_REC.TVADISCOUNT);
      ELSE
        UPDATE DISCMONETAR
        SET
          DISCOUNT     = V_REC.DISCOUNT,
          TVADISCOUNT  = V_REC.TVADISCOUNT
        WHERE
          CODDISCMONETAR = V_REC.CODDISCMONETAR;
      END IF;
    END LOOP;

    DELETE FROM CMDAVANS WHERE CODIESAVANS = RECID AND CODCMDAVANS NOT IN (SELECT CODCMDAVANS FROM TMP_CMDAVANS);
    INSERT INTO CMDAVANS(CODCMDAVANS, CODCOMANDA, CODIESAVANS)
    SELECT SEQ_CMDAVANS_CODCMDAVANS.NEXTVAL, CODCOMANDA, RECID
    FROM
      TMP_CMDAVANS
    WHERE
       CODCMDAVANS &lt; 0;

    DELETE FROM TVAMONETAR WHERE CODIES = RECID AND CODTVAMONETAR NOT IN (SELECT CODTVAMONETAR FROM TMP_TVAMONETAR);
    FOR V_REC IN (SELECT * FROM TMP_TVAMONETAR) LOOP
      IF V_REC.CODTVAMONETAR &lt; 0 THEN
        INSERT INTO TVAMONETAR(CODTVAMONETAR, CODIES, CODTVA, VALOARE, TVA, BONURI)
        VALUES(SEQ_TVAMONETAR_CODTVAMONETAR.NEXTVAL, RECID, V_REC.CODTVA, V_REC.VALOARE, V_REC.TVA, V_REC.BONURI);
      ELSE
        UPDATE TVAMONETAR
        SET
          CODTVA  = V_REC.CODTVA,
          VALOARE = V_REC.VALOARE,
          BONURI  = V_REC.BONURI,
          TVA     = V_REC.TVA
        WHERE
          CODTVAMONETAR = V_REC.CODTVAMONETAR;
      END IF;
    END LOOP;

    DELETE FROM IESDISC WHERE CODIES = RECID AND CODIESDISC NOT IN (SELECT CODIESDISC FROM TMP_IESDISC);
    FOR V_REC IN (SELECT * FROM TMP_IESDISC) LOOP
      IF V_REC.CODIESDISC &lt; 0 THEN
        INSERT INTO IESDISC(CODIESDISC, CODIES, CODDISCOUNT, OFFINVOICE, Valoare, CodObiect, PROCENT)
          VALUES (SEQ_IESDISC_CODIESDISC.NEXTVAL, RECID, V_REC.CODDISCOUNT, V_REC.OFFINVOICE, V_REC.Valoare, V_REC.CodObiect, V_REC.PROCENT);
      ELSE
        UPDATE IESDISC
        SET
          CODDISCOUNT   = V_REC.CODDISCOUNT,
          OFFINVOICE    = V_REC.OFFINVOICE,
          Valoare       = V_REC.Valoare,
          PROCENT       = V_REC.PROCENT,
          CodObiect     = V_REC.CodObiect
        WHERE
          CODIESDISC = V_REC.CODIESDISC;
      END IF;
    END LOOP;

    DELETE FROM OBLIGPIF
    WHERE CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RECID AND TIPDOC = TIPIES)
      AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

    DELETE FROM GENERAL
    WHERE CODDOC = RECID AND TIPDOC = TIPIES
      AND CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

    DELETE FROM STINGERE
    WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE_INITIAL WHERE CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE));

    -- DETAIL GENERAL
    FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
      IF NVL(V_REC.CODGENERAL, 0) &gt; 0  THEN
        UPDATE GENERAL G
        SET
          TIPDOC       = V_REC.TIPDOC,
          CODDOC       = V_REC.CODDOC,
          MONEDA       = V_REC.MONEDA,
          CURS         = V_REC.CURS,
          ICONTAVANS   = V_REC.ICONTAVANS,
          PROCTVAAVANS = V_REC.PROCTVAAVANS,
          SEMNIFICATIE = V_REC.SEMNIFICATIE,
          TVA          = v_rec.TVA,
          ExclusPlata  = v_rec.ExclusPlata,
          DataTVA      = v_rec.DataTVA,
          FaraReg      = v_rec.FaraReg
        WHERE
          G.CODGENERAL = V_REC.CODGENERAL;
      ELSE
       SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO VCOD FROM DUAL;
       INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg)
       VALUES (VCOD, V_REC.TIPDOC, V_REC.CODDOC, V_REC.MONEDA, V_REC.CURS, V_REC.SEMNIFICATIE, V_REC.ICONTAVANS, V_REC.PROCTVAAVANS, V_REC.TVA, V_REC.ExclusPlata, v_rec.DataTVA, V_REC.FaraReg);

       UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD  WHERE CODGENERAL = V_REC.CODGENERAL;

      END IF;
    END LOOP;

    -- Detail OBLIGPIF
    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF) LOOP
      IF NVL(v_rec.CODOBLIGPIF, 0) &gt; 0 THEN
        UPDATE OBLIGPIF
        SET
          CODGENERAL   = v_rec.CODGENERAL,
          TERMEN       = v_rec.TERMEN,
          VALOARE      = NVL(v_rec.VALOARE, 0),
          DINCARETVA   = NVL(v_rec.DINCARETVA, 0),
          REST         =
           (
            CASE
              WHEN V_REC.SEMNIFICATIE = 211 THEN NULL
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 211 AND v_rec.VALOARE &gt; 0 THEN v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 211 AND v_rec.VALOARE &lt; 0 THEN v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
            END),

          RESTTVA         =
           (
            CASE
              WHEN V_REC.SEMNIFICATIE = 211 THEN NULL
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 211 AND NVL(v_rec.VALOARE, 0) &gt; 0 THEN NVL(v_rec.DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 211 AND NVL(v_rec.VALOARE, 0) &lt; 0 THEN NVL(v_rec.DINCARETVA, 0) + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
            END),
          CODPART      = v_rec.CODPART,
          ICONT        = v_rec.ICONT,
          TIPPLATA     = v_rec.TIPPLATA,
          CODCENTRU    = V_REC.CODCENTRU,
          MAJORARI     = v_rec.MAJORARI,
          GRATIE       = V_REC.GRATIE,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          TIP          = v_rec.TIP,
          CODANALIZANOD= V_REC.CODANALIZANOD
        WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;
      ELSE
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
        UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
        UPDATE TMP_IESIRI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;
        UPDATE TMP_IESIRI1 SET CODOBLIGMONETAR = vCOD WHERE CODOBLIGMONETAR = v_rec.CODOBLIGPIF;

        INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU, MAJORARI, SEMNIFICATIE, TIP, CODANALIZANOD, DINCARETVA, RESTTVA, GRATIE)
        VALUES (VCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, V_REC.CODCENTRU, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, V_REC.CODANALIZANOD, V_REC.DINCARETVA, V_REC.DINCARETVA, V_REC.GRATIE);
      END IF;
    END LOOP;

    -- STINGERE
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE);
      END IF;
    END LOOP;

    -- DETAIL IESLINK
    DELETE FROM IESLINK WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_IESLINK)
    );
    DELETE FROM IESPRODLINK WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_IESPRODLINK)
    );
    DELETE FROM FACTSALINK WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_FACTSALINK)
    );
    -- DETAIL IESLINK -- VALORICE FARA DESCARCARE
    DELETE FROM IESVALLINK WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_IESVALLINK)
    );


-- DETAIL IESLINK -- VALORICE COMPUSE FARA DESCARCARE
    DELETE FROM IESVALLINK IL
    WHERE CODIES = RECID
      AND NOT EXISTS (SELECT CODLIVR1 FROM TMP_IESVALLINK WHERE CODLIVR1 = IL.CODLIVR1);

    DELETE PACHETELINK PL
    WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_PACHETELINK)
    );


    DELETE PACHETEOBJLINK PL
    WHERE CODIES1 IN
    ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN
     (SELECT CODIES1 FROM TMP_PACHETEOBJLINK)
    );
-- DETAIL NIRSTOC -- INAINTE DE LIVR1
/*
DELETE FROM NIRSTOC NS
WHERE
  EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NS.CODNIRSTOC)
AND NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC);
*/

-- DETAIL IESIRI1
    FOR v_Rec IN ( SELECT CODIES1 FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1) )
    LOOP

       FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODIES1 = V_REC.CODIES1)
       LOOP

         FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC = 106) LOOP
           UPDATE NCONTRUL
           SET
             RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
             RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
           WHERE
             CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

           UPDATE NCONTRUL
           SET
             RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
             RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
           WHERE
             CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
         END LOOP;


         DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 106;
         DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 106;
         DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
         DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       END LOOP;

       DELETE FROM MASTERCHELTAVANS WHERE CODIES1 = V_REC.CODIES1;
       DELETE FROM TAXDECL WHERE TipDoc = TIPIES and CODDOC1 = V_REC.CODIES1;

      DELETE FROM IESIRI1 WHERE CODIES1 = V_REC.CODIES1;
      UPDATE UTILAJE SET NRCONTR = NULL, DATACONTR = NULL, CODIES1 = NULL    WHERE CODIES1        = V_REC.CODIES1;
      UPDATE BCAR    SET TIPDOC = NULL, CODDOC1 = NULL, USERIDBLOCAJ = NULL  WHERE CODDOC1        = V_REC.CODIES1 AND TIPDOC    = TIPIES;
      UPDATE IESIRI1 SET CODLINIEDOCIMP = NULL, TIPDOCIMP = NULL             WHERE CODLINIEDOCIMP = V_REC.CODIES1 AND TIPDOCIMP = TIPIES;
      UPDATE CANTAR  SET TIPDOC = NULL, CODDOC1 = NULL                       WHERE CODDOC1        = V_REC.CODIES1 AND TIPDOC    = TIPIES;
    END LOOP;
    --DELETE FROM IESIRI1 WHERE CODIES = RECID AND CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1);

    FOR V_REC IN (SELECT * FROM TMP_IESIRI1  ORDER BY INDEXLOCAL) LOOP
      CODCMD1 := V_REC.CodCmdInt1;
      IF TIPIES = 24 and Nvl(CODCMD1,0) = 0 THEN
        CODCMD1 := GetLinieComInt(0,V_REC.OBS,V_REC.OBS);
      END IF;
      IF NVL(V_REC.CODIES1, 0) &gt; 0 /*G_CODIES1*/ THEN
         PRET_IMB_MF := 0; VAL_ACHIZ_MF := 0; CANT_IMB_MF := 0;
         IF NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND TIPIES = 14 THEN
           BEGIN
             SELECT SUM(L1.CANT) AS CANTDIMIN,
                    SUM(L1.CANT * (NS.PRET - COALESCE(NS.ADAOS, 0))) AS VALDIMIN
             INTO
               CANT_IMB_MF,
               VAL_ACHIZ_MF
             FROM
               TMP_LIVR1 L1,
               NIRSTOC NS
             WHERE
               L1.CODIES1 = V_REC.CODIES1
               AND NS.CODNIRSTOC = L1.CODNIRSTOC
             GROUP BY L1.CODIES1;
             EXCEPTION WHEN OTHERS THEN
               NULL;
           END;

           IF NVL(CANT_IMB_MF, 0) &lt;&gt; 0 THEN
             PRET_IMB_MF := VAL_ACHIZ_MF / CANT_IMB_MF;
           END IF;
         END IF;
       select pu,codcontract1 into oldpu,oldcodcontract1 from iesiri1 where codies1 = v_rec.codies1;
       if oldcodcontract1 &gt; 0 and oldcodcontract1 &lt;&gt; v_rec.codcontract1 then
         --actualizez si bcar-ul daca exista
         update bcar set codcontract1 = v_rec.codcontract1
         where coddoc1 = v_rec.codies1 and tipdoc = tipies and codcontract1 &gt; 0;
       end if;
        UPDATE IESIRI1 SET
          INDEXLOCAL       = V_REC.INDEXLOCAL,
          TIPLINIE         = V_REC.TIPLINIE,
          TipLivrare       = V_REC.TipLivrare,
          UMSEC            = V_REC.UMSEC,
          CONTSERV         = V_REC.CONTSERV,
          CONTDISCOUNT     = V_REC.CONTDISCOUNT,
          CODCRITERIU      = V_REC.CODCRITERIU,
          MIFIX            = V_REC.MIFIX,
          ZILE             = V_REC.ZILE,
          ZILECMD          = V_REC.ZILECMD,
          GESTACT          = V_REC.GESTACT,
          CODOBIECT        = V_REC.CODOBIECT,
--          PRETORIG         = V_REC.PRETORIG  / NVL(V_REC.PARITATE, 1),
--          PU               = V_REC.PU   / NVL(V_REC.PARITATE, 1),
          PRETORIG         = PKG_IESIRI.PRETVANZARE(TIPIES,
                                                   NVL(V_REC.ROTUNJIRE, 0),
                                                   V_REC.PRETORIG,
                                                   NVL(V_REC.PARITATE,1),
                                                  1),
          PU               = PKG_IESIRI.PRETVANZARE(TIPIES,
                                                   NVL(V_REC.ROTUNJIRE, 0),
                                                   V_REC.PU,
                                                   NVL(V_REC.PARITATE,1),
                                                  1),
          CANT             = V_REC.CANT * NVL(V_REC.PARITATE, 1),
          TVA              = V_REC.TVA,
          CONT             = V_REC.CONT,
          PROCDISC         = V_REC.PROCDISC,
          CODOBLIGSTORNO   = V_REC.CODOBLIGSTORNO,
          CURSFACTURAAVANS = V_REC.CURSFACTURAAVANS,
          COEFDISCMAJ      = V_REC.COEFDISCMAJ,
          OBS              = V_REC.OBS,
          CODOBIECTORIG    = V_REC.CODOBIECTORIG,
          PARITATEORIG     = V_REC.PARITATEORIG,
          ADDIM            = V_REC.ADDIM,
          CODLIVR1PRODVAL  = V_REC.CODLIVR1PRODVAL,
          CODIES1STORNO    = V_REC.CODIES1STORNO,
          CODOFERTA1       = V_REC.CODOFERTA1,
          CADOU            = V_REC.CADOU,
          TAXA             = V_REC.TAXA,
          TERMENCONTRACT   = V_REC.TERMENCONTRACT,
          CADOULINK        = V_REC.CADOULINK,
          CODIOARTCUST     = V_REC.CODIOARTCUST,
          UMCorelat        = V_REC.UMCorelat ,
          CANTCorelat      = V_REC.CANTCorelat,
          PUCorelat        = V_REC.PUCorelat  ,
          PRETPROMO        = V_REC.PRETPROMO,
          TIPPLATA         = V_REC.TIPPLATA,
          CODCENTRU        = V_REC.CODCENTRU,
          CODCADOU         = V_REC.CODCADOU,
          CODOBLIGMONETAR  = V_REC.CODOBLIGMONETAR,
          CODLINIEDOCIMP   = V_REC.CODLINIEDOCIMP,
          TIPDOCIMP        = V_REC.TIPDOCIMP,
          CODCMDINT1       = CODCMD1,
          CUSTODIEINTRARE  = V_REC.CUSTODIEINTRARE,
          ICONTPART        = V_REC.ICONTPART,
          CANTCONSTATAT    = V_REC.CANTCONSTATAT,
          DISCMANUAL       = V_REC.DISCMANUAL,
          CODUTILAJ        = V_REC.CODUTILAJ,
          PRETUM1          = V_REC.PRETUM1,
          IMPOZABIL        = V_REC.IMPOZABIL,
          CODPARTCOMISEMUL = V_REC.CODPARTCOMISEMUL,
          CODAUTO          = V_REC.CODAUTO,
          CODANALIZANOD    = V_REC.CODANALIZANOD,
          D1D3BCS          = V_REC.D1D3BCS,
          CODOBLIGMAJORAT  = V_REC.CODOBLIGMAJORAT,
          CODAGENTEMULARE  = V_REC.CODAGENTEMULARE,
          CODPROMO1        = V_REC.CODPROMO1,
          CODCONTRACT1     = V_REC.CODCONTRACT1,
          VALDISCPRET      = V_REC.VALDISCPRET,
          Preluat          = V_REC.Preluat,
          CODMIFIX         = V_REC.CODMIFIX,
          RestIMBMF        = CASE
                                WHEN v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND aOperat = 1 AND aAnulat = 0
                                THEN PRET_IMB_MF * V_REC.CANT -    --v_rec.Cant * v_rec.PU -
                                  (SELECT NVL(SUM(IL.CANT), 0)
                                   FROM
                                     IMBMIFIXLINK IL
                                     LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                                     LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                                   WHERE
                                     IL.CODIES1 = v_Rec.CodIES1 AND T.OPERAT = 1 AND T.ANULAT = 0
                                  )
                                ELSE 0
                             END,
  -- SUNT PE AVIZ - RECALCULEZ RESTUL
          RESTFACT     =
          CASE
            WHEN V_REC.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND TIPIES = 20 AND AOPERAT = 1 AND AANULAT = 0
            THEN V_REC.CANT * V_REC.PARITATE -
              (SELECT NVL(SUM(IL.CANT), 0) -- STINFERI PRIN FACTURA LA AVIZ
                FROM
                  IESLINK IL
                  LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                WHERE
                  IL.CODLINIEAVIZ = V_REC.CODIES1 AND I.TIPDOC = 26 AND I.OPERAT = 1 AND I.ANULAT = 0
              ) +
              (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  IESIRI1 AE1,
                  IESIRI  AE
                WHERE
                  AE1.CODIES1STORNO = V_REC.CODIES1 AND AE.CODIES = AE1.CODIES
                AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
              )
            WHEN V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_REC.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT LA LINIILE DE DISCOUNT
            ELSE 0
          END,
          PUMaximal = V_REC.PUMaximal,
          AdMax     = V_REC.AdMax,
          GARANTIE  = V_REC.GARANTIE,
          D1        = V_REC.D1,
          D2        = V_REC.D2,
          D3        = V_REC.D3,
          CANTUM1   = V_REC.CANTUM1,
          CODSERIE  = V_REC.CODSERIE
        WHERE
          CODIES1 = V_REC.CODIES1;

        BEGIN
          SELECT COUNT(*) INTO NRCHELT FROM CHELTAVANS WHERE CODIES1 = V_REC.CODIES1;
          EXCEPTION WHEN OTHERS THEN NRCHELT :=0;
        END;

        IF NRCHELT &gt; 0 THEN
          --IF TIPIES = 3
           -- THEN aVALOARE := ROUND((V_REC.PU * V_REC.CANT - V_REC.TVA ) * NVL(ACURS, 1), 2);
            --ELSE
              aVALOARE := ROUND((V_REC.PU * V_REC.CANT) * NVL(ACURS, 1), 2);
          --END IF;

          FOR V_CHELT1 IN (
            SELECT CA1.CODCHELTAVANS1, CA1.CODCHELTAVANS
            FROM CHELTAVANS CA, CHELTAVANS1 CA1
            WHERE CA.CODIES1 = V_REC.CODIES1 AND CA1.CODCHELTAVANS = CA.CODCHELTAVANS AND VALOARE &lt;&gt; aVALOARE
          )
          LOOP
            UPDATE CHELTAVANS1
            SET   VALOARE = aVALOARE
            WHERE CODCHELTAVANS1 = V_CHELT1.CODCHELTAVANS1;

            UPDATE JURNAL1
            SET  DIRTY = 1
            WHERE CODDOC = V_CHELT1.CODCHELTAVANS AND TIPDOC = 106;
          END LOOP;
        END IF;

        PKG_CANTAR.UNLOCK_RECORDS(TIPIES, v_rec.CodIes1);
        PKG_BCAR.UNLOCK_RECORDS(TIPIES, v_rec.CodIes1);
        VCOD := v_rec.CodIes1;--am nevoie la apelul posibil de actualizare notecredit
      ELSE
        oldpu := 0;
        SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO VCOD FROM DUAL;
        update tmp_jurnal1 set indexlocal = vcod where indexlocal = v_rec.codies1;
        INSERT INTO TMP_LINIICODIF(OLDCODE, NEWCODE) VALUES (V_REC.CODIES1, vCOD);

        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;IESIRI1&apos;, VCOD, V_REC.CODIES1);

/*        IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_IESIRI1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
        END IF;

        IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_BONCONS1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
        END IF;

        IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_MONETAR1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
        END IF;*/

         PRET_IMB_MF := 0; VAL_ACHIZ_MF := 0; CANT_IMB_MF := 0;
         IF NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND TIPIES = 14 THEN
            BEGIN
              SELECT SUM(L1.CANT) AS CANTDIMIN,
                     SUM(L1.CANT * (NS.PRET - COALESCE(NS.ADAOS, 0))) AS VALDIMIN
              INTO
                CANT_IMB_MF,
                VAL_ACHIZ_MF
              FROM
                TMP_LIVR1 L1,
                NIRSTOC NS
              WHERE
                L1.CODIES1 = V_REC.CODIES1
                AND NS.CODNIRSTOC = L1.CODNIRSTOC
              GROUP BY L1.CODIES1;
              EXCEPTION WHEN OTHERS THEN NULL;
            END;

           IF NVL(CANT_IMB_MF, 0) &lt;&gt; 0 THEN
             PRET_IMB_MF := VAL_ACHIZ_MF / CANT_IMB_MF;
           END IF;
         END IF;

        INSERT INTO IESIRI1 (
          CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX,
          ZILE, ZILECMD, GESTACT, CODOBIECT,
          PRETORIG, PU, CANT,
          TVA, CONT, PROCDISC, ADDIM,
          RESTFACT,
          PUMaximal, AdMax, TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS,
          CODOBIECTORIG, PARITATEORIG, CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU,TAXA, TERMENCONTRACT,CADOULINK,
          CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,PRETPROMO, TIPPLATA, CODCENTRU, CODCADOU,
          CODOBLIGMONETAR, CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CUSTODIEINTRARE, ICONTPART, CANTCONSTATAT, DISCMANUAL, CODUTILAJ, CODAUTO, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT,
          CODAGENTEMULARE, CODPROMO1, CODCONTRACT1, VALDISCPRET, Preluat, CODMIFIX, RESTIMBMF, D1, D2, D3, CANTUM1, PRETUM1, IMPOZABIL, CODSERIE, CODPARTCOMISEMUL)
        VALUES (
          VCOD,   RECID, V_REC.INDEXLOCAL , V_REC.TIPLINIE,  V_REC.UMSEC, V_REC.CONTSERV, V_REC.CONTDISCOUNT, V_REC.CODCRITERIU, V_REC.MIFIX,
          V_REC.ZILE, V_REC.ZILECMD, V_REC.GESTACT,  V_REC.CODOBIECT,
          --V_REC.PRETORIG / NVL(V_REC.PARITATE,1),
          --V_REC.PU / NVL(V_REC.PARITATE,1),

         PKG_IESIRI.PRETVANZARE(TIPIES,
                               NVL(V_REC.ROTUNJIRE, 0),
                               V_REC.PRETORIG,
                               NVL(V_REC.PARITATE,1),
                               1),

         PKG_IESIRI.PRETVANZARE(TIPIES,
                               NVL(V_REC.ROTUNJIRE, 0),
                               V_REC.PU,
                               NVL(V_REC.PARITATE,1),
                               1),

          V_REC.CANT * NVL(V_REC.PARITATE, 1),
          V_REC.TVA, V_REC.CONT, V_REC.PROCDISC, V_REC.ADDIM,
          CASE
            WHEN V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_REC.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
            ELSE V_REC.CANT *  NVL(V_REC.PARITATE, 1)
          END,
          V_REC.PUMaximal, V_REC.AdMax, V_REC.TipLivrare, V_REC.GARANTIE, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS, V_REC.COEFDISCMAJ, V_REC.OBS,
          V_REC.CODOBIECTORIG, V_REC.PARITATEORIG, V_REC.CODLIVR1PRODVAL, V_REC.CODIES1STORNO, V_REC.CODOFERTA1,

          CASE WHEN
             COALESCE(V_REC.CADOU, 0) &gt;=0  THEN V_REC.CADOU
             ELSE (SELECT NEWCODE FROM TMP_LINIICODIF WHERE OLDCODE = V_REC.CADOU)
           END,

          V_REC.TAXA,V_REC.TERMENCONTRACT,  V_REC.CADOULINK,
          V_REC.CODIOARTCUST,  v_rec.UMCorelat, v_rec.CANTCorelat, v_rec.PUCorelat,V_REC.PRETPROMO, V_REC.TIPPLATA,V_REC.CODCENTRU, V_REC.CODCADOU,
          V_REC.CODOBLIGMONETAR, V_REC.CODLINIEDOCIMP, V_REC.TIPDOCIMP, CODCMD1, V_REC.CUSTODIEINTRARE, V_REC.ICONTPART,V_REC.CANTCONSTATAT, V_REC.DISCMANUAL, V_REC.CODUTILAJ, V_REC.CODAUTO,  V_REC.CODANALIZANOD, V_REC.D1D3BCS, V_REC.CODOBLIGMAJORAT, V_REC.CODAGENTEMULARE, V_REC.CODPROMO1, V_REC.CODCONTRACT1, V_REC.VALDISCPRET, V_REC.Preluat, V_REC.CODMIFIX,

          CASE WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0
          THEN
            PRET_IMB_MF * V_REC.CANT --V_REC.PU * V_REC.CANT
          ELSE 0
          END,


          V_REC.D1, V_REC.D2, V_REC.D3, V_REC.CANTUM1, V_REC.PRETUM1, V_REC.IMPOZABIL, V_REC.CODSERIE, V_REC.CODPARTCOMISEMUL
          );

        UPDATE TMP_IESIRI1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_LIVR1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_IESLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_IESPRODLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_FACTSALINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_IESVALLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_PACHETELINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
        UPDATE TMP_PACHETEOBJLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;

        PKG_CANTAR.UPDATE_RECORDS(TIPIES, v_rec.CodIes1, vCOD);
        PKG_BCAR.UPDATE_RECORDS(TIPIES, v_rec.CodIes1, vCOD);
      END IF;
      IF V_REC.CODCENTRALIZARE &gt; 0 THEN
        PKG_NOTECREDIT.UPDATE_RECORDS(TIPIES, VCOD, V_REC.CODCENTRALIZARE, aNumarDoc, aDataDoc, aValT, oldpu);
      END IF;
      IF aANULAT = 1 THEN
        UPDATE CANTAR SET TipDoc = NULL, CodDoc1 = NULL WHERE TipDoc = TIPIES AND CodDoc1 = V_REC.CODIES1;
        UPDATE BCAR   SET TipDoc = NULL, CodDoc1 = NULL WHERE TipDoc = TIPIES AND CodDoc1 = V_REC.CodIes1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_IESLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM IESLINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO IESLINK (CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT)
      VALUES  (V_REC.CODIES1, V_REC.CODLINIECOMANDA, V_REC.CODLINIEAVIZ, V_REC.CANT);
      ELSE
      UPDATE IESLINK
      SET
        CODLINIECOMANDA = V_REC.CODLINIECOMANDA,
        CODLINIEAVIZ    = V_REC.CODLINIEAVIZ,
        CANT            = V_REC.CANT
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_IESPRODLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM IESPRODLINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO IESPRODLINK (CODIES1, CODCMDPRODMAT, CANT, CODPROGRAMF1)
      VALUES  (V_REC.CODIES1, V_REC.CODCMDPRODMAT, V_REC.CANT, V_REC.CODPROGRAMF1);
      ELSE
      UPDATE IESPRODLINK
      SET
        CODCMDPRODMAT   = V_REC.CODCMDPRODMAT,
        CANT            = V_REC.CANT,
        CODPROGRAMF1    = V_REC.CODPROGRAMF1
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_FACTSALINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM FACTSALINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO FACTSALINK (CODIES1,
                                   CODCOMANDA,
                                   CODCLASEA,
                                   VALOARE)
      VALUES  (
        v_rec.CODIES1,
        v_rec.CODCOMANDA,
        v_rec.CODCLASEA,
        v_rec.VALOARE
      );
      ELSE
      UPDATE FACTSALINK
      SET
        CODCOMANDA   = V_REC.CODCOMANDA,
        CODCLASEA    = V_REC.CODCLASEA,
        VALOARE      = V_REC.VALOARE
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PACHETELINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM PACHETELINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO PACHETELINK (CODIES1, CODPACHETEOBJ, CANT)
      VALUES  (V_REC.CODIES1, V_REC.CODPACHETEOBJ, V_REC.CANT);
      ELSE
      UPDATE PACHETELINK
      SET
        CODPACHETEOBJ   = V_REC.CODPACHETEOBJ,
        CANT            = V_REC.CANT
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PACHETEOBJLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM PACHETEOBJLINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO PACHETEOBJLINK (CODIES1, CODPACHETEOBJL, CANT)
      VALUES  (V_REC.CODIES1, V_REC.CODPACHETEOBJL, V_REC.CANT);
      ELSE
      UPDATE PACHETEOBJLINK
      SET
        CODPACHETEOBJL   = V_REC.CODPACHETEOBJL,
        CANT            = V_REC.CANT
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    -- IESIRI VALORICE FARA DESCARCARE
    FOR V_REC IN (SELECT * FROM TMP_IESVALLINK WHERE CODIES1 IS NOT NULL)
    LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM IESVALLINK WHERE CODIES1 = V_REC.CODIES1;
      IF NR = 0
      THEN INSERT INTO IESVALLINK (CODIES1, CODLIVR1, CANT, TIPLINK)
      VALUES  (V_REC.CODIES1, V_REC.CODLIVR1, V_REC.CANT, V_REC.TIPLINK);
      ELSE
      UPDATE IESVALLINK
      SET
        CODLIVR1      = V_REC.CODLIVR1,
        CANT          = V_REC.CANT,
        TIPLINK       = V_REC.TIPLINK
      WHERE
        CODIES1 = V_REC.CODIES1;
      END IF;
    END LOOP;

    -- IESIRI VALORICE ARTICOLE COMPUSE FARA DESCARCARE
    FOR V_REC IN (SELECT * FROM TMP_IESVALLINK WHERE CODIES1 IS NULL)
    LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM IESVALLINK WHERE CODIES = RECID AND CODLIVR1 = V_REC.CODLIVR1;
      IF NR = 0
      THEN INSERT INTO IESVALLINK (CODIES, CODLIVR1, CANT)
      VALUES  (RECID, V_REC.CODLIVR1, V_REC.CANT);
      ELSE
      UPDATE IESVALLINK
      SET
        CANT  = V_REC.CANT
      WHERE
        CODIES = RECID
        AND CODLIVR1 = V_REC.CODLIVR1;
      END IF;
    END LOOP;


    -- INAINTE DE LIVRARI REZOLV IESIRILE IN ROSU PENTRU A AVEA APOI DE UNDE LIVRA
    -- IESIRI IN ROSU : RECODIFICARI
    -- INTRARI
    FOR V_RECINTR IN (SELECT * FROM TMP_INTRARI) LOOP
    IF V_RECINTR.CODINTR &lt; 0 THEN
      SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
      UPDATE TMP_NIR SET CODINTR = vCODINTR WHERE CODINTR = V_RECINTR.CODINTR;
      UPDATE TMP_INTRARI1 SET CODINTR = vCODINTR WHERE CODINTR = V_RECINTR.CODINTR;

      INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, ExclusPlata, FaraReg, TVAIncasare)
      VALUES(VCODINTR, V_RECINTR.TIPDOC, V_RECINTR.ANULAT, V_RECINTR.BLOCAT, V_RECINTR.OPERAT, V_RECINTR.PREFIXDOC, V_RECINTR.DATADOC, V_RECINTR.PARTENER, V_RECINTR.AN, V_RECINTR.LUNA, V_RECINTR.ExclusPlata, V_RECINTR.FaraReg, V_RECINTR.TVAIncasare);

    ELSE
      UPDATE INTRARI
      SET
        TIPDOC    = V_RECINTR.TIPDOC,
        ANULAT    = V_RECINTR.ANULAT,
        BLOCAT    = V_RECINTR.BLOCAT,
        OPERAT    = V_RECINTR.OPERAT,
        PREFIXDOC = V_RECINTR.PREFIXDOC,
        DATADOC   = V_RECINTR.DATADOC,
        PARTENER  = V_RECINTR.PARTENER,
        AN        = V_RECINTR.AN,
        LUNA      = V_RECINTR.LUNA,
        ExclusPlata = V_RECINTR.ExclusPlata,
        FaraReg     = V_RECINTR.FaraReg,
        TVAIncasare = v_recintr.TVAIncasare
      WHERE
        CODINTR = V_RECINTR.CODINTR;
    END IF;
    END LOOP;


  -- NIR
    FOR V_RECNIR IN (SELECT * FROM TMP_NIR) LOOP
    IF V_RECNIR.CODNIR &lt; 0 THEN
      SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
      UPDATE TMP_NIRSTOC SET CODNIR = VCODNIR WHERE CODNIR = V_RECNIR.CODNIR;

      INSERT INTO NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
      VALUES (VCODNIR, V_RECNIR.CODINTR, RECID, V_RECNIR.DATANIR,  V_RECNIR.GEST, V_RECNIR.TIPNIR, V_RECNIR.ANULAT, V_RECNIR.BLOCAT, V_RECNIR.OPERAT);
    ELSE
      UPDATE NIR
      SET
        CODINTR = V_RECNIR.CODINTR,
        CODIES  = V_RECNIR.CODIES,
        DATANIR = V_RECNIR.DATANIR,
        GEST    = V_RECNIR.GEST,
        TIPNIR  = V_RECNIR.TIPNIR,
        ANULAT  = V_RECNIR.ANULAT,
        BLOCAT  = V_RECNIR.BLOCAT,
        OPERAT  = V_RECNIR.OPERAT
      WHERE
        CODNIR = V_RECNIR.CODNIR;
    END IF;
    END LOOP;



  -- INTRARI1
    FOR V_RECINTR1 IN (SELECT * FROM TMP_INTRARI1) LOOP
    IF V_RECINTR1.CODINTR1 &lt; 0 THEN
      SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
      UPDATE TMP_NIRSTOC SET CODINTR1 = vCODINTR1 WHERE CODINTR1 = V_RECINTR1.CODINTR1;

      INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, CodOferta1, CODCENTRU, CODANALIZANOD)
      VALUES (VCODINTR1, V_RECINTR1.CODINTR, V_RECINTR1.INDEXLOCAL, V_RECINTR1.TIPLINIE, V_RECINTR1.UMSEC, V_RECINTR1.AN, V_RECINTR1.LUNA, V_RECINTR1.CODOBIECT,
      V_RECINTR1.PRETORIG /  NVL(V_RECINTR1.PARITATE, 1), V_RECINTR1.PU  / NVL(V_RECINTR1.PARITATE, 1), 0, V_RECINTR1.TG, V_RECINTR1.CodOferta1, V_RECINTR1.CODCENTRU, V_RECINTR1.CODANALIZANOD);

    ELSE
      UPDATE INTRARI1
      SET
        CODINTR    = V_RECINTR1.CODINTR,
        INDEXLOCAL = V_RECINTR1.INDEXLOCAL,
        TIPLINIE   = V_RECINTR1.TIPLINIE,
        UMSEC      = V_RECINTR1.UMSEC,
        AN         = V_RECINTR1.AN,
        LUNA       = V_RECINTR1.LUNA,
        CODOBIECT  = V_RECINTR1.CODOBIECT,
        PRETORIG   = V_RECINTR1.PRETORIG / NVL(V_RECINTR1.PARITATE, 1),
        PU         = V_RECINTR1.PU /  NVL(V_RECINTR1.PARITATE, 1),
        CANT       = 0,
        TG         = V_RECINTR1.TG,
        CodOferta1 = V_RECINTR1.CodOferta1,
        CODCENTRU  = V_RECINTR1.CODCENTRU,
        CODANALIZANOD = V_RECINTR1.CODANALIZANOD
      WHERE
        CODINTR1 = V_RECINTR1.CODINTR1;
    END IF;
    END LOOP;


  -- NIRSTOC
    FOR V_RECNIRSTOC IN (SELECT * FROM TMP_NIRSTOC) LOOP
    IF V_RECNIRSTOC.CODNIRSTOC &lt; 0 THEN
      SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;

      UPDATE TMP_LIVR1  SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
      UPDATE TMP_NIRSER SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;

      INSERT INTO NIRSTOC
      (CODNIRSTOC,
      CODNIR,
      CODINTR1,
      CANTNIR,
      CANTUM1,
      CANTUM2,
      REST,
      RESTUM1,
      RESTUM2,
      UMSEC,
      CODOBIECT,
      CODIOART,
      PRET,
      ADAOS,
      TVA,
      TIPSERIE,
      CODLOCATIE,
      TG,
      PUMaximal, AdMax,
      FURN,
      DATAACHIZ,
      TIPDOCACHIZ,
      D1, D2, D3,PUVAL,
      CODGESTPROD,
      SERIELOT,
      PROVIZION)
      VALUES
      ( VCODNIRSTOC,
      V_RECNIRSTOC.CODNIR,
      V_RECNIRSTOC.CODINTR1,
      V_RECNIRSTOC.CANTNIR,
      V_RECNIRSTOC.CANTUM1,
      V_RECNIRSTOC.CANTUM2,
      V_RECNIRSTOC.REST,
      V_RECNIRSTOC.RESTUM1,
      V_RECNIRSTOC.RESTUM2,
      V_RECNIRSTOC.UMSEC,
      V_RECNIRSTOC.CODOBIECT,
      V_RECNIRSTOC.CODIOART,
      V_RECNIRSTOC.PRET / NVL(V_RECNIRSTOC.PARITATE, 1),
      V_RECNIRSTOC.ADAOS /  NVL(V_RECNIRSTOC.PARITATE, 1),
      V_RECNIRSTOC.TVA, V_RECNIRSTOC.TIPSERIE,
      V_RECNIRSTOC.CODLOCATIE,
      V_RECNIRSTOC.TG,
      V_RECNIRSTOC.PUMaximal, V_RECNIRSTOC.AdMax,
      V_RECNIRSTOC.FURN,
      V_RECNIRSTOC.DATAACHIZ,
      V_RECNIRSTOC.TIPDOCACHIZ,
      V_RECNIRSTOC.D1,
      V_RECNIRSTOC.D2,
      V_RECNIRSTOC.D3,
      V_RECNIRSTOC.PUVAL,
      V_RECNIRSTOC.CODGESTPROD,
      V_RECNIRSTOC.SERIELOT,
      V_RECNIRSTOC.PROVIZION
      ) ;

      INSERT INTO NIRSTOC1 (CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      SELECT NS.CODNIRSTOC, NS.CODNIRSTOC, NIR.TIPNIR, NVL(NS.PRET,0) - NVL(NS.ADAOS,0), 0, 1, 0
      FROM NIRSTOC NS
            INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
      WHERE NS.CODNIRSTOC = vCODNIRSTOC;

    ELSE
      UPDATE NIRSTOC
      SET
        CODNIR      = V_RECNIRSTOC.CODNIR,
        CODINTR1    = V_RECNIRSTOC.CODINTR1,
        CANTNIR     = V_RECNIRSTOC.CANTNIR,
        CANTUM1     = V_RECNIRSTOC.CANTUM1,
        CANTUM2     = V_RECNIRSTOC.CANTUM2,
        REST        = V_RECNIRSTOC.REST,
        UMSEC       = V_RECNIRSTOC.UMSEC,
        CODOBIECT   = V_RECNIRSTOC.CODOBIECT,
        CODIOART    = V_RECNIRSTOC.CODIOART,
        PRET        = V_RECNIRSTOC.PRET  / NVL(V_RECNIRSTOC.PARITATE, 1),
        ADAOS       = V_RECNIRSTOC.ADAOS / NVL(V_RECNIRSTOC.PARITATE, 1),
        TVA         = V_RECNIRSTOC.TVA,
        TIPSERIE    = V_RECNIRSTOC.TIPSERIE,
        CODLOCATIE  = V_RECNIRSTOC.CODLOCATIE,
        PUMaximal   = V_RECNIRSTOC.PUMaximal,
        AdMax       = V_RECNIRSTOC.AdMax,
        TG          = V_RECNIRSTOC.TG,
        FURN        = V_RECNIRSTOC.FURN,
        DATAACHIZ   = V_RECNIRSTOC.DATAACHIZ,
        TIPDOCACHIZ = V_RECNIRSTOC.TIPDOCACHIZ,
        D1          = V_RECNIRSTOC.D1,
        D2          = V_RECNIRSTOC.D2,
        D3          = V_RECNIRSTOC.D3,
        PUVAL       = V_RECNIRSTOC.PUVAL,
        CODGESTPROD = V_RECNIRSTOC.CODGESTPROD,
        SERIELOT    = V_RECNIRSTOC.SERIELOT,
        PROVIZION   = V_RECNIRSTOC.PROVIZION
      WHERE
        CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
    END IF;

    UPDATE NIRSTOC1 SET
    TIPDOC = (SELECT NIR.TIPNIR
              FROM TMP_NIR NIR
                    INNER JOIN TMP_NIRSTOC NS ON NS.CODNIR = NIR.CODNIR
              WHERE NS.CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC),
    PRETMAT = V_RECNIRSTOC.PRET  / NVL(V_RECNIRSTOC.PARITATE, 1) - V_RECNIRSTOC.ADAOS / NVL(V_RECNIRSTOC.PARITATE, 1)
    WHERE CODNIRSTOC = V_RECNIRSTOC.CODNIRSTOC;
    END LOOP;


    -- NIRSER
    FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSER) LOOP

      IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca actualizez si NSERII
      BEGIN
          SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC);
          EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
        END;

        IF NVL(aCODSERIE, 0) = 0 THEN
          SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
          INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC));
        END IF;
      ELSE
        aCODSERIE := V_RECNIRSER.CODSERIE;
        -- verific daca la editare nu a schimbat seria
        SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

  --      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
  --        UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
  --      END IF;
      END IF;

      IF V_RECNIRSER.CODNIRSER &lt; 0 THEN
        SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCODNIRSER FROM DUAL;
        UPDATE TMP_LIVR1  SET CODNIRSER = vCODNIRSER WHERE CODNIRSER = V_RECNIRSER.CODNIRSER;

        INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, OBS, TG, CodCertif, DataProd, Stare, CODPRODUCATOR)
        VALUES (vCODNIRSER, V_RECNIRSER.CODNIRSTOC, aCODSERIE, V_RECNIRSER.CANTNIR, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2, V_RECNIRSER.OBS, V_RECNIRSER.TG, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare,
                V_RECNIRSER.CODPRODUCATOR
                ) ;

      ELSE
        UPDATE NIRSER
        SET
          CODNIRSER  = V_RECNIRSER.CODNIRSER,
          CODNIRSTOC = V_RECNIRSER.CODNIRSTOC,
          CODSERIE   = aCODSERIE,
          CANTNIR    = V_RECNIRSER.CANTNIR,
          CANTUM1    = V_RECNIRSER.CANTUM1,
          CANTUM2    = V_RECNIRSER.CANTUM2,
          OBS        = V_RECNIRSER.OBS,
          TG         = V_RECNIRSER.TG,
          CodCertif  = V_RECNIRSER.CodCertif,
          DataProd   = V_RECNIRSER.DataProd,
          Stare      = V_RECNIRSER.Stare,
          CODPRODUCATOR = V_RECNIRSER.CODPRODUCATOR
        WHERE
          CODNIRSER  = V_RECNIRSER.CODNIRSER;
      END IF;
    END LOOP;

    -- DETAIL LIVR
    /* ATENTIE LA ORDINEA STERGERILOR DIN DETALII */

    DELETE LIVRVAL WHERE CODLIVR1 IN
    ( SELECT CODLIVR1 FROM LIVR1 WHERE
      CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = RECID) AND
      CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1)
    );
    if TIPIES = 24 then
      delete tmp_nplink;
      insert into tmp_nplink(codnirstoc, codies1)
      select distinct l.codnirstoc, l1.codies1
      from nplink l
           inner join livr1 l1 on l1.codlivr1 = l.codlivr1
      where l1.codlivr in (select CODLIVR FROM LIVR WHERE CODIES = RECID);
      
      delete nplink l
      where exists (select l1.codlivr1 from livr1 l1 where l1.codlivr1 = l.codlivr1 and l1.codlivr in (select CODLIVR FROM LIVR WHERE CODIES = RECID));
    end if;  
    
    for v_rec in (select codlivr1 from LIVR1 WHERE
                  CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODIES = RECID) AND
                  CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1)
                 ) loop
      DELETE LIVR1 WHERE CODLIVR1 = V_REC.CODLIVR1;
    end loop;             


--  DIN MOTIVE DE COERENTA LIVR1-NIRSTOC-NIRSER STERG DIN NIRSTOC DUPA STERGERILE DIN LIVR1
/*
    DELETE FROM NIRSER WHERE
    CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODIES = RECID)) AND
    CODNIRSER NOT IN ( SELECT CodNirSer FROM TMP_NIRSER);
*/

    DELETE FROM NIRSER NSE
    WHERE
      EXISTS
    (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI  WHERE CODNIRSTOC = NSE.CODNIRSTOC)
    AND NOT EXISTS (SELECT CodNirSer FROM TMP_NIRSER WHERE CODNIRSER = NSE.CODNIRSER);

/*
    DELETE FROM NIRSTOC NS
    WHERE
      EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NS.CODNIRSTOC)
    AND NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC);
*/
   FOR V_REC_NS IN (SELECT * FROM NIRSTOC NS WHERE
                    EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NS.CODNIRSTOC)
                    AND NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC)
    )
    LOOP
      DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC_NS.CODNIRSTOC;
      DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC_NS.CODINTR1;

      FOR V_REC_N IN (SELECT * FROM NIR WHERE CODNIR = V_REC_NS.CODNIRSTOC)
      LOOP
        DELETE FROM NIR WHERE CODNIR = V_REC_N.CODNIR;
        DELETE FROM INTRARI WHERE CODINTR = V_REC_N.CODINTR;
      END LOOP;

    END LOOP;


    DELETE FROM REZERVATS NS
    WHERE
      EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NS.CODNIRSTOC)
    AND NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC);

   DELETE FROM NIRSTOC1 NS1
    WHERE
      EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NS1.CODNIRSTOC)
    AND NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC WHERE CODNIRSTOC = NS1.CODNIRSTOC);


-- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
    FOR V_REC IN (SELECT * FROM LIVR  WHERE ( CODIES = RECID AND CODLIVR NOT IN ( SELECT  CODLIVR FROM TMP_LIVR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
    END LOOP;

    DELETE FROM LIVR WHERE ( CODIES = RECID AND CODLIVR NOT IN ( SELECT  CODLIVR FROM TMP_LIVR ));

    FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP

      IF NVL(V_REC.CODLIVR,0) &lt; 0  THEN
      BEGIN
        SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

        INSERT INTO LIVR ( CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
        VALUES ( VCOD, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR,
                 V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT, V_REC.BLOCAT,  V_REC.OPERAT );

        UPDATE TMP_LIVR1 SET CODLIVR = VCOD  WHERE CODLIVR = V_REC.CODLIVR;
      END;
      ELSE
        BEGIN
          -- VERIFIC DACA S-AU SCHIMBAT CARNETELE DE DOCUMENTE
          SELECT NVL(CARNETLIVR, 0), NVL(NRLIVR, 0) INTO OLDCARNETLIVR, OLDNRLIVR FROM LIVR
          WHERE
          NVL(CODLIVR,0) = NVL(V_REC.CODLIVR,0);

          IF (OLDCARNETLIVR &lt;&gt; 0)AND(OLDNRLIVR &lt;&gt; 0)AND(V_REC.CARNETLIVR &lt;&gt; OLDCARNETLIVR OR V_REC.NRLIVR &lt;&gt; OLDNRLIVR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETLIVR, OLDNRLIVR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETLIVR);
          END IF;

          UPDATE LIVR
          SET
            CARNETLIVR = V_REC.CARNETLIVR,
            NRLIVR     = V_REC.NRLIVR,
            DATALIVR   = V_REC.DATALIVR,
            OBS        = V_REC.OBS,
            TIPLIVR    = V_REC.TIPLIVR,
            ANULAT     = V_REC.ANULAT,
            BLOCAT     = V_REC.BLOCAT,
            OPERAT     = V_REC.OPERAT
          WHERE
            NVL(CODLIVR,0) = NVL(V_REC.CODLIVR,0);
        END;
      END IF;
    END LOOP;

-- DETAIL LIVR1

-- STERGEREA CELOR CE AU DISPARUT E REZOLVATA MAI SUS

    FOR V_REC IN (SELECT * FROM TMP_LIVR1  ORDER BY CODLIVR, CODIES1) LOOP
      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
        PRETINREG = PRETINREG / V_REC.PARITATE,
        PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;

      IF NVL(V_REC.CODLIVR1, 0) &gt; 0  THEN
        UPDATE LIVR1 SET
          CODLIVR       =  V_REC.CODLIVR,
          CODIES1       =  V_REC.CODIES1,
          CODNIRSTOC    =  V_REC.CODNIRSTOC,
          CANT          =  V_REC.CANT * V_REC.PARITATE,
          CANTREZERVAT  =  V_REC.CANTREZERVAT * V_REC.PARITATE,
          CANTUM1       =  V_REC.CANTUM1,
          CANTUM2       =  V_REC.CANTUM2,
          UMSEC         =  V_REC.UMSEC,
          CODPRODCOMP   =  V_REC.CODPRODCOMP,
          CONTINTERMED  =  V_REC.CONTINTERMED,
          CODGESTORIG   =  V_REC.CODGESTORIG,
          CODPROIECT    =  V_REC.CODPROIECT,
          CodCertif     =  v_Rec.codcertif,
          BLOCATUM1     =  V_REC.BLOCATUM1
        WHERE
          CODLIVR1 = V_REC.CODLIVR1;
        if TIPIES = 24 then  
          for v_np in (
            select codnirstoc
            from tmp_nplink
            where codies1 = v_rec.codies1
          ) loop
            insert into nplink(codnirstoc, codlivr1)
            values(v_np.codnirstoc, v_rec.codlivr1);
            exit;
          end loop;    
        end if;  
     ELSE
       SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_LIVR1   SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
       UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;


       INSERT INTO LIVR1
       (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTREZERVAT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC,  CANTUM1, CANTUM2, CODPRODCOMP, CONTINTERMED,CODGESTORIG, CODPROIECT, CODCERTIF,
        BLOCATUM1)
       VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CANTREZERVAT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC,V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CODPRODCOMP, V_REC.CONTINTERMED,V_REC.CODGESTORIG, V_REC.CODPROIECT, V_REC.CODCERTIF,
         V_REC.BLOCATUM1 );
       if TIPIES = 24 then
         select count(1) into fNR
         from iesiri1 i1
              left join iesprodlink l on l.codies1 = i1.codies1
         where i1.codies1 = v_rec.codies1 and i1.codcmdint1 &gt; 0 and l.codies1 is null;
         if fNR &gt; 0 then --suplimentare, caut sa identific predarea dinspre comanda interna
           for v_np in (
             select t.codnirstoc
             from iesiri1 i1
                  inner join iesiri1 ii1 on i1.codcmdint1 = ii1.codcmdint1 and ii1.codies1 &lt;&gt; i1.codies1
                  inner join tmp_nplink t on t.codies1 = ii1.codies1
             where i1.codies1 = v_rec.codies1
           ) loop
             insert into nplink(codnirstoc, codlivr1)
             values(v_np.codnirstoc, vcod);
             exit;
           end loop;
         else
           for v_np in (
             select codnirstoc
             from tmp_nplink
             where codies1 = v_rec.codies1
           ) loop
             insert into nplink(codnirstoc, codlivr1)
             values(v_np.codnirstoc, vcod);
             exit;
           end loop;
         end if;  
       end if;  
     END IF;
   END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_LIVRVAL) LOOP
      IF V_REC.CODLIVRVAL &lt; 0 THEN
        INSERT INTO LIVRVAL(CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
        VALUES (SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,  V_REC.CODLIVR1, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.GEST, V_REC.PRETINREG, V_REC.PRETACHIZ, V_REC.TVANEEX);
      ELSE
        UPDATE LIVRVAL
        SET
          CODLIVR1   = V_REC.CODLIVR1,
          CODOBIECT  = V_REC.CODOBIECT,
          CODIOART   = V_REC.CODIOART,
          GEST       = V_REC.GEST,
          PRETINREG  = V_REC.PRETINREG ,
          PRETACHIZ  = V_REC.PRETACHIZ ,
          TVANEEX    = V_REC.TVANEEX
        WHERE
          CODLIVRVAL = V_REC.CODLIVRVAL;
      END IF;
    END LOOP;

   UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);



   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
    NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);




DELETE FROM JURNAl1 WHERE TIPDOC = TIPIES AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOAREGRUP   = v_rec.VALOAREGRUP,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = V_REC.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODANALIZANOD);
 END IF;
END LOOP;


-- detail VOUCHERCADOULINK

DELETE FROM VOUCHERCADOULINK
WHERE
  CODDOC = RECID
  AND TIPDOC = TIPIES
  AND COD NOT IN (SELECT COD FROM TMP_VOUCHERCADOULINK);

FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
LOOP
  IF V_REC.COD &lt; 0 THEN
    INSERT INTO VOUCHERCADOULINK
    (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
    VALUES
    (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, TIPIES, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
  ELSE
    UPDATE VOUCHERCADOULINK
    SET
      BARCODE     = V_REC.BARCODE,
      VALOARE     = V_REC.VALOARE,
      DATASTART   = V_REC.DATASTART,
      DATASTOP    = V_REC.DATASTOP,
      ZILEVALABIL = V_REC.ZILEVALABIL,
      CODOBIECT   = V_REC.CODOBIECT,
      POSTAT      = V_REC.POSTAT
    WHERE
      COD = V_REC.COD;
  END IF;
END LOOP;


-- detail JURNAL

DELETE FROM JURNAL WHERE TIPDOC = TIPIES AND CODDOC = RECID AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOAREGRUP= v_rec.VALOAREGRUP,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA,
    CODCENTRU  = V_REC.CODCENTRU,
    DATADOC    = V_REC.DATADOC,
    DOCUMENT   = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, RECID, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,
   V_REC.CODANALIZANOD);
 END IF;
END LOOP;
  if TIPIes = 2 then
    Select NUMEDELEGAT into sNUMEDELEGAT from TMP_Iesiri;
		if sNUMEDELEGAT = &apos;MakeDIRTY_FactLaAviz&apos; then
			update Jurnal1 J1 set J1.Dirty = 1
			where J1.TipDoc = 26 and
			J1.CodDoc in (
			   Select distinct x.CodIes
				   from Ieslink k
					 inner join Iesiri1 i1 on k.CodLinieAviz = I1.CodIes1
					 inner join Iesiri  i  on I.CodIes = I1.CodIes
					 inner join Iesiri1 x1 on k.CodIes1 = x1.CodIes1
					 inner join Iesiri  x  on x.CodIes = x1.CodIes
					 where i.Operat = 1 and i.codIes = RecID);
				 for vrec in
				   ( Select distinct x1.CodIes1, I1.Mifix MFSursa
						 from Ieslink k
						 inner join Iesiri1 i1 on k.CodLinieAviz = I1.CodIes1
						 inner join Iesiri  i  on I.CodIes = I1.CodIes
						 inner join Iesiri1 x1 on k.CodIes1 = x1.CodIes1
						 where i.codIes = RecID and i.Operat = 1 and x1.Mifix &lt;&gt; i1.Mifix)
				 loop
				   Update Iesiri1 set Mifix = vrec.Mfsursa where CodIes1 = vrec.CodIes1;
					end loop;
			end if;
	end if;

ELSE  -- INSERT
-- MASTER IESIRI

  SELECT SEQ_IESIRI_CODIES.NEXTVAL INTO RECID FROM DUAL;

  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;IESIRI&apos;, RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN

       WINMADMIN.PKG_USERFIRME.PostLog(&apos;IESIRI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                       RECID,PKG_GLOBALS.FIRMANAME,
                                       aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO IESIRI (
    CODIES, TIPDOC,  ANULAT,   BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC, Is_ETransp,
    NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE,   DELEGAT, AGENT, MAJORARI,
    OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION,
    SUBUNITATEA, MONEDA, CURS, MIJLTRANSP, LISTAT,
    CUSTODIE, FARATRANSPORT, StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, userid,datacreare, MONEDATRANSF, NRI, CONTSUPLIM, DATAINREG, ExclusPlata, ExclusIntrastat, PROCTVADOC, FaraReg,TVAIncasare, DataTVA,
    CARNETCERTIF, NRCERTIF, SERIACERTIF,
    CODANALIZA, CODCONTRACT, FACTSIMPLIF, TRANSPORTATOR, iddescarcare, valdocefact,CodPArtTERT, CODAECUSTODIE, STADIUWMS, CODMONETAR, NUMARBONURI, EMISADECLIENT, NRINFOCM, NRINCASULT, NRINCASIM,
    TIPLIVRARE, NATURATRANZ, MODTRANSP, SPLITTVA, GRATIE, TipSAFT, RotEFact, CODTVASERV, PROCTVAOSS, TipET, NOACCIZE, NRNIR, DATANIR, PLATFORMA_ONLINE,
    REMORCA, PROIECT, CONTRACT, COMANDA, FLAGS
  )
  SELECT RECID,TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC, is_etransp,
    NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, MAJORARI,
    OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION, SUBUNITATEA, MONEDA, CURS,
    MIJLTRANSP,LISTAT,
    CUSTODIE, FARATRANSPORT, StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, pkg_globals.USERID,systimestamp, MONEDATRANSF, NRI, CONTSUPLIM, DATAINREG, ExclusPlata, ExclusIntrastat, PROCTVADOC, FaraReg,TVAIncasare, DataTVA,
    CARNETCERTIF, NRCERTIF, SERIACERTIF,
    CODANALIZA, CODCONTRACT, FACTSIMPLIF, TRANSPORTATOR, iddescarcare, valdocefact,CodPArtTERT, CODAECUSTODIE, STADIUWMS, CODMONETAR, NUMARBONURI, EMISADECLIENT, NRINFOCM, NRINCASULT , NRINCASIM,
    TIPLIVRARE, NATURATRANZ, MODTRANSP, SPLITTVA, GRATIE, TipSAFT, RotEFact, CODTVASERV, PROCTVAOSS, TipET, NOACCIZE, NRNIR, DATANIR, PLATFORMA_ONLINE,
    REMORCA, PROIECT, CONTRACT, COMANDA, FLAGS
  FROM TMP_IESIRI;

-- detail GENERAL
   FOR v_rec IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;
     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg)
     VALUES (VCOD, TIPIES, RecID, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS, V_REC.PROCTVAAVANS, v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA, v_rec.FaraReg);
   END LOOP;


 UPDATE TMP_IESPUNCTE
  SET
    CODIES = RECID;

  FOR V_REC IN (SELECT * FROM TMP_IESPUNCTE)
  LOOP
      INSERT INTO IESPUNCTE(CODIESPUNCTE, CODIES, PUNCTEDOC)
      VALUES(SEQ_IESPUNCTE_CODIESPUNCTE.NEXTVAL, V_REC.CODIES, V_REC.PUNCTEDOC);
  END LOOP;


FOR V_REC IN (SELECT * FROM TMP_VOUCHERCADOULINK)
LOOP
  INSERT INTO VOUCHERCADOULINK
    (COD, TIPDOC, CODDOC, TIPOPERATIE, BARCODE, VALOARE, DATASTART,DATASTOP, ZILEVALABIL,CODOBIECT,POSTAT)
    VALUES
    (SEQ_VOUCHERCADOULINK_COD.NEXTVAL, TIPIES, RECID, V_REC.TIPOPERATIE, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP, V_REC.ZILEVALABIL, V_REC.CODOBIECT, V_REC.POSTAT)  ;
END LOOP;



-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
     UPDATE TMP_IESIRI1 SET CODOBLIGSTORNO   = vCOD WHERE CODOBLIGSTORNO  = v_rec.CODOBLIGPIF;
     UPDATE TMP_IESIRI1 SET CODOBLIGMONETAR  = vCOD WHERE CODOBLIGMONETAR = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CODCENTRU,CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODANALIZANOD, DINCARETVA, RESTTVA, GRATIE)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 211 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA, V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, v_rec.CODCENTRU, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0),
    V_REC.CODANALIZANOD,
    NVL(V_REC.DINCARETVA, 0),
    NVL(V_REC.DINCARETVA, 0),
    V_REC.GRATIE
     );
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;

  -- musai colet, tratare caz
    if AutoColet = 1 then
      update tmp_iesiri1 set tiplivrare = 4;
    end if;


  FOR V_REC IN ( SELECT * FROM TMP_IESIRI1 ORDER BY INDEXLOCAL ) LOOP
-- DETAIL IESIRI1
     CODCMD1 := V_REC.CodCmdInt1;
     IF TIPIES = 24 and Nvl(CODCMD1,0) = 0 THEN
       CODCMD1 := GetLinieComInt(0,V_REC.OBS,V_REC.OBS);
     end if;
     SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO VCOD FROM DUAL;
     update tmp_jurnal1 set indexlocal = vcod where indexlocal = v_rec.codies1;
     INSERT INTO TMP_LINIICODIF(OLDCODE, NEWCODE) VALUES (V_REC.CODIES1, vCOD);

      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;IESIRI1&apos;, VCOD, V_REC.CODIES1);

/*      IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_IESIRI1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
      END IF;


      IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_BONCONS1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
      END IF;


      IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_MONETAR1EXT SET CODIES1 = &apos; || VCOD || &apos; WHERE CODIES1 = &apos; || V_REC.CODIES1;
      END IF;*/


     PRET_IMB_MF := 0; VAL_ACHIZ_MF := 0; CANT_IMB_MF := 0;
     IF NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND TIPIES = 14 THEN
       BEGIN
        SELECT SUM(L1.CANT) AS CANTDIMIN,
               SUM(L1.CANT * (NS.PRET - COALESCE(NS.ADAOS, 0))) AS VALDIMIN
        INTO
          CANT_IMB_MF,
          VAL_ACHIZ_MF
        FROM
          TMP_LIVR1 L1,
          NIRSTOC NS
        WHERE
          L1.CODIES1 = V_REC.CODIES1
          AND NS.CODNIRSTOC = L1.CODNIRSTOC
        GROUP BY L1.CODIES1;

         EXCEPTION WHEN OTHERS THEN NULL;

       END;

       IF NVL(CANT_IMB_MF, 0) &lt;&gt; 0 THEN
         PRET_IMB_MF := VAL_ACHIZ_MF / CANT_IMB_MF;
       END IF;
     END IF;


     INSERT INTO IESIRI1
         ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT, PRETORIG, PU,
           CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMaximal, AdMax, TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG,
           PARITATEORIG, CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,PRETPROMO, TIPPLATA,CODCENTRU, CODCADOU, CODOBLIGMONETAR,
           CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CUSTODIEINTRARE, ICONTPART, CANTCONSTATAT, DISCMANUAL, CODUTILAJ, CODAUTO, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT, CODAGENTEMULARE, CODPROMO1, CODCONTRACT1, VALDISCPRET, Preluat, CODMIFIX, RESTIMBMF,
           D1, D2, D3, CANTUM1, PRETUM1, IMPOZABIL, CODSERIE, CODPARTCOMISEMUL)
     VALUES
         ( VCOD, RECID, V_REC.INDEXLOCAL,  V_REC.TIPLINIE,  V_REC.UMSEC,  V_REC.CONTSERV,  V_REC.CONTDISCOUNT, V_REC.CODCRITERIU, V_REC.MIFIX, V_REC.ZILE, V_REC.ZILECMD,  V_REC.GESTACT,  V_REC.CODOBIECT,
           --V_REC.PRETORIG / NVL(V_REC.PARITATE,1),
          -- V_REC.PU / NVL(V_REC.PARITATE,1),
         PKG_IESIRI.PRETVANZARE(TIPIES,
                               NVL(V_REC.ROTUNJIRE, 0),
                               V_REC.PRETORIG,
                               NVL(V_REC.PARITATE,1),
                               1),
         PKG_IESIRI.PRETVANZARE(TIPIES,
                               NVL(V_REC.ROTUNJIRE, 0),
                               V_REC.PU,
                               NVL(V_REC.PARITATE,1),
                               1),


           V_REC.CANT * NVL(V_REC.PARITATE, 1),
           V_REC.TVA, V_REC.CONT, V_REC.PROCDISC, V_REC.ADDIM,
           CASE
             WHEN V_REC.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND TIPIES = 20 AND AOPERAT = 1 AND AANULAT = 0 THEN V_REC.CANT * V_REC.PARITATE
             WHEN V_REC.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_REC.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
             ELSE 0
           END,
           V_REC.PUMaximal, V_REC.AdMax,V_REC.TipLivrare, V_REC.GARANTIE, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS, V_REC.COEFDISCMAJ, V_REC.OBS, V_REC.CODOBIECTORIG,
           V_REC.PARITATEORIG, V_REC.CODLIVR1PRODVAL, V_REC.CODIES1STORNO, V_REC.CODOFERTA1,

           --V_REC.CADOU,
           CASE WHEN
             COALESCE(V_REC.CADOU, 0) &gt;=0  THEN V_REC.CADOU
             ELSE (SELECT NEWCODE FROM TMP_LINIICODIF WHERE OLDCODE = V_REC.CADOU)
           END,


           V_REC.TAXA, V_REC.TERMENCONTRACT, V_REC.CADOULINK, V_REC.CODIOARTCUST,  v_rec.UMCorelat, v_rec.CANTCorelat, v_rec.PUCorelat,V_REC.PRETPROMO, V_REC.TIPPLATA,V_REC.CODCENTRU, V_REC.CODCADOU,
           V_REC.CODOBLIGMONETAR,
           V_REC.CODLINIEDOCIMP,
           V_REC.TIPDOCIMP,
           CODCMD1,
           V_REC.CUSTODIEINTRARE,
           V_REC.ICONTPART,
           V_REC.CANTCONSTATAT,
           V_REC.DISCMANUAL,
           V_REC.CODUTILAJ,
           V_REC.CODAUTO,
           V_REC.CODANALIZANOD,
           V_REC.D1D3BCS, V_REC.CODOBLIGMAJORAT, V_REC.CODAGENTEMULARE, V_REC.CODPROMO1, V_REC.CODCONTRACT1, V_REC.VALDISCPRET, V_REC.Preluat, V_REC.CODMIFIX,
           CASE
             WHEN  NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 THEN PRET_IMB_MF * V_REC.CANT --V_REC.PU * V_REC.CANT
             ELSE 0
           END,
           V_REC.D1,
           V_REC.D2,
           V_REC.D3,
           V_REC.CANTUM1,
           V_REC.PRETUM1,
           V_REC.IMPOZABIL,
           V_REC.CODSERIE,
           V_REC.CODPARTCOMISEMUL
          );

     UPDATE TMP_IESIRI1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_LIVR1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_IESLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_IESPRODLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_IESVALLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_PACHETELINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_PACHETEOBJLINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;
     UPDATE TMP_FACTSALINK SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODIES1;

     PKG_CANTAR.UPDATE_RECORDS(TIPIES, v_rec.CodIes1, vCOD);
     PKG_BCAR.UPDATE_RECORDS(TIPIES, v_rec.CodIes1, vCOD);
     IF V_REC.CODCENTRALIZARE &gt; 0 THEN
       PKG_NOTECREDIT.UPDATE_RECORDS(TIPIES, VCOD, V_REC.CODCENTRALIZARE, aNumarDoc, aDataDoc, aValT, 0);
     END IF;
  END LOOP;

-- IESLINK
  INSERT INTO IESLINK(CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODIES1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_IESLINK);
  INSERT INTO IESPRODLINK(CODIES1, CODCMDPRODMAT, CANT, CODPROGRAMF1) (SELECT CODIES1, CODCMDPRODMAT, CANT, CODPROGRAMF1 FROM TMP_IESPRODLINK);
  INSERT INTO PACHETELINK(CODIES1, CODPACHETEOBJ, CANT) (SELECT CODIES1, CODPACHETEOBJ, CANT FROM TMP_PACHETELINK);
  INSERT INTO PACHETEOBJLINK(CODIES1, CODPACHETEOBJL, CANT) (SELECT CODIES1, CODPACHETEOBJL, CANT FROM TMP_PACHETEOBJLINK);
-- IESVALLINK
  INSERT INTO IESVALLINK(CODIES1, CODLIVR1, CANT, TIPLINK) (SELECT CODIES1, CODLIVR1, CANT, TIPLINK FROM TMP_IESVALLINK WHERE CODIES1 IS NOT NULL);

  INSERT INTO IESVALLINK(CODLIVR1, CANT, CODIES) (SELECT CODLIVR1, CANT, RECID FROM TMP_IESVALLINK WHERE CODIES1 IS NULL);
  INSERT INTO FACTSALINK(CODIES1, CODCOMANDA, CODCLASEA, VALOARE) SELECT CODIES1, CODCOMANDA, CODCLASEA, VALOARE FROM TMP_FACTSALINK;

-- INAINTE DE LIVRARI REZOLV IESIRILE IN ROSU PENTRU A AVEA APOI DE UNDE LIVRA
-- IESIRI IN ROSU : RECODIFICARI
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC) LOOP
    SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
    UPDATE TMP_NIRSTOC SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    UPDATE TMP_NIRSER  SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    UPDATE TMP_LIVR1   SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_INTRARI) LOOP
    SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
    UPDATE TMP_INTRARI  SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
    UPDATE TMP_NIR SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
    UPDATE TMP_INTRARI1 SET CODINTR = vCODINTR WHERE CODINTR = V_REC.CODINTR;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_INTRARI1) LOOP
    SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
    UPDATE TMP_INTRARI1 SET CODINTR1 = vCODINTR1 WHERE CODINTR1 = V_REC.CODINTR1;
    UPDATE TMP_NIRSTOC  SET CODINTR1  = vCODINTR1 WHERE CODINTR1 = V_REC.CODINTR1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NIR) LOOP
    SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
    UPDATE TMP_NIR SET CODNIR = vCODNIR WHERE CODNIR = V_REC.CODNIR;
    UPDATE TMP_NIRSTOC  SET CODNIR = vCODNIR WHERE CODNIR = V_REC.CODNIR;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCODNIRSER FROM DUAL;

    UPDATE TMP_LIVR1  SET CODNIRSER = vCODNIRSER WHERE CODNIRSER = V_REC.CODNIRSER;
    UPDATE TMP_NIRSER SET CODNIRSER = vCODNIRSER WHERE CODNIRSER = V_REC.CODNIRSER;

    IF V_REC.CODSERIE &lt;= 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, NVL((SELECT CODOBIECT FROM TMP_NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC), 0));

        UPDATE TMP_NIRSER SET CODSERIE = aCODSERIE WHERE CODNIRSER = VCODNIRSER;
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      --verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;
  END LOOP;

-- IESIRI IN ROSU : SCRIERE IN BAZA DE DATE
   INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, ExclusPlata, FaraReg,TVAIncasare)
   SELECT  CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, ExclusPlata, FaraReg,TVAIncasare FROM TMP_INTRARI;

   INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, CodOferta1, CODCENTRU, CODANALIZANOD)
   SELECT CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG /  NVL(PARITATE, 1), PU /  NVL(PARITATE, 1), 0, TG, CodOferta1, CODCENTRU, CODANALIZANOD
   FROM TMP_INTRARI1;

   INSERT INTO NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
   SELECT CODNIR, CODINTR, RECID, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT FROM TMP_NIR;


   INSERT INTO NIRSTOC
   (
     CODNIRSTOC,
     CODNIR,
     CODINTR1,
     CANTNIR,
     CANTUM1,
     CANTUM2,
     REST,
     UMSEC,
     CODOBIECT,
     CODIOART,
     PRET,
     ADAOS,
     TVA,
     TIPSERIE,
     CODLOCATIE,
     TG,
     PUMaximal, AdMax,
     FURN,
     DATAACHIZ,
     TIPDOCACHIZ,
     D1, D2, D3, PUVAL,
     CODGESTPROD,
     SERIELOT,
     PROVIZION,
     CANTFURN
   )
   (
   SELECT
     CODNIRSTOC,
     CODNIR,
     CODINTR1,
     CANTNIR,
     CANTUM1,
     CANTUM2,
     REST,
     UMSEC,
     CODOBIECT,
     CODIOART,
     PRET /  NVL(PARITATE, 1),
     ADAOS /  NVL(PARITATE, 1),
     TVA,
     TIPSERIE,
     CODLOCATIE,
     TG,
     PUMaximal, AdMax,
     FURN,
     DATAACHIZ,
     TIPDOCACHIZ,
     D1, D2, D3, PUVAL,
     CODGESTPROD,
     SERIELOT,
     PROVIZION,
     CANTFURN
   FROM
      TMP_NIRSTOC);

   INSERT INTO NIRSER
         (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, OBS, CodCertif, DataProd, TG, Stare, CODPRODUCATOR)
   SELECT CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, OBS, CodCertif, DataProd, TG, Stare, CODPRODUCATOR
   FROM
     TMP_NIRSER;

   INSERT INTO NIRSTOC1 (CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
   SELECT NS.CODNIRSTOC, NS.CODNIRSTOC, NIR.TIPNIR, NVL(NS.PRET,0) - NVL(NS.ADAOS,0), 0, 1, 0
   FROM TMP_NIRSTOC NS
        INNER JOIN TMP_NIR NIR ON NIR.CODNIR = NS.CODNIR
   WHERE NS.CODNIRSTOC = vCODNIRSTOC;

-- LIVR
  FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP
    SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

    INSERT INTO LIVR (CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    VALUES (VCOD, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR, V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

    UPDATE TMP_LIVR1 SET CODLIVR = VCOD WHERE CODLIVR = V_REC.CODLIVR;
  END LOOP;

-- LIVR1
   FOR V_REC IN (SELECT * FROM TMP_LIVR1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;


     SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_LIVR1   SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
     UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;


     INSERT INTO LIVR1 (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTREZERVAT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2, CODPRODCOMP, CONTINTERMED,CODGESTORIG, CODPROIECT,  CODCERTIF,
                        BLOCATUM1)
     VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CANTREZERVAT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA,V_REC.PMPVALUTADOC, V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CODPRODCOMP, V_REC.CONTINTERMED,V_REC.CODGESTORIG, V_REC.CODPROIECT,  V_Rec.CodCertif,
         V_REC.BLOCATUM1 );
   END LOOP;

   INSERT INTO MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
         (SELECT SEQ_MODURIPLATI_CODMODPLATA.NEXTVAL, RECID, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA FROM TMP_MODURIPLATI);

   INSERT INTO MODPLATA2(CODMODPLATA2, CODIES, CODCARD, VALOARE)
                        (SELECT SEQ_MODPLATA2_CODMODPLATA2.NEXTVAL, RECID, CODCARD, VALOARE FROM  TMP_MODPLATA2);


   DELETE TMP_DISCMONETAR WHERE NVL(DISCOUNT, 0) + NVL(TVADISCOUNT, 0) = 0;

   INSERT INTO DISCMONETAR(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT,TVADISCOUNT)
         (SELECT SEQ_DISCMONETAR_CODDISCMONETAR.NEXTVAL, RECID, PROCTVA, DISCOUNT,TVADISCOUNT FROM TMP_DISCMONETAR);



   INSERT INTO TVAMONETAR(CODTVAMONETAR, CODIES, CODTVA, VALOARE, TVA, BONURI)
   SELECT SEQ_TVAMONETAR_CODTVAMONETAR.NEXTVAL, RECID, CODTVA, VALOARE, TVA, BONURI FROM TMP_TVAMONETAR;

    INSERT INTO CMDAVANS(CODCMDAVANS, CODCOMANDA, CODIESAVANS)
    SELECT SEQ_CMDAVANS_CODCMDAVANS.NEXTVAL, CODCOMANDA, RECID FROM TMP_CMDAVANS;



  INSERT INTO IESDISC(CODIESDISC, CODIES, CODDISCOUNT, OFFINVOICE, Valoare, CodObiect, PROCENT)
         (SELECT SEQ_IESDISC_CODIESDISC.NEXTVAL, RECID, CODDISCOUNT, OFFINVOICE, Valoare, CodObiect, PROCENT from TMP_IesDisc);


   INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
   SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;


   UPDATE NIRSTOC NS SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);


   UPDATE NIRSER NS
   SET
      REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
      RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
      RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);

   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT,CODANALIZANOD )
   (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL1);



   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT,CODANALIZANOD)
  ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);

  if IESPRELATAS = 1 and TIPIES in (19,20) then
    insert into documente(coddocument, coddoc, tipdoc, filename, doc, obs, userid, datacreare, coddosar, coddepozit, tipdocument)
    select seq_documente_coddocument.nextval, RECID, TIPIES, filename, doc, obs, userid, datacreare, coddosar, coddepozit, tipdocument
    from documente
    where tipdoc = 500 and coddoc = (select partener from tmp_iesiri);
  end if;

END IF;

  RezolvUtilaje(RecId);

  if tipies = 24 then
    pkg_pretprod.SetDirtyStructura;
  end if;

IF TIPIES = 26 THEN
-- SUNT PE FACTURA LA AVIZ ; ACTUALIZEZ AVIZELE STINSE
    UPDATE IESIRI1 I1
    SET RESTFACT = I1.CANT -
                   (SELECT Coalesce(sum(IL.CANT), 0)
                    FROM IESLINK IL
                      LEFT JOIN IESIRI1 II1 on II1.CODIES1 = IL.CODIES1
                      LEFT JOIN IESIRI  II  on II.CODIES   = II1.CODIES
                    WHERE IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26 AND II.OPERAT = 1 AND II.ANULAT = 0
                   ) +
                   (SELECT Coalesce(sum(AE1.CANT), 0)    -- STINGERI PRIN STORNARI AVIZE
                    FROM IESIRI1 AE1 LEFT JOIN IESIRI AE ON AE.CODIES = AE1.CODIES
                    WHERE AE1.CODIES1STORNO = I1.CODIES1 AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
                   )
    WHERE I1.CODIES1 IN (SELECT CODLINIEAVIZ FROM TMP_IESLINK UNION
                         SELECT CODLINIEAVIZ FROM TMP_IESLINK_INITIAL);
ELSE -- ACTUALIZEZ RESTULACCEPTAT DE PE COMENZI CLIENTI
  IF TIPIES IN (14, 16, 19, 20, 21, 23) THEN
    UPDATE COMANDA1 C1
    SET C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                  (SELECT NVL(SUM(IL.CANT), 0)
                   FROM IESLINK IL
                    LEFT JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                   WHERE IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTOPERAT) = 1 AND II.ANULAT = 0
                  ) -
                  (SELECT NVL(SUM(IL.CANT), 0)
                   FROM CMDLIVRLINK IL
                    LEFT JOIN COMANDA1 II1 ON II1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT JOIN COMANDA  II ON II.CODCOMANDA    = II1.CODCOMANDA
                   WHERE IL.CODLINIECOMANDA = C1.CODCOMANDA1  AND II.OPERAT = 1 AND II.ANULAT = 0
                  )
    WHERE C1.CODCOMANDA1 IN (SELECT CODLINIECOMANDA FROM TMP_IESLINK UNION SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL);

    IF TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;FACTBLOCKCMD&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) = 1 and
       TIPIES IN (19, 20, 21, 23) THEN
      for v_rec in (
        select c.codcomanda, (SELECT SUM(case when coalesce(c1.RESTACCEPTAT,0) &lt; 0 then 0 else coalesce(c1.RESTACCEPTAT,0) end) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) rest
        from comanda c
             inner join comanda1 x1 on x1.codcomanda = c.codcomanda
        where x1.codcomanda1 in (SELECT CODLINIECOMANDA FROM TMP_IESLINK UNION SELECT CODLINIECOMANDA  FROM TMP_IESLINK_INITIAL)
      ) loop
        UPDATE COMANDA C SET BLOCAT = case when v_rec.rest = 0 then 1 else 0 end where codcomanda = v_rec.codcomanda;
      end loop;
    END IF;

    IF TIPIES in (14,19) THEN
      if AANULAT = 1 then
        delete from pacheteobjlink where codies1 in (select codies1 from iesiri1 where codies = recid);
      end if;
      UPDATE PACHETEOBJL P
      SET
       P.REST = P.CANT -
                   ( SELECT NVL(SUM(IL.CANT), 0)
                     FROM
                      PACHETEOBJLINK IL
                      LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                      LEFT OUTER JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                     WHERE
                     IL.CODPACHETEOBJL = P.CODPACHETEOBJL AND CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTOPERAT) = 1 AND II.ANULAT = 0
                     )
      WHERE
      P.CODPACHETEOBJL IN
      (SELECT CODPACHETEOBJL FROM TMP_PACHETEOBJLINK
       UNION
       SELECT CODPACHETEOBJL FROM TMP_PACHETEOBJLINK_I
      );
    END IF;
    IF TIPIES = 19 THEN
      FOR V_REC IN (SELECT T.CODCLASEA CLASA, T.CODCOMANDA, COALESCE(FACT.VALOARE,0) FACTURAT
                    FROM (SELECT CODCOMANDA, CODCLASEA FROM TMP_FACTSALINK UNION ALL SELECT CODCOMANDA, CODCLASEA FROM TMP_FACTSALINK_INITIAL) T
                         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = T.CODCOMANDA
                         INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                         INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL AND A.CLASA = T.CODCLASEA
                         LEFT  JOIN (SELECT SUM(VALOARE) VALOARE, CODCLASEA, CODCOMANDA
                                     FROM FACTSALINK
                                     GROUP BY CODCLASEA, CODCOMANDA
                                    ) FACT ON FACT.CODCLASEA = A.CLASA AND FACT.CODCOMANDA = T.CODCOMANDA
                   ) LOOP
        UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                              WHERE C1.CODOBIECT = O.CODOBIECT
                                                                    AND O.CODARTICOL = A.CODARTICOL
                                                                    AND A.CLASA = V_REC.CLASA
                                                                    AND A.TIPARTICOL = &apos;0&apos;
                                                             )
                                                      AND C1.CODCOMANDA = V_REC.CODCOMANDA AND C1.MODINCHIDERE = 2;
        UPDATE COMANDA1 C1 SET CANTRETURNAT = 0 WHERE EXISTS (SELECT O.CODOBIECT FROM NARTOBJ O, NART A
                                                              WHERE C1.CODOBIECT = O.CODOBIECT
                                                                    AND O.CODARTICOL = A.CODARTICOL
                                                                    AND A.CLASA = V_REC.CLASA
                                                                    AND A.TIPARTICOL = &apos;1&apos;
                                                             )
                                                      AND C1.CODCOMANDA = V_REC.CODCOMANDA AND COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT;
        IF V_REC.FACTURAT &gt;= 0 THEN
          AVALOARE := V_REC.FACTURAT;
          FOR V_TMP IN (SELECT C1.CODCOMANDA1, C1.CANTACCEPTAT*C1.PU VALOARE
                        FROM COMANDA1 C1
                             INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
                             INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
                        WHERE C1.CODCOMANDA = V_REC.CODCOMANDA AND A.CLASA = V_REC.CLASA
                              AND ((C1.MODINCHIDERE = 2 AND A.TIPARTICOL = &apos;0&apos;) OR (COALESCE(C1.MODINCHIDERE,0) = 0 AND C1.RESTACCEPTAT = C1.CANTACCEPTAT AND A.TIPARTICOL = &apos;1&apos;))
                       ) LOOP
            IF AVALOARE &lt; V_TMP.VALOARE THEN
              UPDATE COMANDA1 SET CANTRETURNAT = AVALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
              AVALOARE := 0;
            ELSE
              UPDATE COMANDA1 SET CANTRETURNAT = V_TMP.VALOARE WHERE CODCOMANDA1 = V_TMP.CODCOMANDA1;
              AVALOARE := AVALOARE - V_TMP.VALOARE;
            END IF;
            IF AVALOARE &lt;= 0 THEN EXIT; END IF;
          END LOOP;
        END IF;
      END LOOP;
    END IF;
  ELSE
    -- comanda interna
    IF TIPIES IN (24) THEN
      UPDATE COMANDA1 C1 -- comenzi clienti stinse prin bonconsum
      SET
        C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                      ( SELECT NVL(SUM(L.CANT), 0)
                      FROM
                        IESLINK L,
                        IESIRI1 I1,
                        IESIRI I
                      WHERE
                        I1.CODIES1 = L.CODIES1
                        AND I.CODIES = I1.CODIES
                        AND I.TIPDOC = 24
                        AND I.OPERAT = 1
                        AND I.ANULAT = 0
                        AND C1.CODCOMANDA1 = L.CODLINIECOMANDA
                      )
        WHERE
          C1.MODINCHIDERE = 3
          AND C1.CODCOMANDA1 IN (SELECT CODLINIECOMANDA FROM TMP_IESLINK UNION SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL);


    UPDATE CMDPRODMAT C1
    SET
     C1.REST = C1.CANT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    IESPRODLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                   WHERE
                   IL.CODCMDPRODMAT = C1.CODCMDPRODMAT AND II.ANULAT = 0
                   )
    WHERE
     --C1.CODCMDPRODMAT IN
     EXISTS
     (
     SELECT UU.CODCMDPRODMAT FROM
     (SELECT CODCMDPRODMAT FROM TMP_IESPRODLINK UNION SELECT CODCMDPRODMAT  FROM TMP_IESPRODLINK_INITIAL) UU
     WHERE
      UU.CODCMDPRODMAT =C1.CODCMDPRODMAT
     )
    ;
    /*
    for v_rec in (select c1.codcomanda1
                  from comanda1 c1
                       inner join comanda c on c.codcomanda = c1.codcomanda
                       inner join iesiri1 i1 on c1.codcomanda1 = i1.codcmdint1
                  where i1.codies = RECID and c.tipdoc = 92
                  ) loop
      update comanda1 c1
      set
      restacceptat = cantacceptat -
      (select nvl(sum(i1.cant),0)
       from iesiri1 i1
            inner join iesiri i on i.codies = i1.codies
       where i1.codcmdint1 = v_rec.codcomanda1 and i.tipdoc = 24
       )
       where codcomanda1 = v_rec.codcomanda1;
    end loop;*/
    UPDATE COMANDA1 C1 -- comenzi clienti stinse prin bonconsum
      SET
        C1.RESTACCEPTAT = C1.CANTACCEPTAT -
                      ( SELECT NVL(SUM(L.CANT), 0)
                      FROM
                        IESLINK L,
                        IESIRI1 I1,
                        IESIRI I
                      WHERE
                        I1.CODIES1 = L.CODIES1
                        AND I.CODIES = I1.CODIES
                        AND I.TIPDOC = 24
                        AND I.OPERAT = 1
                        AND I.ANULAT = 0
                        AND C1.CODCOMANDA1 = L.CODLINIECOMANDA
                      )
        WHERE
          C1.MODINCHIDERE = 2
          AND C1.CODCOMANDA1 IN (SELECT CODLINIECOMANDA FROM TMP_IESLINK UNION SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL)
          AND EXISTS (SELECT C.CODCOMANDA FROM COMANDA C WHERE C.CODCOMANDA = C1.CODCOMANDA AND C.OPERAT = 1 AND C.ANULAT = 0 AND C.TIPDOC = 92);
    end if;
  END IF;
END IF;


IF TIPIES = 20 THEN -- RECALCULEZ RESTURI AVIZE STORNATE de documentul curent
  UPDATE IESIRI1 I1
  SET
   I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  IESLINK IL
                  LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI  II ON II.CODIES    = II1.CODIES
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODIES1 AND II.TIPDOC = 26  AND II.OPERAT = 1 AND II.ANULAT = 0
                 )+
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  IESIRI1 AE1,
                  IESIRI  AE
                WHERE
                  AE1.CODIES1STORNO =I1.CODIES1 AND AE.CODIES = AE1.CODIES
                 AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
               WHERE
                 EXISTS (SELECT CODIES1STORNO FROM (SELECT CODIES1STORNO FROM TMP_IESIRI1 UNION SELECT CODIES1STORNO FROM IESIRI1_MAN) WHERE CODIES1STORNO = I1.CODIES1);
END IF;

  UPDATE PACHETEOBJ POBJ
  SET
   REST = CANT -
          (SELECT NVL(SUM(PL.CANT), 0)
           FROM
            PACHETELINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          ) -
          (SELECT NVL(SUM(PL.CANT), 0)
           FROM
            PACHETEDLLINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          )
  WHERE
   EXISTS
   (
   SELECT UU.CODPACHETEOBJ FROM
   (SELECT CODPACHETEOBJ FROM TMP_PACHETELINK UNION SELECT CODPACHETEOBJ FROM TMP_PACHETELINK_INITIAL) UU
   WHERE
    UU.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
   );


IF TIPIES = 14 THEN

-- DIMINUARI IESIRI VALORICE
    UPDATE LIVR1 L1
    SET
     L1.RESTIESVAL = L1.CANT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    IESVALLINK IL
                    LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI  II ON II.CODIES   = II1.CODIES
                   WHERE
                    IL.CODIES1 IS NOT NULL
                    AND IL.CODLIVR1 = L1.CODLIVR1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
    L1.CODLIVR1 IN
    (SELECT CODLIVR1 FROM TMP_IESVALLINK WHERE CODIES1 IS NOT NULL  UNION SELECT CODLIVR1  FROM TMP_IESVALLINK_INITIAL WHERE CODIES1 IS NOT NULL);

END IF;


IF TIPIES IN (14, 24) THEN

--  ARTICOLE COMPUSE VALORICE FARA DESCARCARE
    UPDATE LIVR1 L1
    SET
     L1.RESTIESVAL = L1.CANT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    IESVALLINK IL,
                    IESIRI II
                   WHERE
                    IL.CODIES1 IS NULL
                    AND II.CODIES   = IL.CODIES
                    AND IL.CODLIVR1 = L1.CODLIVR1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
     L1.CODLIVR1 IN
    (SELECT CODLIVR1 FROM TMP_IESVALLINK WHERE CODIES1 IS NULL  UNION SELECT CODLIVR1  FROM TMP_IESVALLINK_INITIAL WHERE CODIES1 IS NULL);

END IF;



-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;


 END LOOP;

/*
-- ACTUALIZARE CARNETE DOCUMENTE
IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNET &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
THEN
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
END IF;
*/
-- ACTUALIZARE CARNETE DOCUMENTE
IF  CARNETDOC_I &lt;&gt; 0 AND
    NRDOC_I     &lt;&gt; 0 AND
   (ACARNET     &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
THEN
  SELECT COUNT(*) INTO NR FROM DOCCARNETE WHERE CODCARNET = CARNETDOC_I;-- din preluari pot veni coduri aiurea
  IF NR &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
END IF;


-- CERTIFICAT
PKG_CARNETEDOC.SOLVENUMARDOC(ACARNET, ANUMARDOC);

IF (CARNETDOC_C &lt;&gt; 0)AND(NRDOC_C &lt;&gt; 0)AND(ACARNETCERTIF &lt;&gt; CARNETDOC_C OR ANUMARCERTIF &lt;&gt; NRDOC_C)
THEN
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_C, NRDOC_C);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_C);
END IF;

if coalesce(ACARNETCERTIF,0) &gt; 0 then
  PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETCERTIF, ANUMARCERTIF);
end if;

FOR V_REC IN (SELECT * FROM LIVR WHERE  CODIES = RECID)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;



-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
UPDATE OBLIGPIF O
SET
  REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
WHERE
 O.SEMNIFICATIE IN (200, 210)
 AND O.CODOBLIGPIF IN
 ( SELECT CODSTINSPIF FROM TMP_STINGERE

   UNION ALL

   SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
 );


-- actualizez restul obligatiilor stinse de tranzactiile STORNO GARANTII de pe documentul salvat
UPDATE OBLIGPIF O
SET
  REST = VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
WHERE
 O.SEMNIFICATIE = 220
 AND O.CODOBLIGPIF IN
 ( SELECT CODSTINSPIF FROM TMP_STINGERE

   UNION ALL

   SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
 );



-- VALORICE FARA DESCARCARE GENERATE DE DOCUMENTUL CURENT
 FOR V_REC IN
   (SELECT L1.CODLIVR1
    FROM
      LIVRVAL LV,
      LIVR1 L1,
      LIVR L,
      TMP_IOART_LUNA IOALUNA
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1 AND L.CODLIVR = L1.CODLIVR AND
      L.CODIES = RECID AND  LV.CODIOART = IOALUNA.CODIOART AND NVL(IOALUNA.DESCARCAREG, 0) = 0
    )
 LOOP
   UPDATE LIVR1 L1
     SET
      L1.RESTIESVAL = L1.CANT -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IESVALLINK IL
                  LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                WHERE
                  IL.CODLIVR1 = L1.CODLIVR1 AND
                  IL.CODIES1 = I1.CODIES1   AND
                  I.CODIES = I1.CODIES      AND
                  I.OPERAT = 1 AND I.ANULAT = 0
                )
   WHERE
   CODLIVR1 = V_REC.CODLIVR1;
 END LOOP;


-- ARTICOLE COMPUSE VALORICE FARA DESCARCARE GENERATE DE DOCUMENTUL CURENT
 FOR V_REC IN
   (SELECT L1.CODLIVR1
    FROM
      LIVRVAL LV,
      LIVR1 L1,
      LIVR L,
      TMP_IOART_LUNA IOALUNA
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1
      AND (NVL(L1.CODPRODCOMP, 0) &lt;&gt; 0 OR NVL(L1.CODPROIECT, 0) &lt;&gt; 0)
      AND L.CODLIVR = L1.CODLIVR
      AND  L.CODIES = RECID AND  LV.CODIOART = IOALUNA.CODIOART AND NVL(IOALUNA.DESCARCAREG, 0) = 0
    )
 LOOP
   UPDATE LIVR1 L1
   SET
     L1.RESTIESVAL = L1.CANT -
              (SELECT NVL(SUM(IL.CANT), 0)
               FROM
                 IESVALLINK IL,
                 IESIRI  I
               WHERE
                 IL.CODIES1 IS NULL
                 AND  IL.CODLIVR1 = L1.CODLIVR1
                 AND  I.CODIES    = IL.CODIES
                 AND  I.OPERAT    = 1
                 AND  I.ANULAT    = 0
               )
   WHERE
     CODLIVR1 = V_REC.CODLIVR1;
 END LOOP;


 IF aCODMONEDA &lt;&gt; 0 THEN
   FOR V_REC IN
   (
     SELECT
       G.CODGENERAL,
       OL.VALOARE AS VAL_IN,
       O.VALOARE  AS VAL_OUT
     FROM
        TMP_OBLIGPIF_INITIAL OL
        LEFT OUTER JOIN TMP_OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF,
        GENERAL       G
     WHERE
       G.CODGENERAL = OL.CODGENERAL
    )
    LOOP
      IF (V_REC.VAL_IN &lt;&gt; V_REC.VAL_OUT)OR(CURS_IN &lt;&gt; aCURS) THEN
        FOR V_RECREG IN
        (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
        LOOP
          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
        END LOOP;
      END IF;
    END LOOP;
 END IF;

-- ACTUALIZARE REZERVARESTOC
/*
FOR V_REC IN
(SELECT * FROM REZERVATS RS
 WHERE
   EXISTS (SELECT CODLINIECOMANDA FROM TMP_IESLINK WHERE CODLINIECOMANDA = RS.CODCOMANDA1)OR
   EXISTS (SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL WHERE CODLINIECOMANDA = RS.CODCOMANDA1)
 )
 LOOP
   UPDATE REZERVATS RS
   SET
     REST = CANTREZERVAT - NVL(PKG_COMANDA.LIVRAT_DIN_REZERVAT(RS.CODCOMANDA1, RS.CODNIRSTOC, RS.CODNIRSER), 0)
   WHERE
     CODREZERVATS = V_REC.CODREZERVATS;
 END LOOP;
*/

-- ACTUALIZARE REZERVARESTOC : ADUN CANTINITIAL
FOR V_REC IN
(SELECT
   IL.CODLINIECOMANDA,
   NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
   NVL(L1.CODNIRSER,0)  AS CODNIRSER,
   CASE WHEN COALESCE(LV.CODLIVRVAL,0) = 0 THEN L1.CANTREZERVAT ELSE L1.CANT END CANTREZERVAT,
   L1.PARITATE
 FROM
   TMP_LIVR1_INITIAL L1
   LEFT JOIN TMP_LIVRVAL_INITIAL LV ON LV.CODLIVR1 = L1.CODLIVR1,
   TMP_IESLINK_INITIAL IL,
   COMANDA1 C1,
   COMANDA C
 WHERE
   L1.CODIES1 = IL.CODIES1
   AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
   AND C1.CODCOMANDA = C.CODCOMANDA
   AND COALESCE(C.INCHISA,0) = 0
 )
LOOP
   UPDATE REZERVATS
   SET
--     CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT * V_REC.PARITATE,
     REST         = REST         + COALESCE(V_REC.CANTREZERVAT,0) * V_REC.PARITATE
   WHERE
    CODCOMANDA1           = V_REC.CODLINIECOMANDA
    AND CODNIRSTOC        = V_REC.CODNIRSTOC
    AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
END LOOP;

-- ACTUALIZARE REZERVARESTOC : SCAD CE GASESC REZERVAT PE DOCUMENT
FOR V_REC IN
(SELECT
   IL.CODLINIECOMANDA,
   NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
   NVL(L1.CODNIRSER,0)  AS CODNIRSER,
   CASE WHEN COALESCE(LV.CODLIVRVAL,0) = 0 THEN L1.CANTREZERVAT ELSE L1.CANT END CANTREZERVAT,
   L1.PARITATE
 FROM
   TMP_LIVR1 L1
   LEFT JOIN TMP_LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1,
   TMP_IESLINK IL
 WHERE
  L1.CODIES1 = IL.CODIES1
 )
LOOP
   UPDATE REZERVATS
   SET
--     CANTREZERVAT = CANTREZERVAT - V_REC.CANTREZERVAT * V_REC.PARITATE,
     REST         = REST         - COALESCE(V_REC.CANTREZERVAT,0) * V_REC.PARITATE
   WHERE
    CODCOMANDA1           = V_REC.CODLINIECOMANDA
    AND CODNIRSTOC        = V_REC.CODNIRSTOC
    AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
END LOOP;

-- CAZ DEPACO : COMANDA CLIENT ARE REZERVARI INSA FACTUREZ DE PE DISPLIVRAERE CARE NU ARE
-- STING REZERVARI DE PE CODCOMAND1ORIG

-- START DEPACO

  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;REZERVCMDORIG&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO REZERVCMDORIG FROM DUAL;
    EXCEPTION WHEN OTHERS THEN REZERVCMDORIG := 0;
  END;

  IF REZERVCMDORIG = 1 THEN


    FOR V_REC IN
    (SELECT
       IL.CODCOMAND1ORIG,
       NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
       NVL(L1.CODNIRSER,0)  AS CODNIRSER,
       L1.CANTREZERVAT,
       L1.PARITATE
     FROM
       TMP_LIVR1_INITIAL L1,
       TMP_IESLINK_INITIAL IL,
       COMANDA1 C1,
       COMANDA C
     WHERE
      L1.CODIES1 = IL.CODIES1
      AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
      AND C1.CODCOMANDA = C.CODCOMANDA
      AND COALESCE(C.INCHISA,0) = 0
     )
    LOOP
       UPDATE REZERVATS
       SET
--         CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT * V_REC.PARITATE,
         REST         = REST         + V_REC.CANTREZERVAT * V_REC.PARITATE
       WHERE
        CODCOMANDA1           = V_REC.CODCOMAND1ORIG
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
    END LOOP;


    -- ACTUALIZARE REZERVARESTOC : SCAD CE GASESC REZERVAT PE DOCUMENT
    FOR V_REC IN
    (SELECT
       IL.CODCOMAND1ORIG,
       NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
       NVL(L1.CODNIRSER,0)  AS CODNIRSER,
       L1.CANTREZERVAT,
       L1.PARITATE
     FROM
       TMP_LIVR1 L1,
       TMP_IESLINK IL
     WHERE
      L1.CODIES1 = IL.CODIES1
     )
    LOOP
       UPDATE REZERVATS
       SET
--         CANTREZERVAT = CANTREZERVAT - V_REC.CANTREZERVAT * V_REC.PARITATE,
         REST         = REST         - V_REC.CANTREZERVAT * V_REC.PARITATE
       WHERE
        CODCOMANDA1           = V_REC.CODCOMAND1ORIG
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
    END LOOP;

  END IF;
-- END DEPACO

-- RAD REZERVARI INUTILE
FOR V_REC IN
(
SELECT R.CODREZERVATS
from
  REZERVATS R,
  COMANDA1 C1
WHERE
  C1.CODCOMANDA1 = R.CODCOMANDA1
  AND C1.RESTACCEPTAT = 0
  AND R.REST &lt;&gt; 0
  AND EXISTS
  (SELECT CODLINIECOMANDA FROM (SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL UNION SELECT CODLINIECOMANDA FROM TMP_IESLINK) WHERE CODLINIECOMANDA = R.CODCOMANDA1)
)
LOOP
  UPDATE REZERVATS
  SET
    --CANTREZERVAT = 0,
    REST = 0
 WHERE
   CODREZERVATS = V_REC.CODREZERVATS;
END LOOP;


-- ACTUALIZARE REZERVARESTOC MATERIA:E
FOR V_REC IN
(SELECT
   GetLinieComCli(IL.CODLINIECOMANDA) CODLINIECOMANDA,
   NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
   NVL(L1.CODNIRSER,0)  AS CODNIRSER,
   L1.CANTREZERVAT,
   L1.PARITATE,
   IL.CODCMDPRODMAT
 FROM
   TMP_LIVR1_INITIAL L1,
   TMP_IESPRODLINK_INITIAL IL
 WHERE
  L1.CODIES1 = IL.CODIES1
 )
 LOOP
   UPDATE REZERVATS
   SET
--     CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT * V_REC.PARITATE,
     REST         = REST         + V_REC.CANTREZERVAT * V_REC.PARITATE
   WHERE
    CODCOMANDA1           = V_REC.CODLINIECOMANDA
    AND CODNIRSTOC        = V_REC.CODNIRSTOC
    AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
    AND NVL(CODCMDPRODMAT,0) = V_REC.CODCMDPRODMAT;
 END LOOP;

  -- ACTUALIZARE REZERVARESTOC MATERIALE
  FOR V_REC IN (
    SELECT GetLinieComCli(IL.CODLINIECOMANDA) CODLINIECOMANDA, NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC, NVL(L1.CODNIRSER,0)  AS CODNIRSER, L1.CANTREZERVAT, L1.PARITATE,
           IL.CODCMDPRODMAT
    FROM TMP_LIVR1 L1, TMP_IESPRODLINK IL
    WHERE L1.CODIES1 = IL.CODIES1
  ) LOOP
    UPDATE REZERVATS
    SET REST = REST - V_REC.CANTREZERVAT * V_REC.PARITATE
    WHERE CODCOMANDA1 = V_REC.CODLINIECOMANDA AND CODNIRSTOC = V_REC.CODNIRSTOC
          AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER AND NVL(CODCMDPRODMAT,0)= V_REC.CODCMDPRODMAT;
  END LOOP;

  PKG_CANTAR.ELIBEREAZA_ON_SP_POSTRECORDS;
  --PKG_BCAR.ELIBEREAZA_ALL_USER_RECORDS;
  --UPDATE BCAR
  --SET CodDoc1 = NULL,
  --    UserIdBlocaj = NULL,
  --    TipDoc = NULL
  --WHERE UserIdBlocaj = PKG_GLOBALS.UserId;

  --  mFacturaLaAvizClient  = 26
  IF TIPIES = 26 THEN
    StornoAvize := &apos;2&apos;;
    SELECT pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO StornoAvize from dual;
    -- actualizez modif pu fact la aviz
    FOR V_REC IN ( SELECT CodLinieAviz FROM Tmp_Ieslink WHERE ActualizPret = 1 )
    LOOP
      PKG_Jurnal.setDirtyIesAE(V_REC.CODLINIEAVIZ, aCurs);
      IF StornoAvize = &apos;1&apos; THEN
        FOR V_REC_STORNO IN (SELECT I1.CODIES1, I1A.PU AS PRETNOU FROM IESIRI1 I1, IESIRI I, IESIRI1 I1A
                             WHERE
                               I.TIPDOC = 20
                               AND I1.CODIES = I.CODIES
                               AND I1.CODIES1STORNO = V_REC.CODLINIEAVIZ
                               AND I1.CANT &lt; 0
                               AND I1A.CODIES1 = V_REC.CODLINIEAVIZ
                            )
        LOOP
          PKG_Jurnal.setDirtyIesAE_Storno(V_REC_Storno.CODIES1, V_REC_Storno.PRETNOU, aCurs);
        END LOOP;
      END IF;
      --update jurnal1 set dirty = 1 where TipDoc = TipIes and CodDoc = RecID;
    END LOOP;
  ELSE
    --actualizez modif pret nirstoc
    FOR V_REC IN ( SELECT CodNirStoc, Pret FROM Tmp_NIRSTOC WHERE ActualizPret = 1 )
    LOOP
      PKG_Jurnal.setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.Pret, &apos;0&apos;, 0);
    END LOOP;
  END IF;

  IF TIPIES = 15 AND NVL(aTIPTVA, 0) = 1 THEN
    CHECK_REZERVARI_CLONARE_IN;
    CHECK_REZERVARI_CLONARE_OUT;
  END IF;

  IF TIPIES = 26 THEN
    FOR V_REC IN (SELECT * FROM GENERAL G WHERE TIPDOC = 26 AND SEMNIFICATIE = 240 AND CODDOC = RECID AND (SELECT COUNT(*) FROM OBLIGPIF O WHERE CODGENERAL = G.CODGENERAL) = 0)
    LOOP
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, V_REC.CODGENERAL,  0, 0, aCODPART, 7, 240);
    END LOOP;

  END IF;

  IF (TIPIES = 14 or TIPIES = 15) THEN
    aCodInventar := PKG_Inventar.GetCodInventar(RecId, 0);
    IF aCodInventar &gt; 0 THEN
      aCodInventar := PKG_Inventar.UpdateInventarFromDoc(aCodInventar, RecId);
    END IF;
  END IF;

  --pregatesc dezasamblarile
  IF (TIPIES = 24 ) THEN
    DELETE FROM DEZASAMBLARI WHERE CodLIVR1 IN (select CodLIVR1 from TMP_LIVR1);
    BEGIN
      Select DEZAGREGARE into NR from TMP_IESIRI;
    EXCEPTION
      WHEN OTHERS THEN Nr := 0;
    END;
    IF NR = 1 THEN
      INSERT into DEZASAMBLARI (CodLivr1, CodNIRSTOC, Valoare, Inchisa)
      SELECT CodLivr1, CodNIRSTOC, CANT * PretAchiz, 0
      FROM TMP_LIVR1;
    END IF;
  END IF;

  PKG_GLOBALS.MarkDirtyJurnal;

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;IESIRIEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRIEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM IESIRIEXT WHERE CODIES =  &apos; || RECID;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_IESIRIEXT SET CODIESIRIEXT = SEQ_IESIRIEXT_CODIESIRIEXT.NEXTVAL  WHERE CODIESIRIEXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_IESIRIEXT SET CODIES = &apos; || RECID;
    EXECUTE IMMEDIATE &apos;INSERT INTO IESIRIEXT SELECT * FROM TMP_IESIRIEXT &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;MONETAREXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAREXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM MONETAREXT WHERE CODIES =  &apos; || RECID;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_MONETAREXT SET CODMONETAREXT = SEQ_MONETAREXT_CODMONETAREXT.NEXTVAL  WHERE CODMONETAREXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_MONETAREXT SET CODIES = &apos; || RECID;
    EXECUTE IMMEDIATE &apos;INSERT INTO MONETAREXT SELECT * FROM TMP_MONETAREXT &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;BONCONSEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONSEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM BONCONSEXT WHERE CODIES =  &apos; || RECID;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_BONCONSEXT SET CODBONCONSEXT = SEQ_BONCONSEXT_CODBONCONSEXT.NEXTVAL  WHERE CODBONCONSEXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_BONCONSEXT SET CODIES = &apos; || RECID;
    EXECUTE IMMEDIATE &apos;INSERT INTO BONCONSEXT SELECT * FROM TMP_BONCONSEXT &apos;;
  END IF;



  IF PKG_LIST_STRUCT.TmpExists(&apos;IESIRI1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_IESIRI1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM IESIRI1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1_MAN)  &apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_IESIRI1EXT SET CODIESIRI1EXT = SEQ_IESIRI1EXT_CODIESIRI1EXT.NEXTVAL  WHERE CODIESIRI1EXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO IESIRI1EXT SELECT * FROM TMP_IESIRI1EXT &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;MONETAR1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_MONETAR1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM MONETAR1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1_MAN)  &apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_MONETAR1EXT SET CODMONETAR1EXT = SEQ_MONETAR1EXT_CODMONETAR1EXT.NEXTVAL  WHERE CODMONETAR1EXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO MONETAR1EXT SELECT * FROM TMP_MONETAR1EXT &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;BONCONS1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_BONCONS1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM BONCONS1EXT WHERE CODIES1 IN (SELECT CODIES1 FROM IESIRI1_MAN)  &apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_BONCONS1EXT SET CODBONCONS1EXT = SEQ_BONCONS1EXT_CODBONCONS1EXT.NEXTVAL  WHERE CODBONCONS1EXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO BONCONS1EXT SELECT * FROM TMP_BONCONS1EXT &apos;;
  END IF;*/


  --Actulaizare desfasurator in contracte asociate
  UPDATE contract2
  SET TipDoc = TipIes, CodDoc = RecID
  WHERE CodContract2 IN (SELECT CODCONTRACT2 FROM TMP_IES_CONTR2);

  IF aAnulat = 1 THEN
    UPDATE contract2
    SET tipdoc = null, coddoc = null
    WHERE tipdoc = tipies and coddoc = recid;
  END IF;

  DELETE TMP_IES_CONTR2;

  PKG_CFGTABLES.EXT_POSTRECORDS(TIPIES, OPERATION);

  NotifyModif(Operation, RecId, &apos;IESIRI&apos;);

  IF TIPIES = 16 THEN
    FOR V_REC IN (SELECT * FROM TMP_MONETARLINK_INI WHERE CODFACTURA NOT IN (SELECT CODFACTURA FROM TMP_MONETARLINK))
    LOOP
      UPDATE IESIRI
      SET
        CODMONETAR = NULL
      WHERE
        CODIES = V_REC.CODFACTURA;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_MONETARLINK)
    LOOP
      UPDATE IESIRI
      SET
        CODMONETAR = RECID
      WHERE
        CODIES = V_REC.CODFACTURA;
    END LOOP;
  END IF;

  for V_Rec in (Select CodReclamatie,DATADOC from Tmp_Iesiri) loop
    PKG_RECLAMATII.RezolvaReclamatie(v_rec.CodReclamatie, RecID, TipIes,v_rec.DataDoc);
  end loop;

  if aCountBCAR &gt; 0 then
    for v_rec in (select b.codbcar, i.delegat, i.partener codpartener
                  from iesiri1 i1
                       inner join iesiri i on i.codies = i1.codies
                       inner join bcar b on b.coddoc1 = i1.codies1 and b.tipdoc = tipies
                  where i.codies = recid
                  ) loop
      update bcar set coddelegat = aDelegat, codpartener = aPartGest where codbcar = v_rec.codbcar;
    end loop;
  end if;

  COMMIT;

  UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);
   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
    NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);


  CHECK_STERGERI_NIR(RECID);
  CHECK_REZERVARICMD(RECID);


  IF aANULAT = 1 or aOPERAT = 0 THEN
    DELETE FROM STATUSDECL WHERE TipDoc = TIPIES and CODDOC = RECID;
    DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIes);
    DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIes;
    FOR V_REC IN (SELECT C.CODCHELTAVANS, C.CODIES1
    FROM
      IESIRI1 I1,
      CHELTAVANS C
    WHERE
      I1.CODIES = RECID
      AND C.CODIES1 = I1.CODIES1
    )
   LOOP
      DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
      DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
      DELETE FROM MASTERCHELTAVANS WHERE CODIES1 = V_REC.CODIES1;
      DELETE FROM JURNAL  WHERE TIPDOC = 106 AND CODDOC = V_REC.CODCHELTAVANS;
      DELETE FROM JURNAL1 WHERE TIPDOC = 106 AND CODDOC = V_REC.CODCHELTAVANS;

   END LOOP;
  END IF;

  if TipIes in (14,19,20,21,26) then
    PKG_SAFT.UpdateTaxDecl(1, RecId);
  ELSIF TipIes = 16 then
    PKG_SAFT.UpdateTaxDecl(2, RecId);
  end if;

  if TipIes in (19,20) and PKG_CATEGCONST.GetValConstanta(&apos;ContrComInactiv&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    for v_rec in (
      select distinct c1.codcontract, c.datadoc, Decode(TipDoc,10,&apos;CcF&apos;,27,&apos;CcC&apos;)||c.NrDoc||&apos;/&apos;||c.DataDoc Doc
      from tmp_iesiri1 i1
           inner join contract1 c1 on i1.codcontract1 = c1.codcontract1
           inner join contract c on c.codcontract = c1.codcontract
      where c.activ &gt; 0 and c1.cant &gt; 0
    ) loop
      select sum(case
                   when c1.cant - coalesce((select sum(i1.cant)
                                   from iesiri1 i1, iesiri i
                                   where i1.codcontract1 = c1.codcontract1 and i1.codies = i.codies and i.tipdoc in (19,20)
                                   ),0
                                   ) &lt; 0 then 0
                   else c1.cant - coalesce((select sum(i1.cant)
                                   from iesiri1 i1, iesiri i
                                   where i1.codcontract1 = c1.codcontract1 and i1.codies = i.codies and i.tipdoc in (19,20)
                                   ),0)
                end
                ) into aRest
      from contract1 c1
      where c1.codcontract = v_rec.codcontract and c1.cant &gt; 0;
      if aRest &lt;= 0 then
        update contract set activ = 0 where codcontract = v_rec.codcontract;
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;CONTRACT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codcontract,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, v_rec.Doc,
                                        &apos;Inactivare contract, acoperire realizata prin &apos;||aDoc, PKG_GLOBALS.GET_EXE_VERSION);
      end if;
    end loop;
  end if;

  PKG_IESIRI.SetValFin(RecId, 1);

  IF TIPIES = 15 THEN
    CHECK_MODIF_CARACT_MIFIX (RECID);
  END IF;

  DELETE FROM GENERAL G
  WHERE
    TIPDOC = TIPIES
    AND CODDOC = RECID
    AND (SELECT COUNT(*) FROM OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL) = 0;


  if DoCommit then
    COMMIT;
  end if;

  EXCEPTION WHEN OTHERS THEN BEGIN
    ROLLBACK;
    RAISE;
  END;
END;

END;

procedure CHECK_REZERVARICMD(aCodIes in number) is
vRezervari number(20,7);
vDedicat number(20,7);
vCerere number(20,7);
vDif number(20,7);
begin
  for v_rec in
  (
    select
      c1.restacceptat, c1.codcomanda1, c1.codobiect,
      (select sum(r.rest)
       from rezervats r
            inner join nirstoc ns on ns.codnirstoc = r.codnirstoc
       where r.codcomanda1 = c1.codcomanda1 and ns.codobiect = c1.codobiect
      ) rezervari,
      (select sum(r.rest)
       from rezervats r
            inner join comanda1 cf1 on cf1.codcomanda1 = r.codcomanda1f
       where r.codcomanda1 = c1.codcomanda1 and coalesce(r.codnirstoc,0) = 0 and cf1.codobiect = c1.codobiect
      ) dedicat,
      (select sum(r.rest)
       from rezervats r
       where r.codcomanda1 = c1.codcomanda1 and coalesce(r.codnirstoc,0) = 0 and
             coalesce(r.codcomanda1f,0) = 0 and r.codobiect = c1.codobiect
      ) cerere
    from comanda1 c1
         inner join ieslink l on c1.codcomanda1 = l.codliniecomanda
         inner join iesiri1 i1 on i1.codies1 = l.codies1
    where i1.codies = aCodIes
  ) loop
    vRezervari := coalesce(v_rec.rezervari,0);
    vDedicat := coalesce(v_rec.dedicat,0);
    vCerere := coalesce(v_rec.cerere,0);
    if v_rec.restacceptat &lt; vRezervari + vDedicat + vCerere then
      -- trebuie ajustare
      vDif := vRezervari + vDedicat + vCerere - v_rec.restacceptat;
      if vDif &gt; vCerere then
        delete rezervats where codcomanda1 = v_rec.codcomanda1 and coalesce(codnirstoc,0) = 0 and
                               coalesce(codcomanda1f,0) = 0 and codobiect = v_rec.codobiect;
        vDif := vDif - vCerere;
      else
        for v_tmp in (
          select codrezervats, rest, rezervatini
          from rezervats
          where codcomanda1 = v_rec.codcomanda1 and coalesce(codnirstoc,0) = 0 and
                coalesce(codcomanda1f,0) = 0 and codobiect = v_rec.codobiect
        ) loop
          if v_tmp.rest &gt; vDif then
            update rezervats set Rest = Rest - vDif where codrezervats = v_tmp.codrezervats;
            if v_tmp.rezervatini &gt; 0 then
              update rezervats set rezervatini = rezervatini - vDif where codrezervats = v_tmp.codrezervats;
            end if;
            vDif := 0;
          else
            vDif := vDif - v_tmp.rest;
            delete rezervats where codrezervats = v_tmp.codrezervats;
          end if;
          if vDif = 0 then
            Exit;
          end if;
        end loop;
        vDif := 0;
      end if;
      if vDif &gt; 0 then
        if vDif &gt; vDedicat then
          delete rezervats where codcomanda1 = v_rec.codcomanda1 and coalesce(codnirstoc,0) = 0 and
                                 coalesce(codcomanda1f,0) &gt; 0 and codobiect = v_rec.codobiect;
          vDif := vDif - vDedicat;
        else
          for v_tmp in (
            select codrezervats, rest, rezervatini
            from rezervats
            where codcomanda1 = v_rec.codcomanda1 and coalesce(codnirstoc,0) = 0 and
                  coalesce(codcomanda1f,0) &gt; 0 and codobiect = v_rec.codobiect
          ) loop
            if v_tmp.rest &gt; vDif then
              update rezervats set Rest = Rest - vDif where codrezervats = v_tmp.codrezervats;
              if v_tmp.rezervatini &gt; 0 then
                update rezervats set rezervatini = rezervatini - vDif where codrezervats = v_tmp.codrezervats;
              end if;
              vDif := 0;
            else
              vDif := vDif - v_tmp.rest;
              delete rezervats where codrezervats = v_tmp.codrezervats;
            end if;
            if vDif = 0 then
              Exit;
            end if;
          end loop;
          vDif := 0;
        end if;
        if vDif &gt; 0 then
          if vDif &gt; vRezervari then
            for v_tmp in (
              select r.codrezervats
              from rezervats r
                   inner join nirstoc ns on ns.codnirstoc = r.codnirstoc
              where r.codcomanda1 = v_rec.codcomanda1 and ns.codobiect = v_rec.codobiect
              ) loop
              delete rezervats where codrezervats = v_tmp.codrezervats;
            end loop;
          else
            for v_tmp in (
              select r.codrezervats, r.rest, r.rezervatini
              from rezervats r
                   inner join nirstoc ns on ns.codnirstoc = r.codnirstoc
              where r.codcomanda1 = v_rec.codcomanda1 and ns.codobiect = v_rec.codobiect
            ) loop
              if v_tmp.rest &gt; vDif then
                update rezervats set Rest = Rest - vDif where codrezervats = v_tmp.codrezervats;
                if v_tmp.rezervatini &gt; 0 then
                  update rezervats set rezervatini = rezervatini - vDif where codrezervats = v_tmp.codrezervats;
                end if;
                vDif := 0;
              else
                vDif := vDif - v_tmp.rest;
                delete rezervats where codrezervats = v_tmp.codrezervats;
              end if;
              if vDif = 0 then
                Exit;
              end if;
            end loop;
            vDif := 0;
          end if;
        end if;
      end if;
    end if;
  end loop;
end;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

procedure CheckOldUtilaje(aCodIes in number) is
begin
  insert into tmp_manevra_liste(filtru, valoare, filtru1, valoare1)
  select &apos;CODIES1&apos;, codies1, &apos;CODUTILAJ&apos;, codutilaj
  from iesiri1
  where codies = aCodIes and codutilaj &gt; 0;
end;

procedure RezolvUtilaje(aCodIes in number) is
aCount number(10);
aFurn number(20);
aSerie varchar2(75);
begin
  if ConstSelUtilaj = 1 then
    for v_rec in (select valoare1 from tmp_manevra_liste where filtru = &apos;CODIES1&apos; and filtru1 = &apos;CODUTILAJ&apos;) loop
      update utilaje set codies1 = null, codpart = null, nrcontr = null, datacontr = null, doc = null where codutilaj = v_rec.valoare1;
    end loop;

    for v_rec in (select i1.codies1, i1.codutilaj, i.partener, nvl(i.agent,0) agent, c.seriadoc||&apos;-&apos;||c.nrdoc nrcontr, c.datadoc datacontr
                  from iesiri1 i1
                       inner join iesiri i on i1.codies = i.codies
                       left  join contract c on i.codcontract = c.codcontract
                  where i1.codies = aCodIes and codutilaj &gt; 0) loop
      update utilaje
      set
        codpart = v_rec.partener, codies1 = v_rec.codies1,
        nrcontr = v_rec.nrcontr, datacontr = v_rec.datacontr
      where codutilaj = v_rec.codutilaj;
      select count(*) into aCount
      from livr1 l1
           inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
      where l1.codies1 = v_rec.codies1;
      if aCount = 1 then
        --preiau furnizorul si seria daca exista
        select nvl(ns.furn,0), string_agg(ser.serie)
        into aFurn, aSerie
        from livr1 l1
             inner join nirstoc ns on ns.codnirstoc = l1.codnirstoc
             left join nirser nse on l1.codnirser = nse.codnirser
             left join nserii ser on nse.codserie = ser.codserie
        where l1.codies1 = v_rec.codies1
        group by nvl(ns.furn,0);
        update utilaje set codfurnizor = aFurn, serief = substr(aSerie,1,50), agent = case when v_rec.agent &gt; 0 then v_rec.agent end where codutilaj = v_rec.codutilaj;
      end if;
    end loop;
  end if;
end;

procedure ClearManevraPtUtilaje is
begin
  if ConstSelUtilaj = 1 then
    delete tmp_manevra_liste;
  end if;
end;

procedure EXEC_DEBUG IS
BEGIN
  PKG_GLOBALS.SetLunaLucru(2010,7);
  PKG_GLOBALS.SETSUBUNITATE(2);

/*

  delete TMP_MODURIPLATI;
  delete TMP_IESIRI ;
  delete TMP_IESIRI1 ;
  delete TMP_GENERAL ;
  delete TMP_OBLIGPIF;
  delete TMP_OBLIGPIF_INITIAL;
  delete TMP_STINGERE ;
  delete TMP_STINGERE_INITIAL ;
  delete TMP_IESLINK;
  delete TMP_IESPRODLINK;
  delete TMP_IESVALLINK;
  delete TMP_IESVALLINK_INITIAL ;
  delete TMP_LIVR;
  delete  TMP_LIVR1;
  delete  TMP_LIVR1_Initial;
  delete  TMP_LIVRVAL;
  delete  TMP_LIVRTOT;
  SP_GOTORECORD(1357);
*/
END;

FUNCTION GetAmbalaje (pCodIes IN NUMBER) RETURN sys_refcursor IS
  TmpCursor sys_refcursor;
BEGIN
  BEGIN
    OPEN  TmpCursor FOR
      SELECT
        amb.codobiect, a.codarticol,
        CASE WHEN a.tiparticol = 1 THEN &apos;S&apos; ELSE &apos;=&apos; END TipLinie,
        o.denumire,
        u1.codum1 UMSec, U1.Den_UM1, u1.Paritate, amb.cant
      FROM (
        SELECT codobiect, Sum(cant) cant
        FROM (
          SELECT aa.codobiectreturn codobiect, Round(i1.cant / aa.cant) cant
          FROM iesiri1 i1
            INNER JOIN nartamb aa ON aa.codobiect = i1.codobiect
          WHERE codies = pCodIes and coalesce(aa.returnabil,1) = 1
        )
        HAVING Sum(cant) &lt;&gt; 0
        GROUP BY codobiect
      ) amb
        INNER JOIN nartobj o ON o.codobiect = amb.codobiect
        INNER JOIN nart a ON a.codarticol = o.codarticol
        INNER JOIN num1 u1 ON u1.codum = a.um AND u1.secundara = 0;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN TmpCursor;
END;

procedure setjurnaldirty(aCodIes in number, aTipDoc in number) is
begin
  for v_rec in (select i1.codies1, j1.codjurnal1, j.codjurnal,i.an,i.luna
                from iesiri i
                     inner join iesiri1 i1 on i.codies = i1.codies
                     left join jurnal1 j1 on j1.coddoc = i.codies and j1.tipdoc = i.tipdoc and j1.indexlocal = i1.codies1
                     left join jurnal j on j.coddoc = i.codies and j.tipdoc = i.tipdoc and j.indexlocal = i1.codies
                where i.codies = aCodIes and i.tipdoc = aTipDoc
               ) loop
    if v_rec.codjurnal1 is null then
      insert into jurnal1(codjurnal1,coddoc,tipdoc,indexlocal,dirty,an,luna)
      values (seq_jurnal1_codjurnal1.nextval,aCodIes,aTipDoc,v_rec.codies1,1,v_Rec.an,v_rec.luna);
    else
      update jurnal1 set dirty = 1 where codjurnal1 = v_rec.codjurnal1;
    end if;
    if v_rec.codjurnal is null then
      insert into jurnal(codjurnal,coddoc,tipdoc,indexlocal,an,luna)
      values (seq_jurnal_codjurnal.nextval,aCodIes,aTipDoc,aCodIes,v_Rec.an,v_rec.luna);
    end if;
  end loop;
  commit;
end;

END PKG_IESIRI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IESIRIRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDADA4E318F1687CA13BCED758C66660140B5472</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_iesiriretail is

FUNCTION CANLOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM LOCKPOSTRETAIL
  WHERE
    CODPOSTRETAIL = aCODPOSTRETAIL
    AND USERID   &lt;&gt; PKG_GLOBALS.USERID;

  IF NR &gt; 0 THEN RETURN 0; ELSE RETURN 1; END IF;
END;


PROCEDURE LOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO LOCKPOSTRETAIL (USERID, CODPOSTRETAIL)
  VALUES (PKG_GLOBALS.USERID, aCODPOSTRETAIL);
 COMMIT;
END;


PROCEDURE UNLOCKPOSTRETAIL(aCODPOSTRETAIL IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM LOCKPOSTRETAIL
  WHERE
    CODPOSTRETAIL = aCODPOSTRETAIL
    AND USERID = PKG_GLOBALS.USERID; 
 COMMIT;
END;





PROCEDURE PREPARE_TREZOR_FOR_JURNAL(aCODTREZOR NUMBER)
IS
 aCODSUBUNITSTINS NUMBER(20) := 0;
BEGIN
  DELETE TMP_TREZOR;
  DELETE TMP_TREZOR1;
  DELETE TMP_GENERAL;
  DELETE TMP_OBLIGPIF;
  DELETE TMP_STINGERE;
  DELETE TMP_JURNAL;
  DELETE TMP_JURNAL1;
  DELETE TMP_RULAJ;
  PKG_TREZOR.SP_GOTORECORD(aCODTREZOR);
END;    


PROCEDURE CLEAR_IESIRIRETAIL_TEMPS
IS
BEGIN
  DELETE TMP_IESIRIRETAIL;
  DELETE TMP_IESIRI1RETAIL;
  DELETE TMP_MODPLATAIESRETAIL;
  COMMIT;
END;    



PROCEDURE SET_FLAG_MODIF(aCODIESRETAIL IN NUMBER)
IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   UPDATE IESIRIRETAIL
   SET
     TIPMODIF = &apos;M&apos;
   WHERE
     CODIESRETAIL = aCODIESRETAIL; 
   COMMIT;    
END;      




PROCEDURE PREPARE_NEW_IESIRIRETAIL
IS
BEGIN  
   DELETE TMP_IESIRIRETAIL;
   DELETE TMP_IESIRI1RETAIL;
   DELETE TMP_STATUSDECL;
   DELETE TMP_DETALIIET;
   
   INSERT INTO TMP_IESIRIRETAIL(CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, AGENT, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS, TIPET, IS_ETRANSP, ROTEFACT)
   SELECT 
     CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, AGENT, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS, TIPET, IS_ETRANSP, ROTEFACT FROM IESIRIRETAIL 
   WHERE  
     NVL(CODIES, 0) = 0;
   
   INSERT INTO TMP_IESIRI1RETAIL (CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, 
                                  VALDISCPRET, CODGEST, CODIOARTVAL, TVANEEX )
   SELECT 
     CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, 
     VALDISCPRET, CODGEST, CODIOARTVAL, TVANEEX 
   FROM 
     IESIRI1RETAIL 
   WHERE 
     CODIESRETAIL IN (SELECT CODIESRETAIL FROM TMP_IESIRIRETAIL);
       
   INSERT INTO TMP_MODPLATAIESRETAIL SELECT * FROM MODPLATAIESRETAIL 
   WHERE        
      CODIESRETAIL IN (SELECt CODIESRETAIL FROM TMP_IESIRIRETAIL); 

   INSERT INTO TMP_STATUSDECL(CODSTATUSDECL,TIPDOC,CODDOC,IDINCARCARE,IDDESCARCARE,DATAINCARCARE,STARE,TIPMEDIU,USERNAME,AN,LUNA,COMPNAME,FILENAME,CIF,SERIE_CERTIF,UIT)
   SELECT CODSTATUSDECL,TIPDOC,CODDOC,IDINCARCARE,IDDESCARCARE,DATAINCARCARE,STARE,TIPMEDIU,USERNAME,AN,LUNA,COMPNAME,FILENAME,CIF,SERIE_CERTIF,UIT
   FROM
     STATUSDECL
   WHERE
     TIPDOC = -119
     AND CODDOC IN (SELECT CODIESRETAIL FROM TMP_IESIRIRETAIL);  


   INSERT INTO TMP_DETALIIET(CODDETALIU,CODDOC,TIPDOC,CODLOCINC,ADRESAINC,DATATRANSPORT,CODLOCDESC,ADRESADESC,CODPTF,CODBV,CODPARTTR,NRAUTO,NRREMORCA1,NRREMORCA2)
   SELECT CODDETALIU,CODDOC,TIPDOC,CODLOCINC,ADRESAINC,DATATRANSPORT,CODLOCDESC,ADRESADESC,CODPTF,CODBV,CODPARTTR,NRAUTO,NRREMORCA1,NRREMORCA2
   FROM
     DETALIIET
   WHERE
     TIPDOC = -19
     AND CODDOC IN (SELECT CODIESRETAIL FROM TMP_IESIRIRETAIL);  
     
   COMMIT;
END;  

PROCEDURE PREPARE_MODIF_IESIRIRETAIL
IS
BEGIN  
   DELETE TMP_IESIRIRETAIL;
   DELETE TMP_IESIRI1RETAIL;
   DELETE TMP_MODPLATAIESRETAIL;
   
   INSERT INTO TMP_IESIRIRETAIL(CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, AGENT, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS)
   SELECT 
     CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, AGENT, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS FROM IESIRIRETAIL 
   WHERE  
     NVL(CODIES, 0) &lt;&gt; 0
     AND TIPMODIF = &apos;M&apos;;
   
   INSERT INTO TMP_IESIRI1RETAIL (CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, 
                                 VALDISCPRET, CODGEST, CODIOARTVAL, TVANEEX)
   SELECT 
     CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, 
                                  VALDISCPRET, CODGEST, CODIOARTVAL, TVANEEX 
   FROM 
     IESIRI1RETAIL 
   WHERE 
     CODIESRETAIL IN (SELECt CODIESRETAIL FROM TMP_IESIRIRETAIL);


   INSERT INTO TMP_MODPLATAIESRETAIL SELECT * FROM MODPLATAIESRETAIL 
   WHERE        
      CODIESRETAIL IN (SELECt CODIESRETAIL FROM TMP_IESIRIRETAIL); 
   COMMIT;
END;  


PROCEDURE DO_POST_NEWFACT_ONBAZA
IS   
  NEWCODIES              NUMBER(20);
  aCODIES1               NUMBER(20);
  aCODLIVR               NUMBER(20);
  aCODLIVR1              NUMBER(20);
  aCODGENERAL            NUMBER(20);
  aCODOBLIG              NUMBER(20);

  aCODTREZOR             NUMBER(20);
  aCODTREZOR1            NUMBER(20);
  aCODGENERAL_STINGATOR  NUMBER(20);
  aCODOBLIG_STINGATOR    NUMBER(20);
  aCODIOARTVAL           VARCHAR2(10);
  VAL_FACTURA            NUMBER(20,7);
  VAL_STINGERE           NUMBER(20,7);
  
BEGIN
  aCODIOARTVAL := PKG_CATEGCONST.GetValConstanta(&apos;CodIoArtVAl&apos;, PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU);
  FOR V_REC IN (SELECT 
                   CODIESRETAIL 
                FROM 
                   TMP_IESIRIRETAIL 
                WHERE 
                   NVL(CODLOCATIE, 0) &lt;&gt; 0 AND NVL(CODLOCATIE, 0) NOT IN (SELECT CODAGENDA FROM NAGENDA)
               )
  LOOP
    UPDATE TMP_IESIRIRETAIL
    SET
      CODLOCATIE = NULL
    WHERE
      CODIESRETAIL = V_REC.CODIESRETAIL;  
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_IESIRIRETAIL)
  LOOP
    NEWCODIES := SEQ_IESIRI_CODIES.NEXTVAL;
    
    NotifyModif(-11, NEWCODIES, &apos;IESIRI&apos;);
    
    
    PKG_IESIRIRETAIL.SETNRDOC_I(0, 0);
    
    
    IF NVL(V_REC.CARNETDOC, 0) &lt;&gt; 0 AND NVL(V_REC.NRDOC, 0) &lt;&gt; 0 THEN 
      PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
    END IF;  
    
    INSERT INTO IESIRI(CODIES, 
                       TIPDOC, 
                       ANULAT, 
                       BLOCAT, 
                       OPERAT, 
                       PREFIXDOC, 
                       CARNETDOC, 
                       NRDOC, 
                       DATADOC, 
                       PARTENER, 
                       VALDOC, 
                       TVADOC, 
                       VALDISCOUNT, 
                       TVADISCOUNT, 
                       DELEGAT, 
                       OBS, 
                       AN, 
                       LUNA, 
                       CODFISCAL, 
                       SERIADOC, 
                       CODLOCATIE, 
                       TIPTVA, 
                       SUBUNITATEA, 
                       MONEDA, 
                       CURS, 
                       DATACREARE, 
                       MIJLTRANSP, 
                       NRTRANSP, 
                       LISTAT, 
                       INFOCM, 
                       CURSDOC, 
                       NRI, 
                       FARATRANSPORT, 
                       TIPCHELT, 
                       EXCLUSPLATA, 
                       PROCTVADOC, 
                       DATATVA,
                       TIPTRANZACTIE,
                       AGENT,
                       PARTCUSTODIE,
                       TIPET,
                       IS_ETRANSP,
                       ROTEFACT,
                       TIPSAFT
                      )
               VALUES (NEWCODIES, 
                       V_REC.TIPDOC, 
                       V_REC.ANULAT, 
                       V_REC.BLOCAT, 
                       V_REC.OPERAT, 
                       V_REC.PREFIXDOC, 
                       V_REC.CARNETDOC, 
                       V_REC.NRDOC, 
                       V_REC.DATADOC, 
                       V_REC.PARTENER, 
                       V_REC.VALDOC, 
                       V_REC.TVADOC, 
                       V_REC.VALDISCOUNT, 
                       V_REC.TVADISCOUNT, 
                       V_REC.DELEGAT, 
                       V_REC.OBS, 
                       V_REC.AN, 
                       V_REC.LUNA, 
                       V_REC.CODFISCAL, 
                       V_REC.SERIADOC, 
                       V_REC.CODLOCATIE, 
                       1, 
                       V_REC.SUBUNITATEA, 
                       V_REC.MONEDA, 
                       V_REC.CURS, 
                       V_REC.DATACREARE, 
                       V_REC.MIJLTRANSP, 
                       V_REC.NRTRANSP, 
                       V_REC.LISTAT, 
                       V_REC.INFOCM, 
                       V_REC.CURSDOC, 
                       V_REC.NRI, 
                       V_REC.FARATRANSPORT, 
                       V_REC.TIPCHELT, 
                       V_REC.EXCLUSPLATA, 
                       V_REC.PROCTVADOC, 
                       V_REC.DATATVA,
                       1,
                       V_REC.AGENT,
                       V_REC.CODPARTCOMIS,
                       V_REC.TIPET,
                       V_REC.IS_ETRANSP,
                       V_REC.ROTEFACT,
                       CASE
                         WHEN V_REC.INFOCM = 1 THEN 5
                         ELSE NULL
                       END      
                       );
       

       IF V_REC.INFOCM = 0 THEN
         aCODLIVR := SEQ_LIVR_CODLIVR.NEXTVAL;
         INSERT INTO LIVR(CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, TIPLIVR, ANULAT, BLOCAT, OPERAT)
         VALUES(aCODLIVR, NEWCODIES, V_REC.CARNETLIVR, V_REC.NRLIVR,V_REC.DATADOC, V_REC.TIPDOC, 0, 0, 1);         
       END IF;  


      UPDATE TMP_IESIRIRETAIL
      SET
        CODIES = NEWCODIES
      WHERE
        CODIESRETAIL = V_REC.CODIESRETAIL;                
     
      UPDATE TMP_DETALIIET
      SET
        CODDOC = NEWCODIES
      WHERE
        CODDOC =  V_REC.CODIESRETAIL;    

      UPDATE TMP_STATUSDECL
      SET
        CODDOC = NEWCODIES
      WHERE
        CODDOC =  V_REC.CODIESRETAIL;    



      FOR V_REC_D IN (SELECT * FROM TMP_IESIRI1RETAIL WHERE CODIESRETAIL = V_REC.CODIESRETAIL)
      LOOP        
        aCODIES1 := SEQ_IESIRI1_CODIES1.NEXTVAL;             
        INSERT INTO IESIRI1(CODIES1, 
                            CODIES, 
                            INDEXLOCAL, 
                            TIPLINIE, 
                            UMSEC, 
                            CONTSERV, 
                            GESTACT, 
                            CODOBIECT, 
                            PRETORIG, 
                            PU, 
                            CANT, 
                            TVA, 
                            CONT, 
                            ADDIM, 
                            PROCDISC, 
                            RESTFACT, 
                            PUMAXIMAL, 
                            GARANTIE, 
                            COEFDISCMAJ, 
                            OBS, 
                            CONTDISCOUNT, 
                            CODCRITERIU, 
                            ZILE, 
                            CADOU, 
                            CODCADOU, 
                            TAXA, 
                            CODAGENTEMULARE, 
                            VALDISCPRET
                           )
                  VALUES   (aCODIES1, 
                            NEWCODIES,  
                            V_REC_D.INDEXLOCAL, 
                            V_REC_D.TIPLINIE, 
                            V_REC_D.UMSEC, 
                            V_REC_D.CONTSERV, 
                            V_REC_D.GESTACT, 
                            V_REC_D.CODOBIECT, 
                            V_REC_D.PRETORIG, 
                            V_REC_D.PU, 
                            V_REC_D.CANT, 
                            V_REC_D.TVA, 
                            V_REC_D.CONT, 
                            V_REC_D.ADDIM, 
                            V_REC_D.PROCDISC, 
                            V_REC_D.RESTFACT, 
                            V_REC_D.PUMAXIMAL, 
                            V_REC_D.GARANTIE, 
                            V_REC_D.COEFDISCMAJ, 
                            V_REC_D.OBS, 
                            V_REC_D.CONTDISCOUNT, 
                            V_REC_D.CODCRITERIU, 
                            V_REC_D.ZILE, 
                            V_REC_D.CADOU, 
                            V_REC_D.CODCADOU, 
                            V_REC_D.TAXA, 
                            V_REC_D.CODAGENTEMULARE, 
                            V_REC_D.VALDISCPRET
                           );
                           
                           
        IF V_REC.INFOCM = 0 AND V_REC_D.TIPLINIE = &apos;=&apos; THEN
          aCODLIVR1 := SEQ_LIVR1_CODLIVR1.NEXTVAL;
          INSERT INTO LIVR1(CODLIVR1, 
                           CODLIVR, 
                           CODIES1, 
                           CANT,
                           RESTIESVAL, 
                           UMSEC)
                     VALUES(aCODLIVR1,
                            aCODLIVR,
                            aCODIES1,
                            V_REC_D.CANT,
                            V_REC_D.CANT,
                            V_REC_D.UMSEC
                           );
           INSERT INTO LIVRVAL(CODLIVRVAL, 
                               CODLIVR1, 
                               CODOBIECT, 
                               CODIOART, 
                               GEST, 
                               TVANEEX)                                     
                       VALUES(SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,
                              aCODLIVR1,
                              V_REC_D.CODOBIECT,
                              NVL(V_REC_D.CODIOARTVAL, aCODIOARTVAL),
                              V_REC_D.CODGEST,
                              V_REC_D.TVANEEX
                             );         
        END IF;                     
                                                       
      END LOOP; 
      
---       VAL_FACTURA := ROUND(V_REC.VALDOC - V_REC.TVADOC,2) + ROUND(V_REC.TVADOC,2);


      FOR V_REC_X IN (SELECT * FROM TMP_DETALIIET WHERE CODDOC = NEWCODIES )
      LOOP
        INSERT INTO DETALIIET(CODDETALIU,
                              CODDOC, 
                              TIPDOC, 
                              CODLOCINC, 
                              ADRESAINC, 
                              DATATRANSPORT, 
                              CODLOCDESC, 
                              ADRESADESC, 
                              CODPTF, 
                              CODBV, 
                              CODPARTTR, 
                              NRAUTO, 
                              NRREMORCA1, 
                              NRREMORCA2 
                             )    
        VALUES (SEQ_DETALIIET_CODDETALIU.NEXTVAL,
                V_REC_X.CODDOC,
                19,                     
                V_REC_X.CODLOCINC, 
                V_REC_X.ADRESAINC, 
                V_REC_X.DATATRANSPORT, 
                V_REC_X.CODLOCDESC, 
                V_REC_X.ADRESADESC, 
                V_REC_X.CODPTF, 
                V_REC_X.CODBV, 
                V_REC_X.CODPARTTR, 
                V_REC_X.NRAUTO, 
                V_REC_X.NRREMORCA1, 
                V_REC_X.NRREMORCA2
               );  
      END LOOP;   
      
      FOR V_REC_X IN (SELECT * FROM TMP_STATUSDECL WHERE CODDOC = NEWCODIES)
      LOOP
        INSERT INTO STATUSDECL(CODSTATUSDECL,
                               TIPDOC,
                               CODDOC,
                               IDINCARCARE,
                               IDDESCARCARE,
                               DATAINCARCARE,
                               STARE,
                               TIPMEDIU,
                               USERNAME,
                               AN,
                               LUNA,
                               COMPNAME,
                               FILENAME,
                               MESAJE,
                               CIF,
                               SERIE_CERTIF,
                               UIT
                             )    
        VALUES (SEQ_STATUSDECL.NEXTVAL,
                119,                     
                V_REC_X.CODDOC,
                V_REC_X.IDINCARCARE,
                V_REC_X.IDDESCARCARE,
                V_REC_X.DATAINCARCARE,
                V_REC_X.STARE,
                V_REC_X.TIPMEDIU,
                V_REC_X.USERNAME,
                V_REC_X.AN,
                V_REC_X.LUNA,
                V_REC_X.COMPNAME,
                V_REC_X.FILENAME,
                V_REC_X.MESAJE,
                V_REC_X.CIF,
                V_REC_X.SERIE_CERTIF,
                V_REC_X.UIT
               );  
      END LOOP;   
      
       






      IF V_REC.INFOCM = 0 THEN
        aCODGENERAL := SEQ_GENERAL_CODGENERAL.NEXTVAL;
        aCODOBLIG   := SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL;
        
        INSERT INTO GENERAL(CODGENERAL,TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
        VALUES (aCODGENERAL, V_REC.TIPDOC, NEWCODIES, 0, 1, 200);

        INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE)
                    VALUES(aCODOBLIG, aCODGENERAL, V_REC.DATADOC, ROUND(V_REC.VALDOC - V_REC.TVADOC,2) + ROUND(V_REC.TVADOC,2),  ROUND(V_REC.VALDOC - V_REC.TVADOC,2) + ROUND(V_REC.TVADOC,2), V_REC.PARTENER, 3, 200);
                     
        INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,  DIRTY, AN, LUNA, SUBUNITATEA)
                   VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, NEWCODIES, V_REC.TIPDOC, 1, 1, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA);
        
        INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,  AN, LUNA, SUBUNITATEA)
                   VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, NEWCODIES, V_REC.TIPDOC, 1,  V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA);

      END IF;  
      
                    
  END LOOP;

      -- CASA/BANCA
  DELETE TMP_TREZOR1;     
  FOR V_REC_MP_MASTER IN (SELECT DISTINCT 
                            TIPPLATA, 
                            CODBANKCONT, 
                            MP.VOUCHERSGR,
                            I.AN, 
                            I.LUNA, 
                            I.SUBUNITATEA,
                            I.DATADOC
                          FROM 
                            TMP_MODPLATAIESRETAIL MP,  
                            TMP_IESIRIRETAIL I
                          WHERE
                            I.CODIESRETAIL = MP.CODIESRETAIL  
                            AND I.INFOCM = 0
                            AND TIPPLATA &lt;&gt; 3
                            )
  LOOP
    aCODTREZOR  := SEQ_TREZOR_CODTREZOR.NEXTVAL;
    NotifyModif(-11, aCODTREZOR, &apos;TREZOR&apos;);
    
    
    INSERT INTO TREZORRETAIL(CODTREZOR) VALUES (aCODTREZOR);
    INSERT INTO TMP_TREZORRETAIL(CODTREZOR) VALUES (aCODTREZOR);

    INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA, DATADOC,  AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA,  DATACREARE)
    VALUES (aCODTREZOR,
            CASE WHEN V_REC_MP_MASTER.TIPPLATA IN (0, 2) THEN 29
                 WHEN V_REC_MP_MASTER.TIPPLATA = 1 AND COALESCE(V_REC_MP_MASTER.VOUCHERSGR, 0) = 1 THEN 29
                 ELSE 31
            END,
            V_REC_MP_MASTER.CODBANKCONT,
            V_REC_MP_MASTER.DATADOC,         
            V_REC_MP_MASTER.AN,
            V_REC_MP_MASTER.LUNA,
            1,
            0,
            V_REC_MP_MASTER.SUBUNITATEA,
            SYSDATE
          );  
         FOR V_REC_MP IN (SELECT 
                            MP.*,
                            I.CODIES,
                            I.NRDOC,
                            I.DATADOC,
                            I.PARTENER,
                            I.AN,
                            I.LUNA,
                            I.VALDOC,
                            I.TVADOC,
                            I.SUBUNITATEA,
                            O.CODOBLIGPIF 
                          FROM 
                            TMP_MODPLATAIESRETAIL MP,
                            TMP_IESIRIRETAIL I,
                            GENERAL G,
                            OBLIGPIF O 
                          WHERE
                            MP.TIPPLATA = V_REC_MP_MASTER.TIPPLATA
                            AND MP.CODBANKCONT = V_REC_MP_MASTER.CODBANKCONT
                            AND I.DATADOC = V_REC_MP_MASTER.DATADOC
                            AND I.AN = V_REC_MP_MASTER.AN
                            AND I.LUNA = V_REC_MP_MASTER.LUNA
                            AND I.INFOCM = 0
                            AND I.SUBUNITATEA = V_REC_MP_MASTER.SUBUNITATEA
                            AND I.CODIESRETAIL = MP.CODIESRETAIL
                            AND G.TIPDOC = I.TIPDOC
                            AND G.CODDOC = I.CODIES
                            AND G.SEMNIFICATIE = 200
                            AND O.CODGENERAL = G.CODGENERAL
                          )
          LOOP
             aCODTREZOR1 := SEQ_TREZOR1_CODTREZOR1.NEXTVAL;
             VAL_FACTURA := ABS(ROUND(V_REC_MP.VALDOC - V_REC_MP.TVADOC,2) + ROUND(V_REC_MP.TVADOC,2));

             VAL_STINGERE :=  ABS(ROUND(V_REC_MP.VALOARE, 2));
             IF ABS(VAL_STINGERE - VAL_FACTURA) &lt;= 0.01 THEN
               VAL_STINGERE := VAL_FACTURA;
             END IF;  
             INSERT INTO TREZOR1(CODTREZOR1, 
                                 CODTREZOR, 
                                 INDEXLOCAL, 
                                 TIPTRANZ,        
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 VALDOC,
                                 CURS,
                                 OBIECTTRANZ,
                                 CODPART,
                                 AN,
                                 LUNA,
                                 ANULAT)
                        VALUES (aCODTREZOR1,
                                aCODTREZOR,
                                1,
                                CASE
                                 WHEN V_REC_MP.VALOARE &lt; 0 THEN 0
                                 ELSE   1
                                 END,
                                CASE 
                                   WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN &apos;C&apos;
                                   WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN &apos;V&apos;
                                   ELSE &apos;CEC&apos;
                                END,
                                V_REC_MP.NRDOC,
                                V_REC_MP.DATADOC,
                               -- ABS(ROUND(V_REC_MP.VALOARE, 2)),
                                VAL_STINGERE,
                                1,
                                CASE
                                 WHEN V_REC_MP.VALOARE &lt; 0 THEN 1
                                 ELSE   0
                                 END,
                                V_REC_MP.PARTENER,
                                V_REC_MP.AN,
                                V_REC_MP.LUNA,
                                0);


             INSERT INTO TMP_TREZOR1 (CODTREZOR1) VALUES(aCODTREZOR1);                                
             INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY, AN, LUNA, SUBUNITATEA)
             VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, 
                    aCODTREZOR,                    
                    CASE WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                         WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                         ELSE 31
                    END,
                    aCODTREZOR1,
                    1,
                    V_REC_MP.AN,
                    V_REC_MP.LUNA,
                    V_REC_MP.SUBUNITATEA);
                                
             INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, SUBUNITATEA)
             VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, 
                    aCODTREZOR,                    
                    CASE WHEN  V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                         WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                         ELSE 31
                    END,
                    1,
                    V_REC_MP.AN,
                    V_REC_MP.LUNA,
                    V_REC_MP.SUBUNITATEA);


             aCODGENERAL_STINGATOR := SEQ_GENERAL_CODGENERAL.NEXTVAL;
             aCODOBLIG_STINGATOR   := SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL;
             
             INSERT INTO GENERAL(CODGENERAL, 
                                 TIPDOC, 
                                 CODDOC, 
                                 MONEDA, 
                                 CURS, 
                                 SEMNIFICATIE
                                 ) 
                         VALUES(aCODGENERAL_STINGATOR,
                                CASE WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                                     WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                                     ELSE 31
                                END,
                                aCODTREZOR1,
                                0,
                                1,
                                CASE
                                 WHEN V_REC_MP.VALOARE &lt; 0 THEN 420
                                 ELSE 400
                                 END
                               );
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, 
            VALOARE, 
            VALOAREAFISATA, 
            REST, 
            CODPART, 
            ICONT, 
            SEMNIFICATIE)
           VALUES(aCODOBLIG_STINGATOR, 
                  aCODGENERAL_STINGATOR, 
                  VAL_STINGERE,
                  VAL_STINGERE,
                 -- ABS(ROUND(V_REC_MP.VALOARE, 2)),  
                 -- ABS(ROUND(V_REC_MP.VALOARE, 2)), 
                  0, 
                  V_REC_MP.PARTENER, 
                  3, 
                  CASE
                    WHEN V_REC_MP.VALOARE &lt; 0 THEN 420
                    ELSE 400  
                  END
                  );
                    
            INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)        
                        VALUES(SEQ_STINGERE_CODSTINGERE.NEXTVAL, V_REC_MP.CODOBLIGPIF, aCODOBLIG_STINGATOR, /*ABS(V_REC_MP.VALOARE)*/ VAL_STINGERE);
                        
            UPDATE OBLIGPIF
            SET
--              REST = REST - VAL_STINGERE
              REST = (
                    CASE
                     WHEN VALOARE &gt;= 0 THEN REST - VAL_STINGERE
                     WHEN VALOARE &lt; 0  THEN REST + VAL_STINGERE
                    END
                   )
            WHERE
              CODOBLIGPIF = V_REC_MP.CODOBLIGPIF;              
                        
          END LOOP;                                  
             
  END LOOP;    

  BEGIN

      INSERT INTO IESIRIRETAIL(CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, TIPMODIF, AGENT, CARNETLIVR, NRLIVR)
      SELECT CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, TIPMODIF, AGENT, CARNETLIVR, NRLIVR
      FROM TMP_IESIRIRETAIL;
      
      
      
      INSERT INTO IESIRI1RETAIL(CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET, DISCMANUAL, CODUTILAJ, CODGEST, CODIOARTVAL, TVANEEX)
      SELECT CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET, DISCMANUAL, CODUTILAJ, CODGEST, CODIOARTVAL, TVANEEX
      FROM
        TMP_IESIRI1RETAIL;
        
    EXCEPTION WHEN OTHERS THEN
      NULL;    
  END;



  INSERT INTO TMP_IESIRIRETAIL_PREL --folosite pe restserver
  SELECT * FROM TMP_IESIRIRETAIL;
  INSERT INTO TMP_IESIRI1RETAIL_PREL
  SELECT * FROM TMP_IESIRI1RETAIL;


  
--  COMMIT;    
END;





PROCEDURE DO_POST_MODIFFACT_ONBAZA
IS   
  NEWCODIES              NUMBER(20);
  ACODCARNET             NUMBER(20);
  ANRDOC                 NUMBER(20);
  NR                     NUMBER(20);
  aCODIES1               NUMBER(20);
  aCODLIVR               NUMBER(20);
  aCODLIVR1              NUMBER(20);
  aCODGENERAL            NUMBER(20);
  aCODOBLIG              NUMBER(20);

  aCODTREZOR             NUMBER(20);
  aCODTREZOR1            NUMBER(20);
  aCODGENERAL_STINGATOR  NUMBER(20);
  aCODOBLIG_STINGATOR    NUMBER(20);
  
BEGIN
  FOR V_REC IN (SELECT 
                   CODIESRETAIL 
                FROM 
                   TMP_IESIRIRETAIL 
                WHERE 
                   NVL(CODLOCATIE, 0) &lt;&gt; 0 AND NVL(CODLOCATIE, 0) NOT IN (SELECT CODAGENDA FROM NAGENDA)
               )
  LOOP
    UPDATE TMP_IESIRIRETAIL
    SET
      CODLOCATIE = NULL
    WHERE
      CODIESRETAIL = V_REC.CODIESRETAIL;  
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_IESIRIRETAIL)
  LOOP

    BEGIN
      SELECT CARNETDOC, NRDOC INTO aCODCARNET, aNRDOC FROM  IESIRI WHERE  CODIES = V_REC.CODIES;
      EXCEPTION WHEN OTHERS THEN aCODCARNET := 0; aNRDOC := 0;
    END;  
    
    IF (aCODCARNET &lt;&gt; 0 AND aNRDOC &lt;&gt; 0)AND(aCODCARNET &lt;&gt; V_REC.CARNETDOC OR aNRDOC &lt;&gt; V_REC.NRDOC)  THEN
      PKG_CARNETEDOC.RELEASENUMARDOC(ACODCARNET, ANRDOC);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACODCARNET);
    END IF;  

    SELECT COUNT(*) INTO NR FROM IESIRI WHERE CODIES = V_REC.CODIES; 
    IF NR = 1 THEN 
        UPDATE IESIRI
        SET (
             TIPDOC, 
             ANULAT, 
             BLOCAT, 
             OPERAT, 
             PREFIXDOC, 
             CARNETDOC, 
             NRDOC, 
             DATADOC, 
             PARTENER, 
             VALDOC, 
             TVADOC, 
             VALDISCOUNT, 
             TVADISCOUNT, 
             DELEGAT, 
             OBS, 
             AN, 
             LUNA, 
             CODFISCAL, 
             SERIADOC, 
             CODLOCATIE, 
             TIPTVA, 
             SUBUNITATEA, 
             MONEDA, 
             CURS, 
             DATACREARE, 
             MIJLTRANSP, 
             NRTRANSP, 
             LISTAT, 
             INFOCM, 
             CURSDOC, 
             NRI, 
             FARATRANSPORT, 
             TIPCHELT, 
             EXCLUSPLATA, 
             PROCTVADOC, 
             DATATVA,
             AGENT,
             PARTCUSTODIE
            ) = 
            (SELECT 
               V_REC.TIPDOC, 
               V_REC.ANULAT, 
               V_REC.BLOCAT, 
               V_REC.OPERAT, 
               V_REC.PREFIXDOC, 
               V_REC.CARNETDOC, 
               V_REC.NRDOC, 
               V_REC.DATADOC, 
               V_REC.PARTENER, 
               V_REC.VALDOC, 
               V_REC.TVADOC, 
               V_REC.VALDISCOUNT, 
               V_REC.TVADISCOUNT, 
               V_REC.DELEGAT, 
               V_REC.OBS, 
               V_REC.AN, 
               V_REC.LUNA, 
               V_REC.CODFISCAL, 
               V_REC.SERIADOC, 
               V_REC.CODLOCATIE, 
               V_REC.TIPTVA, 
               V_REC.SUBUNITATEA, 
               V_REC.MONEDA, 
               V_REC.CURS, 
               V_REC.DATACREARE, 
               V_REC.MIJLTRANSP, 
               V_REC.NRTRANSP, 
               V_REC.LISTAT, 
               V_REC.INFOCM, 
               V_REC.CURSDOC, 
               V_REC.NRI, 
               V_REC.FARATRANSPORT, 
               V_REC.TIPCHELT, 
               V_REC.EXCLUSPLATA, 
               V_REC.PROCTVADOC, 
               V_REC.DATATVA,
               V_REC.AGENT,
               V_REC.CODPARTCOMIS
            FROM
               DUAL
            )
          WHERE
            CODIES = V_REC.CODIES;

          NotifyModif(-12,  V_REC.CODIES, &apos;IESIRI&apos;);


       IF NVL(V_REC.CARNETDOC, 0) &lt;&gt; 0 AND NVL(V_REC.NRDOC, 0) &lt;&gt; 0 THEN
          PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
       END IF;  

       DELETE IESIRI1 WHERE CODIES = V_REC.CODIES;     
          
       FOR V_REC_L IN (SELECT 
                          L.CODLIVR, 
                          L1.CODLIVR1 
                       FROM 
                          LIVR L, 
                          LIVR1 L1 
                       WHERE 
                         L.CODIES = V_REC.CODIES 
                         AND L1.CODLIVR = L.CODLIVR
                       )
        LOOP
          DELETE FROM LIVRVAL WHERE CODLIVR1 = V_REC_L.CODLIVR1;
          DELETE FROM LIVR1   WHERE CODLIVR1 = V_REC_L.CODLIVR1;
          DELETE FROM LIVR    WHERE CODLIVR  = V_REC_L.CODLIVR;
        END LOOP;                   
                          
       IF V_REC.INFOCM = 0 THEN
         aCODLIVR := SEQ_LIVR_CODLIVR.NEXTVAL;
         INSERT INTO LIVR(CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, TIPLIVR, ANULAT, BLOCAT, OPERAT)
         VALUES(aCODLIVR, V_REC.CODIES, V_REC.CARNETLIVR, V_REC.NRLIVR,V_REC.DATADOC, V_REC.TIPDOC, 0, 0, 1);         
       END IF;  
       

        FOR V_REC_D IN (SELECT * FROM TMP_IESIRI1RETAIL WHERE CODIESRETAIL = V_REC.CODIESRETAIL)
        LOOP       
          aCODIES1 := SEQ_IESIRI1_CODIES1.NEXTVAL;
          INSERT INTO IESIRI1(CODIES1, 
                              CODIES, 
                              INDEXLOCAL, 
                              TIPLINIE, 
                              UMSEC, 
                              CONTSERV, 
                              GESTACT, 
                              CODOBIECT, 
                              PRETORIG, 
                              PU, 
                              CANT, 
                              TVA, 
                              CONT, 
                              ADDIM, 
                              PROCDISC, 
                              RESTFACT, 
                              PUMAXIMAL, 
                              GARANTIE, 
                              COEFDISCMAJ, 
                              OBS, 
                              CONTDISCOUNT, 
                              CODCRITERIU, 
                              ZILE, 
                              CADOU, 
                              CODCADOU, 
                              TAXA, 
                              CODAGENTEMULARE, 
                              VALDISCPRET
                             )
                    VALUES   (aCODIES1, 
                              V_REC.CODIES,  
                              V_REC_D.INDEXLOCAL, 
                              V_REC_D.TIPLINIE, 
                              V_REC_D.UMSEC, 
                              V_REC_D.CONTSERV, 
                              V_REC_D.GESTACT, 
                              V_REC_D.CODOBIECT, 
                              V_REC_D.PRETORIG, 
                              V_REC_D.PU, 
                              V_REC_D.CANT, 
                              V_REC_D.TVA, 
                              V_REC_D.CONT, 
                              V_REC_D.ADDIM, 
                              V_REC_D.PROCDISC, 
                              V_REC_D.RESTFACT, 
                              V_REC_D.PUMAXIMAL, 
                              V_REC_D.GARANTIE, 
                              V_REC_D.COEFDISCMAJ, 
                              V_REC_D.OBS, 
                              V_REC_D.CONTDISCOUNT, 
                              V_REC_D.CODCRITERIU, 
                              V_REC_D.ZILE, 
                              V_REC_D.CADOU, 
                              V_REC_D.CODCADOU, 
                              V_REC_D.TAXA, 
                              V_REC_D.CODAGENTEMULARE, 
                              V_REC_D.VALDISCPRET
                             );
                                                           
        IF V_REC.INFOCM = 0 AND V_REC_D.TIPLINIE = &apos;=&apos; THEN
          aCODLIVR1 := SEQ_LIVR1_CODLIVR1.NEXTVAL;
          INSERT INTO LIVR1(CODLIVR1, 
                           CODLIVR, 
                           CODIES1, 
                           CANT, 
                           UMSEC)
                     VALUES(aCODLIVR1,
                            aCODLIVR,
                            aCODIES1,
                            V_REC_D.CANT,
                            V_REC_D.UMSEC
                           );
           INSERT INTO LIVRVAL(CODLIVRVAL, 
                               CODLIVR1, 
                               CODOBIECT, 
                               CODIOART, 
                               GEST, 
                               TVANEEX)                                     
                       VALUES(SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,
                              aCODLIVR1,
                              V_REC_D.CODOBIECT,
                              V_REC_D.CODIOARTVAL,
                              V_REC_D.CODGEST,
                              V_REC_D.TVANEEX
                             );         
        END IF;                     



        END LOOP;     
        
        IF V_REC.INFOCM = 0 THEN
          FOR V_REC_G IN (SELECT 
                            G.CODGENERAL,
                            O.CODOBLIGPIF 
                          FROM 
                            GENERAL G,
                            OBLIGPIF O
                          WHERE
                            G.TIPDOC = V_REC.TIPDOC
                            AND G.CODDOC = V_REC.CODIES
                            AND O.CODGENERAL = G.CODGENERAL
                         )
          LOOP
             FOR V_REC_S IN (SELECT 
                               S.CODSTINGERE,
                               O.CODOBLIGPIF,
                               G.CODGENERAL,
                               G.CODDOC 
                            FROM 
                              STINGERE S,
                              OBLIGPIF O,
                              GENERAL G
                            WHERE 
                              S.CODSTINSPIF = V_REC_G.CODOBLIGPIF
                              AND O.CODOBLIGPIF = S.CODSTINGATORPIF
                              AND G.CODGENERAL = O.CODGENERAL
                              AND G.TIPDOC IN (29, 30, 31)
                             )
             LOOP
               DELETE FROM OBLIGPIF 
               WHERE
                 CODOBLIGPIF = V_REC_S.CODOBLIGPIF;
                   
                   
               DELETE FROM GENERAL
               WHERE
                 CODGENERAL = V_REC_S.CODGENERAL;
                   
               DELETE FROM TREZOR1 
               WHERE
                 CODTREZOR1 = V_REC_S.CODDOC; 
                 
               DELETE FROM STINGERE WHERE CODSTINGERE = V_REC_S.CODSTINGERE;  
                     
             END LOOP;   
             DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC_G.CODOBLIGPIF;
             DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC_G.CODGENERAL;
                            
          END LOOP;     
        
        
          IF V_REC.INFOCM = 0 THEN
            aCODGENERAL := SEQ_GENERAL_CODGENERAL.NEXTVAL;
            aCODOBLIG   := SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL;
            
            INSERT INTO GENERAL(CODGENERAL,TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
            VALUES (aCODGENERAL, V_REC.TIPDOC, V_REC.CODIES, 0, 1, 200);

            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE)
                        VALUES(aCODOBLIG, aCODGENERAL, V_REC.DATADOC, V_REC.VALDOC, V_REC.VALDOC, V_REC.PARTENER, 3, 200);
                         
            INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,  DIRTY, AN, LUNA, SUBUNITATEA)
                       VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODIES, V_REC.TIPDOC, 1, 1, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA);
            
            INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,  AN, LUNA, SUBUNITATEA)
                       VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, NEWCODIES, V_REC.TIPDOC, 1,  V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA);

          END IF;  
        
      END IF;  
     END IF;    
  END LOOP;


      -- CASA/BANCA
  DELETE TMP_TREZOR1;    
  FOR V_REC_MP_MASTER IN (SELECT DISTINCT 
                            TIPPLATA, 
                            MP.CODBANKCONT, 
                            MP.VOUCHERSGR,
                            I.AN, 
                            I.LUNA, 
                            I.SUBUNITATEA,
                            I.DATADOC
                          FROM 
                            TMP_MODPLATAIESRETAIL MP,  
                            TMP_IESIRIRETAIL I,
                            IESIRI II
                          WHERE
                            I.CODIESRETAIL = MP.CODIESRETAIL  
                            AND II.CODIES = I.CODIES
                            AND I.INFOCM = 0
                            AND TIPPLATA &lt;&gt; 3
                          )
  LOOP
    aCODTREZOR  := SEQ_TREZOR_CODTREZOR.NEXTVAL;
    INSERT INTO TREZORRETAIL(CODTREZOR) VALUES (aCODTREZOR);
    INSERT INTO TMP_TREZORRETAIL(CODTREZOR) VALUES (aCODTREZOR);
    
    INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA, DATADOC,  AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA,  DATACREARE)
    VALUES (aCODTREZOR,
            CASE WHEN V_REC_MP_MASTER.TIPPLATA IN (0, 2) THEN 29
                 WHEN V_REC_MP_MASTER.TIPPLATA =1 AND COALESCE(V_REC_MP_MASTER.VOUCHERSGR, 0) = 1 THEN 29
                 ELSE 31
            END,
            V_REC_MP_MASTER.CODBANKCONT,
            V_REC_MP_MASTER.DATADOC,         
            V_REC_MP_MASTER.AN,
            V_REC_MP_MASTER.LUNA,
            1,
            0,
            V_REC_MP_MASTER.SUBUNITATEA,
            SYSDATE
          );  
         FOR V_REC_MP IN (SELECT 
                            MP.*,
                            I.CODIES,
                            I.NRDOC,
                            I.DATADOC,
                            I.PARTENER,
                            I.AN,
                            I.LUNA,
                            I.SUBUNITATEA,
                            O.CODOBLIGPIF 
                          FROM 
                            TMP_MODPLATAIESRETAIL MP,
                            TMP_IESIRIRETAIL I,
                            IESIRI II,
                            GENERAL G,
                            OBLIGPIF O 
                          WHERE
                            MP.TIPPLATA = V_REC_MP_MASTER.TIPPLATA
                            AND MP.CODBANKCONT = V_REC_MP_MASTER.CODBANKCONT
                            AND I.DATADOC = V_REC_MP_MASTER.DATADOC
                            AND I.AN = V_REC_MP_MASTER.AN
                            AND I.LUNA = V_REC_MP_MASTER.LUNA
                            AND I.INFOCM = 0
                            AND I.SUBUNITATEA = V_REC_MP_MASTER.SUBUNITATEA
                            AND I.CODIESRETAIL = MP.CODIESRETAIL
                            AND II.CODIES = I.CODIES      
                            AND G.TIPDOC = I.TIPDOC
                            AND G.CODDOC = I.CODIES
                            AND G.SEMNIFICATIE = 200
                            AND O.CODGENERAL = G.CODGENERAL
                         )
          LOOP
             aCODTREZOR1 := SEQ_TREZOR1_CODTREZOR1.NEXTVAL;
             INSERT INTO TREZOR1(CODTREZOR1, 
                                 CODTREZOR, 
                                 INDEXLOCAL, 
                                 TIPTRANZ,        
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 VALDOC,
                                 CURS,
                                 OBIECTTRANZ,
                                 CODPART,
                                 AN,
                                 LUNA,
                                 ANULAT)
                        VALUES (aCODTREZOR1,
                                aCODTREZOR,
                                1,
                                1,
                                CASE 
                                   WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN &apos;C&apos;
                                   WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN &apos;V&apos;
                                   ELSE &apos;CEC&apos;
                                END,
                                V_REC_MP.NRDOC,
                                V_REC_MP.DATADOC,
                                V_REC_MP.VALOARE,
                                1,
                                0,
                                V_REC_MP.PARTENER,
                                V_REC_MP.AN,
                                V_REC_MP.LUNA,
                                0);


             INSERT INTO TMP_TREZOR1 (CODTREZOR1) VALUES(aCODTREZOR1);                                

                                
             INSERT INTO JURNAL1(CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY, AN, LUNA, SUBUNITATEA)
             VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, 
                    aCODTREZOR,                    
                    CASE WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                         WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                         ELSE 31
                    END,
                    aCODTREZOR1,
                    1,
                    V_REC_MP.AN,
                    V_REC_MP.LUNA,
                    V_REC_MP.SUBUNITATEA);
                                
             INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, SUBUNITATEA)
             VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, 
                    aCODTREZOR,                    
                    CASE WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                         WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                         ELSE 31
                    END,
                    1,
                    V_REC_MP.AN,
                    V_REC_MP.LUNA,
                    V_REC_MP.SUBUNITATEA);


             aCODGENERAL_STINGATOR := SEQ_GENERAL_CODGENERAL.NEXTVAL;
             aCODOBLIG_STINGATOR   := SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL;
             
             INSERT INTO GENERAL(CODGENERAL, 
                                 TIPDOC, 
                                 CODDOC, 
                                 MONEDA, 
                                 CURS, 
                                 SEMNIFICATIE
                                 ) 
                         VALUES(aCODGENERAL_STINGATOR,
                                CASE WHEN V_REC_MP.TIPPLATA IN (0, 2) THEN 29
                                     WHEN V_REC_MP.TIPPLATA = 1 AND COALESCE(V_REC_MP.VOUCHERSGR, 0) = 1 THEN 29
                                     ELSE 31
                                END,
                                aCODTREZOR1,
                                0,
                                1,
                                400
                               );
            INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, VALOAREAFISATA, REST, CODPART, ICONT, SEMNIFICATIE)
                        VALUES(aCODOBLIG_STINGATOR, aCODGENERAL_STINGATOR, V_REC_MP.VALOARE,  V_REC_MP.VALOARE, 0, V_REC_MP.PARTENER, 3, 400);
                    
            INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)        
                        VALUES(SEQ_STINGERE_CODSTINGERE.NEXTVAL, V_REC_MP.CODOBLIGPIF, aCODOBLIG_STINGATOR, V_REC_MP.VALOARE);
                        
            UPDATE OBLIGPIF
            SET
              REST = REST -  V_REC_MP.VALOARE
            WHERE
              CODOBLIGPIF = V_REC_MP.CODOBLIGPIF;              
                        
          END LOOP;                                  
             
  END LOOP;    

  BEGIN

  INSERT INTO IESIRIRETAIL(CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, TIPMODIF, AGENT, CARNETLIVR, NRLIVR)
  SELECT CODIESRETAIL, CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, NRDOC, DATADOC, CODPARTRETAIL, PARTENER, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, DELEGATRETAIL, DELEGAT, OBS, AN, LUNA, CODFISCALRETAIL, CODFISCAL, SERIADOC, CODSEDIURETAIL, CODLOCATIE, TIPTVA, SUBUNITATEA, MONEDA, CURS, USERID, DATACREARE, MIJLTRANSP, NRTRANSP, LISTAT, INFOCM, CURSDOC, NRI, FARATRANSPORT, TIPCHELT, EXCLUSPLATA, PROCTVADOC, DATATVA, TIPMODIF, AGENT, CARNETLIVR, NRLIVR
  FROM TMP_IESIRIRETAIL;


  
  INSERT INTO IESIRI1RETAIL(CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET, DISCMANUAL, CODUTILAJ, CODGEST, CODIOARTVAL, TVANEEX)
  SELECT CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET, DISCMANUAL, CODUTILAJ, CODGEST, CODIOARTVAL, TVANEEX
  FROM
    TMP_IESIRI1RETAIL;
    


    EXCEPTION WHEN OTHERS THEN
      NULL;
  END;  

  INSERT INTO TMP_IESIRIRETAIL_PREL --folosite pe restserver
  SELECT * FROM TMP_IESIRIRETAIL;
  INSERT INTO TMP_IESIRI1RETAIL_PREL
  SELECT * FROM TMP_IESIRI1RETAIL;


--  COMMIT;    
END;




PROCEDURE MUTA_CODIFICARI_PE_RETAIL
IS
 NR NUMBER(5);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_IESIRIRETAIL WHERE CODIES IS NOT NULL)
  LOOP
    SELECT COUNT(*) INTO NR 
    FROM 
      IESIRI 
    WHERE 
      CODIES = V_REC.CODIES;
      
    IF NR = 0 THEN
     INSERT INTO IESIRI(CODIES, 
                        TIPDOC, 
                        ANULAT, 
                        BLOCAT, 
                        OPERAT, 
                        PREFIXDOC, 
                        CARNETDOC, 
                        NRDOC, 
                        DATADOC, 
                        PARTENER, 
                        VALDOC, 
                        TVADOC, 
                        VALDISCOUNT, 
                        TVADISCOUNT, 
                        DELEGAT, 
                        OBS, 
                        AN, 
                        LUNA, 
                        CODFISCAL, 
                        SERIADOC, 
                        CODLOCATIE, 
                        TIPTVA, 
                        SUBUNITATEA, 
                        MONEDA, 
                        CURS, 
                        DATACREARE, 
                        MIJLTRANSP, 
                        NRTRANSP, 
                        LISTAT, 
                        INFOCM, 
                        CURSDOC, 
                        NRI, 
                        FARATRANSPORT, 
                        TIPCHELT, 
                        EXCLUSPLATA, 
                        PROCTVADOC, 
                        DATATVA,
                        AGENT,
                        TIPET,
                        IS_ETRANSP,
                        ROTEFACT
                        
                        )
                VALUES( V_REC.CODIES, 
                        V_REC.TIPDOC, 
                        V_REC.ANULAT, 
                        V_REC.BLOCAT, 
                        V_REC.OPERAT, 
                        V_REC.PREFIXDOC, 
                        V_REC.CARNETDOC, 
                        V_REC.NRDOC, 
                        V_REC.DATADOC, 
                        V_REC.PARTENER, 
                        V_REC.VALDOC, 
                        V_REC.TVADOC, 
                        V_REC.VALDISCOUNT, 
                        V_REC.TVADISCOUNT, 
                        V_REC.DELEGAT, 
                        V_REC.OBS, 
                        V_REC.AN, 
                        V_REC.LUNA, 
                        V_REC.CODFISCAL, 
                        V_REC.SERIADOC, 
                        V_REC.CODLOCATIE, 
                        V_REC.TIPTVA, 
                        V_REC.SUBUNITATEA, 
                        V_REC.MONEDA, 
                        V_REC.CURS, 
                        V_REC.DATACREARE, 
                        V_REC.MIJLTRANSP, 
                        V_REC.NRTRANSP, 
                        V_REC.LISTAT, 
                        V_REC.INFOCM, 
                        V_REC.CURSDOC, 
                        V_REC.NRI, 
                        V_REC.FARATRANSPORT, 
                        V_REC.TIPCHELT, 
                        V_REC.EXCLUSPLATA, 
                        V_REC.PROCTVADOC, 
                        V_REC.DATATVA,
                        V_REC.AGENT,
                        V_REC.TIPET,
                        V_REC.IS_ETRANSP,
                        V_REC.ROTEFACT
                        );
     
   ELSE
    UPDATE IESIRI
    SET
      (TIPDOC, 
       ANULAT, 
       BLOCAT, 
       OPERAT, 
       PREFIXDOC, 
       CARNETDOC, 
       NRDOC, 
       DATADOC, 
       PARTENER, 
       VALDOC, 
       TVADOC, 
       VALDISCOUNT, 
       TVADISCOUNT, 
       DELEGAT, 
       OBS, 
       AN, 
       LUNA, 
       CODFISCAL, 
       SERIADOC, 
       CODLOCATIE, 
       TIPTVA, 
       SUBUNITATEA, 
       MONEDA, 
       CURS, 
       DATACREARE, 
       MIJLTRANSP, 
       NRTRANSP, 
       LISTAT, 
       INFOCM, 
       CURSDOC, 
       NRI, 
       FARATRANSPORT, 
       TIPCHELT, 
       EXCLUSPLATA, 
       PROCTVADOC, 
       DATATVA,
       AGENT
       )
   = (SELECT 
       V_REC.TIPDOC, 
       V_REC.ANULAT, 
       V_REC.BLOCAT, 
       V_REC.OPERAT, 
       V_REC.PREFIXDOC, 
       V_REC.CARNETDOC, 
       V_REC.NRDOC, 
       V_REC.DATADOC, 
       V_REC.PARTENER, 
       V_REC.VALDOC, 
       V_REC.TVADOC, 
       V_REC.VALDISCOUNT, 
       V_REC.TVADISCOUNT, 
       V_REC.DELEGAT, 
       V_REC.OBS, 
       V_REC.AN, 
       V_REC.LUNA, 
       V_REC.CODFISCAL, 
       V_REC.SERIADOC, 
       V_REC.CODLOCATIE, 
       V_REC.TIPTVA, 
       V_REC.SUBUNITATEA, 
       V_REC.MONEDA, 
       V_REC.CURS, 
       V_REC.DATACREARE, 
       V_REC.MIJLTRANSP, 
       V_REC.NRTRANSP, 
       V_REC.LISTAT, 
       V_REC.INFOCM, 
       V_REC.CURSDOC, 
       V_REC.NRI, 
       V_REC.FARATRANSPORT, 
       V_REC.TIPCHELT, 
       V_REC.EXCLUSPLATA, 
       V_REC.PROCTVADOC, 
       V_REC.DATATVA,
       V_REC.AGENT
      FROM
        DUAL)
    WHERE
      CODIES = V_REC.CODIES;  
   END IF;       
    
    
   UPDATE IESIRIRETAIL
   SET
     CODIES   = V_REC.CODIES,
     TIPMODIF = NULL
   WHERE
     CODIESRETAIL = V_REC.CODIESRETAIL;


   UPDATE EMULARE
   SET
     CODIES   = V_REC.CODIES
   WHERE
     CODIESRETAIL = V_REC.CODIESRETAIL;
   
      
    DELETE IESIRI1 WHERE CODIES = V_REC.CODIES;   
    
    FOR V_REC_D IN (SELECT * FROM TMP_IESIRI1RETAIL WHERE CODIESRETAIL = V_REC.CODIESRETAIL)
    LOOP
        INSERT INTO IESIRI1(CODIES1, 
                            CODIES, 
                            INDEXLOCAL, 
                            TIPLINIE, 
                            UMSEC, 
                            CONTSERV, 
                            GESTACT, 
                            CODOBIECT, 
                            PRETORIG, 
                            PU, 
                            CANT, 
                            TVA, 
                            CONT, 
                            ADDIM, 
                            PROCDISC, 
                            RESTFACT, 
                            PUMAXIMAL, 
                            GARANTIE, 
                            COEFDISCMAJ, 
                            OBS, 
                            CONTDISCOUNT, 
                            CODCRITERIU, 
                            ZILE, 
                            CADOU, 
                            CODCADOU, 
                            TAXA, 
                            CODAGENTEMULARE, 
                            VALDISCPRET)
                  VALUES ((SELECT NVL(MAX(CODIES1), 0) FROM IESIRI1) + 1,--SEQ_IESIRI1_CODIES1.NEXTVAL,
                            V_REC.CODIES,  
                            V_REC_D.INDEXLOCAL, 
                            V_REC_D.TIPLINIE, 
                            V_REC_D.UMSEC, 
                            V_REC_D.CONTSERV, 
                            V_REC_D.GESTACT, 
                            V_REC_D.CODOBIECT, 
                            V_REC_D.PRETORIG, 
                            V_REC_D.PU, 
                            V_REC_D.CANT, 
                            V_REC_D.TVA, 
                            V_REC_D.CONT, 
                            V_REC_D.ADDIM, 
                            V_REC_D.PROCDISC, 
                            V_REC_D.RESTFACT, 
                            V_REC_D.PUMAXIMAL, 
                            V_REC_D.GARANTIE, 
                            V_REC_D.COEFDISCMAJ, 
                            V_REC_D.OBS, 
                            V_REC_D.CONTDISCOUNT, 
                            V_REC_D.CODCRITERIU, 
                            V_REC_D.ZILE, 
                            V_REC_D.CADOU, 
                            V_REC_D.CODCADOU, 
                            V_REC_D.TAXA, 
                            V_REC_D.CODAGENTEMULARE, 
                            V_REC_D.VALDISCPRET);
    END LOOP;    
        

   SELECT COUNT(*) INTO NR  FROM DETALIIET WHERE TIPDOC = 19 AND CODDOC = V_REC.CODIES;
   IF NR = 0 THEN 
       FOR V_REC_X IN (SELECT * FROM TMP_DETALIIET ET WHERE TIPDOC = -19 AND CODDOC = V_REC.CODIESRETAIL)
       LOOP
        INSERT INTO DETALIIET(CODDETALIU,
                              CODDOC, 
                              TIPDOC, 
                              CODLOCINC, 
                              ADRESAINC, 
                              DATATRANSPORT, 
                              CODLOCDESC, 
                              ADRESADESC, 
                              CODPTF, 
                              CODBV, 
                              CODPARTTR, 
                              NRAUTO, 
                              NRREMORCA1, 
                              NRREMORCA2 
                             )    
        VALUES (SEQ_DETALIIET_CODDETALIU.NEXTVAL,
                V_REC.CODIES, 
                19,                     
                V_REC_X.CODLOCINC, 
                V_REC_X.ADRESAINC, 
                V_REC_X.DATATRANSPORT, 
                V_REC_X.CODLOCDESC, 
                V_REC_X.ADRESADESC, 
                V_REC_X.CODPTF, 
                V_REC_X.CODBV, 
                V_REC_X.CODPARTTR, 
                V_REC_X.NRAUTO, 
                V_REC_X.NRREMORCA1, 
                V_REC_X.NRREMORCA2
               );  
       END LOOP;    
    END IF;   


   SELECT COUNT(*) INTO NR  FROM STATUSDECL WHERE TIPDOC = 119 AND CODDOC = V_REC.CODIES;
   IF NR = 0 THEN 
       FOR V_REC_X IN (SELECT * FROM TMP_STATUSDECL ET WHERE TIPDOC = -119 AND CODDOC = V_REC.CODIESRETAIL)
       LOOP
        INSERT INTO STATUSDECL(CODSTATUSDECL,
                               TIPDOC,
                               CODDOC,
                               IDINCARCARE,
                               IDDESCARCARE,
                               DATAINCARCARE,
                               STARE,
                               TIPMEDIU,
                               USERNAME,
                               AN,
                               LUNA,
                               COMPNAME,
                               FILENAME,
                               MESAJE,
                               CIF,
                               SERIE_CERTIF,
                               UIT
                             )    
        VALUES (SEQ_STATUSDECL.NEXTVAL,
                119,                     
                V_REC.CODIES,
                V_REC_X.IDINCARCARE,
                V_REC_X.IDDESCARCARE,
                V_REC_X.DATAINCARCARE,
                V_REC_X.STARE,
                V_REC_X.TIPMEDIU,
                V_REC_X.USERNAME,
                V_REC_X.AN,
                V_REC_X.LUNA,
                V_REC_X.COMPNAME,
                V_REC_X.FILENAME,
                V_REC_X.MESAJE,
                V_REC_X.CIF,
                V_REC_X.SERIE_CERTIF,
                V_REC_X.UIT
               );  

       END LOOP;    
    END IF;   




  END LOOP;    
  
  
  
--  COMMIT;
END;    

PROCEDURE MAKE_IESIRIRETAIL_FROM_IESIRI
IS
 NR NUMBER(5) := 0;
BEGIN
  MERGE INTO IESIRIRETAIL IR
  USING (SELECT 
           I.*, PR.CODPARTRETAIL,
           SR.CODSEDIU AS CODSEDIURETAIL,
           CFR.COD AS CODFISCALRETAIL
         FROM 
           IESIRI I 
           LEFT JOIN NSEDIIPARTRETAIL SR ON I.CODLOCATIE = SR.CODAGENDA
           LEFT JOIN NCODFISCRETAIL CFR ON I.CODFISCAL = CFR.COD_CODFISCAL,
           NPARTRETAIL PR 
         WHERE
           I.PARTENER = PR.CODPART
        ) I    
  ON ( I.CODIES = IR.CODIES)
  WHEN NOT MATCHED THEN
  INSERT (CODIESRETAIL, 
          CODIES, 
          TIPDOC, 
          ANULAT, 
          BLOCAT, 
          OPERAT, 
          PREFIXDOC, 
          CARNETDOC, 
          NRDOC, 
          DATADOC, 
          PARTENER, 
          CODPARTRETAIL,
          VALDOC, 
          TVADOC, 
          VALDISCOUNT, 
          TVADISCOUNT, 
          DELEGAT, 
          OBS, 
          AN, 
          LUNA, 
          CODFISCAL, 
          CODFISCALRETAIL, 
          SERIADOC, 
          CODLOCATIE, 
          CODSEDIURETAIL, 
          TIPTVA, 
          SUBUNITATEA, 
          MONEDA, 
          CURS, 
          USERID, 
          DATACREARE, 
          MIJLTRANSP, 
          NRTRANSP, 
          LISTAT, 
          INFOCM, 
          CURSDOC, 
          NRI, 
          FARATRANSPORT, 
          TIPCHELT, 
          EXCLUSPLATA, 
          PROCTVADOC, 
          DATATVA,
          AGENT
          )
   VALUES(SEQ_IESIRIR_CODIESR.NEXTVAL, 
          I.CODIES, 
          I.TIPDOC, 
          I.ANULAT, 
          I.BLOCAT, 
          I.OPERAT, 
          I.PREFIXDOC, 
          I.CARNETDOC, 
          I.NRDOC, 
          I.DATADOC, 
          I.PARTENER, 
          I.CODPARTRETAIL,
          I.VALDOC, 
          I.TVADOC, 
          I.VALDISCOUNT, 
          I.TVADISCOUNT, 
          I.DELEGAT, 
          I.OBS, 
          I.AN, 
          I.LUNA, 
          I.CODFISCAL, 
          I.CODFISCALRETAIL, 
          I.SERIADOC, 
          I.CODLOCATIE, 
          I.CODSEDIURETAIL, 
          I.TIPTVA, 
          I.SUBUNITATEA, 
          I.MONEDA, 
          I.CURS, 
          I.USERID, 
          I.DATACREARE, 
          I.MIJLTRANSP, 
          I.NRTRANSP, 
          I.LISTAT, 
          I.INFOCM, 
          I.CURSDOC, 
          I.NRI, 
          I.FARATRANSPORT, 
          I.TIPCHELT, 
          I.EXCLUSPLATA, 
          I.PROCTVADOC, 
          I.DATATVA,
          I.AGENT
         );
          
  FOR V_REC IN (SELECT * FROM IESIRIRETAIL WHERE NVL(CODIES, 0) &lt;&gt; 0)
  LOOP
    SELECT COUNT(*) INTO NR FROM IESIRI1RETAIL WHERE CODIESRETAIL = V_REC.CODIESRETAIL;
    IF NR = 0 THEN
       INSERT INTO IESIRI1RETAIL(CODIES1RETAIL, CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET)
              SELECT SEQ_IESIRI1R_CODIES1R.NEXTVAL, V_REC.CODIESRETAIL, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, CONT, ADDIM, PROCDISC, RESTFACT, PUMAXIMAL, GARANTIE, COEFDISCMAJ, OBS, CONTDISCOUNT, CODCRITERIU, ZILE, CADOU, CODCADOU, TAXA, CODAGENTEMULARE, VALDISCPRET FROM IESIRI1 WHERE CODIES = V_REC.CODIES;
    END IF;
    

   UPDATE EMULARE
   SET
     CODIESRETAIL = V_REC.CODIESRETAIL
   WHERE
     CODIES = V_REC.CODIES;  
  END LOOP;           
  COMMIT;
END;    

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
  TMP NUMBER(20);
BEGIN
  SELECT CODIESRETAIL INTO TMP FROM IESIRIRETAIL WHERE CODIESRETAIL = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
  ACARNETDOC NUMBER(20);
  ANRDOC     NUMBER(20);
  ACODIES    NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  SELECT
    CARNETDOC,
    NRDOC,
    NVL(CODIES,0)
  INTO
    ACARNETDOC,
    ANRDOC,
    ACODIES
  FROM
    IESIRIRETAIL
  WHERE CODIESRETAIL = RECID;
  
  IF ACODIES &gt; 0 THEN
    PKG_IESIRI.SP_DELETERECORD(ACODIES);
  END IF;
  
  DELETE FROM IESIRI1RETAIL  WHERE CODIESRETAIL = RECID;
  DELETE FROM MODPLATAIESRETAIL WHERE CODIESRETAIL = RECID;
  DELETE FROM IESIRIRETAIL   WHERE CODIESRETAIL = RECID;

  UPDATE EMULARE SET CODIESRETAIL = NULL WHERE CODIESRETAIL = RECID;

  PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
  
  NotifyModif(2, RecId, &apos;IESIRIRETAIL&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_IESIRIRETAIL FIELDS( CODIESRETAIL ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
aRotEFact      NUMBER(1);
BEGIN
  INSERT INTO TMP_IESIRIRETAIL(
    codiesretail,
    codies,
    tipdoc,
    anulat,
    blocat,         
    operat,         
    prefixdoc,      
    carnetdoc,      
    nrdoc,          
    datadoc,        
    codpartretail,  
    partener,       
    valdoc,         
    tvadoc,         
    valdiscount,    
    tvadiscount,    
    delegatretail,  
    delegat,        
    obs,            
    an,             
    luna,           
    codfiscalretail,
    codfiscal,      
    seriadoc,       
    codsediuretail, 
    codlocatie,     
    tiptva,         
    subunitatea,    
    moneda,         
    curs,           
    userid,         
    datacreare,     
    mijltransp,     
    nrtransp,       
    listat,         
    infocm,         
    cursdoc,        
    nri,            
    faratransport,  
    tipchelt,       
    exclusplata,    
    proctvadoc,     
    datatva,
    agent,
    CARNETLIVR, 
    NRLIVR,
    CODPARTCOMIS, 
    CODPARTRETAILCOMIS, 
    Is_ETRANSP, 
    TipET,  
    ROTEFACT,
    UIT, ET_IDINCARCARE, ET_IDDESCARCARE, ET_TIPMEDIU, ET_STATUS,
    PARTENERCOMUNITAR, SIMBAUTOTARA
    )
  SELECT
    i.CODIESRETAIL,   
    i.CODIES,         
    i.TIPDOC,         
    i.ANULAT,         
    i.BLOCAT,         
    i.OPERAT,         
    i.PREFIXDOC,      
    i.CARNETDOC,      
    i.NRDOC,          
    i.DATADOC,        
    i.CODPARTRETAIL,  
    i.PARTENER,       
    i.VALDOC,         
    i.TVADOC,         
    i.VALDISCOUNT,    
    i.TVADISCOUNT,    
    i.DELEGATRETAIL,  
    i.DELEGAT,        
    i.OBS,            
    i.AN,             
    i.LUNA,           
    i.CODFISCALRETAIL,
    i.CODFISCAL,      
    i.SERIADOC,       
    i.CODSEDIURETAIL, 
    i.CODLOCATIE,     
    i.TIPTVA,         
    i.SUBUNITATEA,    
    i.MONEDA,         
    i.CURS,           
    i.USERID,         
    i.DATACREARE,     
    i.MIJLTRANSP,     
    i.NRTRANSP,       
    i.LISTAT,         
    i.INFOCM,         
    i.CURSDOC,        
    i.NRI,            
    i.FARATRANSPORT,
    i.TIPCHELT,       
    i.EXCLUSPLATA,    
    i.PROCTVADOC,     
    i.DATATVA,
    i.agent,
    i.CARNETLIVR, 
    i.NRLIVR,
    i.CODPARTCOMIS, 
    i.CODPARTRETAILCOMIS,
		i.Is_ETRANSP, 
    i.TipET, 
    i.ROTEFACT,
    ET.UIT, ET.IDINCARCARE, ET.IDDESCARCARE, ET.TIPMEDIU, Coalesce(ET.STARE,&apos;?&apos;),
    T.STATCOMUNITAR, Coalesce(T.SIMBAUTO, &apos;RO&apos;)
  from 
    iesiriretail i 
    LEFT OUTER JOIN NSEDIIPARTRETAIL  A ON A.CODSEDIU = I.CODSEDIURETAIL
    LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT OUTER JOIN NTARI    T ON T.CODTARA    = L.CODTARA
    LEFT OUTER JOIN StatusDecl ET ON ET.CodDoc = I.CodIesRetail and ET.TipDoc = -119
  where 
    codiesretail = RecID;          
  
  
  BEGIN
    SELECT   COALESCE(RotEFact, 0) INTO   aRotEFact FROM TMP_IESIRIRETAIL;
    EXCEPTION WHEN OTHERS THEN aROTEfact := 0;
  END;

  

  DELETE IESIRI1_MAN;
  INSERT INTO IESIRI1_MAN 
    (
     CODIES1,  
     CODIES,   
     INDEXLOCAL,     
     TIPLINIE,       
     UMSEC,          
     CONTSERV,       
     GESTACT,        
     CODOBIECT,      
     PRETORIG,       
     PU,             
     CANT,           
     TVA,            
     CONT,           
     ADDIM,          
     PROCDISC,       
     RESTFACT,       
     PUMAXIMAL,      
     GARANTIE,       
     COEFDISCMAJ,    
     OBS,            
     CONTDISCOUNT,   
     CODCRITERIU,    
     ZILE,           
     CADOU,          
     CODCADOU,       
     TAXA,           
     CODAGENTEMULARE,
     VALDISCPRET,
     DISCMANUAL,
     CODCENTRU -- aici pun gestiune din codgest
     )
  SELECT 
    CODIES1RETAIL,  
    CODIESRETAIL,   
    INDEXLOCAL,     
    TIPLINIE,       
    UMSEC,          
    CONTSERV,       
    GESTACT,        
    CODOBIECT,      
    PRETORIG,       
    PU,             
    CANT,           
    TVA,            
    CONT,           
    ADDIM,          
    PROCDISC,       
    RESTFACT,       
    PUMAXIMAL,      
    GARANTIE,       
    COEFDISCMAJ,    
    OBS,            
    CONTDISCOUNT,   
    CODCRITERIU,    
    ZILE,           
    CADOU,          
    CODCADOU,       
    TAXA,           
    CODAGENTEMULARE,
    VALDISCPRET,
    DISCMANUAL,
    CODGEST
  FROM IESIRI1RETAIL WHERE CODIESRETAIL = RECID;

  INSERT INTO TMP_IESIRI1RETAIL (
    CODIES1RETAIL,  
    CODIESRETAIL,   
    INDEXLOCAL,     
    TIPLINIE,       
    UMSEC,          
    CONTSERV,       
    GESTACT,        
    CODOBIECT,      
    PRETORIG,       
    PU,             
    CANT,           
    TVA,            
    CONT,           
    ADDIM,          
    PROCDISC,       
    RESTFACT,       
    PUMAXIMAL,      
    GARANTIE,       
    COEFDISCMAJ,    
    OBS,            
    CONTDISCOUNT,   
    CODCRITERIU,    
    ZILE,           
    CADOU,          
    CODCADOU,       
    TAXA,           
    CODAGENTEMULARE,
    VALDISCPRET,
    DISCMANUAL,
    DENOBIECT,      
    DENUM,          
    VALOARE,        
    PARITATE,       
    PROCTVA,        
    CODACCIZE,      
    CODTAXA1,       
    CODTAXA2,       
    CODTVA,         
    ROTUNJIRE,      
    CODEXTERN,      
    CODINTERN,      
    PUREAL,
    CODGEST
    )
  SELECT
    I1.CODIES1,  
    I1.CODIES,   
    I1.INDEXLOCAL,     
    I1.TIPLINIE,       
    I1.UMSEC,          
    I1.CONTSERV,       
    I1.GESTACT,        
    I1.CODOBIECT,      
    I1.PRETORIG,       
    I1.PU,             
    I1.CANT,           
    I1.TVA,            
    I1.CONT,           
    I1.ADDIM,          
    I1.PROCDISC,       
    I1.RESTFACT,       
    I1.PUMAXIMAL,      
    I1.GARANTIE,       
    I1.COEFDISCMAJ,    
    I1.OBS,            
    I1.CONTDISCOUNT,   
    I1.CODCRITERIU,    
    I1.ZILE,           
    I1.CADOU,          
    I1.CODCADOU,       
    I1.TAXA,           
    I1.CODAGENTEMULARE,
    I1.VALDISCPRET,
    I1.DISCMANUAL,    
    O.DENUMIRE DENOBIECT,      
    CASE WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos; ELSE U1.DEN_UM1 END DENUM,          
    CASE WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN  
      CASE WHEN aROTEFACT = 1 THEN ROUND(I1.CANT * I1.PU, 2)
      ELSE I1.CANT * I1.PU 
      END ELSE I1.RESTFACT 
    END VALOARE,        
    NVL(U1.PARITATE,1) PARITATE,       
    CASE WHEN I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;, &apos;R&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU) ELSE 0 END PROCTVA,        
    NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, NART1LUNA.CODTVA, 
    O.ROTVALUTA ROTUNJIRE,      
    O.CODEXTERN,      
    O.CODINTERN,      
    CASE
      WHEN TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN NVL(I1.PRETORIG, 0) * NVL(I1.COEFDISCMAJ, 0) *  NVL(U1.PARITATE,1)
      ELSE NULL
    END PUREAL,
    I1.CODCENTRU
  FROM IESIRI1_MAN I1
       LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
       LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
       LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
       LEFT OUTER JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
  where i1.codies = RecID;

  UPDATE TMP_IESIRI1RETAIL I1
  SET
     DENOBIECT = CASE
                   WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;G&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount pe grupul de articole precedente&apos;
                   WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;G&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de grup)&apos;

                   WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;T&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount pe toate articole precedente&apos;
                   WHEN NVL(CODCRITERIU, 0) = 0 AND TIPLINIE = &apos;T&apos; AND CONTDISCOUNT &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de total)&apos;

                   WHEN NVL(CODCRITERIU, 0) = 2 AND TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &lt;=0 THEN &apos;Discount client &apos;
                   WHEN /* NVL(CODCRITERIU, 0)  IN  (3, 4, 5, 6, 7, 8, 9, 10) AND */ TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &lt;=0 THEN &apos;Discount: &apos; || NVL((SELECT DENCRITERIU FROM CRITERIIDISC WHERE CODCRITERIU = I1.CODCRITERIU), &apos;&apos;)
                   WHEN /* NVL(CODCRITERIU, 0)  IN  (3, 4, 5, 6, 7, 8, 9, 10) AND */ TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND CANT &gt; 0 THEN &apos;Majorare : &apos; || NVL((SELECT DENCRITERIU FROM CRITERIIDISC WHERE CODCRITERIU = I1.CODCRITERIU), &apos;&apos;)
                 END,

    SIMBOLCONTSERV =
                  CASE
                    WHEN CONTDISCOUNT &lt;&gt; 0 THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTDISCOUNT) || &apos;)&apos;
                   ELSE &apos;&apos;
                  END
  WHERE
    TIPLINIE IN (&apos;G&apos;, &apos;T&apos;);


  UPDATE TMP_IESIRI1RETAIL I1
  SET
    SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;
  WHERE
    TIPLINIE IN (&apos;S&apos;, &apos;V&apos;, &apos;R&apos;);
  

  INSERT INTO TMP_MODPLATAIESRETAIL SELECT * FROM MODPLATAIESRETAIL WHERE CODIESRETAIL = RECID;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
VCOD NUMBER(20);
ACARNET   INTEGER := 0;
ANUMARDOC INTEGER := 0;
NR NUMBER(10);
BEGIN
BEGIN
  SELECT
     TMP.CARNETDOC,
     TMP.NRDOC
  INTO
     ACARNET,
     ANUMARDOC
  FROM 
    TMP_IESIRIRETAIL TMP;
  
  UPDATE TMP_IESIRIRETAIL I
  SET
    PARTENER     = (SELECT CODPART        FROM NPARTRETAIL      WHERE CODPARTRETAIL = I.CODPARTRETAIL),
    CODPARTCOMIS = (SELECT CODPART        FROM NPARTRETAIL      WHERE CODPARTRETAIL = I.CODPARTRETAILCOMIS),
    CODLOCATIE   = (SELECT CODAGENDA      FROM NSEDIIPARTRETAIL WHERE CODSEDIU      = I.CODSEDIURETAIL),
    DELEGAT      = (SELECT CODPARTTR      FROM NDELEGATRETAIL   WHERE COD           = I.DELEGATRETAIL),
    CODFISCAL    = (SELECT COD_CODFISCAL  FROM NCODFISCRETAIL   WHERE COD           = I.CODFISCALRETAIL);
    
  
  IF OPERATION = 0 THEN  -- UPDATE
    -- MASTER IESIRI
    SELECT CODIESRETAIL INTO RECID FROM TMP_IESIRIRETAIL;

    UPDATE IESIRIRETAIL
    SET
     (
      codiesretail,codies,tipdoc,anulat,blocat,operat,prefixdoc,carnetdoc,nrdoc,datadoc,codpartretail,partener,valdoc,tvadoc,valdiscount,    
      tvadiscount,delegatretail,delegat,obs,an,luna,codfiscalretail,codfiscal,seriadoc,codsediuretail,codlocatie,tiptva,subunitatea,    
      moneda,curs,userid,datacreare,mijltransp,nrtransp,listat,infocm,cursdoc,nri,faratransport,tipchelt,exclusplata,proctvadoc,datatva,
      agent, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS, Is_ETransp, ROTEFACT, TipET
     ) =
     (SELECT RECID,codies,tipdoc,anulat,blocat,operat,prefixdoc,carnetdoc,nrdoc,datadoc,codpartretail,partener,valdoc,tvadoc,valdiscount,    
      tvadiscount,delegatretail,delegat,obs,an,luna,codfiscalretail,codfiscal,seriadoc,codsediuretail,codlocatie,tiptva,subunitatea,    
      moneda,curs,userid,datacreare,mijltransp,nrtransp,listat,infocm,cursdoc,nri,faratransport,tipchelt,exclusplata,proctvadoc,datatva,
      agent, CARNETLIVR, NRLIVR, CODPARTCOMIS, CODPARTRETAILCOMIS, Is_ETransp, ROTEFACT, TipET
      FROM TMP_IESIRIRETAIL
     )
    WHERE CODIESRETAIL = RECID;

    DELETE FROM IESIRI1RETAIL WHERE CODIESRETAIL = RECID AND CODIES1RETAIL NOT IN (SELECT CODIES1RETAIL FROM TMP_IESIRI1RETAIL);

    FOR V_REC IN (SELECT * FROM TMP_IESIRI1RETAIL  ORDER BY INDEXLOCAL) LOOP
      IF NVL(V_REC.CODIES1RETAIL, 0) &gt; 0 THEN
        UPDATE IESIRI1RETAIL SET
          INDEXLOCAL       = V_REC.INDEXLOCAL,                                                
          TIPLINIE         = V_REC.TIPLINIE,                                                    
          UMSEC            = V_REC.UMSEC,                                                          
          CONTSERV         = V_REC.CONTSERV,                                                    
          GESTACT          = V_REC.GESTACT,                                                      
          CODOBIECT        = V_REC.CODOBIECT,                                                  
          PRETORIG         = V_REC.PRETORIG  / NVL(V_REC.PARITATE, 1),                          
          PU               = V_REC.PU   / NVL(V_REC.PARITATE, 1),                                     
          CANT             = V_REC.CANT * NVL(V_REC.PARITATE, 1),                                   
          TVA              = V_REC.TVA,                                                              
          CONT             = V_REC.CONT,                                                            
          PROCDISC         = V_REC.PROCDISC,                                                       
          COEFDISCMAJ      = V_REC.COEFDISCMAJ,                                                 
          OBS              = V_REC.OBS,                                                         
          ADDIM            = V_REC.ADDIM,                                                    
          CADOU            = V_REC.CADOU,                                                            
          TAXA             = V_REC.TAXA,                                                    
          CODCADOU         = V_REC.CODCADOU,                                                 
          CODAGENTEMULARE  = V_REC.CODAGENTEMULARE,                                                
          VALDISCPRET      = V_REC.VALDISCPRET,
          CONTDISCOUNT     = V_REC.CONTDISCOUNT,
          CODCRITERIU      = V_REC.CODCRITERIU,
          ZILE             = V_REC.ZILE,
          DISCMANUAL       = V_REC.DISCMANUAL,
          CODGEST          = V_REC.CODGEST,
          CODIOARTVAL      = V_REC.CODIOARTVAL,
          TVANEEX          = V_REC.TVANEEX
        WHERE                                                                                       
          CODIES1RETAIL = V_REC.CODIES1RETAIL;                                                       
      ELSE                                                                               
        SELECT SEQ_IESIRI1R_CODIES1R.NEXTVAL INTO VCOD FROM DUAL;
        INSERT INTO IESIRI1RETAIL (
          CODIES1RETAIL,
          CODIESRETAIL,
          INDEXLOCAL,
          TIPLINIE,
          UMSEC,
          CONTSERV,
          GESTACT,
          CODOBIECT,
          PRETORIG,
          PU,
          CANT,
          TVA,
          CONT,
          PROCDISC,
          COEFDISCMAJ,
          OBS,
          ADDIM,
          CADOU,
          TAXA,
          CODCADOU,
          CODAGENTEMULARE,
          VALDISCPRET,
          CONTDISCOUNT,
          CODCRITERIU,
          ZILE,
          DISCMANUAL,
          CODGEST,  
          CODIOARTVAL,
          TVANEEX     
  
          )
        VALUES (
          VCOD,
          RECID,
          V_REC.INDEXLOCAL,                         
          V_REC.TIPLINIE,                           
          V_REC.UMSEC,                              
          V_REC.CONTSERV,                           
          V_REC.GESTACT,                            
          V_REC.CODOBIECT,                          
          V_REC.PRETORIG  / NVL(V_REC.PARITATE, 1), 
          V_REC.PU   / NVL(V_REC.PARITATE, 1),      
          V_REC.CANT * NVL(V_REC.PARITATE, 1),      
          V_REC.TVA,                                
          V_REC.CONT,                               
          V_REC.PROCDISC,                           
          V_REC.COEFDISCMAJ,                        
          V_REC.OBS,                                
          V_REC.ADDIM,                              
          V_REC.CADOU,                              
          V_REC.TAXA,                               
          V_REC.CODCADOU,                           
          V_REC.CODAGENTEMULARE,                    
          V_REC.VALDISCPRET,
          V_REC.CONTDISCOUNT,
          V_REC.CODCRITERIU,
          V_REC.ZILE,
          V_REC.DISCMANUAL,
          V_REC.CODGEST,
          V_REC.CODIOARTVAL,
          V_REC.TVANEEX     
          
          
          
          );

        UPDATE TMP_IESIRI1RETAIL SET CODIES1RETAIL = VCOD WHERE CODIES1RETAIL = V_REC.CODIES1RETAIL;
      END IF;
    END LOOP;
    
    DELETE FROM MODPLATAIESRETAIL WHERE CODIESRETAIL = RECID AND COD NOT IN (SELECT COD FROM TMP_MODPLATAIESRETAIL);
    
    FOR V_REC IN (SELECT * FROM TMP_MODPLATAIESRETAIL )
    LOOP
       IF V_REC.COD &gt; 0 THEN 
         UPDATE MODPLATAIESRETAIL
         SET
           CODBANKCONT = V_REC.CODBANKCONT,
           TIPPLATA    = V_REC.TIPPLATA,
           VALOARE     = V_REC.VALOARE,
           VOUCHERSGR  = V_REC.VOUCHERSGR
         WHERE
           COD = V_REC.COD;      
       ELSE
         INSERT INTO MODPLATAIESRETAIL(COD, CODIESRETAIL, TIPPLATA, VALOARE, CODBANKCONT, VOUCHERSGR)
         VALUES (SEQ_MODPLATAIESRETAIL_COD.NEXTVAL, RecID,  V_REC.TIPPLATA, V_REC.VALOARE, V_REC.CODBANKCONT, V_REC.VOUCHERSGR);
       END IF;    
    END LOOP;  
    
  ELSE  -- INSERT
-- MASTER IESIRI

  SELECT SEQ_IESIRIR_CODIESR.NEXTVAL INTO RECID FROM DUAL;

  INSERT INTO IESIRIRETAIL
   ( 
    codiesretail,
    codies,
    tipdoc,
    anulat,
    blocat,         
    operat,         
    prefixdoc,      
    carnetdoc,      
    nrdoc,          
    datadoc,        
    codpartretail,  
    partener,       
    valdoc,         
    tvadoc,         
    valdiscount,    
    tvadiscount,    
    delegatretail,  
    delegat,        
    obs,            
    an,             
    luna,           
    codfiscalretail,
    codfiscal,      
    seriadoc,       
    codsediuretail, 
    codlocatie,     
    tiptva,         
    subunitatea,    
    moneda,         
    curs,           
    userid,         
    datacreare,     
    mijltransp,     
    nrtransp,       
    listat,         
    infocm,         
    cursdoc,        
    nri,            
    faratransport,  
    tipchelt,       
    exclusplata,    
    proctvadoc,     
    datatva,
    agent,
    CARNETLIVR, 
    NRLIVR,
    CODPARTCOMIS, 
    CODPARTRETAILCOMIS,
    Is_ETransp, 
    ROTEFACT,
    TipET
    )
    SELECT 
      RECID,
      codies,
      tipdoc,
      anulat,
      blocat,         
      operat,         
      prefixdoc,      
      carnetdoc,      
      nrdoc,          
      datadoc,        
      codpartretail,  
      partener,       
      valdoc,         
      tvadoc,         
      valdiscount,    
      tvadiscount,    
      delegatretail,  
      delegat,        
      obs,            
      an,             
      luna,           
      codfiscalretail,
      codfiscal,      
      seriadoc,       
      codsediuretail, 
      codlocatie,     
      tiptva,         
      subunitatea,    
      moneda,         
      curs,           
      pkg_globals.USERID,         
      systimestamp,     
      mijltransp,     
      nrtransp,       
      listat,         
      infocm,         
      cursdoc,        
      nri,            
      faratransport,  
      tipchelt,       
      exclusplata,    
      proctvadoc,     
      datatva,
      agent,
      CARNETLIVR, 
      NRLIVR,
      CODPARTCOMIS, 
      CODPARTRETAILCOMIS,
      Is_ETransp, 
      ROTEFACT,
      TipET      
    FROM TMP_IESIRIRETAIL;
    
    INSERT INTO IESIRI1RETAIL (
          CODIES1RETAIL,
          CODIESRETAIL,
          INDEXLOCAL,
          TIPLINIE,
          UMSEC,
          CONTSERV,
          GESTACT,
          CODOBIECT,
          PRETORIG,
          PU,
          CANT,
          TVA,
          CONT,
          PROCDISC,
          COEFDISCMAJ,
          OBS,
          ADDIM,
          CADOU,
          TAXA,
          CODCADOU,
          CODAGENTEMULARE,
          VALDISCPRET,
          CONTDISCOUNT,
          CODCRITERIU,
          ZILE,
          DISCMANUAL,
          CODGEST,
          CODIOARTVAL,
          TVANEEX     
              
          )
        select
          SEQ_IESIRI1R_CODIES1R.NEXTVAL,
          RECID,
          INDEXLOCAL,                         
          TIPLINIE,                           
          UMSEC,                              
          CONTSERV,                           
          GESTACT,                            
          CODOBIECT,                          
          PRETORIG / NVL(PARITATE, 1), 
          PU / NVL(PARITATE, 1),      
          CANT * NVL(PARITATE, 1),      
          TVA,                                
          CONT,                               
          PROCDISC,                           
          COEFDISCMAJ,                        
          OBS,                                
          ADDIM,                              
          CADOU,                              
          TAXA,                               
          CODCADOU,                           
          CODAGENTEMULARE,                    
          VALDISCPRET,
          CONTDISCOUNT,
          CODCRITERIU,
          ZILE,
          DISCMANUAL,
          CODGEST,
          CODIOARTVAL,
          TVANEEX     
          
        from 
          tmp_iesiri1retail;  
          
          
         INSERT INTO MODPLATAIESRETAIL(COD, CODIESRETAIL, TIPPLATA, VALOARE, CODBANKCONT, VOUCHERSGR)
         SELECT SEQ_MODPLATAIESRETAIL_COD.NEXTVAL, RecID,  TIPPLATA, VALOARE, CODBANKCONT, VOUCHERSGR FROM TMP_MODPLATAIESRETAIL;
    
  END IF;

  IF CARNETDOC_I &lt;&gt; 0 AND
     NRDOC_I     &lt;&gt; 0 AND
     (ACARNET     &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
  THEN
    SELECT COUNT(*) INTO NR FROM DOCCARNETE WHERE CODCARNET = CARNETDOC_I;-- din preluari pot veni coduri aiurea
    IF NR &lt;&gt; 0 THEN
      PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
    END IF;
  END IF;
  PKG_CARNETEDOC.SOLVENUMARDOC(ACARNET, ANUMARDOC);


  NotifyModif(Operation, RecId, &apos;IESIRIRETAIL&apos;);


  COMMIT;
  EXCEPTION WHEN OTHERS THEN BEGIN
    ROLLBACK;
    RAISE;
  END;
END;
END;

end pkg_iesiriretail; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IMPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47105B58F89BF982C18E3AEC9FD44C77CAA1DDDB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_IMPORT IS

FUNCTION get_taracomunitara(pCodpart IN NUMBER) RETURN NUMBER IS
iResult NUMBER(1);
BEGIN
  SELECT ntari.statcomunitar INTO iResult
  FROM nagenda nag
    INNER JOIN nlocalit nloc ON nag.codlocalit = nloc.codlocalit
	  INNER JOIN ntari ON ntari.codtara = nloc.codtara
  WHERE nag.codpart = pCodPart AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(NAG.INACTIV, 0) = 0;
  RETURN iResult;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

PROCEDURE del_tabimpcod
IS
BEGIN
  DELETE FROM tabimpcod;
  COMMIT;
END;

FUNCTION GET_NEW_TARA(p_den VARCHAR2, p_simbauto VARCHAR2, p_comunitarue varchar2) RETURN VARCHAR2
IS
  sRet VARCHAR2(20);
  iCod NUMBER(20);
BEGIN
  sRet := &apos;-1&apos;;
  for rec_cursor in (select CodTara from NTARI where trim(upper(p_den)) = trim(upper(Den_Tara)) and trim(upper(p_simbauto)) = trim(upper(SimbAuto)) ) loop --and p_comunitarue = to_char(StatComunitar)
    sRet := to_char(rec_cursor.CodTara);
  end loop;
  if sRet = &apos;-1&apos; then
    Select max(CodTara) + 1 into iCod From NTARI;
    Insert into NTARI (CODTARA, DEN_TARA, SIMBAUTO,CODMONEDA,STATCOMUNITAR) values (iCod, p_den, p_simbauto, 0, to_number(p_comunitarue));
    COMMIT;
    sRet := to_char(iCod);
  end if;

  return sRet;
END;

FUNCTION GET_NEW_ZONA(p_den VARCHAR2, p_simb VARCHAR2, p_obs varchar2) RETURN VARCHAR2
IS
  sRet VARCHAR2(20);
  iCod NUMBER(20);
BEGIN
  sRet := &apos;-1&apos;;
  for rec_cursor in (select CodZona from NZONE where trim(upper(p_den)) = trim(upper(Den_Zona)) and trim(upper(p_simb)) = trim(upper(Simbol)) ) loop --and p_comunitarue = to_char(StatComunitar)
    sRet := to_char(rec_cursor.CodZona);
  end loop;
  if sRet = &apos;-1&apos; then
    Select max(CodZona) into iCod From NZONE;
    if iCod &lt;= 100 then
      iCod := 101;
    else
      iCod := iCod + 1;
    end if;
    Insert into NZONE (CODZONA, DEN_ZONA, SIMBOL,OBS) values (iCod, p_den, p_simb, p_obs);
    COMMIT;
    sRet := to_char(iCod);
  end if;

  return sRet;
END;
FUNCTION GET_NEW_LOCALIT(p_den VARCHAR2, p_jud VARCHAR2, p_tara varchar2, p_siruta varchar2, p_zona varchar2) RETURN VARCHAR2
IS
  sRet VARCHAR2(20);
  iCod NUMBER(20) := -1;
  iCodTara NUMBER(20) := -1;
  iCodJudet NUMBER(20) := -1;
  iCodZona NUMBER(20) := -1;
BEGIN
  sRet := &apos;-1&apos;;
    for rec_tari in (select CodTara from NTARI t where upper(t.simbauto) = upper(trim(p_tara))) loop
      iCodTara := rec_tari.codtara;
      exit when iCodTara &lt;&gt; -1 ;
    end loop;
    if iCodTara = -1 then
      select max(CodTara) + 1 into iCodTara from ntari;
      insert into NTARI(CODTARA,DEN_TARA,SIMBAUTO,CODMONEDA) values ( iCodTara, p_tara, p_tara,0);
      commit;
   end if;
    for rec_jud in (select CodJudet from NJUDET j where upper(j.simbauto) = upper(trim(p_jud)) )  loop
      iCodJudet := rec_jud.codjudet;
      exit when iCodJudet &lt;&gt; -1;
    end loop;
    if iCodJudet = -1 then
      select max(CodJudet) + 1 into iCodJudet from njudet;
      insert into NJUDET(CODJUDET,DEN_JUDET,SIMBAUTO,CODTARA) values ( iCodJudet, p_jud, p_jud, iCodTara);
      commit;
   end if;

  if length(trim(p_zona)) &lt;&gt; 0 then
    for rec_zona in (select CodZona from NZONE z where trim(upper(z.den_zona)) = upper(trim(p_zona)) )  loop
      iCodZona := rec_zona.codzona;
      exit when iCodZona &lt;&gt; -1;
    end loop;
  end if;

  for rec_localit in (select CodLocalit from NLOCALIT l
                    where trim(upper(p_den)) = trim(upper(l.Den_Localit)) and l.codjudet = iCodJudet
                    ) loop -- and  to_char(l.siruta) = p_siruta  and p_comunitarue = to_char(StatComunitar)
    sRet := to_char(rec_localit.CodLocalit);
  end loop;
  if sRet = &apos;-1&apos; then
    Select max(CodLocalit) + 1 into iCod From NLOCALIT;
    Insert into NLOCALIT (CODLOCALIT, DEN_LOCALIT, SIRUTA, CODJUDET,CODTARA, CODZONA) values (iCod, p_den, p_siruta,decode(iCodJudet,-1,null,iCodJudet), decode(iCodTara,-1,null, iCodTara), decode(iCodZona,-1,null,iCodZona));
    COMMIT;
    sRet := to_char(iCod);
  end if;

  return sRet;
END;
/*FUNCTION GET_NEW_LOCALIT(p_den VARCHAR2, p_jud VARCHAR2, p_tara varchar2, p_siruta varchar2) RETURN VARCHAR2
IS
  sRet VARCHAR2(20);
  iCod NUMBER(20) := -1;
  iCodTara NUMBER(20) := -1;
  iCodJudet NUMBER(20) := -1;
BEGIN
  sRet := &apos;-1&apos;;
    for rec_tari in (select CodTara from NTARI t where upper(t.simbauto) = upper(trim(p_tara))) loop
      iCodTara := rec_tari.codtara;
      exit when iCodTara &lt;&gt; -1 ;
    end loop;
    if iCodTara = -1 then
      select max(CodTara) + 1 into iCodTara from ntari;
      insert into NTARI(CODTARA,DEN_TARA,SIMBAUTO,CODMONEDA) values ( iCodTara, p_tara, p_tara,0);
      commit;
   end if;
    for rec_jud in (select CodJudet from NJUDET j where upper(j.simbauto) = upper(trim(p_jud)) )  loop
      iCodJudet := rec_jud.codjudet;
      exit when iCodJudet &lt;&gt; -1;
    end loop;
    if iCodJudet = -1 then
      select max(CodJudet) + 1 into iCodJudet from njudet;
      insert into NJUDET(CODJUDET,DEN_JUDET,SIMBAUTO,CODTARA) values ( iCodJudet, p_jud, p_jud, iCodTara);
      commit;
   end if;
  for rec_localit in (select CodLocalit from NLOCALIT l
                    where trim(upper(p_den)) = trim(upper(l.Den_Localit)) and l.codjudet = iCodJudet
                    ) loop -- and  to_char(l.siruta) = p_siruta  and p_comunitarue = to_char(StatComunitar)
    sRet := to_char(rec_localit.CodLocalit);
  end loop;
  if sRet = &apos;-1&apos; then
    Select max(CodLocalit) + 1 into iCod From NLOCALIT;
    Insert into NLOCALIT (CODLOCALIT, DEN_LOCALIT, SIRUTA, CODJUDET,CODTARA) values (iCod, p_den, p_siruta,decode(iCodJudet,-1,null,iCodJudet), decode(iCodTara,-1,null, iCodTara));
    COMMIT;
    sRet := to_char(iCod);
  end if;

  return sRet;
END;  */

PROCEDURE make_sold_part_ini IS
iLunaPrec NUMBER(2);
iAnPrec NUMBER(4);
iLunaTemp NUMBER(2);
iAnTemp NUMBER(4);
iLunaIni NUMBER(2);
iAnIni NUMBER(4);

BEGIN

  SELECT t.aninitial,t.lunainitiala INTO iAnIni,iLunaIni FROM firmaluni t;

  IF iLunaIni = 1 THEN
    iLunaTemp := 12;
	  iAnTemp := iAnIni - 1;
  ELSE
    iLunaTemp := iLunaIni - 1;
	  iAnTemp := iAnIni;
  END IF;

  IF iLunaTemp = 1 THEN
    iLunaPrec := 12;
	  iAnPrec := iAnTemp - 1;
  ELSE
    iLunaPrec := iLunaTemp - 1;
	  iAnPrec := iAnTemp;
  END IF;

  pkg_globals.SetLunaTemp(iAnTemp,iLunaTemp);
  pkg_globals.SetLunaPRECEDENTA(iAnPrec,iLunaPrec);
  PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(0);

  INSERT INTO npartsoldluna(codpartsoldluna,codpart,icont,codmoneda,soldlei,soldvaluta,an,luna)
  SELECT seq_npartsoldluna_codsoldluna.nextval,v.CODPART,v.ICONT,v.CODMONEDA,v.SOLDLEI,v.SOLDVALUTA, iAnTemp,iLunaTemp
	FROM v_soldpart v;

  FOR v_rec IN (SELECT 	DISTINCT codpart FROM npartsoldluna ) LOOP
    INSERT INTO soldini(codsoldini,codpart) VALUES(seq_soldini_codsoldini.NEXTVAL,v_rec.codpart);
  END LOOP;

  INSERT INTO obligpifluna
  SELECT o.codobligpif, iAnTemp as an, iLunaTemp as luna, sum(o.rest) as rest, sum(Coalesce(g.tva, 0)) as resttva, Sum(Coalesce(o.dincaretva, 0)) AS dincaretva
  FROM obligpif o, GENERAL G
  WHERE G.CODGENERAL = O.CODGENERAL
  GROUP BY o.codobligpif;

  COMMIT;
END;

PROCEDURE make_stocini IS
iLunaPrec NUMBER(2);
iAnPrec NUMBER(4);
iLunaIni NUMBER(2);
iAnIni NUMBER(4);

BEGIN

  SELECT t.aninitial,t.lunainitiala INTO iAnIni,iLunaIni FROM firmaluni t;

  IF iLunaIni = 1 THEN
    iLunaPrec := 12;
	  iAnPrec := iAnIni - 1;
  ELSE
    iLunaPrec := iLunaIni - 1;
	  iAnPrec := iAnIni;
  END IF;

  INSERT INTO nirluna(codnirstoc,an,luna,rest)
      SELECT codnirstoc, iAnPrec, iLunaPrec , rest FROM nirstoc;

  FOR v_rec IN (SELECT 	DISTINCT gest FROM nir ) LOOP
    INSERT INTO stocini(codstocini,codgest) VALUES(seq_stocini_codstocini.NEXTVAL,v_rec.gest);
  END LOOP;

  INSERT INTO nirserluna
  SELECT n.codnirser, n.codnirstoc, iAnPrec as an, iLunaPrec as luna, sum(rest) as rest, sum(restum1) as restum1, sum(restum2) as restum2 from nirser n group by n.codnirser, n.codnirstoc;

  COMMIT;
END;
/*
execute pkg_globals.setlunaprecedenta(2008, 11);
execute pkg_globals.setlunaTEMP(2008, 12);
execute PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(0);
select * from v_soldpart;
INSERT INTO npartsoldluna(codpartsoldluna,codpart,icont,codmoneda,soldlei,soldvaluta,an,luna)
  SELECT seq_npartsoldluna_codsoldluna.nextval,v.CODPART,v.ICONT,v.CODMONEDA,v.SOLDLEI,v.SOLDVALUTA,2008,12
	  FROM v_soldpart v
*/

end PKG_IMPORT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IMPORTALTEAPLICATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42E8E00C33568221A3451F248B0FEB4E2AF8C415</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_IMPORTALTEAPLICATII IS


PROCEDURE POST_JURNAL_CHELTAVANS
 IS 
 NR NUMBER;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_JURNAL)
  LOOP
    DELETE FROM JURNAL WHERE CODDOC = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
  END LOOP;    

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1)
  LOOP
    DELETE FROM JURNAL1 WHERE CODDOC = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
  END LOOP;    

 FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET
      CODDOC       = V_REC.CODDOC,
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,

      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,

      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      CODCENTRU     = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT,
      DIRTY         = V_REC.DIRTY
    WHERE
      CODJURNAL1 = V_REC.CODJURNAL1;
   ELSE
     INSERT INTO JURNAL1
     (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
      CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD,
      ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,
      TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
      DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,
      DATADOC, DOCUMENT )
     VALUES
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,
      V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD,
      V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,
      V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
      V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA,
      V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD,
      V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;
  
  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
   IF V_REC.CODJURNAL &gt; 0 THEN
    UPDATE JURNAL
    SET
      CODDOC     = V_REC.CODDOC,
      TIPDOC     = V_REC.TIPDOC,
      INDEXLOCAL = V_REC.INDEXLOCAL,
      CONTD      = V_REC.CONTD,
      CONTC      = V_REC.CONTC,
      GEST       = V_REC.GEST,
      VALOARE    = V_REC.VALOARE,
      VALOAREV   = V_REC.VALOAREV,
      OBS        = V_REC.OBS,
      AN         = V_REC.AN,
      LUNA       = V_REC.LUNA,
      SUBUNITATEA= V_REC.SUBUNITATEA,
      CODCENTRU  = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD,
      DATADOC    = V_REC.DATADOC,
      DOCUMENT   = V_REC.DOCUMENT
    WHERE
      CODJURNAL = V_REC.CODJURNAL;
   ELSE
   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA,
   CODCENTRU, CODANALIZANOD,
   DATADOC, DOCUMENT)
   VALUES
   ( SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA,
   V_REC.CODCENTRU, V_REC.CODANALIZANOD,
   V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;

-- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
    WHERE
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;
  END LOOP;
 
  COMMIT;

END;  
  


PROCEDURE PREPARE_JURNAL_CHELTAVANS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) -- folosit la import de intrari/iesiri cand se genereaza automat cheltuieli in avans care trebuiesc contabilizate
IS
BEGIN
  DELETE FROM TMP_CHELTAVANS;
  DELETE FROM TMP_CHELTAVANS1;
  DELETE FROM TMP_JURNAL;
  DELETE FROM TMP_JURNAL1;
  DELETE FROM TMP_RULAJ;
  
  IF aTIPDOC &lt; 19 THEN
    FOR V_REC IN (SELECT 
                   AV.CODCHELTAVANS,
                   AV.CODINTR1,
                   AV.CODOBLIGPIF,
                   AV.CODNC1,
                   AV.ANINCEPUT,
                   AV.LUNAINCEPUT,
                   AV.CODIOART,
                   G.CODGEST,
                   G.DEN_GEST,
                   I.SUBUNITATEA,
                   I.NRDOC,
                   P.DEN_PART,
                   I1.OBS,
                   I.PREFIXDOC,
                   I.SERIADOC,
                   AV.DATASTART,
                   AV.DATAEND, 
                   AV.IsVenit
                  FROM
                    INTRARI I
                    INNER JOIN NPART P ON P.CODPART = I.PARTENER
                    INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
                    LEFT  JOIN NGEST G ON G.CODGEST = I1.GESTACT
                    INNER JOIN CHELTAVANS AV ON AV.CODINTR1 = I1.CODINTR1
                  WHERE
                    I.CODINTR = aCODDOC
                  ) 
    LOOP
      INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS,CODINTR1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC,  DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, IsVenit )
                          VALUES(V_REC.CODCHELTAVANS, V_REC.CODINTR1, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT, V_REC.CODIOART, V_REC.CODGEST, V_REC.DEN_GEST, V_REC.SUBUNITATEA, V_REC.NRDOC,  V_REC.DEN_PART, V_REC.OBS, V_REC.PREFIXDOC, V_REC.SERIADOC, V_REC.DATASTART, V_REC.DATAEND, 0, V_REC.IsVenit );
    END LOOP;                  
  ELSE
    FOR V_REC IN (SELECT 
                   AV.CODCHELTAVANS,
                   AV.CODIES1,
                   AV.CODOBLIGPIF,
                   AV.CODNC1,
                   AV.ANINCEPUT,
                   AV.LUNAINCEPUT,
                   AV.CODIOART,
                   G.CODGEST,
                   G.DEN_GEST,
                   I.SUBUNITATEA,
                   I.NRDOC,
                   P.DEN_PART,
                   I1.OBS,
                   I.PREFIXDOC,
                   I.SERIADOC,
                   AV.DATASTART,
                   AV.DATAEND, 
                   AV.IsVenit
                  FROM
                    IESIRI I
                    INNER JOIN NPART P ON P.CODPART = I.PARTENER
                    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
                    LEFT  JOIN NGEST G ON G.CODGEST = I1.GESTACT
                    INNER JOIN CHELTAVANS AV ON AV.CODIES1 = I1.CODIES1
                  WHERE
                    I.CODIES = aCODDOC
                  ) 
    LOOP
      INSERT INTO TMP_CHELTAVANS(CODCHELTAVANS,CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, CODGEST, DEN_GEST, CODSUBUNIT, NRDOC,  DEN_PART, OBS, PREFIXDOC, SERIADOC, DATASTART, DATAEND, TIPINTERVAL, IsVenit )
                          VALUES(V_REC.CODCHELTAVANS, V_REC.CODIES1, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT, V_REC.CODIOART, V_REC.CODGEST, V_REC.DEN_GEST, V_REC.SUBUNITATEA, V_REC.NRDOC,  V_REC.DEN_PART, V_REC.OBS, V_REC.PREFIXDOC, V_REC.SERIADOC, V_REC.DATASTART, V_REC.DATAEND, 0, V_REC.IsVenit );
    END LOOP;                  
  END IF;
  

  
   INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA)
   SELECT CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA FROM CHELTAVANS1 AV1
   WHERE
     EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);


    UPDATE TMP_CHELTAVANS C
    SET
      TIPINTERVAL = 1
    WHERE
      DATASTART IS NOT NULL
      AND
    (
      DATAEND IS NOT NULL
      OR (SELECT COUNT(*) FROM TMP_CHELTAVANS1 C1 WHERE C1.CODCHELTAVANS = C.CODCHELTAVANS AND DATAENDNOUA IS NOT NULL) &gt; 0
    );

    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1)
    LOOP
      IF V_REC.DATAENDNOUA IS NOT NULL THEN
        UPDATE TMP_CHELTAVANS
        SET
          DATAEND = V_REC.DATAENDNOUA
        WHERE
          CODCHELTAVANS = V_REC.CODCHELTAVANS;
      END IF;
    END LOOP;




   COMMIT;
  
  
END;    

PROCEDURE IMPORTA_VENITAVANS
IS
  aCODCHELTAVANS NUMBER(20, 0);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS)
  LOOP
    IF V_REC.CODINTR1 IS NOT NULL THEN
      DELETE FROM MASTERCHELTAVANS WHERE CODINTR1= V_REC.CODINTR1;
    ELSE  
    IF V_REC.CODIES1 IS NOT NULL THEN
      DELETE FROM MASTERCHELTAVANS WHERE CODIES1= V_REC.CODIES1;
    END IF;  
    END IF;
  END LOOP;    



  INSERT INTO MASTERCHELTAVANS SELECT * FROM TMP_MASTERCHELTAVANS;
  FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS)
  LOOP
    aCODCHELTAVANS := SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL;
    UPDATE TMP_CHELTAVANS1
    SET
      CODCHELTAVANS = aCODCHELTAVANS
    WHERE
      CODCHELTAVANS = V_REC.CODCHELTAVANS;  
      
    UPDATE TMP_CHELTAVANS
    SET
      CODCHELTAVANS = aCODCHELTAVANS
    WHERE
      CODCHELTAVANS = V_REC.CODCHELTAVANS;  
      
     INSERT INTO CHELTAVANS(CODCHELTAVANS, ANINCEPUT, LUNAINCEPUT, CODIOART,DATASTART, DATAEND, CODIES1, CODINTR1, ISVENIT, OBSERVATII)
     VALUES (aCODCHELTAVANS, V_REC.ANINCEPUT, V_REC.LUNAINCEPUT, V_REC.CODIOART, V_REC.DATASTART, V_REC.DATAEND, V_REC.CODIES1, V_REC.CODINTR1, V_REC.ISVENIT, V_REC.OBSERVATII);

      
  END LOOP;
  
  FOR V_REC IN (SELECT C1.*, C.ISVENIT FROM TMP_CHELTAVANS1 C1 INNER JOIN TMP_CHELTAVANS C ON C.CODCHELTAVANS = C1.CODCHELTAVANS)
  LOOP
    INSERT INTO CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU)
                VALUES(SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, V_REC.CODCHELTAVANS, V_REC.VALOARE, V_REC.DURATAN, V_REC.DURATAF, V_REC.DFBLOCAT, V_REC.ANSTART, V_REC.LUNASTART, V_REC.AMO, V_REC.CODCENTRU);   


    IF V_REC.ANSTART = PKG_GLOBALS.GetANLUCRU AND V_REC.LUNASTART = PKG_GLOBALS.GetLUNALUCRU  THEN
      INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, ContD, Contc)
      VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL,  V_REC.CODCHELTAVANS, CASE WHEN COALESCE(V_REC.ISVENIT, 0) = 1 THEN 106 ELSE 52 END,  V_REC.CODCHELTAVANS, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 0, 0);

      INSERT INTO JURNAL1(CODJURNAL1, CODDOC, INDEXLOCAL, TIPDOC, AN, LUNA, DIRTY)
      VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL,  V_REC.CODCHELTAVANS,  V_REC.CODCHELTAVANS, CASE WHEN COALESCE(V_REC.ISVENIT, 0) = 1 THEN 106 ELSE 52 END, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 1);
    END IF; 



  END LOOP;    
  COMMIT;
END;    

PROCEDURE UPDATE_INFO_LAPARTENER(aCODOBIECT IN NUMBER, aCODPART IN NUMBER, aCODLACLIENT IN VARCHAR2, aDENLACLIENT IN VARCHAR2)
IS
aCODARTCLI NUMBER := 0;
BEGIN
  BEGIN
    SELECT CODARTCLI INTO aCODARTCLI FROM NARTCLI
    WHERE
      CODOBIECT = aCODOBIECT
      AND CODPART = aCODPART;
      
    EXCEPTION WHEN OTHERS THEN aCODARTCLI := 0;  
  END;  
  
  IF COALESCE(aCODARTCLI, 0) = 0 THEN
    aCODARTCLI := SEQ_NARTCLI_CODARTCLI.NEXTVAL;
    INSERT INTO NARTCLI(CODARTCLI, CODOBIECT, CODPART)
    VALUES (aCODARTCLI, aCODOBIECT, aCODPART);
  END IF;   
  
  IF COALESCE(aCODLACLIENT, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    UPDATE NARTCLI
    SET
      CODLACLIENT = aCODLACLIENT
    WHERE
      CODARTCLI = aCODARTCLI;
  END IF;      
  
  IF COALESCE(aDENLACLIENT, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    UPDATE NARTCLI
    SET
      DENUMIRE = aDENLACLIENT
    WHERE
      CODARTCLI = aCODARTCLI;
  END IF;      
  COMMIT;
END;     

PROCEDURE ADAUGA_NPERS
IS
  aCODAGENDA  NUMBER;
  aCODFUNCTIE NUMBER;
  aCODPERS    NUMBER;
  NR          NUMBER;
BEGIN
  -- START PERSOANE NOI --
  FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE CODAGENDA &lt; 0)
  LOOP
    aCODAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;

    INSERT INTO NAGENDA(CODAGENDA, CODLOCALIT, STRADA, NR1, NR2, APART, BLOC, SCARA, SECTOR, CODPOSTAL)
    VALUES(aCODAGENDA, V_REC.CODLOCALIT, V_REC.STRADA, V_REC.NR1, V_REC.NR2, V_REC.APART, V_REC.BLOC, V_REC.SCARA, V_REC.SECTOR, V_REC.CODPOSTAL);
    UPDATE TMP_NPERS
    SET
      AGENDA = aCODAGENDA
    WHERE
      AGENDA = V_REC.CODAGENDA;  
    
  END LOOP;     
  
  FOR V_REC IN
  (SELECT * FROM TMP_FUNCTII WHERE CODFUNCTIE &lt; 0)
  LOOP
     aCODFUNCTIE := SEQ_FUNCTII_CODFUNCTIE.NEXTVAL;
     INSERT INTO FUNCTII(CODFUNCTIE, DENUMIRE) VALUES (aCODFUNCTIE, V_REC.DENUMIRE);
     UPDATE TMP_NPERS1
     SET
       CODFUNCTIE = aCODFUNCTIE
     WHERE
       CODFUNCTIE = V_REC.CODFUNCTIE;

   END LOOP;

   FOR V_REC IN (SELECT * FROM TMP_NPERS WHERE CODPERS &lt; 0)
   LOOP
      aCODPERS := SEQ_NPERS_CODPERS.NEXTVAL;
      update TMP_NPERS1
      SET
        CODPERS = aCODPERS
      WHERE
        CODPERS = V_REC.CODPERS;

     INSERT INTO NPERS(CODPERS, MARCA, NUME, PRENUME, CNP, DATAN, ACTIV,DATAPLECARII, DATAANGAJARII, BISeria, BINR, BIEliberatDe, LaDataDe, AGENDA)
                VALUES (aCODPERS, V_REC.MARCA, V_REC.NUME, V_REC.PRENUME, V_REC.CNP, V_REC.DATAN, V_REC.ACTIV, V_REC.DATAPLECARII, V_REC.DATAANGAJARII, V_REC.BISeria, V_REC.BINR, V_REC.BIEliberatDe, V_REC.LaDataDe, V_REC.AGENDA);

   END LOOP;

   FOR V_REC IN (SELECT * FROM TMP_NPERS1 WHERE CODPERS1 &lt; 0)
   LOOP
     INSERT INTO NPERS1(CODPERS1, CODPERS, ANSTART, LUNASTART, CODFUNCTIE, ALSTART, ALSTOP)
     VALUES (SEQ_NPERS1_CODPERS1.NEXTVAL, V_REC.CODPERS, V_REC.ANSTART, V_REC.LUNASTART, V_REC.CODFUNCTIE, V_REC.ALSTART, V_REC.ALSTOP);
   END LOOP;
   -- END PERSOANE NOI --
   
   -- START UPDATE PERSOANE EXISTENTE --
   FOR V_REC IN (SELECT * FROM TMP_NPERS WHERE CODPERS &gt; 0)
   LOOP
     UPDATE NPERS
     SET
       BISeria      = CASE 
                        WHEN V_REC.BISERIA IS NOT NULL THEN V_REC.BISERIA
                        ELSE BISERIA
                      END,      
       BINR         = CASE 
                        WHEN V_REC.BINR IS NOT NULL THEN V_REC.BINR
                        ELSE BINR
                      END,      
       BIEliberatDE = CASE 
                        WHEN V_REC.BIEliberatDE IS NOT NULL THEN V_REC.BIEliberatDE
                        ELSE BIEliberatDE
                      END,      
       LaDataDE     = CASE 
                        WHEN V_REC.LaDataDE IS NOT NULL THEN V_REC.LaDataDE
                        ELSE LaDataDE
                      END      
     WHERE
       CODPERS = V_REC.CODPERS;
   END LOOP;    
   
   -- END UPDATE PERSOANE EXISTENTE --
   
   FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE CODAGENDA &gt; 0)
   LOOP
     SELECT COUNT(*) INTO NR FROM NAGENDA WHERE CODAGENDA = V_REC.CODAGENDA;
     IF NR = 0 THEN -- INCOERENTE NPERS-NAGENDA
       INSERT INTO NAGENDA (CODAGENDA) VALUES(V_REC.CODAGENDA);
     END IF;  
     
     UPDATE NAGENDA
     SET
       CODLOCALIT  = CASE 
                        WHEN V_REC.CODLOCALIT IS NOT NULL THEN V_REC.CODLOCALIT
                        ELSE CODLOCALIT
                     END,      
       EMAIL       = CASE 
                        WHEN V_REC.EMAIL IS NOT NULL THEN V_REC.EMAIL
                        ELSE EMAIL
                     END,      
       NR1         = CASE 
                        WHEN V_REC.NR1 IS NOT NULL THEN V_REC.NR1
                        ELSE NR1
                     END,      
       NR2         = CASE 
                        WHEN V_REC.NR2 IS NOT NULL THEN V_REC.NR2
                        ELSE NR2
                     END,        
       APART        = CASE 
                        WHEN V_REC.APART IS NOT NULL THEN V_REC.APART
                        ELSE APART
                      END,                          
       ETAJ        =  CASE 
                        WHEN V_REC.ETAJ IS NOT NULL THEN V_REC.ETAJ
                        ELSE ETAJ
                      END,                          
       BLOC        =  CASE 
                        WHEN V_REC.BLOC IS NOT NULL THEN V_REC.BLOC
                        ELSE BLOC
                      END,                          
                       
       SCARA        = CASE 
                        WHEN V_REC.SCARA IS NOT NULL THEN V_REC.SCARA
                        ELSE SCARA
                      END,                          
       SECTOR       = CASE 
                        WHEN V_REC.SECTOR IS NOT NULL THEN V_REC.SECTOR
                        ELSE SECTOR
                      END,           
       CODPOSTAL    = CASE 
                        WHEN V_REC.CODPOSTAL IS NOT NULL THEN V_REC.CODPOSTAL
                        ELSE CODPOSTAL
                      END                          
                                   
    WHERE
      CODAGENDA = V_REC.CODAGENDA; 
      
   END LOOP;    
   
   
END;


PROCEDURE UPDATEDELEGAT
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NPARTTR) LOOP
    IF COALESCE(V_REC.IMPLICIT, 0) = 1 THEN
      UPDATE NPARTTR
      SET
        IMPLICIT = 0
      WHERE
        CODPART = V_REC.CODPART;
    END IF;

    IF V_REC.CODPARTTR &lt; 0 THEN
      INSERT INTO NPARTTR(CODPARTTR, CODPART, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, IMPLICIT)
      VALUES(SEQ_NPARTTR_CODPARTTR.NEXTVAL, V_REC.CODPART, V_REC.DELEGAT, V_REC.CNP, V_REC.DOC, V_REC.SERIEDOC, V_REC.NRDOC, V_REC.ELIBERAT, V_REC.MIJLTRANSP, V_REC.NRTRANSP, V_REC.ACTIV, V_REC.IMPLICIT);
    ELSE
      UPDATE NPARTTR
      SET
        DELEGAT    = V_REC.DELEGAT,
        CNP        = V_REC.CNP,
        DOC        = V_REC.DOC,
        SERIEDOC   = V_REC.SERIEDOC,
        NRDOC      = V_REC.NRDOC,
        ELIBERAT   = V_REC.ELIBERAT,
        MIJLTRANSP = V_REC.MIJLTRANSP,
        NRTRANSP   = V_REC.NRTRANSP,
        ACTIV      = V_REC.ACTIV,
        IMPLICIT   = V_REC.IMPLICIT
      WHERE
        CODPARTTR = V_REC.CODPARTTR;
    END IF;
  END LOOP;
END;

PROCEDURE UPDATEPERSCONTACT
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NPERSCONTACT) LOOP
    IF COALESCE(V_REC.CODPERSC, 0) = 0 THEN
      INSERT INTO NPERSCONTACT(CODPERSC, CODPART, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, CODLOCATIE)
      VALUES(SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, V_REC.CODPART,  V_REC.NUME,  V_REC.PRENUME,  V_REC.TELEFON,  V_REC.EMAIL,  V_REC.FUNCTIE, V_REC.CODLOCATIE);
    ELSE
      UPDATE
        NPERSCONTACT
      SET
        TELEFON    = V_REC.TELEFON,
        EMAIL      = V_REC.EMAIL,
        FUNCTIE    = V_REC.FUNCTIE,
        CODLOCATIE = V_REC.CODLOCATIE
      WHERE
        CODPERSC = V_REC.CODPERSC;
    END IF;
  END LOOP;
END;



PROCEDURE ADAUGA_CERTIFICAT
IS
BEGIN
  INSERT INTO CERTIF(CODCERTIF, NRCERTIF, DATAPRIMIRE, CODOBIECT, CODSERIE, SUBUNITATE, DATACREARE)
  SELECT CODCERTIF, NRCERTIF, DATAPRIMIRE, CODOBIECT, CODSERIE, SUBUNITATE, SYSDATE FROM TMP_CERTIF;
END;

PROCEDURE UPDATE_CANTNIR
IS
BEGIN
  FOR V_REC IN (
      SELECT TNS.CODNIRSTOC, TNS.CANTNIR, N.CODNIR
      FROM
        TMP_NIRSTOC TNS,
        NIRSTOC NS,
        NIR N
      WHERE
        TNS.CODNIRSTOC = NS.CODNIRSTOC
        AND N.CODNIR = NS.CODNIR
    )
  LOOP
    UPDATE NIRSTOC
    SET
      CANTNIR = V_REC.CANTNIR,
      REST    = PKG_INTRARI.GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir)
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

END;

PROCEDURE UPDATE_NARTAMB
IS
aCODAMB NUMBER;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NARTAMB) LOOP
   BEGIN
    SELECT CODAMB  INTO  aCODAMB
    FROM
      NARTAMB
     WHERE
      CODOBIECT =  V_REC.CODOBIECT
      AND UMSEC = V_REC.UMSEC;
    EXCEPTION WHEN OTHERS THEN
        aCODAMB := 0;
   END;
   IF aCODAMB = 0 THEN
      INSERT INTO NARTAMB(CODAMB, CODOBIECT, UMSEC, CODEXTERN, MASA)
      VALUES(SEQ_NARTAMB_CODAMB.NEXTVAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.CODEXTERN, V_REC.MASA);
   ELSE
     UPDATE NARTAMB
     SET
       CODEXTERN = V_REC.CODEXTERN,
       MASA      = V_REC.MASA
     WHERE
       CODAMB = aCODAMB;

   END IF;
  END LOOP;

  COMMIT;
END;


PROCEDURE GET_SEDII_PART(aCODPART IN NUMBER)
IS
BEGIN
  DELETE TMP_NAGENDA;
  INSERT INTO TMP_NAGENDA(CODAGENDA, CODPART, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, OBS, CODPOSTAL, COD_CODFISCAL, CODFISCAL, IDSEDIU,INACTIV, CODAGENT)
  SELECT CODAGENDA, CODPART, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, OBS, CODPOSTAL, COD_CODFISCAL, CODFISCAL, IDSEDIU, INACTIV, CODAGENT
  FROM
    NAGENDA
  WHERE
    CODPART = aCODPART;

  DELETE FROM TMP_NPERSCONTACT;


END;

PROCEDURE UPDATESEDIIPART
IS
  aCODAGENDA NUMBER;
  aCOD_CODFISCAL NUMBER;
BEGIN

  -- codificari codfiscal
  FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE COD_CODFISCAL &lt; 0)
  LOOP
    BEGIN
      SELECT COD_CODFISCAL INTO aCOD_CODFISCAL FROM NPARTCODFISC
      WHERE
        CODPART = V_REC.CODPART
        AND UPPER(CODFISCAL) = UPPER(V_REC.CODFISCAL);
        EXCEPTION WHEN OTHERS THEN 
           aCOD_CODFISCAL := 0;
    END;  
    IF COALESCE(aCOD_CODFISCAL, 0) = 0 THEN
      aCOD_CODFISCAL := SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL;
      INSERT INTO NPARTCODFISC(COD_CODFISCAL, CODPART, CODFISCAL)
      VALUES(aCOD_CODFISCAL, V_REC.CODPART, V_REC.CODFISCAL);
      UPDATE TMP_NAGENDA
      SET
        COD_CODFISCAL = aCOD_CODFISCAL
      WHERE
        CODAGENDA = V_REC.CODAGENDA;  
    END IF;
    
  END LOOP;    
  

  FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE CODAGENDA &lt; 0) LOOP
    
    aCODAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;
    INSERT INTO NAGENDA(CODAGENDA, CODPART, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, OBS, CODPOSTAL, IDSEDIU, COD_CODFISCAL, CODFISCAL, SUPRAFATA, INACTIV, CODAGENT)
                VALUES (aCODAGENDA,
                        V_REC.CODPART,
                        V_REC.TIP,
                        V_REC.CODLOCALIT,
                        V_REC.SEDIUSOCIAL,
                        V_REC.TELEFON,
                        V_REC.FAX,
                        V_REC.EMAIL,
                        V_REC.SECTOR,
                        V_REC.STRADA,
                        V_REC.NR1,
                        V_REC.NR2,
                        V_REC.BLOC,
                        V_REC.SCARA,
                        V_REC.ETAJ,
                        V_REC.APART,
                        V_REC.OBS,
                        V_REC.CODPOSTAL,
                        V_REC.IDSEDIU,
                        V_REC.COD_CODFISCAL,
                        V_REC.CODFISCAL,
                        V_REC.SUPRAFATA,
                        V_REC.INACTIV,
                        V_REC.CODAGENT);

    UPDATE TMP_NPERSCONTACT
    SET
      CODLOCATIE = aCODAGENDA
    WHERE
      CODLOCATIE = V_REC.CODAGENDA;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NPERSCONTACT)
  LOOP
     INSERT INTO NPERSCONTACT(CODPERSC, CODPART, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, CODLOCATIE)
      VALUES(SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, V_REC.CODPART,  V_REC.NUME,  V_REC.PRENUME,  V_REC.TELEFON,  V_REC.EMAIL,  V_REC.FUNCTIE, V_REC.CODLOCATIE);
  END LOOP;



  FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE CODAGENDA &gt; 0) LOOP
    UPDATE NAGENDA
    SET (CODLOCALIT, TELEFON, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, IDSEDIU, COD_CODFISCAL, CODFISCAL, SUPRAFATA, OBS, INACTIV, CODAGENT) =
         (SELECT 
            V_REC.CODLOCALIT,
            V_REC.TELEFON,
            V_REC.EMAIL,
            V_REC.STRADA,
            V_REC.NR1,
            V_REC.NR2,
            V_REC.BLOC,
            V_REC.SCARA,
            V_REC.ETAJ,
            V_REC.APART,
            V_REC.CODPOSTAL,
            V_REC.IDSEDIU,
            V_REC.COD_CODFISCAL,
            V_REC.CODFISCAL,
            V_REC.SUPRAFATA,
            V_REC.OBS,
            V_REC.INACTIV,
            V_REC.CODAGENT
          FROM DUAL)
     WHERE
       CODAGENDA = V_REC.CODAGENDA;
  END LOOP;


END;



PROCEDURE SETCARNETIMPLICIT_NT(aCODCARNET NUMBER)
IS
BEGIN
  CARNETIMPLICIT_NT := aCODCARNET;
END;



PROCEDURE IMPORTA_MIFIX(TIP NUMBER) IS
aTIPMF VARCHAR2(2);
aCODMIFIX NUMBER(20);
NR NUMBER;
BEGIN
  IF TIP = 0 THEN
    aTIPMF := &apos;OI&apos;;
  ELSE
    aTIPMF := &apos;MF&apos;;
  END IF;

  FOR V_REC IN (SELECT MF.*, CL.DURATA FROM TMP_IMPORT_MIFIX MF,  MFCLASIF CL WHERE MF.CODCLASIF = CL.CODCLASIF) LOOP
    SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    IF NR = 0 THEN
      INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN, DURATANF,DURATANG)
      VALUES(V_REC.CODNIRSTOC, V_REC.CODCLASIF, V_REC.DURATA * 12,  0, 0);
    END IF;

    BEGIN
      SELECT CODMIFIX INTO aCODMIFIX
      FROM
        MIFIX MF
      WHERE
        TIP = aTIPMF
        AND NRINVENTAR = V_REC.NRINVENTAR
        AND (SELECT COUNT(*) FROM MIFIX1 WHERE CODMIFIX = MF.CODMIFIX AND CODNIRSTOC = V_REC.CODNIRSTOC) &gt; 0;
    EXCEPTION WHEN OTHERS THEN
      aCODMIFIX := 0;
    END;

   IF aCODMIFIX &lt;&gt; 0 THEN
     DELETE FROM JURNAL1 WHERE TIPDOC = 36 AND CODDOC = aCODMIFIX;
     DELETE FROM JURNAL  WHERE TIPDOC = 36 AND CODDOC = aCODMIFIX;
     DELETE FROM MIFIX1 WHERE CODMIFIX = aCODMIFIX;
     DELETE FROM MIFIX  WHERE CODMIFIX = aCODMIFIX;
   END IF;

   aCODMIFIX := SEQ_MIFIX_CODMIFIX.NEXTVAL;

   INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, OBS)
   VALUES(aCODMIFIX, aTIPMF, V_REC.NRINVENTAR, V_REC.ANINTRARE, V_REC.LUNAINTRARE, V_REC.OBS);

   INSERT INTO MIFIX1(CODMIFIX1,
                      CODMIFIX,
                      CODNIRSTOC,
                      CODNIRSER,
                      PRET,
                      CANT,
                      CODCLASIF,
                      TIPAMO,
                      STARE,
                      DURATAN,
                      GRADU,
                      DURATAF,
                      AMO,
                      DFBLOCAT,
                      CODPERS,
                      ANSTART,
                      LUNASTART,
                      CODCENTRU,
                      CODANALIZANOD
                     )
               VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
                      aCODMIFIX,
                      V_REC.CODNIRSTOC,
                      V_REC.CODNIRSER,
                      V_REC.PRET,
                      V_REC.CANT,
                      V_REC.CODCLASIF,
                      V_REC.TIPAMO,
                      V_REC.STARE,
                      V_REC.DURATA * 12,
                      100,
                      V_REC.DURATAF,
                      V_REC.AMO * V_REC.CANT,
                      1,
                      V_REC.CODPERS,
                      PKG_GLOBALS.GetANLUCRU,
                      PKG_GLOBALS.GetLUNALUCRU,
                      V_REC.CODCENTRU,
                      V_REC.CODANALIZANOD
                      );

   IF TIP = 1 THEN
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, ContD, Contc)
     VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, aCODMIFIX, 36, aCODMIFIX, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 0, 0);

     INSERT INTO JURNAL1(CODJURNAL1, CODDOC, INDEXLOCAL, TIPDOC, AN, LUNA, DIRTY)
     VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, aCODMIFIX, aCODMIFIX, 36, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU, 1);
   END IF;

  END LOOP;
END;



PROCEDURE POST_LOGIMPORT
IS
BEGIN
  INSERT INTO LOGIMPORTDOC(COD,
                           TIPDOC,
                           IDIMPORT,
                           NRDOC,
                           DATADOC,
                           DATAIMPORT,
                           CODPART,
                           CODOBIECT,
                           TIPOPERATIE,
                           CANTVECHI,
                           CANTNOU
                          )
  SELECT SEQ_LOGIMPORTDOC_COD.NEXTVAL,
                              TIPDOC,
                              IDIMPORT,
                              NRDOC,
                              DATADOC,
                              DATAIMPORT,
                              CODPART,
                              CODOBIECT,
                              TIPOPERATIE,
                              CANTVECHI,
                              CANTNOU
  FROM
    TMP_LOGIMPORTDOC;
  COMMIT;
END;

PROCEDURE SETVANDUTLACASEDEMARCAT(aFLAG IN NUMBER)
IS
BEGIN
  VANDUTLACASADEMARCAT := aFLAG;
END;


PROCEDURE SETDESCARCAREINTEGRALA(aFLAG IN NUMBER)
IS
BEGIN
  V_DESCARCAREINTEGRALA := aFLAG;
END;


PROCEDURE GET_NOMENCLATOARE_NPERS
IS
BEGIN
  DELETE TMP_NPERS;
  DELETE TMP_NPERS1;
  DELETE TMP_Functii;
  DELETE TMP_NAGENDA;
  DELETE TMP_NBANK;
  DELETE TMP_FORMATII;

 -- INSERT INTO TMP_NPERS  SELECT * FROM NPERS;

INSERT INTO TMP_NPERS
(
  CODPERS,
  MARCA,
  NUME,
  PRENUME,
  CNP,
  BISERIA,
  BINR,
  LOCNASTERE,
  ADRESA,
  PRENUMET,
  PRENUMEM,
  LOCALITN,
  DATAN,
  SCIVILA,
  SMILITAR,
  ACTIV,
  STRAINATATE,
  AGENT,
  DELEGAT,
  AGENDA,
  BIELIBERATDE,
  LADATADE,
  TARAN,
  CETATENIE,
  POZA,
  LOGONNAME,
  ACCMAS,
  COMISION,
  CODGEST,
  CODANALIZANOD,
  DATAPLECARII
)
SELECT
  CODPERS,
  MARCA,
  NUME,
  PRENUME,
  CNP,
  BISERIA,
  BINR,
  LOCNASTERE,
  ADRESA,
  PRENUMET,
  PRENUMEM,
  LOCALITN,
  DATAN,
  SCIVILA,
  SMILITAR,
  ACTIV,
  STRAINATATE,
  AGENT,
  DELEGAT,
  AGENDA,
  BIELIBERATDE,
  LADATADE,
  TARAN,
  CETATENIE,
  POZA,
  LOGONNAME,
  ACCMAS,
  COMISION,
  CODGEST,
  CODANALIZANOD,
  DATAPLECARII
FROM
NPERS;

INSERT INTO  TMP_NPERS1 ( CODPERS1, CODPERS, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART,LUNASTART, SCHIMB )
  ( SELECT CODPERS1, CODPERS, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART,LUNASTART,SCHIMB
    FROM NPERS1);

INSERT INTO  TMP_FUNCTII ( CodFunctie, Denumire, CodExtern )
  ( SELECT CodFunctie, Denumire, CodExtern FROM FUNCTII) ;

INSERT INTO TMP_FORMATII(CODFORMATIE,DEN_FORMATIE,SIMBOL)
  SELECT CODFORMATIE, DEN_FORMATIE, SIMBOL FROM FORMATII;

  INSERT INTO  TMP_NAGENDA (
    OBS,CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT,CODPART,CODGEST,CODSUBUNIT,CODTRASEU,POZTRASEU, LONGITUDINE, LATITUDINE, OBS2,
    ADRESA )
  SELECT
    OBS, CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT,CODPART,CODGEST,CODSUBUNIT,CODTRASEU,POZTRASEU, LONGITUDINE, LATITUDINE, OBS2,
    GETADRESA(SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL)
  FROM NAGENDA
  WHERE CODAGENDA IN (SELECT AGENDA FROM TMP_NPERS)  ;

  COMMIT;
END;

PROCEDURE POST_NOMENCLATOARE_NPERS
IS
aCOD NUMBER(20);
BEGIN
  PRC_AL_REFRESH(&apos;TMP_NPERS1&apos;, 0);

  FOR V_REC IN (SELECT * FROM TMP_NBANK WHERE CODBANK &lt; 0)
  LOOP
    aCOD := SEQ_NBANK_CODBANK.NEXTVAL;
    INSERT INTO NBANK(CODBANK, DENUMIRE, SIMBOL) VALUES(aCOD, V_REC.DENUMIRE, V_REC.SIMBOL);
    UPDATE TMP_NPERS
    SET
      CODBANK = aCOD
    WHERE
      CODBANK = ABS(V_REC.CODBANK);

  END LOOP;



  FOR V_REC IN (SELECT * FROM TMP_NAGENDA)
  LOOP
    IF V_REC.CODAGENDA &lt; 0 THEN
      SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL INTO aCOD FROM DUAL;

      UPDATE TMP_NPERS
      SET
        AGENDA = aCOD
      WHERE
        AGENDA = V_REC.CODAGENDA;

      INSERT INTO NAGENDA(CODAGENDA,
                          TIP,
                          OBS,
                          CODLOCALIT,
                          SEDIUSOCIAL,
                          TELEFON,
                          FAX,
                          EMAIL,
                          SECTOR,
                          STRADA,
                          NR1,
                          NR2,
                          BLOC,
                          SCARA,
                          ETAJ,
                          APART,
                          CODPOSTAL,
                          LONGITUDINE, LATITUDINE, OBS2
                        )
                  VALUES( aCOD,
                          V_REC.TIP,
                          V_REC.OBS,
                          V_REC.CODLOCALIT,
                          V_REC.SEDIUSOCIAL,
                          V_REC.TELEFON,
                          V_REC.FAX,
                          V_REC.EMAIL,
                          V_REC.SECTOR,
                          V_REC.STRADA,
                          V_REC.NR1,
                          V_REC.NR2,
                          V_REC.BLOC,
                          V_REC.SCARA,
                          V_REC.ETAJ,
                          V_REC.APART,
                          V_REC.CODPOSTAL,
                          V_REC.LONGITUDINE, V_REC.LATITUDINE, V_REC.OBS2
                        );
     ELSE
      UPDATE NAGENDA
      SET
        TIP         = V_REC.TIP,
        OBS         = V_REC.OBS,
        CODLOCALIT  = V_REC.CODLOCALIT,
        SEDIUSOCIAL = V_REC.SEDIUSOCIAL,
        TELEFON     = V_REC.TELEFON,
        FAX         = V_REC.FAX,
        EMAIL       = V_REC.EMAIL,
        SECTOR      = V_REC.SECTOR,
        STRADA      = V_REC.STRADA,
        NR1         = V_REC.NR1,
        NR2         = V_REC.NR2,
        BLOC        = V_REC.BLOC,
        SCARA       = V_REC.SCARA,
        ETAJ        = V_REC.ETAJ,
        APART       = V_REC.APART,
        CODPOSTAL   = V_REC.CODPOSTAL,
        LONGITUDINE = V_REC.LONGITUDINE,
        LATITUDINE  = V_REC.LATITUDINE,
        OBS2        = V_REC.OBS2
      WHERE
        CODAGENDA = V_REC.CODAGENDA;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NPERS)
  LOOP
    IF V_REC.CODPERS &lt; 0 THEN
      SELECT SEQ_NPERS_CODPERS.NEXTVAL INTO aCOD FROM DUAL;
      update TMP_NPers1 set CodPers = aCod where CodPers = v_rec.CodPers;

      INSERT INTO NPERS(CODPERS, MARCA, NUME, PRENUME, CNP, BISERIA,
                        BINR, LOCNASTERE, PRENUMET, PRENUMEM, LOCALITN, DATAN, SCIVILA, SMILITAR, AGENT, AGENDA, DATAANGAJARII, DATAPLECARII, ACTIV, CODBANK, IBAN)
                VALUES(aCOD, V_REC.MARCA, V_REC.NUME, V_REC.PRENUME, V_REC.CNP, V_REC.BISERIA,
                       V_REC.BINR, V_REC.LOCNASTERE, V_REC.PRENUMET, V_REC.PRENUMEM, V_REC.LOCALITN, V_REC.DATAN, V_REC.SCIVILA, V_REC.SMILITAR, V_REC.AGENT, V_REC.AGENDA, V_REC.DATAANGAJARII, V_REC.DATAPLECARII, V_REC.ACTIV, V_REC.CODBANK, V_REC.IBAN);
    ELSE
      UPDATE NPERS
      SET
        MARCA        = V_REC.MARCA,
        NUME         = V_REC.NUME,
        PRENUME      = V_REC.PRENUME,
        CNP          = V_REC.CNP,
        BISERIA      = V_REC.BISERIA,
        BINR         = V_REC.BINR,
        LOCNASTERE   = V_REC.LOCNASTERE,
        PRENUMET     = V_REC.PRENUMET,
        PRENUMEM     = V_REC.PRENUMEM,
        LOCALITN     = V_REC.LOCALITN,
        DATAN        = V_REC.DATAN,
        SCIVILA      = V_REC.SCIVILA,
        SMILITAR     = V_REC.SMILITAR,
        AGENT        = V_REC.AGENT,
        AGENDA       = V_REC.AGENDA,
        DATAANGAJARII= V_REC.DATAANGAJARII,
        DATAPLECARII = V_REC.DATAPLECARII,
        ACTIV        = V_REC.ACTIV,
        CODBANK      = V_REC.CODBANK,
        IBAN         = V_REC.IBAN
      WHERE
        CODPERS = V_REC.CODPERS;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_Functii)
  LOOP
  -- DETAIL NFunctii

    IF V_REC.CODFunctie &lt; 0 THEN
      SELECT SEQ_Functii_CODFunctie.NEXTVAL INTO aCOD FROM DUAL;
      update TMP_NPers1 set CodFunctie = aCod where CodFunctie = v_rec.CodFunctie;
      INSERT INTO Functii
			(CodFunctie, Denumire, CodExtern)
      VALUES
			(aCOD, V_REC.Denumire, V_REC.CodExtern);
    ELSE
      UPDATE Functii
      SET
        CodExtern = V_REC.CodExtern,
        Denumire = V_REC.Denumire
      WHERE
        CODFunctie = V_REC.CODFunctie;
    END IF;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_Formatii)
  LOOP
  -- DETAIL Formatii

    IF V_REC.CODFormatie &lt; 0 THEN
      SELECT SEQ_FORMATII_CODFormatie.NEXTVAL INTO aCOD FROM DUAL;
      update TMP_NPers1 set CodFormatie = aCod where CodFormatie = v_rec.CodFormatie;
      INSERT INTO FORMATII
			(CodFORMATIE, Den_FORMATIE, SIMBOL)
      VALUES
			(aCOD, V_REC.Den_FORMATIE, V_REC.SIMBOL);
    ELSE
      UPDATE FORMATII
      SET
        SIMBOL = V_REC.SIMBOL
     WHERE
        CODFormatie = V_REC.CODFormatie;
    END IF;
  END LOOP;



  FOR V_REC IN (SELECT * FROM TMP_NPERS1)
  LOOP
  -- DETAIL NPERS1

    IF V_REC.CODPERS1 &lt; 0 THEN
      SELECT SEQ_NPERS1_CODPERS1.NEXTVAL INTO aCOD FROM DUAL;

      INSERT INTO NPERS1
			(CODPERS1, CODPERS, CODIOPERS, CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART,LUNASTART, SCHIMB, ALSTART, ALSTOP )
      VALUES
			(aCOD, V_REC.CODPERS, V_REC.CODIOPERS, V_REC.CODFORMATIE, V_REC.CODFUNCTIE, V_REC.CODMESERIE,
       V_REC.ANSTART,V_REC.LUNASTART, V_REC.SCHIMB, V_REC.ALSTART, V_REC.ALSTOP );
    ELSE
      UPDATE NPERS1
      SET
        CODFUNCTIE  = V_REC.CODFUNCTIE,
        CODFORMATIE = V_REC.CODFORMATIE,
        ALSTART     = V_REC.ALSTART,
        ALSTOP      = V_REC.ALSTOP
      WHERE
        CODPERS1 = V_REC.CODPERS1;
    END IF;
  END LOOP;

  COMMIT;
END;


PROCEDURE SETTIPINFOLUNARE(aTIP IN NUMBER)
IS
BEGIN
  TIPINFOLUNARE := aTIP;
END;


PROCEDURE SOLVE_ERORI_STERGERE
IS
 ERORI NUMBER(10) := 0;
BEGIN
  BEGIN
    FOR V_REC IN (SELECT * FROM ERRORSDELETE ORDER BY NUMETABELA, COD)
    LOOP
      IF V_REC.NUMETABELA = &apos;NCONT&apos; THEN
        FOR V_REC2 IN (SELECT * FROM NCONT WHERE CODPARINTE = V_REC.COD)
        LOOP
          -- ioart1
          UPDATE IOART1
          SET
           CHELTUIELI = NULL
          WHERE
            CHELTUIELI = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            CHELTTVACOLECTAT = NULL
           WHERE
             CHELTTVACOLECTAT = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            CONTROTUNJIRI = NULL
           WHERE
             CONTROTUNJIRI = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            DIFERENTE = NULL
           WHERE
             DIFERENTE = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            DIVERSE = NULL
           WHERE
             DIVERSE = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            PLUSINVENTAR = NULL
           WHERE
             PLUSINVENTAR = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            MINUSINVENTAR = NULL
           WHERE
             MINUSINVENTAR = V_REC2.CODCONT;

           UPDATE IOART1
           SET
            VENITURI = NULL
           WHERE
             VENITURI = V_REC2.CODCONT;

          -- iobank1
           UPDATE IOBANK1
           SET
            CHELTUIELICV = NULL
           WHERE
             CHELTUIELICV = V_REC2.CODCONT;

           UPDATE IOBANK1
           SET
            COMISION = NULL
           WHERE
             COMISION = V_REC2.CODCONT;

           UPDATE IOBANK1
           SET
            CONT = NULL
           WHERE
             CONT = V_REC2.CODCONT;

           UPDATE IOBANK1
           SET
            DOBANDA = NULL
           WHERE
             DOBANDA = V_REC2.CODCONT;

           UPDATE IOBANK1
           SET
            VENITURICV = NULL
           WHERE
             VENITURICV = V_REC2.CODCONT;
-- IOPERS1
           UPDATE IOPERS1
           SET
             CONTALTERETINERI = NULL
           WHERE
             CONTALTERETINERI = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTAVANS  = NULL
           WHERE
             CONTAVANS = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTAVANSDECONT  = NULL
           WHERE
             CONTAVANSDECONT = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTBOALA  = NULL
           WHERE
             CONTBOALA = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTECHIPAMENT  = NULL
           WHERE
             CONTECHIPAMENT = V_REC2.CODCONT;


           UPDATE IOPERS1
           SET
             CONTGARANTII  = NULL
           WHERE
             CONTGARANTII = V_REC2.CODCONT;


           UPDATE IOPERS1
           SET
             CONTIMPOZIT  = NULL
           WHERE
             CONTIMPOZIT = V_REC2.CODCONT;


           UPDATE IOPERS1
           SET
             CONTIMPUTATII  = NULL
           WHERE
             CONTIMPUTATII = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTLIKI  = NULL
           WHERE
             CONTLIKI = V_REC2.CODCONT;


           UPDATE IOPERS1
           SET
             CONTNATURA  = NULL
           WHERE
             CONTNATURA = V_REC2.CODCONT;

           UPDATE IOPERS1
           SET
             CONTNERIDICATE  = NULL
           WHERE
             CONTNERIDICATE = V_REC2.CODCONT;
-- IOFILIAL1
           UPDATE IOFILIAL1
           SET
             CONTDECONTARE  = NULL
           WHERE
             CONTDECONTARE = V_REC2.CODCONT;

           UPDATE IOFILIAL1
           SET
             CONTDECONTAREF  = NULL
           WHERE
             CONTDECONTAREF = V_REC2.CODCONT;

           UPDATE IOFILIAL1
           SET
             CONTDECONTCB  = NULL
           WHERE
             CONTDECONTCB = V_REC2.CODCONT;

           UPDATE IOFILIAL1
           SET
             CONTDECONTCMP  = NULL
           WHERE
             CONTDECONTCMP = V_REC2.CODCONT;

           UPDATE IOFILIAL1
           SET
             CONTDECONTSERV  = NULL
           WHERE
             CONTDECONTSERV = V_REC2.CODCONT;



          DELETE FROM NCONT1 WHERE CODCONT = V_REC2.CODCONT;
          DELETE FROM NCONT  WHERE CODCONT = V_REC2.CODCONT;
        END LOOP;





          UPDATE IOART1
          SET
           CHELTUIELI = NULL
          WHERE
            CHELTUIELI = V_REC.COD;

           UPDATE IOART1
           SET
            CHELTTVACOLECTAT = NULL
           WHERE
             CHELTTVACOLECTAT = V_REC.COD;

           UPDATE IOART1
           SET
            CONTROTUNJIRI = NULL
           WHERE
             CONTROTUNJIRI = V_REC.COD;

           UPDATE IOART1
           SET
            DIFERENTE = NULL
           WHERE
             DIFERENTE = V_REC.COD;

           UPDATE IOART1
           SET
            DIVERSE = NULL
           WHERE
             DIVERSE = V_REC.COD;

           UPDATE IOART1
           SET
            PLUSINVENTAR = NULL
           WHERE
             PLUSINVENTAR = V_REC.COD;

           UPDATE IOART1
           SET
            MINUSINVENTAR = NULL
           WHERE
             MINUSINVENTAR =V_REC.COD;

           UPDATE IOART1
           SET
            VENITURI = NULL
           WHERE
             VENITURI =V_REC.COD;

          -- iobank1
           UPDATE IOBANK1
           SET
            CHELTUIELICV = NULL
           WHERE
             CHELTUIELICV = V_REC.COD;

           UPDATE IOBANK1
           SET
            COMISION = NULL
           WHERE
             COMISION = V_REC.COD;

           UPDATE IOBANK1
           SET
            CONT = NULL
           WHERE
             CONT = V_REC.COD;

           UPDATE IOBANK1
           SET
            DOBANDA = NULL
           WHERE
             DOBANDA = V_REC.COD;

           UPDATE IOBANK1
           SET
            VENITURICV = NULL
           WHERE
             VENITURICV = V_REC.COD;



-- IOPERS1
           UPDATE IOPERS1
           SET
             CONTALTERETINERI = NULL
           WHERE
             CONTALTERETINERI = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTAVANS  = NULL
           WHERE
             CONTAVANS = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTAVANSDECONT  = NULL
           WHERE
             CONTAVANSDECONT = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTBOALA  = NULL
           WHERE
             CONTBOALA = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTECHIPAMENT  = NULL
           WHERE
             CONTECHIPAMENT = V_REC.COD;


           UPDATE IOPERS1
           SET
             CONTGARANTII  = NULL
           WHERE
             CONTGARANTII = V_REC.COD;


           UPDATE IOPERS1
           SET
             CONTIMPOZIT  = NULL
           WHERE
             CONTIMPOZIT = V_REC.COD;


           UPDATE IOPERS1
           SET
             CONTIMPUTATII  = NULL
           WHERE
             CONTIMPUTATII = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTLIKI  = NULL
           WHERE
             CONTLIKI = V_REC.COD;


           UPDATE IOPERS1
           SET
             CONTNATURA  = NULL
           WHERE
             CONTNATURA = V_REC.COD;

           UPDATE IOPERS1
           SET
             CONTNERIDICATE  = NULL
           WHERE
             CONTNERIDICATE = V_REC.COD;
-- IOFILIAL

           UPDATE IOFILIAL1
           SET
             CONTDECONTARE  = NULL
           WHERE
             CONTDECONTARE = V_REC.COD;

           UPDATE IOFILIAL1
           SET
             CONTDECONTAREF  = NULL
           WHERE
             CONTDECONTAREF = V_REC.COD;

           UPDATE IOFILIAL1
           SET
             CONTDECONTCB  = NULL
           WHERE
             CONTDECONTCB = V_REC.COD;

           UPDATE IOFILIAL1
           SET
             CONTDECONTCMP  = NULL
           WHERE
             CONTDECONTCMP = V_REC.COD;

           UPDATE IOFILIAL1
           SET
             CONTDECONTSERV  = NULL
           WHERE
             CONTDECONTSERV = V_REC.COD;



        DELETE FROM NCONT1 WHERE CODCONT = V_REC.COD;
        DELETE FROM NCONT  WHERE CODCONT = V_REC.COD;

      END IF;
    END LOOP;

  -- EXCEPTION WHEN OTHERS THEN ERORI := ERORI + 1;
  END;
  COMMIT;
END;


PROCEDURE SETROTUNJIRI(aROTI IN NUMBER, aROTE IN NUMBER)
IS
BEGIN
  ROTINTRARE := aROTI;
  ROTIESIRE  := aROTE;
END;



PROCEDURE SETSUBUNITATEIMPORT(aSUBUNIT IN NUMBER)
IS
BEGIN
  SUBUNITATEIMPORT := aSUBUNIT;
END;

PROCEDURE SETGESTIMPLICITA(aGEST IN NUMBER)
IS
BEGIN
  GEST_IMPLICITA := aGEST;
END;


PROCEDURE SETCODIOARTIMPLICIT(aCODIOART IN NUMBER)
IS
BEGIN
  CODIOARTIMPLICIT := aCODIOART;
END;


PROCEDURE SETCODTVAIMPLICIT(aCODTVA IN NUMBER)
IS
BEGIN
  CODTVA_IMPLICIT := aCODTVA;
END;

PROCEDURE SETUMIMPLICITA(aUM IN NUMBER)
IS
BEGIN
  UMIMPLICITA := aUM;
END;

PROCEDURE SETCLASAIMPLICITA(aCLASA IN NUMBER)
IS
BEGIN
  CLASAIMPLICITA := aCLASA;
END;



FUNCTION SUPRASCRIERE_COLOANA(NUMECOL IN VARCHAR2) RETURN NUMBER
IS
  NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM TMP_MANEVRACHAR WHERE UPPER(VALOARE) = UPPER(NUMECOL);
  RETURN NR;
END;


PROCEDURE IMPORTAPRETURIEXCEL
IS
 aCODOBJ              NUMBER(20) ;
 aCODART              NUMBER(20) ;
 CODTVAIMPLICIT       NUMBER(20) ;
 NR                   NUMBER(10) := 0;
 I                    NUMBER(5)  := 0;
 aIMPLICIT            NUMBER(1)  := 0;
 aCODCLASA            NUMBER(20) := 0;
 aCODCLASAW           NUMBER(20) := 20;
 aCODPRODUCATOR       NUMBER(20) := 0;
 aCODCARACTSUPLIM     NUMBER(20) := 0;
 aCOMENZIONLINE       NUMBER(1)  := 0;
 aUMP                 NUMBER(20) := 0;
 aCOD                 NUMBER(20) := 0;
 aGEST                NUMBER(20) := 0;
 aCODIOART            NUMBER(20) := 0;
 s                    VARCHAR2(32000);
 ColoaneExtensie      VARCHAR2(20000);
 V_Rec_ColExtensie    VARCHAR2(20000);
 ProcTVAInXLS         NUMBER(1) := 0;
 aSyncPretRetail      VARCHAR2(10);
 aMemoModiPret        VARCHAR2(10);

 AnLunaStartUpdate    NUMBER(20) := 0;
 aLEI                 NUMBER(20, 7); 
 aVALUTA              NUMBER(20, 7); 
 aMONEDA              NUMBER(20);
 aCODAMB              NUMBER(20);
 aCODPRETM            NUMBER(20);
 aCODPRETMAMB         NUMBER(20);

BEGIN
  
  update tmp_pretm p
  set
   CODCATMASTER = (select codcatmaster from ncatpret c where c.codcatpret = p.codcatpret);


  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPretRetail FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aSyncPretRetail := &apos;0&apos;;
  END;

  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aMemoModiPret FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aMemoModiPret := &apos;0&apos;;
  END;


  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ_IMPORT)
  LOOP
     IF V_REC.CODTVA IS NOT NULL THEN  
       CODTVAIMPLICIT := V_REC.CODTVA;
       ProcTVAInXLS   := 1;
     ELSE  
     IF NVL(CODTVA_IMPLICIT, 0) &lt;&gt; 0 THEN 
       CODTVAIMPLICIT := CODTVA_IMPLICIT;
     ELSE
       SELECT PKG_CATEGCONST.GetValConstanta(&apos;TIPTVAImplicit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO CODTVAIMPLICIT FROM DUAL;
     END IF;
     END IF;
     
     aCODCLASA := 0;
     IF V_REC.SIMBOLCLASA IS NOT NULL THEN
       BEGIN
         SELECT CODCLASEA INTO aCODCLASA FROM NCLASEA WHERE SIMBOL = V_REC.SIMBOLCLASA;
         EXCEPTION WHEN OTHERS THEN aCODCLASA := 0;
       END;
     END IF;

     aCODCLASAW := 0;
      IF V_REC.SIMBOL_CLASEASW IS NOT NULL THEN
        BEGIN
          SELECT CODCLASEAS INTO aCODCLASAW FROM NCLASEAS WHERE SIMBOL = V_REC.SIMBOL_CLASEASW ;
          EXCEPTION WHEN OTHERS THEN aCODCLASAW := 0;
        END;
      END IF;

     aCOMENZIONLINE := NVL(V_REC.COMENZIONLINE, 0);

      aCODPRODUCATOR := 0;
      IF V_REC.DENPRODUCATOR IS NOT NULL THEN
        BEGIN
          SELECT CODPART INTO aCODPRODUCATOR FROM NPART WHERE DEN_PART = V_REC.DENPRODUCATOR;
          EXCEPTION WHEN OTHERS THEN aCODPRODUCATOR := 0;
        END;
      END IF;


      aCODCARACTSUPLIM := 0;
      IF V_REC.DENCARACTSUPLIM IS NOT NULL THEN
        BEGIN
          SELECT CODCARSUPART INTO aCODCARACTSUPLIM FROM NCARSUPART WHERE UPPER(DEN_CARSUPART) = UPPER(V_REC.DENCARACTSUPLIM);
          EXCEPTION WHEN OTHERS THEN aCODCARACTSUPLIM := 0;
        END;

       IF aCODCARACTSUPLIM = 0 THEN
         SELECT SEQ_NCARSUPART_CODCARSUPART.NEXTVAL INTO aCODCARACTSUPLIM FROM DUAL;
         INSERT INTO NCARSUPART(CODCARSUPART, DEN_CARSUPART) VALUES (aCODCARACTSUPLIM, V_REC.DENCARACTSUPLIM);
       END IF;

      END IF;

      aUMP := UMIMPLICITA;
      IF NVL(V_REC.DEN_UM, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN

        BEGIN
           SELECT CODUM INTO aCOD FROM NUM U WHERE UPPER(U.DEN_UM) = UPPER(V_REC.DEN_UM);
           EXCEPTION WHEN OTHERS THEN aCOD := 0;
        END;
        IF aCOD &lt;&gt; 0 THEN
          aUMP := aCOD;
        END IF;

      END IF;

    -- delete x;
    -- insert into x(view_name) values(&apos;CODUM &apos; || aUMP);
    -- commit;

      aGEST := GEST_IMPLICITA;
      IF NVL(V_REC.GESTIMPLICITA, 0) &lt;&gt; 0 THEN
        aGEST := V_REC.GESTIMPLICITA;
      END IF;


      aCODIOART := CODIOARTIMPLICIT;
      IF NVL(V_REC.CONTIMPLICIT, 0) &lt;&gt; 0 THEN
        aCODIOART := V_REC.CONTIMPLICIT;
      END IF;




    IF V_REC.CODOBIECT &lt; 0 THEN

      SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO aCODOBJ FROM DUAL;
      SELECT SEQ_NART_CODARTICOL.NEXTVAL INTO aCODART FROM DUAL;

      IF aCODCLASA = 0 THEN
        aCODCLASA := CLASAIMPLICITA;
      END IF;

      UPDATE TMP_NARTOBJ_IMPORT
      SET
        CODOBIECTNOU = aCODOBJ
      WHERE
        CODOBIECT = V_REC.CODOBIECT;

      IF PKG_LIST_STRUCT.TMPEXISTS(&apos;TMP_NARTOBJEXT&apos;) = 1 THEN
        S  := &apos; BEGIN
                UPDATE TMP_NARTOBJEXT
                SET
                  CODOBIECT = &apos; || TO_CHAR(aCODOBJ) ||
              &apos; WHERE
                   CODOBIECT = &apos; || TO_CHAR(V_REC.CODOBIECT) ||  &apos;;END;&apos;;



        EXECUTE IMMEDIATE S;
      END IF;

      UPDATE TMP_PRETM
      SET
        CODOBIECT = aCODOBJ
      WHERE
        CODOBIECT = V_REC.CODOBIECT;

      UPDATE TMP_NARTAMB
      SET
        CODOBIECT = aCODOBJ
      WHERE
        CODOBIECT = V_REC.CODOBIECT;


      UPDATE TMP_NARTCLI
      SET
        CODOBIECT = aCODOBJ
      WHERE
        CODOBIECT = V_REC.CODOBIECT;


      INSERT INTO NART(CODARTICOL, DEN_ARTICOL, TIPARTICOL, UM, UM1, UM2, CLASA, COMENZIONLINE, CASADEMARCAT, CODEXTERNART, TIPSERIE, D1, D2, D3, RELATIEUM1, RELATIEUM2, CLASASTATIST, CODCENTRU, CONTSERVICIU, DCI, CLASAW, CONSTRUCTIENOUA, RISCFISCAL)
      VALUES (aCODART, SUBSTR(V_REC.DENUMIRE,1,100), NVL(V_REC.TIPARTICOL, 0), aUMP, V_REC.UM1, V_REC.UM2, aCODCLASA, aCOMENZIONLINE, VANDUTLACASADEMARCAT, V_REC.CODCATALOG, NVL(V_REC.TIPSERIE, 0), V_REC.D1, V_REC.D2, V_REC.D3, V_REC.RELATIEUM1, V_REC.RELATIEUM2, V_REC.CODCLASEAS, V_REC.CODCENTRU,
      CASE WHEN  NVL(V_REC.TIPARTICOL, 0) = 0 THEN NULL
           ELSE (SELECT CODCONT FROM NCONT WHERE SIMBOL = V_REC.SIMBOL_CONTSERV)
      END,
      V_REC.DCI,
      aCODCLASAW,
      V_REC.CONSTRUCTIENOUA, 
      V_REC.RISCFISCAL
      );

      NotifyModif(1, aCODART, &apos;NART&apos;);

      INSERT INTO NART1(CODARTICOL1, CODARTICOL, CODTVA, ANSTART, LUNASTART, ALSTART, ALSTOP)
      VALUES (SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, CODTVAIMPLICIT, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999);

      INSERT INTO NARTOBJ(CODOBIECT, CODARTICOL, CODEXTERN, CODINTERN, CODVAMAL, MASA, VOLUM,  DENUMIRE, CODPRODUCATOR, CODCARACT,  ROTUNJIRE, ROTVALUTA, TERMENPLATA, CODCNAS, OBS, LUNIGARANTIE, GREUTSPECIFICA, USESTOCMED, FARACMDFURN, FARANIVELAPROB, DURMAXAPROV, PRODUSPROPRIU, PRETMINIM, PROMOTIE, DESCARCAREINTEGRALA, DISCPROMO, INACTIV, BLOCAT, COEFCNAS,
                          TARAORIGINE, DATAADAUGARII, CODCPV, CODD394, EXPORTEMCS, CODNC, CODACCIZABIL, NEFACTURABIL, ADAOSEXCEPTIE, ZILEVALABIL)
      VALUES (aCODOBJ, aCODART, V_REC.CODEXTERN, V_REC.CODINTERN, V_REC.CODVAMAL, V_REC.MASA, V_REC.VOLUM, V_REC.DENUMIRE, aCODPRODUCATOR, ACODCARACTSUPLIM, ROTINTRARE, ROTIESIRE, V_REC.TERMENPLATA, V_REC.CODCNAS, V_REC.OBS, V_REC.LUNIGARANTIE, V_REC.GREUTSPECIFICA, V_REC.USESTOCMED, V_REC.FARACMDFURN, V_REC.FARANIVELAPROB, V_REC.DURMAXAPROV, V_REC.PRODUSPROPRIU, V_REC.PRETMINIM, V_REC.PROMOTIE, v_DescarcareIntegrala, V_REC.DISCPROMO, V_REC.INACTIV, V_REC.BLOCAT, V_REC.COEFCNAS,
              V_REC.TARAORIGINE,
              CASE
                WHEN V_REC.DATAADAUGARII IS NOT NULL THEN  V_REC.DATAADAUGARII
                ELSE SYSDATE
              END,
              V_REC.CODCPV,
              V_REC.CODD394, 
              V_REC.EXPORTEMCS, 
              V_REC.CODNC, 
              V_REC.CODACCIZABIL, 
              V_REC.NEFACTURABIL,
              V_REC.ADAOSEXCEPTIE,
              V_REC.ZILEVALABIL
              );

      INSERT INTO NARTOBJ1(CODOBIECT1, CODOBIECT, ANSTART, LUNASTART, PRETMAXIMAL, GRUPA, PRETREFERINTA, PUNCTESECTIE, TIPPRET, ALSTART, ALSTOP)
      VALUES (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, aCODOBJ, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, V_REC.PRETMAXIMAL, V_REC.GRUPA, V_REC.PRETREFERINTA, V_REC.PUNCTESECTIE, V_REC.TIPPRET, 0, 99999);

      INSERT INTO NARTOBJSUBUNIT(CODS, CODOBIECT, SUBUNITATE, STOCMIN, STOCMAX, STOCMED)
      VALUES (SEQ_NARTOBJSUBUNIT_CODS.NEXTVAL, aCODOBJ, SUBUNITATEIMPORT, V_REC.STOCMIN, V_REC.STOCMAX, V_REC.STOCMED);




      IF aGEST &lt;&gt; 0 OR aCODIOART &lt;&gt; 0 OR NVL(V_REC.LOCATIEIMPLICITA, 0) &lt;&gt; 0 THEN
        INSERT INTO NARTIMPLICITE(CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA)
        VALUES (SEQ_NARTIMPLICITE_CODIMPLICIT.NEXTVAL, aCODART, SUBUNITATEIMPORT, aCODIOART, aGEST, V_REC.LOCATIEIMPLICITA);
      END IF;

     FOR V_REC_AMB IN (SELECT * FROM TMP_NARTAMB WHERE CODOBIECT = aCODOBJ)
     LOOP
       INSERT INTO NARTAMB(CODAMB, CODOBIECT, UMSEC, CODEXTERN, LUNGIME, LATIME, INALTIME, GREUTSPECIFICA, MASA)
                   VALUES(SEQ_NARTAMB_CODAMB.NEXTVAL, V_REC_AMB.CODOBIECT, V_REC_AMB.UMSEC, V_REC_AMB.CODEXTERN, V_REC_AMB.LUNGIME, V_REC_AMB.LATIME, V_REC_AMB.INALTIME, V_REC_AMB.GREUTSPECIFICA, V_REC_AMB.MASA);
     END LOOP;


     FOR V_REC_CLI IN (SELECT * FROM TMP_NARTCLI WHERE CODOBIECT = aCODOBJ)
     LOOP
       INSERT INTO NARTCLI(CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, CODLACLIENT, IMPLICIT, ZILESTOC)
                   VALUES(SEQ_NARTCLI_CODARTCLI.NEXTVAL, V_REC_CLI.CODOBIECT, V_REC_CLI.CODPART, V_REC_CLI.DENUMIRE, V_REC_CLI.CODEXTERN, V_REC_CLI.CODLACLIENT, 
                          V_REC_CLI.IMPLICIT, V_REC_CLI.ZILESTOC);
     END LOOP;



      I := 0;
      FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = aCODOBJ ORDER BY INDEXLOCAL)
      LOOP
        I := I + 1;
        INSERT INTO PRETM(CODPRETM,
                          CODOBIECT,
                          CODCATPRET,
                          INDEXLOCAL,
                          LEI,
                          VALUTA,
                          PROC,
                          MONEDA,
                          SUBUNITATEA,
                          IMPLICIT)
        VALUES (SEQ_PRETM_CODPRETM.NEXTVAL,
                V_REC_PRET.CODOBIECT,
                V_REC_PRET.CODCATPRET,
                V_REC_PRET.INDEXLOCAL,
                V_REC_PRET.LEI,
                V_REC_PRET.VALUTA,
                V_REC_PRET.PROC,
                V_REC_PRET.MONEDA,
                V_REC_PRET.SUBUNITATEA,
                DECODE(I, 1, 1, 0));
      END LOOP;

      IF aSyncPretRetail = &apos;1&apos; THEN
         FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = aCODOBJ ORDER BY INDEXLOCAL)
         LOOP  
           PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_PRET.CODOBIECT, V_REC_PRET.SUBUNITATEA);
         END LOOP;  
      END IF;

      IF aMemoModiPret = &apos;1&apos; THEN
         FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = aCODOBJ ORDER BY INDEXLOCAL)
         LOOP  
            PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_PRET.CODOBIECT, V_REC_PRET.SUBUNITATEA);
         END LOOP;  
      END IF;


      IF PKG_LIST_STRUCT.TMPEXISTS(&apos;TMP_NARTOBJEXT&apos;) = 1 THEN

         ColoaneExtensie   := &apos;&apos;;  V_Rec_ColExtensie := &apos;&apos;;

         FOR V_REC_STR IN (select * from user_tab_cols where table_name = &apos;TMP_NARTOBJEXT&apos; AND COLUMN_ID &gt; 2 ORDER BY COLUMN_ID)
         LOOP
           ColoaneExtensie   := ColoaneExtensie || &apos;,&apos; || V_REC_STR.COLUMN_NAME;
           V_Rec_ColExtensie := V_Rec_ColExtensie || &apos;, V_REC_EXT.&apos; || V_REC_STR.COLUMN_NAME;
         END LOOP ;

         S := &apos;BEGIN
               FOR V_REC_EXT IN (SELECT * FROM TMP_NARTOBJEXT WHERE CODOBIECT = &apos; || TO_CHAR(aCODOBJ) || &apos;)
               LOOP
                 INSERT INTO NARTOBJEXT(CODNARTOBJEXT,
                                        CODOBIECT &apos; || ColoaneExtensie || &apos;
                                        )
                 VALUES (SEQ_NARTOBJEXT_CODNARTOBJEXT.NEXTVAL,
                         V_REC_EXT.CODOBIECT &apos; || V_Rec_ColExtensie || &apos;
                        );
               END LOOP;
               END;&apos;;
               
    --     delete x;
    --     insert into x(test) values(s);
         EXECUTE IMMEDIATE S;

      END IF;


    ELSE


      FOR V_REC_AMB IN (SELECT * FROM TMP_NARTAMB WHERE CODOBIECT = V_REC.CODOBIECT)
      LOOP
        SELECT COUNT(*) INTO NR
        FROM
          NARTAMB
        WHERE
          CODOBIECT = V_REC.CODOBIECT
          AND UMSEC = V_REC_AMB.UMSEC;

        IF NR = 0 THEN
          INSERT INTO NARTAMB(CODAMB, CODOBIECT, UMSEC, CODEXTERN, LUNGIME, LATIME, INALTIME, GREUTSPECIFICA, MASA)
                      VALUES(SEQ_NARTAMB_CODAMB.NEXTVAL, V_REC_AMB.CODOBIECT, V_REC_AMB.UMSEC, V_REC_AMB.CODEXTERN, V_REC_AMB.LUNGIME, V_REC_AMB.LATIME, V_REC_AMB.INALTIME, V_REC_AMB.GREUTSPECIFICA, V_REC_AMB.MASA);
        ELSE
          UPDATE NARTAMB
          SET
            CODEXTERN      = V_REC_AMB.CODEXTERN,
            LUNGIME        = V_REC_AMB.LUNGIME,
            LATIME         = V_REC_AMB.LATIME,
            INALTIME       = V_REC_AMB.INALTIME,
            GREUTSPECIFICA = V_REC_AMB.GREUTSPECIFICA,
            MASA           = V_REC_AMB.MASA
          WHERE
            CODOBIECT = V_REC.CODOBIECT
            AND UMSEC = V_REC_AMB.UMSEC;
        END IF;

      END LOOP;


      FOR V_REC_CLI IN (SELECT * FROM TMP_NARTCLI WHERE CODOBIECT = V_REC.CODOBIECT)
      LOOP
        SELECT COUNT(*) INTO NR
        FROM
          NARTCLI
        WHERE
          CODOBIECT = V_REC.CODOBIECT
          AND CODPART = V_REC_CLI.CODPART;

        IF NR = 0 THEN
          INSERT INTO NARTCLI(CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, CODLACLIENT, IMPLICIT, ZILESTOC)
                      VALUES(SEQ_NARTCLI_CODARTCLI.NEXTVAL, V_REC_CLI.CODOBIECT, V_REC_CLI.CODPART, V_REC_CLI.DENUMIRE, V_REC_CLI.CODEXTERN, V_REC_CLI.CODLACLIENT, 
                             V_REC_CLI.IMPLICIT, V_REC_CLI.ZILESTOC);
        ELSE
          UPDATE NARTCLI
          SET
            DENUMIRE =  CASE
                           WHEN V_REC_CLI.DENUMIRE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DENLACLIENT&apos;) &gt; 0 THEN V_REC_CLI.DENUMIRE
                           ELSE DENUMIRE
                        END,
            CODEXTERN =  CASE
                            WHEN V_REC_CLI.CODEXTERN IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODLACLIENT&apos;) &gt; 0 THEN V_REC_CLI.CODEXTERN
                            ELSE CODEXTERN
                         END, 
            CODLACLIENT = CASE
                             WHEN V_REC_CLI.CODLACLIENT IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODEXTERNLACLIENT&apos;) &gt; 0 THEN V_REC_CLI.CODLACLIENT
                             ELSE CODLACLIENT
                          END, 
           ZILESTOC     = CASE
                             WHEN V_REC_CLI.ZILESTOC IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;ZILESTOC&apos;) &gt; 0 THEN V_REC_CLI.ZILESTOC
                             ELSE ZILESTOC
                          END, 
            IMPLICIT = CASE
                          WHEN V_REC_CLI.IMPLICIT IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;IMPLICITCODCLIENT&apos;) &gt; 0 THEN V_REC_CLI.IMPLICIT
                          ELSE IMPLICIT
                       END 
          WHERE
            CODOBIECT = V_REC.CODOBIECT
            AND CODPART = V_REC_CLI.CODPART;
        END IF;

      END LOOP;



      FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = V_REC.CODOBIECT ORDER BY INDEXLOCAL)
      LOOP
        SELECT COUNT(*) INTO NR
        FROM
          PRETM
        WHERE
          CODOBIECT = V_REC_PRET.CODOBIECT
          AND SUBUNITATEA = V_REC_PRET.SUBUNITATEA
          AND CODCATPRET = V_REC_PRET.CODCATPRET;


        IF NR = 0 THEN

          SELECT COUNT(*) INTO I FROM PRETM  WHERE CODOBIECT = V_REC_PRET.CODOBIECT AND SUBUNITATEA = V_REC_PRET.SUBUNITATEA;

          IF I = 0 THEN aIMPLICIT := 1; ELSE aIMPLICIT := 0; END IF;

          INSERT INTO PRETM(CODPRETM,
                            CODOBIECT,
                            CODCATPRET,
                            INDEXLOCAL,
                            LEI,
                            VALUTA,
                            PROC,
                            MONEDA,
                            SUBUNITATEA,
                            IMPLICIT)
          VALUES (SEQ_PRETM_CODPRETM.NEXTVAL,
                  V_REC_PRET.CODOBIECT,
                  V_REC_PRET.CODCATPRET,
                  V_REC_PRET.INDEXLOCAL,
                  V_REC_PRET.LEI,
                  V_REC_PRET.VALUTA,
                  V_REC_PRET.PROC,
                  V_REC_PRET.MONEDA,
                  V_REC_PRET.SUBUNITATEA,
                  aIMPLICIT);
        ELSE
          IF V_REC_PRET.DETALIERE = &apos;1&apos; THEN
            UPDATE PRETM
            SET
              LEI        = V_REC_PRET.LEI,
              VALUTA     = V_REC_PRET.VALUTA,
              PROC       = V_REC_PRET.PROC,
              MONEDA     = V_REC_PRET.MONEDA,
              INDEXLOCAL = V_REC_PRET.INDEXLOCAL
            WHERE
              CODOBIECT       = V_REC_PRET.CODOBIECT
              AND SUBUNITATEA = V_REC_PRET.SUBUNITATEA
              AND CODCATPRET  = V_REC_PRET.CODCATPRET;
          END IF;
        END IF;
      END LOOP;

      IF aSyncPretRetail = &apos;1&apos; THEN
         FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = V_REC.CODOBIECT)
         LOOP  
           PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_PRET.CODOBIECT, V_REC_PRET.SUBUNITATEA);
         END LOOP;  
      END IF;

      IF aMemoModiPret = &apos;1&apos; THEN
         FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE CODOBIECT = V_REC.CODOBIECT ORDER BY INDEXLOCAL)
         LOOP  
            PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_PRET.CODOBIECT, V_REC_PRET.SUBUNITATEA);
         END LOOP;  
      END IF;



      IF PKG_LIST_STRUCT.TMPEXISTS(&apos;TMP_NARTOBJEXT&apos;) = 1 THEN

         ColoaneExtensie   := &apos;&apos;;  V_Rec_ColExtensie := &apos;&apos;;

         FOR V_REC_STR IN (select * from user_tab_cols where table_name = &apos;TMP_NARTOBJEXT&apos; AND COLUMN_ID &gt; 2 ORDER BY COLUMN_ID)
         LOOP
           ColoaneExtensie   := ColoaneExtensie || &apos;,&apos; || V_REC_STR.COLUMN_NAME;
           V_Rec_ColExtensie := V_Rec_ColExtensie || &apos;, V_REC_EXT.&apos; || V_REC_STR.COLUMN_NAME;
         END LOOP ;





        S := &apos;BEGIN
              FOR V_REC_EXT IN (SELECT * FROM TMP_NARTOBJEXT WHERE CODOBIECT = &apos; || TO_CHAR(V_REC.CODOBIECT) || &apos;)
              LOOP
                 DELETE FROM NARTOBJEXT WHERE CODOBIECT = V_REC_EXT.CODOBIECT;
                 INSERT INTO NARTOBJEXT(CODNARTOBJEXT,
                                        CODOBIECT &apos; || ColoaneExtensie || &apos;
                                         )
                 VALUES (SEQ_NARTOBJEXT_CODNARTOBJEXT.NEXTVAL,
                         V_REC_EXT.CODOBIECT &apos; || V_Rec_ColExtensie || &apos;
                        );

              END LOOP;
              END;&apos;;
              
              
--         INSERT INTO X(TEST) VALUES(S);
         EXECUTE IMMEDIATE S;
      END IF;

      BEGIN
        SELECT CODARTICOL INTO aCODART FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT;
        EXCEPTION WHEN OTHERS THEN aCODART := 0;
      END;
      IF aCODART &lt;&gt; 0 THEN
        UPDATE NART
        SET
         CLASAW   = CASE
                       WHEN V_REC.SIMBOL_CLASEASW IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;SIMBOL_CLASEASW&apos;) &gt; 0 THEN aCODCLASAW
                       ELSE CLASAW
                    END,
         TIPSERIE = CASE
                       WHEN V_REC.TIPSERIE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;TIPSERIE&apos;) &gt; 0 THEN V_REC.TIPSERIE
                       ELSE TIPSERIE
                    END,

         CONSTRUCTIENOUA = CASE
                       WHEN V_REC.CONSTRUCTIENOUA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CONSTRUCTIENOUA&apos;) &gt; 0 THEN V_REC.CONSTRUCTIENOUA
                       ELSE CONSTRUCTIENOUA
                    END,

         RISCFISCAL = CASE
                       WHEN V_REC.RISCFISCAL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;RISCFISCAL&apos;) &gt; 0 THEN V_REC.RISCFISCAL
                       ELSE RISCFISCAL
                    END,


         DCI      = CASE
                       WHEN V_REC.DCI IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DCI&apos;) &gt; 0 THEN V_REC.DCI
                       ELSE DCI
                    END,

         D1        = CASE
                       WHEN V_REC.D1 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;D1&apos;) &gt; 0 THEN V_REC.D1
                       ELSE D1
                     END,
         D2        = CASE
                       WHEN V_REC.D2 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;D2&apos;) &gt; 0 THEN V_REC.D2
                       ELSE D2
                     END,
         D3        = CASE
                       WHEN V_REC.D3 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;D3&apos;) &gt; 0 THEN V_REC.D3
                       ELSE D3
                     END,
         UM1       = CASE
                       WHEN V_REC.UM1 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DEN_UM1&apos;) &gt; 0 THEN V_REC.UM1
                       ELSE UM1
                     END,
         UM2       = CASE
                       WHEN V_REC.UM2 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DEN_UM2&apos;) &gt; 0 THEN V_REC.UM2
                       ELSE UM2
                     END,
         RELATIEUM1 = CASE
                       WHEN V_REC.RELATIEUM1 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;RELATIEUM1&apos;) &gt; 0 THEN V_REC.RELATIEUM1
                       ELSE RELATIEUM1
                     END,
         RELATIEUM2 = CASE
                       WHEN V_REC.RELATIEUM2 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;RELATIEUM2&apos;) &gt; 0 THEN V_REC.RELATIEUM2
                       ELSE RELATIEUM2
                     END,
         CLASASTATIST = CASE
                         WHEN V_REC.CODCLASEAS IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;SIMBOL_CLASEAS&apos;) &gt; 0 THEN V_REC.CODCLASEAS
                         ELSE CLASASTATIST
                        END,
         CODCENTRU = CASE
                       WHEN V_REC.CODCENTRU IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;SIMBOL_CENTRUCOST&apos;) &gt; 0 THEN V_REC.CODCENTRU
                       ELSE CODCENTRU
                     END,

         CONTSERVICIU = CASE
                       WHEN V_REC.SIMBOL_CONTSERV IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;SIMBOL_CONTSERV&apos;) &gt; 0 THEN
                         (
                          CASE WHEN  NVL(V_REC.TIPARTICOL, 0) = 0 THEN NULL
                               ELSE (SELECT CODCONT FROM NCONT WHERE SIMBOL = V_REC.SIMBOL_CONTSERV)
                          END
                         )
                       ELSE CONTSERVICIU
                     END
        WHERE
          CODARTICOL = aCODART;

       if (ProcTVAInXLS = 1)and( SUPRASCRIERE_COLOANA(&apos;PROCTVA&apos;) &gt; 0) then
         AnLunaStartUpdate :=  PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
         DELETE TMP_NART1;

         FOR V_REC_AL IN 
         (SELECT * FROM NART1 
          WHERE 
             CODARTICOL = aCODART
             AND ALSTART &lt;= AnLunaStartUpdate
             AND ALSTOP  &gt;= AnLunaStartUpdate
          )
          LOOP
             IF V_REC_AL.ANSTART * 12 + V_REC_AL.LUNASTART = AnLunaStartUpdate THEN
              
               UPDATE NART1
               SET
                 CODTVA = V_REC.CODTVA
               WHERE
                 CODARTICOL1 = V_REC_AL.CODARTICOL1;      
             ELSE -- trebuie sa sparg intervalul
               --INSEREZ INTERVAL NOU
               INSERT INTO TMP_NART1 (CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE,CODTAXA1, CODTAXA2, CODACCIZEDVI, ANSTART, LUNASTART, ALSTART, ALSTOP)
               VALUES(SEQ_NART1_CODARTICOL1.NEXTVAL, 
                      V_REC_AL.CODARTICOL, 
                      V_REC.CODTVA, 
                      V_REC_AL.CODACCIZE, 
                      V_REC_AL.CODTAXA1, 
                      V_REC_AL.CODTAXA2,  
                      V_REC_AL.CODACCIZEDVI,
                      PKG_GLOBALS.ANLUCRU,  
                      PKG_GLOBALS.LUNALUCRU,
                      AnLunaStartUpdate,
                      V_REC_AL.ALSTOP
                      );
               UPDATE NART1 --INTERVALUL VECHI
               SET
                 ALSTOP = AnLunaStartUpdate - 1
               WHERE
                 CODARTICOL1 = V_REC_AL.CODARTICOL1;      
             END IF;      
          END LOOP;     
        
          INSERT INTO NART1(CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, ANSTART, LUNASTART, CODACCIZEDVI, ALSTART, ALSTOP)
          SELECT 
            CODARTICOL1, 
            CODARTICOL, 
            CODTVA, 
            CODACCIZE, 
            CODTAXA1, 
            CODTAXA2, 
            ANSTART, 
            LUNASTART, 
            CODACCIZEDVI, 
            ALSTART, 
            ALSTOP
          FROM
            TMP_NART1;  
           
          DELETE TMP_NART1; 
         
/*
          UPDATE NART1
          SET
            CODTVA = V_REC.CODTVA
          WHERE
            CODARTICOL = aCODART
            AND
              PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU &gt;= ALSTART
            AND  
              PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU &lt;= ALSTOP;
*/      
       end if;  

       NotifyModif(0, aCODART, &apos;NART&apos;);

      END IF;


      UPDATE NARTOBJ
      SET
        GREUTSPECIFICA= CASE
                         WHEN V_REC.GREUTSPECIFICA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;GREUTSPECIFICA&apos;) &gt; 0 THEN V_REC.GREUTSPECIFICA
                         ELSE GREUTSPECIFICA
                        END,
        MASA          = CASE
                         WHEN V_REC.MASA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;MASA&apos;) &gt; 0 THEN V_REC.MASA
                         ELSE MASA
                        END,
        VOLUM         = CASE
                          WHEN V_REC.VOLUM IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;VOLUM&apos;) &gt; 0 THEN V_REC.VOLUM
                          ELSE VOLUM
                        END,
        LUNIGARANTIE  = CASE
                          WHEN V_REC.VOLUM IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;LUNIGARANTIE&apos;) &gt; 0 THEN V_REC.VOLUM
                          ELSE LUNIGARANTIE
                        END,
        CODPRODUCATOR = CASE
                          WHEN NVL(aCODPRODUCATOR, 0) &lt;&gt; 0 AND SUPRASCRIERE_COLOANA(&apos;DENPRODUCATOR&apos;) &gt; 0 THEN aCODPRODUCATOR
                          ELSE CODPRODUCATOR
                        END,


        CODCARACT = CASE
                      WHEN NVL(aCODCARACTSUPLIM, 0) &lt;&gt; 0 AND SUPRASCRIERE_COLOANA(&apos;DENCARACTSUPLIM&apos;) &gt; 0 THEN aCODCARACTSUPLIM
                      ELSE CODCARACT
                    END,

--        ROTUNJIRE     = ROTINTRARE,

--        ROTVALUTA     = ROTIESIRE,

        CODINTERN     = CASE
                          WHEN V_REC.CODINTERN IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODINTERN&apos;) &gt; 0 THEN V_REC.CODINTERN
                          ELSE CODINTERN
                        END,

        CODEXTERN     = CASE
                          WHEN V_REC.CODEXTERN IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODEXTERN&apos;) &gt; 0 THEN V_REC.CODEXTERN
                          ELSE CODEXTERN
                        END,


        CODVAMAL     = CASE
                         WHEN V_REC.CODVAMAL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODVAMAL&apos;) &gt; 0 THEN V_REC.CODVAMAL
                         ELSE CODVAMAL
                        END,
        CODCNAS      = CASE
                         WHEN V_REC.CODCNAS IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODCNAS&apos;) &gt; 0 THEN V_REC.CODCNAS
                         ELSE CODCNAS
                       END,
        CODCPV       = CASE
                         WHEN V_REC.CODCPV IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODCPV&apos;) &gt; 0 THEN V_REC.CODCPV
                         ELSE CODCPV
                       END,


        CODD394       = CASE
                         WHEN V_REC.CODD394 IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODD394&apos;) &gt; 0 THEN V_REC.CODD394
                         ELSE CODD394
                       END,

        EXPORTEMCS    = CASE
                         WHEN V_REC.EXPORTEMCS IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;EXPORTEMCS&apos;) &gt; 0 THEN V_REC.EXPORTEMCS
                         ELSE EXPORTEMCS
                       END,
                       
        CODNC        = CASE
                         WHEN V_REC.CODNC IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODNC&apos;) &gt; 0 THEN V_REC.CODNC
                         ELSE CODNC
                       END,

        CODACCIZABIL = CASE
                         WHEN V_REC.CODACCIZABIL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;CODACCIZABIL&apos;) &gt; 0 THEN V_REC.CODACCIZABIL
                         ELSE CODACCIZABIL
                       END,

        ADAOSEXCEPTIE = CASE
                         WHEN V_REC.ADAOSEXCEPTIE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;ADAOSEXCEPTIE&apos;) &gt; 0 THEN V_REC.ADAOSEXCEPTIE
                         ELSE ADAOSEXCEPTIE
                       END,
        NEFACTURABIL = CASE
                         WHEN V_REC.NEFACTURABIL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;NEFACTURABIL&apos;) &gt; 0 THEN V_REC.NEFACTURABIL
                         ELSE NEFACTURABIL
                       END,


        OBS           = CASE
                         WHEN V_REC.OBS IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;OBS&apos;) &gt; 0 THEN V_REC.OBS
                         ELSE OBS
                       END,

        TERMENPLATA   = CASE
                         WHEN V_REC.TERMENPLATA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;TERMENPLATA&apos;) &gt; 0 THEN V_REC.TERMENPLATA
                         ELSE TERMENPLATA
                       END,
        DENUMIRE      = CASE
                         WHEN V_REC.DENUMIRE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DENUMIRE&apos;) &gt; 0 THEN V_REC.DENUMIRE
                         ELSE DENUMIRE
                        END,
        USESTOCMED  = CASE
                           WHEN V_REC.USESTOCMED IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;USESTOCMED&apos;) &gt; 0 THEN V_REC.USESTOCMED
                           ELSE USESTOCMED
                          END,
        FARACMDFURN  = CASE
                           WHEN V_REC.FARACMDFURN IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;FARACMDFURN&apos;) &gt; 0 THEN V_REC.FARACMDFURN
                           ELSE FARACMDFURN
                          END,
        FARANIVELAPROB  = CASE
                           WHEN V_REC.FARANIVELAPROB IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;FARANIVELAPROB&apos;) &gt; 0 THEN V_REC.FARANIVELAPROB
                           ELSE FARANIVELAPROB
                          END,
        DURMAXAPROV     = CASE
                           WHEN V_REC.DURMAXAPROV IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DURMAXAPROV&apos;) &gt; 0 THEN V_REC.DURMAXAPROV
                           ELSE FARACMDFURN
                          END,
        PRODUSPROPRIU  = CASE
                           WHEN V_REC.PRODUSPROPRIU IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PRODUSPROPRIU&apos;) &gt; 0 THEN V_REC.PRODUSPROPRIU
                           ELSE PRODUSPROPRIU
                         END,

        PROMOTIE       = CASE
                           WHEN V_REC.PROMOTIE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PROMOTIE&apos;) &gt; 0 THEN V_REC.PROMOTIE
                           ELSE PROMOTIE
                          END,


        DISCPROMO     = CASE
                           WHEN V_REC.DISCPROMO IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DISCPROMO&apos;) &gt; 0 THEN V_REC.DISCPROMO
                           ELSE DISCPROMO
                          END,

        ZILEVALABIL     = CASE
                           WHEN V_REC.ZILEVALABIL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;ZILEVALABIL&apos;) &gt; 0 THEN V_REC.ZILEVALABIL
                           ELSE ZILEVALABIL
                          END,

        INACTIV       = CASE
                           WHEN V_REC.INACTIV IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;INACTIV&apos;) &gt; 0 THEN V_REC.INACTIV
                           ELSE INACTIV
                          END,

        BLOCAT        = CASE
                           WHEN V_REC.BLOCAT IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;BLOCAT&apos;) &gt; 0 THEN V_REC.BLOCAT
                           ELSE BLOCAT
                          END,
        PRETMINIM     = CASE
                           WHEN V_REC.PRETMINIM IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PRETMINIM&apos;) &gt; 0 THEN V_REC.PRETMINIM
                           ELSE PRETMINIM
                         END,
        COEFCNAS      = CASE
                          WHEN V_REC.COEFCNAS IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;COEFCNAS&apos;) &gt; 0 THEN V_REC.COEFCNAS
                          ELSE COEFCNAS
                        END,
        TARAORIGINE   = CASE
                          WHEN V_REC.TARAORIGINE IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;SIMBOL_AUTO_TARA&apos;) &gt; 0 THEN V_REC.TARAORIGINE
                          ELSE TARAORIGINE
                        END,
        DATAADAUGARII = CASE
                         WHEN V_REC.DATAADAUGARII IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DATAADAUGARII&apos;) &gt; 0 THEN V_REC.DATAADAUGARII
                         ELSE DATAADAUGARII
                       END
      WHERE
        CODOBIECT = V_REC.CODOBIECT;


      IF 1 = 1 THEN  -- :1:2:3 NVL(V_REC.STOCMIN, 0) + NVL(V_REC.STOCMAX, 0) + NVL(V_REC.STOCMED, 0) &lt;&gt; 0
        SELECT COUNT(*) INTO NR FROM NARTOBJSUBUNIT
        WHERE
          CODOBIECT = V_REC.CODOBIECT
          AND SUBUNITATE = SUBUNITATEIMPORT
          AND (CODGEST IS NULL OR CODGEST = 0);

        IF NR = 0 THEN
         INSERT INTO NARTOBJSUBUNIT(CODS, CODOBIECT, SUBUNITATE, STOCMIN, STOCMAX, STOCMED)
         VALUES (SEQ_NARTOBJSUBUNIT_CODS.NEXTVAL, V_REC.CODOBIECT, SUBUNITATEIMPORT, V_REC.STOCMIN, V_REC.STOCMAX, V_REC.STOCMED);
        ELSE
          UPDATE NARTOBJSUBUNIT
          SET
            STOCMIN   = CASE
                          WHEN V_REC.STOCMIN IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;STOCMIN&apos;) &gt; 0 THEN V_REC.STOCMIN
                          ELSE STOCMIN
                        END,
            STOCMAX   = CASE
                          WHEN V_REC.STOCMAX IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;STOCMAX&apos;) &gt; 0 THEN V_REC.STOCMAX
                          ELSE STOCMAX
                        END,
            STOCMED   = CASE
                          WHEN V_REC.STOCMED IS NOT NULL  AND SUPRASCRIERE_COLOANA(&apos;STOCMED&apos;) &gt; 0 THEN V_REC.STOCMED
                          ELSE STOCMED
                        END

          WHERE
            CODOBIECT = V_REC.CODOBIECT
            AND SUBUNITATE = SUBUNITATEIMPORT
            AND (CODGEST IS NULL OR CODGEST = 0);

        END IF;

      END IF;

      IF TIPINFOLUNARE = 1 THEN
        SELECT COUNT(*) INTO NR
        FROM NARTOBJ1
        WHERE CODOBIECT = V_REC.CODOBIECT
          AND ANSTART * 12 + LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU;

         IF NR = 0 THEN

          -- verific daca am o descriere anterioara
           SELECT CODOBIECT1 INTO NR
           FROM NARTOBJ1
           WHERE CODOBIECT = V_REC.CODOBIECT
             AND PKG_GLOBALS.ANLUNALUCRU BETWEEN ALSTART AND ALSTOP;

          IF NR = 0 THEN
            INSERT INTO NARTOBJ1(CODOBIECT1, CODOBIECT, ANSTART, LUNASTART, PRETMAXIMAL, GRUPA, PRETREFERINTA, PUNCTESECTIE, TIPPRET)
            VALUES (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, V_REC.CODOBIECT, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, V_REC.PRETMAXIMAL,  V_REC.GRUPA, V_REC.PRETREFERINTA, V_REC.PUNCTESECTIE, V_REC.TIPPRET);
          ELSE
            INSERT INTO NARTOBJ1(CODOBIECT1, CODOBIECT, ANSTART, LUNASTART, PRETMAXIMAL, GRUPA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, PRETREFERINTA, PUNCTESECTIE, TIPPRET)
            SELECT SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, V_REC.CODOBIECT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PRETMAXIMAL, GRUPA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, PRETREFERINTA, PUNCTESECTIE, TIPPRET FROM NARTOBJ1 WHERE CODOBIECT1 = NR;
          END IF;

         END IF;


      END IF;

      PRC_AL_REFRESH(&apos;NARTOBJ1&apos;, V_REC.CODOBIECT);

      UPDATE NARTOBJ1
      SET
        PRETMAXIMAL  = CASE
                         WHEN V_REC.PRETMAXIMAL IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PRETMAXIMAL&apos;) &gt; 0 THEN V_REC.PRETMAXIMAL
                         ELSE PRETMAXIMAL
                       END,
        GRUPA       = CASE
                         WHEN V_REC.GRUPA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;GRUPA&apos;) &gt; 0 THEN V_REC.GRUPA
                         ELSE GRUPA
                       END,

        PRETREFERINTA = CASE
                         WHEN V_REC.PRETREFERINTA IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PRETREFERINTA&apos;) &gt; 0 THEN V_REC.PRETREFERINTA
                         ELSE PRETREFERINTA
                       END,
        PUNCTESECTIE = CASE
                         WHEN V_REC.PUNCTESECTIE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;PUNCTESECTIE&apos;) &gt; 0 THEN V_REC.PUNCTESECTIE
                         ELSE PUNCTESECTIE
                       END,
        TIPPRET      = CASE
                         WHEN V_REC.TIPPRET IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;TIPPRET&apos;) &gt; 0 THEN V_REC.TIPPRET
                         ELSE TIPPRET
                       END
      WHERE CODOBIECT = V_REC.CODOBIECT
        AND PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU BETWEEN ALSTART AND ALSTOP;

    END IF;

    IF aCODCLASA &lt;&gt; 0 THEN
      UPDATE NART
      SET
       CLASA = aCODCLASA
      WHERE
       CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT);
    END IF;

     UPDATE NART
     SET
      DEN_ARTICOL = CASE
                     WHEN V_REC.DENUMIRE IS NOT NULL AND SUPRASCRIERE_COLOANA(&apos;DENUMIRE&apos;) &gt; 0 THEN V_REC.DENUMIRE
                     ELSE DEN_ARTICOL
                   END
     WHERE
      CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT);



     UPDATE NART
     SET
      COMENZIONLINE = aCOMENZIONLINE
     WHERE
      CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
                   AND SUPRASCRIERE_COLOANA(&apos;COMENZIONLINE&apos;) &gt; 0 ;


     UPDATE NART
     SET
      CODEXTERNART = NVL(V_REC.CODCATALOG, CODEXTERNART),
      DCI          = NVL(V_REC.DCI, DCI)
     WHERE
      CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
                   AND SUPRASCRIERE_COLOANA(&apos;CODCATALOG&apos;) &gt; 0 ;


      IF aGEST + aCODIOART + NVL(V_REC.LOCATIEIMPLICITA, 0) &lt;&gt; 0  THEN

        SELECT COUNT(*) INTO NR FROM NARTIMPLICITE
        WHERE
          CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
          AND CODSUBUNIT = SUBUNITATEIMPORT;

        IF NR = 0 THEN
          INSERT INTO NARTIMPLICITE(CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA)
          VALUES (SEQ_NARTIMPLICITE_CODIMPLICIT.NEXTVAL, (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT), SUBUNITATEIMPORT, aCODIOART, aGEST, V_REC.LOCATIEIMPLICITA);
        ELSE

          IF aGEST &lt;&gt; 0 THEN
              UPDATE NARTIMPLICITE
              SET
                GESTIMPLICITA = aGEST
              WHERE
               CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
                AND CODSUBUNIT = SUBUNITATEIMPORT;
          END IF;

          IF aCODIOART&lt;&gt; 0 THEN
              UPDATE NARTIMPLICITE
              SET
                CONTIMPLICIT = aCODIOART
              WHERE
                CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
                AND CODSUBUNIT = SUBUNITATEIMPORT;
          END IF;

          IF NVL(V_REC.LOCATIEIMPLICITA, 0) &lt;&gt; 0 THEN
              UPDATE NARTIMPLICITE
              SET
                LOCATIEIMPLICITA = V_REC.LOCATIEIMPLICITA
              WHERE
               CODARTICOL = (SELECT CODARTICOL FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT)
                AND CODSUBUNIT = SUBUNITATEIMPORT;
          END IF;

        END IF;
      END IF;



  END LOOP;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID, &apos;MON_6&apos;) THEN
    FOR V_REC IN
     (SELECT A.*
      FROM
        TMP_NARTOBJ_IMPORT OI,
        NARTOBJ O,
        NART A
      WHERE
        NVL(OI.CODOBIECTNOU, 0) &lt;&gt; 0
        AND OI.CODOBIECTNOU = O.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
     )
    LOOP
       WINMADMIN.PKG_USERFIRME.PostLog(&apos;NART&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        V_REC.CODARTICOL,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null, V_REC.DEN_ARTICOL,null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END LOOP;



    FOR V_REC IN
     (SELECT A.*
      FROM
        TMP_NARTOBJ_IMPORT OI,
        NARTOBJ O,
        NART A
      WHERE
        OI.CODOBIECT = O.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
     )
    LOOP
       WINMADMIN.PKG_USERFIRME.PostLog(&apos;NART&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        V_REC.CODARTICOL,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null, V_REC.DEN_ARTICOL,null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END LOOP;


  END IF;




  -- la categoriile de pret procentuale actualizez lei/valuta
  FOR V_REC_PRET IN (SELECT * FROM TMP_PRETM WHERE PROC IS NOT NULL)
  LOOP
    IF V_REC_PRET.CODCATMASTER IS NULL THEN -- procent din implicit
      BEGIN
        SELECT LEI, VALUTA, COALESCE(MONEDA, 0) INTO aLEI, aVALUTA, aMONEDA
        FROM
          PRETM PM
        WHERE
          PM.IMPLICIT = 1
          AND PM.CODOBIECT = V_REC_PRET.CODOBIECT
          AND PM.SUBUNITATEA = V_REC_PRET.SUBUNITATEA;   
        EXCEPTION WHEN OTHERS THEN 
          aLEI := 0; aVALUTA := 0; aMONEDA := 0;
      END;  
    ELSE -- procent din alta categorie
      BEGIN
        SELECT LEI, VALUTA, COALESCE(MONEDA, 0) INTO aLEI, aVALUTA, aMONEDA
        FROM
          PRETM PM
        WHERE
          PM.CODCATPRET = V_REC_PRET.CODCATMASTER
          AND PM.CODOBIECT = V_REC_PRET.CODOBIECT
          AND PM.SUBUNITATEA = V_REC_PRET.SUBUNITATEA;   
        EXCEPTION WHEN OTHERS THEN 
          aLEI := 0; aVALUTA := 0; aMONEDA := 0;
      END;  
    END IF;    
    
    IF (COALESCE(aLEI, 0) &lt;&gt; 0) OR (COALESCE(aVALUTA, 0) &lt;&gt; 0) THEN   
      UPDATE PRETM
      SET
        LEI    = aLEI    * V_REC_PRET.PROC / 100,
        VALUTA = aVALUTA * V_REC_PRET.PROC / 100,
        MONEDA = aMONEDA
      WHERE
        CODCATPRET      = V_REC_PRET.CODCATPRET
        AND CODOBIECT   = V_REC_PRET.CODOBIECT
        AND SUBUNITATEA = V_REC_PRET.SUBUNITATEA;  
    END IF;    
  END LOOP;    

  -- preturi pe UM ambalare 

  FOR V_REC IN (SELECT * FROM TMP_PRETMAMB)
  LOOP
    
    BEGIN
      SELECT CODAMB INTO aCODAMB FROM NARTAMB WHERE CODOBIECT = V_REC.CODOBIECT AND UMSEC = V_REC.UMSEC AND ROWNUM = 1;
      EXCEPTION WHEN OTHERS THEN
        aCODAMB := 0;   
    END;   

    BEGIN
      SELECT CODPRETM, MONEDA INTO aCODPRETM, aMONEDA FROM PRETM WHERE CODOBIECT = V_REC.CODOBIECT AND CODCATPRET = V_REC.CODCATPRET AND SUBUNITATEA = V_REC.SUBUNITATEA;
      EXCEPTION WHEN OTHERS THEN
       aCODPRETM := 0;   
    END;  
    
    
    IF aCODAMB &gt; 0 AND aCODPRETM &gt; 0 THEN
       BEGIN
         SELECT CODPRETMAMB INTO aCODPRETMAMB FROM PRETMAMB WHERE CODPRETM = aCODPRETM AND CODAMB = aCODAMB;
         EXCEPTION WHEN OTHERS THEN
           aCODPRETMAMB := 0;
       END;  
         
     IF aCODPRETMAMB &gt; 0 THEN
       UPDATE PRETMAMB
       SET
         LEI    = CASE 
                    WHEN COALESCE(aMONEDA, 0) = 0 THEN V_REC.LEI
                    ELSE NULL
                  END,   
         VALUTA = CASE 
                    WHEN COALESCE(aMONEDA, 0)&gt; 0 THEN V_REC.LEI
                    ELSE NULL
                   END   
       WHERE
         CODPRETMAMB = aCODPRETMAMB;    
     ELSE
       INSERT INTO PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
       VALUES (SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL, 
               aCODPRETM, 
               aCODAMB,
               CASE 
                  WHEN COALESCE(aMONEDA, 0) = 0 THEN V_REC.LEI
                  ELSE NULL
               END,                  
               CASE 
                 WHEN COALESCE(aMONEDA, 0)&gt; 0 THEN V_REC.LEI
                 ELSE NULL
               END   
              ); 
     END IF;         
    END IF;
  END LOOP;    
  

  COMMIT;
END;



FUNCTION CLONEAZA_OBIECT(aCodArticol IN NUMBER ) RETURN NUMBER IS
pragma autonomous_transaction;

CodObjSursa     number(20);
codObjNou       number(20);
denObjNou       varchar2(200);
CodExtObjSursa  varchar2(100) := null;
CodExtObjNou    varchar2(100);
KConst          number(20);
PROC            NUMBER(8,5);
MAJORARE        number(20,7) := 1;
MaxGRUPA        VARCHAR2(5) := &apos;!&apos;;
aOrdine         VARCHAR2(5) := &apos;!&apos;;
MaxOrdine       VARCHAR2(5) := &apos;!&apos;;
CaractObiectGeneric VARCHAR2(10) := &apos;&apos;;

BEGIN
 -- caut obiectul generic fara atribute
 select
   nobj.codobiect,
   nobj.denumire,
   nobj.codextern into CodObjSursa,
   denObjNou,
   CodExtObjSursa
 from
   nartobj nobj
 where
   nobj.codarticol = aCodArticol
   and not exists (select CODOBIECT FROM NATROBJ WHERE CODOBIECT = NOBJ.CODOBIECT);

-- compun denumirea obiectului si codul extern ;
 KConst := pkg_categConst.GetValConstanta(&apos;CodExternAtrib&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU) ;

-- if KConst = 2 then CodExtObjNou := CodExtObjSursa; end if;

  CodExtObjNou := CodExtObjSursa;

  CaractObiectGeneric := NVL(pkg_categConst.GetValConstanta(&apos;CaractObiectGeneric&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU), &apos;&apos;) ;


 FOR V_REC IN (SELECT ATR1.CODVALATR,ATR1.VALOARE,ATR.INDEXLOCAL,atr1.codextern, Atr1.Grupa
               FROM TMP_MANEVRA TMP INNER JOIN NATRIB1 ATR1 ON TMP.CODUNIC   = ATR1.CODVALATR
                                    INNER JOIN NARTATR ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
               WHERE ATR.CODARTICOL = aCodArticol
               ORDER BY  ATR.INDEXLOCAL)
 LOOP
     aOrdine := &apos;&apos;;
     BEGIN
       select VALOARE into aOrdine from TMP_MANEVRA_LISTE where Upper(Nvl(filtru,&apos;?&apos;)) = UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;));
     EXCEPTION
       WHEN no_data_found THEN NULL;
     END;


     if Nvl(aOrdine, &apos;!&apos;) &lt;&gt; &apos;!&apos;  then
       if aOrdine &gt; MaxOrdine then
          MaxOrdine := aOrdine;
          MaxGrupa := UPPER(V_Rec.Grupa);
        end if;
     else
       if UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;)) &gt; MaxGRUPA then MaxGrupa := UPPER(V_Rec.Grupa); end if;
     end if;


   BEGIN
     SELECT Nvl(PROCMAJ,0) INTO PROC FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR AND CODARTICOL = ACODARTICOL;
     EXCEPTION when others then PROC := 0;
   END;

   MAJORARE := MAJORARE * (1 + PROC/100);

   denObjNou := denObjNou||&apos; &apos;||v_rec.valoare;
   if KConst = 1 then
     CodExtObjNou  := CodExtObjNou||&apos; &apos;|| v_rec.valoare;
   end if ;

   if KConst = 2 then
     CodExtObjNou  := CodExtObjNou|| v_rec.codextern;
   end if;


 END LOOP;


 SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO codObjNou FROM DUAL;
-- NARTOBJ
/*
 INSERT INTO NARTOBJ( CODOBIECT, CODARTICOL, CODPRODUCATOR, CODEXTERN, CODINTERN, CODVAMAL, MASA, VOLUM, STOCMIN, STOCMED,  STOCMAX,
                      RETURNABIL, LUNIGARANTIE, OBS, PROCADAOSNIR, ROTUNJIRE, ADAOSEXCEPTIE, PROMOTIE, ROTVALUTA, DENUMIRE,
                      UMAMBALARE, PRETMINIM, TERMENPLATA, DATAADAUGARII, CODPLU, DURMAXAPROV, CODCNAS,
                      CODCARACT, BLOCAT, DISCPROMO, TARAORIGINE, ZILEVALABIL, ZILEDISTRIB,   CODPERISABIL, NEFACTURABIL, GREUTSPECIFICA,
                      PRODUSPROPRIU)
 SELECT  codObjNou, CODARTICOL, CODPRODUCATOR, CodExtObjNou, CODINTERN, CODVAMAL, MASA, VOLUM, STOCMIN, STOCMED,  STOCMAX,
                      RETURNABIL, LUNIGARANTIE, OBS, PROCADAOSNIR, ROTUNJIRE, ADAOSEXCEPTIE, PROMOTIE, ROTVALUTA, denObjNou,
                      UMAMBALARE, PRETMINIM, TERMENPLATA, DATAADAUGARII, CODPLU, DURMAXAPROV, CODCNAS,
                      CODCARACT, BLOCAT, DISCPROMO, TARAORIGINE, ZILEVALABIL, ZILEDISTRIB,  CODPERISABIL, NEFACTURABIL, GREUTSPECIFICA,
                      PRODUSPROPRIU
 FROM NARTOBJ WHERE CODOBIECT = CodObjSursa;

*/

-- NARTOBJ
 INSERT INTO NARTOBJ(
   CODOBIECT,
   CODARTICOL,
   CODPRODUCATOR,
   CODEXTERN,
   MASA,
   VOLUM,
   STOCMIN,
   STOCMED,
   INACTIVCMDONLINE,
   AUTORIZATIE,
   EXPIRAREAUTORIZ,
   MESAJINACTIV,
   STOCMAX,
   RETURNABIL,
   LUNIGARANTIE,
   OBS,
   PROCADAOSNIR,
   ROTUNJIRE,
   ADAOSEXCEPTIE,
   PROMOTIE,
   ROTVALUTA,
   DENUMIRE,
   UMAMBALARE,
   PRETMINIM,
   TERMENPLATA,
   DATAADAUGARII,
   CODPLU,
   USESTOCMED,
   DURMAXAPROV,
   CODCNAS,
   PRODUSPROPRIU,
   CODCARACT,
   BLOCAT,
   DISCPROMO,
   TARAORIGINE,
   ZILEVALABIL,
   ZILEDISTRIB,
   CODPERISABIL,
   NEFACTURABIL,
   GREUTSPECIFICA)
 SELECT
   codObjNou,
   CODARTICOL,
   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPRODUCATOR
    ELSE NULL
   END,
   CodExtObjNou,
   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN MASA
    ELSE NULL
   END,
   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN VOLUM
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMIN
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMED
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN INACTIVCMDONLINE
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN AUTORIZATIE
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN EXPIRAREAUTORIZ
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN MESAJINACTIV
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMAX
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN RETURNABIL
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN LUNIGARANTIE
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN OBS
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN PROCADAOSNIR
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN ROTUNJIRE
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN ADAOSEXCEPTIE
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN PROMOTIE
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN ROTVALUTA
    ELSE NULL
   END,

   denObjNou,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN UMAMBALARE
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN PRETMINIM
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN TERMENPLATA
    ELSE NULL
   END,

   SYSDATE,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPLU
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN USESTOCMED
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN DURMAXAPROV
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN CODCNAS
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN PRODUSPROPRIU
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN CODCARACT
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN BLOCAT
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN DISCPROMO
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN TARAORIGINE
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN ZILEVALABIL
    ELSE NULL
   END,


   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN ZILEDISTRIB
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPERISABIL
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN NEFACTURABIL
    ELSE NULL
   END,

   CASE
    WHEN CaractObiectGeneric = &apos;1&apos; THEN GREUTSPECIFICA
    ELSE NULL
   END

 FROM
   NARTOBJ WHERE CODOBIECT = CodObjSursa;


-- NARTOBJ1
 INSERT INTO NARTOBJ1(CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,PRETREFERINTA,TIPPRETMAX,
                      COMPENSAT,TIPCOMPENSARE,GRUPA,UPLIFT,CODMONEDA,PUNCTE)
 SELECT SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL,codObjNou,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,PRETREFERINTA,TIPPRETMAX,
                      COMPENSAT,TIPCOMPENSARE,GRUPA,UPLIFT,CODMONEDA,PUNCTE
 FROM NARTOBJ1 WHERE CODOBIECT = CodObjSursa;

--NARTOBJSUBUNIT
 INSERT INTO NARTOBJSUBUNIT(CODS,CODOBIECT,SUBUNITATE,STOCMIN,STOCMED,STOCMAX)
 SELECT SEQ_NARTOBJSUBUNIT_CODS.NextVal ,codObjNou, SUBUNITATE,STOCMIN,STOCMED,STOCMAX FROM NARTOBJSUBUNIT
 WHERE CODOBIECT = CodObjSursa;

-- NATROBJ

FOR V_REC IN( SELECT ATR1.CODVALATR,ATR.CODARTATR,ATR1.VALOARE,ATR.INDEXLOCAL
               FROM TMP_MANEVRA TMP INNER JOIN NATRIB1 ATR1 ON TMP.CODUNIC   = ATR1.CODVALATR
                                    INNER JOIN NARTATR ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
               WHERE ATR.CODARTICOL = aCodArticol
               ORDER BY  ATR.INDEXLOCAL ) LOOP
  INSERT INTO NATROBJ(CODATROBJ,CODOBIECT,CODARTATR,CODVALATR,INDEXLOCAL) VALUES
 (SEQ_NATROBJ_CODATROBJ.NEXTVAL,codObjNou,V_REC.CODARTATR,V_REC.CODVALATR,NVL(V_REC.INDEXLOCAL,0)) ;
END LOOP;

--PRETM
 INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET, LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA)
 SELECT SEQ_PRETM_CODPRETM.NEXTVAL, codObjNou,CODCATPRET, Round(LEI * MAJORARE, 2),Round(VALUTA * MAJORARE, 2),MONEDA, 1 ,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA
 FROM PRETM WHERE CODOBIECT = CodObjSursa and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;

--NARTCLI
 INSERT INTO NARTCLI(CODARTCLI, CODOBIECT,CODPART,DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT)
 SELECT SEQ_NARTCLI_CODARTCLI.NEXTVAL, codObjNou,CODPART,DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT
 FROM NARTCLI WHERE CODOBIECT = CodObjSursa;

-- NARTAMB
 INSERT INTO NARTAMB(CODAMB,CODOBIECT,CODOBIECTRETURN,CANT,CANTMIN,UMSEC,CODEXTERN,CODPLU,CODINTERN,MASA,LUNGIME,LATIME,INALTIME,
                    LXLAT, LXH, LATXH)
 SELECT SEQ_NARTAMB_CODAMB.NEXTVAL,codObjNou,CODOBIECTRETURN,CANT,CANTMIN,UMSEC,CODEXTERN,CODPLU,CODINTERN,MASA,LUNGIME,LATIME,INALTIME,
        LXLAT, LXH, LATXH
 FROM NARTAMB WHERE CODOBIECT = CodObjSursa;


 INSERT INTO NARTOBJCOLET(CODOBJCOLET, CODOBIECT, INDEXLOCAL, CONTINUT, IDCOLET)
 SELECT
    SEQ_NARTOBJCOLET_COD.NEXTVAL,
    CodObjNou,
    INDEXLOCAL,
    CONTINUT,
    TRIM(TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;00009&apos;))
 FROM
   NARTOBJCOLET
 WHERE
   CODOBIECT = CodObjSursa;

 prc_al_refresh(&apos;NARTOBJ1&apos;, codObjNou);
 COMMIT;

 RETURN codObjNou;

END;


FUNCTION VERIFICA_OBIECT_EXISTENT(aCODARTICOL IN NUMBER) RETURN NUMBER IS
 NR1 NUMBER(20);
 NR2 NUMBER(20);
 aCODOBIECT NUMBER(20);
BEGIN

  SELECT COUNT(*) INTO NR1 FROM TMP_MANEVRA;
  IF NR1 = 0 THEN
  BEGIN
    SELECT O.CODOBIECT INTO aCODOBIECT
    FROM
      NARTOBJ O,
      NART A
    WHERE
      A.CODARTICOL = aCODARTICOL
      AND O.CODARTICOL = A.CODARTICOL
     AND NOT EXISTS (SELECT CODOBIECT FROM NATROBJ WHERE CODOBIECT = O.CODOBIECT);
     EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
   END;
   RETURN aCODOBIECT;
  END IF;

  FOR V_REC IN (SELECT DISTINCT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = aCOdARTICOL) LOOP
    SELECT COUNT(*) INTO NR1 FROM
     (SELECT CODUNIC FROM TMP_MANEVRA
       MINUS
      SELECT ATROBJ.CODVALATR FROM NARTATR ATR INNER JOIN NATROBJ ATROBJ ON ATR.CODARTATR = ATROBJ.CODARTATR
      WHERE  ATROBJ.CODOBIECT = V_REC.CODOBIECT
     );

    SELECT COUNT(*) INTO NR2 FROM
     (SELECT ATROBJ.CODVALATR FROM NARTATR ATR INNER JOIN NATROBJ ATROBJ ON ATR.CODARTATR = ATROBJ.CODARTATR
      WHERE  ATROBJ.CODOBIECT = V_REC.CODOBIECT
       MINUS
      SELECT CODUNIC FROM TMP_MANEVRA
     );
   IF NR1 + NR2 = 0 THEN
     RETURN V_REC.CODOBIECT;
   END IF;
  END LOOP;
  RETURN -1;
END;



PROCEDURE UPDATEUTILAJ
IS
 aCODUTILAJ NUMBER(20);
BEGIN
  SELECT NVL(CODUTILAJ, 0) INTO aCODUTILAJ FROM TMP_UTILAJE;
  IF aCODUTILAJ = 0 THEN
    SELECT SEQ_UTILAJE_CODUTILAJ.NEXTVAL INTO aCODUTILAJ FROM DUAL;
    INSERT INTO UTILAJE(CODUTILAJ, CODOBIECT, NRINVENTAR, ETICHETA, TIPUTILAJ,FLOTA)
    SELECT aCODUTILAJ, CODOBIECT, NRINVENTAR, ETICHETA, TIPUTILAJ, FLOTA FROM TMP_UTILAJE;
  END IF;

  FOR V_REC IN (SELECT * FROM TMP_UTILAJE1) LOOP
    IF V_REC.CODUTILAJ1 &lt; 0 THEN
      INSERT INTO UTILAJE1(CODUTILAJ1, CODUTILAJ, NRCONTR, CARNETCONTR, STATUS_PART, STATUS_DEPO, CODPART, CODLOCATIE, DATA, USERID, DATACREARE, ESTETIC, CODPERS, OBS)
      VALUES (SEQ_UTILAJE1_CODUTILAJ1.NEXTVAL, aCODUTILAJ, V_REC.NRCONTR, V_REC.CARNETCONTR, V_REC.STATUS_PART, V_REC.STATUS_DEPO, V_REC.CODPART, V_REC.CODLOCATIE, V_REC.DATA,
      PKG_GLOBALS.USERID, SYSTIMESTAMP, V_REC.ESTETIC, V_REC.CODPERS, V_REC.OBS);
    ELSE
      UPDATE UTILAJE1
      SET
        NRCONTR        = V_REC.NRCONTR,
        CARNETCONTR    = V_REC.CARNETCONTR,
        STATUS_PART    = V_REC.STATUS_PART,
        STATUS_DEPO    = V_REC.STATUS_DEPO,
        CODPART        = V_REC.CODPART,
        CODLOCATIE     = V_REC.CODLOCATIE,
        DATA           = V_REC.DATA,
        OBS            = V_REC.OBS,
        CODPERS        = V_REC.CODPERS,
        ESTETIC        = V_REC.ESTETIC
      WHERE
        CODUTILAJ1 = V_REC.CODUTILAJ1;
    END IF;
  END LOOP;
  COMMIT;
END;



FUNCTION GETCODUM(aDENUM IN VARCHAR2) RETURN NUMBER
IS
aCODUM  NUMBER(10) := 0;
aCODUM1 NUMBER(10) := 0;


PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT CODUM INTO aCODUM FROM NUM WHERE upper(DEN_UM) = upper(aDENUM) and rownum = 1;
    EXCEPTION WHEN OTHERS THEN aCODUM := 0;
  END;

  IF aCODUM = 0 THEN
    SELECT SEQ_NUM_CODUM.NEXTVAL INTO aCODUM FROM DUAL;
    SELECT SEQ_NUM1_CODUM1.NEXTVAL INTO aCODUM1 FROM DUAL;

    INSERT INTO NUM  (CODUM, DEN_UM) VALUES (aCODUM, aDENUM);
    INSERT INTO NUM1 (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE)  VALUES (aCODUM1, aCODUM, 0, aDENUM, 1);

  END IF;

  COMMIT;
  RETURN aCODUM;
END;



FUNCTION GETCODSERIE(aCODOBIECT IN NUMBER , aSERIE IN VARCHAR2) RETURN NUMBER
IS
aCODSER NUMBER(20) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT CODSERIE INTO aCODSER FROM NSERII  WHERE CODOBIECT = aCODOBIECT AND SERIE = aSERIE;
    EXCEPTION WHEN OTHERS THEN aCODSER := 0;
  END;

  IF aCODSER = 0 THEN
    SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSER FROM DUAL;
    INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT) VALUES (aCODSER, aSERIE, aCODOBIECT);
  END IF;


  COMMIT;
  RETURN aCODSER;
END;


FUNCTION GETCODLOCALIT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STIPLOCALIT IN VARCHAR2, STARA IN VARCHAR2, NumaiTest in number default 0) RETURN NUMBER
IS
aCODLOCALIT  NUMBER(10)   := 0;
aCODTARA     NUMBER(10)   := 0;
aTIPLOCALIT  VARCHAR2(20) := 0;
aJudet           VARCHAR2(200);
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  aJudet := upper(replace(replace(trim(COALESCE(SJUDET,&apos; &apos;)),&apos;-&apos;,&apos;&apos;),&apos; &apos;,&apos;&apos;));
  BEGIN
    SELECT
      CODLOCALIT INTO aCODLOCALIT
    FROM
      NLOCALIT L
      LEFT OUTER JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
    WHERE
     UPPER(L.DEN_LOCALIT) = UPPER(sLOCALIT)
		 AND
       (UPPER(NVL(J.SIMBAUTO, &apos; &apos;)) = UPPER(NVL(SJUDET, &apos; &apos;))
        OR
			  UPPER(replace(replace(trim(COALESCE(J.DEN_JUDET,&apos; &apos;)),&apos;-&apos;,&apos;&apos;),&apos; &apos;,&apos;&apos;)) = aJudet  )
     AND ROWNUM = 1;
    EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
  END;
 
  IF aCODLOCALIT = 0 and NVL(NumaiTest,0) = 0 THEN

    IF NVL(STARA, &apos; &apos;) &lt;&gt; &apos; &apos; THEN
      BEGIN
       SELECT CODTARA INTO aCODTARA FROM NTARI
       WHERE
         (
				 UPPER(DEN_TARA) = UPPER(STARA)
         OR
				 UPPER(SIMBAUTO) = UPPER(STARA)
				 )
         AND ROWNUM = 1
         ORDER BY CODTARA;
       EXCEPTION WHEN OTHERS THEN aCODTARA := 0;
      END;

      IF aCODTARA = 0 THEN
        SELECT SEQ_NTARI_CODTARA.NEXTVAL INTO aCODTARA FROM DUAL;
        INSERT INTO NTARI (CODTARA, DEN_TARA) VALUES (aCODTARA, STARA);
      END IF;
    END IF;


    SELECT SEQ_NLOCALIT_CODLOCALIT.NEXTVAL INTO aCODLOCALIT FROM DUAL;

    IF UPPER(STIPLOCALIT) = &apos;SAT&apos; THEN aTIPLOCALIT := &apos;Sat&apos;;
    ELSE
      aTIPLOCALIT := &apos;Oras&apos;;
    END IF;

    INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA, TIP)
    VALUES (aCODLOCALIT, SLOCALIT, (SELECT MAX(CODJUDET) 
                                                           FROM NJUDET 
                                                           WHERE (SIMBAUTO = SJUDET 
                                                                             OR UPPER(replace(replace(trim(COALESCE(DEN_JUDET,&apos; &apos;)),&apos;-&apos;,&apos;&apos;),&apos; &apos;,&apos;&apos;)) = aJudet )), aCODTARA, aTIPLOCALIT);
  END IF;

  COMMIT;
  RETURN aCODLOCALIT;
END;

FUNCTION GETCODLOCALITEXT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STIPLOCALIT IN VARCHAR2, STARA IN VARCHAR2, aSIRUTA IN VARCHAR2, NumaiTest in number default 0) RETURN NUMBER
IS
aCODLOCALIT  NUMBER(10)   := 0;
aCODTARA     NUMBER(10)   := 0;
NR           NUMBER(10)   := 0;
aTIPLOCALIT  VARCHAR2(20) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN

  BEGIN
    SELECT
      CODLOCALIT INTO aCODLOCALIT
    FROM
      NLOCALIT L
      LEFT OUTER JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
    WHERE
     UPPER(L.DEN_LOCALIT) = UPPER(sLOCALIT) AND
     NVL(L.SIRUTA, 0)     = TO_NUMBER(NVL(aSIRUTA, &apos;0&apos;)) AND
     UPPER(NVL(J.SIMBAUTO, &apos; &apos;)) = UPPER(NVL(SJUDET, &apos; &apos;))
     AND ROWNUM = 1;
    EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
  END;

  IF aCODLOCALIT = 0 and NVL(NumaiTest,0) = 0 THEN

    IF NVL(STARA, &apos; &apos;) &lt;&gt; &apos; &apos; THEN
      BEGIN
       SELECT CODTARA INTO aCODTARA FROM NTARI
       WHERE
         UPPER(SIMBAUTO) = UPPER(STARA);
       EXCEPTION WHEN OTHERS THEN aCODTARA := 0;
      END;

      IF aCODTARA = 0 THEN
        SELECT SEQ_NTARI_CODTARA.NEXTVAL INTO aCODTARA FROM DUAL;
        INSERT INTO NTARI (CODTARA, DEN_TARA, SIMBAUTO) VALUES (aCODTARA, STARA, STARA);
      END IF;
    END IF;


    SELECT SEQ_NLOCALIT_CODLOCALIT.NEXTVAL INTO aCODLOCALIT FROM DUAL;

    IF UPPER(STIPLOCALIT) = &apos;SAT&apos; THEN aTIPLOCALIT := &apos;Sat&apos;;
    ELSE
      aTIPLOCALIT := &apos;Oras&apos;;
    END IF;

    INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA, TIP, Siruta)
    VALUES (aCODLOCALIT, SLOCALIT, (SELECT CODJUDET FROM NJUDET WHERE SIMBAUTO = SJUDET), aCODTARA, aTIPLOCALIT, aSiruta);
  END IF;

  COMMIT;
  RETURN aCODLOCALIT;
END;

PROCEDURE ADAUGA_ARTICOL_NOU
IS
 aCODART     NUMBER(20)   := 0;
 aCODOBIECT  NUMBER(20)   := 0;
 aCODEXTERN  VARCHAR2(80) := &apos;&apos;;
 aCODINTERN  VARCHAR2(30) := &apos;&apos;;
 aCount      NUMBER(5);
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN

  SELECT SEQ_NART_CODARTICOL.NEXTVAL INTO aCODART FROM DUAL;
  SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO aCODOBIECT FROM DUAL;

  INSERT INTO NART(CODARTICOL, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE, ARETG, CLASA, CONTSERVICIU, CLASASTATIST, UM1, RELATIEUM1, D1, D2, D3, UM2, RELATIEUM2 )
  SELECT aCODART, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE, ARETG, CLASA, CONTSERVICIU, CLASASTATIST, UM1, RELATIEUM1, D1, D2, D3, UM2, RELATIEUM2 FROM TMP_NART;

  INSERT INTO NART1(CODARTICOL1, CODARTICOL, CODTVA, ANSTART, LUNASTART, ALSTART, ALSTOP)
  SELECT SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, CODTVA, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999
  FROM TMP_NART1;

--  VALUES (SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, PKG_CATEGCONST.GETVALCONSTANTA(&apos;TIPTVAImplicit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA);


  INSERT INTO NARTOBJ(CODOBIECT, CODARTICOL, CODEXTERN, CODINTERN, CODCNAS, DENUMIRE, CODCARACT, CODPRODUCATOR, CODVAMAL, PRODUSPROPRIU, MASA, VOLUM)
  SELECT aCODOBIECT, aCODART, CODEXTERN, CODINTERN, CODCNAS, DENUMIRE, CODCARACT, CODPRODUCATOR, CODVAMAL, PRODUSPROPRIU, MASA, VOLUM FROM TMP_NARTOBJ;

  INSERT INTO NARTOBJ1
  (CODOBIECT1, CODOBIECT, ANSTART, LUNASTART, ALSTART, ALSTOP)
  VALUES
  (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, aCODOBIECT, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999) ;

  INSERT INTO NARTAMB(CODAMB, CODOBIECT, UMSEC, CODEXTERN, CODINTERN, MASA, GREUTSPECIFICA)
  SELECT SEQ_NARTAMB_CODAMB.NEXTVAL, aCODOBIECT, UMSEC,  CODEXTERN, CODINTERN, MASA, GREUTSPECIFICA FROM TMP_NARTAMB;


  INSERT INTO NARTCLI(CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, CODLACLIENT)
  SELECT SEQ_NARTCLI_CODARTCLI.NEXTVAL, aCODOBIECT, CODPART, DENUMIRE, CODEXTERN, CODLACLIENT FROM TMP_NARTCLI;


  for v_rec in (select CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA from TMP_NARTIMPLICITE) loop
    select count(*) into acount from nartimplicite where codsubunit = v_Rec.codsubunit and codarticol = aCodArt;
    if acount = 0 then
      INSERT INTO NARTIMPLICITE (CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA)
      SELECT SEQ_NARTIMPLICITE_CODIMPLICIT.NEXTVAL, aCODART, v_Rec.CODSUBUNIT, v_rec.CONTIMPLICIT, v_rec.GESTIMPLICITA FROM TMP_NARTIMPLICITE;
    else
      update nartimplicite set contimplicit = v_Rec.contimplicit, gestimplicita = v_Rec.gestimplicita where codarticol = acodart and codsubunit = v_rec.codsubunit;
    end if;
  end loop;

  UPDATE LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  UPDATE LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  COMMIT;
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
END;


PROCEDURE ADAUGA_ARTICOL_NOU_EXT
IS
 aCODART     NUMBER(20)   := 0;
 aCODARTICOL NUMBER(20)   := 0;
 aCODOBIECT  NUMBER(20)   := 0;
 aCODEXTERN  VARCHAR2(80) := &apos;&apos;;
 aCODINTERN  VARCHAR2(30) := &apos;&apos;;
 VCOD        NUMBER(20)   := 0;
 aCount      NUMBER(5);
-- PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN

  SELECT SEQ_NARTOBJ_CODOBIECT.NEXTVAL INTO aCODOBIECT FROM DUAL;

  BEGIN
    SELECT NVL(CODARTICOL, -1) INTO aCODARTICOL FROM TMP_NARTOBJ;
    EXCEPTION WHEN OTHERS THEN aCODARTICOL := -1;
  END;

  IF aCODARTICOL &lt; 0 THEN
     SELECT SEQ_NART_CODARTICOL.NEXTVAL INTO aCODART FROM DUAL;

      INSERT INTO NART(CODARTICOL, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE, ARETG, CLASA, CONTSERVICIU)
      SELECT aCODART, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE, ARETG, CLASA, CONTSERVICIU FROM TMP_NART;

      INSERT INTO NART1(CODARTICOL1, CODARTICOL, CODTVA, ANSTART, LUNASTART, ALSTART, ALSTOP)
      SELECT SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, CODTVA, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999
      FROM TMP_NART1;
  ELSE
    aCODART := aCODARTICOL;
  END IF;

--  VALUES (SEQ_NART1_CODARTICOL1.NEXTVAL, aCODART, PKG_CATEGCONST.GETVALCONSTANTA(&apos;TIPTVAImplicit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA);


  FOR V_REC IN (SELECT * FROM TMP_NATRIB1) LOOP
    VCOD := SEQ_NATRIB1_CODVALATR.NEXTVAL;
    INSERT INTO NATRIB1(CODVALATR, CODATRIBUT, VALOARE)
    VALUES (VCOD, V_REC.CODATRIBUT, V_REC.VALOARE);

    UPDATE TMP_NATROBJ  SET
     CODVALATR = VCOD
    WHERE
     CODVALATR = V_REC.CODVALATR;
  END LOOP;

  INSERT INTO NARTOBJ(CODOBIECT, CODARTICOL, CODEXTERN, CODINTERN, CODCNAS, DENUMIRE, CODCARACT, CODPRODUCATOR, CODVAMAL, PRODUSPROPRIU, FARACMDFURN, FARANIVELAPROB)
  SELECT aCODOBIECT, aCODART, CODEXTERN, CODINTERN, CODCNAS, DENUMIRE, CODCARACT, CODPRODUCATOR, CODVAMAL, PRODUSPROPRIU, FARACMDFURN, FARANIVELAPROB FROM TMP_NARTOBJ;

  INSERT INTO NARTOBJ1
  (CODOBIECT1, CODOBIECT, ANSTART, LUNASTART, ALSTART, ALSTOP)
  VALUES
  (SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL, aCODOBIECT, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999) ;

  FOR V_REC IN (SELECT * FROM TMP_NATROBJ) LOOP
    INSERT INTO NATROBJ(CODATROBJ, CODOBIECT, CODARTATR, CODVALATR, INDEXLOCAL)
    VALUES (SEQ_NATROBJ_CODATROBJ.NEXTVAL, aCODOBIECT, V_REC.CODARTATR, V_REC.CODVALATR, V_REC.INDEXLOCAL);
  END LOOP;

  INSERT INTO NARTAMB(CODAMB, CODOBIECT, UMSEC, CODEXTERN, CODINTERN, MASA, GREUTSPECIFICA)
  SELECT SEQ_NARTAMB_CODAMB.NEXTVAL, aCODOBIECT, UMSEC,  CODEXTERN, CODINTERN, MASA, GREUTSPECIFICA FROM TMP_NARTAMB;

  for v_rec in (select CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA from TMP_NARTIMPLICITE) loop
    select count(*) into acount from nartimplicite where codsubunit = v_Rec.codsubunit and codarticol = aCodArt;
    if acount = 0 then
      INSERT INTO NARTIMPLICITE (CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA)
      SELECT SEQ_NARTIMPLICITE_CODIMPLICIT.NEXTVAL, aCODART, v_Rec.CODSUBUNIT, v_rec.CONTIMPLICIT, v_rec.GESTIMPLICITA FROM TMP_NARTIMPLICITE;
    else
      update nartimplicite set contimplicit = v_Rec.contimplicit, gestimplicita = v_Rec.gestimplicita where codarticol = acodart and codsubunit = v_rec.codsubunit;
    end if;
  end loop;


  UPDATE LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  UPDATE LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  COMMIT;
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
END;


PROCEDURE ADAUGA_GESTIUNE_NOUA
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO NGEST(CODGEST, DEN_GEST, SIMBOL, CODCLASA, CODACTIVIT, CODSUBUNIT)
  SELECT SEQ_NGEST_CODGEST.NEXTVAL, DEN_GEST, SIMBOL, CODCLASA, CODACTIVIT, CODSUBUNIT FROM TMP_NGEST;
  COMMIT;
END;

PROCEDURE EMPTY_NOMPART_TEMPTABLES
IS
BEGIN
  DELETE TMP_NPART;
  DELETE TMP_NPART1;
  DELETE TMP_NPARTB;
  DELETE TMP_NPARTCODFISC;
  DELETE TMP_NAGENDA;
  DELETE TMP_NPERSCONTACT;
  DELETE TMP_NPARTTR;
  COMMIT;
END;

PROCEDURE CHECK_INFO_PART
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT)
    SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL, TIP, SEDIUSOCIAL, SUBSTR(ADRESA,1, 30),  OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT
    FROM
      TMP_NAGENDA
    WHERE
      CODAGENDA &lt; 0;
   EXCEPTION WHEN OTHERS THEN NULL;
 END;
 COMMIT;
END;

PROCEDURE ADAUGA_PARTENER_NOU
IS
 aCODPART NUMERIC(20) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_NPART_CODPART.NEXTVAL INTO aCODPART FROM DUAL;

  INSERT INTO NPART(CODPART,
                   DEN_PART,
                   REGCOM,
                   CODEXTERN,
                   CODINTERN,
                   CODCLASA,
                   DATAADAUGARII,
                   PERSOANAFIZICA,
                   SCADENTAV,
                   CODMONEDA,
                   BLOCAT,
                   TVALAINCASARE,
                   OBS)
  SELECT
    aCODPART,
    DEN_PART,
    REGCOM,
    CODEXTERN,
    CODINTERN,
    CODCLASA,
    DATAADAUGARII,
    PERSOANAFIZICA,
    SCADENTAV,
    CODMONEDA,
    BLOCAT,
    TVALAINCASARE,
    OBS
  FROM
    TMP_NPART;



  INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART,CREDITCLIENT, ALSTART, ALSTOP)
  SELECT SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, CODIOPART, ANSTART, LUNASTART, CREDITCLIENT, ANSTART * 12 + LUNASTART, 99999
--  SELECT SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, CODIOPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, CREDITCLIENT, 0, 99999
  FROM TMP_NPART1;

  INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
  SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, aCODPART, CODFISCAL, PRINCIPAL FROM TMP_NPARTCODFISC;

  INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART, EMAIL)
  SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL, TIP, SEDIUSOCIAL, SUBSTR(ADRESA,1, 100),  OBS, aCODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART, EMAIL
  FROM TMP_NAGENDA;

  INSERT INTO NPERSCONTACT(CODPERSC, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, CODPART)
  SELECT SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, aCODPART FROM TMP_NPERSCONTACT;


  INSERT INTO NPARTB(CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA)
  SELECT SEQ_NPARTB_CODPARTB.NEXTVAL, aCODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA FROM TMP_NPARTB;


  INSERT INTO NPARTDISC(CODPARTDISC,CODPART,CODCATEGDISC,INDEXLOCAL)
  SELECT SEQ_NPARTDISC_CODPARTDISC.NEXTVAL, aCODPART, CODCATEGDISC,INDEXLOCAL FROM TMP_NPARTDISC;

  INSERT INTO NPARTTR(CODPARTTR, CODPART, CNP, SERIEDOC, NRDOC, ACTIV)
  SELECT SEQ_NPARTTR_CODPARTTR.NEXTVAL, aCODPART, CNP, SERIEDOC, NRDOC, 1 FROM TMP_NPARTTR;

  PKG_NOMPART.DOSYNCPARTRETAIL(aCODPART);

  if pkg_categconst.GetValConstanta(&apos;IDSEDIUAUTOMAT&apos;,    pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) = &apos;1&apos; then
    UPDATE NAGENDA
    SET
      IDSEDIU = CODAGENDA
    WHERE
      CODPART = aCODPART
      AND IDSEDIU IS NULL;
  end IF;



  COMMIT;
END;


PROCEDURE MODIFICA_PARTENER
IS
  aCODPART1  NUMBER(20) := 0;
  aCODAGENDA NUMBER(20) := 0;
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  prc_al_refresh(&apos;TMP_NPART1&apos;, 0);

  FOR V_REC IN (SELECT * FROM TMP_NPART)
  LOOP
     IF V_REC.DEN_PART IS NOT NULL THEN
       UPDATE NPART
       SET
         DEN_PART = V_REC.DEN_PART
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.REGCOM IS NOT NULL THEN
       UPDATE NPART
       SET
         REGCOM = V_REC.REGCOM
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.CODCLASA IS NOT NULL THEN
       UPDATE NPART
       SET
         CODCLASA = V_REC.CODCLASA
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.SCADENTAV IS NOT NULL THEN
       UPDATE NPART
       SET
         SCADENTAV = V_REC.SCADENTAV
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.CODMONEDA IS NOT NULL THEN
       UPDATE NPART
       SET
         CODMONEDA  = V_REC.CODMONEDA
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.OBS IS NOT NULL THEN
       UPDATE NPART
       SET
         OBS  = V_REC.OBS
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     IF V_REC.BLOCAT IS NOT NULL THEN
       UPDATE NPART
       SET
         BLOCAT  = V_REC.BLOCAT
       WHERE
         CODPART = V_REC.CODPART;
     END IF;

     FOR V_REC_D IN (SELECT * FROM TMP_NPART1) LOOP
       BEGIN
           SELECT CODPART1 INTO aCODPART1
           FROM
             NPART1
           WHERE
             CODPART = V_REC.CODPART
             AND ANSTART = V_REC_D.ANSTART
             AND LUNASTART = V_REC_D.LUNASTART;
          EXCEPTION WHEN OTHERS THEN aCODPART1  := 0;
       END;

       IF aCODPART1 = 0 THEN
          INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART, CREDITCLIENT, ALSTART, ALSTOP)
          VALUES(SEQ_NPART1_CODPART1.NEXTVAL, V_REC.CODPART, V_REC_D.CODIOPART, V_REC_D.ANSTART, V_REC_D.LUNASTART, V_REC_D.CREDITCLIENT, V_REC_D.ALSTART, V_REC_D.ALSTOP);
       ELSE
         UPDATE NPART1
         SET
           CODIOPART = V_REC_D.CODIOPART,
           CREDITCLIENT = CASE
                           WHEN V_REC_D.CREDITCLIENT IS NOT NULL THEN V_REC_D.CREDITCLIENT
                           ELSE CREDITCLIENT
                         END,
           ALSTART = V_REC_D.ALSTART,
           ALSTOP  = V_REC_D.ALSTOP
         WHERE
           CODPART1 = aCODPART1;
       END IF;
     END LOOP;

     FOR V_REC_D IN (SELECT * FROM TMP_NPARTCODFISC WHERE CODFISCAL NOT IN (SELECT CODFISCAL FROM NPARTCODFISC WHERE CODPART = V_REC.CODPART))
     LOOP
        UPDATE NPARTCODFISC SET PRINCIPAL = 0 WHERE CODPART = V_REC.CODPART;
        INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
        VALUES(SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, V_REC.CODPART, V_REC_D.CODFISCAL, 1);
     END LOOP;

     FOR V_REC_D IN (SELECT * FROM TMP_NAGENDA WHERE SEDIUSOCIAL = 7)
     LOOP
       BEGIN
         SELECT CODAGENDA INTO aCODAGENDA FROM NAGENDA WHERE CODPART = V_REC.CODPART AND SEDIUSOCIAL = 7;
         EXCEPTION WHEN OTHERS THEN aCODAGENDA := 0;
       END;
       IF aCODAGENDA = 0 THEN
         aCODAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;
         INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART, email)
         VALUES (aCODAGENDA, 0, V_REC_D.SEDIUSOCIAL, SUBSTR(V_REC_D.ADRESA,1, 100),  V_REC_D.OBS, V_REC.CODPART, V_REC_D.CODLOCALIT, V_REC_D.TELEFON, V_REC_D.CODAGENT, V_REC_D.LONGITUDINE, V_REC_D.LATITUDINE, V_REC_D.OBS2, V_REC_D.NR1, V_REC_D.NR2, V_REC_D.BLOC, V_REC_D.SCARA, V_REC_D.ETAJ, V_REC_D.APART, v_rec_d.email);

          if pkg_categconst.GetValConstanta(&apos;IDSEDIUAUTOMAT&apos;,    pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) = &apos;1&apos; then
            UPDATE NAGENDA
            SET
              IDSEDIU = CODAGENDA
            WHERE
              CODAGENDA = aCODAGENDA
              AND IDSEDIU IS NULL;
          end IF;



       ELSE
         IF V_REC_D.OBS IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             STRADA = SUBSTR(V_REC_D.ADRESA, 1, 100)
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.OBS IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             OBS = V_REC_D.OBS
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;


         IF V_REC_D.CODAGENT IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             CODAGENT = V_REC_D.CODAGENT
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;


         IF V_REC_D.CODLOCALIT IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             CODLOCALIT = V_REC_D.CODLOCALIT
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;


         IF V_REC_D.NR1 IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             NR1 = V_REC_D.NR1
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.NR2 IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             NR2 = V_REC_D.NR2
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.BLOC IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             BLOC = V_REC_D.BLOC
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.SCARA IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             SCARA = V_REC_D.SCARA
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.ETAJ IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             ETAJ = V_REC_D.ETAJ
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.APART IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             APART = V_REC_D.APART
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

         IF V_REC_D.EMAIL IS NOT NULL THEN
           UPDATE NAGENDA
           SET
             EMAIL = V_REC_D.EMAIL
           WHERE
             CODAGENDA = aCODAGENDA;
         END IF;

       END IF;

     END LOOP;


     FOR V_REC_D IN (SELECT * FROM TMP_NAGENDA WHERE SEDIUSOCIAL &lt;&gt; 7)
     LOOP
       aCODAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;
       INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART, EMAIL)
       VALUES (ACODAGENDA, V_REC_D.TIP, V_REC_D.SEDIUSOCIAL, SUBSTR(V_REC_D.ADRESA,1, 100),  V_REC_D.OBS, V_REC.CODPART, V_REC_D.CODLOCALIT, V_REC_D.TELEFON, V_REC_D.CODAGENT, V_REC_D.LONGITUDINE, V_REC_D.LATITUDINE, V_REC_D.OBS2, V_REC_D.NR1, V_REC_D.NR2, V_REC_D.BLOC, V_REC_D.SCARA, V_REC_D.ETAJ, V_REC_D.APART, V_REC_D.EMAIL);


          if pkg_categconst.GetValConstanta(&apos;IDSEDIUAUTOMAT&apos;,    pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) = &apos;1&apos; then
            UPDATE NAGENDA
            SET
              IDSEDIU = CODAGENDA
            WHERE
              CODAGENDA = aCODAGENDA
              AND IDSEDIU IS NULL;
          end IF;


     END LOOP;


     FOR V_REC_D IN (SELECT * FROM TMP_NPERSCONTACT)
     LOOP

      INSERT INTO NPERSCONTACT(CODPERSC, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, CODPART)
      VALUES (SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, V_REC_D.NUME, V_REC_D.PRENUME, V_REC_D.TIP, V_REC_D.TELEFON, V_REC_D.EMAIL, V_REC_D.FUNCTIE, V_REC.CODPART);

     END LOOP;


     FOR V_REC_D IN (SELECT * FROM TMP_NPARTB)
     LOOP
       IF NVL(V_REC_D.IMPLICIT, 0) = 1  THEN
         UPDATE NPARTB
         SET
           IMPLICIT = 0
         WHERE
           IMPLICIT = 1
           AND CODPART = V_REC_D.CODPART;
       END IF;
       INSERT INTO NPARTB(CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA)
       VALUES (SEQ_NPARTB_CODPARTB.NEXTVAL, V_REC.CODPART, V_REC_D.CODBANK, V_REC_D.IMPLICIT, V_REC_D.CODLOCALIT, V_REC_D.CONTBANCA, V_REC_D.SUCURSALA);

     END LOOP;


  END LOOP;




/*
      INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART)
      SELECT SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, CODIOPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA FROM TMP_NPART1;

      INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
      SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, aCODPART, CODFISCAL, PRINCIPAL FROM TMP_NPARTCODFISC;

      INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART)
      SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL, TIP, SEDIUSOCIAL, SUBSTR(ADRESA,1, 100),  OBS, aCODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2, NR1, NR2, BLOC, SCARA, ETAJ, APART
      FROM TMP_NAGENDA;

      INSERT INTO NPERSCONTACT(CODPERSC, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, CODPART)
      SELECT SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, aCODPART FROM TMP_NPERSCONTACT;


      INSERT INTO NPARTB(CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA)
      SELECT SEQ_NPARTB_CODPARTB.NEXTVAL, aCODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA FROM TMP_NPARTB;
*/

     COMMIT;
END;



PROCEDURE ADAUGA_PARTENER_NOU_EXT
IS
 aCODPART NUMERIC(20) := 0;
-- PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_NPART_CODPART.NEXTVAL INTO aCODPART FROM DUAL;

  INSERT INTO NPART(CODPART,
                   DEN_PART,
                   REGCOM,
                   CODEXTERN,
                   CODINTERN,
                   CODCLASA,
                   DATAADAUGARII,
                   PERSOANAFIZICA,
                   SCADENTAV,
                   CODMONEDA,
                   OBS,
                   SPLITTVA)
  SELECT
    aCODPART,
    DEN_PART,
    REGCOM,
    CODEXTERN,
    CODINTERN,
    CODCLASA,
    DATAADAUGARII,
    PERSOANAFIZICA,
    SCADENTAV,
    CODMONEDA,
    OBS,
    SPLITTVA
  FROM
    TMP_NPART;



  INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART, ALSTART, ALSTOP)
  SELECT SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, CODIOPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999 FROM TMP_NPART1;

  INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
  SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, aCODPART, CODFISCAL, PRINCIPAL FROM TMP_NPARTCODFISC;

  INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2)
  SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL, TIP, SEDIUSOCIAL, SUBSTR(ADRESA,1, 100),  OBS, aCODPART, CODLOCALIT, TELEFON, CODAGENT, LONGITUDINE, LATITUDINE, OBS2
  FROM TMP_NAGENDA;

  INSERT INTO NPERSCONTACT(CODPERSC, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, CODPART)
  SELECT SEQ_NPERSCONTACT_CODPERSC.NEXTVAL, NUME, PRENUME, TIP, TELEFON, EMAIL, FUNCTIE, aCODPART FROM TMP_NPERSCONTACT;


  INSERT INTO NPARTB(CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA)
  SELECT SEQ_NPARTB_CODPARTB.NEXTVAL, aCODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA FROM TMP_NPARTB;


  COMMIT;
END;


PROCEDURE MIRROR_IESIRI(aRecID IN NUMBER)
IS
NR NUMBER(20) := 0;
BEGIN
  -- IESIRI
  FOR V_REC IN (SELECT * FROM TMP_IESIRI) LOOP
    SELECT COUNT(*) INTO NR FROM IESIRI WHERE CODIES = V_REC.CODIES;
    IF NR = 0 THEN
    INSERT INTO IESIRI
     ( CODIES, TIPDOC,  ANULAT,   BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
       NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
       ACCIZE,   DELEGAT, AGENT, MAJORARI,
       OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION,
       SUBUNITATEA, MONEDA, CURS, MIJLTRANSP, LISTAT,
       CUSTODIE, FARATRANSPORT, StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, userid,datacreare, MONEDATRANSF, NRI, CONTSUPLIM, DATAINREG, ExclusPlata, PROCTVADOC, FaraReg,
       codanaliza, CODAECUSTODIE
      )
     VALUES
    ( V_REC.CODIES, V_REC.TIPDOC,  V_REC.ANULAT,   V_REC.BLOCAT, V_REC.OPERAT, V_REC.PREFIXDOC, V_REC.CODBANKCONT, V_REC.TIPCASAMARCAT, V_REC.TIPTRANZACTIE, V_REC.CARNETDOC,
      V_REC.NRDOC,  V_REC.DATADOC, V_REC.PARTENER, V_REC.CODSUBUNIT, V_REC.CARNETAE, V_REC.NRAE, V_REC.VALDOC, V_REC.TVADOC, V_REC.VALDISCOUNT, V_REC.TVADISCOUNT, V_REC.CONTDISCOUNT,
      V_REC.ACCIZE,   V_REC.DELEGAT, V_REC.AGENT, V_REC.MAJORARI,
      V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.CODFISCAL, V_REC.SERIADOC, V_REC.BUGETARE, V_REC.CODLOCATIE, V_REC.TIPFACTURA, V_REC.CODGESTPROD,    V_REC.TIPCONSUMATOR, V_REC.CODAUTO, V_REC.PARTCUSTODIE, V_REC.CODCMDINTERNA, V_REC.CODPERS,
      V_REC.CONTINTERMED, V_REC.TIPTVA, V_REC.COMISION,
      V_REC.SUBUNITATEA, V_REC.MONEDA, V_REC.CURS, V_REC.MIJLTRANSP, V_REC.LISTAT,
      V_REC.CUSTODIE, V_REC.FARATRANSPORT, V_REC.StareRestituire, V_REC.IDIMPORT, V_REC.TIPCHELT, V_REC.CODPERSC, V_REC.INFOCM,
      V_REC.CURSDOC, V_REC.NRTRANSP, V_REC.userid, V_REC.datacreare, V_REC.MONEDATRANSF, V_REC.NRI, V_REC.CONTSUPLIM,
      V_REC.DATAINREG, V_REC.ExclusPlata, V_REC.PROCTVADOC, V_REC.FaraReg,
      V_REC.codanaliza, V_REC.CODAECUSTODIE
     );
    ELSE

    UPDATE IESIRI
    SET
     (CODIES, TIPDOC,  ANULAT,  BLOCAT,   OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
      NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE,  VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
      ACCIZE,   DELEGAT,  AGENT, MAJORARI,  OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,     TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION, MONEDA, CURS, MIJLTRANSP, LISTAT,
      CUSTODIE, FARATRANSPORT,StareRestituire, IDIMPORT, TIPCHELT, CODPERSC, INFOCM, CURSDOC,  NRTRANSP, MONEDATRANSF, NRI, CONTSUPLIM,
      DATAINREG, CARNETCERTIF, NRCERTIF, SERIACERTIF, ExclusPlata, PROCTVADOC, FaraReg, codanaliza, CODAECUSTODIE) =
     (SELECT CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CODBANKCONT, TIPCASAMARCAT, TIPTRANZACTIE, CARNETDOC,
             NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
             ACCIZE, DELEGAT, AGENT, MAJORARI,
             OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD,    TIPCONSUMATOR, CODAUTO, PARTCUSTODIE, CODCMDINTERNA, CODPERS, CONTINTERMED,TIPTVA, COMISION, MONEDA, CURS, MIJLTRANSP, LISTAT,
             CUSTODIE, FARATRANSPORT,StareRestituire, IDIMPORT,  TIPCHELT, CODPERSC, INFOCM, CURSDOC, NRTRANSP, MONEDATRANSF, NRI, CONTSUPLIM, DATAINREG,
             CARNETCERTIF, NRCERTIF, SERIACERTIF, ExclusPlata,PROCTVADOC, FaraReg, codanaliza, CODAECUSTODIE
      FROM TMP_IESIRI
     )
    WHERE CODIES = V_REC.CODIES;

    END IF;
  END LOOP;


  DELETE FROM IESIRI1 I1 WHERE CODIES = aRECID AND NOT EXISTS (SELECT CODIES1 FROM TMP_IESIRI1 WHERE CODIES1 = I1.CODIES1);

  DELETE FROM LIVR     L WHERE CODIES = aRECID AND NOT EXISTS (SELECT CODLIVR FROM TMP_LIVR WHERE CODLIVR = L.CODLIVR);



  FOR V_REC IN (SELECT * FROM TMP_IESIRI1) LOOP
    SELECT COUNT(*) INTO NR FROM IESIRI1 WHERE CODIES1 = V_REC.CODIES1;
    IF NR = 0 THEN
      INSERT INTO IESIRI1
           ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT, PRETORIG, PU,
             CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG,
             PARITATEORIG, CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,PRETPROMO, TIPPLATA,CODCENTRU, CODCADOU, CODOBLIGMONETAR,
             CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT, CODAGENTEMULARE, CODPROMO1)
       VALUES
           ( V_REC.CODIES1, V_REC.CODIES, V_REC.INDEXLOCAL, V_REC.TIPLINIE, V_REC.UMSEC, V_REC.CONTSERV, V_REC.CONTDISCOUNT, V_REC.CODCRITERIU, V_REC.MIFIX, V_REC.ZILE, V_REC.ZILECMD, V_REC.GESTACT, V_REC.CODOBIECT, V_REC.PRETORIG, V_REC.PU,
             V_REC.CANT, V_REC.TVA, V_REC.CONT, V_REC.PROCDISC, V_REC.ADDIM, V_REC.RESTFACT, V_REC.PUMAXIMAL, V_REC.TipLivrare, V_REC.GARANTIE, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS, V_REC.COEFDISCMAJ, V_REC.OBS, V_REC.CODOBIECTORIG,
             V_REC.PARITATEORIG, V_REC.CODLIVR1PRODVAL, V_REC.CODIES1STORNO, V_REC.CODOFERTA1, V_REC.CADOU, V_REC.TAXA, V_REC.TERMENCONTRACT, V_REC.CADOULINK, V_REC.CODIOARTCUST, V_REC.UMCorelat, V_REC.CANTCorelat, V_REC.PUCorelat,
             V_REC.PRETPROMO, V_REC.TIPPLATA, V_REC.CODCENTRU, V_REC.CODCADOU, V_REC.CODOBLIGMONETAR,
             V_REC.CODLINIEDOCIMP, V_REC.TIPDOCIMP, V_REC.CODCMDINT1, V_REC.CODANALIZANOD, V_REC.D1D3BCS,
             V_REC.CODOBLIGMAJORAT, V_REC.CODAGENTEMULARE, V_REC.CODPROMO1);

    ELSE
      UPDATE IESIRI1
       SET  ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT, PRETORIG, PU,
             CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG,
             PARITATEORIG, CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,PRETPROMO, TIPPLATA,CODCENTRU, CODCADOU, CODOBLIGMONETAR,
             CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT, CODAGENTEMULARE, CODPROMO1)
       =
           (
             SELECT
               CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, ZILE, ZILECMD, GESTACT, CODOBIECT, PRETORIG, PU,
               CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TipLivrare, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG,
               PARITATEORIG, CODLIVR1PRODVAL, CODIES1STORNO, CODOFERTA1, CADOU, TAXA, TERMENCONTRACT, CADOULINK, CODIOARTCUST, UMCorelat, CANTCorelat, PUCorelat,PRETPROMO, TIPPLATA,CODCENTRU, CODCADOU, CODOBLIGMONETAR,
               CODLINIEDOCIMP, TIPDOCIMP, CODCMDINT1, CODANALIZANOD, D1D3BCS, CODOBLIGMAJORAT, CODAGENTEMULARE, CODPROMO1
             FROM
              TMP_IESIRI1
             WHERE
               CODIES1 = V_REC.CODIES1
            )
      WHERE
        CODIES1 = V_REC.CODIES1;

    END IF;
  END LOOP;

  COMMIT;
END;


PROCEDURE MIRROR_NPART(aRecID IN NUMBER)
IS
NR NUMBER(20) := 0;
BEGIN
  prc_al_refresh(&apos;TMP_NPART1&apos;, 0);

  FOR V_REC IN (SELECT * FROM TMP_NPART) LOOP
    SELECT COUNT(*) INTO NR FROM NPART WHERE CODPART = V_REC.CODPART;
    IF NR = 0 THEN
      INSERT INTO NPART
       ( CodPart,
         Den_part,
         CodExtern,
         CodMoneda,
         RegCom,
         EXPIRAREAUTORIZ,
         CODSTATISTICBNR,
         Autorizatie,
         CodIntern,
         CodClasa,
         CodCategPret,
         TipPart,
         ScadentaC,
         ScadentaV,
         Discount,
         CodCategDisc,
         Blocat,
         TIPPARTENER,
         DATAADAUGARII,
         OBS,
         POZA,
         PERSOANAFIZICA,
         VERFACT,
         VERDISPLIVR,
         COLDISCOUNT,
         INFOBLOCAT, MusaiColet, STRATEGIC,
         CifraAfaceri,
         DomeniuActiv,
         NrAngajati,
         SursaLead,
         Lead
       )
        (SELECT
          CodPart,
          Den_part,
          CodExtern,
          CodMoneda,
          RegCom,
          EXPIRAREAUTORIZ,
          CODSTATISTICBNR,
          Autorizatie,
          CodIntern,
          CodClasa,
          CodCategPret,
          TipPart,
          ScadentaC,
          ScadentaV,
          Discount,
          CodCategDisc,
          Blocat,
          TIPPARTENER,
          DATAADAUGARII,
          OBS,
          POZA,
          PERSOANAFIZICA,
          VERFACT,
          VERDISPLIVR,
          COLDISCOUNT,
          INFOBLOCAT, MusaiColet, STRATEGIC,
          CifraAfaceri,
          DomeniuActiv,
          NrAngajati,
          SursaLead,
          Lead
        FROM
          TMP_NPART
        WHERE
          CodPart = V_REC.CODPART
       );

    ELSE
      UPDATE NPART
      SET
         ( CodPart,
           Den_part,
           CodExtern,
           CodMoneda,
           RegCom,
           EXPIRAREAUTORIZ,
           CODSTATISTICBNR,
           Autorizatie,
           CodIntern,
           CodClasa,
           CodCategPret,
           TipPart,
           ScadentaC,
           ScadentaV,
           Discount,
           CodCategDisc,
           Blocat,
           TIPPARTENER,
           DATAADAUGARII,
           OBS,
           POZA,
           PERSOANAFIZICA,
           VERFACT,
           VERDISPLIVR,
           COLDISCOUNT,
           INFOBLOCAT, MusaiColet, STRATEGIC,
           CifraAfaceri,
           DomeniuActiv,
           NrAngajati,
           SursaLead,
           Lead
         )
         =
         (SELECT
            CodPart,
            Den_part,
            CodExtern,
            CodMoneda,
            RegCom,
            EXPIRAREAUTORIZ,
            CODSTATISTICBNR,
            Autorizatie,
            CodIntern,
            CodClasa,
            CodCategPret,
            TipPart,
            ScadentaC,
            ScadentaV,
            Discount,
            CodCategDisc,
            Blocat,
            TIPPARTENER,
            DATAADAUGARII,
            OBS,
            POZA,
            PERSOANAFIZICA,
            VERFACT,
            VERDISPLIVR,
            COLDISCOUNT,
            INFOBLOCAT, MusaiColet, STRATEGIC,
            CifraAfaceri,
            DomeniuActiv,
            NrAngajati,
            SursaLead,
            Lead
          FROM
            TMP_NPART
          WHERE
            CodPart = V_REC.CODPART
         )
          WHERE
            CodPart = V_REC.CODPART;

    END IF;

  END LOOP;

  DELETE FROM NPART1 P1 WHERE CODPART = aREcID AND NOT EXISTS (SELECT CODPART1  FROM TMP_NPART1 WHERE CODPART1 = P1.CODPART1);
  DELETE FROM NAGENDA A WHERE CODPART = aREcID AND NOT EXISTS (SELECT CODAGENDA FROM TMP_NAGENDA WHERE CODAGENDA = A.CODAGENDA);

  prc_al_refresh(&apos;NPART1&apos;, aREcID);

  FOR V_REC IN (SELECT * FROM TMP_NPART1) LOOP
    SELECT COUNT(*) INTO NR FROM NPART1 WHERE CODPART1 = V_REC.CODPART1;
    IF NR = 0 THEN
      INSERT INTO NPART1
      ( CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, SCADENTAV, SCADENTAC, DISCOUNT, CreditClient, VolumTranzF,anstart,lunastart, alstart, alstop )
      ( select CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, SCADENTAV, SCADENTAC, DISCOUNT, CreditClient, VolumTranzF,anstart,lunastart, alstart, alstop FROM TMP_NPART1 WHERE CODPART1 = V_REC.CODPART1 ) ;
    ELSE
      UPDATE NPART1
      SET
      ( CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, SCADENTAV, SCADENTAC, DISCOUNT, CreditClient, VolumTranzF,anstart,lunastart, alstart, alstop )
      =
      ( SELECT CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, SCADENTAV, SCADENTAC, DISCOUNT, CreditClient, VolumTranzF,anstart,lunastart, alstart, alstop FROM TMP_NPART1 WHERE CODPART1 = V_REC.CODPART1)
      WHERE
        CODPART1 = V_REC.CODPART1;
    END IF;

  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NAGENDA) LOOP
    SELECT COUNT(*) INTO NR FROM NAGENDA WHERE CODAGENDA = V_REC.CODAGENDA;
    IF NR = 0 THEN
      INSERT INTO NAGENDA (
        codagenda, OBS, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,
        CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL,  codtraseu, poztraseu, Inactiv, Codcoresp, TranspClient, LONGITUDINE, LATITUDINE, OBS2 )
      SELECT
        codagenda, OBS, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,
        CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL,  codtraseu, poztraseu, Inactiv, Codcoresp, TranspClient, LONGITUDINE, LATITUDINE, OBS2
      FROm TMP_NAGENDA
      WHERE CODAGENDA = V_REC.CODAGENDA;
    ELSE
      UPDATE NAGENDA
      SET
        ( codagenda, OBS, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL,  codtraseu, poztraseu, Inactiv, Codcoresp, TranspClient, LONGITUDINE, LATITUDINE, OBS2 )
        =
        ( SELECT codagenda, OBS, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL,  codtraseu, poztraseu, Inactiv, Codcoresp, TranspClient, LONGITUDINE, LATITUDINE, OBS2 FROm TMP_NAGENDA WHERE CODAGENDA = V_REC.CODAGENDA )
      WHERE
        CODAGENDA = V_REC.CODAGENDA;
    END IF;

  END LOOP;



  COMMIT;
END;

PROCEDURE GET_STOC_INITIAL(aGEST IN NUMBER, aCODIOART IN NUMBER, SUPRASCRIERE IN NUMBER)
IS
BEGIN
  DELETE TMP_NIRSTOCINI;
  DELETE TMP_NIRSERINI;

  IF SUPRASCRIERE = 0 THEN
    INSERT INTO TMP_NIRSTOCINI
       (CODNIRSTOC,
       CODNIR,
       CODINTR1,
       CODINTR,
       DATADOC,
       CODOBIECT,
       CODIOART,
       UMSEC,
       PRETACHIZ ,
       PRETINREG,
       PUVAL,
       TVA,
       TG,
       TIPSERIE,
       CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS,
       DENUM,
       PARITATE,
       D1, D2, D3,
       NRCERTIF,
       ROTLEI,
       ROTVALUTA,
       TIPNIR,
       CODGESTPROD,
       REST,
       SERIELOT,
       CODCENTRU,
       PROVIZION
       )
       (SELECT
           NS.CODNIRSTOC,
           NS.CODNIR,
           I1.CODINTR1,
           I.CODINTR,
           I.DATADOC,
           NS.CODOBIECT,
           NS.CODIOART,
           NS.UMSEC,
           (NS.PRET - NS.ADAOS),
           NS.PRET ,
           NS.PUVAL,
           NS.TVA,
           NS.TG,
           NS.TIPSERIE,
           NS.CANTNIR ,
           NS.CODLOCATIE, I.PARTENER,
           I.INITIALIZARI,
           NS.PUMAXIMAL,
           NS.CANTUM1, NS.CANTUM2,
           NS.PROCENTADAOS,
           NL.DENUMIRE, -- pun den. locatie pe denUM
           U1.PARITATE,
           NS.D1,
           NS.D2,
           NS.D3,
           I1.NRCERTIF,
           NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
           NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
           N.TIPNIR,
           NS.CODGESTPROD,
           NS.REST,
           NS.SERIELOT,
           I1.CODCENTRU,
           NS.PROVIZION
        FROM
          NIRSTOC NS -- NIR-uri din INTRARI
          LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
          LEFT OUTER JOIN NLOCATII NL ON NS.CODLOCATIE = NL.CODLOCATIE
          LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
          LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
          LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR,
          NUM1 U1
        WHERE
          N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
          AND NS.CODIOART = aCODIOART
          AND NS.UMSEC    = U1.CODUM1 AND N.TIPNIR &lt; 10
       );

    UPDATE TMP_NIRSTOCINI NS
    SET
    (MG, DIFPRET, ARETVANEEX, PUSTANDARD) = (SELECT MG, DIFPRET, ARETVANEEX, PUSTANDARD FROM TMP_IOART_LUNA I1 WHERE I1.CODIOART = NS.CODIOART);


    INSERT INTO TMP_NIRSERINI(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, SERIE)
    SELECT
      CODNIRSER,
      CODNIRSTOC,
      NSE.CODSERIE,
      CANTNIR,
      SER.SERIE
    FROM
      NIRSER NSE,
      NSERII SER
    WHERE
     NSE.CODSERIE = SER.CODSERIE
     AND EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC NS WHERE NS.CODNIRSTOC = NSE.CODNIRSTOC);
  END IF;
  COMMIT;
END;


PROCEDURE POST_STOC_INITIAL(aGEST IN NUMBER, aCODIOART IN NUMBER, SUPRASCRIERE IN NUMBER )
IS
  ANI         NUMBER(10) := 0;
  LUNAI       NUMBER(10) := 0;
  NR          NUMBER(10) := 0;
  VCODINTR    NUMBER(10) := 0;
  VCODINTR1   NUMBER(10) := 0;
  VCODNIR     NUMBER(10) := 0;
  VCODNIRSTOC NUMBER(10) := 0;
  aCODSERIE   NUMBER(20) := 0;
  aCODNIRSER  NUMBER(20) := 0;
  NOMSERIE    VARCHAR2(75) := &apos;&apos;;
  aCODLOCATIE NUMBER(20) := 0;
  aCODCERTIF NUMBER(20) := 0;


BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);


  -- codific certificate;
  FOR V_REC IN (SELECT 
                  NSE.CODNIRSER, 
                  NSE.NRCERTIF, 
                  NS.FURNIZOR, 
                  NS.CODOBIECT 
                FROM 
                  TMP_NIRSERINI NSE, 
                  TMP_NIRSTOCINI NS  
                WHERE 
                  NSE.NRCERTIF IS NOT NULL 
                  AND NSE.CODNIRSTOC = NS.CODNIRSTOC
               )
  LOOP
    BEGIN
      SELECT CODCERTIF INTO aCODCERTIF 
      FROM 
        CERTIF 
      WHERE 
        COALESCE(CODPART, 0)       = COALESCE(V_REC.FURNIZOR, 0) 
        AND COALESCE(CODOBIECT, 0) = COALESCE(V_REC.CODOBIECT, 0) 
        AND UPPER(NRCERTIF)        = UPPER(V_REC.NRCERTIF);
      EXCEPTION WHEN OTHERS THEN aCODCERTIF := 0;
    END;
    IF aCODCERTIF = 0 THEN
      aCODCERTIF := SEQ_CERTIF_CODCERTIF.NEXTVAL;
      INSERT INTO CERTIF(CODCERTIF, NRCERTIF, CODPART, CODOBIECT)
      VALUES(aCODCERTIF, V_REC.NRCERTIF, V_REC.FURNIZOR, V_REC.CODOBIECT);
    END IF;

    UPDATE TMP_NIRSERINI
    SET
      CODCERTIF = aCODCERTIF
    WHERE
      CODNIRSER = V_REC.CODNIRSER;
  END LOOP;


  -- codific locatii;
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI WHERE DENUM IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODLOCATIE INTO aCODLOCATIE FROM NLOCATII WHERE CODGEST = aGEST AND UPPER(DENUMIRE) = UPPER(V_REC.DENUM);
      EXCEPTION WHEN OTHERS THEN aCODLOCATIE := 0;
    END;
    IF aCODLOCATIE = 0 THEN
      aCODLOCATIE := SEQ_NLOCALIT_CODLOCALIT.NEXTVAL;
      INSERT INTO NLOCATII(CODLOCATIE, CODGEST, DENUMIRE, INDEXLOCAL)
      VALUES(aCODLOCATIE, aGEST, V_REC.DENUM, 1 + (SELECT COUNT(*) FROM NLOCATII WHERE CODGEST = aGEST));
    END IF;

    UPDATE TMP_NIRSTOCINI
    SET
     CODLOCATIE = aCODLOCATIE
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;




  IF SUPRASCRIERE = 1 THEN
  FOR V_REC IN
       (SELECT
           NS.CODNIRSTOC,
           NS.CODNIR,
           I1.CODINTR1,
           I.CODINTR,
           I.DATADOC,
           NS.CODOBIECT,
           NS.CODIOART,
           NS.UMSEC,
           (NS.PRET - NS.ADAOS) ,
           NS.PRET ,
           NS.PUVAL,
           NS.TVA,
           NS.TG,
           NS.TIPSERIE,
           NS.CANTNIR,
           NS.CODLOCATIE, I.PARTENER,
           I.INITIALIZARI,
           NS.PUMAXIMAL,
           NS.CANTUM1, NS.CANTUM2,
           NS.PROCENTADAOS,
           U1.DEN_UM1,
           U1.PARITATE,
           NS.D1,
           NS.D2,
           NS.D3,
           I1.NRCERTIF,
           NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
           NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
           N.TIPNIR,
           NS.CODGESTPROD,
           NS.REST,
           NS.SERIELOT,
           I1.CODCENTRU
        FROM
          NIRSTOC NS -- NIR-uri din INTRARI
          LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
          LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
          LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
          LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR,
          NUM1 U1
        WHERE
          N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
          AND NS.CODIOART = aCODIOART
          AND NS.UMSEC    = U1.CODUM1 AND N.TIPNIR &lt; 10
     )
     LOOP
       DELETE FROM NIRSER  WHERE  CODNIRSTOC = V_REC.CODNIRSTOC;
       DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
     END LOOP;
    END IF;

 -- BEGIN
    SELECT COUNT(*) INTO NR FROM STOCINI WHERE CODGEST = aGEST;
    IF NR = 0 THEN
     INSERT INTO STOCINI(CODSTOCINI, CODGEST) VALUES (SEQ_STOCINI_CODSTOCINI.NEXTVAL, aGEST);
    END IF;

  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     IF V_REC.CODNIRSTOC &lt; 0 THEN -- linie stoc noua de stoc
       SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
       SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
       SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
       SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;

       UPDATE TMP_NIRSERINI SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

       INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
       VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);

       INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF, CODCENTRU)
       VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ , v_rec.PRETACHIZ  , v_rec.CANTNIR , v_rec.TG, V_REC.PUMAXIMAL , V_REC.NRCERTIF, V_REC.CODCENTRU );

       INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
       VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);

       INSERT INTO NIRSTOC
       (CODNIRSTOC,
        CODNIR,
        CODINTR1,
        CANTNIR,
        REST,
        UMSEC,
        CODOBIECT,
        CODIOART,
        PRET,
        PUVAL,
        ADAOS,
        TVA,
        TIPSERIE,
        FURN,
        DATAACHIZ,
        TIPDOCACHIZ,
        PUMAXIMAL,
        CODLOCATIE,
        TG,
        CANTUM1,
        RESTUM1,
        CANTUM2,
        RESTUM2,
        PROCENTADAOS,
        D1,
        D2,
        D3,
        ROTLEI,
        ROTVALUTA, 
        SERIELOT,
        PROVIZION
        )
       VALUES (vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR , v_rec.CANTNIR , V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART,
              V_REC.PRETINREG ,
              V_REC.PUVAL,
             (V_REC.PRETINREG - V_REC.PRETACHIZ), V_REC.TVA, V_REC.TIPSERIE,
          V_REC.FURNIZOR,
          V_REC.DATADOC,
          1,
          V_REC.PUMAXIMAL,
          V_REC.CODLOCATIE,
          V_REC.TG,
          V_REC.CANTUM1,
          V_REC.CANTUM1,
          V_REC.CANTUM2,
          V_REC.CANTUM2,
          V_REC.PROCENTADAOS,
          V_REC.D1,
          V_REC.D2,
          V_REC.D3 ,
          V_REC.ROTLEI,
          V_REC.ROTVALUTA,
          V_REC.SERIELOT,
          V_REC.PROVIZION
           );

       INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR  , V_REC.CANTUM1, V_REC.CANTUM2);



     ELSE
       UPDATE INTRARI
       SET
         DATADOC  = v_rec.DATADOC,
         PARTENER = v_rec.FURNIZOR
       WHERE
         CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR);

       UPDATE INTRARI1
       SET
         UMSEC     = V_REC.UMSEC,
         PRETORIG  = v_rec.PRETACHIZ ,
         PU        = v_rec.PRETACHIZ ,
         CANT      = v_rec.CANTNIR ,
         TG        = v_rec.TG,
         NRCERTIF  = V_REC.NRCERTIF,
         CODCENTRU = V_REC.CODCENTRU,
         PUMAXIMAL = v_rec.PUMaximal
       WHERE
         CODINTR1 = v_rec.CODINTR1 ;


       UPDATE NIR
       SET
         DATANIR = v_rec.DATADOC,
         GEST    = aGEST
       WHERE
         CODNIR = v_rec.CODNIR ;


       UPDATE NIRSTOC
       SET
         CANTNIR      = V_REC.CANTNIR ,
         CANTUM1      = V_REC.CANTUM1,
         CANTUM2      = V_REC.CANTUM2,
         CODIOART     = V_REC.CODIOART,
         CODOBIECT    = V_REC.CODOBIECT,
         UMSEC        = V_REC.UMSEC,
         PRET         = V_REC.PRETINREG ,
         PUVAL        = V_REC.PUVAL ,
         ADAOS        = (V_REC.PRETINREG - V_REC.PRETACHIZ) ,
         TVA          = V_REC.TVA,
         REST         = PKG_INTRARI.GET_REST_STOC(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR ),
         RESTUM1      = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
         RESTUM2      = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
         FURN         = V_REC.FURNIZOR,
         DATAACHIZ    = V_REC.DATADOC,
         TIPDOCACHIZ  = 1,
         PUMAXIMAL    = V_REC.PUMAXIMAL ,
         CODLOCATIE   = V_REC.CODLOCATIE,
         TG           = V_REC.TG,
         PROCENTADAOS = V_REC.PROCENTADAOS,
         D1           = V_REC.D1,
         D2           = V_REC.D2,
         D3           = V_REC.D3,
         SERIELOT     = V_REC.SERIELOT,
         PROVIZION    = V_REC.PROVIZION
       WHERE
          CODNIRSTOC = v_rec.CODNIRSTOC;


       SELECT COUNT(*) INTO NR
       FROM
         NIRLUNA
        WHERE
          CODNIRSTOC = v_rec.CODNIRSTOC
          AND AN = ANI
          AND LUNA = LUNAI;

        IF NR = 0 THEN
          INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES (V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);
        ELSE
          UPDATE NIRLUNA
          SET
            REST    = V_REC.CANTNIR,
            RESTUM1 = V_REC.CANTUM1,
            RESTUM2 = V_REC.CANTUM2
          WHERE
            CODNIRSTOC = v_rec.CODNIRSTOC
            AND AN = ANI
            AND LUNA = LUNAI;
        END IF;
     END IF;
  END LOOP;

 --  INSERT INTO VOODOO (NR) VALUES (100);
  FOR V_REC IN (SELECT * FROM TMP_NIRSERINI)
  LOOP
  --  INSERT INTO VOODOO (NR) VALUES (200);


   IF V_REC.CODSERIE = 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      BEGIN
        SELECT NVL(SERIE, &apos;?&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
        EXCEPTION WHEN OTHERS THEN NOMSERIE := &apos;?&apos;;
      END;

      IF NVL(NOMSERIE, &apos;?&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;


   IF V_REC.CODNIRSER &lt; 0 THEN
      SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO aCODNIRSER FROM DUAL;

      INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CODCERTIF)
      VALUES (aCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR, V_REC.CANTNIR, V_REC.CODCERTIF);
      INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
      VALUES (aCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);

   ELSE
     UPDATE NIRSER
     SET
       CANTNIR   = V_REC.CANTNIR,
       CODCERTIF = V_REC.CODCERTIF,
       REST      = PKG_INTRARI.GET_REST_STOC_SERIE ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTNIR ),
       RESTUM1   = PKG_INTRARI.GET_REST_STOC_SERIE_UM1 ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTUM1 ),
       RESTUM2   = PKG_INTRARI.GET_REST_STOC_SERIE_UM2 ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTUM2 )
     WHERE
       CODNIRSER = V_REC.CODNIRSER;


       SELECT COUNT(*) INTO NR
       FROM
         NIRSERLUNA
        WHERE
          CODNIRSER= v_rec.CODNIRSER
          AND AN = ANI
          AND LUNA = LUNAI;

        IF NR = 0 THEN
          INSERT INTO NIRSERLUNA(CODNIRSER, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES (V_REC.CODNIRSER, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);
        ELSE
          UPDATE NIRSERLUNA
          SET
            REST    = V_REC.CANTNIR,
            RESTUM1 = V_REC.CANTUM1,
            RESTUM2 = V_REC.CANTUM2
          WHERE
            CODNIRSER = v_rec.CODNIRSER
            AND AN = ANI
            AND LUNA = LUNAI;
        END IF;





   END IF;





  END LOOP;

  COMMIT;
END;



PROCEDURE PREIA_TRANSFERURI_ANALIZATE(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2)
IS
BEGIN
  DELETE TMP_DOC_ANALIZAT;


  INSERT INTO TMP_DOC_ANALIZAT(CODDOC, NRDOC, DATADOC, SERIADOC)
  SELECT
    CODTRANSF,
    NRDOC,
    DATADOC,
    SERIADOC
  FROM
     TRANSF T
     LEFT OUTER JOIN
     (
       SELECT CODDOC, MAX(DATA) AS DATALOG
       FROM
       WINMADMIN.LOG
       WHERE
         UPPER(FIRMA) = PKG_GLOBALS.FIRMANAME
         AND TABELA = &apos;TRANSF&apos;
       GROUP BY CODDOC
     ) L
     ON L.CODDOC = T.CODTRANSF
   WHERE
     NVL(DATALOG, T.DATADOC) &gt;= TO_DATE(aDATASTART, &apos;DD.MM.YYYY&apos;)
     AND T.TIPDOC = 12
     AND NVL(DATALOG, T.DATADOC) &lt;= TO_DATE(aDATAEND, &apos;DD.MM.YYYY&apos;);

    COMMIT;


END;




PROCEDURE PREIA_TRANSFERURI_ANALIZATE2(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2)
IS
BEGIN
  DELETE TMP_DOC_ANALIZAT;


  INSERT INTO TMP_DOC_ANALIZAT(CODDOC, NRDOC, DATADOC, SERIADOC)
  SELECT
    CODTRANSF,
    NRDOC,
    DATADOC,
    SERIADOC
  FROM
     TRANSF T
   WHERE
     T.DATADOC &gt;= TO_DATE(aDATASTART, &apos;DD.MM.YYYY&apos;)
     AND T.TIPDOC = 12
     AND T.DATADOC &lt;= TO_DATE(aDATAEND, &apos;DD.MM.YYYY&apos;);

    COMMIT;


END;



PROCEDURE PREIA_TRANSFERURI_WMS(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2)
IS
BEGIN
  DELETE TMP_DOC_ANALIZAT;


  INSERT INTO TMP_DOC_ANALIZAT(CODDOC, NRDOC, DATADOC, SERIADOC)
  SELECT
    CODTRANSF,
    NRDOC,
    DATADOC,
    SERIADOC
  FROM
     TRANSF T
   WHERE
     T.TIPDOC = 12
     AND T.DATADOC &gt;= TO_DATE(aDATASTART, &apos;DD.MM.YYYY&apos;)
     AND T.DATADOC &lt;= TO_DATE(aDATAEND, &apos;DD.MM.YYYY&apos;)
     AND NVL(T.STADIUWMS, 0) = 1;
    COMMIT;


END;


PROCEDURE PREIA_IESIRI_ANALIZATE(aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2)
IS
BEGIN
  DELETE TMP_DOC_ANALIZAT;


  INSERT INTO TMP_DOC_ANALIZAT(CODDOC, NRDOC, DATADOC, SERIADOC)
  SELECT
    CODIES,
    NRDOC,
    DATADOC,
    SERIADOC
  FROM
     IESIRI I
     LEFT OUTER JOIN
     (
       SELECT CODDOC, MAX(DATA) AS DATALOG
       FROM
       WINMADMIN.LOG
       WHERE
         UPPER(FIRMA) = PKG_GLOBALS.FIRMANAME
         AND TABELA = &apos;IESIRI&apos;
       GROUP BY CODDOC
     ) L
     ON L.CODDOC = I.CODIES
   WHERE
     NVL(DATALOG, I.DATADOC) &gt;= TO_DATE(aDATASTART, &apos;DD.MM.YYYY&apos;)
     AND NVL(DATALOG, I.DATADOC) &lt;= TO_DATE(aDATAEND, &apos;DD.MM.YYYY&apos;);

    COMMIT;


END;


PROCEDURE FISAMF
IS
BEGIN
  DELETE FISAMF;
  INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST,PRETI, PRETE,PREFIXDOC,NRDOC, CANT, OBS)
  SELECT SEQ_FISAMF_CODFISAMF.NEXTVAL, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST,PRETI, PRETE,PREFIXDOC,NRDOC, CANT, OBS
  FROM TMP_FISAMF;
  COMMIT;
END;

PROCEDURE GET_STOC_INITIAL_EXT(SUPRASCRIERE IN NUMBER)
IS
BEGIN
  DELETE TMP_NIRSTOCINI;
  DELETE TMP_NIRSERINI;

  IF SUPRASCRIERE = 0 THEN
    INSERT INTO TMP_NIRSTOCINI
       (CODNIRSTOC,
       CODNIR,
       CODINTR1,
       CODINTR,
       DATADOC,
       CODOBIECT,
       CODIOART,
       UMSEC,
       PRETACHIZ ,
       PRETINREG,
       PUVAL,
       TVA,
       TG,
       TIPSERIE,
       CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS,
       DENUM,
       PARITATE,
       D1, D2, D3,
       NRCERTIF,
       ROTLEI,
       ROTVALUTA,
       TIPNIR,
       CODGESTPROD,
       REST,
       SERIELOT,
       CODCENTRU,
       CODIOARTINITIAL, -- aici pun gestiun NIR
       PROVIZION
       )
       (SELECT
           NS.CODNIRSTOC,
           NS.CODNIR,
           I1.CODINTR1,
           I.CODINTR,
           I.DATADOC,
           NS.CODOBIECT,
           NS.CODIOART,
           NS.UMSEC,
           (NS.PRET - NS.ADAOS),
           NS.PRET ,
           NS.PUVAL,
           NS.TVA,
           NS.TG,
           NS.TIPSERIE,
           NS.CANTNIR ,
           NS.CODLOCATIE, I.PARTENER,
           I.INITIALIZARI,
           NS.PUMAXIMAL,
           NS.CANTUM1, NS.CANTUM2,
           NS.PROCENTADAOS,
           NL.DENUMIRE, -- pun den. locatie pe denUM
           U1.PARITATE,
           NS.D1,
           NS.D2,
           NS.D3,
           I1.NRCERTIF,
           NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
           NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
           N.TIPNIR,
           NS.CODGESTPROD,
           NS.REST,
           NS.SERIELOT,
           I1.CODCENTRU,
           N.GEST,
           NS.PROVIZION
        FROM
          NIRSTOC NS -- NIR-uri din INTRARI
          LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
          LEFT OUTER JOIN NLOCATII NL ON NS.CODLOCATIE = NL.CODLOCATIE
          LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
          LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
          LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR,
          NUM1 U1
        WHERE
          EXISTS (SELECT * FROM TMP_MARIRI_STOC MS WHERE MS.CODGEST = N.GEST AND MS.CODIOART = NS.CODIOART)
          AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
          AND NS.UMSEC    = U1.CODUM1 AND N.TIPNIR &lt; 10
       );

    UPDATE TMP_NIRSTOCINI NS
    SET
    (MG, DIFPRET, ARETVANEEX, PUSTANDARD) = (SELECT MG, DIFPRET, ARETVANEEX, PUSTANDARD FROM TMP_IOART_LUNA I1 WHERE I1.CODIOART = NS.CODIOART);


    INSERT INTO TMP_NIRSERINI(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, SERIE)
    SELECT
      CODNIRSER,
      CODNIRSTOC,
      NSE.CODSERIE,
      CANTNIR,
      SER.SERIE
    FROM
      NIRSER NSE,
      NSERII SER
    WHERE
     NSE.CODSERIE = SER.CODSERIE
     AND EXISTS (SELECT CODNIRSTOC FROM TMP_NIRSTOC NS WHERE NS.CODNIRSTOC = NSE.CODNIRSTOC);
  END IF;
  COMMIT;
END;

PROCEDURE POST_STOC_INITIAL_EXT(SUPRASCRIERE IN NUMBER )
IS
  ANI         NUMBER(10) := 0;
  LUNAI       NUMBER(10) := 0;
  NR          NUMBER(10) := 0;
  VCODINTR    NUMBER(10) := 0;
  VCODINTR1   NUMBER(10) := 0;
  VCODNIR     NUMBER(10) := 0;
  VCODNIRSTOC NUMBER(10) := 0;
  aCODSERIE   NUMBER(20) := 0;
  aCODNIRSER  NUMBER(20) := 0;
  NOMSERIE    VARCHAR2(75) := &apos;&apos;;
  aCODLOCATIE NUMBER(20) := 0;
  aCODCERTIF  NUMBER(20) := 0;


BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);

  -- codific certificate;
  FOR V_REC IN (SELECT 
                  NSE.CODNIRSER, 
                  NSE.NRCERTIF, 
                  NS.FURNIZOR, 
                  NS.CODOBIECT 
                FROM 
                  TMP_NIRSERINI NSE, 
                  TMP_NIRSTOCINI NS  
                WHERE 
                  NSE.NRCERTIF IS NOT NULL 
                  AND NSE.CODNIRSTOC = NS.CODNIRSTOC
               )
  LOOP
    BEGIN
      SELECT CODCERTIF INTO aCODCERTIF 
      FROM 
        CERTIF 
      WHERE 
        COALESCE(CODPART, 0)       = COALESCE(V_REC.FURNIZOR, 0) 
        AND COALESCE(CODOBIECT, 0) = COALESCE(V_REC.CODOBIECT, 0) 
        AND UPPER(NRCERTIF)        = UPPER(V_REC.NRCERTIF);
      EXCEPTION WHEN OTHERS THEN aCODCERTIF := 0;
    END;
    IF aCODCERTIF = 0 THEN
      aCODCERTIF := SEQ_CERTIF_CODCERTIF.NEXTVAL;
      INSERT INTO CERTIF(CODCERTIF, NRCERTIF, CODPART, CODOBIECT)
      VALUES(aCODCERTIF, V_REC.NRCERTIF, V_REC.FURNIZOR, V_REC.CODOBIECT);
    END IF;

    UPDATE TMP_NIRSERINI
    SET
      CODCERTIF = aCODCERTIF
    WHERE
      CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

  -- codific locatii;
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI WHERE DENUM IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODLOCATIE INTO aCODLOCATIE FROM NLOCATII WHERE CODGEST = V_REC.CODIOARTINITIAL AND UPPER(DENUMIRE) = UPPER(V_REC.DENUM);
      EXCEPTION WHEN OTHERS THEN aCODLOCATIE := 0;
    END;
    IF aCODLOCATIE = 0 THEN
      aCODLOCATIE := SEQ_NLOCALIT_CODLOCALIT.NEXTVAL;
      INSERT INTO NLOCATII(CODLOCATIE, CODGEST, DENUMIRE, INDEXLOCAL)
      VALUES(aCODLOCATIE, V_REC.CODIOARTINITIAL, V_REC.DENUM, 1 + (SELECT COUNT(*) FROM NLOCATII WHERE CODGEST = V_REC.CODIOARTINITIAL));
    END IF;

    UPDATE TMP_NIRSTOCINI
    SET
     CODLOCATIE = aCODLOCATIE
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  IF SUPRASCRIERE = 1 THEN
  FOR V_REC IN
       (SELECT
           NS.CODNIRSTOC,
           NS.CODNIR,
           I1.CODINTR1,
           I.CODINTR,
           I.DATADOC,
           NS.CODOBIECT,
           NS.CODIOART,
           NS.UMSEC,
           (NS.PRET - NS.ADAOS) ,
           NS.PRET ,
           NS.PUVAL,
           NS.TVA,
           NS.TG,
           NS.TIPSERIE,
           NS.CANTNIR,
           NS.CODLOCATIE, I.PARTENER,
           I.INITIALIZARI,
           NS.PUMAXIMAL,
           NS.CANTUM1, NS.CANTUM2,
           NS.PROCENTADAOS,
           U1.DEN_UM1,
           U1.PARITATE,
           NS.D1,
           NS.D2,
           NS.D3,
           I1.NRCERTIF,
           NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
           NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
           N.TIPNIR,
           NS.CODGESTPROD,
           NS.REST,
           NS.SERIELOT,
           I1.CODCENTRU
        FROM
          NIRSTOC NS -- NIR-uri din INTRARI
          LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
          LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
          LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT
          LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR,
          NUM1 U1
        WHERE
          EXISTS (SELECT * FROM TMP_MARIRI_STOC MS WHERE MS.CODGEST = N.GEST AND MS.CODIOART = NS.CODIOART)
          AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
          AND NS.UMSEC    = U1.CODUM1 AND N.TIPNIR &lt; 10
     )
     LOOP
       DELETE FROM NIRSER  WHERE  CODNIRSTOC = V_REC.CODNIRSTOC;
       DELETE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
     END LOOP;
    END IF;

 -- BEGIN
    FOR V_REC IN (SELECT CODGEST FROM TMP_MARIRI_STOC)
    LOOP
        SELECT COUNT(*) INTO NR FROM STOCINI WHERE CODGEST = V_REC.CODGEST;
        IF NR = 0 THEN
         INSERT INTO STOCINI(CODSTOCINI, CODGEST) VALUES (SEQ_STOCINI_CODSTOCINI.NEXTVAL, V_REC.CODGEST);
        END IF;
    END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     IF V_REC.CODNIRSTOC &lt; 0 THEN -- linie stoc noua de stoc
       SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
       SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
       SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
       SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;

       UPDATE TMP_NIRSERINI SET CODNIRSTOC = vCODNIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

       INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
       VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);

       INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF, CODCENTRU)
       VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ , v_rec.PRETACHIZ  , v_rec.CANTNIR , v_rec.TG, V_REC.PUMAXIMAL , V_REC.NRCERTIF, V_REC.CODCENTRU );

       INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
       VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, V_REC.CODIOARTINITIAL, 1, 0, 0, 1);

       INSERT INTO NIRSTOC
       (CODNIRSTOC,
        CODNIR,
        CODINTR1,
        CANTNIR,
        REST,
        UMSEC,
        CODOBIECT,
        CODIOART,
        PRET,
        PUVAL,
        ADAOS,
        TVA,
        TIPSERIE,
        FURN,
        DATAACHIZ,
        TIPDOCACHIZ,
        PUMAXIMAL,
        CODLOCATIE,
        TG,
        CANTUM1,
        RESTUM1,
        CANTUM2,
        RESTUM2,
        PROCENTADAOS,
        D1,
        D2,
        D3,ROTLEI,ROTVALUTA, SERIELOT)
       VALUES (vCODNIRSTOC,
              vCODNIR,
              vCODINTR1,
              v_rec.CANTNIR ,
              v_rec.CANTNIR ,
              V_REC.UMSEC,
              V_REC.CODOBIECT,
              V_REC.CODIOART,
              V_REC.PRETINREG ,
              V_REC.PUVAL,
             (V_REC.PRETINREG - V_REC.PRETACHIZ), V_REC.TVA, V_REC.TIPSERIE,
          V_REC.FURNIZOR,
          V_REC.DATADOC,
          1,
          V_REC.PUMAXIMAL,
          V_REC.CODLOCATIE,
          V_REC.TG,
          V_REC.CANTUM1,
          V_REC.CANTUM1,
          V_REC.CANTUM2,
          V_REC.CANTUM2,
          V_REC.PROCENTADAOS,
          V_REC.D1,
          V_REC.D2,
          V_REC.D3 ,
          V_REC.ROTLEI,
          V_REC.ROTVALUTA,
          V_REC.SERIELOT
           );

       INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR  , V_REC.CANTUM1, V_REC.CANTUM2);



     ELSE
       UPDATE INTRARI
       SET
         DATADOC  = v_rec.DATADOC,
         PARTENER = v_rec.FURNIZOR
       WHERE
         CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR);

       UPDATE INTRARI1
       SET
         UMSEC     = V_REC.UMSEC,
         PRETORIG  = v_rec.PRETACHIZ ,
         PU        = v_rec.PRETACHIZ ,
         CANT      = v_rec.CANTNIR ,
         TG        = v_rec.TG,
         NRCERTIF  = V_REC.NRCERTIF,
         CODCENTRU = V_REC.CODCENTRU,
         PUMAXIMAL = v_rec.PUMaximal
       WHERE
         CODINTR1 = v_rec.CODINTR1 ;


       UPDATE NIR
       SET
         DATANIR = v_rec.DATADOC,
         GEST    = V_REC.CODIOARTINITIAL
       WHERE
         CODNIR = v_rec.CODNIR ;


       UPDATE NIRSTOC
       SET
         CANTNIR      = V_REC.CANTNIR ,
         CANTUM1      = V_REC.CANTUM1,
         CANTUM2      = V_REC.CANTUM2,
         CODIOART     = V_REC.CODIOART,
         CODOBIECT    = V_REC.CODOBIECT,
         UMSEC        = V_REC.UMSEC,
         PRET         = V_REC.PRETINREG ,
         PUVAL        = V_REC.PUVAL ,
         ADAOS        = (V_REC.PRETINREG - V_REC.PRETACHIZ) ,
         TVA          = V_REC.TVA,
         REST         = PKG_INTRARI.GET_REST_STOC(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR ),
         RESTUM1      = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
         RESTUM2      = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
         FURN         = V_REC.FURNIZOR,
         DATAACHIZ    = V_REC.DATADOC,
         TIPDOCACHIZ  = 1,
         PUMAXIMAL    = V_REC.PUMAXIMAL ,
         CODLOCATIE   = V_REC.CODLOCATIE,
         TG           = V_REC.TG,
         PROCENTADAOS = V_REC.PROCENTADAOS,
         D1           = V_REC.D1,
         D2           = V_REC.D2,
         D3           = V_REC.D3,
         SERIELOT     = V_REC.SERIELOT
       WHERE
          CODNIRSTOC = v_rec.CODNIRSTOC;


       SELECT COUNT(*) INTO NR
       FROM
         NIRLUNA
        WHERE
          CODNIRSTOC = v_rec.CODNIRSTOC
          AND AN = ANI
          AND LUNA = LUNAI;

        IF NR = 0 THEN
          INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES (V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);
        ELSE
          UPDATE NIRLUNA
          SET
            REST    = V_REC.CANTNIR,
            RESTUM1 = V_REC.CANTUM1,
            RESTUM2 = V_REC.CANTUM2
          WHERE
            CODNIRSTOC = v_rec.CODNIRSTOC
            AND AN = ANI
            AND LUNA = LUNAI;
        END IF;
     END IF;
  END LOOP;

 --  INSERT INTO VOODOO (NR) VALUES (100);
  FOR V_REC IN (SELECT * FROM TMP_NIRSERINI)
  LOOP
  --  INSERT INTO VOODOO (NR) VALUES (200);


   IF V_REC.CODSERIE = 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      BEGIN
        SELECT NVL(SERIE, &apos;?&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
        EXCEPTION WHEN OTHERS THEN NOMSERIE := &apos;?&apos;;
      END;

      IF NVL(NOMSERIE, &apos;?&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;


   IF V_REC.CODNIRSER &lt; 0 THEN
      SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO aCODNIRSER FROM DUAL;

      INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CODCERTIF)
      VALUES (aCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR, V_REC.CANTNIR, V_REC.CODCERTIF);
      INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
      VALUES (aCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);

   ELSE
     UPDATE NIRSER
     SET
       CANTNIR   = V_REC.CANTNIR,
       CODCERTIF = V_REC.CODCERTIF, 
       REST      = PKG_INTRARI.GET_REST_STOC_SERIE ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTNIR ),
       RESTUM1   = PKG_INTRARI.GET_REST_STOC_SERIE_UM1 ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTUM1 ),
       RESTUM2   = PKG_INTRARI.GET_REST_STOC_SERIE_UM2 ((SELECT CODNIR FROM NIRSTOC NS WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTUM2 )
     WHERE
       CODNIRSER = V_REC.CODNIRSER;


       SELECT COUNT(*) INTO NR
       FROM
         NIRSERLUNA
        WHERE
          CODNIRSER= v_rec.CODNIRSER
          AND AN = ANI
          AND LUNA = LUNAI;

        IF NR = 0 THEN
          INSERT INTO NIRSERLUNA(CODNIRSER, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES (V_REC.CODNIRSER, ANI, LUNAI, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);
        ELSE
          UPDATE NIRSERLUNA
          SET
            REST    = V_REC.CANTNIR,
            RESTUM1 = V_REC.CANTUM1,
            RESTUM2 = V_REC.CANTUM2
          WHERE
            CODNIRSER = v_rec.CODNIRSER
            AND AN = ANI
            AND LUNA = LUNAI;
        END IF;





   END IF;





  END LOOP;

  COMMIT;
END;



PROCEDURE SET_CANTNIR_OPERAT_TRANSF_EXT (aCODTRANSF1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, ObsNIR IN VARCHAR2, CODUSER IN NUMBER)
IS
  CANTTRANSF  NUMERIC(20, 7);
  aCODNIR     NUMBER(20);
  aCANTPREL   NUMERIC(20, 7);
  MANCANT     NUMERIC(20, 7);
  aCODTRANSF  NUMBER(20);
  aNRDOC      NUMBER(20);
  aSERIEDOC   VARCHAR2(10) := NULL;
  aSIMBOLDOC  VARCHAR2(10) := NULL;
  aCODNIRSTOC NUMBER(20);
  aCARNETNIR  NUMBER(20);
  aGEST       NUMBER(20);
  NR          NUMBER;
  aDATANIR    DATE;
BEGIN
  -- NIR-ul pe care adaug constatarile este pregatit in TMP_NIR
  -- constatarile dintr-o transmisie prin restserver folosesc acelasi NIR;
  -- RESTSERVERUL valideaza sa se proceseze un singur transfer per pachet de date
  
  SELECT COUNT(*) INTO NR FROM TMP_NIR;
  IF NR = 0 THEN  --
    BEGIN  
      SELECT  
        N.GEST,
        N.CODTRANSF,
        N.DATANIR,
        N.CARNETNIR
      INTO
        aGEST,
        aCODTRANSF,
        aDATANIR,
        aCARNETNIR  
      FROM
        NIRSTOC NS,
        NIR N
      WHERE
        NS.CODTRANSF1 = aCODTRANSF1
        AND N.CODNIR = NS.CODNIR
        AND NVL(N.OPERAT, 0) = 0
        AND NS.CANTNIR &gt; 0
        AND ROWNUM = 1;
       EXCEPTION WHEN OTHERS THEN   
        aCARNETNIR := 0; 
     END; 
      
     IF NVL(ACARNETNIR, 0) &lt;&gt; 0 THEN
       aNRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(aCARNETNIR, aSERIEDOC,  aSIMBOLDOC );
       IF PKG_CARNETEDOC.CANLOCKNUMARDOC(aCARNETNIR,aNRDOC) = 0 THEN
         aNRDOC    := NULL;
         aSERIEDOC := NULL;
       END IF;
      
      aCODNIR := SEQ_NIR_CODNIR.NEXTVAL;

      INSERT INTO TMP_NIR(CODNIR, 
                          CODTRANSF, 
                          CARNETNIR, 
                          DATANIR, 
                          NRNIR,  
                          GEST, 
                          ANULAT, 
                          BLOCAT, 
                          OPERAT, 
                          TIPNIR, 
                          USERID, 
                          DATACREARE, 
                          OBS)
            VALUES( aCODNIR, 
                    aCODTRANSF, 
                    aCARNETNIR, 
                    aDATANIR, 
                    aNRDOC, 
                    aGEST, 0, 0, 1, 12, 
                    PKG_GLOBALS.USERID, 
                    SYSDATE(), 
                    OBSNIR);




      INSERT INTO NIR(CODNIR, 
                      CODTRANSF, 
                      CARNETNIR, 
                      DATANIR, 
                      NRNIR,  
                      GEST, 
                      ANULAT, 
                      BLOCAT, 
                      OPERAT, 
                      TIPNIR, 
                      USERID, 
                      DATACREARE, 
                      OBS)
     SELECT                  
                      CODNIR, 
                      CODTRANSF, 
                      CARNETNIR, 
                      DATANIR, 
                      NRNIR,  
                      GEST, 
                      ANULAT, 
                      BLOCAT, 
                      OPERAT, 
                      TIPNIR, 
                      USERID, 
                      DATACREARE, 
                      OBS
    FROM
      TMP_NIR;                  

      IF NVL(aNRDOC, 0) &lt;&gt; 0 THEN
         PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETNIR, ANRDOC);
      END IF;

      INSERT INTO MODIFICARI(CODMODIFICARE, CODMASTER, TABLENAME, DATAMODIF, USERMODIF, TIPMODIF)
      VALUES (SEQ_MODIFICARI_CODMODIFICARE.NEXTVAL, aCODNIR, &apos;NIR&apos;, SysDate(), CodUser, 1);


     END IF;
      
      
      
      


  END IF; 
   
  
  BEGIN
    SELECT CANT INTO CANTTRANSF FROM TRANSF1 WHERE CODTRANSF1 = aCODTRANSF1;
    EXCEPTION WHEN OTHERS THEN CANTTRANSF := 0;
  END;

  BEGIN
    SELECT CODNIR INTO aCODNIR FROM TMP_NIR;
    EXCEPTION WHEN OTHERS THEN
       aCODNIR := 0;
  END;

  IF CANTTRANSF &gt; 0 AND aCODNIR &gt; 0 THEN
    MANCANT := aCANT;
    FOR V_REC IN
      (SELECT
         NS.CODNIRSTOC,
         NS.CODNIR,
         N.GEST,
         N.DATANIR,
         N.CARNETNIR,
         N.CODTRANSF,
         NS.CANTNIR,
         NS.CODNIRSTOCPARINTE,
         A.RELATIEUM1
       FROM
         NIRSTOC NS,
         NIR N,
         NARTOBJ O,
         NART A
       WHERE
         NS.CODTRANSF1 = aCODTRANSF1
         AND N.CODNIR = NS.CODNIR
         AND NVL(N.OPERAT, 0) = 0
         AND CANTNIR &gt; 0
         AND O.CODOBIECT = NS.CODOBIECT
         AND A.CODARTICOL = O.CODARTICOL
      )
      LOOP
        IF MANCANT &gt; 0 THEN
/*       CERINTA :  la fiecare transmisie voi genera o linie noua de NIR asa ca am comentat codul de mai jos 
          BEGIN
            SELECT NVL(MIN(CODNIR), 0) INTO aCODNIR FROM NIR WHERE CODTRANSF = V_REC.CODTRANSF AND OPERAT = 1;
            EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
          END;
*/

          aCANTPREL := 0;

          IF V_REC.CANTNIR &gt; MANCANT THEN
             aCANTPREL := MANCANT;
             
             
             aCodNIRStoc := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;
             INSERT INTO NIRSTOC (CODNIRSTOC, 
                                  CODNIR, 
                                  CODTRANSF1, 
                                  CODNIRSTOCPARINTE, 
                                  CANTNIR, 
                                  UMSEC, 
                                  CODOBIECT, 
                                  CODIOART, 
                                  PRET, 
                                  ADAOS, 
                                  TVA, 
                                  TIPSERIE, 
                                  CODLIVR1, 
                                  REST, 
                                  PROCENTADAOS, 
                                  SUPLIMENT, 
                                  CANTFURN, 
                                  ROTLEI, 
                                  ROTVALUTA, 
                                  CODLOCATIE, 
                                  CANTUM1, 
                                  CANTUM2, 
                                  RESTUM1, 
                                  RESTUM2, 
                                  TG, 
                                  PUMAXIMAL, 
                                  FURN, 
                                  DATAACHIZ, 
                                  TIPDOCACHIZ, 
                                  CODGESTPROD, 
                                  SUBUNITATEA, 
                                  DISCLIKISTOC, 
                                  D1, 
                                  D2, 
                                  D3, 
                                  PUVAL, 
                                  PROVIZION, 
                                  SUPLNEDED, 
                                  SERIELOT)
                         SELECT aCodNIRSTOC, 
                                aCODNIR, 
                                CODTRANSF1, 
                                CODNIRSTOCPARINTE, 
                                aCANTPREL, 
                                UMSEC, 
                                CODOBIECT, 
                                CODIOART, 
                                PRET, 
                                ADAOS, 
                                TVA, 
                                TIPSERIE, 
                                CODLIVR1, 
                                aCANTPREL, 
                                PROCENTADAOS, 
                                SUPLIMENT, 
                                aCANTPREL, 
                                ROTLEI, 
                                ROTVALUTA, 
                                aCODLOCATIE, 
--                                CANTUM1, 
                                 PKG_JURNAL.GetSpecificCantUM1(V_REC.RelatieUM1, D1, D2, D3, aCANTPREL),
                                CANTUM2, 
--                                RESTUM1, 
                                 PKG_JURNAL.GetSpecificCantUM1(V_REC.RelatieUM1, D1, D2, D3, aCANTPREL),
                                RESTUM2, 
                                TG, 
                                PUMAXIMAL, 
                                FURN, 
                                DATAACHIZ, 
                                TIPDOCACHIZ, 
                                CODGESTPROD, 
                                SUBUNITATEA, 
                                DISCLIKISTOC, 
                                D1, 
                                D2, 
                                D3, 
                                PUVAL, 
                                PROVIZION, 
                                SUPLNEDED, 
                                SERIELOT
                         FROM
                           NIRSTOC
                         WHERE
                           CODNIRSTOC = V_REC.CODNIRSTOC;

             INSERT INTO NIRSER(CODNIRSER,CODNIRSTOC,CODSERIE,CANTNIR,REST, TG, DATAPROD, OBS, STARE)
             SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL, aCodNIRSTOC, CODSERIE,aCANTPREL, aCANTPREL, TG, DATAPROD, OBS, STARE
             FROM
               NIRSER
             WHERE
                CODNIRSTOC = V_REC.CODNIRSTOC;  

             UPDATE NIRSTOC
             SET
               CANTNIR = CANTNIR - aCANTPREL
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSER
             SET
               CANTNIR = CANTNIR - aCANTPREL
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSTOC
             SET
               CANTFURN = CANTNIR
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


          ELSE
            aCANTPREL := V_REC.CANTNIR;

            UPDATE NIRSTOC
            SET
              CODNIR = aCODNIR,
              CODLOCATIE = aCODLOCATIE
            WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSTOC NS
             SET
               REST    = PKG_INTRARI.GET_REST_STOC(aCODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR)
             WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;

             UPDATE NIRSER NS
             SET
               REST    = PKG_INTRARI.GET_REST_STOC_SERIE(aCODNIR,NS.CODNIRSER, V_REC.CANTNIR)
             WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;
         END IF;

          MANCANT := MANCANT - aCANTPREL;



        END IF;
      END LOOP;

      BEGIN
        SELECT CODTRANSF INTO aCODTRANSF FROM  TRANSF1 WHERE CODTRANSF1 = aCODTRANSF1;
        EXCEPTION WHEN OTHERS THEN aCODTRANSF := 0;
      END;

      IF aCODTRANSF &lt;&gt; 0 THEN
        DELETE FROM NIR N WHERE CODTRANSF = aCODTRANSF AND NVL(OPERAT, 0) = 0 AND
        (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0;
      END IF;

--   COMMIT;
  END IF;
END;



PROCEDURE SET_CANTNIR_OPERAT_TRANSF (aCODTRANSF1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, ObsNIR IN VARCHAR2, CODUSER IN NUMBER)
IS
  CANTTRANSF  NUMERIC(20, 7);
  aCODNIR     NUMBER(20);
  aCANTPREL   NUMERIC(20, 7);
  MANCANT     NUMERIC(20, 7);
  aCODTRANSF  NUMBER(20);
  aNRDOC      NUMBER(20);
  aSERIEDOC   VARCHAR2(10) := NULL;
  aSIMBOLDOC  VARCHAR2(10) := NULL;
  aCODNIRSTOC NUMBER(20);

BEGIN
  BEGIN
    SELECT CANT INTO CANTTRANSF FROM TRANSF1 WHERE CODTRANSF1 = aCODTRANSF1;
    EXCEPTION WHEN OTHERS THEN CANTTRANSF := 0;
  END;

  IF CANTTRANSF &gt; 0 THEN
    MANCANT := aCANT;
    FOR V_REC IN
      (SELECT
         NS.CODNIRSTOC,
         NS.CODNIR,
         N.GEST,
         N.DATANIR,
         N.CARNETNIR,
         N.CODTRANSF,
         NS.CANTNIR,
         NS.CODNIRSTOCPARINTE,
         A.RELATIEUM1
       FROM
         NIRSTOC NS,
         NIR N,
         NARTOBJ O,
         NART A
       WHERE
         NS.CODTRANSF1 = aCODTRANSF1
         AND N.CODNIR = NS.CODNIR
         AND NVL(N.OPERAT, 0) = 0
         AND CANTNIR &gt; 0
         AND O.CODOBIECT = NS.CODOBIECT
         AND A.CODARTICOL = O.CODARTICOL
      )
      LOOP
        IF MANCANT &gt; 0 THEN
/*       CERINTA :  la fiecare transmisie voi genera o linie noua de NIR asa ca am comentat codul de mai jos 
          BEGIN
            SELECT NVL(MIN(CODNIR), 0) INTO aCODNIR FROM NIR WHERE CODTRANSF = V_REC.CODTRANSF AND OPERAT = 1;
            EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
          END;
*/
         aCODNIR   := 0; -- cerinta ca fiecare transmisie sa se faca pe un NIR nou cu OPERAT = 1

          aCANTPREL := 0;
          IF aCODNIR = 0 THEN
            aCODNIR := SEQ_NIR_CODNIR.NEXTVAL;

            IF NVL(V_REC.CARNETNIR, 0) &lt;&gt; 0 THEN
              aNRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(V_REC.CARNETNIR, aSERIEDOC,  aSIMBOLDOC );
              IF PKG_CARNETEDOC.CANLOCKNUMARDOC(V_REC.CARNETNIR,aNRDOC) = 0 THEN
                aNRDOC    := NULL;
                aSERIEDOC := NULL;
              END IF;
            END IF;


            INSERT INTO NIR(CODNIR, CODTRANSF, CARNETNIR, DATANIR, NRNIR,  GEST, ANULAT, BLOCAT, OPERAT, TIPNIR, USERID, DATACREARE, OBS)
            VALUES (aCODNIR, V_REC.CODTRANSF, V_REC.CARNETNIR, V_REC.DATANIR, aNRDOC, V_REC.GEST, 0, 0, 1, 12, PKG_GLOBALS.USERID, SYSDATE(), OBSNIR);

            INSERT INTO MODIFICARI(CODMODIFICARE, CODMASTER, TABLENAME, DATAMODIF, USERMODIF, TIPMODIF)
            VALUES (SEQ_MODIFICARI_CODMODIFICARE.NEXTVAL, aCODNIR, &apos;NIR&apos;, SysDAte(), CodUser, 1);

            IF NVL(aNRDOC, 0) &lt;&gt; 0 THEN
               PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, ANRDOC);
            END IF;
          END IF;

          IF V_REC.CANTNIR &gt; MANCANT THEN
             aCANTPREL := MANCANT;
             
             
             aCodNIRStoc := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;
             INSERT INTO NIRSTOC (CODNIRSTOC, 
                                  CODNIR, 
                                  CODTRANSF1, 
                                  CODNIRSTOCPARINTE, 
                                  CANTNIR, 
                                  UMSEC, 
                                  CODOBIECT, 
                                  CODIOART, 
                                  PRET, 
                                  ADAOS, 
                                  TVA, 
                                  TIPSERIE, 
                                  CODLIVR1, 
                                  REST, 
                                  PROCENTADAOS, 
                                  SUPLIMENT, 
                                  CANTFURN, 
                                  ROTLEI, 
                                  ROTVALUTA, 
                                  CODLOCATIE, 
                                  CANTUM1, 
                                  CANTUM2, 
                                  RESTUM1, 
                                  RESTUM2, 
                                  TG, 
                                  PUMAXIMAL, 
                                  FURN, 
                                  DATAACHIZ, 
                                  TIPDOCACHIZ, 
                                  CODGESTPROD, 
                                  SUBUNITATEA, 
                                  DISCLIKISTOC, 
                                  D1, 
                                  D2, 
                                  D3, 
                                  PUVAL, 
                                  PROVIZION, 
                                  SUPLNEDED, 
                                  SERIELOT)
                         SELECT aCodNIRSTOC, 
                                aCODNIR, 
                                CODTRANSF1, 
                                CODNIRSTOCPARINTE, 
                                aCANTPREL, 
                                UMSEC, 
                                CODOBIECT, 
                                CODIOART, 
                                PRET, 
                                ADAOS, 
                                TVA, 
                                TIPSERIE, 
                                CODLIVR1, 
                                aCANTPREL, 
                                PROCENTADAOS, 
                                SUPLIMENT, 
                                aCANTPREL, 
                                ROTLEI, 
                                ROTVALUTA, 
                                aCODLOCATIE, 
--                                CANTUM1, 
                                 PKG_JURNAL.GetSpecificCantUM1(V_REC.RelatieUM1, D1, D2, D3, aCANTPREL),
                                CANTUM2, 
--                                RESTUM1, 
                                 PKG_JURNAL.GetSpecificCantUM1(V_REC.RelatieUM1, D1, D2, D3, aCANTPREL),
                                RESTUM2, 
                                TG, 
                                PUMAXIMAL, 
                                FURN, 
                                DATAACHIZ, 
                                TIPDOCACHIZ, 
                                CODGESTPROD, 
                                SUBUNITATEA, 
                                DISCLIKISTOC, 
                                D1, 
                                D2, 
                                D3, 
                                PUVAL, 
                                PROVIZION, 
                                SUPLNEDED, 
                                SERIELOT
                         FROM
                           NIRSTOC
                         WHERE
                           CODNIRSTOC = V_REC.CODNIRSTOC;

             INSERT INTO NIRSER(CODNIRSER,CODNIRSTOC,CODSERIE,CANTNIR,REST, TG, DATAPROD, OBS, STARE)
             SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL, aCodNIRSTOC, CODSERIE,aCANTPREL, aCANTPREL, TG, DATAPROD, OBS, STARE
             FROM
               NIRSER
             WHERE
                CODNIRSTOC = V_REC.CODNIRSTOC;  

             UPDATE NIRSTOC
             SET
               CANTNIR = CANTNIR - aCANTPREL
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSER
             SET
               CANTNIR = CANTNIR - aCANTPREL
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSTOC
             SET
               CANTFURN = CANTNIR
             WHERE
               CODNIRSTOC = V_REC.CODNIRSTOC;


          ELSE
            aCANTPREL := V_REC.CANTNIR;

            UPDATE NIRSTOC
            SET
              CODNIR = aCODNIR,
              CODLOCATIE = aCODLOCATIE
            WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;


             UPDATE NIRSTOC NS
             SET
               REST    = PKG_INTRARI.GET_REST_STOC(aCODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR)
             WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;

             UPDATE NIRSER NS
             SET
               REST    = PKG_INTRARI.GET_REST_STOC_SERIE(aCODNIR,NS.CODNIRSER, V_REC.CANTNIR)
             WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;
         END IF;

          MANCANT := MANCANT - aCANTPREL;



        END IF;
      END LOOP;

      BEGIN
        SELECT CODTRANSF INTO aCODTRANSF FROM  TRANSF1 WHERE CODTRANSF1 = aCODTRANSF1;
        EXCEPTION WHEN OTHERS THEN aCODTRANSF := 0;
      END;

      IF aCODTRANSF &lt;&gt; 0 THEN
        DELETE FROM NIR N WHERE CODTRANSF = aCODTRANSF AND NVL(OPERAT, 0) = 0 AND
        (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0;
      END IF;

--   COMMIT;
  END IF;
END;



PROCEDURE SET_CANTNIR_OPERAT_INTRARI (aCODINTR1 IN NUMBER, aCANT IN NUMBER)
IS
  CANTINTR   NUMERIC(20, 7);
  aCANTPREL  NUMERIC(20, 7);
  MANCANT    NUMERIC(20, 7);
  NR         NUMBER(10);

BEGIN
  BEGIN
    SELECT CANT INTO CANTINTR FROM INTRARI1 WHERE CODINTR1 = aCODINTR1;
    EXCEPTION WHEN OTHERS THEN CANTINTR := 0;
  END;

  IF CANTINTR &gt; 0 THEN
    SELECT COUNT(*) INTO NR FROM NIRSTOC WHERE CODINTR1 = aCodIntr1;
    MANCANT := aCANT;
    FOR V_REC IN
      (SELECT
         NS.CODNIRSTOC,
         NS.CANTNIR,
         NS.CANTFURN,
         ROWNUM
       FROM
         NIRSTOC NS
       WHERE
         NS.CODINTR1 = aCODINTR1
         AND NS.CANTFURN &gt; 0
      )
      LOOP
          IF V_REC.ROWNUM = NR THEN
            UPDATE NIRSTOC
            SET
              CANTNIR = MANCANT
            WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;
          ELSE
            aCANTPREL := 0;
            IF V_REC.CANTFURN &gt; MANCANT THEN
               aCANTPREL := MANCANT;
            ELSE
              aCANTPREL := V_REC.CANTFURN;
            END IF;

            UPDATE NIRSTOC
            SET
              CANTNIR = aCANTPREL
            WHERE
              CODNIRSTOC = V_REC.CODNIRSTOC;

            IF MANCANT &gt; 0 THEN
              MANCANT := MANCANT - aCANTPREL;
            END IF;
          END IF;
      END LOOP;


--   COMMIT;
  END IF;
END;

PROCEDURE SET_CANTNIR_OPERAT_INTRARI_EXT
IS
 aCODNIR      NUMBER(20);
 NR           NUMBER(10);
 I            NUMBER(10);
 aCANTFURN    NUMBER(20, 7);
 MANCANTFURN  NUMBER(20, 7);
 aDATANIR     DATE;
 aADAOS       NUMBER(20, 7);
 aCODIOART    NUMBER(20);
 aFURN        NUMBER(20);
 aCODNIRSTOC  NUMBER(20);


 aCODDVI1     NUMBER(20);
BEGIN
  FOR V_REC_I IN
  (
   SELECT CODINTR1,
         I1.CODINTR,
         CANT AS CANTFURN,
         UMSEC,
         I1.CODOBIECT,
         PU,
         I.TIPDOC,
         A.TIPSERIE,
         O.ROTUNJIRE,
         DECODE(NVL(I.CURS, 0), 0, 1, NVL(I.CURS, 0)) AS CURS
   FROM
      INTRARI1 I1,
      INTRARI I,
      NARTOBJ O,
      NART A
   WHERE
      EXISTS (SELECT CODINTR1 FROM TMP_RECEPTIEWMS R WHERE R.CODINTR1 = I1.CODINTR1 AND I.CODINTR = I1.CODINTR)
      AND I1.CODOBIECT = O.CODOBIECT
      AND O.CODARTICOL = A.CODARTICOL
  )
  LOOP
    BEGIN
      SELECT CODNIR, DATANIR INTO aCODNIR, aDATANIR FROM NIR WHERE CODINTR = V_REC_I.CODINTR AND ROWNUM = 1;
      EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
    END;

    IF V_REC_I.TIPDOC = 5 THEN
      BEGIN
        SELECT CODDVI1 INTO aCODDVI1 FROM DVI1 WHERE CODINTR1 = V_REC_I.CODINTR1 AND ROWNUM = 1;
        EXCEPTION WHEN OTHERS THEN aCODDVI1 := 0;
      END;

      SELECT CODIOART, FURN, ADAOS INTO aCODIOART, aFURN, aADAOS FROM NIRSTOC WHERE CODDVI1 = aCODDVI1 AND ROWNUM = 1;

    ELSE
      SELECT CODIOART, FURN, ADAOS INTO aCODIOART, aFURN, aADAOS FROM NIRSTOC WHERE CODINTR1 = V_REC_I.CODINTR1 AND ROWNUM = 1;
    END IF;

    IF V_REC_I.TIPDOC = 5 THEN
      DELETE FROM NIRSTOC WHERE CODDVI1 = aCODDVI1;
    ELSE
      DELETE FROM NIRSTOC WHERE CODINTR1 = V_REC_I.CODINTR1;
    END IF;

    aCANTFURN := V_REC_I.CANTFURN;
    SELECT COUNT(*) INTO NR FROM TMP_RECEPTIEWMS WHERE CODINTR1 = V_REC_I.CODINTR1;
    I := 0;


    IF V_REC_I.TIPDOC = 5 THEN
      FOR V_REC_R IN (SELECT * FROM TMP_RECEPTIEWMS WHERE CODINTR1 = V_REC_I.CODINTR1)
        LOOP
          I := I + 1;
          IF I = NR THEN MANCANTFURN := aCANTFURN; ELSE MANCANTFURN := V_REC_R.CANT; END IF;

          aCODNIRSTOC := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;
          INSERT INTO NIRSTOC(CODNIRSTOC,
                              CODNIR,
                              CODDVI1,
                              CANTNIR,
                              CANTFURN,
                              UMSEC,
                              CODOBIECT,
                              CODIOART,
                              PRET,
                              ADAOS,
                              FURN,
                              CODLOCATIE,
                              DATAACHIZ,
                              TIPSERIE,
                              ROTLEI,
                              ROTVALUTA,
                              TG
                              )
         VALUES
           (aCODNIRSTOC,
            aCODNIR,
            aCODDVI1,
            V_REC_R.CANT,
            MANCANTFURN,
            V_REC_I.UMSEC,
            V_REC_I.CODOBIECT,
            aCODIOART,
            PKG_PRETURI.WMROTOPRET(NVL(V_REC_I.ROTUNJIRE,0),  V_REC_I.PU * V_REC_I.CURS),
            aADAOS,
            aFURN,
            V_REC_R.CODLOCATIE,
            aDATANIR,
            V_REC_I.TIPSERIE,
            V_REC_I.ROTUNJIRE,
            V_REC_I.ROTUNJIRE,
            V_REC_R.TG
          );
          IF NVL(V_REC_R.CODSERIE, 0) &lt;&gt; 0 THEN
            INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, TG)
            VALUES (SEQ_NIRSER_CODNIRSER.NEXTVAL, aCODNIRSTOC,V_REC_R.CODSERIE, V_REC_R.CANT, V_REC_R.TG);
          END IF;

            aCANTFURN := aCANTFURN - V_REC_R.CANT;
        END LOOP;


    ELSE
      FOR V_REC_R IN (SELECT * FROM TMP_RECEPTIEWMS WHERE CODINTR1 = V_REC_I.CODINTR1)
      LOOP
        I := I + 1;
        IF I = NR THEN MANCANTFURN := aCANTFURN; ELSE MANCANTFURN := V_REC_R.CANT; END IF;
        aCODNIRSTOC := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;

        INSERT INTO NIRSTOC(CODNIRSTOC,
                            CODNIR,
                            CODINTR1,
                            CANTNIR,
                            CANTFURN,
                            UMSEC,
                            CODOBIECT,
                            CODIOART,
                            PRET,
                            ADAOS,
                            FURN,
                            CODLOCATIE,
                            DATAACHIZ,
                            TIPSERIE,
                            ROTLEI,
                            ROTVALUTA,
                            TG
                            )
       VALUES
         (aCODNIRSTOC,
          aCODNIR,
          V_REC_I.CODINTR1,
          V_REC_R.CANT,
          MANCANTFURN,
          V_REC_I.UMSEC,
          V_REC_I.CODOBIECT,
          aCODIOART,
          PKG_PRETURI.WMROTOPRET(NVL(V_REC_I.ROTUNJIRE,0),  V_REC_I.PU * V_REC_I.CURS),
          aADAOS,
          aFURN,
          V_REC_R.CODLOCATIE,
          aDATANIR,
          V_REC_I.TIPSERIE,
          V_REC_I.ROTUNJIRE,
          V_REC_I.ROTUNJIRE,
          V_REC_R.TG
        );

        IF NVL(V_REC_R.CODSERIE, 0) &lt;&gt; 0 THEN
          INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, TG, DATAPROD)
          VALUES (SEQ_NIRSER_CODNIRSER.NEXTVAL, aCODNIRSTOC,V_REC_R.CODSERIE, V_REC_R.CANT, V_REC_R.TG, V_REC_R.DATAPROD);
        END IF;



          aCANTFURN := aCANTFURN - V_REC_R.CANT;
      END LOOP;
    END IF;
  END LOOP;
END;

PROCEDURE MEMO_CANTNIR_OPERAT_INTRARI (aCODINTR1 IN NUMBER, 
                                       aCANT IN NUMBER, 
                                       aCODLOCATIE IN NUMBER, 
                                       aCODSERIE IN NUMBER, 
                                       aCODGEST IN NUMBER, 
                                       aTG IN VARCHAR2, 
                                       aDATAPROD IN VARCHAR2, 
                                       CODUSER IN NUMBER, 
                                       aNEWCODGEST IN NUMBER,
                                       aOBSSERIE IN VARCHAR2,
                                       aNEWCODLOCATIE IN NUMBER)
IS
BEGIN
  INSERT INTO TMP_RECEPTIEWMS(CODINTR1,
                              CANT, 
                              CODLOCATIE,
                              CODSERIE,
                              CODGEST,
                              TG,
                              DATAPROD,
                              USERID,
                              NEWCODGEST,
                              OBSSERIE,
                              NEWCODLOCATIE)
                     VALUES (aCODINTR1,
                             aCANT,
                             aCODLOCATIE,
                             aCODSERIE,
                             aCODGEST,
                             CASE
                               WHEN aTG IS NOT NULL THEN TO_DATE(aTG, &apos;dd.mm.yyyy&apos;)
                               ELSE NULL
                             END,
                             CASE
                               WHEN aDATAPROD IS NOT NULL THEN TO_DATE(aDATAPROD, &apos;dd.mm.yyyy&apos;)
                               ELSE NULL
                             END,
                             CODUSER,
                             aNEWCODGEST,
                             aOBSSERIE,
                             aNewCodLocatie
                             );
END;

PROCEDURE MEMO_FAPTIC_INVENTAR (aCODINVENTAR1 IN NUMBER, aCANT IN NUMBER, aCODLOCATIE IN NUMBER, aCODOBIECT IN NUMBER, aTIPSERIE IN NUMBER, aCODSERIE IN NUMBER)
IS
BEGIN
  INSERT INTO TMP_RECEPTIEWMS(CODINTR1, CANT, CODLOCATIE, CODOBIECT, TIPSERIE, CODSERIE) VALUES (aCODINVENTAR1, aCANT, aCODLOCATIE, aCODOBIECT, aTIPSERIE, aCODSERIE);
END;



PROCEDURE SET_FAPTIC_INVENTAR(aCODINVENTAR IN NUMBER)
IS
aCODUM1 NUMBER(20) := 0;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_RECEPTIEWMS)
  LOOP
    IF V_REC.CODINTR1 &gt; 0 THEN
      UPDATE INVENTAR1
      SET
        FAPTIC   = V_REC.CANT,
        CODSERIE = V_REC.CODSERIE,
        TIPSERIE = V_REC.TIPSERIE
      WHERE
        CODINVENTAR1 = V_REC.CODINTR1;
    ELSE

       BEGIN
          SELECT
            CODUM1 INTO aCODUM1
          FROM
            NARTOBJ O,
            NART A,
            NUM1 U1
          WHERE
            O.CODOBIECT = V_REC.CODOBIECT
            AND A.CODARTICOL = O.CODARTICOL
            AND U1.CODUM = A.UM
            AND SECUNDARA = 0;
          EXCEPTION WHEN OTHERS THEN aCODUM1 := 0;
       END;

       INSERT INTO INVENTAR1(CODINVENTAR1, CODINVENTAR, CODLOCATIE, CODOBIECT, SCRIPTIC, FAPTIC, UM1, TIPSERIE, CODSERIE)
       VALUES (V_REC.CODINTR1,aCODINVENTAR, V_REC.CODLOCATIE, V_REC.CODOBIECT, 0, V_REC.CANT, aCODUM1, V_REC.TIPSERIE, V_REC.CODSERIE);
    END IF;
  END LOOP;

END;

PROCEDURE SOLVE_TEXT_PROMO
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NCASEMARCAT)
  LOOP
     UPDATE NCASEMARCAT
     SET
       TEXTPROMO = V_REC.TEXTPROMO
     WHERE
       CODCASEMARCAT = V_REC.CODCASEMARCAT;
  END LOOP;
  COMMIT;
END;



FUNCTION GETCODSERIEINTR1(aCODINTR1 IN NUMBER, aSERIE VARCHAR2) RETURN NUMBER
IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  RES        NUMBER(20) := 0;
  aCODOBIECT NUMBER(20) := 0;
BEGIN
  IF aCODINTR1  &lt;&gt; 0 THEN
    BEGIN
      SELECT CODOBIECT INTO aCODOBIECT FROM INTRARI1 WHERE CODINTR1 = aCODINTR1;
      EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
    END;
    IF aCODOBIECT &lt;&gt; 0 THEN

      BEGIN
        SELECT CODSERIE INTO RES FROM NSERII WHERE SERIE = aSERIE AND CODOBIECT = aCODOBIECT;
        EXCEPTION WHEN OTHERS THEN RES := 0;
      END;
      IF RES = 0 THEN
        RES := SEQ_NSERII_CODSERIE.NEXTVAL;
        INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT)
        VALUES (RES,aSERIE, aCODOBIECT);
      END IF;
    END IF ;
  END IF;
  COMMIT;
  RETURN RES;
END;

FUNCTION GETCODSERIEINVENTAR1(aCODINVENTAR1 IN NUMBER, aSERIE VARCHAR2) RETURN NUMBER
IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  RES        NUMBER(20) := 0;
  aCODOBIECT NUMBER(20) := 0;
BEGIN
  IF aCODINVENTAR1  &lt;&gt; 0 THEN
    BEGIN
      SELECT CODOBIECT INTO aCODOBIECT FROM INVENTAR1 WHERE CODINVENTAR1 = aCODINVENTAR1;
      EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
    END;
    IF aCODOBIECT &lt;&gt; 0 THEN

      BEGIN
        SELECT CODSERIE INTO RES FROM NSERII WHERE SERIE = aSERIE AND CODOBIECT = aCODOBIECT;
        EXCEPTION WHEN OTHERS THEN RES := 0;
      END;
      IF RES = 0 THEN
        RES := SEQ_NSERII_CODSERIE.NEXTVAL;
        INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT)
        VALUES (RES,aSERIE, aCODOBIECT);
      END IF;
    END IF ;
  END IF;
  COMMIT;
  RETURN RES;
END;


PROCEDURE SETLOCATIEIMPLICITA(aCODART IN NUMBER, aCODLOCATIE IN NUMBER)
IS
  aCODIMPLICIT NUMBER(20);
  aCODGEST     NUMBER(20);
BEGIN
  BEGIN
    SELECT CODIMPLICIT INTO aCODIMPLICIT FROM NARTIMPLICITE WHERE CODSUBUNIT = PKG_GLOBALS.SUBUNITATE AND CODARTICOL = aCODART;
    EXCEPTION WHEN OTHERS THEN  aCODIMPLICIT := 0;
  END;


  BEGIN
    SELECT NVL(CODGEST, 0) INTO aCODGEST FROM NLOCATII WHERE CODLOCATIE = aCODLOCATIE;
    EXCEPTION WHEN OTHERS THEN aCODGEST := 0;
  END;

  IF aCODIMPLICIT = 0 THEN
     INSERT INTO NARTIMPLICITE(CODIMPLICIT, CODARTICOL, CODSUBUNIT, LOCATIEIMPLICITA, GESTIMPLICITA)
     VALUES (aCODIMPLICIT, aCODART, PKG_GLOBALS.SUBUNITATE, aCODLOCATIE, aCODGEST);
  ELSE
    UPDATE NARTIMPLICITE
    SET
      LOCATIEIMPLICITA = aCODLOCATIE,
      GESTIMPLICITA    = aCODGEST
    WHERE
      CODIMPLICIT = aCODIMPLICIT;
  END IF;
  COMMIT;
END;

PROCEDURE UPDATE_STOC_INTRARE(aCODINTR IN NUMBER)
IS
BEGIN
  FOR V_REC  IN
    (SELECT NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR, NS.CANTUM1, NS.CANTUM2
     FROM
       NIRSTOC NS, NIR N
     WHERE
       N.CODINTR = aCODINTR AND NS.CODNIR = N.CODNIR
      )
  LOOP
    UPDATE NIRSTOC
    SET
      REST    = PKG_INTRARI.GET_REST_STOC(V_REC.CodNIR, V_REC.CodNirStoc , V_REC.CantNIR),
      RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CodNir, V_REC.CodNirStoc, V_REC.CantUM1),
      RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CodNir, V_REC.CodNirStoc, V_REC.CantUM2)
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  FOR V_REC  IN
    (SELECT NS.CODNIR, NSE.CODNIRSER, NSE.CANTNIR, NSE.CANTUM1, NSE.CANTUM2
     FROM
       NIRSER NSE,
       NIRSTOC NS,
       NIR N
     WHERE
       N.CODINTR = aCODINTR AND NS.CODNIR = N.CODNIR
       AND NSE.CODNIRSTOC = NS.CODNIRSTOC
      )
  LOOP
    UPDATE NIRSER
    SET
      REST    = PKG_INTRARI.GET_REST_STOC_SERIE    (V_REC.CodNIR, V_REC.CodNirSer, V_REC.CantNIR),
      RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1(V_REC.CodNir, V_REC.CodNirSer, V_REC.CantUM1),
      RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2(V_REC.CodNir, V_REC.CodNirSer, V_REC.CantUM2)
    WHERE
      CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

  FOR V_REC IN (SELECT CODINTR1, CANT FROM INTRARI1 WHERE CODINTR = aCODINTR)
  LOOP
    UPDATE INTRLINK SET CANT = V_REC.CANT WHERE CODINTR1 = V_REC.CODINTR1;
  END LOOP;

  FOR V_REC IN (SELECT IL.CODLINIECOMANDA FROM INTRARI1 I1, INTRLINK IL WHERE I1.CODINTR = aCODINTR AND IL.CODINTR1 = I1.CODINTR1)
  LOOP

    UPDATE COMANDA1 c1
    SET
     c1.RestAcceptat = c1.CantAcceptat -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
    c1.CodComanda1 = V_REC.CODLINIECOMANDA;

  END LOOP;
END;


PROCEDURE SOLVE_CARNETE_RETAIL
IS
BEGIN
  MERGE INTO DOCCARNETE CD
  USING TMP_DOCCARNETE TCD
  ON (TCD.CODCARNET = CD.CODCARNET)
  WHEN NOT MATCHED THEN
  INSERT (CODCARNET, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA, STARTNRINI, DEDICAT, COMENZIONLINE, CODPOSTRETAIL)
  VALUES (TCD.CODCARNET, TCD.SIMBOL, TCD.DENUMIRE, TCD.SERIE, TCD.STARTNR, TCD.ENDNR, TCD.FREENR, TCD.INACTIV, TCD.SUBUNITATEA, TCD.LIMITA, TCD.STARTNRINI, TCD.DEDICAT, TCD.COMENZIONLINE, TCD.CODPOSTRETAIL)
  WHEN MATCHED THEN
  UPDATE
  SET
    SIMBOL        = TCD.SIMBOL,
    DENUMIRE      = TCD.DENUMIRE,
    SERIE         = TCD.SERIE,
    STARTNR       = TCD.STARTNR,
    ENDNR         = TCD.ENDNR,
    FREENR        = TCD.FREENR,
    INACTIV       = TCD.INACTIV,
    CODPOSTRETAIL = TCD.CODPOSTRETAIL,
    SUBUNITATEA  = TCD.SUBUNITATEA
  WHERE
    CODCARNET = TCD.CODCARNET;

  MERGE INTO DOCLINK L
  USING TMP_DOCLINK  TL
  ON (L.CODDOCLINK = TL.CODDOCLINK)
  WHEN NOT MATCHED THEN
  INSERT (CODDOCLINK, CODCARNET, CODMACHETA)
  VALUES (TL.CODDOCLINK, TL.CODCARNET, TL.CODMACHETA);


  DELETE DOCFREE F
  WHERE
    CODCARNET IN (SELECT CODCARNET FROM TMP_DOCCARNETE);

  DELETE FROM DOCLOCK WHERE USERID IS NULL;


  INSERT INTO DOCFREE (CODDOCFREE, CODCARNET, STARTNR, ENDNR)
  SELECT SEQ_DOCFREE_CODDOCFREE.NEXTVAL,DC.CODCARNET, DC.STARTNR, DC.ENDNR
  FROM
    TMP_DOCCARNETE DC;


 -- PKG_CARNETEDOC.PARCURGESIREFADOC(&apos;IESIRIRETAIL&apos;,  &apos;CARNETDOC&apos;,    &apos;NRDOC&apos;   );
  FOR V_REC IN (SELECT * FROM TMP_DOCCARNETE) LOOP
    PKG_CARNETEDOC.REFACERECARNET(V_REC.CODCARNET);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CODCARNET);
    UPDATE DOCCARNETE SET FREENR = PKG_CARNETEDOC.COUNTFREENR(V_REC.CODCARNET) WHERE CODCARNET = V_REC.CODCARNET;
  END LOOP;



  COMMIT;

END;

PROCEDURE PROCESEAZA_DL_WMS
IS
  aCANT         NUMBER(20, 7);
  aCANTPREL     NUMBER(20, 7);
  aCANTACCEPTAT NUMBER(20, 7);
  aCOD          NUMBER(20) := 0;
  TRANSFERURI   NUMBER(1) := 0;
  aCODTRANSF    NUMBER(20);
  aCODLIVR      NUMBER(20);
  aCODLIVR1     NUMBER(20);
  aCODNIR       NUMBER(20);
  aCODTRANSF1   NUMBER(20);
  aINDEXLOCAL   NUMBER(5) := 0;
  aNRDOC        NUMBER(20);
  aSERIEDOC     VARCHAR2(10);
  aSIMBOLDOC    VARCHAR2(10);
BEGIN

  DELETE TMP_PROCESARE_DLWMS;
  FOR V_REC_DLWMS IN (SELECT * FROM TMP_DISPLIVRARE_WMS)
  LOOP
     FOR V_REC_DLWMS1 IN (SELECT * FROM TMP_DISPLIVRARE_WMS1 WHERE CODDLWMS = V_REC_DLWMS.CODDLWMS)
     LOOP
       aCANT := V_REC_DLWMS1.CANT;
       FOR V_REC_REZ IN
       (
          SELECT
            C1.CODCOMANDA1,
            R.CODREZERVATS,
            NVL(NS.CODLOCATIE, 0) AS OLDCODLOCATIE,
            R.CODNIRSTOC,
            R.CODNIRSER,
            SER.CODSERIE,
            SER.SERIE,
            R.REST
          FROM
            COMANDA1 C1,
            REZERVATS R
            LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = R.CODNIRSER
            LEFT JOIN NSERII SER ON NSE.CODSERIE = SER.CODSERIE,
            NIRSTOC NS,
            NIR N
          WHERE
            C1.CODCOMANDA1 = V_REC_DLWMS.CODCOMANDA1
            AND N.GEST        = V_REC_DLWMS.CODGEST
            AND NVL(SER.SERIE, &apos; &apos;) = NVL(V_REC_DLWMS.SERIE, &apos; &apos;)
            AND R.CODCOMANDA1 = C1.CODCOMANDA1
            AND NS.CODNIRSTOC = R.CODNIRSTOC
            AND NS.CODNIR     = N.CODNIR
        )
        LOOP
           IF aCANT &gt; 0 AND V_REC_REZ.REST &gt; 0 THEN
             IF aCANT &gt;= V_REC_REZ.REST THEN
                aCANTPREL := V_REC_REZ.REST;
             ELSE
                aCANTPREL := aCANT;
             END IF;
             aCANT := aCANT - aCANTPREL;

             UPDATE REZERVATS
             SET
               REST = REST - aCANTPREL
             WHERE
               CODREZERVATS = V_REC_REZ.CODREZERVATS;
             aCOD := aCOD + 1;
             INSERT INTO TMP_PROCESARE_DLWMS(COD,
                                             CODREZERVATS,
                                             CANT,
                                             OLDCODNIRSTOC,
                                             OLDCODNIRSER,
                                             OLDCODLOCATIE,
                                             NEWCODLOCATIE)
             VALUES
               (aCOD,
                V_REC_REZ.CODREZERVATS,
                aCANTPREL,
                V_REC_REZ.CODNIRSTOC,
                V_REC_REZ.CODNIRSER,
                V_REC_REZ.OLDCODLOCATIE,
                NVL(V_REC_DLWMS1.CODLOCATIENOUA, 0)
               );

           END IF;

        END LOOP;
     END LOOP;
  END LOOP;


-- PUN PE ZERO REZERVARILE PRELUCRATE PENTRU A PUNE APOI CONSTATARILE
--
  FOR V_REC_DLWMS IN (SELECT * FROM TMP_DISPLIVRARE_WMS)
  LOOP
       FOR V_REC_REZ IN
       (
          SELECT
            R.CODREZERVATS
          FROM
            COMANDA1 C1,
            REZERVATS R
            LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = R.CODNIRSER
            LEFT JOIN NSERII SER ON NSE.CODSERIE = SER.CODSERIE,
            NIRSTOC NS,
            NIR N
          WHERE
            C1.CODCOMANDA1 = V_REC_DLWMS.CODCOMANDA1
            AND N.GEST        = V_REC_DLWMS.CODGEST
            AND NVL(SER.SERIE, &apos; &apos;) = NVL(V_REC_DLWMS.SERIE, &apos; &apos;)
            AND R.CODCOMANDA1 = C1.CODCOMANDA1
            AND NS.CODNIRSTOC = R.CODNIRSTOC
            AND NS.CODNIR     = N.CODNIR
        )
        LOOP
             UPDATE REZERVATS
             SET
               REST = 0
             WHERE
               CODREZERVATS = V_REC_REZ.CODREZERVATS;

        END LOOP;
  END LOOP;

--

  -- PUN CONSTATARILE
  FOR V_REC IN (SELECT * FROM TMP_PROCESARE_DLWMS)
  LOOP
    IF NVL(V_REC.NEWCODLOCATIE, 0) = 0 THEN
      UPDATE REZERVATS
      SET
        REST = NVL(REST, 0) + V_REC.CANT
      WHERE
        CODREZERVATS = V_REC.CODREZERVATS;
    ELSE -- AICI PREGATESC TANSFER IN ALTE LOCATII
       TRANSFERURI := 1;
       UPDATE TMP_PROCESARE_DLWMS
       SET
         NEWCODNIRSTOC = SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL
       WHERE
         COD = V_REC.COD;

        IF NVL(V_REC.OLDCODNIRSER, 0) &lt;&gt; 0 THEN
        UPDATE TMP_PROCESARE_DLWMS
        SET
          NEWCODNIRSER = SEQ_NIRSER_CODNIRSER.NEXTVAL
        WHERE
          COD = V_REC.COD;

        END IF;
    END IF;
  END LOOP;


  IF TRANSFERURI = 1 THEN
     aCODTRANSF := SEQ_TRANSF_CODTRANSF.NEXTVAL;
     aCODLIVR   := SEQ_LIVR_CODLIVR.NEXTVAL;
     aNRDOC     := NULL; aSERIEDOC := NULL;
     IF NVL(CARNETIMPLICIT_NT, 0) &lt;&gt; 0 THEN
       aNRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(CARNETIMPLICIT_NT, aSERIEDOC, aSIMBOLDOC);
     END IF;


     INSERT INTO TRANSF(CODTRANSF,
                        TIPDOC,
                        ANULAT,
                        BLOCAT,
                        OPERAT,
                        PREFIXDOC,
                        CARNETDOC,
                        NRDOC,
                        DATADOC,
                        AN,
                        LUNA,
                        SUBUNITATEA,
                        USERID,
                        DATACREARE,
                        SERIADOC)
                       VALUES
                       ( aCODTRANSF,
                         12,
                         0,
                         0,
                         1,
                         &apos;NT&apos;,
                         CASE WHEN NVL(CARNETIMPLICIT_NT, 0) = 0 THEN NULL
                              ELSE CARNETIMPLICIT_NT
                         END,
                         aNRDOC,
                         TO_DATE(TO_CHAR(SYSDATE,&apos;DD.MM.YYYY&apos;), &apos;DD.MM.YYYY&apos;),
                         PKG_GLOBALS.GetANLUCRU,
                         PKG_GLOBALS.GetLUNALUCRU,
                         PKG_GLOBALS.GETSUBUNITATE,
                         PKG_GLOBALS.USERID,
                         SYSDATE,
                         aSERIEDOC
                       );

      IF NVL(CARNETIMPLICIT_NT, 0) &lt;&gt; 0 AND NVL(aNRDOC, 0) &lt;&gt; 0 THEN
         PKG_CARNETEDOC.SOLVENUMARDOC(CARNETIMPLICIT_NT, aNRDOC);
      END IF;


    INSERT INTO LIVR(CODLIVR,
                     CODTRANSF,
                     DATALIVR,
                     TIPLIVR,
                     ANULAT,
                     BLOCAT,
                     OPERAT
                     )
             VALUES (aCODLIVR,
                     aCODTRANSF,
                     TO_DATE(TO_CHAR(SYSDATE,&apos;DD.MM.YYYY&apos;), &apos;DD.MM.YYYY&apos;),
                     12,
                     0,
                     0,
                     1);
    FOR V_REC IN
    (SELECT P.*,
            R.CODCOMANDA1,
            N.GEST,
            NS.CODOBIECT,
            NS.PRET,
            NS.UMSEC,
            NS.CODIOART,
            NS.ADAOS,
            NS.TVA,
            NS.TIPSERIE,
            NS.ROTLEI,
            NS.ROTVALUTA,
            NS.TG,
            NS.FURN,
            NS.DATAACHIZ,
            NS.TIPDOCACHIZ,
            NS.CODGESTPROD,
            NS.D1,
            NS.D2,
            NS.D3,
            NS.PUVAL,
            NS.PROVIZION,
            NS.SERIELOT,
            NSE.CODSERIE
     FROM
       TMP_PROCESARE_DLWMS P,
       REZERVATS R
       LEFT JOIN NIRSER NSE ON R.CODNIRSER = NSE.CODNIRSER,
       NIRSTOC NS,
       NIR N
      WHERE
        NVL(P.NEWCODNIRSTOC, 0) &lt;&gt; 0
        AND P.CODREZERVATS = R.CODREZERVATS
        AND NS.CODNIRSTOC = R.CODNIRSTOC
        AND N.CODNIR = NS.CODNIR
     )
     LOOP
       BEGIN
         SELECT CODNIR INTO aCODNIR FROM NIR
         WHERE
           CODTRANSF = aCODTRANSF AND GEST = V_REC.GEST;
         EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
       END;
       IF aCODNIR = 0 THEN
         aCODNIR := SEQ_NIR_CODNIR.NEXTVAL;
         INSERT INTO NIR(CODNIR,
                         CODTRANSF,
                         DATANIR,
                         GEST,
                         TIPNIR,
                         ANULAT,
                         BLOCAT,
                         OPERAT,
                         USERID,
                         DATACREARE)
                  VALUES(aCODNIR,
                         aCODTRANSF,
--                         SYSDATE,
                         TO_DATE(TO_CHAR(SYSDATE,&apos;DD.MM.YYYY&apos;), &apos;DD.MM.YYYY&apos;),
                         V_REC.GEST,
                         12,
                         0,
                         0,
                         1,
                         PKG_GLOBALS.USERID,
                         SYSDATE
                         );

       END IF;
       aCODTRANSF1 := SEQ_TRANSF1_CODTRANSF1.NEXTVAL;
       aINDEXLOCAL := aINDEXLOCAL + 1;
       aCODLIVR1   := SEQ_LIVR1_CODLIVR1.NEXTVAL;

       INSERT INTO TRANSF1(CODTRANSF1,
                           CODTRANSF,
                           INDEXLOCAL,
                           TIPLINIE,
                           UMSEC,
                           CODOBIECT,
                           PU,
                           CANT
                           )
                    VALUES(aCODTRANSF1,
                           aCODTRANSF,
                           aINDEXLOCAL,
                           &apos;=&apos;,
                           V_REC.UMSEC,
                           V_REC.CODOBIECT,
                           V_REC.PRET,
                           V_REC.CANT
                           );

        INSERT INTO LIVR1(CODLIVR1,
                          CODLIVR,
                          CODIES1,
                          CODNIRSTOC,
                          CANT,
                          CODNIRSER,
                          UMSEC)
                    VALUES(aCODLIVR1,
                           aCODLIVR,
                           aCODTRANSF1,
                           V_REC.OLDCODNIRSTOC,
                           V_REC.CANT,
                           V_REC.OLDCODNIRSER,
                           V_REC.UMSEC
                           );

       INSERT INTO NIRSTOC(CODNIRSTOC,
                           CODNIR,
                           CODTRANSF1,
                           CODNIRSTOCPARINTE,
                           CANTNIR,
                           UMSEC,
                           CODOBIECT,
                           CODIOART,
                           PRET,
                           ADAOS,
                           TVA,
                           TIPSERIE,
                           CODLIVR1,
                           REST,
                           CANTFURN,
                           ROTLEI,
                           ROTVALUTA,
                           CODLOCATIE,
                           TG,
                           FURN,
                           DATAACHIZ,
                           TIPDOCACHIZ,
                           CODGESTPROD,
                           D1,
                           D2,
                           D3,
                           PUVAL,
                           PROVIZION,
                           SERIELOT)
                    VALUES(V_REC.NEWCODNIRSTOC,
                           aCODNIR,
                           aCODTRANSF1,
                           V_REC.OLDCODNIRSTOC,
                           V_REC.CANT,
                           V_REC.UMSEC,
                           V_REC.CODOBIECT,
                           V_REC.CODIOART,
                           V_REC.PRET,
                           V_REC.ADAOS,
                           V_REC.TVA,
                           V_REC.TIPSERIE,
                           aCODLIVR1,
                           V_REC.CANT,
                           V_REC.CANT,
                           V_REC.ROTLEI,
                           V_REC.ROTVALUTA,
                           V_REC.NEWCODLOCATIE,
                           V_REC.TG,
                           V_REC.FURN,
                           V_REC.DATAACHIZ,
                           V_REC.TIPDOCACHIZ,
                           V_REC.CODGESTPROD,
                           V_REC.D1,
                           V_REC.D2,
                           V_REC.D3,
                           V_REC.PUVAL,
                           V_REC.PROVIZION,
                           V_REC.SERIELOT);

        UPDATE NIRSTOC
        SET
          REST = REST - V_REC.CANT
        WHERE
          CODNIRSTOC = V_REC.OLDCODNIRSTOC;


        IF NVL(V_REC.NEWCODNIRSER, 0) &lt;&gt; 0 THEN
          INSERT INTO NIRSER( CODNIRSER,
                              CODNIRSTOC,
                              CODSERIE,
                              CANTNIR,
                              REST,
                              TG
                             )
                      VALUES (V_REC.NEWCODNIRSER,
                              V_REC.NEWCODNIRSTOC,
                              V_REC.CODSERIE,
                              V_REC.CANT,
                              V_REC.CANT,
                              V_REC.TG);

          UPDATE NIRSER
          SET
            REST = REST - V_REC.CANT
          WHERE
            CODNIRSER = V_REC.OLDCODNIRSER;


        END IF;

        INSERT INTO REZERVATS(CODREZERVATS,
                              CODCOMANDA1,
                              CODNIRSTOC,
                              CODNIRSER,
                              REST,
                              UMSEC,
                              CODOBIECT)
                     VALUES(SEQ_REZERVATS_CODREZERVATS.NEXTVAL,
                            V_REC.CODCOMANDA1,
                            NVL(V_REC.NEWCODNIRSTOC,0),
                            NVL(V_REC.NEWCODNIRSER,0),
                            V_REC.CANT,
                            V_REC.UMSEC,
                            V_REC.CODOBIECT);


     END LOOP;

  END IF;



  -- RECALCULEZ ACCEPTAT PE DISPLIVRARE
  FOR V_REC IN (SELECt CODCOMANDA1 FROM TMP_DISPLIVRARE_WMS)
  LOOP
    SELECT NVL(SUM(REST), 0) INTO aCANTACCEPTAT FROM REZERVATS WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;

    UPDATE COMANDA1
    SET
      CANTACCEPTAT = aCANTACCEPTAT,
      RESTACCEPTAT = aCANTACCEPTAT
    WHERE
      CODCOMANDA1 = V_REC.CODCOMANDA1;



    FOR V_REC_LINK IN (SELECT * FROM CMDLIVRLINK WHERE CODCOMANDA1 = V_REC.CODCOMANDA1)
    LOOP
      UPDATE CMDLIVRLINK
      SET
        CANT = aCANTACCEPTAT
      WHERE
        CODCOMANDA1 = V_REC.CODCOMANDA1;

      DELETE FROM REZERVATS WHERE REST = 0 AND  CODCOMANDA1 = V_REC.CODCOMANDA1;

        UPDATE COMANDA1 C1 -- refac restul pe comanda initiala
        SET
        C1.RESTACCEPTAT = C1.Cantacceptat -
                   ( SELECT NVL(SUM(CL.CANT), 0)
                     FROM
                       CMDLIVRLINK CL
                       LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = CL.CODCOMANDA1
                       LEFT OUTER JOIN COMANDA CC ON CC1.CODCOMANDA = CC.CODCOMANDA
                     WHERE
                     CL.CODLINIECOMANDA = C1.CODCOMANDA1
                     AND CC.OPERAT = 1 AND CC.ANULAT = 0
                    ) -
                   (SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                      IESLINK IL
                      LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                      LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                    WHERE
                      IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                    ) -
                   (SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                      INTRLINK IL
                      LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                      LEFT OUTER JOIN INTRARI   I ON I.CODINTR  = I1.CODINTR
                    WHERE
                      IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                    )
           WHERE
             CODCOMANDA1 = V_REC_LINK.CODLINIECOMANDA;

    END LOOP;

  END LOOP;

  FOR V_REC IN (SELECT DISTINCT C1.CODCOMANDA, TMP.USERID
                FROM 
                  TMP_DISPLIVRARE_WMS TMP
                  INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = TMP.CODCOMANDA1
                WHERE
                  COALESCE(USERID, 0) &lt;&gt; 0
                )
  LOOP
    INSERT INTO MODIFICARI(CODMODIFICARE, CODMASTER, TABLENAME, DATAMODIF, USERMODIF, TIPMODIF)
                VALUES(SEQ_MODIFICARI_CODMODIFICARE.NEXTVAL, V_REC.CODCOMANDA, &apos;COMANDA&apos;, SYSDATE, V_REC.USERID, 5);
  END LOOP;                    
                  


END;


FUNCTION CONDITIE_LINK_NS(NS_CODINTR1 IN NUMBER, NS_CODDVI1 IN NUMBER,  aCODINTR1 IN NUMBER, aCODDVI1 IN NUMBER) RETURN NUMBER
IS
  RES NUMBER(1);
BEGIN
  RES := 0;
  IF aCODDVI1 &lt;&gt; 0 THEN
    IF NS_CODDVI1 = aCODDVI1 THEN RES := 1; END IF;
  ELSE
    IF NS_CODINTR1 = aCODINTR1 THEN RES := 1; END IF;
  END IF;

  RETURN RES;
END;



PROCEDURE UPDATE_PRET_NART(aCODOBIECT IN NUMBER, aCODCATPRET IN NUMBER, aCODSUBUNIT IN NUMBER, PRET IN NUMBER)
IS
BEGIN
  UPDATE PRETM
  SET
    LEI = PRET
  WHERE
    CODOBIECT       = aCODOBIECT
    AND SUBUNITATEA = aCODSUBUNIT
    AND CODCATPRET  = aCODCATPRET  ;


  IF  sql%rowcount = 0 THEN
    INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, SUBUNITATEA)
    VALUES (SEQ_PRETM_CODPRETM.NEXTVAL, aCODOBIECT, aCODCATPRET, PRET, aCODSUBUNIT);
  END IF;
END;



PROCEDURE FINALIZARE_RECEPTII_PARTIALE(aCODINTR IN NUMBER)
IS
  aMAXNRNIR NUMBER(20);
  aCODNIR NUMBER(20);
  NEW_DATANIR DATE;
BEGIN
  FOR V_REC IN (SELECT N.*, I.AN, I.LUNA FROM NIR N INNER JOIN INTRARI I ON N.CODINTR = I.CODINTR WHERE N.CODINTR = aCODINTR AND N.OPERAT = 0)
  LOOP
    FOR V_REC_NS IN (SELECT * FROM NIRSTOC WHERE CANTNIR = 0 AND CANTFURN = 0 AND CODNIR = V_REC.CODNIR)
    LOOP  
      --DELETE FROM NIRSTOC WHERE CANTNIR = 0 AND CANTFURN = 0 AND CODNIR = V_REC.CODNIR;
      DELETE FROM REZERVATS 
      WHERE 
        CODNIRSTOC = V_REC_NS.CODNIRSTOC;

      DELETE FROM NIRSTOC 
      WHERE 
        CODNIRSTOC = V_REC_NS.CODNIRSTOC;
    END LOOP;  

   -- DELETE FROM NIRSTOC WHERE CANTNIR = 0 AND CANTFURN = 0 AND CODNIR = V_REC.CODNIR;

    NEW_DATANIR := TRUNC(SYSDATE);
    -- data nirului trebuie sa apartina lunii din intrari
    IF LAST_DAY(NEW_DATANIR) &gt; LAST_DAY(TO_DATE(&apos;01.&apos; || V_REC.LUNA || &apos;.&apos; || V_REC.AN, &apos;dd.mm.yyyy&apos;))
    THEN
      NEW_DATANIR := LAST_DAY(TO_DATE(&apos;01.&apos; || V_REC.LUNA || &apos;.&apos; || V_REC.AN, &apos;dd.mm.yyyy&apos;));
    END IF;    



    UPDATE NIRSTOC
    SET
      CANTNIR = 0,
      DATAACHIZ = NEW_DATANIR
    WHERE
      CODNIR = V_REC.CODNIR;

    UPDATE NIR
    SET
      DATANIR = NEW_DATANIR,
      OPERAT = 1
    WHERE
      CODNIR = V_REC.CODNIR;
  END LOOP;
/*
  DELETE FROM NIR N
  WHERE
   CODINTR = aCODINTR
   AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0;
*/
 FOR V_REC IN (SELECT * FROM NIR N
               WHERE
                 CODINTR = aCODINTR
                 AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0
              )
 LOOP
   SELECT NVL(MAX(NRNIR), 0) INTO aMAXNRNIR FROM NIR N
   WHERE
      CODINTR = aCODINTR
      AND CARNETNIR = V_REC.CARNETNIR
      AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) &gt; 0;

    IF aMAXNRNIR &lt;&gt; 0 THEN
      BEGIN
        SELECT CODNIR INTO aCODNIR FROM NIR
        WHERE
          NRNIR = aMAXNRNIR
          AND CODINTR = aCODINTR
          AND CARNETNIR = V_REC.CARNETNIR;
        EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
      END;
      IF aCODNIR &lt;&gt; 0 THEN
          PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, aMAXNRNIR);
          PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
          UPDATE NIR
          SET
            NRNIR = V_REC.NRNIR
          WHERE
            CODNIR = aCODNIR;

      END IF;
    ELSE
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);

    END IF;
    DELETE FROM NIR WHERE CODNIR = V_REC.CODNIR;
 END LOOP;

END;


PROCEDURE GRUPEAZA_LINII_CU_SERII
IS
  MINCODNIRSTOC NUMBER;
BEGIN
  FOR V_REC IN ( 
    select 
      ns.codintr1, 
      ns.codnir,
      COALESCE(ns.tg, to_date(&apos;01.01.2000&apos;, &apos;dd,mm.yyyy&apos;) ) AS TG,
      COALESCE(ns.codlocatie,0) CODLOCATIE,
      count(*) AS NR
    from 
      tmp_nirstoc tns 
      inner join nirstoc ns on ns.codnirstoc = tns.codnirstoc
      inner join nir n on n.codnir = ns.codnir and n.operat = 1
    group by 
      ns.codintr1,
      ns.codnir,
      ns.tg,
      ns.codlocatie
    HAVING COUNT(*) &gt; 1
  )
  LOOP

    select 
      MIN(NS.CODNIRSTOC) INTO MINCODNIRSTOC 
    from 
      nirstoc ns
    WHERE
      CODINTR1   = V_REC.CODINTR1
      AND CODNIR = V_REC.CODNIR
      AND  COALESCE(tg, to_date(&apos;01.01.2000&apos;, &apos;dd,mm.yyyy&apos;)) =  V_REC.TG
      AND COALESCE(CODLOCATIE, 0) = V_REC.CODLOCATIE;

    
    FOR V_REC_NS IN 
     (SELECT NS.* 
     FROM 
       TMP_NIRSTOC TNS
       INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = TNS.CODNIRSTOC
     WHERE  
       NS.CODINTR1   = V_REC.CODINTR1
       AND NS.CODNIR = V_REC.CODNIR
       AND  COALESCE(NS.TG, to_date(&apos;01.01.2000&apos;, &apos;dd,mm.yyyy&apos;)) =  V_REC.TG
       AND COALESCE(NS.CODLOCATIE, 0) = V_REC.CODLOCATIE
       AND NS.CODNIRSTOC &gt; MINCODNIRSTOC
     )
     LOOP
       UPDATE NIRSTOC
       SET
         CANTNIR  = COALESCE(CANTNIR, 0) + COALESCE(V_REC_NS.CANTNIR, 0),
         REST     = COALESCE(REST, 0) + COALESCE(V_REC_NS.REST, 0),
         CANTFURN = COALESCE(CANTFURN, 0) + COALESCE(V_REC_NS.CANTFURN,0),
         CANTUM1  = COALESCE(CANTUM1, 0) + COALESCE(V_REC_NS.CANTUM1, 0)
       WHERE
         CODNIRSTOC = MINCODNIRSTOC;
         
       UPDATE NIRSER SET CODNIRSTOC = MINCODNIRSTOC WHERE CODNIRSTOC = V_REC_NS.CODNIRSTOC;
       DELETE FROM NIRSTOC  WHERE CODNIRSTOC = V_REC_NS.CODNIRSTOC;    
       DELETE FROM NIRSTOC1 WHERE CODNIRSTOC = V_REC_NS.CODNIRSTOC;    
     END LOOP;  
  END LOOP;  
END;    


PROCEDURE SET_RECEPTII_PARTIALE_INTRARI2
IS
  aCODNIR        NUMBER(20);
  aCARNETNIR     NUMBER(20);
  aNRDOC         NUMBER(20);
  aSERIEDOC      VARCHAR2(10);
  aSIMBOLDOC     VARCHAR2(10);
  aOBSSERIE      VARCHAR2(200);
  aDATANIR       DATE;
  MANCANT        NUMBER(20, 7);
  aCANTPREL      NUMBER(20, 7);
  RESTCANTFURN   NUMBER(20, 7);
  CANTFURNINSERT NUMBER(20, 7);
  NEW_DATANIR    DATE;
  aCODDVI1       NUMBER(20);
  aCODNIRSTOC    NUMBER(20);
  aCodNirSer     NUMBER(20);
  aCANTREZ       NUMBER(20,7);
BEGIN
  DELETE FROM TMP_NIRSTOC; -- manevra pentru grupare linii cu serii
  FOR V_REC IN (SELECT DISTINCT R.CODGEST, I.TIPDOC, I.CODINTR, I.AN, I.LUNA, R.NEWCODGEST
                FROM
                  TMP_RECEPTIEWMS R,
                  INTRARI1 I1,
                  INTRARI I
                WHERE
                  R.CODINTR1 = I1.CODINTR1
                  AND I.CODINTR = I1.CODINTR
               )
  LOOP
       aCODNIR   := SEQ_NIR_CODNIR.NEXTVAL;
       aNRDOC    := NULL;
       aSERIEDOC := NULL;

       BEGIN
         SELECT CARNETNIR, DATANIR INTO aCARNETNIR, aDATANIR 
         FROM 
           NIR 
         WHERE 
           GEST = V_REC.CODGEST 
           AND CODINTR = V_REC.CODINTR
           AND OPERAT = 0 
           AND ROWNUM = 1;
         EXCEPTION WHEN OTHERS THEN aCARNETNIR := 0; aDATANIR := NULL;
       END;

        IF NVL(aCARNETNIR, 0) &lt;&gt; 0 THEN
          aNRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(aCARNETNIR, aSERIEDOC,  aSIMBOLDOC );
          
          IF PKG_CARNETEDOC.CANLOCKNUMARDOC(aCARNETNIR,aNRDOC) = 0 THEN
            aNRDOC    := NULL;
            aSERIEDOC := NULL;
          END IF;
        END IF;

        
        NEW_DATANIR := TRUNC(SYSDATE);
        -- data nirului trebuie sa apartina lunii din intrari
        IF LAST_DAY(NEW_DATANIR) &gt; LAST_DAY(TO_DATE(&apos;01.&apos; || V_REC.LUNA || &apos;.&apos; || V_REC.AN, &apos;dd.mm.yyyy&apos;))
        THEN
          NEW_DATANIR := LAST_DAY(TO_DATE(&apos;01.&apos; || V_REC.LUNA || &apos;.&apos; || V_REC.AN, &apos;dd.mm.yyyy&apos;));
        END IF;    
          
        
        
        
        INSERT INTO NIR(CODNIR, CODINTR, CARNETNIR, DATANIR, NRNIR,  GEST, ANULAT, BLOCAT, OPERAT, TIPNIR, USERID, DATACREARE)
        VALUES (aCODNIR, 
                V_REC.CODINTR, 
                aCARNETNIR, /*TRUNC(SYSDATE)*/ 
                NEW_DATANIR, 
                aNRDOC, 
                 CASE 
                   WHEN COALESCE(V_REC.NEWCODGEST, 0) &gt; 0 THEN V_REC.NEWCODGEST
                   ELSE  V_REC.CODGEST
                 END, 
                 0, 
                 0, 
                 1, 
                 V_REC.TIPDOC, 
                 PKG_GLOBALS.USERID, 
                 SYSDATE());

        IF NVL(aNRDOC, 0) &lt;&gt; 0 THEN
           PKG_CARNETEDOC.SOLVENUMARDOC(aCARNETNIR, ANRDOC);
           COMMIT;
        END IF;


       UPDATE TMP_RECEPTIEWMS R
       SET
         CODNIR   = aCODNIR,
         NRDOC    = aNRDOC,
         SERIADOC = aSERIEDOC
       WHERE
         CODGEST = V_REC.CODGEST
         AND COALESCE(NEWCODGEST, 0) = COALESCE(V_REC.NEWCODGEST, 0)
         AND (SELECT CODINTR FROM  INTRARI1 I1 WHERE I1.CODINTR1 = R.CODINTR1) = V_REC.CODINTR;

  END LOOP;


  FOR V_REC_R IN ( SELECT R.*, I1.CODINTR, I.TIPDOC FROM TMP_RECEPTIEWMS R, INTRARI1 I1, INTRARI I WHERE R.CODINTR1 = I1.CODINTR1 AND I.CODINTR = I1.CODINTR)
  LOOP
       aCODNIR := V_REC_R.CODNIR;
       aOBSSERIE := V_REC_R.OBSSERIE;

        MANCANT := V_REC_R.CANT;
        aCODDVI1 := 0;
        IF V_REC_R.TIPDOC = 5 THEN
          BEGIN
            SELECT CODDVI1 INTO aCODDVI1 FROM DVI1 WHERE CODINTR1 = V_REC_R.CODINTR1 AND ROWNUM = 1;
            EXCEPTION WHEN OTHERS THEN aCODDVI1 := 0;
          END;
        END IF;

        FOR V_REC_NS IN
        (SELECT NS.*, NVL(A.RELATIEUM1, 0) AS RELATIEUM1, L.CODLINIECOMANDA CODCOMANDA1
          FROM
            NIRSTOC NS
            LEFT JOIN INTRLINK L ON L.CODINTR1 = NS.CODINTR1,
            NIR N,
            NARTOBJ O,
            NART A
          WHERE
            NS.CODNIR = N.CODNIR
            AND N.GEST = V_REC_R.CODGEST
            AND O.CODOBIECT = NS.CODOBIECT
            AND A.CODARTICOL = O.CODARTICOL
            AND N.OPERAT = 0
            AND CONDITIE_LINK_NS(NVL(NS.CODINTR1, 0),  NVL(NS.CODDVI1,0),  V_REC_R.CODINTR1, aCODDVI1) = 1
         )
         LOOP
           IF MANCANT &gt; 0 THEN
               aCANTPREL := MANCANT;
               IF V_REC_NS.CANTFURN &gt;= aCANTPREL THEN
                 RESTCANTFURN   := V_REC_NS.CANTFURN - aCANTPREL;
                 CANTFURNINSERT := aCANTPREL;
               ELSE
                 RESTCANTFURN   :=0;
                 CANTFURNINSERT := V_REC_NS.CANTFURN;
               END IF;
               
               UPDATE NIRSTOC
               SET
                 CANTNIR   = CASE
                               WHEN CANTNIR &gt;= aCANTPREL THEN CANTNIR  - aCANTPREL
                               ELSE 0
                             END,
                 CANTFURN  = RESTCANTFURN
               WHERE
                 CODNIRSTOC = V_REC_NS.CODNIRSTOC;

               UPDATE NIRSER
               SET
                 CANTNIR   = CANTNIR  - aCANTPREL
               WHERE
                 CODNIRSTOC = V_REC_NS.CODNIRSTOC;

                 aCODNIRSTOC := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;
                 INSERT INTO NIRSTOC(CODNIRSTOC,
                                     CODNIR,
                                     CODINTR1,
                                     CODDVI1,
                                     CODNIRSTOCPARINTE,
                                     CANTNIR,
                                     UMSEC,
                                     CODOBIECT,
                                     CODIOART,
                                     PRET,
                                     ADAOS,
                                     TVA,
                                     TIPSERIE,
                                     CODLIVR1,
                                     REST,
                                     PROCENTADAOS,
                                     CANTFURN,
                                     ROTLEI,
                                     ROTVALUTA,
                                     CODLOCATIE,
                                     DATAACHIZ,
                                     FURN,
                                     D1,
                                     D2,
                                     D3,
                                     CANTUM1,
                                     RESTUM1)
                             VALUES(aCODNIRSTOC,
                                    aCODNIR,
                                    V_REC_NS.CODINTR1,
                                    V_REC_NS.CODDVI1,
                                    V_REC_NS.CODNIRSTOCPARINTE,
                                    aCANTPREL,
                                    V_REC_NS.UMSEC,
                                    V_REC_NS.CODOBIECT,
                                    V_REC_NS.CODIOART,
                                    V_REC_NS.PRET,
                                    V_REC_NS.ADAOS,
                                    V_REC_NS.TVA,
                                    V_REC_NS.TIPSERIE,
                                    V_REC_NS.CODLIVR1,
                                    aCANTPREL,
                                    V_REC_NS.PROCENTADAOS,
                                    CANTFURNINSERT,
                                    V_REC_NS.ROTLEI,
                                    V_REC_NS.ROTVALUTA,
                                    CASE WHEN V_REC_R.NEWCODLOCATIE &gt; 0 THEN V_REC_R.NEWCODLOCATIE ELSE V_REC_R.CODLOCATIE END,
                                    V_REC_NS.DATAACHIZ,
                                    V_REC_NS.FURN,
                                    V_REC_NS.D1,
                                    V_REC_NS.D2,
                                    V_REC_NS.D3,
                                    PKG_JURNAL.GetSpecificCantUM1(V_REC_NS.RelatieUM1, V_REC_NS.D1, V_REC_NS.D2, V_REC_NS.D3, aCANTPREL),
                                    PKG_JURNAL.GetSpecificCantUM1(V_REC_NS.RelatieUM1, V_REC_NS.D1, V_REC_NS.D2, V_REC_NS.D3, aCANTPREL)
                                   );
              aCANTREZ := aCANTPREL;
              aCodNirSer := 0;
              INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG,TIPDOC,PRETMAT,DIRTY,DINSTOC,CODCOMANDA1)
                          VALUES(aCODNIRSTOC, aCODNIRSTOC, V_REC_R.TIPDOC, V_REC_NS.PRET - COALESCE(V_REC_NS.ADAOS,0), 0, 1, 0);                     
              IF NVL(V_REC_R.CODSERIE, 0) &lt;&gt; 0 THEN 
                INSERT INTO TMP_NIRSTOC(CODNIRSTOC) VALUES(aCODNIRSTOC);
                select SEQ_NIRSER_CODNIRSER.NEXTVAL into aCodNirSer from dual;
                INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, TG, DATAPROD, CANTUM1, RESTUM1, OBS)
                VALUES (aCodNirSer, aCODNIRSTOC,V_REC_R.CODSERIE, aCANTPREL, aCANTPREL, V_REC_R.TG, V_REC_R.DATAPROD,
                                    PKG_JURNAL.GetSpecificCantUM1(V_REC_NS.RelatieUM1, V_REC_NS.D1, V_REC_NS.D2, V_REC_NS.D3, aCANTPREL),
                                    PKG_JURNAL.GetSpecificCantUM1(V_REC_NS.RelatieUM1, V_REC_NS.D1, V_REC_NS.D2, V_REC_NS.D3, aCANTPREL),
                                    aOBSSERIE
                );
              END IF;
             FOR V_REZ IN (
                SELECT R.CODCOMANDA1, R.REST, r.umsec, r.codcomanda1f, r.codrezervats
                FROM REZERVATS R
                WHERE R.CODCOMANDA1F = V_REC_NS.CODCOMANDA1
                      AND R.CODNIRSTOC = v_rec_ns.codnirstoc AND R.REST &gt; 0
              ) LOOP
                if aCANTREZ &gt; v_rez.rest then
                  insert into rezervats(codrezervats,
                                        codcomanda1,
                                        codnirstoc,
                                        codnirser,
                                        rest,
                                        umsec,
                                        rezervatini,
                                        codcomanda1f)
                  values (seq_rezervats_codrezervats.nextval,
                          v_rez.codcomanda1,
                          aCodNirStoc,
                          aCodNirSer,
                          v_rez.rest,
                          v_rez.umsec,
                          v_rez.rest,
                          v_rez.codcomanda1f
                         );
                  update rezervats set rest = 0 where codrezervats = v_rez.codrezervats;       
                  aCantRez := aCantRez - v_rez.rest;       
                else
                  insert into rezervats(codrezervats,
                                        codcomanda1,
                                        codnirstoc,
                                        codnirser,
                                        rest,
                                        umsec,
                                        rezervatini,
                                        codcomanda1f)
                  values (seq_rezervats_codrezervats.nextval,
                          v_rez.codcomanda1,
                          aCodNirStoc,
                          aCodNirSer,
                          aCantRez,
                          v_rez.umsec,
                          aCantRez,
                          v_rez.codcomanda1f
                         );
                  update rezervats set rest = rest - aCantRez where codrezervats = v_rez.codrezervats;
                  aCantRez := 0;
                end if;
                if aCantRez = 0 then Exit; end if;
              END LOOP;
             MANCANT := MANCANT - aCANTPREL;
           END IF;
         END LOOP;

--     DELETE FROM NIR N WHERE V_REC_R.CODINTR = CODINTR AND NVL(OPERAT, 0) = 0 AND GEST = V_REC_R.CODGEST
--     AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0;

  END LOOP;

  GRUPEAZA_LINII_CU_SERII;

  FOR V_REC IN (SELECT DISTINCT I1.CODINTR, TMP.USERID
                FROM 
                  TMP_RECEPTIEWMS TMP
                  INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = TMP.CODINTR1
                WHERE
                  COALESCE(USERID, 0) &lt;&gt; 0
               )
  LOOP
    INSERT INTO MODIFICARI(CODMODIFICARE, CODMASTER, TABLENAME, DATAMODIF, USERMODIF, TIPMODIF)
                VALUES(SEQ_MODIFICARI_CODMODIFICARE.NEXTVAL, V_REC.CODINTR, &apos;INTRARI&apos;, SYSDATE, V_REC.USERID, 5);
  END LOOP;                    


END;



PROCEDURE SET_RECEPTII_PARTIALE_INTRARI
IS
  aCODNIR      NUMBER(20);
  aCARNETNIR   NUMBER(20);
  aNRDOC       NUMBER(20);
  aSERIEDOC    VARCHAR2(10);
  aSIMBOLDOC   VARCHAR2(10);
  aDATANIR     DATE;
  MANCANT      NUMBER(20, 7);
  aCANTPREL    NUMBER(20, 7);
  aCODDVI1     NUMBER(20);
  aCODNIRSTOC  NUMBER(20);
BEGIN
  FOR V_REC_R IN ( SELECT R.*, I1.CODINTR, I.TIPDOC FROM TMP_RECEPTIEWMS R, INTRARI1 I1, INTRARI I WHERE R.CODINTR1 = I1.CODINTR1 AND I.CODINTR = I1.CODINTR)
  LOOP
     BEGIN
       SELECT CODNIR INTO aCODNIR FROM NIR WHERE CODINTR = V_REC_R.CODINTR AND GEST = V_REC_R.CODGEST AND OPERAT = 1 AND ROWNUM = 1;
       EXCEPTION WHEN OTHERS THEN aCODNIR := 0;
     END;

     IF aCODNIR = 0 THEN

       aCODNIR := SEQ_NIR_CODNIR.NEXTVAL;

       BEGIN
         SELECT CARNETNIR, DATANIR INTO aCARNETNIR, aDATANIR FROM NIR WHERE CODINTR = V_REC_R.CODINTR AND GEST = V_REC_R.CODGEST AND OPERAT = 0 AND ROWNUM = 1;
         EXCEPTION WHEN OTHERS THEN aCARNETNIR := 0; aDATANIR := NULL;
       END;

        IF NVL(aCARNETNIR, 0) &lt;&gt; 0 THEN
          aNRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(aCARNETNIR, aSERIEDOC,  aSIMBOLDOC );
          IF PKG_CARNETEDOC.CANLOCKNUMARDOC(aCARNETNIR,aNRDOC) = 0 THEN
            aNRDOC    := NULL;
            aSERIEDOC := NULL;
          END IF;
        END IF;


        INSERT INTO NIR(CODNIR, CODINTR, CARNETNIR, DATANIR, NRNIR,  GEST, ANULAT, BLOCAT, OPERAT, TIPNIR, USERID, DATACREARE)
        VALUES (aCODNIR, V_REC_R.CODINTR, aCARNETNIR, aDATANIR, aNRDOC, V_REC_R.CODGEST, 0, 0, 1, V_REC_R.TIPDOC, PKG_GLOBALS.USERID, SYSDATE());

        IF NVL(aNRDOC, 0) &lt;&gt; 0 THEN
           PKG_CARNETEDOC.SOLVENUMARDOC(aCARNETNIR, ANRDOC);
        END IF;

      END IF;

        MANCANT := V_REC_R.CANT;
        aCODDVI1 := 0;
        IF V_REC_R.TIPDOC = 5 THEN
          BEGIN
            SELECT CODDVI1 INTO aCODDVI1 FROM DVI1 WHERE CODINTR1 = V_REC_R.CODINTR1 AND ROWNUM = 1;
            EXCEPTION WHEN OTHERS THEN aCODDVI1 := 0;
          END;
        END IF;

        FOR V_REC_NS IN
        (SELECT NS.*
          FROM
            NIRSTOC NS,
            NIR N
          WHERE
            NS.CODNIR = N.CODNIR
            AND N.GEST = V_REC_R.CODGEST
            AND N.OPERAT = 0
            AND CONDITIE_LINK_NS(NVL(NS.CODINTR1, 0),  NVL(NS.CODDVI1,0),  V_REC_R.CODINTR1, aCODDVI1) = 1
         )
         LOOP
           IF MANCANT &gt; 0 THEN
               --IF MANCANT &gt;= V_REC_NS.CANTNIR THEN aCANTPREL := V_REC_NS.CANTNIR; ELSE aCANTPREL := MANCANT; END IF;
               aCANTPREL := MANCANT;
               IF aCANTPREL &gt;= V_REC_NS.CANTNIR THEN
                 UPDATE NIRSTOC
                 SET
                   CODNIR     = aCODNIR,
                   CODLOCATIE = V_REC_R.CODLOCATIE,
                   CANTFURN   = aCANTPREL,
                   CANTNIR    = aCANTPREL,
                   REST       = aCANTPREL
                 WHERE
                   CODNIRSTOC = V_REC_NS.CODNIRSTOC;

                IF NVL(V_REC_R.CODSERIE, 0) &lt;&gt; 0 THEN
                  DELETE FROM NIRSER WHERE CODNIRSTOC = V_REC_NS.CODNIRSTOC;
                  INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST)
                         VALUES     (SEQ_NIRSER_CODNIRSER.NEXTVAL, V_REC_NS.CODNIRSTOC, V_REC_R.CODSERIE, aCANTPREL, aCANTPREL);


--                 UPDATE NIRSER
--                 SET
--                   CANTNIR    = aCANTPREL,
--                   CODSERIE   = V_REC_R.CODSERIE
--                 WHERE
--                   CODNIRSTOC = V_REC_NS.CODNIRSTOC;
                END IF;


               ELSE
                 UPDATE NIRSTOC
                 SET
                   CANTNIR   = CANTNIR  - aCANTPREL,
                   CANTFURN  = CANTFURN - aCANTPREL
                 WHERE
                   CODNIRSTOC = V_REC_NS.CODNIRSTOC;

                 UPDATE NIRSER
                 SET
                   CANTNIR   = CANTNIR  - aCANTPREL
                 WHERE
                   CODNIRSTOC = V_REC_NS.CODNIRSTOC;

                   aCODNIRSTOC := SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL;
                   INSERT INTO NIRSTOC(CODNIRSTOC,
                                       CODNIR,
                                       CODINTR1,
                                       CODDVI1,
                                       CODNIRSTOCPARINTE,
                                       CANTNIR,
                                       UMSEC,
                                       CODOBIECT,
                                       CODIOART,
                                       PRET,
                                       ADAOS,
                                       TVA,
                                       TIPSERIE,
                                       CODLIVR1,
                                       REST,
                                       PROCENTADAOS,
                                       CANTFURN,
                                       ROTLEI,
                                       ROTVALUTA,
                                       CODLOCATIE,
                                       DATAACHIZ,
                                       FURN)
                               VALUES(aCODNIRSTOC,
                                      aCODNIR,
                                      V_REC_NS.CODINTR1,
                                      V_REC_NS.CODDVI1,
                                      V_REC_NS.CODNIRSTOCPARINTE,
                                      aCANTPREL,
                                      V_REC_NS.UMSEC,
                                      V_REC_NS.CODOBIECT,
                                      V_REC_NS.CODIOART,
                                      V_REC_NS.PRET,
                                      V_REC_NS.ADAOS,
                                      V_REC_NS.TVA,
                                      V_REC_NS.TIPSERIE,
                                      V_REC_NS.CODLIVR1,
                                      aCANTPREL,
                                      V_REC_NS.PROCENTADAOS,
                                      aCANTPREL,
                                      V_REC_NS.ROTLEI,
                                      V_REC_NS.ROTVALUTA,
                                      V_REC_R.CODLOCATIE,
                                      V_REC_NS.DATAACHIZ,
                                      V_REC_NS.FURN
                                     );
                IF NVL(V_REC_R.CODSERIE, 0) &lt;&gt; 0 THEN
                  INSERT INTO NIRSER(CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR)
                  VALUES (SEQ_NIRSER_CODNIRSER.NEXTVAL, aCODNIRSTOC,V_REC_R.CODSERIE, aCANTPREL);
                END IF;

               END IF;
               MANCANT := MANCANT - aCANTPREL;
           END IF;
         END LOOP;

     DELETE FROM NIR N WHERE V_REC_R.CODINTR = CODINTR AND NVL(OPERAT, 0) = 0 AND GEST = V_REC_R.CODGEST
     AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = N.CODNIR) = 0;

  END LOOP;

END;

FUNCTION MUTAREZERVARECUSERIE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          SERIEVECHE   IN VARCHAR2,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          SERIENOUA   IN VARCHAR2,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER
IS
  aCANTIN     NUMBER(20, 7);
  aCANTOUT    NUMBER(20, 7);
  aCANTPREL   NUMBER(20, 7);
  aCODOBIECT  NUMBER(20);
  aUMSEC      NUMBER(20);
BEGIN

  BEGIN
    SELECT CODOBIECT, UMSEC INTO aCODOBIECT, aUMSEC FROM COMANDA1 WHERE CODCOMANDA1 = CODLINIECOMANDA;
    EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
  END;

  IF aCODOBIECT = 0 THEN RETURN 0; END IF;

  aCANTIN   := CANT;
  aCANTOUT  := CANT;
  DELETE TMP_REZERVATS;
  DELETE TMP_PROCESARE_DLWMS;



  FOR V_REC IN (SELECT
                  R.CODREZERVATS,
                  R.REST
                FROM
                  REZERVATS R,
                  NIRSTOC NS,
                  NIR N,
                  NIRSER NSE,
                  NSERII SER
                WHERE
                  R.CODCOMANDA1 = CODLINIECOMANDA
                  AND NS.CODNIRSTOC = R.CODNIRSTOC
                  AND NSE.CODNIRSER = R.CODNIRSER
                  AND N.CODNIR = NS.CODNIR
                  AND N.GEST = CODGESTVECHE
                  AND NVL(NS.CODLOCATIE, 0) = CODLOCATIEVECHE
                  AND SER.CODSERIE = NSE.CODSERIE
                  AND SER.SERIE = SERIEVECHE
               )

   LOOP
      IF aCANTIN &gt;= V_REC.REST THEN aCANTPREL := V_REC.REST;
                               ELSE aCANTPREL := aCANTIN;
      END IF;
      INSERT INTO TMP_REZERVATS(CODREZERVATS, REST) VALUES (V_REC.CODREZERVATS, aCANTPREL);

      aCANTIN := aCANTIN - aCANTPREL;

      IF aCANTIN = 0 THEN EXIT; END IF;

   END LOOP;

   IF aCANTIN &lt;&gt; 0 THEN RETURN 0; END IF;


   FOR V_REC IN (SELECT
                   NS.CODNIRSTOC,
                   NSE.CODNIRSER,
                   NSE.REST - NVL((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSER = NSE.CODNIRSER), 0) AS REST
                 FROM
                   NIRSTOC NS,
                   NIRSER NSE,
                   NSERII SER,
                   NIR N
                WHERE
                  NS.CODOBIECT = aCODOBIECT
                  AND N.CODNIR = NS.CODNIR
                  AND N.GEST = CODGESTNOUA
                  AND NS.CODLOCATIE = CODLOCATIENOUA
                  AND NSE.CODNIRSTOC = NS.CODNIRSTOC
                  AND SER.CODSERIE = NSE.CODSERIE
                  AND UPPER(SER.SERIE) = UPPER(SERIENOUA)
                )
               LOOP
                  IF aCANTOUT &gt;= V_REC.REST THEN aCANTPREL := V_REC.REST;
                                            ELSE aCANTPREL := aCANTOUT;
                  END IF;
                  INSERT INTO TMP_PROCESARE_DLWMS(CANT, NEWCODNIRSTOC, NEWCODNIRSER)
                  VALUES (aCANTPREL, V_REC.CODNIRSTOC, V_REC.CODNIRSER);

                  aCANTOUT := aCANTOUT - aCANTPREL;

                  IF aCANTOUT =0 THEN EXIT; END IF;

               END LOOP;


              IF aCANTIN = 0 AND aCANTOUT = 0 THEN

                FOR V_REC IN (SELECT * FROM TMP_REZERVATS)
                LOOP
                  UPDATE REZERVATS
                  SET
                    REST = REST - V_REC.REST
                  WHERE
                    CODREZERVATS = V_REC.CODREZERVATS;
                END LOOP;


                FOR V_REC IN (SELECT * FROM TMP_PROCESARE_DLWMS)
                LOOP
                  INSERT INTO REZERVATS(CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC)
                  VALUES(SEQ_REZERVATS_CODREZERVATS.NEXTVAL, CODLINIECOMANDA, V_REC.NEWCODNIRSTOC, V_REC.NEWCODNIRSER, V_REC.CANT, aUMSEC);
                END LOOP;

                DELETE REZERVATS WHERE CODCOMANDA1 = CODLINIECOMANDA AND REST = 0;

                COMMIT;
                RETURN 1;
              ELSE
                ROLLBACK;
                RETURN 0;
              END IF;



END;

FUNCTION MUTAREZERVAREFARASERIE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER
IS
  aCANTIN     NUMBER(20, 7);
  aCANTOUT    NUMBER(20, 7);
  aCANTPREL   NUMBER(20, 7);
  aCODOBIECT  NUMBER(20);
  aUMSEC      NUMBER(20);
BEGIN

  BEGIN
    SELECT CODOBIECT, UMSEC INTO aCODOBIECT, aUMSEC FROM COMANDA1 WHERE CODCOMANDA1 = CODLINIECOMANDA;
    EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
  END;

  IF aCODOBIECT = 0 THEN RETURN 0; END IF;

  aCANTIN   := CANT;
  aCANTOUT  := CANT;
  DELETE TMP_REZERVATS;
  DELETE TMP_PROCESARE_DLWMS;



  FOR V_REC IN (SELECT
                  R.CODREZERVATS,
                  R.REST
                FROM
                  REZERVATS R,
                  NIRSTOC NS,
                  NIR N
                WHERE
                  R.CODCOMANDA1 = CODLINIECOMANDA
                  AND NS.CODNIRSTOC = R.CODNIRSTOC
                  AND N.CODNIR = NS.CODNIR
                  AND N.GEST = CODGESTVECHE
                  AND NVL(NS.CODLOCATIE, 0) = CODLOCATIEVECHE
               )

   LOOP
      IF aCANTIN &gt;= V_REC.REST THEN aCANTPREL := V_REC.REST;
                               ELSE aCANTPREL := aCANTIN;
      END IF;
      INSERT INTO TMP_REZERVATS(CODREZERVATS, REST) VALUES (V_REC.CODREZERVATS, aCANTPREL);

      aCANTIN := aCANTIN - aCANTPREL;

      IF aCANTIN = 0 THEN EXIT; END IF;

   END LOOP;

   IF aCANTIN &lt;&gt; 0 THEN RETURN 0; END IF;


   FOR V_REC IN (SELECT
                   NS.CODNIRSTOC,
                   NS.REST - NVL((SELECT SUM(REST) FROM REZERVATS WHERE CODNIRSTOC = NS.CODNIRSTOC), 0) AS REST
                 FROM
                   NIRSTOC NS,
                   NIR N
                WHERE
                  NS.CODOBIECT = aCODOBIECT
                  AND N.CODNIR = NS.CODNIR
                  AND N.GEST = CODGESTNOUA
                  AND NS.CODLOCATIE = CODLOCATIENOUA
                )
               LOOP
                  IF aCANTOUT &gt;= V_REC.REST THEN aCANTPREL := V_REC.REST;
                                            ELSE aCANTPREL := aCANTOUT;
                  END IF;
                  INSERT INTO TMP_PROCESARE_DLWMS(CANT, NEWCODNIRSTOC)
                  VALUES (aCANTPREL, V_REC.CODNIRSTOC);

                  aCANTOUT := aCANTOUT - aCANTPREL;

                  IF aCANTOUT =0 THEN EXIT; END IF;

               END LOOP;


              IF aCANTIN = 0 AND aCANTOUT = 0 THEN

                FOR V_REC IN (SELECT * FROM TMP_REZERVATS)
                LOOP
                  UPDATE REZERVATS
                  SET
                    REST = REST - V_REC.REST
                  WHERE
                    CODREZERVATS = V_REC.CODREZERVATS;
                END LOOP;


                FOR V_REC IN (SELECT * FROM TMP_PROCESARE_DLWMS)
                LOOP
                  INSERT INTO REZERVATS(CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC)
                  VALUES(SEQ_REZERVATS_CODREZERVATS.NEXTVAL, CODLINIECOMANDA, V_REC.NEWCODNIRSTOC, 0, V_REC.CANT, aUMSEC);
                END LOOP;

                DELETE REZERVATS WHERE CODCOMANDA1 = CODLINIECOMANDA AND REST = 0;

                COMMIT;
                RETURN 1;
              ELSE
                ROLLBACK;
                RETURN 0;
              END IF;



END;



FUNCTION SCHIMBAREZERVARE(CODLINIECOMANDA IN NUMBER,
                          CODGESTVECHE IN NUMBER,
                          SERIEVECHE   IN VARCHAR2,
                          CODLOCATIEVECHE IN NUMBER,
                          CODGESTNOUA IN NUMBER,
                          SERIENOUA   IN VARCHAR2,
                          CODLOCATIENOUA IN NUMBER,
                          CANT           IN NUMBER) RETURN NUMBER
IS
aTIPSERIE VARCHAR2(10);
RES NUMBER := 0;
BEGIN
  BEGIN
   SELECT NVL(A.TIPSERIE, &apos;0&apos;) INTO aTIPSERIE FROM COMANDA1 C1, NARTOBJ O, NART A
   WHERE
     C1.CODCOMANDA1 = CODLINIECOMANDA
     AND C1.CODOBIECT = O.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL;
    EXCEPTION WHEN OTHERS THEN aTIPSERIE := &apos;0&apos;;
  END;

  IF aTIPSERIE = &apos;0&apos; THEN RES :=  MUTAREZERVAREFARASERIE(CODLINIECOMANDA,
                                                        CODGESTVECHE,
                                                        CODLOCATIEVECHE,
                                                        CODGESTNOUA,
                                                        CODLOCATIENOUA,
                                                        CANT);
                     ELSE RES :=  MUTAREZERVARECUSERIE(CODLINIECOMANDA,
                                                        CODGESTVECHE,
                                                        SERIEVECHE,
                                                        CODLOCATIEVECHE,
                                                        CODGESTNOUA,
                                                        SERIENOUA,
                                                        CODLOCATIENOUA,
                                                        CANT);
  END IF;

  RETURN RES;
END;


FUNCTION GETSERIEDINLOT(CODSERIELOT IN NUMBER ,aCODOBIECT IN NUMBER, aSERIE IN VARCHAR2 ) RETURN NUMBER
IS
 RES NUMBER := 0;
BEGIN
  BEGIN
    SELECT CODSERIE INTO RES
    FROM
      NSERII
    WHERE
      CODPARINTE = CODSERIELOT
      AND SERIE = aSERIE;

    EXCEPTION WHEN OTHERS THEN RES := 0;
  END;
  IF RES = 0 THEN
    RES := SEQ_NSERII_CODSERIE.NEXTVAL;
    INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT, CODPARINTE)
    VALUES (RES, aSERIE, aCODOBIECT, CODSERIELOT);
  END IF;

  RETURN RES;
END;

PROCEDURE PREIA_SERII_COMANDA
IS
  aCODSERIE NUMBER(20);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_SERIALIZARI) LOOP
    aCODSERIE := GETSERIEDINLOT(V_REC.CODSERIELOT, V_REC.CODOBIECT, V_REC.SERIE);
    INSERT INTO SERIICMD(CODSERIECMD, CODCOMANDA, CODOBIECT, CODSERIE, DATAEXP, GTIN)
    VALUES (SEQ_SERIICMD_CODSERIECMD.NEXTVAL, V_REC.CODDOC, V_REC.CODOBIECT,aCODSERIE, V_REC.DATAEXP, V_REC.GTIN);
  END LOOP;
END;


PROCEDURE PREIA_SERII_INTRARI
IS
  aCODSERIE NUMBER(20);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_SERIALIZARI) LOOP
    aCODSERIE := GETSERIEDINLOT(V_REC.CODSERIELOT, V_REC.CODOBIECT, V_REC.SERIE);
    INSERT INTO SERIIINTR(CODSERIEINTR, CODINTR, CODOBIECT, CODSERIE, DATAEXP, GTIN)
    VALUES (SEQ_SERIIINTR_CODSERIEINTR.NEXTVAL, V_REC.CODDOC, V_REC.CODOBIECT,aCODSERIE, V_REC.DATAEXP, V_REC.GTIN);
  END LOOP;
END;

PROCEDURE PREIA_SERII_IESIRI
IS
  aCODSERIE NUMBER(20);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_SERIALIZARI) LOOP
    aCODSERIE := GETSERIEDINLOT(V_REC.CODSERIELOT, V_REC.CODOBIECT, V_REC.SERIE);
    INSERT INTO SERIIIES(CODSERIEIES, CODIES, CODOBIECT, CODSERIE, DATAEXP, GTIN)
    VALUES (SEQ_SERIIIES_CODSERIEIES.NEXTVAL, V_REC.CODDOC, V_REC.CODOBIECT,aCODSERIE, V_REC.DATAEXP, V_REC.GTIN);
  END LOOP;
END;

end PKG_IMPORTALTEAPLICATII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IMPORTDATEWM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC585290310587F3A87CDCAA56B72B3A3ABBDB96</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_importdatewm IS

PROCEDURE ADAUGA_PARTENER_NOU(aCODPART OUT NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_NPART_CODPART.NEXTVAL INTO aCODPART FROM DUAL;

  INSERT INTO NPART(CODPART, DEN_PART, REGCOM, CODEXTERN, CODINTERN, CODCLASA, DATAADAUGARII, PERSOANAFIZICA)
  SELECT aCODPART, DEN_PART, REGCOM, CODEXTERN, CODINTERN, CODCLASA, DATAADAUGARII, PERSOANAFIZICA FROM TMP_NPART;

  INSERT INTO NPART1 (CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART, ALSTART, ALSTOP)
  SELECT SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, CODIOPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999 FROM TMP_NPART1;

  INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
  SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, aCODPART, CODFISCAL, PRINCIPAL FROM TMP_NPARTCODFISC;

  COMMIT;
END;




PROCEDURE ADAUGA_LOCATIE_NOUA(aCODLOCATIE OUT NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL INTO aCODLOCATIE FROM DUAL;

  INSERT INTO NAGENDA(CODAGENDA, TIP, SEDIUSOCIAL,  STRADA, OBS, CODPART, CODLOCALIT, TELEFON, NR1, NR2, SECTOR, BLOC, ETAJ, APART, SCARA, LONGITUDINE, LATITUDINE, OBS2)
  SELECT aCODLOCATIE, TIP, SEDIUSOCIAL, SUBSTR(ADRESA,1, 30),  OBS, CODPART, CODLOCALIT, TELEFON, NR1, NR2, SECTOR, BLOC, ETAJ, APART, SCARA, LONGITUDINE, LATITUDINE, OBS2 
  FROM TMP_NAGENDA;


  COMMIT;
END;


PROCEDURE ADAUGA_SERIE_NOUA(aCODSERIE OUT NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;

  INSERT INTO NSERII(CODSERIE, SERIE, CODOBIECT, OBS)
  SELECT aCODSERIE, SERIE, CODOBIECT, OBS FROM TMP_NSERII;

  COMMIT;
END;



PROCEDURE ADAUGA_CARNET_NOU(aCODCARNET OUT NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT SEQ_DOCCARNETE_CODCARNET.NEXTVAL INTO aCODCARNET FROM DUAL;

  INSERT INTO DOCCARNETE (CODCARNET, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, SUBUNITATEA, INACTIV)
  SELECT aCODCARNET, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, SUBUNITATEA, 1 FROM TMP_DOCCARNETE;

  INSERT INTO DOCLINK(CODDOCLINK, CODCARNET, CODMACHETA)
  SELECT SEQ_DOCLINK_CODDOCLINK.NEXTVAL, aCODCARNET, CODMACHETA FROM TMP_DOCLINK;


  COMMIT;
END;


end PKG_IMPORTDATEWM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_IMPORT_PART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9521CE720F3BB2E47BFE3956B325D52E5A73E95B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_IMPORT_PART IS


FUNCTION GETCODMONEDA(aSIMBOL IN VARCHAR2) RETURN NUMBER
IS
 aCODMONEDA NUMBER(20) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF NVL(aSIMBOL, &apos;?&apos;) = &apos;?&apos; THEN RETURN 0;
  END IF;
  BEGIN
    SELECT CODMONEDA INTO aCODMONEDA FROM NMONEDE WHERE UPPER(NVL(SIMBOL, &apos;?&apos;)) = UPPER(aSIMBOL);
    EXCEPTION WHEN OTHERS THEN aCODMONEDA := -1;
  END;
  IF aCODMONEDA = -1 THEN
    aCODMONEDA := SEQ_NMONEDE_CODMONEDA.NEXTVAL;
    INSERT INTO NMONEDE(CODMONEDA, DEN_MONEDA, SIMBOL)
                VALUES (aCODMONEDA, aSIMBOL, aSIMBOL);
    COMMIT;
  END IF;
  RETURN aCODMONEDA;
END;



FUNCTION GETCODBANCA(aSIMBOL IN VARCHAR2, aDENUMIRE IN VARCHAR2) RETURN NUMBER
IS
 aCODBANCA NUMBER(20) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF NVL(aSIMBOL, &apos;?&apos;) = &apos;?&apos; THEN RETURN 0;
  END IF;

  BEGIN
    SELECT CODBANK INTO aCODBANCA FROM NBANK WHERE UPPER(NVL(SIMBOL, &apos;?&apos;)) = UPPER(aSIMBOL);
    EXCEPTION WHEN OTHERS THEN aCODBANCA := 0;
  END;
  IF aCODBANCA = 0 THEN
    aCODBANCA := SEQ_NBANK_CODBANK.NEXTVAL;
    INSERT INTO NBANK(CODBANK, DENUMIRE, SIMBOL)
                VALUES (aCODBANCA, aDenumire, aSIMBOL);
    COMMIT;
  END IF;
  RETURN aCODBANCA;
END;


FUNCTION GETLOCALITSEDIU_EXT(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STARA IN VARCHAR2) RETURN NUMBER
IS
aCODLOCALIT  NUMBER(10)   := 0;
aCODTARA     NUMBER(10)   := 0;
NR           NUMBER(10)   := 0;
aTIPLOCALIT  VARCHAR2(20) := 0;
aCodJudet    NUMBER(20);
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  aCODJUDET := 0; aCodTara := 0;

  IF NVL(SJUDET, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN -- daca am judet inseamna ca tara este romania
    BEGIN
      SELECT CODJUDET INTO aCODJUDET
      FROM
        NJUDET
      WHERE
        UPPER(SIMBAUTO) = UPPER(SJUDET)
        OR(UPPER(DEN_JUDET) = UPPER(sJUDET))
        AND ROWNUM = 1;
        EXCEPTION WHEN OTHERS THEN aCODJUDET := 0;
    END;

    BEGIN
      SELECT CODTARA INTO aCODTARA
      FROM
        NTARI
      WHERE
        UPPER(DEN_TARA) = &apos;ROMANIA&apos;
        AND ROWNUM = 1;
        EXCEPTION WHEN OTHERS THEN aCODTARA := 0;
    END;
  ELSE -- nu-mi da judetul  ; verific tara
    IF NVL(STARA, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
      BEGIN
        SELECT CODTARA INTO aCODTARA
        FROM
          NTARI
        WHERE
          (UPPER(DEN_TARA) = UPPER(STARA))
          OR
          (UPPER(SIMBAUTO) = UPPER(STARA))
          AND ROWNUM = 1;
          EXCEPTION WHEN OTHERS THEN aCODTARA := 0;
      END;
    END IF;
  END IF;

  IF aCODJUDET &lt;&gt; 0 THEN
    BEGIN
    SELECT CODLOCALIT  INTO aCODLOCALIT
    FROM NLOCALIT
    WHERE
      UPPER(DEN_LOCALIT) = UPPER(SLOCALIT)
      AND CODJUDET = aCODJUDET
      AND ROWNUM = 1;
      EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
    END;
  ELSE -- NU stiu judet
    IF aCODTARA &lt;&gt; 0 THEN
    BEGIN
      SELECT CODLOCALIT  INTO aCODLOCALIT
      FROM NLOCALIT
      WHERE
        UPPER(DEN_LOCALIT) = UPPER(SLOCALIT)
        AND CODTARA = aCODTARA
        AND ROWNUM = 1;
        EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
    END;
    ELSE
      BEGIN
        SELECT CODLOCALIT  INTO aCODLOCALIT
        FROM NLOCALIT
        WHERE
          UPPER(DEN_LOCALIT) = UPPER(SLOCALIT)
          AND ROWNUM = 1;
          EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
      END;
    END IF;

  END IF;
  IF aCODLOCALIT = 0 THEN
    SELECT SEQ_NLOCALIT_CODLOCALIT.NEXTVAL INTO aCODLOCALIT FROM DUAL;

    INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA, TIP)
    VALUES (aCODLOCALIT,
            SLOCALIT,
            CASE
               WHEN aCodJudet = 0 THEN NULL
               ELSE aCODJUDET
            END,
            CASE
               WHEN aCodTARA = 0 THEN NULL
               ELSE aCODTARA
            END,
            &apos;Oras&apos;);
  END IF;
  COMMIT;
  RETURN aCODLOCALIT;
END;



FUNCTION GETLOCALITSEDIU(SLOCALIT IN VARCHAR2, SJUDET IN VARCHAR2, STARA IN VARCHAR2) RETURN NUMBER
IS
aCODLOCALIT  NUMBER(10)   := 0;
aCODTARA     NUMBER(10)   := 0;
NR           NUMBER(10)   := 0;
aTIPLOCALIT  VARCHAR2(20) := 0;
aCodJudet    NUMBER(20);
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN

  BEGIN
    SELECT
      CODLOCALIT INTO aCODLOCALIT
    FROM
      NLOCALIT L
      LEFT OUTER JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
      LEFT OUTER JOIN NTARI T ON T.CODTARA = L.CODTARA
    WHERE
     UPPER(NVL(L.DEN_LOCALIT, &apos;?&apos;)) = UPPER(NVL(sLOCALIT, &apos;?&apos;)) AND
     UPPER(NVL(J.SIMBAUTO, &apos;?&apos;))    = UPPER(NVL(SJUDET, &apos;?&apos;))AND
     UPPER(NVL(T.DEN_TARA, &apos;?&apos;))    = UPPER(NVL(STARA, &apos;?&apos;))
     AND ROWNUM = 1;
    EXCEPTION WHEN OTHERS THEN aCODLOCALIT := 0;
  END;


  aCODTARA := NULL;
  IF aCODLOCALIT = 0 THEN

    IF NVL(STARA, &apos; &apos;) &lt;&gt; &apos; &apos; THEN
      BEGIN
       SELECT CODTARA INTO aCODTARA FROM NTARI
       WHERE
         UPPER(NVL(DEN_TARA, &apos;?&apos;)) = UPPER(NVL(STARA, &apos;?&apos;));
       EXCEPTION WHEN OTHERS THEN aCODTARA := 0;
      END;

      IF aCODTARA = 0 THEN
        SELECT SEQ_NTARI_CODTARA.NEXTVAL INTO aCODTARA FROM DUAL;
        INSERT INTO NTARI (CODTARA, DEN_TARA) VALUES (aCODTARA, STARA);
      END IF;
    END IF;


    SELECT SEQ_NLOCALIT_CODLOCALIT.NEXTVAL INTO aCODLOCALIT FROM DUAL;

    aTIPLOCALIT := &apos;Oras&apos;;

    aCodJudet := 0;
    for v_jud in (select codjudet from njudet where simbauto = sjudet order by codjudet) loop
      aCodJudet := v_jud.codjudet;
      exit;
    end loop;

    INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA, TIP)
    VALUES (aCODLOCALIT, SLOCALIT, aCodJudet, aCODTARA, aTIPLOCALIT);
  END IF;

  COMMIT;
  RETURN aCODLOCALIT;
END;



PROCEDURE SETCLASAIMPLICITA(aCLASA IN NUMBER)
IS
BEGIN
  CLASAIMPLICITA := aCLASA;
END;


PROCEDURE SETCODIOPARTIMPLICIT(aCODIOART IN NUMBER)
IS
BEGIN
  CODIOPARTIMPLICIT := aCODIOART;
END;

PROCEDURE SETTIPINFOLUNARE(aTIP IN NUMBER)
IS
BEGIN
  TIPINFOLUNARE := aTIP;
END;

PROCEDURE IMPORTA_PART_EXCEL
IS
 aCODPART       NUMBER(20) ;
 NR             NUMBER(10) := 0;
 I              NUMBER(5)  := 0;
 aCODCLASA      NUMBER(20) := 0;
 aCOD           NUMBER(20) := 0;
 aCODIOPART     NUMBER(20) := 0;
BEGIN

  FOR V_REC IN (SELECT * FROM TMP_NPART_IMPORT)
  LOOP
      aCODCLASA := 0;
      IF V_REC.SIMBOLCLASA IS NOT NULL THEN
        BEGIN
          SELECT CODCLASEP INTO aCODCLASA FROM NCLASEP WHERE SIMBOL = V_REC.SIMBOLCLASA;
          EXCEPTION WHEN OTHERS THEN aCODCLASA := 0;
        END;
      END IF;

      aCODIOPART := CODIOPARTIMPLICIT;
      IF NVL(V_REC.CONTIMPLICIT, 0) &lt;&gt; 0 THEN
        aCODIOPART := V_REC.CONTIMPLICIT;
      END IF;




    IF V_REC.CODPART &lt; 0 THEN

      SELECT SEQ_NPART_CODPART.NEXTVAL INTO aCODPART FROM DUAL;
      UPDATE TMP_NAGENDA_IMPORT SET CODPART = aCODPART WHERE CODPART = V_REC.CODPART;
      UPDATE TMP_NPERSCONTACT_IMPORT SET CODPART = aCODPART WHERE CODPART = V_REC.CODPART;
      UPDATE TMP_NPARTB_IMPORT SET CODPART = aCODPART WHERE CODPART = V_REC.CODPART;
      UPDATE TMP_NPARTTR_IMPORT SET CODPART = aCODPART WHERE CODPART = V_REC.CODPART;

      IF aCODCLASA = 0 THEN
        aCODCLASA := CLASAIMPLICITA;
      END IF;


      INSERT INTO NPART(CODPART,
                        DEN_PART,
                        REGCOM,
                        CODEXTERN,
                        CODINTERN,
                        CODCLASA,
                        CODMONEDA,
                        TIPPART,
                        SCADENTAC,
                        SCADENTAV,
                        TIPPARTENER,
                        OBS,
                        PERSOANAFIZICA,
                        STRATEGIC,
                        DISCOUNT,
                        DATAADAUGARII
                        )
      VALUES (aCODPART,
              V_REC.DEN_PART,
              V_REC.REGCOM,
              V_REC.CODEXTERN,
              V_REC.CODINTERN,
              V_REC.CODCLASA,
              V_REC.CODMONEDA,
              V_REC.TIPPART,
              V_REC.SCADENTAC,
              V_REC.SCADENTAV,
              V_REC.TIPPARTENER,
              V_REC.OBS,
              V_REC.PERSOANAFIZICA,
              V_REC.STRATEGIC,
              V_REC.DISCOUNT,
              CASE
                WHEN V_REC.DATAADAUGARII IS NULL THEN SysDate
                ELSE V_REC.DATAADAUGARII
              END

             ) ;
      INSERT INTO NPART1(CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART, ALSTART, ALSTOP)
      VALUES (SEQ_NPART1_CODPART1.NEXTVAL, aCODPART, aCODIOPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, 0, 99999);

      IF V_REC.CODFISCALPRINCIPAL IS NOT NULL THEN
        INSERT INTO NPARTCODFISC(COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
        VALUES (SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, aCODPART, V_REC.CODFISCALPRINCIPAL, 1);
      END IF;
      PKG_NOMPART.CHECKPART1CRM(aCODPART);
    ELSE
      UPDATE NPART
      SET
        DEN_PART  =     CASE
                         WHEN V_REC.DEN_PART IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;DEN_PART&apos;) &gt; 0 THEN V_REC.DEN_PART
                         ELSE DEN_PART
                        END,
        REGCOM =     CASE
                         WHEN V_REC.REGCOM IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;REGCOM&apos;) &gt; 0 THEN V_REC.REGCOM
                         ELSE REGCOM
                        END,
        CODEXTERN =     CASE
                         WHEN V_REC.CODEXTERN IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;CODEXTERN&apos;) &gt; 0 THEN V_REC.CODEXTERN
                         ELSE CODEXTERN
                        END,
        CODINTERN =     CASE
                         WHEN V_REC.CODINTERN IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;CODINTERN&apos;) &gt; 0 THEN V_REC.CODINTERN
                         ELSE CODINTERN
                        END,
        CODMONEDA =     CASE
                         WHEN V_REC.CODMONEDA IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;CODMONEDA&apos;) &gt; 0 THEN V_REC.CODMONEDA
                         ELSE CODMONEDA
                        END,
        CODCLASA =     CASE
                         WHEN V_REC.SIMBOLCLASA IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SIMBOLCLASA&apos;) &gt; 0 THEN aCODCLASA
                         ELSE CODCLASA
                        END,
        SCADENTAC =     CASE
                         WHEN V_REC.SCADENTAC IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SCADENTAC&apos;) &gt; 0 THEN V_REC.SCADENTAC
                         ELSE SCADENTAC
                        END,
        SCADENTAV =     CASE
                         WHEN V_REC.SCADENTAV IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SCADENTAV&apos;) &gt; 0 THEN V_REC.SCADENTAV
                         ELSE SCADENTAV
                        END,
        TIPPARTENER =     CASE
                         WHEN V_REC.TIPPARTENER IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;TIPPARTENER&apos;) &gt; 0 THEN V_REC.TIPPARTENER
                         ELSE TIPPARTENER
                        END,
        PERSOANAFIZICA = CASE
                           WHEN V_REC.PERSOANAFIZICA IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;PERSOANAFIZICA&apos;) &gt; 0 THEN V_REC.PERSOANAFIZICA
                           ELSE PERSOANAFIZICA
                         END,
        STRATEGIC      = CASE
                           WHEN V_REC.STRATEGIC IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;STRATEGIC&apos;) &gt; 0 THEN V_REC.STRATEGIC
                           ELSE STRATEGIC
                         END,
        OBS           = CASE
                         WHEN V_REC.OBS IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;OBS&apos;) &gt; 0 THEN V_REC.OBS
                         ELSE OBS
                       END,
        DISCOUNT = CASE
                           WHEN V_REC.DISCOUNT IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;DISCOUNT&apos;) &gt; 0 THEN V_REC.DISCOUNT
                           ELSE DISCOUNT
                         END
      WHERE
        CODPART = V_REC.CODPART;


      IF TIPINFOLUNARE = 1 THEN
        SELECT COUNT(*) INTO NR
        FROM
          NPART1
        WHERE
          CODPART = V_REC.CODPART
          AND ANSTART * 12 + LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU;

         IF NR = 0 THEN
          -- verific daca am o descriere anterioara
           SELECT CODPART1 INTO NR FROM NPART1
           WHERE CODPART = V_REC.CODPART
             AND PKG_GLOBALS.ANLUNALUCRU BETWEEN ALSTART AND ALSTOP;

          IF NR = 0 THEN
            INSERT INTO NPART1(CODPART1, CODPART, ANSTART, LUNASTART, CODIOPART)
            VALUES (SEQ_NPART1_CODPART1.NEXTVAL, V_REC.CODPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, aCODIOPART);
          ELSE
            INSERT INTO NPART1(CODPART1, CODPART, ANSTART, LUNASTART, CODIOPART)
            SELECT SEQ_NPART1_CODPART1.NEXTVAL, V_REC.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, aCODIOPART FROM NPART1 WHERE CODPART1 = NR;
          END IF;

         END IF;


      END IF;

      PRC_AL_REFRESH(&apos;NPART1&apos;, V_REC.CODPART);

      UPDATE NPART1
      SET
        CODIOPART =     CASE
                         WHEN V_REC.SIMBOL_IOPART IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SIMBOL_IOPART&apos;) &gt; 0 THEN aCODIOPART
                         ELSE CODIOPART
                        END
      WHERE
        CODPART = V_REC.CODPART
        AND
        PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU BETWEEN ALSTART AND ALSTOP;

    END IF;

    IF aCODCLASA &lt;&gt; 0 THEN
      UPDATE NPART
      SET
        CODCLASA = aCODCLASA
      WHERE
       CODPART = V_REC.CODPART;
    END IF;






  END LOOP;

  -- NAGENDA;
  FOR V_REC IN (SELECT * FROM TMP_NAGENDA_IMPORT WHERE SEDIU IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODAGENDA INTO NR FROM
       NAGENDA A
      WHERE
        A.CODPART = V_REC.CODPART
        AND A.OBS = V_REC.SEDIU;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN
      INSERT INTO NAGENDA(CODAGENDA,
                          TIP,
                          CODLOCALIT,
                          SEDIUSOCIAL,
                          TELEFON,
                          FAX,
                          GLN,
                          EMAIL,
                          SECTOR,
                          STRADA,
                          NR1,
                          NR2,
                          BLOC,
                          SCARA,
                          ETAJ,
                          APART,
                          CODPOSTAL,
                          OBS,
                          CODPART,
                          CODFISCAL,
                          CODAGENT,
                          CODTRASEU,
                          CODTRASEU1)
                 VALUES(SEQ_NAGENDA_CODAGENDA.NEXTVAL,
                        0,
--                        GETLOCALITSEDIU(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                        GETLOCALITSEDIU_EXT(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                        V_REC.TIPSEDIU,
                        V_REC.TELEFON,
                        V_REC.FAX,
                        V_REC.GLN,
                        V_REC.EMAIL,
                        V_REC.SECTOR,
                        V_REC.STRADA,
                        V_REC.NR1,
                        V_REC.NR2,
                        V_REC.BLOC,
                        V_REC.SCARA,
                        V_REC.ETAJ,
                        V_REC.APART,
                        V_REC.CODPOSTAL,
                        V_REC.SEDIU,
                        V_REC.CODPART,
                        V_REC.CODFISCAL,
                        V_REC.CODAGENT,
                        V_REC.CODTRASEU,
                        V_REC.CODTRASEU1);

    ELSE
      UPDATE NAGENDA
      SET
        (CODLOCALIT,
        SEDIUSOCIAL,
        TELEFON,
        FAX,
        GLN,
        EMAIL,
        SECTOR,
        STRADA,
        NR1,
        NR2,
        BLOC,
        SCARA,
        ETAJ,
        APART,
        CODPOSTAL,
        OBS,
        CODPART,
        CODFISCAL,
        CODAGENT,
        CODTRASEU,
        CODTRASEU1) =   ( SELECT
--                          GETLOCALITSEDIU(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                          GETLOCALITSEDIU_EXT(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                          CASE
                            WHEN COALESCE(V_REC.TIPSEDIU,0 ) &lt;&gt; 0 AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SEDIUSOCIAL&apos;) &gt; 0  THEN V_REC.TIPSEDIU
                            ELSE SEDIUSOCIAL
                          END,      
                          CASE 
                            WHEN V_REC.TELEFON IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;TELEFON&apos;) &gt; 0 THEN V_REC.TELEFON
                            ELSE TELEFON
                          END,    
                          CASE
                            WHEN V_REC.FAX IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;FAX&apos;) &gt; 0 THEN V_REC.FAX
                            ELSE FAX
                          END,      
                          CASE 
                            WHEN V_REC.GLN IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;GLN&apos;) &gt; 0 THEN V_REC.GLN
                            ELSE GLN
                          END,     
                          CASE
                            WHEN V_REC.EMAIL IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;EMAIL&apos;) &gt; 0 THEN V_REC.EMAIL
                            ELSE EMAIL
                          END,     
                          CASE 
                            WHEN V_REC.SECTOR IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SECTOR&apos;) &gt; 0 THEN V_REC.SECTOR
                            ELSE SECTOR  
                          END,    
                          CASE
                            WHEN V_REC.STRADA IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;STRADA&apos;) &gt; 0 THEN V_REC.STRADA
                            ELSE STRADA
                          END,      
                          CASE 
                            WHEN V_REC.NR1 IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;NR1&apos;) &gt; 0 THEN V_REC.NR1
                            ELSE NR1
                          END,      
                          CASE 
                            WHEN V_REC.NR2 IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;NR2&apos;) &gt; 0 THEN  V_REC.NR2
                            ELSE NR2
                          END,      
                          CASE
                            WHEN V_REC.BLOC IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;BLOC&apos;) &gt; 0 THEN V_REC.BLOC
                            ELSE BLOC
                          END,      
                          CASE
                            WHEN V_REC.SCARA IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SCARA&apos;) &gt; 0 THEN V_REC.SCARA
                            ELSE SCARA
                          END,      
                          CASE 
                            WHEN V_REC.ETAJ IS NOT NULL AND  PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;ETAJ&apos;) &gt; 0 THEN  V_REC.ETAJ
                            ELSE ETAJ
                          END,      
                          CASE
                            WHEN V_REC.APART IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;APART&apos;) &gt; 0 THEN V_REC.APART
                            ELSE APART
                          END,      
                          CASE
                            WHEN V_REC.CODPOSTAL IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;CODPOSTAL&apos;) &gt; 0 THEN V_REC.CODPOSTAL
                            ELSE CODPOSTAL
                          END,      
                          CASE
                            WHEN V_REC.SEDIU IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SEDIU&apos;) &gt; 0 THEN V_REC.SEDIU
                            ELSE OBS
                          END,      
                          V_REC.CODPART,
                          CASE
                            WHEN V_REC.CODFISCAL IS NOT NULL AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;CODFISCAL&apos;) &gt; 0 THEN V_REC.CODFISCAL
                            ELSE CODFISCAL
                          END,      
                          CASE 
                            WHEN COALESCE(V_REC.CODAGENT, 0) &lt;&gt; 0 AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;MARCAAGENT&apos;) &gt; 0  THEN V_REC.CODAGENT
                            ELSE CODAGENT
                          END,     
                          CASE 
                            WHEN COALESCE(V_REC.CODTRASEU, 0) &lt;&gt; 0  AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SIMBOLTRASEULIVR&apos;) &gt; 0 THEN V_REC.CODTRASEU
                            ELSE CODTRASEU
                          END,     
                          CASE 
                            WHEN COALESCE(V_REC.CODTRASEU1, 0) &lt;&gt; 0 AND PKG_IMPORTALTEAPLICATII.SUPRASCRIERE_COLOANA(&apos;SIMBOLTRASEUVIZIT&apos;) &gt; 0 THEN V_REC.CODTRASEU1
                            ELSE CODTRASEU1
                          END     
                          FROM 
                            DUAL)

      WHERE
        CODAGENDA = NR;
    END IF;

  END LOOP;


  -- NPERSC;
  FOR V_REC IN (SELECT * FROM TMP_NPERSCONTACT_IMPORT WHERE NUME IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODPERSC INTO NR FROM
       NPERSCONTACT A
      WHERE
        A.CODPART = V_REC.CODPART
        AND A.NUME = V_REC.NUME
        AND A.PRENUME = V_REC.PRENUME;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN
      INSERT INTO NPERSCONTACT(CODPERSC,
                               NUME,
                               PRENUME,
                               TELEFON,
                               EMAIL,
                               FUNCTIE,
                               RZONA,
                               CODPART
                               )
                 VALUES(SEQ_NPERSCONTACT_CODPERSC.NEXTVAL,
                        V_REC.NUME,
                        V_REC.PRENUME,
                        V_REC.TELEFON,
                        V_REC.EMAIL,
                        V_REC.FUNCTIE,
                        V_REC.RZONA,
                        V_REC.CODPART
                       );
    ELSE
      UPDATE NPERSCONTACT
      SET
       ( NUME,
         PRENUME,
         TELEFON,
         EMAIL,
         FUNCTIE,
         RZONA,
         CODPART
       )         =   ( SELECT
                         V_REC.NUME,
                         V_REC.PRENUME,
                         V_REC.TELEFON,
                         V_REC.EMAIL,
                         V_REC.FUNCTIE,
                         V_REC.RZONA,
                         V_REC.CODPART
                       FROM
                        DUAL
                      )
      WHERE
        CODPERSC = NR;
    END IF;

  END LOOP;

  -- NPARTB
  FOR V_REC IN (SELECT * FROM TMP_NPARTB_IMPORT WHERE CONTBANCA IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODPARTB INTO NR FROM
       NPARTB A
      WHERE
        A.CODPART = V_REC.CODPART
        AND A.CONTBANCA = V_REC.CONTBANCA;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN
      INSERT INTO NPARTB(CODPARTB,
                         CODPART,
                         CODBANK,
                         IMPLICIT,
                         CODLOCALIT,
                         CONTBANCA,
                         SUCURSALA,
                         CODSWIFT,
                         CODMONEDA)

                 VALUES(SEQ_NPARTB_CODPARTB.NEXTVAL,
                         V_REC.CODPART,
                         GETCODBANCA(V_REC.SIMBOLBANCA, V_REC.DENBANCA),
                         V_REC.FACTURARE,
--                         GETLOCALITSEDIU(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),

                         CASE
                           WHEN V_REC.LOCALITATE IS NOT NULL THEN
                             GETLOCALITSEDIU_EXT(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA)
                           ELSE
                             NULL
                          END,
                         V_REC.CONTBANCA,
                         V_REC.SUCURSALA,
                         V_REC.CODSWIFT,
                         GETCODMONEDA(TRIM(V_REC.SIMBOLMONEDA))
                       );
    ELSE
      UPDATE NPARTB
      SET
      ( CODBANK,
        IMPLICIT,
        CODLOCALIT,
        CONTBANCA,
        SUCURSALA,
        CODSWIFT,
        CODMONEDA
       )


       =   ( SELECT GETCODBANCA(V_REC.SIMBOLBANCA, V_REC.DENBANCA),
                    V_REC.FACTURARE,
--                  GETLOCALITSEDIU(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                    GETLOCALITSEDIU_EXT(V_REC.LOCALITATE, V_REC.JUDET, V_REC.TARA),
                    V_REC.CONTBANCA,
                    V_REC.SUCURSALA,
                    V_REC.CODSWIFT,
                    GETCODMONEDA(V_REC.SIMBOLMONEDA)
             FROM
              DUAL
           )
      WHERE
        CODPARTB = NR;
    END IF;
  END LOOP;


-- NPARTTR
  FOR V_REC IN (SELECT * FROM TMP_NPARTTR_IMPORT WHERE DELEGAT IS NOT NULL)
  LOOP
    BEGIN
      SELECT CODPARTTR INTO NR FROM
       NPARTTR A
      WHERE
        A.CODPART = V_REC.CODPART
        AND NVL(A.DELEGAT, &apos; &apos;) = NVL(V_REC.DELEGAT, &apos; &apos;)
        AND NVL(A.CNP, &apos; &apos;) = NVL(V_REC.CNP, &apos; &apos;)
        AND NVL(A.NRTRANSP, &apos; &apos;) = NVL(V_REC.NRTRANSP, &apos; &apos;);
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN
      INSERT INTO NPARTTR(
                         CODPARTTR,
                         CODPART,
                         DELEGAT,
                         CNP,
                         DOC,
                         SERIEDOC,
                         NRDOC,
                         ELIBERAT,
                         MIJLTRANSP,
                         NRTRANSP,
                         ACTIV
                         )

                 VALUES(SEQ_NPARTTR_CODPARTTR.NEXTVAL,
                        V_REC.CODPART,
                        V_REC.DELEGAT,
                        V_REC.CNP,
                        V_REC.DOC,
                        V_REC.SERIEDOC,
                        V_REC.NRDOC,
                        V_REC.ELIBERAT,
                        V_REC.MIJLTRANSP,
                        V_REC.NRTRANSP,
                        1
                       );
    ELSE
      UPDATE NPARTTR
      SET
      (
         DELEGAT,
         CNP,
         DOC,
         SERIEDOC,
         NRDOC,
         ELIBERAT,
         MIJLTRANSP,
         NRTRANSP
       )
       =   (SELECT
              V_REC.DELEGAT,
              V_REC.CNP,
              V_REC.DOC,
              V_REC.SERIEDOC,
              V_REC.NRDOC,
              V_REC.ELIBERAT,
              V_REC.MIJLTRANSP,
              V_REC.NRTRANSP
            FROM
              DUAL
           )
      WHERE
        CODPART = V_REC.CODPART
        AND NVL(DELEGAT, &apos; &apos;) = NVL(V_REC.DELEGAT, &apos; &apos;)
        AND NVL(CNP, &apos; &apos;) = NVL(V_REC.CNP, &apos; &apos;)
        AND NVL(NRTRANSP, &apos; &apos;) = NVL(V_REC.NRTRANSP, &apos; &apos;);
    END IF;


  END LOOP;




  COMMIT;
END;

end PKG_IMPORT_PART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_INCHIDERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>918F4724E6B489C4C39AE63C5A5FEA3370C9F243</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_INCHIDERI IS

  pGAMOMF_AL                    NUMBER(5);
  pGAMOMF_VALIMBNEXTLUNA_Const1 NUMBER(20);
  pGAMOMF_VALIMBNEXTLUNA_UserID NUMBER(20);
  pGAMOMF_VALIMBNEXTLUNA        NUMBER;

PROCEDURE TEST IS
  xAMO NUMBER(20, 7);
BEGIN
 --pkg_globals.setlunaprecedenta(2017, 8);
-- pkg_globals.setlunatemp(2017, 9);
-- PKG_INCHIDERI.MAKE_CHELTAVANS;
  xAMO := pkg_inchideri.AMORTIZARELUNARA(101, 2022, 5);
END;

PROCEDURE TEST_MIFIX IS
BEGIN
 pkg_globals.setlunaprecedenta(2023, 6);
 pkg_globals.setlunatemp(2023, 7);
 PKG_INCHIDERI.MAKE_MIFIX;
END;

FUNCTION SIMULARE_AMORTIZARELUNARA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
 AMOLUNA      NUMBER(20, 7) := 0;
 xAMO         NUMBER(20, 7) := 0;
 xNEUTIL      NUMBER(20, 7) := 0;
 xDURATAF     NUMBER(20, 7) := 0;
 xDURATAN     NUMBER(20, 7) := 0;
 xGRADU       NUMBER(20, 7) := 0;
 xPRET        NUMBER(20, 7) := 0;
 xCANT        NUMBER(20, 7) := 0;
 xANINTRARE   NUMBER(5)     := 0;
 xLUNAINTRARE NUMBER(5)     := 0;
 xTIPAMO      NUMBER(5)     := 0;
 XTIP         VARCHAR(2)    := &apos;&apos;;
 XDATAREEVAL  DATE;
 XAMOVECHI    NUMBER(20, 7) := 0;
 XPRETVECHI   NUMBER(20, 7) := 0;
 XTIPREEVAL   NUMBER(5)    := 0;
 XINCLUDRATA  NUMBER(5)    := 0;
 AN1          NUMBER(5);
 LUNA1        NUMBER(2);
 CODNIRSTOC_Y NUMBER(20);
 PRET_Y       NUMBER(20, 7);
 XCODNIRSTOC  NUMBER(20);

 AN_NIR       NUMBER(5);
 LUNA_NIR     NUMBER(2);
BEGIN
  BEGIN
    SELECT
      NVL(AMO, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAF, 0),
      NVL(PRET, 0),
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0),
      NVL(TIPAMO, 0),
      NVL(DURATAN, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA,
      CODNIRSTOC
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA,
      XCODNIRSTOC
    FROM
      MIFIX1_SIMULARE M1, MIFIX_SIMULARE M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF XDATAREEVAL IS NOT NULL THEN
    IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
      XAMO  := XAMOVECHI;
      XPRET := XPRETVECHI;
    END IF;
  ELSE
    IF NVL(pkg_categconst.GetValConstanta(&apos;VALIMBNEXTLUNA&apos;,Pkg_Globals.GetAnLucru, Pkg_Globals.GetLunaLucru), 0) = 1 THEN
--    verific daca nu sunt imbunatariri in luna respectiva si trebuie sa pastrez valoarea anterioara imbunatatirii
      BEGIN
         PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AN, LUNA, AN1, LUNA1);
         SELECT Case when P.CODMIFIX is Null then N.CODNIRSTOCORIG else P.CODNIRSTOC end ,
                Case when P.CODMIFIX is Null then N.PRETMAT        else P.PRET end
         INTO
           CODNIRSTOC_Y,
           PRET_Y
         FROM  MIFIX1_SIMULARE M1
         left join MIFIX1_SIMULARE P on P.CodMifix = M1.CodMifix  AND P.ANSTART * 12 + P.LUNASTART = AN1 * 12 + LUNA1
         inner join NIRSTOC1 N  on N.CODNIRSTOC = M1.CODNIRSTOC
         where M1.CODMIFIX = ACODMIFIX AND M1.ANSTART * 12 + M1.LUNASTART = AN1 * 12 + LUNA1 + 1;
         EXCEPTION WHEN OTHERS THEN CODNIRSTOC_Y := 0; PRET_Y := 0;
      END;
      IF CODNIRSTOC_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; xPRET AND CODNIRSTOC_Y &lt;&gt; XCODNIRSTOC THEN
        BEGIN
          SELECT T.AN, T.LUNA INTO AN_NIR, LUNA_NIR FROM NIR N, NIRSTOC NS, TRANSF T  WHERE NS.CODNIRSTOC = XCODNIRSTOC AND N.CODNIR = NS.CODNIR AND N.TIPNIR = 13 AND N.CODTRANSF = T.CODTRANSF;
          EXCEPTION WHEN OTHERS THEN BEGIN
             AN_NIR   := 0;
             LUNA_NIR := 0;
          END;
        END;
        IF AN_NIR = AN AND LUNA_NIR = LUNA THEN -- modificare de pret in luna curenta
          XPRET := PRET_Y;
        END IF;
      END IF;
    END IF;
  END IF;

  IF XDURATAF = 0 THEN AMOLUNA := 0;
                  ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
  END IF;
  RETURN AMOLUNA;
END;

FUNCTION SIMULARE_AMORTIZARELUNARA_F(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  xAMO         NUMBER(20, 7) := 0;
  xNEUTIL      NUMBER(20, 7) := 0;
  xDURATAF     NUMBER(20, 7) := 0;
  xDURATAN     NUMBER(20, 7) := 0;
  xGRADU       NUMBER(20, 7) := 0;
  xPRET        NUMBER(20, 7) := 0;
  xCANT        NUMBER(20, 7) := 0;
  xANINTRARE   NUMBER(5)     := 0;
  xLUNAINTRARE NUMBER(5)     := 0;
  xTIPAMO      NUMBER(5)     := 0;
  XTIP         VARCHAR(2)    := &apos;&apos;;
  XDATAREEVAL  DATE;
  XAMOVECHI    NUMBER(20, 7) := 0;
  XPRETVECHI   NUMBER(20, 7) := 0;
  XTIPREEVAL   NUMBER(5)     := 0;
  XINCLUDRATA  NUMBER(5)     := 0;
BEGIN
  BEGIN
    SELECT
      NVL(AMOF, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAFF, 0),
      NVL(PRET, 0),
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0),
      NVL(TIPAMO, 0),
      NVL(DURATANF, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA
    FROM
      MIFIX1_SIMULARE M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF XDATAREEVAL IS NOT NULL THEN
    IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
      XAMO  := XAMOVECHI;
      XPRET := XPRETVECHI;
    END IF;
  END IF;

  IF XDURATAF = 0 THEN AMOLUNA := 0;
                  ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
  END IF;
  RETURN AMOLUNA;
END;

FUNCTION SIMULARE_AMORTIZARELUNARA_G(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
 AMOLUNA      NUMBER(20, 7) := 0;
 xAMO         NUMBER(20, 7) := 0;
 xNEUTIL      NUMBER(20, 7) := 0;
 xDURATAF     NUMBER(20, 7) := 0;
 xDURATAN     NUMBER(20, 7) := 0;
 xGRADU       NUMBER(20, 7) := 0;
 xPRET        NUMBER(20, 7) := 0;
 xCANT        NUMBER(20, 7) := 0;
 xANINTRARE   NUMBER(5)     := 0;
 xLUNAINTRARE NUMBER(5)     := 0;
 xTIPAMO      NUMBER(5)     := 0;
 XTIP         VARCHAR(2)    := &apos;&apos;;
 XDATAREEVAL  DATE;
 XAMOVECHI    NUMBER(20, 7) := 0;
 XPRETVECHI   NUMBER(20, 7) := 0;
 XTIPREEVAL   NUMBER(5)    := 0;
 XINCLUDRATA  NUMBER(5)    := 0;
BEGIN
  BEGIN
    SELECT
      NVL(AMOG, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAFG, 0),
      CASE
        WHEN NVL(PRETINITIAL, 0) = 0 THEN NVL(PRET, 0)
        ELSE NVL(PRETINITIAL, 0)
      END,
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRAREG, 0),
      NVL(LUNAINTRAREG, 0),
      NVL(TIPAMO, 0),
      NVL(DURATANG, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA
    FROM
      MIFIX1_SIMULARE M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF XDATAREEVAL IS NOT NULL THEN
    IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
      XAMO  := XAMOVECHI;
      XPRET := XPRETVECHI;
    END IF;
  END IF;

  IF XDURATAF = 0 THEN AMOLUNA := 0;
                  ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
  END IF;
  RETURN AMOLUNA;
END;

PROCEDURE DO_SIMULARE_MIFIX (simCodMifix1 IN OUT NUMBER)
IS
  NR                NUMERIC(10)    := 0;
  RATALUNA          NUMERIC(20, 7) := 0;
  RATALUNA_F        NUMERIC(20, 7) := 0;
  RATALUNA_G        NUMERIC(20, 7) := 0;
  RATALUNA_REZERVA  NUMERIC(20, 7) := 0;

  STAREPREC      NUMERIC(20, 7) := 0;
  STARECURENTA   NUMERIC(20, 7) := 0;
  DURATAFPREC    NUMERIC(20, 7) := 0;
  AMOPREC        NUMERIC(20, 7) := 0;
  aANINI         NUMERIC(10)    := 0;
  aLUNAINI       NUMERIC(10)    := 0;
  OLDSTARE       NUMERIC(10)    := 0;
  aCODCENTRU     NUMERIC(20)    := 0;
  aCODSABLON     NUMERIC(20)    := 0;
  aCODPERS       NUMERIC(20)    := 0;
  aCODANALIZANOD NUMERIC(20)    := 0;
  aCodClasif     NUMBER(20);

  DURATAFPREC_F  NUMERIC(20, 7) := 0;
  AMOPREC_F      NUMERIC(20, 7) := 0;

  DURATAFPREC_G  NUMERIC(20, 7) := 0;
  AMOPREC_G      NUMERIC(20, 7) := 0;
  aPRETAMOGRUP   NUMERIC(20, 7) := 0;

  AMOPREC_REZERVA NUMERIC(20, 7) := 0;

  ADATAREEVAL    DATE := NULL;
  APRETVECHI     NUMERIC(20, 7) := 0;
  AAMOVECHI      NUMERIC(20, 7) := 0;
  AREZERVAVECHE  NUMERIC(20, 7) := 0;
  APRETPREC      NUMERIC(20, 7) := 0;
  AAMOPREC       NUMERIC(20, 7) := 0;
  ATIPREEVAL     NUMBER(1)      := NULL;
  aUseRezerve    Varchar(2);
  aCODMIFIX1     NUMBER(20);
  aCODAUTO       NUMERIC(20)    := 0;
  CREZREPORT     NUMBER(20);
  PRETINI_PREC   NUMERIC(20, 7) := 0;
  vAnPrec        NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec      NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp        NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp      NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  -- PROPAG INREGISTRARI DIN LUNAPRECDEDENTA IN LUNA TEMP
  BEGIN
    SELECT NVL(pkg_categconst.GetValConstanta(&apos;CRezReport&apos;, vAnTemp, vLunaTemp), 0) INTO CREZREPORT  FROM DUAL;
  EXCEPTION
    WHEN OTHERS THEN CREZREPORT := 0;
  END;

  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO aANINI, aLUNAINI FROM FIRMALUNI;
  EXCEPTION
    WHEN OTHERS THEN aANINI := 0;
  END;

  PKG_INCHIDERI.MAKE_STOC_LUNA_EXT;
  FOR V_REC IN (
    --bag in join si MIFIX_SIMULARE ca sa elimin eventuiale incoerente MIFIX1_SIMULARE-MIFIX_SIMULARE
    SELECT M1.*
    FROM MIFIX1_SIMULARE M1 INNER JOIN MIFIX_SIMULARE M ON M.CODMIFIX = M1.CODMIFIX
    WHERE M1.ANSTART = vAnPrec AND M1.LUNASTART = vLunaPrec
      AND M1.STARE IN (1, 2, 5)
  ) LOOP
    SELECT COUNT(*) INTO NR FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    IF NR = 0 THEN
      simCodMifix1 := simCodMifix1 + 1;

      INSERT INTO MIFIX1_SIMULARE (
        CODMIFIX1, CODMIFIX, CODNIRSTOC, PRET, CANT, CODCLASIF, TIPAMO, STARE, DURATAN, GRADU, DURATAF, AMO,
        NEUTIL, DFBLOCAT, CODPERS, CODNIRSER, ANSTART, LUNASTART, CODPART, CODLOCATIE, CODCENTRU, DURATANF, DURATANG,
        DURATAFF, DURATAFG, AMOF, AMOG, PRETINITIAL, REZERVA, CODSABLON, CODANALIZANOD
      )
      VALUES (
        simCodMifix1, V_REC.CODMIFIX, V_REC.CODNIRSTOC, V_REC.PRET, V_REC.CANT, V_REC.CODCLASIF, V_REC.TIPAMO, V_REC.STARE, V_REC.DURATAN, V_REC.GRADU, V_REC.DURATAF, V_REC.AMO,
        V_REC.NEUTIL, 0, V_REC.CODPERS, V_REC.CODNIRSER, vAnTemp, vLunaTemp, V_REC.CODPART, V_REC.CODLOCATIE, V_REC.CODCENTRU, V_REC.DURATANF, V_REC.DURATANG,
        V_REC.DURATAFF, V_REC.DURATAFG, V_REC.AMOF, V_REC.AMOG, V_REC.PRETINITIAL, NVL(V_REC.REZERVA, 0), NVL(V_REC.CODSABLON, 0), V_REC.CODANALIZANOD
      );
    ELSE
      UPDATE MIFIX1_SIMULARE
      SET DURATAF = V_REC.DURATAF
      WHERE CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT, 0) = 0;

      UPDATE MIFIX1_SIMULARE
      SET DURATAFF = V_REC.DURATAFF
      WHERE CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT_F, 0) = 0;

      UPDATE MIFIX1_SIMULARE
      SET DURATAFG = V_REC.DURATAFG
      WHERE CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT_G, 0) = 0;

      UPDATE MIFIX1_SIMULARE
      SET REZERVA = V_REC.REZERVA
      WHERE CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(REZERVABLOCAT, 0) = 0;
    END IF;
  END LOOP;

  -- VERIFIC DACA IN NOUA LUNA NU AM MIJLOACE FIXE CASATE SAU VANDUTE PENTRU A LE STERGE
  FOR V_REC IN (SELECT * FROM MIFIX1_SIMULARE WHERE ANSTART = vAnPrec AND LUNASTART = vLunaPrec AND STARE IN (3, 4, 6, 7, 8))
  LOOP
    DELETE FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
  END LOOP;

   -- STERG DIN LUNA CURENTA POZITIILE VANDUTE SAU CASATE INTR_O LUNA MAI VECHE
  FOR V_REC IN (SELECT * FROM MIFIX1_SIMULARE WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
  LOOP
    BEGIN
      SELECT STARE INTO OLDSTARE FROM MIFIX1_SIMULARE M1
      WHERE CODMIFIX = V_REC.CODMIFIX
        AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp
        AND ANSTART * 12 + LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp);
    EXCEPTION
      WHEN OTHERS THEN OLDSTARE := 0;
    END;

    IF OLDSTARE IN (3, 4, 6, 7, 8) THEN
      DELETE FROM MIFIX1_SIMULARE WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;
 END LOOP;

  -- LA OBIECTE DE INVENTAR UNDE POT AVEA CANT &gt; 0 POSIBIL IN LUNA ANTERIOARA SA FI CASAT/ VANDUT IAR LUNA CURENTE NU REFLECTA MODIFICAREA
  FOR V_REC IN (
    SELECT ANAL.*, NL.REST
    FROM (
      SELECT M1.CODNIRSTOC, COUNT(*) AS NR, SUM(M1.CANT) AS CANT
      FROM MIFIX1_SIMULARE M1, MIFIX_SIMULARE M
      WHERE M.CODMIFIX = M1.CODMIFIX
        AND M1.ANSTART  = vAnTemp
        AND M1.LUNASTART = vLunaTemp
        AND M1.STARE IN (1, 2)
        AND M.TIP = &apos;OI&apos;
      GROUP BY M1.CODNIRSTOC
    ) ANAL, NIRLUNA NL
    WHERE ANAL.CODNIRSTOC = NL.CODNIRSTOC
      AND NL.AN = vAnTemp
      AND NL.LUNA = vLunaTemp
      AND ANAL.NR = 1
      AND ANAL.CANT &gt; NL.REST
  ) LOOP
    BEGIN
      SELECT CODMIFIX1 INTO aCODMIFIX1
      FROM MIFIX1_SIMULARE
      WHERE CODNIRSTOC = V_REC.CODNIRSTOC
        AND ANSTART    = vAnTemp
        AND LUNASTART  = vLunaTemp
        AND STARE IN (1, 2);
    EXCEPTION
      WHEN OTHERS THEN aCODMIFIX1 := 0;
    END;
    IF aCODMIFIX1 &gt; 0 THEN
      UPDATE MIFIX1_SIMULARE
      SET CANT = V_REC.REST
      WHERE CODMIFIX1 = aCODMIFIX1;
    END IF;
  END LOOP;

  -- RECALCULEZ AMO, NEUTIL, DURATAF IN LUNA DE LUCRU;
  FOR V_REC IN (
    SELECT M1.*, M.ANINTRARE, M.LUNAINTRARE, M.ANINTRAREG, M.LUNAINTRAREG
    FROM MIFIX1_SIMULARE M1 LEFT OUTER JOIN MIFIX_SIMULARE M ON M.CODMIFIX = M1.CODMIFIX
    WHERE STARE IN (1 , 2) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND DATAREEVAL IS NULL
  ) LOOP
    RATALUNA         := SIMULARE_AMORTIZARELUNARA   (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    RATALUNA_REZERVA := 0;
    IF CREZREPORT &lt;&gt; 0 THEN
      RATALUNA_REZERVA := AMORTIZARELUNARA_REZERVA   (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    END IF;

    RATALUNA_F       := SIMULARE_AMORTIZARELUNARA_F (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    RATALUNA_G       := SIMULARE_AMORTIZARELUNARA_G (V_REC.CODMIFIX, vAnPrec, vLunaPrec);

    BEGIN
      SELECT STARE, AMO, DURATAF, AMOF, DURATAFF, AMOG, DURATAFG, AMOREZERVA, PRETINITIAL
      INTO STAREPREC, AMOPREC, DURATAFPREC, AMOPREC_F, DURATAFPREC_F, AMOPREC_G, DURATAFPREC_G,
      AMOPREC_REZERVA, PRETINI_PREC
      FROM MIFIX1_SIMULARE
      WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
    EXCEPTION WHEN OTHERS THEN
      STAREPREC := 0;
      AMOPREC   := 0;
      AMOPREC_F := 0;
      AMOPREC_G := 0;
      PRETINI_PREC := 0;
      AMOPREC_REZERVA   := 0;
    END;

    IF RATALUNA &lt;&gt; 0 THEN
      IF V_REC.PRET &gt;= 0 THEN
        IF RATALUNA &lt;&gt; 0 AND abs(AMOPREC + RATALUNA) &gt; abs(V_REC.PRET * V_REC.CANT) THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        END IF;
      ELSE -- pret negativ rata pozitiva sau negativa
        IF RATALUNA &gt; 0 AND AMOPREC + RATALUNA &gt; V_REC.PRET * V_REC.CANT THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        ELSE
        IF RATALUNA &lt; 0  AND AMOPREC + RATALUNA &lt; V_REC.PRET * V_REC.CANT THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        END IF;
        END IF;
      END IF;
    END IF;

    IF RATALUNA_F &lt;&gt; 0 AND AMOPREC_F + RATALUNA_F &gt; V_REC.PRET * V_REC.CANT THEN
      RATALUNA_F := V_REC.PRET * V_REC.CANT - AMOPREC_F;
    END IF;

    IF RATALUNA_REZERVA &lt;&gt; 0 AND AMOPREC_REZERVA + RATALUNA_REZERVA &gt; V_REC.REZERVA THEN
      RATALUNA_REZERVA := V_REC.REZERVA - AMOPREC_REZERVA;
    END IF;

    IF NVL(V_REC.PRETINITIAL, 0) &lt;&gt; 0
      THEN aPRETAMOGRUP := V_REC.PRETINITIAL;
      ELSE aPRETAMOGRUP := V_REC.PRET;
    END IF;

    IF RATALUNA_G &lt;&gt; 0 AND AMOPREC_G + RATALUNA_G &gt; /*V_REC.PRET*/aPRETAMOGRUP * V_REC.CANT THEN
      RATALUNA_G := /*V_REC.PRET */ aPRETAMOGRUP * V_REC.CANT - AMOPREC_G;
    END IF;

    BEGIN
      SELECT STARE INTO STARECURENTA FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
      EXCEPTION WHEN OTHERS THEN STARECURENTA := 0;
    END;

    IF STAREPREC = 2 THEN
      UPDATE MIFIX1_SIMULARE M1
      SET AMO        = CASE WHEN NVL(V_REC.AMOBLOCAT, 0) = 1 THEN AMO ELSE AMOPREC END,
          AMOREZERVA = CASE WHEN NVL(V_REC.AMORBLOCAT, 0) = 1 THEN AMOREZERVA ELSE AMOPREC_REZERVA END,
          AMOF       = CASE WHEN NVL(V_REC.AMOFBLOCAT, 0) = 1 THEN AMOF ELSE AMOPREC_F END,
          AMOG       = CASE WHEN NVL(V_REC.AMOGBLOCAT, 0) = 1 THEN AMOG ELSE AMOPREC_G END,
          DURATAF    = CASE WHEN DFBLOCAT = 1 THEN DURATAF ELSE DURATAFPREC END,
          DURATAFF   = CASE WHEN DFBLOCAT_F = 1 THEN DURATAFF ELSE DURATAFPREC_F END,
          DURATAFG   = CASE WHEN DFBLOCAT_G = 1 THEN DURATAFG ELSE DURATAFPREC_G END
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    ELSE
      UPDATE MIFIX1_SIMULARE M1
      SET AMO        = CASE
                         WHEN NVL(V_REC.AMOBLOCAT, 0) = 1 THEN AMO
                         WHEN (SELECT NVL(TIPREEVAL, 0) FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) = 1 THEN 0
                         WHEN PRET &gt; 0 AND (SELECT ABS(NVL(AMO, 0) + RATALUNA) /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= ABS(PRET * CANT) AND STARE = 1
                         THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         WHEN PRET  &lt; 0 AND RATALUNA &gt; 0 AND (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= PRET * CANT AND STARE = 1
                         THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         WHEN PRET  &lt; 0 AND RATALUNA &lt; 0 AND (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &gt;= PRET * CANT AND STARE = 1
                         THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE AMO
                       END,
          AMOREZERVA = CASE
                         WHEN NVL(V_REC.AMORBLOCAT, 0) = 1 THEN AMOREZERVA
                         WHEN (SELECT NVL(AMOREZERVA, 0) + RATALUNA_REZERVA FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= REZERVA AND STARE = 1
                         THEN (SELECT NVL(AMOREZERVA, 0) + RATALUNA_REZERVA FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE AMOREZERVA
                       END,
           AMOF     =  CASE
                         WHEN NVL(V_REC.AMOFBLOCAT, 0) = 1 THEN AMOF
                         WHEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= PRET * CANT AND STARE = 1
                         THEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE AMOF
                       END,
           AMOG     =  CASE
                         WHEN NVL(V_REC.AMOGBLOCAT, 0) = 1 THEN AMOG
                          WHEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= DECODE(NVL(PRETINITIAL, 0), 0, PRET, NVL(PRETINITIAL, 0))  /*PRET*/ * CANT AND STARE = 1
                          THEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOG
                       END
         WHERE CODMIFIX1 = V_REC.CODMIFIX1;

      IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRARE * 12 + V_REC.LUNAINTRARE)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI) THEN
        UPDATE MIFIX1_SIMULARE M1
        SET DURATAF  = CASE
                         WHEN DURATAF &gt; 0 AND DFBLOCAT = 1 THEN DURATAF
                         WHEN DURATAF &gt; 0 THEN (SELECT NVL(DURATAF, M1.DURATAF) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE 0
                       END,
            DURATAFF = CASE
                         WHEN DURATAFF &gt; 0 AND DFBLOCAT_F = 1 THEN DURATAFF
                         WHEN DURATAFF &gt; 0 THEN (SELECT NVL(DURATAFF, M1.DURATAFF) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE 0
                       END
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      END IF;

      --DURATAFG
      IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRAREG * 12 + V_REC.LUNAINTRAREG)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI) THEN
        UPDATE MIFIX1_SIMULARE M1
        SET DURATAFG = CASE
                         WHEN DURATAFG &gt; 0 AND DFBLOCAT_G = 1 THEN DURATAFG
                         WHEN DURATAFG &gt; 0 THEN (SELECT NVL(DURATAFG, M1.DURATAFG) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE 0
                       END
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      ELSE
        UPDATE MIFIX1_SIMULARE M1
        SET DURATAFG = (SELECT NVL(DURATAFG, M1.DURATAFG) FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      END IF;
    END IF;
  END LOOP;

  -- RECALCUL DURATE LA REVALUATE
  FOR V_REC IN (
    SELECT M1.*, M.ANINTRARE, M.LUNAINTRARE, M.ANINTRAREG, M.LUNAINTRAREG FROM MIFIX1_SIMULARE M1 LEFT OUTER JOIN MIFIX_SIMULARE M ON M.CODMIFIX = M1.CODMIFIX
    WHERE STARE IN (1 , 2) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND DATAREEVAL IS NOT NULL
  ) LOOP
    BEGIN
      SELECT STARE, AMO, DURATAF, AMOF, DURATAFF, AMOG, DURATAFG
      INTO STAREPREC, AMOPREC, DURATAFPREC, AMOPREC_F, DURATAFPREC_F, AMOPREC_G, DURATAFPREC_G
      FROM MIFIX1_SIMULARE
      WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
    EXCEPTION WHEN OTHERS THEN
      STAREPREC := 0;
      AMOPREC   := 0;
      AMOPREC_F := 0;
      AMOPREC_G := 0;
    END;

    BEGIN
      SELECT STARE INTO STARECURENTA FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    EXCEPTION WHEN OTHERS THEN
      STARECURENTA := 0;
    END;

    IF STAREPREC = 2 THEN
      UPDATE MIFIX1_SIMULARE M1
      SET
        DURATAF  = CASE WHEN DFBLOCAT = 1 THEN DURATAF ELSE DURATAFPREC END,
        DURATAFF = CASE WHEN DFBLOCAT_F = 1 THEN DURATAFF ELSE DURATAFPREC_F END,
        DURATAFG = CASE WHEN DFBLOCAT_G = 1 THEN DURATAFG ELSE DURATAFPREC_G END
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    ELSE
      IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRARE * 12 + V_REC.LUNAINTRARE)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI) THEN
        UPDATE MIFIX1_SIMULARE M1
        SET
          DURATAF  = CASE
                       WHEN DURATAF &gt; 0 AND DFBLOCAT = 1 THEN DURATAF
                       WHEN DURATAF &gt; 0 THEN (SELECT NVL(DURATAF, M1.DURATAF) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                       ELSE 0
                     END,
          DURATAFF = CASE
                       WHEN DURATAFF &gt; 0 AND DFBLOCAT_F = 1 THEN DURATAFF
                       WHEN DURATAFF &gt; 0 THEN (SELECT NVL(DURATAFF, M1.DURATAFF) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                       ELSE 0
                     END
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      END IF;

      --DURATAFG
      IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRAREG * 12 + V_REC.LUNAINTRAREG)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI) THEN
        UPDATE MIFIX1_SIMULARE M1
        SET DURATAFG = CASE
                         WHEN DURATAFG &gt; 0 AND DFBLOCAT_G = 1 THEN DURATAFG
                         WHEN DURATAFG &gt; 0 THEN (SELECT NVL(DURATAFG, M1.DURATAFG) - 1 FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                         ELSE 0
                       END
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      ELSE
        UPDATE MIFIX1_SIMULARE M1
        SET DURATAFG = (SELECT NVL(DURATAFG, M1.DURATAFG) FROM MIFIX1_SIMULARE WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
        WHERE CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
      END IF;
    END IF;
  END LOOP;

  -- CODCENTRU a aparut
  FOR V_REC IN (
    SELECT *
    FROM MIFIX1_SIMULARE
    WHERE (NVL(CODCENTRU, 0) = 0 OR NVL(CODSABLON, 0) = 0 OR NVL(CODANALIZANOD, 0) = 0 OR NVL(CODPERS, 0) = 0) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp
  ) LOOP
    BEGIN
      SELECT CODCENTRU, CODSABLON, CODANALIZANOD, CODPERS, CODCLASIF, CODAUTO INTO aCODCENTRU, aCODSABLON, aCODANALIZANOD, aCODPERS, aCODCLASIF, aCODAUTO
      FROM MIFIX1_SIMULARE
      WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
    EXCEPTION WHEN OTHERS THEN
      aCODCENTRU := 0; aCODSABLON :=0; aCODANALIZANOD := 0; aCodPers := 0; aCodClasif := 0; aCodAuto := 0;
    END;

    IF aCODCLASIF = 0 THEN
      BEGIN
        SELECT CODCLASIF INTO aCODCLASIF FROM MASTERMIFIX MF WHERE MF.CODNIRSTOC = V_REC.CODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN
        aCODCLASIF := 0;
      END;
    END IF;

    IF (NVL(aCODCENTRU, 0) &lt;&gt; 0)AND(NVL(V_REC.CENTRUBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1_SIMULARE
      SET CODCENTRU = aCODCENTRU
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF (NVL(aCODAUTO, 0) &lt;&gt; 0) THEN
      UPDATE MIFIX1_SIMULARE
      SET CODAUTO = aCODAUTO
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF (NVL(aCODCLASIF, 0) &lt;&gt; 0)AND(NVL(V_REC.CODCLASIFBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1_SIMULARE
      SET CODCLASIF = aCODCLASIF
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF NVL(aCODSABLON, 0) &lt;&gt; 0 THEN
      UPDATE MIFIX1_SIMULARE
      SET CODSABLON = aCODSABLON
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF NVL(aCODANALIZANOD, 0) &lt;&gt; 0 AND(NVL(V_REC.NODANALIZABLOCAT, 0) = 0) THEN
      UPDATE MIFIX1_SIMULARE
      SET CODANALIZANOD = aCODANALIZANOD
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF NVL(aCODPers, 0) &lt;&gt; 0  AND(NVL(V_REC.CODPERSBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1_SIMULARE
      SET CODPERS = aCODPERS
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;
  END LOOP;

  BEGIN
    SELECT NVL(pkg_categconst.GetValConstanta(&apos;UseRezervaReev&apos;, vAnTemp, vLunaTemp), &apos;0&apos;) INTO aUseRezerve from dual;
    EXCEPTION WHEN OTHERS THEN aUseRezerve := &apos;0&apos;;
  END;

  FOR V_REC IN (SELECT * FROM MIFIX1_SIMULARE WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
  LOOP
    BEGIN
      SELECT DATAREEVAL, NVL(PRETVECHI,0), NVL(AMOVECHI, 0), NVL(REZERVA, 0), NVL(PRET,0), NVL(AMO, 0) , NVL(TIPREEVAL, 0), NVL(DURATAF, 0)
      INTO ADATAREEVAL, APRETVECHI, AAMOVECHI, AREZERVAVECHE, APRETPREC, AAMOPREC, ATIPREEVAL, DURATAFPREC
      FROM MIFIX1_SIMULARE
      WHERE CODMIFIX      = V_REC.CODMIFIX
        AND ANSTART   = vAnPrec
        AND LUNASTART = vLunaPrec;
    EXCEPTION WHEN OTHERS THEN
      ADATAREEVAL := NULL; APRETVECHI := 0; AAMOVECHI := 0; AREZERVAVECHE := 0; APRETPREC := 0; AAMOPREC := 0;
    END;

    IF (NVL(aUseRezerve, &apos;0&apos;)=&apos;1&apos;)and(aDATAREEVAL IS NOT NULL) THEN
      UPDATE MIFIX1_SIMULARE
      SET REZERVA =  CASE
                       WHEN aTIPREEVAL = 0 THEN NVL(AREZERVAVECHE, 0) + (APRETPREC  - AAMOPREC) - (APRETVECHI - AAMOVECHI)
                       WHEN NVL(DURATAFPREC, 0) &lt;&gt; 0 THEN NVL(AREZERVAVECHE, 0) + APRETPREC   - (APRETVECHI - AAMOVECHI - (aPRETVECHI - aAMOVECHI) / DURATAFPREC )
                       ELSE NULL
                     END
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM MIFIX1_SIMULARE WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND DURATAF &lt; 0)
  LOOP
    UPDATE MIFIX1_SIMULARE
    SET DURATAF = 0
    WHERE CODMIFIX1 = V_REC.CODMIFIX1;
  END LOOP;

  COMMIT;
END;

PROCEDURE SIMULARE_AMORTIZARI(aANLUCRU IN NUMBER,
                              aLUNALUCRU IN NUMBER,
                              aANANALIZA IN NUMBER,
                              aLUNAANALIZA IN NUMBER)
IS
  aANP         NUMBER;
  aLUNAP       NUMBER;
  aANTEMP      NUMBER;
  aLUNATEMP    NUMBER;
  simCodMifix1 NUMBER;
BEGIN
  SELECT Coalesce(Max(CodMifix1), 100)
  INTO simCodMifix1
  FROM Mifix1;

  DELETE MIFIX_SIMULARE;
  INSERT INTO MIFIX_SIMULARE SELECT * FROM MIFIX WHERE TIP = &apos;MF&apos;;

  DELETE MIFIX1_SIMULARE;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(aANLUCRU, aLUNALUCRU, aANP, aLUNAP);

  INSERT INTO MIFIX1_SIMULARE
  SELECT M1.*
  FROM MIFIX1 M1 INNER JOIN MIFIX M ON M1.CODMIFIX = M.CODMIFIX
  WHERE M1.ANSTART = aANP
    AND M1.LUNASTART = aLUNAP
    AND M.TIP = &apos;MF&apos;;

  aANTEMP   := aANLUCRU;
  aLUNATEMP := aLUNALUCRU;

  WHILE aANTEMP * 12 + aLUNATEMP &lt;= aANANALIZA * 12 + aLUNAANALIZA
  LOOP
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(aANTEMP, aLUNATEMP, aANP, aLUNAP);
    PKG_GLOBALS.SetLunaPRECEDENTA(aANP, aLUNAP);
    PKG_GLOBALS.SetLunaTEMP(aANTEMP, aLUNATEMP);
    DO_SIMULARE_MIFIX(simCodMifix1);
    PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(aANTEMP, aLUNATEMP, aANTEMP, aLUNATEMP);
  END LOOP;
  COMMIT;
END;

PROCEDURE MAKE_JurnalStingereTVA IS
BEGIN
  delete from TMP_JURNAL1;
  MAKE_TMP_StingereTVADed;
  MAKE_TMP_StingereTVACole;
  MAKE_TMP_InchidereTVACole;
  PKG_Jurnal.DO_JURNS_DIN_TMP_JURNAL1(81);
END;

FUNCTION CalcTVADed( TipTVA in number, TVANeded in number, ProRata in number, ValTVAExtern in number) return number
is
  ValTVANeded number;
  KProRata    number;
begin
   ValTVANeded := 0;
   KProRata    := 0;
   if TipTVA in (2,3) then
     Return ValTVAExtern;
   else
     if (TipTVA = 4)and(ProRata &lt;&gt; 0) then KProRata := 1.0 - ProRata/100.0; end if;
     if TVANeded = 0 then
       if TipTVA = 4 then ValTVANeded := ValTVAExtern * KProRata; end if;
     elsif TVANeded = 1 then ValTVANeded := ValTVAExtern;
     elsif TVANeded = 2 then ValTVANeded := ValTVAExtern * KProRata;
     elsif TVANeded = 3 then
       ValTVANeded := ValTVAExtern * 0.5;
       if TipTVA = 4 then ValTVANeded := ValTVANeded + ValTVAExtern * 0.5 * KProRata; end if;
     end if;
     Return ValTVAExtern - ValTVANeded;
   end if;
end;

PROCEDURE MAKE_TMP_PER_TVAColectat(pAnLuna NUMBER) IS
  vDataMax DATE;
  vAn      NUMBER;
  vLuna    NUMBER;
BEGIN
  PKG_LIST_BASE_UTILS.ExtractAnLuna (pAnLuna, vAn, vLuna);
  IF vAn &gt; 2013
  THEN vDataMax := To_Date(&apos;20131231&apos;,&apos;yyyymmdd&apos;);
  ELSE vDataMax := To_Date(vAn||&apos;.&apos;||vLuna,&apos;yyyy.mm&apos;) - 1;
  END IF;

  DELETE TMP_PER_TVAColectat;

  INSERT INTO TMP_PER_TVAColectat
  SELECT Data1 - ZileTva, Data2 - ZileTva
  FROM (
    SELECT
      CASE WHEN CL.ANSTART = FL.ANINITIAL AND CL.LUNASTART = FL.LUNAINITIALA THEN To_Date(&apos;2000&apos;,&apos;yyyy&apos;) ELSE To_Date(CL.ANSTART||&apos;.&apos;||CL.LUNASTART,&apos;yyyy.mm&apos;) END Data1,
      Nvl(To_Date(Lead(CL.ANSTART||&apos;.&apos;||CL.LUNASTART) OVER (ORDER BY CL.ANSTART, CL.LUNASTART),&apos;yyyy.mm&apos;)-1, vDataMax) Data2,
      CASE WHEN Nvl(CV.VALOARE,0) BETWEEN 1 AND 9998 THEN To_Number(Nvl(CV.VALOARE,0)) + 1 ELSE 0 END ZileTva
    FROM CONST1 C1
      INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      LEFT JOIN CONSTVAL CV ON cv.codconstluna = cl.codconstluna
      CROSS JOIN FIRMALUNI FL
    WHERE UPPER(C1.simbol) = UPPER(&apos;ZileTVAIncasare&apos;)
      AND CL.ANSTART * 12 + CL.LUNASTART &lt; pAnLuna
      AND CL.ANSTART * 12 + CL.LUNASTART &lt;= 2014*12 -- de la aceata data nu mai e valabila constanta
    ORDER BY CL.ANSTART, CL.LUNASTART
  )
  WHERE ZileTva &lt;&gt; 0
  ORDER BY DATA1, DATA2;
END;

PROCEDURE MAKE_TMP_StingereTVADed(pFromLista NUMBER DEFAULT 0) IS
  vALIni INTEGER;
  vALFin INTEGER;
BEGIN
  IF Coalesce(pFromLista,0) = 1
  THEN
    vALIni := PKG_LIST_BASE_JURNCUMP.GetAnLunaIni;
    vALFin := PKG_LIST_BASE_JURNCUMP.GetAnLunaFin;
  ELSE
    vALIni := PKG_GLOBALS.AnLunaLucru;
    vALFin := PKG_GLOBALS.AnLunaLucru;
  END IF;

  DELETE FROM TMP_TVAINCAS;
  INSERT INTO TMP_TVAINCAS (
    INITIALIZARI, CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DATADOC, PARTENER,
    TIPSTINGERE, PREFIXSTINGERE, NRSTINGERE, DATASTINGERE, ANSTINGERE, LUNASTINGERE,
    VALSTINSA,
    COEF,
    COEFBAZA,
    COEFTVA,
    SplitTVA)
  WITH II AS ( -- exista cazuri mai dubioase pet facturile din initializate cu cecuri in cecuri in curs din initializare cand valdoc nu e real, e rest de incasat
    SELECT I.CODINTR, Sum(i1.pu*i1.cant+i1.tva) ValDoc, Sum(i1.tva) TvaDoc, I.SplitTVA
    FROM INTRARI I INNER JOIN INTRARI1 i1 ON I1.CODINTR = I.CODINTR
    WHERE I.INITIALIZARI = 1
    GROUP BY I.CODINTR, I.SplitTVA
  )
  SELECT
    Coalesce(I.INITIALIZARI,0), I.CODINTR CodDoc, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DATADOC, I.PARTENER,
    T.TipDoc TIPSTINGERE, T1.Doc PREFIXSTINGERE, T1.NrDoc NRSTINGERE, T1.DataDoc DATASTINGERE, T.AN, T.LUNA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * (S.VALOARE+Coalesce(S.DINCARETVA,0)) VALSTINSA,
    Round(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * (S.VALOARE+Coalesce(S.DINCARETVA,0))/Coalesce(II.VALDOC, I.ValDoc) ,17) Coef,
    Round(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * CASE WHEN Coalesce(O_STINS.DINCARETVA,0) = 0 THEN S.VALOARE/Coalesce(II.VALDOC, I.ValDoc) ELSE S.Valoare/(Coalesce(II.VALDOC, I.ValDoc)-Coalesce(II.TVADOC, I.TvaDoc)) END,17) CoefBaza,
    Round(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * CASE WHEN Coalesce(O_STINS.DINCARETVA,0) = 0 THEN S.VALOARE/Coalesce(II.VALDOC, I.ValDoc) ELSE Coalesce(S.DINCARETVA,0)/Coalesce(II.TVADOC, I.TvaDoc) END,17) CoefTVA,
    Coalesce(I.SplitTVA, 0) SplitTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (1, 9)
    INNER JOIN INTRARI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODINTR = G_STINS.CODDOC
    LEFT JOIN II ON II.CODINTR = I.CODINTR
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND T.AN * 12 + T.LUNA BETWEEN vALIni AND vALFin
    AND Coalesce(T1.ANULAT, 0) = 0
    AND Coalesce(II.VALDOC, I.ValDoc) &lt;&gt; 0
    AND Coalesce(II.TVADOC, I.TvaDoc) &lt;&gt; 0
  UNION ALL
  SELECT -- stingeri de tranzactii in curs
    Coalesce(I.INITIALIZARI, 0), I.CODINTR CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DATADOC, I.PARTENER,
    T.TipDoc TIPSTINGERE, T1.Doc PREFIXSTINGERE, T1.NrDoc NRSTINGERE, T1_CURENT.DataDoc DATASTINGERE, T1_CURENT.AN, T1_CURENT.LUNA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END *
    CASE
      WHEN Coalesce(T1.Initializari, 0) = 1
      THEN II.VALDOC
      ELSE  S.VALOARE+Coalesce(S.DINCARETVA,0)
    END VALSTINSA,
    Round(
      CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END *
      CASE
        WHEN Coalesce(T1.Initializari, 0) = 1
        THEN 1
        ELSE (S.VALOARE+Coalesce(S.DINCARETVA,0)    )/I.ValDoc
      END ,17
    ) Coef,
    Round(
      CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END *
      CASE
        WHEN Coalesce(T1.Initializari, 0) = 1
        THEN 1
        ELSE S.VALOARE / CASE WHEN Coalesce(O_STINS.DINCARETVA,0) = 0 THEN I.ValDoc ELSE I.ValDoc-I.TvaDoc END
      END ,17
    ) CoefBaza,
    Round(
      CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END *
      CASE
        WHEN Coalesce(T1.Initializari, 0) = 1 AND Coalesce(S.DINCARETVA,0) = 0 THEN 1 --S_CEC.VALOARE   /Sum(II.ValDoc) OVER (PARTITION BY S_CEC.CODSTINGERE)
        WHEN Coalesce(T1.Initializari, 0) = 1                                  THEN 1 --S_CEC.DINCARETVA/Sum(II.TvaDoc) OVER (PARTITION BY S_CEC.CODSTINGERE)
        WHEN                                      Coalesce(S.DINCARETVA,0) = 0 THEN S.VALOARE   /I.ValDoc
        ELSE                                                                        S.DINCARETVA/I.TvaDoc
      END ,17
    ) CoefTVA,
    Coalesce(I.SplitTVA, 0) SplitTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    INNER JOIN GENERAL G_CEC ON G_CEC.TIPDOC = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE in (500,600)
    INNER JOIN OBLIGPIF O_CEC ON O_CEC.CODGENERAL = G_CEC.CODGENERAL
    INNER JOIN STINGERE S_CEC ON S_CEC.CODSTINSPIF = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT ON O_CURENT.CODOBLIGPIF = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL G_CURENT ON G_CURENT.CODGENERAL = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN TREZOR1 T1_CURENT ON T1_CURENT.CODTREZOR1 = G_CURENT.CODDOC
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (1, 9)
    INNER JOIN INTRARI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODINTR = G_STINS.CODDOC
    LEFT JOIN II ON II.CODINTR = I.CODINTR
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND T1_CURENT.AN * 12 + T1_CURENT.LUNA BETWEEN vALIni AND vALFin
    AND T.AN * 12 + T.LUNA &lt;= vALFin
    AND Coalesce(T1.ANULAT, 0) = 0
    AND Coalesce(II.VALDOC, I.ValDoc) &lt;&gt; 0
  UNION ALL
  SELECT
    INITIALIZARI, CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DataDOC, PARTENER,
    28 TIPSTINGERE, &apos;PV&apos; PREFIXSTINGERE, NRSTINGERE, DATASTINGERE, AN, LUNA,
    VALSTINSA,
    Coef,
    CoefBaza,
    CoefTVA,
    SplitTVA
  FROM (
    SELECT
      Coalesce(I.INITIALIZARI, 0) INITIALIZARI, I.CODINTR CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER,
      C.NrDoc NRSTINGERE, C.DataDoc DATASTINGERE, C.AN, C.LUNA,
      Sum(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * (S.VALOARE+Coalesce(S.DINCARETVA,0))) VALSTINSA,
      Round(Sum(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * (S.VALOARE+Coalesce(S.DINCARETVA,0))/Coalesce(II.VALDOC, I.ValDoc)),17) Coef,
      Round(Sum(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * CASE WHEN Coalesce(O_STINS.DINCARETVA,0) = 0 THEN S.VALOARE/Coalesce(II.VALDOC, I.ValDoc) ELSE S.Valoare/(Coalesce(II.VALDOC, I.ValDoc)-Coalesce(II.TVADOC, I.TvaDoc)) END),17) CoefBaza,
      Round(Sum(CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * CASE WHEN Coalesce(O_STINS.DINCARETVA,0) = 0 THEN S.VALOARE/Coalesce(II.VALDOC, I.ValDoc) ELSE Coalesce(S.DINCARETVA,0)/Coalesce(II.TVADOC, I.TvaDoc) END),17) CoefTVA,
      Coalesce(I.SplitTVA, 0) SplitTVA
    FROM STINGERE S
      INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
      INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
      INNER JOIN COMPENS C ON C.CODCOMPENS = G_STINGATOR.CODDOC
      INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
      INNER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (1, 9)
      INNER JOIN INTRARI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODINTR = G_STINS.CODDOC
      LEFT JOIN II ON II.CODINTR = I.CODINTR
    WHERE Coalesce(I.TVAINCASARE, 0) = 1
      AND C.AN * 12 + C.LUNA BETWEEN vALIni AND vALFin
      AND Coalesce(II.VALDOC, I.ValDoc) &lt;&gt; 0
    GROUP BY I.CODINTR, I.INITIALIZARI, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER, I.SplitTva, C.CODCOMPENS, C.NrDoc, C.DataDoc, C.AN, C.LUNA
  ) SUBS
  WHERE VALSTINSA &lt;&gt; 0;

  INSERT INTO TMP_JURNAL1 (
    CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
    CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
    CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
    GEST, VALOARE, VALOAREV, OBS,
    AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,
    DOCUMENT )
  SELECT
    CASE pFromLista WHEN 1 THEN 0 ELSE SEQ_JURNAL1_CODJURNAL1.NEXTVAL END CODJURNAL1, CASE pFromLista WHEN 1 THEN Docs.CodDoc ELSE 1 END CODDOC, CASE pFromLista WHEN 1 THEN Docs.TipDoc ELSE 81 END TIPDOC, Docs.CodDoc INDEXLOCAL,
    Tot.Prorata, Tot.TVANeded,  1100, Tot.CODTVA, 3, 200, &apos;&apos;,
    0,  0,  1100, Tot.CODTVA, 5, 200, IOP.TVANEEXP,
    Tot.GEST, Round(Docs.CoefTVA*Tot.VALOARE,7) Valoare, Round(Docs.CoefTVA*Tot.VALOAREV,7) ValoareV, &apos;Automat TVA-&apos;||OBS,
    DOCS.AnStingere, Docs.LunaStingere, 0, Tot.SUBUNITATEA, Tot.CODCENTRU, Docs.DataStingere,
    Round(100*Docs.Coef,4)||&apos;% din &apos;||Docs.PREFIXDOC||Docs.SERIADOC||Docs.NRDOC||&apos;/&apos;||to_Char(Docs.DataDoc, &apos;DD.MM.YYYY&apos;)
  FROM Tmp_Tvaincas DOCS
    LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = DOCS.PARTENER
    INNER JOIN (
      SELECT
        CodDoc, TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, ProRata, TVANEded,
        Sum(Valoare) Valoare, Sum(ValoareV) ValoareV, Sum(VALOAREGRUP) VALOAREGRUP, Sum(VALOARE_IFRS) VALOARE_IFRS, Sum(VALOAREV_IFRS) VALOAREV_IFRS
      FROM (
        SELECT
          CodDoc, TipDoc, CODDESCRD CodTVA, ANALITICCONTD ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, CodBazaD ProRata, ICONTBAZAD TVANEded,
          Sum(Coalesce(Valoare,0)) Valoare, Sum(Coalesce(ValoareV,0)) ValoareV, Sum(Coalesce(VALOAREGRUP,0)) VALOAREGRUP, Sum(Coalesce(VALOARE_IFRS,0)) VALOARE_IFRS, Sum(Coalesce(VALOAREV_IFRS,0)) VALOAREV_IFRS
        FROM jurnal1
        WHERE TipContD = -200 AND IContD = 5
        GROUP BY CodDoc, TipDoc, CODDESCRD, ANALITICCONTD, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, CodBazaD, ICONTBAZAD
        UNION ALL
        SELECT
          CodDoc, TipDoc, CODDESCRC CodTVA,ANALITICCONTC ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, CodBazaC ProRata, ICONTBAZAC TVANEded,
          -Sum(Coalesce(Valoare,0)) Valoare, -Sum(Coalesce(ValoareV,0)) ValoareV, -Sum(Coalesce(VALOAREGRUP,0)) VALOAREGRUP, -Sum(Coalesce(VALOARE_IFRS,0)) VALOARE_IFRS, -Sum(Coalesce(VALOAREV_IFRS,0)) VALOAREV_IFRS
        FROM jurnal1
        WHERE  TipContC = -200 and IContC = 5
        GROUP BY CodDoc, TipDoc, CODDESCRC, ANALITICCONTC, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, CodBazaC, ICONTBAZAC
      ) GROUP BY CodDoc, TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs, ProRata, TVANEded
    ) Tot on Tot.CodDoc = Docs.CodDoc AND Tot.TipDoc = Docs.TipDoc
  WHERE Docs.CoefTVA &lt;&gt; 0 AND Coalesce(Docs.INITIALIZARI, 0) = 0;

  --documente din initializari
  INSERT INTO TMP_JURNAL1 (
    CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
    CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
    CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
    GEST, VALOARE, VALOAREV, OBS,
    AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,
    DOCUMENT )
  SELECT
    CASE pFromLista WHEN 1 THEN 0 ELSE SEQ_JURNAL1_CODJURNAL1.NEXTVAL END CODJURNAL1, CASE pFromLista WHEN 1 THEN Docs.CodDoc ELSE 1 END CODDOC, CASE pFromLista WHEN 1 THEN Docs.TipDoc ELSE 81 END TIPDOC, Docs.CodDoc INDEXLOCAL,
    Tot.Prorata, Tot.TVANeded,  1100, Tot.CODTVA, 3, 200, &apos;&apos;,
    0,  0,  1100, Tot.CODTVA, 5, 200, Tot.ANALITICCONT,
    Tot.GEST, Round(DOCS.CoefTVA*Tot.VALOARE,7) Valoare, Round(DOCS.CoefTVA*Tot.VALOAREV,7) ValoareV, &apos;Automat TVA-&apos;||OBS,
    DOCS.AnStingere, Docs.LunaStingere, 0, Tot.SUBUNITATEA, Tot.CODCENTRU, Docs.DataStingere,
    Round(100*Docs.Coef,4)||&apos;% din &apos;||Docs.PREFIXDOC||Docs.SERIADOC||Docs.NRDOC||&apos;/&apos;||to_Char(Docs.DataDoc, &apos;DD.MM.YYYY&apos;)
  FROM Tmp_Tvaincas DOCS
    INNER JOIN (
      SELECT
        I.CodIntr CodDoc, I.TipDoc TipDoc, I.SUBUNITATEA, Coalesce(I.ProRata, 100) ProRata, I1.TVANeded,
        PKG_INCHIDERI.CalcTVADed(I.TipTVA, I1.TVANeded, I.ProRata, I1.TVA*Coalesce(NULLIF(I.Curs,0),1)) Valoare,
        NART1LUNA.CODTVA, 0 Gest, 0 ValoareV, &apos;Initializari&apos;||CASE WHEN p.codpart IS NULL THEN &apos;&apos; ELSE &apos;;Part: &apos;||p.Den_part END Obs, IOP.TVANEEXP ANALITICCONT, 0 CODCENTRU
      FROM Intrari1 I1
        INNER JOIN Intrari I ON I1.CodIntr = I.CodIntr
        LEFT JOIN NartObj o ON o.CodObiect   = I1.CodObiect
        LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
        LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = I.PARTENER
        LEFT JOIN NPART P ON p.codpart = i.partener
      WHERE I.Initializari = 1
    ) Tot on Tot.CodDoc = Docs.CodDoc and Tot.TipDoc = Docs.TipDoc
  WHERE Docs.CoefTVA &lt;&gt; 0 AND Coalesce(Docs.INITIALIZARI, 0) = 1;
END;

PROCEDURE MAKE_TMP_StingereTVACole(pFromLista NUMBER DEFAULT 0) IS
  ZileTVAIncasare  number;
  vALIni INTEGER;
  vALFin INTEGER;
BEGIN
  IF Coalesce(pFromLista,0) = 1
  THEN
    vALIni := PKG_LIST_BASE_JURNVANZ.GetAnLunaIni;
    vALFin := PKG_LIST_BASE_JURNVANZ.GetAnLunaFin;
    IF PKG_LIST_BASE_JURNVANZ.GetAnLista * 12 + PKG_LIST_BASE_JURNVANZ.GetLunaLista &gt; 2014*12
    THEN ZileTVAIncasare := 0;
    ELSE ZileTVAIncasare := Coalesce(pkg_categconst.GetValConstanta(&apos;ZileTVAIncasare&apos;,PKG_LIST_BASE_JURNVANZ.GetAnLista, PKG_LIST_BASE_JURNVANZ.GetLunaLista), 0);
    END IF;
  ELSE
    vALIni := PKG_GLOBALS.AnLunaLucru;
    vALFin := PKG_GLOBALS.AnLunaLucru;
    IF Pkg_Globals.GetAnLucru * 12 + Pkg_Globals.GetLunaLucru &gt; 2014*12
    THEN ZileTVAIncasare := 0;
    ELSE ZileTVAIncasare := Coalesce(pkg_categconst.GetValConstanta(&apos;ZileTVAIncasare&apos;,Pkg_Globals.GetAnLucru, Pkg_Globals.GetLunaLucru), 0);
    END IF;
  END IF;

  MAKE_TMP_PER_TVAColectat(vALIni);
  IF ZileTVAIncasare &gt;= 9999 THEN ZileTVAIncasare := 0; END IF;

  DELETE FROM TMP_TVAINCAS;
  INSERT INTO TMP_TVAINCAS (
    INITIALIZARI, CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DATADOC, PARTENER,
    TIPSTINGERE, PREFIXSTINGERE, NRSTINGERE, DATASTINGERE, ANSTINGERE, LUNASTINGERE, DATASTOP,
    VALSTINSA, COEFTVA)
  WITH II AS ( -- exista cazuri mai dubioase pet facturile din initializate cu cecuri in cecuri in curs din initializare cand valdoc nu e real, e rest de incasat
    SELECT I.CODIES, Sum(i1.pu*i1.cant+i1.tva) ValDoc, Sum(i1.tva) TvaDoc
    FROM IESIRI I INNER JOIN IESIRI1 i1 ON I1.CODIES = I.CODIES
    WHERE I.INITIALIZARI = 1
    GROUP BY I.CODIES
  )
  SELECT
    Coalesce(I.INITIALIZARI, 0),I.CODIES CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER,
    T.TipDoc TIPSTINGERE, T1.Doc PREFIXSTINGERE, T1.NrDoc NRSTINGERE, T1.DataDoc DATASTINGERE, T.AN, T.LUNA,
    CASE WHEN ZileTVAIncasare = 0 THEN NULL ELSE Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1 END DataStopTVA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * S.VALOARE VALSTINSA, CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * Round(S.VALOARE/Coalesce(II.ValDoc,I.ValDoc), 17) CoefTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    INNER JOIN OBLIGPIF O_STINSL ON O_STINSL.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = pkg_inchideri.getOPIFRoot(O_STINSL.CODOBLIGASOCIAT,O_STINSL.CODOBLIGPIF)
    INNER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (19, 26)
    INNER JOIN IESIRI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODIES = G_STINS.CODDOC
    LEFT JOIN II ON II.CODIES = I.CODIES
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE Coalesce(G_STINS.DataTVA, I.DataDoc) BETWEEN T.Data1 AND T.Data2)
    AND T.AN * 12 + T.LUNA BETWEEN vALIni AND vALFin
    AND Coalesce(T1.ANULAT, 0) = 0
    AND (ZileTVAIncasare = 0 OR T1.DataDoc &lt; Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1)
    AND I.ValDoc &lt;&gt; 0
    AND Coalesce(II.ValDoc,I.ValDoc) &lt;&gt; 0
  UNION ALL
  SELECT
    Coalesce(I.INITIALIZARI, 0),I.CODIES CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER,
    T.TipDoc TIPSTINGERE, T1.Doc PREFIXSTINGERE, T1.NrDoc NRSTINGERE, T1_CURENT.DataDoc DATASTINGERE, T1_CURENT.AN, T1_CURENT.LUNA,
    CASE WHEN ZileTVAIncasare = 0 THEN NULL ELSE Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1 END DataStopTVA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * S.VALOARE VALSTINSA, CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * Round(S.VALOARE/Coalesce(II.ValDoc,I.ValDoc), 17) CoefTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    INNER JOIN GENERAL G_CEC ON G_CEC.TIPDOC = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE in (500,600)
    INNER JOIN OBLIGPIF O_CEC ON O_CEC.CODGENERAL = G_CEC.CODGENERAL
    INNER JOIN STINGERE S_CEC ON S_CEC.CODSTINSPIF = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT ON O_CURENT.CODOBLIGPIF = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL G_CURENT ON G_CURENT.CODGENERAL = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN OBLIGPIF O_STINSL ON O_STINSL.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = pkg_inchideri.getOPIFRoot(O_STINSL.CODOBLIGASOCIAT,O_STINSL.CODOBLIGPIF)
    INNER JOIN GENERAL  G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (19, 26)
    INNER JOIN TREZOR1 T1_CURENT ON T1_CURENT.CODTREZOR1 = G_CURENT.CODDOC
    INNER JOIN IESIRI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODIES = G_STINS.CODDOC
    LEFT JOIN II ON II.CODIES = I.CODIES
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE Coalesce(G_STINS.DataTVA, I.DataDoc) BETWEEN T.Data1 AND T.Data2)
    AND T.AN * 12 + T.LUNA &lt;= vALFin
    AND Coalesce(T1.ANULAT, 0) = 0
    AND T1_CURENT.AN * 12 + T1_CURENT.LUNA BETWEEN vALIni AND vALFin
    AND (ZileTVAIncasare = 0 OR T1_CURENT.DataDoc &lt; Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1)
    AND Coalesce(II.ValDoc,I.ValDoc) &lt;&gt; 0
  UNION ALL
  SELECT
    Coalesce(I.INITIALIZARI, 0),I.CODIES CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER,
    28 TIPSTINGERE, &apos;PV&apos; PREFIXSTINGERE, C.NrDoc NRSTINGERE, C.DataDoc DATASTINGERE, C.AN, C.LUNA,
    CASE WHEN ZileTVAIncasare = 0 THEN NULL ELSE Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1 END DataStopTVA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * S.VALOARE VALSTINSA, CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * Round(S.VALOARE/Coalesce(II.ValDoc,I.ValDoc), 17) CoefTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
    INNER JOIN COMPENS C ON C.CODCOMPENS = G_STINGATOR.CODDOC AND C.TipCompens &lt;&gt; 1
    INNER JOIN OBLIGPIF O_STINSL ON O_STINSL.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = pkg_inchideri.getOPIFRoot(O_STINSL.CODOBLIGASOCIAT,O_STINSL.CODOBLIGPIF)
    INNER JOIN GENERAL  G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (19, 26)
    INNER JOIN IESIRI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODIES = G_STINS.CODDOC
    LEFT JOIN II ON II.CODIES = I.CODIES
    LEFT JOIN OBLIGPIF O_ASOC ON O_ASOC.CODOBLIGASOCIAT = O_STINSL.CODOBLIGPIF
    LEFT JOIN GENERAL G_ASOC ON G_ASOC.CODGENERAL = O_ASOC.CODGENERAL
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE Coalesce(G_STINS.DataTVA, I.DataDoc) BETWEEN T.Data1 AND T.Data2)
    AND C.AN * 12 + C.LUNA BETWEEN vALIni AND vALFin
    AND (ZileTVAIncasare = 0 OR C.DataDoc &lt; Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1)
    AND Coalesce(II.ValDoc,I.ValDoc) &lt;&gt; 0
    AND NOT (Coalesce(O_ASOC.SEMNIFICATIE,0) = 1303 AND Coalesce(G_ASOC.CODDOC,0) = G_STINGATOR.CODDOC)
  UNION ALL
  SELECT
    Coalesce(I.INITIALIZARI, 0),I.CODIES CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DataDOC, I.PARTENER,
    I_STING.TipDoc TIPSTINGERE, I_STING.PREFIXDOC PREFIXSTINGERE, I_STING.NrDoc NRSTINGERE, I_STING.DataDoc DATASTINGERE, I_STING.AN, I_STING.LUNA,
    CASE WHEN ZileTVAIncasare = 0 THEN NULL ELSE Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1 END DataStopTVA,
    CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * S.VALOARE VALSTINSA, CASE WHEN O_STINS.VALOARE &lt; 0 THEN -1 ELSE 1 END * Round(S.VALOARE/Coalesce(II.ValDoc,I.ValDoc), 17) CoefTVA
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (16)
    INNER JOIN IESIRI I_STING ON I_STING.CODIES = G_STINGATOR.CODDOC
    INNER JOIN OBLIGPIF O_STINSL ON O_STINSL.CODOBLIGPIF = S.CODSTINSPIF
    INNER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = pkg_inchideri.getOPIFRoot(O_STINSL.CODOBLIGASOCIAT,O_STINSL.CODOBLIGPIF)
    INNER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL AND G_STINS.TIPDOC IN (19, 26)
    INNER JOIN IESIRI I ON I.TIPDOC = G_STINS.TIPDOC AND I.CODIES = G_STINS.CODDOC
    LEFT JOIN II ON II.CODIES = I.CODIES
  WHERE Coalesce(I.TVAINCASARE, 0) = 1
    AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE Coalesce(G_STINS.DataTVA, I.DataDoc) BETWEEN T.Data1 AND T.Data2)
    AND I_STING.AN * 12 + I_STING.LUNA BETWEEN vALIni AND vALFin
    AND Coalesce(I_STING.ANULAT, 0) = 0
    AND (ZileTVAIncasare = 0 OR I_STING.DataDoc &lt; Coalesce(G_STINS.DataTVA, I.DataDoc) + ZileTVAIncasare + 1)
    AND I.ValDoc &lt;&gt; 0
    AND Coalesce(II.ValDoc,I.ValDoc) &lt;&gt; 0;

  INSERT INTO TMP_JURNAL1 (
    CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
    CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
    CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
    GEST, VALOARE, VALOAREV, OBS,
    AN, LUNA, DIRTY,
    SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
  SELECT
    CASE pFromLista WHEN 1 THEN 0 ELSE SEQ_JURNAL1_CODJURNAL1.NEXTVAL END CODJURNAL1, CASE pFromLista WHEN 1 THEN Docs.CodDoc ELSE 2 END CODDOC, CASE pFromLista WHEN 1 THEN Docs.TipDoc ELSE 81 END TIPDOC, Docs.CodDoc INDEXLOCAL,
    0,  0,  1100, CODTVA, 5, 200, IOP.TVANEEXI,
    0,  0,  1100, CODTVA, 4, 200, &apos;&apos;,
    GEST,
    Round(CoefTVA*VALOARE,7) Valoare, Round(CoefTVA*VALOAREV,7) ValoareV, &apos;Automat TVA-&apos;||OBS,
    DOCS.AnStingere, Docs.LunaStingere, 0,
    SUBUNITATEA, CODCENTRU, DataStingere, Round(100*Docs.Coef,4)||&apos;% din &apos;||PREFIXDOC||SERIADOC||NRDOC||&apos;/&apos;||to_Char(DataDoc, &apos;DD.MM.YYYY&apos;)
  FROM Tmp_Tvaincas DOCS
    LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = DOCS.PARTENER
    INNER JOIN (
      SELECT
        CodDoc CodDoc, TipDoc TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
        Sum(Valoare) Valoare, Sum(ValoareV) ValoareV, Sum(VALOAREGRUP) VALOAREGRUP, Sum(VALOARE_IFRS) VALOARE_IFRS, Sum(VALOAREV_IFRS) VALOAREV_IFRS
      FROM (
        SELECT
          CodDoc, TipDoc, CODDESCRD CodTVA, ANALITICCONTD ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
          -Sum(Coalesce(Valoare,0)) Valoare, -Sum(Coalesce(ValoareV,0)) ValoareV, -Sum(Coalesce(VALOAREGRUP,0)) VALOAREGRUP, -Sum(Coalesce(VALOARE_IFRS,0)) VALOARE_IFRS, -Sum(Coalesce(VALOAREV_IFRS,0)) VALOAREV_IFRS
        FROM jurnal1
        WHERE TipContD = -200 AND IContD = 5
        GROUP BY CodDoc, TipDoc, CODDESCRD, ANALITICCONTD, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
        UNION ALL
        SELECT
          CodDoc, TipDoc, CODDESCRC CodTVA,ANALITICCONTC ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
          +Sum(Coalesce(Valoare,0)) Valoare, +Sum(Coalesce(ValoareV,0)) ValoareV, +Sum(Coalesce(VALOAREGRUP,0)) VALOAREGRUP, +Sum(Coalesce(VALOARE_IFRS,0)) VALOARE_IFRS , +Sum(Coalesce(VALOAREV_IFRS,0)) VALOAREV_IFRS
        FROM jurnal1
        WHERE TipContC = -200 AND IContC = 5
        GROUP BY CodDoc, TipDoc, CODDESCRC, ANALITICCONTC, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
      ) GROUP BY CodDoc, TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
    ) Tot ON Tot.CodDoc = Docs.CodDoc AND Tot.TipDoc = Docs.TipDoc
  WHERE Coalesce(Docs.INITIALIZARI, 0) = 0;

  INSERT INTO TMP_JURNAL1 (
    CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
    CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
    CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
    GEST, VALOARE, VALOAREV, OBS,
    AN, LUNA, DIRTY,
    SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
  SELECT
    CASE pFromLista WHEN 1 THEN 0 ELSE SEQ_JURNAL1_CODJURNAL1.NEXTVAL END CODJURNAL1, CASE pFromLista WHEN 1 THEN Docs.CodDoc ELSE 2 END CODDOC, CASE pFromLista WHEN 1 THEN Docs.TipDoc ELSE 81 END TIPDOC, Docs.CodDoc INDEXLOCAL,
    0,  0,  1100, CODTVA, 5, 200, ANALITICCONT,
    0,  0,  1100, CODTVA, 4, 200, &apos;&apos;,
    GEST,
    Round(CoefTVA*VALOARE,7) Valoare, Round(CoefTVA*VALOAREV,7) ValoareV, &apos;Automat TVA-&apos;||OBS,
    DOCS.AnStingere, Docs.LunaStingere, 0,
    SUBUNITATEA, CODCENTRU, DataStingere, Round(100*Docs.Coef,4)||&apos;% din &apos;||PREFIXDOC||SERIADOC||NRDOC||&apos;/&apos;||to_Char(DataDoc, &apos;DD.MM.YYYY&apos;)
  FROM Tmp_Tvaincas DOCS
    INNER JOIN (
      SELECT I.CodIes CodDoc, I.TipDoc TipDoc, I.SUBUNITATEA, I1.TVA*Coalesce(NULLIF(I.Curs,0),1) Valoare, NART1LUNA.CODTVA, 0 Gest, 0 ValoareV, &apos;Initializari&apos; Obs, IOP.TVANEEXI ANALITICCONT, 0 CODCENTRU
      FROM Iesiri1 I1
        INNER JOIN Iesiri I on I1.CodIes = I.CodIes
        LEFT JOIN NartObj o on o.CodObiect   = I1.CodObiect
        LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
        LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = I.PARTENER
      WHERE I.Initializari = 1
    ) Tot ON Tot.CodDoc = Docs.CodDoc AND Tot.TipDoc = Docs.TipDoc
  WHERE Docs.Initializari = 1;
END;

FUNCTION getOPIFRoot (pCodObligPif IN NUMBER, pCodObligAsociat IN NUMBER) RETURN NUMBER IS
  vCodObligPif     NUMBER;
  vCodObligAsociat NUMBER;
BEGIN
  vCodObligPif     := pCodObligPif;
  vCodObligAsociat := Coalesce(pCodObligAsociat, 0);

  WHILE vCodObligAsociat &lt;&gt; 0
  LOOP
    vCodObligPif := vCodObligAsociat;
    BEGIN
      SELECT Coalesce(CodObligAsociat,0) INTO vCodObligAsociat FROM ObligPif WHERE CodObligPif = vCodObligPif;
    EXCEPTION
      WHEN OTHERS THEN
        vCodObligPif     := 0;
        vCodObligAsociat := 0;
    END;
  END LOOP;
  RETURN vCodObligPif;
END;

FUNCTION getStinsTVACole (pCodObligPif IN NUMBER, pAL NUMBER, pDataStopTVA DATE) RETURN NUMBER IS
  vTrezor  NUMBER;
  vCEC     NUMBER;
  vCompens NUMBER;
  vLitig   NUMBER;
BEGIN
  SELECT NVL(SUM(S.VALOARE), 0)
  INTO vTrezor
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif
    AND NVL(T1.ANULAT, 0) = 0
    AND T1.AN * 12 + T1.LUNA &lt;= pAL
    AND T1.DataDoc &lt; pDataStopTVA;

  SELECT NVL(SUM(S.VALOARE), 0)
  INTO vCEC
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN GENERAL G_CEC ON G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600) AND G_CEC.TIPDOC = 31
    INNER JOIN OBLIGPIF O_CEC ON O_CEC.CODGENERAL = G_CEC.CODGENERAL
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN STINGERE S_CEC ON S_CEC.CODSTINSPIF = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT ON O_CURENT.CODOBLIGPIF = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL G_CURENT ON G_CURENT.CODGENERAL = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN TREZOR1 T1_CURENT ON T1_CURENT.CODTREZOR1 = G_CURENT.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif
    AND NVL(T1.ANULAT, 0) = 0
    AND T1.AN * 12 + T1.LUNA &lt;= pAL
    AND T1_CURENT.AN * 12 + T1_CURENT.LUNA &lt;= pAL
    AND T1_CURENT.DataDoc &lt; pDataStopTVA;

  SELECT NVL(SUM(S.VALOARE), 0)
  INTO vCompens
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
    INNER JOIN COMPENS C ON C.CODCOMPENS = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif
    AND C.AN * 12 + C.LUNA &lt;= pAL
    AND C.DataDoc &lt; pDataStopTVA;

  vLitig := 0;
  FOR lREC IN (
    SELECT OL.CodObligPif, OL.VALOARE
    FROM OBLIGPIF OL
      INNER JOIN GENERAL GL ON GL.CODGENERAL = OL.CODGENERAL
      INNER JOIN COMPENS CL ON CL.CODCOMPENS = GL.CODDOC
    WHERE OL.CODOBLIGASOCIAT = pCodObligPif
      AND OL.SEMNIFICATIE = 1303
      AND CL.AN * 12 + CL.LUNA &lt;= pAL
      AND CL.DataDoc &lt; pDataStopTVA
  ) LOOP
    vLitig := vLitig + lREC.VALOARE;
    vLitig := vLitig - getStinsTVACole(lREC.CodObligPif, pAL, pDataStopTVA);
  END LOOP;

  RETURN vTrezor + vCEC + vCompens - vLitig;

END;


PROCEDURE MAKE_TMP_InchidereTVACole(pFromLista NUMBER DEFAULT 0) IS
  ZileTVAIncasare  number;
  vALIni INTEGER;
  vALFin INTEGER;
  vDIni  DATE;
  vDFin  DATE;
BEGIN
  IF NVL(pFromLista,0) = 1
  THEN
    vALIni := PKG_LIST_BASE_JURNVANZ.GetAnLunaIni;
    vALFin := PKG_LIST_BASE_JURNVANZ.GetAnLunaFin;
    vDIni  := PKG_LIST_BASE_JURNVANZ.GetDataIni;
    vDFin  := PKG_LIST_BASE_JURNVANZ.GetDataFin;
    ZileTVAIncasare := NVL(pkg_categconst.GetValConstanta(&apos;ZileTVAIncasare&apos;,PKG_LIST_BASE_JURNVANZ.GetAnLista, PKG_LIST_BASE_JURNVANZ.GetLunaLista), 0);
  ELSE
    vALIni := PKG_GLOBALS.AnLunaLucru;
    vALFin := PKG_GLOBALS.AnLunaLucru;
    vDIni  := To_Date( To_Char(Pkg_Globals.GetAnLucru,&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Pkg_Globals.GetLunaLucru,&apos;fm00&apos;), &apos;yyyy.mm&apos; );
    vDFin  := Last_Day(vDIni);
    ZileTVAIncasare := NVL(pkg_categconst.GetValConstanta(&apos;ZileTVAIncasare&apos;,Pkg_Globals.GetAnLucru, Pkg_Globals.GetLunaLucru), 0);
  END IF;

  IF NOT NVL(pFromLista,0) = 1 THEN
    MAKE_TMP_PER_TVAColectat(vALIni);
    DELETE FROM TMP_TVAINCAS;
  END IF;

  IF ZileTVAIncasare &gt;= 9999 THEN ZileTVAIncasare := 0; END IF;
  IF ZileTVAIncasare &lt;&gt; 0 THEN -- 0 sau +9999 insemna stingere la momentul platii
    ZileTVAIncasare := ZileTVAIncasare + 1;

    INSERT INTO TMP_TVAINCAS (
      INITIALIZARI, CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DATADOC, PARTENER,
      TIPSTINGERE, PREFIXSTINGERE, NRSTINGERE, DATASTINGERE, DATASTOP, ANSTINGERE, LUNASTINGERE,
      VALSTINSA, COEFTVA)
    WITH
    II AS ( -- exista cazuri mai dubioase pet facturile din initializate cu cecuri in cecuri in curs din initializare can valdoc nu e real, e rest de incasat
      SELECT I.CODIES, Sum(i1.pu*i1.cant+i1.tva) ValDoc, Sum(i1.tva) TvaDoc
      FROM IESIRI I INNER JOIN IESIRI1 i1 ON I1.CODIES = I.CODIES
      WHERE I.INITIALIZARI = 1
      GROUP BY I.CODIES ),
    G AS (
      SELECT G.CODGENERAL, G.CODDOC, O.CODOBLIGPIF, Nvl(II.VALDOC,O.VALOARE) VALOARE, G.DataTVA + ZileTVAIncasare DATASTOPTVA
      FROM GENERAL G
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
        LEFT JOIN II ON II.CODIES = G.CODDOC
      WHERE G.TIPDOC IN (19, 26)
        AND G.DATATVA IS NOT NULL
        AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE G.DataTVA BETWEEN T.Data1 AND T.Data2)
        AND G.DataTVA BETWEEN vDIni - ZileTVAIncasare AND vDFin - ZileTVAIncasare )
    SELECT
      INITIALIZARI, CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DATADOC, PARTENER,
      81, &apos;Inchidere TVA&apos;, NRDOC, DATASTOPTVA, DATASTOPTVA, EXTRACT(YEAR FROM DATASTOPTVA) ANSTINGERE, EXTRACT(MONTH FROM DATASTOPTVA) LUNASTINGERE,
      STINS, (ValOblig - STINS)/ ValDoc
    FROM (
      SELECT
        Nvl(I.INITIALIZARI, 0) INITIALIZARI, I.CODIES AS CODDOC, I.TIPDOC, I.NRDOC, I.PREFIXDOC, I.SERIADOC, I.DATADOC, I.PARTENER,
        G.DATASTOPTVA,
        G.Valoare ValOblig,
        Nvl(II.ValDoc, I.ValDoc) ValDoc,
        Nvl(II.TVADOC, I.TVADOC) TVADOC,
        CASE WHEN G.VALOARE &lt; 0 THEN -1 ELSE 1 END * getStinsTVACole(G.CODOBLIGPIF, vALFin, G.DATASTOPTVA) STINS
      FROM G
        INNER JOIN IESIRI I ON I.CODIES = G.CODDOC
        LEFT JOIN II ON II.CODIES = I.CODIES
      WHERE Nvl(II.ValDoc, I.ValDoc) &lt;&gt; 0
    );

    INSERT INTO TMP_JURNAL1 (
      CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
      CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
      CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS,
      AN, LUNA, DIRTY,
      SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
    SELECT
      Decode(pFromLista,1,0,SEQ_JURNAL1_CODJURNAL1.NEXTVAL), Decode(pFromLista,1,Docs.CodDoc,3), Decode(pFromLista,1,Docs.TipDoc,81), 0,
      0,  0,  1100, CODTVA, 5, 200, IOP.TVANEEXI,
      0,  0,  1100, CODTVA, 4, 200, &apos;&apos;,
      GEST, Round(CoefTVA*VALOARE,7) Valoare, Round(CoefTVA*VALOAREV,7) ValoareV, &apos;Automat TVA scadent-&apos;||OBS,
      DOCS.AnStingere, Docs.LunaStingere, 0,
      SUBUNITATEA, CODCENTRU, DataStingere, PREFIXDOC||SERIADOC||NRDOC||&apos;/&apos;||to_Char(DataDoc, &apos;DD.MM.YYYY&apos;)
    --        Round(CoefTVA*VALOAREGRUP,2) VALOAREGRUP, Round(CoefTVA*VALOARE_IFRS,2) VALOARE_IFRS, Round(CoefTVA*VALOAREV_IFRS,2) VALOAREV_IFRS
    FROM Tmp_Tvaincas DOCS
      LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = DOCS.PARTENER
      INNER JOIN (
        Select
          CodDoc CodDoc, TipDoc TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
          Sum(Valoare) Valoare, Sum(ValoareV) ValoareV, Sum(VALOAREGRUP) VALOAREGRUP, Sum(VALOARE_IFRS) VALOARE_IFRS, Sum(VALOAREV_IFRS) VALOAREV_IFRS
        FROM (
          SELECT
            CodDoc, TipDoc, CODDESCRD CodTVA, ANALITICCONTD ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
            -Sum(Nvl(Valoare,0)) Valoare, -Sum(Nvl(ValoareV,0)) ValoareV, -Sum(Nvl(VALOAREGRUP,0)) VALOAREGRUP, -Sum(Nvl(VALOARE_IFRS,0)) VALOARE_IFRS, -Sum(Nvl(VALOAREV_IFRS,0)) VALOAREV_IFRS
          FROM jurnal1
          WHERE TipContD = -200 and IContD = 5
          GROUP BY CodDoc, TipDoc, CODDESCRD, ANALITICCONTD, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
          UNION ALL
          SELECT
            CodDoc, TipDoc, CODDESCRC CodTVA,ANALITICCONTC ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs,
            +Sum(Nvl(Valoare,0)) Valoare, +Sum(Nvl(ValoareV,0)) ValoareV, +Sum(Nvl(VALOAREGRUP,0)) VALOAREGRUP, +Sum(Nvl(VALOARE_IFRS,0)) VALOARE_IFRS, +Sum(Nvl(VALOAREV_IFRS,0)) VALOAREV_IFRS
          FROM jurnal1
          WHERE TipContC = -200 and IContC = 5
          GROUP BY CodDoc, TipDoc, CODDESCRC, ANALITICCONTC, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
        ) GROUP BY CodDoc, TipDoc, CodTVA, ANALITICCONT, Gest, SUBUNITATEA, CODCENTRU, CODANALIZANOD, Obs
      ) Tot on Tot.CodDoc = Docs.CodDoc and Tot.TipDoc = Docs.TipDoc
    WHERE DOCS.TipStingere = 81 AND Docs.Initializari = 0;

    --documente din initializari
    INSERT INTO TMP_JURNAL1 (
      CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
      CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
      CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS,
      AN, LUNA, DIRTY,
      SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
    SELECT
      Decode(pFromLista,1,0,SEQ_JURNAL1_CODJURNAL1.NEXTVAL), Decode(pFromLista,1,Docs.CodDoc,3), Decode(pFromLista,1,Docs.TipDoc,81), 0,
      0,  0,  1100, CODTVA, 5, 200, ANALITICCONT,
      0,  0,  1100, CODTVA, 4, 200, &apos;&apos;,
      GEST, Round(CoefTVA*VALOARE,7) Valoare, Round(CoefTVA*VALOAREV,7) ValoareV, &apos;Automat TVA scadent-&apos;||OBS,
      DOCS.AnStingere, Docs.LunaStingere, 0,
      SUBUNITATEA, CODCENTRU, DataStingere, PREFIXDOC||SERIADOC||NRDOC||&apos;/&apos;||to_Char(DataDoc, &apos;DD.MM.YYYY&apos;)
    --        Round(CoefTVA*VALOAREGRUP,2) VALOAREGRUP, Round(CoefTVA*VALOARE_IFRS,2) VALOARE_IFRS, Round(CoefTVA*VALOAREV_IFRS,2) VALOAREV_IFRS
    FROM Tmp_Tvaincas DOCS
      INNER JOIN
      (
      select I.CodIes CodDocJ, I.TipDoc TipDocJ, I.SUBUNITATEA, I1.TVA*Decode(I.Curs,NULL,1,0,1,I.Curs) Valoare, NART1LUNA.CODTVA, 0 Gest, 0 ValoareV, &apos;Initializari&apos; Obs,
      IOP.TVANEEXI ANALITICCONT, 0 CODCENTRU
      from Iesiri1 I1
            inner join Iesiri I on I1.CodIes = I.CodIes
            left outer join NartObj o on o.CodObiect   = I1.CodObiect
            left outer join TMP_NART_LUNA NART1LUNA  ON NART1LUNA.CODARTICOL = O.CODARTICOL
            LEFT JOIN V_NPART_LUNA IOP ON IOP.CODPART = I.PARTENER
      where I.Initializari = 1
      ) Tot on Tot.CodDocJ = Docs.CodDoc and Tot.TipDocJ = Docs.TipDoc
    WHERE DOCS.TipStingere = 81 and Docs.Initializari = 1;
  END IF;
END;

PROCEDURE MAKE_VOL_TRANZ_STINGERI IS
  BANCASITV   NUMBER(20) := 0;
  MONEDASITV  NUMBER(20) := 0;
  vAnTemp      NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp    NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  vAnTemp, vLunaTemp) INTO BANCASITV  FROM DUAL;
    EXCEPTION WHEN OTHERS THEN BANCASITV := 0;
  END;

  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, vAnTemp, vLunaTemp) INTO MONEDASITV FROM DUAL;
    EXCEPTION WHEN OTHERS THEN MONEDASITV := 0;
  END;

  -- Volum tranzactii CLIENT
  FOR V_REC IN
  (
  SELECT
    CODSTINGERE,
    S.VALOARE * DECODE(GSTINS.CURS,NULL,1,0,1,GSTINS.CURS) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
    STINGERE S,
    OBLIGPIF OSTINS,
    GENERAL  GSTINS,
    IESIRI I
  WHERE
    S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 200
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODIES
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZC = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;



-- Volum tranzactii FURNIZORI
-- INTRARI
  FOR V_REC IN
  (
  SELECT
    CODSTINGERE,
    S.VALOARE * DECODE(GSTINS.CURS,NULL,1,0,1,GSTINS.CURS) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
    STINGERE S,
    OBLIGPIF OSTINS,
    GENERAL  GSTINS,
    INTRARI I
  WHERE
    S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 100
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODINTR
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  -- stingeri de DVI-uri
  FOR V_REC IN
  (
  SELECT
   CODSTINGERE,
   S.VALOARE * DECODE(GSTINS.CURS,NULL,1,0,1,GSTINS.CURS) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(D.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
    STINGERE S,
    OBLIGPIF OSTINS,
    GENERAL  GSTINS,
    DVI D
  WHERE
    S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 130
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = 5
    AND GSTINS.CODDOC = D.CODDVI
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  COMMIT;
END;


PROCEDURE SET_CODOBIECT_PMP(aCODOBIECT IN NUMBER)
IS
BEGIN
  CODOBIECT_PMP := aCODOBIECT;
END;

FUNCTION GET_CODOBIECT_PMP RETURN NUMBER
IS
BEGIN
  RETURN CODOBIECT_PMP;
END;


PROCEDURE REPARA_OBLIGPIF_LUNA
IS
 ANI NUMBER(10);
 ANP NUMBER(10);
 ANM NUMBER(10);
 LUNAI NUMBER(2);
 LUNAP NUMBER(2);
 LUNAM NUMBER(2);
BEGIN
  SELECT ANINITIAL, LUNAINITIALA, ANMAXIM, LUNAMAXIMA INTO ANI, LUNAI, ANM, LUNAM FROM FIRMALUNI;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(ANI, LUNAI, ANP, LUNAP);
  FOR V_REC IN
  (SELECT * FROM OBLIGPIFLUNA OL
   WHERE
   AN = ANP AND LUNA = LUNAP)
  LOOP
    UPDATE OBLIGPIFLUNA
    SET
      RESTTVA = (SELECT NVL(G.TVA, 0) FROM OBLIGPIF O, GENERAL G WHERE O.CODOBLIGPIF = V_REC.CODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL)
    WHERE
     CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = ANP AND LUNA = LUNAP;
  END LOOP;

  WHILE ANP * 12 + LUNAP &lt; ANM * 12 + LUNAM
  LOOP
   PKG_GLOBALS.SetLunaPRECEDENTA(ANP, LUNAP);
   PKG_GLOBALS.SetLunaTEMP(ANI, LUNAI);
   PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
   PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(ANP, LUNAP, ANP, LUNAP);
   PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(ANI, LUNAI, ANI, LUNAI);
  END LOOP;
END;

PROCEDURE GOTO_INCHIDERE_CONTURI
IS
BEGIN
  INSERT INTO TMP_JURNAL
  SELECT * FROM JURNAL WHERE TIPDOC = 32 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

  INSERT INTO TMP_JURNAL1
  SELECT * FROM JURNAL1 WHERE TIPDOC = 32 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
END;

PROCEDURE MAKE_INCHIDERE_CONTURI
IS
NR NUMBER(10) := 0;
BEGIN
  -- detail JURNAlL

DELETE FROM JURNAl1 WHERE TIPDOC = 32 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    DATADOC       = V_REC.DATADOC,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    VALOAREGRUP   = V_REC.VALOAREGRUP
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 ( CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,
                   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST,
                         VALOARE_IFRS,
                         VALOAREV_IFRS,
                   VALOARE, VALOAREV,VALOAREGrup, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC )
   VALUES              ( SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST,
                         V_REC.VALOARE_IFRS,
                         V_REC.VALOAREV_IFRS,
                         V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGrup, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC);
 END IF;
END LOOP;


-- detail JURNAL
DELETE FROM JURNAL WHERE TIPDOC = 32 AND  AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    VALOAREGrup= v_rec.VALOAREGrup,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA,
    DATADOC    = V_REC.DATADOC
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGrup, OBS, AN, LUNA, SUBUNITATEA, DATADOC, VALOARE_IFRS, VALOAREV_IFRS)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL,V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGrup, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS);
 END IF;
END LOOP;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD       = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC       = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD      = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC      = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
     RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),
     RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),
     RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                                                        ELSE  PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                              END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;



   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB,
                                 CODCONTRUL,
                                 RULAJPD,
                                 RULAJPC,
                                 RULAJCD,
                                 RULAJCC,
                                 RULAJVPD,
                                 RULAJVPC,
                                 RULAJVCD,
                                 RULAJVCC,
                                 RULAJP_IFRS,
                                 RULAJC_IFRS,
                                 RULAJVP_IFRS,
                                 RULAJVC_IFRS,
                                 RULAJP_GRUP,
                                 RULAJC_GRUP,
                                 RULAJVP_GRUP,
                                 RULAJVC_GRUP,
                                 SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD       = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC       = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD      = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC      = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
         RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),

         RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),
         RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                                                            ELSE  PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                                  END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;
 END LOOP;

 PKG_GLOBALS.ClearDirtyJurnal;
 COMMIT;

END;



PROCEDURE MAKE_INCHIDERE_CONTURI_SUBUNIT
IS
BEGIN
-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   UPDATE TMP_NCONTRUL
   SET
     RULAJCD      = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC      = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD     = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC     = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
     RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),
     RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),

     RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                                                        ELSE  PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                              END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 END LOOP;


 FOR V_REC IN (SELECT * FROM TMP_RULAJ_PREC) LOOP

   UPDATE TMP_NCONTRUL
   SET
     RULAJPD       = RULAJPD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJPC       = RULAJPC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVPD      = RULAJVPD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVPC      = RULAJVPC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
     RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),
     RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),
     RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                                                        ELSE  PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOARE_GRUP, V_REC.VALOARE, V_REC.VALOAREV)
                                              END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 END LOOP;
 COMMIT;

END;

PROCEDURE MAKE_SOLDURIBANCI_LA_DATA(aDATE VARCHAR2) IS
  LUNA NUMBER(5);
  AN   NUMBER(5);
BEGIN
  BEGIN
    SELECT EXTRACT(MONTH FROM TO_DATE(aDate, &apos;DD.MM.YYYY&apos;)) INTO LUNA FROM DUAL;
    SELECT EXTRACT(YEAR  FROM TO_DATE(aDate, &apos;DD.MM.YYYY&apos;)) INTO AN FROM DUAL;
  EXCEPTION WHEN OTHERS THEN
    AN := 0; LUNA := 0;
  END;

  IF AN + LUNA &lt;&gt; 0 THEN
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AN, LUNA, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);
    PKG_GLOBALS.SETLUNATEMP(AN, LUNA);
    PKG_GLOBALS.DATASOLDBANCI := TO_DATE(aDate, &apos;DD.MM.YYYY&apos;);
  END IF;
  -- apoi se face din program apelul la V_SOLDURIBANCI_LA_DATA;
END;

PROCEDURE MAKE_SOLD_BANK IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  DELETE FROM NBANKSOLDLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO NBANKSOLDLUNA(CODBANKSOLDLUNA, CODBANKCONT, SOLDLEI, SOLDVALUTA, AN, LUNA)
  SELECT SEQ_NBANKSOLDLUNA_CODSOLDLUNA.NextVal, CODBANKCONT, SOLDLEI, SOLDVALUTA, vAnTemp, vLunaTemp
  FROM V_SOLDURIBANCILUNA;

  -- NOILE SOLDURI LE TREC PRIN REGULARIZARI DACA AU FOST LA FINALUL LUNII;
  FOR V_REC IN (
    SELECT S.CODBANKSOLDLUNA, R.CURS
    FROM REG R
      INNER JOIN REGTREZOR1 R1 ON R1.CODREG = R.CODREG
      INNER JOIN NBANKSOLDLUNA S ON S.AN = R.AN AND S.LUNA = R.LUNA AND S.CODBANKCONT = R1.CODBANKCONT
    WHERE R.TIPREG = 45 AND R.AN = vAnTemp AND R.LUNA = vLunaTemp
  )
  LOOP
    UPDATE NBANKSOLDLUNA SET SOLDLEI = SOLDVALUTA * Coalesce(V_REC.CURS, 0) WHERE CODBANKSOLDLUNA = V_REC.CODBANKSOLDLUNA;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_SOLD_PERS IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  aSEMN     NUMBER(5) := 1;
  aTIPCONT  NUMBER(5) := 0;
BEGIN
  DELETE FROM NPERSSOLDLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_SOLDPERS&apos;;

  INSERT INTO TMP_SOLDPERS (CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA)
  SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM V_SOLDPERS_TRANZACTII;

  FOR V_REC IN (
    SELECT * FROM TMP_SOLDPERS S
  ) LOOP
    BEGIN
      SELECT Coalesce(TIPCONT, 0) INTO ATIPCONT
      FROM NCONT
      WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU));
    EXCEPTION
      WHEN OTHERS THEN aTIPCONT := 0;
    END;

    IF Coalesce(aTIPCONT, 0) = 1
    THEN aSEMN := -1;
    ELSE aSEMN :=  1;
    END IF;

    UPDATE TMP_SOLDPERS SET SEMN = aSEMN WHERE CODPERS = V_REC.CODPERS AND ICONT = V_REC.ICONT AND CODMONEDA = V_REC.CODMONEDA;
  END LOOP;

  INSERT INTO NPERSSOLDLUNA(CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  SELECT SEQ_NPERSSOLDLUNA_CODSOLDLUNA.NextVal, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, vAnTemp, vLunaTemp
  FROM (
    SELECT CODPERS, ICONT, CODMONEDA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
    FROM (
      SELECT CODPERS, ICONT, CODMONEDA, Coalesce(SOLDLEI,0) * Coalesce(SEMN, 1) SOLDLEI, Coalesce(SOLDVALUTA,0) * Coalesce(SEMN, 1) SOLDVALUTA FROM TMP_SOLDPERS    UNION ALL
      SELECT CODPERS, ICONT, CODMONEDA,                                         SOLDLEI,                                            SOLDVALUTA FROM V_SOLDPERS_PREC
    ) GROUP BY CODPERS, ICONT, CODMONEDA
  );

  -- NOILE SOLDURI LE TREC PRIN REGULARIZARI DACA AU FOST LA FINALUL LUNII;
  FOR V_REC IN (
    SELECT S.CODPERSSOLDLUNA, R.CURS
    FROM REG R
      INNER JOIN REGPERS1 R1 ON R1.CODREG = R.CODREG
      INNER JOIN NPERSSOLDLUNA S ON S.AN = R.AN AND S.LUNA = R.LUNA AND S.CODPERS = R1.CODPERS AND S.CODMONEDA = R.CODMONEDA
    WHERE R.AN = vAnTemp AND R.LUNA = vLunaTemp AND R.TIPREG = 47
  ) LOOP
    UPDATE NPERSSOLDLUNA SET SOLDLEI = SOLDVALUTA * Coalesce(V_REC.CURS, 0) WHERE CODPERSSOLDLUNA = V_REC.CODPERSSOLDLUNA;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_SOLD_PERS_SUB IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  aSEMN     NUMBER(5) := 1;
  aTIPCONT  NUMBER(5) := 0;
BEGIN
  DELETE FROM NPERSSOLDLUNASUB WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  DELETE TMP_SOLDPERS_SUB;

  INSERT INTO TMP_SOLDPERS_SUB (CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA)
  SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA FROM V_SOLDPERS_TRANZACTII_SUB;

  FOR V_REC IN (
    SELECT * FROM TMP_SOLDPERS_SUB S
  ) LOOP
    BEGIN
      SELECT Coalesce(TIPCONT, 0) INTO ATIPCONT
      FROM NCONT
      WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU));
    EXCEPTION
      WHEN OTHERS THEN aTIPCONT := 0;
    END;

    IF Coalesce(aTIPCONT, 0) = 1
    THEN aSEMN := -1;
    ELSE aSEMN :=  1;
    END IF;

    UPDATE TMP_SOLDPERS_SUB SET SEMN = aSEMN WHERE CODPERS = V_REC.CODPERS AND ICONT = V_REC.ICONT AND CODMONEDA = V_REC.CODMONEDA AND SUBUNITATEA = V_REC.SUBUNITATEA;
  END LOOP;

  INSERT INTO NPERSSOLDLUNASUB(CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  SELECT SEQ_NPERSSOLDLUNASUB_COD.NextVal, CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, vAnTemp, vLunaTemp
  FROM (
    SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
    FROM (
      SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, Coalesce(SOLDLEI,0) * Coalesce(SEMN, 1) SOLDLEI, Coalesce(SOLDVALUTA,0) * Coalesce(SEMN, 1) SOLDVALUTA FROM TMP_SOLDPERS_SUB UNION ALL
      SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA,                                         SOLDLEI,                                            SOLDVALUTA FROM V_SOLDPERS_PREC_SUB
    ) GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
  );

  -- NOILE SOLDURI LE TREC PRIN REGULARIZARI DACA AU FOST LA FINALUL LUNII;
  FOR V_REC IN (
    SELECT S.CODPERSSOLDLUNASUB, R.CURS
    FROM REG R
      INNER JOIN REGPERS1 R1 ON R1.CODREG = R.CODREG
      INNER JOIN NPERSSOLDLUNASUB S ON  S.AN = R.AN AND S.LUNA = R.LUNA AND S.CODPERS = R1.CODPERS AND S.CODMONEDA = R.CODMONEDA
    WHERE R.AN = vAnTemp AND R.LUNA = vLunaTemp AND R.TIPREG = 47
  ) LOOP
    UPDATE NPERSSOLDLUNASUB SET SOLDLEI = SOLDVALUTA * Coalesce(V_REC.CURS, 0) WHERE CODPERSSOLDLUNASUB = V_REC.CODPERSSOLDLUNASUB;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_SOLD_PART IS
  vAnTemp   NUMBER(4)   := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)   := PKG_GLOBALS.GetLUNATEMP;
  sAN       VARCHAR2(5) := TO_CHAR(vAnTemp);
  sLUNA     VARCHAR2(5) := TO_CHAR(vLunaTemp);
  LASTDAY   DATE        := LAST_DAY(TO_DATE(&apos;01.&apos; || SLUNA || &apos;.&apos; || SAN, &apos;DD.MM.YYYY&apos;));
BEGIN
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(LASTDAY, &apos;DD.MM.YYYY&apos;));
  PKG_REGPART.MAKE_INFO_STINSE_LUNA;

  DELETE FROM NPARTSOLDLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO NPARTSOLDLUNA(CODPARTSOLDLUNA, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  SELECT SEQ_NPARTSOLDLUNA_CODSOLDLUNA.NextVal, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, vAnTemp, vLunaTemp
  FROM V_SOLDPART;
  COMMIT;
END;

PROCEDURE MAKE_SOLD_PART_EXT IS
  vAnTemp   NUMBER(4)  := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)  := PKG_GLOBALS.GetLUNATEMP;
  NR        NUMBER(20) := 0;
BEGIN
  PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
  DELETE FROM NPARTSOLDLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;

  INSERT INTO NPARTSOLDLUNA(CODPARTSOLDLUNA, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, AN, LUNA)
  SELECT SEQ_NPARTSOLDLUNA_CODSOLDLUNA.NextVal, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, vAnTemp, vLunaTemp
  FROM V_SOLDPART_EXT;

  -- ajusari IFRS pe moneda=0
  FOR V_REC IN (SELECT * FROM V_SOLDPART_IFRS)
  LOOP
    SELECT COUNT(1) INTO NR FROM NPARTSOLDLUNA WHERE CODPART = V_REC.CODPART AND ICONT = V_REC.ICONT AND CODMONEDA = 0 AND AN = vAnTemp AND LUNA = vLunaTemp;

    IF NR = 0 THEN
      INSERT INTO NPARTSOLDLUNA (CODPARTSOLDLUNA, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, AN, LUNA)
      VALUES (SEQ_NPARTSOLDLUNA_CODSOLDLUNA.NEXTVAL, V_REC.CODPART, V_REC.ICONT, 0, 0, 0, V_REC.SOLD_IFRS, vAnTemp, vLunaTemp);
    ELSE
      UPDATE NPARTSOLDLUNA
      SET SOLD_IFRS = V_REC.SOLD_IFRS
      WHERE CODPART = V_REC.CODPART AND ICONT = V_REC.ICONT AND CODMONEDA = 0 AND AN = vAnTemp AND LUNA = vLunaTemp;
    END IF;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_OBLIGPART_LA_DATA(aDATA VARCHAR2)
IS
  vAnTemp   NUMBER(4)   := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)   := PKG_GLOBALS.GetLUNATEMP;
  sAN       VARCHAR2(5) := TO_CHAR(vAnTemp);
  sLUNA     VARCHAR2(5) := TO_CHAR(vLunaTemp);
  LASTDAY   DATE        := LAST_DAY(TO_DATE(&apos;01.&apos; || SLUNA || &apos;.&apos; || SAN, &apos;DD.MM.YYYY&apos;));

  aPREFIXDOC   VARCHAR2(3) := NULL;
  aDATADOC     DATE        := NULL;
  aNRDOC       NUMBER(20)  := NULL;
  aSUBUNITATEA NUMBER(20)  := NULL;
BEGIN
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(LASTDAY, &apos;DD.MM.YYYY&apos;));
  PKG_GLOBALS.DATASOLDPART := TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;);

  PKG_REGPART.MAKE_STINGERI_LA_DATA;
  DELETE TMP_OBLIGPART_LA_DATA;

   INSERT INTO TMP_OBLIGPART_LA_DATA
   (
    CODOBLIGPIF,
    CODGENERAL,
    CODDOC,
    VALOARE,
    REST,
    ICONT,
    SEMNIFICATIE,
    CODPART,
    CODGEST,
    CURS,
    TVA,
    MONEDA,
    TIPDOC,
    TERMEN
    )
  SELECT
    RG.CODOBLIGPIF,
    RG.CODGENERAL,
    RG.CODDOC,
   (VALOARE - ROUND(NVL(STINS, 0), 7)) VALOARE ,
    VALOARE - ROUND(NVL(STINS, 0), 7)  REST,
    RG.ICONT,
    RG.SEMNIFICATIE,
    RG.CODPART,
    RG.CODGEST,
    RG.CURS,
    RG.TVA,
    RG.MONEDA,
    RG.TIPDOC,
    RG.TERMEN
  FROM
   (
    SELECT
      CODOBLIGPIF,
      CODGENERAL,
      CODDOC,
      ICONT,
      SEMNIFICATIE,
      CODPART,
      CODGEST,
      CURS,
      TVA,
      STINS,
      VALOARE,
      MONEDA,
      TIPDOC,
      TERMEN
    FROM
      V_OBLIGPART_LA_DATA
   ) RG
  WHERE
     ROUND(NVL(VALOARE, 0), 4) - ROUND(NVL(STINS, 0), 4) &lt;&gt; 0;
--     AND CONDITIE_AVIZE(RG.ICONT) = 1;

   FOR V_REC IN (SELECT * FROM TMP_OBLIGPART_LA_DATA)
   LOOP
     aPREFIXDOC   := NULL;
     aDATADOC     := NULL;
     aNRDOC       := NULL;
     aSUBUNITATEA := NULL;

     IF V_REC.SEMNIFICATIE IN (100, 110, 140) THEN
       BEGIN
         SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM INTRARI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODINTR = G.CODDOC;
         EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
       END;
     ELSE
       IF V_REC.SEMNIFICATIE IN (130) THEN
          BEGIN
            SELECT &apos;DVI&apos;, I.DATADOC, I.NRDOC, INTR.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM DVI I, GENERAL G, INTRARI INTR WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODDVI = G.CODDOC AND INTR.CODINTR = I.CODINTR;
            EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
          END;
       ELSE
          IF V_REC.SEMNIFICATIE IN (200, 210, 240) THEN
            BEGIN
              SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM IESIRI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODIES = G.CODDOC;
              EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL;
            END;
          ELSE
            IF V_REC.SEMNIFICATIE IN (310, 410, 330, 430) THEN
              BEGIN
                SELECT SUBSTR(T1.DOC, 1, 2),  T1.DATADOC, T1.NRDOC, T.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM TREZOR1 T1, GENERAL G, TREZOR T WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
                EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
              END;
            ELSE
              IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
                BEGIN
                  SELECT &apos;NC&apos;, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM NC1 N1, GENERAL G, NC N WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODNC1 = G.CODDOC AND N1.CODNC = N.CODNC;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
                END;
              ELSE
                     IF V_REC.SEMNIFICATIE = 1303 THEN
                       BEGIN
                         SELECT
                            I.PREFIXDOC, I.DATADOC, I.NRDOC, I.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
                          FROM
                            OBLIGPIF O
                             LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                             LEFT OUTER JOIN OBLIGPIF OA ON OA.CODOBLIGPIF = O.CODOBLIGASOCIAT
                             LEFT OUTER JOIN GENERAL GA ON GA.CODGENERAL = OA.CODGENERAL
                             LEFT OUTER JOIN IESIRI I ON I.CODIES = GA.CODDOC
                          WHERE
                            G.CODGENERAL = V_REC.CODGENERAL;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL;
                        END;
                      ELSE
                BEGIN -- compensari
                  SELECT &apos;PV&apos;, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM COMPENS, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODCOMPENS = G.CODDOC;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
                END;
                      END IF;
              END IF;
            END IF;
          END IF;
       END IF;
     END IF;

     UPDATE TMP_OBLIGPART_LA_DATA OB
     SET
       PREFIXDOC    = aPREFIXDOC,
       DATADOC      = aDATADOC,
       NRDOC        = aNRDOC,
       SUBUNITATEA  = aSUBUNITATEA,
       CONT         = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))
     WHERE CODGENERAL   = V_REC.CODGENERAL;
   END LOOP;


END;

PROCEDURE MAKE_SOLD_PART_SUB IS
  vAnTemp   NUMBER(4)   := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)   := PKG_GLOBALS.GetLUNATEMP;
  sAN       VARCHAR2(5) := TO_CHAR(vAnTemp);
  sLUNA     VARCHAR2(5) := TO_CHAR(vLunaTemp);
  LASTDAY   DATE        := LAST_DAY(TO_DATE(&apos;01.&apos; || SLUNA || &apos;.&apos; || SAN, &apos;DD.MM.YYYY&apos;));
BEGIN
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(LASTDAY, &apos;DD.MM.YYYY&apos;));
  PKG_REGPART.MAKE_INFO_STINSE_LUNA;

  DELETE FROM NPARTSOLDLUNASUB WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO NPARTSOLDLUNASUB(CODPARTSOLDLUNASUB, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA, AN, LUNA)
  (SELECT SEQ_NPARTSOLDLUNASUB_COD.NextVal, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA, vAnTemp, vLunaTemp
  FROM V_SOLDPART_SUB);
  COMMIT;
END;


PROCEDURE MAKE_SOLD_PART_SUB_EXT IS
  NR        NUMBER(10) := 0;
  vAnTemp   NUMBER(4)  := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)  := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;

  DELETE FROM NPARTSOLDLUNASUB WHERE AN = vAnTemp AND LUNA = vLunaTemp;

  INSERT INTO NPARTSOLDLUNASUB(CODPARTSOLDLUNASUB, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, SUBUNITATEA, AN, LUNA)
  SELECT SEQ_NPARTSOLDLUNASUB_COD.NextVal, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, SUBUNITATEA, vAnTemp, vLunaTemp
  FROM V_SOLDPARTSUB_EXT;

  -- ajustari IFRS pe moneda=0
  FOR V_REC IN (SELECT * FROM V_SOLDPARTSUB_IFRS)
  LOOP
    SELECT COUNT(1) INTO NR FROM NPARTSOLDLUNASUB WHERE CODPART = V_REC.CODPART AND ICONT = V_REC.ICONT AND CODMONEDA = 0 AND SUBUNITATEA = V_REC.SUBUNITATEA AND AN = vAnTemp AND LUNA = vLunaTemp;

    IF NR = 0 THEN
      INSERT INTO NPARTSOLDLUNASUB (CODPARTSOLDLUNASUB, CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, SOLD_IFRS, AN, LUNA)
      VALUES (SEQ_NPARTSOLDLUNASUB_COD.NEXTVAL, V_REC.CODPART, V_REC.ICONT, 0, V_REC.SUBUNITATEA, 0, 0, V_REC.SOLD_IFRS, vAnTemp, vLunaTemp);
    ELSE
      UPDATE NPARTSOLDLUNASUB SET SOLD_IFRS = V_REC.SOLD_IFRS WHERE CODPART = V_REC.CODPART AND ICONT = V_REC.ICONT AND CODMONEDA = 0 AND AN = vAnTemp AND LUNA = vLunaTemp AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END IF;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_AVIZINT_LUNA IS
  vAnPrec   NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  bLunaIni  NUMBER(1);
BEGIN
  SELECT Count(1) INTO bLunaIni FROM FIRMALUNI WHERE ANINITIAL = vAnTemp AND LUNAINITIALA = vLunaTemp;
  IF bLunaIni = 1 THEN
    DELETE FROM AVIZINTLUNA WHERE AN = vAnPrec AND LUNA = vLunaPrec;

    INSERT INTO AVIZINTLUNA (CODINTR1, REST, AN, LUNA)
    SELECT I1.CODINTR1, I1.CANT REST, vAnPrec,  vLunaPrec -- AVIZE DIN LUNA INITIALIZARE
    FROM INTRARI I INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
    WHERE I.AN = vAnPrec AND I.LUNA = vLunaPrec AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2;
  END IF;

  DELETE FROM AVIZINTLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO AVIZINTLUNA (CODINTR1, REST, AN, LUNA)
  SELECT CODINTR1, SUM(REST) AS REST, vAnTemp, vLunaTemp
  FROM (
    SELECT
      CODINTR1, -- DIN LUNA PREC
      REST
    FROM AVIZINTLUNA
    WHERE AN = vAnPrec AND LUNA = vLunaPrec
    UNION ALL
    SELECT
      CASE
        WHEN Coalesce(I1.CODINTR1STORNO, 0) = 0 THEN I1.CODINTR1       -- AVIZE CREATE IN LUNA ANALIZATA
        ELSE                                         I1.CODINTR1STORNO -- AVIZE STORNATE IN LUNA ANALIZATA
      END CODINTR1,
      I1.CANT AS REST
    FROM INTRARI I INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
    WHERE I.AN = vAnTemp AND I.LUNA = vLunaTemp AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2 --PT Index complet am pus contie extra si pe operat si anulat / STEF 15.01.2022
    UNION ALL
    SELECT
      IL.CODLINIEAVIZ AS CODINTR1, -- AVIZE STINSE IN LUNA ANALIZATA
      -IL.CANT AS REST
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      INNER JOIN INTRLINK IL ON IL.CODINTR1 = I1.CODINTR1
    WHERE I.AN = vAnTemp AND I.LUNA = vLunaTemp AND I.OPERAT = 1 AND I.ANULAT = 0 AND (I.TIPDOC = 9 OR (I.TIPDOC = 5 AND I.TIPFACTURA = 10))
  )
  GROUP BY CODINTR1;
  COMMIT;
END;

PROCEDURE REPARE_AVIZIES_STORNO IS
BEGIN
  FOR v_rec IN (
    SELECT ee.CodIes1, ee.codies1storno, ee.Cant
    FROM iesiri1 ee INNER JOIN iesiri e on e.codies = ee.codies and e.custodie = 1
    WHERE ee.cant &lt; 0 and nvl(ee.codies1storno,0) &gt; 0
  ) LOOP
    UPDATE Iesiri1 SET RestFact = RestFact - v_rec.Cant WHERE Codies1 = v_rec.codies1storno;
    UPDATE Iesiri1 SET codies1storno=0 WHERE Codies1 = v_rec.codies1;
  END LOOP;
  COMMIT;
END;

PROCEDURE MAKE_AVIZIES_LUNA IS
  vAnPrec   NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  bLunaIni  NUMBER(1);
BEGIN
  SELECT Count(1) INTO bLunaIni FROM FIRMALUNI WHERE ANINITIAL = vAnTemp AND LUNAINITIALA = vLunaTemp;
  IF bLunaIni = 1 THEN
    DELETE FROM AVIZIESLUNA WHERE AN = vAnPrec AND LUNA = vLunaPrec;

    INSERT INTO AVIZIESLUNA (CODIES1, REST, AN, LUNA)
    SELECT I1.CODIES1, I1.CANT REST, vAnPrec,  vLunaPrec -- AVIZE DIN LUNA INITIALIZARE
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE I.AN = vAnPrec AND I.LUNA = vLunaPrec AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 20;
  END IF;

  DELETE FROM AVIZIESLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO AVIZIESLUNA (CODIES1, REST, AN, LUNA)
  SELECT CODIES1, SUM(REST) AS REST, vAnTemp, vLunaTemp
  FROM (
    SELECT CODIES1, REST -- RESTURI AVIZE DIN LUNA PREC
    FROM AVIZIESLUNA
    WHERE AN = vAnPrec AND LUNA = vLunaPrec
    UNION ALL
    SELECT
      CASE
        WHEN Coalesce(I1.CODIES1STORNO, 0) = 0 THEN I1.CODIES1       -- AVIZE CREATE IN LUNA ANALIZATA
        ELSE                                        I1.CODIES1STORNO -- AVIZE STORNATE IN LUNA ANALIZATA
      END CODIES1,
      I1.CANT REST
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE I.AN = vAnTemp AND I.LUNA = vLunaTemp AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 20
    UNION ALL
    SELECT IL.CODLINIEAVIZ CODIES1, -IL.CANT REST -- AVIZE STINSE IN LUNA ANALIZATA
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
      INNER JOIN IESLINK IL ON IL.CODIES1 = I1.CODIES1
    WHERE I.AN = vAnTemp AND I.LUNA = vLunaTemp AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 26
  )
  GROUP BY CODIES1;
  COMMIT;
END;

PROCEDURE MAKE_COMANDA1_LUNA IS
  vAnPrec   NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  DELETE FROM COMANDA1LUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO COMANDA1LUNA (CODCOMANDA1, REST, AN, LUNA)
  SELECT CODCOMANDA1, SUM(REST) AS REST, vAnTemp, vLunaTemp
  FROM (
    SELECT CODCOMANDA1, REST -- DIN LUNA PREC
    FROM COMANDA1LUNA
    WHERE AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = vLunaPrec AND REST &lt;&gt; 0
    UNION ALL
    SELECT CODCOMANDA1, CANTACCEPTAT REST -- COMENZI CREATE IN LUNA ANALIZATA
    FROM COMANDA1 C1, COMANDA C
    WHERE C1.CODCOMANDA = C.CODCOMANDA
      AND C.TIPDOC  IN (8, 18, 43, 44)
      AND C.AN = vAnTemp AND C.LUNA = vLunaTemp
    UNION ALL
    SELECT IL.CODLINIECOMANDA CODCOMANDA1, -IL.CANT REST -- COMENZI STINSE IN LUNA ANALIZATA -- COMENZI FURNIZORI
    FROM INTRLINK IL, INTRARI1 I1, INTRARI I
    WHERE IL.CODINTR1 = I1.CODINTR1
      AND I1.CODINTR = I.CODINTR
      AND I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 9)
      AND I.AN = vAnTemp AND I.LUNA = vLunaTemp
    UNION ALL
    SELECT IL.CODLINIECOMANDA CODCOMANDA1, -IL.CANT REST -- COMENZI CLIENTI + COMENZI SUBUNITATI
    FROM IESLINK IL, IESIRI1 I1, IESIRI I
    WHERE IL.CODIES1 = I1.CODIES1
      AND I1.CODIES = I.CODIES
      AND I.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26)
      AND I.AN = vAnTemp AND I.LUNA = vLunaTemp
    UNION ALL
    SELECT TL.CODLINIECOMANDA CODCOMANDA1, -TL.CANT REST -- COMENZI GESTIUNI
    FROM TRANSFLINK TL, TRANSF1 T1, TRANSF T
    WHERE TL.CODTRANSF1 = T1.CODTRANSF1
      AND T1.CODTRANSF = T.CODTRANSF
      AND T.TIPDOC = 12
      AND T.AN = vAnTemp AND T.LUNA = vLunaTemp
  )
  GROUP BY CODCOMANDA1;
  COMMIT;
END;

PROCEDURE MAKE_STOC_LUNA IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  DELETE FROM NIRLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;

  INSERT INTO NIRLUNA(CODNIRSTOC, REST, RESTUM1, RESTUM2, AN, LUNA)
  SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2, vAnTemp, vLunaTemp
  FROM V_STOCLUNA;

  DELETE FROM NIRSERLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;

  INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2, AN, LUNA)
  SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2, vAnTemp, vLunaTemp
  FROM V_STOCSER_LUNA;

  COMMIT;
END;

PROCEDURE MAKE_STOC_LUNA_EXT IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
--  EXECUTE IMMEDIATE &apos;ALTER TABLE NIRLUNA NOLOGGING&apos;;
--  EXECUTE IMMEDIATE &apos;ALTER TABLE NIRSERLUNA NOLOGGING&apos;;

  DELETE FROM NIRLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_NIRURI_LUNA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LIVRARI_LUNA&apos;;

  INSERT INTO TMP_NIRURI_LUNA (CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM (
    SELECT * FROM V_STOC_LUNA_PREC UNION ALL
    SELECT * FROM V_NIRURI_LUNA
  )
  GROUP BY CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_LUNA (CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM V_LIVRARI_LUNA
  GROUP BY CODNIRSTOC;

  FOR V_REC IN (
    SELECT N.CODNIRSTOC, Coalesce(N.REST,0) REST, Coalesce(N.RESTUM1,0) RESTUM1, Coalesce(N.RESTUM2,0) RESTUM2, Coalesce(L.REST,0) RESTL, Coalesce(L.RESTUM1,0) RESTL1, Coalesce(L.RESTUM2,0) RESTL2
    FROM TMP_NIRURI_LUNA N LEFT JOIN TMP_LIVRARI_LUNA L ON L.CODNIRSTOC = N.CODNIRSTOC
  ) LOOP
    INSERT /*+APPEND*/ INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES (V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, V_REC.REST + V_REC.RESTL, V_REC.RESTUM1 + V_REC.RESTL1, V_REC.RESTUM2 + V_REC.RESTL2);
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_LIVRARI_LUNA L WHERE NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRURI_LUNA N WHERE N.CODNIRSTOC = L.CODNIRSTOC))
  LOOP
    INSERT  /*+APPEND*/ INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES (V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, Coalesce(V_REC.REST,    0), Coalesce(V_REC.RESTUM1, 0), Coalesce(V_REC.RESTUM2, 0) );
  END LOOP;

  DELETE FROM NIRSERLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_NIRURI_SER_LUNA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LIVRARI_SER_LUNA&apos;;

  INSERT INTO TMP_NIRURI_SER_LUNA (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM(
    SELECT * FROM V_STOCSER_LUNA_PREC UNION ALL
    SELECT * FROM V_NIRURI_SER_LUNA
  )
  GROUP BY CODNIRSER, CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_SER_LUNA (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2) SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2 FROM V_LIVRARI_SER_LUNA GROUP BY CODNIRSER, CODNIRSTOC;

  FOR V_REC IN (
    SELECT N.CODNIRSER, N.CODNIRSTOC, Coalesce(N.REST,0) REST, Coalesce(N.RESTUM1,0) RESTUM1, Coalesce(N.RESTUM2,0) RESTUM2, Coalesce(L.REST,0) RESTL, Coalesce(L.RESTUM1,0) RESTL1, Coalesce(L.RESTUM2,0) RESTL2
    FROM TMP_NIRURI_SER_LUNA N LEFT OUTER JOIN TMP_LIVRARI_SER_LUNA L ON L.CODNIRSER = N.CODNIRSER AND L.CODNIRSTOC = N.CODNIRSTOC
  )
  LOOP
    INSERT /*+APPEND*/ INTO NIRSERLUNA ( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES ( V_REC.CODNIRSER, V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, V_REC.REST + V_REC.RESTL, V_REC.RESTUM1 + V_REC.RESTL1, V_REC.RESTUM2 + V_REC.RESTL2 );
  END LOOP;

  FOR V_REC IN (
    SELECT * FROM TMP_LIVRARI_SER_LUNA L
    WHERE NOT EXISTS (SELECT * FROM TMP_NIRURI_SER_LUNA N WHERE N.CODNIRSER = L.CODNIRSER AND N.CODNIRSTOC = L.CODNIRSTOC)
  ) LOOP
    INSERT /*+APPEND*/ INTO NIRSERLUNA( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES ( V_REC.CODNIRSER, V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, Coalesce(V_REC.REST, 0), Coalesce(V_REC.RESTUM1, 0), Coalesce(V_REC.RESTUM2, 0) );
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_STOC_LUNA_PRAGMA IS
PRAGMA AUTONOMOUS_TRANSACTION;
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN

  DELETE FROM NIRLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  DELETE TMP_NIRURI_LUNA;
  DELETE TMP_LIVRARI_LUNA;

  INSERT INTO TMP_NIRURI_LUNA (CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM (
    SELECT * FROM V_STOC_LUNA_PREC
    UNION ALL
    SELECT * FROM V_NIRURI_LUNA
  )
  GROUP BY CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_LUNA (CODNIRSTOC, REST, RESTUM1, RESTUM2) SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2 FROM V_LIVRARI_LUNA GROUP BY CODNIRSTOC;

  FOR V_REC IN (
    SELECT N.CODNIRSTOC, Nvl(N.REST,0) REST, Nvl(N.RESTUM1,0) RESTUM1, Nvl(N.RESTUM2,0) RESTUM2, Nvl(L.REST,0) RESTL, Nvl(L.RESTUM1,0) RESTL1, Nvl(L.RESTUM2,0) RESTL2
    FROM TMP_NIRURI_LUNA N LEFT OUTER JOIN TMP_LIVRARI_LUNA L ON L.CODNIRSTOC = N.CODNIRSTOC
  ) LOOP
    INSERT /*+APPEND*/ INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES (V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, V_REC.REST + V_REC.RESTL, V_REC.RESTUM1 + V_REC.RESTL1, V_REC.RESTUM2 + V_REC.RESTL2);
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_LIVRARI_LUNA L WHERE NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRURI_LUNA N WHERE N.CODNIRSTOC = L.CODNIRSTOC))
  LOOP
    INSERT  /*+APPEND*/ INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES (V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, NVL(V_REC.REST,    0), NVL(V_REC.RESTUM1, 0), NVL(V_REC.RESTUM2, 0) );
  END LOOP;
  DELETE FROM NIRSERLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  DELETE TMP_NIRURI_SER_LUNA;
  DELETE TMP_LIVRARI_SER_LUNA;


  INSERT INTO TMP_NIRURI_SER_LUNA (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM(
    SELECT * FROM V_STOCSER_LUNA_PREC
    UNION ALL
    SELECT * FROM V_NIRURI_SER_LUNA
  )
  GROUP BY CODNIRSER, CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_SER_LUNA (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2) SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2 FROM V_LIVRARI_SER_LUNA GROUP BY CODNIRSER, CODNIRSTOC;

  FOR V_REC IN (
    SELECT N.CODNIRSER, N.CODNIRSTOC, Nvl(N.REST,0) REST, Nvl(N.RESTUM1,0) RESTUM1, Nvl(N.RESTUM2,0) RESTUM2, Nvl(L.REST,0) RESTL, Nvl(L.RESTUM1,0) RESTL1, Nvl(L.RESTUM2,0) RESTL2
    FROM TMP_NIRURI_SER_LUNA N LEFT OUTER JOIN TMP_LIVRARI_SER_LUNA L ON L.CODNIRSER = N.CODNIRSER AND L.CODNIRSTOC = N.CODNIRSTOC
  )
  LOOP
    INSERT /*+APPEND*/ INTO NIRSERLUNA ( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES ( V_REC.CODNIRSER, V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, V_REC.REST + V_REC.RESTL, V_REC.RESTUM1 + V_REC.RESTL1, V_REC.RESTUM2 + V_REC.RESTL2 );
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_LIVRARI_SER_LUNA L WHERE NOT EXISTS (SELECT * FROM TMP_NIRURI_SER_LUNA N WHERE N.CODNIRSER = L.CODNIRSER AND N.CODNIRSTOC = L.CODNIRSTOC))
  LOOP
    INSERT /*+APPEND*/ INTO NIRSERLUNA( CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
    VALUES ( V_REC.CODNIRSER, V_REC.CODNIRSTOC, vAnTemp, vLunaTemp, NVL(V_REC.REST, 0), NVL(V_REC.RESTUM1, 0), NVL(V_REC.RESTUM2, 0) );
  END LOOP;
  COMMIT;
END;

PROCEDURE MAKE_REST_OBLIGPIF_LUNA
IS
  vAnTemp   NUMBER(4)    := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)    := PKG_GLOBALS.GetLUNATEMP;
  aMARJA    VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;IgnorSoldAvizMic&apos;, vANTEMP, vLUNATEMP), &apos;0&apos;);
BEGIN
  DELETE FROM OBLIGPIFLUNA WHERE AN = vANTEMP AND LUNA = vLUNATEMP;

  INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA, AN, LUNA)
  SELECT CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA, vANTEMP, vLUNATEMP
  FROM V_REST_OBLIGPIF_LUNA;

  IF aMARJA = &apos;1&apos; THEN
    FOR V_REC IN (
      SELECT CODOBLIGPIF
      FROM (
        SELECT OL.CODOBLIGPIF, (SELECT Sum(I1.RESTFACT) FROM INTRARI1 I1 WHERE I1.CODINTR = G.CODDOC) RESTFACT
        FROM OBLIGPIFLUNA OL
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
        WHERE OL.AN = vANTEMP AND OL.LUNA = vLUNATEMP
          AND OL.REST &lt;&gt; 0 AND OL.REST &lt;= 0.1 AND OL.REST &gt;= -0.1
          AND O.SEMNIFICATIE = 140 AND O.ICONT = 6
          AND G.TIPDOC = 2
      )  ssub
      WHERE RESTFACT = 0
    )LOOP
      UPDATE OBLIGPIFLUNA
      SET REST = 0
      WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = vANTEMP AND LUNA = vLUNATEMP;
    END LOOP;

    FOR V_REC IN (
      SELECT CODOBLIGPIF
      FROM (
        SELECT OL.CODOBLIGPIF, (SELECT Sum(I1.RESTFACT) FROM IESIRI1 I1 WHERE I1.CODIES = G.CODDOC) RESTFACT
        FROM OBLIGPIFLUNA OL
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
        WHERE OL.AN = vANTEMP AND OL.LUNA = vLUNATEMP
          AND OL.REST &lt;&gt; 0 AND OL.REST &lt;= 0.1 AND OL.REST &gt;= -0.1
          AND O.SEMNIFICATIE = 240 AND O.ICONT = 7
          AND G.TIPDOC = 20
      )  ssub
      WHERE RESTFACT = 0
    ) LOOP
      UPDATE OBLIGPIFLUNA
      SET REST = 0
      WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = vANTEMP AND LUNA = vLUNATEMP;
    END LOOP;
  END IF;
  COMMIT;

  IF PKG_GLOBALS.g_SplitTVAFirma = 1 THEN
    PKG_SPLITTVA.MAKE_DINCARETVA_LUNA_ALL(0);
  ELSE
    FOR V_REC IN (
      SELECT * FROM NPART WHERE COALESCE(SPLITTVA, 0) = 1
    ) LOOP
      PKG_SPLITTVA.MAKE_DINCARETVA_LUNA(V_REC.CODPART);
    END LOOP;
  END IF;
END;

/*
PROCEDURE MAKE_STOC_MOMENT
IS
BEGIN
  UPDATE NIRSTOC NS SET REST = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR);
  COMMIT;
END;
*/



PROCEDURE MAKE_STOC_MOMENT_EXT
IS
BEGIN
  DELETE TMP_LIVRAT;
  DELETE TMP_LIVRAT_SER;
  DELETE TMP_MARIRI;
  DELETE TMP_MARIRI_SER;

  INSERT INTO TMP_LIVRAT
    SELECT
     CODNIRSTOC,
     NVL(SUM(CANT), 0),
     NVL(SUM(CANTUM1), 0),
     NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSTOC;

  INSERT INTO TMP_LIVRAT_SER
    SELECT
    CODNIRSER,
    NVL(SUM(CANT), 0),
    NVL(SUM(CANTUM1), 0),
    NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSER;



  INSERT INTO TMP_MARIRI
    SELECT
      CODNIRSTOC,
      NVL(SUM(CANT), 0),
      NVL(SUM(CANTUM1), 0),
      NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSTOC;

  INSERT INTO TMP_MARIRI_SER
    SELECT
      CODNIRSER,
      NVL(SUM(CANT), 0),
      NVL(SUM(CANTUM1), 0),
      NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSER;

  FOR V_REC IN
  (
  SELECT
    NS.CODNIRSTOC,
    NS.CANTNIR,
    N.OPERAT,
    NVL(L.CANT, 0) AS LIVRAT,
    NVL(M.CANT, 0) AS MARIRI,
    NVL(L.CANTUM1, 0) AS LIVRATUM1,
    NVL(M.CANTUM1, 0) AS MARIRIUM1,
    NVL(L.CANTUM2, 0) AS LIVRATUM2,
    NVL(M.CANTUM2, 0) AS MARIRIUM2
  FROM
    NIRSTOC NS
    LEFT OUTER JOIN TMP_LIVRAT  L ON L.CODNIRSTOC = NS.CODNIRSTOC
    LEFT OUTER JOIN TMP_MARIRI  M ON M.CODNIRSTOC = NS.CODNIRSTOC,
    NIR N
  WHERE
  N.CODNIR = NS.CODNIR)
  LOOP
    IF V_REC.OPERAT = 1 THEN
      UPDATE NIRSTOC
      SET
        REST    = CANTNIR - V_REC.LIVRAT + V_REC.MARIRI,
        RESTUM1 = CANTUM1 - V_REC.LIVRATUM1 + V_REC.MARIRIUM1,
        RESTUM2 = CANTUM2 - V_REC.LIVRATUM2 + V_REC.MARIRIUM2
      WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
    ELSE
      UPDATE NIRSTOC
      SET
        REST = 0,
        RESTUM1 = 0,
        RESTUM2 = 0
      WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;
  END LOOP;

  FOR V_REC IN
  (
  SELECT
    NSE.CODNIRSER,
    NSE.CANTNIR,
    NVL(L.CANT, 0) AS LIVRAT,
    NVL(L.CANTUM1, 0) AS LIVRATUM1,
    NVL(L.CANTUM2, 0) AS LIVRATUM2,
    NVL(M.CANT, 0) AS MARIRI,
    NVL(M.CANTUM1, 0) AS MARIRIUM1,
    NVL(M.CANTUM2, 0) AS MARIRIUM2,
    N.OPERAT
  FROM
    NIRSER NSE
    LEFT OUTER JOIN TMP_LIVRAT_SER  L ON L.CODNIRSER = NSE.CODNIRSER
    LEFT OUTER JOIN TMP_MARIRI_SER  M ON M.CODNIRSER = NSE.CODNIRSER,
    NIRSTOC NS,
    NIR N
  WHERE
    NSE.CODNIRSTOC = NS.CODNIRSTOC AND N.CODNIR = NS.CODNIR
)
  LOOP
    IF V_REC.OPERAT = 1 THEN
      UPDATE NIRSER
      SET
        REST    = CANTNIR - V_REC.LIVRAT + V_REC.MARIRI,
        RESTUM1 = CANTUM1 - V_REC.LIVRATUM1 + V_REC.MARIRIUM1,
        RESTUM2 = CANTUM2 - V_REC.LIVRATUM2 + V_REC.MARIRIUM2
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    ELSE
      UPDATE NIRSER
      SET
        REST = 0,
        RESTUM1 = 0,
        RESTUM2 = 0
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    END IF;
  END LOOP;
  COMMIT;
END;


PROCEDURE MAKE_STOC_MOMENT
IS
BEGIN
  DELETE TMP_LIVRAT;
  DELETE TMP_LIVRAT_SER;
  DELETE TMP_MARIRI;
  DELETE TMP_MARIRI_SER;

  INSERT INTO TMP_LIVRAT
    SELECT
     CODNIRSTOC,
     NVL(SUM(CANT), 0),
     NVL(SUM(CANTUM1), 0),
     NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSTOC;

  INSERT INTO TMP_LIVRAT_SER
    SELECT
    CODNIRSER,
    NVL(SUM(CANT), 0),
    NVL(SUM(CANTUM1), 0),
    NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSER;



  INSERT INTO TMP_MARIRI
    SELECT
      CODNIRSTOC,
      NVL(SUM(CANT), 0),
      NVL(SUM(CANTUM1), 0),
      NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSTOC;

  INSERT INTO TMP_MARIRI_SER
    SELECT
      CODNIRSER,
      NVL(SUM(CANT), 0),
      NVL(SUM(CANTUM1), 0),
      NVL(SUM(CANTUM2), 0)
     FROM
       LIVR1 l1,
       LIVR l
     WHERE
       l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0
     GROUP BY CODNIRSER;

  FOR V_REC IN
  (
  SELECT
    NS.CODNIRSTOC,
    NS.CANTNIR,
    N.OPERAT,
    NVL(L.CANT, 0) AS LIVRAT,
    NVL(M.CANT, 0) AS MARIRI,
    NVL(L.CANTUM1, 0) AS LIVRATUM1,
    NVL(M.CANTUM1, 0) AS MARIRIUM1,
    NVL(L.CANTUM2, 0) AS LIVRATUM2,
    NVL(M.CANTUM2, 0) AS MARIRIUM2
  FROM
    NIRSTOC NS
    LEFT OUTER JOIN TMP_LIVRAT  L ON L.CODNIRSTOC = NS.CODNIRSTOC
    LEFT OUTER JOIN TMP_MARIRI  M ON M.CODNIRSTOC = NS.CODNIRSTOC,
    NIR N
  WHERE
  N.CODNIR = NS.CODNIR)
  LOOP
    IF V_REC.OPERAT = 1 THEN
      UPDATE NIRSTOC
      SET
        REST    = CANTNIR - V_REC.LIVRAT + V_REC.MARIRI,
        RESTUM1 = CANTUM1 - V_REC.LIVRATUM1 + V_REC.MARIRIUM1,
        RESTUM2 = CANTUM2 - V_REC.LIVRATUM2 + V_REC.MARIRIUM2
      WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
    ELSE
      UPDATE NIRSTOC
      SET
        REST = 0,
        RESTUM1 = 0,
        RESTUM2 = 0
      WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;
  END LOOP;

  FOR V_REC IN
  (
  SELECT
    NSE.CODNIRSER,
    NSE.CANTNIR,
    NVL(L.CANT, 0) AS LIVRAT,
    NVL(L.CANTUM1, 0) AS LIVRATUM1,
    NVL(L.CANTUM2, 0) AS LIVRATUM2,
    NVL(M.CANT, 0) AS MARIRI,
    NVL(M.CANTUM1, 0) AS MARIRIUM1,
    NVL(M.CANTUM2, 0) AS MARIRIUM2,
    N.OPERAT
  FROM
    NIRSER NSE
    LEFT OUTER JOIN TMP_LIVRAT_SER  L ON L.CODNIRSER = NSE.CODNIRSER
    LEFT OUTER JOIN TMP_MARIRI_SER  M ON M.CODNIRSER = NSE.CODNIRSER,
    NIRSTOC NS,
    NIR N
  WHERE
    NSE.CODNIRSTOC = NS.CODNIRSTOC AND N.CODNIR = NS.CODNIR
)
  LOOP
    IF V_REC.OPERAT = 1 THEN
      UPDATE NIRSER
      SET
        REST    = CANTNIR - V_REC.LIVRAT + V_REC.MARIRI,
        RESTUM1 = CANTUM1 - V_REC.LIVRATUM1 + V_REC.MARIRIUM1,
        RESTUM2 = CANTUM2 - V_REC.LIVRATUM2 + V_REC.MARIRIUM2
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    ELSE
      UPDATE NIRSER
      SET
        REST = 0,
        RESTUM1 = 0,
        RESTUM2 = 0
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    END IF;
  END LOOP;
  COMMIT;
END;


PROCEDURE MAKE_PMP_LUNA IS
  aCANTINTR    NUMBER(20, 7);
  aCANT        NUMBER(20, 7);
  aVALINTR     NUMBER(20, 7);
  CANTINTRPREC NUMBER(20, 7) := 0;
  VALINTRPREC  NUMBER(20, 7) := 0;
  NR           NUMBER(20) := 0;
  aValValuta   number(20,7) := 0;
  K            Varchar2(5);
  kTipPMP      Varchar2(5);
  vAnPrec      NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec    NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp      NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp    NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  vALTemp      NUMBER(5) := vAnTemp * 12 + vLunaTemp;
  xAn          NUMBER(4) := CASE WHEN vLunaTemp = 12 THEN vAnTemp   + 1 ELSE vAnTemp END;
  xLu          NUMBER(2) := CASE WHEN vLunaTemp &lt; 12 THEN vLunaTemp + 1 ELSE 1       END;
BEGIN
  SELECT Count(1) INTO Nr FROM JURNAL1 WHERE CODDOC = -999 AND AN = xAN AND LUNA = xLU;
  IF NR = 0 THEN
    INSERT INTO
    JURNAL1(CodJurnal1, coddoc, tipdoc, SUBUNITATEA, AN, LUNA)
    VALUES (SEQ_JURNAL1_CODJURNAL1.Nextval, -999, -9, 2, xAN, xLU);
  ELSE
    UPDATE jurnal1 SET dirty = 1 WHERE coddoc = -999 AND tipdoc = -9 AND AN = xAn AND LUNA = xLU;
  END IF;
  DELETE FROM PMPLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TIPPMP&apos;);
  BEGIN
    SELECT Valoare into K from TMP_CONSTANTE where SIMBOL = &apos;TRANSFPMP&apos; and AnLuna = vALTemp;
  EXCEPTION WHEN OTHERS
    THEN K := &apos;0&apos;;
  END;
  BEGIN
    Select Valoare into kTipPMP from TMP_CONSTANTE where SIMBOL = &apos;TIPPMP&apos; and AnLuna = vALTemp;
  EXCEPTION WHEN OTHERS
    THEN kTipPMP := &apos;1&apos;;
  END;

  IF K &lt;&gt; &apos;3&apos; or kTipPMP = &apos;2&apos; THEN
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA,VALVALUTA)
    SELECT SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, vAnTemp, vLunaTemp, VALVALUTA
    FROM PMPLUNA
    WHERE AN = vAnPrec AND LUNA = vLunaPrec;

    FOR V_REC IN (
      SELECT * FROM V_PMP_LUNA
    ) LOOP
      BEGIN
        SELECT NVL(CANTINTR,0),  NVL(VALINTR, 0),nvl(valvaluta,0) INTO CANTINTRPREC, VALINTRPREC , aValValuta
        FROM PMPLUNA
        WHERE AN = vAnPrec AND LUNA = vLunaPrec AND CODOBIECT = V_REC.CODOBIECT AND CODSUBUNIT = V_REC.CODSUBUNIT;
        EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; aValValuta :=0;
      END;

      aCANT      := V_REC.CANTINTR + CANTINTRPREC;
      aCANTINTR  := V_REC.RESTLUNA + CANTINTRPREC;
      IF aCANT &lt;&gt; 0 THEN
        aVALINTR   := ((V_REC.VALINTR  + VALINTRPREC) / aCANT)*aCantIntr;
        aValValuta := ((V_REC.ValValuta  + aValValuta) / aCANT)*aCantIntr;
      ELSE
        aVALINTR   := 0;
        aValValuta := 0;
      END IF;

      BEGIN
        SELECT CODPMPLUNA INTO NR FROM PMPLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp AND CODOBIECT = V_REC.CODOBIECT AND CODSUBUNIT = V_REC.CODSUBUNIT;
      EXCEPTION
        WHEN OTHERS THEN NR := 0;
      END;

      IF NR = 0 THEN
        INSERT INTO PMPLUNA (
          CODPMPLUNA, CODOBIECT, CODSUBUNIT,
          CANTINTR,
          VALINTR,
          REST,
          AN, LUNA, VALVALUTA)
        VALUES (
          SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, V_REC.CODOBIECT, V_REC.CODSUBUNIT,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          aVALINTR,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          vAnTemp, vLunaTemp, aValValuta
        );
      ELSE
        UPDATE PMPLUNA
        SET CANTINTR  = aCANTINTR,
            VALINTR   = aVALINTR,
            REST      = aCANTINTR,
            ValValuta = aValValuta
        WHERE CODPMPLUNA = NR;
      END IF;
    END LOOP;
  ELSE --K = &apos;3&apos;--kTipPMP = firma
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, AN, LUNA, CANTINTR, VALINTR, VALVALUTA, REST)
    Select SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, CODOBIECT, CODSUBUNIT, AN, LUNA, CANTINTR, VALINTR, VALVALUTA, REST
    FROM (
      SELECT
        CODOBIECT, 1 CODSUBUNIT, vANTEMP AN, vLUNATEMP LUNA,
        SUM(Coalesce(CANTINTR,0)) CANTINTR,  SUM(Coalesce(VALINTR, 0)) VALINTR, SUM(Coalesce(valvaluta,0)) VALVALUTA,SUM(Coalesce(REST,0)) REST
      FROM PMPLUNA
      WHERE AN = vANPREC AND LUNA = vLUNAPREC
      GROUP BY CODOBIECT
    ) X;

    FOR V_REC IN (
      SELECT CODOBIECT, SUM(CANTINTR) CANTINTR, SUM(VALINTR) VALINTR, SUM(RESTLUNA) RESTLUNA, SUM(VALVALUTA) VALVALUTA
      FROM V_PMP_LUNA
      GROUP BY CODOBIECT
    ) LOOP
      BEGIN
        SELECT SUM(Coalesce(CANTINTR,0)), SUM(Coalesce(VALINTR, 0)), SUM(Coalesce(valvaluta,0)) INTO CANTINTRPREC, VALINTRPREC , aValValuta
        FROM PMPLUNA
        WHERE AN = vANPREC AND LUNA = vLUNAPREC AND CODOBIECT  = V_REC.CODOBIECT;
      EXCEPTION
        WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; aValValuta :=0;
      END;

      CANTINTRPREC := Coalesce(CANTINTRPREC,0);
      VALINTRPREC  := Coalesce(VALINTRPREC ,0);
      aValValuta   := Coalesce(aValValuta  ,0);
      aCANT        := V_REC.CANTINTR + CANTINTRPREC;
      aCANTINTR    := V_REC.RESTLUNA + CANTINTRPREC;
      IF aCANT &lt;&gt; 0 THEN
        aVALINTR   := ((V_REC.VALINTR   + VALINTRPREC) / aCANT)*aCantIntr;
        aValValuta := ((V_REC.ValValuta + aValValuta)  / aCANT)*aCantIntr;
      ELSE
        aVALINTR   := 0;
        aValValuta := 0;
      END IF;

      BEGIN
        SELECT CODPMPLUNA INTO NR
        FROM PMPLUNA
        WHERE AN = vANTEMP AND LUNA = vLUNATEMP AND CODOBIECT = V_REC.CODOBIECT;
      EXCEPTION
        WHEN OTHERS THEN NR := 0;
      END;

      IF NR = 0 THEN
        INSERT INTO PMPLUNA (
          CODPMPLUNA, CODOBIECT, CODSUBUNIT,
          CANTINTR,
          VALINTR,
          REST,
          AN, LUNA, VALVALUTA
        )
        VALUES (
          SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, V_REC.CODOBIECT, 1,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          aVALINTR,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          vANTEMP, vLUNATEMP, aValValuta
        );
      ELSE
        UPDATE PMPLUNA
        SET CANTINTR  = aCANTINTR,
            VALINTR   = aVALINTR,
            REST      = aCANTINTR,
            ValValuta = aValValuta
        WHERE CODPMPLUNA = NR;
      END IF;
    END LOOP;
  END IF;
  COMMIT;
END;

PROCEDURE MAKE_PMP_OBIECT_LUNA(aCODOBIECT IN NUMBER) IS
  aCANTINTR    NUMBER(20, 7);
  aCANT        NUMBER(20, 7);
  aVALINTR     NUMBER(20, 7);
  CANTINTRPREC NUMBER(20, 7) := 0;
  VALINTRPREC  NUMBER(20, 7) := 0;
  NR           NUMBER(20) := 0;
  aValValuta   number(20,7) := 0;
  K            Varchar2(5);
  kTipPMP      Varchar2(5);
  vAnPrec      NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec    NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp      NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp    NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  SET_CODOBIECT_PMP(aCODOBIECT);
  DELETE FROM PMPLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp
  AND CODOBIECT = aCODOBIECT;

  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TIPPMP&apos;);
  BEGIN
    Select Valoare into K from TMP_CONSTANTE where SIMBOL = &apos;TRANSFPMP&apos; and AnLuna = vAnTemp * 12 + vLunaTemp;
  EXCEPTION WHEN OTHERS
    THEN K := &apos;0&apos;;
  end;
  BEGIN
    Select Valoare into kTipPMP from TMP_CONSTANTE where SIMBOL = &apos;TIPPMP&apos; and AnLuna = vAnTemp * 12 + vLunaTemp;
  EXCEPTION WHEN OTHERS
    THEN kTipPMP := &apos;1&apos;;
  end;

  if K &lt;&gt; &apos;3&apos; or kTipPMP = &apos;2&apos; then
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA,VALVALUTA)
    SELECT SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, vAnTemp, vLunaTemp,VALVALUTA
    FROM
      PMPLUNA
    WHERE
        AN = vAnPrec
    AND LUNA = vLunaPrec
    AND CODOBIECT = aCODOBIECT;

      FOR V_REC IN
      (
        SELECT * FROM V_PMP_OBIECT_LUNA
      )
      LOOP
        BEGIN
          SELECT NVL(CANTINTR,0),  NVL(VALINTR, 0),nvl(valvaluta,0) INTO CANTINTRPREC, VALINTRPREC , aValValuta
          FROM
            PMPLUNA
          WHERE
            AN             = vAnPrec
            AND LUNA       = vLunaPrec
            AND CODOBIECT  = V_REC.CODOBIECT
            AND CODSUBUNIT = V_REC.CODSUBUNIT;
          EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; aValValuta :=0;
        END;


        aCANT      := V_REC.CANTINTR + CANTINTRPREC;
        aCANTINTR  := V_REC.RESTLUNA + CANTINTRPREC;
        IF aCANT &lt;&gt; 0 THEN
          aVALINTR   := ((V_REC.VALINTR  + VALINTRPREC) / aCANT)*aCantIntr;
          aValValuta := ((V_REC.ValValuta  + aValValuta) / aCANT)*aCantIntr;
        ELSE
          aVALINTR   := 0;
          aValValuta := 0;
        END IF;

        BEGIN
          SELECT CODPMPLUNA INTO NR
          FROM
            PMPLUNA
          WHERE
            AN            = vAnTemp
           AND LUNA       = vLunaTemp
           AND CODSUBUNIT = V_REC.CODSUBUNIT
           AND CODOBIECT  = V_REC.CODOBIECT;

         EXCEPTION WHEN OTHERS THEN NR := 0;
        END;
        IF NR = 0 THEN
           INSERT INTO PMPLUNA
           (
            CODPMPLUNA,
            CODOBIECT,
            CODSUBUNIT,
            CANTINTR,
            VALINTR,
            REST,
            AN,
            LUNA,
            VALVALUTA)
          VALUES
          ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL,
            V_REC.CODOBIECT,
            V_REC.CODSUBUNIT,
            aCANTINTR,
            aVALINTR,
            aCANTINTR,  -- care e chiar v_rec.RestLuna
            vAnTemp,
            vLunaTemp,
            aValValuta
          );
        ELSE
          UPDATE PMPLUNA
          SET
            CANTINTR  = aCANTINTR,
            VALINTR   = aVALINTR,
            REST      = aCANTINTR,
            ValValuta = aValValuta
          WHERE
            CODPMPLUNA = NR;
        END IF;
      END LOOP;
  ELSE
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, AN, LUNA,CANTINTR, VALINTR, VALVALUTA, REST)
    Select SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, X.*
    FROM
    (
    SELECT CODOBIECT, 1, vAnTemp,vLunaTemp,
    SUM(NVL(CANTINTR,0)),  SUM(NVL(VALINTR, 0)),SUM(nvl(valvaluta,0)),SUM(nvl(REST,0))
    FROM
      PMPLUNA
    WHERE
        AN = vAnPrec
        AND LUNA = vLunaPrec
        AND CODOBIECT  = aCODOBIECT
    GROUP BY CODOBIECT
    ) X;

    FOR V_REC IN
    (
     SELECT
     SUM(CANTINTR) CANTINTR,
     SUM(VALINTR)   VALINTR,
     SUM(RESTLUNA) RESTLUNA,
     SUM(VALVALUTA) VALVALUTA
     FROM V_PMP_OBIECT_LUNA
    )
    LOOP
      BEGIN
        SELECT SUM(NVL(CANTINTR,0)),  SUM(NVL(VALINTR, 0)),SUM(nvl(valvaluta,0)) INTO CANTINTRPREC, VALINTRPREC , aValValuta
        FROM
          PMPLUNA
        WHERE
          AN             = vAnPrec
          AND LUNA       = vLunaPrec
          AND CODOBIECT  = aCODOBIECT;
        EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; aValValuta :=0;
      END;


      CANTINTRPREC := NVL(CANTINTRPREC,0);
      VALINTRPREC  := NVL(VALINTRPREC ,0);
      aValValuta   := NVL(aValValuta  ,0);
      aCANT      := V_REC.CANTINTR + CANTINTRPREC;
      aCANTINTR  := V_REC.RESTLUNA + CANTINTRPREC;
      IF aCANT &lt;&gt; 0 THEN
        aVALINTR   := ((V_REC.VALINTR  + VALINTRPREC) / aCANT)*aCantIntr;
        aValValuta := ((V_REC.ValValuta  + aValValuta) / aCANT)*aCantIntr;
      ELSE
        aVALINTR   := 0;
        aValValuta := 0;
      END IF;

      BEGIN
        SELECT CODPMPLUNA INTO NR
        FROM
          PMPLUNA
        WHERE
          AN            = vAnTemp
         AND LUNA       = vLunaTemp
         AND CODOBIECT  = aCODOBIECT;

       EXCEPTION WHEN OTHERS THEN NR := 0;
      END;
      IF NR = 0 THEN
         INSERT INTO PMPLUNA
         (
          CODPMPLUNA,
          CODOBIECT,
          CODSUBUNIT,
          CANTINTR,
          VALINTR,
          REST,
          AN,
          LUNA,
          VALVALUTA)
        VALUES
        ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL,
          aCODOBIECT,
          1,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          aVALINTR,
          aCANTINTR,  -- care e chiar v_rec.RestLuna
          vAnTemp,
          vLunaTemp,
          aValValuta
        );
      ELSE
        UPDATE PMPLUNA
        SET
          CANTINTR  = aCANTINTR,
          VALINTR   = aVALINTR,
          REST      = aCANTINTR,
          ValValuta = aValValuta
        WHERE
          CODPMPLUNA = NR;
      END IF;
    END LOOP;
  END IF;
  COMMIT;
END;

PROCEDURE MAKE_PMP_ALL_LUNA IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  DELETE FROM PMP_ALL_LUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  FOR V_REC IN
  (
   SELECT
     CODOBIECT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     vAnTemp,
     vLunaTemp
   FROM
   (
   SELECT
     NS.CODOBIECT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
      NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc,  vAnTemp,  vLunaTemp) AS RESTLUNA
   FROM
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = vAnTemp AND I.LUNA = vLunaTemp
   )
   GROUP BY CODOBIECT
   )
  LOOP
    INSERT INTO PMP_ALL_LUNA (CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES
   ( SEQ_PMP_ALL_LUNA.NEXTVAL,
     V_REC.CODOBIECT,
     V_REC.CANTINTR,
     V_REC.VALINTR,
     V_REC.RESTLUNA,
     vAnTemp,
     vLunaTemp
   );
  END LOOP;
 COMMIT;
END;

PROCEDURE MAKE_STOCVAL_LUNA IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  PKG_GLOBALS.FILTRARE_STOC_VAL := 0;
  DELETE FROM STOCVALLUNA WHERE AN = vAnTemp AND LUNA = vLunaTemp;
  INSERT INTO STOCVALLUNA (CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
  SELECT SEQ_STOCVALLUNA_CODSTOCVALLUNA.NEXTVAL, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, vAnTemp, vLunaTemp
  FROM V_STOCVAL;
  COMMIT;
END;



FUNCTION GETAMOLUNAREZERVA(AN    IN NUMBER,
                          LUNA   IN NUMBER,
                    xAMOREZERVA  IN NUMBER,
                    xDURATAF     IN NUMBER,
                    xREZERVA     IN NUMBER,
                    xANINTRARE   IN NUMBER,
                    xLUNAINTRARE IN NUMBER
                    ) RETURN NUMBER
IS
  VALREZERVA  NUMBER(20, 7) := 0;
  VALRAMASA    NUMBER(20, 7) := 0;
  aDURATAF     NUMBER(20, 7) := 0;
BEGIN
  IF xDURATAF = 0 THEN
    RETURN 0;
  ELSIF  AN * 12 + LUNA &gt;= xANINTRARE * 12 + xLUNAINTRARE  THEN
    aDURATAF    := xDURATAF;
    VALREZERVA  := xREZERVA;
    VALRAMASA   := VALREZERVA - xAMOREZERVA;

    RETURN(ROUND(VALRAMASA / aDURATAF, 3));
   END IF;
END;





FUNCTION GETAMOLUNA(AN IN NUMBER,
                    LUNA         IN NUMBER,
                    xAMO         IN NUMBER,
                    xNEUTIL      IN NUMBER,
                    xDURATAF     IN NUMBER,
                    xPRET        IN NUMBER,
                    xCANT        IN NUMBER,
                    xGRADU       IN NUMBER,
                    xANINTRARE   IN NUMBER,
                    xLUNAINTRARE IN NUMBER,
                    xTIPAMO      IN NUMBER,
                    xDURATAN     IN NUMBER,
                    XTIP         IN VARCHAR2) RETURN NUMBER
IS
  AMOLUNA       NUMBER(20, 7) := 0;
  VALMIFIX      NUMBER(20, 7) := 0;
  VALRAMASA     NUMBER(20, 7) := 0;
  IND           NUMBER(20, 7) := 0;
  AA            NUMBER(20, 7) := 0;
  AMOAN         NUMBER(20, 7) := 0;
  AAL           NUMBER(20, 7) := 0;
  X             NUMBER(20, 7) := 0;
  aDURATAF      NUMBER(20, 7) := 0;
  ANIRAMASI     NUMBER;
  ANIAMORTIZATI NUMBER;
  I             NUMBER;
BEGIN
  IF xDURATAN = 0 THEN
    --INSERT INTO X(VIEW_NAME) VALUES (&apos;COD MIFIX1 = FUTUT&apos;); !!!!!
    RETURN 0;
  END IF;

  IF xDURATAF = 0 THEN
    RETURN 0;
  ELSIF  AN * 12 + LUNA &gt;= xANINTRARE * 12 + xLUNAINTRARE  THEN
    aDURATAF  := xDURATAF;
    VALMIFIX  := xPRET * xCANT;
    VALRAMASA := VALMIFIX - xAMO;

    IF xTIPAMO = 1 THEN -- LINIARA
      AMOLUNA := ((VALRAMASA / aDURATAF) * xGRADU);
    ELSIF xTIPAMO = 2 THEN -- ACCELERATA
      IF XTIP = &apos;MF&apos; THEN
        IF (AN * 12 + LUNA) - (xANINTRARE * 12 + xLUNAINTRARE) + 1 &lt;= 12
        THEN AMOLUNA := 0.5 * (VALMIFIX / 12);
        ELSE AMOLUNA := ((VALRAMASA / aDURATAF) * xGRADU);
        END IF;
      ELSE -- OBINV 100% la punere in functiune
        IF (AN  = XANINTRARE)AND(LUNA = XLUNAINTRARE)
        THEN AMOLUNA := VALRAMASA;
        ELSE AMOLUNA := 0.0;
        END IF;
      END IF;
    ELSIF xTIPAMO = 3 THEN
      IF XTIP = &apos;MF&apos; THEN -- AD1 PENTRU MF
         IF    xDURATAN BETWEEN  2 AND   5 THEN IND := 1.5;
         ELSIF xDURATAN BETWEEN  5 AND  10 THEN IND := 2;
         ELSIF xDURATAN BETWEEN 10 AND 255 THEN IND := 2.5;
         ELSE                                   IND := 1;
         END IF;

------ start   cod adus din Paradox
         X := aDURATAF;  WHILE MOD(X, 12) &gt; 0 LOOP X := X + 1; END LOOP;
         IF TRUNC(X/12) &lt;&gt; 0 THEN
            AAL := ValRamasa/TRUNC((X / 12));
         END IF;
         ANIRAMASI := TRUNC(X / 12);
         IF ANIRAMASI &lt;=1 THEN
           AMOLUNA := ((VALRAMASA / aDURATAF) * xGRADU);
         ELSE
           ANIAMORTIZATI := XDURATAN - ANIRAMASI;
           AA := VALMIFIX;
           I := 1;
           WHILE I &lt;= ANIAMORTIZATI LOOP
             AMOAN := (IND/ XDURATAN)*AA;
             AA    := AA - AMOAN;
             I := I + 1;
           END LOOP;

           AA := (IND / XDURATAN)*AA;
           IF ANIRAMASI &lt;&gt; 0 THEN
              AAL := VALRAMASA / ANIRAMASI;
           END IF;
           IF AA &gt; AAL THEN AMOLUNA := xGRADU * AA/12; -- ramane degresiva
           ELSE
            AMOLUNA := ((VALRAMASA / aDURATAF)*xGRADU); -- trec la liniara
           END IF;
        END IF;


      ELSE -- 50% PENTRU OBINV
        IF    (AN = XANINTRARE) AND (LUNA = XLUNAINTRARE) THEN AMOLUNA := VALRAMASA / 2;
        ELSIF (AN = XANINTRARE + XDURATAN) AND (LUNA = XLUNAINTRARE) THEN AMOLUNA := VALRAMASA;
        ELSE AMOLUNA := 0.0;
        END IF;
      END IF;
    END IF;
    RETURN ROUND(AMOLUNA, 3);
  ELSE
    RETURN 0;
  END IF;
END;



FUNCTION GETCHELTLUNA_PEZILE(AN           IN NUMBER,
                             LUNA         IN NUMBER,
                             xAMO         IN NUMBER,
                             xVALOARE     IN NUMBER,
                             xDATASTART   IN VARCHAR2,
                             xDATAEND     IN VARCHAR2
                             )            RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  VALMIFIX     NUMBER(20, 7) := 0;
  VALRAMASA    NUMBER(20, 7) := 0;
  aANSTART     NUMBER(10) := 0;
  aANEND       NUMBER(10) := 0;
  aLUNASTART   NUMBER(2)  := 0;
  aLUNAEND     NUMBER(2)  := 0;
  ZISTARTLUNA  VARCHAR2(10);
  ZIENDLUNA    VARCHAR2(10);
  LASTDAY      NUMBER(2) := 0;

  ZILERAMASE   NUMBER(10) := 0;
  ZILELUNA     NUMBER(10) := 0;

BEGIN

  SELECT EXTRACT(YEAR FROM TO_DATE(xDATASTART, &apos;DD.MM.YYYY&apos;)) INTO aANSTART FROM DUAL;
  SELECT EXTRACT(YEAR FROM TO_DATE(xDATAEND, &apos;DD.MM.YYYY&apos;))   INTO aANEND FROM DUAL;

  SELECT EXTRACT(MONTH FROM TO_DATE(xDATASTART, &apos;DD.MM.YYYY&apos;)) INTO aLUNASTART FROM DUAL;
  SELECT EXTRACT(MONTH FROM TO_DATE(xDATAEND, &apos;DD.MM.YYYY&apos;))   INTO aLUNAEND FROM DUAL;

  VALMIFIX  := xVALOARE;
  VALRAMASA := VALMIFIX - xAMO;
  ZISTARTLUNA := &apos;01.&apos; || TO_CHAR(LUNA) || &apos;.&apos; || TO_CHAR(AN);

  IF TO_DATE(ZISTARTLUNA, &apos;dd.mm.yyyy&apos;) &gt; TO_DATE(xDATAEND, &apos;DD.MM.YYYY&apos;) THEN
    RETURN 0;
  END IF;

  LASTDAY   := CAST(to_char(LAST_DAY(to_date(ZISTARTLUNA, &apos;dd.mm.yyyy&apos;)),&apos;dd&apos;) AS INT);
  ZIENDLUNA := TO_CHAR(LASTDAY) || &apos;.&apos; || TO_CHAR(LUNA) || &apos;.&apos; || TO_CHAR(AN);


  IF TO_DATE(XDATASTART, &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(ZIENDLUNA, &apos;DD.MM.YYYY&apos;) THEN
    IF aANSTART * 12 + aLUNASTART = AN * 12 + LUNA THEN
      SELECT TO_DATE(XDATAEND,  &apos;DD.MM.YYYY&apos;) - TO_DATE(XDATASTART, &apos;DD.MM.YYYY&apos;) + 1 INTO ZILERAMASE FROM DUAL;

      IF aANEND * 12 + aLUNAEND = AN * 12 + LUNA THEN ZILELUNA := ZILERAMASE;
      ELSE
        SELECT TO_DATE(ZIENDLUNA, &apos;DD.MM.YYYY&apos;) - TO_DATE(XDATASTART, &apos;DD.MM.YYYY&apos;) + 1 INTO ZILELUNA FROM DUAL;
      END IF;
    ELSE
    IF aANEND * 12 + aLUNAEND = AN * 12 + LUNA THEN
      SELECT TO_DATE(XDATAEND,  &apos;DD.MM.YYYY&apos;) - TO_DATE(ZISTARTLUNA, &apos;DD.MM.YYYY&apos;) + 1 INTO ZILERAMASE FROM DUAL;
      ZILELUNA := ZILERAMASE;
    ELSE
      SELECT TO_DATE(XDATAEND,  &apos;DD.MM.YYYY&apos;) - TO_DATE(ZISTARTLUNA, &apos;DD.MM.YYYY&apos;) + 1 INTO ZILERAMASE FROM DUAL;
      ZILELUNA := LASTDAY;
    END IF;
    END IF;

    IF ZILERAMASE &lt;&gt; 0 THEN
      AMOLUNA := ZILELUNA * VALRAMASA / ZILERAMASE;
    ELSE
      AMOLUNA := 0;
    END IF;
    RETURN ROUND(AMOLUNA, 2);
  ELSE
    RETURN 0;
  END IF;

END;

FUNCTION GETCHELTLUNA(AN           IN NUMBER,
                      LUNA         IN NUMBER,
                      xAMO         IN NUMBER,
                      xDURATAF     IN NUMBER,
                      xVALOARE     IN NUMBER,
                      xANINTRARE   IN NUMBER,
                      xLUNAINTRARE IN NUMBER,
                      xDURATAN     IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF xDURATAF = 0 THEN
    RETURN 0;
  ELSIF AN * 12 + LUNA &gt;= xANINTRARE * 12 + xLUNAINTRARE  THEN
    RETURN ROUND((xVALOARE - xAMO) / xDURATAF, 2);
  ELSE
    RETURN 0;
  END IF;
END;

FUNCTION AMORTIZARELUNARA_REZERVA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
 xAMOREZERVA  NUMBER(20, 7) := 0;
 xDURATAF     NUMBER(20, 7) := 0;
 xREZERVA     NUMBER(20, 7) := 0;
 xDURATAN     NUMBER(20, 7) := 0;
 xANINTRARE   NUMBER(5)     := 0;
 xLUNAINTRARE NUMBER(5)     := 0;
BEGIN
  BEGIN
    SELECT
      NVL(AMOREZERVA, 0),
      NVL(DURATAF, 0),
      NVL(REZERVA, 0),
      NVL(DURATAN, 0),
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0)
    INTO
      xAMOREZERVA,
      xDURATAF,
      xREZERVA,
      xDURATAN,
      xANINTRARE,
      xLUNAINTRARE
    FROM
      MIFIX1 M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;



 IF XDURATAF = 0 THEN RETURN(0);
                 ELSE  RETURN(GETAMOLUNAREZERVA(AN, LUNA, xAMOREZERVA, xDURATAF, xREZERVA, xANINTRARE, xLUNAINTRARE));
 END IF;

END;


FUNCTION AMORTIZARELUNARA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
 AMOLUNA      NUMBER(20, 7) := 0;
 xAMO         NUMBER(20, 7) := 0;
 xNEUTIL      NUMBER(20, 7) := 0;
 xDURATAF     NUMBER(20, 7) := 0;
 xDURATAN     NUMBER(20, 7) := 0;
 xGRADU       NUMBER(20, 7) := 0;
 xPRET        NUMBER(20, 7) := 0;
 xCANT        NUMBER(20, 7) := 0;
 xANINTRARE   NUMBER(5)     := 0;
 xLUNAINTRARE NUMBER(5)     := 0;
 xTIPAMO      NUMBER(5)     := 0;
 XTIP         VARCHAR(2)    := &apos;&apos;;
 XDATAREEVAL  DATE;
 XAMOVECHI    NUMBER(20, 7) := 0;
 XPRETVECHI   NUMBER(20, 7) := 0;
 XTIPREEVAL   NUMBER(5)    := 0;
 XINCLUDRATA  NUMBER(5)    := 0;
 AN1          NUMBER(5);
 LUNA1        NUMBER(2);
 CODNIRSTOC_Y NUMBER(20);
 PRET_Y       NUMBER(20, 7);
 XCODNIRSTOC  NUMBER(20);

 AN_NIR       NUMBER(5);
 LUNA_NIR     NUMBER(2);
 xANLUNASTOPDEGRESIV NUMBER;


BEGIN
  BEGIN
    SELECT
      NVL(AMO, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAF, 0),
      NVL(PRET, 0),
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0),
      NVL(TIPAMO, 0),
      NVL(DURATAN, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA,
      CODNIRSTOC
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA,
      XCODNIRSTOC
    FROM
      MIFIX1 M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;


 IF XDATAREEVAL IS NOT NULL THEN
   IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
     XAMO  := XAMOVECHI;
     XPRET := XPRETVECHI;
   END IF;
 ELSE
   IF NVL(pkg_categconst.GetValConstanta(&apos;VALIMBNEXTLUNA&apos;, An, Luna), 0) = 1 THEN--Pkg_Globals.GetAnLucru, Pkg_Globals.GetLunaLucru), 0) = 1 THEN
--    verific daca nu sunt imbunatariri in luna respectiva si trebuie sa pastrez valoarea anterioara imbunatatirii
       PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AN, LUNA, AN1, LUNA1);
       BEGIN
         SELECT Case when P.CODMIFIX is Null then N.CODNIRSTOCORIG else P.CODNIRSTOC end ,
                 Case when P.CODMIFIX is Null then N.PRETMAT        else P.PRET end
         INTO
           CODNIRSTOC_Y,
           PRET_Y
         FROM  MIFIX1 M1
         left join MIFIX1 P on P.CodMifix = M1.CodMifix  AND P.ANSTART * 12 + P.LUNASTART = AN1 * 12 + LUNA1
         inner join NIRSTOC1 N  on N.CODNIRSTOC = M1.CODNIRSTOC
         where M1.CODMIFIX = ACODMIFIX AND M1.ANSTART * 12 + M1.LUNASTART = AN1 * 12 + LUNA1 + 1;
         EXCEPTION WHEN OTHERS THEN CODNIRSTOC_Y := 0; PRET_Y := 0;
       END;
       IF CODNIRSTOC_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; xPRET AND CODNIRSTOC_Y &lt;&gt; XCODNIRSTOC THEN
       BEGIN
          SELECT T.AN, T.LUNA INTO AN_NIR, LUNA_NIR FROM NIR N, NIRSTOC NS, TRANSF T  WHERE NS.CODNIRSTOC = XCODNIRSTOC AND N.CODNIR = NS.CODNIR AND N.TIPNIR = 13 AND N.CODTRANSF = T.CODTRANSF;
          EXCEPTION WHEN OTHERS THEN BEGIN
             AN_NIR   := 0;
             LUNA_NIR := 0;
          END;
        END;
        IF AN_NIR = AN AND LUNA_NIR = LUNA THEN -- modificare de pret in luna curenta
          XPRET := PRET_Y;
        END IF;
       END IF;
   END IF;
 END IF;

 IF xTIPAMO = 3 THEN -- VERIFIC DACA NU A TRECUT PE LINIARA IN LUNILE PRECEDENTA
   BEGIN
     SELECT COALESCE(ANSTOPDEGRESIV, 0) * 12 + COALESCE(LUNASTOPDEGRESIV, 0) INTO xAnLunaStopDegresiv FROM MIFIX WHERE CODMIFIX = aCODMIFIX;

     exception when others then
     xAnLunaStopDegresiv := 0;
   END;
   if xAnLunaStopDegresiv &lt;&gt; 0 and xAnLunaStopDegresiv &lt;= AN * 12 + LUNA THEN
     xTIPAMO := 1;-- fortez liniara
   END IF;


 END IF;


 IF XDURATAF = 0 THEN AMOLUNA := 0;
                 ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
 END IF;
 RETURN AMOLUNA;
END;

FUNCTION GET_AMO_MIFIX(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER IS
  CODNIRSTOC_Y NUMBER(20);
  PRET_Y       NUMBER(20);
  AN1          NUMBER(4);
  LUNA1        NUMBER(2);
  AN_NIR       NUMBER(4);
  LUNA_NIR     NUMBER(2);
  xPRET        NUMBER(20, 7) := 0;
  XCODNIRSTOC  NUMBER(20);
BEGIN
  BEGIN
    SELECT NVL(AMO, 0), CODNIRSTOC
    INTO   xPRET,       XCODNIRSTOC
    FROM MIFIX1 M1, MIFIX M
    WHERE M1.ANSTART = AN AND M1.LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX
      AND M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF pGAMOMF_VALIMBNEXTLUNA_Const1 IS NULL THEN
    pkg_categconst.GetConst_Param(&apos;VALIMBNEXTLUNA&apos;, pGAMOMF_VALIMBNEXTLUNA_Const1, pGAMOMF_VALIMBNEXTLUNA_UserID);
  END IF;

  IF Coalesce(pGAMOMF_AL, -1) &lt;&gt; (AN*12+LUNA) THEN
    pGAMOMF_AL             := AN*12+LUNA;
    pGAMOMF_VALIMBNEXTLUNA := pkg_categconst.GetConst_Val(pGAMOMF_VALIMBNEXTLUNA_Const1, pGAMOMF_VALIMBNEXTLUNA_UserID, pGAMOMF_AL);
  END IF;

  IF Coalesce(pGAMOMF_VALIMBNEXTLUNA, 0) = 1 THEN
    --verific daca nu sunt imbunatariri in luna respectiva si trebuie sa pastrez valoarea anterioara imbunatatirii
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AN, LUNA, AN1, LUNA1);
    BEGIN
      SELECT Case when P.CODMIFIX is Null then N.CODNIRSTOCORIG else M1.CODNIRSTOC end ,
              GET_AMO_MIFIX(m1.CODMIFIX, AN1, LUNA1) + NVL(J1.VALOARE,0)
      INTO
        CODNIRSTOC_Y,
        PRET_Y
      FROM  MIFIX1 M1
      left join MIFIX1 P on P.CodMifix = M1.CodMifix  AND P.ANSTART * 12 + P.LUNASTART = AN1 * 12 + LUNA1
      inner join NIRSTOC1 N  on N.CODNIRSTOC = M1.CODNIRSTOC
      LEFT JOIN jurnal1 j1 ON j1.indexlocal = m1.codmifix
                           AND j1.tipdoc = 36 AND j1.icontd = 4 AND j1.icontc = 10
                           AND j1.an*12+j1.luna = P.anstart*12+P.lunastart
      where M1.CODMIFIX = ACODMIFIX AND M1.ANSTART * 12 + M1.LUNASTART = AN1 * 12 + LUNA1 + 1;
    EXCEPTION
      WHEN OTHERS THEN CODNIRSTOC_Y := 0; PRET_Y := 0;
    END;
    IF CODNIRSTOC_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; 0 AND PRET_Y &lt;&gt; xPRET AND CODNIRSTOC_Y &lt;&gt; XCODNIRSTOC THEN
      SELECT T.AN, T.LUNA
      INTO   AN_NIR, LUNA_NIR
      FROM NIR N, NIRSTOC NS, TRANSF T
      WHERE NS.CODNIRSTOC = XCODNIRSTOC AND N.CODNIR = NS.CODNIR AND N.TIPNIR = 13 AND N.CODTRANSF = T.CODTRANSF;

      IF AN_NIR = AN AND LUNA_NIR = LUNA THEN -- modificare de pret in luna curenta
        XPRET := PRET_Y;
      END IF;
    END IF;
  END IF;
  RETURN XPRET;
END;

FUNCTION CHELTAVANSLUNA(ACODCHELTAVANS NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  xAMO         NUMBER(20, 7) := 0;
  xDURATAF     NUMBER(20, 7) := 0;
  xDURATAN     NUMBER(20, 7) := 0;
  xVALOARE     NUMBER(20, 7) := 0;
  xANINTRARE   NUMBER(5)     := 0;
  xLUNAINTRARE NUMBER(5)     := 0;
BEGIN
  BEGIN
    SELECT
     NVL(AMO, 0),
     NVL(DURATAF, 0),
     NVL(VALOARE, 0),
     NVL(ANINCEPUT, 0),
     NVL(LUNAINCEPUT, 0),
     NVL(DURATAN, 0)
    INTO
      xAMO,
      xDURATAF,
      xVALOARE,
      xANINTRARE,
      xLUNAINTRARE,
      xDURATAN
    FROM
      CHELTAVANS1 CAV1,
      CHELTAVANS CAV
    WHERE
      ANSTART = AN
      AND LUNASTART = LUNA
      AND CAV1.CODCHELTAVANS = ACODCHELTAVANS
      AND CAV.CODCHELTAVANS  = ACODCHELTAVANS AND
      CAV.ANINCEPUT * 12 + CAV.LUNAINCEPUT &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

 IF XDURATAF = 0 THEN AMOLUNA := 0;
                 ELSE AMOLUNA := GETCHELTLUNA(AN, LUNA, xAMO, xDURATAF, xVALOARE, xANINTRARE, xLUNAINTRARE, xDURATAN);
 END IF;
 RETURN AMOLUNA;
END;


FUNCTION CHELTAVANSLUNA_PEZILE(ACODCHELTAVANS NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  xAMO         NUMBER(20, 7) := 0;
  xVALOARE     NUMBER(20, 7) := 0;
  xDATASTART   VARCHAR2(10);
  xDATAEND     VARCHAR2(10);
BEGIN
  BEGIN
    SELECT
     NVL(AMO, 0),
     NVL(VALOARE, 0),
     TO_CHAR(DATASTART, &apos;DD.MM.YYYY&apos;),
     TO_CHAR(NVL(DATAENDNOUA, DATAEND),   &apos;DD.MM.YYYY&apos;)
    INTO
      xAMO,
      xVALOARE,
      xDATASTART,
      xDATAEND
    FROM
      CHELTAVANS1 CAV1,
      CHELTAVANS CAV
    WHERE
      ANSTART = AN
      AND LUNASTART = LUNA
      AND CAV1.CODCHELTAVANS = ACODCHELTAVANS
      AND CAV.CODCHELTAVANS  = ACODCHELTAVANS AND
      EXTRACT(YEAR FROM CAV.DATASTART) * 12 + EXTRACT(MONTH FROM CAV.DATASTART) &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

 AMOLUNA := GETCHELTLUNA_PEZILE(AN, LUNA, xAMO, xVALOARE, xDATASTART, xDATAEND );


 RETURN AMOLUNA;
END;


PROCEDURE MAKE_CHELTAVANS IS
  NR              NUMBER(10)    := 0;
  aANINI          NUMBER(10)    := 0;
  aLUNAINI        NUMBER(10)    := 0;
  RATALUNA        NUMBER(20, 7) := 0;
  ADURATAF        NUMBER(20, 7) := 0;
  ACODCENTRU      NUMBER(20, 0) := 0;
  ACODANALIZANOD  NUMBER(20, 0) := 0;
  ACODAUTO        NUMBER(20, 0) := 0;
  aCODGEST        NUMBER(20, 0) := 0;
  a               NUMBER;
  vAnPrec         NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec       NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp         NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp       NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO aANINI, aLUNAINI FROM FIRMALUNI;
    EXCEPTION WHEN OTHERS THEN aANINI := 0;
  END;


  FOR V_REC IN
  (
   SELECT * FROM CHELTAVANS1
   WHERE
     ANSTART       = vAnPrec
     AND LUNASTART = vLunaPrec
     AND  ABS(NVL(AMO, 0)) &lt; ABS(VALOARE)
  )
  LOOP
    SELECT COUNT(*) INTO NR FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    IF NR = 0 THEN
      INSERT INTO CHELTAVANS1
      (CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, DATAENDNOUA)
      VALUES (SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, V_REC.CODCHELTAVANS, V_REC.VALOARE, V_REC.DURATAN, V_REC.DURATAF, 0,  vAnTemp, vLunaTemp, V_REC.AMO, V_REC.CODCENTRU, V_REC.DATAENDNOUA);
    ELSE
      UPDATE CHELTAVANS1
      SET
        AMO = V_REC.AMO,
        VALOARE = V_REC.VALOARE
      WHERE
       CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;


      UPDATE CHELTAVANS1
      SET
        DATAENDNOUA = V_REC.DATAENDNOUA
      WHERE
        CODCHELTAVANS = V_REC.CODCHELTAVANS
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DATAENDBLOCATA, 0) = 0;
    END IF;
  END LOOP;


-- VERIFICA DACA IN NOUA LUNA NU AM INREG CARE AU FOST DEJA AMORTIZARE PENTRU A LE STERGE
  FOR V_REC IN
  (SELECT CV1.*, CV.DATASTART, CV.DATAEND
   FROM
     CHELTAVANS1 CV1,
     CHELTAVANS CV
   WHERE
     ANSTART = vAnPrec
     AND LUNASTART = vLunaPrec
     AND CV.CODCHELTAVANS = CV1.CODCHELTAVANS
     AND ABS(NVL(AMO, 0)) &lt; ABS(VALOARE )
    )
  LOOP
    IF V_REC.DATASTART IS NULL
    THEN
      RATALUNA := CHELTAVANSLUNA(V_REC.CODCHELTAVANS, vAnPrec, vLunaPrec);
    ELSE
      RATALUNA := CHELTAVANSLUNA_PEZILE(V_REC.CODCHELTAVANS, vAnPrec, vLunaPrec);
    END IF;
  END LOOP;



  FOR V_REC IN
  (SELECT CAV1.*, CAV.ANINCEPUT, CAV.LUNAINCEPUT, CAV.DATASTART, CAV.DATAEND
   FROM
     CHELTAVANS1 CAV1
     LEFT OUTER JOIN CHELTAVANS CAV ON CAV.CODCHELTAVANS = CAV1.CODCHELTAVANS
   WHERE
      ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
  LOOP
  --  IF V_REC.CODCHELTAVANS = 11389 THEN
   --   A := 1;
  --  END IF;
    IF V_REC.DATASTART IS NULL
    THEN
      RATALUNA := CHELTAVANSLUNA(V_REC.CODCHELTAVANS, vAnPrec, vLunaPrec);
    ELSE
      RATALUNA := CHELTAVANSLUNA_PEZILE(V_REC.CODCHELTAVANS, vAnPrec, vLunaPrec);
    END IF;



    UPDATE CHELTAVANS1 CAV1
      SET
        AMO = CASE
                WHEN (SELECT ABS(NVL(AMO, 0) + RATALUNA)  FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt; ABS(VALOARE)
                THEN (SELECT NVL(AMO, 0) + RATALUNA  FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                WHEN (SELECT ABS(NVL(AMO, 0) + RATALUNA)  FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &gt;= ABS(VALOARE)
                THEN VALOARE
                ELSE AMO
              END
      WHERE
        CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;


       IF V_REC.DATASTART IS NULL THEN
         IF (NVL(V_REC.DFBLOCAT, 0) = 0)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt;= V_REC.ANINCEPUT * 12 + V_REC.LUNAINCEPUT)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
         THEN
           IF V_REC.ANSTART * 12 + V_REC.LUNASTART = V_REC.ANINCEPUT * 12 + V_REC.LUNAINCEPUT THEN -- userul s-a razgandit, a anulat luna si a modificat durata normata
             aDURATAF := V_REC.DURATAN;
           ELSE
             BEGIN
               SELECT NVL(DURATAF, V_REC.DURATAF) - 1 INTO aDURATAF FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
               EXCEPTION WHEN OTHERS THEN aDURATAF := 0;
             END;
           END IF;

           IF aDURATAF &lt; 0 THEN aDURATAF := 0;
           END IF;
           UPDATE CHELTAVANS1 CAV1
           SET
             DURATAF = aDURATAF
             WHERE
               CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
         END IF;
       END IF;
  END LOOP;

  FOR V_REC IN
    (
    SELECT * FROM CHELTAVANS1
    WHERE
     (NVL(CODCENTRU, 0) = 0  OR NVL(CODANALIZANOD, 0) = 0 OR NVL(CODAUTO, 0) = 0)
      AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp
    )
  LOOP
    BEGIN
    SELECT CODCENTRU, CODANALIZANOD, CODAUTO, CODGEST INTO aCODCENTRU, aCODANALIZANOD, aCODAUTO, aCODGEST
    FROM
     CHELTAVANS1
    WHERE
      CODCHELTAVANS = V_REC.CODCHELTAVANS AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN aCODCENTRU := 0; aCODANALIZANOD := 0; aCODAUTO := 0; aCODGEST := 0;
    END;

    IF NVL(aCODCENTRU, 0) &lt;&gt; 0 THEN
      UPDATE CHELTAVANS1
      SET
        CODCENTRU = aCODCENTRU
      WHERE
        CODCHELTAVANS1 = V_REC.CODCHELTAVANS1
        AND NVL(CENTRUBLOCAT, 0) = 0;
    END IF;

    IF NVL(aCODANALIZANOD, 0) &lt;&gt; 0 THEN
      UPDATE CHELTAVANS1
      SET
        CODANALIZANOD = aCODANALIZANOD
      WHERE
        CODCHELTAVANS1 = V_REC.CODCHELTAVANS1
        AND NVL(CODANALIZABLOCAT, 0) = 0;
        --AND NVL(CODANALIZANOD, 0) = 0;
    END IF;

    IF NVL(aCODGEST, 0) &lt;&gt; 0 THEN
      UPDATE CHELTAVANS1
      SET
        CODGEST = aCODGEST
      WHERE
        CODCHELTAVANS1 = V_REC.CODCHELTAVANS1
        AND NVL(CODGESTBLOCAT, 0) = 0;

    END IF;

    IF NVL(aCODAUTO, 0) &lt;&gt; 0 THEN
      UPDATE CHELTAVANS1
      SET
        CODAUTO = aCODAUTO
      WHERE
        CODCHELTAVANS1 = V_REC.CODCHELTAVANS1
        AND NVL(CODAUTO, 0) = 0;
    END IF;

  END LOOP;

  FOR V_REC IN
  (
    SELECT CAV1.CODCHELTAVANS1
    FROM
      CHELTAVANS1 CAV1,
      CHELTAVANS  CAV
   WHERE
     ANSTART       = vAnTemp
     AND LUNASTART = vLunaTemp
     AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
     AND CAV.DATAEND IS NOT NULL
     AND CAV.DATAEND &lt; TO_DATE(&apos;01.&apos; || TO_CHAR(vLunaTemp) || &apos;.&apos; || TO_CHAR(vAnTemp), &apos;dd.mm.yyyy&apos;)
   )
   LOOP
     NULL;
--     DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
   END LOOP;

  PROPAGA_EXTENSII_CHELTAVANS(&apos;CHELT1EXT&apos;);
  PROPAGA_EXTENSII_CHELTAVANS(&apos;VENIT1EXT&apos;);


END;

FUNCTION AMORTIZARELUNARA_F(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  xAMO         NUMBER(20, 7) := 0;
  xNEUTIL      NUMBER(20, 7) := 0;
  xDURATAF     NUMBER(20, 7) := 0;
  xDURATAN     NUMBER(20, 7) := 0;
  xGRADU       NUMBER(20, 7) := 0;
  xPRET        NUMBER(20, 7) := 0;
  xCANT        NUMBER(20, 7) := 0;
  xANINTRARE   NUMBER(5)     := 0;
  xLUNAINTRARE NUMBER(5)     := 0;
  xTIPAMO      NUMBER(5)     := 0;
  XTIP         VARCHAR(2)    := &apos;&apos;;
  XDATAREEVAL  DATE;
  XAMOVECHI    NUMBER(20, 7) := 0;
  XPRETVECHI   NUMBER(20, 7) := 0;
  XTIPREEVAL   NUMBER(5)     := 0;
  XINCLUDRATA  NUMBER(5)     := 0;
BEGIN
  BEGIN
    SELECT
      NVL(AMOF, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAFF, 0),
--      NVL(PRET, 0),
      CASE
        WHEN NVL(PRETINITIAL_F, 0) = 0 THEN NVL(PRET, 0)
        ELSE NVL(PRETINITIAL_F, 0)
      END,

      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0),
      NVL(TIPAMO, 0),
      NVL(DURATANF, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA
    FROM
      MIFIX1 M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF XDATAREEVAL IS NOT NULL THEN
    IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
      XAMO  := XAMOVECHI;
      XPRET := XPRETVECHI;
    END IF;
  END IF;

  IF XDURATAF = 0 THEN AMOLUNA := 0;
                  ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
  END IF;
  RETURN AMOLUNA;
END;

FUNCTION AMORTIZARELUNARA_G(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
  AMOLUNA      NUMBER(20, 7) := 0;
  xAMO         NUMBER(20, 7) := 0;
  xNEUTIL      NUMBER(20, 7) := 0;
  xDURATAF     NUMBER(20, 7) := 0;
  xDURATAN     NUMBER(20, 7) := 0;
  xGRADU       NUMBER(20, 7) := 0;
  xPRET        NUMBER(20, 7) := 0;
  xCANT        NUMBER(20, 7) := 0;
  xANINTRARE   NUMBER(5)     := 0;
  xLUNAINTRARE NUMBER(5)     := 0;
  xTIPAMO      NUMBER(5)     := 0;
  XTIP         VARCHAR(2)    := &apos;&apos;;
  XDATAREEVAL  DATE;
  XAMOVECHI    NUMBER(20, 7) := 0;
  XPRETVECHI   NUMBER(20, 7) := 0;
  XTIPREEVAL   NUMBER(5)     := 0;
  XINCLUDRATA  NUMBER(5)     := 0;
BEGIN
  BEGIN
    SELECT
      NVL(AMOG, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAFG, 0),
      CASE
        WHEN NVL(PRETINITIAL, 0) = 0 THEN NVL(PRET, 0)
        ELSE NVL(PRETINITIAL, 0)
      END,
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRAREG, 0),
      NVL(LUNAINTRAREG, 0),
      NVL(TIPAMO, 0),
      NVL(DURATANG, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA
    FROM
      MIFIX1 M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;

  IF XDATAREEVAL IS NOT NULL THEN
    IF XTIPREEVAL = 0 AND XINCLUDRATA = 1 THEN
      XAMO  := XAMOVECHI;
      XPRET := XPRETVECHI;
    END IF;
  END IF;

  IF XDURATAF = 0 THEN AMOLUNA := 0;
                  ELSE AMOLUNA := GETAMOLUNA(AN, LUNA, xAMO, xNEUTIL, xDURATAF, xPRET, xCANT, xGRADU, xANINTRARE, xLUNAINTRARE, xTIPAMO, xDURATAN, XTIP);
  END IF;
  RETURN AMOLUNA;
END;




PROCEDURE PROPAGA_EXTENSII_CHELTAVANS(NUME_EXTENSIE VARCHAR) IS
  S VARCHAR2(4000);
BEGIN
 IF PKG_LIST_STRUCT.TmpExists(NUME_EXTENSIE) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_&apos; || NUME_EXTENSIE) = 1 THEN
    S := &apos;
    DECLARE
      aCODCHELTAVANS1 NUMBER;
      aCOD&apos; || NUME_EXTENSIE || &apos; NUMBER;
      NR NUMBER;
    BEGIN
     select COUNT(*) INTO NR from user_tab_columns where table_name = &apos;&apos;&apos; || NUME_EXTENSIE ||&apos;&apos;&apos; AND COLUMN_ID &gt; 2;
     IF NR = 0 THEN
       RETURN;
     END IF;

    FOR V_REC IN
    (
    SELECT M1E.*, M1.CODCHELTAVANS FROM
      &apos; || NUME_EXTENSIE ||&apos; M1E,
      CHELTAVANS1 M1
    WHERE
      M1E.CODCHELTAVANS1 = M1.CODCHELTAVANS1
      AND M1.ANSTART = &apos; || PKG_GLOBALS.GetANPRECEDENT ||&apos;
      AND M1.LUNASTART = &apos;  || PKG_GLOBALS.GetLUNAPRECEDENTA ||&apos;
    )
    LOOP
      BEGIN
        SELECT CODCHELTAVANS1 INTO aCODCHELTAVANS1
        FROM
          CHELTAVANS1
        WHERE
          ANSTART =  &apos; || PKG_GLOBALS.GetANTEMP  ||&apos;
          AND LUNASTART =  &apos; || PKG_GLOBALS.GetLUNATEMP ||&apos;
          AND CODCHELTAVANS = V_REC.CODCHELTAVANS;
        EXCEPTION WHEN OTHERS THEN aCODCHELTAVANS1 := 0;
      END;
      IF aCODCHELTAVANS1 &lt;&gt; 0 THEN
        SELECT COUNT(*) INTO NR FROM &apos; || NUME_EXTENSIE || &apos; WHERE CODCHELTAVANS1 = aCODCHELTAVANS1;
        IF NR = 0 THEN
          DELETE TMP_&apos; || NUME_EXTENSIE || &apos;;
          INSERT INTO TMP_&apos; || NUME_EXTENSIE || &apos; SELECT * FROM &apos; || NUME_EXTENSIE || &apos; WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
          aCOD&apos; || NUME_EXTENSIE || &apos; := SEQ_&apos; || NUME_EXTENSIE || &apos;_COD&apos; || NUME_EXTENSIE ||&apos;.NEXTVAL;
          UPDATE TMP_&apos; || NUME_EXTENSIE || &apos; SET COD&apos; || NUME_EXTENSIE || &apos; = aCOD&apos; || NUME_EXTENSIE ||&apos; , CODCHELTAVANS1 = aCODCHELTAVANS1;
          INSERT INTO &apos; || NUME_EXTENSIE || &apos; SELECT * FROM TMP_&apos; || NUME_EXTENSIE ||&apos;;
        END IF;
      END IF;
    END LOOP;
    END;&apos;;
    EXECUTE IMMEDIATE(S);
  END IF;
END;

PROCEDURE PROPAGA_EXTENSII_MIFIX IS
  S VARCHAR2(4000);
BEGIN
 IF PKG_LIST_STRUCT.TmpExists(&apos;MIFIX1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_MIFIX1EXT&apos;) = 1 THEN
    S := &apos;
    DECLARE
      aCODMIFIX1 NUMBER;
      aCODMIFIX1EXT NUMBER;
      NR NUMBER;
    BEGIN
     select COUNT(*) INTO NR from user_tab_columns where table_name = &apos;&apos;MIFIX1EXT&apos;&apos; AND COLUMN_ID &gt; 2;
     IF NR = 0 THEN
       RETURN;
     END IF;

    FOR V_REC IN
    (
    SELECT M1E.*, M1.CODMIFIX FROM
      MIFIX1EXT M1E,
      MIFIX1 M1
    WHERE
      M1E.CODMIFIX1 = M1.CODMIFIX1
      AND M1.ANSTART = &apos; || PKG_GLOBALS.GetANPRECEDENT ||&apos;
      AND M1.LUNASTART = &apos;  || PKG_GLOBALS.GetLUNAPRECEDENTA ||&apos;
    )
    LOOP
      BEGIN
        SELECT CODMIFIX1 INTO aCODMIFIX1
        FROM
          MIFIX1
        WHERE
          ANSTART =  &apos; || PKG_GLOBALS.GetANTEMP  ||&apos;
          AND LUNASTART =  &apos; || PKG_GLOBALS.GetLUNATEMP ||&apos;
          AND CODMIFIX = V_REC.CODMIFIX;
        EXCEPTION WHEN OTHERS THEN aCODMIFIX1 := 0;
      END;
      IF aCODMIFIX1 &lt;&gt; 0 THEN
        SELECT COUNT(*) INTO NR FROM MIFIX1EXT WHERE CODMIFIX1 = aCODMIFIX1;
        IF NR = 0 THEN
          DELETE TMP_MIFIX1EXT;
          INSERT INTO TMP_MIFIX1EXT SELECT * FROM MIFIX1EXT WHERE CODMIFIX1 = V_REC.CODMIFIX1;
          aCODMIFIX1EXT := SEQ_MIFIX1EXT_CODMIFIX1EXT.NEXTVAL;
          UPDATE TMP_MIFIX1EXT SET CODMIFIX1EXT = aCODMIFIX1EXT, CODMIFIX1 = aCODMIFIX1;
          INSERT INTO MIFIX1EXT SELECT * FROM TMP_MIFIX1EXT;
        END IF;
      END IF;
    END LOOP;
    END;&apos;;
    EXECUTE IMMEDIATE(S);
  END IF;
END;

FUNCTION STOPARE_AMO_DEGRESIVA(ACODMIFIX NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
 AMOLUNA       NUMBER(20, 7) := 0;
 xAMO          NUMBER(20, 7) := 0;
 xNEUTIL       NUMBER(20, 7) := 0;
 xDURATAF      NUMBER(20, 7) := 0;

 aDURATAF      NUMBER(20, 7);
 VALMIFIX      NUMBER(20, 7);
 VALRAMASA     NUMBER(20, 7);
 IND           NUMBER(20, 7);
 X             NUMBER(20, 7);
 AAL           NUMBER(20, 7);
 AA            NUMBER(20, 7);
 ANIRAMASI     NUMBER;
 ANIAMORTIZATI NUMBER;
 I             NUMBER;
 AMOAN         NUMBER(20, 7);


 xDURATAN     NUMBER(20, 7) := 0;
 xGRADU       NUMBER(20, 7) := 0;
 xPRET        NUMBER(20, 7) := 0;
 xCANT        NUMBER(20, 7) := 0;
 xANINTRARE   NUMBER(5)     := 0;
 xLUNAINTRARE NUMBER(5)     := 0;
 xTIPAMO      NUMBER(5)     := 0;
 XTIP         VARCHAR(2)    := &apos;&apos;;
 XDATAREEVAL  DATE;
 XAMOVECHI    NUMBER(20, 7) := 0;
 XPRETVECHI   NUMBER(20, 7) := 0;
 XTIPREEVAL   NUMBER(5)    := 0;
 XINCLUDRATA  NUMBER(5)    := 0;
 XCODNIRSTOC  NUMBER(20);


BEGIN

 BEGIN
    SELECT
      NVL(AMO, 0),
      NVL(NEUTIL, 0),
      NVL(DURATAF, 0),
      NVL(PRET, 0),
      NVL(CANT, 0),
      NVL(GRADU, 0)/100,
      NVL(ANINTRARE, 0),
      NVL(LUNAINTRARE, 0),
      NVL(TIPAMO, 0),
      NVL(DURATAN, 0),
      TIP,
      DATAREEVAL ,
      AMOVECHI,
      PRETVECHI,
      TIPREEVAL,
      INCLUDRATA,
      CODNIRSTOC
    INTO
      xAMO,
      xNEUTIL,
      xDURATAF,
      xPRET,
      xCANT,
      xGRADU,
      xANINTRARE,
      xLUNAINTRARE,
      xTIPAMO,
      xDURATAN,
      XTIP,
      XDATAREEVAL,
      XAMOVECHI,
      XPRETVECHI,
      XTIPREEVAL,
      XINCLUDRATA,
      XCODNIRSTOC
    FROM
      MIFIX1 M1, MIFIX M
    WHERE
      ANSTART = AN AND LUNASTART = LUNA AND M1.CODMIFIX = ACODMIFIX AND M.CODMIFIX = ACODMIFIX AND
      M.ANINTRARE * 12 + M.LUNAINTRARE &lt;= AN * 12 + LUNA;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;




  IF xDURATAN = 0 THEN
    --INSERT INTO X(VIEW_NAME) VALUES (&apos;COD MIFIX1 = FUTUT&apos;); !!!!!
    RETURN 0;
  END IF;

  IF xDURATAF = 0 THEN
    RETURN 0;
  ELSIF  AN * 12 + LUNA &gt;= xANINTRARE * 12 + xLUNAINTRARE  THEN
    aDURATAF  := xDURATAF;
    VALMIFIX  := xPRET * xCANT;
    VALRAMASA := VALMIFIX - xAMO;

    IF    xDURATAN BETWEEN  2 AND   5 THEN IND := 1.5;
    ELSIF xDURATAN BETWEEN  5 AND  10 THEN IND := 2;
    ELSIF xDURATAN BETWEEN 10 AND 255 THEN IND := 2.5;
    ELSE                                   IND := 1;
    END IF;
        X := aDURATAF;  WHILE MOD(X, 12) &gt; 0 LOOP X := X + 1; END LOOP;
         IF TRUNC(X/12) &lt;&gt; 0 THEN
            AAL := ValRamasa/TRUNC((X / 12));
         END IF;
         ANIRAMASI := TRUNC(X / 12);
         IF ANIRAMASI &lt;=1 THEN
           AMOLUNA := ((VALRAMASA / aDURATAF) * xGRADU);
           RETURN 1;
         ELSE
           ANIAMORTIZATI := XDURATAN - ANIRAMASI;
           AA := VALMIFIX;
           I := 1;
           WHILE I &lt;= ANIAMORTIZATI LOOP
             AMOAN := (IND/ XDURATAN)*AA;
             AA    := AA - AMOAN;
             I := I + 1;
           END LOOP;

           AA := (IND / XDURATAN)*AA;
           IF ANIRAMASI &lt;&gt; 0 THEN
              AAL := VALRAMASA / ANIRAMASI;
           END IF;
           IF AA &gt; AAL THEN RETURN 0; -- ramane degresiva
           ELSE
            RETURN 1; -- trec la liniara
           END IF;
        END IF;
  END IF;
END;

PROCEDURE MAKE_MIFIX
IS
  NR                NUMERIC(10)    := 0;
  RATALUNA          NUMERIC(20, 7) := 0;
  RATALUNA_F        NUMERIC(20, 7) := 0;
  RATALUNA_G        NUMERIC(20, 7) := 0;
  RATALUNA_REZERVA  NUMERIC(20, 7) := 0;


  STAREPREC      NUMERIC(20, 7) := 0;
  STARECURENTA   NUMERIC(20, 7) := 0;
  DURATAFPREC    NUMERIC(20, 7) := 0;
  AMOPREC        NUMERIC(20, 7) := 0;
  aANINI         NUMERIC(10)    := 0;
  aLUNAINI       NUMERIC(10)    := 0;
  OLDSTARE       NUMERIC(10)    := 0;
  aCODCENTRU     NUMERIC(20)    := 0;
  aCODSABLON     NUMERIC(20)    := 0;
  aCODPERS       NUMERIC(20)    := 0;
  aCODANALIZANOD NUMERIC(20)    := 0;
  aCodClasif     NUMBER(20);
  aCODMIFIX1PREC NUMBER(20)     := 0;

  DURATAFPREC_F  NUMERIC(20, 7) := 0;
  AMOPREC_F      NUMERIC(20, 7) := 0;

  DURATAFPREC_G  NUMERIC(20, 7) := 0;
  AMOPREC_G      NUMERIC(20, 7) := 0;
  aPRETAMOGRUP   NUMERIC(20, 7) := 0;


  AMOPREC_REZERVA NUMERIC(20, 7) := 0;



  ADATAREEVAL    DATE := NULL;
  APRETVECHI     NUMERIC(20, 7) := 0;
  AAMOVECHI      NUMERIC(20, 7) := 0;
  AREZERVAVECHE  NUMERIC(20, 7) := 0;
  APRETPREC      NUMERIC(20, 7) := 0;
  AAMOPREC       NUMERIC(20, 7) := 0;
  ATIPREEVAL     NUMBER(1)      := NULL;
  aUseRezerve    Varchar(2);
  aCODMIFIX1     NUMBER(20);
  aCODAUTO       NUMERIC(20)    := 0;
  CREZREPORT     NUMBER(20);
  xANSTOPDEGRESIV NUMBER(4);
  xLUNASTOPDEGRESIV NUMBER(2);
  vAnPrec      NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec    NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp      NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp    NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  -- PROPAG INREGISTRARI DIN LUNAPRECDEDENTA IN LUNA TEMP

    BEGIN
      SELECT NVL(pkg_categconst.GetValConstanta(&apos;CRezReport&apos;,  vAnTemp, vLunaTemp), 0) INTO CREZREPORT  FROM DUAL;
     EXCEPTION WHEN OTHERS THEN CREZREPORT := 0;
    END;



--  PKG_GLOBALS.SetLunaPRECEDENTA(2013, 9);
--  PKG_GLOBALS.SetLunaTEMP(2013, 10);

  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO aANINI, aLUNAINI FROM FIRMALUNI;
    EXCEPTION WHEN OTHERS THEN aANINI := 0;
  END;

  PKG_INCHIDERI.MAKE_STOC_LUNA_EXT;
  FOR V_REC IN (SELECT M1.* 
                FROM 
                  MIFIX1 M1, 
                  MIFIX M 
                WHERE 
                  ANSTART = vAnPrec 
                  AND LUNASTART = vLunaPrec 
                  AND STARE IN (1, 2, 5) 
                  AND M.CODMIFIX = M1.CODMIFIX 
                  AND COALESCE(M.ANLUNAMIFIXNOU, 0) &lt;&gt; vAnTemp * 12 + vLunaTemp
                )
--bag in join si mifix ca sa elimin eventuiale incoerente mifix1-mifix
--FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnPrec AND LUNASTART = vLunaPrec AND STARE IN (1, 2))
  LOOP
    
    SELECT COUNT(*) INTO NR FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    IF NR = 0 THEN
      INSERT INTO MIFIX1
      (CODMIFIX1,
       CODMIFIX,
       CODNIRSTOC,
       PRET,
       CANT,
       CODCLASIF,
       TIPAMO,
       STARE,
       DURATAN,
       GRADU,
       DURATAF,
       AMO,
       NEUTIL,
       DFBLOCAT,
       CODPERS,
       CODNIRSER,
       ANSTART,
       LUNASTART,
       CODPART,
       CODLOCATIE,
       CODCENTRU,
       DURATANF,
       DURATANG,
       DURATAFF,
       DURATAFG,
       AMOF,
       AMOG,
       PRETINITIAL,
       REZERVA,
       CODSABLON,
       CODANALIZANOD,
       PRETINITIAL_F
       )
       VALUES
       (SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
        V_REC.CODMIFIX,
        V_REC.CODNIRSTOC,
        V_REC.PRET,
        V_REC.CANT,
        V_REC.CODCLASIF,
        V_REC.TIPAMO,
        V_REC.STARE,
        V_REC.DURATAN,
        V_REC.GRADU,
        V_REC.DURATAF,
        V_REC.AMO,
        V_REC.NEUTIL,
        0,
        V_REC.CODPERS,
        V_REC.CODNIRSER,
        vAnTemp,
        vLunaTemp,
        V_REC.CODPART,
        V_REC.CODLOCATIE,
        V_REC.CODCENTRU,
        V_REC.DURATANF,
        V_REC.DURATANG,
        V_REC.DURATAFF,
        V_REC.DURATAFG,
        V_REC.AMOF,
        V_REC.AMOG,
        V_REC.PRETINITIAL,
        NVL(V_REC.REZERVA, 0),
        NVL(V_REC.CODSABLON, 0),
        V_REC.CODANALIZANOD,
        V_REC.PRETINITIAL_F
        );

    ELSE
      UPDATE MIFIX1
      SET
        DURATAF = V_REC.DURATAF
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT, 0) = 0;

      UPDATE MIFIX1
      SET
        DURATAFF = V_REC.DURATAFF
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT_F, 0) = 0;

      UPDATE MIFIX1
      SET
        DURATAFG = V_REC.DURATAFG,
        DURATANG = V_REC.DURATANG
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(DFBLOCAT_G, 0) = 0;


      UPDATE MIFIX1
      SET
        REZERVA = V_REC.REZERVA
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(REZERVABLOCAT, 0) = 0;

      UPDATE MIFIX1
      SET
        PRETINITIAL = V_REC.PRETINITIAL
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(PRETINIBLOCAT, 0) = 0;



      UPDATE MIFIX1
      SET
        PRETINITIAL_F = V_REC.PRETINITIAL_F
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND ANSTART = vAnTemp
        AND LUNASTART = vLunaTemp
        AND NVL(PRETINITIAL_FBLOCAT, 0) = 0;


    END IF;
  END LOOP;
-- VERIFICA DACA IN NOUA LUNA NU AM MIJLOACE FIXE CASATE SAU VANDUTE PENTRU A LE STERGE
  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnPrec AND LUNASTART = vLunaPrec AND STARE IN (3, 4, 6, 7, 8, 9, 10))
  LOOP
    DELETE FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
  END LOOP;


 -- STERG DIN LUNA CURENTA POZITIILE VANDUTE SAU CASATE INTR_O LUNA MAI VECHE
 FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
 LOOP
   BEGIN
   SELECT STARE INTO OLDSTARE FROM MIFIX1 M1
   WHERE
     CODMIFIX = V_REC.CODMIFIX
     AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp
     AND ANSTART * 12 + LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp);
    EXCEPTION WHEN OTHERS THEN OLDSTARE := 0;
   END;
   IF OLDSTARE IN (3, 4, 6, 7, 8, 9, 10) THEN
     DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC.CODMIFIX1;
   END IF;
 END LOOP;

-- LA OBIECTE DE INVENTAR UNDE POT AVEA CANT &gt; 0 POSIBIL IN LUNA ANTERIOARA SA FI CASAT/ VANDUT IAR LUNA CURENTE NU REFLECTA MODIFICAREA
  FOR V_REC IN
 (
  SELECT ANAL.*, NL.REST
  FROM
  (
    SELECT
      M1.CODNIRSTOC,
      COUNT(*) AS NR,
      SUM(M1.CANT) AS CANT
    FROM
      MIFIX1 M1,
      MIFIX M
    WHERE
      M.CODMIFIX = M1.CODMIFIX
      AND M1.ANSTART  = vAnTemp
      AND M1.LUNASTART = vLunaTemp
      AND M1.STARE IN (1, 2)
      AND M.TIP = &apos;OI&apos;
    GROUP BY M1.CODNIRSTOC
  ) ANAL,
    NIRLUNA NL
  WHERE
    ANAL.CODNIRSTOC = NL.CODNIRSTOC
    AND NL.AN = vAnTemp
    AND NL.LUNA = vLunaTemp
    AND ANAL.NR = 1
--    AND ANAL.CODNIRSTOC = 19152
    AND ANAL.CANT &gt; NL.REST
 )
 LOOP
   BEGIN
     SELECT CODMIFIX1 INTO aCODMIFIX1
     FROM
       MIFIX1
     WHERE
       CODNIRSTOC    = V_REC.CODNIRSTOC
       AND ANSTART   = vAnTemp
       AND LUNASTART = vLunaTemp
       AND STARE IN (1, 2);
     EXCEPTION WHEN OTHERS THEN aCODMIFIX1 := 0;
   END;
   IF aCODMIFIX1 &gt; 0 THEN
     UPDATE MIFIX1
     SET
       CANT = V_REC.REST
     WHERE
      CODMIFIX1 = aCODMIFIX1;
   END IF;

 END LOOP;

-- CAUT CONSERVATE IN LUNA PRECEDENTA LA CARE AMORTIZAREA IN LUNA CURENTA E CALCULATA GRESIT
 FOR V_REC IN (SELECT
                 M1.CODMIFIX1, M1_PREC.AMO
               FROM
                 MIFIX1 M1
                 INNER JOIN MIFIX1 M1_PREC ON M1_PREC.ANSTART = vAnPrec AND M1_PREC.LUNASTART = vLunaPrec AND M1_PREC.STARE = 2 AND M1.CODMIFIX = M1_PREC.CODMIFIX
               WHERE
                  M1.STARE         = 2
                  AND M1.ANSTART   = vAnTemp
                  AND M1.LUNASTART = vLunaTemp
                  AND M1.AMO       &lt;&gt; M1_PREC.AMO
              )
  LOOP
    UPDATE MIFIX1
    SET
      AMO = V_REC.AMO
    WHERE
      CODMIFIX1 = V_REC.CODMIFIX1;
  END LOOP;


-- RECALCULEZ AMO, NEUTIL, DURATAF IN LUNA DE LUCRU;
  FOR V_REC IN (SELECT M1.*, M.ANINTRARE, M.LUNAINTRARE, M.ANINTRAREG, M.LUNAINTRAREG FROM MIFIX1 M1 LEFT OUTER JOIN MIFIX M ON M.CODMIFIX = M1.CODMIFIX
                WHERE
                STARE IN (1, 3, 4, 9, 10) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp
                AND DATAREEVAL IS NULL )
  LOOP

    RATALUNA         := AMORTIZARELUNARA   (V_REC.CODMIFIX, vAnPrec, vLunaPrec);

    IF V_REC.TIPAMO = 3 THEN --degresiva; verific daca rata de mai sus nu a trecut pe liniara
      SELECT COALESCE(ANSTOPDEGRESIV, 0), COALESCE(LUNASTOPDEGRESIV, 0) INTO xANSTOPDEGRESIV, xLUNASTOPDEGRESIV
      FROM
        MIFIX
      WHERE
        CODMIFIX = V_REC.CODMIFIX;

      IF xANSTOPDEGRESIV = 0 AND xLUNASTOPDEGRESIV = 0 and stopare_amo_degresiva(V_REC.CODMIFIX, vAnPrec, vLunaPrec) = 1 THEN
        UPDATE MIFIX
        SET
          ANSTOPDEGRESIV =  vAnPrec,
          LUNASTOPDEGRESIV =  vLunaPrec
        WHERE
          CODMIFIX = V_REC.CODMIFIX;
      END IF;


    END IF;


    RATALUNA_REZERVA := 0;
    IF CREZREPORT &lt;&gt; 0 THEN
      RATALUNA_REZERVA := AMORTIZARELUNARA_REZERVA   (V_REC.CODMIFIX, vAnPrec, vLunaPrec);

    END IF;

    RATALUNA_F       := AMORTIZARELUNARA_F (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    RATALUNA_G       := AMORTIZARELUNARA_G (V_REC.CODMIFIX, vAnPrec, vLunaPrec);

    BEGIN
      SELECT
        STARE,
        NVL(AMO,0),
        DURATAF,
        AMOF,
        DURATAFF,
        AMOG,
        DURATAFG,
        AMOREZERVA
      INTO
        STAREPREC,
        AMOPREC,
        DURATAFPREC,
        AMOPREC_F,
        DURATAFPREC_F,
        AMOPREC_G,
        DURATAFPREC_G,
        AMOPREC_REZERVA
      FROM
        MIFIX1
     WHERE
       CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN
      STAREPREC := 0;
      AMOPREC   := 0;
      AMOPREC_F := 0;
      AMOPREC_G := 0;
      AMOPREC_REZERVA   := 0;
    END;

    IF RATALUNA &lt;&gt; 0 THEN
      IF V_REC.PRET &gt;= 0 THEN
        IF RATALUNA &lt;&gt; 0 AND abs(AMOPREC + RATALUNA) &gt; abs(V_REC.PRET * V_REC.CANT) THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        END IF;
      ELSE -- pret negativ rata pozitiva sau negativa
        IF RATALUNA &gt; 0 AND AMOPREC + RATALUNA &gt; V_REC.PRET * V_REC.CANT THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        ELSE
        IF RATALUNA &lt; 0  AND AMOPREC + RATALUNA &lt; V_REC.PRET * V_REC.CANT THEN
          RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
        END IF;
        END IF;
      END IF;
    END IF;

    IF RATALUNA_F &lt;&gt; 0 AND AMOPREC_F + RATALUNA_F &gt; V_REC.PRET * V_REC.CANT THEN
      RATALUNA_F := V_REC.PRET * V_REC.CANT - AMOPREC_F;
    END IF;


    IF RATALUNA_REZERVA &lt;&gt; 0 AND AMOPREC_REZERVA + RATALUNA_REZERVA &gt; V_REC.REZERVA THEN
      RATALUNA_REZERVA := V_REC.REZERVA - AMOPREC_REZERVA;
    END IF;


    IF NVL(V_REC.PRETINITIAL, 0) &lt;&gt; 0
      THEN aPRETAMOGRUP := V_REC.PRETINITIAL;
      ELSE aPRETAMOGRUP := V_REC.PRET;
    END IF;

    IF RATALUNA_G &lt;&gt; 0 AND AMOPREC_G + RATALUNA_G &gt; /*V_REC.PRET*/aPRETAMOGRUP * V_REC.CANT THEN
      RATALUNA_G := /*V_REC.PRET */ aPRETAMOGRUP * V_REC.CANT - AMOPREC_G;
    END IF;


    BEGIN
      SELECT STARE INTO STARECURENTA FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
      EXCEPTION WHEN OTHERS THEN STARECURENTA := 0;
    END;

    IF STAREPREC = 2 THEN
       UPDATE MIFIX1 M1
       SET
         AMO     = CASE
                    WHEN NVL(V_REC.AMOBLOCAT, 0) = 1 THEN AMO
                    ELSE AMOPREC
                   END,
         AMOREZERVA     = CASE
                    WHEN NVL(V_REC.AMORBLOCAT, 0) = 1 THEN AMOREZERVA
                    ELSE AMOPREC_REZERVA
                   END,
         AMOF     = CASE
                    WHEN NVL(V_REC.AMOFBLOCAT, 0) = 1 THEN AMOF
                    ELSE AMOPREC_F
                   END,
         AMOG     = CASE
                    WHEN NVL(V_REC.AMOGBLOCAT, 0) = 1 THEN AMOG
                    ELSE AMOPREC_G
                   END,
--         AMOF    = AMOPREC_F,
--         AMOG    = AMOPREC_G,
         DURATAF = ( CASE
                       WHEN DFBLOCAT = 1 THEN DURATAF
                                         ELSE DURATAFPREC
                     END
                   ),
         DURATAFF = ( CASE
                       WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                         ELSE DURATAFPREC_F
                     END
                   ),
         DURATAFG =( CASE
                       WHEN DFBLOCAT_G = 1 THEN DURATAFG
                                         ELSE DURATAFPREC_G
                     END
                   )
       WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    ELSE
       UPDATE MIFIX1 M1
         SET
           AMO     =  CASE WHEN NVL(V_REC.AMOBLOCAT, 0) = 1 THEN AMO
                      ELSE
                        CASE
                           WHEN (SELECT NVL(TIPREEVAL, 0) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) = 1 THEN 0
                           WHEN PRET &gt; 0 AND (SELECT ABS(NVL(AMO, 0) + RATALUNA) /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= ABS(PRET * CANT) AND STARE IN (1, 3, 4, 9, 10)
                           THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                           WHEN PRET  &lt; 0 AND RATALUNA &gt; 0 AND (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= PRET * CANT AND STARE in (1, 3, 4, 9, 10)
                           THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                           WHEN PRET  &lt; 0 AND RATALUNA &lt; 0 AND (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &gt;= PRET * CANT AND STARE in (1, 3, 4, 9, 10)
                           THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                           ELSE AMO
                        END
                      END ,

           AMOREZERVA =  CASE WHEN NVL(V_REC.AMORBLOCAT, 0) = 1 THEN AMOREZERVA
                      ELSE
                       CASE
                          WHEN (SELECT NVL(AMOREZERVA, 0) + RATALUNA_REZERVA FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= REZERVA AND STARE IN (1, 3, 4, 9, 10)
                          THEN (SELECT NVL(AMOREZERVA, 0) + RATALUNA_REZERVA FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOREZERVA
                       END
                      END ,
           AMOF     =  CASE WHEN NVL(V_REC.AMOFBLOCAT, 0) = 1 THEN AMOF
                       ELSE
                       CASE
                          WHEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= DECODE(NVL(PRETINITIAL_F, 0), 0, PRET, NVL(PRETINITIAL_F, 0))  /*PRET*/ * CANT AND STARE in (1, 3, 4, 9, 10)
                          THEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOF
                       END
                       END,

           AMOG     =  CASE WHEN NVL(V_REC.AMOGBLOCAT, 0) = 1 THEN AMOG
                       ELSE
                       CASE
                          WHEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= DECODE(NVL(PRETINITIAL, 0), 0, PRET, NVL(PRETINITIAL, 0))  /*PRET*/ * CANT AND STARE in (1, 3, 4, 9, 10)
                          THEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOG
                       END
                      END

         WHERE
           CODMIFIX1 = V_REC.CODMIFIX1;

       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRARE * 12 + V_REC.LUNAINTRARE)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
             SET
               DURATAF = CASE WHEN DURATAF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT = 1 THEN DURATAF
                                ELSE (SELECT NVL(DURATAF, M1.DURATAF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END,


               DURATAFF = CASE WHEN DURATAFF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                ELSE (SELECT NVL(DURATAFF, M1.DURATAFF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE in  (1, 3, 4, 9, 10);
       END IF;

--DURATAFG
       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRAREG * 12 + V_REC.LUNAINTRAREG)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
           SET
               DURATAFG = CASE WHEN DURATAFG &gt; 0 THEN
                          ( CASE
                              WHEN DFBLOCAT_G = 1 THEN DURATAFG
                              ELSE (SELECT NVL(DURATAFG, M1.DURATAFG) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE in (1, 3, 4, 9, 10);
       ELSE
           UPDATE MIFIX1 M1
           SET
             DURATAFG = (SELECT NVL(DURATAFG, M1.DURATAFG) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
           WHERE
             CODMIFIX1 = V_REC.CODMIFIX1 AND STARE in (1, 3, 4, 9, 10) AND  NVL(DFBLOCAT_G, 0) = 0;
       END IF;
  END IF;
  END LOOP;

-- RECALCUL DURATE LA REVALUATE
  FOR V_REC IN (SELECT M1.*, M.ANINTRARE, M.LUNAINTRARE, M.ANINTRAREG, M.LUNAINTRAREG FROM MIFIX1 M1 LEFT OUTER JOIN MIFIX M ON M.CODMIFIX = M1.CODMIFIX
                WHERE
                STARE IN (1 , 2) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp
                AND DATAREEVAL IS NOT NULL)
  LOOP


    BEGIN
      SELECT
        STARE,
        AMO,
        DURATAF,
        AMOF,
        DURATAFF,
        AMOG,
        DURATAFG
      INTO
        STAREPREC,
        AMOPREC,
        DURATAFPREC,
        AMOPREC_F,
        DURATAFPREC_F,
        AMOPREC_G,
        DURATAFPREC_G
      FROM
        MIFIX1
     WHERE
       CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN
      STAREPREC := 0;
      AMOPREC   := 0;
      AMOPREC_F := 0;
      AMOPREC_G := 0;
    END;



    BEGIN
      SELECT STARE INTO STARECURENTA FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
      EXCEPTION WHEN OTHERS THEN STARECURENTA := 0;
    END;

    IF STAREPREC = 2 THEN
       UPDATE MIFIX1 M1
       SET
         DURATAF = ( CASE
                       WHEN DFBLOCAT = 1 THEN DURATAF
                                         ELSE DURATAFPREC
                     END
                   ),
         DURATAFF = ( CASE
                       WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                         ELSE DURATAFPREC_F
                     END
                   ),
         DURATAFG =( CASE
                       WHEN DFBLOCAT_G = 1 THEN DURATAFG
                                         ELSE DURATAFPREC_G
                     END
                   )
       WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    ELSE
       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRARE * 12 + V_REC.LUNAINTRARE)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
             SET
               DURATAF = CASE WHEN DURATAF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT = 1 THEN DURATAF
                                ELSE (SELECT NVL(DURATAF, M1.DURATAF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END,


               DURATAFF = CASE WHEN DURATAFF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                ELSE (SELECT NVL(DURATAFF, M1.DURATAFF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       END IF;

--DURATAFG
       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRAREG * 12 + V_REC.LUNAINTRAREG)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
           SET
               DURATAFG = CASE WHEN DURATAFG &gt; 0 THEN
                          ( CASE
                              WHEN DFBLOCAT_G = 1 THEN DURATAFG
                              ELSE (SELECT NVL(DURATAFG, M1.DURATAFG) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       ELSE
           UPDATE MIFIX1 M1
           SET
             DURATAFG = (SELECT NVL(DURATAFG, M1.DURATAFG) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
           WHERE
             CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       END IF;
  END IF;
  END LOOP;



  -- CODCENTRU a aparut
  FOR V_REC IN (SELECT * FROM MIFIX1
                WHERE
                  (NVL(CODCENTRU, 0) = 0 OR NVL(CODSABLON, 0) = 0 OR NVL(CODANALIZANOD, 0) = 0 OR NVL(CODPERS, 0) = 0)
                  AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
  LOOP
    BEGIN
     SELECT coalesce(CODMIFIX1, 0),
             coalesce(CODCENTRU, 0),
             coalesce(CODSABLON, 0),
             coalesce(CODANALIZANOD, 0),
             coalesce(CODPERS, 0),
             coalesce(CODCLASIF, 0),
             coalesce(CODAUTO, 0)
      INTO
        aCODMIFIX1PREC,
        aCODCENTRU,
        aCODSABLON,
        aCODANALIZANOD,
        aCODPERS,
        aCODCLASIF,
        aCODAUTO
    FROM
      MIFIX1
    WHERE
      CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN aCODMIFIX1PREC := 0; aCODCENTRU := 0; aCODSABLON :=0; aCODANALIZANOD := 0; aCodPers := 0;
        aCodClasif := 0; aCodAuto := 0;
    END;

    IF aCODCLASIF = 0 THEN
      BEGIN
        SELECT CODCLASIF INTO aCODCLASIF FROM MASTERMIFIX MF WHERE MF.CODNIRSTOC = V_REC.CODNIRSTOC;
        EXCEPTION WHEN OTHERS THEN aCODCLASIF := 0;
      END;
    END IF;

   IF (NVL(aCODCENTRU, 0) &lt;&gt; 0)AND(NVL(V_REC.CENTRUBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1
      SET
        CODCENTRU = aCODCENTRU
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
   END IF;

   IF (NVL(aCODAUTO, 0) &lt;&gt; 0) THEN
      UPDATE MIFIX1
      SET
        CODAUTO = aCODAUTO
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
   END IF;


   IF (NVL(aCODCLASIF, 0) &lt;&gt; 0)AND(NVL(V_REC.CODCLASIFBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1
      SET
        CODCLASIF = aCODCLASIF
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
   END IF;



    IF NVL(aCODSABLON, 0) &lt;&gt; 0 THEN
      UPDATE MIFIX1
      SET
        CODSABLON = aCODSABLON
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;

    IF NVL(aCODANALIZANOD, 0) &lt;&gt; 0 AND(NVL(V_REC.NODANALIZABLOCAT, 0) = 0) THEN
      UPDATE MIFIX1
      SET
        CODANALIZANOD = aCODANALIZANOD
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;


    IF NVL(aCODMIFIX1PREC, 0) &lt;&gt; 0  AND (NVL(V_REC.CODPERSBLOCAT, 0) = 0) THEN
      UPDATE MIFIX1
      SET
        CODPERS = aCODPERS
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;




  END LOOP;

  BEGIN
    SELECT NVL(pkg_categconst.GetValConstanta(&apos;UseRezervaReev&apos;, vAnTemp, vLunaTemp), &apos;0&apos;) INTO aUseRezerve from dual;
    EXCEPTION WHEN OTHERS THEN aUseRezerve := &apos;0&apos;;
  END;

  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp)
  LOOP
     BEGIN
       SELECT
         DATAREEVAL,
         NVL(PRETVECHI,0),
         NVL(AMOVECHI, 0),
         NVL(REZERVA, 0),
         NVL(PRET,0),
         NVL(AMO, 0) ,
         NVL(TIPREEVAL, 0),
         NVL(DURATAF, 0)
       INTO
         ADATAREEVAL,
         APRETVECHI,
         AAMOVECHI,
         AREZERVAVECHE,
         APRETPREC,
         AAMOPREC,
         ATIPREEVAL,
         DURATAFPREC
       FROM
         MIFIX1
       WHERE
         CODMIFIX      = V_REC.CODMIFIX
         AND ANSTART   = vAnPrec
         AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN ADATAREEVAL := NULL; APRETVECHI := 0; AAMOVECHI := 0; AREZERVAVECHE := 0; APRETPREC := 0; AAMOPREC := 0;
     END;

     IF (NVL(aUseRezerve, &apos;0&apos;)=&apos;1&apos;)and(aDATAREEVAL IS NOT NULL) THEN

       UPDATE MIFIX1
       SET
         REZERVA =  CASE
                       WHEN aTIPREEVAL = 0 THEN NVL(AREZERVAVECHE, 0) + (APRETPREC  - AAMOPREC) - (APRETVECHI - AAMOVECHI)
                       WHEN NVL(DURATAFPREC, 0) &lt;&gt; 0 THEN NVL(AREZERVAVECHE, 0) + APRETPREC   - (APRETVECHI - AAMOVECHI - (aPRETVECHI - aAMOVECHI) / DURATAFPREC )
                       ELSE NULL
                    END
       WHERE
         CODMIFIX1 = V_REC.CODMIFIX1;
     END IF;

  END LOOP;


  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND DURATAF &lt; 0)
  LOOP
    UPDATE MIFIX1
    SET
      DURATAF = 0
    WHERE
      CODMIFIX1 = V_REC.CODMIFIX1;
  END LOOP;


  PROPAGA_EXTENSII_MIFIX;

  COMMIT;
END;


PROCEDURE MAKE_NCONT_LUNA(NUME_TABELA IN VARCHAR2, aAN IN NUMBER, aLUNA IN NUMBER)
IS
 TXT VARCHAR2(1000);
 AN_SOLD_INI NUMBER(10);
BEGIN
  IF aLUNA &gt;= /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN
    AN_SOLD_INI :=  aAN;
  ELSE
    AN_SOLD_INI :=  aAN - 1;
  END IF;



  TXT := &apos; INSERT INTO &apos; || NUME_TABELA || &apos; &apos; ||
         &apos; SELECT N.CODCONT, N.SIMBOL, N.NIVEL, N.CODPARINTE, 0, N1.ANSTART, N1.LUNASTART, SI.SOLDID, SI.SOLDIC, SI.SOLDVID, SI.SOLDVIC, SI.SOLDI_IFRS, SI.SOLDVI_IFRS,  SI.SOLDI_GRUP, SI.SOLDVI_GRUP, RUL.RULAJPD, RUL.RULAJPC, &apos; ||
         &apos;        RUL.RULAJCD, RUL.RULAJCC, RUL.RULAJVPD, RUL.RULAJVPC, RUL.RULAJVCD, RUL.RULAJVCC, RUL.RULAJP_IFRS, RUL.RULAJC_IFRS,  RUL.RULAJVP_IFRS, RUL.RULAJVC_IFRS, RUL.RULAJP_GRUP, RUL.RULAJC_GRUP,  RUL.RULAJVP_GRUP, RUL.RULAJVC_GRUP&apos; ||
         &apos; FROM NCONT N &apos; ||
         &apos;   LEFT JOIN NCONTSOLD SI  ON SI.CODCONT  = N.CODCONT AND SI.AN  = &apos; || AN_SOLD_INI || &apos; AND SI.LUNA = &apos; || /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/ 1 ||
         &apos;   LEFT JOIN NCONTRUL  RUL ON RUL.CODCONT = N.CODCONT AND RUL.AN = &apos; || aAN || &apos; AND RUL.LUNA = &apos; || aLUNA ||
         &apos;   INNER JOIN NCONT1 N1 ON N1.CODCONT = N.CODCONT &apos;|| chr(13) ||
         &apos; WHERE &apos;||To_Char(aAN*12+aLUNA)||&apos; BETWEEN N1.ALStart AND N1.ALStop &apos;||
         &apos; ORDER BY N.CODCONT&apos;;

  EXECUTE IMMEDIATE(TXT);
  EXECUTE IMMEDIATE(&apos;UPDATE &apos; || NUME_TABELA || &apos; N SET NRANALITICE = (SELECT COUNT(*) FROM &apos; || NUME_TABELA ||&apos; WHERE CODPARINTE = N.CODCONT)&apos;);
  COMMIT;
END;


-- PROCEDURA PREIA DIN LUNA ANTERIOARA RULAJELE SI LE PUNE PE RULAJPRECEDENT; DACA E CAZUL, FACE REPARTIZARI PE ANALITICELE NOU APARUTE
PROCEDURE MAKE_RULAJE_NCONT
IS
  vAnTemp      NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp    NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
  AnP          NUMBER(4)  := 0;
  LunaP        NUMBER(2)  := 0;
  Nr           NUMBER(10) := 0;
  aNrAnalitice NUMBER(10) := 0;
  vRowId       ROWID;
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(vAnTemp, vLunaTemp, ANP, LUNAP);
  DELETE TMP_NCONT_LUNA_1;
  DELETE TMP_NCONT_LUNA_2;

  --TMP_NCONT_LUNA_1 CONTINE PLANUL DE CONTURI DIN LUNA ANTERIOARA, CU SOLDURI INITIALE + RULAJE
  --TMP_NCONT_LUNA_2 CONTINE PLANUL DE CONTURI DIN LUNA CURENTA

  MAKE_NCONT_LUNA(&apos;TMP_NCONT_LUNA_1&apos;, Coalesce(ANP, 0),     Coalesce(LUNAP, 0));
  MAKE_NCONT_LUNA(&apos;TMP_NCONT_LUNA_2&apos;, Coalesce(vAnTemp, 0), Coalesce(vLunaTemp, 0));


  --PREGATESC SOLDURILE SI RULAJELE IN TMP_NCONT_LUNA_2

  --PUN PE ZERO SOLDURI + RULAJE IN TABELA DESTINATIE
  UPDATE TMP_NCONT_LUNA_2 L2
  SET ( SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS ) =
      (SELECT   0,     0,       0,       0,       0,       0,       0,    0,     0,       0,        0,        0,        0,       0, 0, 0, 0, 0 FROM DUAL);

  -- STERG RULAJELE CONTURILOR CARE NU SE MAI REGASESC IN LUNA CURENTA
  FOR V_REC IN (SELECT * FROM NCONTRUL WHERE  AN = vAnTemp AND LUNA = vLunaTemp AND CODCONT NOT IN (SELECT CODCONT FROM TMP_NCONT_LUNA_2 L2))
  LOOP
    DELETE FROM NCONTRULSUB WHERE CODCONTRUL = V_REC.CODCONTRUL;
    DELETE FROM NCONTRUL    WHERE CODCONTRUL = V_REC.CODCONTRUL;
  END LOOP;

  -- MUT IN TMP_NCONT_LUNA_2 SOLDURILE SI RULAJELE DIN LUNA ANTERIOARA
  UPDATE TMP_NCONT_LUNA_2 L2
  SET
    ( SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP) =
    (SELECT
      SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP,RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
     FROM TMP_NCONT_LUNA_1
     WHERE CODCONT = L2.CODCONT
     )
  WHERE CODCONT IN (SELECT CODCONT FROM TMP_NCONT_LUNA_1 WHERE NRANALITICE = 0);

  --TRATEZ ANALITICE NOU APARUTE
  --pentru analiticele ale caror parinti au un singur analitic refac datele din NCONTREPSOLD si NCONTREPRUL
  FOR V_REC IN (SELECT * FROM TMP_NCONT_LUNA_2 WHERE CODCONT NOT IN (SELECT CODCONT FROM TMP_NCONT_LUNA_1) ORDER BY CODCONT)
  LOOP
    BEGIN
      SELECT NRANALITICE INTO aNRANALITICE FROM TMP_NCONT_LUNA_2 WHERE CODCONT = V_REC.CODPARINTE;
      EXCEPTION WHEN OTHERS THEN aNRANALITICE := 0;
    END;

    IF aNRANALITICE = 1 THEN
      --NCONTREP
      SELECT COUNT(*) INTO NR FROM NCONTREP WHERE CODCONT = V_REC.CODPARINTE;
      IF NR = 0 THEN
        INSERT INTO NCONTREP (CODCONTREP, CODCONT, AN, LUNA)
        VALUES (SEQ_NCONTREP_CODCONTREP.NEXTVAL, V_REC.CODPARINTE, vAnTemp, vLunaTemp);
      END IF;

      --ACTUALIZEZ SI SOLDUL DE LA INCEPUTUL ANULUI;

      --NCONTSOLD
      SELECT COUNT(*) INTO NR FROM NCONTSOLD WHERE CODCONT = V_REC.CODCONT AND AN = vAnTemp AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/ 1;
      IF NR = 0 THEN
        INSERT INTO NCONTSOLD(
          CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, AN, LUNA)
        SELECT
          SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, V_REC.CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, vAnTemp, /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1
        FROM TMP_NCONT_LUNA_2
        WHERE CODCONT = V_REC.CODPARINTE;
      ELSE
        UPDATE NCONTSOLD
        SET
          (       SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP ) =
          (SELECT SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP FROM TMP_NCONT_LUNA_2 L2 WHERE L2.CODCONT = V_REC.CODPARINTE)
        WHERE CODCONT = V_REC.CODCONT AND AN = vAnTemp AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
      END IF;

      --NCONTREPSOLD
      SELECT COUNT(*) INTO NR FROM NCONTREPSOLD WHERE CODCONT = V_REC.CODCONT;
      IF NR = 0 THEN
        INSERT INTO NCONTREPSOLD(
          CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP)
        SELECT
          SEQ_NCONTREPSOLD_CODCONTREPS.NEXTVAL, V_REC.CODCONT, V_REC.CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP
        FROM TMP_NCONT_LUNA_2 WHERE CODCONT = V_REC.CODPARINTE;
      ELSE
        UPDATE NCONTREPSOLD
        SET
          (       SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP  ) =
          (SELECT SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP FROM TMP_NCONT_LUNA_2 WHERE CODCONT = V_REC.CODPARINTE)
        WHERE CODCONT = V_REC. CODCONT;
      END IF;

      --NCONTREPRUL
      SELECT COUNT(*) INTO NR FROM NCONTREPRUL WHERE CODCONT = V_REC.CODCONT;

      IF NR = 0 THEN
        INSERT INTO NCONTREPRUL (
          CODCONTREPRUL,
          CODCONT,
          CODPARINTE,
          RULAJPD,
          RULAJPC,
          RULAJVPD,
          RULAJVPC,
          RULAJP_IFRS,
          RULAJVP_IFRS,
          RULAJP_GRUP,
          RULAJVP_GRUP
        )
        SELECT
          SEQ_NCONTREPRUL_CODCONTREPRUL.NEXTVAL,
          V_REC.CODCONT,
          V_REC.CODPARINTE,
          RULAJPD + RULAJCD,
          RULAJPC + RULAJCC,
          RULAJVPD + RULAJVCD,
          RULAJVPC + RULAJVCC,
          RULAJP_IFRS + RULAJC_IFRS,
          RULAJVP_IFRS + RULAJVC_IFRS,
          RULAJP_GRUP + RULAJC_GRUP,
          RULAJVP_GRUP + RULAJVC_GRUP
        FROM TMP_NCONT_LUNA_2
        WHERE CODCONT = V_REC.CODPARINTE;
      ELSE
        UPDATE NCONTREPRUL
        SET
          (RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS, RULAJP_GRUP, RULAJVP_GRUP ) =
          (SELECT
            RULAJPD      + RULAJCD,
            RULAJPC      + RULAJCC,
            RULAJVPD     + RULAJVCD,
            RULAJVPC     + RULAJVCC,
            RULAJP_IFRS  + RULAJC_IFRS,
            RULAJVP_IFRS + RULAJVC_IFRS,
            RULAJP_GRUP  + RULAJC_GRUP,
            RULAJVP_GRUP + RULAJVC_GRUP
          FROM TMP_NCONT_LUNA_2
          WHERE CODCONT = V_REC.CODPARINTE)
        WHERE CODCONT = V_REC.CODCONT;
      END IF;

      -- PUN SOLDURILE/RULAJELE PARINTELUI SI IN TMP_NCONT_LUNA_2 - PENTRU CAZUL CAND AM CREAT IN LUNA ANALIZATA  ANALITIC LA ANALITIC
      UPDATE TMP_NCONT_LUNA_2
      SET
        (   SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP,
            RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS, RULAJP_GRUP, RULAJVP_GRUP ) =
        ( SELECT
            SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP,
            RULAJPD      + RULAJCD,
            RULAJPC      + RULAJCC,
            RULAJVPD     + RULAJVCD,
            RULAJVPC     + RULAJVCC,
            RULAJP_IFRS  + RULAJC_IFRS,
            RULAJVP_IFRS + RULAJVC_IFRS,
            RULAJP_GRUP  + RULAJC_GRUP,
            RULAJVP_GRUP + RULAJVC_GRUP
          FROM TMP_NCONT_LUNA_2
          WHERE CODCONT = V_REC.CODPARINTE)
      WHERE CODCONT = V_REC.CODCONT;
    END IF;
  END LOOP;

  UPDATE TMP_NCONT_LUNA_2 L2
  SET
    (       SOLDID,  SOLDIC,  SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP )   =
    (SELECT SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP FROM NCONTREPSOLD WHERE CODCONT = L2.CODCONT ),
    (       RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJP_IFRS, RULAJVP_IFRS, RULAJP_GRUP, RULAJVP_GRUP) =
    (SELECT RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,  RULAJP_IFRS, RULAJVP_IFRS, RULAJP_GRUP, RULAJVP_GRUP FROM NCONTREPRUL WHERE CODCONT = L2.CODCONT)
  WHERE CODCONT NOT IN (SELECT CODCONT FROM TMP_NCONT_LUNA_1);

  --SALVEZ RULAJELE + SOLDURILE PREGATITE IN TMP_NCONT_LUNA_2
  FOR V_RULAJE IN (SELECT * FROM TMP_NCONT_LUNA_2  /* WHERE  NRANALITICE = 0 */)
  LOOP
    -- RULAJE
    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_RULAJE.CODCONT AND AN = vAnTemp AND LUNA = vLunaTemp;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(
        CODCONTRUL,
        CODCONT,
        RULAJPD,
        RULAJPC,
        RULAJCD,
        RULAJCC,
        RULAJVPD,
        RULAJVPC,
        RULAJVCD,
        RULAJVCC,
        RULAJP_IFRS,
        RULAJVP_IFRS,
        RULAJC_IFRS,
        RULAJVC_IFRS,
        RULAJP_GRUP,
        RULAJVP_GRUP,
        RULAJC_GRUP,
        RULAJVC_GRUP,
        AN, LUNA)
      VALUES (
        SEQ_NCONTRUL_CODCONTRUL.NEXTVAL,
        V_RULAJE.CODCONT,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) ELSE 0 END,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0) ELSE 0 END,
        0,
        0,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) ELSE 0 END,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0) ELSE 0 END,
        0,
        0,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJP_IFRS, 0) + NVL(V_RULAJE.RULAJC_IFRS, 0) ELSE 0 END,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVP_IFRS,0) + NVL(V_RULAJE.RULAJVC_IFRS,0) ELSE 0 END,
        0,
        0,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJP_GRUP, 0) + NVL(V_RULAJE.RULAJC_GRUP, 0) ELSE 0 END,
        CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVP_GRUP,0) + NVL(V_RULAJE.RULAJVC_GRUP,0) ELSE 0 END,
        0,
        0,
        vAnTemp, vLunaTemp);
    ELSE
      UPDATE NCONTRUL
      SET
        RULAJPD     = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJPD,     0) + NVL(V_RULAJE.RULAJCD,     0) ELSE 0 END,
        RULAJPC     = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJPC,     0) + NVL(V_RULAJE.RULAJCC,     0) ELSE 0 END,
        RULAJVPD    = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVPD,    0) + NVL(V_RULAJE.RULAJVCD,    0) ELSE 0 END,
        RULAJVPC    = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVPC,    0) + NVL(V_RULAJE.RULAJVCC,    0) ELSE 0 END,
        RULAJP_IFRS = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJP_IFRS, 0) + NVL(V_RULAJE.RULAJC_IFRS, 0) ELSE 0 END,
        RULAJVP_IFRS= CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVP_IFRS,0) + NVL(V_RULAJE.RULAJVC_IFRS,0) ELSE 0 END,
        RULAJP_GRUP = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJP_GRUP, 0) + NVL(V_RULAJE.RULAJC_GRUP, 0) ELSE 0 END,
        RULAJVP_GRUP= CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_RULAJE.RULAJVP_GRUP,0) + NVL(V_RULAJE.RULAJVC_GRUP,0) ELSE 0 END
      WHERE CODCONT = V_RULAJE.CODCONT AND AN = vAnTemp AND LUNA = vLunaTemp;
    END IF;

    IF vLunaTemp = /*PKG_GLOBALS.GET_LUNA_START_AN_CONTABIL*/1 THEN -- SUNT IN IANUARIE; ACTUALIZEZ SOLDUL INITIAL

    SELECT COUNT(*) INTO NR FROM NCONTSOLD WHERE CODCONT = V_RULAJE.CODCONT AND AN = vAnTemp AND LUNA = vLunaTemp;
    IF NR = 0 THEN
      INSERT INTO NCONTSOLD (
        CODCONTSOLD,
        CODCONT,
        SOLDID,
        SOLDIC,
        SOLDVID,
        SOLDVIC,
        SOLDI_IFRS,
        SOLDVI_IFRS,
        SOLDI_GRUP,
        SOLDVI_GRUP,
        AN, LUNA)
      VALUES (
        SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL,
        V_RULAJE.CODCONT,
        CASE
          WHEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) &gt; NVL(V_RULAJE.SOLDIC, 0)  + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0)
          THEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) - (NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0))
          ELSE 0
        END,
        CASE
          WHEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) &lt; NVL(V_RULAJE.SOLDIC, 0)  + NVL(V_RULAJE.RULAJPC, 0)  + NVL(V_RULAJE.RULAJCC, 0)
          THEN NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0) - (NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0))
          ELSE 0
        END,
        CASE
          WHEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) &gt; NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0)
          THEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) - (NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0))
          ELSE 0
        END,
        CASE
          WHEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) &lt; NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0)
          THEN NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0) - (NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0))
          ELSE 0
        END,
        NVL(V_RULAJE.SOLDI_IFRS, 0) + NVL(V_RULAJE.RULAJP_IFRS, 0) + NVL(V_RULAJE.RULAJC_IFRS, 0),
        NVL(V_RULAJE.SOLDVI_IFRS,0) + NVL(V_RULAJE.RULAJVP_IFRS,0) + NVL(V_RULAJE.RULAJVC_IFRS, 0),
        NVL(V_RULAJE.SOLDI_GRUP, 0) + NVL(V_RULAJE.RULAJP_GRUP, 0) + NVL(V_RULAJE.RULAJC_GRUP, 0),
        NVL(V_RULAJE.SOLDVI_GRUP,0) + NVL(V_RULAJE.RULAJVP_GRUP,0) + NVL(V_RULAJE.RULAJVC_GRUP, 0),
        vAnTemp, vLunaTemp);
     ELSE
       UPDATE NCONTSOLD
       SET
         SOLDID  = CASE
                     WHEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) &gt; NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0)
                     THEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) - (NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0))
                     ELSE 0
                   END,
         SOLDIC  = CASE
                     WHEN NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0) &lt;  NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0)
                     THEN NVL(V_RULAJE.SOLDIC, 0) + NVL(V_RULAJE.RULAJPC, 0) + NVL(V_RULAJE.RULAJCC, 0) - (NVL(V_RULAJE.SOLDID, 0) + NVL(V_RULAJE.RULAJPD, 0) + NVL(V_RULAJE.RULAJCD, 0))
                     ELSE 0
                   END,
         SOLDVID = CASE
                     WHEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) &gt; NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0)
                     THEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) - (NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC + V_RULAJE.RULAJVCC, 0))
                     ELSE 0
                   END,
         SOLDVIC = CASE
                     WHEN NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0) &lt; NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0)
                     THEN NVL(V_RULAJE.SOLDVIC, 0) + NVL(V_RULAJE.RULAJVPC, 0) + NVL(V_RULAJE.RULAJVCC, 0) - (NVL(V_RULAJE.SOLDVID, 0) + NVL(V_RULAJE.RULAJVPD, 0) + NVL(V_RULAJE.RULAJVCD, 0))
                     ELSE 0
                   END,
         SOLDI_IFRS  = NVL(V_RULAJE.SOLDI_IFRS, 0) + NVL(V_RULAJE.RULAJP_IFRS, 0) + NVL(V_RULAJE.RULAJC_IFRS, 0),
         SOLDVI_IFRS = NVL(V_RULAJE.SOLDVI_IFRS, 0) + NVL(V_RULAJE.RULAJVP_IFRS, 0) + NVL(V_RULAJE.RULAJVC_IFRS, 0),
         SOLDI_GRUP  = NVL(V_RULAJE.SOLDI_GRUP, 0) + NVL(V_RULAJE.RULAJP_GRUP, 0) + NVL(V_RULAJE.RULAJC_GRUP, 0),
         SOLDVI_GRUP = NVL(V_RULAJE.SOLDVI_GRUP, 0) + NVL(V_RULAJE.RULAJVP_GRUP, 0) + NVL(V_RULAJE.RULAJVC_GRUP, 0)
       WHERE CODCONT = V_RULAJE.CODCONT AND AN = vAnTemp AND LUNA = vLunaTemp;
     END IF;
   END IF;

  END LOOP;

 -- rulaje precedente in NCONTRULSUB
  FOR V_REC IN (
    SELECT
      R_CURENT.CODCONTRUL, RS_PREC.SUBUNITATEA, RS_PREC.RULAJPD, RS_PREC.RULAJCD, RS_PREC.RULAJPC, RS_PREC.RULAJCC,
      RS_PREC.RULAJVPD, RS_PREC.RULAJVCD, RS_PREC.RULAJVPC, RS_PREC.RULAJVCC,
      RS_PREC.RULAJP_IFRS, RS_PREC.RULAJC_IFRS, RS_PREC.RULAJVP_IFRS, RS_PREC.RULAJVC_IFRS,
      RS_PREC.RULAJP_GRUP, RS_PREC.RULAJC_GRUP, RS_PREC.RULAJVP_GRUP,  RS_PREC.RULAJVC_GRUP
   FROM
     NCONTRUL R_PREC,
     NCONTRULSUB RS_PREC,
     NCONTRUL R_CURENT
    WHERE R_PREC.AN = ANP
      AND R_PREC.LUNA = LUNAP
      AND RS_PREC.CODCONTRUL = R_PREC.CODCONTRUL
      AND R_CURENT.AN   = vAnTemp
      AND R_CURENT.LUNA = vLunaTemp
      AND R_CURENT.CODCONT = R_PREC.CODCONT
      AND RS_PREC.SUBUNITATEA IS NOT NULL -- stef 13.02.2014 pe mitropolie sunt foarte multe linii ci subunitatea null si dureaza f.mult
   )
  LOOP
    SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    IF NR = 0 THEN
      INSERT INTO NCONTRULSUB(
        CODCONTRULSUB, CODCONTRUL, SUBUNITATEA,
        RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP)
      VALUES (
        SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC.CODCONTRUL, V_REC.SUBUNITATEA,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,
        0, 0, 0, 0);
    END IF;

    UPDATE NCONTRULSUB
    SET
      RULAJPD     = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJPD,     0) + NVL(V_REC.RULAJCD,     0) ELSE 0 END,
      RULAJPC     = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJPC,     0) + NVL(V_REC.RULAJCC,     0) ELSE 0 END,
      RULAJVPD    = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJVPD,    0) + NVL(V_REC.RULAJVCD,    0) ELSE 0 END,
      RULAJVPC    = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJVPC,    0) + NVL(V_REC.RULAJVCC,    0) ELSE 0 END,
      RULAJP_IFRS = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJP_IFRS, 0) + NVL(V_REC.RULAJC_IFRS, 0) ELSE 0 END,
      RULAJVP_IFRS= CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJVP_IFRS,0) + NVL(V_REC.RULAJVC_IFRS,0) ELSE 0 END,
      RULAJP_GRUP = CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJP_GRUP, 0) + NVL(V_REC.RULAJC_GRUP, 0) ELSE 0 END,
      RULAJVP_GRUP= CASE WHEN vLunaTemp &lt;&gt; /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN NVL(V_REC.RULAJVP_GRUP,0) + NVL(V_REC.RULAJVC_GRUP,0) ELSE 0 END
    WHERE CODCONTRUL = V_REC.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
  END LOOP;


  --REZOLV NCONTSOLDSUB
  IF vLunaTemp = /*PKG_GLOBALS.GET_LUNA_START_AN_CONTABIL*/1 THEN
    --pregatesc o manevra cu solduri initiale si rulaje la finalul anului precedent
    DELETE TMP_NCONT_MAN;

    -- populez cu rulaje si SOLDURILE INITIALE DIN ANUL PRECEDENT
    -- STEF - inlouiesc loopurile comentate de mai jos cu un singur insert
    INSERT INTO TMP_NCONT_MAN (
      CODCONT, SUBUNITATEA,
      SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP,
      RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP)
    SELECT
      CODCONT, SUBUNITATEA,
      Sum(Nvl(SOLDID,0)), Sum(Nvl(SOLDIC,0)), Sum(Nvl(SOLDVID,0)), Sum(Nvl(SOLDVIC,0)), Sum(Nvl(SOLDI_IFRS,0)), Sum(Nvl(SOLDVI_IFRS,0)), Sum(Nvl(SOLDI_GRUP,0)), Sum(Nvl(SOLDVI_GRUP,0)),
      Sum(Nvl(RULAJPD,0)), Sum(Nvl(RULAJPC,0)), Sum(Nvl(RULAJCD,0)), Sum(Nvl(RULAJCC,0)), Sum(Nvl(RULAJVPD,0)), Sum(Nvl(RULAJVPC,0)), Sum(Nvl(RULAJVCD,0)), Sum(Nvl(RULAJVCC,0)),
      Sum(Nvl(RULAJP_IFRS,0)), Sum(Nvl(RULAJC_IFRS,0)), Sum(Nvl(RULAJVP_IFRS,0)), Sum(Nvl(RULAJVC_IFRS,0)),
      Sum(Nvl(RULAJP_GRUP,0)), Sum(Nvl(RULAJC_GRUP,0)), Sum(Nvl(RULAJVP_GRUP,0)), Sum(Nvl(RULAJVC_GRUP,0))
    FROM (
      SELECT
        RP.CODCONT, RP_SUB.SUBUNITATEA,
        0 SOLDID, 0 SOLDIC, 0 SOLDVID, 0 SOLDVIC, 0 SOLDI_IFRS, 0 SOLDVI_IFRS, 0 SOLDI_GRUP, 0 SOLDVI_GRUP,
        RP_SUB.RULAJPD, RP_SUB.RULAJPC, RP_SUB.RULAJCD, RP_SUB.RULAJCC, RP_SUB.RULAJVPD, RP_SUB.RULAJVPC, RP_SUB.RULAJVCD, RP_SUB.RULAJVCC,
        RP_SUB.RULAJP_IFRS, RP_SUB.RULAJC_IFRS, RP_SUB.RULAJVP_IFRS, RP_SUB.RULAJVC_IFRS,
        RP_SUB.RULAJP_GRUP, RP_SUB.RULAJC_GRUP, RP_SUB.RULAJVP_GRUP, RP_SUB.RULAJVC_GRUP
      FROM NCONTRUL RP INNER JOIN NCONTRULSUB RP_SUB ON RP.CODCONTRUL = RP_SUB.CODCONTRUL
      WHERE RP.AN = ANP AND RP.LUNA = LUNAP AND RP_SUB.SUBUNITATEA IS NOT NULL
      UNION ALL
      SELECT
        SP.CODCONT, SP_SUB.SUBUNITATEA,
        SP_SUB.SOLDID, SP_SUB.SOLDIC, SP_SUB.SOLDVID, SP_SUB.SOLDVIC, SP_SUB.SOLDI_IFRS, SP_SUB.SOLDVI_IFRS, SP_SUB.SOLDI_GRUP, SP_SUB.SOLDVI_GRUP,
        0 RULAJPD, 0 RULAJPC, 0 RULAJCD, 0 RULAJCC, 0 RULAJVPD, 0 RULAJVPC, 0 RULAJVCD, 0 RULAJVCC,
        0 RULAJP_IFRS, 0 RULAJC_IFRS, 0 RULAJVP_IFRS, 0 RULAJVC_IFRS,
        0 RULAJP_GRUP, 0 RULAJC_GRUP, 0 RULAJVP_GRUP, 0 RULAJVC_GRUP
      FROM NCONTSOLD SP INNER JOIN NCONTSOLDSUB SP_SUB ON SP.CODCONTSOLD = SP_SUB.CODCONTSOLD
      WHERE SP.AN = ANP AND SP.LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 AND SP_SUB.SUBUNITATEA IS NOT NULL
    )
    GROUP BY CODCONT, SUBUNITATEA;


    -- CALCULEZ SI POSTEZ SOLDURILE INITIALE PE SUBUNITATI
    FOR V_REC IN (
      SELECT
        SC.CODCONTSOLD, NC.SUBUNITATEA,
        NVL(NC.SOLDID, 0) + NVL(NC.RULAJPD, 0) + NVL(NC.RULAJCD, 0) - NVL(NC.SOLDIC, 0) - NVL(NC.RULAJPC, 0) - NVL(NC.RULAJCC, 0) SOLDI,
        NVL(NC.SOLDVID,0) + NVL(NC.RULAJVPD,0) + NVL(NC.RULAJVCD,0) - NVL(NC.SOLDVIC,0) - NVL(NC.RULAJVPC,0) - NVL(NC.RULAJVCC,0) SOLDVI,
        NVL(NC.SOLDI_IFRS, 0) + NVL(NC.RULAJP_IFRS, 0) + NVL(NC.RULAJC_IFRS, 0) SOLDI_IFRS,
        NVL(NC.SOLDVI_IFRS,0) + NVL(NC.RULAJVP_IFRS,0) + NVL(NC.RULAJVC_IFRS,0) SOLDVI_IFRS,
        NVL(NC.SOLDI_GRUP, 0) + NVL(NC.RULAJP_GRUP, 0) + NVL(NC.RULAJC_GRUP, 0) SOLDI_GRUP,
        NVL(NC.SOLDVI_GRUP,0) + NVL(NC.RULAJVP_GRUP,0) + NVL(NC.RULAJVC_GRUP,0) SOLDVI_GRUP
      FROM TMP_NCONT_MAN NC INNER JOIN NCONTSOLD SC ON SC.CODCONT = NC.CODCONT
      WHERE SC.AN = vAnTemp AND SC.LUNA = vLunaTemp
    ) LOOP

      BEGIN
        SELECT ROWID INTO vRowId FROM NCONTSOLDSUB WHERE CODCONTSOLD = V_REC.CODCONTSOLD AND SUBUNITATEA = V_REC.SUBUNITATEA AND ROWNUM = 1;
      EXCEPTION WHEN NO_DATA_FOUND THEN
        INSERT INTO NCONTSOLDSUB (CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA)
        VALUES (SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC.CODCONTSOLD, V_REC.SUBUNITATEA)
        RETURNING ROWID INTO vRowId;
      END;

      UPDATE NCONTSOLDSUB
      SET
        SOLDID      = CASE WHEN V_REC.SOLDI  &gt; 0 THEN  V_REC.SOLDI  ELSE 0 END,
        SOLDIC      = CASE WHEN V_REC.SOLDI  &lt; 0 THEN -V_REC.SOLDI  ELSE 0 END,
        SOLDVID     = CASE WHEN V_REC.SOLDVI &gt; 0 THEN  V_REC.SOLDVI ELSE 0 END,
        SOLDVIC     = CASE WHEN V_REC.SOLDVI &lt; 0 THEN -V_REC.SOLDVI ELSE 0 END,
        SOLDI_IFRS  = V_REC.SOLDI_IFRS,
        SOLDVI_IFRS = V_REC.SOLDVI_IFRS,
        SOLDI_GRUP  = V_REC.SOLDI_GRUP,
        SOLDVI_GRUP = V_REC.SOLDVI_GRUP
      WHERE ROWID = vRowId;--CODCONTSOLD = V_REC.CODCONTSOLD  AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END IF;


  IF vLunaTemp = 1 THEN -- noile solduri din ianuarie incerc a le pun in NCONTEREPSOLD si NCONTREPSRUL

    FOR V_REC IN (SELECT * FROM TMP_NCONT_LUNA_2 WHERE CODCONT NOT IN (SELECT CODCONT FROM TMP_NCONT_LUNA_1) ORDER BY CODCONT)
    LOOP
      BEGIN
        SELECT NRANALITICE INTO aNRANALITICE FROM TMP_NCONT_LUNA_2 WHERE CODCONT = V_REC.CODPARINTE;
        EXCEPTION WHEN OTHERS THEN aNRANALITICE := 0;
      END;

      IF aNRANALITICE = 1 THEN
        UPDATE NCONTREPSOLD
        SET
          (       SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP  ) =
          (SELECT SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP FROM NCONTSOLD WHERE CODCONT = V_REC.CODPARINTE AND AN = vAnTemp AND LUNA = vLunaTemp)
        WHERE CODCONT = V_REC. CODCONT;

        UPDATE NCONTREPRUL
        SET
          RULAJPD      = 0,
          RULAJPC      = 0,
          RULAJVPD     = 0,
          RULAJVPC     = 0,
          RULAJP_IFRS  = 0,
          RULAJVP_IFRS = 0,
          RULAJP_GRUP  = 0,
          RULAJVP_GRUP = 0
        WHERE
          CODCONT = V_REC. CODCONT;


      END IF;
   END LOOP;

-- ECHIVALARI DE CONTURI
  FOR V_REC IN (SELECT * FROM NCONTECHIV WHERE  AN = vAnTemp  AND LUNA = 1)
  LOOP
      UPDATE NCONTSOLD
      SET
        SOLDID       = NVL(SOLDID, 0)      + NVL(V_REC.SOLDID,  0),
        SOLDIC       = NVL(SOLDIC, 0)      + NVL(V_REC.SOLDIC,  0),
        SOLDVID      = NVL(SOLDVID, 0)     + NVL(V_REC.SOLDVID, 0),
        SOLDVIC      = NVL(SOLDVIC, 0)     + NVL(V_REC.SOLDVIC, 0),
        SOLDI_IFRS   = NVL(SOLDI_IFRS, 0)  + NVL(V_REC.SOLDI_IFRS, 0),
        SOLDVI_IFRS  = NVL(SOLDVI_IFRS, 0) + NVL(V_REC.SOLDVI_IFRS, 0),
        SOLDI_GRUP   = NVL(SOLDI_GRUP, 0)  + NVL(V_REC.SOLDI_GRUP, 0),
        SOLDVI_GRUP  = NVL(SOLDVI_GRUP, 0) + NVL(V_REC.SOLDVI_GRUP, 0)
      WHERE
        CODCONT = V_REC.CONTNOU
        AND AN = vAnTemp
        AND LUNA = 1;

  END LOOP;

  FOR V_REC IN (SELECT
                  S.CODCONTSOLD,
                  ES.*
                FROM
                  NCONTECHIVSUB ES,
                  NCONTECHIV E,
                  NCONTSOLD S
                WHERE
                  ES.CODCONTECHIV = E.CODCONTECHIV
                  AND E.AN = vAnTemp
                  AND E.LUNA = 1
                  AND S.CODCONT = E.CONTNOU
                  AND S.AN = E.AN
                  AND S.LUNA = 1
               )
   LOOP
      UPDATE NCONTSOLDSUB
      SET
        SOLDID       = NVL(SOLDID, 0)      + NVL(V_REC.SOLDID,  0),
        SOLDIC       = NVL(SOLDIC, 0)      + NVL(V_REC.SOLDIC,  0),
        SOLDVID      = NVL(SOLDVID, 0)     + NVL(V_REC.SOLDVID, 0),
        SOLDVIC      = NVL(SOLDVIC, 0)     + NVL(V_REC.SOLDVIC, 0),
        SOLDI_IFRS   = NVL(SOLDI_IFRS, 0)  + NVL(V_REC.SOLDI_IFRS, 0),
        SOLDVI_IFRS  = NVL(SOLDVI_IFRS, 0) + NVL(V_REC.SOLDVI_IFRS, 0),
        SOLDI_GRUP   = NVL(SOLDI_GRUP, 0)  + NVL(V_REC.SOLDI_GRUP, 0),
        SOLDVI_GRUP  = NVL(SOLDVI_GRUP, 0) + NVL(V_REC.SOLDVI_GRUP, 0)
      WHERE
        CODCONTSOLD = V_REC.CODCONTSOLD
        AND SUBUNITATEA = V_REC.CODSUBUNIT;
   END LOOP;
  END IF;
  COMMIT;
END;



-- PROCEDURA PREIA DIN LUNA ANTERIOARA RULAJELE pe subunitato SI LE PUNE PE RULAJPRECEDENT; SE APLELEAZA DUPA CLANSAREA MAKE_RULAJE_NCONT
PROCEDURE MAKE_RULAJE_NCONT_SUB IS
  ANP          NUMBER(4)  := 0;
  LUNAP        NUMBER(2)  := 0;
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANTEMP, PKG_GLOBALS.LUNATEMP, ANP, LUNAP);
END;

--procedura reface in NCONTRUL rulajele curente plecand de la JURNAL1;
--tranzactiile luate in calcul sunt cele cu AN = PKG_GLOBALS.ANLUCRU; LUNA = PKG_GLOBALS.LUNALUCRU;

PROCEDURE REMAKE_RULAJE_LUNA_FROMJURNAL(FAC_COMMIT IN NUMBER) IS
  vCodContRul    NUMBER(20);
  vCodContRulSub NUMBER(20);
BEGIN
  UPDATE NCONTRUL
  SET
    RULAJCD      = 0,
    RULAJCC      = 0,
    RULAJVCD     = 0,
    RULAJVCC     = 0,
    RULAJC_IFRS  = 0,
    RULAJVC_IFRS = 0,
    RULAJC_GRUP  = 0,
    RULAJVC_GRUP = 0
  WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

  UPDATE NCONTRULSUB
  SET
    RULAJCD      = 0,
    RULAJCC      = 0,
    RULAJVCD     = 0,
    RULAJVCC     = 0,
    RULAJC_IFRS  = 0,
    RULAJVC_IFRS = 0,
    RULAJC_GRUP  = 0,
    RULAJVC_GRUP = 0
  WHERE CODCONTRUL IN (SELECT CODCONTRUL FROM NCONTRUL WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

  FOR V_REC_JURNAL IN (
    SELECT
      CODCONT, SUBUNITATEA,
      Sum(RULAJCD) RULAJCD, Sum(RULAJVCD) RULAJVCD, Sum(RULAJCC) RULAJCC, Sum(RULAJVCC) RULAJVCC,
      Sum(RULAJC_IFRS) RULAJC_IFRS, Sum(RULAJVC_IFRS) RULAJVC_IFRS, Sum(RULAJC_GRUP) RULAJC_GRUP, Sum(RULAJVC_GRUP) RULAJVC_GRUP
    FROM (
      SELECT
        CONTD CODCONT, SUBUNITATEA,
        VALOARE RULAJCD, VALOAREV RULAJVCD, 0 RULAJCC, 0 RULAJVCC,
        VALOARE_IFRS RULAJC_IFRS, VALOAREV_IFRS RULAJVC_IFRS, VALOAREGRUP RULAJC_GRUP, PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV) RULAJVC_GRUP
      FROM JURNAL
      WHERE AN*12+LUNA = PKG_GLOBALS.ANLUNALUCRU
      UNION ALL
      SELECT
        CONTC CODCONT, SUBUNITATEA,
        0 RULAJCD, 0 RULAJVCD, VALOARE RULAJCC, VALOAREV RULAJVCC,
        -VALOARE_IFRS RULAJC_IFRS, -VALOAREV_IFRS RULAJVC_IFRS, -VALOAREGRUP RULAJC_GRUP, -PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV) RULAJVC_GRUP
      FROM JURNAL
      WHERE AN*12+LUNA = PKG_GLOBALS.ANLUNALUCRU
    )
    GROUP BY CODCONT, ROLLUP (SUBUNITATEA)
    ORDER BY CODCONT, Nvl(SUBUNITATEA,-1)
  ) LOOP
    IF V_REC_JURNAL.SUBUNITATEA IS NULL THEN -- POPULEZ NCONTRUL
      vCodContRul := NULL;
      UPDATE NCONTRUL
      SET
        RULAJCD      = V_REC_JURNAL.RULAJCD,
        RULAJVCD     = V_REC_JURNAL.RULAJVCD,
        RULAJCC      = V_REC_JURNAL.RULAJCC,
        RULAJVCC     = V_REC_JURNAL.RULAJVCC,
        RULAJC_IFRS  = V_REC_JURNAL.RULAJC_IFRS,
        RULAJVC_IFRS = V_REC_JURNAL.RULAJVC_IFRS,
        RULAJC_GRUP  = V_REC_JURNAL.RULAJC_GRUP,
        RULAJVC_GRUP = V_REC_JURNAL.RULAJVC_GRUP
      WHERE CODCONT = V_REC_JURNAL.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND ROWNUM = 1
      RETURNING CODCONTRUL INTO vCodContRul;

      IF vCodContRul IS NULL THEN
        INSERT INTO NCONTRUL(
          CODCONTRUL, CODCONT,
          RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
          RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
          RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
          AN, LUNA)
        VALUES (
          SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CODCONT,
          0, 0, V_REC_JURNAL.RULAJCD, V_REC_JURNAL.RULAJCC, 0, 0, V_REC_JURNAL.RULAJVCD, V_REC_JURNAL.RULAJVCC,
          0, V_REC_JURNAL.RULAJC_IFRS, 0, V_REC_JURNAL.RULAJVC_IFRS,
          0, V_REC_JURNAL.RULAJC_GRUP, 0, V_REC_JURNAL.RULAJVC_GRUP,
          PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
        RETURNING CODCONTRUL INTO vCodContRul;
      END IF;
    ELSE -- POPULEZ NCONTRULSUB
      vCodContRulSub := NULL;
      UPDATE NCONTRULSUB
      SET
        RULAJCD      = V_REC_JURNAL.RULAJCD,
        RULAJVCD     = V_REC_JURNAL.RULAJVCD,
        RULAJCC      = V_REC_JURNAL.RULAJCC,
        RULAJVCC     = V_REC_JURNAL.RULAJVCC,
        RULAJC_IFRS  = V_REC_JURNAL.RULAJC_IFRS,
        RULAJVC_IFRS = V_REC_JURNAL.RULAJVC_IFRS,
        RULAJC_GRUP  = V_REC_JURNAL.RULAJC_GRUP,
        RULAJVC_GRUP = V_REC_JURNAL.RULAJVC_GRUP
      WHERE CODCONTRUL = vCodContRul AND SUBUNITATEA = V_REC_JURNAL.SUBUNITATEA AND ROWNUM = 1
      RETURNING CODCONTRULSUB INTO vCodContRulSub;

      IF vCodContRulSub IS NULL THEN
        INSERT INTO NCONTRULSUB(
          CODCONTRULSUB, CODCONTRUL, SUBUNITATEA,
          RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
          RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
          RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP)
        VALUES (
          SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, vCodContRul, V_REC_JURNAL.SUBUNITATEA,
          0, 0, V_REC_JURNAL.RULAJCD, V_REC_JURNAL.RULAJCC, 0, 0, V_REC_JURNAL.RULAJVCD, V_REC_JURNAL.RULAJVCC,
          0, V_REC_JURNAL.RULAJC_IFRS, 0, V_REC_JURNAL.RULAJVC_IFRS,
          0, V_REC_JURNAL.RULAJC_GRUP, 0, V_REC_JURNAL.RULAJVC_GRUP);
      END IF;
    END IF;
  END LOOP;

/*
  FOR V_REC_JURNAL IN (SELECT
                         CONTD,
                         SUBUNITATEA,
                         SUM(VALOARE) AS VALOARE,
                         SUM(VALOAREV) AS VALOAREV,
                         SUM(VALOARE_IFRS) AS VALOARE_IFRS,
                         SUM(VALOAREV_IFRS) AS VALOAREV_IFRS,
                         SUM(VALOAREGRUP) AS VALOARE_GRUP,
                         SUM(PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV))
                         -- VALOAREGRUP / (VALOARE / DECODE(VALOAREV, 0, 1,VALOAREV)))
                         AS VALOAREV_GRUP
                       FROM
                         JURNAL
                       WHERE
                         AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU GROUP BY CONTD, SUBUNITATEA)
  LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;


    UPDATE NCONTRUL
    SET
      RULAJCD      = RULAJCD              + V_REC_JURNAL.VALOARE,
      RULAJVCD     = RULAJVCD             + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  + NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) + NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
      RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  + NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
      RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) + NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
    WHERE
      CODCONT = V_REC_JURNAL.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
    LOOP

      SELECT COUNT(*) INTO NR FROM NCONTRULSUB
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA =  V_REC_JURNAL.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
        )
        VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_JURN_SUB.CODCONTRUL,  V_REC_JURNAL.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
      END IF;


      UPDATE NCONTRULSUB
      SET
        RULAJCD      = RULAJCD  + V_REC_JURNAL.VALOARE,
        RULAJVCD     = RULAJVCD + V_REC_JURNAL.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  + NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) + NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  + NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) + NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC_JURNAL.SUBUNITATEA;
    END LOOP;


  END LOOP;


  FOR V_REC_JURNAL IN (SELECT
                         CONTC,
                         SUBUNITATEA,
                         SUM(VALOARE) AS VALOARE,
                         SUM(VALOAREV) AS VALOAREV,
                         SUM(VALOARE_IFRS) AS VALOARE_IFRS,
                         SUM(VALOAREV_IFRS) AS VALOAREV_IFRS,
                         SUM(VALOAREGRUP) AS VALOARE_GRUP,
--                       SUM(VALOAREGRUP / (VALOARE / DECODE(VALOAREV, 0, 1,VALOAREV))) AS VALOAREV_GRUP
                         SUM(PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV)) AS VALOAREV_GRUP
                       FROM
                         JURNAL
                       WHERE
                         AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
                       GROUP BY CONTC, SUBUNITATEA)
  LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;


    UPDATE NCONTRUL
    SET
      RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
      RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
      RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
      RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;



    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
    LOOP

      SELECT COUNT(*) INTO NR FROM NCONTRULSUB
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA =  V_REC_JURNAL.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
        )
        VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_JURN_SUB.CODCONTRUL,  V_REC_JURNAL.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
      END IF;

      UPDATE NCONTRULSUB
      SET
        RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
        RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC_JURNAL.SUBUNITATEA;
    END LOOP;
  END LOOP;
*/
  IF FAC_COMMIT = 1 THEN COMMIT;
  END IF;
END;


PROCEDURE REMAKE_RULAJE_SUB_FROMJURNAL(FAC_COMMIT IN NUMBER)
IS
NR NUMERIC := 0;
BEGIN
  FOR V_REC IN
  (SELECT * FROM NCONTRUL WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
  LOOP
    UPDATE NCONTRULSUB
    SET
      RULAJCD  = 0,
      RULAJCC  = 0,
      RULAJVCD = 0,
      RULAJVCC = 0,
      RULAJC_IFRS = 0,
      RULAJVC_IFRS = 0,
      RULAJC_GRUP = 0,
      RULAJVC_GRUP = 0
    WHERE
      CODCONTRUL = V_REC.CODCONTRUL;
  END LOOP;

  FOR V_REC_JURNAL IN (SELECT
                         CONTD,
                         SUBUNITATEA,
                         SUM(VALOARE) AS VALOARE,
                         SUM(VALOAREV) AS VALOAREV,
                         SUM(VALOARE_IFRS) AS VALOARE_IFRS,
                         SUM(VALOAREV_IFRS) AS VALOAREV_IFRS,
                         SUM(VALOAREGRUP) AS VALOARE_GRUP,
--                       SUM(VALOAREGRUP / (VALOARE / DECODE(VALOAREV, 0, 1,VALOAREV))) AS VALOAREV_GRUP
                         SUM(PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV)) AS VALOAREV_GRUP
                       FROM
                         JURNAL
                       WHERE
                         AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
                       GROUP BY CONTD, SUBUNITATEA)
  LOOP
    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
    LOOP

      SELECT COUNT(*) INTO NR FROM NCONTRULSUB
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA =  V_REC_JURNAL.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
        )
        VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_JURN_SUB.CODCONTRUL,  V_REC_JURNAL.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
      END IF;


      UPDATE NCONTRULSUB
      SET
        RULAJCD      = RULAJCD              + V_REC_JURNAL.VALOARE,
        RULAJVCD     = RULAJVCD             + V_REC_JURNAL.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  + NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) + NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  + NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) + NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC_JURNAL.SUBUNITATEA;
    END LOOP;
  END LOOP;


  FOR V_REC_JURNAL IN (SELECT
                         CONTC,
                         SUBUNITATEA,
                         SUM(VALOARE) AS VALOARE,
                         SUM(VALOAREV) AS VALOAREV,
                         SUM(VALOARE_IFRS) AS VALOARE_IFRS,
                         SUM(VALOAREV_IFRS) AS VALOAREV_IFRS,
                         SUM(VALOAREGRUP) AS VALOARE_GRUP,
--                       SUM(VALOAREGRUP / (VALOARE / DECODE(VALOAREV, 0, 1,VALOAREV))) AS VALOAREV_GRUP
                         SUM(PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV)) AS VALOAREV_GRUP
                       FROM
                         JURNAL
                       WHERE
                         AN = PKG_GLOBALS.ANLUCRU  AND LUNA = PKG_GLOBALS.LUNALUCRU
                       GROUP BY CONTC, SUBUNITATEA)
  LOOP
    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
    LOOP

      SELECT COUNT(*) INTO NR FROM NCONTRULSUB
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA =  V_REC_JURNAL.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
        )
        VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_JURN_SUB.CODCONTRUL,  V_REC_JURNAL.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0);
      END IF;

      UPDATE NCONTRULSUB
      SET
        RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
        RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC_JURNAL.VALOARE_IFRS, 0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC_JURNAL.VALOAREV_IFRS, 0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC_JURNAL.VALOARE_GRUP, 0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - NVL(V_REC_JURNAL.VALOAREV_GRUP, 0)
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC_JURNAL.SUBUNITATEA;
    END LOOP;
  END LOOP;


  IF FAC_COMMIT = 1 THEN COMMIT;
  END IF;
END;

-- REFACE RULAJELE PE TOATE LUNILE
PROCEDURE MAKE_RULAJE_SUBUNITATI
IS
  AI  NUMBER(5) := 0;
  AM  NUMBER(5) := 0;
  LI  NUMBER(5) := 0;
  LM  NUMBER(5) := 0;
  aAI NUMBER(5) := 0;
  aLI NUMBER(5) := 0;
BEGIN
  SELECT ANINITIAL, LUNAINITIALA, ANMAXIM, LUNAMAXIMA INTO AI, LI, AM, LM FROM FIRMALUNI;
  aAI := AI;
  aLI := LI;
  WHILE AI * 12 + LI &lt;= AM * 12 + LM
  LOOP
    PKG_GLOBALS.SETLUNALUCRU(AI, LI);
    PKG_INCHIDERI.REMAKE_RULAJE_SUB_FROMJURNAL(0);

    IF LI = 1 AND AI * 12 + LI &gt; aAI * 12 + aLI THEN
      PKG_GLOBALS.SETLUNATEMP(AI, LI);
      PKG_INCHIDERI.MAKE_SOLDINITIAL_SUBUNITATI;
    END IF;

    IF LI = 12 THEN
      LI := 1;
      AI := AI + 1;
    ELSE
      LI := LI + 1;
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE MAKE_SOLDINITIAL_SUBUNITATI
IS
  vAnTemp   NUMBER(4)  := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2)  := PKG_GLOBALS.GetLUNATEMP;
  ANP       NUMBER(4)  := 0;
  LUNAP     NUMBER(2)  := 0;
  NR        NUMBER(10) := 0;
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(vAnTemp, vLunaTemp, ANP, LUNAP);
  -- REZOLV NCONTSOLDSUB
  IF vLunaTemp = 1 THEN
   -- pregatesc o manevra cu solcuri initiale si rulaje la finalul anului precedent
    DELETE TMP_NCONT_MAN;

    -- populez cu rulaje
    FOR V_REC IN
    ( SELECT RP.CODCONT, RP_SUB.*
      FROM
        NCONTRUL RP,
        NCONTRULSUB RP_SUB
      WHERE
        RP.CODCONTRUL = RP_SUB.CODCONTRUL
        AND RP.AN     = ANP
        AND RP.LUNA   = LUNAP
    )
    LOOP
      SELECT COUNT(*) INTO NR FROM TMP_NCONT_MAN
      WHERE
        CODCONT = V_REC.CODCONT
        AND SUBUNITATEA = V_REC.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO TMP_NCONT_MAN (CODCONT, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
        RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
        )
        VALUES (V_REC.CODCONT, V_REC.SUBUNITATEA, V_REC.RULAJPD, V_REC.RULAJPC, V_REC.RULAJCD, V_REC.RULAJCC, V_REC.RULAJVPD, V_REC.RULAJVPC, V_REC.RULAJVCD, V_REC.RULAJVCC,
        V_REC.RULAJP_IFRS, V_REC.RULAJC_IFRS, V_REC.RULAJVP_IFRS, V_REC.RULAJVC_IFRS,
        V_REC.RULAJP_GRUP, V_REC.RULAJC_GRUP, V_REC.RULAJVP_GRUP, V_REC.RULAJVC_GRUP
        );
      ELSE
        UPDATE TMP_NCONT_MAN
        SET
          RULAJPD      = V_REC.RULAJPD,
          RULAJPC      = V_REC.RULAJPC,
          RULAJCD      = V_REC.RULAJCD,
          RULAJCC      = V_REC.RULAJCC,
          RULAJVPD     = V_REC.RULAJVPD,
          RULAJVPC     = V_REC.RULAJVPC,
          RULAJVCD     = V_REC.RULAJVCD,
          RULAJVCC     = V_REC.RULAJVCC,
          RULAJP_IFRS  = V_REC.RULAJP_IFRS,
          RULAJC_IFRS  = V_REC.RULAJC_IFRS,
          RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
          RULAJVC_IFRS = V_REC.RULAJVC_IFRS,

          RULAJP_GRUP  = V_REC.RULAJP_GRUP,
          RULAJC_GRUP  = V_REC.RULAJC_GRUP,
          RULAJVP_GRUP = V_REC.RULAJVP_GRUP,
          RULAJVC_GRUP = V_REC.RULAJVC_GRUP
        WHERE
          CODCONT = V_REC.CODCONT
          AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END IF;
    END LOOP;

    -- populez cu SOLDURILE INITIALE DIN ANUL PRECEDENT
    FOR V_REC IN
    ( SELECT SP.CODCONT, SP_SUB.*
      FROM
        NCONTSOLD SP,
        NCONTSOLDSUB SP_SUB
      WHERE
        SP.CODCONTSOLD = SP_SUB.CODCONTSOLD
        AND SP.AN     = ANP
        AND SP.LUNA   = 1
    )
    LOOP
      SELECT COUNT(*) INTO NR FROM TMP_NCONT_MAN
      WHERE
        CODCONT = V_REC.CODCONT  AND SUBUNITATEA = V_REC.SUBUNITATEA;

      IF NR = 0 THEN
        INSERT INTO TMP_NCONT_MAN (CODCONT, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
        SOLDI_IFRS, SOLDVI_IFRS,
        SOLDI_GRUP, SOLDVI_GRUP
        )
        VALUES (V_REC.CODCONT, V_REC.SUBUNITATEA, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC,
        V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS,
        V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP
        );
      ELSE
        UPDATE TMP_NCONT_MAN
        SET
          SOLDID      = V_REC.SOLDID,
          SOLDIC      = V_REC.SOLDIC,
          SOLDVID     = V_REC.SOLDVID,
          SOLDVIC     = V_REC.SOLDVIC,
          SOLDI_IFRS  = V_REC.SOLDI_IFRS,
          SOLDVI_IFRS = V_REC.SOLDVI_IFRS,
          SOLDI_GRUP  = V_REC.SOLDI_GRUP,
          SOLDVI_GRUP = V_REC.SOLDVI_GRUP
        WHERE
          CODCONT = V_REC.CODCONT AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END IF;
    END LOOP;

    -- CALCULEZ SI POSTEZ SOLDURILE INITIALE PE SUBUNITATI
    FOR V_REC IN
    (
      SELECT SC.CODCONTSOLD,
             NC.*
      FROM
       NCONTSOLD SC,
       TMP_NCONT_MAN NC
      WHERE
        SC.AN          = vAnTemp
        AND SC.LUNA    = vLunaTemp
        AND NC.CODCONT = SC.CODCONT
     )
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTSOLDSUB
       WHERE
         CODCONTSOLD = V_REC.CODCONTSOLD
         AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTSOLDSUB (CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA)
         VALUES (SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC.CODCONTSOLD, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTSOLDSUB
       SET
         SOLDID  = CASE
                     WHEN NVL(V_REC.SOLDID, 0) + NVL(V_REC.RULAJPD, 0) + NVL(V_REC.RULAJCD, 0) &gt; NVL(V_REC.SOLDIC, 0) + NVL(V_REC.RULAJPC, 0) + NVL(V_REC.RULAJCC, 0)
                          THEN NVL(V_REC.SOLDID, 0) + NVL(V_REC.RULAJPD, 0) + NVL(V_REC.RULAJCD, 0) - (NVL(V_REC.SOLDIC, 0) + NVL(V_REC.RULAJPC, 0) + NVL(V_REC.RULAJCC, 0))
                          ELSE 0
                   END,

         SOLDIC  = CASE
                     WHEN NVL(V_REC.SOLDID, 0) + NVL(V_REC.RULAJPD, 0) + NVL(V_REC.RULAJCD, 0) &lt;  NVL(V_REC.SOLDIC, 0) + NVL(V_REC.RULAJPC, 0) + NVL(V_REC.RULAJCC, 0)
                          THEN NVL(V_REC.SOLDIC, 0) + NVL(V_REC.RULAJPC, 0) + NVL(V_REC.RULAJCC, 0) - (NVL(V_REC.SOLDID, 0) + NVL(V_REC.RULAJPD, 0) + NVL(V_REC.RULAJCD, 0))
                          ELSE 0
                   END,
         SOLDVID = CASE
                     WHEN NVL(V_REC.SOLDVID, 0) + NVL(V_REC.RULAJVPD, 0) + NVL(V_REC.RULAJVCD, 0) &gt; NVL(V_REC.SOLDVIC, 0) + NVL(V_REC.RULAJVPC, 0) + NVL(V_REC.RULAJVCC, 0)
                          THEN NVL(V_REC.SOLDVID, 0) + NVL(V_REC.RULAJVPD, 0) + NVL(V_REC.RULAJVCD, 0) - (NVL(V_REC.SOLDVIC, 0) + NVL(V_REC.RULAJVPC + V_REC.RULAJVCC, 0))
                          ELSE 0
                   END,
         SOLDVIC = CASE
                     WHEN NVL(V_REC.SOLDVID, 0) + NVL(V_REC.RULAJVPD, 0) + NVL(V_REC.RULAJVCD, 0) &lt; NVL(V_REC.SOLDVIC, 0) + NVL(V_REC.RULAJVPC, 0) + NVL(V_REC.RULAJVCC, 0)
                          THEN NVL(V_REC.SOLDVIC, 0) + NVL(V_REC.RULAJVPC, 0) + NVL(V_REC.RULAJVCC, 0) - (NVL(V_REC.SOLDVID, 0) + NVL(V_REC.RULAJVPD, 0) + NVL(V_REC.RULAJVCD, 0))
                     ELSE 0
                   END,
         SOLDI_IFRS  = NVL(V_REC.SOLDI_IFRS, 0) + NVL(V_REC.RULAJP_IFRS, 0) + NVL(V_REC.RULAJC_IFRS, 0),

         SOLDVI_IFRS = NVL(V_REC.SOLDVI_IFRS, 0) + NVL(V_REC.RULAJVP_IFRS, 0) + NVL(V_REC.RULAJVC_IFRS, 0),

         SOLDI_GRUP  = NVL(V_REC.SOLDI_GRUP, 0) + NVL(V_REC.RULAJP_GRUP, 0) + NVL(V_REC.RULAJC_GRUP, 0),

         SOLDVI_GRUP = NVL(V_REC.SOLDVI_GRUP, 0) + NVL(V_REC.RULAJVP_GRUP, 0) + NVL(V_REC.RULAJVC_GRUP, 0)
       WHERE
         CODCONTSOLD = V_REC.CODCONTSOLD  AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;

  END IF;

  COMMIT;
END;

PROCEDURE UPD_RUL_SI_SOLD_SUB_FROMTMP(pSub IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER)
IS
  vRecId       INTEGER;
  vCount       INTEGER;
  bSpecial     BOOLEAN;
  vIniRulajpd  NUMBER;
  vIniRulajpc  NUMBER;
  vIniRulajvpd NUMBER;
  vIniRulajvpc NUMBER;
  vSoldID      NUMBER;
  vSoldIC      NUMBER;
  vSoldVID     NUMBER;
  vSoldVIC     NUMBER;

BEGIN
  IF pAn = PKG_GLOBALS.GETANINITIAL AND PKG_GLOBALS.GETLUNAINITIALA &lt;&gt; 1
  THEN bSpecial := True;
  ELSE bSpecial := False;
  END IF;

  FOR v_rec IN (
    SELECT r.CodContRul, r.CodCont,
      Sum(Nvl(tr.rulajpd,0))  rulajpd,  Sum(Nvl(tr.rulajpc,0))  rulajpc,
      Sum(Nvl(tr.rulajcd,0))  rulajcd,  Sum(Nvl(tr.rulajcc,0))  rulajcc,
      Sum(Nvl(tr.rulajvpd,0)) rulajvpd, Sum(Nvl(tr.rulajvpc,0)) rulajvpc,
      Sum(Nvl(tr.rulajvcd,0)) rulajvcd, Sum(Nvl(tr.rulajvcc,0)) rulajvcc
    FROM NContRul r LEFT JOIN tmp_ncontrul tr ON tr.codcont = r.codcont AND tr.an = pAn AND tr.luna = pLuna
    WHERE r.an = pAn AND r.luna = pLuna
    GROUP BY R.CodContRul, R.CodCont
  )
  LOOP
    SELECT Min(CodContRulSub), Count(1) INTO vRecId, vCount FROM ncontrulsub WHERE Subunitatea = pSub AND CodContRul = v_rec.CodContRul;

    IF vCount &gt; 1 THEN
      DELETE ncontrulsub WHERE Subunitatea = pSub AND CodContRul = v_rec.CodContRul AND CodContRulSub &lt;&gt; vRecId;
    END IF;

    IF vCount = 0 THEN
      INSERT INTO NCONTRULSUB ( CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC)
      VALUES ( SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, v_rec.CODCONTRUL, pSub, v_rec.RULAJPD, v_rec.RULAJPC, v_rec.RULAJCD, v_rec.RULAJCC, v_rec.RULAJVPD, v_rec.RULAJVPC, v_rec.RULAJVCD, v_rec.RULAJVCC);
    ELSE
      vIniRulajpd  := 0;
      vIniRulajpc  := 0;
      vIniRulajvpd := 0;
      vIniRulajvpc := 0;
      IF bSpecial THEN
         BEGIN
          SELECT Sum(Nvl(rs.rulajpd,0)),  Sum(Nvl(rs.rulajpc,0)), Sum(Nvl(rs.rulajvpd,0)), Sum(Nvl(rs.rulajvpc,0))
          INTO vIniRulajpd, vIniRulajpc, vIniRulajvpd, vIniRulajvpc
          FROM ncontrul r LEFT JOIN ncontrulsub rs ON rs.CodContrul = r.CodContRul
          WHERE r.CodCont = v_rec.CodCont AND r.An = pAn AND r.Luna = PKG_GLOBALS.GETLUNAINITIALA AND rs.Subunitatea = pSub
          GROUP BY r.CodCont;
        EXCEPTION
          WHEN No_Data_Found THEN NULL;
        END;
      END IF;

      UPDATE ncontrulsub
      SET RULAJPD  = v_rec.rulajpd  + vIniRulajpd,
          RULAJPC  = v_rec.rulajpc  + vIniRulajpc,
          RULAJCD  = v_rec.rulajcd,
          RULAJCC  = v_rec.rulajcc,
          RULAJVPD = v_rec.rulajvpd + vIniRulajvpd,
          RULAJVPC = v_rec.rulajvpc + vIniRulajvpc,
          RULAJVCD = v_rec.rulajvcd,
          RULAJVCC = v_rec.rulajvcc
      WHERE CodContRulSub = vRecId;

    END IF;

  END LOOP;

  IF pLuna = 12 THEN
    DELETE TMP_NCONTSOLD;

    INSERT INTO TMP_NCONTSOLD (CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, AN, LUNA)
    SELECT 0, s.CODCONT, Sum(Nvl(ss.SOLDID,0)), Sum(Nvl(ss.SOLDIC,0)), Sum(Nvl(ss.SOLDVID,0)), Sum(Nvl(ss.SOLDVIC,0)), pAN, pLUNA
    FROM ncontsold s INNER JOIN ncontsoldsub ss ON ss.CodContSold = s.CodContSold
    WHERE s.an = pAn AND s.luna = 1 AND ss.subunitatea = pSub
    GROUP BY CodCont;

    FOR v_rec IN (
      WITH
        r12 AS (
          SELECT r.CodCont,
            Sum(Nvl(rs.rulajpd,0)  + Nvl(rs.rulajcd,0))  ruld,  Sum(Nvl(rs.rulajpc,0)  + Nvl(rs.rulajcc,0)) rulc,
            Sum(Nvl(rs.rulajvpd,0) + Nvl(rs.rulajvcd,0)) rulvd, Sum(Nvl(rs.rulajvpc,0) + Nvl(rs.rulajvcc,0)) rulvc
          FROM NContRul r INNER JOIN NContRulSub rs ON rs.CodContRul = r.codcontrul
          WHERE r.An = pAn AND r.Luna = pLuna AND rs.Subunitatea = pSub
          GROUP BY r.CodCont
        )
      SELECT s.CodContSold, s.CodCont, c.TipCont,
        Nvl(ts.soldid,0)+ Nvl(r12.ruld,0) totd,  Nvl(ts.soldic,0) + Nvl(r12.rulc,0) totc,
        Nvl(ts.soldvid,0)+ Nvl(r12.rulvd,0) totvd,  Nvl(ts.soldvic,0) + Nvl(r12.rulvc,0) totvc
      FROM NContSold s
        INNER JOIN ncont c         ON c.codcont = s.CodCont
        LEFT JOIN r12              ON r12.CodCont = s.CodCont
        LEFT JOIN tmp_ncontsold ts ON ts.CodCont = s.CodCont
      WHERE s.an = pAn+1 AND s.luna = 1
    )
    LOOP
      SELECT Min(CodContSoldSub), Count(1) INTO vRecId, vCount FROM ncontsoldsub WHERE Subunitatea = pSub AND CodContSold = v_rec.CodContSold;

      IF vCount &gt; 1 THEN
        DELETE ncontsoldsub WHERE Subunitatea = pSub AND CodContSold = v_rec.CodContSold AND CodContSoldSub &lt;&gt; vRecId;
      END IF;

      vSoldID  := 0; vSoldIC  := 0; vSoldVID := 0; vSoldVIC := 0;
      IF v_Rec.TipCont = 0 THEN
        vSoldID  := v_rec.totd  - v_rec.totc;
        vSoldVID := v_rec.totvd - v_rec.totvc;
      ELSIF v_Rec.TipCont = 1 THEN
        vSoldIC  := v_rec.totc  - v_rec.totd;
        vSoldVIC := v_rec.totvc - v_rec.totvd;
      ELSE
        IF v_rec.totd &gt; v_rec.totc
        THEN vSoldID  := v_rec.totd  - v_rec.totc;
        ELSE vSoldIC  := v_rec.totc  - v_rec.totd;
        END IF;

        IF v_rec.totvd &gt; v_rec.totvc
        THEN vSoldVID := v_rec.totvd - v_rec.totvc;
        ELSE vSoldVIC := v_rec.totvc - v_rec.totvd;
        END IF;
      END IF;

      IF vCount = 0 THEN
        INSERT INTO NCONTSOLDSUB ( CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC)
        VALUES ( SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, v_rec.CodContSold, pSub, vSoldID, vSoldIC, vSoldVID, vSoldVIC);
      ELSE
        UPDATE ncontsoldsub
        SET SOLDID  = vSoldID,
            SOLDIC  = vSoldIC,
            SOLDVID = vSoldVID,
            SOLDVIC = vSoldVIC
        WHERE CodContSoldSub = vRecId;
      END IF;

    END LOOP;
  END IF;

  COMMIT;
END;


PROCEDURE MAKE_STOC_LA_DATA(aDATA VARCHAR2) IS
  vAnTemp   NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  PKG_GLOBALS.DATACALCULSTOC := TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;);

  DELETE TMP_NIRLUNA;
  DELETE TMP_NIRSERLUNA;
  DELETE TMP_NIRURI_LUNA;
  DELETE TMP_LIVRARI_LUNA;

  INSERT INTO TMP_NIRURI_LUNA
  (CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM
  (
    SELECT * FROM V_STOC_LUNA_PREC
    UNION ALL
    SELECT * FROM V_NIRURI_LUNA_LA_DATA
  )
   GROUP BY CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_LUNA (CODNIRSTOC, REST, RESTUM1, RESTUM2) SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM
  V_LIVRARI_LUNA_LA_DATA GROUP BY CODNIRSTOC;

  FOR V_REC IN
  (SELECT N.CODNIRSTOC,
          N.REST,
          N.RESTUM1,
          N.RESTUM2,
          L.REST RESTL,
          L.RESTUM1 RESTL1,
          L.RESTUM2 RESTL2
   FROM
     TMP_NIRURI_LUNA N
     LEFT OUTER JOIN TMP_LIVRARI_LUNA L ON L.CODNIRSTOC = N.CODNIRSTOC
  )
  LOOP
    INSERT  INTO TMP_NIRLUNA(CODNIRSTOC,
                        AN,
                        LUNA,
                        REST,
                        RESTUM1,
                        RESTUM2)
    VALUES (V_REC.CODNIRSTOC,
            vAnTemp,
            vLunaTemp,
            NVL(V_REC.REST,    0) + NVL(V_REC.RESTL,  0),
            NVL(V_REC.RESTUM1, 0) + NVL(V_REC.RESTL1, 0),
            NVL(V_REC.RESTUM2, 0) + NVL(V_REC.RESTL2, 0)
            );
  END LOOP;

  FOR V_REC IN
  (SELECT * FROM TMP_LIVRARI_LUNA L WHERE NOT EXISTS (SELECT CODNIRSTOC FROM TMP_NIRURI_LUNA N WHERE N.CODNIRSTOC = L.CODNIRSTOC))
  LOOP
    INSERT  INTO TMP_NIRLUNA(CODNIRSTOC,
                        AN,
                        LUNA,
                        REST,
                        RESTUM1,
                        RESTUM2)
    VALUES (V_REC.CODNIRSTOC,
            vAnTemp,
            vLunaTemp,
            NVL(V_REC.REST,    0),
            NVL(V_REC.RESTUM1, 0),
            NVL(V_REC.RESTUM2, 0)
            );
  END LOOP;
/*

  INSERT INTO NIRLUNA(CODNIRSTOC, REST, RESTUM1, RESTUM2, AN, LUNA)
  (SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2, vAnTemp, vLunaTemp
  FROM V_STOCLUNA);
*/
  DELETE FROM TMP_NIRSERLUNA;
  DELETE TMP_NIRURI_SER_LUNA;
  DELETE TMP_LIVRARI_SER_LUNA;


  INSERT INTO TMP_NIRURI_SER_LUNA
  (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM
  (
    SELECT * FROM V_STOCSER_LUNA_PREC
    UNION ALL
    SELECT * FROM V_NIRURI_SER_LUNA_LADATA
  )
  GROUP BY CODNIRSER, CODNIRSTOC;

  INSERT INTO TMP_LIVRARI_SER_LUNA (CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2)
  SELECT CODNIRSER, CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1, SUM(RESTUM2) RESTUM2
  FROM
   V_LIVRARI_SER_LUNA_LADATA
  GROUP BY CODNIRSER, CODNIRSTOC;

  FOR V_REC IN
  (SELECT
          N.CODNIRSER,
          N.CODNIRSTOC,
          N.REST,
          N.RESTUM1,
          N.RESTUM2,
          L.REST RESTL,
          L.RESTUM1 RESTL1,
          L.RESTUM2 RESTL2
   FROM
     TMP_NIRURI_SER_LUNA N
     LEFT OUTER JOIN TMP_LIVRARI_SER_LUNA L ON L.CODNIRSER = N.CODNIRSER AND L.CODNIRSTOC = N.CODNIRSTOC
  )
  LOOP
    INSERT  INTO TMP_NIRSERLUNA
                      (
                        CODNIRSER,
                        CODNIRSTOC,
                        AN,
                        LUNA,
                        REST,
                        RESTUM1,
                        RESTUM2)
    VALUES (
            V_REC.CODNIRSER,
            V_REC.CODNIRSTOC,
            vAnTemp,
            vLunaTemp,
            NVL(V_REC.REST,    0) + NVL(V_REC.RESTL,  0),
            NVL(V_REC.RESTUM1, 0) + NVL(V_REC.RESTL1, 0),
            NVL(V_REC.RESTUM2, 0) + NVL(V_REC.RESTL2, 0)
            );
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_LIVRARI_SER_LUNA L WHERE NOT EXISTS (SELECT * FROM TMP_NIRURI_SER_LUNA N WHERE N.CODNIRSER = L.CODNIRSER AND N.CODNIRSTOC = L.CODNIRSTOC))
  LOOP
    INSERT  INTO TMP_NIRSERLUNA(
                        CODNIRSER,
                        CODNIRSTOC,
                        AN,
                        LUNA,
                        REST,
                        RESTUM1,
                        RESTUM2)
    VALUES (
            V_REC.CODNIRSER,
            V_REC.CODNIRSTOC,
            vAnTemp,
            vLunaTemp,
            NVL(V_REC.REST,    0),
            NVL(V_REC.RESTUM1, 0),
            NVL(V_REC.RESTUM2, 0)
            );
  END LOOP;
  COMMIT;
END;


PROCEDURE REFA_MIFIX(aCODMIFIX IN NUMBER)
IS
  NR           NUMERIC(10)    := 0;
  RATALUNA     NUMERIC(20, 7) := 0;
  RATALUNA_F   NUMERIC(20, 7) := 0;
  RATALUNA_G   NUMERIC(20, 7) := 0;

  STAREPREC    NUMERIC(20, 7) := 0;
  STARECURENTA NUMERIC(20, 7) := 0;
  DURATAFPREC  NUMERIC(20, 7) := 0;
  AMOPREC      NUMERIC(20, 7) := 0;
  aANINI       NUMERIC(10)    := 0;
  aLUNAINI     NUMERIC(10)    := 0;
  OLDSTARE     NUMERIC(10)    := 0;
  aCODCENTRU   NUMERIC(20)    := 0;

  DURATAFPREC_F  NUMERIC(20, 7) := 0;
  AMOPREC_F      NUMERIC(20, 7) := 0;

  DURATAFPREC_G  NUMERIC(20, 7) := 0;
  AMOPREC_G      NUMERIC(20, 7) := 0;
  aPRETAMOGRUP   NUMERIC(20, 7) := 0;

  ADATAREEVAL    DATE := NULL;
  APRETVECHI     NUMERIC(20, 7) := 0;
  AAMOVECHI      NUMERIC(20, 7) := 0;
  AREZERVAVECHE  NUMERIC(20, 7) := 0;
  APRETPREC      NUMERIC(20, 7) := 0;
  AAMOPREC       NUMERIC(20, 7) := 0;
  aUseRezerve    Number(1);
  vAnPrec        NUMBER(4) := PKG_GLOBALS.GetANPRECEDENT;
  vLunaPrec      NUMBER(2) := PKG_GLOBALS.GetLUNAPRECEDENTA;
  vAnTemp        NUMBER(4) := PKG_GLOBALS.GetANTEMP;
  vLunaTemp      NUMBER(2) := PKG_GLOBALS.GetLUNATEMP;
BEGIN
  -- PROPAG INREGISTRARI DIN LUNAPRECDEDENTA IN LUNA TEMP
  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO aANINI, aLUNAINI FROM FIRMALUNI;
    EXCEPTION WHEN OTHERS THEN aANINI := 0;
  END;

  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnPrec AND LUNASTART = vLunaPrec AND STARE IN (1, 2, 5) AND CODMIFIX = aCODMIFIX)
  LOOP
    SELECT COUNT(*) INTO NR FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    IF NR = 0 THEN
      INSERT INTO MIFIX1 (
        CODMIFIX1, CODMIFIX, CODNIRSTOC, PRET, CANT, CODCLASIF, TIPAMO, STARE, DURATAN, GRADU, DURATAF, AMO, NEUTIL, DFBLOCAT,
        CODPERS, CODNIRSER, ANSTART, LUNASTART, CODPART, CODLOCATIE, CODCENTRU, DURATANF, DURATANG, DURATAFF, DURATAFG, AMOF, AMOG, PRETINITIAL, REZERVA)
      VALUES (
        SEQ_MIFIX1_CODMIFIX1.NEXTVAL, V_REC.CODMIFIX, V_REC.CODNIRSTOC, V_REC.PRET, V_REC.CANT, V_REC.CODCLASIF, V_REC.TIPAMO, V_REC.STARE, V_REC.DURATAN, V_REC.GRADU, V_REC.DURATAF, V_REC.AMO, V_REC.NEUTIL, 0,
        V_REC.CODPERS,
        V_REC.CODNIRSER,
        vAnTemp,
        vLunaTemp,
        V_REC.CODPART,
        V_REC.CODLOCATIE,
        V_REC.CODCENTRU,
        V_REC.DURATANF,
        V_REC.DURATANG,
        V_REC.DURATAFF,
        V_REC.DURATAFG,
        V_REC.AMOF,
        V_REC.AMOG,
        V_REC.PRETINITIAL,
        NVL(V_REC.REZERVA, 0)
        );


    END IF;

/*
    IF V_REC.STARE = 2 THEN --trecut in conservare
      UPDATE MIFIX1
      SET
        AMO     = V_REC.AMO,
        DURATAF = V_REC.DURATAF
      WHERE
       CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
    END IF;
*/
  END LOOP;

-- VERIFICA DACA IN NOUA LUNA NU AM MIJLOACE FIXE CASATE SAU VANDUTE PENTRU A LE STERGE
  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnPrec AND LUNASTART = vLunaPrec AND STARE IN (3, 4, 6, 7, 8, 9, 10)AND CODMIFIX = aCODMIFIX)
  LOOP
    DELETE FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
  END LOOP;


 -- STERG DIN LUNA CURENTA POZITIILE VANDUTE SAU CASATE INTR_O LUNA MAI VECHE
 FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND CODMIFIX = aCODMIFIX)
 LOOP
   BEGIN
   SELECT STARE INTO OLDSTARE FROM MIFIX1 M1
   WHERE
     CODMIFIX = V_REC.CODMIFIX
     AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp
     AND ANSTART * 12 + LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART * 12 + LUNASTART &lt;  vAnTemp * 12 + vLunaTemp);
    EXCEPTION WHEN OTHERS THEN OLDSTARE := 0;
   END;
   IF OLDSTARE IN (3, 4, 6, 7, 8, 9, 10) THEN
     DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC.CODMIFIX1;
   END IF;
 END LOOP;


-- RECALCULEZ AMO, NEUTIL, DURATAF IN LUNA DE LUCRU;
  FOR V_REC IN (SELECT M1.*, M.ANINTRARE, M.LUNAINTRARE, M.ANINTRAREG, M.LUNAINTRAREG FROM MIFIX1 M1 LEFT OUTER JOIN MIFIX M ON M.CODMIFIX = M1.CODMIFIX
                WHERE
                M1.CODMIFIX = aCODMIFIX
                AND STARE IN (1 , 2) AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp
                AND DATAREEVAL IS NULL)
  LOOP

    RATALUNA    := AMORTIZARELUNARA   (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    RATALUNA_F  := AMORTIZARELUNARA_F (V_REC.CODMIFIX, vAnPrec, vLunaPrec);
    RATALUNA_G  := AMORTIZARELUNARA_G (V_REC.CODMIFIX, vAnPrec, vLunaPrec);

    BEGIN
      SELECT
        STARE,
        AMO,
        DURATAF,
        AMOF,
        DURATAFF,
        AMOG,
        DURATAFG
      INTO
        STAREPREC,
        AMOPREC,
        DURATAFPREC,
        AMOPREC_F,
        DURATAFPREC_F,
        AMOPREC_G,
        DURATAFPREC_G
      FROM
        MIFIX1
     WHERE
       CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN
      STAREPREC := 0;
      AMOPREC   := 0;
      AMOPREC_F := 0;
      AMOPREC_G := 0;
    END;


    IF RATALUNA &lt;&gt; 0 AND AMOPREC + RATALUNA &gt; V_REC.PRET * V_REC.CANT THEN
      RATALUNA := V_REC.PRET * V_REC.CANT - AMOPREC;
    END IF;


    IF RATALUNA_F &lt;&gt; 0 AND AMOPREC_F + RATALUNA_F &gt; V_REC.PRET * V_REC.CANT THEN
      RATALUNA_F := V_REC.PRET * V_REC.CANT - AMOPREC_F;
    END IF;


    IF NVL(V_REC.PRETINITIAL, 0) &lt;&gt; 0
      THEN aPRETAMOGRUP := V_REC.PRETINITIAL;
      ELSE aPRETAMOGRUP := V_REC.PRET;
    END IF;

    IF RATALUNA_G &lt;&gt; 0 AND AMOPREC_G + RATALUNA_G &gt; /*V_REC.PRET*/aPRETAMOGRUP * V_REC.CANT THEN
      RATALUNA_G := /*V_REC.PRET */ aPRETAMOGRUP * V_REC.CANT - AMOPREC_G;
    END IF;


    BEGIN
      SELECT STARE INTO STARECURENTA FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp;
      EXCEPTION WHEN OTHERS THEN STARECURENTA := 0;
    END;

    IF STAREPREC = 2 THEN
       UPDATE MIFIX1 M1
       SET
         AMO     = AMOPREC,
         AMOF    = AMOPREC_F,
         AMOG    = AMOPREC_F,
         DURATAF = ( CASE
                       WHEN DFBLOCAT = 1 THEN DURATAF
                                         ELSE DURATAFPREC
                     END
                   ),
         DURATAFF = ( CASE
                       WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                         ELSE DURATAFPREC_F
                     END
                   ),
         DURATAFG =( CASE
                       WHEN DFBLOCAT_G = 1 THEN DURATAFG
                                         ELSE DURATAFPREC_G
                     END
                   )
       WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    ELSE
       UPDATE MIFIX1 M1
         SET
           AMO     =  CASE
                          WHEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= PRET * CANT AND STARE = 1
                          THEN (SELECT NVL(AMO, 0) + RATALUNA /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMO
                      END,

           AMOF     =  CASE
                          WHEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= PRET * CANT AND STARE = 1
                          THEN (SELECT NVL(AMOF, 0) + RATALUNA_F /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOF
                       END,

           AMOG     =  CASE
                          WHEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec) &lt;= DECODE(NVL(PRETINITIAL, 0), 0, PRET, NVL(PRETINITIAL, 0))  /*PRET*/ * CANT AND STARE = 1
                          THEN (SELECT NVL(AMOG, 0) + RATALUNA_G /* * CANT */ FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                          ELSE AMOG
                       END

         WHERE
           CODMIFIX1 = V_REC.CODMIFIX1;

       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRARE * 12 + V_REC.LUNAINTRARE)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
             SET
               DURATAF = CASE WHEN DURATAF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT = 1 THEN DURATAF
                                ELSE (SELECT NVL(DURATAF, M1.DURATAF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END,


               DURATAFF = CASE WHEN DURATAFF &gt; 0 THEN
                          ( CASE
                             WHEN DFBLOCAT_F = 1 THEN DURATAFF
                                ELSE (SELECT NVL(DURATAFF, M1.DURATAFF) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       END IF;

--DURATAFG
       IF (V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; V_REC.ANINTRAREG * 12 + V_REC.LUNAINTRAREG)AND(V_REC.ANSTART * 12 + V_REC.LUNASTART &gt; aANINI * 12 + aLUNAINI)
       THEN
           UPDATE MIFIX1 M1
           SET
               DURATAFG = CASE WHEN DURATAFG &gt; 0 THEN
                          ( CASE
                              WHEN DFBLOCAT_G = 1 THEN DURATAFG
                              ELSE (SELECT NVL(DURATAFG, M1.DURATAFG) - 1 FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
                             END
                           )
                           ELSE 0
                         END
             WHERE
               CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       ELSE
           UPDATE MIFIX1 M1
           SET
             DURATAFG = (SELECT NVL(DURATAFG, M1.DURATAFG) FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec)
           WHERE
             CODMIFIX1 = V_REC.CODMIFIX1 AND STARE = 1;
       END IF;
  END IF;
  END LOOP;


  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE NVL(CODCENTRU, 0) = 0 AND ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND CODMIFIX = aCODMIFIX)
  LOOP
    BEGIN
    SELECT CODCENTRU INTO aCODCENTRU
    FROM
      MIFIX1
    WHERE
      CODMIFIX = V_REC.CODMIFIX AND ANSTART = vAnPrec AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN aCODCENTRU := 0;
    END;

    IF NVL(aCODCENTRU, 0) &lt;&gt; 0 THEN
      UPDATE MIFIX1
      SET
        CODCENTRU = aCODCENTRU
      WHERE
        CODMIFIX1 = V_REC.CODMIFIX1;
    END IF;
  END LOOP;


  SELECT NVL(pkg_categconst.GetValConstanta(&apos;UseRezervaReev&apos;, vAnTemp, vLunaTemp), &apos;0&apos;) INTO aUseRezerve from dual;

  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE ANSTART = vAnTemp AND LUNASTART = vLunaTemp AND CODMIFIX = aCODMIFIX)
  LOOP
     BEGIN
       SELECT DATAREEVAL, NVL(PRETVECHI,0),  NVL(AMOVECHI, 0), NVL(REZERVA, 0), NVL(PRET,0), NVL(AMO, 0) INTO ADATAREEVAL, APRETVECHI, AAMOVECHI, AREZERVAVECHE, APRETPREC, AAMOPREC
       FROM
         MIFIX1
       WHERE
         CODMIFIX      = V_REC.CODMIFIX
         AND ANSTART   = vAnPrec
         AND LUNASTART = vLunaPrec;
      EXCEPTION WHEN OTHERS THEN ADATAREEVAL := NULL; APRETVECHI := 0; AAMOVECHI := 0; AREZERVAVECHE := 0; APRETPREC := 0; AAMOPREC := 0;
     END;

     IF (NVL(aUseRezerve, 2)=1)and(aDATAREEVAL IS NOT NULL) THEN
       UPDATE MIFIX1
       SET
         REZERVA = NVL(AREZERVAVECHE, 0) + (APRETPREC  - AAMOPREC) - (APRETVECHI - AAMOVECHI)
       WHERE
         CODMIFIX1 = V_REC.CODMIFIX1;
     END IF;

  END LOOP;


  COMMIT;
END;


END PKG_INCHIDERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_INITSTOCSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1647E6406909CF762943C6A4AE2E6E8B3CAA4F5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_INITSTOCSOLD IS

  procedure GenStocIni
  is
  begin
    for rec_nir in (select distinct gest from nir) loop
      insert into StocIni (Codstocini, Codgest) values (SEQ_STOCINI_CODSTOCINI.Nextval, rec_nir.gest);
    end loop;
    commit;
  end;
  procedure GenSoldPartIni
  is
  begin
    for rec_oblig in (select distinct codpart from obligpif) loop
      insert into Soldini (Codsoldini,Codpart) values (SEQ_SOLDINI_CODSOLDINI.Nextval, rec_oblig.codpart);
    end loop;
    commit;
  end;

  procedure GenStocValIni
  is
  begin
    for rec_stocval in (select distinct gest from stocvalluna) loop
      insert into StocValIni (Codstocvalini, Gest) values (SEQ_STOCVALINI_CODSTOCVALINI.Nextval, rec_stocval.gest);
    end loop;
    commit;
  end;


end pkg_InitStocSold; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_INTERFATAKLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>204F2C29056471D5482F4F3F6E43C0AEC49B5CA5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_INTERFATAKLG is


PROCEDURE POSTINFOMESAJ
IS
BEGIN
  INSERT INTO INTERFATAKLG (COD, 
                            TIPMESAJ, 
                            DATA,
                            NUMEFISIER,
                            XML,
                            IDMESAJ 
                           )
  SELECT 
    SEQ_INTERFATAKLG_COD.NEXTVAL,                           
    TIPMESAJ,
    SYSDATE,
    NUMEFISIER,
    XML,
    IDMESAJ
  FROM  
    TMP_INTERFATAKLG;
    
  COMMIT;  
END;

end PKG_INTERFATAKLG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>747591CD423CC748F7F251CD3153B7289AA93BB8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_INTRARI IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_11&apos;;


function GETSERIILOTCONSUM(aCodCmdProdMat in number) return varchar2 is
aLotPropriu varchar2(5000);
begin
  pkg_globals.SetSeparator(&apos;;&apos;);
  begin
  select stragg3200(serielot) into aLotPropriu
  from
    (
     select distinct ns.serielot
     from cmdprodmat prod
          inner join iesiri1 i1 on i1.codcmdint1 = prod.codcomanda1
          inner join iesiri i on i.codies = i1.codies
          inner join livr l on l.codies = i.codies
          inner join livr1 l1 on l1.codlivr = l.codlivr and i1.codies1 = l1.codies1
          inner join nirstoc ns on ns.codnirstoc = l1.codnirstoc
     where prod.codcmdprodmat = aCodCmdProdMat
    );
  exception when others then aLotPropriu := &apos;&apos;;
  end;
  if Length(aLotPropriu) &gt; 100 then
    aLotPropriu := substr(aLotPropriu,100);
  end if;
  return aLotPropriu;
end;

PROCEDURE MAKE_NIRSTOC_LA_DATA(aDATA IN VARCHAR2)
IS
BEGIN
  DELETE TMP_NIRSTOC_LA_DATA;
  INSERT INTO TMP_NIRSTOC_LA_DATA (CODNIRSTOC, CANTNIR)
  SELECT
    CODNIRSTOC,
    SUM(CANTNIR) AS CANTNIR
  FROM
   (
   SELECT
    NS.CODNIRSTOC,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) MAN,
     NIRSTOC NS,
     NIR N
  WHERE
     NS.CODNIRSTOC = MAN.CODUNIC
     AND NS.CODNIR = N.CODNIR
   )
   WHERE
     NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aDATA, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODNIRSTOC;

   DELETE TMP_LIVRNIRSTOC_LA_DATA;
   INSERT INTO TMP_LIVRNIRSTOC_LA_DATA(CODNIRSTOC, CANTNIR)
   SELECT
     CODNIRSTOC,
     SUM(CANT) AS CANT
   FROM
   (
   SELECT
     NS.CODNIRSTOC,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END
      CANT,
      L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA)  MAN
   WHERE
     MAN.CODUNIC = L1.CODNIRSTOC
     AND L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
   )
   WHERE
    NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODNIRSTOC;

   MERGE INTO TMP_NIRSTOC_LA_DATA N
   USING TMP_LIVRNIRSTOC_LA_DATA L
   ON ( N.CODNIRSTOC = L.CODNIRSTOC)
   WHEN MATCHED THEN UPDATE SET N.CANTNIR = N.CANTNIR - L.CANTNIR;


  -- COMMIT;

END;



FUNCTION INTRAREPLUSMINUS(aCODINTR IN NUMBER, VALOBLIG IN NUMBER) RETURN NUMBER
IS
   NRPLUS   NUMBER(10) := 0;
   NRMINUS  NUMBER(10) := 0;
   aVALOARE NUMBER(20, 7);

BEGIN
  BEGIN
    SELECT ROUND(VALDOC, 2) INTO aVALOARE FROM INTRARI WHERE CODINTR = aCODINTR;
    EXCEPTION WHEN OTHERS THEN aVALOARE := 0;
  END;
  SELECT COUNT(*) INTO NRPLUS FROM GENERAL G, OBLIGPIF O
  WHERE
     G.SEMNIFICATIE = 100
     AND G.CODDOC = aCODINTR
     AND G.CODGENERAL = O.CODGENERAL
     AND O.VALOARE &gt; 0;


  SELECT COUNT(*) INTO NRMINUS FROM GENERAL G, OBLIGPIF O
  WHERE
     G.SEMNIFICATIE = 100
     AND G.CODDOC = aCODINTR
     AND G.CODGENERAL = O.CODGENERAL
     AND O.VALOARE &lt; 0;

  IF NRPLUS &gt; 0 AND NRMINUS &gt; 0 AND VALOBLIG &gt; aVALOARE THEN RETURN 1; ELSE RETURN 0; END IF;
END;


PROCEDURE Actualizeaza_CodContract1 IS
  vDataDoc   DATE;
  vCodContr  NUMBER(20);
  vDataStart DATE;
  vDataStop  DATE;
  vTipContract number(10);
BEGIN
  SELECT c.codcontract, c.datastart, c.datastop, i.datadoc, c.tipcontract
  INTO   vCodContr,     vDataStart,  vDataStop,  vDataDoc, vTipContract
  FROM tmp_intrari i LEFT JOIN contract c ON c.codcontract = i.codcontract;

  if vTipContract = 3 then return; end if;

  IF vCodContr IS NOT NULL THEN
    UPDATE tmp_intrari1 i1
    SET i1.codcontract1 =
        (
          SELECT Max(C1.CodContract1) KEEP (Dense_Rank Last ORDER BY Nvl(C1.DataStart,vDataStart))
          FROM Contract1 C1
          WHERE C1.CodContract = vCodContr
            AND c1.codobiect = i1.codobiect
            AND Nvl(C1.DataStart,vDataStart) &lt;= vDataDoc
            AND Nvl(C1.DataStop,vDataStop) &gt;= vDataDoc
        )
    WHERE Nvl(i1.codcontract1,0) = 0 AND I1.tiplinie IN (&apos;=&apos;,&apos;S&apos;);
  END IF;
EXCEPTION
  WHEN OTHERS THEN NULL;
END;


PROCEDURE DIMINUEAZA_REZERVARI(aCODNIRSTOC IN NUMBER, aCODNIRSER  IN NUMBER, CANT_IN_STOC IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTREZINI   NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTREZINI := CANT_IN_STOC;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
         CODNIRSTOC = aCODNIRSTOC
     AND CODNIRSER  = aCODNIRSER
   )
   LOOP
     IF (V_REC.REST &gt; 0) THEN

       IF CANTREZINI &gt; 0 THEN
         IF CANTREZINI &lt;= V_REC.REST THEN
           CANTREZ := CANTREZINI;
         ELSE
           CANTREZ := V_REC.REST;
         END IF;

         UPDATE REZERVATS
         SET
           REST  = CANTREZ
         WHERE CODREZERVATS = V_REC.CODREZERVATS;
       ELSE
         DELETE FROM REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;
       CANTREZINI := CANTREZINI - CANTREZ;
     END IF;
   END LOOP;
END;


PROCEDURE SOLVE_OBINV(aCODINTR IN NUMBER, aCODCLASIF IN NUMBER )
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
  aTipAmo  NUMBER := 1;
BEGIN
  CODCLASIF_MASTER := aCODCLASIF;

  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipAmoOI&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipAmo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aTIPAMO := 1;
  END;

  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       PRET,
       REST
      FROM
        NIRSTOC NS,
        NIR N,
        TMP_IOART_LUNA IOLUNA
      WHERE
        N.CODINTR = aCODINTR
        AND NS.CODNIR = N.CODNIR
        AND IOLUNA.CODIOART = NS.CODIOART
        AND IOLUNA.ESTEOBINV &gt; 0
     )
   LOOP
     SELECT NVL(SUM(CANT), 0) INTO REZOLVAT
     FROM
       MIFIX1 MF
     WHERE
       MF.CODNIRSTOC = V_REC.CODNIRSTOC
       AND MF.ANSTART * 12 + MF.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


     IF REZOLVAT &lt; V_REC.REST THEN
       BEGIN
         SELECT NVL(CODCLASIF, 0) INTO CODCLASIF_MASTER FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN CODCLASIF_MASTER := 0;
       END;

       IF CODCLASIF_MASTER = 0 THEN CODCLASIF_MASTER := aCODCLASIF;
       END IF;

       BEGIN
         SELECT DURATA INTO aDURATAN FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
       END;


       IF aDURATAN &gt; 0 THEN

         SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         IF NR = 0 THEN
           INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN)
           VALUES (V_REC.CODNIRSTOC, CODCLASIF_MASTER, aDURATAN);
         END IF;

         SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

         INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE )
         VALUES (aCODMIFIX, &apos;OI&apos;, PKG_MIFIX.GetNextNrInv(&apos;OI&apos;), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

         INSERT INTO MIFIX1(CODMIFIX1,
                            CODMIFIX,
                            CODNIRSTOC,
                            PRET,
                            CANT,
                            CODCLASIF,
                            TIPAMO,
                            STARE,
                            DURATAN,
                            GRADU,
                            DURATAF,
                            AMO,
                            DFBLOCAT,
                            ANSTART,
                            LUNASTART,
                            DFBLOCAT_F,
                            DFBLOCAT_G)
         VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
                aCODMIFIX,
                V_REC.CODNIRSTOC,
                V_REC.PRET,
                V_REC.REST - REZOLVAT,
                CODCLASIF_MASTER,
                aTIPAMO,
                1,
                aDURATAN,
                100,
                0,
                (V_REC.REST - REZOLVAT) * V_REC.PRET,
                1,
                PKG_GLOBALS.ANLUCRU,
                PKG_GLOBALS.LUNALUCRU,
                1,
                1);

       END IF;
     END IF;


   END LOOP;
   COMMIT;

END;

PROCEDURE Service_Preluat IS
aNR  number;
begin
  update Intrari1 set PRELUAT = 0;

  update Intrari set TipFactura = 0 where TipFactura = 8;
  for v_rec in
    ( select distinct I.CodIntr
      from CANTAR C
           inner join intrari1 I1 on I1.CodIntr1 = C.CodDoc1
           inner join intrari I on I.CodIntr = I1.CodIntr and I.TipDoc = C.TipDoc
    ) loop
    update Intrari set TipFactura = 8 where CodIntr = v_Rec.CodIntr;
	end loop;
  for v_rec in
    ( select i1.CodIntr1 CodDoc1, I.TipDoc
      from Intrari1 i1
           inner join intrari I on I.CodIntr = I1.CodIntr
           where I.TipFactura = 8
    ) loop
    select Count(*) into aNR from CANTAR where TipDoc = v_rec.TipDoc and CodDoc1 = v_Rec.CodDoc1;
    if aNr &gt; 0  then
      update Intrari1 set PRELUAT = 1 where CodIntr1 = v_Rec.CodDoc1;
		end if;
	end loop;

  update Intrari set TipFactura = 0 where TipFactura = 11;
  for v_rec in
    ( select distinct I.CodIntr
      from BCAR B
           inner join intrari1 I1 on I1.CodIntr1 = B.CodDoc1
           inner join intrari I on I.CodIntr = I1.CodIntr and I.TipDoc = B.TipDoc
    ) loop
    update Intrari set TipFactura = 11 where CodIntr = v_Rec.CodIntr;
	end loop;

  for v_rec in
    ( select i1.CodIntr1 CodDoc1, I.TipDoc
      from Intrari1 i1
           inner join intrari I on I.CodIntr = I1.CodIntr
           where I.TipFactura = 11
    ) loop
    select Count(*) into aNR from BCAR where TipDoc = v_rec.TipDoc and CodDoc1 = v_Rec.CodDoc1;
    if aNr &gt; 0  then
      update Intrari1 set PRELUAT = 2 where CodIntr1 = v_Rec.CodDoc1;
		end if;
  end loop;

	commit;
end;

PROCEDURE EMPTY_INTRARI_TEMPTABLES
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_INTRARI1;
  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;
  DELETE TMP_NIRSTOC_INITIAL;
  DELETE TMP_NIRSTOC1;
  DELETE TMP_LIVR;
  DELETE TMP_LIVRVAL;
  DELETE TMP_LIVRTOT;
  DELETE TMP_LIVR1;
  DELETE TMP_LIVR1_INITIAL;
  DELETE TMP_INTRLINK;
  DELETE TMP_INTRLINK_INITIAL;
  DELETE TMP_GENERAL;
  DELETE TMP_OBLIGPIF;
  DELETE TMP_NIRSER;
  DELETE TMP_IOPARTDOC;
  DELETE TMP_JURNAL1;
  DELETE TMP_JURNAL;
  DELETE TMP_RULAJ;
  DELETE TMP_STINGERE;
  DELETE TMP_STINGERE_INITIAL;
  DELETE TMP_OBLIGPIF_INITIAL;
  DELETE TMP_INTRPRODLINK;
  DELETE TMP_INTRPRODLINK_INITIAL;
  DELETE INTRARI1_MAN;
  DELETE TMP_FISAMAS;
  DELETE TMP_FISAMAS1;
  DELETE TMP_INTRASTEPTLINK;
  DELETE TMP_INTRASTEPTLINK_INITIAL;
  DELETE TMP_DVI;
  DELETE TMP_INTRDOCTRANSP;
  DELETE TMP_DEZASAMBLARI;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRPF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRPF&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTR1PF&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRSUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRSUB&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTR1SUB&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIP&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIP1&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIF&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIF1&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRFAST&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTR1FAST&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIAE&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIAE1&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIFA&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARIFA1&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRFAST&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTR1FAST&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRAST&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTR1AST&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARICF&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete TMP_INTRARICF1&apos;;
  END IF;

  -- tmp ini
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRPF_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRPF_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTR1PF_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRSUB_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRSUB_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTR1SUB_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIP_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIP1_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIF_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIF1_INI&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRFAST_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTR1FAST_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIAE_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIAE1_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIFA_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARIFA1_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRFAST_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTR1FAST_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRAST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRAST_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTR1AST_INI&apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARICF_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_INTRARICF1_INI&apos;;
  END IF;



  commit;
END;


FUNCTION ZECIMALEPRET(aZEC IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aZEC &gt;= 0 THEN RETURN aZEC;
  ELSE
  RETURN 7;
  END IF;
END;

FUNCTION GETLASTPRET_NOTAPREDARE(aCodObiect IN NUMBER) RETURN NUMBER
IS
 PRETNP NUMBER(20, 7) := 0;
BEGIN

  FOR V_REC IN
  (
      SELECT I1.PU
      FROM
        INTRARI1 I1,
        INTRARI I
      WHERE
        I1.CODINTR        = I.CODINTR
        AND I.TIPDOC      = 7
        AND I1.CODOBIECT  = aCODOBIECT
      ORDER BY I.DATADOC DESC
  )
   LOOP
     RETURN V_REC.PU;
   END LOOP;

 RETURN PRETNP;
END;

PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RecId OUT NUMBER ) IS
  vCod    NUMBER(20);
  TIPINTR INTEGER := 0;
  NR      INTEGER := 0;
  aOperat INTEGER := 0;
  aAnuLat INTEGER := 0;


OLDCARNETNIR  NUMBER(20) := 0;
OLDNRNIR      NUMBER(20) := 0;

OLDCARNETLIVR NUMBER(20) := 0;
OLDNRLIVR     NUMBER(20) := 0;

aCARNET       NUMBER(20) := 0;
aNUMARDOC     NUMBER(20) := 0;

aCODSERIE     NUMBER(20) := 0;
aCODPART      NUMBER(20) := 0;
aCODGESTPROD  NUMBER(20) := 0;
aSUBUNITATEA  NUMBER(20) := 0;
NOMSERIE     VARCHAR2(75);
aCODCOMANDA1  NUMBER(20) := 0;
aEXCLUSPLATA  NUMBER(1)  := 0;

--aCODNIR NUMBER(20) := 0;

BEGIN
  Actualizeaza_CodContract1;
  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  SELECT TIPDOC,  OPERAT, ANULAT,   CARNETDOC, NRDOC,     PARTENER, CODGESTPROD,  SUBUNITATEA,  Coalesce(EXCLUSPLATA, 0)
  INTO   TIPINTR, aOperat, aAnulat, aCARNET,   aNUMARDOC, aCODPART, aCODGESTPROD, aSUBUNITATEA, aEXCLUSPLATA
  FROM TMP_INTRARI;

-- Master INTRARI
  SELECT seq_INTRARI_CodIntr.NextVal INTO RecId FROM DUAL;

  INSERT INTO  INTRARI
            (CodIntr, TipDoc, Anulat, Blocat, Operat, PrefixDoc,
             NrDoc, DataDoc, RotEFact, Partener, NrAviz, CarnetDoc,
             ValDoc, TVADoc, Majorari, An, Luna, Obs, Satelit, Complex, CODSUBUNIT,
             CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM,
             CODLOCATIE, TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA,
             TIPTVA, MONEDA, CURS,USERID,DATACREARE, IDIMPORT, DELEGAT, MIJLTRANSP,
             NRTRANSP, ProRata,CODCONTRACT,  CODAUTO, ExclusPlata, FaraReg, TVAINCASARE,
             TVAINCASARE_F, CodAnaliza, TipET, iddescarcare)

 ( SELECT RecId,  TipDoc, Anulat, Blocat, Operat, PrefixDoc,
               NrDoc, DataDoc, RotEFact, Partener, NrAviz, CarnetDoc,
               ValDoc, TVADoc, Majorari, An, Luna, Obs, Satelit, Complex, CODSUBUNIT,
               CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM,
               CODLOCATIE, TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA,
               TIPTVA, MONEDA, CURS,PKG_GLOBALS.USERID,systimestamp, IDIMPORT, DELEGAT, MIJLTRANSP,
               NRTRANSP, ProRata, CODCONTRACT, CODAUTO, ExclusPlata, FaraReg, TVAINCASARE,
               TVAINCASARE_F, CodAnaliza, TipET, iddescarcare
   FROM TMP_INTRARI) ;

-- detail GENERAL
   UPDATE TMP_GENERAL
   SET
     EXCLUSPLATA = aEXCLUSPLATA;


   FOR v_rec IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;
     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS,  PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg)
     VALUES (VCOD, TIPINTR, RecID, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS,  v_rec.PROCTVAAVANS, v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA, v_rec.FaraReg);
   END LOOP;

-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     IF V_REC.CODOBLIGPIF &lt; 0
       THEN SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
       ELSE VCOD := V_REC.CODOBLIGPIF;
     END IF;

     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
     UPDATE TMP_INTRARI1 SET CODOBLIGSTORNO  = vCOD WHERE CODOBLIGSTORNO  = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT,CODANALIZANOD)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 111 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA, V_REC.CODCENTRU, V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0),
    V_REC.CODANALIZANOD );
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;



-- Detail INTRARI1
  FOR v_rec IN ( SELECT * FROM TMP_INTRARI1 ORDER BY IndexLocal ) LOOP

    SELECT seq_INTRARI1_CodIntr1.Nextval INTO vCOD FROM DUAL;
    update tmp_jurnal1 set indexlocal = vcod where indexlocal = v_rec.codintr1;

    INSERT INTO INTRARI1 (
      CodIntr1, CodIntr, IndexLocal,TipLinie,Umsec,An,Luna,ContServ, CONTDISCOUNT,
      ZILE, ZILECMD, GestAct, CodObiect,
      PretOrig, PU, Cant, TVA, AdDim,
      MIFIX, CODOBIECTORIG, CODAUTO, PARITATEORIG, COEFDISCMAJ, OBS,
      RestFact,NrCertif,CODCMD1AE, TG,PUMaximal, AdMax,PURidicata, PROCADAOS,
      FURNAVIZSUBUNIT, GESTPRODAVIZSUB, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, CodOferta1, CODCMDINT1, codcontract1, Taxa, ROTVALTAXA)
    VALUES
     ( vCod, RecId, v_Rec.IndexLocal,  v_Rec.TipLinie,  v_Rec.Umsec,  v_Rec.An,  v_Rec.Luna,  v_Rec.ContServ, V_REC.CONTDISCOUNT,
       V_REC.ZILE, V_REC.ZILECMD, v_Rec.GestAct,  v_Rec.CodObiect,
       v_Rec.PretOrig / NVL(v_Rec.Paritate, 1), v_Rec.PU / NVL(v_Rec.Paritate, 1),  v_Rec.Cant * NVL(v_Rec.Paritate, 1), v_Rec.TVA, v_rec.AdDim,
       V_REC.MIFIX,  V_REC.CODOBIECTORIG, V_REC.CODAUTO, V_REC.PARITATEORIG, V_REC.COEFDISCMAJ, V_REC.OBS,
       CASE
         WHEN TIPINTR = 2 AND v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND aOperat = 1 AND aAnulat = 0 THEN v_Rec.Cant * v_Rec.Paritate
         WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
         ELSE 0
       END,
       v_Rec.NrCertif,  V_REC.CODCMD1AE, v_Rec.TG,  v_Rec.PUMaximal, v_Rec.AdMax, v_Rec.PURidicata, V_REC.PROCADAOS, V_REC.FURNAVIZSUBUNIT, V_REC.GESTPRODAVIZSUB,
       V_REC.DATAACHIZAVIZSUBUNIT, V_REC.CODOBLIGSTORNO, V_REC.CURSFACTURAAVANS, V_REC.CodOferta1, V_REC.CODCMDINT1, V_REC.codcontract1, V_REC.Taxa, V_REC.ROTVALTAXA
     );

    UPDATE TMP_NIRSTOC  SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_LIVR1    SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CodIntr1;
    UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;

  END LOOP;


  INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);

-- Detail NIR
  FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP
    SELECT seq_NIR_CodNIR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO NIR (CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest, v_rec.Obs, v_rec.TipNIR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_NIRSTOC SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
  END LOOP;


-- Detail NIRSTOC
  FOR V_REC IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CodNIRSTOC ) LOOP
    IF V_REC.CODNIRSTOC &lt; 0
      THEN SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCod from DUAL;
      ELSE VCOD := V_REC.CODNIRSTOC;
    END IF;

    INSERT INTO  NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CantNir, CANTFURN, UmSec,  CodObiect, CodIoArt, Pret,
		 RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, RESTUM1, RESTUM2, ProcentAdaos, Supliment, SuplNeded, TG,
		 PUMaximal, AdMax, FURN, CODGESTPROD, SUBUNITATEA, DATAACHIZ, TIPDOCACHIZ,PUVAL)
    VALUES
    (vCod, v_Rec.CodNir, v_Rec.CodIntr1, v_Rec.CantNir * v_Rec.Paritate,  v_Rec.CantFURN * v_Rec.Paritate,  v_Rec.Umsec, v_Rec.CodObiect, nvl(v_Rec.CodIoArt, 0), v_Rec.Pret / v_Rec.Paritate, v_Rec.RotLei, v_Rec.RotValuta, V_REC.CODLOCATIE, V_REC.CANTUM1, V_REC.CANTUM2, v_Rec.Adaos, v_Rec.TVA, v_Rec.TipSerie, v_Rec.CodLivr1,
    GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
    GET_REST_STOC_UM1(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM1),
    GET_REST_STOC_UM2(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM2),
    v_Rec.ProcentAdaos, v_rec.Supliment, v_rec.SuplNeded,
    (SELECT TG FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT PUMaximal FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT AdMax FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
     CASE
       WHEN TIPINTR = 6 THEN (SELECT FURNAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       WHEN TIPINTR IN (1, 2, 3, 4, 5) THEN aCODPART
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 7 THEN aCODGESTPROD
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 6 THEN aSUBUNITATEA
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 6 THEN (SELECT DATAACHIZAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       ELSE (SELECT DATANIR FROM NIR WHERE CODNIR = V_REC.CODNIR)
     END,
     TIPINTR,V_REC.PUVAL

     );

    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    select nvl(i1.codcmdint1,0) into aCodComanda1
    from intrari1 i1
    where i1.codintr1 = v_Rec.Codintr1;

    /*INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
    VALUES (vCod, pkg_list_base_utils.GETCODNIRSTOC_ORIG(vCod), TIPINTR, v_Rec.Pret / v_Rec.Paritate - v_Rec.Adaos,
            case when TIPINTR = 7 then 1 else 0 end, case when TIPINTR = 7 then 0 else 1 end, aCodComanda1);
    if tipintr = 7 then
      update nirstoc1 set dirty = 1 where codcomanda1 = aCodComanda1;
    end if;*/
  END LOOP;


-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;


    IF V_REC.CODNIRSER &lt; 0 THEN  SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;
    ELSE
    VCOD := V_REC.CODNIRSER;
    END IF;
    INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST,
                                               CANTUM1, CANTUM2, RESTUM1, RESTUM2, OBS, CodCertif, DataProd, TG, Stare, DataProd1, TG1) VALUES
    (VCOD, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CANTUM1, V_REC.CANTUM2,
                                                V_REC.OBS, V_REC.CodCertif, v_rec.DataProd, V_REC.TG,  v_rec.Stare,  v_rec.DataProd1,  v_rec.TG1);

  END LOOP;


-- LIVR
  FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP
    SELECT seq_LIVR_CodLIVR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO LIVR (CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLIVR, Obs, TipLIVR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR, v_rec.DataLivr, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_LIVR1 SET CODLIVR = vCod WHERE CODLIVR = v_rec.CODLIVR;
  END LOOP;

-- LIVR1
   INSERT INTO LIVR1
   (CodLivr1, CodLivr, CodIes1, CodIntr1, CodNirStoc, Cant, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC,  UmSec)
   (SELECT  seq_LIVR1_CodLivr1.Nextval, CodLivr, CodIes1, CodIntr1, CodNirStoc,  Cant * Paritate, CodNirSer, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UmSec from TMP_LIVR1);


-- actualizez stocurile din care livrez

   UPDATE NIRSTOC NS
   SET
     REST    = GET_REST_STOC(NS.CodNir, NS.CodNirStoc, NS.CantNIR),
     RESTUM1 = GET_REST_STOC_UM1(NS.CodNir, NS.CodNirStoc, NS.CantUM1),
     RESTUM2 = GET_REST_STOC_UM2(NS.CodNir, NS.CodNirStoc, NS.CantUM2)
   WHERE
     NS.CodNirStoc in (SELECT CodNirStoc FROM TMP_LIVR1);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
   NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1);



  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODANALIZANOD FROM TMP_JURNAL1);



 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODANALIZANOD FROM TMP_JURNAL);


-- SUNT PE FACTURA LA AVIZ ; ACTUALIZEZ RESTUL PE AVIZELE STINSE
IF TIPINTR = 9 THEN
  UPDATE INTRARI1 I1
  SET
   I1.RestFact = i1.Cant -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEAVIZ = I1.CodINTR1 AND II.TIPDOC = 9  AND II.OPERAT = 1 AND II.ANULAT = 0
                 )
  WHERE
  I1.CodINTR1 IN
  (SELECT CODLINIEAVIZ FROM TMP_INTRLINK UNION SELECT CODLINIEAVIZ FROM TMP_INTRLINK_INITIAL);

ELSE -- ACTUALIZEZ RESTULACCEPTAT DE PE COMENZI FURNIZORI
  IF TIPINTR IN (1, 2) THEN
    UPDATE COMANDA1 c1
    SET
     c1.RestAcceptat = c1.CantAcceptat -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
    c1.CodComanda1 IN (SELECT CODLINIECOMANDA FROM TMP_INTRLINK UNION SELECT CODLINIECOMANDA  FROM TMP_INTRLINK_INITIAL);
  END IF;
END IF;



-- actualizare CARNETE DOCUMENTE
IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(aCARNET &lt;&gt; CARNETDOC_I OR aNUMARDOC &lt;&gt; NRDOC_I)
THEN
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
END IF;

IF TIPINTR IN (7) THEN
  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNUMARDOC);
END IF;

FOR V_REC IN (SELECT * FROM LIVR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;


FOR V_REC IN (SELECT * FROM NIR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
END LOOP;


-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
  UPDATE OBLIGPIF O
  SET
   REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE

     UNION ALL

     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );


COMMIT;
END;


FUNCTION DOCUMENTE_CU_NUMARUL(aCODDOC IN NUMBER, aSERIEDOC IN VARCHAR2, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  IF aTIPDOC IN (1, 9) THEN
    BEGIN
      SELECT COUNT(*) INTO NR FROM INTRARI WHERE CODINTR &lt;&gt; aCODDOC AND UPPER(NVL(SERIADOC, &apos;?&apos;)) = UPPER(aSERIEDOC) AND NRDOC = aNUMARDOC AND NVL(PARTENER, 0) = aCODPART AND TIPDOC IN (1, 9);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  ELSE
    BEGIN
      SELECT COUNT(*) INTO NR FROM INTRARI WHERE CODINTR &lt;&gt; aCODDOC AND UPPER(NVL(SERIADOC, &apos;?&apos;)) = UPPER(aSERIEDOC) AND NRDOC = aNUMARDOC AND NVL(PARTENER, 0) = aCODPART AND TIPDOC = aTIPDOC;
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  END IF;
  RETURN NR;
END;


FUNCTION DOCUMENTE_CU_NUMARUL_DATA(aCODDOC IN NUMBER, aSERIEDOC IN VARCHAR2, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER, aDATADOC IN VARCHAR2) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  IF aTIPDOC IN (1, 9) THEN
    BEGIN
      SELECT COUNT(*) INTO NR
      FROM
        INTRARI
      WHERE
        CODINTR &lt;&gt; aCODDOC
        AND UPPER(NVL(SERIADOC, &apos;?&apos;)) = UPPER(aSERIEDOC)
        AND NRDOC = aNUMARDOC
        AND NVL(PARTENER, 0) = aCODPART
        AND TIPDOC IN (1, 9)
        AND DATADOC = TO_DATE(aDATADOC, &apos;DD.MM.YYYY&apos;);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  ELSE
    BEGIN
      SELECT COUNT(*) INTO NR
      FROM
        INTRARI
      WHERE
        CODINTR &lt;&gt; aCODDOC
        AND UPPER(NVL(SERIADOC, &apos;?&apos;)) = UPPER(aSERIEDOC)
        AND NRDOC = aNUMARDOC
        AND NVL(PARTENER, 0) = aCODPART
        AND TIPDOC = aTIPDOC
        AND DATADOC = TO_DATE(aDATADOC, &apos;DD.MM.YYYY&apos;);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  END IF;
  RETURN NR;
END;


FUNCTION DOCUMENTE_CU_NUMARUL_EXT(aCODDOC IN NUMBER, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  IF aTIPDOC IN (1, 9) THEN
    BEGIN
      SELECT COUNT(*) INTO NR FROM INTRARI WHERE CODINTR &lt;&gt; aCODDOC AND NRDOC = aNUMARDOC AND NVL(PARTENER, 0) = aCODPART AND TIPDOC IN (1, 9);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  ELSE
    BEGIN
      SELECT COUNT(*) INTO NR FROM INTRARI WHERE CODINTR &lt;&gt; aCODDOC AND NRDOC = aNUMARDOC AND NVL(PARTENER, 0) = aCODPART AND TIPDOC = aTIPDOC;
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  END IF;
  RETURN NR;
END;



FUNCTION DOCUMENTE_CU_NUMARUL_DATA_EXT(aCODDOC IN NUMBER, aNUMARDOC IN NUMBER, aCODPART IN NUMBER, aTIPDOC IN NUMBER, aDATADOC IN VARCHAR2) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  IF aTIPDOC IN (1, 9) THEN
    BEGIN
      SELECT COUNT(*) INTO NR
      FROM
        INTRARI
      WHERE
        CODINTR     &lt;&gt; aCODDOC
        AND NRDOC    = aNUMARDOC
        AND NVL(PARTENER, 0) = aCODPART
        AND TIPDOC IN (1, 9)
        AND DATADOC  = TO_DATE(aDATADOC, &apos;DD.MM.YYYY&apos;);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  ELSE
    BEGIN
      SELECT COUNT(*) INTO NR
      FROM
        INTRARI
      WHERE
        CODINTR     &lt;&gt; aCODDOC
        AND NRDOC    = aNUMARDOC
        AND NVL(PARTENER, 0) = aCODPART
        AND TIPDOC   = aTIPDOC
        AND DATADOC  = TO_DATE(aDATADOC, &apos;DD.MM.YYYY&apos;);
      EXCEPTION WHEN OTHERS THEN RETURN 0;
    END;
  END IF;
  RETURN NR;
END;



PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := aCARNET;
  NRDOC_I     := aNRDOC;
END;


FUNCTION NR_AVIZE_SUB_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  IF aCodNirStoc &gt; 0  THEN
    BEGIN
      SELECT NVL(COUNT(*), 0) INTO NR
      FROM
      LIVR1 l1, LIVR L
      WHERE
        l.CODLIVR = l1.CODLIVR AND
        l.Tiplivr = 23 AND
        l.OPERAT  = 1 AND
        l.ANULAT  = 0 AND
        l1.CODNIRSTOC = aCodNirStoc;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;
  RETURN NR;
END;

FUNCTION NR_LIVRARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  IF aCodNirStoc &gt; 0  THEN
    BEGIN
      SELECT NVL(COUNT(*), 0) INTO NR
      FROM
      LIVR1 l1, LIVR L
      WHERE
        l.CODLIVR = l1.CODLIVR AND
        l.OPERAT  = 1 AND
        l.ANULAT  = 0 AND
        l1.CODNIRSTOC = aCodNirStoc;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;
  RETURN NR;
END;


FUNCTION NR_REZERVARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  IF aCodNirStoc &gt; 0  THEN
    BEGIN
      SELECT NVL(COUNT(*), 0) INTO NR
      FROM
       REZERVATS
      WHERE
       CODNIRSTOC = aCODNIRSTOC;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;
  RETURN NR;
END;


FUNCTION TOTAL_VALOARE_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT VALOARE INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;
FUNCTION TOTAL_VALOARE_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 TOTAL NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(VALOARE) INTO TOTAL FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF;
    EXCEPTION WHEN OTHERS THEN TOTAL := 0;
  END;
  RETURN TOTAL;
END;


FUNCTION TOTAL_COUNT_ICONT(aICONT IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;

FUNCTION TOTAL_COUNT_SEMNIF(aSEMNIF IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CODOBLIGPIF INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE = aSEMNIF; 
    --SELECT COUNT(*) INTO NR FROM TMP_OBLIGPIF_INITIAL WHERE ICONT = aICONT AND NVL(CURS, 0) = NVL(aCURS, 0); 
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  IF NR = 0 THEN
    NR := 1;
  END IF;
  RETURN NR;
END;



FUNCTION NR_LIVRARI_DIN_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  IF aCodNirSer &gt; 0  THEN
    BEGIN
      SELECT NVL(COUNT(*), 0) INTO NR
      FROM
      LIVR1 l1, LIVR L
      WHERE
        l.CODLIVR = l1.CODLIVR AND
        l.OPERAT  = 1 AND
        l.ANULAT  = 0 AND
        l1.CODNIRSER = aCodNirSER;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;
  RETURN NR;
END;

FUNCTION AMFACTURALAAVIZ(CODAVIZ  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(CANT) INTO SUMA FROM INTRLINK
    WHERE
    CODLINIEAVIZ IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = CODAVIZ);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;


  IF NVL(SUMA, 0) = 0 THEN
  BEGIN
    SELECT COUNT(*) INTO SUMA FROM INTRARI1
    WHERE
    CODINTR1STORNO IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = CODAVIZ);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  END IF;

  RETURN SUMA;
END;


FUNCTION AMAVIZLAFACTURAASTEPTARE(CODAVIZ  IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT SUM(CANT) INTO SUMA FROM INTRASTEPTLINK
    WHERE
    CODLINIEFACTURA IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = CODAVIZ);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;

  RETURN SUMA;
END;



FUNCTION LINIEAVIZSTINSA(aCODINTR1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIEAVIZ), 0) INTO NR FROM INTRLINK
    WHERE
    CODLINIEAVIZ = aCODINTR1;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR = 0 THEN
    BEGIN
      SELECT NVL(COUNT(CODINTR1STORNO), 0) INTO NR FROM INTRARI1
      WHERE
        CODINTR1STORNO = ACODINTR1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;

  RETURN NR;
END;


FUNCTION LINIEAVIZSTINSA_EXT(aCODINTR1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIEAVIZ), 0) INTO NR
    FROM
      INTRLINK IL,
      INTRARI1 I1,
      INTRARI I
    WHERE
    CODLINIEAVIZ = aCODINTR1
    AND I1.CODINTR1 = IL.CODINTR1
    AND I.CODINTR = I1.CODINTR
    AND NVL(I.ANULAT, 0) = 0;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR = 0 THEN
    BEGIN
    SELECT SUM(NR) INTO NR 
    FROM
      (
       select count(*) AS NR
       FROM
         INTRARI1 I1,
         INTRARI I
       WHERE
          I1.CODINTR1STORNO = aCODINTR1
          AND I.CODINTR = I1.CODINTR
          AND NVL(I.ANULAT, 0) = 0
      UNION ALL
       select count(*) AS NR
       FROM
         IESIRI1 IE1,
         IESIRI IE
       WHERE
          IE1.CODLINIEDOCIMP = aCODINTR1
          AND IE1.TIPDOCIMP = 2
          AND IE.CODIES = IE1.CODIES
          AND NVL(IE.ANULAT, 0) = 0
      );
  
    
    
     /* 
      SELECT NVL(COUNT(CODINTR1STORNO), 0) INTO NR
      FROM
        INTRARI1 I1,
        INTRARI I
      WHERE
        I1.CODINTR1STORNO = ACODINTR1
        AND I.CODINTR = I1.CODINTR
        AND NVL(I.ANULAT, 0) = 0;
     */   
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
  END IF;

  RETURN NR;
END;

FUNCTION LINIEFACTASTEPTSTINSA(aCODINTR1  IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(CODLINIEFACTURA), 0) INTO NR
    FROM
      INTRASTEPTLINK IL,
      INTRARI1 I1,
      INTRARI I
    WHERE
      CODLINIEFACTURA = aCODINTR1
      AND I1.CODINTR1 = IL.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND NVL(I.ANULAT, 0) = 0;
      EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  RETURN NR;
END;



FUNCTION NR_LIVRARI_DIN_DOCUMENT(aCodIntr IN NUMBER, aTipIntr IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(*), 0) INTO NR FROM LIVR1
    WHERE
      CODNIRSTOC IN
       ( SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN
       ( SELECT CODNIR FROM NIR WHERE CODINTR = aCodIntr AND TIPNIR = aTipIntr )
       );
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;



FUNCTION GET_MAX_CODNIRSTOC_EDITAT RETURN NUMBER
IS
BEGIN
  RETURN 0 /*g_CodNirStoc*/;
END;

FUNCTION SUMA_LIVRARI_DIN_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;



FUNCTION SUMA_INTRARI_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT CANTNIR INTO SUMA
    FROM
      NIRSTOC NS, NIR N
    WHERE
      NS.CODNIRSTOC = aCODNIRSTOC AND N.CODNIR = NS.CODNIR AND N.OPERAT = 1 AND N.ANULAT = 0
      AND
      aAN = ( CASE
                 WHEN NVL(N.CODINTR, 0)  &lt;&gt; 0 THEN (SELECT AN FROM INTRARI I WHERE I.CODINTR   = N.CODINTR)
                 WHEN NVL(N.CODTRANSF,0) &lt;&gt;0  THEN (SELECT AN FROM TRANSF  T WHERE T.CODTRANSF = N.CODTRANSF)
              END) AND
      aLUNA = ( CASE
                 WHEN NVL(N.CODINTR, 0)  &lt;&gt; 0 THEN (SELECT LUNA FROM INTRARI I WHERE I.CODINTR   = N.CODINTR)
                 WHEN NVL(N.CODTRANSF, 0)&lt;&gt;0  THEN (SELECT LUNA FROM TRANSF  T WHERE T.CODTRANSF = N.CODTRANSF)
              END);

      EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_LIVRARI_DIN_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT NVL(SUM(CANT), 0) INTO SUMA
    FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc AND
    aAN = ( CASE
               WHEN NVL(L.CODIES, 0)    &lt;&gt; 0    THEN (SELECT AN FROM IESIRI I WHERE I.CODIES   = L.CODIES)
               WHEN NVL(L.CODTRANSF, 0) &lt;&gt; 0 THEN (SELECT AN FROM TRANSF  T WHERE T.CODTRANSF = L.CODTRANSF)
               WHEN NVL(L.CODINTR, 0)  &lt;&gt; 0  AND L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) THEN (SELECT AN FROM INTRARI  T WHERE T.CODINTR = L.CODINTR)
            END) AND
    aLUNA = ( CASE
               WHEN NVL(L.CODIES, 0)    &lt;&gt; 0  THEN (SELECT LUNA FROM IESIRI I WHERE I.CODIES   = L.CODIES)
               WHEN NVL(L.CODTRANSF, 0) &lt;&gt; 0 THEN (SELECT LUNA FROM TRANSF  T WHERE T.CODTRANSF = L.CODTRANSF)
               WHEN NVL(L.CODINTR, 0)   &lt;&gt; 0  AND L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) THEN (SELECT LUNA FROM INTRARI  T WHERE T.CODINTR = L.CODINTR)
            END);
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;



FUNCTION SUMA_LIVRARI_DIN_NIR_UM1(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM1), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;



FUNCTION SUMA_LIVRARI_DIN_NIR_UM2(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM2), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_MARIRI_NIR(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT  /*+ INDEX(L, LIVR_PK) */   NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_MARIRI_NIR_IN_LUNA(aCodNirStoc IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc AND
    EXTRACT(YEAR FROM L.DATALIVR) = aAN AND EXTRACT(MONTH FROM L.DATALIVR) = aLUNA;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_MARIRI_NIR_UM1(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT  /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM1), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_MARIRI_NIR_UM2(aCodNirStoc IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM2), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSTOC = aCodNirStoc;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_LIVRARI_DIN_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  IF NVL(aCODNIRSER, 0) = 0 THEN RETURN 0;
  END IF;

  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;

FUNCTION SUMA_MARIRI_NIRSER(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  IF NVL(aCODNIRSER, 0) = 0 THEN RETURN 0;
  END IF;

  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */   NVL(SUM(CANT), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;



FUNCTION SUMA_LIVRARI_DIN_NIRSER_UM1(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  IF NVL(aCODNIRSER, 0) = 0 THEN RETURN 0;
  END IF;

  BEGIN
    SELECT /*+ INDEX(L, LIVR_PK) */   NVL(SUM(CANTUM1), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;

FUNCTION SUMA_MARIRI_NIRSER_UM1(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  IF NVL(aCODNIRSER, 0) = 0 THEN RETURN 0;
  END IF;

  BEGIN
    SELECT  /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM1), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION SUMA_LIVRARI_DIN_NIRSER_UM2(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  IF NVL(aCODNIRSER, 0) = 0 THEN RETURN 0;
  END IF;

  BEGIN
    SELECT  /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM2), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR &lt;&gt; 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;

FUNCTION SUMA_MARIRI_NIRSER_UM2(aCodNirSer IN NUMBER) RETURN NUMBER
IS
SUMA NUMBER(20, 7) := 0;
BEGIN
  BEGIN
    SELECT  /*+ INDEX(L, LIVR_PK) */  NVL(SUM(CANTUM2), 0) INTO SUMA FROM LIVR1 l1, LIVR l
    WHERE
    l.CODLIVR = l1.CODLIVR AND l.TIPLIVR = 15 and l.OPERAT = 1 AND l.ANULAT = 0 AND l1.CODNIRSER = aCodNirSer;
    EXCEPTION WHEN OTHERS THEN SUMA := 0;
  END;
  RETURN SUMA;
END;


FUNCTION GETSTOCARTICOL(aCodObiect IN NUMBER, aCodGest in number default 0) RETURN NUMBER
IS
 STOC NUMBER(20, 7) := 0.0000000;
BEGIN
  IF ACODGEST &gt; 0 THEN
    BEGIN
      SELECT NVL(SUM(NS.REST), 0) INTO STOC
      FROM
        NIRSTOC NS,
        NIR N,
        NGEST G,
        IOART1 IOALUNA
      WHERE NS.CODNIR = N.CODNIR
        AND IOALUNA.CODIOART = NS.CODIOART
        AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
        AND IOALUNA.MG &lt;&gt; 5
        AND IOALUNA.MG &lt;&gt; 3
        AND N.OPERAT = 1 AND N.ANULAT = 0
        AND NS.CODOBIECT = aCodObiect
        AND G.CODGEST = N.GEST
        AND NVL(G.CODSUBUNIT, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
        AND N.GEST = ACODGEST;

    EXCEPTION WHEN OTHERS THEN STOC := 0.0000000;
    END;
  ELSE
    BEGIN
      SELECT NVL(SUM(NS.REST), 0) INTO STOC
      FROM
        NIRSTOC NS,
        NIR N,
        NGEST G,
        IOART1 IOALUNA
      WHERE NS.CODNIR = N.CODNIR
        AND IOALUNA.CODIOART = NS.CODIOART
        AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
        AND IOALUNA.MG &lt;&gt; 5
        AND IOALUNA.MG &lt;&gt; 3
        AND N.OPERAT = 1 AND N.ANULAT = 0
        AND NS.CODOBIECT = aCodObiect
        AND PKG_NOMGEST.GESTIUNE_DEDICATA(N.GEST)  &gt; 0
        AND G.CODGEST = N.GEST
        AND NVL(G.CODSUBUNIT, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE);
    EXCEPTION WHEN OTHERS THEN STOC := 0.0000000;
    END;
  END IF;
  RETURN STOC;
END;

function getpretmediuachiz(aCodObiect in number) return number is
vCant number(20,7);
vVal number(20,7);
vIdx number(10);
vNrIntr number(10);
begin
  vIdx := 1;
  vCant := 0.0;
  vVal  := 0.0;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrPretIntrMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrIntr FROM DUAL;

  if vNrIntr = 0 then return 0.0; end if;

  for v_rec in (
    SELECT  nvl(NS.PRET,0)- nvl(NS.ADAOS,0) pret, ns.cantnir
     FROM
       NIR N,
       NIRSTOC NS,
       NGEST G
     WHERE
       NS.CODOBIECT = aCODOBIECT
       AND NS.CODNIR = N.CODNIR
       AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
       AND OPERAT = 1
       AND ANULAT = 0
       AND G.CODGEST = N.GEST
       AND nvl(G.CODSUBUNIT, 1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
     ORDER BY N.DATANIR ) loop
    if vIdx &gt; vNrIntr then Exit; end if;
    vCant := vCant + v_rec.cantnir;
    vVal := vVal + v_rec.cantnir * v_rec.pret;
    vIdx := vIdx + 1;
  end loop;

  if vCant &lt;&gt; 0 then
    return vVal/vCant;
  else
    return 0;
  end if;
end;


FUNCTION GETLASTPRETACHIZVAL_NIRSTOC(aCodObiect IN NUMBER) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NVL(NS.PUVAL, 0) PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
      AND NVL(NS.PUVAL, 0) &lt;&gt; 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;




FUNCTION GETLASTPRETACHIZ_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
 FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND(N.TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15) OR (N.TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; )) AND N.OPERAT = 1 AND N.ANULAT = 0 AND NVL(I.CUSTODIE,0) = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;


FUNCTION GETLASTPRETINREG_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretInreg
    FROM
      NIRSTOC NS
      INNER JOIN TMP_IOART_LUNA IO ON NS.CODIOART = IO.CODIOART AND IO.DIFPRET = 1
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0 AND NVL(I.CUSTODIE,0) = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretInreg;
  END LOOP;
  RETURN 0;
END;


FUNCTION GETLASTSUPLIMACHIZ_SUBUNIT(aCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT CASE WHEN NVL(NS.CANTNIR,0) = 0 THEN 0 ELSE Nvl(NS.SUPLIMENT,0)/NS.CANTNIR END Suplim
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0 AND NVL(I.CUSTODIE,0) = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.Suplim;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLPA_SUBUNIT_FARAAECUST(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT  JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND (NOT (N.TIPNIR = 2 AND I.CUSTODIE = 1)) AND N.OPERAT = 1 AND N.ANULAT = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLDA_SUBUNIT_FARAAECUST(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE IS
BEGIN
  FOR V_REC IN (
    SELECT N.DATANIR DataAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT  JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND (NOT (N.TIPNIR = 2 AND I.CUSTODIE = 1)) AND N.OPERAT = 1 AND N.ANULAT = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DataAchiz;
  END LOOP;
  RETURN NULL;
END;

FUNCTION GETLASTDATAACHIZ_SUBUNIT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE IS
BEGIN
  FOR V_REC IN (
    SELECT N.DATANIR DataAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND OPERAT = 1 AND ANULAT = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DataAchiz;
  END LOOP;
  RETURN NULL;
END;

/*
FUNCTION GETLASTPRETACHIZ(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN aExclSupl = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;
*/

FUNCTION GETLASTPRETACHIZ(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTPRETACHIZX(aCodObiect IN NUMBER, aCodIntr1 IN NUMBER DEFAULT 0, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
      AND (aCodIntr1 &gt; 0 and coalesce(ns.codintr1,0) &lt;&gt; aCodIntr1 or aCodIntr1 = 0)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTPRETACHIZ1(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 5)
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTPRETACHIZ_VAL(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT (NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END)/COALESCE(I.CURS,IE.CURS,1) PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT JOIN IESIRI IE ON IE.CODIES = N.CODIES
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((N.TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (N.TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND N.OPERAT = 1 AND N.ANULAT = 0 AND COALESCE(I.MONEDA, IE.MONEDA, 0) &gt; 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTPRETACHIZ_RETANN(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 13, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;



FUNCTION GETLASTPRETINREG(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NS.PRET - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretInreg
    FROM
      NIRSTOC NS
      INNER JOIN TMP_IOART_LUNA IO ON NS.CODIOART = IO.CODIOART AND IO.DIFPRET = 1
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretInreg;
  END LOOP;
  RETURN 0;
END;


FUNCTION GETLASTDATAACHIZ(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT N.DATANIR DataAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DataAchiz;
  END LOOP;
  RETURN null;
END;

FUNCTION GETLASTDATAACHIZ_PER(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
vDataIni Date;
vDataFin Date;
vAnIni number(4);
vLunaIni number(2);
vAnFin number(4);
vLunaFin number(2);
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  if pkg_list_selectperioada.DupaData then
    vDataIni := pkg_list_selectperioada.DataIni;
    vDataFin := pkg_list_selectperioada.DataFin;
  else
    if mod(pkg_list_selectperioada.AnLunaIni,12) = 0 then
      vAnIni := pkg_list_selectperioada.AnLunaIni / 12 - 1;
      vLunaIni := 12;
    else
      vAnIni := trunc(pkg_list_selectperioada.AnLunaIni/12);
      vLunaIni := pkg_list_selectperioada.AnLunaIni-vAnIni*12;
    end if;
    vDataIni := to_date(&apos;01.&apos;||LPAD(to_char(vLunaIni),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnIni),&apos;dd.mm.yyyy&apos;);
    if mod(pkg_list_selectperioada.AnLunaFin,12) = 0 then
      vAnFin := pkg_list_selectperioada.AnLunaFin / 12 - 1;
      vLunaFin := 12;
    else
      vAnFin := trunc(pkg_list_selectperioada.AnLunaFin/12);
      vLunaFin := pkg_list_selectperioada.AnLunaFin-vAnFin*12;
    end if;
    vDataFin := Last_Day(to_date(&apos;01.&apos;||LPAD(to_char(vLunaFin),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnFin),&apos;dd.mm.yyyy&apos;));
  end if;

  FOR V_REC IN (
    SELECT N.DATANIR DataAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0 AND N.DATANIR BETWEEN vDataIni AND vDataFin
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DataAchiz;
  END LOOP;
  RETURN null;
END;

FUNCTION GETLASTPRETACHIZ_EXT(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;



FUNCTION GETLASTPRETACHIZFURN(aCodObiect IN NUMBER, aFURN IN NUMBER ) RETURN NUMBER IS
BEGIN
  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0)  PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN INTRARI I ON N.CODINTR = I.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 9) AND N.OPERAT = 1 AND N.ANULAT = 0
         AND I.PARTENER = aFURN
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTFURN_SUBUNIT(aCodObiect IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  FOR V_REC IN (
    SELECT P.DEN_PART
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      INNER JOIN NPART P ON P.CODPART = I.PARTENER
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DEN_PART;
  END LOOP;
  RETURN NULL;
END;

FUNCTION GETLASTCODFURN_SUBUNIT(aCodObiect IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  FOR V_REC IN (
    SELECT P.CODEXTERN
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      INNER JOIN NPART P ON P.CODPART = I.PARTENER
    WHERE NS.CODOBIECT = aCODOBIECT
      AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.CODEXTERN;
  END LOOP;
  RETURN NULL;
END;

FUNCTION GETLASTPRETACHIZ_FACT_AE (aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 9)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.PretAchiz;
  END LOOP;
  RETURN 0;
END;

FUNCTION GETLASTDATAACHIZ_FACT_AE(aCodObiect IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN DATE IS
FaraIntrSubunit VARCHAR2(5) := &apos;?&apos;;
BEGIN
  FaraIntrSubunit := NVL(PKG_CATEGCONST.GetValConstanta(&apos;FaraIntrSubunit&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;);

  FOR V_REC IN (
    SELECT N.DATANIR DataAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND ((TIPNIR IN (1, 2, 3, 4, 5, 9)) OR (TIPNIR = 6 AND FaraIntrSubunit = &apos;2&apos; ))
      AND OPERAT = 1 AND ANULAT = 0
    ORDER BY N.DATANIR DESC )
  LOOP
    RETURN V_REC.DataAchiz;
  END LOOP;
  RETURN null;
END;

FUNCTION GETLASTCODINTR(aCodObiect IN NUMBER) RETURN NUMBER
IS
 COD NUMBER(20) := 0;
BEGIN

  FOR V_REC IN
  (SELECT  N.CodIntr
   FROM
     NIR N, NIRSTOC NS
   WHERE
     NS.CODOBIECT = aCODOBIECT AND NS.CODNIR = N.CODNIR AND TIPNIR IN (1, 2, 3, 4, 5) AND OPERAT = 1 AND ANULAT = 0
   ORDER BY N.DATANIR DESC
   )
   LOOP
     RETURN V_REC.CodIntr;
   END LOOP;


 RETURN COD;

END;

FUNCTION GETLASTPRETMAXIMAL(aCodObiect IN NUMBER) RETURN NUMBER
IS
 PRETMAXIMAL NUMBER(20, 7) := 0;
 LASTDATANIR DATE := NULL;
BEGIN

  FOR V_REC IN
  (SELECT  NS.PUMaximal
   FROM
     NIR N, NIRSTOC NS
   WHERE
     NS.CODOBIECT = aCODOBIECT AND NS.CODNIR = N.CODNIR AND TIPNIR IN (1,2, 3, 4, 5, 6, 7, 8, 9, 15) AND OPERAT = 1 AND ANULAT = 0
   ORDER BY N.DATANIR DESC
   )
   LOOP
     RETURN V_REC.PUMaximal;
   END LOOP;

 RETURN PRETMAXIMAL;

END;

FUNCTION GET_REST_STOC(aCodNIR in NUMBER, aCodNirStoc IN NUMBER, aCantNIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantNir - SUMA_LIVRARI_DIN_NIR(aCodNIRStoc) + SUMA_MARIRI_NIR(aCodNIRStoc) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;



FUNCTION GET_REST_STOC_UM1(aCodNIR in NUMBER, aCodNirStoc IN NUMBER, aCantUM1NIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantUM1Nir - SUMA_LIVRARI_DIN_NIR_UM1(aCodNIRStoc) + SUMA_MARIRI_NIR_UM1(aCodNIRStoc) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;

FUNCTION GET_REST_STOC_UM2(aCodNIR in NUMBER, aCodNirStoc IN NUMBER, aCantUM2NIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantUM2Nir - SUMA_LIVRARI_DIN_NIR_UM2(aCodNIRStoc) + SUMA_MARIRI_NIR_UM2(aCodNIRStoc) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;



FUNCTION GET_REST_STOC_SERIE(aCodNIR in NUMBER, aCodNirSer IN NUMBER, aCantNIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantNir - SUMA_LIVRARI_DIN_NIRSER(aCodNIRSer) + SUMA_MARIRI_NIRSER(aCodNIRSer) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;


FUNCTION GET_REST_STOC_SERIE_UM1(aCodNIR in NUMBER, aCodNirSer IN NUMBER, aCantUM1NIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantUM1Nir - SUMA_LIVRARI_DIN_NIRSER_UM1(aCodNIRSer) + SUMA_MARIRI_NIRSER_UM1(aCodNIRSer) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;


FUNCTION GET_REST_STOC_SERIE_UM2(aCodNIR in NUMBER, aCodNirSer IN NUMBER, aCantUM2NIR IN NUMBER) RETURN NUMBER
IS
STOC NUMBER(20, 7) := 0;
O NUMBER(1) := 0;
A NUMBER(1) := 1;

BEGIN
  BEGIN
    SELECT N.OPERAT, N.ANULAT INTO O, A FROM NIR N
    WHERE
    N.CODNIR = aCODNIR;
    EXCEPTION WHEN OTHERS THEN  STOC := 0;
  END;
  IF (O = 1)AND(A = 0) THEN
    BEGIN
      SELECT aCantUM2Nir - SUMA_LIVRARI_DIN_NIRSER_UM2(aCodNIRSer) + SUMA_MARIRI_NIRSER_UM2(aCodNIRSer) INTO STOC FROM DUAL;
      EXCEPTION WHEN OTHERS THEN STOC := 0;
    END;
  ELSE
    STOC := 0;
  END IF;
  RETURN STOC;
END;

FUNCTION GET_REST_STOC_IN_LUNA(ACODNIRSTOC IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
 STOC      NUMBER(20, 7) := 0;
 aANPREC   NUMBER(5)     := 0;
 aLUNAPREC NUMBER(5)     := 0;
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(aAN, aLUNA, AANPREC, aLUNAPREC);
  BEGIN
    SELECT REST INTO STOC FROM NIRLUNA WHERE CODNIRSTOC = aCODNIRSTOC AND AN = aANPREC AND LUNA = aLUNAPREC;
    EXCEPTION WHEN OTHERS THEN STOC := 0;
  END;
  STOC := STOC + SUMA_INTRARI_NIR_IN_LUNA(aCODNIRSTOC, aAN, aLUNA) - SUMA_LIVRARI_DIN_NIR_IN_LUNA(aCODNIRSTOC, aAN, aLUNA) + SUMA_MARIRI_NIR_IN_LUNA(aCODNIRSTOC, aAN, aLUNA);
  RETURN STOC ;
END;


PROCEDURE SETPARTENERAVIZ(aPart in NUMBER)
IS
BEGIN
  PartenerAviz := aPart;
END;

FUNCTION CONDITIE_PART_AVIZ(aPart in NUMBER) RETURN NUMBER
IS
BEGIN
  IF aPart = PartenerAviz THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodIntr INTO Tmp FROM INTRARI WHERE CodIntr = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  TIPINTR          NUMBER(20);
  aCARNETDOC       NUMBER(20);
  aNRDOC           NUMBER(20);
  aCodSubunit      NUMBER(20);
  aDataDoc         DATE;
  aDoc             VARCHAR2(200);
/*  EXISTAINTRARIF1  NUMBER(10) := 0;
  EXISTAINTRARIP1  NUMBER(10) := 0;
  EXISTAINTR1PF    NUMBER(10) := 0;
  EXISTAINTR1SUB   NUMBER(10) := 0;
  EXISTAINTR1FAST  NUMBER(10) := 0;
  EXISTAINTRARIAE1 NUMBER(10) := 0;
  EXISTAINTRARIFA1 NUMBER(10) := 0;
  EXISTAINTR1AST   NUMBER(10) := 0;
  EXISTAINTRARICF1 NUMBER(10) := 0;*/



  NR              NUMBER(20);
  aTIPFACTURA     INTEGER := 0;
  TotSosit        NUMBER;
  aTIPTRANZACTIE  INTEGER;
  LastUtilaj2c    NUMBER(20);
  aCURS           NUMBER(20, 7) := 1;
	vCod            Number(20);
	aCodBCAR        Number(20);
	aValoare        NUMBER(20, 7);
  StornoAvize     VARCHAR2(30);
  aAUTOFACTURARE  NUMBER(1) := 0;
  CONSTOPERAT     NUMBER(1) := 0;
BEGIN

  PKG_GLOBALS.MarkDirtyJurnal;

  SP_LOCKRECORD(RecId);

  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADACCEPTATNEOPFURN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERAT  := 0;
  END;

  UPDATE SPVARHIVA SV SET CODDOCWME = NULL WHERE SV.CODDOCWME = RECID AND SV.TIPDOC = 1;

  SELECT TIPDOC,  CARNETDOC,  NRDOC,  SUBUNITATEA,  datadoc, prefixdoc||nrdoc||&apos;/&apos;||datadoc, NVL(TIPFACTURA, 0), NVL(TIPTRANZACTIE, 0), CURS,
         AUTOFACTURARE
  INTO   TIPINTR, aCARNETDOC, aNRDOC, aCodSubunit, aDataDoc, aDoc, aTIPFACTURA, aTIPTRANZACTIE, aCURS, aAUTOFACTURARE
  FROM INTRARI WHERE CODINTR = RecID;

  PKG_CFGTABLES.EXT_DELETERECORD (recId, TIPINTR);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM TAXDECL WHERE TipDoc = TIPINTR and CODDOC = RECID;

  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CodUnic)
  SELECT codnirstoc FROM NIRSTOC WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID);
  for v_rec in (select * from tmp_manevra) loop
    insert into tmp_manevra(codunic)
    select ns11.codnirstoc
    from nirstoc1 ns1
         inner join nirstoc1 ns11 on ns1.codcomanda1 = ns11.codcomanda1
    where ns1.codcomanda1 &gt; 0 and ns1.codnirstoc = v_rec.codunic;
  end loop;
  pkg_pretprod.SetDirtyStructura;


 -- MEMOREZ IN INTRAR1_MAN CODURI DE AVIZE STORNATE SI CODURILE FACT IN ASTEPTARE STORNATE si altele
 DELETE INTRARI1_MAN;
 INSERT INTO  INTRARI1_MAN (CODINTR1, CODINTR1STORNO, CODLINIEDOCIMP, TIPDOCIMP, CANT)
                     SELECT CODINTR1, CODINTR1STORNO, CODLINIEDOCIMP, TIPDOCIMP, CANT

 FROM INTRARI1
 WHERE
   CODINTR = RECID;



  -- memorez livrarile care vor fi sterse
  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CodUnic)
  SELECT CodNirStoc FROM Livr1 WHERE CodLivr in (SELECT CodLivr FROM LIVR WHERE CodIntr = RecID);

  IF TIPINTR = 2 AND aTIPFACTURA = 9 THEN -- avize care STING FACTURI IN ASTEPTARE
    DELETE TMP_INTRASTEPTLINK;
    INSERT INTO TMP_INTRASTEPTLINK (CODINTR1, CODLINIEFACTURA, CANT)
    SELECT CODINTR1, CODLINIEFACTURA, CANT FROM INTRASTEPTLINK
    WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1  WHERE CODINTR = RECID);
  END IF;

  FOR V_REC IN (SELECT * FROM INTRDOCTRANSP WHERE CODINTR = RECID)
  LOOP
    UPDATE INTRARI
    SET
      VALTRANSPORT = NVL(VALTRANSPORT, 0) - V_REC.VALTRANSPORT
    WHERE
      CODINTR = V_REC.CODINTRLINK;
  END LOOP;


  BEGIN
   PKG_JURNAL.SET_SKIPUPDATEJURNFLAG(1);
   FOR V_REC IN
   (
    SELECT I1.CODINTR1
    FROM
      INTRARI I,
      INTRARI1 I1,
      INTRDOCTRANSP INTR_DOC_TR
    WHERE
      INTR_DOC_TR.CODINTR = RECID
      AND I.CODINTR = INTR_DOC_TR.CODINTRLINK
      AND I1.CODINTR = I.CODINTR
   )
   LOOP
     PKG_JURNAL.RecalculPRETAchiz(V_REC.CODINTR1);
   END LOOP;
   PKG_JURNAL.SET_SKIPUPDATEJURNFLAG(0);

   MERGE INTO JURNAl1 J1
   USING (SELECT DISTINCT TIPDOC, CODDOC, SUBUNITATEA, AN, LUNA FROM TMP_JURNAL_MAN) JM
   ON ( J1.CODDOC = JM.CODDOC AND J1.TIPDOC = JM.TIPDOC)
   WHEN MATCHED THEN UPDATE SET DIRTY = 1
   WHEN NOT MATCHED THEN INSERT (CODJURNAL1, TIPDOC, CODDOC, SUBUNITATEA, AN, LUNA, DIRTY) VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, JM.TIPDOC, JM.CODDOC, JM.SUBUNITATEA, JM.AN, JM.LUNA, 1);


 END;




 DELETE FROM INTRDOCTRANSP WHERE CODINTR = RECID;
 DELETE FROM DetaliiET1 et1
              where et1.coddetaliuet in (select et.coddetaliu
                                           from detaliiet et
                                           WHERE et.TipDoc = TIPINTR and et.CODDOC = RECID);
 DELETE FROM DetaliiET  WHERE TipDoc = TIPINTR and CODDOC = RECID;
 DELETE FROM STATUSDECL WHERE TipDoc = 100+TIPINTR and CODDOC = RECID;




  IF TIPINTR = 9 THEN --
  -- memorez codurile de avize stinse de INTRLINK-urile care vor fi sterse
    IF aTIPFACTURA &lt;&gt; 9 THEN
      DELETE TMP_INTRARI1;
      INSERT INTO  TMP_INTRARI1(CODINTR1)
      ( SELECT CODINTR1 FROM INTRARI1
        WHERE CODINTR1 IN

        (SELECT IL.CODLINIEAVIZ
         FROM
          INTRLINK IL
          LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
         WHERE
         I1.CODINTR = RecID
        )
     );
    ELSE
      DELETE TMP_COMANDA1;
      INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
      ( SELECT CODLINIECOMANDA FROM INTRLINK IL
        WHERE IL.CODINTR1 IN
        (SELECT I1.CODINTR1 FROM INTRARI1 I1 WHERE CODINTR=RecID AND I1.CODINTR1 = IL.CODINTR1)
      );

    END IF;
   ELSE
   IF TIPINTR IN (1, 2, 3, 4) THEN
    -- memorez codurile de comenzi furnizori stinse de INTRLINK-urile care vor fi sterse
      DELETE TMP_COMANDA1;
      INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
      ( SELECT CODLINIECOMANDA FROM INTRLINK IL
        WHERE IL.CODINTR1 IN
        (SELECT I1.CODINTR1 FROM INTRARI1 I1 WHERE CODINTR=RecID AND I1.CODINTR1 = IL.CODINTR1)
      );

/* mutat la incepu ca=mi mai trebuie temporarul asta
       -- MEMOREZ IN INTRAR1_MAN CODURI DE AVIZE STORNATE SI CODURILE FACT IN ASTEPTARE STORNATE
       DELETE INTRARI1_MAN;
       INSERT INTO  INTRARI1_MAN (CODINTR1, CODINTR1STORNO, CODLINIEDOCIMP, TIPDOCIMP, CANT)
                           SELECT CODINTR1, CODINTR1STORNO, CODLINIEDOCIMP, TIPDOCIMP, CANT
       FROM INTRARI1
       WHERE
         CODINTR = RECID;
*/

   else
     IF TIPINTR IN (7) THEN
    -- memorez codurile de comenzi furnizori stinse de INTRLINK-urile care vor fi sterse
      DELETE TMP_COMANDA1;
      INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
      ( SELECT CODLINIECOMANDA FROM INTRPRODLINK IL
        WHERE IL.CODINTR1 IN
        (SELECT I1.CODINTR1 FROM INTRARI1 I1 WHERE CODINTR=RecID AND I1.CODINTR1 = IL.CODINTR1)
      );

   END IF;
   END IF;
  END IF;

/*
  DELETE FROM LIVR1 l1
  WHERE
  CodLIVR IN
  (SELECT CodLIVR FROM LIVR WHERE CodIntr = RecID);
*/

  DELETE TMP_LIVR1;

  INSERT INTO TMP_LIVR1(CODLIVR1)
  SELECT CODLIVR1 FROM LIVR1 L1
  WHERE
   CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID);


  DELETE FROM LIVRVAL  WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM LIVR1 L1 WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

-- inainte de steregere din LIVR reactivez numerele
  FOR V_REC IN (SELECT * FROM LIVR WHERE  CodIntr = RecId)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
  END LOOP;

  DELETE FROM LIVR WHERE CodIntr = RecId ;

  DELETE FROM NIRSER
  WHERE
  CodNirStoc IN
  (SELECT CodNirStoc FROM NIRSTOC WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID)
  ) ;

  DELETE FROM NIRSERLUNA
  WHERE
  CODNirStoc IN (SELECT CodNirStoc FROM NIRSTOC WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID));

  DELETE FROM NIRLUNA
  WHERE
  CODNirStoc IN (SELECT CodNirStoc FROM NIRSTOC WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID));

  -- LA STERGERE DIN NIRSTOC STERG SI MIJLOACE FIXE
/*
  DELETE TMP_MIFIX;
  FOR V_REC IN (SELECT * FROM NIRSTOC  WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID))
  LOOP
    FOR V_REC_MF IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC)
    LOOP
      INSERT INTO TMP_MIFIX (CODMIFIX) VALUES (V_REC_MF.CODMIFIX);
      DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC_MF.CODMIFIX1;
    END LOOP;
    DELETE FROM MIFIX WHERE CODMIFIX IN (SELECT CODMIFIX FROM TMP_MIFIX);


    DELETE FROM MASTERMIFIX  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;
*/

  FOR V_NS IN
    (
     SELECT
       IL.CODLINIECOMANDA CODCOMANDA1F,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NUM1.PARITATE
     FROM
       NIRSTOC NS
       INNER JOIN NUM1 on ns.umsec = NUM1.CODUM1
       LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRLINK IL
     WHERE
       IL.CODINTR1            = NS.CODINTR1
       and ns.CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID)
       )
  loop
       TotSosit := V_NS.CantNIR;
       if TotSosit &lt;&gt; 0 then
         for v_Rez in ( select CodRezervatS, CodComanda1, CodObiect, UMSec, REZERVATINI Folosit  from  RezervatS
                        where CODCOMANDA1F = v_NS.CODCOMANDA1F
                              AND CodNIRStoc = V_NS.CodNIRStoc
                              AND CodNIRSer  = V_NS.CodNIRSer
                        order By CodComanda1 asc)
         loop
           if TotSosit &lt;&gt; 0 then
             if TotSosit &lt; v_REZ.Folosit then
               update REZERVATS set Rest = Rest + TotSosit
                                where CODCOMANDA1F    = v_NS.CODCOMANDA1F
                                      AND CodObiect   = v_REZ.CodObiect
                                      AND CodComanda1 = v_REZ.CodComanda1
                                      AND CodNIRStoc  = 0;
               TotSosit := 0;
             else
               TotSosit := TotSosit - v_REZ.Folosit ;
               update REZERVATS set Rest = Rest + v_REZ.Folosit
                                where CODCOMANDA1F    = v_NS.CODCOMANDA1F
                                      AND CodObiect   = v_REZ.CodObiect
                                      AND CodComanda1 = v_REZ.CodComanda1
                                      AND CodNIRStoc  = 0;
             end if;
           end if;
         end loop;
       end if;
  end loop;


  FOR V_REC IN (SELECT * FROM NIRSTOC  WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID))
  LOOP
		DELETE FROM DEZASAMBLARI1 WHERE CODLIVR1 in (select CodLivr1 from DEZASAMBLARI  WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
		DELETE FROM DEZASAMBLARI  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM MASTERMIFIX   WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NPLINK        WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC       WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    delete from nirstoc1      where codnirstoc = v_rec.codnirstoc;
    for v_tmp in (select codcomanda1 from rezervats where codnirstoc = v_rec.codnirstoc) loop
      UPDATE COMANDA1 C1
          SET
           C1.RESTLANSAT = C1.CANTACCEPTAT -
                       (
                        SELECT
                          NVL(SUM(c1.cantacceptat), 0)
                        FROM cmdlink l
                             inner join comanda1 c1 on l.codcomanda1 = c1.codcomanda1
                             inner join comanda c on c1.codcomanda = c.codcomanda
                        where c.tipdoc = 53 AND C.OPERAT = 1 AND C.ANULAT = 0
                        START WITH l.codliniecomanda = v_tmp.codcomanda1
                        CONNECT BY PRIOR l.CODCOMANDA1 = l.CODLINIECOMANDA
                        )-
                        (
                        SELECT
                          NVL(SUM(r.rest), 0)
                        FROM rezervats r
                        where r.codcomanda1 = v_tmp.codcomanda1
                        )
          WHERE
          C1.CODCOMANDA1 = v_tmp.codcomanda1;
    end loop;
    DELETE FROM REZERVATS   WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

	IF TIPINTR = 7 THEN
		BEGIN
			 Select codLivr1 into vCod from Dezasamblari1 where CODINTRLINK = RECID;
		EXCEPTION WHEN OTHERS THEN vCod := 0;
		END;
    DELETE FROM DEZASAMBLARI1 WHERE CODINTRLINK = RecId;
		if vCod &gt; 0 then
			BEGIN
				SELECT T.Valoare - Nvl((Select Sum(Nvl(Valoare, 0)) from Dezasamblari1 where codLivr1 = vCod),0)
							 into aVALOARE
				FROM Dezasamblari T WHERE T.codLivr1 = vCod;
			EXCEPTION WHEN OTHERS THEN aVALOARE := 0;
			END;

			if Round(aVALOARE,0) = 0 then
				update DEZASAMBLARI set Inchisa = 1 where CodLivr1 = VCod;
			else
				update DEZASAMBLARI set Inchisa = 0 where CodLivr1 = VCod;
			end if;
		end if;
	end if;

 -- DELETE FROM NIRSTOC  WHERE CodNir in (SELECT CodNir FROM NIR WHERE CodIntr = RecID) ;

-- inainte de stergere din LIVR reactivez numerele
  FOR V_REC IN (SELECT * FROM NIR WHERE  CodIntr = RecId)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
  END LOOP;

  DELETE FROM NIR      WHERE CodIntr = RecId ;

  IF TIPINTR = 9 AND aTIPFACTURA &lt;&gt; 9  THEN
-- INCERC SA REFAC PRELURILE DE PE AVIZELE STINSE DE FACT LA AVIZ

    DELETE TMP_INTRLINK;
    INSERT INTO TMP_INTRLINK (CODLINIEAVIZ)

    SELECT IL.CODLINIEAVIZ
    FROM
     INTRLINK IL,
     INTRARI1 I1,
     INTRARI1 I1AE
    WHERE
      I1.CODINTR = RECID
      AND IL.CODINTR1   = I1.CODINTR1
      AND I1AE.CODINTR1 = IL.CODLINIEAVIZ
      AND I1AE.PU       &lt;&gt; I1.PU;
  END IF;

  DELETE FROM INTRLINK WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = RecId);
  DELETE FROM INTRASTEPTLINK WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = RecId);
  DELETE FROM INTRLINK WHERE CODLINIEAVIZ IN (SELECT CODINTR1 FROM INTRARI1 WHERE CODINTR = RecId);
  insert into tmp_intrprodlink_initial(codintr1, codliniecomanda, codlinieaviz, cant, codprogramf1) select * from intrprodlink link where exists (SELECT i1.CODINTR1 FROM INTRARI1 i1 WHERE i1.CODINTR = RecId and link.codintr1 = i1.codintr1);

/*  EXISTAINTRARIF1  := PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF1&apos;);
  EXISTAINTRARIP1  := PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP1&apos;);

  EXISTAINTR1PF    := PKG_LIST_STRUCT.TmpExists(&apos;INTR1PF&apos;);
  EXISTAINTR1SUB   := PKG_LIST_STRUCT.TmpExists(&apos;INTR1SUB&apos;);
  EXISTAINTR1FAST  := PKG_LIST_STRUCT.TmpExists(&apos;INTR1FAST&apos;);
  EXISTAINTRARIAE1 := PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE1&apos;);
  EXISTAINTRARIFA1 := PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA1&apos;);
  EXISTAINTR1AST   := PKG_LIST_STRUCT.TmpExists(&apos;INTR1AST&apos;);
  EXISTAINTRARICF1 := PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF1&apos;);*/




  FOR V_REC IN
  (SELECT * FROM INTRARI1 WHERE CodIntr = RecId ORDER BY INDEXLOCAL DESC /* musai desc din motive de codintr1link*/)
  LOOP
     DELETE NPARC2 WHERE CODINTR1 = V_REC.CODINTR1;
     UPDATE CANTAR SET TIPDOC = NULL, CODDOC1 = NULL WHERE TIPDOC = TIPINTR AND CODDOC1 = V_REC.CODINTR1;

     IF TIPINTR = 2 AND NVL(V_REC.CODINTR1LINK, 0) &lt;&gt; 0 THEN
       FOR V_REC_S IN (SELECT CODINTR1STORNO FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1LINK)
       LOOP
         IF NVL(V_REC_S.CODINTR1STORNO, 0) &lt;&gt; 0 THEN
           UPDATE BCAR
           SET
             CODDOC1 = V_REC_S.CODINTR1STORNO
           WHERE
             TIPDOC = 2 AND CODDOC1 = V_REC.CODINTR1;
         END IF;
       END LOOP;
     END IF;


     IF NVL(V_REC.CODINTR1LINK, 0) = 0 THEN
       begin
				 Select CodBCAR into aCodBCAR from BCAR WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;
				 insert into trigar_modif (CodModif, datamodif, usermodif, Cod, codmaster, tablename, FieldName, oldvalue,newvalue)
				 Values( SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, aCodBCAR,aCodBCAR, &apos;BCAR&apos;, &apos;CODDOC1&apos;,
								 V_REC.CodIntr1, &apos;Null+DELETE+CODINTR1LINK=0&apos;);
	     exception when others then
				 aCodBCAR := 0;
	     end;
       UPDATE BCAR SET TipDoc = NULL, CodDoc1 = NULL WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;

     END IF;

     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1)
     LOOP
       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC = 52) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;


          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
              RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;


         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

          FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
          LOOP
            UPDATE NCONTRULSUB
            SET
              RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
              RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
            WHERE
              CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
          END LOOP;


       END LOOP;



       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1;
     -- fisa mas
     if tipintr = 7 then
       FOR V_TMP IN (SELECT FM1.CODFISAMAS1
                     FROM FISAMAS1 FM1
                          INNER JOIN FISAMAS FM ON FM.CODFISAMAS = FM1.CODFISAMAS
                          INNER JOIN INTRARI1 I1 ON FM.CODINTR1 = I1.CODINTR1
                     WHERE I1.CODINTR = RecId) LOOP
         DELETE FISAMAS1 WHERE CODFISAMAS1 = V_TMP.CODFISAMAS1;
       END LOOP;
       DELETE FISAMAS WHERE CODINTR1 = V_REC.CODINTR1;
       IF aTIPTRANZACTIE = 10 THEN
         --update utilaje2
         for v_tmp in (select u2c.codutilaj2c
                       from intrprodlink l
                            inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                            inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                       where l.codintr1 = v_rec.codintr1
                       ) loop
           update utilaje2c set indexc = null, dataindexc = null, datastart = null, dataend = null where codutilaj2c = v_tmp.codutilaj2c;
         end loop;
       END IF;
     end if;

     --predari plus
     if tipintr = 7 then
       for v_tmp in (select pp.idinreg
                     from intrari1 i1
                          inner join pplink pp on pp.codintr1 = i1.codintr1
                     where i1.codintr = recid
                     ) loop
         update predariplus set
           NRCMD = null,
           DATACMD = null,
           FSC = null,
           SCHIMB = null,
           FORMATIE = null,
           NRNP = null,
           DATANP = null,
           USERIDBLOCAJ = null,
           CODCOMANDA1 = null,
           CANTITATEWME = null,
           DATAWME = null
         where idinreg = v_tmp.idinreg;
       end loop;
     end if;

     DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1;
     DELETE FROM INTRPRODLINK WHERE CODINTR1 = v_Rec.codintr1;

 /*    IF EXISTAINTRARIF1 &gt; 0 THEN
       EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIF1 WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
     END IF;

    IF EXISTAINTRARIP1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIP1 WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;


     IF EXISTAINTR1PF &gt; 0 THEN
       EXECUTE IMMEDIATE &apos;DELETE FROM INTR1PF WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
     END IF;

    IF EXISTAINTR1SUB &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTR1SUB WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;

    IF EXISTAINTR1FAST &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTR1FAST WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;

    IF EXISTAINTRARIAE1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIAE1 WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;

    IF EXISTAINTRARIFA1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIFA1 WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;

    IF EXISTAINTR1AST &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTR1AST WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;

    IF EXISTAINTRARICF1 &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE FROM INTRARICF1 WHERE CODINTR1 = &apos;|| V_REC.CODINTR1;
    END IF;
*/

  END LOOP ;

--  DELETE FROM INTRARI1 WHERE CodIntr = RecId ;



  DELETE FROM INTRARI  WHERE CodIntr = RecId ;
  DELETE DVI WHERE CODINTR = RECID;


  IF TIPINTR = 9 AND aTIPFACTURA &lt;&gt; 9 THEN
-- INCERC SA REFAC PRELURILE DE PE AVIZELE STINSE DE FACT LA AVIZ
    StornoAvize := &apos;2&apos;;
    SELECT pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO StornoAvize from dual;


    DELETE TMP_JURNAL_MAN;
    FOR V_REC IN (SELECT * FROM TMP_INTRLINK)
    LOOP
      PKG_Jurnal.setDirtyIntrAE(V_REC.CODLINIEAVIZ, aCurs);
      INSERT INTO TMP_JURNAL_MAN(CODDOC, TIPDOC) VALUES(V_REC.CODLINIEAVIZ, 2);

      IF StornoAvize = &apos;1&apos; THEN
        FOR V_REC_STORNO IN (SELECT I1.CODINTR1, I1A.PU AS PRETNOU FROM INTRARI1 I1, INTRARI I, INTRARI1 I1A
                             WHERE
                               I.TIPDOC = 2
                               AND I1.CODINTR = I.CODINTR
                               AND I1.CODINTR1STORNO = V_REC.CODLINIEAVIZ
                               AND I1.CANT &lt; 0
                               AND I1A.CODINTR1 = V_REC.CODLINIEAVIZ
                            )
        LOOP
          PKG_Jurnal.setDirtyINTRAE_Storno(V_REC_Storno.CODINTR1, V_REC_Storno.PRETNOU, aCurs);
        END LOOP;
      END IF;


    END LOOP;
  END IF;


 -- realoc in DOCFREE numarul de document sters
  IF TIPINTR IN (7) OR aAUTOFACTURARE = 1 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;


  -- ObligPIF + GENERAL + STINGERE

  DELETE TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF)
  (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN
     (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR)
   );

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF)
  SELECT CODSTINGERE, CODSTINSPIF FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

-- ordinea de stergere trebuie pastrata pentru a nu viola un constraint
  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);
  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);


  FOR V_REC IN
  (SELECT CODGENERAL
   FROM
     GENERAL G
   WHERE
     CODDOC = RecID AND TIPDOC = TIPINTR
   )
   LOOP
      DELETE FROM GENERAL
      WHERE
       CODGENERAL = V_REC.CODGENERAL;

       FOR V_RECREG IN
       (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
       LOOP
         UPDATE JURNAL1
         SET
           DIRTY = 1
         WHERE
           TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
       END LOOP;
   END LOOP;



--  DELETE FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR;

 UPDATE OBLIGPIF O
  SET
    REST =
      (CASE
         WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END)
  WHERE
    O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);


  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = TIPINTR;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = TIPINTR;


-- reactualizez stocurile implicate in stergerea intrarilor in ROSU
  UPDATE NIRSTOC NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC(NS.CodNir, NS.CodNirStoc, NS.CantNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CodNir, NS.CodNirStoc, NS.CantUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CodNir, NS.CodNirStoc, NS.CantUM2)
  WHERE
    NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);

  UPDATE NIRSER NS
  SET
   Rest    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTNIR),
   RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM1),
   RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM2)
  WHERE
    NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);


  IF TIPINTR = 9 AND ATIPFACTURA &lt;&gt; 9 THEN
  -- am sters factura la aviz; actualizez resturile pe AVIZE
    UPDATE INTRARI1 I1
    SET
     I1.RestFact = i1.Cant -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEAVIZ = I1.CodINTR1
                 AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10))
                 AND II.OPERAT = 1
                 AND II.ANULAT = 0
               ) +
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  INTRARI1 AE1,
                  INTRARI  AE
                WHERE
                  AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                 AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0)
    WHERE
     I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND I1.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1);


  ELSE
  IF (TIPINTR IN (1, 2, 3, 4))OR(TIPINTR = 9 AND ATIPFACTURA = 9) THEN
  --  am sters facturi care sting comenzi; reactualizez restul pe Comenzi
    UPDATE COMANDA1 c1
    SET
     c1.RESTACCEPTAT = c1.CANTACCEPTAT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIECOMANDA = c1.CodComanda1  AND PKG_IESIRI.CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTOPERAT) = 1 /*II.OPERAT = 1*/ AND II.ANULAT = 0
                   )-
               (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    CMDLIVRLINK IL
                    LEFT OUTER JOIN COMANDA1 I1 ON I1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT OUTER JOIN COMANDA   I ON I.CODCOMANDA   = I1.CODCOMANDA
                  WHERE
                    IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                )
    WHERE
    c1.CODCOMANDA1 IN
    (SELECT CODCOMANDA1 FROM TMP_COMANDA1);
  ELSE
    if tipintr = 7 then
      UPDATE CMDPRODMAT c1
      SET
       c1.REST = case when c1.tip = 0 then c1.CCANT else c1.cant end -
                   NVL(( SELECT SUM(IL.CANT)
                     FROM
                      INTRPRODLINK IL
                      LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                      LEFT OUTER JOIN NUM1 ON NUM1.CODUM1 = II1.UMSEC
                      LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                     WHERE
                     IL.CODLINIECOMANDA = c1.Codcmdprodmat  AND II.OPERAT = 1 AND II.ANULAT = 0
                     ), 0)
      WHERE
      c1.CODcmdprodmat IN
      (SELECT CODcomanda1 FROM TMP_comanda1);
    end if;
  END IF;
  END IF;


  IF TIPINTR = 2 THEN -- REACTUALIZEZ RESTURI AVIZE STORNATE
    UPDATE INTRARI1 I1
    SET
    I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                   INTRLINK IL
                   LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                   LEFT OUTER JOIN INTRARI  II  ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODINTR1 AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10))
                 AND II.OPERAT = 1 AND II.ANULAT = 0
                ) +
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  INTRARI1 AE1,
                  INTRARI  AE
                WHERE
                  AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                 AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
    WHERE
     EXISTS (SELECT CODINTR1STORNO FROM INTRARI1_MAN WHERE CODINTR1STORNO = I1.CODINTR1);
  END IF;


  IF TIPINTR = 2 AND aTIPFACTURA = 9 THEN
  -- am sters aviz care stinge facturi in asteptare ; actualizez resturile pe RESTASTEPTARE
  UPDATE INTRARI1 I1
  SET
   I1.RestAsteptare = i1.Cant -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRASTEPTLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEFACTURA = I1.CodINTR1 AND II.TIPDOC = 2  AND II.OPERAT = 1 AND II.ANULAT = 0
               ) +
               (SELECT NVL(SUM(II1.CANT), 0) -- retururi
                FROM
                  INTRARI1 II1
                  INNER JOIN INTRARI II ON II.CODINTR   = II1.CODINTR
                WHERE
                  II1.CANT &lt; 0 AND II1.CODLINIEDOCIMP = I1.CodINTR1 AND II1.TIPDOCIMP = 9 AND II.TIPFACTURA = 9 AND II.OPERAT = 1 AND II.ANULAT = 0
               )

  WHERE
    I1.CodINTR1 IN
     (SELECT CODLINIEFACTURA FROM TMP_INTRASTEPTLINK );

  END IF;

 IF TIPINTR = 9 AND aTIPFACTURA = 9 THEN
  -- am sters O factura in  asteptare care e posibil sa contina retururi; calculez resturile liniilor returnate
  FOR V_REC IN (SELECT CODLINIEDOCIMP FROM INTRARI1_MAN WHERE NVL(CODLINIEDOCIMP, 0) &lt;&gt; 0 AND TIPDOCIMP = 9 AND CANT &lt; 0)
  LOOP
      UPDATE INTRARI1 I1
      SET
        I1.RestAsteptare = i1.Cant -
                   ( SELECT NVL(SUM(IL.CANT), 0)
                     FROM
                      INTRASTEPTLINK IL
                      LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                      LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                     WHERE
                     IL.CODLINIEFACTURA = I1.CodINTR1 AND II.TIPDOC = 2  AND II.OPERAT = 1 AND II.ANULAT = 0
                   ) +
                   (SELECT NVL(SUM(II1.CANT), 0) -- retururi
                    FROM
                      INTRARI1 II1
                      INNER JOIN INTRARI II ON II.CODINTR   = II1.CODINTR
                    WHERE
                      II1.CANT &lt; 0 AND II1.CODLINIEDOCIMP = I1.CodINTR1 AND II1.TIPDOCIMP = 9 AND II.TIPFACTURA = 9 AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
      WHERE
        I1.CodINTR1 = V_REC.CODLINIEDOCIMP;
  END LOOP;
END IF;


 /* IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRARIF&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRARIP&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIP WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRPF&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRPF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRSUB&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRSUB WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRFAST&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRFAST WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRARIAE&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIAE WHERE CODINTR = &apos; || RECID;
  END IF;


  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRARIFA&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIFA WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRAST&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRAST WHERE CODINTR = &apos; || RECID;
  END IF;
  IF PKG_LIST_STRUCT.TMPEXISTS(&apos;INTRARICF&apos;) &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM INTRARICF WHERE CODINTR = &apos; || RECID;
  END IF;
*/

  IF TIPINTR = 1 THEN
    UPDATE CONTRACT2
    SET CODDOC  = NULL,
        TIPDOC  = NULL,
        NRDOC   = NULL,
        DATADOC = NULL
    WHERE CODDOC = RecID AND TIPDOC = TIPINTR;
    UPDATE CONTRACT0
    SET FACTURAT= 0,
        CODDOC  = NULL,
        TIPDOC  = NULL,
        NRDOC   = NULL,
        DATADOC = NULL
    WHERE CODDOC = RecID AND TIPDOC = TIPINTR;
  END IF;

  DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPINTR);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPINTR;

  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = TIPINTR)or(CODDOCASOC = RECID AND TIPDOCASOC = TIPINTR);
  DELETE FROM Reclamatii WHERE CODDOC = RECID AND TIPDOC = TIPINTR;


  UPDATE IESIRI SET CodAECustodie = NULL WHERE NVL(CodAECustodie, 0) = RECID;

  NotifyModif(2, RecId, &apos;INTRARI&apos;);
  COMMIT;
END;



PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_INTRARI FIELDS( CodIntr ) VALUES (0) ;
  DELETE TMP_DIN_CANTARIRI;
  PKG_CFGTABLES.EXT_INSERTRECORD(PKG_GLOBALS.GetTipIntrare);
  COMMIT;
END;



FUNCTION GET_VALOARE_PROD(aCodcomanda1 in number) return number is
  iResult number(20,6);
  TipCoefIndirecte number(20,6);
  aAn number(4);
  aLuna number(2);
begin
	 begin
		 SELECT NVL( SUM((nvl(NS.PRET,0) - nvl(NS.ADAOS,0)) * L1.CANT * (NVL(C1.COEFINDIRECTE,0)+1))  ,0) INTO IRESULT
		 FROM   IESIRI1     IES,
						LIVR1       L1,
						LIVR        L,
						NIRSTOC     NS
						INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
						LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
						COMANDA1    C1
		 WHERE  IES.CODCMDINT1 = aCodcomanda1
			 AND  IES.CODIES1 = L1.CODIES1
			 AND  L.CODLIVR = L1.CODLIVR
			 AND  L.TIPLIVR = 24
			 AND  L1.CODNIRSTOC = NS.CODNIRSTOC
			 AND  C1.CODCOMANDA1 = IES.CODCMDINT1
			 AND  NVL(DVI.TIPIMPORT,0) = 0;
	 exception when others then IRESULT := 0;
	 end;
   return NVL(iResult,0);
end;

FUNCTION GET_REGIE_FIXA(aCodObiect in number) return number is
  iResult number(20,6);
begin
	 begin
      SELECT ValRegie INTO IRESULT
      FROM NARTOBJ1 OBJ1
      WHERE OBJ1.CodObiect = aCodObiect
       AND PKG_GLOBALS.ANLUNALUCRU BETWEEN OBJ1.ALSTART AND OBJ1.ALSTOP;
	 exception when others then IRESULT := 0;
	 end;
   return NVL(iResult,0);
end;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  TIPINTR      NUMBER(20) := 0;
  aCODPART     NUMBER(20) := 0;
  aRotEFact    NUMBER(1);
	ANPREC       NUMBER(5);
  LUNAPREC     NUMBER(2);
  aTIPFACTURA  INTEGER := 0;
  aCodLinieFurn NUMBER(20) := 0;
  aDATADOC     DATE ;
  aDataRef     date;
  LUNAREF      PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
  IOPART1REC   IOPART1 % ROWTYPE;
  aCODSUBUNITSTINS  NUMBER(20);
  TIPPREFIX    VARCHAR2(10);
  CateLinii    NUMBER(20);
  aCURS        NUMBER(20, 7);
  vCount NUMBER(10);
  aTIPTRANZACTIE INTEGER := 0;
	DenLaClient  VARCHAR2(10);
  aANLUCRU     NUMBER;
  aLUNALUCRU   NUMBER;
  aCODSUBUNIT  NUMBER;
  aVanzUMAltUMSec varchar2(5);
  aPU         number(20, 7);
  aPretFurn   number(20, 7);
  aPUFara     number(20, 7);
  aAdaos      number(20, 7);
  aSUBUNIT    number(20);
  aROTPRET    number(2);

BEGIN
  -- Master INTRARI
  --pkg_globals.SetLunaLucru(2008,10);

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  aANLUCRU     := PKG_GLOBALS.ANLUCRU;
  aLUNALUCRU   := PKG_GLOBALS.LUNALUCRU;
  aCODSUBUNIT  := PKG_GLOBALS.GETSUBUNITATE;


  DELETE TMP_MANEVRA;
  DELETE TMP_DIN_CANTARIRI;

  INSERT INTO  TMP_INTRARI (
    CodIntr,   TipDoc, Anulat, Blocat,  Operat, PrefixDoc, NrDoc, DataDoc, Partener, NrAviz,
    CarnetDoc, ValDoc, TVADoc, Majorari, An,    Luna,      Obs,   Satelit, Complex, CODSUBUNIT,
    CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE,
    TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA, TIPTVA, CODCONTRACT,
    MONEDA,
    CURS,
    SCADENTESETATEMANUAL,
    SCHIMB,
    CODFORMATIE,
    DELEGAT,
    NUMEDELEGAT,
    CODAUTO,
    ExclusPlata,
    FaraReg, TVAINCASARE, TVAINCASARE_F,
    UserID,
    PARTCOMUNITAR,
    SIMBAUTOTARA,
    CodAnaliza,
    ProRata,
    CURSDOC,
    Custodie, Transportator,
    VALTRANSPORT,
    FACTSIMPLIF,
    AGENT,
    CURSNIR,
    STADIUWMS,
    DATAREFSCAD, DATATVA,
    AUTOFACTURARE,
    TIPLIVRARE,
    NATURATRANZ,
    MODTRANSP, ORDONANTAT, EXPORTKLG, EXPORTATKLG,
    SPLITTVA,
    PROCSTOPAJ, TipSAFT, RotEFact, TipET,  UIT, ET_IDINCARCARE, ET_IDDESCARCARE, ET_TIPMEDIU, ET_STATUS,
		is_etransp,
		EF_IDINCARCARE, EF_IDDESCARCARE,  EF_TIPMEDIU, EF_Status,
    iddescarcare,
    ValDocEFACT, Aprobat
    )
  SELECT
    CodIntr,   I.TipDoc, Anulat, Blocat,  Operat, PrefixDoc, NrDoc, DataDoc, Partener, NrAviz,
    CarnetDoc, ValDoc, TVADoc, Majorari, I.An,    I.Luna,      I.Obs,   Satelit, Complex, I.CODSUBUNIT,
    I.CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE,
    TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA, TIPTVA,CODCONTRACT,
    MONEDA, CURS, 1, SCHIMB,
    CODFORMATIE,
    I.DELEGAT,
    NVL((SELECT DELEGAT FROM NPARTTR WHERE CODPARTTR = I.DELEGAT), &apos;&apos;),
    CODAUTO,
    ExclusPlata,
    FaraReg, TVAINCASARE, TVAINCASARE_F,
    UserID,
    T.STATCOMUNITAR,
    T.SIMBAUTO,
    I.Codanaliza,
    I.ProRata,
    I.CURSDOC,
    I.Custodie, I.Transportator,
    I.VALTRANSPORT,
    I.FACTSIMPLIF,
    I.AGENT,
    I.CURSNIR,
    I.STADIUWMS,
    NVL(I.DATAREFSCAD,I.DATADOC), I.DATATVA,
    AUTOFACTURARE,
    TIPLIVRARE,
    NATURATRANZ,
    MODTRANSP, ORDONANTAT, EXPORTKLG, EXPORTATKLG,
    SPLITTVA,
    PROCSTOPAJ, Coalesce(TipSAFT, 0), Coalesce(RotEFact,0),
    TipET, ET.UIT, ET.IDINCARCARE, ET.IDDESCARCARE, ET.TIPMEDIU, Coalesce(ET.STARE,&apos;?&apos;), is_etransp,
		E.IDINCARCARE, E.IDDESCARCARE,  E.TIPMEDIU, Coalesce(E.STARE,&apos;?&apos;),
    i.iddescarcare,
    i.ValDocEFACT, I.Aprobat
  FROM
    INTRARI I
    LEFT OUTER JOIN NAGENDA  A ON A.CODAGENDA  = I.CODLOCATIE
    LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT OUTER JOIN NTARI    T ON T.CODTARA    = L.CODTARA
    LEFT OUTER JOIN StatusDecl E ON E.CodDoc = I.CodIntr and E.TipDoc = I.TipDoc
    LEFT OUTER JOIN StatusDecl ET ON ET.CodDoc = I.CodIntr and ET.TipDoc = 100+I.TipDoc
  WHERE
    CodIntr = RecId;

  select count(1) into vCount from dvi where codintr = recid;
  if vCount = 0 then
    Insert into TMP_DVI (Coddvi, Codintr, tipimport) select -1, Recid, 0 from tmp_intrari;
  else
    Insert into TMP_DVI (Coddvi, Codintr, Tipimport) select Coddvi, Codintr, Tipimport from DVI where CodIntr = RecID;
  end if;

  aCURS := 1;
	aRotEFact := 0;
  if RecId &gt; 0 then
    SELECT TIPDOC, PARTENER, RotEFact, NVL(TIPFACTURA, 0), DECODE(NVL(CURS, 1), 0, 1, NVL(CURS, 1)), NVL(TIPTRANZACTIE, 0), DATAREFSCAD, SUBUNITATEA
    INTO TIPINTR, aCODPART, aRotEFact, aTIPFACTURA, aCURS, aTipTranzactie, aDataRef, aSUBUNIT
    FROM TMP_INTRARI;
  end if;

  BEGIN
    SELECT DATADOC, CURS INTO aDATADOC, CURS_IN FROM TMP_INTRARI;
    EXCEPTION WHEN OTHERS THEN aDATADOC := TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;);
  END;

 DELETE INTRARI1_MAN;
 INSERT INTO INTRARI1_MAN (SELECT * FROM INTRARI1 WHERE CODINTR = RECID);

/*
 -- daca e aviz, pun pe nraviz info despre aviz PRELUAT pe DVI
 if TIPINTR = 2 then
   select Count(*) into CateLinii from IntrLink k, INTRARI1_MAN i1m, intrari1 i1, intrari i
   where k.codlinieaviz = i1m.CodIntr1 and i1.CodIntr1 = k.Codintr1 and i.Codintr = i1.Codintr1 and i.TipDoc = 5;
   update tmp_intrari set NrAviz = CateLinii;
 end if;
*/

 -- fisa mas
 if TIPINTR = 7 then
   INSERT INTO TMP_FISAMAS
      (
       CODFISAMAS    ,
       CODINTR1      ,
       NRDOC         ,
       DATADOC       ,
       CODRESPONSABIL,
       CODINSPECTOR  ,
       OBS           ,
       APROBAT       ,
       CARNETDOC     ,
       SERIADOC      ,
       HFACTOR       ,
       CodObiect     ,
       CodProdComp   ,
       CARNETDOC_I   ,
       NRDOC_I
      )
    (SELECT
       F.CODFISAMAS    ,
       F.CODINTR1      ,
       F.NRDOC         ,
       F.DATADOC       ,
       F.CODRESPONSABIL,
       F.CODINSPECTOR  ,
       F.OBS           ,
       F.APROBAT       ,
       F.CARNETDOC     ,
       F.SERIADOC      ,
       PC.HFACTOR      ,
       I1.CodObiect    ,
       C1.CodReteta    ,
       F.CARNETDOC     ,
       F.NRDOC
     FROM FISAMAS F
          LEFT JOIN INTRARI1 I1 on I1.CodIntr1 = F.CodIntr1
          LEFT JOIN INTRPRODLINK L on L.CodIntr1 = I1.CodIntr1
          LEFT JOIN CMDPRODMAT CMD on CMD.CodCmdProdMat = L.CODLINIECOMANDA
          LEFT JOIN COMANDA1 C1 on CMD.CodComanda1 = C1.CODCOMANDA1
          LEFT JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
     WHERE I1.CODINTR = RecId);

     INSERT INTO TMP_FISAMAS1
      (
        CODFISAMAS1,
        CODFISAMAS ,
        CODPRODMAS ,
        VALOARE    ,
        STARE      ,
        OBS        ,
        DESCRIERE  ,
        FRECVENTA  ,
        METODA     ,
        CODObiect  ,
        INDEXLOCAL ,
        Denumire
      )
    (SELECT
        F1.CODFISAMAS1,
        F1.CODFISAMAS ,
        F1.CODPRODMAS ,
        F1.VALOARE    ,
        F1.STARE      ,
        F1.OBS        ,
        PM.DESCRIERE  ,
        PM.FRECVENTA  ,
        PM.METODA     ,
        PM.CODObiect  ,
        PM.INDEXLOCAL ,
        OBJ.Denumire
     FROM FISAMAS1 F1
          LEFT JOIN PRODMAS PM ON PM.CODPRODMAS = F1.CODPRODMAS
          LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = PM.CODOBIECT
          LEFT JOIN FISAMAS F ON F1.CODFISAMAS = F.CODFISAMAS
          LEFT JOIN INTRARI1 I1 on I1.CodIntr1 = F.CodIntr1
     WHERE I1.CODINTR = RecId);
  end if;

  INSERT INTO  TMP_INTRARI1 (
    CodIntr1, CodIntr, IndexLocal, TipLinie, Umsec, An, Luna,
    ContServ, CONTDISCOUNT, ZILE, ZILECMD, GestAct, CodObiect, PretOrig, PU,
    Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, CODAUTO, TVANEDED, PARITATEORIG, COEFDISCMAJ, OBS,
    RestFact, NrCertif, CODCMD1AE,  TG, PUMaximal, AdMax, PURidicata, ProcAdaos,
    FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS,
    DenUM, Valoare, Paritate, ProcTVA,
    GestImplicita, ARETG, CERTIFICAT,
    CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, TIPPRETMAX, DenObiect,
    CODMIFIX, CODINTR1STORNO, PRELUAT, CUSTODIE, CodOferta1,CODCENTRU,
    COEFUM_CANTAR, CONTASTEPTARE, CODCMDINT1, codcontract1, Taxa,  ROTVALTAXA,  TERMENCONTRACT, ICONTPART,
		SimbolIOPart, PRETUM1,
		CMDINT, Contract, CODANALIZANOD,
    CODEXTERN, CODINTERN, D1, D2, D3, RELATIEUM1, UM1, CODINTR1LINK, CODNIMOB, CODVAMAL, CODLINIEDOCIMP, TIPDOCIMP,
		IMPOZABIL,GESTPRODAVIZSUB,RESTASTEPTARE,TAXCODE, CODCPV, RISCFISCAL,
    cod_catalog)
  SELECT
    i1.CodIntr1, i1.CodIntr, i1.IndexLocal, i1.TipLinie, i1.Umsec, i1.An, i1.Luna,
    i1.ContServ, i1.CONTDISCOUNT, I1.ZILE, I1.ZILECMD,  i1.GestAct, i1.CodObiect, i1.PretOrig * NVL(u1.Paritate, 1), i1.PU * NVL(u1.Paritate, 1),
    i1.Cant/ NVL(u1.Paritate, 1), i1.TVA, i1.AdDim, I1.MIFIX, I1.CODOBIECTORIG, I1.CODAUTO, I1.TVANEDED, I1.PARITATEORIG, I1.COEFDISCMAJ, I1.OBS,
    i1.RestFact, i1.NrCertif, I1.CODCMD1AE, i1.TG, i1.PUMaximal, AdMax, i1.PURidicata, i1.procadaos,
    i1.FURNAVIZSUBUNIT,  I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
    CASE WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos; ELSE u1.Den_UM1 END,
    CASE WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;)
		  THEN  CASE WHEN aRotEFact = 1 THEN Round(i1.Cant * i1.PU,2) ELSE i1.Cant * i1.PU END ELSE I1.RESTFACT
		END,
    u1.Paritate,
    CASE WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol, AANLUCRU, ALUNALUCRU) ELSE 0 END,
    (SELECT GESTIMPLICITA FROM NARTIMPLICITE AI WHERE CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = DECODE(aCODSUBUNIT, 1, NVL(AI.CODSUBUNIT, 1), aCODSUBUNIT) AND ROWNUM = 1),
    A.ARETG, A.CERTIFICAT,
    NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, NARTOBJ1LUNA.TIPPRETMAX, O.DENUMIRE,
    I1.CODMIFIX, I1.CODINTR1STORNO, PRELUAT, CUSTODIE, I1.CodOferta1, I1.CODCENTRU,
    CASE WHEN Nvl(u.tipum,0) = 1 THEN u.coef ELSE 0 END COEFUM_CANTAR,
    I1.CONTASTEPTARE, I1.CODCMDINT1, I1.codcontract1, I1.Taxa, I1.ROTVALTAXA, I1.TERMENCONTRACT,
		I1.ICONTPART,
		PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG( 0, I1.ICONTPART, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(aCODPART,AANLUCRU, ALUNALUCRU))),
		I1.PRETUM1, c.nrdoc, ctr.NrDoc, I1.CODANALIZANOD, O.CODEXTERN,
    O.CODINTERN,
    A.D1, A.D2, A.D3, A.RELATIEUM1, A.UM1,
    I1.CODINTR1LINK, I1.CODNIMOB, O.CODVAMAL,
    I1.CODLINIEDOCIMP, I1.TIPDOCIMP, I1.IMPOZABIL, i1.GESTPRODAVIZSUB,I1.RESTASTEPTARE,X.TAXCODE, O.CODCPV, COALESCE(A.RISCFISCAL,0),
    A.CODEXTERNART || case when coalesce(A.SUFIXCODEXTERN,&apos;&apos;) = &apos;&apos; then &apos;&apos; else  &apos;_&apos;|| A.SUFIXCODEXTERN end
  FROM INTRARI1_MAN i1
    LEFT OUTER JOIN NartObj o ON o.CodObiect  = i1.CodObiect
    LEFT OUTER JOIN Nart a    ON a.CodArticol = o.CodArticol
    LEFT OUTER JOIN NUM1 u1   ON u1.CodUM1    = i1.UmSec
    LEFT OUTER JOIN NUM u     ON u.CodUM      = a.Um
    LEFT OUTER JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
    LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
    LEFT OUTER JOIN comanda1 c1 ON i1.codcmdint1 = c1.codcomanda1
    LEFT OUTER JOIN comanda   c ON c1.codcomanda = c.codcomanda
    LEFT OUTER JOIN contract1 ctr1 ON i1.codcontract1 = ctr1.codcontract1
    LEFT OUTER JOIN contract  ctr ON  ctr1.codContract = ctr.codContract
		LEFT JOIN TAXDECL X ON X.TipDoc = TipIntr and X.CODDOC = RecID and X.Coddoc1 = I1.CodIntr1
  WHERE i1.CodIntr = RecId
  ORDER BY i1.IndexLocal;


/*
  for v_rec in (select codintr1 from TMP_INTRARI1 ) loop

    select count(*) into vCount from fisamas where codintr1 = v_rec.codintr1;
    if vCount &gt; 0 then
      UPDATE TMP_INTRARI1
      SET
        FISAMASURATORI = (SELECT FM.NrDoc||&apos;/&apos;||FM.DataDoc
                          FROM FISAMAS FM WHERE FM.CODINTR1 = v_rec.CODINTR1 AND ROWNUM = 1)
      where codintr1 = v_rec.codintr1;
    end if;

  end loop;
*/

  for v_rec in (select FM.* from TMP_INTRARI1 I1 INNER JOIN fisamas FM ON FM.CODINTR1 = I1.CODINTR1 ) loop

      UPDATE TMP_INTRARI1
      SET
        FISAMASURATORI = V_REC.NRDOC || &apos;/&apos; || V_REC .DataDoc
      where codintr1 = v_rec.codintr1;
  end loop;



  UPDATE TMP_INTRARI1
  SET
    DENOBIECT = CASE
                  WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) = 0 AND CANT &lt;= 0 THEN &apos;Discount distribuit pe grupul de articole precedent&apos;
                  WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) = 0 AND CANT  &gt; 0 THEN &apos;Majorare distribuita pe grupul de articole precedent&apos;

                  WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount direct pe cont (de grup)&apos;
                  WHEN TIPLINIE = &apos;G&apos; AND NVL(CONTDISCOUNT, 0)&lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de grup)&apos;

                  WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) = 0  AND CANT &lt;= 0 THEN &apos;Discount distribuit pe toate articolele precedente&apos;
                  WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) = 0  AND CANT  &gt; 0 THEN &apos;Majorare distribuita pe toate articolele precedente&apos;


                  WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT &lt;= 0 THEN &apos;Discount direct pe cont (de total)&apos;
                  WHEN TIPLINIE = &apos;T&apos; AND NVL(CONTDISCOUNT, 0) &lt;&gt; 0 AND CANT  &gt; 0 THEN &apos;Majorare direct pe cont (de total)&apos;
                END,
    SIMBOLCONTSERV = CASE
                  WHEN  NVL(CONTDISCOUNT, 0) &lt;&gt; 0 THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(NVL(CONTDISCOUNT, 0)) || &apos;)&apos;
                  ELSE &apos;&apos;
                END
  WHERE TIPLINIE IN (&apos;G&apos;, &apos;T&apos;);

  UPDATE TMP_INTRARI1 I1
  SET
    SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;,
    ESTEIMBMF      = (SELECT PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(I1.CONTSERV) FROM DUAL),
    INFOMF         = CASE
                       WHEN NVL(I1.CODMIFIX, 0) &lt;&gt; 0 THEN
                        (SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE
                         FROM MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NARTOBJ O
                          WHERE MF.CODMIFIX = I1.CODMIFIX
                            AND MF.CODMIFIX = MF1.CODMIFIX
                            AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                            AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                            AND O.CODOBIECT = NS.CODOBIECT)
                       WHEN NVL(I1.CODOBIECTORIG, 0) &lt;&gt; 0 THEN (SELECT DENUMIRE FROM NARTOBJ WHERE CODOBIECT = I1.CODOBIECTORIG)
                       ELSE NULL
                     END
  WHERE UPPER(TIPLINIE) IN (&apos;S&apos;, &apos;V&apos;, &apos;R&apos;);

  UPDATE TMP_INTRARI1 I1
  SET INFOMF = (SELECT NRINREG FROM NPARCAUT WHERE CODNPARCAUT = I1.CODAUTO)
  WHERE UPPER(TIPLINIE) = &apos;=&apos; AND Nvl(I1.CODAUTO, 0) &lt;&gt; 0;

  UPDATE TMP_INTRARI1 I1
  SET
    SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;
  WHERE UPPER(TIPLINIE) IN (&apos;=&apos;) AND TIPINTR = 9 AND aTIPFACTURA = 9;

  /*UPDATE
    TMP_INTRARI1 I1
  SET
    I1.CantUM2 = (SELECT SUM(C.Net_Kg) FROM CANTAR C WHERE C.TipDoc = TIPINTR AND C.CodDoc1 = I1.CodIntr1)
  WHERE
    I1.PRELUAT = 1;

  if aTIPFACTURA = 9 then*/
    UPDATE
      TMP_INTRARI1 I1
    SET
      I1.CantUM2 = (SELECT ns.cantum2 FROM nirstoc ns WHERE ns.codintr1 = i1.codintr1 and rownum = 1)
    WHERE
      I1.PRELUAT = 2;
  /*else
    UPDATE
      TMP_INTRARI1 I1
    SET
      I1.CantUM2 = (SELECT SUM(B.NetKg) FROM BCAR B WHERE B.TipDoc = TIPINTR AND B.CodDoc1 = I1.CodIntr1)
    WHERE
      I1.PRELUAT = 2;
  end if;*/

  IF TIPINTR IN (1,2,9) THEN
    for v_rec in (select i1.codintr1, cli.denumire, cli.codextern
                  from tmp_intrari1 i1
                       inner join nartcli cli on cli.codobiect = i1.codobiect
                  where cli.codpart = aCodpart) loop
      update tmp_intrari1 set denlapart = v_rec.denumire, codexternlapart = v_rec.codextern where codintr1 = v_rec.codintr1;
    end loop;
    for v_rec in (select i1.codintr1, cli.denumire, cli.codextern
                  from tmp_intrari1 i1
                       inner join nartcli cli on cli.codobiect = i1.codobiect
                       inner join nclasep cls on cli.codclasep = cls.codclasep
                       inner join npart p on cls.codclasep = p.codclasa
                  where p.codpart = aCodpart and cls.codclasep &gt; 0) loop
      update tmp_intrari1 set denlapart = v_rec.denumire, codexternlapart = v_rec.codextern where codintr1 = v_rec.codintr1;
    end loop;
  END IF;

  IF RECID &gt; 0 THEN

    IF  TIPINTR = 9 THEN
       IF aTIPFACTURA &lt;&gt; 9 THEN
         UPDATE TMP_INTRARI1 I1
         SET NRDOCLINK = (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
                          FROM
                            INTRLINK IL
                            LEFT OUTER JOIN INTRARI1 II1 ON II1.CodINTR1 = IL.CODLINIEAVIZ
                            LEFT OUTER JOIN INTRARI  II ON II.CodINTR    = II1.CODINTR
                          WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND IL.CODINTR1 = I1.CODINTR1
                          );
       ELSE
         UPDATE TMP_INTRARI1 I1
         SET
         NRDOCLINK =
         CASE
           WHEN I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) THEN ( SELECT CC.PREFIXDOC || &apos; &apos; || CC.SERIADOC || TO_CHAR(CC.NRDOC)
                                                 FROM
                                                  INTRLINK IL
                                                  LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CodComanda1 = IL.CODLINIECOMANDA
                                                  LEFT OUTER JOIN COMANDA  CC  ON CC.CodComanda   = CC1.CODCOMANDA
                                                  WHERE IL.CODINTR1 = I1.CODINTR1
                                                )

           END
           WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
       END IF;
    ELSE
     IF TIPINTR IN (1, 2, 3, 4) THEN -- LINII CE STING COMENZI
        IF TIPINTR = 2 AND ATIPFACTURA = 9 THEN
         UPDATE TMP_INTRARI1 I1
         SET NRDOCLINK = (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
                          FROM
                            INTRASTEPTLINK IL
                            LEFT OUTER JOIN INTRARI1 II1 ON II1.CodINTR1 = IL.CODLINIEFACTURA
                            LEFT OUTER JOIN INTRARI  II ON II.CodINTR    = II1.CODINTR
                          WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND IL.CODINTR1 = I1.CODINTR1
                          );

        ELSE
          UPDATE TMP_INTRARI1 I1
          SET
          NRDOCLINK =
          CASE
            WHEN I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) THEN ( SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                                                  FROM
                                                   INTRLINK IL
                                                   LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CodComanda1 = IL.CODLINIECOMANDA
                                                   LEFT OUTER JOIN COMANDA  CC  ON CC.CodComanda   = CC1.CODCOMANDA
                                                   WHERE IL.CODINTR1 = I1.CODINTR1
                                                 )

            END
            WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
        END IF;
       ELSE
       IF TIPINTR = 6 THEN
         UPDATE TMP_INTRARI1 I1
         SET
         NRDOCLINK =  (SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                      FROM
                       COMANDA1 CC1 , COMANDA CC WHERE CC1.CodComanda1 = I1.CODCMD1AE
                       AND CC.CodComanda   = CC1.CODCOMANDA);

       ELSE
         IF TIPINTR IN (7) THEN -- LINII CE STING COMENZI
         UPDATE TMP_INTRARI1 I1
         SET
         NRDOCLINK =
         CASE
           WHEN I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) THEN ( SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                                                 FROM
                                                  INTRPRODLINK IL
                                                  LEFT OUTER JOIN CMDPRODMAT MAT ON MAT.Codcmdprodmat = IL.CODLINIECOMANDA
                                                  LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CodComanda1 = MAT.CODCOMANDA1
                                                  LEFT OUTER JOIN COMANDA  CC  ON CC.CodComanda   = CC1.CODCOMANDA
                                                  WHERE IL.CODINTR1 = I1.CODINTR1
                                                )

           END
           WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);
         END IF;
       END IF;
     END IF;
    END IF;
  END IF;

  IF TIPINTR = 7 and aTipTranzactie = 10 THEN
    UPDATE TMP_INTRARI1 I1
    SET
    INDEXINTERVENTIE = (SELECT U2C.INDEXC
                        FROM
                          INTRPRODLINK L
                          INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                          INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                        WHERE L.CodINTR1 = I1.CODINTR1
                         ),
    INDEXEDITABIL = 0,
    UTILAJ = (SELECT OBJ.DENUMIRE
              FROM
                INTRPRODLINK L
                INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                INNER JOIN UTILAJE U ON U2C.CODUTILAJ = U.CODUTILAJ
                INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = U.CODOBIECT
              WHERE L.CodINTR1 = I1.CODINTR1
             ),
    DATASTARTS = (SELECT to_char(u2c.datastart, &apos;DD.MM.YYYY HH24:MI&apos;)
                 FROM
                   INTRPRODLINK L
                   INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                   INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                 WHERE L.CodINTR1 = I1.CODINTR1),
    DATAENDS = (SELECT to_char(u2c.dataend, &apos;DD.MM.YYYY HH24:MI&apos;)
                 FROM
                   INTRPRODLINK L
                   INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                   INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                 WHERE L.CodINTR1 = I1.CODINTR1),
    DATASTART = (SELECT u2c.datastart
                 FROM
                   INTRPRODLINK L
                   INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                   INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                 WHERE L.CodINTR1 = I1.CODINTR1),
    DATAEND = (SELECT u2c.dataend
                 FROM
                   INTRPRODLINK L
                   INNER JOIN CMDPRODMAT PROD ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
                   INNER JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = PROD.CODCOMANDA1
                 WHERE L.CodINTR1 = I1.CODINTR1)             ;
  END IF;

  if TIPINTR = 1 THEN
    FOR V_REC IN (SELECT TMP.CODINTR1, C.CODCENTRALIZARE
                  FROM TMP_INTRARI1 TMP
                       INNER JOIN NOTECREDITFACT F ON F.CODDOC1 = TMP.CODINTR1
                       INNER JOIN CENTRALIZARENC C ON C.CODNCREDIT = F.CODNCREDIT AND C.CODOBIECT = TMP.CODOBIECT AND TMP.PROCTVA = C.PROCTVA
                  WHERE F.TIPDOC = 1 AND
                        C.CODOBIECTASOC = TMP.CODOBIECTORIG
                 ) LOOP
      UPDATE TMP_INTRARI1 SET CODCENTRALIZARE = V_REC.CODCENTRALIZARE WHERE CODINTR1 = V_REC.CODINTR1;
    END LOOP;
  END IF;

 -- GENERAL
 INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg)
 (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, ExclusPlata, DataTVA, FaraReg FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TipIntr);

-- pregatest pentru calcul solduri
  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, ANPREC, LUNAPREC);
  PKG_GLOBALS.SETLUNAPRECEDENTA(ANPREC, LUNAPREC);
  PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(aCODPART);


-- PREIAU DIN TMP_GENERAL MONEDA SI CURSUL + ALTE CAMPURI ADAUGATE
  UPDATE TMP_INTRARI I
  SET
    --SOLDPART  = NVL((SELECT -1 * SUM(SOLDLEI) FROM V_SOLDPART WHERE CODPART = I.PARTENER), 0),
    SCADENTAC = NVL((SELECT SCADENTAC FROM NPART WHERE CODPART = I.PARTENER), 0);

-- OBLIGPIF
 INSERT INTO TMP_OBLIGPIF
 (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, ZILE,CODANALIZANOD, DINCARETVA, SPLITTVA)
 (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT,
 TRUNC(TERMEN - aDATAREF),CODANALIZANOD, DINCARETVA, SPLITTVA
 FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));


  -- pun Procent in OBLIGPIF- versiune cu grupare pe icont
/*
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, ICONT, VALOARE)
  SELECT COUNT(*), ICONT, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (100, 110, 120, 140) GROUP BY ICONT  ;

  UPDATE TMP_OBLIGPIF O
  SET
    PROCENT =
   (
    CASE
      WHEN TOTAL_VALOARE_ICONT(O.ICONT) = 0  THEN 100 / TOTAL_COUNT_ICONT(O.ICONT)
      WHEN TOTAL_VALOARE_ICONT(O.ICONT) &lt;&gt; 0 THEN 100 * VALOARE / TOTAL_VALOARE_ICONT(O.ICONT)
    END
    )
  WHERE
  SEMNIFICATIE IN (100, 110, 120, 140);
*/
 -- pun Procent in OBLIGPIF -- versiune cu grupare pe semnif
 
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL(CODOBLIGPIF, SEMNIFICATIE, VALOARE)
  SELECT COUNT(*), SEMNIFICATIE, SUM(VALOARE) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (100, 110, 120, 140) GROUP BY SEMNIFICATIE ;

 
  UPDATE TMP_OBLIGPIF O
  SET
    PROCENT =
      (
    CASE
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) = 0  THEN 100 / TOTAL_COUNT_SEMNIF(O.SEMNIFICATIE)
      WHEN TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE) &lt;&gt; 0 THEN 100 * O.VALOARE /  TOTAL_VALOARE_SEMNIF(O.SEMNIFICATIE)
    END
    ) 
   WHERE
    SEMNIFICATIE IN (100, 110, 120, 140);






  UPDATE TMP_OBLIGPIF O
  SET
    PROCTVAAVANS = (SELECT PROCTVAAVANS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL)
  WHERE
  SEMNIFICATIE IN (110, 120 );


 -- STINGERE
 INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
 (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));




 UPDATE TMP_OBLIGPIF O
 SET
 (TVA, CURS) = (SELECT TVA, CURS FROM TMP_GENERAL WHERE CODGENERAL = O.CODGENERAL);

 -- memorez starea la intrare a obligatiilor necesara la interfata STORNO FACTURA
   DELETE TMP_OBLIGPIF_INITIAL;
   INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF);
   DELETE TMP_STINGERE_INITIAL;
   INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE);



     IF TIPINTR IN (1, 2, 3, 4, 5) THEN -- LINII CE STING COMENZI
      UPDATE TMP_INTRARI1 I1
        SET
        NRDOCLINK =
        CASE
          WHEN NVL(CODOBLIGSTORNO, 0) = 0  THEN &apos;Avans &apos;
          WHEN NVL(CODOBLIGSTORNO, 0) &lt;&gt; 0 THEN &apos;Storno &apos; ||
            NVL((
             SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; ||  TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
             FROM
              TMP_STINGERE S,
              OBLIGPIF O,
              GENERAL G,
              INTRARI I
             WHERE
              S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND
              S.CODSTINSPIF     =  O.CODOBLIGPIF AND
              G.CODGENERAL = O.CODGENERAL AND
              I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC), &apos;&apos;)
        END
      WHERE
      TIPLINIE = &apos;V&apos;;


      UPDATE TMP_INTRARI1 I1
        SET
        NRDOCLINK =
        CASE
          WHEN NVL(CODOBLIGSTORNO, 0) = 0  THEN &apos;Garantie &apos;
          WHEN NVL(CODOBLIGSTORNO, 0) &lt;&gt; 0 THEN &apos;Storno garantie &apos; ||
            NVL((
             SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; ||  TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
             FROM
              TMP_STINGERE S,
              OBLIGPIF O,
              GENERAL G,
              INTRARI I
             WHERE
              S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND
              S.CODSTINSPIF     =  O.CODOBLIGPIF AND
              G.CODGENERAL = O.CODGENERAL AND
              I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC), &apos;&apos;)
        END
      WHERE
      TIPLINIE = &apos;R&apos;;

    END IF;

     IF TIPINTR = 9 THEN -- facturi la aviz care contin storn avans
      UPDATE TMP_INTRARI1 I1
        SET
        NRDOCLINK = &apos;Storno &apos; ||
            NVL((
             SELECT I.PREFIXDOC || I.NRDOC || &apos;/&apos; ||  TO_CHAR(I.DATADOC, &apos;dd.mm.yyyy&apos;)
             FROM
              TMP_STINGERE S,
              OBLIGPIF O,
              GENERAL G,
              INTRARI I
             WHERE
              S.CODSTINGATORPIF = I1.CODOBLIGSTORNO AND
              S.CODSTINSPIF     =  O.CODOBLIGPIF AND
              G.CODGENERAL = O.CODGENERAL AND
              I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC), &apos;&apos;)
      WHERE
      TIPLINIE = &apos;V&apos; AND COALESCE(I1.CODOBLIGSTORNO, 0) &lt;&gt; 0;
    END IF;


 -- Detail INTRLINK
 INSERT INTO TMP_INTRLINK
 (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT)
 (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT
 FROM
 INTRLINK L
 WHERE
 L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1)
);

 -- Detail INTRASTERPTLINK
 INSERT INTO TMP_INTRASTEPTLINK
 (CODINTR1, CODLINIEFACTURA, CANT)
 (SELECT CODINTR1, CODLINIEFACTURA, CANT
 FROM
 INTRASTEPTLINK L
 WHERE
 L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1)
);

  UPDATE TMP_INTRASTEPTLINK L
  SET
    (MONEDAFACT, CURSFACT, PRETFACT, TVAFACT, DATAFACT, CONTFACT) =
    (SELECT
       G.MONEDA,
       NVL(GREG.CURS, G.CURS),
       S.PU,
       S.TVA,
       I.DATADOC,
       S.CONTSERV
     FROM
       INTRARI1 S,
       GENERAL G
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL,
       INTRARI I
     WHERE
       S.CODINTR1 = L.CODLINIEFACTURA
       AND  G.CODDOC = S.CODINTR
       AND I.CODINTR= S.CODINTR
       AND G.TIPDOC = 9
       AND G.SEMNIFICATIE = 140
      );

  INSERT INTO TMP_INTRASTEPTLINK_INITIAL SELECT * FROM TMP_INTRASTEPTLINK;

INSERT INTO TMP_INTRPRODLINK
 (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODCOMANDA1, CODPROGRAMF1)
 (SELECT L.CODINTR1, L.CODLINIECOMANDA, L.CODLINIEAVIZ, L.CANT, MAT.CODCOMANDA1, L.CODPROGRAMF1
 FROM
 INTRPRODLINK L
 INNER JOIN CMDPRODMAT MAT ON L.CODLINIECOMANDA = MAT.CODCMDPRODMAT
 WHERE
 L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1)
);

 IF TIPINTR = 9 THEN
   UPDATE TMP_INTRLINK L
    SET
      (MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, DATAAVIZ, SUBUNITAVIZ) =
      (SELECT
        G.MONEDA,
        NVL(GREG.CURS, G.CURS),
        S.PU,
        S.CANT,
        S.TVA,
        I.DATADOC,
        I.SUBUNITATEA
       FROM
         INTRARI1 S,
         GENERAL G
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL,
         INTRARI I
      WHERE
        S.CODINTR1 = L.CODLINIEAVIZ AND  G.CODDOC = S.CODINTR AND I.CODINTR= S.CODINTR AND G.TIPDOC = 2/*AVIZ INTRARE*/
        and g.semnificatie = 140)
    ;

 END IF;

 UPDATE TMP_INTRLINK L
 SET
   DATACOMANDA =
   (SELECT  C.DATADOC
    FROM
    COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA)
   ;
 UPDATE TMP_INTRPRODLINK L
 SET
   DATACOMANDA =
   (SELECT  C.DATADOC
    FROM
    CMDPRODMAT MAT,
    COMANDA1 C1, COMANDA C WHERE MAT.CODCMDPRODMAT = L.CODLINIECOMANDA AND MAT.CODCOMANDA1 = C1.CODCOMANDA1 AND C.CODCOMANDA= C1.CODCOMANDA)
   ;



-- Detail NIR
  INSERT INTO  TMP_NIR
    ( CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat, Operat, Valoare )
    ( SELECT
      n.CodNIR, n.CodIntr, n.CarnetNIR, n.NRNIR, n.DataNIR, n.Gest, n.Obs, n.TipNIR, n.Anulat, n.Blocat, n.Operat,
     (Select sum(NS.CantNIR * NS.Pret) from NIRSTOC NS where NS.CODNIR = n.CodNIR)
      FROM
        NIR N
      WHERE
        n.CodIntr = RecId)
      ORDER BY NRNIR;


DELETE NIRSTOC_MAN;
INSERT INTO NIRSTOC_MAN
SELECT * FROM NIRSTOC NS WHERE EXISTS (SELECT CODNIR FROM TMP_NIR WHERE CODNIR = NS.CODNIR);

-- Detail NIRSTOC
  INSERT INTO  TMP_NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CantNir, UmSec, CodObiect, CodIoArt, Pret, PUMaximal, AdMax, RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, ProcentAdaos, Supliment, SuplNeded, D1, D2, D3,
     DenUM, Paritate, Valoare, CantFurn, MG, DIFPRET, ACCIZELATRANSFER, ARETVANEEX, PUStandard,
      ANALITICTVA, CONT, PRETACHIZ, PROCTVA, CODTVA, TG, DISCLIKISTOC, SERIELOT, DenObiect,
      PUVAL,
      PROVIZION,
      PRETREFERINTA,
      CODEXTERN,
      CODINTERN,
      DENCLASA,
      CODEXTERNCLI,
      FURN,
      DATAACHIZ,
      TIPDOCACHIZ,
      EUDR_RN,
      EUDR_VN)
    SELECT  * FROM
    ( SELECT
        NS.CodNirStoc, NS.CodNir,  NS.CodIntr1, NS.CantNir / u1.Paritate, NS.Umsec, NS.CodObiect, NS.CodIoArt, NS.Pret * u1.Paritate, NS.PUMaximal, NS.AdMax * u1.Paritate, NS.RotLei, NS.RotValuta, NS.CODLOCATIE, NS.CANTUM1, NS.CANTUM2,
        NS.Adaos * u1.Paritate, NS.TVA, NS.TipSerie, NS.CodLivr1, NS.Rest, NS.ProcentAdaos, NS.Supliment, NS.SuplNeded, NS.D1, NS.D2, NS.D3, u1.Den_UM1, u1.Paritate,
        NS.CantNIR * NS.Pret, NS.CantFURN / u1.Paritate,
--      (NS.CANTNIR + NVL((Select SUM(DIFERENTA) FROM NIR1 WHERE CodNirStoc = NS.CODNIRSTOC), 0)) / u1.Paritate,
        IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.PUStandard, IOALUNA.TVANEEX AS ANALITICTVA, IOALUNA.CONT,
/*
        (NS.PRET - NS.ADAOS -
        CASE
          WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
          ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR / U1.PARITATE)
        END) * u1.Paritate,
*/
        CASE
          WHEN TIPINTR = 3 THEN (SELECT Round(case when coalesce(cant,0) = 0 then 0 else PU - TVA/Cant end,NS.RotLei) FROM INTRARI1_MAN I1 WHERE I1.CODINTR1 = NS.CODINTR1)
          ELSE (SELECT PU FROM INTRARI1_MAN I1 WHERE I1.CODINTR1 = NS.CODINTR1)
        END * u1.Paritate * aCURS,
        TVL.PROCENT,
        NART1LUNA.CODTVA,
        NS.TG,
        NS.DISCLIKISTOC,
        NS.SERIELOT,
        O.DENUMIRE,
        NS.PUVAL,
        NS.PROVIZION,
        O1.PRETREFERINTA,
        O.CODEXTERN,
        O.CODINTERN,
        SUBSTR(CLA.DEN_CLASEA, 1, 50),
        CLI.CODEXTERN AS CODEXTERNCLI,
        NS.FURN,
        NS.DATAACHIZ,
        NS.TIPDOCACHIZ,
        NS.EUDR_RN,
        NS.EUDR_VN
      FROM
        NIRSTOC_MAN NS
        LEFT OUTER JOIN TMP_INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
        LEFT OUTER JOIN NARTCLI  CLI ON CLI.CODOBIECT = NS.CODOBIECT AND CODPART = NVL(aCODPART, 0)
        LEFT OUTER JOIN TMP_IOART_LUNA IOALUNA ON IOALUNA.CODIOART = NS.CODIOART
        left outer join NartObj o on o.CodObiect   = NS.CodObiect
        left outer join TMP_NARTOBJ_LUNA o1 on o1.CodObiect   = O.CodObiect
        left outer join Nart a on a.CodArticol     = o.CodArticol
        left outer join NCLASEA CLA on CLA.CODCLASEA     = A.CLASA
        LEFT OUTER JOIN TMP_NART_LUNA NART1LUNA  ON NART1LUNA.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN TMP_NTVA_LUNA TVL ON TVL.CODTVA = NART1LUNA.CODTVA,
        NUM1 u1
      WHERE
        NS.CodNir in (Select CodNIR from TMP_NIR) and u1.CodUM1 = NS.UmSec
      )
     ORDER BY CodNir, CodIntr1;

    insert into tmp_nirstoc1
    select ns1.*
    from nirstoc1 ns1
    where exists (select tmp.codnirstoc from tmp_nirstoc tmp where tmp.codnirstoc = ns1.codnirstoc);


-- Detail NirSer
    INSERT INTO TMP_NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, SERIE, CANTUM1, CANTUM2, OBS, CodCertif, DataProd, TG, Stare, NrCertif, Divizor, Bucati,
                            REST, DataProd1, TG1, codproducator)
    (SELECT NS.CODNIRSER, NS.CODNIRSTOC, NS.CODSERIE, NS.CANTNIR, (SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), NS.CANTUM1, NS.CANTUM2, NS.OBS, NS.CodCertif, NS.DataProd, NS.TG,  NS.Stare, CE.NrCertif, NS.Divizor, NS.Bucati,
            NS.REST, NS.DataProd1, NS.TG1, ns.codproducator
     FROM NIRSER NS
     LEFT JOIN CERTIF CE ON NS.CodCertif = CE.CodCertif
     WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC));

-- Detail LIVR
  INSERT INTO  TMP_LIVR
    ( CodLivr,  CodIes, CodIntr, CarnetLivr, NrLivr, DataLivr, Obs, TipLivr, Anulat, Blocat, Operat )
    ( SELECT
      CodLivr,  CodIes, CodIntr, CarnetLivr, NrLivr, DataLivr, Obs, TipLivr, Anulat, Blocat, Operat
      FROM LIVR WHERE CodIntr = RecId) ;

-- Detail LIVR1


/* COPIAT MAI JOS DIN PACKETUL DE TRANSFERURI

  INSERT INTO  TMP_LIVR1
     ( CodLivr1, CodLivr, CodIntr1, CodNirStoc, Cant, CodNirSer, PMP, UmSec,
       DenUM, Paritate, Gest, CodIoArt, CodObiect, CodLivrTot )
     ( SELECT
         l1.Codlivr1, l1.Codlivr, l1.CodIntr1, l1.CodNirStoc, l1.Cant / u1.Paritate, l1.CodNirSer,
         l1.PMP, l1.UmSec, u1.Den_UM1, u1.Paritate, N.Gest, NS.CodIoArt, NS.CodObiect, 0
       FROM
         LIVR1 l1 LEFT OUTER JOIN  NIRSTOC NS on NS.CodNirStoc = L1.CodNirStoc
         LEFT OUTER JOIN NIR n on N.CODNIR = NS.CODNIR
         LEFT OUTER JOIN LIVR l on l.CodLivr = l1.CodLivr,
         NUM1 u1
       WHERE
         l.CodIntr  = RecID and
         u1.CodUM1  = L1.UmSec
     );
*/

  INSERT INTO  TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODINTR1,
       CODNIRSTOC,
       CANT,
       CODNIRSER,
       PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC,
       UMSEC,
       CANTUM1,
       CANTUM2,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE,
       PROVIZION
        )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODINTR1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CODNIRSER,
         L1.PMP, L1.PMPDOC, L1.PMPVALUTA,L1.PMPVALUTADOC,
         L1.UMSEC,
         L1.CANTUM1,
         L1.CANTUM2,
         U1.DEN_UM1,
         U1.PARITATE,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,


         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,

        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
        NS.PROVIZION
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         L.CODINTR  = RECID AND U1.CODUM1 = L1.UMSEC
     );



-- Detail LIVRTOT
  DELETE TMP_LIVRTOT;



  INSERT INTO TMP_LIVRTOT
   (CODLIVRTOT,
   CODLIVR,
   CODIESINT1,
   UMSEC,
   GEST,
   CODIOART,
   CODOBIECT,
   DENUM,
   PARITATE,
   DENGESTIOART,
   DIFPRET,
   ARETVANEEX,
   MG,
   CONT,
   STOCREZOLVAT,
   CANT,
   PRETINREG,
   PRETACHIZ,
   PMP, PMPDOC, PMPVALUTA, PMPVALUTADOC)

  SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODINTR1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         1,
/*
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PRETACHIZ * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMP       * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPDOC    * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTA * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTADOC * L1.CANT) / SUM(L1.CANT)
*/
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMP       * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPDOC    * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPVALUTA * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PMPVALUTADOC * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT))
       FROM
         TMP_LIVR1 L1
         LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
         LEFT JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
         LEFT JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT JOIN IOART IO ON IO.CODIOART = L1.CODIOART
       WHERE L.CODINTR = RECID
       GROUP BY
         0, L1.CODLIVR, L1.CODINTR1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE , G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT
     )
  ORDER BY CODLIVR, CODINTR1;


   UPDATE TMP_LIVRTOT T SET
   CODLIVRTOT  = ROWNUM,
   DENOBIECT   = (SELECT DENUMIRE FROM NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT), --PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
-- INDEXMASTER = (SELECT INDEXLOCAL FROM  WHERE CODTRANSF1 = T.CODIESINT1),
  (UM1, UM2, RELATIEUM1) = (SELECT UM1, UM2, RELATIEUM1 FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   GESTIMPLICITA = (SELECT GESTIMPLICITA
                    FROM
                      NARTIMPLICITE A
                    WHERE
                      CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)
                      AND CODSUBUNIT =DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(A.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
                      AND ROWNUM = 1),
   PROCTVA     = PKG_SELECTARTICOLE.GETPROCENTTVA
                 (PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);



-- FAC LEGATURA INTRE LIVR1 si LIVRTOT
   UPDATE TMP_LIVR1 l1 SET CodLivrTot =
    ( SELECT CodLivrTot FROM TMP_LIVRTOT
      WHERE
        CODLIVR    = l1.CODLIVR  AND
        CODIESINT1 = l1.CODINTR1 AND
        UMSEC      = l1.UMSEC    AND
        Paritate   = l1.Paritate AND
        GEST       = l1.GEST     AND
        CODIOART   = l1.CODIOART
     );


-- DETAIL TMP_LIVRVAL;
   INSERT INTO TMP_LIVRVAL SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

-- PARITATEA PRETURILOR DIN LIVRVAL ESTE CEA DIN TMP_LIVR1
   UPDATE TMP_LIVRVAL LV
   SET
     PRETINREG = PRETINREG * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1),
     PRETACHIZ = PRETACHIZ * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1);



-- PENTRU ORDONARE NIRSTOC PREIAU INDEXLOCAL DE PE INTRARI1
-- PENTRU DISTRIBUIRE VALORI SUPLIMENTARE PREIAU MASA SI VOLUM
-- PENTRU VALIDARI LA IESIRE PREIAU VALORI INITIALE PRET, ADAOS, CODIOART
   UPDATE TMP_NIRSTOC NS
   SET
     INDEXMASTER     = (SELECT nvl(INDEXLOCAL,0) FROM  TMP_INTRARI1 WHERE CODINTR1 = NS.CODINTR1 and rownum = 1),
     (MASA, VOLUM)   = (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = NS.CODOBIECT and rownum = 1),
     (UM1, UM2, RELATIEUM1, RELATIEUM2)      = (SELECT NVL(UM1, 0), NVL(UM2, 0), NVL(RELATIEUM1, 0), NVL(RELATIEUM2, 0) FROM NART A WHERE A.CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(NS.CODOBIECT) and rownum = 1),
     PRETINITIAL     = PRET,
     ADAOSINITIAL    = ADAOS,
     CODIOARTINITIAL = CODIOART;


-- MEMOREZ TAREA LA INTRARE A LIVRARILOR
   DELETE TMP_LIVR1_INITIAL;
   INSERT INTO TMP_LIVR1_INITIAL (SELECT * FROM TMP_LIVR1);

   DELETE TMP_INTRLINK_INITIAL;
   INSERT INTO TMP_INTRLINK_INITIAL (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);

   DELETE TMP_INTRPRODLINK_INITIAL;
   INSERT INTO TMP_INTRPRODLINK_INITIAL (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODCOMANDA1) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODCOMANDA1 FROM TMP_INTRPRODLINK);

   -- PREIAU CARACTERIZAREA CONTABILA VALABILA PE LUNA DE LUCRU A PARTENERULUI DE PE FACTURA
   DELETE TMP_IOPARTDOC;

   IF TIPINTR IN (1, 2, 3, 4, 9) AND aCODPART &lt;&gt; 0  THEN
       LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(aCODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
       LOOP
         FETCH LUNAREF INTO IOPART1REC;
         EXIT WHEN LUNAREF%NOTFOUND;
         IF IOPART1REC.CODIOPART1 &gt; 0 THEN
             INSERT INTO TMP_IOPARTDOC
             ( CODPART,
               CODIOPART1,
               CODIOPART,
               CONTFURNIZOR,
               CONTCLIENT,
               CONTFURNAVANS,
               CONTCLIENTAVANS,
               CONTFURNAVIZ,
               CONTCLIENTAVIZ,
               CONTFURNMF,
               CONTCREDITD,
               CONTDEBITD,
               CONTLITIGII,
               CONTFURNAVS,
               CONTFURNAVIC,
               CONTFURNAVIN,
               CONTTERTI,
               CONTCHELTAVANS,
               CONTVENITAVANS,
							 CONTGARANTIEEF,
							 CONTGARANTIETF,
							 CONTGARANTIEEC,
							 CONTGARANTIETC,
							 ContSuplimF1 ,
							 ContSuplimF2 ,
							 ContSuplimF3 ,
							 ContSuplimF4 ,
							 ContSuplimF5 ,
							 ContSuplimC1 ,
							 ContSuplimC2 ,
							 ContSuplimC3 ,
							 ContSuplimC4 ,
							 ContSuplimC5 ,
               TvaNeexF, TvaNeexP, TvaNeexI,
               TVANEEXC,
               TIP
               )
               VALUES
               (aCODPART,
                IOPART1REC.CODIOPART1,
                IOPART1REC.CODIOPART,
                IOPART1REC.CONTFURNIZOR,
                IOPART1REC.CONTCLIENT,
                IOPART1REC.CONTFURNAVANS,
                IOPART1REC.CONTCLIENTAVANS,
                IOPART1REC.CONTFURNAVIZ,
                IOPART1REC.CONTCLIENTAVIZ,
                IOPART1REC.CONTFURNMF,
                IOPART1REC.CONTCREDITD,
                IOPART1REC.CONTDEBITD,
                IOPART1REC.CONTLITIGII,
                IOPART1REC.CONTFURNAVS,
                IOPART1REC.CONTFURNAVIC,
                IOPART1REC.CONTFURNAVIN,
                IOPART1REC.CONTTERTI,
                IOPART1REC.CONTCHELTAVANS,
                IOPART1REC.CONTVENITAVANS,
								IOPART1REC.CONTGARANTIEEF,
								IOPART1REC.CONTGARANTIETF,
								IOPART1REC.CONTGARANTIEEC,
								IOPART1REC.CONTGARANTIETC,
							  IOPART1REC.ContSuplimF1 ,
							  IOPART1REC.ContSuplimF2 ,
							  IOPART1REC.ContSuplimF3 ,
							  IOPART1REC.ContSuplimF4 ,
							  IOPART1REC.ContSuplimF5 ,
							  IOPART1REC.ContSuplimC1 ,
							  IOPART1REC.ContSuplimC2 ,
							  IOPART1REC.ContSuplimC3 ,
							  IOPART1REC.ContSuplimC4 ,
							  IOPART1REC.ContSuplimC5 ,
                IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
                IOPART1REC.TVANEEXC,
                IOPART1REC.TIP
               );
         END IF;
       END LOOP;
     END IF;


   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = TIPINTR AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = TIPINTR AND CODDOC = RECID);

   DELETE TMP_RULAJ;

   UPDATE TMP_NIRSER NSE
    SET
      PARITATE = NVL((SELECT nvl(PARITATE,1) FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC and rownum = 1),1),
      CANTNIR  = CANTNIR / NVL((SELECT nvl(PARITATE,1) FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC and rownum = 1),1);

-- PUN PE  D1..D3 CARE VIN DE PE COMENZI
  FOR V_REC IN
  (SELECT I1.CODINTR1, C1.D1, C1.D2, C1.D3
   FROM TMP_INTRARI1
     I1,
    TMP_INTRPRODLINK IL,
    COMANDA1 C1,
    CMDPRODMAT MAT
   WHERE
    IL.CODINTR1 = I1.CODINTR1
    AND MAT.CODCMDPRODMAT = IL.CODLINIECOMANDA
    AND MAT.CODCOMANDA1 = C1.CODCOMANDA1
   )
   LOOP
     UPDATE
       TMP_INTRARI1
     SET
       D1 = V_REC.D1,
       D2 = V_REC.D2,
       D3 = V_REC.D3
     WHERE
      CODINTR1 = V_REC.CODINTR1;
   END LOOP;


  FOR V_REC IN
  (SELECT I1.CODINTR1, C1.D1, C1.D2, C1.D3
   FROM TMP_INTRARI1 I1,
    TMP_INTRLINK IL,
    COMANDA1 C1
   WHERE
    IL.CODINTR1 = I1.CODINTR1
    AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
   )
   LOOP
     UPDATE
       TMP_INTRARI1
     SET
       D1 = V_REC.D1,
       D2 = V_REC.D2,
       D3 = V_REC.D3
     WHERE
      CODINTR1 = V_REC.CODINTR1;
   END LOOP;

-- PENTRU INREGISTRARILE CARE NU VIN DE PE COMENZI PUN PE INTRARI1 D1..D3 din  NIRSTOC SAU IMPLICITE DIN NART

  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;VanzUMAltUMSec&apos;, aANLUCRU, aLUNALUCRU), &apos;1&apos;) INTO aVanzUMAltUMSec FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aVanzUMAltUMSec := &apos;1&apos;;
  END;

  IF aVanzUMAltUMSec in (&apos;2&apos;, &apos;3&apos;) then
      FOR V_REC IN
      (SELECT
        I1.CODINTR1,
        A.D1,
        A.D2,
        A.D3,
        (SELECT D1 FROM TMP_NIRSTOC WHERE CODNIRSTOC = (SELECT MIN(CODNIRSTOC) FROM TMP_NIRSTOC NS WHERE NS.CODINTR1 = I1.CODINTR1 )) AS D1_NIRSTOC,
        (SELECT D2 FROM TMP_NIRSTOC WHERE CODNIRSTOC = (SELECT MIN(CODNIRSTOC) FROM TMP_NIRSTOC NS WHERE NS.CODINTR1 = I1.CODINTR1 )) AS D2_NIRSTOC,
        (SELECT D3 FROM TMP_NIRSTOC WHERE CODNIRSTOC = (SELECT MIN(CODNIRSTOC) FROM TMP_NIRSTOC NS WHERE NS.CODINTR1 = I1.CODINTR1 )) AS D3_NIRSTOC
       FROM
        TMP_INTRARI1 I1,

        NARTOBJ O,
        NART A
       WHERE
         TIPLINIE = &apos;=&apos;
         AND NOT EXISTS (SELECT CODINTR1 FROM TMP_INTRLINK     WHERE CODINTR1 = I1.CODINTR1)
         AND NOT EXISTS (SELECT CODINTR1 FROM TMP_INTRPRODLINK WHERE CODINTR1 = I1.CODINTR1)
         AND O.CODOBIECT  = I1.CODOBIECT
         AND A.CODARTICOL = O.CODARTICOL
      )
      LOOP
        UPDATE TMP_INTRARI1
        SET
          D1 = NVL(V_REC.D1_NIRSTOC, V_REC.D1),
          D2 = NVL(V_REC.D2_NIRSTOC, V_REC.D2),
          D3 = NVL(V_REC.D3_NIRSTOC, V_REC.D3)
        WHERE
          CODINTR1 = V_REC.CODINTR1;
      END LOOP;
  END IF;


   FOR V_REC IN
   (SELECT
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM
      TMP_STINGERE S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL
   )LOOP
      aCODSUBUNITSTINS := 0;
      IF V_REC.SEMNIFICATIE IN (110, 120) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;

      UPDATE TMP_STINGERE
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
      END IF;
    END LOOP;


    IF TIPINTR = 2 THEN
      UPDATE TMP_INTRARI1 I1
      SET
        NRDOCLINK = &apos;Storno AE&apos; || (SELECT AE.NRDOC FROM INTRARI1 AE1, INTRARI AE WHERE AE1.CODINTR1 = I1.CODINTR1STORNO AND AE.CODINTR = AE1.CODINTR)
      WHERE
       NVL(I1.CODINTR1STORNO, 0) &lt;&gt; 0;
    END IF;


  DELETE TMP_NIRSERINI;
  INSERT INTO TMP_NIRSERINI
  SELECT * FROM TMP_NIRSER;

  DELETE TMP_NIRSTOC_INITIAL;
  INSERT INTO TMP_NIRSTOC_INITIAL
  SELECT * FROM TMP_NIRSTOC;



   BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
     EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
   END;

   IF TIPPREFIX = &apos;2&apos; THEN
     UPDATE TMP_INTRARI1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;);
   ELSE
   IF TIPPREFIX = &apos;3&apos; THEN
     UPDATE TMP_INTRARI1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;);
   IF TIPPREFIX = &apos;4&apos; THEN
     UPDATE TMP_COMANDA1 I1
     SET
       DENOBIECT = NVL((SELECT A.CODEXTERNART || A.SUFIXCODEXTERN FROM NART A, NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT AND A.CODARTICOL = O.CODARTICOL), &apos;&apos;) || &apos;;&apos; || DENOBIECT
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
   END IF;
   END IF;
   END IF;

   IF TIPPREFIX &lt;&gt; &apos;1&apos; THEN
     UPDATE TMP_NIRSTOC NS
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = NS.CODINTR1);


     UPDATE TMP_LIVR1 L1
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = L1.CODINTR1);


   END IF;

  -- CERINTA ARAMIS - GESTIUNEA IMPLICITA DE RECEPTIE SA VINA SETATA DE PE COMANDA
   FOR V_REC IN (SELECT
                   I1.CODINTR1,
                   C1.GESTACT
                 FROM
                   TMP_INTRLINK IL,
                   TMP_INTRARI1 I1,
                   COMANDA1 C1
                 WHERE
                   IL.CODINTR1 = I1.CODINTR1
                   AND IL.CODLINIECOMANDA = C1.CODCOMANDA1
                   AND NVL(C1.GESTACT, 0) &lt;&gt; 0 AND I1.TIPLINIE = &apos;=&apos;
                )
   LOOP
     UPDATE TMP_INTRARI1
     SET
       GESTIMPLICITA = V_REC.GESTACT
     WHERE
       CODINTR1 = V_REC.CODINTR1
       AND NVL(GESTIMPLICITA, 0) = 0;
   END LOOP;


  DELETE TMP_DIN_CANTARIRI;
  INSERT INTO TMP_DIN_CANTARIRI(CODCANTAR, TIPDOC, CODDOC1)
  SELECT
    CODCANTAR,
    TIPDOC,
    CODDOC1
  FROM
    CANTAR
  WHERE
    TIPDOC = TIPINTR
    AND CODDOC1 IN (SELECT CODINTR1 FROM TMP_INTRARI1);

  INSERT INTO TMP_DIN_CANTARIRI(CODBCAR, TIPDOC, CODDOC1)
  SELECT
    CODBCAR,
    TIPDOC,
    CODDOC1
  FROM
    BCAR
  WHERE
    TIPDOC = TIPINTR
    AND CODDOC1 IN (SELECT CODINTR1 FROM TMP_INTRARI1);



  INSERT INTO TMP_INTRDOCTRANSP(COD,
                                CODINTR,
                                CODINTRLINK,
                                VALTRANSPORT,
                                DEN_PART,
                                NRDOCLINK,
                                DATADOCLINK,
                                PREFIXDOC,
                                VOLTOT,
                                MASATOT,
                                VALTOT
                                )
  SELECT
    T.COD,
    T.CODINTR,
    T.CODINTRLINK,
    T.VALTRANSPORT,
    P.DEN_PART,
    IL.NRDOC,
    IL.DATADOC,
    IL.PREFIXDOC,
    (SELECT SUM(NVL(O.VOLUM, 0) * I1.Cant) FROM INTRARI1 I1, NARTOBJ O WHERE I1.CODINTR = IL.CODINTR AND O.CODOBIECT = I1.CODOBIECT),
    (SELECT SUM(NVL(O.MASA, 0) * I1.Cant)  FROM INTRARI1 I1, NARTOBJ O WHERE I1.CODINTR = IL.CODINTR AND O.CODOBIECT = I1.CODOBIECT),
    (SELECT SUM(NVL(PU, 0) * NVL(CANT, 0) )  FROM INTRARI1 I1 WHERE CODINTR = IL.CODINTR)
  FROM
    INTRDOCTRANSP T,
    INTRARI IL,
    NPART P
  WHERE
    T.CODINTR = RECID
    AND IL.CODINTR = T.CODINTRLINK
    AND P.CODPART = IL.PARTENER;

  DELETE TMP_INTRDOCTRANSP_INI;
  INSERT INTO TMP_INTRDOCTRANSP_INI SELECT * FROM TMP_INTRDOCTRANSP;

--pregatesc dezasamblarile
  IF TIPINTR = 7 THEN
    BEGIN
      Select codLivr1 into aCodLinieFurn from Dezasamblari1 where CODINTRLINK = RECID;
      EXCEPTION WHEN OTHERS THEN aCodLinieFurn := 0;
    END;
    if aCodLinieFurn &gt; 0 then
			INSERT INTO TMP_DEZASAMBLARI(
             codLivr1    ,
             codNIRSTOC  ,
             valoare     ,
             inchisa     ,
             Rest        ,
             den_obiect  ,
						 den_part    ,
             DocIntr     ,
             datadocIntr )
			SELECT
			  T.codLivr1,
				T.codNIRSTOC    ,
        T.valoare       ,
        T.Inchisa       ,
				T.valoare - Nvl((Select Sum(Nvl(Valoare, 0)) from Dezasamblari1 where codLivr1 = aCodLinieFurn and CODINTRLINK &lt;&gt; RECID),0),
				O.Denumire    ,
--				P.DEN_PART      , I.PREFIXDOC || I.SERIADOC || I.NRDOC, I.DATADOC
				G.DEN_GEST      , E.PREFIXDOC || E.SERIADOC || E.NRDOC, E.DATADOC
			FROM
				Dezasamblari T,
--				NIRSTOC NS,	INTRARI1 I1,INTRARI I,NPART P,
				LIVR1 L1,	IESIRI1 E1,IESIRI E,NGEST G,
				NARTOBJ O
			WHERE
				T.codLivr1 = aCodLinieFurn
--				AND NS.CODNIRSTOC = T.CODNIRSTOC AND I1.CODINTR1   = NS.CODINTR1 AND I.CODINTR     = I1.CODINTR AND P.CODPART     = I.PARTENER AND O.CodObiect   = I1.CODObiect
				AND L1.CODLIVR1 = T.CODLIVR1 AND E1.CODIES1   = L1.CODIES1 AND E.CODIES     = E1.CODIES AND O.CodObiect   = E1.CODObiect AND G.CODGEST  = E.CODGESTPROD;

    end if;
/*
  else
			INSERT INTO TMP_DEZASAMBLARI(
             codNIRSTOC  ,
             valoare     ,
             rest        ,
             inchisa
						 )
			SELECT
			  T.codNIRSTOC    ,
        T.valoare       ,
				T.valoare - Nvl(T1.Valoare,0),
        T.Inchisa
			FROM
				Dezasamblari T
				left join
				(Select CodNIRSTOC, Sum(Nvl(Valoare, 0)) Valoare from Dezasamblari1 where CodNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC) group by CODNIRSTOC) T1
				on T1.CodNIRSTOC = T.CODNIRSTOC
			WHERE
				T.CODNIRSTOC  IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC);
  	Select Count(*) into vCount from TMP_DEZASAMBLARI;
		if vCount &gt; 0 then update tmp_intrari set DEZAGREGARE = 1; end if;
*/
	end if;

  UPDATE
    TMP_INTRARI1 I1
  SET
    I1.INFOBCAR = (SELECT NRDOC || &apos;/&apos; || TO_CHAR(datadoc, &apos;DD.MM.YYYY&apos;) FROM BCAR WHERE CODDOC1 = I1.CODINTR1 AND TIPDOC = TIPINTR AND ROWNUM = 1),
    CANTUM1     = (SELECT SUM(NVL(CANTUM1, 0)) FROM NIRSTOC NS WHERE NS.CODINTR1 = I1.CODINTR1);




  FOR V_REC IN (SELECT * FROM TMP_INTRARI1 WHERE NVL(TAXA, 0) = 1 AND NVL(ROTVALTAXA, 0) &gt; 0)
  LOOP
    UPDATE TMP_INTRARI1
    SET
      VALOARE = ROUND(VALOARE, ROTVALTAXA - 1)
    WHERE
      CODINTR1 = V_REC.CODINTR1;
  END LOOP;


  IF TIPINTR &lt;&gt; 7 THEN
		FOR V_REC IN (SELECT Nvl(DenClasa,&apos;?&apos;) DenClasa, Sum(SUPLIMENT-SUPLNEDED) TotSupliment FROM TMP_NIRSTOC GROUP By Nvl(DenClasa,&apos;?&apos;))
		LOOP
			INSERT INTO TMP_DEZASAMBLARI(den_obiect, DocIntr, valoare)  Values(v_rec.DenClasa, &apos;&gt;&gt;&apos;, Round(V_rec.Totsupliment, 2));
			UPDATE TMP_NIRSTOC
			SET
				SUPLIMCLASA = Round(V_rec.Totsupliment, 2)
			WHERE
				Nvl(DenClasa,&apos;?&apos;) = V_rec.DenClasa;
		END LOOP;
	end if;

	IF  TIPINTR &lt; 6 THEN
    BEGIN
      SELECT PKG_CATEGCONST.GetValConstanta(&apos;DenLaClient_F&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO DenLaClient FROM DUAL;
      EXCEPTION WHEN OTHERS THEN DenLaClient := &apos;2&apos;;
    END;
		if DenLaClient = &apos;1&apos; then
			 UPDATE TMP_INTRARI1 I1
			 SET DENOBIECT = (SELECT Coalesce(x.DENUMIRE, &apos;???&apos;||i1.DenObiect)
												FROM
													NARTCLI x
												WHERE x.CODOBIECT = i1.CODOBIECT and x.CODPART = aCodPart
												);
			 UPDATE TMP_NIRSTOC NS
			 SET DENOBIECT = (SELECT distinct x.DenObiect FROM TMP_INTRARI1 x WHERE x.CODOBIECT = ns.CODOBIECT);
			 UPDATE TMP_DVI1 d1
			 SET DENOBIECT = (SELECT distinct x.DenObiect FROM TMP_INTRARI1 x WHERE x.CODOBIECT = d1.CODOBIECT);
			 UPDATE TMP_LIVRTOT lt
			 SET DENOBIECT = (SELECT distinct x.DenObiect FROM TMP_INTRARI1 x WHERE x.CODOBIECT = lt.CODOBIECT);
    end if;
  end if;


  /*IF TIPINTR = 7 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIP&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIP SELECT * FROM INTRARIP WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIF SELECT * FROM INTRARIF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 4 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRPF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRPF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRPF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRPF SELECT * FROM INTRPF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 6 AND  PKG_LIST_STRUCT.TmpExists(&apos;INTRSUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRSUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRSUB&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRSUB SELECT * FROM INTRSUB WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 2 AND ATIPFACTURA = 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRFAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRFAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRFAST SELECT * FROM INTRFAST WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 2 AND ATIPFACTURA &lt;&gt; 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIAE&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIAE SELECT * FROM INTRARIAE WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 9 AND ATIPFACTURA &lt;&gt; 9 AND  PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIFA&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIFA SELECT * FROM INTRARIFA WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 9 AND ATIPFACTURA = 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRAST SELECT * FROM INTRAST WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 3 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARICF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARICF SELECT * FROM INTRARICF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF TIPINTR = 7 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIP1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIP1 SELECT * FROM INTRARIP1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 1 AND  PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIF1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIF1 SELECT * FROM INTRARIF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 4 AND  PKG_LIST_STRUCT.TmpExists(&apos;INTR1PF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1PF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1PF SELECT * FROM INTR1PF WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 6 AND PKG_LIST_STRUCT.TmpExists(&apos;INTR1SUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1SUB&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1SUB SELECT * FROM INTR1SUB WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 2 AND ATIPFACTURA = 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTR1FAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1FAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1FAST SELECT * FROM INTR1FAST WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 2 AND ATIPFACTURA &lt;&gt; 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIAE1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIAE1 SELECT * FROM INTRARIAE1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 9 AND ATIPFACTURA &lt;&gt; 9 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIFA1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIFA1 SELECT * FROM INTRARIFA1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 9 AND ATIPFACTURA = 9 AND  PKG_LIST_STRUCT.TmpExists(&apos;INTR1AST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1AST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1AST SELECT * FROM INTR1AST WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF TIPINTR = 3 AND PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARICF1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARICF1 SELECT * FROM INTRARICF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;
*/
/*
  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIP&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIP SELECT * FROM INTRARIP WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIF SELECT * FROM INTRARIF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRPF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRPF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRPF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRPF SELECT * FROM INTRPF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRSUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRSUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRSUB&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRSUB SELECT * FROM INTRSUB WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRFAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRFAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRFAST SELECT * FROM INTRFAST WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIAE&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIAE SELECT * FROM INTRARIAE WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIFA&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIFA SELECT * FROM INTRARIFA WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRAST SELECT * FROM INTRAST WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARICF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARICF SELECT * FROM INTRARICF WHERE CODINTR = &apos; || RECID;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIP1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIP1 SELECT * FROM INTRARIP1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIF1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIF1 SELECT * FROM INTRARIF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1PF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1PF&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1PF SELECT * FROM INTR1PF WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1SUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1SUB&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1SUB SELECT * FROM INTR1SUB WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1FAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1FAST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1FAST SELECT * FROM INTR1FAST WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIAE1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIAE1 SELECT * FROM INTRARIAE1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARIFA1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARIFA1 SELECT * FROM INTRARIFA1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1AST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTR1AST&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTR1AST SELECT * FROM INTR1AST WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE TMP_INTRARICF1&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_INTRARICF1 SELECT * FROM INTRARICF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1) &apos;;
  END IF;
*/


-- coloane pentru analiza pret la vanzare
  IF TIPINTR = 1 AND PKG_CATEGCONST.GetValConstanta(&apos;PretVanzDinNIR&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) IN (&apos;1&apos;, &apos;3&apos;, &apos;4&apos;) THEN

      FOR V_REC IN
       (SELECT NS.*,
             N.GEST,
             PM.LEI,
             CASE
                WHEN CP_G.CODCATPRET IS NOT NULL THEN  CP_G.CODCATPRET
               ELSE CP_I.CODCATPRET
             END CODCATPRET,
             CASE
               WHEN CP_G.TIP IS NOT NULL THEN  CP_G.TIP
               ELSE CP_I.TIP
             END TIPCATPRET
        FROM
          TMP_NIRSTOC NS
          INNER JOIN TMP_NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST
          LEFT JOIN NCATPRET CP_G ON CP_G.CODCATPRET = G.CODCATPRET
          LEFT JOIN PRETM PM ON PM.CODOBIECT = NS.CODOBIECT AND COALESCE(PM.IMPLICIT, 0) = 1 AND PM.SUBUNITATEA = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
          LEFT JOIN NCATPRET CP_I ON CP_I.CODCATPRET = PM.CODCATPRET
        )
      LOOP
        UPDATE TMP_NIRSTOC
        SET
          PUVANZARE      = V_REC.LEI *  V_REC.paritate,--PKG_PRETURI.GETPRETRECEPTIE(V_REC.CODOBIECT, V_REC.GEST, V_REC.pretachiz, V_REC.proctva/100, V_REC.paritate, 1, 1, /*V_REC.aretvaneex*/1, V_REC.PUMaximal, V_REC.pret),
          CATPRETVANZ    = V_REC.CODCATPRET,
          TIPCATPRETVANZ = V_REC.TIPCATPRET
        WHERE
          CODNIRSTOC = V_REC.CODNIRSTOC;
      END LOOP;

      FOR V_REC IN (SELECT * FROM TMP_NIRSTOC)
      LOOP
        aPU       := V_REC.PUVANZARE;

       if V_REC.TIPCATPRETVANZ = 1 then
          aPUFara := aPU / (1 +  V_REC.ProcTVA / 100);
       else
          aPUFara := aPU ;
       end if;

       BEGIN
        SELECT COALESCE(PM.ROTUNJIRE, O.ROTUNJIRE) INTO aROTPRET
        FROM
          NARTOBJ O
          LEFT JOIN PRETM PM ON PM.SUBUNITATEA = aSUBUNIT
              AND PM.CODOBIECT = O.CODOBIECT AND PM.CODCATPRET = v_rec.CatPretVanz
           WHERE
             O.CODOBIECT = v_rec.CodObiect;
        exception when others then
           aROTPRET := 2;

       END;

       aPUFara := pkg_preturi.WMROTOPRET(aROTPRET, aPUFara);

       aPretFurn := V_REC.PretAchiz + CASE WHEN V_REC.CantNIR &lt;&gt; 0 THEN V_REC.SUPLIMENT / V_REC.CantNIR ELSE 0 END;

      /*
        if V_REC.TIPCATPRETVANZ = 1 then
          aPUFara := aPU / (1 +  V_REC.ProcTVA / 100);
        else
          aPUFara := aPU;
        end if;
     */
        if aPretFurn &lt;&gt; 0 then
          aAdaos := 100 * (aPUFara - aPretFurn) / aPretFurn;
        else
          aAdaos := 100.0;
        end if;

        UPDATE TMP_NIRSTOC
        SET
          PUVANZARE = aPU,--aPUFara,
          AdaosPUVanz = round(aAdaos, 2)
        WHERE
          CodNirSToc = V_REC.CODNIRSTOC;
      END LOOP;
    END IF;
  PKG_CFGTABLES.EXT_GOTORECORD(TIPINTR);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod    NUMBER(20);
  TIPINTR INTEGER := 0;
  NR      INTEGER := 0;
  NRCHELT INTEGER := 0;
  NRMIFIX INTEGER := 0;
  aOperat INTEGER := 0;
  aAnuLat INTEGER := 0;

  DoPU    INTEGER := 0;

	NR_Cerere NUMBER(20);
  NR_Sosite NUMBER(20);
  aCodBCAR  Number(20);

  OLDCARNETNIR  NUMBER(20) := 0;
  OLDNRNIR      NUMBER(20) := 0;

  OLDCARNETLIVR NUMBER(20) := 0;
  OLDNRLIVR     NUMBER(20) := 0;
  OLDOPERAT     NUMBER(1);

  aCARNET       NUMBER(20) := 0;
  aNUMARDOC     NUMBER(20) := 0;

  aCARNETFISA   NUMBER(20) := 0;
  aNRFISA NUMBER(20) := 0;

  aCODSERIE     NUMBER(20) := 0;
  aCODPART      NUMBER(20) := 0;
  aCODGESTPROD  NUMBER(20) := 0;
  aSUBUNITATEA  NUMBER(20) := 0;
  aCODMONEDA    NUMBER(20) := 0;
  aCODOBIECT    NUMBER(20) := 0;
  aUMSec        NUMBER(20) := 0;
  aCURS         NUMBER(20, 7) := 1;
  aVALOARE      NUMBER(20, 7) := 0;
  TotSosit      NUMBER(20, 7) := 0;
  NOMSERIE      VARCHAR2(75);
  VALPROD       NUMBER(20, 7) := 0;
  PRETPROD      NUMBER(20, 7) := 0;
  --aCODNIR NUMBER(20) := 0;

	aCodSubunit number(20);
  aDataDoc date;
  aDATATVA date;
	aDoc varchar2(200);
  aCant NUMBER(20,7);
  aCantRez number(20,7);
  aRezIni NUMBER(20,7);
  aRest NUMBER(20,7);
  aCount number(10);
  aCodFisaMas number(20);
  aTIPFACTURA INTEGER := 0;
  LockStocFaraCertif varchar2(3);
  vRest              number(20,7);
  aTIPTRANZACTIE     INTEGER := 0;
  LastUtilaj2c       NUMBER(20);
  ATVAINCASARE       INTEGER     := 0;
  aZILETVAINCASARE   INTEGER     := 0;
  aCodComanda1 NUMBER(20);
  aTipImport integer := 0;
  aTIPDOCNirStoc1 integer;
  aCodDVI NUMBER(20);
  aTipCompPredat number(1);
  aCantTransfer number(20,7);
  StornoAvize VARCHAR2(30);
  CDirectCmd integer;
  CLegDir integer;
  aAn integer;
  aLuna integer;
  aPrefixDoc            varchar2(2);
  aSeriaDoc             varchar2(20);
  aVALDOC               NUMBER(20, 7);
  aTVADOC               NUMBER(20, 7);
  aTVAOBLIG             NUMBER(20, 7);
  aCountBCAR number(20);
  aDelegat number(20);
  aPartGest number(20);
  aSysDateNir number(10);
  CONSTRESTOPERAT   INTEGER     := 0;
  CONSTOPERAT   INTEGER     := 0;
	TIPTRANZ     NUMBER(20) := 0;
  isSysMonthSameWithLucru NUMBER(1,0) := 0;
  sNUMEDELEGAT Varchar2(100);
  oldpu number(20,7);
  oldcodcontract1 number(20);
--  STINS_BEFORE_SPLITTVA NUMBER(20, 7);
BEGIN
  BEGIN
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADRESTNPNEOP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTRESTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTRESTOPERAT  := 0;
  END;

  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;SCADACCEPTATNEOPFURN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO CONSTOPERAT FROM DUAL;
    EXCEPTION WHEN OTHERS THEN CONSTOPERAT  := 0;
  END;

  Actualizeaza_CodContract1;
  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  SELECT
    TIPDOC,TIPTRANZACTIE,
    OPERAT,
    ANULAT,
    CARNETDOC,
    NRDOC,
    PARTENER,
    CODGESTPROD,
    SUBUNITATEA,
    DATATVA, DATADOC,PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    MONEDA,
    CURS,
    NVL(TIPFACTURA, 0),
    NVL(TIPTRANZACTIE, 0),
    NVL(TVAINCASARE, 0),
    An,
    Luna,
    prefixdoc,
    seriadoc,
    VALDOC,
    TVADOC,
    delegat,
    case when tipdoc = 7 then codgestprod else partener end
  INTO
    TIPINTR,TIPTRANZ,
    aOperat,
    aAnulat,
    aCARNET,
    aNUMARDOC,
    aCODPART,
    aCODGESTPROD,
    aSUBUNITATEA,
    aDATATVA, aDataDoc,
    adoc,
    aCODMONEDA,
    aCURS,
    aTIPFACTURA,
    aTIPTRANZACTIE,
    aTVAINCASARE,
    aAn,
    aLuna,
    aPrefixDoc,
    aSeriaDoc,
    aVALDOC,
    aTVADOC,
    aDelegat,
    aPartGest
  FROM TMP_INTRARI;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (TIPINTR);
  aTipImport := 0;
  if TIPINTR in (1,2) then
    BEGIN
      select Nvl(TipImport,0) into aTipImport from TMP_DVI;
      EXCEPTION WHEN OTHERS THEN aTipImport := 0;
    END;
  end if;
  aTIPDOCNirStoc1 := TIPIntr - 2*TIPIntr*aTipImport;

  IF NVL(aCURS, 0) = 0 THEN aCURS := 1;
  END IF;

  aSysDateNir := to_number(coalesce(PKG_CATEGCONST.GetValConstanta(&apos;SysDateNir&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),&apos;0&apos;));

  isSysMonthSameWithLucru := 0;
  if (extract(month from sysdate) =  PKG_GLOBALS.LUNALUCRU)
     and (extract(year from sysdate) = PKG_GLOBALS.ANLUCRU) then
    isSysMonthSameWithLucru := 1;
  end if;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    delete tmp_manevra_intr1;
  end if;

  delete tmp_manevra;
  insert into tmp_manevra(codunic)
  select ns11.codnirstoc
  from tmp_nirstoc_initial tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
       inner join nirstoc1 ns11 on ns11.codcomanda1 = ns1.codcomanda1
       inner join comanda1 c1 on c1.codcomanda1 = ns1.codcomanda1
  where ns1.codcomanda1 &gt; 0
  union
  select ns1.codnirstoc
  from tmp_nirstoc_initial tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
  where nvl(ns1.codcomanda1,0) = 0
  union
  select ns11.codnirstoc
  from tmp_nirstoc tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
       inner join nirstoc1 ns11 on ns11.codcomanda1 = ns1.codcomanda1
       inner join comanda1 c1 on c1.codcomanda1 = ns1.codcomanda1
  where ns1.codcomanda1 &gt; 0 and tmp.codnirstoc &gt; 0
  union
  select ns1.codnirstoc
  from tmp_nirstoc tmp
       inner join nirstoc1 ns1 on tmp.codnirstoc = ns1.codnirstoc
  where nvl(ns1.codcomanda1,0) = 0 and tmp.codnirstoc &gt; 0
  union
  select ns1.codnirstoc
  from intrari1_man ii
       inner join intrlink l on l.codintr1 = ii.codintr1
       inner join intrari1 i1 on i1.codintr1 = l.codlinieaviz
       inner join nirstoc ns on ns.codintr1 = i1.codintr1
       inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
  union
  select ns1.codnirstoc
  from TMP_INTRARI1 ii
       inner join tmp_intrlink l on l.codintr1 = ii.codintr1
       inner join intrari1 i1 on i1.codintr1 = l.codlinieaviz
       inner join nirstoc ns on ns.codintr1 = i1.codintr1
       inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc;

 IF TIPINTR IN (1, 2, 3, 4, 9) THEN
  UPDATE TMP_GENERAL
  SET DATATVA = NVL(aDATATVA, aDATADOC)
  WHERE SEMNIFICATIE = 100;
 END IF;

  CDirectCmd := pkg_categconst.GetValConstanta(&apos;LegaturaCmdIntrProd&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU);
  CLegDir := pkg_categconst.GetValConstanta(&apos;LinieNPLinieCmdInt&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU);

  aCountBCAR := 0;
  IF Operation = 0 THEN  -- UPDATE
    select count(1) into aCountBCAR
    from tmp_intrari1 i1
         inner join bcar b on i1.codintr1 = b.coddoc1 and b.tipdoc = tipintr
    where (aDelegat &lt;&gt; b.coddelegat or aPartGest &lt;&gt; b.codpartener) and i1.codintr1 &gt; 0;
-- Master INTRARI
    SELECT  CodIntr INTO RecId FROM TMP_INTRARI;

    begin
      select coalesce(operat,0) into OLDOPERAT from intrari where codintr = recid;
    exception when others then OLDOPERAT := 0;
    end;
    if (aSysDateNir = 4) and (aOperat = 1) and (OLDOPERAT = 0) and (isSysMonthSameWithLucru = 1) then
      update tmp_nir set datanir = trunc(sysdate);
    end if;

    UPDATE INTRARI
    SET (TipDoc, Anulat, Blocat, Operat, PrefixDoc, NrDoc, DataDoc,
            Partener, NrAviz, CarnetDoc, ValDoc, TVADoc, Majorari, An,
            Luna, Obs, Satelit, Complex, CODSUBUNIT, CODFISCAL, CONTSUPLIM,
            SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA,
            TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA, TIPTVA, MONEDA, CURS,
            SCHIMB,CODFORMATIE, IDIMPORT, DELEGAT, MIJLTRANSP, NRTRANSP, ProRata,
            CODCONTRACT, CODAUTO, ExclusPlata, FaraReg, TVAINCASARE, TVAINCASARE_F,
            CodAnaliza, CURSDOC, Custodie, Transportator, VALTRANSPORT, FACTSIMPLIF, AGENT,
            CURSNIR, STADIUWMS,
            DATAREFSCAD, DATATVA, AUTOFACTURARE,TIPLIVRARE, NATURATRANZ, MODTRANSP, ORDONANTAT,
            EXPORTKLG, EXPORTATKLG, PROCSTOPAJ, TipSAFT, RotEFact, SPLITTVA, TipET, IS_ETRANSP, iddescarcare, ValDocEFACT,
            Aprobat    ) =
      (SELECT
         TipDoc, Anulat, Blocat, Operat, PrefixDoc, NrDoc, DataDoc,
         Partener, NrAviz, CarnetDoc, ValDoc, TVADoc, Majorari, An,
         Luna, Obs, Satelit, Complex, CODSUBUNIT, CODFISCAL, CONTSUPLIM,
         SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA,
         TIPTRANZACTIE, NRI, CODGESTPROD, SUBUNITATEA, TIPTVA, MONEDA, CURS,
         SCHIMB,CODFORMATIE, IDIMPORT, DELEGAT, MIJLTRANSP, NRTRANSP, ProRata,
         CODCONTRACT, CODAUTO, ExclusPlata, FaraReg, TVAINCASARE, TVAINCASARE_F,
         CodAnaliza, CURSDOC, Custodie, Transportator, VALTRANSPORT, FACTSIMPLIF, AGENT,
         CURSNIR, STADIUWMS,
         DATAREFSCAD, DATATVA, AUTOFACTURARE,TIPLIVRARE, NATURATRANZ, MODTRANSP, ORDONANTAT,
         EXPORTKLG, EXPORTATKLG, PROCSTOPAJ, TipSAFT, RotEFact, SPLITTVA, TipET, is_eTransp, iddescarcare, ValDocEFACT,
         Aprobat
       FROM TMP_INTRARI)
    WHERE CodIntr = RecId ;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

   DELETE FROM OBLIGPIF
   WHERE
   CODGENERAL IN (SELECT CODGENERAL FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR) AND
   CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

   DELETE FROM GENERAL WHERE CODDOC = RecID AND TIPDOC = TIPINTR AND
   CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

   DELETE FROM STINGERE WHERE CODSTINGERE IN
   (SELECT CODSTINGERE FROM TMP_STINGERE_INITIAL WHERE CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE));

-- Detail GENERAL
    FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
      IF NVL(v_rec.CODGENERAL, 0) &gt; 0  THEN
        UPDATE GENERAL G
        SET
          TIPDOC       = v_rec.TIPDOC,
          CODDOC       = v_rec.CODDOC,
          MONEDA       = v_rec.MONEDA,
          CURS         = v_rec.CURS,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          ICONTAVANS   = v_rec.ICONTAVANS,
          PROCTVAAVANS = v_rec.PROCTVAAVANS,
          TVA          = v_rec.TVA,
          ExclusPlata  = v_rec.ExclusPlata,
          DataTVA      = v_rec.DataTVA,
          FaraReg      = v_rec.FaraReg
        WHERE
        G.CODGENERAL = v_rec.CODGENERAL;
      ELSE
       SELECT seq_GENERAL_CODGENERAL.Nextval INTO VCOD from Dual;
       INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg )
       VALUES (VCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.SEMNIFICATIE, v_rec.ICONTAVANS,  v_rec.PROCTVAAVANS,  v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA, v_rec.FaraReg);

       UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD  WHERE CODGENERAL = v_Rec.CODGENERAL;

      END IF;
    END LOOP;

-- Detail OBLIGPIF
    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF) LOOP

      IF NVL(v_rec.CODOBLIGPIF, 0) &gt; 0 THEN

        IF aVALDOC = 0 THEN aTVAOBLIG := 0;
        ELSE
          aTVAOBLIG := V_REC.VALOARE * aTVADOC/aVALDOC;
        END IF;

        --STINS_BEFORE_SPLITTVA := PKG_SPLITTVA.TVASTINS_OBLIG_BEFORE_SPLIT(V_REC.CODOBLIGPIF, V_REC.VALOARE, aTVAOBLIG);


        UPDATE OBLIGPIF
        SET
          CODGENERAL   = v_rec.CODGENERAL,
          TERMEN       = v_rec.TERMEN,
          VALOARE      = NVL(v_rec.VALOARE, 0),
          SPLITTVA     = V_REC.SPLITTVA,
          DINCARETVA   = CASE
                           WHEN V_REC.VALOARE = 0 THEN 0
                           ELSE NVL(v_rec.DINCARETVA, 0)
                         END,
          REST         =
           (
            CASE
              WHEN V_REC.SEMNIFICATIE =  111 THEN NULL
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 111 AND v_rec.VALOARE &gt; 0 THEN v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              WHEN V_REC.SEMNIFICATIE &lt;&gt; 111 AND v_rec.VALOARE &lt; 0 THEN v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
            END),

          RESTTVA         =
           (
            CASE
              WHEN v_rec.VALOARE &gt; 0 THEN NVL(v_rec.DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              WHEN v_rec.VALOARE &lt; 0 THEN NVL(v_rec.DINCARETVA, 0) + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
            END
           ),
          CODPART      = v_rec.CODPART,
          ICONT        = v_rec.ICONT,
          TIPPLATA     = v_rec.TIPPLATA,
          CODCENTRU    = V_REC.CODCENTRU,
          MAJORARI     = v_rec.MAJORARI,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          TIP          = v_rec.TIP,
          CODANALIZANOD= V_REC.CODANALIZANOD
        WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;
      ELSE
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
        UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
        UPDATE  TMP_INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

        INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP,CODANALIZANOD, DINCARETVA, RESTTVA, SPLITTVA)
        VALUES (VCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, V_REC.CODCENTRU,  v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP,
        V_REC.CODANALIZANOD, V_REC.DINCARETVA, V_REC.DINCARETVA, V_REC.SPLITTVA);
      END IF;
    END LOOP;


    -- STINGERE
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE);
      END IF;
    END LOOP;

-- detail INTRDOCTRANSP
   DELETE FROM INTRDOCTRANSP WHERE CODINTR = RECID AND COD NOT IN (SELECT COD FROM TMP_INTRDOCTRANSP);
   FOR V_REC IN (SELECT * FROM TMP_INTRDOCTRANSP)
   LOOP
     IF V_REC.COD &lt; 0 THEN
       INSERT INTO INTRDOCTRANSP(COD, CODINTR, CODINTRLINK, VALTRANSPORT)
       VALUES (SEQ_INTRDOCTRANSP_COD.NEXTVAL, RECID, V_REC.CODINTRLINK, V_REC.VALTRANSPORT);
     ELSE
       UPDATE INTRDOCTRANSP
       SET
         VALTRANSPORT = V_REC.VALTRANSPORT
       WHERE
         COD = V_REC.COD;
     END IF;
   END LOOP;

-- Detail INTRLINK
    DELETE FROM INTRLINK WHERE CODINTR1 IN
    ( SELECT CODINTR1 FROM INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN (SELECT CodIntr1 FROM TMP_INTRLINK)
     );

-- Detail INTRASTEPTLINK
    DELETE FROM INTRASTEPTLINK WHERE CODINTR1 IN
    ( SELECT CODINTR1 FROM INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN (SELECT CodIntr1 FROM TMP_INTRASTEPTLINK)
     );


-- Detail INTRARI1
--  DELETE FROM INTRARI1 WHERE CodIntr = RecId ;

  FOR V_REC IN
  (
    SELECT * FROM INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN
    (SELECT CodIntr1 FROM TMP_INTRARI1)
  )
  LOOP
     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1)
     LOOP

       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC = 52) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
       END LOOP;


       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC = 52;
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1;
     DELETE FROM TAXDECL WHERE TipDoc = TIPINTR and CODDOC1 = V_REC.CODINTR1;

     if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
       pkg_miscari_interne.SetDoCommit(False);
       for v_mf in (select t.codtransf
                    from intrari1 i1
                         inner join imbmifixlink l on l.codintr1 = i1.codintr1
                         inner join transf1 t1 on t1.codtransf1 = l.codtransf1
                         inner join transf t on t.codtransf = t1.codtransf
                    where i1.codintr = recid and i1.codintr1 not in (SELECT CodIntr1 FROM TMP_INTRARI1)
                    ) loop
         pkg_miscari_interne.SP_DELETERECORD(v_mf.codtransf);
       end loop;
       pkg_miscari_interne.SetDoCommit(True);
     end if;

     IF TIPINTR = 2 AND NVL(V_REC.CODINTR1LINK, 0) &lt;&gt; 0 THEN
       FOR V_REC_S IN (SELECT CODINTR1STORNO FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1LINK)
       LOOP
         IF NVL(V_REC_S.CODINTR1STORNO, 0) &lt;&gt; 0 THEN
           UPDATE BCAR
           SET
             CODDOC1 = V_REC_S.CODINTR1STORNO
           WHERE
             TIPDOC = 2 AND CODDOC1 = V_REC.CODINTR1;
         END IF;
       END LOOP;
     END IF;

     -- fisa mas
     if TIPINTR = 7 then
       FOR V_TMP IN (SELECT FM1.CODFISAMAS1
                     FROM FISAMAS1 FM1
                          INNER JOIN FISAMAS FM ON FM1.CODFISAMAS = FM.CODFISAMAS
                     WHERE FM.CODINTR1 = V_REC.CODINTR1) LOOP
         DELETE FISAMAS1 WHERE CODFISAMAS1 = V_TMP.CODFISAMAS1;
       END LOOP;

       BEGIN
         SELECT NVL(CARNETDOC,0), NRDOC INTO ACARNETFISA, ANRFISA FROM FISAMAS WHERE CODINTR1 = V_REC.CODINTR1;
       EXCEPTION WHEN OTHERS THEN ACARNETFISA := 0;
       END;
       DELETE FROM FISAMAS WHERE CODINTR1 = V_REC.CODINTR1;
       IF ACARNETFISA &gt; 0 THEN
         PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETFISA, ANRFISA);
         PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETFISA);
       END IF;
     end if;
     IF TIPINTR = 7 and aTIPTRANZACTIE = 10 THEN
       --update utilaje2
       for v_tmp in (select u2c.codutilaj2c
                     from intrprodlink l
                          inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                          inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                     where l.codintr1 = v_rec.codintr1
                     ) loop
         update utilaje2c set indexc = null, dataindexc = null, datastart = null, dataend = null where codutilaj2c = v_tmp.codutilaj2c;
       end loop;
     END IF;
     DELETE FROM INTRPRODLINK WHERE CODINTR1 = V_REC.CODINTR1;
     DELETE FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1;

     IF NVL(V_REC.CODINTR1LINK, 0) = 0 THEN
       begin
				 Select CodBCAR into aCodBCAR from BCAR WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;
       exception when others then
				 aCodBCAR := 0;
	     end;
       if coalesce(aCodBCAR,0) &gt; 0 then
         insert into trigar_modif (CodModif, datamodif, usermodif, Cod, codmaster, tablename, FieldName, oldvalue,newvalue)
         Values( SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, aCodBCAR,aCodBCAR, &apos;BCAR&apos;, &apos;CODDOC1&apos;,
                 V_REC.CodIntr1, &apos;Null+POSTREC+CODINTR1LINK=0&apos;);

         UPDATE BCAR
         SET TIPDOC = NULL,
             CODDOC1 = NULL,
             USERIDBLOCAJ = NULL
         WHERE
             CODDOC1 = V_REC.CODINTR1
             AND TIPDOC = TIPINTR;
         end if;
     END IF;
    delete nparc2 where codintr1 = v_rec.codintr1;
    if tipintr = 7 then
      for v_pp in (select pp.idinreg
                    from intrari1 i1
                         inner join pplink pp on pp.codintr1 = i1.codintr1
                    where i1.codintr1 = v_rec.codintr1
                    ) loop
        update predariplus set
          NRCMD = null,
          DATACMD = null,
          FSC = null,
          SCHIMB = null,
          FORMATIE = null,
          NRNP = null,
          DATANP = null,
          USERIDBLOCAJ = null,
          CODCOMANDA1 = null,
          CANTITATEWME = null,
          DATAWME = null
        where idinreg = v_pp.idinreg;
      end loop;
    end if;
  END LOOP ;

--    DELETE FROM INTRARI1 WHERE CodIntr = RecID AND CodINTR1 NOT IN
 --   (SELECT CodIntr1 FROM );

    FOR v_rec IN (SELECT * FROM TMP_INTRARI1 ORDER BY IndexLocal) LOOP
			IF TIPINTR = 7 THEN
				DoPU    := InStr(V_REC.OBS, &apos;&lt;PU&gt;&apos;); --inainte musai de PKG_IESIRI.GetLinieComInt(V_REC.OBS,V_REC.OBS);
				IF Nvl(V_REC.CodCmdInt1,0) = 0 THEN
					V_REC.CodCmdInt1 := PKG_IESIRI.GetLinieComInt(V_Rec.CodObiect,V_REC.OBS,V_REC.OBS);
					if Nvl(V_REC.CodCmdInt1,0) &gt; 0 then
						INSERT INTO TMP_INTRPRODLINK (CODINTR1, CODLINIECOMANDA, CODCOMANDA1, CANT)
						VALUES  (v_rec.CODINTR1, (Select codCMDPRODMAT from CMDPRODMAT WHERE CODCOMANDA1 = V_REC.CodCmdInt1 and TIP = 0), V_REC.CodCmdInt1, v_rec.CANT);
					end if;
				end if;
				if (DoPU &gt; 0) and (v_Rec.Cant &lt;&gt; 0) and NVL(V_REC.CodCmdInt1,0) &gt; 0 then
					V_REC.OBS := Substr(V_REC.Obs,  1,  DoPU - 1 )||Substr(V_REC.Obs,  DoPU + 4, 400 );
					ValProd  := GET_VALOARE_PROD(V_REC.CodCmdInt1);
				  PretProd := Round(GET_REGIE_FIXA(V_REC.CodObiect) + ValProd / v_Rec.Cant,2);
					V_REC.PU := PretProd;
					update TMP_NIRSTOC NS set Ns.Pret = PretProd, NS.Adaos = 0 where NS.Codintr1 = V_REC.CodIntr1;
					insert into TMP_Jurnal1 (CodDoc, TipDoc, An ,Luna, Dirty) values (RecId, TipIntr, PKG_GLOBALS.AnLucru,PKG_GLOBALS.LUNALUCRU,1);
					insert into TMP_Jurnal (CodDoc, TipDoc, An ,Luna) values (RecId, TipIntr, PKG_GLOBALS.AnLucru,PKG_GLOBALS.LUNALUCRU);
					update TMP_INTRARI1 set PU = PretProd where Codintr1 = V_REC.CodIntr1;
					update TMP_INTRARI Set ValDoc = (Select Sum(Cant*PU) from tmp_intrari1);
				end if;
			end if;

      IF NVL(v_rec.CodIntr1, 0) &gt; 0 THEN
        select pu, codcontract1 into oldpu, oldcodcontract1 from intrari1 where codintr1 = v_rec.codintr1;
        delete nparc2 where codintr1 = v_rec.codintr1;
        if v_rec.codobiect in (
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRCA&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtCASCO&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtITP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRovigneta&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
                              )
           and v_rec.codauto &gt; 0 then
          begin
            select nvl(max(indexlocal),0) + 1 into aCount from nparc2 where cod = v_rec.codauto;
          exception when others then aCount := 1;
          end;
          insert into nparc2(codnparc2, indexlocal, sn, eliberat, expira, cod, obs, valoare, codintr1, denumire, atentie)
          values (seq_nparc2_codnparc2.nextval, aCount, v_rec.nrcertif, aDataDoc, nvl(v_rec.tg,v_rec.termencontract), v_rec.codauto, v_rec.obs, v_rec.cant * v_rec.pu + v_rec.tva, v_rec.codintr1, (select denumire from nartobj where codobiect = v_rec.codobiect),
                  (select atentionare from nautorizatiiauto where codserviciu = v_rec.codobiect));
        end if;
        if oldcodcontract1 &gt; 0 and oldcodcontract1 &lt;&gt; v_rec.codcontract1 then
          --actualizez si bcar-ul daca exista
          update bcar set codcontract1 = v_rec.codcontract1
          where coddoc1 = v_rec.codintr1 and tipdoc = tipintr and codcontract1 &gt; 0;
        end if;
        UPDATE INTRARI1 SET
           IndexLocal       = v_rec.IndexLocal,
           TipLinie         = v_rec.TipLinie,
           UmSec            = v_rec.UmSec,
           An               = v_rec.An,
           Luna             = v_rec.Luna,
           ContServ         = v_rec.ContServ,
           CONTDISCOUNT     = v_rec.CONTDISCOUNT,
           ZILE             = v_rec.ZILE,
           ZILECMD          = v_rec.ZILECMD,
           GestAct          = v_rec.GestAct,
           CodObiect        = v_rec.CodObiect,
           PretOrig         = v_rec.PretOrig / NVL(v_rec.Paritate, 1),
           PU               = v_rec.PU   / NVL(v_rec.Paritate, 1),
           Cant             = v_rec.Cant * NVL(v_rec.Paritate, 1),
           TVA              = v_rec.TVA,
           AdDim            = v_rec.AdDim,
           MIFIX            = v_rec.MIFIX,
           CODOBIECTORIG    = V_REC.CODOBIECTORIG,
           CODAUTO          = V_REC.CODAUTO,
           TVANEDED         = V_REC.TVANEDED,
           PARITATEORIG     = V_REC.PARITATEORIG,
           COEFDISCMAJ      = v_rec.COEFDISCMAJ,
           OBS              = v_rec.OBS,
           CODOBLIGSTORNO   = v_rec.CODOBLIGSTORNO,
           CODLINIEDOCIMP   = V_REC.CODLINIEDOCIMP,
           TIPDOCIMP        = V_REC.TIPDOCIMP,
           IMPOZABIL        = V_REC.IMPOZABIL,
           CURSFACTURAAVANS = v_rec.CURSFACTURAAVANS,
           CODMIFIX         = V_REC.CODMIFIX,
           CODINTR1STORNO   = V_REC.CODINTR1STORNO,
           PRELUAT          = V_REC.PRELUAT,
           CUSTODIE         = V_REC.CUSTODIE,
           CodOferta1       = V_REC.CodOferta1,
           CODCENTRU        = V_REC.CODCENTRU ,
           CONTASTEPTARE    = V_REC.CONTASTEPTARE,
           CODCMDINT1       = V_REC.CodCmdInt1,
           codcontract1     = V_REC.codcontract1,
           Taxa             = V_REC.Taxa,
           ROTVALTAXA       = V_REC.ROTVALTAXA,
           TERMENCONTRACT   = V_REC.TERMENCONTRACT,
           ICONTPART        = V_REC.ICONTPART,
           PRETUM1          = V_REC.PRETUM1,
           CODANALIZANOD    = V_REC.CODANALIZANOD,
           CODINTR1LINK     = V_REC.CODINTR1LINK,
           CODNIMOB         = V_REC.CODNIMOB,
           GESTPRODAVIZSUB  = v_rec.GESTPRODAVIZSUB,
-- SUNT PE FACTURA IN ASTEPTARE - RECALCULEZ RESTASTEPTARE
           RestAsteptare    =
           CASE
             WHEN v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND TIPINTR = 9 AND aTIPFACTURA = 9 AND aOperat = 1 AND aAnulat = 0 /* AND v_rec.CANT &gt; 0*/
             THEN v_rec.Cant * v_rec.Paritate -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  INTRASTEPTLINK IL
                  LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                WHERE
                IL.CODLINIEFACTURA = v_Rec.CodINTR1 AND I.TIPDOC = 2 AND I.OPERAT = 1 AND I.ANULAT = 0
               ) +
               (SELECT NVL(SUM(I1.CANT), 0) -- retururi
                FROM
                  INTRARI1 I1
                  INNER JOIN INTRARI I ON I.CODINTR   = I1.CODINTR
                WHERE
                  I1.CANT &lt; 0 AND I1.CODLINIEDOCIMP = v_Rec.CodINTR1 AND V_REC.TIPDOCIMP = 9 AND I.TIPFACTURA = 9 AND I.OPERAT = 1 AND I.ANULAT = 0
               )
             ELSE 0
           END,
-- SUNT PE AVIZ - RECALCULEZ RESTUL
           RestFact   =
           CASE
             WHEN v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND TIPINTR = 2 AND aOperat = 1 AND aAnulat = 0
             THEN v_rec.Cant * v_rec.Paritate -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                WHERE
                IL.CODLINIEAVIZ = v_Rec.CodINTR1
                AND (I.TIPDOC = 9 OR (I.TIPDOC = 5 AND I.TIPFACTURA = 10))
                AND I.OPERAT = 1 AND I.ANULAT = 0
               ) +
             (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
              FROM
                INTRARI1 AE1,
                INTRARI  AE
              WHERE
                AE1.CODINTR1STORNO = V_REC.CODINTR1 AND AE.CODINTR = AE1.CODINTR
               AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0
             )


             WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT la liniile de discount
             ELSE 0
           END,


-- SUNT PE IMBUNATATIRIO MF - RECALCULEZ RESTUL
           RestIMBMF   =
           CASE
             WHEN v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 AND aOperat = 1 AND aAnulat = 0
             THEN
               (
                CASE
                  WHEN TIPINTR = 3 THEN  v_rec.Cant * v_rec.PU * aCurs - NVL(V_REC.TVA, 0)
                  ELSE v_rec.Cant * v_rec.PU * aCurs
                END
               )
                -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODINTR1 = v_Rec.CodINTR1 AND T.OPERAT = 1 AND T.ANULAT = 0
               )
             ELSE 0
           END,

           NrCertif             = v_rec.NrCertif,
           CODCMD1AE            = V_REC.CODCMD1AE,
           TG                   = v_rec.TG,
           PUMaximal            = v_rec.PUMaximal,
           AdMax                = v_rec.AdMax,
           PURidicata           = v_rec.PURidicata,
           ProcAdaos            = v_rec.ProcAdaos,
           FURNAVIZSUBUNIT      = V_REC.FURNAVIZSUBUNIT,
           DATAACHIZAVIZSUBUNIT = V_REC.DATAACHIZAVIZSUBUNIT
        WHERE
           CodIntr1   = v_rec.CodIntr1;
        -- fisa mas
        if tipintr = 7 then
          select count(*) into aCount from fisamas where codintr1 = v_rec.codintr1;
          if aCount = 0 then
            select seq_fisamas_codfisamas.nextval into aCodFisaMas from dual;
            for v_tmp in (select codfisamas from tmp_fisamas where codintr1 = v_rec.codintr1) loop
              update tmp_fisamas1 set codfisamas = aCodFisaMas where codfisamas = v_tmp.codfisamas;
              INSERT INTO FISAMAS1
              (
                CODFISAMAS1,
                CODFISAMAS ,
                CODPRODMAS ,
                VALOARE    ,
                STARE      ,
                OBS
              )
              (SELECT
                 seq_fisamas1_codfisamas1.nextval,
                 CodFisaMas ,
                 CODPRODMAS  ,
                 VALOARE     ,
                 STARE       ,
                 OBS
               FROM TMP_FISAMAS1
               WHERE CodFisaMas = aCodFisaMas);
            end loop;

            for v_fis in (select * from TMP_FISAMAS WHERE CodIntr1 = v_rec.codintr1) loop
            INSERT INTO FISAMAS
              (CODFISAMAS,
               CODINTR1,
               NRDOC,
               DATADOC,
               CODRESPONSABIL,
               CODINSPECTOR  ,
               APROBAT,
               OBS,
               CARNETDOC,
               SERIADOC
              )
            values(
               aCodFisaMas,
               v_fis.CODINTR1,
               v_fis.NRDOC,
               v_fis.DATADOC,
               v_fis.CODRESPONSABIL,
               v_fis.CODINSPECTOR  ,
               v_fis.APROBAT,
               v_fis.OBS,
               v_fis.CARNETDOC,
               v_fis.SERIADOC);

             IF NVL(v_fis.CARNETDOC, 0) &lt;&gt; 0 AND NVL(v_fis.NRDOC, 0) &lt;&gt; 0 THEN
               PKG_CARNETEDOC.SOLVENUMARDOC(v_fis.CARNETDOC, v_fis.NRDOC);
             END IF;
             end loop;
          else
            select count(codfisamas) into aCount from tmp_fisamas where codintr1 = v_rec.codintr1;
            if aCount = 1 then
              select codfisamas into aCodFisaMas from tmp_fisamas where codintr1 = v_rec.codintr1;
              for v_fis in (select * from tmp_fisamas where codintr1 = v_rec.codintr1) loop
              update fisamas set
                (
                 NRDOC         ,
                 DATADOC       ,
                 CODRESPONSABIL,
                 CODINSPECTOR  ,
                 OBS           ,
                 APROBAT,
                 CARNETDOC,
                 SERIADOC
                 )
                =
                (select
                 v_fis.NRDOC         ,
                 v_fis.DATADOC       ,
                 v_fis.CODRESPONSABIL,
                 v_fis.CODINSPECTOR  ,
                 v_fis.OBS           ,
                 v_fis.APROBAT,
                 v_fis.CARNETDOC,
                 v_fis.SERIADOC
                 from dual) where codintr1 = v_rec.codintr1;

              IF (v_fis.CARNETDOC_I &lt;&gt; 0)AND(v_fis.NRDOC_I &lt;&gt; 0)AND(v_fis.CARNETDOC &lt;&gt; v_fis.CARNETDOC_I OR v_fis.NRDOC &lt;&gt; v_fis.NRDOC_I)
              THEN
                PKG_CARNETEDOC.RELEASENUMARDOC(v_fis.CARNETDOC_I, v_fis.NRDOC_I);
                PKG_CARNETEDOC.COMPACTEAZAINTERVALE(v_fis.CARNETDOC_I);
              END IF;

              IF NVL(v_fis.CARNETDOC, 0) &lt;&gt; 0 AND NVL(v_fis.NRDOC, 0) &lt;&gt; 0 THEN
                PKG_CARNETEDOC.SOLVENUMARDOC(v_fis.CARNETDOC, v_fis.NRDOC);
              END IF;

              delete from fisamas1 where codfisamas = aCodFisaMas;
              INSERT INTO FISAMAS1
              (
                CODFISAMAS1,
                CODFISAMAS ,
                CODPRODMAS ,
                VALOARE    ,
                STARE      ,
                OBS
              )
              (SELECT
                 seq_fisamas1_codfisamas1.nextval,
                 CodFisaMas  ,
                 CODPRODMAS  ,
                 VALOARE     ,
                 STARE       ,
                 OBS
               FROM TMP_FISAMAS1 where codfisamas = aCodFisaMas);
              end loop;
            end if;
          end if;
          IF aTIPTRANZACTIE = 10 THEN
            --update utilaje2
            for v_tmp in (select u2c.codutilaj2c
                          from intrprodlink l
                               inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                               inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                          where l.codintr1 = v_rec.codintr1
                          ) loop
              update utilaje2c set indexc = v_rec.indexinterventie, datastart = v_rec.datastart, dataend = v_rec.dataend where codutilaj2c = v_tmp.codutilaj2c;
            end loop;
         END IF;
        end if;

        BEGIN
          SELECT COUNT(*) INTO NRCHELT FROM CHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1;
          EXCEPTION WHEN OTHERS THEN NRCHELT :=0;
        END;

        IF NRCHELT &gt; 0 THEN
          IF TIPINTR = 3
            THEN 
              aVALOARE := CASE
                            WHEN  COALESCE(V_REC.TVANEDED, 0) = 0 THEN ROUND((V_REC.PU * V_REC.CANT - V_REC.TVA ) * NVL(ACURS, 1), 2)
                            WHEN  COALESCE(V_REC.TVANEDED, 0) = 1 THEN ROUND((V_REC.PU * V_REC.CANT ) * NVL(ACURS, 1), 2)
                            ELSE  ROUND((V_REC.PU * V_REC.CANT - V_REC.TVA/2 ) * NVL(ACURS, 1), 2)
                          END;    
            ELSE 
              aVALOARE := CASE 
                            WHEN COALESCE(V_REC.TVANEDED, 0) = 0 THEN ROUND((V_REC.PU * V_REC.CANT) * NVL(ACURS, 1), 2)
                            WHEN COALESCE(V_REC.TVANEDED, 1) = 1 THEN ROUND((V_REC.PU * V_REC.CANT + V_REC.TVA) * NVL(ACURS, 1), 2)              
                            ELSE ROUND((V_REC.PU * V_REC.CANT + V_REC.TVA/2) * NVL(ACURS, 1), 2) 
                          END;  
          END IF;

          FOR V_CHELT1 IN (
            SELECT CA1.CODCHELTAVANS1, CA1.CODCHELTAVANS
            FROM CHELTAVANS CA, CHELTAVANS1 CA1
            WHERE CA.CODINTR1 = V_REC.CODINTR1 AND CA1.CODCHELTAVANS = CA.CODCHELTAVANS AND VALOARE &lt;&gt; aVALOARE
          )
          LOOP
            UPDATE CHELTAVANS1
            SET   VALOARE = aVALOARE
            WHERE CODCHELTAVANS1 = V_CHELT1.CODCHELTAVANS1;

            UPDATE JURNAL1
            SET  DIRTY = 1
            WHERE CODDOC = V_CHELT1.CODCHELTAVANS AND TIPDOC = 52;
          END LOOP;
        END IF;
        PKG_CANTAR.UNLOCK_RECORDS(TIPINTR, v_rec.CodIntr1);
        PKG_BCAR.UNLOCK_RECORDS(TIPINTR, v_rec.CodIntr1);

        if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
          for v_mf in (select nsp.pret + i1.cant * i1.pu * aCurs ValNou, ns.pret ValVechi, t1.codtransf1, ns.codnirstoc,
                              t.codtransf, t.tipdoc
                       from intrari1 i1
                            inner join imbmifixlink l on l.codintr1 = i1.codintr1
                            inner join transf1 t1 on t1.codtransf1 = l.codtransf1
                            inner join transf t on t.codtransf = t1.codtransf
                            inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                            inner join nirstoc nsp on nsp.codnirstoc = ns.codnirstocparinte
                       where i1.codintr = recid and i1.codintr1 = v_rec.codintr1
                       ) loop
            if v_mf.valnou &lt;&gt; v_mf.valvechi then
              update transf1 set pu = v_mf.valnou where codtransf1 = v_mf.codtransf1;
              update transf set valdoc = v_mf.valnou where codtransf = v_mf.codtransf;
              update nirstoc set pret = v_mf.valnou where codnirstoc = v_mf.codnirstoc;
              update jurnal1 set dirty = 1 where coddoc = v_mf.codtransf and tipdoc = v_mf.tipdoc;
              PKG_Jurnal.setDirtyNirStoc(V_MF.CODNIRSTOC, V_MF.ValNou, &apos;0&apos;, 0);
            end if;
          end loop;
        end if;
        vcod := v_rec.codintr1;
      ELSE
        SELECT seq_INTRARI1_CodIntr1.Nextval INTO VCOD from Dual;
        UPDATE TMP_JURNAL1  SET IndexLocal = vCod WHERE indexlocal = v_rec.codintr1;
        UPDATE TMP_INTRARI1 SET CodIntr1 = vCod where codintr1 = v_rec.codintr1;
        UPDATE TMP_INTRARI1 SET CODINTR1LINK = VCOD WHERE codintr1LINK = v_rec.codintr1;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI1&apos;, VCOD, V_REC.CODINTR1);

/*        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIP1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIF1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1PF SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1SUB SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;


        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1FAST SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;


       IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIAE1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

       IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIFA1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
       END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1AST SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARICF1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
        END IF;

*/

        if v_rec.codobiect in (
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRCA&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtCASCO&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtITP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRovigneta&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
                              )
           and v_rec.codauto &gt; 0 then
          begin
            select nvl(max(indexlocal),0) + 1 into aCount from nparc2 where cod = v_rec.codauto;
          exception when others then aCount := 1;
          end;
          insert into nparc2(codnparc2, indexlocal, doc, sn, eliberat, expira, cod, obs, valoare, codintr1, denumire, atentie)
          values (seq_nparc2_codnparc2.nextval, aCount, aNumarDoc, v_rec.nrcertif, aDataDoc, nvl(v_rec.tg,v_rec.termencontract), v_rec.codauto, v_rec.obs, v_rec.cant * v_rec.pu + v_rec.tva, vcod,
                  (select denumire from nartobj where codobiect = v_rec.codobiect), (select atentionare from nautorizatiiauto where codserviciu = v_rec.codobiect));
        end if;

        if v_Rec.Tiplinie = &apos;S&apos; and pkg_categconst.ESTEIMBUNATATIREMIFIX(v_rec.contserv) &gt; 0 and
           PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 and v_rec.codmifix &gt; 0 then
          for v_xxx in (select mfix1.codnirstoc
                        from mifix1 mfix1
                        where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
            insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
            values(vCod, v_xxx.codnirstoc, v_rec.cant * v_rec.pu * aCurs);
            exit;
          end loop;
        end if;

        INSERT INTO INTRARI1 (
          CodIntr1, CodIntr, IndexLocal, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT,
          ZILE, ZILECMD, GestAct, CodObiect,
          PretOrig,PU,Cant,
          TVA, AdDim, MIFIX, CODOBIECTORIG, CODAUTO, TVANEDED, PARITATEORIG, COEFDISCMAJ, OBS,
          RestFact,
          NrCertif, CODCMD1AE, TG,PUMaximal, AdMax,PURidicata, ProcAdaos,
          FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CODLINIEDOCIMP, TIPDOCIMP, CURSFACTURAAVANS, CODMIFIX,
          RESTIMBMF, CODINTR1STORNO, PRELUAT, CUSTODIE, CODOFERTA1,CODCENTRU, CONTASTEPTARE, RESTASTEPTARE, CODCMDINT1, codcontract1, Taxa, ROTVALTAXA,
          TERMENCONTRACT, ICONTPART,  PRETUM1, CODANALIZANOD,
          CODINTR1LINK,
          CODNIMOB,
          IMPOZABIL,GESTPRODAVIZSUB)
        VALUES (
          vCod,  RecID, v_rec.IndexLocal , v_rec.TipLinie,  v_rec.Umsec,  v_rec.An,  v_rec.Luna,  v_rec.ContServ, V_REC.CONTDISCOUNT,
          V_REC.ZILE, V_REC.ZILECMD, v_rec.GestAct,  v_rec.CodObiect,
          v_rec.PretOrig /  NVL(v_rec.Paritate, 1),  v_rec.PU /  NVL(v_rec.Paritate, 1), v_rec.Cant *  NVL(v_rec.Paritate, 1),
          v_rec.TVA, v_rec.AdDim, V_REC.MIFIX, V_REC.CODOBIECTORIG, V_REC.CODAUTO, V_REC.TVANEDED, V_REC.PARITATEORIG, V_REC.COEFDISCMAJ, V_REC.OBS,
          CASE
            WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
            ELSE v_rec.Cant *  v_rec.Paritate
          END,
          v_rec.NrCertif,  V_REC.CODCMD1AE, v_rec.TG,  v_rec.PUMaximal, v_rec.AdMax,  v_rec.PURidicata, v_rec.ProcAdaos,
          V_REC.FURNAVIZSUBUNIT, V_REC.DATAACHIZAVIZSUBUNIT, V_REC.CODOBLIGSTORNO, V_REC.CODLINIEDOCIMP, V_REC.TIPDOCIMP, V_REC.CURSFACTURAAVANS, V_REC.CODMIFIX,
          CASE WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0
            THEN
              (
               CASE
                 WHEN TIPINTR = 3 THEN  v_rec.Cant * v_rec.PU * aCurs - NVL(V_REC.TVA, 0)
                 ELSE v_rec.Cant * v_rec.PU * aCurs
               END
               )
--            V_REC.PU * V_REC.CANT * aCurs
            ELSE 0
            END,
          V_REC.CODINTR1STORNO, V_REC.PRELUAT, V_REC.CUSTODIE, V_REC.CODOFERTA1,V_REC.CODCENTRU,
          V_REC.CONTASTEPTARE,
          CASE
            WHEN  TIPINTR = 9 AND aTIPFACTURA = 9  /*AND V_REC.CANT &gt; 0*/ THEN v_rec.Cant *  v_rec.Paritate
            ELSE 0
          END, V_REC.CodCmdInt1, V_REC.codcontract1, V_REC.Taxa, V_REC.ROTVALTAXA, V_REC.TERMENCONTRACT, V_REC.ICONTPART, V_REC.PRETUM1, V_REC.CODANALIZANOD,
          (SELECT CODINTR1LINK FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = VCOD), -- stupid dar doar asa se poate
          V_REC.CODNIMOB,
          V_REC.IMPOZABIL,v_rec.GESTPRODAVIZSUB
        );

        if TipIntr = 7 then
          UPDATE TMP_FISAMAS SET CODINTR1 = vCod where codintr1 = v_rec.codintr1;
          for v_tmp in (select * from tmp_fisamas) loop
            select seq_fisamas_codfisamas.nextval into aCodFisaMas from dual;
            update fisamas1 set codfisamas = aCodFisaMas where codfisamas = v_tmp.codfisamas;
            INSERT INTO FISAMAS
            (CODFISAMAS    ,
             CODINTR1      ,
             NRDOC         ,
             DATADOC       ,
             CODRESPONSABIL,
             CODINSPECTOR  ,
             OBS           ,
             APROBAT,
             CARNETDOC,
             SERIADOC
            )
            values(
               aCODFISAMAS    ,
               V_TMP.CODINTR1      ,
               V_TMP.NRDOC         ,
               V_TMP.DATADOC       ,
               V_TMP.CODRESPONSABIL,
               V_TMP.CODINSPECTOR  ,
               V_TMP.OBS           ,
               V_TMP.APROBAT,
               V_TMP.CARNETDOC,
               V_TMP.SERIADOC);

            IF NVL(v_tmp.CARNETDOC, 0) &lt;&gt; 0 AND NVL(v_tmp.NRDOC, 0) &lt;&gt; 0 THEN
              PKG_CARNETEDOC.SOLVENUMARDOC(v_tmp.CARNETDOC, v_tmp.NRDOC);
            END IF;

             INSERT INTO FISAMAS1
                (
                  CODFISAMAS1,
                  CODFISAMAS ,
                  CODPRODMAS ,
                  VALOARE    ,
                  STARE      ,
                  OBS
                )
                (SELECT
                   seq_fisamas1_codfisamas1.nextval,
                   aCodFisaMas ,
                   FM1.CODPRODMAS  ,
                   FM1.VALOARE     ,
                   FM1.STARE       ,
                   FM1.OBS
                 FROM TMP_FISAMAS1 FM1
                      inner join tmp_fisamas FM on fm.codfisamas = fm1.codfisamas
                 where FM.Codintr1 = vCod);
          end loop;
        end if;
        UPDATE TMP_NIRSTOC SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
        UPDATE TMP_LIVR1 SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
        UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
        UPDATE TMP_INTRASTEPTLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
        UPDATE TMP_INTRPRODLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
        PKG_CANTAR.UPDATE_RECORDS(TIPINTR, v_rec.CodIntr1, vCOD);
        PKG_BCAR.UPDATE_RECORDS(TIPINTR, v_rec.CodIntr1, vCOD);
        for v_tmp in (select u2c.codutilaj, nvl(tmp.indexinterventie,0) indexb
                      from tmp_intrprodlink l
                           inner join intrari1 i1 on l.codintr1 = i1.codintr1
                           inner join TMP_INTRARI1 tmp on tmp.codintr1 = i1.codintr1
                           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                           inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                           inner join utilaje2 u2 on u2.codutilaj2 = u2c.codutilaj2
                           inner join ninterventiiauto iu on iu.codinterventiiauto = u2.interventie
                      where l.codintr1 = vCod and nvl(iu.accidentala,0)=0 and nvl(tmp.indexinterventie,0) &gt; 0) loop
           insert into utilaje3(codutilaj3, codutilaj, databord, indexbord, an, luna)
           values (seq_utilaje3_codutilaj3.nextval, v_tmp.codutilaj, to_date(sysdate,&apos;dd.mm.yyyy&apos;), v_tmp.indexb, Extract(year from sysdate), extract(month from sysdate));
         end loop;
        oldpu := 0; 
      END IF;
      IF V_REC.CODCENTRALIZARE &gt; 0 THEN
        PKG_NOTECREDIT.UPDATE_RECORDS(TIPINTR, VCOD, V_REC.CODCENTRALIZARE, aNumarDoc, aDataDoc, aValDoc, oldpu);
      END IF;
      if aANULAT = 1 then
        UPDATE CANTAR SET USERIDBLOCAJ = null, TIPDOC = NULL, CODDOC1 = NULL WHERE TIPDOC = TIPINTR AND CODDOC1 = V_REC.CODINTR1;

				begin
					 Select CodBCAR into aCodBCAR from BCAR WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;
					 insert into trigar_modif (CodModif, datamodif, usermodif, Cod, codmaster, tablename, FieldName, oldvalue,newvalue)
					 Values( SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, aCodBCAR,aCodBCAR, &apos;BCAR&apos;, &apos;CODDOC1&apos;,
									 V_REC.CodIntr1, &apos;Null+POSTREC+aANULAT=1&apos;);
				exception when others then
					 aCodBCAR := 0;
				end;
        UPDATE BCAR SET USERIDBLOCAJ = null, TipDoc = NULL, CodDoc1 = NULL WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;

      end if;
      if TipIntr = 7 and aTIPTRANZACTIE = 10 THEN
         --update utilaje2
        for v_tmp in (select u2c.codutilaj2c, u2.codutilaj2, nvl(tmp.indexinterventie,0) indexu, i.datadoc datau,
                             iv.perdurata, iv.tip, iv.perkm, iv.atentionarekm, iv.atentionarezile, iv.pertip, tmp.datastart, tmp.dataend,
                             case when u2c.codcomanda1 = u2.codcomanda1 then 1 else 0 end IsLast
                      from tmp_intrprodlink l
                           inner join intrari1 i1 on l.codintr1 = i1.codintr1
                           inner join TMP_INTRARI1 tmp on tmp.codintr1 = i1.codintr1
                           inner join intrari i on i1.codintr = i.codintr
                           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                           inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                           inner join utilaje2 u2 on u2c.codutilaj2 = u2.codutilaj2
                           inner join ninterventiiauto iv on u2.interventie = iv.codinterventiiauto
                      where l.codintr1 = v_rec.codintr1
                      ) loop
          update utilaje2c set indexc = v_tmp.indexu, dataindexc = v_tmp.datau, datastart = v_tmp.datastart, dataend = v_tmp.dataend where codutilaj2c = v_tmp.codutilaj2c;
        end loop;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_INTRLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM INTRLINK WHERE CODINTR1 = v_rec.CODINTR1;
      IF NR = 0  THEN
        INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT)
        VALUES  (v_rec.CODINTR1, v_rec.CODLINIECOMANDA, v_rec.CODLINIEAVIZ, v_rec.CANT);
      ELSE
        UPDATE INTRLINK
        SET
          CODINTR1        = v_Rec.CODINTR1,
          CODLINIECOMANDA = v_rec.CODLINIECOMANDA,
          CODLINIEAVIZ    = v_Rec.CODLINIEAVIZ,
          CANT            = v_Rec.Cant
        WHERE CODINTR1 = v_rec.CODINTR1;
      END IF;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_INTRASTEPTLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM INTRASTEPTLINK WHERE CODINTR1 = v_rec.CODINTR1;
      IF NR = 0  THEN
        INSERT INTO INTRASTEPTLINK (CODINTR1, CODLINIEFACTURA, CANT)
        VALUES  (v_rec.CODINTR1, v_rec.CODLINIEFACTURA, v_rec.CANT);
      ELSE
        UPDATE INTRASTEPTLINK
        SET
          CODINTR1        = v_Rec.CODINTR1,
          CODLINIEFACTURA = v_rec.CODLINIEFACTURA,
          CANT            = v_Rec.Cant
        WHERE CODINTR1 = v_rec.CODINTR1;
      END IF;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_INTRPRODLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM INTRPRODLINK WHERE CODINTR1 = v_rec.CODINTR1;
      IF NR = 0  THEN
        INSERT INTO INTRPRODLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODPROGRAMF1)
        VALUES  (v_rec.CODINTR1, v_rec.CODLINIECOMANDA, v_rec.CODLINIEAVIZ, v_rec.CANT, V_REC.CODPROGRAMF1);
      ELSE
        UPDATE INTRPRODLINK
        SET
          CODINTR1        = v_Rec.CODINTR1,
          CODLINIECOMANDA = v_rec.CODLINIECOMANDA,
          CODLINIEAVIZ    = v_Rec.CODLINIEAVIZ,
          CANT            = v_Rec.Cant,
          CODPROGRAMF1    = V_REC.CODPROGRAMF1
        WHERE CODINTR1 = v_rec.CODINTR1;
      END IF;
    END LOOP;

-- Detail NIRSER, NirStoc, Nir
    /* ATENTIE LA ORDINEA STERGERILOR DIN DETALII */


    FOR V_REC IN
    (
      SELECT * FROM NIRSER WHERE
      CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID)) AND
      CODNIRSER NOT IN ( SELECT CodNirSer FROM TMP_NIRSER)
    )
    LOOP
      DELETE FROM NIRSER WHERE CODNIRSER = V_REC.CODNIRSER;
      DELETE FROM REZERVATS WHERE CODNIRSER = V_REC.CODNIRSER AND NVL(CODCOMANDA1F,0) = 0;
    END LOOP;



  FOR V_REC IN
  (
    SELECT *  FROM NIRSTOC WHERE
    CODNIR IN (SELECT CODNIR FROM NIR WHERE CODINTR = RECID) and
    CODNIRSTOC NOT IN ( SELECT CodNirStoc FROM TMP_NIRSTOC )
  )
  LOOP
    DELETE FROM NPLINK    WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC   WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC1  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM REZERVATS WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND NVL(CODCOMANDA1F,0) = 0;
    DELETE FROM PACHETEOBJ WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  end loop;
-- inainte de steregere din LIVR reactivez numerele
    FOR V_REC IN (SELECT * FROM NIR  WHERE ( CodIntr = RecId AND CodNIR NOT IN ( SELECT  CodNIR FROM TMP_NIR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
    END LOOP;

    DELETE FROM NIR WHERE ( CodIntr = RecId AND CodNIR NOT IN ( SELECT  CodNIR FROM TMP_NIR ));

    if aSysDateNir = 4 and aOperat = 1  and (isSysMonthSameWithLucru = 1) then
      update tmp_nir set datanir = trunc(sysdate) where NVL(CodNIR,0) &lt; 0;
    end if;

    FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP

      IF (NVL(v_Rec.CodNIR,0) &lt; 0) THEN
        BEGIN
          SELECT seq_NIR_CodNIR.Nextval into vcod FROM DUAL;
          INSERT INTO NIR ( CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat,Operat )
          VALUES (vCod, RecId,   v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest,      v_rec.Obs, v_rec.TipNIR, v_rec.Anulat, v_rec.Blocat,  v_rec.Operat );


          UPDATE TMP_NIRSTOC
          SET CODNIR = vCod
          WHERE CODNIR = v_rec.CODNIR;

        END;
      ELSE
        BEGIN
          -- verific daca s-au schimbat CARNETELE de DOCUMENTE
          SELECT NVL(CARNETNIR, 0), NVL(NRNIR, 0) INTO OLDCARNETNIR, OLDNRNIR FROM NIR
          WHERE
          NVL(CodNIR,0) = NVL(v_rec.CodNIR,0);

          IF (OLDCARNETNIR &lt;&gt; 0)AND(OLDNRNIR &lt;&gt; 0)AND(V_REC.CARNETNIR &lt;&gt; OLDCARNETNIR OR V_REC.NRNIR &lt;&gt; OLDNRNIR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETNIR, OLDNRNIR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETNIR);
          END IF;


          UPDATE NIR
          SET
            CarnetNIR = v_rec.CarnetNIR,
            NRNIR     = v_rec.NRNIR,
            DataNIR   = v_rec.DataNIR,
            Gest      = v_rec.Gest,
            Obs       = v_rec.Obs,
            TipNIR    = v_rec.TipNIR,
            Anulat    = v_rec.Anulat,
            Blocat    = v_rec.Blocat,
            Operat    = v_rec.Operat
          WHERE NVL(CodNIR,0) = NVL(v_rec.CodNIR,0);
        END;
      END IF;
    END LOOP;


-- Detail NIRSTOC

  FOR v_rec IN (SELECT * FROM TMP_NIRSTOC ORDER BY CodIntr1) LOOP

   IF v_rec.CODNIRSTOC &gt; 0  THEN
     UPDATE NIRSTOC SET
        CodNir       = v_rec.CodNir,
        CodIntr1     = v_rec.CodIntr1,
        CantNir      = v_rec.CantNir * v_rec.Paritate,
        CantFURN     = v_rec.CantFURN * v_rec.Paritate,
        UmSec        = v_rec.UmSec,
        CodObiect    = v_rec.CodObiect,
        CodIoArt     = nvl(v_rec.CodIoArt, 0),
        Pret         = ROUND(v_rec.Pret / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))),
        RotLei       = v_rec.RotLei,
        RotValuta    = v_rec.RotValuta,
        CODLOCATIE   = V_REC.CODLOCATIE,
        CANTUM1      = V_REC.CANTUM1,
        CANTUM2      = V_REC.CANTUM2,
        Adaos        = nvl(v_rec.Adaos, 0) / v_rec.Paritate,
        TVA          = v_rec.TVA,
        TipSerie     = v_rec.TipSerie,
        CodLivr1     = v_rec.CodLivr1,
        Rest         = GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
        RestUM1      = GET_REST_STOC_UM1(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM1),
        RestUM2      = GET_REST_STOC_UM2(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM2),
        ProcentAdaos = v_rec.ProcentAdaos,
        Supliment    = v_rec.Supliment,
        SuplNeded    = v_rec.SuplNeded,
        TG           = (SELECT TG FROM  TMP_INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1 AND ROWNUM = 1),
        DISCLIKISTOC = V_REC.DISCLIKISTOC,
        SERIELOT     = V_REC.SERIELOT,
        PUMaximal    = (SELECT PUMaximal FROM  TMP_INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1 AND ROWNUM = 1),
        AdMax        = (SELECT AdMax FROM  TMP_INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1 AND ROWNUM = 1),
        EUDR_RN      = V_REC.EUDR_RN,
        EUDR_VN      = V_REC.EUDR_VN,
        FURN         = CASE
                         WHEN TIPINTR in (6,7) THEN (SELECT FURNAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
                         WHEN TIPINTR IN (1, 2, 3, 4, 5) THEN aCODPART
                       ELSE NULL
                       END,
        CODGESTPROD    = CASE
                         WHEN TIPINTR = 7 THEN aCODGESTPROD
                       ELSE NULL
                       END,
        PROVIZION      = V_REC.PROVIZION,
        SUBUNITATEA    = CASE
                         WHEN TIPINTR = 6 THEN aSUBUNITATEA
                         ELSE NULL
                       END,

        DATAACHIZ    = CASE
                         WHEN TIPINTR in (6) THEN (SELECT DATAACHIZAVIZSUBUNIT FROM TMP_INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
                         WHEN TIPINTR in (7) THEN
                                           NVL(
                                           (SELECT DATAACHIZAVIZSUBUNIT FROM TMP_INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
                                           (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR AND ROWNUM = 1)
                                           )
                         ELSE (SELECT DATANIR FROM TMP_NIR WHERE CODNIR = V_REC.CODNIR AND ROWNUM = 1)
                       END,
       TIPDOCACHIZ   = TIPINTR,
       D1            = v_rec.D1,
       D2            = v_rec.D2,
       D3            = v_rec.D3,
       PUVAL          = V_REC.PUVAL
     WHERE
     CodNirStoc = v_rec.CodNirStoc ;
     
     FOR V_REC_COPII IN (SELECT * FROM NIRSTOC1 NS1 WHERE CODNIRSTOCORIG &lt;&gt; CODNIRSTOC AND CODNIRSTOCORIG = v_rec.CodNirSToc)
     loop
       UPDATE NIRSTOC
       SET
         EUDR_RN = V_REC.EUDR_RN,
         EUDR_VN = V_REC.EUDR_VN
       WHERE
         CODNIRSTOC = V_REC_COPII.CODNIRSTOC;  
     end loop;     
     
     
     begin
       select nvl(i1.codcmdint1,0), nvl(prod.tip,0) into aCodComanda1, aTipCompPredat
       from intrari1 i1
            left join intrprodlink l on i1.codintr1 = l.codintr1
            left join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
       where i1.codintr1 = v_Rec.CodIntr1;
     exception when others then aCodComanda1 := 0; aTipCompPredat := 0;
     end;

     update nirstoc1
     set
       pretmat = case when aTIPDOCNirStoc1 &lt; 0 then 0 else ROUND(nvl(v_rec.Pret,0) / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - nvl(v_rec.Adaos, 0) / v_rec.Paritate end,
       Dinstoc = case when aTIPDOCNirStoc1 = 7 and aTipCompPredat = 0 then 0 else 1 end,
       tipdoc = aTIPDOCNirStoc1,
       CodComanda1 = case when aTipCompPredat = 2 then 0 else aCodComanda1 end,
       dirty = case when aTIPDOCNirStoc1 = 7 and aTipCompPredat = 0 then 1 else 0 end
     where codnirstoc = v_rec.codnirstoc;

     if TIPINTR = 7 and aCodComanda1 &gt; 0 then
       update nirstoc1 set dirty = 1, dinstoc = 0 where codcomanda1 = aCodComanda1;
     end if;

-- VERIFIF MODIFICARE PRET  MIFIX

       BEGIN
         SELECT COUNT(*) INTO NRMIFIX FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN NRMIFIX :=0;
       END;

       IF NRMIFIX &gt; 0 THEN
         aVALOARE :=  v_rec.Pret / v_rec.Paritate;

         FOR V_MIFIX1 IN
         (SELECT *
          FROM
            MIFIX1 MF1
          WHERE
            MF1.CODNIRSTOC = V_REC.CODNIRSTOC
            AND PRET &lt;&gt; aVALOARE
         )
         LOOP
           UPDATE MIFIX1
           SET
             PRET = aVALOARE
           WHERE
             CODMIFIX1 = V_MIFIX1.CODMIFIX1;


           UPDATE FISAMF
           SET
             PRETI = aVALOARE
           WHERE
             CODMIFIX = V_MIFIX1.CODMIFIX
             AND CODOPERATIE = 1;


           UPDATE JURNAL1
           SET
             DIRTY = 1
           WHERE
             CODDOC     = V_MIFIX1.CODMIFIX
             AND TIPDOC = 36
             AND AN * 12 + LUNA &gt;= V_MIFIX1.ANSTART * 12 +  V_MIFIX1.LUNASTART;
         END LOOP;
       END IF;

   ELSE
     SELECT seq_NIRSTOC_CodNirStoc.NEXTVAL INTO VCOD FROM DUAL;


    UPDATE TMP_NIRSTOC SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    UPDATE TMP_NIRSER  SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

    INSERT INTO NIRSTOC( CodNirStoc, CodNir, CodIntr1, CantNir, CANTFURN, Umsec,  CodObiect, CodIoArt,
		Pret, RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, RESTUM1, RESTUM2,
    ProcentAdaos,
    Supliment,SuplNeded,
    D1,
    D2,
    D3,
    TG, PUMaximal, AdMax, FURN, CODGESTPROD, SUBUNITATEA, DATAACHIZ, TIPDOCACHIZ, DISCLIKISTOC,
    SERIELOT, PUVAL, PROVIZION, EUDR_RN, EUDR_VN )
    VALUES
    (vCOD, v_rec.CodNir, v_rec.CodIntr1,  v_rec.CantNir * v_rec.Paritate, v_rec.CantFURN * v_rec.Paritate, v_Rec.UmSec,  v_rec.CodObiect,  nvl(v_rec.CodIoArt, 0),
     ROUND(v_rec.Pret / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))),
     v_rec.RotLei, v_rec.RotValuta, V_REC.CODLOCATIE, V_REC.CANTUM1, V_REC.CANTUM2, NVL(v_rec.Adaos, 0)/ v_rec.Paritate,  v_rec.TVA,
     v_rec.TipSerie,  v_rec.CodLivr1,
     GET_REST_STOC(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantNir * v_rec.Paritate),
     GET_REST_STOC_UM1(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM1),
     GET_REST_STOC_UM2(v_Rec.CodNir, v_Rec.CodNirStoc, v_rec.CantUM2),
  --(SELECT v_rec.CantNir * v_rec.Paritate -  NVL(SUM(Cant), 0) FROM Livr1 WHERE CodNirStoc = v_Rec.CodNirStoc),
     v_rec.ProcentAdaos,
     v_rec.Supliment,v_rec.SuplNeded,
     v_rec.D1,
     v_rec.D2,
     v_rec.D3,
    (SELECT TG FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT PUMaximal FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT AdMax FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),

     CASE
       WHEN TIPINTR IN (6, 7) THEN (SELECT FURNAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       WHEN TIPINTR IN (1, 2, 3, 4, 5) THEN aCODPART
       ELSE NULL
     END,
     CASE
       WHEN TIPINTR = 7 THEN aCODGESTPROD
       ELSE NULL
     END,
     CASE
       WHEN TIPINTR = 6 THEN aSUBUNITATEA
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 6 THEN (SELECT DATAACHIZAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       WHEN TIPINTR in (7) THEN
                         NVL(
                         (SELECT DATAACHIZAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
                         (SELECT DATANIR FROM NIR WHERE CODNIR = V_REC.CODNIR AND ROWNUM = 1)
                         )

       ELSE (SELECT DATANIR FROM NIR WHERE CODNIR = V_REC.CODNIR)
     END,
     TIPINTR,
     V_REC.DISCLIKISTOC,
     V_REC.SERIELOT,
     V_REC.PUVAL,
     V_REC.PROVIZION,
     V_REC.EUDR_RN,
     V_REC.EUDR_VN
      );

      begin
        select nvl(i1.codcmdint1,0), nvl(prod.tip,0) into aCodComanda1, aTipCompPredat
        from intrari1 i1
             left join intrprodlink l on i1.codintr1 = l.codintr1
             left join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
        where i1.codintr1 = v_Rec.Codintr1;
      exception when others then
        aCodComanda1 := 0;
        aTipCompPredat := 0;
      end;

      INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      VALUES (vCod, pkg_list_base_utils.GETCODNIRSTOC_ORIG(vCod), aTIPDOCNirStoc1,
              CASE WHEN aTIPDOCNirStoc1 &lt; 0 THEN 0 ELSE ROUND(nvl(v_rec.Pret,0) / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - NVL(v_rec.Adaos, 0)/ v_rec.Paritate END,
              case when TIPINTR = 7 and aTipCompPredat = 0 and aCodComanda1 &gt; 0 then 1 else 0 end, case when TIPINTR = 7 and aTipCompPredat = 0 then 0 else 1 end,
              case when TIPINTR = 7 and aTipCompPredat = 2 then 0 else aCodComanda1 end);
      if aCodComanda1 &gt; 0 then
        update nirstoc1 set dirty = 1 where codcomanda1 = aCodComanda1;
        insert into tmp_manevra(codunic)
        select codnirstoc
        from nirstoc1 where codcomanda1 = aCodComanda1;
      end if;
   END IF;

  END LOOP;

-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP
    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
/*
      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
*/
    END IF;

    IF V_REC.CODNIRSER &lt; 0 THEN
      SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;
      INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2, RESTUM1, RESTUM2, OBS, CodCertif, DataProd, TG, Stare, Divizor, Bucati, DataProd1, TG1,
      CODPRODUCATOR) VALUES
      (VCOD, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2,  V_REC.CANTUM1, V_REC.CANTUM2,
             V_REC.OBS, V_REC.CodCertif, V_REC.DataProd, V_REC.TG,  V_REC.Stare, v_rec.Divizor, v_rec.Bucati, v_rec.DataProd1, v_rec.TG1, v_rec.codproducator);

      UPDATE TMP_NIRSER
      SET
       CODNIRSER = VCOD
      WHERE
        CODNIRSER = V_REC.CODNIRSER;
    ELSE
      UPDATE NIRSER
      SET
        CODNIRSER  = V_REC.CODNIRSER,
        CODNIRSTOC = V_REC.CODNIRSTOC,
        CODSERIE   = aCODSERIE,
        CANTNIR    = V_REC.CANTNIR * V_REC.PARITATE,
        CANTUM1    = V_REC.CANTUM1,
        CANTUM2    = V_REC.CANTUM2,
        OBS        = V_REC.Obs,
        Codcertif  = V_REC.Codcertif,
        DataProd   = V_REC.DataProd,
        Divizor   = v_rec.Divizor,
        Bucati    = v_rec.Bucati,
        TG         = V_REC.TG,
        Stare     = V_REC.Stare,
        DataProd1  = V_REC.DataProd1,
        TG1            = V_REC.TG1,
        CODPRODUCATOR  = V_REC.CODPRODUCATOR,
        REST       = GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantNir * V_REC.PARITATE ),
        RESTUM1    = GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM1 ),
        RESTUM2    = GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM2 )
      WHERE
      CODNIRSER = V_REC.CODNIRSER;
    END IF;
  END LOOP;

-- Detail LIVR
    /* ATENTIE LA ORDINEA STERGERILOR DIN DETALII */



    DELETE LIVRVAL WHERE CODLIVR1 IN
    ( SELECT CODLIVR1 FROM LIVR1 WHERE
      CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID) AND
      CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1)
    );


    DELETE FROM LIVR1 WHERE
    CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODINTR = RECID) and
    CODLIVR1 NOT IN ( SELECT CodLIVR1 FROM TMP_LIVR1);



-- inainte de steregere din LIVR reactivez numerele
    FOR V_REC IN (SELECT * FROM LIVR  WHERE ( CodIntr = RecId AND CodLIVR NOT IN ( SELECT  CodLIVR FROM TMP_LIVR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
    END LOOP;

    DELETE FROM LIVR WHERE ( CodIntr = RecId AND CodLIVR NOT IN ( SELECT  CodLIVR FROM TMP_LIVR ));



    FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP

      IF (NVL(v_Rec.CodLIVR,0) &lt; 0 ) THEN
        BEGIN
          SELECT seq_LIVR_CodLIVR.Nextval into vcod FROM DUAL;

          INSERT INTO LIVR ( CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLivr, Obs, TipLivr, Anulat, Blocat, Operat )
          VALUES ( vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR,
                   v_rec.DataLIVR, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat, v_rec.Blocat,  v_rec.Operat );


          UPDATE TMP_LIVR1 SET CODLIVR = vCod  WHERE CODLIVR = v_rec.CODLIVR;

        END;
      ELSE
        BEGIN
          -- verific daca s-au schimbat CARNETELE de DOCUMENTE
          SELECT NVL(CARNETLIVR, 0), NVL(NRLIVR, 0) INTO OLDCARNETLIVR, OLDNRLIVR FROM LIVR
          WHERE
          NVL(CodLIVR,0) = NVL(v_rec.CodLIVR,0);

          IF (OLDCARNETLIVR &lt;&gt; 0)AND(OLDNRLIVR &lt;&gt; 0)AND(V_REC.CARNETLIVR &lt;&gt; OLDCARNETLIVR OR V_REC.NRLIVR &lt;&gt; OLDNRLIVR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETLIVR, OLDNRLIVR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETLIVR);
          END IF;


          UPDATE LIVR
          SET
            CarnetLIVR = v_rec.CarnetLIVR,
            NRLIVR     = v_rec.NRLIVR,
            DataLIVR   = v_rec.DataLIVR,
            Obs        = v_rec.Obs,
            TipLIVR    = v_rec.TipLIVR,
            Anulat    = v_rec.Anulat,
            Blocat    = v_rec.Blocat,
            Operat    = v_rec.Operat
          WHERE NVL(CodLIVR,0) = NVL(v_rec.CodLIVR,0);
        END;
      END IF;
    END LOOP;


-- Detail Livr1

-- stergerea celor ce au disparut e rezolvata mai sus

   FOR V_REC IN (SELECT * FROM TMP_LIVR1 ORDER BY CODLIVR, CODINTR1) LOOP
      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
        PRETINREG = PRETINREG / V_REC.PARITATE,
        PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;

     IF NVL(V_REC.CODLIVR1, 0) &gt; 0 THEN
        UPDATE LIVR1 SET
          CODLIVR    =  V_REC.CODLIVR,
          CODINTR1   =  V_REC.CODINTR1,
          CODNIRSTOC =  V_REC.CODNIRSTOC,
          CANT       =  V_REC.CANT * V_REC.PARITATE,
          CANTUM1    = V_REC.CANTUM1,
          CANTUM2    = V_REC.CANTUM2,
          UMSEC      =  V_REC.UMSEC
        WHERE
          CODLIVR1 = V_REC.CODLIVR1;
     ELSE

       SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

       INSERT INTO LIVR1
       (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2)
       VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA,V_REC.PMPVALUTADOC, V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2 );
     END IF;
   END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_LIVRVAL) LOOP
      IF V_REC.CODLIVRVAL &lt; 0 THEN
        INSERT INTO LIVRVAL(CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
        VALUES (SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,  V_REC.CODLIVR1, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.GEST, V_REC.PRETINREG, V_REC.PRETACHIZ, V_REC.TVANEEX);
      ELSE
        UPDATE LIVRVAL
        SET
          CODLIVR1   = V_REC.CODLIVR1,
          CODOBIECT  = V_REC.CODOBIECT,
          CODIOART   = V_REC.CODIOART,
          GEST       = V_REC.GEST,
          PRETINREG  = V_REC.PRETINREG ,
          PRETACHIZ  = V_REC.PRETACHIZ ,
          TVANEEX    = V_REC.TVANEEX
        WHERE
          CODLIVRVAL = V_REC.CODLIVRVAL;
      END IF;
    END LOOP;



 UPDATE NIRSTOC NS
 SET
   REST    = GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
   RESTUM1 = GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
   RESTUM2 = GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
 WHERE
  NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1 UNION SELECT CodNirStoc FROM TMP_LIVR1_INITIAL);

 UPDATE NIRSER NS
 SET
   REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
   RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
   RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
 WHERE
 NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1 UNION SELECT CodNirStoc FROM TMP_LIVR1_INITIAL);

-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = TIPINTR AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOAREGRUP   = V_REC.VALOAREGRUP,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC,V_REC.DOCUMENT,V_REC.CODANALIZANOD);
 END IF;
END LOOP;


-- detail JURNAL

DELETE FROM JURNAL WHERE TIPDOC = TIPINTR AND CODDOC = RECID AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOAREGRUP=v_rec.VALOAREGRUP,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA,
    CODCENTRU  = v_rec.CODCENTRU,
    DATADOC    = V_REC.DATADOC,
    DOCUMENT   = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC,Document,CODANALIZANOD)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, RECID, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC,v_rec.document,V_REC.CODANALIZANOD);
 END IF;
END LOOP;
  if TIPINTR = 2 then
    Select NUMEDELEGAT into sNUMEDELEGAT from TMP_Intrari;
		if sNUMEDELEGAT = &apos;MakeDIRTY_FactLaAviz&apos; then
			update Jurnal1 J1 set J1.Dirty = 1
			where J1.TipDoc = 9 and
			J1.CodDoc in (
			   Select distinct x.CodIntr
				   from intrlink k
					 inner join Intrari1 i1 on k.CodLinieAviz = I1.CodIntr1
					 inner join Intrari  i  on I.CodIntr = I1.CodIntr
					 inner join Intrari1 x1 on k.CodIntr1 = x1.CodIntr1
					 inner join Intrari  x  on x.CodIntr = x1.CodIntr
					 where i.Operat = 1 and i.codIntr = RecID);
				 for vrec in
				   ( Select distinct x1.CodIntr1, I1.Mifix MFSursa
						 from intrlink k
						 inner join Intrari1 i1 on k.CodLinieAviz = I1.CodIntr1
						 inner join Intrari  i  on I.CodIntr = I1.CodIntr
						 inner join Intrari1 x1 on k.CodIntr1 = x1.CodIntr1
						 where i.codIntr = RecID and i.Operat = 1 and x1.Mifix &lt;&gt; i1.Mifix)
				 loop
				   Update Intrari1 set Mifix = vrec.Mfsursa where CodIntr1 = vrec.Codintr1;
					end loop;
			end if;
	end if;
ELSE  -- INSERT
-- Master INTRARI
  if aSysDateNir = 4 and aOperat = 1  and (isSysMonthSameWithLucru = 1) then
    update tmp_nir set datanir = trunc(sysdate);
  end if;

  SELECT seq_INTRARI_CodIntr.NextVal INTO RecId FROM DUAL;

  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI&apos;, RecId);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunitatea, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO  INTRARI
  (CodIntr, TipDoc, Anulat, Blocat, Operat, PrefixDoc, NrDoc, DataDoc, Partener, NrAviz, CarnetDoc, ValDoc,
  TVADoc, Majorari, An, Luna, Obs, Satelit, Complex, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC,
  BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD,
  SUBUNITATEA, TIPTVA, MONEDA, CURS,USERID,DATACREARE,SCHIMB,CODFORMATIE, IDIMPORT, DELEGAT,
  MIJLTRANSP, NRTRANSP, ProRata, CODCONTRACT, CODAUTO, ExclusPlata, FaraReg, TVAINCASARE, TVAINCASARE_F,
  CodAnaliza, CURSDOC, Custodie, Transportator, VALTRANSPORT, FACTSIMPLIF, AGENT, CURSNIR, STADIUWMS,
   DATAREFSCAD, DATATVA, AUTOFACTURARE,TIPLIVRARE, NATURATRANZ, MODTRANSP, ORDONANTAT, EXPORTKLG, EXPORTATKLG,
   PROCSTOPAJ, TipSAFT, RotEFact, SPLITTVA, TipET, IS_ETransp, iddescarcare, ValDocEFACT, Aprobat  )

 ( SELECT RecId,  TipDoc, Anulat, Blocat, Operat, PrefixDoc, NrDoc, DataDoc, Partener, NrAviz, CarnetDoc, ValDoc,
                TVADoc, Majorari, An, Luna, Obs, Satelit, Complex, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC,
                BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, TIPTRANZACTIE, NRI, CODGESTPROD,
                SUBUNITATEA, TIPTVA, MONEDA, CURS,PKG_GLOBALS.USERID,systimestamp,SCHIMB,CODFORMATIE, IDIMPORT, DELEGAT,
                MIJLTRANSP, NRTRANSP, ProRata, CODCONTRACT, CODAUTO, ExclusPlata, FaraReg, TVAINCASARE, TVAINCASARE_F,
                CodAnaliza, CURSDOC, Custodie, Transportator, VALTRANSPORT, FACTSIMPLIF, AGENT, CURSNIR, STADIUWMS,
                DATAREFSCAD, DATATVA, AUTOFACTURARE,TIPLIVRARE, NATURATRANZ, MODTRANSP, ORDONANTAT, EXPORTKLG, EXPORTATKLG,
                PROCSTOPAJ, TipSAFT, RotEFact, SPLITTVA, TipET, is_eTransp, iddescarcare, ValDocEFACT, Aprobat
   FROM TMP_INTRARI) ;

-- detail GENERAL
   FOR v_rec IN ( SELECT * FROM TMP_GENERAL) LOOP
     SELECT seq_GENERAL_CODGENERAL.Nextval INTO vCOD FROM DUAL;
     UPDATE TMP_OBLIGPIF SET CODGENERAL = VCOD WHERE CODGENERAL = v_Rec.CODGENERAL;
     INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, ICONTAVANS,  PROCTVAAVANS, TVA, ExclusPlata, DataTVA, FaraReg)
     VALUES (VCOD, TIPINTR, RecID, v_rec.Moneda, v_rec.Curs, v_rec.Semnificatie, v_rec.ICONTAVANS,  v_rec.PROCTVAAVANS, v_rec.TVA, v_rec.ExclusPlata, v_rec.DataTVA, v_rec.FaraReg);
   END LOOP;

-- DETAIL OBLIGPIF
   FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF) LOOP
     SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;
     UPDATE TMP_INTRARI1 SET CODOBLIGSTORNO = vCOD WHERE CODOBLIGSTORNO = v_rec.CODOBLIGPIF;

     INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, CODCENTRU,  MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT,CODANALIZANOD, DINCARETVA, RESTTVA, SPLITTVA)
     VALUES
    (VCOD, V_REC.CODGENERAL, V_REC.TERMEN, NVL(V_REC.VALOARE, 0),
    (  CASE WHEN V_REC.SEMNIFICATIE = 111 THEN NULL
       ELSE NVL(V_REC.VALOARE, 0)
       END
     ),
    V_REC.CODPART, V_REC.ICONT, V_REC.TIPPLATA, V_REC.CODCENTRU,  V_REC.MAJORARI, V_REC.SEMNIFICATIE, V_REC.TIP, NVL(V_REC.CONTBANKTRANZACTIE, 0), NVL(V_REC.CODOBLIGASOCIAT, 0),V_REC.CODANALIZANOD, V_REC.DINCARETVA, V_REC.DINCARETVA, V_REC.SPLITTVA );
   END LOOP;

   -- STINGERE -- debit
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;


      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;

-- detail INTRDOCTRANSP
   FOR V_REC IN (SELECT * FROM TMP_INTRDOCTRANSP)
   LOOP
     INSERT INTO INTRDOCTRANSP(COD, CODINTR, CODINTRLINK, VALTRANSPORT)
     VALUES (SEQ_INTRDOCTRANSP_COD.NEXTVAL, RECID, V_REC.CODINTRLINK, V_REC.VALTRANSPORT);
   END LOOP;


-- Detail INTRARI1
  FOR v_rec IN ( SELECT * FROM TMP_INTRARI1 ORDER BY IndexLocal ) LOOP
		IF TIPINTR = 7 THEN
			DoPU    := InStr(V_REC.OBS, &apos;&lt;PU&gt;&apos;); --inainte musai de PKG_IESIRI.GetLinieComInt(V_REC.OBS,V_REC.OBS);
			IF Nvl(V_REC.CodCmdInt1,0) = 0 THEN
				V_REC.CodCmdInt1 := PKG_IESIRI.GetLinieComInt(V_Rec.CodObiect,V_REC.OBS,V_REC.OBS);
				if Nvl(V_REC.CodCmdInt1,0) &gt; 0 then
					INSERT INTO TMP_INTRPRODLINK (CODINTR1, CODLINIECOMANDA, CODCOMANDA1, CANT)
					VALUES  (v_rec.CODINTR1, (Select codCMDPRODMAT from CMDPRODMAT WHERE CODCOMANDA1 = V_REC.CodCmdInt1 and TIP = 0), V_REC.CodCmdInt1, v_rec.CANT);
				end if;
			end if;
			if (DoPU &gt; 0) and (v_Rec.Cant &lt;&gt; 0) and NVL(V_REC.CodCmdInt1,0) &gt; 0 then
				V_REC.OBS := Substr(V_REC.Obs,  1,  DoPU - 1 )||Substr(V_REC.Obs,  DoPU + 4, 400 );
				ValProd  := GET_VALOARE_PROD(V_REC.CodCmdInt1);
				PretProd := Round(GET_REGIE_FIXA(V_REC.CodObiect) +ValProd / v_Rec.Cant,2);
				V_REC.PU := PretProd;
				update TMP_NIRSTOC NS set Ns.Pret = PretProd, NS.Adaos = 0 where NS.Codintr1 = V_REC.CodIntr1;
				insert into TMP_Jurnal1 (CodDoc, TipDoc, An ,Luna, Dirty) values (RecId, TipIntr, PKG_GLOBALS.AnLucru,PKG_GLOBALS.LUNALUCRU,1);
				insert into TMP_Jurnal (CodDoc, TipDoc, An ,Luna) values (RecId, TipIntr, PKG_GLOBALS.AnLucru,PKG_GLOBALS.LUNALUCRU);
				update TMP_INTRARI1 set PU = PretProd where Codintr1 = V_REC.CodIntr1;
				update TMP_INTRARI Set ValDoc = (Select Sum(Cant*PU) from tmp_intrari1);
			end if;
		end if;

    SELECT seq_INTRARI1_CodIntr1.Nextval INTO vCOD FROM DUAL;
    update tmp_jurnal1 set indexlocal = vcod where indexlocal = v_rec.codintr1;
    update TMP_INTRARI1 set codintr1 = vCod where codintr1 = v_rec.codintr1;
    update TMP_INTRARI1 set codintr1LINK = vCod where codintr1LINK = v_rec.codintr1;

    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;INTRARI1&apos;, vCOD, V_REC.CODINTR1);

 /*   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIP1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIF1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1PF SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1SUB SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;


    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1FAST SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;


   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIAE1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;

   IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARIFA1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
   END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTR1AST SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;

    IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_INTRARICF1 SET CODINTR1 = &apos; || VCOD || &apos; WHERE CODINTR1 = &apos; || V_REC.CODINTR1;
    END IF;*/

    if v_Rec.Tiplinie = &apos;S&apos; and pkg_categconst.ESTEIMBUNATATIREMIFIX(v_rec.contserv) &gt; 0 and
      PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 and v_rec.codmifix &gt; 0 then
      for v_xxx in (select mfix1.codnirstoc
                    from mifix1 mfix1
                    where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
        insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
        values(vCod, v_xxx.codnirstoc, v_rec.cant * v_rec.pu * aCurs);
        exit;
      end loop;
    end if;

    if v_rec.codobiect in (
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRCA&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtCASCO&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtITP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
                               PKG_CATEGCONST.GetValConstanta(&apos;ArtRovigneta&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
                              )
           and v_rec.codauto &gt; 0 then
      begin
        select nvl(max(indexlocal),0) + 1 into aCount from nparc2 where cod = v_rec.codauto;
      exception when others then aCount := 1;
      end;
      insert into nparc2(codnparc2, indexlocal, sn, eliberat, expira, cod, obs, valoare, codintr1, denumire,atentie)
      values (seq_nparc2_codnparc2.nextval, aCount, v_rec.nrcertif, aDataDoc, nvl(v_rec.tg,v_rec.termencontract), v_rec.codauto, v_rec.obs, v_rec.cant * v_rec.pu + v_rec.tva, vcod, v_rec.denobiect,
              (select atentionare from nautorizatiiauto where codserviciu = v_rec.codobiect));
    end if;

    INSERT INTO INTRARI1 (
      CodIntr1, CodIntr, IndexLocal,TipLinie,Umsec,An,Luna,ContServ, CONTDISCOUNT,
      ZILE, ZILECMD, GestAct,CodObiect,
      PretOrig,PU,Cant,
      TVA, AdDim, MIFIX, CODOBIECTORIG, CODAUTO, TVANEDED, PARITATEORIG, COEFDISCMAJ, OBS,
      RestFact,NrCertif, CODCMD1AE, TG,PUMaximal, AdMax,PURidicata, PROCADAOS,
      FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CODLINIEDOCIMP, TIPDOCIMP, CURSFACTURAAVANS, CODMIFIX, RESTIMBMF, CODINTR1STORNO, PRELUAT, CUSTODIE, CodOferta1,CODCENTRU, CONTASTEPTARE, RESTASTEPTARE,
      CODCMDINT1, codcontract1, Taxa, ROTVALTAXA, TERMENCONTRACT, ICONTPART, PRETUM1, CODANALIZANOD,
      CODINTR1LINK,
      CODNIMOB, IMPOZABIL,GESTPRODAVIZSUB)
    VALUES (
      vCod, RecId, v_Rec.IndexLocal,  v_Rec.TipLinie,  v_Rec.Umsec,  v_Rec.An,  v_Rec.Luna,  v_Rec.ContServ, V_REC.CONTDISCOUNT,
      V_REC.ZILE, V_REC.ZILECMD, v_Rec.GestAct,  v_Rec.CodObiect,
      v_Rec.PretOrig / NVL(v_Rec.Paritate, 1), v_Rec.PU / NVL(v_Rec.Paritate, 1),  v_Rec.Cant * NVL(v_Rec.Paritate, 1),
      v_Rec.TVA, v_rec.AdDim, V_REC.MIFIX,  V_REC.CODOBIECTORIG, V_REC.CODAUTO, V_REC.TVANEDED, V_REC.PARITATEORIG, V_REC.COEFDISCMAJ, V_REC.OBS,
      CASE
        WHEN TIPINTR = 2 AND v_rec.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND aOperat = 1 AND aAnulat = 0 THEN v_Rec.Cant * v_Rec.Paritate
        WHEN v_rec.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN v_rec.VALOARE -- valoare discount memorez pe RESTFACT
        ELSE 0
      END,
      v_Rec.NrCertif,  V_REC.CODCMD1AE, v_Rec.TG,  v_Rec.PUMaximal, v_Rec.AdMax, v_Rec.PURidicata, V_REC.PROCADAOS, V_REC.FURNAVIZSUBUNIT,
      V_REC.DATAACHIZAVIZSUBUNIT, V_REC.CODOBLIGSTORNO, V_REC.CODLINIEDOCIMP, V_REC.TIPDOCIMP, V_REC.CURSFACTURAAVANS, V_REC.CODMIFIX,
      CASE WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0
        THEN
          (
           CASE
             WHEN TIPINTR = 3 THEN  v_rec.Cant * v_rec.PU * aCurs - NVL(V_REC.TVA, 0)
             ELSE v_rec.Cant * v_rec.PU * aCurs
           END
           )
        ELSE 0
      END,
      V_REC.CODINTR1STORNO, V_REC.PRELUAT, V_REC.CUSTODIE, V_REC.CodOferta1,V_REC.CODCENTRU,
      V_REC.CONTASTEPTARE,
      CASE
        WHEN  TIPINTR = 9 AND aTIPFACTURA = 9 AND V_REC.CANT &gt; 0 THEN v_rec.Cant *  v_rec.Paritate
        ELSE 0
      END,
      V_REC.CodCmdInt1, V_REC.codcontract1, V_REC.Taxa, V_REC.ROTVALTAXA, V_REC.TERMENCONTRACT, V_REC.ICONTPART, V_REC.PRETUM1,
      V_REC.CODANALIZANOD,
      (SELECT CODINTR1LINK FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = VCOD), -- stupid dar doar asa se poate
      V_REC.CODNIMOB,
      V_REC.IMPOZABIL,v_rec.GESTPRODAVIZSUB
    );

    -- fisa mas
    if TipIntr = 7 then
      UPDATE TMP_FISAMAS SET CODINTR1 = vCod where codintr1 = v_rec.codintr1;
    end if;

    UPDATE TMP_NIRSTOC  SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_LIVR1    SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CodIntr1;
    UPDATE TMP_INTRLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_INTRASTEPTLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    UPDATE TMP_INTRPRODLINK SET CODINTR1 = vCod WHERE CODINTR1 = v_rec.CODINTR1;
    PKG_CANTAR.UPDATE_RECORDS(TIPINTR, v_rec.CodIntr1, vCOD);
    PKG_BCAR.UPDATE_RECORDS(TIPINTR, v_rec.CodIntr1, vCOD);
    IF V_REC.CODCENTRALIZARE &gt; 0 THEN
      PKG_NOTECREDIT.UPDATE_RECORDS(TIPINTR, VCOD, V_REC.CODCENTRALIZARE, aNumarDoc, aDataDoc, aValDoc, 0);
    END IF;
  END LOOP;

  -- fisa mas
  if TipIntr = 7 then
    INSERT INTO INTRPRODLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODPROGRAMF1) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, CODPROGRAMF1 FROM TMP_INTRPRODLINK);
    for v_tmp in (select * from tmp_fisamas) loop
            select seq_fisamas_codfisamas.nextval into aCodFisaMas from dual;
            update fisamas1 set codfisamas = aCodFisaMas where codfisamas = v_tmp.codfisamas;
            INSERT INTO FISAMAS
            (CODFISAMAS    ,
             CODINTR1      ,
             NRDOC         ,
             DATADOC       ,
             CODRESPONSABIL,
             CODINSPECTOR  ,
             OBS           ,
             APROBAT,
             CARNETDOC,
             SERIADOC
            )
            values(
               aCODFISAMAS    ,
               V_TMP.CODINTR1      ,
               V_TMP.NRDOC         ,
               V_TMP.DATADOC       ,
               V_TMP.CODRESPONSABIL,
               V_TMP.CODINSPECTOR  ,
               V_TMP.OBS           ,
               V_TMP.APROBAT,
               V_TMP.CARNETDOC,
               V_TMP.SERIADOC);

            IF NVL(v_tmp.CARNETDOC, 0) &lt;&gt; 0 AND NVL(v_tmp.NRDOC, 0) &lt;&gt; 0 THEN
              PKG_CARNETEDOC.SOLVENUMARDOC(v_tmp.CARNETDOC, v_tmp.NRDOC);
            END IF;

             INSERT INTO FISAMAS1
                (
                  CODFISAMAS1,
                  CODFISAMAS ,
                  CODPRODMAS ,
                  VALOARE    ,
                  STARE      ,
                  OBS
                )
                (SELECT
                   seq_fisamas1_codfisamas1.nextval,
                   aCodFisaMas ,
                   FM1.CODPRODMAS  ,
                   FM1.VALOARE     ,
                   FM1.STARE       ,
                   FM1.OBS
                 FROM TMP_FISAMAS1 FM1
                      inner join tmp_fisamas FM on fm.codfisamas = fm1.codfisamas
                 where FM.Codintr1 = vCod);
          end loop;
    IF aTIPTRANZACTIE = 10 THEN
      for v_rec in (select codintr1 from intrari1 where codintr = RecId) loop
         --update utilaje2
        for v_tmp in (select u2c.codutilaj2c, nvl(tmp.indexinterventie,0) indexu, i.datadoc datau, u2.codutilaj,
                             iv.perdurata, iv.tip, iv.perkm, iv.atentionarekm, iv.atentionarezile, iv.pertip, tmp.datastart, tmp.dataend,
                             nvl(iv.accidentala,0) accidentala
                      from intrprodlink l
                           inner join intrari1 i1 on l.codintr1 = i1.codintr1
                           inner join TMP_INTRARI1 tmp on tmp.codintr1 = i1.codintr1
                           inner join intrari i on i1.codintr = i.codintr
                           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and nvl(prod.tip,0) = 0
                           inner join utilaje2c u2c on u2c.codcomanda1 = prod.codcomanda1
                           inner join utilaje2 u2 on u2c.codutilaj2 = u2.codutilaj2
                           inner join ninterventiiauto iv on u2.interventie = iv.codinterventiiauto
                      where l.codintr1 = v_rec.codintr1
                      ) loop
          if v_tmp.accidentala = 0 then
            insert into utilaje3(codutilaj3, codutilaj, databord, indexbord, an, luna)
            values (seq_utilaje3_codutilaj3.nextval, v_tmp.codutilaj, to_date(sysdate,&apos;dd.mm.yyyy&apos;), v_tmp.indexu, Extract(year from sysdate), extract(month from sysdate));
          end if;

          update utilaje2c set indexc = v_tmp.indexu, dataindexc = v_tmp.datau, datastart = v_tmp.datastart, dataend = v_tmp.dataend where codutilaj2c = v_tmp.codutilaj2c;
        end loop;
      end loop;
    END IF;
  end if;

  INSERT INTO INTRLINK (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT) (SELECT CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT FROM TMP_INTRLINK);

  INSERT INTO INTRASTEPTLINK (CODINTR1, CODLINIEFACTURA, CANT) (SELECT CODINTR1, CODLINIEFACTURA, CANT FROM TMP_INTRASTEPTLINK);

-- Detail NIR
  FOR v_rec IN ( SELECT * FROM TMP_NIR ORDER BY CodNIR ) LOOP
    SELECT seq_NIR_CodNIR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO NIR (CodNIR, CodIntr, CarnetNIR, NRNIR, DataNIR, Gest, Obs, TipNIR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetNIR, v_rec.NRNIR, v_rec.DataNIR, v_rec.Gest, v_rec.Obs, v_rec.TipNIR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_NIRSTOC SET CODNIR = vCod WHERE CODNIR = v_rec.CODNIR;
  END LOOP;


-- Detail NIRSTOC
  FOR v_rec IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CodIntr1 ) LOOP
    SELECT seq_NIRSTOC_CodNirStoc.Nextval INTO vCod from DUAL;

    UPDATE TMP_NIRSTOC
    SET
      CODNIRSTOC = VCOD
    WHERE
      CODNIRSTOC = V_REC.CODNIRSTOC;


    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = v_rec.CODNIRSTOC;


    INSERT INTO NIRSTOC
    (CodNirStoc, CodNir, CodIntr1, CantNir, CANTFURN, UmSec,  CodObiect, CodIoArt, Pret, RotLei, RotValuta, CODLOCATIE, CANTUM1, CANTUM2, Adaos, TVA, TipSerie, CodLivr1, Rest, RESTUM1, RESTUM2, ProcentAdaos, Supliment, SuplNeded, TG, PUMaximal, AdMax, FURN, CODGESTPROD, SUBUNITATEA, DATAACHIZ, TIPDOCACHIZ, DISCLIKISTOC,SERIELOT,  D1, D2, D3,PUVAL, PROVIZION,
    EUDR_RN, EUDR_VN)
    VALUES
    (vCod, v_Rec.CodNir, v_Rec.CodIntr1, v_Rec.CantNir * v_Rec.Paritate,  v_Rec.CantFURN * v_Rec.Paritate,  v_Rec.Umsec, v_Rec.CodObiect, nvl(v_Rec.CodIoArt, 0),

    ROUND(v_rec.Pret / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))),
    v_Rec.RotLei, v_Rec.RotValuta, nvl(V_REC.CODLOCATIE,0), V_REC.CANTUM1, V_REC.CANTUM2, NVL(v_Rec.Adaos, 0)  / v_Rec.Paritate, v_Rec.TVA, v_Rec.TipSerie, v_Rec.CodLivr1,

    GET_REST_STOC(v_Rec.CodNir, vCod, v_rec.CantNir * v_rec.Paritate),
    GET_REST_STOC_UM1(v_Rec.CodNir, vCod, v_rec.CantUM1),
    GET_REST_STOC_UM2(v_Rec.CodNir, vCod, v_rec.CantUM2),
    v_Rec.ProcentAdaos, v_rec.Supliment, v_rec.SuplNeded,
    (SELECT TG FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT PUMaximal FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
    (SELECT AdMax FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
     CASE
       WHEN TIPINTR in (6,7) THEN (SELECT FURNAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       WHEN TIPINTR IN (1, 2, 3, 4, 5) THEN aCODPART
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 7 THEN aCODGESTPROD
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR = 6 THEN aSUBUNITATEA
       ELSE NULL
     END,

     CASE
       WHEN TIPINTR in (6) THEN (SELECT DATAACHIZAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1)
       WHEN TIPINTR in (7) THEN
                         NVL(
                         (SELECT DATAACHIZAVIZSUBUNIT FROM INTRARI1 WHERE CODINTR1 = V_REC.CODINTR1),
                         (SELECT DATANIR FROM NIR WHERE CODNIR = V_REC.CODNIR AND ROWNUM = 1)
                         )
       ELSE (SELECT DATANIR FROM NIR WHERE CODNIR = V_REC.CODNIR)
     END,
     TIPINTR,
     V_REC.DISCLIKISTOC,
     V_REC.SERIELOT,
     V_REC.D1,
     V_REC.D2,
     V_REC.D3,
     V_REC.PUVAL,
     V_REC.PROVIZION,
     V_REC.EUDR_RN,
     V_REC.EUDR_VN
     
     );

    begin
      select nvl(i1.codcmdint1,0), nvl(prod.tip,0) into aCodComanda1, aTipCompPredat
      from intrari1 i1
           left join intrprodlink l on i1.codintr1 = l.codintr1
           left join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
      where i1.codintr1 = v_Rec.Codintr1;
    exception when others then
      aCodComanda1 := 0;
      aTipCompPredat := 0;
    end;

    INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
    VALUES (vCod, pkg_list_base_utils.GETCODNIRSTOC_ORIG(vCod), aTIPDOCNirStoc1,
            CASE WHEN aTIPDOCNirStoc1 &lt; 0 THEN 0 ELSE ROUND(nvl(v_rec.Pret,0) / v_rec.Paritate, ZecimalePret(7 - NVL(V_REC.ROTLEI, 0))) - NVL(v_rec.Adaos, 0)/ v_rec.Paritate END,
            case when TIPINTR = 7 and aTipCompPredat = 0 and aCodComanda1 &gt; 0 then 1 else 0 end, case when TIPINTR = 7 and aTipCompPredat = 0 then 0 else 1 end,
            case when TIPINTR = 7 and aTipCompPredat = 2 then 0 else aCodComanda1 end);
    if aCodComanda1 &gt; 0 then
      update nirstoc1 set dirty = 1 where codcomanda1 = aCodComanda1;
      insert into tmp_manevra(codunic)
      select codnirstoc
      from nirstoc1
      where codcomanda1 = aCodComanda1;
    end if;
  END LOOP;


-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
/*
      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
*/
    END IF;

    SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;


    INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2,
                        RESTUM1, RESTUM2, OBS, CodCertif, DataProd,Bucati, Divizor, TG, Stare, DataProd1, TG1, CODPRODUCATOR) VALUES
    (VCOD, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2,
     V_REC.CANTUM1, V_REC.CANTUM2, V_REC.OBS, V_REC.CodCertif, V_REC.DataProd, v_rec.Bucati, v_rec.Divizor, V_REC.TG, V_REC.Stare, V_REC.DataProd1, 
     V_REC.TG1, V_REC.CODPRODUCATOR);

    UPDATE TMP_NIRSER
    SET
      CODNIRSER = VCOD
    WHERE
      CODNIRSER = V_REC.CODNIRSER;

  END LOOP;


-- LIVR
  FOR v_rec IN ( SELECT * FROM TMP_LIVR ORDER BY CodLIVR ) LOOP
    SELECT seq_LIVR_CodLIVR.NEXTVAL INTO vCod FROM DUAL;

    INSERT INTO LIVR (CodLIVR, CodIntr, CarnetLIVR, NRLIVR, DataLIVR, Obs, TipLIVR, Anulat, Blocat, Operat )
    VALUES (vCod, RecId, v_rec.CarnetLIVR, v_rec.NRLIVR, v_rec.DataLivr, v_rec.Obs, v_rec.TipLIVR, v_rec.Anulat,  v_rec.Blocat, v_rec.Operat);

    UPDATE TMP_LIVR1 SET CODLIVR = vCod WHERE CODLIVR = v_rec.CODLIVR;
  END LOOP;


-- LIVR1
   FOR V_REC IN (SELECT * FROM TMP_LIVR1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;


     SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;


     INSERT INTO LIVR1 (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CODNIRSER, PMP, PMPDOC, PMPVALUTA,PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2)
     VALUES
       ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
         V_REC.CANT * V_REC.PARITATE,
         V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC, V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2 );
   END LOOP;


   INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
   SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;


-- actualizez stocurile din care livrez

   UPDATE NIRSTOC NS
   SET
     REST    = GET_REST_STOC(NS.CodNir, NS.CodNirStoc, NS.CantNIR),
     RESTUM1 = GET_REST_STOC_UM1(NS.CodNir, NS.CodNirStoc, NS.CantUM1),
     RESTUM2 = GET_REST_STOC_UM2(NS.CodNir, NS.CodNirStoc, NS.CantUM2)
   WHERE
     NS.CodNirStoc in (SELECT CodNirStoc FROM TMP_LIVR1);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
   NS.CodNirStoc IN (SELECT CodNirStoc FROM TMP_LIVR1);



  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT,CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL1);



 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT,CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RecID, CONTD, CONTC, GEST, VALOARE, VALOAREV,VALOAREGRUP,  OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);


END IF; -- END INSERT


  pkg_pretprod.SetDirtyStructura;


-- SUNT PE AVIZ CARE STINGE FACTURI IN ASTEPTARE ; ACTUALIZEZ RESTUL PE FACTURILE STINSE
IF TIPINTR = 2 AND aTIPFACTURA = 9 THEN
  UPDATE INTRARI1 I1
  SET
   I1.RestAsteptare = i1.Cant -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRASTEPTLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEFACTURA = I1.CodINTR1 AND II.TIPDOC = 2  AND II.OPERAT = 1 AND II.ANULAT = 0
               ) +
              (SELECT NVL(SUM(II1.CANT), 0) -- retururi
                FROM
                  INTRARI1 II1
                  INNER JOIN INTRARI   II ON II.CODINTR   = II1.CODINTR
                WHERE
                  II1.CANT &lt; 0 AND II1.CODLINIEDOCIMP = I1.CodINTR1 AND II1.TIPDOCIMP = 9 AND II.TIPFACTURA = 9 AND II.OPERAT = 1 AND II.ANULAT = 0
              )
  WHERE
  I1.CodINTR1 IN
  (SELECT CODLINIEFACTURA FROM TMP_INTRASTEPTLINK UNION SELECT CODLINIEFACTURA FROM TMP_INTRASTEPTLINK_INITIAL);
END IF;

-- SUNT PE FACTURA IN ASTEPTARE CARE CONTINE RETURURI; ACTUALIZEZ RESTUL PE FACT.IN ASTEPTARE STORNATE
IF TIPINTR = 9 AND aTIPFACTURA = 9 THEN
  FOR V_REC IN
    (SELECT CODLINIEDOCIMP FROM INTRARI1 WHERE CANT &lt; 0 AND NVL(CODLINIEDOCIMP, 0) &lt;&gt; 0 AND TIPDOCIMP = 9 AND CODINTR = RECID
    UNION ALL
    SELECT CODLINIEDOCIMP FROM INTRARI1_MAN WHERE CANT &lt; 0 AND NVL(CODLINIEDOCIMP, 0) &lt;&gt; 0 AND TIPDOCIMP = 9
    )
  LOOP
    UPDATE INTRARI1
    SET
       RestAsteptare =  CANT  -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  INTRASTEPTLINK IL
                  LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                WHERE
                IL.CODLINIEFACTURA = v_Rec.CODLINIEDOCIMP AND I.TIPDOC = 2 AND I.OPERAT = 1 AND I.ANULAT = 0
               ) +
               (SELECT NVL(SUM(I1.CANT), 0) -- retururi
                FROM
                  INTRARI1 I1
                  INNER JOIN INTRARI I ON I.CODINTR   = I1.CODINTR
                WHERE
                  I1.CANT &lt; 0 AND I1.CODLINIEDOCIMP = v_Rec.CODLINIEDOCIMP AND TIPDOCIMP = 9 AND I.TIPFACTURA = 9 AND I.OPERAT = 1 AND I.ANULAT = 0
               )

    WHERE
      CODINTR1 = V_REC.CODLINIEDOCIMP;

  END LOOP;
END IF;

-- SUNT PE FACTURA LA AVIZ ; ACTUALIZEZ RESTUL PE AVIZELE STINSE
IF TIPINTR = 9 AND aTIPFACTURA &lt;&gt; 9 THEN
  UPDATE INTRARI1 I1
  SET
   I1.RestFact = i1.Cant -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                 WHERE
                 IL.CODLINIEAVIZ = I1.CodINTR1 AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10)) AND II.OPERAT = 1 AND II.ANULAT = 0
                 )+
                 (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                  FROM
                    INTRARI1 AE1,
                    INTRARI  AE
                  WHERE
                    AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                   AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0)
  WHERE
  I1.CodINTR1 IN
  (SELECT CODLINIEAVIZ FROM TMP_INTRLINK UNION SELECT CODLINIEAVIZ FROM TMP_INTRLINK_INITIAL);

ELSE -- ACTUALIZEZ RESTULACCEPTAT DE PE COMENZI FURNIZORI
  delete tmp_comanda;--imi trebe golita ca sa nu se activeze trigerrul pe update la comanda1
  IF (TIPINTR IN (1, 2, 3, 4))OR(TIPINTR = 9 AND aTIPFACTURA = 9) THEN
    UPDATE COMANDA1 c1
    SET
     c1.RestAcceptat = c1.CantAcceptat -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    INTRLINK IL
                    LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                    LEFT OUTER JOIN INTRARI  II ON II.CODINTR   = II1.CODINTR
                   WHERE
                   IL.CODLINIECOMANDA = c1.CodComanda1  AND /*II.OPERAT = 1*/ PKG_IESIRI.CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTOPERAT) = 1 AND II.ANULAT = 0
                   )-
                (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    CMDLIVRLINK IL
                    LEFT OUTER JOIN COMANDA1 I1 ON I1.CODCOMANDA1 = IL.CODCOMANDA1
                    LEFT OUTER JOIN COMANDA   I ON I.CODCOMANDA   = I1.CODCOMANDA
                  WHERE
                    IL.CODLINIECOMANDA = C1.CodCOMANDA1 AND I.OPERAT = 1 AND I.ANULAT = 0
                )

    WHERE
    c1.CodComanda1 IN (SELECT CODLINIECOMANDA FROM TMP_INTRLINK UNION SELECT CODLINIECOMANDA  FROM TMP_INTRLINK_INITIAL);
  ELSE
    if TIPINTR in (7) then
          for v_rec in (select CODLINIECOMANDA from TMP_INTRPRODLINK UNION select CODLINIECOMANDA from TMP_INTRPRODLINK_INITIAL) loop
            select  cant, Rest
            INTO acant,vRest
            from cmdprodmat WHERE codcmdprodmat = v_rec.codliniecomanda;

            --insert into x(test) values(&apos;cant:&apos;||acant::varchar||&apos; rest:&apos;||vrest::varchar);
           begin
           select
              COALESCE((select coalesce (sum (IL.CANT --/ case                                  --corectie in Oracle pe 27.08.2020
                                                         --    when coalesce (NUM1.PARITATE, 1) = 0 then 1
                                                         --    else coalesce (NUM1.PARITATE, 1)
                                                         --  end
                                                 ) , 0)
                                    from INTRPRODLINK       IL
                                         left join INTRARI1 II1 on II1.CODINTR1 = IL.CODINTR1
                                         left join NUM1         on II1.UMSEC    = NUM1.CODUM1
                                         left join INTRARI  II  on II.CODINTR   = II1.CODINTR
                                    where
                                        IL.CODLINIECOMANDA = c1.codcmdprodmat and PKG_IESIRI.CONDITIE_FACTURA_OPERATA(II.OPERAT, CONSTRESTOPERAT) = 1 and II.ANULAT = 0
                                   ),0) into aRest from cmdprodmat c1 where c1.codcmdprodmat = v_rec.codliniecomanda;
            exception when others then null;
              --insert into x(test) values(&apos;eroare&apos;);
            end;
           --insert into x(test) values(&apos;stins:&apos;||arest::varchar);
            update CMDPRODMAT c1
            set Rest = acant - arest
            where
              c1.CodCmdprodmat = v_rec.codliniecomanda;

            select cant,Rest INTO acant,vRest from cmdprodmat WHERE codcmdprodmat = v_rec.codliniecomanda;
           --insert into x(test) values(&apos;cant:&apos;||acant::varchar||&apos; rest:&apos;||vrest::varchar);

            if vRest = 0 then
              for v_tmp in (select mat.codcmdprodmat
                            from cmdprodmat           mat
                                 inner join cmdprodmat prod on prod.codcomanda1 = mat.codcomanda1
                            where prod.codcmdprodmat = v_rec.codliniecomanda and mat.tip = 1)
              loop
                update rezervats set rest = 0 WHERE codcmdprodmat = v_tmp.codcmdprodmat;
              end loop;
            end if;
          end loop;
        end if;
  END IF;
END IF;



IF TIPINTR = 2 THEN -- RECALCULEZ RESTURI AVIZE STORNATE de documentul curent
  UPDATE INTRARI1 I1
  SET
   I1.RESTFACT = I1.CANT -
               ( SELECT NVL(SUM(IL.CANT), 0)
                 FROM
                  INTRLINK IL
                  LEFT OUTER JOIN INTRARI1 II1 ON II1.CODINTR1 = IL.CODINTR1
                  LEFT OUTER JOIN INTRARI  II ON II.CODINTR    = II1.CODINTR
                 WHERE
                 IL.CODLINIEAVIZ = I1.CODINTR1 AND (II.TIPDOC = 9 OR (II.TIPDOC = 5 AND II.TIPFACTURA = 10)) AND II.OPERAT = 1 AND II.ANULAT = 0
                 )+
               (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                FROM
                  INTRARI1 AE1,
                  INTRARI  AE
                WHERE
                  AE1.CODINTR1STORNO =I1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                 AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0
               )
               WHERE
                 EXISTS (SELECT CODINTR1STORNO FROM (SELECT CODINTR1STORNO FROM TMP_INTRARI1 UNION SELECT CODINTR1STORNO FROM INTRARI1_MAN) WHERE CODINTR1STORNO = I1.CODINTR1);
END IF;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU and LUNA= PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;


 END LOOP;

-- actualizare CARNETE DOCUMENTE
IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(aCARNET &lt;&gt; CARNETDOC_I OR aNUMARDOC &lt;&gt; NRDOC_I)
THEN
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
END IF;

IF NVL(aCARNET, 0) &lt;&gt; 0 AND NVL(aNUMARDOC, 0) &lt;&gt; 0 THEN
--  TIPINTR IN (7)
  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNUMARDOC);
END IF;

FOR V_REC IN (SELECT * FROM LIVR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
END LOOP;


FOR V_REC IN (SELECT * FROM NIR WHERE CodIntr = RecId)
LOOP
  PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
END LOOP;


-- actualizez restul obligatiilor stinse de tranzactiile STORNO FACTURA de pe documentul salvat
  UPDATE OBLIGPIF O
  SET
--   REST = VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)

    REST =
      (CASE
         WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END),
     RESTTVA   =
       (
        CASE
          WHEN VALOARE &gt; 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
          WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0) + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        END)

  WHERE
   O.SEMNIFICATIE = 110
   AND O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE

     UNION ALL

     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );


  UPDATE OBLIGPIF O
  SET
   REST = VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
  WHERE
   O.SEMNIFICATIE = 120
   AND O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE

     UNION ALL

     SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
   );


 IF aCODMONEDA &lt;&gt; 0 THEN
   FOR V_REC IN
   (
     SELECT
       G.CODGENERAL,
       OL.VALOARE AS VAL_IN,
       O.VALOARE  AS VAL_OUT
     FROM
        TMP_OBLIGPIF_INITIAL OL
        LEFT OUTER JOIN TMP_OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF,
        GENERAL       G
     WHERE
       G.CODGENERAL = OL.CODGENERAL
    )
    LOOP
      IF (V_REC.VAL_IN &lt;&gt; V_REC.VAL_OUT)OR(CURS_IN &lt;&gt; aCURS) THEN
        FOR V_RECREG IN
        (SELECT CODREG FROM REG1 WHERE CODGENERAL = V_REC.CODGENERAL)
        LOOP
          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            TIPDOC = 46 AND CODDOC = V_RECREG.CODREG;
        END LOOP;
      END IF;
    END LOOP;
 END IF;

 IF TIPINTR = 6 THEN
   -- ACTUALIZARE REZERVARESTOC
   FOR V_REC IN
    (
     SELECT
       CL.CODLINIECOMANDA AS CODCOMANDA1,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NS.PARITATE,
        I1.CODOBIECT
     FROM
       TMP_NIRSTOC_INITIAL NS
       LEFT OUTER JOIN TMP_NIRSERINI NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRARI1_MAN I1,
       CMDLINK CL
     WHERE
       I1.CODINTR1      = NS.CODINTR1
       AND I1.CODCMD1AE = CL.CODCOMANDA1
       )
    LOOP
      UPDATE REZERVATS
      SET
--        CANTREZERVAT = CANTREZERVAT - V_REC.CANTNIR * V_REC.PARITATE,
        REST         = REST         - V_REC.CANTNIR * V_REC.PARITATE,
        REZERVATINI  = REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE
      WHERE
       CODCOMANDA1           = V_REC.CODCOMANDA1
       AND CODNIRSTOC        = V_REC.CODNIRSTOC
       AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
       AND CODOBIECT         = V_REC.CODOBIECT;
    END LOOP;

   FOR V_REC IN
    (
     SELECT
       CL.CODLINIECOMANDA AS CODCOMANDA1,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NS.PARITATE,
        NS.UMSEC,
        I1.CODOBIECT
     FROM
       TMP_NIRSTOC NS
       LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRARI1 I1,
       CMDLINK CL
     WHERE
       I1.CODINTR1      = NS.CODINTR1
       AND I1.CODCMD1AE = CL.CODCOMANDA1
       )
    LOOP
      SELECT COUNT(*) INTO NR FROM REZERVATS
      WHERE
        CODCOMANDA1           = V_REC.CODCOMANDA1
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
        AND CODOBIECT         = V_REC.CODOBIECT;

      IF NR = 0 THEN
        INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC, CODOBIECT, REZERVATINI)
        VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, V_REC.CODNIRSTOC, V_REC.CODNIRSER, V_REC.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CANTNIR * V_REC.PARITATE);
      ELSE
        UPDATE REZERVATS
        SET
--        CANTREZERVAT = CANTREZERVAT + V_REC.CANTNIR * V_REC.PARITATE,
          REST         = REST         + V_REC.CANTNIR * V_REC.PARITATE,
          REZERVATINI  = REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE
        WHERE
         CODCOMANDA1           = V_REC.CODCOMANDA1
         AND CODNIRSTOC        = V_REC.CODNIRSTOC
         AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
         AND CODOBIECT         = V_REC.CODOBIECT;
      END IF;
    END LOOP;

-- CAZ CAND NU EXISTA COMENZI INTRE SUBUNITATI
   FOR V_REC IN
    (
     SELECT
       I1.CODCMD1AE AS CODCOMANDA1,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NS.PARITATE,
        I1.CODOBIECT
     FROM
       TMP_NIRSTOC_INITIAL NS
       LEFT OUTER JOIN TMP_NIRSERINI NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRARI1_MAN I1
       INNER JOIN COMANDA1 C1 ON I1.CODCMD1AE = C1.CODCOMANDA1
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
     WHERE
       I1.CODINTR1      = NS.CODINTR1
       AND (SELECT COUNT(*) FROM CMDLINK CL WHERE I1.CODCMD1AE = CL.CODCOMANDA1) = 0
       AND I1.CODCMD1AE &gt; 0 AND not C.TIPDOC in (44,60)
       )
    LOOP
      UPDATE REZERVATS
      SET
--        CANTREZERVAT = CANTREZERVAT - V_REC.CANTNIR * V_REC.PARITATE,
        REST         = REST         - V_REC.CANTNIR * V_REC.PARITATE,
        REZERVATINI  = REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE
      WHERE
       CODCOMANDA1           = V_REC.CODCOMANDA1
       AND CODNIRSTOC        = V_REC.CODNIRSTOC
       AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
       AND CODOBIECT         = V_REC.CODOBIECT;
    END LOOP;

   FOR V_REC IN
    (
     SELECT
       I1.CODCMD1AE AS CODCOMANDA1,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END
        CANTNIR,
        NS.PARITATE,
        NS.UMSEC,
        I1.CODOBIECT
     FROM
       TMP_NIRSTOC NS
       LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       INTRARI1 I1
       INNER JOIN COMANDA1 C1 ON I1.CODCMD1AE = C1.CODCOMANDA1
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
     WHERE
       I1.CODINTR1      = NS.CODINTR1
       AND (SELECT COUNT(*) FROM CMDLINK CL WHERE I1.CODCMD1AE = CL.CODCOMANDA1) = 0
       AND I1.CODCMD1AE &gt; 0 AND not C.TIPDOC in (44,60)
       )
    LOOP
      SELECT COUNT(*) INTO NR FROM REZERVATS
      WHERE
        CODCOMANDA1           = V_REC.CODCOMANDA1
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
        AND CODOBIECT         = V_REC.CODOBIECT;

      IF NR = 0 THEN
        INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC, CODOBIECT, REZERVATINI)
        VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, V_REC.CODNIRSTOC, V_REC.CODNIRSER, V_REC.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CANTNIR * V_REC.PARITATE);
      ELSE
        UPDATE REZERVATS
        SET
--        CANTREZERVAT = CANTREZERVAT + V_REC.CANTNIR * V_REC.PARITATE,
          REST         = REST         + V_REC.CANTNIR * V_REC.PARITATE,
          REZERVATINI  = REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE
        WHERE
         CODCOMANDA1           = V_REC.CODCOMANDA1
         AND CODNIRSTOC        = V_REC.CODNIRSTOC
         AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
         AND CODOBIECT         = V_REC.CODOBIECT;
      END IF;
    END LOOP;
 END IF;

 if pkg_categconst.GetValConstanta(&apos;RezervaCmdCli&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1 then
 IF TIPINTR = 7 THEN
   -- ACTUALIZARE REZERVARESTOC
   FOR V_REC IN
    (
     SELECT
       C1.CODCOMANDA1,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END CANTNIR,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.REST, 0)
         ELSE  NVL(NS.REST, 0)
       END REST,
       NS.PARITATE,
       CM.CODOBIECT
     FROM
       TMP_NIRSTOC_INITIAL NS
       LEFT OUTER JOIN TMP_NIRSERINI NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
       TMP_INTRPRODLINK_INITIAL IL,
       CMDPRODMAT CM,
       CMDLINK CL,
       COMANDA1 C1,
       COMANDA C
     WHERE
       IL.CODINTR1            = NS.CODINTR1
       AND IL.CODLINIECOMANDA = CM.CODCMDPRODMAT
       --AND CM.TIP             = 0
       AND CM.CODCOMANDA1     = CL.CODCOMANDA1
       AND C1.CODCOMANDA1     = CL.CODLINIECOMANDA
       AND C1.CODCOMANDA      = C.CODCOMANDA
       AND nvl(C.Displivrare, 0) &lt;&gt; 2 and nvl(c.inchisa,0) = 0 and nvl(c.anulat,0) = 0 and CM.Tip = 0 and CM.CodObiect = C1.CodObiect
    )
    LOOP
      begin
        select nvl(sum(nvl(r.rezervatini,0)),0) into aCantTransfer
        from rezervats r
             inner join nirstoc1 ns1 on r.codnirstoc = ns1.codnirstoc
        where r.codnirstoc &lt;&gt; v_rec.codnirstoc and ns1.codnirstocorig = v_rec.codnirstoc and r.codobiect = v_rec.codobiect
              and r.codcomanda1 = v_rec.codcomanda1;
      exception when others then
        aCantTransfer := 0;
      end;

      UPDATE REZERVATS
      SET
--        CANTREZERVAT = CANTREZERVAT - V_REC.CANTNIR * V_REC.PARITATE,
        REST         = case
                         when REST - V_REC.REST * V_REC.PARITATE + aCantTransfer &lt; 0 then 0
                         else REST - V_REC.REST * V_REC.PARITATE + aCantTransfer
                       end,
        REZERVATINI  = case
                         when REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE + aCantTransfer &lt; 0 then 0
                         else REZERVATINI  - V_REC.CANTNIR * V_REC.PARITATE  + aCantTransfer
                       end
      WHERE
        CODCOMANDA1           = V_REC.CODCOMANDA1
        AND CODNIRSTOC        = V_REC.CODNIRSTOC
        AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
        AND CODOBIECT         = V_REC.CODOBIECT;
    END LOOP;

    FOR V_REC IN
    (
     SELECT
       C1.CODCOMANDA1,
       C1.CODCOMANDA,
       NS.CODNIRSTOC,
       NVL(NSE.CODNIRSER, 0) AS CODNIRSER,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0)
         ELSE  NVL(NS.CANTNIR, 0)
       END CANTNIR,
       CASE
         WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.REST, 0)
         ELSE  NVL(NS.REST, 0)
       END REST,
       TMP_NS.PARITATE,
       NS.UMSEC,
       CM.Codobiect,
       C1.CantAcceptat,
       c.tipdoc,
       CM.CODCMDPRODMAT,
       CM.CODCOMANDA1 CODCMDINT1,
       CI.CODCOMANDA codcmdint,
       NVL(I1.CONTRACT,0) STINGERE
     FROM
       TMP_NIRSTOC TMP_NS
       INNER JOIN NIRSTOC NS ON TMP_NS.CODNIRSTOC = NS.CODNIRSTOC
       INNER JOIN TMP_INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
       LEFT OUTER JOIN TMP_NIRSER TMP_NSE ON TMP_NSE.CODNIRSTOC = NS.CODNIRSTOC
       LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSER = TMP_NSE.CODNIRSER,
       TMP_INTRPRODLINK IL,
       CMDPRODMAT CM,
       CMDLINK CL,
       COMANDA1 C1,
       COMANDA C,
       COMANDA1 CI1, COMANDA CI
     WHERE
       IL.CODINTR1            = NS.CODINTR1
       AND IL.CODLINIECOMANDA = CM.CODCMDPRODMAT
       AND CI1.CODCOMANDA1    = CM.CODCOMANDA1
       AND CI.CODCOMANDA      = CI1.CODCOMANDA
       AND CM.CODCOMANDA1     = CL.CODCOMANDA1
       AND C1.CODCOMANDA1     = CL.CODLINIECOMANDA
       AND C1.CODCOMANDA      = C.CODCOMANDA
       AND nvl(C.Displivrare, 0) &lt;&gt; 2 and nvl(c.inchisa,0) = 0 and nvl(c.anulat,0) = 0 and CM.Tip = 0 and CM.CodObiect = C1.CodObiect
    )
    LOOP
      if v_rec.tipdoc in (18,43) and CDirectCmd = 1 and CLegDir in (1,3) then
        begin
          select nvl(sum(nvl(r.rezervatini,0)),0) into aCantTransfer
          from rezervats r
               inner join nirstoc1 ns1 on r.codnirstoc = ns1.codnirstoc
          where r.codnirstoc &lt;&gt; v_rec.codnirstoc and ns1.codnirstocorig = v_rec.codnirstoc and r.codobiect = v_rec.codobiect
                and r.codcomanda1 = v_rec.codcomanda1;
        exception when others then
          aCantTransfer := 0;
        end;

        SELECT COUNT(*) INTO NR FROM REZERVATS
        WHERE
          CODCOMANDA1           = V_REC.CODCOMANDA1
          AND CODNIRSTOC        = V_REC.CODNIRSTOC
          AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
          AND CODOBIECT         = V_REC.CODOBIECT;

        IF NR = 0 then
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC, CODOBIECT, REZERVATINI)
          VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, V_REC.CODNIRSTOC, V_REC.CODNIRSER,
                  CASE WHEN AOPERAT = 1 THEN V_REC.REST ELSE 0 END - aCantTransfer,
                  V_REC.UMSEC, V_REC.CODOBIECT,
                  V_REC.CANTNIR - aCantTransfer);
          delete rezervats where codcomanda1 = v_rec.codcomanda1 and rest &lt; 0 and codobiect = v_rec.codobiect;
        ELSE
          if aOperat = 1 then
            UPDATE REZERVATS
            SET
    --        CANTREZERVAT = CANTREZERVAT + V_REC.CANTNIR * V_REC.PARITATE,
              REST         = Rest + V_REC.REST - aCantTransfer,
              REZERVATINI  = REZERVATINI + V_REC.CANTNIR - aCantTransfer
            WHERE
              CODCOMANDA1           = V_REC.CODCOMANDA1
              AND CODNIRSTOC        = V_REC.CODNIRSTOC
              AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
              AND CODOBIECT         = V_REC.CODOBIECT;
          else
            UPDATE REZERVATS
            SET
              REZERVATINI  = REZERVATINI + V_REC.CANTNIR - aCantTransfer
            WHERE
              CODCOMANDA1           = V_REC.CODCOMANDA1
              AND CODNIRSTOC        = V_REC.CODNIRSTOC
              AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
              AND CODOBIECT         = V_REC.CODOBIECT;
          end if;
          delete rezervats where codcomanda1 = v_rec.codcomanda1 and rest &lt; 0 and codobiect = v_rec.codobiect;
        END IF;

        aCantTransfer := 0;
        begin
          select nvl(sum(nvl(r.rezervatini,0)),0) into aCantTransfer
          from rezervats r
          where r.codcomanda1 = v_rec.codcomanda1;
        exception when others then
          aCantTransfer := 0;
        end;
        if (v_rec.CantAcceptat &lt; aCantTransfer and CLegDir = 1) or (CLegDir = 3 and v_rec.stingere = 1) then
          update comanda1 set cantacceptat = aCantTransfer where codcomanda1 = v_rec.codcomanda1;
          update comanda1 set cantacceptat = aCantTransfer where codcomanda1 = v_rec.codcmdint1;
          update cmdprodmat set cant = aCantTransfer where codcmdprodmat = v_rec.codcmdprodmat;
          update cmdlink set cant = aCantTransfer where codcomanda1 = v_rec.codcmdint1 and codliniecomanda = v_rec.codcomanda1;
          update comanda1 c1
          set restacceptat = cantacceptat - (
                                             select nvl(sum(cant),0)
                                             from ieslink where codliniecomanda = c1.codcomanda1
                                            )
          where c1.codcomanda1 = v_rec.codcomanda1;
          update comanda1 c1
            set restacceptat = cantacceptat - (
                                               select nvl(sum(cant),0)
                                               from cmdlink where codliniecomanda = c1.codcomanda1
                                              )
          where c1.codcomanda1 = v_rec.codcmdint1;
          update cmdprodmat mat
            set rest = cant - nvl((
                               select sum(cant)
                               from intrprodlink where codliniecomanda = mat.codcmdprodmat
                              ),0)
          where mat.codcmdprodmat = v_rec.codcmdprodmat;
          update comanda c set valoare = (select sum(pu * cantacceptat) from comanda1 where codcomanda = c.codcomanda)
          where c.codcomanda = v_rec.codcomanda;
          update comanda c set valoare = (select sum(pu * cantacceptat) from comanda1 where codcomanda = c.codcomanda)
          where c.codcomanda = v_rec.codcmdint;
        end if;
      else
        begin
          select nvl(sum(nvl(r.rezervatini,0)),0) into aCantTransfer
          from rezervats r
               inner join nirstoc1 ns1 on r.codnirstoc = ns1.codnirstoc
          where r.codnirstoc &lt;&gt; v_rec.codnirstoc and ns1.codnirstocorig = v_rec.codnirstoc and r.codobiect = v_rec.codobiect
                and r.codcomanda1 = v_rec.codcomanda1;
        exception when others then
          aCantTransfer := 0;
        end;

        SELECT COUNT(*) INTO NR FROM REZERVATS
        WHERE
          CODCOMANDA1           = V_REC.CODCOMANDA1
          AND CODNIRSTOC        = V_REC.CODNIRSTOC
          AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
          AND CODOBIECT         = V_REC.CODOBIECT;

        IF NR = 0 then
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC, CODOBIECT, REZERVATINI)
          VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, V_REC.CODNIRSTOC, V_REC.CODNIRSER,
                  case
                    when v_rec.cantacceptat &lt; CASE WHEN AOPERAT = 1 THEN V_REC.REST ELSE 0 END then v_rec.cantacceptat
                    else CASE WHEN AOPERAT = 1 THEN V_REC.REST ELSE 0 END
                  end  - aCantTransfer,
                  V_REC.UMSEC, V_REC.CODOBIECT,
                  case
                    when v_rec.cantacceptat &lt; V_REC.CANTNIR then v_rec.cantacceptat
                    else V_REC.CANTNIR
                  end  - aCantTransfer);
          delete rezervats where codcomanda1 = v_rec.codcomanda1 and rest &lt; 0 and codobiect = v_rec.codobiect;
        ELSE
          if aOperat = 1 then
            UPDATE REZERVATS
            SET
    --        CANTREZERVAT = CANTREZERVAT + V_REC.CANTNIR * V_REC.PARITATE,
              REST         = case when v_rec.cantacceptat &lt; REST + V_REC.REST then v_rec.cantacceptat else Rest + V_REC.REST end  - aCantTransfer,
              REZERVATINI  = case when v_rec.cantacceptat &lt; REZERVATINI + V_REC.CANTNIR then v_rec.cantacceptat else REZERVATINI + V_REC.CANTNIR end - aCantTransfer
            WHERE
              CODCOMANDA1           = V_REC.CODCOMANDA1
              AND CODNIRSTOC        = V_REC.CODNIRSTOC
              AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
              AND CODOBIECT         = V_REC.CODOBIECT;
          else
            UPDATE REZERVATS
            SET
              REZERVATINI  = case when v_rec.cantacceptat &lt; REZERVATINI + V_REC.CANTNIR then v_rec.cantacceptat else REZERVATINI + V_REC.CANTNIR end - aCantTransfer
            WHERE
              CODCOMANDA1           = V_REC.CODCOMANDA1
              AND CODNIRSTOC        = V_REC.CODNIRSTOC
              AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER
              AND CODOBIECT         = V_REC.CODOBIECT;
          end if;
          delete rezervats where codcomanda1 = v_rec.codcomanda1 and rest &lt; 0 and codobiect = v_rec.codobiect;
        END IF;
      -- caz actualizare cantacceptat de pe comanda client
      end if;
    END LOOP;

    for v_rec in (
      select rm.codnirstoc, rm.codrezervats
      from tmp_nirstoc_initial ns
           inner join tmp_intrprodlink_initial l on l.codintr1 = ns.codintr1
           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and prod.tip = 0
           inner join lansare1 l1 on l1.codcmd1 = prod.codcomanda1
           inner join lansare1 l2 on l2.codlansare0 = l1.codlansare0
           inner join comanda1 cs1 on cs1.codcomanda1 = l2.codcmd1
           inner join cmdprodmat mat on mat.codcomanda1 = cs1.codcomanda1 and prod.codobiect = mat.codobiect and mat.tip = 1
           left  join tmp_nirserini nse on nse.codnirstoc = ns.codnirstoc
           left  join rezervats rm on rm.codcmdprodmat = mat.codcmdprodmat and rm.codnirstoc = ns.codnirstoc and rm.codnirser = coalesce(nse.codnirstoc,0)
    ) loop
      if v_rec.codnirstoc &gt; 0 and v_Rec.codrezervats &gt; 0 then
        delete rezervats where codrezervats = v_rec.codrezervats;
      end if;
    end loop;
    for v_rec in (
      select mat.codcomanda1,mat.codcmdprodmat, mat.codobiect, coalesce(nse.cantnir,ns.cantnir) cantnir, mat.rest restmat,
             ns.codnirstoc, coalesce(nse.codnirser,0) codnirser, ns.umsec
      from nirstoc ns
           inner join intrprodlink l on l.codintr1 = ns.codintr1
           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda and prod.tip = 0
           inner join lansare1 l1 on l1.codcmd1 = prod.codcomanda1
           inner join lansare1 l2 on l2.codlansare0 = l1.codlansare0
           inner join comanda1 cs1 on cs1.codcomanda1 = l2.codcmd1
           inner join cmdprodmat mat on mat.codcomanda1 = cs1.codcomanda1 and prod.codobiect = mat.codobiect and mat.tip = 1
           left  join nirser nse on nse.codnirstoc = ns.codnirstoc
      where ns.codnir in (select codnir from nir where codintr = recid)
    ) loop
      aCantRez := 0;
      begin
        select coalesce(sum(r.rest),0) into aCantRez from rezervats r where r.codcmdprodmat = v_rec.codcmdprodmat
        and r.codnirstoc = v_rec.codnirstoc and r.codnirser = v_rec.codnirser;
      exception when others then aCantRez := 0;
      end;
      --insert into x(test) values(&apos;v_Rec.cantnir:&apos;||to_char(v_rec.cantnir)||&apos;,v_rec.restmat:&apos;||to_char(v_rec.restmat)||&apos;,aCantRez:&apos;||to_char(aCantRez));
      if v_rec.cantnir &gt; coalesce(v_rec.restmat,0) - aCantRez then
        insert into rezervats(codrezervats,codcomanda1,codnirstoc,codnirser,rest,umsec,codcmdprodmat,rezervatini)
        values(seq_rezervats_codrezervats.nextval,v_Rec.codcomanda1,v_Rec.codnirstoc,v_rec.codnirser,coalesce(v_rec.restmat,0) - aCantRez,v_rec.umsec,v_rec.codcmdprodmat,
               coalesce(v_rec.restmat,0) - aCantRez);
      else
        insert into rezervats(codrezervats,codcomanda1,codnirstoc,codnirser,rest,umsec,codcmdprodmat,rezervatini)
        values(seq_rezervats_codrezervats.nextval,v_Rec.codcomanda1,v_Rec.codnirstoc,v_rec.codnirser,v_rec.cantnir,v_rec.umsec,v_rec.codcmdprodmat,
               v_rec.cantnir);
        Exit;
      end if;
    end loop;
 END IF;
 end if;

 if tipintr &lt; 5 then
   --pun la loc rezervari initiale

   FOR V_REC IN
    (
      SELECT * FROM NIRSER WHERE
      CODNIRSTOC IN ( SELECT CODNIRSTOC FROM NIRSTOC
                      WHERE CODNIR IN ( SELECT CODNIR FROM NIR
                                        WHERE CODINTR = RECID))
    )
   LOOP
      DELETE FROM REZERVATS WHERE CODNIRSER = V_REC.CODNIRSER AND NVL(CODCOMANDA1F,0) &gt; 0;
   END LOOP;



   FOR V_REC IN
    (
      SELECT *  FROM NIRSTOC WHERE
      CODNIR IN ( SELECT CODNIR FROM NIR
                  WHERE CODINTR = RECID)
    )
   LOOP
      DELETE FROM REZERVATS WHERE CODNIRSTOC = V_REC.CODNIRSTOC AND NVL(CODCOMANDA1F,0) &gt; 0;
   end loop;

   for v_linkini in ( select l.CODLINIECOMANDA, l.CodIntr1
                      from tmp_intrlink_initial l
                           inner join rezervats r on r.codcomanda1f = l.codliniecomanda
                           inner join comanda1 c1 on c1.codcomanda1 = r.codcomanda1
                      where coalesce(c1.furnizor,0) = 0
                      union all
                      select l.codliniecomanda, al.codintr1
                      from intrari1 i1
                           inner join intrasteptlink al on al.codintr1 = i1.codintr1
                           inner join intrlink l on l.codintr1 = al.codliniefactura
                      where i1.codintr = recid
                    )
   loop -- pentru toate liniile comanda furnizor de pe acest document
     UPDATE REZERVATS set Rest = RezervatINI
     where CODCOMANDA1F = v_linkIni.CODLINIECOMANDA
           AND CodNIRStoc = 0;
     if aOperat = 1 then
       for v_link in ( select CodIntr1, CODLINIECOMANDA from IntrLink
                       where CODLINIECOMANDA = v_linkini.CODLINIECOMANDA
                             AND CODINTR1 &lt;&gt; v_linkini.CODINTR1
                     )
       loop
         begin
           select Sum(CantNIR) into TotSosit
           from (
                 SELECT
                   CASE WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0) ELSE  NVL(NS.CANTNIR, 0) END CANTNIR
                 FROM
                   NIRSTOC NS
                   LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
                 WHERE
                   NS.CODINTR1 = v_link.Codintr1
               );
           EXCEPTION WHEN OTHERS THEN TotSosit := 0;
         end;
         -- in TotSosit am total cant sosita pt cererea
         if TotSosit &lt;&gt; 0 then
           for v_Rez in ( select R.CodRezervatS, R.REST, R.REZERVATINI
                          from  RezervatS R, Intrari1 I1
                          where I1.CodIntr1 = v_Link.Codintr1
                                AND R.CODCOMANDA1F = v_link.CODLINIECOMANDA
                                AND R.CODObiect    = I1.CODObiect
                                AND R.CodNIRStoc   = 0
                          order By CodComanda1 desc)
           loop
             if TotSosit &lt;&gt; 0 then
               if TotSosit &lt; v_REZ.REST then
                 update REZERVATS set Rest = Rest - TotSosit where CodRezervats = v_Rez.CodRezervatS;
                 TotSosit := 0;
               else
                 TotSosit := TotSosit - v_REZ.REST ;
                 update REZERVATS set Rest = 0 where CodRezervats = v_Rez.CodRezervatS;
               end if;
             end if;
           end loop;
         end if;
       end loop;
     end if;  
   end loop;

   for v_link in ( select l.CODLINIECOMANDA, l.CodIntr1
                      from tmp_intrlink l
                           inner join rezervats r on r.codcomanda1f = l.codliniecomanda
                           inner join comanda1 c1 on c1.codcomanda1 = r.codcomanda1
                      where coalesce(c1.furnizor,0) = 0
                   union all
                   select l.codliniecomanda, al.codintr1
                   from tmp_intrari1 i1
                        inner join tmp_intrasteptlink al on al.codintr1 = i1.codintr1
                        inner join intrlink l on l.codintr1 = al.codliniefactura
                 )
   loop -- pentru toate liniile comanda furnizor de pe acest document
     delete rezervats where codnirstoc in (select codnirstoc from tmp_nirstoc_initial) and codcomanda1f = v_link.codliniecomanda;
     if aOperat = 1 then
       for v_NS in (
                 SELECT
                   NS.Codnirstoc, NVL(NSE.CodNIRSer,0) CodNIRSer , NS.CodObiect,
                   CASE WHEN NS.TIPSERIE &gt; 0 THEN NVL(NSE.CANTNIR, 0) ELSE  NVL(NS.CANTNIR, 0) END CANTNIR,
                   NS.Paritate
                 FROM
                   TMP_NIRSTOC NS
                   LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
                 WHERE
                   NS.CODINTR1 = v_link.Codintr1
                   )
       loop
         -- in TotSosit am total cant sosita pt cererea
         TotSosit := V_NS.CantNIR;
         if TotSosit &lt;&gt; 0 then
           for v_Rez in (select R.CodRezervatS, R.CodComanda1, R.CodObiect, R.UMSec, R.REST, R.REZERVATINI, cs.subunitatea,
                                cs.tipdoc, r.codcmdprodmat
                          from  RezervatS R
                                inner join comanda1 cs1 on cs1.codcomanda1 = r.codcomanda1
                                inner join comanda cs on cs.codcomanda = cs1.codcomanda
                          where R.CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                AND R.CODObiect    = v_NS.CODObiect
                                AND R.CodNIRStoc   = 0
                          order By R.CodComanda1 asc)
           loop
             if v_rez.subunitatea = asubunitatea and v_rez.tipdoc = 44 then
               delete rezervats where codrezervats = v_rez.codrezervats;
             else
               if v_rez.tipdoc = 44 then
                 if pkg_categconst.GetValConstanta(&apos;ReceptRezSubunit&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) &lt;&gt; 1 then
                   if TotSosit &lt;&gt; 0 then
                     if TotSosit &lt; v_REZ.REST then
                       update REZERVATS set Rest = Rest - TotSosit where CodRezervats = v_Rez.CodRezervatS;
                       begin
                         Select Count(*) into Nr from Rezervats
                                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                      AND CODComanda1  = v_REZ.CODComanda1
                                      AND CodNIRStoc   = v_NS.CodNIRStoc
                                      AND CodNIRSer    = v_NS.CodNIRSer;
                         EXCEPTION WHEN OTHERS THEN Nr := 0;
                       end;
                       if NR = 0 then
                         INSERT INTO REZERVATS
                          ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                            REST, REZERVATINI,
                            UMSEC, codcomanda1f, codobiect)
                         VALUES
                          ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                           TotSosit, TotSosit,
                           v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect);
                       else
                         UPDATE REZERVATS
                                SET REST = REST + TotSosit, REZERVATINI = REZERVATINI + TotSosit
                                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                      AND CODComanda1  = v_REZ.CODComanda1
                                      AND CodNIRStoc   = v_NS.CodNIRStoc
                                      AND CodNIRSer    = v_NS.CodNIRSer;
                       end if;
                       TotSosit := 0;

                     else
                       TotSosit := TotSosit - v_REZ.REST ;
                       update REZERVATS set Rest = 0 where CodRezervats = v_Rez.CodRezervatS;

                       begin
                         Select Count(*) into Nr from Rezervats
                                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                      AND CODComanda1  = v_REZ.CODComanda1
                                      AND CodNIRStoc   = v_NS.CodNIRStoc
                                      AND CodNIRSer    = v_NS.CodNIRSer;
                         EXCEPTION WHEN OTHERS THEN Nr := 0;
                       end;
                       if NR = 0 then
                         INSERT INTO REZERVATS
                          ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                            REST, REZERVATINI,
                            UMSEC, codcomanda1f, codobiect)
                         VALUES
                          ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                           v_REZ.REST, v_REZ.REST,
                           v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect);
                       else
                         UPDATE REZERVATS
                                SET REST = REST + v_REZ.REST, REZERVATINI = REZERVATINI + v_REZ.REST
                                where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                      AND CODComanda1  = v_REZ.CODComanda1
                                      AND CodNIRStoc   = v_NS.CodNIRStoc
                                      AND CodNIRSer    = v_NS.CodNIRSer;
                       end if;


                     end if;
                   end if;
                 else
                   delete rezervats where codrezervats = v_rez.codrezervats;
                 end if;
               else
                 if TotSosit &lt;&gt; 0 then
                   if TotSosit &lt; v_REZ.REST then
                     update REZERVATS set Rest = Rest - TotSosit where CodRezervats = v_Rez.CodRezervatS;
                     begin
                       Select Count(*) into Nr from Rezervats
                              where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                    AND CODComanda1  = v_REZ.CODComanda1
                                    AND CodNIRStoc   = v_NS.CodNIRStoc
                                    AND CodNIRSer    = v_NS.CodNIRSer
                                    AND COALESCE(CODCMDPRODMAT,0) = COALESCE(V_REZ.CODCMDPRODMAT,0);
                       EXCEPTION WHEN OTHERS THEN Nr := 0;
                     end;
                     if NR = 0 then
                       INSERT INTO REZERVATS
                        ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                          REST, REZERVATINI,
                          UMSEC, codcomanda1f, codobiect, CODCMDPRODMAT)
                       VALUES
                        ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                         TotSosit, TotSosit,
                         v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect, V_REZ.CODCMDPRODMAT);
                     else
                       UPDATE REZERVATS
                              SET REST = REST + TotSosit, REZERVATINI = REZERVATINI + TotSosit
                              where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                    AND CODComanda1  = v_REZ.CODComanda1
                                    AND CodNIRStoc   = v_NS.CodNIRStoc
                                    AND CodNIRSer    = v_NS.CodNIRSer
                                    AND COALESCE(CODCMDPRODMAT,0) = COALESCE(V_REZ.CODCMDPRODMAT,0);
                     end if;
                     TotSosit := 0;

                   else
                     TotSosit := TotSosit - v_REZ.REST ;
                     update REZERVATS set Rest = 0 where CodRezervats = v_Rez.CodRezervatS;

                     begin
                       Select Count(*) into Nr from Rezervats
                              where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                    AND CODComanda1  = v_REZ.CODComanda1
                                    AND CodNIRStoc   = v_NS.CodNIRStoc
                                    AND CodNIRSer    = v_NS.CodNIRSer
                                    AND COALESCE(CODCMDPRODMAT,0) = COALESCE(V_REZ.CODCMDPRODMAT,0);
                       EXCEPTION WHEN OTHERS THEN Nr := 0;
                     end;
                     if NR = 0 then
                       INSERT INTO REZERVATS
                        ( CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER,
                          REST, REZERVATINI,
                          UMSEC, codcomanda1f, codobiect, CODCMDPRODMAT)
                       VALUES
                        ( SEQ_REZERVATS_CODREZERVATS.NEXTVAL, v_Rez.CodComanda1, V_NS.Codnirstoc, V_NS.Codnirser,
                         v_REZ.REST, v_REZ.REST,
                         v_REZ.UMSEC, v_link.CODLINIECOMANDA, v_REZ.CodObiect, V_REZ.CODCMDPRODMAT);
                     else
                       UPDATE REZERVATS
                              SET REST = REST + v_REZ.REST, REZERVATINI = REZERVATINI + v_REZ.REST
                              where CODCOMANDA1F     = v_link.CODLINIECOMANDA
                                    AND CODComanda1  = v_REZ.CODComanda1
                                    AND CodNIRStoc   = v_NS.CodNIRStoc
                                    AND CodNIRSer    = v_NS.CodNIRSer
                                    AND COALESCE(CODCMDPRODMAT,0) = COALESCE(V_REZ.CODCMDPRODMAT,0);
                     end if;


                   end if;
                 end if;
               end if;
             end if;
           end loop;
         end if;
       end loop;
     end if;  
   end loop;

end if;

  if TIPINTR in (1,2) then
   FOR V_REC IN (SELECT * FROM TMP_DVI) LOOP
     Select Count(*) into NR from DVI where CodIntr = RecId;
     if Nr = 0 then
       SELECT SEQ_DVI_CODDVI.NEXTVAL INTO aCODDVI FROM DUAL;
       INSERT INTO DVI(CODDVI, CODINTR, TIPIMPORT)
       VALUES (aCODDVI, RECID, V_REC.TIPIMPORT);
     else
       update DVI set
         TipImport = v_rec.Tipimport
       where CodIntr = RecId;
     end if;
   END LOOP;
  end if;

  PKG_CANTAR.ELIBEREAZA_ON_SP_POSTRECORDS;

  for V_BCAR in (Select CodBCAR,CodDoc1 from BCAR  WHERE UserIdBlocaj = PKG_GLOBALS.UserId) loop
	   insert into trigar_modif (CodModif, datamodif, usermodif, Cod, codmaster, tablename, FieldName, oldvalue,newvalue)
		 Values( SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, V_BCAR.CodBCAR,V_BCAR.CodBCAR, &apos;BCAR&apos;, &apos;CODDOC1&apos;,
						 V_BCAR.CodDoc1, &apos;Null+POSTREC+UserIdBlocaj&apos;);
  end loop;
  UPDATE BCAR
  SET CodDoc1 = NULL,
      UserIdBlocaj = NULL,
      TipDoc = NULL
  WHERE UserIdBlocaj = PKG_GLOBALS.UserId;

--  mFacturaLaAvizFurnizor =  9;
  IF TIPINTR = 9  AND aTIPFACTURA &lt;&gt; 9 THEN
-- actualizez modif pu fact la aviz

    StornoAvize := &apos;2&apos;;
    SELECT pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO StornoAvize from dual;


   FOR V_REC IN ( SELECT CodLinieAviz FROM Tmp_Intrlink WHERE ActualizPret = 1 )
    LOOP
      PKG_Jurnal.setDirtyIntrAE(V_REC.CODLINIEAVIZ, aCurs);

      IF StornoAvize = &apos;1&apos; THEN
        FOR V_REC_STORNO IN (SELECT I1.CODINTR1, I1A.PU AS PRETNOU FROM INTRARI1 I1, INTRARI I, INTRARI1 I1A
                             WHERE
                               I.TIPDOC = 2
                               AND I1.CODINTR = I.CODINTR
                               AND I1.CODINTR1STORNO = V_REC.CODLINIEAVIZ
                               AND I1.CANT &lt; 0
                               AND I1A.CODINTR1 = V_REC.CODLINIEAVIZ
                            )
        LOOP
          PKG_Jurnal.setDirtyINTRAE_Storno(V_REC_Storno.CODINTR1, V_REC_Storno.PRETNOU, aCurs);
        END LOOP;
      END IF;


    END LOOP;
  ELSE
-- actualizez modif pret nirstoc
    FOR V_REC IN ( SELECT CodNirStoc, Pret FROM Tmp_NIRSTOC WHERE NVL(ActualizPret, 0) &gt; 0 )
     LOOP
       PKG_Jurnal.setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.Pret, &apos;0&apos;, 0);
     END LOOP;
  END IF;

  IF TIPINTR = 9  AND aTIPFACTURA = 9 THEN
-- actualizez modif pu fact la aviz
   FOR V_REC IN
   (
      SELECT
       I1_AE.CODINTR1 AS CODLINIEAVIZ,
       I1_AE.PU AS PU_AE,
       I1_FACT.PU AS PU_FACT
      FROM
       INTRARI1 I1_FACT,
       INTRASTEPTLINK IL,
       INTRARI1 I1_AE
      WHERE
        I1_FACT.CODINTR = RECID
        AND IL.CODLINIEFACTURA = I1_FACT.CODINTR1
        AND I1_AE.CODINTR1 = IL.CODINTR1
        AND I1_AE.PU &lt;&gt;  I1_FACT.PU
    )
    LOOP
      PKG_Jurnal.setDirtyIntrAEASTEPT(V_REC.CODLINIEAVIZ, V_REC.PU_FACT, aCurs);
    END LOOP;
  END IF;



   LockStocFaraCertif := &apos;2&apos;;
   BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;LockStocFaraCertif&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO LockStocFaraCertif FROM DUAL;
     EXCEPTION WHEN OTHERS THEN LockStocFaraCertif := &apos;2&apos;;
   END;

   IF LockStocFaraCertif = &apos;1&apos; THEN
     FOR V_REC IN
     (SELECT NSE.CODNIRSER
      FROM
        TMP_NIRSTOC NS,
        NIRSER NSE,
        NARTOBJ O,
        NART A
      WHERE
        NSE.CODNIRSTOC   = NS.CODNIRSTOC
        AND O.CODOBIECT  = NS.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
        AND NVL(A.MUSAICALITATE, 0) = 1
        AND NVL(NSE.CODCERTIF, 0) = 0
     )
     LOOP
       UPDATE NIRSER
       SET
         STARE = 4
       WHERE
         CODNIRSER = V_REC.CODNIRSER;
     END LOOP;
   END IF;


--pregatesc dezasamblarile
  IF TIPINTR = 7 THEN
		BEGIN
       Select codLivr1 into vCod from Dezasamblari1 where CODINTRLINK = RECID;
		EXCEPTION WHEN OTHERS THEN vCod := 0;
		END;

		Select Count(*) into NR from TMP_DEZASAMBLARI ;
		if NR = 0 then
			 delete DEZASAMBLARI1 where CODINTRLINK = RECID ;
		else
			 FOR V_REC IN (select * from TMP_DEZASAMBLARI) LOOP
				 Update DEZASAMBLARI1 set Valoare = (Select Nvl(ValDoc,0) + Nvl(ValSuplim,0) from TMP_INTRARI)
				 where codLivr1 = V_Rec.codLivr1 and CODINTRLINK = RECID;
				 NR := SQL%rowcount;
				 if NR = 0 then
					 Insert into DEZASAMBLARI1 (codLivr1, CODINTRLINK, Valoare)
					 Values (V_Rec.CodLivr1, RECID, (Select Nvl(ValDoc,0) + Nvl(ValSuplim,0) from TMP_INTRARI));
				 end if;
				 vCod := v_rec.CodLivr1;
			 END LOOP;
		end if;
		if vCod &gt; 0 then
			BEGIN
				SELECT T.Valoare - Nvl((Select Sum(Nvl(Valoare, 0)) from Dezasamblari1 where codLivr1 = vCod),0)
							 into aVALOARE
				FROM Dezasamblari T WHERE T.codLivr1 = vCod;
			EXCEPTION WHEN OTHERS THEN aVALOARE := 0;
			END;

			if Round(aVALOARE,0) = 0 then
				update DEZASAMBLARI set Inchisa = 1 where CodLivr1 = VCod;
			else
				update DEZASAMBLARI set Inchisa = 0 where CodLivr1 = VCod;
			end if;
		end if;
	end if;

-- DOCUMENTE CARE AU CA Transportator PE FURNIZORUL DE PE DOCUMENTUL CURENT
 FOR V_REC IN (
                SELECT CODINTRLINK, VALTRANSPORT FROM TMP_INTRDOCTRANSP_INI
                UNION ALL
                SELECT CODINTRLINK, VALTRANSPORT FROM TMP_INTRDOCTRANSP
              )
 LOOP
   UPDATE INTRARI I
   SET
    VALTRANSPORT = (SELECT NVL(SUM(VALTRANSPORT), 0) FROM INTRDOCTRANSP WHERE CODINTRLINK = I.CODINTR)
   WHERE
     CODINTR = V_REC.CODINTRLINK;
 END LOOP;


 BEGIN
   PKG_JURNAL.SET_SKIPUPDATEJURNFLAG(1);

   FOR V_REC IN
   (
    SELECT I1.CODINTR1
    FROM
      INTRARI I,
      INTRARI1 I1,
    (
                  SELECT CODINTRLINK FROM TMP_INTRDOCTRANSP_INI
                  UNION
                  SELECT CODINTRLINK FROM TMP_INTRDOCTRANSP
    ) INTR_DOC_TR
    WHERE
      I.CODINTR = INTR_DOC_TR.CODINTRLINK
      AND I1.CODINTR = I.CODINTR
   )
   LOOP
     PKG_JURNAL.RecalculPRETAchiz(V_REC.CODINTR1);
   END LOOP;
   PKG_JURNAL.SET_SKIPUPDATEJURNFLAG(0);

   MERGE INTO JURNAl1 J1
   USING (SELECT DISTINCT TIPDOC, CODDOC, SUBUNITATEA, AN, LUNA FROM TMP_JURNAL_MAN) JM
   ON ( J1.CODDOC = JM.CODDOC AND J1.TIPDOC = JM.TIPDOC)
   WHEN MATCHED THEN UPDATE SET DIRTY = 1
   WHEN NOT MATCHED THEN INSERT (CODJURNAL1, TIPDOC, CODDOC, SUBUNITATEA, AN, LUNA, DIRTY) VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, JM.TIPDOC, JM.CODDOC, JM.SUBUNITATEA, JM.AN, JM.LUNA, 1);
 END;




  PKG_GLOBALS.MarkDirtyJurnal;

  FOR V_REC IN
  (SELECT IM.CODINTR1
   FROM
     INTRARI1_MAN IM,
     TMP_INTRARI1 I1
   WHERE
     I1.CODINTR1 = IM.CODINTR1 AND IM.PRELUAT &gt; 0 AND NVL(I1.PRELUAT, 0) = 0
  )
  LOOP
	  begin
		 Select CodBCAR into aCodBCAR from BCAR WHERE TipDoc = TIPINTR AND CodDoc1 = V_REC.CodIntr1;
		 insert into trigar_modif (CodModif, datamodif, usermodif, Cod, codmaster, tablename, FieldName, oldvalue,newvalue)
		 Values( SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, aCodBCAR,aCodBCAR, &apos;BCAR&apos;, &apos;CODDOC1&apos;,
						 V_REC.CodIntr1, &apos;Null+POSTREC+INTRARI1_MAN&apos;);
		exception when others then
			 aCodBCAR := 0;
		end;
    UPDATE BCAR
    SET
     CODDOC1 = NULL,
     TIPDOC = NULL
    WHERE
      TIPDOC = TIPINTR
      AND CODDOC1 = V_REC.CODINTR1;
  END LOOP;

  IF TIPINTR = 2 THEN
    FOR V_REC IN
      (
        SELECT
          I1.CODINTR1,
          IL.CODINTR1STORNO
        FROM
          INTRARI1 I1,
          INTRARI1 IL
        WHERE
          I1.CODINTR = RECID
          AND NVL(IL.CODINTR1, 0) = NVL(I1.CODINTR1LINK, 0)
          AND NVL(IL.CODINTR1STORNO, 0) &lt;&gt; 0
      )
      LOOP
         UPDATE BCAR
         SET
            CODDOC1 = V_REC.CODINTR1
         WHERE
            TIPDOC = 2 AND CODDOC1 = V_REC.CODINTR1STORNO;
      END LOOP;
  END IF;


-- VALORICE FARA DESCARCARE GENERATE DE DOCUMENTUL CURENT
 FOR V_REC IN
   (SELECT L1.CODLIVR1
    FROM
      LIVRVAL LV,
      LIVR1 L1,
      LIVR L,
      TMP_IOART_LUNA IOALUNA
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1 AND L.CODLIVR = L1.CODLIVR AND
      L.CODINTR = RECID AND  LV.CODIOART = IOALUNA.CODIOART AND NVL(IOALUNA.DESCARCAREG, 0) = 0
    )
 LOOP
   UPDATE LIVR1 L1
     SET
      L1.RESTIESVAL = L1.CANT -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IESVALLINK IL
                  LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                WHERE
                  IL.CODLIVR1 = L1.CODLIVR1 AND
                  IL.CODIES1 = I1.CODIES1   AND
                  I.CODIES = I1.CODIES      AND
                  I.OPERAT = 1 AND I.ANULAT = 0
                )
   WHERE
   CODLIVR1 = V_REC.CODLIVR1;
  END LOOP;

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIP WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIP SET CODINTRARIP = SEQ_INTRARIP_CODINTRARIP.NEXTVAL  WHERE CODINTRARIP &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIP SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIP SELECT * FROM TMP_INTRARIP &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRPF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRPF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRPF WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRPF SET CODINTRPF = SEQ_INTRPF_CODINTRPF.NEXTVAL  WHERE CODINTRPF &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRPF SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRPF SELECT * FROM TMP_INTRPF &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRSUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRSUB&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRSUB WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRSUB SET CODINTRSUB = SEQ_INTRSUB_CODINTRSUB.NEXTVAL  WHERE CODINTRSUB &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRSUB SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRSUB SELECT * FROM TMP_INTRSUB &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIF WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIF SET CODINTRARIF = SEQ_INTRARIF_CODINTRARIF.NEXTVAL  WHERE CODINTRARIF &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIF SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIF SELECT * FROM TMP_INTRARIF &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRFAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRFAST&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRFAST WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRFAST SET CODINTRFAST = SEQ_INTRFAST_CODINTRFAST.NEXTVAL  WHERE CODINTRFAST &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRFAST SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRFAST SELECT * FROM TMP_INTRFAST &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIAE WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIAE SET CODINTRARIAE = SEQ_INTRARIAE_CODINTRARIAE.NEXTVAL  WHERE CODINTRARIAE &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIAE SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIAE SELECT * FROM TMP_INTRARIAE &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIFA WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIFA SET CODINTRARIFA = SEQ_INTRARIFA_CODINTRARIFA.NEXTVAL  WHERE CODINTRARIFA &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIFA SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIFA SELECT * FROM TMP_INTRARIFA &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARICF WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARICF SET CODINTRARICF = SEQ_INTRARICF_CODINTRARICF.NEXTVAL  WHERE CODINTRARICF &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARICF SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARICF SELECT * FROM TMP_INTRARICF &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRAST&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRAST WHERE CODINTR =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRAST SET CODINTRAST = SEQ_INTRAST_CODINTRAST.NEXTVAL  WHERE CODINTRAST &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRAST SET CODINTR = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRAST SELECT * FROM TMP_INTRAST &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIP1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIP1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIP1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIP1 SET CODINTRARIP1 = SEQ_INTRARIP1_CODINTRARIP1.NEXTVAL  WHERE CODINTRARIP1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIP1 SELECT * FROM TMP_INTRARIP1 &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIF1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIF1 SET CODINTRARIF1 = SEQ_INTRARIF1_CODINTRARIF1.NEXTVAL  WHERE CODINTRARIF1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIF1 SELECT * FROM TMP_INTRARIF1 &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1PF&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1PF&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTR1PF WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTR1PF SET CODINTR1PF = SEQ_INTR1PF_CODINTR1PF.NEXTVAL  WHERE CODINTR1PF &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTR1PF SELECT * FROM TMP_INTR1PF &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1SUB&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1SUB&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTR1SUB WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTR1SUB SET CODINTR1SUB = SEQ_INTR1SUB_CODINTR1SUB.NEXTVAL  WHERE CODINTR1SUB &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTR1SUB SELECT * FROM TMP_INTR1SUB &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1FAST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1FAST&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTR1FAST WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTR1FAST SET CODINTR1FAST = SEQ_INTR1FAST_CODINTR1FAST.NEXTVAL  WHERE CODINTR1FAST &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTR1FAST SELECT * FROM TMP_INTR1FAST &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTR1AST&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTR1AST&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTR1AST WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTR1AST SET CODINTR1AST = SEQ_INTR1AST_CODINTR1AST.NEXTVAL  WHERE CODINTR1AST &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTR1AST SELECT * FROM TMP_INTR1AST &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARICF1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARICF1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARICF1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARICF1 SET CODINTRARICF1 = SEQ_INTRARICF1_CODINTRARICF1.NEXTVAL  WHERE CODINTRARICF1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARICF1 SELECT * FROM TMP_INTRARICF1 &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIAE1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIAE1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIAE1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIAE1 SET CODINTRARIAE1 = SEQ_INTRARIAE1_CODINTRARIAE1.NEXTVAL  WHERE CODINTRARIAE1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIAE1 SELECT * FROM TMP_INTRARIAE1 &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;INTRARIFA1&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_INTRARIFA1&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM INTRARIFA1 WHERE CODINTR1 IN (SELECT CODINTR1 FROM INTRARI1_MAN)  &apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_INTRARIFA1 SET CODINTRARIFA1 = SEQ_INTRARIFA1_CODINTRARIFA1.NEXTVAL  WHERE CODINTRARIFA1 &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;INSERT INTO INTRARIFA1 SELECT * FROM TMP_INTRARIFA1 &apos;;
  END IF;
*/
  -- ajustez rezervarile pt cazurile de diminuare
  for v_rec in (select ns.rest, ns.codnirstoc, (select sum(r.rest) from rezervats r where r.codnirstoc = ns.codnirstoc) - ns.rest cantdim
                from nirstoc ns
                     inner join intrari1 i1 on i1.codintr1 = ns.codintr1
                     inner join tmp_nirstoc_initial nsi on nsi.codnirstoc = ns.codnirstoc
                where i1.codintr = recid and ns.rest &lt; nsi.rest
                      and (select sum(r.rest) from rezervats r where r.codnirstoc = ns.codnirstoc) &gt; ns.rest
                ) loop
    aCant := v_rec.cantdim;
    for v_rez in (select rest, codrezervats
                  from rezervats
                  where codnirstoc = v_rec.codnirstoc and rest &gt; 0
                  order by codrezervats desc
                  ) loop
      if aCant &gt; v_rez.rest then
        delete rezervats where codrezervats = v_rez.codrezervats;
        aCant := aCant - v_rez.rest;
      else
        update rezervats set rest = rest - aCant where codrezervats = v_rez.codrezervats;
        aCant := 0;
      end if;
      if aCant = 0 then Exit; end if;
    end loop;
  end loop;

  if aCountBCAR &gt; 0 then
    for v_rec in (select b.codbcar, i.delegat, i.partener codpartener
                  from intrari1 i1
                       inner join intrari i on i.codintr = i1.codintr
                       inner join bcar b on b.coddoc1 = i1.codintr1 and b.tipdoc = tipintr
                  where i.codintr = recid
                  ) loop
      update bcar set coddelegat = aDelegat, codpartener = aPartGest where codbcar = v_rec.codbcar;
    end loop;
  end if;


  IF aANULAT = 1 or aOPERAT = 0 THEN
    DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIntr);
    DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPIntr;
    FOR V_REC IN (SELECT C.CODCHELTAVANS, C.CODINTR1
    FROM
      INTRARI1 I1,
      CHELTAVANS C
    WHERE
      I1.CODINTR = RECID
      AND C.CODINTR1 = I1.CODINTR1
    )
   LOOP
      DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
      DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_REC.CODCHELTAVANS;
      DELETE FROM MASTERCHELTAVANS WHERE CODINTR1 = V_REC.CODINTR1;
      DELETE FROM JURNAL  WHERE TIPDOC = 52 AND CODDOC = V_REC.CODCHELTAVANS;
      DELETE FROM JURNAL1 WHERE TIPDOC = 52 AND CODDOC = V_REC.CODCHELTAVANS;
   END LOOP;

  END IF;


  if TipIntr in (1,2,3,4,5,9) then
    PKG_SAFT.UpdateTaxDecl(0, RecId);
	end if;

  if TipIntr in (1,2) and PKG_CATEGCONST.GetValConstanta(&apos;ContrComInactiv&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    for v_rec in (
      select distinct c1.codcontract, c.datadoc, Decode(TipDoc,10,&apos;CcF&apos;,27,&apos;CcC&apos;)||c.NrDoc||&apos;/&apos;||c.DataDoc Doc
      from tmp_intrari1 i1
           inner join contract1 c1 on i1.codcontract1 = c1.codcontract1
           inner join contract c on c.codcontract = c1.codcontract
      where c.activ &gt; 0 and c1.cant &gt; 0
    ) loop
      select sum(case
                   when c1.cant - coalesce((select sum(i1.cant)
                                   from intrari1 i1, intrari i
                                   where i1.codcontract1 = c1.codcontract1 and i1.codintr = i.codintr and i.tipdoc in (1,2)
                                   ),0
                                   ) &lt; 0 then 0
                   else c1.cant - coalesce((select sum(i1.cant)
                                   from intrari1 i1, intrari i
                                   where i1.codcontract1 = c1.codcontract1 and i1.codintr = i.codintr and i.tipdoc in (1,2)
                                   ),0)
                end
                ) into aRest
      from contract1 c1
      where c1.codcontract = v_rec.codcontract and c1.cant &gt; 0;
      if aRest &lt;= 0 then
        update contract set activ = 0 where codcontract = v_rec.codcontract;
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;CONTRACT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codcontract,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, v_rec.Doc,
                                        &apos;Inactivare contract, acoperire realizata prin &apos;||aDoc, PKG_GLOBALS.GET_EXE_VERSION);
      end if;
    end loop;
  end if;


  DELETE FROM GENERAL G
  WHERE
    TIPDOC = TIPINTR
    AND CODDOC = RECID
    AND (SELECT COUNT(*) FROM OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL) = 0;
  PKG_CFGTABLES.EXT_POSTRECORDS(TipIntr, Operation);

  COMMIT;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
    begin
      select count(*) into aCount from tmp_manevra_intr1;
    exception when others then
      aCount := 0;
    end;
    if aCount &gt; 0 then GenereazaModificareDePretMifix(aDataDoc, aAn, aLuna, aSubunitatea); end if;
  end if;
  
  -- sa vedem cum merge dupa commitul final--
  NotifyModif(Operation, RecId, &apos;INTRARI&apos;);
  commit;
  
 EXCEPTION WHEN OTHERS THEN BEGIN
   ROLLBACK;
   RAISE;
 END;
 END;
END;

procedure GenereazaModificareDePretMifix(aDataDoc in date, aAn in number, aLuna in number, aSubunitatea in number) is
aCount number(10);
aCodNIR number(20);
aCarnetTransf number(20);
aCarnetLivr number(20);
aSerieTransf VARCHAR2(10);
aSimbolTransf VARCHAR2(10);
aSerieLivr VARCHAR2(10);
aSimbolLivr VARCHAR2(10);
aNrTransf number(20);
aNrLivr number(20);
aCodTransf1 number(20);
aCodLivr1 number(20);
aCodTransf number(20);
begin
  aCarnetTransf := pkg_carnetedoc.GETCARNETTRANSF;
  aCarnetLivr   := pkg_carnetedoc.GETCARNETLIVR;

  if aCarnetTransf = 0 or aCarnetLivr = 0 then return; end if;

  for v_m in (select tmp.codintr1, tmp.pretpredare, decode(nvl(i.curs,0),0,1,i.curs) curs
              from tmp_manevra_intr1 tmp
                   inner join intrari1 i1 on i1.codintr1 = tmp.codintr1
                   inner join intrari i on i.codintr = i1.codintr
              ) loop

  for v_rec in (
    SELECT
      NS.CODOBIECT,
      NS.PRET,
      NS.REST,
      NS.RESTUM1,
      NS.RESTUM2,
      NS.TIPDOCACHIZ,
      NS.TIPSERIE,
      NS.UMSEC,
      NS.DATAACHIZ,
      NS.FURN,
      NS.TVA AS TVANEEX,
      NS.PUMaximal, NS.AdMax,
      NS.CODNIRSTOC,
      NS.PROVIZION,
      NS.PUVAL,
      NS.D1, NS.D2, NS.D3,
      NS.CODGESTPROD,
      NS.CODLOCATIE,
      NS.ROTLEI,
      NS.ROTVALUTA,
      NS.CANTFURN,
      NS.CANTNIR,
      O.DENUMIRE,
      N.GEST,
      IO.CODIOART,
      IO.DIFERENTE,
      IO.PUSTANDARD,
      IO.DIFPRET,
      IO.MG,
      IO.ARETVANEEX,
      I1.CONTSERV,
      I1.CODMIFIX,
      I1.Cant,
      NS.PRET - NS.ADAOS AS PRETACHIZ,
      TL.CODTVA,
      TL.PROCENT AS PROCTVA,
      NSE.CODNIRSER,
      NSE.CODSERIE,
      NSE.CODCERTIF,
      NSE.STARE,
      NSE.DATAPROD,
      NSE.OBS,
      NVL(NSE.TG, NS.TG) TG,
      O.ROTUNJIRE,
      v_m.CODINTR1,
      v_m.PRETPREDARE,
      NUM1.PARITATE,
      MFIX.NRINVENTAR
    FROM
      MIFIX1 MFIX1,
      MIFIX MFIX,
      NIRSTOC NS
      LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
      NARTOBJ O,
      TMP_NART_LUNA AL,
      TMP_NTVA_LUNA TL,
      TMP_IOART_LUNA IO,
      NIR N,
      NGEST G,
      INTRARI1 I1,
      NUM1
    WHERE
      I1.CODINTR1 = v_m.CODINTR1
      AND MFIX1.CODNIRSTOC = NS.CODNIRSTOC
      AND MFIX.CODMIFIX = I1.CODMIFIX
      AND I1.CODMIFIX = MFIX1.CODMIFIX
      AND NS.CODOBIECT = O.CODOBIECT
      AND O.CODARTICOL = AL.CODARTICOL
      AND AL.CODTVA    = TL.CODTVA
      AND NS.CODNIR    = N.CODNIr
      AND NS.CODIOART  = IO.CODIOART
      AND N.GEST = G.CODGEST
      AND NUM1.CODUM1 = NS.UMSEC
      AND MFIX1.ANSTART = aAN AND MFIX1.LUNASTART = aLUNA
    ORDER BY CODOBIECT
    ) loop

    aCodTransf := 0;
    aCodNir := 0;
    aCodTransf1 := 0;
    aCodLivr1 := 0;
    delete tmp_transf;
    delete tmp_transf1;
    delete tmp_nir;
    delete tmp_livr;
    delete tmp_nirstoc;
    delete tmp_livr1;
    delete TMP_NIRSTOC_RECOD;
    DELETE TMP_IMBMIFIXLINK;
    delete tmp_jurnal;
    delete tmp_jurnal1;

    aNrTransf     := pkg_carnetedoc.GETNEXTNRDOC(aCarnetTransf, aSerieTransf, aSimbolTransf);
    aNrLivr       := pkg_carnetedoc.GETNEXTNRDOC(aCarnetLivr, aSerieLivr, aSimbolLivr);

    insert into tmp_transf(codtransf, tipdoc, anulat, blocat, operat, prefixdoc, carnetdoc, nrdoc, datadoc, valdoc, tvadoc, an, luna,
                           tiprepsuplim, subunitatea, tipmodifpret, obs)
    values (0, 13, 0, 0, 1, &apos;PV&apos;, aCarnetTransf, aNrTransf, aDataDoc, (V_REC.PRET + V_REC.PRETPREDARE) * v_rec.rest, 0, aAn, aLuna,
            0, aSubunitatea, 4, &apos;Nr. inventar: &apos;||V_REC.NRINVENTAR||&apos; - &apos;||V_REC.DENUMIRE);
    insert into tmp_livr(codlivr, codtransf, carnetlivr, nrlivr, datalivr, tiplivr, anulat, blocat, operat)
    values (-1, 0, aCarnetLivr, aNrLivr, aDataDoc, 13, 0, 0, 1);

    begin
      select count(*) into aCount from tmp_nir where gest = v_rec.gest;
    exception when others then aCount := 0;
    end;

    if aCount = 0 then
      aCodNIR := aCodNIR - 1;
      insert into tmp_nir(codnir, codtransf, datanir, gest, tipnir, anulat, blocat, operat)
      values (aCodNIR, 0, aDataDoc, v_rec.Gest, 13, 0, 0, 1);
    else
      begin
        select codnir into aCodNIR from tmp_nir where gest = v_rec.gest;
      exception when others then
        aCodNIR := aCodNIR - 1;
        insert into tmp_nir(codnir, codtransf, datanir, gest, tipnir, anulat, blocat, operat)
        values (aCodNIR, 0, aDataDoc, v_rec.Gest, 13, 0, 0, 1);
      end;
    end if;

    aCodTransf1 := aCodTransf1 - 1;
    insert into tmp_transf1(codtransf1, codtransf, indexlocal, tiplinie, umsec, codobiect, pu, cant, tva,
                            codcont, PUMaximal, codmifix, paritate)
    values(aCodTransf1, 0, aCodTransf1, &apos;=&apos;, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.PRET + V_REC.PRETPREDARE, v_rec.rest, 0,
           V_REC.CONTSERV, V_REC.PUMaximal, V_REC.CODMIFIX, V_REC.PARITATE);

    insert into tmp_imbmifixlink (codtransf1, codintr1, codmifix, cant)
    values(aCodTransf1, v_rec.codintr1, v_rec.codmifix,V_REC.PRETPREDARE);

    aCodLivr1 := aCodLivr1 - 1;
    insert into tmp_livr1(codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, pmp, umsec, cantrezervat, codcertif, pmpvaluta, pmpdoc, pmpvalutadoc, contintermed,
                          PARITATE)
    values (aCodLivr1, -1, aCodTransf1, v_rec.codnirstoc, 1, v_rec.codnirser, 0, v_rec.umsec, 0, 0, 0, 0, 0, 0,
            V_REC.PARITATE);

    insert into tmp_nirstoc (codnir, codtransf1, codnirstocparinte, cantnir, umsec, codobiect, codioart, pret, adaos, tva, tipserie,
                             codlivr1, rest, procentadaos, supliment, cantfurn, rotlei, rotvaluta, codlocatie, tg, PUMaximal, AdMax,
                             furn, dataachiz, tipdocachiz, codgestprod, subunitatea, d1, d2, d3, puval, provizion, PARITATE)
    values(aCodNIR, aCodTransf1, v_rec.codnirstoc, v_rec.rest, v_rec.umsec, v_rec.codobiect, v_rec.codioart, V_REC.PRET + V_REC.PRETPREDARE,
           V_REC.PRET + V_REC.PRETPREDARE, 0, v_rec.tipserie, aCodLivr1, v_rec.rest, 0, 0, v_rec.rest, v_rec.rotlei, v_rec.rotvaluta,
           v_rec.codlocatie, v_rec.tg, v_rec.PUMaximal, v_rec.AdMax,
           v_rec.furn, v_rec.dataachiz, v_rec.tipdocachiz, v_rec.codgestprod, aSubunitatea, v_rec.d1, v_rec.d2, v_rec.d3, v_rec.puval, v_rec.provizion,
           V_REC.PARITATE
          );

    INSERT INTO tmp_JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, DIRTY, SUBUNITATEA)
    values (-1, 0, 13, 1, aan, aluna, 1, aSubunitatea);
    INSERT INTO tmp_JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, SUBUNITATEA)
    values (-1, 0, 13, aCodTransf1, aAN, aLUNA, aSUBUNITATEa);

    begin
      pkg_miscari_interne.SetSkipMifix(True);
      pkg_miscari_interne.SP_POSTRECORDS(-1, aCodTransf);
      update intrari1 set RestIMBMF =
           CASE
             WHEN TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(CODMIFIX, 0) &lt;&gt; 0
             THEN Cant * PU * v_m.Curs -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODINTR1 = v_m.CodINTR1 AND T.OPERAT = 1 AND T.ANULAT = 0
               )
             ELSE 0
           END
       where codintr1 = v_m.codintr1;
      pkg_miscari_interne.SetSkipMifix(False);
    exception when others then
      pkg_miscari_interne.SetSkipMifix(False);
    end;
    update jurnal1 set dirty = 1 where coddoc = aCodTransf and TipDoc = 13;
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= aAn*12+aLuna;
    for v_xxx in (select * from TMP_NIRSTOC_RECOD) loop
      update mifix1 set
        codnirstoc = v_xxx.codnou,
        pret = pret + V_REC.PRETPREDARE
      where codnirstoc = v_rec.codnirstoc and anstart*12+lunastart &gt;= aAn*12+aLuna and codmifix = v_rec.codmifix;
      insert into mastermifix(codnirstoc,
                              codclasif,
                              duratan,
                              duratanf,
                              duratang,
                              codanaliza)
      select v_xxx.codnou, m.codclasif, m.duratan, m.duratanf, m.duratang, m.codanaliza
      from mastermifix m
      where m.codnirstoc = v_rec.codnirstoc;
    end loop;
    update intrari1 set restimbmf = 0 where codintr1 = v_m.codintr1;

    FOR V_xxx IN (SELECT M.CODMIFIX, M1.PRET AS VALOARE
                  FROM
                    MIFIX M,
                    MIFIX1 M1
                  WHERE
                    EXISTS (SELECT CODMIFIX FROM TMP_IMBMIFIXLINK WHERE CODMIFIX = M.CODMIFIX)
                    AND M1.CODMIFIX = M.CODMIFIX
                    AND M1.ANSTART * 12 + M1.LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
                    AND M1.ANSTART * 12 + M1.LUNASTART =
                        (SELECT MAX(ANSTART * 12 + LUNASTART)
                         FROM MIFIX1 M2
                         WHERE M2.CODMIFIX = M.CODMIFIX
                           AND M2.ANSTART * 12 + M2.LUNASTART &lt;=  PKG_GLOBALS.AnLunaLucru
                        )
                    )
    LOOP
      UPDATE MIFIX N1
      SET
        RESTIMBMF = V_xxx.VALOARE  -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODMIFIX = N1.CODMIFIX AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
        CODMIFIX = V_xxx.CODMIFIX;
    END LOOP;

    for v_xxx in (select t.codtransf, t.prefixdoc, t.datadoc, t.nrdoc, t.tipdoc,
                         ns.pret pret_vechi, ns_nou.pret pret_nou, nir.gest gest_vechi, nir_nou.gest gest_nou,
                         t1.cant, t1.codtransf1, t.obs
                  from transf t
                       inner join transf1 t1 on t.codtransf = t1.codtransf
                       inner join imbmifixlink l on t1.codtransf1 = l.codtransf1
                       inner join livr1 l1 on t1.codtransf1 = l1.codies1
                       inner join livr lv on lv.codlivr = l1.codlivr and lv.codtransf = t.codtransf
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join nirstoc ns_nou on ns_nou.codtransf1 = t1.codtransf1
                       inner join nir nir_nou on ns_nou.codnir = nir_nou.codnir
                  where t.codtransf = aCodTransf and l.codintr1 = v_rec.codintr1
                 ) loop
      begin
        select count(*) into aCount from fisamf where codmifix = v_rec.codmifix;
      exception when others then
        aCount := 0;
      end;
      if aCount &gt; 0 then
        insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
        values(seq_fisamf_codfisamf.nextval, v_rec.codmifix, 3, v_xxx.datadoc, v_xxx.gest_vechi, v_xxx.gest_nou,
               v_xxx.pret_vechi, v_xxx.pret_nou, v_xxx.prefixdoc, v_xxx.nrdoc, v_xxx.cant, v_xxx.codtransf1, v_xxx.tipdoc);
      else
        insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
        values(seq_fisamf_codfisamf.nextval, v_rec.codmifix, 1, v_xxx.datadoc, v_xxx.gest_vechi, v_xxx.gest_nou,
               v_xxx.pret_vechi, v_xxx.pret_nou, v_xxx.prefixdoc, v_xxx.nrdoc, v_xxx.cant, v_xxx.codtransf1, v_xxx.tipdoc);
      end if;
    end loop;
    commit;
  end loop;
  end loop;
end;


FUNCTION GETLASTPRETACHIZVAL(aCodObiect IN NUMBER, aCodMoneda IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
aCurs NUMBER(20, 7);
BEGIN
  FOR V_REC IN (
    SELECT I.CURS,
        NS.PRET - Nvl(NS.ADAOS,0) - CASE
                                      WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR
                                      ELSE 0
                                    END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
      AND N.OPERAT = 1
      AND N.ANULAT = 0
      AND I.MONEDA = aCodMoneda
    ORDER BY N.DATANIR DESC )
  LOOP
    aCurs := NVL(V_REC.CURS, 0);
    IF aCurs = 0 then aCurs := 1;end if;
    RETURN V_REC.PretAchiz / aCurs;
  END LOOP;
  RETURN 0;
END;


FUNCTION GETLASTPRETACHIZVAL_SUBUNIT(aCodObiect IN NUMBER, aCodMoneda IN NUMBER, aExclSupl IN NUMBER DEFAULT 0) RETURN NUMBER IS
aCurs NUMBER(20, 7);
BEGIN
  FOR V_REC IN (
    SELECT I.CURS, NS.PRET - Nvl(NS.ADAOS,0) - CASE WHEN NVL(aExclSupl,0) = 1 AND NS.CANTNIR &lt;&gt; 0 THEN Nvl(NS.SUPLIMENT,0)/NS.CANTNIR ELSE 0 END PretAchiz
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
    WHERE NS.CODOBIECT = aCODOBIECT
      AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
      AND N.OPERAT = 1
      AND N.ANULAT = 0
      AND I.MONEDA = aCodMoneda
      AND Nvl(G.CODSUBUNIT, 1) = Decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
    ORDER BY N.DATANIR DESC )
  LOOP
    aCurs := NVL(V_REC.CURS, 0);
    IF aCurs = 0 then aCurs := 1; end if;
    RETURN V_REC.PretAchiz / aCurs;
  END LOOP;
  RETURN 0;
END;

function UPDATEEXTDATAREF(RecId in number, aDataRef in varchar2) return number is
adoc varchar2(500);
adatadoc date;
begin
  SELECT
    DATADOC,PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC||&apos;-DataStart&apos;
  INTO
    aDataDoc,
    adoc
  FROM INTRARI where codintr = recid;
  begin
    execute immediate &apos;begin &apos;||chr(13)||
                      &apos; MERGE INTO INTRARIF F &apos;||CHR(13)||
                      &apos; USING ( &apos;||CHR(13)||
                      &apos;         SELECT    &apos;||CHR(13)||
                      &apos;           &apos;||RECID||&apos; CODINTR, TO_DATE(&apos;&apos;&apos;||ADATAREF||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DATASTART &apos;||CHR(13)||
                      &apos;         FROM DUAL &apos;||CHR(13)||
                      &apos;         ) N &apos;||CHR(13)||
                      &apos;  ON (F.CODINTR = N.CODINTR) &apos;||CHR(13)||
                      &apos;  WHEN NOT MATCHED THEN INSERT (CODINTR, DATASTART) &apos;||CHR(13)||
                      &apos;                                VALUES  &apos;||CHR(13)||
                      &apos;                               (N.CODINTR, N.DATASTART) &apos;||CHR(13)||
                      &apos;  WHEN MATCHED THEN UPDATE SET F.DATASTART = N.DATASTART;&apos;||CHR(13)||
                      &apos;commit; end;&apos;;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RecID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
      commit;
    END IF;
    return 1;
  exception when others then Return 0;
  end;
end;

function GetDataStart(aRECID in number) return date is
Ret date;
begin
  begin
    execute immediate &apos;select datastart from intrarif where codintr = &apos;||aRECID into Ret;
    if Ret &lt;&gt; to_date(&apos;01.01.1900&apos;,&apos;dd.mm.yyyy&apos;) then
      Return Ret;
    end if;
  exception when others then Return to_date(&apos;01.01.1900&apos;,&apos;dd.mm.yyyy&apos;);
  end;
end;

FUNCTION GETCMDFURN(ACODOBIECT IN NUMBER) RETURN NUMBER IS
AREZ NUMBER(20,7);
BEGIN
  BEGIN
    SELECT SUM(C1.RESTACCEPTAT) INTO AREZ
    FROM COMANDA1 C1
         INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    WHERE Nvl(C.INCHISA, 0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8
          AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR C.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE)
          AND C1.CODOBIECT = ACODOBIECT;
  EXCEPTION WHEN OTHERS THEN AREZ := 0;
  END;
  RETURN AREZ;
END;

PROCEDURE AdaugaScanare(
aCodDoc in number,
aTipDoc in number,
aSN in varchar2,
aEXP in varchar2,
aCodSerie in number,
aCodObiect in number,
aGTIN in varchar2,
aRaspuns in varchar2,
aCodRaspuns in varchar2,
aStatus in varchar2,
aCod out varchar2
) IS
vCod number(20);
vCodSerie number(20);
BEGIN
  if aTipDoc in (1,2,3,5) then
    select seq_seriiintr_codserieintr.nextval into vCod from dual;
    select seq_nserii_codserie.nextval into vCodSerie from dual;
    insert into nserii(codserie,serie,codobiect,codparinte)
    values (vCodSerie,aSN,aCodObiect,aCodSerie);
    insert into seriiintr(codserieintr,codintr,codobiect,codserie,dataexp,gtin,Raspuns,Codraspuns,status)
    values (vCod,aCodDoc,aCodObiect,vCodSerie,aEXP,aGTIN,aRaspuns,aCodRaspuns,aStatus);
  else if aTipDoc in (14,19,20) then
    select seq_seriiies_codserieies.nextval into vCod from dual;
    select seq_nserii_codserie.nextval into vCodSerie from dual;
    insert into nserii(codserie,serie,codobiect,codparinte)
    values (vCodSerie,aSN,aCodObiect,aCodSerie);
    insert into seriiies(codserieies,codies,codobiect,codserie,dataexp,gtin,Raspuns,Codraspuns,status)
    values (vCod,aCodDoc,aCodObiect,vCodSerie,aEXP,aGTIN,aRaspuns,aCodRaspuns,aStatus);
  else if aTipDoc = 18 then
    select seq_seriicmd_codseriecmd.nextval into vCod from dual;
    select seq_nserii_codserie.nextval into vCodSerie from dual;
    insert into nserii(codserie,serie,codobiect,codparinte)
    values (vCodSerie,aSN,aCodObiect,aCodSerie);
    insert into seriicmd(codseriecmd,codcomanda,codobiect,codserie,dataexp,gtin,Raspuns,Codraspuns,status)
    values (vCod,aCodDoc,aCodObiect,vCodSerie,aEXP,aGTIN,aRaspuns,aCodRaspuns,aStatus);
  end if;
  end if;
  end if;
  commit;
  aCod := vCod;
END;

function getpmachizgest(aCodObiect in number, aCodGest in number) return number is
vCant number(20,7);
vVal number(20,7);
begin
  vCant := 0.0;
  vVal  := 0.0;

  for v_rec in (
    SELECT  nvl(NS.PRET,0)- nvl(NS.ADAOS,0) pret, ns.rest
     FROM
       NIR N,
       NIRSTOC NS,
       NGEST G
     WHERE
       NS.CODOBIECT = aCODOBIECT
       AND NS.CODNIR = N.CODNIR
       AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
       AND OPERAT = 1
       AND ANULAT = 0
       AND G.CODGEST = N.GEST
       AND G.CODGEST = ACODGEST
       AND NS.REST &gt; 0
     ORDER BY N.DATANIR ) loop
    vCant := vCant + v_rec.rest;
    vVal := vVal + v_rec.rest * v_rec.pret;
  end loop;

  if vCant &lt;&gt; 0 then
    return vVal/vCant;
  else
    return 0;
  end if;
end;

PROCEDURE POSTEFACTURA
IS
  NR NUMBER;
  VCOD NUMBER;
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_StatusDecl)
  LOOP
    SELECT COUNT(*) INTO NR FROM StatusDecl WHERE CODDOC = V_REC.CODDoc and TipDOC = V_REC.TipDoc ;
    IF NR = 0 THEN
      INSERT INTO StatusDecl( CodStatusDecl, CODDoc, TipDoc, IDINCARCARE, IDDESCARCARE, DATAINCARCARE, STARE,TIPMEDIU,
                              UserName, An, Luna, CompName, FileName ,MESAJE, CIF, SERIE_CERTIF, UIT)
      VALUES ( SEQ_StatusDecl.NEXTVAL, V_REC.CODDoc, V_REC.TipDoc, V_REC.IDINCARCARE, V_REC.IDDESCARCARE, V_REC.DATAINCARCARE, V_REC.STARE, V_REC.TIPMEDIU,
               V_REC.UserName, V_REC.An, V_REC.Luna, V_REC.CompName, V_REC.FileName, V_REC.MESAJE, V_REC.CIF, V_REC.SERIE_CERTIF, V_REC.UIT );
    ELSE
      UPDATE StatusDecl
      SET
       IDINCARCARE     = V_REC.IDINCARCARE,
       IDDESCARCARE    = V_REC.IDDESCARCARE,
       DATAINCARCARE   = V_REC.DATAINCARCARE,
       STARE           = V_REC.STARE     ,
       TIPMEDIU        = V_REC.TIPMEDIU  ,
       UserName        = V_REC.UserName  ,
       An              = V_REC.An        ,
       Luna            = V_REC.Luna      ,
       CompName        = V_REC.CompName ,
       FileName        = V_REC.FileName ,
       MESAJE          = V_REC.MESAJE,
       CIF             = V_REC.CIF,
       SERIE_CERTIF    = V_REC.SERIE_CERTIF,
       UIT             = V_REC.UIT
      WHERE
        CODDOC = V_REC.CODDoc and TipDOC = V_REC.TipDoc ;
    END IF;
    if (V_REC.TIPMEDIU = 2)and(Coalesce(V_REC.IDINCARCARE,&apos;?&apos;) &lt;&gt; &apos;?&apos;)and(V_REC.STARE = &apos;ok&apos; or V_REC.STARE = &apos;downloaded&apos;) then
      update Intrari set Blocat = 1 where CodIntr = v_rec.CodDoc and TipDoc = v_rec.Tipdoc;
    end if;
    if v_rec.stare = &apos;XML&apos; then
      for v_intr in (select CODINTR FROM INTRARI WHERE CODINTR = V_REC.CODDoc and TipDOC = V_REC.TipDoc) loop
        NotifyModif(3, V_intr.CODINTR, &apos;INTRARI&apos;);
      end loop;
    end if;
  END LOOP;
  COMMIT;
END;

procedure Aproba is
acount number(20);
begin
  for v_rec in (
    select i.codintr, i.tipdoc 
    from tmp_manevra_liste tmp
         inner join intrari i on i.codintr = tmp.valoare
    where tmp.filtru = &apos;APROBINTR&apos;
  ) loop
    begin
      SP_LOCKRECORD(v_rec.codintr);
      update intrari set aprobat = 1 where codintr = v_rec.codintr;
      select count(*) into acount from cmdaprobari where coddoc = v_rec.codintr and tipdoc = v_rec.tipdoc;
      if acount = 0 then
        insert into cmdaprobari(cod,
                                tipdoc,
                                coddoc,
                                nivel,
                                stare,
                                userid)
        values(seq_cmdaprobari_cod.nextval, v_rec.tipdoc, v_rec.codintr, 1, 1, pkg_globals.GETUSERID);
      else
        update cmdaprobari set stare = 1 where coddoc = v_rec.codintr and tipdoc = v_rec.tipdoc;
      end if;
      update tmp_manevra_liste set valoare1 = &apos;1&apos; where filtru = &apos;APROBINTR&apos; and valoare = v_rec.codintr;
      commit;
    exception when others then null;
    end;
  end loop;
end;

END pkg_INTRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6698CEC1C2CE33B25716AE42C9A61ED3B3F8080</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_INVENTAR IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_38&apos;;
vCodGest number(20);
vTipRezolvare number(1);
vDataInventar Date;
vToateArt number(1);
vToateCont number(1);
vCodInventar number(20);
vToateClasele number(1);
vToateClaseleS number(1);
vToateProd number(1);
vRezDif number(1);
vMarja number(20,7);

procedure CorectieInventContClase is
begin
  for v_rec in (select i.codinventar
                from inventar i
                     left join (select count(*) nr, codinventar from inventcont group by codinventar) cateicont on cateicont.codinventar = i.codinventar
                where i.itipcont = 1 and nvl(cateicont.nr,0) = 0 ) loop
    insert into inventcont(codinventcont, codinventar, codtipcont)
    select seq_inventcont_codinventcont.nextval, v_rec.codinventar, codioart
    from ioart where codioart &gt; 0;
  end loop;
  for v_rec in (select i.codinventar
                from inventar i
                     left join (select count(*) nr, codinventar from inventclase group by codinventar) cateiclase on cateiclase.codinventar = i.codinventar
                where i.iclase = 1 and nvl(cateiclase.nr,0) = 0 ) loop
    insert into inventclase(codinventclase, codinventar, codclasea)
    select seq_inventclase_codinventclase.nextval, v_rec.codinventar, codclasea
    from nclasea;
  end loop;
  for v_rec in (select i.codinventar
                from inventar i
                     left join (select count(*) nr, codinventar from inventclases group by codinventar) cateiclases on cateiclases.codinventar = i.codinventar
                where i.iclases = 1 and nvl(cateiclases.nr,0) = 0 ) loop
    insert into inventclases(codinventclases, codinventar, codclaseas)
    select seq_inventclases_codinvclases.nextval, v_rec.codinventar, codclaseas
    from nclaseas;
  end loop;
  for v_rec in (select i.codinventar
                from inventar i
                     left join (select count(*) nr, codinventar from inventprod group by codinventar) cateiprod on cateiprod.codinventar = i.codinventar
                where i.iprod = 1 and nvl(cateiprod.nr,0) = 0 ) loop
    insert into inventprod(codinventprod, codinventar, codpart)
    select seq_inventprod_codinventprod.nextval, v_rec.codinventar, codpart
    from npart where tippartener = 4;
  end loop;
  commit;
end;

function TestIOClase(aITipCont in number, aIClase in number, aIProd in number, aIClaseS in number, aCodGest in number) return number is
Rezultat number(20);
vCount number(10);
ContOK boolean;
ClaseOK boolean;
ClaseSOK boolean;
ProdOK boolean;
begin
  Rezultat := 0;
  if aITipCont = 1 then
    delete tmp_manevra_liste where filtru = &apos;CODTIPCONT&apos;;
    insert into tmp_manevra_liste(filtru, valoare)
    select &apos;CODTIPCONT&apos;, codioart
    from ioart where codioart &gt; 0;
  end if;
  if aIClase = 1 then
    delete tmp_manevra_liste where filtru = &apos;CODCLASEA&apos;;
    insert into tmp_manevra_liste(filtru, valoare)
    select &apos;CODCLASEA&apos;, codclasea
    from nclasea where codclasea &gt; 0;
  end if;
  if aIClaseS = 1 then
    delete tmp_manevra_liste where filtru = &apos;CODCLASEAS&apos;;
    insert into tmp_manevra_liste(filtru, valoare)
    select &apos;CODCLASEAS&apos;, codclaseas
    from nclaseas where codclaseas &gt; 0;
  end if;
  if aIProd = 1 then
    delete tmp_manevra_liste where filtru = &apos;CODPART&apos;;
    insert into tmp_manevra_liste(filtru, valoare)
    select &apos;CODPART&apos;, codpart
    from npart
    where tippartener = 4 and codpart &gt; 0;
  end if;

  select count(curent.cod) into Rezultat
  from (select tmp.valoare cod
        from tmp_manevra_liste tmp
        where tmp.filtru = &apos;CODTIPCONT&apos;
       ) curent,
       (select iio.codtipcont cod
        from inventar ii
             inner join inventcont iio on ii.codinventar = iio.codinventar
        where nvl(ii.itipcont,1) = 0 and ii.gestiune = aCodGest and nvl(ii.blocat,0) = 0
        union all
        select ioa.codioart cod
        from inventar ii, ioart ioa
        where nvl(ii.itipcont,1) = 1 and ii.gestiune = aCodGest and nvl(ii.blocat,0) = 0
       ) altele
  where curent.cod = altele.cod;
  ContOK := Rezultat = 0;

  select count(*) into vCount from nclasea where codclasea &gt; 0;
  if vCount = 0 then
    ClaseOK := False;
  else
  select count(curent.cod) into Rezultat
  from (select tmp.valoare cod
        from tmp_manevra_liste tmp
        where tmp.filtru = &apos;CODCLASEA&apos;
       ) curent,
       (select ic.codclasea cod
        from inventar iii
             inner join inventclase ic on ic.codinventar = iii.codinventar
        where nvl(iii.iclase,1) = 0 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
        union all
        select cls.codclasea cod
        from inventar iii, nclasea cls
        where nvl(iii.iclase,1) = 1 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
       )
       altele
  where curent.cod = altele.cod;
  ClaseOK := Rezultat = 0;
  end if;

  select count(*) into vCount from nclaseas where codclaseas &gt; 0;
  if vCount = 0 then
    ClaseSOK := False;
  else
  select count(curent.cod) into Rezultat
  from (select tmp.valoare cod
        from tmp_manevra_liste tmp
        where tmp.filtru = &apos;CODCLASEAS&apos;
       ) curent,
       (select ic.codclaseas cod
        from inventar iii
             inner join inventclases ic on ic.codinventar = iii.codinventar
        where nvl(iii.iclases,1) = 0 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
        union all
        select cls.codclaseas cod
        from inventar iii, nclaseas cls
        where nvl(iii.iclases,1) = 1 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
       )
       altele
  where curent.cod = altele.cod;
  ClaseSOK := Rezultat = 0;
  end if;

  select count(*) into vCount from npart where codpart &gt; 0 and tippartener = 4;
  if vCount = 0 then
    ProdOK := False;
  else
  select count(curent.cod) into Rezultat
  from (select tmp.valoare cod
        from tmp_manevra_liste tmp
        where tmp.filtru = &apos;CODPART&apos;
       ) curent,
       (select ip.codpart cod
        from inventar iii
             inner join inventprod ip on ip.codinventar = iii.codinventar
        where nvl(iii.iprod,1) = 0 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
        union all
        select p.codpart cod
        from inventar iii, npart p
        where nvl(iii.iprod,1) = 1 and p.tippartener = 4 and iii.gestiune = aCodGest and nvl(iii.blocat,0) = 0
       )
       altele
  where curent.cod = altele.cod;
  ProdOK := Rezultat = 0;
  end if;

  if ProdOK or ClaseOK or ClaseSOK or ContOK then
    return 0;
  else
    return 1;
  end if;
end;

procedure SPARGE_INVENTAR(aNrInventar in number, CodVechi in number) is
CodNou number(20);
begin
  select seq_inventar_codinventar.nextval into CodNou from dual;

  insert into inventar (codinventar, nrinventar, datainventar, gestiune, responsabil, observatii, tip, iart, itipcont, subunitate, userid, datacreare,
                        tiprezolvare, flgpalm, blocat, iclase)
  select CodNou, aNrInventar, datainventar, gestiune, responsabil, observatii, tip, iart, itipcont, subunitate, pkg_globals.userid, sysdate,
         tiprezolvare, flgpalm, blocat, iclase
  from inventar where codinventar = CodVechi;

  insert into inventcont (codinventcont, codinventar, codtipcont)
  select seq_inventcont_codinventcont.nextval, CodNou, codtipcont
  from inventcont where codinventar = CodVechi;

  insert into inventclase (codinventclase, codinventar, codclasea)
  select seq_inventclase_codinventclase.nextval, CodNou, codclasea
  from inventclase
  where codinventar = CodVechi;

  insert into inventclases (codinventclases, codinventar, codclaseas)
  select seq_inventclases_codinvclases.nextval, CodNou, codclaseas
  from inventclases
  where codinventar = CodVechi;

  insert into inventprod (codinventprod, codinventar, codpart)
  select seq_inventprod_codinventprod.nextval, CodNou, codpart
  from inventprod where codinventar = CodVechi;

  update inventar1 i1 set
  i1.codinventar = CodNou
  where i1.codinventar = CodVechi and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODINVENTAR1&apos; and tmp.valoare = i1.codinventar1);

  update inventstoc ivs set
  ivs.codinventar = CodNou
  where ivs.codinventar = CodVechi and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODINVENTAR1&apos; and tmp.valoare = ivs.codinventar1);

  commit;
end;

PROCEDURE SETPARAMS (aCodInventar IN NUMBER) IS
  aAnPrec    NUMBER(4);
  aLunaPrec  NUMBER(2); 
  aAnLucru   NUMBER(4) := PKG_GLOBALS.GetANLUCRU;
  aLunaLucru NUMBER(2) := PKG_GLOBALS.GetLUNALUCRU;
  vALLucru   NUMBER(5) := aAnLucru*12+aLunaLucru;
BEGIN
  PKG_GLOBALS.SetLunaTemp(aAnLucru, aLunaLucru);

  vCodInventar := aCodInventar;
  SELECT coalesce(Gestiune,0), Tip,           DataInventar,  1,         Coalesce(ITipCont, 0), Coalesce(IClase,0), Coalesce(IClaseS, 0), Coalesce(IProd, 0),
         coalesce(rezdif,0), coalesce(marja,0)
  INTO   vCodGest, vTipRezolvare, vDataInventar, vToateArt, vToateCont,            vToateClasele,      vToateClaseleS,       vToateProd,
         vRezDif, vMarja
  FROM Inventar
  WHERE CodInventar = aCodInventar;

  DELETE FROM TMP_MANEVRA_LISTE;

  IF vToateCont = 1 THEN
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODIOART&apos;, CODIOART FROM IOART;
  ELSE
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODIOART&apos;, CODTIPCONT
    FROM INVENTCONT IC INNER JOIN IOART1 IO1 ON io1.codioart = ic.codtipcont AND io1.mg &lt;&gt; 5 AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
    WHERE CODINVENTAR = aCodInventar;
  END IF;

  IF vToateClasele = 1 THEN
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODCLASEA&apos;, CODCLASEA FROM NCLASEA;
  ELSE
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) 
    WITH /*RECURSIVE*/ tmp (CODCLASEA) AS (
      SELECT codclasea FROM INVENTCLASE WHERE codinventar = aCodInventar
      UNION ALL 
      SELECT c.codclasea FROM NCLASEA C INNER JOIN tmp ON c.codparinte = tmp.codclasea
    )
    SELECT &apos;CODCLASEA&apos;, CODCLASEA FROM tmp;
  END IF;

  IF vToateClaseleS = 1 THEN
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODCLASEAS&apos;, CODCLASEAS FROM NCLASEAS;
  ELSE
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) 
    WITH /*RECURSIVE*/ tmp (CODCLASEAS) AS (
      SELECT codclaseas FROM INVENTCLASES WHERE codinventar = aCodInventar
      UNION ALL 
      SELECT c.codclaseas FROM NCLASEAS C INNER JOIN tmp ON c.codparinte = tmp.CODCLASEAS
    )
    SELECT &apos;CODCLASEAS&apos;, CODCLASEAS FROM tmp;
  END IF;

  IF vToateProd = 1 THEN
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODPART&apos;, CODPART FROM NPART;
  ELSE
    INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) SELECT &apos;CODPART&apos;, CODPART FROM INVENTPROD WHERE CODINVENTAR = aCodInventar;
  END IF;

  IF aLunaLucru = 1 
  THEN aLunaPrec := 12;             aAnPrec := aAnLucru - 1;
  ELSE aLunaPrec := aLunaLucru - 1; aAnPrec := aAnLucru;
  END IF;
  PKG_GLOBALS.SetLunaPRECEDENTA(aAnPrec, aLunaPrec);
  --corectie necesara pentru producatori
  UPDATE nartobj o SET codproducator = NULL WHERE codproducator IS NOT NULL AND NOT EXISTS (SELECT 1 FROM npart    p WHERE o.codproducator = p.codpart);
  UPDATE nart    a SET clasa         = NULL WHERE clasa         IS NOT NULL AND NOT EXISTS (SELECT 1 FROM nclasea  c WHERE c.codclasea     = a.clasa);
  UPDATE nart    a SET clasastatist  = NULL WHERE clasastatist  IS NOT NULL AND NOT EXISTS (SELECT 1 FROM nclaseas c WHERE c.codclaseas    = a.clasastatist);
  COMMIT;
END;

FUNCTION GetCodInventar (aCodIes in number, CuLock in number ) RETURN NUMBER IS
aCod number(20);
c1 number;
c2 number;
aRezDif number;
BEGIN
  if aCodIes = 0 then Return 0; end if;
  begin
    Select CodInventar, coalesce(rezdif,0) into aCod, aRezDif from inventar where Marire = aCodIes or Diminuare = aCodIes;
    Exception when others then aCod := 0;
  end;
  
  if (aCod &gt; 0) and (aRezDif = 0) then
    select count(*) into c1 from inventar1 where codinventar = aCod;
    select count(*) into c2 from (select distinct codobiect, CODSERIE, EXPIRARE, um1, CodLocatie from inventar1 where codinventar = aCod);
    if C1 &lt;&gt; C2 then Return -2; end if;
  end if;
  Return aCod;
END;

function UpdateInventarFromDoc(aCodInventar in number, aCodDoc in number) return number IS
aRezDif number(1);  
BEGIN
  begin
    select coalesce(rezdif,0) into arezdif from inventar where codinventar = acodinventar;
  exception when others then aRezDif := 0;
  end;
  if aCodInventar &gt; 0 and arezdif = 0 then
    Return UpdateInventRez(aCodInventar, aCodDoc);
  else
    Return 0;
  end if;
END;

FUNCTION isToateArt RETURN NUMBER IS
BEGIN
  RETURN vToateArt;
END;

FUNCTION isToateClasele RETURN NUMBER IS
BEGIN
  RETURN vToateClasele;
END;

FUNCTION isToateClaseleS RETURN NUMBER IS
BEGIN
  RETURN vToateClaseleS;
END;

FUNCTION isToateProd RETURN NUMBER IS
BEGIN
  RETURN vToateProd;
END;

FUNCTION isToateConturile RETURN NUMBER IS
BEGIN
  RETURN vToateCont;
END;

FUNCTION GETCODGEST RETURN NUMBER IS
BEGIN
  RETURN vCodGest;
END;

FUNCTION GETCODINVENTAR RETURN NUMBER IS
BEGIN
  RETURN vCodInventar;
END;

FUNCTION GETDATAINVENTAR RETURN DATE IS
BEGIN
  RETURN vDataInventar;
END;

function UpdateInventRez(aCodInventar in number, aCodDoc in number, DoCommit in number default 0) return number is
aCodInventar1 number(20);
aCount number(20);
aScriptic number(20,7);
aFaptic number(20,7);
c number;
begin
  C := TestCoerenta(aCodInventar);
  if C &lt;&gt; 0 then Return C; end if;

 if PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
   for v_rec in (select * from inventar where (codinventar = aCodInventar)and(Nvl(Diminuare, 0) = aCodDoc or Nvl(Marire, 0) = aCodDoc)) loop
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ump.codum1 umsec,ns.codlocatie,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc nirstocorig, ne.codnirser nirserorig,
                         istoc.codinventstoc, ns.tipserie
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join num1 ump on ump.codum = num1.codum and ump.secundara = 0
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Diminuare and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 1 then
        select codinventar1 into acodinventar1
        from inventar1
        where codinventar = v_Rec.Codinventar
              and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
              AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
              AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
              and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
        if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          delete inventrez where codinventar1 = acodinventar1 and codnirstoc = v_tmp.codnirstoc and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
        end if;
      end if;
    end loop;
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ump.codum1 umsec,ns.codlocatie,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc nirstocorig, ne.codnirser nirserorig,
                         istoc.codinventstoc, ns.tipserie
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join num1 ump on ump.codum = num1.codum and ump.secundara = 0
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Marire and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 1 then
        select codinventar1 into acodinventar1
        from inventar1
        where codinventar = v_Rec.Codinventar
              and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
              AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
              AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
              and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
              and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
        --if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          delete inventrez where codinventar1 = acodinventar1 and codnirstoc = v_tmp.codnirstoc and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
        --end if;
      end if;
    end loop;
  end loop;

  for v_rec in (select irez.codrezolvare
                from inventrez irez
                     inner join inventar1 i1 on i1.codinventar1 = irez.codinventar1
                     inner join tmp_livr1_initial lini on lini.codnirstoc = irez.codnirstoc and nvl(irez.codnirser,0) = nvl(lini.codnirser,0)
                     --inner join livr l on lini.codlivr = l.codlivr and l.codies = aCodDoc
                     left join livr1 l1 on lini.codlivr1 = l1.codlivr1
                where i1.codinventar = aCodInventar
                      and nvl(l1.codlivr1,0) = 0 ) loop
    delete inventrez where codrezolvare = v_rec.codrezolvare;
  end loop;

  for v_rec in (select irez.codrezolvare
                from inventrez irez
                     inner join inventar1 i1 on i1.codinventar1 = irez.codinventar1
                     inner join tmp_livr1_initial lini on
                       nvl(lini.codobiect,0) = nvl(i1.CodObiect,0) AND nvl(lini.CODSERIE,0) = nvl(i1.CodSerie,0)
                       AND nvl(i1.EXPIRARE, pkg_globals.Data0) = nvl(lini.TG, pkg_globals.Data0)
                       and nvl(lini.umsec,0) = nvl(i1.um1,0)and nvl(lini.CodLocatie,0) = nvl(i1.CodLocatie,0)
                     left join livr1 l1 on lini.codlivr1 = l1.codlivr1
                where i1.codinventar = aCodInventar
                      and nvl(l1.codlivr1,0) = 0 and i1.scriptic = 0) loop
    delete inventrez where codrezolvare = v_rec.codrezolvare;
  end loop;

  for v_rec in (select * from inventar where (codinventar = aCodInventar)and(Nvl(Diminuare, 0) = aCodDoc or Nvl(Marire, 0) = aCodDoc)) loop
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ump.codum1 umsec, l1.cant, l1.cantum1, l1.cantum2, ump.paritate,
                         ns.codioart, ns.furn, ns.tva, ns.pret, ns.adaos, ns.CodLocatie, nvl(ns.pret,0)-nvl(ns.adaos,0) pretachiz,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc codnirstocorig, ne.codnirser codnirserorig,
                         istoc.codinventstoc, ns.tipserie,
                         ns.d1, ns.d2, ns.d3
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join num1 ump on ump.codum = num1.codum and ump.secundara = 0
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Diminuare and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 0 then
        aCount := 1;
        SELECT SEQ_inventar1_codinventar1.NEXTVAL INTO aCodInventar1 FROM DUAL;
        INSERT INTO  INVENTAR1 ( CodInventar1,
                                 CodInventar,
                                 CodLocatie,
                                 CodObiect,
                                 CodSerie,
                                 Scriptic,
                                 Faptic,
                                 ScripticUM1,
                                 FapticUM1,
                                 ScripticUM2,
                                 FapticUM2,
                                 Expirare,
                                 Rezolvat,
                                 Ordine,
                                 UM1,
                                 Blocat,
                                 Valoare,
                                 TipSerie )
                        values ( aCodInventar1,
                                 aCodinventar,
                                 v_tmp.CodLocatie,
                                 v_tmp.CodObiect,
                                 v_tmp.CodSerie,
                                 0,
                                 -v_tmp.cant,
                                 0,
                                 -v_tmp.cantUM1,
                                 0,
                                 -v_tmp.cantUM2,
                                 v_tmp.TG,
                                 1,
                                 (Select 1 + Max(Ordine) from Inventar1 where CodInventar = aCodInventar),
                                 v_tmp.UMSec,
                                 0,
                                 v_tmp.cant*v_tmp.Pret,
                                 v_tmp.tipserie);
      end if;

      if aCount = 1 then
        if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          select codinventar1 into acodinventar1
          from inventar1
          where codinventar = v_Rec.Codinventar
                and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
                AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
                AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
                and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

          select count(*) into aCount from inventrez
          where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          if aCount = 0 then
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat, rezolvatum1, rezolvatum2, pretachiz, pretinreg, codioart
                                  ,codpart, codnirser, tva, tg, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, aCodInventar1, v_tmp.codnirstoc, -v_tmp.cant, -v_tmp.cantum1, -v_tmp.cantum2,
                    ROUND((v_tmp.PRET - NVL(v_tmp.ADAOS, 0)) * nvl(v_tmp.paritate,2), 7), v_tmp.pret * nvl(v_tmp.paritate,2),v_tmp.codioart, v_tmp.furn,
                    v_tmp.codnirser, v_tmp.tva, v_tmp.tg, v_tmp.d1, v_tmp.d2, v_tmp.d3);
          else if aCount = 1 then
            update inventrez set
              rezolvat = rezolvat - v_tmp.cant,
              rezolvatum1 = rezolvatum1 - v_tmp.cantum1,
              rezolvatum2 = rezolvatum2 - v_tmp.cantum2
            where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          end if;
          end if;
        end if;
      end if;
    end loop;
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ump.codum1 umsec, l1.cant, l1.cantum1, l1.cantum2, ump.paritate,
                         ns.codioart, ns.furn, ns.tva, ns.pret, ns.adaos, ns.CodLocatie, nvl(ns.pret,0)-nvl(ns.adaos,0) pretachiz,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc codnirstocorig, ne.codnirser codnirserorig,
                         istoc.codinventstoc, ns.tipserie,
                         ns.d1, ns.d2, ns.d3
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join num1 ump on ump.codum = num1.codum and ump.secundara = 0
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Marire and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 0 then
        aCount := 1;
        SELECT SEQ_inventar1_codinventar1.NEXTVAL INTO aCodInventar1 FROM DUAL;
        INSERT INTO  INVENTAR1 ( CodInventar1,
                                 CodInventar,
                                 CodLocatie,
                                 CodObiect,
                                 CodSerie,
                                 Scriptic,
                                 Faptic,
                                 ScripticUM1,
                                 FapticUM1,
                                 ScripticUM2,
                                 FapticUM2,
                                 Expirare,
                                 Rezolvat,
                                 Ordine,
                                 UM1,
                                 Blocat,
                                 Valoare,
                                 TipSerie )
                        values ( aCodInventar1,
                                 aCodinventar,
                                 v_tmp.CodLocatie,
                                 v_tmp.CodObiect,
                                 v_tmp.CodSerie,
                                 0,
                                 v_tmp.cant,
                                 0,
                                 v_tmp.cantUM1,
                                 0,
                                 v_tmp.cantUM2,
                                 v_tmp.TG,
                                 1,
                                 (Select 1 + Max(Ordine) from Inventar1 where CodInventar = aCodInventar),
                                 v_tmp.UMSec,
                                 0,
                                 v_tmp.cant*v_tmp.Pret,
                                 v_tmp.tipserie);
      end if;

      if aCount = 1 then
        --if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          select codinventar1 into acodinventar1
          from inventar1
          where codinventar = v_Rec.Codinventar
                and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
                AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
                AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
                and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
                and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
          select count(*) into aCount from inventrez
          where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          if aCount = 0 then
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat, rezolvatum1, rezolvatum2, pretachiz, pretinreg, codioart
                                  ,codpart, codnirser, tva, tg, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, aCodInventar1, v_tmp.codnirstoc, v_tmp.cant, v_tmp.cantum1, v_tmp.cantum2,
                    ROUND((v_tmp.PRET - NVL(v_tmp.ADAOS, 0)) * nvl(v_tmp.paritate,2), 7), round(v_tmp.pret * nvl(v_tmp.paritate,2),7),v_tmp.codioart, v_tmp.furn,
                    v_tmp.codnirser, v_tmp.tva, v_tmp.tg, round(v_tmp.d1,7), round(v_tmp.d2,7), round(v_tmp.d3,7));
          else if aCount = 1 then
            update inventrez set
              rezolvat = rezolvat - v_tmp.cant,
              rezolvatum1 = rezolvatum1 - v_tmp.cantum1,
              rezolvatum2 = rezolvatum2 - v_tmp.cantum2
            where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          end if;
          end if;
        --end if;
      end if;
    end loop;
  end loop;
  for v_rec in ( select i1.CodInventar1, Sum(nvl(iz.Rezolvat,0)) Rezolvat,  Sum(nvl(iz.RezolvatUM1,0)) RezolvatUM1, Sum(nvl(iz.RezolvatUM2,0)) RezolvatUM2
                 from Inventar1 i1
                      left join InventRez iz on I1.CodInventar1 = iz.CodInventar1
                 where i1.CodInventar = aCodInventar
                 Group by i1.CodInventar1)
  loop
    Update Inventar1
    set
      Faptic    = Scriptic + Nvl(v_rec.Rezolvat, 0),
      FapticUM1 = ScripticUM1 + Nvl(v_rec.RezolvatUM1,0),
      FapticUM2 = ScripticUM2 + Nvl(v_rec.RezolvatUM2,0),
      Rezolvat  = 1
    where CodInventar1 = v_rec.CodInventar1;

    Update Inventar1
    set
      Rezolvat = 0,
      Blocat   = 0
    where CodInventar1  = v_rec.CodInventar1
          and Faptic    = Scriptic
          and nvl(FapticUM1,0) = nvl(ScripticUM1,0)
          and nvl(FapticUM2,0) = nvl(ScripticUM2,0);

    for v_tmp in (select codinventar1, scriptic, nvl(blocat,0) blocat
                  from inventar1
                  where codinventar1 = v_rec.codinventar1 and round(faptic,7) = round(scriptic,7)) loop
      if v_tmp.blocat = 0 then
        delete rezervats where codinventar1 = v_tmp.codinventar1;
      end if;
      if v_tmp.scriptic = 0 then
        delete inventrez where codinventar1 = v_tmp.codinventar1;
        delete inventar1 where codinventar1 = v_tmp.codinventar1;
      end if;
    end loop;
  end loop;
 else

  for v_rec in (select * from inventar where (codinventar = aCodInventar)and(Nvl(Diminuare, 0) = aCodDoc or Nvl(Marire, 0) = aCodDoc)) loop
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ns.umsec,ns.codlocatie,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc nirstocorig, ne.codnirser nirserorig,
                         istoc.codinventstoc, ns.tipserie
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Diminuare and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 1 then
        select codinventar1 into acodinventar1
        from inventar1
        where codinventar = v_Rec.Codinventar
              and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
              AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
              AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
              and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
        if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          delete inventrez where codinventar1 = acodinventar1 and codnirstoc = v_tmp.codnirstoc and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
        end if;
      end if;
    end loop;
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ns.umsec,ns.codlocatie,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc nirstocorig, ne.codnirser nirserorig,
                         istoc.codinventstoc, ns.tipserie
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Marire and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 1 then
        select codinventar1 into acodinventar1
        from inventar1
        where codinventar = v_Rec.Codinventar
              and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
              AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
              AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
              and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
              and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
        --if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          delete inventrez where codinventar1 = acodinventar1 and codnirstoc = v_tmp.codnirstoc and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
        --end if;
      end if;
    end loop;
  end loop;

  for v_rec in (select irez.codrezolvare
                from inventrez irez
                     inner join inventar1 i1 on i1.codinventar1 = irez.codinventar1
                     inner join tmp_livr1_initial lini on lini.codnirstoc = irez.codnirstoc and nvl(irez.codnirser,0) = nvl(lini.codnirser,0)
                     --inner join livr l on lini.codlivr = l.codlivr and l.codies = aCodDoc
                     left join livr1 l1 on lini.codlivr1 = l1.codlivr1
                where i1.codinventar = aCodInventar
                      and nvl(l1.codlivr1,0) = 0 ) loop
    delete inventrez where codrezolvare = v_rec.codrezolvare;
  end loop;

  for v_rec in (select irez.codrezolvare
                from inventrez irez
                     inner join inventar1 i1 on i1.codinventar1 = irez.codinventar1
                     inner join tmp_livr1_initial lini on
                       nvl(lini.codobiect,0) = nvl(i1.CodObiect,0) AND nvl(lini.CODSERIE,0) = nvl(i1.CodSerie,0)
                       AND nvl(i1.EXPIRARE, pkg_globals.Data0) = nvl(lini.TG, pkg_globals.Data0)
                       and nvl(lini.umsec,0) = nvl(i1.um1,0)and nvl(lini.CodLocatie,0) = nvl(i1.CodLocatie,0)
                     left join livr1 l1 on lini.codlivr1 = l1.codlivr1
                where i1.codinventar = aCodInventar
                      and nvl(l1.codlivr1,0) = 0 and i1.scriptic = 0) loop
    delete inventrez where codrezolvare = v_rec.codrezolvare;
  end loop;

  for v_rec in (select * from inventar where (codinventar = aCodInventar)and(Nvl(Diminuare, 0) = aCodDoc or Nvl(Marire, 0) = aCodDoc)) loop
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ns.umsec, l1.cant/decode(nvl(num1.paritate,0),0,1,nvl(num1.paritate,0)) cant, l1.cantum1, l1.cantum2, num1.paritate,
                         ns.codioart, ns.furn, ns.tva, ns.pret, ns.adaos, ns.CodLocatie, nvl(ns.pret,0)-nvl(ns.adaos,0) pretachiz,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc codnirstocorig, ne.codnirser codnirserorig,
                         istoc.codinventstoc, ns.tipserie,
                         ns.d1, ns.d2, ns.d3
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Diminuare and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 0 then
        aCount := 1;
        SELECT SEQ_inventar1_codinventar1.NEXTVAL INTO aCodInventar1 FROM DUAL;
        INSERT INTO  INVENTAR1 ( CodInventar1,
                                 CodInventar,
                                 CodLocatie,
                                 CodObiect,
                                 CodSerie,
                                 Scriptic,
                                 Faptic,
                                 ScripticUM1,
                                 FapticUM1,
                                 ScripticUM2,
                                 FapticUM2,
                                 Expirare,
                                 Rezolvat,
                                 Ordine,
                                 UM1,
                                 Blocat,
                                 Valoare,
                                 TipSerie )
                        values ( aCodInventar1,
                                 aCodinventar,
                                 v_tmp.CodLocatie,
                                 v_tmp.CodObiect,
                                 v_tmp.CodSerie,
                                 0,
                                 -v_tmp.cant,
                                 0,
                                 -v_tmp.cantUM1,
                                 0,
                                 -v_tmp.cantUM2,
                                 v_tmp.TG,
                                 1,
                                 (Select 1 + Max(Ordine) from Inventar1 where CodInventar = aCodInventar),
                                 v_tmp.UMSec,
                                 0,
                                 v_tmp.cant*v_tmp.Pret,
                                 v_tmp.tipserie);
      end if;

      if aCount = 1 then
        if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          select codinventar1 into acodinventar1
          from inventar1
          where codinventar = v_Rec.Codinventar
                and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
                AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
                AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
                and nvl(um1,0) = nvl(v_tmp.umsec,0) and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

          select count(*) into aCount from inventrez
          where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          if aCount = 0 then
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat, rezolvatum1, rezolvatum2, pretachiz, pretinreg, codioart
                                  ,codpart, codnirser, tva, tg, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, aCodInventar1, v_tmp.codnirstoc, -v_tmp.cant, -v_tmp.cantum1, -v_tmp.cantum2,
                    ROUND((v_tmp.PRET - NVL(v_tmp.ADAOS, 0)) * nvl(v_tmp.paritate,2), 7), v_tmp.pret * nvl(v_tmp.paritate,2),v_tmp.codioart, v_tmp.furn,
                    v_tmp.codnirser, v_tmp.tva, v_tmp.tg, v_tmp.d1, v_tmp.d2, v_tmp.d3);
          else if aCount = 1 then
            update inventrez set
              rezolvat = rezolvat - v_tmp.cant,
              rezolvatum1 = rezolvatum1 - v_tmp.cantum1,
              rezolvatum2 = rezolvatum2 - v_tmp.cantum2
            where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          end if;
          end if;
        end if;
      end if;
    end loop;
    for v_tmp in (select ns.codobiect, ne.codserie, nvl(ne.tg,ns.tg) tg, ns.umsec, l1.cant/decode(nvl(num1.paritate,0),0,1,nvl(num1.paritate,0)) cant, l1.cantum1, l1.cantum2, num1.paritate,
                         ns.codioart, ns.furn, ns.tva, ns.pret, ns.adaos, ns.CodLocatie, nvl(ns.pret,0)-nvl(ns.adaos,0) pretachiz,
                         case when nir.codies = i.codies then 0 else ns.codnirstoc end codnirstoc,
                         case when nir.codies = i.codies then 0 else ne.codnirser end codnirser,
                         ns.codnirstoc codnirstocorig, ne.codnirser codnirserorig,
                         istoc.codinventstoc, ns.tipserie,
                         ns.d1, ns.d2, ns.d3
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join iesiri i on l.codies = i.codies
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join num1 on ns.umsec = num1.codum1
                       inner join inventcont icont on ns.codioart = icont.codtipcont
                       left join  nirser ne on l1.codnirser = ne.codnirser
                       left join inventstoc istoc on istoc.codinventar = acodinventar and nvl(istoc.codnirstoc,0) = nvl(ns.codnirstoc,0)
                                                     and nvl(istoc.codnirser,0) = nvl(ne.codnirser,0)
                  where l.codies = aCodDoc and l.codies = v_rec.Marire and nir.gest = v_Rec.Gestiune and icont.codinventar = acodinventar) loop

      select count(*) into aCount from inventar1
      where codinventar = v_Rec.Codinventar
            and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0) AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
            AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
            and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
            and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);

      if aCount = 0 then
        aCount := 1;
        SELECT SEQ_inventar1_codinventar1.NEXTVAL INTO aCodInventar1 FROM DUAL;
        INSERT INTO  INVENTAR1 ( CodInventar1,
                                 CodInventar,
                                 CodLocatie,
                                 CodObiect,
                                 CodSerie,
                                 Scriptic,
                                 Faptic,
                                 ScripticUM1,
                                 FapticUM1,
                                 ScripticUM2,
                                 FapticUM2,
                                 Expirare,
                                 Rezolvat,
                                 Ordine,
                                 UM1,
                                 Blocat,
                                 Valoare,
                                 TipSerie )
                        values ( aCodInventar1,
                                 aCodinventar,
                                 v_tmp.CodLocatie,
                                 v_tmp.CodObiect,
                                 v_tmp.CodSerie,
                                 0,
                                 v_tmp.cant,
                                 0,
                                 v_tmp.cantUM1,
                                 0,
                                 v_tmp.cantUM2,
                                 v_tmp.TG,
                                 1,
                                 (Select 1 + Max(Ordine) from Inventar1 where CodInventar = aCodInventar),
                                 v_tmp.UMSec,
                                 0,
                                 v_tmp.cant*v_tmp.Pret,
                                 v_tmp.tipserie);
      end if;

      if aCount = 1 then
        --if (v_tmp.codnirstoc = 0 and v_tmp.codnirser = 0) or (v_tmp.codinventstoc &gt; 0) then
          select codinventar1 into acodinventar1
          from inventar1
          where codinventar = v_Rec.Codinventar
                and nvl(codobiect,0) = nvl(v_tmp.CodObiect,0)
                AND nvl(CODSERIE,0) = nvl(v_tmp.CodSerie,0)
                AND nvl(EXPIRARE, pkg_globals.Data0) = nvl(v_tmp.TG, pkg_globals.Data0)
                and nvl(um1,0) = nvl(v_tmp.umsec,0)and nvl(CodLocatie,0) = nvl(v_tmp.CodLocatie,0)
                and nvl(tipserie,0) = nvl(v_tmp.tipserie,0);
          select count(*) into aCount from inventrez
          where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          if aCount = 0 then
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat, rezolvatum1, rezolvatum2, pretachiz, pretinreg, codioart
                                  ,codpart, codnirser, tva, tg, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, aCodInventar1, v_tmp.codnirstoc, v_tmp.cant, v_tmp.cantum1, v_tmp.cantum2,
                    ROUND((v_tmp.PRET - NVL(v_tmp.ADAOS, 0)) * nvl(v_tmp.paritate,2), 7), round(v_tmp.pret * nvl(v_tmp.paritate,2),7),v_tmp.codioart, v_tmp.furn,
                    v_tmp.codnirser, v_tmp.tva, v_tmp.tg, round(v_tmp.d1,7), round(v_tmp.d2,7), round(v_tmp.d3,7));
          else if aCount = 1 then
            update inventrez set
              rezolvat = rezolvat - v_tmp.cant,
              rezolvatum1 = rezolvatum1 - v_tmp.cantum1,
              rezolvatum2 = rezolvatum2 - v_tmp.cantum2
            where codinventar1 = acodinventar1 and nvl(codnirstoc,0) = nvl(v_tmp.codnirstoc,0) and nvl(codnirser,0) = nvl(v_tmp.codnirser,0);
          end if;
          end if;
        --end if;
      end if;
    end loop;
  end loop;
  for v_rec in ( select i1.CodInventar1, Sum(nvl(iz.Rezolvat,0)) Rezolvat,  Sum(nvl(iz.RezolvatUM1,0)) RezolvatUM1, Sum(nvl(iz.RezolvatUM2,0)) RezolvatUM2
                 from Inventar1 i1
                      left join InventRez iz on I1.CodInventar1 = iz.CodInventar1
                 where i1.CodInventar = aCodInventar
                 Group by i1.CodInventar1)
  loop
    Update Inventar1
    set
      Faptic    = Scriptic + Nvl(v_rec.Rezolvat, 0),
      FapticUM1 = ScripticUM1 + Nvl(v_rec.RezolvatUM1,0),
      FapticUM2 = ScripticUM2 + Nvl(v_rec.RezolvatUM2,0),
      Rezolvat  = 1
    where CodInventar1 = v_rec.CodInventar1;

    Update Inventar1
    set
      Rezolvat = 0,
      Blocat   = 0
    where CodInventar1  = v_rec.CodInventar1
          and Faptic    = Scriptic
          and nvl(FapticUM1,0) = nvl(ScripticUM1,0)
          and nvl(FapticUM2,0) = nvl(ScripticUM2,0);

    for v_tmp in (select codinventar1, scriptic, nvl(blocat,0) blocat
                  from inventar1
                  where codinventar1 = v_rec.codinventar1 and round(faptic,7) = round(scriptic,7)) loop
      if v_tmp.blocat = 0 then
        delete rezervats where codinventar1 = v_tmp.codinventar1;
      end if;
      if v_tmp.scriptic = 0 then
        delete inventrez where codinventar1 = v_tmp.codinventar1;
        delete inventar1 where codinventar1 = v_tmp.codinventar1;
      end if;
    end loop;
  end loop;

  end if;
  if NVL(DoCommit,0) = 1 then
    commit;
  end if;
  Return 0;
end;

procedure RecalculRezervari(aCodInventar in number) is
begin
  delete rezervats where codinventar1 in (select codinventar1 from inventar1 where codinventar = acodinventar);
  for v_rec in (select i1.codinventar1, i1.um1, rez.rezolvat, rez.codnirstoc, rez.codnirser
                from inventar1 i1
                     inner join inventrez rez on rez.codinventar1 = i1.codinventar1
                where i1.codinventar = acodinventar and i1.faptic &lt; i1.scriptic and rez.rezolvat &lt; 0) loop
    insert into rezervats(codrezervats, codnirstoc, codnirser, rest, umsec, rezervatini, codinventar1)
    values (seq_rezervats_codrezervats.nextval, v_rec.codnirstoc, v_rec.codnirser, -v_rec.rezolvat, 1, -v_rec.rezolvat, v_rec.codinventar1);
  end loop;
end;

procedure StergeLiniiGoale(aCodInventar in number) is
begin
  for v_rec in (select codinventar1
                from inventar1
                where codinventar = acodinventar and scriptic = 0) loop
    delete rezervats where codinventar1 = v_rec.codinventar1;
    delete inventrez where codinventar1 = v_rec.codinventar1;
    delete inventar1 where codinventar1 = v_rec.codinventar1;
  end loop;
end;

PROCEDURE SetCodInventar1(aCodInventar in number) IS
  vData0        DATE := pkg_globals.data0;
  aCodInventar1 number(20);
BEGIN
  aCodInventar1 :=0;

  IF PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 THEN
    FOR v_rec in (
      SELECT
        IStoc.CodInventStoc,
        coalesce(NE.Tg, NS.TG, vData0) Expirare, Coalesce(NE.codserie,0) codserie,
        Coalesce(ump.codum1,0) umsec, Coalesce(NS.Codobiect,0) codobiect, NS.CodLocatie, ns.tipserie
      FROM InventStoc IStoc
        INNER JOIN nirstoc ns  ON ns.codnirstoc = IStoc.codnirstoc
        INNER JOIN nartobj o   ON o.codobiect   = ns.codobiect
        INNER JOIN nart    a   ON a.codarticol  = o.codarticol
        INNER JOIN num1    ump ON ump.codum     = a.um AND Coalesce(ump.secundara,0) = 0
        LEFT  JOIN nirser  ne  ON ne.codnirser  = IStoc.codnirser
      WHERE IStoc.CodInventar = aCodInventar
    ) LOOP
      BEGIN
        SELECT CodInventar1 INTO aCodinventar1
        FROM Inventar1
        WHERE CodInventar = aCodInventar
          AND Coalesce(Expirare, vData0) = Coalesce(v_rec.expirare, vData0)
          AND Coalesce(codserie,0) = Coalesce(v_rec.codserie,0)
          AND Coalesce(um1,0) = Coalesce(v_Rec.UmSec,0)
          AND Coalesce(codobiect,0) = Coalesce(v_rec.codobiect,0)
          AND Coalesce(codLocatie,0) = Coalesce(v_rec.codLocatie,0)
          AND coalesce(tipserie,0) = coalesce(v_rec.tipserie,0);
      EXCEPTION
        WHEN OTHERS THEN aCodInventar1 := 0;
      END;
      IF aCodinventar1 &gt; 0
      THEN UPDATE inventstoc SET codinventar1 = aCodinventar1 WHERE CodInventStoc = v_rec.Codinventstoc;
      ELSE DELETE FROM inventstoc                             WHERE CodInventStoc = v_rec.Codinventstoc;
      END IF;
    END LOOP;
  ELSE
    FOR v_rec IN (
      SELECT
        IStoc.CodInventStoc, coalesce(NE.Tg, NS.TG, vData0) Expirare, Coalesce(NE.codserie,0) codserie, Coalesce(NS.umsec,0) umsec,
        Coalesce(NS.Codobiect,0) codobiect, NS.CodLocatie, ns.tipserie
      FROM InventStoc IStoc
        INNER JOIN nirstoc ns ON ns.codnirstoc = IStoc.codnirstoc
        LEFT  JOIN nirser  ne ON ne.codnirser  = IStoc.codnirser
      WHERE IStoc.CodInventar = aCodInventar
    ) LOOP
      BEGIN
        SELECT CodInventar1 INTO aCodinventar1
        FROM Inventar1
        WHERE CodInventar = aCodInventar
          AND Coalesce(Expirare, vData0) = Coalesce(v_rec.expirare, vData0)
          AND Coalesce(codserie,0) = Coalesce(v_rec.codserie,0)
          AND Coalesce(um1,0) = Coalesce(v_Rec.UmSec,0)
          AND Coalesce(codobiect,0) = Coalesce(v_rec.codobiect,0)
          AND Coalesce(codLocatie,0) = Coalesce(v_rec.codLocatie,0)
          AND coalesce(tipserie,0) = coalesce(v_Rec.tipserie,0);
      EXCEPTION
        WHEN OTHERS THEN aCodInventar1 := 0;
      END;
      IF aCodinventar1 &gt; 0
      THEN UPDATE inventstoc SET codinventar1 = aCodinventar1 WHERE CodInventStoc = v_rec.Codinventstoc;
      ELSE DELETE FROM inventstoc                             WHERE CodInventStoc = v_rec.Codinventstoc;
      END IF;
    END LOOP;
  END IF;
END;

function TestCoerenta(aCodInventar in number) return number is
c1 number;
c2 number;
begin
  update inventar1 set CodLocatie = 0 where codinventar = acodinventar and CodLocatie = -1;
  delete from inventar1  where codinventar = aCodInventar
                         and   nvl(scriptic,0)=0 and nvl(Faptic,0)=0
                         and   nvl(scripticUM1,0)=0 and nvl(FapticUM1,0)=0
                         and   nvl(scripticUM2,0)=0 and nvl(FapticUM2,0)=0;

  select count(*) into c1 from inventar1 where codinventar = aCodInventar;
  select count(*) into c2 from (select distinct codobiect, CODSERIE, EXPIRARE, um1, CodLocatie from inventar1 where codinventar = aCodInventar);
  Return C1 - C2;
end;

function UpdateInventStoc(aCodInventar in number) return number is
c number;
begin
  C := TestCoerenta(aCodInventar);
  if C &lt;&gt; 0 then Return C; end if;
  GetInventStoc(aCodInventar);
  SetCodInventar1(aCodInventar);
  return 0;
  Commit;
end;

procedure GetInventStoc(aCodInventar in number) is
  vALInitiala   NUMBER(5);
  vALLucru      NUMBER(5) := PKG_GLOBALS.ANLUNALUCRU;
begin
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  SetParams(aCodInventar);
  SELECT ANINITIAL*12+LUNAINITIALA INTO vALInitiala FROM FIRMALUNI;
  
  DELETE FROM inventstoc i WHERE EXISTS (SELECT CodInventar1 FROM inventar1 WHERE CodInventar1 = i.Codinventar1 AND CodInventar = aCodInventar);

  IF vRezDif &gt; 0 then
    IF PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) &lt;&gt; &apos;1&apos; THEN
      INSERT INTO inventstoc ( codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      SELECT seq_inventstoc_codinventstoc.nextval, seq_inventar1_codinventar1.nextval, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
      FROM (
        SELECT
          ns.codnirstoc, ne.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.rest ELSE ne.rest END / Coalesce(NULLIF(num1.paritate,0),1) rest,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum1 ELSE ne.restum1 END restum1,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum2 ELSE ne.restum2 END restum2
        FROM nirstoc         ns
          INNER JOIN nir     n    ON ns.codnir      = n.codnir
          INNER JOIN num1    num1 ON ns.umsec       = num1.codum1
          INNER JOIN nartobj obj  ON obj.codobiect  = ns.codobiect
          INNER JOIN nart    art  ON obj.codarticol = art.codarticol
          INNER JOIN ioart1  io1  ON io1.codioart   = ns.codioart   AND io1.mg &lt;&gt; 5      AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          LEFT  JOIN nirser  ne   ON ns.codnirstoc  = ne.codnirstoc AND ns.tipserie &gt; 0
        WHERE (ns.rest &lt;&gt; 0 OR ns.restum1 &lt;&gt; 0 OR ns.restum2 &lt;&gt; 0) and ns.rest &lt; vMarja
          AND (n.gest = vCodGest or vCodGest = 0)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODIOART&apos;   AND tmp.valoare = ns.codioart)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODPART&apos;    AND tmp.valoare = COALESCE (obj.codproducator, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEA&apos;  AND tmp.valoare = COALESCE (Art.clasa, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEAS&apos; AND tmp.valoare = COALESCE (Art.clasastatist, 0))
      );  
    else
      INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      SELECT seq_inventstoc_codinventstoc.nextval, seq_inventar1_codinventar1.nextval, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
      FROM (
        SELECT
          ns.codnirstoc, ne.codnirser, ns.pret,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.rest    ELSE ne.rest    END rest,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum1 ELSE ne.restum1 END restum1,
          CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum2 ELSE ne.restum2 END restum2
        FROM nirstoc         ns
          INNER JOIN nir     n    ON ns.codnir      = n.codnir
          INNER JOIN nartobj obj  ON obj.codobiect  = ns.codobiect
          INNER JOIN nart    art  ON obj.codarticol = art.codarticol
          INNER JOIN ioart1  io1  ON io1.codioart   = ns.codioart   AND io1.mg &lt;&gt; 5      AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          LEFT  JOIN nirser  ne   ON ns.codnirstoc  = ne.codnirstoc AND ns.tipserie &gt; 0
        WHERE (ns.rest &lt;&gt; 0 OR ns.restum1 &lt;&gt; 0 OR ns.restum2 &lt;&gt; 0) and ns.rest &lt; vMarja 
          AND (n.gest = vCodGest or vCodGest = 0)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODIOART&apos;   AND tmp.valoare = ns.codioart)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODPART&apos;    AND tmp.valoare = COALESCE (obj.codproducator, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEA&apos;  AND tmp.valoare = COALESCE (Art.clasa, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEAS&apos; AND tmp.valoare = COALESCE (Art.clasastatist, 0))
      );
    end if;  
  else 
  IF PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) &lt;&gt; &apos;1&apos; THEN
    IF vTipRezolvare = 0 THEN
      INSERT INTO inventstoc ( codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
      FROM (
        SELECT
          ns.codnirstoc, ne.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.rest ELSE ne.rest END / Coalesce(NULLIF(num1.paritate,0),1)) rest,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum1 ELSE ne.restum1 END) restum1,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum2 ELSE ne.restum2 END) restum2
        FROM nirstoc         ns
          INNER JOIN nir     n    ON ns.codnir      = n.codnir
          INNER JOIN num1    num1 ON ns.umsec       = num1.codum1
          INNER JOIN nartobj obj  ON obj.codobiect  = ns.codobiect
          INNER JOIN nart    art  ON obj.codarticol = art.codarticol
          INNER JOIN ioart1  io1  ON io1.codioart   = ns.codioart   AND io1.mg &lt;&gt; 5      AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          LEFT  JOIN nirser  ne   ON ns.codnirstoc  = ne.codnirstoc AND ns.tipserie &gt; 0
        WHERE (ns.rest &lt;&gt; 0 OR ns.restum1 &lt;&gt; 0 OR ns.restum2 &lt;&gt; 0) 
          AND n.gest = vCodGest
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODIOART&apos;   AND tmp.valoare = ns.codioart)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODPART&apos;    AND tmp.valoare = COALESCE (obj.codproducator, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEA&apos;  AND tmp.valoare = COALESCE (Art.clasa, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEAS&apos; AND tmp.valoare = COALESCE (Art.clasastatist, 0))
        GROUP BY ns.codnirstoc, ne.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
      );
    END IF;
    IF vTipRezolvare = 1 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest/Coalesce(NULLIF(num1.paritate,0),1)) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai1 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest) rest, Sum(v.restum1/Coalesce(NULLIF(num1.paritate,0),1)) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar1 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      END IF;
    END IF;
    IF vTipRezolvare = 2 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest/Coalesce(NULLIF(num1.paritate,0),1)) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai2 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest/Coalesce(NULLIF(num1.paritate,0),1)) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar2 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      END IF;
    END IF;
    IF vTipRezolvare = 3 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest/Coalesce(NULLIF(num1.paritate,0),1)) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai3 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret * Coalesce(NULLIF(num1.paritate,0),1) pret, Sum(v.rest/Coalesce(NULLIF(num1.paritate,0),1)) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar3 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN num1 ON ns.umsec = num1.codum1
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret, Coalesce(NULLIF(num1.paritate,0),1)
        );
      END IF;
    END IF;
  ELSE
    IF vTipRezolvare = 0 THEN
      INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
      FROM (
        SELECT
          ns.codnirstoc, ne.codnirser, ns.pret,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.rest    ELSE ne.rest    END) rest,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum1 ELSE ne.restum1 END) restum1,
          Sum(CASE WHEN Coalesce(ne.codnirser,0) = 0 THEN ns.restum2 ELSE ne.restum2 END) restum2
        FROM nirstoc         ns
          INNER JOIN nir     n    ON ns.codnir      = n.codnir
          INNER JOIN nartobj obj  ON obj.codobiect  = ns.codobiect
          INNER JOIN nart    art  ON obj.codarticol = art.codarticol
          INNER JOIN ioart1  io1  ON io1.codioart   = ns.codioart   AND io1.mg &lt;&gt; 5      AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          LEFT  JOIN nirser  ne   ON ns.codnirstoc  = ne.codnirstoc AND ns.tipserie &gt; 0
        WHERE (ns.rest &lt;&gt; 0 OR ns.restum1 &lt;&gt; 0 OR ns.restum2 &lt;&gt; 0) 
          AND n.gest = vCodGest
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODIOART&apos;   AND tmp.valoare = ns.codioart)
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODPART&apos;    AND tmp.valoare = COALESCE (obj.codproducator, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEA&apos;  AND tmp.valoare = COALESCE (Art.clasa, 0))
          AND EXISTS (SELECT 1 FROM tmp_manevra_liste tmp WHERE tmp.filtru = &apos;CODCLASEAS&apos; AND tmp.valoare = COALESCE (Art.clasastatist, 0))
        GROUP BY ns.codnirstoc, ne.codnirser, ns.pret
      );
    END IF;
    IF vTipRezolvare = 1 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai1 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar1 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      END IF;
    END IF;
    IF vTipRezolvare = 2 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai2 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar2 v
              INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
              INNER JOIN IOART IO ON ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
                AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      END IF;
    END IF;
    IF vTipRezolvare = 3 THEN
      IF vALLucru = vALInitiala THEN
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar_lunai3 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      ELSE
        INSERT INTO inventstoc (codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        SELECT seq_inventstoc_codinventstoc.nextval, 0, aCodinventar, codnirstoc, codnirser, pret, rest, restum1, restum2
        FROM (
          SELECT v.codnirstoc, v.codnirser, ns.pret, Sum(v.rest) rest, Sum(v.restum1) restum1, Sum(v.restum2) restum2
          FROM v_stoc_inventar3 v
            INNER JOIN nirstoc ns ON v.CODNIRSTOC = ns.codnirstoc
            INNER JOIN IOART IO ON ns.codioart = io.codioart
            INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND vALLucru BETWEEN IO1.ALStart AND IO1.ALStop
          WHERE (v.rest &lt;&gt; 0 OR v.restum1 &lt;&gt; 0 OR v.restum2 &lt;&gt; 0)
            AND io1.mg &lt;&gt; 5
          GROUP BY v.codnirstoc, v.codnirser, ns.pret
        );
      END IF;
    END IF;
  END IF;
  end if;

  DELETE inventstoc WHERE CodInventar = aCodInventar AND Coalesce(Rest,0) = 0 AND Coalesce(RestUM1,0) = 0 AND Coalesce(RestUM2,0) = 0;
  commit;
END;

PROCEDURE SETTIPREZOLVARE( aCodInventar IN NUMBER, aTipRezolvare IN NUMBER) IS
BEGIN
  UPDATE INVENTAR
  SET TipRezolvare = aTipRezolvare
  WHERE CODINVENTAR = aCodInventar;

  COMMIT;
END;

FUNCTION GET_DATACURENTA_SERVER RETURN VARCHAR2 IS
Data varchar2(10);
BEGIN
  SELECT TO_CHAR(SYSDATE, &apos;DD.MM.YYYY&apos;) INTO Data FROM DUAL;
  RETURN Data;
END;

PROCEDURE GENERARE_INVENTAR(aCodInventar in number) IS
  vData0 DATE := pkg_globals.data0;
BEGIN
  PKG_SERVICE.SETZERORECORDS;
  GetInventStoc(aCodInventar);

  if vRezDif &gt; 0 then
    if PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
      INSERT INTO INVENTAR1 (
        CodInventar1,
        CODINVENTAR, CODLOCATIE, CODOBIECT, CODSERIE, SCRIPTIC, SCRIPTICUM1, SCRIPTICUM2, EXPIRARE, REZOLVAT, VALOARE,
        ORDINE,
        UM1, BLOCAT, TipSerie)
      SELECT
        Stoc.codinventar1,
        aCodInventar, Stoc.CodLocatie, stoc.CodObiect, stoc.CodSerie, stoc.rest, stoc.restUM1, stoc.restUM2, stoc.tg, 0 AS REZOLVAT, Stoc.Valoare,
        ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE) AS ORDINE,
        Stoc.UmSec, 1 AS BLOCAT, stoc.Tipserie
      FROM (
        SELECT
          ISToc.CodInventar1,IStoc.rest * NS.Pret AS Valoare, IStoc.rest AS rest, IStoc.restum1 AS restum1, IStoc.restum2 AS restum2, Coalesce(NS.CodLocatie, 0) AS CodLocatie, NS.codobiect,
          CASE WHEN Coalesce(ne.tg, ns.tg, vData0) = vData0 THEN null ELSE Coalesce(ne.tg, ns.tg, vData0) END AS TG,
          Coalesce(ne.codserie,0) AS codserie, ump.codum1 AS umsec, Coalesce(ns.tipserie,0) AS tipserie
        FROM inventstoc IStoc
          inner join nirstoc ns on ns.codnirstoc = IStoc.codnirstoc
          inner join nartobj o on o.codobiect = ns.codobiect
          inner join nart a on a.codarticol = o.codarticol
          inner join num1 ump on ump.codum = a.um and nvl(ump.secundara,0) = 0
          left join nirser ne on ne.codnirser = IStoc.codnirser AND NS.TIPSERIE &gt; 0
        WHERE codinventar = aCodinventar
      ) stoc
        INNER JOIN nartobj ob  ON stoc.codobiect = ob.codobiect
        INNER JOIN nart    art ON ob.codarticol  = art.codarticol
      WHERE art.tiparticol IN (&apos;0&apos;,&apos;2&apos;);
    ELSE
      INSERT INTO INVENTAR1 (
        CodInventar1,
        CODINVENTAR, CODLOCATIE, CODOBIECT, CODSERIE, SCRIPTIC, SCRIPTICUM1, SCRIPTICUM2, EXPIRARE, REZOLVAT, VALOARE,
        ORDINE,
        UM1, BLOCAT, TipSerie)
      SELECT
        Stoc.codinventar1,
        aCodInventar, Stoc.CodLocatie, stoc.CodObiect, stoc.CodSerie, stoc.rest, stoc.restUM1, stoc.restUM2, stoc.tg, 0 AS REZOLVAT, Stoc.Valoare,
        ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE) AS ORDINE,
        Stoc.UmSec, 1 AS BLOCAT, stoc.Tipserie
      FROM (
        SELECT
          ISToc.CodInventar1,IStoc.rest * NS.Pret AS  Valoare, IStoc.rest AS rest, IStoc.restum1 AS restum1, IStoc.restum2 AS restum2, Coalesce(NS.CodLocatie, 0) AS CodLocatie, NS.codobiect,
          CASE WHEN Coalesce(ne.tg, ns.tg, vData0) = vData0 THEN NULL ELSE Coalesce(ne.tg, ns.tg, vData0) END AS tg,
          Coalesce(ne.codserie,0) AS codserie, ns.umsec, Coalesce(ns.tipserie,0) AS tipserie
        FROM inventstoc IStoc
          INNER JOIN nirstoc ns ON ns.codnirstoc = IStoc.codnirstoc
          LEFT  JOIN nirser  ne ON ne.codnirser  = IStoc.codnirser
        WHERE codinventar = aCodinventar
      ) stoc
        INNER JOIN nartobj ob  ON stoc.codobiect = ob.codobiect
        INNER JOIN nart    art ON ob.codarticol = art.codarticol
      WHERE art.tiparticol in (&apos;0&apos;,&apos;2&apos;);
    END IF;
  else
    if PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
      INSERT INTO INVENTAR1 (
        CodInventar1,
        CODINVENTAR, CODLOCATIE, CODOBIECT, CODSERIE, SCRIPTIC, SCRIPTICUM1, SCRIPTICUM2, EXPIRARE, REZOLVAT, VALOARE,
        ORDINE,
        UM1, BLOCAT, TipSerie)
      SELECT
        SEQ_inventar1_codinventar1.NEXTVAL,
        aCodInventar, Stoc.CodLocatie, stoc.CodObiect, stoc.CodSerie, stoc.rest, stoc.restUM1, stoc.restUM2, stoc.tg, 0 AS REZOLVAT, Stoc.Valoare,
        ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE) AS ORDINE,
        Stoc.UmSec, 1 AS BLOCAT, stoc.Tipserie
      FROM (
        SELECT
          SUM(IStoc.rest * NS.Pret) AS Valoare, SUM(IStoc.rest) AS rest, SUM(IStoc.restum1) AS restum1, SUM(IStoc.restum2) AS restum2, Coalesce(NS.CodLocatie, 0) AS CodLocatie, NS.codobiect,
          CASE WHEN Coalesce(ne.tg, ns.tg, vData0) = vData0 THEN null ELSE Coalesce(ne.tg, ns.tg, vData0) END AS TG,
          Coalesce(ne.codserie,0) AS codserie, ump.codum1 AS umsec, Coalesce(ns.tipserie,0) AS tipserie
        FROM inventstoc IStoc
          inner join nirstoc ns on ns.codnirstoc = IStoc.codnirstoc
          inner join nartobj o on o.codobiect = ns.codobiect
          inner join nart a on a.codarticol = o.codarticol
          inner join num1 ump on ump.codum = a.um and nvl(ump.secundara,0) = 0
          left join nirser ne on ne.codnirser = IStoc.codnirser AND NS.TIPSERIE &gt; 0
        WHERE codinventar = aCodinventar
        GROUP BY NS.codobiect, Coalesce(ne.tg, ns.tg, vData0), Coalesce(ne.codserie,0), ump.codum1, Coalesce(NS.CodLocatie, 0), Coalesce(ns.tipserie,0)
      ) stoc
        INNER JOIN nartobj ob  ON stoc.codobiect = ob.codobiect
        INNER JOIN nart    art ON ob.codarticol  = art.codarticol
      WHERE art.tiparticol IN (&apos;0&apos;,&apos;2&apos;);
    ELSE
      INSERT INTO INVENTAR1 (
        CodInventar1,
        CODINVENTAR, CODLOCATIE, CODOBIECT, CODSERIE, SCRIPTIC, SCRIPTICUM1, SCRIPTICUM2, EXPIRARE, REZOLVAT, VALOARE,
        ORDINE,
        UM1, BLOCAT, TipSerie)
      SELECT
        SEQ_inventar1_codinventar1.NEXTVAL,
        aCodInventar, Stoc.CodLocatie, stoc.CodObiect, stoc.CodSerie, stoc.rest, stoc.restUM1, stoc.restUM2, stoc.tg, 0 AS REZOLVAT, Stoc.Valoare,
        ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE) AS ORDINE,
        Stoc.UmSec, 1 AS BLOCAT, stoc.Tipserie
      FROM (
        SELECT
          SUM(IStoc.rest * NS.Pret) AS  Valoare, SUM(IStoc.rest) AS rest, SUM(IStoc.restum1) AS restum1, SUM(IStoc.restum2) AS restum2, Coalesce(NS.CodLocatie, 0) AS CodLocatie, NS.codobiect,
          CASE WHEN Coalesce(ne.tg, ns.tg, vData0) = vData0 THEN NULL ELSE Coalesce(ne.tg, ns.tg, vData0) END AS tg,
          Coalesce(ne.codserie,0) AS codserie, ns.umsec, Coalesce(ns.tipserie,0) AS tipserie
        FROM inventstoc IStoc
          INNER JOIN nirstoc ns ON ns.codnirstoc = IStoc.codnirstoc
          LEFT  JOIN nirser  ne ON ne.codnirser  = IStoc.codnirser
        WHERE codinventar = aCodinventar
        GROUP BY NS.codobiect, Coalesce(ne.tg, ns.tg, vData0), Coalesce(ne.codserie,0),ns.umsec, Coalesce(NS.CodLocatie, 0), Coalesce(ns.tipserie,0)
      ) stoc
        INNER JOIN nartobj ob  ON stoc.codobiect = ob.codobiect
        INNER JOIN nart    art ON ob.codarticol = art.codarticol
      WHERE art.tiparticol in (&apos;0&apos;,&apos;2&apos;);
    END IF;
    SetCodInventar1(aCodInventar);
  end if;  

  INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, REZERVATINI, UMSEC, CODINVENTAR1)
  SELECT SEQ_REZERVATS_CODREZERVATS.NEXTVAL, -1, I.CodNIRStoc, I.CodNIRSer, I.Rest, I.Rest, NS.UMSEC, I.CodInventar1
  FROM INVENTSTOC I INNER JOIN NirStoc NS ON NS.Codnirstoc = I.CodNirStoc
  WHERE I.codinventar = aCodInventar;

  COMMIT;
END;

PROCEDURE PreiaDateNoi(aCodInventar in number) IS
aCodInventar1 number(20);
aBlocat number(1);
aFaptic number(20,7);
aFapticUM1 number(20,7);
aFapticUM2 number(20,7);
aRezolvat number(1);
aTipSerie number(2);
begin
  for v_rec in (select * from inventar1_clona) loop
    begin
      select codinventar1, blocat, faptic, fapticum1, fapticum2, rezolvat, tipserie
      into aCodInventar1, aBlocat, aFaptic, aFapticUM1, aFapticUM2, aRezolvat, aTipSerie
      from inventar1
      where CodInventar = aCodInventar
            and nvl(Expirare, pkg_globals.DATA0) = nvl(v_rec.expirare, pkg_globals.DATA0)
            and nvl(codserie,0) = nvl(v_rec.codserie,0)
            and nvl(um1,0) = nvl(v_Rec.Um1,0)
            and nvl(codobiect,0) = nvl(v_rec.codobiect,0)
            and nvl(codLocatie,0) = nvl(v_rec.codLocatie,0)
            and tipserie = v_Rec.Tipserie;
    exception when others then
      select seq_inventar1_codinventar1.nextval into aCodInventar1 from dual;
      aBlocat := 0;
      aFaptic := v_Rec.Scriptic;
      aFapticUM1 := v_Rec.Scripticum1;
      aFapticUM2 := v_Rec.Scripticum2;
      aRezolvat   := 0;
    end;
    update inventar1_clona
    set codinventar1 = aCodInventar1,
        blocat       = aBlocat,
        Faptic       = aFaptic,
        FapticUM1    = aFapticUM1,
        FapticUM2    = aFapticUM2,
        Rezolvat     = aRezolvat
    where CodInventar = aCodInventar
            and nvl(Expirare, pkg_globals.DATA0) = nvl(v_rec.expirare, pkg_globals.DATA0)
            and nvl(codserie,0) = nvl(v_rec.codserie,0)
            and nvl(um1,0) = nvl(v_Rec.Um1,0)
            and nvl(codobiect,0) = nvl(v_rec.codobiect,0)
            and nvl(codLocatie,0) = nvl(v_rec.codLocatie,0)
            and tipserie = v_rec.tipserie;
  end loop;

  delete inventstoc where codinventar = aCodInventar;
  delete inventar1  where codinventar = aCodInventar;
  insert into inventar1 select * from inventar1_clona;
  insert into inventstoc select * from inventstoc_clona;
end;

PROCEDURE RezolvaBlocaje(aCodInventar in number) IS
aCodInventar1 number(20);
aBlocat number(1);
aCantRez number(20,7);
aCantRezUM1 number(20,7);
aCantRezUM2 number(20,7);
begin
  for v_rec in (select * from inventar1 where codinventar = aCodInventar) loop
    if v_rec.blocat = 1 then
      delete rezervats where codinventar1 = v_rec.codinventar1;
      insert into rezervats(CODREZERVATS, CODNIRSTOC, CODNIRSER, REST,
                            REZERVATINI, UMSEC, CODINVENTAR1)
      select seq_rezervats_codrezervats.nextval, iss.codnirstoc, iss.codnirser, iss.rest - nvl(alterez.cant,0),
             iss.rest - nvl(alterez.cant,0), v_rec.um1, v_rec.codinventar1
      from inventstoc iss
           left join (SELECT NVL(SUM(R.REST),0) CANT, R.Codnirstoc, r.codnirser
                      FROM REZERVATS R
                      WHERE NVL(R.CODNIRSTOC, 0) &gt; 0 AND NVL(R.CODCOMANDA1,0) &gt; 0
                      group by r.codnirstoc, r.codnirser) alterez on nvl(alterez.codnirser,0) = nvl(iss.codnirser,0)
                                                                     and alterez.codnirstoc = iss.codnirstoc
      where iss.codinventar1 = v_rec.codinventar1;
    end if;
    if v_rec.rezolvat = 1 then
      begin
        select sum(nvl(rezolvat,0)), sum(nvl(rezolvatum1,0)), sum(nvl(rezolvatum2,0)) into aCantRez, aCantRezUM1, aCantRezUM2
        from inventrez
        where codinventar1 = v_rec.codinventar1;
      exception when others then
        aCantRez := 0;
        aCantRezUM1 := 0;
        aCantRezUM2 := 0;
      end;
      if nvl(v_rec.faptic,0) - nvl(v_rec.scriptic,0) &lt;&gt; aCantRez or
         nvl(v_rec.fapticUM1,0) - nvl(v_rec.scripticUM1,0) &lt;&gt; aCantRezUM1 or
         nvl(v_rec.fapticUM2,0) - nvl(v_rec.scripticUM2,0) &lt;&gt; aCantRezUM2 then
        update inventar1 set
          rezolvat = 0, blocat = 1
        where codinventar1 = v_rec.codinventar1;
        delete rezervats where codinventar1 = v_rec.codinventar1;
        delete inventrez where codinventar1 = v_rec.codinventar1;
        insert into rezervats(CODREZERVATS, CODNIRSTOC, CODNIRSER, REST,
                              REZERVATINI, UMSEC, CODINVENTAR1)
        select seq_rezervats_codrezervats.nextval, iss.codnirstoc, iss.codnirser, iss.rest - nvl(alterez.cant,0),
               iss.rest - nvl(alterez.cant,0), v_rec.um1, v_rec.codinventar1
        from inventstoc iss
             left join (SELECT NVL(SUM(R.REST),0) CANT, R.Codnirstoc, r.codnirser
                        FROM REZERVATS R
                        WHERE NVL(R.CODNIRSTOC, 0) &gt; 0 AND NVL(R.CODCOMANDA1,0) &gt; 0
                        group by r.codnirstoc, r.codnirser) alterez on nvl(alterez.codnirser,0) = nvl(iss.codnirser,0)
                                                                       and alterez.codnirstoc = iss.codnirstoc
        where iss.codinventar1 = v_rec.codinventar1;
      end if;
    end if;
  end loop;
end;

PROCEDURE RE_GENERARE_INVENTAR(aCodInventar in number) IS
BEGIN
  delete inventstoc_clona;
  delete inventar1_clona;
  GetInventStocTemp(aCodInventar);

  if PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    INSERT INTO INVENTAR1_CLONA( CodInventar1,
                                 CODINVENTAR ,
                                 CODLOCATIE  ,
                                 CODOBIECT   ,
                                 CODSERIE    ,
                                 SCRIPTIC    ,
                                 SCRIPTICUM1 ,
                                 SCRIPTICUM2 ,
                                 EXPIRARE    ,
                                 REZOLVAT    ,
                                 VALOARE     ,
                                 ORDINE      ,
                                 UM1         ,
                                 TipSerie)
                        select SEQ_inventar1_codinventar1.NEXTVAL,
                               aCodInventar,
                               Stoc.CodLocatie,
                               stoc.CodObiect,
                               stoc.CodSerie,
                               stoc.rest,
                               stoc.restUM1,
                               stoc.restUM2,
                               stoc.tg,
                               0,
                               Stoc.Valoare,
                               ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE),
                               Stoc.UmSec,
                               nvl(stoc.TipSerie,0) tipserie
                        from  (
                                select
                                  sum(IStoc.rest * NS.Pret) Valoare,
                                  sum(IStoc.rest) rest,
                                  sum(IStoc.restum1) restum1,
                                  sum(IStoc.restum2) restum2,
                                  NVL(NS.CodLocatie, 0) CodLocatie,
                                  NS.codobiect,
                                  case when NVL(nvl(ne.tg, ns.tg), pkg_globals.data0) = pkg_globals.data0 then null else NVL(nvl(ne.tg, ns.tg), pkg_globals.data0) end tg,
                                  nvl(ne.codserie,0) codserie,
                                  ump.codum1 umsec,
                                  nvl(ns.tipserie,0) tipserie
                                from inventstoc_clona IStoc
                                     inner join nirstoc ns on ns.codnirstoc = IStoc.codnirstoc
                                     inner join nartobj o on o.codobiect = ns.codobiect
                                     inner join nart a on a.codarticol = o.codarticol
                                     inner join num1 ump on ump.codum = a.um and nvl(ump.secundara,0) = 0
                                     left join nirser ne on ne.codnirser = IStoc.codnirser
                                where IStoc.codinventar = aCodinventar
                                group by NS.codobiect, NVL(nvl(ne.tg, ns.tg), pkg_globals.data0), nvl(ne.codserie,0),ump.codum1, NVL(NS.CodLocatie, 0), nvl(ns.tipserie,0)
                              ) stoc
                              inner join nartobj ob on stoc.codobiect = ob.codobiect
                              inner join nart art on ob.codarticol = art.codarticol
                              where art.tiparticol in (0,2);
  else
    INSERT INTO INVENTAR1_CLONA( CodInventar1,
                                 CODINVENTAR ,
                                 CODLOCATIE  ,
                                 CODOBIECT   ,
                                 CODSERIE    ,
                                 SCRIPTIC    ,
                                 SCRIPTICUM1 ,
                                 SCRIPTICUM2 ,
                                 EXPIRARE    ,
                                 REZOLVAT    ,
                                 VALOARE     ,
                                 ORDINE      ,
                                 UM1         ,
                                 TipSerie)
                        select SEQ_inventar1_codinventar1.NEXTVAL,
                               aCodInventar,
                               Stoc.CodLocatie,
                               stoc.CodObiect,
                               stoc.CodSerie,
                               stoc.rest,
                               stoc.restUM1,
                               stoc.restUM2,
                               stoc.tg,
                               0,
                               Stoc.Valoare,
                               ROW_NUMBER() OVER(ORDER BY OB.DENUMIRE),
                               Stoc.UmSec,
                               nvl(stoc.TipSerie,0) tipserie
                        from  (
                                select
                                  sum(IStoc.rest * NS.Pret) Valoare,
                                  sum(IStoc.rest) rest,
                                  sum(IStoc.restum1) restum1,
                                  sum(IStoc.restum2) restum2,
                                  NVL(NS.CodLocatie, 0) CodLocatie,
                                  NS.codobiect,
                                  case when NVL(nvl(ne.tg, ns.tg), pkg_globals.data0) = pkg_globals.data0 then null else NVL(nvl(ne.tg, ns.tg), pkg_globals.data0) end tg,
                                  nvl(ne.codserie,0) codserie,
                                  ns.umsec,
                                  nvl(ns.tipserie,0) tipserie
                                from inventstoc_clona IStoc
                                     inner join nirstoc ns on ns.codnirstoc = IStoc.codnirstoc
                                     left join nirser ne on ne.codnirser = IStoc.codnirser
                                where IStoc.codinventar = aCodinventar
                                group by NS.codobiect, NVL(nvl(ne.tg, ns.tg), pkg_globals.data0), nvl(ne.codserie,0),ns.umsec, NVL(NS.CodLocatie, 0), nvl(ns.tipserie,0)
                              ) stoc
                              inner join nartobj ob on stoc.codobiect = ob.codobiect
                              inner join nart art on ob.codarticol = art.codarticol
                              where art.tiparticol in (0,2);
  end if;
  PreiaDateNoi(aCodInventar);
  SetCodInventar1(aCodInventar);
  RezolvaBlocaje(aCodInventar);
  delete rezervats r
  where r.CodInventar1 &gt; 0 and not exists (select i1.codinventar1 from inventar1 i1 where i1.codinventar1 = r.codinventar1);
  Commit;
END;

procedure GetInventStocTemp(aCodInventar in number) is
aAnInitial number(4);
aLunaInitiala number(2);
begin
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  SetParams(aCodInventar);

  SELECT ANINITIAL, LUNAINITIALA INTO aANINITIAL, aLUNAINITIALA FROM FIRMALUNI;

  if PKG_CATEGCONST.GetValConstanta(&apos;UMInventar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    if vTipRezolvare = 0 then
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         pret,
         rest,
         restum1,
         restum2
       from (
      select
        ns.codnirstoc,
        ne.codnirser,
        ns.pret pret,
        sum(case when nvl(ne.codnirser,0) = 0 then ns.rest else ne.rest end) rest,
        sum(case when nvl(ne.codnirser,0) = 0 then ns.restum1 else ne.restum1 end) restum1,
        sum(case when nvl(ne.codnirser,0) = 0 then ns.restum2 else ne.restum2 end) restum2
      from nirstoc ns
          inner join nartobj obj on obj.codobiect = ns.codobiect
          inner join nart art on obj.codarticol = art.codarticol
          inner join nir n on ns.codnir = n.codnir
          inner join IOART IO on ns.codioart = io.codioart
          inner join tmp_manevra_liste ic on io.codioart = ic.valoare and ic.filtru = &apos;CODIOART&apos;
          inner join tmp_manevra_liste ip on nvl(obj.codproducator,0) = ip.valoare and ip.filtru = &apos;CODPART&apos;
          INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          left  join nirser ne on ns.codnirstoc = ne.codnirstoc and ns.tipserie &gt; 0
      where (ns.rest &lt;&gt; 0 or ns.restum1 &lt;&gt; 0 or ns.restum2 &lt;&gt; 0) and io1.mg &lt;&gt; 5 and n.gest = vCodGest
      and exists (select cl.valoare from tmp_manevra_liste cl where PKG_GLOBALS.IS_SUBCLAS_OF(nvl(Art.clasa,0), to_number(cl.valoare)) = 1 and cl.filtru = &apos;CODCLASEA&apos;)
      and exists (select cls.valoare from tmp_manevra_liste cls where PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(Art.clasastatist,0), to_number(cls.valoare)) = 1 and cls.filtru = &apos;CODCLASEAS&apos;)
      group by ns.codnirstoc, ne.codnirser, ns.pret
      );
    end if;
    if vTipRezolvare = 1 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai1 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar1 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      end if;
    end if;
    if vTipRezolvare = 2 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai2 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar2 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      end if;
    end if;
    if vTipRezolvare = 3 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai3 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret pret,
            sum(v.rest) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar3 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret
          );
      end if;
    end if;
  else
    if vTipRezolvare = 0 then
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         pret,
         rest,
         restum1,
         restum2
       from (
      select
        ns.codnirstoc,
        ne.codnirser,
        ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
        sum(round(case when nvl(ne.codnirser,0) = 0 then ns.rest else ne.rest end / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
        sum(case when nvl(ne.codnirser,0) = 0 then ns.restum1 else ne.restum1 end) restum1,
        sum(case when nvl(ne.codnirser,0) = 0 then ns.restum2 else ne.restum2 end) restum2
      from nirstoc ns
          inner join nartobj obj on obj.codobiect = ns.codobiect
          inner join nart art on obj.codarticol = art.codarticol
          inner join nir n on ns.codnir = n.codnir
          inner join IOART IO on ns.codioart = io.codioart
          inner join tmp_manevra_liste ic on io.codioart = ic.valoare and ic.filtru = &apos;CODIOART&apos;
          inner join tmp_manevra_liste ip on nvl(obj.codproducator,0) = ip.valoare and ip.filtru = &apos;CODPART&apos;
          INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          inner join num1 on ns.umsec = num1.codum1
          left  join nirser ne on ns.codnirstoc = ne.codnirstoc and ns.tipserie &gt; 0
      where (ns.rest &lt;&gt; 0 or ns.restum1 &lt;&gt; 0 or ns.restum2 &lt;&gt; 0) and io1.mg &lt;&gt; 5 and n.gest = vCodGest
      and exists (select cl.valoare from tmp_manevra_liste cl where PKG_GLOBALS.IS_SUBCLAS_OF(nvl(Art.clasa,0), to_number(cl.valoare)) = 1 and cl.filtru = &apos;CODCLASEA&apos;)
      and exists (select cls.valoare from tmp_manevra_liste cls where PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(Art.clasastatist,0), to_number(cls.valoare)) = 1 and cls.filtru = &apos;CODCLASEAS&apos;)
      group by ns.codnirstoc, ne.codnirser, ns.pret, num1.paritate
      );
    end if;

    if vTipRezolvare = 1 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai1 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar1 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      end if;
    end if;

    if vTipRezolvare = 2 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai2 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar2 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      end if;
    end if;

    if vTipRezolvare = 3 then
      if PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU = aAnInitial*12+aLUNAINITIALA then
        insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
        select
           seq_inventstoc_codinventstoc.nextval,
           0,
           aCodinventar,
           codnirstoc,
           codnirser,
           Pret,
           rest,
           restum1,
           restum2
         from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar_lunai3 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      else
      insert into inventstoc_clona(codinventstoc, codinventar1, codinventar, codnirstoc, codnirser, Pret, rest, restum1, restum2)
      select
         seq_inventstoc_codinventstoc.nextval,
         0,
         aCodinventar,
         codnirstoc,
         codnirser,
         Pret,
         rest,
         restum1,
         restum2
       from (
          select
            v.codnirstoc,
            v.codnirser,
            ns.pret * decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)) pret,
            sum(round(v.rest / decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),7)) rest,
            sum(v.restum1) restum1,
            sum(v.restum2) restum2
          from v_stoc_inventar3 v
              inner join nirstoc ns on v.CODNIRSTOC = ns.codnirstoc
              inner join num1 on ns.umsec = num1.codum1
              inner join IOART IO on ns.codioart = io.codioart
              INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALStart AND IO1.ALStop
          where (v.rest &lt;&gt; 0 or v.restum1 &lt;&gt; 0 or v.restum2 &lt;&gt; 0)
                and io1.mg &lt;&gt; 5
          group by v.codnirstoc, v.codnirser, ns.pret, num1.paritate
          );
      end if;
    end if;
  end if;

  delete inventstoc_clona where CodInventar = aCodInventar and Nvl(Rest,0) = 0 and Nvl(RestUM1,0) = 0 and Nvl(RestUM2,0) = 0;
  commit;
end;

PROCEDURE SetCodInventar1Temp(aCodInventar in number) IS
aCodInventar1 number(20);
begin
  aCodInventar1 :=0;
  for v_rec in (
          Select IStoc.CodInventStoc, coalesce(NE.Tg, NS.TG,pkg_globals.data0) Expirare, NE.codserie, NS.umsec, NS.Codobiect, NS.CodLocatie
          from InventStoc_clona IStoc
               inner join nirstoc ns on ns.codnirstoc = IStoc.codnirstoc
               left join nirser ne on ne.codnirser = IStoc.codnirser
          where IStoc.CodInventar = aCodInventar)
  loop
    begin
      Select CodInventar1 into aCodinventar1 from Inventar1_clona
      where CodInventar = aCodInventar
            and nvl(Expirare, pkg_globals.DATA0) = nvl(v_rec.expirare, pkg_globals.DATA0)
            and nvl(codserie,0) = nvl(v_rec.codserie,0)
            and nvl(um1,0) = nvl(v_Rec.UmSec,0)
            and nvl(codobiect,0) = nvl(v_rec.codobiect,0)
            and nvl(codLocatie,0) = nvl(v_rec.codLocatie,0);
      exception when others then aCodInventar1 := 0;
    end;
    if aCodinventar1 &gt; 0
    then
      update inventstoc_clona set codinventar1 = aCodinventar1 where CodInventStoc = v_rec.Codinventstoc;
    else
      delete inventstoc_clona where CodInventStoc = v_rec.Codinventstoc;
    end if;
  end loop;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodInventar INTO Tmp FROM INVENTAR WHERE CodInventar = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aCodSubunit NUMBER(20);
  aDataDoc DATE;
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  SELECT
    SUBUNITATE,
    DATAINVENTAR,
    NRINVENTAR||&apos;/&apos;DATAINVENTAR
  INTO
    aCodSubunit,
    aDataDoc,
    ADOC
  FROM
    INVENTAR
  WHERE
    CODINVENTAR = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INVENTAR&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;


  DELETE FROM INVENTCONT WHERE CodInventar = RecId;
  DELETE FROM INVENTPROD WHERE CodInventar = RecId;
  DELETE FROM INVENTCLASE WHERE CodInventar = RecId;
  DELETE FROM INVENTCLASES WHERE CodInventar = RecId;
  DELETE FROM INVENTSTOC WHERE CodInventar = RecId;
  DELETE FROM INVENTREZ R WHERE EXISTS (SELECT I1.CodInventar1 FROM INVENTAR1 I1 WHERE I1.CodInventar = RecID AND R.CODINVENTAR1 = I1.CodInventar1);
  DELETE FROM REZERVATS R WHERE EXISTS (SELECT I1.CodInventar1 FROM INVENTAR1 I1 WHERE I1.CodInventar = RecID AND R.CODINVENTAR1 = I1.CodInventar1);
  DELETE FROM INVENTAR1  WHERE CodInventar = RecId;
  DELETE FROM INVENTAR   WHERE CodInventar = RecId;

  NotifyModif(2, RecId, &apos;INVENTAR&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_INVENTAR FIELDS( CodInventar, TipRezolvare, Blocat ) VALUES (0, 1, 0) ;
  -- introduc si tipurile contabile
  /*INSERT INTO  TMP_INVENTCONT ( CodInventCont,
                                CodInventar,
                                CodTipCont,
                                Selectat,
                                Den_TipCont )
                       ( select -1,
                                0,
                                IO.CodIOArt,
                                0,
                                IO.Den_IOArt
                        FROM IOART IO ) ;
   */
  COMMIT;
END;

function ExistaInLivrareDocRez(vCodNirStoc in number, vMarire in number, vDiminuare in number) return number is
aCount number(10);
begin
  select count(*) into aCount
  from iesiri i
       inner join livr l on l.codies = i.codies
       inner join iesiri1 i1 on i.codies = i1.codies
       inner join livr1 l1 on l1.codlivr = l.codlivr and l1.codies1 = i1.codies1 and l1.codnirstoc = vcodnirstoc
  where i.codies = vMarire or i.codies = vDiminuare;
  return aCount;
end;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
TIPPREFIX VARCHAR2(20);
aCodSubunit number(20);
vAll number(1);
aVal number(20,7);
aValRez number(20,7);
aValTot number(20,7);
aValDim number(20,7);
aValMar number(20,7);
vMarire number(20);
vDiminuare number(20);
BEGIN
  select nvl(marire,0), nvl(diminuare,0) into vMarire, vDiminuare from inventar where codinventar = recid;
    INSERT INTO  TMP_INVENTAR ( CodInventar,
                                NrInventar,
                                DataInventar,
                                Gestiune,
                                Responsabil,
                                Observatii,
                                Tip,
                                Diminuare,
                                Marire,
                                Facturare,
                                IArt,
                                ITipCont,
                                IClase,
                                IProd,
                                IClaseS,
                                Subunitate,
                                TipRezolvare,
                                flgPalm,
                                Blocat,
                                DocDiminuare,
                                DocMarire,
                                RezDif,
                                Marja )
                       ( select IV.CodInventar,
                                IV.NrInventar,
                                IV.DataInventar,
                                IV.Gestiune,
                                IV.Responsabil,
                                IV.Observatii,
                                IV.Tip,
                                nvl(dim.codies,0),
                                nvl(Mar.CodIes,0),
                                IV.Facturare,
                                IV.IArt,
                                IV.ITipCont,
                                IV.IClase,
                                nvl(IV.IProd,1),
                                nvl(IV.IClaseS,1),
                                IV.Subunitate,
                                IV.TipRezolvare,
                                IV.flgPalm,
                                IV.Blocat,
                                case when nvl(iv.diminuare, 0) = 0 then null else cdim.serie||dim.nrdoc||&apos;/&apos;||dim.datadoc end,
                                case when nvl(iv.marire, 0) = 0 then null else cmar.serie||mar.nrdoc||&apos;/&apos;||mar.datadoc end,
                                IV.RezDif,
                                IV.Marja  
                         FROM INVENTAR IV
                              left join iesiri dim on dim.codies = IV.DIMINUARE
                              left join doccarnete cdim on dim.carnetdoc = cdim.codcarnet
                              left join iesiri mar on mar.codies = iv.marire
                              left join doccarnete cmar on mar.carnetdoc = cmar.codcarnet
                         WHERE CodInventar = RecId ) ;

   begin
     select subunitate into aCodSubunit from tmp_inventar;
   exception when others then aCodSubunit := pkg_globals.GETSUBUNITATE_DOC;
   end;
   -- adaug si locatiile care exista dar nu au fost selectate

   select nvl(ITipCont,0) into vAll from tmp_inventar;
   if vAll = 0 then
     INSERT INTO  TMP_INVENTCONT ( CodInventCont,
                                   CodInventar,
                                   CodTipCont,
                                   Selectat,
                                   Den_TipCont )
                          ( select I.CodInventCont,
                                   I.CodInventar,
                                   I.CodTipCont,
                                   1,
                                   IO.DEN_IOART
                           FROM INVENTCONT I inner join IOART IO on I.CODTIPCONT = IO.CODIOART WHERE CodInventar = RecId ) ;
   else
     INSERT INTO  TMP_INVENTCONT ( CodInventCont,
                                   CodInventar,
                                   CodTipCont,
                                   Selectat,
                                   Den_TipCont )
                          ( select RowNum,
                                   RecId,
                                   IO.CodIOArt,
                                   1,
                                   IO.DEN_IOART
                           FROM IOART IO) ;
   end if;
   -- adaug si tipurile de cont care exista dar nu au fost selectate
    /*INSERT INTO  TMP_INVENTCONT ( CodInventCont,
                                  CodInventar,
                                  CodTipCont,
                                  Selectat,
                                  Den_TipCont )
                         ( select IV.CodInventCont,
                                  IV.CodInventar,
                                  IO.CodIOArt,
                                  0,
                                  IO.DEN_IOART
                          FROM INVENTCONT IV inner join IOART IO on IV.CODTIPCONT = IO.CODIOART WHERE IV.CodInventar = RecId AND IO.CodIOArt NOT IN (SELECT IC.CodTipCont FROM INVENTCONT IC WHERE IC.CodInventar = RecId)) ;
*/

    select nvl(IClase,0) into vAll from tmp_inventar;
    if vAll = 0 then
      INSERT INTO  TMP_INVENTCLASE ( CodInventClase,
                                    CodInventar,
                                    CodClaseA,
                                    Den_ClaseA )
                           ( select I.CodInventClase,
                                    I.CodInventar,
                                    I.CodCLASEA,
                                    CLS.DEN_CLASEA
                            FROM INVENTCLASE I inner join NCLASEA CLS on I.CODCLASEA = CLS.CODCLASEA WHERE CodInventar = RecId ) ;
    else
      INSERT INTO  TMP_INVENTCLASE ( CodInventClase,
                                    CodInventar,
                                    CodClaseA,
                                    Den_ClaseA )
                           ( select RowNum,
                                    RecId,
                                    CLS.CodCLASEA,
                                    CLS.DEN_CLASEA
                            FROM NCLASEA CLS) ;
    end if;
    select nvl(IClaseS,0) into vAll from tmp_inventar;
    if vAll = 0 then
      INSERT INTO  TMP_INVENTCLASES ( CodInventClaseS,
                                    CodInventar,
                                    CodClaseAS,
                                    Den_ClaseAS )
                           ( select I.CodInventClaseS,
                                    I.CodInventar,
                                    I.CodCLASEAS,
                                    CLS.DEN_CLASEAS
                            FROM INVENTCLASES I inner join NCLASEAS CLS on I.CODCLASEAS = CLS.CODCLASEAS WHERE CodInventar = RecId ) ;
    else
      INSERT INTO  TMP_INVENTCLASES ( CodInventClaseS,
                                    CodInventar,
                                    CodClaseAS,
                                    Den_ClaseAS )
                           ( select RowNum,
                                    RecId,
                                    CLS.CodCLASEAS,
                                    CLS.DEN_CLASEAS
                            FROM NCLASEAS CLS) ;
    end if;
    select nvl(IProd,0) into vAll from tmp_inventar;
     if vAll = 0 then
       INSERT INTO  TMP_INVENTPROD ( CodInventProd,
                                     CodInventar,
                                     CodPart,
                                     Den_Part )
                            ( select I.CodInventProd,
                                     I.CodInventar,
                                     I.CodPart,
                                     P.DEN_PART
                             FROM INVENTPROD I inner join NPART P on I.CODPART = P.CODPART WHERE CodInventar = RecId ) ;
     else
       INSERT INTO  TMP_INVENTPROD ( CodInventProd,
                                     CodInventar,
                                     CodPart,
                                     Den_Part )
                            ( select RowNum,
                                     RecId,
                                     P.CodPArt,
                                     P.DEN_PART
                             FROM NPART P where p.tippartener = 4) ;
     end if;


    INSERT INTO  TMP_INVENTAR1 (
                                CODINVENTAR1,
                                CODINVENTAR ,
                                CODLOCATIE  ,
                                CODOBIECT   ,
                                CODSERIE    ,
                                SCRIPTIC    ,
                                FAPTIC      ,
                                SCRIPTICUM1 ,
                                FAPTICUM1   ,
                                SCRIPTICUM2 ,
                                FAPTICUM2   ,
                                EXPIRARE    ,
                                REZOLVAT    ,
                                VALOARE     ,
                                ORDINE      ,
                                UM1         ,
                                BLOCAT      ,
                                TIPSERIE    ,
                                ARETG       ,
                                SERIE       ,
                                DEN_LOCATIE ,
                                DEN_OBIECT  ,
                                CODEXTERN   ,
                                DEN_UM      ,
                                DEN_UM1     ,
                                DEN_UM2     ,
                                DIFERENTE   ,
                                DIFERENTEUM1,
                                DIFERENTEUM2,
                                REZOLVATUM1 ,
                                REZOLVATUM2 ,
                                PRODUCATOR  ,
                                DEN_UMSEC   ,
                                PARITATE    ,
                                CODINTERN,
                                TGString,
                                contimplicit,
                                denumire,
                                den_clasea,
                                codexternloc,
                                codioart,
                                den_claseas,
                                SERIED,
                                CODEXTERNART
                                 )
                          ( select INV1.CodInventar1,
                                   INV1.CodInventar,
                                   INV1.CodLocatie,
                                   INV1.CodObiect,
                                   INV1.CodSerie,
                                   nvl(INV1.Scriptic,0),
                                   nvl(INV1.Faptic,0),
                                   nvl(INV1.ScripticUM1,0),
                                   nvl(INV1.FapticUM1,0),
                                   nvl(INV1.ScripticUM2,0),
                                   nvl(INV1.FapticUM2,0),
                                   INV1.Expirare,
                                   nvl(INV1.Rezolvat,0),
                                   INV1.Valoare,
                                   inv1.ordine,
                                   inv1.um1,
                                   INV1.Blocat,
                                   INV1.Tipserie,
                                   ART.aretg,
                                   NSer.Serie,
                                   LOC.Denumire,
                                   OBJ.Denumire,
                                   OBJ.CodExtern,
                                   U.Den_UM,
                                   U1.Den_UM,
                                   U2.Den_UM,
                                   nvl(Faptic,0) - nvl(Scriptic,0),
                                   nvl(FapticUM1,0) - nvl(ScripticUM1,0),
                                   nvl(FapticUM2,0) - nvl(ScripticUM2,0),
                                   nvl(INV1.Rezolvat,0),
                                   nvl(INV1.Rezolvat,0),
                                   NPART.den_Part,
                                   num1.den_um1,
                                   num1.paritate,
                                   OBJ.CodIntern,
                                   to_char(INV1.Expirare,&apos;dd.mm.yyyy&apos;),
                                   ioa.den_ioart,
                                   obj.denumire,
                                   cls.den_clasea,
                                   loc.codextern,
                                   ioa.codioart,
                                   clss.den_claseas,
                                   NSer.Serie,
                                   art.CODEXTERNART
                          FROM INVENTAR1 INV1
                               inner join NARTOBJ OBJ on INV1.CODOBIECT = OBJ.CODOBIECT
                               inner join NART ART on OBJ.CODARTICOL = ART.CODARTICOL
                               inner join NUM U on ART.UM = U.CODUM
                               left join nclasea cls on nvl(art.clasa,0) = cls.codclasea
                               left join nclaseas clss on nvl(art.clasastatist,0) = clss.codclaseas
                               left join NSERII NSer on INV1.CODSERIE = NSER.CodSerie
                               left join NLOCATII LOC on INV1.CODLOCATIE = LOC.CODLOCATIE
                               left join NUM U1 on ART.UM1 = U1.CODUM
                               left join NUM U2 on ART.UM2 = U2.CODUM
                               left join num1 num1 on inv1.um1 = num1.codum1
                               left join npart on NVL(obj.codproducator, 0) = npart.codpart
                               left join nartimplicite imp on art.codarticol = imp.codarticol and imp.codsubunit = aCodSubunit
                               left join nartobjimp oimp on obj.codobiect = oimp.codobiect and oimp.codsubunit = aCodSubunit
                               left join ioart ioa on ioa.codioart = case when coalesce(oimp.contimplicit,0) = 0 then coalesce(imp.contimplicit,0) else oimp.contimplicit end
                          WHERE CodInventar = RecId);

    update tmp_inventar1 set seried = &apos;###&apos; where (Length(trim(seried)) = 0) or seried is null;

    /*begin
      update tmp_inventar1 v1
      set den_ioart =
        (select string_agg(distinct ioa.den_ioart)
         from inventstoc s
              inner join nirstoc ns on ns.codnirstoc = s.codnirstoc
              inner join ioart ioa on ns.codioart = ioa.codioart
         where s.codinventar1 = v1.codinventar1
         );
    exception when others then null;
    end;*/
    if PKG_CATEGCONST.GetValConstanta(&apos;GetIOAInv&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 then
      for v_rec in (select codinventar1
                    from tmp_inventar1
                   ) loop
        update tmp_inventar1 v1
        set den_ioart =
          (select string_agg(den_ioart)
           from
          (select distinct ioa.den_ioart
           from inventstoc s
                inner join nirstoc ns on ns.codnirstoc = s.codnirstoc
                inner join ioart ioa on ns.codioart = ioa.codioart
           where s.codinventar1 = v_rec.codinventar1
          )
          )
         where codinventar1 = v_rec.codinventar1;
      end loop;
    end if;

    INSERT INTO TMP_INVENTREZ (CodRezolvare,
                               CodInventar1,
                               CodNIRSTOC,
                               Rezolvat,
                               RezolvatUM1,
                               RezolvatUM2,
                               PretAchiz,
                               PretInreg,
                               CodIOArt,
                               CodPart,
                               Codnirser,
                               TVA,
                               TG,
                               PretMaximal,
                               CODLOCATIE,
                               D1,
                               D2,
                               D3,
                               CODGEST,
                               REST,
                               PUVAL,
                               DATAACHIZ)
                       (SELECT IZ.CodRezolvare,
                               IZ.CodInventar1,
                               IZ.CodNIRSTOC,
                               IZ.Rezolvat,
                               IZ.RezolvatUM1,
                               IZ.RezolvatUM2,
                               IZ.PretAchiz,
                               IZ.PretInreg,
                               IZ.CodIOArt,
                               IZ.CodPart,
                               IZ.Codnirser,
                               IZ.TVA,
                               IZ.TG,
                               IZ.PretMaximal,
                               IZ.CodLocatie,
                               IZ.D1,
                               IZ.D2,
                               IZ.D3,
                               IZ.CODGEST,
                               CASE WHEN NS.CODNIRSTOC &gt; 0 THEN NVL(NS.REST,0)/DECODE(NVL(NUM1.PARITATE,0),0,1,NVL(NUM1.PARITATE,0)) ELSE IZ.REZOLVAT END,
                               IZ.PUVAL,
                               IZ.DATAACHIZ
                        FROM INVENTREZ IZ
                             INNER JOIN INVENTAR1 I1 ON I1.CODINVENTAR1 = IZ.CODINVENTAR1
                             LEFT JOIN NIRSTOC NS ON IZ.CODNIRSTOC = NS.CODNIRSTOC
                             LEFT JOIN NUM1 ON NUM1.CODUM1 = I1.UM1
                        WHERE EXISTS ( SELECT CodInventar1 FROM INVENTAR1 WHERE CodInventar = RecId AND IZ.CODINVENTAR1 = INVENTAR1.CODINVENTAR1 ) );

  update tmp_inventrez set CodGest = (select CodGest from tmp_inventar);
  update tmp_inventar1 set reznegative = 0;
  for v_rec in (with Livrari as
                (
                 select distinct l1.codnirstoc
                 from iesiri i
                      inner join livr l on l.codies = i.codies
                      inner join iesiri1 i1 on i.codies = i1.codies
                      inner join livr1 l1 on l1.codlivr = l.codlivr and l1.codies1 = i1.codies1
                 where i.codies = vMarire or i.codies = vDiminuare
                )
                select rez.codinventar1
                from tmp_inventrez rez
                     inner join nirstoc ns on rez.codnirstoc = ns.codnirstoc
                     inner join tmp_inventar1 inv1 on inv1.codinventar1 = rez.codinventar1
                     inner join tmp_inventar inv on inv.codinventar = inv1.codinventar
                     left join Livrari on Livrari.codnirstoc = rez.codnirstoc
                where rez.codnirstoc &gt; 0 and rez.rezolvat &lt; 0 and rez.rezolvat + rez.rest &lt; 0
                      and Livrari.CodNirStoc is null
                ) loop
    update tmp_inventar1 set RezNegative = 1 where codinventar1 = v_rec.codinventar1;
  end loop;

  insert into tmp_inventstoc
  (
    CODINVENTSTOC  ,
    CODINVENTAR1   ,
    CODINVENTAR    ,
    CODNIRSTOC     ,
    CODNIRSER      ,
    PRET           ,
    REST           ,
    RESTUM1        ,
    RESTUM2        ,
    REZERVAT,
    D1, D2, D3,
    Den_IOART
  )
  select
    ivs.codinventstoc,
    ivs.codinventar1,
    ivs.codinventar,
    ivs.codnirstoc,
    Nvl(ivs.codnirser, 0),
    ivs.Pret,
    ivs.rest,
    ivs.restum1,
    ivs.restum2,
    0,
    ns.d1, ns.d2, ns.d3,
    ioa.den_ioart
  from inventstoc ivs
       inner join nirstoc ns on ns.codnirstoc = ivs.codnirstoc
       left join ioart ioa on ioa.codioart = ns.codioart
  where ivs.codinventar = RecId;

  update tmp_inventar1 t1 set poznegative = (select count(*) from tmp_inventstoc s where s.codinventar1 = t1.codinventar1 and s.rest &lt; 0);

  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
  END;

  IF TIPPREFIX = &apos;2&apos; THEN
    UPDATE TMP_INVENTAR1 I1
    SET
      DEN_OBIECT = NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
  ELSE
  IF TIPPREFIX = &apos;3&apos; THEN
    UPDATE TMP_INVENTAR1 I1
    SET
      DEN_OBIECT = NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
  END IF;
  END IF;

  /*aValTot := 0;
  for v_rec in (select codinventar1 from tmp_inventar1) loop
    begin
      select sum(nvl(s.pret,0)*nvl(s.rest,0)) into aVal
      from tmp_inventstoc s
      where s.codinventar1 = v_rec.codinventar1;
    exception when others then aVal := 0;
    end;
    aValTot := aValTot + aVal;
  end loop;*/
  update tmp_inventar iv
  set valscriptic = (select sum(nvl(ivs.pret,0)*nvl(ivs.rest,0))
                     from inventar1 i1
                          inner join inventstoc ivs on ivs.codinventar1 = i1.codinventar1
                          inner join nirstoc ns on ivs.codnirstoc = ns.codnirstoc
                     where i1.codinventar = RecId);

  aValTot := 0;
  aValMar := 0;
  aValDim := 0;
  for v_rec in (select codinventar1, scriptic, faptic, rezolvat from tmp_inventar1) loop
    begin
      select nvl(sum(nvl(s.pret,0)*nvl(s.rest,0)),0) into aVal
      from tmp_inventstoc s
      where s.codinventar1 = v_rec.codinventar1;
    exception when others then aVal := 0;
    end;
    if v_rec.scriptic = v_rec.faptic and v_rec.scriptic = 0 then
      aVal := 0;
    else
      if v_rec.scriptic &lt;&gt; v_rec.faptic then
        if v_rec.rezolvat = 1 then
          begin
            select nvl(sum(nvl(rez.pretinreg,0)*nvl(rez.rezolvat,0)),0) into aValRez
            from tmp_inventrez rez
            where rez.codinventar1 = v_rec.codinventar1;
          exception when others then aValRez := 0;
          end;
          aVal := aVal + aValRez;
          if v_Rec.Faptic &gt; v_rec.scriptic then
            aValMar := aValMar + aValRez;
          else
            aValDim := aValDim - aValRez;
          end if;
        else
          if v_Rec.Faptic &gt; v_rec.scriptic and v_rec.scriptic &lt;&gt; 0 then
            aValMar := aValMar + (v_rec.faptic - v_rec.scriptic) * aVal/v_rec.scriptic;
          else
            if v_rec.scriptic &lt;&gt; 0 then
              aValDim := aValDim + (v_rec.scriptic - v_rec.faptic) * aVal/v_rec.scriptic;
            end if;
          end if;
          if v_rec.scriptic &lt;&gt; 0 then
            aVal := v_rec.faptic * aVal/v_rec.scriptic;
          end if;
        end if;
      end if;
    end if;
    aValTot := aValTot + aVal;
  end loop;
  update tmp_inventar
  set
    valfaptic = aValTot,
    valMariri = aValMar,
    valDiminuari = aValDim;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod number(20);
vFinalizat number(20);
aDataDoc DATE;
aDoc     VARCHAR2(200);
aCodSerie number(20);
NOMSERIE VARCHAR2(30);
aCodGest number(20);
aCount number(10);
aITipCont number(1);
aIClase number(1);
aIClaseS number(1);
aIProd number(1);
BEGIN
  SELECT
    DATAINVENTAR,
    TO_CHAR(NRINVENTAR),
    GESTIUNE,
    ITipCont,
    IClase,
    IClaseS,
    IProd
  INTO
    aDATADOC,
    ADOC,
    aCodgest,
    aITipCont,
    aIClase,
    aIClaseS,
    aIProd
  FROM TMP_INVENTAR;

  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodInventar INTO RecId FROM TMP_INVENTAR;
    SELECT  Blocat INTO vFinalizat FROM TMP_INVENTAR;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INVENTAR&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE INVENTAR SET ( NrInventar,
                          DataInventar,
                          Gestiune,
                          Responsabil,
                          Observatii,
                          Tip,
                          Diminuare,
                          Marire,
                          Facturare,
                          IArt,
                          ITipCont,
                          IClase,
                          IClaseS,
                          IProd,
                          Subunitate,
                          TipRezolvare, flgPalm,Blocat,
                          RezDif,
                          Marja )
               = ( SELECT NrInventar,
                          DataInventar,
                          Gestiune,
                          Responsabil,
                          Observatii,
                          Tip,
                          Diminuare,
                          Marire,
                          Facturare,
                          IArt,
                          ITipCont,
                          IClase,
                          IClaseS,
                          IProd,
                          Subunitate,
                          TipRezolvare, flgPalm, Blocat,
                          RezDif,
                          Marja
              FROM TMP_INVENTAR )
      WHERE CodInventar = RecId ;

    DELETE FROM INVENTCONT where CodInventar = RecId and CodInventCont not in (Select CodInventCont from TMP_INVENTCONT WHERE Selectat = 1 );
    INSERT INTO INVENTCONT ( CodInventCont,
                             CodInventar,
                             CodTipCont )
                           ( SELECT  Seq_InventCont_CodInventCont.Nextval,
                             RecId,
                             CodTipCont
                             FROM TMP_INVENTCONT WHERE CodInventCont &lt; 0 AND Selectat = 1 ) ;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTCONT WHERE NVL(CodInventCont, -1) &gt; 0 AND Selectat = 1 ORDER BY CodInventCont ) LOOP
       UPDATE INVENTCONT
       SET
        CodInventar         = v_rec.CodInventar,
        CodTipCont          = v_rec.CodTipCont
       WHERE CodInventCont  = v_rec.CodInventCont;
    END LOOP;

    select count(*) into aCount from inventcont where codinventar = recid;
    if aCount = 0 and aITipCont = 1 then
      insert into inventcont(codinventcont, codinventar, codtipcont)
      select seq_inventcont_codinventcont.nextval, recid, codioart
      from ioart where codioart &gt; 0;
    end if;

    DELETE FROM INVENTCLASE where CodInventar = RecId and CodInventCLASE not in (Select CodInventCLASE from TMP_INVENTCLASE);
    INSERT INTO INVENTCLASE ( CodInventCLASE,
                             CodInventar,
                             CodCLASEA )
                           ( SELECT  Seq_InventClase_CodInventClase.Nextval,
                             RecId,
                             CodClaseA
                             FROM TMP_INVENTCLASE WHERE CodInventCLASE &lt; 0) ;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTCLASE WHERE NVL(CodInventCLASE, -1) &gt; 0 ORDER BY CodInventClase ) LOOP
       UPDATE INVENTCLASE
       SET
        CodInventar         = v_rec.CodInventar,
        CodCLASEA           = v_rec.CodCLASEA
       WHERE CodInventCLASE  = v_rec.CodInventCLASE;
    END LOOP;

    select count(*) into aCount from inventclase where codinventar = recid;
    if aCount = 0 and aIClase = 1 then
      insert into inventclase(codinventclase, codinventar, codclasea)
      select seq_inventclase_codinventclase.nextval, recid, codclasea
      from nclasea;
    end if;

    DELETE FROM INVENTCLASES where CodInventar = RecId and CodInventCLASES not in (Select CodInventCLASES from TMP_INVENTCLASES);
    INSERT INTO INVENTCLASES ( CodInventCLASES,
                             CodInventar,
                             CodCLASEAS )
                           ( SELECT  Seq_InventClaseS_CodInvClaseS.Nextval,
                             RecId,
                             CodClaseAS
                             FROM TMP_INVENTCLASES WHERE CodInventCLASES &lt; 0) ;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTCLASES WHERE NVL(CodInventCLASES, -1) &gt; 0 ORDER BY CodInventClaseS ) LOOP
       UPDATE INVENTCLASES
       SET
        CodInventar         = v_rec.CodInventar,
        CodCLASEAS           = v_rec.CodCLASEAS
       WHERE CodInventCLASES  = v_rec.CodInventCLASES;
    END LOOP;

    select count(*) into aCount from inventclases where codinventar = recid;
    if aCount = 0 and aIClaseS = 1 then
      insert into inventclases(codinventclases, codinventar, codclaseas)
      select seq_inventclases_codinvclases.nextval, recid, codclaseas
      from nclaseas;
    end if;

    DELETE FROM INVENTPROD where CodInventar = RecId and CodInventProd not in (Select CodInventProd from TMP_INVENTPROD);
    INSERT INTO INVENTPROD ( CodInventProd,
                             CodInventar,
                             CodPart )
                           ( SELECT Seq_InventProd_CodInventProd.Nextval,
                             RecId,
                             CodPart
                             FROM TMP_INVENTPROD WHERE CodInventProd &lt; 0) ;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTPROD WHERE NVL(CodInventProd, -1) &gt; 0 ORDER BY CodInventProd ) LOOP
       UPDATE INVENTPROD
       SET
        CodInventar         = v_rec.CodInventar,
        CodPart             = v_rec.CodPart
       WHERE CodInventProd  = v_rec.CodInventProd;
    END LOOP;

    select count(*) into aCount from inventprod where codinventar = recid;
    if aCount = 0 and aIProd = 1 then
      insert into inventprod(codinventprod, codinventar, codpart)
      select seq_inventprod_codinventprod.nextval, recid, codpart
      from npart
      where tippartener = 4;
    end if;

    FOR V_REC IN (SELECT * FROM TMP_INVENTAR1 where tipserie &gt; 0) LOOP
      IF NVL(V_REC.CODSERIE,0) &lt;= 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
        BEGIN
          SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = v_rec.CODOBIECT;
          EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
        END;

        IF NVL(aCODSERIE, 0) = 0 THEN
          SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
          INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, v_rec.CODOBIECT);
        END IF;
        UPDATE TMP_INVENTAR1 SET CODSERIE = aCODSERIE where codinventar1 = v_rec.codinventar1;
      /*ELSE
        aCODSERIE := V_REC.CODSERIE;
        -- verific daca la editare nu a schimbat seria
        begin
        SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
        exception when others then NOMSERIE := &apos;&apos;;
        end;

        IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
          UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
        END IF;*/
      END IF;
    END LOOP;
    
    for v_rec in (select codinventar1 FROM INVENTAR1 where CodInventar = RecId and CodInventar1 not in (Select CodInventar1 from TMP_INVENTAR1)) loop
      delete rezervats where codinventar1 = v_rec.codinventar1;
      delete inventar1 where codinventar1 = v_rec.codinventar1;
    end loop;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTAR1 WHERE NVL(CodInventar1, -1) &gt; 0 ORDER BY CodInventar1 ) LOOP
       UPDATE INVENTAR1
       SET
        CodLocatie  = v_rec.CodLocatie,
        CodObiect   = v_rec.CodObiect,
        CodSerie    = v_rec.CodSerie,
        Scriptic    = v_rec.Scriptic,
        Faptic      = v_rec.Faptic,
        ScripticUM1 = v_rec.ScripticUM1,
        FapticUM1   = v_rec.FapticUM1,
        ScripticUM2 = v_rec.ScripticUM2,
        FapticUM2   = v_rec.FapticUM2,
        Expirare    = v_rec.Expirare,
        Rezolvat    = v_rec.Rezolvat,
        Ordine      = v_rec.Ordine,
        UM1         = v_rec.UM1,
        Blocat      = v_rec.Blocat,
        Valoare     = v_rec.Valoare,
        TipSerie    = v_rec.TipSerie
       WHERE CodInventar1  = v_rec.CodInventar1;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_INVENTAR1 WHERE CodInventar1 &lt; 0) LOOP
      SELECT SEQ_inventar1_codinventar1.NEXTVAL INTO vCOD FROM DUAL;
      UPDATE TMP_inventrez SET CODinventar1 = vCOD WHERE CODinventar1 = v_rec.codinventar1;
      UPDATE TMP_inventstoc SET CODinventar1 = vCOD WHERE CODinventar1 = v_rec.codinventar1;
      INSERT INTO INVENTAR1 (CodInventar1,
                           CodInventar,
                           CodLocatie,
                           CodObiect,
                           CodSerie,
                           Scriptic,
                           Faptic,
                           ScripticUM1,
                           FapticUM1,
                           ScripticUM2,
                           FapticUM2,
                           Expirare,
                           Rezolvat,
                           Ordine,
                           UM1,
                           Blocat,
                           Valoare,
                           TipSerie)
                           values
                         ( vCod,
                           RecId,
                           v_rec.CodLocatie,
                           v_rec.CodObiect,
                           v_rec.CodSerie,
                           v_rec.Scriptic,
                           v_rec.Faptic,
                           v_rec.ScripticUM1,
                           v_rec.FapticUM1,
                           v_rec.ScripticUM2,
                           v_rec.FapticUM2,
                           v_rec.Expirare,
                           v_rec.Rezolvat,
                           v_rec.Ordine,
                           v_rec.UM1,
                           v_rec.Blocat,
                           v_rec.valoare,
                           v_rec.TipSerie);
    END LOOP;


    DELETE FROM INVENTREZ WHERE (CodInventar1 IN (SELECT CodInventar1 FROM INVENTAR1 WHERE CodInventar = RecId)) AND (CodRezolvare not in (SELECT CodRezolvare FROM TMP_INVENTREZ)) ;
    INSERT INTO INVENTREZ (CODREZOLVARE,CODINVENTAR1,CODNIRSTOC,REZOLVAT,REZOLVATUM1,REZOLVATUM2,PRETACHIZ,PRETINREG, CODIOART, CODPART, CODNIRSER, TVA, TG, PretMaximal, CodLocatie, D1, D2, D3,CODGEST,
                           PUVAL, DATAACHIZ)
    (SELECT seq_inventrez_codrezolvare.nextval,CODINVENTAR1,CODNIRSTOC,REZOLVAT,REZOLVATUM1,REZOLVATUM2,PretAchiz,PretInreg, CodIOArt, CODPART, CODNIRSER, TVA, TG, PretMaximal, CodLocatie,
            D1, D2, D3, aCodGest, PUVAL, DATAACHIZ  FROM TMP_INVENTREZ WHERE CodRezolvare &lt;= 0) ;
    FOR v_rec IN ( SELECT * FROM TMP_INVENTREZ WHERE NVL(CodRezolvare, -1) &gt; 0 ORDER BY CodRezolvare ) LOOP
      UPDATE INVENTREZ
      SET
        CodInventar1 = v_rec.codinventar1,
        CodNirStoc   = v_rec.codnirstoc,
        Rezolvat     = v_rec.rezolvat,
        RezolvatUM1  = v_rec.rezolvatum1,
        RezolvatUM2  = v_rec.rezolvatum2,
        PretAchiz    = v_rec.pretachiz,
        PretInreg    = v_rec.pretinreg,
        CodIOArt     = v_rec.codioart,
        CodPart      = v_rec.codpart,
        CodNirSer    = v_rec.codnirser,
        TVA          = v_rec.TVA,
        TG           = v_rec.TG,
        PretMaximal  = v_rec.PretMaximal,
        CodLocatie   = v_rec.CodLocatie,
        CodGest      = aCodgest,
        D1 = v_rec.D1, D2 = v_rec.D2, D3 = v_rec.D3,
        PUVAL = V_REC.PUVAL,
        DATAACHIZ = V_REC.DATAACHIZ
      WHERE CodRezolvare = v_rec.codrezolvare;
    END LOOP;

    DELETE FROM INVENTSTOC where codinventar = recid  and CodInventStoc not in (Select CodInventStoc from TMP_INVENTSTOC);
    INSERT INTO INVENTSTOC( CODINVENTSTOC,
                            CODINVENTAR1,
                            CODINVENTAR,
                            CODNIRSTOC,
                            CODNIRSER,
                            PRET,
                            REST,
                            RESTUM1,
                            RESTUM2 )
                          ( SELECT  Seq_InventStoc_CodInventStoc.Nextval,
                            CODINVENTAR1,
                            RecId,
                            CODNIRSTOC,
                            CODNIRSER,
                            PRET,
                            REST,
                            RESTUM1,
                            RESTUM2
                            FROM TMP_INVENTSTOC WHERE CodInventStoc &lt; 0 );
    FOR v_rec IN ( SELECT * FROM TMP_INVENTSTOC WHERE NVL(CodInventStoc, -1) &gt; 0 ORDER BY CodInventStoc ) LOOP
       UPDATE INVENTSTOC
       SET
        CODNIRSTOC = v_rec.codnirstoc,
        CODNIRSER  = v_Rec.Codnirser,
        PRET       = v_Rec.Pret,
        REST       = v_rec.rest,
        RESTUM1    = v_rec.restUM1,
        RESTUM2    = v_rec.restUM2
       WHERE CodInventStoc  = v_rec.CodInventStoc;
    END LOOP;

    if vFinalizat = 1 then
      delete from rezervats r where exists (select codinventar1 from inventar1 inv1 where r.codinventar1 = inv1.codinventar1 and inv1.codinventar = recid);
      update inventar1 set blocat = 0 where codinventar = recid;
    end if;

  ELSE

  SELECT Seq_Inventar_CodInventar.NextVal INTO RecId FROM DUAL;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;INVENTAR&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO  INVENTAR ( CodInventar,
                          NrInventar,
                          DataInventar,
                          Gestiune,
                          Responsabil,
                          Observatii,
                          Tip,
                          Diminuare,
                          Marire,
                          Facturare,
                          IArt,
                          ITipCont,
                          IClase,
                          IClaseS,
                          IProd,
                          Subunitate,
                          UserId,
                          DataCreare,
                          TipRezolvare, Flgpalm, Blocat,
                          RezDif, Marja )
                 ( select RecId,
                          NrInventar,
                          DataInventar,
                          Gestiune,
                          Responsabil,
                          Observatii,
                          Tip,
                          Diminuare,
                          Marire,
                          Facturare,
                          IArt,
                          ITipCont,
                          IClase,
                          IClaseS,
                          IProd,
                          Subunitate,
                          pkg_globals.USERID,
                          systimestamp,
                          TipRezolvare, flgPalm, Blocat,
                          RezDif, Marja
                   FROM TMP_INVENTAR ) ;

  INSERT INTO  INVENTCONT ( CodInventCont,
                            CodInventar,
                            CodTipCont )
                   ( select Seq_InventCont_CodInventCont.Nextval,
                            RecId,
                            CodTipCont
                     FROM TMP_INVENTCONT WHERE Selectat = 1 ) ;

  INSERT INTO  INVENTCLASE ( CodInventClase,
                            CodInventar,
                            CodClaseA )
                   ( select Seq_InventClase_CodInventClase.Nextval,
                            RecId,
                            CodClaseA
                     FROM TMP_INVENTCLASE) ;

  INSERT INTO  INVENTCLASES ( CodInventClaseS,
                            CodInventar,
                            CodClaseAS )
                   ( select Seq_InventClaseS_CodInvClaseS.Nextval,
                            RecId,
                            CodClaseAS
                     FROM TMP_INVENTCLASES) ;

  INSERT INTO  INVENTPROD ( CodInventProd,
                            CodInventar,
                            CodPart )
                   ( select Seq_InventProd_CodInventProd.Nextval,
                            RecId,
                            CodPart
                     FROM TMP_INVENTPROD) ;

  for v_Rec in (select * from tmp_inventar1) loop
    INSERT INTO  INVENTAR1 ( CodInventar1,
                             CodInventar,
                             CodLocatie,
                             CodObiect,
                             CodSerie,
                             Scriptic,
                             Faptic,
                             ScripticUM1,
                             FapticUM1,
                             ScripticUM2,
                             FapticUM2,
                             Expirare,
                             Rezolvat,
                             Ordine,
                             UM1,
                             Blocat,
                             Valoare,
                             TipSerie )
                    values ( v_rec.codinventar1,
                             RecId,
                             v_rec.CodLocatie,
                             v_rec.CodObiect,
                             v_rec.CodSerie,
                             v_rec.Scriptic,
                             v_rec.Faptic,
                             v_rec.ScripticUM1,
                             v_rec.FapticUM1,
                             v_rec.ScripticUM2,
                             v_rec.FapticUM2,
                             v_rec.Expirare,
                             v_rec.Rezolvat,
                             v_rec.Ordine,
                             v_rec.UM1,
                             v_rec.Blocat,
                             v_rec.valoare,
                             v_rec.TipSerie);
  end loop;

  INSERT INTO INVENTSTOC( CODINVENTSTOC,
                            CODINVENTAR1,
                            CODINVENTAR,
                            CODNIRSTOC,
                            CODNIRSER,
                            PRET,
                            REST,
                            RESTUM1,
                            RESTUM2 )
                          ( SELECT  Seq_InventStoc_CodInventStoc.Nextval,
                            CodInventar1,
                            RecId,
                            CODNIRSTOC,
                            CODNIRSER,
                            PRET,
                            REST,
                            RESTUM1,
                            RESTUM2
                            FROM TMP_INVENTSTOC);

  END IF;
  NotifyModif(Operation, RecId, &apos;INVENTAR&apos;);
  COMMIT;
END;

function ServiceInventar(aCodInventar IN NUMBER) return number IS
c number;
begin
  for v_rec in (select s.codinventstoc
                from inventstoc s
                     left join nirstoc ns on ns.codnirstoc = s.codnirstoc
                where s.codinventar = aCodInventar and ns.codnirstoc is null
                ) loop
    delete inventstoc where codinventstoc = v_rec.codinventstoc;
  end loop;
  C := TestCoerenta(aCodInventar);
  if C = 0 then Return C; end if;
  DELETE FROM TMP_TESTINV;
  for v_1 in (select * from inventar1 where codinventar = acodinventar) loop
    select count(*) into c from inventar1
    where
         codinventar = aCodInventar
     and codinventar1 &lt;&gt; v_1.CodInventar1
     and codobiect  = v_1.codobiect
     and Nvl(CODSERIE, 0)   = NVL(v_1.CODSERIE,0)
     AND nvl(EXPIRARE, pkg_globals.DATA0) = nvl(v_1.EXPIRARE, pkg_globals.DATA0)
     and nvl(um1,0)        = nvl(v_1.um1,0)
     and nvl(CodLocatie,0) = nvl(v_1.CodLocatie,0);

    if C &lt;&gt; 0 then
      for v_x in (
        select * from inventar1
        where
             codinventar = aCodInventar
         and codinventar1 &lt;&gt; v_1.CodInventar1
         and codobiect  = v_1.codobiect
         and Nvl(CODSERIE, 0)   = NVL(v_1.CODSERIE,0)
         AND nvl(EXPIRARE, pkg_globals.DATA0) = nvl(v_1.EXPIRARE, pkg_globals.DATA0)
         and nvl(um1,0)        = nvl(v_1.um1,0)
         and nvl(CodLocatie,0) = nvl(v_1.CodLocatie,0)
        ) loop
        select Count(*) into c from TMP_TESTINV where Cod2 = v_1.Codinventar1 and Cod1=v_x.Codinventar1;
        if c=0 then
          insert into TMP_TESTINV (Codinventar, cod1, cod2) values(acodinventar, v_1.Codinventar1, v_x.Codinventar1);
         end if;
      end loop;
    end if;
  end loop;

  UPDATE TMP_TESTINV SET den = (SELECT o.DENUMIRE FROM nartobj o left join inventar1 i on i.codobiect=o.codobiect WHERE CODINVENTAR1=COD1);
  commit;
  select Count(*) into c from TMP_TESTINV;
  return c;
end;

procedure CorectieInventar(aCodInventar IN NUMBER) IS
cant number(20,7);
dif number(20,7);
begin
  for v_rec in (select *
                from inventstoc istoc
                     inner join inventar1 i1 on istoc.codinventar1 = i1.codinventar1
                where istoc.codinventar = acodinventar
                      and istoc.rest &lt; 0 and i1.rezolvat = 1) loop
    delete inventstoc where codinventstoc = v_rec.codinventstoc;
  end loop;

  update inventar1 i1 set
    scriptic = (select sum(istoc.rest) from inventstoc istoc where istoc.codinventar = acodinventar and istoc.codinventar1 = i1.codinventar1),
    scripticUM1 = (select sum(istoc.restUM1) from inventstoc istoc where istoc.codinventar = acodinventar and istoc.codinventar1 = i1.codinventar1),
    scripticUM2 = (select sum(istoc.restUM2) from inventstoc istoc where istoc.codinventar = acodinventar and istoc.codinventar1 = i1.codinventar1)
  where i1.codinventar = acodinventar and i1.rezolvat = 1;

  for v_rec in (select i1.codinventar1, i1.faptic - i1.scriptic dif, nvl(rez.rezolvat,0) rezolvat
                from inventar1 i1
                     inner join (select sum(iz.rezolvat) rezolvat, iz.codinventar1
                                 from inventrez iz
                                      inner join inventar1 i1 on i1.codinventar1 = iz.codinventar1
                                 where i1.codinventar = aCodInventar
                                 group by iz.codinventar1) rez on rez.codinventar1 = i1.codinventar1
                where i1.codinventar = aCodInventar and i1.scriptic &gt; 0
                      and i1.faptic - i1.scriptic &lt;&gt; nvl(rez.rezolvat,0) and i1.rezolvat = 1) loop
    if abs(v_rec.rezolvat) &lt; abs(v_rec.dif) then
      dif := v_rec.rezolvat - v_rec.dif;
      for v_tmp in (select istoc.codnirstoc, istoc.codnirser, istoc.pret, ns.rest,
                           ns.pret - nvl(ns.adaos,0) pretachiz, ns.pret pretinreg, ns.codioart, ns.furn codpart, ns.tva, ns.tg, ns.pumaximal pretmaximal, ns.codlocatie,
                           nir.gest codgest, ns.d1, ns.d2, ns.d3
                    from inventstoc istoc
                         inner join nirstoc ns on ns.codnirstoc = istoc.codnirstoc
                         inner join nir on nir.codnir = ns.codnir
                    where istoc.codinventar1 = v_rec.codinventar1
                    order by istoc.codnirstoc
                    ) loop
        if v_tmp.rest &gt; 0 then
          if v_tmp.rest &gt; dif then
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat,
                                  pretachiz, pretinreg, codioart, codpart, codnirser, tva, tg, pretmaximal, codlocatie,
                                  codgest, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, v_rec.codinventar1, v_tmp.codnirstoc, -dif,
                    v_tmp.pretachiz, v_tmp.pretinreg, v_tmp.codioart, v_tmp.codpart, v_tmp.codnirser, v_tmp.tva, v_tmp.tg, v_tmp.pretmaximal,
                    v_tmp.codlocatie, v_tmp.codgest, v_tmp.d1, v_tmp.d2, v_tmp.d3);
            exit;
          else
            insert into inventrez(codrezolvare, codinventar1, codnirstoc, rezolvat,
                                  pretachiz, pretinreg, codioart, codpart, codnirser, tva, tg, pretmaximal, codlocatie,
                                  codgest, d1, d2, d3)
            values (seq_inventrez_codrezolvare.nextval, v_rec.codinventar1, v_tmp.codnirstoc, -v_tmp.rest,
                    v_tmp.pretachiz, v_tmp.pretinreg, v_tmp.codioart, v_tmp.codpart, v_tmp.codnirser, v_tmp.tva, v_tmp.tg, v_tmp.pretmaximal,
                    v_tmp.codlocatie, v_tmp.codgest, v_tmp.d1, v_tmp.d2, v_tmp.d3);
            dif := dif - v_tmp.rest;
          end if;
        end if;
      end loop;
    end if;
  end loop;

  --rezolvare doc diminuare
  for v_rec in (select rez.codnirstoc, rez.codnirser, rez.rezolvat, nvl(l1.codlivr1,0) codlivr1,
                       nvl(ies1.codies1,0) codies1, l.codlivr, ns.umsec
                from inventrez rez
                     inner join nirstoc ns on rez.codnirstoc = ns.codnirstoc
                     inner join inventar1 i1 on rez.codinventar1 = i1.codinventar1
                     inner join inventar i on i1.codinventar = i.codinventar
                     left join iesiri ies on ies.codies = i.diminuare
                     left join livr l on l.codies = ies.codies
                     left join iesiri1 ies1 on ies1.codies = ies.codies and ies1.codobiect = i1.codobiect and ies1.pu = rez.pretinreg
                     left join livr1 l1 on l1.codies1 = ies1.codies1 and l1.codlivr = l.codlivr
                                           and l1.codnirstoc = rez.codnirstoc and nvl(l1.codnirser,0) = nvl(rez.codnirser,0)
                                           and l1.cant = abs(rez.rezolvat)
                where i1.scriptic &gt; i1.faptic and i1.rezolvat = 1
                      and i1.codinventar = aCodInventar
                ) loop
    if v_rec.codies1 &gt; 0 and v_rec.codlivr1 = 0 then
      insert into livr1 (codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, umsec)
      values (seq_livr1_codlivr1.nextval, v_rec.codlivr, v_rec.codies1, v_rec.codnirstoc, abs(v_rec.rezolvat), v_rec.codnirser, v_rec.umsec);

      update iesiri1 set cant = cant + abs(v_Rec.Rezolvat)
      where codies1 = v_rec.codies1;
    end if;
  end loop;
  commit;
end;

procedure IMPORTSCANARE(aCodObiect in number, aCodUM1 in number, aSerie in varchar2, aTG in varchar2, aCant in number, aCodInventar in number) is
aCodInventar1 number(20);
aCodSerie number(20);
aTipSerie number(1);
aCodLocatie number(20);
aSubunitate number(20);
begin
  select subunitate into aSubunitate from inventar where codinventar = aCodInventar;
  begin
    select coalesce(a.tipserie,0),coalesce(oimp.locatieimplicita,aimp.locatieimplicita,0) into aTipSerie, aCodLocatie
    from nartobj o
         inner join nart a on a.codarticol = o.codarticol
         left join nartimplicite aimp on aimp.codarticol = a.codarticol and aimp.codsubunit = aSubunitate
         left join nartobjimp oimp on oimp.codobiect = o.codobiect and oimp.codsubunit = aSubunitate
    where o.codobiect = aCodObiect;
  exception when others then aTipSerie := 0;
  end;

  aCodSerie := 0;
  if length(trim(aserie)) &gt; 0 then
    begin
      select codserie into aCodSerie from nserii where trim(serie) = trim(aSerie) and (codobiect is null or codobiect = aCodObiect);
    exception when others then
      select seq_nserii_codserie.nextval into aCodSerie from dual;
      insert into nserii(codserie,serie,codobiect)
      values (aCodSerie,aSerie,aCodObiect);
      commit;
    end;
  end if;
  if aCodSerie &gt; 0 then
    if Length(coalesce(aTG,&apos;&apos;)) &gt; 0 then
      begin
        select i1.codinventar1 into aCodInventar1
        from inventar1 i1
        where i1.codinventar = aCodInventar and i1.codobiect = aCodObiect and
              i1.um1 = aCodUM1 and
              coalesce(i1.codserie,0) = aCodSerie and expirare = to_date(aTG, &apos;dd.mm.yyyy&apos;);
      exception when others then aCodInventar1 := -1;
      end;
    else
      begin
        select i1.codinventar1 into aCodInventar1
        from inventar1 i1
        where i1.codinventar = aCodInventar and i1.codobiect = aCodObiect and
              i1.um1 = aCodUM1 and
              coalesce(i1.codserie,0) = aCodSerie;
      exception when others then aCodInventar1 := -1;
      end;
    end if;
  else
    if Length(coalesce(aTG,&apos;&apos;)) &gt; 0 then
      begin
        select i1.codinventar1 into aCodInventar1
        from inventar1 i1
        where i1.codinventar = aCodInventar and i1.codobiect = aCodObiect and
              i1.um1 = aCodUM1 and
              expirare = to_date(aTG, &apos;dd.mm.yyyy&apos;);
      exception when others then aCodInventar1 := -1;
      end;
    else
      begin
        select min(i1.codinventar1) into aCodInventar1
        from inventar1 i1
        where i1.codinventar = aCodInventar and i1.codobiect = aCodObiect and
              i1.um1 = aCodUM1;
      exception when others then aCodInventar1 := -1;
      end;
    end if;
  end if;
  if aCodInventar1 &gt; 0 then
    update inventar1 set faptic = coalesce(faptic,0) + aCant, rezolvat = 0 where codinventar1 = aCodInventar1;
    delete inventrez where codinventar1 = aCodInventar1;
  else
    insert into inventar1(codinventar1,codinventar,codobiect,codserie,scriptic,faptic,expirare,um1,tipserie,ordine,codlocatie)
    values (seq_inventar1_codinventar1.nextval,aCodInventar,aCodObiect,aCodSerie,0,aCant,to_date(aTG,&apos;dd.mm.yyyy&apos;), aCodUM1, aTipSerie,
            (select max(ordine)+1 from inventar1 where codinventar = aCodInventar),aCodLocatie);
  end if;
  commit;
end;

procedure INCHIDEINVENTARENEFINALIZATE is
oData varchar2(10);
begin
  oData := &apos;01.&apos;;
  if pkg_globals.GetLUNALUCRU &lt; 10 then
    oData := oData||&apos;0&apos;||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;;
  else
    oData := oData||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;;
  end if;
  oData := oData||to_char(pkg_globals.GetANLUCRU);
  for v_rec in (select i1.codinventar1, i.codinventar
                from inventar i
                     inner join inventar1 i1 on i1.codinventar = i.codinventar
                where i.blocat &lt;&gt; 1 and i.datainventar &lt;= Last_Day(to_date(oData,&apos;dd.mm.yyyy&apos;))
               ) loop
    update inventar set blocat = 1 where codinventar = v_rec.codinventar;
    delete rezervats where codinventar1 = v_rec.codinventar1;
    update inventar1 set blocat = 0 where codinventar1 = v_rec.codinventar1;
  end loop;
end;

procedure RezDifAut(aCodInventar in number) is
begin
  for v_rec in (
    select 
      i1.codinventar1,
      s.codnirstoc,
      coalesce(i1.faptic,0) - coalesce(i1.scriptic,0) rezolvat,
      - ns.restum1 rezolvatum1,
      - ns.restum2 rezolvatum2,
      coalesce(ns.pret,0) - coalesce(ns.adaos,0) pretachiz,
      coalesce(ns.pret,0) pretinreg,
      ns.codioart,
      ns.furn codpart,
      s.codnirser,
      ns.tva,
      coalesce(nse.tg,ns.tg) tg,
      ns.pumaximal pretmaximal,
      i1.codlocatie,
      i.gestiune codgest,
      ns.d1,
      ns.d2,
      ns.d3,
      ns.puval,
      ns.dataachiz
    from inventar1 i1
         inner join inventar i on i.codinventar = i1.codinventar 
         inner join inventstoc s on s.codinventar1 = i1.codinventar1
         inner join nirstoc ns on ns.codnirstoc = s.codnirstoc
         left join nirser nse on nse.codnirstoc = ns.codnirstoc and s.codnirser = nse.codnirser
    where i1.codinventar = aCodInventar and not exists (select r.codrezolvare from inventrez r where r.codinventar1 = s.codinventar1)
          and coalesce(i1.scriptic,0) &lt;&gt; coalesce(i1.faptic,0)
  ) loop
    insert into inventrez(codrezolvare,
                          codinventar1,
                          codnirstoc,
                          rezolvat,
                          rezolvatum1,
                          rezolvatum2,
                          pretachiz,
                          pretinreg,
                          codioart,
                          codpart,
                          codnirser,
                          tva,
                          tg,
                          pretmaximal,
                          codlocatie,
                          codgest,
                          d1,
                          d2,
                          d3,
                          puval,
                          dataachiz)
      
    values (seq_inventrez_codrezolvare.nextval,
            v_rec.codinventar1,
            v_rec.codnirstoc,
            v_rec.rezolvat,
            v_rec.rezolvatum1,
            v_rec.rezolvatum2,
            v_rec.pretachiz,
            v_rec.pretinreg,
            v_rec.codioart,
            v_rec.codpart,
            v_rec.codnirser,
            v_rec.tva,
            v_rec.tg,
            v_rec.pretmaximal,
            v_rec.codlocatie,
            v_rec.codgest,
            v_rec.d1,
            v_rec.d2,
            v_rec.d3,
            v_rec.puval,
            v_rec.dataachiz);
    update inventar1 set rezolvat = 1 where codinventar1 = v_rec.codinventar1;        
  end loop;
  commit;
end;  

procedure Debug is
c1 number;
begin
  pkg_globals.SetLunaLucru(2012,8);
  c1 := UpdateInventStoc(549);
  --c1 := UpdateInventRez(412);
end;
end PKG_INVENTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_JOBLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A85131E8B0799E970E9ED06B2B2FE7EAC5856B1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_jobliste IS

  gTipJob number(1) := 0;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodJob INTO Tmp FROM JOBLISTE WHERE CodJob = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  FOR V_REC IN (
    SELECT U.job_name ,JF.TABLA,J1.CODJOB1
    FROM JOBLISTE1 J1
      INNER JOIN  USER_SCHEDULER_JOBS U ON TO_CHAR(J1.CODJOB1) = U.comments
      INNER JOIN  JOBLISTEFIN JF ON JF.CODJOB1 = J1.CODJOB1
    WHERE J1.CODJOB = RECID
  ) LOOP
    BEGIN
      DBMS_SCHEDULER.DROP_JOB(V_REC.JOB_NAME,TRUE);
      --EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||V_REC.TABLA;
      --DELETE FROM JOBLISTEFIN WHERE CODJOB1 = V_REC.CODJOB1;
      DELETE FROM VARIABILE_SESIUNE WHERE CODJOB1 = V_REC.CODJOB1;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END LOOP;

  SP_LOCKRECORD(RecId);
  DELETE FROM JOBLISTECONFIG WHERE CodJob1  IN (SELECT codJob1  FROM JobListe1 WHERE CodJob = RecId);
  DELETE FROM JOBCORELREZ    WHERE CodCorel IN (SELECT codCorel FROM JobCorel  WHERE CodJob = RecId);
  DELETE FROM LISTCOLS       WHERE CodJob1  IN (SELECT codJob1  FROM JobListe1 WHERE CodJob = RecId);
  DELETE FROM JOBLISTE1      WHERE CodJob = RecId ;
  DELETE FROM JOBCOREL       WHERE CodJob = RecId ;
  DELETE FROM JOBLISTE       WHERE CodJob = RecId ;

  NotifyModif(2, RecId, &apos;JOBLISTE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_JOBLISTE FIELDS( CodJob ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aTipJob number;
BEGIN
  INSERT INTO TMP_JOBLISTE ( CodJob, UserID, Denumire,Codorar,SUBUNITATEA, TIPJOB, NEWDEPO, WEBSERVER )
  SELECT CodJob, UserID, Denumire,Codorar, SUBUNITATEA, TIPJOB, NEWDEPO, WEBSERVER
  FROM JOBLISTE WHERE CodJob = RecId;
  SELECT TIPJOB into aTipJob FROM JOBLISTE WHERE CodJob = RecId;

  INSERT INTO TMP_JOBLISTE1 (
    Codjob1, CodJob, ListaID, ListaVer, TipExecutie, DataExecutie, Perioada, Executata, Printare, Action,
    OraExecutie, Den_Lista,Fisier_Export, export,obs,email,
    activ,areconfig,Tabla,tipinterval )
  SELECT 
    J1.Codjob1, J1.CodJob, J1.ListaID, J1.ListaVer, J1.TipExecutie, J1.DataExecutie, J1.Perioada, J1.Executata, J1.PRINTARE, J1.ACTION,
    To_Char(J1.DataExecutie, &apos;hh24:mi&apos;), L.NAME,j1.fisier_export , j1.export,j1.obs,j1.email,
    Case when aTipJob = 1 then J1.Activ  else decode(X.ENABLED,&apos;TRUE&apos;,1,&apos;FALSE&apos;,0) end ACTIV, areconfig,j1.Tabla,j1.tipinterval
  FROM JOBLISTE1 J1
    INNER JOIN WINMADMIN.LISTS L ON J1.LISTAID = L.LISTID AND J1.LISTAVER = L.LISTVER
    LEFT JOIN USER_SCHEDULER_JOBS X ON X.comments = TO_CHAR(J1.CODJOB1)
  WHERE CodJob = RecId;

  INSERT INTO TMP_JOBCOREL ( 
    CODCOREL, CODJOB,
    CodJob1_1, TABLA1, LookupField1, ValDescrip1,
    CodJob1_2, TABLA2, LookupField2, ValDescrip2,
    Zecimale, Stare, LookupField11, LookupField21,
    DEN_LISTA1, DEN_LISTA2
  ) 
  SELECT
    C.CODCOREL, C.CODJOB,
    C.CodJob1_1, C.TABLA1, C.LookupField1, C.ValDescrip1,
    C.CodJob1_2, C.TABLA2, C.LookupField2, C.ValDescrip2,
    Zecimale, Stare, LookupField11, LookupField21,
    J1_1.DEN_LISTA, J1_2.DEN_LISTA
  FROM JOBCOREL C
    INNER JOIN Tmp_Jobliste1 J1_1 ON J1_1.CodJob1 = C.Codjob1_1
    INNER JOIN Tmp_Jobliste1 J1_2 ON J1_2.CodJob1 = C.Codjob1_2
  WHERE C.CodJob = RecId;

  INSERT INTO TMP_JOBCORELREZ (CodCorelREZ, CodCorel, IDENTIFICATOR, Valoare1, Valoare2, Diferenta)
  SELECT CodCorelREZ, CodCorel, IDENTIFICATOR, Valoare1, Valoare2, Valoare1 - Valoare2
  FROM JOBCORELREZ
  WHERE CodCorel IN (SELECT CodCorel FROM TMP_JOBCOREL);

  FOR v_rec in (
    SELECT codJob1, &apos;JLIST&apos;||codJob1 job_name FROM TMP_JOBLISTE1
  ) loop
    insert into TMP_SCHEDULER (CODJOB1, JOB_ACTION)
    select V_Rec.CODJOB1, JOB_ACTION from ALL_SCHEDULER_JOBS where job_name=v_rec.job_name and upper(owner) = upper(PKG_GLOBALS.FIRMANAME);

    insert into TMP_VARIABILE (CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
    select CODJOB1,SQL_EXEC,TIP_SQL,ORDINE from Variabile_Sesiune where Codjob1=v_rec.CodJob1;
  END LOOP;

  COMMIT;
END;

PROCEDURE CLEAR_ONE_JOB(ACODJOB1 IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN (
    SELECT U.job_name ,JF.TABLA,J1.CODJOB1
    FROM JOBLISTE1 J1
      INNER JOIN USER_SCHEDULER_JOBS U ON TO_CHAR(J1.CODJOB1) = nvl(U.comments,&apos;0&apos;)
      INNER JOIN JOBLISTEFIN JF ON JF.CODJOB1 = J1.CODJOB1
  ) LOOP
    IF V_REC.CODJOB1 = ACODJOB1 THEN
      BEGIN
        DBMS_SCHEDULER.DROP_job(V_REC.JOB_NAME,TRUE);
        DELETE FROM VARIABILE_SESIUNE WHERE CODJOB1 = V_REC.CODJOB1;
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod number(20);
BEGIN
  IF Operation = 0 THEN

    SELECT CodJob INTO RecId FROM TMP_JOBLISTE;
    UPDATE JOBLISTE
    SET ( Denumire,Codorar, UserID, Subunitatea, NEWDEPO, WEBSERVER ) = ( SELECT Denumire,Codorar, UserID, Subunitatea, NEWDEPO, WEBSERVER FROM TMP_JOBLISTE )
    WHERE CodJob = RecId ;

    FOR V_REC IN ( SELECT * FROM JOBLISTE1 where CodJob = RecId and CodJob1 not in (Select CodJob1 from TMP_JOBLISTE1) ) LOOP
      CLEAR_ONE_JOB(V_REC.CODJOB1);
      DELETE FROM JOBLISTE1 WHERE CODJOB1 = V_REC.CODJOB1;
      DELETE FROM LISTCOLS  WHERE CODJOB1 = V_REC.CODJOB1;
    END LOOP;

    DELETE FROM JOBCOREL where CodJob = RecId and CodCOREL not in (Select CodCOREL from TMP_JOBCOREL) ;

    FOR v_rec IN ( SELECT * FROM TMP_JOBLISTE1 ORDER BY CodJob1 ) LOOP
      IF NVL(V_REC. CodJob1,-1)  &lt; 0 THEN
        select seq_jobliste1_codjob1.Nextval into vCod from dual;

        INSERT INTO JOBLISTE1 ( CodJob1, CodJob, ListaID, ListaVer, TipExecutie, DataExecutie, Perioada, Executata, Printare, Action,Fisier_Export,Export,obs,email, activ,areconfig,Tabla,tipinterval )
        VALUES ( vCod, RecID, V_Rec.ListaID, V_Rec.ListaVer, V_Rec.TipExecutie, To_Date(To_Char(V_Rec.DataExecutie, &apos;DD.MM.YYYY&apos;)||&apos; &apos;||V_Rec.OraExecutie, &apos;DD.MM.YYYY HH24:MI:SS&apos;), V_Rec.Perioada, V_Rec.Executata, V_Rec.Printare, V_Rec.Action,V_Rec.fisier_export,V_Rec.Export,V_Rec.obs,V_REC.email, V_Rec.activ,V_Rec.areconfig,V_Rec.Tabla,V_Rec.tipinterval);

        UPDATE tmp_JobCorel SET CodJob1_1 = vCod WHERE CodJob1_1 = v_rec.CodJob1;
        UPDATE tmp_JobCorel SET CodJob1_2 = vCod WHERE CodJob1_2 = v_rec.CodJob1;
      ELSE
        UPDATE JOBLISTE1
        SET
          ListaID       = v_rec.ListaID,
          ListaVer      = v_rec.ListaVer,
          TipExecutie   = v_rec.TipExecutie,
          DataExecutie  = To_Date(To_Char(v_rec.DataExecutie, &apos;DD.MM.YYYY&apos;)||&apos; &apos;||v_rec.OraExecutie||&apos;:00&apos;, &apos;DD.MM.YYYY HH24:MI:SS&apos;),
          Perioada      = v_rec.Perioada,
          Executata     = v_rec.Executata,
          Printare      = v_rec.Printare,
          Action        = v_rec.Action,
          fisier_export = v_rec.fisier_export,
          export        = v_rec.export,
          obs           = v_rec.obs,
					email         = v_rec.email,
          activ         = v_rec.activ,
          areconfig     = v_rec.areconfig,
          Tabla         = v_rec.Tabla,
          tipinterval   = v_rec.tipinterval
        WHERE CodJob1  = v_rec.CodJob1;
      END IF;
    END LOOP;

    INSERT INTO JOBCOREL (
      CODCOREL, CODJOB,
      CodJob1_1, TABLA1, LookupField1, ValDescrip1,
      CodJob1_2, TABLA2, LookupField2, ValDescrip2,
      Zecimale, Stare, LookupField11, LookupField21)
    SELECT
      SEQ_JOBCOREL_CODCOREL.Nextval , RecId ,
      CodJob1_1, TABLA1, LookupField1, ValDescrip1,
      CodJob1_2, TABLA2, LookupField2, ValDescrip2,
      Zecimale, Stare, LookupField11, LookupField21
    FROM TMP_JOBCOREL
    WHERE CodCorel &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_JOBCOREL WHERE NVL(CodCOREL,-1) &gt; 0 ORDER BY CodCOREL ) LOOP
      UPDATE JOBCOREL
      SET
        CodJob1_1        = v_rec.CodJob1_1       ,
        TABLA1           = v_rec.TABLA1          ,
        LookupField1     = v_rec.LookupField1    ,
        LookupField11    = v_rec.LookupField11   ,
        ValDescrip1      = v_rec.ValDescrip1     ,
        CodJob1_2        = v_rec.CodJob1_2       ,
        TABLA2           = v_rec.TABLA2          ,
        LookupField2     = v_rec.LookupField2    ,
        LookupField21    = v_rec.LookupField21   ,
        ValDescrip2      = v_rec.ValDescrip2     ,
        Zecimale         = v_rec.Zecimale        ,
        Stare            = v_rec.Stare
      WHERE CodCOREL  = v_rec.CodCOREL;
    END LOOP;

  ELSE
    SELECT seq_jobliste_codjob.NextVal INTO RecId FROM DUAL;

    INSERT INTO JOBLISTE ( CodJob, UserID, Denumire,Codorar,SUBUNITATEA, TIPJOB, NEWDEPO, WEBSERVER )
    SELECT  RecId, Nvl(UserID, pkg_globals.GETUSERID), Denumire,Codorar,SUBUNITATEA, TIPJOB, NEWDEPO, WEBSERVER
    FROM TMP_JOBLISTE;

    FOR v_Rec in (select * from tmp_JOBLISTE1) LOOP
      select seq_jobliste1_codjob1.Nextval into vCod from dual;
      INSERT INTO JOBLISTE1 ( CodJob1, CodJob, ListaID, ListaVer, TipExecutie, DataExecutie, Perioada, Executata, Printare, Action,Fisier_Export,Export,obs,email,activ,areconfig,Tabla,tipinterval )
      VALUES
      ( vCod, RecID, V_Rec.ListaID, V_Rec.ListaVer, V_Rec.TipExecutie, To_Date(To_Char(V_Rec.DataExecutie, &apos;DD.MM.YYYY&apos;)||&apos; &apos;||V_Rec.OraExecutie, &apos;DD.MM.YYYY HH24:MI:SS&apos;), V_Rec.Perioada, V_Rec.Executata, V_Rec.Printare, V_Rec.Action,V_Rec.fisier_export,V_Rec.Export,V_Rec.obs,V_Rec.email,V_Rec.activ,V_Rec.areconfig,V_Rec.Tabla,V_Rec.tipinterval);
      update tmp_JobCorel set CodJob1_1 = vCod where CodJob1_1 = v_rec.CodJob1;
      update tmp_JobCorel set CodJob1_2 = vCod where CodJob1_2 = v_rec.CodJob1;
    END LOOP;

    INSERT INTO JOBCOREL(
      CODCOREL, CODJOB,
      CodJob1_1, TABLA1, LookupField1, ValDescrip1,
      CodJob1_2, TABLA2, LookupField2, ValDescrip2, Zecimale, Stare, LookupField11, LookupField21)
    SELECT
      SEQ_JOBCOREL_CODCOREL.Nextval , RecId ,
      CodJob1_1, TABLA1, LookupField1, ValDescrip1,
      CodJob1_2, TABLA2, LookupField2, ValDescrip2, Zecimale, Stare, LookupField11, LookupField21
    FROM TMP_JOBCOREL;
  END IF;

  NotifyModif(Operation, RecId, &apos;JOBLISTE&apos;);
  COMMIT;

  SELECT TIPJOB INTO gTipJob FROM TMP_JOBLISTE;
  IF GTIPJOB = 0
  THEN ACTJOBS(RECID);
  END IF;
END;

PROCEDURE SAVELISTACONFIG IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  JOBLISTECONFIG WHERE CODJOB1 IN (SELECT CODJOB1 FROM TMP_JOBLISTECONFIG);

  INSERT INTO JOBLISTECONFIG(CODJOBCONFIG,CODJOB1,FILENAME,FILECONFIG)
  SELECT CODJOBCONFIG,CODJOB1,FILENAME,FILECONFIG FROM TMP_JOBLISTECONFIG;

  COMMIT;
END;

PROCEDURE LOADLISTACONFIG(aCodJob1 number) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM TMP_JOBLISTECONFIG;
  INSERT INTO TMP_JOBLISTECONFIG(CODJOBCONFIG,CODJOB1,FILENAME,FILECONFIG)
  SELECT CODJOBCONFIG,CODJOB1,FILENAME,FILECONFIG FROM JOBLISTECONFIG WHERE CODJOB1 = aCodJob1;
  COMMIT;
END;

PROCEDURE ACTJOBS(ACODJOB IN NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  IDX NUMBER(20);
BEGIN
  FOR V_REC IN (
    SELECT J1.CODJOB1,O.CODORAR ,j1.activ
    FROM JOBLISTE1 J1
      INNER JOIN JOBLISTE J ON J1.CODJOB = J.CODJOB
      INNER JOIN ORAR O  ON O.CODORAR = J.CODORAR
    WHERE j1.CODJOB = ACODJOB
  ) LOOP
    PKG_ORA_LISTS.SET_JOB(V_REC.CODORAR, V_REC.CODJOB1,(v_rec.activ = 1) );
  END LOOP;
END;

PROCEDURE RULEAZA_SET(ACODJOB IN NUMBER) IS
BEGIN
  FOR V_REC IN (
    SELECT U.job_name
    FROM JOBLISTE1 J1 INNER JOIN USER_SCHEDULER_JOBS U ON TO_CHAR(J1.CODJOB1) = U.comments
    WHERE J1.CODJOB = ACODJOB
  ) LOOP
    DBMS_SCHEDULER.run_job(V_REC.JOB_NAME,FALSE);
  END LOOP;
END;

PROCEDURE RULEAZA_SET_SINCRON(ACODJOB IN NUMBER) IS
BEGIN
  FOR V_REC IN (
    SELECT U.job_name
    FROM JOBLISTE1 J1 INNER JOIN USER_SCHEDULER_JOBS U ON TO_CHAR(J1.CODJOB1) = U.comments
    WHERE J1.CODJOB = ACODJOB
  ) LOOP
    DBMS_SCHEDULER.run_job(V_REC.JOB_NAME, TRUE);
  END LOOP;
END;

PROCEDURE MUTAINDEPO(ACODJOBLISTEFIN IN NUMBER, ADEPONAME IN VARCHAR2) IS
BEGIN
  /*INSERT INTO DATAWAREHOUSE(COD,CODJOB1,TABLA,SUBUNITATEA,SKEMAFIRMA,LISTANAME,DATAGEN,TABLE_TYPE,DEPONAME)
  SELECT SEQ_DATAWAREHOUSE_COD.NEXTVAL,CODJOB1,TABLA,SUBUNITATEA,SKEMAFIRMA,LISTANAME,DATAGEN,TABLE_TYPE,ADEPONAME
  FROM JOBLISTEFIN WHERE CODJOBLISTEFIN = ACODJOBLISTEFIN;

  DELETE FROM JOBLISTEFIN WHERE CODJOBLISTEFIN = ACODJOBLISTEFIN;*/
  UPDATE JOBLISTEFIN
  SET
    TIPDEPO = 1,
    DEPONAME = ADEPONAME
  WHERE CODJOBLISTEFIN = ACODJOBLISTEFIN;
  COMMIT;
END;

end pkg_jobliste;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_JUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>577326CB4F8EE7F884745730F5396D439B299512</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_JUDET IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codjudet INTO Tmp FROM NJUDET WHERE codjudet = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NJUDET WHERE codjudet = RecId ;
  NotifyModif(2, RecId, &apos;NJUDET&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NJUDET FIELDS( codjudet ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NJUDET
  INSERT INTO  TMP_NJUDET ( codjudet,den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM )
    ( SELECT codjudet,den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM
      FROM NJUDET WHERE codjudet = RecId ) ;

  COMMIT;

END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NJUDET
    SELECT  codjudet INTO RecId FROM TMP_NJUDET;
    UPDATE NJUDET SET ( den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM )
       = ( SELECT den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM
          FROM TMP_NJUDET )
      WHERE codjudet = RecId ;

  ELSE  -- INSERT
-- Master NJUDET
  SELECT seq_NJUDET_codjudet.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NJUDET ( codjudet,den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM )
 ( SELECT  RecId ,den_judet,simbauto,obs,codtara,REGCOM,CODDRP,DENDRP,JS,ITM
     FROM TMP_NJUDET  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;NJUDET&apos;);
  COMMIT;
END;



END pkg_Judet; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23574BC32EB11B0F65947F68EAE7317DD7E4EC7C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_JURNAL IS

PROCEDURE CHECK_NESTJURNAL IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN (
    SELECT J.*, NJ.CODNESTJURNAL
    FROM (
      SELECT DISTINCT CONTD A,CONTC B, coalesce(GEST,0) CODGEST, coalesce(CODCENTRU,0) CODCENTRU
      FROM jurnal
      WHERE (An*12+Luna = PKG_GLOBALS.AnLunaLucru) or (An*12+Luna = PKG_GLOBALS.AnLunaLucru-1)
      UNION
      SELECT DISTINCT CONTC A,CONTD B, coalesce(GEST,0) CODGEST, coalesce(CODCENTRU,0) CODCENTRU
      FROM jurnal
      WHERE (An*12+Luna = PKG_GLOBALS.AnLunaLucru) or (An*12+Luna = PKG_GLOBALS.AnLunaLucru-1)
    ) J LEFT OUTER JOIN NESTJURNAL NJ ON NJ.CODCONTD = J.A AND NJ.CODCONTC = J.B AND NJ.CODGEST = J.CODGEST AND NJ.CODCENTRU = J.CODCENTRU
    WHERE NJ.CODNESTJURNAL IS NULL
  ) LOOP
    INSERT INTO NestJurnal (Codnestjurnal, Codcontd, Codcontc, Codgest, Codcentru)
    VALUES (seq_nestjurnal_codnestjurnal.NextVal, V_REC.A, V_REC.B, V_REC.Codgest, V_REC.Codcentru);
  END LOOP;
  COMMIT;
END;

function CodNestJurnal(aCodContD in number, aCodContC in number, aCodGest in number, aCodCentru in number) return number is
aCount number(10);
aCod number(20);
begin
  select count(*) into aCount from nestjurnal
  where CodContC = aCodContC and CodContD = aCodContD and CodGest = aCodGest and CodCentru = aCodCentru;

  if aCount = 0 then
	  aCod := 0;
  else
    select CodNestJurnal into aCod from nestjurnal
    where CodContC = aCodContC and CodContD = aCodContD and CodGest = aCodGest and CodCentru = aCodCentru;
  end if;

  return aCod;
end;

function GetCodNestJurnal(aCodContD in number, aCodContC in number, aCodGest in number, aCodCentru in number) return number is
aCount number(10);
aCod number(20);
begin
  select count(*) into aCount from nestjurnal
  where CodContC = aCodContC and CodContD = aCodContD and CodGest = aCodGest and CodCentru = aCodCentru;

  if aCount = 0 then
    select seq_nestjurnal_codnestjurnal.NextVal into aCod from dual;
    insert into NestJurnal (Codnestjurnal, Codcontd, Codcontc, Codgest, Codcentru)
    values (aCod, aCodContD, aCodContC, aCodGest, aCodCentru);
  else
    select CodNestJurnal into aCod from nestjurnal
    where CodContC = aCodContC and CodContD = aCodContD and CodGest = aCodGest and CodCentru = aCodCentru;
  end if;

  return aCod;
end;

function TestDirtyTransfer(aTipDoc in number, aCodDoc in number, aCodNirStoc in number) return number is
iResult number(20) := 0;
newpret number(20,7);
begin
  for v_rec in (select  codNirStoc, pret, adaos
                from NirStoc NS, NIR N
                where
                  ns.codnirstocParinte = aCodnirstoc
                  and N.codNIR = NS.codNIR
                  and N.CodTransf = aCodDoc
                  and N.TipNIR = aTipDoc
                )loop
    iResult := TestDirtyLivrari(v_rec.CodNirStoc, 0);
    if iResult &lt;&gt; 0 then  -- nu poate modifica, adica trebuie break fortat
      RETURN iResult;
    end if;
 end loop;
 RETURN iResult;
end;

function TestDirtyLivrari(aCodNirStoc in number, SchimbIOArt in number) return number is
iResult number(20) := 0;
anLunaCurent number(20);
aCount number;
begin
  select count(*) into aCount from manevra_unic where codunic = acodnirstoc;
  if aCount = 1 then
    select userid into iresult from manevra_unic where codunic = acodnirstoc;
    return iresult;
  end if;
  select ancurent*12+lunacurenta into anLunaCurent from firmaluni;
  for v_rec in (select DISTINCT coalesce(ies.codies,coalesce(intr.codintr,tr.codtransf)) coddoc,
                       l.tiplivr tipdoc,
                       coalesce(ies.an,coalesce(intr.an,tr.an)) an,
                       coalesce(ies.luna,coalesce(intr.luna,tr.luna)) luna
                from livr1 l1 inner join livr l on l.codlivr = l1.codlivr
                              left join iesiri ies on ies.codies = l.codies
                              left join intrari intr on intr.codintr = l.codintr
                              left join transf tr on l.codtransf = tr.codtransf
                where l1.codnirstoc = aCodnirstoc
                ) loop
  if (v_rec.an * 12 + v_rec.luna &gt;= anLunaCurent) then
    if v_rec.tipdoc in (1,2,3,4,5,7,14,15,16,19,20,21,22,23,24) then
      iResult := 0;
      insert into manevra_unic(codunic,userid) values(acodnirstoc,0);
    else
      if (SchimbIOArt = 0) and (v_rec.tipdoc in (12,13)) then
        iResult := TestDirtyTransfer(v_rec.tipdoc, v_rec.coddoc, aCodNirStoc);
        insert into manevra_unic(codunic,userid) values(acodnirstoc,iresult);
      else
        iResult := v_rec.tipdoc;
        insert into manevra_unic(codunic,userid) values(acodnirstoc,iresult);
        RETURN iResult;
      end if;
    end if;
  else
    iResult := -1;
    insert into manevra_unic(codunic,userid) values(acodnirstoc,iresult);
    RETURN iResult;
  end if;
 end loop;
 RETURN iResult;
end;

function TestDirtyNirStoc(aCodNirStoc in number, SchimbIOArt in number) return number is
iResult number(20) := 0;
begin
  iResult := TestDirtyLivrari(aCodNirStoc, SchimbIOArt);
  if iResult &lt;&gt; 0 then
    RETURN iResult;
  end if;
  RETURN iResult;
end;

function TestDirtyIntrAE(aCodLinieAE in number) return number is
iResult number(20) := 0;
anLunaCurent number(20);
anLuna       number(20);
CodDoc       number(20);
begin
  delete manevra_unic;
  select ancurent*12+lunacurenta into anLunaCurent from firmaluni;
  select i.an*12+i.luna, i.CodIntr into anLuna , CodDoc
  from intrari1 i1, intrari i
  where i1.Codintr1=aCodLinieAE and i.CodIntr = i1.CodIntr;

  if AnLuna &lt; anLunaCurent then
    iResult := -1;
    RETURN iResult;
  end if;

  for v_rec in  (select n.CodNirStoc from NirStoc n where n.Codintr1=aCodLinieAE)loop
    iResult := TestDirtyNirStoc(v_rec.CodNirStoc, 0);
    if iResult &lt;&gt; 0 then
      RETURN iResult;
    end if;
  end loop;

  RETURN iResult;
end;

function TestDirtyIesAE(aCodLinieAE in number) return number is
iResult number(20) := 0;
anLunaCurent number(20);
anLuna       number(20);
CodDoc       number(20);
AECust       number(2);
begin
  select ancurent*12+lunacurenta into anLunaCurent from firmaluni;
  select i.an*12+i.luna, i.CodIes, i.custodie into anLuna , CodDoc, AECust
  from iesiri1 i1, iesiri i
  where i1.CodIes1=aCodLinieAE and i.CodIes = i1.CodIes;

  if (coalesce(AECust,0) = 0)and(AnLuna &lt; anLunaCurent) then
    iResult := -1;
    RETURN iResult;
  end if;
  RETURN iResult;
END;

PROCEDURE SET_SKIPUPDATEJURNFLAG(aFLAG IN NUMBER) IS
BEGIN
  glb_SkipUpdateJurn := aFLAG;
END;

procedure SetDirty(acoddoc in number, atipdoc in number, aSubunitatea in number, aAn in number, aLuna in number) is
  nr number(20);
  xCODDOC number(20);
begin
  BEGIN
    SELECT CODDOC INTO xCODDOC FROM TMP_JURNAL_MAN WHERE CODDOC = aCODDOC;
    EXCEPTION WHEN OTHERS THEN xCODDOC := 0;
  END;

  IF xCODDOC = 0 THEN
      INSERT INTO TMP_JURNAL_MAN (coddoc, tipdoc, SUBUNITATEA, AN, LUNA) VALUES (acoddoc, atipdoc, aSUBUNITATEA, aAN, aLUNA);

      IF glb_SkipUpdateJurn = 0 THEN

          Select COUNT(*) into nr from jurnal1 where  coddoc = acoddoc and tipdoc = atipdoc;

          if NR &gt; 0 then
            update jurnal1 set dirty = 1 where coddoc = acoddoc and tipdoc = atipdoc;
          else
            INSERT INTO JURNAL
                         (CODJURNAL, CODDOC,  TIPDOC, INDEXLOCAL, SUBUNITATEA,  AN,  LUNA)
                   VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, aCodDoc, aTipDoc, 0, aSUBUNITATEA, aAn, aLuna);
            INSERT INTO JURNAL1
                         (CODJURNAL1, CODDOC,  TIPDOC, INDEXLOCAL, SUBUNITATEA,  AN,  LUNA, Dirty)
                   VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, aCodDoc, aTipDoc, 0,         aSUBUNITATEA, aAn, aLuna, 1);
          end if;
       END IF;
  END IF;
end;

procedure setDirtyTransfer(aTipDoc in number, aCodDoc in number, aCodNirStoc in number, aPret in number, UrmarirePUVAl in varchar2, aPUVAL IN NUMBER) is
newpret   number(20, 7);
aadaos     number(20, 7);
aCant     number(20, 7);
aVal      number(20, 7);
aSupl     number(20, 7);
aOldPret  number(20, 7);
anewpretTransf1  number(20, 7);
aTIPMODIFPRET NUMBER(20, 0) := 0;
OLDPRETACHIZ NUMBER := 0;
NEWADAOS     NUMBER := 0;
PRETINREG_PARINTE    number(20, 7) := 0;
ADAOS_PARINTE        number(20, 7) := 0;
PRETACHIZ_PARINTE    number(20, 7) := 0;
TEMP                 NUMBER := 0;
begin

  SELECT CODTRANSF INTO TEMP FROM TRANSF WHERE CODTRANSF = aCODDOC FOR UPDATE NOWAIT;



  for v_rec in (select  NS.codNirStoc, NS.pret, NS.adaos,  NS.SUPLIMENT,  NS.CantNIR, NS.Codtransf1, NS.TVA,
                         PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
 --                        7- coalesce(NS.Rotlei, 0) RotLei
                from NirStoc NS, NIR N
                where
                  NS.CodNIRStocParinte = aCodnirstoc
                  and N.codNIR = NS.codNIR
                  and N.CodTransf = aCodDoc
                  and N.TipNIR = aTipDoc
                )loop
    aSupl   := 0;

    if v_rec.cantNIR &lt;&gt; 0 then aSupl   := coalesce(v_rec.Supliment, 0) / v_rec.cantNIR; end if;

    BEGIN
      SELECT coalesce(TIPMODIFPRET, 0) INTO aTIPMODIFPRET FROM TRANSF WHERE CODTRANSF = aCODDOC;
      EXCEPTION WHEN OTHERS THEN aTIPMODIFPRET := 0;
    END;



     BEGIN
        SELECT coalesce(PRET,0),  coalesce(ADAOS, 0) INTO PRETINREG_PARINTE, ADAOS_PARINTE FROM NIRSTOC WHERE CODNIRSTOC = aCODNIRSTOC;
        EXCEPTION WHEN OTHERS THEN PRETINREG_PARINTE := 0; ADAOS_PARINTE := 0;
     END;

    IF aTIPDOC = 13  THEN

      PRETACHIZ_PARINTE :=  PRETINREG_PARINTE - ADAOS_PARINTE;
      IF aTIPMODIFPRET = 0 THEN
         UPDATE
           NIRSTOC
         SET
           ADAOS = PRET - PRETACHIZ_PARINTE
         WHERE
           CODNIRSTOC = V_REC.CODNIRSTOC;

        SELECT coalesce(PRET, 0) INTO NEWPRET FROM NIRSTOC WHERE  CODNIRSTOC = V_REC.CODNIRSTOC;

      END IF;


      IF aTIPMODIFPRET = 2 THEN
         NEWPRET   := V_REC.PRET;
         NEWADAOS  := NEWPRET - PRETACHIZ_PARINTE;
         IF NEWADAOS &lt; 0 THEN
           NEWADAOS := NEWPRET - NEWPRET * 100/(100 + coalesce(V_REC.TVA, 0) * 100) ;
         END IF;


         UPDATE
           NIRSTOC
         SET
           PRET  = NEWPRET,
           ADAOS = NEWADAOS
         WHERE
           CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;


      IF aTIPMODIFPRET = 3 THEN
         OLDPRETACHIZ := coalesce(V_REC.PRET, 0) - coalesce(V_REC.ADAOS, 0);
         NEWADAOS     := PRETINREG_PARINTE - OLDPRETACHIZ;

         UPDATE
           NIRSTOC
         SET
           PRET  = PRETINREG_PARINTE,
           ADAOS = NEWADAOS
         WHERE
           CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;


    ELSE
      aADAOS   := coalesce(V_REC.ADAOS, 0);
      IF aADAOS = 0 THEN
        NEWPRET := ROUND(APRET - ADAOS_PARINTE + aADAOS + ASUPL, V_REC.ROTLEI);
        UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      ELSE
        --PRETACHIZ_PARINTE :=  PRETINREG_PARINTE - ADAOS_PARINTE;
         aSupl := 0;
         IF V_REC.CANTNIR &lt;&gt; 0 THEN
           aSupl := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR;
         END IF;

         PRETACHIZ_PARINTE :=  PRETINREG_PARINTE - ADAOS_PARINTE + aSUPL;
        UPDATE NIRSTOC
        SET
         ADAOS = PRET - PRETACHIZ_PARINTE
        WHERE
          CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;

      SELECT coalesce(PRET, 0) INTO NEWPRET FROM NIRSTOC WHERE  CODNIRSTOC = V_REC.CODNIRSTOC;

    END IF;


    IF UrmarirePUVAl = &apos;1&apos; THEN
      update NIRSTOC set PUVAl = aPUVAL where CodNirStoc = v_rec.CodNirStoc;
    END IF;


/*
  mTransferintregestiuni         = 12;
*/
    if aTipdoc = 12 then
      select Sum(N.CANTFURN), Sum(N.CANTFURN * N.Pret) into aCant, aVal
      from NirStoc n
      where N.Codtransf1 = v_rec.Codtransf1;

      if aCant &lt;&gt; 0 then aNewPretTransf1 := ROUND(aVal / aCant, 6); else aNewPretTransf1 := 0; end if;

      select PU, Cant into aOldPret, aCant from Transf1  where Codtransf1 = v_rec.Codtransf1;
      update transf1 set PU = aNewPretTransf1 where Codtransf1 = v_rec.Codtransf1;
      update transf set ValDoc = ValDoc + (aNewPretTransf1 - aOldPret) * aCant where Codtransf = aCodDoc;
    end if;
--    insert into xxx (xxx, yyy, zzz, ooo) values (4, aCodDoc, atipdoc, &apos;update nirstoc transfer&apos;);


--    setDirtyNirStoc(v_rec.CodNirStoc, aPret);
    setDirtyNirStoc(v_rec.CodNirStoc, NewPret, UrmarirePUVAl, aPUVAL);
 end loop;
end;

procedure setDirtyNirStoc(aCodNirStoc in number, aPret in number, UrmarirePUVAl in varchar2, aPUVAL in number) is
aCant     number(20, 7);
aVal      number(20, 7);
NewPret   number(20, 7);
aOldPret  number(20, 7);
TEMP      NUMBER(20);
aPretMat  number(20,7);
begin
--  insert into xxx (xxx, yyy, zzz, ooo) values (3, acodnirstoc, aPret, &apos;setDirtyNirStoc(CodNirStoc, aPret&apos;);
  begin
    select coalesce(pret,0) - coalesce(adaos,0) into aPretMat from nirstoc where codnirstoc = aCodNirstoc;
  exception when others then aPretMat := 0;
  end;
  update nirstoc1 set pretmat = aPretMat where codnirstoc = aCodNirStoc;
  for v_rec in (select coalesce(ies.codies,coalesce(intr.codintr,tr.codtransf)) coddoc,
                       coalesce(ies.Subunitatea,coalesce(intr.Subunitatea,tr.Subunitatea)) Subunitatea,
                       coalesce(ies.An,coalesce(intr.An,tr.An)) An,
                       coalesce(ies.Luna,coalesce(intr.Luna,tr.Luna)) Luna,
                       l.tiplivr tipdoc,
                       l1.CODIES1,
                       L1.CANT,
                       coalesce(IES.TIPTRANZACTIE, 0) AS TIPTRANZACTIE
                from livr1 l1 inner join livr l on l.codlivr = l1.codlivr
                              left join iesiri ies on ies.codies = l.codies
                              left join intrari intr on intr.codintr = l.codintr
                              left join transf tr on l.codtransf = tr.codtransf
                where l1.codnirstoc = aCodnirstoc
                )loop



  if v_rec.tipdoc in (1, 2, 3, 4, 5, 7, 14, 15, 16, 19, 20, 21, 22, 23, 24) then
--    insert into xxx (xxx, yyy, zzz, ooo) values (3, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty 1..11, 14..24&apos;);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);


     IF V_REC.TIPDOC = 20 THEN
       FOR V_REC_FACTAVIZ IN (
       SELECT DISTINCT IFACT.CODIES, IFACT.SUBUNITATEA, IFACT.AN, IFACT.LUNA
       FROM
         IESIRI IFACT,
         IESIRI1 I1FACT,
         IESLINK IL,
         IESIRI1 I1AE
       WHERE
         I1AE.CODIES         = V_REC.CODDOC
         AND I1AE.CODIES1    = IL.CODLINIEAVIZ
         AND IL.CODIES1      = I1FACT.CODIES1
         AND I1FACT.CODIES   = IFACT.CODIES
         AND IFACT.TIPDOC    = 26
        )
        LOOP
          SetDirty(v_rec_FACTAVIZ.CODIES, 26, v_rec_FACTAVIZ.Subunitatea, v_rec_FACTAVIZ.An, v_rec_FACTAVIZ.Luna);
        END LOOP;
     END IF;

    IF V_REC.TIPDOC = 15 and V_REC.TIPTRANZACTIE  = 2 AND V_REC.CANT &lt; 0 THEN
    FOR V_REC_STORNO IN
      (
        SELECT
          L1_MINUS.CODNIRSTOC CODNIRSTOCVECHI,
          L1_PLUS.CODNIRSTOC AS CODNIRSTOCNOU,
          NS_MINUS.PRET AS PRETNOU,
          NS_MINUS.ADAOS AS ADAOSNOU,
          NS_MINUS.CODIOART,
          NS_MINUS.TVA
        FROM
          LIVR L,
          LIVR1 L1_MINUS,
          NIRSTOC NS_MINUS,
          LIVR1 L1_PLUS
        WHERE
          L.CODIES = V_REC.CODDOC
          AND L1_MINUS.CODLIVR    = L.CODLIVR
          AND L1_Minus.CANT       &lt; 0
          AND L1_PLUS.CODLIVR     = L.CODLIVR
          AND L1_PLUS.CANT        &gt; 0
          AND L1_PLUS.CODIES1     = L1_MINUS.CODIES1
          AND ABS(L1_MINUS.CANT)  = ABS(L1_PLUS.CANT)
          AND L1_MINUS.CODNIRSTOC = aCodNirStoc
          AND NS_MINUS.CODNIRSTOC = aCodNirStoc
      )
      LOOP
        UPDATE NIRSTOC
        SET
          PRET      = V_REC_STORNO.PRETNOU,
          ADAOS     = V_REC_STORNO.ADAOSNOU,
          CODIOART  = V_REC_STORNO.CODIOART,
          TVA       = V_REC_STORNO.TVA
        WHERE
          CODNIRSTOC = V_REC_STORNO.CODNIRSTOCNOU;


          setDirtyNirStoc(V_REC_STORNO.CODNIRSTOCNOU,
                          aPret,
                          UrmarirePUVAl,
                          aPUVAL
                         );
      END LOOP;
    END IF;

    if v_rec.Tipdoc in (14, 15, 23, 24) then
      select
         Sum(l1.Cant),
         Sum(l1.Cant*N.Pret) into aCant, aVal
      from
        Livr1 l1,
        NirStoc n,
        LIVR L
      where
        L1.CodIes1 = v_rec.Codies1
        and N.CODNIRSTOC = L1.Codnirstoc
        AND L.CODLIVR = L1.CODLIVR
        AND L.CODIES =V_REC.CODDOC;

      if aCant &lt;&gt; 0 then NewPret := Round(aVal / aCant,5); else NewPret := 0; end if;

      select PU, Cant into aOldPret, aCant from iesiri1  where CodIes1 = v_rec.CodIes1;
      update iesiri1
      set
        PU       = NewPret,
        PRETORIG = NEWPRET
      where
          CodIes1 = v_rec.CodIes1;

      update iesiri1 i1
      set
          RestIMBMF        = CASE
                                WHEN TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND coalesce(CODMIFIX, 0) &lt;&gt; 0
                                THEN Cant * PU -
                                  (SELECT coalesce(SUM(IL.CANT), 0)
                                   FROM
                                     IMBMIFIXLINK IL
                                     LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                                     LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                                   WHERE
                                     IL.CODIES1 = i1.CodIES1 AND T.OPERAT = 1 AND T.ANULAT = 0
                                  )
                                ELSE 0
                             END
      where
          CodIes1 = v_rec.CodIes1;

      SELECT CODIES INTO TEMP FROM IESIRI WHERE CODIES = V_REC.CODDOC FOR UPDATE NOWAIT;

     -- update Iesiri set ValDoc = ValDoc + (NewPret - aOldPret) * aCant where CodIes = v_rec.CodDoc;
      UPDATE IESIRI
      SET
        VALDOC = (SELECT SUM(PU * CANT) FROM IESIRI1 WHERE CODIES = V_REC.CODDOC)
      WHERE
         CODIES = V_REC.CODDOC;
    end if;
  else
    if v_rec.tipdoc in (12, 13) then
--      insert into xxx (xxx, yyy, zzz, ooo) values (3, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty 12,13&apos;);
      SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
      SetDirtyTransfer(v_rec.tipdoc, v_rec.coddoc, aCodNirStoc, aPret, UrmarirePUVAl, aPUVAL);
    end if;
  end if;
 end loop;
end;

procedure setDirtyIntrAE(aCodLinieAE in number, aCurs in number) is
  aCant     number(20, 7);
  aTVA      number(20, 7);
  aOldTVA   number(20, 7);
  aProcTVA  number(20, 7);
  aVal      number(20, 7);
  aPret     number(20, 7);
  aOldPret  number(20, 7);
  newpret   number(20, 7);
  aNewCurs  number(20, 7);
  aOldCurs  number(20, 7);
  aadaos     number(20, 7);
  DifVal    number(20, 7);
  DifTVA    number(20, 7);
  aSupl     number(20, 7);

  aCodObiect number(20);
  aCodDoc    number(20);
  aCODPART   number(20);

  aAn         number(5);
  aLuna       number(2);
  aTipTVA     number(2);
  aVALDOC     NUMBER(20, 7);
  aTVADOC     NUMBER(20, 7);
  aMONEDA     NUMBER(20);
  aCODGENERAL NUMBER(20);
  NR          number(5);
  aVALOBLIG   NUMBER(20, 7);
  aDATADOC    DATE;
  UrmarirePUVAL varchar2(10);

  VALSUPLIM   NUMBER(20, 7) := 0;
  VALTOT      NUMBER(20, 7) := 0;
  VS          NUMBER(20, 7) := 0;
  TIPSUPLIM   NUMBER(5) := 0;

  CursPUVAL   NUMBER(20, 7);
  aPUVAL      NUMBER(20, 7);
  aCF         VARCHAR2(30);
  NrStingeri  NUMBER(10);
BEGIN
--  insert into xxx (xxx, yyy, ooo) values (0, aCodLinieAE, &apos;setDirtyIntrAE=aCodLinieAE &apos;);
--calculez pret mediu

  Select Sum(coalesce(i1.Cant, 0)), sum(coalesce(i1.PU,0)*coalesce(i1.Cant, 0)),  count(*)   
  into 
    aCant, aVal, NrStingeri
  from intrlink k, Intrari i, Intrari1 i1
  where k.CodLinieAviz = aCodLinieAE
        and i1.Codintr1 = k.Codintr1
        and i.codintr = i1.codintr
        and i.Operat = 1;


  if NrStingeri = 0 then -- daca nu mai sunt stingeri las pretul de pe aviz
    RETURN;
  end if;   



  aPret := 0;
  if aCANT &lt;&gt; 0 then
    aPret := Round(aVal / aCant, 7);
  end if;
--  insert into xxx (xxx, yyy, ooo) values (1, aPret, &apos;pret mediu&apos;);
  for v_rec in
  (select
    i.CodIntr
    CodDoc,
    i.TipDoc,
    i.Subunitatea,
    i.An,
    i.Luna,
    I.PARTENER,
    I.DATADOC,
    I.VALSUPLIM,
    I.TIPREPSUPLIM,
    I.VALTRANSPORT,
    CF.CODFISCAL
  from
    Intrari1 i1,
    intrari i
    LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = I.CODFISCAL

  where i1.codintr1 = aCodLinieAE and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn   := v_rec.An;
    aLuna := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
    aCODPART := V_REC.PARTENER;
    aDATADOC := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0) + coalesce(V_REC.VALTRANSPORT, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);
    aCF       := coalesce(V_REC.CODFISCAL, &apos;?&apos;);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;

  -- update pret intrare pe aviz
  select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
  from intrari1 where CodIntr1 = aCodLinieAE;

  CursPUVAL := 1;
  SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
  IF UrmarirePUVAL = &apos;1&apos; THEN
    BEGIN
      CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                   pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                   pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                   TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                   );
    EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
    END;
  END IF;


  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aTIPTVA := &apos;0&apos;;
  END;
  if aTIPTVA = 1 OR INSTR(UPPER(aCF), &apos;RO&apos;) = 0 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := Round(aPret * aCant * aProcTVA / 100, 6);
  end if;


  update intrari1 I1
  set
    PU       = aPret,
    PRETORIG =  CASE
                  WHEN coalesce(I1.COEFDISCMAJ, 1) = 0 THEN aPRET
                  ELSE aPret / coalesce(I1.COEFDISCMAJ, 1)
                END,
    TVA = aTVA
  where
    CodIntr1 = aCodLinieAE;

  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := aCurs;
  select Curs into aOldCurs from Intrari where CodIntr = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

  UPDATE INTRARI I
  SET
    Curs   = aNewCurs,
    VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
    TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
  WHERE
    I.CODINTR = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 408;
  BEGIN
   SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0),  coalesce(PARTENER, 0)
   INTO
     aVALDOC, aTVADoc, aMONEDA, aCODPART
    FROM
      INTRARI
    WHERE
      CODINTR = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0; aCODPART := 0;
  END;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140;

  aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 2, aCODDOC, aMONEDA, aNewCurs, 140);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

  ELSE
    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 2 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
    END IF;

    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 2
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 140
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALOBLIG,
         REST    = aVALOBLIG
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aNewCurs
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;

  -- recalcul suplimente pe nirstoc
  SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
  FROM
  (
    SELECT
      CASE
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
      END AS VALLINIE
    FROM
      NIRSTOC NS,
      INTRARI1 I1,
      NIR N,
      INTRARI I,
      NARTOBJ O
    WHERE
      NS.CODNIR       = N.CODNIR
      AND N.CODINTR   = aCODDOC
      AND I1.CODINTR1 = NS.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND O.CODOBIECT = NS.CODOBIECT
  );

 FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
               FROM
                 NIRSTOC NS,
                 NIR N,
                 INTRARI1 I1,
                 NARTOBJ O
                 WHERE
                   NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                   AND I1.CODINTR1 = NS.CODINTR1
                   AND O.CODOBIECT = NS.CODOBIECT
             )
 LOOP
   VS := 0;
   IF VALTOT &lt;&gt; 0 THEN
       IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
       ELSE
       IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
       ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
       END IF;
       END IF;
    END IF;

     UPDATE NIRSTOC
     SET
      SUPLIMENT = VS
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
 END LOOP;

  FOR V_REC IN
  ( SELECT
      NS.CODNIRSTOC,
      NS.PRET,
      NS.ADAOS,
      NS.CANTNIR,
      NS.SUPLIMENT,
      I1.PU,
      PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
    FROM
      NIRSTOC NS,
      NIR NR,
      INTRARI1 I1
    WHERE
      NR.CODNIR      = NS.CODNIR
      AND NR.CODINTR = ACODDOC
      AND I1.CODINTR1 = NS.CODINTR1
   -- N.CODINTR1=ACODLINIEAE
  )
  LOOP
  -- pentru toate nirstoc DE PE AVIZ, propag pret nou din acel codnirstoc
    ASUPL   := 0;
    IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
    aADAOS   := coalesce(V_REC.ADAOS, 0);

    IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
    END IF;

    NEWPRET := ROUND(/*APRET*/V_REC.PU * aNEWCURS + aADAOS + ASUPL, V_REC.ROTLEI);

    UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF URMARIREPUVAL = 1 THEN
      APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
      UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;

--  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
    SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);
  END LOOP;
END;

procedure setDirtyIntrAE_Storno(aCodLinieAE in number, aPret in Number, aCurs in number) is
aCant     number(20, 7);
aTVA      number(20, 7);
aOldTVA   number(20, 7);
aProcTVA  number(20, 7);
aVal      number(20, 7);
aOldPret  number(20, 7);
newpret   number(20, 7);
aNewCurs  number(20, 7);
aOldCurs  number(20, 7);
aadaos     number(20, 7);
DifVal    number(20, 7);
DifTVA    number(20, 7);
aSupl     number(20, 7);

aCodObiect number(20);
aCodDoc    number(20);
aCODPART   number(20);

aAn         number(5);
aLuna       number(2);
aTipTVA     number(2);
aVALDOC     NUMBER(20, 7);
aTVADOC     NUMBER(20, 7);
aMONEDA     NUMBER(20);
aCODGENERAL NUMBER(20);
NR          number(5);
aVALOBLIG   NUMBER(20, 7);
aDATADOC    DATE;
UrmarirePUVAL varchar2(10);

VALSUPLIM   NUMBER(20, 7) := 0;
VALTOT      NUMBER(20, 7) := 0;
VS          NUMBER(20, 7) := 0;
TIPSUPLIM  NUMBER(5) := 0;

CursPUVAL   NUMBER(20, 7);
aPUVAL   NUMBER(20, 7);


begin
--  insert into xxx (xxx, yyy, ooo) values (1, aPret, &apos;pret mediu&apos;);
  for v_rec in
  (select i.CodIntr CodDoc, i.TipDoc, i.Subunitatea, i.An, i.Luna, I.PARTENER, I.DATADOC, I.VALSUPLIM, I.TIPREPSUPLIM, I.VALTRANSPORT
  from Intrari1 i1, intrari i
  where i1.codintr1 = aCodLinieAE and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn   := v_rec.An;
    aLuna := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
    aCODPART := V_REC.PARTENER;
    aDATADOC := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0) + coalesce(V_REC.VALTRANSPORT, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;

  -- update pret intrare pe aviz
  select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
  from intrari1 where CodIntr1 = aCodLinieAE;

  CursPUVAL := 1;
  SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
  IF UrmarirePUVAL = &apos;1&apos; THEN
    BEGIN
      CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                   pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                   pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                   TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                   );
    EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
    END;
  END IF;


  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aTIPTVA := &apos;0&apos;;
  END;
  if aTIPTVA = 1 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := Round(aPret * aCant * aProcTVA / 100, 6);
  end if;


  update intrari1
  set
    PU       = aPret,
    PRETORIG = aPret,
    TVA = aTVA
  where
    CodIntr1 = aCodLinieAE;

  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := aCurs;
  select Curs into aOldCurs from Intrari where CodIntr = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

  UPDATE INTRARI I
  SET
    Curs   = aNewCurs,
    VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
    TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
  WHERE
    I.CODINTR = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 408;
  BEGIN
   SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0),  coalesce(PARTENER, 0)
   INTO
     aVALDOC, aTVADoc, aMONEDA, aCODPART
    FROM
      INTRARI
    WHERE
      CODINTR = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0; aCODPART := 0;
  END;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140;

  aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 2, aCODDOC, aMONEDA, aNewCurs, 140);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

  ELSE

    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 2 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
    END IF;



    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 2
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 140
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALOBLIG,
         REST    = aVALOBLIG
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aNewCurs
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;

  -- recalcul suplimente pe nirstoc
  SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
  FROM
  (
    SELECT
      CASE
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
      END AS VALLINIE
    FROM
      NIRSTOC NS,
      INTRARI1 I1,
      NIR N,
      INTRARI I,
      NARTOBJ O
    WHERE
      NS.CODNIR       = N.CODNIR
      AND N.CODINTR   = aCODDOC
      AND I1.CODINTR1 = NS.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND O.CODOBIECT = NS.CODOBIECT
  );



 FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
               FROM
                 NIRSTOC NS,
                 NIR N,
                 INTRARI1 I1,
                 NARTOBJ O
                 WHERE
                   NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                   AND I1.CODINTR1 = NS.CODINTR1
                   AND O.CODOBIECT = NS.CODOBIECT
             )
 LOOP
   VS := 0;
   IF VALTOT &lt;&gt; 0 THEN
       IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
       ELSE
       IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
       ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
       END IF;
       END IF;
    END IF;

     UPDATE NIRSTOC
     SET
      SUPLIMENT = VS
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
 END LOOP;

  FOR V_REC IN
  ( SELECT
      NS.CODNIRSTOC,
      NS.PRET,
      NS.ADAOS,
      NS.CANTNIR,
      NS.SUPLIMENT,
      I1.PU,
      PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
    FROM
      NIRSTOC NS,
      NIR NR,
      INTRARI1 I1
    WHERE
      NR.CODNIR      = NS.CODNIR
      AND NR.CODINTR = ACODDOC
      AND I1.CODINTR1 = NS.CODINTR1
   -- N.CODINTR1=ACODLINIEAE
  )
  LOOP
  -- pentru toate nirstoc DE PE AVIZ, propag pret nou din acel codnirstoc
    ASUPL   := 0;
    IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
    aADAOS   := coalesce(V_REC.ADAOS, 0);

    IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
    END IF;

    NEWPRET := ROUND(/*APRET*/V_REC.PU * aNEWCURS + aADAOS + ASUPL, V_REC.ROTLEI);

    UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF URMARIREPUVAL = 1 THEN
      APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
      UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;

--  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
    SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);
  END LOOP;
END;

procedure setDirtyDVIAE(aCodLinieAE in number, aCurs in number) is
aCant     number(20, 7);
aTVA      number(20, 7);
aOldTVA   number(20, 7);
aProcTVA  number(20, 7);
aVal      number(20, 7);
aValV     number(20, 7);
aPret     number(20, 7);
aPretV    number(20, 7);
aOldPret  number(20, 7);
newpret   number(20, 7);
aOldCurs  number(20, 7);
aadaos     number(20, 7);
DifVal    number(20, 7);
DifTVA    number(20, 7);
aSupl     number(20, 7);

aCodObiect number(20);
aCodDoc    number(20);
aCodIntr   number(20);

aAn        number(5);
aLuna      number(2);
aTipTVA    number(2);
aVALDOC     NUMBER(20, 7);
aTVADOC     NUMBER(20, 7);
aMONEDA     NUMBER(20);
aCODPART    NUMBER(20);
aCODGENERAL NUMBER(20);
NR          number(5);
aVALOBLIG   NUMBER(20, 7);
aDATADOC    DATE;
UrmarirePUVAL varchar2(10);


VALSUPLIM   NUMBER(20, 7) := 0;
VALTOT      NUMBER(20, 7) := 0;
VS          NUMBER(20, 7) := 0;
TIPSUPLIM  NUMBER(5) := 0;


CursPUVAL   NUMBER(20, 7);
aPUVAL     NUMBER(20, 7);
aNEWCURS   NUMBER(20, 7);

TEMP       NUMBER(20, 0);


begin
  BEGIN
    SELECT CODINTR INTO aCODDOC FROM INTRARI1 where codintr1 = aCodLinieAE ;
    EXCEPTION WHEN OTHERS THEN aCODDOC := 0;
  END;

  SELECT CODINTR INTO TEMP FROM INTRARI WHERE CODINTR = aCODDOC FOR UPDATE NOWAIT;


--  insert into xxx (xxx, yyy, ooo) values (0, aCodLinieAE, &apos;setDirtyIntrAE=aCodLinieAE &apos;);
--calculez pret mediu
  Select Sum(coalesce(d1.Cant, 0)), sum(coalesce(d1.PretImport,0)*coalesce(d1.Cant, 0)), sum(coalesce(d1.PretImport/i.Curs,0)*coalesce(d1.Cant, 0))  into aCant, aVal, aValV
  from intrlink k, Intrari i, Intrari1 i1, DVI1 d1
  where k.CodLinieAviz  = aCodLinieAE
        and i1.Codintr1 = k.Codintr1
        and d1.Codintr1 = i1.Codintr1
        and i.codintr   = i1.codintr
        and i.Operat    = 1;

  aPret  := 0;
  aPretV := 0;
  if aCANT &lt;&gt; 0 then
    aPret  := Round(aVal  / aCant, 7);
    aPretV := Round(aValV / aCant, 7);
  end if;
--  insert into xxx (xxx, yyy, ooo) values (1, aPret, &apos;pret mediu&apos;);
  for v_rec in
  (select i.CodIntr CodDoc, i.TipDoc, i.Subunitatea, i.An, i.Luna, I.DATADOC, I.VALSUPLIM, I.TIPREPSUPLIM
  from Intrari1 i1, intrari i
  where i1.codintr1 = aCodLinieAE and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn   := v_rec.An;
    aLuna := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
    aDATADOC := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);

    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;


  CursPUVAL := 1;
  SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
  IF UrmarirePUVAL = &apos;1&apos; THEN
    BEGIN
      CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                   pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                   pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                   TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                   );
    EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
    END;
  END IF;


  -- update pret intrare pe aviz
  select CodObiect, Cant, PU into aCodObiect, aCant, aOldPret
  from intrari1 where CodIntr1 = aCodLinieAE;

  update intrari1
  set
    PU = aPretV,
    PRETORIG = aPRETV,
    TVA = 0
  where
    CodIntr1 = aCodLinieAE;

  DifVal :=  (aPretV - aOldPret ) * aCant ;

--  update Intrari set Curs = aCurs, ValDoc = ValDoc + DifVal where CodIntr = aCodDoc;

  UPDATE INTRARI I
  SET
    Curs   = aCurs,
    VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
    TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
  WHERE
    I.CODINTR = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 408;
  BEGIN
   SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0),  coalesce(PARTENER, 0)
   INTO
     aVALDOC, aTVADoc, aMONEDA, aCODPART
    FROM
      INTRARI
    WHERE
      CODINTR = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0; aCODPART := 0;
  END;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140;

  aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 2, aCODDOC, aMONEDA, aCURS, 140);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140);

  ELSE

    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 2 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
    END IF;


    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 2
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 140
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALOBLIG,
         REST    = aVALOBLIG
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aCURS
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;



  -- recalcul suplimente pe nirstoc
  SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
  FROM
  (
    SELECT
      CASE
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
      END AS VALLINIE
    FROM
      NIRSTOC NS,
      INTRARI1 I1,
      NIR N,
      INTRARI I,
      NARTOBJ O
    WHERE
      NS.CODNIR       = N.CODNIR
      AND N.CODINTR   = aCODDOC
      AND I1.CODINTR1 = NS.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND O.CODOBIECT = NS.CODOBIECT
  );



 FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
               FROM
                 NIRSTOC NS,
                 NIR N,
                 INTRARI1 I1,
                 NARTOBJ O
                 WHERE
                   NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                   AND I1.CODINTR1 = NS.CODINTR1
                   AND O.CODOBIECT = NS.CODOBIECT
             )
 LOOP
   VS := 0;
   IF VALTOT &lt;&gt; 0 THEN
       IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
       ELSE
       IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
       ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
       END IF;
       END IF;
    END IF;

     UPDATE NIRSTOC
     SET
      SUPLIMENT = VS
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
 END LOOP;


  FOR V_REC IN
  ( SELECT
      NS.CODNIRSTOC,
      NS.PRET,
      NS.ADAOS,
      NS.CANTNIR,
      NS.SUPLIMENT,
      I1.PU,
      PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
    FROM
      NIRSTOC NS,
      NIR NR,
      INTRARI1 I1
    WHERE
      NR.CODNIR       = NS.CODNIR
      AND NR.CODINTR  = ACODDOC
      AND I1.CODINTR1 = NS.CODINTR1
   -- N.CODINTR1=ACODLINIEAE
  )
  LOOP
  -- pentru toate nirstoc DE PE AVIZ, propag pret nou din acel codnirstoc
    ASUPL   := 0;
    IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
    aADAOS   := coalesce(V_REC.ADAOS, 0);

    aNEWCURS := aCURS;

    IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
    END IF;


    NEWPRET := ROUND(ANEWCURS * V_REC.PU + aADAOS + ASUPL, V_REC.ROTLEI);

    UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF URMARIREPUVAL = 1 THEN
      APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
      UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;

--  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
    SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);
  END LOOP;
end;

procedure setDirtyIesAE(aCodLinieAE in number, aCurs in number) is
aCant     number(20, 7);
aTVA      number(20, 7);
aOldTVA   number(20, 7);
aProcTVA  number(20, 7);
aVal      number(20, 7);
aPret     number(20, 7);
aOldPret  number(20, 7);
newpret   number(20, 7);
DifVal    number(20, 7);
DifTVA    number(20, 7);
aNewCurs  number(20, 7);
aOldCurs  number(20, 7);

aCodObiect  number(20);
aCodDoc     number(20);

aAn         number(5);
aLuna       number(2);
aTipTVA     number(2);
AECust      number(2) := 0;
aVALDOC     NUMBER(20, 7);
aMONEDA     NUMBER(20);
aCURSDOC    NUMBER(20, 7);
aCODPART    NUMBER(20);
aCODGENERAL NUMBER(20);
NR          number(5);
aTVADOC     NUMBER(20, 7);
aVALDISCDOC NUMBER(20, 7);
aTVADISCDOC NUMBER(20, 7);
aADDIM      NUMBER(20, 7);
aPRETORIG   NUMBER(20, 7);
TEMP        NUMBER(20, 0);
TipTVA      number(1) := 0;
NrStingeri  number(10);

begin

  BEGIN
    SELECT CODIES INTO aCODDOC FROM IESIRI1 where codIES1 = aCodLinieAE ;
    EXCEPTION WHEN OTHERS THEN aCODDOC := 0;
  END;

  SELECT CODIES INTO TEMP FROM IESIRI WHERE CODIES = aCODDOC FOR UPDATE NOWAIT;



--calculez pret mediu
  Select Sum(coalesce(i1.Cant, 0)), sum(coalesce(i1.PU,0)*coalesce(i1.Cant, 0)), count(*)  
  into aCant, aVal, NrStingeri
  from ieslink k, Iesiri i, Iesiri1 i1
  where k.CodLinieAviz = aCodLinieAE
        and i1.CodIes1 = k.CodIes1
        and i.codIes = i1.codIes
        and i.Operat = 1;

  if NrStingeri = 0 then -- daca nu mai sunt stingeri las pretul de pe aviz
    RETURN;
  end if;   

  aPret := 0;
  if aCANT &lt;&gt; 0 then
    aPret := Round(aVal / aCant, 6);
  end if;

  for v_rec in
  ( select i.CodIes CodDoc, i.TipTVA, i.TipDoc, i.Subunitatea, i.An, i.Luna, i.Custodie
    from  Iesiri1 i1, iesiri i
    where i1.codIes1 = aCodLinieAE and i.codIes = i1.codIes)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn     := v_rec.An;
    aLuna   := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
		TipTVA  := v_rec.TipTVA;
    if coalesce(v_rec.Custodie,0) = 0 then
      AECust := coalesce(v_rec.Custodie,0);
      SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
    end if;
  end loop;

  select CodObiect, Cant, PU, TVA, ADDIM into aCodObiect, aCant, aOldPret, aOldTVA, aADDIM
  from iesiri1 where CodIes1 = aCodLinieAE;

  if (AECust = 1)or(TipTVA = 2) then
    aTIPTVA := 1;
  else
    BEGIN
       SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
       EXCEPTION WHEN OTHERS THEN aTIPTVA := 0;
    END;
  end if;

  if aTIPTVA = 1 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := aPret * aCant * aProcTVA / 100;
  end if;

  aPRETORIG := aPRET * 100 / (100 + coalesce(aADDIM, 0));

/*
  update iesiri1
  set
    PU       = aPret,
    PRETORIG = aPRETORIG,
    TVA      = aTVA
  where
  CodIes1 = aCodLinieAE;
*/
  update iesiri1
  set
    PU       = aPret,
    PRETORIG = aPRETORIG,
    TVA      = CASE WHEN coalesce(TIPTVA, 0) IN (2, 3, 4, 5, 6) THEN 0
                    ELSE aTVA
               END
  where
    CodIes1 = aCodLinieAE;


  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := aCurs;
  select Curs into aOldCurs from Iesiri where CodIes = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

--  update Iesiri set Curs = aNewCurs, ValDoc = ValDoc + DifVal, TVADoc = TVADoc + DifTVA where CodIes = aCodDoc;


  SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) INTO aVALDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;
  SELECT SUM( coalesce(TVA, 0)) INTO aTVADOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;

  SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0)  * coalesce(PROCDISC, 0)/100) INTO aVALDISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;
  SELECT SUM( coalesce(TVA, 0) *  coalesce(PROCDISC, 0)/100) INTO aTVADISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;



  UPDATE IESIRI I
  SET
    VALDOC      = coalesce(aVALDOC, 0) + coalesce(aVALDISCDOC,0) + coalesce(aTVADISCDOC,0),
    TVADOC      = coalesce(aTVADOC, 0) + coalesce(aTVADISCDOC,0),
    VALDISCOUNT = coalesce(aVALDISCDOC,0),
    TVADISCOUNT = coalesce(aTVADISCDOC,0)
  WHERE
    I.CODIES = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 418;
  BEGIN
   SELECT coalesce(VALDOC,0),  coalesce(MONEDA,0),  coalesce(CURS, 0), coalesce(PARTENER, 0)
   INTO
     aVALDOC, aMONEDA, aCURSDOC, aCODPART
    FROM
      IESIRI
    WHERE
      CODIES = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0;aMONEDA := 0; aCURSDOC := 0; aCODPART := 0;
  END;

  IF aCURSDOC = 0 THEN aCURSDOC := 1;
  END IF;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = aCODDOC AND SEMNIFICATIE = 240;

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 20, aCODDOC, aMONEDA, aCURS, 240);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALDOC, aVALDOC, 7, 240, aCODPART);

  ELSE
    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 20 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 240
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = aCODDOC AND SEMNIFICATIE = 240), aVALDOC, aVALDOC, 7, 240, aCODPART);
    END IF;

    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 20
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 240
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALDOC,
         REST    = aVALDOC
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;
/*
       UPDATE GENERAL
       SET
         CURS = aCURS
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
*/
     END LOOP;
  END IF;
end;

procedure setDirtyIesAE_STORNO(aCodLinieAE in number, aPRET IN NUMBER, aCurs in number) is
  aCant     number(20, 7);
  aTVA      number(20, 7);
  aOldTVA   number(20, 7);
  aProcTVA  number(20, 7);
  aVal      number(20, 7);
  aOldPret  number(20, 7);
  newpret   number(20, 7);
  DifVal    number(20, 7);
  DifTVA    number(20, 7);
  aNewCurs  number(20, 7);
  aOldCurs  number(20, 7);

  aCodObiect  number(20);
  aCodDoc     number(20);

  aAn         number(5);
  aLuna       number(2);
  aTipTVA     number(2);
  AECust      number(2) := 0;
  aVALDOC     NUMBER(20, 7);
  aMONEDA     NUMBER(20);
  aCURSDOC    NUMBER(20, 7);
  aCODPART    NUMBER(20);
  aCODGENERAL NUMBER(20);
  NR          number(5);
  aTVADOC     NUMBER(20, 7);
  aVALDISCDOC NUMBER(20, 7);
  aTVADISCDOC NUMBER(20, 7);
  aADDIM      NUMBER(20, 7);
  aPRETORIG   NUMBER(20, 7);
  TEMP        NUMBER(20, 0);
  TipTVA      number(1) := 0;
BEGIN
  BEGIN
    SELECT CODIES INTO aCODDOC FROM IESIRI1 where codIES1 = aCodLinieAE ;
    EXCEPTION WHEN OTHERS THEN aCODDOC := 0;
  END;

  SELECT CODIES INTO TEMP FROM IESIRI WHERE CODIES = aCODDOC FOR UPDATE NOWAIT;

  FOR v_rec IN
  ( select i.CodIes CodDoc, i.TipTVA, i.TipDoc, i.Subunitatea, i.An, i.Luna, i.Custodie
    from  Iesiri1 i1, iesiri i
    where i1.codIes1 = aCodLinieAE and i.codIes = i1.codIes)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn     := v_rec.An;
    aLuna   := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
		TipTVA  := v_rec.TipTVA;
    if coalesce(v_rec.Custodie,0) = 0 then
      AECust := coalesce(v_rec.Custodie,0);
      SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
    end if;
  end loop;

  select CodObiect, Cant, PU, TVA, ADDIM into aCodObiect, aCant, aOldPret, aOldTVA, aADDIM
  from iesiri1 where CodIes1 = aCodLinieAE;

  if (AECust = 1)or(TipTVA = 2) then
    aTIPTVA := 1;
  else
    BEGIN
       SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
       EXCEPTION WHEN OTHERS THEN aTIPTVA := 0;
    END;
  end if;

  if aTIPTVA = 1 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := aPret * aCant * aProcTVA / 100;
  end if;

  aPRETORIG := aPRET * 100 / (100 + coalesce(aADDIM, 0));

  update iesiri1
  set
    PU       = aPret,
    PRETORIG = aPRETORIG,
    TVA      = aTVA
  where
  CodIes1 = aCodLinieAE;

  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := aCurs;
  select Curs into aOldCurs from Iesiri where CodIes = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

--  update Iesiri set Curs = aNewCurs, ValDoc = ValDoc + DifVal, TVADoc = TVADoc + DifTVA where CodIes = aCodDoc;
  SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) INTO aVALDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;
  SELECT SUM( coalesce(TVA, 0)) INTO aTVADOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;

  SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0)  * coalesce(PROCDISC, 0)/100) INTO aVALDISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;
  SELECT SUM( coalesce(TVA, 0) *  coalesce(PROCDISC, 0)/100) INTO aTVADISCDOC FROM IESIRI1 I1 WHERE I1.CODIES = aCODDOC;

  UPDATE IESIRI I
  SET
    VALDOC      = coalesce(aVALDOC, 0) + coalesce(aVALDISCDOC,0) + coalesce(aTVADISCDOC,0),
    TVADOC      = coalesce(aTVADOC, 0) + coalesce(aTVADISCDOC,0),
    VALDISCOUNT = coalesce(aVALDISCDOC,0),
    TVADISCOUNT = coalesce(aTVADISCDOC,0),
    CURS        = aNewCurs
  WHERE I.CODIES = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 418;
  BEGIN
    SELECT coalesce(VALDOC,0),  coalesce(MONEDA,0),  coalesce(CURS, 0), coalesce(PARTENER, 0)
    INTO aVALDOC, aMONEDA, aCURSDOC, aCODPART
    FROM IESIRI
    WHERE CODIES = aCODDOC;
  EXCEPTION WHEN OTHERS THEN aVALDOC := 0;aMONEDA := 0; aCURSDOC := 0; aCODPART := 0;
  END;

  IF aCURSDOC = 0 THEN aCURSDOC := 1;
  END IF;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = aCODDOC AND SEMNIFICATIE = 240;

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 20, aCODDOC, aMONEDA, aCURS, 240);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALDOC, aVALDOC, 7, 240, aCODPART);

  ELSE
    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 20 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 240
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 20 AND CODDOC = aCODDOC AND SEMNIFICATIE = 240), aVALDOC, aVALDOC, 7, 240, aCODPART);
    END IF;

    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 20
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 240
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALDOC,
         REST    = aVALDOC
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aCURS
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;
end;

procedure setdirty_Cont (aCodCont in number, AnLunaStart in number, AnLunaFin in number) is
  pragma autonomous_transaction;
  Type t_CodDoc is table of jurnal.coddoc%type index by pls_integer;
  type t_tipdoc is table of jurnal.tipdoc%type index by pls_integer;

  vCodDoc t_CodDoc;
  vTipDoc t_TipDoc;

  idx number(20);
BEGIN
  SELECT j.coddoc,j.tipdoc BULK COLLECT into vCodDoc, vTipDoc from jurnal j
  WHERE ( (j.contd = aCodCont) or (j.contc = aCodCont) )
    AND ( j.an * 12 + j.luna between anLunaStart and AnLunaFin);

  FORALL idx in vCodDoc.First .. vCodDoc.last
    UPDATE jurnal1 j1
    SET j1.dirty = 1
    WHERE j1.coddoc = vCodDoc(idx) and j1.tipdoc = vTipDoc(idx);

  COMMIT;
END;

-- folositia pentru liste care analizeaza balanta pentru o anumita subunitate pana la o data limita;
PROCEDURE MAKE_RULAJE_PANA_LA_DATA(DATA IN VARCHAR, aSUBUNIT IN NUMBER)
IS
  NR                 NUMBER(10)    := 0;
  aRULAJPD           NUMBER(20, 7) := 0;
  aRULAJPC           NUMBER(20, 7) := 0;
  aRULAJVPD          NUMBER(20, 7) := 0;
  aRULAJVPC          NUMBER(20, 7) := 0;

  aRULAJPD_TOT       NUMBER(20, 7) := 0;
  aRULAJPC_TOT       NUMBER(20, 7) := 0;
  aRULAJVPD_TOT      NUMBER(20, 7) := 0;
  aRULAJVPC_TOT      NUMBER(20, 7) := 0;

  aRULAJPD_ANAL      NUMBER(20, 7) := 0;
  aRULAJPC_ANAL      NUMBER(20, 7) := 0;
  aRULAJVPD_ANAL     NUMBER(20, 7) := 0;
  aRULAJVPC_ANAL     NUMBER(20, 7) := 0;

  aRULAJP_IFRS       NUMBER(20, 7) := 0;
  aRULAJVP_IFRS      NUMBER(20, 7) := 0;
  aRULAJP_IFRS_TOT   NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_TOT  NUMBER(20, 7) := 0;

  aRULAJP_IFRS_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_ANAL NUMBER(20, 7) := 0;


  aRULAJP_GRUP       NUMBER(20, 7) := 0;
  aRULAJVP_GRUP      NUMBER(20, 7) := 0;
  aRULAJP_GRUP_TOT   NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_TOT  NUMBER(20, 7) := 0;

  aRULAJP_GRUP_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_ANAL NUMBER(20, 7) := 0;

  aData              DATE;
  aAN                NUMBER(10)    := 0;
  aLUNA              NUMBER(10)    := 0;

  vRowID             ROWID;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    aData := TO_DATE(DATA, &apos;DD.MM.YYYY&apos;);
    aAN   := EXTRACT(YEAR  FROM aData);
    aLUNA := EXTRACT(MONTH FROM aData);
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  DELETE TMP_NCONTRUL;

  -- COMPLETEZ COLOANELE DE RULAJ PRECEDENT;

  IF aSUBUNIT = 1 THEN
    INSERT INTO TMP_NCONTRUL(
      CODCONTRUL, CODCONT,
      RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
      AN, LUNA)
    SELECT
      R.CODCONTRUL, R.CODCONT,
      coalesce(R.RULAJPD,0), coalesce(R.RULAJPC,0), 0 RULAJCD, 0 RULAJCC, coalesce(R.RULAJVPD,0), coalesce(R.RULAJVPC,0), 0 RULAJVCD, 0 RULAJVCC,
      coalesce(R.RULAJP_IFRS,0), coalesce(R.RULAJVP_IFRS,0), 0 RULAJC_IFRS, 0 RULAJVC_IFRS, coalesce(R.RULAJP_GRUP,0), coalesce(R.RULAJVP_GRUP,0), 0 RULAJC_GRUP, 0 RULAJVC_GRUP,
      AN, LUNA
    FROM NCONTRUL R
    WHERE R.AN = aAN AND R.LUNA = aLUNA;
  ELSE
    INSERT INTO TMP_NCONTRUL(
      CODCONTRUL, CODCONT,
      RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
      AN, LUNA)
    SELECT
      R.CODCONTRUL, R.CODCONT,
      coalesce(RS.RULAJPD,0), coalesce(RS.RULAJPC,0), 0 RULAJCD, 0 RULAJCC, coalesce(RS.RULAJVPD,0), coalesce(RS.RULAJVPC,0), 0 RULAJVCD, 0 RULAJVCC,
      coalesce(RS.RULAJP_IFRS,0), coalesce(RS.RULAJVP_IFRS,0), 0 RULAJC_IFRS, 0 RULAJVC_IFRS, coalesce(RS.RULAJP_GRUP,0), coalesce(RS.RULAJVP_GRUP,0), 0 RULAJC_GRUP, 0 RULAJVC_GRUP,
      AN, LUNA
    FROM NCONTRUL R LEFT JOIN NCONTRULSUB RS ON RS.CODCONTRUL = R.CODCONTRUL AND RS.SUBUNITATEA = aSUBUNIT
    WHERE R.AN = aAN AND R.LUNA = aLUNA;
  END IF;

  -- COMPLETEZ COLOANELE DE RULAJ CURENT;
  FOR V_REC_JURNAL IN (
    SELECT
      CODCONT,
      Sum(RULAJCD) RULAJCD, Sum(RULAJCC) RULAJCC, Sum(RULAJVCD) RULAJVCD, Sum(RULAJVCC) RULAJVCC,
      Sum(RULAJC_IFRS) RULAJC_IFRS, Sum(RULAJVC_IFRS) RULAJVC_IFRS, Sum(RULAJC_GRUP) RULAJC_GRUP, Sum(RULAJVC_GRUP) RULAJVC_GRUP
    FROM (
      SELECT
        CONTD CODCONT,
        coalesce(VALOARE,0) RULAJCD, 0 RULAJCC, coalesce(VALOAREV,0) RULAJVCD, 0 RULAJVCC,
        coalesce(VALOARE_IFRS, 0) RULAJC_IFRS, coalesce(VALOAREV_IFRS, 0) RULAJVC_IFRS, coalesce(VALOAREGRUP, 0) RULAJC_GRUP, coalesce(PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV),0) RULAJVC_GRUP
      FROM JURNAL
      WHERE AN = aAN
        AND LUNA = aLUNA
        AND DATADOC &lt;= TO_DATE(DATA, &apos;DD.MM.YYYY&apos;)
        AND SUBUNITATEA = DECODE(aSUBUNIT, 1, SUBUNITATEA, aSUBUNIT) AND TIPDOC &lt;&gt; 32
      UNION ALL
      SELECT
        CONTC CODCONT,
        0 RULAJCD, coalesce(VALOARE,0) RULAJCC, 0 RULAJVCD, coalesce(VALOAREV,0) RULAJVCC,
        -coalesce(VALOARE_IFRS, 0) RULAJC_IFRS, -coalesce(VALOAREV_IFRS, 0) RULAJVC_IFRS, -coalesce(VALOAREGRUP, 0) RULAJC_GRUP, coalesce(-PKG_NC.VALOARE_GRUP_VALUTA(VALOAREGRUP, VALOARE, VALOAREV),0) RULAJVC_GRUP
      FROM JURNAL
      WHERE AN = aAN
        AND LUNA = aLUNA
        AND DATADOC &lt;= TO_DATE(DATA, &apos;DD.MM.YYYY&apos;)
        AND SUBUNITATEA = DECODE(aSUBUNIT, 1, SUBUNITATEA, aSUBUNIT) AND TIPDOC &lt;&gt; 32
    )
    GROUP BY CODCONT
  ) LOOP
    BEGIN
      UPDATE TMP_NCONTRUL
      SET
        RULAJCD      = V_REC_JURNAL.RULAJCD,
        RULAJCC      = V_REC_JURNAL.RULAJCC,
        RULAJVCD     = V_REC_JURNAL.RULAJVCD,
        RULAJVCC     = V_REC_JURNAL.RULAJVCC,
        RULAJC_IFRS  = V_REC_JURNAL.RULAJC_IFRS,
        RULAJVC_IFRS = V_REC_JURNAL.RULAJVC_IFRS,
        RULAJC_GRUP  = V_REC_JURNAL.RULAJC_GRUP,
        RULAJVC_GRUP = V_REC_JURNAL.RULAJVC_GRUP
      WHERE CODCONT = V_REC_JURNAL.CODCONT;
    EXCEPTION WHEN No_Data_Found THEN
      INSERT INTO TMP_NCONTRUL(
        CODCONTRUL, CODCONT,
        RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
        RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
        AN, LUNA)
      VALUES (
        0, V_REC_JURNAL.CODCONT,
        0, 0, V_REC_JURNAL.RULAJCD, V_REC_JURNAL.RULAJCC, 0, 0, V_REC_JURNAL.RULAJVCD, V_REC_JURNAL.RULAJVCC,
        0, V_REC_JURNAL.RULAJC_IFRS, 0, V_REC_JURNAL.RULAJVC_IFRS, 0, V_REC_JURNAL.RULAJC_GRUP, 0, V_REC_JURNAL.RULAJVC_GRUP,
        aAN, aLUNA);
    END;
  END LOOP;

  -- COMPLETEZ RESTUL DE CONTURI CARE NU AU AVUT RULAJE;
  FOR V_REC IN (SELECT * FROM NCONT) LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC.CODCONT;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(
        CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP, AN, LUNA)
      VALUES (
        SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;
  END LOOP;

  -- TESTEZ DACA IN LUNA ANALIZATA NU AU INTERVENIT REPARTIZARI PE ANALITICE NOI
  -- STEF 17.02.2005 PARTEA ASTA NU E NECASARA PENTRU CA RULAJELE RULAJELE PRECEDENTE SE IAU DIN NCONTRUL SI PRIN FIXARE AR TREBUII SA FIE FACUTE REPARTIZARILE
  -- STEF 17.02.2005 AM AJUNS LA ASTA FIINDCA ERAU VALORI DUBLATE
  /*
  FOR V_REC IN (
    SELECT RUL.CODCONT, RUL.RULAJPD, RUL.RULAJPC, RUL.RULAJVPD, RUL.RULAJVPC, RUL.RULAJP_IFRS, RUL.RULAJVP_IFRS, RUL.RULAJP_GRUP, RUL.RULAJVP_GRUP
    FROM TMP_NCONTRUL RUL INNER JOIN NCONTREP REP ON REP.CODCONT = RUL.CODCONT
    WHERE REP.AN = aAN AND REP.LUNA &lt;= aLUNA)
  LOOP
    aRULAJPD      := V_REC.RULAJPD;
    aRULAJPC      := V_REC.RULAJPC;
    aRULAJVPD     := V_REC.RULAJVPD;
    aRULAJVPC     := V_REC.RULAJVPC;
    aRULAJP_IFRS  := V_REC.RULAJP_IFRS;
    aRULAJVP_IFRS := V_REC.RULAJVP_IFRS;

    aRULAJP_GRUP  := V_REC.RULAJP_GRUP;
    aRULAJVP_GRUP := V_REC.RULAJVP_GRUP;

    SELECT SUM(RULAJPD), SUM(RULAJPC), SUM(RULAJVPD), SUM(RULAJVPC), SUM(RULAJP_IFRS), SUM(RULAJVP_IFRS), SUM(RULAJP_GRUP), SUM(RULAJVP_GRUP)
    INTO   aRULAJPD_TOT, aRULAJPC_TOT, aRULAJVPD_TOT, aRULAJVPC_TOT, aRULAJP_IFRS_TOT, aRULAJVP_IFRS_TOT, aRULAJP_GRUP_TOT, aRULAJVP_GRUP_TOT
    FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    FOR V_REC_ANAL IN (
      SELECT
        CODCONT,
        Decode(aRULAJPD_TOT     ,0,0,RULAJPD      * aRULAJPD      / aRULAJPD_TOT)      RULAJPD_ANAL,
        Decode(aRULAJPC_TOT     ,0,0,RULAJPC      * aRULAJPC      / aRULAJPC_TOT)      RULAJPC_ANAL,
        Decode(aRULAJVPD_TOT    ,0,0,RULAJVPD     * aRULAJPD      / aRULAJVPD_TOT)     RULAJVPD_ANAL,
        Decode(aRULAJVPC_TOT    ,0,0,RULAJVPC     * aRULAJPC      / aRULAJVPC_TOT)     RULAJVPC_ANAL,
        Decode(aRULAJP_IFRS_TOT ,0,0,RULAJP_IFRS  * aRULAJP_IFRS  / aRULAJP_IFRS_TOT)  RULAJP_IFRS_ANAL,
        Decode(aRULAJVP_IFRS_TOT,0,0,RULAJVP_IFRS * aRULAJVP_IFRS / aRULAJVP_IFRS_TOT) RULAJVP_IFRS_ANAL,
        Decode(aRULAJP_GRUP_TOT ,0,0,RULAJP_GRUP  * aRULAJP_GRUP  / aRULAJP_GRUP_TOT)  RULAJP_GRUP_ANAL,
        Decode(aRULAJVP_GRUP_TOT,0,0,RULAJVP_GRUP * aRULAJVP_GRUP / aRULAJVP_GRUP_TOT) RULAJVP_GRUP_ANAL
      FROM NCONTREPRUL
      WHERE CODPARINTE = V_REC.CODCONT)
    LOOP
      UPDATE TMP_NCONTRUL
      SET
        RULAJPD      = RULAJPD             + V_REC_ANAL.RULAJPD_ANAL,
        RULAJPC      = RULAJPC             + V_REC_ANAL.RULAJPC_ANAL,
        RULAJVPD     = RULAJVPD            + V_REC_ANAL.RULAJVPD_ANAL,
        RULAJVPC     = RULAJVPC            + V_REC_ANAL.RULAJVPC_ANAL,
        RULAJP_IFRS  = coalesce(RULAJP_IFRS, 0) + V_REC_ANAL.RULAJP_IFRS_ANAL,
        RULAJVP_IFRS = coalesce(RULAJVP_IFRS,0) + V_REC_ANAL.RULAJVP_IFRS_ANAL,
        RULAJP_GRUP  = coalesce(RULAJP_GRUP, 0) + V_REC_ANAL.RULAJP_GRUP_ANAL,
        RULAJVP_GRUP = coalesce(RULAJVP_GRUP,0) + V_REC_ANAL.RULAJVP_GRUP_ANAL
      WHERE CODCONT = V_REC_ANAL.CODCONT;
    END LOOP;
  END LOOP;
  */
  COMMIT;
END;

-- folositia pentru liste care analizeaza balanta pentru o anumita subunitate si o anumit luna;
PROCEDURE MAKE_RULAJE_SELECTIV(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER, aLUNAI IN NUMBER DEFAULT 1)
IS
  NR             NUMBER(10)    := 0;
  aRULAJPD       NUMBER(20, 7) := 0;
  aRULAJPC       NUMBER(20, 7) := 0;
  aRULAJVPD      NUMBER(20, 7) := 0;
  aRULAJVPC      NUMBER(20, 7) := 0;
  aRULAJP_IFRS   NUMBER(20, 7) := 0;
  aRULAJVP_IFRS  NUMBER(20, 7) := 0;

  aRULAJP_GRUP   NUMBER(20, 7) := 0;
  aRULAJVP_GRUP  NUMBER(20, 7) := 0;


  aRULAJPD_TOT      NUMBER(20, 7) := 0;
  aRULAJPC_TOT      NUMBER(20, 7) := 0;
  aRULAJVPD_TOT     NUMBER(20, 7) := 0;
  aRULAJVPC_TOT     NUMBER(20, 7) := 0;

  aRULAJP_IFRS_TOT  NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_TOT NUMBER(20, 7) := 0;

  aRULAJP_GRUP_TOT  NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_TOT NUMBER(20, 7) := 0;


  aRULAJPD_ANAL  NUMBER(20, 7) := 0;
  aRULAJPC_ANAL  NUMBER(20, 7) := 0;
  aRULAJVPD_ANAL NUMBER(20, 7) := 0;
  aRULAJVPC_ANAL NUMBER(20, 7) := 0;

  aRULAJP_IFRS_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_ANAL NUMBER(20, 7) := 0;

  aRULAJP_GRUP_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_ANAL NUMBER(20, 7) := 0;


  aAnIni         NUMBER(4);
  aLunaIni       NUMBER(2);

  PRAGMA AUTONOMOUS_TRANSACTION;

BEGIN
  DELETE TMP_NCONTRUL;

  -- COMPLETEZ COLOANELE DE RULAJ PRECEDENT;
  SELECT AnInitial, LunaInitiala INTO aAnIni, aLunaIni FROM firmaluni;
  IF aAnIni = aAn AND aLunaIni &gt; 1 THEN
    INSERT INTO TMP_NCONTRUL(
      CODCONTRUL,
      CODCONT,
      RULAJPD,
      RULAJPC,
      RULAJCD,
      RULAJCC,
      RULAJVPD,
      RULAJVPC,
      RULAJVCD,
      RULAJVCC,
      RULAJP_IFRS,
      RULAJVP_IFRS,
      RULAJC_IFRS,
      RULAJVC_IFRS,

      RULAJP_GRUP,
      RULAJVP_GRUP,
      RULAJC_GRUP,
      RULAJVC_GRUP,
      AN,
      LUNA
     )
    SELECT
      Min(CR.CODCONTRUL),
      CODCONT,
      Sum(coalesce(CRS.RULAJPD,0)),
      Sum(coalesce(CRS.RULAJPC,0)), 0, 0,
      Sum(coalesce(CRS.RULAJVPD,0)),
      Sum(coalesce(CRS.RULAJVPC,0)), 0, 0,
      Sum(coalesce(CRS.RULAJP_IFRS,0)),
      Sum(coalesce(CRS.RULAJVP_IFRS,0)),
      0,
      0,

      Sum(coalesce(CRS.RULAJP_GRUP,0)),
      Sum(coalesce(CRS.RULAJVP_GRUP,0)),
      0,
      0,

      aAN,
      aLUNA
    FROM NCONTRUL CR INNER JOIN NCONTRULSUB CRS ON CRS.CODCONTRUL = CR.CODCONTRUL
    WHERE CR.AN = aAnIni
      AND CR.LUNA = aLunaIni
      AND CRS.SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA)
    GROUP BY CODCONT;
  END IF;

  FOR V_REC_JURNAL IN (
    SELECT *
    FROM JURNAL
    WHERE AN = aAN
      AND AN * 12 + LUNA BETWEEN aAN * 12 + aLUNAI AND aAN * 12 + aLUNA
      AND SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA) AND TIPDOC &lt;&gt; 32)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    UPDATE TMP_NCONTRUL
    SET
      RULAJPD      = RULAJPD  + V_REC_JURNAL.VALOARE,
      RULAJVPD     = RULAJVPD + V_REC_JURNAL.VALOAREV,
      RULAJP_IFRS  = coalesce(RULAJP_IFRS, 0)  + coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVP_IFRS = coalesce(RULAJVP_IFRS, 0) + coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJP_GRUP  = coalesce(RULAJP_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVP_GRUP = coalesce(RULAJVP_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTD;

    UPDATE TMP_NCONTRUL
    SET
      RULAJPC      = RULAJPC              + V_REC_JURNAL.VALOARE,
      RULAJVPC     = RULAJVPC             + V_REC_JURNAL.VALOAREV,
      RULAJP_IFRS  = coalesce(RULAJP_IFRS, 0)  - coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVP_IFRS = coalesce(RULAJVP_IFRS, 0) - coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJP_GRUP  = coalesce(RULAJP_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVP_GRUP = coalesce(RULAJVP_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC;
  END LOOP;

  -- COMPLETEZ COLOANELE DE RULAJ CURENT;
  FOR V_REC_JURNAL IN (
    SELECT *
    FROM JURNAL
    WHERE AN = aAN
      AND LUNA = aLUNA
      AND SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA) AND TIPDOC &lt;&gt; 32)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    UPDATE TMP_NCONTRUL
    SET
      RULAJCD      = RULAJCD  + V_REC_JURNAL.VALOARE,
      RULAJVCD     = RULAJVCD + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTD;

    UPDATE TMP_NCONTRUL
    SET
      RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
      RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  - coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) - coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC;
  END LOOP;

  -- COMPLETEZ RESTUL DE CONTURI CARE NU AU AVUT RULAJE;
  FOR V_REC IN (SELECT * FROM NCONT) LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC.CODCONT;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;
  END LOOP;

  -- TESTEZ DACA IN LUNA ANALIZATA NU AU INTERVENIT REPARTIZARI PE ANALITICE NOI
  FOR V_REC IN (
    SELECT
      RUL.CODCONT,
      RUL.RULAJPD,
      RUL.RULAJPC,
      RUL.RULAJVPD,
      RUL.RULAJVPC,
      RUL.RULAJP_IFRS,
      RUL.RULAJVP_IFRS,
      RUL.RULAJP_GRUP,
      RUL.RULAJVP_GRUP
    FROM
      TMP_NCONTRUL RUL
      INNER JOIN NCONTREP REP ON REP.CODCONT = RUL.CODCONT
    WHERE REP.AN = aAN AND REP.LUNA BETWEEN ALUNAI AND aLUNA)
  LOOP
    aRULAJPD  := V_REC.RULAJPD;
    aRULAJPC  := V_REC.RULAJPC;
    aRULAJVPD := V_REC.RULAJVPD;
    aRULAJVPC := V_REC.RULAJVPC;

    aRULAJP_IFRS  := V_REC.RULAJP_IFRS;
    aRULAJVP_IFRS := V_REC.RULAJVP_IFRS;

    aRULAJP_GRUP  := V_REC.RULAJP_GRUP;
    aRULAJVP_GRUP := V_REC.RULAJVP_GRUP;

    SELECT SUM(RULAJPD)  INTO aRULAJPD_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJPC)  INTO aRULAJPC_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVPD) INTO aRULAJVPD_TOT FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVPC) INTO aRULAJVPC_TOT FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    SELECT SUM(RULAJP_IFRS)  INTO aRULAJP_IFRS_TOT   FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVP_IFRS) INTO aRULAJVP_IFRS_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    SELECT SUM(RULAJP_GRUP)  INTO aRULAJP_GRUP_TOT   FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVP_GRUP) INTO aRULAJVP_GRUP_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    FOR V_REC_ANAL IN (SELECT * FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT)
    LOOP
      aRULAJPD_ANAL  := 0;
      aRULAJPC_ANAL  := 0;
      aRULAJVPD_ANAL := 0;
      aRULAJVPC_ANAL := 0;

      aRULAJP_IFRS_ANAL  := 0;
      aRULAJVP_IFRS_ANAL := 0;

      aRULAJP_GRUP_ANAL  := 0;
      aRULAJVP_GRUP_ANAL := 0;




      IF aRULAJPD_TOT &lt;&gt; 0 THEN
        aRULAJPD_ANAL  := V_REC_ANAL.RULAJPD  * aRULAJPD / aRULAJPD_TOT;
      END IF;

      IF aRULAJPC_TOT &lt;&gt; 0 THEN
        aRULAJPC_ANAL  := V_REC_ANAL.RULAJPC  * aRULAJPC / aRULAJPC_TOT;
      END IF;

      IF aRULAJVPD_TOT &lt;&gt; 0 THEN
        aRULAJVPD_ANAL := V_REC_ANAL.RULAJVPD * aRULAJPD / aRULAJVPD_TOT;
      END IF;

      IF aRULAJVPC_TOT &lt;&gt; 0 THEN
        aRULAJVPC_ANAL := V_REC_ANAL.RULAJVPC * aRULAJPC / aRULAJVPC_TOT;
      END IF;


      IF aRULAJP_IFRS_TOT &lt;&gt; 0 THEN
        aRULAJP_IFRS_ANAL := V_REC_ANAL.RULAJP_IFRS * aRULAJP_IFRS / aRULAJP_IFRS_TOT;
      END IF;

      IF aRULAJVP_IFRS_TOT &lt;&gt; 0 THEN
        aRULAJVP_IFRS_ANAL := V_REC_ANAL.RULAJVP_IFRS * aRULAJVP_IFRS / aRULAJVP_IFRS_TOT;
      END IF;


      IF aRULAJP_GRUP_TOT &lt;&gt; 0 THEN
        aRULAJP_GRUP_ANAL := V_REC_ANAL.RULAJP_GRUP * aRULAJP_GRUP / aRULAJP_GRUP_TOT;
      END IF;

      IF aRULAJVP_GRUP_TOT &lt;&gt; 0 THEN
        aRULAJVP_GRUP_ANAL := V_REC_ANAL.RULAJVP_GRUP * aRULAJVP_GRUP / aRULAJVP_GRUP_TOT;
      END IF;


      UPDATE TMP_NCONTRUL
      SET
        RULAJPD      = RULAJPD  + aRULAJPD_ANAL,
        RULAJPC      = RULAJPC  + aRULAJPC_ANAL,
        RULAJVPD     = RULAJVPD + aRULAJVPD_ANAL,
        RULAJVPC     = RULAJVPC + aRULAJVPC_ANAL,
        RULAJP_IFRS  = RULAJP_IFRS + aRULAJP_IFRS_ANAL,
        RULAJVP_IFRS = RULAJVP_IFRS + aRULAJVP_IFRS_ANAL,
        RULAJP_GRUP  = RULAJP_GRUP + aRULAJP_GRUP_ANAL,
        RULAJVP_GRUP = RULAJVP_GRUP + aRULAJVP_GRUP_ANAL
      WHERE
        CODCONT = V_REC_ANAL.CODCONT;
    END LOOP;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_RULAJE_SELECTIV_SEC(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER, aLUNAI IN NUMBER DEFAULT 1)
IS
  NR             NUMBER(10)    := 0;
  aRULAJPD       NUMBER(20, 7) := 0;
  aRULAJPC       NUMBER(20, 7) := 0;
  aRULAJVPD      NUMBER(20, 7) := 0;
  aRULAJVPC      NUMBER(20, 7) := 0;
  aRULAJP_IFRS   NUMBER(20, 7) := 0;
  aRULAJVP_IFRS  NUMBER(20, 7) := 0;

  aRULAJP_GRUP   NUMBER(20, 7) := 0;
  aRULAJVP_GRUP  NUMBER(20, 7) := 0;


  aRULAJPD_TOT      NUMBER(20, 7) := 0;
  aRULAJPC_TOT      NUMBER(20, 7) := 0;
  aRULAJVPD_TOT     NUMBER(20, 7) := 0;
  aRULAJVPC_TOT     NUMBER(20, 7) := 0;

  aRULAJP_IFRS_TOT  NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_TOT NUMBER(20, 7) := 0;

  aRULAJP_GRUP_TOT  NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_TOT NUMBER(20, 7) := 0;


  aRULAJPD_ANAL  NUMBER(20, 7) := 0;
  aRULAJPC_ANAL  NUMBER(20, 7) := 0;
  aRULAJVPD_ANAL NUMBER(20, 7) := 0;
  aRULAJVPC_ANAL NUMBER(20, 7) := 0;

  aRULAJP_IFRS_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_IFRS_ANAL NUMBER(20, 7) := 0;

  aRULAJP_GRUP_ANAL  NUMBER(20, 7) := 0;
  aRULAJVP_GRUP_ANAL NUMBER(20, 7) := 0;


  aAnIni         NUMBER(4);
  aLunaIni       NUMBER(2);

  PRAGMA AUTONOMOUS_TRANSACTION;

BEGIN
  DELETE TMP_NCONTRUL;

  -- COMPLETEZ COLOANELE DE RULAJ PRECEDENT;
  SELECT AnInitial, LunaInitiala INTO aAnIni, aLunaIni FROM firmaluni;
  IF aAnIni = aAn AND aLunaIni &gt; 1 THEN
    INSERT INTO TMP_NCONTRUL(
      CODCONTRUL,
      CODCONT,
      RULAJPD,
      RULAJPC,
      RULAJCD,
      RULAJCC,
      RULAJVPD,
      RULAJVPC,
      RULAJVCD,
      RULAJVCC,
      RULAJP_IFRS,
      RULAJVP_IFRS,
      RULAJC_IFRS,
      RULAJVC_IFRS,

      RULAJP_GRUP,
      RULAJVP_GRUP,
      RULAJC_GRUP,
      RULAJVC_GRUP,
      AN,
      LUNA
     )
    SELECT
      Min(CR.CODCONTRUL),
      CODCONT,
      Sum(coalesce(CRS.RULAJPD,0)),
      Sum(coalesce(CRS.RULAJPC,0)), 0, 0,
      Sum(coalesce(CRS.RULAJVPD,0)),
      Sum(coalesce(CRS.RULAJVPC,0)), 0, 0,
      Sum(coalesce(CRS.RULAJP_IFRS,0)),
      Sum(coalesce(CRS.RULAJVP_IFRS,0)),
      0,
      0,

      Sum(coalesce(CRS.RULAJP_GRUP,0)),
      Sum(coalesce(CRS.RULAJVP_GRUP,0)),
      0,
      0,

      aAN,
      aLUNA
    FROM NCONTRUL CR INNER JOIN NCONTRULSUB CRS ON CRS.CODCONTRUL = CR.CODCONTRUL
    WHERE CR.AN = aAnIni
      AND CR.LUNA = aLunaIni
      AND CRS.SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA)
    GROUP BY CODCONT;
  END IF;

  FOR V_REC_JURNAL IN (
    SELECT *
    FROM JURNAL
    WHERE AN = aAN
      AND AN * 12 + LUNA BETWEEN aAN * 12 + aLUNAI AND aAN * 12 + aLUNA - 1
      AND SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA) AND TIPDOC &lt;&gt; 32)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    UPDATE TMP_NCONTRUL
    SET
      RULAJPD      = RULAJPD  + V_REC_JURNAL.VALOARE,
      RULAJVPD     = RULAJVPD + V_REC_JURNAL.VALOAREV,
      RULAJP_IFRS  = coalesce(RULAJP_IFRS, 0)  + coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVP_IFRS = coalesce(RULAJVP_IFRS, 0) + coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJP_GRUP  = coalesce(RULAJP_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVP_GRUP = coalesce(RULAJVP_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTD;

    UPDATE TMP_NCONTRUL
    SET
      RULAJPC      = RULAJPC              + V_REC_JURNAL.VALOARE,
      RULAJVPC     = RULAJVPC             + V_REC_JURNAL.VALOAREV,
      RULAJP_IFRS  = coalesce(RULAJP_IFRS, 0)  - coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVP_IFRS = coalesce(RULAJVP_IFRS, 0) - coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJP_GRUP  = coalesce(RULAJP_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVP_GRUP = coalesce(RULAJVP_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC;
  END LOOP;

  -- COMPLETEZ COLOANELE DE RULAJ CURENT;
  FOR V_REC_JURNAL IN (
    SELECT *
    FROM JURNAL
    WHERE AN = aAN
      AND LUNA = aLUNA
      AND SUBUNITATEA IN (SELECT CODUNIC FROM TMP_MANEVRA) AND TIPDOC &lt;&gt; 32)
  LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    UPDATE TMP_NCONTRUL
    SET
      RULAJCD      = RULAJCD  + V_REC_JURNAL.VALOARE,
      RULAJVCD     = RULAJVCD + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTD;

    UPDATE TMP_NCONTRUL
    SET
      RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
      RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  - coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) - coalesce(V_REC_JURNAL.VALOAREV_IFRS,0),
      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC;
  END LOOP;

  -- COMPLETEZ RESTUL DE CONTURI CARE NU AU AVUT RULAJE;
  FOR V_REC IN (SELECT * FROM NCONT) LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC.CODCONT;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;
  END LOOP;

  -- TESTEZ DACA IN LUNA ANALIZATA NU AU INTERVENIT REPARTIZARI PE ANALITICE NOI
  FOR V_REC IN (
    SELECT
      RUL.CODCONT,
      RUL.RULAJPD,
      RUL.RULAJPC,
      RUL.RULAJVPD,
      RUL.RULAJVPC,
      RUL.RULAJP_IFRS,
      RUL.RULAJVP_IFRS,
      RUL.RULAJP_GRUP,
      RUL.RULAJVP_GRUP
    FROM
      TMP_NCONTRUL RUL
      INNER JOIN NCONTREP REP ON REP.CODCONT = RUL.CODCONT
    WHERE REP.AN = aAN AND REP.LUNA BETWEEN ALUNAI AND aLUNA)
  LOOP
    aRULAJPD  := V_REC.RULAJPD;
    aRULAJPC  := V_REC.RULAJPC;
    aRULAJVPD := V_REC.RULAJVPD;
    aRULAJVPC := V_REC.RULAJVPC;

    aRULAJP_IFRS  := V_REC.RULAJP_IFRS;
    aRULAJVP_IFRS := V_REC.RULAJVP_IFRS;

    aRULAJP_GRUP  := V_REC.RULAJP_GRUP;
    aRULAJVP_GRUP := V_REC.RULAJVP_GRUP;

    SELECT SUM(RULAJPD)  INTO aRULAJPD_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJPC)  INTO aRULAJPC_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVPD) INTO aRULAJVPD_TOT FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVPC) INTO aRULAJVPC_TOT FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    SELECT SUM(RULAJP_IFRS)  INTO aRULAJP_IFRS_TOT   FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVP_IFRS) INTO aRULAJVP_IFRS_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    SELECT SUM(RULAJP_GRUP)  INTO aRULAJP_GRUP_TOT   FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;
    SELECT SUM(RULAJVP_GRUP) INTO aRULAJVP_GRUP_TOT  FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT;

    FOR V_REC_ANAL IN (SELECT * FROM NCONTREPRUL WHERE CODPARINTE = V_REC.CODCONT)
    LOOP
      aRULAJPD_ANAL  := 0;
      aRULAJPC_ANAL  := 0;
      aRULAJVPD_ANAL := 0;
      aRULAJVPC_ANAL := 0;

      aRULAJP_IFRS_ANAL  := 0;
      aRULAJVP_IFRS_ANAL := 0;

      aRULAJP_GRUP_ANAL  := 0;
      aRULAJVP_GRUP_ANAL := 0;




      IF aRULAJPD_TOT &lt;&gt; 0 THEN
        aRULAJPD_ANAL  := V_REC_ANAL.RULAJPD  * aRULAJPD / aRULAJPD_TOT;
      END IF;

      IF aRULAJPC_TOT &lt;&gt; 0 THEN
        aRULAJPC_ANAL  := V_REC_ANAL.RULAJPC  * aRULAJPC / aRULAJPC_TOT;
      END IF;

      IF aRULAJVPD_TOT &lt;&gt; 0 THEN
        aRULAJVPD_ANAL := V_REC_ANAL.RULAJVPD * aRULAJPD / aRULAJVPD_TOT;
      END IF;

      IF aRULAJVPC_TOT &lt;&gt; 0 THEN
        aRULAJVPC_ANAL := V_REC_ANAL.RULAJVPC * aRULAJPC / aRULAJVPC_TOT;
      END IF;


      IF aRULAJP_IFRS_TOT &lt;&gt; 0 THEN
        aRULAJP_IFRS_ANAL := V_REC_ANAL.RULAJP_IFRS * aRULAJP_IFRS / aRULAJP_IFRS_TOT;
      END IF;

      IF aRULAJVP_IFRS_TOT &lt;&gt; 0 THEN
        aRULAJVP_IFRS_ANAL := V_REC_ANAL.RULAJVP_IFRS * aRULAJVP_IFRS / aRULAJVP_IFRS_TOT;
      END IF;


      IF aRULAJP_GRUP_TOT &lt;&gt; 0 THEN
        aRULAJP_GRUP_ANAL := V_REC_ANAL.RULAJP_GRUP * aRULAJP_GRUP / aRULAJP_GRUP_TOT;
      END IF;

      IF aRULAJVP_GRUP_TOT &lt;&gt; 0 THEN
        aRULAJVP_GRUP_ANAL := V_REC_ANAL.RULAJVP_GRUP * aRULAJVP_GRUP / aRULAJVP_GRUP_TOT;
      END IF;


      UPDATE TMP_NCONTRUL
      SET
        RULAJPD      = RULAJPD  + aRULAJPD_ANAL,
        RULAJPC      = RULAJPC  + aRULAJPC_ANAL,
        RULAJVPD     = RULAJVPD + aRULAJVPD_ANAL,
        RULAJVPC     = RULAJVPC + aRULAJVPC_ANAL,
        RULAJP_IFRS  = RULAJP_IFRS + aRULAJP_IFRS_ANAL,
        RULAJVP_IFRS = RULAJVP_IFRS + aRULAJVP_IFRS_ANAL,
        RULAJP_GRUP  = RULAJP_GRUP + aRULAJP_GRUP_ANAL,
        RULAJVP_GRUP = RULAJVP_GRUP + aRULAJVP_GRUP_ANAL
      WHERE
        CODCONT = V_REC_ANAL.CODCONT;
    END LOOP;
  END LOOP;

  COMMIT;
END;

PROCEDURE MAKE_RULAJE_SELECTIV_EXT(aAN IN NUMBER, aLUNA IN NUMBER, aSUBUNIT IN NUMBER)
IS
  NR NUMBER(10) := 0;
  aRULAJPD      NUMBER(20, 7) := 0;
  aRULAJPC      NUMBER(20, 7) := 0;
  aRULAJVPD     NUMBER(20, 7) := 0;
  aRULAJVPC     NUMBER(20, 7) := 0;

  aRULAJPD_TOT  NUMBER(20, 7) := 0;
  aRULAJPC_TOT  NUMBER(20, 7) := 0;
  aRULAJVPD_TOT NUMBER(20, 7) := 0;
  aRULAJVPC_TOT NUMBER(20, 7) := 0;

  aRULAJPD_ANAL  NUMBER(20, 7) := 0;
  aRULAJPC_ANAL  NUMBER(20, 7) := 0;
  aRULAJVPD_ANAL NUMBER(20, 7) := 0;
  aRULAJVPC_ANAL NUMBER(20, 7) := 0;

  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_NCONTRUL;

  INSERT INTO TMP_NCONTRUL (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
  RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
  RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP,
  AN, LUNA)
  SELECT R.CODCONTRUL, R.CODCONT, RS.RULAJPD, RS.RULAJPC, RS.RULAJCD, RS.RULAJCC, RS.RULAJVPD, RS.RULAJVPC, RS.RULAJVCD, RS.RULAJVCC,
  RS.RULAJP_IFRS, RS.RULAJC_IFRS,  RS.RULAJVP_IFRS, RS.RULAJVC_IFRS,
  RS.RULAJP_GRUP, RS.RULAJC_GRUP,  RS.RULAJVP_GRUP, RS.RULAJVC_GRUP,
  aAN, aLUNA
  FROM
    NCONTRUL R,
    NCONTRULSUB RS
  WHERE
       R.AN   = aAN
   AND R.LUNA = aLUNA
   AND RS.CODCONTRUL = R.CODCONTRUL
   AND RS.SUBUNITATEA = aSUBUNIT;

-- completez restul de conturi care nu au avut rulaje;
  FOR V_REC IN (SELECT * FROM NCONT) LOOP
    SELECT COUNT(*) INTO NR FROM TMP_NCONTRUL WHERE CODCONT = V_REC.CODCONT;
    IF NR = 0 THEN
      INSERT INTO TMP_NCONTRUL(CODCONTRUL,
                               CODCONT,
                               RULAJPD,
                               RULAJPC,
                               RULAJCD,
                               RULAJCC,
                               RULAJVPD,
                               RULAJVPC,
                               RULAJVCD,
                               RULAJVCC,
                               RULAJP_IFRS,
                               RULAJC_IFRS,
                               RULAJVP_IFRS,
                               RULAJVC_IFRS,
                               RULAJP_GRUP,
                               RULAJC_GRUP,
                               RULAJVP_GRUP,
                               RULAJVC_GRUP,
                               AN,
                               LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;
  END LOOP;


  COMMIT;
END;







PROCEDURE SETDIRTYTIPDOC (PTIPDOC IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER) IS
    PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN

	UPDATE JURNAL1 J1
  SET
    J1.DIRTY = 1
  WHERE
     J1.TIPDOC = PTIPDOC
     AND
		 (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
	 COMMIT;
 END;

PROCEDURE SETDIRTYJURN (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER) IS
    PRAGMA AUTONOMOUS_TRANSACTION;
S varchar2(100);
BEGIN
  BEGIN
    SELECT coalesce(Machete,&apos;?&apos;)  INTO S from JurnalShort;
  EXCEPTION WHEN OTHERS THEN
		S := &apos;?&apos;;
  END;
  if (PTipBaza &lt;&gt; 200)or(S=&apos;?&apos;)   then
	 UPDATE JURNAL1 J1
  SET
    J1.DIRTY = 1
  WHERE
	   (
       ( J1.TIPBAZAD = PTIPBAZA  AND J1.CODBAZAD = PCODBAZA AND J1.TIPCONTD  = PTIPCONT AND J1.CODDESCRD = PCODDESCR)
       OR
  		 (J1.TIPBAZAC = PTIPBAZA  AND J1.CODBAZAC = PCODBAZA AND J1.TIPCONTC  = PTIPCONT AND J1.CODDESCRC = PCODDESCR)
     )
	  AND
		 (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
  else
		for V_Rec in (
		Select * from (select distinct J1.CodDoc, J1.TipDoc
		FROM
			 JURNAL1 J1
		WHERE
	   (
       ( J1.TIPBAZAD = PTIPBAZA  AND J1.CODBAZAD = PCODBAZA AND J1.TIPCONTD  = PTIPCONT AND J1.CODDESCRD = PCODDESCR)
       OR
  		 (J1.TIPBAZAC = PTIPBAZA  AND J1.CODBAZAC = PCODBAZA AND J1.TIPCONTC  = PTIPCONT AND J1.CODDESCRC = PCODDESCR)
     )
			AND(J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN)

		 union all
		select distinct I.CodIes CodDoc, I.TipDoc
		FROM
			 IESIRI1 I1,
			 IESIRI  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODIES = I1.CodIes
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN

		 union all
		select distinct I.CodIntr CodDoc, I.TipDoc
		FROM
			 INTRARI1 I1,
			 INTRARI  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODINTR = I1.CodINTR
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN

		 union all
		select distinct I.CodTransf CodDoc, I.TipDoc
		FROM
			 TRANSF1 I1,
			 TRANSF  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODTRANSF = I1.CodTRANSF
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN
		)
    ) loop
     	 UPDATE JURNAL1 J1 SET J1.DIRTY = 1 where J1.CodDoc = V_Rec.CodDoc and J1.TipDoc = V_Rec.TipDoc ;
	  end loop;
	 end if;
	 COMMIT;
 END;

PROCEDURE Internal_SETDIRTYBAZA (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER, TipDirty in number) IS
    PRAGMA AUTONOMOUS_TRANSACTION;
S varchar2(100);
BEGIN
  BEGIN
    SELECT coalesce(Machete,&apos;?&apos;)  INTO S from JurnalShort;
  EXCEPTION WHEN OTHERS THEN
		S := &apos;?&apos;;
  END;
  if (PTipBaza &lt;&gt; 200)or(S=&apos;?&apos;)   then
		UPDATE JURNAL1 J1
		SET
			J1.DIRTY = TipDirty
		WHERE
			 (
				 ( J1.TIPBAZAD = PTIPBAZA  AND J1.CODBAZAD = PCODBAZA)
				 OR
				 (J1.TIPBAZAC = PTIPBAZA  AND J1.CODBAZAC = PCODBAZA)
			 )
			 AND
			 (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
   else
		for V_Rec in (
		Select * from (select distinct J1.CodDoc, J1.TipDoc
		FROM
			 JURNAL1 J1
		WHERE
			 (
				 ( J1.TIPBAZAD = PTIPBAZA  AND J1.CODBAZAD = PCODBAZA)
				 OR
				 (J1.TIPBAZAC = PTIPBAZA  AND J1.CODBAZAC = PCODBAZA)
			 )
			AND(J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN)

		 union all
		select distinct I.CodIes CodDoc, I.TipDoc
		FROM
			 IESIRI1 I1,
			 IESIRI  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODIES = I1.CodIes
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN

		 union all
		select distinct I.CodIntr CodDoc, I.TipDoc
		FROM
			 INTRARI1 I1,
			 INTRARI  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODINTR = I1.CodINTR
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN

		 union all
		select distinct I.CodTransf CodDoc, I.TipDoc
		FROM
			 TRANSF1 I1,
			 TRANSF  I
		WHERE
			I1.CODOBIECT = PCODBAZA
			AND I.CODTRANSF = I1.CodTRANSF
			AND InStr(S, &apos;,&apos;||I.TipDoc||&apos;,&apos;) &gt; 0
			AND I.AN * 12 + I.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN
		)
    ) loop
     	 UPDATE JURNAL1 J1 SET J1.DIRTY = TipDirty where J1.CodDoc = V_Rec.CodDoc and J1.TipDoc = V_Rec.TipDoc ;
	  end loop;
	 end if;
	 COMMIT;
 END;

PROCEDURE SETDIRTYBAZA (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER) IS
 BEGIN
   Internal_SETDIRTYBAZA (PTIPBAZA, PCODBAZA,PANLUNASTART,PANLUNAFIN, 1);
 END;

PROCEDURE SETDIRTYBAZA2 (PTIPBAZA IN NUMBER, PCODBAZA IN NUMBER,PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER) IS
    PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   Internal_SETDIRTYBAZA (PTIPBAZA, PCODBAZA,PANLUNASTART,PANLUNAFIN, 2);
END;

PROCEDURE SETDIRTYDESCRIPTOR (PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER ) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   UPDATE
     JURNAL1 J1
   SET
     J1.DIRTY = 1
   WHERE
	    (
       (J1.TIPCONTD  = PTIPCONT AND J1.CODDESCRD = PCODDESCR)
       OR
       (J1.TIPCONTC  = PTIPCONT AND J1.CODDESCRC = PCODDESCR)
      )
		  AND
		  (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
	 COMMIT;
 END;

PROCEDURE SETDIRTYICONT (PTIPCONT IN NUMBER,PCODDESCR IN NUMBER, PICONT IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER ) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
 BEGIN
   IF PCODDESCR = -1 then
     UPDATE
       JURNAL1 J1
     SET
       J1.DIRTY = 1
     WHERE
  	    (
         (J1.TIPCONTD  = PTIPCONT AND J1.ICONTD = PICONT)
         OR
         (J1.TIPCONTC  = PTIPCONT AND J1.ICONTC = PICONT)
        )
  		  AND
  		  (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
   ELSE
     UPDATE
       JURNAL1 J1
     SET
       J1.DIRTY = 1
     WHERE
  	    (
         (J1.TIPCONTD  = PTIPCONT AND J1.CODDESCRD = PCODDESCR AND J1.ICONTD = PICONT)
         OR
         (J1.TIPCONTC  = PTIPCONT AND J1.CODDESCRC = PCODDESCR AND J1.ICONTC = PICONT)
        )
  		  AND
  		  (J1.AN * 12 + J1.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);
   End If;
	 COMMIT;
 END;

FUNCTION  Count_InchideriSubunit(PANLUNA IN NUMBER) RETURN NUMBER IS
iResult NUMBER(20) := 0;
BEGIN
  SELECT COUNT(*) INTO iResult FROM JURNAL J
  WHERE (J.TIPDOC = 32) AND (J.SUBUNITATEA &gt; 1) AND (J.AN * 12 + J.LUNA = PANLUNA);
	RETURN iResult;
END;

FUNCTION NumaraDocsCont (aCONT IN NUMBER, PANLUNASTART IN NUMBER,PANLUNAFIN IN NUMBER ) RETURN NUMBER IS
iResult NUMBER(20) := 0;
BEGIN
	  SELECT COUNT(*) INTO iResult FROM JURNAL J
    WHERE
      (J.CONTD  = aCONT or J.CONTC = aCONT)
		  AND
		  (J.AN * 12 + J.LUNA BETWEEN PANLUNASTART AND PANLUNAFIN);

		RETURN iResult;
END;



procedure Set_Rulaj_Din_Jurnal(Semn in number, aTIPDOC IN NUMBER, aCODDOC IN NUMBER, aAn IN NUMBER, aLuna IN NUMBER)
is
NR number;
begin
  for V_REC in (select * from Jurnal where CodDoc = aCodDoc and TipDoc = aTipDoc AND AN = aAN AND LUNA = aLUNA)
  loop
    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND AN = aAn AND LUNA = aLuna;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAn, aLuna);
    END IF;
    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND AN = aAn AND LUNA = aLuna;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAn, aLuna);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD      = RULAJCD              + Semn * V_REC.VALOARE,
      RULAJVCD     = RULAJVCD             + Semn * V_REC.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + Semn * coalesce(V_REC.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + Semn * coalesce(V_REC.VALOAREV_IFRS, 0),

      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + Semn * coalesce(V_REC.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + Semn * PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOAREGRUP, V_REC.VALOARE, V_REC.VALOAREV)
    WHERE
     CODCONT = V_REC.CONTD AND AN = aAn AND LUNA = aLuna;
    UPDATE NCONTRUL
    SET
      RULAJCD      = RULAJCD              + Semn * V_REC.VALOARE,
      RULAJVCD     = RULAJVCD             + Semn * V_REC.VALOAREV,

      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + Semn * coalesce(V_REC.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + Semn * coalesce(V_REC.VALOAREV_IFRS, 0),

      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + Semn * coalesce(V_REC.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + Semn * PKG_NC.VALOARE_GRUP_VALUTA(V_REC.VALOAREGRUP, V_REC.VALOARE, V_REC.VALOAREV)
    WHERE
     CODCONT = V_REC.CONTC AND AN = aAn AND LUNA = aLuna;

  END LOOP;
end;

PROCEDURE PREIAPRODNETERMLUNAPREC
IS
aANLUCRU number(5);
aLUNALUCRU number(2);
aANPRECEDENT number(5);
aLUNAPRECEDENTA number(2);

aData DATE;
BEGIN
  aANLUCRU   := PKG_GLOBALS.ANLUCRU;
  aLUNALUCRU := PKG_GLOBALS.LUNALUCRU;
  aANPRECEDENT := PKG_GLOBALS.ANPRECEDENT;
  aLUNAPRECEDENTA := PKG_GLOBALS.LUNAPRECEDENTA;
  aData      := TO_DATE(&apos;01.&apos;||LPAD(To_CHAR(aLUNALUCRU), 2, &apos;0&apos;)||aANLUCRU, &apos;DD.MM.YYYY&apos;);

--  Set_Rulaj_Din_Jurnal(-1, 71, 0, aAnLucru, aLUNALUCRU);
  DELETE FROM JURNAL  WHERE AN = aANLUCRU AND LUNA = aLUNALUCRU AND TIPDOC = 71 and CodDoc = 0;
  INSERT INTO JURNAL
  (
    CODJURNAL,
    CODDOC,
    TIPDOC,
    INDEXLOCAL,
    CONTD,
    CONTC,
    GEST,
    VALOARE,
    VALOAREV,
    OBS,
    AN,
    LUNA,
    SUBUNITATEA,
    DATADOC,
    DOCUMENT,
    CODCENTRU,
    VALOAREGRUP
  )
  SELECT
    SEQ_JURNAL_CODJURNAL.NEXTVAL,
    0,
    TipDoc,
    INDEXLOCAL,
    CONTD,
    CONTC,
    GEST,
    -VALOARE,
    -VALOAREV,
    OBS,
    aANLUCRU,
    aLUNALUCRU,
    SUBUNITATEA,
    aDATA,
    DOCUMENT,
    CODCENTRU,
    -VALOAREGRUP
  FROM
    JURNAL
  WHERE
    AN = aANPRECEDENT AND LUNA = aLUNAPRECEDENTA AND TIPDOC = 71 AND CODDOC &lt;&gt; 0;
--  Set_Rulaj_Din_Jurnal(+1, 71, 0, aAnLucru, aLUNALUCRU);

  DELETE FROM JURNAL1 WHERE AN = aANLUCRU AND LUNA = aLUNALUCRU AND TIPDOC = 71 and CodDoc = 0;
  INSERT INTO JURNAL1
  (
   CODJURNAL1,
   CODDOC,
   TIPDOC,
   INDEXLOCAL,
   CODBAZAD,
   TIPBAZAD,
   ICONTBAZAD,
   CODDESCRD,
   ICONTD,
   TIPCONTD,
   ANALITICCONTD,
   CODBAZAC,
   TIPBAZAC,
   ICONTBAZAC,
   CODDESCRC,
   ICONTC,
   TIPCONTC,
   ANALITICCONTC,
   GEST,
   VALOARE,
   VALOAREV,
   OBS,
   AN,
   LUNA,
   DIRTY,
   SUBUNITATEA,
   DATADOC,
   DOCUMENT,
   CODCENTRU,
   VALOAREGRUP
  )
   SELECT
   SEQ_JURNAL1_CODJURNAL1.NEXTVAL,
   0,
   TipDoc,
   INDEXLOCAL,
   CODBAZAD,
   TIPBAZAD,
   ICONTBAZAD,
   CODDESCRD,
   ICONTD,
   TIPCONTD,
   ANALITICCONTD,
   CODBAZAC,
   TIPBAZAC,
   ICONTBAZAC,
   CODDESCRC,
   ICONTC,
   TIPCONTC,
   ANALITICCONTC,
   GEST,
   -VALOARE,
   -VALOAREV,
   OBS,
   aANLUCRU,
   aLUNALUCRU,
   DIRTY,
   SUBUNITATEA,
   aDATA,
   DOCUMENT,
   CODCENTRU,
   -VALOAREGRUP
  FROM JURNAL1
  WHERE AN = aANPRECEDENT AND LUNA = aLUNAPRECEDENTA AND TIPDOC = 71 AND CODDOC &lt;&gt; 0;
END;

PROCEDURE UPDATE_JURN_FROM_TMP IS
  vAnLucru   NUMBER(4)  := PKG_GLOBALS.GETANLUCRU;
  vLunaLucru NUMBER(2)  := PKG_GLOBALS.GETLUNALUCRU;
  vTipJurnal NUMBER(10) := PKG_SERVICE.TIPJURNAL;
BEGIN
  IF vTipJurnal = 0
  THEN
    DELETE FROM JURNAL WHERE AN = vAnLucru AND LUNA = vLunaLucru;
  ELSE
    DELETE FROM JURNAL J
    WHERE AN   = vAnLucru
      AND LUNA = vLunaLucru
      AND EXISTS(SELECT * FROM JURNAL1 J1 WHERE J1.AN = J.AN AND J1.LUNA = J.LUNA AND J1.TIPDOC = J.TIPDOC AND J1.CODDOC = J.CODDOC AND J1.DIRTY &gt; 0);
  END IF;

  INSERT INTO JURNAL
  SELECT
    SEQ_JURNAL_CODJURNAL.NEXTVAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
    SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, VALOAREGRUP,CODANALIZANOD, VALOARE_IFRS, VALOAREV_IFRS
  FROM TMP_JURNAL;

  IF vTipJurnal = 0
  THEN
    DELETE FROM JURNAL1 WHERE AN = vAnLucru AND LUNA = vLunaLucru;
  ELSE
    FOR v_rec IN (
      SELECT DISTINCT CodDoc, TipDoc
      FROM JURNAL1
      WHERE AN = vAnLucru AND LUNA = vLunaLucru AND DIRTY &gt; 0
    )
    LOOP
      DELETE FROM JURNAL1 WHERE AN = vAnLucru AND LUNA = vLunaLucru AND CodDoc = v_rec.CodDoc and TipDoc = v_rec.TipDoc;
    END LOOP;
  END IF;

  INSERT INTO JURNAL1
  SELECT
    SEQ_JURNAL1_CODJURNAL1.NEXTVAL, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, TIPBAZAD, ICONTBAZAD,CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC,
    TIPBAZAC, ICONTBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,document, CODCENTRU, VALOAREGRUP,
    CODANALIZANOD, VALOARE_IFRS, VALOAREV_IFRS
   FROM TMP_JURNAL1;
END;

FUNCTION GETCONTFORJURNAL(CODDESCRIERE IN NUMBER, ICONT IN NUMBER, TIPCONT IN NUMBER, ANALITICCONT IN VARCHAR2, aAN IN NUMBER, aLUNA IN NUMBER ) RETURN NUMBER
IS
  DEN_COL            VARCHAR2(50) := &apos;&apos;;
  NUMETABLA          VARCHAR2(50) := &apos;&apos;;
  DEN_COL_COD        VARCHAR2(50) := &apos;&apos;;
  aCODCONT           NUMBER(20)   := 0;
  COD_DESCRIERE_LUNA NUMBER(20)   := 0;
BEGIN
  IF TIPCONT = TCJCONST THEN aCODCONT := PKG_CATEGCONST.GETVALCONSTBYCODE(CODDESCRIERE, aAN, aLUNA);
  ELSE
  IF TIPCONT = TCJCONT  THEN aCODCONT :=  CODDESCRIERE;
  ELSE --
    -- aici incep sa fie tratate IO-uri si NTVA
    IF Abs(TIPCONT) = TCJTVA THEN
      COD_DESCRIERE_LUNA := PKG_NOMTVA.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;NTVA1&apos;;
      DEN_COL_COD        := &apos;CODTVA1&apos;;
    ELSE
    IF TIPCONT = TCJIOART THEN
      COD_DESCRIERE_LUNA := PKG_CONFIGART.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;IOART1&apos;;
      DEN_COL_COD        := &apos;CODIOART1&apos;;
    ELSE
    IF TIPCONT = TCJIOPART THEN
      COD_DESCRIERE_LUNA := PKG_CONFIGPART.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;IOPART1&apos;;
      DEN_COL_COD        := &apos;CODIOPART1&apos;;
    ELSE
    IF TIPCONT = TCJIOPERS THEN
      COD_DESCRIERE_LUNA := PKG_CONFIGPERS.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;IOPERS1&apos;;
      DEN_COL_COD        := &apos;CODIOPERS1&apos;;
    ELSE
    IF TIPCONT = TCJIOBANK THEN
      COD_DESCRIERE_LUNA := PKG_CONFIGBANK.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;IOBANK1&apos;;
      DEN_COL_COD        := &apos;CODIOBANK1&apos;;
    ELSE
    IF TIPCONT = TCJFILIAL THEN
      COD_DESCRIERE_LUNA := PKG_CONFIGFILIAL.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;IOFILIAL1&apos;;
      DEN_COL_COD        := &apos;CODIOFILIAL1&apos;;
    ELSE
    IF TIPCONT = TCJTAXE THEN
      COD_DESCRIERE_LUNA := PKG_NOMTAXE.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;NTAXE1&apos;;
      DEN_COL_COD        := &apos;CODTAXA1 &apos;;
    ELSE
    IF TIPCONT = TCJNGEST1 THEN
      COD_DESCRIERE_LUNA := PKG_NOMGEST.GETCODCARACTLUNA(CODDESCRIERE, aAN, aLUNA );
      NUMETABLA          := &apos;NGEST1&apos;;
      DEN_COL_COD        := &apos;CODGEST1 &apos;;
    END IF; -- tcjNHEST1
    END IF; -- tcjTAXE
    END IF; -- tcjTIOFILIAL
    END IF; -- tcjTIOBANK
    END IF; -- tcjTIOPERS
    END IF; -- tcjTIOPART
    END IF; -- tcjIOART
    END IF; -- tcjTVA
    END IF; -- tcjCONST

    IF COD_DESCRIERE_LUNA &lt;&gt; 0 THEN
      BEGIN
        SELECT coalesce(T.COLUMN_NAME, &apos;&apos;)  INTO DEN_COL
        FROM
        USER_TAB_COLUMNS T
        WHERE
        T.COLUMN_ID = ICONT + 1 AND TABLE_NAME = NUMETABLA;
        EXCEPTION WHEN OTHERS THEN aCODCONT := 0;
      END;

      BEGIN
        EXECUTE IMMEDIATE &apos;SELECT &apos;|| DEN_COL || &apos; FROM &apos; || NUMETABLA  || &apos; WHERE &apos; || DEN_COL_COD || &apos; = &apos; || COD_DESCRIERE_LUNA INTO aCODCONT;
        EXCEPTION WHEN OTHERS THEN aCODCONT := 0;
      END;
    END IF;
   -- aici se incheie tratare IO-uri si NTVA
  END IF;


  -- tratare ANALITIC
  IF (ANALITICCONT IS NOT NULL)AND(aCODCONT &lt;&gt; 0) THEN
    aCODCONT := PKG_PLANCONTURI.GETCODCONT_BY_SIMBOL(PKG_PLANCONTURI.GETSIMBOLCONT(aCODCONT) || ANALITICCONT);
    IF aCODCONT &lt; 0 THEN aCODCONT := 0;
    END IF;
  END IF;

  RETURN aCODCONT;
END;

PROCEDURE MAKE_JURNAL(aTIPDOC IN NUMBER, aCODDOC IN NUMBER)
 IS
  CONTDEBIT  NUMBER(20);
  CONTCREDIT NUMBER(20);
 BEGIN
 -- CURAT MAI INTAI DIN JURNAL INREGISTRARILE DOCUMENTULUI ANALIZAT
   DELETE FROM JURNAL WHERE TIPDOC= aTIPDOC AND CODDOC = aCODDOC;

   FOR V_REC IN (SELECT * FROM JURNAL1 WHERE TIPDOC = aTIPDOC AND CODDOC = aCODDOC) LOOP
     CONTDEBIT  := GETCONTFORJURNAL(V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.AN, V_REC.LUNA);
     CONTCREDIT := GETCONTFORJURNAL(V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.AN, V_REC.LUNA);
     INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CodAnalizaNod, DATADOC, DOCUMENT)
     VALUES (SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, CONTDEBIT, CONTCREDIT, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, v_rec.CodAnalizaNod, V_REC.DATADOC, V_REC.DOCUMENT);
   END LOOP;
 END;

/*
procedure Set_TMP_Rul_DIN_TMP_JURNAL1(Semn in number)
is
NR number;
begin
  FOR V_REC_JURNAL1 IN (SELECT distinct CodDoc, TipDoc FROM TMP_JURNAL1)
  LOOP
    for V_REC in (select * from Jurnal where CodDoc = V_REC_JURNAL1.CodDoc and TipDoc = V_REC_JURNAL1.TipDoc)
    loop
      SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
      IF NR = 0 THEN
        INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, AN, LUNA)
        VALUES
        (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.AN, V_REC.LUNA);
      END IF;
      SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
      IF NR = 0 THEN
        INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, AN, LUNA)
        VALUES
        (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.AN, V_REC.LUNA);
      END IF;

      UPDATE NCONTRUL
      SET
        RULAJCD      = RULAJCD              + Semn*V_REC.VALOARE,
        RULAJVCD     = RULAJVCD             + Semn*V_REC.VALOAREV,
        RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + Semn*coalesce(V_REC.VALOARE_IFRS, 0),
        RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + Semn*coalesce(V_REC.VALOAREV_IFRS, 0)
      WHERE
       CODCONT = V_REC.CONTD AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
      UPDATE NCONTRUL
      SET
        RULAJCD      = RULAJCD              + Semn*V_REC.VALOARE,
        RULAJVCD     = RULAJVCD             + Semn*V_REC.VALOAREV,
        RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + Semn*coalesce(V_REC.VALOARE_IFRS, 0),
        RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + Semn*coalesce(V_REC.VALOAREV_IFRS, 0)
      WHERE
       CODCONT = V_REC.CONTC AND AN = V_REC.AN AND LUNA = V_REC.LUNA;

    END LOOP;
  END LOOP;
end;
*/
PROCEDURE DO_JURNS_DIN_TMP_JURNAL1(aTipDoc in number)
IS
  NR         NUMBER(10) := 0;
  aAN        NUMBER;
  aLUNA      NUMBER;
BEGIN
--   Set_TMP_Rul_DIN_TMP_JURNAL1(-1);  asta se face la sfarsit
  DELETE FROM Jurnal  where TipDoc = aTipDoc AND AN * 12 + LUNA = PKG_GLOBALS.AnLunaLucru;
  DELETE FROM Jurnal1 where TipDoc = aTipDoc AND AN * 12 + LUNA = PKG_GLOBALS.AnLunaLucru;

  INSERT INTO Jurnal (
    CODJURNAL,
    CODDOC, TIPDOC, IndexLocal,
    CONTD, CONTC,
    GEST, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD, OBS, AN, LUNA,
    VALOARE, VALOAREV, VALOAREGRUP, VALOARE_IFRS, VALOAREV_IFRS
  )
  SELECT
    SEQ_JURNAL_CODJURNAL.NEXTVAL,
    CodDoc, TipDoc, IndexLocal,
    CONTDEBIT, CONTCREDIT,
    GEST, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD, OBS, AN, LUNA,
    VALOARE, VALOAREV,  VALOAREGRUP, VALOARE_IFRS, VALOAREV_IFRS
  FROM (
    SELECT
      CodDoc, TipDoc, IndexLocal,
      CONTDEBIT, CONTCREDIT,
      GEST, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD, OBS, AN, LUNA,
      Round(Sum(VALOARE       ),2) VALOARE ,
      Round(Sum(VALOAREV      ),2) VALOAREV,
      Round(Sum(VALOAREGRUP   ),2) VALOAREGRUP  ,
      Round(Sum(VALOARE_IFRS  ),2) VALOARE_IFRS ,
      Round(Sum(VALOAREV_IFRS ),2) VALOAREV_IFRS
    FROM (
      SELECT
        CodDoc, TipDoc,
        CASE WHEN TipDoc IN (81, 81) THEN IndexLocal ELSE 0 END AS IndexLocal,
        GETCONTFORJURNAL(CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, AN, LUNA) AS CONTDEBIT,
        GETCONTFORJURNAL(CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, AN, LUNA) AS CONTCREDIT,
        GEST, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD, OBS, AN, LUNA,
        VALOARE, VALOAREV,
        Coalesce(VALOAREGRUP, 0) AS VALOAREGRUP,
        Coalesce(VALOARE_IFRS, 0) AS VALOARE_IFRS,
        Coalesce(VALOAREV_IFRS, 0) AS VALOAREV_IFRS
      FROM Tmp_Jurnal1
    )
    GROUP BY CodDoc, TipDoc, IndexLocal, CONTDEBIT, CONTCREDIT, GEST, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD, OBS, AN, LUNA
  )
  WHERE Valoare &lt;&gt; 0.0;
--   Set_TMP_Rul_DIN_TMP_JURNAL1(+1);
  INSERT INTO jurnal1 SELECT * FROM tmp_jurnal1;
END;

PROCEDURE DO_JURNAL_RULAJE_DIN_JURNAL1(aAN IN NUMBER, aLUNA IN NUMBER)
IS
  CONTDEBIT  NUMBER(20);
  CONTCREDIT NUMBER(20);
  NR         NUMBER(10) := 0;
 BEGIN
 -- CURAT MAI INTAI DIN JURNAL INREGISTRARILE DOCUMENTULUI ANALIZAT
   DELETE FROM JURNAL WHERE AN = aAN AND LUNA = aLUNA;
   FOR V_REC IN (SELECT * FROM JURNAL1 WHERE AN = aAN AND LUNA = aLUNA) LOOP
     CONTDEBIT  := GETCONTFORJURNAL(V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD, V_REC.AN, V_REC.LUNA);
     CONTCREDIT := GETCONTFORJURNAL(V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.AN, V_REC.LUNA);

     SELECT  COUNT(*) INTO NR FROM JURNAL
     WHERE
          AN          = aAN
      AND LUNA        = aLUNA
      AND CODDOC      = V_REC.CODDOC
      AND TIPDOC      = V_REC.TIPDOC
      AND GEST        = V_REC.GEST
      AND CONTD       = CONTDEBIT
      AND CONTC       = CONTCREDIT
      AND INDEXLOCAL  = INDEXLOCAL
      AND SUBUNITATEA = V_REC.SUBUNITATEA;

     IF NR = 0 THEN
       INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CodAnalizaNod, DATADOC, DOCUMENT)
       VALUES (SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, CONTDEBIT, CONTCREDIT, V_REC.GEST, ROUND(V_REC.VALOARE, 2), ROUND(V_REC.VALOAREV, 2), round(v_rec.VALOAREGRUP, 2), V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, v_rec.CodAnalizaNod, V_REC.DATADOC, V_REC.DOCUMENT);
    ELSE
      UPDATE JURNAL
      SET
        VALOARE  = VALOARE  + V_REC.VALOARE,
        VALOAREV = VALOAREV + V_REC.VALOAREV,
        VALOAREGRUP = VALOAREGRUP + V_REC.VALOAREGRUP,
        OBS      = V_REC.OBS
     WHERE
          AN          = aAN
      AND LUNA        = aLUNA
      AND CODDOC      = V_REC.CODDOC
      AND TIPDOC      = V_REC.TIPDOC
      AND GEST        = V_REC.GEST
      AND CONTD       = CONTDEBIT
      AND CONTC       = CONTCREDIT
      AND INDEXLOCAL  = V_REC.INDEXLOCAL
      AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END IF;
   END LOOP;

   UPDATE JURNAL
   SET
     VALOARE  = ROUND(VALOARE, 2),
     VALOAREV = ROUND(VALOAREV, 2),
     VALOAREGRUP = ROUND(VALOAREGRUP, 2);

-- REFAC RULAJE
  UPDATE NCONTRUL
  SET
    RULAJCD  = 0,
    RULAJCC  = 0,
    RULAJVCD = 0,
    RULAJVCC = 0
  WHERE
  AN = aAN AND LUNA = aLUNA;

  FOR V_REC_JURNAL IN (SELECT * FROM JURNAL WHERE AN = aAN AND LUNA = aLUNA)
  LOOP

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTD AND AN = aAN AND LUNA = aLUNA;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTD,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC_JURNAL.CONTC AND AN = aAN AND LUNA = aLUNA;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
      AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC_JURNAL.CONTC,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, aAN, aLUNA);
    END IF;

    UPDATE NCONTRUL
    SET
      RULAJCD      = RULAJCD              + V_REC_JURNAL.VALOARE,
      RULAJVCD     = RULAJVCD             + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  + coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) + coalesce(V_REC_JURNAL.VALOAREV_IFRS, 0),

      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
     CODCONT = V_REC_JURNAL.CONTD AND AN = aAN AND LUNA = aLUNA;


    UPDATE NCONTRUL
    SET
      RULAJCC      = RULAJCC  + V_REC_JURNAL.VALOARE,
      RULAJVCC     = RULAJVCC + V_REC_JURNAL.VALOAREV,
      RULAJC_IFRS  = coalesce(RULAJC_IFRS, 0)  - coalesce(V_REC_JURNAL.VALOARE_IFRS, 0),
      RULAJVC_IFRS = coalesce(RULAJVC_IFRS, 0) - coalesce(V_REC_JURNAL.VALOAREV_IFRS, 0),


      RULAJC_GRUP  = coalesce(RULAJC_GRUP, 0)  + coalesce(V_REC_JURNAL.VALOAREGRUP, 0),
      RULAJVC_GRUP = coalesce(RULAJVC_GRUP, 0) + PKG_NC.VALOARE_GRUP_VALUTA(V_REC_JURNAL.VALOAREGRUP, V_REC_JURNAL.VALOARE, V_REC_JURNAL.VALOAREV)
    WHERE
      CODCONT = V_REC_JURNAL.CONTC AND AN = aAN AND LUNA = aLUNA;

  END LOOP;
 END;


PROCEDURE SaveETALON (aAN IN NUMBER, aLUNA IN NUMBER ) is
begin
  DELETE FROM JURNETALON WHERE AN = aAN and LUNA = aLUNA;
  INSERT INTO JURNETALON SELECT * FROM JURNAL WHERE AN = aAN and LUNA = aLUNA;
  COMMIT;
end;

FUNCTION COMPARE_ETALON (aAN IN NUMBER, aLUNA IN NUMBER ) return crs IS
s varchar2(1000);
tmpveki varchar2(30);
cnt number(1);
cResult crs;
BEGIN
 delete from DIFERENTE_JURNAL;
-- INSERT INTO X(SQL) VALUES (AAN || &apos;+&apos; || ALUNA);
 INSERT INTO DIFERENTE_JURNAL(SIMBOLD,SIMBOLC,CODDOC,TIPDOC,INDEXLOCAL,GEST,VALOARE,VALOAREV,VALOAREGRUP,OBS,
                              SUBUNITATEA,DATADOC,DOCUMENT,NOU)
 SELECT D.SIMBOL SIMBOLD,C.SIMBOL SIMBOLC, J.CODDOC,J.TIPDOC,J.INDEXLOCAL,NG.DEN_GEST,J.VALOARE,J.VALOAREV,J.VALOAREGRUP,J.OBS,
        NSUB.DEN_SUBUNIT,J.DATADOC,SUBSTR(J.DOCUMENT,1,30),1 NOU
    FROM JURNAL J LEFT JOIN NCONT C ON J.CONTC = C.CODCONT
                  LEFT JOIN NCONT D ON J.CONTD = D.CODCONT
                  LEFT JOIN NGEST NG ON NG.CODGEST = J.GEST
                  LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = J.SUBUNITATEA
    WHERE J.AN = aAN AND J.LUNA = aLUNA
 MINUS
 SELECT D.SIMBOL SIMBOLD,C.SIMBOL SIMBOLC, JE.CODDOC,JE.TIPDOC,JE.INDEXLOCAL,NG.DEN_GEST,JE.VALOARE,JE.VALOAREV,JE.VALOAREGRUP,JE.OBS,
        NSUB.DEN_SUBUNIT,JE.DATADOC,SUBSTR(JE.DOCUMENT,1,30),1 NOU
    FROM JURNETALON JE LEFT JOIN NCONT C ON JE.CONTC = C.CODCONT
                       LEFT JOIN NCONT D ON JE.CONTD = D.CODCONT
                       LEFT JOIN NGEST NG ON NG.CODGEST = JE.GEST
                       LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = JE.SUBUNITATEA
    WHERE JE.AN = aAN AND JE.LUNA = aLUNA;


 INSERT INTO DIFERENTE_JURNAL(SIMBOLD,SIMBOLC,CODDOC,TIPDOC,INDEXLOCAL,GEST,VALOARE,VALOAREV,VALOAREGRUP,OBS,
                              SUBUNITATEA,DATADOC,DOCUMENT,NOU)
  SELECT D.SIMBOL SIMBOLD,C.SIMBOL SIMBOLC, JE.CODDOC,JE.TIPDOC,JE.INDEXLOCAL,NG.DEN_GEST,JE.VALOARE,JE.VALOAREV,JE.VALOAREGRUP,JE.OBS,
        NSUB.DEN_SUBUNIT,JE.DATADOC,SUBSTR(JE.DOCUMENT,1,30),0 NOU
    FROM JURNETALON JE LEFT JOIN NCONT C ON JE.CONTC = C.CODCONT
                       LEFT JOIN NCONT D ON JE.CONTD = D.CODCONT
                       LEFT JOIN NGEST NG ON NG.CODGEST = JE.GEST
                       LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = JE.SUBUNITATEA
    WHERE JE.AN = aAN AND JE.LUNA = aLUNA
  MINUS
   SELECT D.SIMBOL SIMBOLD,C.SIMBOL SIMBOLC, J.CODDOC,J.TIPDOC,J.INDEXLOCAL,NG.DEN_GEST,J.VALOARE,J.VALOAREV,J.VALOAREGRUP,J.OBS,
        NSUB.DEN_SUBUNIT,J.DATADOC,SUBSTR(J.DOCUMENT,1,30),0 NOU
    FROM JURNAL J LEFT JOIN NCONT C ON J.CONTC = C.CODCONT
                  LEFT JOIN NCONT D ON J.CONTD = D.CODCONT
                  LEFT JOIN NGEST NG ON NG.CODGEST = J.GEST
                  LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = J.SUBUNITATEA
    WHERE J.AN = aAN AND J.LUNA = aLUNA;

 COMMIT;
  open cResult for select * from DIFERENTE_JURNAL;
  return cResult;
END;

FUNCTION GET_INFO_JURNAL(aAn in number, aLuna in number, aDirty out number) RETURN VARCHAR2
IS
Rez varchar2(3000);
BEGIN
  aDirty := 0;
  begin
    SELECT SUM(coalesce(DIRTY, 0)) into aDirty
    FROM JURNAL1 j1
         inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc  and TMP.VALOARE1 = J1.TIPDOC WHERE J1.an*12 + J1.luna = aAn * 12 + aLuna;
  exception when others then aDirty := 0;
  end;

  BEGIN
    select string_agg(JRN.SIMBCONTDEBIT||&apos;=&apos;||JRN.SIMBCONTCREDIT||&apos;(&apos;||JRN.VALOARE||&apos;)&apos;) INTO REZ
    from (
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, J1.Valoare
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC and tmp.filtru = j1.indexlocal,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = aAn * 12 + aLuna
        and J1.TipDoc &lt;&gt; 36
        and not tmp.filtru is null
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      union all
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, J1.Valoare
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = aAn * 12 + aLuna
        and J1.TipDoc &lt;&gt; 36
        and tmp.filtru is null
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      union all
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, J1.Valoare
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC and tmp.filtru = j1.codjurnal1,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = aAn * 12 + aLuna
        and J1.TipDoc = 36
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      /*union all
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, J1.Valoare
      FROM JURNAL1 J1
           inner join jurnal j on j.coddoc = j1.coddoc and j.tipdoc = j1.tipdoc
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC
                      and (coalesce(tmp.filtru,&apos;0&apos;) = &apos;0&apos; or tmp.filtru = j1.indexlocal),
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J1.an*12 + J1.luna = aAn * 12 + aLuna
      and J.an*12 + J.luna = aAn * 12 + aLuna
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDAR, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDAR
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDAR, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDAR
      union all
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, coalesce(J1.ValoareGrup, J1.Valoare) as VALOARE
      FROM JURNAL1 J1
           inner join jurnal j on j.coddoc = j1.coddoc and j.tipdoc = j1.tipdoc
                               and j.contd = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
                               and j.contc = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC
           and (coalesce(tmp.filtru,&apos;0&apos;) = &apos;0&apos; or tmp.filtru = j1.indexlocal),
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J1.an*12 + J1.luna = aAn * 12 + aLuna
      and J.an*12 + J.luna = aAn * 12 + aLuna
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDARG, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDARG
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDARG, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDARG
      union all
      SELECT CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT, coalesce(J1.ValoareGrup, J1.Valoare) as VALOARE
      FROM JURNAL1 J1
           inner join jurnal j on j.coddoc = j1.coddoc and j.tipdoc = j1.tipdoc
                               and j.contd = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
                               and j.contc = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC
                      and (coalesce(tmp.filtru,&apos;0&apos;) = &apos;0&apos; or tmp.filtru = j1.indexlocal),
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J1.an*12 + J1.luna = aAn * 12 + aLuna
      and J.an*12 + J.luna = aAn * 12 + aLuna
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDARGO, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDARGO
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna), J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDARGO, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDARGO*/
    ) JRN;
  EXCEPTION WHEN OTHERS THEN REZ := &apos;&apos;;
  END;

  RETURN REZ;
END;

FUNCTION GET_JURNAL_FULL_LUNA_MULTI(aAn in number, aLuna in number) RETURN JURN_FULL_CURSOR
IS
TMPCURSOR JURN_FULL_CURSOR;
sSQL varchar2(30000);
sExtCols varchar2(5000);
sExtJoin varchar2(500);
BEGIN
  sExtCols := &apos;&apos;;
  sExtJoin := &apos;&apos;;
  if PKG_LIST_STRUCT.TmpExists(&apos;CENTREEXT&apos;) &gt; 0 then
    pkg_globals.SetSeparator(&apos;,&apos;);
    EXECUTE IMMEDIATE &apos;SELECT stragg3200(&apos;&apos;CCEXT.&apos;&apos;||C1.numecamp||&apos;&apos; AS CCEXT_&apos;&apos;||C1.NUMECAMP)
                             FROM CFGTABLES C, CFGTABLES1 C1
                             WHERE upper(C.NUMETABELA) = &apos;&apos;CENTREEXT&apos;&apos; AND C1.CODCFGTABLE = C.CODCFGTABLE&apos; INTO sExtCols;
    if sExtCols is Null then 
      sExtCols := &apos;&apos;;
		else
		  sExtCols := &apos;,&apos;||sExtCols;
      sExtJoin := &apos; LEFT JOIN CENTREEXT CCEXT ON CCEXT.CODCENTRU = CC.CODCENTRU&apos;;
		end if;
  end if;

  BEGIN
    OPEN TMPCURSOR FOR
      &apos;select JRN.*, G.DEN_GEST, CC.DENUMIRE DEN_CC, CC.SIMBOL SIMBOL_CC,
			       Case when AA.Tip = 1 then AN.SimbolNod||&apos;&apos;=&apos;&apos;||AN.DENNod else D1.VALOARE end DEN_NOD&apos;||sExtCols||&apos;
      from (
      SELECT 1 as TipInreg, J1.CodCentru as CentruCost, J1.CodAnalizaNod as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J1.Valoare as V, J1.*, &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC and tmp.filtru = j1.indexlocal,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = &apos;||aAn||&apos; * 12 + &apos;||aLuna||&apos;
        and J1.TipDoc &lt;&gt; 36
        and not tmp.filtru is null
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      union all
      SELECT 1 as TipInreg, J1.CodCentru as CentruCost, J1.CodAnalizaNod as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J1.Valoare as V, J1.*, &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = &apos;||aAn||&apos; * 12 + &apos;||aLuna||&apos;
        and tmp.filtru is null
        and J1.TipDoc &lt;&gt; 36
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      union all
      SELECT 1 as TipInreg, J1.CodCentru as CentruCost, J1.CodAnalizaNod as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J1.Valoare as V, J1.*, &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota
      FROM JURNAL1 J1
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc and TMP.VALOARE1 = J1.TIPDOC
                                            and tmp.filtru = j1.codjurnal1,
           NCONT CD, NCONT CC
      WHERE
        J1.an*12 + J1.luna = &apos;||aAn||&apos; * 12 + &apos;||aLuna||&apos;
        and J1.TipDoc = 36
        and CD.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd, j1.an, j1.luna)
        and CC.Codcont = pkg_jurnal.GETCONTFORJURNAL(j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc, j1.an, j1.luna)
      ) JRN
      left join NGEST G on G.CodGest = JRN.Gest
      left join CENTRECOST CC on CC.CODCENTRU = Jrn.CodCentru
      left join AnalizaNod AN on AN.CODANALIZANOD = Jrn.CODANALIZANOD
      left join Analiza AA on AA.CodAnaliza = AN.CodAnaliza
      left join Descriptori1 D1 on D1.CODDESCRIPTOR1 = AN.CODDESCRIPTOR1&apos;||chr(13)||sExtJoin||chr(13)||&apos;
      ORDER BY CODJURNAL1, INDEXLOCAL, TipInreg&apos;;
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_JURNAL_FULL_LUNA(aTipDoc in number) RETURN JURN_FULL_CURSOR
IS
TMPCURSOR JURN_FULL_CURSOR;
sSQL varchar2(30000);
sExtCols varchar2(5000);
sExtJoin varchar2(500);
BEGIN
  sExtCols := &apos;&apos;;
  sExtJoin := &apos;&apos;;
  if PKG_LIST_STRUCT.TmpExists(&apos;CENTREEXT&apos;) &gt; 0 then
    pkg_globals.SetSeparator(&apos;,&apos;);
    EXECUTE IMMEDIATE &apos;SELECT stragg3200(&apos;&apos;CCEXT.&apos;&apos;||C1.numecamp||&apos;&apos; AS CCEXT_&apos;&apos;||C1.NUMECAMP)
                             FROM CFGTABLES C, CFGTABLES1 C1
                             WHERE upper(C.NUMETABELA) = &apos;&apos;CENTREEXT&apos;&apos; AND C1.CODCFGTABLE = C.CODCFGTABLE&apos; INTO sExtCols;
    if sExtCols is Null then 
      sExtCols := &apos;&apos;;
		else
		  sExtCols := &apos;,&apos;||sExtCols;
      sExtJoin := &apos; LEFT JOIN CENTREEXT CCEXT ON CCEXT.CODCENTRU = CC.CODCENTRU&apos;;
		end if;
  end if;

  BEGIN
    OPEN TMPCURSOR FOR
      &apos;select JRN.*, G.DEN_GEST, CC.DENUMIRE DEN_CC, CC.SIMBOL SIMBOL_CC,
    	       Case when AA.Tip = 1 then AN.SimbolNod||&apos;&apos;=&apos;&apos;||AN.DENNod else D1.VALOARE end DEN_NOD&apos;||sExtCols||&apos;
      from (
      SELECT 1 as TipInreg, J.CodCentru as CodCentru, J.CodAnalizaNod as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J.Valoare as V,
             J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,
						 J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.VALOAREGRUP,J.CODANALIZANOD,J.VALOARE_IFRS,J.VALOAREV_IFRS,
						 &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota,
             (SELECT SUM(coalesce(DIRTY, 0)) FROM JURNAL1 j1 inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc WHERE J1.TipDoc=&apos;||aTipDoc||&apos; and J1.an*12 + J1.luna = PKG_GLOBALS.AnLunaLucru) AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
           NCONT CD, NCONT CC
      WHERE
         J.TipDoc=&apos;||aTipDoc||&apos; and J.an*12 + J.luna = PKG_GLOBALS.AnLunaLucru
        and CD.Codcont = J.ContD
        and CC.Codcont = J.ContC
      union all
      SELECT 2 as TipInreg,
						 Decode( coalesce(C1D.CodCentruS, 0),
										 0, Decode(coalesce(C1C.CodCentruS, 0),0,J.Codcentru,coalesce(C1C.CodCentruS, 0)),
										 coalesce(C1D.CodCentruS, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J.Valoare as V,
             J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,
						 J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.VALOAREGRUP,J.CODANALIZANOD,J.VALOARE_IFRS,J.VALOAREV_IFRS,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos; and J.an*12 + J.luna = PKG_GLOBALS.AnLunaLucru
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDAR, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDAR
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDAR, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDAR
      union all
      SELECT 3 as TipInreg,
						 Decode( coalesce(C1D.CodCentruSG, 0),
										 0, Decode(coalesce(C1C.CodCentruSG, 0),0,J.Codcentru,coalesce(C1C.CodCentruSG, 0)),
										 coalesce(C1D.CodCentruSG, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             coalesce(J.ValoareGrup, J.Valoare) as V,
             J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.VALOAREGRUP,J.CODANALIZANOD,J.VALOARE_IFRS,J.VALOAREV_IFRS,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos; and J.an*12 + J.luna = PKG_GLOBALS.AnLunaLucru
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDARG, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDARG
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDARG, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDARG
      union all
      SELECT 4 as TipInreg,
						 Decode( coalesce(C1D.CodCentruSGO, 0),
										 0, Decode(coalesce(C1C.CodCentruSGO, 0),0,J.Codcentru,coalesce(C1C.CodCentruSGO, 0)),
										 coalesce(C1D.CodCentruSGO, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             coalesce(J.ValoareGrup, J.Valoare) as V,
             J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.VALOAREGRUP,J.CODANALIZANOD,J.VALOARE_IFRS,J.VALOAREV_IFRS,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
        NCONT1 C1D,
        NCONT1 C1C,
        NCONTS CD,
        NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos; and J.an*12 + J.luna = PKG_GLOBALS.AnLunaLucru
      and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
      and coalesce(C1D.CONTSECUNDARGO, 0) &gt; 0
      and CD.CodContS = C1D.CONTSECUNDARGO
      and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
      and coalesce(C1C.CONTSECUNDARGO, 0) &gt; 0
      and CC.CodContS = C1C.CONTSECUNDARGO
      ) JRN
      left join NGEST G on G.CodGest = JRN.Gest
      left join CENTRECOST CC on CC.CODCENTRU = Jrn.CodCentru
      left join AnalizaNod AN on AN.CODANALIZANOD = Jrn.CODANALIZANOD
      left join Analiza AA on AA.CodAnaliza = AN.CodAnaliza
      left join Descriptori1 D1 on D1.CODDESCRIPTOR1 = AN.CODDESCRIPTOR1&apos;||chr(13)||sExtJoin||chr(13)||&apos;
      ORDER BY CODJURNAL, INDEXLOCAL, TipInreg&apos;;
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_JURNAL_FULL(aTipDoc in number) RETURN JURN_FULL_CURSOR
IS
TMPCURSOR JURN_FULL_CURSOR;
sSQL varchar2(30000);
sExtCols varchar2(5000);
sExtJoin varchar2(500);
BEGIN
  sExtCols := &apos;&apos;;
  sExtJoin := &apos;&apos;;
  if PKG_LIST_STRUCT.TmpExists(&apos;CENTREEXT&apos;) &gt; 0 then
    pkg_globals.SetSeparator(&apos;,&apos;);
    EXECUTE IMMEDIATE &apos;SELECT stragg3200(&apos;&apos;CCEXT.&apos;&apos;||C1.numecamp||&apos;&apos; AS CCEXT_&apos;&apos;||C1.NUMECAMP)
                             FROM CFGTABLES C, CFGTABLES1 C1
                             WHERE upper(C.NUMETABELA) = &apos;&apos;CENTREEXT&apos;&apos; AND C1.CODCFGTABLE = C.CODCFGTABLE&apos; INTO sExtCols;
    if sExtCols is Null then 
      sExtCols := &apos;&apos;;
		else
		  sExtCols := &apos;,&apos;||sExtCols;
      sExtJoin := &apos; LEFT JOIN CENTREEXT CCEXT ON CCEXT.CODCENTRU = CC.CODCENTRU&apos;;
		end if;
  end if;

  BEGIN
    OPEN TMPCURSOR FOR
      &apos;select JRN.*, G.DEN_GEST, CC.DENUMIRE DEN_CC, CC.SIMBOL SIMBOL_CC,
    	       Case when AA.Tip = 1 then AN.SimbolNod||&apos;&apos;=&apos;&apos;||AN.DENNod else D1.VALOARE end DEN_NOD&apos;||sExtCols||&apos;
      from (
      SELECT 1 as TipInreg, J.CodCentru as CodCentru, J.CodAnalizaNod as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J.Valoare as V,
             J.CODJURNAL     ,
             J.CODDOC        ,
             J.TIPDOC        ,
             J.INDEXLOCAL    ,
             J.CONTD         ,
             J.CONTC         ,
             J.GEST          ,
             J.VALOARE       ,
             J.VALOAREV      ,
             J.OBS           ,
             J.AN            ,
             J.LUNA          ,
             J.SUBUNITATEA   ,
             J.DATADOC       ,
             J.DOCUMENT      ,
             J.VALOAREGRUP   ,
             J.CODANALIZANOD ,
             J.VALOARE_IFRS  ,
             J.VALOAREV_IFRS ,
						 &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota,
             ( SELECT SUM(coalesce(DIRTY, 0))
               FROM JURNAL1 j1
                    inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J1.CodDoc
              WHERE J1.TipDoc=&apos;||aTipDoc||&apos;) AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
           NCONT CD, NCONT CC
      WHERE
         J.TipDoc=&apos;||aTipDoc||&apos;
         and CD.Codcont = coalesce(J.ContD,0)
         and CC.Codcont = coalesce(J.ContC,0)
      union all
      SELECT 2 as TipInreg,
						 Decode( coalesce(C1D.CodCentruS, 0),
										 0, Decode(coalesce(C1C.CodCentruS, 0),0,J.Codcentru,coalesce(C1C.CodCentruS, 0)),
										 coalesce(C1D.CodCentruS, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             J.Valoare as V,
             J.CODJURNAL     ,
             J.CODDOC        ,
             J.TIPDOC        ,
             J.INDEXLOCAL    ,
             J.CONTD         ,
             J.CONTC         ,
             J.GEST          ,
             J.VALOARE       ,
             J.VALOAREV      ,
             J.OBS           ,
             J.AN            ,
             J.LUNA          ,
             J.SUBUNITATEA   ,
             J.DATADOC       ,
             J.DOCUMENT      ,
             J.VALOAREGRUP   ,
             J.CODANALIZANOD ,
             J.VALOARE_IFRS  ,
             J.VALOAREV_IFRS ,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
           NCONT1 C1D,
           NCONT1 C1C,
           NCONTS CD,
           NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos;
          and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
          and coalesce(C1D.CONTSECUNDAR, 0) &gt; 0
          and CD.CodContS = C1D.CONTSECUNDAR
          and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
          and coalesce(C1C.CONTSECUNDAR, 0) &gt; 0
          and CC.CodContS = C1C.CONTSECUNDAR
      union all
      SELECT 3 as TipInreg,
						 Decode( coalesce(C1D.CodCentruSG, 0),
										 0, Decode(coalesce(C1C.CodCentruSG, 0),0,J.Codcentru,coalesce(C1C.CodCentruSG, 0)),
										 coalesce(C1D.CodCentruSG, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             coalesce(J.ValoareGrup, J.Valoare) as V,
             J.CODJURNAL     ,
             J.CODDOC        ,
             J.TIPDOC        ,
             J.INDEXLOCAL    ,
             J.CONTD         ,
             J.CONTC         ,
             J.GEST          ,
             J.VALOARE       ,
             J.VALOAREV      ,
             J.OBS           ,
             J.AN            ,
             J.LUNA          ,
             J.SUBUNITATEA   ,
             J.DATADOC       ,
             J.DOCUMENT      ,
             J.VALOAREGRUP   ,
             J.CODANALIZANOD ,
             J.VALOARE_IFRS  ,
             J.VALOAREV_IFRS ,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
           NCONT1 C1D,
           NCONT1 C1C,
           NCONTS CD,
           NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos;
          and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
          and coalesce(C1D.CONTSECUNDARG, 0) &gt; 0
          and CD.CodContS = C1D.CONTSECUNDARG
          and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
          and coalesce(C1C.CONTSECUNDARG, 0) &gt; 0
          and CC.CodContS = C1C.CONTSECUNDARG
      union all
      SELECT 4 as TipInreg,
						 Decode( coalesce(C1D.CodCentruSGO, 0),
										 0, Decode(coalesce(C1C.CodCentruSGO, 0),0,J.Codcentru,coalesce(C1C.CodCentruSGO, 0)),
										 coalesce(C1D.CodCentruSGO, 0)) as CodCentru,
             0 as AnalizaNod,
             CD.Simbol AS SIMBCONTDEBIT, CC.Simbol AS SIMBCONTCREDIT,
             CD.Den_Cont AS DENCONTDEBIT, CC.Den_Cont AS DENCONTCREDIT,
             coalesce(J.ValoareGrup, J.Valoare) as V,
             J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.VALOAREGRUP,J.CODANALIZANOD,J.VALOARE_IFRS,J.VALOAREV_IFRS,
             &apos;&apos;-&apos;&apos; as Jurn, &apos;&apos;-&apos;&apos; as Nota, 0 AS DIRTY
      FROM JURNAL J
           inner join TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc,
           NCONT1 C1D,
           NCONT1 C1C,
           NCONTS CD,
           NCONTS CC
      WHERE
          J.TipDoc=&apos;||aTipDoc||&apos;
          and C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
          and coalesce(C1D.CONTSECUNDARGO, 0) &gt; 0
          and CD.CodContS = C1D.CONTSECUNDARGO
          and C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
          and coalesce(C1C.CONTSECUNDARGO, 0) &gt; 0
          and CC.CodContS = C1C.CONTSECUNDARGO
      ) JRN
      left join NGEST G on G.CodGest = JRN.Gest
      left join CENTRECOST CC on CC.CODCENTRU = Jrn.CodCentru
      left join AnalizaNod AN on AN.CODANALIZANOD = Jrn.CODANALIZANOD
      left join Analiza AA on AA.CodAnaliza = AN.CodAnaliza
      left join Descriptori1 D1 on D1.CODDESCRIPTOR1 = AN.CODDESCRIPTOR1&apos;||chr(13)||sExtJoin||chr(13)||&apos;
      ORDER BY CODJURNAL, INDEXLOCAL, TipInreg&apos;;
    EXCEPTION WHEN OTHERS THEN
      OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
    END;
  RETURN TMPCURSOR;
END;



procedure setDirtyNP(aCodLinieNP in number, aPRET IN NUMBER, aConsumPonderat IN NUMBER DEFAULT 0) is
aCant     number(20, 7);
aTVA      number(20, 7);
aOldTVA   number(20, 7);
aProcTVA  number(20, 7);
aVal      number(20, 7);
--aPret     number(20, 7);
aOldPret  number(20, 7);
newpret   number(20, 7);
aNewCurs  number(20, 7);
aOldCurs  number(20, 7);
aadaos     number(20, 7);
DifVal    number(20, 7);
DifTVA    number(20, 7);
aSupl     number(20, 7);

aCodObiect number(20);
aCodDoc    number(20);
aCODPART   number(20);

aAn         number(5);
aLuna       number(2);
aTipTVA     number(2);
aVALDOC     NUMBER(20, 7);
aTVADOC     NUMBER(20, 7);
aMONEDA     NUMBER(20);
aCODGENERAL NUMBER(20);
NR          number(5);
aVALOBLIG   NUMBER(20, 7);
aDATADOC    DATE;
UrmarirePUVAL varchar2(10);

VALSUPLIM   NUMBER(20, 7) := 0;
VALTOT      NUMBER(20, 7) := 0;
VS          NUMBER(20, 7) := 0;
TIPSUPLIM  NUMBER(5) := 0;

CursPUVAL   NUMBER(20, 7);
aPUVAL   NUMBER(20, 7);
TEMP     NUMBER(20) ;
begin
  BEGIN
    SELECT CODINTR INTO aCODDOC FROM INTRARI1 where codINTR1 = aCodLinieNP ;
    EXCEPTION WHEN OTHERS THEN aCODDOC := 0;
  END;

  SELECT CODINTR INTO TEMP FROM INTRARI WHERE CODINTR= aCODDOC FOR UPDATE NOWAIT;


  for v_rec in
  (select i.CodIntr CodDoc, i.TipDoc, i.Subunitatea, i.An, i.Luna, I.PARTENER, I.DATADOC, I.VALSUPLIM, I.TIPREPSUPLIM
  from Intrari1 i1, intrari i
  where i1.codintr1 = aCodLinieNP and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume NP-ul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn   := v_rec.An;
    aLuna := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
    aCODPART := V_REC.PARTENER;
    aDATADOC := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;

  -- update pret intrare pe NP
  select
    CodObiect,
    Cant,
    coalesce(PU, 0),
    TVA
    into
      aCodObiect,
      aCant,
      aOldPret,
      aOldTVA
  from
    intrari1
  where
    CodIntr1 = aCodLinieNP;


     CursPUVAL := 1;
     SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
     IF UrmarirePUVAL = &apos;1&apos; THEN
       BEGIN
         CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                      pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                      pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                      TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                      );
       EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
       END;
     END IF;

     aTIPTVA := &apos;0&apos;;

   --  select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
   --  aTVA := Round(aPret * aCant * aProcTVA / 100, 6);

     aTVA := 0;

     update intrari1
     set
       PU       = aPret,
       PRETORIG = aPret,
       TVA       = aTVA
     where
       CodIntr1 = aCodLinieNP;

     aNewCurs := 1;

     UPDATE INTRARI I
     SET
       Curs   = aNewCurs,
       VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
       TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
     WHERE
       I.CODINTR = aCODDOC;

     -- recalcul suplimente pe nirstoc
     SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
     FROM
     (
       SELECT
         CASE
           WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
           WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
           WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
         END AS VALLINIE
       FROM
         NIRSTOC NS,
         INTRARI1 I1,
         NIR N,
         INTRARI I,
         NARTOBJ O
       WHERE
         NS.CODNIR       = N.CODNIR
         AND N.CODINTR   = aCODDOC
         AND I1.CODINTR1 = NS.CODINTR1
         AND I.CODINTR   = I1.CODINTR
         AND O.CODOBIECT = NS.CODOBIECT
     );

    FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
                  FROM
                    NIRSTOC NS,
                    NIR N,
                    INTRARI1 I1,
                    NARTOBJ O
                    WHERE
                      NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                      AND I1.CODINTR1 = NS.CODINTR1
                      AND O.CODOBIECT = NS.CODOBIECT
                )
    LOOP
      VS := 0;
      IF VALTOT &lt;&gt; 0 THEN
          IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
          ELSE
          IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
          ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
          END IF;
          END IF;
       END IF;

        UPDATE NIRSTOC
        SET
         SUPLIMENT = VS
        WHERE
          CODNIRSTOC = V_REC.CODNIRSTOC;
    END LOOP;

     FOR V_REC IN
     ( SELECT
         NS.CODNIRSTOC,
         NS.PRET,
         NS.ADAOS,
         NS.CANTNIR,
         NS.SUPLIMENT,
         I1.PU,
         PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
       FROM
         NIRSTOC NS,
         NIR NR,
         INTRARI1 I1
       WHERE
         NR.CODNIR      = NS.CODNIR
         AND NR.CODINTR = ACODDOC
         AND I1.CODINTR1 = NS.CODINTR1
     )
     LOOP
     -- pentru toate nirstoc DE PE NP, propag pret nou din acel codnirstoc
       ASUPL   := 0;
       IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
       aADAOS   := COALESCE(V_REC.ADAOS, 0);

       IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
       END IF;

       NEWPRET := ROUND(/*APRET*/V_REC.PU * aNEWCURS + aADAOS + ASUPL, V_REC.ROTLEI);
       if aConsumPonderat = 3 then
         -- daca e pe 3, atunci e agragare (cu tip contabil cu adaos) -&gt; pret de pe doc este pret achiz
         update intrari1
         set
           PU       = V_REC.PRET - aADAOS,
           PRETORIG = V_REC.PRET - aADAOS
         where
           CodIntr1 = aCodLinieNP;
         UPDATE INTRARI I
         SET
           Curs   = aNewCurs,
           VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
           TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
         WHERE
           I.CODINTR = aCODDOC;
         UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         UPDATE NIRSTOC SET ADAOS = PRET - (V_REC.PRET - aADAOS) WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         UPDATE NIRSTOC1 SET PRETMAT = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC OR CODNIRSTOCORIG = V_REC.CODNIRSTOC;
       else
       if aConsumPonderat = 2 then
         UPDATE NIRSTOC SET ADAOS = PRET - ROUND(V_REC.PU * aNEWCURS + ASUPL, V_REC.ROTLEI) WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         UPDATE NIRSTOC1 SET PRETMAT = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC OR CODNIRSTOCORIG = V_REC.CODNIRSTOC;
       else
         UPDATE NIRSTOC SET PRET = NEWPRET, ADAOS = 0 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         UPDATE NIRSTOC1 SET PRETMAT = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC OR CODNIRSTOCORIG = V_REC.CODNIRSTOC;

         IF URMARIREPUVAL = 1 THEN
           APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
           UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         END IF;
       end if;
       end if;

   --  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
       SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);

     END LOOP;
  commit;

END;

procedure SetDirtyAllNPLuna
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCount number;
BEGIN
  delete tmp_manevra;
FOR V_REC in
(SELECT I1.CODINTR1, I1.PU, I1.CODOBIECT, i.codintr, COALESCE(IOA1.DIFPRET,0) DIFPRET
   FROM
     INTRARI I,
     INTRARI1 I1,
     NIR,
     NIRSTOC NS,
     IOART1 IOA1
   WHERE
     I.TIPDOC = 7
     AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
     AND I1.CODINTR = I.CODINTR AND NIR.CODINTR = I.CODINTR AND NS.CODNIR = NIR.CODNIR AND IOA1.CODIOART = NS.CODIOART
     AND PKG_GLOBALS.ANLUCRU*12+PKG_GLOBALS.LUNALUCRU BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND NS.CODINTR1 = I1.CODINTR1
     AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
 )
 LOOP
    Rez := 0;
    for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
      Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
    end loop;
    if Rez = 0 then
      BEGIN
        SELECT
          coalesce(PC.PRET, 0) INTO aPRET
        FROM
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         PRODCOMP PC
        WHERE
         IL.CODINTR1 = V_REC.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP;

         EXCEPTION WHEN OTHERS  THEN aPRET := 0;
      END;
      IF aPRET &lt;&gt; 0 THEN
        if v_rec.difpret &gt; 0 then
          PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET, 2);
        else
          PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET);
        end if;
        select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
        if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
        commit;
      END IF;
    end if;
 END LOOP;
 for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
               from tmp_manevra tmp
                    inner join intrari i on i.codintr = tmp.codunic
              ) loop
   IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
     WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                     PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                     v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret de referinta din retete&apos;, PKG_GLOBALS.GET_EXE_VERSION);
   END IF;
   NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
   commit;
 end loop;
END;

procedure SetDirtyAllNPLunaPretReferinta
is
aPRET NUMBER(20, 7);
aMoneda number(20);
Rez   NUMBER;
aCount number;
BEGIN
  delete tmp_manevra;
  pkg_stoc_generare_facturi.make_config_luna;
  FOR V_REC in
  (SELECT I1.CODINTR1, I1.PU, I1.CODOBIECT, i.codintr, COALESCE(IOA1.DIFPRET,0) DIFPRET, I.DATADOC, i.an, i.luna
   FROM
     INTRARI I,
     INTRARI1 I1,
     NIR,
     NIRSTOC NS,
     IOART1 IOA1
   WHERE
     I.TIPDOC = 7
     AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
     AND I1.CODINTR = I.CODINTR AND NIR.CODINTR = I.CODINTR AND NS.CODNIR = NIR.CODNIR AND IOA1.CODIOART = NS.CODIOART
     AND PKG_GLOBALS.ANLUCRU*12+PKG_GLOBALS.LUNALUCRU BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND NS.CODINTR1 = I1.CODINTR1
     AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
  )
  LOOP
    Rez := 0;
    for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
      Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
    end loop;
    if Rez = 0 then
      BEGIN
        SELECT
          coalesce(PRETREFERINTA, 0), coalesce(codmoneda,0) INTO aPRET, aMoneda 
        FROM
         TMP_NARTOBJ_LUNA OL
        WHERE
          OL.CODOBIECT = V_REC.CODOBIECT;
         EXCEPTION WHEN OTHERS  THEN aPRET := 0;
      END;
      aPret := aPret *  PKG_MONEDE.GETCURSMONEDA(aMoneda, pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;, v_rec.AN, v_rec.LUNA), TO_CHAR(v_rec.DATADOC, &apos;dd.mm.yyyy&apos;));
      IF aPRET &lt;&gt; 0 THEN
        if v_rec.difpret &gt; 0 then
          PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET, 2);
        else
          PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET);
        end if;
        select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
        if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
        commit;
      END IF;
    end if;
  END LOOP;
  for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                from tmp_manevra tmp
                     inner join intrari i on i.codintr = tmp.codunic
               ) loop
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                      PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                      v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret de referinta prestabilit (din nomenclatorul de articole)&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
    commit;
  end loop;
END;



function GetSpecificCantUM1(Rel in number, D1 in number, D2 in number, D3 in number, Cant in number)return number is
Rez number(20,7);
begin
  Rez := 0.0;
  if Rel in (1,2,3,7,8,9) then
    if D1 &lt;&gt; 0.0 then
      Rez := Cant / D1;
    end if;
    if Rel in (2,3,8,9) then
      if D2 &lt;&gt; 0.0 then
        Rez := Rez / D2;
      end if;
      if Rel in (3,9) then
        if D3 &lt;&gt; 0.0 then
          Rez := Rez / D3;
        end if;
      end if;
    end if;
  else
    if Rel in (4,5,6,10,11,12) then
      Rez := Cant * D1;
      if Rel in (5,6,11,12) then
        Rez := Rez * D2;
        if Rel in (6,12) then Rez := Rez * D3; end if;
      end if;
    end if;
  end if;
  Return Rez;
end;

function GetRebuturiInLuna(vCodComanda1 in number) return number is
vPredat number(20,7);
vRebut number(20,7);
begin
  begin
    select coalesce(sum(i1.cant),0) into vRebut
    from intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    where i1.codcmdint1 = vCodComanda1
          AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
          AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPTRANZACTIE = 9;
  exception when others then vRebut := 0;
  end;
  return vRebut;
end;

function GetRebuturi(vCodComanda1 in number) return number is
vPredat number(20,7);
vRebut number(20,7);
begin
  begin
    select coalesce(sum(i1.cant),0) into vRebut
    from intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    where i1.codcmdint1 = vCodComanda1
          AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPTRANZACTIE = 9;
  exception when others then vRebut := 0;
  end;
  return vRebut;
end;

procedure SetDirtyAllNPLunaAGREGARE(ConsumPonderat in number default 0, cuPMP in number default 0, cuRebuturi in number default 0)
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCodComanda1 number(20);
aCant NUMBER(20,7);
aCantTot NUMBER(20,7);
aCantProdus number(20,7);
ComandaInchisa NUMBER(1);
aCount number;
aCount2 number;
BEGIN
  delete tmp_manevra;
  delete manevra_unic;
  aCount2 := 0;
  FOR V_REC in
  (SELECT I1.CODINTR1, I1.PU, I1.CODOBIECT, i.codintr, COALESCE(IOA1.DIFPRET,0) DIFPRET, I1.CODCMDINT1
   FROM
     INTRARI I,
     INTRARI1 I1,
     NIR,
     NIRSTOC NS,
     IOART1 IOA1
   WHERE
     I.TIPDOC = 7
     AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
     AND I1.CODINTR = I.CODINTR AND NIR.CODINTR = I.CODINTR AND NS.CODNIR = NIR.CODNIR AND IOA1.CODIOART = NS.CODIOART
     AND PKG_GLOBALS.ANLUCRU*12+PKG_GLOBALS.LUNALUCRU BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND NS.CODINTR1 = I1.CODINTR1
     AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
  )
  LOOP
    aCount2 := aCount2 + 1;
    Rez := 0;
    for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
      Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
    end loop;
    if Rez = 0 then
      aCodComanda1 := 0;
      BEGIN
        SELECT
          coalesce(CP.CodComanda1, 0), CP.Cant, coalesce(C.INCHISA,0) INTO aCodComanda1, aCantProdus, COMANDAINCHISA
        FROM
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         COMANDA C,
         PRODCOMP PC
        WHERE
         IL.CODINTR1 = V_REC.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP
         AND CP.TIP = 0
         AND coalesce(PC.TIPRETETA,1) = 1
         AND C1.CODCOMANDA = C.CODCOMANDA;
         EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
      END;
      aCant := GetPredariInLuna(aCodComanda1);
      aCantTot := GetPredari(aCodComanda1);
      if cuRebuturi &gt; 0 then
        aCant := aCant + GetRebuturiInLuna(aCodComanda1);
        aCantTot := aCantTot + GetRebuturi(aCodComanda1);
      end if;
      if (aCodComanda1 &gt; 0)and(aCant &lt;&gt; 0.0) then
        if coalesce(ConsumPonderat,0) = 1 then
          aPret := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1, 0, cuPMP) / aCantTot;
        else
          aPret := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1, 0, cuPMP)/aCant;
        end if;
        IF aPRET &lt;&gt; 0 THEN
          if v_rec.difpret &gt; 0 then
            PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET, 3);
          else
            PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET, ConsumPonderat);
          end if;
          select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
          if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
          -- si pentru rebuturi
          if cuRebuturi &gt; 0 then
            FOR V_TMP IN (
              select I1.CODINTR, I1.CODINTR1
              from intrari1 i1
                   inner join intrari i on i1.codintr = i.codintr
              where i1.codcmdint1 = V_REC.CODCMDINT1
                    AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPTRANZACTIE = 9) LOOP
              if v_rec.difpret &gt; 0 then
                PKG_JURNAL.SETDIRTYNP(V_TMP.CODINTR1, aPRET, 3);
              else
                PKG_JURNAL.SETDIRTYNP(V_TMP.CODINTR1, aPRET, ConsumPonderat);
              end if;
              select count(*) into aCount from tmp_manevra where codunic = v_tmp.CODINTR;
              if aCount = 0 then insert into tmp_manevra(codunic) values (v_tmp.codintr); end if;
            END LOOP;
          end if;
          commit;
        END IF;
        commit;
      END IF;
    end if;
  END LOOP;
  if ConsumPonderat = 1 then
    for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                  from tmp_manevra tmp
                       inner join intrari i on i.codintr = tmp.codunic
                 ) loop
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                        PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                        v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale  AGREGARE  (consum ponderat cu predarile)&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
      commit;
    end loop;
  else if ConsumPonderat = 0 then
    for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                  from tmp_manevra tmp
                       inner join intrari i on i.codintr = tmp.codunic
                 ) loop
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                        PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                        v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale  AGREGARE&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
      commit;
    end loop;
  else
    for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                  from tmp_manevra tmp
                       inner join intrari i on i.codintr = tmp.codunic
                 ) loop
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                        PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                        v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale  AGREGARE  (fara afectare pret inregistrare)&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
      commit;
    end loop;
  end if;
  end if;
END;

procedure SetDirtyAllNPLunaAGREGARERebut
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCodComanda1 number(20);
aCant NUMBER(20,7);
aCantProdus number(20,7);
ComandaInchisa NUMBER(1);
aCount number;
BEGIN
delete tmp_manevra;
FOR V_REC in
(SELECT I1.CODINTR1, I1.PU, I.TIPTRANZACTIE, I.CODINTR
 FROM
   INTRARI I,
   INTRARI1 I1
 WHERE
   I.TIPDOC = 7
   AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
   AND I1.CODINTR = I.CODINTR
   AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
 order by i.codintr,i1.codintr1
 )
 LOOP
    Rez := 0;
    for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
      Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
    end loop;
    if Rez = 0 then
      aCodComanda1 := 0;
      BEGIN
        SELECT
          coalesce(CP.CodComanda1, 0), CP.Cant, coalesce(C.INCHISA,0) INTO aCodComanda1, aCantProdus, COMANDAINCHISA
        FROM
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         COMANDA C,
         PRODCOMP PC
        WHERE
         IL.CODINTR1 = V_REC.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP
         AND CP.TIP = 0
         AND coalesce(PC.TIPRETETA,1) = 1
         AND C1.CODCOMANDA = C.CODCOMANDA;
         EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
      END;
      if aCodComanda1 = 0 and v_rec.tiptranzactie = 9 then
        --nota de rebut
        BEGIN
          SELECT
            coalesce(CP.CodComanda1, 0), CP.Cant, coalesce(C.INCHISA,0) INTO aCodComanda1, aCantProdus, COMANDAINCHISA
          FROM
           INTRARI1 I1,
           CMDPRODMAT CP,
           COMANDA1 C1,
           COMANDA C,
           PRODCOMP PC
          WHERE
           I1.CODINTR1 = V_REC.CODINTR1
           AND I1.CODCMDINT1 = C1.CODCOMANDA1
           AND CP.CODCOMANDA1 = C1.CODCOMANDA1
           AND C1.CODRETETA = PC.CODPRODCOMP
           AND CP.TIP = 0
           AND coalesce(PC.TIPRETETA,1) = 1
           AND C1.CODCOMANDA = C.CODCOMANDA;
           EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
        END;
      end if;
      aCant := GetPredariInLunaCuRebut(aCodComanda1);
      if (aCodComanda1 &gt; 0)and(aCant &lt;&gt; 0.0) then
        aPret := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1, 0)/aCant;
        IF aPRET &lt;&gt; 0 AND aPRET &lt;&gt; coalesce(V_REC.PU, 0) THEN
          PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET);
          select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
          if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
          commit;
        END IF;
      END IF;
    end if;
  END LOOP;
  for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                from tmp_manevra tmp
                     inner join intrari i on i.codintr = tmp.codunic
               ) loop
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                      PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                      v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret (inclusv pe rebut) = valoarea consumurilor reale AGREGARE&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
    commit;
  end loop;
END;

procedure SetDirtyAllNPLunaAGREGAREMan(ManReal in number default 0)
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCodComanda1 number(20);
aCantTot NUMBER(20,7);
aCantProdus number(20,7);
ComandaInchisa NUMBER(1);
cValManInPret number(5);
cTipCoefIndirecte number(5);
CoefIndirecte number(20,7);
ValMan number(20,7);
TotalMan number(20,7);
aCount number;
BEGIN
 delete tmp_manevra;
 SELECT pkg_categconst.GetValConstanta(&apos;TipCoefIndirecte&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) INTO cTipCoefIndirecte from dual;
 SELECT pkg_categconst.GetValConstanta(&apos;ValManInPret&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) INTO cValManInPret from dual;

 FOR V_REC in
 (SELECT CODINTR1, PU, I.CODINTR
  FROM
    INTRARI I,
    INTRARI1 I1
  WHERE
    I.TIPDOC = 7
    AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
    AND I1.CODINTR = I.CODINTR
    AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
  order by i.codintr,i1.codintr1
 )
 LOOP
   Rez := 0;
   for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
     Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
   end loop;
   if Rez = 0 then
     aCodComanda1 := 0;
     BEGIN
       SELECT
         coalesce(CP.CodComanda1, 0), CP.Cant, coalesce(C.INCHISA,0), coalesce(PC.COEFINDIRECTE,0), coalesce(pc.valman,0), coalesce((select sum(coalesce(valoare, 0)) from prodman where codprodcomp = pc.codprodcomp),0)
         INTO aCodComanda1, aCantProdus, COMANDAINCHISA, CoefIndirecte, ValMan, TotalMan
       FROM
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         COMANDA C,
         PRODCOMP PC
       WHERE
         IL.CODINTR1 = V_REC.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP
         AND CP.TIP = 0
         AND coalesce(PC.TIPRETETA,1) = 1
         AND C1.CODCOMANDA = C.CODCOMANDA;
     EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
     END;
     aCantTot := GetPredari(aCodComanda1);
     if (aCodComanda1 &gt; 0)and(aCantTot &lt;&gt; 0.0) then
       aPret := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1,0)/aCantTot;
       IF cTipCoefIndirecte = 1 THEN
         aPret := aPret * (1.0 + CoefIndirecte);
       ELSE
         IF cTipCoefIndirecte = 3 THEN
           aPret := aPret + CoefIndirecte;
         END IF;
       END IF;
       if ManReal &gt; 0 then
         aPret := aPret + pkg_pretprod.GetValManReal(aCodComanda1)/aCantTot;
       else
         if cValManInPret = 1 then
           aPret := aPret + ValMan;
         else
           aPret := aPret + TotalMan;
         end if;
       end if;  
       IF aPRET &lt;&gt; 0 AND aPRET &lt;&gt; coalesce(V_REC.PU, 0) THEN
         PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET);
         select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
         if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
         commit;
       END IF;
     END IF;
    end if;
  END LOOP;
  for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                from tmp_manevra tmp
                     inner join intrari i on i.codintr = tmp.codunic
               ) loop
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                      PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                      v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale  + manopera AGREGARE&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
    commit;
  end loop;
END;

procedure SetDirtyAllNPLunaAGREGAREManX
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCodComanda1 number(20);
aCantTot NUMBER(20,7);
aCantProd NUMBER(20,7);
aCantProdus number(20,7);
ComandaInchisa NUMBER(1);
cValManInPret number(5);
cTipCoefIndirecte number(5);
CoefIndirecte number(20,7);
ValMan number(20,7);
TotalMan number(20,7);
aCount number;
aValMan number(20,7);
aValConsum number(20,7);
aAnP number(20);
aLunaP number(20);
aValPredPrec number(20,7);
aCantPredPrec number(20,7);

  function GetValPredariLunaPrec return number is
  vVal number(20,7);
  begin
    begin
      select coalesce(sum(il.cant*i1.pu),0), coalesce(sum(il.cant),0) into vVal, aCantPredPrec
      from intrprodlink il
           inner join cmdprodmat prod on prod.codcmdprodmat = il.codliniecomanda
           inner join intrari1 i1 on il.codintr1 = i1.codintr1
           inner join intrari i on i1.codintr = i.codintr
      where prod.codcomanda1 = aCodComanda1 and prod.tip = 0
            AND I.AN*12+I.LUNA &lt;= aAnP*12+aLunaP;
    exception when others then vVal := 0;
    end;
    return vVal;
  end;

BEGIN
 delete tmp_manevra;
 SELECT pkg_categconst.GetValConstanta(&apos;TipCoefIndirecte&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) INTO cTipCoefIndirecte from dual;
 SELECT pkg_categconst.GetValConstanta(&apos;ValManInPret&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) INTO cValManInPret from dual;
 pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU,aAnP,aLunaP);

 FOR V_REC in
 (SELECT CODINTR1, PU, I.CODINTR, I1.CANT
  FROM
    INTRARI I,
    INTRARI1 I1
  WHERE
    I.TIPDOC = 7
    AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
    AND I1.CODINTR = I.CODINTR AND COALESCE(I1.CANT,0) &lt;&gt; 0
    AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
  order by i.codintr,i1.codintr1
 )
 LOOP
   Rez := 0;
   for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
     Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
   end loop;
   if Rez = 0 then
     aCodComanda1 := 0;
     BEGIN
       SELECT
         coalesce(CP.CodComanda1, 0), CP.Cant, coalesce(C.INCHISA,0), coalesce(PC.COEFINDIRECTE,0), coalesce(pc.valman,0), coalesce((select sum(coalesce(valoare, 0)) from prodman where codprodcomp = pc.codprodcomp),0), PROD.CANT CANTPROD
         INTO aCodComanda1, aCantProdus, COMANDAINCHISA, CoefIndirecte, ValMan, TotalMan, aCantProd
       FROM
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         COMANDA C,
         PRODCOMP PC,
         CMDPRODMAT PROD
       WHERE
         IL.CODINTR1 = V_REC.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP
         AND CP.TIP = 0
         AND coalesce(PC.TIPRETETA,1) = 1
         AND C1.CODCOMANDA = C.CODCOMANDA
         AND C1.CODCOMANDA1 = PROD.CODCOMANDA1 AND PROD.TIP = 0;
     EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
     END;
     aCantTot := GetPredariInLuna(aCodComanda1);
     if (aCodComanda1 &gt; 0)and(aCantTot &lt;&gt; 0.0) then
       aValCOnsum := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1,0);
       aPret := coalesce(aValConsum,0);
       IF cTipCoefIndirecte = 1 THEN
         aPret := aPret * (1.0 + CoefIndirecte);
       ELSE
         IF cTipCoefIndirecte = 3 THEN
           aPret := aPret + coalesce(CoefIndirecte,0);
         END IF;
       END IF;
       aValMan := pkg_pretprod.GetValManReal(aCodComanda1);
       aPret := aPret + coalesce(aValMan,0);
       aValPredPrec := GetValPredariLunaPrec;
       aPret := aPret - coalesce(aValPredPrec,0);
       if aCantProd - coalesce(aCantPredPrec,0) &lt;= 0 then
         aPret := aPret/V_REC.CANT;
       else
         aPret := aPret/(aCantProd - coalesce(aCantPredPrec,0));
       end if;  
       IF aPRET &lt;&gt; 0 AND aPRET &lt;&gt; coalesce(V_REC.PU, 0) THEN
         PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aPRET);
         select count(*) into aCount from tmp_manevra where codunic = v_rec.CODINTR;
         if aCount = 0 then insert into tmp_manevra(codunic) values (v_rec.codintr); end if;
         commit;
       END IF;
     END IF;
    end if;
  END LOOP;
  for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                from tmp_manevra tmp
                     inner join intrari i on i.codintr = tmp.codunic
               ) loop
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                      PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                      v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale (poonderate)  + manopera reala AGREGARE&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
    commit;
  end loop;
END;

function GetPredariInLuna(vCodComanda1 in number) return number is
vPredat number(20,7);
begin
  begin
    select coalesce(sum(il.cant),0) into vPredat
    from intrprodlink il
         inner join cmdprodmat prod on prod.codcmdprodmat = il.codliniecomanda
         inner join intrari1 i1 on il.codintr1 = i1.codintr1
         inner join intrari i on i1.codintr = i.codintr
    where prod.codcomanda1 = vCodComanda1 and prod.tip = 0
          AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU;
  exception when others then vPredat := 0;
  end;
  return vPredat;
end;

function GetPredariInLunaCuRebut(vCodComanda1 in number) return number is
vPredat number(20,7);
vRebut number(20,7);
begin
  begin
    select coalesce(sum(il.cant),0) into vPredat
    from intrprodlink il
         inner join cmdprodmat prod on prod.codcmdprodmat = il.codliniecomanda
         inner join intrari1 i1 on il.codintr1 = i1.codintr1
         inner join intrari i on i1.codintr = i.codintr
    where prod.codcomanda1 = vCodComanda1 and prod.tip = 0
          AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU;
  exception when others then vPredat := 0;
  end;
  begin
    select coalesce(sum(i1.cant),0) into vRebut
    from intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    where i1.codcmdint1 = vCodComanda1
          AND I.AN = PKG_GLOBALS.ANLUCRU AND I.LUNA = PKG_GLOBALS.LUNALUCRU
          AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPTRANZACTIE = 9;
  exception when others then vRebut := 0;
  end;
  return vPredat+vRebut;
end;

function GetPredari(vCodComanda1 in number) return number is
vPredat number(20,7);
begin
  begin
    select coalesce(sum(il.cant),0) into vPredat
    from intrprodlink il
         inner join cmdprodmat prod on prod.codcmdprodmat = il.codliniecomanda
         inner join intrari1 i1 on il.codintr1 = i1.codintr1
         inner join intrari i on i1.codintr = i.codintr
    where prod.codcomanda1 = vCodComanda1 and prod.tip = 0;
  exception when others then vPredat := 0;
  end;
  return vPredat;
end;

function GetPredariDez(vCodComanda1 in number) return number is
vPredat number(20,7);
begin
  begin
    select coalesce(sum(il.cant),0) into vPredat
    from intrprodlink il
         inner join cmdprodmat prod on prod.codcmdprodmat = il.codliniecomanda
         inner join intrari1 i1 on il.codintr1 = i1.codintr1
         inner join intrari i on i1.codintr = i.codintr
    where prod.codcomanda1 = vCodComanda1 and coalesce(prod.reziduu,0) = 0;
  exception when others then vPredat := 0;
  end;
  return vPredat;
end;

procedure SetDirtyAllNPLunaDEZAGREGARE(ConsumPonderat in number default 0)
is
aPRET NUMBER(20, 7);
Rez   NUMBER;
aCodComanda1 number(20);
aCant NUMBER(20, 7);
aCantTot number(20,7);
aCant1 NUMBER(20, 7);
TotUM1Predat NUMBER(20, 7);
TotUM1PredatTot NUMBER(20, 7);
aUM1 number(20);
aZecimale number(10);
aValRezid number(20,7);
aVal number(20,7);
aNewPret number(20,7);
aCantProdus number(20,7);
COMANDAINCHISA NUMBER(1);
aCount number;
BEGIN
  --pkg_globals.SetLunaLucru_SIMPLA(2015,4);
  delete tmp_manevra;
  FOR V_I in (SELECT CODINTR
              FROM INTRARI I
              WHERE I.TIPDOC = 7
              --and i.codintr = 128454
              AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
              AND (PKG_LIST_SELECTSCAD.ToateGestN &gt; 0  OR EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE T.FILTRU = &apos;CODGEST&apos; AND T.VALOARE = I.CODGESTPROD))
              order by i.codintr
             ) LOOP
    --testez daca toate art sunt de pe aceeasi comanda
    aUM1 := -1;
    BEGIN
      SELECT DISTINCT coalesce(c1.UMsec, 0) INTO aUM1
      FROM
       INTRARI1 I1,
       INTRPRODLINK IL,
       CMDPRODMAT CP,
       COMANDA1 C1,
       PRODCOMP PC,
       NART A,
       NARTOBJ O
      WHERE
       I1.CODINTR  = V_I.CODINTR
       AND O.CodObiect = I1.CodObiect
       AND A.CodArticol = O.CodArticol
       AND IL.CODINTR1 = I1.CODINTR1
       AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
       AND CP.CODCOMANDA1 = C1.CODCOMANDA1
       AND C1.CODRETETA = PC.CODPRODCOMP
       AND CP.TIP       = 2
       AND CP.REZIDUU  &lt;&gt; 1
       AND PC.TIPRETETA = 2;
    EXCEPTION WHEN OTHERS THEN
      aUM1 := -1;
    END;

    if aUM1 &lt;&gt; -1 then

      SELECT coalesce(ZECIMALE,0) INTO aZECIMALE FROM NUM1 WHERE CODUM1 = aUM1;

      aCodComanda1 := 0;
      BEGIN
        SELECT DISTINCT coalesce(CP.CodComanda1, 0), coalesce(C.INCHISA,0) INTO aCodComanda1, COMANDAINCHISA
        FROM
         INTRARI1 I1,
         INTRPRODLINK IL,
         CMDPRODMAT CP,
         COMANDA1 C1,
         COMANDA C,
         PRODCOMP PC
        WHERE
         I1.CODINTR  = V_I.CODINTR
         AND IL.CODINTR1 = I1.CODINTR1
         AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
         AND CP.CODCOMANDA1 = C1.CODCOMANDA1
         AND C1.CODRETETA = PC.CODPRODCOMP
         AND PC.TIPRETETA = 2
         AND C1.CODCOMANDA = C.CODCOMANDA;
         EXCEPTION WHEN OTHERS  THEN aCodComanda1 := 0;
      END;
      -- daca sunt toate liniile de pe aceeasi comanda merg mai departe
      if aCodComanda1 &gt; 0 then
      -- se pot rezolva NIRSTOCURILE
        Rez := 0;
        TotUM1Predat := 0;
        TotUM1PredatTot := 0;
        FOR V_REC in
        (SELECT I1.CODINTR1, I1.Cant, CP.D1, CP.D2, CP.D3, A.Relatieum1, CP.CANT CANTPRODUS, I.An, I.Luna
         FROM
           INTRARI I,
           INTRARI1 I1,
           INTRPRODLINK IL,
           CMDPRODMAT CP,
           NART A,
           NARTOBJ O
         WHERE
           I1.CODINTR  = I.CODINTR
           AND IL.CODINTR1 = I1.CODINTR1
           AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
           AND CP.REZIDUU &lt;&gt; 1
           AND A.CodArticol = O.CODARTICOL
           AND I1.Codobiect = O.Codobiect
           AND CP.CODCOMANDA1 = aCodComanda1
           AND I.TIPDOC = 7
         )
         LOOP
            for v_N in (Select NS.CodNIRSTOC from NIRSTOC NS where NS.CodIntr1 = V_REC.CodIntr1) loop
              Rez := Rez + TestDirtyNirStoc(V_N.CodNirStoc, 0);
            end loop;

            if (v_REC.Cant = 0.0) then
              aCant1 := 0.0;
            else
              aCant1 := GetSpecificCantUM1(V_REC.RelatieUM1, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.Cant);
            end if;

            TotUM1PredatTot := TotUM1PredatTot + Round(aCant1, aZECIMALE);
            if v_rec.AN = PKG_GLOBALS.GETANLUCRU AND v_rec.LUNA = PKG_GLOBALS.GETLUNALUCRU then
              TotUM1Predat := TotUM1Predat + Round(aCant1, aZECIMALE);
            end if;
            ACANTPRODUS := V_REC.CANTPRODUS;
         end loop;

         if (Rez = 0) and (TotUM1Predat &lt;&gt; 0) then  -- nirstoc nasol sau tot predat in UMSpec este null
           -- calculez valoare reziduuri
           aValRezid := 0;
           BEGIN
             SELECT Sum( coalesce(I1.Cant, 0)*coalesce(I1.PU, 0)) INTO aValRezid
             FROM
              INTRARI I,
              INTRARI1 I1,
              INTRPRODLINK IL,
              CMDPRODMAT CP,
              COMANDA1 C1,
              PRODCOMP PC
             WHERE
              I1.CODINTR  = I.CODINTR
              AND IL.CODINTR1 = I1.CODINTR1
              AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
              AND CP.CODCOMANDA1 = C1.CODCOMANDA1
              AND C1.CODRETETA = PC.CODPRODCOMP
              AND CP.REZIDUU = 1
              AND PC.TIPRETETA = 2
              AND CP.CODCOMANDA1 = aCodComanda1
              AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
              AND I.TIPDOC = 7
              order by i1.codintr1;
           EXCEPTION WHEN OTHERS  THEN aValRezid := 0;
           END;
           IF coalesce(ConsumPonderat,0) &lt;&gt; 0 then
             aNewPret  := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1, 1) - coalesce(aValRezid,0);
             FOR V_REC in
               (SELECT I1.CODINTR1, I1.Cant, CP.D1, CP.d2, CP.D3, A.RelatieUM1, I1.PU
                FROM
                  INTRARI1 I1,
                  INTRPRODLINK IL,
                  CMDPRODMAT CP,
                  COMANDA1 C1,
                  PRODCOMP PC,
                  NART A,
                  NARTOBJ O
                WHERE
                  I1.CODINTR = V_I.CODINTR
                  AND IL.CODINTR1 = I1.CODINTR1
                  AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
                  AND CP.CODCOMANDA1 = C1.CODCOMANDA1
                  AND C1.CODRETETA = PC.CODPRODCOMP
                  AND coalesce(CP.REZIDUU,0) &lt;&gt; 1
                  AND PC.TIPRETETA = 2
                  AND I1.Codobiect = O.CodObiect
                  AND O.Codarticol = A.Codarticol
                order by i1.codintr1
                )
                LOOP
                  if (V_REC.Cant &lt;&gt; 0.0) then
                    if (V_REC.Cant &lt;&gt; 0.0) then
                      IF aNewPRET * round(GetSpecificCantUM1(V_REC.RelatieUM1, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.Cant),azecimale) / TotUM1PredatTot / v_rec.cant &lt;&gt; 0
                         AND aNewPRET * round(GetSpecificCantUM1(V_REC.RelatieUM1, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.Cant),azecimale) / TotUM1PredatTot / v_rec.cant &lt;&gt; coalesce(V_REC.PU, 0) THEN
                         PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aNewPRET * round(GetSpecificCantUM1(V_REC.RelatieUM1, V_REC.D1, V_REC.D2, V_REC.D3, V_REC.Cant),azecimale) / TotUM1PredatTot / v_rec.cant);
                         select count(*) into aCount from tmp_manevra where codunic = v_i.CODINTR;
                         if aCount = 0 then insert into tmp_manevra(codunic) values (v_i.codintr); end if;
                         commit;
                      END IF;
                    end if;
                  end if;
             END LOOP;
           ELSE
             aVal := PKG_PRODCOMP.GET_VALORE_PRODUS(aCodcomanda1, 1) - coalesce(aValRezid,0);
             aPret := aVal / TotUM1Predat;

             FOR V_REC in
             (SELECT I1.CODINTR1, I1.Cant, CP.D1, CP.d2, CP.D3, A.RelatieUM1, I1.PU
              FROM
                INTRARI1 I1,
                INTRPRODLINK IL,
                CMDPRODMAT CP,
                COMANDA1 C1,
                PRODCOMP PC,
                NART A,
                NARTOBJ O
              WHERE
                I1.CODINTR = V_I.CODINTR
                AND IL.CODINTR1 = I1.CODINTR1
                AND CP.CODCMDPRODMAT = IL.CODLINIECOMANDA
                AND CP.CODCOMANDA1 = C1.CODCOMANDA1
                AND C1.CODRETETA = PC.CODPRODCOMP
                AND coalesce(CP.REZIDUU,0) &lt;&gt; 1
                AND PC.TIPRETETA = 2
                AND I1.Codobiect = O.CodObiect
                AND O.Codarticol = A.Codarticol
              )
              LOOP
                if (V_REC.Cant &lt;&gt; 0.0) then
                  aCant := coalesce(v_rec.Cant, 0);
                  aCant1 := Round(GetSpecificCantUM1(V_REC.RelatieUM1, V_REC.D1, V_REC.D2, V_REC.D3, aCant), aZecimale);
                  aNewPret  := Round( aPret * aCant1 / aCant, 2 );
                  IF aNewPRET &lt;&gt; 0 AND aNewPRET &lt;&gt; coalesce(V_REC.PU, 0) THEN
                    PKG_JURNAL.SETDIRTYNP(V_REC.CODINTR1, aNewPRET);
                    select count(*) into aCount from tmp_manevra where codunic = v_i.CODINTR;
                    if aCount = 0 then insert into tmp_manevra(codunic) values (v_i.codintr); end if;
                    commit;
                  END IF;
                end if;
           END LOOP;
           END IF;
         end if;
        end if;
      end if;
  END LOOP;
  if ConsumPonderat &gt; 0 then
    for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                  from tmp_manevra tmp
                       inner join intrari i on i.codintr = tmp.codunic
                 ) loop
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                        PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                        v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale DEZAGREGARE  (consum ponderat cu predarile)&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
      commit;
    end loop;
  else
    for v_rec in (select tmp.codunic, i.subunitatea, i.datadoc, i.PREFIXDOC||i.NRDOC||&apos;/&apos;||i.DATADOC Doc
                  from tmp_manevra tmp
                       inner join intrari i on i.codintr = tmp.codunic
                 ) loop
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_11&apos;) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;INTRARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codunic,
                                        PKG_GLOBALS.FIRMANAME, v_rec.Subunitatea, v_rec.DataDoc,
                                        v_rec.Doc, &apos;modificare pret predare prin optiunea: Pret = valoarea consumurilor reale DEZAGREGARE&apos;, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      NotifyModif(0, v_rec.codunic, &apos;INTRARI&apos;);
      commit;
    end loop;
  end if;
END;

PROCEDURE UPDATE_JURN_FROM_MAN
IS
BEGIN
  IF PKG_SERVICE.TIPJURNAL = 0
  THEN
    DELETE FROM JURNAL WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  ELSE
    DELETE FROM JURNAL J
    WHERE
          AN   = PKG_GLOBALS.ANLUCRU
      AND LUNA = PKG_GLOBALS.LUNALUCRU
      AND EXISTS(SELECT * FROM JURNAL1 J1
                 WHERE
                   J1.AN         = PKG_GLOBALS.ANLUCRU
                   AND J1.LUNA   = PKG_GLOBALS.LUNALUCRU
                   AND J1.TIPDOC = J.TIPDOC
                   AND J1.CODDOC = J.CODDOC
                   AND DIRTY     &gt; 0
                 );
  END IF;


  INSERT INTO JURNAL
 (SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST,
  VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, document, CODCENTRU, VALOAREGRUP,CODANALIZANOD, VALOARE_IFRS, VALOAREV_IFRS
  FROM MAN_JURNAL);


  IF PKG_SERVICE.TIPJURNAL = 0
  THEN
    DELETE FROM JURNAL1 WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  ELSE
     DELETE FROM JURNAL1 WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND DIRTY &gt; 0;
  END IF;

  INSERT INTO JURNAL1
  (SELECT  SEQ_JURNAL1_CODJURNAL1.NEXTVAL, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, TIPBAZAD, ICONTBAZAD,CODDESCRD,
           ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC,
           TIPBAZAC, ICONTBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,document, CODCENTRU, VALOAREGRUP,
           CODANALIZANOD,
           VALOARE_IFRS,
           VALOAREV_IFRS
   FROM MAN_JURNAL1);
END;



procedure RecalculPRETAchiz(aCodLinieAE in number) is
aCant     number(20, 7);
aTVA      number(20, 7);
aOldTVA   number(20, 7);
aProcTVA  number(20, 7);
aVal      number(20, 7);
aPret     number(20, 7);
aOldPret  number(20, 7);
newpret   number(20, 7);
aNewCurs  number(20, 7);
aOldCurs  number(20, 7);
aadaos     number(20, 7);
DifVal    number(20, 7);
DifTVA    number(20, 7);
aSupl     number(20, 7);

aCodObiect number(20);
aCodDoc    number(20);
aCODPART   number(20);
aTIPDOC    NUMBER(5);

aAn         number(5);
aLuna       number(2);
aTipTVA     number(2);
TipTVADoc   number(2);
aVALDOC     NUMBER(20, 7);
aTVADOC     NUMBER(20, 7);
aMONEDA     NUMBER(20);
aCODGENERAL NUMBER(20);
NR          number(5);
aVALOBLIG   NUMBER(20, 7);
aDATADOC    DATE;
UrmarirePUVAL varchar2(10);

VALSUPLIM   NUMBER(20, 7) := 0;
VALTOT      NUMBER(20, 7) := 0;
VS          NUMBER(20, 7) := 0;
TIPSUPLIM  NUMBER(5) := 0;

CursPUVAL   NUMBER(20, 7);
aPUVAL   NUMBER(20, 7);


begin
--  insert into xxx (xxx, yyy, ooo) values (0, aCodLinieAE, &apos;setDirtyIntrAE=aCodLinieAE &apos;);
--calculez pret mediu

  SELECT COUNT(*) INTO NR FROM INTRLINK WHERE CODLINIEAVIZ = aCODLINIEAE;
  IF NR &gt; 0 THEN
     Select Sum(coalesce(i1.Cant, 0)), sum(coalesce(i1.PU,0)*coalesce(i1.Cant, 0)) into aCant, aVal
     from intrlink k, Intrari i, Intrari1 i1
     where k.CodLinieAviz = aCodLinieAE
           and i1.Codintr1 = k.Codintr1
           and i.codintr = i1.codintr
           and i.Operat = 1;

     aPret := 0;
     if aCANT &lt;&gt; 0 then
       aPret := Round(aVal / aCant, 7);
     end if;
  ELSE
    BEGIN
      SELECT PU INTO aPRET FROM INTRARI1 WHERE CODINTR1 = aCODLINIEAE;
      EXCEPTION WHEN OTHERS THEN aPRET := 0;
    END;
  END IF;
--  insert into xxx (xxx, yyy, ooo) values (1, aPret, &apos;pret mediu&apos;);
  for v_rec in
  (select i.CodIntr CodDoc, i.TipDoc, i.Subunitatea, i.An, i.Luna, I.PARTENER, I.DATADOC, I.VALSUPLIM, I.TIPREPSUPLIM, I.VALTRANSPORT, I.TIPTVA
  from Intrari1 i1, intrari i
  where i1.codintr1 = aCodLinieAE and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn       := v_rec.An;
    aLuna     := v_rec.Luna;
    aCodDoc   := v_rec.CodDoc;
    aTIPDOC   := v_rec.tipdoc;
    TIPTVADOC := V_REC.TIPTVA;
    aCODPART  := V_REC.PARTENER;
    aDATADOC  := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0) + coalesce(V_REC.VALTRANSPORT, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;

  -- update pret intrare pe aviz
  select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
  from intrari1 where CodIntr1 = aCodLinieAE;

  CursPUVAL := 1;
  SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
  IF UrmarirePUVAL = &apos;1&apos; THEN
    BEGIN
      CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                   pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                   pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                   TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                   );
    EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
    END;
  END IF;


  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aTIPTVA := &apos;0&apos;;
  END;
  
  if aTIPDOC &lt;&gt; 2 AND COALESCE(TIPTVADOC, 0) IN (5, 6, 7) then ATVA := 0;
  else    
  if aTIPTVA = 1 AND aTIPDOC = 2 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := Round(aPret * aCant * aProcTVA / 100, 6);
  end if;
  end if;




  update intrari1 I1
  set
    PU       = aPret,
    PRETORIG =  CASE
                  WHEN coalesce(I1.COEFDISCMAJ, 1) = 0 THEN aPRET
                  ELSE aPret / coalesce(I1.COEFDISCMAJ, 1)
                END,
    TVA = aTVA
  where
    CodIntr1 = aCodLinieAE;



  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := 1;
  select Curs into aOldCurs from Intrari where CodIntr = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

  UPDATE INTRARI I
  SET
    Curs   = aNewCurs,
    VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
    TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
  WHERE
    I.CODINTR = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 408;
  BEGIN
   SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0),  coalesce(PARTENER, 0)
   INTO
     aVALDOC, aTVADoc, aMONEDA, aCODPART
    FROM
      INTRARI
    WHERE
      CODINTR = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0; aCODPART := 0;
  END;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140;

  aVALOBLIG := ROUND(aVALDOC - aTVADOC, 2) + ROUND(aTVADOC, 2);

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 2, aCODDOC, aMONEDA, aNewCurs, 140);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

  ELSE

    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 2 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140), aVALDOC, aVALDOC, 6, 140, aCODPART);
    END IF;



    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 2
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 140
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = aVALOBLIG,
         REST    = aVALOBLIG
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aNewCurs
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;

  -- recalcul suplimente pe nirstoc
  SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
  FROM
  (
    SELECT
      CASE
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
      END AS VALLINIE
    FROM
      NIRSTOC NS,
      INTRARI1 I1,
      NIR N,
      INTRARI I,
      NARTOBJ O
    WHERE
      NS.CODNIR       = N.CODNIR
      AND N.CODINTR   = aCODDOC
      AND I1.CODINTR1 = NS.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND O.CODOBIECT = NS.CODOBIECT
  );



 FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
               FROM
                 NIRSTOC NS,
                 NIR N,
                 INTRARI1 I1,
                 NARTOBJ O
                 WHERE
                   NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                   AND I1.CODINTR1 = NS.CODINTR1
                   AND O.CODOBIECT = NS.CODOBIECT
             )
 LOOP
   VS := 0;
   IF VALTOT &lt;&gt; 0 THEN
       IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
       ELSE
       IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
       ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
       END IF;
       END IF;
    END IF;

     UPDATE NIRSTOC
     SET
      SUPLIMENT = VS
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
 END LOOP;



  FOR V_REC IN
  ( SELECT
      NS.CODNIRSTOC,
      NS.PRET,
      NS.ADAOS,
      NS.CANTNIR,
      NS.SUPLIMENT,
      I1.PU,
      PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
    FROM
      NIRSTOC NS,
      NIR NR,
      INTRARI1 I1
    WHERE
      NR.CODNIR      = NS.CODNIR
      AND NR.CODINTR = ACODDOC
      AND I1.CODINTR1 = NS.CODINTR1
   -- N.CODINTR1=ACODLINIEAE
  )
  LOOP
  -- pentru toate nirstoc DE PE AVIZ, propag pret nou din acel codnirstoc
    ASUPL   := 0;
    IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
    aADAOS   := coalesce(V_REC.ADAOS, 0);

    IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
    END IF;

    NEWPRET := ROUND(/*APRET*/V_REC.PU * aNEWCURS + aADAOS + ASUPL, V_REC.ROTLEI);

    UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF URMARIREPUVAL = 1 THEN
      APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
      UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;

--  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
    SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);
  END LOOP;
END;

procedure setDirtyIntrAEAstept(aCodLinieAE in number, aPret IN NUMBER, aCurs in number) is
aCant         number(20, 7);
aTVA          number(20, 7);
aOldTVA       number(20, 7);
aProcTVA      number(20, 7);
aVal          number(20, 7);
aOldPret      number(20, 7);
newpret       number(20, 7);
aNewCurs      number(20, 7);
aOldCurs      number(20, 7);
aadaos         number(20, 7);
DifVal        number(20, 7);
DifTVA        number(20, 7);
aSupl         number(20, 7);

aCodObiect    number(20);
aCodDoc       number(20);
aCODPART      number(20);

aAn           number(5);
aLuna         number(2);
aTipTVA       number(2);
aVALDOC       NUMBER(20, 7);
aTVADOC       NUMBER(20, 7);
aMONEDA       NUMBER(20);
aCODGENERAL   NUMBER(20);
NR            number(5);
aVALOBLIG     NUMBER(20, 7);
aDATADOC      DATE;
UrmarirePUVAL varchar2(10);

VALSUPLIM     NUMBER(20, 7) := 0;
VALTOT        NUMBER(20, 7) := 0;
VS            NUMBER(20, 7) := 0;
TIPSUPLIM     NUMBER(5) := 0;

CursPUVAL     NUMBER(20, 7);
aPUVAL        NUMBER(20, 7);


begin
  for v_rec in
  (select i.CodIntr CodDoc, i.TipDoc, i.Subunitatea, i.An, i.Luna, I.PARTENER, I.DATADOC, I.VALSUPLIM, I.TIPREPSUPLIM, I.VALTRANSPORT
  from Intrari1 i1, intrari i
  where i1.codintr1 = aCodLinieAE and i.codintr = i1.codintr)
  loop
    --o singura inreg- si anume avizul de pe care e linia respectiva
--    insert into xxx (xxx, yyy, zzz, ooo) values (2, v_rec.coddoc, v_rec.tipdoc, &apos;setdirty ae&apos;);
    aAn   := v_rec.An;
    aLuna := v_rec.Luna;
    aCodDoc := v_rec.CodDoc;
    aCODPART := V_REC.PARTENER;
    aDATADOC := V_REC.DATADOC;
    VALSUPLIM := coalesce(V_REC.VALSUPLIM, 0) + coalesce(V_REC.VALTRANSPORT, 0);
    TIPSUPLIM := coalesce(V_REC.TIPREPSUPLIM, 0);
    SetDirty(v_rec.coddoc, v_rec.tipdoc, v_rec.Subunitatea, v_rec.An, v_rec.Luna);
  end loop;

  -- update pret intrare pe aviz
  select CodObiect, Cant, PU, TVA into aCodObiect, aCant, aOldPret, aOldTVA
  from intrari1 where CodIntr1 = aCodLinieAE;

  CursPUVAL := 1;
  SELECT pkg_categconst.GetValConstanta(&apos;UrmarirePUVAL&apos;, aAN, aLUNA) INTO UrmarirePUVAL from dual;
  IF UrmarirePUVAL = &apos;1&apos; THEN
    BEGIN
      CursPUVal := PKG_MONEDE.GETCURSMONEDA(
                   pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, aAN, aLUNA),
                   pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;, aAN, aLUNA),
                   TO_CHAR(aDATADOC, &apos;dd.mm.yyyy&apos;)
                   );
    EXCEPTION WHEN OTHERS THEN  CursPUVAl := 1;
    END;
  END IF;


  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;AvizFaraTVANeex&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aTipTVA FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aTIPTVA := &apos;0&apos;;
  END;
  if aTIPTVA = 1 then aTVA := 0;
  else
    select PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(aCodObiect), aAN, aLUNA) into aProcTVA from dual;
    aTVA := Round(aPret * aCant * aProcTVA / 100, 6);
  end if;


  update intrari1
  set
    PU       = aPret,
    PRETORIG = aPret
--    TVA = aTVA
  where
    CodIntr1 = aCodLinieAE;

  DifTVA :=  aTVA - aOldTVA;
  DifVal :=  aTVA - aOldTVA + (aPret - aOldPret ) * aCant ;

  aNewCurs := aCurs;
  select Curs into aOldCurs from Intrari where CodIntr = aCodDoc;
  if aOldCurs &lt;&gt; 1 then aNewCurs := aOldCurs; end if;

  UPDATE INTRARI I
  SET
    Curs   = aNewCurs,
    VALDOC = coalesce((SELECT SUM( coalesce(PU, 0) * coalesce(CANT, 0) + coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0),
    TVADOC = coalesce((SELECT SUM( coalesce(TVA, 0)) FROM INTRARI1 I1 WHERE I1.CODINTR = aCODDOC), 0)
  WHERE
    I.CODINTR = aCODDOC;

-- RECALCULEZ OBLIGATIILE PE 408;
  BEGIN
   SELECT coalesce(VALDOC,0), coalesce(TVADOC,0), coalesce(MONEDA,0),  coalesce(PARTENER, 0)
   INTO
     aVALDOC, aTVADoc, aMONEDA, aCODPART
    FROM
      INTRARI
    WHERE
      CODINTR = aCODDOC;
     EXCEPTION WHEN OTHERS THEN aVALDOC := 0; aTVADOC := 0; aTVADOC := 0; aMONEDA := 0; aCODPART := 0;
  END;

  SELECT COUNT(*) INTO NR FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140;

  aVALOBLIG := 0;

  IF NR = 0 THEN
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO aCODGENERAL FROM DUAL;

    INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (aCODGENERAL, 2, aCODDOC, aMONEDA, aNewCurs, 140);

    INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
    VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, aCODGENERAL, aVALOBLIG, aVALOBLIG, 6, 140, aCODPART );

  ELSE

    SELECT COUNT(*) INTO NR
    FROM
      OBLIGPIF O,
      GENERAL G
    WHERE
      G.TIPDOC = 2 AND G.CODDOC = aCODDOC AND G.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL;

    IF NR = 0 THEN
      INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, REST, ICONT, SEMNIFICATIE, CODPART)
      VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL, (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 2 AND CODDOC = aCODDOC AND SEMNIFICATIE = 140), 0, 0, 6, 140, aCODPART);
    END IF;



    FOR V_REC_OBLIG IN
    (
      SELECT
         O.CODOBLIGPIF,
         O.CODGENERAL
      FROM
        GENERAL G,
        OBLIGPIF O
      WHERE
            G.TIPDOC = 2
        AND G.CODDOC = aCODDOC
        AND G.SEMNIFICATIE = 140
        AND O.CODGENERAL = G.CODGENERAL
     )
     LOOP
       UPDATE OBLIGPIF
       SET
         VALOARE = 0,
         REST    = 0
       WHERE
         CODOBLIGPIF = V_REC_OBLIG.CODOBLIGPIF;

       UPDATE GENERAL
       SET
         CURS = aNewCurs
       WHERE
         CODGENERAL = V_REC_OBLIG.CODGENERAL;
     END LOOP;
  END IF;

  -- recalcul suplimente pe nirstoc
  SELECT coalesce(SUM(VALLINIE), 0) INTO VALTOT
  FROM
  (
    SELECT
      CASE
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 0 THEN (CANTNIR * I1.PU)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 1 THEN (CANTNIR * O.MASA)
        WHEN coalesce(I.TIPREPSUPLIM, 0) = 2 THEN (CANTNIR * O.VOLUM)
      END AS VALLINIE
    FROM
      NIRSTOC NS,
      INTRARI1 I1,
      NIR N,
      INTRARI I,
      NARTOBJ O
    WHERE
      NS.CODNIR       = N.CODNIR
      AND N.CODINTR   = aCODDOC
      AND I1.CODINTR1 = NS.CODINTR1
      AND I.CODINTR   = I1.CODINTR
      AND O.CODOBIECT = NS.CODOBIECT
  );



 FOR V_REC IN (SELECT NS.CODNIRSTOC, I1.PU, NS.CANTNIR, O.MASA, O.VOLUM
               FROM
                 NIRSTOC NS,
                 NIR N,
                 INTRARI1 I1,
                 NARTOBJ O
                 WHERE
                   NS.CODNIR = N.CODNIR AND N.CODINTR = aCODDOC
                   AND I1.CODINTR1 = NS.CODINTR1
                   AND O.CODOBIECT = NS.CODOBIECT
             )
 LOOP
   VS := 0;
   IF VALTOT &lt;&gt; 0 THEN
       IF TIPSUPLIM = 0 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.PU   / VALTOT;
       ELSE
       IF TIPSUPLIM = 1 THEN VS := VALSUPLIM * V_REC.CANTNIR * V_REC.MASA / VALTOT;
       ELSE VS := VALSUPLIM * V_REC.CANTNIR * V_REC.VOLUM / VALTOT;
       END IF;
       END IF;
    END IF;

     UPDATE NIRSTOC
     SET
      SUPLIMENT = VS
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
 END LOOP;



  FOR V_REC IN
  ( SELECT
      NS.CODNIRSTOC,
      NS.PRET,
      NS.ADAOS,
      NS.CANTNIR,
      NS.SUPLIMENT,
      I1.PU,
      PKG_INTRARI.ZECIMALEPRET(7 - coalesce(NS.ROTLEI, 0)) ROTLEI
    FROM
      NIRSTOC NS,
      NIR NR,
      INTRARI1 I1
    WHERE
      NR.CODNIR      = NS.CODNIR
      AND NR.CODINTR = ACODDOC
      AND I1.CODINTR1 = NS.CODINTR1
   -- N.CODINTR1=ACODLINIEAE
  )
  LOOP
  -- pentru toate nirstoc DE PE AVIZ, propag pret nou din acel codnirstoc
    ASUPL   := 0;
    IF V_REC.CANTNIR &lt;&gt; 0 THEN ASUPL := coalesce(V_REC.SUPLIMENT, 0) / V_REC.CANTNIR; END IF;
    aADAOS   := coalesce(V_REC.ADAOS, 0);

    IF coalesce(aNEWCURS, 0) = 0 THEN aNEWCURS := 1;
    END IF;

    NEWPRET := ROUND(/*APRET*/V_REC.PU * aNEWCURS + aADAOS + ASUPL, V_REC.ROTLEI);

    UPDATE NIRSTOC SET PRET = NEWPRET WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    IF URMARIREPUVAL = 1 THEN
      APUVAL :=  (NEWPRET - aADAOS) / CURSPUVAL;
      UPDATE NIRSTOC SET PUVAL = APUVAL WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;

--  SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, APRET);
    SETDIRTYNIRSTOC(V_REC.CODNIRSTOC, NEWPRET, URMARIREPUVAL, APUVAL);
  END LOOP;
END;

procedure TestGET_JURNAL_FULL
IS
sExtCols varchar2(5000);
sExtJoin varchar2(500);
BEGIN
  sExtCols := &apos;&apos;;
  sExtJoin := &apos;&apos;;
  if PKG_LIST_STRUCT.TmpExists(&apos;CENTREEXT&apos;) &gt; 0 then
    pkg_globals.SetSeparator(&apos;,&apos;);
    EXECUTE IMMEDIATE &apos;SELECT stragg3200(&apos;&apos;CCEXT.&apos;&apos;||C1.numecamp||&apos;&apos; AS CCEXT_&apos;&apos;||C1.NUMECAMP)
                             FROM CFGTABLES C, CFGTABLES1 C1
                             WHERE upper(C.NUMETABELA) = &apos;&apos;CENTREEXT&apos;&apos; AND C1.CODCFGTABLE = C.CODCFGTABLE&apos; INTO sExtCols;
    if sExtCols is Null then 
      sExtCols := &apos;&apos;;
		else
		  sExtCols := &apos;,&apos;||sExtCols;
      sExtJoin := &apos; LEFT JOIN CENTREEXT CCEXT ON CCEXT.CODCENTRU = CC.CODCENTRU&apos;;
		end if;
  end if;
END;

end PKG_JURNAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD3E6227D348F1E1B7C1A6E5E3F4A94565F4A8D5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LANSARE IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_36&apos;;

procedure ActualizeazaCopiiProiectMan(aTermen in date, aCodLansare0 in number, aCodProiectNod in number) is
begin
  for v_rec in (select CodLansare0, CodProiectNod, durata
                from manevra_proiectman
                where NodOriginal = aCodProiectNod and CodLansare0 = aCodLansare0) loop
    update manevra_proiectman set termen = to_date(to_char(aTermen,&apos;dd.mm.yyyy&apos;), &apos;dd.mm.yyyy&apos;) 
    where CodLansare0 = aCodLansare0 and CodProiectNod = v_rec.Codproiectnod;
    ActualizeazaCopiiProiectMan(aTermen - v_rec.durata/(24*60), aCodLansare0, v_rec.CodProiectNod);
  end loop;               
end;  

procedure ActualizeazaProiectMan(aCodLansare0 in number, aCodProiect in number, aTermen in varchar2) is
vDurata number;
vCodProiectNod number(20);
begin
  update manevra_proiectman set termen = to_date(aTermen, &apos;DD.MM.YYYY&apos;)
  where CodLansare0 = aCodLansare0 and NodOriginal = 0 and CodProiect = aCodProiect;
  select Durata, CodProiectNod into vDurata, vCodProiectNod from manevra_proiectman where CodLansare0 = aCodLansare0 and NodOriginal = 0 and CodProiect = aCodProiect;
  ActualizeazaCopiiProiectMan(to_date(aTermen, &apos;dd.mm.yyyy&apos;) - vDurata/(24*60), aCodLansare0, vCodProiectNod);
end;  

procedure STERGEREZERVAREOBIECT(aCodComanda1 IN NUMBER, aCodObiect IN NUMBER, aTip IN NUMBER) IS
pragma autonomous_transaction;
begin
-- cand tip e 1 sau 3
  if aTip &lt;&gt; 2 then delete rezervats where codobiect = aCodObiect and codcomanda1 = aCodComanda1; end if;

-- cand tip e 2 sau 3
  if aTip &lt;&gt; 1 then 
    for v_Rec in (select r.codrezervats 
                  from rezervats r
                       inner join nirstoc ns on r.codnirstoc = ns.codnirstoc
                  where ns.codobiect = aCodObiect and r.codcomanda1 = aCodComanda1) loop
      delete rezervats where codrezervats = v_rec.codrezervats;                 
    end loop;              
  end if;
  commit;
end;

function GetCopilMaxim(aNod in number, aCodLansare0 in number) return number is
x number;
y number;
begin
  select CopilMaxim into x from manevra_Proiectman where CodProiectNod = aNod and CodLansare0 = aCodLansare0;
  if x = -1 then 
    x := 0;
    for v_rec in (select * from  manevra_Proiectman WHERE NodOriginal = aNod and CodLansare0 = aCodLansare0) loop
      y := GetCopilMaxim(v_rec.CodProiectNod, aCodLansare0) + v_rec.Durata;
      if y &gt; x then x := y; end if;
    end loop;
    update manevra_proiectman set copilmaxim = x, DurataNod = Durata + x where CodProiectNod = aNod and CodLansare0 = aCodLansare0;
  end if;
  Return x;
end;

procedure SetCopilMaxim(aCodLansare0 in number) is
x number;
begin
  for v_rec in (select * from manevra_proiectman where codlansare0 = aCodLansare0 order by simbol desc) loop
    x := GetCopilMaxim(v_rec.CodProiectNod, aCodLansare0);
    update manevra_proiectman set copilmaxim = x, DurataNod = Durata + x where CodProiectNod = v_rec.CodProiectNod and CodLansare0 = aCodLansare0;
  end loop;
end;

procedure SetDrumCritic(aCodNod in number, aCodLansare0 in number) is
X number;
begin
  update manevra_proiectman set NodCritic = Simbol where CodProiectNod = aCodNod and CodLansare0 = aCodLansare0;
  begin
    select nvl(CopilMaxim, 0) into X from manevra_proiectman where CodProiectNod = aCodNod and CodLansare0 = aCodLansare0;
    exception when others then X := 0;
  end;

  for v_rec in (select CodProiectNod from manevra_proiectman where Nvl(DurataNod,0) = X and NODORIGINAL = aCodNod and CodLansare0 = aCodLansare0) loop
    SetDrumCritic(v_rec.CodProiectNod, aCodLansare0);
  end loop;
end;

procedure SetDecalaj(aCodNod in number, Total in number, aCodLansare0 in number) is
DurataParinte number;
DecalajParinte number;
begin
  update manevra_proiectman set Incepere = Total - Decalaj - Durata where CodProiectNod = aCodNod and CodLansare0 = aCodLansare0;
  begin
    select nvl(Durata, 0), nvl(Decalaj, 0)  into DurataParinte, DecalajParinte  from manevra_proiectman where CodProiectNod = aCodNod and CodLansare0 = aCodLansare0;
    exception when others then DurataParinte := 0;DecalajParinte := 0;
  end;
  update tmp_proiectman set Decalaj = Decalaj + DecalajParinte + DurataParinte, Incepere = Total - (Decalaj + DecalajParinte + DurataParinte) where NodOriginal = aCodNod;
  for v_rec in (select CodProiectNod from manevra_proiectman where NODORIGINAL = aCodNod and CodLansare0 = aCodLansare0) loop
    SetDecalaj(v_rec.CodProiectNod, Total, aCodLansare0);
  end loop;
end;

procedure IncarcaProiectMan(aCodLansare0 IN NUMBER, aCodProiect IN NUMBER, aCant IN NUMBER) is
X number;
Total number;
aMarja number;
Facut number(1);
aNivel number;
NewOrdine number(5) := -1;  
begin
  insert into manevra_proiectman (
  CODLANSARE0,
  CODPROIECTNOD,
  CODPROIECT,   
  NODORIGINAL,  
  POZITIE,      
  CODRETETA,    
  DEN_OBIECT,   
  TIP,          
  SIMBOL,       
  DURATA,       
  CANT,         
  NIVEL,        
  ORDINE,       
  INCEPERE,
  Decalaj,
  DURATANOD,    
  COPILMAXIM,   
  NODCRITIC,    
  BARA         
  )
  select 
       aCodLansare0,
       PN.CODPROIECTNOD,
       PN.CODPROIECT,
       PN.NODORIGINAL,
       PN.POZITIE,
       PN.CODRETETA,
       obj.denumire den_obiect,
       0,
       pn.IndexParinte Simbol,
       Round(aCant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
       aCant,
       pn.nivel,
       nvl(o.Ordine,0),
       0,
       0,
       0,
       -1,
       &apos;...&apos; NodCritic,
       &apos;...&apos; bara
  from proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
       inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = aCodProiect) - Nivel as Ordine
                   from proiectnod WHERE CodProiect = aCodProiect Group by Nivel) O on O.Nivel = pn.Nivel
  WHERE PN.CodProiect = aCodProiect;

  SetCopilMaxim(aCodLansare0);

  begin
    select CodProiectNod, Nvl(DurataNod, 0) into X, Total from manevra_proiectman where Nvl(NodOriginal,0) = 0 and CodLansare0 = aCodLansare0;
    exception when others then X := 0;Total := 0;
  end;

  if Total &gt; 0 then 
    SetDrumCritic(X, aCodLansare0);
    SetDecalaj(X, Total, aCodLansare0);

    select Nvl(MarjaOrdine, 0) into aMarja from proiect where codproiect = aCodProiect;

    for v_rec in (select CodProiectNod from manevra_proiectman order by Incepere ) loop
      begin
        select nvl(Incepere, 0), Tip, Nivel into X, Facut, aNivel from manevra_proiectman where CodProiectNod = v_rec.CodProiectNod;
        exception when others then X := 0; Facut := 0;
      end;
      if FACUT &lt;&gt; 1 then 
        NewOrdine := NewOrdine + 1;
        update manevra_proiectman  set Tip = 1, Ordine = NewOrdine, Incepere = X, Decalaj = Decalaj - X + Incepere 
        where Nivel &gt; aNivel and Incepere &gt;= X and Incepere &lt;= X + aMarja;
      end if;
    end loop;
  end if;
end;

FUNCTION GETPROIECTNOD(aCodProiect IN NUMBER, aCant IN NUMBER, aCodComanda1 IN NUMBER) RETURN MENU_CURSOR
IS
TMPCURSOR MENU_CURSOR;
BEGIN

  BEGIN
    OPEN TMPCURSOR FOR

     SELECT PN.CODPROIECTNOD CODPROIECTNOD,                     
            PN.CODPROIECT CODPROIECT,                        
            PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.codobiect) CANT,                              
            PN.NODORIGINAL NODORIGINAL,
            PN.POZITIE POZITIE, 
            PN.CODRETETA CODRETETA, 
            PN.TIP,
            case 
              when nvl(NE.Codobiect, 0) = 0 then OBJ.CodObiect
              else OBJE.CodObiect
            end CODOBIECT,
            case 
              when nvl(NE.Codobiect, 0) = 0 then OBJ.DENUMIRE
              else OBJE.Denumire
            end DENUMIRE,
            PC.OBS,
            PC.IDENTIFICATOR   ,
            PC.DATADOCUMENTATIE,
            PC.ARHIVA          ,
            PC.PROIECTANT,
            nvl(aCant/PN0.CANT * PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.paritate), 0) NECESAR,
            0 TOTALCOMINT,  
            0 TOTALCOMFURN, 
            0 TOTALREZERVAT,
            0 TOTALREZOLVAT,
            0 TOTALREALIZAT,
            retete.CodGest,
            case when nvl(obje.codobiect, 0) &gt; 0 then NUME.Den_Um else NUM.DEN_UM end DenUM,
            PN.CODPRODMAT,
            case when nvl(obje.codobiect, 0) &gt; 0 then NUM1E.CodUM1 else NUM1.CodUM1 end UMSec,
            0 Nivel
     FROM PROIECTNOD PN
          INNER JOIN PROIECT P ON PN.Codproiect = P.CodProiect
          INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND nvl(PN0.NODORIGINAL, 0) = 0  
          INNER JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
          LEFT JOIN Nodechiv NE ON PN.CODPROIECTNOD = NE.CODPROIECTNOD AND NE.CODCOMANDA1 = aCodComanda1      
          LEFT JOIN NARTOBJ OBJE ON NE.CODOBIECT = OBJE.Codobiect
          LEFT JOIN NART ON OBJ.CODARTICOL = NART.CodARTICOL
          LEFT JOIN NUM ON NART.Um = NUM.CODUM
          LEFT JOIN NUM1 ON NUM.CODUM = NUM1.CODUM and NVL(NUM1.SECUNDARA, 0) = 0
          LEFT JOIN NART NARTE ON OBJE.CODARTICOL = NARTE.CodARTICOL
          LEFT JOIN NUM NUME ON NARTE.Um = NUME.CODUM
          LEFT JOIN NUM1 NUM1E ON NUME.CODUM = NUM1E.CODUM and NVL(NUM1E.SECUNDARA, 0) = 0 
          LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
          LEFT  JOIN (select RET.CodProdComp, PG.CodGest 
                      from prodcomp ret          
                           left join prodgest pg on pg.codprodcomp = ret.codprodcomp and pg.indexlocal = 1
                      ) retete on PN.Codreteta = retete.codprodcomp     
     WHERE PN.CODPROIECT = aCodProiect;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;  
END;

function BAGAREZERVARE(aCodComanda1 IN NUMBER, aCodCmdProdMat IN NUMBER, aCodNirStoc IN NUMBER, aCodNirSer IN NUMBER, aCant IN NUMBER, aUMSec IN NUMBER, aCodObiect IN NUMBER, aCodComanda1f IN NUMBER) RETURN NUMBER IS
pragma autonomous_transaction;
vCodRezervatS NUMBER(20);
NewCodObiect NUMBER(20);
ScadeFurn NUMBER(1);
aNr NUMBER(10);
aNr1 NUMBER(10);
vCant NUMBER(20,7);
sSql varchar2(1000);
aSubSursa number(20);
aSubCmd number(20);
begin
  if (aCodObiect &gt; 0)and(aCodNirStoc &gt; 0) then 
    ScadeFurn := 1;
    NewCodObiect := 0;
  else
    ScadeFurn := 0;
    NewCodObiect := aCodObiect;
  end if;
  
  aSubSursa := pkg_globals.GETSUBUNITATE;

  select count(*) into aNr 
  from REZERVATS 
  where CodComanda1 = aCodComanda1 
        and nvl(CodNirStoc, 0) = aCodNirStoc 
        and nvl(CodNirSer, 0) = aCodNirSer
        and nvl(CodObiect, 0) = aCodObiect
        and nvl(CodComanda1f, 0) = aCodComanda1f;

  if aNr = 1 then
    update rezervats set RezervatIni = RezervatIni  + aCant, 
                         rest        = rest         + aCant
    where CodComanda1 = aCodComanda1 and 
          nvl(CodNirStoc, 0)  = aCodNirStoc and 
          nvl(CodNirSer, 0)   = aCodNirSer and 
          nvl(CodObiect, 0)   = aCodObiect
          and nvl(CodComanda1f, 0) = aCodComanda1f;                     
  else
    if aCodNirStoc = 0 and aCodNirser = 0 and aCodComanda1f &gt; 0 then
      select count(*) into aNr1 
      from REZERVATS 
      where CodComanda1 = aCodComanda1 
          and nvl(CodNirStoc, 0) = 0 
          and nvl(CodNirSer, 0) = 0
          and nvl(CodObiect, 0) = aCodObiect
          and nvl(CodComanda1f, 0) = aCodComanda1f;
      if aNr1 = 1 then 
        select rest into vCant 
          from REZERVATS 
        where CodComanda1 = aCodComanda1 
            and nvl(CodNirStoc, 0) = 0 
            and nvl(CodNirSer, 0) = 0
            and nvl(CodObiect, 0) = aCodObiect
            and nvl(CodComanda1f, 0) = aCodComanda1f
            and rownum = 1;

        if vCant &gt; aCant then
          update rezervats set RezervatIni = RezervatIni - aCant, 
                               rest        = rest        - aCant
          where CodComanda1 = aCodComanda1 and 
                nvl(CodNirStoc, 0)  = 0 and 
                nvl(CodNirSer, 0)   = 0 and 
                nvl(CodObiect, 0)   = aCodObiect
                and nvl(CodComanda1f, 0) = aCodComanda1f;

          select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
          insert into rezervats 
                 ( codrezervats, codnirstoc, codnirser, RezervatIni, rest, 
                   codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          values ( vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, 
                   aCodComanda1, aCodCmdProdMat, aUMSec, NewCodObiect, aCodComanda1f);
        else
          if vCant = aCant then
            update rezervats set RezervatIni  = 0, 
                                 rest         = 0 
            where CodComanda1 = aCodComanda1 and 
                  nvl(CodNirStoc, 0)  = 0 and 
                  nvl(CodNirSer, 0)   = 0 and 
                  nvl(CodObiect, 0)   = aCodObiect
                  and nvl(CodComanda1f, 0) = aCodComanda1f;

            select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
            insert into rezervats 
                   ( codrezervats, codnirstoc, codnirser, 
                     RezervatIni, rest, 
                     codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
            values ( vCodRezervatS, aCodNirStoc, aCodNirSer, 
                     aCant, aCant, 
                     aCodComanda1, aCodCmdProdMat, aUMSec, NewCodObiect, aCodComanda1f);
          end if;      
        end if;
      else
        if aNr1 = 0 then 
          update rezervats set 
          rest = rest - aCant 
          where
            nvl(codnirstoc,0) = acodnirstoc and nvl(codnirser,0) = acodnirser and nvl(codcomanda1f,0) = 0 and codcomanda1 = acodcomanda1
            and codobiect = acodobiect;
          select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
          insert into rezervats 
          ( codrezervats, codnirstoc, codnirser, 
            RezervatIni, rest, 
            codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          values 
          ( vCodRezervatS, aCodNirStoc, aCodNirSer, 
            aCant, aCant,  
            aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
        end if;
      end if;
    else
      begin
        select g.codsubunit into aSubSursa
        from nirstoc ns
             inner join nir on nir.codnir = ns.codnir
             inner join ngest g on g.codgest = nir.gest
        where ns.codnirstoc = acodnirstoc;     
      exception when others then aSubSursa := pkg_globals.GETSUBUNITATE;
      end;  
      
      begin
        select c.subunitatea into aSubCmd
        from comanda1 c1
             inner join comanda c on c.codcomanda = c1.codcomanda
        where c1.codcomanda1 = acodcomanda1;     
      exception when others then aSubSursa := pkg_globals.GETSUBUNITATE;
      end;  
          
      select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
      sSql := &apos;insert into rezervats ( codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, UMSec &apos;;
      if aCodCmdProdMat &gt; 0 then sSql := sSql||&apos;, codcmdprodmat&apos;; end if;
      if aCodObiect &gt; 0 then sSql := sSql||&apos;, CodObiect&apos;; end if;
      if aCodComanda1f &gt; 0 then sSql := sSql||&apos;, CodComanda1f&apos;; end if;
      sSql := sSql||&apos;)

      values (&apos;||vCodRezervatS||&apos;,&apos;||aCodNirStoc||&apos;,&apos;||aCodNirSer||&apos;,&apos;||aCant||&apos;,&apos;||aCant||&apos;,&apos;||aCodComanda1||&apos;,&apos;||aUMSec;
      if aCodCmdProdMat &gt; 0 then sSql := sSql||&apos;,&apos;||acodcmdprodmat; end if;
      if aCodObiect &gt; 0 then sSql := sSql||&apos;,&apos;||aCodObiect; end if;
      if aCodComanda1f &gt; 0 then sSql := sSql||&apos;,&apos;||aCodComanda1f; end if;
      sSql := sSql||&apos;)&apos;;
      execute immediate sSql;
      if aSubSursa &lt;&gt; aSubCmd then
        update comanda1 set subunitsursa = aSubSursa where codcomanda1 = aCodComanda1;
      end if;
    end if;
  end if;     

  if ScadeFurn = 1 then 
    update rezervats set rest         = rest        - aCant, 
                         rezervatini  = rezervatini - aCant
    where CodComanda1 = aCodComanda1 and 
          Nvl(CodNirStoc,0) = 0 and 
          Nvl(CodNirSer,0) = 0 and 
          Nvl(CodObiect,0) = aCodObiect
          and nvl(CodComanda1f, 0) = aCodComanda1f;
  end if;

  commit;
  Return vCodRezervats;
end;

procedure SetCantInLansare1(vCodLansare1 in number, vCant in number) is
pragma autonomous_transaction;
begin
  update lansare1 set cant = vCant where codlansare1 = vCodLansare1;
  commit;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20);
BEGIN
  SELECT CODLANSARE INTO Tmp FROM LANSARE WHERE CODLANSARE = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
BEGIN
  SP_LOCKRECORD(RecId);

  SELECT
    Nvl(CARNETDOC,0),
    NRDOC
  INTO
    ACARNETDOC,
    ANRDOC
  FROM
    LANSARE
  WHERE
    CODLANSARE = RECID;

  DELETE FROM LANSARENEC WHERE CODLANSARE = RECID;
  DELETE FROM LANSARE1 WHERE CODLANSARE = RecId;
  DELETE FROM LANSARE0 WHERE CODLANSARE = RecId;
	DELETE FROM LANSARE WHERE CODLANSARE = RecId;

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;
  NotifyModif(2, RecId, &apos;LANSARE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_LANSARE FIELDS(CODLANSARE) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS 
vCount number;
vMaxNivel number;
vD1 number;
vD2 number;
vD3 number;
vRel number; 
BEGIN  
  INSERT INTO TMP_LANSARE 
  (CODLANSARE,                      
   NRDOC,                           
   CARNETDOC,                       
   DATADOC,                         
   Subunitatea,                      
   Operat, 
   Blocat, 
   Anulat,
   Obs
   )                   
  SELECT                            
   L.CODLANSARE,                    
   L.NRDOC,
   L.CARNETDOC, 
   L.DATADOC, 
   L.Subunitatea,
   L.Operat, 
   L.Blocat, 
   L.Anulat,
   L.Obs
  FROM 
     LANSARE L 
  WHERE L.CODLANSARE = RECID;               

  insert into tmp_lansare0 
   (codlansare0, 
    codlansare, 
    codcmd1, 
    cant,
    cantum1, 
    codproiect, 
    codscenariu, 
    produs, 
    cantacceptat, 
    restlansat, 
    proiect, 
    scenariu, 
    client, 
    nrdoc, 
    datadoc,
    codobiect,
    termen,
    termenlivrare,
    codextern,
    D1, D2, D3,
    RelatieUM1,
    CodUM1,
    ParitateD1,
    ParitateD2,
    ParitateD3,
    ObsArticol,
    Obs,
    CODINTERN
    )
  select 
    l0.codlansare0,
    l0.codlansare,
    l0.codcmd1,
    l0.cant,
    l0.cantum1,
    l0.codproiect,
    l0.codscenariu,
    prod.denumire,
    c1.cantacceptat,
    c1.restlansat,
    p.versiune,
    sl.den_scenariu,
    part.den_part,
    c.nrdoc,
    c.datadoc,
    c1.codobiect,
    l0.termen,
    c1.termen,
    prod.codextern, 
    C1.D1, C1.D2, C1.D3,
    nart.relatieum1,
    c1.umsec,
    nvl(nart.paritated1,0) paritated1,
    nvl(nart.paritated2,0) paritated2,
    nvl(nart.paritated3,0) paritated3,
    c1.obs obsarticol,
    c.obs,
    PROD.CODINTERN
  from lansare0 l0
       inner join comanda1 c1 on l0.codcmd1 = c1.codcomanda1
       inner join comanda c on c.codcomanda = c1.codcomanda
       inner join nartobj prod on prod.codobiect = c1.codobiect        
       inner join nart on prod.codarticol = nart.codarticol
       inner join proiect p on p.codproiect = c1.codproiect     
       left  join npart part on part.codpart = c.partener
       left  join scenariilivr1 sl1 on sl1.codcomanda1 = l0.codcmd1
       left  join scenariilivr sl on sl.codscenariu = sl1.codscenariu
  where l0.codlansare = RecId;

  select count(*) into vCount from tmp_lansare0 where codlansare = RecId;

  if vCount = 0 then
    insert into tmp_lansare0 
    (
     codlansare0, 
     codlansare, 
     codcmd1, 
     cant,
     codproiect, 
     codscenariu, 
     produs, 
     cantacceptat, 
     restlansat, 
     proiect, 
     scenariu,
     client,
     nrdoc,
     datadoc,
     codobiect,
     termen,
     termenlivrare,
     codextern, D1, D2, D3,
     RelatieUM1,
     CodUM1,
     ParitateD1,
     ParitateD2,
     ParitateD3,
     codintern
    )
    select 
      -999999,
      RecId,
      l.codcmd1,
      l.cant,
      l.codproiect,
      l.codscenariu,
      prod.denumire,
      c1.cantacceptat,
      c1.restlansat,
      p.versiune,
      sl.den_scenariu,
      part.den_part,
      c.nrdoc,
      c.datadoc,
      c1.codobiect,
      c1.termen,
      c1.termen,
      prod.codextern, 
      C1.D1, C1.D2, C1.D3,
      nart.relatieum1,
      c1.umsec,
      nvl(nart.paritated1,0) paritated1,
      nvl(nart.paritated2,0) paritated2,
      nvl(nart.paritated3,0) paritated3,
      prod.codintern
    from lansare l
         inner join comanda1 c1 on l.codcmd1 = c1.codcomanda1
         inner join comanda c on c1.codcomanda = c.codcomanda
         inner join nartobj prod on prod.codobiect = c1.codobiect
         inner join nart on prod.codarticol = nart.codarticol
         inner join proiect p on p.codproiect = c1.codproiect
         inner join npart part on part.codpart = c.partener
         left  join scenariilivr1 sl1 on sl1.codcomanda1 = l.codcmd1
         left  join scenariilivr sl on sl.codscenariu = sl1.codscenariu
    where l.codlansare = recid;
  end if;

  insert into tmp_proiectnod_lans 
  (
    CODLANSARE0,     
    CODPROIECTNOD,   
    CODPROIECT,      
    CANT,            
    NODORIGINAL,
    POZITIE,
    CODRETETA,
    TIP,             
    CODOBIECT,       
    INDEXPARINTE,    
    CODPRODMAT,      
    NIVEL,           
    ORDINE,
    DECALAJ,          
    DENUMIRE,        
    OBS,             
    IDENTIFICATOR,   
    DATADOCUMENTATIE,
    ARHIVA,          
    PROIECTANT,      
    NECESAR,         
    TOTALCOMINT,     
    TOTALCOMFURN,    
    TOTALREZERVAT,   
    TOTALREZOLVAT,   
    TOTALREALIZAT,   
    CODGEST,         
    DENUM,           
    UMSEC,           
    NECESARAUT,      
    TIPECHIV,        
    PARITATE,
    CODEXTERN,
    D1,
    D2,
    D3,
    NECESARUM1,
    RELATIEUM1,
    PARITATED1,
    PARITATED2,
    PARITATED3,
    um1        
  )
  SELECT
    L0.CODLANSARE0,
    PN.CODPROIECTNOD,
    PN.CODPROIECT,
    PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.Paritate) CANT,
    PN.NODORIGINAL,
    PN.POZITIE,
    PN.CODRETETA,
    PN.TIP,
    case when nvl(NE.Codobiect, 0) = 0 then OBJ.CodObiect else OBJE.CodObiect end CODOBIECT,
    PN.IndexParinte,
    PN.CODPRODMAT,
    PN.Nivel, PN.Ordine,
    PN.DECALAJ,
    case when nvl(NE.Codobiect, 0) = 0 then OBJ.DENUMIRE else OBJE.Denumire end DENUMIRE,
    PC.OBS,
    PC.IDENTIFICATOR,
    PC.DATADOCUMENTATIE,
    PC.ARHIVA,
    PC.PROIECTANT,
    nvl(L0.CANT/PN0.CANT * PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.paritate), 0) NECESAR,
    0 TOTALCOMINT,
    0 TOTALCOMFURN,
    0 TOTALREZERVAT,
    0 TOTALREZOLVAT,
    0 TOTALREALIZAT,
    retete.CodGest,
    case when nvl(obje.codobiect, 0) &gt; 0 then NUME.Den_Um else NUM.DEN_UM end DenUM,
    case when nvl(obje.codobiect, 0) &gt; 0 then NUM1E.CodUM1 else NUM1.CodUM1 end UMSec,
    case 
      when NVL(PN.NodOriginal, 0) = 0 then nvl(L0.CANT/PN0.CANT * PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.paritate), 0)
      else 0 
    end NecesarAut,
    NE.TIP TIPECHIV,
    NE.PARITATE,
    OBJ.CODEXTERN,
    case when nvl(pn.nodoriginal,0) = 0 then (select D1 from comanda1 where codcomanda1 = l0.codcmd1) else PMAT.D1 end D1,
    case when nvl(pn.nodoriginal,0) = 0 then (select D2 from comanda1 where codcomanda1 = l0.codcmd1) else PMAT.D2 end D2,
    case when nvl(pn.nodoriginal,0) = 0 then (select D3 from comanda1 where codcomanda1 = l0.codcmd1) else PMAT.D3 end D3,
    nvl(L0.CANTUM1/PN0.CANT * PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.paritate), 0) NECESARUM1,
    NART.RELATIEUM1,
    NVL(NART.PARITATED1,0),
    NVL(NART.PARITATED2,0),
    NVL(NART.PARITATED3,0),
    nart.um1
  FROM tmp_lansare0 L0
       inner join PROIECTNOD PN ON PN.CODPROIECT = L0.CODPROIECT
       INNER JOIN PROIECT P ON PN.Codproiect = P.CodProiect
       INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND nvl(PN0.NODORIGINAL, 0) = 0
       LEFT  JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
       LEFT  JOIN Nodechiv NE ON PN.CODPROIECTNOD = NE.CODPROIECTNOD AND NE.CODCOMANDA1 = l0.codcmd1
       LEFT  JOIN NARTOBJ OBJE ON NE.CODOBIECT = OBJE.Codobiect
       LEFT  JOIN NART ON OBJ.CODARTICOL = NART.CodARTICOL
       LEFT  JOIN NUM ON NART.Um = NUM.CODUM
       LEFT  JOIN NUM1 ON NUM.CODUM = NUM1.CODUM and NVL(NUM1.SECUNDARA, 0) = 0
       LEFT  JOIN NART NARTE ON OBJE.CODARTICOL = NARTE.CodARTICOL
       LEFT  JOIN NUM NUME ON NARTE.Um = NUME.CODUM
       LEFT  JOIN NUM1 NUM1E ON NUME.CODUM = NUM1E.CODUM and NVL(NUM1E.SECUNDARA, 0) = 0
       LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
       LEFT  JOIN PRODMAT PMAT ON PMAT.CodMAT = PN.CodProdMAT
       LEFT  JOIN (select RET.CodProdComp, PG.CodGest
                   from prodcomp ret
                        left join prodgest pg on pg.codprodcomp = ret.codprodcomp and NVL(pg.indexlocal,1) = 1
                  ) retete on PN.Codreteta = retete.codprodcomp 
  WHERE PN.CANT * decode(nvl(ne.codobiect, 0),0, 1, ne.Paritate) &lt;&gt; 0;

  begin
    select nvl(max(nivel),-1) into vMaxNivel from tmp_proiectnod_lans;
  exception when others then vMaxNivel := -1;
  end;

  for vCount in 0..vMaxNivel loop
    for v_rec in (select tmp.codproiectnod, tmp.d1, tmp.d2, tmp.d3, nart.um1, tmp.codlansare0, nart.relatieum1
                  from tmp_proiectnod_lans tmp
                       inner join nartobj obj on tmp.codobiect = obj.codobiect
                       inner join nart on nart.codarticol = obj.codarticol 
                  where tmp.nivel = vcount order by codlansare0, nivel, pozitie) loop
      for v_xxx in (select nart.um1, nart.relatieum1, mat.copyd1, mat.copyd2, mat.copyd3, tmpc.codproiectnod, tmpc.codlansare0
                    from tmp_proiectnod_lans tmpc 
                         inner join nartobj obj on tmpc.codobiect = obj.codobiect
                         inner join nart on nart.codarticol = obj.codarticol 
                         left join prodmat mat on tmpc.codprodmat = mat.codmat
                    where tmpc.nodoriginal = v_rec.codproiectnod and codlansare0 = v_rec.codlansare0) loop
        if v_rec.um1 &gt; 0 and v_xxx.um1 &gt; 0 AND v_rec.relatieum1 &gt; 0  and v_xxx.relatieum1 &gt; 0 then
          vD1 := 0;
          vD2 := 0;
          vD3 := 0;
          vRel := v_xxx.relatieum1;
          if vRel in (1,2,3,7,8,9) then
            vD1 := 1;
            if vRel in (2,3,8,9) then 
              vD2 := 1;
              if vRel in (3,9) then vD3 := 1; end if;
            end if;
          else
            if vRel in (4,5,6,10,11,12) then
              vD1 := 1;
              if vRel in (5,6,11,12) then
                vD2 := 1;
                if vRel in (6,12) then vD3 := 1; end if;
              end if;
            end if;
          end if;

          update tmp_proiectnod_lans set
          D1 = vD1 * v_xxx.copyd1 * v_rec.D1,
          D2 = vD2 * v_xxx.copyd2 * v_rec.D2,
          D3 = vD3 * v_xxx.copyd3 * v_rec.D3
          where codproiectnod = v_xxx.codproiectnod and codlansare0 = v_xxx.codlansare0;
        end if;            
      end loop;                   
    end loop;
  end loop;  

  update tmp_proiectnod_lans set
  necesarum1 = pkg_um.GetSpecificCantUM1(um1, 0, 0, 0, relatieum1, d1, d2, d3, necesar, paritated1 * paritated2 * paritated3),
  cantum1    = pkg_um.GetSpecificCantUM1(um1, 0, 0, 0, relatieum1, d1, d2, d3, cant, paritated1 * paritated2 * paritated3);

  INSERT INTO TMP_LANSARE1(
    CODLANSARE1,
    CODLANSARE0,                         
    CODLANSARE,                          
    CODPROIECTNOD,                       
    TIP,                                 
    CODCMD1,                             
    CANT,                                
    CODRETETA,                           
    DENRETETA,                           
    GESTIUNE,                            
    NRCMD,                               
    DATACMD,                             
    CANTREZERVAT,
    COMANDA,
    UM,
    CodCmd,
    CodGest, 
    CodFormatie,
    Schimb,
    CodPart,
    CodLocatie,
    DenLocatie,
    Denumire,
    CodExtern,
    NodParinte,
    CodCmd1P,
    DECALAJ,
    incepere
    )                        
  SELECT                                
    L1.CODLANSARE1,
    L1.CODLANSARE0,                     
    L1.CODLANSARE,
    L1.CODPROIECTNOD,
    L1.TIP,
    L1.CODCMD1,
    L1.CANT,
    PC.CODPRODCOMP,
    PC.OBS,
    NG.DEN_GEST,
    C.NRDOC,
    C.DATADOC,
    REZ.CANTREZERVAT,
    C.Prefixdoc||&apos; &apos;||C.NrDoc||&apos; / &apos;||C.Datadoc,
    NUM.DEN_UM,
    C.CODCOMANDA,
    C.Codgest,
    c.codformatie,
    c.schimb,
    0,
    C.CODLOCATIE,
    LOC.DENUMIRE,
    OBJ.Denumire,
    OBJ.CodExtern,
    L1.NodParinte,
    L1.CodCmd1P,
    L1.DECALAJ,
    l1.incepere
  FROM LANSARE1 L1 INNER JOIN PROIECTNOD NOD ON L1.CODPROIECTNOD = NOD.CODPROIECTNOD
                   INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = NOD.CODRETETA
                   INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L1.CODCMD1
                   INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                   INNER JOIN NGEST NG ON C.CODGEST = NG.CODGEST
                   LEFT JOIN (select codcomanda1, sum(rest) cantrezervat from REZERVATS where nvl(codcmdprodmat, 0) &lt;&gt; 0 group by codcomanda1) REZ ON REZ.CODCOMANDA1 = C1.CODCOMANDA1
                   LEFT JOIN NARTOBJ OBJ ON C1.Codobiect = OBJ.CodObiect
                   LEFT JOIN NART ART ON OBJ.Codarticol = ART.CodArticol
                   LEFT JOIN NUM ON ART.UM = NUM.CODUM
                   LEFT JOIN NLOCATII LOC ON LOC.Codlocatie = C.CODLOCATIE
  WHERE L1.TIP = 1 AND L1.CODLANSARE = RECID;                   


  INSERT INTO TMP_LANSARE2(
    CODLANSARE1,
    CODLANSARE0,
    CODLANSARE,
    CODPROIECTNOD,
    TIP,
    CODCMD1,
    CANT,
    CODRETETA,
    DENRETETA,
    GESTIUNE,
    NRCMD,
    DATACMD,
    CANTREZERVAT,
    COMANDA,
    UM,
    CodCmd,
    CodGest, 
    CodFormatie,
    Schimb,
    CodPart, 
    CodLocatie,
    DenLocatie,
    Denumire,
    CodExtern,
    NodParinte,
    CodCmd1P,
    DECALAJ,
    incepere
    )
  SELECT  
    L1.CODLANSARE1,
    L1.CODLANSARE0,
    L1.CODLANSARE,
    L1.CODPROIECTNOD,
    L1.TIP,
    L1.CODCMD1,
    L1.CANT,
    PC.CODPRODCOMP,
    PC.OBS,
    NP.DEN_PART,
    C.NRDOC,
    C.DATADOC,
    REZ.CANTREZERVAT,
    C.Prefixdoc||&apos; &apos;||C.NrDoc||&apos; / &apos;||C.Datadoc,
    NUM.DEN_UM,
    C.CodComanda,
    0,
    0,
    1,
    C.PARTENER,
    Loc.COdAgenda,
    Loc.Obs,
    OBJ.Denumire,
    OBJ.CodExtern,
    L1.NodParinte,
    L1.CodCmd1P,
    L1.DECALAJ,
    l1.incepere
  FROM LANSARE1 L1 LEFT JOIN PROIECTNOD NOD ON L1.CODPROIECTNOD = NOD.CODPROIECTNOD
                   LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = NOD.CODRETETA
                   LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L1.CODCMD1
                   LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                   LEFT JOIN NPART NP ON NP.CODPART = C.PARTENER
                   LEFT JOIN (select codcomanda1, sum(rest) cantrezervat from REZERVATS WHERE nvl(codcmdprodmat, 0) = 0 group by codcomanda1) REZ ON REZ.CODCOMANDA1 = C1.CODCOMANDA1
                   LEFT JOIN NARTOBJ OBJ ON C1.Codobiect = OBJ.CodObiect
                   LEFT JOIN NART ART ON OBJ.Codarticol = ART.CodArticol
                   LEFT JOIN NUM ON ART.UM = NUM.CODUM
                   LEFT JOIN NAGENDA LOC ON LOC.CodAgenda = C.CODLOCATIE
  WHERE L1.TIP = 2 AND L1.CODLANSARE = RECID;

  INSERT INTO TMP_LANSARE3
  (
    CODLANSARE1,
    CODLANSARE0,
    CODLANSARE,
    CODPROIECTNOD,
    TIP,
    CODCMD1,
    CANT,
    CODRETETA,
    DENRETETA,
    GESTIUNE,
    NRCMD,
    DATACMD,
    CANTREZERVAT,
    COMANDA,
    UM,
    CodGest,
    CodFormatie,
    Schimb,
    CodPart,
    CodLocatie,
    DenLocatie,
    Denumire,
    CodExtern,
    NodParinte,
    CodCmd1P,
    DECALAJ,
    incepere
  )
  SELECT  
    L1.CODLANSARE1,
    L1.CODLANSARE0,
    L1.CODLANSARE,
    L1.CODPROIECTNOD,
    L1.TIP,
    L1.CODCMD1,
    L1.CANT,
    PC.CODPRODCOMP,
    PC.OBS,
    &apos;&apos;&apos;&apos;,       
    0,
    NS.DATAACHIZ,
    RS.REST,
    &apos; Achiz : &apos;||NS.DataAchiz||&apos;, Furn : &apos;||NP.Den_Part,
    NUM.DEN_UM,
    0,
    0,
    1,
    0,
    0,
    &apos; &apos;,
    OBJ.Denumire,
    OBJ.CodExtern,
    L1.NodParinte,
    L1.CodCmd1P,
    L1.DECALAJ,
    l1.incepere
  FROM LANSARE1 L1 INNER JOIN PROIECTNOD NOD ON L1.CODPROIECTNOD = NOD.CODPROIECTNOD
                   INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = NOD.CODRETETA
                   INNER JOIN REZERVATS RS ON L1.CODREZERVATS = RS.CODREZERVATS
                   INNER JOIN NIRSTOC NS ON RS.CodNirStoc = NS.CodNirStoc
                   LEFT JOIN NIRSER NSE ON RS.CodNirSer = NSE.CodNirSer
                   LEFT JOIN NPART NP ON NS.FURN = NP.CODPART
                   LEFT JOIN NARTOBJ OBJ ON NS.Codobiect = OBJ.CodObiect
                   LEFT JOIN NART ART ON OBJ.Codarticol = ART.CodArticol
                   LEFT JOIN NUM ON ART.UM = NUM.CODUM
  WHERE L1.TIP = 3 AND L1.CODLANSARE = RECID;

  if vCount = 0 then 
    update tmp_lansare1 set codlansare0 = -999999;
    update tmp_lansare2 set codlansare0 = -999999;
    update tmp_lansare3 set codlansare0 = -999999;
  end if;

  for v_rec in (select pnl.codlansare0, pnl.codproiectnod, l1.cant
                from tmp_lansare1 l1
                     inner join tmp_proiectnod_lans pnl on pnl.codlansare0 = l1.codlansare0 and pnl.codproiectnod = l1.codproiectnod
               ) loop
    update tmp_proiectnod_lans set 
      TotalComInt = TotalComInt + v_rec.cant, 
      TotalRezolvat = TotalRezolvat + v_rec.cant
    where codlansare0 = v_rec.codlansare0 and codproiectnod = v_rec.codproiectnod;  
  end loop;

  for v_rec in (select pnl.codlansare0, pnl.codproiectnod, l2.cant
                from tmp_lansare2 l2
                     inner join tmp_proiectnod_lans pnl on pnl.codlansare0 = l2.codlansare0 and pnl.codproiectnod = l2.codproiectnod
               ) loop
    update tmp_proiectnod_lans set 
      TotalComFurn = TotalComFurn + v_rec.cant, 
      TotalRezolvat = TotalRezolvat + v_rec.cant
    where codlansare0 = v_rec.codlansare0 and codproiectnod = v_rec.codproiectnod;  
  end loop;

  for v_rec in (select pnl.codlansare0, pnl.codproiectnod, l3.cant
                from tmp_lansare3 l3
                     inner join tmp_proiectnod_lans pnl on pnl.codlansare0 = l3.codlansare0 and pnl.codproiectnod = l3.codproiectnod
               ) loop
    update tmp_proiectnod_lans set 
      TotalRezervat = TotalRezervat + v_rec.cant, 
      TotalRezolvat = TotalRezolvat + v_rec.cant
    where codlansare0 = v_rec.codlansare0 and codproiectnod = v_rec.codproiectnod;  
  end loop;

  /*for v_Rec in (select * 
                from tmp_proiectnod_lans) loop
    for v_tmp in (select * 
                  from tmp_proiectnod_lans
                  where codlansare0 = v_rec.codlansare0 and nodoriginal = v_Rec.Nodoriginal) loop
      update tmp_proiectnod_lans set Necesar = v_rec.TotalComInt/v_rec.cant * v_tmp.cant
      where codlansare0 = v_tmp.codlansare0 and codproiectnod = v_tmp.codproiectnod;             
    end loop;    
  end loop;*/

  insert into tmp_nodechiv (codcomanda1, codproiectnod, codobiect, paritate, D1, D2, D3, tip)
  select ne.codcomanda1, ne.codproiectnod, ne.codobiect, ne.paritate, ne.D1, ne.D2, ne.D3, ne.tip 
  from nodechiv ne        
       inner join tmp_lansare0 l0 on l0.codcmd1 = ne.codcomanda1;

  INSERT INTO TMP_NODECHIV1 (CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, CODOBIECTORIG, NODORIGINAL, 
                             CANTECHIVALATA, DENOBIECTECHIV)
  select ne1.CODSCENARIU, ne1.CODCOMANDA1, ne1.CODPROIECTNOD, ne1.CODOBIECT, ne1.CANT, ne1.PARITATE, pn.CODOBIECT, pn.NODORIGINAL, 
         ne1.cant/ne1.paritate, obj.denumire
  from nodechiv1 ne1 
       inner join nartobj obj on ne1.codobiect = obj.codobiect
       inner join proiectnod pn on ne1.codproiectnod = pn.codproiectnod
  where codscenariu = (select nvl(codscenariu,0) from tmp_lansare0);

  INSERT INTO TMP_LANSARENEC(CODLANSARE0, DataStart, CODPROIECTNOD, CANT, NECESARP, NECESAR, REZOLVAT, REZERVAT, NESOSIT, RESTREZERVAT, RESTNESOSIT, TOTREZERVAT, TOTNESOSIT, STOC, CMDINT, DIFERENTE, PARITATEECHIV, CODOBIECT, CODLANSARE)
  SELECT CODLANSARE0, DataStart, CODPROIECTNOD, CANT, NECESARP, NECESAR, REZOLVAT, REZERVAT, NESOSIT, RESTREZERVAT, RESTNESOSIT, TOTREZERVAT, TOTNESOSIT, STOC, CMDINT, DIFERENTE, PARITATEECHIV, CODOBIECT, CODLANSARE 
  FROM LANSARENEC WHERE CODLANSARE = RECID;

  INSERT INTO TMP_COMANDA1_MAN (
    CODCOMANDA1, CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,
    PU, PULei, prioritate, CODPROMO1, DataStart,
    CANTCOMANDAT, CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
    CULANSARE, UMCorelat, PUCorelat, CODCADOU, DENUMCorelat,
    RESTLANSAT, TERMEN, ANULAT, ADDIM, PROCDISC, OBS, PRETORIG,
    COEFDISCMAJ, CODCATPRET, SCADENTA, DENUM, VALOARE, PARITATE,
    PROCTVA,
    DENOBIECT, TIPLINIE, CONSUM, REZERVATINI, D1, D2, D3,
    RelatieUM1, TipSursa, CodSursa, CantUm1, AcceptUM1, TIPPLATA, CADOU, CADOULINK, PRETPROMO, UM1, CoefIndirecte,
    ParitateOrig, DenUM1,
    CODRETETA, TIPRETETA, Codproiect, TipLivrare, CODANALIZANOD, Nivel, Pozitie, Rezervari, ProdusPropriu, ROTUNJIRE,
    PARTENER, EXCEPTIONAL, TAXA, CODCONTRACT1, CODOFERTA1, PRETUM1, CONTRACT, PROMOTIE, GESTACT, CODCENTRU, FARANIVELAPROB,
    CODEXTERN, CODINTERN, CODNORMA, MODINCHIDERE, TERMENCONTRACT,
    CMDCLILANS, CMDINTLANS, CODMIFIX, TipLinieSA, CONTSERV
  )
  SELECT
    c1.CODCOMANDA1,c1.CODCOMANDA, c1.INDEXLOCAL, c1.CODOBIECT, c1.UMSEC,
    c1.PU * u1.Paritate, c1.PU * u1.Paritate,prioritate, C1.CODPROMO1, C1.DataStart,
    c1.CANTCOMANDAT / u1.Paritate, c1.CANTACCEPTAT / u1.Paritate, c1.RESTACCEPTAT / u1.Paritate, c1.CANTRETURNAT / u1.Paritate,
    c1.CULANSARE, c1.UMCorelat, c1.PUCorelat, C1.CODCADOU, u2.Den_UM1,
    c1.RESTLANSAT / u1.Paritate, c1.TERMEN, c1.ANULAT, C1.ADDIM, C1.PROCDISC, C1.OBS, C1.PRETORIG * u1.Paritate,
    C1.COEFDISCMAJ, C1.CODCATPRET, C1.SCADENTA, u1.Den_UM1, c1.CANTACCEPTAT * c1.PU, u1.Paritate,
    PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU) PROCTVA,
    O.DENUMIRE, DECODE(NVL(A.TIPARTICOL, 0), 0, &apos;=&apos;, 2, &apos;=&apos;, &apos;S&apos;), c1.CONSUM, c1.REZERVATINI / u1.Paritate, c1.d1, c1.d2, c1.d3,
    a.relatieum1, c1.tipsursa, c1.codsursa, c1.cantum1, c1.AcceptUM1, C1.TIPPLATA,C1.CADOU, C1.CADOULINK,  C1.PRETPROMO, a.um1, c1.CoefIndirecte,
    1 paritateorig, UMSPEC.Den_Um DenUM1,
    c1.codreteta, 1, c1.Codproiect, c1.TipLivrare, c1.CODANALIZANOD, c1.Nivel, c1.Pozitie, &apos;Rezervari&apos;, O.Produspropriu, 
    O.ROTVALUTA,
    PKG_LIST_BASE_UTILS.GetPartComCli(C1.CODCOMANDA1), C1.EXCEPTIONAL, TAXA, C1.CODCONTRACT1, C1.CODOFERTA1, C1.PRETUM1, CTR.NRDOC, O.PROMOTIE, C1.GESTACT, C1.CODCENTRU, O.FARANIVELAPROB,
    SUBSTR(O.CODEXTERN, 1, 80),
    SUBSTR(O.CODINTERN, 1, 80), C1.CODNORMA, NVL(C1.MODINCHIDERE, 0), C1.TERMENCONTRACT,
    (select count(*) from lansare l where l.codcmd1 = C1.CodComanda1),
    (select count(*) from cmdlink where codliniecomanda = c1.Codcomanda1),
    C1.CODMIFIX, C1.TipLinieSA, A.CONTSERVICIU
  FROM LANSARE1 L1
    INNER JOIN COMANDA1 c1 ON C1.CODCOMANDA1 = L1.CODCMD1
    LEFT JOIN Rac_REZ R ON R.codComanda = c1.codComanda
    LEFT JOIN contract1 ctr1 ON C1.codContract1 = ctr1.codContract1
    LEFT JOIN contract  ctr ON  ctr1.codContract = ctr.codContract
    LEFT JOIN NartObj o on o.CodObiect  = c1.CodObiect
    LEFT JOIN Nart a    on a.CodArticol = o.CodArticol
    LEFT JOIN NUM UMSPEC on a.um1 = UMSPEC.CODUM
    LEFT JOIN NUM1 u1 ON u1.CodUM1 = c1.UmSec
    LEFT JOIN NUM1 u2 ON u2.CodUM1 = c1.UmCorelat
  WHERE L1.TIP = 1 AND L1.CODLANSARE = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ) IS
aTIPDOC       NUMBER(20);
aCARNETDOC    NUMBER(20);
aNRDOC        NUMBER(20);
aCodSubunit   NUMBER(20);
aDataDoc      DATE;
aDoc          VARCHAR2(200);
oldCARNETDOC  NUMBER(20) := 0;
oldNRDOC      NUMBER(20) := 0;
aCod          number(20);
BEGIN
  SELECT
    62,
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    &apos;LNP&apos;||NRDOC||&apos;/&apos;||DATADOC
  INTO
    aTipDoc,
    aCARNETDOC,
    aNRDOC,
    aCodSubunit,
    aDATADOC,
    ADOC
  FROM TMP_LANSARE;

 IF OPERATION = 0 THEN --UPDATE

  begin 
    SELECT Nvl(CARNETDOC,0), NRDOC
    INTO   oldCARNETDOC,     oldNRDOC
    FROM   LANSARE
    WHERE  CodLansare = RecId;
  exception when no_data_found then
    oldCarnetDoc := 0;
    oldNrDoc := 0;
  end;  

  IF (oldCARNETDOC &lt;&gt; aCARNETDOC) OR ((oldCARNETDOC &lt;&gt; 0) AND (oldNRDOC &lt;&gt; aNRDOC)) THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(oldCARNETDOC, oldNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(oldCARNETDOC);
  END IF; 

  SELECT CODLANSARE INTO RECID FROM TMP_LANSARE;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSPROD&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  UPDATE LANSARE SET (NRDOC,carnetdoc,DATADOC,CANT,CODPROIECT,Subunitatea,Anulat,Blocat,Operat,Automat,CODSCENARIU, OBS) = 
   (SELECT NRDOC,carnetdoc,DATADOC,CANT,CODPROIECT,SUBUNITATEA,Anulat,Blocat,Operat,Automat,CodScenariu,OBS FROM TMP_LANSARE)
  WHERE CODLANSARE = RECID;  

  /*insert into tmp_lansare1 (codlansare1, codlansare, codproiectnod, tip, codcmd1, cant, codrezervats)
  (select codlansare1, codlansare, codproiectnod, tip, codcmd1, cant, codrezervats from tmp_lansare2
  union all
  select codlansare1, codlansare, codproiectnod, tip, codcmd1, cant, codrezervats from tmp_lansare3);*/

  DELETE LANSARE0 L0 WHERE L0.CODLANSARE = RECID AND NOT EXISTS (SELECT CODLANSARE0 FROM TMP_LANSARE0 WHERE CODLANSARE0 = L0.CODLANSARE0);
  for v_Rec in ( select * from tmp_lansare0 ) loop
    if v_Rec.Codlansare0 &lt;= 0 then 
      select SEQ_LANSARE0_CODLANSARE0.NEXTVAL into aCod from dual;
      update tmp_lansare1 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
      update tmp_lansare2 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
      update tmp_lansare3 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
      INSERT INTO LANSARE0(CODLANSARE0,CODLANSARE,CODCMD1,CANT,CODPROIECT,CODSCENARIU, termen,cantum1)
      values (aCod, RECID, v_rec.CODCMD1,v_rec.CANT,v_rec.CODPROIECT,v_rec.CODSCENARIU, v_rec.termen, v_rec.cantum1);  
    else
      UPDATE LANSARE0 L0 SET
        CODCMD1     = v_rec.codcmd1,
        CANT        = v_rec.cant,
        cantum1     = v_rec.cantum1,
        CODPROIECT  = v_rec.codproiect,
        CODSCENARIU = v_rec.codscenariu,
        termen      = v_rec.termen
      WHERE L0.CODLANSARE0 = V_REC.CODLANSARE0;
    end if;
  end loop;

  DELETE FROM LANSARE1 L1 WHERE l1.CodLansare = RecId and l1.tip = 1 and NOT EXISTS (SELECT CODLANSARE1 FROM TMP_LANSARE1 WHERE CODLANSARE1 = L1.CODLANSARE1);
  DELETE FROM LANSARE1 L1 WHERE l1.CodLansare = RecId and l1.tip = 2 and NOT EXISTS (SELECT CODLANSARE1 FROM TMP_LANSARE2 WHERE CODLANSARE1 = L1.CODLANSARE1);
  DELETE FROM LANSARE1 L1 WHERE l1.CodLansare = RecId and l1.tip = 3 and NOT EXISTS (SELECT CODLANSARE1 FROM TMP_LANSARE3 WHERE CODLANSARE1 = L1.CODLANSARE1);

  INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE FROM TMP_LANSARE1 WHERE CODLANSARE1 &lt;= 0;
  INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE,CODLANSARE0,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE FROM TMP_LANSARE2 WHERE CODLANSARE1 &lt;= 0;
  INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT, CODREZERVATS, NODPARINTE, CodCmd1P, DECALAJ, INCEPERE FROM TMP_LANSARE3 WHERE CODLANSARE1 &lt;= 0;

  FOR V_REC IN (SELECT * FROM TMP_LANSARE1 where codlansare1 &gt; 0 ) LOOP
   UPDATE LANSARE1 L1 SET
     L1.CODLANSARE0    = V_REC.CODLANSARE0,
     L1.CODLANSARE     = V_REC.CODLANSARE,
     L1.CODPROIECTNOD  = V_REC.CODPROIECTNOD,
     L1.TIP            = V_REC.TIP,
     L1.CODCMD1        = V_REC.CODCMD1,
     L1.CANT           = V_REC.CANT,
     L1.NODPARINTE     = V_REC.NODPARINTE,
     L1.CodCmd1P       = V_REC.CodCmd1P,
     L1.DECALAJ        = V_REC.DECALAJ,
     L1.INCEPERE       = V_REC.INCEPERE
   WHERE L1.CODLANSARE1 = V_REC.CODLANSARE1;
  END LOOP; 

  FOR V_REC IN (SELECT * FROM TMP_LANSARE2 where codlansare1 &gt; 0 ) LOOP
   UPDATE LANSARE1 L1 SET
     L1.CODLANSARE0    = V_REC.CODLANSARE0,
     L1.CODLANSARE     = V_REC.CODLANSARE,
     L1.CODPROIECTNOD  = V_REC.CODPROIECTNOD,
     L1.TIP            = V_REC.TIP,
     L1.CODCMD1        = V_REC.CODCMD1,
     L1.CANT           = V_REC.CANT,
     L1.NODPARINTE     = V_REC.NODPARINTE,
     L1.CodCmd1P       = V_REC.CodCmd1P,
     L1.DECALAJ        = V_REC.DECALAJ,
     L1.INCEPERE       = V_REC.INCEPERE
   WHERE L1.CODLANSARE1 = V_REC.CODLANSARE1;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_LANSARE3 where codlansare1 &gt; 0 ) LOOP
   UPDATE LANSARE1 L1 SET
     L1.CODLANSARE0    = V_REC.CODLANSARE0,
     L1.CODLANSARE     = V_REC.CODLANSARE,
     L1.CODPROIECTNOD  = V_REC.CODPROIECTNOD,
     L1.TIP            = V_REC.TIP,
     L1.CODCMD1        = V_REC.CODCMD1,
     L1.CANT           = V_REC.CANT,
     L1.NODPARINTE     = V_REC.NODPARINTE,
     L1.CodCmd1P       = V_REC.CodCmd1P,
     L1.DECALAJ        = V_REC.DECALAJ,
     L1.INCEPERE       = V_REC.INCEPERE
   WHERE L1.CODLANSARE1 = V_REC.CODLANSARE1;
  END LOOP;

 ELSE -- INSERT
   SELECT SEQ_LANSARE_CODLANSARE.NEXTVAL INTO RECID FROM DUAL;

   IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
     WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSPROD&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
   END IF;

   INSERT INTO LANSARE(CODLANSARE,CODCMD1,NRDOC,CARNETDOC,DATADOC,CANT,CODPROIECT, SUBUNITATEA, Anulat, Blocat, Operat, UserId, 
                       DataCreare, Automat, CODSCENARIU, OBS)
   SELECT RECID,CODCMD1,NRDOC,CARNETDOC,DATADOC,CANT,CODPROIECT, SUBUNITATEA, Anulat, Blocat, Operat, PKG_GLOBALS.USERID,
          SYSTIMESTAMP, AUTOMAT, CODSCENARIU, OBS FROM TMP_LANSARE;

   for v_rec in (select * from tmp_lansare0) loop
     select SEQ_LANSARE0_CODLANSARE0.NEXTVAL into aCod from dual;
     update tmp_lansare1 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
     update tmp_lansare2 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
     update tmp_lansare3 set codlansare0 = aCod where codlansare0 = v_rec.codlansare0;
     UPDATE TMP_LANSARENEC SET CODLANSARE0 = ACOD WHERE CODLANSARE0 = V_REC.CODLANSARE0;
     INSERT INTO LANSARE0(CODLANSARE0,CODLANSARE,CODCMD1,CANT,CODPROIECT,CODSCENARIU, termen,cantum1)
     values (aCod, RECID, v_rec.CODCMD1,v_rec.CANT,v_rec.CODPROIECT,v_rec.CODSCENARIU, v_rec.termen, v_rec.cantum1);
   end loop;

   INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,RECID,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE FROM TMP_LANSARE1;
   INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,RECID,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE FROM TMP_LANSARE2;
   INSERT INTO LANSARE1 (CODLANSARE1,CODLANSARE0,CODLANSARE,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE)
   SELECT SEQ_LANSARE1_CODLANSARE1.NEXTVAL,CODLANSARE0,RECID,CODPROIECTNOD,TIP,CODCMD1,CANT,NODPARINTE,CodCmd1P,decalaj,INCEPERE FROM TMP_LANSARE3;
   INSERT INTO LANSARENEC(CODLANSARE0, DataStart, CODPROIECTNOD, CANT, NECESARP, NECESAR, REZOLVAT, REZERVAT, NESOSIT, RESTREZERVAT, RESTNESOSIT, TOTREZERVAT, TOTNESOSIT, STOC, CMDINT, DIFERENTE, PARITATEECHIV, CODOBIECT, CODLANSARE)
   SELECT CODLANSARE0, DataStart, CODPROIECTNOD, CANT, NECESARP, NECESAR, REZOLVAT, REZERVAT, NESOSIT, RESTREZERVAT, RESTNESOSIT, TOTREZERVAT, TOTNESOSIT, STOC, CMDINT, DIFERENTE, PARITATEECHIV, CODOBIECT, RECID 
   FROM TMP_LANSARENEC;
 END IF;

 IF ACARNETDOC &lt;&gt; 0 THEN
   PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
 END IF;
 NotifyModif(Operation, RecId, &apos;LANSARE&apos;);
 COMMIT;
END;

end PKG_LANSARE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6797F03255C03EFD760977FFABD59E03B7D529FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LANSPROD IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_44&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodLansProd INTO Tmp FROM LANSPROD WHERE CodLansProd = RecId FOR UPDATE NOWAIT;
END;

FUNCTION GETPREVACC(aCodObiect in number, aAn in number, aSet in number) RETURN NUMBER IS
oData date;
aPrevSet number(2);
aPrevAn number(4);
aRez number(20,7);  
BEGIN
  oData := iso_week_to_date(aAn, aSet) - 14;--to_date(aset||&apos;.&apos;||aAn,&apos;iw.iyyyy&apos;) - 7;
  aPrevSet := to_number(to_char(odata,&apos;IW&apos;));
  aPrevAn  := to_number(to_char(odata,&apos;IYYY&apos;));
  begin
    SELECT sum(L1.NECESAR) into aRez
    FROM LANSPROD1 L1
         INNER JOIN LANSPROD L ON L.CODLANSPROD = L1.CODLANSPROD
    WHERE L.SAPTAMANA = aPrevSet AND L.AN = aPrevAn AND L.SUBUNITATEA = pkg_globals.GETSUBUNITATE and l1.codobiect = aCodObiect;
  exception when others then aRez := 0;
  end;
  return aRez;  
END;  
  
PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200); 
BEGIN
  SELECT
    trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7,
    SAPTAMANA
  INTO
    aDATADOC,
    ADOC
  FROM LANSPROD WHERE CODLANSPROD = RECID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSPROD&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (RecId, 110);  
  DELETE FROM LANSGEST   WHERE CodLansProd = RecId;
  DELETE FROM LANSPROD1  WHERE CodLansProd = RecId;
  DELETE FROM LANSPROD2S WHERE CodLansProd = RecId;
  DELETE FROM LANSPROD2  WHERE CodLansProd = RecId;
  DELETE FROM LANSPROD   WHERE CodLansProd = RecId;
  COMMIT;
END;
  
PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_LANSPROD FIELDS( CodLansProd, saptamana) VALUES (0, to_number(TO_CHAR(sysdate,&apos;IW&apos;))) ;
  --mLansProd
  PKG_CFGTABLES.EXT_INSERTRECORD(110);    
  COMMIT;
END;
  
PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
vDataStart Date;  
vDataStop Date;
oData date;
aPrevSet number(2);
aPrevAn number(4);
BEGIN
  -- Master LANSPROD
  INSERT INTO  TMP_LANSPROD ( CODLANSPROD, SAPTAMANA, SUBUNITATEA, AN, LUNA, USERID, DATACREARE, ANULAT, BLOCAT, OPERAT, DEN_SUBUNIT, OBS, Datastart, Datastop, Dirty)
    ( SELECT L.CODLANSPROD, L.SAPTAMANA, L.SUBUNITATEA, L.AN, L.LUNA, pkg_globals.GETUSERID, sysdate, L.ANULAT, L.BLOCAT, L.OPERAT, SUB.DEN_SUBUNIT, L.OBS,
             iso_week_to_date(l.an, l.saptamana),
             iso_week_to_date(l.an, l.saptamana) + 6, L.Dirty
      FROM LANSPROD L 
           INNER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = L.SUBUNITATEA 
      WHERE L.CodLansProd = RecId );
  
  select datastart - 7 into oData from tmp_lansprod;
  aPrevSet := to_number(to_char(odata,&apos;IW&apos;));
  aPrevAn  := to_number(to_char(odata,&apos;IYYY&apos;));
  
  begin
    select DataStart - 14, DataStop - 14 into vDataStart, vDataStop from tmp_lansprod;
  exception when others then 
    vDataStart := pkg_globals.DATA0;
    vDataStop  := pkg_globals.DATA0;
  end;  
  
  delete tmp_predari_lansprod;
  insert into tmp_predari_lansprod (cant, codobiect)
  select nvl(sum(i1.cant),0), i1.codobiect 
        from intrari1 i1
             inner join intrari i on i1.codintr = i.codintr
             inner join lansprod1 l1 on l1.codobiect = i1.codobiect
        where i.anulat = 0 and i.operat = 1 and i.datadoc between vDataStart and vDataStop 
              and i.tipdoc = 7 and l1.codlansprod = recid
        group by i1.codobiect;      
  
  INSERT INTO  TMP_LANSPROD1 (CODLANSPROD1,CODLANSPROD,CODOBIECT,CANTCOMANDAT,CANTCOMANDATF,STOC,CANTLANSAT,STOCESTIMAT,STOCOPTIM,CANTCOMANDATN,NECESAR,
                              DENUMIRE,CODEXTERN,OBS,DENUM,DEN_CLASEAS,NECESART,PREDARI,PRET,COEFUM,VALOARE,VALOAREACC,CODGEST,TIMPEST,DEN_GEST,EXCLUS,RESTD,
                              SIMBOL,STOCMAX,ACCPREV,CULOARE,AVGSPI)
  SELECT L1.CODLANSPROD1, L1.CODLANSPROD, L1.CODOBIECT, L1.CANTCOMANDAT, L1.CANTCOMANDATF, L1.STOC, L1.CANTLANSAT, L1.STOCESTIMAT, L1.STOCOPTIM, L1.CANTCOMANDATN, L1.NECESAR,
         OBJ.DENUMIRE, OBJ.CODEXTERN, L1.OBS,NUM.DEN_UM, CLSAS.DEN_CLASEAS, L1.NECESART, L1.Predari, L1.PRET, L1.COEFUM, L1.VALOARE, L1.VALOAREACC,
         L1.CODGEST, L1.TIMPEST, G.DEN_GEST, L1.EXCLUS, L1.RESTD, G.SIMBOL, coalesce(L1.STOCMAX,objs.stocmax),L1.ACCPREV,CS.CULOARE,AVGSPI
  FROM LANSPROD1 L1 
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = L1.CODOBIECT
       INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
       INNER JOIN NUM ON NUM.CODUM = ART.UM
       LEFT  JOIN NCARSUPART CS ON CS.CODCARSUPART = OBJ.CODCARACT
       LEFT  JOIN NGEST G ON L1.CODGEST = G.CODGEST
       LEFT  JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = ART.CLASASTATIST
       left  join tmp_predari_lansprod pred on pred.codobiect = l1.codobiect
       left  join nartobjsubunit objs on objs.codobiect = l1.codobiect 
                                         and ( objs.codgest is null or objs.codgest = 0)
                                         and objs.subunitate = pkg_globals.GETSUBUNITATE
  WHERE L1.CodLansProd = RecId;
  
  update TMP_LANSPROD1 SET CANTCOMANDAT = NULL WHERE CANTCOMANDAT = 0;
  update TMP_LANSPROD1 SET CANTCOMANDATF = NULL WHERE CANTCOMANDATF = 0;
  update TMP_LANSPROD1 SET STOC = NULL WHERE STOC = 0;
  update TMP_LANSPROD1 SET CANTLANSAT = NULL WHERE CANTLANSAT = 0;
  update TMP_LANSPROD1 SET STOCESTIMAT = NULL WHERE STOCESTIMAT = 0;
  update TMP_LANSPROD1 SET STOCOPTIM = NULL WHERE STOCOPTIM = 0;
  update TMP_LANSPROD1 SET CANTCOMANDATN = NULL WHERE CANTCOMANDATN = 0;
  update TMP_LANSPROD1 SET NECESAR = NULL WHERE NECESAR = 0;
  update TMP_LANSPROD1 SET NECESART = NULL WHERE NECESAR = 0;
  
  FOR V_REC IN (SELECT sum(L1.NECESAR) NECESAR, TMP1.CODLANSPROD1
                FROM LANSPROD1 L1
                     INNER JOIN LANSPROD L ON L.CODLANSPROD = L1.CODLANSPROD
                     INNER JOIN TMP_LANSPROD1 TMP1 ON TMP1.CODOBIECT = L1.CODOBIECT
                     INNER JOIN TMP_LANSPROD TMP ON TMP.CODLANSPROD = TMP1.CODLANSPROD
                WHERE L.SAPTAMANA = aPrevSet AND L.AN = aPrevAn AND L.SUBUNITATEA = TMP.SUBUNITATEA AND TMP1.ACCPREV IS NULL
                GROUP BY TMP1.CODLANSPROD1
                ) LOOP
    UPDATE TMP_LANSPROD1 SET ACCPREV = V_REC.NECESAR WHERE CODLANSPROD1 = V_REC.CODLANSPROD1;
  END LOOP;

  update TMP_LANSPROD set 
    TotalVal = (select sum(nvl(Valoare,0)) from tmp_lansprod1);
  update TMP_LANSPROD set 
    TotalValAcc = (select sum(nvl(ValoareAcc,0)) from tmp_lansprod1);
  
  insert into tmp_lansgest(codlansgest, codlansprod, codgest, nrschimburi, capacitate, incarcare, incarcarer, den_gest, simbol, oreschimb)
  select codlansgest, codlansprod, codgest, nrschimburi, capacitate, incarcare, incarcarer, den_gest, simbol, oreschimb
  from lansgest
  where codlansprod = RecId;
  
  INSERT INTO TMP_LANSPROD2 (CODLANSPROD2, CODLANSPROD1, CODLANSPROD, CANT, TIMP, CODGEST, CODOBIECT)
  SELECT CODLANSPROD2, CODLANSPROD1, CODLANSPROD, CANT, TIMP, CODGEST, CODOBIECT
  FROM LANSPROD2
  WHERE CODLANSPROD = RECID;
  
  INSERT INTO TMP_LANSPROD2S(CODLANSPROD2S,CODLANSPROD1,CODLANSPROD,CODGEST,INDEXLOCAL,TIMPEST,CANT)
  SELECT CODLANSPROD2S,CODLANSPROD1,CODLANSPROD,CODGEST,INDEXLOCAL,TIMPEST,CANT
  FROM LANSPROD2S WHERE CODLANSPROD = RECID;
  PKG_CFGTABLES.EXT_GOTORECORD(110);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
vCod     NUMBER(20);  
BEGIN
  SELECT
    DATASTART,
    SAPTAMANA
  INTO
    aDATADOC,
    ADOC
  FROM TMP_LANSPROD;

  for v_rec in (select codlansprod1 from tmp_lansprod1 where codobiect is null or codobiect = 0) loop
    delete tmp_lansprod2 where codlansprod1 = v_rec.codlansprod1;
    delete tmp_lansprod2s where codlansprod1 = v_rec.codlansprod1;
    delete tmp_lansprod1 where codlansprod1 = v_rec.codlansprod1;
  end loop;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (110);
  IF Operation = 0 THEN  -- UPDATE
  -- Master LANSPROD
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSPROD&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    
    SELECT CodLansProd INTO RecId FROM TMP_LANSPROD;
    
    UPDATE LANSPROD 
    SET ( CODLANSPROD, SAPTAMANA, SUBUNITATEA, AN, LUNA, USERID, DATACREARE, OPERAT, BLOCAT, ANULAT, OBS, DIRTY)
    = ( SELECT CODLANSPROD, SAPTAMANA, SUBUNITATEA, AN, LUNA, USERID, DATACREARE, OPERAT, BLOCAT, ANULAT, OBS, DIRTY FROM TMP_LANSPROD )
    WHERE CodLANSPROD = RecId;
  
    delete lansprod1 l1 where l1.codlansprod = recid and not exists (select t1.codlansprod1 from tmp_lansprod1 t1 where t1.codlansprod1 = l1.codlansprod1);
    for v_rec in (select * from tmp_lansprod1) loop
      if v_rec.codlansprod1 &gt; 0 then
        update lansprod1 set
          CODOBIECT     = v_rec.CODOBIECT    ,
          CANTCOMANDAT  = v_rec.CANTCOMANDAT ,
          CANTCOMANDATF = v_rec.CANTCOMANDATF,
          STOC          = v_rec.STOC         , 
          CANTLANSAT    = v_rec.CANTLANSAT   , 
          STOCESTIMAT   = v_rec.STOCESTIMAT  , 
          STOCOPTIM     = v_rec.STOCOPTIM    ,
          STOCMAX       = v_rec.STOCMAX      , 
          CANTCOMANDATN = v_rec.CANTCOMANDATN, 
          NECESAR       = v_rec.NECESAR      ,
          NECESART      = v_rec.NECESART     ,
          OBS           = v_rec.OBS          ,
          PREDARI       = v_rec.Predari      ,
          PRET          = V_REC.PRET,
          COEFUM        = V_REC.COEFUM,
          VALOARE       = V_REC.VALOARE,
          VALOAREACC    = V_REC.VALOAREACC,
          CODGEST       = V_REC.CODGEST,
          TIMPEST       = V_REC.TIMPEST,
          EXCLUS        = V_REC.EXCLUS,
          RESTD         = V_REC.RESTD,
          ACCPREV       = V_REC.ACCPREV,
          AVGSPI        = V_REC.AVGSPI
        where codlansprod1 = v_rec.codlansprod1;
      else
        select seq_lansprod1_CODLANSPROD1.Nextval into vcod from dual;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;lansprod1&apos;, VCOD, V_REC.codlansprod1);
        update tmp_lansprod2 set codlansprod1 = vcod where codlansprod1 = v_rec.codlansprod1;
        update tmp_lansprod2s set codlansprod1 = vcod where codlansprod1 = v_rec.codlansprod1;
        INSERT INTO LANSPROD1 (CODLANSPROD1,CODLANSPROD,CODOBIECT,CANTCOMANDAT,CANTCOMANDATF,STOC,CANTLANSAT,STOCESTIMAT,STOCOPTIM,CANTCOMANDATN,NECESAR,OBS,NECESART,
                               PREDARI, PRET, COEFUM, VALOARE, VALOAREACC, CODGEST, TIMPEST, EXCLUS, RESTD, STOCMAX, ACCPREV,AVGSPI)
        values (vcod, RecId, v_rec.CODOBIECT, v_rec.CANTCOMANDAT, v_rec.CANTCOMANDATF, v_rec.STOC, v_rec.CANTLANSAT, v_rec.STOCESTIMAT, 
                v_rec.STOCOPTIM, v_rec.CANTCOMANDATN, v_rec.NECESAR, v_rec.OBS, v_rec.necesart, V_REC.PREDARI, V_REC.PRET, V_REC.COEFUM, V_REC.VALOARE, V_REC.VALOAREACC,
                V_REC.CODGEST, V_REC.TIMPEST, V_REC.EXCLUS, V_REC.RESTD, V_REC.STOCMAX, V_REC.ACCPREV,V_REC.AVGSPI);
      end if;
    end loop;
  
    delete lansgest lg where lg.codlansprod = recid and not exists (select t.codlansgest from tmp_lansgest t where t.codlansgest = lg.codlansgest);
    for v_rec in (select * from tmp_lansgest) loop
      if v_rec.codlansgest &gt; 0 then
        update lansgest set
          codgest     = v_rec.codgest,
          nrschimburi = v_rec.nrschimburi,
          capacitate  = v_rec.capacitate,
          incarcare   = v_rec.incarcare,
          incarcarer  = v_rec.incarcarer,
          den_gest    = v_rec.den_gest,
          simbol      = v_rec.simbol,
          oreschimb   = v_rec.oreschimb
        where codlansgest = v_rec.codlansgest;
      else
        INSERT INTO LANSGEST (codlansgest, codlansprod, codgest, nrschimburi, capacitate, incarcare, incarcarer, den_gest, simbol, oreschimb)
        values (seq_lansgest_codlansgest.nextval, recid, v_rec.codgest, v_rec.nrschimburi, v_rec.capacitate, v_rec.incarcare, v_rec.incarcarer, v_rec.den_gest, v_rec.simbol,
                v_rec.oreschimb);
      end if;
    end loop;
    
    delete lansprod2 l2 where l2.codlansprod = recid and not exists (select t2.codlansprod2 from tmp_lansprod2 t2 where t2.codlansprod2 = l2.codlansprod2);
    for v_rec in (select * from tmp_lansprod2) loop
      if v_rec.codlansprod2 &gt; 0 then
        update lansprod2 set
          CANT      = CANT,
          TIMP      = TIMP,
          CODGEST   = CODGEST,
          CODOBIECT = CODOBIECT
        where codlansprod2 = v_rec.codlansprod2;
      else
        INSERT INTO LANSPROD2(CODLANSPROD2,CODLANSPROD1,CODLANSPROD,CANT,TIMP,CODGEST,CODOBIECT)
        values (SEQ_LANSPROD2_CODLANSPROD2.NEXTVAL,V_REC.CODLANSPROD1,RECID,V_REC.CANT,V_REC.TIMP,V_REC.CODGEST,V_REC.CODOBIECT);
      end if;
    end loop;
    
    delete lansprod2s l2 where l2.codlansprod = recid and not exists (select t2.codlansprod2s from tmp_lansprod2s t2 where t2.codlansprod2s = l2.codlansprod2s);
    for v_rec in (select * from tmp_lansprod2s) loop
      if v_rec.codlansprod2s &gt; 0 then
        update lansprod2s set
          CODGEST   = V_REC.CODGEST,
          INDEXLOCAL = V_REC.INDEXLOCAL,
          TIMPEST = V_REC.TIMPEST,
          CANT = V_REC.CANT
        where codlansprod2s = v_rec.codlansprod2s;
      else
        INSERT INTO LANSPROD2S(CODLANSPROD2S,CODLANSPROD1,CODLANSPROD,CODGEST,INDEXLOCAL,TIMPEST,CANT)
        values (SEQ_LANSPROD2S_CODLANSPROD2S.NEXTVAL,V_REC.CODLANSPROD1,RECID,V_REC.CODGEST,V_REC.INDEXLOCAL,V_REC.TIMPEST,V_REC.CANT);
      end if;
    end loop;
  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSPROD&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF; 
  -- Master LANSPROD
    SELECT SEQ_LANSPROD_CodLANSPROD.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;LANSPROD&apos;, RecId);
    INSERT INTO  LANSPROD ( CODLANSPROD, SAPTAMANA, SUBUNITATEA, AN, LUNA, USERID, DATACREARE, OPERAT, BLOCAT, ANULAT, OBS, DIRTY )
              ( SELECT  RecId ,SAPTAMANA, SUBUNITATEA, AN, LUNA, PKG_GLOBALS.USERID, SYSTIMESTAMP, OPERAT, BLOCAT, ANULAT, OBS, DIRTY
                FROM TMP_LANSPROD  ) ;
    
    for v_rec in (select * from tmp_lansprod1) loop
      select seq_lansprod1_CODLANSPROD1.Nextval into vcod from dual;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;LANSPROD1&apos;, VCOD, V_REC.codlansprod1);      
      update tmp_lansprod2 set codlansprod1 = vcod where codlansprod1 = v_rec.codlansprod1;
      update tmp_lansprod2s set codlansprod1 = vcod where codlansprod1 = v_rec.codlansprod1; 
  	  INSERT INTO LANSPROD1 
			(CODLANSPROD1, CODLANSPROD, CODOBIECT,CANTCOMANDAT,CANTCOMANDATF,STOC, CANTLANSAT, STOCESTIMAT, STOCOPTIM, CANTCOMANDATN, NECESAR,OBS,NECESART,
        PREDARI,PRET,COEFUM,VALOARE,VALOAREACC,CODGEST,TIMPEST,EXCLUS,RESTD,ACCPREV,AVGSPI)
			values(vcod,RecId,v_rec.CODOBIECT,v_rec.CANTCOMANDAT,v_rec.CANTCOMANDATF,v_rec.STOC,v_rec.CANTLANSAT,v_rec.STOCESTIMAT,v_rec.STOCOPTIM,v_rec.CANTCOMANDATN,v_rec.NECESAR,v_rec.OBS,
             v_rec.NECESART,v_rec.PREDARI,v_rec.PRET,v_rec.COEFUM,v_rec.VALOARE,v_rec.VALOAREACC,v_rec.CODGEST,v_rec.TIMPEST,V_REC.EXCLUS,V_REC.RESTD,
             V_REC.ACCPREV,V_REC.AVGSPI);
    end loop;
         
    insert into lansgest(codlansgest, codlansprod, codgest, nrschimburi, capacitate, incarcare, incarcarer, den_gest, simbol, oreschimb)
    select seq_lansgest_codlansgest.nextval, recid, codgest, nrschimburi, capacitate, incarcare, incarcarer, den_gest, simbol, oreschimb
    from tmp_lansgest;
    
    INSERT INTO LANSPROD2(CODLANSPROD2,CODLANSPROD1,CODLANSPROD,CANT,TIMP,CODGEST,CODOBIECT)
    SELECT SEQ_LANSPROD2_CODLANSPROD2.NEXTVAL,CODLANSPROD1,RECID,CANT,TIMP,CODGEST,CODOBIECT
    FROM TMP_LANSPROD2;
    
    INSERT INTO LANSPROD2S(CODLANSPROD2S,CODLANSPROD1,CODLANSPROD,CODGEST,INDEXLOCAL,TIMPEST,CANT)
    SELECT SEQ_LANSPROD2S_CODLANSPROD2S.NEXTVAL,CODLANSPROD1,RECID,CODGEST,INDEXLOCAL,TIMPEST,CANT FROM TMP_LANSPROD2S;
  END IF;
  PKG_CFGTABLES.EXT_POSTRECORDS(110, OPERATION);
  COMMIT;
END;

procedure PreiaProduse(RecId in number, DataStart in varchar2, DataStop in varchar2) is
begin
  delete tmp_lansprod1;
  
  insert into tmp_lansprod1(
    codlansprod1, 
    codlansprod, 
    codobiect, 
    cantcomandat, 
    cantcomandatf, 
    stoc, 
    cantlansat, 
    stocestimat, 
    stocoptim, 
    cantcomandatn, 
    necesar, 
    denumire, 
    codextern,
    codgest,
    timpest,
    den_gest)
  with 
    Produse as (
      select distinct codobiect, codgest, timpest 
      from (
            select pc.codobiect, pg.codgest, pg.timpest
            from prodcomp pc
                 inner join (select codprodcomp, min(indexlocal) indexlocal from prodgest where timpest &gt; 0 group by codprodcomp) minp on minp.codprodcomp = pc.codprodcomp
                 inner join prodgest pg on pg.codprodcomp = minp.codprodcomp and pg.indexlocal = minp.indexlocal 
            where not exists (select pm.codobiect from prodmat pm where pm.codobiect = pc.codobiect) and pc.implicit = 1
           )
    ),
    Lansari as (
      select prod.codobiect, sum(prod.rest) cant
      from Produse
           inner join cmdprodmat prod on produse.codobiect = prod.codobiect
           inner join comanda1 c1 on prod.codcomanda1 = c1.codcomanda1
           inner join comanda c on c1.codcomanda = c.codcomanda
      where prod.tip = 0 and c.operat = 1 and c.anulat = 0
      group by prod.codobiect
    ),
    Stoc as (
      select 
        produse.codobiect, 
        sum(case 
              when nse.codnirser &gt; 0 then nse.rest
              else ns.rest
            end) cant      
      from produse
           inner join nirstoc ns on ns.codobiect = produse.codobiect
           inner join nir on nir.codnir = ns.codnir
           inner join ngest ng on ng.codgest = nir.gest and ng.codsubunit = pkg_globals.GETSUBUNITATE_DOC
           inner join TMP_IOART_LUNA tmp on tmp.codioart = ns.codioart
           left join nirser nse on nse.codnirstoc = ns.codnirstoc
      where tmp.mg &lt;&gt; 5
      group by produse.codobiect
    )
  select 
    - RowNum, 
    RecId, 
    Produse.CodObiect,
    0,
    0,
    Stoc.Cant, 
    Lansari.Cant, 
    Stoc.Cant + Lansari.Cant, 
    objs.stocmed, 
    0, 
    0, 
    obj.denumire, 
    obj.codextern,
    produse.codgest,
    produse.timpest,
    g.den_gest
  from Produse
       inner join nartobj obj on obj.codobiect = produse.codobiect
       left  join ngest g on produse.codgest = g.codgest 
       left  join stoc on stoc.codobiect = produse.codobiect
       left  join lansari on lansari.codobiect = produse.codobiect
       left  join nartobjsubunit objs on objs.codobiect = produse.codobiect
                                      and ( objs.codgest is null or objs.codgest = 0) 
                                      and objs.subunitate = pkg_globals.getsubunitate_doc;
end;

END PKG_LANSPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F77AB4168434F34AC9F113D46A3530DD4A70F2B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LANSZ IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_46&apos;;

procedure UpdateLansz1Cmd1(aCamp in varchar2, aLansat in number, aCodComanda1 in number, aCodLansz1 in number) is
sSQL varchar2(1000);
begin
  sSQL := &apos;UPDATE LANSZ1 SET LANS_&apos;||aCamp||&apos; = &apos;||aLansat||&apos;, CodCmd1_&apos;||aCamp||&apos; = &apos;||aCodComanda1||&apos; WHERE CODLANSZ1 = &apos;||aCodLansz1;
  execute immediate sSQL;
  commit;
end;

procedure ActualizeazaStoc is
aCodSubunit number(20);
aCount number(10);
begin
  select count(*) into aCount from tmp_lansz1;
  if aCount = 0 then return; end if;
  select subunitatea into aCodSubunit from tmp_lansz;
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  UPDATE TMP_LANSZ1 L1
  SET STOC =
    (
    SELECT SUM(NS.REST) STOC
    FROM NIRSTOC NS
         INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
         INNER JOIN NGEST G ON G.CODGEST = NIR.GEST,
         TMP_IOART_LUNA IOALUNA
    WHERE NS.CODIOART = IOALUNA.CODIOART AND G.TIP &lt;&gt; 4 AND NS.REST &lt;&gt; 0
          AND NIR.OPERAT = 1 AND IOALUNA.MG &lt;&gt; 5 AND G.CODSUBUNIT = aCodSubunit
          AND NS.CODOBIECT = L1.CODOBIECT
    );
end;

function CanLockLansZ(aAn in number, aSaptamana in number, aSubunit in number) return number is
Rez integer(1);
Tmp number(20);
begin
  Rez := 1;
  for v_rec in (select codlansz from lansz where saptamana = aSaptamana and an = aan and subunitatea = asubunit and nvl(finalizat,0) = 0) loop
    begin
      SELECT CodLansZ INTO Tmp FROM LANSZ WHERE CodLansZ = v_rec.codlansz FOR UPDATE NOWAIT;
    exception when others then
      RollBack;
      Rez := 0;
      Exit;
    end;
  end loop;
  return Rez;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodLansZ INTO Tmp FROM LANSZ WHERE CodLansZ = RecId FOR UPDATE NOWAIT;
END;

function ActualizeazaLinie(aCodLansZ1 in number, aCant in number, aZi in number) return number is
Rez number(1);
vCant number(20,7);
vRest number(20,7);
vDif number(20,7);
begin
  Rez := 1;
  begin
    select sum(c1.cantacceptat), sum(prod.rest) into vCant, vRest
    from comanda1 c1
         inner join cmdprodmat prod on prod.codcomanda1 = c1.codcomanda1 and prod.tip = 0
         inner join lansz1_cmd lcmd1 on c1.codcomanda1 = lcmd1.codcomanda1
    where lcmd1.codlansz1 = aCodLansZ1 and lcmd1.zi = aZi;
  exception when others then
    vCant := 0;
    vRest := 0;
  end;

  vDif := vCant - aCant;

  if vDif &gt; vRest then
    Rez := 0;
  else
    for v_rec in (select c1.cantacceptat, prod.rest, c1.codcomanda1, c1.codcomanda, c.carnetdoc, c.nrdoc
                  from lansz1_cmd lcmd1
                       inner join comanda1 c1 on c1.codcomanda1 = lcmd1.codcomanda1
                       inner join comanda c on c1.codcomanda = c.codcomanda
                       inner join cmdprodmat prod on prod.codcomanda1 = c1.codcomanda1 and prod.tip = 0
                  where prod.rest &gt; 0 and lcmd1.codlansz1 = aCodLansZ1 and lcmd1.zi = aZi
                  order by c.datacreare desc
                 ) loop
      if v_rec.rest &lt;= vDif then
        --scadem cu rest
        if v_rec.cantacceptat - v_rec.rest = 0 then
          delete cmdprodmat where codcomanda1 = v_rec.codcomanda1;
          delete cmdprodman where codcomanda1 = v_rec.codcomanda1;
          delete comanda1 where codcomanda1 = v_rec.codcomanda1;
          delete comanda where codcomanda = v_rec.codcomanda;
          delete lansz1_cmd where codcomanda1 = v_rec.codcomanda1;
          if nvl(v_rec.carnetdoc,0) &gt; 0 then
            PKG_CARNETEDOC.RELEASENUMARDOC(v_rec.CARNETDOC, v_rec.NRDOC);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(v_rec.CARNETDOC);
          end if;
        else
          update comanda1 set cantacceptat = cantacceptat - v_rec.rest, cantcomandat = cantacceptat - v_rec.rest where codcomanda1 = v_rec.CodComanda1;
          update cmdprodman set rest = 0, cant = cant - rest where codcomanda1 = v_rec.CodComanda1;
          update cmdprodmat set rest = 0, cant = cant - rest where codcomanda1 = v_rec.CodComanda1;
        end if;
        vDif := vDif - v_rec.Rest;
      else
        update comanda1 set cantacceptat = cantacceptat - vDif, cantcomandat = cantcomandat - vDif where codcomanda1 = v_rec.CodComanda1;
        update cmdprodman set rest = rest - vDif * cant / v_rec.cantacceptat, cant = cant - vDif * cant / v_rec.cantacceptat where codcomanda1 = v_rec.CodComanda1;
        update cmdprodmat set rest = rest - vDif * cant / v_rec.cantacceptat, cant = cant - vDif * cant / v_rec.cantacceptat where codcomanda1 = v_rec.CodComanda1;
        vDif := 0;
      end if;
      if vDif = 0 then Exit; end if;
    end loop;
  end if;

  if rez = 1 then Commit; end if;
  return Rez;
end;

function ActualizeazaLinieCmd1(aCodComanda1 in number, aCant in number) return number is
Rez number(1);
vCant number(20,7);
vRest number(20,7);
vDif number(20,7);
vCodComanda number(20);
begin
  Rez := 1;
  begin
    select codcomanda into vCodComanda
    from comanda1 c1
    where c1.codcomanda1 = aCodComanda1;
  exception when others then
    vCodComanda := 0;
  end;
  begin
    select prod.cant, prod.rest into vCant, vRest
    from comanda1 c1
         inner join cmdprodmat prod on prod.codcomanda1 = c1.codcomanda1 and prod.tip = 0
    where c1.codcomanda1 = aCodComanda1;
  exception when others then
    vCant := 0;
    vRest := 0;
  end;

  vDif := vCant - aCant;

  if aCant = 0 then
    pkg_comanda.SP_DELETERECORD(vcodcomanda);
  else
    if vDif &gt; vRest then
      Rez := 0;
    else
      update comanda1 set cantacceptat = cantacceptat - vDif, cantcomandat = cantcomandat - vDif where codcomanda1 = aCodComanda1;
      update cmdprodman set rest = rest - vDif * cant / vcant, cant = cant - vDif * cant / vcant where codcomanda1 = aCodComanda1;
      update cmdprodmat set rest = rest - vDif * cant / vcant, cant = cant - vDif * cant / vcant, ccant = ccant - vDif * ccant / vcant where codcomanda1 = aCodComanda1;
    end if;
  end if;

  if rez = 1 then Commit; end if;
  return Rez;
end;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
BEGIN
  SELECT
    trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7,
    SAPTAMANA
  INTO
    aDATADOC,
    ADOC
  FROM LANSZ WHERE CODLANSZ = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSZ&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  SP_LOCKRECORD(RecId);
  DELETE FROM DFLANSZ1 WHERE CODLANSZ = RECID;
  DELETE FROM LANSZ1 WHERE CodLansZ = RecId;
  DELETE FROM LANSZ WHERE CodLansZ = RecId;
  NotifyModif(2, RecId, &apos;LANSZ&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_LANSZ FIELDS( CodLansZ, Saptamana, Dirty, Finalizat ) VALUES (0, to_number(TO_CHAR(sysdate,&apos;IW&apos;)), 0, 0) ;
  COMMIT;
END;

procedure CreazaLansZ1(ACODGEST IN NUMBER, ACODLANSZ IN NUMBER, ASAPTAMANA IN NUMBER, AAN IN NUMBER, ASECTIE IN NUMBER) is
aPrevSapt number(2);
aPrevAn   number(4);
aNextAn   number(4);
aNextSapt number(2);
aSubunit  number(20);
VUSERID NUMBER(20);
oData date;
aCount number(10);
begin
  VUSERID := PKG_GLOBALS.GETUSERID;

  oData := iso_week_to_date(aan, asaptamana);

  oData := oData - 7;
  aPrevSapt := to_number(to_char(odata,&apos;IW&apos;));
  aPrevAn   := to_number(to_char(odata,&apos;IYYY&apos;));

  oData := oData + 14;
  aNextSapt := to_number(to_char(odata,&apos;IW&apos;));
  aNextAn   := to_number(to_char(odata,&apos;IYYY&apos;));

  /*IF ASAPTAMANA = 1 THEN
    aPrevSapt := 53;
    aPrevAn := aAn - 1;
  ELSE
    aPrevSapt := aSaptamana - 1;
    aPrevAn := aAn;
  END IF;

  IF ASAPTAMANA = 53 THEN
    aNextSapt := 1;
    aNextAn := aAn + 1;
  ELSE
    aNextSapt := aSaptamana + 1;
    aNextAn := aAn;
  END IF;*/

  begin
    select subunitatea into aSubunit from lansz where codlansz = acodlansz;
  exception when others then
    aSubunit := pkg_globals.GETSUBUNITATE;
  end;

  DELETE TMP_PLANIFNODZ where userid = VUSERID;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, sum(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, sum(PNOD.NECESAR) REFWEEK, VUSERID USERID
         FROM PLANIFNOD PNOD
              INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
              INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
              INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
         WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
               PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
               PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
               PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
               nvl(PP.INSAPTAMANA,1) = 1 and
               PP.SUBUNITATEA = aSubunit AND
               (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
         GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, VUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
               INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
                nvl(PP.INSAPTAMANA,1) = 1 AND
                PP.SUBUNITATEA = aSubunit AND
                (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, VUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
               INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
                nvl(PP.INSAPTAMANA,1) = 1 AND
                PP.SUBUNITATEA = aSubunit AND
                (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, VUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
               INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
                PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
                nvl(PP.INSAPTAMANA,1) = 0 AND
                PP.SUBUNITATEA = aSubunit AND
                (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, VUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
       INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
  WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, VUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
       INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
  WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, VUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
       INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
        PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, VUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
       INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, VUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
       INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = PNOD.CODRETETA and nvl(pg.timpest,0) = 0
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  select X.codreteta CODRETETA, X.codobiect CODOBIECT, 0 necesar, 0 nextweek, 0 REFWEEK, VUSERID USERID from
  (SELECT distinct L1.CODRETETA, L1.CODOBIECT
   from LANSZ1 L1
        inner join LANSZ l on l.codlansz = l1.codlansz
        INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = L1.CODRETETA and nvl(pg.timpest,0) = 0
   where l.operat = 1 and l.anulat = 0 and l.blocat = 0
         and l.an = aprevan and l.saptamana = aprevsapt
         and l1.report &gt; 0 AND L.SUBUNITATEA = aSubunit AND
         (ACODGEST = 0 OR PG.CODGEST = ACODGEST)
   ) X
   ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  DELETE LANSZ1_MANEVRA where userid = vuserid;
  INSERT INTO LANSZ1_MANEVRA (CODLANSZ1, CODLANSZ, CODRETETA, CODOBIECT, DENUMIRE, DEN_CLASEPROD, RETETA, CODFORMATIE, SCHIMB, DEN_CLASEAS,
                          TOTAL, NEXTWEEK, REFWEEK, ORDINE, CODPRODCOMP,
                          GESTIMPLICITA,GESTRETETA,
                          OBS1, OBS2, OBS3, OBS4, OBS5, OBS6,CODNORMA,CODEXTERN,CODINTERN,CODGEST,USERID)
  SELECT - RowNum, ACODLANSZ, PF.CODRETETA, PF.CODOBIECT, OBJ.DENUMIRE, CLS_PROD.DEN_CLASEPROD, PC.OBS, F.CODFORMATIE, S.SCHIMB, CLS_AS.DEN_CLASEAS,
         PF.NECESAR, PF.NextWeek, PF.REFWEEK, PF.ORDINE, PC.CODPRODCOMP,
         GIMP.DEN_GEST, GRET.DEN_GEST, PC.OBS1, PC.OBS2, PC.OBS3, PC.OBS4, PC.OBS5, PC.OBS6, NOR.CODNORMA,
         OBJ.CODEXTERN, OBJ.CODINTERN,GRET.CODGEST,VUSERID
  FROM TMP_PLANIFNODZ PF
    INNER JOIN PRODCOMP PC ON PF.CODRETETA = PC.CODPRODCOMP
    inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and nvl(pg.timpest,0) = 0
    inner JOIN NGEST GRET ON PG.CODGEST = GRET.CODGEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = PF.CODOBIECT
    INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
    LEFT JOIN NARTIMPLICITE AIMP ON ART.CODARTICOL = AIMP.CODARTICOL AND AIMP.CODSUBUNIT = aSubunit
    LEFT JOIN NGEST GIMP ON AIMP.GESTIMPLICITA = GIMP.CODGEST
    LEFT JOIN  PRODNORME NOR ON NOR.CODPRODCOMP = PC.CODPRODCOMP AND NOR.IMPLICIT = 1
    LEFT JOIN NCLASEAS CLS_AS ON CLS_AS.CODCLASEAS = ART.CLASASTATIST
    LEFT JOIN NCLASEPROD CLS_PROD ON CLS_PROD.CODCLASEPROD = PC.CODCLASAPROD,
    (SELECT CODFORMATIE FROM FORMATII
     WHERE CODGEST = aSectie
     UNION ALL
     SELECT CODFORMATIE FROM FORMATII
     WHERE NVL(CODGEST,0) = 0 AND CODFORMATIE &gt; 100
    ) F,
    (select level as schimb from dual connect by level &lt; (select nvl(nrschimburi,0) from ngest where codgest = aSectie) + 1) S
  WHERE PF.USERID = VUSERID;

  INSERT INTO LANSZ1_MANEVRA (CODLANSZ1, CODLANSZ, CODRETETA, CODOBIECT, DENUMIRE, DEN_CLASEPROD, RETETA, CODFORMATIE, SCHIMB, DEN_CLASEAS,
                          TOTAL, NEXTWEEK, REFWEEK, ORDINE, CODPRODCOMP,
                          GESTIMPLICITA,GESTRETETA,
                          OBS1, OBS2, OBS3, OBS4, OBS5, OBS6,CODNORMA,CODEXTERN,CODINTERN,CODGEST,USERID)
  SELECT - RowNum, ACODLANSZ, PF.CODRETETA, PF.CODOBIECT, OBJ.DENUMIRE, CLS_PROD.DEN_CLASEPROD, PC.OBS, 0, 0, CLS_AS.DEN_CLASEAS,
         PF.NECESAR, PF.NextWeek, PF.REFWEEK, PF.ORDINE, PC.CODPRODCOMP,
         GIMP.DEN_GEST, GRET.DEN_GEST, PC.OBS1, PC.OBS2, PC.OBS3, PC.OBS4, PC.OBS5, PC.OBS6, NOR.CODNORMA,
         OBJ.CODEXTERN, OBJ.CODINTERN,GRET.CODGEST,VUSERID
  FROM TMP_PLANIFNODZ PF
    INNER JOIN PRODCOMP PC ON PF.CODRETETA = PC.CODPRODCOMP
    inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and nvl(pg.timpest,0) = 0
    inner JOIN NGEST GRET ON PG.CODGEST = GRET.CODGEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = PF.CODOBIECT
    INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
    LEFT JOIN NARTIMPLICITE AIMP ON ART.CODARTICOL = AIMP.CODARTICOL AND AIMP.CODSUBUNIT = aSubunit
    LEFT JOIN NGEST GIMP ON AIMP.GESTIMPLICITA = GIMP.CODGEST
    LEFT JOIN  PRODNORME NOR ON NOR.CODPRODCOMP = PC.CODPRODCOMP AND NOR.IMPLICIT = 1
    LEFT JOIN NCLASEAS CLS_AS ON CLS_AS.CODCLASEAS = ART.CLASASTATIST
    LEFT JOIN NCLASEPROD CLS_PROD ON CLS_PROD.CODCLASEPROD = PC.CODCLASAPROD
  WHERE PF.USERID = VUSERID;


  IF ACODLANSZ &gt; 0 THEN

    for v_rec in (select l1.codlansz1, l1.LUNI, l1.MARTI, l1.MIERCURI, l1.JOI, l1.VINERI, l1.SAMBATA, l1.DUMINICA, l1.REPORT, l1.schimb, l1.codformatie,
                         l1.codreteta, l1.codobiect
                  from LANSZ1_MANEVRA TMP
                       inner join lansz1 l1 on L1.CODLANSZ = ACODLANSZ
                                               AND L1.CODOBIECT = TMP.CODOBIECT
                                               AND L1.CODRETETA = TMP.CODRETETA
                                               AND L1.CODFORMATIE = TMP.CODFORMATIE
                                               AND L1.SCHIMB = TMP.SCHIMB
                  where tmp.userid = VUSERID) loop
      UPDATE LANSZ1_MANEVRA TMP
      SET (CODLANSZ1,
           LUNI,
           MARTI,
           MIERCURI,
           JOI,
           VINERI,
           SAMBATA,
           DUMINICA,
           REPORT)
        =
        ( select
            v_rec.CODLANSZ1,
            v_rec.LUNI,
            v_rec.MARTI,
            v_rec.MIERCURI,
            v_rec.JOI,
            v_rec.VINERI,
            v_rec.SAMBATA,
            v_rec.DUMINICA,
            v_rec.REPORT
          from dual
         )
          WHERE
            v_rec.CODOBIECT = TMP.CODOBIECT
            AND v_rec.CODRETETA = TMP.CODRETETA
            AND v_rec.CODFORMATIE = TMP.CODFORMATIE
            AND v_rec.SCHIMB = TMP.SCHIMB
            and tmp.userid = vuserid;
    end loop;
    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_luni
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_luni = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_marti
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_marti = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_miercuri
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_miercuri = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_joi
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_joi = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_vineri
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_vineri = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_sambata
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_sambata = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    for v_rec in (select tmp.codlansz1, c1.cantacceptat
                  from lansz1_manevra tmp
                       inner join lansz1 l1 on l1.codlansz1 = tmp.codlansz1
                       inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_duminica
                  where tmp.codlansz1 &gt; 0 and tmp.userid = vuserid) loop
      update lansz1_manevra set lans_duminica = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1 and userid = vuserid;
    end loop;

    IF ACODLANSZ &gt; 0 THEN
      DELETE LANSZ1_MANEVRA1 where userid = vuserid;
      INSERT INTO LANSZ1_MANEVRA1(Codobiect, Codformatie, Codreteta, Schimb, luni, marti, miercuri, joi, vineri, sambata, duminica,userid)
      SELECT Codobiect, Codformatie, Codreteta, Schimb, luni, marti, miercuri, joi, vineri, sambata, duminica, vuserid FROM LANSZ1 where codlansz = acodlansz;
    END IF;

    UPDATE lansz1_manevra TMP
    SET ( LUNI,
          MARTI,
          MIERCURI,
          JOI,
          VINERI,
          SAMBATA,
          DUMINICA
        )
      = (
        SELECT
          SUM(Nvl(L1.Luni,    0)),
          SUM(Nvl(L1.Marti,   0)),
          SUM(Nvl(L1.Miercuri,0)),
          SUM(Nvl(L1.Joi,     0)),
          SUM(Nvl(L1.Vineri,  0)),
          SUM(Nvl(L1.Sambata, 0)),
          SUM(Nvl(L1.Duminica,0))
        FROM LansZ1_manevra1 l1
        WHERE L1.CODOBIECT = TMP.CODOBIECT
          AND L1.CODRETETA = TMP.CODRETETA
          AND L1.CODFORMATIE &gt; 0
          AND L1.SCHIMB &gt; 0
          and l1.userid = vuserid
      )
    WHERE tmp.codformatie = 0 and tmp.schimb = 0 and userid = vuserid;
  END IF;

  delete lansz1_manevra1 where userid = vuserid;
  insert into lansz1_manevra1(codobiect, codreteta, report, userid)
  select distinct l1.codobiect, l1.codreteta, l1.report, vuserid
  from lansz1 l1
       inner join lansz l on l1.codlansz = l.codlansz
  where l.operat = 1 and l.anulat = 0 and l.blocat = 0
        and l.an = aprevan and l.saptamana = aprevsapt
        and l1.report &gt; 0;

  UPDATE LANSZ1_manevra TMP
  SET
    LASTWEEK = (SELECT sum(l1.report)
                from lansz1_manevra1 L1
                where l1.codreteta = tmp.codreteta and l1.codobiect = tmp.codobiect and l1.userid = vuserid
                )
  where userid = vuserid;

  DELETE LANSZ1_MANEVRA1 where userid = vuserid;
  INSERT INTO LANSZ1_MANEVRA1(CODOBIECT, CODRETETA, TOTAL,USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.LUNI,0) + NVL(L1.MARTI,0) + NVL(L1.MIERCURI,0) + NVL(L1.JOI,0) + NVL(L1.VINERI,0) + NVL(L1.SAMBATA,0) + NVL(L1.DUMINICA,0)),
         VUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; ACODLANSZ AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE &gt; 0 AND L1.SCHIMB &gt; 0
        AND L.SUBUNITATEA = aSubunit
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE LANSZ1_MANEVRA TMP
  SET
    ALTE = (SELECT TOTAL
            FROM LANSZ1_MANEVRA1 L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA AND L1.USERID = VUSERID
           )
  WHERE USERID = VUSERID;

  DELETE LANSZ1_MANEVRA1 where userid = vuserid;
  INSERT INTO LANSZ1_MANEVRA1(CODOBIECT, CODRETETA, REPORT,USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.REPORT,0)),VUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; ACODLANSZ AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE = 0 AND L1.SCHIMB = 0
        AND L.SUBUNITATEA = aSubunit
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE LANSZ1_MANEVRA TMP
  SET
    REPORTALTE = (SELECT L1.REPORT
            FROM LANSZ1_MANEVRA1 L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA AND USERID = VUSERID
            )
  WHERE USERID = VUSERID;

  UPDATE LANSZ1_MANEVRA SET
  TOTALDELANSAT = nvl(TOTAL,0) + nvl(LASTWEEK,0) + nvl(NEXTWEEK,0),
  TOTALLANSAT   = nvl(LUNI,0) + nvl(MARTI,0) + nvl(MIERCURI,0) + nvl(JOI,0) + nvl(VINERI,0) + nvl(SAMBATA,0) + nvl(DUMINICA,0)
  WHERE USERID = VUSERID;

  commit;

  UPDATE LANSZ1_MANEVRA TMP SET
  RESTDELANSAT = (select sum(nvl(T.TOTALDELANSAT,0) - nvl(T.TOTALLANSAT,0) - nvl(T.report,0) - nvl(T.alte,0) - nvl(T.ReportAlte,0))
                  FROM LANSZ1_MANEVRA T
                  WHERE T.CODFORMATIE = 0 AND T.SCHIMB = 0
                        AND T.CODRETETA = TMP.CODRETETA AND T.CODOBIECT = TMP.CODOBIECT AND T.USERID = VUSERID
                        AND T.CODFORMATIE = TMP.CODFORMATIE AND T.SCHIMB = TMP.SCHIMB)
  WHERE TMP.USERID = VUSERID;

  update lansz1_MANEVRA tmp set
    Lans_Luni = (select sum(l1.Lans_Luni)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Marti = (select sum(l1.Lans_Marti)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Miercuri = (select sum(l1.Lans_Miercuri)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Joi = (select sum(l1.Lans_Joi)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Vineri = (select sum(l1.Lans_Vineri)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Sambata = (select sum(l1.Lans_Sambata)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID),
    Lans_Duminica = (select sum(l1.Lans_Duminica)
            from LansZ1_MANEVRA l1
            where l1.codlansz = ACODLANSZ and L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
            and l1.codformatie &gt; 0 and l1.schimb &gt; 0 AND L1.USERID = VUSERID)
  where tmp.codformatie = 0 and tmp.schimb = 0 AND TMP.USERID = VUSERID;

  update lansz1_MANEVRA tmp
  set lans_luni = null
  where lans_luni = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_marti = null
  where lans_marti = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_miercuri = null
  where lans_miercuri = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_joi = null
  where lans_joi = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_vineri = null
  where lans_vineri = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_sambata = null
  where lans_sambata = 0 AND USERID = VUSERID;
  update lansz1_MANEVRA tmp
  set lans_duminica = null
  where lans_duminica = 0 AND USERID = VUSERID;

  DELETE FROM LANSZ1_MANEVRA
  WHERE ((codformatie=0 and schimb &gt; 0)or(codformatie &gt; 0 and SCHIMB=0)) AND USERID = VUSERID;
  delete lansz1_MANEVRA where codobiect is null AND USERID = VUSERID;

  delete lansz1_manevra1;
  insert into lansz1_manevra1 (
    CODLANSZ, CODLANSZ1, codformatie, schimb, codreteta, codobiect,
    luni, marti, miercuri, joi, vineri, sambata, duminica,
    report, codplanifnod,
    codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
    total, lastweek, totaldelansat, NextWeek, RefWeek,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
    obs1, obs2, obs3, obs4, obs5, obs6,
    codnorma, codextern, codintern,CODGEST)
  select
    CODLANSZ, CODLANSZ1, codformatie, schimb, codreteta, codobiect,
    luni, marti, miercuri, joi, vineri, sambata, duminica,
    report, codplanifnod,
    codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
    total, lastweek, totaldelansat, NextWeek, RefWeek,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
    obs1, obs2, obs3, obs4, obs5, obs6,
    codnorma, codextern, codintern,CODGEST
  from lansz1_manevra;
  commit;

  DELETE TMP_LANSZ1;
  INSERT INTO TMP_LANSZ1 (
    CODLANSZ, CODLANSZ1, codformatie, schimb, codreteta, codobiect,
    luni, marti, miercuri, joi, vineri, sambata, duminica,
    report, codplanifnod,
    codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
    total, lastweek, totaldelansat, NextWeek, RefWeek,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
    obs1, obs2, obs3, obs4, obs5, obs6,
    codnorma, codextern, codintern,CODGEST )

  SELECT
    CODLANSZ, CODLANSZ1, codformatie, schimb, codreteta, codobiect,
    luni, marti, miercuri, joi, vineri, sambata, duminica,
    report, codplanifnod,
    codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
    total, lastweek, totaldelansat, NextWeek, RefWeek,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
    obs1, obs2, obs3, obs4, obs5, obs6,
    codnorma, codextern, codintern,CODGEST
  FROM LANSZ1_MANEVRA
  WHERE USERID = VUSERID;

  commit;
end;

procedure CreazaLansZ1Man(ACODLANSZ IN NUMBER, ASAPTAMANA IN NUMBER, AAN IN NUMBER, ACODOBIECT IN NUMBER, ACODRETETA IN NUMBER, AUSERID IN NUMBER) is
aPrevSapt number(2);
aPrevAn   number(4);
aNextAn   number(4);
aNextSapt number(2);
aSubunit  number(20);
oData date;
begin
  oData := iso_week_to_date(aan, asaptamana);

  oData := oData - 7;
  aPrevSapt := to_number(to_char(odata,&apos;IW&apos;));
  aPrevAn   := to_number(to_char(odata,&apos;IYYY&apos;));

  oData := oData + 14;
  aNextSapt := to_number(to_char(odata,&apos;IW&apos;));
  aNextAn   := to_number(to_char(odata,&apos;IYYY&apos;));

  /*IF ASAPTAMANA = 1 THEN
    aPrevSapt := 53;
    aPrevAn := aAn - 1;
  ELSE
    aPrevSapt := aSaptamana - 1;
    aPrevAn := aAn;
  END IF;

  IF ASAPTAMANA = 53 THEN
    aNextSapt := 1;
    aNextAn := aAn + 1;
  ELSE
    aNextSapt := aSaptamana + 1;
    aNextAn := aAn;
  END IF;*/

  begin
    select subunitatea into aSubunit from lansz where codlansz = acodlansz;
  exception when others then
    aSubunit := pkg_globals.GETSUBUNITATE;
  end;

  DELETE TMP_PLANIFNODZ where userid = AUSERID;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, sum(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, sum(PNOD.NECESAR) REFWEEK, AUSERID USERID
         FROM PLANIFNOD PNOD
              INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
              INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
         WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
               PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
               PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
               PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
               nvl(PP.INSAPTAMANA,1) = 1 and
               PP.SUBUNITATEA = aSubunit AND
               PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
         GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, AUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
                nvl(PP.INSAPTAMANA,1) = 1 AND
                PP.SUBUNITATEA = aSubunit AND
                PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, AUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
                nvl(PP.INSAPTAMANA,1) = 1 AND
                PP.SUBUNITATEA = aSubunit AND
               PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
         SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, AUSERID USERID
          FROM PLANIFNOD PNOD
               INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
               INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
          WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
                PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
                PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
                PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
                nvl(PP.INSAPTAMANA,1) = 0 AND
                PP.SUBUNITATEA = aSubunit AND
                PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
          GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
        ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, AUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
  WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, 0 NEXTWEEK, SUM(PNOD.NECESAR) REFWEEK, AUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
  WHERE PP.An = aAn and PP.Saptamana = ASAPTAMANA and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, AUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
        PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, AUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  SELECT PNOD.CODRETETA CODRETETA, PNOD.CODOBIECT CODOBIECT, 0 NECESAR, SUM(PNOD.NECESAR) NEXTWEEK, 0 REFWEEK, AUSERID USERID
  FROM PLANIFNOD PNOD
       INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
       INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
  WHERE PP.An = aNextAn and PP.Saptamana = aNEXTSAPT and
        PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
        PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0 AND
        nvl(PP.INSAPTAMANA,1) = 0 AND
        PP.SUBUNITATEA = aSubunit AND
        PNOD.CODRETETA = ACODRETETA AND PNOD.CODOBIECT = ACODOBIECT
  GROUP BY PNOD.CODRETETA, PNOD.CODOBIECT
  ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  MERGE INTO TMP_PLANIFNODZ Z
  USING (
  select X.codreteta CODRETETA, X.codobiect CODOBIECT, 0 necesar, 0 nextweek, 0 REFWEEK, AUSERID USERID from
  (SELECT distinct L1.CODRETETA, L1.CODOBIECT
   from LANSZ1 L1
        inner join LANSZ l on l.codlansz = l1.codlansz
   where l.operat = 1 and l.anulat = 0 and l.blocat = 0
         and l.an = aprevan and l.saptamana = aprevsapt
         and l1.report &gt; 0 AND L.SUBUNITATEA = aSubunit
         AND L1.CODRETETA = ACODRETETA AND L1.CODOBIECT = ACODOBIECT
   ) X
   ) N
  ON (Z.CODOBIECT = N.CODOBIECT and Z.CODRETETA = N.CODRETETA AND Z.USERID = N.USERID)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, NECESAR, NEXTWEEK, REFWEEK, USERID)
                                VALUES
                               (N.CODRETETA, N.CODOBIECT, N.NECESAR, N.NEXTWEEK, N.REFWEEK, N.USERID)
  WHEN MATCHED THEN UPDATE SET Z.NECESAR = nvl(Z.NECESAR,0) + N.NECESAR,
                               Z.NEXTWEEK = NVL(Z.NEXTWEEK,0) + N.NEXTWEEK,
                               Z.REFWEEK = NVL(Z.REFWEEK,0) + N.REFWEEK;

  DELETE LANSZ1_MANEVRA WHERE USERID = AUSERID;
  INSERT INTO LANSZ1_MANEVRA (CODLANSZ, CODRETETA, CODOBIECT, TOTAL, NEXTWEEK, REFWEEK, USERID, Dirty)
  SELECT ACODLANSZ, PF.CODRETETA, PF.CODOBIECT, PF.NECESAR, PF.NextWeek, PF.REFWEEK, AUSERID, nvl(df.dirty,0)
  FROM TMP_PLANIFNODZ PF
       left join dflansz1 df on df.codlansz = acodlansz and df.codobiect = pf.codobiect and df.codreteta = pf.codreteta
                             and df.an = aan and df.saptamana = asaptamana

  WHERE PF.USERID = AUSERID;

  delete lansz1_manevra1 where userid = Auserid;
  insert into lansz1_manevra1(codobiect, codreteta, report, userid)
  select distinct l1.codobiect, l1.codreteta, l1.report, Auserid
  from lansz1 l1
       inner join lansz l on l1.codlansz = l.codlansz
  where l.operat = 1 and l.anulat = 0 and l.blocat = 0
        and l.an = aprevan and l.saptamana = aprevsapt
        and l1.codobiect = acodobiect and l1.codreteta = acodreteta
        and l1.report &gt; 0;

  UPDATE LANSZ1_manevra TMP
  SET
    LASTWEEK = (SELECT sum(l1.report)
                from lansz1_manevra1 L1
                where l1.codreteta = tmp.codreteta and l1.codobiect = tmp.codobiect and l1.userid = Auserid
                )
  where userid = Auserid;

  DELETE LANSZ1_MANEVRA1 where userid = Auserid;
  INSERT INTO LANSZ1_MANEVRA1(CODOBIECT, CODRETETA, TOTAL,USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.LUNI,0) + NVL(L1.MARTI,0) + NVL(L1.MIERCURI,0) + NVL(L1.JOI,0) + NVL(L1.VINERI,0) + NVL(L1.SAMBATA,0) + NVL(L1.DUMINICA,0)),
         AUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; ACODLANSZ AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE &gt; 0 AND L1.SCHIMB &gt; 0
        AND L.SUBUNITATEA = aSubunit and l1.codobiect = acodobiect and l1.codreteta = acodreteta
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE LANSZ1_MANEVRA TMP
  SET
    ALTE = (SELECT TOTAL
            FROM LANSZ1_MANEVRA1 L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA AND L1.USERID = AUSERID
           )
  WHERE USERID = AUSERID;

  DELETE LANSZ1_MANEVRA1 where userid = Auserid;
  INSERT INTO LANSZ1_MANEVRA1(CODOBIECT, CODRETETA, REPORT,USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.REPORT,0)),AUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; ACODLANSZ AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE = 0 AND L1.SCHIMB = 0
        AND L.SUBUNITATEA = aSubunit and l1.codobiect = acodobiect and l1.codreteta = acodreteta
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE LANSZ1_MANEVRA TMP
  SET
    REPORTALTE = (SELECT L1.REPORT
            FROM LANSZ1_MANEVRA1 L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA AND USERID = AUSERID
            )
  WHERE USERID = AUSERID;

  UPDATE LANSZ1_MANEVRA SET
  TOTALDELANSAT = nvl(TOTAL,0) + nvl(LASTWEEK,0) + nvl(NEXTWEEK,0)
  WHERE USERID = AUSERID;

  commit;
end;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCODGEST NUMBER(20);
aNRSCHIMBURI NUMBER;
CONTOR NUMBER;
aCODPLANIFPROD NUMBER(20);
aSAPTAMANA NUMBER(10); -- le folosesc pentru saptamana trecuta
aAN NUMBER(4);
aSubunit number(20);
aCount number(20);
Tmp number(20);
VUSERID NUMBER(20);
aAllGest number(1);
BEGIN
  VUSERID := PKG_GLOBALS.GETUSERID;

  select count(*) into aCount from user_triggers where status = &apos;DISABLED&apos;;
  if aCount &gt; 0 then
    execute immediate &apos;alter table planifnod enable all triggers&apos;;
    execute immediate &apos;alter table planifprod enable all triggers&apos;;
    execute immediate &apos;alter table lansz1 enable all triggers&apos;;
  end if;

  select count(*) into aCount from lansz1 where codlansz = recid and ((codformatie=0 and schimb &gt; 0)or(codformatie &gt; 0 and SCHIMB=0));
  if aCount &gt; 0 then
    DELETE FROM LANSZ1
    WHERE ((codformatie=0 and schimb &gt; 0)or(codformatie &gt; 0 and SCHIMB=0)) and codlansz = recid;
  end if;

  begin
    select subunitatea into aSubunit from lansz where codlansz = recid;
  exception when others then
    aSubunit := pkg_globals.GETSUBUNITATE;
  end;

  INSERT INTO TMP_LANSZ (CODLANSZ, CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, OBS,
                         DATASTART, DATASTOP, AN, LUNA, SAPTAMANA, Finalizat, ALLGEST)
  SELECT LZ.CODLANSZ, LZ.CODGEST, LZ.CODPLANIFPROD, LZ.SUBUNITATEA, LZ.OPERAT, LZ.ANULAT, LZ.BLOCAT, LZ.OBS,
         iso_week_to_date(lz.an, lz.saptamana),
         iso_week_to_date(lz.an, lz.saptamana) + 6,
         LZ.AN, LZ.LUNA, LZ.Saptamana, LZ.FINALIZAT, nvl(LZ.ALLGEST,0)
  FROM LANSZ LZ
  WHERE CODLANSZ = RECID;

  SELECT NVL(TMP.CODGEST,0), NVL(TMP.CODPLANIFPROD,0), NVL(TMP.SAPTAMANA,0), NVL(TMP.AN,0), tmp.allgest
  INTO ACODGEST, ACODPLANIFPROD, ASAPTAMANA, AAN, AALLGEST
  FROM TMP_LANSZ TMP;

  DELETE LANSZ1_MANEVRA WHERE USERID = VUSERID;
  insert into lansz1_manevra(CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
                              LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
                              CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
                              lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                              TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK, userid)
  select CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
         LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
         CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
         lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
         TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK, vuserid
  from lansz1 where codlansz = recid;

  insert into tmp_lansz1 (codlansz1, codlansz, codformatie, schimb, codreteta, codobiect,
                          luni, marti, miercuri, joi, vineri, sambata, duminica,
                          report, codplanifnod,
                          codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
                          total, lastweek, totaldelansat, nextweek, RefWeek, totallansat,
                          lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                          codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
                          obs1, obs2, obs3, obs4, obs5, obs6,
                          codnorma, codextern, codintern,CODGEST,dirty,dirtyini,isOK,codclasea,den_clasea)
  select l1.codlansz1, l1.codlansz, l1.codformatie, l1.schimb, l1.codreteta, l1.codobiect,
         l1.luni, l1.marti, l1.miercuri, l1.joi, l1.vineri, l1.sambata, l1.duminica,
         l1.report, l1.codplanifnod,
         l1.codcmd1_luni, l1.codcmd1_marti, l1.codcmd1_miercuri, l1.codcmd1_joi, l1.codcmd1_vineri, l1.codcmd1_sambata, l1.codcmd1_duminica,
         l1.total, l1.lastweek, l1.totaldelansat, l1.nextweek, l1.RefWeek, l1.totallansat,
         l1.lans_luni, l1.lans_marti, l1.lans_miercuri, l1.lans_joi, l1.lans_vineri, l1.lans_sambata, l1.lans_duminica,
         l1.codreteta, obj.denumire, clsp.den_claseprod, pc.obs, clss.den_claseas, gimp.den_gest,gret.den_gest,
         pc.obs1, pc.obs2, pc.obs3, pc.obs4, pc.obs5, pc.obs6,
         nor.codnorma, obj.codextern, obj.codintern,GRET.CODGEST, nvl(df.dirty,0), nvl(df.dirty,0),case when nvl(df.dirty,0) = 0 then 1 else 0 end,
         cls.codclasea, cls.den_clasea
  from lansz1_manevra l1
       inner join lansz l on l1.codlansz = l.codlansz
       inner join nartobj obj on l1.codobiect = obj.codobiect
       inner join prodcomp pc on pc.codprodcomp = l1.codreteta
       inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and nvl(pg.timpest,0) = 0
       inner JOIN NGEST GRET ON PG.CODGEST = GRET.CODGEST
       inner join nart art on obj.codarticol = art.codarticol
       LEFT JOIN NARTIMPLICITE AIMP ON ART.CODARTICOL = AIMP.CODARTICOL AND AIMP.CODSUBUNIT = aSubunit
       LEFT JOIN NGEST GIMP ON AIMP.GESTIMPLICITA = GIMP.CODGEST
       left join prodnorme nor on nor.codprodcomp = pc.codprodcomp and nor.implicit = 1
       left join nclaseprod clsp on clsp.codclaseprod = pc.codclasaprod
       left join nclasea cls on cls.codclasea = art.clasa
       left join nclaseas clss on clss.codclaseas = art.clasastatist
       left join dflansz1 df  on df.codobiect = l1.codobiect and df.codreteta = l1.codreteta and df.an = l.an and df.saptamana = l.saptamana and df.codlansz = l.codlansz
  where l1.codlansz = RecId and l1.userid = vuserid;

  DELETE LANSZ1_MANEVRA WHERE USERID = VUSERID;
  INSERT INTO LANSZ1_MANEVRA(CODOBIECT, CODRETETA, TOTAL, USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.LUNI,0) + NVL(L1.MARTI,0) + NVL(L1.MIERCURI,0) + NVL(L1.JOI,0) + NVL(L1.VINERI,0) + NVL(L1.SAMBATA,0) + NVL(L1.DUMINICA,0)),
         VUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; recid AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE &gt; 0 AND L1.SCHIMB &gt; 0
        AND L.SUBUNITATEA = aSubunit
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE TMP_LANSZ1 TMP
  SET
    ALTE = (SELECT TOTAL
            FROM LANSZ1_MANEVRA L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
                  AND USERID = VUSERID
           );

  DELETE LANSZ1_MANEVRA WHERE USERID = VUSERID;
  INSERT INTO LANSZ1_MANEVRA(CODOBIECT, CODRETETA, REPORT, USERID)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.REPORT,0)), VUSERID
  FROM LANSZ1 L1
       INNER JOIN LANSZ L ON L.CODLANSZ = L1.CODLANSZ
  WHERE L1.CODLANSZ &lt;&gt; recid AND L.OPERAT = 1 AND L.ANULAT = 0 AND L.BLOCAT = 0
        AND L.SAPTAMANA = ASAPTAMANA AND L.AN = AAN AND L1.CODFORMATIE = 0 AND L1.SCHIMB = 0
        AND L.SUBUNITATEA = aSubunit
  GROUP BY L1.CODOBIECT, L1.CODRETETA;

  UPDATE TMP_LANSZ1 TMP
  SET
    REPORTALTE = (SELECT L1.REPORT
            FROM LANSZ1_MANEVRA L1
            WHERE L1.CODOBIECT = TMP.CODOBIECT and L1.CODRETETA = TMP.CODRETETA
                  AND L1.USERID = VUSERID
            );

  UPDATE TMP_LANSZ1 TMP SET
  RESTDELANSAT = (select sum(nvl(T.TOTALDELANSAT,0) - nvl(T.TOTALLANSAT,0) - nvl(T.report,0) - nvl(T.alte,0) - nvl(T.Reportalte,0))
                  FROM TMP_LANSZ1 T
                  WHERE T.CODFORMATIE = 0 AND T.SCHIMB = 0
                        AND T.CODRETETA = TMP.CODRETETA AND T.CODOBIECT = TMP.CODOBIECT);

  INSERT INTO TMP_FORMATII_MAN(CODFORMATIE, DEN_FORMATIE, SIMBOL, CODGEST)
  SELECT F.CODFORMATIE, F.DEN_FORMATIE, F.SIMBOL, F.CODGEST
  FROM FORMATII F
       INNER JOIN TMP_LANSZ L ON NVL(L.CODGEST,0) = F.CODGEST
  union all
  SELECT F.CODFORMATIE, F.DEN_FORMATIE, F.SIMBOL, F.CODGEST
  FROM FORMATII F
  where nvl(f.codgest,0)=0;

  INSERT INTO TMP_SCHIMBURI_MAN (CODGEST, SCHIMBS, SCHIMB)
  VALUES (ACODGEST, 0, 0);
  BEGIN
    SELECT NVL(NRSCHIMBURI,0) INTO ANRSCHIMBURI FROM NGEST WHERE CODGEST = ACODGEST;
  EXCEPTION WHEN OTHERS THEN ANRSCHIMBURI := 0;
  END;

  FOR CONTOR IN 1..ANRSCHIMBURI LOOP
    INSERT INTO TMP_SCHIMBURI_MAN (CODGEST, SCHIMBS, SCHIMB)
    VALUES (ACODGEST, CONTOR, CONTOR);
  END LOOP;

  update tmp_lansz tmp
  set noi =
  (select count(*)
   from dflansz1 df1
        inner join prodgest pg on df1.codreteta = pg.codprodcomp and nvl(pg.timpest,0) = 0
   where not exists (
     select l1.codlansz, l1.codobiect, l1.codreteta
     from tmp_lansz1 l1
     where l1.codlansz = df1.codlansz and l1.codobiect = df1.codobiect and l1.codreteta = df1.codreteta)
     and codreteta &gt; 0 and codobiect &gt; 0
     and (aALLGEST = 1 or pg.codgest = acodgest)
     and df1.codlansz = tmp.codlansz
  );

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
aSetimana number(2);
aAn number(4);
DocFinalizat number(1);
OldFinalizat number(1);
aCount number(10);
aCodLansZ1 number(20);
aSubunit number(20);
BEGIN
  OldFinalizat := 0;
  if Operation = 0 then
    begin
    select nvl(Finalizat,0) into OldFinalizat from lansz where codlansz = RecId;
    exception when others then OldFinalizat := 0;
    end;
  end if;

  SELECT
    trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7,
    SAPTAMANA,
    saptamana,
    an,
    nvl(Finalizat,0),
    subunitatea
  INTO
    aDATADOC,
    ADOC,
    aSetimana,
    aAn,
    DocFinalizat,
    aSubunit
  FROM TMP_LANSZ;

  DELETE FROM TMP_LANSZ1
  WHERE (codformatie=0 and schimb &gt; 0)or(codformatie &gt; 0 and SCHIMB=0);
  delete tmp_lansz1 where codobiect is null;

  IF Operation = 0 THEN  -- UPDATE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSZ&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT CODLANSZ INTO RecId FROM TMP_LANSZ;

    UPDATE LANSZ
    SET ( CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, OBS, AN, LUNA, SAPTAMANA, FINALIZAT, ALLGEST)
    = ( SELECT CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, OBS, AN, LUNA, SAPTAMANA, FINALIZAT, ALLGEST FROM TMP_LANSZ )
    WHERE CodLANSZ = RecId;

    DELETE LANSZ1 L1 WHERE L1.CODLANSZ = RECID AND NOT EXISTS
    (SELECT TMP.CODLANSZ1 FROM TMP_LANSZ1 TMP WHERE TMP.CODLANSZ1 = L1.CODLANSZ1);
    FOR V_REC IN (SELECT *
                  FROM TMP_LANSZ1
                 ) LOOP
      IF V_REC.CODLANSZ1 &gt; 0 THEN
        UPDATE LANSZ1
        SET
          CODFORMATIE = V_REC.CODFORMATIE,
          SCHIMB      = V_REC.SCHIMB,
          CODRETETA   = V_REC.CODRETETA,
          CODOBIECT   = V_REC.CODOBIECT,
          LUNI        = V_REC.LUNI,
          MARTI       = V_REC.MARTI,
          MIERCURI    = V_REC.MIERCURI,
          JOI         = V_REC.JOI,
          VINERI      = V_REC.VINERI,
          SAMBATA     = V_REC.SAMBATA,
          DUMINICA    = V_REC.DUMINICA,
          CodPlanifNod= v_rec.CodPlanifNod,
          report    = V_REC.report,
          LANS_LUNI = V_REC.LANS_LUNI,
          LANS_MARTI = V_REC.LANS_MARTI,
          LANS_MIERCURI = V_REC.LANS_MIERCURI,
          LANS_JOI = V_REC.LANS_JOI,
          LANS_VINERI = V_REC.LANS_VINERI,
          LANS_SAMBATA = V_REC.LANS_SAMBATA,
          LANS_DUMINICA = V_REC.LANS_DUMINICA,
          CODCMD1_LUNI = V_REC.CODCMD1_LUNI,
          CODCMD1_MARTI = V_REC.CODCMD1_MARTI,
          CODCMD1_MIERCURI = V_REC.CODCMD1_MIERCURI,
          CODCMD1_JOI = V_REC.CODCMD1_JOI,
          CODCMD1_VINERI = V_REC.CODCMD1_VINERI,
          CODCMD1_SAMBATA = V_REC.CODCMD1_SAMBATA,
          CODCMD1_DUMINICA = V_REC.CODCMD1_DUMINICA,
          TOTAL       = V_REC.TOTAL,
          LASTWEEK    = V_REC.LASTWEEK,
          NEXTWEEK    = V_REC.NEXTWEEK,
          REFWEEK    = V_REC.REFWEEK,
          TOTALDELANSAT = V_REC.TOTALDELANSAT,
          TOTALLANSAT = V_REC.TOTALLANSAT
        WHERE CODLANSZ1 = V_REC.CODLANSZ1;
      ELSE
        INSERT INTO LANSZ1 (CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
                            LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
                            LANS_LUNI, LANS_MARTI, LANS_MIERCURI, LANS_JOI, LANS_VINERI, LANS_SAMBATA, LANS_DUMINICA,
                            CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
                            TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK)
        VALUES (SEQ_LANSZ1_CODLANSZ1.NEXTVAL, RECID, V_REC.CODFORMATIE, V_REC.SCHIMB, V_REC.CODRETETA, V_REC.CODOBIECT, v_rec.CodPlanifNod,
                V_REC.LUNI, V_REC.MARTI, V_REC.MIERCURI, V_REC.JOI, V_REC.VINERI, V_REC.SAMBATA, V_REC.DUMINICA, V_REC.report,
                V_REC.LANS_LUNI, V_REC.LANS_MARTI, V_REC.LANS_MIERCURI, V_REC.LANS_JOI, V_REC.LANS_VINERI, V_REC.LANS_SAMBATA, V_REC.LANS_DUMINICA,
                V_REC.CODCMD1_LUNI, V_REC.CODCMD1_MARTI, V_REC.CODCMD1_MIERCURI, V_REC.CODCMD1_JOI, V_REC.CODCMD1_VINERI, V_REC.CODCMD1_SAMBATA, V_REC.CODCMD1_DUMINICA,
                v_rec.TOTAL, v_rec.LASTWEEK, v_rec.Totaldelansat, v_rec.TOTALLANSAT, v_rec.NEXTWEEK, v_rec.Refweek);
      END IF;
      if v_rec.dirty = 0 and v_rec.dirtyini &gt; 0 and v_rec.codformatie = 0 and v_rec.schimb = 0 then
        update dflansz1 set dirty = dirty - v_rec.dirtyini
        where codlansz = recid and codobiect = v_rec.codobiect and codreteta = v_rec.codreteta and an = aan and saptamana = asetimana;
        delete dflansz1 where codlansz = recid and codobiect = v_rec.codobiect
                        and codreteta = v_rec.codreteta and an = aan
                        and saptamana = asetimana and dirty = 0;
      end if;
    END LOOP;
  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;LANSZ&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT SEQ_LANSZ_CODLANSZ.NextVal INTO RecId FROM DUAL;

    INSERT INTO LANSZ ( CODLANSZ, CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, USERID, DATACREARE, OBS, AN, LUNA, SAPTAMANA, FINALIZAT, ALLGEST )
              ( SELECT  RECID, CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, PKG_GLOBALS.USERID, SYSTIMESTAMP, OBS, AN, LUNA, SAPTAMANA,
                        FINALIZAT, ALLGEST
                FROM TMP_LANSZ);

    INSERT INTO LANSZ1 (CODLANSZ1,
                        CODLANSZ,
                        CODFORMATIE,
                        SCHIMB,
                        CODRETETA,
                        CODOBIECT,
                        CodPlanifNod,
                        LUNI,
                        MARTI,
                        MIERCURI,
                        JOI,
                        VINERI,
                        SAMBATA,
                        DUMINICA,
                        report,
                        LANS_LUNI,
                        LANS_MARTI,
                        LANS_MIERCURI,
                        LANS_JOI,
                        LANS_VINERI,
                        LANS_SAMBATA,
                        LANS_DUMINICA,
                        CODCMD1_LUNI,
                        CODCMD1_MARTI,
                        CODCMD1_MIERCURI,
                        CODCMD1_JOI,
                        CODCMD1_VINERI,
                        CODCMD1_SAMBATA,
                        CODCMD1_DUMINICA,
                        TOTAL,
                        LASTWEEK,
                        NEXTWEEK,
                        REFWEEK,
                        TOTALDELANSAT,
                        TOTALLANSAT
                       )
    SELECT SEQ_LANSZ1_CODLANSZ1.NEXTVAL,
           RECID,
           CODFORMATIE,
           SCHIMB,
           CODRETETA,
           CODOBIECT,
           CodPlanifNod,
           LUNI,
           MARTI,
           MIERCURI,
           JOI,
           VINERI,
           SAMBATA,
           DUMINICA,
           report,
           LANS_LUNI,
           LANS_MARTI,
           LANS_MIERCURI,
           LANS_JOI,
           LANS_VINERI,
           LANS_SAMBATA,
           LANS_DUMINICA,
           CODCMD1_LUNI,
           CODCMD1_MARTI,
           CODCMD1_MIERCURI,
           CODCMD1_JOI,
           CODCMD1_VINERI,
           CODCMD1_SAMBATA,
           CODCMD1_DUMINICA,
           TOTAL,
           LASTWEEK,
           NEXTWEEK,
           REFWEEK,
           TOTALDELANSAT,
           TOTALLANSAT
    FROM TMP_LANSZ1;
  END IF;

  if aSetimana = 53 then
    aSetimana := 1;
    aAn := aAn + 1;
  else
    aSetimana := aSetimana + 1;
  end if;

  if OldFinalizat = 0 and DocFinalizat = 1 then
    update lansz set dirty = 1 where codlansz = RecId;
    delete lansz1
    where nvl(luni,0) = 0 and nvl(marti,0) = 0 and nvl(miercuri,0) = 0 and nvl(joi,0) = 0 and nvl(vineri,0) = 0 and nvl(sambata,0) = 0 and nvl(duminica,0) = 0 and
          nvl(CODCMD1_luni,0) = 0 and nvl(CODCMD1_marti,0) = 0 and nvl(CODCMD1_miercuri,0) = 0 and nvl(CODCMD1_joi,0) = 0 and nvl(CODCMD1_vineri,0) = 0 and nvl(CODCMD1_sambata,0) = 0 and nvl(CODCMD1_duminica,0) = 0 and
          nvl(report,0) = 0 and nvl(totaldelansat,0) = 0 and codlansz = recid;
  end if;
  NotifyModif(Operation, RecId, &apos;LANSZ&apos;);
  COMMIT;
END;

PROCEDURE COMANDA1JOI(An number, Saptamana number) IS
vCodComanda1 number(20);
begin
  for v_rec in (with nrcmdint as (
                  select count(c1.codcomanda1) cate, c.schimb, c.codformatie, c1.codobiect, c1.codreteta, c.datadoc
                  from comanda1 c1
                       inner join comanda c on c.codcomanda = c1.codcomanda
                  where c.obs like &apos;Planificare saptamana :%&apos;
                       and c.datadoc = trunc(trunc(to_date(An,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7 + 4 - 1
                  group by c.schimb, c.codformatie, c1.codobiect, c1.codreteta, c.datadoc
                ),
                lansari as (
                  select l1.codlansz1, l.saptamana, l.an, l1.schimb, l1.codformatie, l1.codobiect, l1.codreteta
                  from lansz1 l1
                       inner join lansz l on l.codlansz = l1.codlansz
                  where nvl(l1.codcmd1_joi,0) = 0 and l1.joi &gt; 0 and l.saptamana = Saptamana and l.an = An
                )
                select lansari.codlansz1, lansari.saptamana, lansari.an, lansari.schimb, lansari.codformatie, lansari.codobiect, lansari.codreteta
                from
                  lansari
                  inner join nrcmdint on nrcmdint.schimb = lansari.schimb and
                                         nrcmdint.codformatie = lansari.codformatie and
                                         nrcmdint.codobiect = lansari.codobiect and
                                         nrcmdint.codreteta = lansari.codreteta and
                                         trunc(nrcmdint.datadoc) = trunc(trunc(to_date(An,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7 + 4 - 1
                where nrcmdint.cate = 1
               ) loop
    begin
      vCodComanda1 := 0;
      select c1.codcomanda1 into vCodComanda1
      from comanda1 c1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where c.obs like &apos;Planificare saptamana :&apos;||v_rec.Saptamana||&apos;%&apos; and
            c.schimb = v_rec.schimb and
            c.codformatie = v_rec.codformatie and
            c1.codobiect = v_rec.codobiect and
            c1.codreteta = v_rec.codreteta and
            trunc(c.datadoc) = trunc(trunc(to_date(v_rec.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (v_rec.Saptamana - 1) * 7 + 4 - 1;
    exception when others then
      vCodComanda1 := 0;
    end;
    if vCodComanda1 &gt; 0 then
      update lansz1 set codcmd1_joi = vCodComanda1 where codlansz1 = v_rec.codlansz1;
    end if;
  end loop;
  commit;
end;

procedure UpdateNoi(aCodLansz in number) is
aCodGest number(20);
aAllGest number(1);
begin
  select CodGest, nvl(AllGest,0) into aCodGest, aAllGest from lansz where codlansz = aCodLansZ;
  for v_rec in (
    select df1.codreteta, df1.codobiect
    from dflansz1 df1
         inner join prodgest pg on df1.codreteta = pg.codprodcomp and nvl(pg.timpest,0) = 0
    where not exists (
                      select l1.codlansz, l1.codobiect, l1.codreteta
                      from lansz1 l1
                      where l1.codlansz = acodlansz and l1.codlansz = df1.codlansz and l1.codobiect = df1.codobiect and l1.codreteta = df1.codreteta
                     )
      and df1.codreteta &gt; 0 and df1.codobiect &gt; 0
      and df1.codlansz = aCodLansZ
      and (aAllGest = 1 or pg.codgest = aCodGest)
      ) loop
    insert into lansz1 (codlansz1, codlansz, codformatie, schimb, codobiect, codreteta)
    SELECT seq_lansz1_codlansz1.nextval, ACODLANSZ, F.CODFORMATIE, S.SCHIMB, v_rec.codobiect, v_rec.codreteta
    FROM (SELECT CODFORMATIE FROM FORMATII
          WHERE CODGEST = ACODGEST
          UNION ALL
          SELECT CODFORMATIE FROM FORMATII
          WHERE NVL(CODGEST,0) = 0 AND CODFORMATIE &gt; 100
         ) F,
         (select level as schimb from dual connect by level &lt; (select nvl(nrschimburi,0) from ngest where codgest = ACODGEST) + 1) S;
    insert into lansz1 (codlansz1, codlansz, codformatie, schimb, codobiect, codreteta)
    values (seq_lansz1_codlansz1.nextval, ACODLANSZ, 0, 0, v_rec.codobiect, v_rec.codreteta);
  end loop;
  commit;
end;

procedure updateCmdZile is
begin
  for v_rec in (select codlansz from lansz where nvl(finalizat,0) = 0 and an = 2015) loop
    delete lansz1_manevra;
    insert into lansz1_manevra(CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
                                LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
                                CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
                                lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                                TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK)
    select CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
           LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
           CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
           lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
           TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK
    from lansz1 where codlansz = v_rec.codlansz;
    commit;

    update lansz1_manevra
    set lans_luni = null,
        lans_marti = null,
        lans_miercuri = null,
        lans_joi = null,
        lans_vineri = null,
        lans_sambata = null,
        lans_duminica = null;

    update lansz1_manevra l1
    set
      lans_luni = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_luni)
    where nvl(codcmd1_luni,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_marti = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_marti)
    where nvl(codcmd1_marti,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_miercuri = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_miercuri)
    where nvl(codcmd1_miercuri,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_joi = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_joi)
    where nvl(codcmd1_joi,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_vineri = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_vineri)
    where nvl(codcmd1_vineri,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_sambata = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_sambata)
    where nvl(codcmd1_sambata,0) &gt; 0;
    update lansz1_manevra l1
    set
      lans_duminica = (select nvl(c1.cantacceptat,0) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_duminica)
    where nvl(codcmd1_duminica,0) &gt; 0;

    update lansz1_manevra
    set lans_luni = null,
        lans_marti = null,
        lans_miercuri = null,
        lans_joi = null,
        lans_vineri = null,
        lans_sambata = null,
        lans_duminica = null,
        codcmd1_luni = null,
        codcmd1_marti = null,
        codcmd1_miercuri = null,
        codcmd1_joi = null,
        codcmd1_vineri = null,
        codcmd1_sambata = null,
        codcmd1_duminica = null
    where codformatie = 0 and schimb = 0;

  delete lansz1_manevra1;
  insert into lansz1_manevra1 (
    CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
    LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
    CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK)
  select
    CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
    LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
    CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
    lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
    TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK
  from lansz1_manevra;

    update lansz1_manevra l1 set
    lans_luni = (select sum(nvl(ll1.lans_luni,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_marti = (select sum(nvl(ll1.lans_marti,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_miercuri = (select sum(nvl(ll1.lans_miercuri,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_joi = (select sum(nvl(ll1.lans_joi,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_vineri = (select sum(nvl(ll1.lans_vineri,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_sambata = (select sum(nvl(ll1.lans_sambata,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    lans_duminica = (select sum(nvl(ll1.lans_duminica,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0)
    where l1.codformatie = 0 and l1.schimb = 0;

    update lansz1_manevra l1 set
    luni = (select sum(nvl(ll1.luni,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    marti = (select sum(nvl(ll1.marti,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    miercuri = (select sum(nvl(ll1.miercuri,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    joi = (select sum(nvl(ll1.joi,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    vineri = (select sum(nvl(ll1.vineri,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    sambata = (select sum(nvl(ll1.sambata,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0),
    duminica = (select sum(nvl(ll1.duminica,0)) from lansz1_manevra1 ll1 where l1.codobiect = ll1.codobiect and l1.codreteta = ll1.codreteta and ll1.codformatie &gt; 0 and ll1.schimb &gt; 0)
    where l1.codformatie = 0 and l1.schimb = 0;

    delete lansz1 where codlansz = v_rec.codlansz;
    insert into lansz1(CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
                                LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
                                CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
                                lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                                TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK)
    select CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
           LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
           CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
           lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
           TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK
    from lansz1_manevra;

    commit;
  end loop;
end;

procedure updateCmdZilePePL(aCodLansZ in number) is
aAn number(4);
aSaptamana number(2);
aPrevAn number(4);
aPrevSapt number(2);
asubunit number(20);
aObs varchar2(500);
aDataStart date;
aDataCmd date;
aCount number(10);
numar number(20);
aGest number(20);
begin
  select an, saptamana, subunitatea, codgest into aan, asaptamana, asubunit, aGest
  from lansz
  where codlansz = acodlansz;
  --prima data incerc sa gasesc comenzile rupte
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_luni
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_luni &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_luni = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_marti
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_marti &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_marti = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_miercuri
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_miercuri &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_miercuri = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_joi
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_joi &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_joi = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_vineri
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_vineri &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_vineri = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_sambata
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_sambata &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_sambata = null where codlansz1 = v_rec.codlansz1;
    end loop;
    for v_rec in (
      select l1.codlansz1
      from lansz1 l1
           inner join comanda1 c1 on c1.codcomanda1 = l1.codcmd1_duminica
           inner join comanda c on c.codcomanda = c1.codcomanda
      where l1.codcmd1_duminica &gt; 0 and c.anulat = 1 and l1.codlansz = aCodLansz
    ) loop
      update lansz1 set codcmd1_duminica = null where codlansz1 = v_rec.codlansz1;
    end loop;
    commit;
    for v_rec in (
      select l1.codcmd1_luni, l1.codcmd1_marti, l1.codcmd1_miercuri,l1.codcmd1_joi,l1.codcmd1_vineri,l1.codcmd1_sambata,c.datadoc,
             c.codcomanda,l1.codlansz1, c.nrdoc,c1.codcomanda1, o.denumire, to_char(c.datadoc,&apos;IW&apos;) saptamana, to_char(c.datadoc, &apos;DAY&apos;, &apos;NLS_DATE_LANGUAGE = ROMANIAN&apos;) zi, c1.cantacceptat, g.den_gest sectia, c.schimb, f.den_formatie,
             mat.cant, mat.rest
      from comanda c
           inner join comanda1 c1 on c1.codcomanda = c.codcomanda
           inner join nartobj o on o.codobiect = c1.codobiect
           inner join ngest g on c.codgest = g.codgest
           inner join formatii f on c.codformatie = f.codformatie
           inner join lansz1 l1 on l1.codobiect = c1.codobiect and l1.codformatie = c.codformatie and l1.schimb = c.schimb and c1.codreteta = l1.codreteta
           inner join lansz l on l.codlansz = l1.codlansz and l.codgest = c.codgest
           inner join cmdprodmat mat on mat.codcomanda1 = c1.codcomanda1 and mat.tip = 0
      where
          c.tipdoc = 53 and c.operat = 1 and c.anulat = 0 and to_char(c.datadoc,&apos;IW&apos;) = l.saptamana and extract(year from c.datadoc) = l.an and
          not exists (select l1.codcmd1_luni from lansz1 l1 where l1.codcmd1_luni = c1.codcomanda1
                      union all
                      select l1.codcmd1_marti from lansz1 l1 where l1.codcmd1_marti = c1.codcomanda1
                      union all
                      select l1.codcmd1_miercuri from lansz1 l1 where l1.codcmd1_miercuri = c1.codcomanda1
                      union all
                      select l1.codcmd1_joi from lansz1 l1 where l1.codcmd1_joi = c1.codcomanda1
                      union all
                      select l1.codcmd1_vineri from lansz1 l1 where l1.codcmd1_vineri = c1.codcomanda1
                      union all
                      select l1.codcmd1_sambata from lansz1 l1 where l1.codcmd1_sambata = c1.codcomanda1
                      union all
                      select l1.codcmd1_duminica from lansz1 l1 where l1.codcmd1_duminica = c1.codcomanda1
                     ) and
          c.obs like &apos;Planificare saptamana :%&apos; and l.an = aAn and l.CodGest = aGest and
          (l.saptamana = aSaptamana  /*or l.saptamana+1 = to_char(sysdate,&apos;IW&apos;) or l.saptamana+2 = to_char(sysdate,&apos;IW&apos;) or l.saptamana+3 = to_char(sysdate,&apos;IW&apos;)*/)
     ) loop
       if trim(to_char(v_rec.datadoc, &apos;DAY&apos;)) = &apos;MONDAY&apos; then
         if coalesce(v_Rec.Codcmd1_Luni,0) = 0 then
           update lansz1 set codcmd1_luni = v_rec.codcomanda1, luni = v_rec.cantacceptat, lans_luni = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs =substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
       if trim(to_char(v_Rec.datadoc, &apos;DAY&apos;)) = &apos;TUESDAY&apos; then
         if coalesce(v_Rec.Codcmd1_Marti,0) = 0 then
           update lansz1 set codcmd1_marti = v_rec.codcomanda1, marti = v_rec.cantacceptat, lans_marti = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
       if trim(to_char(v_Rec.datadoc, &apos;DAY&apos;)) = &apos;WEDNESDAY&apos; then
         if coalesce(v_Rec.Codcmd1_miercuri,0) = 0 then
           update lansz1 set codcmd1_miercuri = v_rec.codcomanda1, miercuri = v_rec.cantacceptat, lans_miercuri = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
       if trim(to_char(v_Rec.datadoc, &apos;DAY&apos;)) = &apos;THURSDAY&apos; then
         if coalesce(v_Rec.Codcmd1_joi,0) = 0 then
           update lansz1 set codcmd1_joi = v_rec.codcomanda1, joi = v_rec.cantacceptat, lans_joi = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
       if trim(to_char(v_rec.datadoc, &apos;DAY&apos;)) = &apos;FRIDAY&apos; then
         if coalesce(v_Rec.Codcmd1_vineri,0) = 0 then
           update lansz1 set codcmd1_vineri = v_rec.codcomanda1, vineri = v_rec.cantacceptat, lans_vineri = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
       if trim(to_char(v_rec.datadoc, &apos;DAY&apos;)) = &apos;SATURDAY&apos; then
         if coalesce(v_Rec.Codcmd1_sambata,0) = 0 then
           update lansz1 set codcmd1_sambata = v_rec.codcomanda1, sambata = v_rec.cantacceptat, lans_sambata = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
    end loop;

    insert into x(test) values (&apos;aramis&apos;);
    aDataStart := iso_week_to_date(aan, asaptamana);
    for v_l1 in (select codlansz1 from lansz1 where codlansz = acodlansz and codformatie &gt; 0 and schimb &gt; 0) loop
    -- luni
    aDataCmd := aDataStart;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.luni,0) = 0 and coalesce(l1.codcmd1_luni,0) = 0
            and not exists (select ll1.codcmd1_luni
                            from lansz1 ll1
                            where ll1.codcmd1_luni = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.luni,0) = 0 and coalesce(l1.codcmd1_luni,0) = 0
                          and not exists (select ll1.codcmd1_luni
                                          from lansz1 ll1
                                          where ll1.codcmd1_luni = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set luni = v_rec.cantacceptat, codcmd1_luni = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --marti
    aDataCmd := aDataStart + 1;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.marti,0) = 0 and coalesce(l1.codcmd1_marti,0) = 0
            and not exists (select ll1.codcmd1_marti
                            from lansz1 ll1
                            where ll1.codcmd1_marti = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.marti,0) = 0 and coalesce(l1.codcmd1_marti,0) = 0
                          and not exists (select ll1.codcmd1_marti
                                          from lansz1 ll1
                                          where ll1.codcmd1_marti = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set marti = v_rec.cantacceptat, codcmd1_marti = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --miercuri
    aDataCmd := aDataStart + 2;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.miercuri,0) = 0 and coalesce(l1.codcmd1_miercuri,0) = 0
            and not exists (select ll1.codcmd1_miercuri
                            from lansz1 ll1
                            where ll1.codcmd1_miercuri = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.miercuri,0) = 0 and coalesce(l1.codcmd1_miercuri,0) = 0
                          and not exists (select ll1.codcmd1_miercuri
                                          from lansz1 ll1
                                          where ll1.codcmd1_miercuri = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set miercuri = v_rec.cantacceptat, codcmd1_miercuri = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --joi
    aDataCmd := aDataStart + 3;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.joi,0) = 0 and coalesce(l1.codcmd1_joi,0) = 0
            and not exists (select ll1.codcmd1_joi
                            from lansz1 ll1
                            where ll1.codcmd1_joi = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.joi,0) = 0 and coalesce(l1.codcmd1_joi,0) = 0
                          and not exists (select ll1.codcmd1_joi
                                          from lansz1 ll1
                                          where ll1.codcmd1_joi = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set joi = v_rec.cantacceptat, codcmd1_joi = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --vineri
    aDataCmd := aDataStart + 4;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.vineri,0) = 0 and coalesce(l1.codcmd1_vineri,0) = 0
            and not exists (select ll1.codcmd1_vineri
                            from lansz1 ll1
                            where ll1.codcmd1_vineri = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.vineri,0) = 0 and coalesce(l1.codcmd1_vineri,0) = 0
                          and not exists (select ll1.codcmd1_vineri
                                          from lansz1 ll1
                                          where ll1.codcmd1_vineri = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set vineri = v_rec.cantacceptat, codcmd1_vineri = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --sambata
    aDataCmd := aDataStart + 5;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.sambata,0) = 0 and coalesce(l1.codcmd1_sambata,0) = 0
            and not exists (select ll1.codcmd1_sambata
                            from lansz1 ll1
                            where ll1.codcmd1_sambata = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.sambata,0) = 0 and coalesce(l1.codcmd1_sambata,0) = 0
                          and not exists (select ll1.codcmd1_sambata
                                          from lansz1 ll1
                                          where ll1.codcmd1_sambata = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set sambata = v_rec.cantacceptat, codcmd1_sambata = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    --duminica
    aDataCmd := aDataStart + 6;
    begin
      select count(l1.codlansz1) into aCount
      from lansz1 l1
           inner join lansz l on l.codlansz = l1.codlansz
           inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
           inner join prodnorme n on l1.codreteta = n.codprodcomp
           inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
      where coalesce(l1.duminica,0) = 0 and coalesce(l1.codcmd1_duminica,0) = 0
            and not exists (select ll1.codcmd1_duminica
                            from lansz1 ll1
                            where ll1.codcmd1_duminica = c1.codcomanda1)
            and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
            and l1.codlansz1 = v_l1.codlansz1;
    exception when others then aCount := 0;
    end;
    if aCount = 1 then
      for v_rec in (select c1.codcomanda1, c1.cantacceptat
                    from lansz1 l1
                         inner join lansz l on l.codlansz = l1.codlansz
                         inner join comanda1 c1 on l1.codobiect = c1.codobiect and l1.codreteta = c1.codreteta
                         inner join prodnorme n on l1.codreteta = n.codprodcomp
                         inner join comanda c on c.obs like &apos;Planificare saptamana :&apos;||to_char(l.saptamana)||&apos;; Norma : &apos;||n.norma||&apos;%&apos;
                                              and c.datadoc = aDataCmd and c1.codcomanda = c.codcomanda
                                              and l1.schimb = c.schimb and l1.codformatie = c.codformatie and c.codgest = l.codgest
                    where coalesce(l1.duminica,0) = 0 and coalesce(l1.codcmd1_duminica,0) = 0
                          and not exists (select ll1.codcmd1_duminica
                                          from lansz1 ll1
                                          where ll1.codcmd1_duminica = c1.codcomanda1)
                          and c.operat = 1 and c.anulat = 0 and c.inchisa = 0
                          and l1.codlansz1 = v_l1.codlansz1
                   ) loop
        update lansz1 set duminica = v_rec.cantacceptat, codcmd1_duminica = v_rec.codcomanda1 where codlansz1 = v_l1.codlansz1;
        insert into x(test) values (v_l1.codlansz1);
      end loop;
    end if;
    end loop;
  --apoi procedurile de refacere
  IF ASAPTAMANA = 1 THEN
    aPrevSapt := 53;
    aPrevAn := aAn - 1;
  ELSE
    aPrevSapt := aSaptamana - 1;
    aPrevAn := aAn;
  END IF;

  update lansz1 set lans_luni = null where nvl(codcmd1_luni,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_marti = null where nvl(codcmd1_marti,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_miercuri = null where nvl(codcmd1_miercuri,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_joi = null where nvl(codcmd1_joi,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_vineri = null where nvl(codcmd1_vineri,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_sambata = null where nvl(codcmd1_sambata,0) = 0 and codlansz = acodlansz;
  update lansz1 set lans_duminica = null where nvl(codcmd1_duminica,0) = 0 and codlansz = acodlansz;

  update lansz1 l1 set
    lans_luni = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_luni),
    lans_marti = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_marti),
    lans_miercuri = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_miercuri),
    lans_joi = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_joi),
    lans_vineri = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_vineri),
    lans_sambata = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_sambata),
    lans_duminica = (select sum(c1.cantacceptat) from comanda1 c1 where c1.codcomanda1 = l1.codcmd1_duminica)
  where l1.codlansz = aCodLansZ and l1.codformatie &gt; 0 and l1.schimb &gt; 0;

  update lansz1 ll1
  set
    luni = (select sum(nvl(l1.luni,0))
            from lansz1 l1
            where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
    lans_luni = (select sum(nvl(l1.lans_luni,0))
            from lansz1 l1
            where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set marti = (select sum(nvl(l1.marti,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_marti = (select sum(nvl(l1.lans_marti,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set miercuri = (select sum(nvl(l1.miercuri,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_miercuri = (select sum(nvl(l1.lans_miercuri,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set joi = (select sum(nvl(l1.joi,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_joi = (select sum(nvl(l1.lans_joi,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set vineri = (select sum(nvl(l1.vineri,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_vineri = (select sum(nvl(l1.lans_vineri,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set sambata = (select sum(nvl(l1.sambata,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_sambata = (select sum(nvl(l1.lans_sambata,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set duminica = (select sum(nvl(l1.duminica,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0),
      lans_duminica = (select sum(nvl(l1.lans_duminica,0))
              from lansz1 l1
              where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz and ll1.codformatie = 0 and ll1.schimb = 0;

  update lansz1 ll1
  set totallansat = (select sum(nvl(l1.luni,0)+nvl(l1.marti,0)+nvl(l1.miercuri,0)+nvl(l1.joi,0)+nvl(l1.vineri,0)+nvl(l1.sambata,0)+nvl(l1.duminica,0))
                     from lansz1 l1
                     where l1.codlansz = acodlansz and ll1.codobiect = l1.codobiect and l1.codreteta = ll1.codreteta and l1.codformatie &gt; 0 and l1.schimb &gt; 0)
  where ll1.codlansz = acodlansz;

  MERGE INTO planifstruct ps
  USING (
  SELECT distinct L1.CODRETETA, L1.CODOBIECT, aAn An, aSaptamana Saptamana
  from LANSZ1 L1
       inner join LANSZ l on l.codlansz = l1.codlansz
  where l.operat = 1 and l.anulat = 0 and l.blocat = 0
        and l.an = aprevan and l.saptamana = aprevsapt
        and l1.report &gt; 0 AND L.SUBUNITATEA = aSubunit
  ) N
  ON (ps.CODOBIECT = N.CODOBIECT and ps.CODRETETA = N.CODRETETA AND ps.an = n.an and ps.saptamana = n.saptamana)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, AN, SAPTAMANA)
  VALUES (N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);

  commit;
end;


procedure UpdatePLStructDinPlanif(aCodPlanifProd in number) is
aAn number(4);
aSaptamana number(2);
aInSapt number(1);
aPrevAn number(4);
aPrevSapt number(2);
asubunit number(20);
oData date;
begin
  select nvl(insaptamana,1), an, saptamana, subunitatea into aInSapt, aan, asaptamana, asubunit
  from planifprod
  where codplanifprod = acodplanifprod;

  IF ASAPTAMANA = 1 THEN
    aPrevSapt := 53;
    aPrevAn := aAn - 1;
  ELSE
    aPrevSapt := aSaptamana - 1;
    aPrevAn := aAn;
  END IF;

  oData := iso_week_to_date(aan, asaptamana);

  oData := oData - 7;
  aAn := to_number(to_char(odata,&apos;IYYY&apos;));
  aSaptamana   := to_number(to_char(odata,&apos;IW&apos;));

  if aInSapt &lt;&gt; 1 then
    if aSaptamana = 1 then
      aSaptamana := 53;
      aAn := aAn - 1;
    else
      aSaptamana := aSaptamana - 1;
    end if;
  end if;

  MERGE INTO planifstruct ps
  USING (
  select pn.codobiect codobiect, pn.codreteta codreteta, aAn an, aSaptamana Saptamana
  from planifnod pn
       inner join planifprod p on p.codplanifprod = pn.codplanifprod
  where pn.codplanifprod = aCodPlanifProd and pn.codreteta &gt; 0
  ) N
  ON (ps.CODOBIECT = N.CODOBIECT and ps.CODRETETA = N.CODRETETA AND ps.an = n.an and ps.saptamana = n.saptamana)
  WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, AN, SAPTAMANA)
  VALUES (N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);

  commit;
end;

procedure MAKE_LANS_TRIGG is
aCMD varchar2(32000);
begin
  execute immediate &apos;alter table planifnod disable all triggers&apos;;
  execute immediate &apos;alter table planifprod disable all triggers&apos;;
  execute immediate &apos;alter table lansz1 disable all triggers&apos;;

  updateCmdZile;
  delete dflansz1;
  delete planifstruct;

  for v_rec in (select codlansz, an, saptamana, codgest from lansz where nvl(finalizat,0) = 0 and an = 2015) loop
    delete lansz1 where (codformatie &gt; 0 and schimb = 0) or (codformatie = 0 and schimb &gt; 0) and codlansz = v_rec.codlansz;
    insert into x(test) values (&apos;curata planificari - formatii/schimb: &apos;||v_rec.codlansz);
    commit;
    delete lansz1_manevra;
    insert into lansz1_manevra(CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
                                LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
                                CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
                                lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                                TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK)
    select CODLANSZ1, CODLANSZ, CODFORMATIE, SCHIMB, CODRETETA, CODOBIECT, CodPlanifNod,
           LUNI, MARTI, MIERCURI, JOI, VINERI, SAMBATA, DUMINICA, report,
           CODCMD1_LUNI, CODCMD1_MARTI, CODCMD1_MIERCURI, CODCMD1_JOI, CODCMD1_VINERI, CODCMD1_SAMBATA, CODCMD1_DUMINICA,
           lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
           TOTAL, LASTWEEK, Totaldelansat, TOTALLANSAT, NEXTWEEK, REFWEEK
    from lansz1 where codlansz = v_rec.codlansz;

    MERGE INTO planifstruct ps
    USING (
    SELECT distinct l1.Codreteta codreteta, l1.CodObiect codobiect, v_rec.an An, v_rec.saptamana Saptamana
    from lansz1_manevra l1
    where l1.codlansz = v_rec.codlansz
    ) N
    ON (ps.CODOBIECT = N.CODOBIECT and ps.CODRETETA = N.CODRETETA AND ps.an = n.an and ps.saptamana = n.saptamana)
    WHEN NOT MATCHED THEN INSERT (CODRETETA, CODOBIECT, AN, SAPTAMANA)
    VALUES (N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
    insert into x(test) values (&apos;gen.structuri - cod planificare : &apos;||v_rec.codlansz);
    commit;

    for v_xxx in (select l1.codobiect, l1.codreteta, sum(nvl(l1.luni,0)+nvl(l1.marti,0)+nvl(l1.miercuri,0)+nvl(l1.joi,0)+nvl(l1.vineri,0)+nvl(l1.sambata,0)+nvl(l1.duminica,0)+
                         case when l1.CODCMD1_luni &lt; 0 then 0 else nvl(l1.CODCMD1_luni,0) end +
                         case when l1.CODCMD1_marti &lt; 0 then 0 else nvl(l1.CODCMD1_marti,0) end +
                         case when l1.CODCMD1_miercuri &lt; 0 then 0 else nvl(l1.CODCMD1_miercuri,0) end +
                         case when l1.CODCMD1_joi &lt; 0 then 0 else nvl(l1.CODCMD1_joi,0) end +
                         case when l1.CODCMD1_vineri &lt; 0 then 0 else nvl(l1.CODCMD1_vineri,0) end +
                         case when l1.CODCMD1_sambata &lt; 0 then 0 else nvl(l1.CODCMD1_sambata,0) end +
                         case when l1.CODCMD1_duminica &lt; 0 then 0 else nvl(l1.CODCMD1_duminica,0) end +
                         case when l1.report &lt; 0 then 0 else nvl(l1.report,0) end) cate
                  from lansz1_manevra l1
                       inner join prodgest pg on l1.codreteta = pg.codprodcomp and nvl(pg.timpest,0) = 0
                  where codlansz = v_rec.codlansz and pg.codgest &lt;&gt; v_rec.codgest
                  group by codobiect, codreteta ) loop
      if nvl(v_xxx.cate,0) = 0 then
        delete lansz1 where codlansz = v_rec.codlansz and codobiect = v_xxx.codobiect and codreteta = v_xxx.codreteta;
      end if;
    end loop;
    insert into x(test) values (&apos;curatare - cod planificare : &apos;||v_rec.codlansz);
    commit;
  end loop;

  commit;

  execute immediate &apos;alter table planifnod enable all triggers&apos;;
  execute immediate &apos;alter table planifprod enable all triggers&apos;;
  execute immediate &apos;alter table lansz1 enable all triggers&apos;;
  /*aCMD :=
  &apos;create or replace trigger trg_lansz1_update
     after update on lansz1
     for each row
   declare
     vCodFormatie number(20);
     vSchimb number(10);
     vAn number(4);
     vSetimana number(2);
     vCodObiect number(20);
     vCodReteta number(20);
     vNextSapt number(2);
     vNextAn number(4);
   begin
     vCodFormatie := :Old.CodFormatie;
     vSchimb := :Old.Schimb;
     if vCodFormatie &gt; 0 and vSchimb &gt; 0 then
       vCodObiect := :Old.Codobiect;
       vCodReteta := :Old.Codreteta;
       select l.An, l.Saptamana into vAn, vSetimana
       from lansz l
       where l.codlansz = :Old.CodLansz;

       IF vSetimana = 52 THEN
         vNextSapt := 1;
         vNextAn := vAn + 1;
       ELSE
         vNextSapt := vSetimana + 1;
         vNextAn := vAn;
       END IF;

       if :Old.Nextweek &lt;&gt; :New.Nextweek then
         MERGE INTO dflansz1 df
         USING (
         SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vNextAn An, vNextSapt Saptamana
         FROM lansz l
         where l.an = vnextan and l.saptamana = vnextsapt
         ) N
         ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
         WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
         VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
       end if;
     end if;
   end trg_lansz1;&apos;;
   execute immediate aCMD;

   aCMD := &apos;create or replace trigger trg_planifnod_delete
  after delete on planifnod
  for each row
declare
  vAn number(4);
  vSetimana number(2);
  vCodObiect number(20);
  vCodReteta number(20);
  vPrevSapt number(2);
  vPrevAn number(4);
  vInSaptamana number(1);
begin
  vCodObiect := :Old.Codobiect;
  vCodReteta := :Old.Codreteta;

  select p.an, p.saptamana, nvl(p.insaptamana,0) into vAn, vSetimana, vInSaptamana
  from planifprod p
  where p.codplanifprod = :Old.CodPlanifProd;

  IF vSetimana = 1 THEN
    vPrevSapt := 52;
    vPrevAn := vAn - 1;
  ELSE
    vPrevSapt := vSetimana - 1;
    vPrevAn := vAn;
  END IF;

  if vInSaptamana &gt; 0 then
    MERGE INTO dflansz1 df
    USING (
    SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vAn An, vSetimana Saptamana
    FROM lansz l
    where l.an = van and l.saptamana = vsetimana
    ) N
    ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
    WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
    VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
  else
    MERGE INTO dflansz1 df
    USING (
    SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vPrevAn An, vPrevSapt Saptamana
    FROM lansz l
    where l.an = vprevan and l.saptamana = vprevsapt
    ) N
    ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
    WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
    VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
  end if;
end trg_planifnod_delete;&apos;;
  execute immediate aCMD;

  aCMD := &apos;create or replace trigger trg_planifnod_insert
  after insert on planifnod
  for each row
declare
  vAn number(4);
  vSetimana number(2);
  vCodObiect number(20);
  vCodReteta number(20);
  vPrevSapt number(2);
  vPrevAn number(4);
  vInSaptamana number(1);
begin
  vCodObiect := :New.Codobiect;
  vCodReteta := :New.Codreteta;

  select p.an, p.saptamana, nvl(p.insaptamana,0) into vAn, vSetimana, vInSaptamana
  from planifprod p
  where p.codplanifprod = :New.CodPlanifProd;

  IF vSetimana = 1 THEN
    vPrevSapt := 52;
    vPrevAn := vAn - 1;
  ELSE
    vPrevSapt := vSetimana - 1;
    vPrevAn := vAn;
  END IF;

  if vInSaptamana &gt; 0 then
    MERGE INTO dflansz1 df
    USING (
    SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vAn An, vSetimana Saptamana
    FROM lansz l
    where l.an = van and l.saptamana = vsetimana
    ) N
    ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
    WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
    VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
  else
    MERGE INTO dflansz1 df
    USING (
    SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vPrevAn An, vPrevSapt Saptamana
    FROM lansz l
    where l.an = vprevan and l.saptamana = vprevsapt
    ) N
    ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
    WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
    VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
  end if;
end trg_planifnod_insert;&apos;;
  execute immediate aCMD;

  aCMD := &apos;create or replace trigger trg_planifnod_update
  after update on planifnod
  for each row
declare
  vAn number(4);
  vSetimana number(2);
  vCodObiect number(20);
  vCodReteta number(20);
  vPrevSapt number(2);
  vPrevAn number(4);
  vInSaptamana number(1);
begin
  if :Old.Cant &lt;&gt; :New.Cant then
    vCodObiect := :New.Codobiect;
    vCodReteta := :New.Codreteta;

    select p.an, p.saptamana, nvl(p.insaptamana,0) into vAn, vSetimana, vInSaptamana
    from planifprod p
    where p.codplanifprod = :Old.CodPlanifProd;

    IF vSetimana = 1 THEN
      vPrevSapt := 52;
      vPrevAn := vAn - 1;
    ELSE
      vPrevSapt := vSetimana - 1;
      vPrevAn := vAn;
    END IF;

    if vInSaptamana &gt; 0 then
      MERGE INTO dflansz1 df
      USING (
      SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vAn An, vSetimana Saptamana
      FROM lansz l
      where l.an = van and l.saptamana = vsetimana
      ) N
      ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
      WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
      VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
    else
      MERGE INTO dflansz1 df
      USING (
      SELECT l.codlansz codlansz, vCodreteta codreteta, vCodObiect codobiect, vPrevAn An, vPrevSapt Saptamana
      FROM lansz l
      where l.an = vprevan and l.saptamana = vprevsapt
      ) N
      ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
      WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
      VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
    end if;

    if :Old.CodObiect &lt;&gt; :New.CodObiect or :Old.CodReteta &lt;&gt; :New.CodReteta then
      if vInSaptamana &gt; 0 then
        MERGE INTO dflansz1 df
        USING (
        SELECT l.codlansz codlansz, :Old.CodReteta codreteta, :Old.CodObiect codobiect, vAn An, vSetimana Saptamana
        FROM lansz l
        where l.an = van and l.saptamana = vsetimana

        ) N
        ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
        WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
        VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
      else
        MERGE INTO dflansz1 df
        USING (
        SELECT l.codlansz codlansz, :Old.CodReteta codreteta, :Old.CodObiect codobiect, vPrevAn An, vPrevSapt Saptamana
        FROM lansz l
        where l.an = vprevan and l.saptamana = vprevsapt
        ) N
        ON (df.CODOBIECT = N.CODOBIECT and df.CODRETETA = N.CODRETETA AND df.codlansz = N.codlansz and df.an = n.an and df.saptamana = n.saptamana)
        WHEN NOT MATCHED THEN INSERT (CODLANSZ, CODRETETA, CODOBIECT, AN, SAPTAMANA)
        VALUES (N.CODLANSZ, N.CODRETETA, N.CODOBIECT, N.AN, N.SAPTAMANA);
      end if;
    end if;
  end if;
end trg_planifnod_update;&apos;;
  execute immediate aCMD;
  */
end;

procedure test(aCodLansZ in number) is
aAn number(4);
aSaptamana number(2);
aPrevAn number(4);
aPrevSapt number(2);
asubunit number(20);
aObs varchar2(500);
aDataStart date;
aDataCmd date;
aCount number(10);
numar number(20);
aGest number(20);
begin
  select an, saptamana, subunitatea, codgest into aan, asaptamana, asubunit, aGest
  from lansz
  where codlansz = acodlansz;

    for v_rec in (
      select l1.codcmd1_luni, l1.codcmd1_marti, l1.codcmd1_miercuri,l1.codcmd1_joi,l1.codcmd1_vineri,l1.codcmd1_sambata,c.datadoc,
             c.codcomanda,l1.codlansz1, c.nrdoc,c1.codcomanda1, o.denumire, to_char(c.datadoc,&apos;IW&apos;) saptamana, to_char(c.datadoc, &apos;DAY&apos;, &apos;NLS_DATE_LANGUAGE = ROMANIAN&apos;) zi, c1.cantacceptat, g.den_gest sectia, c.schimb, f.den_formatie,
             mat.cant, mat.rest
      from comanda c
           inner join comanda1 c1 on c1.codcomanda = c.codcomanda
           inner join nartobj o on o.codobiect = c1.codobiect
           inner join ngest g on c.codgest = g.codgest
           inner join formatii f on c.codformatie = f.codformatie
           inner join lansz1 l1 on l1.codobiect = c1.codobiect and l1.codformatie = c.codformatie and l1.schimb = c.schimb and c1.codreteta = l1.codreteta
           inner join lansz l on l.codlansz = l1.codlansz and l.codgest = c.codgest
           inner join cmdprodmat mat on mat.codcomanda1 = c1.codcomanda1 and mat.tip = 0
      where c.codcomanda = 2672928 and
          c.tipdoc = 53 and c.operat = 1 and c.anulat = 0 and to_char(c.datadoc,&apos;IW&apos;) = l.saptamana and extract(year from c.datadoc) = l.an and
          not exists (select l1.codcmd1_luni from lansz1 l1 where l1.codcmd1_luni = c1.codcomanda1
                      union all
                      select l1.codcmd1_marti from lansz1 l1 where l1.codcmd1_marti = c1.codcomanda1
                      union all
                      select l1.codcmd1_miercuri from lansz1 l1 where l1.codcmd1_miercuri = c1.codcomanda1
                      union all
                      select l1.codcmd1_joi from lansz1 l1 where l1.codcmd1_joi = c1.codcomanda1
                      union all
                      select l1.codcmd1_vineri from lansz1 l1 where l1.codcmd1_vineri = c1.codcomanda1
                      union all
                      select l1.codcmd1_sambata from lansz1 l1 where l1.codcmd1_sambata = c1.codcomanda1
                      union all
                      select l1.codcmd1_duminica from lansz1 l1 where l1.codcmd1_duminica = c1.codcomanda1
                     ) and
          c.obs like &apos;Planificare saptamana :%&apos; and l.an = aAn and l.CodGest = aGest and
          (l.saptamana = aSaptamana  /*or l.saptamana+1 = to_char(sysdate,&apos;IW&apos;) or l.saptamana+2 = to_char(sysdate,&apos;IW&apos;) or l.saptamana+3 = to_char(sysdate,&apos;IW&apos;)*/)
     ) loop
       if trim(to_char(v_Rec.datadoc, &apos;DAY&apos;, &apos;NLS_DATE_LANGUAGE = ROMANIAN&apos;)) = &apos;MAR?I&apos; then
         if coalesce(v_Rec.Codcmd1_Marti,0) = 0 then
           update lansz1 set codcmd1_marti = v_rec.codcomanda1, marti = v_rec.cantacceptat, lans_marti = v_rec.cantacceptat where codlansz1 = v_rec.codlansz1;
           update comanda set obs = substr(obs||&apos; - xx - Actualizare cmd1&apos;,1,299) where codcomanda = v_rec.codcomanda;
         else
           if v_rec.cant = v_rec.rest then
             update comanda set anulat = 1, obs = substr(obs||&apos; - xx - Anulat incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
           else
             if v_rec.rest &gt; 0 then
               numar := pkg_lansz.ActualizeazaLinieCmd1(v_rec.CodComanda1, v_rec.cant - v_rec.rest);
               update comanda set inchisa = 1, obs = substr(obs||&apos; - xx - Inchidere incoerente&apos;,1,299) where codcomanda = v_rec.codcomanda;
             else
               update comanda set obs = substr(obs||&apos; - xx - nu apare in planificare&apos;,1,299) where codcomanda = v_rec.codcomanda;
             end if;
           end if;
         end if;
       end if;
    end loop;

  commit;
end;

end PKG_LANSZ;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIMBA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>605923892DC3385E718A701677DA8E18B17A90DF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIMBA IS

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodLimba INTO Tmp FROM NLIMBA WHERE CodLimba = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NARTOBJTRAD WHERE CodLimba = RecId;
  DELETE FROM NLIMBA WHERE CodLimba = RecId;
  NotifyModif(2, RecId, &apos;NLIMBA&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NLIMBA FIELDS(CodLimba) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_NLIMBA (CodLimba, DenLimba, ExtLink)
  (SELECT CodLimba, DenLimba, ExtLink FROM NLIMBA WHERE CodLimba = RecId);

  INSERT INTO TMP_NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, Descriere, DENOBIECT)
  (
    SELECT 
      OT.CodObiectTrad, 
      OT.CodObiect, 
      OT.CodLimba, 
      OT.DenumireTrad, 
      OT.Avertizare, 
      OT.descriere, 
      O.DENUMIRE
    FROM 
      NARTOBJTRAD OT,
      NARTOBJ O
     WHERE 
       OT.CodLimba = RecID
       AND O.CODOBIECT = OT.CODOBIECT
  );

  INSERT INTO TMP_NATRTRAD (CodNatrTrad, CodAtribut, DenAtrib, CodValAtr, ValAtr, ValAtrTrad, MESAJINACTIV, MESAJINACTIVTrad, CODATRIB1TRAD)
  ( SELECT 0 , A.CodAtribut, 
            A.Denumire DenAtrib, 
            A1.CodValAtr, A1.Valoare ValAtr, A1T.DENUMIRE ValAtrTrad, A1.MESAJINACTIV, A1T.MESAJINACTIV MESAJINACTIVTrad,  
            A1T.CODATRIB1TRAD 
  FROM NATRIB A 
       Inner join NATRIB1 A1 on A1.CodAtribut = A.CodAtribut 
       Left join  NATRIB1TRAD A1T on A1T.CODVALATR = A1.CODVALATR AND A1T.CodLimba = RecId  
  );

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
BEGIN
  IF Operation = 0 THEN -- UPDATE
    SELECT CodLimba INTO RecId FROM TMP_NLIMBA;
    UPDATE NLIMBA
    SET (DenLimba, ExtLink) = (SELECT DenLimba, ExtLink FROM TMP_NLIMBA)
    WHERE CodLimba = RecId;
    DELETE FROM NARTOBJTRAD
    WHERE CodLimba = RecID AND CODOBIECTTRAD NOT IN (SELECT CODOBIECTTRAD FROM TMP_NARTOBJTRAD);
  ELSE  -- INSERT
    SELECT SEQ_NLIMBA_CODLIMBA.NextVal INTO RecId FROM DUAL;
    INSERT INTO NLIMBA (CodLimba, DenLimba, ExtLink)
    (SELECT RecId, DenLimba, ExtLink FROM TMP_NLIMBA);
  END IF;

	FOR v_rec IN (SELECT * FROM TMP_NARTOBJTRAD ORDER BY CodObiectTrad)
	LOOP
		IF v_Rec.CodObiectTrad &lt; 0 THEN
			INSERT INTO NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, descriere)
			VALUES (SEQ_NARTOBJTRAD_CodObiectTrad.NextVal ,v_rec.CodObiect, RecID, v_rec.DenumireTrad, v_rec.Avertizare, v_rec.descriere);
		ELSE
			UPDATE NARTOBJTRAD
			SET
				CodObiect    = v_rec.CodObiect,
				CodLimba     = RecID,
				DenumireTrad = v_rec.DenumireTrad,
				descriere    = v_rec.descriere,
				Avertizare   = v_rec.Avertizare  
			WHERE
				CodObiectTrad = v_rec.CodObiectTrad;
		END IF;
	END LOOP;

  MERGE INTO NATRIB1TRAD NA
      USING TMP_NatrTRAD TMP
      ON (TMP.CODATRIB1TRAD = NA.CODATRIB1TRAD)
  WHEN MATCHED THEN 
      UPDATE SET
	    	NA.DENUMIRE    = TMP.ValAtrTrad,
				NA.MESAJINACTIV  = TMP.MESAJINACTIVTrad
  WHEN NOT MATCHED THEN
      INSERT (CODATRIB1TRAD, CODVALATR, CODLIMBA, MESAJINACTIV, DENUMIRE) 
      VALUES (SEQ_NATRIB1TRAD_CODATRIB1TRAD.NextVal ,TMP.CodValAtr , RecID, TMP.MESAJINACTIVTrad, TMP.ValAtrTrad);

	
	NotifyModif(Operation, RecId, &apos;NLIMBA&apos;);
  COMMIT;
END;

PROCEDURE LOAD_OBJTRAD IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM TMP_OBJTRAD;
  INSERT INTO TMP_OBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad)
  (
    SELECT CodObiectTrad, CodObiect, CodLimba, DenumireTrad
    FROM NARTOBJTRAD
  );
  COMMIT;
END;

PROCEDURE SAVE_OBJTRAD IS
  lGotcha NUMBER(20);
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  UPDATE TMP_OBJTRAD SET CodObiectTrad = SEQ_NARTOBJTRAD_CODOBIECTTRAD.NextVal WHERE NVL(CodObiectTrad, 0) = 0;
  FOR v_rec IN (SELECT CodObiectTrad, CodObiect, CodLimba, DenumireTrad FROM TMP_OBJTRAD)
  LOOP
    SELECT COUNT(*) INTO lGotcha FROM NARTOBJTRAD
    WHERE CodLimba = v_rec.CodLimba AND CodObiect = v_rec.CodObiect;
    IF lGotcha &gt; 0 THEN -- UPDATE
      UPDATE NARTOBJTRAD SET DenumireTrad = v_rec.DenumireTrad
      WHERE CodObiect = v_rec.CodObiect AND CodLimba = v_rec.CodLimba;
    ELSE -- INSERT
      INSERT INTO NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad)
      VALUES (v_rec.CodObiectTrad, v_rec.CodObiect, v_rec.CodLimba, v_rec.DenumireTrad);
    END IF;  
  END LOOP;
  -- DELETE (CLEANUP)
  DELETE FROM NARTOBJTRAD WHERE CodObiectTrad NOT IN (SELECT CodObiectTrad FROM TMP_OBJTRAD);
  COMMIT;
END;

PROCEDURE TRADUCERE(aCodObiect IN NUMBER, aOverwrite IN NUMBER) IS
  lDenTrad VARCHAR2(200);
  lHasTrad NUMBER(20);
  lTooMany NUMBER(20);
  lCodArticol NUMBER(20);
BEGIN
  SELECT CodArticol INTO lCodArticol FROM NARTOBJ WHERE CodObiect = aCodObiect;
  FOR v_lang IN
    (SELECT CodLimba FROM NLIMBA WHERE CodLimba &gt; 0 AND ExtLink &lt;&gt; &apos;RO&apos;)
  LOOP
    BEGIN
      SELECT
        COUNT(*) INTO lTooMany
      FROM
        NARTOBJ O
        LEFT OUTER JOIN TMP_OBJTRAD T ON T.CodObiect = O.CodObiect
      WHERE
        (SELECT COUNT(*) FROM NATROBJ A WHERE A.CodObiect = O.CodObiect) = 0 AND
        O.CodArticol = lCodArticol AND
        T.CodLimba = v_lang.CodLimba;
      IF lTooMany = 1 THEN
        SELECT
          T.DenumireTrad INTO lDenTrad
        FROM
          NARTOBJ O
          LEFT OUTER JOIN TMP_OBJTRAD T ON T.CodObiect = O.CodObiect
        WHERE
          (SELECT COUNT(*) FROM NATROBJ A WHERE A.CodObiect = O.CodObiect) = 0 AND
          O.CodArticol = lCodArticol AND
          T.CodLimba = v_lang.CodLimba;
      ELSE
        RAISE NO_DATA_FOUND;
      END IF;
      EXCEPTION WHEN NO_DATA_FOUND THEN lDenTrad := NULL;
    END;
    IF lDenTrad IS NOT NULL THEN
      SELECT COUNT(*) INTO lHasTrad FROM TMP_OBJTRAD WHERE CodObiect = aCodObiect AND CodLimba = v_lang.CodLimba;
      IF lHasTrad = 0 THEN
        INSERT INTO TMP_OBJTRAD
          (CodObiect, CodLimba, DenumireTrad)
        VALUES
          (aCodObiect, v_lang.CodLimba, lDenTrad || &apos; &apos; || PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(aCodObiect));
      ELSE
        IF aOverwrite &gt; 0 THEN
          UPDATE TMP_OBJTRAD
          SET DenumireTrad = lDenTrad || &apos; &apos; || PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(aCodObiect)
          WHERE CodObiect = aCodObiect AND CodLimba = v_lang.CodLimba;
        END IF;
      END IF;
    END IF;  
  END LOOP; -- v_lang
  COMMIT;
END;


PROCEDURE REWRITE_OBJTRAD IS
  -- PROCEDURA SE EXECUTA DOAR MANUAL DIN COMMAND WINDOW
  aDenTrad VARCHAR2(200);
  aHasTrad NUMBER(20);
  aTooMany NUMBER(20);
  --PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SAVEPOINT REWRITEOBJTRAD;
  FOR v_obj IN
    (SELECT CodArticol, CodObiect FROM NARTOBJ WHERE NVL(TraducArtGeneric, 0) = 1)
  LOOP
    FOR v_lang IN
      (SELECT CodLimba FROM NLIMBA WHERE CodLimba &gt; 0 AND ExtLink &lt;&gt; &apos;RO&apos;)
    LOOP
      BEGIN
        SELECT
          COUNT(*) INTO aTooMany
        FROM
          NARTOBJ O
          LEFT OUTER JOIN NARTOBJTRAD T ON T.CodObiect = O.CodObiect
        WHERE
          (SELECT COUNT(*) FROM NATROBJ A WHERE A.CodObiect = O.CodObiect) = 0 AND
          O.CodArticol = v_obj.CodArticol AND
          T.CodLimba = v_lang.CodLimba;
        IF aTooMany = 1 THEN
          SELECT
            T.DenumireTrad INTO aDenTrad
          FROM
            NARTOBJ O
            LEFT OUTER JOIN NARTOBJTRAD T ON T.CodObiect = O.CodObiect
          WHERE
            (SELECT COUNT(*) FROM NATROBJ A WHERE A.CodObiect = O.CodObiect) = 0 AND
            O.CodArticol = v_obj.CodArticol AND
            T.CodLimba = v_lang.CodLimba;
        ELSE
          RAISE NO_DATA_FOUND;
        END IF;
        EXCEPTION WHEN NO_DATA_FOUND THEN aDenTrad := NULL;
      END;
      IF aDenTrad IS NOT NULL THEN
        SELECT COUNT(*) INTO aHasTrad FROM NARTOBJTRAD WHERE CodObiect = v_obj.CodObiect AND CodLimba = v_lang.CodLimba;
        IF aHasTrad &gt; 0 THEN
          UPDATE NARTOBJTRAD SET
            DenumireTrad = aDenTrad || &apos; &apos; || PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(v_obj.CodObiect)
          WHERE
            CodObiect = v_obj.CodObiect AND
            CodLimba = v_lang.CodLimba;
        ELSE
          INSERT INTO NARTOBJTRAD
            (CodObiectTrad, CodObiect, CodLimba, DenumireTrad)
          VALUES
            (SEQ_NARTOBJTRAD_CodObiectTrad.NextVal, v_obj.CodObiect, v_lang.CodLimba, aDenTrad || &apos; &apos; || PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(v_obj.CodObiect));
        END IF;
      END IF;  
    END LOOP; -- v_lang
  END LOOP; -- v_obj
  COMMIT;
  EXCEPTION WHEN OTHERS THEN ROLLBACK TO REWRITEOBJTRAD;
END;


end PKG_LIMBA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIMITACREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B9AA9BD8D073501372692E9336DABB2E398FA63</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_limitacredit IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodLimCredit INTO Tmp FROM NLimCredit WHERE CodLimCredit = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NLimCredit1 WHERE CodLimCredit = RecId;
	DELETE FROM NLimCredit WHERE CodLimCredit = RecId;
  NotifyModif(2, RecId, &apos;NLIMCREDIT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NLimCredit FIELDS(CodLimCredit) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master LimCredit
  INSERT INTO TMP_NLimCredit ( CodLimCredit, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea, Investitie)
  SELECT CodLimCredit, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea, Investitie
  FROM NLimCredit
  WHERE CodLimCredit = RecId ;


  INSERT INTO TMP_NLIMCREDIT1(CODLIMCREDIT1, CODLIMCREDIT, INDEXLOCAL, DATA, SUMA)
  SELECT 
    CODLIMCREDIT1, 
    CODLIMCREDIT, 
    INDEXLOCAL, 
    DATA, 
    SUMA 
  FROM 
    NLIMCREDIT1 
  WHERE 
    CodLimCredit = RecId ;
    
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodLimCredit INTO RecId FROM TMP_NLimCredit;

    UPDATE NLimCredit
    SET ( CodLimCredit, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea, Investitie) = (SELECT CodLimCredit, CodBanca, NrContr, DataContr, DataExp, Nvl(Moneda,0), Valoare, Subunitatea, Investitie FROM TMP_NLimCredit)
    WHERE CodLimCredit = RecId;

    DELETE FROM NLIMCREDIT1 WHERE CODLIMCREDIT = RECID 
    AND CODLIMCREDIT1 NOT IN (SELECT CODLIMCREDIT1 FROM TMP_NLIMCREDIT1);
    
    FOR V_REC IN (SELECT * FROM TMP_NLIMCREDIT1)
    LOOP
      IF V_REC.CODLIMCREDIT1 &lt; 0 THEN
        INSERT INTO NLIMCREDIT1(CODLIMCREDIT1, CODLIMCREDIT, INDEXLOCAL, DATA, SUMA)
        VALUES (SEQ_NLIMCREDIT1_CODLIMCREDIT1.NEXTVAL, RECID, V_REC.INDEXLOCAL, V_REC.DATA, V_REC.SUMA);
      ELSE
        UPDATE NLIMCREDIT1
        SET
          INDEXLOCAL = V_REC.INDEXLOCAL,
          DATA       = V_REC.DATA,
          SUMA       = V_REC.SUMA
        WHERE
          CODLIMCREDIT1 = V_REC.CODLIMCREDIT1;  
      END IF;    
    END LOOP;    

  ELSE  -- INSERT
-- Master LimCredit
    SELECT SEQ_NLimCredit_CodLimCredit.NextVal INTO RecId FROM DUAL;

    INSERT INTO NLimCredit (CodLimCredit, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea,Investitie,  USERID, DATACREARE)
    SELECT RecId, CodBanca, NrContr, DataContr, DataExp, Nvl(Moneda,0), Valoare, Subunitatea, Investitie, PKG_GLOBALS.USERID, SYSTIMESTAMP
    FROM TMP_NLimCredit ;
   INSERT INTO NLIMCREDIT1(CODLIMCREDIT1, CODLIMCREDIT, INDEXLOCAL, DATA, SUMA)
    SELECT SEQ_NLIMCREDIT1_CODLIMCREDIT1.NEXTVAL, RECID, INDEXLOCAL, DATA, SUMA FROM TMP_NLIMCREDIT1;
  END IF;
  NotifyModif(Operation, RecId, &apos;NLIMCREDIT&apos;);
  COMMIT;
END;

END PKG_LimitaCredit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_ALEGPERIOADA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4DEBB965011E662BDF12610C66E9F53FBDE4DE3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_ALEGPERIOADA IS

  gDataS   DATE;
  gDataF   DATE;
  gAnual   BOOLEAN;
  gOpt1    BOOLEAN;
  gOpt2    BOOLEAN;
  gOpt3    BOOLEAN;
  gOpt4    BOOLEAN;
  gDataRef VARCHAR2(10);
  gAllX    BOOLEAN;
  gCriteriu NUMBER(1);
  gSumarIncFact BOOLEAN;

PROCEDURE setParams(
  pDataS        IN VARCHAR2 DEFAULT NULL,
  pDataF        IN VARCHAR2 DEFAULT NULL,
  pAnual        IN NUMBER   DEFAULT 0,
  pOpt1         IN NUMBER   DEFAULT 0,
  pOpt2         IN NUMBER   DEFAULT 0,
  pOpt3         IN NUMBER   DEFAULT 0,
  pOpt4         IN NUMBER   DEFAULT 0,
  pCodJob1      IN NUMBER   DEFAULT 0,
  pDataRef      IN VARCHAR2 DEFAULT NULL,
  pAllX         IN NUMBER   DEFAULT 1,
  pCriteriu     IN NUMBER   DEFAULT 0,
  pSumarIncFact IN NUMBER   DEFAULT 0)
IS
  xLunaAnIni integer;
  xLunaAnFin integer;
BEGIN
  gDataS     := To_Date(pDataS,&apos;DD.MM.YYYY&apos;);
  gDataF     := To_Date(pDataF,&apos;DD.MM.YYYY&apos;);
  gDataRef   := pDataRef;
  xLunaAnIni := Extract(Year from gDataS)*12 + 1;
  xLunaAnFin := Extract(Year from gDataF)*12;

  if NVL(pCodJob1,0) &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCODJOB1,gDataS,gDataF,xLunaAnIni,xLunaAnFin);
    PKG_ORA_LISTS.SET_DATA_DINAMIC    (pCODJOB1,gDataRef);
  end if;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(gDataS,gDataF);

  gAnual        := Coalesce(pAnual,        0) = 1;
  gOpt1         := Coalesce(pOpt1,         0) = 1;
  gOpt2         := Coalesce(pOpt2,         0) = 1;
  gOpt3         := Coalesce(pOpt3,         0) = 1;
  gOpt4         := Coalesce(pOpt4,         0) = 1;
  gAllX         := Coalesce(pAllX,         1) = 1;
  gSumarIncFact := Coalesce(pSumarIncFact, 0) = 1;
  gCriteriu     := Coalesce(pCriteriu,     0);
END;

function GetSumarIncFact return number is
begin
  if gSumarIncFact
    then return 1;
    else return 0;
  end if;
end;

FUNCTION getCriteriu RETURN NUMBER IS
BEGIN
  RETURN gCriteriu;
END;

FUNCTION getDataS RETURN DATE IS
BEGIN
  RETURN gDataS;
END;

FUNCTION getDataF RETURN DATE IS
BEGIN
  RETURN gDataF;
END;

FUNCTION getPerioada RETURN VARCHAR2 IS
  vPerioada VARCHAR2(1000);
BEGIN
  IF    gDataS = gDataF
  THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(gDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(gDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(gDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  RETURN vPerioada;
END;


FUNCTION getDataRef RETURN DATE IS
BEGIN
  RETURN TO_DATE(gDataRef, &apos;DD.MM.YYYY&apos;);
END;

FUNCTION Anual RETURN BOOLEAN IS
BEGIN
  RETURN gAnual;
END;

FUNCTION optiunea1 RETURN BOOLEAN IS
BEGIN
  RETURN gOpt1;
END;

FUNCTION optiunea2 RETURN BOOLEAN IS
BEGIN
  RETURN gOpt2;
END;

FUNCTION optiunea3 RETURN BOOLEAN IS
BEGIN
  RETURN gOpt3;
END;

FUNCTION optiunea4 RETURN BOOLEAN IS
BEGIN
  RETURN gOpt4;
END;

FUNCTION AllX RETURN BOOLEAN IS
BEGIN
  RETURN gAllX;
END;

end PKG_LIST_ALEGPERIOADA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ACHIZFURNART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C102D324FD52E43F0D83BF9B281471A5C2C96E54</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_achizfurnart IS

  vALIni      PLS_INTEGER;
  vALFin      PLS_INTEGER;
  vAllFurn    BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  S     VARCHAR2(100);
  K     PLS_INTEGER   := 0;
  vAn   NUMBER(4);
  vLuna NUMBER(4);
BEGIN
  vALIni   := pkg_list_selectperioada.AnLunaIni;
  vALFin   := pkg_list_selectperioada.AnLunaFin;
  vAllFurn := pkg_list_selectperioada.AllX;

  DELETE tmp_dinamic_cols;
  FOR i IN vALIni..vALFin LOOP
    pkg_list_base_utils.ExtractAnLuna(i, vAn, vLuna);
    S := to_char(vLuna,&apos;fm00&apos;)||&apos;.&apos;||to_char(vAn,&apos;fm0000&apos;);
    K := K + 1;
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k,&apos;fm999&apos;), &apos;Cant.Achiz.&apos;           ||S, k);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Achiz.valut&apos;       ||S, k);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;AV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Achiz.&apos;            ||S, k);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;PV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Plati&apos;             ||S, k);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;XV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Achiz.(TVA excl.)&apos; ||S, k);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;NV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Achiz.(disc.incl.)&apos;||S, k);
  END LOOP;
  COMMIT;
END;

FUNCTION CAMPURI(pTIP VARCHAR2) RETURN VARCHAR2 IS
  S      VARCHAR2(25000);
  vCamp  VARCHAR2(200);
  K      PLS_INTEGER   := 0;

  PROCEDURE CompleteazaS(vAnLuna INTEGER, vLabel VARCHAR2) IS
  BEGIN
    IF pTIP = &apos;SELECT&apos; THEN
      IF vAnLuna = 0
      THEN vCamp := &apos;SUM(T.&apos;||SubStr(vLabel,3)||&apos;) &apos;;
      ELSE vCamp := &apos;SUM(CASE WHEN T.AL = &apos;||vAnLuna||&apos; THEN T.&apos;||vLabel||&apos; ELSE 0 END) &apos;;
      END IF;
    END IF;
    S := S ||&apos;,
    &apos;||vCamp||vLabel;
    IF vAnLuna &lt;&gt; 0 THEN S := S||To_Char(k); END IF;
  END;

BEGIN
  CompleteazaS(0,&apos;T_C&apos;);
  CompleteazaS(0,&apos;T_VV&apos;);
  CompleteazaS(0,&apos;T_AV&apos;);
  CompleteazaS(0,&apos;T_PV&apos;);
  CompleteazaS(0,&apos;T_XV&apos;);
  CompleteazaS(0,&apos;T_NV&apos;);
  FOR i IN vALIni..vALFin LOOP
    K := K + 1;
    CompleteazaS(i,&apos;C&apos;);
    CompleteazaS(i,&apos;VV&apos;);
    CompleteazaS(i,&apos;AV&apos;);
    CompleteazaS(i,&apos;PV&apos;);
    CompleteazaS(i,&apos;XV&apos;);
    CompleteazaS(i,&apos;NV&apos;);
  END LOOP;
  RETURN S;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
  sUpdate   VARCHAR2(30000);
  sWherePer VARCHAR2(100);
  sWhereAux VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;NPART NPART, NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NTARI TSOC, NARTOBJ NOBJ, NART NART, NCLASEP NCP, NCLASEA NCA&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEAS&apos;  , &apos;NCAS&apos;, &apos;NCAS.CODCLASEAS = NART.CLASASTATIST&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  IF vALIni = vALFin
  THEN sWherePer := &apos;= &apos;||vALFin;
  ELSE sWherePer := &apos;BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin;
  END IF;

  IF NOT vAllFurn THEN
    sWhereAux := sWhereAux||&apos;
        AND I.PARTENER IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(Furn, DenClasaC, Art, UM, DenClasaA, Moneda, SoldI, SoldF, X_JUDET, X_CODCLASAP &apos;||
              CAMPURI(&apos;INSERT&apos;)||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  DOC AS (
    SELECT codintr, al, sum(si) si, sum(VV) VV, sum(AV) AV, sum(PV) PV, sum(XV) XV, sum(NV) NV
    FROM (
      SELECT
        i.codintr, 0 AL,
        (OL.REST + CASE WHEN O.SEMNIFICATIE IN (110, 1353) THEN 0 ELSE OL.RESTTVA END) * DECODE(G.CURS,NULL,1,0,1,G.CURS) SI,
        0 VV, 0 AV, 0 PV, 0 XV, 0 NV
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF O   ON O.CODOBLIGPIF  = OL.CODOBLIGPIF
        INNER JOIN OBLIGPIF OS  ON OS.CODOBLIGPIF = Decode(O.SEMNIFICATIE,1353,O.CODOBLIGASOCIAT,O.CODOBLIGPIF)
        INNER JOIN GENERAL  G   ON G.CODGENERAL   = OS.CODGENERAL
        LEFT  JOIN DVI      DVI ON DVI.CODDVI     = G.CODDOC AND G.TIPDOC = 5
        LEFT  JOIN INTRARI  I   ON I.CODINTR      = Nvl(DVI.CODINTR, G.CODDOC) AND I.TIPDOC = G.TIPDOC
      WHERE (OL.AN*12+OL.LUNA) = &apos;||(vALIni - 1)||&apos;
        AND O.SEMNIFICATIE &lt;&gt; 110
        AND G.TIPDOC IN (1,3,4,5,9)
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
      UNION ALL
      SELECT
        i.codintr, (i.an *12 +i.luna) AL,
        0 SI, I.VALDOC VV, I.VALDOC * DECODE(I.CURS,NULL,1,0,1,I.CURS) AV, CASE WHEN I.TIPFACTURA = 7 THEN I.VALDOC * DECODE(I.CURS,NULL,1,0,1,I.CURS) ELSE 0 END PV,
        ( SELECT SUM(I1.CANT * I1.PU - DECODE(I.TIPDOC,3,I1.TVA,0)) FROM INTRARI1 I1 WHERE I1.CODINTR = I.CODINTR AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;S&apos;&apos;) ) * DECODE(I.CURS,NULL,1,0,1,I.CURS) XV,
        (I.VALDOC - I.TVADOC) * DECODE(I.CURS,NULL,1,0,1,I.CURS) NV
      FROM INTRARI I
      WHERE I.TIPDOC IN (1,3,4,5,9) AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND ( I.An * 12 + I.LUNA ) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri trezorerie
        i.codintr, t1.an * 12 + t1.luna AL,
        0 SI, 0 VV, 0 AV,
        (S.VALOARE + NVL(GS.TVA,0)) * Sign(o.valoare) * DECODE(GS.CURS,NULL,1,0,1,GS.CURS) PV,
        0 XV, 0 NV
      FROM TREZOR T
        INNER JOIN TREZOR1  T1  ON T1.CODTREZOR      = T.CODTREZOR
        INNER JOIN GENERAL  GS  ON GS.TIPDOC         = T.TIPDOC AND GS.CODDOC = T1.CODTREZOR1
        INNER JOIN OBLIGPIF OS  ON OS.CODGENERAL     = GS.CODGENERAL
        INNER JOIN STINGERE S   ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
        INNER JOIN OBLIGPIF OL  ON OL.CODOBLIGPIF    = S.CODSTINSPIF
        INNER JOIN OBLIGPIF O   ON O.CODOBLIGPIF     = Decode(OL.SEMNIFICATIE,1353,OL.CODOBLIGASOCIAT,OL.CODOBLIGPIF)
        INNER JOIN GENERAL  G   ON G.CODGENERAL      = O.CODGENERAL
        LEFT  JOIN DVI      DVI ON DVI.CODDVI        = G.CODDOC AND G.TIPDOC = 5
        LEFT  JOIN INTRARI  I   ON I.CODINTR         = Nvl(DVI.CODINTR, G.CODDOC) AND I.TIPDOC = G.TIPDOC
      WHERE G.TIPDOC IN (1,3,4,5,9)
        AND O.SEMNIFICATIE NOT IN (800, 801)
        AND T.TIPDOC IN (29,30,31,33)
        AND T.OPERAT = 1
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (t1.an * 12 + t1.luna) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri compensari
        i.codintr, c.an * 12 + c.luna AL,
        0 SI, 0 VV, 0 AV,
        (S.VALOARE + Decode(C.TipCompens,2,0,NVL(GS.TVA,0))) * Sign(o.valoare) * DECODE(G.CURS,NULL,1,0,1,G.CURS) PV,
        0 XV, 0 NV
      FROM COMPENS C
        INNER JOIN GENERAL  GS ON GS.CODDOC        = C.CODCOMPENS AND GS.TIPDOC = 28
        INNER JOIN OBLIGPIF OS ON OS.CODGENERAL    = GS.CODGENERAL
        INNER JOIN STINGERE S ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
        INNER JOIN OBLIGPIF OX ON OX.CODOBLIGPIF   = S.CODSTINSPIF
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF     = DECODE(OX.CODOBLIGASOCIAT,NULL,OX.CODOBLIGPIF,0,OX.CODOBLIGPIF,OX.CODOBLIGASOCIAT)
        INNER JOIN GENERAL  G ON G.CODGENERAL      = O.CODGENERAL AND G.TIPDOC IN (1,3,4,5,9)
        LEFT  JOIN DVI      DVI ON DVI.CODDVI      = G.CODDOC AND G.TIPDOC = 5
        LEFT  JOIN INTRARI  I ON I.CODINTR         = Nvl(DVI.CODINTR, G.CODDOC) AND I.TIPDOC = G.TIPDOC
      WHERE Nvl(C.TipCompens,0) IN (0,2)
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (c.an * 12 + c.luna) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri retur
        i.codintr, i2.an * 12 + i2.luna AL,
        0 SI, 0 VV, 0 AV,
        S.VALOARE * Sign(o.valoare) * DECODE(G.CURS,NULL,1,0,1,G.CURS) PV,
        0 XV, 0 NV
      FROM INTRARI I
        INNER JOIN GENERAL  G  ON I.CODINTR      = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN OBLIGPIF O  ON O.CODGENERAL   = G.CODGENERAL
        INNER JOIN STINGERE S  ON S.CODSTINSPIF  = O.CODOBLIGPIF
        INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
        INNER JOIN GENERAL  GS ON GS.CODGENERAL  = OS.CODGENERAL
        INNER JOIN INTRARI  I2 ON I2.CODINTR     = GS.CODDOC AND I2.TIPDOC = GS.TIPDOC
      WHERE I.TIPDOC IN (1,3,4,5,9)
        AND GS.SEMNIFICATIE IN (300)
        AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I2.ANULAT = 0 AND I2.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (i2.an * 12 + i2.luna) &apos;||sWherePer||&apos;
    )
    GROUP BY CODINTR, AL),
  TMP AS (
    SELECT
      I.PARTENER, Nvl(I.MONEDA,0) CODMONEDA, NVL(I1.CODOBIECT,0) CODOBIECT, DOC.AL,
      CASE
        WHEN DOC.AL = Nvl(I.AN * 12 + I.LUNA,-1) THEN i1.cant
        ELSE 0
      END  C,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.SI
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.SI / I.VALDOC * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END SI,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.VV
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.VV / I.VALDOC * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END VV,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.AV
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.AV / I.VALDOC * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END AV,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.PV
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.PV / I.VALDOC * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END PV,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.XV
        WHEN I.VALDOC - I.TVADOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.XV / (I.VALDOC - I.TVADOC) * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END XV,
      CASE
        WHEN I1.CODINTR1 IS NULL THEN DOC.NV
        WHEN I.VALDOC - I.TVADOC = 0 OR i1.addim = -100 OR COALESCE(i1.cant, 0) = 0 THEN 0
        ELSE DOC.NV / (I.VALDOC - I.TVADOC) * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (3) THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i1.cant
      END NV
    FROM doc
      INNER JOIN intrari  i  ON i.codintr  = doc.codintr
      LEFT  JOIN intrari1 i1 ON i1.codintr = i.codintr
    WHERE (i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) OR i1.codintr IS NULL)
  )

  SELECT
    NPART.DEN_PART Furn, NCP.DEN_CLASEP DenClasaC, NVL(NOBJ.DENUMIRE,NART.DEN_ARTICOL) Art, U.DEN_UM UM, NCA.DEN_CLASEA DenClasaA, M.SIMBOL Moneda,
    SUM(T.SI) SOLDI, SUM(T.SI + T.AV - T.PV) SOLDF, JSOC.Simbauto, NCP.CODCLASEP&apos;||CAMPURI(&apos;SELECT&apos;)||gUserAlias||&apos;
  FROM TMP T
    INNER JOIN NPART         ON NPART.CODPART   = T.PARTENER
    LEFt  JOIN NMONEDE  M    ON M.CODMONEDA     = T.CODMONEDA
    LEFT  JOIN NAGENDA  SSOC ON SSOC.CODPART    = NPART.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0
    LEFT  JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = NVL(SSOC.CODLOCALIT, 0)
    LEFT  JOIN NJUDET   JSOC ON JSOC.CODJUDET   = NVL(LSOC.CODJUDET, 0)
    LEFT  JOIN NTARI    TSOC ON TSOC.CODTARA    = NVL(LSOC.CODTARA, 0)
    LEFT  JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = T.CODOBIECT
    LEFT  JOIN NART          ON NART.CODARTICOL = NVL(NOBJ.CODARTICOL,0)
    LEFT  JOIN NUM      U    ON U.CODUM         = NART.UM
    LEFT  JOIN NCLASEP  NCP  ON NCP.CODCLASEP   = NPART.CODCLASA
    LEFT  JOIN NCLASEA  NCA  ON NCA.CODCLASEA   = NART.CLASA&apos;||
    gSuplJoins||&apos;
  GROUP BY NPART.DEN_PART, NCP.DEN_CLASEP, NOBJ.DENUMIRE, NART.DEN_ARTICOL, U.DEN_UM, NCA.DEN_CLASEA, M.SIMBOL, JSOC.Simbauto, NCP.CODCLASEP&apos;||gUserAlias;

  sUpdate :=&apos;
  MERGE INTO &apos;|| tmpName ||&apos; A
    USING (
      SELECT ROWID,
        Sum(T_C)  OVER (PARTITION BY Furn, Art) xS_C,
        Sum(T_AV) OVER (PARTITION BY Furn, Art) xS_AV,
        Sum(T_PV) OVER (PARTITION BY Furn, Art) xS_PV,
        Sum(T_XV) OVER (PARTITION BY Furn, Art) xS_XV,
        Sum(T_NV) OVER (PARTITION BY Furn, Art) xS_NV,
        CASE WHEN COUNT(DISTINCT Moneda) OVER (PARTITION BY Furn, Art) = 1 THEN Sum(T_VV) OVER (PARTITION BY Furn, Art) ELSE 0 END xS_VV
      FROM &apos;|| tmpName ||&apos;
    ) B ON (A.ROWID = B.ROWID)
  WHEN MATCHED THEN UPDATE SET A.S_C = B.xS_C, A.S_AV = B.xS_AV, A.S_PV = B.xS_PV, A.S_XV = B.xS_XV, A.S_NV = B.xS_NV, A.S_VV = B.xS_VV&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate         , aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_ACHIZFURNART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_AECUSTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BC62DD818BCC5839EE39A82D26B29523ACC74FE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_AECUSTC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sRest      VARCHAR2(10000);
  sCondRest  VARCHAR2(10000);

  FUNCTION CondPer (pAlias VARCHAR2) RETURN VARCHAR2 IS
    sResult VARCHAR2 (500);
  BEGIN
    CASE
      WHEN PKG_LIST_SELMOMENT.GetTip = 1 THEN sResult := pAlias||&apos;.AN*12+&apos;||pAlias||&apos;.LUNA &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU;
      WHEN PKG_LIST_SELMOMENT.GetTip = 2 THEN sResult := pAlias||&apos;.DATADOC &lt;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELMOMENT.GetDataRef,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      ELSE sResult := &apos;1 = 1 &apos;;
    END CASE;
    RETURN sResult;
  END;

BEGIN
  --pkg_globals.setdebugmode(TRUE);
  gSuplCols := &apos;iesiri i, iesiri1 i1, iesiri ae, iesiri1 ae1, npart p, nartobj o, nart art, num1 u, ioart ioa, ngest g&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;  ,&apos;PD&apos;   ,&apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,&apos;OEXT&apos; ,&apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,&apos;OATR&apos; ,&apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;     ,&apos;CCUST&apos;,&apos;CCUST.CODCONT = IOA1.CUSTODIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;     ,&apos;PROD&apos; ,&apos;PROD.CODPART = O.CODPRODUCATOR&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sRest      := &apos;(i1.cant+Coalesce(storn.cant,0)-Coalesce(fact.cant,0))&apos;;
  IF PKG_LIST_SELMOMENT.Extra1 THEN
    sCondRest := &apos;
    AND &apos;||sRest||&apos; &lt;&gt; 0&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, DOC, NRDOC, DATADOC, Part, Initializare,
    Art, UM, PU,
    CANT, REST,
    CANTL,
    IOArt, Gest, PInreg, PAchiz &apos;||gUserFields||&apos;)&apos;;

  sSelect :=&apos;
  WITH
    det AS (
      SELECT
        codies1,
        --codioart, gest,
        Max(codioart) codioart, Max(gest) gest,
        Sum(cant*pinreg) vinreg, Sum(cant*pachiz) vachiz, SUM(cant) cant
      FROM (
        SELECT
          i1.codies1, Coalesce(i1.CodIOArtCust,0) codioart, Coalesce(i1.gestact,0) gest,
          Coalesce(i1.pu,0) pinreg, Coalesce(i1.pucorelat,0) pachiz, i1.cant
        FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        WHERE &apos;||CondPer(&apos;i&apos;)||&apos; AND i.tipdoc = 20 AND i.custodie IN (1, 2) AND i.operat = 1 AND i.anulat = 0 AND i.initializari = 1
        UNION ALL
        SELECT
          l1.codies1, Coalesce(lv.codioart,ns.codioart,0) codioart, Coalesce(lv.gest,n.gest,0) gest,
          Coalesce(lv.pretinreg, ns.pret,0) pinreg, Coalesce(lv.pretachiz,ns.pret-ns.adaos,0) pachiz, l1.cant cant
        FROM iesiri i
          INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
          INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
          LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
          LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
          LEFT JOIN nir n ON n.codnir = ns.codnir
        WHERE &apos;||CondPer(&apos;i&apos;)||&apos; AND i.tipdoc = 20 AND i.custodie IN (1, 2) AND i.operat = 1 AND i.anulat = 0 AND Coalesce(i.initializari,0) = 0
      )
      --GROUP BY GROUPING SETS (codies1, (codies1, codioart, gest))
      GROUP BY codies1
    ),
    fact as (
      SELECT il.codlinieaviz, Coalesce(Sum(il.cant),0) cant
      FROM ieslink il
        INNER JOIN iesiri1 f1 ON f1.codies1 = il.codies1
        INNER JOIN iesiri f ON f.codies = f1.codies
      WHERE &apos;||CondPer(&apos;f&apos;)||&apos; AND f.operat = 1 AND f.anulat = 0
      GROUP BY il.codlinieaviz
    ),
    storn as (
      SELECT
        codies1storno,
        --codioart, gest,
        Max(codioart) codioart, Max(gest) gest,
        Sum(CASE WHEN cant = 0 THEN 0 WHEN cantfact = cant THEN 0 ELSE cantlivr*(cant-cantfact)/cant        END) cant,
        Sum(CASE WHEN cant = 0 THEN 0 WHEN cantfact = cant THEN 0 ELSE cantlivr*(cant-cantfact)/cant*pachiz END) vachiz
      FROM (
        SELECT
          Coalesce(NULLIf(s1.codies1storno,0), s1.codliniedocimp, 0) codies1storno,
          0 codnirstoc, Coalesce(s1.CodIOArtCust,0) codioart, Coalesce(s1.gestact,0) gest,
          Coalesce(s1.pu,0) pinreg, Coalesce(s1.pucorelat,0) pachiz, s1.cant,
          ( SELECT Coalesce(Sum(il.cant),0)
            FROM ieslink il INNER JOIN iesiri1 f1 ON f1.codies1 = il.codies1 INNER JOIN iesiri f ON f.codies = f1.codies
            WHERE &apos;||CondPer(&apos;f&apos;)||&apos; AND il.codlinieaviz = s1.codies1 AND f.tipdoc = 26
          ) cantfact,
          s1.cant cantlivr
        FROM iesiri1 s1 INNER JOIN iesiri s ON s.codies = s1.codies
        WHERE &apos;||CondPer(&apos;s&apos;)||&apos;
          AND s.tipdoc = 20
          AND CASE
                WHEN Coalesce(s1.codies1storno,0) &gt; 0 THEN s1.codies1storno
                WHEN Coalesce(s1.TipDocImp, 0) = 20   THEN Coalesce(s1.codliniedocimp,0)
                ELSE 0
              END &gt; 1
          AND s.operat = 1 AND s.anulat = 0
          AND Coalesce(s1.cant,0) &lt;&gt; 0
          AND s.initializari = 1
        UNION ALL
        SELECT
          Coalesce(NULLIf(s1.codies1storno,0), s1.codliniedocimp, 0) codies1storno,
          Coalesce(l1s.codnirstoc,0) codnirstoc, Coalesce(lv.codioart,ns.codioart,0) codioart, Coalesce(lv.gest,n.gest,0) gest,
          Coalesce(lv.pretinreg, ns.pret, 0) pinreg, Coalesce(lv.pretachiz, ns.pret - ns.adaos, 0) pachiz, s1.cant,
          ( SELECT Coalesce(Sum(il.cant),0)
            FROM ieslink il INNER JOIN iesiri1 f1 ON f1.codies1 = il.codies1 INNER JOIN iesiri f ON f.codies = f1.codies
            WHERE &apos;||CondPer(&apos;f&apos;)||&apos; AND il.codlinieaviz = s1.codies1 AND f.tipdoc = 26
          ) cantfact,
          l1s.cant cantlivr
        FROM iesiri1 s1
          INNER JOIN iesiri s ON s.codies = s1.codies
          INNER JOIN livr ls ON ls.codies = s.codies AND ls.tiplivr = s.tipdoc
          INNER JOIN livr1 l1s ON l1s.codlivr = ls.codlivr AND l1s.codies1 = s1.codies1
          LEFT JOIN livrval lv ON lv.codlivr1 = l1s.codlivr1
          LEFT JOIN nirstoc ns ON ns.codnirstoc = l1s.codnirstoc
          LEFT JOIN nir n ON n.codnir = ns.codnir
        WHERE &apos;||CondPer(&apos;s&apos;)||&apos;
          AND s.tipdoc = 20
          AND CASE
                WHEN Coalesce(s1.codies1storno,0) &gt; 0 THEN s1.codies1storno
                WHEN Coalesce(s1.TipDocImp, 0) = 20   THEN Coalesce(s1.codliniedocimp,0)
                ELSE 0
              END &gt; 1
          AND s.operat = 1 AND s.anulat = 0
          AND Coalesce(s1.cant,0) &lt;&gt; 0
          AND coalesce(s.initializari,0) = 0
      )
      WHERE cant &lt;&gt; cantfact
      --GROUP BY GROUPING SETS (codies1storno, (codies1storno, codioart, gest))
      GROUP BY codies1storno
    )
  SELECT
    i.Codies, i.tipdoc, i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc Doc, i.NrDoc, i.Datadoc, p.Den_Part, Decode(i.initializari,1,&apos;&apos;DA&apos;&apos;, &apos;&apos;NU&apos;&apos;) Initializare,
    o.denumire, u.den_um1 UM, i1.pu*u.paritate PU,
    i1.cant/u.paritate CANT, &apos;||sRest||&apos;/u.paritate REST,
    CASE
      WHEN ae1.codies IS NULL THEN 0
      ELSE Coalesce(aed.cant,ae1.cant,0)/u.paritate
    END CANTL,
    ioa.den_Ioart IOArt, g.den_gest Gest,
    Coalesce(aed.vinreg/aed.cant,i1.pu,0)*u.paritate PInreg, Coalesce(aed.vachiz/aed.cant,i1.pucorelat,0)*u.paritate PAchiz&apos;||gUserAlias||&apos;
  FROM iesiri ae
    INNER JOIN iesiri1 ae1  ON ae1.codies          = ae.codies
    LEFT JOIN det      aed  ON aed.codies1         = ae1.codies1 --AND aed.codioart IS NOT NULL AND aed.gest IS NOT NULL
    FULL JOIN storn    aes  ON aes.codies1storno   = ae1.codies1 --AND aes.codioart = aed.codioart AND aes.gest = aed.gest
    LEFT JOIN iesiri1  i1   ON i1.codies1          = Coalesce(aes.codies1storno, ae1.codies1, 0)
    LEFT JOIN iesiri   i    ON i.codies            = i1.codies
    LEFT JOIN fact          ON fact.codlinieaviz   = i1.codies1
    LEFT JOIN det           ON det.codies1         = i1.codies1 --AND det.codioart   IS NULL AND det.gest   IS NULL
    LEFT JOIN storn         ON storn.codies1storno = i1.codies1 --AND storn.codioart IS NULL AND storn.gest IS NULL
    LEFT JOIN npart    p    ON p.codpart           = i.partener
    LEFT JOIN nartobj  o    ON o.codobiect         = i1.codobiect
    LEFT JOIN num1     u    ON u.codum1            = i1.umsec
    LEFT JOIN nart     art  ON art.codarticol      = o.codarticol
    LEFT JOIN ioart    ioa  ON ioa.codioart        = COALESCE(aed.codioart, aes.codioart, i1.codioartcust, 0)
		LEFT JOIN ioart1   ioa1 ON ioa1.codioart       = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.alstart AND ioa1.alstop
    LEFT JOIN ngest    g    ON g.codgest           = COALESCE(aed.gest, aes.gest, i1.gestact,0) &apos;||
    gSuplJoins||&apos;
  WHERE &apos;||CondPer(&apos;i&apos;)||&apos;
    AND i.tipdoc = 20 AND i.custodie IN (1, 2) AND i.operat = 1 AND i.anulat = 0
    AND Coalesce(i1.codies1storno,0) = 0 AND i1.Cant &lt;&gt; 0
    AND NOT ( Coalesce(i1.codliniedocimp,i1.codies1storno,0) &lt;&gt; 0 AND i1.Cant &lt; 0 )
    AND NOT (aes.codies1storno IS NOT NULL AND aes.codioart IS NULL) &apos;||
    sCondRest;

  PRC_AL_CHECK(&apos;IOART1&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_AECUSTC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_AECUSTF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FCA1E553D380561F2FB692F6C0ABAD5413B74EA9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_AECUSTF IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(20000);
  sRest     VARCHAR2(10000);
  sFactJoin VARCHAR2(10000);
  vALMin    NUMBER(5);

  FUNCTION CondPer (pAlias VARCHAR2, pPrefix VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
    sResult VARCHAR2 (500);
  BEGIN
    CASE
      WHEN PKG_LIST_SELMOMENT.GetTip = 1 THEN sResult := pPrefix||pAlias||&apos;.AN*12+&apos;||pAlias||&apos;.LUNA &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU;
      WHEN PKG_LIST_SELMOMENT.GetTip = 2 THEN sResult := pPrefix||pAlias||&apos;.DATADOC &lt;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELMOMENT.GetDataRef,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      ELSE sResult := pPrefix||&apos; 1 = 1 &apos;;
    END CASE;
    RETURN sResult;
  END;

BEGIN
  gSuplCols := &apos;intrari i, intrari1 i1&apos;;
  gSuplCols := gSuplCols||&apos;, npart p, nartobj o, nart art, num1 u, ioart ioa, ngest g&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;  ,&apos;PD&apos;   ,&apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,&apos;OEXT&apos; ,&apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,&apos;OATR&apos; ,&apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;     ,&apos;CCUST&apos;,&apos;CCUST.CODCONT = IOA1.CUSTODIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;     ,&apos;PROD&apos; ,&apos;PROD.CODPART = O.CODPRODUCATOR&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  SELECT AnInitial*12+LunaInitiala INTO vALMin FROM FirmaLuni;

  sRest := &apos;(i1.cant+Nvl(storn.cant,0)-Nvl(fact.cant,0)-Nvl(ret.cant,0))&apos;;

  sFactJoin := &apos;
    LEFT JOIN (
      SELECT il.codlinieaviz, Nvl(Sum(il.cant),0) cant
      FROM intrlink il
        INNER JOIN intrari1 f1 ON f1.codintr1 = il.codintr1
        INNER JOIN intrari  f  ON f.codintr   = f1.codintr
      WHERE &apos;||CondPer(&apos;f&apos;)||&apos;
        AND f.operat = 1 AND f.anulat = 0
      GROUP BY il.codlinieaviz
    ) fact ON fact.codlinieaviz = i1.codintr1
    LEFT JOIN (
      SELECT s1.codintr1storno codintr1storno, Nvl(Sum(s1.cant),0) cant
      FROM intrari1 s1 INNER JOIN intrari s ON s.codintr = s1.codintr
      WHERE &apos;||CondPer(&apos;s&apos;)||&apos;
        AND Nvl(s1.codintr1storno,0) &gt; 0
        AND s.operat = 1 AND s.anulat = 0
      GROUP BY s1.codintr1storno
    ) storn ON storn.codintr1storno = i1.codintr1
    LEFT JOIN (
      SELECT r1.codliniedocimp codintr1retur, Nvl(Sum(r1.cant),0) cant
      FROM iesiri1 r1 INNER JOIN iesiri r ON r.codies = r1.codies
      WHERE &apos;||CondPer(&apos;r&apos;)||&apos;
        AND Nvl(r1.codliniedocimp,0) &gt; 0
        AND Nvl(r1.tipdocimp,0) = 2
        AND r.operat = 1 AND r.anulat = 0
      GROUP BY r1.codliniedocimp
    ) ret ON ret.codintr1retur = i1.codintr1&apos;;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, DOC, NRDOC, DATADOC, Part, Initializare,
    Art, UM, PU, CANT, REST, CANTL, 
    IOArt, Gest, PInreg, PAchiz &apos;||gUserFields||&apos;)&apos;;

  sSelect :=&apos;
  SELECT
    i.Codintr, i.tipdoc, i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc Doc, i.NrDoc, i.Datadoc, p.Den_Part, Decode(i.initializari,1,&apos;&apos;DA&apos;&apos;, &apos;&apos;NU&apos;&apos;) Initializare,
    o.denumire, u.den_um1 UM, i1.pu*u.paritate PU, i1.cant/u.paritate CANT, &apos;||sRest||&apos;/u.paritate REST, Nvl(det.cant,i1.cant)/u.paritate CANTL, 
    ioa.den_Ioart IOArt, g.den_gest Gest, Nvl(det.pinreg, i1.pu)* u.paritate PInreg, Nvl(det.pachiz, i1.pretorig)* u.paritate PAchiz&apos;||gUserAlias||&apos;
  FROM intrari i
    INNER JOIN intrari1 i1  ON i1.codintr     = i.codintr
    INNER JOIN npart    p   ON p.codpart      = i.partener
    INNER JOIN nartobj  o   ON o.codobiect    = i1.codobiect
    INNER JOIN num1     u   ON u.codum1       = i1.umsec
    INNER JOIN nart     art ON art.codarticol = o.codarticol
    LEFT JOIN (
      SELECT ns.codintr1, ns.cantnir cant, ns.codioart, nir.gest, ns.pret pinreg, ns.pret - ns.adaos pachiz
      FROM nir INNER JOIN nirstoc ns ON ns.codnir = nir.codnir
      WHERE nir.tipnir = 2
    ) det ON det.codintr1 = i1.codintr1 &apos;||
    sFactJoin||&apos;
    LEFT JOIN ioart  ioa   ON ioa.codioart = det.codioart
    LEFT JOIN ioart1 ioa1 ON ioa1.codioart = ioa.codioart AND Greatest(&apos;||vALMin||&apos;,i.an*12+i.luna) between ioa1.alstart and ioa1.alstop
    LEFT JOIN ngest  g    ON g.codgest     = COALESCE(det.gest, i1.gestact,0)&apos;||
    gSuplJoins||&apos;
  WHERE i.tipdoc = 2 AND (i.custodie = 1 or i1.custodie = 1) AND i.operat = 1 AND i.anulat = 0 &apos;||CondPer(&apos;i&apos;,&apos;
    AND &apos;)||&apos;
    AND NVL(i1.codintr1storno,0) = 0 AND i1.Cant &gt; 0 AND &apos;||sRest||&apos; &lt;&gt; 0 &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_AECUSTF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_AJDEPCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B230EB741B2D217CC8397EB693F3C0C929AEA3C9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_AJDEPCLI is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  sConv       VARCHAR2(100);
  pRegProviz  VARCHAR2(1);

FUNCTION  CalcAdaosDoc( pCodDoc IN NUMBER,
                        pRest   IN NUMBER)
          RETURN NUMBER
IS
  vTipDoc NUMBER;
  vValDoc NUMBER;
  vAdaos  NUMBER;
  vCurs   NUMBER;
BEGIN
  IF Coalesce(pRest,0) = 0 THEN
    RETURN 0;
  END IF;

  SELECT tipdoc,  valdoc,  Coalesce(NULLIF(curs,0),1)
  INTO   vTipDoc, vValDoc, vCurs
  FROM   iesiri i
  WHERE  i.codies = pCodDoc;

  IF vTipDoc IS NULL THEN
    RETURN 0;
  ELSIF vTipDoc = 26 THEN
    SELECT SUM( ( i1.pretorig * Coalesce(i1.coefdiscmaj,1) * vCurs - CASE WHEN lv.codlivrval IS NULL THEN ns.pret - ns.adaos ELSE lv.pretachiz END ) * l1.cant * i1.cant / a1.cant )
    INTO vAdaos
    FROM iesiri1 i1
      INNER JOIN ieslink il ON il.codies1    = i1.codies1
      INNER JOIN iesiri1 a1 ON a1.codies1    = il.codlinieaviz
      INNER JOIN livr    l  on l.codies      = a1.codies
      INNER JOIN livr1   l1 on l1.codies1    = a1.codies1 AND l1.codlivr = l.codlivr
      LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv on lv.codlivr1   = l1.codlivr1
    WHERE i1.codies = pCodDoc AND i1.tiplinie = &apos;=&apos;;
  ELSE
    SELECT
      SUM( ( i1.pretorig * Coalesce(i1.coefdiscmaj,1) * vCurs - CASE WHEN lv.codlivrval IS NULL THEN ns.pret - ns.adaos ELSE lv.pretachiz END -
             (CASE
                WHEN vTipDoc IN (16,21) THEN Coalesce(i1.tva,0) * CASE WHEN i1.pu = 0 THEN 1 ELSE i1.pretorig/i1.pu END * Coalesce(i1.coefdiscmaj,1) * vCurs / i1.cant
                ELSE 0
              END ) ) * l1.cant )
    INTO vAdaos
    FROM iesiri1 i1
      INNER JOIN livr    l  on l.codies      = i1.codies
      INNER JOIN livr1   l1 on l1.codies1    = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv on lv.codlivr1   = l1.codlivr1
    WHERE i1.codies = pCodDoc AND i1.tiplinie = &apos;=&apos;;

  END IF;

  IF Coalesce(vValDoc,0) IN (0,1)
  THEN vAdaos := Coalesce(vAdaos,0) * pRest;
  ELSE vAdaos := Coalesce(vAdaos,0) * (pRest/vValDoc);
  END IF;

  RETURN vAdaos;
END;

PROCEDURE UMPLETMP(aLISTID IN NUMBER DEFAULT 0) IS
  sInsTMP        CLOB;
  sSelTMP        CLOB;
  sAuxCLit       CLOB;
  sAuxJLit       CLOB;
  sJoinFiltru    CLOB         := PKG_LIST_BASE_SCADENTARCL.GetJoinFiltru;
  dDataRef       DATE         := PKG_LIST_SELECTSCADENTAR.DataRef;
  dDataNVL       DATE         := LAST_DAY(ADD_MONTHS(dDataRef,-1));
  sDataRef       VARCHAR2(10) := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);
  sDataNVL       VARCHAR2(10) := To_Char(dDataNVL, &apos;dd.mm.yyyy&apos;);
  sZilePlusDoc   VARCHAR2(100):= &apos;(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) - Coalesce(D.DATADOC,TO_DATE(&apos;&apos;&apos;||sDataNVL||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))&apos;;
  sZilePlusTerm  VARCHAR2(100);
  sFiltruLuna    VARCHAR2(200);
  sAnP           NUMBER(4);
  sLunaP         NUMBER(2);
  sAnC           NUMBER(4);
  sLunaC         NUMBER(2);
BEGIN
--pkg_globals.setdebugmode(TRUE);
  pRegProviz := Coalesce(pkg_categconst.GetValConstanta(&apos;RegProviz&apos; ,EXTRACT (YEAR FROM dDataRef),EXTRACT (MONTH FROM dDataRef)),&apos;0&apos;) ;

  IF pRegProviz = 2 THEN
    sAuxCLit := &apos;Coalesce(NULLIF(gl.curs,0),1)&apos;;
    sAuxJLit := &apos;&apos;;
  ELSE
    sAuxCLit := &apos;Coalesce(rc.curs, Coalesce(NULLIF(g.curs,0),1))&apos;;
    sAuxJLit := &apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = gl.codgeneral&apos;;
  END IF;

  SELECT ancurent, lunacurenta INTO sAnC, sLunaC FROM FIRMALUNI;
  IF (PKG_LIST_SELECTSCADENTAR.TipPerioada = 0) OR (sAnC*12+sLunaC &gt;= PKG_GLOBALS.ANLUNALUCRU) THEN
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, sAnP, sLunaP);
    sFiltruLuna := &apos; = &apos;||pkg_globals.AnLunaLucru;
  ELSE
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(sAnC, sLunaC, sAnP, sLunaP);
    sFiltruLuna := &apos; BETWEEN &apos;|| To_Char(sAnC*12+sLunaC)||&apos; AND &apos;||pkg_globals.AnLunaLucru;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.InLei
  THEN sConv := &apos;*CASE WHEN s.moneda = 0 THEN 1 ELSE s.Curs END&apos;;
  ELSE sConv := &apos;&apos;;
  END IF;

  IF aListID = 250 -- pe gestiuni
  THEN sConv := sConv||&apos;*Coalesce(cg.Coef,1)&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.TipIntarziere = 0
  THEN sZilePlusTerm := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-Coalesce(O.TERMEN,D.DATADOC),0)&apos;;
  ELSE sZilePlusTerm := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-D.DATADOC,0)&apos;;
  END IF;

  DELETE TMP_SCADENTARCL;

  sInsTMP :=
  &apos;INSERT INTO TMP_SCADENTARCL (
    codobligpif,CodDoc,CodDoc1,TipDoc, codpart, doc, nrdoc, datadoc, nri, blocat, termen,
    valoare, tva,
    restval,
    resttva,
    majorare, zile_trecute, zile_depasire,
    cont, adaosdoc,
    moneda, cursini, obs, carnetdoc, seriadoc, subunitatea, agent, codlocatie, initializari,
    codgeneral, coefprovizion, exclusplata,
    curs,
    codcentru,  userid, tvamediu,
    tvaincasare, ansapt, codtippartincert)&apos;;

  sSelTMP :=&apos;
  WITH xStins AS (
    SELECT DISTINCT codstinspif
    FROM obligpif os
      INNER JOIN general  gs ON gs.codgeneral     = os.codgeneral AND gs.tipdoc IN (29,30,31,33)
      INNER JOIN trezor1  t1 ON t1.codtrezor1     = gs.coddoc
      INNER JOIN trezor   t  ON t.codtrezor       = t1.codtrezor
      INNER JOIN stingere s  ON s.codstingatorpif = os.codobligpif
      INNER JOIN obligpif o  ON o.codobligpif     = s.codstinspif&apos;||
      sJoinFiltru||&apos;
    WHERE os.semnificatie = 750 AND (t1.an * 12 + t1.luna&apos;||sFiltruLuna||&apos;) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;t.DataDoc&apos;)||&apos;)
  SELECT -- FACTURI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END*o.valoare valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END tva,
    CASE WHEN d.an * 12 + d.luna&apos;||sFiltruLuna||&apos; THEN o.valoare ELSE Coalesce(ol.rest,0) END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END restval,
    CASE WHEN d.an * 12 + d.luna&apos;||sFiltruLuna||&apos; THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, Coalesce(NULLIF(g.curs,0),1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, d.userid, round(d.tvadoc/Coalesce (NullIF(d.valdoc-CASE WHEN d.tipdoc = 22 THEN d.tvadoc ELSE 0 END,0),1)*100, 2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, NULL codtippartincert
  FROM obligpif o
    INNER JOIN general      g  ON g.codgeneral       = o.codgeneral AND g.tipdoc IN (19,21,22,26)
    INNER JOIN iesiri       d  ON d.codies           = g.coddoc &apos;||sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif     = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT  JOIN xStins          ON xStins.codstinspif = o.codobligpif
  WHERE o.semnificatie IN (200,210,220)
    AND NOT (o.semnificatie = 210 AND Coalesce(g.tva,0)=o.valoare)
    AND (d.an * 12 + d.luna&apos;||sFiltruLuna||&apos; OR Coalesce(ol.rest,0) &lt;&gt; 0 OR Coalesce(ol.resttva,0) &lt;&gt; 0 OR xStins.codstinspif IS NOT NULL)
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||&apos;
  UNION ALL
  SELECT -- FACTURI LITIGII
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;Litigiu &apos;&apos;||Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, PKG_REGPART.GET_CURS_REG_PROVIZION( o.codobligpif, &apos;||pkg_globals.AnLucru||&apos;,&apos;||pkg_globals.LunaLucru||&apos;) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    &apos;||sAuxCLit||&apos; curs,
    o.codcentru, d.userid, round(d.tvadoc/Coalesce (NullIF(d.valdoc-CASE WHEN d.tipdoc = 22 THEN d.tvadoc ELSE 0 END,0),1) * 100, 2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, c.codtippartincert
  FROM obligpif o
    INNER JOIN (
      SELECT CONNECT_BY_ROOT CODOBLIGPIF ROOTCODOBLIGPIF, CODOBLIGPIF, CODGENERAL, ICONT
      FROM OBLIGPIF
      WHERE Coalesce(CODOBLIGASOCIAT,0) = 0
      START WITH semnificatie = 1303
      CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
    ) olit ON olit.rootcodobligpif = o.codobligpif
    INNER JOIN general      g  ON g.codgeneral       = olit.codgeneral AND g.tipdoc IN (19,21,22,26)
    INNER JOIN iesiri       d  ON d.codies           = g.coddoc
    INNER JOIN general      gl ON gl.codgeneral      = o.codgeneral AND gl.tipdoc = 28
    INNER JOIN compens      c  ON c.codcompens       = gl.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif     = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT  JOIN xStins          ON xStins.codstinspif = o.codobligpif&apos;||
    sAuxJLit||&apos;
  WHERE o.semnificatie = 1303
    AND d.an * 12 + d.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND (c.an * 12 + c.luna&apos;||sFiltruLuna||&apos; OR Coalesce(ol.rest,0) &lt;&gt; 0 OR Coalesce(ol.resttva,0) &lt;&gt; 0 OR xStins.codstinspif IS NOT NULL)
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;c.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsTMP||sSelTMP, aListID, 0);

  DELETE TMP_SCADCL_COEFG;
  IF aListID = 250 THEN -- pe gestiuni
    INSERT INTO TMP_SCADCL_COEFG ( CODOBLIGPIF, CODGEST, COEF)
    SELECT CODOBLIGPIF, CODGEST, CASE WHEN NRLINII = 1 THEN 1 WHEN VALTOT = VAL THEN 1 WHEN VALTOT = 0 THEN 0 ELSE VAL / VALTOT END
    FROM (
      SELECT
        S.CODOBLIGPIF, COALESCE(N.GEST, LV.GEST, I1.GESTACT, 0) CODGEST, Sum(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*COALESCE(L1.CANT,I1.CANT)) VAL,
        Count(1) OVER (PARTITION BY S.CODOBLIGPIF) NRLINII, Sum( Sum(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*COALESCE(L1.CANT,I1.CANT)) ) OVER (PARTITION BY S.CODOBLIGPIF) VALTOT
      FROM TMP_SCADENTARCL S
        LEFT JOIN IESIRI  I  ON I.CODIES      = S.CODDOC  AND I.TIPDOC   = S.TIPDOC
        LEFT JOIN IESIRI1 I1 ON I1.CODIES     = I.CODIES
        LEFT JOIN LIVR    L  ON L.CODIES      = I.CODIES  AND L.TIPLIVR  = I.TIPDOC
        LEFT JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
        LEFT JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
        LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      GROUP BY S.CODOBLIGPIF, COALESCE(N.GEST, LV.GEST, I1.GESTACT, 0)
    );
  END IF;

  sSelTMP :=&apos;
  SELECT -- TRANZACTII IN CURS -- TREZORERIE
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, d.doc, d.nrdoc, d.datadoc, d.nri, t.blocat, Coalesce(d.datadecont,o.termen) termen,
    o.valoare, Coalesce(g.tva,0) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_TREZOR.CODCONTCEC(t.CodBanca, o.Semnificatie, d.Tipdecont, d.obiecttranz, t.an, t.luna) cont, o.adaosdoc,
    g.moneda, Coalesce(NULLIF(g.curs,0),1) cursini, d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea, Coalesce(NULLIF(d.agent,0),t.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, t.userid, 0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, NULL codtippartincert
  FROM obligpif o
    INNER JOIN general      g  ON o.codgeneral   = g.codgeneral  AND g.tipdoc = 31
    INNER JOIN trezor1      d  ON d.codtrezor1   = g.coddoc
    INNER JOIN trezor       t  ON t.codtrezor    = d.codtrezor &apos;||sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||
  CASE WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma AND PKG_GLOBALS.GETSUBUNITATE &gt; 1 THEN &apos;
    LEFT JOIN general  gg ON gg.coddoc         = g.coddoc AND gg.tipdoc = g.tipdoc AND gg.semnificatie &lt;&gt; g.semnificatie
    LEFT JOIN obligpif og ON og.codgeneral     = gg.codgeneral
    LEFT JOIN stingere s  ON s.codstingatorpif = og.codobligpif
    LEFT JOIN obligpif os ON os.codobligpif    = s.codstinspif
    LEFT JOIN general  gs ON gs.codgeneral     = os.codgeneral
    LEFT JOIN iesiri   i  ON i.codies          = gs.coddoc AND i.tipdoc = gs.tipdoc&apos;
  END ||&apos;
  WHERE o.semnificatie = 600
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma AND PKG_GLOBALS.GETSUBUNITATE &gt; 1 THEN &apos;
    AND (t.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos; or Coalesce(i.subunitatea,0) = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)&apos;
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma THEN NULL
    ELSE PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)
  END;

  IF PKG_LIST_SELECTSCADENTAR.CuTranzInCurs THEN
    LIST_EXECUTE_IMMEDIATE(sInsTMP||sSelTMP, aListID, 0);
  END IF;

  sSelTMP :=&apos;
  SELECT -- TREZORERIE - PLATI si INCASARI IN AVANS
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, d.doc, d.nrdoc, d.datadoc, d.nri, t.blocat, Coalesce(d.datadecont,o.termen) termen,
    o.valoare * CASE WHEN o.semnificatie = 410 THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 410 THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 410 THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 410 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, Coalesce(NULLIF(g.curs,0),1) cursini,  d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea, Coalesce(NULLIF(d.agent,0),t.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, t.userid, 0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, NULL codtippartincert
  FROM obligpif o
    INNER JOIN general      g  ON o.codgeneral   = g.codgeneral AND g.tipdoc IN (29,30,31,33)
    INNER JOIN trezor1      d  ON d.codtrezor1   = g.coddoc
    INNER JOIN trezor       t  ON t.codtrezor    = d.codtrezor &apos;||
    sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
  WHERE o.semnificatie IN (410,330)
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||&apos;
  UNION ALL
  SELECT -- NOTE CONTABILE LEGATE DE PARTENERI
    o.codobligpif, d.codnc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;NC&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    o.valoare valoare, Coalesce(g.tva,0) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, Coalesce(NULLIF(g.curs,0),1) cursini, nc1.obs, d.carnetdoc, NULL seriadoc, d.subunitatea, nc1.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, d.userid, 0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, NULL codtippartincert
  FROM obligpif o
    INNER JOIN general      g  ON o.codgeneral   = g.codgeneral AND g.tipdoc IN (35)
    INNER JOIN nc1             ON nc1.codnc1     = g.coddoc
    INNER JOIN nc           d  ON d.codnc        = nc1.codnc &apos;||sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
  WHERE o.icont IN (3,5,/*7,*/10,11,18)  -- 7 - facturi de intocmit - trebuie exclus
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||&apos;
  UNION ALL
  SELECT -- NOTE CONTABILE LEGATE DE PARTENERI - LITIGII
    o.codobligpif, d.codnc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;Litigiu NC&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat,  o.termen,
    o.valoare * CASE WHEN o.semnificatie = 1201 THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 1201 THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 1201 THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 1201 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, PKG_REGPART.GET_CURS_REG_PROVIZION( o.codobligpif, &apos;||pkg_globals.AnLucru||&apos;,&apos;||pkg_globals.LunaLucru||&apos;) cursini, nc1.obs, d.carnetdoc, NULL seriadoc, d.subunitatea, COALESCE(nc1.agent,c.agent) agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, d.userid, 0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, c.codtippartincert
  FROM obligpif o
    INNER JOIN (
      SELECT CONNECT_BY_ROOT CODOBLIGPIF ROOTCODOBLIGPIF, CODOBLIGPIF, CODGENERAL, ICONT
      FROM OBLIGPIF
      WHERE Coalesce(CODOBLIGASOCIAT,0) = 0
      START WITH semnificatie = 1303
      CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
    ) olit ON olit.rootcodobligpif = o.codobligpif
    INNER JOIN general g  ON g.codgeneral = olit.codgeneral AND g.tipdoc IN (35)
    INNER JOIN nc1        ON nc1.codnc1   = g.coddoc
    INNER JOIN nc      d  ON d.codnc = nc1.codnc
    INNER JOIN general gl ON gl.codgeneral = o.codgeneral AND gl.tipdoc = 28
    INNER JOIN compens c  ON c.codcompens  = gl.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
  WHERE o.semnificatie = 1303
    AND olit.icont IN (3,5,/*7,*/10,11,18) -- 7 - facturi de intocmit - trebuie exclus
    AND d.an * 12 + d.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND ((c.an * 12 + c.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;c.DataDoc&apos;)||&apos;
  UNION ALL
  SELECT -- COMPENSARI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;PV&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
    PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    g.moneda, Coalesce(NULLIF(g.curs,0),1) cursini,  d.obsc obs, d.carnetdoc, NULL seriadoc, d.subunitatea, d.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce( (SELECT MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc)
          FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
          WHERE r1.CodGeneral = g.Codgeneral AND r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;),
        Coalesce(NULLIF(g.curs,0),1)) curs,
    o.codcentru, d.userid, 0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;yyyyww&apos;&apos;) ansapt, d.codtippartincert
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 28
    INNER JOIN compens d ON d.codcompens = g.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT  JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
  WHERE o.semnificatie IN (1301,1351)
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))
    AND o.icont IN (3,5,7,10,11,18)&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsTMP||sSelTMP, aListID, 0);

  PKG_LIST_BASE_SCADENTARCL.UMPLE_tmp_lst_scad_stins (aListID, sFiltruLuna);
  PKG_LIST_BASE_SCADENTARCL.UMPLE_tmp_lst_scad_sertar(aListID );

  DELETE tmp_dinamic_cols;
  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    INSERT INTO tmp_dinamic_cols (fieldname, display, indexlocal, cod)
    SELECT &apos;D&apos;||ROWNUM, TRUNC(ANSAPT/100)||&apos; Sapt.&apos;||To_Char(Mod(ANSAPT,100),&apos;fm00&apos;), ROWNUM, ANSAPT
    FROM (
      SELECT DISTINCT ANSAPT
      FROM TMP_SCADENTARCL
      WHERE ANSAPT IS NOT NULL
      ORDER BY ANSAPT
    );
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sUpdate    VARCHAR2(30000);
  sFAdaosDoc VARCHAR2(  500) := &apos;, NULL ADAOS&apos;;
  sValDiscZP VARCHAR2(  500) := &apos;, NULL VALDISCZP, NULL VALDISCC&apos;;
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  sCursRef   VARCHAR2(  100) := &apos;, 1 &apos;;
  i          INTEGER;
  aVTot      NUMBER(20, 7);
  dDataRef   DATE         := PKG_LIST_SELECTSCADENTAR.DataRef;
  sDataRef   VARCHAR2(10) := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);
BEGIN
  IF NOT PKG_LIST_SELECTSCADENTAR.TMPOk THEN
    UmpleTmp(aListId);
  END IF;

  gSuplCols :=
    &apos;TMP_SCADENTARCL S, OBLIGPIF O, NPART NP, NPART1 NP1, IOPART IOP, NMONEDE MON, NPARTCODFISC FISC, CENTRECOST CC, &apos;||
    &apos;NAGENDA SLIVR, NLOCALIT LLIVR, NJUDET JLIVR, NZONE ZLIVR, NTARI TLIVR, NPERS AG_SLIVR, NTIPSEDII TSLIVR, TRASEULIVR TRASLIVR,&apos;||
    &apos;NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NZONE ZSOC, NTARI TSOC, NPERS AG_SSOC,&apos;||
    &apos;NPERS AG_DOC, NCLASEP NCP, NCONT NC, NCONT1 NC1, NCONTS CS, DOCCARNETE DC, NPARTB PB, NBANK B, TMP_UTILIZATOR UTILIZATOR&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;     ,&apos;PD&apos;   ,&apos;PD.CODPART = S.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;    ,&apos;IEXT&apos; ,&apos;IEX.CODIES = S.CODDOC AND S.TIPDOC IN (19, 26)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TIPPARTINCERT&apos;,&apos;TPI&apos;  ,&apos;TPI.CODTIPPARTINCERT = S.CODTIPPARTINCERT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NCONT1&apos;);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  PRC_AL_CHECK(&apos;NAGENDA1&apos;);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, s.datadoc )&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcAdaosDoc THEN
    sFAdaosDoc := &apos;,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      WHEN o.semnificatie IN (210,211) THEN 0
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0 AND Coalesce(s.Valoare,0) = 0 THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0 THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))/s.Valoare
      ELSE PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(S.CodDoc,s.restval - Coalesce(stins.valoare,0))
    END ADAOS&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    sValDiscZP := &apos;,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      ELSE Coalesce(PKG_CONTRACT.CALCULEAZA_DISCT_DOC(s.TipDoc, s.CodDoc, &apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,(s.restval - Coalesce(stins.valoare,0))), 0)
    END,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      ELSE Coalesce(PKG_CONTRACT.CALCULEAZA_DISCC_DOC(s.TipDoc, s.CodDoc, To_Date(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), (s.restval - Coalesce(stins.valoare,0))), 0)
    END&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_CodDoc1,NAV_TipDoc,TipDoc,
    DENPART,DENGEST,CODFISCAL,LIVR_DEN,LIVR_LOC,LIVR_JUD,LIVR_ZONA,DENCLASAP,
    BLOCAT,BLOCATDOC,PREFDOC,NRDOC,DATADOC,NRI,OBSDOC,SERDOC,AGDOC,
    TERMEN,TERMENAN,TERMENLUNA,
    VALOARE,
    MAJORARE,REST,RESTTVA,RESTPART,
    VALMAJ,
    ZILE_SCADENTA,ZILE_TRECUTE,ZILE_DEPASIRE,
    DOCUMENT,MONEDA,CONT,CONTS,
    Z_0,L_1,L_2,L_3,L_4,L_5,L_6,T_2,T_3,T_31,T_32,T_33,T_4,S_1,S_2,S_3,S_4,P_30,P_60,P_90,P_360,TS_1,TS_2,TS_3,TS_4,TS_4p,
    P_Z_0,P_L_1,P_L_2,P_L_3,P_L_4,P_L_5,P_L_6,P_T_2,P_T_3,P_T_31,P_T_32,P_T_33,P_T_4,P_S_1,P_S_2,P_S_3,P_S_4,P_P_30,P_P_60,P_P_90,P_P_360,P_TS_1,P_TS_2,P_TS_3,P_TS_4,P_TS_4p,
    SUBUNITATE,EXCLUSPLATA,
    PROVIZION,
    CREDITC,SERTDECONT, SERTDOC, SERTSER, SERTNRDOC, SERTDATADOC, SERTVALDOC, SERTDATADEC, SERTVALASOC, CENTRUCOST, SIMBCENTRUCOST,
    AVANS, PROCTVAMEDIU, TVAINCAS,
    ANSAPT, CURS, CURS_INI, CURS_REF, ADAOSDOC, VALDISCZP, VALDISCC, X_Judet, X_CodClasaP, X_CodGest, X_CodSubunit &apos;||gUserFields||&apos;)&apos;;

  sSelect :=&apos;
  SELECT
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc END,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc1 END,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.TipDoc END,
    pkg_list_base_utils.decode_tipdoc(s.TipDoc),
    np.den_part, g.den_gest, fisc.codfiscal, slivr.obs, llivr.den_localit, jlivr.den_judet, zlivr.den_zona, ncp.den_clasep,
    CASE np.blocat WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END, CASE s.blocat WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END, s.doc, s.nrdoc, s.datadoc, s.nri, s.obs, Coalesce(s.seriadoc,dc.serie),
    CASE WHEN ag_doc.codpers &lt;&gt; 0 THEN ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume ELSE ag_doc.nume END,
    Coalesce(s.termen,s.datadoc), EXTRACT(YEAR FROM Coalesce(s.termen,s.datadoc)), EXTRACT(MONTH FROM Coalesce(s.termen,s.datadoc)),
    CASE
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 AND Coalesce(stins.valoare,0) &lt; 0 THEN Coalesce(s.restval,0) - Coalesce(stins.valoare,0)
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 THEN Coalesce(s.restval,0)
      ELSE s.valoare
    END &apos;||sConv||&apos;,
    s.majorare, (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos;, (s.resttva - Coalesce(stins.tva,0))&apos;||sConv||&apos;, sum((s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos;) OVER (PARTITION BY s.codpart),
    CASE WHEN s.zile_depasire &lt;= 0 THEN 0 ELSE ((s.restval - Coalesce(stins.valoare,0) - CASE WHEN o.semnificatie IN (210,410,430) THEN s.resttva - Coalesce(stins.tva,0) ELSE 0 END) * s.majorare/100 * s.zile_depasire)&apos;||sConv||&apos; END valmaj,
    CASE WHEN s.termen IS NULL THEN 0 ELSE s.termen - s.datadoc END, case when s.zile_trecute &gt; 0 then s.zile_trecute else 0 end, s.zile_depasire,
    s.doc||s.nrdoc||&apos;&apos;/&apos;&apos;||to_char(s.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), mon.den_moneda, nc.simbol, cs.simbol,
    CASE WHEN s.zile_depasire &lt;= 0                THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   1 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  31 AND  60 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  61 AND  90 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 120 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 121 AND 150 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 151 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 210 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 211 AND 240 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 241 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 271 AND 360 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   1 AND   7 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   8 AND  15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  16 AND  21 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  22 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  30               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  60               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  90               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &gt; 360               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  -7 AND  -1 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -14 AND  -8 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -21 AND -15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -28 AND -22 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &lt; -28               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END,
    CASE WHEN s.zile_depasire &lt;= 0                THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   1 AND  30 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  31 AND  60 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  61 AND  90 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 120 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 121 AND 150 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 151 AND 180 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 180 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 270 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 210 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 211 AND 240 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 241 AND 270 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN 271 AND 360 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   1 AND   7 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN   8 AND  15 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  16 AND  21 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  22 AND  30 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  30               THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  60               THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire &gt;  90               THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire &gt; 360               THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN  -7 AND  -1 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -14 AND  -8 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -21 AND -15 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire BETWEEN -28 AND -22 THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    CASE WHEN s.zile_depasire &lt; -28               THEN (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END ELSE 0 END,
    sub.den_subunit, CASE s.exclusplata WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END,
    COALESCE (xa1.creditclient, np1.creditclient) CREDITC, NS.DECONT, NS.DOC, NS.SER, NS.NRDOC, NS.DATADOC, NS.VALOARE, NS.DATADECONT, NS.VALASOC, CC.DENUMIRE,CC.SIMBOL,
    CASE WHEN O.semnificatie IN (110111,210,211,310,330,410,430) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END AVANS, Coalesce(s.TVAMediu,0), CASE s.TvaIncasare WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    s.ansapt, s.curs, s.cursini&apos;||sCursRef||sFAdaosDoc||sValDiscZP||
    &apos;, coalesce(JLIVR.Simbauto, JSOC.Simbauto), NCP.CODCLASEP, g.codgest, sub.codsubunit&apos;||gUserAlias ||&apos;
  FROM tmp_scadentarcl s
    LEFT JOIN obligpif            o          ON o.codobligpif            = s.codobligpif
    LEFT JOIN npart               np         ON np.codpart               = s.codpart
    LEFT JOIN tmp_scadcl_coefg    cg         ON cg.codobligpif           = s.codobligpif
    LEFT JOIN ngest               g          ON g.codgest                = Coalesce(cg.codgest,0)
    LEFT JOIN tmp_lst_scad_stins  stins      ON stins.codstinspif        = s.codobligpif
    LEFT JOIN nmonede             mon        ON mon.codmoneda            = s.moneda
    LEFT JOIN ncont               nc         ON nc.codcont               = s.cont
    LEFT JOIN ncont1              nc1        ON nc1.codcont              = s.cont       AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN nc1.ALStart and nc1.ALStop
    LEFT JOIN nconts              cs         ON cs.codconts              = nc1.contsecundar
    LEFT JOIN npart1              np1        ON np1.codpart              = s.codpart    AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN np1.ALStart and np1.ALStop
    LEFT JOIN iopart              iop        ON iop.codiopart            = np1.codiopart
    LEFt JOIN nagenda1            xA1        ON xA1.CodAgenda            = s.codlocatie AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN xA1.ALStart and xA1.ALStop
    LEFT JOIN NPARTCODFISC        FISC       ON fisc.codpart             = s.codpart    AND fisc.principal = 1
    LEFT JOIN NAGENDA             SSOC       ON ssoc.codpart             = s.codpart    AND Coalesce(ssoc.inactiv,0) = 0 AND ssoc.sediusocial Between 4 AND 7
    LEFT JOIN NAGENDA             SLIVR      ON slivr.codagenda          = CASE WHEN Coalesce(s.codlocatie,0) = 0 THEN ssoc.codagenda ELSE s.codlocatie END
    LEFT JOIN TRASEULIVR          TRASLIVR   ON traslivr.codtraseulivr   = slivr.codtraseu
    LEFT JOIN NTIPSEDII           TSLIVR     ON tslivr.codtipsediu       = slivr.codtipsediu
    LEFT JOIN NLOCALIT            LLIVR      ON llivr.codlocalit         = slivr.codlocalit
    LEFT JOIN NJUDET              JLIVR      ON jlivr.codjudet           = llivr.codjudet
    LEFT JOIN NZONE               ZLIVR      ON zlivr.codzona            = llivr.codzona
    LEFT JOIN NTARI               TLIVR      ON tlivr.codtara            = llivr.codtara
    LEFT JOIN NPERS               AG_SLIVR   ON ag_slivr.codpers         = Coalesce(slivr.codagent,0)
    LEFT JOIN NLOCALIT            LSOC       ON lsoc.codlocalit          = ssoc.codlocalit
    LEFT JOIN NJUDET              JSOC       ON jsoc.codjudet            = lsoc.codjudet
    LEFT JOIN NZONE               ZSOC       ON zsoc.codzona             = lsoc.codzona
    LEFT JOIN NTARI               TSOC       ON tsoc.codtara             = lsoc.codtara
    LEFT JOIN NPERS               AG_SSOC    ON ag_ssoc.codpers          = Coalesce(ssoc.codagent,0)
    LEFT JOIN NPERS               AG_DOC     ON ag_doc.codpers           = Coalesce(s.agent,0)
    LEFT JOIN nsubunit            sub        ON sub.codsubunit           = s.subunitatea
    LEFT JOIN NCLASEP             NCP        ON NCP.CODCLASEP            = NP.CODCLASA
    LEFT JOIN tmp_lst_scad_sertar ns         ON ns.codobligpif           = s.codobligpif
    LEFT JOIN doccarnete          dc         ON dc.codcarnet             = s.carnetdoc
    LEFT JOIN CENTRECOST          CC         ON cc.codcentru             = Coalesce(s.codcentru,0)
    LEFT JOIN NPARTB              PB         ON PB.codpart               = s.codpart AND pb.implicit = 1
    LEFT JOIN NBANK               B          ON b.codbank                = pb.codbank
    LEFT JOIN TMP_SUBUNITDEDICATE TS         ON ts.codsubunit            = s.subunitatea
    LEFT JOIN TMP_UTILIZATOR      UTILIZATOR ON utilizator.codutilizator = s.userid&apos;||
    gSuplJoins||&apos;
  WHERE Abs(s.restval - Coalesce(stins.valoare,0)) &gt;= 0.0001&apos;;

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    EXECUTE IMMEDIATE
     &apos;SELECT sum(valoare)
      FROM &apos;||tmpname||&apos;
      WHERE NAV_TipDoc IN (19,26)&apos;
    INTO aVTot;
    EXECUTE IMMEDIATE
     &apos;UPDATE &apos;||tmpname||&apos;
      SET valdiscv = pkg_contract.CALCULEAZA_DISCV_DOC(NAV_TipDoc,NAV_CodDoc,DataDoc,:VTot,Valoare)
      WHERE NAV_TipDoc IN (19,26)&apos;
    USING aVTot;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    i := 0;
    FOR vrec IN (SELECT fieldname, cod FROM TMP_DINAMIC_COLS ORDER BY INDEXLOCAL)
    LOOP
      i := i+1;
      sUpdate := sUpdate||&apos;,&apos;||vrec.Fieldname||&apos; = CASE ansapt = &apos;||vrec.Cod||&apos; THEN rest ELSE 0 END&apos;;
    END LOOP;
    sUpdate := &apos;UPDATE &apos;||tmpname||&apos; SET &apos;||SubStr(sUpdate,2);
    IF i &gt; 0 THEN
      LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
    END IF;
  END IF;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_List_Struct.AdunaColoanele;
END;

end PKG_LIST_BASE_AJDEPCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_AJDEPSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>434CDCF9B45EA668D7691C66704DAE19241F6752</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_AJDEPSTOC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
  aSubunitate   NUMBER(20);

  AnPrec        NUMBER(4);
  LunaPrec      NUMBER(2);

  DataStoc      DATE;
  AnLista       NUMBER(4);
  LunaLista     NUMBER(2);
  sAnIni        VARCHAR2(4);
  sLunaIni      VARCHAR2(2);
  sAnLunaIni    VARCHAR2(5);
BEGIN
  gSuplCols := &apos;NIRSTOC NS, NIR NIR, NARTOBJ NOBJ, NART NART, NUM1 NUM1, IOART IO, IOART1 IO1, NLOCATII NLOC, NGEST NG, NPART PROD, NPART FURN, NCONT C, NCLASEA NCA,&apos;||
               &apos;NSUBUNIT SUB&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  aSubunitate := pkg_globals.GETSUBUNITATE;

  dataStoc  := pkg_list_selfisamag.getDataStoc;
  LunaLista := EXTRACT(MONTH FROM DataStoc);
  AnLista   := EXTRACT(YEAR FROM DataStoc);

  pkg_globals.SetLunaTemp(AnLista,LunaLista);
  pkg_globals.Calculeaza_Luna_Precedenta(AnLista,LunaLista, AnPrec,LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);

  SELECT to_char(AnInitial,&apos;fm9999&apos;), to_char(LunaInitiala,&apos;fm99&apos;), to_char(AnInitial*12+LunaInitiala,&apos;fm99999&apos;) INTO sAnIni, sLunaIni, sAnLunaIni FROM FirmaLuni;

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(
      NAV_CODDOC,NAV_TIPDOC, NAV_NIRSTOC,
      DEN_GEST, DEN_LGEST, DEN_IOART, DEN_ART, DEN_UM,
      PRETACH, CODINTERN, CODEXTERN,VEKIMEMEDIE,PRODUCATOR,DATAACHIZ, DATAREF, STOC,
      VAL,
      STOC_SUB0, VAL_SUB0, STOC_0_30, VAL_0_30, STOC_31_60, VAL_31_60, STOC_61_90, VAL_61_90, STOC_91_180, VAL_91_180, STOC_180_PLUS, VAL_180_PLUS,
      STOC_0_3_LUNI, VAL_0_3_LUNI, STOC_3_6_LUNI, VAL_3_6_LUNI, STOC_6_9_LUNI, VAL_6_9_LUNI, STOC_9_12_LUNI, VAL_9_12_LUNI, STOC_6_12_LUNI, VAL_6_12_LUNI,
      STOC_1_2_ANI, VAL_1_2_ANI, STOC_2_ANI_PLUS, VAL_2_ANI_PLUS,
      PROV,
      VAL_PROV_SUB0, VAL_PROV_0_30, VAL_PROV_31_60, VAL_PROV_61_90, VAL_PROV_91_180, VAL_PROV_180_PLUS, VAL_PROV_0_3_LUNI, VAL_PROV_3_6_LUNI, VAL_PROV_6_9_LUNI, VAL_PROV_9_12_LUNI, VAL_PROV_6_12_LUNI,
      VAL_PROV_1_2_ANI, VAL_PROV_2_ANI_PLUS &apos;||gUserFields||&apos;)&apos;;

  IF PKG_LIST_SELFISAMAG.STOCLAZI THEN
    sSelect := &apos;
    WITH crs_docs AS(
      SELECT intr.codintr nav_coddoc,intr.tipdoc nav_tipdoc,intr.nrdoc,intr.datadoc,intr.prefixdoc, intr.subunitatea, intr.userid,
        CASE WHEN (intr.an * 12 + intr.luna) &gt;= &apos;||sAnLunaIni||&apos; then intr.an ELSE &apos;||sAnIni||&apos; END an,
        CASE WHEN (intr.an * 12 + intr.luna) &gt;= &apos;||sAnLunaIni||&apos; then intr.luna ELSE &apos;||sLunaIni||&apos; END luna
      FROM intrari intr inner join nir on nir.codintr = intr.codintr
      WHERE nvl(nir.anulat,0) = 0 AND nir.operat = 1
      UNION ALL
      SELECT ies.codies nav_coddoc,ies.tipdoc nav_topdoc,ies.nrdoc,ies.datadoc,ies.prefixdoc, ies.subunitatea,ies.userid,
        CASE WHEN (ies.an * 12 + ies.luna) &gt;= &apos;||sAnLunaIni||&apos; then ies.an ELSE &apos;||sAnIni||&apos; END an,
        CASE WHEN (ies.an * 12 + ies.luna) &gt;= &apos;||sAnLunaIni||&apos; then ies.luna ELSE &apos;||sLunaIni||&apos; END luna
      FROM iesiri ies inner join nir on nir.codies = ies.codies
      WHERE nvl(nir.anulat,0) = 0 AND nir.operat = 1
      UNION ALL
      SELECT tr.codtransf nav_coddoc,tr.tipdoc nav_tipdoc,tr.nrdoc,tr.datadoc,tr.prefixdoc,tr.subunitatea,tr.userid,
        CASE WHEN (tr.an * 12 + tr.luna) &gt;= &apos;||sAnLunaIni||&apos; then tr.an ELSE &apos;||sAnIni||&apos; END an,
        CASE WHEN (tr.an * 12 + tr.luna) &gt;= &apos;||sAnLunaIni||&apos; then tr.luna ELSE &apos;||sLunaIni||&apos; END luna
      FROM transf tr inner join nir on nir.codtransf = tr.codtransf
      WHERE nvl(nir.anulat,0) = 0 AND nir.operat = 1
    )
    SELECT
      COALESCE(NIR.CODINTR,NIR.CODIES,NIR.CODTRANSF), NIR.TIPNIR, NS.CODNIRSTOC,
      NG.DEN_GEST,NLOC.DENUMIRE LOCATIE,IO.DEN_IOART TIPCONTABIL,NOBJ.DENUMIRE,NUM1.DEN_UM1,
      NS.PRET - NS.ADAOS PRETACHIZ, NOBJ.CODINTERN, NOBJ.CODEXTERN, pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) VEKIMEMED,
      PROD.DEN_PART PRODUCATOR,nvl(NS.DATAACHIZ,nir.datanir), pkg_list_selfisamag.getDataRef, NS.REST, NS.REST * (NS.PRET-NS.ADAOS),
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN NS.REST ELSE 0 END STOC_SUB0,
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_SUB,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN NS.REST ELSE 0 END STOC_0_30,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_0_30,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN NS.REST ELSE 0 END STOC_31_60,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_31_60,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN NS.REST ELSE 0 END STOC_61_90,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_61_90,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN NS.REST ELSE 0 END STOC_91_180,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_91_180,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN NS.REST ELSE 0 END STOC_180_PLUS,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_180_PLUS,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN NS.REST ELSE 0 END STOC_0_3_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_0_3_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN NS.REST ELSE 0 END STOC_3_6_LUN,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_3_6_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST ELSE 0 END STOC_6_9_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_6_9_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN NS.REST ELSE 0 END STOC_9_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_9_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST ELSE 0 END STOC_6_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_6_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN NS.REST ELSE 0 END STOC_1_2_ANI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_1_2_ANI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN NS.REST ELSE 0 END STOC_2_ANI_PLUS,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN NS.REST * (NS.PRET-NS.ADAOS) ELSE 0 END VAL_2_ANI_PLUS,
      NS.REST * NVL(NS.PROVIZION,0),
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN NS.REST * NVL(NS.PROVIZION,0) ELSE 0 END&apos;||gUserAlias||&apos;
    FROM NIRSTOC NS
      INNER JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = NS.CODOBIECT
      INNER JOIN NART     NART ON NART.CODARTICOL = NOBJ.CODARTICOL
      INNER JOIN NIR           ON NIR.CODNIR      = NS.CODNIR
      INNER JOIN crs_docs doc  ON doc.nav_coddoc  = coalesce(nir.codtransf,nir.codies,nir.codintr) AND doc.nav_tipdoc = nir.tipnir
      INNER JOIN NGEST    NG   ON NG.CODGEST      = NIR.GEST
      INNER JOIN NSUBUNIT SUB  ON SUB.CODSUBUNIT  = NG.CODSUBUNIT
      INNER JOIN NUM1     NUM1 ON NUM1.CODUM1     = NS.UMSEC
      INNER JOIN IOART    IO   ON IO.CODIOART     = NS.CODIOART
      INNER JOIN IOART1   IO1  ON IO.CODIOART     = IO1.CODIOART AND (doc.an * 12 + doc.luna) BETWEEN IO1.ALSTART and IO1.ALSTOP
      LEFT  JOIN NCLASEA  NCA  ON NCA.CODCLASEA   = NART.CLASA
      LEFT  JOIN NCONT    C    ON C.CODCONT       = IO1.CONT
      LEFT  JOIN NLOCATII NLOC ON NLOC.CODLOCATIE = NS.CODLOCATIE
      LEFT  JOIN NPART    PROD ON PROD.CODPART    = NOBJ.CODPRODUCATOR
      LEFT  JOIN NPART    FURN ON FURN.CODPART    = NS.FURN&apos;||
    gSuplJoins||&apos;
    WHERE IO1.MG &lt;&gt; 5 and ns.rest &lt;&gt; 0 &apos;;

    IF  PKG_LIST_SELFISAMAG.ISALLTIPCONT = FALSE THEN
      sSelect := sSelect ||&apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE  = NS.CODIOART ) &apos;;
    END IF;

    IF  PKG_LIST_SELFISAMAG.isAllGest = FALSE THEN
      sSelect := sSelect || &apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE  = NIR.GEST ) &apos;;
    END IF;

    IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
      sSelect := sSelect || &apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE  = NS.CODOBIECT ) &apos;;
    END IF;

    IF aSubunitate &gt;1 THEN
      sSelect := sSelect ||&apos;
      AND ng.codsubunit = &apos;||aSubunitate;
    END IF;

  ELSE
    sSelect :=&apos;
    SELECT
      COALESCE(NIR.CODINTR,NIR.CODIES,NIR.CODTRANSF), NIR.TIPNIR, NS.CODNIRSTOC,
      NG.DEN_GEST,VLS.LOCATIE,IO.DEN_IOART TIPCONTABIL,NOBJ.DENUMIRE,NUM1.DEN_UM1,
      VLS.PRETACHIZ, NOBJ.CODINTERN, NOBJ.CODEXTERN, pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) VEKIMEMED,
      PROD.DEN_PART PRODUCATOR,INTRATLA, pkg_list_selfisamag.getDataRef, VLS.REST, VLS.REST * VLS.PRETACHIZ,
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN VLS.REST ELSE 0 END STOC_SUB0,
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_SUB0,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN VLS.REST ELSE 0 END STOC_0_30,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_0_30,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN VLS.REST ELSE 0 END STOC_31_60,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_31_60,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN VLS.REST ELSE 0 END STOC_61_90,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_61_90,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN VLS.REST ELSE 0 END STOC_91_180,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_91_180,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN VLS.REST ELSE 0 END STOC_180_PLUS,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_180_PLUS,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN VLS.REST ELSE 0 END STOC_0_3_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_0_3_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN VLS.REST ELSE 0 END STOC_3_6_LUN,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_3_6_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST ELSE 0 END STOC_6_9_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_6_9_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN VLS.REST ELSE 0 END STOC_9_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_9_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST ELSE 0 END STOC_6_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_6_12_LUNI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN VLS.REST ELSE 0 END STOC_1_2_ANI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_1_2_ANI,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN VLS.REST ELSE 0 END STOC_2_ANI_PLUS,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN VLS.REST * VLS.PRETACHIZ ELSE 0 END VAL_2_ANI_PLUS,
      VLS.REST * NVL(VLS.PROVIZION,0),
      CASE WHEN pkg_list_selfisamag.getDataRef &lt; nvl(NS.DATAACHIZ,nir.datanir) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN  0 AND  30 THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 31 AND  60 THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 61 AND  90 THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) BETWEEN 91 AND 180 THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN pkg_list_selfisamag.getDataRef - nvl(NS.DATAACHIZ,nir.datanir) &gt; 180 THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3)+1 AND pkg_list_selfisamag.getDataRef THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -3) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -9) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef, -6) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) BETWEEN ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24)+1 AND ADD_MONTHS(pkg_list_selfisamag.getDataRef,-12) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END,
      CASE WHEN nvl(NS.DATAACHIZ,nir.datanir) &lt;= ADD_MONTHS(pkg_list_selfisamag.getDataRef,-24) THEN VLS.REST * NVL(VLS.PROVIZION,0) ELSE 0 END&apos;||gUserAlias||&apos;
    FROM V_LIST_STOC VLS
      INNER JOIN NIRSTOC  NS   ON NS.CODNIRSTOC   = VLS.CODNIRSTOC
      INNER JOIN NIR      NIR  ON NIR.CODNIR      = VLS.CODNIR
      INNER JOIN NGEST    NG   ON NG.CODGEST      = NIR.GEST
      INNER JOIN NSUBUNIT SUB  ON SUB.CODSUBUNIT  = NG.CODSUBUNIT
      INNER JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = NS.CODOBIECT
      INNER JOIN NART     NART ON NART.CODARTICOL = NOBJ.CODARTICOL
      INNER JOIN NUM1     NUM1 ON NUM1.CODUM1     = NS.UMSEC
      INNER JOIN IOART    IO   ON VLS.CODIOART    = IO.CODIOART
      INNER JOIN IOART1   IO1  ON IO.CODIOART     = IO1.CODIOART AND (vls.an * 12 + vls.luna) BETWEEN IO1.ALSTART and IO1.ALSTOP
      LEFT JOIN NCLASEA   NCA  ON NCA.CODCLASEA   = NART.CLASA
      LEFT JOIN NCONT     C    ON C.CODCONT       = IO1.CONT
      LEFT JOIN NLOCATII  NLOC ON NLOC.CODLOCATIE = VLS.CODLOCATIE
      LEFT JOIN NPART     PROD ON PROD.CODPART    = NOBJ.CODPRODUCATOR
      LEFT JOIN NPART     FURN ON FURN.CODPART    = NS.FURN &apos;||
    gSuplJoins||&apos;
    WHERE IO1.MG &lt;&gt; 5 and vls.rest &lt;&gt; 0 &apos;;

    IF  PKG_LIST_SELFISAMAG.ISALLTIPCONT = FALSE THEN
      sSelect := sSelect ||&apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE  = NS.CODIOART ) &apos;;
    END IF;

    IF  PKG_LIST_SELFISAMAG.isAllGest = FALSE THEN
      sSelect := sSelect || &apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE  = NIR.GEST ) &apos;;
    END IF;

    IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
      sSelect := sSelect || &apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE  = NS.CODOBIECT ) &apos;;
    END IF;

    IF aSubunitate &gt;1 THEN
      sSelect := sSelect ||&apos;
      AND ng.codsubunit = &apos;||aSubunitate;
    END IF;

  END IF;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_AJDEPSTOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_AMBCUSTDEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4EEE946E4B194FF8FC57793B2CA0E595E5E2F0D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_AMBCUSTDEL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(30000);
  sFiltru     VARCHAR2( 1000);
BEGIN

  gSuplCols := &apos;comanda c, comanda1 c1, npart p, nsubunit s, ngest g, npers ag, nmonede m, nartobj o, num1 u1, nparttr del, nagenda sediu, nlocalit sl&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT  = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT  = C1.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELDELEGAT.DupaData THEN
    sFiltru := sFiltru||&apos;
    AND c.datadoc BETWEEN to_date(&apos;&apos;&apos;||PKG_LIST_SELDELEGAT.DataIni||&apos;&apos;&apos;) AND to_date(&apos;&apos;&apos;||PKG_LIST_SELDELEGAT.DataFin||&apos;&apos;&apos;) &apos;;
  ELSE
    sFiltru := sFiltru||&apos;
    AND (c.luna + c.an * 12) BETWEEN &apos;||PKG_LIST_SELDELEGAT.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELDELEGAT.LunaAnFin;
  END IF;

  if NOT PKG_LIST_SELDELEGAT.TotiDelegatii THEN
    sFiltru := sFiltru||&apos;
    AND c.delegat IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;DELEGAT&apos;&apos;) &apos;;
  end if;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, PREFIXDOC, NRDOC, DATADOC, DOCCOM,
    DEN_PART,
    DENUMIRE, DEN_UM1,
    CANTCOMANDAT, CANTRETURNAT, CANTFACTURAT, RESTACCEPTAT,
    PU, TERMEN, LINIE, MONEDA, OBSDOC, OBSLINIE, DELEGAT, MIJLTR, NRTRANSP &apos;||gUserFields||&apos; )
	SELECT
    c.codcomanda, c.tipdoc, c.prefixdoc, c.nrdoc, c.datadoc, c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc doccom,
    CASE
      WHEN NVL(c.partener,0) &lt;&gt; 0 THEN P.Den_Part
      WHEN NVL(c.codgest,0) &lt;&gt; 0 THEN G.Den_Gest
      ELSE S.Den_Subunit
    END den_part,
    o.denumire, u1.den_um1,
    c1.cantcomandat/u1.paritate, c1.cantreturnat/u1.paritate, (c1.cantacceptat - c1.restacceptat) / u1.paritate, c1.restacceptat/u1.paritate,
    c1.pu*u1.paritate, c1.termen, c1.Indexlocal, m.simbol, c.OBS, c1.OBS, del.delegat, del.mijltransp, del.nrtransp&apos;||gUserAlias||&apos;
  FROM comanda c
    LEFT JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
    LEFT JOIN npart p     ON p.codpart    = c.partener
    LEFT JOIN nsubunit s  ON s.codsubunit = c.subunitsursa
    LEFT JOIN ngest g     ON g.codgest    = c.codgest
    LEFT JOIN npers ag    ON ag.codpers   = c.agent
    LEFT JOIN nmonede m   ON m.codmoneda  = Nvl(c.moneda,0)
		LEFT JOIN nartobj o   ON o.codobiect  = c1.codobiect
		LEFT JOIN num1 u1     ON u1.codum1    = c1.umsec
    LEFT JOIN nparttr del ON del.codpers  = c.delegat
    LEFT JOIN nagenda sediu ON sediu.codagenda = c.codlocatie
    LEFT JOIN nlocalit sl ON sl.codlocalit = sediu.codlocalit &apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 57 AND c.anulat = 0 AND c.operat = 1 &apos;||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_AMBCUSTDEL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZACONSUMURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38CF2C05BD11F05A9C2BF002C1B98F626CA3E11D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ANALIZACONSUMURI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500) := &apos;&apos;;
  gSuplJoins  VARCHAR2(5000);
  vAnLuna     number;
  vSub        number(20);

procedure RESET_PRET_NIRSTOC1 is
begin
  pkg_pretprod.UpdateNirStoc1;
  vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  for v_rec in (select ns1.codnirstoc
                from nirstoc1 ns1
                     inner join nirstoc ns on ns.codnirstoc = ns1.codnirstoc
                     inner join NIR N on n.codnir = ns.codnir
                     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
                     LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC
                where nvl(i.anulat, nvl(t.anulat,0)) = 0 and nvl(i.operat, nvl(t.operat,0)) = 1 and nvl(i.an,t.an)*12+nvl(i.luna,t.luna) &gt;= vAnLuna) loop

    update nirstoc1 set
      Dirty    = 1
    where codnirstoc = v_rec.codnirstoc;
  end loop;
  UpdatePretNirStoc1;
end;

function GetPretNirStoc(aCodNirStoc in number) return number is
aTipDoc number(10);
aPret number(20,7);
aCodNirStocOrig number(20);
begin

  begin
    select TipDoc, Nvl(CodNirStocOrig, CodNirStoc) into aTipDoc, aCodNirStocOrig
    from NIRSTOC1
    where codnirstoc = aCodNirStoc;
  exception when others then
    insert into x(test) values (aCodNirstoc);
    commit;
  end;

  if aTipDoc = 7 then
    begin
      select PretMat into aPret from NIRSTOC1
      where codnirstoc = aCodNirStocOrig and Dirty = 0;
      exception when others then aPret := 0;
    end;
    if Nvl(aPret,0) = 0 then
      aPret := GetPretNirStoc1(aCodNirStocOrig);
    end if;
  else
    select nvl(ns.pret,0) - nvl(ns.adaos,0) into aPret
    from NIRSTOC NS
         inner join NIR N on n.codnir = ns.codnir
         LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
         LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC
    where ns.codnirstoc = aCodNirStoc;
  end if;

  --update NirStoc1 set PretMat = aPret, Dirty = 0 where codnirstoc = acodnirstoc;
  --Commit;

  return aPret;
end;

function GetPretNirStoc1(aCodNirStoc in number) return number is
aPredat number(20,7);
aValMat number(20,7);
aAn number(20,7);
aLuna number(20,7);
aPret number(20,7);
begin
  select NVL(i.an, T.AN), NVL(i.luna, T.Luna) into aAn, aLuna
  from NIRSTOC NS
       inner join NIR N on n.codnir = ns.codnir
       LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
       LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC
  where ns.codnirstoc = aCodNirStoc;

  aPredat   := 0;
  aValMat := 0;
  for v_rec in (
    select
      predat.cant predat,
      l1.cant cantlivr,
      case when ns1.tipdoc = 7 then nvl(nso.pret,0) - nvl(nso.adaos, 0) else nvl(nsi.pret,0) - nvl(nsi.adaos, 0) end pu,
      ns1.tipdoc,
      ns1.codnirstoc,
      ns1.dirty,
      nvl(ns1.pretmat,0) pretmat
    from nirstoc ns
         inner join intrari1 i1 on i1.codintr1 = ns.codintr1
         inner join cmdprodmat prod on prod.codcomanda1 = i1.codcmdint1 and nvl(prod.tip,0) = 0
         inner join (select sum(i1.cant) cant, i1.codcmdint1
                     from intrari1 i1
                          inner join intrari i on i1.codintr = i.codintr
                     where i1.codcmdint1 &gt; 0 and i.an = aAn and i.Luna = aLuna
                     group by i1.codcmdint1) predat on predat.codcmdint1 = prod.codcomanda1
         inner join iesiri1 ies1 on ies1.codcmdint1 = prod.codcomanda1
         inner join iesiri ies on ies.codies = ies1.codies
         inner join livr l on l.codies = ies.codies
         inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
         inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
         inner join nirstoc nsi on nsi.codnirstoc = ns1.codnirstoc
         inner join nirstoc nso on nso.codnirstoc = ns1.codnirstocorig
    where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and ies.an = aAn and ies.luna = aLuna and ns.codnirstoc = aCodNirStoc
    ) loop

    aPredat := v_Rec.Predat;

    if (v_rec.TipDoc &lt;&gt; 7) or (v_rec.TipDoc = 7 and v_rec.codnirstoc = aCodNirStoc) then
      aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
    else
      if v_rec.Dirty = 1 then
        aPret := GetPretNirStoc(v_rec.codnirstoc);
        if aPret = 0 then
          aValMat := 0;
          Exit;
        end if;
        aValMat := aValMat + v_Rec.cantlivr * aPret;
      else
        if nvl(v_rec.pretmat,0) = 0 then
          aPret := GetPretNirStoc(v_rec.codnirstoc);
          if aPret = 0 then
            aValMat := 0;
            Exit;
          end if;
          aValMat := aValMat + v_Rec.cantlivr * aPret;
        else
          aValMat := aValMat + v_Rec.cantlivr * v_rec.pretmat;
        end if;
      end if;
    end if;
  end loop;

  if aPredat = 0 then
    --update nirstoc1 set PretMat = 0, Dirty = 0 where codnirstoc = aCodnirstoc;
    return 0;
  end if;

  --update nirstoc1 set PretMat = aValMat/aPredat, Dirty = 0 where codnirstoc = aCodnirstoc;
  return aValMat/aPredat;
end;

procedure UpdatePreturiPeLuna(aAn in number, aLuna in number) is
aPret number(20,7);
begin
  for v_rec in (select ns1.codnirstoc, ns1.codnirstocorig, ns1.TipDoc
                from nirstoc1 ns1
                       inner join nirstoc ns on ns.codnirstoc = ns1.codnirstoc
                       inner join NIR N on n.codnir = ns.codnir
                       LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
                       LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC
                where nvl(i.anulat, nvl(t.anulat,0)) = 0 and nvl(i.operat, nvl(t.operat,0)) = 1 and nvl(i.an,t.an)*12+nvl(i.luna,t.luna) = aAn*12+aLuna and nvl(ns1.Dirty,0) = 1) loop
    if v_rec.tipdoc = 7 then
      aPret := GetPretNirStoc(v_rec.codnirstocorig);
      if aPret = 0 then
        select nvl(pret,0) - nvl(adaos,0) into aPret
        from nirstoc where codnirstoc = v_rec.codnirstocorig;
        update nirstoc1 set
          Pretmat  = aPret,
          Dirty    = 0,
          DinStoc  = 1
        where codnirstoc = v_rec.codnirstoc;
      else
        update nirstoc1 set
          Pretmat  = aPret,
          Dirty    = 0,
          DinStoc  = 0
        where codnirstoc = v_rec.codnirstoc;
      end if;
    else
      select nvl(pret,0) - nvl(adaos,0) into aPret
      from nirstoc where codnirstoc = v_rec.codnirstoc;
      update nirstoc1 set
        Pretmat  = aPret,
        Dirty    = 0,
        DinStoc  = 1
      where codnirstoc = v_rec.codnirstoc;
    end if;
    commit;
  end loop;
end;

procedure UpdatePretNirStoc1(FaraNP in boolean default False) is
aPret NUMBER(20,7);
begin
  for v_rec in (select i1.codintr1, prod.codcomanda1
                from intrari1 i1
                     inner join intrprodlink l on i1.codintr1 = l.codintr1
                     inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
                where nvl(i1.codcmdint1,0) = 0) loop
    update intrari1 set codcmdint1 = v_rec.codcomanda1 where codintr1 = v_rec.codintr1;
  end loop;
  commit;

  if FaraNP then
    for v_rec in (select ns1.codnirstoc, ns1.codnirstocorig, ns1.TipDoc
                  from nirstoc1 ns1
                  where nvl(ns1.Dirty,0) = 1 and nvl(ns1.tipdoc,0) &lt;&gt; 7) loop
      select nvl(pret,0) - nvl(adaos,0) into aPret
      from nirstoc where codnirstoc = v_rec.codnirstoc;
      update nirstoc1 set
        Pretmat  = aPret,
        Dirty    = 0
      where codnirstoc = v_rec.codnirstoc;
      commit;
    end loop;
  else
    for v_rec in (select ns1.codnirstoc, ns1.codnirstocorig, ns1.TipDoc
                  from nirstoc1 ns1
                  where nvl(ns1.Dirty,0) = 1) loop
      if v_rec.tipdoc = 7 then
        aPret := GetPretNirStoc(v_rec.codnirstocorig);
        if aPret = 0 then
          select nvl(pret,0) - nvl(adaos,0) into aPret
          from nirstoc where codnirstoc = v_rec.codnirstocorig;
          update nirstoc1 set
            Pretmat  = aPret,
            Dirty    = 1,
            DinStoc  = 1
          where codnirstoc = v_rec.codnirstoc;
        else
          update nirstoc1 set
            Pretmat  = aPret,
            Dirty    = 0,
            DinStoc  = 0
          where codnirstoc = v_rec.codnirstoc;
        end if;
      else
        select nvl(pret,0) - nvl(adaos,0) into aPret
        from nirstoc where codnirstoc = v_rec.codnirstoc;
        update nirstoc1 set
          Pretmat  = aPret,
          Dirty    = 0,
          DinStoc  = 1
        where codnirstoc = v_rec.codnirstoc;
      end if;
      commit;
    end loop;
  end if;
end;

procedure Corectii(vLuna in number, vAn in number) is
dif number(20,7);
aCodIes1 number(20);
begin
  for v_rec in (select distinct mat.codcmdprodmat
                from cmdprodmat mat
                     inner join iesprodlink l on l.codcmdprodmat = mat.codcmdprodmat
                     inner join iesiri1 ies1 on ies1.codies1 = l.codies1
                     inner join comanda1 c1 on mat.codcomanda1 = c1.codcomanda1
                     inner join comanda c on c1.codcomanda = c.codcomanda
                where c.Luna = vLuna and c.An = vAn and mat.rest &lt; 0) loop
    begin
      select sum(ies1.cant) - mat.cant into Dif
      from cmdprodmat mat
           inner join iesprodlink l on mat.codcmdprodmat = l.codcmdprodmat
           inner join iesiri1 ies1 on ies1.codies1 = l.codies1
      where mat.codcmdprodmat = v_rec.codcmdprodmat
      group by mat.cant;
    exception when others then Dif := 0;
    end;

    if Dif &gt; 0 then
      for v_tmp in (select l.codies1 l_codies1, l.codcmdprodmat l_codcmdprodmat, l.cant l_cant, l.codprogramf1 l_codprogramf1,
                           i1.CODIES1,i1.CODIES,i1.INDEXLOCAL,i1.TIPLINIE,i1.UMSEC,i1.CONTSERV,i1.GESTACT,i1.CODOBIECT,i1.PRETORIG,i1.PU,i1.CANT,i1.TVA,i1.CONT,i1.ADDIM,i1.PROCDISC,i1.RESTFACT,
                           i1.PUMAXIMAL,i1.TIPLIVRARE,i1.GARANTIE,i1.CODOBLIGSTORNO,i1.CURSFACTURAAVANS,i1.COEFDISCMAJ,i1.OBS,i1.CODOBIECTORIG,i1.PARITATEORIG,i1.CONTDISCOUNT,i1.CODCRITERIU,
                           i1.MIFIX,i1.ZILE,i1.COSTTRANSPORT,i1.ZILECMD,i1.CODLIVR1PRODVAL,i1.CODIES1STORNO,i1.CODOFERTA1,i1.CADOU,i1.TIPPLATA,i1.PRETPROMO,i1.CADOULINK,i1.CODIOARTCUST,i1.UMCORELAT,
                           i1.CANTCORELAT,i1.PUCORELAT,i1.CODCENTRU,i1.CODCADOU,i1.CODOBLIGMONETAR,i1.TAXA,i1.TERMENCONTRACT,i1.CODLINIEDOCIMP,i1.TIPDOCIMP,i1.CODCMDINT1,i1.CODANALIZANOD,i1.D1D3BCS,i1.CODOBLIGMAJORAT,
                           NI.NextIndex, i.tipdoc, i.an, i.luna, i.subunitatea
                    from iesprodlink l
                         inner join iesiri1 i1 on i1.codies1 = l.codies1
                         inner join iesiri i on i.codies = i1.codies
                         inner join (select max(indexlocal)+1 nextindex, codies
                                     from iesiri1
                                     group by codies) NI on NI.CodIes = i1.codies
                    where l.codcmdprodmat = v_rec.codcmdprodmat
                    order by i1.codies1 desc
                   )loop
        if Dif = v_tmp.cant then
          delete iesprodlink
          where nvl(codies1,0) = nvl(v_tmp.l_codies1,0)
                and nvl(codcmdprodmat,0) = nvl(v_tmp.l_codcmdprodmat,0)
                and nvl(codprogramf1,0) = nvl(v_tmp.l_codprogramf1,0);
          Exit;
        else
          if Dif &gt; v_tmp.cant then
            delete iesprodlink
            where nvl(codies1,0) = nvl(v_tmp.l_codies1,0)
                and nvl(codcmdprodmat,0) = nvl(v_tmp.l_codcmdprodmat,0)
                and nvl(codprogramf1,0) = nvl(v_tmp.l_codprogramf1,0);
            Dif := Dif - v_tmp.cant;
          else
            select seq_iesiri1_CODIES1.Nextval into aCodIes1 from dual;
            update iesiri1 set
              cant = v_tmp.cant - Dif,
              TVA  = TVA * (v_tmp.cant - Dif)/v_tmp.cant
            where codies1 = v_tmp.codies1;

            update iesprodlink set cant = v_tmp.cant - Dif
            where nvl(codies1,0) = nvl(v_tmp.l_codies1,0)
                  and nvl(codcmdprodmat,0) = nvl(v_tmp.l_codcmdprodmat,0)
                  and nvl(codprogramf1,0) = nvl(v_tmp.l_codprogramf1,0);

            insert into iesiri1 (CODIES1,CODIES,INDEXLOCAL,TIPLINIE,UMSEC,CONTSERV,GESTACT,CODOBIECT,PRETORIG,PU,CANT,TVA,CONT,ADDIM,PROCDISC,RESTFACT,
                                 PUMAXIMAL,TIPLIVRARE,GARANTIE,CODOBLIGSTORNO,CURSFACTURAAVANS,COEFDISCMAJ,OBS,CODOBIECTORIG,PARITATEORIG,CONTDISCOUNT,CODCRITERIU,
                                 MIFIX,ZILE,COSTTRANSPORT,ZILECMD,CODLIVR1PRODVAL,CODIES1STORNO,CODOFERTA1,CADOU,TIPPLATA,PRETPROMO,CADOULINK,CODIOARTCUST,UMCORELAT,
                                 CANTCORELAT,PUCORELAT,CODCENTRU,CODCADOU,CODOBLIGMONETAR,TAXA,TERMENCONTRACT,CODLINIEDOCIMP,TIPDOCIMP,CODCMDINT1,CODANALIZANOD,D1D3BCS,CODOBLIGMAJORAT)
            values (aCodIes1,v_tmp.CODIES,v_tmp.NEXTINDEX,v_tmp.TIPLINIE,v_tmp.UMSEC,v_tmp.CONTSERV,v_tmp.GESTACT,v_tmp.CODOBIECT,v_tmp.PRETORIG,v_tmp.PU,Dif,v_tmp.TVA*Dif/v_tmp.cant,v_tmp.CONT,v_tmp.ADDIM,v_tmp.PROCDISC,v_tmp.RESTFACT,
                    v_tmp.PUMAXIMAL,v_tmp.TIPLIVRARE,v_tmp.GARANTIE,v_tmp.CODOBLIGSTORNO,v_tmp.CURSFACTURAAVANS,v_tmp.COEFDISCMAJ,v_tmp.OBS,v_tmp.CODOBIECTORIG,v_tmp.PARITATEORIG,v_tmp.CONTDISCOUNT,v_tmp.CODCRITERIU,
                    v_tmp.MIFIX,v_tmp.ZILE,v_tmp.COSTTRANSPORT,v_tmp.ZILECMD,v_tmp.CODLIVR1PRODVAL,v_tmp.CODIES1STORNO,v_tmp.CODOFERTA1,v_tmp.CADOU,v_tmp.TIPPLATA,v_tmp.PRETPROMO,v_tmp.CADOULINK,v_tmp.CODIOARTCUST,v_tmp.UMCORELAT,
                    v_tmp.CANTCORELAT,v_tmp.PUCORELAT,v_tmp.CODCENTRU,v_tmp.CODCADOU,v_tmp.CODOBLIGMONETAR,v_tmp.TAXA,v_tmp.TERMENCONTRACT,v_tmp.CODLINIEDOCIMP,v_tmp.TIPDOCIMP,v_tmp.CODCMDINT1,v_tmp.CODANALIZANOD,v_tmp.D1D3BCS,v_tmp.CODOBLIGMAJORAT);
            -- procesez livrarile
            for v_x in (select l1.*
                        from livr1 l1
                        where l1.codies1 = v_tmp.codies1) loop
              if Dif = v_x.cant then
                update livr1 set codies1 = aCodIes1 where codlivr1 = v_x.codlivr1;
                Exit;
              else
                if Dif &gt; v_x.cant then
                  update livr1 set codies1 = aCodIes1 where codlivr1 = v_x.codlivr1;
                  Dif := Dif - v_x.Cant;
                else
                  update livr1 set
                    cant = v_x.cant - Dif,
                    cantum1 = cantum1*(v_x.cant - Dif)/v_x.cant,
                    cantum2 = cantum2*(v_x.cant - Dif)/v_x.cant
                  where codlivr1 = v_x.codlivr1;
                  insert into livr1 (CODLIVR1,CODLIVR,CODIES1,CODINTR1,CODDVI1,CODNIRSTOC,CANT,CODNIRSER,PMP,UMSEC,CANTUM1,CANTUM2,RESTIESVAL,CANTREZERVAT,CODCERTIF,CODPRODCOMP,
                                     PMPVALUTA,PMPDOC,PMPVALUTADOC,CONTINTERMED,CODPROIECT,CODGESTORIG)
                  values (seq_livr1_codlivr1.nextval, v_x.CODLIVR,aCodIes1,v_x.CODINTR1,v_x.CODDVI1,v_x.CODNIRSTOC,Dif,v_x.CODNIRSER,v_x.PMP,v_x.UMSEC,v_x.CANTUM1*Dif/v_x.cant,v_x.CANTUM2*Dif/v_x.cant,v_x.RESTIESVAL,v_x.CANTREZERVAT,v_x.CODCERTIF,v_x.CODPRODCOMP,
                          v_x.PMPVALUTA,v_x.PMPDOC,v_x.PMPVALUTADOC,v_x.CONTINTERMED,v_x.CODPROIECT,v_x.CODGESTORIG);
                  Exit;
                end if;
              end if;
            end loop;
            pkg_jurnal.SetDirty(v_tmp.codies, v_tmp.tipdoc, v_tmp.Subunitatea, v_tmp.An, v_tmp.Luna);
            Exit;
          end if;
        end if;
      end loop;
      update cmdprodmat set rest = 0 where codcmdprodmat = v_rec.codcmdprodmat;
    end if;
  end loop;
  commit;
end;

procedure CompleteazaTemporar(aAnLuna in number, aCodNirStoc in number) is
begin
  if aCodNirStoc = 0 then
    -- suntem la inceput
    insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, NP)
    select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC
    from nirstoc ns
         inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
         inner join intrari1 i1 on ns.codintr1 = i1.codintr1
         inner join intrprodlink l on i1.codintr1 = l.codintr1
         inner join intrari i on i.codintr = i1.codintr
         inner join tmp_manevra_liste tmpart on tmpart.filtru = &apos;CODOBIECT&apos; and to_number(tmpart.valoare) = i1.codobiect
         inner join tmp_manevra_liste tmpgest on tmpgest.filtru = &apos;CODGEST&apos; and to_number(tmpgest.valoare) = i.codgestprod
    where i.tipdoc = 7 and i.an*12+i.luna = vAnLuna
          and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
          and ((vSub = 1) or i.subunitatea = vSub);

    insert into tmp_manevra_intr1_grupl (codcmdprodmat, cantpredata, cantlansata, CMD, AnLuna)
    select tmp.codcmdprodmat, sum(tmp.cantpredata), nvl(prod.cant,0), C.PREFIXDOC||&apos; &apos;||C.NRDOC||&apos;/&apos;||C.DATADOC, aAnLuna
    from tmp_manevra_intr1 tmp
         inner join cmdprodmat prod on tmp.codcmdprodmat = prod.codcmdprodmat
         INNER JOIN COMANDA1 C1 ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C  ON C.CODCOMANDA = C1.CODCOMANDA
    group by tmp.codcmdprodmat, prod.cant, C.PREFIXDOC,C.NRDOC,C.DATADOC;

    insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect, BC, TIPLINIE, codcmdprodmat_mat)
    select tmp.codcmdprodmat, l1.cant, ns1.pretmat pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect, i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC, NS1.TIPDOC,
           link.codcmdprodmat
    from tmp_manevra_intr1_grupl tmp
         inner join cmdprodmat prod on prod.codcmdprodmat = tmp.codcmdprodmat
         inner join iesiri1 i1 on i1.codcmdint1 = prod.codcomanda1
         inner join iesiri i on i.codies = i1.codies
         inner join livr1 l1 on l1.codies1 = i1.codies1
         inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
         inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
         inner join nirstoc nsi on ns1.codnirstocorig = nsi.codnirstoc
         inner join ioart ioa on ioa.codioart = ns.codioart
         left join iesprodlink link on link.codies1 = i1.codies1
    where i.operat = 1 and nvl(i.anulat,0) = 0 and i.an*12+i.luna = vAnLuna;

    update tmp_manevra_intr1_grupc tmpc
    set cant_mat = (select sum(t.cant) from tmp_manevra_intr1_grupc t where tmpc.codcmdprodmat_mat = t.codcmdprodmat_mat),
        cant_ret = (select nvl(mat.cant,0)
                    from tmp_manevra_intr1_grupc t
                         left join cmdprodmat mat on t.codcmdprodmat_mat = mat.codcmdprodmat
                    where t.codcmdprodmat_mat = t.codcmdprodmat_mat and rownum = 1),
        pret_ret = (select nvl(m.pret,0)
                    from tmp_manevra_intr1_grupc t
                         left join cmdprodmat mat on t.codcmdprodmat_mat = mat.codcmdprodmat
                         left join prodmat m on m.codmat = mat.codprodmat
                    where t.codcmdprodmat_mat = t.codcmdprodmat_mat and rownum = 1)
    where nvl(codcmdprodmat_mat,0) &gt; 0;

    update tmp_manevra_intr1_grupc tmpc
    set cantK = cant*cant_ret/cant_mat where nvl(cant_mat,0) &lt;&gt; 0;

    insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect, BC, TIPLINIE, cont, codcmdprodmat_mat, cantK, pret_ret)
    select tmpl.codcmdprodmat, 0, 0, 0, 0, 0, mat.codobiect, &apos;-&apos;, 0, &apos;-&apos;,0, mat.cant, m.pret
    from tmp_manevra_intr1_grupl tmpl
         inner join cmdprodmat prod on prod.codcmdprodmat = tmpl.codcmdprodmat
         inner join cmdprodmat mat on mat.codcomanda1 = prod.codcomanda1 and mat.tip = 1
         inner join prodmat m on m.codmat = mat.codprodmat
    where not exists (select tmpc.codcmdprodmat_mat from tmp_manevra_intr1_grupc tmpc where tmpc.codcmdprodmat_mat = mat.codcmdprodmat);
  else
    commit;
  end if;
end;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(10000);
BEGIN
  vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  vSub := pkg_globals.GETSUBUNITATE;
  -- updatez nirstoc1
  pkg_pretprod.UpdateNirStoc1;
  UpdatePretNirStoc1(True);
  commit;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if pkg_list_selectgestart.AllGest then
    delete tmp_manevra_liste where filtru = &apos;CODGEST&apos;;
    insert into tmp_manevra_liste(filtru, valoare)
    select &apos;CODGEST&apos;, codgest
    from ngest where tip = 2;
  end if;

  if pkg_list_selectgestart.AllArt then
    delete tmp_manevra_liste where filtru = &apos;CODOBIECT&apos;;
    insert into tmp_manevra_liste(filtru, valoare, filtru1, valoare1)
    select &apos;CODOBIECT&apos;, codobiect, &apos;CODOBIECT&apos;, codobiect
    from nartobj;
  end if;

  delete tmp_manevra_intr1;
  delete tmp_manevra_intr1_grupl;
  delete tmp_manevra_intr1_grupc;
  CompleteazaTemporar(vAnLuna, 0);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;
   (NAV_CodDoc,
    NAV_TipDoc,
    Produs,
    CantProdusL,
    CantProdus,
    Material,
    CantMaterial,
    PretMaterial,
    ValMaterial,
    CantMaterial_R,
    PretMaterial_R,
    ValMaterial_R,
    BC,
    CMD,
    NP &apos;||gUserFields||&apos;)
  SELECT
    GC.CODDOC,
    GC.TIPDOC,
    PROD.DENUMIRE,
    I1.CANTPREDATA,
    GL.CANTLANSATA,
    MAT.DENUMIRE,
    nvl(gc.cantK,0),
    nvl(gc.pret_ret,0),
    nvl(gc.cantK,0)*nvl(gc.pret_ret,0),
    I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT,
    GC.PRETCONSUM,
    I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT*GC.PRETCONSUM,
    GC.BC,
    GL.CMD,
    I1.NP &apos;||gUserAlias||&apos;
  FROM tmp_manevra_intr1 I1
    INNER JOIN tmp_manevra_intr1_grupl GL ON GL.CODCMDPRODMAT = I1.CODCMDPRODMAT
    INNER JOIN tmp_manevra_intr1_grupc GC ON GC.CODCMDPRODMAT = GL.CODCMDPRODMAT
    INNER JOIN NARTOBJ PROD ON I1.CODOBIECT = PROD.CODOBIECT
    INNER JOIN NARTOBJ MAT ON GC.CODOBIECT = MAT.CODOBIECT &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

procedure proceseaza_mat(P in number, cantP in number, cantM in number, cantM_r in number, acodnirstoc in number, aStorno in number) is
begin
  /*for v_rec in (select intr1.cant cantP_r, l1.cant,
                       intr1.cant/prod.cant*nvl(mat.cant,0) cantt,
                       intr1.codobiect produs, ies1.pu * l1.cant valoare, ns.codnirstoc, ns.codobiect material, prod.cant cantcomp, nvl(mat.pret,0) pret,
                       mat.codcmdprodmat, prod.cant cantprodusl, ies1.cant canties1, ies.an*12+ies.luna anlunalivr,
                       case when ns1.tipdoc = 7 then ns1.codnirstocorig else 0 end codnirstocorig, Ies.Prefixdoc||&apos; &apos;||ies.nrdoc||&apos;/&apos;||ies.datadoc BC,
                       ies.codies, ies.tipdoc
                from nirstoc nsi
                     inner join intrari1 intr1 on nsi.codintr1 = intr1.CodIntr1
                     inner join intrprodlink link on link.codintr1 = intr1.codintr1
                     inner join cmdprodmat prod on prod.codcmdprodmat = link.codliniecomanda
                     inner join iesiri1 ies1 on ies1.codcmdint1 = prod.codcomanda1
                     inner join iesiri ies on ies.codies = ies1.codies
                     inner join livr l on l.codies = ies.codies
                     inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
                     inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                     inner join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
                     left join iesprodlink ieslink on ieslink.codies1 = ies1.codies1
                     left join cmdprodmat mat on mat.codcmdprodmat = ieslink.codcmdprodmat
                     left join (select sum(cant) cant, codcmdprodmat from iesprodlink group by codcmdprodmat) LConsum on LConsum.codcmdprodmat = mat.codcmdprodmat
                where nsi.codnirstoc = aCodnirstoc and nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1
                      --and ies.datadoc &lt;= to_date(vdatastop,&apos;dd.mm.yyyy&apos;)
                union all
                select intr1.cant cantp_r, 0 cant, intr1.cant/prod.cant*nvl(mat.cant,0) cantt, intr1.codobiect produs, 0 valoare, 0, mat.codobiect material, mat.cant cantcomp, nvl(mat.pret,0) pret,
                       mat.codcmdprodmat, prod.cant cantprodusl, 0 canties1, null anlunalivr, 0 codnirstocorig, null BC, null codies, null tipdoc
                from nirstoc nsi
                     inner join intrari1 intr1 on nsi.codintr1 = intr1.CodIntr1
                     inner join intrprodlink link on link.codintr1 = intr1.codintr1
                     inner join cmdprodmat prod on prod.codcmdprodmat = link.codliniecomanda
                     inner join cmdprodmat mat on mat.codcomanda1 = prod.codcomanda1 and mat.tip = 1
                where nsi.codnirstoc = aCodnirstoc and mat.rest = mat.cant) loop

      if v_rec.cantt = 0 then
        insert into tmp_manevra_285(
          produs,
          cantprodus,
          material,
          cantmaterial,
          valmaterial,
          pretmaterial,
          cantmaterial_r,
          valmaterial_r,
          codcmdprodmat,
          codnirstoc,
          cantstorno,
          anlunalivr,
          codnirstocorig,
          bc, coddoc, tipdoc)
        values (
          p,
          cantp,
          v_Rec.Material,
          0,
          0,
          0,
          cantM_r*v_Rec.Cant/v_REc.cantp_r,
          cantM_r*v_Rec.Cant/v_REc.cantp_r * v_Rec.valoare/v_rec.cant,
          v_rec.codcmdprodmat,
          case when v_Rec.codnirstoc = aCodNirStoc then 0 else v_rec.codnirstoc end,
          case when aStorno = 1 then cantM_r*v_Rec.Cant/v_REc.cantp_r else 0 end,
          v_rec.anlunalivr,
          v_rec.codnirstocorig,
          v_rec.bc,
          v_rec.codies, v_Rec.tipdoc);
      else
        if v_rec.cant &lt;&gt; 0 then
          insert into tmp_manevra_285(
            produs,
            cantprodus,
            material,
            cantmaterial,
            valmaterial,
            pretmaterial,
            cantmaterial_r,
            valmaterial_r,
            codcmdprodmat,
            codnirstoc,
            cantstorno,
            anlunalivr,
            codnirstocorig,
            bc, coddoc, tipdoc)
          values (
            p,
            cantp,
            v_Rec.Material,
            v_rec.cant/v_Rec.canties1*cantM*v_Rec.Cant/v_rec.cantp_r,
            v_rec.cant/v_Rec.canties1*cantM*v_Rec.Cant/v_rec.cantp_r*v_rec.pret,
            v_rec.valoare/v_Rec.Cant,
            cantM_r*v_Rec.Cant/v_Rec.cantp_r,
            cantM_r*v_Rec.Cant/v_Rec.cantp_r
            * v_Rec.valoare/v_rec.cant,
            v_rec.codcmdprodmat,
            case when v_Rec.codnirstoc = aCodNirStoc then 0 else v_rec.codnirstoc end,
            case when aStorno = 1 then cantM_r*v_Rec.Cant/v_Rec.cantp_r else 0 end,
            v_Rec.anlunalivr,
            v_rec.codnirstocorig,
            v_rec.bc, v_Rec.codies, v_rec.tipdoc);
        else
          insert into tmp_manevra_285(
            produs,
            cantprodus,
            material,
            cantmaterial,
            valmaterial,
            pretmaterial,
            cantmaterial_r,
            valmaterial_r,
            codcmdprodmat,
            codnirstoc,
            cantstorno,
            anlunalivr,
            codnirstocorig,
            bc, coddoc, tipdoc)
          values (
            p,
            cantp,
            v_Rec.Material,
            cantM*v_Rec.Cant/v_Rec.cantp_r,
            cantM*v_Rec.Cant/v_rec.cantp_r*v_rec.pret,
            0,
            0,
            0,
            v_rec.codcmdprodmat,
            case when v_Rec.codnirstoc = aCodNirStoc then 0 else v_rec.codnirstoc end,
            0,
            v_Rec.anlunalivr,
            v_rec.codnirstocorig,
            v_rec.bc, v_rec.codies, v_rec.tipdoc);
        end if;
      end if;
  end loop;*/
  commit;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_analizaconsumuri;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZAPRVANZCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA6F68D53BB53E9D29802F2DDECC204BD859F8EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ANALIZAPRVANZCLI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sData       VARCHAR2(100) := &apos;To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELDATA.GetDataRef,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  vCodPart    NUMBER;
  vCodClaseP  NUMBER;
  vCodLocatie NUMBER;
  vCodSubunit NUMBER        := PKG_GLOBALS.GETSUBUNITATE;
  sCondPP     VARCHAR2(500);
  vCodBanca   NUMBER;
BEGIN
  gSuplCols := &apos;nartobj o, nart a, num u, pretm pm, nartcli ac, oferta1 ofe1, oferta ofe, promo1 pr1, promo pr, promo1 pr1d, promo prd, nmonede mon_pref, nmonede mon_ofe, nmonede mon_pr&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMOPART&apos;, &apos;PP&apos;,  &apos;PP.CODPROMOPART  = TMP.CODPROMOPART&apos;   , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMOPART&apos;, &apos;PPD&apos;, &apos;PPD.CODPROMOPART = TMP.CODPROMOPART_D&apos; , 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  SELECT a.CodAgenda, p.CodPart, Coalesce(p.CodClasa, 0)
  INTO vCodLocatie, vCodPart, vCodClaseP
  FROM nagenda a INNER JOIN npart p ON p.codpart = a.CodPart
  WHERE a.CodAgenda = PKG_LIST_SELDATA.CodExtra1;

  IF vCodClaseP = 0 THEN
    sCondPP := &apos;(Coalesce(p.tipclasep,0) = 0 AND Coalesce(pp.partener,0) IN (0, &apos;||vCodPart||&apos;))&apos;;
  ELSE
    sCondPP := &apos;( (Coalesce(p.tipclasep,0) = 0 AND Coalesce(pp.partener,0) IN (0, &apos;||vCodPart||&apos;)) OR (Coalesce(p.tipclasep,0) = 1 AND Coalesce(pp.codclasep,0) = &apos;||vCodClaseP||&apos;) )&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    Art, UM, CantMin,
    RefPret, RefMon, RefCurs,
    OfePret, OfeMon, OfeStart, OfeEnd, OfeCurs,
    Promo1Pret, Promo1Mon, Promo1Start, Promo1End, Promo1Curs,
    Promo2Disc, Promo2Start, Promo2End, Promo2ExclPromo &apos;||
    gUserFields||&apos;)
  SELECT
    o.denumire, u.den_um, tmp.cantmin,
    CASE
      WHEN COALESCE(pmpart.codpretm,0) &lt;&gt; 0 AND pmpart.moneda = 0 THEN pmpart.lei
      WHEN COALESCE(pmpart.codpretm,0) &lt;&gt; 0                       THEN pmpart.valuta
      WHEN COALESCE(pm.codpretm,0)     &lt;&gt; 0 AND pm.moneda = 0     THEN pm.lei
      WHEN COALESCE(pm.codpretm,0)     &lt;&gt; 0                       THEN pm.valuta
      ELSE 0
    END RefPret,
    mon_pref.simbol RefMon,
    curs_pref.Valoare,
    ofe1.pret OfePret, mon_ofe.simbol OfeMon, ofe.datastart OfeStart, ofe.dataend OfeEnd, curs_ofe.Valoare,
    pr1.pret Promo1Pret, mon_pr.simbol Promo1Mon, pr.datastart Promo1Start, pr.dataend Promo1End, curs_pr.Valoare,
    -ABS(Coalesce(pr1d.procdisc,0)) Promo2Disc, prd.datastart Promo2Start, prd.dataend Promo2End,
    CASE WHEN Coalesce(prd.exclaltepromo,0) = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END Promo2ExclPromo  &apos;||
    gUserAlias||&apos;
  FROM (
    SELECT
      subs2.codobiect, subs2.cantmin,
      CASE
        WHEN subs2.codoferta1 &lt;&gt; 0 THEN subs2.codoferta1
        WHEN subs2.cantmin = 1 THEN subs2.codoferta1
        ELSE Last_Value(NullIF(subs2.codoferta1,0) IGNORE NULLS) OVER (PARTITION BY subs2.codobiect ORDER BY subs2.cantmin ROWS UNBOUNDED PRECEDING)
      END codoferta1,
      CASE
        WHEN subs2.codpromo1 &lt;&gt; 0 THEN subs2.codpromo1
        WHEN subs2.cantmin = 1 THEN subs2.codpromo1
        ELSE Last_Value(NullIF(subs2.codpromo1,0) IGNORE NULLS) OVER (PARTITION BY subs2.codobiect ORDER BY subs2.cantmin ROWS UNBOUNDED PRECEDING)
      END codpromo1,
      CASE
        WHEN subs2.codpromo1_d &lt;&gt; 0 THEN subs2.codpromo1_d
        WHEN subs2.cantmin = 1 THEN subs2.codpromo1_d
        ELSE Last_Value(NullIF(subs2.codpromo1_d,0) IGNORE NULLS) OVER (PARTITION BY subs2.codobiect ORDER BY subs2.cantmin ROWS UNBOUNDED PRECEDING)
      END codpromo1_d,
      subs2.codpromopart, subs2.codpromopart_d
    FROM (
      SELECT
        subs1.codobiect, subs1.cantmin, Max(subs1.codoferta1) codoferta1,
        Max(subs1.codpromo1) codpromo1, Max(codpromopart) codpromopart,
        Max(subs1.codpromo1_d)    KEEP (Dense_Rank FIRST ORDER BY subs1.prioritar DESC, subs1.procdisc ASC) codpromo1_d,
        Max(subs1.codpromopart_d) KEEP (Dense_Rank FIRST ORDER BY subs1.prioritar DESC, subs1.procdisc ASC) codpromopart_d
      FROM (
        SELECT
          o.codobiect, 0 cantmin, 0 codoferta1, 0 codpromo1, 0 codpromopart,
          0 codpromo1_d, 0 codpromopart_d, 0 prioritar, 0 procdisc
        FROM nartobj o
        UNION ALL
        SELECT
          o1.codobiect, Coalesce(o1.cantmin, 0) cantmin, o1.codoferta1, 0 codpromo1, 0 codpromopart,
          0 codpromo1_d, 0 codpromopart_d, 0 prioritar, 0 procdisc
        FROM oferta o INNER JOIN oferta1 o1 ON o1.codoferta = o.codoferta
        WHERE o.tipdoc = 50 AND o.anulat = 0 AND o.operat = 1
          AND &apos;||sData||&apos; BETWEEN o.datastart AND o.dataend
          AND coalesce(o.partener,0) IN (0, &apos;||vCodPart||&apos;)
          AND o.subunitatea = &apos;||vCodSubunit||&apos;
        UNION ALL
        SELECT
          o.codobiect, Coalesce(p1.cant, 0) cantmin, 0 codoferta1, p1.codpromo1, pp.codpromopart,
          0 codpromo1_d, 0 codpromopart_d, 0 prioritar, 0 procdisc
        FROM promo p
          INNER JOIN promo1 p1 ON p1.codpromo = p.codpromo
          INNER JOIN nartobj o ON o.codobiect = p1.codobiect
          INNER JOIN promosub ps ON ps.codpromo = p.codpromo
          INNER JOIN promopart pp ON pp.codpromo = p.codpromo
        WHERE p.tipdoc = 56 AND p.anulat = 0 AND p.operat = 1
          AND p.demana = 0
          AND p.tippromotie = 1
          AND p.tipconditie = 1
          AND &apos;||sData||&apos; BETWEEN p.datastart AND p.dataend
          AND &apos;||sCondPP||&apos;
          AND ps.subunitatea = &apos;||vCodSubunit||&apos;
        UNION ALL
        SELECT
          o.codobiect, Coalesce(p1.cant, 0) cantmin, 0 codoferta1, 0 codpromo1, 0 codpromopart,
          p1.codpromo1 codpromo1_d, pp.codpromopart codpromopart_d, Coalesce(pp.prioritar, 0) prioritar, -Abs(Coalesce(p1.procdisc,0)) procdisc
        FROM promo p
          INNER JOIN promo1 p1 ON p1.codpromo = p.codpromo
          LEFT  JOIN nart a ON a.clasa = p1.codclasea AND p.demana = 3
          LEFT  JOIN nartobj o ON o.codobiect  = CASE WHEN p.demana = 0 THEN p1.codobiect ELSE o.codobiect END
                              AND o.codarticol = CASE WHEN p.demana = 3 THEN a.codarticol ELSE o.codarticol END
          INNER JOIN promosub ps ON ps.codpromo = p.codpromo
          INNER JOIN promopart pp ON pp.codpromo = p.codpromo
        WHERE p.tipdoc = 56 AND p.anulat = 0 AND p.operat = 1
          AND p.demana IN (0, 3, 4)
          AND p.tippromotie = 2
          --AND p.tipconditie = 1
          AND &apos;||sData||&apos; BETWEEN p.datastart AND p.dataend
          AND &apos;||sCondPP||&apos;
          AND ps.subunitatea = &apos;||vCodSubunit||&apos;
      ) subs1
      GROUP BY subs1.codobiect, subs1.cantmin
    ) subs2
  ) tmp
    LEFT JOIN nartobj o ON o.codobiect = tmp.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN num u ON u.codum = a.um
    LEFT JOIN pretm pmpart ON pmpart.codobiect = o.codobiect AND pmpart.subunitatea = &apos;||vCodSubunit||&apos; AND pmpart.codcatpret = PKG_LIST_BASE_ANALIZAPRVANZCLI.getcatpretpart(&apos;||vCodPart||&apos;)
    LEFT JOIN pretm pm ON pm.codobiect = o.codobiect AND pm.subunitatea = &apos;||vCodSubunit||&apos; AND pm.implicit = 1
    LEFT JOIN oferta1 ofe1 ON ofe1.codoferta1 = tmp.codoferta1
    LEFT JOIN oferta ofe ON ofe.codoferta = ofe1.codoferta
    LEFT JOIN promo1 pr1 ON pr1.codpromo1 = tmp.codpromo1
    LEFT JOIN promo pr ON pr.codpromo = pr1.codpromo
    LEFT JOIN promo1 pr1d ON pr1d.codpromo1 = tmp.codpromo1_d
    LEFT JOIN promo prd ON prd.codpromo = pr1d.codpromo
    LEFT JOIN nmonede mon_pref ON mon_pref.codmoneda = COALESCE(pmpart.moneda,pm.moneda,0)
    LEFT JOIN tmp_lst_curs curs_pref ON curs_pref.codmoneda = mon_pref.codmoneda
    LEFT JOIN nmonede mon_ofe ON mon_ofe.codmoneda = ofe.moneda
    LEFT JOIN tmp_lst_curs curs_ofe ON curs_ofe.codmoneda = mon_ofe.codmoneda
    LEFT JOIN nmonede mon_pr ON mon_pr.codmoneda = pr.moneda
    LEFT JOIN tmp_lst_curs curs_pr ON curs_pr.codmoneda = mon_pr.codmoneda &apos;||
    gSuplJoins;

  IF vCodBanca IS NULL THEN
    vCodBanca := pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  END IF;
  IF vCodBanca IS NULL THEN
    vCodBanca := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  END IF;

  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

function getcatpretpart(aCodPart in number) return number is
aRez number(20);
begin
  begin
    select nvl(codcategpret,0) into aRez from npart where codpart = aCodPart;
  exception when others then aRez := 0;
  end;
  return aRez;
end;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_ANALIZAPRVANZCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ANALIZASCURTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F98045D6D2ED4AD15AB92D6790324A8D820466F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ANALIZASCURTA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vAnLuna        number;
  vSub           number(20) := 0;
  vCodCmdProdMat number(20) := 0;

  vDataS       DATE;
  vDataF       DATE;

procedure SetParams(
  aCodCmdProdMat in number default 0, aAnLuna in number default 0,
  pDataS    IN VARCHAR2,
  pDataF    IN VARCHAR2,
  V_CODJOB1 IN NUMBER  DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vCodCmdProdMat := aCodCmdProdMat;
  vAnLuna        := aAnLuna;
end;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert     VARCHAR2(20000);
aPret       number(20,7);
vCodComanda number(20);
rez         number;
vDataStart  date;
vDataEnd    date;
xAnLuna     number(20);
cFiltru     varchar2(500);
BEGIN
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  vCodComanda := pkg_list_selectgestart.CodComanda;
  vDataStart  := PKG_LIST_SELECTGESTART.DataStart;
  vDataEnd    := PKG_LIST_SELECTGESTART.DataFin;

  /*if vCodCmdProdMat = 0 then
    vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  end if;*/

  select extract(year from vDataEnd) * 12 + extract(month from vDataEnd) into xAnLuna from dual;
  if vCodCmdProdMat &gt; 0 then xAnLuna := vAnLuna; end if;
  cFiltru := &apos; between to_date(&apos;&apos;&apos;||to_char(vDataStart,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||to_char(vDataEnd,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  vSub := pkg_globals.GETSUBUNITATE;
  -- updatez nirstoc1
  if vCodComanda = 0 then
    rez := pkg_pretprod.UpdateNirStoc1InLuna;
  end if;
  --pkg_list_base_analizaconsumuri.UpdatePretNirStoc1;
  commit;

  gSuplCols := &apos;num ump, num umc, pretm pm, nartobj1 mat1, nclasea cls,prodcomp pc,NARTOBJ PROD,NARTOBJ MAT, &apos; || tmpName || &apos; TMP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if vCodCmdProdMat = 0 then
    if pkg_list_selectgestart.AllGest then
      delete tmp_manevra_liste where filtru = &apos;CODGEST&apos;;
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODGEST&apos;, codgest
      from ngest;
    end if;

    /*if pkg_list_selectgestart.AllArt then
      delete tmp_manevra_liste where filtru = &apos;CODOBIECT&apos;;
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODOBIECT&apos;, codobiect
      from nartobj;
    end if;*/
  end if;

  delete tmp_manevra_intr1;
  if pkg_list_selectgestart.Serii = 1 then
    if vCodCmdProdMat = 0 then
      if vCodComanda &gt; 0 then
        insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, Seriinp, Setimananp)
        select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
               string_agg(ser.serie), to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
        from nirstoc ns
             inner join nirstoc1     ns1  on ns.codnirstoc     = ns1.codnirstoc
             inner join intrari1     i1   on ns.codintr1       = i1.codintr1
             inner join intrprodlink l    on i1.codintr1       = l.codintr1
             inner join intrari      i    on i.codintr         = i1.codintr
             inner join cmdprodmat   prod on l.codliniecomanda = prod.codcmdprodmat
             inner join comanda1     c1   on prod.codcomanda1  = c1.codcomanda1
             left  join nirser       nse  on ns.codnirstoc     = nse.codnirstoc and ns.codnirstoc = nse.codnirstoc
             left  join nserii       ser  on ser.codserie      = nse.codserie
        where i.tipdoc = 7 and c1.codcomanda = vCodComanda
              and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0
        group by i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC,I.NRDOC,I.DATADOC;
      else
        insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, Seriinp, Setimananp)
        select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
               string_agg(ser.serie), to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
        from nirstoc ns
             inner join nirstoc1          ns1     on ns.codnirstoc     = ns1.codnirstoc
             inner join intrari1          i1      on ns.codintr1       = i1.codintr1
             inner join intrprodlink      l       on i1.codintr1       = l.codintr1
             inner join cmdprodmat        prod    on l.codliniecomanda = prod.codcmdprodmat and Coalesce(prod.tip,0) = 0
             inner join intrari           i       on i.codintr         = i1.codintr
             --inner join tmp_manevra_liste tmpart on tmpart.filtru = &apos;CODOBIECT&apos; and to_number(tmpart.valoare) = i1.codobiect
             inner join tmp_manevra_liste tmpgest on tmpgest.filtru    = &apos;CODGEST&apos; and to_number(tmpgest.valoare) = i.codgestprod
             left  join nirser            nse     on ns.codnirstoc     = nse.codnirstoc and ns.codnirstoc = nse.codnirstoc
             left  join nserii            ser     on ser.codserie      = nse.codserie
        where i.tipdoc = 7 and i.datadoc between vDataStart and vDataEnd
              and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0
              and ((vSub = 1) or i.subunitatea = vSub)
        group by i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC,I.NRDOC,I.DATADOC;
      end if;
    else
      insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, seriinp, Setimananp)
      select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
             string_agg(ser.serie), to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
      from nirstoc ns
           inner join nirstoc1     ns1 on ns.codnirstoc = ns1.codnirstoc
           inner join intrari1     i1  on ns.codintr1   = i1.codintr1
           inner join intrprodlink l   on i1.codintr1   = l.codintr1
           inner join intrari      i   on i.codintr     = i1.codintr
           left join nirser        nse on ns.codnirstoc = nse.codnirstoc and ns.codnirstoc = nse.codnirstoc
           left join nserii        ser on ser.codserie  = nse.codserie
      where i.tipdoc = 7 and i.datadoc between vDataStart and vDataEnd and l.codliniecomanda = vCodCmdProdMat
            and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0
            and ((vSub = 1) or i.subunitatea = vSub);
    end if;
  else
    if vCodCmdProdMat = 0 then
      if vCodComanda &gt; 0 then
        insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, Setimananp)
        select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
               to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
        from nirstoc ns
             inner join nirstoc1     ns1  on ns.codnirstoc     = ns1.codnirstoc
             inner join intrari1     i1   on ns.codintr1       = i1.codintr1
             inner join intrprodlink l    on i1.codintr1       = l.codintr1
             inner join intrari      i    on i.codintr         = i1.codintr
             inner join cmdprodmat   prod on l.codliniecomanda = prod.codcmdprodmat
             inner join comanda1     c1   on prod.codcomanda1  = c1.codcomanda1
        where i.tipdoc = 7 and c1.codcomanda = vCodComanda
              and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0;
      else
        insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, Setimananp)
        select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
               to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
        from nirstoc ns
             inner join nirstoc1          ns1     on ns.codnirstoc = ns1.codnirstoc
             inner join intrari1          i1      on ns.codintr1   = i1.codintr1
             inner join intrprodlink      l       on i1.codintr1   = l.codintr1
             inner join cmdprodmat        prod    on l.codliniecomanda = prod.codcmdprodmat and Coalesce(prod.tip,0) = 0
             inner join intrari           i       on i.codintr = i1.codintr
             --inner join tmp_manevra_liste tmpart on tmpart.filtru = &apos;CODOBIECT&apos; and to_number(tmpart.valoare) = i1.codobiect
             inner join tmp_manevra_liste tmpgest on tmpgest.filtru = &apos;CODGEST&apos; and to_number(tmpgest.valoare) = i.codgestprod
        where i.tipdoc = 7 and i.datadoc between vDataStart and vDataEnd
              and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0
              and ((vSub = 1) or i.subunitatea = vSub);
      end if;
    else
      insert into tmp_manevra_intr1(codintr1, codobiect, codcmdprodmat, cantpredata, codnirstoc, pretpredare, NP, Setimananp)
      select i1.codintr1, i1.codobiect, l.codliniecomanda, i1.cant, ns.codnirstoc, Coalesce(ns1.pretmat,0), i.PREFIXDOC||&apos; &apos;||I.NRDOC||&apos;/&apos;||I.DATADOC,
             to_char(to_number(to_char(i.datadoc, &apos;IW&apos;)))
      from nirstoc ns
           inner join nirstoc1     ns1 on ns.codnirstoc = ns1.codnirstoc
           inner join intrari1     i1  on ns.codintr1   = i1.codintr1
           inner join intrprodlink l   on i1.codintr1   = l.codintr1
           inner join intrari      i   on i.codintr     = i1.codintr
      where i.tipdoc = 7 and i.datadoc between vDataStart and vDataEnd and l.codliniecomanda = vCodCmdProdMat
            and Coalesce(i.operat,0) = 1 and Coalesce(i.anulat,0) = 0
            and ((vSub = 1) or i.subunitatea = vSub);
    end if;
  end if;
/*
  for v_Rec in (select tmp.codnirstoc, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0) pret, ns1.tipdoc
                from tmp_manevra_intr1 tmp
                     inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codnirstoc
                     inner join nirstoc ns on ns1.codnirstoc = ns.codnirstoc
                where tmp.codnirstoc &gt; 0 and ns1.dirty = 1) loop
    aPret := pkg_list_base_analizaconsumuri.GetPretNirStoc(v_rec.codnirstoc);
    if aPret = 0 then
      update tmp_manevra_intr1 set pretpredare = v_rec.Pret where codnirstoc = v_rec.codnirstoc;
      update nirstoc1 set pretmat = v_rec.Pret, dinstoc = 1, dirty = 1 where codnirstoc = v_rec.codnirstoc;
    else
      update tmp_manevra_intr1 set pretpredare = aPret where codnirstoc = v_rec.codnirstoc;
      update nirstoc1 set pretmat = aPret, dinstoc = case when v_rec.tipdoc = 7 then 0 else 1 end, dirty = 0 where codnirstoc = v_rec.codnirstoc;
    end if;
    commit;
  end loop;
*/
  delete tmp_manevra_intr1_grupl;
  insert into tmp_manevra_intr1_grupl (codcmdprodmat, cantpredata, cantlansata, CMD, pret_ret)
  select tmp.codcmdprodmat, sum(tmp.cantpredata), Coalesce(prod.cant,0), C.PREFIXDOC||&apos; &apos;||C.NRDOC||&apos;/&apos;||C.DATADOC, Coalesce(pc.pret,0)
  from tmp_manevra_intr1 tmp
       inner join cmdprodmat prod on tmp.codcmdprodmat = prod.codcmdprodmat
       INNER JOIN COMANDA1   C1   ON PROD.CODCOMANDA1  = C1.CODCOMANDA1
       INNER JOIN COMANDA    C    ON C.CODCOMANDA      = C1.CODCOMANDA
       inner join prodcomp   pc   on c1.codreteta      = pc.codprodcomp
  group by tmp.codcmdprodmat, prod.cant, C.PREFIXDOC,C.NRDOC,C.DATADOC, PC.PRET;

  -- inserez si nepredarile
  if vCodCmdProdMat = 0 and vCodComanda = 0 then
    insert into tmp_manevra_intr1_grupl (codcmdprodmat, cantpredata, cantlansata, CMD, pret_ret)
    with ConsLuna as ( select cant, codcmdprodmat from (
      select sum(l.cant) cant, prod.codcmdprodmat
      from iesprodlink l
           inner join iesiri1           ies1 on ies1.codies1 = l.codies1
           inner join iesiri            ies  on ies1.codies  = ies.codies
           inner join cmdprodmat        mat  on mat.codcmdprodmat = l.codcmdprodmat
           inner join cmdprodmat        prod on mat.codcomanda1   = prod.codcomanda1 and Coalesce(prod.tip,0) = 0
           inner join tmp_manevra_liste tmpgest on tmpgest.filtru = &apos;CODGEST&apos; and to_number(tmpgest.valoare) = ies.codgestprod
      where ies.operat = 1 and Coalesce(ies.anulat,0) = 0 and ies.datadoc between vDataStart and vDataEnd
            and ((vSub = 1) or ies.subunitatea = vSub)
      group by prod.codcmdprodmat) where cant &gt; 0 )
    select cl.codcmdprodmat, 0, Coalesce(prod.cant,0), C.PREFIXDOC||&apos; &apos;||C.NRDOC||&apos;/&apos;||C.DATADOC, Coalesce(pc.pret,0)
    from consluna cl
         inner join cmdprodmat prod on cl.codcmdprodmat = prod.codcmdprodmat
         inner join comanda1   c1   on prod.codcomanda1 = c1.codcomanda1
         inner join comanda    c    on c.codcomanda = c1.codcomanda
         inner join prodcomp   pc   on c1.codreteta = pc.codprodcomp
    where not exists (select tmp.codcmdprodmat from tmp_manevra_intr1_grupl tmp where cl.codcmdprodmat = tmp.codcmdprodmat);
  end if;

  delete tmp_manevra_intr1_grupc;
  -- introduc consumurile directe din comanda
  if pkg_list_selectgestart.Serii = 1 then
    if vCodComanda &gt; 0 then
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, codobiectorig, CMDS, SeriiBC)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, link.codcmdprodmat , Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi, case when nm.codobiect = pmat.codobiect then pmat.codobiect end,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds,
             ser.serie
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesprodlink  link  on link.codies1       = i1.codies1
           inner join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           inner join comanda1     c1    on c1.codcomanda1     = mat.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nirser       nse   on l1.codnirser       = nse.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii       ser   on nse.codserie       = ser.codserie
           left  join prodmat      pmat  on mat.codprodmat     = pmat.codmat
           left  join normemat      nm   on nm.codnorma        = c1.codnorma and nm.indexlocal = pmat.indexlocal
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and mat.codobiect = i1.codobiect;
    else
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, codobiectorig, cmds, Seriibc)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, link.codcmdprodmat , Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi, case when nm.codobiect = pmat.codobiect then pmat.codobiect end,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds,
             ser.serie
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesprodlink  link  on link.codies1       = i1.codies1
           inner join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           inner join comanda1     c1    on c1.codcomanda1     = mat.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nirser       nse   on l1.codnirser       = nse.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii       ser   on nse.codserie       = ser.codserie
           left  join prodmat      pmat  on mat.codprodmat     = pmat.codmat
           left  join normemat      nm   on nm.codnorma        = c1.codnorma and nm.indexlocal = pmat.indexlocal
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and i.datadoc between vDataStart and vDataEnd and mat.codobiect = i1.codobiect;
    end if;
  else
    if vCodComanda &gt; 0 then
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, codobiectorig, CMDS)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, link.codcmdprodmat , Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi, case when nm.codobiect = pmat.codobiect then pmat.codobiect end,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesprodlink  link  on link.codies1       = i1.codies1
           inner join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           inner join comanda1     c1    on c1.codcomanda1     = mat.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nirser       nse   on l1.codnirser       = nse.codnirser
           left  join nserii       ser   on nse.codserie       = ser.codserie
           left  join prodmat      pmat  on mat.codprodmat     = pmat.codmat
           left  join normemat      nm   on nm.codnorma        = c1.codnorma and nm.indexlocal = pmat.indexlocal
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and mat.codobiect = i1.codobiect;
    else
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, codobiectorig, cmds)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, link.codcmdprodmat , Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi, case when nm.codobiect = pmat.codobiect then pmat.codobiect end,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesprodlink  link  on link.codies1       = i1.codies1
           inner join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           inner join comanda1     c1    on c1.codcomanda1     = mat.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join prodmat      pmat  on mat.codprodmat     = pmat.codmat
           left  join normemat      nm   on nm.codnorma        = c1.codnorma and nm.indexlocal = pmat.indexlocal
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and i.datadoc between vDataStart and vDataEnd and mat.codobiect = i1.codobiect;
    end if;
  end if;
/*
  for v_Rec in (select tmp.codnirstocconsum, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0) pret, ns1.tipdoc
               from tmp_manevra_intr1_grupc tmp
                    inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codnirstocconsum
                    inner join nirstoc ns on ns1.codnirstoc = ns.codnirstoc
               where ns1.dirty = 1 and codnirstocconsum &gt; 0 ) loop
    aPret := pkg_pretprod.GetPretNirStoc1Mat(v_rec.codnirstocconsum);
    if aPret = 0 then
      update tmp_manevra_intr1 set pretpredare = v_rec.Pret where codnirstoc = v_rec.codnirstocconsum;
      update nirstoc1 set pretmat = v_rec.Pret, dinstoc = 1, dirty = 1 where codnirstoc = v_rec.codnirstocconsum;
    else
      update tmp_manevra_intr1 set pretpredare = aPret where codnirstoc = v_rec.codnirstocconsum;
      update nirstoc1 set pretmat = aPret, dinstoc = case when v_rec.tipdoc = 7 then 0 else 1 end, dirty = 0 where codnirstoc = v_rec.codnirstocconsum;
    end if;
    commit;
  end loop;
*/
  update tmp_manevra_intr1_grupc tmpc
  set cant_mat = (select sum(t.cant) from tmp_manevra_intr1_grupc t where tmpc.codcmdprodmat_mat = t.codcmdprodmat_mat),
      cant_ret = (select Coalesce(mat.cant,0)
                  from tmp_manevra_intr1_grupc t
                       left join cmdprodmat mat on t.codcmdprodmat_mat = mat.codcmdprodmat
                  where t.codcmdprodmat_mat = tmpc.codcmdprodmat_mat and rownum = 1),
      pret_ret = (select Coalesce(m.pret,0)
                  from tmp_manevra_intr1_grupc t
                       left join cmdprodmat mat on t.codcmdprodmat_mat = mat.codcmdprodmat
                       left join prodmat m on m.codmat = mat.codprodmat
                  where t.codcmdprodmat_mat = tmpc.codcmdprodmat_mat and rownum = 1)
  where Coalesce(codcmdprodmat_mat,0) &gt; 0;

  update tmp_manevra_intr1_grupc tmpc
  set cantK = cant*cant_ret/cant_mat where Coalesce(cant_mat,0) &lt;&gt; 0;
  -- bag materialele comenzii care nu au consum
  insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                      BC, TIPLINIE, cont, codcmdprodmat_mat, cantK, pret_ret, pret_contabil, gestiune, nps, AnLuna, codcmdprodmat_semi,
                                      codobiectorig, cmds)
  select tmpl.codcmdprodmat, 0, 0, 0, 0, 0, mat.codobiect, &apos;-&apos;, 0, &apos;-&apos;, mat.codcmdprodmat, mat.cant, m.pret, 0, g.den_gest, &apos;-&apos;, 0, 0, m.codobiect, &apos;-&apos;
  from tmp_manevra_intr1_grupl tmpl
       inner join cmdprodmat prod on prod.codcmdprodmat = tmpl.codcmdprodmat
       inner join cmdprodmat mat  on mat.codcomanda1    = prod.codcomanda1 and mat.tip = 1
       inner join comanda1   c1   on prod.codcomanda1   = c1.codcomanda1
       inner join comanda    c    on c1.codcomanda      = c.codcomanda
       inner join ngest      g    on c.codgest          = g.codgest
       left  join prodmat    m    on m.codmat           = mat.codprodmat
  where not exists (select tmpc.codcmdprodmat from tmp_manevra_intr1_grupc tmpc where tmpc.codcmdprodmat_mat = mat.codcmdprodmat);

  -- introduc consumurile suplimentare
  if pkg_list_selectgestart.Serii = 1 then
    if vCodComanda &gt; 0 then
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, cmds, Seriibc)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds,
             ser.serie
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nirser       nse   on l1.codnirser       = nse.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii       ser   on nse.codserie       = ser.codserie
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join iesprodlink  link  on link.codies1       = i1.codies1
           left  join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and coalesce(mat.codobiect,0) &lt;&gt; i1.codobiect;
    else
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, cmds,seriibc)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds,
             ser.serie
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nirser       nse   on l1.codnirser       = nse.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii       ser   on nse.codserie       = ser.codserie
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join iesprodlink  link  on link.codies1       = i1.codies1
           left  join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and i.datadoc between vDataStart and vDataEnd and coalesce(mat.codobiect,0) &lt;&gt; i1.codobiect;
    end if;
  else
    if vCodComanda &gt; 0 then
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, cmds)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join iesprodlink  link  on link.codies1       = i1.codies1
           left  join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and coalesce(mat.codobiect,0) &lt;&gt; i1.codobiect;
    else
      insert into tmp_manevra_intr1_grupc(codcmdprodmat, cant, pretconsum, codnirstocconsum, coddoc, tipdoc, codobiect,
                                          BC, TIPLINIE, cont, codcmdprodmat_mat, pret_contabil, gestiune,
                                          nps, AnLuna, codcmdprodmat_semi, cmds)
      select tmp.codcmdprodmat, l1.cant, Coalesce(ns1.pretmat,0) pretconsum, ns.codnirstoc codnirstocconsum, i.codies, i.tipdoc, i1.codobiect,
             i.prefixdoc||i.seriadoc||I.NRDOC||&apos;/&apos;||to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;), NS1.TIPDOC, ioa.den_ioart, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), g.den_gest,
             case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos; &apos;||intr.NRDOC||&apos;/&apos;||intr.DATADOC else &apos;-&apos; end nps,
             case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end AnLuna,
             case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end CodCmdProdMat_Semi,
             case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos; &apos;||cs.NRDOC||&apos;/&apos;||cs.DATADOC else &apos;-&apos; end cmds
      from tmp_manevra_intr1_grupl tmp
           inner join cmdprodmat   prod  on prod.codcmdprodmat = tmp.codcmdprodmat
           inner join iesiri1      i1    on i1.codcmdint1      = prod.codcomanda1
           inner join iesiri       i     on i.codies           = i1.codies
           inner join livr         l     on i.codies           = l.codies
           inner join ngest        g     on g.codgest          = i.codgestprod
           inner join livr1        l1    on l1.codies1         = i1.codies1 and l.codlivr = l1.codlivr
           inner join nirstoc      ns    on l1.codnirstoc      = ns.codnirstoc
           inner join nirstoc1     ns1   on ns.codnirstoc      = ns1.codnirstoc
           inner join nirstoc      nsi   on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart        ioa   on ioa.codioart       = ns.codioart
           left  join nir                on nsi.codnir         = nir.codnir
           left  join intrari      intr  on nir.codintr        = intr.codintr and intr.tipdoc = 7
           left  join intrari1     intr1 on intr1.codintr1     = nsi.codintr1
           left  join intrprodlink intrl on intrl.codintr1     = intr1.codintr1
           left  join iesprodlink  link  on link.codies1       = i1.codies1
           left  join cmdprodmat   mat   on mat.codcmdprodmat  = link.codcmdprodmat
           left  join comanda1     cs1   on intr1.codcmdint1   = cs1.codcomanda1
           left  join comanda      cs    on cs1.codcomanda     = cs.codcomanda
      where i.operat = 1 and Coalesce(i.anulat,0) = 0 and i.datadoc between vDataStart and vDataEnd and coalesce(mat.codobiect,0) &lt;&gt; i1.codobiect;
    end if;
  end if;
/*
  for v_Rec in (select tmp.codnirstocconsum, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0) pret, ns1.tipdoc
               from tmp_manevra_intr1_grupc tmp
                    inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codnirstocconsum
                    inner join nirstoc ns on ns1.codnirstoc = ns.codnirstoc
               where ns1.dirty = 1 and codnirstocconsum &gt; 0 ) loop
    aPret := NS1.PretMat; --pkg_pretprod.GetPretNirStoc1Mat(v_rec.codnirstocconsum);
    if aPret = 0 then
      update tmp_manevra_intr1 set pretpredare = v_rec.Pret where codnirstoc = v_rec.codnirstocconsum;
      update nirstoc1 set pretmat = v_rec.Pret, dinstoc = 1, dirty = 1 where codnirstoc = v_rec.codnirstocconsum;
    else
      update tmp_manevra_intr1 set pretpredare = aPret where codnirstoc = v_rec.codnirstocconsum;
      update nirstoc1 set pretmat = aPret, dinstoc = case when v_rec.tipdoc = 7 then 0 else 1 end, dirty = 0 where codnirstoc = v_rec.codnirstocconsum;
    end if;
    commit;
  end loop;
*/
  update tmp_manevra_intr1_grupc set val_contabila = pret_contabil * cant;

  --delete m_intr1;
  --delete m_intr1_grupl;
  --delete m_intr1_grupc;
  --insert into m_intr1 select * from tmp_manevra_intr1;
  --insert into m_intr1_grupl select * from tmp_manevra_intr1_grupl;
  --insert into m_intr1_grupc select * from tmp_manevra_intr1_grupc;


  if pkg_list_selectgestart.Serii = 1 then
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;
     (
        Nav_coddoc, nav_tipdoc,
        produs, cantprodus, cantprodusl, pretprodus,
        material, cantmaterial, pretmaterial, valmaterial,
        cantmaterial_r, pretmaterial_r, valmaterial_r,
        tipcontabil, cantnpout, bc, cmd, NP, pretrez, pret_contabil, val_contabila,
        gestiune, ump, um, nps, AnLuna, CodCmdProdMat, DinStoc, TipContabilImp, matorig, cmds,SeriiNp, SeriiBC, SetimanaNP,
        D1, D2, D3, CantUM1 &apos;||gUserFields||&apos;)
      select
        GC.CODDOC, GC.TIPDOC,
        PROD.DENUMIRE, I1.CANTPREDATA, GL.CANTLANSATA, gl.pret_ret,
        MAT.DENUMIRE, Coalesce(gc.cantK,0), Coalesce(gc.pret_ret,0), Coalesce(gc.cantK,0)*Coalesce(gc.pret_ret,0),
        I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT, GC.PRETCONSUM, I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT*GC.PRETCONSUM,
        gc.cont, 0, GC.BC, GL.CMD, I1.NP, I1.PRETPREDARE, GC.pret_contabil, I1.CANTPREDATA/GL.CANTPREDATA * Coalesce(GC.val_contabila,0),
        gc.gestiune, UMP.DEN_UM, UMC.DEN_UM, GC.nps, GC.AnLuna, GC.codcmdprodmat_semi,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, mato.denumire, GC.cmds,
        I1.SeriiNP, gc.seriibc, I1.SetimanaNP,
        nsl.d1, nsl.d2, nsl.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(nsl.D1, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT/nsl.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0) * Coalesce(nsl.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0)
              END,7) &apos;||gUserAlias||&apos;
      FROM tmp_manevra_intr1 I1
           INNER JOIN tmp_manevra_intr1_grupl GL     ON GL.CODCMDPRODMAT = I1.CODCMDPRODMAT
           INNER JOIN tmp_manevra_intr1_grupc GC     ON GC.CODCMDPRODMAT = GL.CODCMDPRODMAT
           INNER JOIN NARTOBJ                 PROD   ON I1.CODOBIECT     = PROD.CODOBIECT
           INNER JOIN NART                    APROD  ON APROD.CODARTICOL = PROD.CODARTICOL
           INNER JOIN NUM                     UMP    ON UMP.CODUM        = APROD.UM
           INNER JOIN NARTOBJ                 MAT    ON GC.CODOBIECT     = MAT.CODOBIECT
           INNER JOIN NART                    AMAT   ON AMAT.CODARTICOL  = MAT.CODARTICOL
           INNER JOIN NUM                     UMC    ON UMC.CODUM        = AMAT.UM
           inner join cmdprodmat              p      on p.codcmdprodmat  = gl.codcmdprodmat
           inner join comanda1                c1     on p.codcomanda1    = c1.codcomanda1
           inner join prodcomp                pc     on pc.codprodcomp   = c1.codreteta
           left  join cmdprodmat              cmdmat on cmdmat.codcmdprodmat    = gc.codcmdprodmat_mat
           LEFT  JOIN NARTOBJ                 MATO   ON Coalesce(GC.CODOBIECTORIG,0) = MATO.CODOBIECT
           LEFT  join nirstoc1                ns1    on gc.codnirstocconsum     = ns1.codnirstoc
           left  join nirstoc                 nsl    on nsl.codnirstoc  = gc.codnirstocconsum
           LEFT  JOIN NARTIMPLICITE           AIMP   ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP              OIMP   ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART                   IOAIMP ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA                 CLS    ON AMAT.CLASA      = CLS.CODCLASEA
           LEFT  JOIN pretm                   pm     ON pm.codobiect    = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1                mat1   ON mat1.CodObiect  = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      UNION ALL
      SELECT
        gc.coddoc, gc.tipdoc,
        prod.denumire, 0, GL.cantlansata, gl.pret_ret,
        mat.denumire, Coalesce(gc.cantK,0), Coalesce(gc.pret_ret,0), Coalesce(gc.cantK,0)*Coalesce(gc.pret_ret,0),
        GC.CANT, GC.PRETCONSUM, GC.CANT*GC.PRETCONSUM,
        gc.cont, 0, GC.BC, GL.CMD, &apos;&apos;-&apos;&apos;, 0, GC.pret_contabil, Coalesce(GC.val_contabila,0),
        gc.gestiune, UMP.DEN_UM, UMC.DEN_UM, gc.nps, GC.AnLuna, GC.codcmdprodmat_semi,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, mato.denumire, GC.cmds,
        &apos;&apos; &apos;&apos;, gc.seriibc, &apos;&apos; &apos;&apos; SetimanaNP,
        nsl.d1, nsl.d2, nsl.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(nsl.D1, 0) &lt;&gt; 0 THEN GC.CANT/nsl.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) &lt;&gt; 0 THEN GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0) &lt;&gt; 0 THEN GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0) * Coalesce(nsl.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN GC.CANT * Coalesce(nsl.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0)
              END,7) &apos;||gUserAlias||&apos;
      from tmp_manevra_intr1_grupc GC
           INNER JOIN tmp_manevra_intr1_grupl GL     ON GL.CODCMDPRODMAT = gc.CODCMDPRODMAT
           inner join cmdprodmat              p      on p.codcmdprodmat  = gl.codcmdprodmat
           inner join comanda1                c1     on p.codcomanda1    = c1.codcomanda1
           inner join prodcomp                pc     on pc.codprodcomp   = c1.codreteta
           INNER JOIN NARTOBJ                 PROD   ON p.CODOBIECT      = PROD.CODOBIECT
           INNER JOIN NART                    APROD  ON APROD.CODARTICOL = PROD.CODARTICOL
           INNER JOIN NUM                     UMP    ON UMP.CODUM        = APROD.UM
           INNER JOIN NARTOBJ                 MAT    ON GC.CODOBIECT     = MAT.CODOBIECT
           INNER JOIN NART                    AMAT   ON AMAT.CODARTICOL  = MAT.CODARTICOL
           INNER JOIN NUM                     UMC    ON UMC.CODUM        = AMAT.UM
           left  join cmdprodmat              cmdmat on cmdmat.codcmdprodmat    = gc.codcmdprodmat_mat
           LEFT  JOIN NARTOBJ                 MATO   ON Coalesce(GC.CODOBIECTORIG,0) = MATO.CODOBIECT
           LEFT  join nirstoc1                ns1    on gc.codnirstocconsum     = ns1.codnirstoc
           left  join nirstoc                 nsl    on nsl.codnirstoc  = gc.codnirstocconsum
           LEFT  JOIN NARTIMPLICITE           AIMP   ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP              OIMP   ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART                   IOAIMP ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA                 CLS    ON AMAT.CLASA      = CLS.CODCLASEA
           LEFT  JOIN pretm                   pm     ON pm.codobiect    = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1                mat1   ON mat1.CodObiect  = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where Coalesce(GL.Cantpredata,0) = 0&apos;;
    if vCodCmdProdMat = 0 and vCodComanda = 0 then
      sInsert := sInsert||&apos;
      UNION ALL
      SELECT
        i.codies, i.tipdoc,
        &apos;&apos;-&apos;&apos;, 0, 0, 0,
        mat.denumire, 0, 0, 0,
        l1.cant, Coalesce(ns1.pretmat,0), l1.cant*Coalesce(ns1.pretmat,0),
        ioa.den_ioart,0, i.prefixdoc||i.seriadoc||I.NRDOC||&apos;&apos;/&apos;&apos;||to_char(I.DATADOC, &apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;&apos;-&apos;&apos;, &apos;&apos;-&apos;&apos;, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), l1.cant * (Coalesce(ns.pret,0) - Coalesce(ns.adaos,0)),
        g.DEN_GEST, &apos;&apos;-&apos;&apos;, UMC.DEN_UM, case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos;&apos; &apos;&apos;||intr.NRDOC||&apos;&apos;/&apos;&apos;||intr.DATADOC else &apos;&apos;-&apos;&apos; end,
        case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end,
        case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, &apos;&apos;... nedefinit ...&apos;&apos;,
        case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos;&apos; &apos;&apos;||cs.NRDOC||&apos;&apos;/&apos;&apos;||cs.DATADOC else &apos;&apos;-&apos;&apos; end,
        &apos;&apos; &apos;&apos;, ser.serie, &apos;&apos; &apos;&apos; SetimanaNP,
        ns.d1, ns.d2, ns.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(ns.D1, 0) &lt;&gt; 0 THEN l1.cant/ns.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0) * Coalesce(ns.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN l1.CANT * Coalesce(ns.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0)
              END,7) &apos;||gUserAlias||&apos;
      from iesiri i
           inner join livr              l       on i.codies = l.codies
           inner join iesiri1           i1      on i.codies = i1.codies and Coalesce(i1.codcmdint1,0) = 0
           INNER JOIN NARTOBJ           MAT     ON i1.CODOBIECT    = MAT.CODOBIECT
           INNER JOIN NART              AMAT    ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM               UMC     ON UMC.CODUM = AMAT.UM
           INNER JOIN NUM               UMP     ON Coalesce(I1.CODCMDINT1,0) = UMP.CODUM
           inner join livr1             l1      on l1.codies1    = i1.codies1 and l1.codlivr = l.codlivr
           inner join nirstoc           ns      on l1.codnirstoc = ns.codnirstoc
           inner join nirstoc1          ns1     on ns.codnirstoc = ns1.codnirstoc
           inner join nirstoc           nsi     on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart             ioa     on ioa.codioart    = ns.codioart
           INNER JOIN NGEST             G       ON I.CODGESTPROD   = G.CODGEST
           inner join tmp_manevra_liste tmpgest on tmpgest.filtru  = &apos;&apos;CODGEST&apos;&apos; and to_number(tmpgest.valoare) = i.codgestprod
           LEFT  JOIN NARTOBJ           PROD    ON PROD.CODOBIECT  = MAT.CODOBIECT - MAT.CODOBIECT
           left  join nirser            nse     on nse.codnirser   = l1.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii            ser     on nse.codserie    = ser.codserie
           left  join comanda1          c1      on c1.codcomanda1  = i1.codcmdint1
           left  join prodcomp          pc      on pc.codprodcomp  = c1.codreteta
           LEFT  JOIN NARTIMPLICITE     AIMP    ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP        OIMP    ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART             IOAIMP  ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA           CLS     ON AMAT.CLASA  = CLS.CODCLASEA
           left  join nir                       on nsi.codnir  = nir.codnir
           left  join intrari           intr    on nir.codintr = intr.codintr and intr.tipdoc = 7
           left  join intrari1          intr1   on intr1.codintr1   = nsi.codintr1 and intr1.codintr = intr.codintr
           left  join comanda1          cs1     on intr1.codcmdint1 = cs1.codcomanda1
           left  join comanda           cs      on cs1.codcomanda   = cs.codcomanda
           left  join intrprodlink      intrl   on intrl.codintr1   = intr1.codintr1
           LEFT  JOIN pretm             pm      ON pm.codobiect     = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1          mat1    ON mat1.CodObiect   = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where i.tipdoc = 24 and i.operat = 1 and Coalesce(i.anulat,0) = 0&apos;;
      if vCodComanda = 0 then
        sInsert := sInsert ||&apos; and i.datadoc&apos;||cFiltru;
      end if;
        sInsert := sInsert ||&apos;
           and ((&apos;||vSub||&apos; = 1) or i.subunitatea = &apos;||vSub||&apos;)&apos;||&apos;
      UNION ALL
      SELECT
        i.codies, i.tipdoc,
        &apos;&apos;-&apos;&apos;, 0, 0, 0,
        mat.denumire, 0, 0, 0,
        l1.cant, Coalesce(ns1.pretmat,0), l1.cant*Coalesce(ns1.pretmat,0),
        ioa.den_ioart,0, i.prefixdoc||i.seriadoc||I.NRDOC||&apos;&apos;/&apos;&apos;||to_char(I.DATADOC, &apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;&apos;-&apos;&apos;, &apos;&apos;-&apos;&apos;, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), l1.cant * (Coalesce(ns.pret,0) - Coalesce(ns.adaos,0)),
        g.DEN_GEST, &apos;&apos;-&apos;&apos;, UMC.DEN_UM, case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos;&apos; &apos;&apos;||intr.NRDOC||&apos;&apos;/&apos;&apos;||intr.DATADOC else &apos;&apos;-&apos;&apos; end,
        case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end,
        case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, &apos;&apos;... nedefinit ...&apos;&apos;,
        case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos;&apos; &apos;&apos;||cs.NRDOC||&apos;&apos;/&apos;&apos;||cs.DATADOC else &apos;&apos;-&apos;&apos; end,
        &apos;&apos; &apos;&apos;, ser.serie, (select string_agg(to_char(to_number(to_char(ii.datadoc, &apos;&apos;iw&apos;&apos;))))
                           from intrari ii
                                inner join intrari1 ii1 on ii.codintr = ii1.codintr
                           where ii1.codcmdint1 = c1.codcomanda1 and ii1.codobiect = c1.codobiect ),
        ns.d1, ns.d2, ns.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(ns.D1, 0) &lt;&gt; 0 THEN l1.cant/ns.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0) * Coalesce(ns.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN l1.CANT * Coalesce(ns.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0)
              END,7)  &apos;||gUserAlias||&apos;
      from iesiri i
           inner join livr              l       on i.codies = l.codies
           inner join iesiri1           i1      on i.codies = i1.codies and Coalesce(i1.codcmdint1,0) &gt; 0
           inner join cmdprodmat        CMDprod on CMDprod.codcomanda1 = i1.codcmdint1 and Coalesce(CMDprod.tip,0) = 0
           inner join comanda1          c1      on CMDprod.codcomanda1 = c1.codcomanda1
           inner join prodcomp          pc      on pc.codprodcomp = c1.codreteta
           INNER JOIN NARTOBJ           MAT     ON i1.CODOBIECT = MAT.CODOBIECT
           INNER JOIN NART              AMAT    ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM               UMC     ON UMC.CODUM = AMAT.UM
           INNER JOIN NUM               UMP     ON Coalesce(CMDPROD.TIP,0) = UMP.CODUM
           inner join livr1             l1      on l1.codies1    = i1.codies1 and l1.codlivr = l.codlivr
           inner join nirstoc           ns      on l1.codnirstoc = ns.codnirstoc
           inner join nirstoc1          ns1     on ns.codnirstoc = ns1.codnirstoc
           inner join nirstoc           nsi     on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart             ioa     on ioa.codioart  = ns.codioart
           INNER JOIN NGEST             G       ON I.CODGESTPROD = G.CODGEST
           inner join tmp_manevra_liste tmpgest on tmpgest.filtru  = &apos;&apos;CODGEST&apos;&apos; and to_number(tmpgest.valoare) = i.codgestprod
           INNER JOIN NARTOBJ           PROD    ON PROD.CODOBIECT  = C1.CODOBIECT
           left  join nirser            nse     on nse.codnirser   = l1.codnirser and ns.codnirstoc = nse.codnirstoc
           left  join nserii            ser     on nse.codserie    = ser.codserie
           LEFT  JOIN NARTIMPLICITE     AIMP    ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP        OIMP    ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART             IOAIMP  ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA           CLS     ON AMAT.CLASA  = CLS.CODCLASEA
           left  join nir                       on nsi.codnir  = nir.codnir
           left  join intrari           intr    on nir.codintr = intr.codintr and intr.tipdoc = 7
           left  join intrari1          intr1   on intr1.codintr1   = nsi.codintr1 and intr1.codintr = intr.codintr
           left  join comanda1          cs1     on intr1.codcmdint1 = cs1.codcomanda1
           left  join comanda           cs      on cs1.codcomanda   = cs.codcomanda
           left  join intrprodlink      intrl   on intrl.codintr1   = intr1.codintr1
           LEFT  JOIN pretm             pm      ON pm.codobiect     = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1          mat1    ON mat1.CodObiect   = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where i.tipdoc = 24 and i.operat = 1 and Coalesce(i.anulat,0) = 0&apos;;
      if vCodComanda = 0 then
        sInsert := sInsert||&apos; and i.datadoc&apos;||cFiltru;
      end if;
        sInsert := sInsert||&apos;
           and ((&apos;||vSub||&apos; = 1) or i.subunitatea = &apos;||vSub||&apos;)
           and not exists (select tmp.codcmdprodmat from tmp_manevra_intr1_grupl tmp where tmp.codcmdprodmat = CMDprod.codcmdprodmat) &apos;;
    end if;
  else
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;
     (
        Nav_coddoc, nav_tipdoc,
        produs, cantprodus, cantprodusl, pretprodus,
        material, cantmaterial, pretmaterial, valmaterial,
        cantmaterial_r, pretmaterial_r, valmaterial_r,
        tipcontabil, cantnpout, bc, cmd, NP, pretrez, pret_contabil, val_contabila,
        gestiune, ump, um, nps, AnLuna, CodCmdProdMat, DinStoc, TipContabilImp, matorig, cmds, SetimanaNP,
        D1, D2, D3, CantUM1  &apos;||gUserFields||&apos;)
      select
        GC.CODDOC, GC.TIPDOC,
        PROD.DENUMIRE, I1.CANTPREDATA, GL.CANTLANSATA, gl.pret_ret,
        MAT.DENUMIRE, Coalesce(gc.cantK,0), Coalesce(gc.pret_ret,0), Coalesce(gc.cantK,0)*Coalesce(gc.pret_ret,0),
        I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT, GC.PRETCONSUM, I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT*GC.PRETCONSUM,
        gc.cont, 0, GC.BC, GL.CMD, I1.NP, I1.PRETPREDARE, GC.pret_contabil, I1.CANTPREDATA/GL.CANTPREDATA * Coalesce(GC.val_contabila,0),
        gc.gestiune, UMP.DEN_UM, UMC.DEN_UM, GC.nps, GC.AnLuna, GC.codcmdprodmat_semi,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, mato.denumire, GC.cmds, i1.SetimanaNP,
        nsl.d1, nsl.d2, nsl.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(nsl.D1, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT/nsl.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0) &lt;&gt; 0 THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT / (Coalesce(nsl.D1,0) * Coalesce(nsl.D2,0) * Coalesce(nsl.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN I1.CANTPREDATA/GL.CANTPREDATA*GC.CANT * Coalesce(nsl.D1, 0) * Coalesce(nsl.D2, 0) * Coalesce(nsl.D3, 0)
              END,7)  &apos;||gUserAlias||&apos;
      FROM tmp_manevra_intr1 I1
           INNER JOIN tmp_manevra_intr1_grupl GL     ON GL.CODCMDPRODMAT = I1.CODCMDPRODMAT
           INNER JOIN tmp_manevra_intr1_grupc GC     ON GC.CODCMDPRODMAT = GL.CODCMDPRODMAT
           INNER JOIN NARTOBJ                 PROD   ON I1.CODOBIECT = PROD.CODOBIECT
           INNER JOIN NART                    APROD  ON APROD.CODARTICOL = PROD.CODARTICOL
           INNER JOIN NUM                     UMP    ON UMP.CODUM = APROD.UM
           INNER JOIN NARTOBJ                 MAT    ON GC.CODOBIECT = MAT.CODOBIECT
           INNER JOIN NART                    AMAT   ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM                     UMC    ON UMC.CODUM = AMAT.UM
           inner join cmdprodmat              p      on p.codcmdprodmat = gl.codcmdprodmat
           inner join comanda1                c1     on p.codcomanda1   = c1.codcomanda1
           inner join prodcomp                pc     on pc.codprodcomp  = c1.codreteta
           left  join cmdprodmat              cmdmat on cmdmat.codcmdprodmat = gc.codcmdprodmat_mat
           LEFT  JOIN NARTOBJ                 MATO   ON Coalesce(GC.CODOBIECTORIG,0) = MATO.CODOBIECT
           LEFT  join nirstoc1                ns1    on gc.codnirstocconsum = ns1.codnirstoc
           left  join nirstoc                 nsl    on nsl.codnirstoc  = gc.codnirstocconsum
           LEFT  JOIN NARTIMPLICITE           AIMP   ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP              OIMP   ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART                   IOAIMP ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA                 CLS    ON AMAT.CLASA      = CLS.CODCLASEA
           LEFT  JOIN pretm                   pm     ON pm.codobiect    = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1                mat1   ON mat1.CodObiect  = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      UNION ALL
      SELECT
        gc.coddoc, gc.tipdoc,
        prod.denumire, 0, GL.cantlansata, gl.pret_ret,
        mat.denumire, Coalesce(gc.cantK,0), Coalesce(gc.pret_ret,0), Coalesce(gc.cantK,0)*Coalesce(gc.pret_ret,0),
        GC.CANT, GC.PRETCONSUM, GC.CANT*GC.PRETCONSUM,
        gc.cont, 0, GC.BC, GL.CMD, &apos;&apos;-&apos;&apos;, 0, GC.pret_contabil, Coalesce(GC.val_contabila,0),
        gc.gestiune, UMP.DEN_UM, UMC.DEN_UM, gc.nps, GC.AnLuna, GC.codcmdprodmat_semi,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, mato.denumire, GC.cmds, &apos;&apos; &apos;&apos; SetimanaNP,
        nsl.d1, nsl.d2, nsl.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(nsl.d1, 0) &lt;&gt; 0 THEN GC.CANT/nsl.d1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(nsl.d1, 0) * Coalesce(nsl.d2, 0) &lt;&gt; 0 THEN GC.CANT / (Coalesce(nsl.d1,0) * Coalesce(nsl.d2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(nsl.d1, 0) * Coalesce(nsl.d2, 0) * Coalesce(nsl.d3, 0) &lt;&gt; 0 THEN GC.CANT / (Coalesce(nsl.d1,0) * Coalesce(nsl.d2,0) * Coalesce(nsl.d3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN GC.CANT * Coalesce(nsl.d1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN GC.CANT * Coalesce(nsl.d1, 0) * Coalesce(nsl.d2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN GC.CANT * Coalesce(nsl.d1, 0) * Coalesce(nsl.d2, 0) * Coalesce(nsl.d3, 0)
              END,7)  &apos;||gUserAlias||&apos;
      from tmp_manevra_intr1_grupc GC
           INNER JOIN tmp_manevra_intr1_grupl GL     ON GL.CODCMDPRODMAT = gc.CODCMDPRODMAT
           inner join cmdprodmat              p      on p.codcmdprodmat  = gl.codcmdprodmat
           inner join comanda1                c1     on p.codcomanda1  = c1.codcomanda1
           inner join prodcomp                pc     on pc.codprodcomp = c1.codreteta
           INNER JOIN NARTOBJ                 PROD   ON p.CODOBIECT = PROD.CODOBIECT
           INNER JOIN NART                    APROD  ON APROD.CODARTICOL = PROD.CODARTICOL
           INNER JOIN NUM                     UMP    ON UMP.CODUM = APROD.UM
           INNER JOIN NARTOBJ                 MAT    ON GC.CODOBIECT = MAT.CODOBIECT
           INNER JOIN NART                    AMAT   ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM                     UMC    ON UMC.CODUM = AMAT.UM
           left  join cmdprodmat              cmdmat on cmdmat.codcmdprodmat = gc.codcmdprodmat_mat
           LEFT  JOIN NARTOBJ                 MATO   ON Coalesce(GC.CODOBIECTORIG,0) = MATO.CODOBIECT
           LEFT  join nirstoc1                ns1    on gc.codnirstocconsum = ns1.codnirstoc
           left  join nirstoc                 nsl    on nsl.codnirstoc  = gc.codnirstocconsum
           LEFT  JOIN NARTIMPLICITE           AIMP   ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP              OIMP   ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART                   IOAIMP ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA                 CLS    ON AMAT.CLASA      = CLS.CODCLASEA
           LEFT  JOIN pretm                   pm     ON pm.codobiect    = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1                mat1   ON mat1.CodObiect  = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where Coalesce(GL.Cantpredata,0) = 0&apos;;
    if vCodCmdProdMat = 0 and vCodComanda = 0 then
      sInsert := sInsert||&apos;
      UNION ALL
      SELECT
        i.codies, i.tipdoc,
        &apos;&apos;-&apos;&apos;, 0, 0, 0,
        mat.denumire, 0, 0, 0,
        l1.cant, Coalesce(ns1.pretmat,0), l1.cant*Coalesce(ns1.pretmat,0),
        ioa.den_ioart,0, i.prefixdoc||i.seriadoc||I.NRDOC||&apos;&apos;/&apos;&apos;||to_char(I.DATADOC, &apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;&apos;-&apos;&apos;, &apos;&apos;-&apos;&apos;, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), l1.cant * (Coalesce(ns.pret,0) - Coalesce(ns.adaos,0)),
        g.DEN_GEST, &apos;&apos;-&apos;&apos;, UMC.DEN_UM, case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos;&apos; &apos;&apos;||intr.NRDOC||&apos;&apos;/&apos;&apos;||intr.DATADOC else &apos;&apos;-&apos;&apos; end,
        case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end,
        case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, &apos;&apos;... nedefinit ...&apos;&apos;,
        case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos;&apos; &apos;&apos;||cs.NRDOC||&apos;&apos;/&apos;&apos;||cs.DATADOC else &apos;&apos;-&apos;&apos; end, &apos;&apos; &apos;&apos; SetimanaNP,
        ns.d1, ns.d2, ns.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(ns.D1, 0) &lt;&gt; 0 THEN l1.cant/ns.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0) * Coalesce(ns.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN l1.CANT * Coalesce(ns.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0)
              END,7)  &apos;||gUserAlias||&apos;
      from iesiri i
           inner join livr              l       on i.codies = l.codies
           inner join iesiri1           i1      on i.codies = i1.codies and Coalesce(i1.codcmdint1,0) = 0
           INNER JOIN NARTOBJ           MAT     ON i1.CODOBIECT = MAT.CODOBIECT
           INNER JOIN NART              AMAT    ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM               UMC     ON UMC.CODUM = AMAT.UM
           INNER JOIN NUM               UMP     ON Coalesce(I1.CODCMDINT1,0) = UMP.CODUM
           inner join livr1             l1      on l1.codies1    = i1.codies1 and l1.codlivr = l.codlivr
           inner join nirstoc           ns      on l1.codnirstoc = ns.codnirstoc
           inner join nirstoc1          ns1     on ns.codnirstoc = ns1.codnirstoc
           inner join nirstoc           nsi     on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart             ioa     on ioa.codioart   = ns.codioart
           INNER JOIN NGEST             G       ON I.CODGESTPROD  = G.CODGEST
           inner join tmp_manevra_liste tmpgest on tmpgest.filtru = &apos;&apos;CODGEST&apos;&apos; and to_number(tmpgest.valoare) = i.codgestprod
           LEFT  JOIN NARTOBJ           PROD    ON MAT.CODOBIECT - MAT.CODOBIECT = PROD.CODOBIECT
           left  join comanda1          c1      on c1.codcomanda1  = i1.codcmdint1
           left  join prodcomp          pc      on pc.codprodcomp  = c1.codreteta
           LEFT  JOIN NARTIMPLICITE     AIMP    ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP        OIMP    ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART             IOAIMP  ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA           CLS     ON AMAT.CLASA  = CLS.CODCLASEA
           left  join nir                       on nsi.codnir  = nir.codnir
           left  join intrari           intr    on nir.codintr = intr.codintr and intr.tipdoc = 7
           left  join intrari1          intr1   on intr1.codintr1   = nsi.codintr1
           left  join comanda1          cs1     on intr1.codcmdint1 = cs1.codcomanda1
           left  join comanda           cs      on cs1.codcomanda   = cs.codcomanda
           left  join intrprodlink      intrl   on intrl.codintr1   = intr1.codintr1
           LEFT  JOIN pretm             pm      ON pm.codobiect     = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1          mat1    ON mat1.CodObiect   = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where i.tipdoc = 24 and i.operat = 1 and Coalesce(i.anulat,0) = 0&apos;;
      if vCodComanda = 0 then
        sInsert := sInsert ||&apos; and i.datadoc&apos;||cFiltru;
      end if;
        sInsert := sInsert ||&apos;
           and ((&apos;||vSub||&apos; = 1) or i.subunitatea = &apos;||vSub||&apos;)&apos;||&apos;
      UNION ALL
      SELECT
        i.codies, i.tipdoc,
        &apos;&apos;-&apos;&apos;, 0, 0, 0,
        mat.denumire, 0, 0, 0,
        l1.cant, Coalesce(ns1.pretmat,0), l1.cant*Coalesce(ns1.pretmat,0),
        ioa.den_ioart,0, i.prefixdoc||i.seriadoc||I.NRDOC||&apos;&apos;/&apos;&apos;||to_char(I.DATADOC, &apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;&apos;-&apos;&apos;, &apos;&apos;-&apos;&apos;, 0, Coalesce(ns.pret,0) - Coalesce(ns.adaos,0), l1.cant * (Coalesce(ns.pret,0) - Coalesce(ns.adaos,0)),
        g.DEN_GEST, &apos;&apos;-&apos;&apos;, UMC.DEN_UM, case when intr.codintr &gt; 0 then intr.PREFIXDOC||&apos;&apos; &apos;&apos;||intr.NRDOC||&apos;&apos;/&apos;&apos;||intr.DATADOC else &apos;&apos;-&apos;&apos; end,
        case when intr.codintr &gt; 0 then intr.An*12+intr.Luna else 0 end,
        case when intr.codintr &gt; 0 then intrl.codliniecomanda else 0 end,
        case when Coalesce(ns1.dinstoc,0) = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end, IOAIMP.DEN_IOART, &apos;&apos;... nedefinit ...&apos;&apos;,
        case when cs.codcomanda &gt; 0 then cs.PREFIXDOC||&apos;&apos; &apos;&apos;||cs.NRDOC||&apos;&apos;/&apos;&apos;||cs.DATADOC else &apos;&apos;-&apos;&apos; end,
        (select string_agg(to_char(to_number(to_char(ii.datadoc, &apos;&apos;iw&apos;&apos;))))
         from intrari ii
              inner join intrari1 ii1 on ii.codintr = ii1.codintr
         where ii1.codcmdint1 = c1.codcomanda1 and ii1.codobiect = c1.codobiect ),
        ns.d1, ns.d2, ns.d3,
        round(CASE
                WHEN amat.RELATIEUM1 IN (1, 7) AND Coalesce(ns.D1, 0) &lt;&gt; 0 THEN l1.cant/ns.D1
                WHEN amat.RELATIEUM1 IN (2, 8) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0))
                WHEN amat.RELATIEUM1 IN (3, 9) AND Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0) &lt;&gt; 0 THEN l1.CANT / (Coalesce(ns.D1,0) * Coalesce(ns.D2,0) * Coalesce(ns.D3,0))
                WHEN amat.RELATIEUM1 IN (4, 10) THEN l1.CANT * Coalesce(ns.D1,0)
                WHEN amat.RELATIEUM1 IN (5, 11) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0)
                WHEN amat.RELATIEUM1 IN (6, 12) THEN l1.CANT * Coalesce(ns.D1, 0) * Coalesce(ns.D2, 0) * Coalesce(ns.D3, 0)
              END,7)  &apos;||gUserAlias||&apos;
      from iesiri i
           inner join livr              l       on i.codies = l.codies
           inner join iesiri1           i1      on i.codies = i1.codies and Coalesce(i1.codcmdint1,0) &gt; 0
           inner join cmdprodmat        CMDprod on CMDprod.codcomanda1 = i1.codcmdint1 and Coalesce(CMDprod.tip,0) = 0
           inner join comanda1          c1      on CMDprod.codcomanda1 = c1.codcomanda1
           inner join prodcomp          pc      on pc.codprodcomp  = c1.codreteta
           INNER JOIN NARTOBJ           MAT     ON i1.CODOBIECT    = MAT.CODOBIECT
           INNER JOIN NART              AMAT    ON AMAT.CODARTICOL = MAT.CODARTICOL
           INNER JOIN NUM               UMC     ON UMC.CODUM = AMAT.UM
           INNER JOIN NUM               UMP     ON Coalesce(CMDPROD.TIP,0) = UMP.CODUM
           inner join livr1             l1      on l1.codies1    = i1.codies1 and l1.codlivr = l.codlivr
           inner join nirstoc           ns      on l1.codnirstoc = ns.codnirstoc
           inner join nirstoc1          ns1     on ns.codnirstoc = ns1.codnirstoc
           inner join nirstoc           nsi     on ns1.codnirstocorig = nsi.codnirstoc
           inner join ioart             ioa     on ioa.codioart    = ns.codioart
           INNER JOIN NGEST             G       ON I.CODGESTPROD   = G.CODGEST
           inner join tmp_manevra_liste tmpgest on tmpgest.filtru  = &apos;&apos;CODGEST&apos;&apos; and to_number(tmpgest.valoare) = i.codgestprod
           INNER JOIN NARTOBJ           PROD    ON PROD.CODOBIECT  = C1.CODOBIECT
           LEFT  JOIN NARTIMPLICITE     AIMP    ON AIMP.CODARTICOL = AMAT.CODARTICOL AND AIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJIMP        OIMP    ON OIMP.CODOBIECT  = MAT.CODOBIECT AND OIMP.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN IOART             IOAIMP  ON IOAIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN AIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
           LEFT  JOIN NCLASEA           CLS     ON AMAT.CLASA  = CLS.CODCLASEA
           left  join nir                       on nsi.codnir  = nir.codnir
           left  join intrari           intr    on nir.codintr = intr.codintr and intr.tipdoc = 7
           left  join intrari1          intr1   on intr1.codintr1   = nsi.codintr1
           left  join comanda1          cs1     on intr1.codcmdint1 = cs1.codcomanda1
           left  join comanda           cs      on cs1.codcomanda   = cs.codcomanda
           left  join intrprodlink      intrl   on intrl.codintr1   = intr1.codintr1
           LEFT  JOIN pretm             pm      ON pm.codobiect     = mat.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
           LEFT  JOIN NARTOBJ1          mat1    ON mat1.CodObiect   = mat.CodObiect AND &apos;||xAnLuna||&apos; BETWEEN mat1.ALStart and mat1.ALStop &apos;||
           gSuplJoins||&apos;
      where i.tipdoc = 24 and i.operat = 1 and Coalesce(i.anulat,0) = 0&apos;;
      if vCodComanda = 0 then
        sInsert := sInsert||&apos; and i.datadoc&apos;||cFiltru;
      end if;
        sInsert := sInsert||&apos;
           and ((&apos;||vSub||&apos; = 1) or i.subunitatea = &apos;||vSub||&apos;)
           and not exists (select tmp.codcmdprodmat from tmp_manevra_intr1_grupl tmp where tmp.codcmdprodmat = CMDprod.codcmdprodmat) &apos;;
    end if;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;

  if vCodCmdProdMat &gt; 0 then vCodCmdProdMat := 0; end if;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_analizascurta;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ANTECALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43C28899E2D3E73F15606BCCE931B913873E68A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ANTECALCUL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(2000);
BEGIN
  gSuplCols := &apos;NARTOBJ OBJ, NART ART, NUM UM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    PRETM, DENUMIRE, DEN_CLASEAS, PRET, ORDINE, CANT, DATAACHIZ&apos;||gUserFields||&apos;)
  SELECT
    MAN.PRET, MAN.DENUMIRE, MAN.DEN_CLASEAS, NVL(MAND.PRET,0), MAND.ORDINE, MAND.CANT, MAND.DATAACHIZ &apos;||gUserAlias||&apos;
  FROM TMP_MANEVRA_PRETURI MAN
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = MAN.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NUM UM ON UM.CODUM = ART.UM
    LEFT  JOIN TMP_MANEVRA_PRETURI_DETALII MAND ON MAN.CODOBIECT = MAND.CODOBIECT AND MAN.CODARTICOL = MAND.CODARTICOL&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_antecalcul;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_APELTEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88A045B06922A943B3CFC94C21C6C3533DB4C859</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_APELTEL is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    IDAPEL, 
    STARE,  
    TELEFON,
    APELANT,
    DATAORA,
    PRELUAT,
    CLIENT &apos;||gUserFields||&apos;)
  SELECT
    IDAPEL, 
    STARE,  
    TELEFON,
    APELANT,
    DATAORA,
    CASE WHEN PRELUAT &gt; 0 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    CLIENT &apos;||gUserAlias||&apos;
  FROM APELTELEFON
  WHERE DATAORA BETWEEN pkg_list_selectper.DATAINI and pkg_list_selectper.DATAFIN&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_APELTEL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ARTECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F259B27B0A5013AC221922F7FEF9FA773CCDE8F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ARTECHIV IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(5000);
  sJoinExt VARCHAR2( 1000);
BEGIN

  gSuplCols := &apos;nechiv e1, grechiv ge, nartobj o1, nart a1, num u_a1, num u1_a1, num u2_a1&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT1&apos;, &apos;OEXT1.CODOBIECT = O1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT2&apos;, &apos;OEXT2.CODOBIECT = O2.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR1&apos;, &apos;OATR1.CODOBIECT = O1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR2&apos;, &apos;OATR2.CODOBIECT = O2.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

 sInsert :=
 &apos;INSERT INTO &apos;||TMP_NAME|| &apos;(
    ARTICOL,   CODEXTERN,  CODINTERN,  DEN_UM,  DEN_UM1,  DEN_UM2,
    PARITATE, GENERIC, GRUPA &apos;||gUserFields||&apos;)
  SELECT
    o1.denumire, o1.codextern, o1.codintern, u_a1.den_um, u1_a1.den_um, u2_a1.den_um,
    e1.paritate, CASE WHEN E1.GENERIC = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END, GE.DENUMIRE &apos;||gUserAlias||&apos;
  FROM nechiv e1
    INNER JOIN grechiv ge ON ge.codgrechiv = e1.codgrupa
    INNER JOIN nartobj o1 ON o1.codobiect = e1.codobiect
    INNER JOIN nart a1 ON a1.codarticol = o1.codarticol
    INNER JOIN num u_a1 ON u_a1.codum = a1.um
    LEFT JOIN num u1_a1 ON u1_a1.codum = a1.um1
    LEFT JOIN num u2_a1 ON u2_a1.codum = a1.um2&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_artechiv;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ARTNEDESCARCATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31A639710467810ACB28EAB576C34BAF46B749B4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ARTNEDESCARCATE IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(30000);
  sCursRef    VARCHAR2(100);
  aSitV       NUMBER(1);
  aBancaV     NUMBER(20);
  aMonedaV    NUMBER(20);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NGEST G, LIVR L, NARTAMB AA, IESIRI1 IES1, NPART P, LIVR1 L1, LIVRVAL LV&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT  = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT  = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, ies.datadoc )&apos;;
  ELSE sCursRef := &apos;, 1 &apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    NrDoc, DataDoc, NumeDoc,
    DenArt, DenUM, DenGest, Cant, CodExtern, CodIntern,
    DenProd, DenReteta, CantReteta, CURS_REF&apos;||gUserFields||&apos; )
  WITH IOA1 AS (
    SELECT
      CODIOART, CODIOART1, CONT, DESCARCAREG, MG,
      ANSTART * 12 + LUNASTART AnLunaStart,
      NVL(Lead(ANSTART *12 +LUNASTART) OVER (PARTITION BY CODIOART ORDER BY ANSTART, LUNASTART) - 1,PKG_GLOBALS.AnLunaLucru) AnLunaStop
    FROM IOART1
    WHERE (ANSTART *12 +LUNASTART) &lt;= PKG_GLOBALS.AnLunaLucru
    ORDER BY CODIOART
  )
  SELECT
    COALESCE(L.CODIES,L.CODINTR,L.CODTRANSF), COALESCE(IES.TIPDOC,INTR.TIPDOC,T.TIPDOC),
    COALESCE(IES.NRDOC,INTR.NRDOC,T.NRDOC), COALESCE(IES.DATADOC,INTR.DATADOC,T.DATADOC), COALESCE(IES.PREFIXDOC,INTR.PREFIXDOC,T.PREFIXDOC),
    NAO.DENUMIRE, 
    U1.DEN_UM1, G.DEN_GEST, L1.RESTIESVAL, 
    NAO.CODEXTERN, 
    NAO.CODINTERN,
    null, null, null &apos;||sCursRef||gUserAlias||&apos;
  FROM LIVRVAL LV
    INNER JOIN IOA1 ON LV.CODIOART = IOA1.CODIOART
    INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = LV.CODLIVR1
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN IESIRI1 IES1 ON IES1.CODIES = IES.CODIES AND IES1.CODIES1 = L1.CODIES1
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = CASE WHEN COALESCE(LV.CODOBIECT,0) = 0 THEN IES1.CODOBIECT ELSE LV.CODOBIECT END
    LEFT JOIN INTRARI INTR ON INTR.CODINTR = L.CODINTR
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
    LEFT JOIN NUM1 U1 ON U1.CODUM1 = L1.UMSEC
    LEFT JOIN NGEST G ON G.CODGEST = LV.GEST
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = LV.CODOBIECT AND AA.UMSEC = L1.UMSEC
    LEFT JOIN NPART P ON P.CODPART = COALESCE(IES.PARTENER, INTR.PARTENER)&apos;||
    gSuplJoins||&apos;
  WHERE COALESCE(IES.AN * 12 + IES.LUNA,INTR.AN * 12 + INTR.LUNA,T.AN * 12 + T.LUNA) &lt;= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
    AND COALESCE(IES.AN * 12 + IES.LUNA,INTR.AN * 12 + INTR.LUNA,T.AN * 12 + T.LUNA) BETWEEN IOA1.AnLunaStart AND IOA1.AnLunaStop
    AND NVL(IOA1.DESCARCAREG, 0) = 0
    AND NVL(L1.RESTIESVAL,0) &lt;&gt; 0
    AND NVL(L1.CODPRODCOMP, 0) = 0 &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;COALESCE(IES.SUBUNITATEA,INTR.SUBUNITATEA,T.SUBUNITATEA)&apos;)||&apos;
  UNION ALL
  SELECT
    COALESCE(L.CODIES,L.CODINTR,L.CODTRANSF), COALESCE(IES.TIPDOC,INTR.TIPDOC,T.TIPDOC),
    COALESCE(IES.NRDOC,INTR.NRDOC,T.NRDOC), COALESCE(IES.DATADOC,INTR.DATADOC,T.DATADOC), COALESCE(IES.PREFIXDOC,INTR.PREFIXDOC,T.PREFIXDOC),
    NAO.DENUMIRE, UM1.DEN_UM1, G.DEN_GEST, ROUND(L1.RESTIESVAL * Mat.Cant / Pr.Cant, 4), NAO.CODEXTERN, NAO.CODINTERN,
    NAOP.Denumire, PR.Obs, ROUND(MAT.Cant/PR.Cant,4) &apos;||sCursRef||gUserAlias||&apos;
  FROM LIVRVAL LV
    INNER JOIN IOA1 ON LV.CODIOART = IOA1.CODIOART
    INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = LV.CODLIVR1
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN PRODCOMP PR ON L1.CODPRODCOMP = PR.CODPRODCOMP
    INNER JOIN NARTOBJ NAOP ON PR.CODOBIECT = NAOP.CODOBIECT
    INNER JOIN PRODMAT MAT ON PR.CODPRODCOMP = MAT.CODPRODCOMP
    INNER JOIN NARTOBJ NAO ON MAT.CODOBIECT = NAO.CODOBIECT
    INNER JOIN NART ART ON NAO.CODARTICOL = ART.CODARTICOL
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN IESIRI1 IES1 ON IES1.CODIES = IES.CODIES AND IES1.CODIES1 = L1.CODIES1
    LEFT JOIN INTRARI INTR ON INTR.CODINTR = L.CODINTR
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
    LEFT JOIN NGEST G ON G.CODGEST = LV.GEST
    LEFT JOIN NUM1 UM1 ON UM1.CODUM = ART.UM AND UM1.SECUNDARA = 0
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = MAT.CODOBIECT AND AA.UMSEC = UM1.CODUM1
    LEFT JOIN NPART P ON P.CODPART = COALESCE(IES.PARTENER, INTR.PARTENER)&apos;||
    gSuplJoins||&apos;
  WHERE COALESCE(IES.AN * 12 + IES.LUNA,INTR.AN * 12 + INTR.LUNA,T.AN * 12 + T.LUNA) &lt;= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
    AND COALESCE(IES.AN * 12 + IES.LUNA,INTR.AN * 12 + INTR.LUNA,T.AN * 12 + T.LUNA) BETWEEN IOA1.AnLunaStart AND IOA1.AnLunaStop
    AND NVL(IOA1.DESCARCAREG, 0) = 0
    AND NVL(L1.RESTIESVAL,0) &lt;&gt; 0
    AND NVL(L1.CODPRODCOMP, 0) &lt;&gt; 0 &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;COALESCE(IES.SUBUNITATEA,INTR.SUBUNITATEA,T.SUBUNITATEA)&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_ArtNEDESCARCATE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ATRIBUTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9CFF12D08C9E191A4E6A6DDB97914E74E86614A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ATRIBUTE IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NATRIB ATR, NATRIB1 ATR1, VALATREXCEPTII EXC, NARTOBJ ASOC, NART ART&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
      Atribut,
      Prefix,
      Valoare,
      ObjAsoc,
      CodExtern,
      Grupa,
      Inactiv,
      ProcMajPU,
      InactivCmdOnLine,
      MesajInactiv,
      ArtExcept&apos;||gUserFields||&apos;)
  SELECT
    ATR.DENUMIRE,
    ATR.PREFIX,
    ATR1.VALOARE,
    ASOC.DENUMIRE,
    ATR1.CODEXTERN,
    ATR1.GRUPA,
    CASE WHEN ATR1.INACTIV = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    ATR1.PROCMAJPU,
    CASE WHEN ATR1.INACTIVCMDONLINE = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    ATR1.MESAJINACTIV,
    ART.DEN_ARTICOL&apos;||gUserAlias||&apos;
  FROM NATRIB ATR
    INNER JOIN NATRIB1 ATR1 ON ATR.CODATRIBUT = ATR1.CODATRIBUT
    LEFT JOIN VALATREXCEPTII EXC ON EXC.CODVALATR = ATR1.CODVALATR
    LEFT JOIN NARTOBJ ASOC ON ASOC.CODOBIECT = ATR1.CODOBIECTASOC
    LEFT JOIN NART ART ON ART.CODARTICOL = EXC.CODARTICOL &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_ATRIBUTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D5EF1ADC6BC0382CDF8020293F4E5F8B52E2673</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALANTA IS

  gUserFields         VARCHAR2(2500);
  gUserAlias          VARCHAR2(2500);
  gNullAlias          VARCHAR2(2500);
  gSuplCols           VARCHAR2(2500);
  gSuplJoins          VARCHAR2(5000);

  s_clasa             VARCHAR2(100);
  l_clasa             NUMBER(3);
  p_sintetic          NUMBER;
  p_plan              NUMBER;
  p_valuta            NUMBER;
  p_curs              NUMBER;
  p_ALIni             NUMBER;
  p_AnIni             NUMBER;
  p_LunaIni           NUMBER;
  p_ALFin             NUMBER;
  p_AnFin             NUMBER;
  p_LunaFin           NUMBER;
  p_PerFaraRul        NUMBER;
  p_LISTID            NUMBER;
  p_LISTVER           NUMBER;
  p_PeSubunit         VARCHAR2(2);
  p_Lunara            VARCHAR2(2);
  g_tmpTABLE          VARCHAR2(100);
  vLunaStartAnContab  INTEGER;
  p_IDX_SINTETIC      INTEGER;
  CT_PLANCOM CONSTANT INTEGER := 0;
  CT_PLANP   CONSTANT INTEGER := 1;
  CT_PLANS   CONSTANT INTEGER := 2;
  CT_PLANT   CONSTANT INTEGER := 3;

PROCEDURE Set_G_tmpTABLE (aName in varchar2)
IS
BEGIN
  G_tmpTABLE := aName;
end;

function getAnIni return number is
begin
  return p_AnIni;
end;

function getLunaIni return number is
begin
  return p_LunaIni;
end;

function getAnFin return number is
begin
  return p_AnFin;
end;

function getLunaFin return number is
begin
  return p_LunaFin;
end;

PROCEDURE setParams (
  v_clasa      IN VARCHAR2 DEFAULT NULL,
  v_sintetic   IN NUMBER   DEFAULT 0,
  v_plan       IN NUMBER   DEFAULT 0,
  v_valuta     IN NUMBER   DEFAULT 0,
  v_curs       IN NUMBER   DEFAULT 1,
  v_PeSubunit  IN NUMBER   DEFAULT 1,
  v_Lunara     IN NUMBER   DEFAULT 1,
  v_CodJob1    IN NUMBER   DEFAULT 0,
  v_LunaIni    IN NUMBER   DEFAULT 0,
  v_LunaFin    IN NUMBER   DEFAULT 0,
  v_PerFaraRul IN NUMBER   DEFAULT 0
) IS
  vTratSemn    INTEGER;
  aListID      NUMBER(2) := 0;

  dDataS       DATE;
  dDataF       DATE;
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);

  IF v_LunaIni &gt; 12 THEN
    p_ALIni := v_LunaIni;
    p_ALFin := v_LunaFin;
  ELSIF v_Lunara = 2 THEN
    p_ALIni := pkg_globals.AnLucru*12+v_LunaIni;
    p_ALFin := pkg_globals.AnLucru*12+v_LunaFin;
  ELSE
    p_ALIni := pkg_globals.AnLunaLucru;
    p_ALFin := pkg_globals.AnLunaLucru;
  END IF;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,p_ALIni,p_ALFin);
  END IF;
  --IF v_Lunara = 2 THEN
  --  p_ALIni    := Greatest(p_ALIni, pkg_globals.AnLucru*12+1);
  --  p_ALFin    := Least   (p_ALFin, pkg_globals.AnLucru*12+12);
  --END IF;
  PKG_LIST_BASE_UTILS.ExtractAnLuna(p_ALIni, p_AnIni, p_LunaIni);
  PKG_LIST_BASE_UTILS.ExtractAnLuna(p_ALFin, p_AnFin, p_LunaFin);

  --PKG_GLOBALS.SetDebugMode(TRUE);
  PKG_GLOBALS.CheckDebugMode(
    &apos;BEGIN&apos;||CHR(10)||
    &apos;  pkg_globals.SetLunaLucru(&apos;||p_AnFin||&apos;,&apos;||p_LunaFin||&apos;);&apos;||CHR(10)||
    &apos;  PKG_LIST_BASE_BALANTA.setParams (&apos;               ||CHR(10)||
    &apos;    v_clasa      =&gt; &apos;&apos;&apos;||v_clasa||&apos;&apos;&apos;,&apos;            ||CHR(10)||
    &apos;    v_sintetic   =&gt; &apos;  ||v_sintetic||&apos;,&apos;           ||CHR(10)||
    &apos;    v_plan       =&gt; &apos;  ||v_plan||&apos;,&apos;               ||CHR(10)||
    &apos;    v_valuta     =&gt; &apos;  ||v_valuta||&apos;,&apos;             ||CHR(10)||
    &apos;    v_curs       =&gt; &apos;  ||v_curs||&apos;,&apos;               ||CHR(10)||
    &apos;    v_PeSubunit  =&gt; &apos;  ||v_PeSubunit||&apos;,&apos;          ||CHR(10)||
    &apos;    v_Lunara     =&gt; &apos;  ||v_Lunara||&apos;,&apos;             ||CHR(10)||
    &apos;    V_CODJOB1    =&gt; &apos;  ||Coalesce(V_CODJOB1,0)||&apos;,&apos;||CHR(10)||
    &apos;    v_LunaIni    =&gt; &apos;  ||Coalesce(v_LunaIni,0)||&apos;,&apos;||CHR(10)||
    &apos;    v_LunaFin    =&gt; &apos;  ||Coalesce(v_LunaFin,0)||&apos;,&apos;||CHR(10)||
    &apos;    v_PerFaraRul =&gt; &apos;  ||Coalesce(v_PerFaraRul,0)  ||CHR(10)||
    &apos;  ); &apos; ||CHR(10)||
    &apos;END;&apos; , 0, 0
  );

  s_clasa     := Trim(v_clasa);
  l_clasa     := Coalesce(Length(s_clasa), 0);
  p_sintetic  := v_sintetic;
  p_plan      := v_plan;
  p_valuta    := v_valuta;
  p_PerFaraRul:= v_PerFaraRul;
  vTratSemn   := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;BalTratTipCont&apos;, p_AnFin, p_LunaFin), &apos;2&apos;);

  IF p_valuta = 1
  THEN p_curs := v_curs;
  ELSE p_curs := 1;
  END IF;

  p_PeSubunit := CASE WHEN v_PeSubunit = 1 AND pkg_globals.GetSubunitate &gt; 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END;
  p_Lunara    := CASE WHEN v_Lunara &gt; 0                                      THEN &apos;Da&apos; ELSE &apos;Nu&apos; END;

  PKG_LIST_BASE_UTILS.CLEAR_SIMBOL_LIPSA;
  DELETE FROM TMP_LIST_BALANTA;
  DELETE FROM TMP_LIST_BALCUMUL;
  DELETE FROM TMP_NCONT_BAL;
  DELETE FROM TMP_NCONT1_BAL;

  IF p_plan = CT_PLANCOM THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL,
      CODPARINTE,
      SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      CODCONT, SIMBOL, CLASA, DEN_CONT, NULL NAME, TIPCONT, VIZIBILBALANTA, BALSINT, NIVEL,
      CODPARINTE,
      NULL, NULL, NULL
    FROM NCONTCOMUN C
    WHERE C.CODCONT &lt;&gt; 0
      AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1; -- filtrare dupa CLASA
  ELSIF p_plan = CT_PLANP THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, CODCONTP, CODCONTS, CODCONTT,
      SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL,
      CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      C.CODCONT, C.CODCONT, C1.ContSecundar AS CODCONTS, C1.ContTertiar AS CODCONTT,
      C.SIMBOL, C.CLASA, C.DEN_CONT, C.NAME, C.TIPCONT, C.VIZIBILBALANTA, C.BALANTASINTETICA, C.NIVEL,
      C.CODPARINTE, C.SIMBOLSITFIN, CC.DENUMIRE, CC.SIMBOL
    FROM NCONT C
      INNER JOIN NCONT1     C1 ON C.CODCONT    = C1.CODCONT
      LEFT  JOIN CENTRECOST CC ON CC.CODCENTRU = Coalesce(C1.CODCENTRU,0)
    WHERE C.CODCONT &lt;&gt; 0
      AND p_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
      AND NOT EXISTS (SELECT CONTVECHI FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= p_ALFin )
      AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1; -- filtrare dupa CLASA

    INSERT INTO TMP_NCONT1_BAL (
      CODCONT, CODCOMUN, SIMBOLPLANP,
      FRUNZA,
      FRUNZAS,
      SEMN,
      OFFSET)
    SELECT
      T.CODCONT, T.CODCONT CODCOMUN, T.SIMBOL,
      CASE WHEN EXISTS(SELECT 1 FROM TMP_NCONT_BAL X WHERE X.CODPARINTE = T.CODCONT) THEN 0 ELSE 1 END FRUNZA,
      CASE WHEN EXISTS(SELECT 1 FROM TMP_NCONT_BAL X WHERE X.CODPARINTE = T.CODCONT AND X.BALANTASINTETICA = 1) THEN 0 ELSE 1 END FRUNZAS,
      1 SEMN,
      0 OFFSET
    FROM TMP_NCONT_BAL T;
  ELSIF p_plan = CT_PLANS THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, CODCONTS,
      SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      C.CODCONTS, C.CODCONTS,
      C.SIMBOL, C.CLASA, C.DEN_CONT, C.NAME, C.TIPCONT, C.VIZIBILBALANTA, C.BALANTASINTETICA, C.NIVEL, C.CODPARINTE, C.SIMBOLSITFIN, NULL CENTRUCOST, NULL SIMBCENTRUCOST
    FROM NCONTS C
    WHERE C.CODCONTS &lt;&gt; 0
      AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1 -- filtrare dupa CLASA
      AND EXISTS (SELECT 1 FROM NCONTS1 C1 WHERE C1.CODCONTS = C.CODCONTS AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin);

    INSERT INTO TMP_NCONT_BAL (CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    VALUES ( -1, &apos;...Fara coresp..&apos;, 0,&apos;...Fara corespondenta in planul Secundar...&apos;, NULL, 0,  1, 1, 1, 0, NULL, NULL, NULL);

    INSERT INTO TMP_NCONT1_BAL (
      CODCONT, CODCOMUN, SIMBOLPLANP,
      FRUNZA,
      FRUNZAS,
      SEMN,
      OFFSET)
    WITH C1 AS (
      SELECT C1.CODCONT, C1.CONTSECUNDAR   CODCONTS, 0 OFFSET FROM NCONT1 C1 WHERE COALESCE(C1.CONTSECUNDAR,  0) &lt;&gt; 0 AND p_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP UNION
      SELECT C1.CODCONT, C1.CONTSECUNDARG  CODCONTS, 0 OFFSET FROM NCONT1 C1 WHERE COALESCE(C1.CONTSECUNDARG, 0) &lt;&gt; 0 AND p_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP UNION
      SELECT C1.CODCONT, C1.CONTSECUNDARGO CODCONTS, 1 OFFSET FROM NCONT1 C1 WHERE COALESCE(C1.CONTSECUNDARGO,0) &lt;&gt; 0 AND p_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP UNION
      SELECT C.CODCONT , C1.CONTSECUNDAR   CODCONTS, 0 OFFSET
      FROM (
        SELECT C.CODCONT, Min(C1F.CODCONT1) CODCONT1  -- la creare analatice CONTSECUNDAR se muta de pe contul principal pe conturile parinte si atunci trebuie sa fac o analiza
        FROM NCONT1 C1F
          INNER JOIN NCONT  CF ON CF.CODCONT = C1F.CODCONT
          INNER JOIN NCONT  C  ON C.CODCONT  = CF.CODPARINTE
          INNER JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT
        WHERE COALESCE(C1F.CONTSECUNDAR,  0) &lt;&gt; 0 AND p_ALFin &lt;= C1F.ALSTART
          AND Coalesce(CF.CODPARINTE,     0)  &gt; 0 AND p_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
        GROUP BY C.CODCONT
      ) C
       INNER JOIN NCONT1  C1  ON C1.CODCONT1  = C.CODCONT1
       INNER JOIN NCONTS1 CS1 ON CS1.CODCONTS = C1.CONTSECUNDAR
      WHERE p_ALFin BETWEEN CS1.ALSTART AND CS1.ALSTOP
    )
    SELECT
      CASE WHEN C1.CODCONTS IS NULL THEN -1 WHEN C1.CODCONTS = 0 THEN -1 ELSE C1.CODCONTS END CODCONT, C.CODCONT CODCOMUN, C.SIMBOL,
      CASE WHEN EXISTS(SELECT 1 FROM NCONT X INNER JOIN NCONT1 X1 ON X1.CODCONT = X.CODCONT WHERE X.CODPARINTE = C.CODCONT AND (X1.ANSTART * 12 + X1.LUNASTART) &lt;= p_ALFin) THEN 0 ELSE 1 END FRUNZA,
      CASE WHEN C1.CODCONTS IS NULL THEN 1 WHEN EXISTS(SELECT 1 FROM TMP_NCONT_BAL X WHERE X.CODPARINTE = C1.CODCONTS AND X.BALANTASINTETICA = 1) THEN 0 ELSE 1 END FRUNZAS,
      CASE
        WHEN vTratSemn = 2 THEN 1
        WHEN CS.CODCONTS IS NULL THEN 1
        WHEN C.TipCont = 2 THEN 1
        WHEN C.TipCont  = 1 AND CS.TipCont &lt;&gt; 1 THEN -1
        WHEN C.TipCont &lt;&gt; 1 AND CS.TipCont  = 1 THEN -1
        ELSE 1
      END SEMN,
      C1.OFFSET
    FROM NCONT C
      LEFT JOIN C1 ON C1.CODCONT = C.CODCONT
      LEFT JOIN NCONTS CS ON CS.CODCONTS = C1.CODCONTS
    WHERE C.CODCONT &lt;&gt; 0
      AND NOT EXISTS (SELECT 1 FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= p_ALFin)
      AND     EXISTS (SELECT 1 FROM NCONT1     CX WHERE CX.CODCONT   = C.CODCONT AND CX.ALSTART             &lt;= p_ALFin);

  ELSIF p_plan = CT_PLANT THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, CODCONTT,
      SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL,
      CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      C.CODCONTT, C.CODCONTT,
      C.SIMBOL, C.CLASA, C.DEN_CONT, C.NAME, C.TIPCONT, C.VIZIBILBALANTA, C.BALANTASINTETICA, C.NIVEL,
      C.CODPARINTE, C.SIMBOLSITFIN, NULL CENTRUCOST, NULL SIMBCENTRUCOST
    FROM NCONTT C
    WHERE C.CODCONTT &lt;&gt; 0
      AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1 -- filtrare dupa CLASA
      AND EXISTS (SELECT 1 FROM NCONTT1 C1 WHERE C1.CODCONTT = C.CODCONTT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin);

    INSERT INTO TMP_NCONT_BAL ( CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    VALUES ( -1, &apos;...Fara coresp..&apos;, 0,&apos;...Fara corespondenta in planul Tertiar...&apos;, NULL, 0,  1, 1, 1, 0, NULL, NULL, NULL);

    INSERT INTO TMP_NCONT1_BAL (
      CODCONT, CODCOMUN, SIMBOLPLANP,
      FRUNZA,
      FRUNZAS,
      SEMN,
      OFFSET)
    SELECT
      CASE WHEN C1.CONTTERTIAR IS NULL THEN -1 WHEN C1.CONTTERTIAR = 0 THEN -1 ELSE C1.CONTTERTIAR END CODCONT, C.CODCONT, C.SIMBOL,
      CASE WHEN EXISTS(SELECT 1 FROM NCONT X INNER JOIN NCONT1 X1 ON X1.CODCONT = X.CODCONT WHERE X.CODPARINTE = C.CODCONT AND (X1.ANSTART * 12 + X1.LUNASTART) &lt;= p_ALFin) THEN 0 ELSE 1 END FRUNZA,
      CASE WHEN C1.CONTTERTIAR IS NULL THEN 1 WHEN EXISTS(SELECT 1 FROM TMP_NCONT_BAL X WHERE X.CODPARINTE = C1.CONTTERTIAR AND X.BALANTASINTETICA = 1) THEN 0 ELSE 1 END FRUNZAS,
      CASE
        WHEN vTratSemn = 2 THEN 1
        WHEN CT.CODCONTT IS NULL THEN 1
        WHEN C.TipCont = 2 THEN 1
        WHEN C.TipCont  = 1 AND CT.TipCont &lt;&gt; 1 THEN -1
        WHEN C.TipCont &lt;&gt; 1 AND CT.TipCont  = 1 THEN -1
        ELSE 1
      END SEMN,
      0 OFFSET
    FROM NCONT C
      LEFT JOIN NCONT1 C1 ON C1.CODCONT  = C.CODCONT AND p_ALFin BETWEEN ALSTART and ALSTOP
      LEFT JOIN NCONTT CT ON CT.CODCONTT = C1.CONTTERTIAR
    WHERE C.CODCONT &lt;&gt; 0
      AND NOT EXISTS (SELECT CONTVECHI FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= p_ALFin);

  END IF;
  COMMIT;
END;

PROCEDURE ACTUALIZEAZA_TMP_BALCUMUL IS
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  INSERT INTO TMP_LIST_BALCUMUL(
    SIMBOL, CLASA, TIPCONT, BALSINT, NIVEL,
    SOLDID,      SOLDVID,
    SOLDIC,      SOLDVIC,
    SOLDIIFRS,   SOLDVIIFRS,
    SOLDIGRUP,   SOLDVIGRUP,
    RULAJPD,     RULAJVPD,
    RULAJPC,     RULAJVPC,
    RULAJPIFRS,  RULAJVPIFRS,
    RULAJPIFRSD, RULAJVPIFRSD,
    RULAJPIFRSC, RULAJVPIFRSC,
    RULAJPGRUP,  RULAJVPGRUP,
    RULAJCD,     RULAJVCD,
    RULAJCC,     RULAJVCC,
    RULAJCIFRS,  RULAJVCIFRS,
    RULAJCIFRSD, RULAJVCIFRSD,
    RULAJCIFRSC, RULAJVCIFRSC,
    RULAJCGRUP,  RULAJVCGRUP,
    SIMBSINT, CODCONT, CODPARINTE, CODSINT, DEN_CONT, NRANALITICE, VIZIBILBALANTA)
  WITH
    /*recursive*/ RecCS (codcont, nivsint, simbsint, codsint, codparinte) as (
      SELECT codcont, nivel as nivsint, simbol as simbsint, codcont as codsint, codparinte
      FROM NCONT C
      WHERE Coalesce(BALANTASINTETICA, 0) = 1 AND C.CODCONT &lt;&gt; 0 AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
      UNION ALL
	    SELECT c.codcont, nr.nivsint, nr.simbsint, nr.codsint, c.codparinte
      FROM NCONT C INNER JOIN RecCS nr ON nr.codcont = c.codparinte
      WHERE                                       C.CODCONT &lt;&gt; 0 AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
    ),
    /*recursive*/ RecC (codcont, simbol, clasa, den_cont, tipcont, vizibilbalanta, balantasintetica, nivel, codparinte) as (
      SELECT c.codcont, c.simbol, c.clasa, c.den_cont, coalesce(c.tipcont,0) tipcont, c.vizibilbalanta, coalesce(c.balantasintetica,0) balantasintetica, c.nivel, c.codparinte
      FROM NCONT C
      WHERE Coalesce(CODPARINTE, 0) = 0 AND C.CODCONT &lt;&gt; 0 AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
      UNION ALL
	    SELECT c.codcont, c.simbol, c.clasa, c.den_cont, coalesce(c.tipcont,0) tipcont, c.vizibilbalanta, coalesce(c.balantasintetica,0) balantasintetica, c.nivel, c.codparinte
      FROM NCONT C INNER JOIN RecC nr ON nr.codcont = c.codparinte
      WHERE                                 C.CODCONT &lt;&gt; 0 AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
    ),
    CONTSINT AS (
      SELECT CODCONT, SIMBSINT, CODSINT
      FROM (SELECT codcont, simbsint, codsint, Row_Number() OVER (PARTITION BY CODCONT ORDER BY NIVSINT DESC) IdxNivSint FROM RecCS) sub_cs
      WHERE IdxNivSint = 1
    ),
    CONTURI AS (
      SELECT
        codcont, simbol, clasa, den_cont, coalesce(tipcont,0) tipcont, vizibilbalanta, coalesce(balantasintetica,0) balantasintetica, nivel, codparinte,
        CASE WHEN NOT EXISTS (SELECT * FROM RecC ncr WHERE ncr.codparinte = nr.codcont) THEN 1 ELSE 0 END AS FARA_FII
      FROM RecC nr
    ),
    BALANTA AS (
      SELECT
        codcont,
        SUM(soldid)  soldid,  SUM(soldvid)  soldvid,  SUM(soldic)  soldic,  SUM(soldvic)  soldvic,  SUM(soldi_ifrs)  soldiifrs,  SUM(soldvi_ifrs)  soldviifrs,  SUM(soldi_grup)  soldigrup,  SUM(soldvi_grup)  soldvigrup,
        SUM(rulajpd) rulajpd, SUM(rulajvpd) rulajvpd, SUM(rulajpc) rulajpc, SUM(rulajvpc) rulajvpc, SUM(rulajp_ifrs) rulajpifrs, SUM(rulajvp_ifrs) rulajvpifrs, SUM(rulajp_grup) rulajpgrup, SUM(rulajvp_grup) rulajvpgrup,
        SUM(rulajcd) rulajcd, SUM(rulajvcd) rulajvcd, SUM(rulajcc) rulajcc, SUM(rulajvcc) rulajvcc, SUM(rulajc_ifrs) rulajcifrs, SUM(rulajvc_ifrs) rulajvcifrs, SUM(rulajc_grup) rulajcgrup, SUM(rulajvc_grup) rulajvcgrup,
        SUM(rulajp_ifrsd) rulajpifrsd, SUM(rulajp_ifrsc) rulajpifrsc, SUM(rulajvp_ifrsd) rulajvpifrsd, SUM(rulajvp_ifrsc) rulajvpifrsc,
        SUM(rulajc_ifrsd) rulajcifrsd, SUM(rulajc_ifrsc) rulajcifrsc, SUM(rulajvc_ifrsd) rulajvcifrsd, SUM(rulajvc_ifrsc) rulajvcifrsc
      FROM  (
        SELECT
          codcont, soldid, soldvid, soldic, soldvic, soldi_ifrs, soldvi_ifrs, soldi_grup, soldvi_grup,
          0 rulajpd, 0 rulajvpd, 0 rulajpc, 0 rulajvpc, 0 rulajp_ifrs, 0 rulajp_ifrsd, 0 rulajp_ifrsc, 0 rulajvp_ifrs, 0 rulajvp_ifrsd, 0 rulajvp_ifrsc, 0 rulajp_grup, 0 rulajvp_grup,
          0 rulajcd, 0 rulajvcd, 0 rulajcc, 0 rulajvcc, 0 rulajc_ifrs, 0 rulajc_ifrsd, 0 rulajc_ifrsc, 0 rulajvc_ifrs, 0 rulajvc_ifrsd, 0 rulajvc_ifrsc, 0 rulajc_grup, 0 rulajvc_grup
        FROM ncontsold
        WHERE (
                Coalesce(soldid,0)     &lt;&gt; 0 OR Coalesce(soldvid,0)     &lt;&gt; 0 OR Coalesce(soldic,0)     &lt;&gt; 0 OR Coalesce(soldvic,0)     &lt;&gt; 0 OR
                Coalesce(soldi_ifrs,0) &lt;&gt; 0 OR Coalesce(soldvi_ifrs,0) &lt;&gt; 0 OR Coalesce(soldi_grup,0) &lt;&gt; 0 OR Coalesce(soldvi_grup,0) &lt;&gt; 0
              )
          AND an = p_AnIni AND luna = 1
          AND p_PeSubunit = &apos;Nu&apos;
        UNION ALL
        SELECT
          codcont, 0 soldid, 0 soldvid, 0 soldic, 0 soldvic, 0 soldi_ifrs, 0 soldvi_ifrs, 0 soldi_grup, 0 soldvi_grup,
          rulajpd, rulajvpd, rulajpc, rulajvpc, rulajp_ifrs, 0 rulajp_ifrsd, 0 rulajp_ifrsc, rulajvp_ifrs, 0 rulajvp_ifrsd, 0 rulajvp_ifrsc, rulajp_grup, rulajvp_grup,
          rulajcd, rulajvcd, rulajcc, rulajvcc, rulajc_ifrs, 0 rulajc_ifrsd, 0 rulajc_ifrsc, rulajvc_ifrs, 0 rulajvc_ifrsd, 0 rulajvc_ifrsc, rulajc_grup, rulajvc_grup
        FROM ncontrul
        WHERE (
                Coalesce(rulajpd,0)     &lt;&gt; 0 OR Coalesce(rulajvpd,0)     &lt;&gt; 0 OR Coalesce(rulajpc,0)     &lt;&gt; 0 OR Coalesce(rulajvpc,0)     &lt;&gt; 0 OR
                Coalesce(rulajcd,0)     &lt;&gt; 0 OR Coalesce(rulajvcd,0)     &lt;&gt; 0 OR Coalesce(rulajcc,0)     &lt;&gt; 0 OR Coalesce(rulajvcc,0)     &lt;&gt; 0 OR
                Coalesce(rulajp_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajvp_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajp_grup,0) &lt;&gt; 0 OR Coalesce(rulajvp_grup,0) &lt;&gt; 0 OR
                Coalesce(rulajc_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajvc_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajc_grup,0) &lt;&gt; 0 OR Coalesce(rulajvc_grup,0) &lt;&gt; 0
              )
          AND an BETWEEN p_AnIni AND p_AnFin
          AND luna = CASE WHEN an = p_AnFin THEN p_LunaFin ELSE 12 END
          AND p_PeSubunit = &apos;Nu&apos;
        UNION ALL
        SELECT
          b.codcont, bs.soldid, bs.soldvid, bs.soldic, bs.soldvic, bs.soldi_ifrs, bs.soldvi_ifrs, bs.soldi_grup, bs.soldvi_grup,
          0 rulajpd, 0 rulajvpd, 0 rulajpc, 0 rulajvpc, 0 rulajp_ifrs, 0 rulajp_ifrsd, 0 rulajp_ifrsc, 0 rulajvp_ifrs, 0 rulajvp_ifrsd, 0 rulajvp_ifrsc, 0 rulajp_grup, 0 rulajvp_grup,
          0 rulajcd, 0 rulajvcd, 0 rulajcc, 0 rulajvcc, 0 rulajc_ifrs, 0 rulajc_ifrsd, 0 rulajc_ifrsc, 0 rulajvc_ifrs, 0 rulajvc_ifrsd, 0 rulajvc_ifrsc, 0 rulajc_grup, 0 rulajvc_grup
        FROM ncontsold b
          INNER JOIN ncontsoldsub bs ON bs.codcontsold = b.codcontsold
        WHERE not (bs.soldid = 0 AND bs.soldvid = 0 AND bs.soldic = 0 AND bs.soldvic = 0)
          AND b.an = p_AnIni AND b.luna = 1
          AND p_PeSubunit = &apos;Da&apos;
          AND bs.subunitatea = pkg_globals.GetSubunitate
        UNION ALL
        SELECT
          b.codcont, 0 soldid, 0 soldvid, 0 soldic, 0 soldvic, 0 soldi_ifrs, 0 soldvi_ifrs, 0 soldi_grup, 0 soldvi_grup,
          bs.rulajpd, bs.rulajvpd, bs.rulajpc, bs.rulajvpc, bs.rulajp_ifrs, 0 rulajp_ifrsd, 0 rulajp_ifrsc, bs.rulajvp_ifrs, 0 rulajvp_ifrsd, 0 rulajvp_ifrsc, bs.rulajp_grup, bs.rulajvp_grup,
          bs.rulajcd, bs.rulajvcd, bs.rulajcc, bs.rulajvcc, bs.rulajc_ifrs, 0 rulajc_ifrsd, 0 rulajc_ifrsc, bs.rulajvc_ifrs, 0 rulajvc_ifrsd, 0 rulajvc_ifrsc, bs.rulajc_grup, bs.rulajvc_grup
        FROM ncontrul b
          INNER JOIN ncontrulsub bs ON bs.codcontrul = b.codcontrul
        WHERE (
                Coalesce(bs.rulajpd,0)     &lt;&gt; 0 OR Coalesce(bs.rulajvpd,0)     &lt;&gt; 0 OR Coalesce(bs.rulajpc,0)     &lt;&gt; 0 OR Coalesce(bs.rulajvpc,0)     &lt;&gt; 0 OR
                Coalesce(bs.rulajcd,0)     &lt;&gt; 0 OR Coalesce(bs.rulajvcd,0)     &lt;&gt; 0 OR Coalesce(bs.rulajcc,0)     &lt;&gt; 0 OR Coalesce(bs.rulajvcc,0)     &lt;&gt; 0 OR
                Coalesce(bs.rulajp_ifrs,0) &lt;&gt; 0 OR Coalesce(bs.rulajvp_ifrs,0) &lt;&gt; 0 OR Coalesce(bs.rulajp_grup,0) &lt;&gt; 0 OR Coalesce(bs.rulajvp_grup,0) &lt;&gt; 0 OR
                Coalesce(bs.rulajc_ifrs,0) &lt;&gt; 0 OR Coalesce(bs.rulajvc_ifrs,0) &lt;&gt; 0 OR Coalesce(bs.rulajc_grup,0) &lt;&gt; 0 OR Coalesce(bs.rulajvc_grup,0) &lt;&gt; 0
              )
          AND an BETWEEN p_AnIni AND p_AnFin
          AND luna = CASE WHEN an = p_AnFin THEN p_LunaFin ELSE 12 END
          AND p_PeSubunit = &apos;Da&apos;
          AND bs.subunitatea = pkg_globals.GetSubunitate
        UNION ALL
        SELECT
          codcont, 0 soldid, 0 soldvid, 0 soldic, 0 soldvic, 0 soldi_ifrs, 0 soldvi_ifrs, 0 soldi_grup, 0 soldvi_grup,
          0 rulajpd, 0 rulajvpd, 0 rulajpc, 0 rulajvpc, 0 rulajp_ifrs, rulajp_ifrsd, 0 rulajp_ifrsc, 0 rulajvp_ifrs, rulajvp_ifrsd, 0 rulajvp_ifrsc, 0 rulajp_grup, 0 rulajvp_grup,
          0 rulajcd, 0 rulajvcd, 0 rulajcc, 0 rulajvcc, 0 rulajc_ifrs, rulajc_ifrsd, 0 rulajc_ifrsc, 0 rulajvc_ifrs, rulajvc_ifrsd, 0 rulajvc_ifrsc, 0 rulajc_grup, 0 rulajvc_grup
        FROM (
          SELECT
            contd codcont,
            Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN valoare_ifrs ELSE 0 END) rulajp_ifrsd, Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN valoarev_ifrs ELSE 0 END) rulajvp_ifrsd,
            Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN 0 ELSE valoare_ifrs END) rulajc_ifrsd, Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN 0 ELSE valoarev_ifrs END) rulajvc_ifrsd
          FROM jurnal
          WHERE an BETWEEN p_AnIni AND p_AnFin
            AND luna &lt;= CASE WHEN an = p_AnFin THEN p_LunaFin ELSE 12 END
            AND (Coalesce(valoare_ifrs, 0) &lt;&gt; 0 OR Coalesce(valoarev_ifrs, 0) &lt;&gt; 0)
            AND (p_PeSubunit = &apos;Nu&apos; OR subunitatea = pkg_globals.GetSubunitate)
          GROUP BY contd
        )
        UNION ALL
        SELECT
          codcont, 0 soldid, 0 soldvid, 0 soldic, 0 soldvic, 0 soldi_ifrs, 0 soldvi_ifrs, 0 soldi_grup, 0 soldvi_grup,
          0 rulajpd, 0 rulajvpd, 0 rulajpc, 0 rulajvpc, 0 rulajp_ifrs, 0 rulajp_ifrsd, rulajp_ifrsc, 0 rulajvp_ifrs, 0 rulajvp_ifrsd, rulajvp_ifrsc, 0 rulajp_grup, 0 rulajvp_grup,
          0 rulajcd, 0 rulajvcd, 0 rulajcc, 0 rulajvcc, 0 rulajc_ifrs, 0 rulajc_ifrsd, rulajc_ifrsc, 0 rulajvc_ifrs, 0 rulajvc_ifrsd, rulajvc_ifrsc, 0 rulajc_grup, 0 rulajvc_grup
        FROM (
          SELECT
            contc codcont,
            Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN valoare_ifrs ELSE 0 END) rulajp_ifrsc, Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN valoarev_ifrs ELSE 0 END) rulajvp_ifrsc,
            Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN 0 ELSE valoare_ifrs END) rulajc_ifrsc, Sum(CASE WHEN an*12+luna &lt; p_ALIni THEN 0 ELSE valoarev_ifrs END) rulajvc_ifrsc
          FROM jurnal
          WHERE an BETWEEN p_AnIni AND p_AnFin
            AND luna &lt;= CASE WHEN an = p_AnFin THEN p_LunaFin ELSE 12 END
            AND (Coalesce(valoare_ifrs, 0) &lt;&gt; 0 OR Coalesce(valoarev_ifrs, 0) &lt;&gt; 0)
            AND (p_PeSubunit = &apos;Nu&apos; OR subunitatea = pkg_globals.GetSubunitate)
          GROUP BY contc
        )
      )
      GROUP BY CODCONT
    )
  SELECT
    C.SIMBOL, C.CLASA, C.TIPCONT, C.BALANTASINTETICA, C.NIVEL,
    -- STEF valorile urmatoare le-am inmultit cu  C.FARA_FII pentru ca am gasit date care vin cu solduri precedente pe conturi parinte
    -- acestea trebuie sa aiba vallori 0, mai tarziu in balanta fiind recalculate ca suma fiilor
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDID      END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDVID      END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDIC      END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDVIC      END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDIIFRS   END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDVIIFRS   END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDIGRUP   END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.SOLDVIGRUP   END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPD     END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPD     END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPC     END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPC     END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPIFRS  END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPIFRS  END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPIFRSD END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPIFRSD END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPIFRSC END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPIFRSC END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJPGRUP  END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVPGRUP  END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCD     END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCD     END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCC     END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCC     END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCIFRS  END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCIFRS  END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCIFRSD END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCIFRSD END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCIFRSC END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCIFRSC END,0) * C.FARA_FII,
    Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJCGRUP  END,0) * C.FARA_FII, Coalesce(CASE WHEN C.VIZIBILBALANTA = 1 THEN B.RULAJVCGRUP  END,0) * C.FARA_FII,
    CS.SIMBSINT, C.CODCONT, C.CODPARINTE, CS.CODSINT, C.DEN_CONT, C1.NRANALITICE, C.VIZIBILBALANTA
  FROM CONTURI C
    INNER JOIN NCONT1   C1 ON C1.CODCONT = C.CODCONT AND p_ALFin BETWEEN ALSTART and ALSTOP
    LEFT  JOIN BALANTA  B  ON B.CODCONT  = C.CODCONT
    LEFT  JOIN CONTSINT CS ON CS.CODCONT = C.CODCONT
  ORDER BY CS.SIMBSINT, C.SIMBOL;

  COMMIT;

END;

FUNCTION getBalFirmaCur RETURN crs IS
  cResult crs;
BEGIN
  ACTUALIZEAZA_TMP_BALCUMUL;
  OPEN cResult FOR SELECT * FROM TMP_LIST_BALCUMUL;
  RETURN cResult;
END;

FUNCTION getConturiBal RETURN crs IS
  cResult crs;
BEGIN
  IF p_plan = CT_PLANCOM THEN
    OPEN cResult FOR
      SELECT CODCONT, CODFIRMACUPL, CODCONTCOMUN, NRANALITICE, LEGATURAINVALIDA
      FROM NCONTFIRMECUPL;
  ELSIF P_SINTETIC = 0 THEN
    OPEN cResult FOR
      WITH
        CONTURI AS (
          SELECT CODCONT, CLASA, SIMBOL, Coalesce(TIPCONT,0) TIPCONT, Coalesce(BALANTASINTETICA,0) BALANTASINTETICA, NIVEL, CONNECT_BY_ISLEAF FARA_FII, VIZIBILBALANTA
          FROM (
            SELECT *
            FROM NCONT C
            WHERE C.CODCONT &lt;&gt; 0
              AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1 -- filtrare dupa CLASA
              AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
          )
          START WITH Coalesce(CODPARINTE,0) = 0
          CONNECT BY PRIOR CODCONT = CODPARINTE
        )
      SELECT C.SIMBOL, 0, C.CODCONT, C.CLASA, C.TIPCONT, C.BALANTASINTETICA, C.NIVEL, C.VIZIBILBALANTA, C.FARA_FII
      FROM CONTURI C;
  ELSE
    OPEN cResult FOR

      SELECT SIMBOL, 0, CODCONT, BALSINT, Sum(FII_BS) - BALSINT FII_BALSINT
      FROM (
        SELECT
          CONNECT_BY_ROOT CODCONT CODCONT,
          CONNECT_BY_ROOT SIMBOL SIMBOL,
          Coalesce(CONNECT_BY_ROOT BALANTASINTETICA,0) BALSINT,
          Coalesce(BALANTASINTETICA,0) FII_BS
        FROM (
          SELECT *
          FROM NCONT C
          WHERE C.CODCONT &lt;&gt; 0
            AND CASE WHEN l_clasa = 0 THEN 1 WHEN s_clasa = SubStr(C.SIMBOL,1,l_clasa) THEN 1 ELSE 0 END = 1 -- filtrare dupa CLASA
            AND EXISTS (SELECT 1 FROM NCONT1 C1 WHERE C1.CODCONT = C.CODCONT AND (C1.ANSTART*12+C1.LUNASTART) &lt;= p_ALFin)
        )
        CONNECT BY PRIOR CODCONT = CODPARINTE
      )
      GROUP BY CODCONT, SIMBOL, BALSINT;
  END IF;

  RETURN cResult;
END;

PROCEDURE GetContRec(p_CodCont IN NCont.Codcont%TYPE, v_rec IN OUT TMP_NCONT_BAL%ROWTYPE)
IS
BEGIN
  SELECT *
  INTO v_rec
  FROM TMP_NCONT_BAL
  WHERE CODCONT = p_CodCont;
END;

PROCEDURE Insert_Rec(p_rec IN tmp_list_balanta%ROWTYPE, tmpName IN VARCHAR2)
IS
  sInsert VARCHAR2(10000);
  v_TOTALCPD    Tmp_List_Balanta.TOTALCPD%TYPE;
  v_TOTALCPC    Tmp_List_Balanta.TOTALCPC%TYPE;
  v_TOTALCD     Tmp_List_Balanta.TOTALCD%TYPE;
  v_TOTALCC     Tmp_List_Balanta.TOTALCC%TYPE;
BEGIN
  IF Coalesce(p_rec.simbol,&apos;*&apos;) &lt;&gt; &apos;*&apos; AND
    (p_sintetic = 0 OR (p_sintetic = 1 AND p_rec.balantasintetica = 1))   -- filtrare dupa analitic / sintetic
  THEN
    -- stef 19.09.2011 corectie Sume de total sa fie calculate in funtie de solul initial trecut pe debit sau credit
    v_TOTALCPD    := p_rec.SOLDID + p_rec.RULAJPD;
    v_TOTALCPC    := p_rec.SOLDIC + p_rec.RULAJPC;
    v_TOTALCD     := p_rec.SOLDID + p_rec.RULAJCD;
    v_TOTALCC     := p_rec.SOLDIC + p_rec.RULAJCC;

    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
      CODCONTP, CODCONTS, CODCONTT,
      CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL, INDEX_SINTETIC, FRUNZA,
      CENTRUCOST, SIMBCENTRUCOST, SIMBOLSITFIN, SIMBPLANP, SIMBSINTETIC, DEN_SINTETIC,
      SOLDID, SOLDIC, SOLDIIFRS, SOLDIIFRSD, SOLDIIFRSC, SOLDIGRUP,
      RULAJPD, RULAJPC, RULAJPIFRS, RULAJPIFRSD, RULAJPIFRSC, RULAJPGRUP,
      TOTALCPD, TOTALCPC, RULAJD, RULAJC, RULAJIFRS, RULAJIFRSD, RULAJIFRSC, RULAJGRUP,
      RULAJCD, RULAJCC, TOTALCD, TOTALCC, SOLDFD, SOLDFC, SOLDFIFRS, SOLDFIFRSD, SOLDFIFRSC, SOLDFGRUP)
    VALUES(
      :CODCONTP, :CODCONTS, :CODCONTT,
      :CLASA, :SIMBOL, :DEN_CONT, :TIPCONT, :NAME, :BALANTASINTETICA, :NIVEL, :INDEX_SINTETIC, :FRUNZA,
      :CENTRUCOST, :SIMBCENTRUCOST, :SIMBOLSITFIN, :SIMBPLANP, :SIMBSINTETIC, :DEN_SINTETIC,
      :SOLDID, :SOLDIC, :SOLDIIFRS, :SOLDIIFRSD, :SOLDIIFRSC, :SOLDIGRUP,
      :RULAJPD, :RULAJPC, :RULAJPIFRS, :RULAJPIFRSD, :RULAJPIFRSC, :RULAJPGRUP,
      :TOTALCPD, :TOTALCPC, :RULAJD, :RULAJC, :RULAJIFRS, :RULAJIFRSD, :RULAJIFRSC, :RULAJGRUP,
      :RULAJCD, :RULAJCC, :TOTALCD, :TOTALCC, :SOLDFD, :SOLDFC, :SOLDFIFRS, :SOLDFIFRSD, :SOLDFIFRSC, :SOLDFGRUP)&apos; ;

    EXECUTE IMMEDIATE sInsert
    USING
      p_rec.codcontp, p_rec.codconts, p_rec.codcontt,
      p_rec.clasa, p_rec.simbol, p_rec.den_cont, p_rec.tipcont, p_rec.name, p_rec.balantasintetica, p_rec.nivel, p_idx_sintetic, 1,
      p_rec.centrucost, p_rec.simbcentrucost, p_rec.simbolsitfin, p_rec.simbplanp, p_rec.simbsintetic, p_rec.den_sintetic,
      p_rec.soldid, p_rec.soldic, p_rec.soldiifrs, p_rec.soldiifrsd, p_rec.soldiifrsc, p_rec.soldigrup,
      p_rec.rulajpd, p_rec.rulajpc, p_rec.rulajpifrs, p_rec.rulajpifrsd, p_rec.rulajpifrsc, p_rec.rulajpgrup,
      v_totalcpd, v_totalcpc, p_rec.rulajd, p_rec.rulajc, p_rec.rulajifrs, p_rec.rulajifrsd, p_rec.rulajifrsc, p_rec.rulajgrup,
      p_rec.rulajcd, p_rec.rulajcc, v_totalcd, v_totalcc, p_rec.soldfd, p_rec.soldfc, p_rec.soldfifrs, p_rec.soldfifrsd, p_rec.soldfifrsc, p_rec.soldfgrup;

    IF p_rec.codcont = -1 THEN
      PKG_LIST_BASE_UTILS.SET_LISTA_SIMBOL_LIPSA(p_rec.simbplanp);
    END IF;
  END IF;
END;

PROCEDURE Fill_RecTotals(v_bal IN TMP_LIST_BALANTA%ROWTYPE)
IS
  v_ncont       TMP_NCONT_BAL%ROWTYPE;
  v_codparinte  NUMBER(20);
  vSIMBPLANP    VARCHAR2(3200);
  v_AUX_CODCONT Tmp_List_Balanta.CODCONT%TYPE;
  v_TOTALCPD    Tmp_List_Balanta.TOTALCPD%TYPE;
  v_TOTALCPC    Tmp_List_Balanta.TOTALCPC%TYPE;
  v_TOTALCD     Tmp_List_Balanta.TOTALCD%TYPE;
  v_TOTALCC     Tmp_List_Balanta.TOTALCC%TYPE;
BEGIN
  v_codparinte := v_bal.codparinte;
  WHILE Coalesce(v_codparinte,0) &lt;&gt; 0 LOOP
    GetContRec(v_codparinte, v_ncont);

    IF  ((p_sintetic = 0 AND v_ncont.vizibilbalanta = 1) OR (p_sintetic = 1 AND v_ncont.balantasintetica = 1)) -- filtrare dupa analitic / sintetic
    THEN
      v_AUX_CODCONT := 0;
      v_TOTALCPD    := v_bal.SOLDID + v_bal.RULAJPD;
      v_TOTALCPC    := v_bal.SOLDIC + v_bal.RULAJPC;
      v_TOTALCD     := v_bal.SOLDID + v_bal.RULAJCD;
      v_TOTALCC     := v_bal.SOLDIC + v_bal.RULAJCC;

      UPDATE TMP_LIST_BALANTA
      SET SOLDID      = SOLDID      + v_bal.SOLDID,
          SOLDIC      = SOLDIC      + v_bal.SOLDIC,
          SOLDIIFRS   = SOLDIIFRS   + v_bal.SOLDIIFRS,
          SOLDIIFRSD  = SOLDIIFRSD  + v_bal.SOLDIIFRSD,
          SOLDIIFRSC  = SOLDIIFRSC  + v_bal.SOLDIIFRSC,
          SOLDIGRUP   = SOLDIGRUP   + v_bal.SOLDIGRUP,
          RULAJPD     = RULAJPD     + v_bal.RULAJPD,
          RULAJPC     = RULAJPC     + v_bal.RULAJPC,
          RULAJPIFRS  = RULAJPIFRS  + v_bal.RULAJPIFRS,
          RULAJPIFRSD = RULAJPIFRSD + v_bal.RULAJPIFRSD,
          RULAJPIFRSC = RULAJPIFRSC + v_bal.RULAJPIFRSC,
          RULAJPGRUP  = RULAJPGRUP  + v_bal.RULAJPGRUP,
          TOTALCPD    = TOTALCPD    + v_TOTALCPD,
          TOTALCPC    = TOTALCPC    + v_TOTALCPC,
          RULAJD      = RULAJD      + v_bal.RULAJD,
          RULAJC      = RULAJC      + v_bal.RULAJC,
          RULAJIFRS   = RULAJIFRS   + v_bal.RULAJIFRS,
          RULAJIFRSD  = RULAJIFRSD  + v_bal.RULAJIFRSD,
          RULAJIFRSC  = RULAJIFRSC  + v_bal.RULAJIFRSC,
          RULAJGRUP   = RULAJGRUP   + v_bal.RULAJGRUP,
          RULAJCD     = RULAJCD     + v_bal.RULAJCD,
          RULAJCC     = RULAJCC     + v_bal.RULAJCC,
          TOTALCD     = TOTALCD     + v_TOTALCD,
          TOTALCC     = TOTALCC     + v_TOTALCC,
          SOLDFD      = SOLDFD      + v_bal.SOLDFD,
          SOLDFC      = SOLDFC      + v_bal.SOLDFC,
          SOLDFIFRS   = SOLDFIFRS   + v_bal.SOLDFIFRS,
          SOLDFIFRSD  = SOLDFIFRSD  + v_bal.SOLDFIFRSD,
          SOLDFIFRSC  = SOLDFIFRSC  + v_bal.SOLDFIFRSC,
          SOLDFGRUP   = SOLDFGRUP   + v_bal.SOLDFGRUP
      WHERE CODCONT = v_ncont.codcont
      RETURNING CODCONT INTO v_aux_codcont;

      IF v_AUX_CODCONT = 0 THEN
        SELECT Max(SIMBOLPLANP) INTO vSIMBPLANP FROM TMP_NCONT1_BAL WHERE CODCONT = v_ncont.codcont;

        INSERT INTO TMP_LIST_BALANTA (
          CODCONT, CODCONTP, CODCONTS, CODCONTT,
          SIMBOL, CLASA, DEN_CONT, TIPCONT, NAME,
          BALANTASINTETICA, NIVEL, CODSINTETIC, CODPARINTE,
          CENTRUCOST, SIMBCENTRUCOST, SIMBOLSITFIN, SIMBPLANP, SIMBSINTETIC, DEN_SINTETIC,
          SOLDID,  SOLDIC,  SOLDIIFRS,  SOLDIIFRSD,  SOLDIIFRSC,  SOLDIGRUP,
          RULAJPD, RULAJPC, RULAJPIFRS, RULAJPIFRSD, RULAJPIFRSC, RULAJPGRUP,                    TOTALCPD, TOTALCPC,
          RULAJD,  RULAJC,  RULAJIFRS,  RULAJIFRSD,  RULAJIFRSC,  RULAJGRUP,  RULAJCD,  RULAJCC, TOTALCD,  TOTALCC,
          SOLDFD,  SOLDFC,  SOLDFIFRS,  SOLDFIFRSD,  SOLDFIFRSC,  SOLDFGRUP )
        VALUES (
          v_ncont.codcont, v_ncont.codcontp, v_ncont.codconts, v_ncont.codcontt,
          v_ncont.simbol, v_ncont.clasa, v_ncont.den_cont, CASE v_ncont.tipcont WHEN 1 THEN &apos;PASIV&apos; WHEN 2 THEN &apos;BIFUNC&apos; ELSE &apos;ACTIV&apos; END, v_ncont.name,
          Coalesce(v_ncont.balantasintetica,-1), v_ncont.nivel, v_bal.codsintetic, v_ncont.codparinte,
          v_bal.CENTRUCOST, v_bal.SIMBCENTRUCOST, v_ncont.SIMBOLSITFIN, vSIMBPLANP, v_bal.SIMBSINTETIC, v_bal.DEN_SINTETIC,
          v_bal.SOLDID,  v_bal.SOLDIC,  v_bal.SOLDIIFRS,  v_bal.SOLDIIFRSD,  v_bal.SOLDIIFRSC,  v_bal.SOLDIGRUP,
          v_bal.RULAJPD, v_bal.RULAJPC, v_bal.RULAJPIFRS, v_bal.RULAJPIFRSD, v_bal.RULAJPIFRSC, v_bal.RULAJPGRUP,                               v_TOTALCPD, v_TOTALCPC,
          v_bal.RULAJD,  v_bal.RULAJC,  v_bal.RULAJIFRS,  v_bal.RULAJIFRSD,  v_bal.RULAJIFRSC,  v_bal.RULAJGRUP,  v_bal.RULAJCD, v_bal.RULAJCC, v_TOTALCD,  v_TOTALCC,
          v_bal.SOLDFD,  v_bal.SOLDFC,  v_bal.SOLDFIFRS,  v_bal.SOLDFIFRSD,  v_bal.SOLDFIFRSC,  v_bal.SOLDFGRUP );
      END IF;

    END IF;
    v_codparinte := v_ncont.codparinte;
  END LOOP;
END;

PROCEDURE Insert_RecTotal(tmpName IN VARCHAR2)
IS
  sInsert   VARCHAR2(5000);
  sVFrunza  VARCHAR2(5000)  := &apos;0 FRUNZA&apos;;
  sJFrunza  VARCHAR2(5000)  := &apos;&apos;;
BEGIN
  IF p_sintetic = 1 THEN
    sVFrunza := &apos;Coalesce(X.FRUNZAS,0) FRUNZA&apos;;
    sJFrunza := &apos; LEFT JOIN TMP_NCONT1_BAL X ON X.CODCONT = T.CODCONT&apos;;
  END IF;
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    CODCONTP, CODCONTS, CODCONTT,
    CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL,
    SOLDID,
    SOLDIC,
    SOLDIIFRS,
    SOLDIIFRSD,
    SOLDIIFRSC,
    SOLDIGRUP,
    RULAJPD, RULAJPC, RULAJPIFRS, RULAJPIFRSD, RULAJPIFRSC, RULAJPGRUP, TOTALCPD, TOTALCPC,
    RULAJD,  RULAJC,  RULAJIFRS,  RULAJIFRSD,  RULAJIFRSC,  RULAJGRUP,
    RULAJCD, RULAJCC, TOTALCD, TOTALCC,
    SOLDFD,
    SOLDFC,
    SOLDFIFRS,
    SOLDFIFRSD,
    SOLDFIFRSC,
    SOLDFGRUP,
    INDEX_SINTETIC, FRUNZA, CENTRUCOST, SIMBCENTRUCOST, SIMBOLSITFIN, SIMBPLANP, SIMBSINTETIC, DEN_SINTETIC)
  SELECT
    T.CODCONTP, T.CODCONTS, T.CODCONTT,
    T.CLASA, T.SIMBOL, T.DEN_CONT, T.TIPCONT, T.NAME, T.BALANTASINTETICA, T.NIVEL,
    CASE
      WHEN T.TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN T.SOLDID - T.SOLDIC
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDID &gt; T.SOLDIC THEN T.SOLDID - T.SOLDIC
      ELSE 0
    END SOLDID,
    CASE
      WHEN T.TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN T.SOLDIC - T.SOLDID
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDIC &gt; T.SOLDID THEN T.SOLDIC - T.SOLDID
      ELSE 0
    END SOLDIC,
    T.SOLDIIFRS,
    CASE
      WHEN T.TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN T.SOLDIIFRSD - T.SOLDIIFRSC
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDIIFRSD &gt; T.SOLDIIFRSC THEN T.SOLDIIFRSD - T.SOLDIIFRSC
      ELSE 0
    END SOLDIIFRSD,
    CASE
      WHEN T.TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN T.SOLDIIFRSC - T.SOLDIIFRSD
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDIIFRSC &gt; T.SOLDIIFRSD THEN T.SOLDIIFRSC - T.SOLDIIFRSD
      ELSE 0
    END SOLDIIFRSC,
    T.SOLDIGRUP,
    T.RULAJPD, T.RULAJPC, T.RULAJPIFRS, T.RULAJPIFRSD, T.RULAJPIFRSC, T.RULAJPGRUP, T.TOTALCPD, T.TOTALCPC,
    T.RULAJD,  T.RULAJC,  T.RULAJIFRS,  T.RULAJIFRSD,  T.RULAJIFRSC,  T.RULAJGRUP,
    T.RULAJCD, T.RULAJCC, T.TOTALCD, T.TOTALCC,
    CASE
      WHEN T.TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN T.SOLDFD - T.SOLDFC
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDFD &gt; T.SOLDFC THEN T.SOLDFD - T.SOLDFC
      ELSE 0
    END SOLDFD,
    CASE
      WHEN T.TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN T.SOLDFC - T.SOLDFD
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDFC &gt; T.SOLDFD THEN T.SOLDFC - T.SOLDFD
      ELSE 0
    END SOLDFC,
    T.SOLDFIFRS,
    CASE
      WHEN T.TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN T.SOLDFIFRSD - T.SOLDFIFRSC
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDFIFRSD &gt; T.SOLDFIFRSC THEN T.SOLDFIFRSD - T.SOLDFIFRSC
      ELSE 0
    END SOLDFIFRSD,
    CASE
      WHEN T.TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN T.SOLDFIFRSC - T.SOLDFIFRSD
      WHEN T.TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND T.SOLDFIFRSC &gt; T.SOLDFIFRSD THEN T.SOLDFIFRSC - T.SOLDFIFRSD
      ELSE 0
    END SOLDFIFRSC,
    T.SOLDFGRUP,
    :INDEX_SINTETIC, &apos;||sVFrunza||&apos;, T.CENTRUCOST, T.SIMBCENTRUCOST, T.SIMBOLSITFIN, T.SIMBPLANP, T.SIMBSINTETIC, T.DEN_SINTETIC
  FROM TMP_LIST_BALANTA T&apos;||sJFrunza;

  EXECUTE IMMEDIATE sInsert USING p_IDX_SINTETIC;
  DELETE TMP_LIST_BALANTA;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE UMPLE_TMP_BALANTA IS
  cInsert            CLOB;
  cSelect            CLOB;
  cSelect0           CLOB;
  cCondAnLuna        CLOB;
  cCondSub           CLOB        := &apos;&apos;;
  cJoinSub           CLOB        := &apos;&apos;;
  nrSub              NUMBER;
  sV                 VARCHAR2(1) := CASE WHEN p_valuta = 2 THEN &apos;v&apos; ELSE &apos;&apos; END;
  sB                 VARCHAR2(5) := &apos;b&apos;;
  vRulALIni          NUMBER      := p_ALIni;
  cCondJurn          CLOB;
  sALIni             VARCHAR2(5) := To_Char(p_ALIni, &apos;fm99990&apos;);
  sALFin             VARCHAR2(5) := To_Char(p_ALFin, &apos;fm99990&apos;);
BEGIN
  SELECT Count(1) INTO nrSub FROM TMP_MANEVRA;
  IF nrSub = 0 AND p_PeSubunit = &apos;Da&apos; THEN
    INSERT INTO TMP_MANEVRA (CodUnic) VALUES (pkg_globals.GetSubunitate);
  END IF;

  IF p_PeSubunit = &apos;Da&apos; THEN
    sB       := &apos;bs&apos;;
    cCondSub := &apos;
    AND bs.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
  END IF;

  IF p_ALIni = p_ALFin
  THEN cCondAnLuna := &apos;b.an*12+b.luna = &apos;||sALIni;
  ELSE cCondAnLuna := &apos;b.an*12+b.luna BETWEEN &apos;||sALIni||&apos; AND &apos;||sALFin;
  END IF;

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LIST_BALANTA_BRUT&apos;, p_ListID, p_ListVer);

  cInsert := &apos;INSERT INTO TMP_LIST_BALANTA_BRUT(
    CODCONT, CODCOMUN, SIMBOLPLANP, OFFSET,
    SOLDID,  SOLDIC,  SOLDIIFRS,  SOLDIIFRSD,  SOLDIIFRSC,  SOLDIGRUP,
    RULAJPD, RULAJPC, RULAJPIFRS, RULAJPIFRSD, RULAJPIFRSC, RULAJPGRUP,
    RULAJD,  RULAJC,  RULAJIFRS,  RULAJIFRSD,  RULAJIFRSC,  RULAJGRUP )&apos;;

  IF p_PeSubunit = &apos;Da&apos; THEN
    cJoinSub := &apos;
    INNER JOIN ncontsoldsub BS ON BS.CODCONTSOLD = B.CODCONTSOLD&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;id,0) soldid, Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;ic,0) soldic, Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;i_ifrs,0) soldiifrs, 0 soldiifrsd, 0 soldiifrsc, Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;i_grup,0) soldigrup,
    0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpifrsd, 0 rulajpifrsc, 0 rulajpgrup,
    0 rulajd, 0 rulajc, 0 rulajifrs, 0 rulajifrsd, 0 rulajifrsc, 0 rulajgrup
  FROM ncontsold B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT&apos;||
    cJoinSub||&apos;
  WHERE (Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;id,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;ic,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;i_ifrs,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.sold&apos;||sV||&apos;i_grup,0) &lt;&gt; 0 )
    AND b.an = &apos;||To_Char(p_AnIni, &apos;fm9990&apos;)||&apos; AND b.luna = 1
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  -- atentie in ncontrul (ncontrulsub) campurile rulajcX se refara la rulaj curent (mai tarziu se va folosi rulajcX ca fiind rulaj cumulat)
  -- De ce :1 Fiindca aici s-a ajuns dupa modificari si s-a corectat de forma cea ma simpla !

  IF p_PeSubunit = &apos;Da&apos; THEN
    cJoinSub := &apos;
    INNER JOIN ncontrulsub BS ON BS.CODCONTRUL = B.CODCONTRUL&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid, 0 soldic, 0 soldiifrs, 0 soldiifrsd, 0 soldiifrsc, 0 soldigrup,
    CASE WHEN b.An*12+b.luna = &apos;||sALIni||&apos; THEN Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd,    0) ELSE 0 END rulajpd,
    CASE WHEN b.An*12+b.luna = &apos;||sALIni||&apos; THEN Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc,    0) ELSE 0 END rulajpc,
    CASE WHEN b.An*12+b.luna = &apos;||sALIni||&apos; THEN Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs,0) ELSE 0 END rulajpIFRS, 0 rulajpifrsd, 0 rulajpifrsc,
    CASE WHEN b.An*12+b.luna = &apos;||sALIni||&apos; THEN Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_grup,0) ELSE 0 END rulajpgrup,
    Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cd, 0) rulajd,  Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cc, 0) rulajc , Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_ifrs,0) rulajIFRS, 0 rulajifrsd, 0 rulajifrsc,  Coalesce(c.semn*&apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_grup,0) rulajgrup
  FROM ncontrul B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT&apos;||
    cJoinSub||&apos;
  WHERE (
      ((Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs,0) &lt;&gt; 0) AND (b.An*12+b.luna = &apos;||sALIni||&apos;)) OR
       (Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cd,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cc,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_ifrs,0) &lt;&gt; 0)
    )
    AND &apos;||cCondAnLuna||&apos;
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub;

  IF p_Lunara = &apos;Da&apos; THEN
    LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);
  END IF;

  -- p_Lunara = &apos;Nu&apos;
  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid, 0 soldic, 0 soldiifrs, 0 soldiifrsd, 0 soldiifrsc, 0 soldigrup,
    Coalesce(c.semn*b.rulaj&apos;||sV||&apos;pd,0) rulajpd, Coalesce(c.semn*b.rulaj&apos;||sV||&apos;pc,0) rulajpc, Coalesce(c.semn*b.rulaj&apos;||sV||&apos;p_ifrs,0) rulajpIFRS, 0 rulajpifrsd, 0 rulajpifrsc, Coalesce(c.semn*b.rulaj&apos;||sV||&apos;p_grup,0) rulajpgrup,
    Coalesce(c.semn*b.rulaj&apos;||sV||&apos;cd,0) rulajd,  Coalesce(c.semn*b.rulaj&apos;||sV||&apos;cc,0) rulajc,  Coalesce(c.semn*b.rulaj&apos;||sV||&apos;c_ifrs,0) rulajIFRS,  0 rulajifrsd,  0 rulajifrsc,  Coalesce(c.semn*b.rulaj&apos;||sV||&apos;c_grup,0) rulajgrup
  FROM tmp_ncontrul B INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
  WHERE (
      (Coalesce(b.rulaj&apos;||sV||&apos;pd,0) &lt;&gt; 0 OR Coalesce(b.rulaj&apos;||sV||&apos;pc,0) &lt;&gt; 0 OR Coalesce(b.rulaj&apos;||sV||&apos;p_ifrs,0) &lt;&gt; 0) OR
      (Coalesce(b.rulaj&apos;||sV||&apos;cd,0) &lt;&gt; 0 OR Coalesce(b.rulaj&apos;||sV||&apos;cc,0) &lt;&gt; 0 OR Coalesce(b.rulaj&apos;||sV||&apos;c_ifrs,0) &lt;&gt; 0)
    )
    AND &apos;||cCondAnLuna||&apos;
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;;
  IF p_Lunara = &apos;Nu&apos; THEN
    LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);
  END IF;

  IF p_PeSubunit = &apos;Da&apos; THEN
    cCondSub := &apos;
      AND b.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid,  0 soldic,  0 soldiifrs,  0 soldiifrsd,  0 soldiifrsc,  0 soldigrup,
    0 rulajpd, 0 rulajpc, 0 rulajpifrs, b.rulajpifrsd, 0 rulajpifrsc, 0 rulajpgrup,
    0 rulajd,  0 rulajc,  0 rulajifrs,  b.rulajifrsd,  0 rulajifrsc,  0 rulajgrup
  FROM (
    SELECT
      b.contd codcont,
      Sum(Case WHEN &apos;||cCondAnLuna||&apos; then 0 else b.valoare&apos;||sV||&apos;_ifrs end) rulajpifrsd,
      Sum(Case WHEN &apos;||cCondAnLuna||&apos; then b.valoare&apos;||sV||&apos;_ifrs else 0 end) rulajifrsd
    FROM jurnal B
    WHERE b.an*12+b.luna BETWEEN &apos;||To_Char(p_AnIni*12+1, &apos;fm99990&apos;)||&apos; AND &apos;||sALFin||&apos;
      AND Coalesce(b.valoare&apos;||sV||&apos;_ifrs, 0) &lt;&gt; 0&apos;||
      cCondSub||&apos;
    GROUP BY b.contd
  ) B INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
  WHERE c.codcont &lt;&gt; 0 AND c.frunza = 1&apos;;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid,  0 soldic,  0 soldiifrs,  0 soldiifrsd,  0 soldiifrsc,  0 soldigrup,
    0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpifrsd, b.rulajpifrsc, 0 rulajpgrup,
    0 rulajd,  0 rulajc,  0 rulajifrs,  0 rulajifrsd,  b.rulajifrsc,  0 rulajgrup
  FROM (
    SELECT
      b.contc codcont,
      Sum(Case WHEN &apos;||cCondAnLuna||&apos; then 0 else b.valoare&apos;||sV||&apos;_ifrs end) rulajpifrsc,
      Sum(Case WHEN &apos;||cCondAnLuna||&apos; then b.valoare&apos;||sV||&apos;_ifrs else 0 end) rulajifrsc
    FROM jurnal B
    WHERE b.an*12+b.luna BETWEEN &apos;||To_Char(p_AnIni*12+1, &apos;fm99990&apos;)||&apos; AND &apos;||sALFin||&apos;
      AND Coalesce(b.valoare&apos;||sV||&apos;_ifrs, 0) &lt;&gt; 0&apos;||
      cCondSub||&apos;
    GROUP BY b.contc
  ) B INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
  WHERE c.codcont &lt;&gt; 0 AND c.frunza = 1&apos;;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  IF p_PerFaraRul &gt; 0 THEN
    --0==Exclude conturile cu rulaj 0 in perioada selectata
    --8==Include toate conturile indiferent de rulaj
    --9==Include conturile rulaj 0 in perioada selectata dar cu miscari in perioada selectata
    --1==Include conturile rulaj 0 in perioada selectata dar cu miscari in anul curent
    --2==Include conturile rulaj 0 in perioada selectata dar cu miscari in ultimii 2 ani
    --3==Include conturile rulaj 0 in perioada selectata dar cu miscari in ultimii 3 ani
    IF p_PerFaraRul &lt; 9 THEN
      vRulALIni := (p_AnIni - p_PerFaraRul + 1)*12+1;
    END IF;

    IF vRulALIni = p_ALFin
    THEN cCondJurn := &apos;AND (j.an*12+j.luna) = &apos;||sALFin;
    ELSE cCondJurn := &apos;AND (j.an*12+j.luna) BETWEEN &apos;||To_Char(vRulALIni, &apos;fm99990&apos;)||&apos; AND &apos;||sALFin;
    END IF;

    IF  p_PeSubunit = &apos;Da&apos;
    THEN cCondJurn := cCondJurn ||&apos; AND j.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
    END IF;

    cSelect := &apos;
    SELECT
      c.codcont, c.codcomun, c.simbolplanp, c.offset,
      0 soldid, 0 soldic, 0 soldiifrs, 0 soldiifrsd, 0 soldiifrsc, 0 soldigrup,
      0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpifrsd, 0 rulajpifrsc, 0 rulajpgrup,
      0 rulajd, 0 rulajc, 0 rulajifrs, 0 rulajifrsd, 0 rulajifrsc, 0 rulajgrup
    FROM TMP_NCONT1_BAL C
    WHERE NOT Exists( SELECT 1 FROM TMP_LIST_BALANTA_BRUT T WHERE T.CodComun = C.CodComun)&apos;;

    IF p_PerFaraRul = 8 THEN
      LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);
    ELSE
      cSelect0 := cSelect||&apos;
      AND EXISTS (SELECT 1 FROM jurnal j WHERE j.contd = c.CodComun &apos;||cCondJurn||&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(cInsert||cSelect0, p_ListID, p_ListVer);

      cSelect0 := cSelect||&apos;
      AND EXISTS (SELECT 1 FROM jurnal j WHERE j.contc = c.CodComun &apos;||cCondJurn||&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(cInsert||cSelect0, p_ListID, p_ListVer);
    END IF;
  END IF;
  COMMIT;
END;

PROCEDURE UMPLE_TMP_BALANTA_AC IS
  cInsert            CLOB;
  cSelect            CLOB;
  vAI                NUMBER(4);
  vAC                NUMBER(4);
  vLI                NUMBER(2);
  vLC                NUMBER(2);
  ALC                NUMBER(5);
  ALI                NUMBER(5);
  cCondSub           CLOB;
  cJoinSub           CLOB        := &apos;&apos;;
  nrSub              NUMBER;
  sV                 VARCHAR2(1) := CASE WHEN p_valuta = 2 THEN &apos;v&apos; END;
  sB                 VARCHAR2(5) := &apos;b&apos;;
BEGIN
  SELECT Count(1) INTO nrSub FROM TMP_MANEVRA;
  IF nrSub = 0 AND p_PeSubunit = &apos;Da&apos; THEN
    INSERT INTO TMP_MANEVRA (CodUnic) VALUES (pkg_globals.GetSubunitate);
  END IF;

  IF p_PeSubunit = &apos;Da&apos; THEN
    sB := &apos;bs&apos;;
    cCondSub := &apos;
    AND bs.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
  END IF;

  vAC := p_AnIni;
  vLC := p_LunaFin;
  vLI := vLunaStartAnContab;
  IF vLI &gt; vLC
  THEN vAI := vAC - 1;
  ELSE vAI := vAC;
  END IF;

  ALC := vAC*12+vLC;
  ALI := vAI*12+vLI;

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LIST_BALANTA_BRUT&apos;, p_ListID, p_ListVer);

  cInsert := &apos;INSERT INTO TMP_LIST_BALANTA_BRUT(
    CODCONT, CODCOMUN, SIMBOLPLANP, OFFSET,
    SOLDID,  SOLDIC,  SOLDIIFRS,  SOLDIIFRSD,  SOLDIIFRSC,  SOLDIGRUP,
    RULAJPD, RULAJPC, RULAJPIFRS, RULAJPIFRSD, RULAJPIFRSC, RULAJPGRUP,
    RULAJD,  RULAJC,  RULAJIFRS,  RULAJIFRSD,  RULAJIFRSC,  RULAJGRUP )&apos;;

  IF p_PeSubunit = &apos;Da&apos; THEN
    cJoinSub := &apos;
    INNER JOIN ncontsoldsub BS ON BS.CODCONTSOLD = B.CODCONTSOLD&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    Coalesce(CASE WHEN b.an &lt;&gt; &apos;||To_Char(vAI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.sold&apos;||sV||&apos;id     END,0) soldid,
    Coalesce(CASE WHEN b.an &lt;&gt; &apos;||To_Char(vAI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.sold&apos;||sV||&apos;ic     END,0) soldic,
    Coalesce(CASE WHEN b.an &lt;&gt; &apos;||To_Char(vAI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.sold&apos;||sV||&apos;i_ifrs END,0) soldiifrs, 0 soldiifrsD, 0 soldiifrsC,
    Coalesce(CASE WHEN b.an &lt;&gt; &apos;||To_Char(vAI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.sold&apos;||sV||&apos;i_grup END,0) soldigrup,
    0 rulajpd,
    0 rulajpc,
    0 rulajpifrs, 0 rulajpifrsd, 0 rulajpifrsc,
    0 rulajpgrup,
    0 rulajd,
    0 rulajc,
    0 rulajifrs, 0 rulajifrsd, 0 rulajifrsc,
    0 rulajgrup
  FROM ncontsold B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT&apos;||
    cJoinSub||&apos;
  WHERE b.an * 12 + b.luna IN (&apos;||To_Char(vAI*12+1)||&apos;,&apos;||To_Char(vAC*12+1)||&apos;)
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  IF p_PeSubunit = &apos;Da&apos; THEN
    cJoinSub := &apos;
    INNER JOIN ncontrulsub BS ON BS.CODCONTRUL = B.CODCONTRUL&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd     END,0) soldid,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc     END,0) soldic,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs END,0) soldiifrs, 0 soldiifrsD, 0 soldiifrsC,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_grup END,0) soldigrup,&apos;||
  CASE WHEN vAC &lt;&gt; vAI THEN &apos;
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd END,0) + --rulaj precedent decembrie
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;cd END,0) + --rulaj curent decembrie&apos;
  END||&apos;
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd END,0) - --rulaj precedent curent
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd END,0) rulajpd, --rulaj precedent initial&apos;||
  CASE WHEN vAC &lt;&gt; vAI THEN &apos;
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc END,0) +
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;cc END,0) +&apos;
  END||&apos;
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc END,0) -
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc END,0) rulajpc,&apos;||
  CASE WHEN vAC &lt;&gt; vAI THEN &apos;
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs END,0) +
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_ifrs END,0) +&apos;
  END||&apos;
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs END,0) -
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs END,0) rulajpIFRS, 0 rulajpIFRSd, 0 rulajpIFRSc,&apos;||
  CASE WHEN vAC &lt;&gt; vAI THEN &apos;
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_grup END,0) +
    Coalesce(CASE WHEN b.luna &lt;&gt; 12 THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_grup END,0) +&apos;
  END||&apos;
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_grup END,0) -
    Coalesce(CASE WHEN b.an*12+b.luna &lt;&gt; &apos;||To_Char(ALI)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_grup END,0) rulajpgrup,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;cd     END,0) rulajd,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;cc     END,0) rulajc,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_ifrs END,0) rulajIFRS, 0 rulajIFRSd, 0 rulajIFRSc,
    Coalesce(CASE WHEN b.luna &lt;&gt; &apos;||To_Char(vLC)||&apos; THEN 0 ELSE &apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_grup END,0) rulajgrup
  FROM ncontrul B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT&apos;||
    cJoinSub||&apos;
  WHERE b.an*12+b.luna IN (&apos;||To_Char(ALI)||&apos;,&apos;||To_Char(vAI*12+12)||&apos;,&apos;||To_Char(ALC)||&apos;)
    AND b.an*12+b.luna &lt;= &apos;||To_Char(ALC)||&apos;
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  IF p_PeSubunit = &apos;Da&apos; THEN
    cCondSub := &apos;
    AND b.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
  END IF;

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid,  0 soldic,  0 soldiifrs,  0                                                                                         soldiifrsd,  0 soldiifrsc,  0 soldigrup,
    0 rulajpd, 0 rulajpc, 0 rulajpifrs, Sum(Case WHEN b.an*12+b.luna = &apos;||To_Char(ALC)||&apos; then 0 else b.valoare&apos;||sV||&apos;_ifrs end) rulajpifrsd, 0 rulajpifrsc, 0 rulajpgrup,
    0 rulajd,  0 rulajc,  0 rulajifrs,  Sum(Case WHEN b.an*12+b.luna = &apos;||To_Char(ALC)||&apos; then b.valoare&apos;||sV||&apos;_ifrs else 0 end) rulajifrsd,  0 rulajifrsc,  0 rulajgrup
  FROM jurnal B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CONTD
  WHERE b.an*12+b.luna BETWEEN &apos;||To_Char(ALI)||&apos; AND &apos;||To_Char(ALC)||&apos;
    AND Coalesce(b.valoare&apos;||sV||&apos;_ifrs, 0) &lt;&gt; 0
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub||&apos;
  GROUP BY c.codcont, c.codcomun, c.simbolplanp, c.offset&apos;;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  cSelect := &apos;
  SELECT
    c.codcont, c.codcomun, c.simbolplanp, c.offset,
    0 soldid,  0 soldic,  0 soldiifrs,  0 soldiifrsd,  0                                                                                         soldiifrsc,  0 soldigrup,
    0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpifrsd, Sum(Case WHEN b.an*12+b.luna = &apos;||To_Char(ALC)||&apos; then 0 else b.valoare&apos;||sV||&apos;_ifrs end) rulajpifrsc, 0 rulajpgrup,
    0 rulajd,  0 rulajc,  0 rulajifrs,  0 rulajifrsd,  Sum(Case WHEN b.an*12+b.luna = &apos;||To_Char(ALC)||&apos; then b.valoare&apos;||sV||&apos;_ifrs else 0 end) rulajifrsc,  0 rulajgrup
  FROM jurnal B
    INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CONTC
  WHERE b.an*12+b.luna BETWEEN &apos;||To_Char(ALI)||&apos; AND &apos;||To_Char(ALC)||&apos;
    AND Coalesce(b.valoare&apos;||sV||&apos;_ifrs, 0) &lt;&gt; 0
    AND c.codcont &lt;&gt; 0
    AND c.frunza = 1&apos;||
    cCondSub||&apos;
  GROUP BY c.codcont, c.codcomun, c.simbolplanp, c.offset&apos;;
  LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);

  LIST_EXECUTE_IMMEDIATE(&apos;DELETE TMP_LIST_BALANTA_BRUT WHERE soldid = 0 AND soldic = 0 AND soldiifrs = 0 AND soldiifrsd = 0 AND soldiifrsc = 0 AND soldigrup = 0 AND rulajpd = 0 AND rulajpc = 0 AND rulajpIFRS = 0 AND rulajpIFRSD = 0 AND rulajpIFRSC = 0 AND rulajpgrup = 0 AND rulajd = 0 AND rulajc = 0 AND rulajIFRS = 0 AND rulajIFRSD = 0 AND rulajIFRSC = 0 AND rulajgrup = 0&apos;, p_ListID, p_ListVer);
  IF p_PerFaraRul &gt; 0  THEN
    IF  p_PeSubunit = &apos;Da&apos; THEN
      cJoinSub := &apos; INNER JOIN ncontrulsub BS ON BS.CODCONTRUL = B.CODCONTRUL&apos;;
      cCondSub := &apos;
          AND bs.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)&apos;;
    END IF;

    cSelect := &apos;
    SELECT
      c.codcont, c.codcomun, c.simbolplanp, c.offset,
      0 soldid, 0 soldic, 0 soldiifrs, 0 soldiifrsd, 0 soldiifrsc, 0 soldigrup,
      0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpifrsd, 0 rulajpifrsc, 0 rulajpgrup,
      0 rulajd, 0 rulajc, 0 rulajifrs, 0 rulajifrsd, 0 rulajifrsc, 0 rulajgrup
    FROM TMP_NCONT1_BAL C
    WHERE NOT Exists( SELECT 1 FROM TMP_LIST_BALANTA_BRUT T WHERE T.CodComun = C.CodComun)
      AND EXISTS (
        SELECT 1
        FROM ncontrul B&apos;||cJoinSub||&apos;
        WHERE C.CODCOMUN = B.CODCONT AND b.an*12+b.luna BETWEEN &apos;||To_Char(ALI-12*(p_PerFaraRul-1))||&apos; AND &apos;||To_Char(ALC)||&apos;
          AND (Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pd,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;pc,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;p_ifrs,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cd,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;cc,0) &lt;&gt; 0 OR Coalesce(&apos;||sB||&apos;.rulaj&apos;||sV||&apos;c_ifrs,0) &lt;&gt; 0 )&apos;||
          cCondSub||&apos;
      )&apos;;
    LIST_EXECUTE_IMMEDIATE(cInsert||cSelect, p_ListID, p_ListVer);
  END IF;

  COMMIT;
END;

PROCEDURE PROCESSBALANTA(tmpName IN VARCHAR2) IS
  v_prev_codsintetic NUMBER(20)  := -1;
BEGIN
  FOR v_rec IN (
		WITH
      /*RECURSIVE*/ cRec (
          codcont, codcontp, codconts, codcontt, clasa, nivel, simbol, den_cont, tipcont,
				  name, balantasintetica, codsintetic, simbsintetic, den_sintetic, codparinte,
				  vizibilbalanta, centrucost, simbcentrucost, simbolsitfin
      ) AS (
			  SELECT
				  tnb.codcont, tnb.codcontp, tnb.codconts, tnb.codcontt, tnb.clasa, 1 nivel, tnb.simbol, tnb.den_cont, tnb.tipcont,
				  tnb.name, tnb.balantasintetica, tnb.codcont codsintetic, tnb.simbol simbsintetic, tnb.den_cont den_sintetic, tnb.codparinte,
				  tnb.vizibilbalanta, tnb.centrucost, tnb.simbcentrucost, tnb.simbolsitfin
			  FROM tmp_ncont_bal tnb
			  WHERE coalesce(codparinte, 0) = 0
			  UNION ALL
			  SELECT
				  tnbi.codcont, tnbi.codcontp, tnbi.codconts, tnbi.codcontt, tnbi.clasa, cr.nivel+1 as nivel, tnbi.simbol, tnbi.den_cont, tnbi.tipcont,
				  tnbi.name, tnbi.balantasintetica, cr.codsintetic, cr.simbsintetic, cr.den_sintetic, tnbi.codparinte,
				  tnbi.vizibilbalanta, tnbi.centrucost, tnbi.simbcentrucost, tnbi.simbolsitfin
			  FROM tmp_ncont_bal tnbi JOIN cRec cr on cr.codcont = tnbi.codparinte
		  ),
		  CONTURI AS (
			  SELECT
          cc.codcont, cc.codcontp, cc.codconts, cc.codcontt, cc.clasa, cc.simbol, cc.den_cont, coalesce(cc.tipcont, 0) tipcont, cc.name, cc.balantasintetica, cc.nivel,
          cc.codsintetic, cc.simbsintetic, cc.den_sintetic, cc.codparinte,
          CASE WHEN NOT EXISTS (SELECT 1 FROM cRec c2r WHERE c2r.codparinte = cc.codcont) THEN 1 ELSE 0 END AS fara_fii,
          cc.vizibilbalanta, cc.centrucost, cc.simbcentrucost, cc.simbolsitfin
			  FROM cRec cc
			  ORDER BY cc.CLASA , cc.SIMBOL
		  ),
      BALANTA AS (
        SELECT
          codcont,
          vc2_nt_to_vc3200_dist(CAST(COLLECT(simbolplanp ORDER BY simbolplanp) AS vc2_nt)) simbplanp,
          SUM(CASE WHEN offset = 1 THEN soldic  ELSE soldid  END)/p_curs soldid,  SUM(CASE WHEN offset = 1 THEN soldid  ELSE soldic  END)/p_curs soldic, SUM(soldiifrs)/p_curs soldiifrs, SUM(soldigrup)/p_curs soldigrup,
          SUM(CASE WHEN offset = 1 THEN rulajpc ELSE rulajpd END)/p_curs rulajpd, SUM(CASE WHEN offset = 1 THEN rulajpd ELSE rulajpc END)/p_curs rulajpc,
          SUM(CASE WHEN offset = 1 THEN rulajpifrsc ELSE rulajpifrsd END)/p_curs rulajpifrsd, SUM(CASE WHEN offset = 1 THEN rulajpifrsd ELSE rulajpifrsc END)/p_curs rulajpifrsc,
          SUM(rulajpifrs)/p_curs rulajpifrs, SUM(rulajpgrup)/p_curs rulajpgrup,
          SUM(CASE WHEN offset = 1 THEN rulajc  ELSE rulajd  END)/p_curs rulajd,  SUM(CASE WHEN offset = 1 THEN rulajd  ELSE rulajc  END)/p_curs rulajc,
          SUM(CASE WHEN offset = 1 THEN rulajifrsc ELSE rulajifrsd END)/p_curs rulajifrsd, SUM(CASE WHEN offset = 1 THEN rulajifrsd ELSE rulajifrsc END)/p_curs rulajifrsc,
          SUM(rulajifrs) /p_curs rulajifrs,  SUM(rulajgrup) /p_curs rulajgrup,
          SUM(CASE WHEN offset = 1 THEN soldic + rulajpc + rulajc ELSE soldid + rulajpd + rulajd END)/p_curs totalcd,
          SUM(CASE WHEN offset = 1 THEN soldid + rulajpd + rulajd ELSE soldic + rulajpc + rulajc END)/p_curs totalcc,
          SUM(soldiifrs + rulajpifrs + rulajifrs)/p_curs soldfifrs,
          SUM(soldigrup + rulajpgrup + rulajgrup)/p_curs soldfgrup
        FROM TMP_LIST_BALANTA_BRUT
        GROUP BY codcont
      )
    -- in selectul urmator facand referire la comentariul anterior xxxCD sau xxxCC inseamna xxx CUMULAT (nu curent) debitor (respectiv creditor)
    SELECT
      C.CODCONT, C.CODCONTP, C.CODCONTS, C.CODCONTT, C.CLASA, C.SIMBOL, C.DEN_CONT, CASE C.TIPCONT WHEN 1 THEN &apos;PASIV&apos; WHEN 2 THEN &apos;BIFUNC&apos; ELSE &apos;ACTIV&apos; END TIPCont, C.NAME,
      C.BALANTASINTETICA, C.NIVEL, C.CODSINTETIC, C.CODPARINTE,
      CASE WHEN TIPCONT=2 AND B.SOLDID &gt; B.SOLDIC THEN B.SOLDID - B.SOLDIC WHEN TIPCONT=0 THEN B.SOLDID - B.SOLDIC ELSE 0 END AS SOLDID,
      CASE WHEN TIPCONT=2 AND B.SOLDIC &gt; B.SOLDID THEN B.SOLDIC - B.SOLDID WHEN TIPCONT=1 THEN B.SOLDIC - B.SOLDID ELSE 0 END AS SOLDIC,
      B.SOLDIIFRS,
      CASE WHEN TIPCONT=2 AND B.SOLDIIFRS &gt; 0 THEN  B.SOLDIIFRS WHEN TIPCONT=0 THEN  B.SOLDIIFRS ELSE 0 END AS SOLDIIFRSD,
      CASE WHEN TIPCONT=2 AND B.SOLDIIFRS &lt; 0 THEN -B.SOLDIIFRS WHEN TIPCONT=1 THEN -B.SOLDIIFRS ELSE 0 END AS SOLDIIFRSC,
      B.SOLDIGRUP,
      B.RULAJPD, B.RULAJPC, B.RULAJPIFRS, B.RULAJPIFRSD, B.RULAJPIFRSC, B.RULAJPGRUP,
      (B.SOLDID + B.RULAJPD) TOTALCPD, (B.SOLDIC + B.RULAJPC) TOTALCPC,
      B.RULAJD, B.RULAJC, B.RULAJIFRS, B.RULAJIFRSD, B.RULAJIFRSC, B.RULAJGRUP,
      (B.RULAJD + B.RULAJPD) RULAJCD, (B.RULAJC + B.RULAJPC) RULAJCC,
      B.TOTALCD, B.TOTALCC,
      CASE WHEN TIPCONT=2 AND B.TOTALCD &gt; B.TOTALCC THEN B.TOTALCD - B.TOTALCC WHEN TIPCONT=0 THEN B.TOTALCD - B.TOTALCC ELSE 0 END AS SOLDFD,
      CASE WHEN TIPCONT=2 AND B.TOTALCC &gt; B.TOTALCD THEN B.TOTALCC - B.TOTALCD WHEN TIPCONT=1 THEN B.TOTALCC - B.TOTALCD ELSE 0 END AS SOLDFC,
      B.SOLDFIFRS,
      CASE WHEN TIPCONT=2 AND B.SOLDFIFRS &gt; 0 THEN  B.SOLDFIFRS WHEN TIPCONT=0 THEN  B.SOLDFIFRS ELSE 0 END AS SOLDFIFRSD,
      CASE WHEN TIPCONT=2 AND B.SOLDFIFRS &lt; 0 THEN -B.SOLDFIFRS WHEN TIPCONT=1 THEN -B.SOLDFIFRS ELSE 0 END AS SOLDFIFRSC,
      B.SOLDFGRUP,
      C.CENTRUCOST, C.SIMBCENTRUCOST, C.SIMBOLSITFIN,
      B.SIMBPLANP, C.SIMBSINTETIC, C.DEN_SINTETIC
    FROM CONTURI C INNER JOIN BALANTA B ON B.CODCONT = C.CODCONT
    WHERE C.FARA_FII = 1 AND C.VIZIBILBALANTA = 1
    ORDER BY C.CLASA, C.SIMBSINTETIC
  ) LOOP
    if coalesce(p_LISTID,0) &lt;&gt; 487 THEN -- balanta bruta KPMG -- coalesce pentru cand vine din sitfin
			IF v_rec.codsintetic &lt;&gt; v_prev_codsintetic THEN
				 IF p_IDX_SINTETIC &gt; 0 THEN
					 Insert_RecTotal(tmpName);
				 END IF;
				 p_IDX_SINTETIC := p_IDX_SINTETIC + 1;
				 v_prev_codsintetic := v_rec.codsintetic;
			END IF;
    end if;
		Fill_RecTotals(v_rec);
		Insert_Rec(v_rec,tmpName);
  END LOOP;
  if coalesce(p_LISTID,0) &lt;&gt; 487 THEN-- coalesce pentru cand vine din sitfin
    Insert_RecTotal(tmpName);
	end if;
  COMMIT;
END;

PROCEDURE PROCESSBALANTAFIRME(tmpName IN VARCHAR2) IS
  v_prev_codsintetic NUMBER(20)  := -1;
  vTest VARCHAR2(30000);
BEGIN
  FOR v_rec IN (
		WITH
      /*RECURSIVE*/ cRec (
          codcont, codcontp, codconts, codcontt, clasa, nivel, simbol, den_cont, tipcont,
				  name, balantasintetica, codsintetic, simbsintetic, den_sintetic, codparinte,
				  vizibilbalanta, centrucost, simbcentrucost, simbolsitfin
      ) AS (
			  SELECT
				  tnb.codcont, tnb.codcontp, tnb.codconts, tnb.codcontt, tnb.clasa, 1 nivel, tnb.simbol, tnb.den_cont, tnb.tipcont,
				  tnb.name, tnb.balantasintetica, tnb.codcont codsintetic, tnb.simbol simbsintetic, tnb.den_cont den_sintetic, tnb.codparinte,
				  tnb.vizibilbalanta, tnb.centrucost, tnb.simbcentrucost, tnb.simbolsitfin
			  FROM tmp_ncont_bal tnb
			  WHERE coalesce(codparinte, 0) = 0
			  UNION ALL
			  SELECT
				  tnbi.codcont, tnbi.codcontp, tnbi.codconts, tnbi.codcontt, tnbi.clasa, cr.nivel+1 as nivel, tnbi.simbol, tnbi.den_cont, tnbi.tipcont,
				  tnbi.name, tnbi.balantasintetica, cr.codsintetic, cr.simbsintetic, cr.den_sintetic, tnbi.codparinte,
				  tnbi.vizibilbalanta, tnbi.centrucost, tnbi.simbcentrucost, tnbi.simbolsitfin
			  FROM tmp_ncont_bal tnbi JOIN cRec cr on cr.codcont = tnbi.codparinte
		  ),
		  CONTURI AS (
			  SELECT
          cc.codcont, cc.codcontp, cc.codconts, cc.codcontt, cc.clasa, cc.simbol, cc.den_cont, coalesce(cc.tipcont, 0) tipcont, cc.name, cc.balantasintetica, cc.nivel,
          cc.codsintetic, cc.simbsintetic, cc.den_sintetic, cc.codparinte,
          CASE WHEN NOT EXISTS (SELECT 1 FROM cRec c2r WHERE c2r.codparinte = cc.codcont) THEN 1 ELSE 0 END AS fara_fii,
          cc.vizibilbalanta, cc.centrucost, cc.simbcentrucost, cc.simbolsitfin
			  FROM cRec cc
			  ORDER BY cc.CLASA , cc.SIMBOL
		  ),
      BALANTA AS (
        SELECT
          CODCONT,
          SUM(CASE WHEN p_valuta = 2 THEN soldvid      ELSE soldid      END)/p_curs soldid,      SUM(CASE WHEN p_valuta = 2 THEN soldvic      ELSE soldic      END)/p_curs soldic,
          SUM(CASE WHEN p_valuta = 2 THEN soldviifrs   ELSE soldiifrs   END)/p_curs soldiifrs,   SUM(CASE WHEN p_valuta = 2 THEN soldvigrup   ELSE soldigrup   END)/p_curs soldigrup,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvpd     ELSE rulajpd     END)/p_curs rulajpd,     SUM(CASE WHEN p_valuta = 2 THEN rulajvpc     ELSE rulajpc     END)/p_curs rulajpc,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvpifrsd ELSE rulajpifrsd END)/p_curs rulajpifrsd, SUM(CASE WHEN p_valuta = 2 THEN rulajvpifrsc ELSE rulajpifrsc END)/p_curs rulajpifrsc,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvpifrs  ELSE rulajpifrs  END)/p_curs rulajpifrs,  SUM(CASE WHEN p_valuta = 2 THEN rulajvpgrup  ELSE rulajpgrup  END)/p_curs rulajpgrup,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvcd     ELSE rulajcd     END)/p_curs rulajd,      SUM(CASE WHEN p_valuta = 2 THEN rulajvcc     ELSE rulajcc     END)/p_curs rulajc,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvcifrsd ELSE rulajcifrsd END)/p_curs rulajifrsd,  SUM(CASE WHEN p_valuta = 2 THEN rulajvcifrsc ELSE rulajcifrsc END)/p_curs rulajifrsc,
          SUM(CASE WHEN p_valuta = 2 THEN rulajvcifrs  ELSE rulajcifrs  END)/p_curs rulajifrs,   SUM(CASE WHEN p_valuta = 2 THEN rulajvcgrup  ELSE rulajcgrup  END)/p_curs rulajgrup,
          SUM(CASE WHEN p_valuta = 2 THEN soldvid + rulajvpd + rulajvcd          ELSE soldid + rulajpd + rulajcd          END)/p_curs totalcd,
          SUM(CASE WHEN p_valuta = 2 THEN soldvic + rulajvpc + rulajvcc          ELSE soldic + rulajpc + rulajcc          END)/p_curs totalcc,
          SUM(CASE WHEN p_valuta = 2 THEN soldviifrs + rulajvpifrs + rulajvcifrs ELSE soldiifrs + rulajpifrs + rulajcifrs END)/p_curs soldfifrs,
          SUM(CASE WHEN p_valuta = 2 THEN soldvigrup + rulajvpgrup + rulajvcgrup ELSE soldigrup + rulajpgrup + rulajcgrup END)/p_curs soldfgrup
        FROM TMP_LIST_BALCUMUL
        GROUP BY CODCONT)
    SELECT
      C.CODCONT, C.CODCONTP, C.CODCONTS, C.CODCONTT, C.CLASA, C.SIMBOL, C.DEN_CONT, CASE C.TIPCONT WHEN 1 THEN &apos;PASIV&apos; WHEN 2 THEN &apos;BIFUNC&apos; ELSE &apos;ACTIV&apos; END AS TIPCont, NULL AS NAME,
      C.BALANTASINTETICA, C.NIVEL, C.CODSINTETIC, C.CODPARINTE,
      CASE WHEN TIPCONT=2 AND B.SOLDID &gt; B.SOLDIC THEN B.SOLDID - B.SOLDIC WHEN TIPCONT=0 THEN B.SOLDID - B.SOLDIC ELSE 0 END AS SOLDID,
      CASE WHEN TIPCONT=2 AND B.SOLDIC &gt; B.SOLDID THEN B.SOLDIC - B.SOLDID WHEN TIPCONT=1 THEN B.SOLDIC - B.SOLDID ELSE 0 END AS SOLDIC,
      B.SOLDIIFRS,
      CASE WHEN TIPCONT=2 AND B.SOLDIIFRS &gt; 0 THEN  B.SOLDIIFRS WHEN TIPCONT=0 THEN  B.SOLDIIFRS ELSE 0 END AS SOLDIIFRSD,
      CASE WHEN TIPCONT=2 AND B.SOLDIIFRS &lt; 0 THEN -B.SOLDIIFRS WHEN TIPCONT=1 THEN -B.SOLDIIFRS ELSE 0 END AS SOLDIIFRSC,
      B.SOLDIGRUP,
      B.RULAJPD, B.RULAJPC, B.RULAJPIFRS, B.RULAJPIFRSD, B.RULAJPIFRSC, B.RULAJPGRUP,
      (B.SOLDID + B.RULAJPD) AS TOTALCPD, (B.SOLDIC + B.RULAJPC) AS TOTALCPC,
      B.RULAJD, B.RULAJC, B.RULAJIFRS, B.RULAJIFRSD, B.RULAJIFRSC, B.RULAJGRUP,
      (B.RULAJD + B.RULAJPD) AS RULAJCD, (B.RULAJC + B.RULAJPC) AS RULAJCC, B.TOTALCD, B.TOTALCC,
      CASE WHEN TIPCONT=2 AND B.TOTALCD &gt; B.TOTALCC THEN B.TOTALCD - B.TOTALCC WHEN TIPCONT=0 THEN B.TOTALCD - B.TOTALCC ELSE 0 END AS SOLDFD,
      CASE WHEN TIPCONT=2 AND B.TOTALCC &gt; B.TOTALCD THEN B.TOTALCC - B.TOTALCD WHEN TIPCONT=1 THEN B.TOTALCC - B.TOTALCD ELSE 0 END AS SOLDFC,
      B.SOLDFIFRS,
      CASE WHEN TIPCONT=2 AND B.SOLDFIFRS &gt; 0 THEN  B.SOLDFIFRS WHEN TIPCONT=0 THEN  B.SOLDFIFRS ELSE 0 END AS SOLDFIFRSD,
      CASE WHEN TIPCONT=2 AND B.SOLDFIFRS &lt; 0 THEN -B.SOLDFIFRS WHEN TIPCONT=1 THEN -B.SOLDFIFRS ELSE 0 END AS SOLDFIFRSC,
      B.SOLDFGRUP,
      C.CENTRUCOST, C.SIMBCENTRUCOST, C.SIMBOLSITFIN,
      C.SIMBOL SIMBPLANP, C.SIMBSINTETIC, C.DEN_SINTETIC
    FROM CONTURI C INNER JOIN BALANTA B ON B.CODCONT = C.CODCONT
    ORDER BY C.CLASA, C.SIMBSINTETIC
  ) LOOP
    IF v_rec.codsintetic &lt;&gt; v_prev_codsintetic THEN
       IF p_IDX_SINTETIC &gt; 0 THEN
         Insert_RecTotal(tmpName);
       END IF;
       p_IDX_SINTETIC := p_IDX_SINTETIC + 1;
       v_prev_codsintetic := v_rec.codsintetic;
    END IF;

    Fill_RecTotals(v_rec);
    Insert_Rec(v_rec,tmpName);
  END LOOP;
  Insert_RecTotal(tmpName);
  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  PRC_AL_CHECK(&apos;CONSTLUNA&apos;);

  p_LISTID  := aLISTID;
  p_LISTVER := aLISTVER;

  gSuplCols := tmpName||&apos; T&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_NCONT_BAL&apos;,  &apos;TC&apos;,  &apos;TC.CODCONT  = T.CODCONTP&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_NCONT1_BAL&apos;, &apos;TC1&apos;, &apos;TC1.CODCONT = T.CODCONTP&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,          &apos;CP&apos;,  &apos;CP.CODCONT  = T.CODCONTP&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;,         &apos;CS&apos;,  &apos;CS.CODCONTS = T.CODCONTS&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTT&apos;,         &apos;CT&apos;,  &apos;CT.CODCONTT = T.CODCONTT&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  g_tmpTABLE         := tmpName;
  p_IDX_SINTETIC     := 0;
  vLunaStartAnContab := Coalesce(pkg_categconst.GetValConstanta(&apos;LunaStartAnContab&apos;, p_AnFin, p_LunaFin),&apos;1&apos;);
  IF aLISTID = 138 THEN -- balantacumulata firme
    PROCESSBALANTAFIRME(tmpName);
  ELSIF aLISTID = 342 AND vLunaStartAnContab &gt; 1 THEN -- balanta pentru an contabil care nu incepe in ianuarie
    UMPLE_TMP_BALANTA_AC;
    PROCESSBALANTA(tmpName);
  ELSE
    UMPLE_TMP_BALANTA;
    PROCESSBALANTA(tmpName);
  END IF;

  IF gUserFields IS NOT NULL THEN
    -- stef - elimin virgula de la inceput fiindca e update
    gUserFields := SubStr(gUserFields,2);
    gUserAlias  := SubStr(gUserAlias,2);
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; lst_tmp SET (&apos;||gUserFields||&apos;) = (SELECT &apos;||gUserAlias||&apos; FROM &apos;||tmpName||&apos; t &apos;||gSuplJoins||&apos; WHERE t.rowid = lst_tmp.rowid)&apos;;
    COMMIT;
  END IF;

  IF p_sintetic = 1 THEN
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET TOTALCPD = SOLDID + RULAJPD, TOTALCPC = SOLDIC + RULAJPC, TOTALCD = SOLDID + RULAJCD, TOTALCC = SOLDIC + RULAJCC&apos;;
    COMMIT;
  END IF;
	IF aListID = 487 THEN
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET SIMBOl = TRIM(SIMBOL)&apos;;
    COMMIT;
  ELSE
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET SIMBOl = LPAD(&apos;&apos; &apos;&apos;,NIVEL-1,&apos;&apos; &apos;&apos;)||TRIM(SIMBOL)&apos;;
    COMMIT;
	END IF;

--  BEGIN EXECUTE IMMEDIATE &apos;DROP TABLE XXX_NCONT_BAL         PURGE&apos;; EXCEPTION WHEN OTHERS THEN NULL; END;
--  BEGIN EXECUTE IMMEDIATE &apos;DROP TABLE XXX_LIST_BALANTA_BRUT PURGE&apos;; EXCEPTION WHEN OTHERS THEN NULL; END;
--  BEGIN EXECUTE IMMEDIATE &apos;DROP TABLE XXX_LIST_BALCUMUL     PURGE&apos;; EXCEPTION WHEN OTHERS THEN NULL; END;
--  BEGIN EXECUTE IMMEDIATE &apos;DROP TABLE XXX_BALANTA           PURGE&apos;; EXCEPTION WHEN OTHERS THEN NULL; END;
--  EXECUTE IMMEDIATE &apos;CREATE TABLE XXX_NCONT_BAL AS SELECT * FROM TMP_NCONT_BAL&apos;;
--  EXECUTE IMMEDIATE &apos;CREATE TABLE XXX_LIST_BALANTA_BRUT AS SELECT * FROM TMP_LIST_BALANTA_BRUT&apos;;
--  EXECUTE IMMEDIATE &apos;CREATE TABLE XXX_LIST_BALCUMUL AS SELECT * FROM TMP_LIST_BALCUMUL&apos;;
--  EXECUTE IMMEDIATE &apos;CREATE TABLE XXX_BALANTA AS SELECT * FROM &apos;||tmpName;
END;

FUNCTION SaveBalanta (anLuna in varchar2, TmpName in varchar2 ) RETURN NUMBER is
  TAB_BALANTA VARCHAR2(30);
  iRESULT NUMBER(1);
BEGIN
  TAB_BALANTA :=&apos;LST_BALANTA_&apos;||ANLUNA;
  SELECT COUNT(*) INTO IRESULT FROM USER_TABLES WHERE UPPER(TABLE_NAME) = UPPER(TAB_BALANTA);

  IF IRESULT &gt; 0 THEN
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||TAB_BALANTA;
    EXCEPTION
      WHEN OTHERS THEN RETURN 2;
    END;
  END IF;

  IF UPPER(TmpName) &lt;&gt; &apos;DEL&apos; THEN
		BEGIN
			EXECUTE IMMEDIATE &apos;CREATE TABLE &apos;||TAB_BALANTA||&apos; AS SELECT * FROM &apos;||TmpName;
		EXCEPTION
			WHEN OTHERS THEN RETURN 2;
		END;
  END IF;

  RETURN 1;
END;

FUNCTION COMPARE_BALANTA (ANLUNA IN VARCHAR2) return crs IS
  s varchar2(1000);
  tmpveki varchar2(30);
  cnt number(1);
  cResult crs;
BEGIN
  DELETE FROM DIFERENTE_BALANTA;

  tmpveki := &apos;LST_BALANTA_&apos;||ANLUNA;

  SELECT COUNT(*) INTO cnt FROM USER_TABLES WHERE UPPER(TABLE_NAME) = UPPER(TMPVEKI);
  IF cnt &lt;&gt; 1 THEN
    INSERT INTO DIFERENTE_BALANTA(Simbol) VALUES (0);
    COMMIT;
    OPEN cResult FOR SELECT * FROM DIFERENTE_BALANTA;
    RETURN cResult;
  END IF;

  S :=&apos; INSERT INTO DIFERENTE_BALANTA (SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,NOU) &apos;||
      &apos; SELECT SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,0 FROM &apos;||TMPVEKI||&apos; WHERE FRUNZA=1 &apos;||
      &apos; MINUS &apos;||
      &apos; SELECT SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,0 FROM &apos;||g_tmpTABLE||&apos; WHERE FRUNZA=1 &apos;;
  EXECUTE IMMEDIATE S;

  S :=&apos; INSERT INTO DIFERENTE_BALANTA (SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,NOU) &apos;||
      &apos; SELECT SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,1 FROM &apos;||g_tmpTABLE||&apos; WHERE FRUNZA=1 &apos;||
      &apos; MINUS &apos;||
      &apos; SELECT SIMBOL,SOLDID,SOLDIC,RULAJPD,RULAJPC,RULAJCD,RULAJCC,SOLDFD,SOLDFC,1 FROM &apos;||TMPVEKI||&apos; WHERE FRUNZA=1 &apos;;
  EXECUTE IMMEDIATE S;

  COMMIT;

  OPEN cResult FOR SELECT * FROM DIFERENTE_BALANTA
                   where SOLDID&lt;&gt;0 or SOLDIC&lt;&gt;0 or RULAJPD&lt;&gt;0 or RULAJPC&lt;&gt;0 or RULAJCD&lt;&gt;0 or RULAJCC&lt;&gt;0 or SOLDFD&lt;&gt;0 or SOLDFC&lt;&gt;0;
  RETURN cResult;
END;

PROCEDURE BalaVer(aLISTID IN NUMBER) IS
BEGIN
  p_LISTID  := aLISTID;
  p_LISTVER := 0;
end;

PROCEDURE TestTmpBrut IS
BEGIN
  Delete Debug_Liste; Commit;
  PKG_GLOBALS.SETDEBUGMODE(True);
  PKG_GLOBALS.SetLunaLucru_SIMPLA(2021,1);
  PKG_LIST_BASE_BALANTA.setParams;
  PKG_LIST_BASE_BALANTA.BalaVer(342);
  PKG_LIST_BASE_BALANTA.UMPLE_TMP_BALANTA;
END;

END PKG_LIST_BASE_BALANTA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALASUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7FE9FF1AF6DA69FE92C5884A5D645A57986D7C2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALASUBUNIT IS

  -- stef - stripped package (apelat la varianta asta pt ca actualizarea de martor nu sterge obiecte)
  -- daca are cineva nevoie de el poate sa ia si sa faca ce vrea cu el
  -- tot ce era pe acest paket se face din PKG_LIST_BASE_BALANTA

end pkg_list_base_balaSubunit; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALCUMUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E81726F345B2E89326B8B6E9D061D62F06392B4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALCUMUL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vToateGest   BOOLEAN        := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt  BOOLEAN        := PKG_LIST_SELECTSCAD.ToateIoart;
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  vZiua1       DATE           := to_date(&apos;01.&apos;||to_char(PKG_LIST_SELECTSCAD.DataIni,&apos;MM.YYYY&apos;),&apos;DD.MM.YYYY&apos;);
  vZiuaIni     DATE           := PKG_LIST_SELECTSCAD.DataIni;
  vZiuaFin     DATE           := PKG_LIST_SELECTSCAD.DataScad;
  vWhereStoc   VARCHAR2(3000) := &apos;&apos;;
  vWhereStocG  VARCHAR2(3000) := &apos;&apos;;
  vJoinStoc    VARCHAR2(500);
  anStocIni    INTEGER;
  lunaStocIni  INTEGER;
  vWhereCLivr  VARCHAR2(200);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NGEST NG, NART NA, NUM NUM, NPART PROD, NCLASEA NCA&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  anStocIni   := to_char(vZiua1-1,&apos;YYYY&apos;);
  lunaStocIni := to_char(vZiua1-1,&apos;MM&apos;);

  vWhereStoc := PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;NVL(I.SUBUNITATEA,T.SUBUNITATEA)&apos;);
  IF vWhereStoc IS NOT NULL THEN
    vJoinStoc  := &apos;
          LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
          LEFT JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF&apos;;
  END IF;

  IF not Pkg_List_Selectscad.Extra1 THEN
    vWhereStoc  := vWhereStoc|| &apos; AND (N.TIPNIR NOT IN (12,13,14,15)) &apos;;
    vWhereCLivr := &apos; AND (L.TIPLIVR NOT IN (12,13,14,15)) &apos;;
  END IF;


  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vWhereStocG := vWhereStocG||&apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = S.GEST) &apos;;
    elsif vCateGest = 0 then
      vWhereStocG := vWhereStocG||&apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = S.CODLOCATIE) &apos;;
    else
      vWhereStocG := vWhereStocG||&apos;
        AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = S.GEST) OR
             EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = S.CODLOCATIE)) &apos;;
    end if;
  end if;

  if NOT vToateIOArt then
    vWhereStoc := vWhereStoc||&apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;( Gest, Art, UM, StocIni, Int, Ies, StocFin, Masa, Volum, CodExt, CodInt, Prod &apos;||gUserFields||&apos;)
  WITH IOA AS (
    SELECT IO.CODIOART, IO.DEN_IOART,IO1.MG, IO1.CONT
    FROM IOART IO INNER JOIN IOART1 IO1 ON IO1.CODIOART = IO.CODIOART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IO1.ALSTART and IO1.ALSTOP
    WHERE IO1.MG &lt;&gt; 5 ),
  CANTLIVR AS (
    SELECT L1.CODNIRSTOC,
      SUM(CASE WHEN L.DATALIVR &lt; &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; THEN L1.CANT ELSE 0 END) CINI,
      SUM(CASE WHEN L.DATALIVR &lt; &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; THEN 0 WHEN L.TIPLIVR = 15 THEN 0       WHEN L.TIPLIVR &gt;  7 THEN  L1.CANT ELSE 0 END) CIES,
      SUM(CASE WHEN L.DATALIVR &lt; &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; THEN 0 WHEN L.TIPLIVR = 15 THEN L1.CANT WHEN L.TIPLIVR &lt;= 7 THEN -L1.CANT ELSE 0 END) CINTR
    FROM LIVR L INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||vZiua1||&apos;&apos;&apos; AND &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;&apos;||vWhereCLivr||&apos;
    GROUP BY L1.CODNIRSTOC ),
  CANTNIR AS (
    SELECT NS.CODNIRSTOC,
      SUM(CASE WHEN N.DATANIR BETWEEN &apos;&apos;&apos;||vZiua1||&apos;&apos;&apos; AND &apos;&apos;&apos;||(vZiuaIni-1)||&apos;&apos;&apos; THEN NS.CANTNIR ELSE 0 END) CINI,
      SUM(CASE WHEN N.DATANIR BETWEEN &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; AND &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos; AND N.TIPNIR &lt;  19 THEN  NS.CANTNIR ELSE 0 END) CINTR,
      SUM(CASE WHEN N.DATANIR BETWEEN &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; AND &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos; AND N.TIPNIR &gt;= 19 THEN -NS.CANTNIR ELSE 0 END) CIES
    FROM NIR N
      INNER JOIN NIRSTOC NS ON NS.CODNIR     = N.CODNIR
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
      LEFT  JOIN NIRLUNA NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN = &apos;||anStocIni||&apos; AND NL.LUNA = &apos;||lunaStocIni||
      vJoinStoc||
 &apos; WHERE N.DATANIR &lt;= &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos; AND N.OPERAT = 1 AND N.ANULAT = 0 &apos;||vWhereStoc||&apos;
   GROUP BY NS.CODNIRSTOC
  ),   
  STOC AS (
    SELECT NS.CODOBIECT, N.GEST, NS.CODLOCATIE, 
      SUM(NVL(NL.REST,0) - NVL(L.CINI,0) + NVL(CN.CINI,0)) STOCINI,
      SUM(NVL(CN.CINTR,0) + NVL(L.CINTR,0)) INTR,
      SUM(NVL(CN.CIES,0) + NVL(L.CIES, 0)) IES
    FROM NIR N
      INNER JOIN NIRSTOC  NS ON NS.CODNIR     = N.CODNIR
      LEFT  JOIN CANTNIR  CN ON CN.CODNIRSTOC = NS.CODNIRSTOC
      LEFT  JOIN CANTLIVR L  ON L.CODNIRSTOC  = NS.CODNIRSTOC
      LEFT  JOIN NIRLUNA  NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN = &apos;||anStocIni||&apos; AND NL.LUNA = &apos;||lunaStocIni||&apos;
    WHERE N.DATANIR &lt;= &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos; AND N.OPERAT = 1 AND N.ANULAT = 0
    GROUP BY CODOBIECT, GEST, CODLOCATIE)
  SELECT NG.DEN_GEST, NAO.DENUMIRE, NUM.DEN_UM, S.STOCINI, S.INTR, S.IES, S.STOCINI + S.INTR - S.IES, NAO.MASA,NAO.VOLUM, NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART PRODUCATOR&apos;||gUserAlias||&apos;
  FROM STOC S
    INNER JOIN NARTOBJ NAO  ON NAO.CODOBIECT = S.CODOBIECT
    INNER JOIN NART    NA   ON NA.CODARTICOL = NAO.CODARTICOL
    INNER JOIN NGEST   NG   ON NG.CODGEST    = S.GEST&apos;|| vWhereStocG ||&apos;
    LEFT  JOIN NUM          ON NUM.CODUM     = NA.UM
    LEFT  JOIN NPART   PROD ON PROD.CODPART  = NAO.CODPRODUCATOR
    LEFT  JOIN NCLASEA NCA  ON NCA.CODCLASEA = NA.CLASA&apos;||
    gSuplJoins||&apos;
  WHERE (S.STOCINI &lt;&gt; 0 OR S.INTR &lt;&gt; 0 OR S.IES &lt;&gt; 0)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BALCUMUL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALCUMUL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEB497FE001FDF956833B3EAE86DF6DC3C103B37</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALCUMUL1 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vZiua1       DATE            := to_date(&apos;01.&apos;||to_char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;MM.YYYY&apos;),&apos;DD.MM.YYYY&apos;);
  vZiuaIni     DATE            := PKG_LIST_ALEGPERIOADA.getDataS;
  vZiuaFin     DATE            := PKG_LIST_ALEGPERIOADA.getDataF;
  vInclMiscInt BOOLEAN         := PKG_LIST_ALEGPERIOADA.optiunea1;
  vCalcRestCom BOOLEAN         := PKG_LIST_ALEGPERIOADA.optiunea2;
  vPeSubunit   BOOLEAN         := PKG_LIST_ALEGPERIOADA.optiunea3;
  vCalcComPer  BOOLEAN         := PKG_LIST_ALEGPERIOADA.optiunea4;
  anStocIni    INTEGER;
  lunaStocIni  INTEGER;
  vJoinStoc    VARCHAR2(  500);
  vWhereStoc   VARCHAR2(  200) := &apos;&apos;;
  vWhenStoc    VARCHAR2(  200) := &apos;&apos;;
  vWhereCLivr  VARCHAR2(  200) := &apos;&apos;;
  vWithCom     VARCHAR2( 2000);
  vJoinCom     VARCHAR2(  500);
  vOrCom1      VARCHAR2(  100) := &apos;&apos;;
  vOrCom2      VARCHAR2(  100) := &apos;&apos;;
  vFieldCom1   VARCHAR2(  100) := &apos;, NULL RestCom&apos;;
  vFieldCom2   VARCHAR2(  100) := &apos;, NULL AcceptCom&apos;;
  vFieldSubS   VARCHAR2(  100) := &apos;, 1 &apos;;
  vFieldSubCA  VARCHAR2(  100) := &apos;, 1 &apos;;
  vFieldSubCL  VARCHAR2(  100) := &apos;, 1 &apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM, NPART PROD, NCLASEA NCA&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  anStocIni   := to_char(vZiua1-1,&apos;YYYY&apos;);
  lunaStocIni := to_char(vZiua1-1,&apos;MM&apos;);

  vWhereStoc   := PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;Coalesce(I.SUBUNITATEA,T.SUBUNITATEA)&apos;);
  IF vWhereStoc IS NOT NULL THEN
    vJoinStoc := &apos;
        LEFT JOIN INTRARI I ON I.CODINTR   = N.CODINTR
        LEFT JOIN TRANSF  T ON T.CODTRANSF = N.CODTRANSF&apos;;
  END IF;

  if not vInclMiscInt THEN
    vWhenStoc   := &apos;WHEN N.TIPNIR IN (12,13,14,15) THEN 0 &apos;;
    vWhereCLivr := &apos; AND L.TIPLIVR NOT IN (12,13,14,15) &apos;;
  end if;

  IF vPeSubunit THEN
    vFieldSubCA := &apos;, C.SUBUNITATEA&apos;;
    vFieldSubCL := &apos;, I.SUBUNITATEA&apos;;
    vFieldSubS  := &apos;, G.CODSUBUNIT&apos;;
  END IF;

  IF vCalcComPer THEN
    vOrCom2    := &apos; OR Coalesce(CA.CANTA,0) &lt;&gt; 0&apos;;
    vFieldCom2 := &apos;, Coalesce(CA.CANTA,0)&apos;;
    vWithCom  := &apos;
    COMACCEPTAT AS (
      SELECT C1.CODOBIECT&apos;||vFieldSubCA||&apos; CodSubunit, SUM(C1.CANTACCEPTAT) CANTA
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.TIPDOC = 18 AND C.ANULAT = 0 AND C.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        AND C.DATADOC BETWEEN &apos;&apos;&apos;||vZiua1||&apos;&apos;&apos; AND &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;
      GROUP BY C1.CODOBIECT&apos;||vFieldSubCA||&apos; ),&apos;;
    vJoinCom := &apos;
    LEFT JOIN COMACCEPTAT CA ON CA.CODOBIECT = S.CODOBIECT AND CA.CodSubunit = S.CodSubunit&apos;;
  END IF;

  IF vCalcRestCom THEN
    vOrCom1    := &apos; OR Coalesce(CA.CANT,0)-Coalesce(CL.CANT,0) &lt;&gt; 0&apos;;
    vFieldCom1 := &apos;,Coalesce(CA.CANT,0) - Coalesce(CL.CANT,0) RestCom&apos;;
    vWithCom  := &apos;
    COMACCEPTAT AS (
      SELECT C1.CODOBIECT&apos;||vFieldSubCA||&apos; CodSubunit, SUM(C1.CANTACCEPTAT) CANT, SUM(CASE WHEN C.DATADOC &lt; &apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos; THEN 0 ELSE Coalesce(C1.CANTACCEPTAT,0) END) CANTA
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.TIPDOC = 18 AND C.ANULAT = 0 AND C.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        AND C.DATADOC &lt;= &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;
      GROUP BY C1.CODOBIECT&apos;||vFieldSubCA||&apos; ),
    COMLIVRAT AS (
      SELECT I1.CODOBIECT&apos;||vFieldSubCL||&apos; CodSubunit, SUM(IL.CANT) CANT
      FROM IESLINK IL
        INNER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
        INNER JOIN IESIRI  I  ON I.CODIES   = I1.CODIES
      WHERE I.DATADOC &lt;= &apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND IL.CODLINIECOMANDA IS NOT NULL
      GROUP BY I1.CODOBIECT&apos;||vFieldSubCL||&apos;),&apos;;
    vJoinCom := &apos;
    LEFT JOIN COMACCEPTAT CA ON CA.CODOBIECT = S.CODOBIECT AND CA.CodSubunit = S.CodSubunit
    LEFT JOIN COMLIVRAT CL ON CL.CODOBIECT = S.CODOBIECT AND CL.CodSubunit = S.CodSubunit&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Art, UM, StocIni, Int, Ies, StocFin, Masa, Volum, CodExt, CodInt, Prod, Subunit,
    RestCom, AcceptCom &apos;||gUserFields||&apos;)
  WITH
    IOA AS (
      SELECT IO.CODIOART, IO.DEN_IOART,IO1.MG, IO1.CONT
    FROM IOART IO INNER JOIN IOART1 IO1 ON IO1.CODIOART = IO.CODIOART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IO1.ALSTART and IO1.ALSTOP
    WHERE IO1.MG &lt;&gt; 5 ),&apos;||
    vWithCom||&apos;
    CANTLIVR AS (
      SELECT L1.CODNIRSTOC,
        SUM(CASE WHEN L.DATALIVR &lt; To_date(&apos;&apos;&apos;||To_char(vZiuaIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN L1.CANT ELSE 0 END) CINI,
        SUM(CASE WHEN L.DATALIVR &lt; To_date(&apos;&apos;&apos;||To_char(vZiuaIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 WHEN L.TIPLIVR = 15 THEN 0       WHEN L.TIPLIVR &gt;  7 THEN  L1.CANT ELSE 0 END) CIES,
        SUM(CASE WHEN L.DATALIVR &lt; To_date(&apos;&apos;&apos;||To_char(vZiuaIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 WHEN L.TIPLIVR = 15 THEN L1.CANT WHEN L.TIPLIVR &lt;= 7 THEN -L1.CANT ELSE 0 END) CINTR
      FROM LIVR L
        INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      WHERE L.DATALIVR BETWEEN To_date(&apos;&apos;&apos;||To_char(vZiua1, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_date(&apos;&apos;&apos;||To_char(vZiuaFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
        vWhereCLivr||&apos;
      GROUP BY L1.CODNIRSTOC ),
    STOC AS (
      SELECT NS.CODOBIECT&apos;||vFieldSubS||&apos; CodSubunit,
        SUM(Coalesce(NL.REST,0) - Coalesce(L.CINI,0) + (CASE WHEN N.DATANIR BETWEEN To_date(&apos;&apos;&apos;||To_char(vZiua1, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_date(&apos;&apos;&apos;||To_char(vZiuaIni-1, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN NS.CANTNIR ELSE 0 END)) STOCINI,
        SUM((CASE &apos;||vWhenStoc||&apos;WHEN N.DATANIR BETWEEN To_date(&apos;&apos;&apos;||To_char(vZiuaIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_date(&apos;&apos;&apos;||To_char(vZiuaFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND N.TIPNIR &lt;  19 THEN  NS.CANTNIR ELSE 0 END) + Coalesce(L.CINTR,0)) INTR,
        SUM((CASE &apos;||vWhenStoc||&apos;WHEN N.DATANIR BETWEEN To_date(&apos;&apos;&apos;||To_char(vZiuaIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_date(&apos;&apos;&apos;||To_char(vZiuaFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND N.TIPNIR &gt;= 19 THEN -NS.CANTNIR ELSE 0 END) + Coalesce(L.CIES,0)) IES
      FROM NIR N
        INNER JOIN NIRSTOC  NS ON NS.CODNIR     = N.CODNIR
        INNER JOIN IOA         ON IOA.CODIOART  = NS.CODIOART
        LEFt  JOIN NGEST    G  ON G.CODGEST     = N.GEST
        LEFT  JOIN CANTLIVR L  ON L.CODNIRSTOC  = NS.CODNIRSTOC
        LEFT  JOIN NIRLUNA  NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN = &apos;||anStocIni||&apos; AND NL.LUNA = &apos;||lunaStocIni||
        vJoinStoc||&apos;
      WHERE N.DATANIR &lt;= To_date(&apos;&apos;&apos;||To_char(vZiuaFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND N.OPERAT = 1 AND N.ANULAT = 0 &apos;||vWhereStoc||&apos;
      GROUP BY CODOBIECT&apos;||vFieldSubS||&apos;)
  SELECT
    NAO.DENUMIRE, NUM.DEN_UM, S.STOCINI, S.INTR, S.IES, S.STOCINI + S.INTR - S.IES, NAO.MASA,NAO.VOLUM, NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART, SUB.DEN_SUBUNIT
    &apos;||vFieldCom1||vFieldCom2||gUserAlias||&apos;
  FROM STOC S
    INNER JOIN NARTOBJ  NAO  ON NAO.CODOBIECT  = S.CODOBIECT
    INNER JOIN NART     NA   ON NA.CODARTICOL  = NAO.CODARTICOL
    LEFT  JOIN NUM           ON NUM.CODUM      = NA.UM
    LEFT  JOIN NCLASEA  NCA  ON NCA.CODCLASEA  = NA.CLASA
    LEFT  JOIN NPART    PROD ON PROD.CODPART   = NAO.CODPRODUCATOR
    LEFT  JOIN NSUBUNIT SUB  ON SUB.CODSUBUNIT = S.CODSUBUNIT&apos;||
    vJoinCom||
    gSuplJoins||&apos;
  WHERE (S.STOCINI &lt;&gt; 0 OR S.INTR &lt;&gt; 0 OR S.IES &lt;&gt; 0&apos;||vOrCom1||vOrCom2||&apos;)&apos;;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BALCUMUL1;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSINTPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5986B3481D1AA51D5DF4A16C7A5F3ADBE82CB93B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSINTPART IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  g_AL        NUMBER;

PROCEDURE SET_LISTA_PARAMS (
  IsAllMoneda IN NUMBER  DEFAULT 1,
  IsAllCont   IN NUMBER  DEFAULT 1,
  IsAllSub    IN NUMBER  DEFAULT 1,
  aLunaStart  IN NUMBER,
  aLunaFin    IN NUMBER,
  aTipIopart  IN NUMBER  DEFAULT 0,
  pCodJob1    IN NUMBER  DEFAULT 0,
  pAllSting   IN NUMBER  DEFAULT 0,
  IsSubStins  IN NUMBER  DEFAULT 0
) IS
BEGIN
  g_AL := aLunaFin;
  -- STEF (pCodJob1 &gt; 0) nu e nevoie de setat interval dinamic aici fiindca se apeleaza in PKG_LIST_BASE_FISAANALITIKPART
  PKG_LIST_BASE_FISAANALITIKPART.SET_LISTA_PARAMS (
    IsAllMoneda =&gt; Coalesce(IsAllMoneda, 1),
    IsAllCont   =&gt; Coalesce(IsAllCont,   1),
    IsAllSub    =&gt; Coalesce(IsAllSub,    1),
    IsBalanta   =&gt; 1,
    aCodpart    =&gt; 0,
    aLunaStart  =&gt; aLunaStart,
    aLunaFin    =&gt; aLunaFin,
    aTipIopart  =&gt; Coalesce(IsAllSub,    0),
    IsDefalcLoc =&gt; 0,
    IsDefalcDoc =&gt; 0,
    AduInfoCM   =&gt; 0,
    pCodJob1    =&gt; Coalesce(pCodJob1,    0),
    pAllSting   =&gt; Coalesce(pAllSting,   0),
    IsSubStins  =&gt; Coalesce(IsSubStins,  0)
  );
END;

PROCEDURE processlist(tmpname IN VARCHAR, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  gSuplCols := &apos;NPART NP, NCONT C, NSUBUNIT SUB, NCLASEP NCP, NMONEDE MON, NPARTCODFISC NPCF, NAGENDA SSOC, NLOCALIT LOCSOC, NTARI TARASOC, NJUDET JUDSOC&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,             &apos;AGP&apos;,   &apos;AGP.CODPERS = SSOC.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,          &apos;PDET&apos;,  &apos;PDET.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_SAFT_NPARTDET&apos;, &apos;PSAFT&apos;, &apos;PSAFT.CODPART = NP.CODPART&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_DETBALSINT&apos;;
  PKG_LIST_BASE_FISAANALITIKPART.processList(&apos;TMP_LST_DETBALSINT&apos;,aLISTID,aLISTVER);

	sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CODPART, DEN_PART, CODEXTERN, ICONT, SIMBOL, TIPSOLD,
    CLASA, CODINTERN, DEN_MONEDA, CODFISCAL, SUBUNITATEA,
    SOLD_INI, RUL_DEBIT, RUL_CREDIT, SOLD_FINAL, SOLD_INI_IFRS, RUL_IFRS, SOLD_FINAL_IFRS,
    SOLD_FINAL_TOTAL, X_Judet, X_COdClasaP &apos;||gUserFields||&apos;)
  SELECT
    NP.CODPART, NP.DEN_PART, NP.CODEXTERN, tmp.ICONT, C.SIMBOL, tmp.TIPSOLD,
    NCP.DEN_CLASEP, NP.CODINTERN, MON.DEN_MONEDA, NPCF.CODFISCAL, sub.den_subunit,
    TMP.SOLD_INI, TMP.RUL_DEBIT, TMP.RUL_CREDIT, TMP.SOLD_FINAL, TMP.SOLD_INI_IFRS, TMP.RUL_IFRS, TMP.SOLD_FINAL_IFRS,
    TMP.SOLD_FINAL_TOTAL, JUDSOC.Simbauto, NCP.CODCLASEP  &apos;||gUserAlias||&apos;
  FROM (
    SELECT
      codpart, codsubunit, icont, codcont, codmoneda, tipsold,
      Sum(CASE WHEN ordine = 0 THEN sold_col ELSE 0 END) sold_ini,
      Sum(CASE WHEN ordine = 0 THEN 0 ELSE DEBIT END) RUL_DEBIT,
      Sum(CASE WHEN ordine = 0 THEN 0 ELSE CREDIT END) RUL_CREDIT,
      Sum(sold_col) SOLD_FINAL,
      Sum(CASE WHEN ordine = 0 THEN sold_col_ifrs ELSE 0 END) SOLD_INI_IFRS,
      Sum(CASE WHEN ordine = 0 THEN 0 ELSE IFRS END) RUL_IFRS,
      Sum(sold_col_ifrs) SOLD_FINAL_IFRS,
      Sum(sold_col_total) SOLD_FINAL_TOTAL
    FROM TMP_LST_DETBALSINT
    GROUP BY codpart, codsubunit, icont, codcont, codmoneda, tipsold
  ) tmp
    LEFT JOIN NPART        NP      ON np.codpart        = tmp.codpart
    LEFT JOIN NCONT        C       ON c.codCont         = tmp.CodCont
    LEFT JOIN NSUBUNIT     SUB     ON SUB.CODSUBUNIT    = tmp.CODSUBUNIT
    LEFT JOIN NCLASEP      NCP     ON NP.CODCLASA       = NCP.CODCLASEP
    LEFT JOIN NMONEDE      MON     ON MON.CODMONEDA     = tmp.CODMONEDA
    LEFT JOIN NPARTCODFISC NPCF    ON NPCF.CODPART      = NP.CODPART AND Coalesce(NPCF.PRINCIPAL, 1) = 1
    LEFT JOIN NAGENDA      SSOC    ON ssoc.codpart      = np.codpart AND ssoc.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(ssoc.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT     LOCSOC  ON locsoc.codlocalit = ssoc.codlocalit
    LEFT JOIN NTARI        TARASOC ON LOCSOC.codtara    = TARASOC.codtara
    LEFT JOIN NJUDET       JUDSOC  ON judsoc.codjudet   = locsoc.codjudet&apos;||
    gSuplJoins||&apos;
  WHERE (ABS(SOLD_INI) &gt;= 0.01 OR ABS(RUL_DEBIT) &gt;= 0.01 OR ABS(RUL_CREDIT) &gt;= 0.01)&apos; ;

  IF Instr(Upper(gSuplJoins), &apos;TMP_SAFT_NPARTDET&apos;) &gt; 0 THEN
    PKG_SAFT.UMPLE_NPARTDET(0, g_AL);
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_BalSintPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSINTPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D8DDAAC9FAA15C815423BC3C4FE7FEFB6986BEE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSINTPERS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  sInsert     VARCHAR2(1000);
  sSelect     VARCHAR2(31000);

function GetLunaU(aAn in number, aLuna in number) return number is
begin
  if aLuna = 12 then return 1; else return aLuna + 1; end if;
end;

function GetAnU(aAn in number, aLuna in number) return number is
begin
  if aLuna = 12 then return aAn + 1; else return aAn; end if;
end;

PROCEDURE SetSql(tmpname IN VARCHAR2, aLISTID IN NUMBER, aLISTVER IN NUMBER, aHolding IN NUMBER) IS
  sPerioada   VARCHAR2(200);
  sSubunit    NUMBER(20)   := PKG_GLOBALS.GETSUBUNITATE;
  sCondMon    VARCHAR2(500);
  sCondCont   VARCHAR2(500);
  sSoldIni    VARCHAR2(500);
  sSoldFin    VARCHAR2(500);
  vMonCount   INTEGER := 0;
  vContCount  INTEGER := 0;
  sTipSold    VARCHAR2( 10);
  sTabelaSold VARCHAR2(300);
  vAnInitial    number(4);
  vLunaInitiala number(2);
BEGIN
  gSuplCols := &apos;NPERS NP, NCONT NCONT, NMONEDE MON&apos;;
  
  PRC_AL_CHECK(&apos;NPERS1&apos;);
  
  select aninitial into vAnInitial from firmaluni;
  select lunainitiala into vLunaInitiala from firmaluni;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||tmpname||&apos;
     (CONT, ANGAJAT, TIPSOLD, SOLDINI, DEBIT, CREDIT, DEBIT_ALTE, CREDIT_ALTE, SOLDFIN, MONEDA&apos;||gUserFields||&apos;) &apos;;

  IF PKG_LIST_SELFISAPERS.AnLunaIni = PKG_LIST_SELFISAPERS.AnLunaFin
  THEN sPerioada := &apos;= &apos;||PKG_LIST_SELFISAPERS.AnLunaIni;
  ELSE sPerioada := &apos;BETWEEN &apos;||PKG_LIST_SELFISAPERS.AnLunaIni||&apos; AND &apos;||PKG_LIST_SELFISAPERS.AnLunaFin;
  END IF;

  IF NOT PKG_LIST_SELFISAPERS.isAllMon THEN
    sCondMon := &apos;
        AND MON.CODMONEDA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;

    SELECT COUNT(DISTINCT VALOARE)
    INTO vMonCount
    FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODMONEDA&apos;;
  END IF;


  vContCount := 0;
  IF NOT PKG_LIST_SELFISAPERS.isAllTipC THEN
    sCondCont := &apos;
        AND NC.CODCONT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos; ) &apos;;

    WITH x AS (SELECT DISTINCT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODCONT&apos;)
    SELECT COUNT(1), Decode( Max(NCONT.TipCont),1,&apos;C&apos;,&apos;D&apos;)
    INTO vContCount, sTipSold
    FROM x INNER JOIN NCONT ON NCONT.CODCONt = X.VALOARE;
  END IF;

  IF vContCount &lt;&gt; 1
  THEN sTipSold := &apos;D&apos;;
  END IF;

  if PKG_LIST_SELFISAPERS.isSubunit then
    if PKG_LIST_SELFISAPERS.isAllTipC then
      sSoldIni := &apos;NVL(soldini.SoldIni,0) &apos;;
      sSoldFin := &apos;NVL(soldini.SoldIni,0) + NVL(rulaje.Rul_Debit,0) - NVL(rulaje.Rul_Credit,0) + NVL(rulaje.Rul_Debit_Alte,0) - NVL(rulaje.Rul_Credit_Alte,0)&apos;;
    else
      sSoldIni := &apos;NVL(soldini.SoldIni,0) &apos;;
      sSoldFin := &apos;case when ncont.tipcont &lt;&gt; 1 then NVL(soldini.SoldIni,0) + NVL(rulaje.Rul_Debit,0) + NVL(rulaje.Rul_Debit_Alte,0) - NVL(rulaje.Rul_Credit,0) - NVL(rulaje.Rul_Credit_Alte,0)
                        else NVL(soldini.SoldIni,0) - NVL(rulaje.Rul_Debit,0) - NVL(rulaje.Rul_Debit_Alte,0) + NVL(rulaje.Rul_Credit,0) + NVL(rulaje.Rul_Credit_Alte,0)
                   end &apos;;
    end if;
  else
    if PKG_LIST_SELFISAPERS.isAllTipC then
      sSoldIni := &apos;NVL(soldini.SoldIni,0) &apos;;
      sSoldFin := &apos;NVL(soldini.SoldIni,0) + NVL(rulaje.Rul_Debit,0) - NVL(rulaje.Rul_Credit,0)&apos;;
    else
      sSoldIni := &apos;NVL(soldini.SoldIni,0) &apos;;
      sSoldFin := &apos;case when ncont.tipcont &lt;&gt; 1 then NVL(soldini.SoldIni,0) + NVL(rulaje.Rul_Debit,0) - NVL(rulaje.Rul_Credit,0) else NVL(soldini.SoldIni,0) - NVL(rulaje.Rul_Debit,0) + NVL(rulaje.Rul_Credit,0) end &apos;;
    end if;
  end if;

  IF aHolding = 1
  THEN sTabelaSold := &apos;nperssoldlunasub&apos;;
  ELSE sTabelaSold := &apos;nperssoldluna&apos;;
  END IF;

  if PKG_LIST_SELFISAPERS.isAllTipC then
    IF PKG_LIST_SELFISAPERS.isSubunit then
      sSelect := &apos;
      WITH
      SOLDINI AS (
        SELECT
          NC.CodCont, NPS.CodPers, MON.CodMoneda,
          SUM(case
                when nc.tipcont &lt;&gt; 1 then
                  CASE
                    WHEN PKG_LIST_SELFISAPERS.Lei = 1
                         OR MON.CodMoneda = 0 THEN NPS.SoldLei
                    ELSE NPS.SoldValuta
                  END
                else
                  CASE
                    WHEN PKG_LIST_SELFISAPERS.Lei = 1
                         OR MON.CodMoneda = 0 THEN - NPS.SoldLei
                    ELSE - NPS.SoldValuta
                  END
              end
             ) SoldIni
        FROM &apos;||CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;nperssoldlunasub&apos; ELSE &apos;nperssoldluna&apos; END||&apos; NPS
          INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;, pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
          INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
        WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
          CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;
          AND NPS.SUBUNITATEA = &apos;||pkg_globals.GETSUBUNITATE else &apos;&apos; END ||
          sCondMon||
          sCondCont||&apos;
        GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
    else
      if pkg_globals.GETSUBUNITATE &gt; 1 then
        sSelect := &apos;
        WITH
        SOLDINI AS (
          SELECT
            NC.CodCont, NPS.CodPers, MON.CodMoneda,
            SUM(case
                  when nc.tipcont &lt;&gt; 1 then
                    CASE
                      WHEN PKG_LIST_SELFISAPERS.Lei = 1
                           OR MON.CodMoneda = 0 THEN NPS.SoldLei
                      ELSE NPS.SoldValuta
                    END
                  else
                    CASE
                      WHEN PKG_LIST_SELFISAPERS.Lei = 1
                           OR MON.CodMoneda = 0 THEN - NPS.SoldLei
                      ELSE - NPS.SoldValuta
                    END
                  end
               ) SoldIni
          FROM nperssoldlunasub NPS
            INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;,pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
            INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
          WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
            PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NPS&apos;)||
            sCondMon||
            sCondCont||&apos;
          GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
      else
        sSelect := &apos;
        WITH
        SOLDINI AS (
          SELECT
            NC.CodCont, NPS.CodPers, MON.CodMoneda,
            SUM(case
                  when nc.tipcont &lt;&gt; 1 then
                    CASE
                      WHEN PKG_LIST_SELFISAPERS.Lei = 1
                           OR MON.CodMoneda = 0 THEN NPS.SoldLei
                      ELSE NPS.SoldValuta
                    END
                  else
                    CASE
                      WHEN PKG_LIST_SELFISAPERS.Lei = 1
                           OR MON.CodMoneda = 0 THEN - NPS.SoldLei
                      ELSE - NPS.SoldValuta
                    END
                end
               ) SoldIni
          FROM nperssoldluna NPS
            INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;,pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
            INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
          WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
            sCondMon||
            sCondCont||&apos;
          GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
      end if;
    end if;
  else
    IF PKG_LIST_SELFISAPERS.isSubunit then
      sSelect := &apos;
      WITH
      SOLDINI AS (
        SELECT
          NC.CodCont, NPS.CodPers, MON.CodMoneda,
          SUM(CASE
                WHEN PKG_LIST_SELFISAPERS.Lei = 1
                     OR MON.CodMoneda = 0 THEN NPS.SoldLei
                ELSE NPS.SoldValuta
              END
             ) SoldIni
        FROM &apos;||CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;nperssoldlunasub&apos; ELSE &apos;nperssoldluna&apos; END||&apos; NPS
          INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;,pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
          INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
        WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
          CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;
          AND NPS.SUBUNITATEA = &apos;||pkg_globals.GETSUBUNITATE else &apos;&apos; END ||
          sCondMon||
          sCondCont||&apos;
        GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
    else
      if pkg_globals.GETSUBUNITATE &gt; 1 then
        sSelect := &apos;
        WITH
        SOLDINI AS (
          SELECT
            NC.CodCont, NPS.CodPers, MON.CodMoneda,
            SUM(CASE
                  WHEN PKG_LIST_SELFISAPERS.Lei = 1
                       OR MON.CodMoneda = 0 THEN NPS.SoldLei
                  ELSE NPS.SoldValuta
                END
               ) SoldIni
          FROM nperssoldlunasub NPS
            INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;,pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
            INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
          WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
            PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NPS&apos;)||
            sCondMon||
            sCondCont||&apos;
          GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
      else
        sSelect := &apos;
        WITH
        SOLDINI AS (
          SELECT
            NC.CodCont, NPS.CodPers, MON.CodMoneda,
            SUM(
                CASE
                  WHEN PKG_LIST_SELFISAPERS.Lei = 1
                       OR MON.CodMoneda = 0 THEN NPS.SoldLei
                  ELSE NPS.SoldValuta
                END
               ) SoldIni
          FROM nperssoldluna NPS
            INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;,pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
            INNER JOIN NMONEDE MON ON MON.CodMoneda = NPS.CodMoneda
          WHERE (NPS.An * 12 + NPS.Luna) = &apos;||to_char(PKG_LIST_SELFISAPERS.AnLunaIni-1)||
            sCondMon||
            sCondCont||&apos;
          GROUP BY NC.CodCont, NPS.CodPers, MON.CodMoneda),&apos;;
      end if;
    end if;
  end if;

  --delete x;
  --insert into x(test) values (sselect);
  --commit;

  sSelect := sSelect||
 &apos;RULAJE AS (
    SELECT
      CodCont, CodPers, CodMoneda,
      SUM(CASE WHEN &apos;||sSubunit||&apos; IN (1,Subunitatea) THEN Debit  ELSE 0 END) Rul_Debit,
      SUM(CASE WHEN &apos;||sSubunit||&apos; IN (1,Subunitatea) THEN Credit ELSE 0 END) Rul_Credit,
      SUM(CASE WHEN &apos;||sSubunit||&apos; IN (1,Subunitatea) THEN 0 ELSE Debit  END) Rul_Debit_Alte,
      SUM(CASE WHEN &apos;||sSubunit||&apos; IN (1,Subunitatea) THEN 0 ELSE Credit END) Rul_Credit_Alte
    FROM (
      SELECT /* justificari decont */
        NC.CodCont, NP1.CodPers, MON.CodMoneda, T.Subunitatea,
        Decode(T1.TipTranz, 1, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 then decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Debit,
        Decode(T1.TipTranz, 0, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 then decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Credit
      FROM TREZOR T
        INNER JOIN TREZOR1 T1  ON T1.CodTrezor  = T.CodTrezor
        INNER JOIN NPERS1  NP1 ON NP1.CodPers   = T.CodBanca AND (T.An * 12 + T.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, T.IContPers, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, T.An, T.Luna))
        INNER JOIN NMONEDE MON ON MON.CodMoneda = Nvl(T.MonedaPers,0)
      WHERE T.TipDoc = 33 AND (T.An * 12 + T.Luna) &apos;||sPerioada||&apos; AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1 &apos;||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) else &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT /*trenzactii casa - banca*/
        NC.CodCont, NP1.CodPers, MON.CodMoneda, T.Subunitatea,
        Decode(T1.TipTranz, 0, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Debit,
        Decode(T1.TipTranz, 1, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Credit
      FROM TREZOR T
        INNER JOIN TREZOR1  T1  ON T1.CodTrezor  = T.CodTrezor
        INNER JOIN GENERAL  G   ON G.CodDoc      = T1.CodTrezor1 AND G.Semnificatie IN (1100, 1101)
        INNER JOIN OBLIGPIF O   ON O.CodGeneral  = G.CodGeneral
        INNER JOIN NPERS1   NP1 ON NP1.CodPers   = T1.CodPart AND (T.An * 12 + T.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT    NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, T.An, T.Luna))
        INNER JOIN NMONEDE  MON ON MON.CodMoneda = Nvl(G.Moneda,0)
      WHERE T.TipDoc &lt;&gt; 33 AND T1.ObiectTranz = 2 AND (T.An * 12 + T.Luna) &apos;||sPerioada||&apos; AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1 &apos;||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) else &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT
        NC.CodCont, NP1.CodPers, MON.CodMoneda, T.Subunitatea,
        Decode(T1.TipTranz, 0, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Debit,
        Decode(T1.TipTranz, 1, T1.ValDoc, 0) * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(T1.Curs,1),0,1,NVL(T1.Curs,1)) ELSE 1 END Credit
      FROM TREZOR T
        INNER JOIN TREZOR1  T1  ON T1.CodTrezor  = T.CodTrezor
        INNER JOIN GENERAL  G   ON G.CodDoc      = T1.CodTrezor1 AND G.Semnificatie IN (1100, 1101)
        INNER JOIN OBLIGPIF O   ON O.CODGENERAL  = G.CodGeneral
        INNER JOIN NPERS    NP  ON NP.CODPERS    = T1.CodPart
        INNER JOIN NPERS1   NP1 ON NP1.CODPERS   = T1.CodPart AND (T.An * 12 + T.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT    NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, T.An, T.Luna))
        INNER JOIN NMONEDE  MON ON MON.CodMoneda = NVL(G.Moneda, 0)
      WHERE T.TipDoc = 33 AND T1.ObiectTranz = 2 AND (T.An * 12 + T.Luna) &apos;||sPerioada||&apos; AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1 &apos;||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT /*note contabile - debit*/
        NC.CodCont, NP1.CodPers, MON.CodMoneda, N.Subunitatea,
        N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(N.Curs,1),0,1,NVL(N.Curs,1)) ELSE 1 END Debit,
        0 Credit
      FROM NC N
        INNER JOIN NC1     N1  ON N1.CodNC      = N.CodNC
        INNER JOIN NPERS1  NP1 ON NP1.CodPers   = N1.AGENT AND (N.An * 12 + N.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.IContD, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, N.An, N.Luna))
        INNER JOIN NMONEDE MON ON MON.CodMoneda = Nvl(N.Moneda,0)
      WHERE NVL(N1.AGENT, 0) &lt;&gt; 0 AND NVL(N1.ICONTD, 0) &lt;&gt; 0 AND NVL(N1.PERSD, 0) &lt;&gt; 0 AND (N.An * 12 + N.Luna) &apos;||sPerioada||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;) ELSE &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT /*note contabile - credit*/
        NC.CodCont, NP1.CodPers, MON.CodMoneda, N.Subunitatea,
        0 Debit,
        N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN decode(NVL(N.Curs,1),0,1,NVL(N.Curs,1)) ELSE 1 END Credit
      FROM NC N
        INNER JOIN NC1     N1  ON N1.CodNC      = N.CodNC
        INNER JOIN NPERS1  NP1 ON NP1.CodPers   = N1.AGENT AND (N.An * 12 + N.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.IContC, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, N.An, N.Luna))
        INNER JOIN NMONEDE MON ON MON.CodMoneda = Nvl(N.Moneda,0)
      WHERE NVL(N1.AGENT, 0) &lt;&gt; 0 AND NVL(N1.ICONTC, 0) &lt;&gt; 0 AND NVL(N1.PERSC, 0) &lt;&gt; 0 AND (N.An * 12 + N.Luna) &apos;||sPerioada||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;) ELSE &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT -- conversii valutare de personal in
        NC.CodCont, NP1.CodPers, MON.CodMoneda, CV.Subunitatea,
        0 Debit,
        CV.SOLDVALUTA_IN * CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND mon.codmoneda &lt;&gt; 0 THEN CV.CursConversie ELSE 1 END CREDIT
      FROM CONVERTCURSPERS CV
        INNER JOIN NPERS   NP  ON NP.CODPERS    = CV.CodPers
        INNER JOIN NPERS1  NP1 ON NP1.CODPERS   = CV.CodPers AND (CV.An * 12 + CV.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, CV.IContPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, CV.An, CV.Luna))
        INNER JOIN NMONEDE MON ON MON.CodMoneda = NVL(CV.Moneda_IN, 0)
      WHERE (CV.An * 12 + CV.Luna) &apos;||sPerioada||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CV&apos;) ELSE &apos;&apos; END||
        sCondMon||
        sCondCont||&apos;
      UNION ALL
      SELECT -- conversii valutare de personal out
        NC.CodCont, NP1.CodPers, MON.CodMoneda, CV.Subunitatea,
        CV.SOLDVALUTA_OUT / CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND mon.codmoneda &lt;&gt; 0 THEN CV.CursConversie ELSE 1 END DEBIT,
        0 Credit
      FROM CONVERTCURSPERS CV
        INNER JOIN NPERS   NP  ON NP.CODPERS    = CV.CodPers
        INNER JOIN NPERS1  NP1 ON NP1.CODPERS   = CV.CodPers AND (CV.An * 12 + CV.Luna) BETWEEN NP1.ALStart and NP1.ALStop
        INNER JOIN NCONT   NC  ON NC.CodCont    = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, CV.IContPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NP1.CodPers, CV.An, CV.Luna))
        INNER JOIN NMONEDE MON ON MON.CodMoneda = NVL(CV.Moneda_OUT, 0)
      WHERE (CV.An * 12 + CV.Luna) &apos;||sPerioada||
        CASE WHEN aHolding = 1 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CV&apos;) ELSE &apos;&apos; END||
        sCondMon||
        sCondCont||&apos; &apos;;
  IF PKG_LIST_SELFISAPERS.Lei = 1 THEN
    sSelect := sSelect||&apos;
      UNION ALL
      SELECT --regularizari de valuta
        NC.CodCont CodCont,
        REG1.CodPers,
        MON.CodMoneda, REG1.subunitatea,
        CASE
          WHEN NC.tipcont = 1 AND reg1.SOLDDOCREG - reg1.solddocval &lt;  0 then -(reg1.SOLDDOCREG - reg1.solddocval)
          WHEN NC.tipcont in (0,2) AND reg1.SOLDDOCREG - reg1.solddocval &gt;= 0 then reg1.SOLDDOCREG - reg1.solddocval
          ELSE 0
        END DEBIT,
        CASE
          WHEN NC.tipcont = 1 AND reg1.SOLDDOCREG - reg1.solddocval &gt;= 0 then reg1.SOLDDOCREG - reg1.solddocval
          WHEN NC.tipcont in (0,2) AND reg1.SOLDDOCREG - reg1.solddocval &lt;  0 then -(reg1.SOLDDOCREG - reg1.solddocval)
          ELSE 0
        END CREDIT
      FROM REG
        INNER JOIN REGPERS1 REG1 ON REG1.CODREG   = REG.CODREG
        INNER JOIN NPERS    NP   ON NP.CODPERS    = REG1.CODPERS
        INNER JOIN NCONT    NC   ON NC.CODCONT    = REG1.CODCONT
        INNER JOIN NMONEDE  MON  ON MON.CODMONEDA = NVL(REG.CODMONEDA,0)&apos;;
    /*IF aHolding = 1 THEN
      sSelect := sSelect||&apos;
        LEFT JOIN dvi on dvi.coddvi = g.coddoc and g.tipdoc = 5 and g.semnificatie = 130
        LEFT JOIN intrari intr on intr.codintr = NVL(dvi.codintr, g.coddoc) and intr.tipdoc = g.tipdoc
        LEFT JOIN iesiri ies on ies.codies = g.coddoc and ies.tipdoc = g.tipdoc
        LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc and g.tipdoc IN (29, 30, 31, 33)
        LEFT JOIN trezor t on t.codtrezor = t1.codtrezor
        LEFT JOIN compens c ON c.codcompens = g.coddoc and g.tipdoc = 28
        LEFT JOIN nc1 n1 on n1.codnc1 = g.coddoc and g.tipdoc IN (35)
        LEFT JOIN nc n on n.codnc = n1.codnc&apos;;
    END IF;*/
    sSelect := sSelect||&apos;
      WHERE (REG.an * 12 + REG.luna) &apos;||sPerioada||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;REG1.SUBUNITATEA&apos;)||
      sCondMon||
      sCondCont;
  END IF;

  sSelect := sSelect||&apos;
    )
    GROUP BY CodCont, CodPers, CodMoneda
  )
  select misc.simbol, misc.ANGAJAT, misc.TIPSOLD, misc.SOLDINI, misc.DEBIT, misc.CREDIT, misc.DEBIT_ALTE, misc.CREDIT_ALTE, misc.SOLDFIN, misc.MONEDA &apos;||gUserAlias||&apos;
  from (
  SELECT
    NCONT.SIMBOL, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT, &apos;&apos;&apos;||sTipSold||&apos;&apos;&apos; tipsold,
    SoldIni.SOLDINI, NVL(rulaje.Rul_Debit, 0) DEBIT, NVL(rulaje.Rul_Credit, 0) CREDIT, NVL(rulaje.Rul_Debit_Alte, 0) DEBIT_ALTE, NVL(rulaje.Rul_Credit_Alte, 0) CREDIT_ALTE,
    &apos;||sSoldFin||&apos; SOLDFIN,
    MON.SIMBOL MONEDA,
    rulaje.codpers, rulaje.codcont, rulaje.codmoneda
  FROM rulaje
    LEFT JOIN SOLDINI       ON rulaje.CodCont   = soldini.CodCont AND rulaje.CodPers = soldini.CodPers AND rulaje.CodMoneda = soldini.CodMoneda
    LEFT JOIN NMONEDE MON   ON rulaje.CodMoneda = MON.CodMoneda
    LEFT JOIN NCONT   NCONT ON rulaje.CodCont   = NCONT.CodCont
    LEFT JOIN NPERS   NP    ON rulaje.CodPers   = NP.CodPers
  UNION ALL
  SELECT
    NCONT.SIMBOL, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT, &apos;&apos;&apos;||sTipSold||&apos;&apos;&apos; tipsold,
    SoldIni.soldini SOLDINI, NVL(rulaje.Rul_Debit, 0) DEBIT, NVL(rulaje.Rul_Credit, 0) CREDIT, NVL(rulaje.Rul_Debit_Alte, 0) DEBIT_ALTE, NVL(rulaje.Rul_Credit_Alte, 0) CREDIT_ALTE,
    &apos;||sSoldFin||&apos; SOLDFIN,
    MON.SIMBOL MONEDA,
    soldini.codpers, soldini.codcont, soldini.codmoneda
  FROM soldini
    LEFT JOIN rulaje        ON soldini.CodCont   = rulaje.CodCont AND soldini.CodPers = rulaje.CodPers AND soldini.CodMoneda = rulaje.CodMoneda
    LEFT JOIN NMONEDE MON   ON soldini.CodMoneda = MON.CodMoneda
    LEFT JOIN NCONT   NCONT ON soldini.CodCont   = NCONT.CodCont
    LEFT JOIN NPERS   NP    ON soldini.CodPers   = NP.CodPers
  WHERE NVL(rulaje.Rul_Debit,0) = 0 AND NVL(rulaje.Rul_Debit_Alte,0) = 0 AND NVL(rulaje.Rul_Credit,0) = 0 AND NVL(rulaje.Rul_Credit_Alte,0) = 0 AND NVL(soldini.SoldIni,0) &lt;&gt; 0
  ) misc
    LEFT JOIN NPERS   NP    ON misc.CodPers   = NP.CodPers
    LEFT JOIN NCONT   NCONT ON misc.CodCont   = NCONT.CodCont
    LEFT JOIN NMONEDE MON   ON misc.CodMoneda = MON.CodMoneda&apos;||
    gSuplJoins;
  if PKG_LIST_SELFISAPERS.isSubunit then
    sSelect := sSelect||&apos;
    WHERE NVL(MISC.SOLDINI,0) &lt;&gt; 0 OR NVL(MISC.debit,0) &lt;&gt; 0 OR NVL(MISC.credit,0) &lt;&gt; 0 OR NVL(misc.Credit_Alte,0) &lt;&gt; 0 OR NVL(misc.debit_Alte,0) &lt;&gt; 0 &apos;;
  else
    sSelect := sSelect||&apos;
    WHERE NVL(MISC.SOLDINI,0) &lt;&gt; 0 OR NVL(MISC.debit,0) &lt;&gt; 0 OR NVL(MISC.credit,0) &lt;&gt; 0 &apos;;
  end if;

END;

PROCEDURE processList(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  SetSql(tmpname, aLISTID, aLISTVER, 0);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE processListHolding(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  SetSql(tmpname, aLISTID, aLISTVER, 1);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_BALSINTPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D74AA5CD410B73992536925885EF337496325C0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSTOC IS

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);

  -- si -&gt; stoc initial; ci - cant.intr; ce - cant.ies; ti -&gt; cant.intr.transfer; ir - cant.intr.retur; ie - intrari pe doc de iesire

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       CLOB;
  sSelectS      CLOB;
  sSelectV      CLOB;
  sSelectT      CLOB;
  sUpdate1      CLOB;
  sUpdate2      CLOB;
  vToateGest    BOOLEAN        := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt   BOOLEAN        := PKG_LIST_SELECTSCAD.ToateIoart;
  vCondAnLuna   VARCHAR2(  300);
  vAnLucru      NUMBER         := PKG_GLOBALS.GETANLUCRU;
  vLunaLucru    NUMBER         := PKG_GLOBALS.GETLUNALUCRU;
  sALLucru      NUMBER         := To_Char(PKG_GLOBALS.AnLunaLucru, &apos;fm00000&apos;);
  vALMax        NUMBER;
  vAlTMP        NUMBER;
  vAnTMP        NUMBER;
  vLunaTMP      NUMBER;
  vAnIni        NUMBER;
  vLunaIni      NUMBER;
  vAnPreced     NUMBER;
  vLunaPreced   NUMBER;
  vDataIni      DATE           := PKG_LIST_SELECTSCAD.DataIni;
  vDataFin      DATE           := PKG_LIST_SELECTSCAD.DataScad;
  sDataIni      VARCHAR2(  100);
  sDataFin      VARCHAR2(  100);
  vAuxPret      CLOB;
  vAuxPret_CI   CLOB;
  vAuxPret_CFI  CLOB;
  vAuxSold      CLOB;
  sCondPmp      VARCHAR2(  200);
  sAnLuna       VARCHAR2(  200);
  gAnLuna       VARCHAR2(  200);
  sStocIni      VARCHAR2( 1000);
  sStocIniT     VARCHAR2( 1000);
  sAuxIes       VARCHAR2(  200):= &apos;(16, 19, 20, 21, 22, 23, 24)&apos; ;
  sAuxMar       VARCHAR2( 5000):= &apos;&apos;;
  sAuxMarV      VARCHAR2( 5000):= &apos;&apos;;
  vCondIoart    VARCHAR2(  500):= &apos;&apos;;
  vCondGestN    VARCHAR2(  500):= &apos;&apos;;
  vCondGestLV   VARCHAR2(  500):= &apos;&apos;;
  vCondGestG    VARCHAR2(  500):= &apos;&apos;;
  bSerii        BOOLEAN        := PKG_LIST_SELECTSCAD.Extra1;
  bPeLuni       BOOLEAN        := FALSE;
  bInclVal      BOOLEAN        := FALSE;
  bInclTerti    BOOLEAN        := PKG_LIST_SELECTSCAD.Extra3;
  bFaraRezInv   BOOLEAN        := PKG_LIST_SELECTSCAD.FaraRezInventar;
  sSerTG        VARCHAR2( 1000):= &apos;, NULL SERIE, NULL SerObs, NS.TG, NULL CODCERTIF&apos;;
  sSerTG_C      VARCHAR2( 1000):= &apos;, NULL SERIE, NULL SerObs, NULL TG, NULL CODCERTIF&apos;;
  sJoinSerNL    VARCHAR2( 1000);
  sJoinSerN     VARCHAR2( 1000);
  sJoinSerL     VARCHAR2( 1000);
  sSI           VARCHAR2( 1000);
  sNSCantNIR    VARCHAR2( 1000):=&apos;NS.CANTNIR&apos;;
  sNSCantUM1    VARCHAR2( 1000):=&apos;NS.CANTUM1&apos;;
  sNSCantUM2    VARCHAR2( 1000):=&apos;NS.CANTUM2&apos;;
  sSubPMP       VARCHAR2(   50):=&apos;1&apos;;
  bCalcPMP      BOOLEAN;
  vGestAcces    INTEGER;
BEGIN
  vGestAcces := to_number(Coalesce(pkg_categconst.GetValConstanta(&apos;GestAccesListeStoc&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),&apos;2&apos;));
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=
    &apos;tmp_lst_bals s, nartobj o, nart a, ioart io, ncont c, ncont1 c1, nconts cs, ngest g, npart pcust, npart prod, nclasea ca, nartamb aa, npers pg, ncarsupart csa, nagenda sgest, nlocalit lgest, njudet jgest, nclaseas cas,&apos;||
    &apos;nsubunit sub&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,  &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,  &apos;OATR&apos;,  &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,     &apos;CERTC&apos;, &apos;CERT.CODCERTIF = S.CODCERTIF&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIF&apos;,      &apos;CERT&apos;,  &apos;CERT.CODCERTIF = S.CODCERTIF&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJTRAD&apos;, &apos;TRAD&apos;,  &apos;TRAD.CODOBIECT = O.CODOBIECT AND TRAD.CODLIMBA = &apos;||Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;LIMBADENART&apos;,vANLUCRU,vLUNALUCRU),&apos;0&apos;) );

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTSCAD.Extra2 THEN
    bInclVal := (aLISTID =  26);
    bPeLuni  := (aLISTID = 206);
  END IF;

  sSi := &apos;,
    NL.REST SI, NL.RESTUM1 SI1, NL.RESTUM2 SI2&apos;;

  IF aLISTID = 26
  THEN
    vCondAnLuna := &apos;= &apos;||sALLucru;
    vDataIni    := To_Date(To_Char(vAnLucru, &apos;fm0000&apos;)||To_Char(vLunaLucru,&apos;fm00&apos;),&apos;YYYYMM&apos;);
    vDataFin    := Last_Day(vDataIni);
    vAnIni      := vAnLucru;
    vLunaIni    := vLunaLucru;
    sCondPmp    := &apos; or ((s.ie &lt;&gt; 0) AND (s.mg = 3))&apos;;
  ELSE
    IF Trunc(vDataIni,&apos;MM&apos;) = Trunc(vDataFin,&apos;MM&apos;)
    THEN vCondAnLuna := &apos;= &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;));
    ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;))||&apos; AND &apos;||To_Char(To_Char(vDataFin,&apos;yyyy&apos;)*12+To_Char(vDataFin,&apos;mm&apos;));
    END IF;
    vAnIni      := EXTRACT(YEAR  FROM vDataIni);
    vLunaIni    := EXTRACT(MONTH FROM vDataIni);
  END IF;
  sDataIni := &apos;To_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin := &apos;To_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  pkg_globals.Calculeaza_Luna_Precedenta(vAnIni,vLunaIni,vAnPreced,vLunaPreced);

  IF PKG_LIST_SELECTSCAD.FaraPret
  THEN
    vAuxPret     := &apos;, 0 pret, 0 adaos, 0 puval&apos;;
    vAuxPret_CI  := &apos;, 0 pret, 0 adaos, 0 puval&apos;;
    vAuxPret_CFI := &apos;, 0 pret, 0 adaos, 0 puval&apos;;
    vAuxSold     := &apos;,
    0 pret, 0 pretach, 0 puval, 0 soldini, 0 soldint, 0 soldies, 0 sold,
    0 pmplei, 0 pmpval, 0 pmpprec, 0 pmpprecval&apos;;
  ELSE
    vAuxPret     := &apos;, ns.pret, ns.adaos, &apos;||CASE WHEN bPeLuni THEN &apos;0&apos; ELSE &apos;Coalesce(ns.puval, 0)&apos; END||&apos; AS puval &apos;;  --Ticket 67474 
    vAuxPret_CI  := &apos;, Coalesce(i1.pucorelat, i1.pu) pret, 0 adaos, 0 puval&apos;;
    vAuxPret_CFI := &apos;, Coalesce(ae1.pucorelat,i1.pu) pret, 0 adaos, 0 puval&apos;;
    vAuxSold     := &apos;, s.pret, s.pret - s.adaos, s.puval, s.si*s.pret soldini, s.ci*s.pret soldint, s.ce*s.pret soldies, (s.si+s.ci-s.ce)*s.pret sold,
    0 pmplei, 0 pmpval, 0 pmpprec, 0 pmpprecval&apos;;
  END IF;

  sStocIni := &apos;,
    SUM(SI) SI, SUM(SI1) SI1, SUM(SI2) SI2&apos;;
  sStocIniT := &apos;,
    SUM(SI) SI, SUM(SI1) SI1, SUM(SI2) SI2&apos;;
  IF aLISTID = 26 THEN
    sAnLuna := &apos;, &apos;||vAnIni||&apos; An, &apos;||vLunaIni||&apos; Luna&apos;;
  ELSIF bPeLuni THEN
    sAnLuna  := &apos;, An, Luna&apos;;
    gAnLuna  := &apos;, An, Luna&apos;;
    sStocIni := &apos;,
      SUM(SI) +Coalesce(SUM(SUM(SI) +SUM(CI) -SUM(CE) ) OVER (PARTITION BY GEST,CODLOCATIE,CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI,
      SUM(SI1)+Coalesce(SUM(SUM(SI1)+SUM(CI1)-SUM(CE1)) OVER (PARTITION BY GEST,CODLOCATIE,CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI1,
      SUM(SI2)+Coalesce(SUM(SUM(SI2)+SUM(CI2)-SUM(CE2)) OVER (PARTITION BY GEST,CODLOCATIE,CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI2&apos;;
    sStocIniT := &apos;,
      SUM(SI) +Coalesce(SUM(SUM(SI) +SUM(CI) -SUM(CE) ) OVER (PARTITION BY CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI,
      SUM(SI1)+Coalesce(SUM(SUM(SI1)+SUM(CI1)-SUM(CE1)) OVER (PARTITION BY CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI1,
      SUM(SI2)+Coalesce(SUM(SUM(SI2)+SUM(CI2)-SUM(CE2)) OVER (PARTITION BY CODOBIECT,CODIOART,CONT,MG,SERIE,SEROBS,TG,PRET,ADAOS,PUVAL ORDER BY AN,LUNA ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING),0) SI2&apos;;
  ELSE
    sAnLuna := &apos;, &apos;||EXTRACT(YEAR FROM vDataFin)||&apos; An, &apos;||EXTRACT(MONTH FROM vDataFin)||&apos; Luna&apos;;
  END IF;

  IF NOT vToateIOArt THEN
    vCondIoart := &apos;
      AND CODIOART IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
  END IF;

  IF NOT vToateGest THEN
    vCondGestN := &apos;
      AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    vCondGestLV := &apos;
      AND LV.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    vCondGestG := &apos;
      AND G.CODGEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  ELSE
    if vGestAcces &lt;&gt; 1 then
      DELETE TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
      INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
      SELECT &apos;CODGEST&apos;, CODGEST
      FROM NGEST WHERE PKG_NOMGEST.GESTIUNE_DEDICATA(CODGEST) &gt; 0;
      vCondGestN := &apos;
        AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      vCondGestLV := &apos;
        AND LV.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      vCondGestG := &apos;
        AND G.CODGEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    end if;
  END IF;

  IF bSerii THEN
    sJoinSerNL := &apos;
      LEFT JOIN nirserluna nserl ON nserl.codnirstoc = ns.codnirstoc AND nserl.an = &apos;||vANPreced||&apos; AND nserl.luna = &apos;||vLunaPreced||&apos;
      LEFT JOIN nirser nser ON nser.codnirser = nserl.codnirser
      LEFT JOIN nserii ser on ser.codserie = nser.codserie&apos;;
    sJoinSerN := &apos;
      LEFT JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
      LEFT JOIN nserii ser on ser.codserie = nser.codserie&apos;;
    sJoinSerL :=&apos;
      LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
      LEFT JOIN nserii ser on ser.codserie = nser.codserie&apos;;
    sSerTG := &apos;, ser.serie, nser.obs serobs, Coalesce(nser.tg, ns.tg) tg, nser.codcertif&apos;;
    sSi := &apos;,
      Coalesce(NSERL.REST,NL.REST) SI, Coalesce(NSERL.RESTUM1,NL.RESTUM1) SI1, Coalesce(NSERL.RESTUM2,NL.RESTUM2) SI2&apos;;
    sNSCantNIR :=&apos;Coalesce(NSER.CANTNIR,NS.CANTNIR)&apos;;
    sNSCantUM1 :=&apos;Coalesce(NSER.CANTUM1,NS.CANTUM1)&apos;;
    sNSCantUM2 :=&apos;Coalesce(NSER.CANTUM2,NS.CANTUM2)&apos;;
  END IF;

  IF NOT bFaraRezInv THEN
    sAuxIes := &apos;(14, 16, 19, 20, 21, 22, 23, 24)&apos; ;
    sAuxMar := &apos;
    UNION ALL -- MARIRI DE STOC
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, I.AN, I.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANT ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM2 ELSE 0 END SI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT END CI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END CI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; OR N.CODIES = I.CODIES THEN 0 WHEN Coalesce(N.CODIES,0) = I.CODIES THEN -L1.CANT ELSE 0 END IE
    FROM LIVR1 L1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      INNER JOIN IESIRI  I  ON I.CODIES      = L.CODIES
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST   G  ON N.GEST        = G.CODGEST
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;&apos;||
      vCondGestN;

    sAuxMarV := &apos;
    UNION ALL -- MARIRI DE STOC
    SELECT
      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
      CASE WHEN trunc(L.DATALIVR) &lt; &apos;||sDataIni||&apos; THEN LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1,0 SI2,
      CASE WHEN trunc(L.DATALIVR) &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM LIVRVAL LV
      INNER JOIN IOA        ON IOA.CODIOART  = LV.CODIOART
      INNER JOIN LIVR1   L1 ON L1.CODLIVR1   = LV.CODLIVR1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      INNER JOIN IESIRI  I  ON I.CODIES      = L.CODIES
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST   G  ON N.GEST        = G.CODGEST
    WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;&apos;||
    vCondGestLV;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    X_Judet, X_CodSubunit, X_CodGest,
    CodObiect, DenArt, PartCust, DenGest, DenLGest, DenSub, DenCont, DenContS, DenUM, DenUM1, DenUM2, An, Luna, CodExt, CodInt, Prod,
    StocInit, CantIntr, CantIes, CantIntrRet, CantTransfIn, CantIesIn, StocFinal, StocInitUM1, CantIntrUM1, CantIesUM1, StocFinUM1, StocInitUM2, CantIntrUM2, CantIesUM2, StocFinUM2,
    MG,
    UMTRANSF,
    COEFTRANSF, PULEI, PUVALUTA, CLASAACOMPL, SERIE, SEROBS, TG,
    PretInreg, PretAch, PUVal, SoldInit, ValIntr, ValIes, SoldFinal,
    PMP, PMPVALUTA, PMPPREC, PMPPRECVAL&apos;||gUserFields||&apos; )&apos;;

  sSelectS :=&apos;
  WITH IOA AS (
    SELECT codioart, cont, mg
    FROM ioart1
    WHERE &apos;||sALLucru||&apos; BETWEEN ALStart and ALStop  AND mg &lt;&gt; 5 &apos;||vCondIoart||&apos;),
  B AS (
    -- Initial
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, &apos;||vAnIni||&apos; AN, &apos;||vLunaIni||&apos; LUNA&apos;||
      sSI||&apos;,
      0 CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM nirluna nl
      INNER JOIN nirstoc ns ON ns.codnirstoc = nl.codnirstoc
      INNER JOIN nir     n  ON n.codnir      = ns.codnir
      INNER JOIN ngest   g  ON g.codgest     = n.gest
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerNL||&apos;
    WHERE nl.an = &apos;||vANPreced||&apos; AND nl.luna = &apos;||vLunaPreced||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestN||&apos;
    UNION ALL -- NIR Intrari
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, I.AN, I.LUNA,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTNIR||&apos; ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM1||&apos; ELSE 0 END SI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM2||&apos; ELSE 0 END SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END CI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM1||&apos; END CI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM2||&apos; END CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM NIRSTOC NS
      INNER JOIN NIR     N ON N.CODNIR     = NS.CODNIR
      INNER JOIN NGEST   G ON N.GEST       = G.CODGEST
      INNER JOIN INTRARI I ON I.CODINTR    = N.CODINTR
      INNER JOIN IOA       ON IOA.CODIOART = NS.CODIOART&apos;||
      sJoinSerN||&apos;
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestN||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- NIR-uri din MISCARI INTERNE
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, T.AN, T.LUNA,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTNIR||&apos; ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM1||&apos; ELSE 0 END SI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM2||&apos; ELSE 0 END SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END CI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM1||&apos; END CI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM2||&apos; END CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; OR N.TIPNIR &lt;&gt; 12 THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END TI, 0 IE
    FROM NIRSTOC NS
      INNER JOIN NIR    N ON N.CODNIR     = NS.CODNIR
      INNER JOIN NGEST  G ON N.GEST       = G.CODGEST
      INNER JOIN TRANSF T ON T.CODTRANSF  = N.CODTRANSF
      INNER JOIN IOA      ON IOA.CODIOART = NS.CODIOART&apos;||
      sJoinSerN||&apos;
    WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      vCondGestN||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- RETURURI
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, I.AN, I.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT END CI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM1 END CI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM2 END CI2,
      0 CE, 0 CE1, 0 CE2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT END IR, 0 TI, 0 IE
    FROM LIVR1 L1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      INNER JOIN INTRARI I  ON I.CODINTR     = L.CODINTR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST   G  ON N.GEST        = G.CODGEST
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      vCondGestN||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- IESIRI
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, I.AN, I.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      0 CI, 0 CI1, 0 CI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT END CE,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END CE1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END CE2,
      0 IR, 0 TI, CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; OR N.CODIES = I.CODIES THEN 0 WHEN Coalesce(N.CODIES,0) = I.CODIES THEN L1.CANT ELSE 0 END IE
    FROM LIVR1 L1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      INNER JOIN IESIRI  I  ON I.CODIES      = L.CODIES   AND I.TIPDOC = L.TIPLIVR
      INNER JOIN IESIRI1 I1 ON I1.CODIES1    = L1.CODIES1 AND I1.CODIES = I.CODIES
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST   G  ON N.GEST        = G.CODGEST
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE L.TIPLIVR IN &apos;||sAuxIes||&apos; AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      vCondGestN||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- MISCARI INTERNE
    SELECT N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;, T.AN, T.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      0 CI, 0 CI1, 0 CI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT END CE,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END CE1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END CE2,
      0 IR, 0 TI, 0 IE
    FROM LIVR1 L1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      INNER JOIN TRANSF  T  ON T.CODTRANSF   = L.CODTRANSF
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST   G  ON N.GEST        = G.CODGEST
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      vCondGestN||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;&apos;||
    sAuxMar||&apos;),
  BALS AS (
    SELECT
      0 PARTCUST, GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF,PRET,ADAOS,PUVAL&apos;||sAnLuna||
      sStocIni||&apos;,
      sum(CI) CI, sum(CI1) CI1, sum(CI2) CI2, sum(CE) CE, sum(CE1) CE1, sum(CE2) CE2, sum(IR) IR, sum(TI) TI, sum(IE) IE
    FROM b
    GROUP BY gest, codlocatie, codobiect, codioart, cont, mg, serie, serobs, tg, codcertif, pret, adaos, puval&apos;||gAnLuna||&apos;),
  CAC AS (
    SELECT codclasea, SUBSTR(SYS_CONNECT_BY_PATH(den_clasea,&apos;&apos;|&apos;&apos;),2) den_compl
    FROM nclasea
    CONNECT BY codparinte = PRIOR codclasea
    START WITH Coalesce(codparinte,0) = 0 AND codclasea &lt;&gt; 0)
  SELECT
    jgest.simbauto, sub.codsubunit, g.codgest,
    s.codobiect, o.denumire, pcust.den_part, g.den_gest, l.denumire, sub.den_subunit, c.simbol, cs.simbol, u.den_um1, u1.den_um, u2.den_um, s.an, s.luna, o.codextern, o.codintern, prod.den_part,
    s.si, s.ci, s.ce, s.ir, s.ti, s.ie, s.si+s.ci-s.ce stoc, s.si1, s.ci1, s.ce1, s.si1+s.ci1-s.ce1 stocum1, s.si2, s.ci2, s.ce2, s.si2+s.ci2-s.ce2 stocum2,
    CASE s.mg WHEN 1 THEN &apos;&apos;FIFO&apos;&apos; WHEN 2 THEN &apos;&apos;LIFO&apos;&apos; WHEN 3 THEN &apos;&apos;PMP&apos;&apos; WHEN 4 THEN &apos;&apos;IDS&apos;&apos; WHEN 5 THEN &apos;&apos;VAL&apos;&apos; END MG,
    CASE num.tipum WHEN 1 THEN &apos;&apos;Kg&apos;&apos; WHEN 2 THEN &apos;&apos;Cm3&apos;&apos; WHEN 3 THEN &apos;&apos;M2&apos;&apos; WHEN 4 THEN &apos;&apos;M&apos;&apos; WHEN 5 THEN &apos;&apos;Buc&apos;&apos; END UMTRANSF,
    num.coef, pm.lei, pm.valuta, cac.den_compl, s.Serie, s.SerObs, s.TG &apos;||
    vAuxSold||gUserAlias||&apos;
  FROM BALS S
    LEFT JOIN nartobj    o     ON o.codobiect      = s.codobiect
    LEFT JOIN ngest      g     ON g.codgest        = s.gest
    LEFT JOIN npart      pcust ON pcust.codpart    = s.partcust
    LEFT JOIN pretm      pm    on o.codobiect      = pm.codobiect and pm.subunitatea = g.codsubunit and pm.implicit = 1
    LEFT JOIN nart       a     ON a.codarticol     = o.codarticol
    LEFT JOIN num1       u     ON u.codum          = a.um       AND u.secundara = 0
    LEFT JOIN num              on a.um             = num.codum
    LEFT JOIN num        u1    ON u1.codum         = a.um1
    LEFT JOIN num        u2    ON u2.codum         = a.um2
    LEFT JOIN ioart      io    ON io.codioart      = s.codioart
    LEFT JOIN ncont      c     ON c.codcont        = s.cont
    LEFT JOIN ncont1     c1    ON c1.codcont       = s.cont AND &apos;||sALLucru||&apos; Between c1.ALStart and c1.ALStop
    LEFT JOIN nconts     cs    ON cs.codconts      = c1.contsecundar
    LEFT JOIN npers      pg    ON pg.codpers       = g.codgestionar
    LEFT JOIN nlocatii   l     ON l.codlocatie     = s.codlocatie
    LEFT JOIN nsubunit   sub   ON sub.codsubunit   = g.codsubunit
    LEFT JOIN npart      prod  ON prod.codpart     = o.codproducator
    LEFT JOIN nclasea    ca    ON ca.codclasea     = a.clasa
    LEFT JOIN nclaseas   cas   ON cas.codclaseas   = a.clasastatist
    LEFT JOIN cac              ON cac.codclasea    = a.clasa
    LEFT JOIN nartamb    aa    ON aa.codobiect     = s.codobiect AND aa.umsec = u.codum1
    LEFT JOIN ncarsupart csa   ON csa.codcarsupart = o.codcaract
    LEFT JOIN nagenda    sgest ON sgest.codgest    = g.codgest
    LEFT JOIN nlocalit   lgest ON lgest.codlocalit = sgest.codlocalit
    LEFT JOIN njudet     jgest ON jgest.codjudet   = lgest.codjudet&apos;||
    gSuplJoins||&apos;
  WHERE ((s.si &lt;&gt; 0) or (s.ci &lt;&gt; 0) or (s.ce &lt;&gt; 0) or (Coalesce(s.si2,0) &lt;&gt; 0) or (Coalesce(s.ci2,0) &lt;&gt; 0) or (Coalesce(s.ce2,0) &lt;&gt; 0)&apos;||sCondPMP||&apos;) &apos;;

  -- partea valorica daca este cazul
  sSelectV := &apos;
  WITH
  IOA AS (
    SELECT codioart, cont, mg
    FROM ioart1
    WHERE &apos;||sALLucru||&apos; BETWEEN ALStart and ALStop AND mg = 5 &apos;||vCondIoart||&apos;),
  B AS (
    -- Initial
    SELECT
      SVL.GEST, SVL.CODIOART, IOA.CONT, IOA.MG, &apos;||vAnIni||&apos; An, &apos;||vLunaIni||&apos; Luna,
      SVL.SOLD SI, 0 SI1, 0 SI2,
      0 CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM STOCVALLUNA SVL
      INNER JOIN ngest g ON g.codgest    = svl.gest
      INNER JOIN ioa     ON ioa.codioart = svl.codioart
    WHERE svl.an = &apos;||vANPreced||&apos; AND svl.luna = &apos;||vLunaPreced||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestG||&apos;
    UNION ALL -- NIR Intrari
    SELECT
      N.GEST, NS.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR * NS.PRET ELSE 0 END SI, 0 SI1, 0 SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR * NS.PRET END CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM NIRSTOC NS
      INNER JOIN IOA       ON IOA.CODIOART = NS.CODIOART
      INNER JOIN NIR     N ON N.CODNIR     = NS.CODNIR
      INNER JOIN ngest   g ON g.codgest    = N.gest
      INNER JOIN INTRARI I ON I.CODINTR    = N.CODINTR
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestN||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- NIR-uri din MISCARI INTERNE
    SELECT
      N.GEST, NS.CODIOART, IOA.CONT, IOA.MG, T.AN, T.LUNA,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR * NS.PRET ELSE 0 END SI, 0 SI1, 0 SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR * NS.PRET END CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      0 IR, CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; OR N.TIPNIR &lt;&gt; 12 THEN 0 ELSE NS.CANTNIR * NS.PRET END TI, 0 IE
    FROM NIRSTOC NS
      INNER JOIN IOA      ON IOA.CODIOART = NS.CODIOART
      INNER JOIN NIR    N ON N.CODNIR     = NS.CODNIR
      INNER JOIN ngest  g ON g.codgest    = N.gest
      INNER JOIN TRANSF T ON T.CODTRANSF  = N.CODTRANSF
    WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestN||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- LIVRARI INTRARI
    SELECT
      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN - LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE - LV.PRETINREG * L1.CANT END CI, 0 CI1, 0 CI2,
      0 CE, 0 CE1, 0 CE2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE - LV.PRETINREG * L1.CANT END IR, 0 TI, 0 IE
    FROM LIVRVAL LV
      INNER JOIN IOA        ON IOA.CODIOART = LV.CODIOART
      INNER JOIN LIVR1   L1 ON L1.CODLIVR1  = LV.CODLIVR1
      INNER JOIN LIVR    L  ON L.CODLIVR    = L1.CODLIVR
      INNER JOIN INTRARI I  ON I.CODINTR    = L.CODINTR
      INNER JOIN ngest   g ON g.codgest     = LV.gest
    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestLV||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- LIVRARI IESIRI
    SELECT
      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN - LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
      0 CI, 0 CI1, 0 CI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM LIVRVAL LV
      INNER JOIN IOA        ON IOA.CODIOART = LV.CODIOART
      INNER JOIN LIVR1   L1 ON L1.CODLIVR1  = LV.CODLIVR1
      INNER JOIN LIVR    L  ON L.CODLIVR    = L1.CODLIVR
      INNER JOIN IESIRI  I  ON I.CODIES     = L.CODIES AND I.TIPDOC = L.TIPLIVR
      INNER JOIN IESIRI1 I1 ON I1.CODIES1   = L1.CODIES1 AND I1.CODIES = I.CODIES
      INNER JOIN ngest   g ON g.codgest     = LV.gest
    WHERE L.TIPLIVR IN &apos;||sAuxIes||&apos; AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestLV||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
    UNION ALL -- LIVRARI MISCARI INTERNE
    SELECT
      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, T.AN, T.LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
      0 CI, 0 CI1, 0 CI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CE, 0 CE1, 0 CE2,
      0 IR, 0 TI, 0 IE
    FROM LIVRVAL LV
      INNER JOIN IOA       ON IOA.CODIOART = LV.CODIOART
      INNER JOIN LIVR1  L1 ON L1.CODLIVR1  = LV.CODLIVR1
      INNER JOIN LIVR   L  ON L.CODLIVR    = L1.CODLIVR
      INNER JOIN TRANSF T  ON T.CODTRANSF  = L.CODTRANSF
      INNER JOIN ngest   g ON g.codgest     = LV.gest
    WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      vCondGestLV||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;&apos;||
      sAuxMarV||&apos;),
  BALS AS (
    SELECT
      0 partcust, gest, 0 codlocatie, 0 codobiect, codioart, cont, mg, 1 pret, 0 adaos, 0 puval&apos;||sAnLuna||&apos;,
      sum(SI) SI, sum(SI1) SI1, sum(SI2) SI2, sum(CI) CI, sum(CI1) CI1, sum(CI2) CI2, sum(IR) IR, sum(TI) TI, sum(IE) IE, sum(CE) CE, sum(CE1) CE1, sum(CE2) CE2
    FROM b
    GROUP BY gest, codioart, cont, mg&apos;||gAnLuna||&apos;),
  CAC AS (
    SELECT codclasea, SUBSTR(SYS_CONNECT_BY_PATH(den_clasea,&apos;&apos;|&apos;&apos;),2) den_compl
    FROM nclasea
    CONNECT BY codparinte = PRIOR codclasea
    START WITH Coalesce(codparinte,0) = 0 AND codclasea &lt;&gt; 0)
  SELECT
    jgest.simbauto, sub.codsubunit, g.codgest,
    s.codobiect, &apos;&apos;Tranzactii valorice&apos;&apos;, pcust.den_part, g.den_gest, l.denumire, sub.den_subunit, c.simbol, cs.simbol, &apos;&apos;LEI&apos;&apos;, NULL, NULL, s.an, s.luna, o.codextern, o.codintern, prod.den_part,
    s.si, s.ci, s.ce, s.ir, s.ti, s.ie, s.si+s.ci-s.ce stoc, s.si1, s.ci1, s.ce1, s.si1+s.ci1-s.ce1 stocum1, s.si2, s.ci2, s.ce2, s.si2+s.ci2-s.ce2 stocum2,
    &apos;&apos;VAL&apos;&apos;,
    NULL,
    1, pm.lei, pm.valuta, cac.den_compl, NULL Serie, NULL SerObs, NULL TG&apos;||
    vAuxSold||gUserAlias||&apos;
  FROM BALS S
    LEFT JOIN nartobj    o     ON o.codobiect      = s.codobiect
    LEFT JOIN ngest      g     ON g.codgest        = s.gest
    LEFT JOIN npart      pcust ON pcust.codpart    = s.partcust
    LEFT JOIN pretm      pm    on o.codobiect      = pm.codobiect and pm.subunitatea = g.codsubunit and pm.implicit = 1
    LEFT JOIN nart       a     ON a.codarticol     = o.codarticol
    LEFT JOIN num1       u     ON u.codum          = a.um AND u.secundara = 0
    LEFT JOIN ioart      io    ON io.codioart      = s.codioart
    LEFT JOIN ncont      c     ON c.codcont        = s.cont
    LEFT JOIN ncont1     c1    ON c1.codcont       = s.cont AND &apos;||sALLucru||&apos; BETWEEN c1.ALStart and c1.ALStop
    LEFT JOIN nconts     cs    ON cs.codconts      = c1.contsecundar
    LEFT JOIN npers      pg    ON pg.codpers       = g.codgestionar
    LEFT JOIN nlocatii   l     ON l.codlocatie     = s.codlocatie
    LEFT JOIN nsubunit   sub   ON sub.codsubunit   = g.codsubunit
    LEFT JOIN npart      prod  ON prod.codpart     = o.codproducator
    LEFT JOIN nclasea    ca    ON ca.codclasea     = a.clasa
    LEFT JOIN cac              ON cac.codclasea    = a.clasa
    LEFT JOIN nartamb    aa    ON aa.codobiect     = s.codobiect AND aa.umsec = u.codum1
    LEFT JOIN ncarsupart csa   ON csa.codcarsupart = o.codcaract
    LEFT JOIN nagenda    sgest ON sgest.codgest    = g.codgest
    LEFT JOIN nlocalit   lgest ON lgest.codlocalit = sgest.codlocalit
    LEFT JOIN njudet     jgest ON jgest.codjudet   = lgest.codjudet&apos;||
    gSuplJoins||&apos;
  WHERE ((s.si &lt;&gt; 0) or (s.ci &lt;&gt; 0) or (s.ce &lt;&gt; 0) or (Coalesce(s.si2,0) &lt;&gt; 0) or (Coalesce(s.ci2,0) &lt;&gt; 0) or (Coalesce(s.ce2,0) &lt;&gt; 0)&apos;||sCondPMP||&apos;) &apos;;

  -- Stocuri la terti daca este cazul
  sSelectT :=&apos;
  WITH
  IOA AS (
    SELECT codioart, custodie cont, mg
    FROM ioart1
    WHERE &apos;||sALLucru||&apos; BETWEEN ALStart and ALStop AND mg &lt;&gt; 5&apos;||vCondIoart||&apos;),
  B AS (
    SELECT -- custodie initializari
      I.PARTENER PARTCUST, I1.CODOBIECT, I1.CODIOARTCUST CODIOART, COALESCE(IOA.CONT, 0) CONT, IOA.MG&apos;||sSerTG_C||vAuxPret_CI||&apos;,
      &apos;||vAnIni  ||&apos; AN,
      &apos;||vLunaIni||&apos; LUNA,
      I1.CANT SI,
      0 SI1,
      0 SI2,
      0 CI,
      0 CI1,
      0 CI2,
      0 CE,
      0 CE1,
      0 CE2,
      0 IR, 0 TI, 0 IE
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES    = I.CODIES
      INNER JOIN IOA        ON IOA.CODIOART = I1.CODIOARTCUST
    WHERE I.TIPDOC = 20 AND I.CUSTODIE = 1 AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND I.AN * 12 + I.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI)
    UNION ALL
    SELECT -- custodie facturi la initializari
      I.PARTENER PARTCUST, I1.CODOBIECT, AE1.CODIOARTCUST CODIOART, COALESCE(IOA.CONT, 0) CONT, IOA.MG&apos;||sSerTG_C||vAuxPret_CFI||&apos;,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vAnIni  ||&apos; ELSE I.An   END AN,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vLunaIni||&apos; ELSE I.Luna END LUNA,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN -I1.CANT ELSE 0 END SI,
      0 SI1,
      0 SI2,
      0 CI,
      0 CI1,
      0 CI2,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN 0 ELSE I1.CANT END CE,
      0 CE1,
      0 CE2,
      0 IR, 0 TI, 0 IE
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies    = i.codies
      INNER JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      INNER JOIN iesiri1 ae1  ON ae1.codies1  = ilae.codlinieaviz
      INNER JOIN iesiri  ae   ON ae.codies    = ae1.codies
      INNER JOIN IOA          ON IOA.CODIOART = AE1.CODIOARTCUST
    WHERE I.TIPDOC = 26 AND I.OPERAT = 1 AND I.ANULAT = 0
      AND trunc(I.DATADOC) &lt;= &apos;||sDataFin||&apos;
      AND AE.TIPDOC = 20 AND AE.CUSTODIE = 1 AND AE.OPERAT = 1 AND AE.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
      AND AE.AN * 12 + AE.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI)
    UNION ALL
    SELECT -- custodie iesiri avize
      I.PARTENER PARTCUST, I1.CODOBIECT, NS.CODIOART, COALESCE(IOA.CONT, 0) CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vAnIni  ||&apos; ELSE I.An   END AN,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vLunaIni||&apos; ELSE I.Luna END LUNA,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANT ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM2 ELSE 0 END SI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END CI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END CI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END CI2,
      0 CE,
      0 CE1,
      0 CE2,
      0 IR, 0 TI, 0 IE
    FROM IESIRI I
      INNER JOIN LIVR    L  ON L.CODIES      = I.CODIES AND L.TIPLIVR = I.TIPDOC
      INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN IESIRI1 I1 ON I1.CODIES1    = L1.CODIES1 AND I1.CODIES = I.CODIES
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE I.TIPDOC = 20 AND I.CUSTODIE = 1 AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
      AND I.AN * 12 + I.LUNA &gt;= (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI)
    UNION ALL
    SELECT -- custodie iesiri facturi la avize
      I.PARTENER PARTCUST, I1.CODOBIECT, NS.CODIOART, COALESCE(IOA.CONT, 0) CONT, IOA.MG&apos;||sSerTG||vAuxPret||&apos;,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vAnIni  ||&apos; ELSE I.An   END AN,
      CASE WHEN I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnIni*12+vLunaIni)||&apos; THEN &apos;||vLunaIni||&apos; ELSE I.Luna END LUNA,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN -I1.CANT/AE1.CANT * L1.CANT    ELSE 0 END SI,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN -I1.CANT/AE1.CANT * L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN -I1.CANT/AE1.CANT * L1.CANTUM2 ELSE 0 END SI2,
      0 CI,
      0 CI1,
      0 CI2,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN 0 ELSE I1.CANT/AE1.CANT * L1.CANT    END CE,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN 0 ELSE I1.CANT/AE1.CANT * L1.CANTUM1 END CE1,
      CASE WHEN I.DATADOC &lt; &apos;||sDataIni||&apos; THEN 0 ELSE I1.CANT/AE1.CANT * L1.CANTUM1 END CE2,
      0 IR, 0 TI, 0 IE
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies     = i.codies
      INNER JOIN ieslink ilae ON ilae.codies1  = i1.codies1
      INNER JOIN iesiri1 ae1  ON ae1.codies1   = ilae.codlinieaviz
      INNER JOIN iesiri  ae   ON ae.codies     = ae1.codies
      INNER JOIN LIVR    L    ON L.CODIES      = AE.CODIES AND L.TIPLIVR = AE.TIPDOC
      INNER JOIN LIVR1   L1   ON L1.CODLIVR    = L.CODLIVR AND L1.CODIES1 = AE1.CODIES1
      INNER JOIN NIRSTOC NS   ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N    ON N.CODNIR      = NS.CODNIR
      INNER JOIN IOA          ON IOA.CODIOART  = NS.CODIOART&apos;||
      sJoinSerL||&apos;
    WHERE I.TIPDOC = 26 AND I.OPERAT = 1 AND I.ANULAT = 0
      AND trunc(I.DATADOC) &lt;= &apos;||sDataFin||&apos;
      AND AE.TIPDOC = 20 AND AE.CUSTODIE = 1 AND AE.OPERAT = 1 AND AE.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
      AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||&apos;
      AND AE.AN * 12 + AE.LUNA &gt;= (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI)
  ),
  BALS AS (
    SELECT
      PARTCUST, 0 GEST, 0 CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, PRET, ADAOS, PUVAL&apos;||sAnLuna||
      sStocIniT||&apos;,
      sum(CI) CI, sum(CI1) CI1, sum(CI2) CI2, sum(CE) CE, sum(CE1) CE1, sum(CE2) CE2, sum(IR) IR, sum(TI) TI, sum(IE) IE
    FROM b
    GROUP BY partcust, codobiect, codioart, cont, mg, serie, serobs, tg, codcertif, pret, adaos, puval&apos;||gAnLuna||&apos;),
  CAC AS (
    SELECT codclasea, SUBSTR(SYS_CONNECT_BY_PATH(den_clasea,&apos;&apos;|&apos;&apos;),2) den_compl
    FROM nclasea
    CONNECT BY codparinte = PRIOR codclasea
    START WITH Coalesce(codparinte,0) = 0 AND codclasea &lt;&gt; 0)
  SELECT
    jgest.simbauto, sub.codsubunit, g.codgest,
    s.codobiect, o.denumire, pcust.den_part, g.den_gest, l.denumire, sub.den_subunit, c.simbol, cs.simbol, u.den_um1, u1.den_um, u2.den_um, s.an, s.luna, o.codextern, o.codintern, prod.den_part,
    s.si, s.ci, s.ce, s.ir, s.ti, s.ie, s.si+s.ci-s.ce stoc, s.si1, s.ci1, s.ce1, s.si1+s.ci1-s.ce1 stocum1, s.si2, s.ci2, s.ce2, s.si2+s.ci2-s.ce2 stocum2,
    CASE s.mg WHEN 1 THEN &apos;&apos;FIFO&apos;&apos; WHEN 2 THEN &apos;&apos;LIFO&apos;&apos; WHEN 3 THEN &apos;&apos;PMP&apos;&apos; WHEN 4 THEN &apos;&apos;IDS&apos;&apos; WHEN 5 THEN &apos;&apos;VAL&apos;&apos; END MG,
    CASE num.tipum WHEN 1 THEN &apos;&apos;Kg&apos;&apos; WHEN 2 THEN &apos;&apos;Cm3&apos;&apos; WHEN 3 THEN &apos;&apos;M2&apos;&apos; WHEN 4 THEN &apos;&apos;M&apos;&apos; WHEN 5 THEN &apos;&apos;Buc&apos;&apos; END UMTRANSF,
    num.coef, pm.lei, pm.valuta, cac.den_compl, s.Serie, s.SerObs, s.TG &apos;||
    vAuxSold||gUserAlias||&apos;
  FROM BALS S
    LEFT JOIN nartobj    o     ON o.codobiect      = s.codobiect
    LEFT JOIN ngest      g     ON g.codgest        = s.gest
    LEFT JOIN npart      pcust ON pcust.codpart    = s.partcust
    LEFT JOIN pretm      pm    on o.codobiect      = pm.codobiect and pm.subunitatea = g.codsubunit and pm.implicit = 1
    LEFT JOIN nart       a     ON a.codarticol     = o.codarticol
    LEFT JOIN num1       u     ON u.codum          = a.um AND u.secundara = 0
    LEFT JOIN num              on a.um             = num.codum
    LEFT JOIN num        u1    ON u1.codum         = a.um1
    LEFT JOIN num        u2    ON u2.codum         = a.um2
    LEFT JOIN ioart      io    ON io.codioart      = s.codioart
    LEFT JOIN ncont      c     ON c.codcont        = s.cont
    LEFT JOIN ncont1     c1    ON c1.codcont       = s.cont
    LEFT JOIN nconts     cs    ON cs.codconts      = c1.contsecundar
    LEFT JOIN npers      pg    ON pg.codpers       = g.codgestionar
    LEFT JOIN nlocatii   l     ON l.codlocatie     = s.codlocatie
    LEFT JOIN nsubunit   sub   ON sub.codsubunit   = g.codsubunit
    LEFT JOIN npart      prod  ON prod.codpart     = o.codproducator
    LEFT JOIN nclasea    ca    ON ca.codclasea     = a.clasa
    LEFT JOIN nclaseas   cas   ON cas.codclaseas   = a.clasastatist
    LEFT JOIN cac              ON cac.codclasea    = a.clasa
    LEFT JOIN nartamb    aa    ON aa.codobiect     = s.codobiect AND aa.umsec = u.codum1
    LEFT JOIN ncarsupart csa   ON csa.codcarsupart = o.codcaract
    LEFT JOIN nagenda    sgest ON sgest.codgest    = g.codgest
    LEFT JOIN nlocalit   lgest ON lgest.codlocalit = sgest.codlocalit
    LEFT JOIN njudet     jgest ON jgest.codjudet   = lgest.codjudet&apos;||
    gSuplJoins||&apos;
  WHERE ((s.si &lt;&gt; 0) or (s.ci &lt;&gt; 0) or (s.ce &lt;&gt; 0) or (Coalesce(s.si2,0) &lt;&gt; 0) or (Coalesce(s.ci2,0) &lt;&gt; 0) or (Coalesce(s.ce2,0) &lt;&gt; 0)) &apos;;

  IF Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;TipPMP&apos;, vANLUCRU, vLUNALUCRU), &apos;1&apos;) &lt;&gt; 1 THEN
    sSubPMP := &apos;X_CodSubunit&apos; ;
  END IF;

  sUpdate1 := &apos;UPDATE &apos;||tmpName||&apos;
  SET
    PMP        = PKG_PMP.GET_PMP_LEI(codobiect,&apos;||sSubPMP||&apos;,an,luna),
    PMPVALUTA  = PKG_PMP.GET_PMP_VALUTA_FROM_VAR,
    PMPPREC    = PKG_PMP.GET_PMP_PREC_FROM_VAR,
    PMPPRECVAL = PKG_PMP.GET_PMP_PREC_VALUTA_FROM_VAR
  WHERE MG = &apos;&apos;PMP&apos;&apos;&apos;;

  sUpdate2 := &apos;UPDATE &apos;||tmpName||&apos;
  SET
    SoldInit  = CASE WHEN Coalesce(PMPPREC,0) = 0 THEN SoldInit  ELSE StocInit * PMPPREC END,
    ValIntr   = CASE WHEN Coalesce(PMP,0)     = 0 THEN ValIntr   ELSE (CantIntr - CantTransfIn - CantIntrRet) * PretInreg + (CantTransfIn + CantIntrRet) * PMP END,
    ValIes    = CASE WHEN Coalesce(PMP,0)     = 0 THEN ValIes    ELSE (CantIes - CantIesIn) * PMP + CantIesIn * PretInreg END,
    SoldFinal = CASE WHEN Coalesce(PMP,0)     = 0 THEN SoldFinal ELSE StocFinal * PMP END
  WHERE MG = &apos;&apos;PMP&apos;&apos; AND (Coalesce(PMP,0) &lt;&gt; 0 OR Coalesce(PMPPREC,0) &lt;&gt; 0)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectS, aListID, aListVer);
  IF bInclVal THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectV, aListID, aListVer);
  END IF;
  IF bInclTerti THEN
    COMMIT;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectT, aListID, aListVer);
  END IF;
  IF ((aLISTID = 26) OR bPeLuni) AND NOT PKG_LIST_SELECTSCAD.FaraPret THEN
    -- stef - evit ora-14552 la apelul PKG_PMP.GET_PMP_LEI =&gt; GET_PMP_OBIECT_DOC
    EXECUTE IMMEDIATE &apos;SELECT Coalesce(Min(An*12+LUNA),0), Coalesce(Max(An*12+LUNA),0) FROM &apos;||tmpName INTO vAlTMP, vALMax;
    WHILE vAlTMP &lt;= vALMax AND vALMax &gt; 0 LOOP
      PKG_LIST_BASE_UTILS.ExtractAnLuna(vAlTMP, vAnTMP, vLunaTMP);
      pkg_globals.SetLunaTemp(vAnTMP, vLunaTMP);
      PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);
      vAlTMP := vAlTMP + 1;
    END LOOP;

    LIST_EXECUTE_IMMEDIATE(sUpdate1, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sUpdate2, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_BALSTOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AA36A4E93DD52F6FFD4637F7150C9BCB25AB7D4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSTOC1 IS

  gUserFields VARCHAR2(3000);
  gUserAlias  VARCHAR2(3000);
  gNullAlias  VARCHAR2(3000);
  gSuplCols   VARCHAR2(3000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(30000);
  vToateIoart  BOOLEAN        := PKG_LIST_SELECTIOART.ToateIOArt;
  vAnLucru     Number         := PKG_GLOBALS.GetANLUCRU;
  vLunaLucru   Number         := PKG_GLOBALS.GetLUNALUCRU;
  vAnPreced    Number;
  vLunaPreced  Number;
  vWhere       VARCHAR2( 1000);
  vWhere1      VARCHAR2( 1000);
  vTipDoc      VARCHAR2( 1000);
  vAUX         VARCHAR2(  100);
  sInsertDC    VARCHAR2( 2000);
  sWithDc      VARCHAR2( 2000);
  sSelectDC    VARCHAR2( 2000);
  sJoinDC      VARCHAR2( 2000);
  vMax         INTEGER        := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;
BEGIN
  gSuplCols := &apos;nartobj nao, nart na, num num, nclasea nca, pretm p&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  pkg_globals.Calculeaza_Luna_Precedenta(vAnLucru,vLunaLucru, vAnPreced,vLunaPreced);

  vAUX := &apos;
    AND&apos;;
  if NOT vToateIoart Then
    vWhere := Vaux||&apos; ns.codioart IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
    vAux   := &apos;
      AND&apos;;
  end if;
  vTipDoc := &apos;6,12,13,14,15,23&apos;;
  if pkg_list_selectioart.Extra2 then 
    vTipDoc := &apos;6,23&apos;;
  end if;
  if not pkg_list_selectioart.Extra2 then 
    vWhere := vWhere||&apos; and n.tipnir in (1,2, 3, 4, 5, 19, 20, 21) &apos;;
  end if;
  vWhere1 := &apos;&apos;;
  if not pkg_list_selectioart.Extra2 then 
    vWhere1 := &apos; and coalesce(i.tipdoc,t.tipdoc,o.tipdoc) in (1,2, 3, 4, 5, 19, 20, 21) &apos;;
  end if;
  --vWhere := vWhere||PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;COALESCE(INTR.SUBUNITATEA,I.SUBUNITATEA,T.SUBUNITATEA)&apos;,vAux);
  
  FOR i in 1..Coalesce(vMax,0) loop
    sInsertDC := sInsertDC||&apos;, CLS&apos;   ||to_char(i)||&apos;, CLSS&apos;  ||to_char(i);
    sSelectDC := sSelectDC||&apos;, CLSC.D&apos;||to_char(i)||&apos;, CLSC.S&apos;||to_char(i);
  END LOOP;

  IF Coalesce(vMax,0) &gt; 0 THEN
    sWithDC := sWithDC||&apos;
    Clase AS (
    SELECT codclasea &apos;;
    IF Coalesce(vMax,0) &gt; 0 THEN
      for i in 1..Coalesce(vMax,0) loop
        sWithDC := sWithDC ||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE &apos;&apos;&apos;&apos; end) d&apos;||to_char(i)||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN simbol ELSE &apos;&apos;&apos;&apos; end) s&apos;||to_char(i);
      end loop;
    END IF;
    sWithDC := sWithDC||&apos;
    FROM TMP_PROFIT_NCLASEA
    GROUP BY codclasea),&apos;;

    sJoinDC := sJoinDC||&apos;
    LEFT JOIN clase clsc ON clsc.codclasea = na.clasa&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos; || tmpName || &apos;(DenArt, DenUM, StocIni, ValStocIni, TotInt, ValCInt, PMInt, Ies, ValCIes, ValVIes, Stoc, ValCStoc, ValVStoc, GESTIUNE, ADAOS, DISCPRIM, DISCAC &apos; ||COALESCE(sInsertDC, &apos;&apos;) || gUserFields || &apos;)
   WITH &apos;
    || coalesce(sWithDC,&apos;&apos;) ||
    &apos; nsn AS (
    SELECT ns.codnirstoc, SUM(ns.cantnir) cantint, SUM((1-NVL(I1.COEFDISCMAJ,1))*NS.CANTNIR*NVL(I1.PRETORIG,0)) DISC
    FROM nirstoc ns
    INNER JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN intrari i ON i.codintr = n.codintr
    LEFT JOIN transf t ON t.codtransf = n.codtransf
    LEFT JOIN INTRARI1 I1 ON NS.CODINTR1 = I1.CODINTR1 AND I1.CODINTR = I.CODINTR
    WHERE NVL(N.OPERAT,0) = 1 AND NVL(i.an,t.an) = &apos;||vAnLucru||&apos; AND NVL(i.luna,t.luna) = &apos;||vLunaLucru||&apos; /*&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;COALESCE(i.subunitatea, t.subunitatea)&apos;)||&apos;*/
    GROUP BY ns.codnirstoc ),
  nsnv AS (
    SELECT ns.codnirstoc, SUM(ns.cantnir) cantint
    FROM nirstoc ns
    INNER JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN intrari i ON i.codintr = n.codintr
    LEFT JOIN transf t ON t.codtransf = n.codtransf
    LEFT JOIN INTRARI1 I1 ON NS.CODINTR1 = I1.CODINTR1 AND I1.CODINTR = I.CODINTR
    WHERE NVL(N.OPERAT,0) = 1 AND NOT N.TIPNIR IN (&apos;||vTipDoc||&apos;) AND NVL(i.an,t.an) = &apos;||vAnLucru||&apos; AND NVL(i.luna,t.luna) = &apos;||vLunaLucru||&apos; /*&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;COALESCE(i.subunitatea, t.subunitatea)&apos;)||&apos;*/
    GROUP BY ns.codnirstoc ),  
  nsl AS (
    SELECT
      l1.codnirstoc,
      SUM(CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE CASE WHEN l.codintr IS NULL THEN 0 ELSE - l1.cant END END) cantint,
      SUM(CASE when l.tiplivr = 15 then 0 else case WHEN l.codintr IS NULL THEN l1.cant ELSE 0 end end) canties,
      SUM(CASE when l.tiplivr = 15 then 0 else case WHEN l.codintr IS NULL THEN l1.cant * NVL(i1.pu,t1.pu) ELSE 0 END end) valies,
      SUM((1-NVL(I1.COEFDISCMAJ,1))*L1.CANT*NVL(I1.PRETORIG,0)) DISC
    FROM livr1 l1
      INNER JOIN livr l ON l.codlivr = l1.codlivr
      LEFT JOIN iesiri i ON i.codies = l.codies
      LEFT JOIN iesiri1 i1 ON i1.codies = l.codies AND i1.codies1 = l1.codies1
      LEFT JOIN transf t ON t.codtransf = l.codtransf
      LEFT JOIN transf1 t1 ON t1.codtransf = l.codtransf AND t1.codtransf1 = l1.codies1
      LEFT JOIN intrari o ON o.codintr = l.codintr
    WHERE NVL(i.an,NVL(t.an,o.an)) = &apos;||vAnLucru||&apos; AND NVL(i.luna,NVL(t.luna,o.luna)) = &apos;||vLunaLucru||vWhere1||&apos; /*&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;COALESCE(i.subunitatea,t.subunitatea,o.subunitatea)&apos;)||&apos;*/
    GROUP BY l1.codnirstoc ),
  nslv AS (
    SELECT
      l1.codnirstoc,
      SUM(CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE CASE WHEN l.codintr IS NULL THEN 0 ELSE - l1.cant END END) cantint,
      SUM(CASE when l.tiplivr = 15 then 0 else case WHEN l.codintr IS NULL THEN l1.cant ELSE 0 end end) canties,
      SUM(CASE when l.tiplivr = 15 then 0 else case WHEN l.codintr IS NULL THEN l1.cant * NVL(i1.pu,t1.pu) ELSE 0 END end) valies,
      SUM((1-NVL(I1.COEFDISCMAJ,1))*L1.CANT*NVL(I1.PRETORIG,0)) DISC
    FROM livr1 l1
      INNER JOIN livr l ON l.codlivr = l1.codlivr
      LEFT JOIN iesiri i ON i.codies = l.codies
      LEFT JOIN iesiri1 i1 ON i1.codies = l.codies AND i1.codies1 = l1.codies1
      LEFT JOIN transf t ON t.codtransf = l.codtransf
      LEFT JOIN transf1 t1 ON t1.codtransf = l.codtransf AND t1.codtransf1 = l1.codies1
      LEFT JOIN intrari o ON o.codintr = l.codintr
    WHERE NOT L.TIPLIVR IN (&apos;||vTipDoc||&apos;) AND NVL(i.an,NVL(t.an,o.an)) = &apos;||vAnLucru||&apos; AND NVL(i.luna,NVL(t.luna,o.luna)) = &apos;||vLunaLucru||&apos; /*&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;COALESCE(i.subunitatea,t.subunitatea,o.subunitatea)&apos;)||&apos;*/
    GROUP BY l1.codnirstoc ),  
  si AS (
    SELECT nl.codnirstoc, sum(nl.rest) as stocini, sum(nl.rest*nvl(ns.pret,0)) as valstocini
    FROM nirluna nl
         INNER JOIN NIRSTOC NS ON NL.CODNIRSTOC = NS.CODNIRSTOC
         INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
         INNER JOIN NGEST G ON G.CODGEST = N.GEST 
    WHERE nl.an = &apos;||vAnPreced||&apos; and nl.luna = &apos;||vLunaPreced||&apos; /*&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;G.CODSUBUNIT&apos;)||&apos;*/
    GROUP BY nl.codnirstoc ),
  bals as (
    SELECT
      ns.codobiect, sum(nvl(si.stocini,0)) StocIni, sum(nvl(nsn.cantint,0)+nvl(nsl.cantint,0)) TotInt,
      sum(nvl(nsl.canties,0)) Ies, sum((nvl(nsnv.cantint,0)+nvl(nsl.cantint,0))*ns.pret) ValCInt,
      sum(nvl(nslv.canties,0)*ns.pret) ValCIes, sum(nvl(nslv.valies,0)) ValVIes,
      sum(nvl(si.stocini,0)) + sum(nvl(nsn.cantint,0)) + sum(nvl(nsl.cantint,0)) - sum(nvl(nsl.canties,0)) as Stoc, sum(nvl(si.stocini,0) * ns.pret + nvl(nsn.cantint,0) * ns.pret  + nvl(nsl.cantint,0) * ns.pret - nvl(nsl.canties,0) * ns.pret) ValCStoc, G.DEN_GEST, sum(nvl(ns.rest,0) * NVL(ns.ADAOS,0)) ADAOS,
      SUM(NSN.DISC) DISCPRIM, SUM(NSL.DISC) DISCAC, sum(nvl(si.valstocini,0)) ValStocIni
    FROM nirstoc ns
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN NGEST G ON N.GEST = G.CODGEST
      LEFT JOIN nsn on nsn.codnirstoc = ns.codnirstoc
      LEFT JOIN nsnv on nsnv.codnirstoc = ns.codnirstoc
      LEFT JOIN nsl on nsl.codnirstoc = ns.codnirstoc
      LEFT JOIN nslv on nslv.codnirstoc = ns.codnirstoc
      LEFT JOIN si on si.codnirstoc = ns.codnirstoc
      LEFT JOIN INTRARI INTR ON N.CODINTR = INTR.CODINTR
      LEFT JOIN IESIRI I ON I.CODIES = N.CODIES
      LEFT JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
    WHERE NVL(N.OPERAT,0) = 1 &apos;||vWhere||&apos; 
    GROUP BY ns.codobiect, G.DEN_GEST)
  SELECT
    nao.denumire, num.den_um, s.StocIni, s.valstocini, s.TotInt, s.ValCInt, 
    case 
      when nvl(s.totint,0) = 0 then  
        case
          when s.stocini &lt;&gt; 0 then s.valstocini/s.stocini
          else 0  
        end
      else s.ValCInt/s.TotInt 
    end PMInt,
    s.Ies, s.ValCIes, s.ValVIes, s.Stoc, s.ValCStoc, (s.Stoc * nvl(p.lei,0)) ValVStoc, S.DEN_GEST, S.ADAOS,
    S.DISCPRIM, S.DISCAC &apos;|| coalesce(sSelectDC,&apos;&apos;) ||gUserAlias||&apos;
  FROM BALS S
    INNER JOIN nartobj nao ON nao.codobiect = s.codobiect
    INNER JOIN nart na ON na.codarticol = nao.codarticol
    INNER JOIN num num ON num.codum = na.um
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = NA.CLASA
    LEFT JOIN pretm p ON nao.codobiect = p.codobiect AND nvl(p.implicit,0) = 1 and p.subunitatea = 2 &apos;||
    COALESCE(sJoinDC, &apos;&apos;) || gSuplJoins;
  if pkg_list_selectioart.Extra then
    sInsert := sInsert||&apos; WHERE nvl(s.TotInt,0) &lt;&gt; 0 or nvl(s.ies,0) &lt;&gt; 0 or nvl(s.StocIni,0) &lt;&gt; 0 &apos;;
  else
    sInsert := sInsert||&apos; WHERE nvl(s.TotInt,0) &lt;&gt; 0 or nvl(s.ies,0) &lt;&gt; 0&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_BALSTOC1; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOCPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81D83D50D758CFEB4D5B0F02AD44BC3F13BBC4BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSTOCPART IS

  gUserFields VARCHAR2(3000);
  gUserAlias  VARCHAR2(3000);
  gNullAlias  VARCHAR2(3000);
  gSuplCols   VARCHAR2(3000);
  gSuplJoins  VARCHAR2(5000);

  -- si -&gt; stoc initial; ci - cant.intr; ce - cant.ies; ti -&gt; cant.intr.transfer; ir - cant.intr.retur; ie - intrari pe doc de iesire

FUNCTION CondFurn( vCamp IN VARCHAR2 ) RETURN VARCHAR2 IS
  sCond VARCHAR2(300) := &apos;&apos;;
BEGIN
  IF NOT PKG_LIST_SELECTPERIOADA.AllX THEN
    sCond :=&apos;
      AND &apos;||vCamp||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  RETURN sCond;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       CLOB;
  sInsertAux    CLOB;
  sInsertTmpS   CLOB;
  sCurata       CLOB;
  sUpdate       CLOB;
  sGolesteTMP   CLOB           := &apos;TRUNCATE TABLE tmp_lst_balsf&apos;;
  vAn           NUMBER;
  vLuna         NUMBER;
  vCondAnLuna   VARCHAR2(  300);
  bDupaData     BOOLEAN        := PKG_LIST_SELECTPERIOADA.DupaData;
  vAnLunaIni    NUMBER         := PKG_LIST_SELECTPERIOADA.AnLunaIni;
  vAnLunaFin    NUMBER         := PKG_LIST_SELECTPERIOADA.AnLunaFin;
  vAnLunaPrec   NUMBER;
  vDataIni      DATE           := PKG_LIST_SELECTPERIOADA.DataIni;
  vDataFin      DATE           := PKG_LIST_SELECTPERIOADA.DataFin;
  sDataIni      VARCHAR2(  100);
  sDataFin      VARCHAR2(  100);
  bSerii        BOOLEAN        := PKG_LIST_SELECTPERIOADA.optiunea1;
  sSerTG        VARCHAR2( 1000);
  sJoinSerNL    VARCHAR2( 1000);
  sJoinSerN     VARCHAR2( 1000);
  sJoinSerL     VARCHAR2( 1000);
  sSI           VARCHAR2( 1000);
  sNSCantNIR    VARCHAR2( 1000);
  sNSCantUM1    VARCHAR2( 1000);
  sNSCantUM2    VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;tmp_lst_balsf s, npart furn, ngest gprod, nartobj o, ngest g, pretm pm, nart a, num1 u, num up, num u1, num u2, ioart io, ncont c, npers pg, nlocatii l,&apos;||
               &apos;nsubunit sub, npart prod, nclasea ca, nclaseas cas, nartamb aa, ncarsupart csa, nagenda sgest, nlocalit lgest, njudet jgest, centrecost cc&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,  &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,  &apos;OATR&apos;,  &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,     &apos;CERTC&apos;, &apos;CERT.CODCERTIF = S.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIF&apos;,      &apos;CERT&apos;,  &apos;CERT.CODCERTIF = S.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJTRAD&apos;, &apos;TRAD&apos;,  &apos;TRAD.CODOBIECT = O.CODOBIECT AND TRAD.CODLIMBA = &apos;||Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;LIMBADENART&apos;,PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU),0) );

  pkg_list_struct.GetSuplCols(aLISTID,aLISTVER,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF bDupaData THEN
    IF Trunc(vDataIni,&apos;MM&apos;) = Trunc(vDataFin,&apos;MM&apos;)
    THEN vCondAnLuna := &apos;= &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;));
    ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;))||&apos; AND &apos;||To_Char(To_Char(vDataFin,&apos;yyyy&apos;)*12+To_Char(vDataFin,&apos;mm&apos;));
    END IF;

    vAnLunaIni  := EXTRACT(YEAR  FROM vDataIni) * 12 + EXTRACT(MONTH FROM vDataIni);
    vAnLunaFin  := EXTRACT(YEAR  FROM vDataFin) * 12 + EXTRACT(MONTH FROM vDataFin);
  ELSE
    IF vAnLunaIni = vAnLunaFin
    THEN vCondAnLuna := &apos;= &apos;||To_Char(vAnLunaIni);
    ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(vAnLunaIni)||&apos; AND &apos;||To_Char(vAnLunaFin);
    END IF;

    PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaIni, vAn, vLuna);
    vDataIni := To_Date( To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;YYYYMM&apos;);
    PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaFin, vAn, vLuna);
    vDataFin := Last_Day(To_Date( To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;YYYYMM&apos;));
  END IF;
  vAnLunaPrec := vAnLunaIni - 1;

  sDataIni := &apos;To_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin := &apos;To_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;


  IF bSerii THEN
    sJoinSerNL := &apos;
      LEFT JOIN nirserluna nserl ON nserl.codnirstoc = ns.codnirstoc AND nserl.an * 12 + nserl.luna = &apos;||vAnLunaPrec||&apos;
      LEFT JOIN nirser     nser  ON nser.codnirser   = nserl.codnirser
      LEFT JOIN nserii     ser   on ser.codserie     = nser.codserie&apos;;
    sJoinSerN := &apos;
      LEFT JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
      LEFT JOIN nserii ser  on ser.codserie    = nser.codserie&apos;;
    sJoinSerL :=&apos;
      LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
      LEFT JOIN nserii ser  on ser.codserie   = nser.codserie&apos;;
    sSerTG := &apos;,
      ser.serie, nser.obs serobs, Coalesce(nser.tg, ns.tg) tg, nser.codcertif&apos;;
    sSi := &apos;,
      Coalesce(NSERL.REST,NL.REST) SI, Coalesce(NSERL.RESTUM1,NL.RESTUM1) SI1, Coalesce(NSERL.RESTUM2,NL.RESTUM2) SI2&apos;;
    sNSCantNIR :=&apos;Coalesce(NSER.CANTNIR,NS.CANTNIR)&apos;;
    sNSCantUM1 :=&apos;Coalesce(NSER.CANTUM1,NS.CANTUM1)&apos;;
    sNSCantUM2 :=&apos;Coalesce(NSER.CANTUM2,NS.CANTUM2)&apos;;
  ELSE
    sSerTG := &apos;,
      NULL SERIE, NULL SerObs, NS.TG, NULL CODCERTIF&apos;;
  sSi := &apos;,
      NL.REST SI, NL.RESTUM1 SI1, NL.RESTUM2 SI2&apos;;
    sNSCantNIR :=&apos;NS.CANTNIR&apos;;
    sNSCantUM1 :=&apos;NS.CANTUM1&apos;;
    sNSCantUM2 :=&apos;NS.CANTUM2&apos;;
  END IF;

  sInsertTmpS :=
  &apos;INSERT INTO tmp_lst_balsf (
    FURN, CODGESTPROD,
    GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, CODCENTRU,
    SI,  CI,  CP,  CE,  CC,  CT,
    SI1, CI1, CP1, CE1, CC1, CT1,
    SI2, CI2, CP2, CE2, CC2, CT2,
    SoldI, VI, VP, VE, VC, VT,
    CantIntrAS,    CantIntrT,
    CantIntrASUM1, CantIntrTUM1,
    CantIntrASUM2, CantIntrTUM2,
    ValIntrAS,     ValIntrT,
    CantIesAS,     CantIesT,
    CantIesASUM1,  CantIesTUM1,
    CantIesASUM2,  CantIesTUM2,
    ValIesAS,      ValIesT,
    CantDimin,     CantMariri,
    CantDiminUM1,  CantMaririUM1,
    CantDiminUM2,  CantMaririUM2,
    ValDimin,      ValMariri,
    ValVanzari,
    DataStart, DataStop,
    Valoric,
    CantIntrMP,
    CantIntrMPUM1,
    CantIntrMPUM2,
    ValIntrMP,
    CantIesMP,
    CantIesMPUM1,
    CantIesMPUM2,
    ValIesMP
    )
  WITH 
  B AS (
    -- Initial
    SELECT
      0 TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, 0 CODCENTRU&apos;||sSerTG||
      sSi||&apos;,
      0 CI, 0 CI1, 0 CI2,
      0 CP, 0 CP1, 0 CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM nirluna nl
      INNER JOIN nirstoc ns  ON ns.codnirstoc = nl.codnirstoc
      INNER JOIN nir     n   ON n.codnir  = ns.codnir
      INNER JOIN ngest   g   ON g.codgest = n.gest
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerNL||&apos;
    WHERE nl.an *12 + nl.luna = &apos;||vAnLunaPrec||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- NIR Intrari
    SELECT
      N.TIPNIR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, Coalesce(I1.CODCENTRU,0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTNIR||&apos; ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM1||&apos; ELSE 0 END SI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM2||&apos; ELSE 0 END SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END * DECODE(N.TIPNIR,7,0,1) CI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM1||&apos; END * DECODE(N.TIPNIR,7,0,1) CI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM2||&apos; END * DECODE(N.TIPNIR,7,0,1) CI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END * DECODE(N.TIPNIR,7,1,0) CP,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM1||&apos; END * DECODE(N.TIPNIR,7,1,0) CP1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM2||&apos; END * DECODE(N.TIPNIR,7,1,0) CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM NIRSTOC NS
      INNER JOIN NIR     N   ON N.CODNIR  = NS.CODNIR
      INNER JOIN INTRARI I   ON I.CODINTR = N.CODINTR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerN||&apos;
      LEFT JOIN INTRARI1 I1  ON I1.CODINTR1 = NS.CODINTR1
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- NIR-uri din MISCARI INTERNE
    SELECT
      N.TIPNIR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(T1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTNIR||&apos; ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM1||&apos; ELSE 0 END SI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN &apos;||sNSCANTUM2||&apos; ELSE 0 END SI2,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTNIR||&apos; END CI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM1||&apos; END CI1,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE &apos;||sNSCANTUM2||&apos; END CI2,
      0 CP, 0 CP1, 0 CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM NIRSTOC NS
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN TRANSF  T   ON T.CODTRANSF = N.CODTRANSF
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerN||&apos;
      LEFT JOIN TRANSF1  T1  ON T1.CODTRANSF1 = NS.CODTRANSF1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1 = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(N.DATANIR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- RETURURI
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT ELSE 0    END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END * DECODE(L.TIPLIVR,7,0,1) CI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM1 END * DECODE(L.TIPLIVR,7,0,1) CI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM2 END * DECODE(L.TIPLIVR,7,0,1) CI2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END * DECODE(L.TIPLIVR,7,1,0) CP,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM1 END * DECODE(L.TIPLIVR,7,1,0) CP1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM2 END * DECODE(L.TIPLIVR,7,1,0) CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
      INNER JOIN INTRARI I   ON I.CODINTR = L.CODINTR
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerL||&apos;
      LEFT JOIN INTRARI1 I1  ON I1.CODINTR1 = L1.CODINTR1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1 = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- IESIRI
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT    ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      0 CI, 0 CI1, 0 CI2,
      0 CP, 0 CP1, 0 CP2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,14,0,24,0,1) CE,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END * DECODE(L.TIPLIVR,14,0,24,0,1) CE1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END * DECODE(L.TIPLIVR,14,0,24,0,1) CE2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,24,1,0) CC,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END * DECODE(L.TIPLIVR,24,1,0) CC1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END * DECODE(L.TIPLIVR,24,1,0) CC2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,14,1,0) CT,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END * DECODE(L.TIPLIVR,14,1,0) CT1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END * DECODE(L.TIPLIVR,14,1,0) CT2,
      CASE
        WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0
        WHEN I1.CANT = 0 THEN 0
        WHEN I1.PU   = 0 THEN 0
        WHEN I.TIPDOC IN (19, 20) THEN I1.PRETORIG * I1.COEFDISCMAJ
        WHEN I.TIPDOC = 21 THEN (I1.PU-I1.TVA/I1.CANT)*I1.PRETORIG*I1.COEFDISCMAJ/I1.PU
        WHEN I.TIPDOC = 16 THEN
          case 
            WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
            else PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, coalesce(i1.contserv,0), -1, 1)
          end * (i1.pu - Decode(i1.cant,0,0,Coalesce(i1.tva,0)/i1.cant))    
        ELSE 0
      END PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
      INNER JOIN IESIRI  I   ON I.CODIES = L.CODIES AND I.TIPDOC = L.TIPLIVR
      INNER JOIN IESIRI1 I1  ON I1.CODIES1 = L1.CODIES1 AND I1.CODIES = I.CODIES
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerL||&apos;
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1 = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- MISCARI INTERNE
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(T1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT    ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANTUM2 ELSE 0 END SI2,
      0 CI, 0 CI1, 0 CI2,
      0 CP, 0 CP1, 0 CP2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END CE,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM1 END CE1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANTUM2 END CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
      INNER JOIN TRANSF  T   ON T.CODTRANSF = L.CODTRANSF
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerL||&apos;
      LEFT JOIN TRANSF1  T1  ON T1.CODTRANSF1  = L1.CODINTR1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1 = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- MARIRI DE STOC
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU&apos;||sSerTG||&apos;,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANT    ELSE 0 END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM1 ELSE 0 END SI1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANTUM2 ELSE 0 END SI2,
      0 CI, 0 CI1, 0 CI2,
      0 CP, 0 CP1, 0 CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END CT,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM1 END CT1,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANTUM2 END CT2,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
      INNER JOIN IESIRI  I   ON I.CODIES  = L.CODIES
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 &apos;||
      sJoinSerL||&apos;
      LEFT JOIN IESIRI1  I1  ON I1.CODIES1 = L1.CODIES1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1 = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND trunc(L.DATALIVR) &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
  )
  SELECT
    FURN, CODGESTPROD,
    GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, CODCENTRU,
    SUM(SI)  SI,  SUM(CI)  CI,  SUM(CP)  CP,  SUM(CE)  CE,  SUM(CC)  CC,  SUM(CT)  CT,
    SUM(SI1) SI1, SUM(CI1) CI1, SUM(CP1) CP1, SUM(CE1) CE1, SUM(CC1) CC1, SUM(CT1) CT1,
    SUM(SI2) SI2, SUM(CI2) CI2, SUM(CP2) CP2, SUM(CE2) CE2, SUM(CC2) CC2, SUM(CT2) CT2,
    SUM(SI*PRET) SoldI, SUM(CI*PRET) VI, SUM(CP*PRET) VP, SUM(CE*PRET) VE, SUM(CC*PRET) VC, SUM(CT*PRET) VT,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI      ELSE 0 END) CantIntrAS,    SUM(CASE WHEN B.TIPDOC = 12 THEN CI      ELSE 0 END) CantIntrT,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI1     ELSE 0 END) CantIntrASUM1, SUM(CASE WHEN B.TIPDOC = 12 THEN CI1     ELSE 0 END) CantIntrTUM1,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI2     ELSE 0 END) CantIntrASUM2, SUM(CASE WHEN B.TIPDOC = 12 THEN CI2     ELSE 0 END) CantIntrTUM2,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI*PRET ELSE 0 END) ValIntrAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CI*PRET ELSE 0 END) ValIntrT,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE      ELSE 0 END) CantIesAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CE      ELSE 0 END) CantIesT,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE1     ELSE 0 END) CantIesASUM1,  SUM(CASE WHEN B.TIPDOC = 12 THEN CE1     ELSE 0 END) CantIesTUM1,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE2     ELSE 0 END) CantIesASUM2,  SUM(CASE WHEN B.TIPDOC = 12 THEN CE2     ELSE 0 END) CantIesTUM2,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE*PRET ELSE 0 END) ValIesAS,      SUM(CASE WHEN B.TIPDOC = 12 THEN CE*PRET ELSE 0 END) ValIesT,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT      ELSE 0 END) CantDimin,     SUM(CASE WHEN B.TIPDOC = 15 THEN CT      ELSE 0 END) CantMariri,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT1     ELSE 0 END) CantDiminUM1,  SUM(CASE WHEN B.TIPDOC = 15 THEN CT1     ELSE 0 END) CantMaririUM1,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT2     ELSE 0 END) CantDiminUM2,  SUM(CASE WHEN B.TIPDOC = 15 THEN CT2     ELSE 0 END) CantMaririUM2,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT*PRET ELSE 0 END) ValDimin,      SUM(CASE WHEN B.TIPDOC = 15 THEN CT*PRET ELSE 0 END) ValMariri,
    SUM(CE * PretV) ValVanzari,
    to_date(&apos;&apos;&apos;||to_char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStart, to_date(&apos;&apos;&apos;||to_char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStop,
    0 Valoric,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CI      ELSE 0 END) CantIntrMP,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CI1     ELSE 0 END) CantIntrMPUM1,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CI2     ELSE 0 END) CantIntrMPUM2,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CI*PRET ELSE 0 END) ValIntrMP,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CE      ELSE 0 END) CantIesMP,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CE1     ELSE 0 END) CantIesMPUM1,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CE2     ELSE 0 END) CantIesMPUM2,
    SUM(CASE WHEN B.TIPDOC = 13 THEN CE*PRET ELSE 0 END) ValIesMP
  FROM b
  GROUP BY furn, codgestprod, gest, codlocatie, codobiect, codioart, cont, mg, serie, serobs, tg, codcertif, codcentru&apos;;

  sCurata :=
  &apos;DELETE tmp_lst_balsf
  WHERE Coalesce(si, 0) = 0 AND Coalesce(ci, 0) = 0 AND Coalesce(cp, 0) = 0 AND Coalesce(ce, 0) = 0 AND Coalesce(cc, 0) = 0 AND (Coalesce(ct, 0) = 0)
    AND Coalesce(si1,0) = 0 AND Coalesce(ci1,0) = 0 AND Coalesce(cp1,0) = 0 AND Coalesce(ce1,0) = 0 AND Coalesce(cc1,0) = 0 AND (Coalesce(ct1,0) = 0)
    AND Coalesce(si2,0) = 0 AND Coalesce(ci2,0) = 0 AND Coalesce(cp2,0) = 0 AND Coalesce(ce2,0) = 0 AND Coalesce(cc2,0) = 0 AND (Coalesce(ct2,0) = 0)
    AND Coalesce(CantIntrAS,0) = 0 AND Coalesce(CantIntrT,0) = 0 AND Coalesce(CantIesAS,0) = 0 AND Coalesce(CantIesT,0) = 0
    AND Coalesce(CantDimin,0) = 0 AND Coalesce(CantMariri,0) = 0&apos;;

  sUpdate :=
  &apos;UPDATE tmp_lst_balsf
  SET sf    = si   +ci +cp -ce -cc -ct,
      sf1   = si1  +ci1+cp1-ce1-cc1-ct1,
      sf2   = si2  +ci2+cp2-ce2-cc2-ct2,
      soldf = soldi+vi +vp -ve -vc -vt&apos;;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    X_Judet, X_CodGest, X_Codsubunit, CodObiect, DenArt,
    DenFurn,
    TipFurn,
    DenGest, DenLGest, DenSub, DenCont,
    DenUM, DenUM1, DenUM2,
    CodExt, CodInt, Prod,
    StocInit,    CantIntr,    CantProd,    CantIes,    CantCons,    CantTr,    StocFinal,
    StocInitUM1, CantIntrUM1, CantProdUM1, CantIesUM1, CantConsUM1, CantTrUM1, StocFinUM1,
    StocInitUM2, CantIntrUM2, CantProdUM2, CantIesUM2, CantConsUM2, CantTrUM2, StocFinUM2,
    SoldInit,    ValIntr,     ValProd,     ValIes,     ValCons,     ValTr,     SoldFinal,
    CantIntrAS,    CantIntrT,    CantIesAS,    CantIesT,    CantDimin,    CantMariri,
    CantIntrASUM1, CantIntrTUM1, CantIesASUM1, CantIesTUM1, CantDiminUM1, CantMaririUM1,
    CantIntrASUM2, CantIntrTUM2, CantIesASUM2, CantIesTUM2, CantDiminUM2, CantMaririUM2,
    ValIntrAS,     ValIntrT,     ValIesAS,     ValIesT,     ValDimin,     ValMariri,
    MG,
    UMTRANSF,
    COEFTRANSF,
    SERIE, SEROBS, TG, CentruCost,
    CantIntrMP,
    CantIntrMPUM1,
    CantIntrMPUM2,
    ValIntrMP,
    CantIesMP,
    CantIesMPUM1,
    CantIesMPUM2,
    ValIesMP &apos;||
    gUserFields||&apos;)
  SELECT
    jgest.Simbauto, g.codgest, sub.codsubunit, s.codobiect, CASE WHEN valoric = 0 THEN o.denumire ELSE &apos;&apos;Tranzactii valorice&apos;&apos; END DenArt,
    CASE WHEN s.codgestprod &gt; 0 THEN gprod.den_gest ELSE furn.den_part END DenFurn,
    CASE WHEN s.codgestprod &gt; 0 THEN &apos;&apos;GESTIUNE PRODUCATOARE&apos;&apos; ELSE &apos;&apos;FURNIZOR&apos;&apos; END TipFurn,
    g.den_gest, l.denumire, sub.den_subunit, c.simbol,
    CASE WHEN valoric = 0 THEN u.den_um1 ELSE &apos;&apos;LEI&apos;&apos; END DenUM, CASE WHEN valoric = 0 THEN u1.den_um END DenUM1, CASE WHEN valoric = 0 THEN u2.den_um END DenUM2,
    o.codextern, o.codintern, prod.den_part,
    s.si,    s.ci,  s.cp,  s.ce,  s.cc,  s.ct,  s.sf    StocFinal,
    s.si1,   s.ci1, s.cp1, s.ce1, s.cc1, s.ct1, s.sf1   StocFinUM1,
    s.si2,   s.ci2, s.cp2, s.ce2, s.cc2, s.ct2, s.sf2   StocFinUM2,
    s.SoldI, s.vi,  s.vp,  s.ve,  s.vc,  s.vt,  s.soldf SoldFinal,
    s.CantIntrAS,    s.CantIntrT,    s.CantIesAS,    s.CantIesT,    s.CantDimin,    s.CantMariri,
    s.CantIntrASUM1, s.CantIntrTUM1, s.CantIesASUM1, s.CantIesTUM1, s.CantDiminUM1, s.CantMaririUM1,
    s.CantIntrASUM2, s.CantIntrTUM2, s.CantIesASUM2, s.CantIesTUM2, s.CantDiminUM2, s.CantMaririUM2,
    s.ValIntrAS,     s.ValIntrT,     s.ValIesAS,     s.ValIesT,     s.ValDimin,     s.ValMariri,
    CASE s.mg WHEN 1 THEN &apos;&apos;FIFO&apos;&apos; WHEN 2 THEN &apos;&apos;LIFO&apos;&apos; WHEN 3 THEN &apos;&apos;PMP&apos;&apos; WHEN 4 THEN &apos;&apos;IDS&apos;&apos; WHEN 5 THEN &apos;&apos;VAL&apos;&apos;END MG,
    CASE WHEN valoric = 1 THEN NULL WHEN up.tipum=1 THEN &apos;&apos;Kg&apos;&apos; WHEN up.tipum=2 THEN &apos;&apos;Cm3&apos;&apos; WHEN up.tipum=3 THEN &apos;&apos;M2&apos;&apos; WHEN up.tipum=4 THEN &apos;&apos;M&apos;&apos; WHEN up.tipum=5 THEN &apos;&apos;Buc&apos;&apos; END UMTRANSF,
    CASE WHEN valoric = 1 THEN 1 ELSE up.coef END COEFTRANSF,
    s.Serie, s.SerObs, s.TG, cc.Denumire,
    s.CantIntrMP,
    s.CantIntrMPUM1,
    s.CantIntrMPUM2,
    s.ValIntrMP,
    s.CantIesMP,
    s.CantIesMPUM1,
    s.CantIesMPUM2,
    s.ValIesMP &apos;||
    gUserAlias||&apos;
  FROM tmp_lst_balsf s
    LEFT JOIN npart      furn  ON furn.codpart  = coalesce(s.furn,0)
    LEFT JOIN ngest      gprod ON gprod.codgest = s.codgestprod
    LEFT JOIN nartobj    o     ON o.codobiect   = s.codobiect
    LEFT JOIN ngest      g     ON g.codgest     = s.gest
    LEFT JOIN pretm      pm    on o.codobiect   = pm.codobiect and pm.subunitatea = g.codsubunit and pm.implicit = 1
    LEFT JOIN nart       a     ON a.codarticol  = o.codarticol
    LEFT JOIN num1       u     ON u.codum  = a.um AND u.secundara = 0
    LEFT JOIN num        up    on up.codum = a.um
    LEFT JOIN num        u1    ON u1.codum = a.um1
    LEFT JOIN num        u2    ON u2.codum = a.um2
    LEFT JOIN ioart      io    ON io.codioart  = s.codioart
    LEFT JOIN ncont      c     ON c.codcont    = s.cont
    LEFT JOIN npers      pg    ON pg.codpers   = g.codgestionar
    LEFT JOIN nlocatii   l     ON l.codlocatie = s.codlocatie
    LEFT JOIN nsubunit   sub   ON sub.codsubunit = g.codsubunit
    LEFT JOIN npart      prod  ON prod.codpart   = o.codproducator
    LEFT JOIN nclasea    ca    ON ca.codclasea   = a.clasa
    LEFT JOIN nclaseas   cas   ON cas.codclaseas = a.clasastatist
    LEFT JOIN nartamb    aa    ON aa.codobiect   = s.codobiect AND aa.umsec = u.codum1
    LEFT JOIN ncarsupart csa   ON csa.codcarsupart = o.codcaract
    LEFT JOIN nagenda    sgest ON sgest.codgest    = g.codgest
    LEFT JOIN nlocalit   lgest ON lgest.codlocalit = sgest.codlocalit
    LEFT JOIN njudet     jgest ON jgest.codjudet   = lgest.codjudet
    LEFT JOIN centrecost cc    ON cc.codcentru     = s.codcentru&apos;||
    gSuplJoins;

  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  LIST_EXECUTE_IMMEDIATE(sGolesteTMP, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsertTmpS, aListID, aListVer);
  if not PKG_LIST_SELECTPERIOADA.optiunea2 then
    LIST_EXECUTE_IMMEDIATE(sCurata    , aListID, aListVer);
  end if;
  LIST_EXECUTE_IMMEDIATE(sUpdate    , aListID, aListVer);

  if PKG_LIST_SELECTPERIOADA.optiunea2 then
    sInsertAux :=
    &apos;INSERT INTO tmp_lst_balsf (
      FURN, CODGESTPROD,
      GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, CODCERTIF, CODCENTRU,
      SI,  CI,  CP,  CE,  CC,  CT,
      SI1, CI1, CP1, CE1, CC1, CT1,
      SI2, CI2, CP2, CE2, CC2, CT2,
      SoldI, VI, VP, VE, VC, VT,
      CantIntrAS,    CantIntrT,
      CantIntrASUM1, CantIntrTUM1,
      CantIntrASUM2, CantIntrTUM2,
      ValIntrAS,     ValIntrT,
      CantIesAS,     CantIesT,
      CantIesASUM1,  CantIesTUM1,
      CantIesASUM2,  CantIesTUM2,
      ValIesAS,      ValIesT,
      CantDimin,     CantMariri,
      CantDiminUM1,  CantMaririUM1,
      CantDiminUM2,  CantMaririUM2,
      ValDimin,      ValMariri,
      ValVanzari, Valoric)
    select
      LF.LAST_FURN FURN, 0 CODGESTPROD,
      0 GEST, 0 CODLOCATIE, O.CODOBIECT, 0 CODIOART, 0 CONT, 0 CODCERTIF, 0 CODCENTRU,
      0 SI, 0 CI, 0 CP, 0 CE, 0 CC, 0 CT,
      0 SI1, 0 CI1, 0 CP1, 0 CE1, 0 CC1, 0 CT1,
      0 SI2, 0 CI2, 0 CP2, 0 CE2, 0 CC2, 0 CT2,
      0 SoldI, 0 VI, 0 VP, 0 VE, 0 VC, 0 VT,
      0 CantIntrAS,    0 CantIntrT,
      0 CantIntrASUM1, 0 CantIntrTUM1,
      0 CantIntrASUM2, 0 CantIntrTUM2,
      0 ValIntrAS,     0 ValIntrT,
      0 CantIesAS,     0 CantIesT,
      0 CantIesASUM1,  0 CantIesTUM1,
      0 CantIesASUM2,  0 CantIesTUM2,
      0 ValIesAS,      0 ValIesT,
      0 CantDimin,     0 CantMariri,
      0 CantDiminUM1,  0 CantMaririUM1,
      0 CantDiminUM2,  0 CantMaririUM2,
      0 ValDimin,      0 ValMariri,
      0 ValVanzari, 0 Valoric
    FROM NARTOBJ O
         INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
         LEFT JOIN
         (SELECT
            DISTINCT
            NS.CODOBIECT,
            LAST_VALUE(NS.FURN) IGNORE NULLS
            OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
                  UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_FURN,
            LAST_VALUE(N.DATANIR) IGNORE NULLS
            OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
                  UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_DATAACHIZ,
            LAST_VALUE(NS.PRET) IGNORE NULLS
            OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
                  UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_PRETACHIZ
          FROM NIR N
            INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
            INNER JOIN NGEST G ON G.CODGEST = N.GEST
            LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
            LEFT JOIN NPART P ON P.CODPART = I.PARTENER
          WHERE N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos; AND
          NOT EXISTS (SELECT T.CODOBIECT FROM tmp_lst_balsf T WHERE T.CODOBIECT = NS.CODOBIECT)
         ) LF ON LF.CODOBIECT = O.CODOBIECT
    WHERE COALESCE(O.INACTIV,0) = 0 AND A.TIPARTICOL IN (&apos;&apos;0&apos;&apos;, &apos;&apos;2&apos;&apos;) AND
          NOT EXISTS (SELECT T.CODOBIECT FROM tmp_lst_balsf T WHERE T.CODOBIECT = O.CODOBIECT) AND O.CODOBIECT &gt;= 100 &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsertAux,aListID,aListVer);
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert,aListID,aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

--  Umplerea TMP-ului cu partea valorica daca va fi cazul nu e actualizata
--  sInsertTmpS :=
--  &apos;INSERT INTO tmp_lst_balsf (
--    FURN, CODGESTPROD,
--    GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, CODCENTRU,
--    SI,  CI,  CP,  CE,  CC,  CT,
--    SI1, CI1, CP1, CE1, CC1, CT1,
--    SI2, CI2, CP2, CE2, CC2, CT2,
--    SoldI, VI, VP, VE, VC, VT,
--    CantIntrAS,    CantIntrT,
--    CantIntrASUM1, CantIntrTUM1,
--    CantIntrASUM2, CantIntrTUM2,
--    ValIntrAS,     ValIntrT,
--    CantIesAS,     CantIesT,
--    CantIesASUM1,  CantIesTUM1,
--    CantIesASUM2,  CantIesTUM2,
--    ValIesAS,      ValIesT,
--    CantDimin,     CantMariri,
--    CantDiminUM1,  CantMaririUM1,
--    CantDiminUM2,  CantMaririUM2,
--    ValDimin,      ValMariri,
--    DataStart, DataStop,
--    Valoric)
--  WITH
--  IOA AS (
--    SELECT codioart, cont, mg
--    FROM (
--      SELECT codioart, Max(cont) KEEP (Dense_Rank last ORDER BY ANSTART, LUNASTART) cont, Max(mg) KEEP (Dense_Rank last ORDER BY ANSTART, LUNASTART) mg
--      FROM ioart1
--      WHERE ANSTART * 12 + LUNASTART &lt;= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
--      GROUP BY codioart)
--    WHERE mg = 5 ),
--  B AS (
--    -- Initial
--    SELECT
--      0 TipDoc,
--      SVL.GEST, SVL.CODIOART, IOA.CONT, IOA.MG,
--      SVL.SOLD SI, 0 SI1, 0 SI2,
--      0 CI, 0 CI1, 0 CI2,
--      0 CE, 0 CE1, 0 CE2,
--      0 IR, 0 TI, 0 IE
--    FROM STOCVALLUNA SVL
--      INNER JOIN ngest g ON g.codgest = svl.gest
--      INNER JOIN ioa ON ioa.codioart = svl.codioart
--    WHERE svl.an *12 + svl.luna  = &apos;||vAnLunaPrec||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||&apos;
--    UNION ALL -- NIR Intrari
--    SELECT
--      N.TIPNIR TipDoc,
--      N.GEST, NS.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
--      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR * NS.PRET ELSE 0 END SI, 0 SI1, 0 SI2,
--      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR * NS.PRET END CI, 0 CI1, 0 CI2,
--      0 CE, 0 CE1, 0 CE2,
--      0 IR, 0 TI, 0 IE
--    FROM NIRSTOC NS
--      INNER JOIN IOA ON IOA.CODIOART = NS.CODIOART
--      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
--      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
--    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND N.DATANIR &lt;= &apos;||sDataFin||&apos;
--    UNION ALL -- NIR-uri din MISCARI INTERNE
--    SELECT
--      N.TIPNIR TipDoc,
--      N.GEST, NS.CODIOART, IOA.CONT, IOA.MG, T.AN, T.LUNA,
--      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR * NS.PRET ELSE 0 END SI, 0 SI1, 0 SI2,
--      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR * NS.PRET END CI, 0 CI1, 0 CI2,
--      0 CE, 0 CE1, 0 CE2,
--      0 IR, CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; OR N.TIPNIR &lt;&gt; 12 THEN 0 ELSE NS.CANTNIR * NS.PRET END TI, 0 IE
--    FROM NIRSTOC NS
--      INNER JOIN IOA ON IOA.CODIOART = NS.CODIOART
--      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
--      INNER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
--    WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
--      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND N.DATANIR &lt;= &apos;||sDataFin||&apos;
--    UNION ALL -- LIVRARI INTRARI
--    SELECT
--      L.TIPLIVR TipDoc,
--      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN - LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE - LV.PRETINREG * L1.CANT END CI, 0 CI1, 0 CI2,
--      0 CE, 0 CE1, 0 CE2,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE - LV.PRETINREG * L1.CANT END IR, 0 TI, 0 IE
--    FROM LIVRVAL LV
--      INNER JOIN IOA ON IOA.CODIOART = LV.CODIOART
--      INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
--      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
--      INNER JOIN INTRARI I ON I.CODINTR = L.CODINTR
--    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||&apos;
--    UNION ALL -- LIVRARI IESIRI
--    SELECT
--      L.TIPLIVR TipDoc,
--      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN - LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
--      0 CI, 0 CI1, 0 CI2,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CE, 0 CE1, 0 CE2,
--      0 IR, 0 TI, 0 IE
--    FROM LIVRVAL LV
--      INNER JOIN IOA ON IOA.CODIOART = LV.CODIOART
--      INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
--      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
--      INNER JOIN IESIRI I ON I.CODIES = L.CODIES AND I.TIPDOC = L.TIPLIVR
--      INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1 AND I1.CODIES = I.CODIES
--    WHERE L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||&apos;
--    UNION ALL -- LIVRARI MISCARI INTERNE
--    SELECT
--      L.TIPLIVR TipDoc,
--      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, T.AN, T.LUNA,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1, 0 SI2,
--      0 CI, 0 CI1, 0 CI2,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CE, 0 CE1, 0 CE2,
--      0 IR, 0 TI, 0 IE
--    FROM LIVRVAL LV
--      INNER JOIN IOA ON IOA.CODIOART = LV.CODIOART
--      INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
--      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
--      INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
--    WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
--      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||&apos;
--    UNION ALL -- MARIRI DE STOC
--    SELECT
--      L.TIPLIVR TipDoc,
--      LV.GEST, LV.CODIOART, IOA.CONT, IOA.MG, I.AN, I.LUNA,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN LV.PRETINREG * L1.CANT ELSE 0 END SI, 0 SI1,0 SI2,
--      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE LV.PRETINREG * L1.CANT END CI, 0 CI1, 0 CI2,
--      0 CE, 0 CE1, 0 CE2,
--      0 IR, 0 TI, 0 IE
--    FROM LIVRVAL LV
--      INNER JOIN IOA ON IOA.CODIOART = LV.CODIOART
--      INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
--      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
--      INNER JOIN IESIRI I ON I.CODIES = L.CODIES
--      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
--      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
--    WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||&apos;
--  )
--  SELECT
--    gest, 0 codlocatie, 0 codobiect, codioart, cont, mg, 1 pret, 0 adaos, 0 puval,
--    SUM(SI)  SI,  SUM(CI)  CI,  SUM(CE)  CE,
--    SUM(SI1) SI1, SUM(CI1) CI1, SUM(CE1) CE1,
--    SUM(SI2) SI2, SUM(CI2) CI2, SUM(CE2) CE2,
--    SUM(CASE WHEN B.TIPDOC =  6 THEN CI  ELSE 0 END) CantIntrAS,    SUM(CASE WHEN B.TIPDOC = 12 THEN CI  ELSE 0 END) CantIntrT,
--    SUM(CASE WHEN B.TIPDOC =  6 THEN CI1 ELSE 0 END) CantIntrASUM1, SUM(CASE WHEN B.TIPDOC = 12 THEN CI1 ELSE 0 END) CantIntrTUM1,
--    SUM(CASE WHEN B.TIPDOC =  6 THEN CI2 ELSE 0 END) CantIntrASUM2, SUM(CASE WHEN B.TIPDOC = 12 THEN CI2 ELSE 0 END) CantIntrTUM2,
--    SUM(CASE WHEN B.TIPDOC =  6 THEN CI  ELSE 0 END) ValIntrAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CI  ELSE 0 END) ValIntrT,
--    SUM(CASE WHEN B.TIPDOC = 23 THEN CE  ELSE 0 END) CantIesAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CE  ELSE 0 END) CantIesT,
--    SUM(CASE WHEN B.TIPDOC = 23 THEN CE1 ELSE 0 END) CantIesASUM1,  SUM(CASE WHEN B.TIPDOC = 12 THEN CE1 ELSE 0 END) CantIesTUM1,
--    SUM(CASE WHEN B.TIPDOC = 23 THEN CE2 ELSE 0 END) CantIesASUM2,  SUM(CASE WHEN B.TIPDOC = 12 THEN CE2 ELSE 0 END) CantIesTUM2,
--    SUM(CASE WHEN B.TIPDOC = 23 THEN CE  ELSE 0 END) ValIESAS,      SUM(CASE WHEN B.TIPDOC = 12 THEN CE  ELSE 0 END) ValIesT,
--    SUM(CASE WHEN B.TIPDOC = 14 THEN CT  ELSE 0 END) CantDimin,     SUM(CASE WHEN B.TIPDOC = 15 THEN CT  ELSE 0 END) CantMariri,
--    SUM(CASE WHEN B.TIPDOC = 14 THEN CT1 ELSE 0 END) CantDiminUM1,  SUM(CASE WHEN B.TIPDOC = 15 THEN CT1 ELSE 0 END) CantMaririUM1,
--    SUM(CASE WHEN B.TIPDOC = 14 THEN CT2 ELSE 0 END) CantDiminUM2,  SUM(CASE WHEN B.TIPDOC = 15 THEN CT2 ELSE 0 END) CantMaririUM2,
--    SUM(CASE WHEN B.TIPDOC = 14 THEN CT  ELSE 0 END) ValDimin,      SUM(CASE WHEN B.TIPDOC = 15 THEN CT  ELSE 0 END) ValMariri,
--    to_date(&apos;&apos;&apos;||to_char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStart, to_date(&apos;&apos;&apos;||to_char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStop,
--    1 Valoric
--  FROM b
--  GROUP BY gest, codioart, cont, mg&apos;;

END PKG_LIST_BASE_BALSTOCPART;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BALSTOCREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCB7FE21D49BE183771480B193C90B3B7B1AFFF8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BALSTOCREST IS

  gUserFields VARCHAR2(3000);
  gUserAlias  VARCHAR2(3000);
  gNullAlias  VARCHAR2(3000);
  gSuplCols   VARCHAR2(3000);
  gSuplJoins  VARCHAR2(5000);

  -- si -&gt; stoc initial; ci - cant.intr; ce - cant.ies; ti -&gt; cant.intr.transfer; ir - cant.intr.retur; ie - intrari pe doc de iesire

FUNCTION CondFurn( vCamp IN VARCHAR2 ) RETURN VARCHAR2 IS
  sCond VARCHAR2(300) := &apos;&apos;;
BEGIN
  IF NOT PKG_LIST_SELECTPERIOADA.AllX THEN
    sCond :=&apos;
      AND &apos;||vCamp||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  RETURN sCond;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       CLOB;
  sInsertTmpS   CLOB;
  sCurata       CLOB;
  sUpdate       CLOB;
  sGolesteTMP   CLOB           := &apos;TRUNCATE TABLE tmp_lst_balsf&apos;;
  vAn           NUMBER;
  vLuna         NUMBER;
  vCondAnLuna   VARCHAR2(  300);
  bDupaData     BOOLEAN        := PKG_LIST_SELECTPERIOADA.DupaData;
  vAnLunaIni    NUMBER         := PKG_LIST_SELECTPERIOADA.AnLunaIni;
  vAnLunaFin    NUMBER         := PKG_LIST_SELECTPERIOADA.AnLunaFin;
  vAnLunaPrec   NUMBER;
  vDataIni      DATE           := PKG_LIST_SELECTPERIOADA.DataIni;
  vDataFin      DATE           := PKG_LIST_SELECTPERIOADA.DataFin;
  sDataIni      VARCHAR2(  100);
  sDataFin      VARCHAR2(  100);
  bSerii        BOOLEAN        := PKG_LIST_SELECTPERIOADA.optiunea1;
BEGIN
  gSuplCols := &apos;tmp_lst_balsf s, npart furn, ngest gprod, nartobj o, ngest g, pretm pm, nart a, num1 u, num up, ioart io, ncont c, npers pg, nlocatii l,&apos;||
               &apos;nsubunit sub, npart prod, nclasea ca, nclaseas cas, nartamb aa, ncarsupart csa, nagenda sgest, nlocalit lgest, njudet jgest, centrecost cc&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,  &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,  &apos;OATR&apos;,  &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,aLISTVER,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF bDupaData THEN
    IF Trunc(vDataIni,&apos;MM&apos;) = Trunc(vDataFin,&apos;MM&apos;)
    THEN vCondAnLuna := &apos;= &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;));
    ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(To_Char(vDataIni,&apos;yyyy&apos;)*12+To_Char(vDataIni,&apos;mm&apos;))||&apos; AND &apos;||To_Char(To_Char(vDataFin,&apos;yyyy&apos;)*12+To_Char(vDataFin,&apos;mm&apos;));
    END IF;

    vAnLunaIni  := EXTRACT(YEAR  FROM vDataIni) * 12 + EXTRACT(MONTH FROM vDataIni);
    vAnLunaFin  := EXTRACT(YEAR  FROM vDataFin) * 12 + EXTRACT(MONTH FROM vDataFin);
  ELSE
    IF vAnLunaIni = vAnLunaFin
    THEN vCondAnLuna := &apos;= &apos;||To_Char(vAnLunaIni);
    ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(vAnLunaIni)||&apos; AND &apos;||To_Char(vAnLunaFin);
    END IF;

    PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaIni, vAn, vLuna);
    vDataIni := To_Date( To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;YYYYMM&apos;);
    PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaFin, vAn, vLuna);
    vDataFin := Last_Day(To_Date( To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;), &apos;YYYYMM&apos;));
  END IF;
  vAnLunaPrec := vAnLunaIni - 1;

  sDataIni := &apos;To_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin := &apos;To_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  sInsertTmpS :=
  &apos;INSERT INTO tmp_lst_balsf (
    FURN, CODGESTPROD,
    GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, CODCENTRU,
    SI,  CI,  CP,  CE,  CC,  CT,
    SI1, CI1, CP1, CE1, CC1, CT1,
    SI2, CI2, CP2, CE2, CC2, CT2,
    SoldI, VI, VP, VE, VC, VT,
    CantIntrAS,    CantIntrT,
    CantIntrASUM1, CantIntrTUM1,
    CantIntrASUM2, CantIntrTUM2,
    ValIntrAS,     ValIntrT,
    CantIesAS,     CantIesT,
    CantIesASUM1,  CantIesTUM1,
    CantIesASUM2,  CantIesTUM2,
    ValIesAS,      ValIesT,
    CantDimin,     CantMariri,
    CantDiminUM1,  CantMaririUM1,
    CantDiminUM2,  CantMaririUM2,
    ValDimin,      ValMariri,
    ValVanzari,
    DataStart, DataStop,
    Valoric)
  WITH 
  B AS (
    -- Initial
    SELECT
      0 TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, 0 CODCENTRU,
      NL.REST SI, NL.RESTUM1 SI1, NL.RESTUM2 SI2,
      0 CI, 0 CI1, 0 CI2,
      0 CP, 0 CP1, 0 CP2,
      0 CE, 0 CE1, 0 CE2,
      0 CC, 0 CC1, 0 CC2,
      0 CT, 0 CT1, 0 CT2,
      0 PRETV
    FROM nirluna nl
      INNER JOIN nirstoc ns  ON ns.codnirstoc = nl.codnirstoc
      INNER JOIN nir     n   ON n.codnir      = ns.codnir
      INNER JOIN ngest   g   ON g.codgest     = n.gest
      INNER JOIN ioart1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5 
    WHERE nl.an *12 + nl.luna = &apos;||vAnLunaPrec||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- NIR Intrari
    SELECT
      N.TIPNIR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, Coalesce(I1.CODCENTRU,0) CODCENTRU,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR END * DECODE(N.TIPNIR,7,0,1) CI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR END * DECODE(N.TIPNIR,7,1,0) CP,
      0 CE,
      0 CC,
      0 CT,
      0 PRETV
    FROM NIRSTOC NS
      INNER JOIN NIR     N   ON N.CODNIR     = NS.CODNIR
      INNER JOIN INTRARI I   ON I.CODINTR    = N.CODINTR
      INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN INTRARI1 I1  ON I1.CODINTR1  = NS.CODINTR1
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND N.DATANIR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- NIR-uri din MISCARI INTERNE
    SELECT
      N.TIPNIR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(T1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN NS.CANTNIR ELSE 0 END SI,
      CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE NS.CANTNIR END CI,
      0 CP,
      0 CE,
      0 CC,
      0 CT,
      0 PRETV
    FROM NIRSTOC NS
      INNER JOIN NIR     N   ON N.CODNIR       = NS.CODNIR
      INNER JOIN TRANSF  T   ON T.CODTRANSF    = N.CODTRANSF
      INNER JOIN ioart1  IOA ON IOA.CODIOART   = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN TRANSF1  T1  ON T1.CODTRANSF1  = NS.CODTRANSF1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR      = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1   = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND N.DATANIR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- RETURURI
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT ELSE 0    END SI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END * DECODE(L.TIPLIVR,7,0,1) CI,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END * DECODE(L.TIPLIVR,7,1,0) CP,
      0 CE,
      0 CC,
      0 CT,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR      = L1.CODLIVR
      INNER JOIN INTRARI I   ON I.CODINTR      = L.CODINTR
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC  = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR       = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART   = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN INTRARI1 I1  ON I1.CODINTR1    = L1.CODINTR1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR      = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1   = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- IESIRI
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT    ELSE 0 END SI,
      0 CI,
      0 CP,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,14,0,24,0,1) CE,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,24,1,0) CC,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END * DECODE(L.TIPLIVR,14,1,0) CT,
      CASE
        WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0
        WHEN I1.CANT = 0 THEN 0
        WHEN I1.PU   = 0 THEN 0
        WHEN I.TIPDOC IN (19, 20) THEN I1.PRETORIG * I1.COEFDISCMAJ
        WHEN I.TIPDOC IN (21)     THEN (I1.PU-I1.TVA/I1.CANT)*I1.PRETORIG*I1.COEFDISCMAJ/I1.PU
        ELSE 0
      END PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR      = L1.CODLIVR
      INNER JOIN IESIRI  I   ON I.CODIES       = L.CODIES AND I.TIPDOC = L.TIPLIVR
      INNER JOIN IESIRI1 I1  ON I1.CODIES1     = L1.CODIES1 AND I1.CODIES = I.CODIES
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC  = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR       = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART   = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR      = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1   = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- MISCARI INTERNE
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(T1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN -L1.CANT    ELSE 0 END SI,
      0 CI,
      0 CP,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE L1.CANT    END CE,
      0 CC,
      0 CT,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR      = L1.CODLIVR
      INNER JOIN TRANSF  T   ON T.CODTRANSF    = L.CODTRANSF
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC  = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR       = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART   = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN TRANSF1  T1  ON T1.CODTRANSF1  = L1.CODINTR1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR      = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1   = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
    UNION ALL -- MARIRI DE STOC
    SELECT
      L.TIPLIVR TipDoc,
      Coalesce(NS.FURN,0) FURN, Coalesce(NS.CODGESTPROD,0) CODGESTPROD,
      N.GEST, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.CODOBIECT, NS.CODIOART, IOA.CONT, IOA.MG, NS.PRET, COALESCE(I1.CODCENTRU, I1O.CODCENTRU, 0) CODCENTRU,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANT    ELSE 0 END SI,
      0 CI,
      0 CP,
      0 CE,
      0 CC,
      CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN 0 ELSE -L1.CANT    END CT,
      0 PRETV
    FROM LIVR1 L1
      INNER JOIN LIVR    L   ON L.CODLIVR      = L1.CODLIVR
      INNER JOIN IESIRI  I   ON I.CODIES       = L.CODIES
      INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC  = L1.CODNIRSTOC
      INNER JOIN NIR     N   ON N.CODNIR       = NS.CODNIR
      INNER JOIN ioart1  IOA ON IOA.CODIOART   = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg &lt;&gt; 5
      LEFT JOIN IESIRI1  I1  ON I1.CODIES1     = L1.CODIES1
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN NIRSTOC  NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      NO  ON NO.CODNIR      = NSO.CODNIR
      LEFT JOIN INTRARI1 I1O ON I1O.CODINTR1   = NSO.CODINTR1 AND I1O.CODINTR = NO.CODINTR
    WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND L.DATALIVR &lt;= &apos;||sDataFin||
      CondFurn(&apos;ns.furn&apos;)||&apos;
  )
  SELECT
    FURN, CODGESTPROD,
    GEST, CODLOCATIE, CODOBIECT, CODIOART, CONT, MG, SERIE, SEROBS, TG, CODCERTIF, CODCENTRU,
    SUM(SI)  SI,  SUM(CI)  CI,  SUM(CP)  CP,  SUM(CE)  CE,  SUM(CC)  CC,  SUM(CT)  CT,
    SUM(SI*PRET) SoldI, SUM(CI*PRET) VI, SUM(CP*PRET) VP, SUM(CE*PRET) VE, SUM(CC*PRET) VC, SUM(CT*PRET) VT,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI      ELSE 0 END) CantIntrAS,    SUM(CASE WHEN B.TIPDOC = 12 THEN CI      ELSE 0 END) CantIntrT,
    SUM(CASE WHEN B.TIPDOC =  6 THEN CI*PRET ELSE 0 END) ValIntrAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CI*PRET ELSE 0 END) ValIntrT,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE      ELSE 0 END) CantIesAS,     SUM(CASE WHEN B.TIPDOC = 12 THEN CE      ELSE 0 END) CantIesT,
    SUM(CASE WHEN B.TIPDOC = 23 THEN CE*PRET ELSE 0 END) ValIesAS,      SUM(CASE WHEN B.TIPDOC = 12 THEN CE*PRET ELSE 0 END) ValIesT,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT      ELSE 0 END) CantDimin,     SUM(CASE WHEN B.TIPDOC = 15 THEN CT      ELSE 0 END) CantMariri,
    SUM(CASE WHEN B.TIPDOC = 14 THEN CT*PRET ELSE 0 END) ValDimin,      SUM(CASE WHEN B.TIPDOC = 15 THEN CT*PRET ELSE 0 END) ValMariri,
    SUM(CE * PretV) ValVanzari,
    to_date(&apos;&apos;&apos;||to_char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStart, to_date(&apos;&apos;&apos;||to_char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStop,
    0 Valoric
  FROM b
  GROUP BY furn, codgestprod, gest, codlocatie, codobiect, codioart, cont, mg, serie, serobs, tg, codcertif, codcentru&apos;;

  sCurata :=
  &apos;DELETE tmp_lst_balsf
  WHERE Coalesce(si, 0) = 0 AND Coalesce(ci, 0) = 0 AND Coalesce(cp, 0) = 0 AND Coalesce(ce, 0) = 0 AND Coalesce(cc, 0) = 0 AND (Coalesce(ct, 0) = 0)
    AND Coalesce(CantIntrAS,0) = 0 AND Coalesce(CantIntrT,0) = 0 AND Coalesce(CantIesAS,0) = 0 AND Coalesce(CantIesT,0) = 0
    AND Coalesce(CantDimin,0) = 0 AND Coalesce(CantMariri,0) = 0&apos;;

  sUpdate :=
  &apos;UPDATE tmp_lst_balsf
  SET sf    = si   +ci +cp -ce -cc -ct,
      soldf = soldi+vi +vp -ve -vc -vt&apos;;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    X_Judet, X_CodGest, X_Codsubunit, CodObiect, DenArt,
    DenFurn,
    TipFurn,
    DenGest, DenLGest, DenSub, DenCont,
    DenUM, DenUM1, DenUM2,
    CodExt, CodInt, Prod,
    StocInit,    CantIntr,    CantProd,    CantIes,    CantCons,    CantTr,    StocFinal,
    SoldInit,    ValIntr,     ValProd,     ValIes,     ValCons,     ValTr,     SoldFinal,
    CantIntrAS,  CantIntrT,   CantIesAS,   CantIesT,   CantDimin,   CantMariri,
    ValIntrAS,   ValIntrT,    ValIesAS,    ValIesT,    ValDimin,    ValMariri,
    MG,
    UMTRANSF,
    COEFTRANSF,
    SERIE, SEROBS, TG, CentruCost&apos;||
    gUserFields||&apos;)
  SELECT
    jgest.Simbauto, g.codgest, sub.codsubunit, s.codobiect, CASE WHEN valoric = 0 THEN o.denumire ELSE &apos;&apos;Tranzactii valorice&apos;&apos; END DenArt,
    CASE WHEN s.codgestprod &gt; 0 THEN gprod.den_gest ELSE furn.den_part END DenFurn,
    CASE WHEN s.codgestprod &gt; 0 THEN &apos;&apos;GESTIUNE PRODUCATOARE&apos;&apos; ELSE &apos;&apos;FURNIZOR&apos;&apos; END TipFurn,
    g.den_gest, l.denumire, sub.den_subunit, c.simbol,
    CASE WHEN valoric = 0 THEN u.den_um1 ELSE &apos;&apos;LEI&apos;&apos; END DenUM, CASE WHEN valoric = 0 THEN u1.den_um END DenUM1, CASE WHEN valoric = 0 THEN u2.den_um END DenUM2,
    o.codextern, o.codintern, prod.den_part,
    s.si,    s.ci,  s.cp,  s.ce,  s.cc,  s.ct,  s.sf    StocFinal,
    s.SoldI, s.vi,  s.vp,  s.ve,  s.vc,  s.vt,  s.soldf SoldFinal,
    s.CantIntrAS,    s.CantIntrT,    s.CantIesAS,    s.CantIesT,    s.CantDimin,    s.CantMariri,
    s.ValIntrAS,     s.ValIntrT,     s.ValIesAS,     s.ValIesT,     s.ValDimin,     s.ValMariri,
    CASE s.mg WHEN 1 THEN &apos;&apos;FIFO&apos;&apos; WHEN 2 THEN &apos;&apos;LIFO&apos;&apos; WHEN 3 THEN &apos;&apos;PMP&apos;&apos; WHEN 4 THEN &apos;&apos;IDS&apos;&apos; WHEN 5 THEN &apos;&apos;VAL&apos;&apos;END MG,
    CASE WHEN valoric = 1 THEN NULL WHEN up.tipum=1 THEN &apos;&apos;Kg&apos;&apos; WHEN up.tipum=2 THEN &apos;&apos;Cm3&apos;&apos; WHEN up.tipum=3 THEN &apos;&apos;M2&apos;&apos; WHEN up.tipum=4 THEN &apos;&apos;M&apos;&apos; WHEN up.tipum=5 THEN &apos;&apos;Buc&apos;&apos; END UMTRANSF,
    CASE WHEN valoric = 1 THEN 1 ELSE up.coef END COEFTRANSF &apos;||
    gUserAlias||&apos;
  FROM tmp_lst_balsf s
    LEFT JOIN npart      furn  ON furn.codpart     = s.furn
    LEFT JOIN ngest      gprod ON gprod.codgest    = s.codgestprod
    LEFT JOIN nartobj    o     ON o.codobiect      = s.codobiect
    LEFT JOIN ngest      g     ON g.codgest        = s.gest
    LEFT JOIN pretm      pm    on o.codobiect      = pm.codobiect and pm.subunitatea = g.codsubunit and pm.implicit = 1
    LEFT JOIN nart       a     ON a.codarticol     = o.codarticol
    LEFT JOIN num1       u     ON u.codum          = a.um AND u.secundara = 0
    LEFT JOIN num        up    on up.codum         = a.um
    LEFT JOIN ioart      io    ON io.codioart      = s.codioart
    LEFT JOIN ncont      c     ON c.codcont        = s.cont
    LEFT JOIN npers      pg    ON pg.codpers       = g.codgestionar
    LEFT JOIN nlocatii   l     ON l.codlocatie     = s.codlocatie
    LEFT JOIN nsubunit   sub   ON sub.codsubunit   = g.codsubunit
    LEFT JOIN npart      prod  ON prod.codpart     = o.codproducator
    LEFT JOIN nclasea    ca    ON ca.codclasea     = a.clasa
    LEFT JOIN nclaseas   cas   ON cas.codclaseas   = a.clasastatist
    LEFT JOIN nartamb    aa    ON aa.codobiect     = s.codobiect AND aa.umsec = u.codum1
    LEFT JOIN ncarsupart csa   ON csa.codcarsupart = o.codcaract
    LEFT JOIN nagenda    sgest ON sgest.codgest    = g.codgest
    LEFT JOIN nlocalit   lgest ON lgest.codlocalit = sgest.codlocalit
    LEFT JOIN njudet     jgest ON jgest.codjudet   = lgest.codjudet
    LEFT JOIN centrecost cc    ON cc.codcentru     = s.codcentru&apos;||
    gSuplJoins;

  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  LIST_EXECUTE_IMMEDIATE(sGolesteTMP, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsertTmpS, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sCurata    , aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate    , aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert    , aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_BALSTOCREST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BAL_IFRS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BA7259D9146D9B2FBF8FC6C3E104BFA1BFA4DE0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BAL_IFRS IS

  gSuplCols varchar2(1) := &apos;&apos;;
  p_clasa        NUMBER;
  p_sintetic     NUMBER;
  p_plan         NUMBER;
  p_valuta       NUMBER;
  p_PeSubunit    VARCHAR2(2);
  p_Lunara       VARCHAR2(2);
  g_tmpTABLE     varchar2(100);
  p_AL           NUMBER;
  p_An           NUMBER;
  p_Luna         NUMBER;
  p_LunaI        NUMBER;

  p_IDX_SINTETIC INTEGER;

  CT_PLANCOM CONSTANT INTEGER := 0;
  CT_PLANP   CONSTANT INTEGER := 1;
  CT_PLANS   CONSTANT INTEGER := 2;
  CT_PLANT   CONSTANT INTEGER := 3;

PROCEDURE Set_G_tmpTABLE (aName in varchar2)
IS
BEGIN
  G_tmpTABLE := aName;
end;

PROCEDURE setParams (
  v_clasa      IN NUMBER DEFAULT 0,
  v_sintetic   IN NUMBER DEFAULT 0,
  v_plan       IN NUMBER DEFAULT 0,
  v_valuta     IN NUMBER DEFAULT 0,
  v_PeSubunit  IN NUMBER DEFAULT 1,
  v_Lunara     IN NUMBER DEFAULT 1,
  v_Luna       IN NUMBER DEFAULT 0,
  v_An         IN NUMBER DEFAULT 0,
  V_CODJOB1    IN NUMBER DEFAULT 0,
  v_lunaI      IN NUMBER DEFAULT 1 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  dDataS     DATE;
  dDataF     DATE;
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  IF Coalesce(v_An, 0) = 0
  THEN p_AL  := pkg_globals.AnLunaLucru;
  ELSE p_AL  := v_An * 12 + v_Luna;
  END IF;
  xLunaAnIni := p_AL;
  xLunaAnFin := pkg_globals.AnLunaLucru;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  p_AL := xLunaAnIni;
  PKG_LIST_BASE_UTILS.ExtractAnLuna(p_AL, p_An, p_Luna);
  p_LunaI := v_lunai;

  p_clasa      := v_clasa;
  p_sintetic   := v_sintetic;
  p_plan       := v_plan;
  p_valuta     := v_valuta;
  p_PeSubunit  := CASE WHEN v_PeSubunit = 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END;
  p_Lunara     := CASE WHEN v_Lunara    = 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END;

  DELETE TMP_NCONT_BAL;
  DELETE TMP_NCONT1_BAL;
  PKG_LIST_BASE_UTILS.CLEAR_SIMBOL_LIPSA;

  IF p_plan = CT_PLANCOM THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      CODCONT, SIMBOL, CLASA, DEN_CONT, NULL NAME, TIPCONT, VIZIBILBALANTA, BALSINT, NIVEL, CODPARINTE, NULL, NULL, NULL
    FROM NCONTCOMUN NC
    WHERE NC.CODCONT &lt;&gt; 0
      AND DECODE(p_clasa,0,CLASA, p_clasa) = CLASA; -- filtrare dupa CLASA
  ELSIF p_plan = CT_PLANP THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA,
      NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
--    WITH NC1 AS (
--      SELECT CODCONT, Max(CODCENTRU) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) CODCENTRU
--      FROM ncont1
--      WHERE (ANSTART * 12 + LUNASTART) &lt;= p_An*12+p_Luna
--      GROUP BY CODCONT)
    SELECT
      NC.CODCONT, NC.SIMBOL, NC.CLASA, NC.DEN_CONT, NC.NAME, NC.TIPCONT, NC.VIZIBILBALANTA, NC.BALANTASINTETICA,
      NC.NIVEL, NC.CODPARINTE, NC.SIMBOLSITFIN, CC.DENUMIRE, CC.SIMBOL
    FROM NCONT1 NC1
      INNER JOIN NCONT      NC ON NC.CODCONT   = NC1.CODCONT AND (p_An*12+p_Luna) BETWEEN NC1.ALSTART and NC1.ALSTOP
      LEFT  JOIN CENTRECOST CC ON CC.CODCENTRU = Nvl(NC1.CODCENTRU,0)
    WHERE NC.CODCONT &lt;&gt; 0
      AND Decode(p_Clasa,0,1,CLASA,1,0) = 1; -- filtrare dupa CLASA

    INSERT INTO TMP_NCONT1_BAL (CODCONT, CODCOMUN) SELECT CODCONT, CODCONT FROM TMP_NCONT_BAL;
    /*
    INSERT INTO TMP_NCONT1_BAL (CODCONT, CODCOMUN)
    SELECT DISTINCT CODCONT, CODCONT
    FROM NCONT1
    WHERE ANSTART*12+LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru;
    */
  ELSIF p_plan = CT_PLANS THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      NC.CODCONTS, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, NULL, NULL
    FROM NCONTS NC
    WHERE NC.CODCONTS &lt;&gt; 0
      AND EXISTS (SELECT 1 FROM NCONTS1 NC1 WHERE NC1.CODCONTS = NC.CODCONTS AND (NC1.ANSTART*12+NC1.LUNASTART) &lt;= p_An*12+p_Luna);

    INSERT INTO TMP_NCONT_BAL (CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    VALUES ( -1, &apos;...Fara coresp..&apos;, 0,&apos;...Fara corespondenta in planul Secundar...&apos;, NULL, 0,  1, 1, 1, 0, NULL, NULL, NULL);

    INSERT INTO TMP_NCONT1_BAL (CODCONT, CODCOMUN, SIMBOLPLANP, FRUNZA)
--    WITH C1 AS (
--      SELECT CODCONT, Max(CONTSECUNDAR) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) CODCONTS
--      FROM NCONT1
--      WHERE (ANSTART * 12 + LUNASTART) &lt;= p_An*12+p_Luna
--      GROUP BY CODCONT)
    SELECT Decode(C1.CONTSECUNDAR,NULL,-1,0,-1,C1.CONTSECUNDAR), C.CODCONT, C.SIMBOL, CASE WHEN EXISTS(SELECT 1 FROM NCONT WHERE CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND (p_An*12+p_Luna) BETWEEN C1.ALSTART and C1.ALSTOP;

  ELSIF p_plan = CT_PLANT THEN
    INSERT INTO TMP_NCONT_BAL (
      CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    SELECT
      NC.CODCONTT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, NULL, NULL
    FROM NCONTT NC
    WHERE NC.CODCONTT &lt;&gt; 0
      AND Decode(p_Clasa,0,1,CLASA,1,0) = 1 -- filtrare dupa CLASA
      AND EXISTS (SELECT 1 FROM NCONTT1 NC1 WHERE NC1.CODCONTT = NC.CODCONTT AND (NC1.ANSTART*12+NC1.LUNASTART) &lt;= p_An*12+p_Luna);

    INSERT INTO TMP_NCONT_BAL (CODCONT, SIMBOL, CLASA, DEN_CONT, NAME, TIPCONT, VIZIBILBALANTA, BALANTASINTETICA, NIVEL, CODPARINTE, SIMBOLSITFIN, CENTRUCOST, SIMBCENTRUCOST)
    VALUES ( -1, &apos;...Fara coresp..&apos;, 0,&apos;...Fara corespondenta in planul Secundar...&apos;, NULL, 0,  1, 1, 1, 0, NULL, NULL, NULL);

    INSERT INTO TMP_NCONT1_BAL (CODCONT, CODCOMUN, SIMBOLPLANP, FRUNZA)
--    WITH C1 AS (
--      SELECT CODCONT, Max(CONTTERTIAR) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) CODCONTT
--      FROM NCONT1
--      WHERE (ANSTART * 12 + LUNASTART) &lt;= p_An*12+p_Luna
--      GROUP BY CODCONT)
    SELECT Decode(C1.CONTTERTIAR,NULL,-1,0,-1,C1.CONTTERTIAR), C.CODCONT, C.SIMBOL, CASE WHEN EXISTS(SELECT 1 FROM NCONT WHERE CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND (p_An*12+p_Luna) BETWEEN C1.ALSTART and C1.ALSTOP;

  END IF;

  COMMIT;
END;

FUNCTION getConturiBal RETURN crs IS
  cResult crs;
BEGIN
  IF p_plan = CT_PLANCOM THEN
    OPEN cResult FOR
      SELECT CODCONT, CODFIRMACUPL, CODCONTCOMUN, NRANALITICE, LEGATURAINVALIDA
      FROM NCONTFIRMECUPL;
  ELSIF P_SINTETIC = 0 THEN
    OPEN cResult FOR
      WITH
        CONTURI AS (
          SELECT CODCONT, CLASA, SIMBOL, NVL(TIPCONT,0) TIPCONT, NVL(BALANTASINTETICA,0) BALANTASINTETICA, NIVEL, CONNECT_BY_ISLEAF FARA_FII, VIZIBILBALANTA
          FROM (SELECT * FROM NCONT NC
                WHERE DECODE(p_clasa,0,CLASA, p_clasa) = CLASA
                AND NC.CODCONT &lt;&gt; 0
                AND EXISTS (SELECT 1 FROM NCONT1 NC1 WHERE NC1.CODCONT = NC.CODCONT AND (NC1.ANSTART*12+NC1.LUNASTART) &lt;= p_An*12+p_Luna)
              )
          START WITH NVL(CODPARINTE,0) = 0
          CONNECT BY PRIOR CODCONT = CODPARINTE
        )
      SELECT C.SIMBOL, 0, C.CODCONT, C.CLASA, C.TIPCONT, C.BALANTASINTETICA, C.NIVEL, C.VIZIBILBALANTA, C.FARA_FII
      FROM CONTURI C;
  ELSE
    OPEN cResult FOR

      SELECT SIMBOL, 0, CODCONT, BALSINT, Sum(FII_BS) - BALSINT FII_BALSINT
      FROM (
        SELECT
          CONNECT_BY_ROOT CODCONT CODCONT,
          CONNECT_BY_ROOT SIMBOL SIMBOL,
          Nvl(CONNECT_BY_ROOT BALANTASINTETICA,0) BALSINT,
          Nvl(BALANTASINTETICA,0) FII_BS
        FROM (
          SELECT * FROM NCONT NC
          WHERE NC.CODCONT &lt;&gt; 0
          AND DECODE(p_clasa,0,CLASA, p_clasa) = CLASA
          AND EXISTS (SELECT 1 FROM NCONT1 NC1 WHERE NC1.CODCONT = NC.CODCONT AND (NC1.ANSTART*12+NC1.LUNASTART) &lt;= p_An*12+p_Luna)
        )
        CONNECT BY PRIOR CODCONT = CODPARINTE
      )
      GROUP BY CODCONT, SIMBOL, BALSINT;
  END IF;

  RETURN cResult;
END;

PROCEDURE GetContRec(p_CodCont IN NCont.Codcont%TYPE, v_rec IN OUT TMP_NCONT_BAL%ROWTYPE)
IS
BEGIN
  SELECT CODCONT,
         CODCONTP,
         CODCONTS,
         CODCONTT,
         SIMBOL,
         CLASA,
         DEN_CONT,
         NAME,
         TIPCONT,
         VIZIBILBALANTA,
         BALANTASINTETICA,
         NIVEL,
         CODPARINTE,
         SIMBOLSITFIN,
         CENTRUCOST,
         SIMBCENTRUCOST,
         NRANALITICE
  INTO v_rec
  FROM TMP_NCONT_BAL
  WHERE CODCONT = p_CodCont;
END;

PROCEDURE Insert_Rec(p_rec IN TMP_LIST_BALANTA_IFRS%ROWTYPE , tmpName IN VARCHAR2)
IS
  sInsert VARCHAR2(10000);
  v_TOTALCPD    TMP_LIST_BALANTA_IFRS.TOTALCPD%TYPE;
  v_TOTALCPC    TMP_LIST_BALANTA_IFRS.TOTALCPC%TYPE;
  v_TOTALCD     TMP_LIST_BALANTA_IFRS.TOTALCD%TYPE;
  v_TOTALCC     TMP_LIST_BALANTA_IFRS.TOTALCC%TYPE;
BEGIN
  IF nvl(p_rec.simbol,&apos;*&apos;) &lt;&gt; &apos;*&apos; AND
    (p_sintetic = 0 OR (p_sintetic = 1 AND p_rec.balantasintetica = 1))   -- filtrare dupa analitic / sintetic
  THEN
    -- stef 19.09.2011 corectie Sume de total sa fie calculate in funtie de solul initial trecut pe debit sau credit
    v_TOTALCPD    := p_rec.SOLDID + p_rec.RULAJPD;
    v_TOTALCPC    := p_rec.SOLDIC + p_rec.RULAJPC;
    v_TOTALCD     := p_rec.SOLDID + p_rec.RULAJCD;
    v_TOTALCC     := p_rec.SOLDIC + p_rec.RULAJCC;

    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
      CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL, INDEX_SINTETIC, FRUNZA, CENTRUCOST, SIMBCENTRUCOST,
      SOLDID, SOLDIC, SOLDIIFRS, SOLDIGRUP, RULAJPD, RULAJPC, RULAJPIFRS, RULAJPGRUP, TOTALCPD, TOTALCPC, RULAJD, RULAJC, RULAJIFRS, RULAJGRUP,
      RULAJCD, RULAJCC, RULAJCIFRS, RULAJCGRUP, TOTALCD, TOTALCC, SOLDFD, SOLDFC, SOLDFIFRS, SOLDFGRUP
      )
    VALUES(
      :CODCONT, :CLASA, :SIMBOL, :DEN_CONT, :TIPCONT, :NAME, :BALANTASINTETICA, :NIVEL, :INDEX_SINTETIC, :FRUNZA, :CENTRUCOST, :SIMBCENTRUCOST,
      :SOLDID, :SOLDIC, :SOLDIIFRS, :SOLDIGRUP, :RULAJPD, :RULAJPC, :RULAJPIFRS, :RULAJPGRUP, :TOTALCPD, :TOTALCPC, :RULAJD, :RULAJC, :RULAJIFRS, :RULAJGRUP,
      :RULAJCD, :RULAJCC, :RULAJCIFRS, :RULAJCGRUP, :TOTALCD, :TOTALCC, :SOLDFD, :SOLDFC, :SOLDFIFRS, :SOLDFGRUP
      )&apos; ;

    EXECUTE IMMEDIATE sInsert
    USING
      p_rec.Codcont, p_rec.clasa, p_rec.simbol, p_rec.den_cont, p_rec.tipcont, p_rec.name, p_rec.balantasintetica, p_rec.nivel, p_idx_sintetic, 1, p_rec.centrucost, p_rec.simbcentrucost,
      p_rec.soldid, p_rec.soldic, p_rec.soldiifrs, p_rec.soldigrup, p_rec.rulajpd, p_rec.rulajpc, p_rec.rulajpifrs, p_rec.rulajpgrup, v_totalcpd, v_totalcpc, p_rec.rulajd, p_rec.rulajc, p_rec.rulajifrs, p_rec.rulajgrup,
      p_rec.rulajcd, p_rec.rulajcc, p_rec.rulajcifrs, p_rec.rulajcgrup, v_totalcd, v_totalcc, p_rec.soldfd, p_rec.soldfc, p_rec.soldfifrs, p_rec.soldfgrup;

    IF p_rec.codcont = -1 THEN
      PKG_LIST_BASE_UTILS.SET_LISTA_SIMBOL_LIPSA(p_rec.simbplanp);
    END IF;
  END IF;
END;

PROCEDURE Fill_RecTotals(v_bal IN TMP_LIST_BALANTA_IFRS%ROWTYPE)
IS
  v_ncont       TMP_NCONT_BAL%ROWTYPE;
  v_codparinte  NUMBER(20);
  v_aux_codcont TMP_LIST_BALANTA_IFRS.Codcont%TYPE;
  v_TOTALCPD    TMP_LIST_BALANTA_IFRS.TOTALCPD%TYPE;
  v_TOTALCPC    TMP_LIST_BALANTA_IFRS.TOTALCPC%TYPE;
  v_TOTALCD     TMP_LIST_BALANTA_IFRS.TOTALCD%TYPE;
  v_TOTALCC     TMP_LIST_BALANTA_IFRS.TOTALCC%TYPE;
BEGIN
  v_codparinte := v_bal.codparinte;
  WHILE Nvl(v_codparinte,0) &lt;&gt; 0 LOOP
    GetContRec(v_codparinte, v_ncont);

    IF  ((p_sintetic = 0 AND v_ncont.vizibilbalanta = 1) OR (p_sintetic = 1 AND v_ncont.balantasintetica = 1)) -- filtrare dupa analitic / sintetic
    THEN
      v_aux_codcont := 0;
      -- stef 19.09.2011 corectie Sume de total sa fie calculate in funtie de solul initial trecut pe debit sau credit
      v_TOTALCPD    := v_bal.SOLDID + v_bal.RULAJPD;
      v_TOTALCPC    := v_bal.SOLDIC + v_bal.RULAJPC;
      v_TOTALCD     := v_bal.SOLDID + v_bal.RULAJCD;
      v_TOTALCC     := v_bal.SOLDIC + v_bal.RULAJCC;

      UPDATE TMP_LIST_BALANTA_IFRS
      SET SOLDID = SOLDID + v_bal.SOLDID,
          SOLDIC = SOLDIC + v_bal.SOLDIC,
          SOLDIIFRS = SOLDIIFRS + v_bal.SOLDIIFRS,
          SOLDIGRUP = SOLDIGRUP + v_bal.SOLDIGRUP,
          RULAJPD = RULAJPD + v_bal.RULAJPD,
          RULAJPC = RULAJPC + v_bal.RULAJPC,
          RULAJPIFRS = RULAJPIFRS + v_bal.RULAJPIFRS,
          RULAJPGRUP = RULAJPGRUP + v_bal.RULAJPGRUP,
          TOTALCPD = TOTALCPD + v_TOTALCPD,--v_bal.TOTALCPD,
          TOTALCPC = TOTALCPC + v_TOTALCPC,--v_bal.TOTALCPC,
          RULAJD = RULAJD + v_bal.RULAJD,
          RULAJC = RULAJC + v_bal.RULAJC,
          RULAJIFRS = RULAJIFRS + v_bal.RULAJIFRS,
          RULAJGRUP = RULAJGRUP + v_bal.RULAJGRUP,
          RULAJCD = RULAJCD + v_bal.RULAJCD,
          RULAJCC = RULAJCC + v_bal.RULAJCC,
          RULAJCIFRS = RULAJCIFRS + v_bal.RULAJCIFRS,
          RULAJCGRUP = RULAJCGRUP + v_bal.RULAJCGRUP,
          TOTALCD = TOTALCD + v_TOTALCD,--v_bal.TOTALCD,
          TOTALCC = TOTALCC + v_TOTALCC,--v_bal.TOTALCC,
          SOLDFD = SOLDFD + v_bal.SOLDFD,
          SOLDFC = SOLDFC + v_bal.SOLDFC,
          SOLDFIFRS = SOLDFIFRS + v_bal.SOLDFIFRS,
          SOLDFGRUP = SOLDFGRUP + v_bal.SOLDFGRUP
      WHERE CODCONT = v_ncont.codcont
      RETURNING CODCONT INTO v_aux_codcont;

      IF v_aux_codcont = 0 THEN
        INSERT INTO TMP_LIST_BALANTA_IFRS (
          CODCONT, SIMBOL, CLASA, DEN_CONT, TIPCONT, NAME,
          BALANTASINTETICA, NIVEL, CODSINTETIC, CODPARINTE, CENTRUCOST, SIMBCENTRUCOST,
          SOLDID, SOLDIC, SOLDIIFRS, SOLDIGRUP, RULAJPD, RULAJPC, RULAJPIFRS, RULAJPGRUP, TOTALCPD, TOTALCPC,
          RULAJD, RULAJC, RULAJIFRS, RULAJGRUP, RULAJCD, RULAJCC, RULAJCIFRS, RULAJCGRUP, TOTALCD, TOTALCC, SOLDFD, SOLDFC, SOLDFIFRS, SOLDFGRUP )
        VALUES (
          v_ncont.codcont, v_ncont.simbol, v_ncont.clasa, v_ncont.den_cont, DECODE(v_ncont.tipcont,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;,&apos;ACTIV&apos;), v_ncont.name,
          nvl(v_ncont.balantasintetica,-1), v_ncont.nivel, v_bal.codsintetic, v_ncont.codparinte, v_bal.CENTRUCOST, v_bal.SIMBCENTRUCOST,
          v_bal.SOLDID, v_bal.SOLDIC, v_bal.SOLDIIFRS, v_bal.SOLDIGRUP, v_bal.RULAJPD, v_bal.RULAJPC, v_bal.RULAJPIFRS, v_bal.RULAJPGRUP, v_TOTALCPD, v_TOTALCPC,
          v_bal.RULAJD, v_bal.RULAJC, v_bal.RULAJIFRS, v_bal.RULAJGRUP, v_bal.RULAJCD, v_bal.RULAJCC, v_bal.RULAJCIFRS, v_bal.RULAJCGRUP, v_TOTALCD, v_TOTALCC, v_bal.SOLDFD, v_bal.SOLDFC, v_bal.SOLDFIFRS, v_bal.SOLDFGRUP );
      END IF;
    END IF;
    v_codparinte := v_ncont.codparinte;
  END LOOP;
END;

PROCEDURE Insert_RecTotal(tmpName IN VARCHAR2)
IS
  sInsert  VARCHAR2(5000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL,
    SOLDID, SOLDIC,
    RULAJPD, RULAJPC, TOTALCPD, TOTALCPC, RULAJD, RULAJC,
    RULAJCD, RULAJCC, RULAJCIFRS, RULAJCGRUP, TOTALCD, TOTALCC,
    SOLDFD, SOLDFC,
    INDEX_SINTETIC, FRUNZA, CENTRUCOST, SIMBCENTRUCOST)
  SELECT
    CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL,
    CASE
      WHEN TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN SOLDID - SOLDIC
      WHEN TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND SOLDID &gt; SOLDIC THEN SOLDID - SOLDIC
      ELSE 0
    END SOLDID,
    CASE
      WHEN TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN SOLDIC - SOLDID
      WHEN TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND SOLDIC &gt; SOLDID THEN SOLDIC - SOLDID
      ELSE 0
    END SOLDIC,
    RULAJPD, RULAJPC, TOTALCPD, TOTALCPC, RULAJD, RULAJC,
    RULAJCD, RULAJCC, RULAJCIFRS, RULAJCGRUP, TOTALCD, TOTALCC,
    CASE
      WHEN TIPCONT=&apos;&apos;ACTIV&apos;&apos; THEN SOLDFD - SOLDFC
      WHEN TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND SOLDFD &gt; SOLDFC THEN SOLDFD - SOLDFC
      ELSE 0
    END SOLDFD,
    CASE
      WHEN TIPCONT=&apos;&apos;PASIV&apos;&apos; THEN SOLDFC - SOLDFD
      WHEN TIPCONT=&apos;&apos;BIFUNC&apos;&apos; AND SOLDFC &gt; SOLDFD THEN SOLDFC - SOLDFD
      ELSE 0
    END SOLDFC,
    :INDEX_SINTETIC, 0, CENTRUCOST, SIMBCENTRUCOST
  FROM TMP_LIST_BALANTA_IFRS&apos;;
  EXECUTE IMMEDIATE sInsert USING p_IDX_SINTETIC;
  DELETE TMP_LIST_BALANTA_IFRS;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSBALANTA(tmpName IN VARCHAR2) IS
  v_prev_codsintetic NUMBER(20)  := -1;
BEGIN
  FOR v_rec IN (
    WITH
      CONTURI AS (
        SELECT
          CODCONT,
          CLASA, lpad(&apos; &apos;,LEVEL - 1)||SIMBOL SIMBOL, DEN_CONT, NVL(TIPCONT,0) TIPCONT, NAME, BALANTASINTETICA, NIVEL,
          CONNECT_BY_ROOT CODCONT CODSINTETIC, CONNECT_BY_ROOT SIMBOL SIMBSINTETIC, CODPARINTE,
          CONNECT_BY_ISLEAF FARA_FII, VIZIBILBALANTA, CENTRUCOST, SIMBCENTRUCOST, SIMBOLSITFIN
        FROM TMP_NCONT_BAL
        START WITH NVL(CODPARINTE,0) = 0
        CONNECT BY PRIOR CODCONT = CODPARINTE
        ORDER BY CLASA, SIMBOL),
      BALANTA AS (
        SELECT
          codcont,
          vc2_nt_to_vc3200_dist(CAST(COLLECT(simbolplanp ORDER BY simbolplanp) AS vc2_nt)) simbplanp,
          SUM(soldid)  soldid,  SUM(soldic)  soldic,  SUM(soldiifrs)  soldiifrs, SUM(soldigrup)  soldigrup,
          SUM(rulajpd) rulajpd, SUM(rulajpc) rulajpc, SUM(rulajpifrs) rulajpifrs, SUM(rulajpgrup) rulajpgrup,
          SUM(rulajd)  rulajd,  SUM(rulajc)  rulajc,  SUM(rulajifrs)  rulajifrs, SUM(rulajgrup)  rulajgrup,
          SUM(soldid + rulajpd + rulajd) totalcd, SUM(soldic + rulajpc + rulajc) totalcc,
          SUM(soldiifrs + rulajpifrs + rulajifrs) soldfifrs, SUM(soldigrup + rulajpgrup + rulajgrup) soldfgrup
        FROM  (
          SELECT
            c.codcont, c.simbolplanp,
            NVL(DECODE(p_valuta,0,b.soldid,b.soldvid),0) soldid, NVL(DECODE(p_valuta,0,b.soldic,b.soldvic),0) soldic,
            NVL(DECODE(p_valuta,0,b.soldi_ifrs,b.soldvi_ifrs),0) soldiifrs, NVL(DECODE(p_valuta,0,b.soldi_grup,b.soldvi_grup),0) soldigrup,
            0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpgrup, 0 rulajd, 0 rulajc, 0 rulajifrs, 0 rulajgrup
          FROM ncontsold B
            INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
          WHERE (NVL(DECODE(p_valuta,0,b.soldid,b.soldvid),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.soldic,b.soldvic),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.soldi_ifrs,b.soldvi_ifrs),0) &lt;&gt; 0 )
            AND b.an = p_An AND b.luna = p_LunaI
            AND p_PeSubunit = &apos;Nu&apos;
            AND c.codcont &lt;&gt; 0
          UNION ALL
          SELECT
            c.codcont, c.simbolplanp,
            NVL(DECODE(p_valuta,0,bs.soldid,bs.soldvid),0) soldid, NVL(DECODE(p_valuta,0,bs.soldic,bs.soldvic),0) soldic,
            NVL(DECODE(p_valuta,0,b.soldi_ifrs,b.soldvi_ifrs),0) soldiifrs, NVL(DECODE(p_valuta,0,b.soldi_grup,b.soldvi_grup),0) soldigrup,
            0 rulajpd, 0 rulajpc, 0 rulajpifrs, 0 rulajpgrup, 0 rulajd, 0 rulajc, 0 rulajifrs, 0 rulajgrup
          FROM ncontsold B
            INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
            INNER JOIN ncontsoldsub BS ON BS.CODCONTSOLD = B.CODCONTSOLD
          WHERE (NVL(DECODE(p_valuta,0,bs.soldid,bs.soldvid),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,bs.soldic,bs.soldvic),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,bs.soldi_ifrs,bs.soldvi_ifrs),0) &lt;&gt; 0 )
            AND b.an = p_An AND b.luna = p_LunaI
            AND p_PeSubunit = &apos;Da&apos;
            AND c.codcont &lt;&gt; 0
            AND bs.subunitatea IN (SELECT CodUnic FROM TMP_MANEVRA)
          -- atentie in ncontrul (ncontrulsub) campurile rulajcX se refara la rulaj curent (mai tarziu se va folosi rulajcX ca fiind rulaj cumulat)
          -- De ce :1 Fiindca aici s-a ajuns dupa modificari si s-a corectat de forma cea ma simpla !
          UNION ALL
          SELECT
            c.codcont, c.simbolplanp,
            0 soldid, 0 soldic, 0 soldiifrs, 0 soldigrup,
            NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) rulajpd, NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) rulajpc,
            NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) rulajpIFRS, NVL(DECODE(p_valuta,0,b.rulajp_grup,b.rulajvp_grup),0) rulajpgrup,
            NVL(DECODE(p_valuta,0,b.rulajcd,b.rulajvcd),0) rulajd,  NVL(DECODE(p_valuta,0,b.rulajcc,b.rulajvcc),0) rulajc,
            NVL(DECODE(p_valuta,0,b.rulajc_ifrs,b.rulajvc_ifrs),0) rulajIFRS, NVL(DECODE(p_valuta,0,b.rulajc_grup,b.rulajvc_grup),0) rulajgrup
          FROM ncontrul B
            INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
          WHERE ( NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) &lt;&gt; 0 OR
                  NVL(DECODE(p_valuta,0,b.rulajcd,b.rulajvcd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajcc,b.rulajvcc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajc_ifrs,b.rulajvc_ifrs),0) &lt;&gt; 0 )
            AND b.an = p_An AND b.luna = p_Luna
            AND p_PeSubunit = &apos;Nu&apos; AND p_Lunara = &apos;Da&apos;
            AND c.codcont &lt;&gt; 0
          UNION ALL
          SELECT
            c.codcont, c.simbolplanp,
            0 soldid, 0 soldic, 0 soldiifrs, 0 soldigrup,
            -NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) rulajpd, -NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) rulajpc,
            -NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) rulajpIFRS, -NVL(DECODE(p_valuta,0,b.rulajp_grup,b.rulajvp_grup),0) rulajpgrup,
            0 rulajd,  0 rulajc,
            0 rulajIFRS, 0 rulajgrup
          FROM ncontrul B
            INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
          WHERE ( NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) &lt;&gt; 0 OR
                  NVL(DECODE(p_valuta,0,b.rulajcd,b.rulajvcd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajcc,b.rulajvcc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajc_ifrs,b.rulajvc_ifrs),0) &lt;&gt; 0 )
            AND p_LunaI &gt; 1 and b.an = p_An AND b.luna = p_LunaI
            AND p_PeSubunit = &apos;Nu&apos; AND p_Lunara = &apos;Da&apos;
            AND c.codcont &lt;&gt; 0  
          UNION ALL
          SELECT
            c.codcont, c.simbolplanp,
            0 soldid, 0 soldic, 0 soldiifrs, 0 soldigrup,
            NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) rulajpd, NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) rulajpc,
            NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) rulajpIFRS, NVL(DECODE(p_valuta,0,b.rulajp_grup,b.rulajvp_grup),0) rulajpgrup,
            NVL(DECODE(p_valuta,0,b.rulajcd,b.rulajvcd),0) rulajd,  NVL(DECODE(p_valuta,0,b.rulajcc,b.rulajvcc),0) rulajc ,
            NVL(DECODE(p_valuta,0,b.rulajc_ifrs,b.rulajvc_ifrs),0) rulajIFRS, NVL(DECODE(p_valuta,0,b.rulajc_grup,b.rulajvc_grup),0) rulajgrup
          FROM tmp_ncontrul B
            INNER JOIN TMP_NCONT1_BAL C ON C.CODCOMUN = B.CODCONT
          WHERE ( NVL(DECODE(p_valuta,0,b.rulajpd,b.rulajvpd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajpc,b.rulajvpc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajp_ifrs,b.rulajvp_ifrs),0) &lt;&gt; 0 OR
                  NVL(DECODE(p_valuta,0,b.rulajcd,b.rulajvcd),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajcc,b.rulajvcc),0) &lt;&gt; 0 OR NVL(DECODE(p_valuta,0,b.rulajc_ifrs,b.rulajvc_ifrs),0) &lt;&gt; 0 )
            AND b.an = p_An AND b.luna = p_Luna
            AND (p_PeSubunit = &apos;Da&apos; OR p_Lunara = &apos;Nu&apos;)
            AND c.codcont &lt;&gt; 0
        )
        GROUP BY codcont
      )
    -- in selectul urmator facand referire la comentariul anterior xxxCD sau xxxCC inseamna xxx CUMULAT (nu curent) debitor (respectiv creditor)
    SELECT
      C.CODCONT,
      C.CLASA,
      C.SIMBOL,
      C.DEN_CONT,
      DECODE(C.TIPCONT,0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;) TIPCont,
      C.NAME,
      C.BALANTASINTETICA,
      C.NIVEL,
      C.CODSINTETIC,
      C.CODPARINTE,
      CASE
        WHEN C.TIPCONT=2 AND B.SOLDID &gt; B.SOLDIC THEN B.SOLDID - B.SOLDIC
        WHEN C.TIPCONT=0 THEN B.SOLDID - B.SOLDIC
        ELSE 0
      END AS SOLDID,
      CASE
        WHEN C.TIPCONT=2 AND B.SOLDIC &gt; B.SOLDID THEN B.SOLDIC - B.SOLDID
        WHEN C.TIPCONT=1 THEN B.SOLDIC - B.SOLDID
        ELSE 0
      END AS SOLDIC,
      B.SOLDIIFRS,
      B.SOLDIGRUP,
      B.RULAJPD,
      B.RULAJPC,
      B.RULAJPIFRS,
      B.RULAJPGRUP,
      (B.SOLDID + B.RULAJPD) TOTALCPD,
      (B.SOLDIC + B.RULAJPC) TOTALCPC,
      B.RULAJD,
      B.RULAJC,
      B.RULAJIFRS,
      B.RULAJGRUP,
      (B.RULAJD + B.RULAJPD) RULAJCD,
      (B.RULAJC + B.RULAJPC) RULAJCC,
      (B.RULAJIFRS + B.RULAJPIFRS) RULAJCIFRS,
      (B.RULAJGRUP + B.RULAJPGRUP) RULAJCGRUP,
      B.TOTALCD,
      B.TOTALCC,
      CASE
        WHEN C.TIPCONT=2 AND B.TOTALCD &gt; B.TOTALCC THEN B.TOTALCD - B.TOTALCC
        WHEN C.TIPCONT=0 THEN B.TOTALCD  - B.TOTALCC
        ELSE 0
      END AS SOLDFD,
      CASE
        WHEN C.TIPCONT=2 AND B.TOTALCC &gt; B.TOTALCD THEN B.TOTALCC - B.TOTALCD
        WHEN C.TIPCONT=1 THEN B.TOTALCC - B.TOTALCD
        ELSE 0
      END AS SOLDFC,
      B.SOLDFIFRS,
      B.SOLDFGRUP,
      0 INDEX_SINTETIC,
      0 FRUNZA,
      C.CENTRUCOST,
      C.SIMBCENTRUCOST,
      C.SIMBOLSITFIN,
      B.SIMBPLANP,
      CP.SIMBOL SIMBSINTETIC,
      CP.DEN_CONT DEN_SINTETIC,
      0 CODCONTP,
      0 CODCONTS,
      0 CODCONTT,
      0 SOLDFIFRSD,
      0 SOLDFIFRSC, 
      0 RULAJIFRSD, 
      0 RULAJIFRSC, 
      0 RULAJPIFRSD,
      0 RULAJPIFRSC,
      0 SOLDIIFRSD, 
      0 SOLDIIFRSC 
    FROM CONTURI C
         INNER JOIN BALANTA B ON B.CODCONT = C.CODCONT
         LEFT JOIN CONTURI CP ON C.CODPARINTE = CP.CODCONT
    WHERE C.FARA_FII = 1 AND C.VIZIBILBALANTA = 1
    ORDER BY CLASA, SIMBSINTETIC
  ) LOOP

    IF v_rec.codsintetic &lt;&gt; v_prev_codsintetic THEN
       IF p_IDX_SINTETIC &gt; 0 THEN
         Insert_RecTotal(tmpName);
       END IF;
       p_IDX_SINTETIC := p_IDX_SINTETIC + 1;
       v_prev_codsintetic := v_rec.codsintetic;
    END IF;

    Fill_RecTotals(v_rec);
    Insert_Rec(v_rec,tmpName);
  END LOOP;
  Insert_RecTotal(tmpName);
  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2) IS
BEGIN
  g_tmpTABLE := tmpName;
  p_IDX_SINTETIC := 0;

  PROCESSBALANTA(tmpName);
END;

PROCEDURE DEBUG IS
BEGIN
  SETPARAMS(0,0,1,1,1,1,3,2013,0);
  PKG_JURNAL.MAKE_RULAJE_SELECTIV(2013, 3, 2);
  PROCESSLIST(&apos;tmp_list_balanta_secfp&apos;);
END;

end pkg_list_base_bal_ifrs;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A677A12CE1165D358B56584C86700F7D570F901F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_bcar IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
  sFiltru VARCHAR2(500);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;BCAR B, INTRARI I, NARTOBJ O, NPART P, NGEST G, NSUBUNIT S, NSUBUNIT SDOC, NPARTTR D, NAGENDA SED, NLOCALIT LOC, NJUDET JUD, NPARTCODFISC NPCF, CONTRACT1 CONTR1, CONTRACT CONTR&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;     , &apos;BEXT&apos; , &apos;BEXT.CODBCAR = B.CODBCAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;  , &apos;OEXT&apos; , &apos;OEXT.CODOBIECT  = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;  , &apos;OATR&apos; , &apos;OATR.CODOBIECT  = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACTEXT&apos; , &apos;CEXT&apos; , &apos;CEXT.CODCONTRACT = CONTR.CODCONTRACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACTEXT1&apos;, &apos;C1EXT&apos;, &apos;C1EXT.CODCONTRACT1 = CONTR1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CANTAR&apos;      , &apos;CT&apos;   , &apos;CT.CODCANTAR = B.CODCANTAROUT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CANTAR&apos;      , &apos;CB&apos;   , &apos;CB.CODCANTAR = B.CODCANTARIN&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTB&apos;      , &apos;CONTB&apos;, &apos;P.CODPART = CONTB.CODPART AND CONTB.IMPLICIT = 1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NBANK&apos;       , &apos;BANCA&apos;, &apos;BANCA.CODBANK = CONTB.CODBANK&apos;);

  sFiltru := &apos;&apos;;
  if pkg_list_alegperioada.optiunea1 then
    sFiltru := &apos; and coalesce(b.coddoc1,0) = 0 &apos;;
  end if;
  if not pkg_list_alegperioada.optiunea2 then
    sFiltru := sFiltru||&apos;  AND b.operat = 1 &apos;;
  end if;

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, BCAR_PREFIX, BCAR_NR, BCAR_DATA,
    PARTENER,
    DELEGAT, MIJLTRANSP, NRTRANSP, DOCINSOTIRE,
    SED_DEN, SED_LOC, SED_JUD, SED_ADR,
    ARTICOL, CANT_BRUTA, TARA, CANT_NETA, CANT_UTILA, CANT_UTILA_STAS, PRET_ACHIZ, PRET_USCARE,
    SEMN_STOC,
    DataDocPrel, NrDocPrel, SerieDocPrel, TipDocPrel, Subunit,
    TipBCAR,
    SUmiditate, SStraine, SIncoltit, SHectolitrica, SGluten,
    SFuzaritate, SCadere, SDeformare, SSticlozitate, SSparturi,
    AUmiditate, AStraine, AIncoltit, AHectolitrica, AGluten,
    AFuzaritate, ACadere, ADeformare, ASticlozitate, ASparturi,
    DUmiditate, DStraine,
    DIncoltit, DHectolitrica, DGluten,
    DFuzaritate, DCadere, DDeformare, DSticlozitate, DSparturi,
    nrcontr, datacontr, obscontr,
    StocU, StocB, StocN,
    X_Judet, X_CodGest, X_CodSubunit, X_CodClasaP, OPERAT&apos;||
    gUserFields||&apos;)
  SELECT
    b.codbcar NAV_CodDoc, 67 NAV_TipDoc, b.prefixdoc, b.nrdoc, b.datadoc,
    CASE WHEN B.TipBCAR IN (0, 2) THEN p.den_part WHEN B.TipBCAR IN (1, 5, 6) THEN g.den_gest WHEN B.TipBCAR IN (3, 4) THEN s.den_subunit END PARTENER,
    d.delegat, d.mijltransp, d.nrtransp, b.prefixavizin||b.nravizin||&apos;&apos;/&apos;&apos;||to_char(b.dataavizin,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOCINSOTIRE,
    sed.obs, loc.den_localit, jud.den_judet, GetAdresa(sed.sector, sed.strada, sed.nr1, sed.nr2, sed.bloc, sed.scara, sed.etaj, sed.apart, sed.codpostal) SED_ADR,
    o.denumire, Decode(b.retur,1,-1,1)*b.brutkg, b.tara, Decode(b.retur,1,-1,1)*b.netkg, Decode(b.retur,1,-1,1)*b.utilkg, Decode(b.retur,1,-1,1)*b.utilstaskg, b.pretachiz, b.pretuscare,
    CASE WHEN b.tipbcar IN (2,4,5) THEN -1 ELSE 1 END SEMN_STOC,
    Coalesce(i.datadoc, ie.datadoc, tr.datadoc) DataDocPrel, Coalesce(i.nrdoc, ie.nrdoc, tr.nrdoc) NrDocPrel, Coalesce(i.prefixdoc, ie.prefixdoc, tr.prefixdoc) SerieDocPrel, tm.numeext TipDocPrel, sdoc.den_subunit,
    Decode(b.tipbcar,0,&apos;&apos;Bon de la furnizor&apos;&apos;,1,&apos;&apos;Bon din productie&apos;&apos;,2,&apos;&apos;Bon catre client&apos;&apos;,3,&apos;&apos;Bon de la subunitati&apos;&apos;,4,&apos;&apos;Bon catre subunitati&apos;&apos;,5,&apos;&apos;Consum intern&apos;&apos;,6,&apos;&apos;Transfer intre gestiuni&apos;&apos;,&apos;&apos;.NEDEFINIT.&apos;&apos;) TipBCAR,
    b.isumiditate, b.isstraine, b.isincoltit, b.ishectolitrica, b.isgluten,
    b.isfuzaritate, b.iscadere, b.isdeformare, b.issticlozitate, b.issparturi,
    b.iaumiditate, b.iastraine, b.iaincoltit, b.iahectolitrica, b.iagluten,
    b.iafuzaritate, b.iacadere, b.iadeformare, b.iasticlozitate, b.iasparturi,
    CASE WHEN b.isumiditate &gt; b.iaumiditate THEN 0 ELSE b.isumiditate - b.iaumiditate END DUmiditate, CASE WHEN b.isstraine &gt; b.iastraine THEN 0 ELSE b.isstraine - b.iastraine END DStraine,
    b.isincoltit - b.iaincoltit DIncoltit, CASE WHEN b.ishectolitrica &lt; b.iahectolitrica THEN 0 ELSE b.ishectolitrica - b.iahectolitrica END DHectolitrica, b.isgluten - b.iagluten DGluten,
    b.isfuzaritate - b.iafuzaritate DFuzaritate, b.iscadere - b.iacadere DCadere, b.isdeformare - b.iadeformare DDeformare, b.issticlozitate - b.iasticlozitate DSticlozitate,
    CASE WHEN b.issparturi &gt; b.iasparturi THEN 0 ELSE b.issparturi - b.iasparturi END DSparturi,
    contr.nrdoc, contr.datadoc, contr.obs,
    CASE WHEN NOT b.tipbcar IN (2,4,5) THEN Decode(b.retur,1,-1,1)*Coalesce(b.utilkg,0) ELSE (-1)*Decode(b.retur,1,-1,1)*Coalesce(b.utilkg,0) END StocU,
    CASE WHEN NOT b.tipbcar IN (2,4,5) THEN Decode(b.retur,1,-1,1)*Coalesce(b.brutkg,0) ELSE (-1)*Decode(b.retur,1,-1,1)*Coalesce(b.brutkg,0) END StocB,
    CASE WHEN NOT b.tipbcar IN (2,4,5) THEN Decode(b.retur,1,-1,1)*Coalesce(b.netkg,0)  ELSE (-1)*Decode(b.retur,1,-1,1)*Coalesce(b.netkg,0)  END StocN,
    jud.simbauto, g.codgest, sdoc.codsubunit, p.codclasa,CASE WHEN B.OPERAT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END &apos;||
    gUserAlias||&apos;
  FROM bcar b
    LEFT JOIN tmp_machete  tm     ON tm.codmacheta       = b.tipdoc
    LEFT JOIN intrari1     i1     ON i1.codintr1         = b.coddoc1
    LEFT JOIN intrari      i      ON  i1.codintr         = i.codintr and b.tipdoc = i.tipdoc
    LEFT JOIN iesiri1      ie1    ON ie1.codies1         = b.coddoc1
    LEFT JOIN iesiri       ie     ON ie1.codies          = ie.codies and b.tipdoc = ie.tipdoc
    LEFT JOIN transf1      tr1    ON tr1.codtransf1      = b.coddoc1
    LEFT JOIN transf       tr     ON tr.codtransf        = tr1.codtransf and b.tipdoc = tr.tipdoc
    LEFT JOIN nartobj      o      ON o.codobiect         = b.codobiect
    LEFT JOIN npart        p      ON p.codpart           = b.codpartener AND B.TipBCAR IN (0, 2)
    LEFT JOIN ngest        g      ON g.codgest           = b.codpartener AND B.TipBCAR IN (1, 5, 6)
    LEFT JOIN nsubunit     s      ON s.codsubunit        = b.codpartener AND B.TipBCAR IN (3, 4)
    LEFT JOIN nparttr      d      ON d.codparttr         = b.coddelegat
    LEFT JOIN nagenda      sedp   ON sedp.codagenda      = b.codsediu AND B.TipBCAR IN (0, 2)
    LEFT JOIN nagenda      sedg   ON sedg.codgest        = b.codpartener AND B.TipBCAR IN (1, 5, 6)
    LEFT JOIN nagenda      seds   ON seds.codsubunit     = b.codpartener AND B.TipBCAR IN (3, 4)
    LEFT JOIN nagenda      sed    ON sed.codagenda       = COALESCE(sedp.codagenda, sedg.codagenda, seds.codagenda)
    LEFT JOIN nlocalit     loc    ON loc.codlocalit      = sed.codlocalit
    LEFT JOIN njudet       jud    ON jud.codjudet        = loc.codjudet
    LEFT JOIN nsubunit     sdoc   ON sdoc.codsubunit     = b.codsubunitate
    LEFT JOIN npartcodfisc npcf   ON npcf.codpart        = p.codpart AND npcf.principal = 1
    LEFT JOIN contract1    contr1 ON contr1.codcontract1 = b.codcontract1
    LEFT JOIN contract     contr  ON contr.codcontract   = contr1.codcontract&apos;||
    gSuplJoins||&apos;
  WHERE b.datadoc &apos;||pkg_list_alegPerioada.getPerioada||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;B&apos;,&apos;CODSUBUNITATE&apos;)||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_BCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BORDAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E09BC4A7970A773D3AB90B88272CE9515CC5BBE2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BORDAUTO is

vCodAuto number(20);
gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE SETPARAMS(pCodAuto IN NUMBER) IS
BEGIN
  vCodAuto := pCodAuto;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      OBJ.DENUMIRE,
      A.NRINV,
      A.NRINREG,
      SOF.NUME||&apos; &apos;||SOF.PRENUME SOFER,
      A.KMPORNIRE,
      CASE WHEN A.TIP = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END TRACTAT,
      to_char(DATAINREG,&apos;dd.mm.yyyy&apos;) DATAINREG,
      MK.MARCA,
      MD.MODEL,
      A.ANF,
      A.SERIEC,
      A.CULOARE,
      A.LUNG,
      A.LAT,
      A.INALT,
      A.TIPMOTOR,
      A.SERIEM,
      A.CILINDREE,
      A.PUTERE,
      A.CMM,
      A.CMU,
      A.CME,
      case A.TIPINCARC when 1 then &apos;Marfa&apos; when 2 then &apos;Persoane&apos; else &apos;Mixta&apos; end TipIncarc,
      A.GREUTATE,
      A.MASAM,
      A.MASAU,
      A.MASAURDF,
      A.MASAURFDF,
      A.LOCT,
      A.LOCF,
      A.LOCS,
      A.LOCP,
      A.ANVRECOMF,
      A.ANVRECOMS,
      A.ANVOPT1F,
      A.ANVOPT1S,
      A.ANVOPT2F,
      A.ANVOPT2S,
      A.KG,
      A.KGR,
      GRA.GRUPA GRUPAUTO,
      REMA.TIPURIREMORCI TIPREM,
      INST.INSTALATIE INSTSP,
      AE.ELEMENT AER,
      A.REZERVOR,
      A.VOLUMU,
      A.CULOAREC,
      A.SURSAE,
      CASE WHEN A.EXTERN = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END EXTERN,
      P.DEN_PART PARTENER,
      CASE A.INACTIV
        WHEN 0 THEN &apos;Activ&apos;
        WHEN 2 THEN &apos;Conservare&apos;
        WHEN 3 THEN &apos;Dauna totala&apos;
        WHEN 4 THEN &apos;La vanzare&apos;
        WHEN 1 THEN &apos;Vandut&apos;
        WHEN 5 THEN &apos;Radiat&apos;
      END INACTIV,
      GE.DEN_GEST GESTEXPL,
      PL.DEN_PART PARTLEAS,
      A.NRCONTR,
      MON.SIMBOL MONEDA,
      A.RATALEAS,
      A.RATARCA,
      A.RATACASCO,
      to_char(A.DATAACHIZ,&apos;dd.mm.yyyy&apos;) DATAACHIZ,
      to_char(A.DATAENDLEAS,&apos;dd.mm.yyyy&apos;) DATAENDLEAS,
      PU.DEN_PART PARTUTILIZ,
      SOF.NUME||&apos; &apos;||SOF.PRENUME PERSUTILIZ,
      A.OBS,
      A.TIPULEI,
      CASE WHEN A.TIPVEHICUL = 1 THEN &apos;Autoturism&apos; ELSE &apos;Utilitar&apos; end tipvehicul,
      DE.DEN_PART DEALER,
      A.LIMITAKM,
      A.DOTARI,
      A.CODRADIO,
      CASE A.TRANSMISIE WHEN 1 THEN &apos;Manuala&apos; ELSE &apos;Automata&apos; END TRANSMISIE,
      CASE A.TRACTIUNE WHEN 1 THEN &apos;Fata&apos; WHEN 2 THEN &apos;Spate&apos; WHEN 3 THEN &apos;4x4&apos; END TRACTIUNE,
      CASE WHEN A.GPS = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END GPS,
      CASE WHEN A.GPL = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END GPL
    FROM NPARCAUT A
         LEFT JOIN NARTOBJ OBJ ON A.CODART = OBJ.CODOBIECT
         LEFT JOIN NPERS SOF ON SOF.CODPERS = A.SOFER
         LEFT JOIN NMARCIAUTO MK ON MK.CODMARCIAUTO = A.MARCA
         LEFT JOIN NMODELEAUTO MD ON MD.CODMODELEAUTO = A.MODEL
         LEFT JOIN NGRUPEAUTO GRA ON GRA.CODGRUPEAUTO = A.GRUPAUTO
         LEFT JOIN NREMAUTO REMA ON REMA.CODREMAUTO = A.TIPREM
         LEFT JOIN NINSTAUTO INST ON INST.CODINSTAUTO = A.INSTSP
         LEFT JOIN NELEMAEROAUTO AE ON AE.CODELEMAEROAUTO = A.AER
         LEFT JOIN NPART P ON P.CODPART = A.PARTENER
         LEFT JOIN NGEST GE ON GE.CODGEST = A.CODGEST
         LEFT JOIN NPART PL ON PL.CODPART = A.PARTLEAS
         LEFT JOIN NMONEDE MON ON MON.CODMONEDA = A.MONEDA
         LEFT JOIN NPART PU ON PU.CODPART = A.PARTUTILIZ
         LEFT JOIN NPERS SOFU ON SOFU.CODPERS = A.PERSUTILIZ
         LEFT JOIN NPART DE ON DE.CODPART = A.CODDEALER
    WHERE CODNPARCAUT = vCodAuto
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Articol&apos;, v_rec.DENUMIRE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr.inventar&apos;, v_rec.NRINV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr.inmatriculare&apos;, v_rec.NRINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sofer intern&apos;, v_rec.SOFER);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Km. pornire&apos;, v_rec.KMPORNIRE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tractat&apos;, v_rec.TRACTAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data inmatriculare&apos;, v_rec.DATAINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Marca&apos;, v_rec.MARCA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Model&apos;, v_rec.MODEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;An fabricatie&apos;, v_rec.ANF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serie caroserie&apos;, v_rec.SERIEC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Lungime&apos;, v_rec.LUNG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Latime&apos;, v_rec.LAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Inaltime&apos;, v_rec.INALT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip motor&apos;, v_rec.TIPMOTOR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serie motor&apos;, v_rec.SERIEM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cilindree&apos;, v_rec.CILINDREE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Putere&apos;, v_rec.PUTERE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Consum mediu - Mixt&apos;, v_rec.CMM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Consum mediu - Urban&apos;, v_rec.CMU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Consum mediu - Extraurban&apos;, v_rec.CME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip incarcatura&apos;, v_rec.TipIncarc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Masa proprie&apos;, v_rec.GREUTATE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Masa maxima&apos;, v_rec.MASAM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Masa utila&apos;, v_rec.MASAU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Masa (remorcabila) cu disp.franare&apos;, v_rec.MASAURDF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Masa (remorcabila) fara disp.franare&apos;, v_rec.MASAURFDF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Locuri - total&apos;, v_rec.LOCT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Locuri - in fata&apos;, v_rec.LOCF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Locuri - pe scaune&apos;, v_rec.LOCS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope recomandate fata&apos;, v_rec.ANVRECOMF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope recomandate spate&apos;, v_rec.ANVRECOMS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope vara fata&apos;, v_rec.ANVOPT1F);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope vara spate&apos;, v_rec.ANVOPT1S);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope iarna fata&apos;, v_rec.ANVOPT2F);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Anevelope iarna spate&apos;, v_rec.ANVOPT2S);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Coeficient corectie consum mediu pt.sarcina trasportata&apos;, v_rec.KG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Coeficient corectie consum mediu pt.sarcina trasportata - tractare remorci&apos;, v_rec.KGR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Grupa de automobile(spor circulatie in localitatile urbane)&apos;, v_rec.GRUPAUTO);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip remorca&apos;, v_rec.TIPREM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Instalatii speciale&apos;, v_rec.INSTSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Elemente cu influenta aerodinamica&apos;, v_rec.AER);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Capacitate rezervor&apos;, v_rec.REZERVOR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Volum util&apos;, v_rec.VOLUMU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Culoare caroserie&apos;, v_rec.CULOAREC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sursa energie&apos;, v_rec.SURSAE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Din parcul partenerilor&apos;, v_rec.EXTERN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partner&apos;, v_rec.PARTENER);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Stare&apos;, v_rec.INACTIV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune exploatare&apos;, v_rec.GESTEXPL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Furnizor leasing&apos;, v_rec.PARTLEAS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr.contract leasing&apos;, v_rec.NRCONTR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;, v_rec.MONEDA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Rata leasing&apos;, v_rec.RATALEAS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Rata RCA&apos;, v_rec.RATARCA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Rata CASCO&apos;, v_rec.RATACASCO);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data achizitie&apos;, v_rec.DATAACHIZ);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Final leasing&apos;, v_rec.DATAENDLEAS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilizator extern&apos;, v_rec.PARTUTILIZ);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;, v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip ulei&apos;, v_rec.TIPULEI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip vechicul&apos;, v_rec.tipvehicul);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Dealer&apos;, v_rec.DEALER);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Limita km.&apos;, v_rec.LIMITAKM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Dotari&apos;, v_rec.DOTARI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod radio&apos;, v_rec.CODRADIO);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Transmisie&apos;, v_rec.TRANSMISIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tractiune&apos;, v_rec.TRACTIUNE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GPS&apos;, v_rec.GPS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GPL&apos;, v_rec.GPL);
    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      DataBord,
      KmBord,  
      Sofer,   
      An,      
      Luna,    
      Obs&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    P0.DataBord,
    P0.KmBord,
    S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME Sofer,
    P0.An,
    P0.Luna,
    P0.Obs &apos;||gUserAlias||&apos;
  FROM NPARC0 P0
       LEFT JOIN NPERS S ON P0.CODPERS = S.CODPERS &apos;||gSuplJoins||&apos;
  WHERE P0.CODNPARCAUT = &apos;||vCodAuto;

  LIST_EXECUTE_IMMEDIATE(sInsert||sselect, aListID, aListVer);

  processparams(tmpName);
  COMMIT;
END;
  
end PKG_LIST_BASE_BORDAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1458DDDD8279117FAC051BACAD00F38D2F4D316E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BORDEROUABON IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols   := &apos;IESIRI I, NMONEDE MON, NPART P, NPERS AG, DOCCARNETE DC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
   &apos;INSERT INTO &apos;||tmpName||&apos;
     (NrContr, NrFact, ValDoc, TvaDoc, Moneda, Carnet, Part,
      Agent, Operat, Scadenta, Majorari &apos;||gUserFields||&apos;)
    WITH SCAD AS (
      SELECT C2.TipDoc, C2.CodDoc, MAX(O.TERMEN) SCADENTA, MAX(O.MAJORARI) MAJ
      FROM TMP_MANEVRA_LISTE TMP
           INNER JOIN CONTRACT2  C2   ON C2.CodContract2 = TMP.Valoare
           INNER JOIN GENERAL    G    ON G.TIPDOC = C2.TipDoc AND G.CodDoc = C2.CodDoc
           INNER JOIN OBLIGPIF   O    ON O.CODGENERAL = G.CODGENERAL
      GROUP BY C2.TipDoc, C2.CodDoc
    )
    SELECT C.NrDoc, I.NrDoc, I.ValDoc, I.TvaDoc, MON.Simbol, DC.Denumire, P.Den_Part,
           AG.Nume||&apos;&apos; &apos;&apos;||Ag.Prenume Den_Agent, Decode(I.Operat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), S.Scadenta, S.Maj &apos;||gUserAlias||&apos;
    FROM TMP_MANEVRA_LISTE TMP
      INNER JOIN CONTRACT2  C2   ON C2.CodContract2 = TMP.Valoare
      INNER JOIN CONTRACT   C    ON C.CodContract   = C2.CodContract
      INNER JOIN IESIRI     I    ON I.CodIes        = C2.CodDoc AND I.TipDoc = C2.TipDoc
      INNER JOIN NMONEDE    MON  ON MON.CodMoneda   = I.Moneda
      INNER JOIN NPART      P    ON P.CodPart       = C.Partener
      LEFT  JOIN DOCCARNETE DC   ON DC.CodCarnet    = I.CarnetDoc
      LEFT  JOIN NPERS      AG   ON AG.CodPers      = C.Agent
      LEFT  JOIN SCAD       S    ON S.CodDoc        = C2.CodDoc AND S.TipDoc = C2.TipDoc&apos;||
      gSuplJoins||&apos;
    WHERE TMP.FILTRU = &apos;&apos;CODCONTRACT2&apos;&apos; &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BORDEROUABON;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C26B3A9D46076E06A642F826102E20F8BF66FC7E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BORDEROUAMB IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;COMANDA C, IESIRI I, TRANSF T, NMONEDE MON, NPART P, NPERS AG, DOCCARNETE DC, NPARTTR TR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NrCom, NrIes, ValDoc, TvaDoc, Moneda, Carnet,
    Part,
    Agent, Delegat &apos;||gUserFields||&apos;)
  SELECT
    C.NrDoc, Nvl(T.NrDoc,I.NrDoc), Nvl(T.ValDoc,I.ValDoc), Nvl(T.TvaDoc,I.TvaDoc), MON.Simbol, DC.Denumire,
    CASE
      WHEN Nvl(C.CodGest,0) &lt;&gt; 0 THEN G.Den_Gest
      WHEN Nvl(S.CodSubunit,0) &lt;&gt; 0 THEN S.Den_Subunit
      ELSE P.Den_Part
    END,
    AG.Nume||&apos;&apos; &apos;&apos;||Ag.Prenume Den_Agent, TR.Delegat &apos;||gUserAlias||&apos;
  FROM TMP_MANEVRA_LISTE TMP
    INNER JOIN COMANDA    C   ON C.CodComanda  = TMP.Valoare
    LEFT  JOIN IESIRI     I   ON I.CodIes      = TMP.Valoare1 AND Nvl(C.CodGest,0) = 0
    LEFT  JOIN TRANSF     T   ON T.CodTransf   = TMP.Valoare1 AND Nvl(C.CodGest,0) &lt;&gt; 0
    LEFT  JOIN NMONEDE    MON ON MON.CodMoneda = Nvl(I.Moneda,0)
    LEFT  JOIN NPART      P   ON P.CodPart     = C.Partener
    LEFT  JOIN NGEST      G   ON G.CodGest     = C.CodGest
    LEFT  JOIN NSUBUNIT   S   ON S.CodSubunit  = C.SubunitSursa
    LEFT  JOIN DOCCARNETE DC  ON DC.CodCarnet  = NVL(I.CarnetDoc,T.CarnetDoc)
    LEFT  JOIN NPERS      AG  ON AG.CodPers    = C.Agent
    LEFT  JOIN NPARTTR    TR  ON TR.CodPartTR  = C.Delegat&apos;||
    gSuplJoins||&apos;
  WHERE TMP.FILTRU = &apos;&apos;CUSTAMB&apos;&apos; &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BORDEROUAMB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>098BDC7A170DBA977A835B505920F64A93C32C51</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BORDEROUCOM IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;COMANDA C, IESIRI I, NMONEDE MON, NPART P, NPERS AG, DOCCARNETE DC, NPARTTR TR&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NrCom, PrefixDoc, NrDoc, DataDoc,
    Doc,
    ValDoc, TvaDoc,
    Moneda, Carnet,
    Part,
    Agent, Delegat &apos;||gUserFields||&apos;)
  SELECT
    C.NrDoc, NVL(I.PrefixDoc, T.PrefixDoc), NVL(I.NrDoc, T.NrDoc),NVL(I.DataDoc, T.DataDoc),
    NVL(I.PrefixDoc, T.PrefixDoc)||NVL(I.NrDoc, T.NrDoc)||&apos;&apos;/&apos;&apos;||NVL(I.DataDoc, T.DataDoc),
    NVL(I.ValDoc,T.ValDoc), NVL(I.TvaDoc,T.TvaDoc),
    MON.Simbol, DC.Denumire,
    COALESCE(P.Den_Part,G.Den_Gest, S.Den_Subunit),
    TMP.DenAgent, TR.Delegat &apos;||gUserAlias||&apos;
  FROM TMP_ONORCOM_COMENZI TMP
    INNER JOIN COMANDA    C   ON C.CodComanda  = TMP.CODCOMANDA
    LEFT  JOIN IESIRI     I   ON I.CodIes      = TMP.CODDOC AND I.TIPDOC = TMP.TIPDOC
    LEFT  JOIN TRANSF     T   ON T.CodTransf   = TMP.CODDOC AND T.TIPDOC = TMP.TIPDOC
    LEFT  JOIN NMONEDE    MON ON MON.CodMoneda = I.Moneda
    LEFT  JOIN NPART      P   ON P.CodPart     = C.Partener AND C.TIPDOC IN (19,20)
    LEFT  JOIN NSUBUNIT   S   ON S.CodSubunit  = C.Partener AND C.TIPDOC = 23
    LEFT  JOIN NGEST      G   ON G.CodGest     = C.Partener AND C.TIPDOC = 12
    LEFT  JOIN DOCCARNETE DC  ON DC.CodCarnet  = C.CarnetDoc
    LEFT  JOIN NPARTTR    TR  ON TR.CodPartTR  = C.Delegat&apos;||
    gSuplJoins||&apos;
  WHERE TMP.GDI = 1 &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BORDEROUCOM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BORDEROUIESBULK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D7B499D6E93ABFD0CC4A7148C529E1D50716ABB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_borderouiesbulk IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;IESIRI I, IESIRI1 I1, NMONEDE MON, NPART P, NPARTCODFISC FISC, NARTOBJ NAO, NUM1 UM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    PrefixDoc, NrDoc, DataDoc, ValDoc, TvaDoc, Moneda, Part, Art, 
    DEN_UM1, Cant, PU, PIES &apos;||gUserFields||&apos;)
  SELECT
    I.PrefixDoc, I.NrDoc, I.DataDoc, I.ValDoc, I.TvaDoc, MON.Simbol, P.Den_Part, NAO.Denumire,
    UM.DEN_UM1, I1.CANT/UM.PARITATE CANT, I1.PU * UM.PARITATE PU, I1.PretOrig*Coalesce(I1.CoefDiscmaj,1)*UM.PARITATE PIES&apos;||gUserAlias||&apos;
  FROM TMP_MANEVRA TMP
    LEFT JOIN IESIRI I ON I.CodIes = TMP.CODUNIC
    LEFT JOIN IESIRI1 I1 ON I1.CODIES = TMP.CODUNIC
    LEFT JOIN NMONEDE MON ON MON.CodMoneda = I.Moneda
    LEFT JOIN NPART P ON P.CodPart = I.Partener
    LEFT JOIN NPARTCODFISC FISC ON FISC.CODPART = I.PARTENER AND FISC.PRINCIPAL = 1
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = I1.CODOBIECT
    LEFT JOIN NUM1 UM ON UM.CODUM1 = I1.UMSEC&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_BORDEROUIESBULK;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_BUGETLUNAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B20CF1C5BB29477D6AA4816662037B8F51EECDEA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_BUGETLUNAR is

gUserFields   VARCHAR2(2500);
gUserAlias    VARCHAR2(2500);
gNullAlias    VARCHAR2(2500);
gSuplCols     VARCHAR2(2500);
gSuplJoins    VARCHAR2(5000);
vCodBugetProd NUMBER(20);

PROCEDURE setParams(aCodBugetProd IN NUMBER) IS
BEGIN
  vCodBugetProd := aCodBugetProd;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  FOR v_rec IN (
    SELECT
      B.SAPTAMANA, B.ANIMPORT, B.OBS,
      CASE
        WHEN B.ANULAT = 1 THEN &apos;DA&apos;
        ELSE &apos;NU&apos;
      END ANULAT,
      CASE
        WHEN B.OPERAT = 1 THEN &apos;DA&apos;
        ELSE &apos;NU&apos;
      END OPERAT,
      CASE
        WHEN B.BLOCAT = 1 THEN &apos;DA&apos;
        ELSE &apos;NU&apos;
      END BLOCAT,
      S.DEN_SUBUNIT
    FROM BUGETPROD B
         LEFT JOIN NSUBUNIT S ON B.SUBUNITATEA = S.CODSUBUNIT
    WHERE B.CodBugetProd = vCodBugetProd
    ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;SAPTAMANA&apos;,    v_rec.Saptamana);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AN&apos; ,          v_rec.AnImport);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANULAT&apos;,       v_rec.Anulat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OPERAT&apos;,       v_rec.Operat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BLOCAT&apos;,       v_rec.Blocat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATEA&apos;,  v_rec.Den_Subunit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBS&apos;,          v_rec.Obs);
    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
     Element,
     Ianuarie,
     Februarie,
     Martie,
     Aprilie,
     Mai,
     Iunie,
     Iulie,
     August,
     Septembrie,
     Octombrie,
     Noiembrie,
     Decembrie,
     Tip &apos;||gUserFields||&apos;)
  SELECT
     E.ELEMENT,
     V.L1,
     V.L2,
     V.L3,
     V.L4,
     V.L5,
     V.L6,
     V.L7,
     V.L8,
     V.L9,
     V.L10,
     V.L11,
     V.L12,
     &apos;&apos;VENIT&apos;&apos; &apos;||gUserAlias||&apos;
  FROM BUGETVL V
       INNER JOIN ELEMBUGET E ON V.CODELEMBUGET = E.CODELEMBUGET &apos;||gSuplJoins||&apos;
  WHERE V.CODBUGETPROD = &apos;||vCodBugetProd||&apos;
  UNION ALL
  SELECT
    E.ELEMENT,
    C.L1,
    C.L2,
    C.L3,
    C.L4,
    C.L5,
    C.L6,
    C.L7,
    C.L8,
    C.L9,
    C.L10,
    C.L11,
    C.L12,
    &apos;&apos;CHELTUIALA&apos;&apos; &apos;||gUserAlias||&apos;
  FROM BUGETCL C
       INNER JOIN ELEMBUGET E ON C.CODELEMBUGET = E.CODELEMBUGET &apos;||gSuplJoins||&apos;
  WHERE C.CODBUGETPROD = &apos;||vCodBugetProd;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  PROCESSPARAMS;

  COMMIT;
END;

end PKG_LIST_BASE_BUGETLUNAR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CAMPANII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E778157A51A3FBED5F0F273F606689696D1C4B31</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_campanii IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(25000);

FUNCTION  Costuri (pCodCampanie NUMBER) RETURN NUMBER IS
  vCosturi NUMBER;
BEGIN
  SELECT
    SUM(
      CASE
        WHEN CC.TipDoc = 0 THEN CC.ValDoc
        WHEN CC.TipDoc IN (1, 2, 3, 4, 5, 6, 7) THEN (SELECT SUM(I1.PretOrig * I1.Cant * NVL(I1.CoefDiscMaj, 1)) FROM Intrari1 I1 WHERE I1.CodIntr = CC.CodDoc)
        WHEN CC.TipDoc = 24 THEN (SELECT SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = CC.CodDoc)
        WHEN CC.TipDoc IN (29, 30, 31, 33) THEN (SELECT case WHEN T1.TipTranz = 0 THEN (T1.ValDoc + nvl(T1.Comision, 0)) else -(T1.ValDoc + nvl(T1.Comision, 0)) end FROM Trezor1 T1 WHERE T1.CodTrezor1 = CC.CodDoc)
        WHEN CC.TipDoc = 35 THEN (SELECT Sum(Nc1.Valoare) FROM Nc1 WHERE NC1.CodNc = CC.CodDoc)
        ELSE 0
      END
    )
  INTO vCosturi
  FROM CAMPANIICOST CC
  WHERE CC.CODCAMPANIE = pCodCampanie;

  RETURN Coalesce(vCosturi,0);
END;

FUNCTION  Venituri(pCodCampanie NUMBER) RETURN NUMBER IS
  vVenituri NUMBER;
BEGIN
  SELECT
    SUM(
      CASE
        WHEN CV.TipDoc = 0 THEN CV.ValDoc
        WHEN CV.TipDoc = 18 THEN (SELECT Nvl(SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)),0) FROM Comanda1 C1 LEFT JOIN IesLink IL ON IL.CodLinieComanda = C1.Codcomanda1 LEFT JOIN Iesiri1 I1 ON I1.CodIes1 = IL.CodIes1 WHERE C1.CodComanda = CV.CodDoc)
        WHEN CV.TipDoc IN (19, 26) THEN (SELECT SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = CV.CodDoc)
        WHEN CV.TipDoc = 35 THEN 0
        ELSE 0
      END
    )
  INTO vVenituri
  FROM CAMPANIIVENIT CV
  WHERE CV.CODCAMPANIE = pCodCampanie;

  RETURN Coalesce(vVenituri,0);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;CAMPANII C, NMONEDE M, NPARTTR RESP&apos;;
  IF PKG_LIST_SELECTLUNAAN.optiunea1 THEN
    gSuplCols := gSuplCols ||&apos;, INTRARI DI, IESIRI DE, TREZOR1 DT1, TREZOR DT, COMANDA DC, NC DNC, NPART NP, NGEST NG&apos;;
  END IF;

  pkg_list_struct.StartSuplCols;
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTLUNAAN.optiunea1 THEN
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      codcampanie, dencampanie, obiectiv, target, datainit, datafin, Den_Moneda, Responsabil, Costuri, Venituri,
      NAV_CodDoc, NAV_TipDoc, PREFIXDOC, NrDoc, DataDoc, VALDOC, Partener, TIP, IndexLocal&apos;||gUserFields||&apos;)&apos;;

    sSelect := &apos;
    WITH DOCS AS (
      SELECT CV.CODCAMPANIE, CV.CODDOC, CV.TIPDOC, CV.INDEXLOCAL, CV.PrefixDoc, CV.NrDoc, CV.DataDoc, CV.CodPart, CV.ValDoc, &apos;&apos;VENITURI&apos;&apos; as TIP
      FROM CAMPANIIVENIT CV INNER JOIN CAMPANII C ON CV.CODCAMPANIE = C.CODCAMPANIE&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;CODSUBUNITATE&apos;,&apos;
      WHERE&apos;)||&apos;
      UNION ALL
      SELECT CC.CODCAMPANIE, CC.CODDOC, CC.TIPDOC, CC.INDEXLOCAL, CC.PrefixDoc, CC.NrDoc, CC.DataDoc, CC.CodPart, CC.ValDoc, &apos;&apos;COSTURI&apos;&apos; as TIP
      FROM CAMPANIICOST CC INNER JOIN CAMPANII C ON CC.CODCAMPANIE = C.CODCAMPANIE&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;CODSUBUNITATE&apos;,&apos;
      WHERE&apos;)||&apos;
    )
    SELECT
      c.codcampanie, C.dencampanie, C.obiectiv, C.target, C.datainit, C.datafin, M.Den_Moneda, RESP.NUME||&apos;&apos; &apos;&apos;||RESP.PRENUME,
      case when DOCS.TIP = &apos;&apos;COSTURI&apos;&apos; then DOCS.VALDOC end, case when DOCS.TIP = &apos;&apos;VENITURI&apos;&apos; then DOCS.VALDOC end,
      DOCS.CODDOC NAV_CodDoc, DOCS.TIPDOC NAV_TipDoc,
      CASE
        WHEN DOCS.TipDoc IN (29, 30, 31, 33) THEN &apos;&apos;TREZ&apos;&apos;
        WHEN DOCS.TipDoc = 35 THEN &apos;&apos;NC&apos;&apos;
        ELSE COALESCE(DC.PrefixDoc, DE.PrefixDoc, DI.PrefixDoc, DOCS.PrefixDoc)
      END PrefixDoc ,
      COALESCE(To_Char(DNC.NrDoc), To_Char(DT1.NrDoc), To_Char(DC.NrDoc), To_Char(DE.NrDoc), To_Char(DI.NrDoc), DOCS.NrDoc) NrDoc,
      COALESCE(DNC.DataDoc, DT1.DataDoc, DC.DataDoc, DE.DataDoc, DI.DataDoc, DOCS.DataDoc) DataDoc,
      CASE
        WHEN DOCS.TipDoc = 0 THEN DOCS.ValDoc
        WHEN DOCS.TipDoc in (1, 2, 3, 4, 5, 6, 7) THEN (SELECT SUM(I1.PretOrig * I1.Cant * NVL(I1.CoefDiscMaj, 1)) FROM Intrari1 I1 WHERE I1.CodIntr = DOCS.CodDoc)
        WHEN DOCS.TipDoc = 18 THEN (SELECT SUM(C1.PU * C1.CantAcceptat * NVL(C1.CoefDiscMaj, 1)) FROM Comanda1 C1 WHERE C1.CodComanda = DOCS.CodDoc)
        WHEN DOCS.TipDoc IN (19, 24, 26) THEN (SELECT SUM((I1.PretOrig * I1.Cant) * NVL(I1.CoefDiscMaj, 1)) FROM Iesiri1 I1 WHERE I1.CodIes = DOCS.CodDoc)
        WHEN DOCS.TipDoc in (29, 30, 31, 33) THEN CASE WHEN DT1.TipTranz = 0 THEN 1 ELSE -1 END * (DT1.ValDoc + Coalesce(DT1.Comision, 0))
        WHEN DOCS.TipDoc = 35 THEN (SELECT Sum(Nc1.Valoare) FROM Nc1 WHERE NC1.CodNc = DOCS.CodDoc)
      END ValDoc,
      COALESCE(NG.DEN_GEST, NP.DEN_PART, &apos;&apos;...nedefinit...&apos;&apos;) Partener, DOCS.TIP, DOCS.IndexLocal&apos;||gUserAlias||&apos;
    FROM CAMPANII C
      LEFT JOIN DOCS ON C.CODCAMPANIE = DOCS.CODCAMPANIE
      LEFT JOIN NMONEDE M   ON M.CodMoneda = C.CodMoneda
      LEFT JOIN NPERS RESP  ON RESP.CODPERS = C.CodResponsabil
      LEFT JOIN Intrari DI  ON DI.CODINTR = DOCS.CODDOC AND DOCS.TipDoc IN (1, 2, 3, 4, 5, 6, 7)
      LEFT JOIN Iesiri  DE  ON DE.CODIES = DOCS.CODDOC AND DOCS.TipDoc IN (19, 24, 26)
      LEFT JOIN Trezor1 DT1 ON DT1.CodTrezor1 = DOCS.CODDOC AND DOCS.TipDoc IN (29, 30, 31, 33)
      LEFT JOIN Trezor  DT  ON DT.CodTrezor = DT1.CodTrezor
      LEFT JOIN Comanda DC  ON DC.CodComanda = DOCS.CODDOC AND DOCS.TipDoc IN (18)
      LEFT JOIN NC      DNC ON DNC.CodNc = DOCS.CODDOC AND DOCS.TipDoc IN (35)
      LEFT JOIN NPART   NP  ON NP.CODPART = COALESCE(DNC.PART, DT1.CODPART, DC.PARTENER, DI.PARTENER, DE.PARTENER, DOCS.CODPART)
      LEFT JOIN NGEST   NG  ON NG.CODGEST = DE.PARTENER AND DOCS.TipDoc IN (24) &apos;||
      gSuplJoins||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;CODSUBUNITATE&apos;,&apos;
      WHERE&apos;)||&apos; AND (C.DATAINIT BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
                   or C.DATAFIN BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))&apos; ;
  ELSE
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      dencampanie, obiectiv, target, datainit, datafin, Den_Moneda, Responsabil, Costuri, Venituri&apos;||
      gUserFields||&apos;)&apos;;

    sSelect := &apos;
    SELECT
      C.dencampanie, C.obiectiv, C.target, C.datainit, C.datafin, M.Den_Moneda, RESP.NUME||&apos;&apos; &apos;&apos;||RESP.PRENUME,
      PKG_LIST_BASE_CAMPANII.Costuri(C.CODCAMPANIE), PKG_LIST_BASE_CAMPANII.Venituri(C.CODCAMPANIE) &apos;||gUserAlias||&apos;
    FROM CAMPANII C
      LEFT JOIN NMONEDE M ON M.CodMoneda = C.CodMoneda
      LEFT JOIN NPERS RESP ON RESP.CODPERS = C.CodResponsabil&apos;||
      gSuplJoins||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;CODSUBUNITATE&apos;,&apos;
    WHERE&apos;)||&apos; AND (C.DATAINIT BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
                   or C.DATAFIN BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||pkg_list_selectlunaan.DataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_CAMPANII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0550F841AE0BD12FEA48D39F62AD4AED7012546E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CANTAR IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;cantar c, nartobj o, nartobj a1, nartobj a2, nartobj a3, nartobj a4, nartobj a5, nartobj a6, nartobj t1, nartobj t2, &apos;||
               &apos;nart a, nclasea ca, iesiri ies, intrari intr, transf tr, comanda com&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, CLASA, TOTAL_KG, TARA_KG, NET_KG,
    AMB1, AMB1_KG, AMB1_CANT, AMB2, AMB2_KG, AMB2_CANT, AMB3, AMB3_KG, AMB3_CANT, AMB4, AMB4_KG, AMB4_CANT,
    AMB5, AMB5_KG, AMB5_CANT, AMB6, AMB6_KG, AMB6_CANT,
    PALET_KG, TRANSP1, TRANSP1_KG, TRANSP1_CANT, TRANSP2, TRANSP2_KG, TRANSP2_CANT,
    DATACANTAR, ORACANTAR, ANULAT,
    DOC,
    PART &apos;||gUserFields||&apos; )&apos;;

  sSelect := &apos;
	SELECT
    o.denumire, ca.den_clasea, c.total_kg, c.tara_kg, c.net_kg,
    a1.denumire, c.amb1_kg, c.amb1_cant, a2.denumire, c.amb2_kg, c.amb2_cant, a3.denumire, c.amb3_kg, c.amb3_cant, 
    a4.denumire, c.amb4_kg, c.amb4_cant, a5.denumire, c.amb5_kg, c.amb5_cant, a6.denumire, c.amb6_kg, c.amb6_cant,
    c.palet_kg, t1.denumire, c.transp1_kg, c.transp1_cant, t2.denumire, c.transp2_kg, c.transp2_cant,
    trunc(c.datacreare), to_char(c.datacreare,&apos;&apos;hh24:mi:ss&apos;&apos;), DECODE(c.anulat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;),
    CASE
      WHEN ies.codies     IS NOT NULL THEN ies.prefixdoc ||ies.nrdoc ||&apos;&apos;/&apos;&apos;||To_Char(ies.datadoc ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN intr.codintr   IS NOT NULL THEN intr.prefixdoc||intr.nrdoc||&apos;&apos;/&apos;&apos;||To_Char(intr.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN tr.codtransf   IS NOT NULL THEN tr.prefixdoc  ||tr.nrdoc  ||&apos;&apos;/&apos;&apos;||To_Char(tr.datadoc  ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN com.codcomanda IS NOT NULL THEN com.prefixdoc ||com.nrdoc ||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      ELSE &apos;&apos;...&apos;&apos;
    END doc,
    CASE
      WHEN c.tipdoc IN (6,23,44) THEN s.den_subunit
      WHEN c.tipdoc IN (7,12,24,43) THEN g.den_gest
      ELSE p.den_part
    END &apos;||gUserAlias||&apos;
  FROM cantar c
		LEFT JOIN nartobj o ON o.codobiect = c.codobiect
		LEFT JOIN nartobj a1 ON a1.codobiect = c.amb1_cod
		LEFT JOIN nartobj a2 ON a2.codobiect = c.amb2_cod
		LEFT JOIN nartobj a3 ON a3.codobiect = c.amb3_cod
		LEFT JOIN nartobj a4 ON a4.codobiect = c.amb4_cod
    LEFT JOIN nartobj a5 ON a5.codobiect = c.amb5_cod
    LEFT JOIN nartobj a6 ON a6.codobiect = c.amb6_cod
		LEFT JOIN nartobj t1 ON t1.codobiect = c.transp1_cod
		LEFT JOIN nartobj t2 ON t2.codobiect = c.transp2_cod
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = c.coddoc1
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies AND ies.tipdoc = c.tipdoc
    LEFT JOIN intrari1 intr1 ON intr1.codintr1 = c.coddoc1
    LEFT JOIN intrari intr ON intr.codintr = intr1.codintr AND intr.tipdoc = c.tipdoc
    LEFT JOIN transf1 tr1 ON tr1.codtransf1 = c.coddoc1
    LEFT JOIN transf tr ON tr.codtransf = tr1.codtransf AND tr.tipdoc = c.tipdoc
    LEFT JOIN comanda1 com1 ON com1.codcomanda1 = c.coddoc1
    LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda AND com.tipdoc = c.tipdoc
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart p ON p.codpart = COALESCE(ies.partener, intr.partener, com.partener)
    LEFT JOIN nsubunit s ON s.codsubunit = COALESCE(ies.codsubunit, intr.codsubunit, com.subunitsursa)
    LEFT JOIN ngest g ON g.codgest = COALESCE(tr.codgestcmd,ies.codgestprod,intr.codgestprod,com.codgest)&apos;||
    gSuplJoins||&apos;
  WHERE C.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND C.LUNA = &apos;||PKG_GLOBALS.GetLUNALUCRU||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_CANTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CDOCIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7692090A8A044733EB64F571EDE91501BD753F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CDOCIMP IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(10000);
BEGIN
  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(ORD, ERR)&apos;;
  sSelect := &apos;
  SELECT ORD, ERR
  FROM TMP_LST_CDOCIMP&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_CDOCIMP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CENTRCONSUMMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05D41115191EB7D7738A9CA3804BF442C6BD4549</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CENTRCONSUMMAT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vAllGest   BOOLEAN;
  vAllArt    BOOLEAN;
  vDataStart VARCHAR2(20);
  vDataFin   VARCHAR2(20);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(2000);
  sSelect    VARCHAR2(9000);
  sSelect1   VARCHAR2(9000);
  sCondGest  VARCHAR2(1000);
  sCondObj   VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;comanda1 c1, comanda c, doccarnete CDOC, ngest g, NARTOBJ OBJmat, NART ArtMat, NUM UM, NARTOBJ ObjRet, NART ArtRet, NUM UMret,PRODCOMP PC, cmdprodmat mat&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTMAT&apos;, &apos;OEXTMAT.CODOBIECT = OBJMAT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTRET&apos;, &apos;OEXTRET.CODOBIECT = OBJRET.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRMAT&apos;, &apos;OATRMAT.CODOBIECT = OBJMAT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRRET&apos;, &apos;OATRRET.CODOBIECT = OBJRET.CODOBIECT&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vAllGest   := pkg_list_selectgestart.AllGest;
  vAllArt    := pkg_list_selectgestart.AllArt;
  vDataStart := pkg_list_selectgestart.DataStart;
  vDataFin   := pkg_list_selectgestart.DataFin;

  sCondGest := &apos;&apos;;
  if not vAllGest then
    sCondGest := &apos;
    AND g.codgest IN (SELECT to_number(valoare) FROM tmp_manevra_liste WHERE upper(filtru) = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  end if;

  sCondObj := &apos;&apos;;
  if not vAllArt then
    sCondObj := &apos;
    AND objret.codobiect IN (SELECT to_number(valoare) FROM tmp_manevra_liste WHERE upper(filtru) = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     Articol,
     UM,
     Pret,
     CantCom,
     CantReal,
     DifCant,
     ValCom,
     ValReal,
     DifVal,
     Produs,
     UMProdus,
     CantComProd,
     CantRealProd,
     ValLansata,
     PretMediu&apos;||
     gUserFields||&apos;) &apos;;

  sSelect := &apos;
  WITH realizari as (
    select mat.codcmdprodmat, sum(coalesce(i1.cant,0)) cant, sum(coalesce(i1.cant,0)*coalesce(i1.PU,0)) val, SUM(coalesce(I1.PU,0) * coalesce(I1.CANT,0))/SUM(coalesce(I1.CANT,0)) pret
    from cmdprodmat mat
      inner join intrari1 i1 on mat.codcomanda1 = i1.codcmdint1
      inner join intrari i on i1.codintr = i.codintr
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
    group by mat.codcmdprodmat),
  consumuri as (
    select mat.codcmdprodmat, sum(i1.cant) cant, SUM(I1.PU * I1.CANT)/SUM(I1.CANT) PRET
    from cmdprodmat mat
      inner join iesprodlink ieslink on mat.codcmdprodmat = ieslink.codcmdprodmat
      inner join iesiri1 i1 on ieslink.codies1 = i1.codies1
      inner join iesiri i on i1.codies = i.codies
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
    group by mat.codcmdprodmat)
  select
    x.Articol,
    x.UM,
    x.Pret,
    x.CantCom,
    x.CantReal,
    x.DifCant,
    x.ValCom,
    x.ValReal,
    x.DifVal,
    x.Produs,
    x.UMProdus,
    x.CantComProd,
    x.CantRealProd,
    x.ValLansata,
    x.PretMediu &apos;||gUserAlias||&apos;
  from (
  SELECT
     objmat.DENUMIRE Articol,
     um.den_um UM,
     sum(nvl(mat.pret, 0)) Pret,
     sum(nvl(mat.cant, 0)) CantCom,
     sum(nvl(consumuri.cant, 0)) CantReal,
     sum(nvl(mat.cant, 0) - nvl(consumuri.cant, 0)) DifCant,
     sum(round(nvl(mat.cant, 0) * nvl(mat.pret, 0), 2)) ValCom,
     sum(round(nvl(consumuri.cant, 0) * nvl(consumuri.pret, 0), 2)) ValReal,
     sum(round(mat.cant * mat.pret, 2) - round(nvl(consumuri.cant,0) * nvl(consumuri.pret,0), 2)) DifVal,
     ObjRet.denumire Produs,
     umret.den_um UMProdus,
     c1.cantacceptat CantComProd,
     nvl(realizari.cant,0) CantRealProd,
     nvl(realizari.val,0) ValLansata,
     nvl(realizari.pret,0) PretMediu,
     mat.codobiect,
     c1.codcomanda1,
     MAT.CODCMDPRODMAT
  FROM cmdprodmat mat
    INNER JOIN comanda1        c1 ON mat.codcomanda1 = c1.codcomanda1
    INNER JOIN comanda          c ON c1.codcomanda = c.codcomanda
    INNER JOIN ngest            g ON c.codgest = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect  = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NART        ArtRet ON objret.codarticol = artret.codarticol
    INNER JOIN NUM          UMret ON artret.um = umret.codum
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet
    LEFT  JOIN realizari          ON mat.codcmdprodmat = realizari.codcmdprodmat
    LEFT  JOIN consumuri          ON mat.codcmdprodmat = consumuri.codcmdprodmat
  WHERE mat.tip = 1 and c.tipdoc = 53
    AND c.datadoc between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||
    sCondgest||sCondObj||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;)||&apos;
  GROUP BY objmat.DENUMIRE, um.den_um, ObjRet.denumire, umret.den_um, realizari.cant, c1.cantacceptat, realizari.val, realizari.pret, mat.codobiect, c1.codcomanda1, MAT.CODCMDPRODMAT ) x
    INNER JOIN comanda1        c1 ON x.codcomanda1 = c1.codcomanda1
    INNER JOIN comanda          c ON c1.codcomanda = c.codcomanda
    INNER JOIN ngest            g ON c.codgest = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON x.codobiect  = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NART        ArtRet ON objret.codarticol = artret.codarticol
    INNER JOIN NUM          UMret ON artret.um = umret.codum
    INNER JOIN PRODCOMP        PC ON C1.CODRETETA = PC.CODPRODCOMP
    INNER JOIN CMDPRODMAT     MAT ON MAT.CODCMDPRODMAT = X.CODCMDPRODMAT
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet &apos;||
    gSuplJoins;

  sSelect1 := &apos;
  WITH CONS as (
    select i1.codobiect, c1.codcomanda1, sum(coalesce(i1.cant,0)) cant, sum(coalesce(i1.cant,0)*coalesce(i1.PU,0)) val, 
           sum(coalesce(i1.cant,0)*coalesce(pkg_list_base_difpecomint.getpretachiz(i1.codies1),0))/decode(sum(i1.cant),0,1) Pret
    from iesiri1 i1
      inner join iesiri i on i.codies = i1.codies
      inner join comanda1 c1 on i1.codcmdint1 = c1.codcomanda1
      left join iesprodlink il on i1.codies1 = il.codies1
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and nvl(i1.codcmdint1, 0) &gt; 0 and nvl(il.codcmdprodmat, 0) = 0
    group by i1.codobiect, c1.codcomanda1 ),
    realizari as (
    select mat.codcmdprodmat, sum(i1.cant) cant, sum(i1.cant*i1.PU) val, AVG(I1.PU) pret
    from cmdprodmat mat
      inner join intrari1 i1 on mat.codcomanda1 = i1.codcmdint1
      inner join intrari i on i1.codintr = i.codintr
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
    group by mat.codcmdprodmat)
  select
    x.Articol,
    x.UM,
    x.Pret,
    x.CantCom,
    x.CantReal,
    x.DifCant,
    x.ValCom,
    x.ValReal,
    x.DifVal,
    x.Produs,
    x.UMProdus,
    x.CantComProd,
    x.CantRealProd,
    x.ValLansata,
    x.PretMediu &apos;||gUserAlias||&apos;
  from (
  SELECT
     objmat.DENUMIRE Articol,
     um.den_um UM,
     sum(nvl(cons.pret, 0)) Pret,
     0 CantCom,
     sum(nvl(cons.cant, 0)) CantReal,
     - sum(nvl(cons.cant, 0)) DifCant,
     0 ValCom,
     sum(round(nvl(cons.cant, 0) * nvl(cons.pret, 0), 2)) ValReal,
     - sum(round(nvl(cons.cant, 0) * nvl(cons.pret, 0), 2)) DifVal,
     ObjRet.denumire Produs,
     umret.den_um UMProdus,
     c1.cantacceptat CantComProd,
     nvl(realizari.cant,0) CantRealProd,
     nvl(realizari.val,0) ValLansata,
     nvl(realizari.pret,0) PretMediu,
     cons.codobiect,
     c1.codcomanda1,
     prod.codcmdprodmat
  FROM cons
    INNER JOIN comanda1        c1 ON cons.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat    prod on prod.codcomanda1 = c1.codcomanda1 and nvl(prod.tip,0) = 0
    INNER JOIN comanda          c ON c1.codcomanda = c.codcomanda
    INNER JOIN ngest            g ON c.codgest = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON cons.codobiect  = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NART        ArtRet ON objret.codarticol = artret.codarticol
    INNER JOIN NUM          UMret ON artret.um = umret.codum
    LEFT  JOIN realizari          ON prod.codcmdprodmat = realizari.codcmdprodmat
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet
  WHERE c.tipdoc = 53
    AND c.datadoc between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||
    sCondgest||sCondObj||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;)||&apos;
  GROUP BY objmat.DENUMIRE, um.den_um, ObjRet.denumire, umret.den_um, c1.cantacceptat, realizari.cant, realizari.val, realizari.pret, cons.codobiect, c1.codcomanda1,prod.codcmdprodmat ) x
    INNER JOIN comanda1        c1 ON x.codcomanda1 = c1.codcomanda1
    INNER JOIN comanda          c ON c1.codcomanda = c.codcomanda
    INNER JOIN ngest            g ON c.codgest = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON x.codobiect  = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NART        ArtRet ON objret.codarticol = artret.codarticol
    INNER JOIN NUM          UMret ON artret.um = umret.codum
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP = C1.CODRETETA
    inner join cmdprodmat    prod on x.codcmdprodmat = prod.codcmdprodmat
    left  join cmdprodmat     mat ON mat.codcmdprodmat = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet&apos;||
    gSuplJoins;

  --delete x;
  --insert into x(test) values (sselect);
  --insert into x(test) values (sselect1);
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_centrconsummat; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>785FBFCDD0C7C7A70AD05B0AA3EE8AD12035B16E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_centrecost IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;centrecost cc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,  &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = CC.CODCENTRU&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Simbol, Denumire, 
    TipChelt, 
    TipAloc&apos;||
    gUserFields||&apos;)
  SELECT
    cc.simbol, cc.denumire, 
    Decode (cc.tipchelt,
      01, &apos;&apos;activitate de baza&apos;&apos;,
      02, &apos;&apos;cheltuieli indirecte - regie fixa&apos;&apos;, 
      03, &apos;&apos;cheltuieli indirecte - regie variabila&apos;&apos;,
      14, &apos;&apos;Cheltuieli indirecte comune&apos;&apos;, 
      11, &apos;&apos;Cheltuieli auxiliare&apos;&apos;, 
      12, &apos;&apos;Cheltuieli generale de administratie&apos;&apos;, 
      13, &apos;&apos;Cheltuieli de desfacere&apos;&apos;
    ) TipChelt,
    Decode (cc.tipaloc,
      0, &apos;&apos;Alocabil in calcul pret&apos;&apos;,
      1, &apos;&apos;Nealocabil in calcul pret&apos;&apos;,
      2, &apos;&apos;Fara inregistrari clasa 9&apos;&apos;
    ) TipAloc&apos;||
    gUserAlias||&apos;
  FROM centrecost cc &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_centrecost;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CENTRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C74514DDA83B3CBC285D50315D4F9E0527D2CF8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CENTRSTOC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  AnPrec    NUMBER(4);
  LunaPrec  NUMBER(2);
BEGIN
  gSuplCols := &apos;NARTOBJ NOBJ,NART NART,NUM NUM,NCLASEA NC,NPART PROD,NARTAMB AA&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_list_base_utils.make_config_luna_ioart;
  pkg_globals.SetLunaTemp(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru);
  pkg_globals.Calculeaza_Luna_Precedenta(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru, AnPrec,LunaPrec);
  pkg_globals.SetLunaPrecedenta(AnPrec,LunaPrec);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    ARTICOL,STOC,CLASA,UM,VALPRETI,VALPRETA,STOCMIN,STOCMED,STOCMAX,CODINT,CODEXT,
    PROD,PRACHIZLAST,FURNLAST,PRIMPLICIT&apos;||gUserFields||&apos;)
  WITH
  STOCART AS (
    SELECT NS.CODOBIECT, SUM(v.REST) CANT, SUM((NS.Pret - NS.ADAOS) * v.REST) VALACH, SUM(NS.PRET * v.REST) VALINREG
    FROM v_stocluna v
      INNER JOIN NIRSTOC NS  ON v.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN IOART1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN IOA.ALStart and IOA.ALStop
      INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST   G   ON G.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    WHERE v.REST &lt;&gt; 0 AND IOA.MG &lt;&gt; 5
    GROUP BY NS.CODOBIECT),
  PA AS (
    SELECT
      NS.CODOBIECT,
      MAX(NS.PRET-NS.ADAOS) KEEP (Dense_Rank LAST ORDER BY N.DATANIR) PRACHIZLAST,
      MAX(NS.FURN) KEEP (Dense_Rank LAST ORDER BY N.DATANIR) FURNLAST
    FROM NIRSTOC NS
      INNER JOIN NIR     N ON N.CODNIR  = NS.CODNIR
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND N.OPERAT = 1 AND N.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos;
    GROUP BY NS.CODOBIECT )
  SELECT
    NOBJ.DENUMIRE, Nvl(SA.CANT,0) STOC, NC.DEN_CLASEA, NUM.DEN_UM, SA.VALINREG, SA.VALACH, NOBJS.STOCMIN, NOBJS.STOCMED, NOBJS.STOCMAX, NOBJ.CODINTERN, NOBJ.CODEXTERN,
    PROD.DEN_PART, PA.PRACHIZLAST, LF.DEN_PART,PM.LEI&apos;||gUserAlias||&apos;
  FROM NARTOBJ NOBJ
    LEFT JOIN STOCART        SA    ON SA.CODOBIECT    = NOBJ.CODOBIECT
    LEFT JOIN NART                 ON NART.CODARTICOL = NOBJ.CODARTICOL
    LEFT JOIN NARTOBJSUBUNIT NOBJS ON NOBJS.CODOBIECT = NOBJ.CODOBIECT
                                   AND ( NOBJS.codgest is null or NOBJS.codgest = 0)
                                   AND NOBJS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NUM                  ON NUM.CODUM    = NART.UM
    LEFT JOIN NCLASEA        NC    ON NC.CODCLASEA = NART.CLASA
    LEFT JOIN NPART          PROD  ON PROD.CODPART = NOBJ.CODPRODUCATOR
    LEFT JOIN NUM1           U1    ON U1.CODUM     = NART.UM AND U1.SECUNDARA = 0
    LEFT JOIN NARTAMB        AA    ON AA.CODOBIECT = NOBJ.CODOBIECT AND AA.UMSEC = U1.CODUM1
    LEFT JOIN PA                   ON PA.CODOBIECT = NOBJ.CODOBIECT
    LEFT JOIN NPART          LF    ON LF.CODPART   = PA.FURNLAST
    LEFT JOIN PRETM          PM    ON PM.CODOBIECT = NOBJ.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = &apos;||PKG_GLOBALS.GETSUBUNITATE||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_CENTRSTOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98360B3B42459A3525D199B8A2C2E66745B6342D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CERTIF IS

  vCodCertif  CERTIF.CODCERTIF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodCertif  IN NUMBER) IS
BEGIN
  vCodCertif := pCodCertif;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;CERTIF C, NARTOBJ OBJ, NSERII S, NTARI T, NPART P, NPART PROD, NARTCLI AC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,    &apos;CC&apos;,   &apos;CC.CODCERTIF = C.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CERTIFICAT, DATAPRIMIRE, PARTENER, ARTICOL, SERIE, TARA, PROVENIENTA, OBS, PRODUCATOR &apos;||gUserFields||&apos;)
  SELECT
    C.NrCertif, C.DataPrimire, P.Den_Part, OBJ.Denumire, S.Serie, T.Den_Tara, C.Provenienta, C.Obs, PROD.DEN_PART &apos;||gUserAlias||&apos;
  FROM CERTIF C
    INNER JOIN NARTOBJ OBJ ON C.CodObiect = OBJ.CodObiect
    INNER JOIN NSERII S ON C.CodSerie = S.CodSerie
    LEFT  JOIN NTARI T ON C.CodTara = T.CodTara
    INNER JOIN NPART P ON C.CodPart = P.CodPart
    LEFT  JOIN NPART PROD ON PROD.CODPART = OBJ.CODPRODUCATOR
    LEFT  JOIN NARTCLI AC ON AC.CODOBIECT = C.CODOBIECT AND AC.CODPART = C.CODPART&apos;||
    gSuplJoins||&apos;
  WHERE C.CodCertif = &apos;||vCodCertif;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_certif;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F7DEC9A76A46362571777CF5A03024A4C0F225C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CERTIFLIVR IS

  vCodDoc     IESIRI.CODIES%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc  := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;LIVR1 L1, IESIRI I, IESIRI1 I1, NARTOBJ OBJ, NTARI T, NPART P, NGEST G, NPART PROD, NARTCLI ACCER, NARTCLI ACIES&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIF&apos;,     &apos;C&apos;,    &apos;C.CODCERTIF = LC.CODCERTIF&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,    &apos;CC&apos;,   &apos;CC.CODCERTIF = C.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CERTIFICAT, DATAPRIMIRE, PARTENER, ARTICOL, SERIE, TARA, PROVENIENTA, OBS, UM, CANT,
    EXPIRARE, LUNAEXP, ANEXP, DATAPROD, PRODUCATOR &apos;||gUserFields||&apos;)
  WITH LC AS (
    SELECT
      sum(l1.cant) cant, nvl(nser.tg,NS.TG) TG, S.SERIE, C.NrCertif, C.CODTARA, C.CODPART,
      C.CODGEST, C.DataPrimire, C.Provenienta, C.Obs, NSER.DATAPROD, L1.codlivr1, C.CODCERTIF, C.TIPPART, L1.CODLIVR
    FROM IESIRI I
      INNER JOIN LIVR L ON I.CODIES = L.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      LEFT JOIN NIRSTOC NS ON L1.CodNirSToc = NS.CodNirStoc
      LEFT JOIN NIRSER NSER ON L1.CodNIRSER = NSER.CodNirSer
      LEFT JOIN CERTIF C ON C.CodCertif = Decode(L1.CodCertif, NULL, NSER.CodCertif, 0, NSER.CodCertif, L1.CodCertif)
      LEFT JOIN NSERII S ON S.CodSerie = C.CodSerie
    WHERE I.CodIes = &apos;||vCodDoc||&apos; AND Nvl(C.CodCertif,0) &lt;&gt; 0
    GROUP BY nser.tg,NS.TG,S.SERIE,C.NrCertif,C.CODTARA,C.CODPART,C.CODGEST, C.CODCERTIF, C.DataPrimire, C.Provenienta,C.Obs,NSER.DATAPROD,L1.CODLIVR1, C.TIPPART, L1.CODLIVR
  )
  SELECT
    LC.NrCertif, LC.DataPrimire, CASE WHEN lc.tippart = 3 THEN G.Den_Gest ELSE P.Den_Part END, OBJ.Denumire, LC.Serie, T.Den_Tara, LC.Provenienta, LC.Obs, NUM1.Den_UM1, LC.Cant, LC.TG,
    extract(month FROM LC.TG), extract(year FROM LC.TG), LC.DATAPROD, PROD.DEN_PART&apos;||gUserAlias||&apos;
  FROM IESIRI1 I1
    INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
    INNER JOIN LIVR L ON L.CODIES = I.CODIES
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
    INNER JOIN NUM1 ON NUM1.CODUM1 = I1.UMSEC
    INNER JOIN NARTOBJ OBJ ON I1.CODOBIECT = OBJ.CODOBIECT
    LEFT  JOIN LC ON L1.CODLIVR1 = LC.CODLIVR1 AND LC.CODLIVR = L.CODLIVR and l1.codcertif = lc.codcertif
    LEFT  JOIN NTARI T ON LC.CODTARA = T.CODTARA
    LEFT  JOIN NPART P ON LC.CODPART = P.CODPART
    LEFT  JOIN NGEST G ON LC.CODGEST = G.CODGEST
    LEFT  JOIN NPART PROD ON PROD.CODPART = OBJ.CODPRODUCATOR
    LEFT  JOIN NARTCLI ACCER ON ACCER.CODOBIECT = I1.CODOBIECT AND ACCER.CODPART = P.CODPART
    LEFT  JOIN NARTCLI ACIES ON ACIES.CODOBIECT = I1.CODOBIECT AND ACIES.CODPART = I.PARTENER &apos;||
    gSuplJoins||&apos;
  WHERE I.CODIES = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END pkg_list_base_certiflivr;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFLIVRTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12743AD7E218BD498AA2043BD69F10EF6170C0F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CERTIFLIVRTRANSF IS

  vCodDoc  TRANSF.CODTRANSF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;TRANSF T, TRANSF1 T1, NUM1 NUM1, NARTOBJ OBJ, LIVR L, LIVR1 L1, NIRSTOC NS, NIRSER NSER, CERTIF C, NSERII S, NTARI TR, NPART P, NGEST G, NPART PROD, NARTCLI AC&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,    &apos;CC&apos;,   &apos;CC.CODCERTIF = C.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CERTIFICAT, DATAPRIMIRE, PARTENER, ARTICOL, SERIE, TARA, PROVENIENTA, OBS, UM, CANT,
    EXPIRARE, LUNAEXP, ANEXP, DATAPROD, PRODUCATOR &apos;||gUserFields||&apos;)
  SELECT
    C.NrCertif, C.DataPrimire, case when C.TipPart = 3 then G.Den_gest else P.Den_Part end, OBJ.Denumire, S.Serie, TR.Den_Tara, C.Provenienta, C.Obs, NUM1.Den_UM1, L1.Cant,
    nvl(nser.tg,NS.TG) TG, extract(month FROM nvl(nser.tg,NS.TG)), extract(year FROM nvl(nser.tg,NS.TG)), NSER.DATAPROD, PROD.DEN_PART &apos;||gUserAlias||&apos;
  FROM TRANSF T
    INNER JOIN TRANSF1 T1 ON T.CodTransf = T1.CodTransf
    INNER JOIN NUM1 ON NUM1.CodUM1 = T1.UMSec
    INNER JOIN NARTOBJ OBJ ON T1.CodObiect = OBJ.CodObiect
    INNER JOIN LIVR L ON L.CodTransf = T.CodTransf
    INNER JOIN LIVR1 L1 ON T1.CodTransf1 = L1.CodIes1 AND L1.CodLivr = L.CodLivr
    INNER JOIN NIRSTOC NS ON L1.CodNirSToc = NS.CodNirStoc
    INNER JOIN NIRSER NSER ON L1.CodNIRSER = NSER.CodNirSer
    INNER JOIN CERTIF C ON NSER.CodCertif = C.CodCertif
    INNER JOIN NSERII S ON C.CodSerie = S.CodSerie
    LEFT  JOIN NTARI TR ON C.CodTara = TR.CodTara
    LEFT  JOIN NPART P ON C.CodPart = P.CodPart
    LEFT  JOIN NGEST G ON C.CodGest = G.CodGest
    LEFT  JOIN NPART PROD ON PROD.CODPART = OBJ.CODPRODUCATOR
    LEFT  JOIN NARTCLI AC ON AC.CODOBIECT = T1.CODOBIECT AND AC.CODPART = P.CODPART&apos;||
    gSuplJoins||&apos;
  WHERE T.CodTransf = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

end pkg_list_base_certiflivrtransf;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CERTIFNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2066C13A404528F4126CA97C9026FE075199ADA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CERTIFNIR IS

  vCodDoc INTRARI.CODINTR%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER) IS
BEGIN
  vCodDoc  := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;INTRARI I, INTRARI1, NARTOBJ OBJ, NTARI T, NPART P, NGEST G, NPART PROD, NARTCLI ACCER, NARTCLI ACIES&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIF&apos;,     &apos;C&apos;,    &apos;C.CODCERTIF = LC.CODCERTIF&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CERTIFC&apos;,    &apos;CC&apos;,   &apos;CC.CODCERTIF = C.CODCERTIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CERTIFICAT, DATAPRIMIRE, PARTENER, ARTICOL, SERIE, TARA, PROVENIENTA, OBS, UM, CANT,
    EXPIRARE, LUNAEXP, ANEXP, DATAPROD, PRODUCATOR &apos;||gUserFields||&apos;)
  SELECT
    LC.NrCertif, LC.DataPrimire, CASE WHEN lc.tippart = 3 THEN G.Den_Gest ELSE P.Den_Part END, OBJ.Denumire, LC.Serie, T.Den_Tara, LC.Provenienta, LC.Obs, NUM1.Den_UM1, LC.Cant, LC.TG,
    extract(month FROM LC.TG), extract(year FROM LC.TG), LC.DATAPROD, PROD.DEN_PART&apos;||gUserAlias||&apos;
  FROM INTRARI I
    INNER JOIN NIR ON I.CODINTR = NIR.CODINTR
    INNER JOIN INTRARI1 I1 ON I.CODINTR = I1.CODINTR
    INNER JOIN NUM1 ON NUM1.CodUM1 = I1.UMSec
    INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
    INNER JOIN (
      SELECT sum(I1.CANT) cant, nvl(nser.tg,NS.TG) TG, S.SERIE, C.NrCertif, C.CODTARA, C.CODPART,
             C.CODGEST, C.DataPrimire, C.Provenienta, C.Obs, NSER.DATAPROD, I1.CODINTR1, C.CODCERTIF, C.TIPPART,
             NIR.CODNIR
      FROM NIR
        INNER JOIN NIRSTOC NS ON NIR.CodNir = NS.CodNir
        INNER JOIN INTRARI1 I1 ON NS.CODINTR1 = I1.CODINTR1
        INNER JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN CERTIF C ON NSER.CodCertif = C.CodCertif
        INNER JOIN NSERII S ON NSER.CodSerie = S.CodSerie
      GROUP BY nser.tg,NS.TG,S.SERIE,C.NrCertif,C.CODTARA,C.CODPART,C.CODGEST, C.CODCERTIF, C.DataPrimire,
               C.Provenienta,C.Obs,NSER.DATAPROD,I1.CODINTR1, C.TIPPART, NIR.CODNIR
      UNION ALL
      SELECT sum(DVI1.CANT) cant, nvl(nser.tg,NS.TG) TG, S.SERIE, C.NrCertif, C.CODTARA, C.CODPART,
             C.CODGEST, C.DataPrimire, C.Provenienta, C.Obs, NSER.DATAPROD, DVI1.CODINTR1, C.CODCERTIF, C.TIPPART,
             NIR.CODNIR
      FROM NIR
        INNER JOIN NIRSTOC NS ON NIR.CodNir = NS.CodNir
        INNER JOIN DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
        INNER JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN CERTIF C ON NSER.CodCertif = C.CodCertif
        INNER JOIN NSERII S ON NSER.CodSerie = S.CodSerie
      GROUP BY nser.tg,NS.TG,S.SERIE,C.NrCertif,C.CODTARA,C.CODPART,C.CODGEST, C.CODCERTIF, C.DataPrimire,
               C.Provenienta,C.Obs,NSER.DATAPROD,DVI1.CODINTR1, C.TIPPART, NIR.CODNIR
    ) LC on I1.CODINTR1 = LC.CODINTR1 AND NIR.CODNIR = LC.CODNIR
    LEFT  JOIN NTARI T ON LC.CodTara = T.CodTara
    LEFT  JOIN NPART P ON LC.CodPart = P.CodPart
    LEFT  JOIN NGEST G ON LC.CodGest = G.CodGest
    LEFT  JOIN NPART PROD ON PROD.CODPART = OBJ.CODPRODUCATOR
    LEFT  JOIN NARTCLI ACCER ON ACCER.CODOBIECT = I1.CODOBIECT AND ACCER.CODPART = P.CODPART
    LEFT  JOIN NARTCLI ACIES ON ACIES.CODOBIECT = I1.CODOBIECT AND ACIES.CODPART = I.PARTENER &apos;||
    gSuplJoins||&apos;
  WHERE I.CODINTR = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_CERTIFNIR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFADDD0895E19C34CEDEB86366D82E9C2734452C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CHELTAVANS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sSelectC_I  CLOB;
  sSelectC_T  CLOB;
  sSelectC_NC CLOB;
  sSelectV_I  CLOB;
  sSelectV_T  CLOB;
  sSelectV_NC CLOB;
  vAn         NUMBER         := PKG_GLOBALS.GETANLUCRU;
  vLuna       NUMBER         := PKG_GLOBALS.GETLUNALUCRU;
  sAL         VARCHAR2(    6):= To_Char(vAn,&apos;fm0000&apos;)||To_Char(vLuna,&apos;fm00&apos;);
  vAL         NUMBER         := vAn*12+vLuna;
  sMax        VARCHAR2(    2):= To_Char(Last_Day(To_Date(sAl,&apos;yyyymm&apos;)),&apos;dd&apos;);
--  vTTM        VARCHAR2(   20):= To_Char(Coalesce(To_Number(pkg_categconst.GetValConstanta(&apos;TipTVAMixt100&apos;, vLuna, vLuna)),0),&apos;9999999990&apos;);
BEGIN
--  PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;CHELTAVANS CAV, CHELTAVANS1 CAV1, NPART P, NGEST G, IOART IOA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    TIP, ART, NRDOC, DATADOC, GEST, PART, OBS, IOART, VALOARE, ANINCEPUT, LUNAINCEPUT,
    AMO, AMOLUNA,
    REZOLVAT, DURATAN, DURATAF, Subunit, GestRez, SubunitRez, ObsRez&apos;||gUserFields||&apos;)&apos;;

  sSelectC_I := &apos;
  SELECT
    &apos;&apos;CHELTUIALA&apos;&apos; Tip, VCA.DENUMIRE, I.NRDOC, I.DATADOC, G.DEN_GEST, P.DEN_PART, I1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN,CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT  &apos;||gUserAlias||&apos;
  FROM TMP_CHELTAVANS_INTR VCA
    INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = VCA.CODINTR1
    INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    LEFT JOIN CHELTAVANS CAV ON CAV.CODINTR1 = VCA.CODINTR1
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART = &apos;||vAn||&apos; AND CAV1.LUNASTART = &apos;||vLuna||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
    LEFT JOIN NPART P ON P.CODPART = I.PARTENER
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT
    &apos;||
    gSuplJoins;

  sSelectC_T := &apos;
  SELECT
    &apos;&apos;CHELTUIALA&apos;&apos; Tip, VCA.DENUMIRE, T1.NRDOC, T1.DATADOC, G.DEN_GEST, P.DEN_PART, T1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN, CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT   &apos;||gUserAlias||&apos;
  FROM TMP_CHELTAVANS_TREZOR VCA
    INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = VCA.CODOBLIGPIF
    INNER JOIN GENERAL GEN ON GEN.CODGENERAL = O.CODGENERAL
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = GEN.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR   = T1.CODTREZOR
    LEFT JOIN CHELTAVANS CAV ON CAV.CODOBLIGPIF = VCA.CODOBLIGPIF
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART = &apos;||vAn||&apos; AND CAV1.LUNASTART = &apos;||vLuna||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = O.CODGEST
    LEFT JOIN NPART P ON P.CODPART = T1.CODPART
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = T.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT&apos;||
    gSuplJoins;

  sSelectC_NC := &apos;
  SELECT
    &apos;&apos;CHELTUIALA&apos;&apos; Tip, VCA.DENUMIRE, N.NRDOC, N.DATADOC, G.DEN_GEST, P.DEN_PART, N1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN, CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT    &apos;||gUserAlias||&apos;
  FROM TMP_CHELTAVANS_NC1 VCA
    INNER JOIN NC1 N1 ON N1.CODNC1 = VCA.CODNC1
    INNER JOIN NC N ON N.CODNC = N1.CODNC
    LEFT JOIN CHELTAVANS CAV ON CAV.CODNC1 = VCA.CODNC1
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART*12+CAV1.LUNASTART = &apos;||vAL||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = N1.CODGEST
    LEFT JOIN NPART P ON P.CODPART = N.PART
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = N.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT&apos;||
    gSuplJoins;

  sSelectV_I := &apos;
  SELECT
    &apos;&apos;VENIT&apos;&apos; Tip, VCA.DENUMIRE, I.NRDOC, I.DATADOC, G.DEN_GEST, P.DEN_PART, I1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN,CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT    &apos;||gUserAlias||&apos;
  FROM TMP_VENITAVANS_IES VCA
    INNER JOIN IESIRI1 I1 ON I1.CODIES1 = VCA.CODIES1
    INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
    LEFT JOIN CHELTAVANS CAV ON CAV.CODIES1 = VCA.CODIES1
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART = &apos;||vAn||&apos; AND CAV1.LUNASTART = &apos;||vLuna||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
    LEFT JOIN NPART P ON P.CODPART = I.PARTENER
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT&apos;||
    gSuplJoins;

  sSelectV_T := &apos;
  SELECT
    &apos;&apos;VENIT&apos;&apos; Tip, VCA.DENUMIRE, T1.NRDOC, T1.DATADOC, G.DEN_GEST, P.DEN_PART, T1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN, CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT     &apos;||gUserAlias||&apos;
  FROM TMP_VENITAVANS_TREZOR VCA
    INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = VCA.CODOBLIGPIF
    INNER JOIN GENERAL GEN ON GEN.CODGENERAL = O.CODGENERAL
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = GEN.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR   = T1.CODTREZOR
    LEFT JOIN CHELTAVANS CAV ON CAV.CODOBLIGPIF = VCA.CODOBLIGPIF
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART = &apos;||vAn||&apos; AND CAV1.LUNASTART = &apos;||vLuna||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = O.CODGEST
    LEFT JOIN NPART P ON P.CODPART = T1.CODPART
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = T.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT&apos;||
    gSuplJoins;

  sSelectV_NC := &apos;
  SELECT
    &apos;&apos;VENIT&apos;&apos; Tip, VCA.DENUMIRE, N.NRDOC, N.DATADOC, G.DEN_GEST, P.DEN_PART, N1.OBS, IOA.DEN_IOART, VCA.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT,
    Coalesce(CAV1.AMO,0),
    CASE
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)  ,&apos;&apos;yyyymm&apos;&apos;))&lt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL AND To_Number(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;))&gt;&apos;||sAL||&apos; THEN 0
      WHEN CAV.DATASTART IS NOT NULL AND COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) IS NOT NULL THEN
        (VCA.VALOARE - Coalesce(CAV1.AMO,0))/
        (COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND) - GREATEST(TO_DATE(&apos;&apos;&apos;||sAL||&apos;01&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;), CAV.DATASTART) + 1)*
        (DECODE(TO_CHAR(COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND),&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM COALESCE(CAV1.DATAENDNOUA, CAV.DATAEND)),&apos;||sMax||&apos;) - DECODE(TO_CHAR(CAV.DATASTART,&apos;&apos;yyyymm&apos;&apos;),&apos;&apos;&apos;||sAL||&apos;&apos;&apos;, EXTRACT (DAY FROM CAV.DATASTART) - 1,0))
      WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; &apos;||vAL||&apos; THEN 0
      WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
      ELSE (VCA.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
    END,
    DECODE(VCA.REZOLVAT, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), CAV1.DURATAN, CAV1.DURATAF,
    SUB.DEN_SUBUNIT,
    NG.DEN_GEST,
    NSCH.DEN_SUBUNIT, VCA.OBSCHELT     &apos;||gUserAlias||&apos;
  FROM TMP_VENITAVANS_NC1 VCA
    INNER JOIN NC1 N1 ON N1.CODNC1 = VCA.CODNC1
    INNER JOIN NC N ON N.CODNC = N1.CODNC
    LEFT JOIN CHELTAVANS CAV ON CAV.CODNC1 = VCA.CODNC1
    LEFT JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART*12+CAV1.LUNASTART = &apos;||vAL||&apos;
    LEFT JOIN NGEST G ON G.CODGEST = N1.CODGEST
    LEFT JOIN NPART P ON P.CODPART = N.PART
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = N.SUBUNITATEA
    LEFT JOIN NGEST NG ON NG.CODGEST = VCA.CODGEST_REZ
    LEFT JOIN NSUBUNIT NSCH ON NSCH.CODSUBUNIT = NG.CODSUBUNIT&apos;||
    gSuplJoins;


  PKG_CHELTAVANS.MAKE_TEMP_FOR_VIEWCHELTAVANS;
  PKG_CHELTAVANS.MAKE_TEMP_FOR_VIEWVENITAVANS;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectC_I,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectC_T,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectC_NC, aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectV_I,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectV_T,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectV_NC, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;||tmpName||&apos; SET REST = Coalesce(Valoare,0) - Coalesce(Amo,0) - Coalesce(AmoLuna,0) &apos;, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_CHELTAVANS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CHELTPARCAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09AEAD96F04FFEC96EBF4E1B333A3761E9773ECB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CHELTPARCAUTO IS
-- stef - nu se mai foloseste - spart in doua liste
  vAnLunaIni  INTEGER;
  vAnLunaFin  INTEGER;
  vDistZile   BOOLEAN;
  vConsZile   BOOLEAN;
  vCC0        BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  vAn     NUMBER;
  vLuna   NUMBER;
  vNrZile NUMBER := 31;
  vTipA   NUMBER := 2;
  vTipB   NUMBER := 1;
BEGIN
  DELETE tmp_dinamic_cols;
  INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) VALUES (&apos;CC0&apos;,  &apos;Total&apos;, 0, 0, 0);

  INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2)
  SELECT &apos;CC&apos;||ROWNUM, Denumire, ROWNUM, CodCentru, 0
  FROM (
    SELECT CODCENTRU, DENUMIRE
    FROM CENTRECOST
    WHERE CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
      AND CODCENTRU &gt; 0
    ORDER BY CODCENTRU
  );

  IF vDistZile OR vConsZile THEN
    pkg_list_base_utils.ExtractAnLuna(vAnLunaIni, vAn, vLuna);
    vNrZile := EXTRACT (DAY FROM LAST_DAY(To_Date(vAn||&apos;.&apos;||vLuna,&apos;yyyy.mm&apos;)));

    IF vDistZile THEN vTipA := 1; END IF;
    IF vConsZile THEN vTipB := 2; END IF;

    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, COD, COD2)
    SELECT &apos;D&apos;||ROWNUM, CASE WHEN TIP = 1 THEN &apos;KM/&apos; ELSE &apos;CONS./&apos; END||ZI, ROWNUM, ZI, TIP
    FROM (
      SELECT Z.ZI, T.TIP
      FROM (SELECT LEVEL ZI FROM DUAL CONNECT BY LEVEL &lt;= 31) Z
      CROSS JOIN (SELECT LEVEL TIP FROM DUAL CONNECT BY LEVEL &lt;= 2) T
      WHERE T.TIP BETWEEN vTipA AND vTipB
      ORDER BY Z.ZI, T.TIP
    );

  END IF;
END;

FUNCTION  xCodCentru(     pCodCont IN NUMBER,
                          pAnLuna IN NUMBER)
RETURN NUMBER IS
  vResult NUMBER;
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  SELECT Nvl(NC1.CODCENTRU,0)
  INTO vResult
  FROM NCONT1 NC1
  WHERE nc1.codcont = pCodCont
    AND pAnLuna BETWEEN NC1.ALSTART and NC1.ALSTOP;

  RETURN vResult;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION  ContCodCentru(  pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pCodCont1 IN NUMBER,
                          pCodCont2 IN NUMBER DEFAULT NULL)
RETURN NUMBER IS
  vResult NUMBER;
BEGIN
  vResult := Nvl(pCodAuto,0);
  IF vResult = 0 THEN
    vResult := PKG_LIST_BASE_CHELTPARCAUTO.xCodCentru(pCodCont1,pAnLuna);
  END IF;
  IF vResult = 0 AND Nvl(pCodCont2,0) &lt;&gt; 0 THEN
    vResult := PKG_LIST_BASE_CHELTPARCAUTO.xCodCentru(pCodCont2,pAnLuna);
  END IF;
  RETURN vResult;
END;


FUNCTION  IContCodCentru( pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pICont    IN NUMBER,
                          pCodPart  IN NUMBER,
                          pSemnif   IN NUMBER)
RETURN NUMBER IS
  vResult   NUMBER;
BEGIN
  vResult := Nvl(pCodAuto,0);
  IF vResult = 0 THEN
    vResult := PKG_LIST_BASE_CHELTPARCAUTO.xCodCentru(pkg_list_base_utils.iCont_CodCont(pICont,pCodPart,pAnLuna,pSemnif),pAnLuna);
  END IF;
  RETURN vResult;
END;

PROCEDURE SETPARAMS(pAnLunaIni IN NUMBER DEFAULT NULL,
                    pAnLunaFin IN NUMBER DEFAULT NULL,
                    pDistZile  IN NUMBER DEFAULT 0,
                    pConsZile  IN NUMBER DEFAULT 0,
                    pCC0       IN NUMBER DEFAULT 0,
                    V_CODJOB1  IN NUMBER DEFAULT 0 )
IS
  dDataS DATE;
  dDataF DATE;

BEGIN
  vAnLunaIni  := pAnLunaIni;
  vAnLunaFin  := pAnLunaFin;

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,vAnLunaIni,vAnLunaFin);
  END IF;

  vDistZile   := Coalesce(pDistZile, 0) = 1 AND (pAnLunaIni = pAnLunaFin);
  vConsZile   := Coalesce(pConsZile, 0) = 1 AND (pAnLunaIni = pAnLunaFin);
  vCC0        := Coalesce(pCC0,      0) = 1;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(30000);
  sInsDC     VARCHAR2(10000);
  sSelDC     VARCHAR2(10000);
  sColDc     VARCHAR2(10000);
  sKMZi      VARCHAR2(10000);
  pStocComb  VARCHAR2(10000);
  pServComb  VARCHAR2(10000);
  sFiltruCC0 VARCHAR2( 1000);
BEGIN

  gSuplCols := &apos;nparcaut pa, npers s, nartobj o, nart a, nclasea ca&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;,&apos;);
  pStocComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtStocCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;
  pServComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtServCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;

  sInsDC := &apos;, CC0&apos;;
  sSelDC := &apos;, AG.CC0&apos;;
  sColDC := &apos;, SUM(valoare) CC0&apos;;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD &lt;&gt; 0 AND COD2 = 0 ORDER BY COD)
  LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, AG.&apos;||vRec.FIELDNAME;
    sColDC := sColDC||&apos;,
      SUM(DECODE(codcentru,&apos;||vRec.COD||&apos;,valoare,0)) &apos;||vRec.FIELDNAME;
  END LOOP;

  IF vDistZile OR vConsZile THEN
    FOR i IN 1..31 LOOP
      sKMZi := sKMZi||&apos;,SUM(DECODE(zi,&apos;||i||&apos;,km,0)) Z&apos;||i;
    END LOOP;
  END IF;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD2 = 1 ORDER BY COD) LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, Nvl(kml.z&apos;||vRec.COD||&apos;,0)&apos;;
  END LOOP;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD2 = 2 ORDER BY COD) LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, Nvl(pa.cmm*kml.z&apos;||vRec.COD||&apos;,0)&apos;;
  END LOOP;

  IF NOT vCC0 THEN
    sFiltruCC0 := &apos;
    WHERE Nvl(codcentru,0) &lt;&gt; 0&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||
   &apos;(NRAUTO, SOFER, ART, CLASA, AN, LUNA, KMLUNA, COMBCANT, COMBVAL&apos;||sInsDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH COSTURI AS (
    SELECT
      CASE WHEN NVL(i1.codauto,0) = 0 THEN i.codauto ELSE i1.codauto END codauto,
      PKG_LIST_BASE_CHELTPARCAUTO.ContCodCentru(i1.codcentru,i.an*12+i.luna,i1.contserv) codcentru,
      i.an, i.luna, (i1.pu * i1.cant - DECODE(i.tipdoc,3,nvl(i1.tva,0),0)) * DECODE(i.curs,NULL,1,0,1,i.curs) valoare,
      CASE WHEN i1.codobiect IN (&apos;||pServComb||&apos;) THEN i1.cant ELSE 0 END combcant,
      CASE WHEN i1.codobiect IN (&apos;||pServComb||&apos;) THEN (i1.pu * i1.cant - DECODE(i.tipdoc,3,nvl(i1.tva,0),0)) * DECODE(i.curs,NULL,1,0,1,i.curs) ELSE 0 END combval
    FROM intrari i
      INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    WHERE (Nvl(i1.codauto,0) &lt;&gt; 0 OR Nvl(i.codauto,0) &lt;&gt; 0)
      AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      i.codauto, Nvl(j.codcentru,0) codcentru, j.an, j.luna, j.valoare,
      0 combcant, 0 combval
    FROM iesiri i
      INNER JOIN jurnal j ON j.coddoc = i.codies AND j.tipdoc = i.tipdoc
    WHERE Nvl(i.codauto,0) &lt;&gt; 0
      AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      i.codauto, Nvl(i1.codcentru,0) codcentru, i.an, i.luna, 0 valoare,
      i1.cant combcant, (i1.pu * i1.cant - CASE WHEN i.tipdoc IN (16,21) then nvl(i1.tva,0) ELSE 0 END) * DECODE(i.curs,NULL,1,0,1,i.curs) combval
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    WHERE Nvl(i.codauto,0) &lt;&gt; 0
      AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND i1.tiplinie = &apos;&apos;=&apos;&apos;
      AND i1.codobiect IN (&apos;||pStocComb||&apos;)
    UNION ALL
    SELECT
      o.codnparcaut codauto,
      PKG_LIST_BASE_CHELTPARCAUTO.IContCodCentru (o.codcentru,t.an*12+t.luna,o.icont,o.codpart,o.semnificatie) codcentru,
      t.an, t.luna, o.valoare,
      0 combcant, 0 combval
    FROM trezor t
      inner join trezor1  t1 ON t1.codtrezor = t.codtrezor
      inner join general  g  ON g.coddoc     = t1.codtrezor1 AND g.tipdoc = t.tipdoc
      inner join obligpif o  ON o.codgeneral = g.codgeneral
    WHERE Nvl(o.codnparcaut,0) &lt;&gt; 0
      AND t.an*12+t.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND T1.ANULAT = 0 AND T.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
    UNION ALL
    SELECT
      nc1.codauto,
      PKG_LIST_BASE_CHELTPARCAUTO.ContCodCentru(nc1.codcentru,nc1.an*12+nc1.luna,nc1.contd,nc1.contc) codcentru,
      nc1.an, nc1.luna, nc1.valoare * DECODE(nc.curs,NULL,1,0,1,nc.curs),
      0 combcant, 0 combval
    FROM nc1
      INNER JOIN nc ON nc.codnc = nc1.codnc
    WHERE Nvl(nc1.codauto,0) &lt;&gt; 0
      AND nc1.an*12+nc1.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;)||&apos;
    UNION ALL
    SELECT
      pa.codnparcaut codauto, Nvl(j.codcentru,0) codcentru, j.an, j.luna, j.valoare,
      0 combcant, 0 combval
    FROM jurnal j
      INNER JOIN mifix mf ON mf.codmifix = j.coddoc
      INNER JOIN nparcaut pa ON pa.nrinv = mf.nrinventar
    WHERE j.tipdoc = 36
      AND j.an*12+j.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;)||&apos;
  ),
  AG AS (
    SELECT codauto, an, luna, sum(combcant) combcant, sum(combval) combval&apos;||sColDC||&apos;
    FROM Costuri&apos;||
    sFiltruCC0||&apos;
    GROUP BY codauto, an, luna),
  KMLUN AS (
    SELECT codnparcaut, an, luna, Sum(km) kmluna &apos;||sKMZi||&apos;
    FROM (
      SELECT
        p.codnparcaut, p0.luna, p0.an, EXTRACT (DAY FROM p0.databord) zi,
        p0.kmbord - COALESCE(Lag(p0.kmbord) OVER (PARTITION BY p.codnparcaut ORDER BY p0.databord),p.kmpornire,0) km
      FROM nparc0 p0 INNER JOIN nparcaut p ON p.codnparcaut = p0.codnparcaut)
    WHERE an*12+luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
    GROUP BY codnparcaut, an, luna)
  SELECT
    PA.NRINREG, S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME, O.DENUMIRE, CA.DEN_CLASEA, AG.AN, AG.LUNA, KML.KMLUNA, AG.COMBCANT, AG.COMBVAL &apos;||sSelDC||gUserAlias||&apos;
  FROM AG
    INNER JOIN nparcaut pa  ON pa.codnparcaut  = ag.codauto
    LEFT  JOIN npers    s   ON s.codpers       = NVL(pa.sofer,0)
    LEFT  JOIN nartobj  o   ON o.codobiect     = pa.codart
    LEFT  JOIN nart     a   ON a.codarticol    = o.codarticol
    LEFT  JOIN nclasea  ca  ON ca.codclasea    = NVL(a.clasa,0)
    LEFT  JOIN kmlun    kml ON kml.codnparcaut = ag.codauto AND kml.an = ag.an AND kml.luna = ag.luna&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_CHELTPARCAUTO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CHELTPARCAUTO2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E81F64B77F9BAF817D70C53930E99047B32D29B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CHELTPARCAUTO2 IS
-- stef - nu se mai foloseste - spart in doua liste
  vDataStart  VARCHAR2(10);
  vDataEnd    VARCHAR2(10);
  vAllCars    BOOLEAN;
  vExclCont   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  
PROCEDURE SETPARAMS(
  pDataStart IN VARCHAR2 DEFAULT NULL,
  pDataEnd   IN VARCHAR2 DEFAULT NULL,
  pAllCars   IN NUMBER   DEFAULT 1,
  V_CODJOB1  IN NUMBER   DEFAULT 0,
  pExclCont  IN NUMBER   DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataStart  := pDataStart;
  vDataEnd    := pDataEnd;
  vAllCars    := pAllCars = 1;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataStart,vDataEnd,xLunaAnIni,xLunaAnFin);
  END IF;
  vExclCont := pExclCont = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    CLOB;
  sSelect1   CLOB;
  sSelect2   CLOB;
  sSelect3   CLOB;
  sSelect4   CLOB;
  pStocComb  VARCHAR2(10000);
  pServComb  VARCHAR2(10000);
  sFiltru    VARCHAR2(10000);
  pAnLunaIni number(20);
  pAnLunaFin number(20);
  sData varchar2(10);
  sAn varchar2(4);
  sLuna varchar2(2);
  sJoinAux VARCHAR2(5000);
  sFiltruCont VARCHAR2(1000);
BEGIN
  gSuplCols  := &apos;nparcaut pa, npers s, nartobj opa, nart apa, nclasea capa, nartobj oli, nart ali, nclasea cali&apos;;
  pAnLunaIni := extract(year from to_date(&apos;&apos;||vDataStart||&apos;&apos;,&apos;dd.mm.yyyy&apos;)) * 12 + extract(month from to_date(&apos;&apos;||vDataStart||&apos;&apos;,&apos;dd.mm.yyyy&apos;));
  pAnLunaFin := extract(year from to_date(&apos;&apos;||vDataEnd||&apos;&apos;,&apos;dd.mm.yyyy&apos;)) * 12 + extract(month from to_date(&apos;&apos;||vDataEnd||&apos;&apos;,&apos;dd.mm.yyyy&apos;));
  
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OPAEXT&apos;, &apos;OPAEXT.CODOBIECT = OPA.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OLIEXT&apos;, &apos;OLIEXT.CODOBIECT = OLI.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OPAATR&apos;, &apos;OPAATR.CODOBIECT = OPA.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OLIATR&apos;, &apos;OLIATR.CODOBIECT = OLI.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;,&apos;);
  pStocComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtStocCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;
  pServComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtServCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;

  IF NOT vAllCars THEN
    sFiltru := &apos;
    AND pa.codnparcaut IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;&apos;CODNPARCAUT&apos;&apos;)&apos;;
  END IF;

  delete tmp_km1;
  sJoinAux := &apos;
  insert into tmp_km1
  with x as 
  (
  SELECT
    codnparcaut,
    min(abs(trunc(pa.databord) - to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))) inceput,
    min(abs(trunc(pa.databord) - to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))) sfarsit
  FROM nparc0 pa
  where coalesce(pa.kmbord,0) &lt;&gt; 0 &apos;||sFiltru||&apos;
  group by pa.codnparcaut
  ),
  f as 
  (
   select max(p0i.kmbord) kmbord, p0i.codnparcaut 
   from nparc0 p0i 
        inner join x on p0i.codnparcaut = x.codnparcaut
   where x.inceput = abs(trunc(p0i.databord) - to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) and coalesce(p0i.kmbord,0) &lt;&gt; 0
   group by p0i.codnparcaut 
  ),
  l as 
  (select min(p0f.kmbord) kmbord, p0f.codnparcaut  
   from nparc0 p0f 
        inner join x on p0f.codnparcaut = x.codnparcaut
   where x.sfarsit = abs(trunc(p0f.databord) - to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) and coalesce(p0f.kmbord,0) &lt;&gt; 0
   group by p0f.codnparcaut
  )
  select x.codnparcaut, f.kmbord, l.kmbord
  from x
       left join f on f.codnparcaut = x.codnparcaut
       left join l on l.codnparcaut = x.codnparcaut&apos;;
  execute immediate sjoinaux;
  
  sJoinAux := &apos;
  LEFT JOIN (
      select x.codnparcaut, 
      (select p0i.kmbord 
       from nparc0 p0i 
       where p0i.codnparcaut = x.codnparcaut and x.inceput = abs(p0i.databord - to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
             and coalesce(p0i.kmbord,0) &lt;&gt; 0 and rownum = 1
      ) first_km, 
      (select p0f.kmbord 
       from nparc0 p0f 
       where p0f.codnparcaut = x.codnparcaut and x.sfarsit = abs(p0f.databord - to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
             and coalesce(p0f.kmbord,0) &lt;&gt; 0 and rownum = 1
      ) last_km
      from 
      (
      SELECT
        codnparcaut,
        min(abs(databord - to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))) inceput,
        min(abs(databord - to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))) sfarsit
      FROM nparc0
      where coalesce(kmbord,0) &lt;&gt; 0
      group by codnparcaut
      ) x
    ) LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
  &apos;;

  sFiltruCont := &apos;&apos;;
  if vExclCont then
    sFiltruCont := &apos; and not exists &apos;||chr(13)||
                   &apos;      (select cv.valoare from constval cv, constluna cl, const1 cc &apos;||chr(13)||
                   &apos;       where cc.simbol = &apos;&apos;CContCheltAvans&apos;&apos; and cl.codconst1 = cc.codconst1 and cv.codconstluna = cl.codconstluna &apos;||chr(13)||
                   &apos;       and i.an*12+i.luna between cl.alstart and cl.alstop and cv.valoare = ali.contserviciu) &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CODDOC, NAV_TIPDOC,
    NRAUTO, SOFER, PA_ART, PA_CLASA,
    PREFIXDOC, NRDOC, DATADOC, OBSDOC, AN, LUNA,
    ART, CLASA, OBSLIN,
    VALOARE,
    COMBUSTIBIL, CANT,
    CENTRUCOST, KMSTART, KMEND, PARTENER &apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    i.codintr, i.tipdoc,
    PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
    I.PREFIXDOC, I.NRDOC, I.DATADOC, I.OBS OBSDOC, I.AN, I.LUNA,
    OLI.DENUMIRE, CALI.DEN_CLASEA, I1.OBS OBSLIN,
    (i1.pu * i1.cant - DECODE(i.tipdoc,3,nvl(i1.tva,0),0)) * DECODE(i.curs,NULL,1,0,1,i.curs) VALOARE,
    CASE WHEN i1.codobiect IN (&apos;||pServComb||&apos;) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END COMBUSTIBIL, i1.cant,
    cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
  FROM intrari i
    INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    INNER JOIN nparcaut pa ON pa.codnparcaut = CASE WHEN NVL(i.codauto,0) = 0 THEN i1.codauto ELSE i.codauto END
    LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
    LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
    LEFT JOIN npart p ON p.codpart = i.partener
    LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
    LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
    LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
    LEFT JOIN nartobj oli ON oli.codobiect = i1.codobiect
    LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
    LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
    LEFT JOIN centrecost cc ON cc.codcentru = pkg_list_base_cheltparcauto.ContCodCentru(i1.codcentru,i.an*12+i.luna,i1.contserv) &apos;||
    gSuplJoins||&apos;
  WHERE (Nvl(i1.codauto,0) &gt; 0 OR Nvl(i.codauto,0) &gt; 0)
    AND i.datadoc BETWEEN to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    sFiltru||sFiltruCont;

  sSelect2 := &apos;
  SELECT
    i.codies, i.tipdoc,
    PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
    I.PREFIXDOC, I.NRDOC, I.DATADOC, I.OBS OBSDOC, I.AN, I.LUNA, OLI.DENUMIRE, CALI.DEN_CLASEA, I1.OBS OBSLIN,
    (i1.pu * i1.cant - CASE WHEN i.tipdoc IN (16,21) then nvl(i1.tva,0) ELSE 0 END) * DECODE(i.curs,NULL,1,0,1,i.curs) VALOARE,
    CASE WHEN i1.codobiect IN (&apos;||pStocComb||&apos;) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END COMBUSTIBIL, i1.cant,
    cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN nparcaut pa ON pa.codnparcaut = case when nvl(i.codauto,0) = 0 then i1.codauto else i.codauto end
    LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
    LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
    LEFT JOIN npart p ON p.codpart = i.partener
    LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
    LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
    LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
    LEFT JOIN nartobj oli ON oli.codobiect = i1.codobiect
    LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
    LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
    LEFT JOIN centrecost cc ON cc.codcentru = Nvl(i1.codcentru,0) &apos;||
    gSuplJoins||&apos;
  WHERE i.tipdoc IN (14,24)
    and (Nvl(i1.codauto,0) &gt; 0 OR Nvl(i.codauto,0) &gt; 0)
    AND i.datadoc BETWEEN to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    sFiltru;

  sSelect3 := &apos;
  SELECT
    nc.codnc, 35,
    PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
    &apos;&apos;NC&apos;&apos;, NC.NRDOC, NC.DATADOC, NC.OBS OBSDOC, NC1.AN, NC1.LUNA, OLI.DENUMIRE, CALI.DEN_CLASEA, NC1.OBS OBSLIN,
    nc1.valoare * DECODE(nc.curs,NULL,1,0,1,nc.curs) VALOARE,
    &apos;&apos;NU&apos;&apos; Combustibil, 0 cant,
    cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
  FROM nc1
    INNER JOIN nc ON nc.codnc = nc1.codnc
    INNER JOIN nparcaut pa ON pa.codnparcaut = nc1.codauto
    LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
    LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
    LEFT JOIN npart p ON p.codpart = nc1.codnc - nc1.codnc
    LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
    LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
    LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
    LEFT JOIN nartobj oli ON oli.codobiect = (Nc1.codnc1-Nc1.codnc1)
    LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
    LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
    LEFT JOIN centrecost cc ON cc.codcentru = pkg_list_base_cheltparcauto.ContCodCentru(nc1.codcentru,nc1.an*12+nc1.luna,nc1.contd,nc1.contc) &apos;||
    gSuplJoins||&apos;
  WHERE Nvl(nc1.codauto,0) &lt;&gt; 0 and coalesce(nc.sablon,0) = 0
    AND nc.datadoc BETWEEN to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
    sFiltru;

  sSelect4 := &apos;
  SELECT
    t.codtrezor, t.tipdoc,
    PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
    T1.DOC, T1.NRDOC, T1.DATADOC, T1.OBS OBSDOC, T1.AN, T1.LUNA, OLI.DENUMIRE, CALI.DEN_CLASEA, NULL OBSLIN,
    o.valoare * COALESCE(NULLIF(g.curs,0),1) - coalesce(g.tva,0) VALOARE,
    &apos;&apos;NU&apos;&apos; Combustibil, 0 cant, 
    cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
  FROM trezor t
    INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
    INNER JOIN general g ON g.coddoc = t1.codtrezor1 AND g.tipdoc = t.tipdoc
    INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    INNER JOIN nparcaut pa ON pa.codnparcaut = o.codnparcaut
    LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
    LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
    LEFT JOIN npart p ON p.codpart = t1.codpart
    LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
    LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
    LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
    LEFT JOIN nartobj oli ON oli.codobiect = (t.codtrezor-t.codtrezor)
    LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
    LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
    LEFT JOIN centrecost cc ON cc.codcentru = o.codcentru &apos;||
    gSuplJoins||&apos;
  WHERE Coalesce(o.codnparcaut,0) &lt;&gt; 0
    AND t.datadoc BETWEEN to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||vDataEnd||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
    sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
  
  for i in pAnLunaIni..pAnLunaFin loop
    if trunc(i/12) = i/12 then
      sAn := to_char(i/12 - 1);
      sLuna := &apos;12&apos;;
    else
      sAn := to_char(trunc(i/12));
      sLuna := LPAD(to_char(i - trunc(i/12)*12),2,&apos;0&apos;);
    end if;
    sData := to_char(last_day(to_date(&apos;01.&apos;||sLuna||&apos;.&apos;||sAn)),&apos;dd.mm.yyyy&apos;);
    sSelect4 := &apos;
      SELECT
        mf1.codnirstoc, 36 tipdoc,
        PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
        &apos;&apos;MF&apos;&apos; DOC, cast(null as number) NRDOC, to_date(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) DATADOC, &apos;&apos;Amortizare mifix nr.inventar: &apos;&apos;||to_char(mf.nrinventar) OBSDOC, j1.AN, j1.LUNA, OLI.DENUMIRE, CALI.DEN_CLASEA, NULL OBSLIN,
        j1.valoare VALOARE,
        &apos;&apos;NU&apos;&apos; Combustibil, 0 cant,
        cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
      FROM mifix mf
        INNER JOIN mifix1 mf1 ON mf1.codmifix = mf.codmifix
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
        INNER JOIN nparcaut pa ON pa.codnparcaut = mf1.codauto
        INNER JOIN JURNAL1 J1 ON J1.CODDOC = MF.CODMIFIX AND J1.TIPDOC = 36
        LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
        LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
        LEFT JOIN npart p ON p.codpart = pa.codnparcaut - pa.codnparcaut
        LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
        LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
        LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
        LEFT JOIN nartobj oli ON oli.codobiect = ns.codobiect
        LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
        LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
        LEFT JOIN centrecost cc ON cc.codcentru = mf1.codcentru &apos;||
        gSuplJoins||&apos;
      WHERE mf1.anstart*12+mf1.lunastart = j1.an*12+j1.luna and j1.an*12+j1.luna = &apos;||i||sFiltru;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
    
    sSelect4 := &apos;
      SELECT
        coalesce(i.codintr,nc.codnc,ies.codies,tr1.codtrezor1), 52 tipdoc,
        PA.NRINREG, NumePrenume(S.NUME,S.PRENUME), OPA.DENUMIRE, CApA.DEN_CLASEA,
        &apos;&apos;CHELT.AV.&apos;&apos; DOC, coalesce(i.nrdoc,nc.nrdoc,ies.nrdoc,tr1.nrdoc) NRDOC, coalesce(i.datadoc,nc.datadoc,ies.datadoc,tr1.datadoc) DATADOC, &apos;&apos;Cheltuiala in avans&apos;&apos; OBSDOC, j1.AN, j1.LUNA, OLI.DENUMIRE, CALI.DEN_CLASEA, 
        coalesce(i.obs,nc.obs,ies.obs,tr1.obs) OBSLIN, j1.valoare VALOARE,
        &apos;&apos;NU&apos;&apos; Combustibil, 0 cant,
        cc.simbol, LKM.FIRST_KM, LKM.LAST_KM, p.den_part &apos;|| gUserAlias||&apos;
      FROM cheltavans ca
        INNER JOIN cheltavans1 ca1 ON ca.codcheltavans = ca1.codcheltavans
        INNER JOIN nparcaut pa ON pa.codnparcaut = ca1.codauto
        INNER JOIN JURNAL1 J1 ON J1.CODDOC = ca.codcheltavans AND J1.TIPDOC = 52
        LEFT JOIN TMP_KM1 LKM ON LKM.CODNPARCAUT = PA.CODNPARCAUT
        LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
        LEFT JOIN intrari1 i1 on i1.codintr1 = ca.codintr1
        LEFT JOIN intrari i on i1.codintr = i.codintr
        LEFT JOIN nc1 on nc1.codnc1 = ca.codnc1
        LEFT JOIN nc on nc.codnc = nc1.codnc
        LEFT JOIN iesiri1 ies1 on ies1.codies1 = ca.codies1
        LEFT JOIN iesiri ies on ies.codies = ies1.codies
        LEFT JOIN obligpif pif on pif.codobligpif = ca.codobligpif
        LEFT JOIN general gpif on gpif.codgeneral = pif.codgeneral
        LEFT JOIN trezor1 tr1 on tr1.codtrezor1 = gpif.coddoc and (select tr.tipdoc from trezor tr where tr.codtrezor = tr1.codtrezor) = gpif.tipdoc
        LEFT JOIN nartobj opa ON opa.codobiect = pa.codart
        LEFT JOIN nart apa ON apa.codarticol = opa.codarticol
        LEFT JOIN nclasea capa ON capa.codclasea = NVL(apa.clasa,0)
        LEFT JOIN nartobj oli ON oli.codobiect = coalesce(i1.CODOBIECT,ies1.codobiect)
        LEFT JOIN nart ali ON ali.codarticol = oli.codarticol
        LEFT JOIN nclasea cali ON cali.codclasea = NVL(ali.clasa,0)
        LEFT JOIN centrecost cc ON cc.codcentru = ca1.codcentru 
        LEFT JOIN npart p ON p.codpart = coalesce(i.partener,ies.partener,nc1.codpart)
        &apos;||gSuplJoins||&apos;
      WHERE ca1.anstart*12+ca1.lunastart = j1.an*12+j1.luna and j1.an*12+j1.luna = &apos;||i||&apos; and coalesce(ca.isvenit,0) = 0 &apos;||sFiltru;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
  end loop;
  
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_cheltparcauto2; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CLASEPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0AD8FF4FB161B731CD250B70A39F2C41ECF3E7F7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CLASEPART is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(500);
BEGIN
  gSuplCols := &apos;nclasep nc&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos; ( DENUMIRE,SIMBOL, NIVEL, NRANALITICE &apos;||gUserFields||&apos;)&apos;||
    &apos;SELECT lpad(&apos;&apos; &apos;&apos;,LEVEL*2,&apos;&apos; &apos;&apos;)||nc.den_clasep,nc.simbol,LEVEL AS nivel, nc.nranalitice&apos;||gUserAlias||&apos; &apos;||
    &apos;FROM nclasep nc &apos;||
    gSuplJoins||
    &apos;START WITH nc.codparinte IS NULL &apos;|| 
    &apos;CONNECT BY PRIOR nc.codclasep = nc.codparinte &apos;;
    
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_CLASEPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CLIFARAMISCAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F9CDF61A98605F09122D00A028C99F24127377D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CLIFARAMISCAG IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(30000);
  sPer     VARCHAR2( 1000);
  sAgent   VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;npart cli, npers ag, iopart io&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_selperagent.dupadata AND pkg_list_selperagent.DataIni = pkg_list_selperagent.DataFin THEN
    sPer := &apos;i.datadoc = TO_DATE(&apos;&apos;&apos;||To_Char(pkg_list_selperagent.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF pkg_list_selperagent.dupadata THEN
    sPer := &apos;i.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(pkg_list_selperagent.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(pkg_list_selperagent.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF pkg_list_selperagent.LunaAnIni = pkg_list_selperagent.LunaAnFin THEN
    sPer := &apos;i.an*12+i.luna = &apos;||pkg_list_selperagent.LunaAnIni;
  ELSE
    sPer := &apos;i.an*12+i.luna BETWEEN &apos;||pkg_list_selperagent.LunaAnIni||&apos; AND &apos;||pkg_list_selperagent.LunaAnFin;
  END IF;
  IF NOT pkg_list_selperagent.TotiAgentii THEN
    sAgent := &apos;
      AND Nvl(a.codagent,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPERS&apos;&apos;)&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;( CLIENT, AGENT&apos;||gUserFields||&apos;)
  WITH
  TMP AS (
    SELECT DISTINCT codpart, codagent
    FROM nagenda a
    WHERE Nvl(a.codagent,0) &lt;&gt; 0 AND Nvl(a.codpart,0) &lt;&gt; 0 AND Nvl(a.tip,0) = 0 &apos;||
      sAgent||&apos;
      AND NOT EXISTS (SELECT codies FROM iesiri i WHERE i.partener = a.codpart AND i.agent = a.codagent &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos; AND &apos;||sPer||&apos;)
  )
  SELECT cli.den_part, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume&apos;||gUserAlias||&apos;
  FROM tmp
    LEFT JOIN npers  ag  ON ag.codpers   = tmp.codagent
    LEFT JOIN npart  cli ON cli.codpart  = tmp.codpart
    LEFT JOIN npart1 p1  ON p1.codpart   = tmp.codpart AND &apos;||pkg_list_selperagent.LunaAnFin||&apos; BETWEEN p1.ALStart and p1.ALStop
    LEFT JOIN iopart io  On io.codiopart = p1.codiopart&apos;||
    gSuplJoins;

  PRC_AL_CHECK(&apos;NPART1&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_CLIFARAMISCAG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>471B28CF8A815B0D7C241D1531B5D6C96DB3A720</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMANDA IS

  CT_LISTID_COMFURN    CONSTANT NUMBER :=  44;
  CT_LISTID_COMCL      CONSTANT NUMBER :=  45;
  CT_LISTID_COMGEST    CONSTANT NUMBER := 124;
  CT_LISTID_COMSUB     CONSTANT NUMBER := 125;
  CT_LISTID_COMSA      CONSTANT NUMBER := 401;
  CT_LISTID_COMRAC     CONSTANT NUMBER := 408;

  gCodComanda NUMBER(20);
  xDocAv_Nr   VARCHAR2(3000);
  xDocAv_Data VARCHAR2(3000);
  xDocAv_Val  VARCHAR2(3000);
  xDocAv1Doc  VARCHAR2( 100);
  xDocAv1Val  NUMBER;
  xDocAv2Doc  VARCHAR2( 100);
  xDocAv2Val  NUMBER;
  xDocAv3Doc  VARCHAR2( 100);
  xDocAv3Val  NUMBER;
  xDocAv4Doc  VARCHAR2( 100);
  xDocAv4Val  NUMBER;
  xDocAv5Doc  VARCHAR2( 100);
  xDocAv5Val  NUMBER;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(10000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);


PROCEDURE SetDocAv (pCodComanda IN NUMBER) IS
BEGIN
  IF Coalesce(gCodComanda,0) &lt;&gt; pCodComanda THEN
    gCodComanda := pCodComanda;
    pkg_globals.setseparator(&apos;; &apos;);
    WITH i AS (
      SELECT Row_Number() OVER (ORDER BY DATADOC, NRDOC, CODIES) IDX, NrDoc, PrefixDoc, DataDoc, ValDoc
      FROM iesiri
      WHERE codies IN (
        SELECT c.codiesavans  FROM comanda c                                                        WHERE c.codcomanda = gCodComanda AND c.codiesavans  IS NOT NULL UNION
        SELECT ca.codiesavans FROM comanda c INNER JOIN cmdavans ca ON ca.codcomanda = c.codcomanda WHERE c.codcomanda = gCodComanda AND ca.codiesavans IS NOT NULL )
    )
    SELECT
      vc2_nt_to_string(CAST(collect(To_Char(NrDoc)               ) AS vc2_nt)) Nr,
      vc2_nt_to_string(CAST(collect(To_Char(DataDoc,&apos;DD.MM.YYYY&apos;)) AS vc2_nt)) Data,
      vc2_nt_to_string(CAST(collect(To_Char(ValDoc)              ) AS vc2_nt)) Val,
      Max(Decode(IDX,1,PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;DD.MM.YYYY&apos;),NULL)), Sum(Decode(IDX,1,ValDoc,0)),
      Max(Decode(IDX,2,PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;DD.MM.YYYY&apos;),NULL)), Sum(Decode(IDX,2,ValDoc,0)),
      Max(Decode(IDX,3,PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;DD.MM.YYYY&apos;),NULL)), Sum(Decode(IDX,3,ValDoc,0)),
      Max(Decode(IDX,4,PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;DD.MM.YYYY&apos;),NULL)), Sum(Decode(IDX,4,ValDoc,0)),
      Max(Decode(IDX,5,PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;DD.MM.YYYY&apos;),NULL)), Sum(Decode(IDX,5,ValDoc,0))
    INTO
      xDocAv_Nr,
      xDocAv_Data,
      xDocAv_Val,
      xDocAv1Doc, xDocAv1Val,
      xDocAv2Doc, xDocAv2Val,
      xDocAv3Doc, xDocAv3Val,
      xDocAv4Doc, xDocAv4Val,
      xDocAv5Doc, xDocAv5Val
    FROM i;
  END IF;
END;

FUNCTION GetDataAvX(pCodComanda IN NUMBER, aIDX in number) RETURN DATE IS
oData Date;
BEGIN
  oData := null;
  begin
    WITH i AS (
      SELECT Row_Number() OVER (ORDER BY DATADOC, NRDOC, CODIES) IDX, DataDoc
      FROM iesiri
      WHERE codies IN (
        SELECT c.codiesavans
        FROM comanda c
        WHERE c.codcomanda = gCodComanda AND c.codiesavans IS NOT NULL
        UNION
        SELECT ca.codiesavans
        FROM comanda c INNER JOIN cmdavans ca ON ca.codcomanda = c.codcomanda
        WHERE c.codcomanda = gCodComanda AND ca.codiesavans IS NOT NULL )
    )
    SELECT
      datadoc
    INTO
      oData
    FROM i where idx = aIDX;
  exception when others then oData := null;
  end;
  return oData;
END;

FUNCTION  GetDocAv_Nr  (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv_Nr;
END;

FUNCTION  GetDocAv_Data(pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv_Data;
END;

FUNCTION  GetDocAv_Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv_Val;
END;

FUNCTION  GetDocAv1Doc (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv1Doc;
END;

FUNCTION  GetDocAv1Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv1Val;
END;

FUNCTION  GetDocAv2Doc (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv2Doc;
END;

FUNCTION  GetDocAv2Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv2Val;
END;

FUNCTION  GetDocAv3Doc (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv3Doc;
END;

FUNCTION  GetDocAv3Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv3Val;
END;

FUNCTION  GetDocAv4Doc (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv4Doc;
END;

FUNCTION  GetDocAv4Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv4Val;
END;

FUNCTION  GetDocAv5Doc (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv5Doc;
END;

FUNCTION  GetDocAv5Val (pCodComanda IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SetDocAv(pCodComanda);
  RETURN xDocAv5Val;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  DELETE tmp_dinamic_cols;

  delete tmp_manevra_liste where filtru = &apos;CODPART&apos;;
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
  select distinct &apos;CODPART&apos;, partener
  from
  (
  SELECT TO_CHAR(cf.partener) partener
  FROM comanda c
       INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
       INNER JOIN REZERVATS R ON R.CODCOMANDA1 = C1.CODCOMANDA1 AND R.CODCOMANDA1F &gt; 0
       INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
       INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
       INNER JOIN NPART P ON P.CODPART = CF.PARTENER
  WHERE c.tipdoc in (18,65)
    AND c.datadoc BETWEEN PKG_LIST_ALEGPERIOADA.getDataS AND PKG_LIST_ALEGPERIOADA.getDataF
    AND C.ANULAT = 0 AND C.OPERAT = 1 AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR C.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE)
  UNION ALL
  SELECT TO_CHAR(cf.partener) partener
  FROM comanda c
       INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
       INNER JOIN CMDLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
       INNER JOIN REZERVATS R ON R.CODCOMANDA1 = L.CODCOMANDA1 AND R.CODCOMANDA1F &gt; 0
       INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
       INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
       INNER JOIN NPART P ON P.CODPART = CF.PARTENER
  WHERE c.tipdoc in (18,65)
    AND c.datadoc BETWEEN PKG_LIST_ALEGPERIOADA.getDataS AND PKG_LIST_ALEGPERIOADA.getDataF
    AND C.ANULAT = 0 AND C.OPERAT = 1 AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR C.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE)
  );

  INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Ftype, fsize)
  SELECT fieldname, display, rownum, cod, 2, 2500 from (
    SELECT &apos;C&apos;||to_char(partener) fieldname, DEN_PART display, partener cod
    FROM (
      SELECT T.VALOARE partener, P.DEN_PART
      FROM TMP_MANEVRA_LISTE T INNER JOIN NPART P ON P.CODPART = T.VALOARE
      WHERE T.FILTRU = &apos;CODPART&apos;
    )
    UNION ALL
    SELECT &apos;F&apos;||to_char(partener) fieldname, &apos;Intr.&apos;||DEN_PART display, partener cod
    FROM (
      SELECT T.VALOARE partener, P.DEN_PART
      FROM TMP_MANEVRA_LISTE T INNER JOIN NPART P ON P.CODPART = T.VALOARE
      WHERE T.FILTRU = &apos;CODPART&apos;
    )
  );

  COMMIT;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sUpdate       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
  sJoinAux      VARCHAR2(10000);
  sDenPart      VARCHAR2(100);
  vTipDoc       NUMBER;
  vTabla        VARCHAR2(50);
  vTabla1       VARCHAR2(50);
  sSMAux        VARCHAR2(500);
  sSMFiltruGest VARCHAR2(500);
  sAuxIns       VARCHAR2(5000);
  sAuxSel       VARCHAR2(5000);
  fAnulatOperat VARCHAR2(1000);
  sValidSold    VARCHAR2(2);
  sValidCredit  VARCHAR2(2);
  sZileGratie   VARCHAR2(10);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  sZileGratie := coalesce(pkg_categconst.GetValConstanta(&apos;ZileGratie&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),&apos;0&apos;);
  if Trim(sZileGratie) = &apos;&apos; then sZileGratie := &apos;0&apos;; end if;
  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj nobj, nart art, num1 num1, num us, nmonede mon, npers ag, nparttr del,&apos;||
    &apos;nagenda sedl, nlocalit locl, njudet judl, nzone zonal, ntari taral, nclasea cla, nclasep clp, &apos;||
    &apos;traseulivr t, npart prod, ncarsupart cs, nclaseas clas, oferta1 o1, ngest gact, nperscontact pcz&apos;;

  fAnulatOperat := &apos;
    AND c.anulat = 0 AND c.operat = 1&apos;;

  IF aLISTID = CT_LISTID_COMFURN THEN
    vTipDoc   := 8;
    vTabla    := &apos;COMANDF&apos;;
    vTabla1   := &apos;COMANDF1&apos;;
    sDenPart  := &apos;np.den_part&apos;;
    gSuplCols := gSuplCols ||&apos;, npart np, npart1 np1&apos;;
    sJoinAux  := &apos;
    LEFT JOIN npart np ON c.partener = np.codpart
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(Decode(ca.stare,1,1,0)) NRAprob,
        Max(Decode(ca.nivel,1,ca.stare)) Niv1Stare, Max(Decode(ca.nivel,1,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv1User,
        Max(Decode(ca.nivel,2,ca.stare)) Niv2Stare, Max(Decode(ca.nivel,2,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv2User,
        Max(Decode(ca.nivel,3,ca.stare)) Niv3Stare, Max(Decode(ca.nivel,3,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv3User,
        Max(Decode(ca.nivel,4,ca.stare)) Niv4Stare, Max(Decode(ca.nivel,4,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv4User,
        Max(Decode(ca.nivel,5,ca.stare)) Niv5Stare, Max(Decode(ca.nivel,5,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv5User
      FROM comanda c INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda&apos;;
    sAuxIns   := &apos;,
    CATUSER, FACTURABIL,
    NIV1Stare, NIV1User, NIV2Stare, NIV2User, NIV3Stare, NIV3User, NIV4Stare, NIV4User, NIV5Stare, NIV5User&apos;;
    sAuxSel   := &apos;,
    WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(c.USerId), CASE WHEN Coalesce(c.nrmaxaprobari,0) &lt;= Coalesce(Aprob.NRAprob,0) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    DECODE(Aprob.Niv1Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv1User,
    DECODE(Aprob.Niv2Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv2User,
    DECODE(Aprob.Niv3Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv3User,
    DECODE(Aprob.Niv4Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv4User,
    DECODE(Aprob.Niv5Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv5User&apos;;
  ELSIF aLISTID = CT_LISTID_COMCL  THEN
    vTipDoc   := 18;
    vTabla    := &apos;COMANDC&apos;;
    vTabla1   := &apos;COMANDC1&apos;;
    sDenPart  := &apos;np.den_part&apos;;
    gSuplCols := gSuplCols ||&apos;, npart np, npart1 np1&apos;;
    sJoinAux  := &apos;
    LEFT JOIN npart np ON c.partener = np.codpart
    LEFT JOIN (
      SELECT codcomanda1, vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) serii, vc2_nt_to_vc3200(CAST(COLLECT(serie||&apos;&apos; - &apos;&apos;||tg) AS vc2_nt)) serii_tg
      FROM (
        SELECT r.codcomanda1, CASE WHEN SUM(R.REST) = 1 THEN NSERII.SERIE ELSE NSERII.SERIE||&apos;&apos;(&apos;&apos;||SUM(R.REST)||&apos;&apos;)&apos;&apos;  END SERIE, Coalesce(nirser.tg, ns.tg) TG
        FROM rezervats r
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC    = R.CODNIRSTOC
          INNER JOIN NIRSER     ON NIRSER.CODNIRSER = R.CODNIRSER
          INNER JOIN NSERII     ON NSERII.CODSERIE  = NIRSER.CODSERIE
        WHERE r.codcomanda1 &gt; 0 and r.codnirstoc &gt; 0
        GROUP BY r.codcomanda1, nserii.serie, Coalesce(nirser.tg, ns.tg)
      )
      GROUP BY codcomanda1
    ) ser ON ser.codcomanda1 = c1.codcomanda1
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(Decode(ca.stare,1,1,0)) NRAprob,
        Max(Decode(ca.nivel,1,ca.stare)) Niv1Stare, Max(Decode(ca.nivel,1,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv1User,
        Max(Decode(ca.nivel,2,ca.stare)) Niv2Stare, Max(Decode(ca.nivel,2,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv2User,
        Max(Decode(ca.nivel,3,ca.stare)) Niv3Stare, Max(Decode(ca.nivel,3,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv3User,
        Max(Decode(ca.nivel,4,ca.stare)) Niv4Stare, Max(Decode(ca.nivel,4,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv4User,
        Max(Decode(ca.nivel,5,ca.stare)) Niv5Stare, Max(Decode(ca.nivel,5,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv5User
      FROM comanda c INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda&apos;;
    sAuxIns   := &apos;,
    PARPALET, PARCUTIE,
    DOCAVNR,DOCAVDATA,DOCAVVAL,
    DOCAV1DOC, DOCAV1VAL,
    DOCAV2DOC, DOCAV2VAL,
    DOCAV3DOC, DOCAV3VAL,
    DOCAV4DOC, DOCAV4VAL,
    DOCAV5DOC, DOCAV5VAL,
    SERII,
    SERIEDATA,NIV1Stare, NIV1User, NIV2Stare, NIV2User, NIV3Stare, NIV3User, NIV4Stare, NIV4User, NIV5Stare, NIV5User&apos;;
    sAuxSel   := &apos;,
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;PALET&apos;&apos;, NOBJ.CODOBIECT),
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;CUTIE&apos;&apos;, NOBJ.CODOBIECT),
    PKG_LIST_BASE_COMANDA.GetDocAv_Nr(c.codcomanda),PKG_LIST_BASE_COMANDA.GetDocAv_Data(c.codcomanda),PKG_LIST_BASE_COMANDA.GetDocAv_Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv1Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv1Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv2Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv2Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv3Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv3Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv4Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv4Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv5Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv5Val(c.codcomanda),
    SER.SERII, SER.SERII_TG,
    DECODE(Aprob.Niv1Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv1User,
    DECODE(Aprob.Niv2Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv2User,
    DECODE(Aprob.Niv3Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv3User,
    DECODE(Aprob.Niv4Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv4User,
    DECODE(Aprob.Niv5Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;,3, &apos;&apos;De reanalizat&apos;&apos;), Niv5User&apos;;
  ELSIF aLISTID = CT_LISTID_COMGEST    THEN
    vTipDoc   := 43;
    vTabla    := &apos;COMANDI&apos;;
    vTabla1   := &apos;COMANDI1&apos;;
    sDenPart  := &apos;np.den_gest&apos;;
    gSuplCols := gSuplCols ||&apos;, ngest np&apos;;
    sJoinAux  := &apos;
    LEFT JOIN ngest np ON c.codgest = np.codgest&apos;;
  ELSIF aLISTID = CT_LISTID_COMSUB THEN
    vTipDoc   := 44;
    vTabla    := &apos;COMANDI&apos;;
    vTabla1   := &apos;COMANDI1&apos;;
    sDenPart  := &apos;np.den_subunit&apos;;
    gSuplCols := gSuplCols ||&apos;, nsubunit np&apos;;
    sJoinAux  := &apos;
    LEFT JOIN nsubunit np ON c.subunitsursa = np.codsubunit&apos;;
  ELSIF aLISTID = CT_LISTID_COMSA   THEN
    vTipDoc   := &apos;92&apos;;
    vTabla    := &apos;COMANDSA&apos;;
    vTabla1   := &apos;COMANDSA1&apos;;
    gSuplCols := gSuplCols||&apos;, npart np, nparcaut pa&apos;;
    sDenPart  := &apos;np.den_part&apos;;
    sJoinAux  := &apos;
    LEFT JOIN npart    np  ON c.partener     = np.codpart
    LEFT JOIN nparccom csa ON csa.codcomanda = c.codcomanda
    LEFT JOIN nparcaut pa  ON pa.codnparcaut = csa.codnparcaut&apos;;
    sAuxIns   := &apos;,
    AUTONR,AUTOSERC, KMBORD,
    TIPSA,
    RETURNAT,
    TIPLINIESA,
    EXTERN&apos;;
    sAuxSel   := &apos;,
    pa.nrinreg, pa.seriec, csa.kmbord,
    Decode(csa.tipcomsa ,1,&apos;&apos;Asigurare&apos;&apos;,2,&apos;&apos;Garantie&apos;&apos;,3,&apos;&apos;Client&apos;&apos;,4,&apos;&apos;Interne&apos;&apos;),
    c1.cantreturnat/num1.paritate,
    Decode(c1.tipliniesa ,1, &apos;&apos;2.Constatata&apos;&apos;, &apos;&apos;1.Cerere Client&apos;&apos;),
    Decode(c1.culansare , 1, &apos;&apos;DA&apos;&apos;, &apos;&apos;NU&apos;&apos;)&apos;;
  ELSIF aLISTID = CT_LISTID_COMRAC  THEN
    vTipDoc   := &apos;94&apos;;
    vTabla    := &apos;&apos;;
    vTabla1   := &apos;&apos;;
    gSuplCols := gSuplCols||&apos;, rac_rez rac, npart np, nparcaut pa&apos;;
    sDenPart  := &apos;np.den_part&apos;;
    sJoinAux  := &apos;
    LEFT JOIN npart            np       ON c.partener               = np.codpart
    LEFT JOIN nparcaut         pa       ON pa.codnparcaut           = c.mijltransp
    LEFT JOIN rac_rez          rac      ON rac.codcomanda           = c.codcomanda
    LEFT JOIN ngest            racgp    ON racgp.codgest            = rac.codgestsursa
    LEFT JOIN nlocalit         raclp    ON raclp.codlocalit         = rac.codlocalit_prel
    LEFT JOIN ngest            racgl    ON racgl.codgest            = rac.codgestdest
    LEFT JOIN nlocalit         racll    ON racll.codlocalit         = rac.codlocalit_livr
    LEFT JOIN npart            racpe    ON racpe.codpart            = rac.codpartext
		LEFT JOIN nparttr          racd1    ON racd1.Codparttr          = rac.coddelegat1
		LEFT JOIN nparttr          racd2    ON racd2.Codparttr          = rac.coddelegat2
    LEFT JOIN nmarciauto       racmarca ON racmarca.codmarciauto    = rac.codmarca
    LEFT JOIN nmodeleauto      racmodel ON racmodel.codmodeleauto   = rac.codmodel
    LEFT JOIN ngest            racgt    ON racgt.codgest            = c.codgest
    LEFT JOIN ninterventiiauto racia    ON racia.codinterventiiauto = rac.codinterventie
    LEFT JOIN nechiv           ech      ON ech.codobiect            = c1.codobiect
    LEFT JOIN grechiv          grech    ON grech.codgrechiv         = ech.codgrupa
    LEFT JOIN ninterventiiauto racia    ON racia.codinterventiiauto = rac.codinterventie
    &apos;;
    sAuxIns   := &apos;,
    TIPREZ, TIPINTERV,
    AUTONR, AUTOSERC, RAC_NR_REF, NR_ZBOR, PARTEXT, MARCA, MODEL, GEST_TRANSF,
    GEST_PREL, LOC_PREL, ADR_PREL, GEST_LIVR, LOC_LIVR, ADR_LIVR,
    SOFER1, SOFER2, GRECHIVAL,
    RAC_DSTART, RAC_OSTART, RAC_DSTOP, RAC_OSTOP&apos;;
    sAuxSel   := &apos;,
    Decode(rac.tiprezervare,0,&apos;&apos;Customer&apos;&apos;,1,&apos;&apos;Shuttle&apos;&apos;,3,&apos;&apos;Courtesy&apos;&apos;,4,&apos;&apos;Uz intern&apos;&apos;,5,&apos;&apos;Reparatii&apos;&apos;,6,&apos;&apos;Abonament&apos;&apos;,7,&apos;&apos;Transfer&apos;&apos;) TipRez, racia.denumire TIPINTERV,
    pa.nrinreg, pa.seriec, rac.nr_ref, rac.nr_zbor, racpe.den_part, racmarca.marca, racmodel.model, racgt.den_gest,
    racgp.den_gest, raclp.den_localit, rac.adresa_prel, racgl.den_gest, racll.den_localit, rac.adresa_livr,
    racd1.delegat, racd2.delegat, grech.denumire grechival,
    Trunc(rac.datastart) rac_dstart, To_char(rac.datastart,&apos;&apos;hh24:mi&apos;&apos;) rac_ostart, Trunc(rac.datastop) rac_dstop, To_char(rac.datastop,&apos;&apos;hh24:mi&apos;&apos;) rac_ostop&apos;;
    fAnulatOperat := &apos;&apos;;
  END IF;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla,       &apos;CV&apos;,    &apos;CV.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla1,      &apos;CV1&apos;,   &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,  &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  gUserAlias := Upper(gUserAlias);

  IF InStr(gUserAlias, &apos;NP1.&apos;) &gt; 0 THEN
    gSuplJoins  := gSuplJoins||&apos;
    LEFT JOIN npart1 np1 ON np1.codpart = np.codpart AND (c.an*12+c.luna) BETWEEN np1.alstart AND np1.alstop &apos;;
  END IF;

  sSMAux := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  IF sSMAux IS NOT NULL THEN
    sSMAux := &apos; INNER JOIN nir n ON n.codnir = ns.codnir INNER JOIN ngest g ON g.codgest = n.gest &apos;||sSMAux;
  END IF;

  sSMFiltruGest := &apos;&apos;;
  IF NOT pkg_list_alegperioada.AllX THEN
    sSMFiltruGest := &apos; AND EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODGEST&apos;&apos; AND valoare = g.codgest)&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc,NAV_CodDoc1,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCCOM,DEN_PART,
    DENUMIRE,DEN_UM1,
    CANTCOMANDAT,CANTACCEPTAT,RESTACCEPTAT,
    PU,ACCEPTUM1,PRETUM1,
    VALLINIE,
    TERMEN,LINIE,
    MONEDA, OBSDOC, OBSLINIE, STOCMIN, STOCMED, STOCMAX,
    STOCMOM,
    TRASEU, DELEGAT, MIJLTR, NRTRANSP, UMSPEC, CANTUMSPEC,
    CANTREZ,
    LIVR_DEN, LIVR_ADR, LIVR_LOC, LIVR_JUD, LIVR_ZONA,
    DENUSER,
    STARE,
    DenLaCli, CodLaCli,
    CodListat,
    NRCOLETE,
    VALTREZ,
    SUBUNITATEA,
    X_Judet, X_CodPart, X_CodAgenda, X_CodClasaP, X_CodGest, X_Codsubunit&apos;||
    sAuxIns||gUserFields||&apos;)&apos;;

  sSelect := &apos;
	SELECT
    c.codcomanda, c1.codcomanda1, c.tipdoc,c.prefixdoc,c.nrdoc,c.datadoc, c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc doccom, &apos;||sDenPart||&apos;,
    nobj.denumire, num1.den_um1,
    CASE WHEN c.tipdoc = 65 THEN -1 ELSE 1 END*c1.cantcomandat/num1.paritate CANTCOMANDAT,
    CASE WHEN c.tipdoc = 65 THEN -1 ELSE 1 END*c1.cantacceptat/num1.paritate CANTACCEPTAT,
    CASE WHEN c.tipdoc = 65 THEN  0 ELSE 1 END*c1.restacceptat/num1.paritate RESTACCEPTAT,
    c1.pu*num1.paritate PU, c1.acceptum1, c1.pretum1,
    CASE WHEN c.tipdoc = 65 THEN -1 ELSE 1 END * c1.pu*c1.cantacceptat VALLINIE,
    c1.termen, c1.Indexlocal,
    Coalesce(mon.simbol ,&apos;&apos;-&apos;&apos;) MONEDA, c.OBS OBSDOC, c1.OBS OBSLINIE, nobjs.STOCMIN, nobjs.STOCMED, nobjs.STOCMAX,
    (SELECT SUM(ns.rest) FROM nirstoc ns&apos;||sSMAux||&apos; WHERE ns.codobiect = c1.codobiect AND ns.rest &lt;&gt; 0&apos;||sSMFiltruGest||&apos;)/num1.Paritate stocmom,
    t.dentraseu, del.delegat, del.mijltransp, del.nrtransp, us.den_um, c1.cantum1,
    (SELECT Coalesce(SUM(r.rest),0) FROM rezervats r WHERE r.codcomanda1 = c1.codcomanda1 and r.codnirstoc &gt; 0)/num1.Paritate cantrez,
    sedl.obs, getadresa(sedl.sector, sedl.strada, sedl.nr1, sedl.nr2, sedl.bloc, sedl.scara, sedl.etaj, sedl.apart, sedl.codpostal),
    locl.den_localit, judl.den_judet, zonal.den_zona,
    winmadmin.pkg_userfirme.getUserName(c.userid) DENUSER,
    CASE
      WHEN C.FARAFACTURA = 1                                                                                                                               THEN &apos;&apos;FARA FACTURARE&apos;&apos;
      WHEN SUM(ABS(Coalesce(c1.cantacceptat,0))) OVER (PARTITION BY c.codcomanda) = 0                                                                      THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN SUM(ABS(Coalesce(c1.cantacceptat,0))) OVER (PARTITION BY c.codcomanda) = SUM(ABS(Coalesce(c1.restacceptat,0))) OVER (PARTITION BY c.codcomanda) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN SUM(CASE WHEN Coalesce(c1.cantacceptat, 0) &gt; 0 AND Coalesce(c1.restacceptat, 0) &gt; 0 THEN 1 ELSE 0 END) OVER (PARTITION BY c.codcomanda) = 0
       AND SUM(ABS(Coalesce(c1.cantacceptat,0))) OVER (PARTITION BY c.codcomanda) &lt;&gt; 0                                                                     THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN SUM(ABS(Coalesce(c1.cantacceptat,0))) OVER (PARTITION BY c.codcomanda) &gt; SUM(ABS(Coalesce(c1.restacceptat,0))) over (PARTITION BY c.codcomanda) THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
    END Stare,
    COALESCE(ac.denumire,trad.denumiretrad,nobj.denumire) DenLaCli, Coalesce(ac.codextern,nobj.codextern) CodLaCli,
    Coalesce(
      CASE ac.tipcodafisat
        WHEN 1 THEN gre.cod
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN nobj.codextern
        WHEN 4 THEN nobj.codintern
        WHEN 5 THEN nobj.codvamal
        WHEN 6 THEN To_Char(nobj.codplu)
        WHEN 7 THEN o1.codextofe
      END,nobj.codextern
    ) CodListat,
    (SELECT COUNT(1) FROM nartobjcolet oc WHERE oc.codobiect = c1.codobiect) NRCOLETE,
    (SELECT SUM(valdoc) FROM trezor1 x WHERE x.codcomanda = c.codcomanda) VALTREZ,
    s.den_subunit, judl.Simbauto, p.codpart, sedl.codagenda, clp.codclasep, gact.codgest, s.codsubunit&apos;||sAuxSel||gUserAlias||&apos;
  FROM comanda c
    LEFT JOIN comanda1       c1    ON c.codcomanda     = c1.codcomanda
		LEFT JOIN nartobj        nobj  ON nobj.codobiect   = c1.codobiect
    LEFT JOIN nart           art   ON nobj.codarticol  = art.codarticol
    LEFT JOIN nartobjsubunit nobjs ON nobjs.codobiect  = nobj.codobiect
                                  AND (nobjs.codgest IS NULL OR nobjs.codgest = 0)
                                  AND nobjs.subunitate = c.subunitatea
		LEFT JOIN num1                 ON num1.codum1      = c1.umsec
    LEFT JOIN num            us    ON us.codum         = art.um1
		LEFT JOIN nmonede        mon   ON mon.codmoneda    = c.moneda
    LEFT JOIN npers          ag    on c.agent          = ag.codpers
    LEFT JOIN nagenda        sedl  ON sedl.codagenda   = c.codlocatie
    LEFT JOIN nlocalit       locl  ON locl.codlocalit  = sedl.codlocalit
    LEFT JOIN njudet         judl  ON judl.codjudet    = locl.codjudet
    LEFT JOIN nzone          zonal ON zonal.codzona    = locl.codzona
    LEFT JOIN ntari          taral ON taral.codtara    = locl.codtara
    LEFT JOIN nclasea        cla   on art.clasa        = cla.codclasea
    LEFT JOIN npart          p     on c.partener       = p.codpart
    LEFT JOIN nclasep        clp   on p.codclasa       = clp.codclasep
    LEFT JOIN traseulivr     t     on sedl.codtraseu   = t.codtraseulivr
    LEFT JOIN npart          prod  ON prod.codpart     = nobj.codproducator
    LEFT JOIN nparttr        del   ON c.delegat        = del.codparttr
    LEFT JOIN ncarsupart     cs    ON cs.codcarsupart  = nobj.codcaract
    LEFT JOIN nclaseas       clas  ON art.CLASASTATIST = clas.codclaseas
    LEFT JOIN nartcli        ac    ON ac.codartcli     = PKG_LIST_BASE_UTILS.GetCodArtCli(c1.codobiect, c.partener, p.codclasa)
    LEFT JOIN nartobjtrad    trad  ON trad.codlimba    = taral.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv         e     ON e.codobiect      = c1.codobiect
    LEFT JOIN grechiv        gre   ON gre.codgrechiv   = e.codgrupa
    LEFT JOIN oferta1        o1    ON o1.codoferta1    = COALESCE(c1.codoferta1,CASE WHEN c1.tipsursa IN (50,51) THEN c1.codsursa ELSE NULL END)
    LEFT JOIN nsubunit       s     On s.codsubunit     = c.subunitatea
    LEFT JOIN ngest          gact  On gact.codgest     = c1.gestact
    LEFT JOIN (
      SELECT codpart, MIN(codpersc) codpersc
      FROM nperscontact
      WHERE Coalesce(rzona,0) = 1
      GROUP BY codpart
    )                        xpcz  ON xpcz.codpart     = c.partener
    LEFT JOIN nperscontact   pcz   ON pcz.codpersc     = xpcz.codpersc &apos;||
    sJoinAux||
    gSuplJoins;
  IF vTipDoc = 18 THEN
    sSelect := sSelect||&apos;
    WHERE c.tipdoc IN (18,65) &apos;;
  ELSE
    sSelect := sSelect||&apos;
    WHERE c.tipdoc = :TipDoc &apos;;
  END IF;
  sSelect := sSelect||&apos;
    AND c.datadoc BETWEEN :DataS AND :DataF &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;C&apos;)||
    fAnulatOperat;
  IF vTipDoc = 18 AND pkg_list_alegperioada.optiunea1 THEN
    sSelect := sSelect||&apos; AND Coalesce(C.DISPLIVRARE,0) &lt;&gt; 1&apos;;
  END IF;

  pkg_globals.CheckDebugMode(sInsert||sSelect, aListID, aListVer);

  IF vTipDoc = 18 THEN
    EXECUTE IMMEDIATE sInsert||sSelect USING pkg_list_alegperioada.getDataS, pkg_list_alegperioada.getDataF;
    IF PKG_LIST_ALEGPERIOADA.optiunea3 THEN
      FOR V_REC IN (
        SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODPART&apos;
      ) LOOP
        sUpdate := &apos;UPDATE &apos;||TMPNAME||&apos; T
        SET C&apos;||V_REC.VALOARE||&apos; = (
          SELECT STRING_AGG(DISTINCT DOC)
          FROM (
            SELECT TO_CHAR(CF.NRDOC)||&apos;&apos;/&apos;&apos;||TO_CHAR(CF.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) DOC
            FROM REZERVATS R
              INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
              INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
            WHERE r.codcomanda1 = t.nav_coddoc1 and cf.partener = &apos;||v_rec.valoare||&apos;
            UNION ALL
            SELECT TO_CHAR(CF.NRDOC)||&apos;&apos;/&apos;&apos;||TO_CHAR(CF.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) DOC
            FROM CMDLINK L
              INNER JOIN REZERVATS R ON R.CODCOMANDA1 = L.CODCOMANDA1
              INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
              INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
            WHERE L.CODLINIECOMANDA = t.nav_coddoc1 and cf.partener = &apos;||v_rec.valoare||&apos;
          )
        )&apos;;
        BEGIN
          LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);
        EXCEPTION
          WHEN OTHERS THEN NULL;
        END;

        sUpdate := &apos;UPDATE &apos;||TMPNAME||&apos; T
        SET F&apos;||V_REC.VALOARE||&apos; = (
          SELECT STRING_AGG(DISTINCT DOC)
          FROM (
            SELECT TO_CHAR(I.NRDOC)||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) DOC
            FROM REZERVATS R
              INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
              INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
              INNER JOIN INTRLINK L ON L.CODLINIECOMANDA = R.CODCOMANDA1F
              INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L.CODINTR1
              INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
            WHERE r.codcomanda1 = t.nav_coddoc1 and cf.partener = &apos;||v_rec.valoare||&apos;
            UNION ALL
            SELECT TO_CHAR(I.NRDOC)||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) DOC
            FROM CMDLINK CL
              INNER JOIN REZERVATS R ON CL.CODCOMANDA1 = R.CODCOMANDA1
              INNER JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = R.CODCOMANDA1F
              INNER JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA
              INNER JOIN INTRLINK L ON L.CODLINIECOMANDA = R.CODCOMANDA1F
              INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L.CODINTR1
              INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
            WHERE CL.CODLINIECOMANDA = t.nav_coddoc1 and cf.partener = &apos;||v_rec.valoare||&apos;
          )
        )&apos;;
        BEGIN
          LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);
        EXCEPTION
          WHEN OTHERS THEN NULL;
        END;
      END LOOP;
    END IF;
  ELSE
    EXECUTE IMMEDIATE sInsert||sSelect USING vTipDoc, pkg_list_alegperioada.getDataS, pkg_list_alegperioada.getDataF;
  END IF;

  IF PKG_LIST_ALEGPERIOADA.optiunea2 THEN
    LIST_EXECUTE_IMMEDIATE (&apos;DELETE FROM &apos;||TMPNAME||&apos; WHERE Coalesce(STARE, &apos;&apos;#&apos;&apos;) &lt;&gt; &apos;&apos;NEFACTURATA&apos;&apos; &apos;, aListID, aListVer);
  END IF;

  IF PKG_LIST_ALEGPERIOADA.optiunea4 THEN
    PKG_COMANDA.ValidSetConst(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

    sUpdate := &apos;UPDATE &apos;||TMPNAME||&apos; SET ValidAdaos = CASE WHEN PKG_COMANDA.ValidAdaosMinim(NAV_CodDoc1) = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END &apos;;
    BEGIN
      LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;

    sInsert := &apos;INSERT INTO TMP_LST_PARTCOM (CODPART, CODAGENDA, VALP_COMNEFACT, VALA_COMNEFACT)
    SELECT DISTINCT
      X_CODPART, X_CODAGENDA,
      SUM(COALESCE(VALLINIE, 0)) OVER (PARTITION BY X_CODPART)              AS VALP_COMNEFACT,
      SUM(COALESCE(VALLINIE, 0)) OVER (PARTITION BY X_CODPART, X_CODAGENDA) AS VALA_COMNEFACT
    FROM &apos;||TMPNAME;
    TRUNCATE_TABLE(&apos;TMP_LST_PARTCOM&apos;);
    LIST_EXECUTE_IMMEDIATE (sInsert, aListID, aListVer);

    sUpdate := &apos;UPDATE TMP_LST_PARTCOM T
    SET (  SOLD,
           SOLDTVA,
           TERMENDEPASIT,
           SOLDDEP
        ) =
        (
         SELECT
          Sum(
            CASE
              WHEN O.SEMNIFICATIE IN (100, 130)           THEN - O.REST
              WHEN O.SEMNIFICATIE = 110                   THEN   O.REST - Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE = 120                   THEN -(O.REST - Coalesce(O.RESTTVA, 0))
              WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2  THEN - O.REST
              WHEN O.SEMNIFICATIE = 200                   THEN   O.REST
              WHEN O.SEMNIFICATIE = 210                   THEN -(O.REST - Coalesce(O.RESTTVA, 0))
              WHEN O.SEMNIFICATIE = 220                   THEN  (O.REST - Coalesce(O.RESTTVA, 0))
              WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN   O.REST
              WHEN O.SEMNIFICATIE IN (310, 330)           THEN   O.REST - Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE IN (410, 430)           THEN -(O.REST - Coalesce(O.RESTTVA, 0))
              WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (2, 5, 6, 8, 9,15,16,17,   20,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -O.REST
              WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5,    8, 9,15,16,   18,20,      25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -O.REST
              WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (3, 4,    7,10,11,12,13,14,   18,19,23,24,30,31,32,33,34) THEN O.REST
              WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3, 4, 6, 7,10,11,12,13,14,17,   19,      30,31,32,33,34) THEN O.REST
              ELSE 0
            END *
            CASE WHEN Coalesce(G.MONEDA,0) = 0 THEN 1 ELSE COALESCE(REG.CURS,G.CURS,1) END
          ) AS SOLD,
          Sum(
            CASE
              WHEN O.SEMNIFICATIE = 110         THEN  Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE = 120         THEN -Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE = 210         THEN -Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE = 220         THEN  Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE IN (310, 330) THEN  Coalesce(O.RESTTVA, 0)
              WHEN O.SEMNIFICATIE IN (410, 430) THEN -Coalesce(O.RESTTVA, 0)
              ELSE 0
            END *
            CASE WHEN Coalesce(G.MONEDA,0) = 0 THEN 1 ELSE COALESCE(REG.CURS,G.CURS,1) END
          ) AS SOLDTVA,
          Max (
            CASE
              WHEN NOT O.SEMNIFICATIE IN (200, 240) THEN 0
              WHEN Coalesce(TRUNC(O.TERMEN), TRUNC(SYSDATE)) + &apos;||sZileGratie||&apos; &lt; TRUNC(SYSDATE) THEN TRUNC(SYSDATE - O.TERMEN)
              ELSE 0
            END
          ) AS TERMENDEPASIT,
          Sum(
            CASE
              WHEN NOT O.SEMNIFICATIE IN (200, 240) THEN 0
              WHEN Coalesce(TRUNC(O.TERMEN), TRUNC(SYSDATE)) + &apos;||sZileGratie||&apos; &lt; TRUNC(SYSDATE) THEN 
                CASE
                  WHEN O.SEMNIFICATIE IN (100, 130)           THEN - O.REST
                  WHEN O.SEMNIFICATIE = 110                   THEN   O.REST - Coalesce(O.RESTTVA, 0)
                  WHEN O.SEMNIFICATIE = 120                   THEN -(O.REST - Coalesce(O.RESTTVA, 0))
                  WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2  THEN - O.REST
                  WHEN O.SEMNIFICATIE = 200                   THEN   O.REST
                  WHEN O.SEMNIFICATIE = 210                   THEN -(O.REST - Coalesce(O.RESTTVA, 0))
                  WHEN O.SEMNIFICATIE = 220                   THEN  (O.REST - Coalesce(O.RESTTVA, 0))
                  WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN   O.REST
                  WHEN O.SEMNIFICATIE IN (310, 330)           THEN   O.REST - Coalesce(O.RESTTVA, 0)
                  WHEN O.SEMNIFICATIE IN (410, 430)           THEN -(O.REST - Coalesce(O.RESTTVA, 0))
                  WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (2, 5, 6, 8, 9,15,16,17,   20,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -O.REST
                  WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5,    8, 9,15,16,   18,20,      25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -O.REST
                  WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (3, 4,    7,10,11,12,13,14,   18,19,23,24,30,31,32,33,34) THEN O.REST
                  WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3, 4, 6, 7,10,11,12,13,14,17,   19,      30,31,32,33,34) THEN O.REST
                  ELSE 0
                END *
                CASE WHEN Coalesce(G.MONEDA,0) = 0 THEN 1 ELSE COALESCE(REG.CURS,G.CURS,1) END
              ELSE 0
            END
          ) AS SOLDDEP
        FROM OBLIGPIF O
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN (
            SELECT
              R1.CODGENERAL,
              Max(R.CURS)      KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS,
              Max(R.CURS_IFRS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS_IFRS
            FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
            GROUP BY R1.CODGENERAL
          ) REG ON REG.CODGENERAL = G.CODGENERAL
        WHERE O.REST &lt;&gt; 0
          AND O.SEMNIFICATIE IN (200, 210, 220, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
          AND O.CODPART = T.CODPART
      )&apos;;
    LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);

    sUpdate := &apos;UPDATE TMP_LST_PARTCOM T
    SET CREDIT =
        COALESCE (
          (SELECT A1.CREDITCLIENT FROM NAGENDA A LEFT JOIN NAGENDA1 A1 ON A1.CODAGENDA = A.CODAGENDA AND A1.ALSTOP = 99999 WHERE A.CODPART = T.CODPART AND A.CODAGENDA = T.CODAGENDA),
          (SELECT P1.CREDITCLIENT FROM NPART1 P1 WHERE P1.CODPART = T.CODPART AND P1.ALSTOP = 99999 ),
          0
        )&apos;;
    LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);

    sUpdate := &apos;UPDATE  &apos;||TMPNAME||&apos; TL
    SET (
           ValidSold,
           ValidCredit,
           ZileDep,
           Sold,
           SoldDep
        ) =
        (
        SELECT
          CASE WHEN TP.TERMENDEPASIT &gt; 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END,
          CASE 
            WHEN coalesce(TP.CREDIT,0) = 0 THEN &apos;&apos;DA&apos;&apos; 
            WHEN TP.SOLD + TP.VALP_COMNEFACT &gt; TP.CREDIT THEN &apos;&apos;NU&apos;&apos;
            ELSE &apos;&apos;DA&apos;&apos; 
          END,
          TP.TERMENDEPASIT, 
          case when TP.Sold &gt; 0 then tp.sold end,
          TP.SoldDep
        FROM TMP_LST_PARTCOM TP
        WHERE TP.CODPART = TL.X_CODPART AND TP.CODAGENDA = TL.X_CodAgenda
        )&apos;;
    LIST_EXECUTE_IMMEDIATE (sUpdate, aListID, aListVer);
  END IF;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_comanda;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMANDRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BC23521CD7A1D1BB8B4511246B6F87BEBCE1365</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMANDRAC IS

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);
  DataStartRac VARCHAR2(50);
  DataStopRac  VARCHAR2(50);
  gAnual       BOOLEAN;
  vAllCars     BOOLEAN;
  vTipInterval NUMBER(2);

PROCEDURE setParams(
  DataStart    IN VARCHAR2,
  DataStop     IN VARCHAR2,
  pAnual       IN Number DEFAULT 0,
  pAllCars     IN Number DEFAULT 1,
  pTipInterval IN NUMBER DEFAULT 0,
  V_CODJOB1    IN NUMBER DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  DataStartRac := DataStart;
  DataStopRac  := DataStop;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,DataStartRac,DataStopRac,xLunaAnIni,xLunaAnFin);
  END IF;
  gAnual       := Coalesce(pAnual,   0) = 1;
  vAllCars     := Coalesce(pAllCars, 1) = 1;
  vTipInterval := pTipInterval;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(30000);
--  cStare        VARCHAR2(5000);
  vTipDoc       NUMBER;
  vTabla        VARCHAR2(50);
  vTabla1       VARCHAR2(50);
--  fAnulatOperat VARCHAR2(1000);
  sFiltru       VARCHAR2(10000);
	ColoaneIncas  varchar2(2000);
	ColoaneIncasX varchar2(2000);
	JoinIncas     varchar2(5000);
	Desfasurat    boolean;
  sFiltru2      varchar2(1000);
BEGIN
  vTipDoc   := &apos;94&apos;;
  vTabla    := &apos;&apos;;
  vTabla1   := &apos;&apos;;
  pkg_globals.SetSeparator(&apos;,&apos;);

  if gAnual then
    DataStartRac := &apos;01.01.&apos;||PKG_Globals.GETANLUCRU;
    DataStopRac  := &apos;31.12.&apos;||PKG_Globals.GETANLUCRU;
	end if;
  gSuplCols := &apos;Comanda c, comanda1 c1, rac_rez rac&apos;;
  pkg_list_struct.StartSuplCols;

  --pkg_list_struct.AddSuplTabs(gSuplCols, vTabla,       &apos;CV&apos;,    &apos;CV.CODCOMANDA = C.CODCOMANDA&apos;);
  --pkg_list_struct.AddSuplTabs(gSuplCols, vTabla1,      &apos;CV1&apos;,   &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,  &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,  &apos;Csup&apos;,    &apos;CSup.CODComanda = C.CODComanda&apos;);
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;RAC_REZ&apos;,  &apos;Rsup&apos;,   &apos;Rsup.CODComanda = C.CODComanda&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  gUserAlias := Upper(gUserAlias);

  if vTipInterval = 0 then
    sFiltru2 := &apos; AND Trunc(rac.datastart) between TO_DATE(&apos;&apos;&apos;||DataStartRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||DataStopRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  else if vTipInterval = 1 then
    sFiltru2 := &apos; AND Trunc(rac.datastop) between TO_DATE(&apos;&apos;&apos;||DataStartRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||DataStopRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  else
    sFiltru2 := &apos; AND (
                       Trunc(rac.datastart) between (TO_DATE(&apos;&apos;&apos;||DataStartRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) and (TO_DATE(&apos;&apos;&apos;||DataStopRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
                       OR
                       Trunc(rac.datastop) between (TO_DATE(&apos;&apos;&apos;||DataStartRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) and(TO_DATE(&apos;&apos;&apos;||DataStopRac||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
                       )&apos;;  end if;
  end if;

--  IF InStr(gUserAlias, &apos;NP1.&apos;) &gt; 0 THEN
--    gSuplJoins  := gSuplJoins||&apos;
--    LEFT JOIN (
--      SELECT p1.*,
--        CASE WHEN p1.anstart = fl.aninitial AND p1.lunastart = fl.lunainitiala THEN 0 ELSE p1.anstart * 12 + p1.lunastart END xalstart,
--        Coalesce(Lead(p1.anstart * 12 + p1.lunastart) OVER (PARTITION BY CODPART ORDER BY P1.ANSTART, P1.LUNASTART) - 1,fl.anmaxim*12+fl.lunamaxima) xalstop
--      FROM npart1 p1 cross JOIN firmaluni fl
--    ) np1 ON np1.codpart = np.codpart AND c.an*12+c.luna BETWEEN xalstart AND xalstop&apos;;
--  END IF;

--  cStare := &apos;CASE
--      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
--      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = SUM(Coalesce(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;NEFACTURATA&apos;&apos;
--      WHEN SUM(CASE WHEN Coalesce(c1.cantacceptat, 0) &gt; 0 AND Coalesce(c1.restacceptat, 0) &gt; 0 THEN 1 ELSE 0 END) over (PARTITION BY c.codcomanda) = 0
--       AND SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &lt;&gt; 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
--      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &gt; SUM(Coalesce(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
--      ELSE NULL
--    END&apos;;

--  fAnulatOperat := &apos;
--    AND c.anulat = 0 AND c.operat = 1&apos;;
  Desfasurat := aListID = 408;
  if Desfasurat then
    ColoaneIncasX := &apos;X.IncasClient, X.FactClient, X.TotalClient, X.IncasSofer, X.FactSofer, X.TotalSofer,
                      X.IncasClientV, X.FactClientV, X.IncasSoferV, X.FactSoferV, &apos;;
    ColoaneIncas  := &apos;IncasClient, FactClient, TotalClient, IncasSofer, FactSofer, TotalSofer,
                      IncasClientV, FactClientV, IncasSoferV, FactSoferV, &apos;;
    JoinIncas     :=&apos;
		  LEFT JOIN ( --rest de incasat
      SELECT
        CodComanda,
        Sum(Coalesce(IncasClient ,0)) IncasClient , Sum(Coalesce(IncasSofer ,0)) IncasSofer,
        Sum(Coalesce(FactClient  ,0)) FactClient  , Sum(Coalesce(FactSofer  ,0)) FactSofer,
        Sum(Coalesce(TotalClient ,0)) TotalClient , Sum(Coalesce(TotalSofer ,0)) TotalSofer,
        Sum(Coalesce(IncasClientV,0)) IncasClientV, Sum(Coalesce(IncasSoferV,0)) IncasSoferV,
        Sum(Coalesce(FactClientV ,0)) FactClientV , Sum(Coalesce(FactSoferV ,0)) FactSoferV
      FROM (
        SELECT
          CodComanda,
          Case When Cineplateste &lt;&gt;2 then Sum(Valoare) else 0 end IncasClient,
          Case When Cineplateste = 2 then Sum(Valoare) else 0 end IncasSofer,
          Case When Cineplateste &lt;&gt;2 then Sum(ValDoc)  else 0 end FactClient,
          Case When Cineplateste = 2 then Sum(ValDoc)  else 0 end FactSofer,
          0 TotalClient, 0 TotalSofer,
          Case When Cineplateste &lt;&gt;2 then Sum(ValoareV) else 0 end IncasClientV,
          Case When Cineplateste = 2 then Sum(ValoareV) else 0 end IncasSoferV,
          Case When Cineplateste &lt;&gt;2 then Sum(ValDocV)  else 0 end FactClientV,
          Case When Cineplateste = 2 then Sum(ValDocV)  else 0 end FactSoferV
        FROM (
          SELECT CodComanda, CinePlateste,
					       Sum(ValDoc) ValDoc,
								 Sum(ValDoc/CursDoc) ValDocV,
					       Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),CodComanda)/CursDoc) ValoareV,
								 Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),CodComanda)) Valoare
          FROM (
            SELECT
              C.CodComanda, E.CodIes, Coalesce(c1.Culansare,1) CinePlateste, Coalesce(E.CursDoc,1) CursDoc,
              Sum(Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0)) ValDoc,
              Sum((Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0))/Coalesce(E.CursDoc,1)) ValDocV
            FROM comanda c
              INNER JOIN comanda1 c1 ON c1.codcomanda     = c.codcomanda
              LEFT  JOIN ieslink  l  ON l.codliniecomanda = c1.codcomanda1 AND Coalesce(l.codies1,0) &lt;&gt; 0
              LEFT  JOIN iesiri1  e1 ON e1.codies1        = l.codies1
              inner JOIN iesiri   e  ON e.codies          = e1.codies  and E.TipDoc &lt;&gt; 16
							group by C.CodComanda, E.CodIes, Coalesce(c1.Culansare,1), Coalesce(E.CursDoc,1)
          ) GROUP BY CodComanda, CinePlateste
          UNION ALL
          SELECT CodComanda, CinePlateste,
					       Sum(ValDoc) ValDoc,
								 Sum(ValDocV) ValDocV,
					       Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),CodComanda)/CursDoc) ValoareV,
								 Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),CodComanda)) Valoare
          FROM (
            SELECT
              C.CodComanda, E.CodIes, Coalesce(c1.Culansare,1) CinePlateste, Coalesce(C.Curs,1) CursDoc,
              Sum(Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0)) ValDoc,
              Sum((Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0))/Coalesce(E.CursDoc,1)) ValDocV
            FROM comanda c
              INNER JOIN comanda1 c1 ON c1.codcomanda     = c.codcomanda
              LEFT  JOIN ieslink  l  ON l.codliniecomanda = c1.codcomanda1 AND Coalesce(l.codies1,0) &lt;&gt; 0
              LEFT  JOIN iesiri1  e1 ON e1.codies1        = l.codies1
              inner JOIN iesiri   e  ON e.codies          = e1.codies and E.TipDoc = 16
							group by C.CodComanda, E.CodIes, Coalesce(c1.Culansare,1), Coalesce(C.Curs,1)
          ) GROUP BY CodComanda, CinePlateste
          UNION ALL
          Select C.CODCOMANDA, Coalesce(c1.Culansare,1) CinePlateste,
					       Sum(e1.Cant*e1.Pret) ValDoc, Sum(e1.Cant*e1.Pret/Coalesce(C.Curs,1)) ValDocV,
								 Sum(e1.Cant*e1.Pret) Valoare, Sum(e1.Cant*e1.Pret/Coalesce(C.Curs,1)) ValoareV
          FROM Emulare1 e1
            INNER JOIN Emulare  e  on e.CodEmulare   = e1.CodEmulare
            INNER JOIN Comanda1 C1 on C1.Codcomanda1 = Coalesce(e1.codcomanda1,0)
            INNER JOIN Comanda  C  on C.Codcomanda   = Coalesce(c1.codcomanda,0)
          WHERE Coalesce(e.CODMONETAR,0) = 0 group by C.CodComanda, Coalesce(c1.Culansare,1)
        ) GROUP BY CodComanda, CinePlateste
        UNION ALL
        SELECT
          CodComanda,
					0 IncasClient,  0 IncasSofer,  0 FactClient,0 FactSofer,
          valClientF + valClientcm  TotalClient, valsoferF + valsofercm TotalSofer,
					0 IncasClientV,  0 IncasSoferV,  0 FactClientV,0 FactSoferV
        FROM Rac_Rez
      ) group by CodComanda
    ) X on X.CodComanda = C.CodComanda&apos;;
	else
		ColoaneIncas  := &apos;&apos;;
		ColoaneIncasX := &apos;&apos;;
		JoinIncas     := &apos;&apos;;
	end if;


	IF NOT vAllCars THEN
    sFiltru := &apos;
    AND pa.codnparcaut IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;&apos;CODNPARCAUT&apos;&apos;)&apos;;
  END IF;

  sInsert :=&apos;INSERT INTO &apos;||TMPNAME||&apos;(

  NAV_CodDoc, NAV_TipDoc, NRDOC, DATADOC,
    PARTENER,
    TIPREZ,
    TIPINTERV, GRECHIVAL, Art, UM, UMSpec,
    GESTsursa, GESTdest, GESTtransf,
    PARTEXT,
    SOFER,
    SOFER1,
    SOFER2,
    NRauto, MARCA, MODEL,
    CANTC, CANTA, PU, ACCEPTUM1, PRETUM1, PRETinit,
    DataSTART, OraSTART,
    DataSTOP, OraSTOP,
    ANULAT,
    BLOCAT,
    OPERAT,
    INCHIS,
    Stare, SursaClient,
    Proccedat, Voucher, REF, TELEFON, EMAIL, ZBOR, ADRPREL, ADRLIVR, DATAFact,
    DATAPred,&apos;
    ||ColoaneIncas||
		&apos;OBS,
    Garantie, Judet, Clona, SeriaDoc,
    TVA, ModInchidere, Platitor, Status, Predat, X_Judet &apos;||gUserFields||&apos;
  )&apos;;


  sSelect := &apos;

  SELECT
    C.CodComanda, C.TipDoc, C.NRDOC, C.DATADOC,
    PART.DEN_PART,
    Decode(rac.tiprezervare,0,&apos;&apos;Customer&apos;&apos;,1,&apos;&apos;Shuttle&apos;&apos;,3,&apos;&apos;Courtesy&apos;&apos;,4,&apos;&apos;Uz intern&apos;&apos;,5,&apos;&apos;Reparatii&apos;&apos;,6,&apos;&apos;Abonament&apos;&apos;,7,&apos;&apos;Transfer&apos;&apos;) TipRez,
    RACIA.DENUMIRE interventie, GRE.DENUMIRE, ART.DEN_ARTICOL, UM.DEN_UM UM, UM2.DEN_UM UM1,
    RACGs.DEN_GEST, RACGd.DEN_GEST, RACGt.DEN_GEST,
    PARTD.DEN_PART,
    Case when Rac.Tiprezervare in (1,4,5,7) then RACS.Delegat  else  NPSof.Den_Part  end sofer,
    Case when Rac.Tiprezervare in (1,4,5,7) then PARTS1.delegat else NPSof1.Den_Part end sofer1,
    Case when Rac.Tiprezervare in (1,4,5,7) then PARTS2.delegat else NPSof2.Den_Part end sofer2,
    NVL(PA.NRInreg,&apos;&apos;..nedefinit..&apos;&apos;) NRInreg, racmarca.MARCA, racmodel.MODEL,
    C1.CantComandat, C1.CantAcceptat, C1.PU, C1.ACCEPTUM1, C1.PRETUM1, C1.PUCorelat,
    Trunc(rac.datastart) rac_dstart, To_char(rac.datastart,&apos;&apos;HH24:mi&apos;&apos;) rac_ostart,
    Trunc(rac.datastop ) rac_dstop,  To_char(rac.datastop ,&apos;&apos;HH24:mi&apos;&apos;) rac_ostop,
    Decode(C.ANULAT,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) Anulat,
    Decode(C.BLOCAT,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) BLOCAT,
    Decode(C.OPERAT,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) OPERAT,
    Decode(C.INCHISA,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) INCHIS,
    CASE
      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = SUM(Coalesce(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN SUM(CASE WHEN Coalesce(c1.cantacceptat, 0) &gt; 0 AND Coalesce(c1.restacceptat, 0) &gt; 0 THEN 1 ELSE 0 END) over (PARTITION BY c.codcomanda) = 0
       AND SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &lt;&gt; 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN SUM(Coalesce(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &gt; SUM(Coalesce(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
      ELSE NULL
    END,
    RAC.SursaClient,
    RAC.Proccedat, V.OBS, RAC.NR_REF, RAC.TELEFON, RAC.EMAIL, RAC.NR_ZBOR, RAC.ADRESA_PREL, RAC.ADRESA_LIVR, RAC.DATAFact,
    CASE WHEN Coalesce(RAC.Predat,0) &lt;&gt; 0 THEN RAC.DATAPRED ELSE NULL END DATAPred,&apos;
    ||ColoaneIncasX||
		&apos;
    Substr(C.OBS,1,200) Obs,
    RAC.SUMAGARANTIE, J.SimbAuto Judet,
    CASE
      WHEN Coalesce(RAC.CodRezervare,0) &gt; 0 THEN &apos;&apos;Clona&apos;&apos;
      WHEN (Select Count(*) from Rac_REZ where CodREZERVARE = C.CodComanda and CodComanda &gt; 0) &gt; 0 THEN &apos;&apos;Clonata&apos;&apos;
      ELSE &apos;&apos;Originala&apos;&apos;
    END Clona, C.SERIADOC,
    CASE
      WHEN RAC.FARATVA = 1 THEN 0
      ELSE NVL(c1.CANTACCEPTAT * c1.PU * PKG_SELECTARTICOLE.GETPROCENTTVA(art.CodArticol,Extract(year from Rac.DataStart), Extract(Month from Rac.DataStart))/ 100 , 0)  -- am luat anlucru lunalucru din comanda, nu din pkg globals
    END TVA,
    CASE
      WHEN C1.ModInchidere = 0 THEN &apos;&apos;Facturare&apos;&apos;
      WHEN C1.ModInchidere = 1 THEN &apos;&apos;Casa de marcat&apos;&apos;
    END ModInchidere,
    CASE
      WHEN C1.CuLansare = 1 THEN &apos;&apos;Client&apos;&apos;
      WHEN C1.CuLansare = 2 THEN &apos;&apos;Sofer&apos;&apos;
    END Platitor,
    Decode(PA.INACTIV,0,&apos;&apos;Activ&apos;&apos;,2,&apos;&apos;Conservare&apos;&apos;,3,&apos;&apos;Dauna totala&apos;&apos;,4,&apos;&apos;La vanzare&apos;&apos;,1,&apos;&apos;Vandut&apos;&apos;,5,&apos;&apos;Radiat&apos;&apos;) Status,
    Decode((NVL(RAC.PREDAT,0)),0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;), J.Simbauto  &apos;
    ||gUserAlias||
    &apos;
  FROM comanda c
    INNER JOIN rac_rez rac ON rac.codcomanda = c.codcomanda
    INNER JOIN NAGENDA Ax ON Ax.CodGest = Coalesce(rac.codgestsursa,0) AND Ax.CodGest IS NOT NULL
    INNER JOIN NLocalit Lx on Lx.CodLocalit = Ax.Codlocalit
    INNER JOIN NJudet J on J.CodJudet = Lx.CodJudet
    LEFT  JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda&apos;
    ||JoinIncas||
	 &apos;
    LEFT  JOIN nartobj          obj      ON obj.codobiect            = c1.codobiect
    LEFT  JOIN nart             art      ON obj.codarticol           = art.codarticol
    LEFT  JOIN npart            part     ON part.codpart             = c.PARTENER
    LEFT  JOIN npart            partd    ON partd.codpart            = rac.CODPARTEXT
    LEFT  JOIN nparttr          racs     ON racs.Codparttr           = C.Delegat
    LEFT  JOIN nparttr          parts1   ON parts1.codparttr         = rac.coddelegat1
    LEFT  JOIN nparttr          parts2   ON parts2.codparttr         = rac.coddelegat2
    LEFT  JOIN npart            NPSof    ON NPSof.Codpart            = rac.CodSofer
    LEFT  JOIN npart            NPSof1   ON NPSof1.Codpart           = rac.CodSofer1
    LEFT  JOIN npart            NPSof2   ON NPSof2.Codpart           = rac.CodSofer2
    LEFT  JOIN nechiv           e        ON e.codobiect              = c1.codobiect
    LEFT  JOIN grechiv          gre      ON gre.codgrechiv           = e.codgrupa
    LEFT  JOIN nparcaut         pa       ON pa.codnparcaut           = c.mijltransp
    LEFT  JOIN ninterventiiauto racia    ON racia.codinterventiiauto = rac.codinterventie
    LEFT  JOIN num              um       ON um.codum                 = art.um
    LEFT  JOIN num              um2      ON um2.codum                = art.um1
    LEFT  JOIN nmarciauto       racmarca ON racmarca.codmarciauto    = rac.codmarca
    LEFT  JOIN nmodeleauto      racmodel ON racmodel.codmodeleauto   = rac.codmodel
    LEFT  JOIN ngest            racgs    ON racgs.codgest            = rac.codgestsursa
    LEFT  JOIN ngest            racgd    ON racgd.codgest            = rac.codgestdest
    LEFT  JOIN ngest            racgt    ON racgt.codgest            = c.codgest
    LEFT  JOIN voucher          v        ON v.codvoucher             = rac.codvoucher
    &apos;||gSuplJoins||&apos;
    WHERE C.TipDoc = 94 and c.datadoc IS NOT NULL &apos;||sFiltru2||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;C&apos;)||
    sFiltru;

  PKG_RAC_REZ.SET_RAC_DATASTART(PKG_LIST_ALEGPERIOADA.getDataS);

  delete from x;
  Insert into x values (&apos;zssszzaStatus&apos;, sSelect);commit;

	LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_ComandRAC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMANDREPRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D1D90657C5A7ADA0809F2C283E92D4D66F0CD80</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMANDRepRAC IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sPer     VARCHAR2(1000);

BEGIN
  gSuplCols := &apos;comanda c,RAC_REZ RAC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
        NAV_CodDoc,    
        NAV_TipDoc,    
        SERIADOC,      
        NRDOC,         
        DATADOC,       
        ANULAT,        
        OPERAT,        
        CLIENT,        
        CIFCLIENT,     
        MODEL,         
        MARCA,         
        NRINREG,       
        ANFABRICATIE,  
        CULOAREC,      
        SERIECAROSERIE,
        SERIEMOTOR,    
        LUCRARE,       
        OBSERVATII,    
        GARANTIE,      
        OPERATIE,      
        EXECUTAT,      
        Datastart,     
        DataPred,      
        Gest_Sursa,
        Tip &apos;||gUserFields||&apos;     
    )&apos;;
/*
        Decode(C.Operat,0,&apos;&apos;Da&apos;&apos;,1,&apos;&apos;Nu&apos;&apos;) Operat,    
        Decode(C.Anulat,0,&apos;&apos;Da&apos;&apos;,1,&apos;&apos;Nu&apos;&apos;) Anulat,
        Decode(C.Inchisa,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Inchis,
        
        Silvia zice ca la operat si anulat erau inversate valorile, la inchisa nu...
*/

  sSelect := &apos;
     SELECT
        C.CodComanda,
        C.TipDoc,
        C.SeriaDoc,
        C.NrDoc,
        C.DataDOC,
        Decode(C.Anulat,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) Anulat,
        Decode(C.Operat,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;) Operat,    
        NPart.Den_Part Client,
        CIF.CodFiscal CIFClient,
        NMo.Model,
        NMa.Marca,
        NPA.NRINREG,
        NPA.ANF AnFabricatie,
        NPA.CULOAREC,
        NPA.SERIEC SerieCaroserie,
        NPA.Seriem SerieMotor,
        LS.Denumire Lucrare,
        C2.Obs Observatii,
        Decode(C2.Garantie,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
        NO.Denumire Operatie,
        Decode(C3.Executat,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
        trunc(RAC.DataStart),
        trunc(RAC.DataPred),
        NGR.DEN_GEST GEST_Sursa,
        Decode(C3.Tip,0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;) &apos;||gUserAlias||&apos;
     from comanda c
        LEFT JOIN RAC_REZ RAC on RAC.CODCOMANDA = C.CODCOMANDA      
        Left join NGest NGR on NGR.CodGest = RAC.CodGestSursa
        LEFT JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
        LEFT JOIN nartobj nao ON nao.codobiect = c1.codobiect
        Left join Comanda2 C2 on C2.CodComanda = C.CodComanda
        Left join Comanda3 C3 on C3.CodComanda2 = C2.CodComanda2
        left join Nparccom NPC on NPC.CodComanda = C.CodComanda
        Left join NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
        Left join Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
        Left join NModeleauto NMo on NMo.CodModeleauto=NPA.Model
        Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
        Left join Npart NPart on NPart.CodPart = C.Partener
        Left join NPartCodFisc CIF on CIF.CODPART = C.Partener
        Left join Npart NP on NP.CodPart = C2.Codpart
        Left join NPartCodFisc CIF2 on CIF2.CODPART = C2.Codpart
        Left join NGest NG on NG.CodGest = C.CodGest
        Left join NOper NO on NO.CODOP = C3.CodOperatie&apos;||
        gSuplJoins||&apos;
      WHERE C.TipDoc = 94
      AND RAC.TipRezervare = 5
      AND C.DataDoc &apos;||sPer||&apos;
		UNION ALL	
  SELECT 
        NPA.CodNparcaut CodComanda,
        505 TipDoc,
        null SeriaDoc,
        null NrDoc,
        null DataDOC,
        &apos;&apos;NU&apos;&apos; Anulat,
        &apos;&apos;DA&apos;&apos; Operat,    
        null Client,
        null CIFClient,
        NMo.Model,
        NMa.Marca,
        NPA.NRINREG,
        NPA.ANF AnFabricatie,
        NPA.CULOAREC,
        NPA.SERIEC SerieCaroserie,
        NPA.Seriem SerieMotor,
        LS.Denumire Lucrare,
        C2.Obs Observatii,
        Decode(C2.Garantie,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
        NO.Denumire Operatie,
        Decode(C3.Executat,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
        null DataStart,
        null DataPred,
        null GEST_Sursa,
        Decode(C3.Tip,0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;) &apos;||gUserAlias||&apos;
     from Comanda2 C2 
        Left join Comanda3 C3 on C3.CodComanda2 = C2.CodComanda2
        Left join Comanda C on C3.CodComanda = C.CodComanda
        LEFT JOIN RAC_REZ RAC on RAC.CODCOMANDA = C.CODCOMANDA
        Left join NparcAut NPA on NPA.CodNparcaut = C2.CodNparcaut
        Left join Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
        Left join NModeleauto NMo on NMo.CodModeleauto=NPA.Model
        Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
        Left join Npart NP on NP.CodPart = C2.Codpart
        Left join NPartCodFisc CIF2 on CIF2.CODPART = C2.Codpart
        Left join NOper NO on NO.CODOP = C3.CodOperatie&apos;||
        gSuplJoins||&apos;
      WHERE Nvl(C2.CodComanda, 0) = 0
      AND (C3.DataStart is null or C3.DataStart &apos;||sPer||&apos;)&apos;;

	LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_COMANDRepRAC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMANDSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9B250A3203E496F81171648E877A4583290A4F3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMANDSA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
  sPer    VARCHAR2(1000);
	gDataS	DATE := PKG_LIST_ALEGPERIOADA.getDataS;
	gDataF	DATE := PKG_LIST_ALEGPERIOADA.getDataF;

BEGIN
  gSuplCols := &apos;COMANDA C, COMANDA2 C2, COMANDA3 C3, NPARCCOM NPC, NPARCAUT NPA, NMARCIAUTO NMA, NMODELEAUTO NMO, TIPLUCRARISA LS, NPART NP, NPARTCODFISC CIF, NPART NP2, NPARTCODFISC CIF2, NGEST NG, NOPER NO&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NSUBUNIT&apos;, &apos;SUB&apos;,  &apos;SUB.CODSUBUNIT = C.SUBUNITATEA&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF gDataS = gDataF
  THEN sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(gDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(gDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(gDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    NAV_CodDoc, NAV_TipDoc, SERIADOC, NRDOC, DATADOC,
    ANULAT, OPERAT, INCHIS,
    CLIENT, CIFCLIENT,
    MODEL, MARCA, NRINREG, ANFABRICATIE, CULOAREC, SERIECAROSERIE, SERIEMOTOR, LUCRARE, OBSERVATII,
    PLATITOR, CIFPLATITOR, GARANTIE,
    OPERATIE, DESCRIERE, DATAFIN,
    TIP, EXECUTAT, GESTIUNE, TIPCOLOANA&apos;||
    gUserFields||&apos;
  )
  SELECT
    C.CodComanda, C.TipDoc, C.SeriaDoc, C.NrDoc, C.DataDOC,
    CASE WHEN C.Operat = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END AS OPERAT, CASE WHEN C.Anulat = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END AS Anulat, CASE WHEN C.Inchisa = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END AS Inchis,
    CASE WHEN C.FaraFactura = 1 THEN &apos;&apos;Comanda interna&apos;&apos; ELSE NP.Den_Part END AS Client, CIF.CodFiscal CIFClient,
    NMo.Model, NMa.Marca, NPA.NRINREG, NPA.ANF AnFabricatie, NPA.CULOAREC, NPA.SERIEC SerieCaroserie, NPA.Seriem SerieMotor, LS.Denumire Lucrare, C2.Obs Observatii,
    Coalesce(NP2.DEN_PART,NP.Den_Part) Platitor, Coalesce(CIF2.CodFiscal,CIF.CodFiscal) CIFPlatitor, CASE WHEN C2.Garantie = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END Garantie,
    NO.Denumire Operatie, C3.Obs Descriere, C3.Data DataFin,
    CASE C3.Tip WHEN 0 THEN &apos;&apos;Solicitare&apos;&apos; WHEN 1 THEN &apos;&apos;Constatare&apos;&apos; WHEN 2 THEN &apos;&apos;Nefacturabila&apos;&apos; END AS Tip,
    CASE WHEN C3.Executat = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END AS Executat, NG.Den_gest Gestiune, NPC.TIPCOMANDA TIPCOLOANA&apos;||
    gUserAlias||&apos;
  FROM comanda c
    LEFT JOIN Comanda2     C2   ON C2.CodComanda = C.CodComanda
    LEFT JOIN Comanda3     C3   ON C3.CodComanda2 = C2.CodComanda2
    LEFT JOIN Nparccom     NPC  ON NPC.CodComanda = C.CodComanda
    LEFT JOIN NparcAut     NPA  ON NPA.CodNparcaut = NPC.CodNparcaut
    LEFT JOIN Nmarciauto   NMa  ON Nma.Codmarciauto=NPA.Marca
    LEFT JOIN NModeleauto  NMo  ON NMo.CodModeleauto=NPA.Model
    LEFT JOIN Tiplucrarisa LS   ON LS.Codtiplucrare=C2.Codlucrare
    LEFT JOIN Npart        NP   ON NP.CodPart = C.Partener
    LEFT JOIN NPartCodFisc CIF  ON CIF.CODPART = C.Partener
    LEFT JOIN Npart        NP2  ON NP2.CodPart = C2.Codpart
    LEFT JOIN NPartCodFisc CIF2 ON CIF2.CODPART = C2.Codpart
    LEFT JOIN NGest        NG   ON NG.CodGest = C.CodGest
    LEFT JOIN NOper        NO   ON NO.CODOP = C3.CodOperatie&apos;||
    gSuplJoins||&apos;
  WHERE C.TipDoc = 92
    AND C.DataDoc &apos;||sPer||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

	LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_List_Struct.AdunaColoanele;
END;

end PKG_LIST_BASE_COMANDSA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMANDSADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E73315414449D1384F964842878D486B74171EE1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMANDSADOC IS

  vCodDoc     NUMBER(20);
  vCodPart    NUMBER(20);
	vCodSediu   NUMBER(20);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc NUMBER, pCodPart NUMBER, pCodSediu NUMBER) IS
BEGIN
  vCodDoc   := pCodDoc;
  vCodPart  := pCodPart;
  vCodSediu := pCodSediu;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  pkg_globals.setseparator(&apos;;&apos;);
  gSuplCols :=
   &apos;COMANDA C, COMANDA1 C1, NARTOBJ O, NART A, NCLASEA CA,COMANDA3 C3, COMANDA2 C2, CMDPRODMAT CPM, Tiplucrarisa LS, Noper OP, NUM1 U1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

--separ in 3 bucati pentru a surprinde si cazul cu centralizarea
--serviciile din operatii
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    LUCRARE,
    OPERATIE,
    OBSERVATII,
    GARANTIE,
    DESCRIERE,
    DATAFIN,
    TIP,
    EXECUTAT,
    ARTICOL,
    PU,
    CANTITATE,
    UM,
    VALOARE,
    TVA,
    CLART,
    SIMBCLART,
    MODINCHIDERE,
    CODEXTERN &apos;|| gUserFields||&apos;)
  SELECT
    Coalesce(LS.Denumire,&apos;&apos;-&apos;&apos;) Lucrare,
    Coalesce(Op.Denumire,&apos;&apos;-&apos;&apos;) Operatie,
    Coalesce(C2.Obs,&apos;&apos;-&apos;&apos;) Observatii,
    Decode(Coalesce(C2.Garantie,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
    Coalesce(C3.Obs,&apos;&apos;-&apos;&apos;) Descriere,
    C3.Data DataFin,
    Decode(Coalesce(C3.Tip,0),0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;) Tip,
    Decode(Coalesce(C3.Executat,0) ,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
    O.denumire Articol,
    C1.PU,
    c1.CANTACCEPTAT / u1.Paritate Cantitate,
    u1.Den_UM1 UM,
    c1.CANTACCEPTAT * c1.PU valoare,
    Coalesce( c1.CANTACCEPTAT * c1.PU *
				  PKG_SELECTARTICOLE.GETPROCENTTVA( a.CodArticol,
						                                pkg_globals.getanlucru,
																						pkg_globals.getlunalucru) /100,0),
    ca.den_clasea CLART, ca.simbol SIMBCLART,
    DECODE(Coalesce(C1.ModInchidere,0),0,&apos;&apos;Factura&apos;&apos;,1,&apos;&apos;Casa de marcat&apos;&apos;,2,&apos;&apos;Bon consum&apos;&apos;) MODINCHIDERE,
    O.CodExtern &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
    INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
    INNER JOIN Nart A on A.CodArticol = o.CodArticol
    INNER join Comanda3 C3 on C3.CodComanda1 = C1.CodComanda1      --serviciu de operatie legat de comanda1
    INNER join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2      -- lucrare
    LEFT  JOIN nclasea ca ON ca.codclasea = A.clasa
    Left join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
    Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
    Left join Noper OP on Op.Codop = C3.CODOPERATIE
    LEFT JOIN NUM1 U1 ON u1.CodUM1 = C1.UmSec&apos;||
    gSuplJoins||&apos;
  WHERE C.Codcomanda = &apos;||vCodDoc||&apos;
		AND C.TipDoc = 92
		AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.Partener = &apos;||vCodPart||&apos; OR
         C2.Codpart = &apos;||vCodPart||&apos;
        )
		AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.CodLocatie = &apos;||vCodSediu||&apos; OR
         C2.CodLocatie = &apos;||vCodSediu||&apos;
        )&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

--materialele necentralizate libere
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    LUCRARE,
    OPERATIE,
    OBSERVATII,
    GARANTIE,
    DESCRIERE,
    DATAFIN,
    TIP,
    EXECUTAT,
    ARTICOL,
    PU,
    CANTITATE,
    UM,
    VALOARE,
    TVA,
    CLART,
    SIMBCLART,
    MODINCHIDERE,
    CODEXTERN &apos;|| gUserFields||&apos;)
  SELECT
    Coalesce(LS.Denumire,&apos;&apos;-&apos;&apos;) Lucrare,
    Coalesce(Op.Denumire,&apos;&apos;-&apos;&apos;) Operatie,
    Coalesce(C2.Obs,&apos;&apos;-&apos;&apos;) Observatii,
    Decode(Coalesce(C2.Garantie,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
    Coalesce(C3.Obs,&apos;&apos;-&apos;&apos;) Descriere,
    C3.Data DataFin,
    Decode(Coalesce(C3.Tip,0),0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;) Tip,
    Decode(Coalesce(C3.Executat,0) ,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
    O.denumire Articol,
    C1.PU,
    c1.CANTACCEPTAT / u1.Paritate Cantitate,
    u1.Den_UM1 UM,
    c1.CANTACCEPTAT * c1.PU valoare,
    Coalesce( c1.CANTACCEPTAT * c1.PU *
          PKG_SELECTARTICOLE.GETPROCENTTVA( a.CodArticol,
                                            pkg_globals.getanlucru,
                                            pkg_globals.getlunalucru) /100,0),
    ca.den_clasea CLART, ca.simbol SIMBCLART,
    DECODE(Coalesce(C1.ModInchidere,0),0,&apos;&apos;Factura&apos;&apos;,1,&apos;&apos;Casa de marcat&apos;&apos;,2,&apos;&apos;Bon consum&apos;&apos;) MODINCHIDERE,
    O.CodExtern &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
    INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
    INNER JOIN Nart A on A.CodArticol = o.CodArticol
    LEFT  join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
    LEFT  join Comanda3 C3 on C3.CodComanda1 = C1.CodComanda1
    LEFT  join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2   --lucrare
    LEFT JOIN nclasea ca ON ca.codclasea = A.clasa
    Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
    Left join Noper OP on Op.Codop = C3.CODOPERATIE
    LEFT JOIN NUM1 U1 ON u1.CodUM1 = C1.UmSec&apos;||
    gSuplJoins||&apos;
  WHERE C.Codcomanda = &apos;||vCodDoc||&apos;
    AND CPM.CODCMDPRODMAT IS NULL
    AND C3.CODCOMANDA3 IS NULL
    AND C.TipDoc = 92 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer); 

--materialele necentralizate
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    LUCRARE,
    OPERATIE,
    OBSERVATII,
    GARANTIE,
    DESCRIERE,
    DATAFIN,
    TIP,
    EXECUTAT,
    ARTICOL,
    PU,
    CANTITATE,
    UM,
    VALOARE,
    TVA,
    CLART,
    SIMBCLART,
    MODINCHIDERE,
    CODEXTERN &apos;|| gUserFields||&apos;)
  SELECT
    Coalesce(LS.Denumire,&apos;&apos;-&apos;&apos;) Lucrare,
    Coalesce(Op.Denumire,&apos;&apos;-&apos;&apos;) Operatie,
    Coalesce(C2.Obs,&apos;&apos;-&apos;&apos;) Observatii,
    Decode(Coalesce(C2.Garantie,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
    Coalesce(C3.Obs,&apos;&apos;-&apos;&apos;) Descriere,
    C3.Data DataFin,
    Decode(Coalesce(C3.Tip,0),0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;) Tip,
    Decode(Coalesce(C3.Executat,0) ,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
    O.denumire Articol,
    C1.PU,
    c1.CANTACCEPTAT / u1.Paritate Cantitate,
    u1.Den_UM1 UM,
    c1.CANTACCEPTAT * c1.PU valoare,
    Coalesce( c1.CANTACCEPTAT * c1.PU *
          PKG_SELECTARTICOLE.GETPROCENTTVA( a.CodArticol,
                                            pkg_globals.getanlucru,
                                            pkg_globals.getlunalucru) /100,0),
    ca.den_clasea CLART, ca.simbol SIMBCLART,
    DECODE(Coalesce(C1.ModInchidere,0),0,&apos;&apos;Factura&apos;&apos;,1,&apos;&apos;Casa de marcat&apos;&apos;,2,&apos;&apos;Bon consum&apos;&apos;) MODINCHIDERE,
    O.CodExtern &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
    INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
    INNER JOIN Nart A on A.CodArticol = o.CodArticol
    INNER join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
    INNER join Comanda3 C3 on C3.CodComanda3 = CPM.CodComanda3   --operatia materialului
    INNER join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2   --lucrare
    LEFT JOIN nclasea ca ON ca.codclasea = A.clasa
    Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
    Left join Noper OP on Op.Codop = C3.CODOPERATIE
    LEFT JOIN NUM1 U1 ON u1.CodUM1 = C1.UmSec&apos;||
    gSuplJoins||&apos;
  WHERE C.Codcomanda = &apos;||vCodDoc||&apos;
    AND (SELECT COUNT(*) FROM CMDPRODMAT CMD WHERE CMD.CODCOMANDA1 = C1.CODCOMANDA1) = 1
    AND C.TipDoc = 92
    AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.Partener = &apos;||vCodPart||&apos; OR
         C2.Codpart = &apos;||vCodPart||&apos;
        )
		AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.CodLocatie = &apos;||vCodSediu||&apos; OR
         C2.CodLocatie = &apos;||vCodSediu||&apos;
        )&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

--materialele centralizate  
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    LUCRARE,
    OPERATIE,
    OBSERVATII,
    GARANTIE,
    DESCRIERE,
    DATAFIN,
    TIP,
    EXECUTAT,
    ARTICOL,
    PU,
    CANTITATE,
    UM,
    VALOARE,
    TVA,
    CLART,
    SIMBCLART,
    MODINCHIDERE,
    CODEXTERN &apos;|| gUserFields||&apos;)
  SELECT
    CENTR.Lucrare,
    CENTR.Operatie,
    CENTR.Observatii,
    CENTR.Garantie,
    CENTR.Descriere,
    CENTR.DataFin,
    CENTR.Tip,
    CENTR.Executat,
    O.denumire Articol,
    C1.PU,
    c1.CANTACCEPTAT / u1.Paritate Cantitate,
    u1.Den_UM1 UM,
    c1.CANTACCEPTAT * c1.PU valoare,
    Coalesce( c1.CANTACCEPTAT * c1.PU *
          PKG_SELECTARTICOLE.GETPROCENTTVA( a.CodArticol,
                                            pkg_globals.getanlucru,
                                            pkg_globals.getlunalucru) /100,0),
    ca.den_clasea CLART, ca.simbol SIMBCLART,
    DECODE(Coalesce(C1.ModInchidere,0),0,&apos;&apos;Factura&apos;&apos;,1,&apos;&apos;Casa de marcat&apos;&apos;,2,&apos;&apos;Bon consum&apos;&apos;) MODINCHIDERE,
    O.CodExtern &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
    INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
    INNER JOIN Nart A on A.CodArticol = o.CodArticol
    INNER JOIN (
      SELECT
        stragg3200(DISTINCT Coalesce(LSX.Denumire,&apos;&apos;-&apos;&apos;)) Lucrare,
        stragg3200(DISTINCT Coalesce(OpX.Denumire,&apos;&apos;-&apos;&apos;)) Operatie,
        stragg3200(DISTINCT Coalesce(C2X.Obs,&apos;&apos;-&apos;&apos;)) Observatii,
        stragg3200(DISTINCT Decode(Coalesce(C2X.Garantie,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;)) Garantie,
        stragg3200(DISTINCT Coalesce(C3X.Obs,&apos;&apos;-&apos;&apos;)) Descriere,
        max(C3X.Data) DataFin,
        stragg3200(DISTINCT Decode(Coalesce(C3X.Tip,0),0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;)) Tip,
        stragg3200(DISTINCT Decode(Coalesce(C3X.Executat,0) ,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;)) Executat,
        CPMX.CODCOMANDA1
      FROM CMDPRODMAT CPMX
           INNER join Comanda3 C3X on C3X.CodComanda3 = CPMX.CodComanda3
           INNER join Comanda2 C2X on C2X.CodComanda2 = C3X.CodComanda2
           INNER JOIN COMANDA1 C1X ON C1X.CODCOMANDA1 = CPMX.CODCOMANDA1
           Left join Tiplucrarisa LSX on LSX.Codtiplucrare=C2X.Codlucrare
           Left join Noper OPX on OpX.Codop = C3X.CODOPERATIE
      WHERE C1X.CODCOMANDA = &apos;||vCodDoc||&apos;
      GROUP BY CPMX.CODCOMANDA1
    ) CENTR ON CENTR.CODCOMANDA1 = C1.CODCOMANDA1
    left join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1 - C1.CodComanda1
    left join Comanda3 C3 on C3.CodComanda3 = CPM.CodComanda3
    left join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2
    LEFT JOIN nclasea ca ON ca.codclasea = A.clasa
    Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
    Left join Noper OP on Op.Codop = C3.CODOPERATIE
    LEFT JOIN NUM1 U1 ON u1.CodUM1 = C1.UmSec&apos;||
    gSuplJoins||&apos;
  WHERE C.Codcomanda = &apos;||vCodDoc||&apos;
    AND (SELECT COUNT(*) FROM CMDPRODMAT CMD WHERE CMD.CODCOMANDA1 = C1.CODCOMANDA1) &gt; 1
    AND C.TipDoc = 92
    AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.Partener = &apos;||vCodPart||&apos; OR
         C2.Codpart = &apos;||vCodPart||&apos;
        )
		AND (Coalesce(C.FaraFactura, 0) = 1 OR
         C.CodLocatie = &apos;||vCodSediu||&apos; OR
         C2.CodLocatie = &apos;||vCodSediu||&apos;
        )&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  pkg_list_base_comandSAdoc.add_list_params;
  COMMIT;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  -- apelat si din PKG_LIST_BASE_COMETICHETE
  pkg_list_Struct.GOLESTE_PARAM;

  For v_rec IN (
    SELECT
      PC.Delegat PCNume,  PC.TELEFON PCTel, PC.EMAIL PCEmail
    FROM NPART P
      LEFT JOIN NPartTR PC ON PC.CodPart = P.CodPart
    WHERE P.CodPart = vCodPart
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,         v_rec.PCNume);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Telefon&apos;, v_rec.PCTel);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Email&apos;,   v_rec.PCEmail);
  END LOOP;

  For v_rec IN (
    SELECT
      PB.ContBanca PContBanca, PB.Sucursala PSucursala, PBK.DENUMIRE PDENBANCA, PBK.SIMBOL PSIMBBANCA
    FROM NPART P
      LEFT JOIN NPARTB PB ON PB.CODPART = P.CodPart AND PB.IMPLICIT = 1
      LEFT JOIN NBANK PBK ON PBK.CODBANK = PB.CODBANK
    WHERE P.CodPart = vCodPart
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA Cont client&apos;,           v_rec.PContBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA Client denumire&apos;,       v_rec.PDenBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA Client simbol&apos;,         v_rec.PSimbBanca);
  END LOOP;

  For v_rec IN (
    SELECT
      P.DEN_PART, PCF.CODFISCAL PCIF, P.AUTORIZATIE PAUTORIZATIE, P.REGCOM PREGCOM, P.OBS PARTOBS, P.CODSTATISTICBNR PCODSTATISTICBNR
    FROM NPART P
      LEFT JOIN NPartCodFisc PCF ON PCF.CODPART = P.CodPart AND PCF.Principal = 1
    WHERE P.CodPart = vCodPart
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER&apos;,                    v_rec.DEN_PART);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER CIF&apos;,                v_rec.PCif);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER R.C. &apos;,              v_rec.PRegCom);
  END LOOP;

  FOR v_rec IN (
    SELECT
      TP.Delegat TNume,
      TP.Doc TDoc, TP.SerieDoc||&apos; &apos;||TP.NrDoc TCI, TP.Eliberat TEliberat, TP.DataDoc TDataDoc, TP.MijlTransp TMijlTransp, TP.NrTransp TNrTransp, TP.CNP TCNP, TP.TELEFON TTEL
    FROM Comanda C
      LEFT JOIN NPARTTR TP ON TP.CODPARTTR = C.DELEGAT
    WHERE C.CodComanda = vCodDoc
      AND C.Tipdoc = 92
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT Nume&apos;,                v_rec.TNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CNP&apos;,                 v_rec.TCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CI&apos;,                  v_rec.TCI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT TIP CI&apos;,              v_rec.TDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT Telefon&apos;,             v_rec.TTEL);
  END LOOP;

  FOR v_rec IN (
    SELECT
      C.PrefixDoc, C.SeriaDoc, C.NrDoc, C.DataDoc, C.Obs,
      CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET, CAR.SERIE SERIECARNET,
      DECODE(TCMD.TIPPLATA,0,&apos;Nedefinit&apos;,1,&apos;Numerar&apos;,2,&apos;Ordin plata&apos;,3,&apos;CEC&apos;,4,&apos;Bilet la ordin&apos;,5,&apos;Compensare&apos;,6,&apos;Majorari&apos;,7,&apos;CEC/BO girat&apos;,8,&apos;BO avalizat&apos;) TipPlata,
      Coalesce( NullIf(C.CURS,0),1) CURS, M.DEN_MONEDA,
      SSUB.TELEFON TelSUB
    FROM Comanda C
      LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = C.CARNETDOC
      LEFT JOIN TERMENECMD TCMD on TCMD.CodComanda = C.CodComanda
      LEFT JOIN NMONEDE M ON M.CODMONEDA = C.MONEDA

      LEFT JOIN NAGENDA SSUB ON SSUB.CODSUBUNIT = C.SUBUNITATEA

    WHERE C.CodComanda = vCodDoc
      AND C.Tipdoc = 92
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Prefix&apos;,             v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Serie&apos;,              v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Nr&apos;,                 v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Data&apos;,               v_rec.DataDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Tip plata&apos;,          v_rec.TipPlata);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Curs Valutar&apos;,       v_rec.Curs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT Moneda&apos;,             v_rec.Den_moneda);

    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE Telefon&apos;,          v_rec.TelSUB);
  END LOOP;

  For v_rec IN (
    SELECT
      SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.FAX SSOCFax, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.Email SSOCEmail,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, NULL) SSOCAdresa_No_Cp,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
      LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara
    FROM NPART P
      LEFT JOIN NAGENDA SSOC ON SSOC.CODPART = P.CodPart AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = Coalesce(SSOC.CODLOCALIT, 0)
      LEFT JOIN NJUDET JSOC ON JSOC.CODJUDET = Coalesce(LSOC.CODJUDET, 0)
      LEFT JOIN NTARI TSOC ON TSOC.CODTARA = Coalesce(LSOC.CODTARA, 0)
    WHERE P.CodPart = vCodPart
      AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;ADRESA Sediu&apos;,  	            v_rec.SSocAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU Localitatea&apos;,           v_rec.SSocLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU Judetul&apos;,               v_rec.SSocSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU Den judet&apos;,             v_rec.SSocJudet);
  END LOOP;

  FOR v_rec IN (
    SELECT
      ROUND(SUM(c1.PU*c1.cantacceptat),2) Manopera,
      ROUND(SUM(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) TVAManopera,
      ROUND(SUM(c1.PU*c1.cantacceptat)+sum(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) ManoperaCT
    FROM COMANDA1 c1
      LEFT JOIN comanda c on C.codcomanda = C1.codcomanda
      LEFT JOIN Comanda3 C3 on C3.CodComanda1 = C1.CodComanda1      --serviciu de operatie legat de comanda1
      LEFT JOIN Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2      -- lucrare
      LEFT JOIN CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
      LEFT JOIN Comanda3 C3x on C3x.CodComanda3 = CPM.CodComanda3   --operatia materialului
      LEFT JOIN Comanda2 C2x on C2x.CodComanda2 = C3x.CodComanda2   --lucrare
      INNER JOIN nartobj nao on c1.codobiect=nao.codobiect
      INNER JOIN nart na on na.codarticol=nao.codarticol
    WHERE C.CodComanda = vCodDoc
      and na.tiparticol = 1 --manopera
      And C.Tipdoc = 92
      AND (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.Partener = vCodPart) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = vCodPart))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = vCodPart))
                     )
      AND (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.CodLocatie = vCodSediu) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = vCodSediu))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = vCodSediu))
                     )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Manopera&apos;,        v_rec.Manopera);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE TVA Manopera&apos;,    v_rec.TVAManopera);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Manopera cu TVA&apos;, v_rec.ManoperaCT);
    EXIT;
  END LOOP;

  For v_rec IN (
    select
      ROUND(sum(c1.PU*c1.cantacceptat),2) Materiale,
      ROUND(sum(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) TVAMateriale,
      ROUND(sum(c1.PU*c1.cantacceptat)+sum(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) MaterialeCT
    from COMANDA1 c1
      left join comanda c on C.codcomanda = C1.codcomanda
      Left join Comanda3 C3 on C3.CodComanda1 = C1.CodComanda1      --serviciu de operatie legat de comanda1
      Left join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2      -- lucrare
      left join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
      Left join Comanda3 C3x on C3x.CodComanda3 = CPM.CodComanda3   --operatia materialului
      Left join Comanda2 C2x on C2x.CodComanda2 = C3x.CodComanda2   --lucrare
      inner join nartobj nao on c1.codobiect=nao.codobiect
      inner join nart na on na.codarticol=nao.codarticol
    WHERE C.CodComanda = vCodDoc
      and na.tiparticol = 0 --materiale
      And C.Tipdoc = 92
      and (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.Partener = vCodPart) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = vCodPart))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = vCodPart))
                     )
      AND (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.CodLocatie = vCodSediu) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = vCodSediu))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = vCodSediu))
                     )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Materiale&apos;,        v_rec.Materiale);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE TVA Materiale&apos;,     v_rec.TVAMateriale);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Materiale cu TVA&apos;,   v_rec.MaterialeCT);
    EXIT;
  END LOOP;

  For v_rec IN (
    SELECT
      ROUND(sum(c1.PU*c1.cantacceptat),2) Deviz,
      ROUND(sum(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) TVADeviz,
      ROUND(sum(c1.PU*c1.cantacceptat)+sum(c1.PU*c1.cantacceptat * PKG_SELECTARTICOLE.GETPROCENTTVA( NA.CodArticol,pkg_globals.getanlucru,pkg_globals.getlunalucru) /100),2) DevizCT
    from COMANDA1 c1
      left join comanda c on C.codcomanda = C1.codcomanda
      Left join Comanda3 C3 on C3.CodComanda1 = C1.CodComanda1      --serviciu de operatie legat de comanda1
      Left join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2      -- lucrare
      left join CMDProdMat CPM on CPM.CodComanda1 = C1.CodComanda1  --material legat de comanda1
      Left join Comanda3 C3x on C3x.CodComanda3 = CPM.CodComanda3   --operatia materialului
      Left join Comanda2 C2x on C2x.CodComanda2 = C3x.CodComanda2   --lucrare
      inner join nartobj nao on c1.codobiect=nao.codobiect
      inner join nart na on na.codarticol=nao.codarticol
    WHERE C.CodComanda = vCodDoc
      And C.Tipdoc = 92
      and (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.Partener = vCodPart) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.Codpart,0) = vCodPart))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.Codpart,0) = vCodPart))
                     )
      and (    Coalesce(C.FaraFactura, 0) = 1
               or
                 (
                  (C.CodLocatie = vCodSediu) and ( ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = 0))
                                                    or
                ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = 0))
                or
                  ((C2.Codcomanda2 is null)and(C2x.Codcomanda2 is null))
                 )
                     )
                     or
                     ((C2.Codcomanda2 is not null)and(Coalesce(C2.CodLocatie,0) = vCodSediu))
                     or
                     ((C2x.Codcomanda2 is not null)and(Coalesce(C2x.CodLocatie,0) = vCodSediu))
                     )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Deviz&apos;,        v_rec.Deviz);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE TVA Deviz&apos;,     v_rec.TVADeviz);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE Deviz cu TVA&apos;,   v_rec.DevizCT);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      C.PrefixDoc, C.SeriaDoc, C.NrDoc, C.DataDoc, C.Obs ObsC,
      NPart.Den_Part Client,
      CIF.CodFiscal CIFClient,
      NMo.Model,
      NMa.Marca,
      NPA.NRINREG,
      NPA.SERIEC SerieCaroserie,
      --
      NPA.Cilindree,
      NPA.SursaE,
      NPA.CULOAREC,
      NPA.ANF AnFabricatie,
      NPA.Seriem SerieMotor,
      Decode(Coalesce(NPC.ProbaDrum,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) ProbaDrum,
      Decode(Coalesce(NPC.PieseClient,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) PieseClient,
      Decode(Coalesce(NPC.InmatrRom,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) InmatrRom,
      Decode(Coalesce(NPC.Spalare,0),0,&apos;Nu&apos;,1,&apos;Da&apos;)  Spalare ,
      Decode(Coalesce(NPC.Inspectie,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) Inspectie,
      NPC.Nivrezervor,
      NPC.KMBORD,
      --
      C2.Obs Observatii,
      Coalesce(NP.DEN_PART,NPart.Den_Part) Platitor,
      Coalesce(CIF2.CodFiscal,CIF.CodFiscal) CIFPlatitor,
      Decode(Coalesce(C2.Garantie,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) Garantie,
      NO.Denumire Operatie,
      C3.Obs Descriere,
      C3.Data DataFin,
      Decode(Coalesce(C3.Tip,0),0,&apos;Solicitare&apos;,1,&apos;Constatare&apos;) Tip,
      Decode(Coalesce(C3.Executat,0),0,&apos;Nu&apos;,1,&apos;Da&apos;) Executat,
      NG.Den_gest Gestiune,
      OBJ1.denumire Material,
      OBJ2.denumire Materialechiv,
      C3.Durata,
      C3.Valoare,
      CPM.Cant Cantitate,
      CPM.Pret,
      C.OBS DescAv, NPC.Obs constatari, NPC.TipComanda TipCom, NP1.DEN_PART Asigurator, NPC.Recomandari,
      C.Nri, R.Nume||&apos; &apos;||R.Prenume NumeInsotitor, NC.Nume||&apos; &apos;||NC.Prenume PersContact, Nc.Email emailPC, NC.Telefon telefonPC
    from comanda c
      Left join Comanda2 C2 on C2.CodComanda = C.CodComanda
      Left join Comanda3 C3 on C3.CodComanda2 = C2.CodComanda2
      left join Nparccom NPC on NPC.CodComanda = C.CodComanda
      Left join NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
      Left join Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
      Left join NModeleauto NMo on NMo.CodModeleauto=NPA.Model
      Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
      Left join Npart NPart on NPart.CodPart = C.Partener
      Left join NPartCodFisc CIF on CIF.CODPART = C.Partener
      Left join Npart NP on NP.CodPart = C2.Codpart
      Left join Npart NP1 on NP1.CodPart = NPC.Asigurator
      Left join NPartCodFisc CIF2 on CIF2.CODPART = C2.Codpart
      Left join NGest NG on NG.CodGest = C.CodGest
      Left join NOper NO on NO.CODOP = C3.CodOperatie
      Left join CMDProdMat CPM on CPM.CodComanda3 = C3.CodComanda3
      LEFT join NARTOBJ OBJ1 ON CPM.CODOBIECT = OBJ1.CODOBIECT
      left join prodmat pm on pm.codmat = CPM.codprodmat
      left join nartobj OBJ2 on OBJ2.codobiect = pm.codobiect
      left join nperscontact NC on C.codpersc = NC.codpersc
      left join npers R on C.Insotitor = R.codpers
    WHERE C.TipDoc = 92 and C.CODComanda = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;SA Prefix&apos;           , v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SA Serie&apos;            , v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SA Nr&apos;               , v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SA Data&apos;             , v_rec.DataDoc);

    pkg_list_struct.ADAUGA_PARAM(&apos;SA Data Doc&apos;         , to_char(v_rec.Datadoc,&apos;dd.mm.yyyy hh24:mi&apos;));
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Nr. Doc&apos;          , v_rec.NrDoc);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Obs. comanda&apos;     , v_rec.ObsC);

    pkg_list_struct.ADAUGA_PARAM(&apos;SA Model masina&apos;     , v_rec.Model);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Marca masina&apos;     , v_rec.Marca);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Nr. inmatr.&apos;      , v_rec.NRINREG);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Serie caroserie&apos;  , v_rec.SERIECaroserie);

    pkg_list_struct.ADAUGA_PARAM(&apos;SA Cilindree&apos;        , v_rec.Cilindree);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Sursa energie&apos;    , v_rec.SursaE);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Culoare&apos;          , v_rec.CULOAREC);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA An fabricatie&apos;    , v_rec.AnFabricatie);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Serie motor&apos;      , v_rec.SerieMotor);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Proba drum&apos;       , v_rec.ProbaDrum);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Piese la client&apos;  , v_rec.PieseClient);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Inmatr. in RO&apos;    , v_rec.InmatrRom);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Spalare&apos;          , v_rec.Spalare);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Inspectie&apos;        , v_rec.Inspectie);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Niv. rezervor&apos;    , v_rec.Nivrezervor);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA KM la bord&apos;       , v_rec.KMBORD);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Descriere avarii&apos; , v_rec.DescAv);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Constatari&apos;       , v_rec.Constatari);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Recomandari&apos;      , v_rec.Recomandari);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Tip comanda&apos;      , v_rec.TipCom);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Asigurator&apos;       , v_rec.Asigurator);

    pkg_list_struct.ADAUGA_PARAM(&apos;SA NRI&apos;              , v_rec.NRI);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Receptioner&apos;      , v_rec.NumeInsotitor);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA PersContact&apos;      , v_rec.PersContact);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Mail PersContact&apos; , v_rec.emailPC);
    pkg_list_struct.ADAUGA_PARAM(&apos;SA Tel PersContact&apos;  , v_rec.TelefonPC);
    EXIT;
  END LOOP;
END;


PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_COMANDSADOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E2F9BD0631DA721899249C46C40194139FB70B2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMDOC IS

  vCodComanda      NUMBER(20);
  vID              NUMBER(20);
  vTabla           VARCHAR2( 500);
  vTabla1          VARCHAR2( 500);
  gUserFields      VARCHAR2(5000);
  gUserAlias       VARCHAR2(5000);
  gNullAlias       VARCHAR2(2500);
  gSuplCols        VARCHAR2(5000);
  gSuplJoins       VARCHAR2(5000);
  gShortVer        NUMBER(10);

  vLISTID          NUMBER(10);
  vLISTVER         NUMBER(10);

  pGetSoldListFact VARCHAR2(10);

function GetCodComanda return number is
begin
  return vCodComanda;
end;

procedure ComMatMan(tmpName IN VARCHAR2) is
sInsert varchar2(10000);
begin
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     ART,
     UM,
     CANTACC,
     CANTREST,
     PRET,
     Reteta,
     NrOp,
     Cant,
     Operatie,
     LocMunca,
     DenTarif,
     tarif,
     tu,
     valoare,
     dsv,
     bps,
     tpi,
     obs,
     detalii,
     COMP_TIP &apos;||gUserFields||&apos;)
  SELECT
     prod.DENUMIRE,
     NUM1.DEN_UM1,
     C1.CANTACCEPTAT,
     C1.RESTACCEPTAT,
     C1.PU,
     PC.OBS,
     MAN.NrOp,
     MAN.Cant,
     OP.DENUMIRE,
     LM.DENUMIRE,
     T.DenUMIRE,
     T.tarif,
     MAN.tu,
     MAN.valoare,
     MAN.dsv,
     MAN.bps,
     MAN.tpi,
     C1.obs,
     MAN.detalii,
     &apos;&apos;Manopera&apos;&apos; &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1   c1      on c.codcomanda       = c1.codcomanda
    INNER JOIN NARTOBJ    PROD    ON PROD.CODOBIECT     = C1.CODOBIECT
    INNER JOIN NART       ARTPROD ON ARTPROD.CODARTICOL = PROD.CODARTICOL
    INNER JOIN NUM1       NUM1    ON NUM1.CODUM1        = C1.UMSEC
    INNER JOIN cmdprodman man     on c1.codcomanda1     = man.codcomanda1
    INNER JOIN PRODCOMP   PC      ON PC.CODPRODCOMP     = C1.CODRETETA
    INNER JOIN noper      op      on man.codop          = op.codop
    INNER JOIN locmunca   lm      on lm.codloc          = man.codloc
    INNER JOIN (
      SELECT T1.codtarif, T1.Tarif, t.denumire
      FROM TARIFEMAN1 T1 INNER JOIN tarifeman t on t1.codtarif = t .codtarif AND pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU BETWEEN T1.ALSTART AND T1.ALSTOP
    ) T ON MAN.CODTARIF = T.CODTARIF
    LEFT JOIN cmdprodmat mat on mat.codcmdprodmat = man.codcomanda1-man.codcomanda1
    LEFT JOIN prodsdv    sdv on sdv.codprodsdv    = man.codcomanda1-man.codcomanda1
  &apos;||gSuplJoins||&apos;
  WHERE C.CodComanda = &apos;||vCodComanda;
  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);

  sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP, COMP_SERIE, COMP_LOT,
      ART, UM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM
      &apos;||gUserFields||&apos;)
    WITH REZ_SERII AS (
      SELECT
        CODOBIECT, CODCOMANDA1,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serie) AS vc2_nt)) serii,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serielot) AS vc2_nt)) lotpropriu
      FROM (
        SELECT NS.CODOBIECT, C1.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC  NS   ON R.CODNIRSTOC      = NS.CODNIRSTOC
          INNER JOIN CMDLINK  L    ON L.CODLINIECOMANDA = R.CODCOMANDA1
          INNER JOIN COMANDA1 C1   ON L.CODCOMANDA1     = C1.CODCOMANDA1
          LEFT  JOIN NIRSER   NSER ON R.CODNIRSER       = NSER.CODNIRSER
          LEFT  JOIN NSERII   SER  ON NSER.CODSERIE     = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
        UNION
        SELECT NS.CODOBIECT, R.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC    NS   ON R.CODNIRSTOC    = NS.CODNIRSTOC
          INNER JOIN CMDPRODMAT MAT  ON R.CODCMDPRODMAT = MAT.CODCMDPRODMAT
          INNER JOIN COMANDA1   C1   ON C1.CODCOMANDA1  = MAT.CODCOMANDA1
          LEFT JOIN NIRSER      NSER ON R.CODNIRSER     = NSER.CODNIRSER
          LEFT JOIN NSERII      SER  ON NSER.CODSERIE   = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
      )
      GROUP BY CODOBIECT, CODCOMANDA1
    )
    SELECT
      objmat.denumire COMP_ART, ummat.den_um COMP_UM, mat.cant COMP_CANT, mat.pret COMP_PRET, DECODE(mat.tip, 1, &apos;&apos;Articole folosite&apos;&apos;, 2, &apos;&apos;Articole rezultate&apos;&apos;, 0, &apos;&apos;Articole folosite&apos;&apos;) COMP_TIP,
      REZ_SERII.SERII COMP_SERIE, REZ_SERII.LOTPROPRIU COMP_LOT,
      nao.denumire, num1.den_um1, c1.cantacceptat / num1.paritate, c1.restacceptat / num1.paritate, c1.pu * num1.paritate,
      c1.cantcomandat * c1.pu, c1.cantacceptat * c1.pu, c1.restacceptat * c1.pu, c1.termen &apos;||gUserAlias||&apos;
    FROM comanda c
      INNER JOIN comanda1   c1     ON c1.codcomanda = c.codcomanda
      INNER JOIN prodcomp   pc     on c1.codreteta = pc.codprodcomp
      INNER JOIN cmdprodmat mat    on mat.codcomanda1 = c1.codcomanda1
      INNER JOIN nartobj    objmat on mat.codobiect = objmat.codobiect
      INNER JOIN nart       artmat on objmat.codarticol = artmat.codarticol
      INNER JOIN num        ummat  on artmat.um = ummat.codum
      INNER JOIN nartobj    nao    ON nao.codobiect = c1.codobiect
      INNER JOIN nart       na     ON na.codarticol = nao.codarticol
      INNER JOIN num1              ON num1.codum1 = c1.umsec
      LEFT JOIN cmdprodman  man    on man.codcmdprodman = mat.codcomanda1-mat.codcomanda1
      LEFT JOIN REZ_SERII          ON C1.CODCOMANDA1 = REZ_SERII.CODCOMANDA1 AND MAT.CODOBIECT = REZ_SERII.CODOBIECT
      LEFT JOIN prodsdv     sdv    on sdv.codprodsdv = mat.codcomanda1-mat.codcomanda1
      &apos;||gSuplJoins||&apos;
    WHERE (mat.tip &gt; 0 or (mat.tip = 0 and pc.tipreteta = 2)) AND c.codcomanda = &apos;||vCodComanda;
  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);

  sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP, COMP_SERIE, COMP_LOT,
      ART, UM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM
      &apos;||gUserFields||&apos;)
    SELECT
      objmat.denumire COMP_ART, ummat.den_um COMP_UM, c1.cantacceptat/pc.cant*sdv.cant COMP_CANT, sdv.pret COMP_PRET, &apos;&apos;SDV&apos;&apos; COMP_TIP,
      null COMP_SERIE, null COMP_LOT,
      nao.denumire, num1.den_um1, c1.cantacceptat / num1.paritate, c1.restacceptat / num1.paritate, c1.pu * num1.paritate,
      c1.cantcomandat * c1.pu, c1.cantacceptat * c1.pu, c1.restacceptat * c1.pu, c1.termen &apos;||gUserAlias||&apos;
    FROM comanda c
      INNER JOIN comanda1   c1     ON c1.codcomanda     = c.codcomanda
      INNER JOIN prodcomp   pc     on c1.codreteta      = pc.codprodcomp
      INNER JOIN prodsdv    sdv    on sdv.codprodcomp   = pc.codprodcomp
      INNER JOIN nartobj    objmat on objmat.codobiect  = sdv.codsdv
      INNER JOIN nart       artmat on objmat.codarticol = artmat.codarticol
      INNER JOIN num        ummat  on artmat.um     = ummat.codum
      INNER JOIN nartobj    nao    ON nao.codobiect = sdv.codsdv - sdv.codsdv
      INNER JOIN nart       na     ON na.codarticol = nao.codarticol
      INNER JOIN num1              ON num1.codum1   = c1.umsec
      LEFT  JOIN cmdprodmat mat    on mat.codcmdprodmat = c1.codcomanda1-c1.codcomanda1
      LEFT  JOIN cmdprodman man    on man.codcmdprodman = mat.codcomanda1-mat.codcomanda1
      &apos;||gSuplJoins||&apos;
    WHERE c.codcomanda = &apos;||vCodComanda;
  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
end;

PROCEDURE SETPARAMS( pCodComanda IN NUMBER DEFAULT NULL, pID IN NUMBER, pShortVer IN NUMBER default 0) IS
BEGIN
  vCodComanda := pCodComanda;
  vID         := pID;
  CASE vID
    WHEN 105 THEN vTabla := &apos;COMANDF&apos;;  vTabla1 := &apos;COMANDF1&apos;;
    WHEN 122 THEN vTabla := &apos;COMANDC&apos;;  vTabla1 := &apos;COMANDC1&apos;;
    WHEN 146 THEN vTabla := &apos;COMANDI&apos;;  vTabla1 := &apos;COMANDI1&apos;;
    WHEN 267 THEN vTabla := &apos;COMANDL&apos;;  vTabla1 := &apos;COMANDL1&apos;;
    WHEN 289 THEN vTabla := &apos;COMANDI&apos;;  vTabla1 := &apos;COMANDI1&apos;;
    WHEN 384 THEN vTabla := &apos;COMANDSA&apos;; vTabla1 := &apos;COMANDSA1&apos;;
    WHEN 407 THEN vTabla := &apos;&apos;;         vTabla1 := &apos;&apos;;          -- RAC
    ELSE          vTabla := NULL;       vTabla1 := NULL;
  END CASE;
  gShortVer        := pShortVer;
  pGetSoldListFact := pkg_categconst.GetValConstanta(&apos;GetSoldListFact&apos;,pkg_globals.ANLUCRU, pkg_globals.lunalucru) ;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ComInterne(tmpName IN VARCHAR2) IS
sInsert VARCHAR2(25000);
BEGIN
  IF gShortVer = 1 THEN
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP, COMP_SERIE, COMP_LOT,
      ART, UM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM
      &apos;||gUserFields||&apos;)
    WITH REZ_SERII AS (
      SELECT
        CODOBIECT, CODCOMANDA1,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serie) AS vc2_nt)) serii,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serielot) AS vc2_nt)) lotpropriu
      FROM (
        SELECT NS.CODOBIECT, C1.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC  NS   ON R.CODNIRSTOC      = NS.CODNIRSTOC
          INNER JOIN CMDLINK  L    ON L.CODLINIECOMANDA = R.CODCOMANDA1
          INNER JOIN COMANDA1 C1   ON L.CODCOMANDA1     = C1.CODCOMANDA1
          LEFT  JOIN NIRSER   NSER ON R.CODNIRSER       = NSER.CODNIRSER
          LEFT  JOIN NSERII   SER  ON NSER.CODSERIE     = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
        UNION
        SELECT NS.CODOBIECT, R.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC    NS   ON R.CODNIRSTOC    = NS.CODNIRSTOC
          INNER JOIN CMDPRODMAT MAT  ON R.CODCMDPRODMAT = MAT.CODCMDPRODMAT
          INNER JOIN COMANDA1   C1   ON C1.CODCOMANDA1  = MAT.CODCOMANDA1
          LEFT  JOIN NIRSER     NSER ON R.CODNIRSER     = NSER.CODNIRSER
          LEFT  JOIN NSERII     SER  ON NSER.CODSERIE   = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
      )
      GROUP BY CODOBIECT, CODCOMANDA1
    )
    SELECT
      objmat.denumire COMP_ART, ummat.den_um COMP_UM, mat.cant COMP_CANT, mat.pret COMP_PRET, DECODE(mat.tip, 1, &apos;&apos;Articole folosite&apos;&apos;, 2, &apos;&apos;Articole rezultate&apos;&apos;, 0, &apos;&apos;Articole folosite&apos;&apos;) COMP_TIP,
      REZ_SERII.SERII COMP_SERIE, REZ_SERII.LOTPROPRIU COMP_LOT,
      nao.denumire, num1.den_um1, c1.cantacceptat / num1.paritate, c1.restacceptat / num1.paritate, c1.pu * num1.paritate,
      c1.cantcomandat * c1.pu, c1.cantacceptat * c1.pu, c1.restacceptat * c1.pu, c1.termen &apos;||gUserAlias||&apos;
    FROM comanda c
      INNER JOIN comanda1   c1     ON c1.codcomanda     = c.codcomanda
      INNER JOIN prodcomp   pc     on c1.codreteta      = pc.codprodcomp
      INNER JOIN cmdprodmat mat    on mat.codcomanda1   = c1.codcomanda1
      INNER JOIN nartobj    objmat on mat.codobiect     = objmat.codobiect
      INNER JOIN nart       artmat on objmat.codarticol = artmat.codarticol
      INNER JOIN num        ummat  on artmat.um         = ummat.codum
      INNER JOIN nartobj    nao    ON nao.codobiect     = c1.codobiect
      INNER JOIN nart       na     ON na.codarticol     = nao.codarticol
      INNER JOIN num1              ON num1.codum1       = c1.umsec
      LEFT  JOIN REZ_SERII         ON C1.CODCOMANDA1    = REZ_SERII.CODCOMANDA1 AND MAT.CODOBIECT = REZ_SERII.CODOBIECT
      &apos;||gSuplJoins||&apos;
    WHERE (mat.tip &gt; 0 or (mat.tip = 0 and pc.tipreteta = 2)) AND c.codcomanda = &apos;||vCodComanda;
  ELSE
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP, COMP_SERIE, COMP_LOT,
      ART, UM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM,
      ADAOS, DISC, PROCTVA, VALCUTVA,
      OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, Masa, Volum, CodVamal,Prod,
      DenLaCli, CodLaCli, CodListat, D1, D2, D3, Comp_D1, Comp_D2, Comp_D3,
      UMMasa, UMDimA, UMDimB, UMDimC, DenClaseAS, NrComCli, Beneficiar,
      CantAccUMSpec,
      DENATRIB, CLIENT, Responsabili, OBSMAT, COMP_ATRIBUTE, PROD_ATRIBUTE&apos;||gUserFields||&apos;)
    WITH /*REZ_SERII AS (
      SELECT
        CODOBIECT, CODCOMANDA1,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serie) AS vc2_nt)) serii,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT serielot) AS vc2_nt)) lotpropriu
      FROM (
        SELECT NS.CODOBIECT, C1.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC  NS   ON R.CODNIRSTOC      = NS.CODNIRSTOC
          INNER JOIN CMDLINK  L    ON L.CODLINIECOMANDA = R.CODCOMANDA1
          INNER JOIN COMANDA1 C1   ON L.CODCOMANDA1     = C1.CODCOMANDA1
          LEFT  JOIN NIRSER   NSER ON R.CODNIRSER       = NSER.CODNIRSER
          LEFT  JOIN NSERII   SER  ON NSER.CODSERIE     = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
        UNION
        SELECT NS.CODOBIECT, R.CODCOMANDA1, SER.SERIE, NS.SERIELOT
        FROM REZERVATS R
          INNER JOIN NIRSTOC    NS   ON R.CODNIRSTOC    = NS.CODNIRSTOC
          INNER JOIN CMDPRODMAT MAT  ON R.CODCMDPRODMAT = MAT.CODCMDPRODMAT
          INNER JOIN COMANDA1   C1   ON C1.CODCOMANDA1  = MAT.CODCOMANDA1
          LEFT  JOIN NIRSER     NSER ON R.CODNIRSER     = NSER.CODNIRSER
          LEFT  JOIN NSERII     SER  ON NSER.CODSERIE   = SER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos; AND Coalesce(SER.SERIE, NS.SERIELOT) IS NOT NULL
      )
      GROUP BY CODOBIECT, CODCOMANDA1
    ),*/
    Resp as
    (
     SELECT STRING_AGG(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME) PERSOANE, U2P.CODUTILAJ2
     FROM UTILAJE2P U2P
          INNER JOIN NPERS P ON U2P.CODPERS = P.CODPERS
     GROUP BY U2P.CODUTILAJ2
     )
    SELECT
      objmat.denumire COMP_ART, ummat.den_um COMP_UM, mat.cant COMP_CANT, mat.pret COMP_PRET, DECODE(mat.tip, 1, &apos;&apos;Articole folosite&apos;&apos;, 2, &apos;&apos;Articole rezultate&apos;&apos;, 0, &apos;&apos;Articole folosite&apos;&apos;) COMP_TIP,
      /*REZ_SERII.SERII*/ &apos;&apos; &apos;&apos; COMP_SERIE, /*REZ_SERII.LOTPROPRIU*/ &apos;&apos; &apos;&apos; COMP_LOT,
      nao.denumire, num1.den_um1, c1.cantacceptat / num1.paritate, c1.restacceptat / num1.paritate, c1.pu * num1.paritate,
      c1.cantcomandat * c1.pu, c1.cantacceptat * c1.pu, c1.restacceptat * c1.pu, c1.termen,
      c1.addim, c1.procdisc, t1.procent, c1.cantacceptat * c1.pu * (100 + t1.procent) / 100,
      c1.obs, c.obs, nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, nao.codvamal, prod.den_part,
      Coalesce(ac.denumire,nao.denumire), Coalesce(ac.codextern,nao.codextern),&apos;||chr(13);
      if vid = 384 then
        sInsert := sInsert||&apos;Coalesce(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),&apos;||chr(13);
      else
        sInsert := sInsert||&apos;Coalesce(DECODE(ac.tipcodafisat,1,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu),nao.codextern),&apos;||chr(13);
      end if;
      sInsert := sInsert||&apos;c1.D1, c1.D2, c1.D3, mat.D1, mat.D2, mat.D3,
      aa.masa, aa.lungime, aa.latime, aa.inaltime, cs.den_claseas, CC.NrDoc,
      CASE WHEN Coalesce(csub.codsubunit, 0) &gt; 0 and cc.tipdoc = 44 then csub.den_subunit when gest.codgest &gt; 0 then gest.den_gest ELSE PKG_LIST_BASE_UTILS.GetPartComCli(C1.CODCOMANDA1) END,
      c1.acceptum1,
      (SELECT vc2_nt_to_string(CAST(collect(a.denumire order by aa.indexlocal) AS vc2_nt))
        FROM nartatr aa INNER JOIN natrib a ON a.codatribut = aa.codatribut
        WHERE aa.codarticol = nao.codarticol
      ) DENATRIB, PKG_LIST_BASE_UTILS.GetPartComCli(C1.CODCOMANDA1), &apos;||chr(13);
      if vid = 384 then
        sInsert := sInsert||&apos; RESP.PERSOANE, &apos;||chr(13);
      else
        sInsert := sInsert||&apos; &apos;&apos; &apos;&apos; RESPONSABILI, &apos;||chr(13);
      end if;
      sInsert := sInsert||
      &apos; CASE WHEN MAT.TIP = 1 THEN PMAT.OBS ELSE &apos;&apos;&apos;&apos; END,
      (SELECT STRING_AGG(ATR.denumire||&apos;&apos; = &apos;&apos;||ATR1.VALOARE)
        FROM (SELECT * FROM NATROBJ ORDER BY INDEXLOCAL) OATR
            INNER JOIN NATRIB1 ATR1 ON ATR1.CODVALATR = OATR.CODVALATR
            INNER JOIN NATRIB ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
        WHERE OATR.CODOBIECT = OBJMAT.CODOBIECT
      ) COMP_ATRIBUTE,
      (SELECT STRING_AGG(ATR.denumire||&apos;&apos; = &apos;&apos;||ATR1.VALOARE)
        FROM (SELECT * FROM NATROBJ ORDER BY INDEXLOCAL) OATR
            INNER JOIN NATRIB1 ATR1 ON ATR1.CODVALATR = OATR.CODVALATR
            INNER JOIN NATRIB ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
        WHERE OATR.CODOBIECT = NAO.CODOBIECT
      ) PROD_ATRIBUTE &apos;||gUserAlias||&apos;
    FROM comanda c
      INNER JOIN comanda1         c1      ON c1.codcomanda     = c.codcomanda
      INNER JOIN cmdprodmat       mat     on mat.codcomanda1   = c1.codcomanda1
      INNER JOIN nartobj          objmat  on mat.codobiect     = objmat.codobiect
      INNER JOIN nart             artmat  on objmat.codarticol = artmat.codarticol
      INNER JOIN num              ummat   on artmat.um         = ummat.codum
      INNER JOIN nartobj          nao     ON nao.codobiect     = c1.codobiect
      INNER JOIN nart             na      ON na.codarticol     = nao.codarticol
      INNER JOIN num1                     ON num1.codum1       = c1.umsec
      INNER JOIN PRODCOMP         PC      ON PC.CODPRODCOMP    = C1.CODRETETA
      INNER JOIN TMP_nart_luna    na1     ON na1.codarticol    = nao.codarticol
      INNER JOIN tmp_ntva_luna    t1      ON t1.codtva         = na1.codtva
      INNER JOIN tmp_nartobj_luna nao1    ON nao1.codobiect    = nao.codobiect
      LEFT  JOIN nartimplicite    AIMP    ON AIMP.codarticol   = artmat.codarticol and aimp.codsubunit = pkg_globals.getsubunitate
      LEFT  JOIN nartobjimp       OIMP    ON OIMP.CODOBIECT    = OBJmat.codOBIECT and Oimp.codsubunit = pkg_globals.getsubunitate
      LEFT  JOIN IOART            IOAIMP  ON IOAIMP.CODIOART   = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN Coalesce(AIMP.CONTIMPLICIT,0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
      LEFT  JOIN NGEST            GESTIMP ON Coalesce(AIMP.GESTIMPLICITA,0) = GESTIMP.CODGEST
      LEFT  JOIN PRODMAT          PMAT    ON MAT.CODPRODMAT    = PMAT.CODMAT
      LEFT  JOIN cmdlink          cll     ON cll.codcomanda1   = c1.codcomanda1
      LEFT  JOIN comanda1         csursa1 ON csursa1.codcomanda1 = cll.codliniecomanda
      LEFT  JOIN comanda          csursa  ON csursa.codcomanda = csursa1.codcomanda
      LEFT  JOIN ngest            gest    ON gest.codgest      = csursa.codgest
      LEFT  JOIN cmdlivrlink      clc     ON clc.codcomanda1   = COALESCE(cll.codliniecomanda, c1.codcomanda1)
      LEFT  JOIN comanda1         c1c     ON c1c.codcomanda1   = CASE WHEN csursa.tipdoc IN (8,18) AND Coalesce(csursa.displivrare,0) = 0 THEN csursa1.codcomanda1 ELSE clc.codliniecomanda END
      LEFT  JOIN comanda          cc      ON cc.codcomanda     = c1c.codcomanda
      --LEFT JOIN REZ_SERII ON C1.CODCOMANDA1 = REZ_SERII.CODCOMANDA1 AND MAT.CODOBIECT = REZ_SERII.CODOBIECT
      LEFT  JOIN nsubunit         csub    on cc.subunitatea    = csub.codsubunit
      LEFT  JOIN nartamb          aa      ON aa.codobiect      = nao.codobiect AND aa.umsec = c1.umsec
      LEFT  JOIN npart            prod    ON prod.codpart      = nao.codproducator
      LEFT  JOIN nclasea          ca      ON ca.codclasea      = na.clasa
      LEFT  JOIN nclasea          compcls ON compcls.codclasea = artmat.clasa
      LEFT  JOIN nclaseas         cs      ON cs.codclaseas     = na.clasastatist
      LEFT  JOIN npart            np      ON np.codpart        = c.partener
      LEFT  JOIN nartcli          ac      ON ac.codartcli      = 0&apos;||chr(13);
   if vid = 384 then
   sInsert := sInsert||&apos;
      LEFT JOIN nagenda     nag   ON nag.codagenda  = c.codlocatie
      LEFT JOIN nlocalit    nloc  ON nag.codlocalit = nloc.codlocalit
      LEFT JOIN ntari             ON ntari.codtara  = nloc.codtara
      LEFT JOIN nartobjtrad ntrad ON ntrad.codlimba = ntari.codlimba and ntrad.codobiect = nao.codobiect
      LEFT JOIN nechiv      e     ON e.codobiect    = c1.codobiect
      LEFT JOIN grechiv     gre   ON gre.codgrechiv = e.codgrupa
      LEFT JOIN oferta1     o1    ON o1.codoferta1  = COALESCE(c1.codoferta1,CASE WHEN c1.tipsursa IN (50,51) THEN c1.codsursa ELSE NULL END)
      LEFT JOIN UTILAJE2C   U2C   ON C1.CODCOMANDA1 = U2C.CODCOMANDA1
      LEFT JOIN Resp              ON U2C.CODUTILAJ2 = Resp.CODUTILAJ2
      LEFT JOIN UTILAJE     U     ON U2C.CODUTILAJ  = U.CODUTILAJ&apos;||chr(13);
   end if;
   sInsert := sInsert||
      gSuplJoins||&apos;
    WHERE (mat.tip &gt; 0 or (mat.tip = 0 and pc.tipreteta = 2)) AND c.codcomanda = &apos;||vCodComanda;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
END;

PROCEDURE ComMentenanta(tmpName IN VARCHAR2) IS
  sInsert   VARCHAR2(25000);
  sInsert1  VARCHAR2(25000);
BEGIn
  delete TMP_PERSONAL_MAN;
  delete tmp_comdoc_men;
  sInsert :=
  &apos;INSERT INTO TMP_PERSONAL_MAN(PERSOANE, MARCI, COD)
   SELECT STRING_AGG(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME) PERSOANE, STRING_AGG(P.MARCA) MARCI, U2P.CODUTILAJ2
   FROM UTILAJE2P U2P
        INNER JOIN NPERS P ON U2P.CODPERS = P.CODPERS
   GROUP BY U2P.CODUTILAJ2&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);

  sInsert :=
 &apos;insert into tmp_comdoc_men (
    denumire,
    den_um1,
    cantcomandat,
    cantacceptat,
    restacceptat,
    pu,
    valcom,
    valacc,
    valrest,
    termen,
    procent,
    valacctva,
    obslinie,
    obs,
    codintern,
    codextern,
    den_um,
    paritate,
    comp_art,
    comp_um,
    comp_cant,
    comp_pret,
    comp_tip,
    locmunca,
    dsv,
    nrop,
    detalii,
    operatie,
    bps,
    tarif,
    tpimin,
    tpiore,
    tumin,
    tuore,
    manval,
    manobs,
    codcomanda1,
    um1,
    umsec,
    codobiect,
    codproducator,
    clasa,
    clasastatist,
    partener,
    codlocatie,
    codsursa,
    tipsursa,
    codoferta1,
    indexlocal,
    tip)
  SELECT
    nao.denumire,
    num1.den_um1,
    c1.cantcomandat/num1.paritate cantcomandat,
    c1.cantacceptat/num1.paritate cantacceptat,
    c1.restacceptat/num1.paritate restacceptat,
    c1.pu * num1.paritate pu,
    c1.cantcomandat * c1.pu valcom,
    c1.cantacceptat * c1.pu valacc,
    c1.restacceptat * c1.pu valrest,
    c1.termen,
    t1.procent,
    c1.cantacceptat * c1.pu * (100 + t1.procent) / 100 valacctva,
    c1.obs obslinie,
    c.obs,
    nao.codintern,
    nao.codextern,
    num.den_um,
    num1.paritate,
    objmat.denumire COMP_ART,
    ummat.den_um COMP_UM,
    mat.cant COMP_CANT,
    mat.pret COMP_PRET,
    DECODE(mat.tip, 0, &apos;&apos;Produs&apos;&apos;, 1, &apos;&apos;Articole folosite&apos;&apos;, 2, &apos;&apos;Articole rezultate&apos;&apos;) COMP_TIP,
    null LOCMUNCA,
    null DSV,
    null NrOp,
    null Detalii,
    null Operatie,
    null BPS,
    null Tarif,
    null TPIMIN,
    null TPIORE,
    null TUMIN,
    null TUORE,
    null MANVAL,
    null MANOBS,
    c1.codcomanda1,
    na.um1,
    c1.umsec,
    nao.codobiect,
    nao.codproducator,
    na.clasa,
    na.clasastatist,
    c.partener,
    c.codlocatie,
    c1.codsursa,
    c1.tipsursa,
    c1.codoferta1,
    c1.indexlocal,
    mat.tip
  FROM comanda c
    INNER JOIN comanda1   c1     ON c1.codcomanda     = c.codcomanda
    INNER JOIN cmdprodmat mat    on mat.codcomanda1   = c1.codcomanda1
    INNER JOIN nartobj    objmat on mat.codobiect     = objmat.codobiect
    INNER JOIN nart       artmat on objmat.codarticol = artmat.codarticol
    INNER JOIN num        ummat  on artmat.um         = ummat.codum
    INNER JOIN nartobj    nao    ON nao.codobiect     = c1.codobiect
    INNER JOIN nart       na     ON na.codarticol     = nao.codarticol
    INNER JOIN num               ON num.codum         = na.um
    INNER JOIN num1              ON num1.codum1       = c1.umsec
    INNER JOIN nart1      na1    ON na1.codarticol    = nao.codarticol AND (c.an*12+c.luna) BETWEEN na1.ALSTART  and na1.ALSTOP
    INNER JOIN ntva1      t1     ON t1.codtva         = na1.codtva     AND (c.an*12+c.luna) BETWEEN t1.ALSTART   and t1.ALSTOP
    INNER JOIN nartobj1   nao1   ON nao1.codobiect = nao.codobiect     AND (c.an*12+c.luna) BETWEEN nao1.ALSTART and nao1.ALSTOP
  WHERE c.codcomanda = &apos;||vCodComanda;
  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
  sInsert :=
 &apos;insert into tmp_comdoc_men (
    denumire,
    den_um1,
    cantcomandat,
    cantacceptat,
    restacceptat,
    pu,
    valcom,
    valacc,
    valrest,
    termen,
    procent,
    valacctva,
    obslinie,
    obs,
    codintern,
    codextern,
    den_um,
    paritate,
    comp_art,
    comp_um,
    comp_cant,
    comp_pret,
    comp_tip,
    locmunca,
    dsv,
    nrop,
    detalii,
    operatie,
    bps,
    tarif,
    tpimin,
    tpiore,
    tumin,
    tuore,
    manval,
    manobs,
    codcomanda1,
    um1,
    umsec,
    codobiect,
    codproducator,
    clasa,
    clasastatist,
    partener,
    codlocatie,
    codsursa,
    tipsursa,
    codoferta1,
    indexlocal,
    tip)
  SELECT
    nao.denumire,
    num1.den_um1,
    c1.cantcomandat/num1.paritate cantcomandat,
    c1.cantacceptat/num1.paritate cantacceptat,
    c1.restacceptat/num1.paritate restacceptat,
    c1.pu * num1.paritate pu,
    c1.cantcomandat * c1.pu valcom,
    c1.cantacceptat * c1.pu valacc,
    c1.restacceptat * c1.pu valrest,
    c1.termen,
    t1.procent,
    c1.cantacceptat * c1.pu * (100 + t1.procent) / 100 valacctva,
    c1.obs obslinie,
    c.obs,
    nao.codintern,
    nao.codextern,
    num.den_um,
    num1.paritate,
    null COMP_ART,
    null COMP_UM,
    null COMP_CANT,
    null COMP_PRET,
    &apos;&apos;Manopera&apos;&apos; COMP_TIP,
    LM.DENUMIRE LOCMUNCA,
    MAN.DSV,
    MAN.NrOp,
    MAN.Detalii,
    OP.DENUMIRE Operatie,
    MAN.BPS,
    TF.DENUMIRE Tarif,
    MAN.TPI TPIMIN,
    MAN.TPI/60 TPIORE,
    MAN.TU TUMIN,
    MAN.TU/60 TUORE,
    MAN.VALOARE MANVAL,
    MAN.OBS MANOBS,
    c1.codcomanda1,
    na.um1,
    c1.umsec,
    nao.codobiect,
    nao.codproducator,
    na.clasa,
    na.clasastatist,
    c.partener,
    c.codlocatie,
    c1.codsursa,
    c1.tipsursa,
    c1.codoferta1,
    c1.indexlocal,
    -1 tip
  FROM comanda c
    INNER JOIN comanda1   c1   ON c1.codcomanda   = c.codcomanda
    INNER JOIN cmdprodman man  on man.codcomanda1 = c1.codcomanda1
    INNER JOIN LOCMUNCA   LM   ON LM.CODLOC       = MAN.CODLOC
    INNER JOIN NOPER      OP   ON OP.CODOP        = MAN.CODOP
    INNER JOIN TARIFEMAN  TF   ON TF.CODTARIF     = MAN.CODTARIF
    INNER JOIN nartobj    nao  ON nao.codobiect   = c1.codobiect
    INNER JOIN nart       na   ON na.codarticol   = nao.codarticol
    INNER JOIN num             ON num.codum       = na.um
    INNER JOIN num1            ON num1.codum1     = c1.umsec
    INNER JOIN nart1      na1  ON na1.codarticol  = nao.codarticol AND (c.an*12+c.luna) BETWEEN na1.ALSTART  and na1.ALSTOP
    INNER JOIN ntva1      t1   ON t1.codtva       = na1.codtva     AND (c.an*12+c.luna) BETWEEN t1.ALSTART   and t1.ALSTOP
    INNER JOIN nartobj1   nao1 ON nao1.codobiect  = nao.codobiect  AND (c.an*12+c.luna) BETWEEN nao1.ALSTART and nao1.ALSTOP
  WHERE c.codcomanda = &apos;||vCodComanda;

  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTCOM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST,
    TERM, PROCTVA, VALCUTVA, OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, UMPrinc, Paritate,
    COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP,
    LOCMUNCA, DSV, NrOp, Detalii, Operatie, BPS, Tarif, TPIMIN, TPIORE, TUMIN, TUORE, MANVAL, MANOBS,
    Interventie, Responsabili, NRINV, Utilaj, Marci, Descriere &apos;||gUserFields||&apos;)
  SELECT
    tmp.denumire, tmp.den_um1, tmp.cantcomandat, tmp.cantacceptat, tmp.restacceptat, tmp.pu, tmp.valcom, tmp.valacc, tmp.valrest,
    tmp.termen, tmp.procent, tmp.valacctva, tmp.obslinie, tmp.obs, tmp.codintern, tmp.codextern, ca.den_clasea, ca.simbol, tmp.den_um, tmp.paritate,
    tmp.COMP_ART, tmp.COMP_UM, tmp.COMP_CANT, tmp.COMP_PRET, DECODE(tmp.tip, 0, &apos;&apos;Produs&apos;&apos;, 1, &apos;&apos;Articole folosite&apos;&apos;, 2, &apos;&apos;Articole rezultate&apos;&apos;) COMP_TIP,
    tmp.LOCMUNCA, tmp.DSV, tmp.NrOp, tmp.Detalii, tmp.Operatie, tmp.BPS, tmp.Tarif, tmp.TPIMIN, tmp.TPIORE, tmp.TUMIN, tmp.TUORE, tmp.MANVAL, tmp.MANOBS,
    INTERV.DENUMIRE Interventie, RESP.PERSOANE Responsabili, U.NRINVENTAR, OBJU.DENUMIRE Utilaj, RESP.MARCI, PKG_LIST_BASE_FISAMENTENANTA.AduDescriere(u2.codutilaj2) &apos;||gUserAlias||&apos;
  FROM tmp_comdoc_men tmp
    LEFT JOIN cmdlink          cll     ON cll.codcomanda1     = tmp.codcomanda1
    LEFT JOIN comanda1         csursa1 ON csursa1.codcomanda1 = cll.codliniecomanda
    LEFT JOIN comanda          csursa  ON csursa.codcomanda   = csursa1.codcomanda
    LEFT JOIN cmdlivrlink      clc     ON clc.codcomanda1     = COALESCE(cll.codliniecomanda, tmp.codcomanda1)
    LEFT JOIN comanda1         c1c     ON c1c.codcomanda1     = CASE WHEN csursa.tipdoc IN (8,18) AND Coalesce(csursa.displivrare,0) = 0 THEN tmp.codcomanda1 ELSE clc.codliniecomanda END
    LEFT JOIN comanda          cc      ON cc.codcomanda   = c1c.codcomanda
    LEFT JOIN num              umspec  ON umspec.codum    = tmp.um1
    LEFT JOIN nartamb          aa      ON aa.codobiect    = tmp.codobiect AND aa.umsec = tmp.umsec
    LEFT JOIN npart            prod    ON prod.codpart    = tmp.codproducator
    LEFT JOIN nclasea          ca      ON ca.codclasea    = tmp.clasa
    LEFT JOIN nclaseas         cs      ON cs.codclaseas   = tmp.clasastatist
    LEFT JOIN npart            np      ON np.codpart      = tmp.partener
    LEFT JOIN nartcli          ac      ON ac.codartcli    = 0
    LEFT JOIN nagenda          nag     ON nag.codagenda   = tmp.codlocatie
    LEFT JOIN nlocalit         nloc    ON nag.codlocalit  = nloc.codlocalit
    LEFT JOIN ntari                    ON ntari.codtara   = nloc.codtara
    LEFT JOIN nartobjtrad      ntrad   ON ntrad.codlimba  = ntari.codlimba and ntrad.codobiect = tmp.codobiect
    LEFT JOIN nechiv           e       ON e.codobiect     = tmp.codobiect
    LEFT JOIN grechiv          gre     ON gre.codgrechiv  = e.codgrupa
    LEFT JOIN oferta1          o1      ON o1.codoferta1   = COALESCE(tmp.codoferta1,CASE WHEN tmp.tipsursa IN (50,51) THEN tmp.codsursa ELSE NULL END)
    LEFT JOIN UTILAJE2C        U2C     ON tmp.CODCOMANDA1 = U2C.CODCOMANDA1
    LEFT JOIN UTILAJE2         U2      ON U2C.CODUTILAJ2  = U2.CODUTILAJ2
    LEFT JOIN NINTERVENTIIAUTO INTERV  ON INTERV.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN UTILAJE          U       ON U.CODUTILAJ    = U2.CODUTILAJ
    LEFT JOIN NARTOBJ          OBJU    ON OBJU.CODOBIECT = U.CODOBIECT
    LEFT JOIN TMP_PERSONAL_MAN Resp    ON U2C.CODUTILAJ2 = Resp.COD
    &apos;||gSuplJoins||&apos;
  ORDER BY tmp.indexlocal &apos;;

  sInsert1 :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTCOM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST,
    TERM, PROCTVA, VALCUTVA, OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, UMPrinc, Paritate,
    COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, COMP_TIP,
    LOCMUNCA, DSV, NrOp, Detalii, Operatie, BPS, Tarif, TPIMIN, TPIORE, TUMIN, TUORE, MANVAL, MANOBS,
    Interventie, Responsabili, NRINV, Utilaj, Marci, Descriere &apos;||gUserFields||&apos;)
  SELECT
    tmp.denumire, tmp.den_um1, tmp.cantcomandat, tmp.cantacceptat, tmp.restacceptat, tmp.pu, tmp.valcom, tmp.valacc, tmp.valrest,
    tmp.termen, tmp.procent, tmp.valacctva, tmp.obslinie, tmp.obs, tmp.codintern, tmp.codextern, ca.den_clasea, ca.simbol, tmp.den_um, tmp.paritate,
    tmp.COMP_ART, tmp.COMP_UM, tmp.COMP_CANT, tmp.COMP_PRET, &apos;&apos;Manopera&apos;&apos; COMP_TIP,
    tmp.LOCMUNCA, tmp.DSV, tmp.NrOp, tmp.Detalii, tmp.Operatie, tmp.BPS, tmp.Tarif, tmp.TPIMIN, tmp.TPIORE, tmp.TUMIN, tmp.TUORE, tmp.MANVAL, tmp.MANOBS,
    INTERV.DENUMIRE Interventie, RESP.PERSOANE Responsabili, U.NRINVENTAR, OBJU.DENUMIRE Utilaj, RESP.MARCI, PKG_LIST_BASE_FISAMENTENANTA.AduDescriere(u2.codutilaj2)&apos;||gUserAlias||&apos;
  FROM tmp_comdoc_men tmp
    LEFT JOIN num              umspec  ON umspec.codum    = tmp.um1
    LEFT JOIN nartamb          aa      ON aa.codobiect    = tmp.codobiect AND aa.umsec = tmp.umsec
    LEFT JOIN npart            prod    ON prod.codpart    = tmp.codproducator
    LEFT JOIN nclasea          ca      ON ca.codclasea    = tmp.clasa
    LEFT JOIN nclaseas         cs      ON cs.codclaseas   = tmp.clasastatist
    LEFT JOIN npart            np      ON np.codpart      = tmp.partener
    LEFT JOIN nartcli          ac      ON ac.codartcli    = 0
    LEFT JOIN nagenda          nag     ON nag.codagenda   = tmp.codlocatie
    LEFT JOIN nlocalit         nloc    ON nag.codlocalit  = nloc.codlocalit
    LEFT JOIN ntari                    ON ntari.codtara   = nloc.codtara
    LEFT JOIN nartobjtrad      ntrad   ON ntrad.codlimba  = ntari.codlimba and ntrad.codobiect = tmp.codobiect
    LEFT JOIN nechiv           e       ON e.codobiect     = tmp.codobiect
    LEFT JOIN grechiv          gre     ON gre.codgrechiv  = e.codgrupa
    LEFT JOIN oferta1          o1      ON o1.codoferta1   = COALESCE(tmp.codoferta1,CASE WHEN tmp.tipsursa IN (50,51) THEN tmp.codsursa ELSE NULL END)
    LEFT JOIN cmdlink          cll     ON cll.codcomanda1 = tmp.codcomanda1
    LEFT JOIN comanda1         csursa1 ON csursa1.codcomanda1 = cll.codliniecomanda
    LEFT JOIN comanda          csursa  ON csursa.codcomanda = csursa1.codcomanda
    LEFT JOIN UTILAJE2C        U2C     ON tmp.CODCOMANDA1 = U2C.CODCOMANDA1
    LEFT JOIN UTILAJE2         U2      ON U2C.CODUTILAJ2  = U2.CODUTILAJ2
    LEFT JOIN NINTERVENTIIAUTO INTERV  ON INTERV.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN UTILAJE          U       ON U.CODUTILAJ    = U2.CODUTILAJ
    LEFT JOIN NARTOBJ          OBJU    ON OBJU.CODOBIECT = U.CODOBIECT
    LEFT JOIN TMP_PERSONAL_MAN Resp    ON U2C.CODUTILAJ2 = Resp.COD
    &apos;||gSuplJoins||&apos;
  ORDER BY tmp.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert,  vListID, vListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert1, vListID, vListVer);
END;

PROCEDURE ComManopera(tmpName IN VARCHAR2) IS
  sInsert   VARCHAR2(25000);
BEGIn
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     ART,
     UM,
     CANTACC,
     CANTREST,
     PRET,
     Reteta,
     NrOp,
     Cant,
     Operatie,
     LocMunca,
     DenTarif,
     tarif,
     tu,
     valoare,
     dsv,
     bps,
     tpi,
     obs,
     detalii &apos;||gUserFields||&apos;)
  SELECT
     prod.DENUMIRE,
     NUM1.DEN_UM1,
     C1.CANTACCEPTAT,
     C1.RESTACCEPTAT,
     C1.PU,
     PC.OBS,
     MAN.NrOp,
     MAN.Cant,
     OP.DENUMIRE,
     LM.DENUMIRE,
     T.DenUMIRE,
     T.tarif,
     MAN.tu,
     MAN.valoare,
     MAN.dsv,
     MAN.bps,
     MAN.tpi,
     C1.obs,
     MAN.detalii &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1   c1      on c.codcomanda       = c1.codcomanda
    INNER JOIN NARTOBJ    PROD    ON PROD.CODOBIECT     = C1.CODOBIECT
    INNER JOIN NART       ARTPROD ON ARTPROD.CODARTICOL = PROD.CODARTICOL
    INNER JOIN NUM1       NUM1    ON NUM1.CODUM1        = C1.UMSEC
    INNER JOIN cmdprodman man     on c1.codcomanda1     = man.codcomanda1
    INNER JOIN PRODCOMP   PC      ON PC.CODPRODCOMP     = C1.CODRETETA
    INNER JOIN noper      op      on man.codop          = op.codop
    INNER JOIN locmunca   lm      on lm.codloc          = man.codloc
    INNER JOIN (
      SELECT T1.codtarif, T1.Tarif, t.denumire
      FROM TARIFEMAN1 T1 INNER JOIN tarifeman t on t1.codtarif = t .codtarif AND pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU BETWEEN T1.ALSTART and T1.ALSTOP
    ) T ON MAN.CODTARIF = T.CODTARIF
  &apos;||gSuplJoins||&apos;
  WHERE C.CodComanda = &apos;||vCodComanda;

  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
END;

PROCEDURE ComServAuto(tmpName IN VARCHAR2, aID in number) IS
  sInsert       VARCHAR2(25000);
  sSer          VARCHAR2(5000);
  sInsUMA       VARCHAR2(5000);
  sSelUMA       VARCHAR2(5000);
  sJoinUMA      VARCHAR2(5000);
  aModulCereale NUMBER := 2;
  sT1Procent    VARCHAR2(100) := &apos;case when c.tipdoc=94 and r.faratva=1 then 0 else t1.procent end&apos;;
  sAnLuna       VARCHAR2(100) := &apos;(Extract(year from R.DataStart)*12+Extract(Month from R.DataStart))&apos;;
  sServ         VARCHAR2(500);
  gServ         VARCHAR2(500);
BEGIN
  sServ := &apos;&apos;;
  gServ := &apos;&apos;;
  if aID = 384 then
    sServ   := &apos;, TipServ&apos;;
    gServ   := &apos;, Decode(c1.tipliniesa,1,&apos;&apos;Client&apos;&apos;,2,&apos;&apos;Constatat&apos;&apos;,&apos;&apos;...Nedefinit...&apos;&apos;)&apos;;
		sAnLuna := &apos;(c.an*12+c.luna)&apos;;
  end if;
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTCOM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM,
    ADAOS, DISC, PROCTVA, VALCUTVA,
    OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, Masa, Volum, CodVamal, Prod,
    DenLaCli, CodLaCli, CodListat,
    UMPrinc, Paritate, PlataSofer,SursaClient &apos;||sServ||gUserFields||&apos;)
  SELECT
    nao.denumire, num1.den_um1,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantcomandat / num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantacceptat / num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.restacceptat / num1.paritate,
    c1.pu * num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantcomandat * c1.pu,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantacceptat * c1.pu,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.restacceptat * c1.pu,
    c1.termen,
    c1.addim, c1.procdisc, &apos;||sT1Procent||&apos;,
    case
       when r.faratva = 1 then  c1.cantacceptat * c1.pu
       else c1.cantacceptat * c1.pu * (100 + &apos;||sT1Procent||&apos;) / 100
    end,
    c1.obs, c.obs, nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, nao.codvamal, prod.den_part,
    COALESCE(ac.denumire,ntrad.denumiretrad,nao.denumire), Coalesce(ac.codextern,nao.codextern),
    Coalesce(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),
    num.den_um, num1.paritate, Decode(C1.CuLansare,1,&apos;&apos;Nu&apos;&apos;,2,&apos;&apos;Da&apos;&apos;) PlataSofer, R.SursaClient &apos;||gServ||gUserAlias||&apos;
  FROM comanda c
    Left  JOIN Rac_Rez     R      ON R.codcomanda   = c.codcomanda
    INNER JOIN comanda1    c1     ON c1.codcomanda  = c.codcomanda
    INNER JOIN nartobj     nao    ON nao.codobiect  = c1.codobiect
    INNER JOIN nart        na     ON na.codarticol  = nao.codarticol
    INNER JOIN num                ON num.codum      = na.um
    INNER JOIN num1               ON num1.codum1    = c1.umsec
    LEFT  JOIN num         umspec ON umspec.codum   = na.um1
    LEFT  JOIN nartamb     aa     ON aa.codobiect   = nao.codobiect AND aa.umsec = c1.umsec
    LEFT  JOIN npart       prod   ON prod.codpart   = nao.codproducator
    LEFT  JOIN nclasea     ca     ON ca.codclasea   = na.clasa
    LEFT  JOIN nclaseas    cs     ON cs.codclaseas  = na.clasastatist
    LEFT  JOIN npart       np     ON np.codpart     = c.partener
    LEFT  JOIN tmp_nartcli ac     ON ac.codobiect   = c1.codobiect
    LEFT  JOIN nagenda     nag    ON nag.codagenda  = c.codlocatie
    LEFT  JOIN nlocalit    nloc   ON nag.codlocalit = nloc.codlocalit
    LEFT  JOIN ntari              ON ntari.codtara  = nloc.codtara
    LEFT  JOIN nartobjtrad ntrad  ON ntrad.codlimba = ntari.codlimba and ntrad.codobiect = nao.codobiect
    LEFT  JOIN nechiv      e      ON e.codobiect    = c1.codobiect
    LEFT  JOIN grechiv     gre    ON gre.codgrechiv = e.codgrupa
    LEFT  JOIN nart1       na1    ON na1.codarticol = nao.codarticol AND &apos;||sAnLuna||&apos; BETWEEN  na1.ALSTART and  na1.ALSTOP
    LEFT  JOIN ntva1       t1     ON t1.codtva      = na1.codtva     AND &apos;||sAnLuna||&apos; BETWEEN   t1.ALSTART and   t1.ALSTOP
    LEFT  JOIN nartobj1    nao1   ON nao1.codobiect = nao.codobiect  AND &apos;||sAnLuna||&apos; BETWEEN nao1.ALSTART and nao1.ALSTOP
    LEFT  JOIN oferta1     o1     ON o1.codoferta1  = COALESCE(c1.codoferta1,CASE WHEN c1.tipsursa IN (50,51) THEN c1.codsursa ELSE NULL END)&apos;||
    gSuplJoins||&apos;
  WHERE c.codcomanda = &apos;||vCodComanda||&apos;
  ORDER BY c1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
END;

PROCEDURE ComPart(tmpName IN VARCHAR2) IS
  sInsert       VARCHAR2(25000);
  sSer          VARCHAR2(5000);
  sInsUMA       VARCHAR2(5000);
  sSelUMA       VARCHAR2(5000);
  sJoinUMA      VARCHAR2(5000);
  aModulCereale NUMBER := 2;
  sT1Procent    VARCHAR2(100) := &apos;t1.procent&apos;;
BEGIN
  BEGIN
    SELECT CASE WHEN UPPER(SubStr(trim(cf.codfiscal),1,2)) = &apos;RO&apos; AND pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos; THEN 1 ELSE 2 END
    INTO aModulCereale
    FROM comanda c LEFT JOIN npartcodfisc cf ON cf.cod_codfiscal = c.codfiscal
    WHERE c.codcomanda = vCodComanda;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  IF aModulCereale = 1 THEN
    sT1Procent := &apos;CASE WHEN trim(nao.codd394) is NULL THEN t1.procent ELSE 0 END&apos;;
  END IF;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantacceptat&apos;,&apos;c1.codobiect&apos;,sInsUMA,sSelUMA,sJoinUMA);
  IF vID IN (104,122,267) THEN
    sSer := &apos;
      SELECT
        codcomanda1,
        vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) serii,
        vc2_nt_to_vc3200(CAST(COLLECT(serie||&apos;&apos; - &apos;&apos;||sertg) AS vc2_nt)) serii_tg,
        vc2_nt_to_vc3200(CAST(COLLECT(ser)     AS vc2_nt)) ser,
        vc2_nt_to_vc3200(CAST(COLLECT(sertg)   AS vc2_nt)) sertg,
        vc2_nt_to_vc3200(CAST(COLLECT(sercant) AS vc2_nt)) sercant
      FROM (
        SELECT c1.codcomanda1, NSERII.SERIE||CASE WHEN SUM(R.REST) &lt;&gt; 1 THEN &apos;&apos;(&apos;&apos;||SUM(R.REST)||&apos;&apos;)&apos;&apos; END SERIE, NSERII.SERIE SER, TO_CHAR(SUM(R.REST)) SERCANT, TO_CHAR(Coalesce(nirser.tg, ns.tg)) SERTG
        FROM COMANDA1 C1
          INNER JOIN REZERVATS R  ON R.CODCOMANDA1    = C1.CODCOMANDA1
          INNER JOIN NIRSTOC   NS ON NS.CODNIRSTOC    = R.CODNIRSTOC
          INNER JOIN NIRSER       ON NIRSER.CODNIRSER = R.CODNIRSER
          INNER JOIN NSERII       ON NSERII.CODSERIE  = NIRSER.CODSERIE
        WHERE c1.codcomanda = &apos;||vCodComanda||&apos;
        GROUP BY c1.codcomanda1, nserii.serie, Coalesce(nirser.tg, ns.tg)
      )
      GROUP BY codcomanda1
    &apos;;
  ELSE
    sSer := &apos;SELECT 0 codcomanda1, NULL serii, NULL serii_tg, NULL ser, NULL serTG, NULL serCant FROM dual&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTCOM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM,
    ADAOS, DISC, PROCTVA, VALCUTVA,
    OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, Masa, Volum, CodVamal, Prod,
    DenLaCli, CodLaCli, CodListat,
    UMPrinc, Paritate, UM1, CANTUM1, D1, D2, D3,
    Relatie,
    UMMasa, UMDimA, UMDimB, UMDimC, DenClaseAS,
    DENATRIB,
    PARTENER, TipCmdLans,
    SERII, SERIEDATA, SER, SERTG, SERCANT,
    Responsabili&apos;||sInsUMA||gUserFields||&apos;)
  SELECT
    nao.denumire, num1.den_um1,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantcomandat / num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantacceptat / num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.restacceptat / num1.paritate,
    c1.pu * num1.paritate,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantcomandat * c1.pu,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.cantacceptat * c1.pu,
    CASE WHEN c.tipdoc IN (65,66) THEN -1 ELSE 1 END * c1.restacceptat * c1.pu,
    c1.termen,
    c1.addim, c1.procdisc, &apos;||sT1Procent||&apos;, c1.cantacceptat * c1.pu * (100 + &apos;||sT1Procent||&apos;) / 100,
    c1.obs, c.obs, nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, nao.codvamal, prod.den_part,
    COALESCE(ac.denumire,ntrad.denumiretrad,nao.denumire), Coalesce(ac.codextern,nao.codextern),
    Coalesce(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),
    num.den_um, num1.paritate, umspec.den_um, case when &apos;||vID||&apos; = 289 then c1.acceptum1 else c1.cantum1 end, c1.d1, c1.d2, c1.d3,
    decode(na.relatieum1,
      0,&apos;&apos;independente&apos;&apos;,
      1,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / &apos;&apos;||c1.D1,
      2,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos;)&apos;&apos;,
      3,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos; x &apos;&apos;||c1.D3||&apos;&apos;)&apos;&apos;,
      4,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||c1.D1,
      5,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2,
      6,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos; x &apos;&apos;||c1.D3,
      7,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||c1.D1,
      8,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2,
      9,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos; x &apos;&apos;||c1.D3,
      10,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / &apos;&apos;||c1.D1,
      11,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / (&apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos;)&apos;&apos;,
      12,num.den_um||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / (&apos;&apos;||c1.D1||&apos;&apos; x &apos;&apos;||c1.D2||&apos;&apos; x &apos;&apos;||c1.D3||&apos;&apos;)&apos;&apos; ),
    aa.masa, aa.lungime, aa.latime, aa.inaltime, cs.den_claseas,
    ( SELECT vc2_nt_to_string(CAST(collect(a.denumire order by aa.indexlocal) AS vc2_nt))
      FROM nartatr aa INNER JOIN natrib a ON a.codatribut = aa.codatribut
      WHERE aa.codarticol = nao.codarticol
    ) DENATRIB,
    case when &apos;||vID||&apos;=289 then Coalesce(PKG_LIST_BASE_UTILS.GetPartComCli(C1.CODCOMANDA1),PKG_LIST_BASE_UTILS.GetGestCom(C1.CODCOMANDA1)) else &apos;&apos;&apos;&apos; end, case when csursa.tipdoc = 18 then &apos;&apos;Cc&apos;&apos; when csursa.tipdoc = 44 then &apos;&apos;Cs&apos;&apos; else &apos;&apos;&apos;&apos; end,
    SER.SERII, SER.SERII_TG, SER.SER, SER.SERTG, SER.SERCANT,
    (SELECT STRING_AGG(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME) FROM UTILAJE2P U2P LEFT JOIN NPERS P ON U2P.CODPERS = P.CODPERS WHERE U2P.CODUTILAJ2 = U2C.CODUTILAJ2) Responsabili&apos;||
    sSelUMA||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1     c1      ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj      nao     ON nao.codobiect = c1.codobiect
    INNER JOIN nart         na      ON na.codarticol = nao.codarticol
    INNER JOIN num                  ON num.codum   = na.um
    INNER JOIN num1                 ON num1.codum1 = c1.umsec
    LEFT  JOIN cmdlink      cll     ON cll.codcomanda1     = c1.codcomanda1
    LEFT  JOIN comanda1     csursa1 ON csursa1.codcomanda1 = cll.codliniecomanda
    LEFT  JOIN comanda      csursa  ON csursa.codcomanda   = csursa1.codcomanda
    LEFT  JOIN cmdlivrlink  clc     ON clc.codcomanda1 = COALESCE(cll.codliniecomanda, c1.codcomanda1)
    LEFT  JOIN comanda1     c1c     ON c1c.codcomanda1 = CASE WHEN c.tipdoc IN (8,18) AND Coalesce(c.displivrare,0) = 0 THEN c1.codcomanda1 ELSE clc.codliniecomanda END
    LEFT  JOIN comanda      cc      ON cc.codcomanda  = c1c.codcomanda
    LEFT  JOIN num          umspec  ON umspec.codum   = na.um1
    LEFT  JOIN nartamb      aa      ON aa.codobiect   = nao.codobiect AND aa.umsec = c1.umsec
    LEFT  JOIN npart        prod    ON prod.codpart   = nao.codproducator
    LEFT  JOIN nclasea      ca      ON ca.codclasea   = na.clasa
    LEFT  JOIN nclaseas     cs      ON cs.codclaseas  = na.clasastatist
    LEFT  JOIN npart        np      ON np.codpart     = c.partener
    LEFT  JOIN tmp_nartcli  ac      ON ac.codobiect   = c1.codobiect
    LEFT  JOIN nagenda      nag     ON nag.codagenda  = c.codlocatie
    LEFT  JOIN nlocalit     nloc    ON nag.codlocalit = nloc.codlocalit
    LEFT  JOIN ntari                ON ntari.codtara  = nloc.codtara
    LEFT  JOIN nartobjtrad  ntrad   ON ntrad.codlimba = ntari.codlimba and ntrad.codobiect = nao.codobiect
    LEFT  JOIN nechiv       e       ON e.codobiect    = c1.codobiect
    LEFT  JOIN grechiv      gre     ON gre.codgrechiv = e.codgrupa
    LEFT  JOIN nart1        na1     ON na1.codarticol = nao.codarticol AND (c.an*12+c.luna) BETWEEN  na1.ALSTART and  na1.ALSTOP
    LEFT  JOIN ntva1        t1      ON t1.codtva      = na1.codtva     AND (c.an*12+c.luna) BETWEEN   t1.ALSTART and   t1.ALSTOP
    LEFT  JOIN nartobj1     nao1    ON nao1.codobiect = nao.codobiect  AND (c.an*12+c.luna) BETWEEN nao1.ALSTART and nao1.ALSTOP
    LEFT  JOIN oferta1      o1      ON o1.codoferta1      = COALESCE(c1.codoferta1,CASE WHEN c1.tipsursa IN (50,51) THEN c1.codsursa ELSE NULL END)
    LEFT  JOIN UTILAJE2C    U2C     ON C1.CODCOMANDA1     = U2C.CODCOMANDA1
    LEFT  JOIN CONTRACT1    CONTR1  ON C1.CODCONTRACT1    = CONTR1.CODCONTRACT1
    LEFT  JOIN CONTRACT     CONTR   ON CONTR1.CODCONTRACT = CONTR.CODCONTRACT
    LEFT  JOIN (&apos;||sSer||&apos;) SER     ON ser.codcomanda1    = c1.codcomanda1&apos;||
    sJoinUMA||gSuplJoins||&apos;
  WHERE c.codcomanda = &apos;||vCodComanda||&apos;
  ORDER BY c1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, vListID, vListVer);
END;

PROCEDURE ADD_LIST_PARAMS IS
  SitV           VARCHAR2(2);
  aSitV          NUMBER;
  aBancaV        NUMBER;
  aMonedaV       NUMBER;
  vTipDoc        NUMBER;
  vNrTerm        NUMBER := 12;
  vVal           NUMBER :=  0;
  vVCT           NUMBER :=  0;
  vTVA           NUMBER :=  0;
  sCotaTVA       VARCHAR2(3200);
  vMaxTerm       DATE;
  mComFurn       NUMBER :=  8;
  mComCli        NUMBER := 18;
  mComGest       NUMBER := 43;
  mComCatreSub   NUMBER := 44;
  mComProdComp   NUMBER := 53;
  mAmbCustDel    NUMBER := 57;
  mComDeLaSub    NUMBER := 60;
  mComStorno     NUMBER := 65;
  mComStornoFurn NUMBER := 66;
  mComServAut    NUMBER := 92;
  mComenziRAC    NUMBER := 94;
  aInd           NUMBER := 1;
  vSoldPart      NUMBER := 0;
  vComCurs       NUMBER := 0;
  sAux           VARCHAR2(3200);
  adrPrel        VARCHAR2(200);
  adrLivr        VARCHAR2(200);
  vAnLunaIni     NUMBER;
BEGIN
  -- apelat si din PKG_LIST_BASE_COMETICHETE
  pkg_list_Struct.GOLESTE_PARAM;
  pkg_globals.SetSeparator(&apos;;&apos;);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN SitV := &apos;DA&apos;;
  ELSE SitV := &apos;NU&apos;;
  END IF;

  SELECT aninitial*12+lunainitiala INTO vAnLunaIni FROM FIRMALUNI;

  SELECT
    Round(SUM(CASE WHEN COALESCE(c1.cantacceptat,0) = 0 THEN c1.cantcomandat ELSE c1.cantacceptat END * c1.pu * (1+Coalesce(c1.procdisc,0)/100) * (1+
   Case when C.TipDoc = 94 and r.faratva=1 then 0 else  Coalesce(t1.procent,0)end /100) ),2),
    Round(SUM(CASE WHEN COALESCE(c1.cantacceptat,0) = 0 THEN c1.cantcomandat ELSE c1.cantacceptat END * c1.pu * (1+Coalesce(c1.procdisc,0)/100) *
   Case when C.TipDoc = 94 and r.faratva=1 then 0 else 
                                                case when (coalesce(c.pretcuamanunt,0) = 1 and C.TipDoc = 18) then COALESCE(t1.procent,0)/(100 + COALESCE(t1.procent,0))  
                                                     else  Coalesce(t1.procent,0)/100 
                                                 end 
         end      ), 2),
    Max(COALESCE(C1.Termen,PKG_GLOBALS.DATA0)),
    vc2_nt_to_vc3200_dist(CAST(COLLECT(To_Char(t1.procent) ORDER BY Coalesce(t1.procent,0)) AS vc2_nt)) CotaTVA
  INTO
    vVCT,
    vTVA,
    vMaxTerm,
    sCotaTVA
  FROM Comanda C
    INNER JOIN Comanda1 C1 ON c1.codcomanda = c.codcomanda
    LEFT  JOIN RAC_REZ  R  ON R.codcomanda  = c.codcomanda
    INNER JOIN nartobj  o  ON o.codobiect   = c1.codobiect
    INNER JOIN nart1    a1 ON a1.codarticol = o.codarticol AND Greatest(Case when C.TipDoc = 94 then Extract(year from R.DataStart)*12+ Extract(Month from R.DataStart) else  C.An * 12 + C.Luna end, vAnLunaIni)
                                                                 BETWEEN a1.ALSTART and a1.ALSTOP
    INNER JOIN ntva1    t1 ON t1.codtva     = a1.codtva    AND Greatest(Case when C.TipDoc = 94 then Extract(year from R.DataStart)*12+ Extract(Month from R.DataStart) else  C.An * 12 + C.Luna end, vAnLunaIni)
                                                                 BETWEEN t1.ALSTART and t1.ALSTOP
  WHERE C.CodComanda = vCodComanda;

  FOR v_rec IN (
    SELECT
      SAC.kmbord SAKMBORD, Decode(SAC.tipcomsa,1,&apos;Asigurare&apos;,2,&apos;Garantie&apos;,3,&apos;Client&apos;,4,&apos;Interne&apos;) SATIP,
      SAA.nrinreg SANRINREG, SAM.MARCA SAMARCA, SAV.MODEL SAMODEL,
      SAA.SERIEC SASERIEC, SAA.SERIEM SASERIEM,
      SAC.CODNPARCAUT SACODNPARCAUT,
      SAC.kmbord LSAKMBORD, Decode(SAC.tipcomsa,1,&apos;Asigurare&apos;,2,&apos;Garantie&apos;,3,&apos;Client&apos;,4,&apos;Interne&apos;) LSATIP,
      C.PrefixDoc, C.SeriaDoc, C.NrDoc, C.DataDoc
    FROM NPARCCOM SAC
      LEFT JOIN NPARCAUT    SAA  ON SAA.CODNPARCAUT   = SAC.CODNPARCAUT
      LEFT JOIN NMARCIAUTO  SAM  ON SAM.CODMARCIAUTO  = SAA.MARCA
      LEFT JOIN NMODELEAUTO SAV  ON SAV.CODMODELEAUTO =  SAA.MODEL
      LEFT JOIN NPARCCOM    SACA ON SACA.CODNPARCAUT  = SAC.CODNPARCAUT AND SACA.CODNPARCCOM &lt; SAC.CODNPARCCOM
      LEFT JOIN COMANDA     C    ON C.CODCOMANDA      = SACA.CODCOMANDA
    WHERE SAC.CODCOMANDA = vCodComanda AND ROWNUM = 1
    ORDER BY SACA.CODNPARCCOM DESC
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - KM Bord&apos;,           v_rec.SAKMBORD);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Tip&apos;,               v_rec.SATIP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Numar&apos;,             v_rec.SANRINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Marca&apos;,             v_rec.SAMARCA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Model&apos;,             v_rec.SAMODEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Serie caroserie&apos;,   v_rec.SASERIEC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto - Serie motor&apos;,       v_rec.SASERIEM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - KM Bord&apos;,  v_rec.LSAKMBORD);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - Tip&apos;,      v_rec.LSATIP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - DOC&apos;,      v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - SERIEDOC&apos;, v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - NRDOC&apos;,    v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serv Auto anterior - DATADOC&apos;,  To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
  END LOOP;

  FOR v_rec IN (
    SELECT
      UT.UserName, Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI, US.TELEFON UTEL, US.EMAIL UEMAIL
    FROM Comanda C
      LEFT JOIN NPERS          U  ON U.LOGONNAME      = C.USERID
      LEFT JOIN NAGENDA        US ON US.CODAGENDA     = U.AGENDA
  	  LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = C.USERID
    WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT DE&apos;,                     v_rec.USERNAME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,                   v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT TELEFON&apos;,                v_rec.UTEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT EMAIL&apos;,                  v_rec.UEMAIL);
  END LOOP;

  FOR v_rec IN (
    SELECT
      coalesce(c.pretcuamanunt,0) pretcuamanunt,
      C.TipDoc, C.PrefixDoc, C.SeriaDoc, C.NrDoc, C.DataDoc, C.Obs, C.NRI,
      CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET, case when c.tipdoc = mComenziRAC then C.SERIADOC else CAR.SERIE end SERIECARNET,
      C.Schimb, C.Lot, DECODE(C.CURS,0,1,NULL,1,C.CURS) CURS, M.DEN_MONEDA,
      C.Valoare Val,
      CASE WHEN Coalesce(aMonedaV,0) = 0 OR Coalesce(aBancaV,0) = 0 THEN 1 ELSE PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMonedaV,aBancaV,c.datadoc) END CursSitV,
      (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = Coalesce(aMonedaV,0)) MonedaSitV,
      (SELECT DENUMIRE FROM NBANK WHERE CODBANK = Coalesce(aBancaV,0)) BancaSitV,
      Decode(C.VERIFICAT,1,&apos;Verificat&apos;,&apos;Neverificat&apos;) VERIFICAT,
      (select listagg(&apos; &apos;||i.prefixdoc||to_char(i.nrdoc)||&apos;/&apos;||to_char(i.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||TO_CHAR(i.valdoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;), &apos;;&apos;)
       WITHIN GROUP (ORDER BY i.datadoc) from iesiri i, cmdavans l where i.codies = l.codiesavans and l.codcomanda = c.codcomanda) factav,
      (select sum(i.valdoc) from iesiri i, cmdavans l where i.codies = l.codiesavans and l.codcomanda = c.codcomanda) valav
    FROM Comanda C
      LEFT JOIN NMonede    M   ON M.CODMONEDA   = C.MONEDA
      LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = C.CARNETDOC
    WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
  ) LOOP
    vTipDoc := v_rec.TipDoc;
    if v_Rec.pretcuamanunt = 1 then
    vVal    := v_rec.Val-vtva;
    vVCT    := v_rec.Val;
    vTVA    := Coalesce(vTVA, 0);  
    else
    vVal    := v_rec.Val;
    vVCT    := Coalesce(vVCT, v_rec.Val);
    vTVA    := Coalesce(vTVA, 0);
    end if;

    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CURS&apos;,                            TO_CHAR(v_rec.Curs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT&apos;,                        v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NRI&apos;,                    v_rec.NRI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,                  v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    if not vTipDoc = 18 then
      if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE&apos;,                TO_CHAR(vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE CU TVA&apos;,         TO_CHAR(vVCT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE TVA&apos;,            TO_CHAR(vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI&apos;,               TO_CHAR(v_rec.Curs*vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI CU TVA&apos;,        TO_CHAR(v_rec.Curs*vVCT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI TVA&apos;,           TO_CHAR(v_rec.Curs*vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      else
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE&apos;,                &apos;***&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE CU TVA&apos;,         &apos;***&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE TVA&apos;,            &apos;***&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI&apos;,               &apos;***&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI CU TVA&apos;,        &apos;***&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI TVA&apos;,           &apos;***&apos;);
      end if;
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;AVANS&apos;,                           v_rec.factav);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AVANS VALOARE TOTALA&apos;,            TO_CHAR(coalesce(v_rec.valav,0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT REST NEF.AVANS&apos;,         TO_CHAR(vVCT-coalesce(v_rec.valav,0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE&apos;,                TO_CHAR(vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE CU TVA&apos;,         TO_CHAR(vVCT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE TVA&apos;,            TO_CHAR(vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI&apos;,               TO_CHAR(v_rec.Curs*vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI CU TVA&apos;,        TO_CHAR(v_rec.Curs*vVCT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VAL. LEI TVA&apos;,           TO_CHAR(v_rec.Curs*vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    end if;
    pkg_list_Struct.ADAUGA_PARAM(&apos;COTA TVA&apos;,                        sCotaTVA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SerieCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);

    pkg_list_Struct.ADAUGA_PARAM(&apos;VERIFICAT&apos;,                       v_rec.Verificat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA&apos;         ,      SitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - MONEDA&apos;,      v_rec.MonedaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - BANCA&apos; ,      v_rec.BancaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - CURS&apos;  ,      TO_CHAR(v_rec.CursSitV,&apos;fm9G999G999G990D0000&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  FOR V_rec IN (
    SELECT SUM(Coalesce(O.MASA,0) * C1.CANTACCEPTAT) MASA, SUM(Coalesce(O.VOLUM,0)* C1.CANTACCEPTAT) VOLUM
    FROM COMANDA1 C1 INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
    WHERE C1.CODCOMANDA = vCodComanda
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA ACCEPTATA&apos;,                  TO_CHAR(v_rec.Masa ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM ACCEPTAT&apos;,                  TO_CHAR(v_rec.Volum,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  IF vTipDoc = mComGest THEN
    sAux := &apos;&apos;;
    BEGIN
      SELECT STRING_AGG(DEN_GEST)
      INTO sAux
      FROM (
        SELECT DISTINCT G.DEN_GEST
        FROM COMANDA1 C1, REZERVATS R, NIRSTOC NS, NIR, NGEST G
        WHERE C1.CodComanda = vCodComanda AND C1.CODCOMANDA1 = R.CODCOMANDA1 AND R.CODNIRSTOC = NS.CODNIRSTOC AND  NS.CODNIR = NIR.CODNIR AND NIR.GEST = G.CODGEST
      );
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
    pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiuni de rezervare&apos;,         sAux);
  END IF;

  IF vTipDoc IN (mComServAut, mComenziRAC) THEN
    FOR v_rec IN (
      SELECT
        G.Den_Gest, GS.Telefon GTelefon, GetAdresa(GS.sector, GS.strada, GS.nr1, GS.nr2, GS.bloc, GS.scara, GS.etaj, GS.apart, GS.codpostal) GAdresa, GL.Den_Localit GDen_localit, GJ.Den_Judet GDen_judet,
        GSOS.TELEFON GTelefonS,
        GetAdresa(GSOS.sector, GSOS.strada, GSOS.nr1, GSOS.nr2, GSOS.bloc, GSOS.scara, GSOS.etaj, GSOS.apart, GSOS.codpostal) GDestAdresa,
        r.kmnextrev LimitaKM
       FROM Comanda C
        LEFT JOIN RAC_REZ  R    ON C.CODCOMANDA  = R.CODCOMANDA
        LEFT JOIN NGEST    G    ON G.CODGEST     = R.CODGESTSURSA
        LEFT JOIN NAGENDA  GS   ON GS.CODGEST    = G.CODGEST
        LEFT JOIN NLOCALIT GL   ON GL.CODLOCALIT = GS.CODLOCALIT
        LEFT JOIN NJUDET   GJ   ON GJ.CODJUDET   = GL.CODJUDET
        LEFT JOIN NGEST    GSO  ON GSO.CODGEST   = R.CODGESTDEST
        LEFT JOIN NAGENDA  GSOS ON GSO.CODGEST   = GSOS.CODGEST
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune plecare Denumire&apos;,             v_rec.Den_Gest);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune plecare Telefon&apos;,              v_rec.GTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune plecare Adresa&apos;,               v_rec.GAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune plecare Localitate&apos;,           v_rec.GDen_localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune plecare Judet&apos;,                v_rec.GDen_judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune sursa Telefon&apos;,                v_rec.GTelefonS);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Gestiune destinatie Telefon&apos;,       v_rec.GTelefonS);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Gestiune destinatie Adresa&apos;,        v_rec.GDestAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Limita km&apos;,                         v_rec.LimitaKM);
    END LOOP;
  END IF;

  IF vTipDoc = mComGest THEN
    FOR v_rec IN (
      SELECT
        G.Den_Gest, GS.Telefon GTelefon, GetAdresa(GS.sector, GS.strada, GS.nr1, GS.nr2, GS.bloc, GS.scara, GS.etaj, GS.apart, GS.codpostal) GAdresa, GL.Den_Localit GDen_localit, GJ.Den_Judet GDen_judet,
        D.DELEGAT, D.CNP, D.SERIEDOC, D.NRDOC, D.mijltransp, D.nrtransp, M.NRINREG
       FROM Comanda C
        LEFT JOIN NPARTTR  D  ON D.CODPARTTR   = C.DELEGAT
        LEFT JOIN NGEST    G  ON G.CODGEST     = c.codgest
        LEFT JOIN NAGENDA  GS ON GS.CODGEST    = G.CODGEST
        LEFT JOIN NLOCALIT GL ON GL.CODLOCALIT = GS.CODLOCALIT
        LEFT JOIN NJUDET   GJ ON GJ.CODJUDET   = GL.CODJUDET
        LEFT JOIN NPARCAUT M  ON M.CODNPARCAUT = C.MIJLTRANSP
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune Denumire&apos;,             v_rec.Den_Gest);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune Telefon&apos;,              v_rec.GTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune Adresa&apos;,               v_rec.GAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune Localitate&apos;,           v_rec.GDen_localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune Judet&apos;,                v_rec.GDen_judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT&apos;,                       v_rec.DELEGAT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CI SERIE&apos;,              v_rec.SERIEDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CI NR&apos;,                 v_rec.NRDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CNP&apos;,                   v_rec.CNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT TRANSPORT&apos;,             v_rec.MIJLTRANSP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT NR AUTO&apos;,               v_rec.NRTRANSP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR AUTO&apos;,             v_rec.NRINREG);
    END LOOP;
  END IF;

  IF vTipDoc = mComCatreSub THEN
    FOR v_rec IN (
      SELECT
        S.DEN_SUBUNIT, S.CIF SCIF, S.REGCOM SREGCOM, GetAdresa(SS.sector, SS.strada, SS.nr1, SS.nr2, SS.bloc, SS.scara, SS.etaj, SS.apart, SS.codpostal) SADRESA,
        SS.TELEFON STELEFON, SL.DEN_LOCALIT SDEN_LOCALIT, SJ.SIMBAUTO SSIMBAUTO, SJ.DEN_JUDET SDEN_JUDET, SBC.DEN_CONT SDEN_CONT, SBC.NRCONT SNRCONT, SB.DENUMIRE SDEN_BANCA, SB.SIMBOL SSIMB_BANCA
      FROM Comanda C
        LEFT JOIN NSUBUNIT  S   ON S.CODSUBUNIT    = C.SUBUNITSURSA
        LEFT JOIN NAGENDA   SS  ON SS.CODSUBUNIT   = S.CODSUBUNIT
        LEFT JOIN NLOCALIT  SL  ON SL.CODLOCALIT   = SS.CODLOCALIT
        LEFT JOIN NJUDET    SJ  ON SJ.CODJUDET     = SL.CODJUDET
        LEFT JOIN NBANKCONT SBC ON SBC.CODBANKCONT = S.CODBANKCONT
        LEFT JOIN NBANK     SB  ON SB.CODBANK      = SBC.CODBANK
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Denumire&apos;,           v_rec.Den_Subunit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate CIF&apos;,                v_rec.SCIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate R.C.&apos;,               v_rec.SRegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Adresa&apos;,             v_rec.SAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Localitate&apos;,         v_rec.SDen_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Judet&apos;,              v_rec.SDen_Judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Banca&apos;,              v_rec.SDen_Banca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate Banca Simbol&apos;,       v_rec.SSimb_Banca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate NrCont&apos;,             v_rec.SNrCont);
    END LOOP;
  END IF;

  IF vTipDoc IN (mComFurn, mComCli, mAmbCustDel, mComStorno, mComServAut, mComenziRAC) THEN
    FOR v_rec IN (
      SELECT
        P.DEN_PART, P.CODPART, PCF.CODFISCAL PCIF, P.AUTORIZATIE PAUTORIZATIE, P.REGCOM PREGCOM, P.OBS PARTOBS, P.CODSTATISTICBNR PCODSTATISTICBNR,
        PB.ContBanca PContBanca, PB.Sucursala PSucursala,PB.CODSWIFT PCodSwift,PB.OBS PObs, PBK.DENUMIRE PDENBANCA, PBK.SIMBOL PSIMBBANCA, P.PERSOANAFIZICA,
        PC.Nume PCNume, PC.Prenume PCPrenume, PC.TELEFON PCTel, PC.EMAIL PCEmail,
        SFACT.OBS SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.FAX SFACTFax, SFACT.CODPOSTAL SFACTCodPostal, SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, SFACT.Email SFACTEmail,
        GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
        LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara,
        SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.FAX SSOCFax, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.Email SSOCEmail,
        GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, NULL) SSOCAdresa_No_Cp,
        GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
        LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
        CASE c.tiplivrare
          WHEN  0 THEN &apos;...&apos;
          WHEN  1 THEN &apos;EXW&apos;
          WHEN  2 THEN &apos;FCA&apos;
          WHEN  3 THEN &apos;CPT&apos;
          WHEN  4 THEN &apos;CIP&apos;
          WHEN  5 THEN &apos;DAT&apos;
          WHEN  6 THEN &apos;DAP&apos;
          WHEN  7 THEN &apos;DDP&apos;
          WHEN  8 THEN &apos;FAS&apos;
          WHEN  9 THEN &apos;FOB&apos;
          WHEN 10 THEN &apos;CFR&apos;
          WHEN 11 THEN &apos;CIF&apos;
        END InCoTerms,
        CASE c.tiplivrare
          WHEN  0 THEN &apos;&apos;
          WHEN  1 THEN &apos;Ex Works (named place of delivery)&apos;
          WHEN  2 THEN &apos;Free Carrier (named place of delivery)&apos;
          WHEN  3 THEN &apos;Carriage Paid To (named place of destination)&apos;
          WHEN  4 THEN &apos;Carriage and Insurance Paid to (named place of destination)&apos;
          WHEN  5 THEN &apos;Delivered at Terminal (named terminal at port or place of destination)&apos;
          WHEN  6 THEN &apos;Delivered at Place (named place of destination)&apos;
          WHEN  7 THEN &apos;Delivered Duty Paid (named place of destination)&apos;
          WHEN  8 THEN &apos;Free alongside ship (named port of shipment)&apos;
          WHEN  9 THEN &apos;Free on Board (named port of shipment)&apos;
          WHEN 10 THEN &apos;Cost and Freight (named port of destination)&apos;
          WHEN 11 THEN &apos;Cost, Insurance and Freight (named port of destination)&apos;
        END InCoTermsDesc, DEL.DELEGAT, DEL.CNP, DEL.SERIEDOC, DEL.NRDOC, DEL.mijltransp, DEL.nrtransp, DEL.TELEFON
      FROM Comanda C
        LEFT JOIN NPartCODFISC PCF   ON C.CODFISCAL      = PCF.Cod_CodFiscal
        LEFT JOIN NPart        P     ON P.CODPART        = C.PARTENER
        LEFT JOIN NPARTB       PB    ON PB.CODPART       = C.PARTENER AND PB.IMPLICIT = 1
        LEFT JOIN NBANK        PBK   ON PBK.CODBANK      = PB.CODBANK
        LEFT JOIN NPERSCONTACT PC    ON PC.CodPersC      = C.CodPersC
        LEFT JOIN NAGENDA      SLIVR ON SLIVR.CODAGENDA  = C.CODLOCATIE AND SLIVR.CODPART = C.PARTENER
        LEFT JOIN NAGENDA      SFACT ON SFACT.CODAGENDA  = CASE WHEN SLIVR.SediuSocial = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SediuSocial IN (3,7) THEN SLIVR.CODAGENDA ELSE 0 END
        LEFT JOIN NLOCALIT     LFACT ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
        LEFT JOIN NJUDET       JFACT ON JFACT.CODJUDET   = Coalesce(LFACT.CODJUDET, 0)
        LEFT JOIN NTARI        TFACT ON TFACT.CODTARA    = Coalesce(LFACT.CODTARA, 0)
        LEFT JOIN NAGENDA      SSOC  ON SSOC.CODPART     = C.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
        LEFT JOIN NLOCALIT     LSOC  ON LSOC.CODLOCALIT  = Coalesce(SSOC.CODLOCALIT, 0)
        LEFT JOIN NJUDET       JSOC  ON JSOC.CODJUDET    = Coalesce(LSOC.CODJUDET, 0)
        LEFT JOIN NTARI        TSOC  ON TSOC.CODTARA     = Coalesce(LSOC.CODTARA, 0)
        LEFT JOIN NPARTTR      DEL   ON DEL.CODPARTTR    = C.DELEGAT
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Denumire&apos;,             v_rec.Den_Part);
      if v_rec.persoanafizica = 1 then
        pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CIF&apos;,                  &apos;&apos;);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CNP&apos;,                  v_rec.PCif);
      else
        pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CIF&apos;,                  v_rec.PCif);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CNP&apos;,                  &apos;&apos;);
      end if;
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Autorizatie&apos;,          v_rec.PAutorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener R.C. &apos;,                v_rec.PRegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Cod Statistic BNR &apos;,   v_rec.PCODSTATISTICBNR);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener observatii&apos;,           v_rec.PartObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART CONT&apos;,               v_rec.PContBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART DENUMIRE&apos;,           v_rec.PDenBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART SIMBOL&apos;,             v_rec.PSimbBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART SUCURSALA&apos;,          v_rec.PSucursala);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART SWIFT&apos;,              v_rec.PCodSwift);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA PART OBS&apos;,                v_rec.PObs);

      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Nume&apos;,      v_rec.PCNume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Prenume&apos;,   v_rec.PCPrenume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Telefon&apos;,   v_rec.PCTel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT Email&apos;,     v_rec.PCEmail);

      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE&apos;,               v_rec.SFactObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,        v_rec.SFactAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATEA&apos;,   v_rec.SFactLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,       v_rec.SFactTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE FAX&apos;,           v_rec.SFactFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,         v_rec.SFactEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDETUL&apos;,       v_rec.SFactSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,v_rec.SFactJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,          v_rec.SFactTara);

      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL&apos;,                  v_rec.SSocObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,           v_rec.SSocAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA FARA CP&apos;,   v_rec.SSocAdresa_No_CP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,       v_rec.SSocCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATEA&apos;,      v_rec.SSocLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,          v_rec.SSocTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL FAX&apos;,              v_rec.SSocFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,            v_rec.SSocEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDETUL&apos;,          v_rec.SSocSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,   v_rec.SSocJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,             v_rec.SSocTara);
      IF VTIPDOC in (mCOMCLI,mComFurn) THEN
        pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTerms&apos;,                     v_rec.InCoTerms);
        pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTerms descriere&apos;,           v_rec.InCoTermsDesc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT&apos;,                       v_rec.delegat);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CI SERIE&apos;,              v_rec.SERIEDOC);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CI NR&apos;,                 v_rec.NRDOC);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CNP&apos;,                   v_rec.CNP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT TRANSPORT&apos;,             v_rec.MIJLTRANSP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT NR AUTO&apos;,               v_rec.NRTRANSP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT TELEFON&apos;,               v_rec.TELEFON);
      END IF;
    END LOOP;
  END IF;

  IF vTipDoc IN (mComCli,mAmbCustDel) THEN
    FOR v_rec IN (
      SELECT
        C.Partener,
        AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
        SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.FAX SLivrFax, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.Email SLIVREmail, SLIVR.KM SLIVRKM,
        GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, NULL) SLivrAdresa_No_Cp,
        GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
        LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
        Coalesce(TP.DELEGAT, TD.Nume||&apos; &apos;||TD.Prenume) TDelegat,
        TP.Doc TDoc, TP.NrDoc TNrDoc, TP.SerieDoc TSerieDoc, TP.Eliberat TEliberat, TP.DataDoc TDataDoc, TP.MijlTransp TMijlTransp, TP.NrTransp TNrTransp, TP.CNP TCNP,
        PAO.DENUMIRE PADen, NumePrenume(PAS.NUme, PAS.Prenume) PASofer, PA.NrInreg PANrInreg,
        (SELECT P1.CREDITCLIENT FROM NPART1 P1 WHERE P1.CODPART = C.PARTENER AND C.AN*12+C.LUNA BETWEEN P1.ALSTART and P1.ALSTOP) CREDITCLIENT
      FROM Comanda C
        LEFT JOIN NPERS AG ON AG.CODPERS = C.AGENT

        LEFT JOIN NAGENDA  SLIVR ON SLIVR.CODAGENDA  = C.CODLOCATIE AND SLIVR.CODPART = C.PARTENER
        LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
        LEFT JOIN NJUDET   JLIVR ON JLIVR.CODJUDET   = Coalesce(LLIVR.CODJUDET, 0)
        LEFT JOIN NTARI    TLIVR ON TLIVR.CODTARA    = Coalesce(LLIVR.CODTARA, 0)

        LEFT JOIN NPERS    TD    ON TD.CODPERS   = C.DELEGAT AND C.TipDoc = mAmbCustDel
        LEFT JOIN NPARTTR  TP    ON TP.CODPARTTR = C.DELEGAT

        LEFT JOIN NPARCAUT PA    ON PA.CODNPARCAUT = C.MIJLTRANSP
        LEFT JOIN NPERS    PAS   ON PAS.CODPERS    = PA.SOFER
        LEFT JOIN NARTOBJ  PAO   ON PAO.CODOBIECT  = PA.CODART
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                         v_rec.ANume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                     v_rec.ACNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                      v_rec.ABI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,        v_rec.SLivrObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,          v_rec.SLivrAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,  v_rec.SLivrAdresa_No_CP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,      v_rec.SLivrCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,      v_rec.SLivrLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,         v_rec.SLivrTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,             v_rec.SLivrFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,           v_rec.SLivrEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,           v_rec.SLivrSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,  v_rec.SLivrJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,            v_rec.SLivrTara);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,      v_rec.SLivrCodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER KM&apos;,                   v_rec.SLIVRKM);

      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,             v_rec.TDelegat);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,            v_rec.TDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR DOCUMENT&apos;,         v_rec.TNrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,      v_rec.TSerieDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,        v_rec.TEliberat);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,      v_rec.TDataDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                 v_rec.TMijlTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,           v_rec.TNrTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP&apos;,                 v_rec.TCNP);

      pkg_list_Struct.ADAUGA_PARAM(&apos;PARC AUTO DENUMIRE&apos;,            v_rec.PADen);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PARC AUTO SOFER&apos;,               v_rec.PASofer);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PARC AUTO NUMAR INREGISTRARE&apos;,  v_rec.PANrInreg);

      IF pGetSoldListFact = &apos;1&apos; THEN
        vSoldPart := PKG_LIST_BASE_UTILS.GetSoldPart(v_rec.Partener, 0);

        SELECT Coalesce(Sum(c1.restacceptat*c1.pu),0) INTO vComCurs
        FROM comanda c INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda AND c1.restacceptat &lt;&gt; 0
        WHERE c.partener = v_rec.Partener AND c.tipdoc = 18 AND pkg_globals.GetSubunitate IN (1,c.subunitatea);
      END IF;

      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CREDIT&apos;,                 v_rec.CREDITCLIENT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD NEACOPERIT&apos;,        TO_CHAR(vSoldPart+vComCurs ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    END LOOP;
  END IF;

  IF vTipDoc IN (mComServAut, mComenziRAC) THEN
    FOR v_rec IN (
      SELECT
        NumePrenume(RSA.Nume, RSA.Prenume) SAReceptioner
      FROM Comanda C
        LEFT JOIN NPERS RSA ON RSA.CODPERS = C.INSOTITOR
      WHERE C.CodComanda = vCodComanda AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;RECEPTIONER&apos;,                   v_rec.SAReceptioner);
      if vMaxTerm &lt;&gt; pkg_globals.DATA0 then
        pkg_list_Struct.ADAUGA_PARAM(&apos;TERMEN FINAL&apos;,                  To_Char(vMaxTerm,&apos;dd.mm.yyyy&apos;));
      else
        pkg_list_Struct.ADAUGA_PARAM(&apos;TERMEN FINAL&apos;,                  &apos;&apos;);
      end if;
    END LOOP;
  END IF;

  IF vTipDoc = mComProdComp THEN
    FOR V_REC IN (
      SELECT
        G.Den_Gest, F.DEN_FORMATIE, C.LOT, C.SCHIMB
      FROM Comanda C
        LEFT JOIN NGEST    G ON C.CODGEST     = G.CODGEST
        LEFT JOIN FORMATII F ON C.CODFORMATIE = F.CODFORMATIE
      WHERE C.CodComanda = vCodComanda
      AND ROWNUM = 1) loop
      pkg_list_Struct.ADAUGA_PARAM(&apos;SECTIE&apos;,                        v_rec.Den_Gest);
      pkg_list_Struct.ADAUGA_PARAM(&apos;FORMATIE&apos;,                      v_rec.Den_Formatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SCHIMB&apos;,                        v_rec.Schimb);
      pkg_list_Struct.ADAUGA_PARAM(&apos;LOT&apos;,                           v_rec.LOT);
      Exit;
    end loop;
  END IF;

  IF vTipDoc = mComenziRAC THEN
  	aInd := PKG_RAC_REZ.IndexGrupaAuto;
    FOR v_rec IN (
      SELECT
        Decode(rac.tiprezervare,0,&apos;Customer&apos;,1,&apos;Shuttle&apos;,3,&apos;Courtesy&apos;,4,&apos;Uz intern&apos;,5,&apos;Reparatii&apos;,6,&apos;Abonament&apos;,7,&apos;Transfer&apos;) TipRez,
        Coalesce(pa.nrinreg,&apos;..nedefinit..&apos;) nrinreg, pa.seriec, rac.nr_ref, rac.nr_zbor, racpe.den_part,
				racmarcapref.marca marpr, racmodelpref.model modpr,racmarca.marca, racmodel.model, racgt.den_gest gest_transf,
        rac.nume_card, rac.email, rac.telefon, rac.CodGestSursa,rac.CodGestDest,
        racgp.den_gest gest_prel, raclp.den_localit localit_prel, rac.adresa_prel adresa_prel,
        racgl.den_gest gest_livr, racll.den_localit localit_livr, rac.adresa_livr adresa_livr,
        rac.kmin, rac.kmout, rac.combin, rac.combout, rac.kmnextrev,
        Contr.Nrdoc nrcontract, contr.datadoc datacontract,
				rac.SUMAGARANTIE,
        PKG_LIST_BASE_UTILS.DECODE_ZI(rac.DataStart)||&apos;, &apos;|| TO_CHAR(rac.DataStart,&apos;DD.MM.YYYY HH24:MI&apos;) DataPlecare,
				PKG_LIST_BASE_UTILS.DECODE_ZI(rac.DataStop) ||&apos;, &apos;|| TO_CHAR(rac.DataStop,&apos;DD.MM.YYYY HH24:MI&apos;) DataSosire,
				PKG_LIST_BASE_UTILS.DECODE_ZI(rac.DataPred) ||&apos;, &apos;|| TO_CHAR(rac.DataPred,&apos;DD.MM.YYYY HH24:MI&apos;) DataPreluare,
        trim(TO_CHAR(rac.DataStart, &apos;Day&apos;,&apos;NLS_DATE_LANGUAGE=ENGLISH&apos;)||&apos;, &apos;||TO_CHAR(rac.DataStart, &apos;DD.MM.YYYY HH24:MI&apos;)) DepartureDate,
				trim(TO_CHAR(rac.DataStop,  &apos;Day&apos;,&apos;NLS_DATE_LANGUAGE=ENGLISH&apos;)||&apos;, &apos;||TO_CHAR(rac.DataStop, &apos;DD.MM.YYYY HH24:MI&apos;)) ArrivalDate,
				trim(TO_CHAR(rac.DataPred,  &apos;Day&apos;,&apos;NLS_DATE_LANGUAGE=ENGLISH&apos;)||&apos;, &apos;||TO_CHAR(rac.DataPred, &apos;DD.MM.YYYY HH24:MI&apos;)) RetrievalDate,
        c1.Acceptum1 CantAccept , c1.Pretum1 PretCant,
				G.Denumire ClasaAuto,
				Gc1.Denumire ClasaAutoPref,
        To_char(rac.datastart,&apos;HH24:mi&apos;) oraplecare, To_char(rac.datastop,&apos;HH24:mi&apos;) orasosire, To_char(rac.Datapred,&apos;HH24:mi&apos;) orapreluare,
        trunc(rac.datastop - rac.datastart)||&apos; zile si &apos;||cast(((rac.datastop-rac.datastart)- trunc(rac.datastop-rac.datastart))*24 as int)||&apos; ore&apos; as Zileoreinch,
        trunc(rac.datastop - rac.datastart)||&apos; days and &apos;||cast(((rac.datastop-rac.datastart)- trunc(rac.datastop-rac.datastart))*24 as int)||&apos;hours&apos; as Zileoreengl,
--sofer principal
-- NPR, NPSof, NASof, NLSof, NTSof
-- xNPR, xNLSof, xNTSof
        Coalesce(NPSof.Den_Part, xNPr.Delegat) Sofer0,
			  Coalesce(NPR.Doc,xNPr.Doc) TipDocument0 ,
			  Coalesce(NPR.Seriedoc||NPR.nrdoc, xNpr.Seriedoc||xNpr.nrdoc) as SerieDocument0 ,
			  Coalesce(NPR.Permis ,xNpr.Permis ) Permis0 ,
			  Coalesce(NLSof.Den_Localit,xNLSof.Den_Localit) Localit0 ,
			  Coalesce(NTSof.DEN_TARA, xNTSof.DEN_TARA) Tara0 ,
			  Coalesce(npr.NrPass ,xNpr.NrPass ) NrPass0,
--Sofer 1
        Coalesce(NPSof1.Den_Part, xNPr1.Delegat) Sofer1,
        Coalesce(npr1.Doc,xNpr1.Doc) TipDocument1 ,
			  Coalesce(npr1.Seriedoc||npr1.nrdoc, xNpr1.Seriedoc||xNpr1.nrdoc) as SerieDocument1 ,
			  Coalesce(npr1.Permis ,xNpr1.Permis ) Permis1 ,
			  Coalesce(NLSof1.Den_Localit,xNLSof1.Den_Localit) Localit1 ,
			  Coalesce(NTSof1.DEN_TARA, xNTSof1.DEN_TARA) Tara1 ,
			  Coalesce(npr1.NrPass ,xNpr1.NrPass ) NrPass1 ,
--Sofer 2
        Coalesce(NPSof2.Den_Part, xNPr2.Delegat) Sofer2,
        Coalesce(npr2.Doc,xNpr2.Doc) TipDocument2 ,
			  Coalesce(npr2.Seriedoc||npr2.nrdoc, xNpr2.Seriedoc||xNpr2.nrdoc) as SerieDocument2 ,
			  Coalesce(npr2.Permis ,xNpr2.Permis ) Permis2 ,
			  Coalesce(NLSof2.Den_Localit,xNLSof2.Den_Localit) Localit2 ,
			  Coalesce(NTSof2.DEN_TARA, xNTSof2.DEN_TARA) Tara2 ,
			  Coalesce(npr2.NrPass ,xNpr2.NrPass ) NrPass2
      FROM Comanda C
        LEFT JOIN Comanda1  c1   ON c1.CODCOMANDA  = c.CODCOMANDA
			  left join NEchiv   Ec1  on Ec1.Codobiect  = c1.CodObiect and Ec1.ind=1
        left join GrEchiv  Gc1  on Gc1.CODGRECHIV = Ec1.CodGrupa

        LEFT JOIN nparcaut pa ON pa.codnparcaut = c.mijltransp

				LEFT JOIN NEchiv  E ON E.Codobiect  = Pa.CodArt
        LEFT JOIN GrEchiv G ON G.CODGRECHIV = E.CodGrupa

				LEFT JOIN rac_rez  rac   ON rac.codcomanda   = c.codcomanda
        LEFT JOIN ngest    racgp ON racgp.codgest    = rac.codgestsursa
        LEFT JOIN nlocalit raclp ON raclp.codlocalit = rac.codlocalit_prel
        LEFT JOIN ngest    racgl ON racgl.codgest    = rac.codgestdest
        LEFT JOIN nlocalit racll ON racll.codlocalit = rac.codlocalit_livr
        LEFT JOIN npart    racpe ON racpe.codpart    = rac.codpartext

		    LEFT JOIN contract    contr        ON contr.Codcontract = C.codContract
		    LEFT JOIN nparcaut    auto         ON auto.Codnparcaut  = C.Mijltransp
        LEFT JOIN nmarciauto  racmarca     ON racmarca.codmarciauto  = auto.marca
        LEFT JOIN nmodeleauto racmodel     ON racmodel.codmodeleauto = auto.model
        LEFT JOIN nmarciauto  racmarcapref ON racmarcapref.codmarciauto  = rac.codmarca
        LEFT JOIN nmodeleauto racmodelpref ON racmodelpref.codmodeleauto = rac.codmodel
        LEFT JOIN ngest       racgt        ON racgt.codgest = c.codgest
--soferii din NPART
		    LEFT JOIN npart NPSof  ON NPSof.Codpart   = rac.CodSofer
		    LEFT JOIN npart NPSof1 ON NPSof1.Codpart  = rac.CodSofer1
		    LEFT JOIN npart NPSof2 ON NPSof2.Codpart  = rac.CodSofer2

		    LEFT JOIN NAgenda NASof  ON NASof.Codpart   = NPSof.Codpart  and RowNum = 1
        LEFT JOIN NAgenda NASof1 ON NASof1.Codpart  = NPSof1.Codpart and RowNum = 1
        LEFT JOIN NAgenda NASof2 ON NASof2.Codpart  = NPSof2.Codpart and RowNum = 1

		    LEFT JOIN NLocalit NLSof  ON NLSof.CodLocalit   = NASof.CodLocalit
		    LEFT JOIN NLocalit NLSof1 ON NLSof1.CodLocalit  = NASof1.CodLocalit
		    LEFT JOIN NLocalit NLSof2 ON NLSof2.CodLocalit  = NASof2.CodLocalit

		    LEFT JOIN NTari NTSof  ON NLSof.CodTara   = NTSof.CodTara
		    LEFT JOIN NTari NTSof1 ON NLSof1.CodTara  = NTSof1.CodTara
		    LEFT JOIN NTari NTSof2 ON NLSof2.CodTara  = NTSof2.CodTara
        --astea is pt permis, pasaport, soferii din NPart
		    LEFT JOIN nparttr Npr  ON Npr.Codpart   = rac.CodSofer  and RowNum = 1
		    LEFT JOIN nparttr Npr1 ON Npr1.Codpart  = rac.CodSofer1 and RowNum = 1
		    LEFT JOIN nparttr Npr2 ON Npr2.Codpart  = rac.CodSofer2 and RowNum = 1

--Soferii din NPARTR
		    LEFT JOIN nparttr xNpr  ON xNpr.codparttr   = C.Delegat
        LEFT JOIN nparttr xNpr1 ON xNpr1.Codparttr  = rac.coddelegat1
		    LEFT JOIN nparttr xNpr2 ON xNpr2.Codparttr  = rac.coddelegat2

		    LEFT JOIN NLocalit xNLSof  ON xNLSof.CodLocalit   = xNpr.CodLocalit
		    LEFT JOIN NLocalit xNLSof1 ON xNLSof1.CodLocalit  = xNpr1.CodLocalit
		    LEFT JOIN NLocalit xNLSof2 ON xNLSof2.CodLocalit  = xNpr2.CodLocalit

		    LEFT JOIN NTari xNTSof  ON xNLSof.CodTara   = xNLSof.CodTara
		    LEFT JOIN NTari xNTSof1 ON xNLSof1.CodTara  = xNLSof1.CodTara
		    LEFT JOIN NTari xNTSof2 ON xNLSof2.CodTara  = xNLSof2.CodTara


      WHERE C.CodComanda = vCodComanda --and Nvl(Gc1.Ind,0) = aInd and c1.CANTACCEPTAT = 1
        AND ROWNUM = 1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC TIP REZERVARE&apos;,             v_rec.TipRez);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC NUMAR INREGISTRARE&apos;,        v_rec.nrinreg);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC SERIE CAROSERIE&apos;,           v_rec.seriec);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC MODEL preferat&apos;,            v_rec.modpr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC MARCA preferata&apos;,           v_rec.marpr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC MODEL&apos;,                     v_rec.model);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC MARCA&apos;,                     v_rec.marca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC ClasaAuto&apos;,                 v_rec.ClasaAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC ClasaAuto preferata&apos;,       v_rec.ClasaAutoPref);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC GESTIUNEA TRANSFER&apos;,        v_rec.gest_transf);

      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC NUMAR REFERINTA&apos;,           v_rec.nr_ref);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC NUMAR ZBOR&apos;,                v_rec.nr_zbor);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC PARTENER EXTERN&apos;,           v_rec.den_part);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC NUME CARD&apos;,                 v_rec.nume_card);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC EMAIL&apos;,                     v_rec.email);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC TELEFON&apos;,                   v_rec.telefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC SOFER1&apos;,                    v_rec.sofer1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC SOFER2&apos;,                    v_rec.sofer2);

      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC GESTIUNEA PRELUARE&apos;,        v_rec.gest_prel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC LOCALITATE PRELUARE&apos;,       v_rec.localit_prel);

			begin
  			SELECT GetAdresa(sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal) into adrPrel FROM NAGENDA WHERE codgest = Coalesce(v_rec.CodGestSursa,0);
      exception
				when others then 	adrPrel := &apos;-&apos;;
			end;
			begin
  			SELECT GetAdresa(sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal) into adrLivr FROM NAGENDA WHERE codgest = Coalesce(v_rec.CodGestDest,0);
      exception
				when others then 	adrLivr := &apos;-&apos;;
			end;

			pkg_list_Struct.ADAUGA_PARAM(&apos;RAC ADRESA PRELUARE&apos;,           Nvl(v_rec.adresa_prel,  adrPrel));
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC GESTIUNEA LIVRARE&apos;,         v_rec.gest_livr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC LOCALITATE LIVRARE&apos;,        v_rec.localit_livr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC ADRESA LIVRARE&apos;,            Nvl(v_rec.adresa_livr,  adrLivr));

      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC COMBUSTIBIL PLECARE&apos;,       v_rec.combout);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC KM PLECARE&apos;,                v_rec.kmout);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC COMBUSTIBIL INTOARCERE&apos;,    v_rec.combin);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC KM INTOARCERE&apos;,             v_rec.kmin);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC KM URMATOAREA REVIZIE&apos;,     v_rec.kmnextrev);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC SOFER&apos;,                     v_rec.Sofer0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Nr contract&apos;,               v_rec.nrcontract);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Data contract&apos;,             v_rec.Datacontract);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Garantie&apos;,                  v_rec.SUMAGARANTIE);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Data plecare&apos;,              v_rec.DataPlecare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Data sosire&apos;,               v_rec.DataSosire);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Data preluare&apos;,             v_rec.DataPreluare);

      pkg_list_Struct.ADAUGA_PARAM(&apos;EN RAC Departure Date&apos;,         v_rec.DepartureDate);
      pkg_list_Struct.ADAUGA_PARAM(&apos;EN RAC Arrival Date&apos;,           v_rec.ArrivalDate);
      pkg_list_Struct.ADAUGA_PARAM(&apos;EN RAC Retrieval Date&apos;,         v_rec.RetrievalDate);

      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tip document sofer&apos;,   v_rec.TipDocument0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tip document sofer1&apos;,  v_rec.TipDocument1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tip document sofer2&apos;,  v_rec.TipDocument2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie document sofer&apos;, v_rec.SerieDocument0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie document sofer1&apos;,v_rec.SerieDocument1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie document sofer2&apos;,v_rec.SerieDocument2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie permis sofer&apos;,   v_rec.Permis0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie permis sofer1&apos;,  v_rec.Permis1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Serie permis sofer2&apos;,  v_rec.Permis2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Pasaport sofer&apos;,       v_rec.NrPass0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Pasaport sofer1&apos;,      v_rec.NrPass1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Pasaport sofer2&apos;,      v_rec.NrPass2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Oras sofer&apos;,           v_rec.Localit0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Oras sofer1&apos;,          v_rec.Localit1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Oras sofer2&apos;,          v_rec.Localit2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tara sofer&apos;,           v_rec.Tara0);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tara sofer1&apos;,          v_rec.Tara1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Tara sofer2&apos;,          v_rec.Tara2);

      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Ora plecare&apos;,          v_rec.oraplecare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Ora sosire&apos;,           v_rec.orasosire);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Ora preluare&apos;,         v_rec.orapreluare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC Perioada inchiriere&apos;,  v_rec.zileoreinch);
      pkg_list_Struct.ADAUGA_PARAM(&apos;EN RAC Perioada inchiriere&apos;,  v_rec.zileoreengl);
    END LOOP;
  END IF;

  IF vTipDoc = mComenziRAC THEN
    FOR v_rec IN (
      SELECT
        Sum(Coalesce(IncasClient,0)) IncasClient, Sum(Coalesce(IncasSofer,0)) IncasSofer,
        Sum(Coalesce(FactClient,0))  FactClient,  Sum(Coalesce(FactSofer,0))  FactSofer,
        Sum(Coalesce(TotalClient,0)) TotalClient, Sum(Coalesce(TotalSofer,0)) TotalSofer,
        Sum(Coalesce(TotalClientLei,0)) TotalClientLei, Sum(Coalesce(TotalSoferLei,0)) TotalSoferLei
      FROM (
        SELECT
          Case When Cineplateste &lt;&gt;2 then Cast(Sum(Valoare) as decimal(16,2)) else 0 end IncasClient,
          Case When Cineplateste = 2 then Cast(Sum(Valoare) as decimal(16,2)) else 0 end IncasSofer,
          Case When Cineplateste &lt;&gt;2 then Sum(ValDoc) else 0  end FactClient,
          Case When Cineplateste = 2 then Sum(ValDoc) else 0 end FactSofer,
          0 TotalClient, 0 TotalSofer, 0 TotalClientLei, 0 TotalSoferLei
        FROM (
          SELECT CinePlateste, Sum(ValDoc) ValDoc, Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),vCodComanda)/decode(CursDoc,0,1,CursDoc)) Valoare
          FROM (
            SELECT
              E.CodIes, Coalesce(c1.Culansare,1) CinePlateste, Coalesce(E.CursDoc,1) CursDoc,
              Sum(Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0)) ValDoc
            FROM comanda c
              INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
              LEFT  JOIN ieslink  l  ON l.codliniecomanda = c1.codcomanda1 AND Coalesce(l.codies1,0) &lt;&gt; 0
              LEFT  JOIN iesiri1  e1 ON e1.codies1 = l.codies1
              INNER JOIN iesiri   e  ON e.codies = e1.codies and E.TipDoc &lt;&gt; 16
            WHERE C.CodComanda = vCodComanda
            GROUP BY E.CodIes, Coalesce(c1.Culansare,1), Coalesce(E.CursDoc,1)
          )
          GROUP BY CinePlateste
          UNION ALL
          SELECT CinePlateste, Sum(ValDoc) ValDoc, Sum(PKG_LIST_BASE_UTILS.getStinsIes(Coalesce(codies,0),vCodComanda)/decode(CursDoc,0,1,CursDoc)) Valoare
          FROM (
            SELECT
              E.CodIes, Coalesce(c1.Culansare,1) CinePlateste, Coalesce(E.CursDoc,1) CursDoc,
              Sum(Coalesce(e1.PU,0)*Coalesce(e1.Cant,0) + Coalesce(e1.TVA,0)) ValDoc
            FROM comanda c
              INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
              LEFT  JOIN ieslink  l  ON l.codliniecomanda = c1.codcomanda1 AND Coalesce(l.codies1,0) &lt;&gt; 0
              LEFT  JOIN iesiri1  e1 ON e1.codies1 = l.codies1
              INNER JOIN iesiri   e  ON e.codies = e1.codies and E.TipDoc = 16
            WHERE C.CodComanda = vCodComanda
            GROUP BY E.CodIes, Coalesce(c1.Culansare,1), Coalesce(E.CursDoc,1)
          )
          GROUP BY CinePlateste
          UNION ALL
          Select Coalesce(c1.Culansare,1) CinePlateste, Sum(e1.Cant*e1.Pret) ValDoc, Sum(e1.Cant*e1.Pret) Valoare
          FROM Emulare1 e1
            INNER JOIN Emulare  e  on e.CodEmulare = e1.CodEmulare
            INNER JOIN Comanda1 C1 on C1.Codcomanda1 = Coalesce(e1.codcomanda1,0)
            INNER JOIN Comanda  C  on C.Codcomanda = Coalesce(c1.codcomanda,0)
          WHERE C.CodComanda = vCodComanda AND Coalesce(e.CODMONETAR,0) = 0
          GROUP BY Coalesce(c1.Culansare,1)
        )
        GROUP BY CinePlateste
        UNION ALL
        SELECT
          0 IncasClient,  0 IncasSofer,
          0 FactClient,0 FactSofer,
          Cast((r.valClientF + r.valClientcm) AS DECIMAL(16,2)) TotalClient, Cast((r.valsoferF + r.valsofercm) AS DECIMAL(16,2)) TotalSofer,
          case
            when c.moneda &gt; 0 then Cast(((r.valClientF + r.valClientcm)*decode(coalesce(c.curs,1),0,1,coalesce(c.curs,1))) AS DECIMAL(16,2))
            else Cast((r.valClientF + r.valClientcm) AS DECIMAL(16,2))
          end TotalClientLei,
          case
            when c.moneda &gt; 0 then Cast(((r.valsoferF + r.valsofercm)*decode(coalesce(c.curs,1),0,1,coalesce(c.curs,1))) AS DECIMAL(16,2))
            else Cast((r.valsoferF + r.valsofercm) AS DECIMAL(16,2))
          end TotalSoferLei
        FROM Rac_Rez r
             inner join comanda c on c.codcomanda = r.codcomanda
        WHERE r.CodComanda = vCodComanda
      )
    ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Incasare client&apos;,                 v_rec.IncasClient);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Incasare sofer&apos;,                  v_rec.IncasSofer);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Total client&apos;,                    v_rec.TotalClient);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Total sofer&apos;,                     v_rec.TotalSofer);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Total client lei&apos;,                v_rec.TotalClientLei);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Total sofer lei&apos;,                 v_rec.TotalSoferLei);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Fact client&apos;,                     v_rec.FactClient);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Fact sofer&apos;,                      v_rec.FactSofer);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Valoare de incasat sofer&apos;,        v_rec.TotalSofer-v_rec.IncasSofer);
        pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ Valoare de incasat client&apos;,       v_rec.TotalClient-v_rec.IncasClient);
    END LOOP;
  END IF;

  IF vTipDoc IN (mComFurn, mComCli) THEN
    FOR v_rec IN (
      SELECT
        &apos;TERMEN &apos;||To_Char(aux.nr,&apos;fm99&apos;) PName,
        CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(tc.zile, &apos;fm99990&apos;)                                                        END zile,
        CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(         tc.procent,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) END procent,
        CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE tc.tip                                                                             END tip,
        CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(vVal*tc.procent/100,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) END Val,
        CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(vVCT*tc.procent/100,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) END VCT
      FROM (SELECT level Nr, CAST(&apos;...&apos; AS VARCHAR2(50)) p FROM DUAL connect by level &lt;= vNrTerm) aux
        LEFT JOIN (
          SELECT
            Row_Number() OVER (ORDER BY zile, codtermen) idx,
            Count(1) OVER (PARTITION BY codcomanda) nrinreg,
            zile, procent,
            DECODE(tipplata,1,&apos;Numerar&apos;,
                            2,&apos;OrdP&apos;,
                            3,&apos;Cec&apos;,
                            4,&apos;Bilet la Ordin&apos;,
                            5,&apos;Compensare&apos;,
                            6,&apos;Majorari&apos;,
                            7,&apos;CEC/BO girat&apos;,
                            8,&apos;BO avalizat&apos;,
                            9,&apos;Avans&apos;,
                            &apos;...nedefinit...&apos;) tip
          FROM termenecmd
          WHERE codcomanda = vCodComanda
        ) tc ON tc.idx = aux.nr
      ORDER BY aux.nr
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; ZILE&apos;          ,  v_rec.Zile);
      pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; PROCENT&apos;       ,  v_rec.Procent);
      pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; TIP&apos;           ,  v_rec.Tip);
      pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; VALOARE&apos;       ,  v_rec.Val);
      pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; VALOARE CU TVA&apos;,  v_rec.VCT);
    END LOOP;
  END IF;

  IF vTipDoc = mComProdComp AND vID = 146 and gShortVer = 0 then
    FOR v_rec IN (
      SELECT
        vc2_nt_to_vc3200_dist(set(CAST(COLLECT(p.den_part        ORDER BY c1.codcomanda1) AS vc2_nt))) cli,
        vc2_nt_to_vc3200_dist(set(CAST(COLLECT(slivr.obs         ORDER BY c1.codcomanda1) AS vc2_nt))) scli,
        vc2_nt_to_vc3200_dist(set(CAST(COLLECT(llivr.den_localit ORDER BY c1.codcomanda1) AS vc2_nt))) lcli,
        vc2_nt_to_vc3200_dist(set(CAST(COLLECT(o.denumire        ORDER BY c1.codcomanda1) AS vc2_nt))) obj
      FROM COMANDA C
        INNER JOIN COMANDA1 C1    ON C.CODCOMANDA = C1.CODCOMANDA
        INNER JOIN NARTOBJ  O     ON O.CODOBIECT  = C1.CODOBIECT
        LEFT  JOIN COMANDA1 CC1   ON CC1.CODCOMANDA1 = PKG_COMANDA.DINCMDCLI(C1.CODCOMANDA1)
        LEFT  JOIN COMANDA  CC    ON CC1.CODCOMANDA  = CC.CODCOMANDA
        LEFT  JOIN NPART    P     ON CC.PARTENER = P.CODPART
        LEFT  JOIN NAGENDA  SLIVR ON SLIVR.CODAGENDA  = CC.CODLOCATIE AND SLIVR.CODPART = CC.PARTENER
        LEFT  JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
      WHERE C.CODCOMANDA = VCODCOMANDA
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;BENEFICIAR&apos;            , substr(v_rec.cli,1,3000));
      pkg_list_Struct.ADAUGA_PARAM(&apos;BENEFICIAR SEDIU&apos;      , substr(v_rec.scli,1,3000));
      pkg_list_Struct.ADAUGA_PARAM(&apos;BENEFICIAR LOCALITATE&apos; , substr(v_rec.lcli,1,3000));
      pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUS&apos;                , substr(v_rec.obj,1,3000));
      EXIT;
    END LOOP;
  END IF;

  IF vTipDoc = mComProdComp and gShortVer = 0 then
    FOR v_rec IN (
      SELECT
        vc2_nt_to_vc3200_dist(CAST(COLLECT(O.DENUMIRE  ORDER BY MAT.CODCMDPRODMAT) AS vc2_nt)) COMP_DEN,
        vc2_nt_to_vc3200_dist(CAST(COLLECT(O.CODEXTERN ORDER BY MAT.CODCMDPRODMAT) AS vc2_nt)) COMP_CODEXTERN,
        vc2_nt_to_vc3200_dist(CAST(COLLECT(to_char(MAT.CANT) ORDER BY MAT.CODCMDPRODMAT) AS vc2_nt)) COMP_CANT
      FROM COMANDA1 C1
        INNER JOIN CMDPRODMAT MAT ON MAT.CODCOMANDA1 = C1.CODCOMANDA1 AND MAT.TIP = 1
        INNER JOIN NARTOBJ    O   ON O.CODOBIECT     = MAT.CODOBIECT
      WHERE C1.CODCOMANDA = VCODCOMANDA
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPONENT&apos;            , v_rec.COMP_DEN);
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPONENT COD EXTERN&apos; , v_rec.COMP_CODEXTERN);
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPONENT CANTITATE&apos;  , v_rec.COMP_CANT);
      EXIT;
    END LOOP;
  END IF;

  if (vTipDoc = mComFurn and pkg_categconst.GetValConstanta(&apos;AprobariCmdFurn&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos;) or
     (vTipDoc = mComCli and pkg_categconst.GetValConstanta(&apos;AprobariCmdCl&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos;) or
     (vTipDoc = mComCatreSub and pkg_categconst.GetValConstanta(&apos;AprobariCmdSub&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos;) or
     (vTipDoc = mComGest and pkg_categconst.GetValConstanta(&apos;AprobariCmdGest&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos;) then
    for v_rec in (
                  select coalesce(n.obs,&apos;Nivel &apos;||to_char(p.nivel))||&apos;: &apos;||
                         coalesce(d.obs,case when p.stare = 0 then &apos;Incerta&apos; when p.stare = 1 then &apos;Aprobata&apos; when p.stare = 2 then &apos;Respinsa&apos; when p.stare = 3 then &apos;Reanaliza&apos; end)||
                         &apos; - &apos;||pr.nume||&apos; &apos;||pr.prenume apr,
                         coalesce(n.obs,&apos;Nivel &apos;||to_char(p.nivel)) apr_den
                  from cmdaprobari p
                       inner join npers   pr on pr.logonname = p.userid
                       left  join diverse d  on p.stare = d.cod and d.tip = 12
                       left  join diverse n  on n.cod = p.nivel and n.tip = 11
                  where p.coddoc = vCodComanda and p.TipDoc = vTipDoc
                 ) loop
      pkg_list_Struct.ADAUGA_PARAM(&apos;APROBARE: &apos;||v_rec.apr_den  , v_rec.apr);
    end loop;
  end if;

  IF vTabla IS NOT NULL THEN
    pkg_list_Struct.ADAUGA_PARAM_EXT(vTabla, &apos;CODCOMANDA&apos;, vCodComanda);
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
aPart      NUMBER;
aClasa     NUMBER;  
BEGIN
--pkg_globals.setdebugmode(TRUE);
  PKG_LIST_STRUCT.GOLESTE_PARAM;
  if vID &lt;&gt; 463 then
    gSuplCols := &apos;comanda c, comanda1 c1, npart np, nartobj nao, nartobj1 nao1, nart na, num1 num1, npart prod, nclasea ca, nclaseas cs, nartamb aa, grechiv gre, comanda csursa, &apos;||
                 &apos;nartobjtrad ntrad, nartcli ac, oferta1 o1, nagenda nag&apos;;
    IF    vID IN (105,122)  THEN
      gSuplCols := gSuplCols||&apos;, contract contr, contract1 contr1&apos;;
    ELSIF vID = 146 AND gShortVer = 1 THEN
      gSuplCols := &apos;comanda c, comanda1 c1, npart np, nartobj nao, cmdprodmat mat, nartobj objmat, nart artmat&apos;;
    ELSIF vID = 146 THEN
      gSuplCols := gSuplCols||&apos;, cmdprodmat mat, nartobj objmat, nart artmat, num ummat, nclasea compcls, ioart ioaimp, ngest gestimp, prodmat pmat, prodcomp pc&apos;;
    ELSIF vID = 314 THEN
      gSuplCols := gSuplCols||&apos;, utilaje u&apos;;
    ELSIF vID = 383 THEN
      gSuplCols := &apos;comanda c, comanda1 c1, npart np, nartobj nao, cmdprodman man, nartobj prod, nart artprod&apos;;
    ELSIF vID = 407 THEN
      gSuplCols := &apos;comanda c, comanda1 c1, npart np, nartobj nao, cmdprodman man, nartobj prod, nart artprod&apos;;
    END IF;
    if vID = 267 then
      gSuplCols := gSuplCols||&apos;, comanda cc, comanda1 c1c&apos;;
    end if;
  ELSE
    gSuplCols := &apos;comanda c, comanda1 c1, PRODCOMP PC, cmdprodman man, cmdprodmat mat, prodsdv sdv&apos;;
  end if;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla,            &apos;CV&apos;,    &apos;CV.CODCOMANDA = C1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla1,           &apos;CV1&apos;,   &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,      &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,      &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,      &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,       &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCARSUPART&apos;,      &apos;CSA&apos;,   &apos;CSA.CODCARSUPART = NAO.CODCARACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_NARTATR_LST&apos;, &apos;TAA&apos;,   &apos;TAA.CODARTICOL = NA.CODARTICOL&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF InStr(Upper(gSuplJoins),&apos;TMP_NARTATR_LST&apos;) &gt; 0 THEN
    pkg_globals.SetSeparator(&apos;;&apos;);
    PKG_LIST_BASE_UTILS.UMPLE_TMP_NARTATR_LST;
  END IF;

  PKG_GLOBALS.SetSeparator(&apos;, &apos;);

  if vID in (267,122,122,105,384) then
    BEGIN
      SELECT i.partener, coalesce(p.codclasa,0) INTO aPart, aClasa
      FROM comanda i
           left join npart p on p.codpart = i.partener 
      WHERE i.codcomanda = vCodComanda;
    EXCEPTION WHEN OTHERS THEN aPart := 0; aClasa := 0;
    END;
    DELETE FROM tmp_nartcli;
    INSERT INTO tmp_nartcli(
      codartcli,
      codobiect,
      codpart,
      denumire,
      codextern,
      umsec,
      codmoneda,
      pret,
      tipcodafisat,
      umcorelat,
      implicit,
      codlaclient,
      codclasep,
      codgama,
      codintern,
      obs,
      obs2,
      umsecimpdoc,
      duratatr,
      zilestoc,
      gln,
      idspecific
      )
      select
      codartcli,
      codobiect,
      codpart,
      denumire,
      codextern,
      umsec,
      codmoneda,
      pret,
      tipcodafisat,
      umcorelat,
      implicit,
      codlaclient,
      codclasep,
      codgama,
      codintern,
      obs,
      obs2,
      umsecimpdoc,
      duratatr,
      zilestoc,
      gln,
      idspecific
      from nartcli
    where codpart = aPart;
    if aClasa &gt; 0 then
      INSERT INTO tmp_nartcli(
        codartcli,
        codobiect,
        codpart,
        denumire,
        codextern,
        umsec,
        codmoneda,
        pret,
        tipcodafisat,
        umcorelat,
        implicit,
        codlaclient,
        codclasep,
        codgama,
        codintern,
        obs,
        obs2,
        umsecimpdoc,
        duratatr,
        zilestoc,
        gln,
        idspecific
        )
        select
        codartcli,
        codobiect,
        codpart,
        denumire,
        codextern,
        umsec,
        codmoneda,
        pret,
        tipcodafisat,
        umcorelat,
        implicit,
        codlaclient,
        codclasep,
        codgama,
        codintern,
        obs,
        obs2,
        umsecimpdoc,
        duratatr,
        zilestoc,
        gln,
        idspecific
        from nartcli c
      where c.codclasep = aClasa and not exists (select t.codobiect from tmp_nartcli t where t.codobiect = c.codobiect);
    end if;
  end if;  

  vLISTID  := aLISTID;
  vLISTVER := aLISTVER;
  CASE vID
    WHEN 146 THEN ComInterne   (tmpName);      -- Document Comenzi interne :1 prod comp
    WHEN 314 THEN ComMentenanta(tmpName);      -- Comanda mentenanta
    WHEN 383 THEN ComManopera  (tmpName);
    WHEN 384 THEN ComServAuto  (tmpName, vID);
    WHEN 407 THEN ComServAuto  (tmpName, vID); -- Comanda Rent A Car
    WHEN 463 THEN ComMatMan    (tmpName);
    ELSE          ComPart      (tmpName);
  END CASE;

  pkg_list_base_comdoc.add_list_params;
  COMMIT;
END;

end PKG_LIST_BASE_COMDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54A07BF5D0DFC78A14D10E20CBB1A927FACDAE99</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_comenzi IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(1000);
  sSelect       VARCHAR2(9000);
  sFiltru       VARCHAR2(1000);
  sSMAux        VARCHAR2(500);
  sSMFiltruGest VARCHAR2(500);
BEGIN

  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj nobj, nart art, num1 num1, num us, nmonede mon, npers ag, nparttr del, &apos;||
    &apos;nagenda sedl, nlocalit locl, njudet judl, nzone zonal, ntari taral, nclasea cla, nclaseas cs, nclasep clp, &apos;||
    &apos;traseulivr t, npart prod, iesiri iesavans, oferta1 o1, npart np, ngest ng, nsubunit ns, ngest gact&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,  &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCARSUPART&apos;, &apos;CSA&apos;,   &apos;CSA.CODCARSUPART = NOBJ.CODCARACT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;
    AND c.tipdoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;) &apos;;

  sFiltru := sFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)&apos; )||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;C&apos;);

  IF PKG_LIST_SELCOMENZI.DupaData THEN
    sFiltru := sFiltru||&apos;
    AND c.datadoc &apos;|| PKG_LIST_SELCOMENZI.Perioada;
  ELSE
    sFiltru := sFiltru||&apos;
    AND (c.luna + c.an * 12) &apos;|| PKG_LIST_SELCOMENZI.Perioada;
  END IF;

  sSMAux := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  IF sSMAux IS NOT NULL THEN
    sSMAux := &apos; INNER JOIN nir n ON n.codnir = ns.codnir INNER JOIN ngest g ON g.codgest = n.gest &apos;||sSMAux;
  END IF;

  sSMFiltruGest := &apos;&apos;;
  if not PKG_LIST_SELCOMENZI.AllGest then
    sSMFiltruGest := &apos; and exists (select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODGEST&apos;&apos; and valoare = g.codgest)&apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPnAME||&apos;(
    NAV_CodDoc,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCCOM,DEN_PART,
    DENUMIRE,DEN_UM1,CANTCOMANDAT,CANTACCEPTAT,RESTACCEPTAT,
    PU,VALLINIE,TERMEN,LINIE,
    MONEDA,OBSDOC,OBSLINIE,STOCMIN,STOCMED,STOCMAX,
    STOCMOM,
    TRASEU, DELEGAT, MIJLTR, NRTRANSP, UMSPEC, CANTUMSPEC,
    CANTREZ,
    LIVR_DEN, LIVR_ADR, LIVR_LOC, LIVR_JUD, LIVR_ZONA,
    DENUSER,
    STARE,
    NRCOLETE,
    VALTREZ,
    SUBUNITATEA,
    X_Judet, X_CodClasaP, X_CodGest, X_Codsubunit&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
	SELECT
    c.codcomanda, c.tipdoc,c.prefixdoc,c.nrdoc,c.datadoc, c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc doccom,
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part),
    nobj.denumire, num1.den_um1, c1.cantcomandat/num1.paritate, c1.cantacceptat/num1.paritate, c1.restacceptat/num1.paritate,
    c1.pu*num1.paritate, c1.pu*c1.cantacceptat, c1.termen, c1.Indexlocal,
    nvl(mon.simbol ,&apos;&apos;-&apos;&apos;), c.OBS, c1.OBS, nobjs.STOCMIN, nobjs.STOCMED, nobjs.STOCMAX,
    (SELECT SUM(ns.rest) FROM nirstoc ns&apos;||sSMAux||&apos; WHERE ns.codobiect = c1.codobiect AND ns.rest &lt;&gt; 0&apos;||sSMFiltruGest||&apos;)/num1.Paritate stocmom,
    t.dentraseu, del.delegat, del.mijltransp, del.nrtransp, us.den_um, c1.cantum1,
    (SELECT NVL(SUM(r.rest),0) FROM rezervats r WHERE r.codcomanda1 = c1.codcomanda1)/num1.Paritate cantrez,
    sedl.obs, getadresa(sedl.sector, sedl.strada, sedl.nr1, sedl.nr2, sedl.bloc, sedl.scara, sedl.etaj, sedl.apart, sedl.codpostal),
    locl.den_localit, judl.den_judet, zonal.den_zona,
    winmadmin.pkg_userfirme.getUserName(c.userid),
    CASE
      WHEN SUM(NVL(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN SUM(NVL(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) = SUM(NVL(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN SUM(CASE WHEN NVL(c1.cantacceptat, 0) &gt; 0 AND NVL(c1.restacceptat, 0) &gt; 0 THEN 1 ELSE 0 END) over (PARTITION BY c.codcomanda) = 0
       AND SUM(NVL(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &lt;&gt; 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN SUM(NVL(c1.cantacceptat,0)) over (PARTITION BY c.codcomanda) &gt; SUM(NVL(c1.restacceptat,0)) over (PARTITION BY c.codcomanda) THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
      ELSE NULL
    END,
    (SELECT COUNT(1) FROM nartobjcolet oc WHERE oc.codobiect = c1.codobiect),
    (SELECT SUM(valdoc) FROM trezor1 x WHERE x.codcomanda = c.codcomanda) VALTREZ,
    s.den_subunit, judl.Simbauto, clp.codclasep, gact.codgest, s.codsubunit&apos;||
    gUserAlias||&apos;
  FROM comanda c
    LEFT JOIN comanda1       c1       ON c.codcomanda     = c1.codcomanda
		LEFT JOIN nartobj        nobj     ON nobj.codobiect   = c1.codobiect
    LEFT JOIN nart           art      ON nobj.codarticol  = art.codarticol
    LEFT JOIN nartobjsubunit nobjs    ON nobjs.codobiect  = nobj.codobiect 
                                         and (nobjs.codgest is null or nobjs.codgest = 0)
                                         AND nobjs.subunitate = DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)
		LEFT JOIN num1                    ON num1.codum1      = c1.umsec
    LEFT JOIN num            us       ON us.codum         = art.um1
		LEFT JOIN nmonede        mon      ON mon.codmoneda    = c.moneda
    LEFT JOIN npers          ag       on c.agent          = ag.codpers
    LEFT JOIN nagenda        sedl     ON sedl.codagenda   = c.codlocatie
    LEFT JOIN nlocalit       locl     ON locl.codlocalit  = sedl.codlocalit
    LEFT JOIN njudet         judl     ON judl.codjudet    = locl.codjudet
    LEFT JOIN nzone          zonal    ON zonal.codzona    = locl.codzona
    LEFT JOIN ntari          taral    ON taral.codtara    = locl.codtara
    LEFT JOIN nclasea        cla      on art.clasa        = cla.codclasea
    LEFT JOIN nclaseas       cs       on art.clasastatist = cs.codclaseas
    LEFT JOIN traseulivr     t        on t.codtraseulivr  = sedl.codtraseu
    LEFT JOIN npart          prod     ON prod.codpart     = nobj.codproducator
    LEFT JOIN nparttr        del      ON c.delegat        = del.codparttr
    LEFT JOIN npart          np       ON np.codpart       = c.partener
    LEFT JOIN ngest          ng       ON ng.codgest       = c.codgest
    LEFT JOIN nsubunit       ns       ON ns.codsubunit    = c.subunitatea
    LEFT JOIN nclasep        clp      on clp.codclasep    = np.codclasa
    LEFT JOIN iesiri         iesavans ON iesavans.codies  = c.codiesavans
    LEFT JOIN nsubunit       s        On s.codsubunit     = c.subunitatea
    LEFT JOIN oferta1        o1       ON o1.codoferta1    = COALESCE(c1.codoferta1,CASE WHEN c1.tipsursa IN (50,51) THEN c1.codsursa ELSE NULL END)
    LEFT JOIN ngest          gact     On gact.codgest     = c1.gestact&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 &apos;||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_COMENZI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMENZIINCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36CDCB9638C3CD2184C4E5AD8835F9FA8897166E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMENZIINCURS IS

  g_lunaFin   NUMBER(2);
  g_An        NUMBER(4);

  CT_LISTID_COMFURN    CONSTANT NUMBER := 167;
  CT_LISTID_COMCL      CONSTANT NUMBER := 168;
  CT_LISTID_COMGEST    CONSTANT NUMBER := 126;
  CT_LISTID_COMSUB     CONSTANT NUMBER := 127;
  CT_LISTID_COMSA      CONSTANT NUMBER := 402;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(5000);
  sSelect   VARCHAR2(15000);
  sJoinAux  VARCHAR2(5000);
  sTipDoc   VARCHAR2(200);
  sTipStorn VARCHAR2(20);
  sXFrom    VARCHAR2(5000);
  sAuxIns   VARCHAR2(5000);
  sAuxSel   VARCHAR2(5000);
  sDenPart  VARCHAR2(100);
  vTabla    VARCHAR2(50);
  vTabla1   VARCHAR2(50);
  sSM       VARCHAR2(5000);
  sSMAux    VARCHAR2(5000);
  sRest     VARCHAR2(100);
  bSMSub    BOOLEAN;
  bSMGest   BOOLEAN;
BEGIN
  DELETE FROM TMP_CMD_TMP; 
  if PKG_LIST_SELFISAMAG.inclArtStoc0 and aLISTID = 168 then
    sRest := &apos;,c1.restacceptat&apos;;
  else
    sRest := &apos;,(c1.cantacceptat - Coalesce(ilink.valoare,0))/u1.Paritate&apos;;
  end if;  
  PRC_AL_CHECK(&apos;IOART1&apos;);
  pkg_globals.SetSeparator(&apos;;&apos;);
  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj nobj, nart art, num1, nmonede mon, npers ag, nclasea cla, nclasep clp, traseulivr t, npart prod, ncarsupart cs,&apos;||
    &apos;nparttr d, nagenda slivr, nlocalit loclivr, njudet judlivr, nzone zonalivr, ntari taralivr, npart p&apos;;

  IF aLISTID = CT_LISTID_COMFURN THEN
    sDenPart  := &apos;np.den_part&apos;;
    sTipDoc   := &apos;8&apos;;
    vTabla    := &apos;COMANDF&apos;;
    vTabla1   := &apos;COMANDF1&apos;;
    sXFrom    := &apos;intrlink il
      INNER JOIN intrari1 i1 ON i1.codintr1 = il.codintr1
      INNER JOIN intrari i ON i.codintr = i1.codintr&apos;;
    sJoinAux  := &apos;
    INNER JOIN npart np ON np.codpart = c.partener
    LEFT JOIN TMP_LST_CURS cfc ON cfc.codmoneda = c.moneda
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(CASE WHEN ca.stare=1 THEN 1 ELSE 0 end) NRAprob,
        Max(CASE ca.nivel WHEN 1 THEN ca.stare END) Niv1Stare, Max(CASE ca.nivel WHEN 1 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv1User,
        Max(CASE ca.nivel WHEN 2 THEN ca.stare END) Niv2Stare, Max(CASE ca.nivel WHEN 2 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv2User,
        Max(CASE ca.nivel WHEN 3 THEN ca.stare END) Niv3Stare, Max(CASE ca.nivel WHEN 3 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv3User,
        Max(CASE ca.nivel WHEN 4 THEN ca.stare END) Niv4Stare, Max(CASE ca.nivel WHEN 4 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv4User,
        Max(CASE ca.nivel WHEN 5 THEN ca.stare END) Niv5Stare, Max(CASE ca.nivel WHEN 5 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv5User
      FROM (
        SELECT DISTINCT c1.codcomanda
        FROM tmp_manevra_liste tmpc inner join comanda1 c1 ON c1.codcomanda1 = tmpc.valoare
        WHERE tmpc.filtru = &apos;&apos;CODCOMANDA1&apos;&apos; and tmpc.filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
      ) x
        INNER JOIN comanda c ON x.codcomanda = c.codcomanda
        INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda&apos;;
    sAuxIns   := &apos;,
    CATUSER, FACTURABIL,
    NIV1Stare, NIV1User, NIV2Stare, NIV2User, NIV3Stare, NIV3User, NIV4Stare, NIV4User, NIV5Stare, NIV5User,
    CF_AS, CF_CURS, CF_VALOARE&apos;;
    sAuxSel   := &apos;,
    WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(c.USerId), CASE WHEN Coalesce(c.nrmaxaprobari,0) &lt;= Coalesce(Aprob.NRAprob,0) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    CASE Aprob.Niv1Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv1User,
    CASE Aprob.Niv2Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv2User,
    CASE Aprob.Niv3Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv3User,
    CASE Aprob.Niv4Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv4User,
    CASE Aprob.Niv5Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv5User,
    TO_CHAR( Coalesce(C1.Termen, C.DataDoc)+Coalesce(np.scadentac,0),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS,
    Coalesce(cfc.valoare,1) CF_CURS, c1.pu*c1.restacceptat*Coalesce(cfc.valoare,1) CF_VALOARE&apos;;
    sTipStorn := 66;
  ELSIF aLISTID = CT_LISTID_COMCL THEN
    gSuplCols := gSuplCols||&apos;,ngest gestlivr&apos;;
    sDenPart  := &apos;np.den_part&apos;;
    if PKG_LIST_SELFISAMAG.areSerii then
      sTipDoc   := &apos;18 and Coalesce(c.displivrare,0) &lt;&gt; 1&apos;;
    else
      sTipDoc   := &apos;18&apos;;
    end if;
    vTabla    := &apos;COMANDC&apos;;
    vTabla1   := &apos;COMANDC1&apos;;
    sAuxIns   := &apos;,
    PARPALET,PARCUTIE,ADDIM,PROCDISC,
    DOCAVNR,DOCAVDATA,DOCAVVAL,
    DOCAV1DOC, DOCAV1VAL,
    DOCAV2DOC, DOCAV2VAL,
    DOCAV3DOC, DOCAV3VAL,
    DOCAV4DOC, DOCAV4VAL,
    DOCAV5DOC, DOCAV5VAL,
    REST_CC, REST_CF,
    NIV1Stare, NIV1User, NIV2Stare, NIV2User, NIV3Stare, NIV3User, NIV4Stare, NIV4User, NIV5Stare, NIV5User,
    CF_AS, CF_CURS, CF_VALOARE, ACC_DL, REST_DL, FACT_CMD, FACT_DL&apos;;
    sAuxSel   := &apos;,
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;PALET&apos;&apos;, NOBJ.CODOBIECT),
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;CUTIE&apos;&apos;, NOBJ.CODOBIECT),
    Coalesce(c1.addim,0), Coalesce(c1.procdisc,0),
    PKG_LIST_BASE_COMANDA.GetDocAv_Nr(c.codcomanda),PKG_LIST_BASE_COMANDA.GetDocAv_Data(c.codcomanda),PKG_LIST_BASE_COMANDA.GetDocAv_Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv1Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv1Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv2Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv2Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv3Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv3Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv4Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv4Val(c.codcomanda),
    PKG_LIST_BASE_COMANDA.GetDocAv5Doc(c.codcomanda), PKG_LIST_BASE_COMANDA.GetDocAv5Val(c.codcomanda),
    Coalesce(RSA.RCC,0) - C1.RESTACCEPTAT,
    (SELECT sum(cf1.restacceptat - Coalesce(storno.cant,0))
     FROM (
         SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1F&apos;&apos;
       ) tmp
       INNER JOIN comanda1 cf1 ON tmp.valoare = cF1.codcomanda1
       left join (
         SELECT SUM(LL.CANT) CANT, LL.CODLINIECOMANDA CODCOMANDA1
         FROM CMDLIVRLINK LL
           INNER JOIN (
             SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1F&apos;&apos;
           )                   TMP ON LL.CODLINIECOMANDA = TMP.VALOARE
           INNER JOIN COMANDA1 S1  ON LL.CODCOMANDA1     = S1.CODCOMANDA1
           INNER JOIN COMANDA  S   ON S1.CODCOMANDA      = S.CODCOMANDA
         WHERE S.OPERAT = 1 AND Coalesce(S.ANULAT,0) = 0 AND S.TIPDOC = 66
         GROUP BY LL.CODLINIECOMANDA
       ) storno ON storno.codcomanda1 = cf1.codcomanda1
     where cf1.codobiect = c1.codobiect
    ),
    CASE Aprob.Niv1Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv1User,
    CASE Aprob.Niv2Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv2User,
    CASE Aprob.Niv3Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv3User,
    CASE Aprob.Niv4Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv4User,
    CASE Aprob.Niv5Stare WHEN 0 THEN &apos;&apos;Incert&apos;&apos; WHEN 1 THEN &apos;&apos;Aprobat&apos;&apos; WHEN 2 THEN &apos;&apos;Respins&apos;&apos; END, Niv5User,
    TO_CHAR( Coalesce(C1.Termen, C.DataDoc)+Coalesce(np.scadentav,0),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS,
    Coalesce(cfc.valoare,1) CF_CURS, c1.pu*c1.restacceptat*Coalesce(cfc.valoare,1) CF_VALOARE,
    COALESCE(DL_C.CANTA,0), COALESCE(DL_C.RESTA,0), COALESCE(FACT_C.CANTA,0), COALESCE(DL_C.CANTA,0) - COALESCE(DL_C.RESTA,0) &apos;;
    sXFrom    := &apos;ieslink il
      INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
      INNER JOIN iesiri i ON i1.codies = i.codies&apos;;
    sJoinAux  := &apos;
    INNER JOIN npart       np       ON np.codpart        = c.partener
    LEFT JOIN TMP_CMD_TMP  FACT_C   ON FACT_C.CODOBIECT  = C1.CODCOMANDA1 AND FACT_C.TIP = &apos;&apos;FACT&apos;&apos;
    LEFT JOIN TMP_CMD_TMP  DL_C     ON DL_C.CODOBIECT    = C1.CODCOMANDA1 AND DL_C.TIP = &apos;&apos;DL&apos;&apos;
    LEFT JOIN TMP_LST_CURS cfc      ON cfc.codmoneda     = c.moneda
    LEFT JOIN NGEST        GESTLIVR ON Coalesce(C1.GESTACT,0) = GESTLIVR.CODGEST
    LEFT JOIN (
      SELECT c1.codobiect, Sum(CASE WHEN c.tipdoc=8 THEN c1.restacceptat ELSE 0 END) rcf, Sum(CASE WHEN c.tipdoc=18 THEN c1.restacceptat ELSE 0 END) rcc
      FROM (
          SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1&apos;&apos; AND filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
        ) tmpc
        INNER JOIN comanda1 c1 ON c1.codcomanda1 = tmpc.valoare
        INNER JOIN comanda  c  ON c.codcomanda   = c1.codcomanda
      GROUP BY c1.codobiect
    ) RSA ON rsa.codobiect = c1.codobiect
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(CASE WHEN ca.stare = 1 THEN 1 ELSE 0 END ) NRAprob,
        Max(CASE ca.nivel WHEN 1 THEN ca.stare END) Niv1Stare, Max(CASE ca.nivel WHEN 1 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv1User,
        Max(CASE ca.nivel WHEN 2 THEN ca.stare END) Niv2Stare, Max(CASE ca.nivel WHEN 2 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv2User,
        Max(CASE ca.nivel WHEN 3 THEN ca.stare END) Niv3Stare, Max(CASE ca.nivel WHEN 3 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv3User,
        Max(CASE ca.nivel WHEN 4 THEN ca.stare END) Niv4Stare, Max(CASE ca.nivel WHEN 4 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv4User,
        Max(CASE ca.nivel WHEN 5 THEN ca.stare END) Niv5Stare, Max(CASE ca.nivel WHEN 5 THEN WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId) END) Niv5User
      FROM (
        SELECT DISTINCT c1.codcomanda
        FROM tmp_manevra_liste tmpc inner join comanda1 c1 ON c1.codcomanda1 = tmpc.valoare
        WHERE tmpc.filtru = &apos;&apos;CODCOMANDA1&apos;&apos; and tmpc.filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
      ) x
        INNER JOIN comanda     c  ON x.codcomanda = c.codcomanda
        INNER JOIN cmdaprobari ca ON ca.coddoc    = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda&apos;;
    sTipStorn := 65;
  ELSIF aLISTID = CT_LISTID_COMGEST THEN
    sDenPart  := &apos;np.den_gest&apos;;
    sTipDoc   := &apos;43&apos;;
    vTabla    := &apos;COMANDI&apos;;
    vTabla1   := &apos;COMANDI1&apos;;
    sXFrom    := &apos;ieslink il
      INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
      INNER JOIN iesiri  i  ON i1.codies  = i.codies&apos;;
    sJoinAux  := &apos;
    INNER JOIN ngest np ON np.codgest = c.codgest&apos;;
    sTipStorn := 0;
  ELSIF aLISTID = CT_LISTID_COMSUB  THEN
    sDenPart  := &apos;np.den_subunit&apos;;
    sTipDoc   := &apos;44&apos;;
    vTabla    := &apos;COMANDI&apos;;
    vTabla1   := &apos;COMANDI1&apos;;
    sXFrom    := &apos;ieslink il
      INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
      INNER JOIN iesiri  i  ON i1.codies  = i.codies&apos;;
    sJoinAux  := &apos;
    INNER JOIN nsubunit np ON np.codsubunit = c.subunitsursa&apos;;
    sTipStorn := 88;
  ELSIF aLISTID = CT_LISTID_COMSA   THEN
    gSuplCols := gSuplCols||&apos;, nparcaut pa&apos;;
    sDenPart  := &apos;p.den_part&apos;;
    sTipDoc   := &apos;92&apos;;
    vTabla    := &apos;COMANDSA&apos;;
    vTabla1   := &apos;COMANDSA1&apos;;
    sJoinAux  := &apos;
    LEFT JOIN nparccom csa ON csa.codcomanda = c.codcomanda
    LEFT JOIN nparcaut pa  ON pa.codnparcaut = csa.codnparcaut&apos;;
    sAuxIns   := &apos;,
    AUTONR,AUTOSERC,KMBORD,
    TIPSA,
    RETURNAT,
    TIPLINIESA,
    EXTERN&apos;;
    sAuxSel   := &apos;,
    pa.nrinreg, pa.seriec, csa.kmbord,
    CASE csa.tipcomsa WHEN 1 THEN &apos;&apos;Asigurare&apos;&apos; WHEN 2 THEN &apos;&apos;Garantie&apos;&apos; WHEN 3 THEN &apos;&apos;Client&apos;&apos; WHEN 4 THEN &apos;&apos;Interne&apos;&apos; END,
    c1.cantreturnat/u1.Paritate,
    CASE WHEN c1.tipliniesa = 1 THEN &apos;&apos;2.Constatata&apos;&apos; ELSE &apos;&apos;1.Cerere Client&apos;&apos; END,
    CASE WHEN c1.culansare = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END&apos;;
    sXFrom    := &apos;ieslink il
      INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
      INNER JOIN iesiri  i  ON i1.codies  = i.codies&apos;;
    sTipStorn := 0;
  END IF;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla,       &apos;CV&apos;,    &apos;CV.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla1,      &apos;CV1&apos;,   &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTREEXT&apos;,  &apos;CCEXT&apos;, &apos;CCEXT.CODCENTRU = Coalesce(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  g_lunaFin   := pkg_globals.LunaLucru;
  g_an        := pkg_globals.AnLucru;

  IF g_an IS NULL OR g_lunaFin IS NULL THEN --job
    SELECT LUNAMAXIMA, ANMAXIM INTO g_lunaFin, g_an FROM FIRMALUNI;
  END IF;

  sSM :=&apos;
    SELECT ns.codobiect, SUM(ns.rest) Stoc
    FROM nirstoc ns&apos;;

  sSMAux := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  bSMSub := NOT sSMAux IS NULL;
  bSMGest:= NOT pkg_list_selfisamag.isAllGest;

  IF bSMSub THEN
    sSM := sSM||  &apos;
      INNER JOIN nir     n    ON n.codnir      = ns.codnir
      INNER JOIN ngest   g    ON g.codgest     = n.gest
      LEFT  JOIN intrari intr ON intr.codintr  = n.codintr   AND intr.tipdoc = n.tipnir
      LEFT  JOIN transf  t    ON t.codtransf   = n.codtransf AND t.tipdoc    = n.tipnir
      LEFT  JOIN iesiri  ies  ON ies.codies    = n.codies    AND ies.tipdoc  = n.tipnir
      LEFT  JOIN ioart1  ioa1 ON ioa1.codioart = ns.codioart AND COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) BETWEEN ioa1.alstart AND ioa1.alstop
      WHERE ns.rest &lt;&gt; 0 AND ioa1.mg &lt;&gt; 5 &apos;||sSMAux;
  ELSIF bSMGest THEN
    sSM := sSM||  &apos;
      INNER JOIN nir     n    ON n.codnir      = ns.codnir
      INNER JOIN ngest   g    ON g.codgest     = n.gest
      LEFT  JOIN intrari intr ON intr.codintr  = n.codintr AND intr.tipdoc = n.tipnir
      LEFT  JOIN transf  t    ON t.codtransf   = n.codtransf AND t.tipdoc = n.tipnir
      LEFT  JOIN iesiri  ies  ON ies.codies    = n.codies AND ies.tipdoc = n.tipnir
      LEFT  JOIN ioart1  ioa1 ON ioa1.codioart = ns.codioart AND COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) BETWEEN ioa1.alstart AND ioa1.alstop
      WHERE ns.rest &lt;&gt; 0 AND ioa1.mg &lt;&gt; 5 &apos;||sSMAux;
  ELSE
    sSM := sSM||  &apos;
    WHERE ns.rest &lt;&gt; 0 &apos;||sSMAux;
  END IF;
  IF bSMGest then
    sSM := sSM||&apos;
      AND g.codgest IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selfisamag.isAllTipCont THEN
    sSM := sSM||&apos;
      AND ns.codioart IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;)&apos;;
  END IF;
  sSM := sSM||  &apos;
    GROUP BY ns.codobiect&apos;;

  DELETE FROM tmp_manevra_liste WHERE FILTRU NOT IN (&apos;CODGEST&apos;, &apos;CODIOART&apos;);

  sInsert :=
  &apos;INSERT INTO tmp_manevra_liste(filtru, valoare, filtru1)
  SELECT CODCOMANDA1, sum(cant), &apos;&apos;ILINK&apos;&apos;
  FROM (
    SELECT il.codliniecomanda codcomanda1, il.cant
    FROM &apos;||sXFrom||&apos;
    WHERE i.operat = 1 AND i.anulat = 0
      AND i.luna+i.an *12 &lt;= &apos;||to_char(g_an*12+g_lunaFin,&apos;fm99990&apos;)||&apos;
    UNION ALL
    SELECT cl.codliniecomanda codcomanda1, cant
    FROM comanda c
      INNER JOIN comanda1    c1 ON c1.codcomanda  = c.codcomanda
      INNER JOIN cmdlivrlink cl ON cl.codcomanda1 = c1.codcomanda1
    WHERE c.tipdoc = &apos;||sTipDoc||&apos;
      AND (c.an * 12 + c.luna) &lt;= &apos;||to_char(g_an*12+g_lunaFin,&apos;fm99990&apos;)||&apos;
      AND c.displivrare in (1,4)
    UNION ALL
    SELECT cl.codliniecomanda codcomanda1, cant
    FROM comanda c
      INNER JOIN comanda1    c1 ON c1.codcomanda  = c.codcomanda
      INNER JOIN cmdlivrlink cl ON cl.codcomanda1 = c1.codcomanda1
    WHERE c.tipdoc = &apos;||sTipStorn||&apos;
      AND (c.an * 12 + c.luna) &lt;= &apos;||to_char(g_an*12+g_lunaFin,&apos;fm99990&apos;)||&apos;
  ) subs
  GROUP BY codcomanda1 &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert :=
  &apos;INSERT INTO tmp_manevra_liste(filtru, valoare, filtru1)
  SELECT &apos;&apos;CODCOMANDA1&apos;&apos;, c1.codcomanda1, &apos;&apos;CODCOMANDA1&apos;&apos;
  FROM comanda c
    INNER JOIN comanda1          c1    ON c.codcomanda = c1.codcomanda
    LEFT  JOIN (
      SELECT TO_NUMBER(valoare) valoare, To_Number(filtru) filtru FROM tmp_manevra_liste WHERE filtru1 = &apos;&apos;ILINK&apos;&apos;
    ) ilink ON ilink.filtru = c1.codcomanda1
  WHERE c.tipdoc = &apos;||sTipDoc||&apos;
    AND (c.an * 12 + c.luna) &lt;= &apos;||to_char(g_an*12+g_lunaFin,&apos;fm99990&apos;)||&apos;
    AND c.anulat = 0 AND c.operat = 1 AND Coalesce(C.INCHISA, 0) = 0
    AND c1.cantacceptat - Coalesce(ilink.valoare,0) &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert :=
  &apos;INSERT INTO tmp_manevra_liste(filtru, valoare)
  SELECT &apos;&apos;CODCOMANDA1F&apos;&apos;, c1.codcomanda1
  FROM comanda c INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
  WHERE c.tipdoc = 8
    AND c.anulat = 0 AND c.operat = 1 AND Coalesce(C.INCHISA, 0) = 0
    AND c1.restacceptat &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  IF aLISTID = CT_LISTID_COMCL THEN
    sInsert :=
    &apos;INSERT INTO tmp_cmd_TMP(codobiect, canta, resta, tip)
     SELECT tmp.valoare, sum(dl1.cantacceptat), sum(dl1.restacceptat), &apos;&apos;DL&apos;&apos;
     FROM (
       SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1&apos;&apos; AND filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
     ) tmp
       INNER JOIN CMDLIVRLINK DLINK ON DLINK.CODLINIECOMANDA = TMP.VALOARE
       INNER JOIN COMANDA1    DL1   ON DL1.CODCOMANDA1       = DLINK.CODCOMANDA1
       INNER JOIN COMANDA     DL    ON DL.CODCOMANDA         = DL1.CODCOMANDA
     WHERE DL.anulat = 0 AND DL.operat = 1 AND Coalesce(DL.INCHISA, 0) = 0
     GROUP BY TMP.VALOARE &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

    sInsert :=
    &apos;INSERT INTO tmp_cmd_TMP(codobiect, canta, tip)
     SELECT tmp.valoare, sum(l.cant), &apos;&apos;FACT&apos;&apos;
     FROM (
       SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1&apos;&apos; AND filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
     ) tmp
       INNER JOIN IESLINK L  ON L.CODLINIECOMANDA = TMP.VALOARE
       INNER JOIN IESIRI1 I1 ON I1.CODIES1        = L.CODIES1
       INNER JOIN IESIRI  I  ON I.CODIES          = I1.CODIES
     WHERE I.anulat = 0 AND I.operat = 1
     GROUP BY TMP.VALOARE &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CodDoc,NAV_TipDoc,NRDOC,DATADOC,PREFIXDOC,DENUMIRE,DEN_UM1,
    CANTCOMANDAT,CANTACCEPTAT,RESTACCEPTAT,
    PU,DEN_PART,VALOARE,OBS,TERMEN,MONEDA,STOCMIN,STOCMED,STOCMAX,
    STOCMOM,
    TRASEU, DELEGAT, MIJLTR, NRTRANSP, UMSPEC, CANTUMSPEC,
    CANTREZ,
    LIVR_DEN, LIVR_ADR, LIVR_LOC, LIVR_JUD, LIVR_ZONA,
    DENUSER,
    DenLaCli, CodLaCli,
    CodListat,
    NRCOLETE,
    VALTREZ,
    SUBUNITATEA,
    x_judet, x_codclasap, x_codsubunit&apos;||
    sAuxIns||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH SM AS (&apos;||sSM||&apos;)
  SELECT
    c.codcomanda, c.tipdoc,c.nrdoc,c.datadoc,c.prefixdoc,nobj.denumire, u1.den_um1,
    c1.cantcomandat/u1.Paritate,c1.cantacceptat/u1.Paritate&apos;||sRest||&apos;,
    c1.pu*u1.Paritate, &apos;||sDenPart||&apos;, c1.pu*c1.cantacceptat, c.obs, c1.termen, mon.den_moneda, nobjs.stocmin, nobjs.stocmed, nobjs.stocmax,
    Coalesce(sm.stoc,0)/u1.Paritate stocmom,
    t.dentraseu, d.delegat, d.mijltransp, d.nrtransp, us.den_um, c1.cantum1,
    (SELECT Coalesce(SUM(r.rest),0) FROM rezervats r WHERE r.codcomanda1 = c1.codcomanda1 and r.codnirstoc &gt; 0 and (r.codobiect = c1.codobiect or Coalesce(r.codobiect,0) = 0))/u1.Paritate cantrez,
    slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal),
    loclivr.den_localit, judlivr.den_judet, zonalivr.den_zona,
    winmadmin.pkg_userfirme.getUserName(c.userid),
    COALESCE(ac.denumire,trad.denumiretrad,nobj.denumire), Coalesce(ac.codextern,nobj.codextern),
    Coalesce(
      CASE ac.tipcodafisat
        WHEN 1 THEN gre.cod
        WHEN 2 THEN ac.codextern
        WHEN 3 THEN nobj.codextern
        WHEN 4 THEN nobj.codintern
        WHEN 5 THEN nobj.codvamal
        WHEN 6 THEN To_Char(nobj.codplu)
        WHEN 7 THEN o1.codextofe
      END,nobj.codextern
    ),
    (SELECT COUNT(1) FROM nartobjcolet oc WHERE oc.codobiect = c1.codobiect),
    (SELECT SUM(valdoc) FROM trezor1 x WHERE x.codcomanda = c.codcomanda) VALTREZ,
    s.den_subunit, judlivr.simbauto, clp.codclasep, s.codsubunit&apos;||
    sAuxSel||gUserAlias||&apos;
  FROM (
      SELECT To_Number(valoare) valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCOMANDA1&apos;&apos; and filtru1 = &apos;&apos;CODCOMANDA1&apos;&apos;
    ) tmpc
    INNER JOIN comanda1          c1       ON c1.codcomanda1     = tmpc.valoare
    INNER JOIN comanda           c        ON c.codcomanda       = c1.codcomanda
    INNER JOIN nartobj           nobj     ON nobj.codobiect     = c1.codobiect
    INNER JOIN nart              art      ON nobj.codarticol    = art.codarticol
    INNER JOIN num1              u1       ON u1.codum1          = c1.umsec
    LEFT  JOIN num               us       ON us.codum           = art.um1 &apos;||
    sJoinAux||&apos;
    LEFT  JOIN sm                         ON sm.codobiect       = c1.codobiect
    LEFT  JOIN nartobjsubunit    nobjs    ON nobjs.codobiect    = nobj.codobiect AND nobjs.subunitate = c.subunitatea AND (nobjs.codgest is null or nobjs.codgest = 0)
    LEFT  JOIN nmonede           mon      ON mon.codmoneda      = c.moneda
    LEFT  JOIN (
      SELECT TO_NUMBER(valoare) valoare, To_Number(filtru) filtru FROM tmp_manevra_liste WHERE filtru1 = &apos;&apos;ILINK&apos;&apos;
    )                            ilink    ON ilink.filtru       = c1.codcomanda1
    LEFT  JOIN npers             ag       ON c.agent            = ag.codpers
    LEFT  JOIN nclasea           cla      ON art.clasa          = cla.codclasea
    LEFT  JOIN npart             p        ON c.partener         = p.codpart
    LEFT  JOIN nclasep           clp      ON p.codclasa         = clp.codclasep
    LEFT  JOIN npart             prod     ON prod.codpart       = nobj.codproducator
    LEFT  JOIN ncarsupart        cs       ON cs.codcarsupart    = nobj.codcaract
    LEFT  JOIN nparttr           d        ON d.codparttr        = c.delegat
    LEFT  JOIN nagenda           slivr    ON slivr.codagenda    = c.codlocatie
    LEFT  JOIN nlocalit          loclivr  ON loclivr.codlocalit = slivr.codlocalit
    LEFT  JOIN njudet            judlivr  ON judlivr.codjudet   = loclivr.codjudet
    LEFT  JOIN nzone             zonalivr ON zonalivr.codzona   = loclivr.codzona
    LEFT  JOIN ntari             taralivr ON taralivr.codtara   = loclivr.codtara
    LEFT  JOIN traseulivr        t        ON t.codtraseulivr    = slivr.codtraseu
    LEFT  JOIN nartcli           ac       ON ac.codartcli       = PKG_LIST_BASE_UTILS.GetCodArtCli(c1.codobiect, c.partener, p.codclasa)
    LEFT  JOIN nartobjtrad       trad     ON trad.codlimba      = taralivr.codlimba and trad.codobiect = c1.codobiect
    LEFT  JOIN nechiv            e        ON e.codobiect        = c1.codobiect
    LEFT  JOIN grechiv           gre      ON gre.codgrechiv     = e.codgrupa
    LEFT  JOIN oferta1           o1       ON o1.codoferta1      = c1.codsursa
    LEFT  JOIN nsubunit          s        ON s.codsubunit       = c.subunitatea&apos;||
    gSuplJoins;
  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_comenziincurs;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BD3B0FE7A9E8BC14CAD96A756D713CFFEF6BAEE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMETICHETE IS

  vCodDoc   COMANDA.CODCOMANDA%TYPE;
  vNrAtrib  INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;

  SELECT Nvl(Max(AA.IndexLocal),0)
  INTO   vNrAtrib
  FROM Comanda1 C1
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nartatr aa ON aa.codarticol = o.codarticol
  WHERE c1.CodComanda = vCodDoc;

  DELETE tmp_dinamic_cols;

  FOR k IN 1..vNrAtrib
  LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2-1),&apos;fm999&apos;), &apos;Den.ATRIBUT&apos;||To_Char(k*2-1));
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2)  ,&apos;fm999&apos;), &apos;Val.ATRIBUT&apos;||To_Char(k*2));
  END LOOP;

  COMMIT;
END;

FUNCTION get_NrAtrib RETURN Integer IS
BEGIN
  RETURN vNrAtrib;
END;

FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib IS
  sCod VARCHAR2(50);
  sDen VARCHAR2(50);
  sVal VARCHAR2(50);
BEGIN
  SELECT a.Denumire, a1.CodExtern, a1.Valoare
  INTO   sDen      , sCod        , sVal
  FROM natrobj oa
    INNER JOIN nartatr aa ON aa.codartatr = oa.codartatr
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
    INNER JOIN natrib  a  ON a.codatribut = a1.codatribut
  WHERE oa.codobiect = pCodObiect
    AND aa.indexlocal = pIDX
    AND RowNum = 1;

  RETURN t_objatrib(sDen, sCod, sVal);
EXCEPTION
  WHEN No_Data_Found THEN RETURN t_objatrib(NULL, NULL, NULL);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(5000);
  sSelect     VARCHAR2(20000);
  sInsertDC   VARCHAR2(1000);
  sSelectDC   VARCHAR2(5000);
  sColIndex   varchar2(1000);
  sColCant    varchar2(100);
  sCondSelect varchar2(1000);
  aCount number(10);
BEGIN
  gSuplCols := &apos;comanda c, comanda1 c1, nartobj nao, nart na, comanda1 cc1, comanda cc, ngest g, formatii fm, npart p, nagenda ss, nagenda sl, nlocalit LocS, nlocalit LocL, nartcli ac, ntari tl, nartobjtrad ot, nartobjcolet co,&apos;||
                &apos;cmdprodmat prod&apos;;

  if Nvl(pkg_categconst.GetValConstanta(&apos;EticheteCantPeLinie&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) in (1,2) then
    sColIndex := &apos;, Y.NrColet, to_number(to_char(c1.codcomanda1)||LPAD(Y.NrColet, 4, &apos;&apos;0&apos;&apos;)) &apos;;
    sColCant  := &apos;, 1 Cant &apos;;
  else
    sColIndex := &apos;, c1.indexlocal, to_number(to_char(c1.codcomanda1)||LPAD(c1.indexlocal, 4, &apos;&apos;0&apos;&apos;)) &apos;;
    sColCant  := &apos;, c1.CantAcceptat &apos;;
  end if;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;, &apos;COMC&apos;, &apos;COMC.CODCOMANDA = CC.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;, &apos;COMC1&apos;, &apos;COMC1.CODCOMANDA1 = CC1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;, &apos;COMI&apos;, &apos;COMI.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;, &apos;COMI1&apos;, &apos;COMI1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if vCodDoc = 0 then
    sCondSelect := &apos; and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;&apos;CODCOMANDA&apos;&apos; and tmp.valoare = c.codcomanda) &apos;||chr(13);
  else
    sCondSelect := &apos; and c.codcomanda = &apos;||vCodDoc||chr(13);
  end if;

  FOR k IN 1..vNrAtrib LOOP
    sInsertDC := sInsertDC||&apos;,
    DenAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, ValAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, CodAtrib_&apos; || to_char(k, &apos;fm999&apos;);
    sSelectDC := sSelectDC ||&apos;,
    PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Den, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Val, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Cod&apos;;
  END LOOP;

  sInsert :=
  &apos;INSERT INTO &apos; || TMPNAME || &apos;(
    ART, CODCATALOG, NUMARCOLET,
    CLIENT, CODCLIENT, CODCOLET, IDFirma, NrComanda, SediuClient, ObsComanda, PozaClient,
    NrComandaInt,CodIntern,An,Formatie,DataCmdInt,Gest,Sapt,Schimb,CodExtern,Nivel,
    Adresaclient,
    Adresalivrare,
    DenLaClient, D1, D2, D3, Cant, IndexLocal, IdentUnic &apos;||sInsertDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    NAO.DENUMIRE, NA.CODEXTERNART, NVL(CO.INDEXLOCAL, 1) || &apos;&apos;/&apos;&apos; || GREATEST((SELECT COUNT(*) FROM NARTOBJCOLET WHERE CODOBIECT = C1.CODOBIECT), 1),
    P.DEN_PART, P.CODEXTERN,  CO.IDCOLET, PKG_GLOBALS.GETFIRMA_ID, CC.NRDOC, SL.OBS, CC.OBS, P.POZA,
    C.NRDOC,NAO.CodIntern,SUBSTR(to_char(C.An),3,2),FM.den_formatie,c.DatadOC,g.Den_Gest,to_char(c.datadoc, &apos;&apos;WW&apos;&apos;),C.Schimb,NAO.CodExtern,nvl(pnod.nivel,0),
    GetAdresa(SS.sector, SS.strada, SS.nr1, SS.nr2, SS.bloc, SS.scara, SS.etaj, SS.apart, SS.codpostal) AdresaClient,
    GetAdresa(SL.sector, SL.strada, SL.nr1, SL.nr2, SL.bloc, SL.scara, SL.etaj, SL.apart, SL.codpostal) AdresaLivrare,
    COALESCE(ac.denumire, ot.denumiretrad, nao.denumire), C1.D1, C1.D2, C1.D3&apos;||sColCant||
    sColIndex||sSelectDC||gUserAlias ||&apos;
  FROM comanda c
    inner join comanda1 c1 on c1.codcomanda = c.codcomanda
    inner join nartobj nao on nao.codobiect = c1.codobiect
    inner join nart na on nao.codarticol = na.codarticol&apos;||chr(13);
  if Nvl(pkg_categconst.GetValConstanta(&apos;EticheteCantPeLinie&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) = 1 then
    sSelect := sSelect|| &apos;  inner join (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= Nvl(c1.cantacceptat, 0) &apos;||chr(13);
  else if Nvl(pkg_categconst.GetValConstanta(&apos;EticheteCantPeLinie&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) = 2 then
    sSelect := sSelect|| &apos;  inner join (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= Nvl(c1.acceptum1, 0) &apos;||chr(13);
  end if;
  end if;
  sSelect := sSelect||
  &apos; left join cmdprodmat prod on prod.codcomanda1 = c1.codcomanda1 and prod.tip = 0
    left join cmdlink k on k.codcomanda1 = c1.codcomanda1
    left join comanda1 cc1 on cc1.codcomanda1 = k.codliniecomanda
    left join comanda cc on cc.codcomanda   = cc1.codcomanda
    left join ngest g on c.codgest = g.codgest
    left join formatii fm on fm.codformatie = c.codformatie
    left join lansare1 lans1 on lans1.codcmd1 = c1.codcomanda1
    left join proiectnod pnod on lans1.codproiectnod = pnod.codproiectnod
    left join npart p on p.codpart = cc.partener
    left join nagenda ss on ss.codpart = cc.partener and ss.sediusocial in (4,5,6,7)
    left join nagenda sl on sl.codagenda = cc.codlocatie
    left join nlocalit LocS on LocS.CodLocalit = ss.codlocalit
    left join nlocalit LocL on LocL.CodLocalit = sl.CodLocalit
    left join nartcli ac on ac.codobiect = c1.codobiect and ac.codpart = cc.partener
    left join ntari tl on tl.codtara = LocL.codtara
    left join nartobjtrad ot on ot.codlimba = tl.codlimba and ot.codobiect = c1.codobiect
    left join nartobjcolet co on co.codobiect = nao.codobiect &apos;||
    gSuplJoins||&apos;
  WHERE 1 = 1 &apos;||sCondSelect||&apos;
  union all
  SELECT
    NAO.DENUMIRE, NA.CODEXTERNART, NVL(CO.INDEXLOCAL, 1) || &apos;&apos;/&apos;&apos; || GREATEST((SELECT COUNT(*) FROM NARTOBJCOLET WHERE CODOBIECT = C1.CODOBIECT), 1),
    P.DEN_PART, P.CODEXTERN,  CO.IDCOLET, PKG_GLOBALS.GETFIRMA_ID, CC.NRDOC, SL.OBS, CC.OBS, P.POZA,
    C.NRDOC,NAO.CodIntern,SUBSTR(to_char(C.An),3,2),FM.den_formatie,c.DatadOC,g.Den_Gest,to_char(c.datadoc, &apos;&apos;WW&apos;&apos;),C.Schimb,NAO.CodExtern,nvl(pnod.nivel,0),
    GetAdresa(SS.sector, SS.strada, SS.nr1, SS.nr2, SS.bloc, SS.scara, SS.etaj, SS.apart, SS.codpostal) AdresaClient,
    GetAdresa(SL.sector, SL.strada, SL.nr1, SL.nr2, SL.bloc, SL.scara, SL.etaj, SL.apart, SL.codpostal) AdresaLivrare,
    COALESCE(ac.denumire, ot.denumiretrad, nao.denumire), C1.D1, C1.D2, C1.D3&apos;||sColCant||
    sColIndex||sSelectDC||gUserAlias ||&apos;
  FROM comanda c
    inner join comanda1 c1 on c1.codcomanda = c.codcomanda
    inner join cmdprodmat prod on prod.codcomanda1 = c1.codcomanda1 and prod.tip = 2
    inner join nartobj nao on nao.codobiect = prod.codobiect
    inner join nart na on nao.codarticol = na.codarticol &apos;||chr(13);
  if Nvl(pkg_categconst.GetValConstanta(&apos;EticheteCantPeLinie&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) = 1 then
    sSelect := sSelect|| &apos;  inner join (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= Nvl(prod.cant, 0) &apos;||chr(13);
  else if Nvl(pkg_categconst.GetValConstanta(&apos;EticheteCantPeLinie&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) = 2 then
    sSelect := sSelect|| &apos;  inner join (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= Nvl(prod.cantum1, 0) &apos;||chr(13);
  end if;
  end if;
  sSelect := sSelect||
  &apos; left join cmdlink k on k.codcomanda1 = c1.codcomanda1
    left join comanda1 cc1 on cc1.codcomanda1 = k.codliniecomanda
    left join comanda cc on cc.codcomanda   = cc1.codcomanda
    left join ngest g on c.codgest = g.codgest
    left join formatii fm on fm.codformatie = c.codformatie
    left join lansare1 lans1 on lans1.codcmd1 = c1.codcomanda1
    left join proiectnod pnod on lans1.codproiectnod = pnod.codproiectnod
    left join npart p on p.codpart = cc.partener
    left join nagenda ss on ss.codpart = cc.partener and ss.sediusocial in (4,5,6,7)
    left join nagenda sl on sl.codagenda = cc.codlocatie
    left join nlocalit LocS on LocS.CodLocalit = ss.codlocalit
    left join nlocalit LocL on LocL.CodLocalit = sl.CodLocalit
    left join nartcli ac on ac.codobiect = c1.codobiect and ac.codpart = cc.partener
    left join ntari tl on tl.codtara = LocL.codtara
    left join nartobjtrad ot on ot.codlimba = tl.codlimba and ot.codobiect = c1.codobiect
    left join nartobjcolet co on co.codobiect = nao.codobiect &apos;||
    gSuplJoins||&apos;
  WHERE c1.consum = 2 &apos;||sCondSelect;

  pkg_list_base_comdoc.setparams(vCodDoc, aLISTID);
  pkg_list_base_comdoc.add_list_params;

  --delete x;
  --insert into x(test) values (sselect);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  execute immediate &apos;select count(*) from &apos;||TMPNAME into aCount;
  if aCount &gt; 0 then
    execute immediate &apos;update &apos;||TMPNAME||&apos; set contor = to_char(rownum)||&apos;&apos;/&apos;&apos;||&apos;||to_char(acount);
  end if;

  COMMIT;
END;

END PKG_LIST_BASE_COMETICHETE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAD6BFC23F260881FCCBAE781206042C0EAC0570</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMETICHETEMAN is

  vCodDoc     COMANDA.CODCOMANDA%TYPE;
  vNrAtrib    INTEGER;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;

  SELECT Nvl(Max(AA.IndexLocal),0)
  INTO   vNrAtrib
  FROM Comanda1 C1
    INNER JOIN nartobj o  ON o.codobiect   = c1.codobiect
    INNER JOIN nartatr aa ON aa.codarticol = o.codarticol
  WHERE c1.CodComanda = vCodDoc;

  DELETE tmp_dinamic_cols;

  FOR k IN 1..vNrAtrib
  LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2-1),&apos;fm999&apos;), &apos;Den.ATRIBUT&apos;||To_Char(k*2-1));
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2)  ,&apos;fm999&apos;), &apos;Val.ATRIBUT&apos;||To_Char(k*2));
  END LOOP;

  COMMIT;
END;

FUNCTION get_NrAtrib RETURN Integer IS
BEGIN
  RETURN vNrAtrib;
END;

FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib IS
  sCod VARCHAR2(50);
  sDen VARCHAR2(50);
  sVal VARCHAR2(50);
BEGIN
  SELECT a.Denumire, a1.CodExtern, a1.Valoare
  INTO   sDen      , sCod        , sVal
  FROM natrobj oa
    INNER JOIN nartatr aa ON aa.codartatr = oa.codartatr
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
    INNER JOIN natrib  a  ON a.codatribut = a1.codatribut
  WHERE oa.codobiect = pCodObiect
    AND aa.indexlocal = pIDX
    AND RowNum = 1;

  RETURN t_objatrib(sDen, sCod, sVal);
EXCEPTION
  WHEN No_Data_Found THEN RETURN t_objatrib(NULL, NULL, NULL);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(5000);
  sSelect     VARCHAR2(20000);
  sInsertDC   VARCHAR2(1000);
  sSelectDC   VARCHAR2(5000);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;comanda c,comanda1 c1,nartobj nao,nart na,ngest g,formatii fm, cmdprodman man&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;   , &apos;COMI&apos; , &apos;COMI.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;  , &apos;COMI1&apos;, &apos;COMI1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos; , &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos; , &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  FOR k IN 1..vNrAtrib LOOP
    sInsertDC := sInsertDC||&apos;,
    DenAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, ValAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, CodAtrib_&apos; || to_char(k, &apos;fm999&apos;);
    sSelectDC := sSelectDC ||&apos;,
    PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Den, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Val, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Cod&apos;;
  END LOOP;

  sInsert :=
  &apos;INSERT INTO &apos; || TMPNAME || &apos;(
     ART,
     CODCATALOG,
     NrComandaInt,
     CodIntern,
     An,
     Formatie,
     DataCmdInt,
     Gest,
     Sapt,
     Schimb,
     CodExtern,
     NrOp,      
     Cant,      
     Operatie,  
     LocMunca,  
     DenTarif,  
     tarif,     
     tu,        
     valoare,   
     dsv,       
     bps,       
     tpi,       
     obs,       
     detalii&apos;||sInsertDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    NAO.DENUMIRE,
    NA.CODEXTERNART,
    C.NRDOC,
    NAO.CodIntern,
    SUBSTR(to_char(C.An),3,2),
    FM.den_formatie,
    c.DatadOC,
    g.Den_Gest,
    to_char(c.datadoc, &apos;&apos;WW&apos;&apos;),
    C.Schimb,
    NAO.CodExtern,
    man.NrOp,      
    man.Cant,      
    OP.DENUMIRE,  
    LM.DENUMIRE,  
    T.DenUMIRE,  
    T.tarif,     
    MAN.tu,        
    MAN.valoare,   
    MAN.dsv,       
    MAN.bps,       
    MAN.tpi,       
    C1.obs,       
    MAN.detalii &apos;||sSelectDC||gUserAlias ||&apos;
  FROM comanda c
    inner join comanda1   c1  on c1.codcomanda  = c.codcomanda
    inner join prodcomp   pc  on c1.codreteta   = pc.codprodcomp
    inner join cmdprodman man on c1.codcomanda1 = man.codcomanda1
    inner join nartobj    nao on nao.codobiect  = c1.codobiect
    inner join nart       na  on nao.codarticol = na.codarticol
    inner join ngest      g   on c.codgest      = g.codgest
    INNER JOIN noper      op  on man.codop      = op.codop
    INNER JOIN locmunca   lm  on lm.codloc      = man.codloc
    INNER JOIN (
      SELECT T1.codtarif, T1.Tarif, t.denumire
      FROM TARIFEMAN1 T1 INNER JOIN tarifeman t on t1.codtarif = t.codtarif AND (pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU) BETWEEN T1.ALSTART and T1.ALSTOP
    ) T ON MAN.CODTARIF = T.CODTARIF 
    left join formatii    fm  on fm.codformatie = c.codformatie &apos;||gSuplJoins||&apos;
  WHERE c.codcomanda = &apos; || vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_COMETICHETEMAN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMETICHETEMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67E80C23201D2B7C08EF217F596C08D6C177B366</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMETICHETEMAT IS

  vCodDoc   COMANDA.CODCOMANDA%TYPE;
  vNrAtrib  INTEGER;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;

  SELECT Nvl(Max(AA.IndexLocal),0)
  INTO   vNrAtrib
  FROM Comanda1 C1
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nartatr aa ON aa.codarticol = o.codarticol
  WHERE c1.CodComanda = vCodDoc;

  DELETE tmp_dinamic_cols;

  FOR k IN 1..vNrAtrib
  LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2-1),&apos;fm999&apos;), &apos;Den.ATRIBUT&apos;||To_Char(k*2-1));
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2)  ,&apos;fm999&apos;), &apos;Val.ATRIBUT&apos;||To_Char(k*2));
  END LOOP;

  COMMIT;
END;

FUNCTION get_NrAtrib RETURN Integer IS
BEGIN
  RETURN vNrAtrib;
END;

FUNCTION Atrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN t_objatrib IS
  sCod VARCHAR2(50);
  sDen VARCHAR2(50);
  sVal VARCHAR2(50);
BEGIN
  SELECT a.Denumire, a1.CodExtern, a1.Valoare
  INTO   sDen      , sCod        , sVal
  FROM natrobj oa
    INNER JOIN nartatr aa ON aa.codartatr = oa.codartatr
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
    INNER JOIN natrib  a  ON a.codatribut = a1.codatribut
  WHERE oa.codobiect = pCodObiect
    AND aa.indexlocal = pIDX
    AND RowNum = 1;

  RETURN t_objatrib(sDen, sCod, sVal);
EXCEPTION
  WHEN No_Data_Found THEN RETURN t_objatrib(NULL, NULL, NULL);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(5000);
  sSelect     VARCHAR2(20000);
  sInsertDC   VARCHAR2(1000);
  sSelectDC   VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;comanda c,comanda1 c1,nartobj nao,nart na,ngest g,formatii fm,cmdprodmat mat&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;, &apos;COMI&apos;, &apos;COMI.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;, &apos;COMI1&apos;, &apos;COMI1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  FOR k IN 1..vNrAtrib LOOP
    sInsertDC := sInsertDC||&apos;,
    DenAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, ValAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||&apos;, CodAtrib_&apos; || to_char(k, &apos;fm999&apos;);
    sSelectDC := sSelectDC ||&apos;,
    PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Den, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Val, PKG_LIST_BASE_COMETICHETE.Atrib(c1.codobiect,&apos; || k ||&apos;).Cod&apos;;
  END LOOP;

  sInsert :=
  &apos;INSERT INTO &apos; || TMPNAME || &apos;(
     ART,
     CODCATALOG,
     NUMARCOLET,
     CODCOLET,
     IDFirma,
     NrComandaInt,
     CodIntern,
     An,
     Formatie,
     DataCmdInt,
     Gest,
     Sapt,
     Schimb,
     CodExtern,
     D1,
     D2,
     D3,
     Cant&apos;||sInsertDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    NAO.DENUMIRE,
    NA.CODEXTERNART,
    NVL(CO.INDEXLOCAL, 1) || &apos;&apos;/&apos;&apos; || GREATEST((SELECT COUNT(*) FROM NARTOBJCOLET WHERE CODOBIECT = C1.CODOBIECT), 1),
    CO.IDCOLET,
    PKG_GLOBALS.GETFIRMA_ID,
    C.NRDOC,
    NAO.CodIntern,
    SUBSTR(to_char(C.An),3,2),
    FM.den_formatie,
    c.DatadOC,
    g.Den_Gest,
    to_char(c.datadoc, &apos;&apos;WW&apos;&apos;),
    C.Schimb,
    NAO.CodExtern,
    MAT.D1,
    MAT.D2,
    MAT.D3,
    MAT.Cant &apos;||sSelectDC||gUserAlias ||&apos;
  FROM comanda c
    inner join comanda1 c1 on c1.codcomanda = c.codcomanda
    inner join prodcomp pc on c1.codreteta = pc.codprodcomp
    inner join cmdprodmat mat on c1.codcomanda1 = mat.codcomanda1
    inner join nartobj nao on nao.codobiect = mat.codobiect
    inner join nart na on nao.codarticol = na.codarticol
    left join ngest g on c.codgest = g.codgest
    left join formatii fm on fm.codformatie = c.codformatie
    left join lansare1 lans1 on lans1.codcmd1 = c1.codcomanda1
    left join proiectnod pnod on lans1.codproiectnod = pnod.codproiectnod
    left join nartobjcolet co on co.codobiect = nao.codobiect &apos;||
    gSuplJoins||&apos;
  WHERE (mat.tip = 1 or (mat.tip = 0 and pc.tipreteta = 2)) and c.codcomanda = &apos; || vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_COMETICHETEMAT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMINTLANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4539BF917B53886F7C760A8B27386AF28F0AD39</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMINTLANS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(5000);
  sSelect   VARCHAR2(25000);
  sCondCmd  VARCHAR2(500);
BEGIN
  IF pkg_list_selectperioada.optiunea1 THEN
    gSuplCols := &apos;comanda c, comanda1 c1, nartobj produs, nartobj component, nart artc, formatii formatii, num umcomponent, prodcomp pc, ngest gimp, cmdprodmat mat&apos;;
  ELSE
    gSuplCols := &apos;comanda c, comanda1 c1, nartobj produs, formatii formatii, prodcomp pc&apos;;
  END IF;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTPROD&apos;, &apos;OEXTPROD.CODOBIECT = PRODUS.CODOBIECT&apos;);
  IF pkg_list_selectperioada.optiunea1 THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTCOMP&apos;, &apos;OEXTCOMP.CODOBIECT = COMPONENT.CODOBIECT&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if not pkg_list_selectperioada.DupaData then
    sCondCmd := &apos;c.an*12+c.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;;
  else
    sCondCmd := &apos;c.datadoc between to_date(&apos;&apos;&apos;||to_char(pkg_list_selectperioada.dataini, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||to_char(pkg_list_selectperioada.datafin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, CarnetDocProd, NrDocProd, DataDocProd, SerieDocProd, Articol, Reteta,
    TermenExec, DenUM, CantLansata, PretLansat, ValLansata, CantRealiz, CantRealizCur, ValRealiz,
    DifCant, DifVal, Client, CarnetDocCli, NrDocCli, DataDocCli, SerieDocCli, Sectie, TermenLivr,&apos;||chr(13);
    if pkg_list_selectperioada.optiunea1 then
      sInsert := sInsert||&apos;Component, CantComp, UMComp, GestImp,&apos;||chr(13);
    end if;
    sInsert := sInsert||&apos;
    Schimb, Formatie,
    Facturat,
    FNrDoc,
    FDataDoc,
    ComClosed, Subunitate, CmdSubSerie, CmdSubNrDoc, CmdSubDataDoc, Saptamana, ComCanceled, ComCliClosed, ComCliCanceled &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH ComProd as (
    select
      c.CodComanda, c.TipDoc, c1.CodComanda1, mat.CodCmdProdMat, doc.simbol CarnetDocProd, c.NrDoc NrDocProd, c.DataDoc DataDocProd, doc.serie SerieDocProd,
      obj.denumire produs, obj.codobiect codprodus, ret.obs Reteta, c1.Termen TermenExec, num1.den_um1 DenUM,
      mat.Cant CantLansata, mat.Pret PretLansat, mat.Cant*mat.Pret ValLansata, mat.Cant - mat.Rest CantRealiz, (mat.Cant - mat.Rest)*mat.Pret ValRealiz,
      mat.Rest DifCant, mat.Rest*mat.Pret DifVal, G.Den_gest Sectie, c.CodFormatie, nvl(c.schimb, 0) schimb,&apos;||chr(13);
  if pkg_list_selectperioada.optiunea1 then
    sSelect := sSelect||&apos;objc.denumire component, objc.codobiect codcomponent, matc.cant CantComp, matc.codcmdprodmat codmaterial, &apos;||chr(13);
  end if;
    sSelect := sSelect||&apos;
      case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, to_number(to_char(c1.termen, &apos;&apos;IW&apos;&apos;)) saptamana, case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled
    from comanda c
      inner join ngest         g on c.codgest      = g.codgest
      inner join comanda1     c1 on c1.codcomanda  = c.codcomanda
      inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0
      inner join nartobj     obj on mat.codobiect  = obj.codobiect&apos;||chr(13);
  if pkg_list_selectperioada.optiunea1 then
    sSelect := sSelect||&apos;inner join cmdprodmat matc on c1.codcomanda1 = matc.codcomanda1 and matc.tip &gt; 0
      inner join nartobj    objc on matc.codobiect = objc.codobiect &apos;||chr(13);
  end if;
    sSelect := sSelect||&apos;inner join num1            on c1.umsec       = num1.codum1
      left  join doccarnete  doc on c.carnetdoc    = doc.codcarnet
      left  join prodcomp    ret on c1.codreteta   = ret.codprodcomp
    where &apos;||sCondCmd||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||&apos;),
  ComCli as (
    SELECT
      cc1.codcomanda1 codliniecomanda, c1.codcomanda1, doc.simbol CarnetDocCli, cc.NrDoc NrDocCli, cc.DataDoc DataDocCli, doc.serie SerieDocCli, P.den_part client, cc1.Termen TermenLivr,
      case when cc.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, case when cc.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled
    FROM comanda c
         inner join comanda1 c1 on c.codcomanda = c1.codcomanda
         inner join comanda1 cc1 on cc1.codcomanda1 = pkg_comanda.dincmdcli(c1.codcomanda1)
         inner join comanda cc on cc1.codcomanda = cc.codcomanda
         inner join npart p on cc.partener = p.codpart
         left join doccarnete doc on cc.carnetdoc = doc.codcarnet
    where &apos;||sCondCmd||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||&apos;
  ),
  ComSub as (
    SELECT c1.CodComanda1, doc.simbol CarnetDocSub, c.NrDoc NrDocSub, c.DataDoc DataDocSub, doc.serie SerieDocSub, s.den_subunit subunitate, c1.Termen TermenLivr
    FROM comanda c
      inner join nsubunit     s on c.subunitatea   = s.codsubunit
      inner join comanda1    c1 on c1.codcomanda  = c.codcomanda
      left  join doccarnete doc on c.carnetdoc    = doc.codcarnet
    WHERE c.tipdoc = 44 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;)||&apos;),
  CantRealLC as (
    SELECT sum(i1.Cant) cant, pl.codliniecomanda
    FROM intrari i
      inner join intrari1    i1 on i.codintr = i1.codintr
      inner join intrprodlink PL on i1.codintr1 = PL.codintr1
    WHERE i.tipdoc = 7 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by pl.codliniecomanda ),
  FACTURAT as (
    SELECT c1.Codcomanda1, sum(i1.Cant) cant, stragg3200(to_char(i.nrdoc)) nrdoc, stragg3200(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc
    FROM iesiri i
      inner join iesiri1 i1 on i.codies = i1.codies
      inner join ieslink L on i1.codies1 = L.codies1
      inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1
    WHERE 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ),
  DL as (
    SELECT c1.Codcomanda1, sum(i1.Cant) cant, stragg3200(to_char(i.nrdoc)) nrdoc, stragg3200(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc
    FROM iesiri i
      inner join iesiri1 i1 on i.codies = i1.codies
      inner join ieslink L on i1.codies1 = L.codies1
      inner join cmdlivrlink LL on L.codliniecomanda = LL.codcomanda1
      inner join comanda1 c1 on LL.codliniecomanda = c1.codcomanda1
   WHERE 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 )
  SELECT
    ComProd.CodComanda, ComProd.TipDoc, ComProd.CarnetDocProd, ComProd.NrDocProd, ComProd.DataDocProd, ComProd.SerieDocProd, ComProd.Produs, ComProd.Reteta,
    ComProd.TermenExec, ComProd.DenUM, ComProd.CantLansata, ComProd.PretLansat, ComProd.ValLansata, ComProd.CantRealiz, CantRealLC.Cant, ComProd.ValRealiz,
    ComProd.DifCant, ComProd.DifVal, ComCli.Client, ComCli.CarnetDocCli, ComCli.NrDocCli, ComCli.DataDocCli, ComCli.SerieDocCli, ComProd.Sectie, ComCli.TermenLivr,&apos;||chr(13);
  if pkg_list_selectperioada.optiunea1 then
    sSelect := sSelect||&apos; ComProd.Component, ComProd.CantComp, umcomponent.den_um, gimp.den_gest,&apos;||chr(13);
  end if;
  sSelect := sSelect||&apos; ComProd.Schimb, formatii.den_formatie,
    case when nvl(facturat.codcomanda1,0) = 0 then DL.cant else facturat.cant end,
    case when nvl(facturat.codcomanda1,0) = 0 then DL.nrdoc else facturat.nrdoc end,
    case when nvl(facturat.codcomanda1,0) = 0 then DL.datadoc else facturat.datadoc end,
    ComProd.ComClosed, ComSub.Subunitate, ComSub.SerieDocSub, ComSub.NrDocSub, ComSub.DataDocSub, ComProd.Saptamana, ComProd.ComCanceled, ComCli.ComClosed, ComCli.ComCanceled &apos;||gUserAlias||&apos;
  FROM ComProd
    inner join nartobj produs on produs.codobiect = comprod.codprodus&apos;||chr(13);
  if pkg_list_selectperioada.optiunea1 then
    sSelect := sSelect||&apos;
    inner join nartobj component on component.codobiect = comprod.codcomponent
    inner join nart artc on component.codarticol = artc.codarticol
    inner join num umcomponent on artc.um = umcomponent.codum
    left join nartimplicite artcimp on artc.codarticol = artcimp.codarticol AND artcimp.codsubunit = pkg_globals.getsubunitate
    left join ngest gimp on artcimp.gestimplicita = gimp.codgest
    left join cmdprodmat mat on mat.codcmdprodmat = comprod.codmaterial &apos;||chr(13);
  end if;
  sSelect := sSelect||&apos;
    left join comanda1 c1 on c1.codcomanda1 = comprod.codcomanda1
    left join comanda c on c.codcomanda = comprod.codcomanda
    left join prodcomp pc on pc.codprodcomp = c1.codreteta
    left join formatii on nvl(comprod.codformatie, 0) = formatii.codformatie
    left join comcli on comprod.codcomanda1 = comcli.codcomanda1
    left join cmdlink on cmdlink.codcomanda1 = comprod.codcomanda1
    left join comsub on cmdlink.codliniecomanda = comsub.codcomanda1
    left join facturat on facturat.codcomanda1 = comcli.codliniecomanda
    left join DL on DL.codcomanda1 = comcli.codliniecomanda
    left join cantrealLC on cantreallc.codliniecomanda = comprod.codcmdprodmat&apos;||
    gSuplJoins;

 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
 COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_comintlans; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FA795F4208322071834474AF1106C50B6478EDD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_compens IS

  xPrefixDoc VARCHAR2(50);
  xNrDoc     NUMBER;
  xDataDoc   DATE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GET_PREFIXDOC_FROM_VAR RETURN VARCHAR2 IS
BEGIN
 RETURN xPrefixDoc  ;
 xPrefixDoc := NULL;
END;

FUNCTION GET_NRDOC_FROM_VAR     RETURN NUMBER IS
BEGIN
 RETURN xNrDoc  ;
 xNrDoc := NULL;
END;

FUNCTION GET_DATADOC_FROM_VAR   RETURN DATE IS
BEGIN
 RETURN xDataDoc  ;
 xDataDoc := NULL;
END;

FUNCTION  GET_EXPLICATIE(pSemnificatie INTEGER,
                         pDenPart      VARCHAR2,
                         pTipDoc       NUMBER,
                         pCodDoc       NUMBER,
                         pMoneda       VARCHAR2,
                         pSemnifStins  INTEGER
                        ) RETURN VARCHAR2 IS
  vDoc VARCHAR2(100);
  vExplicatie VARCHAR2(350);
BEGIN

  xPrefixDoc := NULL;
  xNrDoc     := NULL;
  xDataDoc   := NULL;

  IF pSemnificatie IN (1302,1352) THEN
    vExplicatie := &apos;Direct pe cont&apos;;
  ELSIF pSemnificatie IN (1301,1351) THEN
    vExplicatie := pDenPart||&apos; Fara doc. de legatura&apos;;
  ELSIF pSemnificatie IN (1300,1303,1350,1353) THEN
    IF pTipDoc = 5 AND pSemnifStins = 130 THEN
      SELECT &apos;DVI/&apos;||dvi.nrdoc||&apos;/&apos;||dvi.datadoc, &apos;DVI&apos;, dvi.nrdoc, dvi.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM dvi
      WHERE dvi.coddvi = pCodDoc;
    ELSIF pTipDoc IN (1,3,4,5,9) THEN
      SELECT i.prefixdoc||&apos;/&apos;||i.nrdoc||&apos;/&apos;||i.datadoc, i.prefixdoc, i.nrdoc, i.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM intrari i
      WHERE i.codintr = pCodDoc AND i.tipdoc = pTipDoc;
    ELSIF pTipDoc IN (16,19,21,22,26) THEN
      SELECT i.prefixdoc||&apos;/&apos;||i.nrdoc||&apos;/&apos;||i.datadoc, i.prefixdoc, i.nrdoc, i.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM iesiri i
      WHERE i.codies = pCodDoc AND i.tipdoc = pTipDoc;
    ELSIF pTipDoc = 28 THEN
      SELECT &apos;PV/&apos;||c.nrdoc||&apos;/&apos;||c.datadoc, &apos;PV&apos;, c.nrdoc, c.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM compens c
      WHERE c.codcompens = pCodDoc;
    ELSIF pTipDoc IN (29,30) THEN
      SELECT t1.doc||&apos;/&apos;||t1.nrdoc||&apos;/&apos;||t1.datadoc, t1.doc, t1.nrdoc, t1.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM  trezor1 t1
      WHERE t1.codtrezor1 = pCodDoc;
    ELSIF pTipDoc = 35 THEN
      SELECT &apos;NC/&apos;||nc.nrdoc||&apos;/&apos;||nc.datadoc, &apos;NC&apos;, nc.nrdoc, nc.datadoc
      INTO vDoc, xPrefixDoc, xNrDoc, xDataDoc
      FROM  nc1 INNER JOIN nc ON nc.codnc = nc1.codnc
      WHERE nc1.codnc1 = pCodDoc;
    END IF;
    IF pSemnificatie IN (1303,1353) THEN
      vExplicatie := &apos;Litigiu &apos;;
    END IF;
    vExplicatie := vExplicatie||pDenPart||&apos; &apos;||vDoc;
  END IF;

  IF pMoneda IS NOT NULL
  THEN  vExplicatie := vExplicatie ||&apos; /&apos;||pMoneda;
  END IF;
  RETURN vExplicatie;
END;

PROCEDURE Umple_TMP_LIST_COMPENS (vCodDoc NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sWhere   VARCHAR2( 1000);
BEGIN

  IF Nvl(vCodDoc, 0) &gt; 0 THEN
    sWhere := &apos;
    WHERE C.CODCOMPENS = &apos;||vCodDoc;
  ELSE
    sWhere := &apos;
    WHERE C.DATADOC &apos;;

    IF pkg_list_alegperioada.getDataS = pkg_list_alegperioada.getDataF
    THEN sWhere := sWhere||&apos;= To_Date(&apos;&apos;&apos;||To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
    ELSE sWhere := sWhere||&apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
    END IF;

    sWhere := sWhere||pkg_list_base_utils.COND_SUBUNIT(&apos;C&apos;);
  END IF;

  sInsert :=
  &apos;INSERT INTO TMP_LIST_COMPENS (
    CODDOC, IDX,
    EXPLD, PARTD, CODPARTD, CODCONTD, VALD, RESTD, CURSD, TVAD, PROVIZIOND, PREFIXDOCD, NRDOCD, DATADOCD,
    EXPLC, PARTC, CODPARTC, CODCONTC, VALC, RESTC, CURSC, TVAC, PROVIZIONC, PREFIXDOCC, NRDOCC, DATADOCC,
    CODOBLIGSTINSD, CODOBLIGSTINSC)
  SELECT
    NVL(cc.codcompens, cd.codcompens), NVL(cd.idx,cc.idx),
    cd.expl, cd.den_part, cd.codpart, cd.cont , cd.val * cd.curs, Nvl(cd.rest,0) * cd.curs, cd.curs, cd.tva, cd.provizion, cd.prefixdoc, cd.nrdoc, cd.datadoc,
    cc.expl, cc.den_part, cc.codpart, cc.cont , cc.val * cc.curs, Nvl(cc.rest,0) * cc.curs, cc.curs, cc.tva, cc.provizion, cc.prefixdoc, cc.nrdoc, cc.datadoc,
    cd.codobligpif, cc.codobligpif
  FROM  (
    SELECT c.codcompens,
      RANK() over (PARTITION BY c.codcompens ORDER BY g.codgeneral) idx,
      PKG_LIST_BASE_COMPENS.GET_EXPLICATIE(o.semnificatie, p.den_part, gs.tipdoc, gs.coddoc, mon.simbol, gs.semnificatie) expl, p.codpart, p.den_part,
      PKG_LIST_BASE_COMPENS.GET_PREFIXDOC_FROM_VAR PrefixDOC,
      PKG_LIST_BASE_COMPENS.GET_NRDOC_FROM_VAR NrDOC,
      PKG_LIST_BASE_COMPENS.GET_DATADOC_FROM_VAR DataDOC,
      DECODE(o.semnificatie,1302,o.icont,PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,p.codpart,c.an*12+c.luna,o.semnificatie)) cont,
      DECODE(o.semnificatie,1301,-1,1) * o.valoare val,
      DECODE(o.semnificatie,1301,-1,1) * nvl(os.rest,0) rest ,
      g.curs, g.tva, nvl(o.valoare * g.curs * o.coefprovizion,0) provizion, os.codobligpif
    FROM  compens c
      INNER JOIN general g ON c.codcompens = g.coddoc AND g.tipdoc = 28
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral AND o.semnificatie IN (1300,1301,1302,1303)
      INNER JOIN npart p ON p.codpart = c.partd
      LEFT JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN obligpif os ON os.codobligpif = Decode(o.semnificatie,1303,o.codobligasociat,s.codstinspif)
      LEFT JOIN general gs ON gs.codgeneral = os.codgeneral
      LEFT JOIN nmonede mon ON mon.codmoneda = g.moneda&apos;||
    sWhere||&apos;
    ) cd
  FULL OUTER JOIN (
    SELECT c.codcompens,
      RANK() over (PARTITION BY c.codcompens ORDER BY g.codgeneral) idx,
      PKG_LIST_BASE_COMPENS.GET_EXPLICATIE(o.semnificatie, p.den_part, gs.tipdoc, gs.coddoc, mon.simbol, gs.semnificatie) expl, p.codpart, p.den_part,
      PKG_LIST_BASE_COMPENS.GET_PREFIXDOC_FROM_VAR PrefixDOC,
      PKG_LIST_BASE_COMPENS.GET_NRDOC_FROM_VAR NrDOC,
      PKG_LIST_BASE_COMPENS.GET_DATADOC_FROM_VAR DataDOC,
      DECODE(o.semnificatie,1352,o.icont,PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,p.codpart,c.an*12+c.luna,o.semnificatie)) cont,
      DECODE(o.semnificatie,1351,-1,1) * o.valoare val,
      DECODE(o.semnificatie,1351,-1,1) * nvl(os.rest,0) rest ,
      g.curs, g.tva, nvl(o.valoare * g.curs * o.coefprovizion,0) provizion, os.codobligpif
    FROM  compens c
      INNER JOIN general g ON c.codcompens = g.coddoc AND g.tipdoc = 28
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral AND o.semnificatie IN (1350,1351,1352,1353)
      INNER JOIN npart p ON p.codpart = c.partc
      LEFT JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN obligpif os ON os.codobligpif = Decode(o.semnificatie,1353,o.codobligasociat,s.codstinspif)
      LEFT JOIN general gs ON gs.codgeneral = os.codgeneral
      LEFT JOIN nmonede mon ON mon.codmoneda = g.moneda&apos;||
    sWhere||&apos;
    ) cc ON cd.codcompens = cc.codcompens AND cd.idx = cc.idx &apos;;

  DELETE TMP_LIST_COMPENS;
  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
END;


PROCEDURE processlist (tmp_name  VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(30000);
  sCursRef  VARCHAR2(100);
  aSitV     NUMBER(1);
  aBancaV   NUMBER(20);
  aMonedaV  NUMBER(20);
BEGIN
  gSuplCols := &apos;tmp_list_compens t, compens c, doccarnete carn, nsubunit sub&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, c.datadoc )&apos;;
  ELSE sCursRef := &apos;, 1 &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmp_name||&apos; (
    NAV_CodDoc,NAV_TipDoc,
    DOCCOMPENS,DATADOC,DENCARNET,SIMBCARNET,SERCARNET,
    EXPLD,Partd,CONTD,VALD,RESTD,CURSD,TVAD,OBSD,PROVIZIOND,PREFIXDOCD,NRDOCD,DATADOCD,
    EXPLC,PartC,CONTC,VALC,RESTC,CURSC,TVAC,OBSC,PROVIZIONC,PREFIXDOCC,NRDOCC,DATADOCC,
    SUBUNITATEA,IDX,Curs_ref&apos;||gUserFields||&apos;)
  SELECT c.codcompens, 28,
    c.nrdoc||&apos;&apos; / &apos;&apos;||c.datadoc,c.datadoc, carn.denumire, carn.simbol, carn.serie,
    t.expld, t.partd, ncd.simbol, t.vald, t.restd, t.cursd, t.tvad, c.obsd, t.proviziond, t.prefixdocd, t.nrdocd, t.datadocd,
    t.explc, t.partc, ncc.simbol, t.valc, t.restc, t.cursc, t.tvac, c.obsc, t.provizionc, t.prefixdocc, t.nrdocc, t.datadocc,
    sub.den_subunit, t.idx &apos;||sCursRef||gUserAlias||&apos;
  FROM TMP_LIST_COMPENS t
    INNER JOIN compens c ON c.codcompens = t.coddoc
    LEFT JOIN doccarnete carn ON carn.codcarnet = c.carnetdoc
    LEFT JOIN nsubunit sub ON sub.codsubunit = c.subunitatea
    LEFT JOIN ncont ncd ON ncd.codcont = t.codcontd
    LEFT JOIN ncont ncc ON ncc.codcont = t.codcontc&apos;||
    gSuplJoins;

  Umple_TMP_LIST_COMPENS;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_compens; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMPENSDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED727B92852B95228281BCB8AE8189303665A2EF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMPENSDOC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vCodDoc     COMPENS.CODCOMPENS%TYPE;

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      DC.SIMBOL SimbolCarnet, DC.SERIE SerieCarnet, DC.DENUMIRE DenumireCarnet, C.NRDOC, C.DATADOC,
      PD.DEN_PART PD_DEN, CFD.CODFISCAL PD_CIF, Decode(PD.PERSOANAFIZICA,1,NULL,PD.REGCOM) PD_REGCOM,
      SSD.OBS SSDObs, SSD.TELEFON SSDTelefon, SSD.FAX SSDFax, SSD.CODPOSTAL SSDCodPostal, SSD.CODFISCAL SSDCodFiscal, SSD.Email SSDEmail,
      GetAdresa(SSD.sector, SSD.strada, SSD.nr1, SSD.nr2, SSD.bloc, SSD.scara, SSD.etaj, SSD.apart, SSD.codpostal) SSDAdresa,
      GetAdresa(SSD.sector, SSD.strada, SSD.nr1, SSD.nr2, SSD.bloc, SSD.scara, SSD.etaj, SSD.apart, NULL         ) SSDAdresaNoCP,
      LSD.DEN_LOCALIT SSDLocalit, JSD.SIMBAUTO SSDSimbAuto, JSD.Den_Judet SSDJudet, TSD.Den_Tara SSDTara,
      PC.DEN_PART PC_DEN, CFC.CODFISCAL PC_CIF, Decode(PC.PERSOANAFIZICA,1,NULL,PC.REGCOM) PC_REGCOM,
      SSC.OBS SSCObs, SSC.TELEFON SSCTelefon, SSC.FAX SSCFax, SSC.CODPOSTAL SSCCodPostal, SSC.CODFISCAL SSCCodFiscal, SSC.Email SSCEmail,
      GetAdresa(SSC.sector, SSC.strada, SSC.nr1, SSC.nr2, SSC.bloc, SSC.scara, SSC.etaj, SSC.apart, SSC.codpostal) SSCAdresa,
      GetAdresa(SSC.sector, SSC.strada, SSC.nr1, SSC.nr2, SSC.bloc, SSC.scara, SSC.etaj, SSC.apart, NULL         ) SSCAdresaNoCP,
      LSC.DEN_LOCALIT SSCLocalit, JSC.SIMBAUTO SSCSimbAuto, JSC.Den_Judet SSCJudet, TSC.Den_Tara SSCTara
    FROM COMPENS C
      LEFT JOIN DOCCARNETE DC ON C.CARNETDOC = DC.CODCARNET

      LEFT JOIN NPART PD ON PD.CODPART = C.PARTD
      LEFT JOIN NPARTCODFISC CFD ON CFD.CODPART = C.PARTD AND CFD.PRINCIPAL = 1
      LEFT JOIN NAGENDA SSD ON SSD.CODPART = C.PARTD AND SSD.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSD.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT LSD ON LSD.CODLOCALIT = NVL(SSD.CODLOCALIT, 0)
      LEFT JOIN NJUDET JSD ON JSD.CODJUDET = NVL(LSD.CODJUDET, 0)
      LEFT JOIN NTARI TSD ON TSD.CODTARA = NVL(LSD.CODTARA, 0)

      LEFT JOIN NPART PC ON PC.CODPART = C.PARTC
      LEFT JOIN NPARTCODFISC CFC ON CFC.CODPART = C.PARTC AND CFC.PRINCIPAL = 1
      LEFT JOIN NAGENDA SSC ON SSC.CODPART = C.PARTC AND SSC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSC.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT LSC ON LSC.CODLOCALIT = NVL(SSC.CODLOCALIT, 0)
      LEFT JOIN NJUDET JSC ON JSC.CODJUDET = NVL(LSC.CODJUDET, 0)
      LEFT JOIN NTARI TSC ON TSC.CODTARA = NVL(LSC.CODTARA, 0)

    WHERE C.CODCOMPENS = vCodDoc
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                     v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                      v_rec.SerieCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                   v_rec.DenumireCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                    v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                     To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));

    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT DENUMIRE&apos;,                v_rec.PD_DEN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT CODFISCAL/CNP&apos;,           v_rec.PD_CIF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT REGISTRU COMERT&apos;,         v_rec.PD_REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL DENUMIRE&apos;,        v_rec.SSDObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL ADRESA&apos;,          v_rec.SSDAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL ADRESA FARA CP&apos;,  v_rec.SSDAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL LOCALITATE&apos;,      v_rec.SSDLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL TELEFON&apos;,         v_rec.SSDTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL FAX&apos;,             v_rec.SSDFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL JUDET&apos;,           v_rec.SSDSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL DENUMIRE JUDET&apos;,  v_rec.SSDJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL COD POSTAL&apos;,      v_rec.SSDCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL COD FISCAL&apos;,      v_rec.SSDCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL TARA&apos;,            v_rec.SSDTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTDEBIT SSOCIAL EMAIL&apos;,           v_rec.SSDEmail);

    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT DENUMIRE&apos;,               v_rec.PC_DEN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT CODFISCAL/CNP&apos;,          v_rec.PC_CIF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT REGISTRU COMERT&apos;,        v_rec.PC_REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL DENUMIRE&apos;,       v_rec.SSCObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL ADRESA&apos;,         v_rec.SSCAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL ADRESA FARA CP&apos;, v_rec.SSCAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL LOCALITATE&apos;,     v_rec.SSCLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL TELEFON&apos;,        v_rec.SSCTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL FAX&apos;,            v_rec.SSCFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL JUDET&apos;,          v_rec.SSCSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL DENUMIRE JUDET&apos;, v_rec.SSCJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL COD POSTAL&apos;,     v_rec.SSCCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL COD FISCAL&apos;,     v_rec.SSCCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL TARA&apos;,           v_rec.SSCTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTCREDIT SSOCIAL EMAIL&apos;,          v_rec.SSCEmail);


    EXIT;
  END LOOP;


END;



PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;tmp_list_compens t, compens c, doccarnete carn, nsubunit sub&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NRDOC,DATADOC,DENCARNET,SIMBCARNET,SERCARNET,
    EXPLD,Partd,CONTD,VALD,RESTD,CURSD,TVAD,OBSD,
    EXPLC,PartC,CONTC,VALC,RESTC,CURSC,TVAC,OBSC,
    IDX&apos;||gUserFields||&apos;)
  SELECT
    c.nrdoc, c.datadoc, carn.denumire, carn.simbol, carn.serie,
    t.expld, t.partd, ncd.simbol, t.vald, t.restd, t.cursd, t.tvad, c.obsd,
    t.explc, t.partc, ncc.simbol, t.valc, t.restc, t.cursc, t.tvac, c.obsc,
    t.idx &apos;||gUserAlias||&apos;
  FROM TMP_LIST_COMPENS t
    INNER JOIN compens c ON c.codcompens = t.coddoc
    LEFT JOIN doccarnete carn ON carn.codcarnet = c.carnetdoc
    LEFT JOIN nsubunit sub ON sub.codsubunit = c.subunitatea
    LEFT JOIN ncont ncd ON ncd.codcont = t.codcontd
    LEFT JOIN ncont ncc ON ncc.codcont = t.codcontc&apos;||
    gSuplJoins;

  PKG_LIST_BASE_COMPENS.Umple_TMP_LIST_COMPENS (vCodDoc);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  processparams;
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_compensdoc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMREPRACDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E53D5D40BC0330D104E07A9446DAE23B6497C147</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_COMREPRACDOC IS

  vCodDoc     NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;COMANDA C, COMANDA2 C2, COMANDA3 C3, NPART NP, NINTERVENTIIAUTO NIA &apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
     operatie,
     lucrare,
     observatii,
     platitor,
     interventie,
     garantie, 
     executat&apos;||gUserFields||&apos;)
  SELECT
     no.denumire operatie,
     tipl.denumire lucrare,
     c2.obs observatii,
     nvl(np.den_part,&apos;&apos;...nedefinit&apos;&apos;) platitor,
     nia.denumire interventie,
     case when c2.garantie=1 then &apos;&apos;Da&apos;&apos; else &apos;&apos;Nu&apos;&apos; end garantie, 
     case when c3.executat=1 then &apos;&apos;Da&apos;&apos; else &apos;&apos;Nu&apos;&apos; end executat&apos;||gUserAlias||&apos;
  FROM noper no 
    INNER JOIN comanda3 c3 on no.codop=c3.codoperatie
    INNER JOIN comanda2  c2 on c2.CODCOMANDA2=c3.CODCOMANDA2
    INNER JOIN comanda c on c.codcomanda=c3.codcomanda
    INNER JOIN tiplucrarisa tipl on tipl.CODTIPLUCRARE=c2.CODLUCRARE
    LEFT JOIN ninterventiiauto nia on nia.codinterventiiauto=c2.codinterventie
    LEFT JOIN npart np on np.codpart=c2.codpart
    &apos;||gSuplJoins||&apos;
  WHERE c.CODCOMANDA = &apos;||vCodDoc ;

  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  pkg_list_base_ComRepRacDoc.add_list_params;

  COMMIT;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
 
 For v_rec IN (
    SELECT P.Den_part, RAC.DataStart, RAC.DataStop,G.Den_Gest AgentiaPlecare, C.nrdoc, C.Datadoc
    FROM comanda c
        INNER JOIN NPART P on P.CodPart = C.Partener
        INNER JOIN RAC_REZ RAC on RAC.CodComanda = C.CodcOMANDA
        LEFT JOIN NGEST G on RAC.CODGESTSURSA = G.CodGEST
     where C.CODCOMANDA = vCodDoc
  ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Comanda_PARTENER&apos;,           v_rec.DEN_PART);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Rac_DataStart&apos;,              v_rec.DataStart);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Rac_DataStop&apos;,               v_rec.DataStop);
      pkg_list_Struct.ADAUGA_PARAM(&apos;G_AgentiaPlecare&apos;,           v_rec.AgentiaPlecare);
    
      EXIT;
    END LOOP;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_COMREPRACDOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_COMREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D40CE7ABB90BB81716C77DB6C33F863FFA992DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_comrez IS

  vCodComanda COMANDA.CODCOMANDA%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodComanda IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodComanda := pCodComanda;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
  vFiltru  VARCHAR2(1000);
  sSJoin   VARCHAR2(1000);
BEGIN
  gSuplCols := 
    &apos;comanda c, comanda1 c1, nartobj nao, nart na, num num, num1 num1, num umspec, nartamb aa, npart prod, nclasea ca, nclaseas cs, nartcli ac, nechiv e, &apos;||
    &apos;grechiv gre, nart1 na1, ntva1 t1, rezervats rez, nirstoc ns, npart f, nir nir, nirser nse, nserii nser, nlocatii loc, ngest gest, ioart ioa, oferta1 o1, &apos;||
    &apos;comanda1 cf1, comanda cf, npart cfp&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;,    &apos;CC&apos;,   &apos;CC.CODCOMANDA = C1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;,   &apos;CC&apos;,   &apos;CC1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCARSUPART&apos;, &apos;CSA&apos;,  &apos;CSA.CODCARSUPART = NAO.CODCARACT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vCodComanda IS NOT NULL THEN
    vFiltru := &apos;
    AND c.codcomanda = &apos;||vCodComanda;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTCOM, CANTACC, CANTREST, PRET, VALCOM, VALACC, VALREST, TERM,
    ADAOS, DISC, PROCTVA, VALCUTVA,
    OBSART, OBSCOM, CodIntern, CodExtern, DenClasaA, SimbClasaA, Masa, Volum, CodVamal,Prod,
    DenLaCli, CodLaCli, CodListat,
    UMPrinc, Paritate, UM1, CANTUM1, UMMasa, UMDimA, UMDimB, UMDimC, DenClaseAS,
    PretAchiz, PretInreg, Serie, TG, DataAchiz, Furnizor, DataIntr, CantRez, Locatie, D1, D2, D3 &apos;||gUserFields||&apos;)
  SELECT
    nao.denumire, num1.den_um1, c1.cantcomandat, c1.cantacceptat, c1.restacceptat, c1.pu,
    c1.cantcomandat * c1.pu, c1.cantacceptat * c1.pu, c1.restacceptat * c1.pu, c1.termen,
    c1.addim, c1.procdisc, t1.procent, c1.cantcomandat * c1.pu * (100 + t1.procent) / 100,
    c1.obs, c.obs, nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, nao.codvamal, prod.den_part,
    NVL(ac.denumire,nao.denumire), NVL(ac.codextern,nao.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),
    num.den_um, num1.paritate, umspec.den_um, c1.cantum1, aa.masa, aa.lungime, aa.latime, aa.inaltime, cs.den_claseas,
    ROUND(NS.PRET - NVL(NS.ADAOS, 0), 4), ns.pret, nser.serie, nvl(nse.tg,NS.TG), ns.dataachiz, coalesce(cfp.den_part,f.den_part), nir.datanir, NVL(rez.rest,0), loc.denumire,
    C1.D1, C1.D2, C1.D3 &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1  c1     ON c1.codcomanda   = c.codcomanda
    INNER JOIN nartobj   nao    ON nao.codobiect   = c1.codobiect
    INNER JOIN nart      na     ON na.codarticol   = nao.codarticol
    INNER JOIN num              ON num.codum       = na.um
    INNER JOIN num1             ON num1.codum1     = c1.umsec
    LEFT  JOIN num       umspec ON umspec.codum    = na.um1
    LEFT  JOIN nartamb   aa     ON aa.codobiect    = nao.codobiect AND aa.umsec = c1.umsec
    LEFT  JOIN npart     prod   ON prod.codpart    = nao.codproducator
    LEFT  JOIN nclasea   ca     ON ca.codclasea    = na.clasa
    LEFT  JOIN nclaseas  cs     ON cs.codclaseas   = na.clasastatist
    LEFT  JOIN nartcli   ac     ON ac.codobiect    = c1.codobiect AND ac.codpart = c.partener
    LEFT  JOIN nechiv    e      ON e.codobiect     = c1.codobiect
    LEFT  JOIN grechiv   gre    ON gre.codgrechiv  = e.codgrupa
    LEFT  JOIN nart1     na1    ON na1.codarticol  = nao.codarticol AND (c.an*12+c.luna) between na1.alstart and na1.alstop
    LEFT  JOIN ntva1     t1     ON t1.codtva       = na1.codtva     AND (c.an*12+c.luna) between  t1.alstart and  t1.alstop
    LEFT  JOIN rezervats rez    ON rez.codcomanda1 = c1.codcomanda1
    LEFT  JOIN nirstoc   ns     ON rez.codnirstoc  = ns.codnirstoc
    LEFT  JOIN npart     f      on ns.furn         = f.codpart
    LEFT  JOIN nir              on ns.codnir       = nir.codnir
    LEFT  JOIN nirser    nse    ON rez.codnirser   = nse.codnirser
    LEFT  JOIN nserii    nser   ON nse.codserie    = nser.codserie
    LEFT  JOIN nlocatii  loc    ON ns.codlocatie   = loc.codlocatie
    LEFT  JOIN ngest     gest   ON gest.codgest    = nir.gest
    LEFT  JOIN ioart     ioa    ON ioa.codioart    = ns.codioart
    LEFT  JOIN oferta1   o1     ON o1.codoferta1   = c1.codsursa
    LEFT  JOIN COMANDA1  CF1    ON cf1.codcomanda1 = rez.codcomanda1f
    left  join comanda   cf     on cf.codcomanda   = cf1.codcomanda 
    left  join npart     cfp    on cfp.codpart     = cf.partener&apos;||
    sSJoin||
    gSuplJoins||&apos;
  WHERE 1 = 1 &apos;||
  vFiltru||&apos;
  ORDER BY c1.indexlocal&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_comrez;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BDC9F46A9161609883C9EEDB2E365DEC1A2E5EA7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONST IS

  vToateConstGen  BOOLEAN ;
  vToateConstUt   BOOLEAN ;
  p_AL            INTEGER; 

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);


PROCEDURE SETPARAMS(  pToateConstGen IN NUMBER DEFAULT 1,
                      pToateConstUt  IN NUMBER DEFAULT 1,
                      V_CODJOB1      IN NUMBER DEFAULT 0 )
IS
  xFin   INTEGER;
  dDataS DATE;
  dDataF DATE;
BEGIN
  p_AL := PKG_GLOBALS.AnLunaLucru;
  xFin := p_AL;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,p_AL,xFin);
  END IF;

  vToateConstGen    := Coalesce(pToateConstGen, 1) = 1 ;
  vToateConstUt     := Coalesce(pToateConstUt,  1) = 1;
END;

procedure ProcessList(TmpName IN varchar2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) is
  sInsert   varchar2(10000);
  vAuxCond  varchar2(5000);
BEGIN
  gSuplCols := &apos;categconst cc, CONST1 c1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos; || TmpName ||&apos;(
    ANSTART, LUNASTART, INDEXLOCAL, SIMBOL, DENUMIRE, DENCATEGORIE, TIPCATEG, DENUSER, DENGRUP, VALOARE&apos;||gUserFields||&apos;)
  SELECT cl.AnStart, cl.LunaStart, c1.IndexLocal, c1.simbol, c1.Denumire,cc.Denumire,
    DECODE(cc.tipcateg,&apos;&apos;G&apos;&apos;,&apos;&apos;Globala&apos;&apos;,&apos;&apos;U&apos;&apos;,&apos;&apos;Utilizator&apos;&apos;),
    DECODE(cc.tipcateg,&apos;&apos;U&apos;&apos;,WINMADMIN.PKG_USERFIRME.GetUserName(cl.USerId),&apos;&apos; &apos;&apos;),
    DECODE(cc.tipcateg,&apos;&apos;U&apos;&apos;,WINMADMIN.PKG_USERFIRME.Get_Nume_Grup_User(cl.USerId),&apos;&apos; &apos;&apos;),
    pkg_categconst.GetValAfis(c1.Tip, cl.CodConstLuna) Valoare&apos;||gUserAlias||&apos;
  FROM CATEGCONST cc
    INNER JOIN CONST1 c1 ON c1.codcateg = cc.codcateg
    INNER JOIN (
      SELECT CodConst1, UserId,
        --Count(1) OVER (PARTITION BY CodConst1) Nr,
        max(codconstluna) keep (dense_rank Last order by AnStart, LunaStart) codconstluna,
        max(AnStart)      keep (dense_rank Last order by AnStart, LunaStart) AnStart,
        max(LunaStart)    keep (dense_rank Last order by AnStart, LunaStart) LunaStart
      FROM CONSTLUNA
      WHERE UserId IS NOT NULL
        AND AnStart * 12 + LunaStart &lt;= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
      GROUP BY CodConst1, UserId
    ) cl ON cl.CodConst1 = c1.codconst1&apos;||gSuplJoins||&apos;
  WHERE (cc.tipcateg = &apos;&apos;G&apos;&apos; OR cl.USerId &gt; 0 /*OR cl.Nr = 1 -- de vazut daca trebuie si asta*/) &apos;;

  IF (not vToateConstGen) OR (not vToateConstUt)
  THEN
    IF vToateConstGen
    THEN vAuxCond := &apos;(cc.tipcateg = &apos;&apos;G&apos;&apos;)&apos;;
    ELSE vAuxCond := &apos;(cc.tipcateg = &apos;&apos;G&apos;&apos; AND cc.codcateg IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CONSTG&apos;&apos;))&apos;;
    END IF;

    vAuxCond := vAuxCond || &apos; OR &apos;;

    IF vToateConstUt
    THEN vAuxCond := vAuxCond||&apos;(cc.tipcateg = &apos;&apos;U&apos;&apos;)&apos;;
    ELSE vAuxCond := vAuxCond||&apos;(cc.tipcateg = &apos;&apos;U&apos;&apos; AND cc.codcateg IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CONSTU&apos;&apos;))&apos;;
    END IF;

    sInsert := sInsert || &apos;
    AND (&apos;|| vAuxCond ||&apos;)&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


end Pkg_List_Base_Const;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONSUM_PROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85376D4A66412FFFCD6145BC3CB8D73763022868</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONSUM_PROD IS

  p_flgAllArt  NUMBER(1);
  p_Sursa      NUMBER(1);
  p_Tip        NUMBER(1);
  p_Stoc       NUMBER(1);
  p_flgAllGest NUMBER(1);
  p_PMP        NUMBER(1);
  p_Inactive   number(1);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GETLASTPRETACHIZ(aCodObiect IN NUMBER) RETURN NUMBER
IS
 PRETACHIZ NUMBER(20, 7) := 0;
BEGIN
  for v_rec in (SELECT nvl((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) -
                  CASE
                    WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
                    ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0) / U1.PARITATE)
                  END) * nvl(u1.Paritate,0) , 0) aPretAchiz, N.DataNir
   FROM
     NIR N,
     NIRSTOC NS
     LEFT JOIN NUM1 u1 on u1.codum1 = ns.umsec,
     NGEST G
   WHERE
     NS.CODOBIECT = aCODOBIECT
     AND NS.CODNIR = N.CODNIR
     AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
     AND OPERAT = 1
     AND ANULAT = 0
     AND G.CODGEST = N.GEST
     AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
   ORDER BY N.DATANIR DESC, N.DATACREARE DESC ) loop
     PretAchiz := v_rec.aPretAchiz;
     Exit;
  end loop;

  RETURN PRETACHIZ;

END;

FUNCTION GET_PMP_OBIECT (aCodObiect in number, aCodSubunit in Number, aAnLuna in number DEFAULT 0 ) return number is
  iPMP          NUMBER(20,7) := 0;
  iPMPVal       NUMBER(20,7) := 0;
  iPMPPrec      NUMBER(20,7) := 0;
  iPMPPrecVal   NUMBER(20,7) := 0;

  aCANTINTR     NUMBER(20,7) := 0;
  aVALINTR      NUMBER(20,7) := 0;
  aVALVALUTA    NUMBER(20,7) := 0;
  CANTINTRPREC  NUMBER(20,7) := 0;
  VALINTRPREC   NUMBER(20,7) := 0;
  VALVALUTAPREC NUMBER(20,7) := 0;
  IAN           NUMBER(4);
  ILUNA         NUMBER(2);
  AnLuna        number(20);
	cTRANSFPMP    NUMBER;
	xTRANSFPMP    VARCHAR2(5);
BEGIN
 -- pkg_globals.SetLunaLucru(2008,8);
 AnLuna := aAnLuna;
  IF AnLuna = 0 THEN
    AnLuna := pkg_globals.AnLunaLucru;
  END IF  ;

  if trunc(AnLuna/12) = AnLuna/12 then
    IAN := trunc(AnLuna/12) - 1;
    ILUNA := 12;
  else
    IAN := trunc(AnLuna/12) - 1;
    ILUNA := AnLuna - IAN*12;
  end if;

  pkg_globals.SetLunaTemp(IAN, ILUNA);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);
  BEGIN
    SELECT SUM(CANTINTR),  SUM(VALINTR), SUM(VALVALUTA) INTO CANTINTRPREC, VALINTRPREC , VALVALUTAPREC
    FROM PMPLUNA
    WHERE CodObiect  = aCodObiect
      AND CodSubunit = Decode(aCodSubunit,1,CodSubunit,aCodSubunit)
      AND (an*12 + luna) = (IAN * 12 + ILUNA - 1);
  EXCEPTION
    WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; VALVALUTAPREC := 0;
  END;

  IF Nvl(CANTINTRPREC,0) &lt;&gt; 0 THEN
    iPMPPrec    := Round(VALINTRPREC   / CANTINTRPREC,7);
    iPMPPrecVal := Round(VALVALUTAPREC / CANTINTRPREC,7);
  END IF;

  BEGIN
		SELECT Sum(VALINTR), Sum(CANTINTR), sum(VALVALUTA) INTO aVALINTR, aCANTINTR, aVALVALUTA
    FROM V_PMP_LUNA
    WHERE CodObiect  = aCodObiect
      AND CodSubunit = Decode(aCodSubunit,1,CodSubunit,aCodSubunit);
  EXCEPTION
    WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
  END;

  aVALINTR   := Nvl(aVALINTR  ,0) + NVL(VALINTRPREC,  0);
  aCANTINTR  := Nvl(aCANTINTR ,0) + Nvl(CANTINTRPREC, 0);
  aVALVALUTA := Nvl(aVALVALUTA,0) + NVL(VALVALUTAPREC,0);
  IF aCANTINTR &lt;&gt; 0 THEN
    iPMP    := Round(aVALINTR   / aCANTINTR,7);
    iPMPVal := Round(aVALVALUTA / aCANTINTR,7);
  END IF;

  RETURN iPMP;
END;


FUNCTION GetPretMinStoc(aCodObiect IN NUMBER) RETURN NUMBER IS
aMin NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT
      nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) -
      CASE
        WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
        ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0))
      END)) , 0)
    INTO aMin
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND NS.Codobiect = aCodObiect AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
  EXCEPTION WHEN OTHERS THEN
    aMin := 0;
  END;

  if aMin = 0 then
    BEGIN
      SELECT
        nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) -
        CASE
          WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
          ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR)
        END)),0)
      INTO aMin
      FROM NIRSTOC NS
        INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      WHERE G.Tip &lt;&gt; 4 AND NS.Codobiect = aCodObiect AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
    EXCEPTION WHEN OTHERS THEN
      aMin := 0;
    END;
  end if;

  RETURN aMin;

END;

FUNCTION GetPretMinOferta(aCodObiect IN NUMBER) RETURN NUMBER IS
aMin NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT Min(O1.PRET)
    INTO aMin
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
    WHERE O1.CODOBIECT = aCodObiect and pkg_oferta.OfertaVal(O.CODOFERTA) = 1
      AND O.SUBUNITATEA = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
  EXCEPTION WHEN OTHERS THEN
    aMin := 0;
  END;
  RETURN aMin;
END;

FUNCTION GetPretMaxStoc(aCodObiect IN NUMBER) RETURN NUMBER IS
aMax NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT
      nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) -
      CASE
        WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
        ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR)
      END)),0)
    INTO aMax
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND NS.Codobiect = aCodObiect AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
  EXCEPTION WHEN OTHERS THEN
    aMax := 0;
  END;

  if aMax = 0 then
    BEGIN
      SELECT
        nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) -
        CASE
          WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
          ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR)
        END)),0)
      INTO aMax
      FROM NIRSTOC NS
        INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      WHERE G.Tip &lt;&gt; 4 AND NS.Codobiect = aCodObiect AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
    EXCEPTION WHEN OTHERS THEN
      aMax := 0;
    END;
  end if;

  RETURN aMax;
END;

FUNCTION GetPretMaxOferta(aCodObiect IN NUMBER) RETURN NUMBER IS
aMax NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT Max(O1.PRET)
    INTO aMax
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
    WHERE O1.CODOBIECT = aCodObiect and pkg_oferta.OfertaVal(O.CODOFERTA) = 1
      AND O.SUBUNITATEA = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate);
  EXCEPTION WHEN OTHERS THEN
    aMax := 0;
  END;
  RETURN aMax;
END;

PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Sursa IN NUMBER, v_Tip IN NUMBER, v_Stoc in NUMBER DEFAULT 0, v_flgAllGest in NUMBER DEFAULT 0, v_PMP in number default 0, v_Inactive in NUMBER DEFAULT 0) IS
BEGIN
  p_flgAllArt  := v_flgAllArt;
  p_Sursa      := v_Sursa;
  p_Tip        := v_Tip;
  p_Stoc       := v_Stoc;
  p_flgAllGest := v_flgAllGest;
  p_PMP        := v_PMP;
  p_Inactive   := v_inactive;
END;

function GetAllArt return number is
begin
  return p_flgAllArt;
end;

function GetSursa return number is
begin
  return p_Sursa;
end;

function GetTip return number is
begin
  return p_Tip;
end;

function GetStoc return number is
begin
  return p_Stoc;
end;

function GetAllGest return number is
begin
  return p_flgAllGest;
end;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  sSelect     VARCHAR2(20000);
  AnLunaLucru NUMBER(20);
  sSelect0    VARCHAR2(20000);
  sSelect1    VARCHAR2(20000);
  gStocField  varchar2(50);
  gStocAlias  varchar2(50);
  gJoinStoc   varchar2(500);
  vUserID     NUMBER(20);
  vSubunitatea NUMBER(20);
  sJoinPMP    varchar2(500);
  active      varchar2(100);
  activePC    varchar2(100);
  anulatPC    varchar2(100);
BEGIN
  AnLunaLucru := PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU;
  vUserID := pkg_globals.GETUSERID;
  vSubunitatea := PKG_GLOBALS.GETSUBUNITATE;
  if vSubunitatea = 1 then vSubunitatea := 2; end if;
  gStocField := &apos; &apos;;
  gStocAlias := &apos; &apos;;
  gJoinStoc  := &apos; &apos;;
  if p_Stoc = 1 then
    gStocAlias := &apos; ,Stoc &apos;;
    gStocField := &apos; ,nvl(tmpp.CantC,0) &apos;;
    gJoinStoc  := &apos;
                   left join tmp_cmd1 tmpp on tmpp.codobiect = mat.codobiect AND TMPP.USERID = &apos;||VUSERID||&apos; AND TMPP.TIP = &apos;&apos;STOC&apos;&apos; &apos;;
  end if;

  pkg_list_base_utils.make_config_luna_ioart;

  gSuplCols := &apos;NARTOBJ OBJP, NARTOBJ OBJC, PRODCOMP PC, PRODMAT MAT, PRODMAT MATS, NCLASEA CLSCOMP, NGEST SECTIE, NARTOBJSUBUNIT OBJCS, NARTOBJSUBUNIT OBJPS&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTP&apos;, &apos;OEXTP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRP&apos;, &apos;OATRP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTC&apos;, &apos;OEXTC.CODOBIECT = OBJC.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRC&apos;, &apos;OATRC.CODOBIECT = OBJC.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  if p_Inactive = 0 then
    active   := &apos; and nvl(p.activ, 0) = 1&apos;;
    activePC := &apos; and nvl(pc.inactiv, 0) = 0&apos;;
    anulatPC := &apos; and nvl(pc.anulat, 0) = 0&apos;;
  else
    active   := &apos;&apos;;
    activePC := &apos;&apos;;
    anulatPC := &apos;&apos;;
  end if;
  if p_PMP &gt; 0 then
    sJoinPMP := CHR(13)||&apos;LEFT JOIN PMPLUNA PMP ON MAT.CODOBIECT = PMP.CODOBIECT AND PMP.CODSUBUNIT = &apos;||vSubunitatea||&apos; AND PMP.AN*12+PMP.LUNA = &apos;||AnLunaLucru||CHR(13);
  else
    sJoinPMP := &apos;&apos;;
  end if;

  delete tmp_cmd1 where userid = vUserID;
  if p_flgAllArt = 1 then
    delete tmp_prodcomp_man where userid = vuserid;
    delete tmp_proiectnod_man where userid = vUserID;
    if p_Tip = 0 then
      insert into tmp_prodcomp_man (codprodcomp, cant, pret, userid)
      select codprodcomp, cant, Pret, vUserID
      from prodcomp
      where nvl(ascuns,0) = 0;
      INSERT INTO tmp_cmd1(CODOBIECT, TIP, USERID)
      SELECT DISTINCT MAT.CODOBIECT, &apos;MAT&apos;, VUSERID
      FROM tmp_prodcomp_man TMP
           INNER JOIN PRODMAT MAT ON MAT.CODPRODCOMP = TMP.CODPRODCOMP
      where tmp.userid = vuserid;
    else
      if p_Inactive = 0 then
        insert into tmp_proiectnod_man(codproiectnod,necesar,cant,codobiect,codproiect,userid)
        select pn.codproiectnod,pn.cant,pn.cant,pn.codobiect,pn.codproiect,vUserID
        from proiectnod pn
             inner join proiect p on p.codproiect = pn.codproiect
        where pn.nodoriginal = 0 and p.activ = 1;
      else
        insert into tmp_proiectnod_man(codproiectnod,necesar,cant,codobiect,codproiect,userid)
        select pn.codproiectnod,pn.cant,pn.cant,pn.codobiect,pn.codproiect,vUserID
        from proiectnod pn
             inner join proiect p on p.codproiect = pn.codproiect
        where pn.nodoriginal = 0;
      end if;
      INSERT INTO tmp_cmd1(CODOBIECT, TIP, USERID)
      SELECT DISTINCT MAT.CODOBIECT, &apos;MAT&apos;, VUSERID
      FROM TMP_PROIECTNOD_MAN TMP
           INNER JOIN PROIECTNOD PN ON PN.CODPROIECT = TMP.CODPROIECT AND PN.NODORIGINAL &gt; 0
           INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
      where tmp.userid = vuserid;
    end if;
    COMMIT;
  else
    if p_Tip = 0 then
      INSERT INTO tmp_cmd1(CODOBIECT, TIP, USERID)
      SELECT DISTINCT MAT.CODOBIECT, &apos;MAT&apos;, VUSERID
      FROM tmp_prodcomp_man TMP
           INNER JOIN PRODMAT MAT ON MAT.CODPRODCOMP = TMP.CODPRODCOMP
      where tmp.userid = vuserid;
    else
      INSERT INTO tmp_cmd1(CODOBIECT, TIP, USERID)
      SELECT DISTINCT MAT.CODOBIECT, &apos;MAT&apos;, VUSERID
      FROM TMP_PROIECTNOD_MAN TMP
           INNER JOIN PROIECTNOD PN ON PN.CODPROIECT = TMP.CODPROIECT AND PN.NODORIGINAL &gt; 0
           INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
      where tmp.userid = vuserid;
    end if;
  end if;

  if p_Stoc = 1 then
    if p_flgAllGest = 1 then
      if p_Tip = 0 then
        INSERT INTO tmp_cmd1 (CODOBIECT, CANTC, TIP, USERID)
        SELECT CODOBIECT, sum(REST), &apos;STOC&apos;, VUSERID FROM (
        SELECT
          NS.CODOBIECT,
          CASE
            WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST
            ELSE NSE.REST
          END REST
        FROM
          NIRSTOC NS
          INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST and (G.CODSUBUNIT = vSubunitatea OR vSubunitatea = 1)
          INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = &apos;MAT&apos;
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE
          IO.MG &lt;&gt; 5)
        GROUP BY CODOBIECT;
      else
        INSERT INTO tmp_cmd1 (CODOBIECT, CANTC, TIP, USERID)
        SELECT CODOBIECT, sum(REST), &apos;STOC&apos;, VUSERID FROM (
        SELECT
          NS.CODOBIECT,
          CASE
            WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST
            ELSE NSE.REST
          END REST
        FROM
          NIRSTOC NS
          INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST and (G.CODSUBUNIT = vSubunitatea OR vSubunitatea = 1)
          INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = &apos;MAT&apos;
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE
          IO.MG &lt;&gt; 5)
        GROUP BY CODOBIECT;
      end if;
    else
      if p_Tip = 0 then
        INSERT INTO tmp_cmd1(CODOBIECT, CANTC, TIP, USERID)
        SELECT CODOBIECT, sum(REST), &apos;STOC&apos;, VUSERID FROM (
        SELECT
          NS.CODOBIECT,
          CASE
            WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST
            ELSE NSE.REST
          END REST
        FROM
          NIRSTOC NS
          INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST
          INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = &apos;MAT&apos;
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE
          EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGESTSTOC&apos; AND VALOARE = G.CODGEST)
          and IO.MG &lt;&gt; 5
        )
        GROUP BY CODOBIECT;
      ELSE
        INSERT INTO tmp_cmd1(CODOBIECT, CANTC, TIP, USERID)
        SELECT CODOBIECT, sum(REST), &apos;STOC&apos;, VUSERID FROM (
        SELECT
          NS.CODOBIECT,
          CASE
            WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST
            ELSE NSE.REST
          END REST
        FROM
          NIRSTOC NS
          INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST
          INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = &apos;MAT&apos;
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE
          EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGESTSTOC&apos; AND VALOARE = G.CODGEST)
          and IO.MG &lt;&gt; 5
        )
        GROUP BY CODOBIECT;
      END IF;
    end if;
  end if;

  IF p_Sursa = 0 THEN
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0)) END)) , 0) Pret, NS.CODOBIECT,
           &apos;PMIN&apos;, VUSERID
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND G.CODSUBUNIT = decode(vSubunitatea,1,2,vSubunitatea)
    GROUP BY NS.CODOBIECT;
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0)) END)) , 0) Pret, NS.CODOBIECT,
           &apos;PMIN0&apos;, vUserID
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &lt;= 0 AND G.CODSUBUNIT = decode(vSubunitatea,1,2,vSubunitatea)
    GROUP BY NS.CODOBIECT;
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0)) END)) , 0) Pret, NS.CODOBIECT,
           &apos;PMAX&apos;, vUserID
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND G.CODSUBUNIT = decode(vSubunitatea,1,2,vSubunitatea)
    GROUP BY NS.CODOBIECT;
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0)) END)) , 0) Pret, NS.CODOBIECT,
           &apos;PMAX0&apos;, vUserID
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &lt;= 0 AND G.CODSUBUNIT = decode(vSubunitatea,1,2,vSubunitatea)
    GROUP BY NS.CODOBIECT;
  ELSE
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT Min(O1.PRET) pret, O1.CodObiect, &apos;PRETMIN&apos;, VUSERID
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = O1.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE (ANLUNALUCRU &lt;= Extract(MONTH FROM nvl(O.Dataend, to_date(&apos;01.01.2899&apos;,&apos;dd.mm.yyyy&apos;)))+12*Extract(Year FROM nvl(O.Dataend, to_date(&apos;01.01.2899&apos;,&apos;dd.mm.yyyy&apos;))))
      AND (ANLUNALUCRU &gt;= Extract(MONTH FROM nvl(O.Datastart, to_date(&apos;01.01.1899&apos;,&apos;dd.mm.yyyy&apos;)))+12*Extract(Year FROM nvl(O.Datastart, to_date(&apos;01.01.1899&apos;,&apos;dd.mm.yyyy&apos;))))
      AND O.SUBUNITATEA = decode(vSubunitatea,1,2,vSubunitatea) AND O.TIPDOC = 51
    GROUP BY O1.CodObiect;
    insert into tmp_cmd1 (cantc, codobiect, tip, userid)
    SELECT Min(O1.PRET) pret, O1.CodObiect, &apos;PRETMAX&apos;, VUSERID
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
      INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = O1.CODOBIECT AND TMP.TIP = &apos;MAT&apos; AND TMP.USERID = VUSERID
    WHERE (ANLUNALUCRU &lt;= Extract(MONTH FROM nvl(O.Dataend, to_date(&apos;01.01.2899&apos;,&apos;dd.mm.yyyy&apos;)))+12*Extract(Year FROM nvl(O.Dataend, to_date(&apos;01.01.2899&apos;,&apos;dd.mm.yyyy&apos;))))
      AND (ANLUNALUCRU &gt;= Extract(MONTH FROM nvl(O.Datastart, to_date(&apos;01.01.1899&apos;,&apos;dd.mm.yyyy&apos;)))+12*Extract(Year FROM nvl(O.Datastart, to_date(&apos;01.01.1899&apos;,&apos;dd.mm.yyyy&apos;))))
      AND O.SUBUNITATEA = decode(vSubunitatea,1,2,vSubunitatea) AND O.TIPDOC = 51
    GROUP BY O1.CodObiect;
  END IF;

  delete tmp_cmd where userid = vUserID;
  sSelect := &apos;INSERT INTO tmp_cmd(codobiect,D1,tip,UserID)&apos;||chr(13)||
             &apos;SELECT NS.CODOBIECT, MAX(NS.CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY NS.DATAACHIZ, NS.CODNIRSTOC) CODNIRSTOC,&apos;&apos;ULT&apos;&apos;,&apos;||vUserID||CHR(13)||
             &apos;FROM (SELECT NS.CODNIRSTOC,NS.CODNIR,NS.FURN,NS.CODNIRSTOCPARINTE,NS.CODOBIECT,NS.DATAACHIZ &apos;||CHR(13)||
             &apos;      FROM NIRSTOC NS &apos;||CHR(13)||
             &apos;           INNER JOIN tmp_cmd1 TMP ON TMP.CODOBIECT = NS.CODOBIECT AND TMP.TIP = &apos;&apos;MAT&apos;&apos; AND TMP.USERID = &apos;||VUSERID||CHR(13)||
             &apos;      WHERE NOT NS.DATAACHIZ IS NULL) NS &apos;||CHR(13)||
             &apos;     INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||chr(13)||
             &apos;     INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||chr(13)||
             &apos;WHERE NS.FURN &gt; 0 AND Nvl(NS.CODNIRSTOCPARINTE,0) = 0 AND N.TIPNIR IN (1,2,3,4,5,6) GROUP BY NS.CODOBIECT&apos;;
    EXECUTE IMMEDIATE sSelect;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos; (
    SysCod, NAV_CODDOC, NAV_TIPDOC, PR_ART, PR_UM, PR_UM1, PR_CANT, PR_PRET, PR_Data, COMP_ART, COMP_PARINTE, COMP_UM, COMP_UM1, COMP_CANT, COMP_PRET, COMP_TIP,
    EV_Pret_Sursa_min, EV_val_min, EV_Pret_Sursa_max, EV_val_max, EV_Pret_Sursa_med, EV_val_med, EV_Pret_Sursa_PMP, EV_val_PMP, Necesar, Activa, PR_CANT_SELECTATA,
    D1, D2, D3, Tip, CLSP, PR_PRET_REF, COMP_PRET_REF, NIVEL, ORDINE, PR_PRET_IMP, NOD, LotOptim, PretAchizU&apos;||gStocAlias||gUserFields||&apos;)&apos;;

  if p_Tip = 0 then
    sSelect0 := &apos;
    SELECT
      PC.CODPRODCOMP, PC.CODPRODCOMP, 504, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, TMP.Cant, TMP.Pret, PC.Data, OBJC.Denumire, OBJP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, MAT.Cant, nvl(MAT.Pret,0),
      case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end,
      case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end,
      MAT.Cant * case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end,
      case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end,
      MAT.Cant * case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end,
      (case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end +case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end) / 2,
      MAT.Cant * (case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end +case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end) / 2,&apos;;
      if p_PMP &gt; 0 then
        sSelect0 := sSelect0||&apos;
        PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;),
        MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;), &apos;;
      else
        sSelect0 := sSelect0||&apos;
        0,
        0, &apos;;
      end if;
      sSelect0 := sSelect0||&apos;
      TMP.Cant / PC.Cant * MAT.Cant,
      case when PC.Inactiv = 1 then &apos;&apos;Inactiva&apos;&apos; else &apos;&apos;Activa&apos;&apos; end,
      TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Reteta&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA, 1 NIVEL, MAT.IndexLocal, PM.lei, LPAD(MAT.IndexLocal, 2, &apos;&apos;0&apos;&apos;), PC.CANT,
      NSU.PRET- NVL(NSU.ADAOS,0) &apos;||gStocField||gUserAlias||&apos;
    FROM
      PRODCOMP PC
      INNER JOIN TMP_PRODCOMP_MAN TMP ON PC.CodProdComp = TMP.CodProdComp and tmp.userid = &apos;||vUserID||&apos;
      INNER JOIN PRODMAT MAT  ON PC.CODPRODCOMP = MAT.CODPRODCOMP
      INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST AND PG.CODPRODCOMP = PC.CODPRODCOMP
      INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
      INNER JOIN NARTOBJ OBJP ON PC.CODOBIECT = OBJP.CODOBIECT
      INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
      INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
      INNER JOIN NARTOBJ OBJC ON MAT.CODOBIECT = OBJC.CODOBIECT
      INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
      INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
      left join NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect
                                        and (OBJCS.codgest is null or OBJCS.codgest = 0)
                                        and objcs.subunitate = &apos;||vSubunitatea||&apos;
      left join NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect
                                     and (OBJPS.codgest is null or OBJPS.codgest = 0)
                                     and objps.subunitate = &apos;||vSubunitatea||&apos;
      LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = &apos;||vSubunitatea||&apos;
      LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
      LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
      LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
      LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
      LEFT  JOIN TMP_NARTOBJ_LUNA P1 ON P1.CodObiect  = OBJP.CodObiect
      LEFT  JOIN TMP_NARTOBJ_LUNA C1 ON C1.CodObiect  = OBJC.CodObiect
      LEFT  JOIN tmp_cmd1 PMin on PMin.COdObiect = Mat.CodObiect AND PMIN.TIP = &apos;&apos;PMIN&apos;&apos; AND PMIN.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMin0 on PMin0.COdObiect = Mat.CodObiect AND PMIN0.TIP = &apos;&apos;PMIN0&apos;&apos; AND PMIN0.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMax on PMax.COdObiect = Mat.CodObiect AND PMAX.TIP = &apos;&apos;PMAX&apos;&apos; AND PMAX.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMax0 on PMax0.COdObiect = Mat.CodObiect AND PMAX0.TIP = &apos;&apos;PMAX0&apos;&apos; AND PMAX0.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd ULT on ULT.COdObiect = Mat.CodObiect AND ULT.TIP = &apos;&apos;ULT&apos;&apos; AND ULT.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN NIRSTOC NSU ON NSU.CODNIRSTOC = ULT.D1
      LEFT  JOIN PRODMAT MATS ON MATS.CODMAT = MAT.CODMAT - MAT.CODMAT &apos;||sJoinPMP||gJoinStoc||
      gSuplJoins||&apos;
    WHERE
      tmp.userid = &apos;||vuserid || activePC;
  else
    sSelect0 := &apos;SELECT
      P.CODPROIECT, P.CODPROIECT, 507, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, TMP.cant, TMP.necesar, P.DataProiect, OBJC.Denumire, OBJPP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, PN.Cant, nvl(MAT.Pret,0),
      case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end,
      case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end,
      MAT.Cant * case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end,
      case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.cantc,0) else nvl(PMax.CANTC,0) end,
      MAT.Cant * case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end,
      (case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end +case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end) / 2,
      MAT.Cant * (case when nvl(PMax.CANTC,0) = 0 then nvl(PMax0.CANTC,0) else nvl(PMax.CANTC,0) end +case when nvl(PMin.CANTC,0) = 0 then nvl(PMin0.CANTC,0) else nvl(PMin.CANTC,0) end) / 2,&apos;;
      if p_PMP &gt; 0 then
        sSelect0 := sSelect0||&apos;
        PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;),
        MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;), &apos;;
      else
        sSelect0 := sSelect0||&apos;
        0,
        0, &apos;;
      end if;
      sSelect0 := sSelect0||&apos;TMP.Cant/PN0.CANT * PN.Cant, case when P.ACTIV = 1 then &apos;&apos;Activ&apos;&apos; else &apos;&apos;Inactiv&apos;&apos; end, TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Proiect&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA,
      NVL(PN.Nivel,0), NVL(PN.Ordine,0), PM.Lei, X.IND, PCP.CANT, NSU.PRET- NVL(NSU.ADAOS,0) &apos;||gStocField||gUserAlias||&apos;
    FROM
      PROIECT P
      INNER JOIN TMP_PROIECTNOD_MAN TMP ON P.CodProiect = TMP.CodProiect and tmp.userid = &apos;||vUserID||&apos;
      INNER JOIN PROIECTNOD PN ON P.CODPROIECT = PN.CODPROIECT
      INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0
      INNER JOIN PRODCOMP PC ON PN0.CODRETETA = PC.CODPRODCOMP
      INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
      INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST
      INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
      INNER JOIN NARTOBJ OBJP ON P.CODOBIECTPROD = OBJP.CODOBIECT
      INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
      INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
      INNER JOIN NARTOBJ OBJC ON PN.CODOBIECT = OBJC.CODOBIECT
      INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
      INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
      left join NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect
                                     and (OBJCS.codgest is null or OBJCS.codgest = 0)
                                     and objcs.subunitate = &apos;||vSubunitatea||&apos;
      left join NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect
                                     and (OBJPS.codgest is null or OBJPS.codgest = 0)
                                     and objps.subunitate = &apos;||vSubunitatea||&apos;
      LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = &apos;||vSubunitatea||&apos;
      LEFT  JOIN PROIECTNOD PNP ON PN.NODORIGINAL = PNP.CODPROIECTNOD
      LEFT  JOIN PRODMAT MATS ON MATS.CODMAT = PNP.CODPRODMAT
      LEFT  JOIN PRODCOMP PCP ON PCP.CODPRODCOMP = DECODE(NVL(PNP.CODPROIECTNOD,0),0, PN0.CODRETETA, PNP.CODRETETA)
      LEFT  JOIN NARTOBJ OBJPP ON PNP.CODOBIECT = OBJPP.CODOBIECT
      LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
      LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
      LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
      LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
      LEFT  JOIN TMP_NARTOBJ_LUNA P1 ON P1.CodObiect  = OBJP.CodObiect
      LEFT  JOIN TMP_NARTOBJ_LUNA C1 ON C1.CodObiect  = OBJC.CodObiect
      LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = PN.CodProiectNod
      LEFT  JOIN tmp_cmd1 PMin on PMin.COdObiect = Mat.CodObiect AND PMIN.TIP = &apos;&apos;PMIN&apos;&apos; AND PMIN.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMin0 on PMin0.COdObiect = Mat.CodObiect AND PMIN0.TIP = &apos;&apos;PMIN0&apos;&apos; AND PMIN0.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMax on PMax.COdObiect = Mat.CodObiect AND PMAX.TIP = &apos;&apos;PMAX&apos;&apos; AND PMAX.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PMax0 on PMax0.COdObiect = Mat.CodObiect AND PMAX0.TIP = &apos;&apos;PMAX0&apos;&apos; AND PMAX0.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd ULT on ULT.COdObiect = Mat.CodObiect AND ULT.TIP = &apos;&apos;ULT&apos;&apos; AND ULT.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN NIRSTOC NSU ON NSU.CODNIRSTOC = ULT.D1
      &apos;||sJoinPMP||gJoinStoc||
      gSuplJoins||&apos;
    WHERE pn.tip = 3 and tmp.userid = &apos;||vuserid || active;
  end if;

  if p_Tip = 0 then
    sSelect1 := &apos;
    SELECT
      PC.CODPRODCOMP, PC.CODPRODCOMP, 504, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, PC.Cant, TMP.pret, PC.Data, OBJC.Denumire, OBJP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, MAT.Cant, nvl(MAT.Pret,0),
      case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end, NVL(PretMin.CantC,0), MAT.Cant * NVL(PretMin.CANTC,0), NVL(PretMax.CANTC,0), MAT.Cant * NVL(PretMax.CANTC,0),
      (NVL(PretMax.CANTC,0) +NVL(PretMin.CANTC,0)) / 2, MAT.Cant * (NVL(PretMax.CANTC,0) +NVL(PretMin.CANTC,0)) / 2, &apos;;
      if p_PMP &gt; 0 then
        sSelect1 := sSelect1||&apos;
        PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;),
        MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;), &apos;;
      else
        sSelect1 := sSelect1||&apos;
        0,
        0, &apos;;
      end if;
    sSelect1 := sSelect1||&apos;  TMP.Cant / PC.Cant * MAT.Cant,
      CASE when PC.Anulat = 1 then &apos;&apos;Inactiva&apos;&apos; else &apos;&apos;Activa&apos;&apos; end, TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Reteta&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA, 1 NIVEL, MAT.IndexLocal, PM.Lei,
      LPAD(MAT.IndexLocal, 2, &apos;&apos;0&apos;&apos;), PC.CANT, NSU.PRET- NVL(NSU.ADAOS,0) &apos;||gStocField||gUserAlias||&apos;
    FROM PRODCOMP PC
      INNER JOIN TMP_PRODCOMP_MAN TMP ON PC.CodProdComp = TMP.CodProdComp and tmp.userid = &apos;||vUserID||&apos;
      INNER JOIN PRODMAT MAT  ON PC.CODPRODCOMP = MAT.CODPRODCOMP
      INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST AND PG.CODPRODCOMP = PC.CODPRODCOMP
      INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
      INNER JOIN NARTOBJ OBJP ON PC.CODOBIECT = OBJP.CODOBIECT
      INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
      INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
      INNER JOIN NARTOBJ OBJC ON MAT.CODOBIECT = OBJC.CODOBIECT
      INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
      INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
      left join NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect
                                     and ( OBJCS.codgest is null or OBJCS.codgest = 0)
                                     and objcs.subunitate = &apos;||vSubunitatea||&apos;
      left join NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect
                                     and ( OBJPS.codgest is null or OBJPS.codgest = 0)
                                     and objps.subunitate = &apos;||vSubunitatea||&apos;
      LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = &apos;||vSubunitatea||&apos;
      LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
      LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
      LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
      LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
      LEFT  JOIN TMP_NARTOBJ_LUNA P1 ON P1.CodObiect  = OBJP.CodObiect
      LEFT  JOIN TMP_NARTOBJ_LUNA C1 ON C1.CodObiect  = OBJC.CodObiect
      LEFT  JOIN tmp_cmd1 PretMin on PretMin.COdObiect = Mat.CodObiect AND PRETMIN.TIP = &apos;&apos;PRETMIN&apos;&apos; AND PRETMIN.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PretMax on PretMax.COdObiect = Mat.CodObiect AND PRETMAX.TIP = &apos;&apos;PRETMAX&apos;&apos; AND PRETMAX.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd ULT on ULT.COdObiect = Mat.CodObiect AND ULT.TIP = &apos;&apos;ULT&apos;&apos; AND ULT.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN NIRSTOC NSU ON NSU.CODNIRSTOC = ULT.D1
      LEFT  JOIN PRODMAT MATS ON MATS.CODMAT = MAT.CODMAT - MAT.CODMAT&apos;||sJoinPMP||gJoinStoc||
      gSuplJoins||&apos;
    WHERE tmp.userid = &apos;||vuserid || anulatPC;
  else
    sSelect1 := &apos;
    SELECT
      P.CODPROIECT, P.CODPROIECT, 507, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, TMP.Cant, TMP.necesar, P.DataProiect, OBJC.Denumire, OBJPP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, PN.Cant, nvl(MAT.Pret,0),
      case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end, NVL(PretMin.CANTC,0), MAT.Cant * NVL(PretMin.CANTC,0), NVL(PretMax.CANTC,0), MAT.Cant * NVL(PretMax.CANTC,0),
      (NVL(PretMax.CANTC,0)+NVL(PretMin.CANTC,0)) / 2, MAT.Cant * (NVL(PretMax.CANTC,0)+NVL(PretMin.CANTC,0)) / 2, &apos;;
    if p_PMP &gt; 0 then
      sSelect1 := sSelect1||&apos;
      PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;),
      MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, &apos;||vSubunitatea||&apos;), &apos;;
    else
      sSelect1 := sSelect1||&apos;
      0,
      0, &apos;;
    end if;
    sSelect1 := sSelect1||&apos;TMP.Cant / PN0.CANT * PN.Cant, case when P.ACTIV = 1 then &apos;&apos;Activ&apos;&apos; else &apos;&apos;Inactiv&apos;&apos; end,
      TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Proiect&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA, NVL(PN.NIVEL,0), NVL(PN.ORDINE,0), PM.Lei, X.IND, PCP.CANT, NSU.PRET- NVL(NSU.ADAOS,0) &apos;||gStocField||gUserAlias||&apos;
    FROM
      PROIECT P
      INNER JOIN TMP_PROIECTNOD_MAN TMP ON P.CodProiect = TMP.CodProiect and tmp.userid = &apos;||vUserID||&apos;
      INNER JOIN PROIECTNOD PN ON P.CODPROIECT = PN.CODPROIECT
      INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0
      INNER JOIN PRODCOMP PC ON PN0.CODRETETA = PC.CODPRODCOMP
      INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
      INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST
      INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
      INNER JOIN NARTOBJ OBJP ON P.CODOBIECTPROD = OBJP.CODOBIECT
      INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
      INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
      INNER JOIN NARTOBJ OBJC ON PN.CODOBIECT = OBJC.CODOBIECT
      INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
      INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
      left join NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect
                                     and ( OBJCS.codgest is null or OBJCS.codgest = 0)
                                     and objcs.subunitate = &apos;||vSubunitatea||&apos;
      left join NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect
                                     and ( OBJPS.codgest is null or OBJPS.codgest = 0)
                                     and objps.subunitate = &apos;||vSubunitatea||&apos;
      LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = &apos;||vSubunitatea||&apos;
      LEFT  JOIN PROIECTNOD PNP ON PN.NODORIGINAL = PNP.CODPROIECTNOD
      LEFT  JOIN PRODMAT MATS ON MATS.CODMAT = PNP.CODPRODMAT
      LEFT  JOIN PRODCOMP PCP ON PCP.CODPRODCOMP = DECODE(NVL(PNP.CODPROIECTNOD,0), 0, PN0.CODRETETA, PNP.CODRETETA)
      LEFT  JOIN NARTOBJ OBJPP ON PNP.CODOBIECT = OBJPP.CODOBIECT
      LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
      LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
      LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
      LEFT  JOIN NCLASEA CLSCOMP ON nvl(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
      LEFT  JOIN TMP_NARTOBJ_LUNA P1 ON P1.CodObiect  = OBJP.CodObiect
      LEFT  JOIN TMP_NARTOBJ_LUNA C1 ON C1.CodObiect  = OBJC.CodObiect
      LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND
                  FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = PN.CodProiectNod
      LEFT  JOIN tmp_cmd1 PretMin on PretMin.COdObiect = Mat.CodObiect AND PRETMIN.TIP = &apos;&apos;PRETMIN&apos;&apos; AND PRETMIN.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd1 PretMax on PretMax.COdObiect = Mat.CodObiect AND PRETMAX.TIP = &apos;&apos;PRETMAX&apos;&apos; AND PRETMAX.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN tmp_cmd ULT on ULT.COdObiect = Mat.CodObiect AND ULT.TIP = &apos;&apos;ULT&apos;&apos; AND ULT.USERID = &apos;||VUSERID||&apos;
      LEFT  JOIN NIRSTOC NSU ON NSU.CODNIRSTOC = ULT.D1
      &apos;||sJoinPMP||gJoinStoc||gSuplJoins||&apos;
    WHERE tmp.userid = &apos;||vuserid||&apos;
      and pn.tip = 3&apos; || active;
  end if;

  IF p_Sursa = 0
  THEN sSelect := sSelect0;
  ELSE sSelect := sSelect1;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

  DELETE TMP_PRODCOMP_MAN WHERE USERID = VUSERID;
  DELETE TMP_PROIECTNOD_MAN WHERE USERID = VUSERID;
  DELETE tmp_cmd1 WHERE USERID = VUSERID;
  DELETE tmp_cmd WHERE USERID = VUSERID;
  COMMIT;
END;

PROCEDURE TEST IS
BEGIN
  PKG_GLOBALS.SETUSERID(1291);
  PKG_GLOBALS.SETSUBUNITATE(2);
  PKG_GLOBALS.SetLunaLucru_SIMPLA(2020,2);
  PKG_LIST_BASE_CONSUM_PROD.SETALLPARAMS(1,0,0,0,0,0,0);
  PKG_LIST_BASE_CONSUM_PROD.processlist(&apos;TMP_LST_CP_1291_169762&apos;,0,0);
END;

end PKG_LIST_BASE_CONSUM_PROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONSUM_ZILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B453CCB8938E06822D87AF986A27F77B9A829275</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONSUM_ZILE is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2200);
  gSuplJoins  VARCHAR2(5000);
  vAnLuna     number;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(20000);
datastart date;
datastop date;
BEGIN
  vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  select to_date(&apos;01.&apos;||pkg_globals.GetLUNALUCRU||&apos;.&apos;||pkg_globals.GetANLUCRU, &apos;dd.mm.yyyy&apos;) into datastart from dual;
  select last_day(to_date(&apos;01.&apos;||pkg_globals.GetLUNALUCRU||&apos;.&apos;||pkg_globals.GetANLUCRU, &apos;dd.mm.yyyy&apos;)) into datastop from dual;

--INSERT INTO x(view_name,test) values(&apos;na&apos;,to_char(datastart,&apos;dd.mm.yyyy&apos;));
--INSERT INTO x(view_name,test) values(&apos;na&apos;,to_char(datastop ,&apos;dd.mm.yyyy&apos;));

/*
  insert into tmp_manevra_predari(codcomanda1, datadoc, codobiect, cant)
  select c1.codcomanda1, i.datadoc, i1.codobiect, sum(i1.cant) cant
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join intrari1 i1 on i1.codcmdint1 = c1.codcomanda1
       inner join intrari i on i.codintr = i1.codintr
  where i.datadoc between datastart and datastop
        and nvl(c.anulat,0) = 0 and c.operat = 1
        and nvl(i.anulat,0) = 0 and i.operat = 1
  group by c1.codcomanda1, i1.codobiect, i.datadoc
  order by i.datadoc;
*/
execute immediate &apos;insert into tmp_manevra_predari(codcomanda1, datadoc, codobiect, cant)
  select c1.codcomanda1, i.datadoc, i1.codobiect, sum(i1.cant) cant
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join intrari1 i1 on i1.codcmdint1 = c1.codcomanda1
       inner join intrari i on i.codintr = i1.codintr
  where i.datadoc between to_date(&apos;&apos;&apos;||to_char(datastart,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||to_char(datastop ,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        and nvl(c.anulat,0) = 0 and c.operat = 1
        and nvl(i.anulat,0) = 0 and i.operat = 1
  group by c1.codcomanda1, i1.codobiect, i.datadoc
  order by i.datadoc &apos;
  ;

/*
  insert into tmp_manevra_consum(codcomanda1, datadoc, codobiect, cant, cantmat, cantprod)
  select c1.codcomanda1, i.datadoc, i1.codobiect, sum(i1.cant) cant, nvl(mat.cant,0) cantmat, nvl(prod.cant,0) cantprod
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join iesiri1 i1 on i1.codcmdint1 = c1.codcomanda1
       inner join iesiri i on i.codies = i1.codies
       left  join iesprodlink l on i1.codies1 = l.codies1
       left  join cmdprodmat mat on l.codcmdprodmat = mat.codcmdprodmat
       left  join cmdprodmat prod on prod.codcomanda1 = mat.codcomanda1 and prod.tip = 0
  where i.datadoc between datastart and datastop
        and nvl(c.anulat,0) = 0 and c.operat = 1
        and nvl(i.anulat,0) = 0 and i.operat = 1
  group by c1.codcomanda1, i1.codobiect, i.datadoc, mat.cant, prod.cant
  order by i.datadoc;
*/
execute immediate &apos;insert into tmp_manevra_consum(codcomanda1, datadoc, codobiect, cant, cantmat, cantprod)
  select c1.codcomanda1, i.datadoc, i1.codobiect, sum(i1.cant) cant, nvl(mat.cant,0) cantmat, nvl(prod.cant,0) cantprod
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join iesiri1 i1 on i1.codcmdint1 = c1.codcomanda1
       inner join iesiri i on i.codies = i1.codies
       left  join iesprodlink l on i1.codies1 = l.codies1
       left  join cmdprodmat mat on l.codcmdprodmat = mat.codcmdprodmat
       left  join cmdprodmat prod on prod.codcomanda1 = mat.codcomanda1 and prod.tip = 0
  where i.datadoc between to_date(&apos;&apos;&apos;||to_char(datastart,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||to_char(datastop ,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        and nvl(c.anulat,0) = 0 and c.operat = 1
        and nvl(i.anulat,0) = 0 and i.operat = 1
  group by c1.codcomanda1, i1.codobiect, i.datadoc, mat.cant, prod.cant
  order by i.datadoc &apos;;

  for v_rec in (select c1.codcomanda1, tmp.codobiect, c.codgest, c.nrdoc, g.den_gest, obj.denumire
                from (select distinct codcomanda1, codobiect from tmp_manevra_predari) tmp
                     inner join comanda1 c1 on c1.codcomanda1 = tmp.codcomanda1
                     inner join comanda c on c1.codcomanda = c.codcomanda
                     inner join nartobj obj on tmp.codobiect = obj.codobiect
                     inner join ngest g on g.codgest = c.codgest
               ) loop
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(CodComanda1, CodProdus, CodGest, NrDoc, den_Gest, produs, Explicatie)
     values (&apos;||v_rec.codcomanda1||&apos;,&apos;||v_rec.codobiect||&apos;,&apos;||v_rec.codgest||&apos;,&apos;||v_rec.nrdoc||&apos;,&apos;&apos;&apos;||v_rec.den_gest||
             &apos;&apos;&apos;,&apos;&apos;&apos;||v_rec.denumire||&apos;&apos;&apos;, &apos;&apos;Predari produse pe &apos;||v_rec.den_gest||&apos;&apos;&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);         
  end loop;

  for v_rec in (select tmp.codcomanda1, tmp.datadoc, tmp.codobiect CodProdus, nvl(tmp.cant,0) cant, c.codgest, extract(day from tmp.datadoc) zi
               from tmp_manevra_predari tmp
                     inner join comanda1 c1 on c1.codcomanda1 = tmp.codcomanda1
                     inner join comanda c on c1.codcomanda = c.codcomanda
                     inner join nartobj obj on tmp.codobiect = obj.codobiect
                     inner join ngest g on g.codgest = c.codgest) loop
    sInsert :=
    &apos;update &apos;||tmpName||&apos; set D&apos;||v_rec.zi||&apos; = &apos;||v_rec.cant||&apos;
     where CodComanda1 = &apos;||v_rec.codcomanda1||&apos; and CodGest = &apos;||v_rec.codgest||&apos; and
           CodProdus = &apos;||v_rec.codprodus||&apos; and CodMaterial is null&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
  end loop;

  for v_rec in (select tmp_p.codcomanda1, tmp_p.codobiect CodProdus, tmp_c.codobiect CodMaterial,
                       prod.denumire produs, mat.denumire material, c.codgest, g.den_gest, c.nrdoc
                from (select distinct codcomanda1, codobiect from tmp_manevra_predari) tmp_p
                     inner join (select distinct codcomanda1, codobiect from tmp_manevra_consum) tmp_c on tmp_c.codcomanda1 = tmp_p.codcomanda1
                     inner join nartobj prod on prod.codobiect = tmp_p.codobiect
                     inner join nartobj mat on mat.codobiect = tmp_c.codobiect
                     inner join comanda1 c1 on tmp_p.codcomanda1 = c1.codcomanda1
                     inner join comanda c on c.codcomanda = c1.codcomanda
                     inner join ngest g on g.codgest = c.codgest
               ) loop
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(CodComanda1, CodGest, CodProdus, CodMaterial, NrDoc, den_Gest, produs, material, explicatie)
    values (&apos;||v_rec.codcomanda1||&apos;,&apos;||v_rec.codgest||&apos;,&apos;||v_rec.codprodus||&apos;,&apos;||v_rec.codmaterial||&apos;,&apos;||v_Rec.nrdoc||&apos;,&apos;&apos;&apos;||v_rec.den_gest||&apos;&apos;&apos;,&apos;&apos;&apos;||
            v_rec.produs||&apos;&apos;&apos;,&apos;&apos;&apos;||v_rec.material||&apos;&apos;&apos;, &apos;&apos;Consum material real&apos;&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);        
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(CodComanda1, CodGest, CodProdus, CodMaterial, NrDoc, den_Gest, produs, material, explicatie)
    values (&apos;||v_rec.codcomanda1||&apos;,&apos;||v_rec.codgest||&apos;,&apos;||v_rec.codprodus||&apos;,&apos;||v_rec.codmaterial||&apos;,&apos;||v_Rec.nrdoc||&apos;,&apos;&apos;&apos;||v_rec.den_gest||&apos;&apos;&apos;,&apos;&apos;&apos;||
            v_rec.produs||&apos;&apos;&apos;,&apos;&apos;&apos;||v_rec.material||&apos;&apos;&apos;, &apos;&apos;Consum teoretic pe baza predarii&apos;&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);        
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(CodComanda1, CodGest, CodProdus, CodMaterial, NrDoc, den_Gest, produs, material, explicatie)
    values (&apos;||v_rec.codcomanda1||&apos;,&apos;||v_rec.codgest||&apos;,&apos;||v_rec.codprodus||&apos;,&apos;||v_rec.codmaterial||&apos;,&apos;||v_Rec.nrdoc||&apos;,&apos;&apos;&apos;||v_rec.den_gest||&apos;&apos;&apos;,&apos;&apos;&apos;||
            v_rec.produs||&apos;&apos;&apos;,&apos;&apos;&apos;||v_rec.material||&apos;&apos;&apos;, &apos;&apos;Diferenta&apos;&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);        
  end loop;

  for v_rec in (select tmp_p.codcomanda1, tmp_p.codobiect CodProdus, tmp_c.codobiect CodMaterial,
                       prod.denumire produs, mat.denumire material, c.codgest, nvl(tmp_c.cant,0) cant,
                       case when nvl(tmp_c.cantprod,0) &lt;&gt; 0 then nvl(tmp_p.Cant,0)/tmp_c.cantprod * nvl(tmp_c.cantmat,0)
                            else 0
                       end cantt,
                       nvl(tmp_c.cant,0) -
                       case when nvl(tmp_c.cantprod,0) &lt;&gt; 0 then nvl(tmp_p.Cant,0)/tmp_c.cantprod * nvl(tmp_c.cantmat,0)
                            else 0
                       end dif,
                       extract(day from tmp_c.datadoc) zi
                from (select distinct codcomanda1, codobiect, cant from tmp_manevra_predari) tmp_p
                     inner join tmp_manevra_consum tmp_c on tmp_c.codcomanda1 = tmp_p.codcomanda1
                     inner join nartobj prod on prod.codobiect = tmp_p.codobiect
                     inner join nartobj mat on mat.codobiect = tmp_c.codobiect
                     inner join comanda1 c1 on tmp_p.codcomanda1 = c1.codcomanda1
                     inner join comanda c on c.codcomanda = c1.codcomanda
                     inner join ngest g on g.codgest = c.codgest
               ) loop
    sInsert :=
    &apos;update &apos;||tmpName||&apos; set D&apos;||v_rec.zi||&apos; = &apos;||v_rec.cant||&apos;
     where CodComanda1 = &apos;||v_rec.codcomanda1||&apos; and CodGest = &apos;||v_rec.codgest||&apos; and
           CodProdus = &apos;||v_rec.codprodus||&apos; and CodMaterial = &apos;||v_rec.codmaterial||&apos; and Explicatie = &apos;&apos;Consum material real&apos;&apos;&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
    sInsert :=
    &apos;update &apos;||tmpName||&apos; set D&apos;||v_rec.zi||&apos; = &apos;||v_rec.cantt||&apos;
     where CodComanda1 = &apos;||v_rec.codcomanda1||&apos; and CodGest = &apos;||v_rec.codgest||&apos; and
           CodProdus = &apos;||v_rec.codprodus||&apos; and CodMaterial = &apos;||v_rec.codmaterial||&apos; and Explicatie = &apos;&apos;Consum teoretic pe baza predarii&apos;&apos;&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
    sInsert :=
    &apos;update &apos;||tmpName||&apos; set D&apos;||v_rec.zi||&apos; = &apos;||v_rec.dif||&apos;
     where CodComanda1 = &apos;||v_rec.codcomanda1||&apos; and CodGest = &apos;||v_rec.codgest||&apos; and
           CodProdus = &apos;||v_rec.codprodus||&apos; and CodMaterial = &apos;||v_rec.codmaterial||&apos; and Explicatie = &apos;&apos;Diferenta&apos;&apos;&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
  end loop;

  sInsert := &apos;update &apos;||tmpName||&apos; set TotalLuna = &apos;;
  for v_rec in 1..extract(day from last_day(to_date(&apos;01.&apos;||pkg_globals.GetLUNALUCRU||&apos;.&apos;||pkg_globals.GetANLUCRU, &apos;dd.mm.yyyy&apos;))) loop
    sInsert := sInsert||&apos;D&apos;||v_rec||&apos; + &apos;;
  end loop;
  sInsert := sInsert||&apos;0&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_CONSUM_ZILE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONTEVOLUTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE683398D3FEA5E30599C102B9F8661C6900E280</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONTEVOLUTIE IS

  vTipAnaliza  INTEGER; --1 -&gt; Rulaj curent Debit
                        --2 -&gt; Rulaj curent Credit
                        --3 -&gt; Sold final Debit
                        --4 -&gt; Sold final Credit
                        --5 -&gt; Sold lunar Debit
                        --6 -&gt; Sold lunar Credit
  vLunaIni     INTEGER;
  vLunaFin     INTEGER;
  vPlanCont    INTEGER;
  vAnContSold  INTEGER;

  vNrCol       INTEGER;

  gDinFieldsI  CLOB;
  gDinFieldsG  CLOB;
  gDinFieldsS  CLOB;

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  vIL     INTEGER := 0;
  vAl     NUMBER  := vLunaIni;
  vAn     NUMBER;
  vLuna   NUMBER;
  sDen    VARCHAR2(10)  := CASE vTipAnaliza WHEN 1 THEN &apos;RD&apos; WHEN 2 THEN &apos;RC&apos; WHEN 3 THEN &apos;SD&apos; WHEN 4 THEN &apos;SC&apos; WHEN 5 THEN &apos;LD&apos; WHEN 6 THEN &apos;LC&apos; END;
BEGIN
  gDinFieldsI := &apos;&apos;;
  gDinFieldsG := &apos;&apos;;
  gDinFieldsS := &apos;&apos;;
  DELETE tmp_dinamic_cols;
  WHILE vAl &lt;= vLunaFin LOOP
    vIL := vIL + 1;
    PKG_LIST_BASE_UTILS.ExtractAnLuna(vAl, vAn, vLuna);
    IF vIL = 1 THEN vAnContSold := vAn; END IF;
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod) VALUES (&apos;D&apos; ||To_Char(vIL,&apos;fm999&apos;), sDen||&apos;_&apos;||To_Char(vAn,&apos;fm0000&apos;)||&apos;_&apos;||To_Char(vLuna ,&apos;fm00&apos;),vIL, vAl);

    gDinFieldsI := gDinFieldsI||&apos;, D&apos; ||To_Char(vIL,&apos;fm999&apos;);
    gDinFieldsG := gDinFieldsG||
      CASE
        WHEN vTipAnaliza IN (1,2) THEN &apos;, Sum(CASE WHEN AL = &apos;||vAl||&apos; THEN CE ELSE 0 END) D&apos;||To_Char(vIL,&apos;fm999&apos;)
        WHEN vTipAnaliza IN (3,4) THEN &apos;, Sum(SI) + Sum(CASE WHEN AL &lt;= &apos;||vAl||&apos; THEN CE ELSE 0 END) D&apos;||To_Char(vIL,&apos;fm999&apos;)
        WHEN vTipAnaliza IN (5,6) THEN &apos;, Sum(CASE WHEN AL = &apos;||vAl||&apos; THEN CE ELSE 0 END) D&apos;||To_Char(vIL,&apos;fm999&apos;)
      END;
    gDinFieldsS := gDinFieldsS||&apos;, Nvl(E.D&apos;||To_Char(vIL,&apos;fm999&apos;)||&apos;,0)&apos;;
    vAl := vAl + 1;
  END LOOP;
  COMMIT;
  vNrCol := vIl;
END;

PROCEDURE SETPARAMS(pLunaIni    IN INTEGER  DEFAULT NULL,
                    pLunaFin    IN INTEGER  DEFAULT NULL,
                    pTipAnaliza IN INTEGER  DEFAULT NULL,
                    pPlanCont   IN INTEGER  DEFAULT NULL,
                    V_CODJOB1 IN NUMBER  DEFAULT 0)
IS
  dDataS DATE;
  dDataF DATE;
BEGIN
  vTipAnaliza  := pTipAnaliza;
  vLunaIni     := pLunaIni;
  vLunaFin     := pLunaFin;
  vPlanCont    := pPlanCont;

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,vLunaIni,vLunaFin);
  END IF;

  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  sCampSI  VARCHAR2(100);
  sCampRP  VARCHAR2(100);
  sCampRC  VARCHAR2(100);
  sPer     VARCHAR2(100)  := CASE WHEN vLunaIni = vLunaFin THEN &apos; = &apos;||vLunaIni ELSE &apos; BETWEEN &apos;||vLunaIni||&apos; AND &apos;||vLunaFin END;
  vAIni    NUMBER;
  vLIni    NUMBER;
BEGIN
  CASE vTipAnaliza
    WHEN 1 THEN
      sCampSI := &apos;Nvl(x.soldid,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpd,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcd,0)&apos;;
    WHEN 2 THEN
      sCampSI := &apos;Nvl(x.soldic,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpc,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcc,0)&apos;;
    WHEN 3 THEN
      sCampSI := &apos;Nvl(x.soldid,0)-Nvl(x.soldic,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpd,0)-Nvl(x.rulajpc,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcd,0)-Nvl(x.rulajcc,0)&apos;;
    WHEN 4 THEN
      sCampSI := &apos;Nvl(x.soldic,0)-Nvl(x.soldid,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpc,0)-Nvl(x.rulajpd,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcc,0)-Nvl(x.rulajcd,0)&apos;;
    WHEN 5 THEN
      sCampSI := &apos;Nvl(x.soldid,0)-Nvl(x.soldic,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpd,0)-Nvl(x.rulajpc,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcd,0)-Nvl(x.rulajcc,0)&apos;;
    WHEN 6 THEN
      sCampSI := &apos;Nvl(x.soldic,0)-Nvl(x.soldid,0)&apos;;
      sCampRP := &apos;Nvl(x.rulajpc,0)-Nvl(x.rulajpd,0)&apos;;
      sCampRC := &apos;Nvl(x.rulajcc,0)-Nvl(x.rulajcd,0)&apos;;
  END CASE;

  gSuplCols := &apos;NCONT C&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName || &apos;(CONTSIMB, CONTDEN, CONTTIP, SOLDINI&apos;||gDinFieldsI||gUserFields||&apos;)
  WITH
  C AS (
    SELECT codcont, CONNECT_BY_ROOT codcont codx, CONNECT_BY_ISLEAF frunza
    FROM ncont
    CONNECT BY codparinte = PRIOR codcont
    START WITH codcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;)
  ),
  E AS (
    SELECT CodCont, SUM(SI) SI&apos;||gDinFieldsG||&apos;
    FROM (
      SELECT c.codx CodCont, &apos;||vLunaIni||&apos; Al, &apos;||sCampSI||&apos; SI, 0 CE
      FROM c INNER JOIN ncontsold x ON x.codcont = c.codcont
      WHERE c.frunza = 1 AND x.An = &apos;||vAnContSold||&apos; AND x.Luna = 1
      UNION ALL
      SELECT c.codx CodCont, x.An*12+x.Luna Al, CASE WHEN x.An*12+x.Luna &gt; &apos;||vLunaIni||&apos; THEN 0 ELSE &apos;||sCampRP||&apos; END SI, &apos;||sCampRC||&apos; CE
      FROM c INNER JOIN ncontrul x ON x.codcont = c.codcont
      WHERE c.frunza = 1 AND x.An*12+x.Luna&apos;||sPer||&apos;
    )
    GROUP BY CodCont
  )
  SELECT C.Simbol, C.Den_Cont, Decode(c.tipcont,0,&apos;&apos;D&apos;&apos;,1,&apos;&apos;C&apos;&apos;,&apos;&apos;B&apos;&apos;), Nvl(E.SI,0) &apos;||gDinFieldsS||&apos;
  FROM ncont c
    LEFT JOIN e ON e.codcont = c.codcont&apos;||
    gSuplJoins||&apos;
  WHERE c.codcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_contevolutie;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONTRABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5590A265CBBC8CBCCAA1247AD005F1741EF1C81</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONTRABON IS

  vTipPer     NUMBER;
  sData       VARCHAR2(20);
  vData       DATE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setparams  (aTipPer IN NUMBER DEFAULT 0, V_CODJOB1 IN NUMBER  DEFAULT 0 )
IS
  auxAL1  INTEGER;
  auxAL2  INTEGER;
  auxData VARCHAR2(10);

BEGIN
  vTipPer := aTipPer;
  sData   := &apos;01.&apos;||To_Char(PKG_GLOBALS.GetLunaLucru,&apos;00&apos;)||&apos;.&apos;||To_Char(PKG_GLOBALS.GetAnLucru,&apos;0000&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sData,auxData,auxAL1,auxAL2);
  END IF;
  vData := To_Date(sData,&apos;dd.mm.yyyy&apos;);
END;

FUNCTION CodContract2(aCodContract IN NUMBER) RETURN NUMBER IS
  vCodContract2 NUMBER;
BEGIN
  SELECT Min(CodContract2) KEEP (Dense_Rank First ORDER BY data)
  INTO vCodContract2
  FROM Contract2
  WHERE CodContract = aCodContract AND data &gt;= vData;

  RETURN Nvl(vCodContract2,0);
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
  sSelect  VARCHAR2(20000);

  sJoinC2  VARCHAR2( 1000);
  sFiltru  VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;contract c, contract2 c2, iesiri i, npart p, nmonede mc, nmonede md, nclasep cp, nagenda slivr, npartcodfisc codf &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, CONTRDATAF, CONTRMoneda, CONTRVal, CONTRActiv, ZiFact, ProcMaj,
    SLIVR_TIP,SLIVR_DEN,SLIVR_ADR,
    SLIVR_LOC,SLIVR_JUD,SLIVR_TARA,SLIVR_ZONA,
    PrefixDoc, NrDoc, DataDoc, Part, Moneda, ValDoc, TVADoc, VALTOTDOC, X_Judet, X_Codclasap, OBSERVATII, OBS_LINII  &apos;||gUserFields||&apos;)&apos;;

  IF vTipPer = 0 THEN -- cu facturare in luna de lucru
    sJoinC2 := &apos;
    INNER JOIN contract2 c2 ON c2.codcontract = c.codcontract&apos;;
    sFiltru := &apos;
    AND c2.data BETWEEN TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND LAST_DAY(TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))&apos;;
  ELSIF vTipPer = 1 THEN -- valabile in luna de lucru
    sJoinC2 := &apos;
    LEFT JOIN contract2 c2 ON c2.codcontract2 = PKG_LIST_BASE_CONTRABON.CodContract2(c.codcontract)&apos;;
    sFiltru := &apos;
    AND c.datastop &gt;= TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND c.datastart &lt;= LAST_DAY(TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))&apos;;
  ELSIF vTipPer = 2 THEN -- valabile in luna de lucru sau viitor
    sJoinC2 := &apos;
    LEFT JOIN contract2 c2 ON c2.codcontract2 = PKG_LIST_BASE_CONTRABON.CodContract2(c.codcontract)&apos;;
    sFiltru := &apos;
    AND c.datastop &gt;= TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sSelect := &apos;
  with man_obs as (
     select ctr1.codcontract as codcontract,
       vc2_nt_to_vc3200(CAST(COLLECT(ctr1.obs) AS vc2_nt), &apos;&apos;; &apos;&apos;) as obs_linii
     from contract1 ctr1
     group by ctr1.codcontract
  )
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, c2.data, mc.den_moneda, c2.suma, DECODE(c.activ,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), c.ZiFact, c.ProcMaj,
    tipslivr.denumire , slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal),
    loclivr.den_localit, judlivr.den_judet, taralivr.den_tara, zonalivr.den_zona,
    i.prefixdoc, i.nrdoc, i.datadoc, p.den_part, md.den_moneda, i.valdoc - i.tvadoc, i.tvadoc, i.valdoc, judlivr.simbauto, cp.codclasep,
    c.obs, m_obs.obs_linii &apos;||gUserAlias||&apos;
  FROM contract c&apos;||
    sJoinC2 ||&apos;
    LEFT JOIN man_obs   m_obs     ON m_obs.codcontract = c.codcontract
    LEFT JOIN iesiri       i        ON i.codies             = c2.coddoc AND i.tipdoc = c2.tipdoc
    LEFT JOIN npart        p        ON p.codpart            = c.partener
    LEFT JOIN nmonede      mc       ON mc.codmoneda         = c.moneda
    LEFT JOIN nmonede      md       ON md.codmoneda         = i.moneda
    LEFT JOIN nclasep      cp       ON cp.codclasep         = p.codclasa
    LEFT JOIN nagenda      slivr    ON slivr.codagenda      = c.codlocatie
    LEFT JOIN nlocalit     loclivr  ON loclivr.codlocalit   = slivr.codlocalit
    LEFT JOIN njudet       judlivr  ON judlivr.codjudet     = loclivr.codjudet
    LEFT JOIN nzone        zonalivr ON zonalivr.codzona     = loclivr.codzona
    LEFT JOIN ntari        taralivr ON taralivr.codtara     = loclivr.codtara
    LEFT JOIN traseulivr   tlivr    ON tlivr.codtraseulivr  = slivr.codtraseu
    LEFT JOIN ntipsedii    tipslivr ON tipslivr.codtipsediu = slivr.codtipsediu
    LEFT JOIN npers        ag       ON ag.codpers           = c.agent
    LEFT JOIN npartcodfisc codf     ON codf.cod_codfiscal   = c.codfiscal&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 34 AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
    sFiltru;

  EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;

END;

PROCEDURE SETJOINURI IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_CONTRABON;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CONTRACTDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8E591C02907B627A9AA9A1F7028866B26808953</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CONTRACTDOC IS

  vCodCONTRACT  CONTRACT.CODCONTRACT%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodCONTRACT IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodCONTRACT := pCodCONTRACT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT C.TipDoc, C.NrDoc, C.DataDoc, C.DataStart, C.DataStop, C.Obs,
      PCF.CodFiscal CIF, P.Den_Part, P.Autorizatie, P.RegCom,
      M.Simbol, L.Den_Localit,
      NumePrenume(PC.Nume,PC.Prenume) PersContact,
      UT.UserName, Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      US.TELEFON UTEL, US.EMAIL UEMAIL,
      CASE C.tiplivrare
        WHEN  0 THEN &apos;...&apos;
        WHEN  1 THEN &apos;EXW - Ex Works (named place of delivery)&apos;
        WHEN  2 THEN &apos;FCA - Free Carrier (named place of delivery)&apos;
        WHEN  3 THEN &apos;CPT - Carriage Paid To (named place of destination)&apos;
        WHEN  4 THEN &apos;CIP - Carriage and Insurance Paid to (named place of destination)&apos;
        WHEN  5 THEN &apos;DAT - Delivered at Terminal (named terminal at port or place of destination)&apos;
        WHEN  6 THEN &apos;DAP - Delivered at Place (named place of destination)&apos;
        WHEN  7 THEN &apos;DDP - Delivered Duty Paid (named place of destination)&apos;
        WHEN  8 THEN &apos;FAS - Free alongside ship (named port of shipment)&apos;
        WHEN  9 THEN &apos;FOB - Free on Board (named port of shipment)&apos;
        WHEN 10 THEN &apos;CFR - Cost and Freight (named port of destination)&apos;
        WHEN 11 THEN &apos;CIF - Cost, Insurance and Freight (named port of destination)&apos;
      END InCoTerms,
      GetAdresa(ag.sector, ag.strada, ag.nr1, ag.nr2, ag.bloc, ag.scara, ag.etaj, ag.apart, ag.codpostal) AS ADRESA, l.den_localit localitp, J.den_judet judetp, AG.Telefon telefonp, AG. Email emailp,
      coalesce(bk.denumire,bk0.denumire) denumirep, coalesce(b.contbanca,b0.contbanca) contbanca
    FROM Contract C
      LEFT JOIN NMONEDE M ON C.Moneda = M.CodMoneda
      LEFT JOIN NPARTCODFISC PCF ON C.CodFiscal = PCF.Cod_CodFiscal
      LEFT JOIN NPART P ON C.Partener = P.CodPart
      LEFT JOIN NAGENDA AG ON C.CodLocatie = AG.CodAgenda
      LEFT JOIN NLOCALIT L ON AG.CodLocalit = L.CodLocalit
      LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET

       LEFT JOIN
      (select count (*) nr, b2.codpart from NPARTB B2
       where nvl(b2.implicit,0)=0
      group by b2.codpart
      having count(*)=1

       ) b1 ON b1.CODPART = P.CODPART

      LEFT JOIN NPARTB B0 on B1.CODPART = B0.CODPART
      LEFT JOIN npartb B on B.CODPART = P.CODPART AND B.IMPLICIT = 1
      LEFT JOIN NBANK BK ON B.CODBANK = BK.CODBANK
      LEFT JOIN NBANK BK0 ON B0.CODBANK = BK0.CODBANK


      LEFT JOIN NPERSCONTACT PC ON PC.CodPersC = C.CodPersC
      LEFT JOIN NPERS U ON U.LOGONNAME = C.USERID
      LEFT JOIN NAGENDA US ON US.CODAGENDA = U.AGENDA
   	  LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = C.USERID
    WHERE C.CodContract = vCodCONTRACT
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT DE&apos;,                     v_rec.USERNAME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,                   v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT TELEFON&apos;,                v_rec.UTEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT EMAIL&apos;,                  v_rec.UEMAIL);

    pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Contract&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data Contract&apos;,                   TO_CHAR(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Perioada de valabilitate&apos;,        TO_CHAR(v_rec.DataStart,&apos;dd.mm.yyyy&apos;)||&apos; - &apos;||TO_CHAR(v_rec.DataStop,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener &apos;,                       v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CUI&apos;,                    v_rec.CIF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Reg Com&apos;,                v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener autorizatie&apos;,            v_rec.Autorizatie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                          v_rec.Simbol);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu partener&apos;,                  v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Persoana de contact&apos;,             v_rec.PersContact);
    pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTerms&apos;,                       v_rec.InCoTerms);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Adresa&apos;,                 v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener localitate&apos;,             v_rec.localitp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener judet&apos;,                  v_rec.judetp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener telefon&apos;,                v_rec.telefonp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener email&apos;,                   v_rec.emailp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener banca&apos;,                   v_rec.denumirep);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener cont&apos;,                    v_rec.contbanca);


    EXIT;
  END LOOP;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;CONTRACT1 C1, CONTRACT C, NPART PART, NARTOBJ OBJ, NARTCLI ARTCLI, NART NA, NUM1 UM, NPART PROD, NCLASEA CA&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANT, PRET, DISC, OBS, ZileC, DenLaCli, CodLaCli, CodListat&apos;||gUserFields||&apos;)
  SELECT
    OBJ.Denumire, UM.Den_UM1, C1.Cant/um.paritate, C1.Pret*um.paritate, C1.ProcDisc, C1.Obs, C1.ZileC,
    NVL(ac.denumire,obj.denumire), NVL(ac.codextern,obj.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,obj.codextern,4,obj.codintern,5,obj.codvamal,6,obj.codplu),obj.codextern)
    &apos;||gUserAlias||&apos;
  FROM CONTRACT1 C1
    LEFT JOIN CONTRACT C ON C1.CodCONTRACT = C.CodCONTRACT
    LEFT JOIN NPART PART ON PART.CodPart = C.Partener
    LEFT JOIN NARTOBJ OBJ ON OBJ.CodObiect = C1.CodObiect
    LEFT JOIN NARTCLI ARTCLI ON OBJ.CodObiect = ARTCLI.CodObiect AND ARTCLI.CodPart = C.Partener
    LEFT JOIN NART NA ON NA.CodArticol = OBJ.CodArticol
    LEFT JOIN NUM1 UM ON UM.CodUM1 = C1.UMSec
    LEFT JOIN NPART PROD ON PROD.CodPart = OBJ.CodProducator
    LEFT JOIN NCLASEA CA ON CA.CodClaseA = NA.Clasa
    LEFT JOIN nartcli ac ON ac.codobiect = C1.codobiect AND ac.codpart = C.partener
    LEFT JOIN nechiv e ON e.codobiect = C1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa&apos;||
    gSuplJoins||&apos;
  WHERE C.CodCONTRACT = &apos;||vCodCONTRACT||&apos;
  ORDER BY C1.CodCONTRACT1&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  ADD_LIST_PARAMS;
  COMMIT;
END;

end PKG_LIST_BASE_CONTRACTDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CURSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3FC06B39BE8CD6F171AAC16754726C726462E5E1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CURSURI IS

  vDataIni        DATE;
  vDataFin        DATE;
  vToateMonedele  BOOLEAN;
  vToateBancile   BOOLEAN;

  gUserFields     VARCHAR2(2500);
  gUserAlias      VARCHAR2(2500);
  gNullAlias      VARCHAR2(2500);
  gSuplCols       VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pDataIni       IN VARCHAR2 DEFAULT NULL,
                    pDataFin       IN VARCHAR2 DEFAULT NULL,
                    pToateMonedele IN NUMBER   DEFAULT 1,
                    pToateBancile  IN NUMBER   DEFAULT 1,
                    V_CODJOB1      IN NUMBER   DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataIni        := to_date(pDataIni,&apos;DD.MM.YYYY&apos;);
  vDataFin        := to_date(pDataFin,&apos;DD.MM.YYYY&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  vToateMonedele  := Coalesce(pToateMonedele, 1) = 1;
  vToateBancile   := Coalesce(pToateBancile,  1) = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;NMONEDA M, NBANK B&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;( DATA, CURS, DEN_BANK, SIMB_BANK, DEN_MON, SIMB_MON&apos;||gUserFields||&apos;)
  SELECT M1.DATA, M1.VALOARE, B.DENUMIRE, B.SIMBOL, M.DEN_MONEDA, M.SIMBOL&apos;||gUserAlias||&apos;
  FROM nmonede1 m1
    INNER JOIN nmonede m ON m.codmoneda = m1.codmoneda
    INNER JOIN nbank b ON b.codbank = m1.codbanca&apos;||
    gSuplJoins||&apos;
  WHERE M1.DATA BETWEEN :1 AND :2&apos;;

  IF NOT vToateMonedele THEN
    sInsert:= sInsert ||&apos;
    AND m1.codmoneda IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)&apos;;
  END IF;
  IF NOT vToateBancile THEN
    sInsert:= sInsert ||&apos;
    AND m1.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANCA&apos;&apos;)&apos;;
  END IF;

  EXECUTE IMMEDIATE sInsert USING vDataIni, vDataFin;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_CURSURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_CUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA4159865150845AB8CFF11512756534EBCAB676</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_CUSTOM IS

  gUserFields CLOB;
  gUserAlias  CLOB;
  gNullAlias  CLOB;
  gSuplCols   CLOB;
  gSuplJoins  CLOB;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

procedure TEST_PRELANSARE(aLISTID in number) is
sPrelansare CLOB;
sVariabile CLOB;
sSQL CLOB;
begin
  begin
    select trim(prelansare), trim(variabile) into sPrelansare, sVariabile from winmadmin.menuliste where listid = aLISTID;
  exception when others then sPrelansare := &apos;&apos;; sVariabile := &apos;&apos;;
  end;
  sSQL := &apos;&apos;;
  if sVariabile &lt;&gt; empty_clob() then
    sSQL := &apos;DECLARE &apos;||sVariabile;
  end if;
  if sPrelansare &lt;&gt; empty_clob() then
    sSQL := sSQL||&apos;BEGIN &apos;||sPrelansare||&apos; END;&apos;;
  end if;
  execute immediate sSQL;
end;

PROCEDURE TESTSTOC
is
begin
 pkg_globals.lstDATASTOP := sysdate;
 execute immediate &apos;begin PKG_RESTAURANT.MAKE_ALL_STOC_LA_DATA(to_char(pkg_globals.DATASTOP,&apos;&apos;dd.mm.yyyy&apos;&apos;)); end;&apos;;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sSelect   CLOB;
  sPrelansare CLOB;
  sVariabile CLOB;
  sSQL CLOB;
BEGIN
  PKG_GLOBALS.SETPARAMS_CUSTOM(aLISTID,aLISTVER);
  --prelansare
  begin
    select trim(prelansare), trim(variabile) into sPrelansare, sVariabile from winmadmin.menuliste where listid = aLISTID;
  exception when others then sPrelansare := &apos;&apos;; sVariabile := &apos;&apos;;
  end;
  sSQL := &apos;&apos;;
  if sVariabile &lt;&gt; empty_clob() then
    sSQL := &apos;DECLARE &apos;||sVariabile;
  end if;
  if sPrelansare &lt;&gt; empty_clob() then
    sSQL := sSQL||&apos;BEGIN &apos;||sPrelansare||&apos; END;&apos;;
  end if;
  if sSQL &lt;&gt; empty_clob() then
    begin
      execute immediate sSQL;
    exception when others then null;
    end;
  end if;
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;&apos;;--&apos;TMP_MANEVRA T&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF gSuplJoins IS NULL
  THEN gSuplJoins := &apos;DUAL&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(CUST_ListId&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT &apos;||aLISTID||&apos; CUST_ListId&apos;||gUserAlias||&apos;
  FROM &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

END pkg_list_base_custom; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_D390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0F9AF4E62204441AA7002DB589E1DA9F87652F6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_D390 IS

  vCodD390 D390.CODD390%TYPE;
  
  vDataS       DATE;
  vDataF       DATE;
 
PROCEDURE SETPARAMS( pCodD390  IN NUMBER ,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      ) IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vCodD390 := pCodD390 ;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(Tip, Tara, CodO, DenO, Baza, OBS)&apos;;

  sSelect := &apos;
  SELECT TIP, TARA, CODO, DENO, BAZA, OBS
  FROM D390O
  WHERE BAZA &lt;&gt; 0 AND CodD390 = &apos;||vCodD390;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_D390;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_D390BULK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A604931F40A8A3F77A69F8448F9A2CC73A8B77AE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_D390BULK IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  gSuplCols := &apos;D390 D, D390O DO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    AnLuna, ObsD,
    Tip, Tara, CodO, DenO, Baza, OBS &apos;||gUserFields||&apos;)
  SELECT
    D.AN||&apos;&apos;.&apos;&apos;||To_Char(D.LunaD,&apos;&apos;00&apos;&apos;) AnLuna, D.Obs ObsD,
    DO.TIP, DO.TARA, DO.CODO, DO.DENO, DO.BAZA, DO.OBS &apos;||gUserAlias||&apos;
  FROM D390 D
    INNER JOIN D390O DO ON DO.CodD390 = D.CodD390&apos;||
    gSuplJoins||&apos; 
  WHERE DO.BAZA &lt;&gt; 0
    AND D.An*12+D.LunaD BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_D390BULK;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_D394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1FD61079BC2D1ECA6D4C28CB3E07379F04656ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_D394 IS

  vCodD394 D394.CODD394%TYPE;

PROCEDURE SETPARAMS( pCodD394  IN NUMBER) IS
BEGIN
  vCodD394 := pCodD394 ;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sSelectL VARCHAR2(10000);
  sSelectA VARCHAR2(10000);
  sSelectV VARCHAR2(10000);
  sSelectC VARCHAR2(10000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
   TipOperatiune, PREFIXCIF, CISTVABFP, DenBFP, Baza, TVA, NRFACT, Sursa, OBS, TI,
   CUICorect)&apos;;

  sSelectL := &apos;
  SELECT
    TipOperatiune, CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;&apos;RO&apos;&apos; THEN &apos;&apos;RO&apos;&apos; ELSE &apos;&apos; &apos;&apos; END PREFIXCIF, CISTVABFP, DenBFP, Baza, TVA, NRFACT, DECODE(Generat,1,&apos;&apos;E&apos;&apos;,2,&apos;&apos;T&apos;&apos;,3,&apos;&apos;F&apos;&apos;,4,&apos;&apos;M&apos;&apos;) Sursa, OBS, &apos;&apos;NU&apos;&apos; TI,
    CASE cif_valid(CISTVABFP) WHEN 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect
  FROM D394L
  WHERE CodD394 = &apos;||vCodD394;

  sSelectA := &apos;
  SELECT
    TipOperatiune, CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;&apos;RO&apos;&apos; THEN &apos;&apos;RO&apos;&apos; ELSE &apos;&apos; &apos;&apos; END PREFIXCIF, CISTVABFP, DenBFP, Baza, TVA, NRFACT, DECODE(Generat,1,&apos;&apos;E&apos;&apos;,2,&apos;&apos;T&apos;&apos;,3,&apos;&apos;F&apos;&apos;,4,&apos;&apos;M&apos;&apos;) Sursa, OBS, &apos;&apos;NU&apos;&apos; TI,
    CASE cif_valid(CISTVABFP) WHEN 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect
  FROM D394A
  WHERE CodD394 = &apos;||vCodD394;

  sSelectV := &apos;
  SELECT
    TipOperatiune, CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;&apos;RO&apos;&apos; THEN &apos;&apos;RO&apos;&apos; ELSE &apos;&apos; &apos;&apos; END PREFIXCIF, CISTVABFP, DenBFP, Baza, TVA, NRFACT, DECODE(Generat,1,&apos;&apos;E&apos;&apos;,2,&apos;&apos;T&apos;&apos;,3,&apos;&apos;F&apos;&apos;,4,&apos;&apos;M&apos;&apos;) Sursa, OBS, &apos;&apos;DA&apos;&apos; TI,
    CASE cif_valid(CISTVABFP) WHEN 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect
  FROM D394V
  WHERE CodD394 = &apos;||vCodD394;

  sSelectC := &apos;
  SELECT
    TipOperatiune, CASE WHEN Upper(SubStr(Trim(CFText),1,2)) = &apos;&apos;RO&apos;&apos; THEN &apos;&apos;RO&apos;&apos; ELSE &apos;&apos; &apos;&apos; END PREFIXCIF, CISTVABFP, DenBFP, Baza, TVA, NRFACT, DECODE(Generat,1,&apos;&apos;E&apos;&apos;,2,&apos;&apos;T&apos;&apos;,3,&apos;&apos;F&apos;&apos;,4,&apos;&apos;M&apos;&apos;) Sursa, OBS, &apos;&apos;DA&apos;&apos; TI,
    CASE cif_valid(CISTVABFP) WHEN 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect
  FROM D394C
  WHERE CodD394 = &apos;||vCodD394;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectL, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectV, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectC, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_D394;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DECONTPARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C003731A7CAEAEE2ADEE7038C1AF40665443FA00</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DECONTPARTICIP is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert varchar2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);

  gSuplCols := &apos;ncont c, ncont1 c1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos;(
     SIMBOL, 
     DEN_CONT,
     VENIT,
     CHELT,
     REAL,
     ASOC,
     PROC
   &apos;||gUserFields||&apos;)
  SELECT
    tmp.simbol,
    tmp.den_cont,
    case 
      when substr(tmp.simbol,1,1) = pkg_categconst.GetValConstanta(&apos;&apos;ClasaVenit&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru) then tmp.RULAJC * p.procent / 100
      else 0
    end,
    case 
      when substr(tmp.simbol,1,1) = pkg_categconst.GetValConstanta(&apos;&apos;ClasaChelt&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru) then tmp.rulajd * p.procent / 100
      else 0
    end,
    case 
      when substr(tmp.simbol,1,1) = pkg_categconst.GetValConstanta(&apos;&apos;ClasaVenit&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru) then tmp.RULAJC * p.procent / 100
      when substr(tmp.simbol,1,1) = pkg_categconst.GetValConstanta(&apos;&apos;ClasaChelt&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru) then - tmp.rulajd  * p.procent / 100
    end,    
    p.denumire,
    p.procent &apos;||gUserAlias||&apos;
  FROM tmp_list_balanta_sec tmp
       inner join ncont  c  on tmp.simbol = c.simbol 
       inner join ncont1 c1 on c1.codcont = c.codcont AND (pkg_globals.getanlucru * 12 + pkg_globals.getlunalucru) BETWEEN c1.ALSTART and c1.ALSTOP,
       particip p
  WHERE (substr(tmp.simbol,1,1)=pkg_categconst.GetValConstanta(&apos;&apos;ClasaChelt&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru) or
         substr(tmp.simbol,1,1)=pkg_categconst.GetValConstanta(&apos;&apos;ClasaVenit&apos;&apos;,pkg_globals.getanlucru,pkg_globals.getlunalucru)) 
        and c1.PARTICIPATIUNE = 1&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert,  aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DECONTPARTICIP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DEVUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EDCA1120A1A99422F95BC9F517DEA6C9FCC40B1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DEVUTILAJ is

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);
  vCodUtilaj20 NUMBER(20);

PROCEDURE setParams (pCodUtilaj20 in number) IS
BEGIN
  vCodUtilaj20 := pCodUtilaj20;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
SSQL VARCHAR2(10000);
ValCamp number(20);
vCodProiect number(20);
Display varchar2(500);
ValDisplay varchar2(1000);
BEGIN
  FOR v_rec IN (
    SELECT u.tiputilaj, u.eticheta, u.flota, CLI.DEN_PART CLIENT, FURN.DEN_PART FURNIZOR, U.NRCONTR, TO_CHAR(U.DATACONTR,&apos;DD.MM.YYYY&apos;) DATACONTR, U.DOC,
           OBJ.DENUMIRE, U20.NRDOC NRPROBLEMA, U20.DATADOC DATAPROBLEMA, U20.DESCRIERE, UT.USERNAME OPERATOR, U20.OBS OBS, IV.DENUMIRE INTERVENTIE
    FROM utilaje20 u20
         INNER JOIN utilaje2 u2 ON u20.codutilaj20 = u2.codutilaj20
         INNER JOIN utilaje u on u.codutilaj = u2.codutilaj and u.codutilaj = u20.codutilaj
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = U.CODOBIECT
         INNER JOIN NINTERVENTIIAUTO IV ON IV.CODINTERVENTIIAUTO = U2.INTERVENTIE
         LEFT JOIN NPART CLI ON CLI.CODPART= U.CODPART
         LEFT JOIN NPART FURN ON FURN.CODPART = U.CODFURNIZOR
         LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = U20.OPERATOR
    WHERE U20.CodUtilaj20 = vCodUtilaj20
    ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip utilaj&apos;,                v_rec.tiputilaj);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Eticheta&apos;,                  v_rec.eticheta);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Flota&apos;,                     v_rec.flota);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Client&apos;,                    v_rec.client);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Furnizor&apos;,                  v_rec.furnizor);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - numar&apos;,          v_rec.nrcontr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - data&apos;,           v_rec.datacontr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document de vanzare&apos;,       v_rec.doc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj&apos;,                    v_rec.denumire);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - numar&apos;,          v_rec.nrproblema);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - data semnalare&apos;, v_rec.dataproblema);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - descriere&apos;,      v_rec.descriere);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - operator&apos;,       v_rec.operator);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - observatii&apos;,     v_rec.obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Interventie&apos;,               v_rec.interventie);

    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert  VARCHAR2(10000);
sInsert1 VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NART ART, NARTOBJ OBJ, ninterventiiauto iv, utilaje2 u2, iesiri1 i1, iesiri i, utilajedev dev&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    Denumire,
    UM,
    Cant,
    Pret,
    Facturabil,
    Consumabil,
    Factura,
    BonConsum,
    Interventie &apos;||gUserFields||&apos;)
  SELECT
    obj.denumire,
    um.den_um,
    dev.cant,
    dev.pret,
    case when dev.facturabil = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    case when dev.consumabil= 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    case when i.codies &gt; 0 and dev.facturabil = 1 then i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) end,
    case when bc.codies &gt; 0 and dev.consumabil = 1 then bc.prefixdoc||bc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(bc.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) end,
    (select stragg3200(iv.denumire)
     from ninterventiiauto iv
          inner join utilaje2 u2 on u2.interventie = iv.codinterventiiauto
     where u2.codutilaj20 = u20.codutilaj20
    ) &apos;||gUserAlias||&apos;
  FROM utilajedev dev
       inner join nartobj obj on obj.codobiect = dev.codobiect
       inner join nart art on art.codarticol = obj.codarticol
       inner join num um on um.codum = art.um
       inner join utilaje20 u20 on u20.codutilaj20 = dev.codutilaj20
       inner join utilaje u on u20.codutilaj = u.codutilaj
       left join iesiri i on i.codies = u20.codies
       left join iesiri bc on bc.codies = u20.codbc
  &apos;||gSuplJoins||&apos;
  WHERE dev.codutilaj20 = &apos;||vCodUtilaj20;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  PROCESSPARAMS;

  COMMIT;
END;

end PKG_LIST_BASE_DEVUTILAJ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DIFB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C553AE46CEE003A7AF1757A336741E05BC9D29DB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DIFB is

gUserFields VARCHAR2(500);
gUserAlias  VARCHAR2(500);
gNullAlias  VARCHAR2(500);
gSuplCols   VARCHAR2(500) :=&apos;&apos;;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(2000);
BEGIN
  sInsert:=
   &apos;INSERT INTO &apos;||tmpName|| &apos;(
      Simbol ,
      D_SI_D ,
      D_SI_C ,
      D_RP_D ,
      D_RP_C ,
      D_RC_D ,
      D_RC_C ,
      D_SF_D ,
      D_SF_C ,
      V_SI_D ,
      V_SI_C ,
      V_RP_D ,
      V_RP_C ,
      V_RC_D ,
      V_RC_C ,
      V_SF_D ,
      V_SF_C ,
      N_SI_D ,
      N_SI_C ,
      N_RP_D ,
      N_RP_C ,
      N_RC_D ,
      N_RC_C ,
      N_SF_D ,
      N_SF_C &apos;||gUserFields||&apos; )
    SELECT
      Simbol ,
      D_SI_D ,
      D_SI_C ,
      D_RP_D ,
      D_RP_C ,
      D_RC_D ,
      D_RC_C ,
      D_SF_D ,
      D_SF_C ,
      V_SI_D ,
      V_SI_C ,
      V_RP_D ,
      V_RP_C ,
      V_RC_D ,
      V_RC_C ,
      V_SF_D ,
      V_SF_C ,
      N_SI_D ,
      N_SI_C ,
      N_RP_D ,
      N_RP_C ,
      N_RC_D ,
      N_RC_C ,
      N_SF_D ,
      N_SF_C &apos;||gUserAlias|| &apos;
    FROM
      TMP_DIFB &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);    
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_difb;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DIFBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>006E440BBB591CC6D2D98992B0ABBFFED490E8F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DIFBJ is

  gUserFields VARCHAR2(500);
  gUserAlias  VARCHAR2(500);
  gNullAlias  VARCHAR2(500);
  gSuplCols   VARCHAR2(500) :=&apos;&apos;;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(2000);
BEGIN
  sInsert:=
   &apos;INSERT INTO &apos;||tmpName|| &apos;(
      SimbolD,
      SimbolC,
      NAV_CodDoc,
      NAV_TipDoc,
      D_INDEXLOCAL,
      D_GEST,
      D_VALOARE,
      D_VALOAREV,
      D_OBS,
      D_SUBUNITATEA,
      D_DATADOC,
      D_DOCUMENT,
      V_INDEXLOCAL,
      V_GEST,
      V_VALOARE,
      V_VALOAREV,
      V_OBS,
      V_SUBUNITATEA,
      V_DATADOC,
      V_DOCUMENT,
      N_INDEXLOCAL,
      N_GEST,
      N_VALOARE,
      N_VALOAREV,
      N_OBS,
      N_SUBUNITATEA,
      N_DATADOC,
      N_DOCUMENT &apos;||gUserFields||&apos; )
    SELECT
      SimbolD,
      SimbolC,
      CODDOC,
      TIPDOC,
      D_INDEXLOCAL,
      D_GEST,
      D_VALOARE,
      D_VALOAREV,
      D_OBS,
      D_SUBUNITATEA,
      D_DATADOC,
      D_DOCUMENT,
      V_INDEXLOCAL,
      V_GEST,
      V_VALOARE,
      V_VALOAREV,
      V_OBS,
      V_SUBUNITATEA,
      V_DATADOC,
      V_DOCUMENT,
      N_INDEXLOCAL,
      N_GEST,
      N_VALOARE,
      N_VALOAREV,
      N_OBS,
      N_SUBUNITATEA,
      N_DATADOC,
      N_DOCUMENT &apos;||gUserFields||&apos;
    FROM
      TMP_DIFBJ &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_difbj;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DIFPECOMINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>351976B5543B2B2675A379442F46C7BB595FE3DB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DIFPECOMINT IS

  gUserFields   VARCHAR2(10000);
  gUserAlias    VARCHAR2(10000);
  gNullAlias    VARCHAR2(10000);
  gSuplCols     VARCHAR2(10000);
  gSuplJoins    VARCHAR2(10000);

function getpretproiectat(acodobiect in integer, acodprodcomp in number) return number is
aPret number(20,7);
begin
  aPret := 0;
  begin
    select sum(nvl(mat.pret,0)*nvl(mat.cant,0))/decode(sum(nvl(mat.cant,0)),0,1,sum(nvl(mat.cant,0))) into aPret
    from prodmat mat
    where mat.codprodcomp = acodprodcomp
    and mat.codobiect = acodobiect;
  exception when others then aPret := 0;
  end;
  return aPret;
end;

function getpretachiz(aCodIes1 IN NUMBER) RETURN NUMBER IS
aPretM NUMBER(20,7);
begin
  aPretM := 0;
  select sum(nvl(L1.cant,0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(L1.cant,0)),0,1,sum(nvl(L1.cant,0))) into aPretM
  from iesiri1 i1
       left join livr1 l1 on i1.codies1 = l1.codies1
       left join nirstoc ns on l1.codnirstoc = ns.codnirstoc
  where i1.codies1 = aCodIes1;

  return aPretM;
end;

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(2000);
  sWith        VARCHAR2(9000);
  sSelect      VARCHAR2(32000);
  sWith1       VARCHAR2(9000);
  sSelect1     VARCHAR2(9000);
  sCondGest    VARCHAR2(1000);
  sCondObj     VARCHAR2(1000);
  sWith2       VARCHAR2(9000);
  sSelect2     VARCHAR2(19000);
  sSelect_Man  VARCHAR2(19000);
  sSelect1_Man VARCHAR2(19000);
  sWith_Man    VARCHAR2(9000);
  sWith1_Man   VARCHAR2(9000);
  sPer         VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;comanda c, formatii f, NARTOBJ OBJMAT, NARTOBJ OBJRET, NPART P, comanda1 c1, cmdprodmat mat, cmdprodmat prod&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);

  sCondGest := &apos;&apos;;
  if not pkg_list_selectgestart.AllGest then
    sCondGest := &apos;inner join tmp_manevra_liste tmpg on g.codgest = to_number(tmpg.valoare) and upper(tmpg.filtru) = &apos;&apos;CODGEST&apos;&apos; &apos;;
  end if;

  sCondObj := &apos;&apos;;
  if not pkg_list_selectgestart.AllArt then
    sCondObj := &apos;inner join tmp_manevra_liste tmp on objret.codobiect = to_number(tmp.valoare) and upper(tmp.filtru) = &apos;&apos;CODOBIECT&apos;&apos; &apos;;
  end if;

  IF pkg_list_selectgestart.DataStart = pkg_list_selectgestart.DataFin
  THEN sPer := &apos;= to_date(&apos;&apos;&apos;||To_Char(pkg_list_selectgestart.DataStart,&apos;DD.MM.YYYY&apos;)||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  ELSE sPer := &apos; between to_date(&apos;&apos;&apos;||To_Char(pkg_list_selectgestart.DataStart,&apos;DD.MM.YYYY&apos;)||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) and to_date(&apos;&apos;&apos;||To_Char(pkg_list_selectgestart.DataFin,&apos;DD.MM.YYYY&apos;)||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc,
    NAV_TipDoc,
    Articol,
    UM,
    Pret,
    CantCom,
    CantReal,
    DifCant,
    DifVal,
    SerieCarnet,
    SimbolCarnet,
    DenCarnet,
    NrComInt,
    DataComInt,
    Produs,
    CantComProd,
    CantRealProd,
    CantRebutProd,
    Sursa,
    RestCom,
    Client,
    DataComCli,
    NrComCli,
    ValComCli,
    Sectie,
    PretPr,
    PretC,
    PretR,
    PVProdus,
    CantLuna,
    PretLuna,
    CantNorma,
    CantRealLuna,
    CantRebutLuna,
    Ordine,
    TU,
    Tarif,
    CodComanda1,
    CodObiect,
    CodMaterial &apos;||gUserFields||&apos;) &apos;;

  sWith := &apos;
  WITH
    REALIZARI as (
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and i.an*12+i.luna &gt;= (select ANINITIAL * 12 + LUNAINITIALA from firmaluni where rownum = 1)
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and i.tiptranzactie &lt;&gt; 9
      group by mat.codcmdprodmat
      union all
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1    c1   on mat.codcomanda1   = c1.codcomanda1
            inner join comanda     c    on c1.codcomanda     = c.codcomanda
            inner join iesprodlink link on mat.codcmdprodmat = link.codcmdprodmat
            inner join iesiri1     i1   on link.codies1      = i1.codies1
            inner join iesiri      i    on i1.codies         = i.codies
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and i.an*12+i.luna &gt;= (select ANINITIAL * 12 + LUNAINITIALA from firmaluni where rownum = 1)
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and c1.consum = 2 and mat.tip = 0
      group by mat.codcmdprodmat
        ),
    REBUT as (
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and i.tiptranzactie = 9
      group by mat.codcmdprodmat
        ),
    REALIZARIL as (
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru and i.tiptranzactie &lt;&gt; 9
      group by mat.codcmdprodmat
        ),
    REBUTL as (
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1 = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru and i.tiptranzactie = 9
      group by mat.codcmdprodmat
        ),
    CONSUMURI as (
      select
        mat.codcmdprodmat,
        sum(l1.cant) cant,
        sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM
      from cmdprodmat mat
            inner join comanda1    c1      on mat.codcomanda1   = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda     = c.codcomanda
            inner join iesprodlink ieslink on mat.codcmdprodmat = ieslink.codcmdprodmat
            inner join iesiri1     i1      on ieslink.codies1   = i1.codies1
            inner join iesiri      i       on i1.codies         = i.codies
            inner join livr        l       on i.codies          = l.codies
            inner join livr1       l1      on i1.codies1        = l1.codies1 and l1.codlivr = l.codlivr
            inner join nirstoc     ns      on l1.codnirstoc     = ns.codnirstoc
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and mat.codobiect = i1.codobiect
      group by mat.codcmdprodmat
      union all
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant,
        sum(i1.cant*i1.pu)/sum(i1.cant) PAchizM
      from cmdprodmat mat
            inner join comanda1    c1      on mat.codcomanda1 = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda   = c.codcomanda
            inner join intrari1    i1      on c1.codcomanda1  = i1.codcmdint1
            inner join intrari     i       on i1.codintr      = i.codintr
            inner join prodmat     m       on m.codmat        = mat.codprodmat
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and mat.codobiect = i1.codobiect and i1.tiplinie = &apos;&apos;S&apos;&apos; and m.tip = 6
      group by mat.codcmdprodmat
    ),
    CONSUMURIL as (
      select
        mat.codcmdprodmat,
        sum(l1.cant) cant,
        sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM
      from cmdprodmat mat
            inner join comanda1    c1      on mat.codcomanda1   = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda     = c.codcomanda
            inner join iesprodlink ieslink on mat.codcmdprodmat = ieslink.codcmdprodmat
            inner join iesiri1     i1      on ieslink.codies1   = i1.codies1
            inner join iesiri      i       on i1.codies         = i.codies
            left  join livr        l       on i.codies          = l.codies
            left  join livr1       l1      on i1.codies1        = l1.codies1 and l1.codlivr = l.codlivr
            left  join nirstoc     ns      on l1.codnirstoc     = ns.codnirstoc
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru
            and mat.codobiect = i1.codobiect
      group by mat.codcmdprodmat
      union all
      select
        mat.codcmdprodmat,
        sum(i1.cant) cant,
        sum(i1.cant*i1.pu)/sum(i1.cant) PAchizM
      from cmdprodmat mat
            inner join comanda1    c1      on mat.codcomanda1 = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda   = c.codcomanda
            inner join intrari1    i1      on c1.codcomanda1  = i1.codcmdint1
            inner join intrari     i       on i1.codintr      = i.codintr
            inner join prodmat     m       on m.codmat        = mat.codprodmat
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and mat.codobiect = i1.codobiect and i1.tiplinie = &apos;&apos;S&apos;&apos; and m.tip = 6
            and i.an*12+i.luna = pkg_globals.anlunalucru
      group by mat.codcmdprodmat  )
            &apos;;
  sSelect :=&apos;
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    objmat.DENUMIRE,
    um.den_um,
    mat.pret,
    case when mat.tip = 0 then 0 else nvl(mat.cant, 0) end,
    nvl(consumuri.cant, 0),
    case when mat.tip = 0 then 0 else nvl(consumuri.cant, 0) - nvl(mat.cant,0) end,
    case when mat.tip = 0 then 0 else round((nvl(consumuri.cant, 0) - nvl(mat.cant,0)) * nvl(consumuri.PAchizM,0), 2) end,
    c.seriadoc,
    cdoc.simbol,
    cdoc.denumire,
    c.nrdoc,
    c.datadoc,
    ObjRet.denumire,
    c1.cantacceptat,
    case when mat.tip = 0 then nvl(realizari.cant, 0) else 0 end,
    case when mat.tip = 0 then nvl(rebut.cant, 0) else 0 end,
    case when mat.tip = 0 then &apos;&apos;Produs&apos;&apos; else &apos;&apos;Materiale&apos;&apos; end Sursa,
    c1.cantacceptat - nvl(realizari.cant,0),
    p.den_part,
    ccli.datadoc,
    ccli.nrdoc,
    ccli.valoare,
    g.den_gest,
    case when mat.tip = 0 then c1.pu else prodmat.pret end PretPr,
    nvl(consumuri.PAchizM,0),
    objmat1.pretreferinta,
    pm.lei,
    case when mat.tip = 0 then nvl(consumuriL.cant, 0) else 0 end,
    nvl(consumuriL.PAchizM,0),
    nvl(realizari.cant, 0)/decode(nvl(c1.cantacceptat,0),0,1,nvl(c1.cantacceptat,0)) * mat.cant,
    case when mat.tip = 0 then nvl(realizariL.cant,0) else 0 end,
    case when mat.tip = 0 then nvl(rebutL.cant,0) else 0 end,
    mat.IndexLocal,
    0,
    0,
    c1.codcomanda1,
    PROD.CODOBIECT,
    case when mat.tip = 1 then mat.codobiect else 0 end CodMaterial&apos;||gUserAlias||&apos;
  FROM cmdprodmat mat
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1  = MAT.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN comanda1        c1 ON mat.codcomanda1   = c1.codcomanda1
    INNER JOIN comanda          c ON c1.codcomanda     = c.codcomanda
    INNER JOIN ngest            g ON c.codgest         = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect     = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um         = um.codum
    INNER JOIN NARTOBJ     ObjRet ON PROD.codobiect    = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP    = C1.CODRETETA &apos;
    ||sCondObj||
    sCondgest||&apos;
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc       = cdoc.codcarnet
    LEFT  JOIN realizari          on mat.codcmdprodmat = realizari.codcmdprodmat
    LEFT  JOIN rebut              on mat.codcmdprodmat = rebut.codcmdprodmat
    LEFT  JOIN realizariL         on mat.codcmdprodmat = realizariL.codcmdprodmat
    LEFT  JOIN rebutL             on mat.codcmdprodmat = rebutL.codcmdprodmat
    LEFT  JOIN consumuri          on mat.codcmdprodmat = consumuri.codcmdprodmat
    LEFT  JOIN consumuriL         on mat.codcmdprodmat = consumuriL.codcmdprodmat
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1    = Clink.COdComanda1
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda   = ccli1.codcomanda
    left  join npart            p on p.codpart         = ccli.partener
    left  join nartobj1   objmat1 on objmat1.codobiect = objmat.codobiect AND (C.AN*12+C.LUNA) BETWEEN objmat1.ALStart and objmat1.ALStop
    LEFT  JOIN pretm           pm ON pm.codobiect      = c1.codobiect     AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN prodmat            ON prodmat.codmat    = mat.codprodmat
    LEFT  JOIN formatii         f ON c.codformatie     = f.codformatie&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||&apos;
        AND C.AN * 12 + C.LUNA &gt;= (select ANINITIAL * 12 + LUNAINITIALA from firmaluni where rownum = 1)&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;)||&apos;
  UNION ALL
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    objmat.DENUMIRE,
    um.den_um,
    mat.pret,
    case when mat.tip = 0 then 0 else nvl(mat.cant, 0) end,
    nvl(consumuri.cant, 0),
    case when mat.tip = 0 then 0 else nvl(consumuri.cant, 0) - nvl(mat.cant,0) end,
    case when mat.tip = 0 then 0 else round((nvl(consumuri.cant, 0) - nvl(mat.cant,0)) * nvl(consumuri.PAchizM,0), 2) end,
    c.seriadoc,
    cdoc.simbol,
    cdoc.denumire,
    c.nrdoc,
    c.datadoc,
    ObjRet.denumire,
    c1.cantacceptat,
    case when mat.tip = 0 then nvl(realizari.cant, 0) else 0 end,
    case when mat.tip = 0 then nvl(rebut.cant, 0) else 0 end,
    case when mat.tip = 0 then &apos;&apos;Produs&apos;&apos; else &apos;&apos;Materiale&apos;&apos; end Sursa,
    c1.cantacceptat - nvl(realizari.cant,0),
    p.den_part,
    ccli.datadoc,
    ccli.nrdoc,
    ccli.valoare,
    g.den_gest,
    case when mat.tip = 0 then c1.pu else prodmat.pret end PretPr,
    nvl(consumuri.PAchizM,0),
    objmat1.pretreferinta,
    pm.lei,
    case when mat.tip = 0 then nvl(consumuriL.cant, 0) else 0 end,
    nvl(consumuriL.PAchizM,0),
    nvl(realizari.cant, 0)/decode(nvl(c1.cantacceptat,0),0,1,nvl(c1.cantacceptat,0)) * mat.cant,
    case when mat.tip = 0 then nvl(realizariL.cant,0) else 0 end,
    case when mat.tip = 0 then nvl(rebutL.cant,0) else 0 end,
    mat.IndexLocal,
    0,
    0,
    c1.codcomanda1,
    PROD.CODOBIECT,
    case when mat.tip = 1 then mat.codobiect else 0 end CodMaterial&apos;||gUserAlias||&apos;
  FROM cmdprodmat mat
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1  = MAT.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN comanda1        c1 ON mat.codcomanda1   = c1.codcomanda1
    INNER JOIN comanda          c ON c1.codcomanda     = c.codcomanda
    INNER JOIN ngest            g ON c.codgest         = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect     = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um         = um.codum
    INNER JOIN NARTOBJ     ObjRet ON PROD.codobiect    = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP    = C1.CODRETETA &apos;
    ||sCondObj||
    sCondgest||&apos;
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet
    LEFT  JOIN realizari          on mat.codcmdprodmat = realizari.codcmdprodmat
    LEFT  JOIN rebut              on mat.codcmdprodmat = rebut.codcmdprodmat
    LEFT  JOIN realizariL         on mat.codcmdprodmat = realizariL.codcmdprodmat
    LEFT  JOIN rebutL             on mat.codcmdprodmat = rebutL.codcmdprodmat
    LEFT  JOIN consumuri          on mat.codcmdprodmat = consumuri.codcmdprodmat
    LEFT  JOIN consumuriL         on mat.codcmdprodmat = consumuriL.codcmdprodmat
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1 = Clink.COdComanda1
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda = ccli1.codcomanda
    left  join npart            p on p.codpart = ccli.partener
    left  join nartobj1   objmat1 on objmat1.codobiect = objmat.codobiect
    LEFT  JOIN pretm           pm ON pm.codobiect = c1.codobiect AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN prodmat            ON prodmat.codmat = mat.codprodmat
    LEFT  JOIN formatii         f ON c.codformatie = f.codformatie&apos;||
    gSuplJoins||&apos;
  WHERE c1.cantacceptat &lt;&gt; 0 and c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||&apos; AND C.AN * 12 + C.LUNA &lt; (select ANINITIAL * 12 + LUNAINITIALA from firmaluni where rownum = 1)
    AND objmat1.ANSTART * 12 + objmat1.LUNASTART = (select ANINITIAL * 12 + LUNAINITIALA from firmaluni where rownum = 1) &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;);

  sWith2 := &apos;
  WITH
    CONSUMURI as (
      select
        i1.codobiect,
        sum(l1.cant) cant,
        sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM,
        mat.codcomanda1,
        mat.IndexLocal Ordine,
        mat.codcmdprodmat
      from cmdprodmat mat
            inner join comanda1    c1      on mat.codcomanda1   = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda     = c.codcomanda
            inner join iesprodlink ieslink on mat.codcmdprodmat = ieslink.codcmdprodmat
            inner join iesiri1     i1      on ieslink.codies1   = i1.codies1
            inner join iesiri      i       on i1.codies         = i.codies
            left join livr         l       on i.codies          = l.codies
            left join livr1        l1      on i1.codies1        = l1.codies1 and l1.codlivr = l.codlivr
            left join nirstoc      ns      on l1.codnirstoc     = ns.codnirstoc
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and mat.codobiect &lt;&gt; i1.codobiect
      group by mat.IndexLocal, i1.codobiect, mat.codcomanda1, mat.codcmdprodmat  ),
    CONSUMURIL as (
      select
        i1.codobiect,
        sum(l1.cant) cant,
        sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM,
        mat.codcomanda1,
        mat.codcmdprodmat
      from cmdprodmat mat
           inner join comanda1    c1      on mat.codcomanda1   = c1.codcomanda1
           inner join comanda     c       on c1.codcomanda     = c.codcomanda
           inner join iesprodlink ieslink on mat.codcmdprodmat = ieslink.codcmdprodmat
           inner join iesiri1     i1      on ieslink.codies1   = i1.codies1
           inner join iesiri      i       on i1.codies         = i.codies
           left  join livr        l       on i.codies          = l.codies
           left  join livr1       l1      on i1.codies1        = l1.codies1 and l1.codlivr = l.codlivr
           left  join nirstoc     ns      on l1.codnirstoc     = ns.codnirstoc
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and mat.codobiect &lt;&gt; i1.codobiect
            and i.an*12+i.luna = pkg_globals.anlunalucru
      group by i1.codobiect, mat.codcomanda1, mat.codcmdprodmat  )
            &apos;;
  sSelect2 :=&apos;
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    objmat.DENUMIRE ,
    um.den_um,
    c1.pu,
    0,
    nvl(consumuri.cant, 0),
    nvl(consumuri.cant, 0),
    round(nvl(consumuri.cant, 0) * nvl(consumuri.PAchizM,0), 2),
    cdoc.serie,
    cdoc.simbol,
    cdoc.denumire,
    c.nrdoc,
    c.datadoc,
    ObjRet.denumire,
    c1.cantacceptat,
    0,
    0,
    &apos;&apos;Materiale&apos;&apos; Sursa,
    c1.cantacceptat,
    p.den_part,
    ccli.datadoc,
    ccli.nrdoc,
    ccli.valoare,
    g.den_gest,
    PretPr.Pret,
    nvl(consumuri.PAchizM,0),
    objmat1.pretreferinta,
    pm.lei,
    0,
    nvl(consumuriL.PAchizM,0),
    0,
    0,
    0,
    Consumuri.Ordine,
    0,
    0,
    C1.CODCOMANDA1,
    PROD.CODOBIECT,
    case when mat.tip = 1 then mat.codobiect else 0 end CodMaterial
     &apos;||gUserAlias||&apos;
  FROM consumuri
    INNER JOIN comanda1        c1 ON consumuri.codcomanda1 = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1      = C1.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN CMDPRODMAT    MAT  ON MAT.CODCMDPRODMAT     = CONSUMURI.CODCMDPRODMAT
    INNER JOIN comanda          c ON c1.codcomanda         = c.codcomanda
    INNER JOIN ngest            g ON c.codgest             = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON consumuri.codobiect   = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol     = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um             = um.codum
    INNER JOIN NARTOBJ     ObjRet ON PROD.codobiect        = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP        = C1.CODRETETA &apos;
    ||sCondgest
    ||sCondObj|| &apos;
    left  join (select mat.codprodcomp, mat.codobiect, sum(nvl(mat.pret,0)*nvl(mat.cant,0))/decode(sum(nvl(mat.cant,0)),0,1,sum(nvl(mat.cant,0))) Pret
                from prodmat mat
                group by mat.codprodcomp,mat.codobiect ) PretPr on PretPr.codobiect = consumuri.codobiect and PretPr.CodProdComp = c1.codreteta
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc           = cdoc.codcarnet
    LEFT  JOIN consumuriL         on consumuri.codcomanda1 = consumuriL.codcomanda1
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1        = Clink.COdComanda1
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda       = ccli1.codcomanda
    left  join npart            p on p.codpart             = ccli.partener
    left  join nartobj1   objmat1 on objmat1.codobiect     = objmat.codobiect AND (C.AN*12+C.LUNA) BETWEEN objmat1.ALStart and objmat1.ALStop
    LEFT  JOIN pretm           pm ON pm.codobiect          = c1.codobiect     AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN formatii         f ON c.codformatie         = f.codformatie&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;);

  sWith1 := &apos;
  WITH CONS as (
    select
      i1.codobiect,
      c1.codcomanda1,
      sum(l1.cant) cant,
      sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM
    from iesiri1 i1
         inner join iesiri      i  on i.codies      = i1.codies
         inner join comanda1    c1 on i1.codcmdint1 = c1.codcomanda1
         left  join iesprodlink il on i1.codies1    = il.codies1
         left  join livr        l  on i.codies      = l.codies
         left  join livr1       l1 on i1.codies1    = l1.codies1 and l1.codlivr = l.codlivr
         left  join nirstoc     ns on l1.codnirstoc = ns.codnirstoc
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and nvl(i1.codcmdint1, 0) &gt; 0 and nvl(il.codcmdprodmat, 0) = 0
    group by i1.codobiect, c1.codcomanda1 ),
    CONSUMURIL as (
    select
      i1.codobiect,
      c1.codcomanda1,
      sum(l1.cant) cant,
      sum(nvl(abs(L1.cant),0)*(nvl(NS.Pret,0)-nvl(NS.adaos,0)))/decode(sum(nvl(abs(L1.cant),0)),0,1,sum(nvl(abs(L1.cant),0))) PAchizM
    from iesiri1 i1
          inner join iesiri      i  on i.codies      = i1.codies
          inner join comanda1    c1 on i1.codcmdint1 = c1.codcomanda1
          left  join iesprodlink il on i1.codies1    = il.codies1
          left  join livr        l  on i.codies      = l.codies
          left  join livr1       l1 on i1.codies1    = l1.codies1 and l1.codlivr = l.codlivr
          left  join nirstoc     ns on l1.codnirstoc = ns.codnirstoc
    where nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and nvl(i1.codcmdint1, 0) &gt; 0 and nvl(il.codcmdprodmat, 0) = 0
          and i.an*12+i.luna = pkg_globals.anlunalucru
    group by i1.codobiect, c1.codcomanda1 )&apos;;
  sSelect1 := &apos;
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    objmat.DENUMIRE, um.den_um, 0 pret, 0, nvl(cons.cant, 0),
    nvl(cons.cant, 0), 0 ,
    cdoc.serie, cdoc.simbol, cdoc.denumire, c.nrdoc, c.datadoc, ObjRet.denumire, c1.cantacceptat, c1.cantacceptat - PROD.REST, 0,
    &apos;&apos;Materiale&apos;&apos; Sursa,
    PROD.REST, p.den_part, ccli.datadoc, ccli.nrdoc, ccli.valoare, g.den_gest,
    0 PretPr,
    nvl(cons.PAchizM,0),objmat1.pretreferinta, pm.lei,
    0,
    nvl(consumuriL.PAchizM,0),
    0,
    0,
    0,
    0,
    0,
    0,
    C1.CODCOMANDA1,
    PROD.CODOBIECT,
    0 CodMaterial &apos;||gUserAlias||&apos;
  FROM cons
    INNER JOIN comanda1        c1 ON cons.codcomanda1  = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1  = C1.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN comanda          c ON c1.codcomanda     = c.codcomanda
    INNER JOIN ngest            g ON c.codgest         = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON cons.codobiect    = objmat.codobiect
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um         = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect      = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP    = C1.CODRETETA &apos;
    ||sCondgest
    ||sCondObj|| &apos;
    LEFT JOIN CMDPRODMAT      MAT ON MAT.CODCOMANDA1   = C1.CODCOMANDA1 - C1.CODCOMANDA1
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc       = cdoc.codcarnet
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1    = Clink.COdComanda1
    LEFT  JOIN consumuriL         on cons.codcomanda1  = consumuriL.codcomanda1 and CONSUMURIL.codobiect = cons.codobiect
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda   = ccli1.codcomanda
    left  join npart            p on p.codpart         = ccli.partener
    left  join nartobj1   objmat1 on objmat1.codobiect = objmat.codobiect AND (C.AN*12+C.LUNA) BETWEEN objmat1.ALStart and objmat1.ALStop
    LEFT  JOIN pretm           pm ON pm.codobiect      = c1.codobiect     AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN formatii         f ON c.codformatie     = f.codformatie&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;);

  --MANOPERA--
  sWith_Man := &apos;
  WITH
    REALIZARI as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and i.tiptranzactie &lt;&gt; 9
      group by c1.codcomanda1
        ),
    REALIZARIL as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru and i.tiptranzactie &lt;&gt; 9
      group by c1.codcomanda1
        ),
    CONSUMURI as (
      select
        man.codcmdprodman,
        sum(p2.realizat) cant
      from cmdprodman man
            inner join comanda1    c1      on man.codcomanda1     = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda       = c.codcomanda
            inner join manprodlink manlink on man.codcmdprodman   = manlink.codcmdprodman
            inner join raportp2    p2      on manlink.codraportp2 = p2.codraportp2
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
      group by man.codcmdprodman),
    CONSUMURIL as (
      select
        man.codcmdprodman,
        sum(p2.realizat) cant
      from cmdprodman man
            inner join comanda1    c1      on man.codcomanda1     = c1.codcomanda1
            inner join comanda     c       on c1.codcomanda       = c.codcomanda
            inner join manprodlink manlink on man.codcmdprodman   = manlink.codcmdprodman
            inner join raportp2    p2      on manlink.codraportp2 = p2.codraportp2
            inner join raportp1    p1      on p1.codraportp1      = p2.codraportp1
            inner join raportp     p       on p.codraportp        = p1.codraportp
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and p.an*12+p.luna = pkg_globals.anlunalucru
      group by man.codcmdprodman
        ) &apos;;
  sSelect_Man :=&apos;
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    op.DENUMIRE,
    &apos;&apos;&apos;&apos; ,
    0,
    man.cant,
    nvl(consumuri.cant, 0),
    nvl(consumuri.cant, 0) - nvl(man.cant,0),
    (nvl(consumuri.cant, 0) - nvl(man.cant,0)) * round(man.tu * t.tarif/60,5),
    c.seriadoc,
    cdoc.simbol,
    cdoc.denumire,
    c.nrdoc,
    c.datadoc,
    ObjRet.denumire,
    c1.cantacceptat,
    nvl(realizari.cant,0),
    0,
    &apos;&apos;Manopera&apos;&apos;,
    c1.cantacceptat - nvl(realizari.cant,0),
    p.den_part,
    ccli.datadoc,
    ccli.nrdoc,
    ccli.valoare,
    g.den_gest,
    c1.pu,
    0,
    0,
    pm.lei,
    nvl(consumuriL.cant, 0),
    0,
    nvl(realizari.cant, 0)/decode(nvl(c1.cantacceptat,0),0,1,nvl(c1.cantacceptat,0)) * man.cant,
    nvl(realizariL.cant,0),
    0,
    man.IndexLocal,
    man.TU,
    T.Tarif,
    C1.CODCOMANDA1,
    PROD.CODOBIECT,
    0 CodMaterial &apos;||gUserAlias||&apos;
  FROM cmdprodman man
    INNER JOIN comanda1        c1 ON man.codcomanda1  = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN comanda          c ON c1.codcomanda    = c.codcomanda
    INNER JOIN ngest            g ON c.codgest        = g.codgest
    INNER JOIN NOPER           OP ON man.codop        = op.codop
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect     = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP   = C1.CODRETETA  &apos;
    ||sCondObj||
    sCondgest||&apos;
    INNER JOIN CMDPRODMAT     MAT ON MAT.CODCOMANDA1  = C1.CODCOMANDA1 - C1.CODCOMANDA1
    left JOIN (
      select T1.codtarif, T1.Tarif, t.denumire
      from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif
      WHERE pkg_globals.AnLunaLUCRU BETWEEN T1.ALStart and T1.ALStop
    ) T ON Man.CODTARIF = T.CODTARIF
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc = cdoc.codcarnet
    LEFT  JOIN realizari          on c1.codcomanda1 = realizari.codcomanda1
    LEFT  JOIN realizariL         on c1.codcomanda1 = realizariL.codcomanda1
    LEFT  JOIN consumuri          on man.codcmdprodman = consumuri.codcmdprodman
    LEFT  JOIN consumuriL         on man.codcmdprodman = consumuriL.codcmdprodman
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1 = Clink.COdComanda1
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda = ccli1.codcomanda
    left  join npart            p on p.codpart = ccli.partener
    LEFT  JOIN pretm           pm ON pm.codobiect = c1.codobiect AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN prodman            ON prodman.codman = man.codman
    LEFT  JOIN formatii         f ON c.codformatie = f.codformatie
    LEFT  JOIN NARTOBJ     OBJmat ON prod.TIP = objmat.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;);


  sWith1_Man := &apos;
  WITH
    REALIZARI as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and i.tiptranzactie &lt;&gt; 9
      group by c1.codcomanda1
        ),
    REBUT as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0 and i.tiptranzactie = 9
      group by c1.codcomanda1
        ),
    REALIZARIL as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru and i.tiptranzactie &lt;&gt; 9
      group by c1.codcomanda1
        ),
    REBUTL as (
      select
        c1.codcomanda1,
        sum(i1.cant) cant
      from cmdprodmat mat
            inner join comanda1     c1       on mat.codcomanda1   = c1.codcomanda1
            inner join comanda      c        on c1.codcomanda     = c.codcomanda
            inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
            inner join intrari1     i1       on intrlink.codintr1 = i1.codintr1
            inner join intrari      i        on i1.codintr        = i.codintr
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and i.an*12+i.luna = pkg_globals.anlunalucru and i.tiptranzactie = 9
      group by c1.codcomanda1
        ),
    CONSUMURI as (
      select
        p2.codraportp2,
        sum(p2.realizat) cant
      from raportp2 p2
           inner join raportp1 p1 on p2.codraportp1 = p1.codraportp1
           inner join raportp0 p0 on p0.codraportp0 = p1.codraportp0
           inner join comanda1 c1 on p0.codcomanda1 = c1.codcomanda1
           inner join comanda  c  on c1.codcomanda  = c.codcomanda
           left  join manprodlink manlink on p2.codraportp2 = manlink.codraportp2
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(manlink.codraportp2,0) = 0
      group by p2.codraportp2),
    CONSUMURIL as (
      select
        p2.codraportp2,
        sum(p2.realizat) cant
      from raportp2 p2
           inner join raportp1 p1 on p2.codraportp1 = p1.codraportp1
           inner join raportp0 p0 on p0.codraportp0 = p1.codraportp0
           inner join raportp  p  on p0.codraportp  = p.codraportp
           inner join comanda1 c1 on p0.codcomanda1 = c1.codcomanda1
           inner join comanda  c  on c1.codcomanda  = c.codcomanda
           left  join manprodlink manlink on p2.codraportp2 = manlink.codraportp2
      where c.tipdoc = 53 and c.datadoc &apos;||sPer||&apos;
            and nvl(manlink.codraportp2,0) = 0
            and p.an*12+p.luna = pkg_globals.anlunalucru
      group by p2.codraportp2
    ) &apos;;
  sSelect1_Man :=&apos;
  SELECT
    c.codcomanda nav_coddoc,
    c.tipdoc nav_tipdoc,
    op.DENUMIRE,
    &apos;&apos;&apos;&apos;,
    0,
    consumuri.cant,
    nvl(consumuri.cant, 0),
    nvl(consumuri.cant, 0),
    nvl(consumuri.cant, 0) * round(p2.tu * t.tarif/60,5),
    c.seriadoc,
    cdoc.simbol,
    cdoc.denumire,
    c.nrdoc,
    c.datadoc,
    ObjRet.denumire,
    c1.cantacceptat,
    nvl(realizari.cant,0),
    nvl(rebut.cant,0),
    &apos;&apos;Manopera&apos;&apos;,
    c1.cantacceptat - nvl(realizari.cant,0),
    p.den_part,
    ccli.datadoc,
    ccli.nrdoc,
    ccli.valoare,
    g.den_gest,
    c1.pu,
    0,
    0,
    pm.lei,
    nvl(consumuriL.cant, 0),
    0,
    0,
    nvl(realizariL.cant,0),
    nvl(rebutL.cant,0),
    0,
    p2.TU,
    T.Tarif,
    C1.CODCOMANDA1,
    PROD.CODOBIECT,
    0 CodMaterial &apos;||gUserAlias||&apos;
  FROM consumuri
    INNER JOIN RAPORTP2        P2 ON P2.CODRAPORTP2   = consumuri.codraportp2
    INNER JOIN comanda1        c1 ON p2.codcomanda1   = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1 AND PROD.TIP = 0
    INNER JOIN comanda          c ON c1.codcomanda    = c.codcomanda
    INNER JOIN ngest            g ON c.codgest        = g.codgest
    INNER JOIN NOPER           OP ON p2.codop         = op.codop
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect     = objret.codobiect
    INNER JOIN PRODCOMP        PC ON PC.CODPRODCOMP   = C1.CODRETETA  &apos;
    ||sCondObj||
    sCondgest||&apos;
    INNER JOIN CMDPRODMAT     MAT ON MAT.CODCOMANDA1 = C1.CODCOMANDA1 - C1.CODCOMANDA1
    left JOIN (
      select T1.codtarif, T1.Tarif, t.denumire
      from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t .codtarif
      WHERE pkg_globals.AnLunaLUCRU BETWEEN T1.ALStart and T1.ALStop
    ) T ON p2.CODTARIF = T.CODTARIF
    LEFT  JOIN doccarnete    CDOC ON c.carnetdoc    = cdoc.codcarnet
    LEFT  JOIN realizari          on c1.codcomanda1 = realizari.codcomanda1
    LEFT  JOIN rebut              on c1.codcomanda1 = rebut.codcomanda1
    LEFT  JOIN realizariL         on c1.codcomanda1 = realizariL.codcomanda1
    LEFT  JOIN rebutL             on c1.codcomanda1 = rebutL.codcomanda1
    LEFT  JOIN consumuriL         on consumuri.codraportp2 = consumuriL.codraportp2
    LEFT  JOIN CMDLINK      CLINK ON C1.codcomanda1 = Clink.COdComanda1
    LEFT  JOIN comanda1     CCli1 on clink.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli on ccli.codcomanda = ccli1.codcomanda
    left  join npart            p on p.codpart       = ccli.partener
    LEFT  JOIN pretm           pm ON pm.codobiect    = c1.codobiect AND pm.implicit = 1 AND pm.subunitatea = c.subunitatea
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN NARTOBJ     OBJmat ON prod.TIP        = objmat.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 53 and c.anulat &lt;&gt; 1 and c.datadoc &apos;||sPer||&apos; &apos;||
  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sWith1||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sWith2||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sWith_Man||sSelect_Man, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sWith1_Man||sSelect1_Man, aListID, aListVer);

  --
  sSelect :=
  &apos;begin
     update &apos;||tmpName||&apos; tmp set NrCom =
     (select count(distinct tmp1.codmaterial) from &apos;||tmpName||&apos; tmp1 where tmp1.CantCom &gt; 0 and tmp1.CodMaterial &gt; 0 and tmp1.Sursa = &apos;&apos;Materiale&apos;&apos; and tmp1.codobiect = tmp.codobiect);
   end;&apos;;
  EXECUTE IMMEDIATE sSelect;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_difpecomint;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DIRTY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>833FD21627607AA5EC03A1C63444895A6B9A005E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DIRTY IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NCont cont_d, NCont cont_c, NGest g, Jurnal j, NSubunit sub, CentreCost cc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if aLISTID = 223 then
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos; (NAV_CodDoc, NAV_TipDoc, DATADOC, Document, OBS, Subunitatea, NumeDoc &apos;||gUserFields||&apos;)
    select distinct J.CodDoc NAV_CODDOC, J.TipDoc NAV_TIPDEC, J.DataDoc, J.Document, J.Obs, S.Den_Subunit Subunitatea , PKG_LIST_BASE_UTILS.decode_tipdoc(J.TIPDOC) AS NumeDoc &apos;||gUserAlias||&apos;
    FROM TMP_JURNAL_MAN JM
      INNER JOIN JURNAL J ON J.CODDOC  = JM.CODDOC AND J.TIPDOC  = JM.TIPDOC
      INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = J.SUBUNITATEA&apos;||
      gSuplJoins||&apos;
    ORDER BY J.DataDoc, J.TipDoc &apos;;
  else
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos; (NAV_CodDoc, NAV_TipDoc, DATADOC, Document, OBS, Subunitatea, NumeDoc &apos;||gUserFields||&apos;)
    select distinct C.CodComanda NAV_CODDOC, C.TipDoc NAV_TIPDEC, C.DataDoc, C.NrDoc||&apos;&apos;/&apos;&apos;||to_char(C.DataDoc, &apos;&apos;dd.mm.yyyy&apos;&apos;), C.Obs, S.Den_Subunit Subunitatea , PKG_LIST_BASE_UTILS.decode_tipdoc(C.TIPDOC) AS NumeDoc &apos;||gUserAlias||&apos;
    FROM comanda c
      INNER JOIN tmp_manevra_liste tmp on tmp.filtru = &apos;&apos;CODCOMANDA&apos;&apos; and tmp.valoare = c.codcomanda
      INNER JOIN nsubunit s on c.subunitatea = s.codsubunit&apos;||
      gSuplJoins||&apos;
    ORDER BY c.DataDoc, c.TipDoc &apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DIRTY;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DISPLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17FA3E6743D063C222C55B40C0483EF996055CC1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DISPLIVR IS

 PROCEDURE PROCESSLIST IS
   BEGIN
     INSERT INTO TMP_LIST_DISPLIVR(CODLIVRTOT,CODLIVR,CODIESINT1,CODOBIECT,UMSEC,CANT,GEST,SIMBOL,PRETACHIZ,
                                   PRETINREG,DENUM,PARITATE,DENOBIECT,DENGESTIOART,PROCTVA,DIFPRET,VALTOT,FURNIZOR)
     (SELECT TMP_LIVRTOT.CODLIVRTOT,TMP_LIVRTOT.CODLIVR,CODIESINT1,TMP_LIVRTOT.CODOBIECT,TMP_LIVRTOT.UMSEC,TMP_LIVRTOT.CANT,TMP_LIVRTOT.GEST,SIMBOL,TMP_LIVRTOT.PRETACHIZ,
             TMP_LIVRTOT.PRETINREG,TMP_LIVRTOT.DENUM,TMP_LIVRTOT.PARITATE,TMP_LIVRTOT.DENOBIECT,DENGESTIOART,TMP_LIVRTOT.PROCTVA,TMP_LIVRTOT.DIFPRET,
             TMP_LIVRTOT.PRETACHIZ*TMP_LIVRTOT.CANT AS VALTOT,NULL DEN_PART
     FROM TMP_LIVRTOT ,NCONT,IOART1/*,TMP_LIVR1,NIRSTOC,
          INTRARI1,INTRARI,NPART,TMP_LIVR*/
         WHERE 
         PKG_CONFIGART.GETCODCARACTLUNA(TMP_LIVRTOT.CODIOART,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU) = IOART1.CODIOART1 AND
         IOART1.CONT = NCONT.CODCONT /*AND
         TMP_LIVRTOT.CODLIVR = TMP_LIVR.CODLIVR AND
         TMP_LIVR.CODLIVR   = TMP_LIVR1.CODLIVR1 AND
         TMP_LIVR1.CODNIRSTOC = NIRSTOC.CODNIRSTOC AND
          NIRSTOC.CODINTR1 = INTRARI1.CODINTR1 AND
         INTRARI1.CODINTR = INTRARI.CODINTR AND
         INTRARI.PARTENER = NPART.CODPART*/
      );
      COMMIT;                                 
          
   END;      
end PKG_LIST_BASE_DISPLIVR; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D5017FD23E43F09AC2947D8412706426A2C792C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DISTRIBC is

  vCodDistrib  DISTRIB.CODDISTRIB%TYPE;
  gUserFields  VARCHAR2(500);
  gUserAlias   VARCHAR2(500);
  gNullAlias   VARCHAR2(500);
  gSuplCols    VARCHAR2(500);

PROCEDURE SETPARAMS(pCodDistrib IN NUMBER DEFAULT NULL)IS
BEGIN
  vCodDistrib := pCodDistrib;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(13000);
BEGIN
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     Gestiune,
     CentruC,
     Debit,
     Credit,
     Valoare,
     Procent,
     ValoareD,
     GestiuneD,
     CentruCD &apos;||gUserFields||&apos; )
   SELECT
    G.DEN_GEST,
    CC.Simbol,
    DEBIT.SIMBOL,
    CREDIT.SIMBOL,
    PCF1.VAL,
    PCF2.PROCENT,
    PCF1.VAL*PCF2.PROCENT/100,
    GD.DEN_GEST,
    CCD.Simbol
  FROM DISTRIBCHELT1 PCF1
       LEFT JOIN DISTRIBCHELT2 PCF2 ON PCF2.CODDISTRIBCHELT1 = PCF1.CODDISTRIBCHELT1
       LEFT JOIN NESTJURNAL NS ON PCF1.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NGEST GD ON GD.CODGEST = PCF2.CODGEST
       LEFT JOIN CENTRECOST CCD ON CCD.CODCENTRU = PCF2.CODCENTRU
  WHERE PCF1.CodDISTRIBCHELT = &apos;||vCodDistrib;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_distribc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8876DB62F1FB3EB3F5481E5E16E5027585498B7C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DISTRIBSTOC IS
  vToate        BOOLEAN;
  vStoc0        BOOLEAN;
  vDetCCS       BOOLEAN;
  vVanzPer      BOOLEAN;
  vVanzPerAE    BOOLEAN;
  vDataIni      DATE;
  vDataFin      DATE;
  sDataIni      VARCHAR2(100);
  sDataFin      VARCHAR2(100);
  vTipSel       INTEGER;
  vDetRez       BOOLEAN;
  vInfoStoc     BOOLEAN;

  CT_TIPGEST    CONSTANT INTEGER := 1;
  CT_TIPSUBUNIT CONSTANT INTEGER := 2;
  CT_TIPLOCATII CONSTANT INTEGER := 3;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SetParams (
  pTipSel    IN INTEGER  DEFAULT 1,
  pToate     IN NUMBER   DEFAULT 1,
  pStoc0     IN NUMBER   DEFAULT 0,
  pDetCCS    IN NUMBER   DEFAULT 0,
  pVanzPer   IN NUMBER   DEFAULT 0,
  pDataIni   IN VARCHAR2 DEFAULT NULL,
  pDataFin   IN VARCHAR2 DEFAULT NULL,
  pVanzPerAE IN NUMBER   DEFAULT 0,
  V_CODJOB1  IN NUMBER   DEFAULT 0,
  pDetRez    IN NUMBER   DEFAULT 0,
  pInfoStoc  IN NUMBER   DEFAULT 0
  )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  vTipSel    := pTipSel;
  vToate     := Coalesce(pToate,     1) = 1;
  vStoc0     := Coalesce(pStoc0,     0) = 1;
  vDetCCS    := Coalesce(pDetCCS,    0) = 1;
  vVanzPer   := Coalesce(pVanzPer,   0) = 1;
  vVanzPerAE := Coalesce(pVanzPerAE, 0) = 1;
  vDetRez    := Coalesce(pDetRez,    0) = 1;
  vInfoStoc  := Coalesce(pInfoStoc,  0) = 1;

  vDataIni   := To_Date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin   := To_Date(pDataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  sDataIni   := &apos;To_Date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin   := &apos;To_Date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
END;

function GetDataIni return date is
begin
  return vDataIni;
end;

function GetDataFin return date is
begin
  return vDataFin;
end;

function GetDataIniS return varchar2 is
begin
  return sDataIni;
end;

function GetDataFinS return varchar2 is
begin
  return sDataFin;
end;

PROCEDURE BAGA_DINAMIC_COLS IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  DELETE tmp_dinamic_cols;

  IF vTipSel = CT_TIPGEST THEN
    sSelect :=
     &apos;SELECT Row_Number() OVER (ORDER BY NG.DEN_GEST, NG.CODGEST) IDX, NG.DEN_GEST DEN, NG.CODGEST COD, 0 COD2
      FROM NGEST NG&apos;;
    IF vToate THEN
      sSelect := sSelect||&apos;
      WHERE NG.CODGEST &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);
    ELSE
      sSelect := sSelect||&apos;
      INNER JOIN TMP_MANEVRA_LISTE TML ON TML.VALOARE = NG.CODGEST AND TML.FILTRU = &apos;&apos;CODDS&apos;&apos;&apos;;
    END IF;
  ELSIF vTipSel = CT_TIPSUBUNIT THEN
    sSelect :=
     &apos;SELECT Row_Number() OVER (ORDER BY NS.DEN_SUBUNIT, NS.CODSUBUNIT) IDX, NS.DEN_SUBUNIT DEN, NS.CODSUBUNIT COD, 0 COD2
      FROM NSUBUNIT NS&apos;;
    IF vToate THEN
      sSelect := sSelect||&apos;
      WHERE NS.CODSUBUNIT &gt; 1 &apos;;
    ELSE
      sSelect := sSelect||&apos;
        INNER JOIN TMP_MANEVRA_LISTE TML ON TML.VALOARE = NS.CODSUBUNIT AND TML.FILTRU = &apos;&apos;CODDS&apos;&apos;&apos;;
    END IF;
  ELSIF vTipSel = CT_TIPLOCATII THEN
    sSelect :=
     &apos;SELECT
        Row_Number() OVER (ORDER BY NG.DEN_GEST, NG.CODGEST, Coalesce(NL.INDEXLOCAL,0), NL.DENUMIRE) IDX,
        NG.DEN_GEST||CASE WHEN NL.CODLOCATIE &lt;&gt; 0 THEN &apos;&apos;/&apos;&apos;||NL.DENUMIRE END DEN,
        NG.CODGEST COD, NULLIF(NL.CODLOCATIE, 0) COD2
      FROM NGEST NG
        INNER JOIN NLOCATII NL ON NL.CODGEST = NG.CODGEST&apos;;
    IF vToate THEN
      sSelect := sSelect||&apos;
      WHERE NG.CODGEST &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);
    ELSE
      sSelect := sSelect||&apos;
        INNER JOIN (SELECT VALOARE COD, Coalesce(VALOARE1,&apos;&apos;0&apos;&apos;) COD2 FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODDS&apos;&apos;) TML ON TML.COD = NG.CODGEST AND TML.COD2 = NL.CODLOCATIE&apos;;
    END IF;
  END IF;

  sInsert := &apos;INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) &apos;||
             &apos;SELECT &apos;&apos;D&apos;&apos;||to_char(idx,&apos;&apos;fm999&apos;&apos;), Den, Idx, Cod, Cod2 &apos;||
             &apos;FROM (&apos;||sSelect||&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  
  if vInfoStoc then
    sInsert := &apos;INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) &apos;||
               &apos;SELECT &apos;&apos;MI&apos;&apos;||to_char(idx,&apos;&apos;fm999&apos;&apos;), &apos;&apos;min. &apos;&apos;||Den, Idx, Cod, Cod2 &apos;||
               &apos;FROM (&apos;||sSelect||&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  end if;

  IF vDetCCS THEN
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod)
    SELECT &apos;CCS&apos;||to_char(IDX,&apos;fm999&apos;), &apos;Com.Catre &apos;||Den, IDX, Cod
    FROM (
      SELECT Row_Number() OVER (ORDER BY DEN_SUBUNIT, CODSUBUNIT) IDX, CodSubunit Cod, Den_Subunit Den
      FROM Nsubunit
      WHERE CodSubunit &gt; 1
      ORDER BY DEN_SUBUNIT
    );
  END IF;

  IF vDetRez THEN
    sInsert := &apos;INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) &apos;||
               &apos;SELECT &apos;&apos;RZ&apos;&apos;||to_char(idx,&apos;&apos;fm999&apos;&apos;), &apos;&apos;Rez.din &apos;&apos;||Den, Idx, Cod, Cod2 &apos;||
               &apos;FROM (&apos;||sSelect||&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  END IF;

  IF vVanzPer AND vTipSel = CT_TIPSUBUNIT THEN
    sInsert := &apos;INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) &apos;||
               &apos;SELECT &apos;&apos;V&apos;&apos;||to_char(idx,&apos;&apos;fm999&apos;&apos;), &apos;&apos;Vanz.&apos;&apos;||Den, Idx, Cod, Cod2 &apos;||
               &apos;FROM (&apos;||sSelect||&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  END IF;

  COMMIT;
END;

FUNCTION GetToate return boolean is
BEGIN
  RETURN vToate;
END;

FUNCTION GetStoc0 return boolean is
BEGIN
  RETURN vStoc0;
END;

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sSelect     CLOB;
  sAuxIns     CLOB;
  sAuxSel     CLOB;
  sDSSel      CLOB;
  sRZSel      CLOB;
  sCCSSel     CLOB;
  sDSJoin     VARCHAR2( 1000);
  sUnionStoc0 VARCHAR2( 1000);
  sUnionVanzP VARCHAR2( 1000);
  sUnionCom   VARCHAR2( 1000);
  sCWhere     VARCHAR2( 1000);
  sCWhereS    VARCHAR2( 1000);
  sIWhere     VARCHAR2( 1000);
  sCampSel    VARCHAR2(  100);
  sCampSelV   VARCHAR2(  100);
  sGrupSelV   VARCHAR2(  100) := &apos;&apos;;
  sCampSel0   VARCHAR2(  100);
  vCod        VARCHAR2(  100);
  vCod2       VARCHAR2(  100);
  vDen        VARCHAR2(  100);
  sAux        VARCHAR2(  200);
  sColMinMax  VARCHAR2(  100) := &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  k           INTEGER         := 0;
	AnPrec      NUMBER(4);
  LunaPrec    NUMBER(2);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO,NART NA,NUM NUM,NCLASEA NCA,NPART PROD,NARTAMB AA&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetLunaTemp(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru);
  pkg_globals.Calculeaza_Luna_Precedenta(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru, AnPrec,LunaPrec);
  pkg_globals.SetLunaPrecedenta(AnPrec,LunaPrec);

  DELETE FROM tmp_ioart_luna;
  INSERT INTO tmp_ioart_luna (CODIOART1, CODIOART, MG, ANSTART, LUNASTART)
  SELECT CODIOART1, CODIOART, MG, ANSTART, LUNASTART
  FROM IOART1
  WHERE PKG_GLOBALS.AnLunaLucru BETWEEN ALSTART AND ALSTOP;

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  IF vTipSel = CT_TIPGEST THEN
    sCampSel  := &apos;NIR.GEST COD&apos;;
    sCampSel0 := &apos;0 COD&apos;;
    sCampSelV := sCampSel0;
    sCWhere   :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
    sCWhereS  :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;);
    sIWhere   :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

    IF vToate THEN
      sDSJoin := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);
    ELSE
      sDSJoin := &apos;
      INNER JOIN TMP_MANEVRA_LISTE TML ON TML.VALOARE = NIR.GEST AND TML.FILTRU = &apos;&apos;CODDS&apos;&apos;&apos;;
    END IF;
  ELSIF vTipSel = CT_TIPSUBUNIT THEN
    sColMinMax := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
    sCampSel   := &apos;NG.CODSUBUNIT COD&apos;;
    sCampSel0  := &apos;0 COD&apos;;
    sCampSelV := &apos;I.SUBUNITATEA COD&apos;;
    sGrupSelV := &apos;I.SUBUNITATEA, &apos;;
    IF vToate THEN
      sDSJoin := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;;
    ELSE
      sDSJoin := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST
      INNER JOIN TMP_MANEVRA_LISTE TML ON TML.VALOARE = NG.CODSUBUNIT AND TML.FILTRU = &apos;&apos;CODDS&apos;&apos;&apos;;

      sCWhere  := &apos;AND C.SUBUNITATEA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODDS&apos;&apos;)&apos;;
      sCWhereS := &apos;AND C.SUBUNITSURSA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODDS&apos;&apos;)&apos;;
      sIWhere  := &apos;AND I.SUBUNITATEA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODDS&apos;&apos;)&apos;;
    END IF;
  ELSIF vTipSel = CT_TIPLOCATII THEN
    sCampSel  := &apos;NIR.GEST CODG, Coalesce(NS.CODLOCATIE,0) CODL&apos;;
    sCampSel0 := &apos;0 CODG, 0 CODL&apos;;
    sCampSelV := sCampSel0;
    sCWhere   :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
    sCWhereS  :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;);
    sIWhere   :=  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

    IF vToate THEN
      sDSJoin := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);
    ELSE
      sDSJoin := &apos;
      INNER JOIN TMP_MANEVRA_LISTE TML ON TML.FILTRU = &apos;&apos;CODDS&apos;&apos; AND TML.VALOARE = NIR.GEST AND (TML.VALOARE1 IS NULL OR TML.VALOARE1 = NVL(NS.CODLOCATIE,0))&apos;;
    END IF;

  END IF;

  IF vStoc0 THEN
    sUnionStoc0 := &apos;
      UNION ALL
      SELECT CodObiect, 0 Stoc, 0 Vanz, &apos;||sCampSel0||&apos;
      FROM NartObj&apos;;

    sUnionCom := &apos;
      UNION ALL
      SELECT C1.CODOBIECT, 0 SUBUNITATEA, 0 CF, 0 CC, 0 CDS, 0 CCS, SUM(C1.CANTCOMANDAT) CCF
      FROM COMANDA C INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND Nvl(C.INCHISA,0) = 0
        AND C.TIPDOC = 8
        AND C1.CANTACCEPTAT = 0 &apos;||sCWhere||&apos;
      GROUP BY C1.CODOBIECT&apos;;

  END IF;

  IF vVanzPer THEN
    sAux := &apos;26&apos;;
    IF vVanzPerAE THEN
      sAux := &apos;20&apos;;
    END IF;

    sUnionVanzP := &apos;
      UNION ALL
      SELECT i1.CodObiect, 0 Stoc, Sum(i1.cant) Vanz, &apos;||sCampSelV||&apos;
      FROM Iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      WHERE i.tipdoc in (16,19,&apos;||sAux||&apos;)
        AND i1.tiplinie = &apos;&apos;=&apos;&apos;
        AND i.datadoc BETWEEN &apos;||sDataIni||&apos; AND &apos;||sDataFin||&apos;
        AND Nvl(i.infocm,0) = 0 &apos;||sIWhere||&apos;
      GROUP BY &apos;||sGrupSelV||&apos;i1.CodObiect&apos;;
  END IF;


  IF vTipSel = CT_TIPLOCATII THEN
    FOR vRec IN (SELECT fieldname, display, indexlocal, cod, cod2 FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;D%&apos; ORDER BY INDEXLOCAL)
    LOOP
      IF vRec.Cod2 IS NOT NULL
      THEN sAux := &apos; AND codl=&apos;||vrec.Cod2;
      ELSE sAux := &apos;&apos;;
      END IF;

      sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
      sAuxSel := sAuxSel ||&apos;,DS.&apos;||vRec.fieldname;
      sDSSel  := sDSSel||&apos;,SUM(CASE WHEN codg=&apos;||vrec.Cod||sAux||&apos; THEN stoc ELSE 0 END) &apos;||vRec.fieldname;
    END LOOP;
  ELSE
    FOR vRec IN (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;D%&apos; ORDER BY INDEXLOCAL)
    LOOP
      sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
      sAuxSel := sAuxSel ||&apos;,DS.&apos;||vRec.fieldname;
      sDSSel  := sDSSel  ||&apos;,Sum(CASE WHEN cod = &apos;||vrec.Cod||&apos; THEN stoc ELSE 0 END) &apos;||vRec.fieldname;
    END LOOP;
    if vInfoStoc then
      FOR vRec IN (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;MI%&apos; ORDER BY INDEXLOCAL)
      LOOP
        sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
        sAuxSel := sAuxSel ||&apos;,0&apos;;
      END LOOP;
    end if;
  END IF;

  FOR vRec IN (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;V%&apos; ORDER BY INDEXLOCAL)
  LOOP
    sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
    sAuxSel := sAuxSel ||&apos;,DS.&apos;||vRec.fieldname;
    sDSSel  := sDSSel  ||&apos;,Sum(CASE WHEN cod = &apos;||vrec.Cod||&apos; THEN Vanz ELSE 0 END) &apos;||vRec.fieldname;
  END LOOP;

  FOR vRec IN (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;CCS%&apos; ORDER BY INDEXLOCAL)
  LOOP
    sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
    sAuxSel := sAuxSel ||&apos;,C.&apos;||vRec.fieldname;
    sCCSSel := sCCSSel ||&apos;,Sum(CASE WHEN SUBUNITATEA = &apos;||vrec.Cod||&apos; THEN CDS ELSE 0 END) &apos;||vRec.fieldname;
  END LOOP;

  if vDetRez then
    FOR vRec IN (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;RZ%&apos; ORDER BY INDEXLOCAL)
    LOOP
      sAuxIns := sAuxIns ||&apos; ,&apos;||vRec.fieldname;
      sAuxSel := sAuxSel ||&apos;,REZCC.&apos;||vRec.fieldname;
      sRZSel := sRZSel ||&apos;,Sum(CASE WHEN NIR.GEST = &apos;||vrec.Cod||&apos; THEN R.REST ELSE 0 END) &apos;||vRec.fieldname;
    END LOOP;
  end if;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    CODOBIECT,ARTICOL,TOTAL,RestA_CF,RestA_CC,RestA_CDS,RestA_CCS,CantC_CF,REZERVAT,VANZARI,CLASA,DEN_UM,MASA,VOLUM,STOCMIN,STOCMED,STOCMAX,CODINT,CODEXT,PROD&apos;||sAuxIns||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  DS AS (
    SELECT CODOBIECT, SUM(STOC) TOTAL, SUM(Vanz) VANZARI &apos;||sDSSel||&apos;
    FROM (
      SELECT NS.CODOBIECT, v.REST STOC, 0 Vanz, &apos;||sCampSel||&apos;
      FROM v_stocluna v
        INNER JOIN NIRSTOC NS on v.codnirstoc = ns.codnirstoc
        INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR &apos;||
        sDSJoin||&apos;
      WHERE v.rest &gt; 0&apos;||
      sUnionStoc0||
      sUnionVanzP||&apos;)
    GROUP BY CODOBIECT),
  C AS (
    SELECT CODOBIECT, SUM(CF) RestA_CF, SUM(CC) RestA_CC, SUM(CDS) RestA_CDS, SUM(CCS) RestA_CCS, SUM(CCF) CantC_CF&apos;||sCCSSel||&apos;
    FROM (
      SELECT C1.CODOBIECT, C.SUBUNITATEA, SUM(DECODE(C.TIPDOC,8,C1.RESTACCEPTAT,0)) CF, SUM(DECODE(C.TIPDOC,18,C1.RESTACCEPTAT,0)) CC, 0 CDS, SUM(DECODE(C.TIPDOC,44,C1.RESTACCEPTAT,0)) CCS, 0 CCF
      FROM COMANDA C INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND Nvl(C.INCHISA,0) = 0
        AND C.TIPDOC IN (8,18, 44)
        AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||sCWhere||&apos;
      GROUP BY C1.CODOBIECT, C.SUBUNITATEA
      UNION ALL
      SELECT C1.CODOBIECT, C.SUBUNITSURSA, 0 CF, 0 CC, SUM(C1.RESTACCEPTAT) CDS, 0 CCS, 0 CCF
      FROM COMANDA C INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND Nvl(C.INCHISA,0) = 0
        AND C.TIPDOC = 44
        AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||sCWhereS||&apos;
      GROUP BY C1.CODOBIECT, C.SUBUNITSURSA &apos;||
      sUnionCom||&apos;
    )
    GROUP BY CODOBIECT
  ),
  STOCREZ AS (
    SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
    FROM REZERVATS R
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR &apos;||
      sDSJoin||&apos;
    WHERE NVL(R.REST,0) &lt;&gt; 0
    GROUP BY NS.CODOBIECT)&apos;||CHR(13);

  if vDetRez then
    sSelect := sSelect||&apos;,
    REZCC AS (
    SELECT NS.CODOBIECT &apos;||sRZSel||&apos;
    FROM REZERVATS R
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
      INNER JOIN COMANDA1 C1 ON R.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA&apos;||
      sDSJoin||&apos;
    WHERE NVL(R.REST,0) &lt;&gt; 0 AND C.ANULAT = 0
    GROUP BY NS.CODOBIECT)&apos;||chr(13);
  end if;

  sSelect := sSelect||
  &apos;SELECT
    DS.CODOBIECT, NAO.DENUMIRE, DS.TOTAL, NVL(C.RestA_CF,0), NVL(C.RestA_CC,0), NVL(C.RestA_CDS,0), NVL(C.RestA_CCS,0), NVL(C.CantC_CF,0), NVL(SR.REZERVAT,0), NVL(DS.VANZARI,0), NCA.DEN_CLASEA, NUM.DEN_UM,
    NAO.MASA, NAO.VOLUM&apos;||sColMinMax||&apos;, NAO.CODINTERN, NAO.CODEXTERN, PROD.DEN_PART
    &apos;||sAuxSel||gUserAlias||&apos;
  FROM DS
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = DS.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NARTOBJSUBUNIT NAOS ON NAOS.CODOBIECT = NAO.CODOBIECT AND (NAOS.codgest is null or NAOS.codgest = 0) AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN C ON C.CODOBIECT = DS.CODOBIECT
    LEFT JOIN STOCREZ SR ON SR.CODOBIECT = DS.CODOBIECT&apos;||chr(13);
  if vDetRez then
    sSelect := sSelect||&apos;LEFT JOIN REZCC ON REZCC.CODOBIECT = DS.CODOBIECT&apos;||CHR(13);
  end if;
  sSelect := sSelect||
   &apos;LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = NA.CLASA
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NUM1 U1 ON U1.CODUM = NA.UM AND U1.SECUNDARA = 0
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = DS.CODOBIECT AND AA.UMSEC = U1.CODUM1&apos;||
    gSuplJoins||&apos;
  WHERE (DS.TOTAL &lt;&gt; 0 OR NVL(C.RestA_CF,0) &lt;&gt; 0 OR NVL(C.RestA_CC,0) &lt;&gt; 0 OR NVL(C.RestA_CDS,0) &lt;&gt; 0 OR NVL(C.RestA_CCS,0) &lt;&gt; 0 OR NVL(C.CantC_CF,0) &lt;&gt; 0 OR NVL(SR.REZERVAT,0) &lt;&gt; 0 OR NVL(DS.VANZARI,0) &lt;&gt; 0)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  if vInfoStoc then
    for v_rec in (SELECT fieldname, display, indexlocal, cod FROM tmp_dinamic_cols WHERE fieldname LIKE &apos;MI%&apos; ORDER BY INDEXLOCAL) loop
      sInsert := &apos;update &apos;||tmpName||&apos; t set &apos;||v_rec.fieldname||&apos; = (select s.stocmin from nartobjsubunit s where s.codobiect = t.codobiect and s.codgest = &apos;||v_rec.cod||&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
    end loop;  
  end if;
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_distribstoc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DISTRIBSTOCLC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>517CFB1291C96D54FF280392D198481F6775A8EE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DISTRIBSTOCLC is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vToate      boolean;

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2( 6000);
  sSelect     VARCHAR2(30000);
  sDSSel      VARCHAR2( 5000);
  sDSJoin     VARCHAR2( 1000);
  sCWhere     VARCHAR2( 1000);
  sCampSel    VARCHAR2(  100);
  vCod        VARCHAR2(  100);
  vCod2       VARCHAR2(  100);
  vDen        VARCHAR2(  100);
  sColMinMax  VARCHAR2(  100):= &apos;, OBJS.STOCMIN, OBJS.STOCMED, OBJS.STOCMAX&apos;;
  k           INTEGER        := 0;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO,NART NA,NUM NUM,NCLASEA NCA,NPART PROD,NARTAMB AA,PACHETE P&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vToate := pkg_list_base_distribstoc.GetToate;

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, OBJ.STOCMIN, OBJ.STOCMED, OBJ.STOCMAX&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    CODOBIECT,
    ARTICOL,
    STOC,
    RestA_CF,
    RestA_CC,
    REZERVAT,
    CLASA,
    DEN_UM,
    MASA,
    VOLUM,
    STOCMIN,
    STOCMED,
    STOCMAX,
    CODINT,
    CODEXT,
    PROD,
    LOCATIE,
    GESTIUNE,
    COLET&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  C AS (
    SELECT C1.CODOBIECT, SUM(DECODE(C.TIPDOC,8,C1.RESTACCEPTAT,0)) RestA_CF, SUM(DECODE(C.TIPDOC,18,C1.RESTACCEPTAT,0)) RestA_CC
    FROM COMANDA C INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA
    WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND Nvl(C.INCHISA,0) = 0
      AND C.TIPDOC IN (8,18)
      AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||sCWhere||&apos;
    GROUP BY C1.CODOBIECT),
  STOCREZ AS (
    SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
    FROM REZERVATS R
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR &apos;||
      sDSJoin||&apos;
    WHERE NVL(R.REST,0) &lt;&gt; 0
    GROUP BY NS.CODOBIECT)
  SELECT
    NAO.codobiect, NAO.denumire, x.total, x.CF, X.CC, X.REZ, NCA.DEN_CLASEA, NUM.DEN_UM,
    NAO.MASA, NAO.VOLUM, X.STOCMIN, X.STOCMED, X.STOCMAX, NAO.CODINTERN, NAO.CODEXTERN, PROD.DEN_PART, LOC.DENUMIRE, G.DEN_GEST, P.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(P.DATAP,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM
  (
    SELECT
      NS.CODOBIECT, SUM(NVL(POBJ.REST,0)) TOTAL, NVL(C.RestA_CF,0) CF, NVL(C.RestA_CC,0) CC, NVL(SR.REZERVAT,0) REZ &apos;||sColMinMax||&apos;, NS.CODLOCATIE, NIR.GEST, P.CODPACHETE
    FROM PACHETE P
         INNER JOIN PACHETEOBJ POBJ ON POBJ.CODPACHETE = P.CODPACHETE
         INNER JOIN NIRSTOC NS ON POBJ.CODNIRSTOC = NS.CODNIRSTOC
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
         INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
         INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
         LEFT JOIN NARTOBJSUBUNIT OBJS ON OBJS.CODOBIECT = OBJ.CODOBIECT and (OBJS.codgest is null or OBJS.codgest = 0) AND OBJS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
         LEFT JOIN C ON C.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN STOCREZ SR ON SR.CODOBIECT = OBJ.CODOBIECT
    WHERE POBJ.REST &gt; 0 AND P.TIPPACHET = 1
    GROUP BY NS.CODOBIECT &apos;||sColMinMax||&apos;, NS.CODLOCATIE, NIR.GEST, P.CODPACHETE, C.RestA_CF, C.RestA_CC, SR.REZERVAT
    UNION ALL
    SELECT
      NS.CODOBIECT, SUM(NS.REST - NVL(POBJ.REST,0)) TOTAL, NVL(C.RestA_CF,0) CF, NVL(C.RestA_CC,0) CC, NVL(SR.REZERVAT,0) REZ &apos;||sColMinMax||&apos;, NS.CODLOCATIE, NIR.GEST, 0 CODPACHETE
    FROM NIRSTOC NS
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
         INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
         INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
         LEFT JOIN (select sum(rest) rest, codnirstoc from PACHETEOBJ group by codnirstoc) POBJ ON POBJ.CODNIRSTOC = NS.CODNIRSTOC
         LEFT JOIN NARTOBJSUBUNIT OBJS ON OBJS.CODOBIECT = OBJ.CODOBIECT and (OBJS.codgest is null or OBJS.codgest = 0) AND OBJS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
         LEFT JOIN C ON C.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN STOCREZ SR ON SR.CODOBIECT = OBJ.CODOBIECT
    WHERE NS.REST - NVL(POBJ.REST,0) &gt; 0
    GROUP BY NS.CODOBIECT &apos;||sColMinMax||&apos;, NS.CODLOCATIE, NIR.GEST, C.RestA_CF, C.RestA_CC, SR.REZERVAT
  ) X
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = X.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    INNER JOIN NGEST G ON G.CODGEST = X.GEST
    LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = X.CODLOCATIE
    LEFT JOIN PACHETE P ON P.CODPACHETE = X.CODPACHETE
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = NA.CLASA
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NUM1 U1 ON U1.CODUM = NA.UM AND U1.SECUNDARA = 0
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = NAO.CODOBIECT AND AA.UMSEC = U1.CODUM1
  &apos;||gSuplJoins;

  IF NOT vToate THEN
    sSelect := sSelect||&apos; where exists (select tmp.valoare1 from tmp_manevra_liste tmp where tmp.filtru = &apos;&apos;CODDS&apos;&apos; and LOC.CodLocatie = tmp.valoare1)&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DISTRIBSTOCLC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCAMBALAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F146C66593C5EC961FEFE0F0BFFF982EEA540B61</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_docambalaje IS

  vCodDoc  COMANDA.CODCOMANDA%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodDoc := pCodDoc;
END;

function GetCodComanda return number is
begin  
  return vCodDoc;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  gSuplCols := &apos;comanda1 c1, nartobj nao, nart na, num1 num1&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(ART, UM, CANTCOM, CANTRET, CANTACC, PU&apos;||gUserFields||&apos;)
  SELECT
    nao.denumire, num1.den_um1,
    c1.cantcomandat / num1.paritate, c1.cantreturnat / num1.paritate, c1.cantacceptat / num1.paritate, c1.pu * num1.paritate&apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj nao ON nao.codobiect = c1.codobiect
    INNER JOIN nart na ON na.codarticol = nao.codarticol
    INNER JOIN num1 ON num1.codum1 = c1.umsec&apos;||
    gSuplJoins||&apos;
  WHERE c.codcomanda = &apos;||vCodDoc||&apos;
  ORDER BY c1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_DOCAMBALAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCANULATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A5D81FD9A5BCE17F145AF27BC8097E728575DD6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCANULATE IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(1000);
  sSelect   VARCHAR2(9000);
  vCondLuna VARCHAR2(200);
BEGIN
  gSuplCols := &apos;DOCCARNETE DC, NPERS AG, INTRARI INTR,IESIRI IES, TRANSF TR, TREZOR TZ&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTLUNA.LunaStart = PKG_LIST_SELECTLUNA.LunaFin
  THEN vCondLuna := &apos; = &apos;||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaStart);
  ELSE vCondLuna := &apos; BETWEEN &apos;||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaStart)||
                    &apos; AND &apos;    ||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaFin);
  END IF;


  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos; (NAV_CodDoc, NAV_TipDoc, TIPDOC, SERDOC, PREFIXDOC, NRDOC, DATADOC, DENUMIRE, SERIE, SIMBOL, PART, VAL, SUBUNITATEA,OBS&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH DA AS (
    SELECT I.CODINTR CODDOC, I.TIPDOC, I.CARNETDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.SUBUNITATEA, I.SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, I.VALDOC, I.OBS, I.AGENT
    FROM INTRARI I
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, I.CARNETDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.SUBUNITATEA, I.SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, I.VALDOC, I.OBS, I.AGENT
    FROM IESIRI I
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, T.CARNETDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, T.SUBUNITATEA, T.SERIADOC,
      G.DEN_GEST PART, T.VALDOC, T.OBS, 0 AGENT
    FROM  TRANSF T
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE T.ANULAT = 1 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTREZOR CODDOC, T.TIPDOC, T1.CARNETDOC, T1.DOC PREFIXDOC, T1.NRDOC, T1.DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      DECODE(T1.OBIECTTRANZ,3,B.DENUMIRE||&apos;&apos; &apos;&apos;||BC.NRCONT,2,PERS.NUME|| &apos;&apos; &apos;&apos; || PERS.PRENUME,1,P.DEN_PART,0,P.DEN_PART,C.SIMBOL) PART, T1.VALDOC,
      T1.OBS, T.AGENT
    FROM  TREZOR1 T1
      INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
      LEFT JOIN GENERAL G ON G.TIPDOC = T.TIPDOC AND G.CODDOC = T1.CODTREZOR1
      LEFT JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = O.CODOBLIGPIF
      LEFT JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
      LEFT JOIN TREZOR1 TS1 ON TS1.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29,31)
      LEFT JOIN TREZOR TS ON TS.CODTREZOR = TS1.CODTREZOR
      LEFT JOIN NPART P ON P.CODPART = T1.CODPART AND T1.OBIECTTRANZ IN (0,1)
      LEFT JOIN NPERS PERS ON PERS.CODPERS = T1.CODPART AND T1.OBIECTTRANZ = 2
      LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = T1.CODPART AND T1.OBIECTTRANZ = 3
      LEFT JOIN NBANK B ON B.CODBANK = BC.CODBANK
      LEFT JOIN NCONT C ON C.CODCONT =
        CASE
          WHEN o.semnificatie IN (300,320) AND NVL(os.semnificatie, 0) = 500 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
          WHEN o.semnificatie IN (400,420) AND NVL(os.semnificatie, 0) = 600 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
          WHEN o.semnificatie IN (800,801) THEN To_Number(PKG_CATEGCONST.GETVALCONSTBYCODE(o.icont,t.an,t.luna))
          WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
          WHEN o.semnificatie = 1000 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(t.codbanca,t.an,t.luna))
          WHEN o.semnificatie IN (1100,1101) THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
          ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
        END
    WHERE T1.ANULAT = 1 AND (T1.AN * 12 + T1.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODINTR CODDOC, I.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC, I.OBS, I.AGENT
    FROM  NIR N
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE N.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC, I.OBS, I.AGENT
    FROM NIR N
      INNER JOIN IESIRI I ON I.CODIES = N.CODIES
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE N.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      G.DEN_GEST PART, 0 VALDOC, T.OBS, 0 AGENT
    FROM NIR N
      INNER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE N.ANULAT = 1 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODINTR CODDOC, I.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC, I.OBS, I.AGENT
    FROM LIVR L
      INNER JOIN INTRARI I ON I.CODINTR = L.CODINTR
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE L.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC, I.OBS, I.AGENT
    FROM LIVR L
      INNER JOIN IESIRI I ON I.CODIES = L.CODIES
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE L.ANULAT = 1 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      G.DEN_GEST PART, 0 VALDOC, T.OBS, 0 AGENT
    FROM LIVR L
      INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE L.ANULAT = 1 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna||&apos;
  )
  SELECT
    DA.CODDOC, DA.TIPDOC, pkg_list_base_utils.decode_tipdoc(DA.TIPDOC), Nvl(DA.SERIADOC,DC.SERIE),
    DA.PREFIXDOC, DA.NRDOC, DA.DATADOC, DC.DENUMIRE, DC.SERIE, DC.SIMBOL, DA.PART, DA.VALDOC, S.DEN_SUBUNIT, DA.OBS &apos;||gUserAlias||&apos;
  FROM DA
    LEFT JOIN INTRARI INTR ON INTR.CODINTR = DA.CODDOC AND INTR.TIPDOC = DA.TIPDOC
    LEFT JOIN IESIRI   IES ON IES.CODIES = DA.CODDOC AND IES.TIPDOC = DA.TIPDOC
    LEFT JOIN TRANSF    TR ON TR.CODTRANSF = DA.CODDOC AND TR.TIPDOC = DA.TIPDOC
    LEFT JOIN TREZOR    TZ ON TZ.CODTREZOR = DA.CODDOC AND TZ.TIPDOC = DA.TIPDOC
    LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = DA.CARNETDOC
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = DA.SUBUNITATEA
    LEFT JOIN NPERS AG ON AG.CODPERS = DA.AGENT&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_DOCANULATE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D042A063C718E0B4DC3BC6B8A3524217DE8EB27</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_docasoc IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;TMP_DOCASOC DOC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    CodDoc,
    TipDoc,
    CodDocAsoc,
    TipDocAsoc,
    DenDoc,
    DenDocAsoc&apos;||gUserFields||&apos;
  )&apos;;

  sSelect := &apos;
  with tmp as
  (
   select distinct coddoc, tipdoc
   from 
   (
     select coddoc, tipdoc from docasoc
     union all 
     select coddocasoc, tipdocasoc from docasoc
   )
  )
  SELECT 
    DOC.CODDOC,DOC.TIPDOC,DOC.CODDOCASOC,DOC.TIPDOCASOC,DOC.DENDOC,DOC.DENDOCASOC&apos;||gUserAlias||&apos;
  FROM (  
    SELECT
      da.CodDoc,
      da.TipDoc,
      da.CodDocAsoc,
      da.TipDocAsoc,
      pkg_list_base_utils.GetDenDoc(da.CodDoc,da.TipDoc) DenDoc,
      pkg_list_base_utils.GetDenDoc(da.CodDocAsoc,da.TipDocAsoc) DenDocAsoc
    FROM tmp
         inner join DOCASOC da on da.coddoc = tmp.coddoc and da.tipdoc = tmp.tipdoc
    UNION ALL
    SELECT
      da.CodDocAsoc coddoc,
      da.TipDocAsoc tipdoc,
      da.CodDoc coddocasoc,
      da.TipDoc tipdocasoc,
      pkg_list_base_utils.GetDenDoc(da.CodDocAsoc,da.TipDocAsoc) DenDoc,
      pkg_list_base_utils.GetDenDoc(da.CodDoc,da.TipDoc) DenDocAsoc
    FROM tmp
         inner join DOCASOC da on da.coddocasoc = tmp.coddoc and da.tipdocasoc = tmp.tipdoc
  ) DOC &apos;||gSuplJoins;

  --delete x;
  --insert into x(test) values(sselect); 
  --commit;
  
  EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DOCASOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCAUTOFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF2FF043883506E4AEAB3DA27194497A7BE1D144</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCAUTOFACT is

  vCodDoc NUMBER(20);
  vSubCur NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
	vCodDoc := pCodDoc;
  vSubCur := pkg_globals.getSubunitate;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(32000);
BEGIN
  gSuplCols := &apos;INTRARI I, INTRARI1 I1, NUM1 UM, NARTOBJ NOBJ, NART NART, NPART P, NCLASEA NCA, NCLASEAS NCLS&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,       &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,     &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SDOC&apos;,     &apos;SDOC.CODAGENDA = I.CODLOCATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCDOC&apos;,   &apos;LOCDOC.CODLOCALIT = SDOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARADOC&apos;,  &apos;LOCDOC.CODTARA = TARADOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SSOC&apos;,     &apos;SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOSDOC&apos;,   &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARASOC&apos;,  &apos;LOSDOC.CODTARA = TARASOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;,    &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,    &apos;AC&apos;,       &apos;PKG_LIST_BASE_UTILS.GetCodArtCli(i1.codobiect, i.partener, p.codclasa)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE intrari1_man&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO intrari1_man SELECT i1.* FROM intrari1 i1 WHERE i1.codintr = &apos;||vCodDoc, aListID, aListVer);
  COMMIT;

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     Idx, ART, UM, CANT, PU, VAL, TVA,
     TIPSERIE, SERII, SERNOCANT, SERCANT, SERTG, TG, CERTIF, DATACERTIF,
     CODEXTERN, CODINTERN, DEN_CLASEA, DEN_CLASEAS &apos;||gUserFields||&apos;)
  WITH MAN1 AS (
    SELECT
      I1.codINTR1,
      CASE Coalesce(ns.tipserie,0) WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt)) WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||nser.cantnir||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt)) ELSE NULL END serii,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(Coalesce(nser.tg,ns.tg),&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) tg,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.nrcertif)) AS vc2_nt)) nrcertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.dataprimire,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) datacertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.divizor)) AS vc2_nt)) divizor,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.bucati)) AS vc2_nt)) bucati
    FROM intrari1_man i1
      INNER JOIN NIRSTOC NS on i1.codintr1 = ns.codintr1
      INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
      INNER JOIN nserii s ON s.codserie = nser.codserie
      LEFT  JOIN certif c ON c.codcertif = nser.codcertif
    GROUP BY i1.codintr1, ns.tipserie),
  MAN2 AS (
    SELECT
      codintr1,
      vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) sernocant,
      vc2_nt_to_vc3200(CAST(COLLECT(to_char(tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) sertg,
      vc2_nt_to_vc3200(CAST(COLLECT(To_Char(cant)) AS vc2_nt)) sercant
    FROM (
      SELECT i1.codintr1, s.serie, sum(nser.cantnir) cant, Coalesce(nser.tg, ns.tg) tg
      FROM INTRARI1_MAN I1
        INNER JOIN NIRSTOC NS ON I1.CODINTR1 = NS.CODINTR1
        INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
        INNER JOIN nserii s ON s.codserie = nser.codserie
        LEFT  JOIN certif c ON c.codcertif = nser.codcertif
      WHERE Coalesce(ns.tipserie,0) &gt; 0
      GROUP BY I1.codintr1, s.serie, Coalesce(nser.tg, ns.tg)
    )
    GROUP BY codintr1)
  SELECT
    i1.indexlocal Idx, nobj.denumire ART, um.den_um1 UM, i1.cant/um.paritate CANT, i1.pu*um.paritate PU, i1.cant*i1.pu VAL, i1.TVA,
    CASE nart.tipserie WHEN 0 THEN &apos;&apos;fara serie&apos;&apos; WHEN 1 THEN &apos;&apos;serie pe bucata&apos;&apos; WHEN 2 THEN &apos;&apos;serie pe lot&apos;&apos; END tipserie, MAN1.SERII, MAN2.SERNOCANT, MAN2.SERCANT, MAN2.SERTG, MAN1.TG, MAN1.NRCERTIF, MAN1.DATACERTIF,
    nobj.CODEXTERN, nobj.CODINTERN, nca.DEN_CLASEA, NCLS.DEN_CLASEAS &apos;||gUserAlias||&apos;
  FROM intrari1_man i1
    INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR
    INNER JOIN num1 um ON um.codum1 = I1.umsec
    INNER JOIN nartobj nobj ON nobj.codobiect = I1.codobiect
    INNER JOIN nart ON nart.codarticol = nobj.codarticol
    LEFT JOIN npart p ON p.codpart = i.partener
    LEFT JOIN nart1 on nart1.codarticol = nobj.codarticol AND i.an+12+i.luna BETWEEN nart1.alstart AND nart1.alstop
    LEFT JOIN ntva1 ON ntva1.codtva = nart1.codtva AND i.an+12+i.luna BETWEEN ntva1.alstart AND ntva1.alstop
    LEFT JOIN nartobj1 nobj1 ON nobj1.codobiect = nobj.codobiect AND i.an+12+i.luna BETWEEN nobj1.alstart AND nobj1.alstop
    LEFT JOIN nclasea nca ON nca.codclasea = Coalesce(nart.clasa,0)
    LEFT JOIN nclaseas ncls ON ncls.codclaseas = nart.clasastatist
    LEFT JOIN man1 ON man1.codintr1 = i1.codintr1
    LEFT JOIN man2 ON man2.codintr1 = i1.codintr1 &apos;||
    gSuplJoins||&apos;
  ORDER BY i1.indexlocal &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  processparams(tmpName);
  COMMIT;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
  vValDoc number(20,7);
  vTVADoc number(20,7);
  vValLei number(20,7);
  vTVALei number(20,7);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  IF Coalesce(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;

  FOR v_rec IN (
    SELECT
      I.TIPDOC, I.NRDOC, I.DATADOC, I.SERIADOC, I.VALDOC, I.TVADOC, I.CURS, I.NRI, I.OBS, I.USERID, CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET,
      P.DEN_PART, CODF.CODFISCAL, P.CODEXTERN, P.CODSTATISTICBNR, Decode(I.Anulat,1,&apos;X&apos;,&apos;&apos;) AnulatX,
      Decode(P.PERSOANAFIZICA,1,NULL,P.REGCOM) REGCOM, P.PERSOANAFIZICA, P.AUTORIZATIE, B.CONTBANCA, B.SUCURSALA, BK.DENUMIRE DENBANCA, BK.SIMBOL SIMBBANCA,
      M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE, DECODE(I.CURSDOC,0,1,NULL,1,I.CURSDOC) CURSDOC,
      Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      Decode(P.PERSOANAFIZICA,1,PF.SerieDoc,NULL) PFSerieDoc, Decode(P.PERSOANAFIZICA,1,PF.NrDoc,NULL) PFNrDoc,
      SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.FAX SLivrFax, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.Email SLIVREmail, SLIVR.IDSediu SLIVRIDSediu,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, NULL           ) SLivrAdresaNoCP,
      LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
      SFACT.OBS SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.FAX SFACTFax, SFACT.CODPOSTAL SFACTCodPostal, SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, SFACT.Email SFACTEmail, SFACT.IDSediu SFACTIDSediu,
      GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
      GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, NULL           ) SFACTAdresaNoCP,
      LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara,
      SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.FAX SSOCFax, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.Email SSOCEmail, SSOC.IDSediu SSOCIDSediu,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, NULL          ) SSOCAdresaNoCP,
      LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
      AG.NUME||&apos; &apos;||AG.PRENUME PERSP
    FROM INTRARI I
      LEFT JOIN NMONEDE M ON M.CODMONEDA  = Coalesce(I.MONEDA,0)
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NPARTCODFISC CODF ON CODF.COD_CODFISCAL = I.CODFISCAL
      LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = I.CARNETDOC
      LEFT JOIN NPERS U ON U.LOGONNAME = I.USERID
      LEFT JOIN NPERS AG ON AG.CODPERS = I.AGENT
      LEFT JOIN NPARTTR PF ON PF.CODPART = I.PARTENER AND PF.IMPLICIT = 1
      LEFT JOIN NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE AND SLIVR.CODPART = I.PARTENER
      LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
      LEFT JOIN NJUDET JLIVR ON JLIVR.CODJUDET = Coalesce(LLIVR.CODJUDET, 0)
      LEFT JOIN NTARI TLIVR ON TLIVR.CODTARA = Coalesce(LLIVR.CODTARA, 0)
      LEFT JOIN NAGENDA SFACT ON SFACT.CODAGENDA = CASE WHEN SLIVR.SediuSocial = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SediuSocial IN (3,7) THEN SLIVR.CODAGENDA ELSE 0 END
      LEFT JOIN NLOCALIT LFACT ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
      LEFT JOIN NJUDET JFACT ON JFACT.CODJUDET = Coalesce(LFACT.CODJUDET, 0)
      LEFT JOIN NTARI TFACT ON TFACT.CODTARA = Coalesce(LFACT.CODTARA, 0)
      LEFT JOIN NAGENDA SSOC ON SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = Coalesce(SSOC.CODLOCALIT, 0)
      LEFT JOIN NJUDET JSOC ON JSOC.CODJUDET = Coalesce(LSOC.CODJUDET, 0)
      LEFT JOIN NTARI TSOC ON TSOC.CODTARA = Coalesce(LSOC.CODTARA, 0)
      LEFT JOIN NPARTB B ON B.CODPART = P.CODPART AND B.IMPLICIT = 1
      LEFT JOIN NBANK BK ON B.CODBANK = BK.CODBANK
    WHERE I.CODINTR = vCodDoc
  ) LOOP

    vValDoc := v_rec.ValDoc;
    vTVADoc := v_rec.TVADoc;
    vValLei := v_rec.ValDoc * v_rec.Curs;
    vTVALei := v_rec.TVADoc * v_rec.Curs;

    IF v_rec.Tipdoc = 9
    THEN
      vValDoc := Round(vValDoc,2);
      vValLei := Round(vValLei,2);
    ELSE
      vValDoc := Round(vValDoc - vTVADoc,2) + Round(vTVADoc,2);
      vValLei := Round(vValLei - vTVALei,2) + Round(vTVALei,2);
    END IF;

    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERIE CARTE IDENTITATE&apos;,          v_rec.PFSerieDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR CARTE IDENTITATE&apos;,          v_rec.PFNrDoc);

    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER&apos;,                        v_rec.DEN_PART);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.OBS);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE&apos;,                    NumarRO(Round(vValDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE ENG&apos;,                NumarUK(Round(vValDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL&apos;,                       TO_CHAR(vValDoc-vTvaDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE&apos;,                NumarRO(Round(vValDoc-vTvaDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE ENG&apos;,            NumarUK(Round(vValDoc-vTvaDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(vTVADoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(vTVADoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(vTVADoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CURS&apos;,                     TO_CHAR(v_rec.Curs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL IN LEI&apos;,                    TO_CHAR(vValLei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL IN LEI LITERE&apos;,             NumarRO(Round(vValLei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL IN LEI LITERE ENG&apos;,         NumarUK(Round(vValLei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI&apos;,                TO_CHAR(vValLei - vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE&apos;,      NumarRO(Round(vValLei - vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vValLei - vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI&apos;,                TO_CHAR(vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE&apos;,      NumarRO(Round(vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));

    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,    v_rec.SLivrAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,               v_rec.SLivrFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE IDSEDIU&apos;,           v_rec.SLivrIDSediu);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE&apos;,        v_rec.SFactObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,          v_rec.SFactAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA FARA CP&apos;,  v_rec.SFactAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATE&apos;,      v_rec.SFactLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,         v_rec.SFactTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE FAX&apos;,             v_rec.SFactFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDET&apos;,           v_rec.SFactSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,  v_rec.SFactJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD POSTAL&apos;,      v_rec.SFactCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD FISCAL&apos;,      v_rec.SFactCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD LA CLIENT&apos;,   v_rec.SFactCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,            v_rec.SFactTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,           v_rec.SFactEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE IDSEDIU&apos;,         v_rec.SFactIDSediu);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.SSocObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.SSocAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA FARA CP&apos;,     v_rec.SSocAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.SSocLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.SSocTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL FAX&apos;,                v_rec.SSocFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SSocSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.SSocJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.SSocCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.SSocCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.SSocCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.SSocTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,              v_rec.SSocEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL IDSEDIU&apos;,            v_rec.SSocIDSediu);

    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER DENUMIRE&apos;,               v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER SIMBOL&apos;,                 v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER SERIE&apos;,                  v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER DENUMIRE&apos;,               v_rec.DenumireCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER CODEXTERN&apos;,              v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER AUTORIZATIE&apos;,            v_rec.Autorizatie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER CODFISCAL/CNP&apos;,          v_rec.CodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER REGISTRU COMERT&apos;,        v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER CONT&apos;,                   v_rec.ContBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER BANCA&apos;,                  v_rec.DenBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER SIMBOL BANCA&apos;,           v_rec.SimbBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER SUCURSALA BANCA&apos;,        v_rec.Sucursala);

  END LOOP;
END;

end PKG_LIST_BASE_DOCAUTOFACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15F5B3623A778DE295BC637DFFD114E9C59AB62D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCBCAR IS

  vCodDoc BCAR.CODBCAR%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  vzec       number(10);
  vdec       VARCHAR2(1);
BEGIN
  gSuplCols := &apos;BCAR B&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BEXT&apos;, &apos;BEXT.CODBCAR = B.CODBCAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CANTAR&apos;, &apos;CT&apos;, &apos;CT.CODCANTAR = B.CODCANTAROUT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CANTAR&apos;, &apos;CB&apos;, &apos;CB.CODCANTAR = B.CODCANTARIN&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Tip,
    Umiditate, Straine, Incoltit, Hectolitrica, Gluten,
    Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    Proteina,    
    Aflatoxina,  
    Atac_plosnita,
    Continut_ulei,
    Aciditate,
    TipBon,
    Sistave,
    Refractie,
    IndiceW,
    ToxinaDON,
    BoabeToxice&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    &apos;&apos;STAS&apos;&apos;,
    B.ISUmiditate, B.ISStraine, B.ISIncoltit, B.ISHectolitrica, B.ISGluten,
    B.ISFuzaritate, B.ISCadere, B.ISDeformare, B.ISSticlozitate, B.ISSparturi,
    B.ISProteina,    
    B.ISAflatoxina,  
    B.ISAtac_plosnita,
    B.ISContinut_ulei,
    B.ISAciditate,
    CASE B.TipBCAR
      WHEN 0 THEN &apos;&apos;Bon de la furnizor&apos;&apos;
      WHEN 1 THEN &apos;&apos;Bon din productie&apos;&apos;
      WHEN 2 THEN &apos;&apos;Bon catre client&apos;&apos;
      WHEN 3 THEN &apos;&apos;Bon de la subunitati&apos;&apos;
      WHEN 4 THEN &apos;&apos;Bon catre subunitati&apos;&apos;
      WHEN 5 THEN &apos;&apos;Consum intern&apos;&apos;
      WHEN 6 THEN &apos;&apos;Transfer intre gestiuni&apos;&apos;
      ELSE &apos;&apos;.NEDEFINIT.&apos;&apos;
    END,
    B.ISSISTAVE,
    B.ISREFRACTIE,
    B.ISINDICE_W,
    B.ISTOXINA_DON,
    B.ISBOABE_TOXICE&apos;||
    gUserAlias||&apos;
  FROM bcar b&apos;||
    gSuplJoins||&apos;
  WHERE b.codbcar = &apos;||vCodDoc||&apos;
  UNION ALL
  SELECT
    &apos;&apos;ANALIZA&apos;&apos;,
    B.IAUmiditate, B.IAStraine, B.IAIncoltit, B.IAHectolitrica, B.IAGluten,
    B.IAFuzaritate, B.IACadere, B.IADeformare, B.IASticlozitate, B.IASparturi,
    B.IAProteina,    
    B.IAAflatoxina,  
    B.IAAtac_plosnita,
    B.IAContinut_ulei,
    B.IAAciditate,
    CASE B.TipBCAR
      WHEN 0 THEN &apos;&apos;Bon de la furnizor&apos;&apos;
      WHEN 1 THEN &apos;&apos;Bon din productie&apos;&apos;
      WHEN 2 THEN &apos;&apos;Bon catre client&apos;&apos;
      WHEN 3 THEN &apos;&apos;Bon de la subunitati&apos;&apos;
      WHEN 4 THEN &apos;&apos;Bon catre subunitati&apos;&apos;
      WHEN 5 THEN &apos;&apos;Consum intern&apos;&apos;
      WHEN 6 THEN &apos;&apos;Transfer intre gestiuni&apos;&apos;
      ELSE &apos;&apos;.NEDEFINIT.&apos;&apos;
    END,
    B.IASISTAVE,
    B.IAREFRACTIE,
    B.IAINDICE_W,
    B.IATOXINA_DON,
    B.IABOABE_TOXICE&apos;||
    gUserAlias||&apos;
  FROM bcar b&apos;||
    gSuplJoins||&apos;
  WHERE b.codbcar = &apos;||vCodDoc||&apos;
  UNION ALL
  SELECT
    &apos;&apos;DEPASIRE&apos;&apos;,
    CASE WHEN B.ISUmiditate &gt; B.IAUmiditate THEN 0 ELSE B.ISUmiditate - B.IAUmiditate END,
    CASE WHEN B.ISStraine &gt; B.IAStraine THEN 0 ELSE B.ISStraine - B.IAStraine END,
    B.ISIncoltit - B.IAIncoltit,
    CASE WHEN B.ISHectolitrica &lt; B.IAHectolitrica THEN 0 ELSE B.ISHectolitrica - B.IAHectolitrica END,
    B.ISGluten - B.IAGluten,
    B.ISFuzaritate - B.IAFuzaritate, B.ISCadere - B.IACadere, B.ISDeformare - B.IADeformare, B.ISSticlozitate - B.IASticlozitate,
    CASE WHEN B.ISSparturi &gt; B.IASparturi THEN 0 ELSE B.ISSparturi - B.IASparturi END,
    CASE WHEN B.ISProteina &gt; B.IAProteina THEN 0 ELSE B.ISProteina - B.IAProteina END,
    CASE WHEN B.ISAflatoxina &gt; B.IAAflatoxina THEN 0 ELSE B.ISAflatoxina - B.IAAflatoxina END,
    CASE WHEN B.ISAtac_plosnita &gt; B.IAAtac_plosnita THEN 0 ELSE B.ISAtac_plosnita - B.IAAtac_plosnita END,
    CASE WHEN B.ISContinut_ulei &gt; B.IAContinut_ulei THEN 0 ELSE B.ISContinut_ulei - B.IAContinut_ulei END,
    CASE WHEN B.ISAciditate &gt; B.IAAciditate THEN 0 ELSE B.ISAciditate - B.IAAciditate END,
    CASE B.TipBCAR
      WHEN 0 THEN &apos;&apos;Bon de la furnizor&apos;&apos;
      WHEN 1 THEN &apos;&apos;Bon din productie&apos;&apos;
      WHEN 2 THEN &apos;&apos;Bon catre client&apos;&apos;
      WHEN 3 THEN &apos;&apos;Bon de la subunitati&apos;&apos;
      WHEN 4 THEN &apos;&apos;Bon catre subunitati&apos;&apos;
      WHEN 5 THEN &apos;&apos;Consum intern&apos;&apos;
      WHEN 6 THEN &apos;&apos;Transfer intre gestiuni&apos;&apos;
      ELSE &apos;&apos;.NEDEFINIT.&apos;&apos;
    END,
    CASE WHEN B.ISSistave &gt; B.IASistave THEN 0 ELSE B.ISSistave - B.IASistave END,
    CASE WHEN B.ISRefractie &gt; B.IARefractie THEN 0 ELSE B.ISRefractie - B.IARefractie END,
    CASE WHEN B.ISIndice_W &gt; B.IAIndice_W THEN 0 ELSE B.ISIndice_W - B.IAIndice_W END,
    CASE WHEN B.ISTOXINA_DON &gt; B.IATOXINA_DON THEN 0 ELSE B.ISTOXINA_DON - B.IATOXINA_DON END,
    CASE WHEN B.ISBOABE_TOXICE &gt; B.IABOABE_TOXICE THEN 0 ELSE B.ISBOABE_TOXICE - B.IABOABE_TOXICE END &apos;||
    gUserAlias||&apos;
  FROM bcar b&apos;||
    gSuplJoins||&apos;
  WHERE b.codbcar = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      b.prefixdoc, b.nrdoc, b.datadoc,
      case when coalesce(b.codauto,0) = 0 then b.nrtransp else pa.nrinreg end bcarnrtransp, Coalesce(pr.nrinreg, b.nrremorca) bcarnrremorca,
      car.simbol simbolcarnet, car.denumire denumirecarnet,
      del.delegat, del.mijltransp, del.nrtransp,
      DEL.DOC DelDoc, DEL.NRdoc DelNrDoc, DEL.SERIedoc DelSerDoc, DEL.ELIBERAT DelElib, DEL.CNP DelCNP, DEL.DATADoc DelDataDoc,
      CASE B.TipBCAR
        WHEN 0 THEN &apos;Bon de la furnizor&apos;
        WHEN 1 THEN &apos;Bon din productie&apos;
        WHEN 2 THEN &apos;Bon catre client&apos;
        WHEN 3 THEN &apos;Bon de la subunitati&apos;
        WHEN 4 THEN &apos;Bon catre subunitati&apos;
        WHEN 5 THEN &apos;Consum intern&apos;
        WHEN 6 THEN &apos;Transfer intre gestiuni&apos;
        ELSE &apos;.NEDEFINIT.&apos;
      END TipBon,
      b.prefixavizin, b.nravizin, b.dataavizin,
      Coalesce(INTR.PREFIXDOC, IES.PREFIXDOC) DOCLEG, Coalesce(INTR.NRDOC, IES.NRDOC) NRDOCLEG, Coalesce(INTR.DATADOC, IES.DATADOC) DATADOCLEG, Coalesce(INTR.SERIADOC, IES.SERIADOC) SERIADOCLEG,
      o.denumire articol, b.brutkg, b.tara, b.netkg, b.utilkg, b.utilstaskg, b.pretachiz, b.pretuscare,
      Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      TO_CHAR(CIN.DATACREARE, &apos;DD.MM.YYYY HH24:MI:SS&apos;) DATAB, TO_CHAR(CTARA.DATACREARE, &apos;DD.MM.YYYY HH24:MI:SS&apos;) DATAT,
      uo.nume||&apos; &apos;||uo.prenume PersT,  ui.nume||&apos; &apos;||ui.prenume PersB,
      C.SERIADOC CONTRSERIE, C.NRDOC CONTRNR, TO_CHAR(C.DATADOC, &apos;DD.MM.YYYY&apos;) CONTRDATADOC, TO_CHAR(C.DATASTART, &apos;DD.MM.YYYY&apos;) CONTRDATASTART, TO_CHAR(C.DATASTOP, &apos;DD.MM.YYYY&apos;) CONTRDATASTOP,
      case when coalesce(u.coef,1) = 1 then 0 else U.Zecimale end zec
    FROM bcar b
      LEFT JOIN doccarnete car ON car.codcarnet = b.carnetdoc
      LEFT JOIN nparttr del ON del.codparttr = b.coddelegat
      LEFt JOIN nartobj o ON o.codobiect = b.codobiect
      LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      LEFT JOIN NUM U ON U.CODUM = A.UM
      LEFT JOIN npers u ON u.logonname = b.userid
      LEFT JOIN CANTAR CIN ON CIN.CODCANTAR = B.CODCANTARIN
      LEFT JOIN npers ui ON cin.userid = ui.logonname
      LEFT JOIN CANTAR CTARA ON CTARA.CODCANTAR = B.CODCANTAROUT
      LEFT JOIN npers uo ON ctara.userid = uo.logonname
      LEFT JOIN INTRARI1 INTR1 ON INTR1.CODINTR1 = B.CODDOC1
      LEFT JOIN INTRARI INTR ON INTR.CODINTR = INTR1.CODINTR AND INTR.TIPDOC = B.TIPDOC
      LEFT JOIN IESIRI1 IES1 ON IES1.CODIES1 = B.CODDOC1
      LEFT JOIN IESIRI IES ON IES.CODIES = IES1.CODIES AND B.TIPDOC = IES.TIPDOC
      LEFT JOIN contract1 c1 ON c1.codcontract1 = b.codcontract1
      LEFT JOIN contract c ON c.codcontract = c1.codcontract
      LEFT JOIN nparcaut pa ON pa.codnparcaut = b.codauto
      LEFT JOIN nparcaut pr ON pr.codnparcaut = b.codremorca
    WHERE b.codbcar = vCodDoc
  ) LOOP
    vdec := &apos;&apos;;
    if v_rec.zec &gt; 0 then vdec := RPAD(&apos;D&apos;,v_Rec.zec,&apos;9&apos;); end if;
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,          v_rec.prefixdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NR&apos;,             v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,           v_rec.datadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NRAUTO&apos;,         v_rec.bcarnrtransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NR REMORCA&apos;,     v_rec.bcarnrremorca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,           v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,         v_rec.DenumireCarnet);

    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT&apos;,                 v_rec.Delegat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT DOCUMENT&apos;,        v_rec.DelDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT NR DOCUMENT&apos;,     v_rec.DelNRdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT SERIE DOCUMENT&apos;,  v_rec.DelSerDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT DOC ELIBERAT&apos;,    v_rec.DelElib);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT DATA ELIBERARE&apos;,  To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CNP&apos;,             v_rec.DelCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MIJLOC TRANSPORT&apos;,        v_rec.mijltransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR AUTO&apos;,                 v_rec.nrtransp);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TIP BON&apos;,                 v_rec.TipBon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.INSOTIRE - SERIE&apos;,    Coalesce(v_rec.prefixavizin, v_rec.seriadocleg));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.INSOTIRE - NR&apos;,       Coalesce(v_rec.nravizin, v_rec.nrdocleg));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.INSOTIRE - DATA&apos;,     Coalesce(v_rec.dataavizin, v_rec.datadocleg));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document preluare - tip&apos;,   v_rec.docleg);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document preluare - numar&apos;, v_rec.nrdocleg);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document preluare - data&apos;,  v_rec.datadocleg);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document preluare - seria&apos;, v_rec.seriadocleg);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ARTICOL&apos;,                 v_rec.Articol);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CANT BRUTA&apos;,              TO_CHAR(v_rec.brutkg,&apos;fm9G999G999G990&apos;||vdec, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TARA&apos;,                    TO_CHAR(v_rec.Tara,&apos;fm9G999G999G990&apos;||vdec, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;CANT NETA&apos;,               TO_CHAR(v_rec.NetKG,&apos;fm9G999G999G990&apos;||vdec, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;CANT UTILA&apos;,              TO_CHAR(v_rec.UtilKG,&apos;fm9G999G999G990&apos;||vdec, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;CANT UTILA PE STAS&apos;,      TO_CHAR(v_rec.UtilStasKG,&apos;fm9G999G999G990&apos;||vdec, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRET ACHIZITIE&apos;,          v_rec.PretAchiz);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRET USCARE&apos;,             v_rec.PretUscare);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,          v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,        v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,            v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,             v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data cantarire Brut&apos;,     v_rec.DataB);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data cantarire Tara&apos;,     v_rec.DataT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit de (nume, prenume) la cantarire TARA&apos;, v_rec.PersT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit de (nume, prenume) la cantarire BRUT&apos;, v_rec.PersB);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - serie&apos;,          v_rec.contrserie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - nr&apos;,             v_rec.contrnr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - data&apos;,           v_rec.contrdatadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - data start&apos;,     v_rec.contrdatastart);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Contract - data stop&apos;,      v_rec.contrdatastop);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      part.den_part, Coalesce(sed.codfiscal, CF.CODFISCAL) CODFISCAL, part.regcom,
      GetAdresa(sed.sector, sed.strada, sed.nr1, sed.nr2, sed.bloc, sed.scara, sed.etaj, sed.apart, sed.codpostal) adresa,
      sed.obs, sed.telefon, loc.den_localit, jud.den_judet
    FROM bcar b
      LEFT JOIN npart part ON part.codpart = b.codpartener
      LEFT JOIN nagenda sed ON sed.codagenda = b.codsediu
      LEFT JOIN nlocalit loc ON loc.codlocalit = sed.codlocalit
      LEFT JOIN njudet jud ON jud.codjudet = loc.codjudet
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = B.CODPARTENER AND CF.PRINCIPAL = 1
    WHERE b.codbcar = vCodDoc AND b.tipbcar IN (0, 2)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER&apos;,              v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CIF PARTENER&apos;,          v_rec.codfiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;REGCOM PARTENER&apos;,       v_rec.regcom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU ADRESA&apos;,          v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU DENUMIRE&apos;,        v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LOCALITATE&apos;,      v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU JUDET&apos;,           v_rec.Den_Judet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU TELEFON&apos;,         v_rec.Telefon);

    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      gest.den_gest, Coalesce(sed.codfiscal, CF.CODFISCAL) CODFISCAL,
      GetAdresa(sed.sector, sed.strada, sed.nr1, sed.nr2, sed.bloc, sed.scara, sed.etaj, sed.apart, sed.codpostal) adresa,
      sed.obs, sed.telefon, loc.den_localit, jud.den_judet
    FROM bcar b
      LEFT JOIN ngest gest ON gest.codgest = b.codpartener
      LEFT JOIN nagenda sed ON sed.codgest = b.codpartener
      LEFT JOIN nlocalit loc ON loc.codlocalit = sed.codlocalit
      LEFT JOIN njudet jud ON jud.codjudet = loc.codjudet
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = B.CODPARTENER AND CF.PRINCIPAL = 1
    WHERE b.codbcar = vCodDoc AND b.tipbcar IN (1, 5)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR&apos;,            v_rec.Den_Gest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CIF partener&apos;,          v_rec.codfiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;REGCOM PARTENER&apos;,       &apos;&apos;);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR ADRESA&apos;,     v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR DENUMIRE&apos;,   v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR LOCALITATE&apos;, v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR JUDET&apos;,      v_rec.Den_Judet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PRODUCATOR TELEFON&apos;,    v_rec.Telefon);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      gest.den_gest, Coalesce(sed.codfiscal, CF.CODFISCAL) CODFISCAL,
      GetAdresa(sed.sector, sed.strada, sed.nr1, sed.nr2, sed.bloc, sed.scara, sed.etaj, sed.apart, sed.codpostal) adresa,
      sed.obs, sed.telefon, loc.den_localit, jud.den_judet
    FROM bcar b
      LEFT JOIN ngest gest ON gest.codgest = b.codpartener
      LEFT JOIN nagenda sed ON sed.codgest = b.codpartener
      LEFT JOIN nlocalit loc ON loc.codlocalit = sed.codlocalit
      LEFT JOIN njudet jud ON jud.codjudet = loc.codjudet
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = B.CODPARTENER AND CF.PRINCIPAL = 1
    WHERE b.codbcar = vCodDoc AND b.tipbcar IN (6)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE&apos;,            v_rec.Den_Gest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CIF partener&apos;,        v_rec.codfiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;REGCOM PARTENER&apos;,     &apos;&apos;);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE ADRESA&apos;,     v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE DENUMIRE&apos;,   v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE LOCALITATE&apos;, v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE JUDET&apos;,      v_rec.Den_Judet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE TELEFON&apos;,    v_rec.Telefon);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      sub.den_subunit, Coalesce(sed.codfiscal, CF.CODFISCAL) CODFISCAL, sub.regcom,
      GetAdresa(sed.sector, sed.strada, sed.nr1, sed.nr2, sed.bloc, sed.scara, sed.etaj, sed.apart, sed.codpostal) adresa,
      sed.obs, sed.telefon, loc.den_localit, jud.den_judet
    FROM bcar b
      LEFT JOIN nsubunit sub ON sub.codsubunit = b.codpartener
      LEFT JOIN nagenda sed ON sed.codsubunit = b.codpartener
      LEFT JOIN nlocalit loc ON loc.codlocalit = sed.codlocalit
      LEFT JOIN njudet jud ON jud.codjudet = loc.codjudet
      LEFT JOIN NPARTCODFISC CF ON CF.CODPART = B.CODPARTENER AND CF.PRINCIPAL = 1
    WHERE b.codbcar = vCodDoc AND b.tipbcar IN (3, 4)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE&apos;,            v_rec.Den_Subunit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CIF partener&apos;,          v_rec.codfiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;REGCOM PARTENER&apos;,       v_rec.regcom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE ADRESA&apos;,     v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DENUMIRE&apos;,   v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE LOCALITATE&apos;, v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE JUDET&apos;,      v_rec.Den_Judet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE TELEFON&apos;,    v_rec.Telefon);
    EXIT;
  END LOOP;

  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;BCAREXT&apos;, &apos;CODBCAR&apos;, vCodDoc);

  COMMIT;
END;

end PKG_LIST_BASE_DOCBCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCBONCONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2CB97E25E5B0BAF74FB301471D89A7AA91030222</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCBONCONSUM IS

  vCodDoc     IESIRI.CODIES%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
  vDGest  VARCHAR2(500);
  vGGest  VARCHAR2(500);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      I.NRDOC NRDOC, I.DATADOC DATADOC, I.OBS OBS, NG.DEN_GEST DGEST, PG.NUME||&apos; &apos;||PG.Prenume GGest,
      PA.NRINREG NRINREG, P.Nume||&apos; &apos;||P.Prenume Persoana, NP.Den_part DEN_PART,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI, UT.USERNAME,
      I.SERIADOC
    FROM IESIRI I
      LEFT JOIN NGEST          NG ON I.CodGestProd    = NG.CodGest
      LEFT JOIN NPERS          PG ON PG.CODPERS       = NG.CODGESTIONAR
      LEFT JOIN NPARCAUT       PA ON I.CodAuto        = PA.CodNParcAut
      LEFT JOIN NPERS          P  ON I.CodPers        = P.CodPers
      LEFT JOIN NPART          NP ON I.PartCustodie   = NP.CodPart
      LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = I.USERID
      LEFT JOIN NPERS          U  ON U.LOGONNAME      = I.USERID
    WHERE I.CODIES = vCodDoc
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,              v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,               v_rec.datadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,              v_rec.seriadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                  v_rec.obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTUINEA CONSUM&apos;,            v_rec.DGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTUINEA CONSUM GESTIONAR&apos;,  v_rec.GGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASINA&apos;,                      v_rec.NrInreg);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA&apos;,                    v_rec.Persoana);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PARTENER CUSTODIE&apos;,           v_rec.Den_Part);

    pkg_list_Struct.ADAUGA_PARAM(&apos;UTILIZATOR&apos;,                  v_rec.USERNAME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,              v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,            v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                 v_rec.UBI);
    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(9000);
BEGIN

  gSuplCols :=
    &apos;iesiri1 i1, nartobj nao, nart na, num1 um, num um1, num um2, nclasea c, nartobj1 nao1, ngest ng, npers np, npart prod,&apos;||
    &apos;comanda1 ci1, comanda ci, formatii f, comanda1 cc1, comanda cc, npart p&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;I&apos;,     &apos;I.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,    &apos;CIO&apos;,   &apos;CIO.CODOBIECT = CI1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,    &apos;CCO&apos;,   &apos;CCO.CODOBIECT = CC1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(BC.CODCENTRU,0)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANT, PRET, VAL,
    GESTIUNE, GESTIONAR, OBSART, DENCLASAA, SIMBCLASAA,
    CodIntern, CodExtern, MASA, VOLUM, PRODUCATOR,
    PuMAX,
    UM1, UM2, CANT1, CANT2, SERII, SERIEDATA,SER,SERTG,SERCANT, GAR, TG, IDX,
    PREFIXCI, NRCI, DATACI, FORMATIECI, SCHIMBCI, PARTENER, PREFIXCC, NRCC, DATACC, TIPCONTABIL,UTILIZATOR&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH BC AS (
    SELECT
      i.an, i.luna,
      i1.indexlocal, i1.codies1, i1.tiplinie, i1.codobiect, i1.umsec, i1.obs obsart, i1.pu, i1.garantie, i1.codcentru,
      DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,NVL(lv.gest, n.gest),i1.gestact) gest,
      SUM(DECODE(lv.codlivrval,NULL,ns.pret,lv.pretinreg) * l1.cant) valinreg, NVL(i1.pumaximal,MAX(ns.pumaximal)) pumax,
      DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,case when i.operat = 1 then sum(l1.cant) else i1.cant end,i1.cant) cant,
      sum(l1.cantum1) cantum1,
      sum(l1.cantum2) cantum2,
      vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(s.serie||DECODE(ns.tipserie,2,&apos;&apos;(&apos;&apos;||nrtostr(l1.cant)||&apos;&apos;)&apos;&apos;)).VC2 ORDER BY s.serie) AS vc2_nt)) serii,
      vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(s.serie||DECODE(ns.tipserie,2,&apos;&apos;(&apos;&apos;||nrtostr(l1.cant)||&apos;&apos;)&apos;&apos;)||&apos;&apos; - &apos;&apos;||TO_CHAR(NVL(nser.tg, ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)).VC2) AS vc2_nt)) seriedata,
      vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT to_char(nvl(nser.tg,ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)) AS vc2_nt)) tg,
      vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(s.serie).VC2 ORDER BY s.serie) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(TO_CHAR(NVL(nser.tg, ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)).VC2 ORDER BY s.serie) AS vc2_nt)) sertg,
      vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(nrtostr(l1.cant)).VC2 ORDER BY s.serie) AS vc2_nt)) sercant,
      vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT IOA.DEN_IOART) AS vc2_nt)) DEN_IOART,
      i1.codcmdint1, i.userid,
      pkg_comanda.DinCmdCli(i1.codcmdint1) cc1_codcomanda1
    FROM iesiri i
      LEFT JOIN iesiri1 i1   ON i1.codies      = i.codies
      LEFT JOIN livr    l    ON l.codies       = i1.codies
      LEFT JOIN livr1   l1   ON l1.codies1     = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT JOIN livrval lv   ON lv.codlivr1    = l1.codlivr1
      LEFT JOIN nirstoc ns   ON ns.codnirstoc  = l1.codnirstoc
      LEFT JOIN nir     n    ON n.codnir       = ns.codnir
      LEFT JOIN nirser  nser ON nser.codnirser = l1.codnirser
      LEFT JOIN nserii  s    on s.codserie     = nser.codserie
      LEFT JOIN IOART   IOA  ON NS.CODIOART    = IOA.CODIOART
    WHERE i.codies =&apos;||vCodDoc||&apos;
    GROUP BY
      i.an, i.luna, i1.indexlocal, i1.codies1, i1.tiplinie, i1.codobiect, i1.umsec,  i1.pu, i1.cant, i1.pumaximal, i1.codcentru,
      i1.garantie, i1.obs, i1.gestact, l1.umsec, lv.gest, n.gest, i.operat, i1.codcmdint1, i.userid
  )
  SELECT
    nao.denumire, um.den_um1, bc.cant/um.paritate, bc.pu * um.paritate, bc.pu * bc.cant,
    ng.den_gest, np.nume||&apos;&apos; &apos;&apos;||np.prenume, bc.obsart, c.den_clasea, c.simbol,
    nao.codintern, nao.codextern, nao.masa, nao.volum, prod.den_part,
    CASE
      WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN decode (bc.pumax,-1,0,bc.pumax)
      WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN decode (nvl(nao1.pretmaximal,0),-1,0,nvl(nao1.pretmaximal,0))
      ELSE 0
    END,
    um1.den_um, um2.den_um, bc.cantum1, bc.cantum2, bc.serii, bc.seriedata, bc.ser, bc.sertg, bc.sercant, bc.garantie, bc.tg, bc.indexlocal,
    ci.prefixdoc, ci.nrdoc, ci.datadoc, f.den_formatie, ci.schimb, p.den_part, cc.prefixdoc, cc.nrdoc, cc.datadoc,
    BC.DEN_IOART,UT.USERNAME&apos;||
    gUserAlias||&apos;
  FROM bc
    INNER JOIN IESIRI1        I1   ON BC.CODIES1       = I1.CODIES1
    INNER JOIN NARTOBJ        NAO  ON NAO.CODOBIECT    = BC.CODOBIECT
    INNER JOIN NART           NA   ON NA.CODARTICOL    = NAO.CODARTICOL
    INNER JOIN NUM1           UM   ON um.codum1        = bc.umsec
    LEFT  JOIN NUM            UM1  ON um1.codum        = na.um1
    LEFT  JOIN NUM            UM2  ON um2.codum        = na.um2
    LEFT  JOIN nclasea        c    ON c.codclasea      = na.clasa
    LEFT  JOIN nartobj1       nao1 ON nao1.codobiect   = bc.codobiect AND (bc.an*12+bc.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN ngest          ng   ON ng.codgest       = bc.gest
    LEFT  JOIN npers          np   ON np.codpers       = ng.codgestionar
    LEFT  JOIN npart          prod ON prod.codpart     = nao.codproducator
    LEFT  JOIN comanda1       ci1  ON ci1.codcomanda1  = bc.codcmdint1
    LEFT  JOIN comanda        ci   ON ci.codcomanda    = ci1.codcomanda
    LEFT  JOIN formatii       f    ON f.codformatie    = ci.codformatie
    LEFT  JOIN comanda1       cc1  ON cc1.codcomanda1  = bc.cc1_codcomanda1
    LEFT  JOIN comanda        cc   ON cc.codcomanda    = cc1.codcomanda
    LEFT  JOIN tmp_utilizator ut   ON ut.codutilizator = bc.userid
    LEFT  JOIN npart          p    ON p.codpart        = cc.partener&apos;||
    gSuplJoins||&apos;
  ORDER BY bc.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  ProcessParams;
  COMMIT;

END;

end PKG_LIST_BASE_DOCBONCONSUM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCCANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13E41FA2119646078C743771BD72D334180F32A7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCCANTAR is

gUserFields   VARCHAR2(2500);
gUserAlias    VARCHAR2(2500);
gNullAlias    VARCHAR2(2500);
gSuplCols     VARCHAR2(2500);
gSuplJoins    VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;TMP_LST_CANTAR TMP, nartobj o, nartobj a1, nartobj a2, nartobj a3, nartobj a4, nartobj a5, nartobj a6, nartobj t1, nartobj t2 &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, CLASA, TOTAL_KG, TARA_KG, NET_KG,
    AMB1, AMB1_KG, AMB1_CANT, AMB2, AMB2_KG, AMB2_CANT, AMB3, AMB3_KG, AMB3_CANT, AMB4, AMB4_KG, AMB4_CANT,
    AMB5, AMB5_KG, AMB5_CANT, AMB6, AMB6_KG, AMB6_CANT,
    PALET_KG, TRANSP1, TRANSP1_KG, TRANSP1_CANT, TRANSP2, TRANSP2_KG, TRANSP2_CANT,
    DATACANTAR, ORACANTAR, ANULAT,
    DOC,
    PART &apos;||gUserFields||&apos; )&apos;;

  sSelect := &apos;
  SELECT
    o.denumire, ca.den_clasea, tmp.total_kg, tmp.tara_kg, tmp.net_kg,
    a1.denumire, tmp.amb1_kg, tmp.amb1_cant, a2.denumire, tmp.amb2_kg, tmp.amb2_cant, a3.denumire, tmp.amb3_kg, tmp.amb3_cant, 
    a4.denumire, tmp.amb4_kg, tmp.amb4_cant, a5.denumire, tmp.amb5_kg, tmp.amb5_cant, a6.denumire, tmp.amb6_kg, tmp.amb6_cant,
    tmp.palet_kg, t1.denumire, tmp.transp1_kg, tmp.transp1_cant, t2.denumire, tmp.transp2_kg, tmp.transp2_cant,
    trunc(tmp.datacreare), to_char(tmp.datacreare,&apos;&apos;hh24:mi:ss&apos;&apos;), DECODE(tmp.anulat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;),
    CASE
      WHEN ies.codies     IS NOT NULL THEN ies.prefixdoc ||ies.nrdoc ||&apos;&apos;/&apos;&apos;||To_Char(ies.datadoc ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN intr.codintr   IS NOT NULL THEN intr.prefixdoc||intr.nrdoc||&apos;&apos;/&apos;&apos;||To_Char(intr.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN tr.codtransf   IS NOT NULL THEN tr.prefixdoc  ||tr.nrdoc  ||&apos;&apos;/&apos;&apos;||To_Char(tr.datadoc  ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      WHEN com.codcomanda IS NOT NULL THEN com.prefixdoc ||com.nrdoc ||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc ,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      ELSE &apos;&apos;...&apos;&apos;
    END doc,
    coalesce(s.den_subunit,g.den_gest,p.den_part) &apos;||gUserAlias||&apos;
  FROM TMP_LST_CANTAR TMP
    LEFT JOIN nartobj o ON o.codobiect = tmp.codobiect
    LEFT JOIN nartobj a1 ON a1.codobiect = tmp.amb1_cod
    LEFT JOIN nartobj a2 ON a2.codobiect = tmp.amb2_cod
    LEFT JOIN nartobj a3 ON a3.codobiect = tmp.amb3_cod
    LEFT JOIN nartobj a4 ON a4.codobiect = tmp.amb4_cod
    LEFT JOIN nartobj a5 ON a5.codobiect = tmp.amb5_cod
    LEFT JOIN nartobj a6 ON a6.codobiect = tmp.amb6_cod
    LEFT JOIN nartobj t1 ON t1.codobiect = tmp.transp1_cod
    LEFT JOIN nartobj t2 ON t2.codobiect = tmp.transp2_cod
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = tmp.coddoc1
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies AND ies.tipdoc = tmp.tipdoc
    LEFT JOIN intrari1 intr1 ON intr1.codintr1 = tmp.coddoc1
    LEFT JOIN intrari intr ON intr.codintr = intr1.codintr AND intr.tipdoc = tmp.tipdoc
    LEFT JOIN transf1 tr1 ON tr1.codtransf1 = tmp.coddoc1
    LEFT JOIN transf tr ON tr.codtransf = tr1.codtransf AND tr.tipdoc = tmp.tipdoc
    LEFT JOIN comanda1 com1 ON com1.codcomanda1 = tmp.coddoc1
    LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda AND com.tipdoc = tmp.tipdoc
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart p ON p.codpart = COALESCE(tmp.furnizor, tmp.client) and COALESCE(tmp.furnizor, tmp.client) &gt; 0
    LEFT JOIN nsubunit s ON s.codsubunit = tmp.subunitate and tmp.subunitate &gt; 0
    LEFT JOIN ngest g ON g.codgest = tmp.gestiune and tmp.gestiune &gt; 0 &apos;||
    gSuplJoins||&apos;
  WHERE tmp.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND tmp.LUNA = &apos;||PKG_GLOBALS.GetLUNALUCRU||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;tmp&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DOCCANTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDE346544CF33382151F64CCB56E3A1F94D53E83</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCCASHFLOW is

  vCodDoc NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(5000);
  sDataRef   VARCHAR2(10);
BEGIN
  if aListID = 436 then
    gSuplCols := &apos;OBLIGPIF O, INTRARI I, NC NC, TREZOR T, IESIRI IES&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

    select to_char(data, &apos;dd.mm.yyyy&apos;) into sDataRef from cashflow where codcashflow = vCodDoc;

    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      DOC,
      DATADOC,
      NRDOC,
      TERMEN,
      SUBUNITATEA,
      VALOARE,
      RESTI,
      RESTICONV,
      RESTP,
      RESTPCONV,
      Sold_fake,
      DATAPROPUSA,
      DENPART,
      SIMBOLMONEDA,
      CURS,
      ORDINE&apos;||
      gUserFields||&apos;)&apos;;

    sSelect := &apos;
    SELECT
      BK.DENUMIRE DOC,
      TO_DATE(&apos;&apos;&apos;||SDATAREF||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DATADOC,
      BC.NRCONT NRDOC,
      NULL TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      NULL VALOARE,
      SC.SOLD RESTI,
      SC.SOLDCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      SC.SOLDCONV Sold_fake,
      TRUNC(TO_DATE(&apos;&apos;&apos;||SDATAREF||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)-1) DATAPROPUSA,
      BK.DENUMIRE DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      0 ORDINE&apos;||gUserAlias||&apos;
    FROM SOLDCASHFLOW SC
         INNER JOIN NBANKCONT BC ON BC.CODBANKCONT = SC.CODBANKCONT
         INNER JOIN NBANK BK ON BK.CODBANK = BC.CODBANK
         INNER JOIN NMONEDE M ON M.CODMONEDA = BC.CODMONEDA
         LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = BC.SUBUNITATEA
         LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = SC.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
         LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = BC.CODBANKCONT - BC.CODBANKCONT
         LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
         LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
         LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
         LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
         LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
         LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
         LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
    WHERE SC.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      I.PREFIXDOC DOC,
      I.DATADOC,
      I.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE = 100
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
          INNER JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      I.PREFIXDOC DOC,
      I.DATADOC,
      I.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE = 130
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
          INNER JOIN DVI D ON D.CODDVI = G.CODDOC
          INNER JOIN INTRARI I ON I.CODINTR = D.CODINTR AND I.TIPDOC = G.TIPDOC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;NC&apos;&apos; DOC,
      NC.DATADOC,
      NC.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE IN (1200, 1201)
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL AND G.TIPDOC = 35
          INNER JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC
          INNER JOIN NC NC ON NC.CODNC = NC1.CODNC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NC.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC
           &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      T1.DOC,
      T1.DATADOC,
      T1.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE IN (410,500)
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL AND G.TIPDOC IN (29, 30, 31, 33)
          INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
          INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = T.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      NULL DOC,
      NULL DATADOC,
      NULL NRDOC,
      OP1.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      SUBSTR(OP.OBS, 1, 50) DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN OPREG1 OP1 ON OP1.CODOP1 = P1.CODOP1
          INNER JOIN OPREG OP ON OP.CODOP = OP1.CODOP
          INNER JOIN NMONEDE M ON M.CODMONEDA = NVL(OP.CODMONEDA, 0)
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = OP.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = OP.CODOP - OP.CODOP
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOP1, 0) &lt;&gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;Contr.leas&apos;&apos; DOC,
      C2.DATA DATADOC,
      C.NRDOC,
      C2.DATA TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          LEFT JOIN CONTRACT2 C2 ON P1.CODCONTRACT2 = C2.CODCONTRACT2
          LEFT JOIN CONTRACT C ON C.CODCONTRACT = C2.CODCONTRACT
          LEFT JOIN NPART P ON P.CODPART = C.PARTENER
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = C.CODCONTRACT - C.CODCONTRACT
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODCONTRACT2, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;Nota credit&apos;&apos; DOC,
      NULL DATADOC,
      NULL NRDOC,
      NC.DATASTOP TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          INNER JOIN NOTECREDIT NC ON P1.CODNCREDIT = NC.CODNCREDIT
          LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
          LEFT JOIN CONTRACT C ON C.CODCONTRACT = C2.CODCONTRACT
          LEFT JOIN NPART P ON P.CODPART = NC.CODPART
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NC.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = C.CODCONTRACT - C.CODCONTRACT
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODNCREDIT, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      p1.DOC,
      p1.DATADOC,
      p1.NRDOC,
      p1.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      NULL RESTI,
      NULL RESTICONV,
      P1.REST RESTP,
      P1.RESTCONV RESTPCONV,
      - P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW1 P1
          LEFT JOIN CASHFLOW CP ON CP.CODCASHFLOW = P1.CODCASHFLOW
          LEFT JOIN NPART P ON P.CODPART = P1.CODPART
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(P1.CODMONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = CP.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODCASHFLOW - P1.CODCASHFLOW
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE P1.TIP = 1
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      IES.PREFIXDOC DOC,
      IES.DATADOC,
      IES.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      1 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
          INNER JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = IES.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;NC&apos;&apos; DOC,
      NC.DATADOC,
      NC.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      1 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE IN (1200, 1201)
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL AND G.TIPDOC = 35
          INNER JOIN NC1 ON NC1.CODNC1 = G.CODDOC
          INNER JOIN NC ON NC.CODNC = NC1.CODNC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NC.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      T1.DOC,
      T1.DATADOC,
      T1.NRDOC,
      O.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      1 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = P1.CODOBLIGPIF AND O.SEMNIFICATIE IN (310,600)
          INNER JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
          INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
          INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR AND T.TIPDOC = G.TIPDOC
          INNER JOIN NPART P ON P.CODPART = O.CODPART
          INNER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = T.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOBLIGPIF, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      NULL DOC,
      NULL DATADOC,
      NULL NRDOC,
      OP1.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      SUBSTR(OP.OBS, 1, 50) DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN OPREG1 OP1 ON OP1.CODOP1 = P1.CODOP1
          INNER JOIN OPREG OP ON OP.CODOP = OP1.CODOP
          INNER JOIN NMONEDE M ON M.CODMONEDA = NVL(OP.CODMONEDA, 0)
          LEFT  JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = OP.SUBUNITATEA
          LEFT  JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = OP.CODOP - OP.CODOP
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC 
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODOP1, 0) &lt;&gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;Contr.abon.&apos;&apos; DOC,
      C2.DATA DATADOC,
      C.NRDOC,
      C2.DATA TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN CONTRACT2 C2 ON P1.CODCONTRACT2 = C2.CODCONTRACT2
          INNER JOIN CONTRACT C ON C.CODCONTRACT = C2.CODCONTRACT
          LEFT JOIN NPART P ON P.CODPART = C.PARTENER
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = C.CODCONTRACT - C.CODCONTRACT
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODCONTRACT2, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      &apos;&apos;Nota credit&apos;&apos; DOC,
      NULL DATADOC,
      NULL NRDOC,
      NC.DATASTOP TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          INNER JOIN NOTECREDIT NC ON P1.CODNCREDIT = NC.CODNCREDIT
          LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
          LEFT JOIN CONTRACT C ON C.CODCONTRACT = C2.CODCONTRACT
          LEFT JOIN NPART P ON P.CODPART = NC.CODPART
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NC.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = NC.CODNCREDIT - NC.CODNCREDIT
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE NVL(P1.CODNCREDIT, 0) &gt; 0
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
    
    sSelect := &apos;
    SELECT
      p1.DOC,
      p1.DATADOC,
      p1.NRDOC,
      p1.TERMEN,
      SUB.DEN_SUBUNIT SUBUNITATEA,
      P1.VALOARE,
      P1.REST RESTI,
      P1.RESTCONV RESTICONV,
      NULL RESTP,
      NULL RESTPCONV,
      P1.RESTCONV Sold_fake,
      P1.DATAPROPUSA,
      P.DEN_PART DENPART,
      M.SIMBOL SIMBOLMONEDA,
      CC.CURS,
      2 ORDINE&apos;||gUserAlias||&apos;
     FROM CASHFLOW2 P1
          LEFT JOIN CASHFLOW CP ON CP.CODCASHFLOW = P1.CODCASHFLOW
          LEFT JOIN NPART P ON P.CODPART = P1.CODPART
          LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(P1.CODMONEDA, 0)
          LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = CP.SUBUNITATEA
          LEFT JOIN CURSCASHFLOW CC ON CC.CODCASHFLOW = P1.CODCASHFLOW AND CC.CODMONEDA = M.CODMONEDA
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = CP.CODCASHFLOW - CP.CODCASHFLOW
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
          LEFT JOIN NC1 NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC NC ON NC1.CODNC = NC.CODNC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
          LEFT JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC &apos;||
      gSuplJoins||&apos;
     WHERE P1.TIP = 1
       AND P1.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    pkg_list_Struct.GOLESTE_PARAM;
    FOR v_rec IN (
      SELECT W.NRDOC, W.DATA, W.ZILE, M.SIMBOL
      FROM CASHFLOW W LEFT JOIN NMONEDE M ON W.CODMONEDA = M.CODMONEDA
      WHERE W.CODCASHFLOW = vCodDoc
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;NR&apos;,           v_rec.nrdoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DATA&apos;,         v_rec.data);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ZILE ANALIZA&apos;, v_rec.zile);
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,       v_rec.simbol);
      EXIT;
    END LOOP;
  ELSE
    gSuplCols := &apos;CASHFLOW CP&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      DATA,SOLD,INCASARI,PLATI,SOLDFINAL&apos;||
      gUserFields||&apos;)&apos;;
    
    sSelect := &apos;
    SELECT
      T.DATA,COALESCE(T.SOLD,0),COALESCE(T.INCASARI,0),COALESCE(T.PLATI,0),COALESCE(T.SOLDFINAL,0) &apos;||gUserAlias||&apos;
     FROM TMP_CRONOCASHFLOW T
          INNER JOIN CASHFLOW CP ON CP.CODCASHFLOW = T.CODCASHFLOW &apos;||
      gSuplJoins||&apos;
     WHERE CP.CODCASHFLOW = &apos;||vCodDoc;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    pkg_list_Struct.GOLESTE_PARAM;
    FOR v_rec IN (
      SELECT W.NRDOC, W.DATA, W.ZILE, M.SIMBOL
      FROM CASHFLOW W LEFT JOIN NMONEDE M ON W.CODMONEDA = M.CODMONEDA
      WHERE W.CODCASHFLOW = vCodDoc
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;NR&apos;,           v_rec.nrdoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DATA&apos;,         v_rec.data);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ZILE ANALIZA&apos;, v_rec.zile);
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,       v_rec.simbol);
      EXIT;
    END LOOP;
  END IF;  

  COMMIT;
END;

end PKG_LIST_BASE_DOCCASHFLOW;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCESTM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87AB7DF3551FF6B609175E13C3E4EE1C57006351</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCESTM is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodEstimareProd NUMBER(20) DEFAULT 0;

PROCEDURE setParams(aCodEstimareProd IN number)IS
BEGIN
  pCodEstimareProd := aCodEstimareProd;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sSelect  VARCHAR2(30000);
  sJoinExt VARCHAR2(1000);
  Sap number(2);
  An number(4);
  sSaptamani varchar2(5000);
  sNecesar varchar2(5000);
  sCant varchar2(5000);
  sDepasiri varchar2(5000);
  sAn varchar2(1);
BEGIN
  gSuplCols := &apos;estimariprod1m e1, nartobj obj, nart art, estimariprod ep&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  select Saptamana, AnImport into Sap, An
  from estimariprod
  where codestimareprod = pCodEstimareProd;

  sAn := &apos;C&apos;;
  sSaptamani := &apos;&apos;;
  sNecesar := &apos;&apos;;
  sCant := &apos;&apos;;
  for iter in 1..52 loop
    sSaptamani := sSaptamani||&apos;e1.val_&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    sNecesar := sNecesar||&apos;e1.nec_&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    sCant := sCant||&apos;e1.&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    if Sap = 53 then
      sAn := &apos;N&apos;;
      Sap := 1;
    else
      Sap := Sap + 1;
    end if;
  end loop;

  sDepasiri := &apos;0&apos;;
  if sAn = &apos;C&apos; then
    for iter in Sap..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_&apos;||sAn||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_N&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..15 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_T&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    sDepasiri := sDepasiri||&apos; + nvl(e1.depasiri,0)&apos;;
  else
    for iter in Sap..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_N&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..15 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_T&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    sDepasiri := sDepasiri||&apos; + nvl(e1.depasire,0)&apos;;
  end if;
  sDepasiri := sDepasiri||&apos;,&apos;;

  sInsert :=
  &apos;insert into &apos;||tmpName||&apos;(
    S1 ,  S2,  S3, S4,  S5,  S6,  S7,  S8,  S9,
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19,
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29,
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39,
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49,
    S50, S51, S52,
    NEC1 ,  NEC2,  NEC3, NEC4,  NEC5,  NEC6,  NEC7,  NEC8,  NEC9,
    NEC10, NEC11, NEC12, NEC13, NEC14, NEC15, NEC16, NEC17, NEC18, NEC19,
    NEC20, NEC21, NEC22, NEC23, NEC24, NEC25, NEC26, NEC27, NEC28, NEC29,
    NEC30, NEC31, NEC32, NEC33, NEC34, NEC35, NEC36, NEC37, NEC38, NEC39,
    NEC40, NEC41, NEC42, NEC43, NEC44, NEC45, NEC46, NEC47, NEC48, NEC49,
    NEC50, NEC51, NEC52,
    CANT1 ,  CANT2,  CANT3, CANT4,  CANT5,  CANT6,  CANT7,  CANT8,  CANT9,
    CANT10, CANT11, CANT12, CANT13, CANT14, CANT15, CANT16, CANT17, CANT18, CANT19,
    CANT20, CANT21, CANT22, CANT23, CANT24, CANT25, CANT26, CANT27, CANT28, CANT29,
    CANT30, CANT31, CANT32, CANT33, CANT34, CANT35, CANT36, CANT37, CANT38, CANT39,
    CANT40, CANT41, CANT42, CANT43, CANT44, CANT45, CANT46, CANT47, CANT48, CANT49,
    CANT50, CANT51, CANT52,
    Depasiri,
    PRET,
    SCADENTA,
    DEPASIRE,
    DENUMIRE,
    CODEXTERN,
    CODINTERN,
    DENUM,
    DEN_CLASEAS,
    STOC,
    STOCOPTIM,
    COEFUM,
    PRODUCATOR
    &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  select &apos;||sSaptamani||sNecesar||sCant||sDepasiri||&apos;
    e1.PRET,
    e1.SCADENTA,
    e1.DEPASIRE,
    obj.DENUMIRE,
    obj.CODEXTERN,
    obj.CODINTERN,
    num.DEN_UM,
    cls.DEN_CLASEAS,
    e1.STOC,
    e1.STOCOPTIM,
    e1.COEFUM,
    P.DEN_PART &apos;||gUserAlias||&apos;
  from estimariprod1m e1
    inner join estimariprod ep on ep.codestimareprod = e1.codestimareprod
    inner join nartobj obj on e1.codobiect = obj.codobiect
    inner join nart art on art.codarticol = obj.codarticol
    inner join num on num.codum = art.um
    LEFT JOIN NPART P ON OBJ.CODPRODUCATOR = P.CODPART
    left join nclaseas cls on cls.codclaseas = art.CLASASTATIST&apos;||gSuplJoins||&apos;
  where e1.codestimareprod = &apos;||pCodEstimareProd;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  Commit;
END;

end PKG_LIST_BASE_DOCESTM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCESTV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DA0CC643D685000E4CBD37BD927AABEFFC9C29B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCESTV is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  pCodEstimareProd NUMBER(20) DEFAULT 0;

PROCEDURE setParams(aCodEstimareProd IN number) IS
BEGIN
  pCodEstimareProd := aCodEstimareProd;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sSelect  VARCHAR2(30000);
  sJoinExt VARCHAR2(1000);
  Sap number(2);
  An number(4);
  sSaptamani varchar2(5000);
  sNecesar varchar2(5000);
  sCant varchar2(5000);
  sDepasiri varchar2(5000);
  sAn varchar2(1);
BEGIN
  gSuplCols := &apos;estimariprod1 e1, estimariprod1n e1n, nartobj obj, nart art, estimariprod ep&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  select Saptamana, AnImport into Sap, An
  from estimariprod
  where codestimareprod = pCodEstimareProd;

  sAn := &apos;C&apos;;
  sSaptamani := &apos;&apos;;
  sNecesar := &apos;&apos;;
  sCant := &apos;&apos;;
  for iter in 1..52 loop
    sSaptamani := sSaptamani||&apos;e1.val_&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    sNecesar := sNecesar||&apos;e1n.nec_&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    sCant := sCant||&apos;e1.&apos;||sAn||to_char(Sap)||&apos;,&apos;;
    if Sap = 53 then
      sAn := &apos;N&apos;;
      Sap := 1;
    else
      Sap := Sap + 1;
    end if;
  end loop;

  sDepasiri := &apos;0&apos;;
  if sAn = &apos;C&apos; then
    for iter in Sap..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_&apos;||sAn||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_N&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..15 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_T&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    sDepasiri := sDepasiri||&apos; + nvl(e1.depasiri,0)&apos;;
  else
    for iter in Sap..53 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_N&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    for iter in 1..15 loop
      sDepasiri := sDepasiri||&apos; + nvl(e1.val_T&apos;||to_char(iter)||&apos;,0)&apos;;
    end loop;
    sDepasiri := sDepasiri||&apos; + nvl(e1.depasire,0)&apos;;
  end if;
  sDepasiri := sDepasiri||&apos;,&apos;;

  sInsert :=
  &apos;insert into &apos;||tmpName||&apos;(
    S1 ,  S2,  S3, S4,  S5,  S6,  S7,  S8,  S9,
    S10, S11, S12, S13, S14, S15, S16, S17, S18, S19,
    S20, S21, S22, S23, S24, S25, S26, S27, S28, S29,
    S30, S31, S32, S33, S34, S35, S36, S37, S38, S39,
    S40, S41, S42, S43, S44, S45, S46, S47, S48, S49,
    S50, S51, S52,
    NEC1 ,  NEC2,  NEC3, NEC4,  NEC5,  NEC6,  NEC7,  NEC8,  NEC9,
    NEC10, NEC11, NEC12, NEC13, NEC14, NEC15, NEC16, NEC17, NEC18, NEC19,
    NEC20, NEC21, NEC22, NEC23, NEC24, NEC25, NEC26, NEC27, NEC28, NEC29,
    NEC30, NEC31, NEC32, NEC33, NEC34, NEC35, NEC36, NEC37, NEC38, NEC39,
    NEC40, NEC41, NEC42, NEC43, NEC44, NEC45, NEC46, NEC47, NEC48, NEC49,
    NEC50, NEC51, NEC52,
    CANT1 ,  CANT2,  CANT3, CANT4,  CANT5,  CANT6,  CANT7,  CANT8,  CANT9,
    CANT10, CANT11, CANT12, CANT13, CANT14, CANT15, CANT16, CANT17, CANT18, CANT19,
    CANT20, CANT21, CANT22, CANT23, CANT24, CANT25, CANT26, CANT27, CANT28, CANT29,
    CANT30, CANT31, CANT32, CANT33, CANT34, CANT35, CANT36, CANT37, CANT38, CANT39,
    CANT40, CANT41, CANT42, CANT43, CANT44, CANT45, CANT46, CANT47, CANT48, CANT49,
    CANT50, CANT51, CANT52,
    Depasiri,
    PRET,
    SCADENTA,
    DEPASIRE,
    DENUMIRE,
    CODEXTERN,
    CODINTERN,
    DENUM,
    DEN_CLASEAS,
    STOC,
    STOCOPTIM,
    COEFUM
    &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  select &apos;||sSaptamani||sNecesar||sCant||sDepasiri||&apos;
    e1.PRET,
    e1.SCADENTA,
    e1.DEPASIRE,
    obj.DENUMIRE,
    obj.CODEXTERN,
    obj.CODINTERN,
    num.DEN_UM,
    cls.DEN_CLASEAS,
    e1n.STOC,
    e1n.STOCOPTIM,
    e1n.COEFUM &apos;||gUserAlias||&apos;
  from estimariprod1 e1
    inner join estimariprod1n e1n on e1.codobiect = e1n.codobiect and e1n.codestimareprod = &apos;||pCodEstimareProd||&apos;
    inner join estimariprod ep on ep.codestimareprod = e1.codestimareprod
    inner join nartobj obj on e1.codobiect = obj.codobiect
    inner join nart art on art.codarticol = obj.codarticol
    inner join num on num.codum = art.um
    left join nclaseas cls on cls.codclaseas = art.CLASASTATIST&apos;||gSuplJoins||&apos;
  where e1.codestimareprod = &apos;||pCodEstimareProd;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  Commit;
END;

end PKG_LIST_BASE_DOCESTV;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCFAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E0E67BFC41E3BF7C4952EFAA1E06453A0ADFA39</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCFAZ is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vCodFAZ number(20);

PROCEDURE SETPARAMS(pCodFAZ in number) IS
BEGIN
  vCodFAZ := pCodFAZ;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;faz faz, faz0 faz0&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     PrefixDoc,
     NrDoc,
     DataDoc,
     SeriaDoc,
     Diagrama,
     ConsumMediu,
     KmBordPlecare,
     KmBordSosire,
     ParcursTotal,
     ParcursNejustificat,
     KmEchivCatDrum,
     KmEchivCatDrum_Plin,
     KmEchivCatDrum_Gol,
     KmEchivSporuri,
     KmEchivSporuri_Tractare,
     KmEchivSporuri_Urban,
     KmEchivSporuri_Aero,
     KmEchivSporuri_Inst,
     KmEchivTotal,
     ConsumSuplim_PO,
     ConsumSuplim_Iarna,
     ConsumSuplim_Incalzire,
     ConsumSuplim_RezAer,
     ConsumSuplim_Combina,
     CoefSarcina_FaraRem,
     CoefSarcina_CuRem,
     RezervorPlecare,
     Alimentare,
     ConsumNormat,
     ConsumReal,
     RezervorSosire_Calculat,
     RezervorSosire_Real,
     DifConsum,
     Transp,
     Stationare,
     Pontaj_Acord,
     Pontaj_Regie,
     Pontaj_Nejustif,
     NrInreg,
     Auto,
     ConsumRealizat,
     Sofer,
     DataPlecare,
     KmPlecare,
     KmSosire,
     IndexLocal &apos;||gUserFields||&apos;)
  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)
  SELECT
     FAZ.PrefixDoc,
     FAZ.NrDoc,
     FAZ.DataDoc,
     FAZ.SeriaDoc,
     FAZ.Diagrama,
     FAZ.CmM,
     FAZ.KMPLECARE KmBordPlecare,
     FAZ.KMSOSIRE KmBordSosire,
     case
       when nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0) &lt; 0  then 0
       else nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0)
     end ParcursTotal,
     FAZ.KMN ParcursNejustificat,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE CODFAZ = FAZ.CODFAZ) KmEchivCatDrum,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE INCARCAT = 1 AND CODFAZ = FAZ.CODFAZ) KmEchivCatDrum_Plin,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE INCARCAT = 0 AND CODFAZ = FAZ.CODFAZ) KmEchivCatDrum_Gol,
     0 KmEchivSporuri,
     0 KmEchivSporuri_Tractare,
     0 KmEchivSporuri_Urban,
     0 KmEchivSporuri_Aero,
     0 KmEchivSporuri_Inst,
     (SELECT NVL(SUM(NVL(CANT * SPOR,0)),0) FROM FAZ2 WHERE CODFAZ = FAZ.CODFAZ) KmEchivTotal,
     FAZ.TSTART ConsumSuplim_PO,
     0 ConsumSuplim_Iarna,
     FAZ.TIMOTOR ConsumSuplim_Incalzire,
     0 ConsumSuplim_RezAer,
     FAZ.TCURSE ConsumSuplim_Combina,
     FAZ.CSARCINA CoefSarcina_FaraRem,
     FAZ.CSARCINAR CoefSarcina_CuRem,
     FAZ.RezervorPlecare,
     FAZ.ALIMPOMPA Alimentare,
     FAZ.CONSUM ConsumNormat,
     FAZ.CONSUM ConsumReal,
     FAZ.REZERVORCALC RezervorSosire_Calculat,
     FAZ.REZERVOR RezervorSosire_Real,
     FAZ.REZERVORCALC - FAZ.REZERVOR DifConsum,
     FAZ.TONES Transp,
     FAZ.ORES Stationare,
     FAZ.OREACORD Pontaj_Acord,
     FAZ.OREREGIE Pontaj_Regie,
     FAZ.OREN Pontaj_Nejustif,
     PA.NRINREG NrInreg,
     O.DENUMIRE Auto,
     case when nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0) = 0 then 0 else (nvl(FAZ.RezervorPlecare,0) + nvl(FAZ.Alimpompa,0) + nvl(FAZ.ALIMBCF,0) + nvl(FAZ.ALIMAVANS,0)
               - nvl(FAZ.Rezervor,0)) *100 / (nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0)) end,
     S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME Sofer,
     faz0.dataplecare,
     faz0.kmplecare,
     faz0.kmsosire,
     faz0.indexlocal&apos;||gUserAlias||&apos;
  FROM FAZ FAZ
    INNER JOIN nparcaut pa on FAZ.CODAUTO = pa.CODNPARCAUT
    LEFT JOIN FAZ0 FAZ0 ON FAZ0.CODFAZ = FAZ.CODFAZ
    LEFT JOIN NPERS S ON S.CODPERS = FAZ0.CODPERS
    LEFT JOIN mifix mf ON mf.nrinventar = pa.nrinv
    LEFT JOIN mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model&apos;||
    gSuplJoins||&apos;
  WHERE FAZ.CODFAZ = &apos;||vCodFAZ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert := &apos;update &apos;||tmpName||&apos; tmp set
                Alimentare = null,
                RezervorPlecare = null,
                RezervorSosire_Calculat = null,
                RezervorSosire_Real = null,
                ConsumMediu = null,
                ConsumNormat = null,
                ConsumReal = null,
                ConsumRealizat = null,
                DifConsum = null
              where tmp.indexlocal &lt;&gt; (select max(indexlocal) from &apos;||tmpName||&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_DOCFAZ;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF4C347A0D175D6E8EACCA9122C1AC226E7DB6B8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCIES IS

  vCodDoc         IESIRI.CODIES%TYPE;
  vTipDoc         IESIRI.TIPDOC%TYPE;
  pCursDoc        VARCHAR2(3200);
  vNrDC           INTEGER;
  vFiltruClasaArt BOOLEAN;
  vSubCur         NSUBUNIT.CodSubunit%TYPE;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(25000);
  gSuplJoins  VARCHAR2(10000);

  pListareDiscLangaTot  VARCHAR2(10);
  pListareLiniiDiscPart VARCHAR2(10);
  pListareUMAmbPretCant VARCHAR2(10);
  pListareDocAgregat    VARCHAR2(10);
  pGetSoldListFact      VARCHAR2(10);

function GetProcente(aCodIes1 in number) return varchar2 is
  aCodIes     NUMBER(20);
  aIndexLocal NUMBER(20);
  aProc       VARCHAR2(500);
  aTipLinie   VARCHAR(10);
  Idx         NUMERIC := 0;
begin
  aProc := &apos;&apos;;
  begin
    select indexlocal, codies, tiplinie into aIndexLocal, aCodIes, aTipLinie from iesiri1 where codies1 = aCodIes1;
  exception when others then aIndexLocal := 0;
  end;
  if aIndexLocal &gt; 0 and aTipLinie in (&apos;=&apos;,&apos;S&apos;)then
    for v_rec in (
      select i1.codies1, -i1.cant cant, i1.indexlocal, i1.tiplinie, o.idx
      from iesiri1 i1
           inner join (
             select row_number() over (order by i1.indexlocal) as idx, i1.indexlocal
             from iesiri1 i1
             where i1.codies = acodies
           ) o on o.indexlocal = i1.indexlocal
      where i1.codies = aCodIes and i1.indexlocal &gt; aIndexLocal and i1.tiplinie = &apos;G&apos;
            and not exists (select ii1.codies1 from iesiri1 ii1 where ii1.codies = aCodIes and ii1.indexlocal between aIndexLocal and i1.indexlocal and ii1.tiplinie = &apos;T&apos;)
      order by indexlocal
    ) loop
      if Idx = 0 then
        Idx := v_rec.idx;
        aProc := aProc||TO_CHAR(v_rec.cant,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
      else
        if Idx+1 = v_rec.idx and v_rec.tiplinie = &apos;G&apos; then
          aProc := aProc||&apos; + &apos;||TO_CHAR(v_rec.cant,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
          Idx := v_rec.Idx;
        else
          Exit;
        end if;
      end if;
    end loop;
    for v_rec in (
      select i1.codies1, -i1.cant cant, i1.indexlocal
      from iesiri1 i1 where i1.codies = aCodIes and i1.indexlocal &gt; aIndexLocal and i1.tiplinie = &apos;T&apos;
      and not exists (select ii1.codies1 from iesiri1 ii1 where ii1.codies = aCodIes and ii1.indexlocal between aIndexLocal and i1.indexlocal and ii1.tiplinie = &apos;G&apos;)
      order by i1.indexlocal
    ) loop
      if Length(aProc) &gt; 0 then
        aProc := aProc||&apos; + &apos;||TO_CHAR(v_rec.cant,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
      else
        aProc := to_char(v_rec.cant,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
      end if;
    end loop;
  end if;
  return aProc;
end;

PROCEDURE BAGA_DINAMIC_COLS IS
  vCursor  crs_cols  := get_cursor_coloane;
  vDen     VARCHAR2(30);
BEGIN
  DELETE tmp_dinamic_cols;

  vNrDC := 0;
  IF pListareUMAmbPretCant = &apos;1&apos; THEN
    LOOP
      FETCH vCursor INTO vDen;
      EXIT WHEN vCursor%NOTFOUND;
      INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+1,&apos;fm999&apos;), &apos;Cant.&apos;||vDen);
      INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+2,&apos;fm999&apos;), &apos;Pret/&apos;||vDen);
      vNrDC := vNrDC + 2;
    END LOOP;
    CLOSE vCursor;
  END IF;

  COMMIT;
END;

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER, pFiltruClasaArt IN BOOLEAN) IS
BEGIN
  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  vCodDoc               := pCodDoc;
  vFiltruClasaArt       := pFiltruClasaArt;
  SELECT TipDoc, TO_CHAR(Decode(CursDoc,0,1,NULL,1,CursDoc),&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) CursDoc
  INTO vTipdoc, pCursDoc
  FROM iesiri
  WHERE codies = vCodDoc;

	pListareDiscLangaTot  := pkg_categconst.GetValConstanta(&apos;ListareDiscLangaTot&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
	pListareLiniiDiscPart := pkg_categconst.GetValConstanta(&apos;ListareLiniiDiscPart&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
	pListareUMAmbPretCant := pkg_categconst.GetValConstanta(&apos;ListareUMAmbPretCant&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
	pListareDocAgregat    := pkg_categconst.GetValConstanta(&apos;ListareDocAgregat&apos;,   pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
	pGetSoldListFact      := pkg_categconst.GetValConstanta(&apos;GetSoldListFact&apos;,     pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
	vSubCur               := pkg_globals.getSubunitate;

	BAGA_DINAMIC_COLS;
END;

FUNCTION get_cursor_coloane RETURN crs_cols IS
  crs crs_cols;
BEGIN
  OPEN crs FOR
    SELECT den_um1 || Decode(idxobj,1,NULL,&apos;(&apos;||idxobj||&apos;)&apos;) DEN
    FROM (
      SELECT Upper(U1.DEN_UM1) den_um1, Dense_Rank() OVER (PARTITION BY i1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
      FROM IESIRI I
        INNER JOIN IESIRI1 I1  ON I1.CODIES     = I.CODIES
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = I1.CODOBIECT
        INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
      WHERE I.CODIES = vCodDoc
    )
    GROUP BY den_um1, idxobj
    ORDER BY den_um1, idxobj;

  RETURN crs;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
  sSqlAux     CLOB;
  pAviz       VARCHAR2(3200);
  pSerieAviz  VARCHAR2(3200);
  pNrAviz     VARCHAR2(3200);
  pDataAviz   VARCHAR2(3200);
  pMoneda     VARCHAR2( 100);
  pSMoneda    VARCHAR2( 100);
  SitV        VARCHAR2(   2);
  aSitV       NUMBER(     1);
  aBancaV     NUMBER(    20);
  aMonedaV    NUMBER(    20);
  vCodPart    NUMBER(    20);
  vdocmax     NUMBER;
  vtvamax     NUMBER;
  vValDoc     NUMBER;
  vTVADoc     NUMBER;
  vValLei     NUMBER;
  vTVALei     NUMBER;
  vPjTVA      NUMBER;
  vLiniiTMP   NUMBER;
  vCantBuc    NUMBER;
  vCantCut    NUMBER;
  vGSpCut     NUMBER;
  vCantPal    NUMBER;
  vDiscV      NUMBER := 0;
  vDiscT      NUMBER := 0;
  vSoldPart   NUMBER := 0;
  vComCurs    NUMBER := 0;
  vSoldPartLP NUMBER := 0;
  vAnLuna     NUMBER;
BEGIN
  PRC_AL_CHECK(&apos;NPART1&apos;);
  pkg_list_Struct.GOLESTE_PARAM;

  IF Coalesce(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;

  begin
    select an*12+luna into vAnLuna from iesiri where codies = vCodDoc;
  exception when others then vAnLuna := 0;
  end;

  IF vTipDoc = 23 THEN -- parametrii la subunitati

    FOR v_rec IN (
      SELECT
        I.NRDOC, I.DATADOC, I.NRI, I.SERIADOC, I.VALDOC, I.OBS,
        M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE,
        (SELECT Count(1) FROM IESIRI1 I1 WHERE i1.codies = i.codies) NrLinii,
        CAR.SIMBOL SIMBOLCARNET, CAR.SERIE SERIECARNET, CAR.DENUMIRE DENUMIRECARNET,
        S.DEN_SUBUNIT, S.RegCom, S.CIF, BK.DENUMIRE as banca, BC.nrCONT as contbanca,
        GetAdresa(nag.sector, nag.strada, nag.nr1, nag.nr2, nag.bloc, nag.scara, nag.etaj, nag.apart, nag.codpostal) AS ADRESA, loc.den_localit, J.den_judet, NAG.Telefon,
        DEL.DELegat DelNume, DEL.DOC DelDoc, DEL.NRdoc DelNrDoc, DEL.SERIedoc DelSerDoc, DEL.ELIBERAT DelElib, DEL.CNP DelCNP, DEL.DATADoc DelDataDoc,
        I.MIJLTRANSP DelMTransp, I.NRTRANSP DelNrTransp, PAUT.NrInreg AutoNr,
        Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
        ETRANS.UIT
      FROM IESIRI I
        INNER JOIN NSUBUNIT   S    ON S.CODSUBUNIT     = I.CODSUBUNIT
        LEFT  JOIN NMONEDE    M    ON M.CODMONEDA      = Coalesce(I.MONEDA,0)
        LEFT  JOIN DOCCARNETE CAR  ON CAR.CODCARNET    = I.CARNETDOC
        LEFT  JOIN NAGENDA    NAG  ON NAG.CODSUBUNIT   = S.CODSUBUNIT
        LEFT  JOIN NLOCALIT   LOC  ON LOC.CODLOCALIT   = NAG.CODLOCALIT
        LEFT  JOIN NJUDET     J    ON LOC.CODJUDET     = J.CODJUDET
        LEFT  JOIN NBANKCONT  BC   ON S.CODBANKCONT    = BC.CODBANKCONT
        LEFT  JOIN NBANK      BK   ON BC.CODBANK       = BK.CODBANK
        LEFT  JOIN NPARTTR    DEL  ON DEL.CODPARTTR    = I.DELEGAT
        LEFT  JOIN NPARCAUT   PAUT ON PAUT.CODNPARCAUT = I.CODAUTO
        LEFT  JOIN NPERS      U    ON U.LOGONNAME      = I.USERID
        LEFT JOIN STATUSDECL ETRANS ON ETRANS.CODDOC = I.CODIES AND ETRANS.TIPDOC = 100 + I.TIPDOC
      WHERE I.CODIES = vCodDoc
    ) LOOP

      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SerieCarnet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);

      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA (/)&apos;,               To_Char(v_rec.DataDoc,&apos;dd/mm/yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR LINII&apos;,            v_rec.NrLinii);

      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE DENUMIRE&apos;,  v_rec.DEN_SUBUNIT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE CIF&apos;,       v_rec.CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE R.C.&apos;,      v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE LOCALITATE&apos;,v_rec.Den_localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE JUDET&apos;,     v_rec.Den_judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE ADRESA&apos;,    v_rec.adresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE BANCA&apos;,     v_rec.banca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE CONT&apos;,      v_rec.contbanca);

      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE&apos;,                TO_CHAR(v_rec.ValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE LITERE&apos;,         NumarRO(Round(v_rec.ValDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT VALOARE LITERE ENG&apos;,     NumarUK(Round(v_rec.ValDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.OBS);

      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,               v_rec.DelNume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,              v_rec.DelDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR DOCUMENT&apos;,           v_rec.DelNRdoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,        v_rec.DelSerDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,          v_rec.DelElib);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,        To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP&apos;,                   v_rec.DelCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                   v_rec.DelMTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,             v_rec.DelNrTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AUTO NUMAR&apos;,                      v_rec.AutoNr);

      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;UIT&apos;,                             v_rec.UIT);

    END LOOP;

  ELSE
    IF vTipDoc = 26 THEN
      sSqlAux := &apos;
      SELECT
        VC2_NT_TO_VC3200(CAST(COLLECT(DISTINCT Aviz)      AS vc2_nt)) Aviz,
        VC2_NT_TO_VC3200(CAST(COLLECT(DISTINCT SerieAviz) AS vc2_nt)) SerieAviz,
        VC2_NT_TO_VC3200(CAST(COLLECT(DISTINCT NrAviz)    AS vc2_nt)) NrAviz,
        VC2_NT_TO_VC3200(CAST(COLLECT(DISTINCT DataAviz)  AS vc2_nt)) DataAviz,
        VC2_NT_TO_VC3200(CAST(COLLECT(DISTINCT CursDoc)   AS vc2_nt)) CursDoc
      FROM (
        SELECT
          DC.SERIE||&apos;&apos; &apos;&apos;||IA.NrDoc||&apos;&apos;/&apos;&apos;||to_char(IA.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Aviz,
          DC.SERIE SerieAviz,
          to_char(IA.NrDoc) NrAviz,
          TO_CHAR(IA.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) DataAviz,
          CAST(to_char(Decode(IA.CursDoc,0,1,NULL,1,IA.CursDoc),&apos;&apos;fm9G999G999G990D0099&apos;&apos;, &apos;&apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;&apos;&apos;,.&apos;&apos;&apos;&apos;&apos;&apos;) AS VARCHAR2(20)) CursDoc
        FROM IESIRI I
          INNER JOIN IESIRI1    I1  ON I1.CODIES       = I.CODIES
          INNER JOIN IESLINK    IL  ON I1.CODIES1      = IL.CODIES1
          INNER JOIN IESIRI1    IA1 ON IL.CODLINIEAVIZ = IA1.CodIes1
          INNER JOIN IESIRI     IA  ON IA1.CODIES      = IA.CodIes
          LEFT  JOIN DOCCARNETE DC  ON IA.CARNETDOC    = DC.CodCarnet
        WHERE I.CODIES = &apos;||vCodDoc||&apos; AND I.TipDoc = 26)&apos;;

      EXECUTE IMMEDIATE sSqlAux INTO pAviz, pSerieAviz, pNrAviz, pDataAviz, pCursDoc;
    ELSE
      pAviz     := &apos;&apos;;
      pNrAviz   := &apos;&apos;;
      pDataAviz := &apos;&apos;;
    END IF;

    pkg_list_Struct.ADAUGA_PARAM(&apos;Aviz&apos;,        pAviz    );
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serie Aviz&apos;,  pSerieAviz  );
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr. Aviz&apos;,    pNrAviz  );
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data Aviz&apos;,   pDataAviz);

    EXECUTE IMMEDIATE &apos;SELECT COUNT(1), Coalesce(SUM(Coalesce(PretMaximal,0)*Coalesce(Cant,0)),0), Coalesce(SUM(Coalesce(PretMaximal,0)*Coalesce(Cant,0)*Coalesce(proctva/100,0)),0) FROM &apos;||TMPNAME INTO vLiniiTMP, vDocMax, vTvaMax;

    WITH UMCP AS (
      SELECT
        codies1,
        Max(CASE WHEN uext = &apos;CUTIE&apos; THEN upar END) cutiepar,
        Max(CASE WHEN uext = &apos;CUTIE&apos; THEN gsp  END) cutiegsp,
        Max(CASE WHEN uext = &apos;PALET&apos; THEN upar END) paletpar
      FROM (
        SELECT
          I1.CODIES1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
          Dense_Rank() OVER (PARTITION BY i1.codies1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = i1.umsec THEN 0 ELSE u1.paritate END) idxobj
        FROM IESIRI1 I1
          INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = I1.CODOBIECT
          INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
        WHERE I1.CODIES = vCodDoc AND I1.TIPLINIE = &apos;=&apos; AND Upper(U1.codextern) IN (&apos;CUTIE&apos;,&apos;PALET&apos;)
      ) subs
      WHERE idxobj = 1
      GROUP BY codies1
    )
    SELECT
      Coalesce(Ceil (SUM(Coalesce(I1.Cant,0))),0),
      Coalesce(Ceil (SUM(Coalesce(I1.Cant/UMCP.CutiePar,0))),0),
      Coalesce(Round(SUM(Coalesce(I1.Cant*UMCP.CutieGSp/UMCP.CutiePar,0))),0),
      Coalesce(Ceil (SUM(Coalesce(I1.Cant/UMCP.PaletPar,0))),0)
    INTO
      vCantBuc,
      vCantCut,
      vGSpCut,
      vCantPal
    FROM IESIRI1 I1 LEFT JOIN UMCP ON UMCP.CODIES1 = I1.CODIES1
    WHERE I1.CODIES = vCodDoc AND I1.TIPLINIE = &apos;=&apos;;

    BEGIN
      SELECT Coalesce(t.procent,0) INTO vPjTVA
      FROM (
        SELECT i.an, i.luna, i1.codobiect, Row_Number() OVER (ORDER BY i1.indexlocal) NrCrt
        FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
        WHERE i.codies = vCodDoc AND i1.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;)
      ) xI
        LEFT JOIN nartobj nao ON nao.codobiect = xi.codobiect
        LEFT JOIN NART1   A   ON A.CODARTICOL  = NAO.CODARTICOL AND (xi.AN*12+xi.LUNA) BETWEEN a.ALStart AND a.ALStop
        LEFT JOIN NTVA1   T   ON T.CODTVA      = A.CODTVA       AND (xi.AN*12+xi.LUNA) BETWEEN t.ALStart AND t.ALStop
      WHERE xi.NrCrt = 1;
     EXCEPTION
       WHEN OTHERS THEN vPjTVA := 0;
     END;

    IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
    THEN SitV := &apos;DA&apos;;
    ELSE SitV := &apos;NU&apos;;
    END IF;

    SELECT Coalesce(Sum(i1.restfact),0), Coalesce(Sum(i1.tva),0)
    INTO vDiscV, vDiscT
    FROM iesiri1 i1
    WHERE i1.codies = vCodDoc AND i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;) AND i1.codcriteriu IS NULL;

    FOR v_rec IN (
      SELECT
        I.CODIES, I.TIPDOC, I.NRDOC, I.DATADOC, I.SERIADOC, I.VALDOC, I.TVADOC, I.CURS, I.CODLOCATIE, I.ACCIZE, I.VALDISCOUNT+vDiscV VALDISCOUNT, I.TVADISCOUNT+vDiscT TVADISCOUNT, I.TIPTRANZACTIE, I.TIPTVA,
        I.NRI, I.AGENT, I.DELEGAT, I.OBS, CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET,
        CODF.CODFISCAL C_CUI, CASE WHEN P.PERSOANAFIZICA = 1 THEN &apos;&apos; ELSE CODF.CODFISCAL END C_CIF, CASE WHEN P.PERSOANAFIZICA = 1 THEN CODF.CODFISCAL ELSE &apos;&apos; END C_CNP,
        I.CODPERSC, P.DEN_PART, P.CODEXTERN, P.CODSTATISTICBNR, P.CODINTERN,
        CASE WHEN I.Anulat = 1 THEN &apos;X&apos; ELSE &apos;&apos; END AnulatX,
        CASE WHEN P.PERSOANAFIZICA = 1 THEN &apos;&apos; ELSE P.REGCOM END REGCOM,
        P.PERSOANAFIZICA, P.CODPART, P.AUTORIZATIE, M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE, I.USERID,
        Coalesce(NULLIF(I.CURSDOC,0),1) CURSDOC, MT.DEN_MONEDA DEN_MONEDAT,
        Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI, UA.Email UEMAIL,
        CASE WHEN P.PERSOANAFIZICA = 1 THEN PF.SerieDoc ELSE &apos;&apos; END PFSerieDoc, CASE WHEN P.PERSOANAFIZICA = 1 THEN PF.NrDoc ELSE &apos;&apos; END PFNrDoc, CASE WHEN P.PERSOANAFIZICA = 1 THEN PF.CNP ELSE &apos;&apos; END PFCNP,
        SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.FAX SLivrFax, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.Email SLIVREmail, SLIVR.IDSediu SLIVRIDSediu,
        GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
        GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, NULL           ) SLivrAdresaNoCP,
        coalesce(SLIVR.strada,&apos;-&apos;) SLivrStrada, case when coalesce(SLIVR.nr1,0) = 0 then &apos;-&apos; else to_char(SLIVR.nr1) end SLivrNrStrada, case when coalesce(SLIVR.Sector,0) = 0 then LLIVR.DENSUP ELSE TO_CHAR(SLIVR.Sector) end SLivrSector,
        LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
        SFACT.OBS SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.FAX SFACTFax, SFACT.CODPOSTAL SFACTCodPostal, SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, SFACT.Email SFACTEmail, SFACT.IDSediu SFACTIDSediu,
        GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
        GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, NULL           ) SFACTAdresaNoCP,
        coalesce(SFACT.strada,&apos;-&apos;) SFactStrada, case when coalesce(SFACT.nr1,0) = 0 then &apos;-&apos; else to_char(SFACT.nr1) end SFactNrStrada, case when coalesce(SFACT.Sector,0) = 0 then LFACT.DENSUP ELSE TO_CHAR(SFACT.Sector) end SFactSector,
        LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara,
        SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.FAX SSOCFax, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.Email SSOCEmail, SSOC.IDSediu SSOCIDSediu,
        GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
        GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, NULL          ) SSOCAdresaNoCP,
        coalesce(SSOC.strada,&apos;-&apos;) SSocStrada, case when coalesce(SSOC.nr1,0) = 0 then &apos;-&apos; else to_char(SSOC.nr1) end SSocNrStrada, case when coalesce(SSOC.Sector,0) = 0 then LSOC.DENSUP ELSE TO_CHAR(SSOC.Sector) end SSocSector,
        LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
        B.CONTBANCA, B.SUCURSALA, BK.DENUMIRE DENBANCA, BK.SIMBOL SIMBBANCA,
        AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
        DEL.DELegat DelNume, DEL.DOC DelDoc, DEL.NRdoc DelNrDoc, DEL.SERIedoc DelSerDoc, DEL.ELIBERAT DelElib, DEL.CNP DelCNP,
        DEL.MIJLTRANSP DelMTransp, DEL.NRTRANSP DelNrTransp, DEL.DATADoc DelDataDoc,
        CASE i.TipTranzactie
          WHEN 1 THEN &apos;Tranzactie interna&apos;
          WHEN 2 THEN &apos;Livrare intracomunitara&apos;
          WHEN 3 THEN &apos;Export&apos;
          WHEN 4 THEN &apos;Interna-autofacturare&apos;
          ELSE  &apos; &apos;
        END  TIP_TRANZ,
        CASE i.TipTVA
          WHEN 1 THEN &apos;taxare normala&apos;
          WHEN 2 THEN &apos;taxare inversa&apos;
          WHEN 3 THEN &apos;tranzactie triunghiulara&apos;
          WHEN 4 THEN &apos;locul livrarii/prestarii in afara Romaniei&apos;
          WHEN 5 THEN &apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;
          WHEN 6 THEN &apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;
          WHEN 7 THEN &apos;regim special de scutire art 311 CF&apos;
          WHEN 8 THEN &apos;regim special de scutire art 312 CF&apos;
          ELSE  &apos; &apos;
        END TIP_TVA,
        NI.SIMBOL||&apos; &apos;||NI.DENUMIRE InCoTerms,
        NI.SIMBOL simbolInCoTerms,
        PC.Nume||&apos; &apos;||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail,
        (SELECT Count(1) FROM IESIRI1 I1 WHERE i1.codies = i.codies) NrLinii,
        CASE WHEN Coalesce(aMonedaV,0) = 0 OR Coalesce(aBancaV,0) = 0 THEN 1 ELSE PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMonedaV,aBancaV,To_Char(i.datadoc,&apos;dd.mm.yyyy&apos;)) END CursSitV,
        (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = Coalesce(aMonedaV,0)) MonedaSitV,
        (SELECT DENUMIRE FROM NBANK WHERE CODBANK = Coalesce(aBancaV,0)) BancaSitV,
        CASE WHEN I.TVAINCASARE=1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END TVAINCASARE, I.DATATVA,
        P.ProcCurstransf, C.NrDoc C_NrDoc, C.DataDoc C_DataDoc, C.Obs C_Obs, COMIS.DEN_PART COMIS_NUME, COMIS.CODEXTERN COMIS_CODEXTERN,
        COMIS.CODINTERN COMIS_CODINTERN, COMISCF.CODFISCAL COMIS_CODFISCAL, PAUT.NrInreg AutoNr,
        (SELECT P1.CREDITCLIENT FROM NPART1 P1 WHERE P1.CODPART = P.CODPART AND (I.AN*12+I.LUNA) BETWEEN P1.ALStart and P1.ALStop) CREDITCLIENT,
        CASE WHEN I.TipTVA IN (7,8) THEN &apos;Regim special de scutire, pretul include TVA&apos; ELSE NULL END REG_SCUTIRE,
        E.NRBON, E.DATABON,
        SSUB.TELEFON SubTelefon, SSUB.FAX SubFax,
        ( SELECT trim(string_agg(&apos; &apos;||em2.denumire||&apos;: &apos;||TO_CHAR(em2.valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)))
          FROM emulare em inner join emulare2 em2 ON em2.codemulare = em.codemulare
          WHERE em.codies = i.codies AND em2.valoare &lt;&gt; 0
        ) MODPLATA,
        case
          when i.moneda = 0 then to_char(i.datadoc,&apos;dd.mm.yyyy&apos;)
          when i.curs   = 1 then to_char(i.datadoc,&apos;dd.mm.yyyy&apos;)
          else pkg_monede.GETDATACURS(i.moneda,pkg_categconst.GetValConstanta(&apos;BancaCursTrezor&apos; ,i.AN,i.luna),i.datadoc,i.curs)
        END DATACURS, AGPERS.telefon as tel_agent,
        Coalesce(UBO.Nume,&apos;...nedefinit...&apos;) UBONume, Coalesce(UBO.Prenume,&apos;...nedefinit...&apos;) UBOPrenume, Coalesce(UBO.CNP,&apos;...nedefinit...&apos;) UBOCNP, UBO.BISERIA||&apos; &apos;||UBO.BINR UBOBI,
        UBOA.Email UBOEMAIL, ETRANS.UIT, EFACT.IDDESCARCARE, EFACT.IDINCARCARE
      FROM IESIRI I
        INNER JOIN NPART        P       ON P.CODPART        = I.PARTENER
        LEFT  JOIN NMONEDE      M       ON M.CODMONEDA      = Coalesce(I.MONEDA,0)
        LEFT  JOIN NMONEDE      MT      ON MT.CODMONEDA     = Coalesce(I.MONEDATRANSF,0)
        LEFT  JOIN DOCCARNETE   CAR     ON CAR.CODCARNET    = I.CARNETDOC
        LEFT  JOIN NPARTCODFISC CODF    ON CODF.COD_CODFISCAL = I.CODFISCAL
        LEFT  JOIN NPERS        U       ON U.LOGONNAME      = I.USERID
        LEFT  JOIN NAGENDA      UA      ON UA.CODAGENDA     = U.AGENDA
        LEFT  JOIN NAGENDA      SLIVR   ON SLIVR.CODAGENDA  = I.CODLOCATIE AND SLIVR.CODPART = I.PARTENER
        LEFT  JOIN NLOCALIT     LLIVR   ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
        LEFT  JOIN NJUDET       JLIVR   ON JLIVR.CODJUDET   = Coalesce(LLIVR.CODJUDET, 0)
        LEFT  JOIN NTARI        TLIVR   ON TLIVR.CODTARA    = Coalesce(LLIVR.CODTARA, 0)
        LEFT  JOIN NAGENDA      SFACT   ON SFACT.CODAGENDA  = CASE WHEN SLIVR.SediuSocial = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SediuSocial IN (3,7) THEN SLIVR.CODAGENDA ELSE 0 END
        LEFT  JOIN NLOCALIT     LFACT   ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
        LEFT  JOIN NJUDET       JFACT   ON JFACT.CODJUDET   = Coalesce(LFACT.CODJUDET, 0)
        LEFT  JOIN NTARI        TFACT   ON TFACT.CODTARA    = Coalesce(LFACT.CODTARA, 0)
        LEFT  JOIN NAGENDA      SSOC    ON SSOC.CODPART     = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
        LEFT  JOIN NLOCALIT     LSOC    ON LSOC.CODLOCALIT  = Coalesce(SSOC.CODLOCALIT, 0)
        LEFT  JOIN NJUDET       JSOC    ON JSOC.CODJUDET    = Coalesce(LSOC.CODJUDET, 0)
        LEFT  JOIN NTARI        TSOC    ON TSOC.CODTARA     = Coalesce(LSOC.CODTARA, 0)
        LEFT  JOIN NPARTB       B       ON B.CODPART        = P.CODPART AND B.IMPLICIT = 1
        LEFT  JOIN NBANK        BK      ON B.CODBANK        = BK.CODBANK
        LEFT  JOIN NPERS        AG      ON AG.CODPERS       = I.AGENT
        LEFT  JOIN NPARTTR      DEL     ON DEL.CODPARTTR    = I.DELEGAT
        LEFT  JOIN NPARTTR      PF      ON PF.CODPART       = I.PARTENER AND PF.IMPLICIT = 1
        LEFT  JOIN NPERSCONTACT PC      ON PC.CodPart       = P.CodPart AND PC.CodPersC = Coalesce(I.CodPersC,PC.CodPersC)
        LEFT  JOIN CONTRACT     C       ON C.CODCONTRACT    = I.CODCONTRACT
        LEFT  JOIN NPART        COMIS   ON COMIS.CODPART    = I.PARTCUSTODIE
        LEFT  JOIN NPARTCODFISC COMISCF ON COMISCF.CODPART  = I.PARTCUSTODIE AND COMISCF.PRINCIPAL = 1
        LEFT  JOIN NPARCAUT     PAUT    ON PAUT.CODNPARCAUT = I.CODAUTO
        LEFT  JOIN EMULARE      E       ON E.CODIES         = I.CODIES
        LEFT  JOIN NPERS        UBO     ON UBO.CODPERS      = E.CODPERS
        LEFT  JOIN NAGENDA      UBOA    ON UBOA.CODAGENDA   = UBO.AGENDA
        LEFT  JOIN NAGENDA      SSUB    ON SSUB.CODSUBUNIT  = I.SUBUNITATEA
        LEFT  JOIN NINTRASTAT   NI      ON I.TIPLIVRARE     = NI.CODNINTRASTAT
        LEFT  JOIN NAGENDA      AGPERS  ON AG.AGENDA        = AGPERS.CODAGENDA
        LEFT JOIN STATUSDECL ETRANS ON ETRANS.CODDOC = I.CODIES AND ETRANS.TIPDOC = 100 + I.TIPDOC
        LEFT JOIN STATUSDECL EFACT  ON EFACT.CODDOC = I.CODIES AND EFACT.TIPDOC = I.TIPDOC
      WHERE I.CODIES = vCodDoc
    ) LOOP
      IF vTipdoc &lt;&gt; 26
      THEN pCursDoc := TO_CHAR(v_rec.CursDoc,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
      ELSE
        IF Coalesce(pkg_categconst.GetValConstanta(&apos;FACTINVALUTA&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru),2) = 1 THEN
          pCursDoc := TO_CHAR(v_rec.CursDoc,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
        END IF;
      END IF;

      vValDoc := v_rec.ValDoc;
      vTVADoc := v_rec.TVADoc;

      IF vTipdoc = 26
      THEN vValDoc := Round(vValDoc,2);
      ELSE vValDoc := Round(vValDoc - vTVADoc,2) + Round(vTVADoc,2);
      END IF;
      --vValDoc := Round(vValDoc - vTVADoc,2) + Round(vTVADoc,2);
      vTVADoc := Round(vTVADoc,2);

      IF v_rec.TipTva IN (7,8)
      THEN vTVADoc := 0;
      END IF;

      vValLei := v_rec.ValDoc * v_rec.Curs;
      vTVALei := v_rec.TVADoc * v_rec.Curs;

      IF vTipdoc = 26
      THEN vValLei := Round(vValLei,2);
      ELSE vValLei := Round(vValLei - vTVALei,2) + Round(vTVALei,2);
      END IF;
      --vValLei := Round(vValLei - vTVALei,2) + Round(vTVALei,2);
      vTVALei := Round(vTVALei,2);

      pMoneda := v_rec.Den_Moneda;
      pSMoneda:= v_rec.SDenumire;

      IF pGetSoldListFact = &apos;1&apos;
      THEN
        vSoldPart := PKG_LIST_BASE_UTILS.GetSoldPart(v_rec.CodPart, 0 /*v_rec.CodLocatie*/);

        SELECT Coalesce(Sum(c1.restacceptat*c1.pu),0) INTO vComCurs
        FROM comanda c INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda AND c1.restacceptat &lt;&gt; 0
        WHERE c.partener = v_rec.CodPart AND c.tipdoc = 18 AND pkg_globals.GetSubunitate IN (1,c.subunitatea);

        SELECT Coalesce(Sum(SoldLei),0) INTO vSoldPartLP
        FROM NPARTSOLDLUNA
        WHERE CodPart = v_rec.CodPart AND an*12+luna = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU -1;
      END IF;

      pkg_list_Struct.ADAUGA_PARAM(&apos;ANULAT&apos;,                          v_rec.AnulatX);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.Den_Part);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SeriaDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,                v_rec.CodExtern);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODINTERN&apos;,                v_rec.CodIntern);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,              v_rec.Autorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL/CNP&apos;,            v_rec.C_CUI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL&apos;,                v_rec.C_CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CNP&apos;,                      v_rec.C_CNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,          v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD STATISTIC BNR&apos;,        v_rec.CodStatisticBNR);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CREDIT&apos;,                   v_rec.CREDITCLIENT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA (/)&apos;,               To_Char(v_rec.DataDoc,&apos;dd/mm/yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR LINII&apos;,            v_rec.NrLinii);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR LINII LISTA&apos;,      vLiniiTMP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BON NUMAR&apos;,                       v_rec.NrBon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BON DATA&apos;,                        To_Char(v_rec.DataBon,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;MOD INCASARE RETAIL&apos;,             v_rec.MODPLATA);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE&apos;,                    NumarRO(Round(vValDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE ENG&apos;,                NumarUK(Round(vValDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL&apos;,                       TO_CHAR(vValDoc-vTvaDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE&apos;,                NumarRO(Round(vValDoc-vTvaDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE ENG&apos;,            NumarUK(Round(vValDoc-vTvaDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(vTVADoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(vTVADoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(vTVADoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE&apos;,                    TO_CHAR(v_rec.Accize,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE LITERE&apos;,             NumarRO(Round(v_rec.Accize,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE LITERE ENG&apos;,         NumarUK(Round(v_rec.Accize,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CURS&apos;,                     TO_CHAR(v_rec.Curs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA DATA CURS&apos;,                v_rec.DataCurs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CURS CALCUL PRET&apos;,                pCursDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CALCUL PRET&apos;,              v_rec.Den_MonedaT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI&apos;,                TO_CHAR(vValLei - vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE&apos;,      NumarRO(Round(vValLei - vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vValLei - vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI&apos;,                TO_CHAR(vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE&apos;,      NumarRO(Round(vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL FACT.VALUTA IN LEI&apos;,        TO_CHAR(vValLei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LA PRET MAXIMAL&apos;,           TO_CHAR(vDocMax,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LA PRET MAXIMAL Cu TVA&apos;,    TO_CHAR(vDocMax+vTvaMax,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN BUCATI&apos;,       TO_CHAR(vCantBuc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN CUTII&apos;,        TO_CHAR(vCantCut,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL GREUTATE SPECIFICA CUTII&apos;,  TO_CHAR(vGSpCut, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN PALETI&apos;,       TO_CHAR(vCantPal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;Regim scutire&apos;,                   v_rec.REG_SCUTIRE);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit EMAIL&apos;,                  v_rec.UEMAIL);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Operator nume &apos;,                  v_rec.UBONUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Operator prenume&apos;,                v_rec.UBOPRENUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Operator CNP&apos;,                    v_rec.UBOCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Operator BI&apos;,                     v_rec.UBOBI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Operator EMAIL&apos;,                  v_rec.UBOEMAIL);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SERIE CARTE IDENTITATE&apos;,          v_rec.PFSerieDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR CARTE IDENTITATE&apos;,          v_rec.PFNrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DELEGAT CNP&apos;,                     v_rec.PFCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,    v_rec.SLivrAdresaNoCP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,               v_rec.SLivrFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE IDSEDIU&apos;,           v_rec.SLivrIDSediu);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE STRADA&apos;,            v_rec.SLivrStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE NUMAR STRADA&apos;,      v_rec.SLivrNrStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE SECTOR&apos;,            v_rec.SLivrSector);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE&apos;,        v_rec.SFactObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,          v_rec.SFactAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA FARA CP&apos;,  v_rec.SFactAdresaNoCP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATE&apos;,      v_rec.SFactLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,         v_rec.SFactTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE FAX&apos;,             v_rec.SFactFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDET&apos;,           v_rec.SFactSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,  v_rec.SFactJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD POSTAL&apos;,      v_rec.SFactCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD FISCAL&apos;,      v_rec.SFactCodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD LA CLIENT&apos;,   v_rec.SFactCodClient);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,            v_rec.SFactTara);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,           v_rec.SFactEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE IDSEDIU&apos;,         v_rec.SFactIDSediu);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE STRADA&apos;,          v_rec.SFactStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE NUMAR STRADA&apos;,    v_rec.SFactNrStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE SECTOR&apos;,          v_rec.SFactSector);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.SSocObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.SSocAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA FARA CP&apos;,     v_rec.SSocAdresaNoCP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.SSocLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.SSocTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL FAX&apos;,                v_rec.SSocFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SSocSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.SSocJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.SSocCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.SSocCodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.SSocCodClient);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.SSocTara);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,              v_rec.SSocEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL IDSEDIU&apos;,            v_rec.SSocIDSediu);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL STRADA&apos;,             v_rec.SSocStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL NUMAR STRADA&apos;,       v_rec.SSocNrStrada);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL SECTOR&apos;,             v_rec.SSocSector);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;,                     v_rec.ContBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;,                    v_rec.DenBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;,             v_rec.SimbBanca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SUCURSALA BANCA&apos;,          v_rec.Sucursala);
      --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                     TO_CHAR(vSoldPart ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD NEACOPERIT&apos;,          TO_CHAR(vSoldPart+vComCurs, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD DOAR DIN IESIRI&apos;,     TO_CHAR(vSoldPart, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD LUNA PRECEDENTA&apos;,     TO_CHAR(vSoldPartLP, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;COTA TVA&apos;,                        TO_CHAR(vPjTVA,&apos;fm9G999G999G990&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TVA LA INCASARE&apos;,                 v_rec.TVAINCASARE);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DATA DE CALCUL TVA&apos;,              To_Char(v_rec.DataTva,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT FARA TVA&apos;,               &apos;Discount: &apos;   ||TO_CHAR(v_rec.ValDiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT TVA&apos;,                    &apos;TVADiscount: &apos;||TO_CHAR(v_rec.TVADiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT CU TVA&apos;,                 &apos;Discount: &apos;   ||TO_CHAR(v_rec.ValDiscount+v_rec.TVADiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.ANUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                       v_rec.ACNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                        v_rec.ABI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,               v_rec.DelNume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,           v_rec.DelCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,              v_rec.DelDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,          v_rec.DelNRdoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,        v_rec.DelSerDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,          v_rec.DelElib);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,        To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                   v_rec.DelMTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,             v_rec.DelNrTransp);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AUTO NUMAR&apos;,                      v_rec.AutoNr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.Obs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIP TRANZACTIE&apos;,                  v_rec.Tip_Tranz);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PARTICULARITATI TVA&apos;,             v_rec.Tip_Tva);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,             v_rec.PCNume);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT TELEFON&apos;,     v_rec.PCTel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT EMAIL&apos;,       v_rec.PCEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA&apos;         ,      SitV);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - MONEDA&apos;,      v_rec.MonedaSitV);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - BANCA&apos; ,      v_rec.BancaSitV);
      pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - CURS&apos;  ,      TO_CHAR(v_rec.CursSitV,&apos;fm9G999G999G990D0000&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;PROCENT APLICAT LA CURS&apos;,         TO_CHAR(v_rec.ProcCurstransf,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;CONTRACT NUMAR&apos; ,                 v_rec.C_NrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CONTRACT DATA&apos; ,                  v_rec.C_DataDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CONTRACT OBSERVATII&apos; ,            v_rec.C_Obs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE TELEFON&apos; ,             v_rec.SubTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE FAX&apos; ,                 v_rec.SubFax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT TELEFON&apos; ,                  v_rec.tel_agent);
      if vTipDoc in (19,20,26) then
        pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTerms&apos;,                       v_rec.InCoTerms);
        pkg_list_Struct.ADAUGA_PARAM(&apos;INCOTERMS SIMBOL&apos;,                v_rec.simbolInCoTerms);
      end if;
      if vTipDoc in (19,20) then
        pkg_list_Struct.ADAUGA_PARAM(&apos;UIT&apos;,                       v_rec.UIT);
        pkg_list_Struct.ADAUGA_PARAM(&apos;IDDESCARCARE&apos;,              v_rec.IDDESCARCARE);
        pkg_list_Struct.ADAUGA_PARAM(&apos;IDINCARCARE&apos;,               v_rec.IDINCARCARE);
      end if;
      if vTipDoc = 26 then
        pkg_list_Struct.ADAUGA_PARAM(&apos;IDDESCARCARE&apos;,              v_rec.IDDESCARCARE);
        pkg_list_Struct.ADAUGA_PARAM(&apos;IDINCARCARE&apos;,               v_rec.IDINCARCARE);
      end if;
      IF vTipdoc IN (19,21) THEN
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR NUME&apos;,               v_rec.COMIS_NUME);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODINTERN&apos;,          v_rec.COMIS_CODINTERN);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODEXTERN&apos;,          v_rec.COMIS_CODEXTERN);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODFISCAL/CNP&apos;,      v_rec.COMIS_CODFISCAL);
        pkg_list_Struct.ADAUGA_PARAM(&apos;VOUCHER DATA&apos;,                  To_Char(v_rec.DataDoc,&apos;dd/mm/yyyy&apos;));
      END IF;

      EXIT;
    END LOOP;

    FOR v_rec IN (
      SELECT
        vc2_nt_to_string(CAST(COLLECT(InfoTScad ORDER BY Termen) AS vc2_nt), 24) InfoScadT,
        vc2_nt_to_string(CAST(COLLECT(InfoZScad ORDER BY Termen) AS vc2_nt), 24) InfoScadZ,
        vc2_nt_to_string(CAST(COLLECT(SInfoTScad ORDER BY Termen) AS vc2_nt), 24) SInfoScadT,
        vc2_nt_to_string(CAST(COLLECT(SInfoZScad ORDER BY Termen) AS vc2_nt), 24) SInfoScadZ,
        vc2_nt_to_string(CAST(COLLECT(DenPlata  ORDER BY Termen) AS vc2_nt), 24) InfoTipP,
        Max(Termen) ScadTermenMax, Max(Zile) ScadZileMax, Max(Majorari) ScadMajMax
      FROM (
        SELECT
          TO_CHAR(O.TERMEN,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||TO_CHAR(O.Valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)||M.Simbol||&apos;-&apos;||TP.DenPlata InfoTScad,
          (O.TERMEN - I.DATADOC)||&apos;-&apos;||TO_CHAR(O.Valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)||M.Simbol||&apos;-&apos;||TP.DenPlata InfoZScad,
          TO_CHAR(O.TERMEN,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||TO_CHAR(O.Valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)||M.Simbol SInfoTScad,
          (O.TERMEN - I.DATADOC)||&apos;-&apos;||TO_CHAR(O.Valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)||M.Simbol SInfoZScad,
          TP.DenPlata,
          O.TERMEN, O.TERMEN - I.DATADOC ZILE, O.MAJORARI
        FROM IESIRI I
          INNER JOIN GENERAL  G ON G.TIPDOC     = I.TIPDOC AND G.CODDOC = I.CODIES
          INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
          LEFT  JOIN NMONEDE  M ON M.CODMONEDA  = Coalesce(G.MONEDA,0)
          LEFT  JOIN (
            SELECT
              LEVEL TIPPLATA,
              CASE LEVEL
                WHEN 1 THEN &apos;Numerar&apos;
                WHEN 2 THEN &apos;Ordin Plata&apos;
                WHEN 3 THEN &apos;Cec&apos;
                WHEN 4 THEN &apos;Bilet la Ordin&apos;
                WHEN 5 THEN &apos;Compensare&apos;
                WHEN 6 THEN &apos;Majorari&apos;
                WHEN 7 THEN &apos;CEC/BO girat&apos;
                WHEN 8 THEN &apos;BO avalizat&apos;
                WHEN 9 THEN &apos;Avans&apos;
                WHEN 10 THEN &apos;Ramburs&apos;
                WHEN 11 THEN &apos;CARD&apos;
                WHEN 12 THEN &apos;De comun acord&apos;
                WHEN 13 THEN &apos;Voucher CARD&apos;
                WHEN 14 THEN &apos;Voucher CEC&apos;
                ELSE &apos;...nedefinit...&apos;
              END DenPlata
            FROM DUAL CONNECT BY LEVEL &lt;= 14
          ) TP ON TP.TIPPLATA = Coalesce(O.TIPPLATA,1)
        WHERE I.CODIES = vCodDoc AND G.SEMNIFICATIE = 200
        ORDER BY O.TERMEN)
      )
    LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;SCADENTA&apos;,                        TO_CHAR(v_rec.ScadTermenMax,&apos;dd.mm.yyyy&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;SCADENTE MULTIPLE&apos;,               v_rec.InfoScadT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SCADENTE MULTIPLE SIMPL.&apos;,        v_rec.SInfoScadT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ZILE SCADENTA&apos;,                   v_rec.ScadZileMax);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ZILE SCADENTE MULTIPLE&apos;,          v_rec.InfoScadZ);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ZILE SCADENTE MULTIPLE SIMPL.&apos;,   v_rec.SInfoScadZ);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIPPLATA&apos;,                        v_rec.InfoTipP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;MAJORARI&apos;,                        TO_CHAR(v_rec.ScadMajMax,&apos;fm9G999G999G990D9999999&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    END LOOP;

    FOR v_rec IN (
      SELECT
        vc2_nt_to_string(CAST(COLLECT(Doc                           ORDER BY DATADOC) AS vc2_nt)) IncDoc,
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(NrDoc)                ORDER BY DATADOC) AS vc2_nt)) IncNrDoc,
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(DataDoc,&apos;dd.mm.yyyy&apos;) ORDER BY DATADOC) AS vc2_nt)) IncDataDoc,
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(VALDOC,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ORDER BY DATADOC) AS vc2_nt)) IncVal,
        CASE WHEN Count(1) = 1 THEN Sum(VALDOC) ELSE NULL END IncSum
      FROM (
        SELECT T1.DOC||&apos; &apos;||T1.NRDOC DOC, T1.NRDOC, T1.DATADOC, T1.VALDOC
        FROM (
          SELECT DISTINCT GS.CODDOC CODTREZOR1
          FROM GENERAL G
            INNER JOIN OBLIGPIF O  ON O.CODGENERAL   = G.CODGENERAL
            INNER JOIN STINGERE S  ON S.CODSTINSPIF  = O.CODOBLIGPIF
            INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  GS ON GS.CODGENERAL  = OS.CODGENERAL AND GS.TIPDOC IN (29, 30, 31)
          WHERE G.TIPDOC = vTipDoc AND G.CODDOC = vCodDoc
        ) TMP INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = TMP.CODTREZOR1
      )
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI DOC&apos;,                    v_rec.IncDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI NRDOC&apos;,                  v_rec.IncNrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI DATA&apos;,                   v_rec.IncDataDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI VALORI&apos;,                 v_rec.IncVal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI LITERE&apos;,                 NumarRO(Round(v_rec.IncSum,2), pMoneda, &apos;&apos;, pSMoneda, &apos;&apos;) );
      pkg_list_Struct.ADAUGA_PARAM(&apos;INCASARI MONEDE&apos;,                 pMoneda);
    END LOOP;

    --- COMPENSARI
    FOR v_rec IN (
      SELECT
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(NrDoc) ORDER BY DATADOC) AS vc2_nt)) CompNrDoc,
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(DataDoc, &apos;dd.mm.yyyy&apos;) ORDER BY DATADOC) AS vc2_nt)) CompDataDoc,
        vc2_nt_to_string(CAST(COLLECT(TO_CHAR(valCmp, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ORDER BY DATADOC) AS vc2_nt)) CompVal
      FROM (
        SELECT cmp.NRDOC, cmp.DATADOC, tmp.valCmp
        FROM (
          SELECT GS.CODDOC codcompens, sum(os.valoare) as valCmp
          FROM GENERAL G
            INNER JOIN OBLIGPIF O  ON O.CODGENERAL = G.CODGENERAL
            INNER JOIN STINGERE S  ON S.CODSTINSPIF = O.CODOBLIGPIF
            INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  GS ON GS.CODGENERAL = OS.CODGENERAL AND GS.TIPDOC IN (28)
          WHERE G.TIPDOC = vTipDoc AND G.CODDOC = vCodDoc
          GROUP BY GS.CODDOC
        ) TMP
          INNER JOIN COMPENS cmp ON cmp.codcompens = TMP.codcompens
      )
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPENSARI NRDOC&apos;,                v_rec.CompNrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPENSARI DATA&apos;,                 v_rec.CompDataDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;COMPENSARI VALORI&apos;,               v_rec.CompVal);
    END LOOP;

    IF vTipDoc = 26 THEN
      FOR v_rec IN (
        SELECT
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(NrDoc)                ORDER BY CODCOMANDA) AS vc2_nt),100) ComDoc,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(DataDoc,&apos;dd.mm.yyyy&apos;) ORDER BY CODCOMANDA) AS vc2_nt),100) ComData,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(Nri)                  ORDER BY CODCOMANDA) AS vc2_nt),100) ComNri
        FROM (
          SELECT DISTINCT c.codcomanda, c.prefixdoc, c.nrdoc, c.datadoc, c.nri
          FROM iesiri i
            INNER JOIN iesiri1  i1  ON i1.codies      = i.codies
            INNER JOIN ieslink  ila ON ila.codies1    = i1.codies1
            INNER JOIN ieslink  ilc ON ilc.codies1    = ila.codlinieaviz
            INNER JOIN comanda1 c1  ON c1.codcomanda1 = ilc.codliniecomanda
            INNER JOIN comanda  c   ON c.codcomanda   = c1.codcomanda
          WHERE i.codies = vCodDoc)
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI NR&apos;,                    v_rec.ComDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI DATA&apos;,                  v_rec.ComData);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI NRI&apos;,                   v_rec.ComNri);
      END LOOP;

      FOR v_rec IN (
        SELECT
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(nrlivr)                ORDER BY codlivr) AS vc2_nt)) LivrDoc,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(datalivr,&apos;dd.mm.yyyy&apos;) ORDER BY codlivr) AS vc2_nt)) LivrData,
          vc2_nt_to_string(CAST(COLLECT(obs                            ORDER BY codlivr) AS vc2_nt)) LivrObs
        FROM (
          SELECT DISTINCT l.codlivr, l.nrlivr, l.datalivr, l.obs
          FROM iesiri i
            INNER JOIN iesiri1 i1  ON i1.codies   = i.codies
            INNER JOIN ieslink ila ON ila.codies1 = i1.codies1
            INNER JOIN iesiri1 ae1 ON ae1.codies1 = ila.codlinieaviz
            INNER JOIN livr    l   ON l.codies    = ae1.codies
          WHERE i.codies = vCodDoc)
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI NR&apos;,                    v_rec.LivrDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI DATA&apos;,                  v_rec.LivrData);
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI OBS&apos;,                   v_rec.LivrObs);
      END LOOP;

    ELSE
      FOR v_rec IN (
        SELECT
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(NrDoc)                ORDER BY CODCOMANDA) AS vc2_nt),100) ComDoc,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(DataDoc,&apos;dd.mm.yyyy&apos;) ORDER BY CODCOMANDA) AS vc2_nt),100) ComData,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(Nri)                  ORDER BY CODCOMANDA) AS vc2_nt),100) ComNri,
          vc2_nt_to_string(CAST(COLLECT(prefixdoc                     ORDER BY CODCOMANDA) AS vc2_nt),100) ComPrefix,
          vc2_nt_to_string(CAST(COLLECT(serie                         ORDER BY CODCOMANDA) AS vc2_nt),100) ComSerie
        FROM (
          SELECT DISTINCT c.codcomanda, c.prefixdoc, c.nrdoc, c.datadoc, c.nri, Coalesce(c.seriadoc,d.serie,&apos; &apos;) serie
          FROM iesiri i
            INNER JOIN iesiri1   i1  ON i1.codies      = i.codies
            INNER JOIN ieslink   ilc ON ilc.codies1    = i1.codies1
            INNER JOIN comanda1  c1  ON c1.codcomanda1 = ilc.codliniecomanda
            INNER JOIN comanda   c   ON c.codcomanda   = c1.codcomanda
            LEFT JOIN doccarnete d   ON d.codcarnet    = c.carnetdoc
          WHERE i.codies = vCodDoc)
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI PREFIX&apos;,                v_rec.ComPrefix);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI NR&apos;,                    v_rec.ComDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI DATA&apos;,                  v_rec.ComData);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI NRI&apos;,                   v_rec.ComNri);
        pkg_list_Struct.ADAUGA_PARAM(&apos;COMENZI SERIE&apos;,                 v_rec.ComSerie);
      END LOOP;

      FOR v_rec IN (
        SELECT
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(nrlivr)                ORDER BY codlivr) AS vc2_nt)) LivrDoc,
          vc2_nt_to_string(CAST(COLLECT(TO_CHAR(datalivr,&apos;dd.mm.yyyy&apos;) ORDER BY codlivr) AS vc2_nt)) LivrData,
          vc2_nt_to_string(CAST(COLLECT(obs                            ORDER BY codlivr) AS vc2_nt)) LivrObs
        FROM livr
        WHERE codies = vCodDoc
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI NR&apos;,                    v_rec.LivrDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI DATA&apos;,                  v_rec.LivrData);
        pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI OBS&apos;,                   v_rec.LivrObs);
      END LOOP;

    END IF;

    FOR v_rec IN (
      SELECT
        Max(CASE WHEN Idx =  1 THEN Den ELSE NULL END) Den1,
        Max(CASE WHEN Idx =  1 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val1,
        Max(CASE WHEN Idx =  2 THEN Den ELSE NULL END) Den2,
        Max(CASE WHEN Idx =  2 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val2,
        Max(CASE WHEN Idx =  3 THEN Den ELSE NULL END) Den3,
        Max(CASE WHEN Idx =  3 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val3,
        Max(CASE WHEN Idx =  4 THEN Den ELSE NULL END) Den4,
        Max(CASE WHEN Idx =  4 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val4,
        Max(CASE WHEN Idx =  5 THEN Den ELSE NULL END) Den5,
        Max(CASE WHEN Idx =  5 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val5,
        Max(CASE WHEN Idx =  6 THEN Den ELSE NULL END) Den6,
        Max(CASE WHEN Idx =  6 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val6,
        Max(CASE WHEN Idx =  7 THEN Den ELSE NULL END) Den7,
        Max(CASE WHEN Idx =  7 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val7,
        Max(CASE WHEN Idx =  8 THEN Den ELSE NULL END) Den8,
        Max(CASE WHEN Idx =  8 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val8,
        Max(CASE WHEN Idx =  9 THEN Den ELSE NULL END) Den9,
        Max(CASE WHEN Idx =  9 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val9,
        Max(CASE WHEN Idx = 10 THEN Den ELSE NULL END) Den10,
        Max(CASE WHEN Idx = 10 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val10,
        TO_CHAR(Coalesce(Sum(Val),0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ValTot
      FROM (
        SELECT
          Row_Number() OVER (ORDER BY Sign(i1.cant), i1.codcriteriu) Idx,
          CASE WHEN Sign(i1.cant)&gt;0  THEN &apos;Majorare &apos; ELSE &apos;Discount &apos; END || CASE WHEN i1.codcriteriu=2 THEN &apos;client&apos; ELSE cd.dencriteriu END den,
          Sum(i1.restfact) val
        FROM iesiri1 i1 LEFT JOIN criteriidisc cd ON cd.codcriteriu = i1.codcriteriu
        WHERE i1.codies = vCodDoc
          AND i1.tiplinie IN (&apos;G&apos;, &apos;T&apos;)
          AND i1.codcriteriu &gt; 1
        GROUP BY Sign(i1.cant), i1.codcriteriu, cd.dencriteriu
        ORDER BY Sign(i1.cant), i1.codcriteriu
      )
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_DEN&apos;,                     v_rec.Den1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_VAL&apos;,                     v_rec.Val1);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_DEN&apos;,                     v_rec.Den2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_VAL&apos;,                     v_rec.Val2);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_DEN&apos;,                     v_rec.Den3);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_VAL&apos;,                     v_rec.Val3);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_DEN&apos;,                     v_rec.Den4);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_VAL&apos;,                     v_rec.Val4);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_DEN&apos;,                     v_rec.Den5);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_VAL&apos;,                     v_rec.Val5);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_DEN&apos;,                     v_rec.Den6);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_VAL&apos;,                     v_rec.Val6);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_DEN&apos;,                     v_rec.Den7);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_VAL&apos;,                     v_rec.Val7);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_DEN&apos;,                     v_rec.Den8);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_VAL&apos;,                     v_rec.Val8);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_DEN&apos;,                     v_rec.Den9);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_VAL&apos;,                     v_rec.Val9);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_DEN&apos;,                    v_rec.Den10);
      pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_VAL&apos;,                    v_rec.Val10);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL DISC. PARTENER&apos;,          v_rec.ValTot);
    END LOOP;

    FOR v_rec IN (
        SELECT
             GestPlecare ,AdrGestPlecare, gest_prel, localit_prel, adresa_prel,
                gest_livr, localit_livr, adresa_livr,
                kmin, kmout,
                DataPlecare, DataSosire, DataPreluare
        FROM (
          SELECT N.DEN_GEST GestPlecare, GETADRESA(A.SECTOR,A.STRADA,A.NR1,A.NR2,A.BLOC,A.SCARA,A.ETAJ,A.APART,A.CODPOSTAL) AdrGestPlecare,
                racgp.den_gest gest_prel, raclp.den_localit localit_prel, r.adresa_prel adresa_prel,
                racgl.den_gest gest_livr, racll.den_localit localit_livr, r.adresa_livr adresa_livr,
                r.kmin, r.kmout,
                r.DataStart DataPlecare, r.DataStop DataSosire, r.DataPred DataPreluare
          FROM iesiri i
            INNER JOIN iesiri1  i1    ON i1.codies        = i.codies
            INNER JOIN ieslink  ilc   ON ilc.codies1      = i1.codies1
            INNER JOIN comanda1 c1    ON c1.codcomanda1   = ilc.codliniecomanda
            INNER JOIN Rac_rez  R     ON R.codcomanda     = c1.codcomanda
            INNER JOIN nlocalit raclp ON raclp.codlocalit = r.codlocalit_prel
            INNER JOIN ngest    racgp ON racgp.codgest    = r.codgestsursa
            INNER JOIN ngest    racgl ON racgl.codgest    = r.codgestdest
            INNER JOIN nlocalit racll ON racll.codlocalit = r.codlocalit_livr
            INNER JOIN NGEST    N     ON N.CodGest = R.Codgestsursa
            INNER JOIN NAGENDA  A     ON A.CODGEST = N.CODGEST
          WHERE i.codies = vCodDoc)
      )
    LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_GestPlecare&apos;,               v_rec.GestPlecare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_AdrGestPlecare&apos;,            v_rec.AdrGestPlecare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_GESTIUNEA PRELUARE&apos;,        v_rec.gest_prel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_LOCALITATE PRELUARE&apos;,       v_rec.localit_prel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ADRESA PRELUARE&apos;,           v_rec.adresa_prel);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_GESTIUNEA LIVRARE&apos;,         v_rec.gest_livr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_LOCALITATE LIVRARE&apos;,        v_rec.localit_livr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_ADRESA LIVRARE&apos;,            v_rec.adresa_livr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_KM PLECARE&apos;,                v_rec.kmout);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_KM INTOARCERE&apos;,             v_rec.kmin);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_Data plecare&apos;,              v_rec.DataPlecare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_Data sosire&apos;,               v_rec.DataSosire);
      pkg_list_Struct.ADAUGA_PARAM(&apos;RAC_Data preluare&apos;,             v_rec.DataPreluare);
    END LOOP;


    pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;IESIRIEXT&apos;, &apos;CODIES&apos;, vCodDoc);
  END IF;

  FOR v_rec IN (
    SELECT
      SUM(i1.pu * i1.cant) ValBruta,
      SUM(ABS(i1.cant) * Coalesce(o.volum,0)) Volum,
      SUM(ABS(i1.cant) * Coalesce(o.masa, 0)) Masa,
      SUM(ABS(i1.cant) * Coalesce(o.masa, 0) * Coalesce(u.coef, 1)) MasaM,
      SUM(Ceil(i1.cant) * (SELECT count(1) FROM nartobjcolet oc WHERE oc.codobiect = i1.codobiect) ) NrCol
    FROM iesiri1 i1
      INNER JOIN nartobj o ON o.codobiect  = i1.codobiect
      INNER JOIN nart    a ON A.CODARTICOL = O.CODARTICOL
      INNER JOIN NUM     U ON U.CODUM = A.UM
    WHERE i1.codies = vCodDoc
      AND NOT (i1.tiplinie IN (&apos;G&apos;, &apos;T&apos;))
    GROUP BY i1.codies
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE BRUTA&apos;,                 TO_CHAR(v_rec.ValBruta,    &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,                   TO_CHAR(v_rec.Masa,        &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA ROTUNJITA&apos;,         TO_CHAR(Round(v_rec.Masa), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA MULTIPLA&apos;,                 TO_CHAR(v_rec.MasaM,       &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,                   TO_CHAR(v_rec.Volum,       &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR COLETE TOTAL&apos;,               TO_CHAR(v_rec.NrCol,       &apos;fm9G999G999G990&apos;,    &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  if vTipDoc = 19 then
    for v_rec in (
      select stragg3200(den_gest) gestiuni, stragg3200(getadresa(sector,strada,nr1,NR2,bloc,scara,etaj,apart,codpostal)) adresa from
      (
       select distinct g.den_gest,ag.sector,ag.strada,ag.nr1,ag.NR2,ag.bloc,ag.scara,ag.etaj,ag.apart,ag.codpostal
       from livr l
            inner join livr1   l1 on l.codlivr     = l1.codlivr
            left  join nirstoc ns on ns.codnirstoc = l1.codnirstoc
            left  join nir        on nir.codnir    = ns.codnir
            left  join livrval lv on lv.codlivr1   = l1.codlivr1
            left  join ngest   g  on g.codgest     = coalesce(nir.gest,lv.gest)
            left  join nagenda ag on ag.codgest    = g.codgest
       where l.codies = vCodDoc
      )
    ) loop
      pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNI LIVRARE&apos;, v_rec.gestiuni);
      pkg_list_Struct.ADAUGA_PARAM(&apos;ADRESA GESTIUNI LIVRARE&apos;, v_rec.adresa);
    end loop;
    for v_rec in (
         SELECT
                 vc2_nt_to_string(CAST(COLLECT(I1.OBS) AS vc2_nt),100) VoucherObs,
                 vc2_nt_to_string(CAST(COLLECT(SF.COD) AS vc2_nt),100) VoucherCod,
                 -1 * sum(i1.PU * i1.Cant) VoucherPret
            FROM
                iesiri i
                INNER JOIN iesiri1 i1 ON i1.codies = i.codies
                LEFT JOIN SERVFACT SF ON sf.codservfact = i1.codserie
            WHERE
                i.codies = vCodDoc
                and i1.taxa = 2
      )
     loop
      pkg_list_Struct.ADAUGA_PARAM(&apos;Voucher cod&apos;, v_rec.VoucherCod);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Voucher obs&apos;, v_rec.VoucherObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Voucher pret&apos;, v_rec.VoucherPret);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Total fara voucher&apos;, to_char(vValDoc + v_rec.VoucherPret,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)) ;
      pkg_list_Struct.ADAUGA_PARAM(&apos;Total neformatat&apos;  , to_char(vValDoc                    ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)) ;
    end loop;
  end if;

  IF vTipDoc in (19,20,26) THEN
    DELETE FROM LST_DOCIES_TVA;
    PKG_IESIRI.SetValFin(vCodDoc, 0);

    INSERT INTO LST_DOCIES_TVA (TVA,VALOARE,BAZA)
    SELECT Coalesce(ss_t.TVA, ss_i.TVA), Coalesce(ss_i.Valoare, 0), Coalesce(ss_i.Baza, 0)
    FROM (
      SELECT ss_a.TVA, Sum(Round(ss_a.VALOARE*ss_a.COEF, ss_a.RotZec)) AS VALOARE, Sum(Round(ss_a.BAZA*ss_a.COEF, ss_a.RotZec)) AS BAZA
      FROM (
        SELECT
          Round(PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1), 0) TVA,
          Coalesce(I1.VALFIN,I1.PU*I1.Cant, 0) BAZA, Coalesce(I1.TVAFIN,I1.TVA,0) VALOARE,
          CASE
            WHEN BITAND(Coalesce(i.Flags, 0), 1) &lt;&gt; 0 THEN 1
            WHEN Coalesce(i1.CoefDiscMaj, 1) = 1      THEN 1
            WHEN I1.PretOrig = 0                      THEN 0
            WHEN I1.PU = 0                            THEN 0
            ELSE                                           i1.CoefDiscMaj * I1.PretOrig / I1.PU
          END Coef,
          CASE WHEN Coalesce(I.ROTEFACT, 0) = 1 THEN 2 ELSE 7 END RotZec
        FROM IESIRI1 I1
          INNER JOIN IESIRI          I  ON i.codies      = i1.codies
          LEFT  JOIN NARTOBJ         O  ON o.codobiect   = i1.codobiect
          LEFT  JOIN NART1           A1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
          LEFT  JOIN NTVA1           T1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
        WHERE I1.CODIES = vCodDoc AND NOT I1.TIPLINIE IN (&apos;G&apos;,&apos;T&apos;)
      ) ss_a
      GROUP BY ss_a.TVA
    ) ss_i FULL JOIN (
      SELECT 0 TVA FROM DUAL
      UNION
      SELECT Coalesce(TO_NUMBER(VALOARE),0) TVA
      FROM const1 c1
        INNER JOIN constluna cl ON cl.codconst1 = c1.codconst1
        INNER JOIN constval  cv ON cv.codconstluna = cl.codconstluna
      WHERE UPPER(c1.SIMBOL) IN (&apos;PROCTVAMIN&apos;,&apos;PROCTVAMED&apos;,&apos;PROCTVAMAX&apos;,&apos;PROCTVAREG&apos;,&apos;PROCTVAREG2&apos;,&apos;PROCTVAREG3&apos;,&apos;PROCTVAREG4&apos;,&apos;PROCTVAREG5&apos;) AND vAnLuna BETWEEN CL.ALSTART AND CL.ALSTOP
    ) ss_t ON ss_t.TVA = ss_i.TVA;

    COMMIT;

    FOR V_REC IN (SELECT TVA, VALOARE, BAZA FROM LST_DOCIES_TVA) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare TVA &apos;     ||To_Char(v_rec.tva, &apos;fm990&apos;), to_char(v_rec.Valoare               ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare baza TVA &apos;||To_Char(v_rec.tva, &apos;fm990&apos;), to_char(v_rec.Baza                  ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare cu TVA &apos;  ||To_Char(v_rec.tva, &apos;fm990&apos;), to_char((v_rec.Valoare + v_rec.Baza),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    END LOOP;
  END IF;

  BEGIN
    SELECT Coalesce(Partener,0) INTO vCodPart FROM iesiri WHERE codies = vCodDoc;
  EXCEPTION WHEN OTHERS THEN vCodPart := 0;
  END;
  IF vCodPart &gt; 0 THEN
    pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;NPARTDET&apos;, &apos;CODPART&apos;, vCodPart, &apos;CLIENT &apos;);
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sPjTVA     VARCHAR2(  300):= &apos;PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TMP_TVA.PROCENT, I.ROTEFACT, 1)&apos;;
  sCondDiscP VARCHAR2(  100);
  sCondClasa VARCHAR2(  100);
  sInsertDC  VARCHAR2(10000);
  sSelectDC  VARCHAR2( 5000);
  sNullDC    VARCHAR2( 2000);
  sWithDC    VARCHAR2( 5000);
  sJoinSer   VARCHAR2( 1000);
  sDenDisc   VARCHAR2(  500);
  sInsMAN    VARCHAR2(30000);
  sSelect1   VARCHAR2( 1000);
  sGroupBy1  VARCHAR2( 1000);
  sGroupBy2  VARCHAR2( 1000);
  sJoinL1M   VARCHAR2( 5000);
  sJoinAux   VARCHAR2(10000);
  ConstPAPL  NUMBER         := Coalesce(pkg_categconst.GetValConstanta(&apos;ProcAdaosPeLinie&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru),2);
  ConstPDPL  NUMBER         := Coalesce(pkg_categconst.GetValConstanta(&apos;ProcDiscPeLinie&apos; ,pkg_globals.AnLucru,pkg_globals.LunaLucru),2);
  vTipTva    NUMBER;
  aPart      NUMBER;
  aClasa     NUMBER;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  gSuplCols :=
    &apos;iesiri i, iesiri1 i1, nartobj nao, nart na, nclasea c, nclaseas cs, npart p, iesiri ae, comanda1 com1, comanda com, comanda cc, &apos;||
    &apos;nartcli ac, nartobjtrad ntrad, ntva1 tmp_tva, oferta1 o1, lst_docies_ser ms, lst_docies_ns mns, lst_docies_ml ml&apos;;

  sJoinAux := &apos;&apos;;
  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;mi1.cant&apos;,&apos;i1.codobiect&apos;,sInsertDC,sSelectDC,sJoinAux);

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,    &apos;OAS&apos;,   &apos;OAS.CODOBIECT = I1.CODOBIECTORIG&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM1&apos;,       &apos;UM&apos;,    &apos;UM.CODUM1 = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,        &apos;UM1&apos;,   &apos;UM1.CODUM = NA.UM1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,        &apos;UM2&apos;,   &apos;UM2.CODUM = NA.UM2&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM1&apos;,       &apos;UMCOR&apos;, &apos;UMCOR.CODUM1 = I1.UMCORELAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,      &apos;PROD&apos;,  &apos;PROD.CODPART = NAO.CODPRODUCATOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,      &apos;NC&apos;,    &apos;NC.CODCONT = I1.CONTDISCOUNT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;AE1&apos;,   &apos;AE1.CODIES1 = ML.CODAE1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,   &apos;DL1&apos;,   &apos;DL1.CODCOMANDA1 = ML.CODDL1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,   &apos;CC1&apos;,   &apos;CC1.CODCOMANDA1 = ML.CODCC1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,    &apos;DL&apos;,    &apos;DL.CODCOMANDA = ML.CODMDL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,    &apos;AEDEL&apos;, &apos;AEDEL.CODPARTTR = AE.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;,    &apos;COMC&apos;,  &apos;COMC.CODCOMANDA = ML.CODCC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;,   &apos;COMC1&apos;, &apos;COMC1.CODCOMANDA1 = ML.CODCC1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;,    &apos;COMI&apos;,  &apos;COMI.CODCOMANDA = ML.CODCOM&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;,   &apos;COMI1&apos;, &apos;COMI1.CODCOMANDA1 = ML.CODCOM1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1EXT&apos;, &apos;I1EXT&apos;, &apos;I1EXT.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,  &apos;IEXT&apos;,  &apos;IEXT.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARCAUT&apos;,   &apos;PAUT&apos;,  &apos;PAUT.CODNPARCAUT = I1.CODAUTO&apos;);
  IF Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;CUMULEZBCAR&apos;,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;, &apos;BCAR&apos;, &apos;BCAR.CODDOC1 = I1.CODIES1 AND BCAR.TIPDOC = I.TIPDOC&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BCAREXT&apos;, &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  sDenDisc := pkg_categconst.GetValConstanta(&apos;DenDiscount&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) ;
  IF Trim(sDenDisc) IS NULL
  THEN sDenDisc := &apos;Discount&apos;;
  ELSE sDenDisc := REPLACE(sDenDisc,&apos;&apos;&apos;&apos;,&apos;&apos;&apos;&apos;&apos;&apos;);
  END IF;

  IF pListareLiniiDiscPart &lt;&gt; 1 THEN
    sCondDiscP := &apos;
        AND Coalesce(i1.CODCRITERIU,0) = 0&apos;;
  END IF;

  sCondClasa := &apos;&apos;;
  IF vFiltruClasaArt then
    sCondClasa := &apos;
    AND C.CodClaseA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;) &apos;;
  END IF;

  IF vNrDC &gt; 0 THEN
    FOR k IN 1..vNrDC LOOP
      sInsertDC := sInsertDC||&apos;, D&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    sWithDC := sWithDC||&apos;
      DC AS (
        SELECT codobiect&apos;;

    FOR k IN 1..vNrDC/2 LOOP
      sWithDC   := sWithDC   ||&apos;, Max(Decode(idx,&apos;||to_char(k,&apos;fm999&apos;)||&apos;,p)) p&apos;||to_char(k,&apos;fm999&apos;);
      sSelectDC := sSelectDC ||&apos;, i1.cant/dc.p&apos;||to_char(k,&apos;fm999&apos;)||&apos;, i1.pu*dc.p&apos;||to_char(k,&apos;fm999&apos;);
      sNullDC   := sNullDC   ||&apos;, NULL, NULL&apos;;
    END LOOP;

    sWithDC := sWithDC||&apos;
        FROM (
          SELECT codobiect, den_um1, idxobj, p, Dense_Rank() OVER (ORDER BY den_um1, idxobj) idx
          FROM (
            SELECT DISTINCT i1.CODOBIECT, Upper(U1.DEN_UM1) den_um1, u1.paritate p,
              Dense_Rank() OVER (PARTITION BY i1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
            FROM IESIRI I
              INNER JOIN IESIRI1 I1  ON I1.CODIES     = I.CODIES
              INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = I1.CODOBIECT
              INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
            WHERE I.CODIES = &apos;||vCodDoc||&apos;)
        ) GROUP BY codobiect),&apos;;

    sJoinAux := sJoinAux||&apos;
      LEFT JOIN DC ON dc.codobiect = i1.codobiect&apos;;
  END IF;

  IF vTipdoc = 26 THEN
    sJoinSer := &apos;
        INNER JOIN IESLINK ILAE ON ILAE.CODIES1 = I1.CODIES1
        INNER JOIN IESIRI1 AE1  ON AE1.CODIES1  = ILAE.CODLINIEAVIZ
        INNER JOIN LIVR    L    ON L.CODIES     = AE1.CODIES
        INNER JOIN LIVR1   L1   ON L1.CODIES1   = AE1.CODIES1 AND L1.CODLIVR = L.CODLIVR&apos;;
  ELSE
    sJoinSer := &apos;
        INNER JOIN LIVR  L  ON L.CODIES   = I1.CODIES
        INNER JOIN LIVR1 L1 ON L1.CODIES1 = I1.CODIES1 AND L1.CODLIVR = L.CODLIVR&apos;;
  END IF;

  DELETE LIVR1_MAN;
  DELETE LST_DOCIES_IES1;
  DELETE LST_DOCIES_SER;
  DELETE LST_DOCIES_NS;
  DELETE LST_DOCIES_NSIN;
  DELETE LST_DOCIES_ML;

  sInsMAN :=
  &apos;INSERT INTO LIVR1_MAN(
    CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODDVI1, CODNIRSTOC, CANT, CODNIRSER, PMP, UMSEC,
    CANTUM1, CANTUM2, RESTIESVAL, CANTREZERVAT, CODCERTIF, CODPRODCOMP,
    PMPVALUTA, PMPDOC, PMPVALUTADOC, CONTINTERMED, CODPROIECT)
  SELECT
    L1.CODLIVR1, L1.CODLIVR, I1.CODIES1, L1.CODINTR1, L1.CODDVI1, L1.CODNIRSTOC, L1.CANT, L1.CODNIRSER, L1.PMP, L1.UMSEC,
    L1.CANTUM1, L1.CANTUM2, L1.RESTIESVAL, L1.CANTREZERVAT, L1.CODCERTIF, L1.CODPRODCOMP,
    L1.PMPVALUTA, L1.PMPDOC, L1.PMPVALUTADOC, L1.CONTINTERMED, L1.CODPROIECT
  FROM IESIRI1 I1&apos;||sJoinSer||&apos;
  WHERE I1.CODIES = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);

  sInsMAN :=
  &apos;INSERT INTO LST_DOCIES_IES1(CODIES, CODOBIECT, UMSEC, CODIES1, AL, CANT, CANTCORELAT, PRETORIG, PU, PIES, TVA, PUCORELAT, VORIG, VU, VIESL, MINPDISC, MAXPDISC, MINADDIM, MAXADDIM)&apos;;

  -- STEF AL -&gt; CAST(I.AN*12+I.LUNA AS NUMBER(5)) pentru ca am gasit cazuri cand crapa pe oracle XE

  IF pListareDocAgregat = &apos;1&apos; THEN -- ARTICOL/UMSEC
    sGroupBy1 := &apos;I1.CODOBIECT, I1.UMSEC&apos;;
    sSelect1  := &apos;CODOBIECT, UMSEC&apos;;
    sGroupBy2 := &apos;CODOBIECT, UMSEC&apos;;
    sJoinL1M  := &apos;
          INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1&apos;;
    sJoinAux := sJoinAux||&apos;
    LEFT JOIN lst_docies_ser ms ON ms.codobiect = i1.codobiect AND ms.umsec = i1.umsec
    LEFT JOIN lst_docies_ns mns ON mns.codobiect = i1.codobiect AND mns.umsec = i1.umsec&apos;;

    sInsMAN := sInsMAN||&apos;
    SELECT
      I1.CODIES, I1.CODOBIECT, I1.UMSEC, I1.CODIES1, CAST(I.AN*12+I.LUNA AS NUMBER(5)),
      I1.CANT, I1.CANTCORELAT, I1.PRETORIG, I1.PU, I1.PRETORIG*COALESCE(I1.COEFDISCMAJ,1) PIES, I1.TVA, I1.PUCORELAT,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END VU,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
      Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE i1.codies = &apos;||vCodDoc||sCondDiscP||&apos;
      AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos;
    UNION ALL
    SELECT
      I1.CODIES, I1.CODOBIECT, I1.UMSEC, MIN(I1.CODIES1) CODIES1, CAST(MIN(I.AN*12+I.LUNA) AS NUMBER(5)),
      SUM(I1.CANT) CANT, SUM(I1.CANTCORELAT) CANTCORELAT,
      SUM(I1.CANT * I1.PRETORIG)/SUM(I1.CANT) PRETORIG, SUM(I1.CANT * I1.PU)/SUM(I1.CANT) PU,
      SUM(I1.CANT * I1.PRETORIG*COALESCE(I1.COEFDISCMAJ,1))/SUM(I1.CANT) PIES,
      SUM(I1.TVA) TVA, SUM(I1.CANTCORELAT * I1.PUCORELAT)/SUM(I1.CANT) PUCORELAT,
      SUM(I1.CANT*I1.PRETORIG) VORIG,
      SUM(I1.CANT*I1.PU) VU,
      SUM(I1.CANT*I1.PU*(1+Coalesce(I1.PROCDISC/100,0))) VIESL,
      Min(Coalesce(I1.PROCDISC,0)) MINPDISC, Max(Coalesce(I1.PROCDISC,0)) MAXPDISC, Min(Coalesce(I1.ADDIM,0)) MINADDIM, Max(Coalesce(I1.ADDIM,0)) MAXADDIM
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE i1.codies = &apos;||vCodDoc||sCondDiscP||&apos;
      AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
    GROUP BY I1.CODIES, I1.CODOBIECT, I1.UMSEC, SIGN(I1.CANT)&apos;;
  ELSIF pListareDocAgregat = &apos;3&apos; THEN -- ARTICOL/UMSEC/PU
    sGroupBy1 := &apos;I1.CODOBIECT, I1.UMSEC, I1.PU&apos;;
    sSelect1  := &apos;CODOBIECT, UMSEC, PU&apos;;
    sGroupBy2 := &apos;CODOBIECT, UMSEC, PU&apos;;
    sJoinL1M  := &apos;
          INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1&apos;;
    sJoinAux := sJoinAux||&apos;
    LEFT JOIN lst_docies_ser ms ON ms.codobiect  = i1.codobiect AND ms.umsec  = i1.umsec AND ms.pu  = i1.pu
    LEFT JOIN lst_docies_ns mns ON mns.codobiect = i1.codobiect AND mns.umsec = i1.umsec AND mns.pu = i1.pu&apos;;

    sInsMAN := sInsMAN||&apos;
    SELECT
      I1.CODIES, I1.CODOBIECT, I1.UMSEC, I1.CODIES1, CAST(I.AN*12+I.LUNA AS NUMBER(5)),
      I1.CANT, I1.CANTCORELAT, I1.PRETORIG, I1.PU, I1.PRETORIG*COALESCE(I1.COEFDISCMAJ,1) PIES, I1.TVA, I1.PUCORELAT,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END VU,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
      Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE i1.codies = &apos;||vCodDoc||sCondDiscP||&apos;
      AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos;
    UNION ALL
    SELECT
      I1.CODIES, I1.CODOBIECT, I1.UMSEC, MIN(I1.CODIES1) CODIES1, CAST(MIN(I.AN*12+I.LUNA) AS NUMBER(5)),
      SUM(I1.CANT) CANT, SUM(I1.CANTCORELAT) CANTCORELAT,
      SUM(I1.CANT * I1.PRETORIG)/SUM(I1.CANT) PRETORIG, I1.PU,
      SUM(I1.CANT * I1.PRETORIG*COALESCE(I1.COEFDISCMAJ,1))/SUM(I1.CANT) PIES,
      SUM(I1.TVA) TVA, SUM(I1.CANTCORELAT * I1.PUCORELAT)/SUM(I1.CANT) PUCORELAT,
      SUM(I1.CANT*I1.PRETORIG) VORIG,
      SUM(I1.CANT*I1.PU) VU,
      SUM(I1.CANT*I1.PU*(1+Coalesce(I1.PROCDISC/100,0))) VIESL,
      Min(Coalesce(I1.PROCDISC,0)) MINPDISC, Max(Coalesce(I1.PROCDISC,0)) MAXPDISC, Min(Coalesce(I1.ADDIM,0)) MINADDIM, Max(Coalesce(I1.ADDIM,0)) MAXADDIM
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE i1.codies = &apos;||vCodDoc||sCondDiscP||&apos;
      AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
    GROUP BY I1.CODIES, I1.CODOBIECT, I1.UMSEC, I1.PU, SIGN(I1.CANT)&apos;;
  ELSE
    sGroupBY1 := &apos;L1.CODIES1&apos;;
    sSelect1  := &apos;CODIES1&apos;;
    sGroupBY2 := &apos;CODIES1&apos;;
    sJoinAux := sJoinAux||&apos;
    LEFT JOIN lst_docies_ser ms ON ms.codies1 = i1.codies1
    LEFT JOIN lst_docies_ns mns ON mns.codies1 = i1.codies1&apos;;
    sInsMAN := sInsMAN||&apos;
    SELECT
      I1.CODIES, I1.CODOBIECT, I1.UMSEC, I1.CODIES1, CAST(I.AN*12+I.LUNA AS NUMBER(5)),
      I1.CANT, I1.CANTCORELAT,
      I1.PRETORIG, I1.PU,
      I1.PRETORIG*COALESCE(I1.COEFDISCMAJ,1) PIES,
      I1.TVA, I1.PUCORELAT,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END VU,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
      Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE i.codies = &apos;||vCodDoc||sCondDiscP;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);
  SELECT TipTva INTO vTipTva FROM iesiri WHERE codies = vCodDoc;
  IF vTipTva IN (7,8) THEN
    UPDATE LST_DOCIES_IES1
    SET PRETORIG = PRETORIG * (1+TVA/VU),
        PU       = PU       * (1+TVA/VU),
        PIES     = PIES     * (1+TVA/VU),
        VORIG    = VORIG    * (1+TVA/VU),
        VIESL    = VIESL    * (1+TVA/VU)
    WHERE TVA &lt;&gt; 0 AND VU &lt;&gt; 0;

    UPDATE LST_DOCIES_IES1
    SET VU  = VU+TVA,
        TVA = 0;
  END IF;

  UPDATE LST_DOCIES_IES1 L SET CODOBIECT1 = (SELECT O1.CodObiect1 FROM NartObj1 O1 WHERE O1.CodObiect = L.CodoBiect AND L.AL BETWEEN O1.ALStart and O1.ALStop);

  UPDATE LST_DOCIES_IES1 L
  SET (  CODOBIECTORIG, PARITATE, DEN_UMSEC, DEN_UM1, DEN_UM2, DEN_UMCOR, ART_ASOCIAT, PRODUCATOR) =
      (SELECT
         i1.codobiectorig, um.paritate, CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN &apos;%&apos; ELSE um.den_um1 END, um1.den_um, um2.den_um, umcor.den_um1, oas.denumire, prod.den_part
       FROM iesiri1 i1
          LEFT JOIN nartobj nao   ON nao.codobiect = i1.codobiect
          LEFT JOIN nartobj oas   ON oas.codobiect = i1.codobiectorig
          LEFT JOIN nart    na    ON na.codarticol = nao.codarticol
          LEFT JOIN num1    um    ON um.codum1 = i1.umsec
          LEFT JOIN num     um1   ON um1.codum = na.um1
          LEFT JOIN num     um2   ON um2.codum = na.um2
          LEFT JOIN num1    umcor ON i1.umcorelat = umcor.codum1
          LEFT JOIN npart   prod  ON prod.codpart = nao.codproducator
       WHERE i1.codies1 = l.codies1
      );

  sInsMAN :=
  &apos;INSERT INTO LST_DOCIES_SER(&apos;||sGroupBy2||&apos;, serii, ser, sertg, sercant, serobs, serii_tg)
  SELECT
    &apos;||sGroupBy2||&apos;,
    vc2_nt_to_vc3200(CAST(COLLECT(serie                 ORDER BY serie     ) AS vc2_nt)) serii,
    vc2_nt_to_vc3200(CAST(COLLECT(ser                   ORDER BY ser       ) AS vc2_nt)) ser,
    vc2_nt_to_vc3200(CAST(COLLECT(sertg                 ORDER BY ser, sertg) AS vc2_nt)) sertg,
    vc2_nt_to_vc3200(CAST(COLLECT(sercant               ORDER BY ser, sertg) AS vc2_nt)) sercant,
    vc2_nt_to_vc3200(CAST(COLLECT(serobs                ORDER BY ser, sertg) AS vc2_nt)) serobs,
    vc2_nt_to_vc3200(CAST(COLLECT(serie||&apos;&apos; - &apos;&apos;||sertg ORDER BY ser, sertg) AS vc2_nt)) serii_tg
  FROM (
    SELECT &apos;||sGroupBy1||&apos;,
      NSERII.SERIE||CASE WHEN SUM(L1.CANT) &lt;&gt; 1 THEN &apos;&apos;(&apos;&apos;||SUM(L1.CANT)||&apos;&apos;)&apos;&apos; END SERIE, NSERII.SERIE SER,
      TO_CHAR(SUM(L1.CANT)) SERCANT, TO_CHAR(COALESCE(nirser.tg, ns.tg)) SERTG, NIRSER.OBS  SEROBS
    FROM LIVR1_MAN L1&apos;||
      sJoinL1M||&apos;
      INNER JOIN NIRSER     ON NIRSER.CODNIRSER = L1.CODNIRSER
      INNER JOIN NSERII     ON NSERII.CODSERIE  = NIRSER.CODSERIE
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC    = L1.CODNIRSTOC
    GROUP BY &apos;||sGroupBy1||&apos;, NSERII.SERIE, COALESCE(nirser.tg, ns.tg), NIRSER.OBS
  )
  GROUP BY &apos;||sGroupBy2;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);

  sInsMAN :=
  &apos;INSERT INTO LST_DOCIES_NSIN(codnirstoc, codintr1, coddvi1)
  SELECT ns1.codnirstoc, ns.codintr1, ns.coddvi1
  FROM nirstoc1 ns1 INNER JOIN nirstoc ns ON ns.codnirstoc = ns1.codnirstocorig
  WHERE ns1.codnirstocorig IN (SELECT DISTINCT CODNIRSTOC FROM LIVR1_MAN)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);

  sInsMAN :=
  &apos;INSERT INTO LST_DOCIES_NS(&apos;||sSelect1||&apos;, pumaximal, cantum1, cantum2, tg, nrcertif, dim, d1, eudr_rn, eudr_vn)
  SELECT
    &apos;||sGroupBy1||&apos;, MAX(Coalesce(ns.pumaximal,0)) pumaximal,
    sum(Coalesce(l1.cantum1,0)) cantum1, sum(Coalesce(l1.cantum2,0)) cantum2,
    vc2_nt_to_string(CAST(COLLECT(DISTINCT to_char(coalesce(nse.tg,ns.tg))) AS vc2_nt)) tg,
    vc2_nt_to_string(CAST(COLLECT(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
    vc2_nt_to_string(CAST(COLLECT(DISTINCT CAST(
      decode(
        na.relatieum1,
         1,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; / &apos;&apos;||NS.D1,
         2,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; / (&apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos;)&apos;&apos;,
         3,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; / (&apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos; x &apos;&apos;||NS.D3||&apos;&apos;)&apos;&apos;,
         4,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; x &apos;&apos;||NS.D1,
         5,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; x &apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2,
         6,umspec.den_um||&apos;&apos; = &apos;&apos;||num.den_um   ||&apos;&apos; x &apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos; x &apos;&apos;||NS.D3,
         7,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||NS.D1,
         8,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2,
         9,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; x &apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos; x &apos;&apos;||NS.D3,
        10,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / &apos;&apos;||NS.D1,
        11,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / (&apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos;)&apos;&apos;,
        12,num.den_um   ||&apos;&apos; = &apos;&apos;||umspec.den_um||&apos;&apos; / (&apos;&apos;||NS.D1||&apos;&apos; x &apos;&apos;||NS.D2||&apos;&apos; x &apos;&apos;||NS.D3||&apos;&apos;)&apos;&apos;
      ) AS VARCHAR2(300)) ) AS vc2_nt) ) dim,
    vc2_nt_to_string(CAST(COLLECT(DISTINCT CAST(CASE WHEN na.relatieum1 BETWEEN 1 AND 12 THEN To_Char(NS.D1) ELSE &apos;&apos;&apos;&apos; END AS VARCHAR2(300)) ) AS vc2_nt) ) d1,
    vc2_nt_to_vc3200_dist(CAST(COLLECT(ns.eudr_rn ORDER BY ns.eudr_rn) AS vc2_nt)) eudr_rn,
    vc2_nt_to_vc3200_dist(CAST(COLLECT(ns.eudr_vn ORDER BY ns.eudr_vn) AS vc2_nt)) eudr_vn
  FROM LIVR1_MAN L1
    INNER JOIN IESIRI1         I1     ON I1.CODIES1      = L1.CODIES1
    LEFT  JOIN NIRSTOC         NS     ON NS.CODNIRSTOC   = L1.CODNIRSTOC
    LEFT  JOIN NIRSER          NSE    ON NSE.CODNIRSER   = L1.CODNIRSER
    LEFT  JOIN NARTOBJ         NO     ON NO.CODOBIECT    = I1.CODOBIECT
    LEFT  JOIN NART            NA     ON NA.CODARTICOL   = NO.CODARTICOL
    LEFT  JOIN NUM                    ON NUM.CODUM       = NA.UM
    LEFT  JOIN NUM             UMSPEC ON UMSPEC.CODUM    = NA.UM1
    LEFT  JOIN LST_DOCIES_NSIN NSIN   ON NSIN.CODNIRSTOC = NS.CODNIRSTOC
    LEFT  JOIN DVI1                   ON DVI1.CODDVI1    = NSIN.CODDVI1
    LEFT  JOIN INTRARI1        INT1   ON INT1.CODINTR1   = Coalesce(DVI1.CODINTR1, NSIN.CODINTR1)
  GROUP BY &apos;||sGroupBy1;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);

  sInsMAN :=
  &apos;INSERT INTO LST_DOCIES_ML(codies1, codae1, codae, codcom1, coddl1, coddl, codcc1, codcc, codoferta1)
  SELECT
    i1.codies1 codies1, ae1.codies1 codae1, ae1.codies codae, com1.codcomanda1 codcom1, dl1.codcomanda1 coddl1, dl1.codcomanda coddl, cc1.codcomanda1 codcc1, cc1.codcomanda codcc,
    COALESCE(cc1.codoferta1,CASE WHEN cc1.tipsursa = 50 THEN cc1.codsursa ELSE NULL END,ae1.codoferta1,i1.codoferta1) codoferta1
  FROM iesiri i
    LEFT JOIN iesiri1     i1   ON i1.codies   = i.codies
    LEFT JOIN ieslink     il1  ON il1.codies1 = i1.codies1
    LEFT JOIN ieslink     il2  ON il2.codies1 = il1.codlinieaviz
    LEFT JOIN iesiri1     ae1  ON ae1.codies1 = il1.codlinieaviz
    LEFT JOIN iesiri      ae   ON ae.codies   = ae1.codies
    LEFT JOIN comanda1    com1 ON com1.codcomanda1 = COALESCE(il1.codliniecomanda, il2.codliniecomanda)
    LEFT JOIN comanda     com  ON com.codcomanda  = com1.codcomanda
    LEFT JOIN cmdlink     cl   ON cl.codcomanda1  = COALESCE(il1.codliniecomanda, il2.codliniecomanda)
    LEFT JOIN cmdlivrlink cll  ON cll.codcomanda1 = COALESCE(cl.codliniecomanda,il1.codliniecomanda, il2.codliniecomanda)
    LEFT JOIN comanda1    dl1  ON dl1.codcomanda1 = cll.codcomanda1
    LEFT JOIN comanda1    cc1  ON cc1.codcomanda1 = CASE WHEN cll.codliniecomanda IS NOT NULL THEN cll.codliniecomanda WHEN i.tipdoc IN (23,24) THEN cl.codliniecomanda ELSE Coalesce(il1.codliniecomanda, il2.codliniecomanda) END
    LEFT JOIN comanda     cc   ON cc.codcomanda   = cc1.codcomanda
  WHERE i.codies = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsman, aListID, aListVer);

  EXECUTE IMMEDIATE &apos;DELETE &apos;||TMPNAME; -- curatat pentru listare BULK

  BEGIN
    SELECT i.partener, coalesce(p.codclasa,0) INTO aPart, aClasa
    FROM iesiri i LEFT JOIN npart p on p.codpart = i.partener
    WHERE i.codies = vCodDoc;
  EXCEPTION WHEN OTHERS THEN aPart := 0; aClasa := 0;
  END;
  DELETE FROM tmp_nartcli;
  INSERT INTO tmp_nartcli(
    CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT, IMPLICIT,
    CODLACLIENT, CODCLASEP, CODGAMA, CODINTERN, OBS, OBS2, UMSECIMPDOC, DURATATR, ZILESTOC, GLN, IDSPECIFIC )
  SELECT
    CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT, IMPLICIT,
    CODLACLIENT, CODCLASEP, CODGAMA, CODINTERN, OBS, OBS2, UMSECIMPDOC, DURATATR, ZILESTOC, GLN, IDSPECIFIC
  FROM nartcli
  WHERE codpart = aPart;
  IF aClasa &gt; 0 THEN
    INSERT INTO tmp_nartcli(
      CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT, IMPLICIT,
      CODLACLIENT, CODCLASEP, CODGAMA, CODINTERN, OBS, OBS2, UMSECIMPDOC, DURATATR, ZILESTOC, GLN, IDSPECIFIC )
    SELECT
      CODARTCLI, CODOBIECT, CODPART, DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, TIPCODAFISAT, UMCORELAT, IMPLICIT,
      CODLACLIENT, CODCLASEP, CODGAMA, CODINTERN, OBS, OBS2, UMSECIMPDOC, DURATATR, ZILESTOC, GLN, IDSPECIFIC
    FROM nartcli c
    WHERE c.codclasep = aClasa AND NOT EXISTS (SELECT t.codobiect FROM tmp_nartcli t WHERE t.codobiect = c.codobiect);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      ART, ART_ASOCIAT,
      UM,
      OBSART, CANT, CodIntern,CodExtern,Producator,Masa,Volum,CodVamal,
      PRET, PU, PD,
      PRET_LEI, PU_LEI, PD_LEI,
      VAL, VALADAOS, VALTVA,
      VAL_LEI, VALADAOS_LEI, VALTVA_LEI,
      PROCADAOS,PROCTVA,PROCTVAART,PROCDISC,
      PretMaximal,
      GARIES, GARART, DATAEXP,
      DenClasaA,
      SimbClasaA,
      UM1, UM2, CANT1, CANT2, Serii, SerieData, Ser, SerTg, SerCant, SerObs, TipSerie,
      Aviz, Comanda, ComClient, NRCERTIF, DiscAfis,
      ARTCli,
      CodExtCli, CodListat,DenClaseAS, IDX, NrUnic, UMCor, CantUMCor, PretUMCor, Dimensiuni, Dim1,
      CANTREZ,
      CURSAVIZ,
      NRCOLETE,
      DENATRIB,
      TIPLIVRARE,
      INFODOCRETUR,
      CantUMPrinc, CutiePar, CutieExt, CutieGSp, PaletPar, EUDR_rn, EUDR_vn&apos;;

  -- liniile de pe iesiri
        --de o fi cazul am pregatit si d2, d3
        --vc2_nt_to_string(CAST(COLLECT(DISTINCT CAST(CASE WHEN na.relatieum1 IN (2,3,5,6,8,9,11,12) THEN To_Char(NS.D1) ELSE &apos;&apos;&apos;&apos; END AS VARCHAR2(200)) ) AS vc2_nt) ) d2,
        --vc2_nt_to_string(CAST(COLLECT(DISTINCT CAST(CASE WHEN na.relatieum1 IN (3,6,9,12) THEN To_Char(NS.D1) ELSE &apos;&apos;&apos;&apos; END AS VARCHAR2(200)) ) AS vc2_nt) ) d3

  sSelect := &apos;)
  WITH &apos;||
    sWithDC||&apos;
    UMCP AS (
      SELECT codies1, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,upar)) cutiepar, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,aext)) cutieext, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;&apos;PALET&apos;&apos;,upar)) paletpar
      FROM (
        SELECT
          I1.CODIES1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
          Dense_Rank() OVER (PARTITION BY i1.codies1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = i1.umsec THEN 0 ELSE u1.paritate END) idxobj
        FROM IESIRI I
          INNER JOIN IESIRI1 I1  ON I1.CODIES     = I.CODIES
          INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = I1.CODOBIECT
          INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
        WHERE I.CODIES = &apos;||vCodDoc||&apos; AND Upper(U1.codextern) IN (&apos;&apos;CUTIE&apos;&apos;,&apos;&apos;PALET&apos;&apos;)
      )
      WHERE idxobj = 1
      GROUP BY codies1)
  SELECT
    CASE
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos; client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos;: &apos;&apos; || cd.DENCRITERIU
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare: &apos;&apos; || cd.DENCRITERIU
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe grupul de articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de grup)&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe toate articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de total)&apos;&apos;
      ELSE nao.denumire
    END ART,
    mi1.ART_ASOCIAT,
    mi1.DEN_UMSEC,
    i1.obs OBSART, mi1.cant/Coalesce(mi1.paritate,1) CANT, nao.codintern, nao.codextern, mi1.Producator, nao.masa, nao.volum, nao.codvamal,
    mi1.pretorig*mi1.paritate Pret, mi1.pu*mi1.paritate PU, mi1.pies*mi1.paritate PD,
    mi1.pretorig*mi1.paritate*Coalesce(i.curs,1) Pret_LEI, mi1.pu*mi1.paritate*Coalesce(i.curs,1) PU_LEI, mi1.pies*mi1.paritate*Coalesce(i.curs,1) PD_LEI,
    CASE WHEN I.ROTEFACT = 1 THEN ROUND(mi1.vu,2) ELSE mi1.vu end VAL, mi1.pu - mi1.pretorig VALADAOS, mi1.tva VALTVA,
    CASE WHEN I.ROTEFACT = 1 THEN ROUND(mi1.vu * Coalesce(i.curs,1),2) ELSE mi1.vu * Coalesce(i.curs,1) end VAL_LEI, (mi1.vu - mi1.vorig) * Coalesce(i.curs,1) VALADAOS_LEI, mi1.tva * Coalesce(i.curs,1) VALTVA_LEI,
    CASE
      WHEN mi1.minaddim = mi1.maxaddim THEN mi1.minaddim
      ELSE DECODE(mi1.vorig,0,0,(mi1.vu - mi1.vorig)*100/mi1.vorig)
    END PROCADAOS,
    ROUND(CASE
      WHEN i.tipdoc = 23 THEN tmp_tva.procent
      WHEN mi1.vu = 0 THEN tmp_tva.procent
      WHEN Coalesce(mi1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND mi1.vu = Coalesce(mi1.tva,0) THEN 100
      WHEN i.tipdoc IN (16,21) THEN Coalesce(mi1.tva,0) / (mi1.vu-Coalesce(mi1.tva,0)) * 100
      ELSE Coalesce(mi1.tva,0) / mi1.vu * 100
    END,2) PROCTVA,
    ROUND(CASE
      WHEN tmp_tva.procent IS NOT NULL THEN tmp_tva.procent
      WHEN Coalesce(mi1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND mi1.vu = Coalesce(mi1.tva,0) THEN 100
      WHEN i.tipdoc IN (16,21) THEN Coalesce(mi1.tva,0) / (mi1.vu-Coalesce(mi1.tva,0)) * 100
      ELSE Coalesce(mi1.tva,0) / mi1.vu * 100
    END,2) PROCTVAART,
    CASE
      WHEN mi1.minpdisc= mi1.maxpdisc THEN mi1.minpdisc
      ELSE DECODE(mi1.vu,0,0,(mi1.viesl - mi1.vu)*100/mi1.vu)
    END PROCDISC,
    CASE
      WHEN i.tipdoc = 23 AND Coalesce(nao1.tippretmax,0) = 3 THEN decode (Coalesce(mns.pumaximal,0),-1,0,Coalesce(mns.pumaximal,0))
      WHEN i.tipdoc = 23 AND Coalesce(nao1.tippretmax,0) = 6 THEN decode (Coalesce(nao1.pretmaximal,0),-1,0,Coalesce(nao1.pretmaximal,0))
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2) THEN decode (Coalesce(i1.pumaximal, mns.pumaximal),-1,0,Coalesce(i1.pumaximal, mns.pumaximal) )
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5) THEN decode (Coalesce(nao1.pretmaximal,0),-1,0,Coalesce(nao1.pretmaximal,0))
      ELSE 0
    END PretMaximal,
    i1.garantie GARIES, nao.lunigarantie GARART, Coalesce(mns.tg,&apos;&apos;-&apos;&apos;) DATAEXP,
    CASE
      WHEN i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos;
      WHEN i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT  &gt; 0 THEN &apos;&apos; Majorare (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos;
      ELSE c.den_clasea
    END DenClasaA,
    CASE
      WHEN i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;= 0 THEN &apos;&apos; D (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos;
      WHEN i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT  &gt; 0 THEN &apos;&apos; M (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos;
      ELSE c.simbol
    END SimbClasaA,
    mi1.den_um1, mi1.den_um2, mns.cantum1 CANT1, mns.cantum2 CANT2, ms.serii, ms.serii_tg, ms.ser, ms.sertg, ms.sercant, ms.serobs, decode(na.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) TipSerie,
    CASE WHEN ae.codies IS NULL THEN NULL ELSE ae.prefixdoc||&apos;&apos; &apos;&apos;||ae.nrdoc||&apos;&apos;/&apos;&apos;||ae.datadoc END Aviz,
    CASE WHEN com.codcomanda IS NULL THEN NULL ELSE com.prefixdoc||&apos;&apos; &apos;&apos;||com.nrdoc||&apos;&apos;/&apos;&apos;||com.datadoc END Comanda,
    CASE WHEN cc.codcomanda  IS NULL THEN NULL ELSE cc.prefixdoc ||&apos;&apos; &apos;&apos;||cc.nrdoc ||&apos;&apos;/&apos;&apos;||cc.datadoc  END ComClient,
    mns.nrcertif, case when Coalesce(i1.procdisc,0) = 0 then &apos;&apos; &apos;&apos; else to_char(i1.procdisc)||&apos;&apos;%&apos;&apos; end DiscAfis,
    CASE
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos; client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos;: &apos;&apos; || cd.DENCRITERIU
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare: &apos;&apos; || cd.DENCRITERIU
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe grupul de articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de grup)&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe toate articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de total)&apos;&apos;
      ELSE COALESCE(ac.denumire, ntrad.denumiretrad,nao.denumire)
    END ARTCLI,
    Coalesce(ac.codextern,nao.codextern) CodExtCli,
    Coalesce(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern) CodListat,
    cs.den_claseas DenClaseAS, i1.indexlocal IDX, rownum NrUnic, mi1.den_umcor, mi1.cantcorelat CantUMCor, mi1.pucorelat PretUMCor, mns.dim Dimensiuni, mns.d1 Dim1,
    Coalesce((SELECT SUM(rest) FROM rezervats r WHERE r.codcomanda1 = com1.codcomanda1),0) CANTREZ,
    CASE WHEN ae.codies IS NULL THEN NULL ELSE DECODE(ae.curs,NULL,1,0,1,ae.curs) END CURSAVIZ,
    ( SELECT COUNT(1) FROM nartobjcolet naoc WHERE naoc.codobiect = nao.codobiect) NRCOLETE,
    ( SELECT vc2_nt_to_string(CAST(COLLECT(a.denumire order by aa.indexlocal) AS vc2_nt))
      FROM nartatr aa INNER JOIN natrib a ON a.codatribut = aa.codatribut
      WHERE aa.codarticol = nao.codarticol
    ) DENATRIB,
    DECODE(i1.tiplivrare,1,&apos;&apos;Ridicata&apos;&apos;,2,&apos;&apos;Custodie&apos;&apos;,3,&apos;&apos;Nesosita&apos;&apos;,4,&apos;&apos;De ridicat&apos;&apos;,5,&apos;&apos;Custodie curier/terti&apos;&apos;) TIPLIVRARE,
    CASE
      WHEN Coalesce(I1.CodObligStorno, 0) &gt; 0 THEN (
        SELECT XI.PREFIXDOC||XI.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(XI.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)
        FROM stingere xs
          INNER JOIN obligpif xo ON xo.codobligpif = xs.CODSTINSPIF
          INNER JOIN general  xg ON xg.codgeneral  = xo.codgeneral
          INNER JOIN iesiri   xi ON xi.codies      = xg.coddoc AND xi.tipdoc = xg.tipdoc
        WHERE xs.CODSTINGATORPIF = I1.CodObligStorno
      )
      WHEN Coalesce(I1.CODLINIEDOCIMP, 0 ) = 0 THEN NULL
      WHEN Coalesce(I1.TIPDOCIMP, 0) = 0 THEN NULL
      WHEN I1.TIPDOCIMP IN (19, 20, 26)    THEN (
        SELECT XI.PREFIXDOC||XI.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(XI.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)
        FROM IESIRI1 XI1 INNER JOIN IESIRI XI ON XI.CODIES  = XI1.CODIES
        WHERE XI1.CODIES1  = I1.CODLINIEDOCIMP
      )
      WHEN I1.TIPDOCIMP IN (1, 2, 3, 4, 5) THEN (
        SELECT XI.PREFIXDOC||XI.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(XI.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)
        FROM INTRARI1 XI1 INNER JOIN INTRARI XI ON XI.CODINTR = XI1.CODINTR
        WHERE XI1.CODINTR1 = i1.CODLINIEDOCIMP
      )
      ELSE NULL
    END INFODOCRETUR,
    mi1.cant CantUMPrinc, UMCP.CutiePar, UMCP.CutieExt, UMCP.CutieGSp, UMCP.PaletPar, mns.EUDR_rn, mns.EUDR_vn&apos;||sSelectDC||gUserAlias||&apos;
  FROM lst_docies_ies1 mi1
    LEFT JOIN iesiri1       i1      ON i1.codies1       = mi1.codies1
    LEFT JOIN iesiri        i       ON i.codies         = i1.codies
    LEFT JOIN nartobj       nao     ON nao.codobiect    = i1.codobiect
    LEFT JOIN nart          na      ON na.codarticol    = nao.codarticol
    LEFT JOIN nclasea       c       ON c.codclasea      = na.clasa
    LEFT JOIN nclaseas      cs      ON cs.codclaseas    = na.clasastatist
    LEFT JOIN npart         p       ON p.codpart        = i.partener
    LEFT JOIN lst_docies_ml ml      ON ml.codies1       = mi1.codies1
    LEFT JOIN iesiri        ae      ON ae.codies        = ml.codae
    LEFT JOIN comanda1      com1    ON com1.codcomanda1 = ml.codcom1
    LEFT JOIN comanda       com     ON com.codcomanda   = com1.codcomanda
    LEFT JOIN comanda       cc      ON cc.codcomanda    = ml.codcc
    LEFT JOIN oferta1       o1      ON o1.codoferta1    = ml.codoferta1
    LEFT JOIN tmp_nartcli   ac      ON ac.codobiect     = i1.codobiect
    LEFT JOIN nechiv        e       ON e.codobiect      = i1.codobiect
    LEFT JOIN grechiv       gre     ON gre.codgrechiv   = e.codgrupa
    LEFT JOIN nartobj1      nao1    ON nao1.codobiect1  = mi1.CODOBIECT1
    LEFT JOIN criteriidisc  cd      ON cd.codcriteriu   = i1.codcriteriu
    LEFT JOIN nagenda       nag     ON nag.codagenda    = i.codlocatie
    LEFT JOIN nlocalit      nloc    ON nag.codlocalit   = nloc.codlocalit
    LEFT JOIN ntari                 ON ntari.codtara    = nloc.codtara
    LEFT JOIN nartobjtrad   ntrad   ON ntrad.codlimba   = ntari.codlimba and ntrad.codobiect = nao.codobiect
    LEFT JOIN NART1         TMP_A   ON TMP_A.CODARTICOL = NA.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
    LEFT JOIN NTVA1         TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA  AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    LEFT JOIN UMCP                  ON UMCP.CODIES1     = mi1.codies1 &apos;||
    sJoinAux||
    gSuplJoins||&apos;
  WHERE 1=1 &apos;||
    sCondClasa||&apos;
  ORDER BY i1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sinsertdc||guserfields||sselect, aListID, aListVer);

  IF ConstPAPL =1 THEN -- DA
    -- adaos/diminuare pe linie
    sSelect := &apos;)
    SELECT
      CASE WHEN i1.addim &gt; 0 THEN &apos;&apos; Adaos&apos;&apos; ELSE &apos;&apos; Diminuare&apos;&apos; END ART, nao.denumire ART_ASOCIAT,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.addim CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      i1.cant*i1.pretorig/100 PRET, 0 PU, 0 PD,
      i1.cant*i1.pretorig/100*Coalesce(i.curs,1) PRET_LEI, 0 PU_LEI, 0 PD_LEI,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(i1.cant*(i1.pu-i1.pretorig),2) ELSE i1.cant*(i1.pu-i1.pretorig) end VAL, 0 VALADAOS,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig),2) ELSE Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig) end VALTVA,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1),2) ELSE i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1) end  VAL_LEI, i1.cant*(i1.pu-i1.pretorig) * Coalesce(i.curs,1) VALADAOS_LEI, Decode(i1.pretorig,0,0,i1.tva*i1.pu*Coalesce(i.curs,1)/i1.pretorig) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, Coalesce(tmp_tva.procent,0) PROCTVAART, i1.PROCDISC, NULL PretMaximal,
      NULL GARIES, NULL GARART, NULL DATAEXP, &apos;&apos; &apos;&apos; DenClasaA, &apos;&apos; &apos;&apos; SimbClasaA, &apos;&apos; &apos;&apos; UM1, &apos;&apos; &apos;&apos; UM2,
      NULL CANT1, NULL CANT2, NULL Serii, NULL SerieData, NULL Ser, NULL SerTg, NULL SerCant, NULL SerObs, NULL TipSerie,
      NULL Aviz, NULL Comanda, NULL ComClient, NULL NRCERTIF, NULL DiscAfis,
      CASE WHEN i1.addim &gt; 0 THEN &apos;&apos; Adaos&apos;&apos; ELSE &apos;&apos; Diminuare&apos;&apos; END ARTCli, NULL CodExtCli, NULL CodListat,
      NULL DenClaseAS, i1.indexlocal + 0.1 IDX, 999999 NrUnic, NULL UMCor, NULL CantUMCor, NULL PretUMCor, NULL Dimensiuni, NULL Dim1, NULL CANTREZ, NULL CURSAVIZ, 0 NRCOLETE, NULL DENATRIB, NULL TIPLIVRARE, NULL INFODOCRETUR,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar, null EUDR_rn, null EUDR_vn
    FROM iesiri i
      INNER JOIN iesiri1 i1      ON i1.codies        = i.codies
      INNER JOIN nmonede nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1   TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1   TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codies = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.addim,0) &lt;&gt; 0&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  ELSIF ConstPAPL =3 THEN -- Adaos/diminuare pe grupul de articole

    sSelect := &apos;)
    SELECT
      CASE WHEN i1.addim &gt; 0 THEN &apos;&apos; Adaos&apos;&apos; ELSE &apos;&apos; Diminuare&apos;&apos; END||&apos;&apos; pe grupul de articole&apos;&apos; ART, NULL ART_ASOCIAT,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.addim CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      Sum(i1.cant*i1.pretorig/100) PRET, 0 PU, 0 PD,
      Sum(i1.cant*i1.pretorig/100*Coalesce(i.curs,1)) PRET_LEI, 0 PU_LEI, 0 PD_LEI,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Sum(i1.cant*(i1.pu-i1.pretorig)),2) ELSE Sum(i1.cant*(i1.pu-i1.pretorig)) end VAL, 0 VALADAOS,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Sum(Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig)),2) ELSE Sum(Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig)) end VALTVA,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Sum(i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1)),2) ELSE Sum(i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1)) end VAL_LEI, Sum(i1.cant*(i1.pu-i1.pretorig) * Coalesce(i.curs,1)) VALADAOS_LEI, Sum(Decode(i1.pretorig,0,0,i1.tva*i1.pu*Coalesce(i.curs,1)/i1.pretorig)) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, 0 PROCTVAART, 0 PROCDISC, NULL PretMaximal,
      NULL GARIES, NULL GARART, NULL DATAEXP, &apos;&apos; &apos;&apos; DenClasaA, &apos;&apos; &apos;&apos; SimbClasaA, &apos;&apos; &apos;&apos; UM1, &apos;&apos; &apos;&apos; UM2,
      NULL CANT1, NULL CANT2, NULL Serii, NULL SerieData, NULL Ser, NULL SerTg, NULL SerCant, NULL SerObs, NULL TipSerie,
      NULL Aviz, NULL Comanda, NULL ComClient, NULL NRCERTIF, NULL DiscAfis,
      &apos;&apos; Discount pe grupul de articole&apos;&apos; ARTCli, NULL CodExtCli, NULL CodListat,
      NULL DenClaseAS, Max(i1.indexlocal) + 0.1 IDX, 999999 NrUnic,NULL UMCor, NULL CantUMCor, NULL PretUMCor, NULL Dimensiuni, NULL Dim1, NULL CANTREZ, NULL CURSAVIZ, 0 NRCOLETE, NULL DENATRIB, NULL TIPLIVRARE, NULL INFODOCRETUR,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar, null EUDR_rn, null EUDR_vn
    FROM iesiri i
      INNER JOIN iesiri1 i1      ON i1.codies        = i.codies
      INNER JOIN nmonede nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1   TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1   TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codies = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.addim,0) &lt;&gt; 0
    GROUP BY i1.addim,i.rotefact, &apos;||sPjTva;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  IF ConstPDPL = 1 THEN  -- DA
    -- discount pe linie

    sSelect := &apos;)
    SELECT
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ART, nao.denumire ART_ASOCIAT,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.procdisc CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      i1.cant*i1.pretorig/100 PRET, i1.cant*i1.pu/100 PU, 0 PD,
      i1.cant*i1.pretorig/100*Coalesce(i.curs,1) PRET_LEI, i1.cant*i1.pu/100*Coalesce(i.curs,1) PU_LEI, 0 PD_LEI,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(i1.cant*i1.pu*i1.procdisc/100,2) ELSE i1.cant*i1.pu*i1.procdisc/100 end VAL, i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100 VALADAOS, i1.tva*i1.procdisc/100 VALTVA,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1),2) ELSE i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1) end VAL_LEI, i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100*Coalesce(i.curs,1) VALADAOS_LEI, i1.tva*i1.procdisc/100*Coalesce(i.curs,1) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, Coalesce(tmp_tva.procent,0) PROCTVAART, i1.PROCDISC, NULL PretMaximal,
      NULL GARIES, NULL GARART, NULL DATAEXP, &apos;&apos; &apos;&apos; DenClasaA, &apos;&apos; &apos;&apos; SimbClasaA, &apos;&apos; &apos;&apos; UM1, &apos;&apos; &apos;&apos; UM2,
      NULL CANT1, NULL CANT2, NULL Serii, NULL SerieData, NULL Ser, NULL SerTg, NULL SerCant, NULL SerObs, NULL TipSerie,
      NULL Aviz, NULL Comanda, NULL ComClient, NULL NRCERTIF, NULL DiscAfis,
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ARTCli, NULL CodExtCli, NULL CodListat,
      NULL DenClaseAS, i1.indexlocal + 0.1 IDX, 999999 NrUnic,NULL UMCor, NULL CantUMCor, NULL PretUMCor, NULL Dimensiuni, NULL Dim1, NULL CANTREZ, NULL CURSAVIZ, 0 NRCOLETE, NULL DENATRIB, NULL TIPLIVRARE, NULL INFODOCRETUR,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar, null EUDR_rn, null EUDR_vn
    FROM iesiri i
      INNER JOIN iesiri1 i1      ON i1.codies        = i.codies
      INNER JOIN nmonede nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1   TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1   TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codies = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  ELSIF ConstPDPL = 3 THEN -- Da, grupat pe procent discount

    sSelect := &apos;)
    SELECT
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ART, NULL ART_ASOCIAT,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.procdisc CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      Sum(i1.cant*i1.pretorig/100) PRET, Sum(i1.cant*i1.pu/100) PU, 0 PD,
      Sum(i1.cant*i1.pretorig/100*Coalesce(i.curs,1)) PRET_LEI, Sum(i1.cant*i1.pu/100*Coalesce(i.curs,1)) PU_LEI, 0 PD_LEI,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Sum(i1.cant*i1.pu*i1.procdisc/100),2) ELSE Sum(i1.cant*i1.pu*i1.procdisc/100) end VAL, Sum(i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100) VALADAOS, Sum(i1.tva*i1.procdisc/100) VALTVA,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(Sum(i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1)),2) ELSE Sum(i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1)) end VAL_LEI, Sum(i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100*Coalesce(i.curs,1)) VALADAOS_LEI, Sum(i1.tva*i1.procdisc/100*Coalesce(i.curs,1)) VALTVA_LEI,
      0 PROCADAOS, 0 PROCTVA, 0 PROCTVAART, 0 PROCDISC, NULL PretMaximal,
      NULL GARIES, NULL GARART, NULL DATAEXP, &apos;&apos; &apos;&apos; DenClasaA, &apos;&apos; &apos;&apos; SimbClasaA, &apos;&apos; &apos;&apos; UM1, &apos;&apos; &apos;&apos; UM2,
      NULL CANT1, NULL CANT2, NULL Serii, NULL SerieData, NULL Ser, NULL SerTg, NULL SerCant, NULL SerObs, NULL TipSerie,
      NULL Aviz, NULL Comanda, NULL ComClient, NULL NRCERTIF, NULL DiscAfis,
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ARTCli, NULL CodExtCli, NULL CodListat,
      NULL DenClaseAS, 99999 IDX, 999999 NrUnic,NULL UMCor, NULL CantUMCor, NULL PretUMCor, NULL Dimensiuni, NULL Dim1, NULL CANTREZ, NULL CURSAVIZ, 0 NRCOLETE, NULL DENATRIB, NULL TIPLIVRARE, NULL INFODOCRETUR,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar, null EUDR_rn, null EUDR_vn
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      INNER JOIN nmonede nm ON nm.codmoneda = Coalesce(i.moneda,0)
    WHERE i1.codies = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0
    GROUP BY i1.procdisc, i.rotefact&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  IF NOT vFiltruClasaArt and (pListareDiscLangaTot &lt;&gt; &apos;1&apos;) THEN
  -- calculul disc/maj grupat pe TVA
    sSelect := &apos;)
    SELECT
      CASE WHEN MIN(sign(i1.procdisc)) &gt; 0 THEN &apos;&apos; Majorare&apos;&apos;  ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ||&apos;&apos; cumulat TVA &apos;&apos;||&apos;||sPjTva||&apos; ART, NULL ART_ASOCIAT,
      nm.simbol UM,
      &apos;&apos; &apos;&apos; OBSART, 1 CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      SUM(i1.cant * i1.pretorig * i1.procdisc / 100) PRET, SUM(i1.cant * i1.pu * i1.procdisc / 100) PU, SUM(i1.cant * i1.pu * i1.procdisc / 100) PD,
      SUM(i1.cant * i1.pretorig * i1.procdisc / 100 * Coalesce(i.curs,1)) PRET_LEI, SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) PU_LEI, SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) PD_LEI,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(SUM(i1.cant * i1.pu * i1.procdisc / 100),2) ELSE SUM(i1.cant * i1.pu * i1.procdisc / 100) end VAL, SUM(i1.cant * (i1.pu-i1.pretorig) * i1.procdisc / 100) VALADAOS, SUM(i1.tva  * i1.procdisc / 100) VALTVA,
      CASE WHEN I.ROTEFACT = 1 THEN ROUND(SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)),2) ELSE SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) end VAL_LEI, SUM(i1.cant * (i1.pu-i1.pretorig) * i1.procdisc / 100 * Coalesce(i.curs,1)) VALADAOS_LEI, SUM(i1.tva * i1.procdisc / 100 * Coalesce(i.curs,1)) VALTVA_LEI,
      CASE
        WHEN SUM(i1.cant * i1.pu) = 0 THEN 0
        ELSE (SUM(Abs(i1.cant * i1.pu)) / SUM(Abs(i1.cant * i1.pretorig))-1)*100
      END PROCADAOS,
      &apos;||sPjTva||&apos; PROCTVA,
      Max(Coalesce(tmp_tva.procent,0)) PROCTVAART,
      CASE
        WHEN SUM(i1.cant * i1.pu * (1+i1.procdisc / 100)) = 0 THEN 0
        ELSE (SUM( Abs(i1.cant * i1.pu * (1+i1.procdisc / 100)) ) / SUM(Abs(i1.cant * i1.pu))-1) * 100
      END PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART, NULL DATAEXP, &apos;&apos; &apos;&apos; DenClasaA, &apos;&apos; &apos;&apos; SimbClasaA, &apos;&apos; &apos;&apos; UM1, &apos;&apos; &apos;&apos; UM2,
      NULL CANT1, NULL CANT2, NULL Serii, NULL SerieData, NULL Ser, NULL SerTg, NULL SerCant, NULL SerObs, NULL TipSerie, NULL Aviz, NULL Comanda, NULL ComClient, NULL NRCERTIF, NULL DiscAfis,
      CASE WHEN MIN(sign(i1.procdisc)) &gt; 0 THEN &apos;&apos; Majorare&apos;&apos;  ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ||&apos;&apos; cumulat TVA &apos;&apos;||&apos;||sPjTva||&apos; ARTCli, NULL CodExtCli, NULL CodListat,
      NULL DenClaseAS, 1000000+&apos;||sPjTva||&apos;  IDX,1000000+&apos;||sPjTva||&apos;  NrUnic, NULL UMCor, NULL CantUMCor, NULL PretUMCor, NULL Dimensiuni, NULL Dim1, NULL CANTREZ, NULL CURSAVIZ, 0 NRCOLETE, NULL DENATRIB, NULL TIPLIVRARE, NULL INFODOCRETUR,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar, null EUDR_rn, null EUDR_vn
    FROM iesiri i
      INNER JOIN iesiri1 i1      ON i1.codies        = i.codies
      INNER JOIN nmonede nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1   TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1   TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codies = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0
    GROUP BY &apos;||sPjTva||&apos;, nm.simbol, i.rotefact &apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  processparams(tmpName);
--  pkg_globals.ResetAllRecordsLunaFlags;
  COMMIT;

END;

END PKG_LIST_BASE_DOCIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCIESRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>607ACE1B36079694BDD64A19F7F98129184C4A48</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCIESRETAIL IS

  vCodDoc         number(20);
  vTipDoc         number(10);
  pCursDoc        VARCHAR2(3000);
  vNrDC           INTEGER;
  vFiltruClasaArt BOOLEAN;
  vSubCur         number(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pListareDiscLangaTot  VARCHAR2(10);
  pListareLiniiDiscPart VARCHAR2(10);
  pListareUMAmbPretCant VARCHAR2(10);
  pListareDocAgregat    VARCHAR2(10);
  --pGetSoldListFact      VARCHAR2(10);


FUNCTION get_cursor_coloane RETURN crs_cols IS
  crs crs_cols;
BEGIN
  OPEN crs FOR
    SELECT den_um1 || Decode(idxobj,1,NULL,&apos;(&apos;||idxobj||&apos;)&apos;) DEN
    FROM (
      SELECT Upper(U1.DEN_UM1) den_um1, Dense_Rank() OVER (PARTITION BY i1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
      FROM IESIRIRETAIL I
        INNER JOIN IESIRI1RETAIL I1  ON I1.codiesretail = I.codiesretail
        INNER JOIN NARTAMB       AMB ON AMB.CODOBIECT   = I1.CODOBIECT
        INNER JOIN NUM1          U1  ON U1.CODUM1       = AMB.UMSEC
      WHERE I.codiesretail = vCodDoc
    )
    GROUP BY den_um1, idxobj
    ORDER BY den_um1, idxobj;

  RETURN crs;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  vCursor  crs_cols  := get_cursor_coloane;
  vDen     VARCHAR2(30);
BEGIN
  DELETE tmp_dinamic_cols;

  vNrDC := 0;
  IF pListareUMAmbPretCant = &apos;1&apos; THEN
    LOOP
      FETCH vCursor INTO vDen;
      EXIT WHEN vCursor%NOTFOUND;
      INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+1,&apos;fm999&apos;), &apos;Cant.&apos;||vDen);
      INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+2,&apos;fm999&apos;), &apos;Pret/&apos;||vDen);
      vNrDC := vNrDC + 2;
    END LOOP;
    CLOSE vCursor;
  END IF;

  COMMIT;
END;

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER, pFiltruClasaArt IN INTEGER ) IS
BEGIN
  vCodDoc               := pCodDoc;
  vFiltruClasaArt       := pFiltruClasaArt = 1;
  pListareDiscLangaTot  := pkg_categconst.GetValConstanta(&apos;ListareDiscLangaTot&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareLiniiDiscPart := pkg_categconst.GetValConstanta(&apos;ListareLiniiDiscPart&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareUMAmbPretCant := pkg_categconst.GetValConstanta(&apos;ListareUMAmbPretCant&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareDocAgregat    := pkg_categconst.GetValConstanta(&apos;ListareDocAgregat&apos;,   pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  --pGetSoldListFact      := pkg_categconst.GetValConstanta(&apos;GetSoldListFact&apos;,     pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  vSubCur               := pkg_globals.getSubunitate;

  SELECT TipDoc, TO_CHAR(Decode(CursDoc,0,1,NULL,1,CursDoc),&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) CursDoc
  INTO vTipdoc, pCursDoc
  FROM IESIRIRETAIL
  WHERE codiesretail = vCodDoc;

  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
  sSqlAux    VARCHAR2(5000);
  pAviz      VARCHAR2(3000);
  pNrAviz    VARCHAR2(3000);
  pDataAviz  VARCHAR2(3000);
  pMoneda    VARCHAR2( 100);
  pSMoneda   VARCHAR2( 100);
  SitV       VARCHAR2(   2);
  aSitV      NUMBER(     1);
  aBancaV    NUMBER(    20);
  aMonedaV   NUMBER(    20);
  vCodPart   NUMBER(    20);
  vdocmax    NUMBER;
  vtvamax    NUMBER;
  vValDoc    NUMBER;
  vTVADoc    NUMBER;
  vValLei    NUMBER;
  vTVALei    NUMBER;
  vPjTVA     NUMBER;
  vLiniiTMP  NUMBER;
  vCantBuc   NUMBER;
  vCantCut   NUMBER;
  vGSpCut    NUMBER;
  vCantPal   NUMBER;
  vDiscV     NUMBER := 0;
  vDiscT     NUMBER := 0;
  --vSoldPart  NUMBER := 0;
  --vComCurs   NUMBER := 0;
  --vPuncteIes NUMBER := 0;
  --vPunctePar NUMBER := 0;
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NPART1_LST;

  IF Coalesce(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;

  EXECUTE IMMEDIATE &apos;SELECT COUNT(1), Coalesce(SUM(Coalesce(PretMaximal,0)*Coalesce(Cant,0)),0), Coalesce(SUM(Coalesce(PretMaximal,0)*Coalesce(Cant,0)*Coalesce(proctva/100,0)),0) FROM &apos;||TMPNAME INTO vLiniiTMP, vDocMax, vTvaMax;

  WITH UMCP AS (
    SELECT codies1retail, Max(Decode(uext,&apos;CUTIE&apos;,upar)) cutiepar, Max(Decode(uext,&apos;CUTIE&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;PALET&apos;,upar)) paletpar
    FROM (
      SELECT
        I1.codies1retail, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
        Dense_Rank() OVER (PARTITION BY i1.codies1retail, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = i1.umsec THEN 0 ELSE u1.paritate END) idxobj
      FROM IESIRI1RETAIL I1
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = I1.CODOBIECT
        INNER JOIN NUM1    U1  ON U1.CODUM1 = AMB.UMSEC
      WHERE I1.codiesretail = vCodDoc AND I1.TIPLINIE = &apos;=&apos; AND Upper(U1.codextern) IN (&apos;CUTIE&apos;,&apos;PALET&apos;)
    )
    WHERE idxobj = 1
    GROUP BY codies1retail
  )
  SELECT Coalesce(CEIL(SUM(Coalesce(I1.Cant,0))),0), Coalesce(CEIL(SUM(Coalesce(I1.Cant/UMCP.CutiePar,0))),0), Coalesce(Round(SUM(Coalesce(I1.Cant*UMCP.CutieGSp/UMCP.CutiePar,0))),0), Coalesce(CEIL(SUM(Coalesce(I1.Cant/UMCP.PaletPar,0))),0)
  INTO vCantBuc, vCantCut, vGSpCut, vCantPal
  FROM IESIRI1RETAIL I1 LEFT JOIN UMCP ON UMCP.codies1retail = I1.codies1retail
  WHERE I1.codiesretail = vCodDoc AND I1.TIPLINIE = &apos;=&apos;;

  BEGIN
    SELECT Coalesce(t.procent,0) INTO vPjTVA
    FROM (
      SELECT i.an, i.luna, i1.codobiect, Row_Number() OVER (ORDER BY i1.indexlocal) NrCrt
      FROM IESIRIRETAIL i INNER JOIN IESIRI1RETAIL i1 ON i1.codiesretail = i.codiesretail
      WHERE i.codiesretail = vCodDoc AND i1.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;)
    ) xI
      LEFT JOIN nartobj nao ON nao.codobiect = xi.codobiect
      LEFT JOIN NART1   A   ON A.CODARTICOL  = NAO.CODARTICOL AND (xi.AN*12+xi.LUNA) BETWEEN a.ALStart AND a.ALStop
      LEFT JOIN NTVA1   T   ON T.CODTVA      = A.CODTVA       AND (xi.AN*12+xi.LUNA) BETWEEN t.ALStart AND t.ALStop
    WHERE xi.NrCrt = 1;
  EXCEPTION
    WHEN OTHERS THEN vPjTVA := 0;
  END;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN SitV := &apos;DA&apos;;
  ELSE SitV := &apos;NU&apos;;
  END IF;

  SELECT Coalesce(Sum(i1.restfact),0), Coalesce(Sum(i1.tva),0)
  INTO vDiscV, vDiscT
  FROM IESIRI1RETAIL i1
  WHERE i1.codiesretail = vCodDoc AND i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;) AND i1.codcriteriu IS NULL;

  FOR v_rec IN (
    SELECT
      I.codiesretail, I.TIPDOC, I.NRDOC, I.DATADOC, I.SERIADOC, I.VALDOC, I.TVADOC, I.CURS, I.CODLOCATIE,
      --I.ACCIZE,
      I.VALDISCOUNT+vDiscV VALDISCOUNT, I.TVADISCOUNT+vDiscT TVADISCOUNT,
      --I.TIPTRANZACTIE, I.TIPTVA,
      I.NRI, I.AGENT, I.DELEGAT, I.OBS, CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET,
      CODF.CODFISCAL C_CUI, Decode(xP.PERSOANAFIZICA,1,NULL,CODF.CODFISCAL) C_CIF, Decode(xP.PERSOANAFIZICA,1,CODF.CODFISCAL) C_CNP,
      P.DENUMIRE DEN_PART, P.CODEXTERN, P.Codintern CLICODINTERN, to_char(i.datadoc + coalesce(p1.scadentav,xp.scadentav,0),&apos;dd.mm.yyyy&apos;) scadenta,--P.CODSTATISTICBNR,
      Decode(I.Anulat,1,&apos;X&apos;,&apos;&apos;) AnulatX,
      P.REGCOM,
      --P.PERSOANAFIZICA, P.CODPART, P.AUTORIZATIE,
      M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE, I.USERID,
      DECODE(I.CURSDOC,0,1,NULL,1,I.CURSDOC) CURSDOC,
      --MT.DEN_MONEDA DEN_MONEDAT,
      Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      --Decode(P.PERSOANAFIZICA,1,PF.SerieDoc,NULL) PFSerieDoc, Decode(P.PERSOANAFIZICA,1,PF.NrDoc,NULL) PFNrDoc,
      SLIVR.Denumire SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.FAX SLivrFax, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.Email SLIVREmail,
      --SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, --SLIVR.IDSediu SLIVRIDSediu,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, NULL           ) SLivrAdresaNoCP,
      LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
      SFACT.Denumire SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.FAX SFACTFax, SFACT.CODPOSTAL SFACTCodPostal, SFACT.Email SFACTEmail,
      --SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, --SFACT.IDSediu SFACTIDSediu,
      GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
      GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, NULL           ) SFACTAdresaNoCP,
      LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara,
      SSOC.Denumire SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.FAX SSOCFax, SSOC.CODPOSTAL SSOCCodPostal, SSOC.Email SSOCEmail,
      --SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, --SSOC.IDSediu SSOCIDSediu,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, NULL          ) SSOCAdresaNoCP,
      LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
      B.CONTBANCA, B.SUCURSALA, Coalesce(BK.DENUMIRE,B.DENBANCA) DENBANCA, BK.SIMBOL SIMBBANCA,
      AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
      Coalesce(DEL.DELegat, DELE.DELEGAT) DelNume, Coalesce(DEL.DOC,DELE.DOC) DelDoc, Coalesce(DEL.NRdoc,DELE.NRDOC) DelNrDoc,
      Coalesce(DEL.SERIedoc,DELE.SERIEDOC) DelSerDoc, Coalesce(DEL.ELIBERAT,DELE.ELIBERAT) DelElib, Coalesce(DEL.CNP,DELE.CNP) DelCNP,
      Coalesce(DEL.MIJLTRANSP,DELE.MIJLTRANSP) DelMTransp, Coalesce(DEL.NRTRANSP,DELE.NRTRANSP) DelNrTransp, Coalesce(DEL.DATADoc,DELE.DATADOC) DelDataDoc,
      --Decode(i.TipTranzactie,1,&apos;Tranzactie interna&apos;,2,&apos;Livrare intracomunitara&apos;,3,&apos;Export&apos;,&apos; &apos;) Tip_Tranz,
      --Decode(i.TipTVA,1,&apos;taxare normala&apos;,2,&apos;taxare inversa&apos;,3,&apos;tranzactie triunghiulara&apos;,4,&apos;locul livrarii/prestarii in afara Romaniei&apos;,
      --                5,&apos;intracom.,scutit&apos;,6,&apos;cu drept de ded.(lit.a/d)&apos;,7,&apos;intracom.,scutit&apos;,8,&apos;cu drept de ded.(lit.b/c)&apos;,&apos; &apos;) Tip_TVA,
      --PC.Nume||&apos; &apos;||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail,
      (SELECT Count(1) FROM IESIRI1RETAIL I1 WHERE i1.codiesretail = i.codiesretail) NrLinii,
      CASE WHEN Coalesce(aMonedaV,0) = 0 OR Coalesce(aBancaV,0) = 0 THEN 1 ELSE PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMonedaV,aBancaV,i.datadoc) END CursSitV,
      (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = Coalesce(aMonedaV,0)) MonedaSitV,
      (SELECT DENUMIRE FROM NBANK WHERE CODBANK = Coalesce(aBancaV,0)) BancaSitV,
      (SELECT string_agg(CASE
                           WHEN Coalesce(TIPPLATA,0) = 0 THEN &apos;CASH&apos;
                           WHEN Coalesce(TIPPLATA,0) = 1 THEN &apos;CEC&apos;
                           WHEN Coalesce(TIPPLATA,0) = 2 THEN &apos;CARD&apos;
                           WHEN Coalesce(TIPPLATA,0) = 3 THEN &apos;CREDIT&apos;
                         END||&apos;: &apos;||TO_CHAR(VALOARE,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)||&apos; &apos;)
       FROM MODPLATAIESRETAIL
       WHERE CODIESRETAIL = VCODDOC) MODPLATA,  ETRANS.UIT
    FROM IESIRIRETAIL I
      LEFT JOIN EMULARE EM ON EM.CODIESRETAIL = I.CODIESRETAIL
      LEFT JOIN NPARTRETAIL P ON P.CODPARTRETAIL = I.CODPARTRETAIL
      LEFT JOIN NPART xP ON xP.CODPART = P.CODPART
      LEFT JOIN NMONEDE M ON M.CODMONEDA  = Coalesce(I.MONEDA,0)
      LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = I.CARNETDOC
      --LEFT JOIN NPARTCODFISC CODF ON CODF.COD_CODFISCAL = I.CODFISCAL
      LEFT JOIN NCODFISCRETAIL CODF ON CODF.COD = I.CODFISCALRETAIL
      LEFT JOIN NPERS U ON U.CODPERS = EM.CODPERS
      LEFT JOIN NSEDIIPARTRETAIL SLIVR ON SLIVR.CODSEDIU = I.CODSEDIURETAIL AND SLIVR.CODPARTRETAIL = I.CODPARTRETAIL
      --LEFT JOIN NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE AND SLIVR.CODPART = I.PARTENER
      LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
      LEFT JOIN NJUDET JLIVR ON JLIVR.CODJUDET = Coalesce(LLIVR.CODJUDET, 0)
      LEFT JOIN NTARI TLIVR ON TLIVR.CODTARA = Coalesce(LLIVR.CODTARA, 0)
      LEFT JOIN NSEDIIPARTRETAIL SFACT ON SFACT.CODPARTRETAIL = I.CODPARTRETAIL AND SFACT.SEDIUSOCIAL IN (3,7)
      --LEFT JOIN NAGENDA SFACT ON SFACT.CODAGENDA = CASE WHEN SLIVR.SediuSocial = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SediuSocial IN (3,7) THEN SLIVR.CODAGENDA ELSE 0 END
      LEFT JOIN NLOCALIT LFACT ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
      LEFT JOIN NJUDET JFACT ON JFACT.CODJUDET = Coalesce(LFACT.CODJUDET, 0)
      LEFT JOIN NTARI TFACT ON TFACT.CODTARA = Coalesce(LFACT.CODTARA, 0)
      LEFT JOIN NSEDIIPARTRETAIL SSOC ON SSOC.CODPARTRETAIL = I.CODPARTRETAIL AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7
      --LEFT JOIN NAGENDA SSOC ON SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = Coalesce(SSOC.CODLOCALIT, 0)
      LEFT JOIN NJUDET JSOC ON JSOC.CODJUDET = Coalesce(LSOC.CODJUDET, 0)
      LEFT JOIN NTARI TSOC ON TSOC.CODTARA = Coalesce(LSOC.CODTARA, 0)
      --LEFT JOIN NPARTB B ON B.CODPART = P.CODPART AND B.IMPLICIT = 1
      LEFT JOIN NBANCIRETAIL B ON B.CODPARTRETAIL = P.CODPARTRETAIL AND B.IMPLICIT = 1
      LEFT JOIN NBANK BK ON B.CODBANK = BK.CODBANK
      LEFT JOIN NPERS AG ON AG.CODPERS = I.AGENT
      --LEFT JOIN NPARTTR DEL ON DEL.CODPARTTR = I.DELEGAT
      LEFT JOIN NDELEGATRETAIL DEL ON DEL.COD = I.DELEGATRETAIL
      LEFT JOIN NPARTTR DELE ON DELE.CODPARTTR = EM.DELEGAT
      --LEFT JOIN NPARTTR PF ON PF.CODPART = I.PARTENER AND PF.IMPLICIT = 1
      --LEFT JOIN NPERSCONTACT PC ON PC.CodPart = P.CodPart AND PC.CodPersC = Coalesce(I.CodPersC,PC.CodPersC)
      LEFT JOIN NPART1 p1 ON p1.codpart1 = P.codpart AND I.AN*12+I.LUNA BETWEEN p1.alstart AND p1.alstop
      LEFT JOIN STATUSDECL ETRANS ON ETRANS.CODDOC = I.CODIESRETAIL AND ETRANS.TIPDOC = (-1)*(100 + I.TIPDOC)
    WHERE I.codiesretail = vCodDoc
  ) LOOP
    IF vTipdoc &lt;&gt; 26
    THEN pCursDoc := TO_CHAR(v_rec.CursDoc,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;);
    END IF;

    vValDoc := v_rec.ValDoc;
    vTVADoc := v_rec.TVADoc;

    IF vTipdoc = 26
    THEN vValDoc := Round(vValDoc,2);
    ELSE vValDoc := Round(vValDoc - vTVADoc,2) + Round(vTVADoc,2);
    END IF;

    vTVADoc := Round(vTVADoc,2);

    vValLei := v_rec.ValDoc * v_rec.Curs;
    vTVALei := v_rec.TVADoc * v_rec.Curs;

    IF vTipdoc = 26
    THEN vValLei := Round(vValLei,2);
    ELSE vValLei := Round(vValLei - vTVALei,2) + Round(vTVALei,2);
    END IF;

    vTVALei := Round(vTVALei,2);

    pMoneda := v_rec.Den_Moneda;
    pSMoneda:= v_rec.SDenumire;

    --IF pGetSoldListFact = &apos;1&apos;
    --THEN
    --  vSoldPart := PKG_LIST_BASE_UTILS.GetSoldPart(v_rec.CodPart, 0 /*v_rec.CodLocatie*/);

    --  SELECT Coalesce(Sum(c1.restacceptat*c1.pu),0) INTO vComCurs
    --  FROM comanda c INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda AND c1.restacceptat &lt;&gt; 0
    --  WHERE c.partener = v_rec.CodPart AND c.tipdoc = 18 AND pkg_globals.GetSubunitate IN (1,c.subunitatea);
    --END IF;

    pkg_list_Struct.ADAUGA_PARAM(&apos;ANULAT&apos;,                          v_rec.AnulatX);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,                v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODINTERN&apos;,                v_rec.CliCodIntern);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,              v_rec.Autorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL/CNP&apos;,            v_rec.C_CUI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL&apos;,                v_rec.C_CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CNP&apos;,                      v_rec.C_CNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,          v_rec.RegCom);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD STATISTIC BNR&apos;,        v_rec.CodStatisticBNR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR LINII&apos;,            v_rec.NrLinii);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR LINII LISTA&apos;,      vLiniiTMP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SCADENTA&apos;,               v_rec.scadenta);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MOD INCASARE&apos;,                    v_rec.MODPLATA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE&apos;,                    NumarRO(Round(vValDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE ENG&apos;,                NumarUK(Round(vValDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL&apos;,                       TO_CHAR(vValDoc-vTvaDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE&apos;,                NumarRO(Round(vValDoc-vTvaDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE ENG&apos;,            NumarUK(Round(vValDoc-vTvaDoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(vTVADoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(vTVADoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(vTVADoc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE&apos;,                    TO_CHAR(v_rec.Accize,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE LITERE&apos;,             NumarRO(Round(v_rec.Accize,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL ACCIZE LITERE ENG&apos;,         NumarUK(Round(v_rec.Accize,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CURS&apos;,                     TO_CHAR(v_rec.Curs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CURS CALCUL PRET&apos;,                pCursDoc);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CALCUL PRET&apos;,              v_rec.Den_MonedaT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI&apos;,                TO_CHAR(vValLei - vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE&apos;,      NumarRO(Round(vValLei - vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vValLei - vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI&apos;,                TO_CHAR(vTVALei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE&apos;,      NumarRO(Round(vTVALei,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vTVALei,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL FACT.VALUTA IN LEI&apos;,        TO_CHAR(vValLei,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LA PRET MAXIMAL&apos;,           TO_CHAR(vDocMax,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LA PRET MAXIMAL Cu TVA&apos;,    TO_CHAR(vDocMax+vTvaMax,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN BUCATI&apos;,       TO_CHAR(vCantBuc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN CUTII&apos;,        TO_CHAR(vCantCut,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL GREUTATE SPECIFICA CUTII&apos;,  TO_CHAR(vGSpCut, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN PALETI&apos;,       TO_CHAR(vCantPal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SERIE CARTE IDENTITATE&apos;,          v_rec.PFSerieDoc);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR CARTE IDENTITATE&apos;,          v_rec.PFNrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,    v_rec.SLivrAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,               v_rec.SLivrFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE IDSEDIU&apos;,           v_rec.SLivrIDSediu);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE&apos;,        v_rec.SFactObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,          v_rec.SFactAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA FARA CP&apos;,  v_rec.SFactAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATE&apos;,      v_rec.SFactLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,         v_rec.SFactTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE FAX&apos;,             v_rec.SFactFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDET&apos;,           v_rec.SFactSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,  v_rec.SFactJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD POSTAL&apos;,      v_rec.SFactCodPostal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD FISCAL&apos;,      v_rec.SFactCodFiscal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD LA CLIENT&apos;,   v_rec.SFactCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,            v_rec.SFactTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,           v_rec.SFactEmail);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE IDSEDIU&apos;,         v_rec.SFactIDSediu);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.SSocObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.SSocAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA FARA CP&apos;,     v_rec.SSocAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.SSocLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.SSocTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL FAX&apos;,                v_rec.SSocFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SSocSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.SSocJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.SSocCodPostal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.SSocCodFiscal);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.SSocCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.SSocTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,              v_rec.SSocEmail);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL IDSEDIU&apos;,            v_rec.SSocIDSediu);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;,                     v_rec.ContBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;,                    v_rec.DenBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;,             v_rec.SimbBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SUCURSALA BANCA&apos;,          v_rec.Sucursala);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                     TO_CHAR(vSoldPart ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD NEACOPERIT&apos;,          TO_CHAR(vSoldPart+vComCurs ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;COTA TVA&apos;,                        TO_CHAR(vPjTVA,&apos;fm9G999G999G990&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TVA LA INCASARE&apos;,                 v_rec.TVAINCASARE);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;DATA DE CALCUL TVA&apos;,              To_Char(v_rec.DataTva,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT FARA TVA&apos;,               &apos;Discount: &apos;   ||TO_CHAR(v_rec.ValDiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT TVA&apos;,                    &apos;TVADiscount: &apos;||TO_CHAR(v_rec.TVADiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT CU TVA&apos;,                 &apos;Discount: &apos;   ||TO_CHAR(v_rec.ValDiscount+v_rec.TVADiscount,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.ANUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                       v_rec.ACNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                        v_rec.ABI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,               v_rec.DelNume);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,           v_rec.DelCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,              v_rec.DelDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,          v_rec.DelNRdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,        v_rec.DelSerDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,          v_rec.DelElib);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,        To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                   v_rec.DelMTransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,             v_rec.DelNrTransp);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;AUTO NUMAR&apos;,                      v_rec.AutoNr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.Obs);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TIP TRANZACTIE&apos;,                  v_rec.Tip_Tranz);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PARTICULARITATI TVA&apos;,             v_rec.Tip_Tva);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,             v_rec.PCNume);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT TELEFON&apos;,     v_rec.PCTel);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT EMAIL&apos;,       v_rec.PCEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA&apos;         ,      SitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - MONEDA&apos;,      v_rec.MonedaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - BANCA&apos; ,      v_rec.BancaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;UIT&apos;,                                             v_rec.UIT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - CURS&apos;  ,      TO_CHAR(v_rec.CursSitV,&apos;fm9G999G999G990D0000&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PROCENT APLICAT LA CURS&apos;,         TO_CHAR(v_rec.ProcCurstransf,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));

    --pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR NUME&apos;,               v_rec.COMIS_NUME);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODINTERN&apos;,          v_rec.COMIS_CODINTERN);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODEXTERN&apos;,          v_rec.COMIS_CODEXTERN);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODFISCAL/CNP&apos;,      v_rec.COMIS_CODFISCAL);

    --SELECT Coalesce(Sum(PUNCTE),0) , Coalesce(Sum(CASE WHEN E.codiesretail = v_rec.codiesretail THEN PUNCTE ELSE 0 END),0)
    --INTO vPunctePar, vPuncteIes
    --FROM PARTPUNCTE P INNER JOIN EMULARE E ON E.CODEMULARE = P.CODEMULARE
    --WHERE P.CodPart = v_rec.CodPart AND P.Data &lt;= v_rec.DataDoc;
    --pkg_list_Struct.ADAUGA_PARAM(&apos;PUNCTE CUMULATE PE BON&apos;  ,        TO_CHAR(vPuncteIes,&apos;fm9G999G999G990D0000&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL PUNCTE DISPONIBILE&apos;,        TO_CHAR(vPunctePar,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    --EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      Max(CASE WHEN Idx =  1 THEN Den ELSE NULL END) Den1,
      Max(CASE WHEN Idx =  1 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val1,
      Max(CASE WHEN Idx =  2 THEN Den ELSE NULL END) Den2,
      Max(CASE WHEN Idx =  2 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val2,
      Max(CASE WHEN Idx =  3 THEN Den ELSE NULL END) Den3,
      Max(CASE WHEN Idx =  3 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val3,
      Max(CASE WHEN Idx =  4 THEN Den ELSE NULL END) Den4,
      Max(CASE WHEN Idx =  4 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val4,
      Max(CASE WHEN Idx =  5 THEN Den ELSE NULL END) Den5,
      Max(CASE WHEN Idx =  5 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val5,
      Max(CASE WHEN Idx =  6 THEN Den ELSE NULL END) Den6,
      Max(CASE WHEN Idx =  6 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val6,
      Max(CASE WHEN Idx =  7 THEN Den ELSE NULL END) Den7,
      Max(CASE WHEN Idx =  7 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val7,
      Max(CASE WHEN Idx =  8 THEN Den ELSE NULL END) Den8,
      Max(CASE WHEN Idx =  8 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val8,
      Max(CASE WHEN Idx =  9 THEN Den ELSE NULL END) Den9,
      Max(CASE WHEN Idx =  9 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val9,
      Max(CASE WHEN Idx = 10 THEN Den ELSE NULL END) Den10,
      Max(CASE WHEN Idx = 10 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val10,
      TO_CHAR(Coalesce(Sum(Val),0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ValTot
    FROM (
      SELECT
        Row_Number() OVER (ORDER BY Sign(i1.cant), i1.codcriteriu) Idx,
        CASE WHEN Sign(i1.cant)&gt;0  THEN &apos;Majorare &apos; ELSE &apos;Discount &apos; END || CASE WHEN i1.codcriteriu=2 THEN &apos;client&apos; ELSE cd.dencriteriu END den,
        Sum(i1.restfact) val
      FROM iesiri1retail i1 LEFT JOIN criteriidisc cd ON cd.codcriteriu = i1.codcriteriu
      WHERE i1.codiesretail = vCodDoc
        AND i1.tiplinie IN (&apos;G&apos;, &apos;T&apos;)
        AND i1.codcriteriu &gt; 1
      GROUP BY Sign(i1.cant), i1.codcriteriu, cd.dencriteriu
      ORDER BY Sign(i1.cant), i1.codcriteriu
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_DEN&apos;,                     v_rec.Den1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_VAL&apos;,                     v_rec.Val1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_DEN&apos;,                     v_rec.Den2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_VAL&apos;,                     v_rec.Val2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_DEN&apos;,                     v_rec.Den3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_VAL&apos;,                     v_rec.Val3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_DEN&apos;,                     v_rec.Den4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_VAL&apos;,                     v_rec.Val4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_DEN&apos;,                     v_rec.Den5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_VAL&apos;,                     v_rec.Val5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_DEN&apos;,                     v_rec.Den6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_VAL&apos;,                     v_rec.Val6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_DEN&apos;,                     v_rec.Den7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_VAL&apos;,                     v_rec.Val7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_DEN&apos;,                     v_rec.Den8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_VAL&apos;,                     v_rec.Val8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_DEN&apos;,                     v_rec.Den9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_VAL&apos;,                     v_rec.Val9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_DEN&apos;,                    v_rec.Den10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_VAL&apos;,                    v_rec.Val10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL DISC. PARTENER&apos;,          v_rec.ValTot);
  END LOOP;

  FOR v_rec IN (
    SELECT
      SUM(i1.pu * i1.cant) ValBruta,
      SUM(CASE WHEN i1.cant &gt; 0 THEN i1.cant * Coalesce(o.volum,0) ELSE 0 END) Volum,
      SUM(CASE WHEN i1.cant &gt; 0 THEN i1.cant * Coalesce(o.masa,0) ELSE 0 END) Masa,
      SUM(CASE WHEN i1.cant &gt; 0 THEN i1.cant * Coalesce(o.masa,0) * Coalesce(u.coef, 1) ELSE 0 END) MasaM,
      SUM(Ceil(i1.cant) * (SELECT count(1) FROM nartobjcolet oc WHERE oc.codobiect = i1.codobiect) ) NrCol
    FROM iesiri1retail i1
      INNER JOIN nartobj o ON o.codobiect  = i1.codobiect
      INNER JOIN nart    a ON A.CODARTICOL = O.CODARTICOL
      INNER JOIN NUM     U ON U.CODUM = A.UM
    WHERE i1.codiesretail = vCodDoc
      AND NOT (i1.tiplinie IN (&apos;G&apos;, &apos;T&apos;))
    GROUP BY i1.codiesretail
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE BRUTA&apos;,                 TO_CHAR(v_rec.ValBruta,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,                   TO_CHAR(v_rec.Masa,    &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA MULTIPLA&apos;,                 TO_CHAR(v_rec.MasaM,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,                   TO_CHAR(v_rec.Volum,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR COLETE TOTAL&apos;,               TO_CHAR(v_rec.NrCol,   &apos;fm9G999G999G990&apos;,    &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  --pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;IESIRIEXT&apos;, &apos;codiesretail&apos;, vCodDoc);
  --begin
  --  select Coalesce(Partener,0) into vCodPart from IESIRIRETAIL where codiesretail = vCodDoc;
  --exception when others then vCodPart := 0;
  --end;
  --if vCodPart &gt; 0 then
  --  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;NPARTDET&apos;, &apos;CODPART&apos;, vCodPart, &apos;CLIENT &apos;);
  --end if;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sPjTVA     VARCHAR2(  100):= &apos;DECODE(i1.pu*i1.cant,0,0,ROUND(i1.tva*100/(i1.pu*i1.cant)))&apos;;
  sCondDiscP VARCHAR2(  100);
  sCondClasa VARCHAR2(  100);
  sInsertDC  VARCHAR2( 1000);
  sSelectDC  VARCHAR2( 5000);
  sNullDC    VARCHAR2( 2000);
  sWithDC    VARCHAR2( 5000);
  sJoinSer   VARCHAR2( 1000);
  sDenDisc   VARCHAR2(  500);
  sGroupBy1  VARCHAR2( 1000);
  sGroupBy2  VARCHAR2( 1000);
  sJoinL1M   VARCHAR2( 1000);
  sWithMI1   VARCHAR2( 5000);
  sJoinAux   VARCHAR2( 5000);
  ConstPAPL  NUMBER         := Coalesce(pkg_categconst.GetValConstanta(&apos;ProcAdaosPeLinie&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru),2);
  ConstPDPL  NUMBER         := Coalesce(pkg_categconst.GetValConstanta(&apos;ProcDiscPeLinie&apos; ,pkg_globals.AnLucru,pkg_globals.LunaLucru),2);
BEGIN
  gSuplCols :=
    &apos;iesiriretail i, iesiri1retail i1, nartobj nao, nart na, num1 um, nclasea c, nclaseas cs, npart prod, ncont nc, ntva1 tmp_tva&apos;;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;mi1.cant&apos;,&apos;i1.codobiect&apos;,sInsertDC,sSelectDC,sJoinAux);

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  sDenDisc := pkg_categconst.GetValConstanta(&apos;DenDiscount&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) ;
  IF Trim(sDenDisc) IS NULL
  THEN sDenDisc := &apos;Discount&apos;;
  ELSE sDenDisc := REPLACE(sDenDisc,&apos;&apos;&apos;&apos;,&apos;&apos;&apos;&apos;&apos;&apos;);
  END IF;

  IF pListareLiniiDiscPart &lt;&gt; 1 THEN
    sCondDiscP := &apos;
        AND Coalesce(i1.CODCRITERIU,0) = 0&apos;;
  END IF;

  sCondClasa := &apos;&apos;;
  IF vFiltruClasaArt then
    sCondClasa := &apos;
    AND C.CodClaseA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;) &apos;;
  END IF;

  IF vNrDC &gt; 0 THEN
    FOR k IN 1..vNrDC LOOP
      sInsertDC := sInsertDC||&apos;, D&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    sWithDC := sWithDC||&apos;
      DC AS (
        SELECT codobiect&apos;;

    FOR k IN 1..vNrDC/2 LOOP
      sWithDC   := sWithDC   ||&apos;, Max(Decode(idx,&apos;||to_char(k,&apos;fm999&apos;)||&apos;,p)) p&apos;||to_char(k,&apos;fm999&apos;);
      sSelectDC := sSelectDC ||&apos;, i1.cant/dc.p&apos;||to_char(k,&apos;fm999&apos;)||&apos;, i1.pu*dc.p&apos;||to_char(k,&apos;fm999&apos;);
      sNullDC   := sNullDC   ||&apos;, NULL, NULL&apos;;
    END LOOP;

    sWithDC := sWithDC||&apos;
        FROM (
          SELECT codobiect, den_um1, idxobj, p, Dense_Rank() OVER (ORDER BY den_um1, idxobj) idx
          FROM (
            SELECT DISTINCT i1.CODOBIECT, Upper(U1.DEN_UM1) den_um1, u1.paritate p,
              Dense_Rank() OVER (PARTITION BY i1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
            FROM IESIRIRETAIL I
              INNER JOIN IESIRI1RETAIL I1  ON I1.codiesretail = I.codiesretail
              INNER JOIN NARTAMB       AMB ON AMB.CODOBIECT   = I1.CODOBIECT
              INNER JOIN NUM1          U1  ON U1.CODUM1 = AMB.UMSEC
            WHERE I.codiesretail = &apos;||vCodDoc||&apos;)
        ) GROUP BY codobiect),&apos;;

    sJoinAux := sJoinAux||&apos;
    LEFT JOIN DC ON dc.codobiect = i1.codobiect&apos;;
  END IF;

  IF pListareDocAgregat = &apos;1&apos; THEN
    sGroupBy1 := &apos;I1.CODOBIECT, I1.UMSEC&apos;;
    sGroupBy2 := &apos;CODOBIECT, UMSEC&apos;;
    sJoinL1M  := &apos;
          INNER JOIN IESIRI1RETAIL I1 ON I1.codies1retail = L1.codies1retail&apos;;
    sWithMI1:= &apos;,
    MAN_IESIRI1 AS (
      SELECT
        I1.codiesretail, I1.CODOBIECT, I1.UMSEC, I1.codies1retail,
        I1.CANT,
        I1.PRETORIG, I1.PU,
        I1.PRETORIG*DECODE(I1.COEFDISCMAJ,0,1,NULL,1,I1.COEFDISCMAJ) PIES,
        I1.TVA,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END VU,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
        Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
      FROM IESIRI1RETAIL I1
      WHERE i1.codiesretail = &apos;||vCodDoc||sCondDiscP||&apos;
        AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos;
      UNION ALL
      SELECT
        I1.codiesretail, I1.CODOBIECT, I1.UMSEC, MIN(I1.codies1retail) codies1retail,
        SUM(I1.CANT) CANT,
        SUM(I1.CANT * I1.PRETORIG)/SUM(I1.CANT) PRETORIG, SUM(I1.CANT * I1.PU)/SUM(I1.CANT) PU,
        SUM(I1.CANT * I1.PRETORIG*DECODE(I1.COEFDISCMAJ,0,1,NULL,1,I1.COEFDISCMAJ))/SUM(I1.CANT) PIES,
        SUM(I1.TVA) TVA,
        SUM(I1.CANT*I1.PRETORIG) VORIG,
        SUM(I1.CANT*I1.PU) VU,
        SUM(I1.CANT*I1.PU*(1+Coalesce(I1.PROCDISC/100,0))) VIESL,
        Min(Coalesce(I1.PROCDISC,0)) MINPDISC, Max(Coalesce(I1.PROCDISC,0)) MAXPDISC, Min(Coalesce(I1.ADDIM,0)) MINADDIM, Max(Coalesce(I1.ADDIM,0)) MAXADDIM
      FROM IESIRI1RETAIL I1
      WHERE i1.codiesretail = &apos;||vCodDoc||sCondDiscP||&apos;
        AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
      GROUP BY I1.codiesretail, I1.CODOBIECT, I1.UMSEC, SIGN(I1.CANT)
    )&apos;;
  ELSE IF pListareDocAgregat = &apos;3&apos; THEN -- ARTICOL/UMSEC/PU
    sGroupBy1 := &apos;I1.CODOBIECT, I1.UMSEC, I1.PU&apos;;
    sGroupBy2 := &apos;CODOBIECT, UMSEC, PU&apos;;
    sJoinL1M  := &apos;
          INNER JOIN IESIRI1RETAIL I1 ON I1.codies1retail = L1.codies1retail&apos;;
    sWithMI1:= &apos;,
    MAN_IESIRI1 AS (
      SELECT
        I1.codiesretail, I1.CODOBIECT, I1.UMSEC, I1.codies1retail,
        I1.CANT,
        I1.PRETORIG, I1.PU,
        I1.PRETORIG*DECODE(I1.COEFDISCMAJ,0,1,NULL,1,I1.COEFDISCMAJ) PIES,
        I1.TVA,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END VU,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
        Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
      FROM IESIRI1RETAIL I1
      WHERE i1.codiesretail = &apos;||vCodDoc||sCondDiscP||&apos;
        AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos;
      UNION ALL
      SELECT
        I1.codiesretail, I1.CODOBIECT, I1.UMSEC, MIN(I1.codies1retail) codies1retail,
        SUM(I1.CANT) CANT,
        SUM(I1.CANT * I1.PRETORIG)/SUM(I1.CANT) PRETORIG, I1.PU,
        SUM(I1.CANT * I1.PRETORIG*DECODE(I1.COEFDISCMAJ,0,1,NULL,1,I1.COEFDISCMAJ))/SUM(I1.CANT) PIES,
        SUM(I1.TVA) TVA,
        SUM(I1.CANT*I1.PRETORIG) VORIG,
        SUM(I1.CANT*I1.PU) VU,
        SUM(I1.CANT*I1.PU*(1+Coalesce(I1.PROCDISC/100,0))) VIESL,
        Min(Coalesce(I1.PROCDISC,0)) MINPDISC, Max(Coalesce(I1.PROCDISC,0)) MAXPDISC, Min(Coalesce(I1.ADDIM,0)) MINADDIM, Max(Coalesce(I1.ADDIM,0)) MAXADDIM
      FROM IESIRI1RETAIL I1
      WHERE i1.codiesretail = &apos;||vCodDoc||sCondDiscP||&apos;
        AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
      GROUP BY I1.codiesretail, I1.CODOBIECT, I1.UMSEC, SIGN(I1.CANT), I1.PU
    )&apos;;
  ELSE
    sGroupBY1 := &apos;l1.codies1retail&apos;;
    sGroupBY2 := &apos;codies1retail&apos;;
    sWithMI1:= &apos;,
    MAN_IESIRI1 AS (
      SELECT
        I1.codiesretail, I1.CODOBIECT, I1.UMSEC, I1.codies1retail,
        I1.CANT,
        I1.PRETORIG, I1.PU,
        I1.PRETORIG*DECODE(I1.COEFDISCMAJ,0,1,NULL,1,I1.COEFDISCMAJ) PIES,
        I1.TVA,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.RESTFACT ELSE I1.CANT*I1.PU END VU,
        CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
        Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
      FROM IESIRI1RETAIL I1
      WHERE i1.codiesretail = &apos;||vCodDoc||sCondDiscP||&apos;)&apos;;
  END IF;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      ART,
      UM,
      OBSART, CANT, CodIntern,CodExtern,Producator,Masa,Volum,CodVamal,
      PRET, PU, PD,
      PRET_LEI, PU_LEI, PD_LEI,
      VAL, VALADAOS, VALTVA,
      VAL_LEI, VALADAOS_LEI, VALTVA_LEI,
      PROCADAOS,PROCTVA,PROCTVAART,PROCDISC,
      PretMaximal,
      GARIES, GARART,
      DenClasaA,
      SimbClasaA,
      DiscAfis,
      DenClaseAS, IDX, NrUnic,
      NRCOLETE,
      DENATRIB,
      CantUMPrinc, CutiePar, CutieExt, CutieGSp, PaletPar&apos;;

  sSelect := &apos;)
  WITH &apos;||
    sWithDC||&apos;
    UMCP AS (
      SELECT codies1retail, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,upar)) cutiepar, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,aext)) cutieext, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;&apos;PALET&apos;&apos;,upar)) paletpar
      FROM (
        SELECT
          I1.codies1retail, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
          Dense_Rank() OVER (PARTITION BY i1.codies1retail, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = i1.umsec THEN 0 ELSE u1.paritate END) idxobj
        FROM IESIRIRETAIL I
          INNER JOIN IESIRI1RETAIL I1  ON I1.codiesretail = I.codiesretail
          INNER JOIN NARTAMB       AMB ON AMB.CODOBIECT   = I1.CODOBIECT
          INNER JOIN NUM1          U1  ON U1.CODUM1 = AMB.UMSEC
        WHERE I.codiesretail = &apos;||vCodDoc||&apos; AND Upper(U1.codextern) IN (&apos;&apos;CUTIE&apos;&apos;,&apos;&apos;PALET&apos;&apos;)
      )
      WHERE idxobj = 1
      GROUP BY codies1retail)&apos;||
    sWithMI1||&apos;
  SELECT
    CASE
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos; client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos;: &apos;&apos; || cd.DENCRITERIU
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare: &apos;&apos; || cd.DENCRITERIU
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe grupul de articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de grup)&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe toate articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de total)&apos;&apos;
      ELSE nao.denumire
    END ART,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN &apos;&apos;%&apos;&apos; ELSE um.den_um1 END UM,
    i1.obs OBSART, mi1.cant/Coalesce(um.paritate,1) CANT, nao.codintern, nao.codextern, prod.den_part Producator, nao.masa, nao.volum, nao.codvamal,
    mi1.pretorig*um.paritate Pret, mi1.pu*um.paritate PU, mi1.pies*um.paritate PD,
    mi1.pretorig*um.paritate*Coalesce(i.curs,1) Pret_LEI, mi1.pu*um.paritate*Coalesce(i.curs,1) PU_LEI, mi1.pies*um.paritate*Coalesce(i.curs,1) PD_LEI,
    mi1.vu VAL, mi1.pu - mi1.pretorig VALADAOS, mi1.tva VALTVA,
    mi1.vu * Coalesce(i.curs,1) VAL_LEI, (mi1.vu - mi1.vorig) * Coalesce(i.curs,1) VALADAOS_LEI, mi1.tva * Coalesce(i.curs,1) VALTVA_LEI,
    CASE WHEN mi1.minaddim = mi1.maxaddim THEN mi1.minaddim ELSE DECODE(mi1.vorig,0,0,(mi1.vu - mi1.vorig)*100/mi1.vorig) END PROCADAOS,
    ROUND(CASE WHEN mi1.vu = 0 THEN tmp_tva.procent WHEN Coalesce(mi1.tva,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0) / mi1.vu * 100 END,2) PROCTVA,
    ROUND(CASE WHEN tmp_tva.procent IS NOT NULL THEN tmp_tva.procent WHEN Coalesce(mi1.tva,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0) / mi1.vu * 100 END,2) PROCTVAART,
    CASE WHEN mi1.minpdisc= mi1.maxpdisc THEN mi1.minpdisc ELSE DECODE(mi1.vu,0,0,(mi1.viesl - mi1.vu)*100/mi1.vu) END PROCDISC,
    CASE
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2) THEN decode (Coalesce(i1.pumaximal, 0),-1,0,Coalesce(i1.pumaximal, 0) )
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5) THEN decode (Coalesce(nao1.pretmaximal,0),-1,0,Coalesce(nao1.pretmaximal,0))
      ELSE 0
    END PretMaximal,
    i1.garantie GARIES, nao.lunigarantie GARART,
    CASE WHEN NOT I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN c.den_clasea WHEN I1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos; ELSE &apos;&apos; Majorare (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos; END DenClasaA,
    CASE WHEN NOT I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN c.simbol     WHEN i1.CANT &lt;= 0 THEN &apos;&apos; D (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos; ELSE &apos;&apos; M (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos; END SimbClasaA,
    case when Coalesce(i1.procdisc,0) = 0 then &apos;&apos; &apos;&apos; else to_char(i1.procdisc)||&apos;&apos;%&apos;&apos; end DiscAfis,
    cs.den_claseas DenClaseAS, i1.indexlocal IDX, ROWNUM NrUnic,
    (SELECT COUNT(1) FROM nartobjcolet naoc WHERE naoc.codobiect = nao.codobiect) NRCOLETE,
    (SELECT vc2_nt_to_string(CAST(COLLECT(a.denumire order by aa.indexlocal) AS vc2_nt)) FROM nartatr aa INNER JOIN natrib a ON a.codatribut = aa.codatribut WHERE aa.codarticol = nao.codarticol ) DENATRIB,
    mi1.cant CantUMPrinc, UMCP.CutiePar, UMCP.CutieExt, UMCP.CutieGSp, UMCP.PaletPar&apos;||sSelectDC||gUserAlias||&apos;
  FROM man_iesiri1 mi1
    LEFT JOIN iesiri1retail i1      ON i1.codies1retail = mi1.codies1retail
    LEFT JOIN iesiriretail  i       ON i.codiesretail   = i1.codiesretail
    LEFT JOIN nartobj       nao     ON nao.codobiect    = i1.codobiect
    LEFT JOIN nart          na      ON na.codarticol    = nao.codarticol
    LEFT JOIN num1          um      ON um.codum1        = i1.umsec
    LEFT JOIN nclasea       c       ON c.codclasea      = na.clasa
    LEFT JOIN nclaseas      cs      ON cs.codclaseas    = na.clasastatist
    LEFT JOIN npart         prod    ON prod.codpart     = nao.codproducator
    LEFT JOIN npart         p       ON p.codpart        = i.partener
    LEFT JOIN ncont         nc      ON nc.codcont       = i1.contdiscount
    LEFT JOIN nechiv        e       ON e.codobiect      = i1.codobiect
    LEFT JOIN grechiv       gre     ON gre.codgrechiv   = e.codgrupa
    LEFT JOIN nartobj1      nao1    ON nao1.codobiect   = i1.codobiect AND (i.an*12+i.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT JOIN criteriidisc  cd      ON cd.codcriteriu   = i1.codcriteriu
    LEFT JOIN nart1         tmp_a   ON tmp_a.codarticol = na.codarticol AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
    LEFT JOIN ntva1         tmp_tva ON tmp_tva.codtva   = tmp_a.codtva  AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    LEFT JOIN umcp                  ON umcp.codies1retail = mi1.codies1retail &apos;||
    sJoinAux||
    gSuplJoins||&apos;
  WHERE 1=1 &apos;||
    sCondClasa||&apos;
  ORDER BY i1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sinsertdc||guserfields||sSelect, aListID, aListVer);

  IF ConstPAPL =1 THEN -- DA
    -- adaos/diminuare pe linie
    sSelect := &apos;)
    SELECT
      CASE WHEN i1.addim &gt; 0 THEN &apos;&apos; Adaos&apos;&apos; ELSE &apos;&apos; Diminuare&apos;&apos; END ART,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.addim CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      i1.cant*i1.pretorig/100 PRET, 0 PU, 0 PD,
      i1.cant*i1.pretorig/100*Coalesce(i.curs,1) PRET_LEI, 0 PU_LEI, 0 PD_LEI,
      i1.cant*(i1.pu-i1.pretorig) VAL, 0 VALADAOS, Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig) VALTVA,
      i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1) VAL_LEI, i1.cant*(i1.pu-i1.pretorig) * Coalesce(i.curs,1) VALADAOS_LEI, Decode(i1.pretorig,0,0,i1.tva*i1.pu*Coalesce(i.curs,1)/i1.pretorig) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, Coalesce(tmp_tva.procent,0) PROCTVAART, i1.PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART,
      &apos;&apos; &apos;&apos; DenClasaA,
      &apos;&apos; &apos;&apos; SimbClasaA,
      NULL DiscAfis,
      NULL DenClaseAS, i1.indexlocal + 0.1 IDX, 999999 NrUnic,
      0 NRCOLETE,
      NULL DENATRIB,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar
    FROM IESIRIRETAIL i
      INNER JOIN IESIRI1RETAIL i1      ON i1.codiesretail  = i.codiesretail
      INNER JOIN nmonede       nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj       nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1         TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1         TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codiesretail = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.addim,0) &lt;&gt; 0&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  ELSIF ConstPAPL =3 THEN -- Adaos/diminuare pe grupul de articole
    sSelect := &apos;)
    SELECT
      CASE WHEN i1.addim &gt; 0 THEN &apos;&apos; Adaos&apos;&apos; ELSE &apos;&apos; Diminuare&apos;&apos; END||&apos;&apos; pe grupul de articole&apos;&apos; ART,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.addim CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      Sum(i1.cant*i1.pretorig/100) PRET, 0 PU, 0 PD,
      Sum(i1.cant*i1.pretorig/100*Coalesce(i.curs,1)) PRET_LEI, 0 PU_LEI, 0 PD_LEI,
      Sum(i1.cant*(i1.pu-i1.pretorig)) VAL, 0 VALADAOS, Sum(Decode(i1.pretorig,0,0,i1.tva *i1.pu/i1.pretorig)) VALTVA,
      Sum(i1.cant*(i1.pu-i1.pretorig)*Coalesce(i.curs,1)) VAL_LEI, Sum(i1.cant*(i1.pu-i1.pretorig) * Coalesce(i.curs,1)) VALADAOS_LEI, Sum(Decode(i1.pretorig,0,0,i1.tva*i1.pu*Coalesce(i.curs,1)/i1.pretorig)) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, 0 PROCTVAART, 0 PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART,
      &apos;&apos; &apos;&apos; DenClasaA,
      &apos;&apos; &apos;&apos; SimbClasaA,
      NULL DiscAfis,
      NULL DenClaseAS, Max(i1.indexlocal) + 0.1 IDX, 999999 NrUnic,
      0 NRCOLETE,
      NULL DENATRIB,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar
    FROM IESIRIRETAIL i
      INNER JOIN IESIRI1RETAIL i1 ON i1.codiesretail = i.codiesretail
      INNER JOIN nmonede       nm ON nm.codmoneda = Coalesce(i.moneda,0)
    WHERE i1.codiesretail = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.addim,0) &lt;&gt; 0
    GROUP BY i1.addim, &apos;||sPjTva;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  IF ConstPDPL = 1 THEN  -- DA
    -- discount pe linie
    sSelect := &apos;)
    SELECT
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ART,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.procdisc CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      i1.cant*i1.pretorig/100 PRET, i1.cant*i1.pu/100 PU, 0 PD,
      i1.cant*i1.pretorig/100*Coalesce(i.curs,1) PRET_LEI, i1.cant*i1.pu/100*Coalesce(i.curs,1) PU_LEI, 0 PD_LEI,
      i1.cant*i1.pu*i1.procdisc/100 VAL, i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100 VALADAOS, i1.tva*i1.procdisc/100 VALTVA,
      i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1) VAL_LEI, i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100*Coalesce(i.curs,1) VALADAOS_LEI, i1.tva*i1.procdisc/100*Coalesce(i.curs,1) VALTVA_LEI,
      Coalesce(i1.AdDim,0) PROCADAOS, &apos;||sPjTva||&apos; PROCTVA, Coalesce(tmp_tva.procent,0) PROCTVAART, i1.PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART,
      &apos;&apos; &apos;&apos; DenClasaA,
      &apos;&apos; &apos;&apos; SimbClasaA,
      NULL DiscAfis,
      NULL DenClaseAS, i1.indexlocal + 0.1 IDX, 999999 NrUnic,
      0 NRCOLETE,
      NULL DENATRIB,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar
    FROM IESIRIRETAIL i
      INNER JOIN IESIRI1RETAIL i1      ON i1.codiesretail = i.codiesretail
      INNER JOIN nmonede       nm      ON nm.codmoneda  = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj       nao     ON nao.codobiect = i1.codobiect
      LEFT  JOIN NART1         TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1         TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codiesretail = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  ELSIF ConstPDPL = 3 THEN -- Da, grupat pe procent discount
    sSelect := &apos;)
    SELECT
      CASE WHEN i1.procdisc &gt; 0 THEN &apos;&apos; Majorare&apos;&apos; ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ART,
      &apos;&apos;%&apos;&apos; UM,
      &apos;&apos; &apos;&apos; OBSART, i1.procdisc CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      Sum(i1.cant*i1.pretorig/100) PRET, Sum(i1.cant*i1.pu/100) PU, 0 PD,
      Sum(i1.cant*i1.pretorig/100*Coalesce(i.curs,1)) PRET_LEI, Sum(i1.cant*i1.pu/100*Coalesce(i.curs,1)) PU_LEI, 0 PD_LEI,
      Sum(i1.cant*i1.pu*i1.procdisc/100) VAL, Sum(i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100) VALADAOS, Sum(i1.tva*i1.procdisc/100) VALTVA,
      Sum(i1.cant*i1.pu*i1.procdisc/100*Coalesce(i.curs,1)) VAL_LEI, Sum(i1.cant*(i1.pu-i1.pretorig)*i1.procdisc/100*Coalesce(i.curs,1)) VALADAOS_LEI, Sum(i1.tva*i1.procdisc/100*Coalesce(i.curs,1)) VALTVA_LEI,
      0 PROCADAOS, 0 PROCTVA, 0 PROCTVAART, 0 PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART,
      &apos;&apos; &apos;&apos; DenClasaA,
      &apos;&apos; &apos;&apos; SimbClasaA,
      NULL DiscAfis,
      NULL DenClaseAS, 99999 IDX, 999999 NrUnic,
      0 NRCOLETE,
      NULL DENATRIB,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar
    FROM IESIRIRETAIL i
      INNER JOIN IESIRI1RETAIL i1 ON i1.codiesretail = i.codiesretail
      INNER JOIN nmonede       nm ON nm.codmoneda = Coalesce(i.moneda,0)
    WHERE i1.codiesretail = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0
    GROUP BY i1.procdisc&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;


  IF NOT vFiltruClasaArt and (pListareDiscLangaTot &lt;&gt; &apos;1&apos;) THEN
  -- calculul disc/maj grupat pe TVA
    sSelect := &apos;)
    SELECT
      CASE WHEN MIN(sign(i1.procdisc)) &gt; 0 THEN &apos;&apos; Majorare&apos;&apos;  ELSE &apos;&apos; &apos;||sDenDisc||&apos;&apos;&apos; END ||&apos;&apos; cumulat TVA &apos;&apos;||&apos;||sPjTva||&apos; ART,
      nm.simbol UM,
      &apos;&apos; &apos;&apos; OBSART, 1 CANT, &apos;&apos; &apos;&apos; CodIntern, &apos;&apos; &apos;&apos; CodExtern, &apos;&apos; &apos;&apos; Producator, NULL Masa, NULL Volum, NULL CodVamal,
      SUM(i1.cant * i1.pretorig * i1.procdisc / 100) PRET, SUM(i1.cant * i1.pu * i1.procdisc / 100) PU, SUM(i1.cant * i1.pu * i1.procdisc / 100) PD,
      SUM(i1.cant * i1.pretorig * i1.procdisc / 100 * Coalesce(i.curs,1)) PRET_LEI, SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) PU_LEI, SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) PD_LEI,
      SUM(i1.cant * i1.pu * i1.procdisc / 100) VAL, SUM(i1.cant * (i1.pu-i1.pretorig) * i1.procdisc / 100) VALADAOS, SUM(i1.tva  * i1.procdisc / 100) VALTVA,
      SUM(i1.cant * i1.pu * i1.procdisc / 100 * Coalesce(i.curs,1)) VAL_LEI, SUM(i1.cant * (i1.pu-i1.pretorig) * i1.procdisc / 100 * Coalesce(i.curs,1)) VALADAOS_LEI, SUM(i1.tva  * i1.procdisc / 100 * Coalesce(i.curs,1)) VALTVA_LEI,
      CASE WHEN SUM(i1.cant * i1.pu) = 0 THEN 0 ELSE (SUM(i1.cant * i1.pu) / SUM(i1.cant * i1.pretorig)-1)*100 END PROCADAOS,
      &apos;||sPjTva||&apos; PROCTVA, Max(Coalesce(tmp_tva.procent,0)) PROCTVAART,
      CASE WHEN SUM(i1.cant * i1.pu * (1+i1.procdisc / 100)) = 0 THEN 0 ELSE (SUM(i1.cant * i1.pu * (1+i1.procdisc / 100)) / SUM(i1.cant * i1.pu)-1) * 100 END PROCDISC,
      NULL PretMaximal,
      NULL GARIES, NULL GARART,
      &apos;&apos; &apos;&apos; DenClasaA,
      &apos;&apos; &apos;&apos; SimbClasaA,
      NULL DiscAfis,
      NULL DenClaseAS, 1000000+&apos;||sPjTva||&apos;  IDX,1000000+&apos;||sPjTva||&apos;  NrUnic,
      0 NRCOLETE,
      NULL DENATRIB,
      NULL CantUMPrinc, NULL CutiePar, NULL CutieExt, NULL CutieGSp, NULL PaletPar
    FROM IESIRIRETAIL i
      INNER JOIN IESIRI1RETAIL i1      ON i1.codiesretail  = i.codiesretail
      INNER JOIN nmonede       nm      ON nm.codmoneda     = Coalesce(i.moneda,0)
      LEFT  JOIN nartobj       nao     ON nao.codobiect    = i1.codobiect
      LEFT  JOIN NART1         TMP_A   ON TMP_A.CODARTICOL = NAO.CODARTICOL AND (i.AN*12+i.LUNA) BETWEEN TMP_A.ALStart   AND TMP_A.ALStop
      LEFT  JOIN NTVA1         TMP_TVA ON TMP_TVA.CODTVA   = TMP_A.CODTVA   AND (i.AN*12+i.LUNA) BETWEEN TMP_TVA.ALStart AND TMP_TVA.ALStop
    WHERE i1.codiesretail = &apos;||vCodDoc||&apos;
      AND Coalesce(i1.procdisc,0) &lt;&gt; 0
    GROUP BY &apos;||sPjTva||&apos;, nm.simbol &apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  processparams(tmpName);
--  pkg_globals.ResetAllRecordsLunaFlags;
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_dociesretail;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1728954075DE9220F9059BADFC5CF40FC517C637</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCINTR is

  vCodDoc NUMBER(20);
  vSubCur NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
	vCodDoc := pCodDoc;
  vSubCur := pkg_globals.getSubunitate;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(32000);
BEGIN
  gSuplCols :=
    &apos;NGEST S, NUM1 NUM1, NARTOBJ NOBJ, NART NART, NPART NP, NPART PROD, NCLASEA NCA, NCLASEAS NCLS, NUM UM1, NUM UM2, &apos;||
    &apos;INTRARI1 I1, NARTCLI AC, COMANDA1 CCL1, COMANDA CCL, COMANDA1 CINT1, COMANDA CINT, NPART PARTCMDCL&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,       &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,     &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SDOC&apos;,     &apos;SDOC.CODAGENDA = I.CODLOCATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCDOC&apos;,   &apos;LOCDOC.CODLOCALIT = SDOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARADOC&apos;,  &apos;LOCDOC.CODTARA = TARADOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SSOC&apos;,     &apos;SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOSDOC&apos;,   &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARASOC&apos;,  &apos;LOSDOC.CODTARA = TARASOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SPROD&apos;,    &apos;SPROD.CODPART = PROD.CODPART AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SPROD.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCPROD&apos;,  &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARAPROD&apos;, &apos;LOCPROD.CODTARA = TARAPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;,       &apos;BCAR&apos;,     &apos;BCAR.TIPDOC = NIR.TIPNIR AND BCAR.CODDOC1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,    &apos;DEL_BCAR&apos;, &apos;BCAR.CODDELEGAT = DEL_BCAR.CODPARTTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;,    &apos;BCAREXT&apos;,  &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;,    &apos;CCOST.CODCENTRU = NVL(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  DELETE FROM intrari1_man;
  INSERT INTO intrari1_man
  SELECT i1.*
  FROM intrari1 i1
  WHERE i1.codintr = vCodDoc;
  COMMIT;

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     DOCUMENT,
     ORD,
     DENUMIRE,
     DEN_UM1,
     CANT,
     PU,
     DEN_GEST,
     PRETMAXIMAL,
     TIPSERIE,
     SERII,
     SERNOCANT,
     SERCANT,
     SERTG,
     TG,
     CERTIF,
     DATACERTIF,
     DATAPROD,
     CODEXTERN,
     CODINTERN,
     DEN_CLASEA,
     CLASAS,
     NRCMDINT,
     DATACMDINT,
     NRCMDCL,
     DATACMDCL,
     PARTCMDCL,
     OPERATOR &apos;||gUserFields||&apos;)
  WITH
  MAN1 AS (
    SELECT
      I1.codINTR1,
      CASE nvl(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||nser.cantnir||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
        ELSE NULL
      END serii,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg),&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) tg,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.nrcertif)) AS vc2_nt)) nrcertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.dataprimire,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) datacertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dataprod,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.divizor)) AS vc2_nt)) divizor,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.bucati)) AS vc2_nt)) bucati
    FROM intrari1_man i1
      inner join NIRSTOC NS on i1.codintr1 = ns.codintr1
      INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
      INNER JOIN nserii s ON s.codserie = nser.codserie
      LEFT JOIN certif c ON c.codcertif = nser.codcertif
    GROUP BY i1.codintr1, ns.tipserie),
  MAN2 AS (
    SELECT
      codintr1,
      vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) sernocant,
      vc2_nt_to_vc3200(CAST(COLLECT(to_char(tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) sertg,
      vc2_nt_to_vc3200(CAST(COLLECT(To_Char(cant)) AS vc2_nt)) sercant
    FROM
    (
      SELECT i1.codintr1, s.serie, sum(nser.cantnir) cant, nvl(nser.tg, ns.tg) tg
      FROM INTRARI1_MAN I1
        INNER JOIN NIRSTOC NS ON I1.CODINTR1 = NS.CODINTR1
        INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
        INNER JOIN nserii s ON s.codserie = nser.codserie
        LEFT JOIN certif c ON c.codcertif = nser.codcertif
      WHERE nvl(ns.tipserie,0) &gt; 0
      GROUP BY I1.codintr1, s.serie, nvl(nser.tg, ns.tg)
    )
    GROUP BY codintr1)
  SELECT
    i.nrdoc DOCUMENT,
    i1.indexlocal ORD,
    nobj.denumire,
    num1.DEN_UM1,
    i1.CANT,
    i1.PU,
    s.DEN_GEST,
    nobj1.PRETMAXIMAL,
    decode(nart.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie,
    MAN1.SERII,
    MAN2.SERNOCANT,
    MAN2.SERCANT,
    MAN2.SERTG,
    MAN1.TG,
    MAN1.NRCERTIF,
    MAN1.DATACERTIF,
    MAN1.DATAPROD,
    nobj.CODEXTERN,
    nobj.CODINTERN,
    nca.DEN_CLASEA,
    NCLS.DEN_CLASEAS,
    CINT.NRDOC,
    CINT.DATADOC,
    CCL.NRDOC,
    CCL.DATADOC,
    PARTCMDCL.DEN_PART,
    UT.USERNAME &apos;||gUserAlias||&apos;
  FROM intrari1_man i1
    INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR
    INNER JOIN ngest S ON S.codgest = I.CODGESTPROD
    INNER JOIN num1 ON num1.codum1 = I1.umsec
    INNER JOIN nartobj nobj ON nobj.codobiect = I1.codobiect
    INNER JOIN nart ON nart.codarticol = nobj.codarticol
    LEFT JOIN nart1 nart1 ON nart1.codarticol = nobj.codarticol AND (i.an*12+i.luna) BETWEEN nart1.ALStart AND nart1.ALStop
    LEFT JOIN ntva1 ntva1 ON ntva1.codtva = nart1.codtva        AND (i.an*12+i.luna) BETWEEN ntva1.ALStart AND ntva1.ALStop
    LEFT JOIN nartobj1 nobj1 ON nobj1.codobiect = i1.codobiect  AND (i.an*12+i.luna) BETWEEN nobj1.ALStart AND nobj1.ALStop
    LEFT JOIN npart prod ON prod.codpart = nobj.codproducator
    LEFT JOIN nclasea nca ON nca.codclasea = NVL(nart.clasa,0)
    LEFT JOIN num um1 ON um1.codum = nvl(nart.um1,0)
    LEFT JOIN num um2 ON um2.codum = nvl(nart.um2,0)
    left JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = i.USERID
    LEFT JOIN nclaseas ncls ON ncls.codclaseas = nart.clasastatist
    LEFT JOIN man1 ON man1.codintr1 = i1.codintr1
    LEFT JOIN man2 ON man2.codintr1 = i1.codintr1
    LEFT JOIN intrprodlink iprodlink ON iprodlink.codintr1 = I1.codintr1
    LEFT JOIN cmdprodmat cmdpm ON iprodlink.codliniecomanda = cmdpm.codcmdprodmat
    LEFT JOIN cmdlink clink ON clink.codcomanda1 = nvl(i1.codcmd1ae,cmdpm.codcomanda1)
    LEFT JOIN comanda1 ccl1 ON ccl1.codcomanda1 = clink.codliniecomanda
    LEFT JOIN comanda ccl ON ccl1.codcomanda = ccl.codcomanda
    LEFT JOIN comanda1 cint1  ON cint1.codcomanda1 = cmdpm.codcomanda1
    LEFT JOIN comanda cint ON cint.codcomanda = cint1.codcomanda
    LEFT JOIN npart partcmdcl ON partcmdcl.codpart = ccl.partener
    LEFT JOIN npart np ON np.codpart = i.partener
    LEFT JOIN nartcli ac ON ac.codobiect = i1.codobiect AND ac.codpart = i.partener &apos;||
    gSuplJoins||&apos;
  ORDER BY i1.indexlocal &apos;;

  EXECUTE IMMEDIATE sInsert;
  processparams(tmpName);
  COMMIT;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
vValDoc number(20,7);
vValLei number(20,7);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  IF Nvl(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;

  FOR v_rec IN (
    SELECT
      I.CODINTR,
      I.TIPDOC,
      I.NRDOC,
      I.DATADOC,
      I.SERIADOC,
      I.VALDOC,
      I.NRI,
      I.OBS,
      CAR.SIMBOL SIMBOLCARNET,
      CAR.DENUMIRE DENUMIRECARNET,
      G.DEN_GEST,
      I.USERID,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume,
      Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume,
      Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP,
      U.BISERIA||&apos; &apos;||U.BINR UBI,
      AG.NUME||&apos; &apos;||AG.PRENUME PERSP
    FROM INTRARI I
      INNER JOIN NGEST G ON I.CODGESTPROD = G.CODGEST
      LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = I.CARNETDOC
      LEFT JOIN NPERS U ON U.LOGONNAME = I.USERID
      LEFT JOIN NPERS AG ON AG.CODPERS = I.AGENT
    WHERE I.CODINTR = vCodDoc
  ) LOOP

    vValDoc := v_rec.ValDoc;
    vValDoc := Round(vValDoc,2);
    vValLei := v_rec.ValDoc;

    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SIMBOL&apos;,                   v_rec.SimbolCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET SERIE&apos;,                    v_rec.SeriaDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CARNET DENUMIRE&apos;,                 v_rec.DenumireCarnet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SECTIE DE PRODUCTIE&apos;,             v_rec.DEN_GEST);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
    if AccesGranted(pkg_globals.GETUSERID, &apos;BLIND&apos;) &gt; 0 THEN
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    ELSE
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           &apos;***&apos;);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
    if v_rec.tipdoc = 7 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;Predat de (persoana) &apos;,         v_rec.persp);
    end if;
  END LOOP;
END;

end PKG_LIST_BASE_DOCINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEAF59C7CF72947BFCACE6231EF9FCBD20CEA7D2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCLANSPROD IS

  vCodLansProd LANSPROD.CODLANSPROD%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodLansProd := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;nartobj obj, nart art, num num, nclasea cls, lansprod1 lans1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DENUMIRE,
    CODEXTERN,
    CANTCOMANDAT,
    CANTCOMANDATF,
    STOC,
    CANTLANSAT,
    STOCESTIMAT,
    STOCOPTIM,
    STOCMAX,
    CANTCOMANDATN,
    NECESAR,
    OBS,
    PREDARI,
    VALOAREACC,
    PRET,
    COEFUM&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    OBJ.DENUMIRE,
    OBJ.CODEXTERN,
    L1.CANTCOMANDAT,
    L1.CANTCOMANDATF,
    L1.STOC,
    L1.CANTLANSAT,
    L1.STOCESTIMAT,
    L1.STOCOPTIM,
    COALESCE(L1.STOCMAX,OBJS.STOCMAX),
    L1.CANTCOMANDATN,
    L1.NECESAR,
    L1.OBS,
    L1.PREDARI,
    L1.VALOAREACC,
    L1.PRET,
    L1.COEFUM&apos;||gUserAlias||&apos;
  FROM tmp_lansprod1 l1
    inner join lansprod1 lans1 on l1.codlansprod1 = lans1.codlansprod1
    inner join nartobj obj on l1.codobiect = obj.codobiect
    inner join nart art on obj.codarticol = art.codarticol
    inner join num num on num.codum = art.um
    left join nclasea cls on art.clasa = cls.codclasea
    left join nartobjsubunit objs on objs.codobiect = obj.codobiect 
                                  and (objs.codgest is null or objs.codgest = 0)
                                  and objs.subunitate = &apos;||pkg_globals.getsubunitate||&apos; &apos;||
    gSuplJoins||&apos;
  WHERE l1.codlansprod = &apos;||vCodlansprod;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;
END;

end pkg_list_base_doclansprod;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF88E14121249E5357F799F84690C0C0CE493F94</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCLANSZ IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodLansZ   NUMBER(20) DEFAULT 0;

PROCEDURE setParams(aCodLansZ IN number) IS
BEGIN
  pCodLansZ := aCodLansZ;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sString  VARCHAR2(20000);
  sJoinExt VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;nartobj obj, prodcomp pc, tmp_lansz1 l1, tmp_lansz l&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     FORMATIE,
     SCHIMB,
     LUNI,
     MARTI,
     MIERCURI,
     JOI,
     VINERI,
     SAMBATA,
     DUMINICA,
     NEXTWEEK,
     CMD1_LUNI,
     CMD1_MARTI,
     CMD1_MIERCURI,
     CMD1_JOI,
     CMD1_VINERI,
     CMD1_SAMBATA,
     CMD1_DUMINICA,
     TOTAL,
     ALTE,
     LASTWEEK,
     REFWEEK,
     DENUMIRE,
     DEN_CLASEPROD,
     RETETA,
     DEN_CLASEAS,
     TOTALDELANSAT,
     TOTALLANSAT,
     RESTDELANSAT,
     LANS_LUNI,
     LANS_MARTI,
     LANS_MIERCURI,
     LANS_JOI,
     LANS_VINERI,
     LANS_SAMBATA,
     LANS_DUMINICA,
     SUBUNITATEA,
     OPERAT,
     ANULAT,
     BLOCAT,
     OBS,
     AN,
     LUNA,
     SAPTAMANA,
     DATASTART,
     DATASTOP,
     SECTIE,
     REPORT,
     REPORTALTE &apos;||gUserFields||&apos;)
  select
     f.den_formatie FORMATIE,
     l1.SCHIMB,
     l1.LUNI,
     l1.MARTI,
     l1.MIERCURI,
     l1.JOI,
     l1.VINERI,
     l1.SAMBATA,
     l1.DUMINICA,
     l1.NEXTWEEK,
     case when cluni.codcomanda &gt; 0 then CLUNI.PrefixDoc||CLUNI.NrDoc||&apos;&apos;/&apos;&apos;||CLUNI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cmarti.codcomanda &gt; 0 then CMARTI.PrefixDoc||CMARTI.NrDoc||&apos;&apos;/&apos;&apos;||CMARTI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cmiercuri.codcomanda &gt; 0 then CMIERCURI.PrefixDoc||CMIERCURI.NrDoc||&apos;&apos;/&apos;&apos;||CMIERCURI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cjoi.codcomanda &gt; 0 then CJOI.PrefixDoc||CJOI.NrDoc||&apos;&apos;/&apos;&apos;||CJOI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cvineri.codcomanda &gt; 0 then CVINERI.PrefixDoc||CVINERI.NrDoc||&apos;&apos;/&apos;&apos;||CVINERI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when csambata.codcomanda &gt; 0 then CSAMBATA.PrefixDoc||CSAMBATA.NrDoc||&apos;&apos;/&apos;&apos;||CSAMBATA.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cduminica.codcomanda &gt; 0 then CDUMINICA.PrefixDoc||CDUMINICA.NrDoc||&apos;&apos;/&apos;&apos;||CDUMINICA.DataDoc else &apos;&apos;&apos;&apos; end,
     l1.TOTAL,
     l1.ALTE,
     l1.LASTWEEK,
     l1.REFWEEK,
     obj.DENUMIRE,
     l1.DEN_CLASEPROD,
     l1.RETETA,
     l1.DEN_CLASEAS,
     l1.TOTALDELANSAT,
     l1.TOTALLANSAT,
     l1.RESTDELANSAT,
     L1.LANS_LUNI,
     L1.LANS_MARTI,
     L1.LANS_MIERCURI,
     L1.LANS_JOI,
     L1.LANS_VINERI,
     L1.LANS_SAMBATA,
     L1.LANS_DUMINICA,
     sub.den_subunit SUBUNITATEA,
     case when l.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end OPERAT,
     case when l.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ANULAT,
     case when l.blocat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end BLOCAT,
     l.OBS,
     l.AN,
     l.LUNA,
     l.SAPTAMANA,
     to_char(trunc(trunc(to_date(l.AN,&apos;&apos;yyyy&apos;&apos;),&apos;&apos;yyyy&apos;&apos;),&apos;&apos;iw&apos;&apos;) + (l.Saptamana - 1) * 7, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStart,
     to_char(trunc(trunc(to_date(l.AN,&apos;&apos;yyyy&apos;&apos;),&apos;&apos;yyyy&apos;&apos;),&apos;&apos;iw&apos;&apos;) + l.Saptamana  * 7 - 1, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStop,
     g.den_gest SECTIE,
     l1.report,
     l1.reportalte &apos;||gUserAlias||&apos;
  from tmp_lansz1 l1
    inner join tmp_lansz l on l1.codlansz = l.codlansz
    inner join ngest g on l.codgest = g.codgest
    inner join formatii f on f.codformatie = l1.codformatie
    inner join nartobj obj on l1.codobiect = obj.codobiect
    inner join nart art on obj.codarticol = art.codarticol
    inner join num um on um.codum = art.um
    inner join nartobj prod on l1.codobiect = prod.codobiect
    inner join prodcomp pc on pc.codprodcomp = l1.codreteta
    inner join nsubunit sub on l.subunitatea = sub.codsubunit
    left join comanda1 c1luni on c1luni.codcomanda1 = l1.codcmd1_luni
    left join comanda  cluni  on c1luni.codcomanda = cluni.codcomanda
    left join comanda1 c1marti on c1marti.codcomanda1 = l1.codcmd1_marti
    left join comanda  cmarti  on c1marti.codcomanda = cmarti.codcomanda
    left join comanda1 c1miercuri on c1miercuri.codcomanda1 = l1.codcmd1_miercuri
    left join comanda  cmiercuri  on c1miercuri.codcomanda = cmiercuri.codcomanda
    left join comanda1 c1joi on c1joi.codcomanda1 = l1.codcmd1_joi
    left join comanda  cjoi  on c1joi.codcomanda = cjoi.codcomanda
    left join comanda1 c1vineri on c1vineri.codcomanda1 = l1.codcmd1_vineri
    left join comanda  cvineri  on c1vineri.codcomanda = cvineri.codcomanda
    left join comanda1 c1sambata on c1sambata.codcomanda1 = l1.codcmd1_sambata
    left join comanda  csambata  on c1sambata.codcomanda = csambata.codcomanda
    left join comanda1 c1duminica on c1duminica.codcomanda1 = l1.codcmd1_duminica
    left join comanda  cduminica  on c1duminica.codcomanda  = cduminica.codcomanda&apos;||
    gSuplJoins||&apos;
  where f.codformatie &gt; 0 and l.codlansz = &apos;||pCodLansZ;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);
  Commit;
END;

end pkg_list_base_doclansz;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>740058FBB763A0C0F7942884D28E0B7B2D7BB274</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCLANSZ_STOC is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodLansZ NUMBER(20) default 0;

PROCEDURE setParams(aCodLansZ IN number) IS
BEGIN
  pCodLansZ := aCodLansZ;
END;

FUNCTION CODLANSZ RETURN NUMBER IS
BEGIN
  RETURN pCodLansZ;
END;  

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;nartobj comp&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  delete tmp_stocreal;
  insert into tmp_stocreal(codobiect, codgest)
  select distinct codobiect, codgest from (
    select nm.codobiect, glivr.codgest
    from lansz1 l1
         inner join (select codcmd1_luni codcomanda1, codlansz1               from lansz1 where codlansz = pCodLansZ and codcmd1_luni &gt; 0
                     union all select codcmd1_marti codcomanda1, codlansz1    from lansz1 where codlansz = pCodLansZ and codcmd1_marti &gt; 0
                     union all select codcmd1_miercuri codcomanda1, codlansz1 from lansz1 where codlansz = pCodLansZ and codcmd1_miercuri &gt; 0
                     union all select codcmd1_joi codcomanda1, codlansz1      from lansz1 where codlansz = pCodLansZ and codcmd1_joi &gt; 0
                     union all select codcmd1_vineri codcomanda1, codlansz1   from lansz1 where codlansz = pCodLansZ and codcmd1_vineri &gt; 0
                     union all select codcmd1_sambata codcomanda1, codlansz1  from lansz1 where codlansz = pCodLansZ and codcmd1_sambata &gt; 0
                     union all select codcmd1_duminica codcomanda1, codlansz1 from lansz1 where codlansz = pCodLansZ and codcmd1_duminica &gt; 0
                     ) cmd              on cmd.codlansz1   = l1.codlansz1
         inner join comanda1      c1    on c1.codcomanda1  = cmd.codcomanda1
         inner join prodnorme     n     on n.codnorma      = c1.codnorma
         inner join normemat      nm    on nm.codnorma     = n.codnorma
         inner join nartobj       comp  on nm.codobiect    = comp.codobiect
         inner join nartimplicite imp   on comp.codarticol = imp.codarticol and imp.codsubunit = pkg_globals.GETSUBUNITATE_DOC
         inner join ngest         glivr on glivr.codgest   = imp.gestimplicita
    where l1.codlansz = pCodLansZ
    union all
    select nm.codobiect, gnir.codgest
    from lansz1 l1
         inner join (select codcmd1_luni codcomanda1, codlansz1               from lansz1 where codlansz = pCodLansZ and codcmd1_luni &gt; 0
                     union all select codcmd1_marti codcomanda1, codlansz1    from lansz1 where codlansz = pCodLansZ and codcmd1_marti &gt; 0
                     union all select codcmd1_miercuri codcomanda1, codlansz1 from lansz1 where codlansz = pCodLansZ and codcmd1_miercuri &gt; 0
                     union all select codcmd1_joi codcomanda1, codlansz1      from lansz1 where codlansz = pCodLansZ and codcmd1_joi &gt; 0
                     union all select codcmd1_vineri codcomanda1, codlansz1   from lansz1 where codlansz = pCodLansZ and codcmd1_vineri &gt; 0
                     union all select codcmd1_sambata codcomanda1, codlansz1  from lansz1 where codlansz = pCodLansZ and codcmd1_sambata &gt; 0
                     union all select codcmd1_duminica codcomanda1, codlansz1 from lansz1 where codlansz = pCodLansZ and codcmd1_duminica &gt; 0
                     ) cmd         on cmd.codlansz1  = l1.codlansz1
         inner join comanda1  c1   on c1.codcomanda1 = cmd.codcomanda1
         inner join prodnorme n    on n.codnorma     = c1.codnorma
         inner join normemat  nm   on nm.codnorma    = n.codnorma
         inner join nartobj   comp on nm.codobiect   = comp.codobiect
         inner join lansz     l    on l1.codlansz    = l.codlansz
         inner join ngest     gnir on l.codgest      = gnir.codgest
    where l1.codlansz = pCodLansZ
    );

  update tmp_stocreal tmp
  set cant = (
              SELECT nvl(sum(NS.REST),0)
              FROM
                NIRSTOC NS,
                NIR N,
                NGEST G,
                IOART1 IO1
              WHERE
                NS.CODNIR = N.CODNIR
                AND N.GEST = G.CODGEST
                AND NVL(NS.REST, 0) &lt;&gt; 0
                AND NS.CODIOART = IO1.CODIOART
                AND IO1.MG &lt;&gt; 5
                and tmp.codobiect = ns.codobiect
                and tmp.codgest = g.codgest
                and pkg_globals.GETSUBUNITATE_DOC = G.CODSUBUNIT
                and (PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU) BETWEEN IO1.ALSTART and IO1.ALSTOP
               ),
       cantUM1 = (
              SELECT nvl(sum(NS.RESTUM1),0)
              FROM
                NIRSTOC NS,
                NIR N,
                NGEST G,
                IOART1 IO1
              WHERE
                NS.CODNIR = N.CODNIR
                AND N.GEST = G.CODGEST
                AND NVL(NS.RESTUM1, 0) &lt;&gt; 0
                AND NS.CODIOART = IO1.CODIOART
                AND IO1.MG &lt;&gt; 5
                and tmp.codobiect = ns.codobiect
                and tmp.codgest = g.codgest
                and pkg_globals.GETSUBUNITATE_DOC = G.CODSUBUNIT
                and (PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU) BETWEEN IO1.ALSTART and IO1.ALSTOP
               );


  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     SAPTAMANA,
     COMPONENT,
     CODINTERN,
     UM,
     UMS,
     NECESAR,
     NECESARUMS,
     GESTLIVR,
     STOCL,
     STOCLUMS,
     DIFL,
     DIFLUMS,
     GESTNIR,
     STOCR,
     STOCRUMS,
     DIFR,
     DIFRUMS &apos;||gUserFields||&apos;)
  select
    x.saptamana,
    comp.denumire COMPONENT,
    comp.CODINTERN,
    um.den_um UM,
    um1.den_um UMS,
    x.NECESAR,
    x.NECESARUMS,
    glivr.den_gest GESTLIVR,
    stocl.cant STOCL,
    stocl.cantUM1 STOCLUMS,
    nvl(stocl.cant,0) - nvl(x.NECESAR,0) DIFL,
    nvl(stocl.cantUM1,0) - nvl(x.NECESARUMS,0) DIFLUMS,
    gnir.den_gest GESTNIR,
    stocn.cant STOCR,
    stocn.cantUM1 STOCRUMS,
    nvl(stocn.cant,0) - nvl(x.NECESAR,0) DIFR,
    nvl(stocn.cantUM1,0) - nvl(x.NECESARUMS,0) DIFRUMS&apos;||gUserAlias||&apos;
  from (
    select
      l.SAPTAMANA,
      comp.codobiect,
      sum(c1.cantacceptat/pc.cant*nm.cant) NECESAR,
      sum(CASE
        WHEN acomp.RELATIEUM1 IN (1, 7) AND NVL(nm.D1, 0) &lt;&gt; 0 THEN c1.cantacceptat/pc.cant*nm.cant / nm.D1
        WHEN acomp.RELATIEUM1 IN (2, 8) AND NVL(nm.D1, 0) * NVL(nm.D2, 0) &lt;&gt; 0 THEN c1.cantacceptat/pc.cant*nm.cant/(NVL(nm.D1,0) * NVL(nm.D2,0))
        WHEN acomp.RELATIEUM1 IN (3, 9) AND NVL(nm.D1, 0) * NVL(nm.D2, 0) * NVL(nm.D3, 0) &lt;&gt; 0 THEN c1.cantacceptat/pc.cant*nm.cant/(NVL(nm.D1, 0) * NVL(nm.D2, 0) * NVL(nm.D3, 0))
        WHEN acomp.RELATIEUM1 IN (4, 10) THEN c1.cantacceptat/pc.cant*nm.cant * NVL(nm.D1, 0)
        WHEN acomp.RELATIEUM1 IN (5, 11) THEN c1.cantacceptat/pc.cant*nm.cant * NVL(nm.D1, 0) * NVL(nm.D2, 0)
        WHEN acomp.RELATIEUM1 IN (6, 12) THEN c1.cantacceptat/pc.cant*nm.cant * NVL(nm.D1, 0) * NVL(nm.D2, 0) * NVL(nm.D3, 0)
      END) NECESARUMS,
      nvl(glivr.codgest,0) glivr,
      nvl(gnir.codgest,0) gnir
    from lansz1 l1
         inner join lansz l on l1.codlansz = l.codlansz
         inner join (select codcmd1_luni codcomanda1, codlansz1               from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_luni &gt; 0
                     union all select codcmd1_marti codcomanda1, codlansz1    from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_marti &gt; 0
                     union all select codcmd1_miercuri codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_miercuri &gt; 0
                     union all select codcmd1_joi codcomanda1, codlansz1      from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_joi &gt; 0
                     union all select codcmd1_vineri codcomanda1, codlansz1   from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_vineri &gt; 0
                     union all select codcmd1_sambata codcomanda1, codlansz1  from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_sambata &gt; 0
                     union all select codcmd1_duminica codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_duminica &gt; 0
                     ) cmd             on cmd.codlansz1    = l1.codlansz1
         inner join comanda1     c1    on c1.codcomanda1   = cmd.codcomanda1
         inner join comanda      c     on c1.codcomanda    = c.codcomanda
         inner join nartobj      prod  on c1.codobiect     = prod.codobiect
         inner join prodnorme    n     on n.codnorma       = c1.codnorma
         inner join prodcomp     pc    on pc.codprodcomp   = c1.codreteta
         inner join normemat     nm    on nm.codnorma      = n.codnorma
         inner join nartobj      comp  on nm.codobiect     = comp.codobiect
         inner join nart         acomp on acomp.codarticol = comp.codarticol
         inner join num                on num.codum        = acomp.um
         inner join ngest        gnir  on l.codgest        = gnir.codgest
         left join nartimplicite imp   on acomp.codarticol = imp.codarticol and imp.codsubunit = pkg_globals.GETSUBUNITATE_DOC
         left join num           ums   on ums.codum        = acomp.um1
         left join ngest         glivr on glivr.codgest    = imp.gestimplicita
    where l1.codlansz = &apos;||pCodLansZ||&apos;
    group by l.saptamana, comp.codobiect, glivr.codgest, gnir.codgest
  ) x
    inner join nartobj     comp  on comp.codobiect   = x.codobiect
    inner join nart        acomp on acomp.codarticol = comp.codarticol
    inner join num         um    on acomp.um         = um.codum
    left join num          um1   on acomp.um1        = um1.codum
    left join ngest        gnir  on x.gnir           = gnir.codgest
    left join ngest        glivr on glivr.codgest    = x.glivr
    left join tmp_stocreal stocl on comp.codobiect   = stocl.codobiect and glivr.codgest = stocl.codgest
    left join tmp_stocreal stocn on comp.codobiect   = stocn.codobiect and gnir.codgest = stocn.codgest &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);

  Commit;
END;

end PKG_LIST_BASE_DOCLANSZ_STOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCLANSZ_TRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48D03B9CB9C81B41BFB73DF22D45422674AA9F26</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCLANSZ_TRANSF is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodLansZ NUMBER(20) default 0;

PROCEDURE setParams(aCodLansZ IN number) IS
BEGIN
  pCodLansZ := aCodLansZ;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sString  VARCHAR2(20000);
  sJoinExt VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;nartobj prod, nartobj comp,transf t,IOART IOACIMP,nclaseas clsas&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     SAPTAMANA,
     NRCMD,
     DATACMD,
     SCHIMB,
     FORMATIE,
     NORMA,
     PRODUS,
     CODEXTERN,
     NRTRANSF,
     DATATRANSF,
     COMPONENT,
     CODINTERN,
     UM,
     CANT,
     UMS,
     CANTUM1,
     GESTLIVR,
     NRLIVR,
     DATALIVR,
     GESTNIR,
     NRNIR,
     DATANIR,
     ARTINNORMA,
     CANTTR,
     CANTTRUM1,
     CANTNORMA,
     CANTNORMAUM1,
     CANTPROD,
     CANTRETETA,
     PRODUM,
     DEN_CLASEAS &apos;||gUserFields||&apos;)
  select
    l.saptamana,
    c.nrdoc,
    c.datadoc,
    c.SCHIMB,
    f.den_formatie,
    n.NORMA,
    prod.denumire,
    prod.CODEXTERN,
    t.nrdoc,
    t.datadoc,
    comp.denumire,
    comp.CODINTERN,
    num1.den_um1,
    c1.cantacceptat/ret.cant*nm.cant,
    UMS.Den_Um,
    CASE
      WHEN acomp.RELATIEUM1 IN (1, 7) AND NVL(acomp.D1, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / acomp.D1
      WHEN acomp.RELATIEUM1 IN (2, 8) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0))
      WHEN acomp.RELATIEUM1 IN (3, 9) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0))
      WHEN acomp.RELATIEUM1 IN (4, 10) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0)
      WHEN acomp.RELATIEUM1 IN (5, 11) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0) * NVL(acomp.D2, 0)
      WHEN acomp.RELATIEUM1 IN (6, 12) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0)
    END,
    glivr.den_gest,
    lv.nrlivr,
    lv.datalivr,
    gnir.den_gest,
    nir.nrnir,
    nir.datanir,
    case when nm.codnormemat &gt; 0 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    t1.cant,
    CASE
      WHEN acomp.RELATIEUM1 IN (1, 7) AND NVL(acomp.D1, 0) &lt;&gt; 0 THEN t1.CANT / acomp.D1
      WHEN acomp.RELATIEUM1 IN (2, 8) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) &lt;&gt; 0 THEN t1.CANT / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0))
      WHEN acomp.RELATIEUM1 IN (3, 9) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0) &lt;&gt; 0 THEN t1.CANT / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0))
      WHEN acomp.RELATIEUM1 IN (4, 10) THEN t1.CANT * NVL(acomp.D1, 0)
      WHEN acomp.RELATIEUM1 IN (5, 11) THEN t1.CANT * NVL(acomp.D1, 0) * NVL(acomp.D2, 0)
      WHEN acomp.RELATIEUM1 IN (6, 12) THEN t1.CANT * NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0)
    END,
    nm.cant,
    nm.cantum1,
    l1.totaldelansat,
    ret.cant,
    produm.den_um,
    clsas.den_claseas &apos;||gUserAlias||&apos;
  from tmp_lansz1 l1
       inner join lansz l on l1.codlansz = l.codlansz
       inner join (select codcmd1_luni codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_luni &gt; 0
                   union all select codcmd1_marti codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_marti &gt; 0
                   union all select codcmd1_miercuri codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_miercuri &gt; 0
                   union all select codcmd1_joi codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_joi &gt; 0
                   union all select codcmd1_vineri codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_vineri &gt; 0
                   union all select codcmd1_sambata codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_sambata &gt; 0
                   union all select codcmd1_duminica codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_duminica &gt; 0
                   ) cmd on cmd.codlansz1 = l1.codlansz1
       inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
       inner join comanda c on c1.codcomanda = c.codcomanda
       inner join transf1 t1 on t1.codcomanda1 = c1.codcomanda1
       inner join transf t on t.codtransf = t1.codtransf
       inner join prodnorme n on n.codnorma = c1.codnorma
       inner join prodcomp ret on ret.codprodcomp = c1.codreteta
       inner join normemat nm on nm.codnorma = n.codnorma and nm.codobiect = t1.codobiect
       inner join nartobj prod on c1.codobiect = prod.codobiect
       inner join nartobj comp on nm.codobiect = comp.codobiect
       inner join nart acomp on acomp.codarticol = comp.codarticol
       inner join nart aprod on aprod.codarticol = prod.codarticol
       inner join num produm on produm.codum = aprod.um
       left join num ums on ums.codum = acomp.um1
       left join num1 on num1.codum = acomp.um and nvl(num1.secundara,0) = 0
       left join formatii f on f.codformatie = c.codformatie
       left join livr1 lv1 on lv1.codies1 = t1.codtransf1
       left join livr lv on lv1.codlivr = lv.codlivr and lv.codtransf = t.codtransf
       left join nirstoc nsl on nsl.codnirstoc = lv1.codnirstoc
       left join nir nirl on nirl.codnir = nsl.codnir
       left join ngest glivr on glivr.codgest = nirl.gest
       left join nir on nir.codtransf = t.codtransf
       left join nirstoc ns on ns.codnir = nir.codnir and ns.codtransf1 = t1.codtransf1
       left join ngest gnir on gnir.codgest = nir.gest
       LEFT JOIN NARTIMPLICITE IMP ON Acomp.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = l.subunitatea
       LEFT JOIN NARTOBJIMP OIMP ON comp.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = l.subunitatea
       LEFT JOIN IOART IOACIMP ON IOACIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT,0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
       left join nclaseas clsas on acomp.CLASASTATIST = clsas.codclaseas
  where l1.codlansz = &apos;||pCodLansZ;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     SAPTAMANA,
     NRCMD,
     DATACMD,
     SCHIMB,
     FORMATIE,
     NORMA,
     PRODUS,
     CODEXTERN,
     NRTRANSF,
     DATATRANSF,
     COMPONENT,
     CODINTERN,
     UM,
     CANT,
     UMS,
     CANTUM1,
     GESTLIVR,
     NRLIVR,
     DATALIVR,
     GESTNIR,
     NRNIR,
     DATANIR,
     ARTINNORMA,
     CANTTR,
     CANTTRUM1,
     CANTNORMA,
     CANTNORMAUM1,
     CANTPROD,
     CANTRETETA,
     PRODUM,
     DEN_CLASEAS &apos;||gUserFields||&apos;)
  select
    l.saptamana,
    c.nrdoc,
    c.datadoc,
    c.SCHIMB,
    f.den_formatie,
    n.NORMA,
    prod.denumire,
    prod.CODEXTERN,
    t.nrdoc,
    t.datadoc,
    comp.denumire,
    comp.CODINTERN,
    num1.den_um1,
    c1.cantacceptat/ret.cant*nm.cant,
    UMS.Den_Um,
    CASE
      WHEN acomp.RELATIEUM1 IN (1, 7) AND NVL(acomp.D1, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / acomp.D1
      WHEN acomp.RELATIEUM1 IN (2, 8) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0))
      WHEN acomp.RELATIEUM1 IN (3, 9) AND NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0) &lt;&gt; 0 THEN c1.cantacceptat/ret.cant*nm.cant / (NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0))
      WHEN acomp.RELATIEUM1 IN (4, 10) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0)
      WHEN acomp.RELATIEUM1 IN (5, 11) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0) * NVL(acomp.D2, 0)
      WHEN acomp.RELATIEUM1 IN (6, 12) THEN c1.cantacceptat/ret.cant*nm.cant * NVL(acomp.D1, 0) * NVL(acomp.D2, 0) * NVL(acomp.D3, 0)
    END,
    glivr.den_gest,
    lv.nrlivr,
    lv.datalivr,
    gnir.den_gest,
    nir.nrnir,
    nir.datanir,
    case when nm.codnormemat &gt; 0 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    0,
    0,
    nm.cant,
    nm.cantum1,
    l1.totaldelansat,
    ret.cant,
    produm.den_um,
    clsas.den_claseas &apos;||gUserAlias||&apos;
  from tmp_lansz1 l1
    inner join lansz l on l1.codlansz = l.codlansz
    inner join (select codcmd1_luni codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_luni &gt; 0
                union all select codcmd1_marti codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_marti &gt; 0
                union all select codcmd1_miercuri codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_miercuri &gt; 0
                union all select codcmd1_joi codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_joi &gt; 0
                union all select codcmd1_vineri codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_vineri &gt; 0
                union all select codcmd1_sambata codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_sambata &gt; 0
                union all select codcmd1_duminica codcomanda1, codlansz1 from lansz1 where codlansz = &apos;||pCodLansZ||&apos; and codcmd1_duminica &gt; 0
                ) cmd on cmd.codlansz1 = l1.codlansz1
    inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
    inner join comanda c on c1.codcomanda = c.codcomanda
    inner join prodnorme n on n.codnorma = c1.codnorma
    inner join prodcomp ret on ret.codprodcomp = c1.codreteta
    inner join normemat nm on nm.codnorma = n.codnorma
    inner join nartobj prod on c1.codobiect = prod.codobiect
    inner join nartobj comp on nm.codobiect = comp.codobiect
    inner join nart acomp on acomp.codarticol = comp.codarticol
    inner join nart aprod on aprod.codarticol = prod.codarticol
    inner join num produm on produm.codum = aprod.um
    left join transf1 t1 on t1.codcomanda1 = c1.codcomanda1 and t1.codobiect = nm.codobiect
    left join transf t on t.codtransf = t1.codtransf
    left join num ums on ums.codum = acomp.um1
    left join num1 on num1.codum = acomp.um and nvl(num1.secundara,0) = 0
    left join formatii f on f.codformatie = c.codformatie
    left join livr1 lv1 on lv1.codies1 = t1.codtransf1
    left join livr lv on lv1.codlivr = lv.codlivr and lv.codtransf = t.codtransf
    left join nirstoc nsl on nsl.codnirstoc = lv1.codnirstoc
    left join nir nirl on nirl.codnir = nsl.codnir
    left join ngest glivr on glivr.codgest = nirl.gest
    left join nir on nir.codtransf = t.codtransf
    left join nirstoc ns on ns.codnir = nir.codnir and ns.codtransf1 = t1.codtransf1
    left join ngest gnir on gnir.codgest = nir.gest
    LEFT JOIN NARTIMPLICITE IMP ON Acomp.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = l.subunitatea
    LEFT JOIN NARTOBJIMP OIMP ON comp.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = l.subunitatea
    LEFT JOIN IOART IOACIMP ON IOACIMP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN NVL(IMP.CONTIMPLICIT,0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
    left join nclaseas clsas on acomp.CLASASTATIST = clsas.codclaseas&apos;||
    gSuplJoins||&apos;
  where nvl(t1.codtransf1,0) = 0 and l1.codlansz = &apos;||pCodLansZ;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);

  Commit;
END;

end PKG_LIST_BASE_DOCLANSZ_TRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCLIBERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F97319BE753BD2F593C7FFCCEB48AEAD44EC0873</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_doclibere IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(1000);
  sSelect   VARCHAR2(19000);
BEGIN
  gSuplCols := &apos;DOCFREE DF, DOCCARNETE DC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos; (DENUMIRE,SIMBOL,SERIE,ACTIV,NRSTART,NREND,TOT,TOTLIB,INTERV,SUBUNITATEA,FIRSTNR,DATALAST&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
    WITH FNR AS
      (
       select dc.CODCARNET, min(coalesce(bcar.nrdoc,
                                 k.nraviz,
                                 cf.nrdoc,
                                 c.nrdoc,
                                 cmp.nrdoc,
                                 cc.nrdoc,
                                 ep.nrdoc,
                                 fz.nrdoc,
                                 fmas.nrdoc,
                                 iesc.nrdoc,
                                 ies.nrdoc,
                                 iesr.nrdoc,
                                 iesrl.nrdoc,
                                 intr.nrdoc,
                                 lans.nrdoc,
                                 livr.nrlivr,
                                 nc.nrdoc,
                                 nec.nrdoc,
                                 nir.nrnir,
                                 ncr.nrdoc,
                                 o.nrdoc,
                                 opt.nrdoc,
                                 pk.nrdoc,
                                 pp.nrdoc,
                                 plati.nrdoc,
                                 pf.nrdoc,
                                 po.nrdoc,
                                 rp.nrdoc,
                                 rcl.nrdoc,
                                 rnp.nrdoc,
                                 tsk.nrdoc,
                                 tr.nrdoc,
                                 t1.nrdoc,
                                 0
                                )
                       ) Primul,
                       max(
                        coalesce(bcar.datadoc,
                                 k.DATACREARE,
                                 cf.data,
                                 c.datadoc,
                                 cmp.datadoc,
                                 cc.datadoc,
                                 ep.datadoc,
                                 fz.datadoc,
                                 fmas.datadoc,
                                 iesc.datadoc,
                                 ies.datadoc,
                                 iesr.datadoc,
                                 iesrl.datadoc,
                                 intr.datadoc,
                                 lans.datadoc,
                                 livr.datalivr,
                                 nc.datadoc,
                                 nec.datadoc,
                                 nir.datanir,
                                 ncr.DATACREARE,
                                 o.DATAOFERTA,
                                 opt.datadoc,
                                 pk.datap,
                                 pp.datadoc,
                                 plati.data,
                                 pf.DATAINREG,
                                 po.DATACREARE,
                                 rp.DATACREARE,
                                 rcl.datadoc,
                                 rnp.datadoc,
                                 tsk.DATATASK,
                                 tr.datadoc,
                                 t1.datadoc
                                )
                          ) DataLast
        from doccarnete dc
             left join bcar on bcar.carnetdoc = dc.codcarnet
             left join cantar k on k.carnetdoc = dc.codcarnet
             left join CASHFLOW cf on cf.carnetdoc = dc.codcarnet
             left join COMANDA c on c.carnetdoc = dc.codcarnet
             left join COMPENS cmp on cmp.CARNETDOC = dc.codcarnet
             left join CONTRACT cc on cc.CARNETDOC = dc.codcarnet
             left join ESTIMARIPROD ep on ep.CARNETDOC = dc.codcarnet
             left join FAZ fz on fz.CARNETDOC = dc.codcarnet
             left join FISAMAS fmas on fmas.CARNETDOC = dc.codcarnet
             left join IESIRI iesc on iesc.CARNETCERTIF = dc.codcarnet
             left join IESIRI ies on ies.CARNETDOC = dc.codcarnet
             left join IESIRIRETAIL iesr on iesr.CARNETDOC = dc.codcarnet
             left join IESIRIRETAIL iesrl on iesrl.CARNETLIVR = dc.codcarnet
             left join INTRARI intr on intr.CARNETDOC = dc.codcarnet
             left join LANSARE lans on lans.CARNETDOC = dc.codcarnet
             left join LIVR on livr.CARNETLIVR = dc.codcarnet
             left join NC on nc.CARNETDOC = dc.codcarnet
             left join NECESAR nec on nec.carnetdoc = dc.codcarnet
             left join NIR on nir.CARNETNIR = dc.codcarnet
             left join NOTECREDIT ncr on ncr.CARNETDOC = dc.codcarnet
             left join OFERTA o on o.CARNETDOC = dc.codcarnet
             left join OPORTUNITATI opt on opt.CODCARNETDOC = dc.codcarnet
             left join PACHETE pk on pk.CARNETDOC = dc.codcarnet
             left join PLANIFPROD pp on pp.CARNETDOC = dc.codcarnet
             left join PLATI on plati.CARNETDOC = dc.codcarnet
             left join PROGRAMF pf on pf.CARNETDOC = dc.codcarnet
             left join PROMO PO on PO.CARNETDOC = dc.codcarnet
             left join RAPORTP rp on rp.CARNETDOC = dc.codcarnet
             left join RECLAMATII rcl on rcl.CARNETDOC = dc.codcarnet
             left join RESTNP rnp on rnp.CARNETDOC = dc.codcarnet
             left join SETTASK tsk on tsk.CARNETDOC = dc.codcarnet
             left join TRANSF tr on tr.CARNETDOC = dc.codcarnet
             left join TREZOR1 t1 on t1.CARNETDOC = dc.codcarnet
        where coalesce(extract(year from bcar.datadoc),
                       k.an,
                       cf.an,
                       c.an,
                       cmp.an,
                       cc.an,
                       ep.an,
                       fz.an,
                       extract(year from fmas.datadoc),
                       iesc.an,
                       ies.an,
                       iesr.an,
                       iesrl.an,
                       intr.an,
                       extract(year from lans.datadoc),
                       extract(year from livr.datalivr),
                       nc.an,
                       nec.an,
                       extract(year from nir.datanir),
                       ncr.an,
                       o.an,
                       opt.an,
                       pk.an,
                       pp.an,
                       plati.an,
                       pf.an,
                       po.an,
                       rp.an,
                       extract(year from rcl.datadoc),
                       extract(year from rnp.datadoc),
                       extract(year from tsk.datatask),
                       tr.an,
                       t1.an) = PKG_LIST_BASE_SELANLUNAREF.AN
        group by dc.codcarnet
       ),
       LD as
       (
       select dc.CODCARNET, 
                       max(
                        coalesce(bcar.datadoc,
                                 k.DATACREARE,
                                 cf.data,
                                 c.datadoc,
                                 cmp.datadoc,
                                 cc.datadoc,
                                 ep.datadoc,
                                 fz.datadoc,
                                 fmas.datadoc,
                                 iesc.datadoc,
                                 ies.datadoc,
                                 iesr.datadoc,
                                 iesrl.datadoc,
                                 intr.datadoc,
                                 lans.datadoc,
                                 livr.datalivr,
                                 nc.datadoc,
                                 nec.datadoc,
                                 nir.datanir,
                                 ncr.DATACREARE,
                                 o.DATAOFERTA,
                                 opt.datadoc,
                                 pk.datap,
                                 pp.datadoc,
                                 plati.data,
                                 pf.DATAINREG,
                                 po.DATACREARE,
                                 rp.DATACREARE,
                                 rcl.datadoc,
                                 rnp.datadoc,
                                 tsk.DATATASK,
                                 tr.datadoc,
                                 t1.datadoc
                                )
                          ) DataLast
        from doccarnete dc
             left join bcar on bcar.carnetdoc = dc.codcarnet
             left join cantar k on k.carnetdoc = dc.codcarnet
             left join CASHFLOW cf on cf.carnetdoc = dc.codcarnet
             left join COMANDA c on c.carnetdoc = dc.codcarnet
             left join COMPENS cmp on cmp.CARNETDOC = dc.codcarnet
             left join CONTRACT cc on cc.CARNETDOC = dc.codcarnet
             left join ESTIMARIPROD ep on ep.CARNETDOC = dc.codcarnet
             left join FAZ fz on fz.CARNETDOC = dc.codcarnet
             left join FISAMAS fmas on fmas.CARNETDOC = dc.codcarnet
             left join IESIRI iesc on iesc.CARNETCERTIF = dc.codcarnet
             left join IESIRI ies on ies.CARNETDOC = dc.codcarnet
             left join IESIRIRETAIL iesr on iesr.CARNETDOC = dc.codcarnet
             left join IESIRIRETAIL iesrl on iesrl.CARNETLIVR = dc.codcarnet
             left join INTRARI intr on intr.CARNETDOC = dc.codcarnet
             left join LANSARE lans on lans.CARNETDOC = dc.codcarnet
             left join LIVR on livr.CARNETLIVR = dc.codcarnet
             left join NC on nc.CARNETDOC = dc.codcarnet
             left join NECESAR nec on nec.carnetdoc = dc.codcarnet
             left join NIR on nir.CARNETNIR = dc.codcarnet
             left join NOTECREDIT ncr on ncr.CARNETDOC = dc.codcarnet
             left join OFERTA o on o.CARNETDOC = dc.codcarnet
             left join OPORTUNITATI opt on opt.CODCARNETDOC = dc.codcarnet
             left join PACHETE pk on pk.CARNETDOC = dc.codcarnet
             left join PLANIFPROD pp on pp.CARNETDOC = dc.codcarnet
             left join PLATI on plati.CARNETDOC = dc.codcarnet
             left join PROGRAMF pf on pf.CARNETDOC = dc.codcarnet
             left join PROMO PO on PO.CARNETDOC = dc.codcarnet
             left join RAPORTP rp on rp.CARNETDOC = dc.codcarnet
             left join RECLAMATII rcl on rcl.CARNETDOC = dc.codcarnet
             left join RESTNP rnp on rnp.CARNETDOC = dc.codcarnet
             left join SETTASK tsk on tsk.CARNETDOC = dc.codcarnet
             left join TRANSF tr on tr.CARNETDOC = dc.codcarnet
             left join TREZOR1 t1 on t1.CARNETDOC = dc.codcarnet
       group by dc.codcarnet
       ),
         FFREE AS 
      (
       SELECT MIN(STARTNR) STARTNR, CODCARNET
       FROM DOCFREE
       GROUP BY CODCARNET
       )
    SELECT DC.DENUMIRE, DC.SIMBOL, DC.SERIE, DECODE(DC.INACTIV,0,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) ACTIV,
           DC.STARTNR, DC.ENDNR, DC.ENDNR - DC.STARTNR + 1 TOTALNR, DC.FREENR,
           DF.STARTNR ||&apos;&apos; - &apos;&apos;||DF.ENDNR INTERV, S.DEN_SUBUNIT, CASE WHEN NVL(FNR.PRIMUL,0) = 0 THEN fFREE.STARTNR ELSE FNR.PRIMUL END,LD.DATALAST  &apos;||gUserAlias||&apos;
    FROM DOCFREE DF
         LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = DF.CODCARNET
         LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = DC.SUBUNITATEA
         LEFT JOIN FNR ON FNR.CODCARNET = DF.CODCARNET
         LEFT JOIN LD ON LD.CODCARNET = DF.CODCARNET
         LEFT JOIN FFREE ON FFREE.CODCARNET = DF.CODCARNET&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_DOCLIBERE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCMARIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA7E75CD59F1A973A7931CD2561D9FE8B89FD0C0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCMARIRI IS

  vCodDoc NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  FOR v_rec IN (
                SELECT
                  I.NRDOC,I.DATADOC,I.VALDOC,I.NRAE,I.OBS,I.USERID, TC.DENUMIRE TIPINREG,I.TIPDOC,
                  P.DEN_PART, P.CODEXTERN, P.AUTORIZATIE, CODF.CODFISCAL, P.REGCOM, P.CODSTATISTICBNR,
                  CR.NUME, CR.PRENUME, CR.CNP,I.SERIADOC,
                  SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.FAX SLivrFax, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.Email SLIVREmail, SLIVR.IDSediu SLIVRIDSediu,
                  GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
                  GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, NULL           ) SLivrAdresaNoCP,
                  LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara, DEL.DELEGAT
                FROM IESIRI I
                     LEFT JOIN TIPCHELT TC ON TC.CODTIPCHELT = I.TIPCHELT
                     LEFT JOIN NPART P ON I.PARTENER = P.CODPART
                     LEFT JOIN NPARTTR DEL ON DEL.CODPART = P.CODPART AND DEL.ACTIV = 1
                     LEFT JOIN NPARTCODFISC CODF ON CODF.COD_CODFISCAL = I.CODFISCAL
                     LEFT JOIN NPERS CR ON CR.LOGONNAME = I.USERID
                     LEFT JOIN NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE AND SLIVR.CODPART = I.PARTENER
                     LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
                     LEFT JOIN NJUDET JLIVR ON JLIVR.CODJUDET = Coalesce(LLIVR.CODJUDET, 0)
                     LEFT JOIN NTARI TLIVR ON TLIVR.CODTARA = Coalesce(LLIVR.CODTARA, 0)
                WHERE I.CODIES = vCodDoc
                ORDER BY DEL.CODPARTTR
               ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,           v_rec.DEN_PART);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,          v_rec.CODEXTERN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,        v_rec.AUTORIZATIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL/CNP&apos;,      v_rec.CODFISCAL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,    v_rec.REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD STATISTIC BNR&apos;,  v_rec.CODSTATISTICBNR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DELEGAT&apos;,            v_rec.DELEGAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,            v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIA&apos;,            v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,             v_rec.DATADOC);
    if AccesGranted(pkg_globals.GETUSERID, &apos;BLIND&apos;) &gt; 0 THEN
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT TOTAL&apos;,            v_rec.VALDOC);
    ELSE
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT TOTAL&apos;,            &apos;***&apos;);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;AVIZ NUMAR&apos;,                v_rec.NRAE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATIE&apos;,                v_rec.OBS);
    IF V_REC.TIPDOC = 14 THEN
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIP DOC&apos;,                 &apos;Proces verbal de diminuare de stoc&apos;);
    ELSE
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIP DOC&apos;,                 &apos;Proces verbal de marire de stoc&apos;);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;TIP INREGISTRARE&apos;,          v_rec.TIPINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,             v_rec.NUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,          v_rec.PRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,              v_rec.CNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FILTRU&apos;,                    &apos;&apos;);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,    v_rec.SLivrAdresaNoCP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,               v_rec.SLivrFax);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE IDSEDIU&apos;,           v_rec.SLivrIDSediu);
    EXIT;
  END LOOP;
  FOR v_rec IN (
                SELECT SUM(L1.CANT * NVL(NS.PRET,0)) TOTAL
                FROM LIVR L,
                     LIVR1 L1,
                     NIRSTOC NS
                WHERE L.CODIES = vCodDoc AND L.CODLIVR = L1.CODLIVR AND L1.CODNIRSTOC = NS.CODNIRSTOC
               ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LIVRARI&apos;, v_rec.TOTAL);
  END LOOP;
  FOR V_REC IN (
                SELECT SUM(I1.CANT * NVL(O.VOLUM,0)) VOLUM, SUM(I1.CANT * NVL(O.MASA,0)) MASA, SUM(I1.CANT * NVL(O.MASA,0) * Nvl(U.Coef, 1)) MASAM
                FROM IESIRI I
                  INNER JOIN IESIRI1 I1 ON I.CODIES = I1.CODIES
                  INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
                  INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
                  INNER JOIN NUM U ON U.CODUM = A.UM
                WHERE I.CODIES = vCodDoc
               ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,    v_rec.VOLUM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,    v_rec.MASA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA MULTIPLA&apos;,  v_rec.MASAM);
  END LOOP;
END;

PROCEDURE SetParams( aCodDoc IN NUMBER ) IS
BEGIN
  vCodDoc := aCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(32000);
BEGIN
  gSuplCols := &apos;IESIRI IES, IESIRI1 IES1, NARTOBJ NOBJ, NART NART, NUM1 NUM1, NUM UM_ALT1, NUM UM_ALT2, NCLASEA NCA, NGEST NG, IOART IO, IOART1 IO1, NPART PROD, NPART FURN, NART1 N1, NTVA1 NTVA1, NCONT NCONT&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  IF aLISTID = 108 THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DIMINEXT&apos;, &apos;IEXT&apos;, &apos;IEXT.CODIES = IES.CODIES&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DIMIN1EXT&apos;, &apos;I1EXT&apos;, &apos;I1EXT.CODIES1 = IES1.CODIES1&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos; (
    DATADOC,DENUMIRE,CANT,DEN_UM1,CLASA_ART,GESTIUNEA,CONT,
    PUINREG, PUACHIZ,VALINREG,VALACHIZ, PUMAXIMAL,
    PRODUCATOR,FURNIZOR, CODINTERN,CODEXTERN,PROCENT,
    TIPSERIE,SERII,SERIEDATA,SER,SERTG,SERCANT,TG,
    DEN_UM1_ALT1, DEN_UM1_ALT2, CANT_ALT1, CANT_ALT2 &apos;||gUserFields||&apos;)
  WITH LG AS (
    SELECT
      i1.codies, i1.codies1, n.gest, nvl(lv.codioart, ns.codioart) codioart,
      sum(CASE WHEN L1.CODLIVR1 IS NULL THEN I1.CANT ELSE l1.cant END) cant,
      sum(CASE WHEN L1.CODLIVR1 IS NULL THEN I1.CANTUM1 ELSE l1.cantum1 END) cantum1,
      sum(l1.cantum2) cantum2,
      Sum(DECODE(lv.codlivrval,NULL,ns.pret,lv.pretinreg) * l1.cant) valinreg,
      Sum(DECODE(nvl(ns.tva,0),0,0,ns.pret*l1.cant*ns.tva/(1+ns.tva))) tvaneex,
      Sum(NVL(DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz)*l1.cant,0)) valachiz,
      NVL(i1.pumaximal,max(NVL(ns.pumaximal,0))) pumaximal,
      ns.tipserie, ns.furn,
      CASE nvl(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_vc3200(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt))
        ELSE NULL
      END serii,
      CASE nvl(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie||&apos;&apos; - &apos;&apos;||TO_CHAR(NVL(nser.tg, ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_vc3200(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;||&apos;&apos; - &apos;&apos;||TO_CHAR(NVL(nser.tg, ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)) AS vc2_nt))
        ELSE NULL
      END seriedata,
      vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT to_char(nvl(nser.tg,ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;)) AS vc2_nt)) tg,
      vc2_nt_to_vc3200(CAST(COLLECT(s.serie ORDER BY s.serie) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(COLLECT(TO_CHAR(NVL(nser.tg, ns.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;) ORDER BY s.serie) AS vc2_nt)) sertg,
      vc2_nt_to_vc3200(CAST(COLLECT(TO_CHAR(l1.cant) ORDER BY s.serie) AS vc2_nt)) sercant
    FROM IESIRI1 i1
      LEFT JOIN livr l ON l.codies = i1.codies
      LEFT JOIN livr1 l1 ON l1.codies1 = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
      LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      LEFT JOIN nir n ON n.codnir = ns.codnir
      LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
      LEFT JOIN nserii s ON s.codserie = nser.codserie
    WHERE I1.CODIES = &apos;||vCodDoc||&apos;
    GROUP BY i1.codies, i1.codies1, i1.pumaximal, n.gest, lv.codioart, ns.codioart, ns.tipserie, ns.furn)
  SELECT
    IES.DATADOC, NOBJ.DENUMIRE, LG.CANT, NUM1.DEN_UM1, NCA.DEN_CLASEA, NG.DEN_GEST, NCONT.SIMBOL,
    DECODE(lg.cant,0,0,lg.valinreg*num1.paritate/lg.cant), DECODE(lg.cant,0,0,lg.valachiz*num1.paritate/lg.cant), lg.valinreg, lg.valachiz, lg.pumaximal,
    PROD.DEN_PART, FURN.DEN_PART, NOBJ.CODINTERN, NOBJ.CODEXTERN, NTVA1.PROCENT,
    DECODE(LG.TIPSERIE, 1, &apos;&apos;serie pe bucata&apos;&apos;, 2, &apos;&apos;serie pe lot&apos;&apos;, &apos;&apos;fara serie&apos;&apos;) TIPSERIE, LG.SERII,LG.SERIEDATA,LG.SER,LG.SERTG,LG.SERCANT,LG.TG,
    UM_Alt1.den_um, UM_Alt2.den_um, LG.CantUM1, LG.CantUM2 &apos;||gUserAlias||&apos;
  FROM LG
    INNER JOIN IESIRI IES ON IES.CODIES = LG.CODIES
    INNER JOIN IESIRI1 IES1 ON IES1.CODIES1 = LG.CODIES1
    LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = IES1.CODOBIECT
    LEFT JOIN NART NART ON NART.CODARTICOL = NOBJ.CODARTICOL
    LEFT JOIN NUM1 NUM1 ON NUM1.CODUM1 = IES1.UMSEC
    LEFT JOIN NUM UM_ALT1 ON NART.UM1 = UM_ALT1.CodUm
    LEFT JOIN NUM UM_ALT2 ON NART.UM2 = UM_ALT2.CodUm
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = Nvl(NART.CLASA,0)
    LEFT JOIN NGEST NG ON NG.CODGEST = LG.GEST
    LEFT JOIN IOART IO ON IO.CODIOART = LG.CODIOART
    LEFT JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART AND (IES.AN*12+IES.LUNA) BETWEEN io1.ALStart and io1.ALStop
    LEFT JOIN NPART PROD ON PROD.CODPART = NOBJ.CODPRODUCATOR
    LEFT JOIN NPART FURN ON FURN.CODPART = LG.FURN
    LEFT JOIN NART1 N1 ON N1.CODARTICOL = NART.CODARTICOL AND (IES.AN*12+IES.LUNA) BETWEEN n1.ALStart and n1.ALStop
    LEFT JOIN NTVA1 NTVA1 ON NTVA1.CODTVA = N1.CODTVA AND (IES.AN*12+IES.LUNA) BETWEEN NTVA1.ALStart and NTVA1.ALStop 
    LEFT JOIN NCONT ON NCONT.CODCONT = Nvl(IES1.CONT,IO1.CONT)&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  ADD_LIST_PARAMS;
  COMMIT;

END;

end PKG_LIST_BASE_DOCMARIRI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCMONETARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A917820A297A72F27AA038EB49B50027E637C92</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_docmonetare IS

  vCodDoc   IESIRI.CODIES%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

function GetCodIes return IESIRI.CODIES%TYPE is
begin
  return vCodDoc;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(9000);
BEGIN
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  
  gSuplCols := &apos;iesiri i, iesiri1 i1, nartobj nao, nart na, NUM1 UM, NUM UM1, NUM UM2, nclasea c, pretm p, nartobj1 nao1, ncont nc, ngest ng&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART,UM,CANT,PRET,VAL,
    PJTVA,VALTVA,
    OBSART,CodIntern,CodExtern,PuAchiz,
    PuMAX,
    PretV, GEST,DenCONT,SimbCONT,DenClasaA,SimbClasaA,UM1,UM2,CANT1,CANT2,
    SERII,GAR,TG,IDX&apos;||gUserFields||&apos;)&apos;;

  -- liniile de pe iesiri
  sSelect := &apos;
  WITH MAN_SER_GROUP AS (
    SELECT CODIES1, vc2_nt_to_vc3200(CAST(collect(serie) AS vc2_nt)) serii
    FROM (
      SELECT L1.CODIES1, CASE WHEN SUM(L1.CANT) = 1 THEN NSERII.SERIE ELSE NSERII.SERIE||&apos;&apos;(&apos;&apos;||SUM(L1.CANT)||&apos;&apos;)&apos;&apos;  END SERIE
      FROM LIVR1 L1
        INNER JOIN LIVR L ON L.CODLIVR        = L1.CODLIVR
        INNER JOIN NIRSER ON NIRSER.CODNIRSER = L1.CODNIRSER
        INNER JOIN NSERII ON NSERII.CODSERIE  = NIRSER.CODSERIE
      WHERE L.CODIES = &apos;||vCodDoc||&apos;
      GROUP BY L1.CODIES1, NSERII.SERIE)
    GROUP BY CODIES1 ),
  MAN_NIRSTOC AS (
    SELECT
      L1.CODIES1, nvl(MAX(ns.pumaximal),0) pumaximal, SUM(l1.cantum1) cantum1,
      SUM(l1.cantum2) cantum2, vc2_nt_to_string(CAST(collect(DISTINCT to_char(ns.tg)) AS vc2_nt)) tg,
      SUM( NVL(lv.pretachiz,ns.pret - ns.adaos) * l1.cant) valachiz
    FROM LIVR1 L1
      INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      LEFT  JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
      LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    WHERE L.CODIES =&apos;||vCodDoc||&apos;
    GROUP BY L1.CODIES1)
  SELECT
    nao.denumire, um.den_um1, i1.cant/um.paritate, i1.pu * um.paritate, i1.pu * i1.cant,
    DECODE(i1.pu*i1.cant,0,0,ROUND(i1.tva*100/(i1.pu*i1.cant - i1.tva))) , i1.tva,
    i1.obs,  nao.codintern, nao.codextern, mns.valachiz / (i1.cant/um.paritate),
    CASE
      WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN decode (NVL(i1.pumaximal, mns.pumaximal),-1,0,NVL(i1.pumaximal, mns.pumaximal) )
      WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN decode (nvl(nao1.pretmaximal,0),-1,0,nvl(nao1.pretmaximal,0))
      ELSE 0
    END,
    NVL(p.lei,0), ng.den_gest, nc.den_cont, nc.simbol, c.den_clasea, c.simbol, um1.den_um, um2.den_um, mns.cantum1, mns.cantum2,
    ms.serii, i1.garantie,  mns.tg, i1.indexlocal&apos;||gUserAlias||&apos;
  FROM iesiri i
    INNER JOIN iesiri1       i1   ON i1.codies      = i.codies
    LEFT  JOIN nartobj       nao  ON nao.codobiect  = i1.codobiect
    LEFT  JOIN nart          na   ON na.codarticol  = nao.codarticol
    LEFT  JOIN NUM1          UM   ON um.codum1      = i1.umsec
    LEFT  JOIN NUM           UM1  ON um1.codum      = na.um1
    LEFT  JOIN NUM           UM2  ON um2.codum      = na.um2
    LEFT  JOIN nclasea       c    ON c.codclasea    = na.clasa
    LEFT  JOIN pretm         p    ON p.codobiect    = i1.codobiect AND p.subunitatea = i.subunitatea AND p.implicit = 1
    LEFT  JOIN man_ser_group ms   ON ms.codies1     = i1.codies1
    LEFT  JOIN man_nirstoc   mns  ON mns.codies1    = i1.codies1
    LEFT  JOIN nartobj1      nao1 ON nao1.codobiect = i1.codobiect AND (i.an*12+i.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN ncont         nc   ON nc.codcont     = i1.contserv
    LEFT  JOIN ngest         ng   ON ng.codgest     = i1.gestact&apos;||
    gSuplJoins||&apos;
  WHERE i1.codies =&apos;||vCodDoc||&apos;
  ORDER BY i1.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      I.VALDISCOUNT, I.TVADISCOUNT, I.VALDOC, I.TVADOC, I.NRDOC, I.DATADOC, I.OBS,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      i.numarbonuri
    FROM iesiri i
      LEFT JOIN NPERS U ON U.LOGONNAME = I.USERID
    WHERE I.CODIES = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT TOTAL&apos;,    TO_CHAR(v_rec.VALDISCOUNT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT TVA&apos;,      TO_CHAR(v_rec.TVADISCOUNT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONETAR VALOARE&apos;,   TO_CHAR(v_rec.VALDOC,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONETAR TVA&apos;,       TO_CHAR(v_rec.TVADOC,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,    v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,     v_rec.DATADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,        v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR BONURI&apos;,      to_char(v_rec.numarbonuri));

    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,    v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,  v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,      v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,       v_rec.UBI);

    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT vc2_nt_to_string(CAST(COLLECT(denmodplata||Decode(bc.nrcont,NULL, NULL, &apos;/&apos;||bc.nrcont||&apos; - &apos;||To_Char(valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ) ORDER BY codmodplata) AS vc2_nt)) IncDoc
    FROM moduriplati mp left join nbankcont bc ON bc.codbankcont = mp.codbankcont
    WHERE mp.codies = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;TIP PLATA&apos;,         v_rec.IncDoc);

    EXIT;
  END LOOP;
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;MONETAREXT&apos;, &apos;CODIES&apos;, vCodDoc);

  COMMIT;

END;

end PKG_LIST_BASE_DOCMONETARE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DAE8E5D97756E6C05161A69DFE67CC8CD0F2D88A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCNECESAR IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodNecesar NUMBER(20) default 0;

PROCEDURE setParams(aCodNecesar IN number) IS
BEGIN
  pCodNecesar := aCodNecesar;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;nartobj obj, necesar nec, nart art, num um, num um1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     Articol,
     CodIntern,
     ClasaSt,
     Clasa,
     Um,
     Stoc,
     SetimanaPrec,
     CmdFurnPrec,
     Setimana,
     CmdFurn,
     CmdFurnNext,
     CmdFurnTot,
     PlanifPrec,
     Planif,
     Necesar1,
     StocMin,
     Necesar2,
     Acceptat,
     CmdFurnNec,
     Rest,
     ValAcceptat,
     PMP,
     ValNecesar,
     Um1,
     NecesarUM1,
     AcceptatUM1,
     RestUM1,
     D1,
     D2,
     D3,
     Consum,
     ConsumPrec &apos;||gUserFields||&apos;)
   select
     OBJ.DENUMIRE Articol,
     OBJ.CodIntern,
     CLSS.DEN_CLASEAS ClasaSt,
     CLS.DEN_CLASEA Clasa,
     UM.DEN_UM Um,
     NECOBJ.STOC - NECOBJ.REZERVAT Stoc,
     NEC.SAPTAMANA - 1 SetimanaPrec,
     NECOBJ.CF CmdFurnPrec,
     NEC.SAPTAMANA Setimana,
     NECOBJ.CFPER CmdFurn,
     NECOBJ.CFNEXT CmdFurnNext,
     NECOBJ.CF + NECOBJ.CFPER + NECOBJ.CFNEXT CmdFurnTot,
     NECOBJ.PlanifPrec,
     NECOBJ.PlanifPer,
     NECOBJ.Necesar Necesar1,
     NECOBJ.StocMin,
     CASE WHEN NECOBJ.Necesar &lt; NECOBJ.StocMin THEN NECOBJ.StocMin - NECOBJ.Necesar ELSE 0 END Necesar2,
     NECOBJ.Acceptat,
     NVL(CMDFNEC.CANT,0) CmdFurnNec,
     CASE WHEN NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0) &gt; 0 THEN NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0) ELSE 0 END Rest,
     NECOBJ.Acceptat * NECOBJ.PMP ValAcceptat,
     NECOBJ.PMP,
     NECOBJ.NECESAR * NECOBJ.PMP ValNecesar,
     UM1.DEN_UM Um1,
     round(CASE
       WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN NECOBJ.NECESAR/ART.D1
       WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN NECOBJ.NECESAR / (NVL(ART.D1,0) * NVL(ART.D2,0))
       WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN NECOBJ.NECESAR / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
       WHEN ART.RELATIEUM1 IN (4, 10) THEN NECOBJ.NECESAR * NVL(ART.D1,0)
       WHEN ART.RELATIEUM1 IN (5, 11) THEN NECOBJ.NECESAR * NVL(ART.D1, 0) * NVL(ART.D2, 0)
       WHEN ART.RELATIEUM1 IN (6, 12) THEN NECOBJ.NECESAR * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
     END,7),
     NECOBJ.AcceptatUM1,
     CASE WHEN NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0) &gt; 0 THEN
       round(CASE
         WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0))/ART.D1
         WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0)) / (NVL(ART.D1,0) * NVL(ART.D2,0))
         WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0)) / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
         WHEN ART.RELATIEUM1 IN (4, 10) THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0)) * NVL(ART.D1,0)
         WHEN ART.RELATIEUM1 IN (5, 11) THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0)) * NVL(ART.D1, 0) * NVL(ART.D2, 0)
         WHEN ART.RELATIEUM1 IN (6, 12) THEN (NECOBJ.Acceptat - NVL(CMDFNEC.CANT,0)) * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
       END,7)
       ELSE 0
     END RESTUM1,
     ART.D1,
     ART.D2,
     ART.D3,
     NECOBJ.Consum,
     NECOBJ.ConsumPrec &apos;||gUserAlias||&apos;
   from NECESAROBJ NECOBJ
    INNER JOIN NECESAR NEC ON NEC.CODNECESAR = NECOBJ.CODNECESAR
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NECOBJ.CODOBIECT
    INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
    INNER JOIN NUM UM ON ART.UM = UM.CODUM
    LEFT JOIN NUM UM1 ON ART.UM1 = UM1.CODUM
    LEFT JOIN NCLASEA CLS ON CLS.CODCLASEA = ART.CLASA
    LEFT JOIN NCLASEAS CLSS ON CLSS.CODCLASEAS = ART.CLASASTATIST
    LEFT JOIN (SELECT SUM(C1.CANTACCEPTAT - NVL(Storno.Cant,0)) CANT, C1.CODOBIECT
                FROM NECESARCMD NECCMD
                    INNER JOIN COMANDA C ON C.CODCOMANDA = NECCMD.CODCOMANDA
                    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = C.CODCOMANDA
                    LEFT  JOIN (SELECT SUM(L.CANT) CANT, CODLINIECOMANDA
                                FROM CMDLIVRLINK L
                                     INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
                                     INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
                                WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
                                GROUP BY CODLINIECOMANDA) STORNO ON STORNO.CodLINIECOMANDA = C1.CodComanda1
                WHERE NECCMD.CODNECESAR = &apos;||pCodNecesar||&apos;
                      and C.INCHISA = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8
                GROUP BY C1.CODOBIECT
                ) CMDFNEC ON CMDFNEC.CODOBIECT = NECOBJ.CODOBIECT&apos;||
    gSuplJoins||&apos;
   where NECOBJ.CODNECESAR = &apos;||pCodNecesar;

  FOR v_rec IN (
    SELECT
      TO_CHAR(NRDOC) nrdoc,
      SERIADOC,
      TO_CHAR(DATADOC,&apos;DD.MM.YYYY&apos;) datadoc,
      OBS,
      TO_CHAR(SAPTAMANA) saptamana,
      SUB.DEN_SUBUNIT subunitatea,
      TO_CHAR(VALPMP) valpmp,
      CASE TIPNECESAR
        WHEN 0 THEN &apos;Neafectat&apos;
        WHEN 1 THEN &apos;Stoc minim&apos;
        WHEN 2 THEN &apos;Stoc mediu&apos;
        WHEN 3 THEN &apos;Stoc maxim&apos;
      END AfectareNecesar
    FROM NECESAR NEC
         INNER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NEC.SUBUNITATEA
    WHERE NEC.CODNECESAR = pCodNecesar
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;NRDOC&apos;,       v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERIADOC&apos;,    v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATADOC&apos;,     v_rec.DATADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBS&apos;,         v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SAPTAMANA&apos;,   v_rec.SAPTAMANA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATEA&apos;, v_rec.SUBUNITATEA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALPMP&apos;,      v_rec.VALPMP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AFECTARE NECESAR&apos;, v_rec.AFECTARENECESAR);
    EXIT;
  END LOOP;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);

  Commit;
END;

end PKG_LIST_BASE_DOCNECESAR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCNEOPERATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3ED447F1DAD86E59715B86D46C2B7CEB587754C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCNEOPERATE IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);




PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(9000);
  vCondLuna VARCHAR2(200);
BEGIN
  gSuplCols := &apos;DOCCARNETE DC, tmp_lst_docneoperate da&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTLUNA.LunaStart = PKG_LIST_SELECTLUNA.LunaFin
  THEN vCondLuna := &apos; = &apos;||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaStart);
  ELSE vCondLuna := &apos; BETWEEN &apos;||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaStart)||
                    &apos; AND &apos;    ||to_char(PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaFin);
  END IF;

  delete tmp_lst_docneoperate;

  sInsert := &apos;INSERT INTO tmp_lst_docneoperate(CODDOC,TIPDOC,CARNETDOC,PREFIXDOC,NRDOC,DATADOC,SUBUNITATEA,SERIADOC,PART,VALDOC)
    SELECT I.CODINTR CODDOC, I.TIPDOC, I.CARNETDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.SUBUNITATEA, I.SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, I.VALDOC
    FROM INTRARI I
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.OPERAT = 0 AND I.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, I.CARNETDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.SUBUNITATEA, I.SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, I.VALDOC
    FROM IESIRI I
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.OPERAT = 0 AND I.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, T.CARNETDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, T.SUBUNITATEA, T.SERIADOC,
      G.DEN_GEST PART, T.VALDOC
    FROM  TRANSF T
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE T.OPERAT = 0 AND T.ANULAT = 0 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTREZOR CODDOC, T.TIPDOC, T1.CARNETDOC, T1.DOC PREFIXDOC, T1.NRDOC, T1.DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      DECODE(T1.OBIECTTRANZ,3,B.DENUMIRE||&apos;&apos; &apos;&apos;||BC.NRCONT,2,PERS.NUME|| &apos;&apos; &apos;&apos; || PERS.PRENUME,1,P.DEN_PART,0,P.DEN_PART,C.SIMBOL) PART, T1.VALDOC
    FROM  TREZOR1 T1
      INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
      LEFT JOIN GENERAL G ON G.TIPDOC = T.TIPDOC AND G.CODDOC = T1.CODTREZOR1
      LEFT JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = O.CODOBLIGPIF
      LEFT JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
      LEFT JOIN TREZOR1 TS1 ON TS1.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29,31)
      LEFT JOIN TREZOR TS ON TS.CODTREZOR = TS1.CODTREZOR
      LEFT JOIN NPART P ON P.CODPART = T1.CODPART AND T1.OBIECTTRANZ IN (0,1)
      LEFT JOIN NPERS PERS ON PERS.CODPERS = T1.CODPART AND T1.OBIECTTRANZ = 2
      LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = T1.CODPART AND T1.OBIECTTRANZ = 3
      LEFT JOIN NBANK B ON B.CODBANK = BC.CODBANK
      LEFT JOIN NCONT C ON C.CODCONT =
        CASE
          WHEN o.semnificatie IN (300,320) AND NVL(os.semnificatie, 0) = 500 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
          WHEN o.semnificatie IN (400,420) AND NVL(os.semnificatie, 0) = 600 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
          WHEN o.semnificatie IN (800,801) THEN To_Number(PKG_CATEGCONST.GETVALCONSTBYCODE(o.icont,t.an,t.luna))
          WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
          WHEN o.semnificatie = 1000 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(t.codbanca,t.an,t.luna))
          WHEN o.semnificatie IN (1100,1101) THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
          ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
        END
    WHERE T.OPERAT = 0 AND T1.ANULAT = 0 AND (T1.AN * 12 + T1.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODINTR CODDOC, I.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC
    FROM  NIR N
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE N.OPERAT = 0 AND N.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC
    FROM NIR N
      INNER JOIN IESIRI I ON I.CODIES = N.CODIES
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE N.OPERAT = 0 AND N.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, N.CARNETNIR CARNETDOC, NULL PREFIXDOC, N.NRNIR NRDOC, N.DATANIR DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      G.DEN_GEST PART, 0 VALDOC
    FROM NIR N
      INNER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE N.OPERAT = 0 AND N.ANULAT = 0 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODINTR CODDOC, I.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC
    FROM LIVR L
      INNER JOIN INTRARI I ON I.CODINTR = L.CODINTR
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE L.OPERAT = 0 AND L.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT I.CODIES CODDOC, I.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, I.SUBUNITATEA, NULL SERIADOC,
      DECODE(I.TIPDOC,23,S.DEN_SUBUNIT,24,G.DEN_GEST,P.DEN_PART) PART, 0 VALDOC
    FROM LIVR L
      INNER JOIN IESIRI I ON I.CODIES = L.CODIES
      LEFT JOIN NPART P ON P.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE L.OPERAT = 0 AND L.ANULAT = 0 AND (I.AN * 12 + I.LUNA) &apos;||vCondLuna||&apos;
    UNION ALL
    SELECT T.CODTRANSF CODDOC, T.TIPDOC, L.CARNETLIVR CARNETDOC, NULL PREFIXDOC, L.NRLIVR NRDOC, L.DATALIVR DATADOC, T.SUBUNITATEA, NULL SERIADOC,
      G.DEN_GEST PART, 0 VALDOC
    FROM LIVR L
      INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
      LEFT JOIN NGEST G ON G.CODGEST = T.CODGESTCMD
    WHERE L.OPERAT = 0 AND L.ANULAT = 0 AND (T.AN * 12 + T.LUNA) &apos;||vCondLuna;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos; (NAV_CodDoc, NAV_TipDoc, TIPDOC, SERDOC, PREFIXDOC, NRDOC, DATADOC, DENUMIRE, SERIE, SIMBOL, PART, VAL, SUBUNITATEA&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    DA.CODDOC, DA.TIPDOC, pkg_list_base_utils.decode_tipdoc(DA.TIPDOC), Nvl(DA.SERIADOC,DC.SERIE),
    DA.PREFIXDOC, DA.NRDOC, DA.DATADOC, DC.DENUMIRE, DC.SERIE, DC.SIMBOL, DA.PART, DA.VALDOC, S.DEN_SUBUNIT &apos;||gUserAlias||&apos;
  FROM tmp_lst_docneoperate da
    LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = DA.CARNETDOC
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = DA.SUBUNITATEA&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_DOCNEOPERATE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1988ED50CF6F1168F3F0E9AC8F4554CEB24F0D33</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCPLANIFPROD is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pCodPlanifProd NUMBER(20) default 0;

PROCEDURE setParams(aCodPlanifProd IN number) IS
BEGIN
  pCodPlanifProd := aCodPlanifProd;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sString  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;nartobj comp, nartobj prod,prodcomp ppc,IOART IOAP,planifnod nod&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;( Produs, Necesar, Component, UM, Cant, Pozitie, Nivel, ordine, obs, varianta&apos;||gUserFields||&apos;)
  select prod.denumire, pp1.necesar, comp.denumire, UM.den_um, nod.necesar, nod.Pozitie, nod.Nivel, substr(nod.indexparinte,5, length(nod.indexparinte)-3), mat.obs,
         case when nvl(pp1.cuproiect,0) = 1 and nvl(nodp.nodoriginal,0) = 0 then pr.versiune else pc.obs end&apos;||gUserAlias||&apos;
  from planifprod pp
    inner join planifprod1 pp1 on pp.codplanifprod = pp1.codplanifprod
    inner join planifnod nod on nod.codplanifprod1 = pp1.codplanifprod1 and nod.codplanifprod = pp.codplanifprod
    inner join planifnod nodp on nodp.codplanifnod = nod.nodoriginal
    inner join nartobj comp on nod.codobiect = comp.codobiect
    inner join nart art on comp.codarticol = art.codarticol
    inner join num um on um.codum = art.um
    inner join nartobj prod on pp1.codobiect = prod.codobiect
    inner join nart aprod on prod.codarticol = aprod.codarticol
    left join nartobjsubunit objsub on nod.codobiect = objsub.codobiect 
                                    and (objsub.codgest is null or objsub.codgest = 0)
                                    and objsub.subunitate = pkg_globals.getsubunitate
    left join nclasea cls on cls.codclasea = art.clasa
    left join prodmat mat on nod.codprodmat = mat.codmat
    left join prodcomp pc on pc.codprodcomp = nod.codreteta and pc.codprodcomp &gt; 0
    left join prodcomp ppc on ppc.codprodcomp = decode(nvl(nodp.codreteta,0),-1,nod.codreteta,nodp.codreteta) and ppc.codprodcomp &gt; 0
    left join proiect pr on pr.codproiect = nod.codreteta and pr.codproiect &gt; 0
    LEFT JOIN NARTIMPLICITE IMP ON Aprod.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = pp.subunitatea
    LEFT JOIN NARTOBJIMP OIMP ON PROD.CODOBIECT = OIMP.CODOBIECT AND OIMP.CODSUBUNIT = pp.subunitatea
    LEFT JOIN IOART IOAP ON IOAP.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN COALESCE(IMP.CONTIMPLICIT,0) ELSE COALESCE(OIMP.CONTIMPLICIT,0) END &apos;||
    gSuplJoins||&apos;
  where nvl(nod.nodoriginal, 0) &gt; 0  and nod.codplanifProd = &apos;||pCodPlanifProd;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);
  Commit;
END;

end PKG_LIST_BASE_DOCPLANIFPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0AC8F7B3F0D8EBC06A01206EC3D12056C98D093</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCPLATI IS

  vCodDoc PLATI.CODPLATA%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  aVal       number(20,7);
BEGIN
  gSuplCols := &apos;PLATI1 PL1, PLATI PL, INTRARI I, NPART P, NSUBUNIT S, NMONEDE M, NBANKCONT BC, NBANK B&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;;&apos;);

  PRC_AL_CHECK(&apos;NPERS1&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DenFurn, AdrFurn,
    PrefixDoc, NrDoc, ValDoc, SoldBuget, NodAnaliza, SimbolNodAnaliza,Termen,
    Valoare, ContDest, CodSWIFT, CodBnr, CodStatisticBNR, Curs&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    CASE
      WHEN P.CODPART &gt; 0 THEN P.DEN_PART
      WHEN PE.CODPERS &gt; 0 THEN PE.NUME||&apos;&apos; &apos;&apos;||PE.PRENUME
      WHEN C.CODCONT &gt; 0 THEN C.SIMBOL||&apos;&apos; - &apos;&apos;||C.DEN_CONT
    END, PL1.ADRESAFURN,
    CASE WHEN PL1.CodObligPIF = 0 THEN &apos;&apos;Plata in avans&apos;&apos; WHEN PL1.CodObligPIF = 1 THEN &apos;&apos;Avans decont&apos;&apos; WHEN PL1.CodObligPIF = 2 THEN &apos;&apos;Direct pe cont&apos;&apos; ELSE I.PREFIXDOC END PrefixDoc, I. NRDOC, COALESCE(O.VALOARE,PL1.VALOARE),
    PKG_PLATI.GetSoldBuget(Case when PL1.CodObligPIF in (0,1,2) then PL1.CodAnalizaNodx else O.CodAnalizaNod end,PL.An,PL.Luna, 0, 1) SoldBuget,
    NVL(AN.DENNOD, ANx.DENNOD) NodAnaliza,
    NVL(AN.SIMBOLNOD, ANx.SIMBOLNOD) SimbolNodAnaliza,
    O.TERMEN, PL1.VALOARE, PL1.CONTDEST, PL1.CODSWIFT, PL1.CODBNR, PL1.CODSTATISTICBNR, DECODE(NVL(PL.CURS,0),0,1,NVL(PL.CURS,0))&apos;||
    gUserAlias||&apos;
  FROM PLATI1 PL1
    LEFT JOIN PLATI      PL  ON PL.CODPLATA        = PL1.CODPLATA
    LEFT JOIN OBLIGPIF   O   ON O.CODOBLIGPIF      = PL1.CODOBLIGPIF
    LEFT JOIN ANALIZANOD AN  ON Nvl(O.CODOBLIGPIF,0) &gt; 10 and O.CODANALIZANOD = AN.CODANALIZANOD
    LEFT JOIN ANALIZANOD ANx ON PL1.CODANALIZANODx = ANx.CODANALIZANOD
    LEFT JOIN GENERAL    G   ON G.CODGENERAL       = O.CODGENERAL
    LEFT JOIN DVI            ON DVI.CODDVI         = G.CODDOC AND G.TIPDOC = 5
    LEFT JOIN INTRARI    I   ON I.TIPDOC           = G.TIPDOC AND I.CODINTR = Coalesce(G.CODDOC, DVI.CODINTR)
    LEFT JOIN NPART      P   ON P.CODPART          = COALESCE(O.CODPART, PL1.CODPART)
    LEFT JOIN NPERS      PE  ON PE.CODPERS         = PL1.CODPERS
    LEFT JOIN NCONT      C   ON C.CODCONT          = PL1.CODCONT
    LEFT JOIN NSUBUNIT   S   ON S.CODSUBUNIT       = COALESCE(I.SUBUNITATEA,PL.SUBUNITATEA)
    LEFT JOIN NMONEDE    M   ON M.CODMONEDA        = PL1.CODMONEDA
    LEFT JOIN NBANKCONT  BC  ON BC.CODBANKCONT     = PL.CODBANKCONT
    LEFT JOIN NBANK      B   ON B.CODBANK          = COALESCE(BC.CODBANK,PL1.CODBANK)&apos;||
    gSuplJoins||&apos;
  WHERE PL1.CODPLATA = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);



  FOR v_rec IN (
    SELECT TO_CHAR(DATA,&apos;DD.MM.YYYY&apos;) DATA, SERIE, TO_CHAR(NRDOC) NRDOC, NRCONT, Aprobat, Obs
    from (
    select distinct P.DATA, DC.SERIE, P.NRDOC, BK.NRCONT, Decode(P.APROBAT,1,&apos;DA&apos;,&apos;NU&apos;) Aprobat, P.Obs
    FROM PLATI P
      LEFT JOIN NBANKCONT  BK ON BK.CODBANKCONT = P.CODBANKCONT
      LEFT JOIN DOCCARNETE DC ON DC.CODCARNET   = P.CARNETDOC
      LEFT JOIN NBANK      B  ON BK.CODBANK     = B.CODBANK
    WHERE p.codplata = vCodDoC
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,            v_rec.serie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NR&apos;,               v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,             v_rec.data);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NRCONT&apos;,                    v_rec.nrcont);
    pkg_list_Struct.ADAUGA_PARAM(&apos;APROBAT&apos;,                   v_rec.aprobat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBS&apos;,                       v_rec.obs);
    EXIT;
  END LOOP;
  --BANCA
  FOR v_rec IN (
    SELECT STRAGG3200(SIMBOLB) SIMBOLB, STRAGG3200(DENUMIREB) DENUMIREB
    from (
    select distinct B.SIMBOL SIMBOLB, B.DENUMIRE DENUMIREB
    FROM PLATI P
      LEFT JOIN PLATI1    PL1 ON PL1.CODPLATA   = P.CODPLATA
      LEFT JOIN NBANKCONT BK  ON BK.CODBANKCONT = P.CODBANKCONT
      LEFT JOIN NBANK     B   ON BK.CODBANK     = B.CODBANK
    WHERE p.codplata = vCodDoc and PL1.CODPART &gt; 0
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA - SIMBOL&apos;,            v_rec.SIMBOLB);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA&apos;,                     v_rec.DENUMIREB);
    EXIT;
  END LOOP;
  --ARTICOLE
  FOR v_rec IN (
    SELECT stragg3200(articol) articol
    from (
    select DISTINCT OBJ.DENUMIRE ARTICOL
    FROM PLATI P
      LEFT JOIN PLATI1   PL1 ON PL1.CODPLATA  = P.CODPLATA
      LEFT JOIN OBLIGPIF O   ON O.CODOBLIGPIF = PL1.CODOBLIGPIF
      LEFT JOIN GENERAL  G   ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN INTRARI  I   ON I.CODINTR     = G.CODDOC AND I.TIPDOC = G.TIPDOC
      LEFT JOIN INTRARI1 I1  ON I.CODINTR     = I1.CODINTR
      LEFT JOIN NARTOBJ  OBJ ON I1.CODOBIECT  = OBJ.CODOBIECT
    WHERE p.codplata = vCodDoc and PL1.CODPART &gt; 0
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR ARTICOLE&apos;,         v_rec.ARTICOL);
    EXIT;
  END LOOP;
  --DOCUMENTE
  FOR v_rec IN (
    SELECT stragg3200(doc) doc, stragg3200(DEST) DEST
    from (
    select distinct I.SERIADOC||I.NRDOC||&apos;/&apos;||TO_CHAR(I.DATADOC,&apos;DD.MM.YYYY&apos;) DOC,
           Case when PL1.CODOBLIGPIF = 0 then P.DEN_PART
                when PL1.CODOBLIGPIF = 1 then PE.NUME || &apos; &apos;||PE.PRENUME
                when PL1.CODOBLIGPIF = 2 then C.Simbol
           end DEST
    FROM PLATI P
      LEFT JOIN PLATI1   PL1 ON PL1.CODPLATA  = P.CODPLATA
      LEFT JOIN OBLIGPIF O   ON O.CODOBLIGPIF = PL1.CODOBLIGPIF
      LEFT JOIN GENERAL  G   ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN INTRARI  I   ON I.CODINTR     = G.CODDOC AND I.TIPDOC = G.TIPDOC
      LEFT JOIN NPART    P   ON P.CODPART     = COALESCE(O.CODPART, PL1.CODPART)
      LEFT JOIN NPERS    PE  ON PE.CODPERS    = PL1.CODPERS
      LEFT JOIN NCONT    C   ON C.CODCONT     = PL1.CODCONT
    WHERE p.codplata = vCodDoc
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR DOCUMENTE&apos;,        v_rec.DOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DESTINATIE PLATA&apos;,          v_rec.DEST);
    EXIT;
  END LOOP;
  --PLATI PERSONAL
  FOR v_rec IN (
    SELECT stragg3200(DOCID) DOCID, stragg3200(FUNCTIE) FUNCTIE, stragg3200(BSIMBOL) BSIMBOL, stragg3200(BDENUMIRE) BDENUMIRE, stragg3200(CONTBANCA) CONTBANCA
    from (
    select DISTINCT PE.BISERIA||PE.BINR DOCID, B.SIMBOL BSIMBOL, B.DENUMIRE BDENUMIRE, PE.IBAN CONTBANCA, F.DENUMIRE FUNCTIE
    FROM PLATI P
      INNER JOIN PLATI1  PL1 ON PL1.CODPLATA = P.CODPLATA
      INNER JOIN NPERS   PE  ON PE.CODPERS   = PL1.CODPERS
      LEFT  JOIN NPERS1  PE1 ON PE1.CODPERS  = PE.CODPERS AND (P.AN*12+P.LUNA) BETWEEN PE1.ALStart and PE1.ALStop
      LEFT  JOIN FUNCTII F   ON F.CODFUNCTIE = PE1.CODFUNCTIE
      LEFT  JOIN NBANK   B   ON PE.CODBANK   = B.CODBANK
    WHERE p.codplata = vCodDoc
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANGAJAT ID&apos;,              v_rec.DOCID);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANGAJAT FUNCTIE&apos;,         v_rec.FUNCTIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANGAJAT BANCA SIMBOL&apos;,    v_rec.BSIMBOL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANGAJAT BANCA&apos;,           v_rec.BDENUMIRE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ANGAJAT CONT&apos;,            v_rec.CONTBANCA);
    EXIT;
  END LOOP;
  --VALORI
  FOR v_rec IN (
    SELECT stragg3200(TO_CHAR(VALOARE)) VALOARE, sum(valoare) val, DEN_MONEDA, SDENUMIRE, SIMBOL, CURS
    from (
    select PL1.VALOARE, M.DEN_MONEDA, M.SDENUMIRE, M.SIMBOL, DECODE(NVL(P.CURS,0),0,1,NVL(P.CURS,0)) CURS
    FROM PLATI P
      LEFT JOIN PLATI1          PL1 ON PL1.CODPLATA   = P.CODPLATA
      LEFT OUTER JOIN NBANKCONT BK  ON BK.CODBANKCONT = P.CODBANKCONT
      LEFT OUTER JOIN NMONEDE   M   ON BK.CODMONEDA   = M.CODMONEDA
      LEFT JOIN OBLIGPIF        O   ON O.CODOBLIGPIF  = PL1.CODOBLIGPIF
      LEFT JOIN GENERAL         G   ON G.CODGENERAL   = O.CODGENERAL
    WHERE p.codplata = vCodDoc
    )
    GROUP BY DEN_MONEDA, SDENUMIRE, SIMBOL, CURS
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE&apos;, v_rec.valoare);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;, v_rec.simbol);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CURS&apos;, TO_CHAR(v_rec.CURS,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL DE PLATA&apos;, TO_CHAR(v_rec.Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL DE PLATA LITERE&apos;,  NumarRO(Round(v_rec.val,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    EXIT;
  END LOOP;
  -- FURNIZORI
  FOR v_rec IN (
    SELECT stragg3200(den_part) den_part, stragg3200(CODFISCAL) CODFISCAL,
           stragg3200(REGCOM) REGCOM, stragg3200(ADRESAFURN) ADRESAFURN,
           stragg3200(NRCONTDEST) NRCONTDEST, stragg3200(LOCALITATE) LOCALITATE,
           stragg3200(SIMBOLBF) SIMBOLBF, stragg3200(DENUMIREBF) DENUMIREBF
    from (
    select distinct p.den_part, CF.CODFISCAL, P.REGCOM, PL1.ADRESAFURN,
           PB.CONTBANCA NRCONTDEST, LOC.DEN_LOCALIT LOCALITATE,
           BF.SIMBOL SIMBOLBF, BF.DENUMIRE DENUMIREBF
    FROM PLATI P
      LEFT JOIN PLATI1       PL1 ON PL1.CODPLATA   = P.CODPLATA
      LEFT JOIN NPART        P   ON P.CODPART      = PL1.CODPART
      LEFT JOIN NPARTCODFISC CF  ON CF.CODPART     = P.CODPART AND CF.PRINCIPAL = 1
      LEFT JOIN NPARTB       PB  ON PB.CODPART     = P.CODPART AND PB.IMPLICIT = 1
      LEFT JOIN NLOCALIT     LOC ON LOC.CODLOCALIT = PB.CODLOCALIT
      LEFT JOIN NBANK        BF  ON BF.CODBANK     = PB.CODBANK
    WHERE p.codplata = vCodDoc and PL1.CODPART &gt; 0
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR&apos;,                  v_rec.DEN_PART);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR COD FISCAL&apos;,       v_rec.CODFISCAL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR REG.COM.&apos;,         v_rec.REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR ADRESA&apos;,           v_rec.adresafurn);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR CONT BANCAR&apos;,      v_rec.NRCONTDEST);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR BANCA - SIMBOL&apos;,   v_rec.SIMBOLBF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR BANCA&apos;,            v_rec.DENUMIREBF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR LOCALITATE BANCA&apos;, v_rec.LOCALITATE);
    EXIT;
  END LOOP;
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;BCAREXT&apos;, &apos;CODBCAR&apos;, vCodDoc);

  COMMIT;
END;

END pkg_list_base_docplati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCPLATIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C46D83A37EEB3410FC81A0A8CCEFA805F886614</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCPLATIP IS

  vCodDoc number(20);
  vCodPart number(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN NUMBER, pCodPart IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
  vCodPart := pCodPart;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sDocLeg    VARCHAR2(2000);
BEGIN
  gSuplCols := &apos;PLATI1 PL1, PLATI PL, INTRARI I, NPART P, NSUBUNIT S, NMONEDE M, NBANKCONT BC, NBANK B&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DenFurn, AdrFurn,
    PrefixDoc, NrDoc, ValDoc, DataDoc, Termen,
    Valoare, ContDest, CodSWIFT, CodBnr, CodStatisticBNR&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    CASE
      WHEN P.CODPART &gt; 0 THEN P.DEN_PART
      WHEN PE.CODPERS &gt; 0 THEN PE.NUME||&apos;&apos; &apos;&apos;||PE.PRENUME
      WHEN C.CODCONT &gt; 0 THEN C.SIMBOL||&apos;&apos; - &apos;&apos;||C.DEN_CONT
    END, PL1.ADRESAFURN,
    CASE WHEN I.CODINTR IS NULL THEN &apos;&apos;Plata in avans&apos;&apos; ELSE I.PREFIXDOC END PrefixDoc, I. NRDOC, COALESCE(I.VALDOC,PL1.VALOARE), I.DataDoc, O.TERMEN,
    PL1.VALOARE, PL1.CONTDEST, PL1.CODSWIFT, PL1.CODBNR, PL1.CODSTATISTICBNR&apos;||
    gUserAlias||&apos;
  FROM PLATI1 PL1
    LEFT JOIN PLATI PL ON PL.CODPLATA = PL1.CODPLATA
    LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = PL1.CODOBLIGPIF
    LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
    LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5
    LEFT JOIN INTRARI I ON I.TIPDOC = G.TIPDOC AND I.CODINTR = Coalesce(G.CODDOC, DVI.CODINTR)
    LEFT JOIN NPART P ON P.CODPART = COALESCE(O.CODPART, PL1.CODPART)
    LEFT JOIN NPERS PE ON PE.CODPERS = PL1.CODPERS
    LEFT JOIN NCONT C ON C.CODCONT = PL1.CODCONT
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = COALESCE(I.SUBUNITATEA,PL.SUBUNITATEA)
    LEFT JOIN NMONEDE M ON M.CODMONEDA = PL1.CODMONEDA
    LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = PL.CODBANKCONT
    LEFT JOIN NBANK B ON B.CODBANK = COALESCE(BC.CODBANK,PL1.CODBANK)&apos;||
    gSuplJoins||&apos;
  WHERE PL1.CODPLATA = &apos;||vCodDoc||&apos; AND P.CODPART = &apos;||vCodPart;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT DATA, SERIE, NRDOC, MONEDA, NRCONT, Aprobat, SIMBOLB, DENUMIREB
    FROM  (
    SELECT DISTINCT PL.DATA, DC.SERIE, PL.NRDOC, M.SIMBOL MONEDA, BK.NRCONT, Decode(PL.APROBAT,1,&apos;DA&apos;,&apos;NU&apos;) Aprobat,
           B.SIMBOL SIMBOLB, B.DENUMIRE DENUMIREB
    FROM PLATI PL
         LEFT JOIN PLATI1 PL1 ON PL.CODPLATA = PL1.CODPLATA
         LEFT JOIN NBANKCONT BK ON BK.CODBANKCONT = PL.CODBANKCONT
         LEFT JOIN NMONEDE M ON BK.CODMONEDA = M.CODMONEDA
         LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = PL.CARNETDOC
         LEFT JOIN NBANK B ON BK.CODBANK = B.CODBANK
    WHERE PL.codplata = vCodDoc and PL1.CODPART = vCodPart)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,            v_rec.serie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NR&apos;,               v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,             v_rec.data);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NRCONT&apos;,                    v_rec.nrcont);
    pkg_list_Struct.ADAUGA_PARAM(&apos;APROBAT&apos;,                   v_rec.aprobat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA - SIMBOL&apos;,            v_rec.SIMBOLB);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BANCA&apos;,                     v_rec.DENUMIREB);
    EXIT;
  END LOOP;
  FOR v_rec IN (
    SELECT STRAGG3200(TO_CHAR(VALOARE)) VALOARE,
           STRAGG3200(DocLeg) DocLeg
    FROM  (
    SELECT DISTINCT PL1.VALOARE, CASE WHEN I.CODINTR IS NULL THEN &apos;Plata in avans&apos; ELSE I.PREFIXDOC END||I. NRDOC||&apos;/&apos;||to_char(I.DataDoc,&apos;dd.mm.yyyy&apos;) DocLeg
    FROM PLATI PL
         LEFT JOIN PLATI1 PL1 ON PL.CODPLATA = PL1.CODPLATA
         LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = PL1.CODOBLIGPIF
         LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
         LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5
         LEFT JOIN INTRARI I ON I.TIPDOC = G.TIPDOC AND I.CODINTR = Coalesce(G.CODDOC, DVI.CODINTR)
    WHERE PL.codplata = vCodDoc and PL1.CODPART = vCodPart)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE&apos;,                   v_rec.valoare);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Documente de legatura&apos;,     v_rec.DocLeg);
    EXIT;
  END LOOP;
  --FURNIZOR
  FOR v_rec IN (
    SELECT STRAGG3200(den_part) den_part, STRAGG3200(CODFISCAL) CODFISCAL,
           STRAGG3200(REGCOM) REGCOM, STRAGG3200(ADRESAFURN) ADRESAFURN,
           STRAGG3200(NRCONTDEST) NRCONTDEST, STRAGG3200(LOCALITATE) LOCALITATE,
           STRAGG3200(SIMBOLBF) SIMBOLBF, STRAGG3200(DENUMIREBF) DENUMIREBF
    FROM  (
    SELECT DISTINCT
           p.den_part, CF.CODFISCAL,
           P.REGCOM, PL1.ADRESAFURN,
           PB.CONTBANCA NRCONTDEST, LOC.DEN_LOCALIT LOCALITATE,
           BF.SIMBOL SIMBOLBF, BF.DENUMIRE DENUMIREBF
    FROM PLATI PL
         LEFT JOIN PLATI1 PL1 ON PL.CODPLATA = PL1.CODPLATA
         LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = PL1.CODOBLIGPIF
         LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
         LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5
         LEFT JOIN INTRARI I ON I.TIPDOC = G.TIPDOC AND I.CODINTR = Coalesce(G.CODDOC, DVI.CODINTR)
         LEFT JOIN NBANKCONT BK ON BK.CODBANKCONT = PL.CODBANKCONT
         LEFT JOIN NMONEDE M ON BK.CODMONEDA = M.CODMONEDA
         LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = PL.CARNETDOC
         LEFT JOIN NBANK B ON BK.CODBANK = B.CODBANK
         LEFT JOIN NPART P ON P.CODPART = PL1.CODPART
         LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
         LEFT JOIN NPARTB PB ON PB.CODPART = P.CODPART AND PB.IMPLICIT = 1
         LEFT JOIN NLOCALIT LOC ON LOC.CODLOCALIT = PB.CODLOCALIT
         LEFT JOIN NBANK BF ON BF.CODBANK = PB.CODBANK
    WHERE PL.codplata = vCodDoc and P.CODPART = vCodPart)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR&apos;,                  v_rec.den_part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR COD FISCAL&apos;,       v_rec.CODFISCAL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR REG.COM.&apos;,         v_rec.REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR ADRESA&apos;,           v_rec.adresafurn);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR CONT BANCAR&apos;,      v_rec.NRCONTDEST);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR BANCA - SIMBOL&apos;,   v_rec.SIMBOLBF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR BANCA&apos;,            v_rec.DENUMIREBF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FURNIZOR LOCALITATE BANCA&apos;, v_rec.LOCALITATE);
    EXIT;
  END LOOP;
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;BCAREXT&apos;, &apos;CODBCAR&apos;, vCodDoc);

  COMMIT;
END;

END pkg_list_base_docplatip;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCPRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18E8C8265BCBED305731B7D2076DE8E2C89221AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCPRODNET is

  vCodDoc NUMBER(20);
  vTip    number(1);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SetParams( aCodDoc IN NUMBER, aTip in number)  IS
BEGIN
  vCodDoc := aCodDoc;
  vTip    := aTip;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(32000);
BEGIN

  if vTip = 0 then
    gSuplCols := &apos;prodnet pn, prodnet1 pn1, comanda1 c1, nartobj obj, comanda c, iesiri1 i1, nartobj objmat, centrecost cc&apos;;
  else
    gSuplCols := &apos;prodnet pn, prodnet1 pn1, comanda1 c1, nartobj obj, comanda c, noper op, centrecost cc&apos;;
  end if;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if vTip = 0 then
    sInsert :=
    &apos;INSERT INTO &apos;||tmpname||&apos; (EXPLICATII, VALMAT, DIFCANT, CANTREAL, PRET, CANT, NRDOC, DATADOC, DENUMIRE, MATERIAL, CENTRU &apos;||gUserFields||&apos;)
    SELECT PN1.EXPLICATII, PN1.VALMAT, PN1.DIFCANT, PN1.CANTREAL, PN1.PRET, Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0), c.nrdoc, c.datadoc, obj.denumire, objmat.denumire, cc.simbol &apos;||gUserAlias||&apos;
    FROM PRODNET PN
      LEFT JOIN PRODNET1 PN1 ON PN1.CODPRODNET = PN.CODPRODNET
      LEFT join comanda1 c1 on pn1.coddoc1 = c1.codcomanda1
      LEFT join nartobj obj on c1.codobiect = obj.codobiect
      left join comanda c on c1.codcomanda = c.codcomanda
      left join iesiri1 i1 on pn1.codies1 = i1.codies1
      left join nartobj objmat on i1.codobiect = objmat.codobiect
      left  join centrecost cc on nvl(PN1.codcentru,0) = cc.codcentru&apos;||
      gSuplJoins||&apos;
    WHERE PN.codprodnet = &apos;||vCodDoc||&apos; AND nvl(PN1.Tip,0) = 0&apos;;
  else
    sInsert :=
    &apos;INSERT INTO &apos;||tmpname||&apos; (EXPLICATII, VALMAN, DIFCANT, CANTREAL, PRET, CANT, NRDOC, DATADOC, DENUMIRE, OPERATIE, CENTRU &apos;||gUserFields||&apos;)
    SELECT PN1.EXPLICATII, PN1.VALMAN, PN1.DIFCANT, PN1.CANTREAL, PN1.PRET, Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0), c.nrdoc, c.datadoc, obj.denumire, op.denumire, cc.simbol &apos;||gUserAlias||&apos;
    FROM PRODNET PN
      LEFT JOIN PRODNET1 PN1 ON PN1.CODPRODNET = PN.CODPRODNET
      LEFT join comanda1 c1 on pn1.coddoc1 = c1.codcomanda1
      LEFT join nartobj obj on c1.codobiect = obj.codobiect
      left join comanda c on c1.codcomanda = c.codcomanda
      left join cmdprodman man on man.codcmdprodman = pn1.codcmdprodmat
      left join noper op on op.codop = man.codop
      left  join centrecost cc on nvl(PN1.codcentru,0) = cc.codcentru&apos;||
      gSuplJoins||&apos;
    WHERE PN.codprodnet = &apos;||vCodDoc||&apos; AND nvl(PN1.Tip,0) = 1&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_docprodnet;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCPROFORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A01C9247D229382402CE41F75085394CEF1CC26</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCPROFORMA IS

  vCodDoc NUMBER(20);
  vNrDC   INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pListareDiscLangaTot  VARCHAR2(10);
  pListareLiniiDiscPart VARCHAR2(10);
  pListareUMAmbPretCant VARCHAR2(10);
  pBancaCursPUV         INTEGER;

PROCEDURE BAGA_DINAMIC_COLS IS
  vCursor  crs_cols  := get_cursor_coloane;
  vDen     VARCHAR2(30);
BEGIN
  DELETE tmp_dinamic_cols;

  LOOP
    FETCH vCursor INTO vDen;
    EXIT WHEN vCursor%NOTFOUND;
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+1,&apos;fm999&apos;), &apos;Cant.&apos;||vDen);
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+2,&apos;fm999&apos;), &apos;Pret/&apos;||vDen);
    vNrDC := vNrDC + 2;
  END LOOP;
  CLOSE vCursor;

  COMMIT;
END;

PROCEDURE SETPARAMS(pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
  pListareDiscLangaTot  := pkg_categconst.GetValConstanta(&apos;ListareDiscLangaTot&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareLiniiDiscPart := pkg_categconst.GetValConstanta(&apos;ListareLiniiDiscPart&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareUMAmbPretCant := pkg_categconst.GetValConstanta(&apos;ListareUMAmbPretCant&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pBancaCursPUV         := To_Number(pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru));

  vNrDC := 0;
  IF pListareUMAmbPretCant = &apos;1&apos; THEN
    BAGA_DINAMIC_COLS;
  END IF;
END;

FUNCTION get_cursor_coloane RETURN crs_cols IS
  crs crs_cols;
BEGIN
  OPEN crs FOR
    SELECT den_um1 || Decode(idxobj,1,NULL,&apos;(&apos;||idxobj||&apos;)&apos;) DEN
    FROM (
      SELECT Upper(U1.DEN_UM1) den_um1, Dense_Rank() OVER (PARTITION BY p1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
      FROM tmp_list_proforma1 p1
        INNER JOIN nartamb amb ON amb.codobiect = p1.codobiect
        INNER JOIN num1 u1 ON u1.codum1 = amb.umsec
      WHERE p1.codcomanda = vCodDoc
    )
    GROUP BY den_um1, idxobj
    ORDER BY den_um1, idxobj;

  RETURN crs;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
  sCondDiscP    VARCHAR2(  100);
  sInsertDC     VARCHAR2(10000);
  sSelectDC     VARCHAR2(10000);
  sJoinDC       VARCHAR2(10000);
  sCurs         VARCHAR2(  100);
  vMoneda       INTEGER;
  sDataDoc      VARCHAR2(   10);

  SitV          VARCHAR2(2);
  aSitV         NUMBER(1);
  aBancaV       NUMBER(20);
  aMonedaV      NUMBER(20);

  vCantBuc      NUMBER;
  vCantCut      NUMBER;
  vGSpCut       NUMBER;
  vCantPal      NUMBER;

  vVal          NUMBER;
  vTva          NUMBER;
  vValDisc      NUMBER;
  vTvaDisc      NUMBER;

  vLeiVal       NUMBER;
  vLeiTva       NUMBER;
  vLeiValDisc   NUMBER;
  vLeiTvaDisc   NUMBER;

  vCurs         NUMBER;
  vPA           NUMBER;
  vROTEFACT     NUMBER;
  vROUND        NUMBER;
  sCotaTVA      VARCHAR2(3200);

  vNrTerm       NUMBER := 12;
  aModulCereale NUMBER :=  2;
BEGIN
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  gSuplCols :=
    &apos;tmp_list_proforma1 p1, comanda com, comanda1 com1, nartobj nao, nartobj1 nao1, nart na, num1 um, num um1, num um2, nclasea c, nclaseas cs, npart prod, nartcli ac, nechiv e, grechiv gre,&apos;||
    &apos;nagenda nag, nlocalit nloc, ntari ntari, nartobjtrad ntrad&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,      &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,      &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_NARTATR_LST&apos;, &apos;TAA&apos;,  &apos;TAA.CODARTICOL = NA.CODARTICOL&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pListareLiniiDiscPart &lt;&gt; 1 THEN
    sCondDiscP := &apos;
      AND NOT p1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)&apos;;
  END IF;

  SELECT
    Coalesce(c.Moneda,0), To_Char(c.DataDoc,&apos;dd.mm.yyyy&apos;), c.Curs,
    CASE WHEN UPPER(SubStr(trim(cf.codfiscal),1,2)) = &apos;RO&apos; AND pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos; THEN 1 ELSE 2 END
  INTO
    vMoneda, sDataDoc, vCurs,
    aModulCereale
  FROM comanda c LEFT JOIN npartcodfisc cf ON cf.cod_codfiscal = c.codfiscal
  WHERE c.codcomanda = vCodDoc;

  IF vMoneda = 0
  THEN vCurs := 1;
  ELSIF vCurs IS NULL THEN vCurs := pkg_monede.getcursmoneda(vMoneda, pBancaCursPUV, sDataDoc);
  END IF;

  IF Coalesce(vCurs, 0) = 0
  THEN vCurs := 1;
  END IF;

  sCurs := To_Char(vCurs,&apos;FM9999999999999D9999999&apos;, &apos;NLS_NUMERIC_CHARACTERS = &apos;&apos;.,&apos;&apos;&apos;);

  IF vNrDC &gt; 0 THEN
    FOR k IN 1..vNrDC LOOP
      sInsertDC := sInsertDC||&apos;, D&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    FOR k IN 1..vNrDC/2 LOOP
      sJoinDC   := sJoinDC   ||&apos;, Max(Decode(idx,&apos;||to_char(k,&apos;fm999&apos;)||&apos;,p)) p&apos;||to_char(k,&apos;fm999&apos;);
      sSelectDC := sSelectDC ||&apos;, p1.cant*p1.paritate/dc.p&apos;||to_char(k,&apos;fm999&apos;)||&apos;, p1.pu/p1.paritate*dc.p&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    sJoinDC := &apos;
    LEFT JOIN (
      SELECT codobiect&apos;||sJoinDC||&apos;
      FROM (
        SELECT codobiect, den_um1, idxobj, p, Dense_Rank() OVER (ORDER BY den_um1, idxobj) idx
        FROM (
          SELECT DISTINCT p1.CODOBIECT, Upper(U1.DEN_UM1) den_um1, u1.paritate p, Dense_Rank() OVER (PARTITION BY p1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
          FROM tmp_list_proforma1 p1
            INNER JOIN nartamb amb ON amb.codobiect = p1.codobiect
            INNER JOIN num1    u1  ON u1.codum1     = amb.umsec
          WHERE p1.codcomanda = &apos;||vCodDoc||&apos;)
      ) GROUP BY codobiect
    ) DC ON dc.codobiect = p1.codobiect&apos;;

  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, OBSART, CANT, CodIntern,CodExtern,Producator,Masa,Volum,CodVamal,
    PRET, PU, PD, VAL, VALADAOS,
    PRET_LEI, PU_LEI, PD_LEI,
    VAL_LEI, VALADAOS_LEI,
    PROCADAOS,PROCDISC,
    PROCTVA,
    GARART, DenClasaA, SimbClasaA, UM1, CANT1, TipSerie,
    DiscAfis, ARTCli, CodExtCli,
    CodListat,
    DenClaseAS, IDX,
    Dim, Dim1, Dim2, Dim3,
    CantUMPrinc, CutiePar, CutieExt, CutieGSp, PaletPar &apos;||sInsertDC||gUserFields||&apos;)&apos;;

  -- liniile de pe iesiri
  sSelect := &apos;
  WITH UMCP AS (
    SELECT codcomanda1, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,upar)) cutiepar, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,aext)) cutieext, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;&apos;PALET&apos;&apos;,upar)) paletpar
    FROM (
      SELECT
        c1.codcomanda1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
        Dense_Rank() OVER (PARTITION BY c1.codcomanda1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = c1.umsec THEN 0 ELSE u1.paritate END) idxobj
      FROM COMANDA1 C1
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = C1.CODOBIECT
        INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
      WHERE C1.CODCOMANDA = &apos;||vCodDoc||&apos; AND Upper(U1.codextern) IN (&apos;&apos;CUTIE&apos;&apos;,&apos;&apos;PALET&apos;&apos;)
    )
    WHERE idxobj = 1
    GROUP BY codcomanda1)
  SELECT
    p1.DenObiect, p1.denum, p1.obs, p1.cant, nao.codintern, nao.codextern, prod.den_part, nao.masa, nao.volum, nao.codvamal,
    p1.pretorig, p1.pu, p1.pretorig * p1.coefdiscmaj, p1.valoare, (p1.pu - p1.pretorig) * p1.cant,
    PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pretorig*&apos;||sCurs||&apos;),
    PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pu*&apos;||sCurs||&apos;),
    PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pretorig * p1.coefdiscmaj*&apos;||sCurs||&apos;),
    PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pu*&apos;||sCurs||&apos;)* p1.cant,
    (PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pu*&apos;||sCurs||&apos;) - PKG_PRETURI.WMROTOPRET(Coalesce(nao.rotvaluta, 0), p1.pretorig*&apos;||sCurs||&apos;)) * p1.cant,
    DECODE(p1.pretorig,0,0,(p1.pu - p1.pretorig)*100/p1.pretorig), p1.procdisc,
    p1.proctva,
    nao.lunigarantie, c.den_clasea, c.simbol, um1.den_um, p1.cantum1, decode(na.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;),
    Decode(Coalesce(p1.procdisc,0),0,&apos;&apos; &apos;&apos;,to_char(p1.procdisc)||&apos;&apos;%&apos;&apos;), Coalesce(ac.denumire,nao.denumire), Coalesce(ac.codextern, nao.codextern),
    Coalesce(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),
    cs.den_claseas, p1.indexlocal,
    decode(
      na.relatieum1,
      1,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / &apos;&apos;||com1.d1,
      2,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos;)&apos;&apos;,
      3,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos; x &apos;&apos;||com1.d3||&apos;&apos;)&apos;&apos;,
      4,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||com1.d1,
      5,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2,
      6,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos; x &apos;&apos;||com1.d3,
      7,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||com1.d1,
      8,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2,
      9,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos; x &apos;&apos;||com1.d3,
      10,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / &apos;&apos;||com1.d1,
      11,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / (&apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos;)&apos;&apos;,
      12,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / (&apos;&apos;||com1.d1||&apos;&apos; x &apos;&apos;||com1.d2||&apos;&apos; x &apos;&apos;||com1.d3||&apos;&apos;)&apos;&apos;
    ),
    com1.d1, com1.d2, com1.d3,
    com1.cantcomandat cantumprinc, umcp.cutiepar, umcp.cutieext, umcp.cutiegsp, umcp.paletpar &apos;||sSelectDC||gUserAlias||&apos;
  FROM tmp_list_proforma1 p1
    INNER JOIN comanda     com   ON com.codcomanda   = p1.codcomanda
    LEFT  JOIN comanda1    com1  ON com1.codcomanda1 = p1.codcomanda1
    LEFT  JOIN nartobj     nao   ON nao.codobiect    = p1.codobiect
    LEFT  JOIN nart        na    ON na.codarticol    = nao.codarticol
    LEFT  JOIN num1        um    ON um.codum1        = p1.umsec
    LEFT  JOIN num               ON num.codum        = na.um
    LEFT  JOIN num         um1   ON um1.codum        = na.um1
    LEFT  JOIN num         um2   ON um2.codum        = na.um2
    LEFT  JOIN nclasea     c     ON c.codclasea      = na.clasa
    LEFT  JOIN nclaseas    cs    ON cs.codclaseas    = na.clasastatist
    LEFT  JOIN npart       prod  ON prod.codpart     = nao.codproducator
    LEFT  JOIN oferta1     o1    ON o1.codoferta1    = p1.codsursa
    LEFT  JOIN nartcli     ac    ON ac.codobiect     = p1.codobiect AND ac.codpart = com.partener
    LEFT  JOIN nechiv      e     ON e.codobiect      = p1.codobiect
    LEFT  JOIN grechiv     gre   ON gre.codgrechiv   = e.codgrupa
    LEFT  JOIN umcp              ON umcp.codcomanda1 = p1.codcomanda1
    LEFT  JOIN nagenda     nag   ON nag.codagenda    = com.codlocatie
    LEFT  JOIN nlocalit    nloc  ON nag.codlocalit   = nloc.codlocalit
    LEFT  JOIN ntari             ON ntari.codtara    = nloc.codtara
    LEFT  JOIN nartobjtrad ntrad ON ntrad.codlimba   = ntari.codlimba and ntrad.codobiect = nao.codobiect
    LEFT  JOIN nartobj1    nao1  ON nao1.codobiect   = p1.codobiect   AND (com.an*12+com.luna) BETWEEN nao1.ALStart and nao1.ALStop &apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE p1.codcomanda =&apos;||vCodDoc||sCondDiscP||&apos;
  ORDER BY p1.indexlocal&apos;;

  IF InStr(Upper(gSuplJoins),&apos;TMP_NARTATR_LST&apos;) &gt; 0 THEN
    pkg_globals.SetSeparator(&apos;;&apos;);
    PKG_LIST_BASE_UTILS.UMPLE_TMP_NARTATR_LST;
  END IF;

  PKG_GLOBALS.SetSeparator(&apos;, &apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  WITH UMCP AS (
    SELECT codcomanda1, Max(Decode(uext,&apos;CUTIE&apos;,upar)) cutiepar, Max(Decode(uext,&apos;CUTIE&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;PALET&apos;,upar)) paletpar
    FROM (
      SELECT
        c1.codcomanda1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
        Dense_Rank() OVER (PARTITION BY c1.codcomanda1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = c1.umsec THEN 0 ELSE u1.paritate END) idxobj
      FROM COMANDA1 C1
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = C1.CODOBIECT
        INNER JOIN NUM1 U1 ON U1.CODUM1 = AMB.UMSEC
      WHERE C1.CODCOMANDA = vCodDoc AND Upper(U1.codextern) IN (&apos;CUTIE&apos;,&apos;PALET&apos;)
    )
    WHERE idxobj = 1
    GROUP BY codcomanda1)
  SELECT
    Coalesce(CEIL(SUM(Coalesce(c1.cantcomandat,0))),0), 
    Coalesce(CEIL(SUM(Coalesce(c1.cantcomandat/UMCP.CutiePar,0))),0), 
    Coalesce(Round(SUM(Coalesce(c1.cantcomandat*UMCP.CutieGSp/UMCP.CutiePar,0))),0), 
    Coalesce(CEIL(SUM(Coalesce(c1.cantcomandat/UMCP.PaletPar,0))),0),
    C.PRETCUAMANUNT, C.ROTEFACT
  INTO vCantBuc, vCantCut, vGSpCut, vCantPal, vPA, vROTEFACT
  FROM COMANDA1 C1
    INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
    LEFT  JOIN UMCP      ON UMCP.codcomanda1 = c1.codcomanda1
  WHERE c1.codcomanda = vCodDoc
  GROUP BY C.PRETCUAMANUNT, C.ROTEFACT;

  IF vROTEFACT = 1 
  THEN vROUND := 2;
  ELSE vROUND := 7;
  END IF;
     
  SELECT
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        WHEN C.PRETCUAMANUNT = 1 THEN T.VALOARE/(1+Coalesce(t.proctva,0)/100)
        ELSE t.valoare
      END, vROUND) 
    ) Val,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL THEN 0
        WHEN C.PRETCUAMANUNT = 1 THEN T.VALOARE - T.VALOARE/(1+Coalesce(t.proctva,0)/100)
        ELSE t.valoare*Coalesce(t.proctva,0)/100
      END, vROUND)
    ) TVA,
    Sum(Round(
      CASE WHEN C.PRETCUAMANUNT = 1 THEN T.VALOARE/(1+Coalesce(t.proctva,0)/100) ELSE t.valoare END * 
      CASE WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 1 ELSE 1+Coalesce(t.procdisc/100,0) END,
      vROUND)
    ) ValDisc,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL THEN 0
        ELSE CASE WHEN C.PRETCUAMANUNT = 1 THEN t.pretorig/(1+Coalesce(t.proctva,0)/100) ELSE t.pretorig END *t.cant*Coalesce(t.proctva,0)/100*Coalesce(t.CoefDiscMaj,1)
      END, vROUND)
    ) TVADisc,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        ELSE PKG_PRETURI.WMROTOPRET(Coalesce(o.rotvaluta, 0), CASE WHEN C.PRETCUAMANUNT = 1 THEN t.pu/(1+Coalesce(t.proctva,0)/100)      ELSE t.pu END*vCurs)*t.cant
      END, vROUND)
    ) LeiVal,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL THEN 0
        ELSE PKG_PRETURI.WMROTOPRET(Coalesce(o.rotvaluta,0), CASE WHEN C.PRETCUAMANUNT = 1 THEN t.pretorig/(1+Coalesce(t.proctva,0)/100) ELSE t.pretorig END*vCurs)*t.cant*Coalesce(t.proctva,0)/100
      END, vROUND)
    ) LeiTVA,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) 
        THEN PKG_PRETURI.WMROTOPRET(Coalesce(o.rotvaluta,0),CASE WHEN C.PRETCUAMANUNT = 1 THEN t.valoare/(1+Coalesce(t.proctva,0)/100) ELSE t.valoare END*vCurs)
        ELSE PKG_PRETURI.WMROTOPRET(Coalesce(o.rotvaluta,0),CASE WHEN C.PRETCUAMANUNT = 1 THEN t.pu     /(1+Coalesce(t.proctva,0)/100) ELSE t.pu      END*vCurs)*t.cant*(1+Coalesce(t.procdisc/100,0))
      END, vROUND)
    ) LeiValDisc,
    Sum(Round(
      CASE
        WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0
        WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL THEN 0
        ELSE PKG_PRETURI.WMROTOPRET(Coalesce(o.rotvaluta,0),CASE WHEN C.PRETCUAMANUNT = 1 THEN t.pretorig/(1+Coalesce(t.proctva,0)/100) ELSE t.pretorig END*vCurs)*t.cant*Coalesce(t.proctva,0)/100*Coalesce(t.CoefDiscMaj,1)
      END, vROUND)
    ) LeiTVADisc,
    vc2_nt_to_vc3200_dist(CAST(COLLECT(To_Char(t.proctva) ORDER BY Coalesce(t.proctva,0)) AS vc2_nt)) CotaTVA
  INTO
    vVal,
    vTva,
    vValDisc,
    vTvaDisc,
    vLeiVal,
    vLeiTva,
    vLeiValDisc,
    vLeiTvaDisc,
    sCotaTVA
  FROM tmp_list_proforma1 t
    INNER JOIN COMANDA C ON T.CODCOMANDA = C.CODCOMANDA
    LEFT  JOIN nartobj o ON o.codobiect = t.codobiect;

  --vTvaDisc    := CASE WHEN vVal    = 0 OR vValDisc    =0 OR vTva    = 0 THEN 0 ELSE vValDisc    * vTva    / vVal    END;
  --vLeiTvaDisc := CASE WHEN vLeiVal = 0 OR vLeiValDisc =0 OR vLeiTva = 0 THEN 0 ELSE vLeiValDisc * vLeiTva / vLeiVal END;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN SitV := &apos;DA&apos;;
  ELSE SitV := &apos;NU&apos;;
  END IF;

  FOR v_rec IN (
    SELECT
      C.CODIES, C.TIPDOC, C.NRDOC, C.DATADOC, C.SERIADOC, C.CURS, C.CODLOCATIE, C.NRI,
      C.AGENT, C.DELEGAT, C.OBS, CODF.CODFISCAL, P.DEN_PART, P.CODEXTERN, P.CODSTATISTICBNR,
      Decode(P.PERSOANAFIZICA,1,NULL,P.REGCOM) REGCOM, P.PERSOANAFIZICA, P.CODPART, P.AUTORIZATIE, M.CODMONEDA, M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE, C.USERID,
      Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      Decode(P.PERSOANAFIZICA,1,TR.SerieDoc,NULL) PFSerieDoc, Decode(P.PERSOANAFIZICA,1,TR.NrDoc,NULL) PFNrDoc,
      SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.EMAIL SLIVREmail,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
      LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
      SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.EMAIL SSOCEmail,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
      LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
      B.CONTBANCA, B.SUCURSALA, BK.DENUMIRE DENBANCA, BK.SIMBOL SIMBBANCA,
      AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
      DEL.DELegat DelNume, DEL.DOC DelDoc, DEL.NRdoc DelNrDoc, DEL.SERIedoc DelSerDoc, DEL.ELIBERAT DelElib, DEL.CNP DelCNP,
      DEL.MIJLTRANSP DelMTransp, DEL.NRTRANSP DelNrTransp, DEL.DATADoc DelDataDoc,
      case when p.persoanafizica = 1 then p.den_part else PC.Nume||&apos; &apos;||PC.Prenume end PCNume,
      case when p.persoanafizica = 1 then slivr.telefon else PC.TELEFON end PCTel,
      case when p.persoanafizica = 1 then slivr.email else PC.EMAIL end PCEmail,
      (SELECT Count(1) FROM IESIRI1 I1 WHERE i1.codies = C.codies) NrLinii,
      CASE WHEN Coalesce(aMonedaV,0) = 0 OR Coalesce(aBancaV,0) = 0 THEN 1 ELSE PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMonedaV,aBancaV,C.datadoc) END CursSitV,
      (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = Coalesce(aMonedaV,0)) MonedaSitV,
      (SELECT DENUMIRE FROM NBANK WHERE CODBANK = Coalesce(aBancaV,0)) BancaSitV,
      (select listagg(&apos; &apos;||i.prefixdoc||to_char(i.nrdoc)||&apos;/&apos;||to_char(i.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||TO_CHAR(i.valdoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;), &apos;;&apos;)
       WITHIN GROUP (ORDER BY i.datadoc) from iesiri i, cmdavans l where i.codies = l.codiesavans and l.codcomanda = c.codcomanda) factav,
      (select sum(i.valdoc) from iesiri i, cmdavans l where i.codies = l.codiesavans and l.codcomanda = c.codcomanda) valav
    FROM COMANDA C
      INNER JOIN NPART        P     ON P.CODPART        = C.PARTENER
      INNER JOIN NMONEDE      M     ON M.CODMONEDA      = Coalesce(C.MONEDA,0)
      LEFT  JOIN NPARTCODFISC CODF  ON CODF.COD_CODFISCAL = C.CODFISCAL
      LEFT  JOIN NPERS        U     ON U.LOGONNAME      = C.USERID
      LEFT  JOIN NPARTTR      TR    ON TR.CODPARTTR     = C.DELEGAT
      LEFT  JOIN NAGENDA      SLIVR ON SLIVR.CODAGENDA  = C.CODLOCATIE AND SLIVR.CODPART = C.PARTENER
      LEFT  JOIN NLOCALIT     LLIVR ON LLIVR.CODLOCALIT = Coalesce(SLIVR.CODLOCALIT, 0)
      LEFT  JOIN NJUDET       JLIVR ON JLIVR.CODJUDET   = Coalesce(LLIVR.CODJUDET, 0)
      LEFT  JOIN NTARI        TLIVR ON TLIVR.CODTARA    = Coalesce(LLIVR.CODTARA, 0)
      LEFT  JOIN NAGENDA      SSOC  ON SSOC.CODPART     = C.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
      LEFT  JOIN NLOCALIT     LSOC  ON LSOC.CODLOCALIT  = Coalesce(SSOC.CODLOCALIT, 0)
      LEFT  JOIN NJUDET       JSOC  ON JSOC.CODJUDET    = Coalesce(LSOC.CODJUDET, 0)
      LEFT  JOIN NTARI        TSOC  ON TSOC.CODTARA     = Coalesce(LSOC.CODTARA, 0)
      LEFT  JOIN NPARTB       B     ON B.CODPART        = P.CODPART AND B.IMPLICIT = 1
      LEFT  JOIN NBANK        BK    ON B.CODBANK        = BK.CODBANK
      LEFT  JOIN NPERS        AG    ON AG.CODPERS       = C.AGENT
      LEFT  JOIN NPARTTR      DEL   ON DEL.CODPARTTR    = C.DELEGAT
      LEFT  JOIN NPERSCONTACT PC    ON PC.CodPersC      = C.CodPersC
    WHERE c.codcomanda = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,                v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,              v_rec.Autorizatie);
    if v_rec.persoanafizica = 1 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL&apos;,            &apos;&apos;);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CNP&apos;,                  v_rec.CodFiscal);
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL&apos;,            v_rec.CodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CNP&apos;,                  &apos;&apos;);
    end if;
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,          v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD STATISTIC BNR&apos;,        v_rec.CodStatisticBNR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,                  v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE&apos;,                    NumarRO(Round(vVal,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE ENG&apos;,                NumarUK(Round(vVal,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA&apos;,                    TO_CHAR(vVal+vTva,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA LITERE&apos;,             NumarRO(Round(vVal+vTva,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA LITERE ENG&apos;,         NumarUK(Round(vVal+vTva,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(vTVA,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(vTVA,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC&apos;,                   TO_CHAR(vValDisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC LITERE&apos;,            NumarRO(Round(vValDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC LITERE ENG&apos;,        NumarUK(Round(vValDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA&apos;,            TO_CHAR(Round(vValDisc,2)+round(vTvaDisc,2),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LITERE&apos;,     NumarRO(Round(vValDisc,2)+round(vTvaDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LITERE ENG&apos;, NumarUK(Round(vValDisc,2)+round(vTvaDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA&apos;,               TO_CHAR(vTVADisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LITERE&apos;,        NumarRO(Round(vTVADisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LITERE ENG&apos;,    NumarUK(Round(vTVADisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CURS&apos;,                     TO_CHAR(vCurs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI&apos;,                TO_CHAR(vLeiVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE&apos;,      NumarRO(Round(vLeiVal,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vLeiVal,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI&apos;,             TO_CHAR(round(vLeiVal,2)+round(vLeiTva,2),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI LITERE&apos;,      NumarRO(Round(vLeiVal,2)+round(vLeiTva,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI LITERE ENG&apos;,  NumarUK(Round(vLeiVal,2)+round(vLeiTva,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI&apos;,                TO_CHAR(vLeiTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE&apos;,      NumarRO(Round(vLeiTVA,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vLeiTVA,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI&apos;,           TO_CHAR(vLeiValDisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI LITERE&apos;,    NumarRO(Round(vLeiValDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI ENG&apos;,       NumarUK(Round(vLeiValDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI&apos;,        TO_CHAR(round(vLeiValDisc,2)+round(vLeiTvaDisc,2),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI LITERE&apos;, NumarRO(Round(vLeiValDisc,2)+round(vLeiTvaDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI ENG&apos;,    NumarUK(Round(vLeiValDisc,2)+round(vLeiTvaDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI&apos;,           TO_CHAR(vLeiTVADisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI LITERE&apos;,    NumarRO(Round(vLeiTVADisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI ENG&apos;,       NumarUK(Round(vLeiTVADisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL FACT.VALUTA IN LEI&apos;,        TO_CHAR(vLeiVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN BUCATI&apos;,       TO_CHAR(vCantBuc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN CUTII&apos;,        TO_CHAR(vCantCut,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL GREUTATE SPECIFICA CUTII&apos;,  TO_CHAR(vGSpCut, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN PALETI&apos;,       TO_CHAR(vCantPal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;COTA TVA&apos;,                        sCotaTVA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERIE CARTE IDENTITATE&apos;,          v_rec.PFSerieDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR CARTE IDENTITATE&apos;,          v_rec.PFNrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
    if v_rec.tipdoc = 18 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;AVANS&apos;,                           v_rec.factav);
      pkg_list_Struct.ADAUGA_PARAM(&apos;AVANS VALOARE TOTALA&apos;,            TO_CHAR(coalesce(v_rec.valav,0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT REST NEF.AVANS&apos;,         TO_CHAR((Round(vValDisc,2)+round(vTvaDisc,2))-coalesce(v_rec.valav,0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    end if;    
    for v_sfact in (select SFACT.OBS SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.CODPOSTAL SFACTCodPostal, SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, SFACT.EMAIL SFACTEmail,
                           GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
                           LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara
                    from nagenda sfact
                         LEFT  JOIN NLOCALIT     LFACT ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
                         LEFT  JOIN NJUDET       JFACT ON JFACT.CODJUDET   = Coalesce(LFACT.CODJUDET, 0)
                         LEFT  JOIN NTARI        TFACT ON TFACT.CODTARA    = Coalesce(LFACT.CODTARA, 0)
                    where sfact.codpart = v_rec.codpart and sfact.sediusocial in (2,3,6,7)
                    order by codagenda) loop
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE&apos;,        v_sfact.SFactObs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,          v_sfact.SFactAdresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATE&apos;,      v_sfact.SFactLocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,         v_sfact.SFactTelefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,           v_sfact.SFactEmail);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDET&apos;,           v_sfact.SFactSimbAuto);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,  v_sfact.SFactJudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD POSTAL&apos;,      v_sfact.SFactCodPostal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD FISCAL&apos;,      v_sfact.SFactCodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD LA CLIENT&apos;,   v_sfact.SFactCodClient);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,            v_sfact.SFactTara);
      exit;
    end loop;
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.SSocObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.SSocAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.SSocLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.SSocTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,              v_rec.SSocEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SSocSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.SSocJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.SSocCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.SSocCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.SSocCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.SSocTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;,                     v_rec.ContBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;,                    v_rec.DenBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;,             v_rec.SimbBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SUCURSALA BANCA&apos;,          v_rec.Sucursala);
    IF pkg_categconst.GetValConstanta(&apos;GetSoldListFact&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = &apos;1&apos;
    THEN pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                TO_CHAR(PKG_LIST_BASE_UTILS.GetSoldPart(v_rec.CodPart, v_rec.CodLocatie) ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    ELSE pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                &apos;0&apos;);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.ANUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                       v_rec.ACNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                        v_rec.ABI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,               v_rec.DelNume);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,           v_rec.DelCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,              v_rec.DelDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,          v_rec.DelNRdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,        v_rec.DelSerDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,          v_rec.DelElib);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,        To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                   v_rec.DelMTransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,             v_rec.DelNrTransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,             v_rec.PCNume);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT TELEFON&apos;,     v_rec.PCTel);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT EMAIL&apos;,       v_rec.PCEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA&apos;         ,      SitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - MONEDA&apos;,      v_rec.MonedaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - BANCA&apos; ,      v_rec.BancaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - CURS&apos;  ,      TO_CHAR(v_rec.CursSitV,&apos;fm9G999G999G990D0000&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      Max(CASE WHEN Idx =  1 THEN Den ELSE NULL END) Den1,
      Max(CASE WHEN Idx =  1 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val1,
      Max(CASE WHEN Idx =  2 THEN Den                                                                ELSE NULL END) Den2,
      Max(CASE WHEN Idx =  2 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val2,
      Max(CASE WHEN Idx =  3 THEN Den                                                                ELSE NULL END) Den3,
      Max(CASE WHEN Idx =  3 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val3,
      Max(CASE WHEN Idx =  4 THEN Den                                                                ELSE NULL END) Den4,
      Max(CASE WHEN Idx =  4 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val4,
      Max(CASE WHEN Idx =  5 THEN Den                                                                ELSE NULL END) Den5,
      Max(CASE WHEN Idx =  5 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val5,
      Max(CASE WHEN Idx =  6 THEN Den                                                                ELSE NULL END) Den6,
      Max(CASE WHEN Idx =  6 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val6,
      Max(CASE WHEN Idx =  7 THEN Den                                                                ELSE NULL END) Den7,
      Max(CASE WHEN Idx =  7 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val7,
      Max(CASE WHEN Idx =  8 THEN Den                                                                ELSE NULL END) Den8,
      Max(CASE WHEN Idx =  8 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val8,
      Max(CASE WHEN Idx =  9 THEN Den                                                                ELSE NULL END) Den9,
      Max(CASE WHEN Idx =  9 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val9,
      Max(CASE WHEN Idx = 10 THEN Den                                                                ELSE NULL END) Den10,
      Max(CASE WHEN Idx = 10 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val10,
      TO_CHAR(Coalesce(Sum(Val),0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ValTot
    FROM (
      SELECT Row_Number() OVER (ORDER BY Sign(cant), Denobiect) Idx, Denobiect den, Sum(valoare) val
      FROM tmp_list_proforma1
      WHERE tiplinie IN (&apos;G&apos;, &apos;T&apos;)
      GROUP BY Sign(cant), denobiect
      ORDER BY Sign(cant), denobiect
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_DEN&apos;,  v_rec.Den1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_VAL&apos;,  v_rec.Val1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_DEN&apos;,  v_rec.Den2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_VAL&apos;,  v_rec.Val2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_DEN&apos;,  v_rec.Den3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_VAL&apos;,  v_rec.Val3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_DEN&apos;,  v_rec.Den4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_VAL&apos;,  v_rec.Val4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_DEN&apos;,  v_rec.Den5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_VAL&apos;,  v_rec.Val5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_DEN&apos;,  v_rec.Den6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_VAL&apos;,  v_rec.Val6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_DEN&apos;,  v_rec.Den7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_VAL&apos;,  v_rec.Val7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_DEN&apos;,  v_rec.Den8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_VAL&apos;,  v_rec.Val8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_DEN&apos;,  v_rec.Den9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_VAL&apos;,  v_rec.Val9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_DEN&apos;, v_rec.Den10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_VAL&apos;, v_rec.Val10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT&apos;,   v_rec.ValTot);
  END LOOP;

  FOR v_rec IN (
    SELECT
      SUM(c1.pu * c1.cantcomandat) ValBruta,
      SUM(CASE WHEN c1.cantcomandat &gt; 0 THEN c1.cantcomandat * Coalesce(o.volum,0)                      ELSE 0 END) Volum,
      SUM(CASE WHEN c1.cantcomandat &gt; 0 THEN c1.cantcomandat * Coalesce(o.masa,0)                       ELSE 0 END) Masa,
      SUM(CASE WHEN c1.cantcomandat &gt; 0 THEN c1.cantcomandat * Coalesce(o.masa,0) * Coalesce(u.coef, 1) ELSE 0 END) MasaM,
      SUM(Ceil(c1.cantcomandat) * (SELECT count(1) FROM nartobjcolet oc WHERE oc.codobiect = c1.codobiect) ) NrCol
    FROM comanda1 c1
      INNER JOIN nartobj o ON o.codobiect  = c1.codobiect
      INNER JOIN nart    a ON a.codarticol = o.codarticol
      INNER JOIN num     u ON u.codum = a.um
    WHERE c1.codcomanda = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE BRUTA&apos;,                 TO_CHAR(v_rec.ValBruta,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,                   TO_CHAR(v_rec.Masa,    &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA MULTIPLA&apos;,                 TO_CHAR(v_rec.MasaM,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,                   TO_CHAR(v_rec.Volum,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR COLETE TOTAL&apos;,               TO_CHAR(v_rec.NrCol,   &apos;fm9G999G999G990&apos;,    &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  FOR v_rec IN (
    SELECT
      &apos;TERMEN &apos;||To_Char(aux.nr,&apos;fm99&apos;) PName,
      CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(tc.zile, &apos;fm99990&apos;)                                                               END zile,
      CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(         tc.procent,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)        END procent,
      CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE tc.tip                                                                                    END tip,
      CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char(vVal*tc.procent/100,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;)        END Val,
      CASE WHEN tc.idx = vNrTerm AND tc.nrinreg &gt; vNrTerm THEN aux.p ELSE To_Char((vVal+vTva)*tc.procent/100,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) END VCT
    FROM (SELECT level Nr, CAST(&apos;...&apos; AS VARCHAR2(50)) p FROM DUAL connect by level &lt;= vNrTerm) aux
      LEFT JOIN (
        SELECT
          Row_Number() OVER (ORDER BY zile, codtermen) idx,
          Count(1) OVER (PARTITION BY codcomanda) nrinreg,
          zile, procent,
          DECODE(tipplata,2,&apos;Numerar&apos;,3,&apos;OrdP&apos;,4,&apos;Cec&apos;,5,&apos;Bilet la Ordin&apos;,6,&apos;Compensare&apos;,7,&apos;Majorari&apos;,&apos;...nedefinit...&apos;) tip
        FROM termenecmd
        WHERE codcomanda = vCodDoc
      ) tc ON tc.idx = aux.nr
    ORDER BY aux.nr
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; ZILE&apos;          ,  v_rec.Zile);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; PROCENT&apos;       ,  v_rec.Procent);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; TIP&apos;           ,  v_rec.Tip);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; VALOARE&apos;       ,  v_rec.Val);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.PName||&apos; VALOARE CU TVA&apos;,  v_rec.VCT);
  END LOOP;

  FOR v_rec IN (
    SELECT
      PA.NRINREG, PC.KMBORD, PA.SERIEC, MA.MARCA, MO.MODEL, CA.NRDOC, CA.DATADOC, CA.SERIADOC, NumePrenume(r.nume, r.prenume) RECEPTIONER,
      (SELECT Max(C1.Termen) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) TERMEN
    FROM COMANDA C
      LEFT JOIN NPARCCOM PC    ON PC.CODCOMANDA   = C.CODCOMANDA
      LEFT JOIN NPARCAUT PA    ON PA.CODNPARCAUT  = PC.CODNPARCAUT
      LEFT JOIN NPARCCOM PCA   ON PCA.CODNPARCAUT = PC.CODNPARCAUT
      LEFT JOIN COMANDA  CA    ON CA.CODCOMANDA   = PCA.CODCOMANDA AND CA.DATADOC &lt; C.DATADOC

      LEFT JOIN NMARCIAUTO  MA ON MA.CODMARCIAUTO = PA.MARCA
      LEFT JOIN NMODELEAUTO MO ON MO.CODMODELEAUTO = PA.MODEL

      LEFT JOIN NPERS R        ON R.CODPERS = C.INSOTITOR
    WHERE c.codcomanda = vCodDoc AND C.TipDoc = 92
    ORDER BY CA.DATADOC DESC
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - NUMAR&apos;           ,  v_rec.NRINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - KM BORD&apos;         ,  v_rec.KMBORD);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - SERIE CAROSERIE&apos; ,  v_rec.SERIEC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - MARCA&apos;           ,  v_rec.MARCA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - MODEL&apos;           ,  v_rec.MODEL);


    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - SERDOC&apos; ,  v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - NRDOC&apos;  ,  v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - DATADOC&apos;,  To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));

    pkg_list_Struct.ADAUGA_PARAM(&apos;TERMEN FINAL&apos;                ,  To_Char(v_rec.Termen,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;RECEPTIONER&apos;                 ,  v_rec.RECEPTIONER);

    EXIT;
  END LOOP;

  COMMIT;

END;

END PKG_LIST_BASE_DOCPROFORMA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCSETTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F4BB5967545BE741E9CB2BF16B527DD33F573E6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCSETTASK is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  TaskFirma   NUMBER(1);
  vCodDoc WINMADMIN.SetTask.CodTask%TYPE;

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE ADD_LIST_PARAMS IS
  TaskFirma number(1);
begin
  pkg_list_Struct.GOLESTE_PARAM;
  pkg_globals.SetSeparator(&apos;;&apos;);

  IF TaskFirma = 2 THEN
		FOR v_rec IN (
			SELECT
				ST.NrDoc, ST.SeriaDoc, CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET, ST.DataTask,
				ST.Problema, Decode(ST.Done,1, &apos;DA&apos;, &apos;NU&apos;) Rezolvat, ST.DataRez, substr(ST.Rezolvare,1,3200) rezolvare,
				S.DENSERVICIU, P.DEN_PART, NUMEPRENUME(R.NUME, R.PRENUME) RESPONSABIL, round(ST.VALOARE,2) valoare, M.SIMBOL MONEDA, Decode(ST.FACTURABIL,1,&apos;DA&apos;,&apos;NU&apos;) FACTURABIL,
				string_agg(O.DENUMIRE) DENUMIRE, string_agg(ASOC.SERII) SERII, string_agg(ASOC.CODINTERN) OBSERVATII
			FROM SetTask ST
				LEFT JOIN SETTASKOBJASOC ASOC ON ASOC.CODTASK = ST.CODTASK
				LEFT JOIN NARTOBJ O ON O.CODOBIECT = ASOC.CODOBIECT
				LEFT JOIN SERVPOST S ON S.CODSERVICIU = ST.CODSERVICIU
				LEFT JOIN NPART P ON P.CODPART = ST.CODPART
				LEFT JOIN NPERS R ON R.CODPERS = ST.CODPERS
				LEFT JOIN NMONEDE M ON M.CODMONEDA = ST.CODMONEDA
				LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = ST.CARNETDOC
			WHERE st.CodTask = vCodDoc
			GROUP BY ST.NrDoc, ST.SeriaDoc, CAR.SIMBOL, CAR.DENUMIRE, ST.DataTask, ST.Problema, ST.Done, ST.DataRez, ST.Rezolvare,
				S.DENSERVICIU, P.DEN_PART, R.NUME, R.PRENUME, ST.VALOARE, M.SIMBOL, ST.FACTURABIL
		) LOOP
			pkg_list_Struct.ADAUGA_PARAM(&apos;Serie Document&apos;,     v_rec.SeriaDoc);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Document&apos;,     v_rec.NrDoc);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet Simbol&apos;,      v_rec.SimbolCarnet);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet Denumire&apos;,    v_rec.DenumireCarnet);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Data Task&apos;,          TO_CHAR(v_rec.DataTask,&apos;dd.mm.yyyy&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Problema&apos;,           v_rec.Problema);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Rezolvat&apos;,           v_rec.Rezolvat);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Data Rezolvare&apos;,     TO_CHAR(v_rec.DataRez,&apos;dd.mm.yyyy&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Rezolvare&apos;,          v_rec.Rezolvare);

			pkg_list_Struct.ADAUGA_PARAM(&apos;Serviciu&apos;,           v_rec.DENSERVICIU);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,           v_rec.DEN_PART);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Responsabil&apos;,        v_rec.RESPONSABIL);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare&apos;,            TO_CHAR(v_rec.VALOARE,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,             v_rec.MONEDA);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Facturabil&apos;,         v_rec.FACTURABIL);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate&apos;,  v_rec.DENUMIRE);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate - serii&apos;,  v_rec.SERII);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate - Obs.&apos;,  v_rec.OBSERVATII);

			EXIT;
		END LOOP;
  ELSE
		FOR v_rec IN (
			SELECT
				ST.NrDoc, ST.SeriaDoc, CAR.SIMBOL SIMBOLCARNET, CAR.DENUMIRE DENUMIRECARNET, ST.DataTask,
				ST.Problema, Decode(ST.Done,1, &apos;DA&apos;, &apos;NU&apos;) Rezolvat, ST.DataRez, substr(ST.Rezolvare,1,3200) rezolvare,
				S.DENSERVICIU, P.DEN_PART, NUMEPRENUME(R.NUME, R.PRENUME) RESPONSABIL, round(ST.VALOARE,2) valoare, M.SIMBOL MONEDA, Decode(ST.FACTURABIL,1,&apos;DA&apos;,&apos;NU&apos;) FACTURABIL,
				string_agg(O.DENUMIRE) DENUMIRE, string_agg(ASOC.SERII) SERII, string_agg(ASOC.CODINTERN) OBSERVATII
			FROM WINMADMIN.SetTask ST
				LEFT JOIN WINMADMIN.SETTASKOBJASOC ASOC ON ASOC.CODTASK = ST.CODTASK
				LEFT JOIN NARTOBJ O ON O.CODOBIECT = ASOC.CODOBIECT
				LEFT JOIN SERVPOST S ON S.CODSERVICIU = ST.CODSERVICIU
				LEFT JOIN NPART P ON P.CODPART = ST.CODPART
				LEFT JOIN NPERS R ON R.CODPERS = ST.CODPERS
				LEFT JOIN NMONEDE M ON M.CODMONEDA = ST.CODMONEDA
				LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = ST.CARNETDOC
			WHERE st.CodTask = vCodDoc
			group by ST.NrDoc, ST.SeriaDoc, CAR.SIMBOL, CAR.DENUMIRE, ST.DataTask, ST.Problema, ST.Done, ST.DataRez, ST.Rezolvare,
				S.DENSERVICIU, P.DEN_PART, R.NUME, R.PRENUME, ST.VALOARE, M.SIMBOL, ST.FACTURABIL
		) LOOP
			pkg_list_Struct.ADAUGA_PARAM(&apos;Serie Document&apos;,     v_rec.SeriaDoc);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Document&apos;,     v_rec.NrDoc);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet Simbol&apos;,      v_rec.SimbolCarnet);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet Denumire&apos;,    v_rec.DenumireCarnet);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Data Task&apos;,          TO_CHAR(v_rec.DataTask,&apos;dd.mm.yyyy&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Problema&apos;,           v_rec.Problema);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Rezolvat&apos;,           v_rec.Rezolvat);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Data Rezolvare&apos;,     TO_CHAR(v_rec.DataRez,&apos;dd.mm.yyyy&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Rezolvare&apos;,          v_rec.Rezolvare);

			pkg_list_Struct.ADAUGA_PARAM(&apos;Serviciu&apos;,           v_rec.DENSERVICIU);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,           v_rec.DEN_PART);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Responsabil&apos;,        v_rec.RESPONSABIL);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare&apos;,            TO_CHAR(v_rec.VALOARE,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
			pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,             v_rec.MONEDA);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Facturabil&apos;,         v_rec.FACTURABIL);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate&apos;,  v_rec.DENUMIRE);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate - serii&apos;,  v_rec.SERII);
			pkg_list_Struct.ADAUGA_PARAM(&apos;Articole asociate - Obs.&apos;,  v_rec.OBSERVATII);

			EXIT;
		END LOOP;
	end if;
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;SETTASKEXT&apos;, &apos;CODTASK&apos;, vCodDoc, &apos;EXTENSII - &apos;);

END;


PROCEDURE PROCESSLIST(TmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(20000);
	LocTask   varchar2(10);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;

	IF TaskFirma = 2 THEN
    LocTask   := &apos;&apos;;
    gSuplCols := &apos;SETTASK ST, SETTASKOBJ STO&apos;;
  ELSE
    LocTask   := &apos;WINMADMIN.&apos;;
    gSuplCols := &apos;LST_SETTASK ST, LST_SETTASKOBJ STO&apos;;
  END IF;

  gSuplCols := gSuplCols||&apos;, NARTOBJ O, NART A, NPERS P, NUM UM&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMONEDE&apos;,        &apos;MON&apos;,    &apos;MON.CODMONEDA = ST.CODMONEDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;COM&apos;,    &apos;COM.CODCOMANDA = ST.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;IES&apos;,    &apos;IES.CODIES = ST.CODFACTURA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA&apos;,         &apos;OFE&apos;,    &apos;OFE.CODOFERTA = ST.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;SERVPOST&apos;,       &apos;SERV&apos;,   &apos;SERV.CODSERVICIU = ST.CODSERVICIU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;,      &apos;CONTR1&apos;, &apos;CONTR1.CODCONTRACT1 = ST.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT&apos;,       &apos;CONTR&apos;,  &apos;CONTR.CODCONTRACT = CONTR1.CODCONTRACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;SETTASKEXT&apos;,     &apos;STE&apos;,    &apos;STE.CODTASK = ST.CODTASK&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos; || TmpName || &apos;(
    Proiect, Destinatar, Executant, Termen, Prioritate, Domeniu,
    Tip, UserName, Problema, Done, DataRez, Rezolvare, Observatii,
    TipArticol, Articol, Cant, CodExtern, Nepreluat, Pret, Valoare, Persoana&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    ST.Proiect, ST.Destinatar, ST.Executant, ST.Termen, ST.Prioritate, ST.Domeniu,
    ST.Tip, ST.UserName, substr(ST.Problema,1,3200), ST.Done, ST.DataRez, substr(ST.Rezolvare,1,3200), substr(ST.Observatii,1,3200),
    Decode(A.TIPARTICOL,1,&apos;&apos;Serviciu&apos;&apos;,&apos;&apos;Stoc&apos;&apos;) TipArticol, O.DENUMIRE, STO.CANT, O.CodExtern,
    Decode(STO.Nepreluabil, 1, &apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) Nepreluat, STO.PRET, round(STO.PRET * STO.CANT,2), P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME &apos;||
    gUserAlias||&apos;
  FROM &apos;||LocTask||&apos;SetTask ST
    LEFT JOIN &apos;||LocTask||&apos;SetTaskObj STO ON STO.CodTask = ST.CodTask
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = STO.CODOBIECT
    LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
    LEFT JOIN NPERS P ON P.CODPERS = STO.CODPERS
    LEFT JOIN NUM UM ON UM.CODUM = A.UM &apos;||
    gSuplJoins||&apos;
  WHERE ST.CodTask = &apos;||vCodDoc;

  --PKG_GLOBALS.SetDebugMOde(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  add_list_params;
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_DOCSETTASK;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCTRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A0F62C22450E054FF4DFC04B5D4E4A23935EA5B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCTRANSPORT IS

  vCodDoc NUMBER;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(10000);
sSelect   VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;TRANSPORT T, TRANSPORT1 T1, TRANSPORT2 T2&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    SERIECOLET,
    NRCOLET,
    DATACOLET,
    PREFIXDOC,
    SERIEDOC,
    NRDOC,
    DATADOC,
    TIPPARTENER,
    PARTENER,
    ARTICOL,
    CANT,
    DEN_UM1,
    VALOARETR,
    VALFARATVA,
    MASA,
    VOLUM &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  select
    DOCPK.Serie SERIECOLET,
    PK.NrDoc NRCOLET,
    PK.DataP DATACOLET,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T.PREFIXDOC
      ELSE I.PREFIXDOC
    END,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN DOCT.Serie
      ELSE DOCIES.Serie
    END,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T.NrDoc
      ELSE I.NrDoc
    END,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T.DataDoc
      ELSE I.DataDoc
    END,
    CASE
      WHEN T1.TipDoc = 12 THEN &apos;&apos;GESTIUNE&apos;&apos;
      WHEN T1.TipDoc = 13 THEN &apos;&apos;...NEDEFINIT...&apos;&apos;
      WHEN T1.TipDoc = 23 THEN &apos;&apos;SUBUNITATE&apos;&apos;
      ELSE &apos;&apos;PARTENER&apos;&apos;
    END,
    CASE
      WHEN T1.TipDoc = 12 THEN G.Den_Gest
      WHEN T1.TipDoc = 13 THEN &apos;&apos;...NEDEFINIT...&apos;&apos;
      WHEN T1.TipDoc = 23 THEN S.Den_Subunit
      ELSE P.Den_Part
    END,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN TOBJ.Denumire
      ELSE IOBJ.Denumire
    END Articol,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T1.Cant
      ELSE I1.Cant
    END cant,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN TUM1.Den_UM1
      ELSE IUM1.Den_UM1
    END Den_UM1,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T1.CostTransport
      ELSE I1.CostTransport
    END Valoaretr,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T1.Cant * T1.Pu
      ELSE I1.Cant * I1.PU
    END ValFaraTVA,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN
        CASE
          WHEN NVL(AMBT.CODAMB, -1) = -1 THEN TOBJ.Masa
          ELSE AMBT.Masa
        END
      ELSE
        CASE
          WHEN NVL(AMBI.CODAMB, -1) = -1 THEN IOBJ.Masa
          ELSE AMBI.Masa
        END
    END *
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T1.Cant
      ELSE I1.Cant
    END Masa,
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN
        CASE
          WHEN NVL(AMBT.CODAMB, -1) = -1 THEN TOBJ.Volum
          ELSE NVL(AMBT.Inaltime, 0) * NVL(AMBT.Lungime, 0) * NVL(AMBT.Latime, 0)
        END
      ELSE
        CASE
          WHEN NVL(AMBI.CODAMB, -1) = -1 THEN IOBJ.Volum
          ELSE NVL(AMBI.Inaltime, 0) * NVL(AMBI.Lungime, 0) * NVL(AMBI.Latime, 0)
        END
    END *
    CASE
      WHEN T1.TipDoc IN (12, 13) THEN T1.Cant
      ELSE I1.Cant
    END Volum
  FROM TRANSPORT1 T1
       LEFT JOIN PACHETE PK ON T1.CodColet = PK.CODPACHETE
       LEFT JOIN DOCCARNETE DOCPK ON PK.Carnetdoc = DOCPK.CODCARNET
       LEFT JOIN IESIRI I ON T1.CodDoc = I.CodIes AND NVL(I.Anulat, 0) &lt;&gt; 1
       LEFT JOIN DOCCARNETE DOCIES ON I.CarnetDoc = DOCIES.CODCARNET
       LEFT JOIN NPART P ON I.Partener = P.Codpart
       LEFT JOIN NSUBUNIT S ON I.CodSubunit = S.Codsubunit
       LEFT JOIN TRANSF T ON T1.CodDoc = T.Codtransf AND NVL(T.Anulat, 0) &lt;&gt; 1
       LEFT JOIN DOCCARNETE DOCT ON T.CarnetDoc = DOCT.CodCarnet
       LEFT JOIN NGEST G ON T.CodGestCmd = G.CodGest
       LEFT JOIN IESIRI1 I1 ON I.CodIes = I1.CodIes
       LEFT JOIN NARTOBJ IOBJ ON I1.CodObiect = IOBJ.CodObiect
       LEFT JOIN NUM1 IUM1 ON I1.UMSec = IUM1.CodUM1
       LEFT JOIN NARTAMB AMBI ON IOBJ.CodObiect = AMBI.CodOBiect AND I1.UMSec = AMBI.UMSec
       LEFT JOIN TRANSF1 T1 ON T.CodTransf = T1.CodTransf
       LEFT JOIN NARTOBJ TOBJ ON T1.CodObiect = TOBJ.CodObiect
       LEFT JOIN NUM1 TUM1 ON T1.UMSec = TUM1.CodUM1
       LEFT JOIN NARTAMB AMBT ON TOBJ.CodObiect = AMBT.CodOBiect AND T1.UMSec = AMBT.UMSec&apos;||
    gSuplJoins||&apos;
  WHERE t1.codtransport = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    select
      to_char(TR.DataTransport,&apos;dd.mm.yyyy&apos;) DATATR,
      TR.Indicativ IDENTIFICATOR,
      TO_CHAR(ROUND(TR.Valoare,2)) VALOARE,
      P.NUME||&apos; &apos;||P.PRENUME PERS,
      OBJ.DENUMIRE AUTO,
      Round(NVL(PA.MasaU, 0), 5) Masa,
      Round(NVL(PA.Lung, 0) * NVL(PA.Lat, 0) * NVL(PA.Inalt, 0)/1000000, 5) Volum,
      PA.NRINV MASINA
    FROM TRANSPORT TR
         LEFT JOIN NPARCAUT PA ON TR.CodParcAuto = PA.CODNPARCAUT
         LEFT JOIN NARTOBJ OBJ ON PA.CODART = OBJ.CODOBIECT
         LEFT JOIN NPERS P ON P.CODPERS = TR.CODSOFER
    WHERE TR.CodTransport = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;AUTOVEHICUL&apos;,              v_rec.AUTO);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA TRANSPORTATOARE&apos;, v_rec.PERS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASINA&apos;,                   v_rec.MASINA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE&apos;,                  v_rec.VALOARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SARCINA UTILA&apos;,            v_rec.MASA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM UTIL&apos;,               v_rec.VOLUM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATA&apos;,                     v_rec.DATATR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;IDENTIFICATOR&apos;,            v_rec.IDENTIFICATOR);
    EXIT;
  END LOOP;

  COMMIT;
END;

end PKG_LIST_BASE_DOCTRANSPORT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B887CCCE0A17C08F19E86DA37BE32EF230CD6A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCTREZOR IS

  vCodTrezor  TREZOR1.CODTREZOR%TYPE;
  vCodTrezor1 TREZOR1.CODTREZOR1%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(
  pCodTrezor  IN NUMBER DEFAULT NULL,
  pCodTrezor1 IN NUMBER DEFAULT NULL
)  IS
BEGIN
  vCodTrezor  := pCodTrezor;
  vCodTrezor1 := pCodTrezor1;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

FUNCTION  OBLIGPIF_DENDOCLEGATURA( pCodObligPif IN NUMBER, pSemnificatie IN NUMBER)
          RETURN VARCHAR2
IS
 sResult      VARCHAR2(50);
 vSemnifStins OBLIGPIF.SEMNIFICATIE%TYPE;
BEGIN
  -- stef prelucrat dupa pkg_trezor --&gt; UPDATE TMP_OBLIGPIF OB -&gt; DENDOCLEGATURA

  vSemnifStins := 0;
  IF pCodObligPif &lt;&gt; 0 THEN
    BEGIN
      SELECT OO.SEMNIFICATIE INTO vSemnifStins
      FROM STINGERE SS LEFT JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
      WHERE SS.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1;
    EXCEPTION
      WHEN OTHERS THEN vSemnifStins := 0;
    END;
  END IF;

  SELECT
    CASE
      /* PLATA FURN - FACTURA IN NEGRU*/
      WHEN pSemnificatie  = 300 AND vSemnifStins = 100 THEN
      ( SELECT I.PREFIXDOC || Decode(I.SERIADOC,NULL,NULL,I.SERIADOC||&apos;&apos;/&apos;&apos;) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* PLATA FURN - DVI*/
      WHEN pSemnificatie  = 300 AND vSemnifStins = 130 THEN
      ( SELECT &apos;DVOT&apos; || D.NRDOC || &apos;(&apos; || to_char(D.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN DVI D ON D.CODDVI = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* INCASARE CLIENT - FACTURA IN NEGRU*/
      WHEN pSemnificatie  = 400 AND vSemnifStins = 200 THEN
      ( SELECT I.PREFIXDOC || Decode(I.SERIADOC,NULL,NULL,I.SERIADOC||&apos;&apos;/&apos;&apos;) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN IESIRI I ON I.CODIES = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* PLATA FURN - NOTA CONTABILA IN NEGRU*/
      WHEN pSemnificatie  = 300 AND vSemnifStins = 1201 THEN
      ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
          LEFT JOIN NC  N  ON N.CODNC   = N1.CODNC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* PLATA FURN - OBLIGATIE DIN COMPENSARI IN NEGRU*/
      WHEN pSemnificatie  = 300 AND vSemnifStins = 1351 THEN
      ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* INCASARE CLIENT - NOTA CONTABILA IN NEGRU*/
      WHEN pSemnificatie  = 400 AND vSemnifStins = 1200 THEN
      ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
          LEFT JOIN NC  N  ON N.CODNC   = N1.CODNC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* INCASARE CLIENT - COMPENSARE IN NEGRU*/
      WHEN pSemnificatie  = 400 AND vSemnifStins IN (1301) THEN
      ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* LITIGII*/
      WHEN pSemnificatie  = 400 AND vSemnifStins IN (1303) THEN
      ( SELECT I.PREFIXDOC || Decode(I.SERIADOC,NULL,NULL,I.SERIADOC||&apos;&apos;/&apos;&apos;) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
          LEFT JOIN OBLIGPIF F ON F.CODOBLIGPIF = O.CODOBLIGASOCIAT
          LEFT JOIN GENERAL GF ON GF.CODGENERAL = F.CODGENERAL
          LEFT JOIN IESIRI I ON I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* PLATA FURN - STINGERE CEC */
      WHEN pSemnificatie  = 300 AND vSemnifStins = 500 THEN
      ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* INCASARE CLIENT - STINGERE CEC */
      WHEN pSemnificatie  = 400 AND vSemnifStins = 600 THEN
      ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* RETUR FURN* - PLATA AVANS SAU RETUR CEC */
      WHEN pSemnificatie  = 320 AND vSemnifStins IN (310, 330,  500) THEN
      ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* RETUR CLIENT* - INCASARE AVANS SAU RETUR CEC */
      WHEN pSemnificatie  = 420 AND vSemnifStins IN (410, 430, 600) THEN
      ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif AND ROWNUM &lt;=1
      )
      /* RETUR FURN* - FACTURA IN ROSU */
      WHEN pSemnificatie  = 320 AND vSemnifStins = 100 THEN
      ( SELECT I.PREFIXDOC || Decode(I.SERIADOC,NULL,NULL,I.SERIADOC||&apos;&apos;/&apos;&apos;) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM
          STINGERE S LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* RETUR FURN* - OBLIGATIE DIN NOTE CONTABILE */
      WHEN pSemnificatie  IN (320, 420) AND vSemnifStins = 1200 THEN
      ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
          LEFT JOIN NC  N  ON N.CODNC   = N1.CODNC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* RETUR FURN* - OBLIGATIE DIN COMPENSARI */
      WHEN pSemnificatie  = 320 AND vSemnifStins IN (1301) THEN
      ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* RETUR CLIENT* - FACTURA IN ROSU */
      WHEN pSemnificatie  = 420  AND vSemnifStins = 200 THEN
      ( SELECT I.PREFIXDOC || Decode(I.SERIADOC,NULL,NULL,I.SERIADOC||&apos;&apos;/&apos;&apos;) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN IESIRI I ON I.CODIES = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* RETUR CLIENT* - OBLIGATII DIN NOTE CONTABILE */
      WHEN pSemnificatie  IN (320, 420) AND vSemnifStins = 1201 THEN
      ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
          LEFT JOIN NC   N ON N.CODNC   = N1.CODNC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* RETUR CLIENT* - OBLIGATII DIN COMPENSARI */
      WHEN pSemnificatie  = 420 AND vSemnifStins = 1351 THEN
      ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      /* viramente cu legatura */
      WHEN pSemnificatie  IN (800, 801) AND vSemnifStins IN (800, 801) THEN
      ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
        FROM STINGERE S
          LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
        WHERE S.CODSTINGATORPIF = pCodObligPif  AND ROWNUM &lt;=1
      )
      WHEN pSemnificatie  IN (310, 330)   THEN &apos;Plata in avans&apos;
      WHEN pSemnificatie  IN (410, 430)   THEN &apos;Incasare in avans&apos;
      WHEN pSemnificatie  IN (800, 801)   THEN &apos;Viramente interne&apos;
      WHEN pSemnificatie  = 900           THEN &apos;Pe cheltuieli&apos;
      WHEN pSemnificatie  = 901           THEN &apos;Pe venituri&apos;
      WHEN pSemnificatie  IN (950, 951)   THEN &apos;Direct pe cont&apos;
      WHEN pSemnificatie  = 1000          THEN &apos;Dobanda&apos;
      WHEN pSemnificatie  IN (1100, 1101) THEN &apos;Angajat&apos;
      ELSE &apos;???&apos;
    END
  INTO sResult
  FROM Dual;

	RETURN sResult;

EXCEPTION
  WHEN OTHERS THEN RETURN &apos;???&apos;;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(32000);
  sFiltru    VARCHAR2(100);
  sCodMoneda VARCHAR2(100);
  sDocLeg    VARCHAR2(1000);
BEGIN
  --pkg_globals.setdebugmode(TRUE);
  gSuplCols   := &apos;TREZOR1 T1, TREZOR T, GENERAL G, OBLIGPIF O, NPARTB PARTB, NBANK BANKP&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;STINGERE&apos;, &apos;S&apos;,     &apos;S.CODSTINGATORPIF = O.CODOBLIGPIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OBLIGPIF&apos;, &apos;O_S&apos;,   &apos;O_S.CODOBLIGPIF = S.CODSTINSPIF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;GENERAL&apos;,  &apos;G_S&apos;,   &apos;G_S.CODGENERAL = O_S.CODGENERAL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMPENS&apos;,  &apos;C_S&apos;,   &apos;C_S.CODCOMPENS = G_S.CODDOC AND G_S.TIPDOC = 28&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OBLIGPIF&apos;, &apos;O_F&apos;,   &apos;O_F.CODOBLIGPIF = O_S.CODOBLIGASOCIAT AND O.SEMNIFICATIE = 400 AND O_S.SEMNIFICATIE = 1303&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;GENERAL&apos;,  &apos;G_F&apos;,   &apos;G_F.CODGENERAL = O_F.CODGENERAL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,   &apos;IES_S&apos;, &apos;IES_S.CODIES = Coalesce(G_F.CODDOC, G_S.CODDOC) AND IES_S.TIPDOC = Coalesce(G_F.TIPDOC, G_S.TIPDOC) &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DVI&apos;,      &apos;DVI_S&apos;, &apos;DVI_S.CODDVI = G_S.CODDOC AND O.SEMNIFICATIE = 300 AND O_S.SEMNIFICATIE = 130&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,  &apos;INT_S&apos;, &apos;INT_S.CODINTR = Coalesce(DVI_S.CODINTR, G_S.CODDOC) AND INT_S.TIPDOC = G_S.TIPDOC &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC1&apos;,      &apos;NC1_S&apos;, &apos;NC1_S.CODNC1 = G_S.CODDOC AND G_S.TIPDOC = 35 &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC&apos;,       &apos;NC_S&apos;,  &apos;NC_S.CODNC = NC1_S.CODNC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;,  &apos;T1_S&apos;,  &apos;T1_S.CODTREZOR1 = G_S.CODDOC AND G_S.TIPDOC IN (29, 30, 31, 33) &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,   &apos;T_S&apos;,   &apos;T_S.CODTREZOR = T1_S.CODTREZOR&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF aListId = 226 and vCodTrezor1 = 0
  THEN
    sFiltru    := &apos;T.CodTrezor = &apos;||vCodTrezor;
    sCodMoneda := &apos;NVL(t.monedapers,0)&apos;;
  ELSE
    sFiltru    := &apos;T1.CodTrezor1 = &apos;||vCodTrezor1;
    sCodMoneda := &apos;NVL(bc.codmoneda,0)&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(DOCTREZOR, DOC, VAL, VALLIT, MONEDA, TIPDECONT,TIPTRANZ,PART,OBS&apos;||gUserFields||&apos;)
  SELECT
    T1.DOC||T1.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(T1.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),
    PKG_LIST_BASE_DOCTREZOR.OBLIGPIF_DENDOCLEGATURA(O.CODOBLIGPIF, O.SEMNIFICATIE),
    CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE O.VALOAREAFISATA END VAL,
    NumarRO(CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE O.VALOAREAFISATA END, m.Den_Moneda, NULL, m.SDenumire, NULL), m.Den_Moneda,
    DECODE(T1.TIPDECONT,1,&apos;&apos;Cecuri&apos;&apos;,2,&apos;&apos;Efecte acceptate&apos;&apos;,3,&apos;&apos;Efecte remise&apos;&apos;),
    DECODE(T1.TIPTRANZ,1,&apos;&apos;Incasare&apos;&apos;,&apos;&apos;Plata&apos;&apos;),
    CASE
      WHEN T1.TIPTRANZ = 0 AND T1.OBIECTTRANZ = 0 THEN &apos;&apos;Furnizor : &apos;&apos;||p.den_part
      WHEN T1.TIPTRANZ = 1 AND T1.OBIECTTRANZ = 0 THEN &apos;&apos;Client : &apos;&apos;||p.den_part
      WHEN T1.OBIECTTRANZ = 1 THEN &apos;&apos;Retur : &apos;&apos;||p.den_part
      WHEN T1.OBIECTTRANZ = 2 THEN &apos;&apos;Personal angajat : &apos;&apos;||ang.nume||&apos;&apos; &apos;&apos;|| ang.prenume
      WHEN T1.OBIECTTRANZ = 3 THEN &apos;&apos;Viramente interne : &apos;&apos;||bv.simbol || &apos;&apos; - &apos;&apos; || bcv.nrcont
      WHEN T1.TIPTRANZ = 0 AND T1.OBIECTTRANZ = 4 THEN &apos;&apos;Servicii, articole fara NIR... : &apos;&apos; || PKG_PLANCONTURI.GETDENCONT( o.icont )
      WHEN T1.TIPTRANZ = 1 AND T1.OBIECTTRANZ = 4 THEN &apos;&apos;Direct pe venituri...&apos;&apos; || PKG_PLANCONTURI.GETDENCONT( o.icont )
      WHEN T1.TIPTRANZ = 0 AND T1.OBIECTTRANZ = 5 THEN &apos;&apos;Datorii, taxe, impozite &apos;&apos; || PKG_PLANCONTURI.GETDENCONT( o.icont )
      WHEN T1.TIPTRANZ = 1 AND T1.OBIECTTRANZ = 5 THEN &apos;&apos;Imprumuturi, subventii &apos;&apos; || PKG_PLANCONTURI.GETDENCONT( o.icont )
      WHEN T1.TIPTRANZ = 1 AND T1.OBIECTTRANZ = 6 THEN &apos;&apos;Dobanda la depozit:&apos;&apos; ||PKG_PLANCONTURI.GETDENCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1000,o.icont,PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(T.CODBANCA, t1.an, t1.luna)))
      ELSE &apos;&apos; &apos;&apos;
    END Part,
    T1.Obs &apos;||gUserAlias||&apos;
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.TIPDOC = T.TIPDOC
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    LEFT JOIN npers ang ON ang.codpers = t1.codpart AND t1.obiecttranz = 2
    LEFT JOIN npart p ON p.codpart = t1.codpart AND t1.obiecttranz IN (0,1)
    LEFT JOIN nbankcont bcv ON bcv.codbankcont = t1.codpart AND t1.obiecttranz = 3
    LEFT JOIN nbank bv ON bv.codbank = bcv.codbank
    LEFT JOIN npartb partb ON partb.codpart = t1.codpart AND t1.obiecttranz IN (0,1) AND partb.implicit = 1
    LEFT JOIN nbank bankp ON bankp.codbank = partb.codbank
    LEFT JOIN nbankcont bc ON bc.codbankcont = t.codbanca
    LEFT JOIN nmonede m ON m.codmoneda = &apos;||sCodMoneda||
    gSuplJoins||&apos;
  WHERE &apos;||sFiltru||&apos;
    AND (O.SEMNIFICATIE &lt;&gt; 500) AND (O.SEMNIFICATIE &lt;&gt; 600) AND (O.SEMNIFICATIE &lt;&gt; 700)
    AND (O.SEMNIFICATIE &lt;&gt; 701) AND (O.SEMNIFICATIE &lt;&gt; 750) AND (O.SEMNIFICATIE &lt;&gt; 751)
  ORDER BY O.CODOBLIGPIF&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;
  EXECUTE IMMEDIATE &apos;SELECT vc2_nt_to_string(CAST(COLLECT(DISTINCT DOC) AS vc2_nt)) FROM &apos;||TMPNAME INTO sDocLeg;

  IF aListId = 226 THEN
    if vCodTrezor1 &gt; 0 then
      FOR v_rec IN (
        SELECT
          Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP,
          T.NumeDoc, T.DataDoc, M.Den_Moneda, M.SDenumire,
          ( SELECT NVL(SUM(VALDOC), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 1 and t1.codtrezor1 = vcodtrezor1
          ) incasari,
          ( SELECT NVL(SUM(VALDOC), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 0 and t1.codtrezor1 = vcodtrezor1
          ) +
          ( SELECT NVL(SUM(COMISION), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 0 and t1.codtrezor1 = vcodtrezor1
          ) plati,
          ang.nume||&apos; &apos;||ang.prenume angajat, ang.cnp, ang.biseria, ang.binr,
          GETADRESA(dang.sector,dang.strada,dang.nr1,dang.nr2,dang.bloc,dang.scara,dang.etaj,dang.apart,dang.codpostal) angadresa,
          lang.den_localit anglocalit, jang.den_judet angjudet, dc.denumire carnet, t.nrdoc, t.seriadoc
        FROM trezor t
          LEFT JOIN npers u ON u.logonname   = t.userid
          LEFT JOIN npers ang ON ang.codpers = t.codbanca
          LEFT JOIN nagenda dang ON dang.codagenda = ang.agenda
          LEFT JOIN nlocalit lang ON lang.codlocalit = dang.codlocalit
          LEFT JOIN njudet jang ON jang.codjudet = lang.codjudet
          LEFT JOIN nmonede m ON m.codmoneda = NVL(t.monedapers,0)
          LEFT JOIN doccarnete dc on dc.codcarnet = t.carnetdoc
        WHERE t.codtrezor = vCodTrezor
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,            v_rec.UNUME);
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,         v_rec.UPRENUME);
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,             v_rec.UCNP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Document cumulativ&apos;,       v_rec.NumeDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Data Document&apos;,            v_rec.DataDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Documente de legatura&apos;,    sDocLeg);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                   v_rec.Den_Moneda);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare incasari&apos;,         TO_CHAR(v_rec.Incasari,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare incasari litere&apos;,  NumarRO(Round(v_rec.Incasari,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare plati&apos;,            TO_CHAR(v_rec.Plati,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare plati litere&apos;,     NumarRO(Round(v_rec.Plati,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat &apos;,                 v_rec.Angajat);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat CNP&apos;,              v_rec.CNP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat serie doc.&apos;,       v_rec.BISeria);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat numar doc.&apos;,       v_rec.BINr);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat adresa&apos;,           v_rec.angadresa);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat localitate&apos;,       v_rec.anglocalit);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat judet&apos;,            v_rec.angjudet);
        if pkg_categconst.GetValConstanta(&apos;CarnetDocCumJustif&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) = 1 then
          pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet document&apos;,        v_rec.carnet);
          pkg_list_Struct.ADAUGA_PARAM(&apos;Numar document&apos;,         v_rec.nrdoc);
          pkg_list_Struct.ADAUGA_PARAM(&apos;Serie document&apos;,         v_rec.seriadoc);
        end if;
        
        EXIT;
      END LOOP;
    else
      FOR v_rec IN (
        SELECT
          Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP,
          T.NumeDoc, T.DataDoc, M.Den_Moneda, M.SDenumire,
          ( SELECT NVL(SUM(VALDOC), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 1
          ) incasari,
          ( SELECT NVL(SUM(VALDOC), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 0
          ) +
          ( SELECT NVL(SUM(COMISION), 0)
            FROM TREZOR1 T1
            WHERE T1.CODTREZOR = T.CODTREZOR AND T.OPERAT = 1 AND T1.ANULAT = 0 AND TIPTRANZ = 0
          ) plati,
          ang.nume||&apos; &apos;||ang.prenume angajat, ang.cnp, ang.biseria, ang.binr,
          GETADRESA(dang.sector,dang.strada,dang.nr1,dang.nr2,dang.bloc,dang.scara,dang.etaj,dang.apart,dang.codpostal) angadresa,
          lang.den_localit anglocalit, jang.den_judet angjudet, dc.denumire carnet, t.nrdoc, t.seriadoc
        FROM trezor t
          LEFT JOIN npers u ON u.logonname   = t.userid
          LEFT JOIN npers ang ON ang.codpers = t.codbanca
          LEFT JOIN nagenda dang ON dang.codagenda = ang.agenda
          LEFT JOIN nlocalit lang ON lang.codlocalit = dang.codlocalit
          LEFT JOIN njudet jang ON jang.codjudet = lang.codjudet
          LEFT JOIN nmonede m ON m.codmoneda = NVL(t.monedapers,0)
          LEFT JOIN doccarnete dc on dc.codcarnet = t.carnetdoc
        WHERE t.codtrezor = vCodTrezor
      ) LOOP
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,            v_rec.UNUME);
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,         v_rec.UPRENUME);
        pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,             v_rec.UCNP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Document cumulativ&apos;,       v_rec.NumeDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Data Document&apos;,            v_rec.DataDoc);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Documente de legatura&apos;,    sDocLeg);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                   v_rec.Den_Moneda);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare incasari&apos;,         TO_CHAR(v_rec.Incasari,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare incasari litere&apos;,  NumarRO(Round(v_rec.Incasari,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare plati&apos;,            TO_CHAR(v_rec.Plati,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare plati litere&apos;,     NumarRO(Round(v_rec.Plati,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat &apos;,                 v_rec.Angajat);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat CNP&apos;,              v_rec.CNP);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat serie doc.&apos;,       v_rec.BISeria);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat numar doc.&apos;,       v_rec.BINr);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat adresa&apos;,           v_rec.angadresa);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat localitate&apos;,       v_rec.anglocalit);
        pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat judet&apos;,            v_rec.angjudet);
        if pkg_categconst.GetValConstanta(&apos;CarnetDocCumJustif&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) = 1 then
          pkg_list_Struct.ADAUGA_PARAM(&apos;Carnet document&apos;,        v_rec.carnet);
          pkg_list_Struct.ADAUGA_PARAM(&apos;Numar document&apos;,         v_rec.nrdoc);
          pkg_list_Struct.ADAUGA_PARAM(&apos;Serie document&apos;,         v_rec.seriadoc);
        end if;
        
        EXIT;
      END LOOP;
    end if;  

    FOR v_rec IN (
      SELECT soldlei, soldvaluta FROM v_soldpersoana_luna_prec
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat sold ini lei&apos;,     v_rec.soldlei);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat sold ini valuta&apos;,  v_rec.soldvaluta);
      EXIT;
    END LOOP;
    FOR v_rec IN (
      SELECT soldlei, soldvaluta FROM v_soldpersoana_luna
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat sold fin lei&apos;,     v_rec.soldlei);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat sold fin valuta&apos;,  v_rec.soldvaluta);
      EXIT;
    END LOOP;
  ELSE
    --pkg_list_base_utils.UMPLE_TMP_NPERS1_LST;
    PRC_AL_CHECK(&apos;NPERS1&apos;);
    FOR v_rec IN (
      SELECT
        Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP,
        T.NumeDoc, T.DataDoc DataCumul, T1.Doc, T1.NrDoc, T1.nri, T1.SerieDoc, T1.DataDoc, t1.valdoc, t1.obs, m.den_moneda, m.sdenumire,
        CASE
          WHEN T1.TIPTRANZ = 0 AND T1.OBIECTTRANZ = 0 THEN &apos;Furnizor &apos;
          WHEN T1.TIPTRANZ = 1 AND T1.OBIECTTRANZ = 0 THEN &apos;Client &apos;
          WHEN T1.OBIECTTRANZ = 1 THEN &apos;Retur &apos;
          WHEN T1.OBIECTTRANZ = 2 THEN &apos;Personal angajat &apos;
          WHEN T1.OBIECTTRANZ = 3 THEN &apos;Viramente interne&apos;
        END Tranzactie,
        CASE
          WHEN T1.OBIECTTRANZ IN (0,1) THEN p.den_part
          WHEN T1.OBIECTTRANZ = 2 THEN ang.nume||&apos; &apos;||ang.prenume
          WHEN T1.OBIECTTRANZ = 3 THEN bv.simbol||&apos; &apos;||bcv.nrcont
        END Partener,
        ag.nume||&apos; &apos;||ag.prenume agent,
        pcf.codfiscal CIF, P.Autorizatie, P.RegCom, p.codextern,
        ssoc.obs sediu,
        GETADRESA(ssoc.sector, ssoc.strada, ssoc.nr1, ssoc.nr2, ssoc.bloc, ssoc.scara, ssoc.etaj, ssoc.apart, ssoc.codpostal) adresa,
        locsoc.den_localit, judsoc.den_judet, ang.nume||&apos; &apos;||ang.prenume angajat, FCT.DENUMIRE FUNCTIE,ang.cnp, ang.biseria, ang.binr,
        GETADRESA(dang.sector,dang.strada,dang.nr1,dang.nr2,dang.bloc,dang.scara,dang.etaj,dang.apart,dang.codpostal) angadresa,
        lang.den_localit anglocalit, jang.den_judet angjudet,
        bpb.denumire bancapart, bpb.simbol sbancapart, Nvl(pb.contbanca,bcv.nrcont) contpart, pb.sucursala, locpb.den_localit bancalocalit
      FROM trezor1 t1
        INNER JOIN trezor t ON t.codtrezor = t1.codtrezor
        LEFT JOIN npers u ON u.logonname   = t.userid
        LEFT JOIN npers ag ON ag.codpers = t.agent
        LEFT JOIN npers ang ON ang.codpers = t1.codpart AND t1.obiecttranz = 2
        LEFT JOIN NPERS1 AG1 ON AG1.CODPERS = ANG.CODPERS AND T.AN*12+T.LUNA BETWEEN AG1.ALSTART AND AG1.ALSTOP
        LEFT JOIN FUNCTII FCT ON FCT.CODFUNCTIE = AG1.CODFUNCTIE
        LEFT JOIN nagenda dang ON dang.codagenda = ang.agenda
        LEFT JOIN nlocalit lang ON lang.codlocalit = dang.codlocalit
        LEFT JOIN njudet jang ON jang.codjudet = lang.codjudet
        LEFT JOIN npart p ON p.codpart = t1.codpart AND t1.obiecttranz IN (0,1)
        LEFT JOIN nbankcont bcv ON bcv.codbankcont = t1.codpart AND t1.obiecttranz = 3
        LEFT JOIN nbank bv ON bv.codbank = bcv.codbank
        LEFT JOIN npartcodfisc pcf ON pcf.codpart = p.codpart AND pcf.principal = 1
        LEFT JOIN npartb pb ON pb.codpart = p.codpart AND pb.implicit = 1
        LEFT JOIN nbank bpb ON bpb.codbank = Nvl(pb.codbank,bcv.codbank)
        LEFT JOIN nlocalit locpb ON locpb.codlocalit = Nvl(pb.codlocalit,bcv.codlocalitate)
        LEFT JOIN nagenda sedv ON t1.obiecttranz = 3 AND sedv.codbankcont = bcv.codbankcont AND NVL(sedv.inactiv, 0) = 0
        LEFT JOIN nagenda sedp ON t1.obiecttranz IN (0,1) AND sedp.codpart = p.codpart AND sedp.sediusocial IN (4,5,6,7) AND NVL(sedp.inactiv, 0) = 0
        LEFT JOIN nagenda ssoc ON ssoc.codagenda = Coalesce(sedp.CodAgenda,sedv.CodAgenda,0)
        LEFT JOIN nlocalit locsoc ON locsoc.codlocalit = ssoc.codlocalit
        LEFT JOIN njudet judsoc ON judsoc.codjudet = locsoc.codjudet
        LEFT JOIN nbankcont bc ON bc.codbankcont = t.codbanca
        LEFT JOIN nbank nb ON nb.codbank = bc.codbank
        LEFT JOIN nmonede m ON m.codmoneda = NVL(bc.codmoneda,0)
      WHERE t1.codtrezor1 = vCodTrezor1
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,            v_rec.UNUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,         v_rec.UPRENUME);
      pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,             v_rec.UCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Document cumulativ&apos;,       v_rec.NumeDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Data Document cumulativ&apos;,  v_rec.DataCumul);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Document&apos;,                 v_rec.Doc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Serie Document&apos;,           v_rec.SerieDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Document&apos;,           v_rec.NrDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Data Document&apos;,            v_rec.DataDoc);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Inregistrare&apos;,       v_rec.NrI);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Documente de legatura&apos;,    sDocLeg);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                   v_rec.Den_Moneda);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare&apos;,                  TO_CHAR(v_rec.ValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare Litere&apos;,           NumarRO(Round(v_rec.ValDoc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii Document&apos;,      v_rec.Obs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Agent incasator&apos;,          v_rec.Agent);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Tranzactie&apos;,               v_rec.Tranzactie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener &apos;,                v_rec.Partener);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CUI&apos;,             v_rec.CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Reg Com&apos;,         v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener autorizatie&apos;,     v_rec.Autorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener banca&apos;,           v_rec.bancapart);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener simbol banca&apos;,    v_rec.sbancapart);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener cont&apos;,            v_rec.contpart);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener sucursala banca&apos;, v_rec.sucursala);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Partener localitate banca&apos;,v_rec.bancalocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat &apos;,                 v_rec.Angajat);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat CNP&apos;,              v_rec.CNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat functie&apos;,          v_rec.functie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat serie doc.&apos;,       v_rec.BISeria);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat numar doc.&apos;,       v_rec.BINr);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat adresa&apos;,           v_rec.angadresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat localitate&apos;,       v_rec.anglocalit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Angajat judet&apos;,            v_rec.angjudet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu social&apos;,             v_rec.Sediu);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu social adresa&apos;,      v_rec.Adresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu social localitate&apos;,  v_rec.Den_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu social judet&apos;,       v_rec.Den_Judet);
      EXIT;
    END LOOP;
  END IF;

  COMMIT;
END;

END PKG_LIST_BASE_DOCTREZOR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCVOUCHRETR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>179413B84088F79936003AD569054D7668C1A193</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCVOUCHRETR IS

  vCodDoc  number(20);
  vTipDoc    number(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER DEFAULT NULL, pTipDoc IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodDoc := pCodDoc;
  vTipDoc   := pTipDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  gSuplCols := &apos;&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(SESSIONID, STARTEDAT, REFUND, VOUCHERBARCODE&apos;||gUserFields||&apos;)
  SELECT
    rt.SESSIONID,  rt.STARTEDAT,  rt.REFUND,  rt.VOUCHERBARCODE&apos;||gUserAlias||&apos;
   FROM returo rt &apos;
   ||gSuplJoins||&apos;
  WHERE rt.tipdoc = &apos;||vTipDoc||&apos; and rt.coddoc = &apos;||vCodDoc;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_DOCVOUCHRETR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCVOUCHRRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>784DFE586A134C3EAFA65BD98BDAD9B6101B2E6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCVOUCHRRET IS

  vCodDoc  number(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  gSuplCols := &apos;&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(STARTEDAT, DATACREARE, REFUND, VOUCHERBARCODE&apos;||gUserFields||&apos;)
  SELECT
    sgrc.data, sgrc.datacreare, sgrc.valoare, sgrc.voucherbarcode &apos;||gUserAlias||&apos;
   FROM SGRCOLECT sgrc &apos;
   ||gSuplJoins||&apos;
  WHERE sgrc.codsgrcolect = &apos;||vCodDoc;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_DOCVOUCHRRET;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCWCF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22CC7196E03155FF256B26A6DD33B0818B8EC2C4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCWCF IS

  vCodDoc     WEEKCASHFLOW.CODCASHFLOW%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;WEEKCASHFLOW W, WEEKCASHFLOW1 W1, NPART P, NSUBUNIT S&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Ordine,
    Categorie,
    Denumire, SimbolCont, Valoare, Restante,
    week01, week02, week03, week04, week05, week06, week07, week08, week09, week10, week11, week12, week13,
    week14, week15, week16, week17, week18, week19, week20, week21, week22, week23, week24, week25, week26,
    week27, week28, week29, week30, week31, week32, week33, week34, week35, week36, week37, week38, week39,
    week40, week41, week42, week43, week44, week45, week46, week47, week48, week49, week50, week51, week52,
    week52p,
    TipCF&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    Row_Number() Over (Order By W1.IndexTipLinie, W1.IndexLocal) Ordine,
    Decode(
      To_Number(W1.IndexTipLinie),
      00, &apos;&apos;Sold initial de numerar&apos;&apos;,
      01, &apos;&apos;Incasari&apos;&apos;,
      02, &apos;&apos;Incasari din vanzari&apos;&apos;,
      03, &apos;&apos;Plati&apos;&apos;,
      04, &apos;&apos;Achizitie de stocuri&apos;&apos;,
      05, &apos;&apos;Total cash operational&apos;&apos;,
      06, &apos;&apos;...nedefinit...&apos;&apos;,
      07, &apos;&apos;Alte plati&apos;&apos;,
      08, &apos;&apos;...nedefinit...&apos;&apos;,
      09, &apos;&apos;Rambursari&apos;&apos;,
      10, &apos;&apos;...nedefinit...&apos;&apos;,
      11, &apos;&apos;Investitii disponibil&apos;&apos;,
      12, &apos;&apos;Investitii plati&apos;&apos;,
      13, &apos;&apos;...nedefinit...&apos;&apos;,
      14, &apos;&apos;Linii suplimentare&apos;&apos;,
      15, &apos;&apos;Sold final&apos;&apos;,
      16, &apos;&apos;Estimari productie - vanzari&apos;&apos;,
      17, &apos;&apos;Estimari productie - achizitii&apos;&apos;,
      &apos;&apos;...nedefinit...&apos;&apos;
    ) Categorie,
    W1.Denumire, W1.SimbolCont, W1.Valoare, W1.Restante,
    W1.week1,  W1.week2,  W1.week3,  W1.week4,  W1.week5,  W1.week6,  W1.week7,  W1.week8,  W1.week9,  W1.week10, W1.week11, W1.week12, W1.week13,
    W1.week14, W1.week15, W1.week16, W1.week17, W1.week18, W1.week19, W1.week20, W1.week21, W1.week22, W1.week23, W1.week24, W1.week25, W1.week26,
    W1.week27, W1.week28, W1.week29, W1.week30, W1.week31, W1.week32, W1.week33, W1.week34, W1.week35, W1.week36, W1.week37, W1.week38, W1.week39,
    W1.week40, W1.week41, W1.week42, W1.week43, W1.week44, W1.week45, W1.week46, W1.week47, W1.week48, W1.week49, W1.week50, W1.week51, W1.week52,
    W1.peste52,
    Decode(W.TIP,0,&apos;&apos;Estimativ&apos;&apos;,&apos;&apos;Operational&apos;&apos;) TIPCF&apos;||
    gUserAlias||&apos;
  FROM WEEKCASHFLOW W
    INNER JOIN WEEKCASHFLOW1 W1 ON W1.CODCASHFLOW = W.CODCASHFLOW
    LEFT  JOIN NPART P ON P.CODPART = W1.CODPART
    LEFT  JOIN NSUBUNIT S ON S.CODSUBUNIT = W.SUBUNITATEA &apos;||
    gSuplJoins||&apos;
  WHERE W.CODCASHFLOW = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT W.NRDOC, W.DATADOC, W.SAPTAMANA, S.DEN_SUBUNIT
    FROM WEEKCASHFLOW W INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = W.SUBUNITATEA
    WHERE W.CODCASHFLOW = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR&apos;,             v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATA&apos;,           v_rec.datadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SAPTAMANA&apos;,      v_rec.saptamana);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATEA&apos;,    v_rec.den_subunit);
    EXIT;
  END LOOP;

  COMMIT;
END;

end PKG_LIST_BASE_DOCWCF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DOCWCFP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>401CB27506B55D9D4607978DD981E7FB7FF66166</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_DOCWCFP IS

  vCodDoc     WEEKCASHFLOW.CODCASHFLOW%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  vBancaSitV NUMBER;
  sCurs      VARCHAR2(1000) := &apos;1&apos;;
BEGIN
  gSuplCols := &apos;WEEKCASHFLOW W, WEEKCASHFLOW1 W1, WEEKCASHPLATI WP, NPART P, NMONEDE M, OBLIGPIF O, GENERAL G&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NSUBUNIT&apos;, &apos;S&apos;, &apos;S.CODSUBUNIT = W.SUBUNITATEA&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vBancaSitV :=  pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  IF Nvl(vBancaSitV,0) &gt; 0 THEN
    sCurs := &apos;CASE WHEN Nvl(G.Moneda,0) &gt; 0 THEN PKG_MONEDE.GETCURSMONEDA(G.Moneda, &apos;||vBancaSitV||&apos;, W.DATADOC) ELSE 1 END&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    PART, PREFIXDOC, NRDOC, DATADOC, SIMBOLCONT, SIMBOLMONEDA,
    RESTOBLIGRAMAS, SUMAPLATA, TERMENOBLIG, DATAPLATA,
    CURS,
    TIPCF&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    P.DEN_PART, WP.PREFIXDOC, WP.NRDOC, WP.DATADOC, W1.SIMBOLCONT, M.Simbol SIMBOLMONEDA,
    WP.RESTOBLIG - WP.SUMAPLATA RESTOBLIGRAMAS, WP.SUMAPLATA, WP.TERMENOBLIG, WP.DATAPLATA,
    &apos;||sCurs||&apos; CURS,
    Decode(W.TIP,0,&apos;&apos;Estimativ&apos;&apos;,&apos;&apos;Operational&apos;&apos;) TIPCF&apos;||
    gUserAlias||&apos;
  FROM WEEKCASHFLOW W
    INNER JOIN WEEKCASHFLOW1 W1 ON W1.CODCASHFLOW = W.CODCASHFLOW
    INNER JOIN WEEKCASHPLATI WP ON WP.CODCASHFLOW1 = W1.CODCASHFLOW1
    LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = WP.CODOBLIGPIF
    LEFT JOIN NPART P ON P.CODPART = O.CODPART
    LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
    LEFT JOIN NMONEDE M ON M.CODMONEDA = Nvl(G.MONEDA,0)&apos;||
    gSuplJoins||&apos;
  WHERE W.CODCASHFLOW = &apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||TMPNAME||&apos; SET RESTOBLIGLEI = RESTOBLIGRAMAS*CURS, SUMAPLATALEI = SUMAPLATA*CURS&apos;;

  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT W.NRDOC, W.DATADOC, W.SAPTAMANA, S.DEN_SUBUNIT
    FROM WEEKCASHFLOW W INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = W.SUBUNITATEA
    WHERE W.CODCASHFLOW = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR&apos;,             v_rec.nrdoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATA&apos;,           v_rec.datadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SAPTAMANA&apos;,      v_rec.saptamana);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATEA&apos;,    v_rec.den_subunit);
    EXIT;
  END LOOP;

  COMMIT;
END;

end PKG_LIST_BASE_DOCWCFP;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DREPTUSERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46270B1208A46A373ED36BFE18EFE6752B57D29C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_dreptuseri IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE processList(tmpname in varchar2, listid in number default 0, listver in number default 0) is
  sInsert varchar2(30000);
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(LISTID,listver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos; (
    UTILIZATOR, GRUP, OPERATIE, PROT,
    MODUL, ORDMODUL,
    TIP,
    TIPFUNCTIE,
    ACCES,
    DETALIU,
    ADAUGARE,
    EDITARE,
    STERGERE,
    FILTRUVID,
    ORDINE,
    CODFUNCTIE&apos;||gUserFields||&apos;)
  SELECT
    USERNAMES, GRUP, OPERATIE, PROT,
    DECODE(modul,1,&apos;&apos;MENTOR&apos;&apos;,2,&apos;&apos;SERVICE&apos;&apos;,3,&apos;&apos;SALARII&apos;&apos;,4,&apos;&apos;COMERCIAL&apos;&apos;,5,&apos;&apos;PRODUCTIE&apos;&apos;,6,&apos;&apos;EXPERT&apos;&apos;,7,&apos;&apos;CRM&apos;&apos;,8,&apos;&apos;ALTE MODULE&apos;&apos;) MODUL, modul ORDMODUL,
    DECODE(date_liste,1,&apos;&apos;DATE&apos;&apos;,2,&apos;&apos;LISTE&apos;&apos;) TIP,
    DECODE(tipfunctie,1,&apos;&apos;VIEW&apos;&apos;,3,&apos;&apos;MACHETA&apos;&apos;) TIPFUNCTIE,
    DECODE(BITAND(Acces, 1), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) Acces,
    DECODE(BITAND(Acces, 2), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) Detaliu,
    DECODE(BITAND(Acces, 4), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) Adauga,
    DECODE(BITAND(Acces, 8), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) Editare,
    DECODE(BITAND(Acces,16), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) Sterge,
    DECODE(BITAND(Acces,32), 0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) FiltruVid,
    ORDINE,
    CODFUNCTIE&apos;||gUserAlias||&apos;
  FROM TABLE(WINMADMIN.PKG_USERFIRME.list_pipe_usersrights)&apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, ListID, ListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_DREPTUSERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DURATAMEDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5F5D02ABAD7023B9F2C8D6F79AF93FF0A0A2FF1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_duratamedcli IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelectD   VARCHAR2(20000);
  sSelectI   VARCHAR2(20000);
  vDataIni   DATE    := pkg_list_alegperioada.getDataS;
  vDataFin   DATE    := pkg_list_alegperioada.getDataF;
  vLei       INTEGER := 0;
  sNrZile    VARCHAR2(5) := To_Char(vDataFin - vDataIni + 1);
BEGIN

  gSuplCols := &apos;nartobj nao, nart a, npart p, nclasep cp, nclasea ca, npart prod, nmonede m, ncont c&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_alegperioada.Anual
  THEN sNrZile := &apos;365&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1
  THEN vLei := 1;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, Doc, Moneda, Part, DenClasaP, ContP, Agent,
    Art, DenClasaA, CodIntern, CodExtern, Producator,
    SoldIni, SoldFin, SoldIniT, SoldFinT,
    ValVanz, ValDisc, ZilePer &apos;||gUserFields||&apos;) &apos;;

  sSelectI := &apos;
  SELECT
    NULL, NULL, t.doc, m.den_moneda, p.den_part, cp.den_clasep, c.simbol, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume,
    &apos;&apos;...nedefinit...&apos;&apos;, ca.den_clasea, nao.codintern, nao.codextern, prod.den_part,
    t.soldini, t.soldfin, t.soldinit, t.soldfin, t.valoare, 0, &apos;||sNrZile||gUserAlias||&apos;
  FROM tmp_list_duratamed t
    INNER JOIN iesiri i ON i.codies = t.coddoc
    LEFT JOIN npart p ON p.codpart = nvl(i.partener,0)
    LEFT JOIN nartobj nao ON nao.codobiect = 0
    LEFT JOIN nart a ON a.codarticol = nvl(nao.codarticol,0)
    LEFT JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT JOIN npers ag ON ag.codpers = i.agent
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart prod ON prod.codpart = nao.codproducator
    LEFT JOIN nmonede m ON m.codmoneda = t.codmoneda
    LEFT JOIN ncont c ON c.codcont = t.codcont&apos;||
    gSuplJoins||&apos;
  WHERE t.initializari = 1&apos;;


  sSelectD := &apos;
  WITH i AS (
    SELECT
      t.codmoneda, t.doc, t.codcont, t.valoare, t.soldini, t.soldfin, t.soldinit, t.soldfint,
      i.codies, i.tipdoc, i.partener, i.agent, i1.tiplinie, i1.codobiect, i1.contdiscount,
      CASE WHEN NOT i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN &apos;&apos;&apos;&apos; WHEN i1.cant &gt; 0 THEN &apos;&apos;Majorare&apos;&apos; ELSE &apos;&apos;Discount&apos;&apos; END tipdisc, NVL(i1.codcriteriu,0) codcriteriu,
      DECODE(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 21 THEN Sum(i1.restfact)
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(i1.restfact + nvl(i1.tva,0))
          WHEN i.tipdoc = 21 THEN Sum(i1.pu * i1.cant * (1 + nvl(i1.procdisc/100,0)) )
          ELSE Sum((i1.pu * i1.cant + nvl(i1.tva,0))  * (1 + nvl(i1.procdisc/100,0)) )
        END /i.valdoc) coeflin,
      DECODE(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(nvl(i1.tva,0))
          WHEN i.tipdoc = 21 THEN Sum(i1.pu * i1.cant + nvl(i1.tva,0) * nvl(i1.procdisc/100,0))
          ELSE Sum(i1.pu * i1.cant + nvl(i1.tva,0) * (1 + nvl(i1.procdisc/100,0)))
        END /i.valdoc) coefobj,
      DECODE(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 21 THEN Sum(i1.restfact - nvl(i1.tva,0))
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(i1.restfact)
          WHEN i.tipdoc = 21 THEN Sum((i1.pu * i1.cant - nvl(i1.tva,0)) * nvl(i1.procdisc/100,0) )
          ELSE Sum( i1.pu * i1.cant * nvl(i1.procdisc/100,0) )
        END /i.valdoc) coefdisc
    FROM tmp_list_duratamed t
      INNER JOIN iesiri i ON i.codies = t.coddoc
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    GROUP BY
      t.codmoneda, t.doc, t.codcont, t.valoare, t.soldini, t.soldfin, t.soldinit, t.soldfint,
      i.codies, i.tipdoc, i.partener, i.agent, i.valdoc, i.tvadoc, i1.tiplinie, i1.codobiect, i1.contdiscount, i1.codcriteriu,
      CASE WHEN NOT i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN &apos;&apos;&apos;&apos; WHEN i1.cant &gt; 0 THEN &apos;&apos;Majorare&apos;&apos; ELSE &apos;&apos;Discount&apos;&apos; END)
  SELECT
    i.codies, i.tipdoc, i.doc, m.den_moneda, p.den_part, cp.den_clasep, c.simbol, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume,
    CASE
      WHEN i.codcriteriu = 0 AND i.tiplinie = &apos;&apos;G&apos;&apos; AND i.contdiscount &lt;&gt; 0 THEN i.tipdisc||&apos;&apos; direct pe cont (de grup) (&apos;&apos; ||cd.simbol||&apos;&apos;)&apos;&apos;
      WHEN i.codcriteriu = 0 AND i.tiplinie = &apos;&apos;T&apos;&apos; AND i.contdiscount &lt;&gt; 0 THEN i.tipdisc||&apos;&apos; direct pe cont (de total) (&apos;&apos;||cd.simbol||&apos;&apos;)&apos;&apos;
      WHEN i.codcriteriu = 2 AND i.tiplinie IN (&apos;&apos;G&apos;&apos;, &apos;&apos;T&apos;&apos;) THEN i.tipdisc||&apos;&apos; client &apos;&apos;
      WHEN i.tiplinie IN (&apos;&apos;G&apos;&apos;, &apos;&apos;T&apos;&apos;) THEN i.tipdisc||&apos;&apos;: &apos;&apos; || critd.dencriteriu
      ELSE nao.denumire
    END,
    ca.den_clasea, nao.codintern, nao.codextern, prod.den_part,
    i.coeflin * i.soldini, i.coeflin * i.soldfin, i.coeflin * i.soldinit, i.coeflin * i.soldfin, i.coefobj * i.valoare, i.coefdisc * i.valoare, &apos;||sNrZile||gUserAlias||&apos;
  FROM i
    INNER JOIN npart p ON p.codpart = i.partener
    LEFT JOIN nartobj nao ON nao.codobiect = i.codobiect
    LEFT JOIN nart a ON a.codarticol = nao.codarticol
    LEFT JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT JOIN npers ag ON ag.codpers = i.agent
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart prod ON prod.codpart = nao.codproducator
    LEFT JOIN nmonede m ON m.codmoneda = i.codmoneda
    LEFT JOIN ncont c ON c.codcont = i.codcont
    LEFT JOIN ncont cd ON cd.codcont = i.contdiscount
    LEFt JOIN criteriidisc critd ON critd.codcriteriu = i.codcriteriu&apos;||
    gSuplJoins;

  DELETE TMP_LIST_DURATAMED;

  INSERT INTO TMP_LIST_DURATAMED (CODDOC, CODMONEDA, DOC, INITIALIZARI, DATADOC, CODCONT, VALOARE, SOLDINI, SOLDFIN, SOLDINIT, SOLDFINT)
  WITH
    stins AS (
      SELECT
        s.codstinspif,
        SUM( (CASE
                WHEN COALESCE(i.datadoc,t1.datadoc,c.datadoc) &gt;= vDataIni THEN 0
                WHEN O.SEMNIFICATIE IN (211,420,751,1300) AND OSTINS.SEMNIFICATIE &lt;&gt; 600 THEN -1
                ELSE 1
              END) * s.valoare
            ) val_ini,
        SUM( (CASE WHEN O.SEMNIFICATIE IN (211,420,751,1300) AND OSTINS.SEMNIFICATIE &lt;&gt; 600 THEN -1 ELSE 1 END) * s.valoare) val
      FROM stingere s
        INNER JOIN obligpif o ON o.codobligpif = s.codstingatorpif
        INNER JOIN obligpif ostins ON ostins.codobligpif = s.codstinspif
        INNER JOIN general g ON  g.codgeneral = o.codgeneral
        LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29,30,31,33)
        LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
        LEFT JOIN iesiri i ON i.codies = g.coddoc AND O.SEMNIFICATIE IN (211)
      WHERE COALESCE(i.datadoc,t1.datadoc,c.datadoc) &lt;= vDataFin
      GROUP BY s.codstinspif ),
    scadentar AS (
  		SELECT o.codobligpif, d.codies, nvl(o.termen,d.datadoc) termen, o.valoare * DECODE(o.semnificatie,210,-1,1) valoare,
        CASE WHEN vLei = 1 THEN 0 ELSE g.moneda END moneda,
        Decode(o.semnificatie,1303,&apos;Litigiu&apos;,nvl(d.PREFIXDOC,&apos;F&apos;))||d.nrdoc||&apos;/&apos;||d.datadoc doc, d.initializari, d.datadoc,
        PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,pkg_globals.AnLunaLucru,o.semnificatie) cont,
        CASE WHEN vLei = 1 THEN DECODE(g.curs,NULL,1,0,1,g.curs) ELSE 1 END curs
      FROM obligpif o
        INNER JOIN general g ON g.codgeneral = o.codgeneral AND g.tipdoc IN (19,21,22,26)
        INNER JOIN iesiri d ON d.codies = g.coddoc
      WHERE o.semnificatie IN (200,/*210,*/1303)
        AND d.datadoc &lt;= vDataFin
        AND d.anulat = 0 AND d.operat = 1
        AND ((PKG_GLOBALS.GETSUBUNITATE = d.subunitatea) OR (PKG_GLOBALS.GETSUBUNITATE = 1 AND d.subunitatea IN (SELECT CodSubunit FROM tmp_subunitdedicate)))
    )
  SELECT
    s.codies, Nvl(s.moneda,0) moneda, s.doc, s.initializari, s.datadoc, Nvl(s.cont,0) cont,
    Sum(CASE WHEN s.DataDoc BETWEEN vDataIni AND vDataFin THEN s.valoare ELSE 0 END * s.Curs) valoare,
    Sum(CASE WHEN s.DataDoc &gt;= vDataIni THEN 0 ELSE s.valoare - nvl(stins.val_ini,0) END * s.Curs) soldini,
    Sum((s.valoare - nvl(stins.val,0)) * s.Curs) soldfin,
    Sum(CASE WHEN s.Termen &lt; vDataIni OR s.DataDoc &gt;= vDataIni THEN 0 ELSE s.Valoare END * s.Curs) soldinit,
    Sum(CASE WHEN s.Termen &gt; vDataFin THEN s.Valoare ELSE 0 END * s.Curs) soldfint
  FROM scadentar s LEFT JOIN stins ON stins.codstinspif = s.codobligpif
  WHERE (CASE WHEN s.DataDoc &gt;= vDataIni THEN 0 ELSE s.valoare - nvl(stins.val_ini,0) END) &lt;&gt; 0
      OR (s.valoare - nvl(stins.val,0)) &lt;&gt; 0
      OR (CASE WHEN s.Termen &lt; vDataIni OR s.DataDoc &gt;= vDataIni THEN 0 ELSE s.Valoare END) &lt;&gt; 0
      OR (CASE WHEN s.Termen &gt; vDataFin THEN s.Valoare ELSE 0 END) &lt;&gt; 0
      OR s.DataDoc BETWEEN vDataIni AND vDataFin
  GROUP BY s.codies, s.moneda, s.doc, s.initializari, s.datadoc, s.cont;

  DELETE TMP_LIST_DURATAMED WHERE NOT (Round(soldini,2) &lt;&gt; 0 OR Round(soldfin,2)  &lt;&gt; 0 OR Round(soldinit,2) &lt;&gt; 0 OR Round(soldfint,2) &lt;&gt; 0 OR DataDoc BETWEEN vDataIni AND vDataFin);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelecti, aListID, aListVer);
  DELETE TMP_LIST_DURATAMED WHERE initializari = 1;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectd, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_DurataMedCli;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_DURATAMEDFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60E823E68EC3F19667B7190F517C787C85ABC2C7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_duratamedfurn IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelectD   VARCHAR2(20000);
  sSelectI   VARCHAR2(20000);
  vDataIni   DATE    := pkg_list_alegperioada.getDataS;
  vDataFin   DATE    := pkg_list_alegperioada.getDataF;
  vLei       INTEGER := 0;
  sNrZile    VARCHAR2(5) := To_Char(vDataFin - vDataIni + 1);
BEGIN
  gSuplCols := &apos;nartobj nao, nart a, npart p, nclasep cp, nclasea ca, npart prod, nmonede m, intrari intr&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_alegperioada.Anual
  THEN sNrZile := &apos;365&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1
  THEN vLei := 1;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, Doc, Moneda, Part, DenClasaP, ContP, Art, DenClasaA, CodIntern, CodExtern, Producator,
    SoldIni, SoldFin, SoldIniT, SoldFinT,
    ValAchiz, ValDisc, ZilePer &apos;||gUserFields||&apos;) &apos;;

  sSelectI := &apos;
  SELECT
    NULL, NULL, t.doc, m.den_moneda, p.den_part, cp.den_clasep, c.simbol, &apos;&apos;...nedefinit...&apos;&apos;, ca.den_clasea, nao.codintern, nao.codextern, prod.den_part,
    t.soldini, t.soldfin, t.soldinit, t.soldfin, t.valoare, 0, &apos;||sNrZile||gUserAlias||&apos;
  FROM tmp_list_duratamed t
    INNER JOIN intrari intr ON intr.codintr = t.coddoc
    LEFT JOIN npart p ON p.codpart = nvl(intr.partener,0)
    LEFT JOIN nartobj nao ON nao.codobiect = 0
    LEFT JOIN nart a ON a.codarticol = NVL(nao.codarticol,0)
    LEFT JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart prod ON prod.codpart = nao.codproducator
    LEFT JOIN nmonede m ON m.codmoneda = t.codmoneda
    LEFT JOIN ncont c ON c.codcont = t.codcont&apos;||
    gSuplJoins||&apos;
  WHERE t.initializari = 1&apos;;

  sSelectD := &apos;
  WITH i AS   (
    SELECT
      t.codmoneda, t.doc, t.codcont, t.valoare, t.soldini, t.soldfin, t.soldinit, t.soldfint,
      i.codintr, i.tipdoc, i.partener, i1.tiplinie, i1.codobiect, i1.contdiscount,
      CASE WHEN NOT i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN &apos;&apos;&apos;&apos; WHEN i1.cant &gt; 0 THEN &apos;&apos;Majorare&apos;&apos; ELSE &apos;&apos;Discount&apos;&apos; END tipdisc,
      Decode(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 3 THEN Sum(i1.restfact)
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(i1.restfact + nvl(i1.tva,0))
          WHEN i.tipdoc = 3 THEN Sum(i1.pu * i1.cant)
          ELSE Sum(i1.pu * i1.cant + nvl(i1.tva,0))
        END /i.valdoc) coeflin,
      Decode(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(nvl(i1.tva,0))
          WHEN i.tipdoc = 3 THEN Sum(i1.pu * i1.cant)
          ELSE Sum(i1.pu * i1.cant + nvl(i1.tva,0))
        END /i.valdoc) coefobj,
      Decode(i.valdoc,0,0,
        CASE
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 3 THEN Sum(i1.restfact - nvl(i1.tva,0))
          WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN Sum(i1.restfact)
          ELSE 0
        END /i.valdoc) coefdisc
    FROM TMP_LIST_DURATAMED t
      INNER JOIN intrari i ON i.codintr = t.coddoc
      INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    WHERE NOT (i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND NVL(i1.contdiscount, 0) = 0)
    GROUP BY
      t.codmoneda, t.doc, t.codcont, t.valoare, t.soldini, t.soldfin, t.soldinit, t.soldfint,
      i.codintr, i.tipdoc, i.partener, i.valdoc, i.tvadoc, i1.tiplinie, i1.codobiect, i1.contdiscount,
      CASE WHEN NOT i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN &apos;&apos;&apos;&apos; WHEN i1.cant &gt; 0 THEN &apos;&apos;Majorare&apos;&apos; ELSE &apos;&apos;Discount&apos;&apos; END
  )
  SELECT
    i.codintr, i.tipdoc, i.doc, m.den_moneda, p.den_part, cp.den_clasep, c.simbol,
    CASE
      WHEN TIPLINIE = &apos;&apos;G&apos;&apos; THEN i.tipdisc||&apos;&apos; direct pe cont (de grup) (&apos;&apos; ||cd.simbol||&apos;&apos;)&apos;&apos;
      WHEN TIPLINIE = &apos;&apos;T&apos;&apos; THEN i.tipdisc||&apos;&apos; direct pe cont (de total) (&apos;&apos;||cd.simbol||&apos;&apos;)&apos;&apos;
      ELSE nao.denumire
    END,
    ca.den_clasea, nao.codintern, nao.codextern, prod.den_part,
    i.coeflin * i.soldini, i.coeflin * i.soldfin, i.coeflin * i.soldinit, i.coeflin * i.soldfin, i.coefobj * i.valoare, i.coefdisc * i.valoare, &apos;||sNrZile||gUserAlias||&apos;
  FROM i
    INNER JOIN INTRARI INTR ON INTR.CODINTR = I.CODINTR
    INNER JOIN npart p ON p.codpart = i.partener
    LEFT JOIN nartobj nao ON nao.codobiect = i.codobiect
    LEFT JOIN nart a ON a.codarticol = nao.codarticol
    LEFT JOIN nclasep cp ON cp.codclasep = p.codclasa
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN npart prod ON prod.codpart = nao.codproducator
    LEFT JOIN nmonede m ON m.codmoneda = i.codmoneda
    LEFT JOIN ncont c ON c.codcont = i.codcont
    LEFT JOIN ncont cd ON cd.codcont = i.contdiscount&apos;||
    gSuplJoins;

  DELETE TMP_LIST_DURATAMED;

  INSERT INTO TMP_LIST_DURATAMED (CODDOC, CODMONEDA, DOC, INITIALIZARI, DATADOC, CODCONT, VALOARE, SOLDINI, SOLDFIN, SOLDINIT, SOLDFINT)
  WITH
    stins AS (
      SELECT
        s.codstinspif,
        SUM( (CASE
                WHEN COALESCE(i.datadoc,t1.datadoc,c.datadoc) &gt;= vDataIni THEN 0
                WHEN O.SEMNIFICATIE IN (111,320,701,1350) AND OSTINS.SEMNIFICATIE &lt;&gt; 500 THEN -1
                ELSE 1
              END) * s.valoare
            ) val_ini,
        SUM( (CASE WHEN O.SEMNIFICATIE IN (111,320,701,1350) AND OSTINS.SEMNIFICATIE &lt;&gt; 500 THEN -1 ELSE 1 END) * s.valoare) val
      FROM stingere s
        INNER JOIN obligpif o ON o.codobligpif = s.codstingatorpif
        INNER JOIN obligpif ostins ON ostins.codobligpif = s.codstinspif
        INNER JOIN general g ON  g.codgeneral = o.codgeneral
        LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29,30,31,33)
        LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
        LEFT JOIN intrari i ON i.codintr = g.coddoc AND O.SEMNIFICATIE IN (111)
      WHERE COALESCE(i.datadoc,t1.datadoc,c.datadoc) &lt;= vDataFin
      GROUP BY s.codstinspif ),
    scadentar AS (
      /* FACTURI */
  		SELECT o.codobligpif, d.codintr, nvl(o.termen,d.datadoc) termen, o.valoare * DECODE(o.semnificatie,110,-1,1) valoare,
        CASE WHEN vLei = 1 THEN 0 ELSE g.moneda END moneda,
        nvl(d.PREFIXDOC,&apos;F&apos;)||d.nrdoc||&apos;/&apos;||d.datadoc doc, d.Initializari, d.datadoc,
        PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,pkg_globals.AnLunaLucru,o.semnificatie) cont,
        CASE WHEN vLei = 1 THEN DECODE(g.curs,NULL,1,0,1,g.curs) ELSE 1 END curs
      FROM obligpif o
        INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (1,3,4,5,9)
        INNER JOIN intrari d ON d.codintr = g.coddoc
      WHERE o.semnificatie IN (100/*,110*/)
        AND d.datadoc &lt;= vDataFin
        AND d.anulat = 0 AND d.operat = 1
        AND ((PKG_GLOBALS.GETSUBUNITATE = d.subunitatea) OR (PKG_GLOBALS.GETSUBUNITATE = 1 AND d.subunitatea IN (SELECT CodSubunit FROM tmp_subunitdedicate)))
      UNION ALL
      /* FACTURI EXTERNE  -- PLATI VAMA*/
  		SELECT o.codobligpif, i.codintr, nvl(o.termen,d.datadoc) termen, o.valoare,
        CASE WHEN vLei = 1 THEN 0 ELSE g.moneda END moneda,
        &apos;DVI&apos;||d.nrdoc||&apos;/&apos;||d.datadoc doc, i.Initializari, d.datadoc,
        PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,pkg_globals.AnLunaLucru,o.semnificatie) cont,
        CASE WHEN vLei = 1 THEN DECODE(g.curs,NULL,1,0,1,g.curs) ELSE 1 END curs
      FROM obligpif o
        INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 5
        INNER JOIN dvi d ON d.coddvi = g.coddoc
        INNER JOIN intrari i ON i.codintr = d.codintr
      WHERE o.semnificatie = 130
        AND d.datadoc &lt;= vDataFin
        AND o.codpart = i.partener
        AND i.anulat = 0 AND i.operat = 1
        AND ((PKG_GLOBALS.GETSUBUNITATE = i.subunitatea) OR (PKG_GLOBALS.GETSUBUNITATE = 1 AND i.subunitatea IN (SELECT CodSubunit FROM tmp_subunitdedicate)))
    )
  SELECT
    s.codintr, Nvl(s.moneda,0) moneda, s.doc, s.initializari, s.datadoc, Nvl(s.cont,0) cont,
    Sum(CASE WHEN s.DataDoc BETWEEN vDataIni AND vDataFin THEN s.valoare ELSE 0 END * s.Curs) valoare,
    Sum(CASE WHEN s.DataDoc &gt;= vDataIni THEN 0 ELSE s.valoare - nvl(stins.val_ini,0) END * s.Curs) soldini,
    Sum((s.valoare - nvl(stins.val,0))  * s.Curs) soldfin,
    Sum(CASE WHEN s.Termen &lt; vDataIni OR s.DataDoc &gt;= vDataIni THEN 0 ELSE s.Valoare END * s.Curs) soldinit,
    Sum(CASE WHEN s.Termen &gt; vDataFin THEN s.Valoare ELSE 0 END * s.Curs) soldfint
  FROM scadentar s LEFT JOIN stins ON stins.codstinspif = s.codobligpif
  WHERE (CASE WHEN s.DataDoc &gt;= vDataIni THEN 0 ELSE s.valoare - nvl(stins.val_ini,0) END) &lt;&gt; 0
      OR (s.valoare - nvl(stins.val,0)) &lt;&gt; 0
      OR (CASE WHEN s.Termen &lt; vDataIni OR s.DataDoc &gt;= vDataIni THEN 0 ELSE s.Valoare END) &lt;&gt; 0
      OR (CASE WHEN s.Termen &gt; vDataFin THEN s.Valoare ELSE 0 END) &lt;&gt; 0
      OR s.DataDoc BETWEEN vDataIni AND vDataFin
  GROUP BY s.codintr, s.moneda, s.doc, s.Initializari, s.DataDoc, s.Cont;

  DELETE TMP_LIST_DURATAMED WHERE NOT (Round(soldini,2) &lt;&gt; 0 OR Round(soldfin,2)  &lt;&gt; 0 OR Round(soldinit,2) &lt;&gt; 0 OR Round(soldfint,2) &lt;&gt; 0 OR DataDoc BETWEEN vDataIni AND vDataFin);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelecti, aListID, aListVer);
  DELETE TMP_LIST_DURATAMED WHERE initializari = 1;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectd, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_DurataMedFurn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EFECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F55826CDEBF0A76F53D26DFE19B678509F27C84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EFECTE IS

  vTipTranz    NUMBER;
  vPeDocumente BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataS       DATE;
  vDataF       DATE;
  
PROCEDURE SETPARAMS(pTipTranz IN NUMBER, 
                      pPeDocumente IN NUMBER  DEFAULT 0,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 ,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2
                      )IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vTipTranz    := pTipTranz;
  vPeDocumente := pPeDocumente = 1;
END;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(1000);
  sSelect       VARCHAR2(30000);
  sSemnificatie VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;trezor t, trezor1 t1, general g, obligpif ofact, nmonede nm, npart p, npartcodfisc cf, nlocalit nlocpart, nbank bk, nbankcont bc, npartb bp, nbank bkp&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vTipTranz = 0
  THEN sSemnificatie := &apos;500&apos;;
  ELSE sSemnificatie := &apos;600&apos;;
  END IF;

  IF NOT vPeDocumente THEN
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, NUMEPART, SIMBOLMONEDA, DOC, NRDOC, DATADOC, NDOC, VALOARE, TERMEN,
      REST,
      BANCA, LocPart, CUIPart, RegComPart,
      Subunitatea, DocCumulativ, DataCumulativ, ValoareStins,
      AgentInc,
      CF_AS, CF_CURS, CF_VALOARE&apos;||gUserFields||&apos;)&apos;;

    sSelect :=&apos;
    SELECT
      T.CODTREZOR, T1.CODTREZOR1, T.TipDoc, P.DEN_PART, M.SIMBOL, T1.DOC, T1.NRDOC, T1.DATADOC, T1.NRDOC||&apos;&apos;/&apos;&apos;||to_char(T1.DATADOC, &apos;&apos;dd.mm.yyyy&apos;&apos;), T1.VALDOC, T1.DATADECONT,
      CASE WHEN T1ST.AN * 12 + T1ST.LUNA = PKG_GLOBALS.ANLUNALUCRU THEN 0 ELSE T1.VALDOC END REST,
      BK.SIMBOL||&apos;&apos; &apos;&apos;||BC.DEN_CONT, NLOCPART.DEN_LOCALIT, CF.CODFISCAL, P.REGCOM,
      SUB.Den_Subunit, T.NUMEDOC, T.DATADOC, T1ST.VALDOC,
      CASE WHEN AGINC.CODPERS &lt;&gt; 0 THEN AGINC.NUME||&apos;&apos; &apos;&apos;||AGINC.PRENUME ELSE AGINC.NUME END,
      TO_CHAR( Coalesce(T1.DATADECONT, O.Termen, T1.DataDoc),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Nvl(cfc.valoare,1) CF_CURS, T1.VALDOC*Nvl(cfc.valoare,1) CF &apos;||gUserAlias||&apos;
    FROM TREZOR T
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.TIPDOC = T.TIPDOC AND G.SEMNIFICATIE = &apos;||sSemnificatie||&apos;
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN NPART P ON P.CODPART = O.CODPART
      INNER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
      INNER JOIN NBANK BK ON BK.CODBANK = BC.CODBANK
      INNER JOIN NMONEDE M ON M.CODMONEDA = BC.CODMONEDA
      LEFT JOIN NPARTB BP ON BP.CODPART = O.CODPART AND BP.IMPLICIT = 1
      LEFT JOIN NBANK BKP ON BKP.CODBANK = BP.CODBANK
      LEFT JOIN NSUBUNIT SUB ON T.SUBUNITATEA = SUB.CODSUBUNIT
      LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT JOIN GENERAL GST ON GST.CODGENERAL = OST.CODGENERAL
      LEFT JOIN TREZOR1 T1ST ON T1ST.CODTREZOR1 = GST.CODDOC
      LEFT JOIN NPARTCODFISC CF ON P.CODPART = CF.CODPART AND NVL(CF.PRINCIPAL, 0) = 1
      LEFT JOIN NAGENDA AGPART ON AGPART.CODPART = P.CODPART AND AGPART.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(AGPART.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT NLOCPART ON AGPART.CODLOCALIT = NLOCPART.CODLOCALIT
      LEFT JOIN NPERS AGINC ON AGINC.CODPERS = COALESCE(T1.Agent, T.Agent, 0)
      LEFT JOIN OBLIGPIF OFACT ON OFACT.CODOBLIGPIF = O.CODOBLIGPIF - O.CODOBLIGPIF
      LEFT JOIN TMP_LST_CURS cfc ON cfc.codmoneda = bc.codmoneda&apos;||
      gSuplJoins||&apos;
    WHERE T.TIPDOC = 31&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      AND T1.AN * 12 + T1.LUNA &lt;= PKG_GLOBALS.ANLUNALUCRU
      AND (T1ST.AN IS NULL OR T1ST.AN * 12 + T1ST.LUNA &gt;= PKG_GLOBALS.ANLUNALUCRU)
      AND (CASE WHEN T1ST.AN * 12 + T1ST.LUNA = PKG_GLOBALS.ANLUNALUCRU THEN 0 ELSE T1.VALDOC END) &lt;&gt; 0 &apos;;
  ELSE
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, NUMEPART, SIMBOLMONEDA, DOC, NRDOC, DATADOC, NDOC, VALOARE, TERMEN,
      REST,
      BANCA, LocPart, CUIPart, RegComPart, PrefixStins, nrdocstins, datastins,
      Subunitatea, DocCumulativ, DataCumulativ, ValoareStins,
      AgentInc,
      AgentDoc,
      CF_AS, CF_CURS, CF_VALOARE&apos;||gUserFields||&apos;)&apos;;

    sSelect := &apos;
    WITH X AS (
      SELECT G.CODGENERAL, T.TIPDOC, T1.CODTREZOR1, T.CODTREZOR, O.CODPART, CASE WHEN T1ST.AN * 12 + T1ST.LUNA = PKG_GLOBALS.ANLUNALUCRU THEN 0 ELSE t1.valdoc END REST, S.VALOARE
      FROM TREZOR T
        INNER JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR
        INNER JOIN GENERAL G ON G.TIPDOC = T.TIPDOC AND G.CODDOC = T1.CODTREZOR1 AND G.TIPDOC = T.TIPDOC AND G.SEMNIFICATIE = &apos;||sSemnificatie||&apos;
        INNER JOIN OBLIGPIF O ON G.CODGENERAL = O.CODGENERAL
        LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN GENERAL GST ON GST.CODGENERAL = OST.CODGENERAL
        LEFT JOIN TREZOR1 T1ST ON T1ST.CODTREZOR1 = GST.CODDOC
      WHERE T.TIPDOC = 31&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        AND T1.AN * 12 + T1.LUNA &lt;= PKG_GLOBALS.ANLUNALUCRU
        AND ( T1ST.AN IS NULL OR T1ST.AN * 12 + T1ST.LUNA &gt;= PKG_GLOBALS.ANLUNALUCRU )
        AND ( CASE WHEN T1ST.AN * 12 + T1ST.LUNA = PKG_GLOBALS.ANLUNALUCRU THEN 0 ELSE T1.VALDOC END) &lt;&gt; 0
    )
    SELECT
      X.CODTREZOR NAV_CodDoc, X.CODTREZOR1 NAV_CodDoc1, X.TipDoc NAV_TipDoc, P.DEN_PART, M.SIMBOL SIMBOLMONEDA, T1.DOC, T1.NRDOC, T1.DATADOC, T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC NDOC, T1.VALDOC VALOARE, T1.DATADECONT TERMEN,
      CASE
        WHEN COALESCE(Intr.initializari, Ies.initializari, 0) = 1 AND Coalesce(t1.platatva,0) = 1 THEN Coalesce(ot.dincaretva,0)
        WHEN COALESCE(Intr.initializari, Ies.initializari, 0) = 1                                 THEN ot.valoare
        WHEN X.REST = 0                                                                           THEN 0
        WHEN Coalesce(t1.platatva,0) = 1                                                          THEN st.dincaretva
        ELSE                                                                                           st.valoare
      END REST,
      BK.SIMBOL||&apos;&apos; &apos;&apos;||BC.DEN_CONT BANCA, NLOCPART.DEN_LOCALIT LocPart, CF.CODFISCAL CUIPart, P.REGCOM RegComPart,
      CASE WHEN C.CODCOMPENS IS NOT NULL THEN &apos;&apos;PV &apos;&apos; WHEN NC.CODNC IS NOT NULL THEN &apos;&apos;NC &apos;&apos; ELSE COALESCE(Ies.PrefixDoc, Intr.PrefixDoc) END PREFIXSTINS,
      COALESCE(C.NrDoc, NC.NrDoc, Ies.NrDoc, Intr.NrDoc) NrDocStins,
      COALESCE(C.DataDoc, NC.DataDoc, Ies.DataDoc, Intr.DataDoc) DataStins,
      SUB.Den_Subunit, T.NUMEDOC DocCumulativ, T.DATADOC DataCumulativ, ST.valoare,
      CASE WHEN AGINC.CODPERS &lt;&gt; 0 THEN AGINC.NUME||&apos;&apos; &apos;&apos;||AGINC.PRENUME ELSE AGINC.NUME END,
      CASE WHEN AGDOC.CODPERS &lt;&gt; 0 THEN AGDOC.NUME||&apos;&apos; &apos;&apos;||AGDOC.PRENUME ELSE AGDOC.NUME END,
      TO_CHAR( Coalesce(T1.DATADECONT, OT.Termen, T1.DataDoc),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Nvl(cfc.valoare,1) CF_CURS, T1.VALDOC*Nvl(cfc.valoare,1) CF_VALOARE &apos;||gUserAlias||&apos;
    FROM X
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = X.CODTREZOR1
      INNER JOIN TREZOR T ON T.CODTREZOR = X.CODTREZOR
      INNER JOIN GENERAL GT ON GT.TIPDOC = X.TIPDOC AND GT.CODDOC = X.CODTREZOR1 AND GT.CODGENERAL &lt;&gt; X.CODGENERAL
      INNER JOIN OBLIGPIF OT ON OT.CODGENERAL = GT.CODGENERAL
      INNER JOIN STINGERE ST ON ST.CODSTINGATORPIF = OT.CODOBLIGPIF
      LEFT JOIN NPART P ON P.CODPART = X.CODPART
      LEFT JOIN NPARTB BP ON BP.CODPART = P.CODPART AND BP.IMPLICIT = 1
      LEFT JOIN NBANK BKP ON BKP.CODBANK = BP.CODBANK
      LEFT JOIN NPARTCODFISC CF ON P.CODPART = CF.CODPART AND NVL(CF.PRINCIPAL, 0) = 1
      LEFT JOIN NAGENDA AGPART ON AGPART.CODPART = P.CODPART AND AGPART.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(AGPART.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT NLOCPART ON AGPART.CODLOCALIT = NLOCPART.CODLOCALIT
      LEFT JOIN NBANKCONT BC ON T.CODBANCA = BC.CODBANKCONT
      LEFT JOIN NBANK BK ON BK.CODBANK = BC.CODBANK
      LEFT JOIN NMONEDE M ON M.CODMONEDA = BC.CODMONEDA
      LEFT JOIN NSUBUNIT SUB ON T.SUBUNITATEA = SUB.CODSUBUNIT
      LEFT JOIN OBLIGPIF OFACT ON OFACT.CODOBLIGPIF = ST.CODSTINSPIF
      LEFT JOIN GENERAL GS ON GS.CODGENERAL = OFACT.CODGENERAL
      LEFT JOIN IESIRI IES ON IES.CODIES = GS.CODDOC AND IES.TIPDOC = GS.TIPDOC
      LEFT JOIN INTRARI INTR ON INTR.CODINTR = GS.CODDOC AND INTR.TIPDOC = GS.TIPDOC
      LEFT JOIN COMPENS C ON C.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
      LEFT JOIN NC1 ON NC1.CODNC1 = GS.CODDOC AND GS.TIPDOC = 35
      LEFT JOIN NC ON NC.CODNC = NC1.CODNC
      LEFT JOIN NPERS AGINC ON AGINC.CODPERS = COALESCE(T1.Agent, T.Agent, 0)
      LEFT JOIN NPERS AGDOC ON AGDOC.CODPERS = COALESCE(Ies.Agent, C.Agent, 0)
      LEFT JOIN TMP_LST_CURS cfc ON cfc.codmoneda = bc.codmoneda&apos;||
    gSuplJoins;
  END IF;


  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_EFECTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EFECTEREMISE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C71F200CB9B25AE4ED1B2CA1752D48AC8538521</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_efecteremise IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(30000);
  sJoin    VARCHAR2(30000);
  sStins   VARCHAR2(1000);
  sPer     VARCHAR2(200);
BEGIN
  gSuplCols := &apos;trezor t, trezor1 t1, general g, obligpif o, obligpif ost, nmonede nm, npart p, npartcodfisc cf, nlocalit nlocpart, nbank bk, nbankcont bk&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;, &apos;PD&apos;, &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTLUNAAN.LunaStart = PKG_LIST_SELECTLUNAAN.LunaStop
  THEN sPer := &apos;= &apos;||PKG_LIST_SELECTLUNAAN.LunaStart;
  ELSE sPer := &apos;BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop;
  END IF;

  sInsert:= &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, NUMEPART, MONEDA, DOCCUMUL, DATACUMULATIV, TIPDOC, NRDOC, DATADOC, VALOARE, TERMEN,
    TIPTRANZ,
    PREFIXSTINS, NRDOCSTINS, DATASTINS, VALSTINS,
    REST, DATASTING,
    BANCA, LocPart, CUIPart, RegComPart, Subunitatea&apos;||gUserFields||&apos;)&apos;;

  IF PKG_LIST_SELECTLUNAAN.optiunea1 THEN
    sJoin :=  &apos;
    LEFT JOIN GENERAL GS ON GS.TIPDOC = T.TIPDOC AND GS.CODDOC = T1.CODTREZOR1 AND (NOT GS.semnificatie IN (500, 600, 700, 701, 750, 751))
    LEFT JOIN OBLIGPIF OS ON OS.CODGENERAL = GS.CODGENERAL
    LEFT JOIN STINGERE SD ON SD.CODSTINGATORPIF = OS.CODOBLIGPIF
    LEFT JOIN OBLIGPIF OD ON OD.CODOBLIGPIF = SD.CODSTINSPIF
    LEFT JOIN OBLIGPIF OL ON OL.CODOBLIGPIF = OD.CODOBLIGASOCIAT
    LEFT JOIN GENERAL GD ON GD.CODGENERAL = NVL(OL.CODGENERAL,OD.CODGENERAL)
    LEFT JOIN TREZOR1 TREZ1 ON TREZ1.CODTREZOR1 = GD.CODDOC AND GD.TIPDOC = 31
    LEFT JOIN INTRARI INTR ON INTR.CODINTR = GD.CODDOC AND INTR.TIPDOC = GD.TIPDOC
    LEFT JOIN IESIRI IES ON IES.CODIES = GD.CODDOC AND IES.TIPDOC = GD.TIPDOC&apos;;
    sStins := &apos;,
    DECODE(GS.SEMNIFICATIE,310,&apos;&apos;AVANS&apos;&apos;,410,&apos;&apos;AVANS&apos;&apos;,COALESCE(INTR.PREFIXDOC, IES.PREFIXDOC, TREZ1.DOC)),
    COALESCE(INTR.NRDOC, IES.NRDOC, TREZ1.NRDOC), COALESCE(INTR.DATADOC, IES.DATADOC, TREZ1.DATADOC), SD.VALOARE*DECODE(T1.TIPTRANZ,1,1,-1),
    CASE WHEN O.SEMNIFICATIE IN (320, 420) THEN 0 ELSE DECODE(T1ST.CODTREZOR1,NULL,SD.VALOARE,0)*DECODE(T1.TIPTRANZ,1,1,-1) END&apos;;
  ELSE
    sStins := &apos;,
    NULL PREFIXSTINS, NULL NRDOCSTINS, NULL DATASTINS, NULL VALSTINS,
    CASE WHEN O.SEMNIFICATIE IN (320, 420) THEN 0 ELSE DECODE(T1ST.CODTREZOR1,NULL,T1.VALDOC,0)*DECODE(T1.TIPTRANZ,1,1,-1) END&apos;;
  END IF;

  sSelect :=&apos;
  SELECT
    T.CODTREZOR, T1.CODTREZOR1, T.TipDoc, P.DEN_PART, M.SIMBOL, T.NUMEDOC, T.DATADOC, T1.DOC, T1.NRDOC, T1.DATADOC, T1.VALDOC*DECODE(T1.TIPTRANZ,1,1,-1), T1.DATADECONT,
    DECODE(T1.TIPTRANZ,1,&apos;&apos;Incasare&apos;&apos;,&apos;&apos;Plata&apos;&apos;)||CASE WHEN O.SEMNIFICATIE IN (320, 420) THEN &apos;&apos; - Retur&apos;&apos; END&apos;||
    sStins||&apos;, DECODE(T1ST.CODTREZOR1,NULL,NULL,T1ST.DATADECONT),
    BK.SIMBOL||&apos;&apos; &apos;&apos;||BC.DEN_CONT, NLOCPART.DEN_LOCALIT, CF.CODFISCAL, P.REGCOM, SUB.Den_Subunit &apos;||gUserAlias||&apos;
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
    INNER JOIN NBANK BK ON BK.CODBANK = BC.CODBANK
    INNER JOIN NMONEDE M ON M.CODMONEDA = BC.CODMONEDA
    INNER JOIN GENERAL G ON G.TIPDOC = T.TIPDOC AND G.CODDOC = T1.CODTREZOR1
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    LEFT JOIN NPART P ON P.CODPART = O.CODPART
    LEFT JOIN NSUBUNIT SUB ON T.SUBUNITATEA = SUB.CODSUBUNIT
    LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
    LEFT JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = S.CODSTINGATORPIF
    LEFT JOIN GENERAL GST ON GST.CODGENERAL = OST.CODGENERAL
    LEFT JOIN TREZOR1 T1ST ON T1ST.CODTREZOR1 = GST.CODDOC AND T1ST.AN * 12 + T1ST.LUNA &apos;||sPer||&apos;
    LEFT JOIN NPARTCODFISC CF ON P.CODPART = CF.CODPART AND NVL(CF.PRINCIPAL, 0) = 1
    LEFT JOIN NAGENDA AGPART ON AGPART.CODPART = P.CODPART AND AGPART.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(AGPART.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT NLOCPART ON AGPART.CODLOCALIT = NLOCPART.CODLOCALIT&apos;||
    sJoin||
    gSuplJoins||&apos;
  WHERE T.TIPDOC = 31 AND O.SEMNIFICATIE IN (320, 420, 500, 600) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;
    AND T1.AN * 12 + T1.LUNA &apos;||sPer;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_EFECTEREMISE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A91D89C3328FF2AC7EE36C2CCDD1C013DC617BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_emulare IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sInsertTMP  CLOB;
  sInsertTMP1 CLOB;
  sFiltruDATA VARCHAR2(2000);
  sFiltruCamp VARCHAR2(50);
  sFiltruRetCamp VARCHAR2(50);
BEGIN
  gSuplCols := &apos;TMP_LIST_EMULARE E, TMP_LIST_EMULARE1 E1, NCASEMARCAT C, NPERS OP, NPART P, NARTOBJ O, NART NA, NCLASEA CA, NUM1 UM1, IESIRI I, NGEST G, IOART IOA&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;EMULARE&apos;, &apos;EM&apos;, &apos;E.CODEMULARE = EM.CODEMULARE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;EMULARE1&apos;, &apos;EM1&apos;, &apos;E1.CODEMULARE1 = EM1.CODEMULARE1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;, &apos;PME&apos;, &apos;PME.CODOBIECT = O.CODOBIECT AND PME.CODCATPRET = &apos;||Nvl(pkg_categconst.GetValConstanta(&apos;CodCatPretEmul&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0));
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;, &apos;PMEUSR&apos;, &apos;PMEUSR.CODOBIECT = O.CODOBIECT AND PMEUSR.CODCATPRET = &apos;||Nvl(pkg_categconst.GetValConstanta(&apos;CodCatPretEmulUsr&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0));
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if PKG_LIST_SELECTEMULARE.getTipFiltrare = 1 then
    sFiltruCamp := &apos;E.DATACREARE &apos;; 
    sFiltruRetCamp := &apos;I.DATACREARE &apos;;
    IF PKG_LIST_SELECTEMULARE.getDataIni = PKG_LIST_SELECTEMULARE.getDataFin
    THEN sFiltruDATA := &apos;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;) &apos;;
    ELSE sFiltruDATA := &apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;) &apos;;
    END IF;
  else
    sFiltruCamp := &apos;E.DATABON &apos;;
    sFiltruRetCamp := &apos;I.DATADOC &apos;;
    IF PKG_LIST_SELECTEMULARE.getDataIni = PKG_LIST_SELECTEMULARE.getDataFin
    THEN sFiltruDATA := &apos;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;) &apos;;
    ELSE sFiltruDATA := &apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;) &apos;;
    END IF;
  end if;  

  sInsertTMP := &apos;
  INSERT INTO TMP_LIST_EMULARE(
    id, codemulare, nrbon, databon, valoare, valoarediscount, listat, preluat, codcasamarcat, tvatotal, tvadiscount, tipcasamarcat, userid, datacreare, datalistare,
    codies, codpart, incasareclient, codmonetar, codpers, codpostretail, codaecustodie, codlocatie, codagent, obs)
  SELECT
    0, e.codemulare, e.nrbon, e.databon, e.valoare, e.valoarediscount, e.listat, e.preluat, e.codcasamarcat, e.tvatotal, e.tvadiscount, NULL tipcasamarcat, NULL userid, e.datacreare, e.datalistare,
    e.codies, e.codpart, NULL incasareclient, NULL codmonetar, e.codpers, e.codpostretail, NULL codaecustodie, e.codlocatie, e.codagent, e.obs
  FROM SintezaEmulare E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
    INNER JOIN POSTRETAIL P ON P.COD = E.CODPOSTRETAIL
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos;
    AND e.codpostretail IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPOSTRETAIL&apos;&apos;)&apos;;

  sInsertTMP1 := &apos;
  INSERT INTO TMP_LIST_EMULARE1(
     id, codemulare1, codemulare, codobiect, indexlocal, pretart, pret, cant, umsec, discount, codioart, codgest, tva, tiplinie, pretnirstoc,
     contserv, codemulstingere, farastoc, codcomanda1, tiplivrare, cadou, pretpromo, codgestorig)
  SELECT
    0, e1.codemulare1, e.codemulare, e1.codobiect, e1.indexlocal, e1.pretart, e1.pret, e1.cant, e1.umsec, e1.discount, NULL codioart, NULL codgest, e1.tva, e1.tiplinie, NULL pretnirstoc,
    e1.contserv, NULL codemulstingere, NULL farastoc, NULL codcomanda1, NULL tiplivrare, e1.cadou, e1.pretpromo, NULL codgestorig
  FROM SintezaEmulare E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
    INNER JOIN SintezaEmulare1 E1 ON e1.codsinteza = e.codsinteza
    INNER JOIN POSTRETAIL P ON P.COD = E.CODPOSTRETAIL
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos;
    AND e.codpostretail IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPOSTRETAIL&apos;&apos;)&apos;;

  IF PKG_LIST_SELECTEMULARE.getTipPrel = 0 THEN
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LIST_EMULARE&apos;;
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LIST_EMULARE1&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsertTMP,  aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsertTMP1, aListID, aListVer);
  END IF;

  sInsertTMP := &apos;
  INSERT INTO TMP_LIST_EMULARE(
    id, codemulare, nrbon, databon, valoare, valoarediscount, listat, preluat, codcasamarcat, tvatotal, tvadiscount, tipcasamarcat, userid, datacreare, datalistare,
    codies, codpart, incasareclient, codmonetar, codpers, codpostretail, codaecustodie, codlocatie, codagent, obs)
  SELECT
    0, e.codemulare, e.nrbon, e.databon, e.valoare, e.valoarediscount, e.listat, e.preluat, e.codcasamarcat, e.tvatotal, e.tvadiscount, e.tipcasamarcat, e.userid, e.datacreare, e.datalistare,
    CASE
      WHEN e.codies IS NULL THEN (SELECT min(g.tipdoc) FROM EmulStingeri es, obligpif o, general g WHERE es.codemulare = e.codemulare AND o.codobligpif = es.codobligpif AND g.codgeneral = o.codgeneral)
      ELSE e.codies
    END codies,
    e.codpart, e.incasareclient, e.codmonetar, e.codpers, e.codpostretail, e.codaecustodie, e.codlocatie, e.codagent, e.obs
  FROM EMULARE E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  sInsertTMP1 := &apos;
  INSERT INTO TMP_LIST_EMULARE1(
     id, codemulare1, codemulare, codobiect, indexlocal, pretart, pret, cant, umsec, discount, codioart, codgest, tva, tiplinie, pretnirstoc,
     contserv, codemulstingere, farastoc, codcomanda1, tiplivrare, cadou, pretpromo, codgestorig)
  SELECT
    0, e1.codemulare1, e1.codemulare, e1.codobiect, e1.indexlocal, e1.pretart, e1.pret, e1.cant, e1.umsec, e1.discount, e1.codioart, e1.codgest, e1.tva, e1.tiplinie, e1.pretnirstoc,
    e1.contserv, e1.codemulstingere, e1.farastoc, e1.codcomanda1, e1.tiplivrare, e1.cadou, e1.pretpromo, e1.codgestorig
  FROM EMULARE E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
    INNER JOIN EMULARE1 E1 ON e1.codemulare = e.codemulare
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsertTMP,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsertTMP1, aListID, aListVer);

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    Operator, Agent,
    Client, Bon, NrBon, DataBon,
    Preluat, Ies, PrefixIes, NrIes, DataIes,
    Art, UM, Cant, PretArt, PretNir, Pret, PretFTva,
    Adaos, AdaosVal, Discount, Tva, Obs&apos;||gUserFields||&apos;)
  SELECT
    CASE WHEN E.ID = 0 THEN E.CodEmulare ELSE NULL END, CASE WHEN E.ID = 0 THEN 64 ELSE NULL END,
    CASE WHEN op.codpers = 0 THEN op.Nume ELSE op.Nume||&apos;&apos; &apos;&apos;||op.Prenume END, CASE WHEN ag.codpers = 0 THEN ag.nume ELSE ag.nume||&apos;&apos; &apos;&apos;||ag.prenume END,
    P.Den_Part, E.NrBon||&apos;&apos;/&apos;&apos;||TO_CHAR(E.DataBon,&apos;&apos;dd.mm.yyyy&apos;&apos;), E.NrBon, E.DataBon,
    Decode(E.Preluat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), i.prefixdoc, i.nrdoc, i.Datadoc,
    o.denumire, um1.den_um1, e1.Cant/um1.Paritate, e1.PretArt*um1.Paritate, e1.PretNirStoc*um1.Paritate, e1.Pret*um1.Paritate, (e1.Pret - CASE WHEN Nvl(e1.cant,0) = 0 THEN 0 ELSE e1.tva/e1.cant END)*um1.Paritate PretFTva,
    CASE WHEN e1.PretNirStoc = 0 THEN 0 ELSE e1.Pret/e1.PretNirStoc * 100 - 100 END Adaos, (e1.Pret - e1.PretNirStoc) * e1.Cant AdaosVal, e1.discount, e1.Tva, E.OBS &apos;||gUserAlias||&apos;
  FROM TMP_LIST_EMULARE E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;)||&apos;
	  LEFT JOIN TMP_LIST_EMULARE1 E1 ON e1.codemulare = e.codemulare AND e1.ID = e.ID
    LEFT JOIN NPERS OP ON op.codpers = nvl(e.codpers,0)
    LEFT JOIN NPERS AG ON ag.codpers = nvl(e.codagent,0)
    LEFT JOIN NPART P ON p.codpart = e.codpart
    LEFT JOIN NARTOBJ O ON o.codobiect = e1.codobiect
    LEFT JOIN NART NA ON NA.CodArticol = O.CodArticol
    LEFT JOIN NCLASEA CA ON CA.CodClaseA = NA.Clasa
    LEFT JOIN NUM1 UM1 ON um1.codum1 = e1.umsec
    LEFT JOIN IESIRI I ON i.codies = e.codies
    LEFT JOIN NGEST G ON g.codgest = coalesce(e1.codgest, 0)
    LEFT JOIN IOART IOA ON ioa.codioart = e1.codioart&apos;||
    gSuplJoins||
    &apos; WHERE (G.CODGEST IN (SELECT CODGEST FROM TMP_GESTDEDICATE) or coalesce(G.CODGEST,0) = 0)&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  if PKG_LIST_SELECTEMULARE.getSiRetur then 
    sInsert:= &apos;
    INSERT INTO &apos;|| tmpName ||&apos;(
      NAV_CodDoc, NAV_TipDoc,
      Operator, Agent,
      Client, Bon, NrBon, DataBon,
      Preluat, Ies, PrefixIes, NrIes, DataIes,
      Art, UM, Cant, PretArt, PretNir, Pret, PretFTva,
      Adaos, AdaosVal, Discount, Tva, Obs&apos;||gUserFields||&apos;)
    SELECT
      I.CODIES, 
      I.TIPDOC,
      CASE WHEN op.codpers = 0 THEN op.Nume ELSE op.Nume||&apos;&apos; &apos;&apos;||op.Prenume END, 
      CASE WHEN ag.codpers = 0 THEN ag.nume ELSE ag.nume||&apos;&apos; &apos;&apos;||ag.prenume END,
      P.Den_Part, 
      NULL BON, 
      NULL NrDOC, NULL DataDOC,
      &apos;&apos;Nu&apos;&apos;, 
      i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), i.prefixdoc, i.nrdoc, i.Datadoc,
      o.denumire, um1.den_um1, L1.CANT, 
      I1.PU, 
      NS.PRET, 
      I1.PU, 
      I1.PU PretFTva,
      (1-I1.COEFDISCMAJ)*100 Adaos, 
      (NS.Pret - NVL(NS.ADAOS,0)) * L1.Cant AdaosVal, 
      NULL, 
      I1.Tva, 
      I.OBS &apos;||gUserAlias||&apos;
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODIES1 = I1.CODIES1 AND L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON g.codgest = NIR.GEST
      INNER JOIN TMP_MANEVRA_LISTE TMP ON G.CODPOSTRETAIL = TMP.VALOARE AND TMP.FILTRU = &apos;&apos;CODPOSTRETAIL&apos;&apos;
      LEFT JOIN NPERS OP ON op.LOGONNAME = I.USERID
      LEFT JOIN NPERS AG ON ag.codpers = I.AGENT
      LEFT JOIN NPART P ON p.codpart = I.PARTENER
      LEFT JOIN NARTOBJ O ON o.codobiect = I1.codobiect
      LEFT JOIN NART NA ON NA.CodArticol = O.CodArticol
      LEFT JOIN NCLASEA CA ON CA.CodClaseA = NA.Clasa
      LEFT JOIN NUM1 UM1 ON um1.codum1 = I1.umsec
      LEFT JOIN IOART IOA ON ioa.codioart = NS.codioart&apos;||gSuplJoins||
    &apos; WHERE I1.CANT &lt; 0 AND I.OPERAT = 1 AND I.ANULAT = 0 AND &apos;||sFiltruRetCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    &apos; AND G.CODGEST IN (SELECT CODGEST FROM TMP_GESTDEDICATE)&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  end if;
  
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END PKG_LIST_BASE_EMULARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EMULAREDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01F6803134CB98CBD2B7EB51336B34F74021E96A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EMULAREDOC IS

  vCodEmulare  NUMBER(20);
  vCodGest     NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pListareDocAgregat VARCHAR2(10);


PROCEDURE SETPARAMS(pCodEmulare IN NUMBER, pCodGest IN NUMBER) IS
BEGIN
  vCodEmulare := pCodEmulare;
  vCodGest    := Coalesce(pCodGest,-1);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsTMP  CLOB;
  sInsert  CLOB;
  sFGest   VARCHAR2( 200);
  sGroupBy VARCHAR2( 200);
BEGIN

  gSuplCols := &apos;EMULARE E, EMULARE1 E1, NPART P, NARTOBJ O, NART NA, NCLASEA CA, NUM1 UM, NGEST G, IOART IOA, NPART COMIS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pListareDocAgregat := pkg_categconst.GetValConstanta(&apos;ListareDocAgregat&apos;, pkg_globals.ANLUCRU, pkg_globals.lunalucru) ;

  sGroupBy := &apos;
  GROUP BY &apos;;

  sInsTMP := &apos;INSERT INTO TMP_LST_DOCEMULARE1 (CODEMULARE1, PRETART, PRET, CANT)
  SELECT &apos;;

  IF pListareDocAgregat = &apos;1&apos; THEN -- ARTICOL/UMSEC
    sInsTMP := sInsTMP||&apos;
    Min(E1.CodEmulare1), SUM(E1.Cant*E1.PretArt)/SUM(E1.Cant), SUM(E1.Cant*E1.Pret)/SUM(E1.Cant), SUM(E1.Cant)&apos;;
    sGroupBy := sGroupBy||&apos;E1.CodObiect, E1.UMSec&apos;;
  ELSIF pListareDocAgregat = &apos;3&apos; THEN -- ARTICOL/UMSEC/Pret
    sInsTMP := sInsTMP||&apos;
    Min(E1.CodEmulare1), E1.PretArt, E1.Pret, SUM(E1.Cant)&apos;;
    sGroupBy := sGroupBy||&apos;E1.CodObiect, E1.UMSec, E1.PretArt, E1.Pret&apos; ;
  ELSE
    sInsTMP := sInsTMP||&apos;
    E1.CodEmulare1, E1.PretArt, E1.Pret, E1.Cant&apos;;
    sGroupBy := &apos;&apos;;
  END IF;

  sInsTMP := sInsTMP||&apos;
  FROM EMULARE E INNER JOIN EMULARE1 E1 ON E1.CodEmulare = E.CodEmulare
  WHERE E.Codemulare = &apos;||vCodemulare;

  IF vCodGest &gt;= 0 THEN
    sInsTMP := sInsTMP||&apos;
    AND COALESCE(E1.CodGestOrig, E1.CodGest, 0) = &apos;||vCodGest;
  END IF;
  sInsTMP := sInsTMP||sGroupBy;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM,
    CANT, PRETART, PRET, DISC, VAL,
    CODINTERN, CODEXTERN, PROMOTIE, GEST, GESTORIG, IOART,
    TIPLIVR&apos;||
    gUserFields||&apos;)
  SELECT
    O.Denumire, UM.Den_UM1,
    TE1.Cant / um.paritate, TE1.PretArt * um.paritate, TE1.Pret * um.paritate, e1.Discount, TE1.Pret * TE1.Cant,
    o.codintern, o.codextern, DECODE(e1.pretpromo,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), G.Den_Gest, GO.Den_Gest, IOA.DEN_IOART,
    DECODE(e1.tiplivrare,1,&apos;&apos;Ridicata&apos;&apos;,2,&apos;&apos;Custodie&apos;&apos;,3,&apos;&apos;Nesosita&apos;&apos;,4,&apos;&apos;De ridicat&apos;&apos;)&apos;||
    gUserAlias||&apos;
  FROM TMP_LST_DOCEMULARE1 TE1
    INNER JOIN EMULARE1 E1 ON e1.Codemulare1 = te1.Codemulare1
    INNER JOIN EMULARE E  ON e.Codemulare = e1.Codemulare
    LEFT JOIN NPART P ON P.CodPart = E.CodPart
    LEFT JOIN NPART COMIS ON COMIS.CodPart = E.CodPartComis
    LEFT JOIN NARTOBJ O ON O.CodObiect = E1.CodObiect
    LEFT JOIN NART NA ON NA.CodArticol = O.CodArticol
    LEFt JOIN NCLASEA CA ON CA.CodClaseA = NA.Clasa
    LEFT JOIN NUM1 UM ON UM.CodUM1 = E1.UMSec
    LEFT JOIN NGEST G ON G.CodGest = COALESCE(E1.CodGest, 0)
    LEFT JOIN NGEST GO ON GO.CodGest = COALESCE(E1.CodGestOrig, E1.CodGest, 0)
    LEFT JOIN IOART IOA ON IOA.CodIOArt = E1.CodIOArt&apos;||
    gSuplJoins;

  DELETE TMP_LST_DOCEMULARE1;
  LIST_EXECUTE_IMMEDIATE(sInsTMP, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      e.nrbon, e.databon,e.valoare, e.tvatotal, e.obs,
      p.den_part, p.codextern, p.regcom, p.autorizatie,
      CASE WHEN o.codpers  = 0 THEN o.nume  ELSE o.nume ||&apos; &apos;||o.prenume  END OPERATOR,
      CASE WHEN ag.codpers = 0 THEN ag.nume ELSE ag.nume||&apos; &apos;||ag.prenume END AGENT,
      M.SIMBOL AS SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE SDENMONEDA,
      COMIS.DEN_PART COMIS_NUME, COMIS.CODEXTERN COMIS_CODEXTERN,
      COMIS.CODINTERN COMIS_CODINTERN, COMISCF.CODFISCAL COMIS_CODFISCAL, PF.CODFISCAL P_CODFISCAL, 
      getadresa(COALESCE(SL.SECTOR,SS.SECTOR),
                COALESCE(SL.STRADA,SS.STRADA),
                COALESCE(SL.NR1,SS.NR1),
                COALESCE(SL.NR2,SS.NR2),
                COALESCE(SL.BLOC,SS.BLOC),
                COALESCE(SL.SCARA,SS.SCARA),
                COALESCE(SL.ETAJ,SS.ETAJ),
                COALESCE(SL.APART,SS.APART),
                COALESCE(SL.CODPOSTAL,SS.CODPOSTAL)) ADRESA,
      P.REGCOM P_REGCOM, LOC.DEN_LOCALIT
    FROM EMULARE E
      LEFT JOIN NPART P   ON P.CODPART   = E.CODPART
      LEFT JOIN NPARTCODFISC PF ON PF.CODPART = E.CODPART AND PF.PRINCIPAL = 1
      LEFT JOIN NPART COMIS ON COMIS.CODPART = E.CODPARTCOMIS
      LEFT JOIN NPARTCODFISC COMISCF ON COMISCF.CODPART = E.CODPARTCOMIS AND COMISCF.PRINCIPAL = 1
      LEFT JOIN NPERS O   ON O.CODPERS   = Nvl(E.CODPERS,0)
      LEFT JOIN NPERS AG  ON AG.CODPERS  = Nvl(E.CODAGENT,0)
      LEFT JOIN NMONEDE M ON M.CODMONEDA = (E.Codemulare - E.Codemulare)
      LEFT JOIN NAGENDA SL ON SL.CODAGENDA = E.CODLOCATIE
      LEFT JOIN NAGENDA SS ON SS.CODPART = P.CODPART AND SS.SEDIUSOCIAL BETWEEN 4 AND 7
      LEFT JOIN NLOCALIT LOC ON LOC.CODLOCALIT = COALESCE(SL.CODLOCALIT,SS.CODLOCALIT)
    WHERE E.Codemulare = vCodemulare
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;BON NUMAR&apos;,                       v_rec.NrBon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BON DATA&apos;,                        To_Char(v_rec.DataBon,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;BON OBSERVATII&apos;,                  v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OPERATOR&apos;,                        v_rec.Operator);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.Agent);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL/CNP&apos;,            v_rec.P_CODFISCAL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT ADRESA&apos;,                   v_rec.ADRESA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REG.COM.&apos;,                 v_rec.P_REGCOM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT LOCALITATE&apos;,               v_rec.DEN_LOCALIT);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,                v_rec.CodExtern);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,              v_rec.Autorizatie);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,          v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL&apos;,                       TO_CHAR(v_rec.valoare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE&apos;,                NumarRO(Round(v_rec.valoare,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenMoneda, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL LITERE ENG&apos;,            NumarUK(Round(v_rec.valoare,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(v_rec.TVATotal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(v_rec.TVATotal,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenMoneda, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(v_rec.TVATotal,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR NUME&apos;,                 v_rec.COMIS_NUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODINTERN&apos;,            v_rec.COMIS_CODINTERN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODEXTERN&apos;,            v_rec.COMIS_CODEXTERN);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMISIONAR CODFISCAL/CNP&apos;,        v_rec.COMIS_CODFISCAL);
    EXIT;
  END LOOP;
  COMMIT;
END;

end PKG_LIST_BASE_EMULAREDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EMULARESINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AEAEE2058B60871889F7DCAED96699D60776BBEC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_emularesint IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sInsertTMP  CLOB;
  sFiltruDATA VARCHAR2(2000);
  sFiltruCamp VARCHAR2(50);
BEGIN
  gSuplCols := &apos;NPERS OP, NPERS AG, NPART P&apos;;
  if PKG_LIST_SELECTEMULARE.getSiRetur then
    gSuplCols := gSuplCols||&apos;,EMULARE E&apos;;
  end if;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if PKG_LIST_SELECTEMULARE.getTipFiltrare = 1 then
    sFiltruCamp := &apos;E.DATACREARE &apos;;
    IF PKG_LIST_SELECTEMULARE.getDataIni = PKG_LIST_SELECTEMULARE.getDataFin
    THEN sFiltruDATA := &apos;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;)&apos;;
    ELSE sFiltruDATA := &apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;yyyymmdd hh24:mi&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd hh24:mi&apos;&apos;)&apos;;
    END IF;
  else
    sFiltruCamp := &apos;E.DATABON &apos;;
    IF PKG_LIST_SELECTEMULARE.getDataIni = PKG_LIST_SELECTEMULARE.getDataFin
    THEN sFiltruDATA := &apos;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;)&apos;;
    ELSE sFiltruDATA := &apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;)&apos;;
    END IF;
  end if;  

  sInsertTMP := &apos;
  INSERT INTO TMP_LIST_EMULARE(
    id, codemulare, nrbon, databon, valoare, valoarediscount, listat, preluat, codcasamarcat, tvatotal, tvadiscount, tipcasamarcat, userid, datacreare, datalistare,
    codies, codpart, incasareclient, codmonetar, codpers, codpostretail, codaecustodie, codlocatie, codagent, obs)
  SELECT
    0, e.codemulare, e.nrbon, e.databon, e.valoare, e.valoarediscount, e.listat, e.preluat, e.codcasamarcat, e.tvatotal, e.tvadiscount, NULL tipcasamarcat, NULL userid, e.datacreare, e.datalistare,
    e.codies, e.codpart, NULL incasareclient, NULL codmonetar, e.codpers, e.codpostretail, NULL codaecustodie, e.codlocatie, e.codagent, e.obs
  FROM SintezaEmulare E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
    INNER JOIN POSTRETAIL P ON P.COD = E.CODPOSTRETAIL
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos;
    AND e.codpostretail IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPOSTRETAIL&apos;&apos;)&apos;;

  IF PKG_LIST_SELECTEMULARE.getTipPrel = 0 THEN
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LIST_EMULARE&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsertTMP, aListID, aListVer);
  END IF;

  sInsertTMP := &apos;
  INSERT INTO TMP_LIST_EMULARE(
    id, codemulare, nrbon, databon, valoare, valoarediscount, listat, preluat, codcasamarcat, tvatotal, tvadiscount, tipcasamarcat, userid, datacreare, datalistare,
    codies, codpart, incasareclient, codmonetar, codpers, codpostretail, codaecustodie, codlocatie, codagent, obs)
  SELECT
    0, e.codemulare, e.nrbon, e.databon, e.valoare, e.valoarediscount, e.listat, e.preluat, e.codcasamarcat, e.tvatotal, e.tvadiscount, e.tipcasamarcat, e.userid, e.datacreare, e.datalistare,
    e.codies, e.codpart, e.incasareclient, e.codmonetar, e.codpers, e.codpostretail, e.codaecustodie, e.codlocatie, e.codagent, e.obs
  FROM EMULARE E
    INNER JOIN NCASEMARCAT C ON c.codcasemarcat = e.codcasamarcat
  WHERE &apos;||sFiltruCamp||sFiltruDATA||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsertTMP, aListID, aListVer);

  if PKG_LIST_SELECTEMULARE.getSiRetur then
    sInsert:= &apos;
    INSERT INTO &apos;||tmpName ||&apos;(
      DataBon, Client,
      Operator,
      Agent,
      NrBonuri, Preluate, Valoare, Discount, TVA, TVADiscount &apos;||gUserFields||&apos;)
    WITH ES AS (
      SELECT
        E.DATABON, nvl(e.codpers,0) codpers, nvl(e.codagent,0) codagent, e.codpart, e.codemulare,
        count(1) NrBonuri, SUM(Nvl(E.Preluat,0)) Preluate, SUM(E.Valoare) Valoare, SUM(E.ValoareDiscount) Discount, SUM(E.TvaTotal) Tva, SUM(E.TVADiscount) TVADiscount
      FROM TMP_LIST_EMULARE E
      GROUP BY E.DATABON, nvl(e.codpers,0), nvl(e.codagent,0), e.codpart, e.codemulare
    )
    SELECT
      ES.DataBon, P.Den_Part,
      CASE WHEN op.codpers = 0 THEN OP.Nume ELSE OP.Nume||&apos;&apos; &apos;&apos;||OP.Prenume END,
      CASE WHEN ag.codpers = 0 THEN ag.nume ELSE ag.nume||&apos;&apos; &apos;&apos;||ag.prenume END,
      ES.NrBonuri, ES.Preluate, ES.Valoare, ES.Discount, ES.TVA, ES.TVADiscount &apos;||gUserAlias||&apos;
    FROM ES
      INNER JOIN EMULARE E ON E.CODEMULARE = ES.CODEMULARE
      LEFT JOIN NPERS OP ON op.codpers = es.codpers
      LEFT JOIN NPERS AG ON ag.codpers = es.codagent
      LEFT JOIN NPART P ON p.codpart = es.codpart&apos;||
      gSuplJoins;
  else
    sInsert:= &apos;
    INSERT INTO &apos;||tmpName ||&apos;(
      DataBon, Client,
      Operator,
      Agent,
      NrBonuri, Preluate, Valoare, Discount, TVA, TVADiscount &apos;||gUserFields||&apos;)
    WITH ES AS (
      SELECT
        E.DATABON, nvl(e.codpers,0) codpers, nvl(e.codagent,0) codagent, e.codpart,
        count(1) NrBonuri, SUM(Nvl(E.Preluat,0)) Preluate, SUM(E.Valoare) Valoare, SUM(E.ValoareDiscount) Discount, SUM(E.TvaTotal) Tva, SUM(E.TVADiscount) TVADiscount
      FROM TMP_LIST_EMULARE E
      GROUP BY E.DATABON, nvl(e.codpers,0), nvl(e.codagent,0), e.codpart)
    SELECT
      ES.DataBon, P.Den_Part,
      CASE WHEN op.codpers = 0 THEN OP.Nume ELSE OP.Nume||&apos;&apos; &apos;&apos;||OP.Prenume END,
      CASE WHEN ag.codpers = 0 THEN ag.nume ELSE ag.nume||&apos;&apos; &apos;&apos;||ag.prenume END,
      ES.NrBonuri, ES.Preluate, ES.Valoare, ES.Discount, ES.TVA, ES.TVADiscount &apos;||gUserAlias||&apos;
    FROM ES
      LEFT JOIN NPERS OP ON op.codpers = es.codpers
      LEFT JOIN NPERS AG ON ag.codpers = es.codagent
      LEFT JOIN NPART P ON p.codpart = es.codpart&apos;||
      gSuplJoins;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert,    aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END pkg_list_base_emularesint; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ETVAWME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1ECC7B8CBCEBBEAA0A9D8533DA6C2D886E99621A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ETVAWME IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vNrCrt      NUMBER;
  vAn         NUMBER;
  vLuna       NUMBER;
  vSubunit    NUMBER;

PROCEDURE SETPARAMS(pNrCrt IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER, pSubunit IN NUMBER) IS
BEGIN
  vNrCrt   := pNrCrt;
  vAn      := pAn;
  vLuna    := pLuna;

  IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pAn, pLuna) = &apos;1&apos;
  THEN vSubunit := pSubunit;
  ELSE vSubunit := 1;
  END IF;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sDebug       CLOB;
  sInsert      CLOB;
  sSelect      CLOB;
  sUpdate      CLOB;
  vCotaTva     VARCHAR2(10);
  vTipTva      VARCHAR2(10);
  vCotaMAX     VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;PROCTVAMAX&apos;, vAn, vLuna),&apos;19&apos;);
  vCotaMIN     VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;PROCTVAMIN&apos;, vAn, vLuna), &apos;9&apos;);
  vCotaMED     VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;PROCTVAMED&apos;, vAn, vLuna), &apos;5&apos;);
  sAMEF_B_MAX  VARCHAR2(30) := &apos;Coalesce(VALOARE_&apos;||vCotaMAX||&apos;, 0)&apos;;
  sAMEF_B_MIN  VARCHAR2(30) := &apos;Coalesce(VALOARE_&apos;||vCotaMIN||&apos;, 0)&apos;;
  sAMEF_B_MED  VARCHAR2(30) := &apos;Coalesce(VALOARE_&apos;||vCotaMED||&apos;, 0)&apos;;
  sAMEF_T_MAX  VARCHAR2(30) := &apos;Coalesce(TVA_&apos;||    vCotaMAX||&apos;, 0)&apos;;
  sAMEF_T_MIN  VARCHAR2(30) := &apos;Coalesce(TVA_&apos;||    vCotaMIN||&apos;, 0)&apos;;
  sAMEF_T_MED  VARCHAR2(30) := &apos;Coalesce(TVA_&apos;||    vCotaMED||&apos;, 0)&apos;;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CODDOC,NAV_CODDOC1,NAV_TIPDOC,ORDDOC,
    DATADOC,NRDOC,NRI,PREFIXDOC,SERIADOC,
    DEN_PART,CODFISCAL,PERS_FIZ,VALDOC,
    PROC_TVA,
    JURN_BAZA,JURN_TVA,
    ETVA_DATA_Z,ETVA_NR_Z,ETVA_BAZA,ETVA_TVA,ETVA_DEN_PART,ETVA_CODFISCAL,ETVA_NR_DOC&apos;||gUserFields||&apos;)&apos;;

  IF vNrCrt IN (9, 10, 11) THEN
    sDebug := &apos;BEGIN&apos;||Chr(10)||
              &apos;  EXECUTE IMMEDIATE &apos;&apos;TRUNCATE TABLE TMP_JV_D300&apos;&apos;;&apos;||Chr(10)||
              &apos;  PKG_LIST_BASE_JURNVANZ.SetPerioada(&apos;||vAn||&apos;,&apos;||vLuna||&apos;,0,&apos;||vSubunit||&apos;);&apos;||Chr(10)||
              &apos;  PKG_LIST_BASE_JURNVANZ.ProcessList(&apos;&apos;TMP_JV_D300&apos;&apos;);&apos;||Chr(10)||
              &apos;END;&apos;;
    PKG_GLOBALS.CheckDebugMode(sDebug, aLISTID, aLISTVER);

    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_JV_D300&apos;;
    PKG_LIST_BASE_JURNVANZ.SetPerioada(vAn, vLuna, 0, vSubunit);
    PKG_LIST_BASE_JURNVANZ.ProcessList(&apos;TMP_JV_D300&apos;);

    IF    vNrCrt =  9 THEN
      vCotaTva := vCotaMAX;
      vTipTva  := &apos;MAX&apos;;
    ELSIF vNrCrt = 10 THEN
      vCotaTva := vCotaMIN;
      vTipTva  := &apos;MIN&apos;;
    ELSIF vNrCrt = 11 THEN
      vCotaTva := vCotaMED;
      vTipTva  := &apos;MED&apos;;
    END IF;

    sSelect := &apos;
    SELECT
      Coalesce(jv.NAV_CODDOC, 0) NAV_CODDOC, Coalesce(jv.NAV_CODDOC1, 0) NAV_CODDOC1, Coalesce(jv.NAV_TIPDOC, 16) NAV_TIPDOC, Coalesce(jv.ORDDOC, 1) ORDDOC,
      jv.DATADOC,jv.NRDOC,jv.NRI,Coalesce(jv.PREFIXDOC, &apos;&apos;M&apos;&apos;) PREFIXDOC,jv.SERIADOC,
      jv.DEN_PART,jv.CODFISCAL,&apos;&apos;X&apos;&apos; PERS_FIZ,jv.VALDOC,
      &apos;||vCotaTva||&apos; AS PROC_TVA,
      jv.BAZA_&apos;||vTipTva||&apos; AS JURN_BAZA, jv.TVA_&apos;||vTipTva||&apos; AS JURN_TVA,
      A.Data_Z, A.NR_Z, A.BAZA_&apos;||vTipTva||&apos;, A.TVA_&apos;||vTipTva||&apos;, NULL AS ETVA_DEN_PART, NULL AS ETVA_CODFISCAL, NULL AS ETVA_NR_DOC &apos;||gUserAlias||&apos;
    FROM (
        SELECT
          NAV_CODDOC,NAV_CODDOC1,NAV_TIPDOC,ORDDOC,
          DATADOC,NRDOC,NRI,PREFIXDOC,SERIADOC,DEN_PART,CODFISCAL,VALDOC,
          BAZA_MAX, TVA_MAX,
          BAZA_MIN, TVA_MIN,
          BAZA_MED, TVA_MED,
          Row_Number() OVER (PARTITION BY DATADOC, Round(BAZA_MAX+TVA_MAX,2), Round(BAZA_MIN+TVA_MIN,2), Round(BAZA_MED+TVA_MED,2) ORDER BY NAV_CODDOC) IdxLoc
        FROM TMP_JV_D300
        WHERE NAV_TIPDOC = 16 AND (BAZA_&apos;||vTipTva||&apos; &lt;&gt; 0 OR TVA_&apos;||vTipTva||&apos; &lt;&gt; 0)
      ) JV
      FULL JOIN (
        SELECT
          a.NUI, trunc(a.Data_Z) Data_Z, a.NR_Z,
          &apos;||sAMEF_B_MAX||&apos; AS BAZA_MAX, &apos;||sAMEF_T_MAX||&apos; AS TVA_MAX,
          &apos;||sAMEF_B_MIN||&apos; AS BAZA_MIN, &apos;||sAMEF_T_MIN||&apos; AS TVA_MIN,
          &apos;||sAMEF_B_MED||&apos; AS BAZA_MED, &apos;||sAMEF_T_MED||&apos; AS TVA_MED,
          Row_Number() OVER (PARTITION BY trunc(a.Data_Z) + &apos;||sAMEF_B_MAX||&apos;+&apos;||sAMEF_T_MAX||&apos;, &apos;||sAMEF_B_MIN||&apos;+&apos;||sAMEF_T_MIN||&apos;, &apos;||sAMEF_B_MED||&apos;+&apos;||sAMEF_T_MED||&apos; ORDER BY a.NUI, a.NR_Z) IdxLoc
        FROM etva_AMEF a INNER JOIN etva e on a.codetva = e.codetva
        WHERE e.an = &apos;||vAn||&apos; and e.luna = &apos;||vLuna||&apos;
      ) A ON JV.DATADOC  = A.DATA_Z AND JV.IdxLoc = A.IdxLoc
         AND (A.BAZA_MAX+A.TVA_MAX) = Round(JV.BAZA_MAX+JV.TVA_MAX,2)
         AND (A.BAZA_MIN+A.TVA_MIN) = Round(JV.BAZA_MIN+JV.TVA_MIN,2)
         AND (A.BAZA_MED+A.TVA_MED) = Round(JV.BAZA_MED+JV.TVA_MED,2)&apos;||
      gSuplJoins||&apos;
    WHERE ( Coalesce( JV.BAZA_&apos;||vTipTva||&apos;, A.BAZA_&apos;||vTipTva||&apos;) &lt;&gt; 0 OR Coalesce( JV.TVA_&apos;||vTipTva||&apos;, JV.TVA_&apos;||vTipTva||&apos;) &lt;&gt; 0 )&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    sSelect := &apos;
    SELECT
      Coalesce(jv.NAV_CODDOC,I.CODIES) NAV_CODDOC, jv.NAV_CODDOC1, Coalesce(jv.NAV_TIPDOC,i.TIPDOC) NAV_TIPDOC, jv.ORDDOC,
      Coalesce(jv.DATADOC,i.DATADOC),Coalesce(jv.NRDOC,i.NRDOC),Coalesce(jv.NRI,i.NRI),Coalesce(jv.PREFIXDOC,i.PREFIXDOC,&apos;&apos;F&apos;&apos;),Coalesce(jv.SERIADOC,i.SERIADOC),
      Coalesce(jv.DEN_PART,i.DEN_PART),Coalesce(jv.CODFISCAL,i.CODFISCAL),Coalesce(jv.PERS_FIZ,i.PERS_FIZ),Coalesce(jv.VALDOC,i.VALDOC),
      &apos;||vCotaTva||&apos; AS PROC_TVA,
      jv.JURN_BAZA, jv.JURN_TVA,
      NULL AS Data_Z, NULL AS NR_Z, A.BAZA_LEI, A.TVA_LEI, A.DEN_CUMPARATOR,A.CUMP_CUI,A.NR_FACTURA &apos;||gUserAlias||&apos;
    FROM (
        SELECT
          t.NAV_CODDOC,t.NAV_CODDOC1,t.NAV_TIPDOC,t.ORDDOC,
          t.DATADOC,t.NRDOC,t.NRI,t.PREFIXDOC,t.SERIADOC,t.DEN_PART,t.CODFISCAL,t.VALDOC,
          CASE WHEN Coalesce(np.persoanafizica, 0) = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END PERS_FIZ,
          t.BAZA_&apos;||vTipTva||&apos; AS JURN_BAZA, t.TVA_&apos;||vTipTva||&apos; AS JURN_TVA,
          Coalesce(REPLACE(i.SERIADOC,&apos;&apos; &apos;&apos;), &apos;&apos;&apos;&apos;)||To_Char(i.NRDOC) NR_FACTURA
        FROM TMP_JV_D300 t
          INNER JOIN IESIRI i  ON i.codies   = t.nav_coddoc AND i.tipdoc = t.nav_tipdoc
          INNER JOIN NPART  np ON np.CODPART = i.PARTENER
        WHERE NOT t.NAV_TIPDOC IN (16)
          AND (t.BAZA_&apos;||vTipTva||&apos; &lt;&gt; 0 OR t.TVA_&apos;||vTipTva||&apos; &lt;&gt; 0)
      ) jv
      FULL JOIN (
        SELECT t.CODETVA_FACTURA, t.BAZA_LEI,t.TVA_LEI,f.DEN_CUMPARATOR,f.CUMP_CUI, REPLACE(f.NR_FACTURA,&apos;&apos; &apos;&apos;) NR_FACTURA
        FROM etva_factura_tva t
          INNER JOIN etva_factura f on t.codetva_factura = f.codetva_factura
          INNER JOIN etva         e on e.codetva         = t.codetva
        WHERE f.tip = &apos;&apos;V&apos;&apos; AND e.an = &apos;||vAn||&apos; and e.luna = &apos;||vLuna||&apos; AND t.cota_tva = &apos;||vCotaTva||&apos;
      ) A ON A.NR_FACTURA = jv.NR_FACTURA
      LEFT JOIN (
        SELECT
          i.codies, i.tipdoc,
          i.DATADOC,i.NRDOC,i.NRI,i.PREFIXDOC,i.SERIADOC, np.DEN_PART, cf.CODFISCAL, i.valdoc,
          CASE WHEN Coalesce(np.persoanafizica, 0) = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END PERS_FIZ,
          Coalesce(REPLACE(i.SERIADOC,&apos;&apos; &apos;&apos;), &apos;&apos;&apos;&apos;)||To_Char(i.NRDOC) NR_FACTURA
        FROM IESIRI i
          LEFT JOIN NPART        np ON np.codpart       = i.partener
          LEFT JOIN NPARTCODFISC cf ON cf.cod_codfiscal = i.codfiscal
        WHERE NOT i.TIPDOC IN (16)
          AND i.an = &apos;||vAn||&apos; and i.luna = &apos;||vLuna||&apos;
      ) I ON I.NR_FACTURA = A.NR_FACTURA AND jv.NR_FACTURA IS NULL &apos;||
      gSuplJoins;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  sUpdate := &apos;UPDATE &apos;||tmpName||&apos;
  SET DIF_BAZA = Coalesce(JURN_BAZA, 0) - Coalesce(ETVA_BAZA, 0),
      DIF_TVA  = Coalesce(JURN_TVA,  0) - Coalesce(ETVA_TVA,  0),
      TIPDOC   = PKG_LIST_BASE_UTILS.decode_tipdoc(NAV_TIPDOC)  &apos;;

  LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
  --PROCESSPARAMS;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_ETVAWME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EUDR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC48FB435D25845F7B06A07E8423774AE9561131</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EUDR is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  vNP          BOOLEAN;
  vIes         BOOLEAN;
  vAllCls      NUMBER(1);
  vAllArt      NUMBER(1);
  vTipA        INTEGER;
  vTipV        INTEGER;
  vEUDRA       VARCHAR2(100);
  vEUDRV       VARCHAR2(100);
  
PROCEDURE setParams (
  pDupaData   IN NUMBER   DEFAULT 1,
  pDataIni    IN VARCHAR2 DEFAULT NULL,
  pDataFin    IN VARCHAR2 DEFAULT NULL,
  pLunaAnIni  IN INTEGER  DEFAULT 0,
  pLunaAnFin  IN INTEGER  DEFAULT 0,
  pNP         IN INTEGER  DEFAULT 0,
  pIes        IN INTEGER  DEFAULT 0,
  pTipA       IN INTEGER  DEFAULT 0,
  pTipV       IN INTEGER  DEFAULT 0,
  pEUDRA      IN VARCHAR2 DEFAULT NULL,
  pEUDRV      IN VARCHAR2 DEFAULT NULL,
  pAllCls     IN NUMBER   DEFAULT 1,
  pAllArt     IN NUMBER   DEFAULT 1,
  pCodJob1    IN NUMBER   DEFAULT 0
)
IS
BEGIN
  vDupaData  := pDupaData = 1;
  vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vLunaAnIni := NVL(pLunaAnIni,0);
  vLunaAnFin := NVL(pLunaAnFin,0);
  vNP        := pNP = 1;
  vIes       := pIes = 1;
  vTipA      := pTipA;
  vTipV      := pTipV;
  vEUDRA     := pEUDRA;
  vEUDRV     := pEUDRV;
  vAllCls    := pAllCls;
  vAllArt    := pAllArt;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
  END IF;
END;

procedure CompleteazaSemif(aCodnirstoc in number, aCodNirStocS in number, aCantSemif in number) is
vSQL VARCHAR2(10000);
begin
  for v_rec in (
    select ns1.tipdoc, ns.codintr1, l1.codlivr1, aCantSemif * l1.cant / nssp.cantnir cant, ns.codnirstoc, ns.codobiect
    from nirstoc1 nss1
         inner join nirstoc nssp on nssp.codnirstoc = nss1.codnirstoc
         inner join comanda1 c1 on c1.codcomanda1 = nss1.codcomanda1
         inner join nartobj objp on objp.codobiect = c1.codobiect
         inner join nplink lk on lk.codnirstoc = nssp.codnirstoc
         inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
         inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
         inner join iesiri bc on bc.codies = bc1.codies
         inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr
         inner join nirstoc nsm on nsm.codnirstoc = l1.codnirstoc
         inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
         inner join nartobj objm on objm.codobiect = bc1.codobiect
    where nss1.codnirstoc = aCodNirStocS
          and (vTipA = 0 or vTipA = 1 and objm.CERTIF_DDS = 1 or vTipA = 2 and ns.eudr_rn = vEUDRA)
  ) loop
    if v_rec.tipdoc = 7 then
      pkg_list_base_eudr.CompleteazaSemif(acodnirstoc, v_rec.CodNirStoc, v_rec.cant);
    else
      insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
      values(acodnirstoc, v_rec.codlivr1, v_rec.cant);
      commit;
    end if;
  end loop;  
end;  

procedure CreateTmp is
vSQL VARCHAR2(10000);
sFiltruNP varchar2(500); 
begin
  delete tmp_lst_eudr; 
  if vNP then
    -- produse + semifabricate
    for v_rec in (
      select ns1.tipdoc, np1.codintr1, L1.codlivr1, ns.codnirstoc codnirstocS, l1.cant, nsp.codnirstoc
      from intrari np
           inner join intrari1 np1 on np1.codintr = np.codintr
           inner join nirstoc nsp on nsp.codintr1 = np1.codintr1
           inner join nartobj objp on objp.codobiect = np1.codobiect
           inner join nart a on objp.codarticol = a.codarticol
           inner join nplink lk on lk.codnirstoc = nsp.codnirstoc
           inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
           inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
           inner join iesiri bc on bc.codies = bc1.codies
           inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr 
           inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
           inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
           inner join nartobj objm on objm.codobiect = bc1.codobiect
      where np.tipdoc = 7 and np.operat = 1 and coalesce(np.anulat,0) = 0 and np1.codcmdint1 &gt; 0
            and np.datadoc between vDataIni and vDataFin
            and objp.produspropriu in (1,2)
            and (vAllCls = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = &apos;CODCLASEA&apos; and t.valoare = a.clasa))
            and (vAllArt = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = &apos;CODOBIECT&apos; and t.valoare = objp.codobiect))
            and (vTipA = 0 or vTipA = 1 and objm.CERTIF_DDS = 1 or vTipA = 2 and ns.eudr_rn = vEUDRA)
            and (vTipV = 0 or vTipV = 1 and objp.CERTIF_DDS = 1 or vTipV = 2 and nsp.eudr_rn = vEUDRV)
    ) loop
      if v_rec.tipdoc = 7 then
        pkg_list_base_eudr.CompleteazaSemif(v_rec.codnirstoc, v_rec.CodNirStocS, v_rec.cant);
      else
        insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
        values(v_rec.codnirstoc, v_rec.codlivr1, v_rec.cant);
      end if;
    end loop;
  else
    -- produse
    for v_rec in (
      select ns1.tipdoc, np1.codintr1, l1.codlivr1, ns.codnirstoc codnirstocS, l1.cant, nsp.codnirstoc
      from intrari np
           inner join intrari1 np1 on np1.codintr = np.codintr
           inner join nirstoc nsp on nsp.codintr1 = np1.codintr1
           inner join nartobj objp on objp.codobiect = np1.codobiect
           inner join nart a on objp.codarticol = a.codarticol
           inner join nplink lk on lk.codnirstoc = nsp.codnirstoc
           inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
           inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
           inner join iesiri bc on bc.codies = bc1.codies
           inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr 
           inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
           inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
           inner join nartobj objm on objm.codobiect = bc1.codobiect
      where np.tipdoc = 7 and np.operat = 1 and coalesce(np.anulat,0) = 0 and np1.codcmdint1 &gt; 0
            and np.datadoc between vDataIni and vDataFin
            and objp.produspropriu = 2
            and (vAllCls = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = &apos;CODCLASEA&apos; and t.valoare = a.clasa))
            and (vAllArt = 1 or exists (select t.valoare from tmp_manevra_liste t where t.filtru = &apos;CODOBIECT&apos; and t.valoare = objp.codobiect))
            and (vTipA = 0 or vTipA = 1 and objm.CERTIF_DDS = 1 or vTipA = 2 and ns.eudr_rn = vEUDRA)
            and (vTipV = 0 or vTipV = 1 and objp.CERTIF_DDS = 1 or vTipV = 2 and nsp.eudr_rn = vEUDRV)
    ) loop
      if v_rec.tipdoc = 7 then
        pkg_list_base_eudr.CompleteazaSemif(v_rec.codnirstoc, v_rec.CodNirStocS, v_rec.cant);
      else
        insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
        values(v_rec.codnirstoc, v_rec.codlivr1, v_rec.cant);
      end if;
    end loop;
  end if;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;tmp_lst_eudr t, intrari i, intrari1 i1, livr1 l1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  CreateTmp;
  
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     RegNrV,
     VerNrV,
     DataProd,
     Produs,
     CodExternV,
     UMV,
     CantV,    
     Material, 
     CodExternA,
     UMA,
     CantA,    
     RegNrA,   
     VerNrA,   
     Furnizor&apos;||gUserFields||&apos;
   )
  SELECT
     i.codintr NAV_CodDoc,
     i.tipdoc NAV_TipDoc,
     ns.EUDR_RN RegNrV,
     ns.EUDR_VN VerNrV,
     i.datadoc DataProd,
     objp.denumire Produs,
     objp.codextern CodExternV,
     ump1.den_um1 UMV,
     ns.cantnir CantV,
     objm.denumire Material, 
     objm.codextern CodExternA,
     umm1.den_um1 UMA,
     t.cant CantA,
     nsm.EUDR_RN RegNrA,   
     nsm.EUDR_VN VerNrA,
     p.den_part Furnizor &apos;||gUserAlias||&apos;
  FROM tmp_lst_eudr t
       inner join nirstoc ns on ns.codnirstoc = t.codnirstoc
       inner join intrari1 i1 on ns.codintr1 = i1.codintr1
       inner join intrari i on i.codintr = i1.codintr
       inner join nir n on n.codintr = i.codintr and ns.codnir = n.codnir
       inner join nartobj objp on objp.codobiect = i1.codobiect
       inner join num1 ump1 on ump1.codum1 = i1.umsec
       inner join livr1 l1 on t.codlivr1 = l1.codlivr1
       inner join iesiri1 ies1 on ies1.codies1 = l1.codies1
       inner join nartobj objm on objm.codobiect = ies1.codobiect
       inner join num1 umm1 on umm1.codum1 = ies1.umsec
       inner join nirstoc nsm on nsm.codnirstoc = l1.codnirstoc
       left join npart p on p.codpart = nsm.furn &apos;||
       gSuplJoins;

  --delete x;
  --insert into x(test) values(sinsert);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

procedure test is
begin
  delete tmp_lst_eudr;
  commit;
  for v_rec in (
    select ns1.tipdoc, np1.codintr1, l1.codlivr1, ns.codnirstoc codnirstocS, l1.cant, nsp.codnirstoc, ns.codobiect
    from intrari np
         inner join intrari1 np1 on np1.codintr = np.codintr
         inner join nirstoc nsp on nsp.codintr1 = np1.codintr1
         inner join nartobj objp on objp.codobiect = np1.codobiect
         inner join nart a on objp.codarticol = a.codarticol
         inner join nplink lk on lk.codnirstoc = nsp.codnirstoc
         inner join livr1 l1 on l1.codlivr1 = lk.codlivr1
         inner join iesiri1 bc1 on bc1.codies1 = l1.codies1
         inner join iesiri bc on bc.codies = bc1.codies
         inner join livr l on l.codies = bc.codies and l1.codlivr = l.codlivr 
         inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
         inner join nartobj objm on objm.codobiect = bc1.codobiect
    where np.tipdoc = 7 and np.operat = 1 and coalesce(np.anulat,0) = 0 and np1.codcmdint1 &gt; 0
          and np.datadoc = to_date(&apos;12.12.2025&apos;,&apos;dd.mm.yyyy&apos;)
          and objp.produspropriu = 2
  ) loop
    if v_rec.tipdoc = 7 then
      pkg_list_base_eudr.CompleteazaSemif(v_rec.codnirstoc, v_rec.CodNirStocS, v_rec.cant);
    else
      insert into tmp_lst_eudr(codnirstoc, codlivr1, cant)
      values(v_rec.codnirstoc, v_rec.codlivr1, v_rec.cant);
      commit;
    end if;
  end loop;
end;  


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_EUDR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>717084CA5771A6BB8CC78F7F6A0A8CA80A2A42F8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EVIDENTAMF is

  gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(2000);
  sSelect     VARCHAR2(10000);
  vCodNirStoc NUMBER(20);
  RecId       NUMBER(10);
  aLuna       NUMBER(2);
  aAn         NUMBER(4);
  aAL         NUMBER(5);
  dDataMax    DATE;
  aUserID     NUMBER(20);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;nartobj obj, nart art, nartobj imb&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  aUserID  := pkg_globals.getuserid;
  aLuna    := pkg_list_selectluna.LunaFin;
  aAn      := pkg_globals.GetANLUCRU;
  aAL      := aAn*12+aLuna;
  dDataMax := LAST_DAY(TO_DATE(&apos;01.&apos;||TO_CHAR(ALUNA,&apos;fm00&apos;)||&apos;.&apos;||TO_CHAR(AAN,&apos;fm0000&apos;),&apos;DD.MM.YYYY&apos;));

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);

  PKG_CATEGCONST.UMPLE_TMP_CODCONT_CONST(
    ESTEMIFIX             =&gt; TRUE,
    ESTEIMBUNATATIREMIFIX =&gt; TRUE
  );

  DELETE TMP_LST_FISAIMOB WHERE USERID = aUserID;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, IES.CODIES CODDOC, IES.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, IES1.CODIES1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC,
    F.CANT, F.CANT * F.PRETE VALOARE, IES1.TVA, IES.DATADOC, F.OBS, 1 MF, 0 IMBMF,
    &apos;Intrare in firma&apos; TIPOPERATIE,
    0 Dirty, IES.AN, IES.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 1 AND FMF.tipdoc = 15
  ) F
    INNER JOIN IESIRI1 IES1 ON IES1.CODIES1 = F.CODDOC1
    INNER JOIN IESIRI IES ON IES.CODIES = IES1.CODIES AND IES.TIPDOC = F.TIPDOC
    INNER JOIN NIR NIR ON NIR.CODIES = IES.CODIES
    INNER JOIN INTRARI I ON I.CODINTR = NIR.CODINTR
    INNER JOIN INTRARI1 I1 ON I.CODINTR = I.CODINTR
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODINTR1 = I1.CODINTR1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND IES.AN*12+IES.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE IES.AN*12+IES.LUNA &lt;= aAL
    AND Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC,
    F.CANT CANT, F.CANT * F.PRETE VALOARE, T1.TVA, T.DATADOC, F.OBS, 1 MF, 0 IMBMF,
    &apos;Transfer intre gestiuni&apos; TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 2 AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF AND F.TIPDOC = T.TIPDOC
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN*12+T.LUNA &lt;= aAL
    AND Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, II.CODINTR CODDOC, II.TIPDOC TIPDOC, T.CODTRANSF CODDOCSEC, T.TIPDOC TIPDOCSEC, II1.CODINTR1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, P.DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, II1.PU*DECODE(NVL(II.CURS,1),0,1,NVL(II.CURS,1)) PRETE, II.PREFIXDOC, II.NRDOC,
    II1.CANT CANT, II1.CANT * II1.PU*DECODE(NVL(II.CURS,1),0,1,NVL(II.CURS,1)) VALOARE, II1.TVA*DECODE(NVL(II.CURS,1),0,1,NVL(II.CURS,1)), II.DATADOC DATADOC, F.OBS, 1 MF, 0 IMBMF,
    CASE
      WHEN II.TIPDOC = 1 AND II.TIPFACTURA = 3 THEN &apos;Leasing&apos;
      WHEN II.TIPDOC = 1 AND nvl(II.TIPFACTURA,0) = 0 THEN &apos;Factura intrare - interna&apos;
      WHEN II.TIPDOC = 5 THEN &apos;Factura intrare - import&apos;
    END TIPOPERATIE,
    0 Dirty, II.AN, II.LUNA, NVL(P.CODPART,0) CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 3 AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF AND F.TIPDOC = T.TIPDOC
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN IMBMIFIXLINK L ON L.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN INTRARI1 II1 ON II1.CODINTR1 = L.CODINTR1
    INNER JOIN INTRARI II ON II.CODINTR = II1.CODINTR
    INNER JOIN NPART P ON P.CODPART = II.PARTENER
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN*12+T.LUNA &lt;= aAL
    AND Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    obj.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC,
    F.CANT, F.CANT * F.PRETE VALOARE, T1.TVA, T.DATADOC, F.OBS, 1 MF, 0 IMBMF,
    CASE
      WHEN F.CODOPERATIE =  6 THEN &apos;Reevaluare - valoare MF&apos;
      WHEN F.CODOPERATIE =  7 THEN &apos;Reevaluare - amortizare prec&apos;
      WHEN F.CODOPERATIE =  9 THEN &apos;Modificare gestiune&apos;
      WHEN F.CODOPERATIE = 10 THEN &apos;Modificare centru de cost&apos;
      WHEN F.CODOPERATIE = 11 THEN &apos;Modificare tip contabil&apos;
    END TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
  FROM  (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE IN (6,7,9,10,11) AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF AND F.TIPDOC = T.TIPDOC
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN*12+T.LUNA &lt;= aAL
    AND Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    objm.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE PRETE, F.PREFIXDOC PREFIXDOC, F.NRDOC NrDoc,
    F.CANT CANT, F.CANT * F.PRETE VALOARE, T1.TVA, Coalesce(T.DATADOC,F.dataoperatie) DATADOC, F.OBS, 1 MF, 0 IMBMF,
    &apos;Punere in functiune&apos; TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
   FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 12 AND tipdoc = 12 AND FMF.DATAOPERATIE &lt;= dDataMax
  ) F
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsm on nsm.codnirstoc = mf1.codnirstoc
    INNER JOIN nartobj objm on nsm.codobiect = objm.codobiect
    LEFT JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    LEFT JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF AND F.TIPDOC = T.TIPDOC
    LEFT JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    LEFT JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    NS.CODNIRSTOC, IES.CODIES CODDOC, IES.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, IES1.CODIES1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, P.DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC,
    F.CANT, F.CANT * F.PRETE VALOARE, CASE WHEN f.codoperatie = 5 THEN 0 ELSE IES1.TVA END TVA, IES.DATADOC, F.OBS, 1 MF, 0 IMBMF,
    CASE
      WHEN F.CODOPERATIE = 4 THEN &apos;Casare&apos;
      WHEN F.CODOPERATIE = 5 THEN &apos;Vanzare&apos;
    END TIPOPERATIE,
    0 Dirty, IES.AN, IES.LUNA, NVL(P.CODPART,0) CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CODNS, IOA1.CODIOART1, mf1.CODMIFIX1, aUserID
  FROM  (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE IN (4,5)AND tipdoc IN (14, 19, 20, 21, 22, 23)
  ) F
    INNER JOIN IESIRI1 IES1 ON IES1.CODIES1 = F.CODDOC1
    INNER JOIN IESIRI IES ON IES.CODIES = IES1.CODIES AND IES.TIPDOC = F.TIPDOC
    INNER JOIN LIVR L ON L.CODIES = IES1.CODIES AND L.TIPLIVR = F.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = IES1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND IES.AN*12+IES.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR AND Coalesce(NIR.CODIES,0) &lt;&gt; IES.CODIES
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    LEFT JOIN NPART P ON P.CODPART = IES.PARTENER
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE IES.AN*12+IES.LUNA &lt;= aAL
    AND Coalesce(TCC.ESTEMIFIX, 0) = 1;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc,
    cant, valoare, tva, datadoc, obs, mf, imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1, userid
  )
  SELECT
    0 CODNIRSTOC, J1.CODDOC, J1.TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, J1.CodDoc IndexLocal,
    OBJ.DENUMIRE, MF.NrInventar, &apos; &apos; DEN_PART,
    J1.CODDOC CODMIFIX, 12 CODOPERATIE, J1.DATADOC DATAOPERATIE, 0 GESTSURSA, 0 GESTDEST, NS.PRET PRETI, NS.PRET PRETE, J1.DOCUMENT PREFIXDOC, 0 NrDoc,
    NS.REST CANT, J1.VALOARE, 0 TVA, J1.DATADOC, J1.OBS, 1 MF, 0 IMBMF,
    &apos;Amortizare&apos; TIPOPERATIE,
    J1.Dirty, J1.AN, J1.LUNA, 0 CODPART, 0 CODPARTSEC, 0 CodDoc1, NS.CodNirStoc CODNS, IOA1.CODIOART1, mff1.CODMIFIX1, aUserID
  FROM (
    SELECT DISTINCT xj1.coddoc, xj1.tipdoc, xj1.datadoc, xj1.valoare, xj1.an, xj1.luna, xj1.dirty, xj1.obs, xj1.document, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = xj1.coddoc) al_mf1
    FROM JURNAL1 xj1
    WHERE xj1.TipDoc = 36 AND xj1.AN*12+xj1.LUNA &lt;= aAL
  ) J1
    INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = J1.CODDOC AND MF1.ANSTART*12+MF1.LUNASTART = J1.AN*12+J1.LUNA
    INNER JOIN MIFIX MF ON MF1.CODMIFIX = MF.CODMIFIX
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND J1.AN*12+J1.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN mifix1 mff1 on mff1.codmifix = J1.CODDOC AND MF1.ANSTART*12+MF1.LUNASTART = j1.al_mf1
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE Coalesce(TCC.ESTEMIFIX, 0) = 1;

  DELETE tmp_lst_fisaimob where MF = 0 OR CodOperatie IN (6, 7);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NrInventar, Articol, Cont, ValPtAmo, Clasificare, Durata, RestDurata,
    TipAmo,
    DataPunere, ValAmo, ValNeAmo, AmoLunara, LunaC, AnC,
    Stare,
    DataStare, CentruCost, Gestiune, Tip, Partener, Doc,
    Cant, Pret, Valoare, TVA, Luna, An,
    Vechi, Nou, CentruCostM, GestiuneM, DataOperatie &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    tmp.NrInventar, tmp.denumire Articol, c.simbol Cont, 0 ValPtAmo, cls.denumire Clasificare, 0 Durata, 0 RestDurata,
    case
      when mf1.TipAmo = 1 then &apos;&apos;Liniara&apos;&apos;
      when mf1.TipAmo = 2 then &apos;&apos;Accelerata&apos;&apos;
      when mf1.TipAmo = 3 then &apos;&apos;Degresiva 1&apos;&apos;
      when mf1.TipAmo = 4 then &apos;&apos;Degresiva 2&apos;&apos;
    end TipAmo,
    ev.datastart DataPunere, 0 ValAmo, 0 ValNeAmo, 0 AmoLunara, mfl.lunastart Luna, tmp.An,
    case
      when mf1.stare = 1 then &apos;&apos;in Curs de amortizare&apos;&apos;
      when mf1.stare = 2 then &apos;&apos;Trecut in conservare&apos;&apos;
      when mf1.stare = 3 then &apos;&apos;Casat in luna curenta&apos;&apos;
      when mf1.stare = 4 then &apos;&apos;Vandut in luna curenta&apos;&apos;
    end Stare,
    tmp.dataoperatie DataStare, ccc.denumire CentruCost, gc.den_gest Gestiune, TMP.TIPOPERATIE Tip, TMP.DEN_PART Partener, TMP.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(TMP.DATAOPERATIE, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,
    TMP.Cant, TMP.PretE, TMP.Valoare, TMP.TVA, TMP.Luna, TMP.An,
    &apos;&apos; &apos;&apos; Vechi, &apos;&apos; &apos;&apos; Nou, &apos;&apos; &apos;&apos; CentruCostM, &apos;&apos; &apos;&apos; GestiuneM, tmp.dataoperatie &apos;||gUserAlias||&apos;
  FROM tmp_lst_fisaimob tmp
    LEFT JOIN transf1 t1 on tmp.coddoc1 = t1.codtransf1 and tmp.codoperatie = 3
    LEFT JOIN nartobj imb on t1.codobiect = imb.codobiect
    LEFT JOIN ioart1 ioa1 on ioa1.codioart1 = tmp.codioart1
    LEFT JOIN ioart ioa on ioa.codioart = ioa1.codioart
    LEFT JOIN ncont c on ioa1.cont = c.codcont
    LEFT JOIN mifix1 mf1 on mf1.codmifix1 = tmp.codmifix1 and mf1.anstart * 12 + mf1.lunastart = tmp.an * 12 + tmp.luna
    LEFT JOIN mifix1 mfl on mfl.codmifix1 = tmp.codmifix1
    LEFT JOIN mfclasif cls on cls.codclasif = mfl.codclasif
    LEFT JOIN centrecost ccc on ccc.codcentru = mfl.codcentru
    LEFT JOIN nirstoc nsc on nsc.codnirstoc = mfl.codnirstoc
    LEFT JOIN nir nirc on nirc.codnir = nsc.codnir
    LEFT JOIN ngest gc on gc.codgest = nirc.gest
    LEFT JOIN nirstoc ns on ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nartobj obj on obj.codobiect = ns.codobiect
    LEFT JOIN nart art on art.codarticol = obj.codarticol
    LEFT JOIN nir on nir.codnir = ns.codnir
    LEFT JOIN ngest g on g.codgest = nir.gest
    LEFT JOIN evidentamf ev on ev.codmifix = tmp.codmifix &apos;||
    gSuplJoins||&apos;
  WHERE tmp.userid = pkg_globals.getuserid&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_EVIDENTAMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D1FBBC668706D4680CC32BDB69B34B418C101FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERT IS

  gNivelMax   NUMBER(10);
  gCodAnaliza NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GETCODANALIZA RETURN NUMBER IS
BEGIN
  RETURN gCodAnaliza;
END;

PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER) IS
BEGIN
  gCodAnaliza := ACODANALIZA;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
BEGIN
  DELETE FROM TMP_DINAMIC_COLS;

  INSERT INTO TMP_DINAMIC_COLS(
    FieldName,
    Display, IndexLocal, FType, FSize, Cod)
  SELECT 
    &apos;D&apos;||Row_Number() OVER (ORDER BY A1.INDEXLOCAL, D.CODDESCRIPTOR),
    D.DEN_DESCRIPTOR , A1.INDEXLOCAL, 2, 200, D.CODDESCRIPTOR
  FROM   ANALIZA1 A1 INNER JOIN DESCRIPTORI D ON A1.CODDESCRIPTOR = D.CODDESCRIPTOR
  WHERE A1.CODANALIZA = PKG_LIST_BASE_EXPERT.GETCODANALIZA
  ORDER BY A1.INDEXLOCAL, D.CODDESCRIPTOR;

  SELECT Coalesce(Max(LEVEL),0)-1 INTO gNivelMax
  FROM ANALIZANOD
  CONNECT BY PRIOR CODANALIZANOD = NODPARINTE
  START WITH COALESCE(NODPARINTE,0) = 0 AND CODANALIZA = gCodAnaliza;

  FOR j IN 1..gNivelMax LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;N&apos;||To_Char(j,&apos;fm999&apos;), &apos;Simbol nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;B&apos;||To_Char(j,&apos;fm999&apos;), &apos;Descr. nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
  END LOOP;

  COMMIT;
END;

FUNCTION GET_VALOARE(S in varchar2 ,I in number) RETURN VARCHAR2 IS
  finish       number(3);
  stop         number(20) := 0;
  coddescript1 varchar2(20);
  RES          VARCHAR2(200);
  str          varchar2(200);
BEGIN
  str := trim(S);
  str := substr(str,4,length(str));
  WHILE stop &lt; i LOOP
    finish       := instr(str,&apos;,&apos;);
    coddescript1 := substr(str,1,finish-1);
    str          := substr(str,finish+1,length(str));
    stop         := stop + 1;
  END LOOP;
  IF to_number(coddescript1) &gt; 0 THEN
    BEGIN
      SELECT VALOARE INTO RES FROM DESCRIPTORI1 WHERE CODDESCRIPTOR1 = TO_NUMBER(CODDESCRIPT1);
    EXCEPTION WHEN OTHERS THEN
      RES := &apos;?&apos;;
    END;
  ELSE
    RES := &apos;?&apos;;
  END IF;

  RETURN COALESCE(RES,&apos;?&apos;);
END;

PROCEDURE POPULEAZA_COL_DINAMICE(tmpname in varchar2) IS
  sUpdate varchar2(4000);
  idx number(3);
BEGIN
  FOR V_REC IN (
    SELECT X.CODANALIZANOD, X.CODDESCRIPTOR, SYS_CONNECT_BY_PATH(COALESCE(X.CODDESCRIPTOR1,0),&apos;,&apos;)||&apos;,&apos; caleax
    FROM  (
      SELECT AN.CODANALIZANOD,AN.NODPARINTE,D1.VALOARE,AN.CODANALIZA,D1.CODDESCRIPTOR1, D1.CODDESCRIPTOR
      FROM ANALIZANOD AN LEFT JOIN  DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
      WHERE CODANALIZA = PKG_LIST_BASE_EXPERT.GETCODANALIZA
    ) X
    START WITH X.NODPARINTE = 0
    CONNECT BY PRIOR X.CODANALIZANOD = X.NODPARINTE
  ) LOOP
    SUPDATE := &apos;UPDATE &apos;||TMPNAME||&apos; SET &apos;;
    idx := 0;
    FOR V_REC_COLS IN (SELECT * FROM TMP_DINAMIC_COLS) LOOP
      idx := idx+1;
      SUPDATE := SUPDATE||V_REC_COLS.FIELDNAME||&apos; = &apos;&apos;&apos;||REPLACE(Get_valoare(v_rec.caleax,idx),&apos;&apos;&apos;&apos;,&apos;&apos;&apos;&apos;&apos;&apos;)||&apos;&apos;&apos;,&apos;;
    END LOOP;
    sUpdate := SUBSTR(SUPDATE,1,LENGTH(SUPDATE)-1);
    sUpdate := SUPDATE ||&apos; WHERE CODANALIZANOD = &apos;||V_REC.CODANALIZANOD;
    IF idx &gt; 0 THEN
      EXECUTE IMMEDIATE sUpdate;
    END IF;
  END LOOP;
END;


PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sINSERT CLOB;
  sUpdate CLOB;
  sInsDc  CLOB;
  sSelDC  CLOB;
  sWithDC CLOB;
  sTranfC VARCHAR2(100);
BEGIN
  gSuplCols := &apos;EXPERT E, EXPERT1 E1, NCONT NCDEBIT, NCONT NCCREDIT, ELEMENTE EL, ANALIZANOD AN, DESCRIPTORI1 D1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sTranfC := CASE WHEN PKG_LIST_SELECTLUNAAN.Curs = 1 THEN &apos;&apos; ELSE &apos;/PKG_LIST_SELECTLUNAAN.Curs&apos; END;

  FOR j IN 1..gNivelMax LOOP
    sInsDc  := sInsDc ||&apos;, N&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, B&apos;||To_Char(j,&apos;fm999&apos;);
    sSelDC  := sSelDC ||&apos;, dc.N&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, COALESCE(dc.B&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;)&apos;;
    sWithDC := sWithDC||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Valoare END) B&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Simbol  END) N&apos;||To_Char(j,&apos;fm999&apos;);
  END LOOP;

  -- stef - ca sa evit niste coloane dinamice cu valori NULL -- cazuri exceptionale intalnite
  FOR xRec IN (SELECT Fieldname, IndexLocal FROM TMP_DINAMIC_COLS WHERE SubStr(FieldName,1,1) = &apos;D&apos;)
  LOOP
    sInsDc  := sInsDc ||&apos;, &apos;||xRec.Fieldname;
    sSelDC  := sSelDC ||&apos;, &apos;&apos;...&apos;&apos;&apos;;
  END LOOP;

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CODANALIZANOD,NAV_TIPDOC,NAV_CODDOC,
    DOCUMENT,
    DOCOBS,
    SIMBOL,
    DEN_ELEMENT,
    TIPCONT,
    TIPELEMENT,
    VALDESCRIPT,
    VALOAREC,
    VALOARED,
    VALTOT,
    VALOAREV, AN, LUNA, LUNAX&apos;||sInsDc||gUserFields||&apos;)
  WITH DC AS (
    SELECT Cod&apos;||
      sWithDC||&apos;
    FROM (
      SELECT x.Cod, y.idx, d.valoare, y.simbol
      FROM (
          SELECT CONNECT_BY_ROOT CodAnalizaNod Cod, CodAnalizaNod, CodDescriptor1, LEVEL IDX
          FROM AnalizaNod
          WHERE NODPARINTE &lt;&gt; 0
          CONNECT BY PRIOR NODPARINTE = CODANALIZANOD
          START WITH CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) x
        LEFT JOIN (
          SELECT CodAnalizaNod, LEVEL-1 IDX, SubStr(sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;),5,30) SIMBOL
          FROM AnalizaNod
          CONNECT BY NODPARINTE = PRIOR CODANALIZANOD
          START WITH NODPARINTE = 0 AND CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) y ON y.codanalizanod = x.codanalizanod
        LEFT JOIN descriptori1 d ON d.coddescriptor1 = x.coddescriptor1
    )
    GROUP BY Cod
  )
  SELECT
    COALESCE(AN.CODANALIZANOD,0) CODANALIZANOD,E.TIPDOC,e.CODDOC,
    pkg_list_base_utils.GETDENDOC(E.CODDOC, E.TIPDOC, E1.INDEXJURN) AS DOCUMENT,
    pkg_list_base_utils.GETOBSDOC(E.CODDOC, E.TIPDOC, E1.INDEXJURN) AS DOCOBS,
    CASE WHEN E1.TIPCONT = 0 THEN NCDEBIT.SIMBOL ELSE NCCREDIT.SIMBOL END SIMBOL,
    EL.DEN_ELEMENT,
    DECODE(COALESCE(EL.CV,0),0,&apos;&apos;Cheltuiala&apos;&apos;,1,&apos;&apos;Venit&apos;&apos;) tipCont,
    DECODE(EL.TIP,0,&apos;&apos;Element de cheltuiala&apos;&apos;,1,&apos;&apos;Element de venit&apos;&apos;,2,&apos;&apos;Element bifunctional&apos;&apos;) tipelement,
    D1.VALOARE VALDESCRIPT,
    CASE WHEN E1.TIPCONT = 0 THEN E1.VALOARE WHEN E1.TIPCONT = 2 AND E1.VALOARE &lt; 0 THEN -E1.VALOARE ELSE 0 END&apos;||sTranfC||&apos; VALOAREC,
    CASE WHEN E1.TIPCONT = 1 THEN E1.VALOARE WHEN E1.TIPCONT = 2 AND E1.VALOARE &gt; 0 THEN  E1.VALOARE ELSE 0 END&apos;||sTranfC||&apos; VALOARED,
    CASE WHEN COALESCE(EL.CV,0) = 0 THEN (CASE WHEN E1.TIPCONT = 0 THEN E1.VALOARE  ELSE -1 * E1.VALOARE  END) ELSE (CASE WHEN E1.TIPCONT = 0 THEN -1 * E1.VALOARE  ELSE E1.VALOARE  END) END&apos;||sTranfC||&apos; VALTOT,
    CASE WHEN COALESCE(EL.CV,0) = 0 THEN (CASE WHEN E1.TIPCONT = 0 THEN E1.VALOAREV ELSE -1 * E1.VALOAREV END) ELSE (CASE WHEN E1.TIPCONT = 0 THEN -1 * E1.VALOAREV ELSE E1.VALOAREV END) END&apos;||sTranfC||&apos; VALOAREV,
    E.An, E.Luna, pkg_list_base_utils.decode_luna(E.Luna)&apos;||sSelDC||gUserAlias||&apos;
  FROM EXPERT E
    INNER JOIN EXPERT1 E1 ON E.CODEXPERT = E1.CODEXPERT
    INNER JOIN NCONT NCDEBIT ON NCDEBIT.CODCONT =E1.CONTD
    INNER JOIN NCONT NCCREDIT ON NCCREDIT.CODCONT = E1.CONTC
    INNER JOIN ELEMENTE EL ON EL.CODELEMENT = E1.CODELEMENT
    LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = E1.CODANALIZANOD
    LEFT JOIN DESCRIPTORI1 D1 ON D1.CODDESCRIPTOR1 = E1.CODDESCRIPTOR1
    LEFT JOIN DC ON DC.cod = e1.CodAnalizaNod&apos;||
    gSuplJoins||&apos;
  WHERE E.CODANALIZA = &apos;||gCodAnaliza||&apos;
    AND E.AN * 12 + E.LUNA BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;E1&apos;,&apos;SUBUNITJURN&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  FOR j IN 2..gNivelMax LOOP
    sUpdate := &apos;
    UPDATE &apos;||tmpName||&apos;
    SET N&apos;||To_Char(j,&apos;fm999&apos;)||&apos; = N&apos;||To_Char(j-1,&apos;fm999&apos;)||&apos;||&apos;&apos;.00&apos;&apos;
    WHERE N&apos;||To_Char(j,&apos;fm999&apos;)||&apos; IS NULL&apos;;
    LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
  END LOOP;

  COMMIT;
  POPULEAZA_COL_DINAMICE(TMPNAME);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_EXPERT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTBAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A87E8791D8473838A57C908A8AFC6070EAF48028</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERTBAL IS

  gCodAnaliza NUMBER(20);
  gAn         NUMBER(4);
  gLuna       NUMBER(2);

  gUserFields    VARCHAR2(2500);
  gUserAlias     VARCHAR2(2500);
  gNullAlias     VARCHAR2(2500);
  gSuplCols      VARCHAR2(2500);
  gSuplJoins     VARCHAR2(5000);

  p_sintetic     NUMBER;
  g_tmpTABLE     VARCHAR2(100);
  prev_codsint   NUMBER(20);
  p_IDX_SINTETIC INTEGER;

  p_ClasaV       INTEGER;
  p_ClasaC       INTEGER;

PROCEDURE SETPARAMS (
  pCodAnaliza IN NUMBER,
  pAn         IN NUMBER,
  pLuna       IN NUMBER,
  v_CodJob1   IN NUMBER  DEFAULT 0)
IS
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  dDataS     DATE;
  dDataF     DATE;
BEGIN
  dDataS     := GetData(pAn, pLuna);
  dDataF     := Last_Day(dDataF);
  xLunaAnIni := pAn*12+pLuna;
  xLunaAnFin := pAn*12+pLuna;

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(v_CodJob1,dDataS,dDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  gCodAnaliza := pCodAnaliza;
  PKG_LIST_BASE_UTILS.ExtractAnLuna (xLunaAnIni, gAn, gLuna);
END;

PROCEDURE GetContRec(p_CodCont IN NCont.Codcont%TYPE, v_rec IN OUT NCONT%ROWTYPE)
IS
BEGIN
  SELECT *
  INTO v_rec
  FROM NCONT
  WHERE CODCONT = p_CodCont;
END;

PROCEDURE Insert_Rec(p_rec IN TMP_LST_EXPERTBAL%ROWTYPE, tmpName IN VARCHAR2)
IS
  sInsert VARCHAR2(10000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    CODCONT, CODANALIZANOD,
    CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL, INDEX_SINTETIC, FRUNZA,
    SIMBSINTETIC, DEN_SINTETIC, SIMB_NOD, DEN_NOD,
    RULAJPD, RULAJPC, RULAJCD, RULAJCC, TOTALD, TOTALC)
  VALUES(
    :CODCONT, :CODANALIZANOD,
    :CLASA, :SIMBOL, :DEN_CONT, :TIPCONT, :NAME, :BALANTASINTETICA, :NIVEL, :INDEX_SINTETIC, :FRUNZA,
    :SIMBSINTETIC, :DEN_SINTETIC, :SIMB_NOD, :DEN_NOD,
    :RULAJPD, :RULAJPC, :RULAJCD, :RULAJCC, :TOTALD, :TOTALC)&apos; ;

  EXECUTE IMMEDIATE sInsert
  USING
    p_rec.codcont, p_rec.codanalizanod,
    p_rec.clasa, p_rec.simbol, p_rec.den_cont, p_rec.tipcont, p_rec.name, p_rec.balantasintetica, p_rec.nivel, p_idx_sintetic, 1,
    p_rec.simbsintetic, p_rec.den_sintetic, p_rec.simb_nod, p_rec.den_nod,
    p_rec.rulajpd, p_rec.rulajpc, p_rec.rulajcd, p_rec.rulajcc, p_rec.rulajpd+p_rec.rulajcd, p_rec.rulajpc+p_rec.rulajcc;
END;

PROCEDURE Fill_RecTotals(v_bal IN TMP_LST_EXPERTBAL%ROWTYPE)
IS
  v_ncont       NCONT%ROWTYPE;
  v_codparinte  NUMBER(20);
  vSIMBPLANP    VARCHAR2(3200);
  v_AUX_CODCONT TMP_LST_EXPERTBAL.CODCONT%TYPE;
BEGIN
  v_codparinte := v_bal.codparinte;
  WHILE Coalesce(v_codparinte,0) &lt;&gt; 0 LOOP
    GetContRec(v_codparinte, v_ncont);

    IF v_ncont.vizibilbalanta = 1
    -- ((p_sintetic = 0 AND v_ncont.vizibilbalanta = 1) OR (p_sintetic = 1 AND v_ncont.balantasintetica = 1)) -- filtrare dupa analitic / sintetic
    THEN
      v_AUX_CODCONT := 0;

      UPDATE TMP_LST_EXPERTBAL
      SET
        RULAJPD    = RULAJPD + v_bal.RULAJPD,
        RULAJPC    = RULAJPC + v_bal.RULAJPC,
        RULAJCD    = RULAJCD + v_bal.RULAJCD,
        RULAJCC    = RULAJCC + v_bal.RULAJCC
      WHERE CODCONT = v_ncont.codcont
      RETURNING CODCONT INTO v_aux_codcont;

      IF v_AUX_CODCONT = 0 THEN
        INSERT INTO TMP_LST_EXPERTBAL (
          CODCONT, CODANALIZANOD, CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME,
          BALANTASINTETICA, NIVEL, CODSINTETIC, CODPARINTE, SIMBSINTETIC, DEN_SINTETIC,
          RULAJPD, RULAJPC, RULAJCD, RULAJCC)
        VALUES (
          v_ncont.codcont, 0, v_ncont.clasa, v_ncont.simbol, v_ncont.den_cont, CASE v_ncont.tipcont WHEN 1 THEN &apos;PASIV&apos; WHEN 2 THEN &apos;BIFUNC&apos; ELSE &apos;ACTIV&apos; END, v_ncont.name,
          Coalesce(v_ncont.balantasintetica,-1), v_ncont.nivel, v_bal.codsintetic, v_ncont.codparinte, v_bal.simbsintetic, v_bal.den_sintetic,
          v_bal.RULAJPD, v_bal.RULAJPC, v_bal.RULAJCD, v_bal.RULAJCC);
      END IF;

    END IF;
    v_codparinte := v_ncont.codparinte;
  END LOOP;
END;

PROCEDURE Insert_RecTotal(tmpName IN VARCHAR2)
IS
  sInsert   VARCHAR2(5000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    CODCONT, CODANALIZANOD, CLASA, SIMBOL, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL, INDEX_SINTETIC, SIMBSINTETIC, DEN_SINTETIC,
    RULAJPD, RULAJPC, RULAJCD, RULAJCC, TOTALD, TOTALC)
  SELECT
    T.CODCONT, T.CODANALIZANOD, T.CLASA, T.SIMBOL, T.DEN_CONT, T.TIPCONT, T.NAME, T.BALANTASINTETICA, T.NIVEL, :INDEX_SINTETIC, T.SIMBSINTETIC, T.DEN_SINTETIC,
    T.RULAJPD, T.RULAJPC, T.RULAJCD, T.RULAJCC, T.RULAJPD+T.RULAJCD, T.RULAJPC+T.RULAJCC
  FROM TMP_LST_EXPERTBAL T&apos;;

  EXECUTE IMMEDIATE sInsert USING p_IDX_SINTETIC;
  DELETE TMP_LST_EXPERTBAL;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSBALANTA(tmpName IN VARCHAR2) IS
  vTest   VARCHAR2(30000);
BEGIN
  prev_codsint := -1;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_EXPERTBALRAW&apos;;

  FOR vLuna IN 1..gLuna
  LOOP
    INSERT INTO TMP_LST_EXPERTBALRAW(CODCONT, CODANALIZANOD, AN, LUNA, RULAJD, RULAJC)
    SELECT codcont, codanalizanod, an, luna, Sum(rulajd), Sum(rulajc)
    FROM (
      SELECT c.codcont, Coalesce(e1.codanalizanod, 0) codanalizanod, e.an, e.luna, e1.valoare rulajd, 0 rulajc
      FROM expert e
        INNER JOIN expert1 e1 ON e1.codexpert = e.codexpert
        INNER JOIN ncont c ON c.codcont = e1.contd
      WHERE e.an = gAn AND e.luna = vLuna
        AND (c.clasa = p_ClasaV OR c.clasa = p_ClasaC)
        AND Coalesce(e.codanaliza, 0) = gCodAnaliza
        AND e1.tipcont = c.tipcont
      UNION ALL
      SELECT c.codcont, Coalesce(e1.codanalizanod, 0) codanalizanod, e.an, e.luna, 0 rulajd, e1.valoare rulajc
      FROM expert e
        INNER JOIN expert1 e1 ON e1.codexpert = e.codexpert
        INNER JOIN ncont c ON c.codcont = e1.contc
      WHERE e.an = gAn AND e.luna = vLuna
        AND (c.clasa = p_ClasaV OR c.clasa = p_ClasaC)
        AND Coalesce(e.codanaliza, 0) = gCodAnaliza
        AND e1.tipcont = c.tipcont
    ) ebal
    GROUP BY codcont, codanalizanod, an, luna;
  END LOOP;
  COMMIT;

  FOR v_rec IN (
    WITH
      /*RECURSIVE*/ C (CODCONT, CLASA, CODPARINTE, DEN_CONT, TIPCONT, NAME, BALANTASINTETICA, NIVEL, SIMBOL, CODSINTETIC, SIMBSINTETIC, DEN_SINTETIC, FARA_FII) AS ( 
        SELECT
          XC.CODCONT, XC.CLASA, XC.CODPARINTE, XC.DEN_CONT, Coalesce(XC.TIPCONT,0) AS TIPCONT, XC.NAME, XC.BALANTASINTETICA, 
          0 AS NIVEL, LPad(&apos; &apos;, 0)||XC.SIMBOL AS SIMBOL,
          XC.CODCONT CODSINTETIC, XC.SIMBOL SIMBSINTETIC, XC.DEN_CONT DEN_SINTETIC,
          CASE WHEN EXISTS (SELECT 1 FROM ncont cp WHERE cp.codparinte = xc.codcont) THEN 0 ELSE 1 END AS FARA_FII
        FROM   ncont xc 
        WHERE  Coalesce(codparinte,0) = 0 AND (clasa = p_ClasaV OR clasa = p_ClasaC)
        UNION ALL 
        SELECT
          XC.CODCONT, XC.CLASA, XC.CODPARINTE, XC.DEN_CONT, Coalesce(XC.TIPCONT,0) AS TIPCONT, XC.NAME, XC.BALANTASINTETICA, 
          C.NIVEL + 1 AS NIVEL, LPad(&apos; &apos;, 2*(C.NIVEL+1))||XC.SIMBOL AS SIMBOL, 
          C.CODSINTETIC, C.SIMBSINTETIC, C.DEN_SINTETIC,
          CASE WHEN EXISTS (SELECT 1 FROM ncont cp WHERE cp.codparinte = xc.codcont) THEN 0 ELSE 1 END AS FARA_FII
        FROM ncont xc INNER JOIN c ON c.codcont = xc.codparinte
      ),
      B AS (
        SELECT
          CODCONT, CODANALIZANOD,
          SUM(CASE WHEN luna &lt; gLuna THEN rulajd ELSE 0 END) rulajpd, SUM(CASE WHEN luna &lt; gLuna THEN rulajc ELSE 0 END) rulajpc,
          SUM(CASE WHEN luna = gLuna THEN rulajd ELSE 0 END) rulajcd, SUM(CASE WHEN luna = gLuna THEN rulajc ELSE 0 END) rulajcc
        FROM TMP_LST_EXPERTBALRAW
        GROUP BY CODCONT, CODANALIZANOD
      )
    SELECT
      C.CODCONT, B.CODANALIZANOD,
      C.CLASA, C.SIMBOL SIMBOL, C.DEN_CONT, CASE C.TIPCONT WHEN 1 THEN &apos;PASIV&apos; WHEN 2 THEN &apos;BIFUNC&apos; ELSE &apos;ACTIV&apos; END TIPCont, NULL AS NAME,
      C.BALANTASINTETICA, C.NIVEL, C.CODSINTETIC, C.CODPARINTE, C.SIMBSINTETIC, C.DEN_SINTETIC, AN.SIMBOLNOD SIMB_NOD, AN.DENNOD DEN_NOD,
      B.RULAJPD, B.RULAJPC, B.RULAJCD, B.RULAJCC
    FROM C
      INNER JOIN B ON B.CODCONT = C.CODCONT
      LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = B.CODANALIZANOD
    ORDER BY C.CLASA, C.SIMBSINTETIC, C.CODCONT
  ) LOOP
    IF v_rec.codsintetic &lt;&gt; prev_codsint THEN
       IF p_IDX_SINTETIC &gt; 0 THEN
         Insert_RecTotal(tmpName);
       END IF;
       p_IDX_SINTETIC := p_IDX_SINTETIC + 1;
       prev_codsint := v_rec.codsintetic;
    END IF;

    Fill_RecTotals(v_rec);
    Insert_Rec(v_rec,tmpName);
  END LOOP;
  Insert_RecTotal(tmpName);

  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,      &apos;CP&apos;, &apos;CP.CODCONT       = T.CODCONT&apos;,       1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;, &apos;AN&apos;, &apos;AN.CODANALIZANOD = T.CODANALIZANOD&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF aLISTID &gt;= 60000 THEN 
    p_ClasaC := 4;
    p_ClasaV := 5;
  ELSE 
    p_ClasaC := 6;
    p_ClasaV := 7;
  END IF;
  g_tmpTABLE         := tmpName;
  p_IDX_SINTETIC     := 0;

  PROCESSBALANTA(tmpName);

  IF gUserFields IS NOT NULL THEN
    -- stef - elimin virgula de la inceput fiindca e update
    gUserFields := SubStr(gUserFields,2);
    gUserAlias  := SubStr(gUserAlias ,2);
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; lst_tmp SET (&apos;||gUserFields||&apos;) = (SELECT &apos;||gUserAlias||&apos; FROM &apos;||tmpName||&apos; t &apos;||gSuplJoins||&apos; WHERE t.rowid = lst_tmp.rowid)&apos;;
    COMMIT;
  END IF;
END;


END PKG_LIST_BASE_EXPERTBAL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E48992C67383F3E3C5D4AB1F7D33E6C64A435D2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERTBUGET IS

  gNivelMax   NUMBER(10);
  gCodAnaliza NUMBER(20);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GETCODANALIZA RETURN NUMBER IS
BEGIN
  RETURN gCodAnaliza;
END;

PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER) IS
BEGIN
  gCodAnaliza := ACODANALIZA;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  k INTEGER := 0;
BEGIN
  DELETE FROM TMP_DINAMIC_COLS;

  INSERT INTO TMP_DINAMIC_COLS(
    FieldName,
    Display, IndexLocal, FType, FSize, Cod)
  SELECT
    &apos;D&apos;||Row_Number() OVER (ORDER BY A1.INDEXLOCAL, D.CODDESCRIPTOR),
    D.DEN_DESCRIPTOR, A1.INDEXLOCAL, 2, 200, D.CODDESCRIPTOR
  FROM ANALIZA1 A1 INNER JOIN DESCRIPTORI D ON A1.CODDESCRIPTOR = D.CODDESCRIPTOR
  WHERE A1.CODANALIZA = pkg_list_base_expertbuget.GETCODANALIZA
  ORDER BY A1.INDEXLOCAL;


  FOR j IN PKG_LIST_SELECTLUNA.LunaStart..PKG_LIST_SELECTLUNA.LunaFin LOOP
    k := k + 1;
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VR&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Realizata - &apos;||pkg_list_base_utils.decode_luna(j), j, 0, 0);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VB&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Bugetata - &apos; ||pkg_list_base_utils.decode_luna(j), j, 0, 0);
  END LOOP;

  SELECT Coalesce(Max(LEVEL),0)-1 INTO gNivelMax
  FROM ANALIZANOD
  CONNECT BY PRIOR CODANALIZANOD = NODPARINTE
  START WITH COALESCE(NODPARINTE,0) = 0 AND CODANALIZA = Coalesce(gCodAnaliza,0);

  FOR j IN 1..Coalesce(gNivelMax,0) LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;NS&apos;||To_Char(j,&apos;fm999&apos;), &apos;Simbol nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;ND&apos;||To_Char(j,&apos;fm999&apos;), &apos;Descr. nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
  END LOOP;

  COMMIT;
END;

FUNCTION GET_VALOARE(S in varchar2 ,I in number) RETURN VARCHAR2 IS
  finish number(3);
  stop   number(20) := 0;
  coddescript1 varchar2(20);
  RES VARCHAR2(200);
  str varchar2(200);
BEGIN
  STR := trim(S);
  str := substr(str,4,length(str));
  WHILE stop &lt;&gt; i LOOP
  finish :=instr(str,&apos;,&apos;);
  coddescript1  := substr(str,1,finish-1);
  str  := substr(str,finish+1,length(str));
  stop := stop + 1;
  END LOOP;
  if to_number(coddescript1) &gt; 0 then
    BEGIN
      SELECT VALOARE INTO RES FROM DESCRIPTORI1 WHERE CODDESCRIPTOR1 = TO_NUMBER(CODDESCRIPT1);
    EXCEPTION WHEN OTHERS THEN
      RES := &apos;?&apos;;
    END;
  ELSE
    RES := &apos;?&apos;;
  END IF;

  RETURN COALESCE(RES,&apos;?&apos;);
END;

PROCEDURE POPULEAZA_COL_DINAMICE(tmpname in varchar2) IS
  sUpdate VARCHAR2(4000);
  idx     NUMBER(3);
BEGIN
  FOR V_REC IN (
    SELECT X.CODANALIZANOD,x.coddescriptor, SYS_CONNECT_BY_PATH(COALESCE(X.CODDESCRIPTOR1,0),&apos;,&apos;)||&apos;,&apos; caleax
    FROM  (
      SELECT AN.CODANALIZANOD,AN.NODPARINTE,D1.VALOARE,AN.CODANALIZA,D1.CODDESCRIPTOR1, D1.CODDESCRIPTOR
      FROM ANALIZANOD AN LEFT JOIN  DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
      WHERE CODANALIZA = pkg_list_base_expertbuget.GETCODANALIZA
    ) X
    START WITH X.NODPARINTE = 0
    CONNECT BY PRIOR X.CODANALIZANOD = X.NODPARINTE
  ) LOOP
    SUPDATE := &apos;UPDATE &apos;||TMPNAME||&apos; SET &apos;;
    idx := 0;
    FOR V_REC_COLS IN (SELECT * FROM TMP_DINAMIC_COLS WHERE FIELDNAME LIKE &apos;D%&apos;) LOOP
      idx := idx+1;
      SUPDATE := SUPDATE||V_REC_COLS.FIELDNAME||&apos; = &apos;&apos;&apos;||Get_valoare(v_rec.caleax,IDX)||&apos;&apos;&apos;,&apos;;
    END LOOP;
    sUpdate := SUBSTR(SUPDATE,1,LENGTH(SUPDATE)-1);
    sUpdate := SUPDATE ||&apos; WHERE CODANALIZANOD = &apos;||V_REC.CODANALIZANOD;
    IF idx &gt; 0 THEN
      EXECUTE IMMEDIATE sUpdate;
    END IF;
  END LOOP;
END;

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sINSERT CLOB;
  sUpdate CLOB;
  sInsDc  CLOB;
  sSelDC  CLOB;
  sWithDC CLOB;
  sSelBa  CLOB;
  sSelX   CLOB;
  k       INTEGER;
  aCurs   NUMBER(20,7)  := PKG_LIST_SELECTLUNA.Curs;
  sCurs   VARCHAR2(100) := To_Char(aCurs,&apos;FM9999999999999D9999999&apos;, &apos;NLS_NUMERIC_CHARACTERS = &apos;&apos;.,&apos;&apos;&apos;);
  sTranfB VARCHAR2(100) := &apos;&apos;;
  sTranfE VARCHAR2(100) := &apos;&apos;;
  vMon    NUMBER(20);
  vBanca  NUMBER(20);
  sJoinE  CLOB;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;EXPERT E, EXPERT1 E1, NCONT NCDEBIT, NCONT NCCREDIT, ELEMENTE EL, JURNAL J, ANALIZANOD AN, DESCRIPTORI1 D1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF    aCurs = -1 THEN
    vMon    := pkg_categconst.GetValConstanta(&apos;MonBugetareAnaliza&apos;, pkg_globals.ANLUCRU, pkg_globals.lunalucru) ;
    vBanca  := pkg_categconst.GetValConstanta(&apos;BancaCursTrezor&apos;   , pkg_globals.ANLUCRU, pkg_globals.lunalucru) ;
    sTranfE := &apos;/PKG_MONEDE.GETCURSMONEDA(&apos;||vMon||&apos;, &apos;||vbanca||&apos;, Coalesce(DINT.DataDoc, DIES.DataDoc, DTRZ.DataDoc))&apos;;
    sJoinE := &apos;
        LEFT JOIN INTRARI DINT ON DINT.CODINTR    = E.CODDOC AND DINT.TIPDOC = E.TIPDOC
        LEFT JOIN IESIRI  DIES ON DIES.CODIES     = E.CODDOC AND DIES.TIPDOC = E.TIPDOC
        --LEFT JOIN TREZOR1 DTRZ ON DTRZ.CODTREZOR1 = E.CODDOC AND E.TIPDOC IN (29, 30, 31, 32) --stef EXPERT tine zic eu eronat CODTREZOR in CODDOC
        LEFT JOIN TREZOR  DTRZ ON DTRZ.CODTREZOR  = E.CODDOC AND E.TIPDOC IN (29, 30, 31, 32)&apos;;
  ELSIF aCurs &lt;&gt; 1 THEN
    --sTranfB := &apos;/&apos;||sCurs;
    sTranfE := &apos;/&apos;||sCurs;
  END IF;

  k := 0;
  FOR j IN PKG_LIST_SELECTLUNA.LunaStart..PKG_LIST_SELECTLUNA.LunaFin LOOP
    k := k + 1;
    sSelBa := sSelBa ||&apos;,
      SUM(CASE WHEN luna = &apos;||To_Char(j,&apos;fm99&apos;)||&apos; THEN buget ELSE 0 END) VB&apos;||To_Char(k,&apos;fm999&apos;);
    sSelX := sSelX ||&apos;,
      ABS(SUM(CASE WHEN luna &lt;&gt; &apos;||To_Char(j,&apos;fm99&apos;)||&apos; THEN 0 WHEN TIPCONT = 0 THEN -VALOARE ELSE VALOARE END)) VR&apos;||To_Char(k,&apos;fm999&apos;);
    sInsDc  := sInsDc ||&apos;, VR&apos;||To_Char(k,&apos;fm999&apos;)||&apos;, VB&apos;||To_Char(k,&apos;fm999&apos;);
    sSelDC  := sSelDC ||&apos;, COALESCE(X.VR&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0), BA.VB&apos;||To_Char(k,&apos;fm999&apos;);
  END LOOP;

  FOR j IN 1..gNivelMax LOOP
    sInsDc  := sInsDc ||&apos;, NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, ND&apos;||To_Char(j,&apos;fm999&apos;);
    sSelDC  := sSelDC ||&apos;, COALESCE(dc.NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;), COALESCE(dc.ND&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;)&apos;;
    sWithDC := sWithDC||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Valoare END) ND&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Simbol  END) NS&apos;||To_Char(j,&apos;fm999&apos;);
  END LOOP;

  -- stef - ca sa evit niste coloane dinamice cu valori NULL -- cazuri exceptionale intalnite
  FOR xRec IN (SELECT Fieldname, IndexLocal FROM TMP_DINAMIC_COLS WHERE SubStr(FieldName,1,1) = &apos;D&apos;)
  LOOP
    sInsDc  := sInsDc ||&apos;, &apos;||xRec.Fieldname;
    sSelDC  := sSelDC ||&apos;, &apos;&apos;...&apos;&apos;&apos;;
  END LOOP;

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CODANALIZANOD, DEN_ELEMENT,TIPELEMENT, VALDESCRIPT,
    VBT,
    VR0, VB0&apos;||sInsDc||gUserFields||&apos;)
  WITH
  DC AS (
    SELECT Cod&apos;||
      sWithDC||&apos;
    FROM (
      SELECT x.Cod, Y.IDX, y.Simbol, d.valoare Valoare
      FROM (
          SELECT CONNECT_BY_ROOT CodAnalizaNod Cod, CodAnalizaNod, CodDescriptor1, LEVEL IDX
          FROM AnalizaNod
          WHERE NODPARINTE &lt;&gt; 0
          CONNECT BY PRIOR NODPARINTE = CODANALIZANOD
          START WITH CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) x
        LEFT JOIN (
          SELECT CodAnalizaNod, LEVEL-1 IDX, SubStr(sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;),5,30) SIMBOL
          FROM AnalizaNod
          CONNECT BY NODPARINTE = PRIOR CODANALIZANOD
          START WITH NODPARINTE = 0 AND CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) y ON y.codanalizanod = x.codanalizanod
        LEFT JOIN descriptori1 d ON d.coddescriptor1 = x.coddescriptor1
    )
    GROUP BY Cod
  ),
  BA AS (
    SELECT
      codanaliza, codanalizanod, codelement,
      SUM(buget) VBT,
      SUM(CASE WHEN luna &lt;= &apos;||PKG_LIST_SELECTLUNA.LunaFin||&apos; THEN buget ELSE 0 END) VB0&apos;||
      sSelBA||&apos;
    FROM (
      SELECT b.codanaliza, COALESCE(b.codanalizanod,0) codanalizanod, b.codelement, b.luna, b.buget&apos;||sTranfB||&apos; AS BUGET
      FROM bugetanaliza b
      WHERE b.codanaliza = &apos;||gCodAnaliza||&apos; AND b.an = &apos;||pkg_globals.getanlucru||&apos;
      AND Not Exists(SELECT * FROM analizanod a WHERE a.codanaliza = b.codanaliza AND a.nodparinte = b.codanalizanod)
    )
    GROUP BY codanaliza, codanalizanod, codelement),
  X AS (
    SELECT
      CODANALIZA, CODANALIZANOD, CODELEMENT, CODDESCRIPTOR1,
      ABS(SUM(CASE WHEN TIPCONT = 0 THEN -1 ELSE 1 END * VALOARE)) VR0&apos;||
      sSelX||&apos;
    FROM (
      SELECT
        E.CODANALIZA, E1.CODANALIZANOD, E1.CODELEMENT, E1.CODDESCRIPTOR1, E1.TIPCONT, E1.VALOARE&apos;||sTranfE||&apos; AS VALOARE, E.LUNA
      FROM EXPERT E
        INNER JOIN EXPERT1 E1 ON E.CODEXPERT = E1.CODEXPERT
        INNER JOIN NCONT NCDEBIT ON NCDEBIT.CODCONT = E1.CONTD
        INNER JOIN NCONT NCCREDIT ON NCCREDIT.CODCONT = E1.CONTC
        INNER JOIN BUGETANALIZA BA ON BA.CODANALIZA = E.CODANALIZA AND BA.CODANALIZANOD = E1.CODANALIZANOD AND BA.CODELEMENT = E1.CODELEMENT AND BA.AN = E.AN AND BA.LUNA = E.LUNA&apos;||
        sJoinE||&apos;
      WHERE E.CODANALIZA = &apos;||gCodAnaliza||&apos; AND E.AN = &apos;||pkg_globals.getanlucru||&apos; AND E.LUNA &lt;= &apos;||PKG_LIST_SELECTLUNA.LunaFin||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;E1&apos;,&apos;SUBUNITJURN&apos;)||&apos;
    )
    GROUP BY CODANALIZA, CODANALIZANOD, CODELEMENT, CODDESCRIPTOR1
  )
  SELECT
    BA.CODANALIZANOD, EL.DEN_ELEMENT, DECODE(EL.TIP,0,&apos;&apos;Element de cheltuiala&apos;&apos;,1,&apos;&apos;Element de venit&apos;&apos;,2,&apos;&apos;Element bifunctional&apos;&apos;) TIPELEMENT, D1.VALOARE VALDESCRIPT,
    BA.VBT,
    COALESCE(X.VR0,0), BA.VB0&apos;||sSelDC||gUserAlias||&apos;
  FROM BA
    INNER JOIN ELEMENTE EL ON EL.CODELEMENT = BA.CODELEMENT
    LEFT JOIN X ON BA.CODANALIZA = X.CODANALIZA AND BA.CODANALIZANOD = X.CODANALIZANOD AND BA.CODELEMENT = X.CODELEMENT
    LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = BA.CODANALIZANOD
    LEFT JOIN DESCRIPTORI1 D1 ON D1.CODDESCRIPTOR1 = X.CODDESCRIPTOR1
    LEFT JOIN DC ON DC.cod = BA.CODANALIZANOD&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  FOR j IN 2..gNivelMax LOOP
    sUpdate := &apos;
    UPDATE &apos;||tmpName||&apos;
    SET NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos; = NS&apos;||To_Char(j-1,&apos;fm999&apos;)||&apos;||&apos;&apos;.00&apos;&apos;
    WHERE NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos; IS NULL&apos;;

    LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
  END LOOP;
  COMMIT;
  POPULEAZA_COL_DINAMICE(TMPNAME);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_expertbuget;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTCC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5DD73616C397973FFF2E9CD0720CBE3365573B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERTCC IS

  gNivelMax   NUMBER(10);
  gCodAnaliza NUMBER(20);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETCODANALIZA (aCodAnaliza NUMBER) IS
BEGIN
  gCodAnaliza := aCodAnaliza;

  SELECT Coalesce(Max(LEVEL),0)-1 INTO gNivelMax
  FROM ANALIZANOD
  CONNECT BY PRIOR CODANALIZANOD = NODPARINTE
  START WITH COALESCE(NODPARINTE,0) = 0 AND CODANALIZA = gCodAnaliza;

  DELETE FROM TMP_DINAMIC_COLS;
  FOR j IN 1..gNivelMax LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;N&apos;||To_Char(j,&apos;fm999&apos;), &apos;Simbol nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;D&apos;||To_Char(j,&apos;fm999&apos;), &apos;Descr. nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
  END LOOP;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
  sUpdate CLOB;
  sInsDc  CLOB;
  sSelDC  CLOB;
  sWithDC CLOB;
  sTranfC VARCHAR2(100);

  sXJoin  VARCHAR2(400);
  sXCond  VARCHAR2(400);
  sInclCont CLOB  := Coalesce(pkg_categconst.GetValConstanta(&apos;ListBugetCCInclCont&apos;,pkg_globals.getanlucru,pkg_list_selectluna.LunaStart),&apos;-1&apos;);
BEGIN
  gSuplCols := &apos;Jurnal J, ncont contd, ncont contc, centrecost cc, nconts cs, ngest g&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE tmp_manevra&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_manevra SELECT codcont FROM ncont WHERE codcont IN (&apos;||sInclCont||&apos;) UNION SELECT codcont FROM ncont WHERE clasa IN (6, 7)&apos;, aListID, aListVer);

  IF gCodAnaliza = 0 THEN
    sXJoin := &apos;&apos;;
    sXCond := &apos;Coalesce(j.codanalizanod, 0) = 0&apos;;
  ELSE
    sXJoin := &apos;
    INNER JOIN analizanod an ON an.codanalizanod = j.codanalizanod&apos;;
    sXCond := &apos;an.codanaliza = &apos;||gCodAnaliza;
  END IF;

  sTranfC := CASE WHEN PKG_LIST_SELECTLUNAAN.Curs = 1 THEN &apos;&apos; ELSE &apos;/PKG_LIST_SELECTLUNAAN.Curs&apos; END;

  FOR j IN 1..gNivelMax LOOP
    sInsDc  := sInsDc ||&apos;, N&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, D&apos;||To_Char(j,&apos;fm999&apos;);
    sSelDC  := sSelDC ||&apos;, dc.N&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, COALESCE(dc.D&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;)&apos;;
    sWithDC := sWithDC||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Valoare END) D&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Simbol  END) N&apos;||To_Char(j,&apos;fm999&apos;);
  END LOOP;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_TipDoc, Doc, DataDoc,
    SimbCont,
    ValChelt,
    ValVenit,
    ValReal,
    CheltVal,
    VenitVal,
    RealVal,
    An, Luna, LunaX, CentruCost,
    DenCont &apos;||
    sInsDc||gUserFields||&apos;)
  WITH DC AS (
    SELECT
      cod&apos;||
        sWithDC||&apos;
    FROM (
      SELECT x.Cod, Y.IDX, y.Simbol, d.valoare Valoare
      FROM (
          SELECT CONNECT_BY_ROOT CodAnalizaNod Cod, CodAnalizaNod, CodDescriptor1, LEVEL IDX
          FROM AnalizaNod
          WHERE NODPARINTE &lt;&gt; 0
          CONNECT BY PRIOR NODPARINTE = CODANALIZANOD
          START WITH CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) x
        LEFT JOIN (
          SELECT CodAnalizaNod, LEVEL-1 IDX, SubStr(sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;),5,30) SIMBOL
          FROM AnalizaNod
          CONNECT BY NODPARINTE = PRIOR CODANALIZANOD
          START WITH NODPARINTE = 0 AND CODANALIZA = &apos;||gCodAnaliza||&apos;
        ) y ON y.codanalizanod = x.codanalizanod
        LEFT JOIN descriptori1 d ON d.coddescriptor1 = x.coddescriptor1
    )
    GROUP BY Cod
  )
  SELECT
    j.coddoc, j.tipdoc, j.Document, j.DataDoc,
    CASE WHEN contd.clasa in (6, 7) THEN contd.simbol ELSE contc.simbol END,
    CASE WHEN contd.clasa in (6, 7) THEN j.valoare ELSE 0 END&apos;||sTranfC||&apos;,
    CASE WHEN contc.clasa in (6, 7) THEN j.valoare ELSE 0 END&apos;||sTranfC||&apos;,
    CASE WHEN contc.clasa in (6, 7) THEN j.valoare ELSE 0 END - CASE WHEN contd.clasa in (6, 7) THEN j.valoare ELSE 0 END&apos;||sTranfC||&apos;,
    CASE WHEN contd.clasa in (6, 7) THEN j.valoareV ELSE 0 END as cheltval,
    CASE WHEN contc.clasa in (6, 7) THEN j.valoareV ELSE 0 END as venitval,
    CASE WHEN contc.clasa in (6, 7) THEN j.valoareV ELSE 0 END - CASE WHEN contd.clasa in (6, 7) THEN j.valoareV ELSE 0 END as cheltval,
    J.An, J.Luna, pkg_list_base_utils.decode_luna(J.Luna), CC.Denumire,
    CASE WHEN contd.clasa in (6, 7) THEN contd.den_cont ELSE contc.den_cont END&apos;||
    sSelDC||gUserAlias||&apos;
  FROM jurnal j&apos;||
    sXJoin||&apos;
    INNER JOIN ncont       contc ON contc.codcont = j.contc
    INNER JOIN ncont       contd ON contd.codcont = j.contd
    LEFT  JOIN tmp_manevra tcc   ON tcc.codunic   = j.contc
    LEFT  JOIN tmp_manevra tcd   ON tcd.codunic   = j.contd
    LEFT  JOIN ngest       g     ON g.codgest     = j.gest
    LEFT  JOIN centrecost  cc    ON cc.codcentru  = Coalesce(j.codcentru, 0)
    LEFT  JOIN nconts      cs    ON cs.codconts   = pkg_list_base_utils.get_codconts(CASE WHEN contd.clasa in (6, 7) THEN contd.codcont ELSE contc.codcont END, j.an, j.luna)
    LEFT  JOIN             dc    ON dc.cod        = j.CodAnalizaNod&apos;||
    gSuplJoins||&apos;
  WHERE &apos;||sXCond||&apos;
    AND (J.AN*12+J.LUNA BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop||&apos;)
    AND (tcc.codunic IS NOT NULL OR tcd.codunic IS NOT NULL)
    AND (J.TipDoc &lt;&gt; 32 OR (J.TipDoc = 32 AND J.CodDoc = 1)) &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  FOR j IN 2..gNivelMax LOOP
    sUpdate := &apos;
    UPDATE &apos;||tmpName||&apos;
    SET N&apos;||To_Char(j,&apos;fm999&apos;)||&apos; = N&apos;||To_Char(j-1,&apos;fm999&apos;)||&apos;||&apos;&apos;.00&apos;&apos;
    WHERE N&apos;||To_Char(j,&apos;fm999&apos;)||&apos; IS NULL&apos;;

    EXECUTE IMMEDIATE sUpdate;
  END LOOP;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_expertcc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTCCBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36211866A8C2FD231D1FB5F6B9A3B7F30E8783EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERTCCBUGET IS

  gNivelMax   NUMBER(10);
  gCodAnaliza NUMBER(20);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETCODANALIZA (ACODANALIZA NUMBER) IS
BEGIN
  gCodAnaliza := ACODANALIZA;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  k INTEGER := 0;
BEGIN
  DELETE FROM TMP_DINAMIC_COLS;

  IF NOT pkg_list_selectluna.COLFIX THEN
    FOR j IN pkg_list_selectluna.LunaStart..pkg_list_selectluna.LunaFin LOOP
      k := k + 1;
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VC&apos;||To_Char(k,&apos;fm999&apos;), &apos;Cheltuieli - &apos;||pkg_list_base_utils.decode_luna(j), j, 0, 0);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Venituri - &apos;  ||pkg_list_base_utils.decode_luna(j), j, 0, 0);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VR&apos;||To_Char(k,&apos;fm999&apos;), &apos;Realizat - &apos;  ||pkg_list_base_utils.decode_luna(j), j, 0, 0);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;VB&apos;||To_Char(k,&apos;fm999&apos;), &apos;Bugetat - &apos;   ||pkg_list_base_utils.decode_luna(j), j, 0, 0);
    END LOOP;
  END IF;

  SELECT Coalesce(Max(LEVEL),0)-1 INTO gNivelMax
  FROM ANALIZANOD
  CONNECT BY PRIOR CODANALIZANOD = NODPARINTE
  START WITH COALESCE(NODPARINTE,0) = 0 AND CODANALIZA = gCodAnaliza;

  FOR j IN 1..gNivelMax LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;NS&apos;||To_Char(j,&apos;fm999&apos;), &apos;Simbol nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, FType, FSize) VALUES (&apos;ND&apos;||To_Char(j,&apos;fm999&apos;), &apos;Descr. nivel &apos;||To_Char(j,&apos;fm999&apos;), j, 2, 200);
  END LOOP;

  COMMIT;
END;

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sINSERT   CLOB;
  sUpdate   CLOB;
  sInsDc    CLOB;
  sSelDC    CLOB;
  sWithDC   CLOB;
  sSelBa    CLOB;
  sSelX     CLOB;
  k         INTEGER;
  sTranfC   CLOB;

  sBSel     CLOB;
  sXSel     CLOB;
  sXJoin    CLOB;
  sXCond    CLOB;

  sCondCont CLOB  := &apos;&apos;;
  vNrCont   NUMBER;
  sInclCont CLOB  := Coalesce(pkg_categconst.GetValConstanta(&apos;ListBugetCCInclCont&apos;,pkg_globals.getanlucru,pkg_list_selectluna.LunaStart),&apos;-1&apos;);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;ANALIZANOD AN, CENTRECOST CC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;, &apos;DINT&apos;, &apos;DINT.CODINTR = X.CODDOC AND DINT.TIPDOC = X.TIPDOC&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,  &apos;DIES&apos;, &apos;DIES.CODIES  = X.CODDOC AND DIES.TIPDOC = X.TIPDOC&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE tmp_manevra&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_manevra SELECT codcont FROM ncont WHERE codcont IN (&apos;||sInclCont||&apos;) UNION SELECT codcont FROM ncont WHERE clasa IN (6, 7)&apos;, aListID, aListVer);

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);

  IF gCodAnaliza = 0 THEN
    sBSel  := &apos;0 codanalizanod, 0 codanaliza, &apos;;
    sXSel  := &apos;0 codanalizanod, 0 codanaliza, &apos;;
    sXJoin := &apos;&apos;;
    sXCond := &apos;1=1&apos;;--&apos;Coalesce(j.codanalizanod, 0) = 0&apos;;
  ELSE
    sBSel  := &apos;COALESCE(b.codanalizanod,0) codanalizanod, b.codanaliza, &apos;;
    sXSel  := &apos;an.codanalizanod, an.codanaliza, &apos;;
    sXJoin := &apos;
        INNER JOIN analizanod an ON an.codanalizanod = j.codanalizanod&apos;;
        --INNER JOIN bugetanaliza ba ON ba.codanaliza = an.codanaliza AND ba.codanalizanod = an.codanalizanod AND ba.codcentru = j.codcentru AND ba.an = j.an AND ba.luna = j.luna&apos;;
    sXCond := &apos;an.codanaliza = &apos;||gCodAnaliza;
  END IF;

  IF pkg_list_selectluna.Extra1 THEN
    sXSel  := sXSel||&apos;j.coddoc, j.tipdoc, j.datadoc, j.document, &apos;;
  ELSE
    sXSel  := sXSel||&apos;0 coddoc, 0 tipdoc, NULL datadoc, NULL document, &apos;;
  END IF;

  sTranfC := CASE WHEN not pkg_list_selectluna.isValuta THEN &apos;&apos; ELSE &apos;/PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonBugetareAnaliza&apos;&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), pkg_categconst.GetValConstanta(&apos;&apos;BancaCursTrezor&apos;&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), J.DataDoc)&apos; END;

  IF pkg_list_selectluna.COLFIX THEN
    FOR j IN 1..12 LOOP
      sSelBa := sSelBa ||&apos;,
        SUM(CASE WHEN luna = &apos;||To_Char(j,&apos;fm99&apos;)||&apos; THEN buget ELSE 0 END) VB&apos;||To_Char(j,&apos;fm999&apos;);
      sSelX := sSelX ||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_d = 1 THEN valoare ELSE 0 END) VC&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_c = 1 THEN valoare ELSE 0 END) VV&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_c = 1 THEN valoare ELSE 0 END - CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_d = 1 THEN valoare ELSE 0 END) VR&apos;||To_Char(j,&apos;fm999&apos;);

      sInsDc  := sInsDc ||&apos;, VC&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, VV&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, VR&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, VB&apos;||To_Char(j,&apos;fm999&apos;);
      sSelDC  := sSelDC ||&apos;, COALESCE(X.VC&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,0), COALESCE(X.VV&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,0), COALESCE(X.VR&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,0), BA.VB&apos;||To_Char(j,&apos;fm999&apos;);
    END LOOP;
  ELSE
    k := 0;
    FOR j IN pkg_list_selectluna.LunaStart..pkg_list_selectluna.LunaFin LOOP
      k := k + 1;
      sSelBa := sSelBa ||&apos;,
        SUM(CASE WHEN luna = &apos;||To_Char(j,&apos;fm99&apos;)||&apos; THEN buget ELSE 0 END) VB&apos;||To_Char(k,&apos;fm999&apos;);
      sSelX := sSelX ||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_d = 1 THEN valoare ELSE 0 END) VC&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_c = 1 THEN valoare ELSE 0 END) VV&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,
        SUM(CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_c = 1 THEN valoare ELSE 0 END - CASE WHEN LUNA =&apos;||To_Char(j,&apos;fm99&apos;)||&apos; AND is_d = 1 THEN valoare ELSE 0 END) VR&apos;||To_Char(k,&apos;fm999&apos;);

      sInsDc  := sInsDc ||&apos;, VC&apos;||To_Char(k,&apos;fm999&apos;)||&apos;, VV&apos;||To_Char(k,&apos;fm999&apos;)||&apos;, VR&apos;||To_Char(k,&apos;fm999&apos;)||&apos;, VB&apos;||To_Char(k,&apos;fm999&apos;);
      sSelDC  := sSelDC ||&apos;, COALESCE(X.VC&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0), COALESCE(X.VV&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0), COALESCE(X.VR&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0), BA.VB&apos;||To_Char(k,&apos;fm999&apos;);
    END LOOP;
  END IF;

  FOR j IN 1..gNivelMax LOOP
    sInsDc  := sInsDc ||&apos;, NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos;, ND&apos;||To_Char(j,&apos;fm999&apos;);
    sSelDC  := sSelDC ||&apos;, COALESCE(dc.NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;), COALESCE(dc.ND&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,&apos;&apos;.&apos;&apos;)&apos;;
    sWithDC := sWithDC||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Valoare END) ND&apos;||To_Char(j,&apos;fm999&apos;)||&apos;,
      Max (CASE WHEN IDX = &apos;||To_Char(j,&apos;fm999&apos;)||&apos; THEN Simbol  END) NS&apos;||To_Char(j,&apos;fm999&apos;);
  END LOOP;

  DELETE TMP_LST_DOC_CONT;
  sInsert := &apos;INSERT INTO TMP_LST_DOC_CONT(CODDOC, TIPDOC, CODCONT)
  SELECT j.coddoc, j.tipdoc, ioa.cheltuieli
  FROM jurnal j
    inner join iesiri i on i.codies = j.coddoc and i.tipdoc = j.tipdoc
    inner join livr l on l.codies = i.codies
    inner join iesiri1 i1 on i.codies = i1.codies
    inner join livr1 l1 on l.codlivr = l1.codlivr and l1.codies1 = i1.codies1
    left join nirstoc ns on l1.codnirstoc = ns.codnirstoc
    left join livrval lv on lv.codlivr1 = l1.codlivr1
    left join IOART1 ioa on ioa.codioart = coalesce(ns.codioart,lv.codioart) and i.an*12+i.luna between ioa.alstart and ioa.alstop
  WHERE i.tipdoc in (19,20,21)
    and J.AN = &apos;||pkg_globals.getanlucru||&apos; AND J.LUNA &lt;= &apos;||pkg_list_selectluna.LunaFin||&apos;
    and ioa.cheltuieli &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;);
  EXECUTE IMMEDIATE sInsert;
  COMMIT;

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, Doc, DataDoc,
    CODANALIZANOD, CCOST,
    VC0, VV0, VR0, VB0, SOLD_COL, ORDINE&apos;||sInsDc||gUserFields||&apos;)
  WITH /*RECURSIVE*/ 
  A(Cod, NodParinte, CodAnalizaNod, CodDescriptor1, Idx) AS (
		SELECT CODANALIZANOD COD, NODPARINTE, CODANALIZANOD, CodDescriptor1, 1 IDX
		FROM ANALIZANOD
		WHERE CODANALIZA = &apos;||gCodAnaliza||&apos; AND NODPARINTE &lt;&gt; 0
		UNION ALL
		SELECT A.COD, O.NODPARINTE, O.CODANALIZANOD, O.CodDescriptor1, A.IDX + 1 AS IDX
		FROM ANALIZANOD O INNER JOIN A ON A.NODPARINTE = O.CODANALIZANOD
    WHERE O.NODPARINTE &lt;&gt; 0
	),
  B(CodAnalizaNod, NodParinte, Simbol, Idx) AS (
    SELECT CodAnalizaNod, nodparinte,  &apos;&apos;&apos;&apos; simbol, 0 IDX
		FROM AnalizaNod
		WHERE Coalesce(nodparinte,0)=0 AND CODANALIZA = &apos;||gCodAnaliza||&apos;
		UNION ALL
		SELECT n.CodAnalizaNod, n.nodparinte, CASE WHEN b.idx &gt; 0 THEN b.SIMBOL||&apos;&apos;.&apos;&apos; ELSE &apos;&apos;&apos;&apos; END||LPAD(N.POZITIE, 2, &apos;&apos;0&apos;&apos;), b.IDX+1 IDX
		FROM AnalizaNod n INNER JOIN b ON b.CodAnalizaNod = n.nodparinte
  ),
  DC AS (
    SELECT Cod&apos;||sWithDC||&apos;
    FROM (
      SELECT a.Cod, b.Idx, b.Simbol, d.valoare
      FROM a
        LEFT JOIN b ON b.codanalizanod = a.codanalizanod
        LEFT JOIN descriptori1 d ON d.coddescriptor1 = a.coddescriptor1
    ) SUBS
    GROUP BY Cod
  ),
  BA AS (
    SELECT
      codanalizanod, codanaliza, codcentru,
      SUM(buget) VB0&apos;||
      sSelBA||&apos;
    FROM (
      SELECT &apos;||sBSel||&apos;b.codcentru, b.buget as buget, b.luna
      FROM bugetanaliza b
      WHERE b.codanaliza = &apos;||gCodAnaliza||&apos; AND b.an = &apos;||pkg_globals.getanlucru||&apos; AND b.luna &lt;= &apos;||pkg_list_selectluna.LunaFin||&apos;
        AND Not Exists(SELECT 1 FROM analizanod a WHERE a.codanaliza = b.codanaliza AND a.nodparinte = b.codanalizanod)
        AND (PKG_LIST_SELECTLUNA.extra2numeric &gt; 0 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;&apos;CODCENTRU&apos;&apos; AND TMP.VALOARE = B.CODCENTRU))
      UNION ALL
      SELECT 0 codanalizanod, 0 codanaliza,CC.codcentru, 0 as buget, &apos;||pkg_list_selectluna.LunaFin||&apos; luna
      FROM CENTRECOST CC
      WHERE CC.CODCENTRU &gt; 0
        AND NOT EXISTS (
          SELECT B.CODCENTRU
          FROM BUGETANALIZA B
          WHERE B.CODCENTRU = CC.CODCENTRU
            AND b.codanaliza = &apos;||gCodAnaliza||&apos;
            AND b.an = &apos;||pkg_globals.getanlucru||&apos; AND b.luna &lt;= &apos;||pkg_list_selectluna.LunaFin||&apos;
        )
        AND (PKG_LIST_SELECTLUNA.extra2numeric &gt; 0 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;&apos;CODCENTRU&apos;&apos; AND TMP.VALOARE = CC.CODCENTRU))
    ) SUBS
    GROUP BY codanaliza, codanalizanod, codcentru
  ),
  X AS (
    SELECT
      coddoc, tipdoc, document, datadoc,
      codanalizanod, codanaliza, codcentru,
      Sum(CASE WHEN is_d = 1 THEN valoare ELSE 0 END) VC0,
      Sum(CASE WHEN is_c = 1 THEN valoare ELSE 0 END) VV0,
      Sum(CASE WHEN is_c = 1 THEN valoare ELSE 0 END - CASE WHEN is_d = 1 THEN valoare ELSE 0 END) VR0&apos;||
      sSelX||&apos;
    FROM (
      SELECT
        &apos;||sXSel||&apos;j.codcentru, CASE WHEN contd.codunic IS NULL THEN 0 ELSE 1 END as is_d,
        CASE WHEN contc.codunic IS NULL THEN 0 ELSE 1 END as is_c,  j.valoare&apos;||sTranfC||&apos; as valoare, j.luna
      FROM jurnal j&apos;||
        sXJoin||&apos;
        LEFT JOIN tmp_manevra contc ON j.contc = contc.codunic
        LEFT JOIN tmp_manevra contd ON j.contd = contd.codunic
      WHERE &apos;||sXCond||&apos;
        AND J.AN = &apos;||pkg_globals.getanlucru||&apos; AND J.LUNA &lt;= &apos;||pkg_list_selectluna.LunaFin||&apos;
        AND (contd.codunic IS NOT NULL OR contc.codunic IS NOT NULL)
        AND (J.TipDoc &lt;&gt; 32 OR (J.TipDoc = 32 AND J.CodDoc = 1)) &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;);
  if pkg_list_selectluna.Extra3Numeric &gt; 0 then
    sInsert := sInsert||&apos;AND NOT EXISTS (SELECT TMP.CODDOC FROM TMP_LST_DOC_CONT TMP
                          WHERE TMP.CODDOC = J.CODDOC AND TMP.TIPDOC = J.TIPDOC
                                AND J.CONTD = TMP.CODCONT)&apos;;
  end if;
  sInsert := sInsert||&apos;
    ) SUBS
    GROUP BY codanalizanod, codanaliza, codcentru, coddoc, tipdoc, datadoc, document
  )
  SELECT
    X.CODDOC, X.TIPDOC, X.DOCUMENT, X.DATADOC,
    BA.CODANALIZANOD, CC.Denumire,
    COALESCE(X.VC0,0), COALESCE(X.VV0,0), COALESCE(X.VR0,0), BA.VB0, COALESCE(X.VV0,0) - COALESCE(X.VC0,0), 1&apos;||sSelDC||gUserAlias||&apos;
  FROM BA
    LEFT JOIN X ON BA.CODANALIZA = X.CODANALIZA AND BA.CODANALIZANOD = X.CODANALIZANOD AND BA.CODCENTRU = X.CODCENTRU
    LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = BA.CODANALIZANOD
    LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = BA.CODCENTRU
    LEFT JOIN DC ON DC.cod = BA.CODANALIZANOD&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, Doc, DataDoc,
    CODANALIZANOD, CCOST,SOLD_COL,ORDINE&apos;||gUserFields||&apos;)
  WITH
  BA AS (
    SELECT
      codanalizanod, codanaliza, codcentru,
      SUM(buget) VB0&apos;||
      sSelBA||&apos;
    FROM (
      SELECT &apos;||sBSel||&apos;b.codcentru, b.buget as buget, b.luna
      FROM bugetanaliza b
      WHERE b.codanaliza = &apos;||gCodAnaliza||&apos; AND b.an = &apos;||pkg_globals.getanlucru||&apos; AND b.luna &lt;= &apos;||pkg_list_selectluna.LunaFin||&apos;
        AND Not Exists(SELECT 1 FROM analizanod a WHERE a.codanaliza = b.codanaliza AND a.nodparinte = b.codanalizanod)
        AND (PKG_LIST_SELECTLUNA.extra2numeric &gt; 0 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;&apos;CODCENTRU&apos;&apos; AND TMP.VALOARE = B.CODCENTRU))
    ) GROUP BY codanaliza, codanalizanod, codcentru),
  X AS (
    SELECT
      0 coddoc, 0 tipdoc, &apos;&apos; &apos;&apos; document, null as datadoc,
      0 codanalizanod, 0 codanaliza, 0 codcentru,
      0 VC0,
      0 VV0,
      0 VR0
    FROM dual
  )
  SELECT
    0, 0, CASE WHEN BA.VB0 = 0 THEN &apos;&apos;NEBUGETAT&apos;&apos; ELSE &apos;&apos;Sold initial&apos;&apos; END, null DATADOC,
    BA.CODANALIZANOD, CC.Denumire,
    BA.VB0,0&apos;||gUserAlias||&apos;
  FROM BA
    LEFT JOIN X ON BA.CODANALIZA = X.CODANALIZA AND BA.CODANALIZANOD = X.CODANALIZANOD AND BA.CODCENTRU = X.CODCENTRU
    LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = BA.CODANALIZANOD
    LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = BA.CODCENTRU&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  FOR j IN 2..gNivelMax LOOP
    sUpdate := &apos;
    UPDATE &apos;||tmpName||&apos;
    SET NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos; = NS&apos;||To_Char(j-1,&apos;fm999&apos;)||&apos;||&apos;&apos;.00&apos;&apos;
    WHERE NS&apos;||To_Char(j,&apos;fm999&apos;)||&apos; IS NULL&apos;;

    LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
  END LOOP;

  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_expertccbuget;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_EXPERTEXECB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A77611EFB43682A3FEEA063A22BD2E89E01348E2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_EXPERTEXECB IS

  gCodAnaliza NUMBER(20);
  gAn         NUMBER(4);
  gLuna       NUMBER(2);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS (pCodAnaliza NUMBER, pAn NUMBER, pLuna NUMBER, v_CodJob1 IN NUMBER  DEFAULT 0 )
IS
BEGIN
  gCodAnaliza := pCodAnaliza;
  gAn         := pAn;
  gLuna       := pLuna;
  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    gAn   := pkg_globals.GetANLUCRU;
    gLuna := 12;
  END IF;
END;

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sINSERT CLOB;
BEGIN
  gSuplCols := &apos;ANALIZANOD AN&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CODANALIZANOD, SIMBOLNOD, DENNOD,
    E00T1, E00T2, E00T3, E00T4, E00,
    E01T1, E01T2, E01T3, E01T4, E01,
    E02T1, E02T2, E02T3, E02T4, E02,
    E03T1, E03T2, E03T3, E03T4, E03,
    E04T1, E04T2, E04T3, E04T4, E04,
    E05T1, E05T2, E05T3, E05T4, E05,
    E06T1, E06T2, E06T3, E06T4, E06,
    E07T1, E07T2, E07T3, E07T4, E07,
    E08T1, E08T2, E08T3, E08T4, E08,
    E09T1, E09T2, E09T3, E09T4, E09,
    E10T1, E10T2, E10T3, E10T4, E10 &apos;||gUserFields||&apos;)
  WITH TMP AS (
    SELECT
      CODANALIZANOD,
      Sum(CASE CODCENTRU WHEN  0 THEN B1+B2+B3 ELSE 0 END) E00T1, Sum(CASE CODCENTRU WHEN  0 THEN B4+B5+B6 ELSE 0 END) E00T2, Sum(CASE CODCENTRU WHEN  0 THEN B7+B8+B9 ELSE 0 END) E00T3, Sum(CASE CODCENTRU WHEN  0 THEN B10+B11+B12 ELSE 0 END) E00T4,
      Sum(CASE CODCENTRU WHEN  1 THEN B1+B2+B3 ELSE 0 END) E01T1, Sum(CASE CODCENTRU WHEN  1 THEN B4+B5+B6 ELSE 0 END) E01T2, Sum(CASE CODCENTRU WHEN  1 THEN B7+B8+B9 ELSE 0 END) E01T3, Sum(CASE CODCENTRU WHEN  1 THEN B10+B11+B12 ELSE 0 END) E01T4,
      Sum(CASE CODCENTRU WHEN  2 THEN B1+B2+B3 ELSE 0 END) E02T1, Sum(CASE CODCENTRU WHEN  2 THEN B4+B5+B6 ELSE 0 END) E02T2, Sum(CASE CODCENTRU WHEN  2 THEN B7+B8+B9 ELSE 0 END) E02T3, Sum(CASE CODCENTRU WHEN  2 THEN B10+B11+B12 ELSE 0 END) E02T4,
      Sum(CASE CODCENTRU WHEN  3 THEN B1+B2+B3 ELSE 0 END) E03T1, Sum(CASE CODCENTRU WHEN  3 THEN B4+B5+B6 ELSE 0 END) E03T2, Sum(CASE CODCENTRU WHEN  3 THEN B7+B8+B9 ELSE 0 END) E03T3, Sum(CASE CODCENTRU WHEN  3 THEN B10+B11+B12 ELSE 0 END) E03T4,
      Sum(CASE CODCENTRU WHEN  4 THEN B1+B2+B3 ELSE 0 END) E04T1, Sum(CASE CODCENTRU WHEN  4 THEN B4+B5+B6 ELSE 0 END) E04T2, Sum(CASE CODCENTRU WHEN  4 THEN B7+B8+B9 ELSE 0 END) E04T3, Sum(CASE CODCENTRU WHEN  4 THEN B10+B11+B12 ELSE 0 END) E04T4,
      Sum(CASE CODCENTRU WHEN  5 THEN B1+B2+B3 ELSE 0 END) E05T1, Sum(CASE CODCENTRU WHEN  5 THEN B4+B5+B6 ELSE 0 END) E05T2, Sum(CASE CODCENTRU WHEN  5 THEN B7+B8+B9 ELSE 0 END) E05T3, Sum(CASE CODCENTRU WHEN  5 THEN B10+B11+B12 ELSE 0 END) E05T4,
      Sum(CASE CODCENTRU WHEN  6 THEN B1+B2+B3 ELSE 0 END) E06T1, Sum(CASE CODCENTRU WHEN  6 THEN B4+B5+B6 ELSE 0 END) E06T2, Sum(CASE CODCENTRU WHEN  6 THEN B7+B8+B9 ELSE 0 END) E06T3, Sum(CASE CODCENTRU WHEN  6 THEN B10+B11+B12 ELSE 0 END) E06T4,
      Sum(CASE CODCENTRU WHEN  7 THEN B1+B2+B3 ELSE 0 END) E07T1, Sum(CASE CODCENTRU WHEN  7 THEN B4+B5+B6 ELSE 0 END) E07T2, Sum(CASE CODCENTRU WHEN  7 THEN B7+B8+B9 ELSE 0 END) E07T3, Sum(CASE CODCENTRU WHEN  7 THEN B10+B11+B12 ELSE 0 END) E07T4,
      Sum(CASE CODCENTRU WHEN  8 THEN B1+B2+B3 ELSE 0 END) E08T1, Sum(CASE CODCENTRU WHEN  8 THEN B4+B5+B6 ELSE 0 END) E08T2, Sum(CASE CODCENTRU WHEN  8 THEN B7+B8+B9 ELSE 0 END) E08T3, Sum(CASE CODCENTRU WHEN  8 THEN B10+B11+B12 ELSE 0 END) E08T4,
      Sum(CASE CODCENTRU WHEN  9 THEN B1+B2+B3 ELSE 0 END) E09T1, Sum(CASE CODCENTRU WHEN  9 THEN B4+B5+B6 ELSE 0 END) E09T2, Sum(CASE CODCENTRU WHEN  9 THEN B7+B8+B9 ELSE 0 END) E09T3, Sum(CASE CODCENTRU WHEN  9 THEN B10+B11+B12 ELSE 0 END) E09T4,
      Sum(CASE CODCENTRU WHEN 10 THEN B1+B2+B3 ELSE 0 END) E10T1, Sum(CASE CODCENTRU WHEN 10 THEN B4+B5+B6 ELSE 0 END) E10T2, Sum(CASE CODCENTRU WHEN 10 THEN B7+B8+B9 ELSE 0 END) E10T3, Sum(CASE CODCENTRU WHEN 10 THEN B10+B11+B12 ELSE 0 END) E10T4
    FROM  TMP_BUGETANALIZA
    GROUP BY CODANALIZANOD
  )
  SELECT
    TMP.CODANALIZANOD, AN.SIMBOLNOD, AN.DENNOD,
    TMP.E00T1, TMP.E00T2, TMP.E00T3, TMP.E00T4, TMP.E00T1+TMP.E00T2+TMP.E00T3+TMP.E00T4 E00,
    TMP.E01T1, TMP.E01T2, TMP.E01T3, TMP.E01T4, TMP.E01T1+TMP.E01T2+TMP.E01T3+TMP.E01T4 E01,
    TMP.E02T1, TMP.E02T2, TMP.E02T3, TMP.E02T4, TMP.E02T1+TMP.E02T2+TMP.E02T3+TMP.E02T4 E02,
    TMP.E03T1, TMP.E03T2, TMP.E03T3, TMP.E03T4, TMP.E03T1+TMP.E03T2+TMP.E03T3+TMP.E03T4 E03,
    TMP.E04T1, TMP.E04T2, TMP.E04T3, TMP.E04T4, TMP.E04T1+TMP.E04T2+TMP.E04T3+TMP.E04T4 E04,
    TMP.E05T1, TMP.E05T2, TMP.E05T3, TMP.E05T4, TMP.E05T1+TMP.E05T2+TMP.E05T3+TMP.E05T4 E05,
    TMP.E06T1, TMP.E06T2, TMP.E06T3, TMP.E06T4, TMP.E06T1+TMP.E06T2+TMP.E06T3+TMP.E06T4 E06,
    TMP.E07T1, TMP.E07T2, TMP.E07T3, TMP.E07T4, TMP.E07T1+TMP.E07T2+TMP.E07T3+TMP.E07T4 E07,
    TMP.E08T1, TMP.E08T2, TMP.E08T3, TMP.E08T4, TMP.E08T1+TMP.E08T2+TMP.E08T3+TMP.E08T4 E08,
    TMP.E09T1, TMP.E09T2, TMP.E09T3, TMP.E09T4, TMP.E09T1+TMP.E09T2+TMP.E09T3+TMP.E09T4 E09,
    TMP.E10T1, TMP.E10T2, TMP.E10T3, TMP.E10T4, TMP.E10T1+TMP.E10T2+TMP.E10T3+TMP.E10T4 E10 &apos;||gUserAlias||&apos;  FROM TMP
    LEFT JOIN ANALIZANOD AN ON AN.CODANALIZANOD = TMP.codanalizanod &apos;||
    gSuplJoins;

  --PKG_GLOBALS.SetDebugMode(TRUE);

  LIST_EXECUTE_IMMEDIATE(
    &apos;BEGIN&apos;||Chr(10)||
    &apos;  DELETE TMP_BUGETANALIZA;&apos;||Chr(10)||
    &apos;  PKG_ANALIZA.GetBugete( &apos;||gCodAnaliza||&apos;, &apos;||gAn||&apos;, 1, &apos;||gLuna||&apos;, 9, 0 );&apos;||Chr(10)||
    &apos;  DELETE TMP_BUGETANALIZA WHERE CODANALIZANOD IN (SELECT DISTINCT NODPARINTE FROM ANALIZANOD WHERE CODANALIZA = &apos;||gCodAnaliza||&apos;);&apos;||Chr(10)||
    &apos;  COMMIT;&apos;||Chr(10)||
    &apos;END;&apos;,
    aListID, aListVer
  );
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_EXPERTEXECB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FACTASTEPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20755AF06921AE10D237BDA22A47C9064127A5B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_factastept IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist (tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;INTRARI I, INTRARI1 I1, DOCCARNETE DC, NMONEDE M, NPART P, NSUBUNIT SUB, NARTOBJ O, NUM1 UM, NCONT C&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CODDOC,NAV_TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC,
    DOCUMENT, OBSDOC,
    PARTENER, MONEDA, SUBUNITATE, ARTICOL, UM, CONT,
    CANT, PU, VALLIN, TVALIN, REST, VALREST, TVAREST&apos;||gUserFields||&apos;)
  WITH il AS (
    SELECT il.codliniefactura, Sum(Nvl(il.CANT,0)) CANT
    FROM intrari ae
      INNER JOIN intrari1 ae1 ON ae1.codintr = ae.codintr
      INNER JOIN intrasteptlink il ON il.codintr1 = ae1.codintr1
    WHERE ae.anulat = 0 AND ae.operat = 1 AND ae.tipdoc = 2
      AND (ae.luna + ae.an*12) &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      AND NVL(ae.tipfactura, 0) = 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;ae&apos;)||&apos;
    GROUP BY il.codliniefactura
  )
  SELECT
    I.CODINTR,  I.TIPDOC, I.PREFIXDOC, NVL(I.SERIADOC, DC.SERIE) SERIADOC, I.NRDOC, I.DATADOC,
    I.PREFIXDOC||NVL(I.SERIADOC, DC.SERIE)||I.NRDOC||&apos;&apos;/&apos;&apos;||to_char(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) doc, I.OBS,
    P.DEN_PART, M.SIMBOL, SUB.DEN_SUBUNIT, O.DENUMIRE, UM.DEN_UM1, C.SIMBOL,
    I1.CANT/NVL(UM.PARITATE,1) CANT, I1.PU*NVL(UM.PARITATE,1) PU, I1.PU*I1.CANT VALLIN, I1.TVA,
    (I1.CANT - NVL(IL.CANT,0))/NVL(UM.PARITATE,1) REST, (I1.CANT - NVL(IL.CANT,0))*I1.PU VALREST, (I1.CANT - NVL(IL.CANT,0))*I1.TVA/DECODE(I1.CANT,0,1,I1.CANT) TVAREST&apos;||
    gUserAlias||&apos;
  FROM INTRARI I
    INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
    LEFT JOIN IL ON IL.CODLINIEFACTURA = I1.CODINTR1
    LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
    LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(I.MONEDA,0)
    LEFT JOIN NPART P ON P.CODPART = I.PARTENER
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
    LEFT JOIN NUM1 UM ON UM.CODUM1 = I1.UMSEC
    LEFT JOIN NCONT C ON C.CODCONT = I1.CONTSERV&apos;||
    gSuplJoins||&apos;
  WHERE I.ANULAT = 0 AND I.OPERAT = 1 AND I.TIPDOC = 9
    AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;V&apos;&apos;)
    AND (I.LUNA + I.AN*12) &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND NVL(I.TIPFACTURA, 0) = 9
    AND Abs(I1.CANT) &gt; Abs(Nvl(IL.CANT,0)) &apos;||
    pkg_list_base_utils.cond_subunit(&apos;I&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_FACTASTEPT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FACTIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>815693F576F6A188503F3962EBE75283ED16F220</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FACTIES IS

PROCEDURE PROCESSLIST(tmpName VARCHAR2) IS
  sInsert  VARCHAR2(3000);
BEGIN
  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos;
          (ART, UM, CANT, PRET, PU, VAL,
           PROCADAOS, VALADAOS,
           PROCTVA, VALTVA)
		SELECT nao.denumire, num1.den_um1, i1.cant, i1.pretorig, i1.pu , i1.cant * i1.pu,
           (i1.pu - i1.pretorig)*100/i1.pretorig, i1.pu - i1.pretorig,
           (i1.tva*100/i1.pu), i1.tva
    FROM tmp_iesiri1 i1
         INNER JOIN nartobj nao ON nao.codobiect = i1.codobiect
         INNER JOIN num1 ON num1.codum1 = i1.umsec &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  COMMIT;
END;
end PKG_LIST_BASE_FACTIES; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FACTINTOCMIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7ECBF7FEF9717C0AAE30C73350515D010F600ACC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FACTINTOCMIT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist (tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsertTmp CLOB;
  sUpdateTmp CLOB;
  sInsert    VARCHAR2(10000);
  sUpdate    VARCHAR2(10000);
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  sCursRef   VARCHAR2(100);
  sCodIes1   VARCHAR2(500)  := &apos;i1.codies1&apos;;
  sDenDisc   VARCHAR2(500);
  sAn        VARCHAR2(4);
  sLuna      VARCHAR2(2);
  LastDay    DATE;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=
    &apos;tmp_lst_factintocmit ca, iesiri i, iesiri1 i1, general g, nmonede mon, num1 u1, nartobj nobj, nart na, nclasea nca, npart np, centrecost cc, nsubunit ns, nagenda slivr, nlocalit llivr, &apos;||
    &apos;comanda1 c1, comanda c, comanda ac, npers ag, ngest ng, iopart iop, npart1 np1, iopart ciop, npart1 cp1, criteriidisc cd, nart1 artl, ntva1 tva, tmp_lst_curs cfc&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,    &apos;NAC&apos;,  &apos;NAC.CODOBIECT = NOBJ.CODOBIECT AND NAC.CODPART = I.PARTENER &apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sAn     := TO_CHAR(PKG_GLOBALS.GetANLUCRU,&apos;fm0000&apos;);
  sLuna   := TO_CHAR(PKG_GLOBALS.GetLunaLUCRU,&apos;fm00&apos;);
  LastDay := LAST_DAY(TO_DATE(sAn||sLuna, &apos;YYYYMM&apos;));
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(LASTDAY, &apos;DD.MM.YYYY&apos;));

  IF pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 THEN
    sCodIes1 := &apos;CASE
        WHEN Coalesce(i1.codies1storno,0)  &lt;&gt; 0 THEN i1.codies1storno
        WHEN Coalesce(i1.codliniedocimp,0) &lt;&gt; 0
         AND Coalesce(i1.tipdocimp,0)      = 20
         AND i.custodie                    =  1 THEN i1.codliniedocimp
        ELSE i1.codies1
      END&apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i.datadoc)&apos;;
  ELSE
    sCursRef := &apos;1&apos;;
  END IF;

  sDenDisc := pkg_categconst.GetValConstanta(&apos;DenDiscount&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) ;
  IF Trim(sDenDisc) IS NULL THEN
    sDenDisc := &apos;Discount&apos;;
  ELSE
    sDenDisc := REPLACE(sDenDisc,&apos;&apos;&apos;&apos;,&apos;&apos;&apos;&apos;&apos;&apos;);
  END IF;

  -- stef scos conditia urmatoare din cadrul selectului
  -- problema era ca am gasit caz cu mai multe facturi la acelasi aviz avize din care unul era egal cu cant aviz care nu era luat in considerare
  --AND (i1.cant &lt;&gt; Coalesce(il.cant,0) OR f.an * 12 + f.luna &gt; &apos;||pkg_globals.AnLunaLucru||&apos;)

  DELETE FROM tmp_lst_factintocmit;
  sInsertTmp :=
  &apos;INSERT INTO TMP_LST_FACTINTOCMIT( codies1, cant_aviz, vald_aviz, tva_aviz, cant_fact, vald_fact, tva_fact, val_achiz)
  SELECT codies1, SUM(cant_aviz) cant_aviz, SUM(vald_aviz) vald_aviz, SUM(tva_aviz) tva_aviz, SUM(cant_fact) cant_fact, SUM(vald_fact) vald_fact, SUM(tva_fact) tva_fact, SUM(val_achiz) val_achiz
  FROM (
    SELECT
      i1.codies1,
      i1.cant cant_aviz, Coalesce(i1.restfact,0) vald_aviz, Coalesce(i1.tva,0) tva_aviz,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN il.cant                 ELSE 0 END) cant_fact,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN Coalesce(f1.restfact,0) ELSE 0 END) vald_fact,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN Coalesce(f1.tva,0)      ELSE 0 END) tva_fact,
      CASE
        WHEN i1.tiplinie &lt;&gt; &apos;&apos;=&apos;&apos; THEN 0
        WHEN i.initializari = 1 THEN i1.cant * i1.pucorelat
        ELSE (
          SELECT SUM(l1.cant * DECODE(lv.codlivrval,NULL, ns.pret - ns.adaos, lv.pretachiz))
          FROM livr l
            INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
            LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
            LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
          WHERE l.codies = i1.codies AND l1.codies1 = i1.codies1 )
      END val_achiz
    FROM iesiri i
      LEFT JOIN iesiri1 i1 ON i.codies   = i1.codies
      LEFT JOIN ieslink il ON i1.codies1 = il.codlinieaviz AND Coalesce(il.cant,0) &lt;&gt; 0
      LEFT JOIN iesiri1 f1 ON f1.codies1 = il.codies1
      LEFT JOIN iesiri  f  ON f.codies   = f1.codies
    WHERE i.tipdoc = 20 AND i.anulat = 0 AND i.operat = 1 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
      AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      AND Coalesce(i1.codies1storno,0) = 0
      AND NOT (Coalesce(i1.codliniedocimp,0) &lt;&gt; 0 AND Coalesce(i1.tipdocimp,0) = 20)
      AND i1.cant &lt;&gt; 0
      AND Coalesce(i1.custodieintrare,0) &lt;&gt; 1
      AND Coalesce(i.TipConsumator,0) &lt;&gt; 2
    GROUP BY i1.codies, i1.codies1, i1.tiplinie, i.initializari, i1.cant, i1.pucorelat, i1.restfact, i1.tva
    UNION ALL
    SELECT
      &apos;||sCodIes1||&apos; codies1,
      i1.cant cant_aviz, Coalesce(i1.restfact,0) vald_aviz, Coalesce(i1.tva,0) tva_aviz,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN il.cant                 ELSE 0 END) cant_fact,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN Coalesce(f1.restfact,0) ELSE 0 END) vald_fact,
      SUM(CASE WHEN f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; THEN Coalesce(f1.tva,0)      ELSE 0 END) tva_fact,
      CASE
        WHEN i1.tiplinie &lt;&gt; &apos;&apos;=&apos;&apos; THEN 0
        WHEN i.initializari = 1 THEN i1.cant * i1.pucorelat
        ELSE (
          SELECT SUM(l1.cant * DECODE(lv.codlivrval,NULL, ns.pret - ns.adaos, lv.pretachiz))
          FROM livr l
            INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
            LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
            LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
          WHERE l.codies = i1.codies AND l1.codies1 = i1.codies1
        )
      END val_achiz
    FROM iesiri i
      LEFT JOIN iesiri1 i1 ON i.codies   = i1.codies
      LEFT JOIN ieslink il ON i1.codies1 = il.codlinieaviz AND Coalesce(il.cant,0) &lt;&gt; 0
      LEFT JOIN iesiri1 f1 ON f1.codies1 = il.codies1
      LEFT JOIN iesiri  f  ON f.codies   = f1.codies
    WHERE i.tipdoc = 20 AND i.anulat = 0 AND i.operat = 1 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
      AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      AND (Coalesce(i1.codies1storno,0) &lt;&gt; 0 OR (Coalesce(i1.codliniedocimp,0) &lt;&gt; 0 AND Coalesce(i1.tipdocimp,0) = 20))
      AND Coalesce(i1.custodieintrare,0) &lt;&gt; 1
      AND Coalesce(i.TipConsumator,0) &lt;&gt; 2
    GROUP BY i1.codies, i1.codies1, i1.codies1storno, i1.codliniedocimp, i1.tipdocimp, i1.tiplinie, i.initializari, i1.cant, i1.pucorelat, i1.restfact, i1.tva, i.custodie
  ) subs 
  GROUP BY codies1
  HAVING ( SUM(cant_aviz) &lt;&gt; SUM(cant_fact) AND SUM(cant_aviz) &lt;&gt; 0)&apos;;

  sUpdateTmp :=
  &apos;UPDATE TMP_LST_FACTINTOCMIT X
  SET
    (
        SERII,
        IOArtL,
        ContIOArtL,
        ContCustL
    )
    =
    (
      SELECT
        CASE MAX(Coalesce(ns.tipserie,0))
          WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))
          ELSE vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
        END,
        vc2_nt_to_vc3200(CAST(COLLECT(IO.DEN_IOART) AS vc2_nt)),
        vc2_nt_to_vc3200(CAST(COLLECT(CR.SIMBOL)    AS vc2_nt)),
        vc2_nt_to_vc3200(CAST(COLLECT(CC.SIMBOL)    AS vc2_nt))
      FROM IESIRI1 I1
        INNER JOIN IESIRI  I    ON I.CODIES = I1.CODIES
        INNER JOIN LIVR    L    ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
        INNER JOIN LIVR1   L1   ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
        LEFT  JOIN LIVRVAL LV   ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIRSTOC NS   ON NS.CODNIRSTOC  = L1.CODNIRSTOC
        LEFT  JOIN NIRSER  NSER ON NSER.CODNIRSER = L1.CODNIRSER
        LEFT  JOIN NSERII  S    ON S.CODSERIE   = NSER.CODSERIE
        LEFT  JOIN IOART   IO   ON IO.CODIOART  = Coalesce(lv.codioart,ns.codioart)
        LEFT  JOIN IOART1  IO1  ON IO1.CODIOART = IO.CODIOART AND I.An*12+I.Luna BETWEEN IO1.ALStart AND IO1.ALStop
        LEFT  JOIN NCONT   CR   ON CR.CODCONT = IO1.CONT
        LEFT  JOIN NCONT   CC   ON CC.CODCONT = IO1.CUSTODIE
      WHERE I1.CODIES1 = X.CODIES1
    )&apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CODDOC,NAV_TIPDOC,CODIES1,NRDOC,PREFIXDOC,DATADOC,DOCUMENT,DEN_MONEDA,
    DEN_UM1,
    PU,PACHIZ,CANT_AVIZ,CANT_FACT,
    DIFERENTA,VALOARE,VALCUTVA,ADDIM,
    DENUMIRE,
    DEN_PART,DEN_SUB,CUSTODIE,NRCUST,
    CF_AS, CF_CURS,
    CURS_DOC,CURS_REF,
    SERII, IOArtL, ContIOArtL, ContCustL &apos;||
    gUserFields||&apos;)
  SELECT
    i.codies,i.tipdoc,i1.codies1,i.nrdoc,i.prefixdoc,i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc document, mon.den_moneda,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN &apos;&apos;%&apos;&apos; ELSE u1.den_um1 END DEN_UM1,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN 0 ELSE i1.pu*u1.paritate END PU,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN 0 ELSE ca.val_achiz/ca.cant_aviz*u1.paritate END PACHIZ,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN ca.cant_aviz ELSE ca.cant_aviz/u1.paritate END CANT_AVIZ,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN ca.cant_aviz ELSE ca.cant_fact/u1.paritate END CANT_FACT,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN ca.cant_aviz ELSE (ca.cant_aviz-ca.cant_fact)/u1.paritate END DIFERENTA,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN ca.vald_aviz-ca.vald_fact ELSE i1.pu*(ca.cant_aviz-ca.cant_fact) END VALOARE,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN ca.vald_aviz-ca.vald_fact ELSE i1.pu*(ca.cant_aviz-ca.cant_fact)+Decode(ca.tva_aviz,0,0,ca.tva_aviz-ca.tva_fact) END VALCUTVA,
    Coalesce(i1.addim ,0) addim,
    CASE
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos; client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos;: &apos;&apos; || cd.DENCRITERIU
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare: &apos;&apos; || cd.DENCRITERIU
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe grupul de articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de grup)&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe toate articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de total)&apos;&apos;
      ELSE nobj.denumire
    END DENUMIRE,
    np.den_part, ns.den_subunit,DECODE(i.custodie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) CUSTODIE, ac.nrdoc NRCUST,
    TO_CHAR( i.DataDoc + Coalesce(np.scadentav,0),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Coalesce(cfc.valoare,1) CF_CURS,
    DECODE(Coalesce(GREG.CURS, G.CURS), 0, 1, Coalesce(GREG.CURS, G.CURS)) CURS_DOC, &apos;||sCursRef||&apos; CURS_REF,
    SERII, IOArtL, ContIOArtL, ContCustL &apos;||
    gUserAlias||&apos;
  FROM tmp_lst_factintocmit ca
    INNER JOIN iesiri1                  i1    ON i1.codies1       = ca.codies1
    INNER JOIN iesiri                   i     ON i.codies         = i1.codies
    LEFT JOIN general                   g     ON g.coddoc         = i.codies AND g.tipdoc = i.tipdoc
    LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG  ON GREG.CODGENERAL  = G.CODGENERAL
    LEFT JOIN nmonede                   mon   ON mon.codmoneda    = g.moneda
    LEFT JOIN num1                      u1    ON u1.codum1        = i1.umsec
    LEFT JOIN nartobj                   nobj  ON nobj.codobiect   = i1.codobiect
    LEFT JOIN nart1                     artl  ON artl.codarticol  = nobj.codarticol AND i.an*12+i.luna BETWEEN artl.ALStart and artl.ALStop
    left join ntva1                     tva   on tva.codtva       = artl.codtva     AND i.an*12+i.luna BETWEEN tva.ALStart  and tva.ALStop
    LEFT JOIN npart                     np    on np.codpart       = i.partener
    LEFT JOIN npart1                    np1   on np1.codpart      = i.partener      AND i.an*12+i.luna BETWEEN np1.ALStart  and np1.ALStop
    LEFT JOIN iopart                    iop   ON iop.codiopart    = np1.codiopart
    LEFT JOIN npart1                    cp1   on cp1.codpart      = i.partener AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN cp1.ALStart and cp1.ALStop
    LEFT JOIN iopart                    ciop  ON ciop.codiopart   = cp1.codiopart
    LEFT JOIN nsubunit                  ns    ON ns.codsubunit    = i.subunitatea
    LEFT JOIN centrecost                cc    ON cc.codcentru     = i1.codcentru
    LEFT JOIN criteriidisc              cd    ON cd.codcriteriu   = i1.codcriteriu
    LEFT JOIN nagenda                   slivr ON slivr.codagenda  = i.codlocatie
    LEFT JOIN nlocalit                  llivr ON llivr.codlocalit = slivr.codlocalit
    LEFT JOIN ieslink                   il    ON il.codies1       = i1.codies1 AND il.codliniecomanda IS NOT NULL
    LEFT JOIN comanda1                  c1    ON c1.codcomanda1   = il.codliniecomanda
    LEFT JOIN comanda                   c     ON c.codcomanda     = c1.codcomanda
    LEFT JOIN comanda                   ac    ON ac.codies        = i.codies AND ac.partener = i.partener
    LEFT JOIN npers                     ag    ON ag.codpers       = i.agent
    LEFT JOIN ngest                     ng    on ng.codgest       = i1.gestact
    LEFT JOIN nart                      na    ON na.codarticol    = nobj.codarticol
    LEFT JOIN nclasea                   nca   ON nca.codclasea    = na.clasa
    LEFT JOIN TMP_LST_CURS              cfc   ON cfc.codmoneda    = g.moneda&apos;||
    gSuplJoins||&apos;
  WHERE ca.cant_aviz &lt;&gt; ca.cant_fact AND ca.cant_aviz &lt;&gt; 0 &apos;;

  sUpdate := &apos;UPDATE &apos;||tmpname||&apos; X SET CF_VALOARE = CF_CURS*VALCUTVA&apos;;

  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;
  PRC_AL_CHECK(&apos;IOART1&apos;);
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsertTmp, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdateTmp, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert,    aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate,    aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_factintocmit;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FACTNESOSIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>316D9C0306DB57571091716685B2E3CBF621F9EB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FACTNESOSIT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
	sInsert   VARCHAR2(20000);
  aSitV     NUMBER(1);
  aBancaV   NUMBER(20);
  aMonedaV  NUMBER(20);
  sCursRef  VARCHAR2(100);
  sCodIntr1 VARCHAR2(100)   := &apos;i1.codintr1&apos;;
  sAuxSer   VARCHAR2(100)   := &apos;&apos;;
  sAn       VARCHAR2(4);
  sLuna     VARCHAR2(2);
  sALMin    VARCHAR2(5);
  LastDay   DATE;
  sAuxStoc  VARCHAR2(100) := &apos;&apos;;
  fAuxStoc  VARCHAR2(10) := &apos;&apos;;
  jAuxStoc  VARCHAR2(500) := &apos;&apos;;
  AnLista   number(4);
  LunaLista number(2);
  AnPrec    number(4);
  LunaPrec  number(2);
BEGIN
  gSuplCols := &apos;intrari i, intrari1 i1, nmonede mon, num1 u1, nartobj nobj, npart np, nsubunit ns, centrecost cc, nparttr nptr, npart transp, npers deleg, nparcaut paut, ngest ng, iopart iop, iopart ciop&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sAn     := TO_CHAR(PKG_GLOBALS.GetANLUCRU,&apos;fm0000&apos;);
  sLuna   := TO_CHAR(PKG_GLOBALS.GetLunaLUCRU,&apos;fm00&apos;);
  LastDay := LAST_DAY(TO_DATE(sAn||sLuna, &apos;YYYYMM&apos;));
  SELECT To_Char(Max(AnInitial*12+LunaInitiala)) INTO sALMin FROM FirmaLuni;
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(LASTDAY, &apos;DD.MM.YYYY&apos;));
  if PKG_LIST_SELECTPERIOADA.optiunea1 then
    sAuxStoc := &apos;,STM.Rest&apos;;
    fAuxStoc := &apos;,Stoc&apos;;
    jAuxStoc := &apos;    LEFT JOIN tmp_lst_stocobj STM on STM.CODOBIECT = I1.CODOBIECT &apos;;
    AnLista  := pkg_globals.GetANLUCRU;
    LunaLista := pkg_globals.GetLUNALUCRU;
    pkg_globals.SetLunaTemp(AnLista,LunaLista);
    pkg_globals.Calculeaza_Luna_Precedenta(AnLista,LunaLista,AnPrec,LunaPrec);
    pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);
    --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
    PRC_AL_CHECK(&apos;IOART1&apos;);
    PKG_LIST_SELFISAMAG.setAllParams(lastday,lastday,lastday,1,1,1);
    delete tmp_lst_stocobj;
    sInsert :=
    &apos;INSERT INTO tmp_lst_stocobj(codobiect, rest)
    SELECT ns.codobiect, Sum(COALESCE(VS.REST/NUM1.PARITATE,0))
    FROM v_stoc_luna vs
      INNER JOIN nirstoc  ns        ON ns.codnirstoc = vs.codnirstoc
      INNER JOIN nir      n         ON n.codnir = ns.codnir
      INNER JOIN ngest    ng        ON ng.codgest = n.gest
      LEFT  JOIN NUM1               ON NUM1.CODUM1 = NS.UMSEC
      LEFT  JOIN intrari  intr      ON intr.codintr = n.codintr AND intr.tipdoc = n.tipnir
      LEFT  JOIN dvi1               ON dvi1.coddvi1 = ns.coddvi1
      LEFT  JOIN intrari1 intr1     ON intr1.codintr = intr.codintr AND intr1.codintr1 = Coalesce(dvi1.codintr1,ns.codintr1)
      LEFT  JOIN transf   t         ON t.codtransf = n.codtransf AND t.tipdoc = n.tipnir
      LEFT  JOIN transf1  t1        ON t1.codtransf = n.codtransf AND t1.codtransf1 = ns.codtransf1
      LEFT  JOIN iesiri   ies       ON ies.codies = n.codies AND ies.tipdoc = n.tipnir
      LEFT  JOIN livr     l         ON l.codies = n.codies AND l.codlivr = n.codnir
      LEFT  JOIN livr1    l1        ON l1.codlivr = l.codlivr AND l1.codnirstoc = ns.codnirstoc AND (l1.cant &lt; 0 OR n.tipnir = 15)
      LEFT  JOIN iesiri1  ies1      ON ies1.codies1 = l1.codies1
      LEFT  JOIN nirstoc1 ns1       ON ns1.codnirstoc = NS.CodNirStoc
      LEFT  JOIN nirstoc  nsroot    ON nsroot.codnirstoc = ns1.codnirstocOrig
      LEFT  JOIN nir      nroot     ON nroot.codnir = nsroot.codnir
      LEFT  JOIN intrari  intrroot  ON intrroot.codintr = nroot.codintr AND intr.tipdoc = nroot.tipnir
      LEFT  JOIN dvi1     dvi1root  ON dvi1root.coddvi1 = nsroot.coddvi1
      LEFT  JOIN intrari1 intr1root ON intr1root.codintr = intrroot.codintr AND intr1root.codintr1 = Coalesce(dvi1root.codintr1,nsroot.codintr1)
      LEFT  JOIN ioart1   ioa1      ON ioa1.codioart = ns.codioart AND COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) BETWEEN ioa1.alstart AND ioa1.alstop
    WHERE (VS.REST &lt;&gt; 0 OR VS.RESTUM2 &lt;&gt; 0)
      AND ioa1.mg &lt;&gt; 5
      AND (ies1.codies IS NULL OR ies1.codies = n.codies)
      AND (l.codlivr IS NULL OR l1.codlivr = l.codlivr)&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    GROUP BY NS.CODOBIECT&apos;;
    EXECUTE IMMEDIATE sInsert;
  end if;

  IF pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 THEN
    sCodIntr1 := &apos;i1.codintr1storno&apos;;
    sAuxSer   := &apos;-&apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i.datadoc ) curs_ref &apos;;
  ELSE
    sCursRef := &apos;, 1 curs_ref &apos;;
  END IF;

  -- stef scos conditia urmatoare din cadrul selectului
  -- problema era ca am gasit caz cu mai multe facturi la acelasi aviz avize din care unul era egal cu cant aviz care nu era luat in considerare
  --AND (i1.cant &lt;&gt; nvl(il.cant,0) OR f.an * 12 + f.luna &gt; &apos;||pkg_globals.AnLunaLucru||&apos;)

	sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_TipDoc,NRDOC,PREFIXDOC,DATADOC,DOCUMENT,DEN_MONEDA, DEN_UM1, PU,
    CANT_AVIZ,CANT_FACT,DIFERENTA,VALOARE,VALCUTVA,
    ADDIM,denumire,DEN_PART, DEN_SUB,
    CUSTODIE,
    NETBCAR, TipSerie, Serie,
    CF_AS, CF_CURS,
    curs_doc,curs_ref&apos;||fAuxStoc||gUserFields||&apos;)
  WITH
  ser AS (
    SELECT
      codintr1, Max(tipserie) tipserie,
      CASE Max(tipserie)
        WHEN 1 THEN vc2_nt_to_string(CAST(collect(serie ORDER BY serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_string_sum(CAST(collect(serie||&apos;&apos;(~#&apos;&apos;||cant||&apos;&apos;#~)&apos;&apos; ORDER BY serie) AS vc2_nt))
        ELSE NULL
      END SERII
    FROM (
      SELECT codintr1, serie, Sum(cant) cant, Max(tipserie) tipserie
      FROM (
        SELECT i1.codintr1, nser.cantnir cant, s.serie, Nvl(ns.tipserie,0) tipserie
        FROM intrari i
          INNER JOIN intrari1 i1   ON i.codintr = i1.codintr
          INNER JOIN nirstoc  ns   ON ns.codintr1 = i1.codintr1
          INNER JOIN nir      n    ON n.codnir = ns.codnir AND n.tipnir = i.tipdoc AND n.codintr = i.codintr
          INNER JOIN nirser   nser ON nser.codnirstoc = ns.codnirstoc
          INNER JOIN nserii   s    on s.codserie = nser.codserie
        WHERE i.tipdoc = 2 AND i.anulat = 0 AND i.operat = 1
          AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
          AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
          AND NVL(i1.codintr1storno,0) = 0
        UNION ALL
        SELECT i1.codintr1, -l1.cant cant, s.serie, Nvl(ns.tipserie,0) tipserie
        FROM intrari i
          INNER JOIN intrari1 i1   ON i.codintr = i1.codintr
          INNER JOIN livr1    l1   ON l1.codintr1 = i1.codintr1
          INNER JOIN nirstoc  ns   ON ns.codnirstoc = l1.codnirstoc
          INNER JOIN nirser   nser ON nser.codnirstoc = ns.codnirstoc and l1.codnirser = nser.codnirser
          INNER JOIN nserii   s    on s.codserie = nser.codserie
        WHERE i.tipdoc = 2 AND i.anulat = 0 AND i.operat = 1
          AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
          AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
          AND NVL(i1.codintr1storno,0) = 0
        UNION ALL
        SELECT &apos;||sCodIntr1||&apos; codintr1, &apos;||sAuxSer||&apos;l1.cant, s.serie, Nvl(ns.tipserie,0) tipserie
        FROM intrari i
          INNER JOIN intrari1 i1   ON i.codintr = i1.codintr
          INNER JOIN livr1    l1   ON l1.codintr1 = i1.codintr1
          INNER JOIN nirser   nser ON nser.codnirser = l1.codnirser
          INNER JOIN nserii   s    on s.codserie = nser.codserie
          INNER JOIN nirstoc  ns   ON ns.codnirstoc = nser.codnirstoc
        WHERE i.tipdoc = 2 AND i.anulat = 0 AND i.operat = 1
          AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
          AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
          AND NVL(i1.codintr1storno,0) &lt;&gt; 0
      )
      GROUP BY codintr1, serie
    )
    WHERE cant &lt;&gt; 0
    GROUP BY codintr1),
  crs_avize AS (
    SELECT codintr1, SUM(cant_aviz) cant_aviz, sum(cant_fact) cant_fact, (SELECT SUM(NETKG) FROM BCAR X WHERE x.tipdoc = 2 AND x.coddoc1 = a.codintr1) netBCAR
    FROM (
      SELECT
        i1.codintr1, i1.cant cant_aviz,
        (
          SELECT Nvl(Sum(il.cant),0)
          FROM intrlink il
            INNER JOIN intrari1 f1 ON f1.codintr1 = il.codintr1
            INNER JOIN intrari  f  ON f.codintr = f1.codintr
          WHERE il.codlinieaviz = i1.codintr1 AND Nvl(il.cant,0) &lt;&gt; 0 AND f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        ) +
        (
          SELECT Nvl(Sum(f1.cant),0)
          FROM iesiri1 f1 INNER JOIN iesiri f ON f.codies = f1.codies
          WHERE f1.codliniedocimp = i1.codintr1 AND f1.tipdocimp = i.tipdoc AND Nvl(f1.custodieintrare,0) = 1 AND Nvl(f1.cant,0) &lt;&gt; 0 AND f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        ) cant_fact
      FROM intrari i LEFT JOIN intrari1 i1 ON i.codintr = i1.codintr
      WHERE i.tipdoc = 2 AND i.anulat = 0 AND i.operat = 1
        AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
        AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        AND NVL(i1.codintr1storno,0) = 0
      UNION ALL
      SELECT
        &apos;||sCodIntr1||&apos; codintr1, i1.cant cant_aviz,
        (
          SELECT Nvl(Sum(il.cant),0)
          FROM intrlink il
            INNER JOIN intrari1 f1 ON f1.codintr1 = il.codintr1
            INNER JOIN intrari  f  ON f.codintr = f1.codintr
          WHERE il.codlinieaviz = i1.codintr1 AND Nvl(il.cant,0) &lt;&gt; 0 AND f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        ) +
        (
          SELECT Nvl(Sum(f1.cant),0)
          FROM iesiri1 f1 INNER JOIN iesiri f ON f.codies = f1.codies
          WHERE f1.codliniedocimp = i1.codintr1 AND f1.tipdocimp = i.tipdoc AND Nvl(f1.custodieintrare,0) = 1 AND Nvl(f1.cant,0) &lt;&gt; 0 AND f.anulat = 0 AND f.operat = 1 AND f.an * 12 + f.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        ) cant_fact
      FROM intrari i LEFT JOIN intrari1 i1 ON i.codintr = i1.codintr
      WHERE i.tipdoc = 2 AND i.anulat = 0 AND i.operat = 1
        AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;I&apos;)||&apos;
        AND i.an * 12 + i.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
        AND NVL(i1.codintr1storno,0) &lt;&gt; 0
      UNION ALL
      SELECT
        i1.codintr1, 0 cant_aviz,
        sum(il.cant) cant_fact
      FROM intrari f
        INNER JOIN intrari1 f1 ON f1.codintr = f.codintr
        INNER JOIN intrlink il ON il.codintr1 = f1.codintr1 AND Nvl(il.cant,0) &lt;&gt; 0
        INNER JOIN intrari1 i1 ON i1.codintr1 = il.codlinieaviz
        INNER JOIN intrari  i  ON i.codintr = i1.codintr
      WHERE f.tipdoc IN (5,9) AND f.anulat = 0 AND f.operat = 1
        AND NVL(i.tipfactura,0) &lt;&gt; 9 &apos;||pkg_list_base_utils.cond_subunit(&apos;f&apos;)||&apos;
        AND f.an * 12 + f.luna = &apos;||pkg_globals.AnLunaLucru||&apos;
        AND i.an * 12 + i.luna &gt; &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY i1.codintr1
    ) a
    GROUP BY codintr1)
  SELECT
    i.codintr, i.tipdoc, i.nrdoc, i.prefixdoc, i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc document, mon.den_moneda, u1.den_um1, i1.pu,
    ca.cant_aviz/u1.paritate, ca.cant_fact/u1.paritate, (ca.cant_aviz-ca.cant_fact)/u1.paritate, i1.pu*(ca.cant_aviz-ca.cant_fact),
    (i1.pu + Decode(i1.cant,0,0,COALESCE(i1.tva,0)/i1.cant)) * (ca.cant_aviz - ca.cant_fact),
    nvl(i1.addim ,0) addim, nobj.denumire, np.den_part, ns.den_subunit,
    CASE WHEN nvl(i.custodie,0) = 1 THEN &apos;&apos;DA&apos;&apos; WHEN Nvl(i.tipfactura,0) = 14 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    ca.netBCAR, DECODE(ser.tipserie,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie, ser.serii,
    TO_CHAR( i.DataDoc + Nvl(np.scadentac,0),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Nvl(cfc.valoare,1) CF_CURS,
    DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))&apos;||sCursRef||sAuxStoc||gUserAlias||&apos;
  FROM crs_avize ca
    INNER JOIN intrari1                 i1     ON i1.codintr1 = ca.codintr1
    LEFT JOIN intrari                   i      ON i.codintr = i1.codintr
    LEFT JOIN general                   g      ON g.coddoc = i.codintr AND g.tipdoc = i.tipdoc
    LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG   ON GREG.CODGENERAL = G.CODGENERAL
    LEFT JOIN nmonede                   mon    ON mon.codmoneda = g.moneda
    LEFT JOIN num1                      u1     ON u1.codum1 = i1.umsec
    LEFT JOIN nartobj                   nobj   ON nobj.codobiect = i1.codobiect
		LEFT JOIN npart                     np     on np.codpart = i.partener
		LEFT JOIN npart1                    np1    on np1.codpart = i.partener AND GREATEST(i.an*12+i.luna,&apos;||sALMin||&apos;) BETWEEN np1.alstart and np1.alstop
    LEFT JOIN iopart                    iop    ON iop.codiopart = np1.codiopart
		LEFT JOIN npart1                    cp1    on cp1.codpart = i.partener AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN cp1.alstart and cp1.alstop
    LEFT JOIN iopart                    ciop   ON ciop.codiopart = cp1.codiopart
    LEFT JOIN nsubunit                  ns     ON ns.codsubunit = i.subunitatea
    LEFT JOIN centrecost                cc     ON cc.codcentru = i1.codcentru
    LEFT JOIN nparttr                   nptr   ON nptr.codparttr = i.delegat
    LEFT JOIN npart                     transp ON transp.codpart = nptr.codpart
    LEFT JOIN npers                     deleg  ON deleg.codpers = nptr.codpers
    LEFT JOIN ngest                     ng     on ng.codgest = i1.gestact
    LEFT JOIN nparcaut                  paut   ON paut.codnparcaut = nptr.codauto
    LEFT JOIN ser                              ON ser.codintr1 = ca.codintr1
    LEFT JOIN TMP_LST_CURS              cfc    ON cfc.codmoneda = g.moneda&apos;||
    jAuxStoc||gSuplJoins||&apos;
  WHERE Round(ca.cant_aviz,4) &lt;&gt; Round(ca.cant_fact,4) &apos;;

  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpname||&apos; SET CF_VALOARE = CF_CURS*VALCUTVA&apos;;
	COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE TEST IS
AnLista number(4);
LunaLista number(2);
AnPrec number(4);
LunaPrec number(2);
aCount number(10);
BEGIN
  AnLista := 2008;
  LunaLista := 7;
  pkg_globals.SetLunaTemp(AnLista,LunaLista);
  pkg_globals.Calculeaza_Luna_Precedenta(AnLista,LunaLista,AnPrec,LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);
  select count(*) into acount from v_stoc_luna;
  delete tmp_lst_stocobj;
  INSERT INTO tmp_lst_stocobj (
    codobiect, rest
  )
  SELECT
    ns.codobiect,
    sum(COALESCE(VS.REST/NUM1.PARITATE,0))
  FROM v_stoc_luna vs
    INNER JOIN nirstoc ns ON ns.codnirstoc = vs.codnirstoc
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest ng ON ng.codgest = n.gest and ng.codsubunit = 2
    LEFT JOIN NUM1 ON NUM1.CODUM1 = NS.UMSEC
    LEFT JOIN intrari intr ON intr.codintr = n.codintr AND intr.tipdoc = n.tipnir
    LEFT JOIN dvi1 ON dvi1.coddvi1 = ns.coddvi1
    LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr AND intr1.codintr1 = Coalesce(dvi1.codintr1,ns.codintr1)
    LEFT JOIN transf t ON t.codtransf = n.codtransf AND t.tipdoc = n.tipnir
    LEFT JOIN transf1 t1 ON t1.codtransf = n.codtransf AND t1.codtransf1 = ns.codtransf1
    LEFT JOIN iesiri ies ON ies.codies = n.codies AND ies.tipdoc = n.tipnir
    LEFT JOIN livr l ON l.codies = n.codies AND l.codlivr = n.codnir
    LEFT JOIN livr1 l1 ON l1.codlivr = l.codlivr AND l1.codnirstoc = ns.codnirstoc AND (l1.cant &lt; 0 OR n.tipnir = 15)
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = l1.codies1
    LEFT JOIN nirstoc1 ns1 ON ns1.codnirstoc = NS.CodNirStoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocOrig
    LEFT JOIN nir nroot ON nroot.codnir = nsroot.codnir
    LEFT JOIN intrari intrroot ON intrroot.codintr = nroot.codintr AND intr.tipdoc = nroot.tipnir
    LEFT JOIN dvi1 dvi1root ON dvi1root.coddvi1 = nsroot.coddvi1
    LEFT JOIN intrari1 intr1root ON intr1root.codintr = intrroot.codintr AND intr1root.codintr1 = Coalesce(dvi1root.codintr1,nsroot.codintr1)
    LEFT JOIN ioart1 ioa1 ON ioa1.codioart = ns.codioart AND COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) BETWEEN ioa1.alstart AND ioa1.alstop
  WHERE
    (VS.REST &lt;&gt; 0 OR VS.RESTUM2 &lt;&gt; 0)
    AND ioa1.mg &lt;&gt; 5
    AND (ies1.codies IS NULL OR ies1.codies = n.codies)
    AND (l.codlivr IS NULL OR l1.codlivr = l.codlivr)
  GROUP BY NS.CODOBIECT;
  commit;
END;


end pkg_list_base_factnesosit;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F803537D64E73F7CC9CC09DE2B2A2BAA56FCCCEA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FAZ is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vAllAuto     BOOLEAN;
  vAllSoferi   BOOLEAN;
  vDataIni     varchar2(10);
  vDataFin     varchar2(10);

PROCEDURE SETPARAMS(pDataIni    IN VARCHAR2 DEFAULT NULL,
                    pDataFin    IN VARCHAR2 DEFAULT NULL,
                    pAllAuto    IN NUMBER   DEFAULT 1,
                    pAllSoferi  IN NUMBER   DEFAULT 1,
                    V_CODJOB1   IN NUMBER   DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vAllAuto   := Coalesce(pAllAuto,   1) = 1;
  vAllSoferi := Coalesce(pAllSoferi, 1) = 1;

  vDataIni   := pDataIni;
  vDataFin   := pDataFin;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sCondSupl varchar2(1000);
BEGIN
  gSuplCols := &apos;faz faz, faz0 fazZ&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sCondSupl := &apos;&apos;;
  if not vAllAuto then
    sCondSupl := sCondSupl||&apos; and exists (select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODNPARCAUT&apos;&apos; and valoare = pa.codnparcaut) &apos;;
  end if;
  if not vAllSoferi then
    sCondSupl := sCondSupl||&apos; and exists (select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODPERS&apos;&apos; and valoare = S.CODPERS) &apos;;
  end if;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     PrefixDoc,
     NrDoc,
     DataDoc,
     SeriaDoc,
     Diagrama,
     ConsumMediu,
     KmBordPlecare,
     KmBordSosire,
     ParcursTotal,
     ParcursNejustificat,
     KmEchivCatDrum,
     KmEchivCatDrum_Plin,
     KmEchivCatDrum_Gol,
     KmEchivSporuri,
     KmEchivSporuri_Tractare,
     KmEchivSporuri_Urban,
     KmEchivSporuri_Aero,
     KmEchivSporuri_Inst,
     KmEchivTotal,
     ConsumSuplim_PO,
     ConsumSuplim_Iarna,
     ConsumSuplim_Incalzire,
     ConsumSuplim_RezAer,
     ConsumSuplim_Combina,
     CoefSarcina_FaraRem,
     CoefSarcina_CuRem,
     RezervorPlecare,
     Alimentare,
     ConsumNormat,
     ConsumReal,
     RezervorSosire_Calculat,
     RezervorSosire_Real,
     DifConsum,
     Transp,
     Stationare,
     Pontaj_Acord,
     Pontaj_Regie,
     Pontaj_Nejustif,
     NrInreg,
     Auto,
     ConsumRealizat,
     Sofer,
     DataPlecare,
     KmPlecare,
     KmSosire,
     IndexLocal&apos;||gUserFields||&apos;)
  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)
  SELECT
     FAZ.CODFAZ NAV_CodDoc,
     89 NAV_TipDoc,
     FAZ.PrefixDoc,
     FAZ.NrDoc,
     FAZ.DataDoc,
     FAZ.SeriaDoc,
     FAZ.Diagrama,
     FAZ.CmM,
     FAZ.KMPLECARE KmBordPlecare,
     FAZ.KMSOSIRE KmBordSosire,
     case
       when nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0) &lt; 0  then 0
       else nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0)
     end ParcursTotal,
     FAZ.KMN ParcursNejustificat,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE CODFAZ = FAZ.CODFAZ) KmEchivCatDrum,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE INCARCAT = 1 AND CODFAZ = FAZ.CODFAZ) KmEchivCatDrum_Plin,
     (SELECT NVL(SUM(KM * COEF),0) FROM FAZ1 WHERE INCARCAT = 0 AND CODFAZ = FAZ.CODFAZ) KmEchivCatDrum_Gol,
     0 KmEchivSporuri,
     0 KmEchivSporuri_Tractare,
     0 KmEchivSporuri_Urban,
     0 KmEchivSporuri_Aero,
     0 KmEchivSporuri_Inst,
     (SELECT NVL(SUM(NVL(CANT * SPOR,0)),0) FROM FAZ2 WHERE CODFAZ = FAZ.CODFAZ) KmEchivTotal,
     FAZ.TSTART ConsumSuplim_PO,
     0 ConsumSuplim_Iarna,
     FAZ.TIMOTOR ConsumSuplim_Incalzire,
     0 ConsumSuplim_RezAer,
     FAZ.TCURSE ConsumSuplim_Combina,
     FAZ.CSARCINA CoefSarcina_FaraRem,
     FAZ.CSARCINAR CoefSarcina_CuRem,
     FAZ.RezervorPlecare,
     FAZ.ALIMPOMPA Alimentare,
     FAZ.CONSUM ConsumNormat,
     FAZ.CONSUM ConsumReal,
     FAZ.REZERVORCALC RezervorSosire_Calculat,
     FAZ.REZERVOR RezervorSosire_Real,
     FAZ.REZERVORCALC - FAZ.REZERVOR DifConsum,
     FAZ.TONES Transp,
     FAZ.ORES Stationare,
     FAZ.OREACORD Pontaj_Acord,
     FAZ.OREREGIE Pontaj_Regie,
     FAZ.OREN Pontaj_Nejustif,
     PA.NRINREG NrInreg,
     O.DENUMIRE Auto,
     case when nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0) = 0 then 0 else (nvl(FAZ.RezervorPlecare,0) + nvl(FAZ.Alimpompa,0) + nvl(FAZ.ALIMBCF,0) + nvl(FAZ.ALIMAVANS,0)
               - nvl(FAZ.Rezervor,0)) *100 / (nvl(FAZ.KmSosire,0) - nvl(FAZ.KmPlecare,0)) end,
     S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME Sofer,
     fazZ.dataplecare,
     fazZ.kmplecare,
     fazZ.kmsosire,
     fazZ.indexlocal&apos;||gUserAlias||&apos;
  FROM FAZ FAZ
    INNER JOIN nparcaut pa on FAZ.CODAUTO = pa.CODNPARCAUT
    LEFT JOIN FAZ0 FAZZ ON FAZZ.CODFAZ = FAZ.CODFAZ
    LEFT JOIN NPERS S ON S.CODPERS = FAZZ.CODPERS
    LEFT JOIN mifix mf ON mf.nrinventar = pa.nrinv and mf.tip = &apos;&apos;MF&apos;&apos;
    LEFT JOIN mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model&apos;||
    gSuplJoins||&apos;
  WHERE FAZ.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||sCondSupl;

  --delete x;
  --insert into x(test) values(sinsert);
  --commit;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert := &apos;begin
              for v_rec in (select nav_coddoc, max(indexlocal) indexlocal
                            from &apos;||tmpName||&apos;
                            group by nav_coddoc) loop
              update &apos;||tmpName||&apos; tmp set
                Alimentare = null,
                RezervorPlecare = null,
                RezervorSosire_Calculat = null,
                RezervorSosire_Real = null,
                ConsumMediu = null,
                ConsumNormat = null,
                ConsumReal = null,
                ConsumRealizat = null,
                DifConsum = null
              where tmp.nav_coddoc = v_rec.nav_coddoc and tmp.indexlocal &lt;&gt; v_rec.indexlocal;
              end loop;
              end;&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_FAZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FIDELIZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>418ED458EAF0D9D70DE563371B99A3356B2B94AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_fidelizare IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(30000);
  vDataStart varchar2(10);
  vDataStop varchar2(10);
BEGIN
  gSuplCols := &apos;npart p, emulare e,punctaje pj&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vDataStart := to_char(pkg_list_selectscadentar.DataRef, &apos;dd.mm.yyyy&apos;);
  vDataStop := to_char(pkg_list_selectscadentar.DataRest, &apos;dd.mm.yyyy&apos;);
  
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;
   (
    NRBON,
    DATABON,
    VAL_BON,
    DEN_PART,
    PUNCTE_P,
    PUNCTE_F,
    VAL_PUNCTE_P,
    VAL_PUNCTE_F,
    TIPPUNCTAJ,
    SOLD,
    ordine &apos;||gUserFields||&apos;
    )
    with PuncteCentr as (
      select
        codemulare,
        codpunctaj,
        codpart,
        sum(case when puncte &gt; 0 then puncte else 0 end) puncte_p,
        sum(case when puncte &lt; 0 then - puncte else 0 end) puncte_f,
        sum(case when valoare &gt; 0 then valoare else 0 end) val_puncte_p,
        sum(case when valoare &lt; 0 then - valoare else 0 end) val_puncte_f
      from partpuncte
      where data between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataStop||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      group by codemulare, codpunctaj, codpart
    )
    select
      pp.nrbon,
      pp.databon,
      pp.val_bon,
      pp.den_part,
      pp.puncte_p,
      pp.puncte_f,
      pp.val_puncte_p,
      pp.val_puncte_f,
      pp.tippunctaj,
      SUM(pp.puncte_p - pp.puncte_f) over (PARTITION BY pp.codpart ORDER BY pp.ordine ROWS BETWEEN unbounded preceding AND CURRENT ROW),
      pp.ordine &apos;||gUserAlias||&apos;
    from (
    select
      to_date(&apos;&apos;30.12.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) ordine,
      pp.codpart,
      null nrbon,
      to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) databon,
      null val_bon,
      p.den_part,
      sum(pp.puncte) puncte_p,
      0 puncte_f,
      sum(pp.valoare) val_puncte_p,
      0 val_puncte_f,
      &apos;&apos;Sold puncte&apos;&apos; TipPunctaj,
      pp.codpunctaj,
      pp.codemulare
    from partpuncte pp
         inner join npart p on pp.codpart = p.codpart
         left join punctaje pj on pp.codpunctaj = pj.codpunctaj
         left join emulare e on e.codemulare = pp.codemulare
    where pp.data &lt; to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          and (pkg_list_selectscadentar.TotiPartNumber = 1 or exists(select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODPART&apos;&apos; and p.codpart = valoare))
          and (pkg_list_selectscadentar.ToateClaseleNumber = 1 or exists(select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODCLASEP&apos;&apos; and p.codclasa = valoare))
    group by p.den_part, pp.codpart,pp.codpunctaj,pp.codemulare
    union all
    select
      e.datacreare ordine,
      pp.codpart,
      e.nrbon,
      e.databon,
      e.valoare val_bon,
      p.den_part,
      pp.puncte_p,
      pp.puncte_f,
      pp.val_puncte_p,
      pp.val_puncte_f,
      case when pj.tip = 1 then &apos;&apos;Bonus valoric&apos;&apos;
           when pj.tip = 2 then &apos;&apos;Bonus procentual&apos;&apos;
           else &apos;&apos; &apos;&apos;
      end TipPunctaj,
      pp.codpunctaj,
      pp.codemulare
    from punctecentr pp
         inner join npart p on pp.codpart = p.codpart
         inner join punctaje pj on pp.codpunctaj = pj.codpunctaj
         inner join emulare e on e.codemulare = pp.codemulare
    where (pkg_list_selectscadentar.TotiPartNumber = 1 or exists(select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODPART&apos;&apos; and p.codpart = valoare))
          and (pkg_list_selectscadentar.ToateClaseleNumber = 1 or exists(select valoare from tmp_manevra_liste where filtru = &apos;&apos;CODCLASEP&apos;&apos; and p.codclasa = valoare)
    )
    ) pp
     inner join npart p on pp.codpart = p.codpart
     left join punctaje pj on pp.codpunctaj = pj.codpunctaj
     left join emulare e on e.codemulare = pp.codemulare&apos;||
     gSuplJoins||&apos;
    ORDER BY ordine &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_fidelizare;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAANALITIKPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B73EC373797BD2D2CC92ADA25711306B9492E3E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAANALITIKPART IS

  bMoneda    BOOLEAN := FALSE;
  bCont      BOOLEAN := FALSE;
  bAllSub    BOOLEAN := FALSE;
  vAllSting  INTEGER := 0;
  bSubStins  BOOLEAN := FALSE;
  pSubunit   NUMBER(20);
  bBalanta   BOOLEAN := FALSE;
  bDefalcLoc BOOLEAN := TRUE;
  bDefalcDoc BOOLEAN := FALSE;
  bAduInfoCM BOOLEAN := FALSE;
  bExpert    BOOLEAN := FALSE;
  bMonSold   BOOLEAN := FALSE;
  pTipIopart INTEGER := 0 ;
  aCodMoneda INTEGER;
  nrMonede   INTEGER;
  g_codPart  NUMBER(20);
  g_lunaIni  NUMBER(20);
  g_lunaFin  NUMBER(20);
  vCFTSub    NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  sIcontS_F   VARCHAR2(2500) := &apos;,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59&apos;;
  sIcontS_C   VARCHAR2(2500) := &apos;,30,31,32,33,34&apos;;


FUNCTION getTrezIFRS(aCodGeneral IN number, aMoneda IN number, aValoare IN number, aAnLuna IN number) return number is
  Reg_OLD number(20,7);
BEGIN
  IF aMoneda = 0 THEN
    RETURN 0;
  END IF;
  BEGIN
    SELECT CASE WHEN Coalesce(REG.CURS_IFRS, 0) &lt;&gt; 0 THEN (REG.CURS_IFRS-reg.curs)*aValoare ELSE 0 END into Reg_OLD
    FROM REG
      INNER JOIN (
        SELECT max(ol.an*12+ol.luna) AnLuna
        FROM OBLIGPIFLUNA OL
            INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
            INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL AND G.CodGeneral = aCodGeneral
            INNER JOIN reg1 on g.codgeneral = reg1.codgeneral
            INNER JOIN reg on reg1.codreg = reg.codreg and ol.an = reg.an and ol.luna = reg.luna
          WHERE ol.an*12+ol.luna &lt;= aAnLuna
            AND reg.curs_ifrs &lt;&gt; 0 AND ol.rest &lt;&gt; 0 AND reg.codmoneda = aMoneda
            AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      ) R ON REG.AN*12+REG.LUNA = R.ANLUNA
      INNER JOIN reg1 ON REG.codREG = reg1.codREG AND REG1.CODGENERAL = ACODGENERAL;
  EXCEPTION
    WHEN others THEN Reg_OLD := 0;
  END;
  RETURN Reg_OLD;
END;

FUNCTION getreg1ifrs(aCodGeneral IN number, aDifIFRS IN number, aAnLuna IN number, aCursIFRS IN number, aSoldDoc IN number) return number is
  DIF_CURS_OLD number(20,7);
BEGIN
  IF aCursIFRS = 0 THEN
    RETURN 0;
  END IF;
  BEGIN
    SELECT (REG.CURS_IFRS - REG.CURS)*aSOLDDOC into DIF_CURS_OLD
    FROM REG
      INNER JOIN (
        SELECT max(ol.an*12+ol.luna) AnLuna
        FROM OBLIGPIFLUNA OL
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL AND G.CodGeneral = aCodGeneral
          inner join reg1 on g.codgeneral = reg1.codgeneral
          inner join reg on reg1.codreg = reg.codreg and ol.an = reg.an and ol.luna = reg.luna
        WHERE ol.an*12+ol.luna &lt;= aAnLuna and reg.curs_ifrs &lt;&gt; 0 and ol.rest &lt;&gt; 0 and reg.tipreg = 46
          AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      ) R ON REG.AN*12+REG.LUNA = R.ANLUNA
      INNER JOIN reg1 on REG.codREG = reg1.codREG AND REG1.CODGENERAL = ACODGENERAL;
  EXCEPTION
    WHEN others THEN DIF_CURS_OLD := 0;
  END;
  RETURN aDifIFRS - DIF_CURS_OLD;
END;

FUNCTION GetDataDecont(pCodDoc IN NUMBER, pTipDoc IN NUMBER) RETURN VARCHAR2 IS
  vResult VARCHAR2(3200);
  vSep    VARCHAR2(1);
BEGIN
  IF Coalesce(pCodDoc,0) = 0 OR Coalesce(pTipDoc,0) = 0 THEN
    vResult := &apos;&apos;;
  ELSIF pTipDoc = 31 THEN
    vResult := &apos;&apos;;
    vSep    := &apos;&apos;;
    FOR vRec IN (
      SELECT DISTINCT t1s.datadoc DataDecont
      FROM general gc
        INNER JOIN obligpif oc ON oc.codgeneral = gc.codgeneral
        INNER JOIN stingere sc ON sc.codstinspif = oc.codobligpif
        INNER JOIN obligpif osc ON osc.codobligpif = sc.codstingatorpif
        INNER JOIN general gsc ON gsc.codgeneral = osc.codgeneral
        INNER JOIN trezor1 t1s ON t1s.codtrezor1 = gsc.coddoc
      WHERE gc.semnificatie IN (500,600) AND gc.tipdoc = pTipDoc AND gc.coddoc = pCodDoc
        AND t1s.datadoc IS NOT NULL
      ORDER BY 1
      --ORDER BY t1s.datadoc
    ) LOOP
      vResult := vResult||vSep||To_Char(vRec.DataDecont,&apos;dd.mm.yyyy&apos;);
      vSep    := &apos;;&apos;;
    END LOOP;
  ELSE
    vResult := &apos;&apos;;
    vSep    := &apos;&apos;;
    FOR vRec IN (
      SELECT DISTINCT t1s.datadoc DataDecont
      FROM general gc
        INNER JOIN general g ON g.coddoc = gc.coddoc AND g.tipdoc = gc.tipdoc AND g.semnificatie &lt;&gt; gc.semnificatie
        INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
        INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
        INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
        INNER JOIN general gs ON gs.codgeneral = os.codgeneral
        INNER JOIN trezor1 t1 ON t1.codtrezor1 = gc.coddoc
        INNER JOIN obligpif oc ON oc.codgeneral = gc.codgeneral
        INNER JOIN stingere sc ON sc.codstinspif = oc.codobligpif
        INNER JOIN obligpif osc ON osc.codobligpif = sc.codstingatorpif
        INNER JOIN general gsc ON gsc.codgeneral = osc.codgeneral
        INNER JOIN trezor1 t1s ON t1s.codtrezor1 = gsc.coddoc
      WHERE gc.semnificatie IN (500,600) AND gs.tipdoc = pTipDoc AND gs.coddoc = pCodDoc
        AND t1s.datadoc IS NOT NULL
      ORDER BY 1
      --ORDER BY t1s.datadoc -- la un anumit client in anumite conditii crapa cu ORA-00942: tabelul sau vizualizarea nu exista
    ) LOOP
      vResult := vResult||vSep||To_Char(vRec.DataDecont,&apos;dd.mm.yyyy&apos;);
      vSep    := &apos;;&apos;;
    END LOOP;
  END IF;
  RETURN vRESULT;
END;

PROCEDURE MAKE_UTILFISAPART IS
  vCond     VARCHAR2(10000)    := &apos;&apos;;
  vInsert1  VARCHAR2(10000);
  vInsert2  VARCHAR2(10000);
  vInsert3  VARCHAR2(10000);
  vAL       NUMBER(5);
BEGIN
  IF NOT bBalanta THEN
    vCond  :=&apos;
    AND O.CODPART = &apos;||g_CodPart;
  END IF;

  IF pSubunit &lt;&gt; 1 THEN
    vCond  := vCond||&apos;
    AND I.SUBUNITATEA = &apos;||pSubunit;
  END IF;

  DELETE TMP_FISAPART_OBLIG;
  vInsert1 := &apos;
  INSERT INTO TMP_FISAPART_OBLIG   -- AVIZE DE INTRARE STINSE
  SELECT O.CODOBLIGPIF, -Sum(I1.PU * I1.CANT + Coalesce(SI1.TVA, 0) * CASE WHEN SI1.PU * SI1.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT /(SI1.PU*SI1.CANT) END)
  FROM INTRARI I
    INNER JOIN GENERAL  G   ON G.CODDOC      = I.CODINTR AND G.TIPDOC = I.TIPDOC
    INNER JOIN OBLIGPIF O   ON O.CODGENERAL  = G.CODGENERAL
    INNER JOIN INTRARI1 I1  ON I1.CODINTR    = I.CODINTR
    INNER JOIN INTRLINK IL  ON IL.CODINTR1   = I1.CODINTR1
    INNER JOIN INTRARI1 SI1 ON SI1.CODINTR1  = IL.CODLINIEAVIZ
    INNER JOIN INTRARI  SI  ON SI.CODINTR    = SI1.CODINTR
    INNER JOIN GENERAL  SG  ON SG.CODDOC     = SI.CODINTR AND SG.TIPDOC = SI.TIPDOC
    INNER JOIN OBLIGPIF SO  ON SO.CODGENERAL = SG.CODGENERAL
  WHERE I.TIPDOC = 9 AND I.OPERAT = 1 AND I.MONEDA &lt;&gt; 0
    AND I.AN * 12 + I.LUNA BETWEEN &apos;||g_LunaIni||&apos; AND &apos;||g_LunaFin||
    vCond||&apos;
    AND O.SEMNIFICATIE = 140
    AND Coalesce(G.FaraReg, 0) = 0
    AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)
  GROUP BY O.CODOBLIGPIF&apos;;

  vInsert2 := &apos;
  INSERT INTO TMP_FISAPART_OBLIG   -- AVIZE DE INTRARE STINSE PRIN DVI
  SELECT O.CODOBLIGPIF, -Sum(I1.PU * I1.CANT + Coalesce(SI1.TVA, 0) * CASE WHEN SI1.PU * SI1.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT /(SI1.PU*SI1.CANT) END)
  FROM INTRARI I
    INNER JOIN GENERAL  G   ON G.CODDOC      = I.CODINTR AND G.TIPDOC = I.TIPDOC
    INNER JOIN OBLIGPIF O   ON O.CODGENERAL  = G.CODGENERAL
    INNER JOIN INTRARI1 I1  ON I1.CODINTR    = I.CODINTR
    INNER JOIN INTRLINK IL  ON IL.CODINTR1   = I1.CODINTR1
    INNER JOIN INTRARI1 SI1 ON SI1.CODINTR1  = IL.CODLINIEAVIZ
    INNER JOIN INTRARI  SI  ON SI.CODINTR    = SI1.CODINTR
    INNER JOIN GENERAL  SG  ON SG.CODDOC     = SI.CODINTR AND SG.TIPDOC = SI.TIPDOC
    INNER JOIN OBLIGPIF SO  ON SO.CODGENERAL = SG.CODGENERAL
  WHERE I.TIPDOC = 5 AND Coalesce(I.TIPFACTURA, 0) = 10 AND I.OPERAT = 1 AND I.MONEDA &lt;&gt; 0
    AND I.AN * 12 + I.LUNA BETWEEN &apos;||g_LunaIni||&apos; AND &apos;||g_LunaFin||
    vCond||&apos;
    AND O.SEMNIFICATIE = 140
    AND Coalesce(G.FaraReg, 0) = 0
    AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)
  GROUP BY O.CODOBLIGPIF&apos;;

  vInsert3 := &apos;
  INSERT INTO TMP_FISAPART_OBLIG   -- AVIZE DE IESIRE STINSE
  SELECT O.CODOBLIGPIF, -Sum(I1.PU * I1.CANT + Coalesce(SI1.TVA, 0) * CASE WHEN SI1.PU * SI1.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT /(SI1.PU*SI1.CANT) END)
  FROM IESIRI I
    INNER JOIN GENERAL  G   ON G.CODDOC      = I.CODIES AND G.TIPDOC = I.TIPDOC
    INNER JOIN OBLIGPIF O   ON O.CODGENERAL  = G.CODGENERAL
    INNER JOIN IESIRI1  I1  ON I1.CODIES     = I.CODIES
    INNER JOIN IESLINK  IL  ON IL.CODIES1    = I1.CODIES1
    INNER JOIN IESIRI1  SI1 ON SI1.CODIES1   = IL.CODLINIEAVIZ
    INNER JOIN IESIRI   SI  ON SI.CODIES     = SI1.CODIES
    INNER JOIN GENERAL  SG  ON SG.CODDOC     = SI.CODIES AND SG.TIPDOC = SI.TIPDOC
    INNER JOIN OBLIGPIF SO  ON SO.CODGENERAL = SG.CODGENERAL
  WHERE I.TIPDOC = 26 AND I.OPERAT = 1 AND I.MONEDA &lt;&gt; 0
    AND I.AN * 12 + I.LUNA BETWEEN &apos;||g_LunaIni||&apos; AND &apos;||g_LunaFin||
    vCond||&apos;
    AND O.SEMNIFICATIE = 240
    AND Coalesce(G.FaraReg, 0) = 0
    AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)
  GROUP BY O.CODOBLIGPIF&apos;;

  LIST_EXECUTE_IMMEDIATE(vInsert1,0,0);
  LIST_EXECUTE_IMMEDIATE(vInsert2,0,0);
  LIST_EXECUTE_IMMEDIATE(vInsert3,0,0);
  COMMIT;

  DELETE FROM TMP_CONSTANTE WHERE SIMBOL = &apos;CONTABCURSLINIE&apos;;
  vAL := g_LunaIni;
  WHILE vAL &lt;= g_LunaFin LOOP
    INSERT INTO TMP_CONSTANTE (SIMBOL, VALOARE, ANLUNA) VALUES(&apos;CONTABCURSLINIE&apos;, Coalesce(pkg_categconst.GetValConstanta(&apos;CONTABCURSLINIE&apos;,0,vAL), &apos;0&apos;), vAL);
    vAL := vAL + 1;
  END LOOP;
END;

PROCEDURE SET_LISTA_PARAMS (
  IsAllMoneda IN NUMBER  DEFAULT 1,
  IsAllCont   IN NUMBER  DEFAULT 1,
  IsAllSub    IN NUMBER  DEFAULT 1,
  IsBalanta   IN NUMBER  DEFAULT 1,
  aCodpart    IN NUMBER,
  aLunaStart  IN NUMBER,
  aLunaFin    IN NUMBER,
  aTipIopart  IN NUMBER  DEFAULT 0,
  IsDefalcLoc IN NUMBER  DEFAULT 1,
  IsDefalcDoc IN NUMBER  DEFAULT 0,
  AduInfoCM   IN NUMBER  DEFAULT 0,
  pCodJob1    IN NUMBER  DEFAULT 0,
  pAllSting   IN NUMBER  DEFAULT 0,
  IsSubStins  IN NUMBER  DEFAULT 0,
  pExpert     IN NUMBER  DEFAULT 0,
  pMonSold    IN NUMBER  DEFAULT 0
) IS
  dDataS     DATE;
  dDataF     DATE;
  sSelContS  VARCHAR2(3200);
  sSelContD  VARCHAR2(3200);
BEGIN
  bMoneda     := Coalesce(IsAllMoneda, 1) = 1 ;
  bCont       := Coalesce(IsAllCont,   1) = 1 ;
  bAllSub     := Coalesce(IsAllSub,    1) = 1 ;
  vAllSting   := Coalesce(pAllSting,   0);
  bSubStins   := Coalesce(IsSubStins,  0) = 1;
  IF bAllSub THEN
    pSubunit  := 1;
    vCFTSub   := 1;
  ELSE
    vCFTSub   := Coalesce(pkg_categconst.GetValConstanta(&apos;CumulatFirmaToateSub&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),2);
    pSubunit  := PKG_GLOBALS.GETSUBUNITATE;
  END IF;
  bBalanta    := Coalesce(IsBalanta,   1) = 1;
  bDefalcLoc  := Coalesce(IsDefalcLoc, 1) = 1;
  bDefalcDoc  := Coalesce(IsDefalcDoc, 0) = 1;
  bAduInfoCM  := Coalesce(AduInfoCM,   0) = 1;
  bExpert     := Coalesce(pExpert,     0) = 1;
  bMonSold    := Coalesce(pMonSold,    0) = 1;
  g_codPart   := aCodPart;
  g_lunaIni   := aLunaStart;
  g_lunaFin   := aLunaFin;
  pTipIopart  := aTipIopart;

  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,dDataS,dDataF,g_lunaIni,g_lunaFin);
  END IF;

  nrMonede    := 0;
  IF NOT bMoneda THEN
    SELECT Count(1), Max(valoare) INTO nrMonede, aCodMoneda FROM tmp_manevra_liste WHERE filtru = &apos;CODMONEDA&apos;;
  END IF;
  IF nrMonede &lt;&gt; 1
  THEN aCodMoneda := -1;
  END IF;

  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  MAKE_UTILFISAPART;

  pkg_list_Struct.GOLESTE_PARAM;
  pkg_globals.SetSeparator(&apos;,&apos;);

  SELECT vc2_nt_to_vc3200(CAST(COLLECT(Simbol   ORDER BY clasa, simbol) AS vc2_nt)), vc2_nt_to_vc3200(CAST(COLLECT(Den_Cont ORDER BY clasa, simbol) AS vc2_nt))
  INTO sSelContS, sSelContD
  FROM ncont c
  WHERE c.codcont IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODCONT&apos;);

  pkg_list_Struct.ADAUGA_PARAM(&apos;Conturi selectate&apos;,             sSelContS);
  pkg_list_Struct.ADAUGA_PARAM(&apos;Conturi selectate - denumiri&apos;,  sSelContD);
END;

procedure doInsert(d number, c number, a varchar2, s number) IS
begin
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_semnificatii(debit, credit, alias, semn) values(:v1, :v2, :v3, :v4) &apos; USING  d, c, a, s;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_semnificatii(debit, credit, alias, semn) values(:v1, :v2, :v3, :v4) &apos; USING -c, -d, a, -s;
END;

PROCEDURE setSemnificatii IS
BEGIN
  DELETE FROM tmp_semnificatii;
  doInsert(NULL,  100, &apos;tsObligFurn&apos;,                    1);
  doInsert( 101, NULL, &apos;tsFactAvFurn&apos;,                  -1);
  doInsert( 102, NULL, &apos;tsDVIAvFurn&apos;,                   -1);
  doInsert( 110, NULL, &apos;tsAvansFurn&apos;,                    1);
  doInsert( 111, NULL, &apos;tsStornoAvansFurn&apos;,             -1);
  doInsert( NULL, 120, &apos;tsGarantieFurn&apos;,                 1);
  doInsert( 121, NULL, &apos;tsStornoGarantieFurn&apos;,          -1);
  doInsert(NULL,  130, &apos;tsObligVama&apos;,                    1);
  doInsert(NULL,  140, &apos;tsAvizeFurn&apos;,                    1);
  doInsert( 200, NULL, &apos;tsObligClient&apos;,                  1);
  doInsert(NULL,  201, &apos;tsFactAvClient&apos;,                -1);
  doInsert(NULL,  210, &apos;tsAvansClient&apos;,                  1);
  doInsert(NULL,  211, &apos;tsStornoAvansClient&apos;,           -1);
  doInsert(220,  NULL, &apos;tsGarantieClient&apos;,               1);
  doInsert(NULL,  221, &apos;tsStornoGarantieClient&apos;,        -1);
  doInsert( 240, NULL, &apos;tsAvizeClient&apos;,                  1);
  doInsert( 300, NULL, &apos;tsPlataFurn&apos;,                    1);
  doInsert( 310, NULL, &apos;tsPlataInAvansFurn&apos;,             1);
  doInsert(NULL,  320, &apos;tsReturFurnizor&apos;,                1);
  doInsert(NULL,  330, &apos;tsPlataInAvansReturClient&apos;,     -1);
  doInsert(NULL,  400, &apos;tsIncasareClient&apos;,               1);
  doInsert(NULL,  410, &apos;tsIncasareInAvansClient&apos;,        1);
  doInsert( 420, NULL, &apos;tsReturClient&apos;,                  1);
  doInsert( 430, NULL, &apos;tsIncasareInAvansReturFurn&apos;,    -1);
  doInsert( 700, NULL, &apos;tsReturCECFurn_Fact&apos;,            1);
  doInsert( 701, NULL, &apos;tsReturCECFurn_AnulareAvans&apos;,   -1);
  doInsert(NULL,  750, &apos;tsReturnCECClient_Fact&apos;,         1);
  doInsert(NULL,  751, &apos;tsReturCECClient_AnulareAvans&apos;, -1);
  doInsert(1200, NULL, &apos;tsNotaContabila&apos;,               -1);
  doInsert(NULL, 1201, &apos;tsNotaContabilaCredit&apos;,         -1);
  doInsert(1250, NULL, &apos;tsNotaContabilaAjustareDebit&apos;,  -1);
  doInsert(NULL, 1251, &apos;tsNotaContabilaAjustareCredit&apos;, -1);
  doInsert(1300, NULL, &apos;tsCompensDebit&apos;,                 1);
  doInsert(1301, NULL, &apos;tsCompensDebitFaraLeg&apos;,         -1);
  doInsert(1302, NULL, &apos;tsCompensDebitPeCont&apos;,          -1);
  doInsert(1303, NULL, &apos;tsCompensDebitLitigii&apos;,         -1);
  doInsert(NULL, 1350, &apos;tsCompensCredit&apos;,                1);
  doInsert(NULL, 1351, &apos;tsCompensCreditFaraLeg&apos;,        -1);
  doInsert(NULL, 1352, &apos;tsCompensCreditPeCont&apos;,         -1);
  doInsert(NULL, 1353, &apos;tsCompensCreditLitigii&apos;,        -1);

  doInsert(NULL, 9999, &apos;tsInfoCM&apos;,                       1); -- inventat pentru InfoCM

  COMMIT;
END;

FUNCTION  getTipSold RETURN INTEGER IS
  nrC       INTEGER;
  aTipCont  INTEGER;
BEGIN
  SELECT Count(1), Max(n.tipcont) INTO nrC, aTipCont
  FROM tmp_manevra_liste tmp INNER JOIN ncont n ON n.codcont = tmp.valoare
  WHERE tmp.filtru = &apos;CODCONT&apos;;

  IF nrC &lt;&gt; 1 THEN aTipCont := 2; END IF;

  RETURN aTipCont;
END;

FUNCTION  getColDebitCredit(sCurs VARCHAR2) RETURN CLOB IS
BEGIN
  RETURN &apos;,
    CASE
      WHEN                     tmp.semnificatie =   120 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN                     tmp.semnificatie =   120 AND tmp.icont NOT IN (21,22) THEN  0
      WHEN                     tmp.semnificatie =   121 AND tmp.icont     IN (21,22) THEN  0
      WHEN                     tmp.semnificatie =   121 AND tmp.icont NOT IN (21,22) THEN  tmp.valoare
      WHEN                     tmp.semnificatie = -1200 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN                     tmp.semnificatie =   220 AND tmp.icont     IN (23,24) THEN  0
      WHEN                     tmp.semnificatie =   220 AND tmp.icont NOT IN (23,24) THEN -tmp.valoare
      WHEN                     tmp.semnificatie =   221 AND tmp.icont     IN (23,24) THEN -tmp.valoare
      WHEN                     tmp.semnificatie =   221 AND tmp.icont NOT IN (23,24) THEN  0
      WHEN                     tmp.semnificatie = -1201 AND tmp.icont     IN (23,24) THEN  0
      WHEN                     tmp.semnificatie IN (1250,1251)                       THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  -220 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie = -1200 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1201 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1201 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN semn_d.debit IS NULL                                                      THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  -120 AND tmp.icont     IN (21,22) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1200 AND tmp.icont     IN (21,22) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1200 AND tmp.icont     IN (23,24) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie = -1201 AND tmp.icont     IN (21,22) THEN  0
      WHEN tmp.tipdoc = 46                                                           THEN  tmp.valoare
      WHEN                     tmp.semnificatie =  1300                              THEN  tmp.valoare*semn_d.semn
      WHEN tmp.icont IN (3,4,7,10,11,12,13,14,18,19,21,22&apos;||sIcontS_C||&apos;)
       AND tmp.tipdoc IN (28, 35)                                                    THEN -tmp.valoare*semn_d.semn
      ELSE                                                                                 tmp.valoare*semn_d.semn
    END * CASE WHEN tmp.tipdoc = 46 THEN 1 ELSE &apos;||sCurs||&apos; END + tmp.Corectie*Coalesce(semn_d.semn, semn_c.semn,1)*&apos;||sCurs||&apos; debit,
    CASE
      WHEN                     tmp.semnificatie =   120 AND tmp.icont     IN (21,22) THEN  0
      WHEN                     tmp.semnificatie =   120 AND tmp.icont NOT IN (21,22) THEN -tmp.valoare
      WHEN                     tmp.semnificatie =   121 AND tmp.icont     IN (21,22) THEN -tmp.valoare
      WHEN                     tmp.semnificatie =   121 AND tmp.icont NOT IN (21,22) THEN  0
      WHEN                     tmp.semnificatie = -1200 AND tmp.icont     IN (21,22) THEN  0
      WHEN                     tmp.semnificatie =   220 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN                     tmp.semnificatie =   220 AND tmp.icont NOT IN (23,24) THEN  0
      WHEN                     tmp.semnificatie =   221 AND tmp.icont     IN (23,24) THEN  0
      WHEN                     tmp.semnificatie =   221 AND tmp.icont NOT IN (23,24) THEN  tmp.valoare
      WHEN                     tmp.semnificatie = -1201 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN                     tmp.semnificatie IN (1250,1251)                       THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  -120 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1200 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1200 AND tmp.icont     IN (23,24) THEN  tmp.valoare
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie = -1201 AND tmp.icont     IN (21,22) THEN  tmp.valoare
      WHEN semn_c.credit IS NULL                                                     THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  -220 AND tmp.icont     IN (23,24) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie = -1200 AND tmp.icont     IN (23,24) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1201 AND tmp.icont     IN (21,22) THEN  0
      WHEN tmp.tipdoc = 46 AND tmp.semnificatie =  1201 AND tmp.icont     IN (23,24) THEN  0
      WHEN tmp.tipdoc = 46                                                           THEN  tmp.valoare
      WHEN tmp.semnificatie = 1350                                                   THEN  tmp.valoare*semn_c.semn
      WHEN tmp.semnificatie = 1351 AND tmp.icont IN (19)                             THEN -tmp.valoare*semn_c.semn
      WHEN tmp.icont IN (2,5,6,8,9,15,16,17,20,23,24&apos;||sIcontS_F||&apos;)
       AND tmp.tipdoc IN (28, 35)                                                    THEN -tmp.valoare*semn_c.semn
      ELSE                                                                                 tmp.valoare*semn_c.semn
    END * CASE WHEN tmp.tipdoc = 46 THEN 1 ELSE &apos;||sCurs||&apos; END + tmp.Corectie*Coalesce(semn_d.semn, semn_c.semn,1)*&apos;||sCurs||&apos; credit,
    CASE
      WHEN tmp.icont IN (2,5,6,8,9,15,16,17,20,23,24&apos;||sIcontS_F||&apos;)
      THEN tmp.valoareifrs * CASE WHEN tmp.tipdoc IN (28, 29,30,31) THEN  1 ELSE -1 END
      WHEN tmp.icont IN (3,4,7,10,11,12,13,14,18,19,21,22&apos;||sIcontS_C||&apos;)
      THEN tmp.valoareifrs * CASE WHEN tmp.tipdoc IN (28, 29,30,31) then -1 ELSE  1 END
      ELSE 0
    END ifrs&apos;;
END;

FUNCTION CONDSUBUNIT(camp VARCHAR2) RETURN VARCHAR2 IS
  RESULT VARCHAR2(1000);
  sNot   VARCHAR2(1000);
BEGIN
  IF pSUBUNIT &gt; 1 THEN
    RESULT := &apos;
      AND &apos;||camp||&apos; = &apos;||pSUBUNIT;
  ELSIF pSUBUNIT &lt; -1 THEN
    RESULT := &apos;
      AND &apos;||camp||&apos; &lt;&gt; &apos;||Abs(pSUBUNIT);
  ELSIF pSUBUNIT &lt;&gt; 0 AND vCFTSub = 2 THEN
    sNot := CASE WHEN pSUBUNIT = -1 THEN &apos;NOT &apos; ELSE &apos;&apos; END;
    RESULT := &apos;
      AND &apos;||sNot||camp||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate)&apos; ;
  ELSIF pSUBUNIT = -1 THEN
    RESULT := &apos;
      AND 1=2&apos; ;
  END IF;
  RETURN RESULT;
END;

FUNCTION CONDSUBUNITSTING(camp1 VARCHAR2, camp2 VARCHAR2) RETURN VARCHAR2 IS
  RESULT VARCHAR2(1000);
  sNot   VARCHAR2(1000);
BEGIN
  IF vAllSting = 0 THEN
    RESULT := CONDSUBUNIT(camp1);
  ELSIF vAllSting = 2 THEN
    RESULT := CONDSUBUNIT(camp2);
  ELSIF pSUBUNIT &gt; 1 THEN
    RESULT := &apos;
      AND (&apos;||camp1||&apos; = &apos;||pSUBUNIT||&apos; OR &apos;||camp2||&apos; = &apos;||pSUBUNIT||&apos;)&apos;;
  ELSIF pSUBUNIT &lt; -1 THEN
    RESULT := &apos;
      AND NOT (&apos;||camp1||&apos; = &apos;||Abs(pSUBUNIT)||&apos; OR &apos;||camp2||&apos; = &apos;||Abs(pSUBUNIT)||&apos;)&apos;;
  ELSIF pSUBUNIT &lt;&gt; 0 AND vCFTSub = 2 THEN
    sNot := CASE WHEN pSUBUNIT = -1 THEN &apos;NOT &apos; ELSE &apos;&apos; END;
    RESULT := &apos;
      AND &apos;||sNot||&apos;(&apos;||camp1||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate) OR &apos;||camp2||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate))&apos;;
  ELSIF pSUBUNIT = -1 THEN
    RESULT := &apos;
      AND 1=2&apos; ;
  END IF;
  RETURN RESULT;
END;

FUNCTION fPart (Col1 VARCHAR2, Col2 VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
  vResult VARCHAR2(200);
  vCond   VARCHAR2(200);
BEGIN
  vResult := &apos;&apos;;
  IF bBalanta
  THEN vCond := &apos; &lt;&gt; 0&apos;;
  ELSE vCond := &apos; = &apos;||g_codPart;
  END IF;

  vResult := Col1||vCond;
  IF Col2 IS NOT NULL
  THEN vResult := &apos;(&apos;||vResult||&apos; OR &apos;||Col2||vCond||&apos;)&apos;;
  END IF;

  vResult := &apos;
      AND &apos;||vResult;

  RETURN vResult;
END;

FUNCTION getSqlDocs(pHolding BOOLEAN, pOriceMoneda IN BOOLEAN, pAnalitica IN BOOLEAN) RETURN CLOB IS
  sqlDocs    CLOB;
  sqlInfoCM  VARCHAR2( 5000) :=&apos;&apos;;
  bForceLei  BOOLEAN         := NOT pAnalitica AND (aCodMoneda = -1);
  fMonedaG   VARCHAR2(  300);
  fMonedaI   VARCHAR2(  300);
  fCurs      VARCHAR2(  300);
  sLocatieT1 VARCHAR2(  300);
  sLocatieC  VARCHAR2(  300);
  sDocX      VARCHAR2( 1000);
  sDocXGroup VARCHAR2( 1000);
  sCursAjDep VARCHAR(   500) :=&apos;&apos;;
BEGIN
  if bExpert then
    IF bDefalcLoc THEN
      sLocatieT1 := &apos;COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0)&apos;;
      sLocatieC  := &apos;COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0)&apos;;
    ELSE
      sLocatieT1 := &apos;COALESCE(t1.codlocatie, 0)&apos;;
      sLocatieC  := &apos;0&apos;;
    END IF;

    IF bDefalcDoc AND pAnalitica THEN
      sDocX := &apos;,
        COALESCE(intr.tipdoc,ies.tipdoc,ts.tipdoc) dstinstipdoc, COALESCE(intr.codintr,ies.codies,t1s.codtrezor1) dstinscoddoc,
        COALESCE(intr.seriadoc,ies.seriadoc,t1s.seriedoc) dstinsseria, COALESCE(intr.carnetdoc,ies.carnetdoc,t1s.carnetdoc,nc.carnetdoc,cs.carnetdoc) dstinscarnet,
        CASE WHEN dvi.coddvi is NOT NULL THEN &apos;&apos;DVI&apos;&apos; WHEN nc.codnc is NOT NULL THEN &apos;&apos;NC&apos;&apos; WHEN cs.codcompens IS NOT NULL THEN &apos;&apos;PV&apos;&apos; ELSE COALESCE(intr.prefixdoc,ies.prefixdoc,t1s.doc) END dstinsprefix,
        COALESCE(dvi.nrdoc,intr.nrdoc,ies.nrdoc,t1s.nrdoc,nc.nrdoc,cs.nrdoc) dstinsnr, COALESCE(dvi.datadoc,intr.datadoc,ies.datadoc,t1s.datadoc,nc.datadoc,cs.datadoc) dstinsdata,
        COALESCE(intr.an,ies.an,t1s.an,nc.an,cs.an) dstinsan, COALESCE(intr.luna,ies.luna,t1s.luna,nc.luna,cs.luna) dstinsluna&apos;;
    ELSE
      sDocX  := &apos;,
        NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;;
    END IF;

    IF pOriceMoneda THEN
      fMonedaG   := &apos;&apos;;
      fMonedaI   := &apos;&apos;;
      fCurs      := &apos; Coalesce(tmp.curs, 1) &apos;;
    ELSE
      fCurs      := &apos; 1 &apos;;
      fMonedaG   := &apos;
        AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;
      fMonedaI   := &apos;
        AND Coalesce(I.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;
    END IF;

    IF bAduInfoCM AND pAnalitica THEN
      sqlInfoCM := &apos;
      UNION ALL
      SELECT
        0 issoldini, 0 codobligpif, i.tipdoc, i.codies coddoc, NULL coddoc1, i.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(i.moneda,0)&apos; END||&apos; moneda, i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri,
        aux.semn * i.valdoc valdoc, aux.semn * i.valdoc valdocbaza,
        i.curs, i.curs cursdoc,
        aux.semn * i.tvadoc tva, To_Char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) datadecont, i.agent, i.subunitatea,
        i.codlocatie, i.partener, 0 codcentru,
        aux.semn * 9999 semnificatie,
        0 icont, i.partener codpart, i.datadoc termen, 0 majorari,
        aux.semn * i.valdoc valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        ( SELECT vc2_nt_to_vc3200_dist (CAST(COLLECT(com.prefixdoc||&apos;&apos; &apos;&apos;||To_Char(com.nrdoc)||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY com.nrdoc, com.datadoc) AS vc2_nt))
          FROM iesiri1 i1
            LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
            LEFT JOIN ieslink ilcom ON ilcom.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilcom.codliniecomanda IS NOT NULL
            INNER JOIN comanda1 com1 ON com1.codcomanda1 = ilcom.codliniecomanda
            INNER JOIN comanda com ON com1.codcomanda = com.codcomanda
          WHERE i1.codies = i.codies
        ) ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;i.tipdoc dstinstipdoc, i.codies dstinscoddoc, i.seriadoc dstinsseria, i.carnetdoc dstinscarnet, i.prefixdoc dstinsprefix, i.nrdoc dstinsnr, i.datadoc dstinsdata, i.an dstinsan, i.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM iesiri i
        CROSS JOIN (SELECT CASE WHEN level = 1 THEN 1 ELSE -1 END semn FROM dual CONNECT BY level &lt;= 2) aux
      WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND Coalesce(i.INFOCM, 0) = 1 &apos;||
        CondSubunit(&apos;i.subunitatea&apos;)||
        fMonedaI||
        fPart(&apos;i.partener&apos;);
    END IF;

    IF aCodMoneda = -1 THEN
      sCursAjDep := &apos;*curs&apos;;
    END IF;

    sqlDocs :=&apos;
    WITH
    j   AS (SELECT DISTINCT CODDOC, TIPDOC, CODCENTRU, CODANALIZANOD FROM JURNAL),
    tmp AS (
      SELECT
        0 issoldini, xGIO.codobligpif, xGIO.tipdoc, xGIO.coddoc, NULL coddoc1, xGIO.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;xGIO.moneda&apos; END||&apos; moneda,
        xGIO.an, xGIO.luna, xGIO.datadoc, xGIO.carnetdoc, xGIO.seriadoc, xGIO.prefixdoc, xGIO.nrdoc, xGIO.nri,
        CASE
          WHEN xGIO.semnificatie IN (110,111) THEN xGIO.valoare - xGIO.tva
          ELSE xGIO.valdoc
        END valdoc,
        xGIO.valdoc valdocbaza,
        CASE
          WHEN xGIO.moneda = 0 THEN 1
          WHEN xGIO.semnificatie = 111 THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,xGIO.an, xGIO.luna),gs.curs)
          ELSE xGIO.curs
        END curs,
        CASE WHEN xGIO.moneda = 0 THEN 1 ELSE xGIO.curs END cursdoc,
        xGIO.TVA ,
        PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(xGIO.coddoc, xGIO.tipdoc) datadecont, 0 codpers, xGIO.subunitatea,
        xGIO.codlocatie, xGIO.partener, Coalesce(j.codcentru,0) codcentru,
        CASE
          WHEN xGIO.tipdoc = 9 AND xGIO.semnificatie = 140 THEN 101
          WHEN xGIO.tipdoc = 5 AND xGIO.tipfactura = 10 AND xGIO.semnificatie = 140 THEN 102
          ELSE xGIO.semnificatie
        END semnificatie,
        xGIO.icont, xGIO.codpart, xGIO.termen, xGIO.majorari,
        CASE
          WHEN xGIO.tipdoc = 9 AND xGIO.semnificatie = 140 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.tipdoc = 5 AND xGIO.tipfactura = 10 AND xGIO.semnificatie = 140 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.valoare = 0 THEN 0
          WHEN xGIO.semnificatie IN (110, 111) THEN xGIO.valoare - Coalesce(Nullif(xGIO.tva, xGIO.valoare),0)
          WHEN xGIO.semnificatie IN (120, 121) THEN xGIO.valoare - xGIO.tva
          ELSE xGIO.valoare
        END valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;istins.tipdoc dstinstipdoc, istins.codintr dstinscoddoc, istins.seriadoc dstinsseria, istins.carnetdoc dstinscarnet, istins.prefixdoc dstinsprefix, istins.nrdoc dstinsnr, istins.datadoc dstinsdata, istins.an dstinsan, istins.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM (
        SELECT
          g.semnificatie, g.tipdoc, g.coddoc, Coalesce(g.moneda,0) moneda,
          o.codobligpif, o.valoare, o.icont, o.codpart, Coalesce(o.termen, i.datadoc) termen, o.majorari, o.codcentru, o.codanalizanod,
          i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri, i.valdoc, i.obs,
          CASE WHEN CCL.VALOARE IS NOT NULL THEN g.curs ELSE i.curs END curs,
          i.subunitatea, i.codlocatie, i.partener, Coalesce(i.tipfactura,0) tipfactura,
          CASE
            WHEN (SELECT SUM(VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
            ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
          END TVA
        FROM GENERAL G
          INNER JOIN INTRARI        I   ON G.CODDOC     = I.CODINTR AND G.TIPDOC = I.TIPDOC
          INNER JOIN OBLIGPIF       O   ON O.CODGENERAL = G.CODGENERAL
          LEFT  JOIN TMP_CONSTANTE  CCL ON CCL.ANLUNA   = I.AN*12+I.LUNA AND CCL.SIMBOL = &apos;&apos;CONTABCURSLINIE&apos;&apos; AND CCL.VALOARE = &apos;&apos;1&apos;&apos;
        WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin||&apos;
          AND g.semnificatie NOT IN (130, 500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
          AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0
          AND NOT (g.semnificatie = 140 AND Coalesce(i.tipfactura, 0) = 9) &apos;||
          CondSubunit(&apos;i.subunitatea&apos;)||
          fMonedaG||
          fPart(&apos;Coalesce(o.codpart,0)&apos;)||&apos;
      ) xGIO
        LEFT JOIN J ON J.CODDOC = xGIO.CODDOC AND J.TIPDOC = xGIO.TIPDOC AND J.CODANALIZANOD = xGIO.CODANALIZANOD
        LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = xGIO.CODOBLIGPIF
        LEFT JOIN OBLIGPIF OS ON S.CODSTINSPIF = OS.CODOBLIGPIF
        LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        LEFT JOIN INTRARI ISTINS ON ISTINS.CODINTR = Coalesce(GS.CODDOC,xGIO.CODDOC) AND ISTINS.TIPDOC = Coalesce(GS.TIPDOC, xGIO.TIPDOC)
        LEFT JOIN TMP_FISAPART_OBLIG TMP ON TMP.CODOBLIGPIF = xGIO.CODOBLIGPIF
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, g.tipdoc, i.codintr coddoc, NULL coddoc1, i.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, i.an, i.luna, dvi.datadoc, i.carnetdoc, i.seriadoc, &apos;&apos;FE&apos;&apos; prefixdoc, dvi.nrdoc, i.nri,
        o.valoare valdoc, i.valdoc valdocbaza,
        g.curs, g.curs cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, i.subunitatea,
        i.codlocatie, dvi.codvama partener, Coalesce(j.codcentru,0) codcentru,
        o.semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, dvi.datadoc) termen, o.majorari,
        o.valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;i.tipdoc dstinstipdoc, i.codintr dstinscoddoc, i.seriadoc dstinsseria, i.carnetdoc dstinscarnet, &apos;&apos;DVI&apos;&apos; dstinsprefix, dvi.nrdoc dstinsnr, dvi.datadoc dstinsdata, i.an dstinsan, i.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM DVI
        INNER JOIN GENERAL G ON G.CODDOC = DVI.CODDVI AND G.TIPDOC = 5
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
        INNER JOIN INTRARI I ON i.CODINTR = DVI.CODINTR
        INNER JOIN J ON J.CODDOC = G.CODDOC AND J.TIPDOC = G.TIPDOC
      WHERE i.AN * 12 + i.LUNA BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND o.valoare &lt;&gt; 0
        AND g.semnificatie IN (130) &apos;||
        CondSubunit(&apos;i.subunitatea&apos;)||
        fMonedaG||
        fPart(&apos;Coalesce(dvi.codvama,0)&apos;)||&apos;
      UNION ALL
      SELECT
        0 issoldini, xGIO.codobligpif, xGIO.tipdoc, xGIO.coddoc, NULL coddoc1, xGIO.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;xGIO.moneda&apos; END||&apos; moneda,
        xGIO.an, xGIO.luna, xGIO.datadoc, xGIO.carnetdoc, xGIO.seriadoc, xGIO.prefixdoc, xGIO.nrdoc, xGIO.nri,
        --xGIO.valdoc,
        CASE
          WHEN xGIO.semnificatie IN (210,211) THEN xGIO.valoare - xGIO.tva
          ELSE xGIO.valdoc
        END valdoc,
        xGIO.valdoc valdocbaza,
        CASE
          WHEN xGIO.moneda = 0 THEN 1
          WHEN xGIO.semnificatie = 211 THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,xGIO.an, xGIO.luna),gs.curs)
          ELSE xGIO.curs
        END curs,
        CASE WHEN xGIO.moneda = 0 THEN 1 ELSE xGIO.curs END cursdoc,
        xGIO.TVA ,
        PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(xGIO.coddoc, xGIO.tipdoc) datadecont, xGIO.agent codpers, xGIO.subunitatea,
        xGIO.codlocatie, xGIO.partener, Coalesce(j.codcentru,0) codcentru,
        CASE WHEN xGIO.tipdoc = 26 AND xGIO.semnificatie = 240 THEN 201 ELSE xGIO.semnificatie END semnificatie,
        xGIO.icont, xGIO.codpart, xGIO.termen, xGIO.majorari,
        CASE
          WHEN xGIO.tipdoc = 26 AND xGIO.semnificatie = 240 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.semnificatie IN (210, 211, 220, 221) THEN xGIO.valoare-Coalesce(xGIO.tva, 0)
          ELSE xGIO.valoare
        END valoare,
        0 valoareifrs,
        CASE WHEN xGIO.tipfactura = 7 AND NOT xGIO.SEMNIFICATIE IN (210, 211) THEN xGIO.valdoc ELSE 0 END corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        ( SELECT vc2_nt_to_vc3200_dist (CAST(COLLECT(com.prefixdoc||&apos;&apos; &apos;&apos;||To_Char(com.nrdoc)||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY com.nrdoc, com.datadoc) AS vc2_nt))
          FROM iesiri1 i1
            LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
            LEFT JOIN ieslink ilcom ON ilcom.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilcom.codliniecomanda IS NOT NULL
            INNER JOIN comanda1 com1 ON com1.codcomanda1 = ilcom.codliniecomanda
            INNER JOIN comanda com ON com1.codcomanda = com.codcomanda
          WHERE i1.codies = xGIO.coddoc
        ) ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;istins.tipdoc dstinstipdoc, istins.codies dstinscoddoc, istins.seriadoc dstinsseria, istins.carnetdoc dstinscarnet, istins.prefixdoc dstinsprefix, istins.nrdoc dstinsnr, istins.datadoc dstinsdata, istins.an dstinsan, istins.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM (
        SELECT
          g.semnificatie, g.tipdoc, g.coddoc, Coalesce(g.moneda,0) moneda,
          o.codobligpif, o.valoare, o.icont, o.codpart, Coalesce(o.termen, i.datadoc) termen, o.majorari, o.codcentru, o.codanalizanod,
          i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri, i.valdoc, i.obs,
          CASE WHEN CCL.VALOARE IS NOT NULL THEN g.curs ELSE i.curs END curs,
          i.subunitatea, i.codlocatie,
          CASE WHEN Coalesce(i.partener,0)=0 AND i.tipdoc = 16 THEN o.codpart ELSE i.partener END partener,
          Coalesce(i.tipfactura,0) tipfactura, i.agent,
          CASE
            WHEN (SELECT SUM(VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
            ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
          END TVA
        FROM GENERAL G
          INNER JOIN IESIRI         I   ON G.CODDOC     = I.CODIES AND G.TIPDOC = I.TIPDOC
          INNER JOIN OBLIGPIF       O   ON O.CODGENERAL = G.CODGENERAL
          LEFT  JOIN TMP_CONSTANTE  CCL ON CCL.ANLUNA   = I.AN*12+I.LUNA AND CCL.SIMBOL = &apos;&apos;CONTABCURSLINIE&apos;&apos; AND CCL.VALOARE = &apos;&apos;1&apos;&apos;
        WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
          AND NOT (G.SEMNIFICATIE = 240 AND Coalesce(I.CUSTODIE,0) = 1)
          AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND Coalesce(i.INFOCM, 0) = 0 &apos;||
          CondSubunit(&apos;i.subunitatea&apos;)||
          fMonedaG||
          fPart(&apos;CASE WHEN Coalesce(i.partener,0)=0 AND i.tipdoc = 16 THEN Coalesce(o.codpart,0) ELSE Coalesce(i.partener,0) END&apos;)||&apos;
      ) xGIO
        INNER JOIN J ON J.CODDOC = xGIO.CODDOC AND J.TIPDOC = xGIO.TIPDOC
        LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = xGIO.CODOBLIGPIF
        LEFT JOIN OBLIGPIF OS ON S.CODSTINSPIF = OS.CODOBLIGPIF
        LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        LEFT JOIN IESIRI ISTINS ON ISTINS.CODIES = Coalesce(gs.CODDOC,xGIO.CODDOC) AND ISTINS.TIPDOC = Coalesce(gs.TIPDOC, xGIO.TIPDOC)
        LEFT JOIN TMP_FISAPART_OBLIG tmp ON tmp.CODOBLIGPIF = xGIO.CODOBLIGPIF&apos;||
      sqlInfoCM||&apos;
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, g.tipdoc, nc.codnc coddoc, nc1.codnc1 coddoc1, nc.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, nc.an, nc.luna, nc.datadoc, nc.carnetdoc, NULL seriadoc, &apos;&apos;NC&apos;&apos; prefixdoc, nc.nrdoc, &apos;&apos; &apos;&apos; nri,
        nc.valoare valdoc, nc.valoare valdocbaza,
        CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE Coalesce(Nullif(g.curs,0), 1) END curs,
        CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE Coalesce(Nullif(g.curs,0), 1) END cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, nc.subunitatea,
        0 codlocatie, CASE WHEN Coalesce(nc1.codpart,0) = 0 THEN Coalesce(nc.part,0) ELSE nc1.codpart END partener, Coalesce(j.codcentru,0) codcentru,
        o.semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, nc.datadoc) termen, o.majorari,
        case when g.semnificatie IN (1250,1251) then 0 else o.valoare end valoare,
        case when g.semnificatie IN (1250,1251) then o.valoare else 0 end valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, nc.carnetdoc dstinscarnet, &apos;&apos;NC&apos;&apos; dstinsprefix, nc.nrdoc dstinsnr, nc.datadoc dstinsdata, nc.an dstinsan, nc.luna dstinsluna&apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM general g
        INNER JOIN NC1 ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35
        INNER JOIN NC  ON NC.CODNC = NC1.CODNC
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
        INNER JOIN J ON J.CODDOC = G.CODDOC AND J.TIPDOC = G.TIPDOC
      WHERE NC.an * 12 + NC.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101) &apos;||
        CondSubunit(&apos;nc.subunitatea&apos;)||
        fMonedaG||
        fPart(&apos;CASE WHEN Coalesce(nc1.codpart,0) = 0 THEN Coalesce(nc.part,0) ELSE nc1.codpart END&apos;)||&apos;
      UNION ALL
      SELECT
        0 issoldini, codobligpif, tipdoc, coddoc, NULL coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, NULL seriadoc, &apos;&apos;PV&apos;&apos; prefixdoc, nrdoc, &apos;&apos; &apos;&apos; nri,
        SUM(valdoc) valdoc,
        ( SELECT SUM(Coalesce(GX.CURS,1)*(Coalesce(ox.dincaretva,0)+Coalesce(ox.valoare,0)))
          FROM GENERAL GX INNER JOIN OBLIGPIF OX ON OX.CODGENERAL = GX.CODGENERAL
          WHERE GX.TIPDOC = 28 AND GX.CODDOC = subs.CODDOC AND GX.SEMNIFICATIE IN (1350, 1351, 1352, 1353)
        ) valdocbaza,
        curs, cursdoc,
        tva, datadecont, 0 codpers, subunitatea,
        codlocatie, partener, codcentru,
        semnificatie,
        icont, codpart, Min(termen) termen, majorari,
        valoare,
        SUM(valoareifrs) valoareifrs,
        0 corectie,
        CASE WHEN SEMN_AJDEP =  1 THEN 0 ELSE VAL_AJDEP END&apos;||sCursAjDep||&apos; DEBIT_AJDEP, CASE WHEN SEMN_AJDEP = -1 THEN 0 ELSE VAL_AJDEP END&apos;||sCursAjDep||&apos; CREDIT_AJDEP, SEMN_AJDEP*VAL_AJDEP&apos;||sCursAjDep||&apos; SOLD_AJDEP,
        NULL ComCli,
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
      FROM (
        SELECT
          o.codobligpif, g.tipdoc, g.coddoc, c.obsd||&apos;&apos;; &apos;&apos;||c.obsc obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, c.an, c.luna, c.datadoc, c.carnetdoc, c.nrdoc,
          CASE WHEN o.semnificatie IN (1351) AND o.icont IN (6) THEN -1 ELSE 1 END * (Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)) valdoc,
          CASE
            WHEN COALESCE(gs.moneda, g.moneda, 0) = 0 THEN 1
            WHEN g.semnificatie IN (1301, 1303, 1350, 1351) THEN COALESCE(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,c.an,c.luna), gs.curs, g.curs, 1)
            ELSE Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,c.an,c.luna), gs.curs)
          END curs,
          CASE
            WHEN Coalesce(g.moneda,0) = 0 THEN 1
            ELSE Coalesce(Nullif(g.curs,0), 1)
          END cursdoc,
          Coalesce(g.tva,0) tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, &apos;||CASE WHEN bSubStins THEN &apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea,c.subunitatea)&apos; ELSE &apos;c.subunitatea&apos; END ||&apos; subunitatea,
          &apos;||sLocatieC||&apos; codlocatie, o.codpart partener, Coalesce(j.codcentru,0) codcentru,
          o.semnificatie,
          o.icont, o.codpart, Coalesce(o.termen, c.datadoc) termen, o.majorari,
          CASE
            WHEN o.semnificatie IN (1300) AND o.icont IN (4, 12) AND Coalesce(C.TipCompens,0) IN (5) THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)+Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND o.icont IN (    5) AND Coalesce(C.TipCompens,0) IN (5) THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1300)                                                            THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND os.semnificatie IN (410)                               THEN -(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND os.semnificatie not IN (1303, 1302)                    THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1351) AND o.icont IN (6)                                         THEN -(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))
            ELSE                                                                                          +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))
          END VALOARE,
          pkg_list_base_fisaanalitikpart.getTrezIFRS(gs.codGeneral, g.Moneda, Coalesce(s.dincaretva,0)+Coalesce(s.valoare,0), c.An*12+c.Luna-1) valoareifrs,
          CASE
            WHEN Coalesce(C.TipCompens,0) = 2 THEN -1
            WHEN Coalesce(C.TipCompens,0) = 3 AND Coalesce(CS.TipCompens,0) = 1 THEN -1
            WHEN Coalesce(C.TipCompens,0) IN (1,3,4) THEN 1
            ELSE 0
          END SEMN_AJDEP,
          (Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))*Coalesce(O.CoefProvizion,0) VAL_AJDEP&apos;||
          sDocX||&apos;
        FROM general g
          INNER JOIN compens c ON g.coddoc = c.codcompens
          INNER JOIN obligpif o on o.codgeneral = g.codgeneral
          INNER JOIN J ON J.CODDOC = G.CODDOC AND J.TIPDOC = G.TIPDOC
          LEFT JOIN stingere s on s.codstingatorpif = o.codobligpif
          LEFT JOIN obligpif os on os.codobligpif = s.codstinspif
          LEFT JOIN general gs on gs.codgeneral = os.codgeneral
          LEFT JOIN dvi on dvi.coddvi = gs.coddoc AND gs.tipdoc = 5 AND gs.semnificatie = 130
          LEFT JOIN intrari intr ON intr.codintr = Coalesce(dvi.codintr,gs.coddoc) AND intr.tipdoc = gs.tipdoc
          LEFT JOIN iesiri ies ON ies.codies = gs.coddoc AND ies.tipdoc = gs.tipdoc
          LEFT JOIN trezor1 t1s ON t1s.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29, 30, 31, 33)
          LEFT JOIN trezor ts ON ts.codtrezor = t1s.codtrezor
          LEFT JOIN nc1 on nc1.codnc1 = gs.coddoc AND gs.tipdoc = 35
          LEFT JOIN nc on nc.codnc = nc1.codnc
          LEFT JOIN compens cs ON cs.codcompens = CASE WHEN gs.tipdoc = 28 THEN gs.coddoc WHEN gs.codgeneral IS NULL THEN c.codcompens END
        WHERE g.tipdoc = 28 AND c.an * 12 + c.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101, 1302, 1352)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9) &apos;||
          CondSubunitSting(&apos;c.subunitatea&apos;,&apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea)&apos;)||
          fMonedaG||
          fPart(&apos;Coalesce(o.codpart,0)&apos;)||&apos;
      ) subs
      GROUP BY
        codobligpif, tipdoc, coddoc, obs, moneda, an, luna, datadoc, carnetdoc, nrdoc, curs, cursdoc, tva, datadecont, subunitatea, codlocatie, partener, codcentru, semnificatie, icont, codpart, majorari, valoare,
        semn_ajdep, val_ajdep, dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna&apos;;

    IF pOriceMoneda AND pSUBUNIT &gt; 0 THEN
      sqlDocs := sqlDocs ||&apos;
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, reg.tipreg tipdoc, reg.codreg coddoc, NULL coddoc1, reg.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, reg.an, reg.luna, reg.datadoc, NULL carnetdoc, NULL seriadoc,
        &apos;&apos;Reg.&apos;&apos;||
        CASE
          WHEN dvi.coddvi is not NULL THEN &apos;&apos;DVI&apos;&apos;||dvi.nrdoc||&apos;&apos;/&apos;&apos;||to_char(dvi.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN intr.codintr is not NULL THEN intr.prefixdoc||intr.nrdoc||&apos;&apos;/&apos;&apos;||to_char(intr.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN ies.codies is not NULL THEN ies.prefixdoc||ies.nrdoc||&apos;&apos;/&apos;&apos;||to_char(ies.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN t1s.codtrezor1 is not NULL THEN t1s.doc||t1s.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1s.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN cs.codcompens is not NULL THEN &apos;&apos;PV&apos;&apos;||cs.nrdoc||&apos;&apos;/&apos;&apos;||to_char(cs.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN nc.codnc is not NULL THEN &apos;&apos;NC&apos;&apos;||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          ELSE NULL
        END prefixdoc,
        reg.nrdoc, &apos;&apos; &apos;&apos; nri,
        reg1.solddocval valdoc, reg1.solddocreg - reg1.solddocval valdocbaza,
        reg1.curs,
        reg1.curs cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, COALESCE(nc.subunitatea, cs.subunitatea, ts.subunitatea, ies.subunitatea, intr.subunitatea) subunitatea,
        COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0) codlocatie, o.codpart, Coalesce(o.codcentru,0) codcentru,
        CASE
          WHEN o.semnificatie NOT IN (1200, 1201, 430, 330) THEN Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1200 AND o.icont IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN  Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1201 AND o.icont IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN -Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1200 AND o.icont IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;)    THEN -Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1201 AND o.icont IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;)    THEN  Sign(reg1.solddocreg - reg1.solddocval)
          ELSE - Sign(reg1.solddocreg - reg1.solddocval)
        END * o.semnificatie semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, reg.datadoc) termen, o.majorari,
        ABS(reg1.solddocreg - reg1.solddocval) valoare,
        pkg_list_base_fisaanalitikpart.getreg1ifrs(reg1.codGeneral, reg1.solddoc*(Reg.Curs_IFRS - Reg.Curs), reg.An*12+reg.Luna-1, Coalesce(Reg.Curs_IFRS,0), Reg1.SoldDoc) as valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli&apos;||
        sDocX||&apos;
      FROM reg
        INNER JOIN reg1 on reg.codreg = reg1.codreg
        INNER JOIN general g on g.codgeneral = reg1.codgeneral
        INNER JOIN obligpif o on o.codgeneral = g.codgeneral AND o.icont = reg1.cont AND o.codobligpif = Coalesce(reg1.codobligpif,o.codobligpif)
        LEFT JOIN dvi on dvi.coddvi = g.coddoc AND g.tipdoc = 5 AND g.semnificatie = 130
        LEFT JOIN intrari intr on intr.codintr = Coalesce(dvi.codintr, g.coddoc) AND intr.tipdoc = g.tipdoc
        LEFT JOIN iesiri ies on ies.codies = g.coddoc AND ies.tipdoc = g.tipdoc
        LEFT JOIN trezor1 t1s ON t1s.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
        LEFT JOIN trezor ts ON ts.codtrezor = t1s.codtrezor
        LEFT JOIN nc1 on nc1.codnc1 = g.coddoc AND g.tipdoc = 35
        LEFT JOIN nc on nc.codnc = nc1.codnc
        LEFT JOIN compens cs ON cs.codcompens = g.coddoc AND g.tipdoc = 28
      WHERE reg.tipreg = 46 AND reg.an*12 + reg.luna BETWEEN &apos;||g_lunaIni||&apos; AND &apos;||g_lunaFin||
        fMonedaG||
        fPart(&apos;Coalesce(o.codpart,0)&apos;)||
        CondSubunit(&apos;COALESCE(nc.subunitatea, cs.subunitatea, ts.subunitatea, ies.subunitatea, intr.subunitatea)&apos;);
    END IF;

    sqldocs := sqldocs ||&apos;
      UNION ALL
      SELECT
        0 issoldini, Max(codobligpif) codobligpif, tipdoc, coddoc, coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, seriedoc, doc, nrdoc, nri,
        SUM(valdoc) valdoc, valdocbaza,
        curs, cursdoc, tva, datadecont, codpers, subunitatea,
        codlocatie, codpart, codcentru,
        semnificatie, icont, partener, Min(termen) termen, majorari,
        SUM(VALOARE) VALOARE,
        SUM(valoareifrs) valoareifrs,
        0 corectie,
        Sum(VAL_AJDEP)&apos;||sCursAjDep||&apos; DEBIT_AJDEP,
        0 CREDIT_AJDEP,
        -Sum(VAL_AJDEP)&apos;||sCursAjDep||&apos; SOLD_AJDEP,
        NULL ComCli,
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
      FROM (
        SELECT
          o.codobligpif, g.tipdoc, t.codtrezor coddoc, t1.codtrezor1 coddoc1, t1.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, t.an, t.luna, t1.datadoc, t1.carnetdoc, t1.seriedoc, t1.doc, t1.nrdoc, t1.nri,
          CASE WHEN Coalesce(t1.platatva,0) = 1 THEN o.dincaretva ELSE o.valoare END valdoc, t1.valdoc valdocbaza,
          CASE
            WHEN Coalesce(g.moneda,0) = 0 THEN 1
            WHEN o.semnificatie IN (320, 420) THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,t.an,t.luna),gs.curs)
            ELSE g.curs
          END curs,
          CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE g.curs END cursdoc,
          Coalesce(g.tva,0) tva, CASE WHEN g.tipdoc = 31 THEN PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) ELSE To_Char(t1.datadecont,&apos;&apos;dd.mm.yyyy&apos;&apos;) END datadecont,
          Coalesce(t1.agent, t.agent) codpers, &apos;||CASE WHEN bSubStins THEN &apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea,t.subunitatea)&apos; ELSE &apos;t.subunitatea&apos; END ||&apos; subunitatea,
          &apos;||sLocatieT1||&apos; codlocatie, t1.codpart partener, Coalesce(Nullif(j.codcentru,0),js.codcentru) codcentru,
          o.semnificatie, o.icont, o.codpart, Coalesce(t1.datadecont, o.termen, t1.datadoc) termen, o.majorari,
          CASE WHEN Coalesce(t1.platatva,0) = 1 THEN o.dincaretva WHEN o.semnificatie IN (310, 410, 320, 420, 330, 430) THEN o.valoare - Coalesce(g.tva, 0) ELSE o.valoare END VALOARE,
          pkg_list_base_fisaanalitikpart.getTrezIFRS(gs.codGeneral, g.Moneda, s.Valoare, t.An*12+t.Luna-1) valoareifrs,
          s.Valoare* Coalesce(os.coefprovizion,0)*CASE WHEN Coalesce(CS.TipCompens,0) IN (1,3,4) THEN 1 ELSE 0 END VAL_AJDEP&apos;||
          sDocX||&apos;
        FROM trezor t
          INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
          INNER JOIN general g ON g.coddoc = t1.codtrezor1 AND g.tipdoc = t.tipdoc
          INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
          INNER JOIN (SELECT DISTINCT CODDOC, INDEXLOCAL, TIPDOC, CODCENTRU FROM JURNAL WHERE TIPDOC IN (29,30,31)) J ON J.CODDOC = T.CODTREZOR AND J.TIPDOC = G.TIPDOC AND J.INDEXLOCAL = T1.CODTREZOR1
          LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = O.CODOBLIGPIF
          LEFT JOIN OBLIGPIF os ON os.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL gs ON gs.CODGENERAL = os.CODGENERAL
          LEFT JOIN (SELECT DISTINCT CODDOC, TIPDOC, CODCENTRU FROM JURNAL) JS ON JS.CODDOC = GS.CODDOC AND JS.TIPDOC = GS.TIPDOC
          LEFT JOIN DVI ON DVI.CODDVI = gs.CODDOC AND gs.TIPDOC = 5 AND gs.SEMNIFICATIE = 130
          LEFT JOIN INTRARI INTR ON INTR.CODINTR = Coalesce(DVI.CODINTR,gs.CODDOC) AND INTR.TIPDOC = gs.TIPDOC
          LEFT JOIN IESIRI IES ON IES.CODIES = gs.CODDOC AND IES.TIPDOC = gs.TIPDOC
          LEFT JOIN TREZOR1 T1S ON T1S.CODTREZOR1 = CASE WHEN gs.codgeneral IS NULL THEN t1.codtrezor1 WHEN gs.TIPDOC IN (29, 30, 31, 33) THEN gs.CODDOC END
          LEFT JOIN TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
          LEFT JOIN COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
          LEFT JOIN NC1 ON NC1.CODNC1 = GS.CODDOC AND GS.TIPDOC = 35
          LEFT JOIN NC ON NC.CODNC = NC1.CODNC
        WHERE t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
          AND t.an * 12 + t.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9)
          AND NOT EXISTS (SELECT S.CODSTINGATORPIF FROM STINGERE S INNER JOIN OBLIGPIF OB ON S.CODSTINSPIF = OB.CODOBLIGPIF WHERE OB.SEMNIFICATIE IN (500, 600) AND O.CODOBLIGPIF = S.CODSTINGATORPIF ) &apos;||
          CondSubunitSting(&apos;t.subunitatea&apos;,&apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea)&apos;)||
          fMonedaG||
          fPart(&apos;Coalesce(t1.codpart,0)&apos;)||&apos;
      )
      GROUP BY
        tipdoc, coddoc, coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, seriedoc, doc, nrdoc, nri, valdocbaza, curs, cursdoc, tva, datadecont, codpers, subunitatea, codlocatie, partener, codcentru, semnificatie, icont, codpart, majorari,
        val_ajdep, dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
    ) &apos;;
  else
    IF bDefalcLoc THEN
      sLocatieT1 := &apos;COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0)&apos;;
      sLocatieC  := &apos;COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0)&apos;;
    ELSE
      sLocatieT1 := &apos;COALESCE(t1.codlocatie, 0)&apos;;
      sLocatieC  := &apos;0&apos;;
    END IF;

    IF bDefalcDoc AND pAnalitica THEN
      sDocX := &apos;,
        COALESCE(intr.tipdoc,ies.tipdoc,ts.tipdoc) dstinstipdoc, COALESCE(intr.codintr,ies.codies,t1s.codtrezor1) dstinscoddoc,
        COALESCE(intr.seriadoc,ies.seriadoc,t1s.seriedoc) dstinsseria, COALESCE(intr.carnetdoc,ies.carnetdoc,t1s.carnetdoc,nc.carnetdoc,cs.carnetdoc) dstinscarnet,
        CASE WHEN dvi.coddvi is NOT NULL THEN &apos;&apos;DVI&apos;&apos; WHEN nc.codnc is NOT NULL THEN &apos;&apos;NC&apos;&apos; WHEN cs.codcompens IS NOT NULL THEN &apos;&apos;PV&apos;&apos; ELSE COALESCE(intr.prefixdoc,ies.prefixdoc,t1s.doc) END dstinsprefix,
        COALESCE(dvi.nrdoc,intr.nrdoc,ies.nrdoc,t1s.nrdoc,nc.nrdoc,cs.nrdoc) dstinsnr, COALESCE(dvi.datadoc,intr.datadoc,ies.datadoc,t1s.datadoc,nc.datadoc,cs.datadoc) dstinsdata,
        COALESCE(intr.an,ies.an,t1s.an,nc.an,cs.an) dstinsan, COALESCE(intr.luna,ies.luna,t1s.luna,nc.luna,cs.luna) dstinsluna&apos;;
      sDocXGroup := &apos;,
        COALESCE(intr.tipdoc,ies.tipdoc,ts.tipdoc), COALESCE(intr.codintr,ies.codies,t1s.codtrezor1),
        COALESCE(intr.seriadoc,ies.seriadoc,t1s.seriedoc), COALESCE(intr.carnetdoc,ies.carnetdoc,t1s.carnetdoc,nc.carnetdoc,cs.carnetdoc),
        CASE WHEN dvi.coddvi is NOT NULL THEN &apos;&apos;DVI&apos;&apos; WHEN nc.codnc is NOT NULL THEN &apos;&apos;NC&apos;&apos; WHEN cs.codcompens is NOT NULL THEN &apos;&apos;PV&apos;&apos; ELSE COALESCE(intr.prefixdoc,ies.prefixdoc,t1s.doc) END,
        COALESCE(dvi.nrdoc,intr.nrdoc,ies.nrdoc,t1s.nrdoc,nc.nrdoc,cs.nrdoc), COALESCE(dvi.datadoc,intr.datadoc,ies.datadoc,t1s.datadoc,nc.datadoc,cs.datadoc),
        COALESCE(intr.an,ies.an,t1s.an,nc.an,cs.an), COALESCE(intr.luna,ies.luna,t1s.luna,nc.luna,cs.luna)&apos;;
    ELSE
      sDocX  := &apos;,
        NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;;
      sDocXGroup := &apos;&apos;;
    END IF;

    IF pOriceMoneda THEN
      fMonedaG   := &apos;&apos;;
      fMonedaI   := &apos;&apos;;
      fCurs      := &apos; Coalesce(tmp.curs, 1) &apos;;
    ELSE
      fCurs      := &apos; 1 &apos;;
      fMonedaG   := &apos;
        AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;
      fMonedaI   := &apos;
        AND Coalesce(I.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;
    END IF;

    IF bAduInfoCM AND pAnalitica THEN
      sqlInfoCM := &apos;
      UNION ALL
      SELECT
        0 issoldini, 0 codobligpif, i.tipdoc, i.codies coddoc, NULL coddoc1, i.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(i.moneda,0)&apos; END||&apos; moneda, i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri,
        aux.semn * i.valdoc valdoc, aux.semn * i.valdoc valdocbaza,
        i.curs, i.curs cursdoc,
        aux.semn * i.tvadoc tva, To_Char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) datadecont, i.agent, i.subunitatea,
        i.codlocatie, i.partener, 0 codcentru,
        aux.semn * 9999 semnificatie,
        0 icont, i.partener codpart, i.datadoc termen, 0 majorari,
        aux.semn * i.valdoc valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        ( SELECT vc2_nt_to_vc3200_dist (CAST(COLLECT(com.prefixdoc||&apos;&apos; &apos;&apos;||To_Char(com.nrdoc)||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY com.nrdoc, com.datadoc) AS vc2_nt))
          FROM iesiri1 i1
            LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
            LEFT JOIN ieslink ilcom ON ilcom.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilcom.codliniecomanda IS NOT NULL
            INNER JOIN comanda1 com1 ON com1.codcomanda1 = ilcom.codliniecomanda
            INNER JOIN comanda com ON com1.codcomanda = com.codcomanda
          WHERE i1.codies = i.codies
        ) ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;i.tipdoc dstinstipdoc, i.codies dstinscoddoc, i.seriadoc dstinsseria, i.carnetdoc dstinscarnet, i.prefixdoc dstinsprefix, i.nrdoc dstinsnr, i.datadoc dstinsdata, i.an dstinsan, i.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM iesiri i
        CROSS JOIN (SELECT CASE WHEN level = 1 THEN 1 ELSE -1 END semn FROM dual CONNECT BY level &lt;= 2) aux
      WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND Coalesce(i.INFOCM, 0) = 1 &apos;||
        CondSubunit(&apos;i.subunitatea&apos;)||
        fMonedaI||
        fPart(&apos;i.partener&apos;);
    END IF;

    sqlDocs :=&apos;
    WITH
    tmp AS (
      SELECT
        0 issoldini, xGIO.codobligpif, xGIO.tipdoc, xGIO.coddoc, NULL coddoc1, xGIO.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(xGIO.moneda,0)&apos; END||&apos; moneda,
				xGIO.an, xGIO.luna, xGIO.datadoc, xGIO.carnetdoc, xGIO.seriadoc, xGIO.prefixdoc, xGIO.nrdoc, xGIO.nri,
        CASE
  				WHEN xGIO.semnificatie IN (110,111) THEN xGIO.valoare - xGIO.tva
					ELSE xGIO.valdoc
  			END valdoc,
				xGIO.valdoc valdocbaza,
        CASE
          WHEN Coalesce(xGIO.moneda,0) = 0 THEN 1
          WHEN xGIO.semnificatie = 111 THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,xGIO.an, xGIO.luna),gs.curs)
          ELSE xGIO.curs
        END curs,
        CASE WHEN Coalesce(xGIO.moneda,0) = 0 THEN 1 ELSE xGIO.curs END cursdoc,
        xGIO.TVA,
				PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(xGIO.coddoc, xGIO.tipdoc) datadecont, 0 codpers, xGIO.subunitatea,
        xGIO.codlocatie, xGIO.partener, Coalesce(xGIO.codcentru,0) codcentru,
        CASE
          WHEN xGIO.tipdoc = 9 AND xGIO.semnificatie = 140 THEN 101
          WHEN xGIO.tipdoc = 5 AND Coalesce(xGIO.tipfactura, 0) = 10 AND xGIO.semnificatie = 140 THEN 102
          ELSE xGIO.semnificatie
        END semnificatie,
        xGIO.icont, xGIO.codpart, Coalesce(xGIO.termen, xGIO.datadoc) termen, xGIO.majorari,
        CASE
          WHEN xGIO.tipdoc = 9 AND xGIO.semnificatie = 140 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.tipdoc = 5 AND Coalesce(xGIO.tipfactura, 0) = 10 AND xGIO.semnificatie = 140 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.valoare = 0 THEN 0
          WHEN xGIO.semnificatie IN (110, 111) THEN xGIO.valoare - Coalesce(Nullif(xGIO.tva, xGIO.valoare),0)
          WHEN xGIO.semnificatie IN (120, 121) THEN xGIO.valoare - xGIO.tva
          ELSE xGIO.valoare
        END valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;istins.tipdoc dstinstipdoc, istins.codintr dstinscoddoc, istins.seriadoc dstinsseria, istins.carnetdoc dstinscarnet, istins.prefixdoc dstinsprefix, istins.nrdoc dstinsnr, istins.datadoc dstinsdata, istins.an dstinsan, istins.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM (
        SELECT
          g.semnificatie, g.tipdoc, g.coddoc, Coalesce(g.moneda,0) moneda,
          o.codobligpif, o.valoare, o.icont, o.codpart, Coalesce(o.termen, i.datadoc) termen, o.majorari, o.codcentru,
          i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri, i.valdoc, i.obs,
          CASE WHEN CCL.VALOARE IS NOT NULL THEN g.curs ELSE i.curs END curs,
          i.subunitatea, i.codlocatie, i.partener, Coalesce(i.tipfactura,0) tipfactura,
          CASE
            WHEN (SELECT SUM(VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
            ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
          END TVA
        FROM GENERAL G
          INNER JOIN INTRARI        I   ON G.CODDOC     = I.CODINTR AND G.TIPDOC = I.TIPDOC
          INNER JOIN OBLIGPIF       O   ON O.CODGENERAL = G.CODGENERAL
          LEFT  JOIN TMP_CONSTANTE  CCL ON CCL.ANLUNA   = I.AN*12+I.LUNA AND CCL.SIMBOL = &apos;&apos;CONTABCURSLINIE&apos;&apos; AND CCL.VALOARE = &apos;&apos;1&apos;&apos;
				WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin||&apos;
					AND g.semnificatie NOT IN (130, 500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
					AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0
					AND NOT (g.semnificatie = 140 AND Coalesce(i.tipfactura, 0) = 9) &apos;||
					CondSubunit(&apos;i.subunitatea&apos;)||
					fMonedaG||
					fPart(&apos;Coalesce(o.codpart,0)&apos;)||&apos;
				) xGIO
        LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = xGIO.CODOBLIGPIF
        LEFT JOIN OBLIGPIF OS ON S.CODSTINSPIF = OS.CODOBLIGPIF
        LEFT JOIN GENERAL gs ON gs.CODGENERAL = OS.CODGENERAL
        LEFT JOIN INTRARI ISTINS ON ISTINS.CODINTR = Coalesce(gs.CODDOC,xGIO.CODDOC) AND ISTINS.TIPDOC = Coalesce(gs.TIPDOC, xGIO.TIPDOC)
        LEFT JOIN TMP_FISAPART_OBLIG tmp ON tmp.CODOBLIGPIF = xGIO.CODOBLIGPIF
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, g.tipdoc, i.codintr coddoc, NULL coddoc1, i.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, i.an, i.luna, dvi.datadoc, i.carnetdoc, i.seriadoc, &apos;&apos;FE&apos;&apos; prefixdoc, dvi.nrdoc, i.nri,
        o.valoare valdoc, i.valdoc valdocbaza,
        g.curs,
        g.curs cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, i.subunitatea,
        i.codlocatie, dvi.codvama partener, Coalesce(o.codcentru,0) codcentru,
        o.semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, dvi.datadoc) termen, o.majorari,
        o.valoare,
        0 valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;i.tipdoc dstinstipdoc, i.codintr dstinscoddoc, i.seriadoc dstinsseria, i.carnetdoc dstinscarnet, &apos;&apos;DVI&apos;&apos; dstinsprefix, dvi.nrdoc dstinsnr, dvi.datadoc dstinsdata, i.an dstinsan, i.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM DVI
        INNER JOIN GENERAL G ON G.CODDOC = DVI.CODDVI AND G.TIPDOC = 5
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
        INNER JOIN INTRARI I ON i.CODINTR = DVI.CODINTR
      WHERE i.AN * 12 + i.LUNA BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND o.valoare &lt;&gt; 0
        AND g.semnificatie IN (130) &apos;||
        CondSubunit(&apos;i.subunitatea&apos;)||
        fMonedaG||
        fPart(&apos;Coalesce(dvi.codvama,0)&apos;)||&apos;
      UNION ALL
      SELECT
        0 issoldini, xGIO.codobligpif, xGIO.tipdoc, xGIO.coddoc, NULL coddoc1, xGIO.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;xGIO.moneda&apos; END||&apos; moneda,
        xGIO.an, xGIO.luna, xGIO.datadoc, xGIO.carnetdoc, xGIO.seriadoc, xGIO.prefixdoc, xGIO.nrdoc, xGIO.nri,
        --xGIO.valdoc,
        CASE
  				WHEN xGIO.semnificatie IN (210,211) THEN xGIO.valoare - xGIO.tva
					ELSE xGIO.valdoc
  			END valdoc,
        xGIO.valdoc valdocbaza,
        CASE
          WHEN xGIO.moneda = 0 THEN 1
          WHEN xGIO.semnificatie = 211 THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,xGIO.an, xGIO.luna),gs.curs)
          ELSE xGIO.curs
        END curs,
        CASE WHEN xGIO.moneda = 0 THEN 1 ELSE xGIO.curs END cursdoc,
        xGIO.TVA ,
        PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(xGIO.coddoc, xGIO.tipdoc) datadecont, xGIO.agent codpers, xGIO.subunitatea,
        xGIO.codlocatie, xGIO.partener, Coalesce(xGIO.codcentru,0) codcentru,
        CASE WHEN xGIO.tipdoc = 26 AND xGIO.semnificatie = 240 THEN 201 ELSE xGIO.semnificatie END semnificatie,
        xGIO.icont, xGIO.codpart, xGIO.termen, xGIO.majorari,
        CASE
          WHEN xGIO.tipdoc = 26 AND xGIO.semnificatie = 240 THEN Coalesce(tmp.valoare, xGIO.valoare)
          WHEN xGIO.semnificatie IN (210, 211, 220, 221) THEN xGIO.valoare-Coalesce(xGIO.tva, 0)
          ELSE xGIO.valoare
        END valoare,
        0 valoareifrs,
        CASE WHEN xGIO.tipfactura = 7 AND NOT xGIO.SEMNIFICATIE IN (210, 211) THEN xGIO.valdoc ELSE 0 END corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        ( SELECT vc2_nt_to_vc3200_dist (CAST(COLLECT(com.prefixdoc||&apos;&apos; &apos;&apos;||To_Char(com.nrdoc)||&apos;&apos;/&apos;&apos;||To_Char(com.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY com.nrdoc, com.datadoc) AS vc2_nt))
          FROM iesiri1 i1
            LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1 AND ilae.codlinieaviz IS NOT NULL
            LEFT JOIN ieslink ilcom ON ilcom.codies1 = Coalesce(ilae.codlinieaviz, i1.codies1) AND ilcom.codliniecomanda IS NOT NULL
            INNER JOIN comanda1 com1 ON com1.codcomanda1 = ilcom.codliniecomanda
            INNER JOIN comanda com ON com1.codcomanda = com.codcomanda
          WHERE i1.codies = xGIO.coddoc
        ) ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;istins.tipdoc dstinstipdoc, istins.codies dstinscoddoc, istins.seriadoc dstinsseria, istins.carnetdoc dstinscarnet, istins.prefixdoc dstinsprefix, istins.nrdoc dstinsnr, istins.datadoc dstinsdata, istins.an dstinsan, istins.luna dstinsluna &apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM (
        SELECT
          g.semnificatie, g.tipdoc, g.coddoc, Coalesce(g.moneda,0) moneda,
          o.codobligpif, o.valoare, o.icont, o.codpart, Coalesce(o.termen, i.datadoc) termen, o.majorari, o.codcentru, o.codanalizanod,
          i.an, i.luna, i.datadoc, i.carnetdoc, i.seriadoc, i.prefixdoc, i.nrdoc, i.nri, i.valdoc, i.obs,
          CASE WHEN CCL.VALOARE IS NOT NULL THEN g.curs ELSE i.curs END curs,
          i.subunitatea, i.codlocatie,
          CASE WHEN Coalesce(i.partener,0)=0 AND i.tipdoc = 16 THEN o.codpart ELSE i.partener END partener,
          Coalesce(i.tipfactura,0) tipfactura, i.agent,
          CASE
            WHEN (SELECT SUM(VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
            ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
          END TVA
        FROM GENERAL G
          INNER JOIN IESIRI         I   ON G.CODDOC     = I.CODIES AND G.TIPDOC = I.TIPDOC
          INNER JOIN OBLIGPIF       O   ON O.CODGENERAL = G.CODGENERAL
          LEFT  JOIN TMP_CONSTANTE  CCL ON CCL.ANLUNA   = I.AN*12+I.LUNA AND CCL.SIMBOL = &apos;&apos;CONTABCURSLINIE&apos;&apos; AND CCL.VALOARE = &apos;&apos;1&apos;&apos;
        WHERE i.an * 12 + i.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
          AND NOT (G.SEMNIFICATIE = 240 AND Coalesce(I.CUSTODIE,0) = 1)
          AND i.operat = 1 AND Coalesce(i.anulat, 0) = 0 AND Coalesce(i.INFOCM, 0) = 0 &apos;||
          CondSubunit(&apos;i.subunitatea&apos;)||
          fMonedaG||
          fPart(&apos;CASE WHEN Coalesce(i.partener,0)=0 AND i.tipdoc = 16 THEN Coalesce(o.codpart,0) ELSE Coalesce(i.partener,0) END&apos;)||&apos;
      ) xGIO
        LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = xGIO.CODOBLIGPIF
        LEFT JOIN OBLIGPIF OS ON S.CODSTINSPIF = OS.CODOBLIGPIF
        LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        LEFT JOIN IESIRI ISTINS ON ISTINS.CODIES = Coalesce(gs.CODDOC,xGIO.CODDOC) AND ISTINS.TIPDOC = Coalesce(gs.TIPDOC, xGIO.TIPDOC)
        LEFT JOIN TMP_FISAPART_OBLIG tmp ON tmp.CODOBLIGPIF = xGIO.CODOBLIGPIF&apos;||
      sqlInfoCM||&apos;
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, g.tipdoc, nc.codnc coddoc, nc1.codnc1 coddoc1, nc.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, nc.an, nc.luna, nc.datadoc, nc.carnetdoc, NULL seriadoc, &apos;&apos;NC&apos;&apos; prefixdoc, nc.nrdoc, &apos;&apos; &apos;&apos; nri,
        nc.valoare valdoc, nc.valoare valdocbaza,
        CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE Coalesce(Nullif(g.curs,0),1) END curs,
        CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE Coalesce(Nullif(g.curs,0),1) END cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, nc.subunitatea,
        0 codlocatie, CASE WHEN Coalesce(nc1.codpart,0) = 0 THEN Coalesce(nc.part,0) ELSE nc1.codpart END partener, Coalesce(o.codcentru,0) codcentru,
        o.semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, nc.datadoc) termen, o.majorari,
        case when g.semnificatie IN (1250,1251) then 0 else o.valoare end valoare,
        case when g.semnificatie IN (1250,1251) then o.valoare else 0 end valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli,
        &apos;||
        CASE
          WHEN bDefalcDoc
          THEN &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, nc.carnetdoc dstinscarnet, &apos;&apos;NC&apos;&apos; dstinsprefix, nc.nrdoc dstinsnr, nc.datadoc dstinsdata, nc.an dstinsan, nc.luna dstinsluna&apos;
          ELSE &apos;NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna&apos;
        END||&apos;
      FROM general g
        INNER JOIN nc1  ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35
        INNER JOIN NC ON NC.CODNC = NC1.CODNC
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      WHERE NC.an * 12 + NC.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
        AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101) &apos;||
        CondSubunit(&apos;nc.subunitatea&apos;)||
        fMonedaG||
        fPart(&apos;CASE WHEN Coalesce(nc1.codpart,0) = 0 THEN Coalesce(nc.part,0) ELSE nc1.codpart END&apos;)||&apos;
      UNION ALL
      SELECT
        0 issoldini, codobligpif, tipdoc, coddoc, NULL coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, NULL seriadoc, &apos;&apos;PV&apos;&apos; prefixdoc, nrdoc, &apos;&apos; &apos;&apos; nri,
        SUM(valdoc) valdoc,
        ( SELECT SUM(Coalesce(GX.CURS, 1) * (Coalesce(ox.dincaretva,0)+Coalesce(ox.valoare,0)) )
          FROM GENERAL GX INNER JOIN OBLIGPIF OX ON OX.CODGENERAL = GX.CODGENERAL
          WHERE GX.TIPDOC = 28 AND GX.CODDOC = subs.CODDOC AND GX.SEMNIFICATIE IN (1350, 1351, 1352, 1353)
        ) valdocbaza,
        curs, cursdoc,
        tva, datadecont, 0 codpers, subunitatea,
        codlocatie, partener, codcentru,
        semnificatie,
        icont, codpart, Min(termen) termen, majorari,
        VALOARE,
        SUM(valoareifrs) valoareifrs,
        0 corectie,
        CASE WHEN SEMN_AJDEP = 1 THEN 0 ELSE VAL_AJDEP END&apos;||sCursAjDep||&apos; DEBIT_AJDEP, CASE WHEN SEMN_AJDEP = -1 THEN 0 ELSE VAL_AJDEP END&apos;||sCursAjDep||&apos; CREDIT_AJDEP, SEMN_AJDEP*VAL_AJDEP&apos;||sCursAjDep||&apos; SOLD_AJDEP,
        NULL ComCli,
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
      FROM (
        SELECT
          o.codobligpif, g.tipdoc, g.coddoc, c.obsd||&apos;&apos;; &apos;&apos;||c.obsc obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, c.an, c.luna, c.datadoc, c.carnetdoc, c.nrdoc,
          CASE WHEN o.semnificatie IN (1351) AND o.icont IN (6) THEN -1 ELSE 1 END * (Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)) valdoc,
          CASE
            WHEN COALESCE(gs.moneda, g.moneda, 0) = 0 THEN 1
            WHEN g.semnificatie IN (1301, 1303, 1350, 1351) THEN COALESCE(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,c.an,c.luna), gs.curs, g.curs, 1)
            ELSE Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,c.an,c.luna), gs.curs)
          END curs,
          CASE
            WHEN Coalesce(g.moneda,0) = 0 THEN 1
            ELSE Coalesce(Nullif(g.curs,0), 1)
          END cursdoc,
          Coalesce(g.tva,0) tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, &apos;||CASE WHEN bSubStins THEN &apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea,c.subunitatea)&apos; ELSE &apos;c.subunitatea&apos; END ||&apos; subunitatea,
          &apos;||sLocatieC||&apos; codlocatie, o.codpart partener, Coalesce(o.codcentru,0) codcentru,
          o.semnificatie,
          o.icont, o.codpart, Coalesce(o.termen, c.datadoc) termen, o.majorari,
          CASE
            WHEN o.semnificatie IN (1300) AND o.icont IN (4, 12) AND Coalesce(C.TipCompens,0) IN (5) THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)+Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND o.icont IN (    5) AND Coalesce(C.TipCompens,0) IN (5) THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1300)                                                            THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND os.semnificatie IN (410)                               THEN -(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1350) AND os.semnificatie not IN (1303, 1302)                    THEN +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0)-Coalesce(G.TVA,0))
            WHEN o.semnificatie IN (1351) AND o.icont IN (6)                                         THEN -(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))
            ELSE                                                                                          +(Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))
          END VALOARE,
          pkg_list_base_fisaanalitikpart.getTrezIFRS(gs.codGeneral, g.Moneda, Coalesce(s.dincaretva,0)+Coalesce(s.valoare,0), c.An*12+c.Luna-1) valoareifrs,
          CASE
            WHEN Coalesce(C.TipCompens,0) = 2 THEN -1
            WHEN Coalesce(C.TipCompens,0) = 3 AND Coalesce(CS.TipCompens,0) = 1 THEN -1
            WHEN Coalesce(C.TipCompens,0) IN (1,3,4) THEN 1
            ELSE 0
          END SEMN_AJDEP,
          (Coalesce(o.dincaretva,0)+Coalesce(o.valoare,0))*Coalesce(O.CoefProvizion,0) VAL_AJDEP&apos;||
          sDocX||&apos;
        FROM general g
          INNER JOIN compens c ON g.coddoc = c.codcompens
          INNER JOIN obligpif o on o.codgeneral = g.codgeneral
          LEFT JOIN stingere s on s.codstingatorpif = o.codobligpif
          LEFT JOIN obligpif os on os.codobligpif = s.codstinspif
          LEFT JOIN general gs on gs.codgeneral = os.codgeneral
          LEFT JOIN dvi on dvi.coddvi = gs.coddoc AND gs.tipdoc = 5 AND gs.semnificatie = 130
          LEFT JOIN intrari intr ON intr.codintr = Coalesce(dvi.codintr,gs.coddoc) AND intr.tipdoc = gs.tipdoc
          LEFT JOIN iesiri ies ON ies.codies = gs.coddoc AND ies.tipdoc = gs.tipdoc
          LEFT JOIN trezor1 t1s ON t1s.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29, 30, 31, 33)
          LEFT JOIN trezor ts ON ts.codtrezor = t1s.codtrezor
          LEFT JOIN nc1 on nc1.codnc1 = gs.coddoc AND gs.tipdoc = 35
          LEFT JOIN nc on nc.codnc = nc1.codnc
          LEFT JOIN compens cs ON cs.codcompens = CASE WHEN gs.tipdoc = 28 THEN gs.coddoc WHEN gs.codgeneral IS NULL THEN c.codcompens END
        WHERE g.tipdoc = 28 AND c.an * 12 + c.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101, 1302, 1352)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9) &apos;||
          CondSubunitSting(&apos;c.subunitatea&apos;,&apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea)&apos;)||
          fMonedaG||
          fPart(&apos;Coalesce(o.codpart,0)&apos;)||&apos;
      ) subs
      GROUP BY
        codobligpif, tipdoc, coddoc, obs, moneda, an, luna, datadoc, carnetdoc, nrdoc, curs, cursdoc, tva, datadecont, subunitatea, codlocatie, partener, codcentru, semnificatie, icont, codpart, majorari, valoare,
        semn_ajdep, val_ajdep, dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna&apos;;

    IF pOriceMoneda AND pSUBUNIT &gt; 0 THEN
      sqlDocs := sqlDocs ||&apos;
      UNION ALL
      SELECT
        0 issoldini, o.codobligpif, reg.tipreg tipdoc, reg.codreg coddoc, NULL coddoc1, reg.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, reg.an, reg.luna, reg.datadoc, NULL carnetdoc, NULL seriadoc,
        &apos;&apos;Reg.&apos;&apos;||
        CASE
          WHEN dvi.coddvi is not NULL THEN &apos;&apos;DVI&apos;&apos;||dvi.nrdoc||&apos;&apos;/&apos;&apos;||to_char(dvi.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN intr.codintr is not NULL THEN intr.prefixdoc||intr.nrdoc||&apos;&apos;/&apos;&apos;||to_char(intr.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN ies.codies is not NULL THEN ies.prefixdoc||ies.nrdoc||&apos;&apos;/&apos;&apos;||to_char(ies.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN t1s.codtrezor1 is not NULL THEN t1s.doc||t1s.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1s.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN cs.codcompens is not NULL THEN &apos;&apos;PV&apos;&apos;||cs.nrdoc||&apos;&apos;/&apos;&apos;||to_char(cs.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHEN nc.codnc is not NULL THEN &apos;&apos;NC&apos;&apos;||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          ELSE NULL
        END prefixdoc,
        reg.nrdoc, &apos;&apos; &apos;&apos; nri,
        reg1.solddocval valdoc, reg1.solddocreg - reg1.solddocval valdocbaza,
        reg1.curs,
        reg1.curs cursdoc,
        g.tva, PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) datadecont, 0 codpers, COALESCE(nc.subunitatea, cs.subunitatea, ts.subunitatea, ies.subunitatea, intr.subunitatea) subunitatea,
        COALESCE(ies.codlocatie, intr.codlocatie, t1s.codlocatie, 0) codlocatie, o.codpart, Coalesce(o.codcentru,0) codcentru,
        CASE
          WHEN o.semnificatie NOT IN (1200, 1201, 430, 330) THEN Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1200 AND o.icont IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN  Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1201 AND o.icont IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN -Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1200 AND o.icont IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;)      THEN -Sign(reg1.solddocreg - reg1.solddocval)
          WHEN o.semnificatie = 1201 AND o.icont IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;)      THEN  Sign(reg1.solddocreg - reg1.solddocval)
          ELSE - Sign(reg1.solddocreg - reg1.solddocval)
        END * o.semnificatie semnificatie,
        o.icont, o.codpart, Coalesce(o.termen, reg.datadoc) termen, o.majorari,
        ABS(reg1.solddocreg - reg1.solddocval) valoare,
        pkg_list_base_fisaanalitikpart.getreg1ifrs(reg1.codGeneral, reg1.solddoc*(Reg.Curs_IFRS - Reg.Curs), reg.An*12+reg.Luna-1, Coalesce(Reg.Curs_IFRS,0), Reg1.SoldDoc) as valoareifrs,
        0 corectie,
        0 DEBIT_AJDEP, 0 CREDIT_AJDEP, 0 SOLD_AJDEP,
        NULL ComCli&apos;||
        sDocX||&apos;
      FROM reg
        INNER JOIN reg1 on reg.codreg = reg1.codreg
        INNER JOIN general g on g.codgeneral = reg1.codgeneral
        INNER JOIN obligpif o on o.codgeneral = g.codgeneral AND o.icont = reg1.cont AND o.codobligpif = Coalesce(reg1.codobligpif,o.codobligpif)
        LEFT JOIN dvi on dvi.coddvi = g.coddoc AND g.tipdoc = 5 AND g.semnificatie = 130
        LEFT JOIN intrari intr on intr.codintr = Coalesce(dvi.codintr, g.coddoc) AND intr.tipdoc = g.tipdoc
        LEFT JOIN iesiri ies on ies.codies = g.coddoc AND ies.tipdoc = g.tipdoc
        LEFT JOIN trezor1 t1s ON t1s.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
        LEFT JOIN trezor ts ON ts.codtrezor = t1s.codtrezor
        LEFT JOIN nc1 on nc1.codnc1 = g.coddoc AND g.tipdoc = 35
        LEFT JOIN nc on nc.codnc = nc1.codnc
        LEFT JOIN compens cs ON cs.codcompens = g.coddoc AND g.tipdoc = 28
      WHERE reg.tipreg = 46 AND reg.an*12 + reg.luna BETWEEN &apos;||g_lunaIni||&apos; AND &apos;||g_lunaFin||
        fMonedaG||
        fPart(&apos;Coalesce(o.codpart,0)&apos;)||
        CondSubunit(&apos;COALESCE(nc.subunitatea, cs.subunitatea, ts.subunitatea, ies.subunitatea, intr.subunitatea)&apos;);
    END IF;

    sqldocs := sqldocs ||&apos;
      UNION ALL
      SELECT
        0 issoldini, Max(codobligpif) codobligpif, tipdoc, coddoc, coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, seriedoc, doc, nrdoc, nri,
        SUM(valdoc) valdoc, valdocbaza,
        curs, cursdoc, tva, datadecont, codpers, subunitatea,
        codlocatie, partener, codcentru,
        semnificatie, icont, codpart, Min(termen) termen, majorari,
        SUM(VALOARE) VALOARE,
        SUM(valoareifrs) valoareifrs,
        0 corectie,
        Sum(VAL_AJDEP)&apos;||sCursAjDep||&apos; DEBIT_AJDEP,
        0 CREDIT_AJDEP,
        -Sum(VAL_AJDEP)&apos;||sCursAjDep||&apos; SOLD_AJDEP,
        NULL ComCli,
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
      FROM (
        SELECT
          o.codobligpif, g.tipdoc, t.codtrezor coddoc, t1.codtrezor1 coddoc1, t1.obs, &apos;||CASE WHEN bForceLei THEN &apos;0&apos; ELSE &apos;Coalesce(g.moneda,0)&apos; END||&apos; moneda, t.an, t.luna, t1.datadoc, t1.carnetdoc, t1.seriedoc, t1.doc, t1.nrdoc, t1.nri,
          CASE WHEN Coalesce(t1.platatva,0) = 1 THEN o.dincaretva ELSE o.valoare END valdoc, t1.valdoc valdocbaza,
          CASE
            WHEN Coalesce(g.moneda,0) = 0 THEN 1
            WHEN o.semnificatie IN (320, 420) THEN Coalesce(PKG_LIST_BASE_UTILS.GetCursReg(gs.codgeneral,os.icont,t.an,t.luna),gs.curs)
            ELSE g.curs
          END curs,
          CASE WHEN Coalesce(g.moneda,0) = 0 THEN 1 ELSE g.curs END cursdoc,
          Coalesce(g.tva,0) tva, CASE WHEN g.tipdoc = 31 THEN PKG_LIST_BASE_FISAANALITIKPART.GetDataDecont(g.coddoc, g.tipdoc) ELSE To_Char(t1.datadecont,&apos;&apos;dd.mm.yyyy&apos;&apos;) END datadecont,
          Coalesce(t1.agent, t.agent) codpers, &apos;||CASE WHEN bSubStins THEN &apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea,t.subunitatea)&apos; ELSE &apos;t.subunitatea&apos; END ||&apos; subunitatea,
          &apos;||sLocatieT1||&apos; codlocatie, t1.codpart partener, Coalesce(o.codcentru,0) codcentru,
          o.semnificatie, o.icont, o.codpart, Coalesce(t1.datadecont, o.termen, t1.datadoc) termen, o.majorari,
          CASE WHEN Coalesce(t1.platatva,0) = 1 THEN o.dincaretva WHEN o.semnificatie IN (310, 410, 320, 420, 330, 430) THEN o.valoare - Coalesce(g.tva, 0) ELSE o.valoare END VALOARE,
          pkg_list_base_fisaanalitikpart.getTrezIFRS(gs.codGeneral, g.Moneda, s.Valoare, t.An*12+t.Luna-1) valoareifrs,
          s.Valoare* Coalesce(os.coefprovizion,0)*CASE WHEN Coalesce(CS.TipCompens,0) IN (1,3,4) THEN 1 ELSE 0 END VAL_AJDEP&apos;||
          sDocX||&apos;
        FROM trezor t
          INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
          INNER JOIN general g ON g.coddoc = t1.codtrezor1 AND g.tipdoc = t.tipdoc
          INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
          LEFT JOIN STINGERE S ON S.CODSTINGATORPIF = O.CODOBLIGPIF
          LEFT JOIN OBLIGPIF os ON os.CODOBLIGPIF = S.CODSTINSPIF
          LEFT JOIN GENERAL gs ON gs.CODGENERAL = os.CODGENERAL
          LEFT JOIN DVI ON DVI.CODDVI = gs.CODDOC AND gs.TIPDOC = 5 AND gs.SEMNIFICATIE = 130
          LEFT JOIN INTRARI INTR ON INTR.CODINTR = Coalesce(DVI.CODINTR,gs.CODDOC) AND INTR.TIPDOC = gs.TIPDOC
          LEFT JOIN IESIRI IES ON IES.CODIES = gs.CODDOC AND IES.TIPDOC = gs.TIPDOC
          LEFT JOIN TREZOR1 T1S ON T1S.CODTREZOR1 = CASE WHEN gs.codgeneral IS NULL THEN t1.codtrezor1 WHEN gs.TIPDOC IN (29, 30, 31, 33) THEN gs.CODDOC END
          LEFT JOIN TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
          LEFT JOIN COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
          LEFT JOIN NC1 ON NC1.CODNC1 = GS.CODDOC AND GS.TIPDOC = 35
          LEFT JOIN NC ON NC.CODNC = NC1.CODNC
        WHERE t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
          AND t.an * 12 + t.luna BETWEEN &apos;||g_LunaIni||&apos; AND &apos;|| g_LunaFin ||&apos;
          AND g.semnificatie NOT IN (500, 600, 800, 801, 900, 901, 950, 951, 1000, 1100, 1101)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9)
          AND NOT EXISTS (
            SELECT S.CODSTINGATORPIF FROM STINGERE S INNER JOIN OBLIGPIF OB ON S.CODSTINSPIF = OB.CODOBLIGPIF
            WHERE OB.SEMNIFICATIE IN (500, 600) AND O.CODOBLIGPIF = S.CODSTINGATORPIF ) &apos;||
          CondSubunitSting(&apos;t.subunitatea&apos;,&apos;COALESCE(intr.subunitatea,ies.subunitatea,ts.subunitatea,nc.subunitatea,cs.subunitatea)&apos;)||
          fMonedaG||
          fPart(&apos;Coalesce(t1.codpart,0)&apos;)||&apos;
      ) subs
      GROUP BY
        tipdoc, coddoc, coddoc1, obs, moneda, an, luna, datadoc, carnetdoc, seriedoc, doc, nrdoc, nri, valdocbaza, curs, cursdoc, tva, datadecont, codpers, subunitatea, codlocatie, partener, codcentru, semnificatie, icont, codpart, majorari,
        VAL_AJDEP, dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna
    ) &apos;;
  end if;

  RETURN sqldocs;
END;

FUNCTION getSqlIni(pHolding BOOLEAN, pOriceMoneda IN BOOLEAN, pAnalitica IN BOOLEAN) RETURN CLOB IS
  sMonedaSI     VARCHAR2(300)  :=&apos;&apos;;
  sWithNPS      CLOB;
  sGroupBySI    VARCHAR2(500)  := &apos;&apos;;
  sCurs         VARCHAR2(500)  := &apos;&apos;;
  sCursVal      VARCHAR2(500)  := &apos;&apos;;
BEGIN

  sCurs := &apos;CASE WHEN SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END * REST) = 0 THEN 0 ELSE SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END * REST * CURS) / SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END * REST) END&apos;;
  IF aCodMoneda IN (-1,0) THEN
    IF bMonSold THEN
      sMonedaSi  := &apos;CodMoneda &apos;;
      sGroupBySI := &apos;, codmoneda&apos;;
    ELSE
      sMonedaSi  := &apos;0&apos;;
      sCurs      := &apos;NULL&apos;;
    END IF;
    sCursVal     := &apos;*CURS&apos;;
  ELSE
    sMonedaSi    := aCodMoneda;
  END IF;

  IF bDefalcDoc THEN
    sGroupBySI := sGroupBySI||&apos;, dstinstipdoc, dstinscoddoc, dstinsseria, dstinsprefix, dstinsnr, dstinsdata, dstinscarnet, dstinsan, dstinsluna&apos;;
  END IF;

  if bExpert then
    sWithNPS := &apos;
      SELECT
        CODOBLIGPIF, 1 issoldini, NULL tipdoc, NULL coddoc, NULL coddoc1, NULL obs, &apos;||sMonedaSi||&apos; moneda, an, luna, NULL datadoc, NULL carnetdoc, NULL seriadoc, NULL prefixdoc, NULL nrdoc, NULL nri, NULL valdoc, NULL valdocbaza, &apos;||sCurs||&apos; curs, NULL tva,
        NULL datadecont, NULL codpers, subunitatea, NULL codlocatie, codpart partener, NULL codcentru, 0 semnificatie, icont, codpart, NULL termen, NULL majorari,
        SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END*REST&apos;||sCursVal||&apos;) valoare, SUM(RESTIFRS) valoareIFRS, 0 corectie, NULL ComCli, 0 DEBIT_AJDEP, 0 CREDIT_AJDEP, SUM(REST*TipAjDep*CoefProvizion) SOLD_AJDEP,&apos;;
    IF bDefalcDoc THEN
      sWithNPS := sWithNPS||&apos;
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna, &apos;&apos;DA&apos;&apos; dstinssini&apos;;
    ELSE
      sWithNPS := sWithNPS||&apos;
        NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna, NULL dstinssini&apos;;
    END IF;
    sWithNPS := sWithNPS||&apos;
      FROM (
        SELECT
          OL.CODOBLIGPIF, OL.AN, OL.LUNA, O.CODPART, O.ICONT, Coalesce(G.MONEDA,0) CODMONEDA, COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea) subunitatea,
          CASE
            WHEN O.SEMNIFICATIE IN (100, 130) THEN -OL.REST
            WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2 THEN -OL.REST
            WHEN O.SEMNIFICATIE = 110 THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE IN (120,121) THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE = 200 THEN OL.REST
            WHEN O.SEMNIFICATIE = 210 THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (220,221) THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
            WHEN O.SEMNIFICATIE IN (310, 330) THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE IN (410, 430) THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;) THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2,5,8,9,15,16,18,20&apos;||sIcontS_F||&apos;) THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3,4,6,7,10,11,12,13,14,17,19&apos;||sIcontS_C||&apos;) THEN OL.REST
          END REST,
          Coalesce(OL.RESTTVA, 0) AS TVA,
          &apos;||CASE WHEN aCodMoneda = -1 THEN &apos;CASE WHEN Coalesce(G.MONEDA, 0) = 0 THEN 1 ELSE Coalesce(REG.CURS, G.CURS) END &apos; END||&apos; CURS,
          CASE WHEN O.SEMNIFICATIE IN (1250, 1251) THEN OL.REST END RESTIFRS,
          Coalesce(O.COEFPROVIZION,0) CoefProvizion,
          CASE
            WHEN Coalesce(C.TipCompens,0) = 2 THEN -1
            WHEN Coalesce(C.TipCompens,0) IN (1,3,4) THEN 1
            ELSE 0
          END TipAjDep&apos;;
    IF bDefalcDoc AND pAnalitica THEN
      sWithNPS := sWithNPS||&apos;,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.tipdoc,  ies.tipdoc,  t.tipdoc     ) END dstinstipdoc,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.codintr, ies.codies,  t1.codtrezor1) END dstinscoddoc,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.seriadoc,ies.seriadoc,t1.seriedoc  ) END dstinsseria,
          CASE
            WHEN NOT &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN &apos;&apos;...Alte subunitati ...&apos;&apos;
            WHEN DVI.CODDVI IS NOT NULL THEN &apos;&apos;DVI&apos;&apos;
            WHEN C.CODCOMPENS IS NOT NULL THEN &apos;&apos;PV&apos;&apos;
            WHEN NC.CODNC IS NOT NULL THEN &apos;&apos;NC&apos;&apos;
            ELSE COALESCE(intr.prefixdoc,ies.prefixdoc,t1.doc)
          END dstinsprefix,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(dvi.nrdoc,intr.nrdoc,ies.nrdoc,t1.nrdoc,c.nrdoc,nc.nrdoc) END dstinsnr,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(dvi.datadoc,intr.datadoc,ies.datadoc,t1.datadoc,c.datadoc,nc.datadoc) END dstinsdata,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.carnetdoc,ies.carnetdoc,t1.carnetdoc,c.carnetdoc,nc.carnetdoc) END dstinscarnet,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.an,ies.an,t1.an,c.an,nc.an) END dstinsan,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.luna,ies.luna,t1.luna,c.luna,nc.luna) END dstinsluna&apos;;
    END IF;
    sWithNPS := sWithNPS||&apos;
        FROM OBLIGPIFLUNA OL
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN (
            SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
            FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
            WHERE R.TIPREG = 46 AND R.AN * 12 + R.LUNA &lt;= &apos;||(g_LunaIni-1)||&apos;
            GROUP BY R1.CODGENERAL
          ) REG ON REG.CODGENERAL = G.CODGENERAL
          LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5 AND G.SEMNIFICATIE = 130
          LEFT JOIN INTRARI INTR ON INTR.CODINTR = Coalesce(DVI.CODINTR,G.CODDOC) AND INTR.TIPDOC = G.TIPDOC
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33)
          LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
          LEFT JOIN NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC ON NC.CODNC = NC1.CODNC
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28
        WHERE OL.REST &lt;&gt; 0
          AND O.SEMNIFICATIE IN (100, 110, 120, 121, 130, 140, 200, 210, 220, 221, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9)
          AND OL.AN * 12 + OL.LUNA = &apos;||(g_LunaIni-1)||
          fPART(&apos;Coalesce(o.codpart, 0)&apos;)||
          CondSubunit(&apos;COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea)&apos;)||
          CASE WHEN NOT bMoneda THEN &apos;
          AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)&apos; END ||&apos;
      )
      GROUP BY codobligpif,luna, an, icont, subunitatea, codpart&apos;||sGroupBySI;
  ELSE
    sWithNPS := &apos;
      SELECT
        0 codobligpif, 1 issoldini, NULL tipdoc, NULL coddoc, NULL coddoc1, NULL obs, &apos;||sMonedaSi||&apos; moneda, an, luna, NULL datadoc, NULL carnetdoc, NULL seriadoc, NULL prefixdoc, NULL nrdoc, NULL nri, NULL valdoc, NULL valdocbaza, &apos;||sCurs||&apos; curs,
        NULL datadecont, NULL codpers, subunitatea, NULL codlocatie, codpart partener, NULL codcentru, 0 semnificatie, icont, codpart, NULL termen, NULL majorari,
        SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END*REST&apos;||sCursVal||&apos;) valoare,
        SUM(CASE WHEN icont in (21,22,23,24) THEN -1 ELSE 1 END*TVA&apos; ||sCursVal||&apos;) tva,
        SUM(RESTIFRS) valoareIFRS, 0 corectie, NULL ComCli, 0 DEBIT_AJDEP, 0 CREDIT_AJDEP, SUM(REST*TipAjDep*CoefProvizion) SOLD_AJDEP,&apos;;
    IF bDefalcDoc THEN
      sWithNPS := sWithNPS||&apos;
        dstinstipdoc, dstinscoddoc, dstinsseria, dstinscarnet, dstinsprefix, dstinsnr, dstinsdata, dstinsan, dstinsluna, &apos;&apos;DA&apos;&apos; dstinssini&apos;;
    ELSE
      sWithNPS := sWithNPS||&apos;
        NULL dstinstipdoc, NULL dstinscoddoc, NULL dstinsseria, NULL dstinscarnet, NULL dstinsprefix, NULL dstinsnr, NULL dstinsdata, NULL dstinsan, NULL dstinsluna, NULL dstinssini&apos;;
    END IF;
    sWithNPS := sWithNPS||&apos;
      FROM (
        SELECT
          OL.AN, OL.LUNA, O.CODPART, O.ICONT, Coalesce(G.MONEDA,0) CODMONEDA, COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea) subunitatea,
          CASE
            WHEN O.SEMNIFICATIE IN (100, 130) THEN -OL.REST
            WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2 THEN -OL.REST
            WHEN O.SEMNIFICATIE = 110 THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE IN (120,121) THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE = 200 THEN OL.REST
            WHEN O.SEMNIFICATIE = 210 THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (220,221) THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
            WHEN O.SEMNIFICATIE IN (310, 330) THEN OL.REST - Coalesce(OL.RESTTVA, 0)
            WHEN O.SEMNIFICATIE IN (410, 430) THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
            WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (2,5,6,8,9,15,16,17,20,21,22&apos;||sIcontS_F||&apos;) THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (3,4,7,10,11,12,13,14,18,19,23,24&apos;||sIcontS_C||&apos;) THEN OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2,5,8,9,15,16,18,20&apos;||sIcontS_F||&apos;) THEN -OL.REST
            WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3,4,6,7,10,11,12,13,14,17,19&apos;||sIcontS_C||&apos;) THEN OL.REST
          END REST,
          Coalesce(
            CASE
              WHEN O.SEMNIFICATIE = 110         THEN  OL.RESTTVA
              WHEN O.SEMNIFICATIE IN (120,121)  THEN -OL.RESTTVA
              WHEN O.SEMNIFICATIE = 210         THEN -OL.RESTTVA
              WHEN O.SEMNIFICATIE IN (220,221)  THEN  OL.RESTTVA
              WHEN O.SEMNIFICATIE IN (310, 330) THEN  OL.RESTTVA
              WHEN O.SEMNIFICATIE IN (410, 430) THEN -OL.RESTTVA
            END, 0
          ) TVA,
          CASE WHEN Coalesce(G.MONEDA, 0) = 0 THEN 1 ELSE Coalesce(REG.CURS, G.CURS) END CURS,
          CASE WHEN O.SEMNIFICATIE IN (1250, 1251) THEN OL.REST END RESTIFRS,
          Coalesce(O.COEFPROVIZION,0) CoefProvizion,
          CASE
            WHEN Coalesce(C.TipCompens,0) = 2 THEN -1
            WHEN Coalesce(C.TipCompens,0) IN (1,3,4) THEN 1
            ELSE 0
          END TipAjDep&apos;;
    IF bDefalcDoc AND pAnalitica THEN
      sWithNPS := sWithNPS||&apos;,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.tipdoc,ies.tipdoc,t.tipdoc) END dstinstipdoc,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.codintr,ies.codies,t1.codtrezor1) END dstinscoddoc,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.seriadoc,ies.seriadoc,t1.seriedoc) END dstinsseria,
          CASE
            WHEN NOT &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN &apos;&apos;...Alte subunitati ...&apos;&apos;
            WHEN DVI.CODDVI IS NOT NULL THEN &apos;&apos;DVI&apos;&apos;
            WHEN C.CODCOMPENS IS NOT NULL THEN &apos;&apos;PV&apos;&apos;
            WHEN NC.CODNC IS NOT NULL THEN &apos;&apos;NC&apos;&apos;
            ELSE COALESCE(intr.prefixdoc,ies.prefixdoc,t1.doc)
          END dstinsprefix,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(dvi.nrdoc,intr.nrdoc,ies.nrdoc,t1.nrdoc,c.nrdoc,nc.nrdoc) END dstinsnr,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(dvi.datadoc,intr.datadoc,ies.datadoc,t1.datadoc,c.datadoc,nc.datadoc) END dstinsdata,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.carnetdoc,ies.carnetdoc,t1.carnetdoc,c.carnetdoc,nc.carnetdoc) END dstinscarnet,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.an,ies.an,t1.an,c.an,nc.an) END dstinsan,
          CASE WHEN &apos;||pSubunit||&apos; IN (1,COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA, C.SUBUNITATEA)) THEN COALESCE(intr.luna,ies.luna,t1.luna,c.luna,nc.luna) END dstinsluna&apos;;
    END IF;
    sWithNPS := sWithNPS||&apos;
        FROM OBLIGPIFLUNA OL
          INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          LEFT JOIN (
            SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
            FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
            WHERE R.TIPREG = 46 AND R.AN * 12 + R.LUNA &lt;= &apos;||(g_LunaIni-1)||&apos;
            GROUP BY R1.CODGENERAL
          ) REG ON REG.CODGENERAL = G.CODGENERAL
          LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5 AND G.SEMNIFICATIE = 130
          LEFT JOIN INTRARI INTR ON INTR.CODINTR = Coalesce(DVI.CODINTR,G.CODDOC) AND INTR.TIPDOC = G.TIPDOC
          LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC
          LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33)
          LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
          LEFT JOIN NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35
          LEFT JOIN NC ON NC.CODNC = NC1.CODNC
          LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28
        WHERE OL.REST &lt;&gt; 0
          AND O.SEMNIFICATIE IN (100, 110, 120, 121, 130, 140, 200, 210, 220, 221, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
          AND NOT (g.semnificatie = 140 AND Coalesce(intr.tipfactura, 0) = 9)
          AND OL.AN * 12 + OL.LUNA = &apos;||(g_LunaIni-1)||
          fPART(&apos;Coalesce(o.codpart, 0)&apos;)||
          CondSubunit(&apos;COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea)&apos;)||
          CASE WHEN NOT bMoneda THEN &apos;
          AND Coalesce(G.MONEDA,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)&apos; END ||&apos;
      )
      GROUP BY luna, an, icont, subunitatea, codpart&apos;||sGroupBySI;
  END IF;

  RETURN &apos;
  WITH tmp AS (&apos;||sWithNPS||&apos;)&apos;;
END;

PROCEDURE processList(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      CLOB;
  sUpdate      CLOB;
  cJoinComun   CLOB;
  sqlSoldIni   CLOB;
  sqlMiscari   CLOB;
  sqlAux       CLOB;

  fCont        VARCHAR(200)   :=&apos;&apos;;
  aSitV        NUMBER(1);
  aBancaV      NUMBER(20);
  aMonedaV     NUMBER(20);
  aTipCont     INTEGER        := getTipSold;
  fCurs        VARCHAR2(100)  := &apos; 1 &apos;;
  sCursRef     VARCHAR2(500)  := &apos;, 1 curs_ref &apos;;
  bHolding     BOOLEAN        := Coalesce(pkg_categconst.GetValConstanta(&apos;Holding&apos;, 0, g_lunaFin),2) &lt;&gt; 2;
  sALIopart    VARCHAR2(200);
  sALIopartI   VARCHAR2(200);
  fClase       VARCHAR2(200) :=&apos;&apos;;
  NR           NUMBER;
  bAnalitica   BOOLEAN       := tmpname &lt;&gt; &apos;TMP_LST_DETBALSINT&apos;;
BEGIN
  IF bAnalitica THEN
    gSuplCols := &apos;tmp_fisapart tmp, nmonede mon, npart np, npartcodfisc cf, ncont ncont, npers npers, nagenda nag, nsubunit sub, nclasep nclp, doccarnete dc, doccarnete dcstins, centrecost cc&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  END IF;

  SELECT Count(1) INTO Nr from TMP_CLASEPDEDICATE;
  IF Nr &gt; 0 THEN
    fClase := &apos;
    AND (Coalesce(NP.CODCLASA,0) IN (SELECT CODCLASEP FROM TMP_CLASEPDEDICATE)) &apos;;
  END IF;

  SetSemnificatii;

  IF aCodMoneda = -1
  THEN fCurs := &apos; Coalesce(tmp.curs, 1) &apos;;
  END IF;

  IF NOT bCont THEN
    fCont := &apos;
    AND NCONT.CODCONT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;) &apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV, aBancaV, aMonedaV) THEN
    sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;, &apos;||aBancaV||&apos;, tmp.datadoc ) curs_ref &apos;;
  END IF;

  IF pTipIopart = 2 THEN
    SELECT anmaxim*12+lunamaxima   INTO sALIopart FROM FIRMALUNI WHERE ROWNUM = 1;
    sALIopartI := sALIopart;
  ELSIF pTipIopart = 1 THEN
    SELECT ancurent*12+lunacurenta INTO sALIopart FROM FIRMALUNI WHERE ROWNUM = 1;
    sALIopartI := sALIopart;
  ELSE
    sALIopart  := &apos;tmp.an*12+tmp.luna&apos;;
    sALIopartI := g_LunaIni;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpname||&apos;(
    CODPART, CODSUBUNIT, ICONT, CODCONT, TIPCONT, CODMONEDA, ORDINE,
    DEBIT, CREDIT,
    IFRS,
    DEBIT_AJDEP, CREDIT_AJDEP, SOLD_COL_AJDEP&apos;;
  IF bAnalitica THEN
    sInsert := sInsert||&apos;,
    NAV_CODDOC, NAV_CodDoc1, NAV_TIPDOC,
    DATADOC, SERIADOC, PREFIXDOC, NRDOC,
    DOC,
    NRI, VALDOC, TVA, VALDOCBAZA, CURS, CURSDOC, SIMBOL, DEN_MONEDA,
    TERMEN, MAJORARI,
    SEMNIFICATIE, PARTENER, CODFISCAL, CODEXTERN, CODINTERN,
    CURS_REF,
    AGENT, SEDIU, SUBUNITATEA, OBS, CLASA,
    LUNA,
    ATASAMENT,
    CENTRUCOST, SIMBCENTRUCOST,
    DOCSTINS,
    DSTINSPREFIX, DSTINSNR, DSTINSDATA, DSTINSSINI,
    DATADECONT, COMCLI, SERTDECONT, SERTDOC, SERTSER, SERTNRDOC, SERTDATADOC, SERTVALDOC, SERTDATADEC, SERTVALASOC, VAL_EXP, DESCRIPTOR&apos;;
    sInsert := sInsert||gUserFields;
  END IF;
  sInsert := sInsert||&apos;
  ) &apos;;

  cJoinComun := &apos;
    LEFT JOIN NPERS ON NPERS.CODPERS = tmp.CODPERS
    LEFT JOIN NAGENDA NAG ON NAG.CODAGENDA = tmp.CODLOCATIE
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = tmp.SUBUNITATEA
    LEFT JOIN NCLASEP NCLP ON NCLP.CODCLASEP = NP.CODCLASA
    LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = tmp.CARNETDOC
    LEFT JOIN DOCCARNETE DCSTINS ON DCSTINS.CODCARNET = tmp.DSTINSCARNET
    LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = Coalesce(tmp.CODCENTRU,0)
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = tmp.subunitatea&apos;||
    gSuplJoins;

  sqlMiscari :=
  sInsert||
  getSqlDocs(bHolding, bMoneda, bAnalitica);

  sqlAux := &apos;,
  SERTAR AS (
    SELECT
      ns1.codobligpif,
      vc2_nt_to_vc3200(CAST(collect(DISTINCT CASE NS.DECONT WHEN 3 THEN &apos;&apos;Efecte remise&apos;&apos; WHEN 2 THEN &apos;&apos;Efecte acceptate&apos;&apos; ELSE &apos;&apos;Cecuri&apos;&apos; END) AS vc2_nt)) decont,
      vc2_nt_to_vc3200(CAST(collect(NS.DOC||&apos;&apos; &apos;&apos;||NS.NRDOC||&apos;&apos;/&apos;&apos;||To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) doc,
      vc2_nt_to_vc3200(CAST(collect(NS.DOC ORDER BY NS.CODSERTAR) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.NRDOC) ORDER BY NS.CODSERTAR) AS vc2_nt)) nrdoc,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadoc,
      SUM(NS.VALOARE * CASE NS.TIP WHEN 1 THEN 1 ELSE -1 END) VALOARE,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.DATADECONT,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadecont,
      SUM(NS1.VALOARE * CASE NS.TIP WHEN 1 THEN 1 ELSE -1 END) VALASOC
    FROM nsertar1 ns1
      LEFT JOIN nsertar ns ON ns.codsertar = ns1.codsertar
      LEFT JOIN trezor1 t1 ON t1.codsertar = ns1.codsertar AND (t1.an * 12 + t1.luna) &lt;= &apos;||g_LunaFin||&apos;
      LEFT JOIN obligpif o ON o.codobligpif = ns1.codobligpif
      LEFT JOIN general g ON g.codgeneral = o.codgeneral
    WHERE t1.codtrezor IS NULL
    GROUP BY ns1.codobligpif)&apos;;

  IF bAnalitica THEN
    sqlMiscari := sqlMiscari||sqlAux;
  END IF;
  sqlMiscari := sqlMiscari||&apos;
  SELECT
    np.codpart, tmp.subunitatea codsubunit, tmp.icont, ncont.codcont, ncont.tipcont, tmp.moneda codmoneda, 2 ordine&apos;||
    getColDebitCredit(fCurs)||&apos;,
    TMP.Debit_AjDep, TMP.Credit_AjDep, TMP.SOLD_AJDEP SOLD_COL_AJDEP&apos;;

  sqlAux := &apos;,
    CASE WHEN ts.codsubunit IS NOT NULL THEN tmp.coddoc END NAV_CODDOC, CASE WHEN ts.codsubunit IS NOT NULL THEN tmp.coddoc1 END NAV_CodDoc1, CASE WHEN ts.codsubunit IS NOT NULL THEN tmp.tipdoc END NAV_TIPDOC,
    tmp.datadoc, Coalesce(tmp.seriadoc, dc.serie) SERIADOC, tmp.prefixdoc, tmp.nrdoc,
    tmp.prefixdoc||Coalesce(tmp.seriadoc, dc.serie)||tmp.nrdoc||&apos;&apos;/&apos;&apos;||to_char(tmp.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOC,
    tmp.nri, tmp.valdoc, tmp.tva, tmp.valdocbaza, Coalesce(tmp.curs, 1) curs, Coalesce(tmp.cursdoc, 1) cursdoc, ncont.simbol, mon.den_moneda,
    Coalesce(tmp.termen, tmp.datadoc) termen, tmp.majorari,
    tmp.semnificatie, np.den_part PARTENER, cf.codfiscal, np.codextern, np.codintern&apos;||
    sCursRef||&apos;,
    NPERS.NUME||&apos;&apos; &apos;&apos;||NPERS.PRENUME AGENT, NAG.OBS SEDIU, SUB.DEN_SUBUNIT SUBUNITATEA, tmp.obs, NCLP.DEN_CLASEP CLASA,
    to_char(tmp.an, &apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(tmp.luna, &apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(tmp.Luna) LUNA,
    CASE WHEN EXISTS (SELECT 1 FROM DOCUMENTE X WHERE X.CODDOC = tmp.coddoc AND X.TIPDOC = tmp.tipdoc) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END ATASAMENT,
    CC.DENUMIRE CENTRUCOST, CC.SIMBOL SIMBCENTRUCOST,
    tmp.DSTINSPREFIX||Coalesce(tmp.dstinsseria, dcstins.serie)||tmp.DSTINSNR||CASE WHEN tmp.DSTINSDATA IS NULL THEN &apos;&apos;&apos;&apos; ELSE &apos;&apos;/&apos;&apos;||TO_CHAR(tmp.DSTINSDATA,&apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINS,
    tmp.DSTINSPREFIX, tmp.DSTINSNR, tmp.DSTINSDATA, CASE WHEN tmp.AN IS NULL THEN NULL WHEN tmp.DSTINSAN*12+tmp.DSTINSLUNA &lt; &apos;||g_LunaIni||&apos; THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END DSTINSSINI,
    tmp.DataDecont, tmp.ComCli, sert.DECONT SERTDECONT, sert.DOC SERTDOC, sert.SER SERTSER, sert.NRDOC SERTNRDOC, sert.DATADOC SERTDATADOC, sert.VALOARE SERTVALDOC, sert.DATADECONT SERTDATADEC, sert.VALASOC SERTVALASOC&apos;;
  IF bAnalitica THEN
    IF bExpert then
      sqlAux := sqlAux||&apos;,COALESCE(-EXPS.VAL_EXP,EXP.VAL_EXP) AS VAL_EXP, COALESCE(EXP.DESCRIPTOR,EXPS.DESCRIPTOR) AS DESCRIPTOR&apos;;
    else
      sqlAux := sqlAux||&apos;,0 AS VAL_EXP, NULL AS DESCRIPTOR&apos;;
    end if;
    sqlMiscari := sqlMiscari||sqlAux;
    sqlMiscari := sqlMiscari||gUserAlias;
  END IF;
  sqlMiscari := sqlMiscari||&apos;
  FROM tmp
    INNER JOIN nmonede mon ON mon.codmoneda = tmp.moneda
    INNER JOIN npart np ON np.codpart = CASE WHEN tmp.codpart = 0 THEN tmp.partener ELSE tmp.codpart END
    LEFT JOIN npartcodfisc cf ON cf.codpart = np.codpart AND cf.principal = 1
    LEFT JOIN ncont on ncont.codcont = Coalesce(PKG_LIST_BASE_UTILS.iCont_CodCont(tmp.icont, np.codpart, &apos;||sALIopart||&apos;, tmp.semnificatie), 0)
    LEFT JOIN tmp_semnificatii semn_d ON semn_d.debit = tmp.semnificatie
    LEFT JOIN tmp_semnificatii semn_c ON semn_c.credit = tmp.semnificatie&apos;;

  sqlAux := &apos;
    LEFT JOIN sertar sert ON sert.codobligpif = tmp.codobligpif&apos;||
    cJoinComun;
  IF bAnalitica THEN
    sqlMiscari := sqlMiscari||sqlAux;
    if bExpert then
      sqlMiscari := sqlMiscari||&apos;
      LEFT JOIN (SELECT J.CODDOC, J.TIPDOC, J.CODCENTRU, EX1.VALOARE VAL_EXP, DSC1.VALOARE DESCRIPTOR, O.CODOBLIGPIF
                 FROM OBLIGPIF O
                      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                      INNER JOIN JURNAL J ON J.CODDOC = G.CODDOC AND J.TIPDOC = G.TIPDOC AND J.CODANALIZANOD = O.CODANALIZANOD
                      INNER JOIN EXPERT EX ON EX.CODDOC = J.CODDOC AND J.TIPDOC = EX.TIPDOC
                      INNER JOIN EXPERT1 EX1 ON EX1.CODEXPERT = EX.CODEXPERT AND EX1.CONTD = J.CONTD AND
                                                EX1.CONTC = J.CONTC AND EX1.INDEXJURN = J.INDEXLOCAL AND Coalesce(EX1.GESTJURN,0) = Coalesce(J.GEST,0) AND EX1.CODCENTRU = J.CODCENTRU AND
                                                EX1.ANALIZANODJURN = J.CODANALIZANOD AND EX1.SUBUNITJURN = J.SUBUNITATEA AND EX1.CONTD &lt;&gt; 11246 AND EX1.CONTC &lt;&gt; 11246
                      INNER JOIN ANALIZANOD ANOD ON ANOD.CODANALIZANOD = EX1.CODANALIZANOD
                      INNER JOIN DESCRIPTORI1 DSC1 ON DSC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1) EXP ON TMP.CODOBLIGPIF = EXP.CODOBLIGPIF
      LEFT JOIN (SELECT ST.CODSTINGATORPIF CODOBLIGPIF, EXX1.CODCENTRU, EXX1.VALOARE VAL_EXP, DESC1X.VALOARE DESCRIPTOR
                 FROM STINGERE ST
                      INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = ST.CODSTINSPIF
                      INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                      INNER JOIN EXPERT EXX ON GS.CODDOC = EXX.CODDOC AND GS.TIPDOC = EXX.TIPDOC
                      INNER JOIN EXPERT1 EXX1 ON EXX1.CODEXPERT = EXX.CODEXPERT AND EXX1.CONTD &lt;&gt; 11246 AND EXX1.CONTC &lt;&gt; 11246
                      INNER JOIN ANALIZANOD ANODX ON ANODX.CODANALIZANOD = EXX1.CODANALIZANOD
                      INNER JOIN DESCRIPTORI1 DESC1X ON DESC1X.CODDESCRIPTOR1 = ANODX.CODDESCRIPTOR1) EXPS ON EXPS.CODOBLIGPIF = TMP.CODOBLIGPIF AND EXPS.CODCENTRU = TMP.CODCENTRU&apos;;
    end if;
  END IF;
  sqlMiscari := sqlMiscari||&apos;
  WHERE tmp.icont NOT IN (900, 901, 950, 951, 1000, 1100, 1101) &apos;||
    fCont || fClase;

  sqlSoldIni :=
  sInsert||
  getSqlIni(bHolding, bMoneda, bAnalitica)||&apos;
  SELECT
    np.codpart, tmp.subunitatea codsubunit, tmp.icont, ncont.codcont, ncont.tipcont, tmp.moneda codmoneda, 0 ordine,
    CASE
      WHEN NCONT.TIPCONT = 0 THEN tmp.valoare
      WHEN NCONT.TIPCONT = 1 THEN 0
      WHEN tmp.valoare &gt; 0 THEN tmp.valoare
      ELSE 0
    END DEBIT,
    CASE
      WHEN NCONT.TIPCONT = 0 THEN 0
      WHEN NCONT.TIPCONT = 1 THEN -tmp.valoare
      WHEN tmp.valoare &lt; 0 THEN -tmp.valoare
      ELSE 0
    END CREDIT,
    TMP.VALOAREIFRS IFRS,
    TMP.Debit_AjDep, TMP.Credit_AjDep, TMP.SOLD_AJDEP SOLD_COL_AJDEP&apos;;

  sqlAux := &apos;,
    NULL NAV_CODDOC, NULL NAV_CodDoc1, NULL NAV_TIPDOC,
    Add_Months(to_date(&apos;&apos;01.&apos;&apos;||tmp.luna||&apos;&apos;.&apos;&apos;||tmp.an, &apos;&apos;dd.mm.yyyy&apos;&apos;), 1) DATADOC, NULL SERIADOC, &apos;&apos;Sold initial&apos;&apos; PREFIXDOC, NULL NRDOC,
    &apos;&apos;Sold initial &apos;&apos;||TO_CHAR( Add_Months(to_date(&apos;&apos;01.&apos;&apos;||tmp.luna||&apos;&apos;.&apos;&apos;||tmp.an, &apos;&apos;dd.mm.yyyy&apos;&apos;), 1),&apos;&apos;mm.yyyy&apos;&apos;) DOC,
    &apos;&apos; &apos;&apos; NRI, 0 VALDOC, tmp.tva, 0 VALDOCBAZA, tmp.CURS, tmp.CURS CURSDOC, NCONT.SIMBOL, MON.DEN_MONEDA DEN_MONEDA,
    NULL TERMEN, NULL MAJORARI,
    NULL SEMNIFICATIE, NP.DEN_PART PARTENER, CF.CODFISCAL, NP.CODEXTERN, NP.CODINTERN,
    1 CURS_REF,
    NULL AGENT, NULL SEDIU, SUB.DEN_SUBUNIT SUBUNITATEA, &apos;&apos;Sold initial&apos;&apos; OBS, NCLP.DEN_CLASEP CLASA,
    to_char(tmp.an, &apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(tmp.luna, &apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(tmp.Luna) LUNA,
    &apos;&apos;NU&apos;&apos; ATASAMENT,
    CC.DENUMIRE CENTRUCOST, CC.SIMBOL SIMBCENTRUCOST,
    tmp.DSTINSPREFIX||Coalesce(tmp.DSTINSSERIA, DCSTINS.SERIE)||tmp.DSTINSNR||CASE WHEN tmp.DSTINSDATA IS NULL THEN &apos;&apos;&apos;&apos; ELSE &apos;&apos;/&apos;&apos;||TO_CHAR(tmp.DSTINSDATA,&apos;&apos;DD.MM.YYYY&apos;&apos;) END DOCSTINS,
    tmp.DSTINSPREFIX, tmp.DSTINSNR, tmp.DSTINSDATA, tmp.DSTINSSINI,
    NULL DataDecont, NULL ComCli, NULL SERTDECONT, NULL SERTDOC, NULL SERTSER, NULL SERTNRDOC, NULL SERTDATADOC, NULL SERTVALDOC, NULL SERTDATADEC, NULL SERTVALASOC&apos;;
  IF bAnalitica THEN
    sqlAux := sqlAux||&apos;,0 AS VAL_EXP, NULL AS DESCRIPTOR&apos;;
    sqlSoldIni := sqlSoldIni||sqlAux;
    sqlSoldIni := sqlSoldIni||gUserAlias;
  END IF;
  sqlSoldIni := sqlSoldIni||&apos;
  FROM tmp
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = tmp.MONEDA
    INNER JOIN NPART NP ON NP.CODPART = tmp.CODPART
    LEFT JOIN NPARTCODFISC CF ON CF.CODPART = NP.CODPART AND CF.PRINCIPAL = 1
    LEFT JOIN NCONT ON NCONT.CODCONT = Coalesce(PKG_LIST_BASE_UTILS.iCont_CodCont(tmp.icont,tmp.codpart,&apos;||sALIopartI||&apos;,0), 0)&apos;;
  IF bAnalitica THEN
    sqlSoldIni := sqlSoldIni||
    cJoinComun;
  END IF;

  sqlSoldIni := sqlSoldIni||&apos;
  WHERE 1 = 1&apos;||
    fCont || fClase;

  LIST_EXECUTE_IMMEDIATE(sqlsoldini, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sqlmiscari, aListID, aListVer);

  IF aTipCont = 1 THEN
    sUpdate :=
      &apos;UPDATE &apos;||tmpname||Chr(10)||
      &apos;SET &apos;||Chr(10)||
      &apos;  TIPSOLD        = &apos;&apos;C&apos;&apos;, &apos;||Chr(10)||
      &apos;  SOLD_COL       = CREDIT-DEBIT, &apos;||Chr(10)||
      &apos;  SOLD_COL_CUTVA = CREDIT-DEBIT + ABS(TVA)*(SIGN(CREDIT)-SIGN(DEBIT)), &apos;||Chr(10)||
      &apos;  SOLD_COL_IFRS  = -Coalesce(IFRS,0), &apos;||Chr(10)||
      &apos;  SOLD_COL_TOTAL = CREDIT-DEBIT - Coalesce(IFRS,0), &apos;||Chr(10)||
      &apos;  SOLD_COL_D     = CASE WHEN TIPCONT = 1 THEN 0 ELSE DEBIT-CREDIT END, &apos;||Chr(10)||
      &apos;  SOLD_COL_C     = CASE WHEN TIPCONT = 1 THEN CREDIT-DEBIT ELSE 0 END&apos;;
  ELSE
    sUpdate :=
      &apos;UPDATE &apos;||tmpname||Chr(10)||
      &apos;SET &apos;||Chr(10)||
      &apos;  TIPSOLD        = &apos;&apos;D&apos;&apos;, &apos;||Chr(10)||
      &apos;  SOLD_COL       = DEBIT-CREDIT, &apos;||Chr(10)||
      &apos;  SOLD_COL_CUTVA = DEBIT-CREDIT + ABS(TVA)*(SIGN(DEBIT)-SIGN(CREDIT)), &apos;||Chr(10)||
      &apos;  SOLD_COL_IFRS  = Coalesce(IFRS,0), &apos;||Chr(10)||
      &apos;  SOLD_COL_TOTAL = DEBIT-CREDIT + Coalesce(IFRS,0), &apos;||Chr(10)||
      &apos;  SOLD_COL_D     = CASE WHEN TIPCONT = 1 THEN 0 ELSE DEBIT-CREDIT END, &apos;||Chr(10)||
      &apos;  SOLD_COL_C     = CASE WHEN TIPCONT = 1 THEN CREDIT-DEBIT ELSE 0 END&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(supdate, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_fisaAnalitikPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFB1167C25E36812C1B1D3D5FE7D471D5982A8E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISACONT IS
  v_TipPlan   INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(10000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(10000);
  gSuplJoins  VARCHAR2(5000);

  vSubPar     VARCHAR2(3000);

PROCEDURE UTIL_FISACONT(sTabCont OUT VARCHAR2, sCodCont  OUT VARCHAR2)
IS
  sInsAux     VARCHAR2(30000);
  sFCRul      VARCHAR2(30000);
  sFCSold     VARCHAR2(30000);
  vSubTmp     VARCHAR2(3000);
  sMfUpd      VARCHAR2(30000);
  v_LunaStart NUMBER(20) := PKG_LIST_SELCONT.GetLunaStart;
  v_LunaStop  NUMBER(20) := PKG_LIST_SELCONT.GetLunaStop;
  v_lunaI     NUMBER(20) := v_LunaStart - mod(v_LunaStart-1,12);
  vSubunit    NUMBER(20) := pkg_list_selcont.getSubunit;
  vSoldSub    BOOLEAN    := pkg_list_selcont.getSoldSub;
  vAnLunaMin  NUMBER;
  vSubNull    NUMBER;
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);

  v_TipPlan := PKG_LIST_SELCONT.GetTipPlan;

  SELECT aninitial*12+lunainitiala INTO vAnLunaMin FROM FirmaLuni;

  IF vSubunit &gt; 1 THEN
    vSubNull := vSubunit;
  ELSE
    SELECT Coalesce(Min(CodSubunit),1)
    INTO vSubNull
    FROM NSubunit
    WHERE CodSubunit &gt; 1;
  END IF;

  IF vSoldSub THEN
    vSubTmp := &apos;Coalesce(s.subunitatea,&apos;||vSubNull||&apos;)&apos;;
    vSubPar := &apos;, t.subunitatea&apos;;
    sFCRul  := &apos;
    INSERT INTO TMP_LIST_FCRUL (
      codcont,
      rulajpd, rulajpc, rulajcd, rulajcc,
      rulajvpd, rulajvpc, rulajvcd, rulajvcc,
      rulajp_ifrs, rulajc_ifrs, rulajvp_ifrs, rulajvc_ifrs,
      rulajp_grup, rulajc_grup, rulajvp_grup, rulajvc_grup,
      an, luna, subunitatea
    )
    SELECT
      c.codcont,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajpd      ELSE s.rulajpd      END,0) rulajpd,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajpc      ELSE s.rulajpc      END,0) rulajpc,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajcd      ELSE s.rulajcd      END,0) rulajcd,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajcc      ELSE s.rulajcc      END,0) rulajcc,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvpd     ELSE s.rulajvpd     END,0) rulajvpd,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvpc     ELSE s.rulajvpc     END,0) rulajvpc,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvcd     ELSE s.rulajvcd     END,0) rulajvcd,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvcc     ELSE s.rulajvcc     END,0) rulajvcc,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajp_ifrs  ELSE s.rulajp_ifrs  END,0) rulajp_ifrs,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajc_ifrs  ELSE s.rulajc_ifrs  END,0) rulajc_ifrs,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvp_ifrs ELSE s.rulajvp_ifrs END,0) rulajvp_ifrs,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvc_ifrs ELSE s.rulajvc_ifrs END,0) rulajvc_ifrs,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajp_grup  ELSE s.rulajp_grup  END,0) rulajp_grup,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajc_grup  ELSE s.rulajc_grup  END,0) rulajc_grup,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvp_grup ELSE s.rulajvp_grup END,0) rulajvp_grup,
      Coalesce(CASE WHEN s.codcontrul IS NULL THEN c.rulajvc_grup ELSE s.rulajvc_grup END,0) rulajvc_grup,
      c.an, c.luna, &apos;||vSubTmp||&apos; subunitatea
    FROM ncontrul c
      LEFT JOIN ncontrulsub s ON s.codcontrul = c.codcontrul
    WHERE c.an*12+c.luna = &apos;||v_LunaStart||&apos; AND c.luna &gt; 1
      AND (s.subunitatea IS NULL &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;s&apos;,  pSUBUNIT =&gt; vSubunit, pPREFIX =&gt; &apos; OR&apos;)||&apos;)&apos;;

    sFCSold := &apos;
    INSERT INTO TMP_LIST_FCSOLD (
      codcont,
      debit, credit, debitv, creditv, sold, soldv,
      ifrs, ifrsv, sold_ifrs, sold_ifrsv,
      grup, grupv,
      sold_grup, sold_grupv,
      an, luna, subunitatea
    )
    SELECT
      c.codcont,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldid      ELSE s.soldid      END,0) debit,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldic      ELSE s.soldic      END,0) credit,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvid     ELSE s.soldvid     END,0) debitv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvic     ELSE s.soldvic     END,0) creditv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldid      ELSE s.soldid      END,0) -
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldic      ELSE s.soldic      END,0) sold,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvid     ELSE s.soldvid     END,0) -
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvic     ELSE s.soldvic     END,0) soldv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldi_ifrs  ELSE s.soldi_ifrs  END,0) ifrs,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvi_ifrs ELSE s.soldvi_ifrs END,0) ifrsv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldi_ifrs  ELSE s.soldi_ifrs  END,0) sold_ifrs,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvi_ifrs ELSE s.soldvi_ifrs END,0) sold_ifrsv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldi_grup  ELSE s.soldi_grup  END,0) grup,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvi_grup ELSE s.soldvi_grup END,0) grupv,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldi_grup  ELSE s.soldi_grup  END,0) sold_grup,
      Coalesce(CASE WHEN s.codcontsold IS NULL THEN c.soldvi_grup ELSE s.soldvi_grup END,0) sold_grupv,
      c.an, c.luna, &apos;||vSubTmp||&apos; subunitatea
    FROM ncontsold c
      LEFT JOIN ncontsoldsub s ON s.codcontsold = c.codcontsold
    WHERE c.an * 12 + c.luna = &apos;||v_lunai||&apos;
      AND (s.subunitatea IS NULL &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;s&apos;,  pSUBUNIT =&gt; vSubunit, pPREFIX =&gt; &apos; OR&apos;)||&apos;)&apos;;
  ELSE
    vSubTmp := &apos;1&apos;;
    vSubPar := &apos;&apos;;
    sFCRul  := &apos;
    INSERT INTO TMP_LIST_FCRUL (
      codcont,
      rulajpd, rulajpc, rulajcd, rulajcc,
      rulajvpd, rulajvpc, rulajvcd, rulajvcc,
      rulajp_ifrs, rulajc_ifrs, rulajvp_ifrs, rulajvc_ifrs,
      rulajp_grup, rulajc_grup, rulajvp_grup, rulajvc_grup,
      an, luna, subunitatea
    )
    SELECT
      c.codcont,
      Coalesce(c.rulajpd,     0) rulajpd,
      Coalesce(c.rulajpc,     0) rulajpc,
      Coalesce(c.rulajcd,     0) rulajcd,
      Coalesce(c.rulajcc,     0) rulajcc,
      Coalesce(c.rulajvpd,    0) rulajvpd,
      Coalesce(c.rulajvpc,    0) rulajvpc,
      Coalesce(c.rulajvcd,    0) rulajvcd,
      Coalesce(c.rulajvcc,    0) rulajvcc,
      Coalesce(c.rulajp_ifrs, 0) rulajp_ifrs,
      Coalesce(c.rulajc_ifrs, 0) rulajc_ifrs,
      Coalesce(c.rulajvp_ifrs,0) rulajvp_ifrs,
      Coalesce(c.rulajvc_ifrs,0) rulajvc_ifrs,
      Coalesce(c.rulajp_grup, 0) rulajp_grup,
      Coalesce(c.rulajc_grup, 0) rulajc_grup,
      Coalesce(c.rulajvp_grup,0) rulajvp_grup,
      Coalesce(c.rulajvc_grup,0) rulajvc_grup,
      c.an, c.luna, &apos;||vSubTmp||&apos; subunitatea
    FROM ncontrul c
    WHERE c.an*12+c.luna = &apos;||v_LunaStart||&apos; AND c.luna &gt; 1 &apos;;

    sFCSold := &apos;
    INSERT INTO TMP_LIST_FCSOLD (
      codcont,
      debit, credit, debitv, creditv, sold, soldv,
      ifrs, ifrsv, sold_ifrs, sold_ifrsv,
      grup, grupv,
      sold_grup, sold_grupv,
      an, luna, subunitatea
    )
    SELECT
      c.codcont,
      Coalesce(c.soldid,     0) debit,
      Coalesce(c.soldic,     0) credit,
      Coalesce(c.soldvid,    0) debitv,
      Coalesce(c.soldvic,    0) creditv,
      Coalesce(c.soldid,     0) -
      Coalesce(c.soldic,     0) sold,
      Coalesce(c.soldvid,    0) -
      Coalesce(c.soldvic,    0) soldv,
      Coalesce(c.soldi_ifrs, 0) ifrs,
      Coalesce(c.soldvi_ifrs,0) ifrsv,
      Coalesce(c.soldi_ifrs, 0) sold_ifrs,
      Coalesce(c.soldvi_ifrs,0) sold_ifrsv,
      Coalesce(c.soldi_grup, 0) grup,
      Coalesce(c.soldvi_grup,0) grupv,
      Coalesce(c.soldi_grup, 0) sold_grup,
      Coalesce(c.soldvi_grup,0) sold_grupv,
      c.an, c.luna, &apos;||vSubTmp||&apos; subunitatea
    FROM ncontsold c
    WHERE c.an * 12 + c.luna = &apos;||v_lunai;
  END IF;

  sInsAux :=
  &apos;INSERT INTO TMP_LIST_FISACONT (
    NAV_CODDOC, NAV_TIPDOC, CODCONT, CODCORESP, DEBIT, CREDIT, DEBITV, CREDITV, VALOARE, VALOAREV,
    SOLD, SOLDV,
    IFRS, IFRSV, SOLD_IFRS, SOLD_IFRSV,
    GRUP, GRUPV,
    SOLD_GRUP, SOLD_GRUPV,
    OBS, DOCUMENT, DATADOC, SUBUNITATEA, GEST, AN, LUNA,
    ORDINE,
    CODCENTRU, CODANALIZANOD, INDEXLOCAL )&apos;;

  IF v_TipPlan = 2 THEN -- plan secundar
    sTabCont := &apos;nconts&apos;;
    sCodCont := &apos;codconts&apos;;
    sInsAux := sInsAux||&apos;
    WITH n AS (
      SELECT c.codconts
      FROM nconts c
      WHERE EXISTS (SELECT 1 FROM nconts1 c1 WHERE c1.codconts = c.codconts AND c1.anstart*12+c1.lunastart &lt;= &apos;||v_LunaStop||&apos;)
      START WITH c.codconts IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCONT&apos;&apos;)
      CONNECT BY PRIOR c.codconts = c.codparinte)
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, c1.contsecundar, 0 codcoresp, sum(s.debit) debit,  sum(s.credit) credit, sum(s.debitv) debitv, sum(s.creditv) creditv, 0 valoare, 0 valoarev,
      sum(s.sold) sold, sum(s.soldv) soldv,
      sum(s.ifrs) ifrs, sum(s.ifrsv) ifrsv, sum(s.sold_ifrs) sold_ifrs, sum(s.sold_ifrsv) sold_ifrsv,
      sum(s.grup) grup, sum(s.grupv) grupv, sum(s.sold_grup) sold_grup, sum(s.sold_grupv) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||s.luna||&apos;&apos;.&apos;&apos;||s.an,&apos;&apos;dd.mm.yyyy&apos;&apos;) datadoc, s.subunitatea, 0 gest, s.an, s.luna,
       -1 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCSOLD s
      INNER JOIN NCONT1 C1 ON C1.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(s.codcont, Greatest(s.An*12+s.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n         ON n.codconts  = c1.contsecundar
    WHERE Coalesce(c1.contsecundar, 0) &gt; 0
    GROUP BY c1.contsecundar, s.subunitatea, s.an, s.luna
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, c1.contsecundar, 0 codcoresp,
      sum(Coalesce(r.rulajpd,0)) debit, sum(Coalesce(r.rulajpc,0)) credit, sum(Coalesce(r.rulajvpd,0)) debitv, sum(Coalesce(r.rulajvpc,0)) creditv, 0 valoare, 0 valoarev,
      sum(Coalesce(r.rulajpd,0) - Coalesce(r.rulajpc,0)) sold, sum(Coalesce(r.rulajvpd,0) - Coalesce(r.rulajvpc,0)) soldv,
      sum(Coalesce(r.rulajp_ifrs,0)) ifrs,  sum(Coalesce(r.rulajvp_ifrs,0)) ifrsv, sum(Coalesce(r.rulajp_ifrs,0)) sold_ifrs, sum(Coalesce(r.rulajvp_ifrs,0)) sold_ifrsv,
      sum(Coalesce(r.rulajp_grup,0)) grup,  sum(Coalesce(r.rulajvp_grup,0)) grupv,
      sum(Coalesce(r.rulajp_grup,0)) sold_grup, sum(Coalesce(r.rulajvp_grup,0)) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCRUL r
      INNER JOIN NCONT1 C1 ON C1.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(r.codcont, Greatest(r.An*12+r.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n         ON n.codconts  = c1.contsecundar
    WHERE Coalesce(c1.contsecundar, 0) &gt; 0
    GROUP BY c1.contsecundar, r.subunitatea, r.an, r.luna
    UNION ALL
    SELECT  -- tipinreg 2 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1d.contsecundar, c1c.contsecundar,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Coalesce(j.valoare,0) sold, Coalesce(j.valoarev,0) soldv,
      Coalesce(j.valoare_ifrs,0) ifrs, Coalesce(j.valoarev_ifrs,0) ifrsv, Coalesce(j.valoare_ifrs,0) sold_ifrs, Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      Coalesce(j.valoaregrup,0) grup, Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END grupv,
      Coalesce(j.valoaregrup,0) sold_grup, Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruS, 0) WHEN 0 THEN Coalesce(C1C.CodCentruS,0) ELSE C1D.CodCentruS END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1d.contsecundar
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.contsecundar, 0) &gt; 0
      AND Coalesce(C1C.contsecundar, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 2 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1c.contsecundar, c1d.contsecundar,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      -Coalesce(j.valoare,0) sold, -Coalesce(j.valoarev,0) soldv,
      -Coalesce(j.valoare_ifrs,0) ifrs, -Coalesce(j.valoarev_ifrs,0) ifrsv, -Coalesce(j.valoare_ifrs,0) sold_ifrs, -Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      -Coalesce(j.valoaregrup,0) grup, -Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END grupv,
      -Coalesce(j.valoaregrup,0) sold_grup, -Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruS, 0) WHEN 0 THEN Coalesce(C1C.CodCentruS,0) ELSE C1D.CodCentruS END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1c.contsecundar
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.contsecundar, 0) &gt; 0
      AND Coalesce(C1C.contsecundar, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 3 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1d.CONTSECUNDARG, c1c.CONTSECUNDARG,
      Coalesce(J.ValoareGrup, J.Valoare) debit, 0 credit, j.valoarev debitv, 0 creditv, Coalesce(J.ValoareGrup, J.Valoare), j.valoarev,
      Coalesce(J.ValoareGrup, J.Valoare,0) sold, Coalesce(j.valoarev,0) soldv,
      Coalesce(j.valoare_ifrs,0) ifrs, Coalesce(j.valoarev_ifrs,0) ifrsv, Coalesce(j.valoare_ifrs,0) sold_ifrs, Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      Coalesce(j.valoaregrup,0) grup, Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END grupv,
      Coalesce(j.valoaregrup,0) sold_grup, Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruSG, 0) WHEN 0 THEN Coalesce(C1C.CodCentruSG,0) ELSE C1D.CodCentruS END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1d.CONTSECUNDARG
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTSECUNDARG, 0) &gt; 0
      AND Coalesce(C1C.CONTSECUNDARG, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 3 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1c.CONTSECUNDARG, c1d.CONTSECUNDARG,
      0 debit, Coalesce(J.ValoareGrup, J.Valoare) credit, 0 debitv, j.valoarev creditv, Coalesce(J.ValoareGrup, J.Valoare), j.valoarev,
      -Coalesce(J.ValoareGrup, J.Valoare,0) sold, -Coalesce(j.valoarev,0) soldv,
      -Coalesce(j.valoare_ifrs,0) ifrs, -Coalesce(j.valoarev_ifrs,0) ifrsv, -Coalesce(j.valoare_ifrs,0) sold_ifrs, -Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      -Coalesce(j.valoaregrup,0) grup, -Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END grupv,
      -Coalesce(j.valoaregrup,0) sold_grup, -Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruSG, 0) WHEN 0 THEN Coalesce(C1C.CodCentruSG,0) ELSE C1D.CodCentruSG END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1c.CONTSECUNDARG
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTSECUNDARG, 0) &gt; 0
      AND Coalesce(C1C.CONTSECUNDARG, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 4 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1d.CONTSECUNDARG, c1c.CONTSECUNDARG,
      Coalesce(J.ValoareGrup, J.Valoare) debit, 0 credit, j.valoarev debitv, 0 creditv, Coalesce(J.ValoareGrup, J.Valoare), j.valoarev,
      Coalesce(J.ValoareGrup, J.Valoare,0) sold, Coalesce(j.valoarev,0) soldv,
      Coalesce(j.valoare_ifrs,0) ifrs, Coalesce(j.valoarev_ifrs,0) ifrsv, Coalesce(j.valoare_ifrs,0) sold_ifrs, Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      Coalesce(j.valoaregrup,0) grup,
      Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END grupv,
      Coalesce(j.valoaregrup,0) sold_grup, Coalesce(j.valoaregrup,0)*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruSGO, 0) WHEN 0 THEN Coalesce(C1C.CodCentruSGO,0) ELSE C1D.CodCentruSGO END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1d.CONTSECUNDARGO
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTSECUNDARGO, 0) &gt; 0
      AND Coalesce(C1C.CONTSECUNDARGO, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 4 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1c.CONTSECUNDARG, c1d.CONTSECUNDARG,
      0 debit, Coalesce(J.ValoareGrup, J.Valoare) credit, 0 debitv, j.valoarev creditv, Coalesce(J.ValoareGrup, J.Valoare), j.valoarev,
      -Coalesce(J.ValoareGrup, J.Valoare,0) sold, -Coalesce(j.valoarev,0) soldv,
      -Coalesce(j.valoare_ifrs,0) ifrs, -Coalesce(j.valoarev_ifrs,0) ifrsv, -Coalesce(j.valoare_ifrs,0) sold_ifrs, -Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      -Coalesce(j.valoaregrup,0) grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) grupv,
      -Coalesce(j.valoaregrup,0) sold_grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruSGO, 0) WHEN 0 THEN Coalesce(C1C.CodCentruSGO,0) ELSE C1D.CodCentruSGO END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codconts   = c1c.CONTSECUNDARGO
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTSECUNDARGO, 0) &gt; 0
      AND Coalesce(C1C.CONTSECUNDARGO, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit);
  ELSIF v_TipPlan = 3 THEN -- plan tertiar
    sTabCont := &apos;ncontt&apos;;
    sCodCont := &apos;codcontt&apos;;
    sInsAux := sInsAux||&apos;
    WITH n AS (
      SELECT c.codcontt
      FROM ncontt c
      WHERE EXISTS (SELECT 1 FROM ncontt1 c1 WHERE c1.codcontt = c.codcontt AND c1.anstart*12+c1.lunastart &lt;= &apos;||v_LunaStop||&apos;)
      START WITH c.codcontt IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCONT&apos;&apos;)
      CONNECT BY PRIOR c.codcontt = c.codparinte)
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, c1.conttertiar, 0 codcoresp, sum(s.debit) debit,  sum(s.credit) credit, sum(s.debitv) debitv, sum(s.creditv) creditv, 0 valoare, 0 valoarev,
      sum(s.sold) sold, sum(s.soldv) soldv,
      sum(s.ifrs) ifrs, sum(s.ifrsv) ifrsv, sum(s.sold_ifrs) sold_ifrs, sum(s.sold_ifrsv) sold_ifrsv,
      sum(s.grup) grup, sum(s.grupv) grupv,
      sum(s.sold_grup) sold_grup, sum(s.sold_grupv) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||s.luna||&apos;&apos;.&apos;&apos;||s.an,&apos;&apos;dd.mm.yyyy&apos;&apos;) datadoc, s.subunitatea, 0 gest, s.an, s.luna,
       -1 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCSOLD s
      INNER JOIN NCONT1 C1 ON C1.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(s.codcont, Greatest(s.An*12+s.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n         ON n.codcontt  = c1.conttertiar
    WHERE Coalesce(c1.conttertiar, 0) &gt; 0
    GROUP BY c1.conttertiar, s.subunitatea, s.an, s.luna
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, c1.conttertiar, 0 codcoresp,
      sum(Coalesce(r.rulajpd,0)) debit, sum(Coalesce(r.rulajpc,0)) credit, sum(Coalesce(r.rulajvpd,0)) debitv, sum(Coalesce(r.rulajvpc,0)) creditv, 0 valoare, 0 valoarev,
      sum(Coalesce(r.rulajpd,0) - Coalesce(r.rulajpc,0)) sold, sum(Coalesce(r.rulajvpd,0) - Coalesce(r.rulajvpc,0)) soldv,
      sum(Coalesce(r.rulajp_ifrs,0)) ifrs, sum(Coalesce(r.rulajvp_ifrs,0)) ifrsv, sum(Coalesce(r.rulajp_ifrs,0)) sold_ifrs, sum(Coalesce(r.rulajvp_ifrs,0)) sold_ifrsv,
      sum(Coalesce(r.rulajp_grup,0)) grup, sum(Coalesce(r.rulajvp_grup,0)) grupv,
      sum(Coalesce(r.rulajp_grup,0)) sold_grup, sum(Coalesce(r.rulajvp_grup,0)) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCRUL r
      INNER JOIN NCONT1 C1 ON C1.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(r.codcont, Greatest(r.An*12+r.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n         ON n.codcontt  = c1.conttertiar
    WHERE Coalesce(c1.conttertiar, 0) &gt; 0
    GROUP BY c1.conttertiar, r.subunitatea, r.an, r.luna
    UNION ALL
    SELECT -- tipinreg 5 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1d.conttertiar, c1c.conttertiar,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Coalesce(j.valoare,0) sold, Coalesce(j.valoarev,0) soldv,
      Coalesce(j.valoare_ifrs,0) ifrs, Coalesce(j.valoarev_ifrs,0) ifrsv, Coalesce(j.valoare_ifrs,0) sold_ifrs, Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      Coalesce(j.valoaregrup,0) grup, Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) grupv,
      Coalesce(j.valoaregrup,0) sold_grup, Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruS, 0) WHEN 0 THEN Coalesce(C1C.CodCentruS,0) ELSE C1D.CodCentruS END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codcontt   = c1d.conttertiar
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTTERTIAR, 0) &gt; 0
      AND Coalesce(C1C.CONTTERTIAR, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT -- tipinreg 5 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, c1c.conttertiar, c1d.conttertiar,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Coalesce(-j.valoare,0) sold, Coalesce(-j.valoarev,0) soldv,
      -Coalesce(j.valoare_ifrs,0) ifrs, -Coalesce(j.valoarev_ifrs,0) ifrsv, -Coalesce(j.valoare_ifrs,0) sold_ifrs, -Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      -Coalesce(j.valoaregrup,0) grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) grupv,
      -Coalesce(j.valoaregrup,0) sold_grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      CASE Coalesce(C1D.CodCentruS, 0) WHEN 0 THEN Coalesce(C1C.CodCentruS,0) ELSE C1D.CodCentruS END codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContD, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_ANLUNA(J.ContC, Greatest(J.An*12+J.Luna,&apos;||vAnLunaMin||&apos;))
      INNER JOIN n          ON n.codcontt   = c1c.conttertiar
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos;
      AND Coalesce(C1D.CONTTERTIAR, 0) &gt; 0
      AND Coalesce(C1C.CONTTERTIAR, 0) &gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit);
  ELSE -- plan principal
    sTabCont := &apos;ncont&apos;;
    sCodCont := &apos;codcont&apos;;
    sInsAux := sInsAux||&apos;
    WITH n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||v_LunaStop||&apos;)
      START WITH c.codcont IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCONT&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, s.codcont, 0 codcoresp, 0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      sum(s.sold) sold, sum(s.soldv) soldv,
      sum(s.ifrs) ifrs, sum(s.ifrsv) ifrsv, sum(s.sold_ifrs) sold_ifrs, sum(s.sold_ifrsv) sold_ifrsv,
      sum(s.grup) grup, sum(s.grupv) grupv,
      sum(s.sold_grup) sold_grup, sum(s.sold_grupv) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||s.luna||&apos;&apos;.&apos;&apos;||s.an,&apos;&apos;dd.mm.yyyy&apos;&apos;) datadoc, s.subunitatea, 0 gest, s.an, s.luna,
       -1 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCSOLD s
      INNER JOIN n ON n.codcont = s.codcont
    GROUP BY s.codcont, s.subunitatea, s.an, s.luna
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      sum(Coalesce(r.rulajpd,0)) debit, sum(Coalesce(r.rulajpc,0)) credit, sum(Coalesce(r.rulajvpd,0)) debitv, sum(Coalesce(r.rulajvpc,0)) creditv, 0 valoare, 0 valoarev,
      sum(Coalesce(r.rulajpd,0) - Coalesce(r.rulajpc,0)) sold, sum(Coalesce(r.rulajvpd,0) - Coalesce(r.rulajvpc,0)) soldv,
      sum(Coalesce(r.rulajp_ifrs,0)) ifrs,  sum(Coalesce(r.rulajvp_ifrs,0)) ifrsv, sum(Coalesce(r.rulajp_ifrs,0)) sold_ifrs, sum(Coalesce(r.rulajvp_ifrs,0)) sold_ifrsv,
      sum(Coalesce(r.rulajp_grup,0)) grup,  sum(Coalesce(r.rulajvp_grup,0)) grupv,
      sum(Coalesce(r.rulajp_grup,0)) sold_grup, sum(Coalesce(r.rulajvp_grup,0)) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 codanalizanod, 0 indexlocal
    FROM TMP_LIST_FCRUL r
      INNER JOIN n ON n.codcont = r.codcont
    GROUP BY r.codcont, r.subunitatea, r.an, r.luna
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Coalesce(j.valoare,0) sold, Coalesce(j.valoarev,0) soldv,
      Coalesce(j.valoare_ifrs,0) ifrs, Coalesce(j.valoarev_ifrs,0) ifrsv, Coalesce(j.valoare_ifrs,0) sold_ifrs, Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      Coalesce(j.valoaregrup,0) grup, Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) grupv,
      Coalesce(j.valoaregrup,0) sold_grup, Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos; &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Coalesce(-j.valoare,0) sold, Coalesce(-j.valoarev,0) soldv,
      -Coalesce(j.valoare_ifrs,0) ifrs, -Coalesce(j.valoarev_ifrs,0) ifrsv, -Coalesce(j.valoare_ifrs,0) sold_ifrs, -Coalesce(j.valoarev_ifrs,0) sold_ifrsv,
      -Coalesce(j.valoaregrup,0) grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) grupv,
      -Coalesce(j.valoaregrup,0) sold_grup, -Coalesce(j.valoaregrup*CASE WHEN j.valoare = 0 THEN 1 WHEN j.valoarev = 0 THEN 1 ELSE j.valoarev/j.valoare END,0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.codanalizanod, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||v_LunaStart||&apos; AND &apos;||v_LunaStop||&apos; &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit);
  END IF;

  -- pentru mifix se schimba coddoc ( codnirstoc pt luna curenta si 0 in rest)
  sMfUpd := 
  &apos;UPDATE TMP_LIST_FISACONT tmf 
  SET nav_coddoc = ( 
                     SELECT
                       CASE
                         WHEN mf1.anstart = PKG_GLOBALS.GetANLUCRU() AND mf1.lunastart = PKG_GLOBALS.GetLUNALUCRU() THEN mf1.codnirstoc
                         ELSE 0
                       END
                     FROM mifix1 mf1
                     WHERE mf1.codmifix  = tmf.nav_coddoc
                       AND mf1.anstart   = tmf.an
                       AND mf1.lunastart = tmf.luna
                       AND rownum=1
                   )
  WHERE tmf.nav_coddoc &lt;&gt; 0 
    AND tmf.nav_tipdoc = 36&apos;;

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LIST_FCSOLD&apos;,   0, 0);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LIST_FCRUL&apos;,    0, 0);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LIST_FISACONT&apos;, 0, 0);

  LIST_EXECUTE_IMMEDIATE(sFCSold,   0, 0);
  LIST_EXECUTE_IMMEDIATE(sFCRul,    0, 0);
  LIST_EXECUTE_IMMEDIATE(sInsAux,   0, 0);
  LIST_EXECUTE_IMMEDIATE(sMfUpd,    0, 0);

  PKG_LIST_BASE_UTILS.CLEAR_SIMBOL_LIPSA;
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_NCONT1_BAL&apos;,    0, 0);

  IF v_TipPlan = 2 THEN -- plan secundar
    INSERT INTO TMP_NCONT1_BAL (CODCONT, SIMBOLPLANP, FRUNZA)
    SELECT C.CODCONT, C.SIMBOL, CASE WHEN EXISTS(SELECT 1 FROM NCONT WHERE CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND v_LunaStop BETWEEN C1.ALSTART and C1.ALSTOP
    WHERE Coalesce(C1.CONTSECUNDAR,0) = 0
      AND NOT EXISTS (SELECT CONTVECHI FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_LunaStop);
  ELSIF v_TipPlan = 3 THEN -- plan tertiar
    INSERT INTO TMP_NCONT1_BAL (CODCONT, SIMBOLPLANP, FRUNZA)
    SELECT C.CODCONT, C.SIMBOL, CASE WHEN EXISTS(SELECT 1 FROM NCONT WHERE CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND v_LunaStop BETWEEN C1.ALSTART and C1.ALSTOP
    WHERE Coalesce(C1.CONTTERTIAR,0) = 0
      AND NOT EXISTS (SELECT CONTVECHI FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_LunaStop);
  END IF;

  DELETE TMP_NCONT1_BAL WHERE FRUNZA = 0;

  IF v_TipPlan &gt; 1 THEN
    INSERT INTO TMP_LIPSA_CORESP_PLANP (SIMBOL)
    SELECT DISTINCT t.SIMBOLPLANP
    FROM ncontrul x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.codcont
    WHERE an * 12 + luna = v_LunaStart AND luna &gt; 1
      AND (
        Coalesce(rulajpd,0) &lt;&gt; 0 OR Coalesce(rulajpc,0) &lt;&gt; 0 OR Coalesce(rulajcd,0) &lt;&gt; 0 OR Coalesce(rulajcc,0) &lt;&gt; 0 OR
        Coalesce(rulajvpd,0) &lt;&gt; 0 OR Coalesce(rulajvpc,0) &lt;&gt; 0 OR Coalesce(rulajvcd,0) &lt;&gt; 0 OR Coalesce(rulajvcc,0) &lt;&gt; 0 OR
        Coalesce(rulajp_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajc_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajvp_ifrs,0) &lt;&gt; 0 OR Coalesce(rulajvc_ifrs,0) &lt;&gt; 0
      )
    UNION
    SELECT DISTINCT t.SIMBOLPLANP
    FROM ncontsold x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.codcont
    WHERE an * 12 + luna = v_lunai
      AND (Coalesce(soldid,0) &lt;&gt; 0 OR Coalesce(soldic,0) &lt;&gt; 0 OR Coalesce(soldvid,0) &lt;&gt; 0 OR Coalesce(soldvic,0) &lt;&gt; 0 OR Coalesce(soldi_ifrs,0) &lt;&gt; 0 OR Coalesce(soldvi_ifrs,0) &lt;&gt; 0)
    UNION
    SELECT DISTINCT t.SIMBOLPLANP
    FROM JURNAL x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.contd
    WHERE an *12 + luna BETWEEN v_LunaStart AND v_LunaStop
      AND (Coalesce(valoare,0) &lt;&gt; 0 OR Coalesce(valoarev,0) &lt;&gt; 0 OR Coalesce(valoare_ifrs,0) &lt;&gt; 0 OR Coalesce(valoarev_ifrs,0) &lt;&gt; 0)
    UNION
    SELECT DISTINCT t.SIMBOLPLANP
    FROM JURNAL x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.contc
    WHERE an *12 + luna BETWEEN v_LunaStart AND v_LunaStop
      AND (Coalesce(valoare,0) &lt;&gt; 0 OR Coalesce(valoarev,0) &lt;&gt; 0 OR Coalesce(valoare_ifrs,0) &lt;&gt; 0 OR Coalesce(valoarev_ifrs,0) &lt;&gt; 0);
  END IF;

  COMMIT;
END;

PROCEDURE PROCESSLIST(TMpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(30000);
  sSelect     VARCHAR2(30000);
  sTabCont    VARCHAR2(20);
  sCodCont    VARCHAR2(20);
  sObsDoc     VARCHAR2(500)  := &apos;, NULL ObsDoc&apos;;
  sCursRef    VARCHAR2(500)  := &apos;, 1 CURS_REF&apos;;
  aSitV       NUMBER(1);
  aBancaV     NUMBER(20);
  aMonedaV    NUMBER(20);
BEGIN
  gSuplCols := &apos;tmp_list_fisacont fc, ngest g, nsubunit s, centrecost c&apos; ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;, &apos;NP&apos;, &apos;NP.CODPART = PKG_LIST_BASE_UTILS.GetPartDoc(CASE WHEN j.tipdoc IN (29,30,31,33) THEN fc.indexlocal ELSE fc.nav_coddoc END, fc.nav_tipdoc)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_FISACONT.UTIL_FISACONT(sTabCont, sCodCont);
  IF pkg_list_selcont.getCuObs THEN
    sObsDoc := &apos;,
    pkg_list_base_utils.GetObsDoc(fc.nav_coddoc,fc.nav_tipdoc,fc.indexlocal) ObsDoc&apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCursRef   := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, fc.datadoc ) CURS_REF&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CODDOC, NAV_TIPDOC, ORDINE,
    CODCONT, CONT, CORESP, DEN_CONT,NAME_CONT,DEN_CORESP,NAME_CORESP,
    DEBIT,CREDIT,VALOARE,NSOLD,TIPSOLD,
    DEBITV,CREDITV,VALOAREV,SOLDV,TIPSOLDV,
    V_IFRS, V_IFRSV, IFRS_SOLD, IFRSV_SOLD,
    GRUP, GRUPV,
    SOLD_GRUP, SOLD_GRUPV,
    OBS,DOCUMENT_LST,DATADOC,SUBUNITATEA,DEN_GEST,
    LUNA,
    CentruCost, SimbCentruCost,
    ObsDoc, Curs_Ref&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH fc AS (
    SELECT
      t.nav_coddoc, t.nav_tipdoc, t.codcont, t.codcoresp, t.debit, t.credit, t.debitv, t.creditv, t.valoare, t.valoarev,
      Sum(t.sold)  OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sold,
      Sum(t.soldv) OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) soldv,
      t.obs, t.document, t.datadoc, t.subunitatea, t.gest, t.an, t.luna, t.codcentru,
      Row_Number() OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE) ORDINE,
      t.indexlocal, t.ifrs, t.ifrsv,
      Sum(t.sold_ifrs)  OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sold_ifrs,
      Sum(t.sold_ifrsv) OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sold_ifrsv,
      t.grup, t.grupv,
      Sum(t.sold_grup)  OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sold_grup,
      Sum(t.sold_grupv) OVER (PARTITION BY t.codcont&apos;||vSubPar||&apos; ORDER BY t.DATADOC, cc.CLASA, t.ORDINE ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sold_grupv,
      t.curs_doc, t.codmoneda_doc, t.val_doc, t.codanalizanod
    FROM tmp_list_fisacont t LEFT JOIN &apos;||sTabCont||&apos; cc ON cc.&apos;||sCodCont||&apos; = t.codcoresp
  )
  SELECT
    fc.NAV_CODDOC, fc.NAV_TIPDOC, fc.ORDINE,
    fc.codcont, N1.SIMBOL CONT, N2.SIMBOL CORESP, N1.DEN_CONT DEN_CONT, N1.NAME NAME_CONT, N2.DEN_CONT DEN_CORESP, N2.NAME NAME_CORESP,
    fc.DEBIT, fc.CREDIT, fc.VALOARE, ABS(fc.SOLD),
    CASE WHEN fc.SOLD &gt; 0 THEN &apos;&apos;D&apos;&apos; WHEN fc.SOLD &lt; 0 THEN &apos;&apos;C&apos;&apos; WHEN N1.TIPCONT = 1 THEN &apos;&apos;C&apos;&apos; ELSE &apos;&apos;D&apos;&apos; END TIPSOLD,
    fc.DEBITV, fc.CREDITV, fc.VALOAREV, ABS(fc.SOLDV),
    CASE WHEN fc.SOLDV &gt; 0 THEN &apos;&apos;D&apos;&apos; WHEN fc.SOLDV &lt; 0 THEN &apos;&apos;C&apos;&apos; WHEN N1.TIPCONT = 1 THEN &apos;&apos;C&apos;&apos; ELSE &apos;&apos;D&apos;&apos; END TIPSOLD,
    fc.ifrs, fc.ifrsv, fc.sold_ifrs, fc.sold_ifrsv,
    fc.grup, fc.grupv,
    fc.sold_grup, fc.sold_grupv,
    fc.OBS, fc.DOCUMENT, fc.DATADOC, S.DEN_SUBUNIT,G.DEN_GEST,
    to_char(fc.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(fc.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(fc.Luna) luna,
    c.denumire, c.simbol &apos;||sObsDoc||sCursRef||gUserAlias||&apos;
  FROM fc
    LEFT JOIN &apos;||sTabCont||&apos; n1 ON n1.&apos;||sCodCont||&apos; = fc.codcont
    LEFT JOIN &apos;||sTabCont||&apos; n2 ON n2.&apos;||sCodCont||&apos; = fc.codcoresp
    LEFT JOIN ngest          g  ON g.codgest         = fc.gest
    LEFT JOIN nsubunit       s  ON s.codsubunit      = fc.subunitatea
    LEFT JOIN centrecost     c  on c.codcentru       = Coalesce(fc.codcentru,0)&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_FISACONT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38A023D47C901013B04A7EDB1E4BA870360C3171</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISACONT2 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  v_LunaStart NUMBER(20) := Coalesce(PKG_LIST_SELCONT.GetLunaStart, 0);
  v_LunaStop  NUMBER(20) := Coalesce(PKG_LIST_SELCONT.GetLunaStop,  0);
  i           NUMBER(20);
  k           NUMBER(20) := 0;
  An          NUMBER(4);
  Luna        NUMBER(2);
BEGIN
  DELETE tmp_dinamic_cols;
  IF v_LunaStart &gt; 0 THEN
    PKG_LIST_BASE_UTILS.ExtractAnLuna(v_LunaStart, An, Luna);
    FOR i IN v_LunaStart..v_LunaStop
    LOOP
      k := k + 1;
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) VALUES (&apos;D&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;D-&apos;||An||&apos;.&apos;||Luna,k,i,0);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;C-&apos;||An||&apos;.&apos;||Luna,k,i,1);
      PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(An, Luna, An, Luna);
    END LOOP;
  END IF;
  COMMIT;
END;

PROCEDURE PROCESSLIST(TMpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(30000);
  sSelect     VARCHAR2(30000);
  sTabCont    VARCHAR2(20);
  sCodCont    VARCHAR2(20);
BEGIN
  gSuplCols := &apos;tmp_list_fisacont fc, ngest g, nsubunit s, centrecost c&apos; ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_FISACONT.UTIL_FISACONT(sTabCont, sCodCont);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CODDOC, NAV_TIPDOC,
    CODCONT, CONT, CORESP, DEN_CONT,NAME_CONT,DEN_CORESP,NAME_CORESP,
    DEBIT,CREDIT,VALOARE,
    DEBITV,CREDITV,VALOAREV,
    OBS,DOCUMENT,DATADOC,SUBUNITATEA,DEN_GEST,
    LUNA,
    CentruCost, SimbCentruCost&apos;;

  FOR vRec IN (
    SELECT FieldName, Cod, Decode(Cod2,0,&apos;fc.DEBIT&apos;,&apos;fc.CREDIT&apos;) Camp
    FROM tmp_dinamic_cols
    ORDER BY IndexLocal)
  LOOP
    sInsert := sInsert ||&apos;,
    &apos;||vRec.FieldName;

    sSelect := sSelect ||&apos;,
    CASE WHEN fc.an*12+fc.luna = &apos;||vRec.Cod||&apos; THEN &apos;||vRec.Camp||&apos; ELSE 0 END &apos;||vRec.FieldName;
  END LOOP;

  sInsert := sInsert||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    fc.NAV_CODDOC, fc.NAV_TIPDOC,
    fc.codcont, N1.SIMBOL CONT, N2.SIMBOL CORESP, N1.DEN_CONT DEN_CONT, N1.NAME NAME_CONT, N2.DEN_CONT DEN_CORESP, N2.NAME NAME_CORESP,
    fc.DEBIT, fc.CREDIT, fc.VALOARE,
    fc.DEBITV, fc.CREDITV, fc.VALOAREV,
    fc.OBS, fc.DOCUMENT, fc.DATADOC, S.DEN_SUBUNIT, G.DEN_GEST,
    to_char(fc.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(fc.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(fc.Luna) luna,
    c.denumire, c.simbol&apos;||sSelect||gUserAlias||&apos;
  FROM tmp_list_fisacont fc
    LEFT JOIN &apos;||sTabCont||&apos; n1 ON n1.&apos;||sCodCont||&apos; = fc.codcont
    LEFT JOIN &apos;||sTabCont||&apos; n2 ON n2.&apos;||sCodCont||&apos; = fc.codcoresp
    LEFT JOIN ngest g ON g.codgest = fc.gest
    LEFT JOIN nsubunit s ON s.codsubunit = fc.subunitatea
    LEFT JOIN centrecost c on c.codcentru = NVL(fc.codcentru,0)&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_FISACONT2;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISACONT3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E82B783D911A31137C64C3018F49FCF7A595DE89</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISACONT3 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  NiveleANod  NUMBER(20);

PROCEDURE PROCESSLIST(TMpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
  sInsertDC VARCHAR2( 5000);
  sSelectDC VARCHAR2( 5000);
  sJoinDC   VARCHAR2( 5000);
  sTree     VARCHAR2( 3200);
  sAux      VARCHAR2(  200);
  sIDX      VARCHAR2(   50);
  
  p_Plan    NUMBER(1);
  p_LunaIni NUMBER(5);
  p_LunaFin NUMBER(5);
  p_Subunit NUMBER(20);
  p_Index     BOOLEAN;
BEGIN
  NiveleANod  := pkg_list_base_utils.NIVELE_ANALIZA;

  gSuplCols := &apos;TMP_LST_JURNAL1 T, NPART P,NAGENDA SED,NPARTCODFISC CIF,NCLASEP CLSP,NARTOBJ OBJ, ANALIZANOD ANOD,ANALIZA ANALIZ,DESCRIPTORI1 ADESC1,DESCRIPTORI ADESC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;, &apos;C1D&apos;, &apos;C1D.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(CD.CODCONT, T.AN, T.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSD&apos;, &apos;CSD.CODCONTS = C1D.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;, &apos;C1C&apos;, &apos;C1C.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(CC.CODCONT, T.AN, T.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSC&apos;, &apos;CSC.CODCONTS = C1C.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSC&apos;, &apos;CSC.CODCONTS = C1C.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;, &apos;UT&apos;, &apos;UT.CODUTILIZATOR = T.USERID&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  p_Plan    := pkg_list_base_regjurnal.Plan;
  p_LunaIni := pkg_list_base_regjurnal.LunaIni;
  p_LunaFin := pkg_list_base_regjurnal.LunaFin;
  p_Index   := pkg_list_base_regjurnal.isIndex;

  p_Subunit := CASE WHEN pkg_list_base_regjurnal.SubCurenta = 1 THEN pkg_globals.GETSUBUNITATE ELSE 1 END;

  pkg_list_utilfisacont.UMPLE_TMP_LST_JURNAL1(p_Plan, p_LunaIni, p_LunaFin, p_Subunit, aLISTID);

  pkg_list_base_realgest.ver_col_analiza(tmpName,Coalesce(NiveleANod,0));
  sSelectDC := &apos;&apos;;
  sInsertDC := &apos;&apos;;
  sJoinDC   := &apos;&apos;;
  sTree     := &apos;&apos;;
  sIDX      := &apos;,null as idx&apos;;
  IF Nvl(NiveleANod,0) &gt; 0 THEN
    sJoinDC := &apos;
    LEFT JOIN (
      SELECT
        CodAnalizaNod, IDX&apos;;
    FOR i IN 1..NiveleANod LOOP
      sInsertDC := sInsertDC||&apos;, NA&apos;||to_char(i);
      sSelectDC := sSelectDC||&apos;, DC.NA&apos;||to_char(i);
      sJoinDC := sJoinDC ||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN valoare ELSE NULL end) NA&apos;||to_char(i);
      if i = 1 then  
        sTree := &apos;,DC.NA&apos;||to_char(i);
      else
        sAux := &apos;&apos;;
        for j in 1..3*i loop
          sAux := sAux||&apos; &apos;;
        end loop;
        sTree := sTree||&apos;||chr(13)||&apos;&apos;&apos;||sAux||&apos;&apos;&apos;||TRIM(DC.NA&apos;||to_char(i)||&apos;)&apos;;
      end if;
    END LOOP;
    sJoinDC := sJoinDC ||&apos;
      FROM TMP_TREE_ANALIZANOD
      GROUP BY CodAnalizaNod,IDX
    ) DC ON DC.CodAnalizaNod = t.CodAnalizaNod &apos;;
    sIDX      := &apos;,dc.idx as idx&apos;;
  ELSE
    sTree := &apos;,null&apos;;  
  END IF;

  if p_Index then
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
       NAV_CodDoc,
       NAV_TipDoc,
       Partener,
       DOC,
       DATADOC,
       ARTICOL,
       DocLegatura,
       Cant,
       Pret,
       VALOARE,
       CONT,
       CORESP,
       DATACREARE,
       SUBUNITATEA,
       EXPLICATII,
       GESTIUNE,
       ORDINE,
       CENTRUCOST,
       CENTRUCOSTSIMB,
       INDEXLOCAL,
       TIPDOC,
       IDX,
       XTREE
      &apos;||sInsertDC||gUserFields||&apos;)&apos;;
    sSelect := &apos;
    select
      t.coddoc,
      t.tipdoc,
      p.Den_Part,
      t.DOCUMENT,
      t.DATADOC,
      t.ARTICOL,
      t.DocLegatura,
      t.Cant,
      t.Pret,
      t.VALOARE,
      CD.SIMBOL,
      CC.SIMBOL,
      T.DATACREARE,
      S.Den_subunit,
      t.obs,
      ng.den_gest,
      t.tipdoc + DECODE(t.tipdoc,32,100,0),
      c.denumire,
      c.simbol,
      J.INDEXLOCAL,
      PKG_LIST_BASE_UTILS.DECODE_TIPDOC(t.TIPDOC)&apos;||sIDX||sTree||sSelectDC||gUserAlias||&apos;
    from tmp_lst_jurnal1 t
         inner join ncont CD on CD.codcont = t.codcontd
         inner join ncont CC on CC.codcont = t.codcontc
         inner join nsubunit s on t.subunitatea = s.codsubunit
         INNER JOIN jurnal j on nvl(t.coddoc,0) = nvl(j.coddoc,0) and nvl(t.tipdoc,0) = nvl(j.tipdoc,0) and t.codcontd = j.contd
                            and t.codcontc = j.contc and nvl(t.gest,0) = nvl(j.gest,0) and t.an*12+t.luna = j.an*12+j.luna
                            and t.subunitatea = j.subunitatea and nvl(t.codcentru,0) = nvl(j.codcentru,0) and nvl(t.codanalizanod,0)=nvl(j.codanalizanod,0)
         LEFT  JOIN ngest ng on ng.codgest = NVL(t.gest,0)
         LEFT  JOIN centrecost c on c.codcentru = t.codcentru
         LEFT JOIN NPART P ON P.CODPART = t.CODPART
         LEFT JOIN NAGENDA SED ON SED.CODAGENDA = t.CODAGENDA
         LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = t.COD_CODFISCAL
         LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
         LEFT JOIN NARTOBJ OBJ ON T.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = t.codanalizanod
         LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
         LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
         LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor&apos;||
    sJoinDC||gSuplJoins||&apos;
    where t.tipdoc in (1,2,3,5,7,9,12,13,14,15,19,20,24,25,26,28,52)
    union all
    select
      t.coddoc,
      t.tipdoc,
      p.Den_Part,
      t.DOCUMENT,
      t.DATADOC,
      t.ARTICOL,
      t.DocLegatura,
      t.Cant,
      t.Pret,
      t.VALOARE,
      CD.SIMBOL,
      CC.SIMBOL,
      T.DATACREARE,
      S.Den_subunit,
      t.obs,
      ng.den_gest,
      t.tipdoc + DECODE(t.tipdoc,32,100,0),
      c.denumire,
      c.simbol,
      0,
      PKG_LIST_BASE_UTILS.DECODE_TIPDOC(t.TIPDOC)&apos;||sIDX||sTree||sSelectDC||gUserAlias||&apos;
    from tmp_lst_jurnal1 t
         inner join ncont CD on CD.codcont = t.codcontd
         inner join ncont CC on CC.codcont = t.codcontc
         inner join nsubunit s on t.subunitatea = s.codsubunit
         LEFT  JOIN ngest ng on ng.codgest = NVL(t.gest,0)
         LEFT  JOIN centrecost c on c.codcentru = t.codcentru
         LEFT JOIN NPART P ON P.CODPART = t.CODPART
         LEFT JOIN NAGENDA SED ON SED.CODAGENDA = t.CODAGENDA
         LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = t.COD_CODFISCAL
         LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
         LEFT JOIN NARTOBJ OBJ ON T.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = t.codanalizanod
         LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
         LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
         LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor&apos;||
    sJoinDC||gSuplJoins||&apos;
    where t.tipdoc = 0
    union all
    select
      t.coddoc,
      t.tipdoc,
      p.Den_Part,
      t.DOCUMENT,
      t.DATADOC,
      t.ARTICOL,
      t.DocLegatura,
      t.Cant,
      t.Pret,
      t.VALOARE,
      CD.SIMBOL,
      CC.SIMBOL,
      T.DATACREARE,
      S.Den_subunit,
      t.obs,
      ng.den_gest,
      t.tipdoc + DECODE(t.tipdoc,32,100,0),
      c.denumire,
      c.simbol,
      J.INDEXLOCAL,
      PKG_LIST_BASE_UTILS.DECODE_TIPDOC(t.TIPDOC)&apos;||sIDX||sTree||sSelectDC||gUserAlias||&apos;
    from tmp_lst_jurnal1 t
         inner join ncont CD on CD.codcont = t.codcontd
         inner join ncont CC on CC.codcont = t.codcontc
         inner join nsubunit s on t.subunitatea = s.codsubunit
         INNER JOIN jurnal j on nvl(t.coddoc,0) = nvl(j.coddoc,0) and nvl(t.tipdoc,0) = nvl(j.tipdoc,0) and t.codcontd = j.contd
                            and t.codcontc = j.contc and nvl(t.gest,0) = nvl(j.gest,0) and t.an*12+t.luna = j.an*12+j.luna and t.indexlocal = j.indexlocal
                            and t.subunitatea = j.subunitatea and nvl(t.codcentru,0) = nvl(j.codcentru,0) and nvl(t.codanalizanod,0)=nvl(j.codanalizanod,0)
         LEFT  JOIN ngest ng on ng.codgest = NVL(t.gest,0)
         LEFT  JOIN centrecost c on c.codcentru = t.codcentru
         LEFT JOIN NPART P ON P.CODPART = t.CODPART
         LEFT JOIN NAGENDA SED ON SED.CODAGENDA = t.CODAGENDA
         LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = t.COD_CODFISCAL
         LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
         LEFT JOIN NARTOBJ OBJ ON T.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = t.codanalizanod
         LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
         LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
         LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor&apos;||
    sJoinDC||gSuplJoins||&apos;
    where t.tipdoc in (29,30,31,32,33,35,36,45,46,47,55)
    &apos;;
  else
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
       NAV_CodDoc,
       NAV_TipDoc,
       Partener,
       DOC,
       DATADOC,
       ARTICOL,
       DocLegatura,
       Cant,
       Pret,
       VALOARE,
       CONT,
       CORESP,
       DATACREARE,
       SUBUNITATEA,
       EXPLICATII,
       GESTIUNE,
       ORDINE,
       CENTRUCOST,
       CENTRUCOSTSIMB,
       TIPDOC,
       IDX,
       XTREE
      &apos;||sInsertDC||gUserFields||&apos;)&apos;;
    sSelect := &apos;
    select
      t.coddoc,
      t.tipdoc,
      p.Den_Part,
      t.DOCUMENT,
      t.DATADOC,
      t.ARTICOL,
      t.DocLegatura,
      t.Cant,
      t.Pret,
      t.VALOARE,
      CD.SIMBOL,
      CC.SIMBOL,
      T.DATACREARE,
      S.Den_subunit,
      t.obs,
      ng.den_gest,
      t.tipdoc + DECODE(t.tipdoc,32,100,0),
      c.denumire,
      c.simbol,
      PKG_LIST_BASE_UTILS.DECODE_TIPDOC(t.TIPDOC)&apos;||sIDX||sTree||sSelectDC||gUserAlias||&apos;
    from tmp_lst_jurnal1 t
         inner join ncont CD on CD.codcont = t.codcontd
         inner join ncont CC on CC.codcont = t.codcontc
         inner join nsubunit s on t.subunitatea = s.codsubunit
         LEFT  JOIN ngest ng on ng.codgest = NVL(t.gest,0)
         LEFT  JOIN centrecost c on c.codcentru = t.codcentru
         LEFT JOIN NPART P ON P.CODPART = t.CODPART
         LEFT JOIN NAGENDA SED ON SED.CODAGENDA = t.CODAGENDA
         LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = t.COD_CODFISCAL
         LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
         LEFT JOIN NARTOBJ OBJ ON T.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = t.codanalizanod
         LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
         LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
         LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor&apos;||
    sJoinDC||gSuplJoins;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_fisacont3;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7666217053BA956E0D8C1DF52F87A14DC99FE3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAMAG IS

FUNCTION get_TVA_ARTICOL (p_codobiect IN NUMBER,p_an IN NUMBER,p_luna IN NUMBER) RETURN NUMBER IS
iResult NUMBER(20,6);
BEGIN
  SELECT 1+ntva1.procent/100 INTO iResult
  FROM nartobj nobj
    LEFT JOIN nart1 ON nobj.codarticol = nart1.codarticol AND p_an * 12 + p_luna BETWEEN nart1.ALStart AND nart1.ALStop 
    LEFT JOIN ntva1 ON ntva1.codtva    = nart1.codtva     AND p_an * 12 + p_luna BETWEEN ntva1.ALStart AND ntva1.ALStop
  WHERE nobj.codobiect = p_codobiect;
  RETURN iResult;
END;

PROCEDURE setPozitiiNS IS
sInsert VARCHAR2(1000);
pSubunitate NUMBER(20);
BEGIN
sInsert := &apos; INSERT INTO tmp_manevra_liste (filtru,valoare) &apos;||
         &apos; SELECT  &apos;&apos;CODNIRSTOC&apos;&apos;,ns.codnirstoc &apos;||
          	 &apos; from nirstoc ns WHERE &apos;||
		           &apos;  EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NS.CODOBIECT)&apos;;

IF NOT pkg_list_selfisamag.isAllTipCont  THEN
  sInsert := sInsert|| &apos; AND  EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;  AND VALOARE = NS.CODIOART)&apos;;
END IF;

EXECUTE IMMEDIATE sInsert;
COMMIT;

END;

 PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS

  sInsert VARCHAR2(25000);
	sqlIntr VARCHAR2(7500);    --&gt; Intrairi,transferuri catre...,modificari de pret
	sqlTransf VARCHAR2 (7500); --&gt; Transferuri din..,modificari pret
	sqlIes  VARCHAR2(7500);    --&gt; Diminuari,Mariri,Iesiri
	sqlSTocIni   VARCHAR2 (7500);--&gt; Stocuri initiale
BEGIN
	  setPozitiiNS;
		pkg_list_base_utils.baga_serii_in_tmp;

	  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos; (NAV_CODDOC,NAV_TIPDOC,DENUMIRE,INTRARE,IESIRE,STOC_FAKE,GESTIUNEA,LOCATIE,EXPLICATII,DATADOC,SIMBOL,DEN_IOART,PREFIXDOC,NRDOC,ORDINE,PINREG,PACHIZ,DEN_UM,TIPSERIE,SERIE,DATACREARE) &apos;||
		           &apos;SELECT  coddoc, tipdoc, DENUMIRE,INTRARE,IESIRE,STOC_FAKE,GESTIUNEA,LOCATIE,EXPLICATII,DATADOC,SIMBOL,DEN_IOART,PREFIXDOC,NRDOC,ORDINE,PINREG,PACHIZ,DEN_UM,TIPSERIE,SERIE,DATACREARE &apos;||
               &apos;FROM ( &apos;;
		sqlIntr := &apos;SELECT
		               CASE
									   WHEN NIR.TIPNIR BETWEEN 1  AND 7  THEN NIR.CODINTR
										 WHEN NIR.TIPNIR BETWEEN 12 AND 13 THEN NIR.CODTRANSF
										 WHEN NIR.TIPNIR = 19 THEN NIR.CODIES
									 END CODDOC,
									 NIR.TIPNIR tipdoc,
		               nobj.denumire, &apos;||
                       &apos;CASE &apos;||
									 &apos;WHEN nir.tipnir BETWEEN 1 AND 7 THEN nvl(ns.cantnir,0) &apos;||
									 &apos;ELSE 0 &apos;||
							&apos;END intrare, &apos;||
							&apos;CASE &apos;||
										&apos;WHEN nir.tipnir between 12 AND 13  THEN nvl(ns.cantnir,0) &apos;||
										&apos;WHEN nir.tipnir = 19 THEN  ies1.cant	&apos;||
										&apos;ELSE 0 &apos;||
							&apos;END iesire, &apos;||
							&apos;CASE &apos;||
										&apos;WHEN nir.tipnir BETWEEN 1 AND 7 THEN nvl(ns.cantnir,0) &apos;||
										&apos;WHEN nir.tipnir between 12 AND 13  THEN -nvl(ns.cantnir,0) &apos;||
										&apos;WHEN nir.tipnir = 19 THEN -ies1.cant	&apos;||
										&apos;ELSE 0 &apos;||
							 &apos;END stoc_fake, &apos;||
							 &apos;CASE &apos;||
										&apos;WHEN nir.tipnir BETWEEN 1 AND 7 THEN ng.den_gest &apos;||
										&apos;WHEN nir.tipnir = 19 THEN ng.den_gest &apos;||
										&apos;ELSE ngsursa.den_gest &apos;||
							 &apos;END gestiunea, &apos;||
							 &apos;NVL(NLOC.DENUMIRE,&apos;&apos;...&apos;&apos;) LOCATIE,&apos;||
							 &apos;CASE &apos;||
										&apos;WHEN nir.tipnir BETWEEN 1 AND 7 THEN &apos;&apos;Intrare &apos;&apos;||intr.prefixdoc||&apos;&apos; &apos;&apos;||intr.nrdoc||&apos;&apos; &apos;&apos;||intr.datadoc||&apos;&apos; &apos;&apos;||np.den_part &apos;||
										&apos;WHEN nir.tipnir = 12 THEN &apos;&apos;Transf. catre &apos;&apos;||ng.den_gest &apos;||
										&apos;WHEN nir.tipnir = 13 THEN &apos;&apos;Modif. pret &apos;&apos;||t.prefixdoc||t.nrdoc||&apos;&apos;  &apos;&apos;||t.datadoc||&apos;&apos; &apos;&apos;||ng.den_gest &apos;||
										&apos;WHEN nir.tipnir = 19 THEN &apos;&apos;Iesire in rosu &apos;&apos;||ng.den_gest &apos;||
										&apos;ELSE &apos;&apos;-&apos;&apos; &apos;||
							 &apos;END explicatii, &apos;||
							 &apos;nir.datanir datadoc,ncont.simbol,io.den_ioart, &apos;||
							 &apos;Coalesce(T.PREFIXDOC, INTR.PREFIXDOC,IES.PREFIXDOC) prefixdoc, &apos;||
							 &apos;Coalesce(T.NRDOC, INTR.NRDOC,IES.NRDOC) nrdoc, 2 ordine, &apos;||
							 &apos;CASE &apos;||
										 &apos;WHEN nir.tipnir = 19 THEN ies1.pu   &apos;||
										 &apos;WHEN nir.tipnir = 3 THEN intr1.pu-intr1.tva &apos;||
										 &apos;WHEN nir.tipnir = 5 THEN dvi1.PRETIMPORT &apos;||
										 &apos;ELSE  NVL(INTR1.PU,T1.PU) * G.CURS &apos;||
								&apos;END PACHIZ,&apos;||
								&apos;nvl(NS.PRET,0) pinreg,&apos;||
								&apos;num.den_um, &apos;||
								&apos;DECODE(NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, &apos;||
								&apos;ser.serii serie, &apos;||
								&apos;CASE
									   WHEN NIR.TIPNIR BETWEEN 1  AND 7  THEN INTR.DATACREARE
										 WHEN NIR.TIPNIR BETWEEN 12 AND 13 THEN T.DATACREARE
										 WHEN NIR.TIPNIR = 19 THEN IES.DATACREARE
									 END DATACREARE &apos;||
				&apos;FROM  nirstoc ns LEFT JOIN  nir ON nir.codnir = ns.codnir &apos;||
													&apos;LEFT JOIN NLOCATII NLOC ON NS.CODLOCATIE = NLOC.CODLOCATIE &apos;||
													&apos;LEFT JOIN intrari intr ON nir.codintr = intr.codintr AND intr.operat = 1 &apos;||
													&apos;LEFT JOIN GENERAL G ON G.CODDOC = INTR.CODINTR AND (G.TIPDOC = INTR.TIPDOC AND G.SEMNIFICATIE = 100) &apos;||
													&apos;LEFT JOIN iesiri ies ON nir.codies = ies.codies AND ies.operat = 1 &apos;||
													&apos;LEFT join DVI1 on DVI1.coddvi1 = ns.coddvi1 &apos;||
													&apos;LEFT JOIN transf t ON nir.codtransf = t.codtransf &apos;||
													&apos;LEFT JOIN nartobj nobj ON ns.codobiect = nobj.codobiect &apos;||
													&apos;LEFT JOIN ngest ng ON nir.gest = ng.codgest &apos;||
													&apos;LEFT JOIN intrari1 intr1 ON ns.codintr1 = intr1.codintr1 &apos;||
													&apos;LEFT JOIN transf1 t1 ON ns.codtransf1 = t1.codtransf1 &apos;||
													&apos;LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies &apos;||
													&apos;LEFT JOIN npart np ON intr.partener = np.codpart &apos;||
													&apos;LEFT JOIN nirstoc nssursa ON ns.codnirstocparinte = nssursa.codnirstoc &apos;||
													&apos;LEFT JOIN nir nirsursa ON nirsursa.codnir = nssursa.codnir &apos;||
											    &apos;LEFT JOIN ngest ngsursa ON ngsursa.codgest = nirsursa.gest &apos;||
                          &apos;LEFT JOIN ioart io ON ns.codioart = io.codioart &apos;||
                          &apos;LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart AND Coalesce(t.an*12+t.luna, intr.an*12+intr.luna, ies.an*12+ies.luna) BETWEEN nart1.ALStart AND nart1.ALStop&apos;||
                          &apos;LEFT JOIN ncont ON ncont.codcont = io1.cont &apos;||
                          &apos;LEFT JOIN NART ON NART.CODARTICOL = Nobj.CODARTICOL &apos;||
                          &apos;LEFT JOIN num ON nart.um = num.codum &apos;||
                          &apos;LEFT JOIN  TMP_MANEVRA_SERII SER ON SER.CODNIRSTOC = NS.CODNIRSTOC &apos;||
         &apos;WHERE Coalesce(t.datadoc, intr.datadoc, ies.datadoc) BETWEEN &apos;|| pkg_list_selfisamag.GetInterval ||
          &apos; AND (&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;,&apos; &apos;)|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NGSURSA&apos;,&apos;CODSUBUNIT&apos;,&apos; OR&apos;)||&apos; )&apos;;

 sqlIntr := sqlIntr|| &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;


IF NOT pkg_list_selfisamag.isAllTipCont THEN
 sqlIntr := sqlIntr|| &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = IO.CODIOART) &apos;;
END IF;

IF NOT pkg_list_selfisamag.isAllGest THEN
 sqlIntr := sqlIntr|| &apos; AND (  ( EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NG.CODGEST) &apos;||
                      &apos;       OR EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NGSURSA.CODGEST) ) &apos;||
                      &apos; OR EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NLOC.CODLOCATIE) ) &apos;;
 END IF;
--INSERT INTO x(SQL) VALUES (sqlIntr); COMMIT;
   sqlTransf := &apos;SELECT
                   CASE
                     WHEN L.TIPLIVR  BETWEEN 12  AND 13  THEN L.CODTRANSF
                     WHEN L.TIPLIVR &gt; 19 THEN L.CODIES
                   END CODDOC,
                   L.TIPLIVR tipdoc,
                        nobj.denumire, &apos;||
                        &apos;CASE &apos;||
                              &apos;WHEN l.tiplivr between 12 AND 13  THEN nvl(ns.cantnir,0) &apos;||
                              &apos;ELSE 0 &apos;||
                         &apos;END intrare, &apos;||
                         &apos;CASE &apos;||
                               &apos;WHEN l.tiplivr &gt; 19  THEN nvl(ns.cantnir,0) &apos;||
                               &apos;ELSE 0 &apos;||
                         &apos;END iesire, &apos;||
                         &apos;CASE &apos;||
                               &apos;WHEN l.tiplivr BETWEEN 12 AND 13 THEN nvl(ns.cantnir,0) &apos;||
                               &apos;WHEN l.tiplivr &gt; 19  THEN -nvl(ns.cantnir,0) &apos;||
                               &apos;ELSE 0 &apos;||
                         &apos;END stoc_fake, &apos;||
                         &apos;ngsursa.den_gest, &apos;||
                         &apos;NVL(NLOC.DENUMIRE,&apos;&apos;...&apos;&apos;) LOCATIE,&apos;||
                         &apos;CASE &apos;||
                               &apos;WHEN l.tiplivr = 12 THEN &apos;&apos;Transf. din &apos;&apos;||ng.den_gest &apos;||
                               &apos;WHEN l.tiplivr = 13 THEN &apos;&apos;Modif. pret &apos;&apos;||t.prefixdoc||t.nrdoc||&apos;&apos;  &apos;&apos;||t.datadoc||&apos;&apos; &apos;&apos;||ng.den_gest &apos;||
                               &apos;ELSE &apos;&apos;-&apos;&apos; &apos;||
                         &apos;END explicatii, &apos;||
                         &apos;l.datalivr,ncont.simbol,io.den_ioart,t.prefixdoc prefixdoc, t.nrdoc nrdoc, 2 ordine, &apos;||
                         &apos;intr1.pu pachiz, &apos;||
                         &apos;ns.pret pinreg,NUM.DEN_UM, &apos;||
                         &apos;DECODE(NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, &apos;||
                         &apos;ser.serii serie, &apos;||
                         &apos;CASE
                            WHEN L.TIPLIVR  BETWEEN 12  AND 13  THEN T.DATACREARE
                            WHEN L.TIPLIVR &gt; 19 THEN IES.DATACREARE
                          END DATACREARE &apos;||
                &apos;FROM livr l &apos;||
                      &apos;LEFT JOIN livr1 l1 ON l1.codlivr = l.codlivr &apos;||
                      &apos;LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES &apos;||
                      &apos;LEFT JOIN transf t ON t.codtransf = l.codtransf &apos;||
                      &apos;LEFT JOIN transf1 t1 ON t.codtransf = t1.codtransf1 &apos;||
                      &apos;LEFT JOIN nirstoc ns ON ns.codlivr1 = l1.codlivr1 &apos;||
                      &apos;LEFT JOIN nirstoc ns1 ON ns.codnirstocparinte = ns1.codnirstoc &apos;||
                      &apos;LEFT JOIN NLOCATII NLOC ON NS1.CODLOCATIE = NLOC.CODLOCATIE &apos;||
                      &apos;LEFT JOIN nir ON nir.codnir = ns1.codnir &apos;||
                      &apos;LEFT JOIN nir nirsursa ON nirsursa.codnir = ns.codnir &apos;||
                      &apos;LEFT JOIN ngest ng ON ng.codgest = nir.gest &apos;||
                      &apos;LEFT JOIN ngest ngsursa ON ngsursa.codgest = nirsursa.gest &apos;||
                      &apos;LEFT JOIN nartobj nobj ON ns.codobiect = nobj.codobiect &apos;||
                      &apos;LEFT JOIN ioart io ON ns1.codioart = io.codioart &apos;||
                      &apos;LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart AND t.an*12+t.luna BETWEEN io1.ALStart AND io1.ALStop&apos;||
                      &apos;LEFT JOIN ncont ON ncont.codcont = io1.cont &apos;||
                      &apos;LEFT JOIN intrari1 intr1 ON intr1.codintr1 = ns1.codintr1 &apos;||
                      &apos;LEFT JOIN NART ON NART.CODARTICOL = Nobj.CODARTICOL &apos;||
                      &apos;LEFT JOIN num ON nart.um = num.codum &apos;||
                      &apos;LEFT JOIN  TMP_MANEVRA_SERII SER ON SER.CODNIRSTOC = NS.CODNIRSTOC &apos;||
                &apos;WHERE AND t.datadoc BETWEEN &apos;|| pkg_list_selfisamag.GetInterval ||
                     &apos; AND (&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;,&apos; &apos;)|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NGSURSA&apos;,&apos;CODSUBUNIT&apos;,&apos; OR&apos;)||&apos; )&apos;||
                     &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;


IF NOT pkg_list_selfisamag.isAllTipCont  THEN
 sqlTransf := sqlTransf|| &apos;AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = IO.CODIOART) &apos;;
END IF;

IF NOT pkg_list_selfisamag.isAllGest THEN
 sqlTransf := sqlTransf|| &apos; AND (   EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NGSURSA.CODGEST)  &apos;||
                         &apos; OR EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NLOC.CODLOCATIE) ) &apos;;
 END IF;
--INSERT INTO x(SQL) VALUES(sqlTransf);
  sqlIes := &apos;SELECT
                  CASE
                     WHEN L.TIPLIVR = 1  THEN L.CODINTR
                     WHEN L.TIPLIVR BETWEEN 14 AND 15 THEN L.CODIES
                   END CODDOC,
                   L.TIPLIVR tipdoc,
                    nobj.denumire, &apos;||
                    &apos;CASE &apos;||
                          &apos;WHEN l.tiplivr = 15 THEN l1.cant &apos;||
                          &apos;WHEN l.tiplivr = 1 THEN i1.cant &apos;||
                          &apos;ELSE 0 &apos;||
                    &apos;END intrare, &apos;||
                    &apos;CASE &apos;||
                          &apos;WHEN l.tiplivr = 15 THEN 0 &apos;||
                          &apos;ELSE l1.cant &apos;||
                    &apos;END iesire, &apos;||
                    &apos;CASE &apos;||
                          &apos;WHEN l.tiplivr = 15 THEN l1.cant &apos;||
                          &apos;WHEN l.tiplivr = 1 THEN i1.cant &apos;||
                          &apos;ELSE -l1.cant &apos;||
                    &apos;END stoc_fake, &apos;||
                    &apos;ng.den_gest, &apos;||
                    &apos;NVL(NLOC.DENUMIRE,&apos;&apos;...&apos;&apos;) LOCATIE, &apos;||
                    &apos;CASE &apos;||
                          &apos;WHEN l.tiplivr = 14 THEN &apos;&apos;Dimin. &apos;&apos;||ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc &apos;||
                          &apos;WHEN l.tiplivr = 15 THEN &apos;&apos;Marire &apos;&apos;||ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc &apos;||
                          &apos;WHEN l.tiplivr = 1  THEN &apos;&apos;Intrare in rosu &apos;&apos;||intr.prefixdoc|| intr.nrdoc||&apos;&apos; / &apos;&apos;||intr.datadoc &apos;||
                          &apos;ELSE &apos;&apos;Iesire &apos;&apos;||ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc &apos;||
                    &apos;END explicatii, &apos;||
                    &apos;l.datalivr,ncont.simbol,io.den_ioart,nvl(IES.PREFIXDOC,intr.prefixdoc) prefixdoc, &apos;||
                    &apos;nvl(IES.NRDOC,intr.nrdoc) nrdoc ,2 ordine, &apos;||
                    &apos;NVL(INTR1.PU, nvl(IES1.PU,i1.pu)) pachiz, &apos;||
                    &apos;ns.pret pinreg,NUM.DEN_UM, &apos;||
                    &apos;DECODE(NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, &apos;||
                    &apos;ser.serii serie, &apos;||
                    &apos;CASE
                        WHEN L.TIPLIVR = 1  THEN INTR.DATACREARE
                        WHEN L.TIPLIVR BETWEEN 14 AND 15 THEN IES.DATACREARE
                      END DATACREARE &apos;||
             &apos;FROM &apos;||
                   &apos;livr l LEFT JOIN livr1 l1 ON l.codlivr = l1.codlivr  AND l1.cant &gt; 0&apos;||
                   &apos;LEFT JOIN intrari intr ON l.codintr = intr.codintr &apos;||
                   &apos;LEFT JOIN intrari1 i1 ON i1.codintr = intr.codintr &apos;||
                   &apos;LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc &apos;||
                   &apos;LEFT JOIN NLOCATII NLOC ON NS.CODLOCATIE = NLOC.CODLOCATIE &apos;||
                   &apos;LEFT JOIN nir ON nir.codnir = ns.codnir &apos;||
                   &apos;LEFT JOIN nartobj nobj ON nobj.codobiect = ns.codobiect &apos;||
                   &apos;LEFT JOIN nart ON nart.codarticol = nobj.codarticol &apos;||
                   &apos;LEFT JOIN num ON num.codum = nart.um &apos;||
                   &apos;LEFT JOIN nclasea nca ON nca.codclasea = nart.clasa &apos;||
                   &apos;LEFT JOIN ngest ng ON ng.codgest = nir.gest &apos;||
                   &apos;LEFT JOIN ioart io ON ns.codioart = io.codioart &apos;||
                   &apos;LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart &apos;||
                   &apos;LEFT JOIN iesiri ies ON ies.codies = l.codies &apos;||
                   &apos;LEFT JOIN ncont ON io1.cont = ncont.codcont &apos;||
                   &apos;LEFT JOIN nirstoc ns1 ON ns.codnirstocparinte = ns1.codnirstoc &apos;||
                   &apos;LEFT JOIN intrari1 intr1 ON intr1.codintr1 = ns1.codintr1 &apos;||
                   &apos;LEFT JOIN iesiri1 ies1 ON ies1.codies1 = l1.codies1 &apos;||
                   &apos;LEFT JOIN  TMP_MANEVRA_SERII SER ON SER.CODNIRSTOC = NS.CODNIRSTOC &apos;||
             &apos;WHERE Coalesce(ies.an*12+ies.luna,intr.an*12+intr.luna) BETWEEN io1.alstart AND io1.alstop &apos;||
             &apos; AND Coalesce(ies.datadoc,intr.datadoc)  BETWEEN &apos;|| pkg_list_selfisamag.GetInterval ||
             &apos; AND Coalesce(ies.operat,intr.operat) = 1 &apos;||
             PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
             &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;

IF NOT pkg_list_selfisamag.isAllTipCont THEN
 sqlIes := sqlIes|| &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = IO.CODIOART) &apos;;
END IF;

IF NOT pkg_list_selfisamag.isAllGest THEN
 sqlIes := sqlIes|| &apos; AND (   EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NG.CODGEST)  &apos;||
                         &apos; OR EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NLOC.CODLOCATIE) ) &apos;;
 END IF;
--INSERT INTO x(SQL) VALUES (sqlIes);COMMIT;

 sqlStocIni :=&apos;SELECT NULL coddoc, NULL tipdoc,stoc_ini.denumire,0 intrare,0 iesire,nvl(sum(cant),0) stoc_fake ,stoc_ini.den_gest,NULL LOCATIE, &apos;||
                    &apos; &apos;&apos;Stoc initial&apos;&apos; EXPLICATII, &apos;||
                     &apos;CASE &apos;||
                           &apos;WHEN stoc_ini.datanir IS NULL THEN PKG_LIST_SELFISAMAG.GETDATAINI &apos;||
                           &apos;ELSE stoc_ini.datanir &apos;||
                      &apos;END dataini, &apos;||
                     &apos;stoc_ini.Simbol,stoc_ini.den_ioart,NULL prefixdoc,NULL nrdoc, 1 ordine, &apos;||
                     &apos; stoc_ini.pach, stoc_ini.pintr,DEN_UM, &apos;||
                     &apos; tipserie, &apos;||
                     &apos; serie,NULL DATACREARE &apos;||
               &apos;FROM &apos;||
                   /*&apos;(SELECT nobj.codobiect,nobj.denumire,ng.codgest,ng.den_gest &apos;||
                     &apos;FROM ngest ng ,nartobj nobj &apos;||
                     &apos;WHERE ng.codgest &gt; 0 &apos;||
                     &apos;AND nobj.codobiect IN (&apos;|| pkg_list_selfisamag.getlistObj||&apos;) &apos;;
 IF NOT pkg_list_selfisamag.isAllGest(lstGestiuni) THEN
    sqlSTocIni := sqlSTocIni ||&apos;AND NG.CODGEST IN (&apos;||lstGestiuni||&apos;) &apos;;
 END IF;
     sqlSTocIni:=sqlSTocIni||   &apos;) toate, &apos;||*/
                    &apos;(SELECT nobj.codobiect,nir.datanir,nir.gest, null locatie ,nl.rest cant, &apos;||
                             &apos;io.den_ioart,nc.simbol, intr1.pu pach, ns.pret pintr,DEN_UM,nobj.denumire,ng.den_gest, &apos;||
                             &apos;DECODE(NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, &apos;||
                             &apos;ser.serii serie &apos;||
                      &apos;FROM nirluna nl &apos;||
                            &apos;left join nirstoc ns on nl.codnirstoc = ns.codnirstoc &apos;||
                            &apos;left join nir on nir.codnir = ns.codnir &apos;||
                            &apos;LEFT JOIN nartobj nobj ON nobj.codobiect = ns.codobiect &apos;||
                            &apos;LEFT JOIN ioart io ON io.codioart = ns.codioart &apos;||
                            &apos;LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart &apos;||
                            &apos;LEFT JOIN ncont nc ON nc.codcont = io1.cont &apos;||
                            &apos;LEFT JOIN intrari1 intr1 on ns.codintr1 = intr1.codintr1 &apos;||
                            &apos;LEFT JOIN NART ON NART.CODARTICOL = Nobj.CODARTICOL &apos;||
                            &apos;LEFT JOIN num ON nart.um = num.codum &apos;||
                            &apos;LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;||
                            &apos;LEFT JOIN  TMP_MANEVRA_SERII SER ON SER.CODNIRSTOC = NS.CODNIRSTOC &apos;||
                            &apos;WHERE nl.an = extract(YEAR FROM add_months(last_day(pkg_list_selfisamag.getDataIni),-1)) &apos;||
                            &apos; AND nl.luna = extract(MONTH FROM add_months(last_day(pkg_list_selfisamag.getDataIni),-1)) &apos;||
                            &apos; AND nl.an*12+nl.luna+1 BETWEEN io1.alstart AND alstop &apos;||
                            PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
                            &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;

IF NOT pkg_list_selfisamag.isAllGest THEN
   sqlSTocIni := sqlSTocIni ||&apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NIR.GEST) &apos;;
 END IF;

IF NOT pkg_list_selfisamag.isAllTipCont  THEN
 sqlStocIni := sqlStocIni|| &apos;AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = IO.CODIOART) &apos;;
END IF;

 sqlStocIni:=sqlStocIni||&apos;UNION ALL &apos;||
                      &apos;SELECT nobj.codobiect,null,nir.gest, NULL,ns.cantnir,NULL,NULL,NULL,NULL,DEN_UM,nobj.denumire,ng.den_gest,null tipserie ,null serie  &apos;||
                      &apos;FROM &apos;||
                             &apos;nirstoc ns LEFT JOIN nir ON ns.codnir = nir.codnir &apos;||
                                        &apos;LEFT JOIN nartobj nobj ON nobj.codobiect = ns.codobiect &apos;||
                                        &apos;LEFT JOIN NART ON NART.CODARTICOL = Nobj.CODARTICOL &apos;||
                                        &apos;LEFT JOIN num ON nart.um = num.codum &apos;||
                                        &apos;LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;||
                      &apos;WHERE nir.datanir BETWEEN add_months(last_day(pkg_list_selfisamag.getDataIni),-1) + 1 AND pkg_list_selfisamag.getDataIni -1 &apos;||
                      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
                      &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;

IF NOT pkg_list_selfisamag.isAllGest THEN
    sqlSTocIni := sqlSTocIni ||&apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NIR.GEST) &apos;;
END IF;

 sqlSTocIni:=sqlSTocIni||&apos;UNION ALL &apos;||
                      &apos;SELECT nobj.codobiect,null, &apos;||
                              &apos;CASE &apos;||
                                    &apos;WHEN l.tiplivr IN (14,15,19) THEN nir.gest &apos;||
                                    &apos;ELSE x.gest &apos;||
                              &apos;END gest, &apos;||
                              &apos;NVL(NLOC.DENUMIRE,&apos;&apos;...&apos;&apos;) LOCATIE,&apos;||
                              &apos;CASE &apos;||
                                    &apos;WHEN l.tiplivr = 15 THEN l1.cant &apos;||
                                    &apos;ELSE -l1.cant &apos;||
                              &apos;END canties,NULL,NULL,NULL,NULL,DEN_UM,nobj.denumire,ng.den_gest,null tipserie, null serie &apos;||
                       &apos;FROM livr1 l1 &apos;||
                                   &apos;LEFT JOIN  nirstoc ns ON ns.codnirstoc = l1.codnirstoc &apos;||
                                   &apos;LEFT JOIN NLOCATII NLOC ON NS.CODLOCATIE = NLOC.CODLOCATIE &apos;||
                                   &apos;LEFT JOIN  nir ON nir.codnir =  ns.codnir &apos;||
                                   &apos;LEFT JOIN iesiri1 ies1 ON l1.codies1 = ies1.codies1 &apos;||
                                   &apos;LEFT JOIN &apos;||
                                        &apos;(SELECT ns.codlivr1,nir.gest FROM &apos;||
                                                 &apos;nirstoc ns INNER JOIN nirstoc ns1 ON ns.codnirstocparinte = ns1.codnirstoc &apos;||
                                                 &apos;INNER JOIN nir ON nir.codnir = ns1.codnir &apos;||
                                         &apos;) x ON l1.codlivr1=x.codlivr1 &apos;||
                                   &apos;LEFT JOIN livr l ON l1.codlivr = l.codlivr &apos;||
                                   &apos;LEFT JOIN nartobj nobj ON ns.codobiect = nobj.codobiect &apos;||
                                   &apos;LEFT JOIN NART ON NART.CODARTICOL = Nobj.CODARTICOL &apos;||
                                   &apos;LEFT JOIN num ON nart.um = num.codum &apos;||
                                   &apos;LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST &apos;||
                       &apos;WHERE l.datalivr BETWEEN add_months(last_day(pkg_list_selfisamag.getDataIni),-1) + 1 AND pkg_list_selfisamag.getDataIni -1 &apos;||
                       PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
                       &apos; AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT) &apos;;



  IF NOT pkg_list_selfisamag.isAllGest THEN
  sqlSTocIni := sqlSTocIni ||&apos; AND ( EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NIR.GEST) &apos;||
                                  &apos; OR EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = X.GEST)) &apos;;

  END IF;

  sqlSTocIni:=sqlSTocIni||&apos;) stoc_ini &apos;||
              &apos;GROUP BY (STOC_INI.den_gest,STOC_INI.denumire,stoc_ini.datanir,stoc_ini.simbol,stoc_ini.den_ioart,stoc_ini.pach,stoc_ini.pintr,stoc_ini.den_um,stoc_ini.tipserie,stoc_ini.serie)  &apos;;
  sInsert := sInsert||sqlIntr||&apos; UNION ALL &apos;||sqlTransf||&apos; UNION ALL &apos;||sqlIes||&apos; UNION ALL &apos;||sqlSTocIni||
            &apos;)sql_miscari &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
NULL;
END;
end PKG_LIST_BASE_FISAMAG;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAG2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71C939E46146CA9D078338705EA48969BF47EFE8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAMAG2 IS

  vSint        BOOLEAN;
  vSerii       BOOLEAN;
  vGroup       BOOLEAN;
  vCodObiect   NUMBER(20) := 0;
  AnLunaMin    NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(aCodObiect IN NUMBER) IS
BEGIN
  vCodObiect := aCodObiect;
  DELETE TMP_MANEVRA_LISTE WHERE filtru = &apos;CODOBIECT&apos;;
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE) VALUES (&apos;CODOBIECT&apos;, ACODOBIECT);
  COMMIT;
  pkg_list_selfisamag.setAllParams(PKG_LIST_BASE_STOCEP.GetDataIni, PKG_LIST_BASE_STOCEP.GetDataFin, PKG_LIST_BASE_STOCEP.GetDataFin, 1, 1, 0);
END;

PROCEDURE maketmpSerii IS
	AnTemp    NUMBER(4);
	LunaTemp  NUMBER(2);
  AnPrec    NUMBER(4);
  LunaPrec  NUMBER(2);
  vDataIni  DATE       := add_months(last_day(pkg_list_selfisamag.getDataIni),-1);
  vDataFin  DATE       := pkg_list_selfisamag.getDataFin;
BEGIN
  AnTemp   := EXTRACT (YEAR  FROM PKG_LIST_SELFISAMAG.getDataIni);
  LunaTemp := EXTRACT (MONTH FROM PKG_LIST_SELFISAMAG.getDataIni);
  pkg_globals.SetLunaTemp(AnTemp,LunaTemp);
  pkg_globals.Calculeaza_Luna_Precedenta(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);

  INSERT INTO tmp_manevra_liste (filtru,valoare)
  SELECT DISTINCT &apos;CODNIRSTOC&apos;,CODNIRSTOC
  FROM(
    SELECT ns.codnirstoc
    FROM tmp_manevra_liste tmp
      INNER JOIN nirstoc ns  ON ns.codobiect  = tmp.valoare
      INNER JOIN nirluna nl  ON nl.codnirstoc = ns.codnirstoc AND NL.AN = AnPrec AND nl.luna = LunaPrec
      INNER JOIN IOART1  IO1 ON io1.codioart  = ns.codioart   AND Greatest(AnPrec*12+LunaPrec, AnLunaMin) BETWEEN IO1.ALStart AND IO1.ALStop
    WHERE tmp.filtru = &apos;CODOBIECT&apos;
      AND IO1.MG &lt;&gt; 5
      AND (Coalesce(NL.REST,0) &lt;&gt; 0 OR Coalesce(NL.RESTUM1, 0) &lt;&gt; 0 OR Coalesce(NL.RESTUM2, 0) &lt;&gt; 0)
    UNION
    SELECT ns.codnirstoc
    FROM tmp_manevra_liste tmp
      INNER JOIN nirstoc ns ON ns.codobiect = tmp.valoare
			INNER JOIN nir n ON ns.codnir = n.codnir
    WHERE tmp.filtru = &apos;CODOBIECT&apos; AND trunc(n.datanir) BETWEEN vDataIni AND vDataFin
    UNION
    SELECT ns.codnirstoc
    FROM tmp_manevra_liste tmp
      INNER JOIN nirstoc ns ON ns.codobiect = tmp.valoare
			INNER JOIN LIVR1 L1 ON NS.CODNIRSTOC = L1.CODNIRSTOC
			INNER JOIN LIVR L ON  L1.CODLIVR = L.CODLIVR
    WHERE tmp.filtru = &apos;CODOBIECT&apos; AND trunc(l.datalivr) BETWEEN vDataIni AND vDataFin
	);

  INSERT INTO tmp_manevra_liste(filtru,valoare)
  SELECT &apos;CODNIRSTOC&apos;, ns.codnirstocparinte
	FROM nirstoc ns INNER JOIN tmp_manevra_liste tmp ON ns.codnirstoc = tmp.valoare
	WHERE tmp.filtru = &apos;CODNIRSTOC&apos; AND Coalesce(ns.codnirstocparinte,0) &lt;&gt; 0;

  COMMIT;

  pkg_list_base_utils.BAGA_SERII_IN_TMP(pkg_list_base_utils.CT_TOATE);
END;

PROCEDURE MakeSQLStocIni(tmpName IN VARCHAR2, pInsert IN VARCHAR2, pFiltruGest IN BOOLEAN) IS
	pInterval    VARCHAR2(500) := pkg_list_selfisamag.GetInterval;
  pCond        VARCHAR2(5000)  := &apos;&apos;;
  pCondExtra   VARCHAR2(5000)  := &apos;&apos;;
	sqlTmpSI     VARCHAR2(32000);
	sqlStocIni   VARCHAR2(32000);
	sqlTranz     VARCHAR2(32000) := &apos;&apos;;
	AnTemp       NUMBER(4);
	LunaTemp     NUMBER(2);
	AnPrec       NUMBER(4);
  LunaPrec     NUMBER(2);
  pColAgg      VARCHAR2(500);
  pColSerii    VARCHAR2(500);
  pGroup       VARCHAR2(500);
  sComCol      VARCHAR2(3000);
  fInterval    VARCHAR2(500);
  aDataI       DATE;
  aDataF       DATE;
BEGIN
  sComCol  := &apos;
        ns.codobiect, ns.codnirstoc, n.gest, Coalesce(ns.codlocatie,0) CodLocatie, ns.codioart, ioa1.codioart1,
        Coalesce(NS.PRET,0) PInreg, (Coalesce(NS.PRET,0) - Coalesce(NS.Adaos,0)) PAchiz, Coalesce(NS.PUVal,0) PUVal, NULL userid, NULL obs, Coalesce(NS.TIPSERIE,0) TipSerie&apos;;
  IF pkg_list_selfisamag.isToateArt = 0 THEN
    pCond := pCond||&apos;
        AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos; ;
  END IF;
  IF NOT pkg_list_selfisamag.isAllTipCont THEN
    pCond := pCond||&apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos; ;
  END IF;
  IF pFiltruGest THEN
  	pCond := pCond||&apos;
        AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;
  IF pkg_list_selfisamag.TipStocIni = 1 THEN -- doar articole cu livrari din pozitiile de stoc in perioada selectata
    pCondExtra := &apos;
        AND EXISTS (
              SELECT 1
              FROM livr xl INNER JOIN livr1 xl1 ON xL1.CODLIVR = xL.CODLIVR
              WHERE xL1.CODNIRSTOC = NS.CODNIRSTOC AND xL.OPERAT = 1 AND xL.ANULAT = 0 AND trunc(xL.DATALIVR) BETWEEN &apos;||pInterval||&apos;
            )&apos;;
  END IF;
  IF pkg_list_selfisamag.TipStocIni = 2 THEN -- doar articole cu miscari in perioada selectata
    --CALL create_wm_temps_flag(&apos;TMP_LST_FM_SI2&apos;); -- pt PG
    sqlTmpSI := &apos;INSERT INTO TMP_LST_FM_SI2(CODOBIECT, CODIOART, CODGEST)
    SELECT NS.CODOBIECT, NS.CODIOART, N.GEST
    FROM livr l
      INNER JOIN livr1   l1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN nirstoc ns ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN nir     n  ON N.CODNIR      = NS.CODNIR
      INNER JOIN ngest   g  ON G.CODGEST     = N.GEST
    WHERE L.OPERAT = 1 AND L.ANULAT = 0
      AND trunc(L.DATALIVR) BETWEEN &apos;||pInterval||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      pCond||&apos;
    UNION
    SELECT NS.CODOBIECT, NS.CODIOART, N.GEST
    FROM nir n
      INNER JOIN nirstoc ns ON NS.CODNIR = N.CODNIR
      INNER JOIN ngest   g  ON G.CODGEST = N.GEST
    WHERE N.OPERAT = 1 AND N.ANULAT = 0
      AND trunc(N.DATANIR) BETWEEN &apos;||pInterval||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      pCond;

    LIST_EXECUTE_IMMEDIATE(sqlTmpSI, 0, 0);
    pCondExtra := &apos;
        AND EXISTS (SELECT 1 FROM TMP_LST_FM_SI2 xT WHERE xT.CODOBIECT = NS.CODOBIECT AND xT.CODIOART = NS.CODIOART AND xT.CODGEST = N.GEST)&apos;;
  END IF;

  AnTemp   := EXTRACT (YEAR  FROM PKG_LIST_SELFISAMAG.getDataIni);
  LunaTemp := EXTRACT (MONTH FROM PKG_LIST_SELFISAMAG.getDataIni);
  pkg_globals.SetLunaTemp(AnTemp,LunaTemp);
  pkg_globals.Calculeaza_Luna_Precedenta(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(Anprec,LunaPrec);

  aDataI := Trunc(pkg_list_selfisamag.getDataIni,&apos;MM&apos;);
  aDataF := pkg_list_selfisamag.getDataIni-1;

  IF aDataF &gt;= aDataI THEN
    IF aDataF = aDataI
    THEN fInterval := &apos;= to_date(&apos;&apos;&apos;||To_Char(aDataI,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    ELSE fInterval := &apos;BETWEEN to_date(&apos;&apos;&apos;||To_Char(aDataI,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||To_Char(aDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    END IF;

    sqlTranz := sqlTranz||&apos;
      UNION ALL
      SELECT&apos;||
        sComCol||&apos;,
        NS.CANTNIR REST, NS.CANTUM1 RESTUM1, NS.CANTUM2 RESTUM2
      FROM NIRSTOC NS
        INNER JOIN NIR    N    ON N.CODNIR    = NS.CODNIR
        INNER JOIN NGEST  G    ON G.CODGEST   = N.GEST
        INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND &apos;||To_Char(Greatest(AnTemp*12+LunaTemp,AnLunaMin))||&apos; BETWEEN IOA1.ALStart and IOA1.ALStop
      WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13)
        AND trunc(N.DATANIR) &apos;||fInterval||&apos;
        AND N.ANULAT = 0 AND N.OPERAT = 1 AND IOA1.MG &lt;&gt; 5 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
        pCond||
        pCondExtra||&apos;
      UNION ALL
      SELECT&apos;||
        sComCol||&apos;,
        CASE L.TIPLIVR WHEN 15 THEN 1 ELSE -1 END * L1.CANT REST, CASE L.TIPLIVR WHEN 15 THEN 1 ELSE -1 END * L1.CANTUM1 RESTUM1, CASE L.TIPLIVR WHEN 15 THEN 1 ELSE -1 END * L1.CANTUM2 RESTUM2
      FROM LIVR L
        INNER JOIN LIVR1   L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST   G ON G.CODGEST = N.GEST
        INNER JOIN IOART1  IOA1 ON NS.CODIOART = IOA1.CODIOART AND &apos;||To_Char(Greatest(AnTemp*12+LunaTemp,AnLunaMin))||&apos; BETWEEN IOA1.ALStart and IOA1.ALStop
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 19, 20, 23, 24)
        AND trunc(L.DATALIVR) &apos;||fInterval||&apos;
        AND L.OPERAT = 1 AND L.ANULAT = 0 AND IOA1.MG &lt;&gt; 5 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
        pCond||
        pCondExtra;
  END IF;

  IF vSint THEN
    pColAgg    := &apos;, 0 codnirstoc, Sum(Coalesce(pinreg,0)*rest)/Coalesce(NULLIF(Sum(rest),0),1) pinreg&apos;;
    pColSerii  := &apos;null serii, null serii_obs, null sernocant&apos;;
    pGroup     := &apos;&apos;;
  ELSIF vSerii THEN
    pColAgg    := &apos;, CASE tipserie WHEN 0 THEN 0 ELSE codnirstoc END codnirstoc, pinreg&apos;;
    pColSerii  := &apos;tmp.serii, tmp.serii_obs, tmp.serii_aux1&apos;;
    pGroup     := &apos;, CASE tipserie WHEN 0 THEN 0 ELSE codnirstoc END, pinreg&apos;;
  ELSE
    pColAgg    := &apos;, 0 codnirstoc, pinreg&apos;;
    pColSerii  := &apos;null serii, null serii_obs, null sernocant&apos;;
    pGroup     := &apos;, pinreg&apos;;
  END IF;

  sqlStocIni :=&apos;
  WITH
  CRS_INI AS (
    SELECT
      0 coddoc, 0 tipdoc, codobiect, gest, CodLocatie, codioart, codioart1&apos;||pColAgg||&apos;,
      Sum(rest) cant, Sum(restum1) cantum1, Sum(restum2) cantum2, Sum(Coalesce(pachiz,0)*rest)/Coalesce(NULLIF(Sum(rest),0),1) pachiz, Sum(Coalesce(puval,0)*rest)/Coalesce(NULLIF(Sum(rest),0),1) puval,
      0 partener,  0 userid, 0 codlocatiep, 0 tipmiscare, 0 coddoc1, 0 codcentru
    FROM (
      SELECT&apos;||
        sComCol||&apos;,
        nl.rest, nl.restum1, nl.restum2
      FROM NIRLUNA NL
        INNER JOIN NIRSTOC NS   ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN IOART1  IOA1 ON NS.CODIOART   = IOA1.CODIOART AND &apos;||To_Char(Greatest(AnTemp*12+LunaTemp,AnLunaMin))||&apos; BETWEEN IOA1.ALStart and IOA1.ALStop
        LEFT  JOIN NIR     N    ON N.CODNIR      = NS.CODNIR
        LEFT  JOIN NGEST   NG   ON N.GEST        = NG.CODGEST
      WHERE NL.AN = &apos;||Anprec||&apos; AND NL.LUNA = &apos;||LunaPrec||&apos;
        AND (Coalesce(NL.REST,0) &lt;&gt; 0 OR Coalesce(NL.RESTUM1,0) &lt;&gt; 0 OR Coalesce(NL.RESTUM2,0) &lt;&gt; 0)
        AND IOA1.MG &lt;&gt; 5 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
        pCond||
        pCondExtra||
      sqlTranz||&apos;
    ) subs
    GROUP BY codobiect, gest, codlocatie, codioart, codioart1&apos;||pGroup||&apos;)
  SELECT
    m.coddoc, m.tipdoc, m.codnirstoc, m.codobiect, nobj.denumire, 0 intrare, 0 iesire, m.cant, 0 intr_um1,0 ies_um1, m.cantum1, 0 intr_um2, 0 ies_um2, m.cantum2,
    m.pachiz, m.puval, m.pInreg, 0 pumaxmimal, NULL DATAEXP, CASE furn.codpart WHEN 0 THEN gestprod.den_gest ELSE furn.den_part END, prod.den_part,
    pkg_list_selfisamag.getDataIni DATADOC, pkg_list_selfisamag.getDataIni DATAMISC, null nrdoc, &apos;&apos;StocInitial&apos;&apos;, NULL TipDoc, 0 ordine,
    null sursadest,
    null partener,
    gestiunea.den_gest,io.den_ioart, ncont.simbol, loc.denumire denlocatie,&apos;||pColSerii||&apos;,
    null codlivr1, sub.den_subunit, um_princ.den_um um_princ, um_alt1.den_um um_alt1, um_alt2.den_um um_alt2, null d1, null d2, null d3, null clasas,
    null pmp, null pmpvaluta, null pmpdoc, null pmpvaldoc, null delegat, null obsdoc, null obslin, null datacreare, null oracreare&apos;||gUserAlias||&apos;
  FROM crs_ini m
    INNER JOIN nartobj        nobj       on m.codobiect       = nobj.codobiect
    INNER JOIN nart           a          on a.codarticol      = nobj.codarticol
    INNER JOIN num            um_princ   on um_princ.codum    = a.um
    LEFT  JOIN nclasea        nca        ON nca.codclasea     = a.clasa
    LEFT  JOIN num            um_alt1    on um_alt1.codum     = a.um1
    LEFT  JOIN num            um_alt2    on um_alt2.codum     = a.um2
    LEFT  JOIN nlocatii       loc        ON loc.codlocatie    = m.codlocatie
    LEFT  JOIN ngest          gestiunea  ON gestiunea.codgest = m.gest
    LEFT  JOIN ioart          io         on io.codioart       = m.codioart
    LEFT  JOIN ioart1         io1        ON io1.codioart1     = m.codioart1
    LEFT  JOIN ncont                     ON io1.cont          = ncont.codcont
    LEFT  JOIN nsubunit       sub        on sub.codsubunit    = gestiunea.codsubunit
    LEFT  JOIN nirstoc        ns         on ns.codnirstoc     = m.codnirstoc
    LEFT  JOIN nirstoc        nsroot     on nsroot.codnirstoc = m.codnirstoc
    LEFT  JOIN nir            n          ON n.codnir          = ns.codnir
    LEFT  JOIN npart          prod       ON prod.codpart      = nobj.codproducator
    LEFT  JOIN npart          furn       ON furn.codpart      = Coalesce(ns.furn,0)
    LEFT  JOIN ngest          gestprod   ON gestprod.codgest  = ns.codgestprod
    LEFT  JOIN num1                      ON num1.codum        = a.um AND num1.secundara = 0
    LEFT  JOIN nartamb        aa         ON aa.codobiect      = nobj.codobiect AND aa.umsec = num1.codum1
    -- joinuri de forma care sunt parcatic folosite doar in miscari
    LEFT  JOIN npart          partener   ON m.partener        = partener.codpart
    LEFT  JOIN ngest          gestdest   ON m.partener        = gestdest.codgest
    LEFT  JOIN tmp_utilizator utilizator on m.userid          = utilizator.codutilizator
    LEFT  JOIN nagenda        sediu      ON m.codlocatiep     = sediu.codagenda
    LEFT  JOIN nlocalit       sedloc     ON sedloc.codlocalit = sediu.codlocalit&apos;||
    gSuplJoins;

  if vSerii then
    sqlStociNI := sqlStocIni || &apos;
    LEFT JOIN tmp_manevra_serii tmp on tmp.codnirstoc = m.codnirstoc &apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(pInsert||sqlstocini, 0, 0);
  COMMIT;
END;

PROCEDURE MakeSQLMiscari ( tmpname IN VARCHAR2, pInsert IN VARCHAR2, pFiltruGest IN BOOLEAN ) IS
	pInterval    VARCHAR2(500) := pkg_list_selfisamag.GetInterval;
  pCond        VARCHAR2(5000):= &apos;&apos;;
	sqlMiscari   VARCHAR2(32000);
  pColSerii    VARCHAR2(10000);
  pColTG       VARCHAR2(10000);
  pJoinSerii   VARCHAR2(10000);
  pCol         VARCHAR2(10000);
  pPreturi     VARCHAR2(10000);
  pGroup       VARCHAR2(10000);
BEGIN
-- crs_miscari
  IF pkg_list_selfisamag.isToateArt = 0 THEN
    pCond := pCond||&apos;
        AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos; ;
  END IF;
  IF NOT pkg_list_selfisamag.isAllTipCont THEN
    pCond := pCond||&apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos; ;
  END IF;
  IF pFiltruGest THEN
    pCond := pCond||&apos;
        AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;

  IF vGroup THEN
    pCol   := &apos;,
      Sum(intrare)  intrare,  Sum(iesire)  iesire,  Sum(intrare - iesire) stoc_fake,
      Sum(intr_um1) intr_um1, Sum(ies_um1) ies_um1, Sum(intr_um1-ies_um1) stoc_fake1,
      Sum(intr_um2) intr_um2, Sum(ies_um2) ies_um2, Sum(intr_um2-ies_um2) stoc_fake2,
      Sum((intrare-iesire)*Coalesce(PAchiz,0)) pAchiz, Sum((intrare-iesire)*Coalesce(PUVal,0)) PUVal, Sum((intrare-iesire)*Coalesce(PInreg,0)) PInreg, MAX(pumaximal) pumaximal,
      NULL dataexp, -1 furn, NULL pmpdoc, NULL pmpvalutadoc, NULL pmp, NULL pmpvaluta, NULL codnirstoc, NULL codnirstocparinte, NULL codlivr1&apos;;
    pGroup := &apos;
    GROUP BY
      sign(intrare), sign(iesire), coddoc, coddoc1,
      codobiect,tipmiscare,datadoc,datamisc,prefixdoc,nrdoc,
      gest,partener,codsubunit,codgestprod,an,luna,codioart,codlocatie,ordine,subunitatea_doc,userid,d1,d2,d3,codlocatiep,sursadest,contasoc,delegat,
      obsdoc, obslin, datacreare, codcentru&apos;;
    pPreturi := &apos;,
    m.pAchiz/CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END,
    m.PUVal/CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END,
    m.pInreg/CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END&apos;;
  ELSE
    pCol   := &apos;,
      intrare, iesire, (intrare - iesire) stoc_fake, intr_um1, ies_um1, (intr_um1-ies_um1) stoc_fake1, intr_um2,ies_um2,(intr_um2-ies_um2) stoc_fake2,
      Coalesce(PAchiz,0) PAchiz, Coalesce(puval,0) puval, Coalesce(pInreg,0) pInreg, Coalesce(pumaximal,0) pumaximal, dataexp, Coalesce(furn,0) furn,
      pmpdoc,pmpvalutadoc,pmp,pmpvaluta,codnirstoc,codnirstocparinte, codlivr1&apos;;
    pPreturi := &apos;,
    m.pAchiz, m.puval, m.pInreg&apos;;
  END IF;


  IF vSerii THEN
    pColSerii  := &apos;,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_ies
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_ies
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_ies
    END SERII,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii_obs
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_obs
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_obs
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii_obs
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_obs
    END SERII_OBS,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii_aux1
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_aux1
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_aux1
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii_aux1
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_aux1
    END SERNOCANT&apos;;

    pColTG := &apos;,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.TG
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.TG
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.TG
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.TG
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.TG
    END dataexp&apos;;

    pJoinSerii  := &apos;
    LEFT JOIN tmp_manevra_serii TMP ON TMP.CODNIRSTOC = M.CODNIRSTOC
    LEFT JOIN tmp_manevra_serii SERIES ON SERIES.CODLIVR1 = M.CODLIVR1&apos;;
  ELSE
    pColTG := &apos;,to_char(m.dataexp,&apos;&apos;dd.mm.yyyy&apos;&apos;) dataexp&apos;;
    pColSerii  := &apos;,
    NULL SERII, NULL SERII_OBS, NULL SERNOCANT&apos;;
  END IF;

  sqlmiscari := &apos;
  WITH crs_miscari AS (
    SELECT
      codobiect,coddoc1,tipmiscare,datadoc,datamisc,prefixdoc,nrdoc,
      coddoc, gest, partener,codsubunit,codgestprod,an,luna,codioart,
      codlocatie,ordine,subunitatea_doc,userid,d1,d2,d3,codlocatiep,
      sursadest, contasoc, delegat, obsdoc, obslin, datacreare, codcentru &apos;||
      pCol||&apos;
    FROM (
      SELECT
        ns.codnirstoc,ns.codnirstocparinte,ns.codobiect,n.codintr coddoc,i.datadoc,n.datanir datamisc,i.prefixdoc,i.nrdoc,
        ns.codintr1 coddoc1, ns.codlivr1,
        ns.cantnir intrare, 0 iesire, ns.cantum1 intr_um1, 0 ies_um1, ns.cantum2 intr_um2, 0 ies_um2, n.tipnir tipmiscare, 1 ordine,
        ( ns.pret - ns.adaos) PAchiz, Coalesce(NS.PUVal,0) PUVal, ns.pret pInreg, ns.pumaximal, ns.tg dataexp, ns.furn, n.gest, &apos;&apos; &apos;&apos; sursadest,
        i.partener, i.codsubunit, Coalesce(i.codgestprod,ns.codgestprod) codgestprod,
        i.an,i.luna,ns.codioart,ns.codlocatie,i.subunitatea subunitatea_doc,i.userid, ns.d1, ns.d2, ns.d3,
        null PMPDOC,null PMPVALUTADOC, NULL PMP,NULL PMPVALUTA,i.codlocatie codlocatiep,
        NULL contasoc, del.delegat, i.obs obsdoc, i1.obs obslin, i.datacreare, i1.codcentru
      FROM nirstoc ns
        INNER JOIN nir n ON ns.codnir = n.codnir
        LEFT JOIN intrari1 i1 ON ns.codintr1 = i1.codintr1
        LEFT JOIN dvi1 ON ns.coddvi1 = dvi1.coddvi1
        LEFT JOIN intrari i ON i.codintr = n.codintr
        LEFT JOIN nparttr del ON i.delegat = del.codparttr
      WHERE n.tipnir BETWEEN 1 AND 9
        AND n.datanir BETWEEN &apos;||pInterval||&apos;
        AND N.ANULAT = 0 AND N.OPERAT = 1&apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||
        pCond||&apos;
      UNION ALL --iesiri,intrari in rosu(pe acelasi codnirstoc), monetare,mariri si diminuare
      SELECT
        ns.codnirstoc,ns.codnirstocparinte,ns.codobiect,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.codintr ELSE ies.codies END coddoc,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.datadoc ELSE ies.datadoc END datadoc,
        l.datalivr datamisc,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.prefixdoc ELSE ies.prefixdoc END prefixdoc,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.nrdoc ELSE ies.nrdoc END nrdoc,
        COALESCE(l1.codies1, l1.codintr1) coddoc1, l1.codlivr1,
        CASE WHEN l.tiplivr in(1,2,3,4,5,6,7) THEN -l1.cant WHEN L.TIPLIVR IN (15) THEN L1.CANT ELSE 0 END intrare,
        CASE WHEN (l.tiplivr BETWEEN 19 AND 26 ) OR (l.tiplivr = 16) OR (l.tiplivr = 14) THEN l1.cant ELSE 0 END iesire,
        CASE WHEN l.tiplivr in(1,2,3,4,5,6,7) THEN -l1.cantum1 WHEN L.TIPLIVR IN (15) THEN L1.CANTUM1 ELSE 0 END intr_um1,
        CASE WHEN (l.tiplivr BETWEEN 19 AND 26 ) OR (l.tiplivr = 16) OR (l.tiplivr = 14) THEN l1.cantUM1 ELSE 0 END ies_um1,
        CASE WHEN l.tiplivr in(1,2,3,4,5,6,7) THEN -l1.cantum2 WHEN L.TIPLIVR IN (15) THEN L1.CANTUM2 ELSE 0 END intr_um2,
        CASE WHEN (l.tiplivr BETWEEN 19 AND 26 ) OR (l.tiplivr = 16) OR (l.tiplivr = 14) THEN l1.cantUM2 ELSE 0 END ies_um2,
        l.tiplivr tipmiscare,
        CASE WHEN l.tiplivr = 1 THEN 4 ELSE 5 END ordine,
        (ns.pret - ns.adaos) pAchiz, Coalesce(NS.PUVal,0) PUVal, ns.pret pInreg, ns.pumaximal, ns.tg dataexp, ns.furn, n.gest, &apos;&apos; &apos;&apos; sursadest,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.partener ELSE ies.partener END partener,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.codsubunit ELSE ies.codsubunit END codsubunit,
        Coalesce(ies.codgestprod, intr.codgestprod) codgestprod,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.an ELSE ies.an END an,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.luna ELSE ies.luna END luna,
        ns.codioart,ns.codlocatie,
        CASE WHEN INTR.CODINTR IS NULL THEN IES.SUBUNITATEA ELSE INTR.SUBUNITATEA END SUBUNITATEA_DOC,
        CASE WHEN INTR.CODINTR IS NULL THEN IES.userid ELSE INTR.userid END userid, ns.d1, ns.d2, ns.d3,
        l1.PMPDOC,l1.PMPVALUTADOC,L1.PMP,L1.PMPVALUTA, ies.codlocatie codlocatiep,
        CASE
          WHEN tiplivr IN (14,15) AND Coalesce(ies1.cont,0) &lt;&gt; 0 THEN ies1.cont
          WHEN tiplivr IN (14,15) AND Coalesce(tc.codcont,0) &lt;&gt; 0 THEN tc.codcont
          ELSE NULL
        END contasoc, del.delegat,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.obs ELSE ies.obs END obsdoc,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr1.obs ELSE ies1.obs END obslin,
        CASE WHEN l.tiplivr in (1,2,3,4,5,6,7) THEN intr.datacreare ELSE ies.datacreare END datacreare,
        ies1.codcentru
      FROM livr1 l1
        INNER JOIN livr l ON l.codlivr = l1.codlivr
        INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
        LEFT JOIN iesiri ies ON ies.codies = l.codies
        LEFT JOIN nparttr del ON ies.delegat = del.codparttr
        LEFT JOIN intrari intr ON intr.codintr = l.codintr
        LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies AND ies1.codies1 = l1.codies1
        LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr AND intr1.codintr1 = l1.codintr1
        LEFT JOIN tipchelt tc ON tc.codtipchelt = ies.tipchelt
        LEFT JOIN nir n ON n.codnir = ns.codnir
      WHERE ((l.tiplivr BETWEEN 19 AND 26 AND l1.cant &gt; 0 ) OR (tiplivr IN (1,2,3,4,5,6,7,14,15,16) ))
        AND trunc(l.DATALIVR)  BETWEEN &apos;||pInterval||&apos;
        AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;COALESCE(intr.subunitatea,ies.subunitatea)&apos;)||
        pCond||&apos;
      UNION ALL -- iesiri in rosu pe codnirstocuri noi
      SELECT
        ns.codnirstoc,ns.codnirstocparinte,ns.codobiect, i.codies coddoc,i.datadoc, l.datalivr datamisc ,i.prefixdoc,i.nrdoc,
        l1.codies1 coddoc1,l1.codlivr1,
        0 intrare, l1.cant iesire, -l1.cantum1 intr_um1, 0 ies_um1, -l1.cantum2 intr_um2, 0 ies_um2,
        l.tiplivr tipmiscare, 4 ordine,
        (ns.pret - ns.adaos) pAchiz, Coalesce(NS.PUVal,0) PUVal, ns.pret pInreg, ns.pumaximal, ns.tg dataexp,
        ns.furn, n.gest, &apos;&apos; &apos;&apos; sursadest, i.partener, i.codsubunit, Coalesce(i.codgestprod,ns.codgestprod) codgestprod,
        i.an,i.luna,ns.codioart,ns.codlocatie,i.subunitatea SUBUNITATEA_DOC,
        i.userid, ns.d1, ns.d2, ns.d3, l1.PMPDOC,l1.PMPVALUTADOC,l1.pmp,l1.pmpvaluta, i.codlocatie codlocatiep,
        NULL contasoc, del.delegat, i.obs obsdoc, ies1.obs obslin, i.datacreare, ies1.codcentru
      FROM livr1 l1
        INNER JOIN livr l ON l.codlivr = l1.codlivr
        INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
        LEFT JOIN iesiri i ON i.codies = l.codies
        LEFT JOIN iesiri1 ies1 ON ies1.codies = i.codies AND ies1.codies1 = l1.codies1
        LEFT JOIN nparttr del ON i.delegat = del.codparttr
        LEFT JOIN nir n ON n.codnir = ns.codnir
      WHERE (l.tiplivr BETWEEN 19 AND 26 AND l1.cant &lt; 0 )
        AND trunc(l.DATALIVR)  BETWEEN &apos;||pInterval||&apos;
        AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||
        pCond||&apos;
      UNION ALL -- transferuri destinatii
      SELECT
        ns.codnirstoc,ns.codnirstocparinte,ns.codobiect, t.codtransf,t.datadoc,n.datanir datamisc,t.prefixdoc,t.nrdoc,
        ns.codtransf1 coddoc1,ns.codlivr1,
        ns.cantnir intrare, 0 iesire, ns.cantum1 intr_um1, 0 ies_um1, ns.cantum2 intr_um2, 0 ies_um2,
        n.tipnir AS tipmiscare, 2 ordine ,(ns.pret - ns.adaos) pAchiz, Coalesce(NS.PUVal,0) PUVal, ns.pret pInreg,ns.pumaximal, ns.tg dataexp, ns.furn, n.gest,
        &apos;&apos;Transfer din &apos;&apos; sursadest,
        ngs.CODGEST partener,NULL codsubunit, ns.codgestprod, t.an, t.luna, ns.codioart,ns.codlocatie, t.SUBUNITATEA SUBUNITATEA_DOC,
        t.userid, ns.d1, ns.d2, ns.d3,NULL PMPDOC,NULL PMPVALUTADOC,null PMP,null PMPVALUTA, 0 codlocatiep,
        NULL contasoc, del.delegat, t.obs obsdoc, CAST(t1.obs AS VARCHAR2(500)) obslin, t.datacreare, t1.codcentru
      FROM transf1 t1
        INNER JOIN nirstoc ns ON ns.codtransf1 = t1.codtransf1
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest= n.gest
        INNER JOIN transf t ON t.codtransf = t1.codtransf
        LEFT JOIN nparttr del ON t.delegat = del.codparttr
        LEFT JOIN nirstoc nss ON nss.codnirstoc = ns.codnirstocparinte
        LEFT JOIN nir nirs ON nirs.codnir = nss.codnir
        LEFT JOIN ngest ngs ON ngs.codgest= nirs.gest
      WHERE trunc(n.datanir) BETWEEN &apos;||pInterval||&apos;
        AND N.ANULAT = 0 AND N.OPERAT = 1&apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||--pot fi transferuri intre gestiuni de pe subunitati diferite
        pCond||&apos;
      UNION ALL --transferuri surse
      SELECT
        nsd.codnirstoc, ns.codnirstoc, ns.codobiect, t.codtransf, t.datadoc, l.datalivr datamisc, t.prefixdoc, t.nrdoc,
        t1.codtransf1 coddoc1, l1.codlivr1,
        0 intrare, nsd.cantnir iesire, 0 intr_um1, nsd.cantum1 ies_um1, 0 intr_um2, nsd.cantum2 ies_um2, nd.tipnir tipmiscare, 3 ordine,
        (ns.pret - ns.adaos) pAchiz, Coalesce(NS.PUVal,0) PUVal, ns.pret pInreg, ns.pumaximal, ns.tg dataexp, ns.furn, n.gest,
        &apos;&apos;Transfer catre &apos;&apos; sursadest,
        nd.gest partener, NULL codsubunit, ns.codgestprod, t.an,t.luna,ns.codioart,ns.codlocatie, t.subunitatea SUBUNITATEA_DOC,
        t.userid, ns.d1, ns.d2, ns.d3, NULL PMPDOC,NULL PMPVALUTADOC,null PMP,null PMPVALUTA, 0 codlocatiep,
        NULL contasoc, del.delegat, t.obs obsdoc, CAST(t1.obs AS VARCHAR2(500)) obslin, t.datacreare, t1.codcentru
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN transf1 t1 ON t1.codtransf1 = l1.codies1
        INNER JOIN transf t ON t.codtransf = t1.codtransf
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN nirstoc nsd ON nsd.codlivr1 = l1.codlivr1
        INNER JOIN nir nd ON nd.codnir = nsd.codnir
        LEFT JOIN ngest ngd ON ngd.codgest= nd.gest
        LEFT JOIN nparttr del ON t.delegat = del.codparttr
      WHERE trunc(L.DATALIVR) BETWEEN &apos;||pInterval||&apos;
        AND L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0&apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||
        pCond||&apos;
    )&apos;||
    pGroup||&apos;
  )
  SELECT
    m.coddoc, m.tipmiscare, m.codnirstoc, m.codobiect, nobj.denumire, m.intrare,m.iesire, m.stoc_fake, m.intr_um1, m.ies_um1 , m.stoc_fake1, m.intr_um2, m.ies_um2, m.stoc_fake2&apos;||
    pPreturi||&apos;, m.pumaximal&apos;||pColTG||&apos;, CASE m.furn WHEN 0 THEN gestprod.den_gest ELSE furn.den_part END denfurn, prod.den_part,
    m.datadoc, m.datamisc, m.nrdoc, m.prefixdoc, pkg_list_base_utils.decode_tipdoc(m.tipmiscare) tipdoc, m.ordine,
    CASE
      WHEN m.tipmiscare IN (6,23) THEN nsub.den_subunit
      WHEN m.tipmiscare IN (7,24) THEN gestprod.den_gest
      WHEN m.tipmiscare IN (12)   THEN m.sursadest||gestdest.den_gest
      WHEN m.tipmiscare IN (13)   THEN &apos;&apos;Modificare de pret &apos;&apos;|| gestiunea.den_gest
      WHEN m.tipmiscare IN (14)   THEN &apos;&apos;Diminuare stoc pe contul &apos;&apos;||casoc.simbol||&apos;&apos; &apos;&apos;||gestiunea.den_gest
      WHEN m.tipmiscare IN (15)   THEN &apos;&apos;Marire stoc pe contul &apos;&apos;||casoc.simbol||&apos;&apos; &apos;&apos;||gestiunea.den_gest
      WHEN m.tipmiscare IN (16)   THEN (SELECT string_agg(DISTINCT nrcont) FROM moduriplati mp inner join nbankcont b ON b.codbankcont = mp.codbankcont where mp.codies = m.coddoc)
      ELSE m.prefixdoc||m.nrdoc||&apos;&apos;/&apos;&apos;||to_char(m.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)||&apos;&apos; &apos;&apos;||partener.den_part
    END sursadest,
    CASE
      WHEN m.tipmiscare IN (6,23) THEN nsub.den_subunit
      WHEN m.tipmiscare IN (7,24) THEN gestprod.den_gest
      WHEN m.tipmiscare IN (12)   THEN gestdest.den_gest
      WHEN m.tipmiscare IN (13,14,15) THEN gestiunea.den_gest
      ELSE partener.den_part
    END partener,
    gestiunea.den_gest, io.den_ioart, ncont.simbol, loc.denumire denlocatie&apos;||pColSerii||&apos;,
    m.codlivr1,SUB.DEN_SUBUNIT SUBUNITATEA_DOC, UM_PRINC.DEN_UM UM_PRINC,UM_ALT1.DEN_UM UM_ALT1, UM_ALT2.DEN_UM UM_ALT2,m.d1,m.d2 ,m.d3, NCLS.DEN_CLASEAS,
    m.pmp,m.pmpvaluta, m.PMPDOC, m.PMPVALUTADOC, m.delegat, m.obsdoc, m.obslin, trunc(m.datacreare), to_char(m.datacreare,&apos;&apos;hh24:mi&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM crs_miscari m
    INNER JOIN nartobj nobj ON m.codobiect = nobj.codobiect
    INNER JOIN nart a ON nobj.codarticol = a.codarticol
    LEFT JOIN npart furn ON m.furn = furn.codpart
    LEFT JOIN npart prod ON prod.codpart = nobj.codproducator
    LEFT JOIN npart partener ON m.partener = partener.codpart
    LEFT JOIN nsubunit nsub ON m.codsubunit = nsub.codsubunit
    LEFT JOIN ngest gestprod ON m.codgestprod = gestprod.codgest
    LEFT JOIN ngest gestiunea ON m.gest = gestiunea.codgest
    LEFT JOIN ioart io ON m.codioart = io.codioart
    LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart
    LEFT JOIN ncont ON io1.cont = ncont.codcont
    LEFT JOIN ncont casoc ON casoc.codcont = COALESCE(m.contasoc, CASE m.tipmiscare WHEN 14 THEN io1.minusinventar WHEN 15 THEN io1.plusinventar END, 0)
    LEFT JOIN nlocatii loc ON m.codlocatie = loc.codlocatie
    LEFT JOIN ngest gestdest on m.partener = gestdest.codgest&apos;||
    pJoinSerii||&apos;
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = m.SUBUNITATEA_DOC
    LEFT JOIN NUM UM_PRINC ON UM_PRINC.CODUM = A.UM
    LEFT JOIN NUM UM_ALT1 ON UM_ALT1.CODUM = A.UM1
    LEFT JOIN NUM UM_ALT2 ON UM_ALT2.CODUM = A.UM2
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = A.CLASA
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = A.CLASASTATIST
    LEFT JOIN NUM1 ON NUM1.CODUM = A.UM AND NUM1.SECUNDARA = 0
    LEFT JOIN NARTAMB AA ON aa.codobiect = m.codobiect AND aa.umsec = num1.codum1
    LEFT JOIN tmp_utilizator utilizator on m.userid = utilizator.codutilizator
    LEFT JOIN nagenda sediu ON m.codlocatiep = sediu.codagenda
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sediu.codlocalit
    LEFT JOIN nirstoc ns on ns.codnirstoc = m.codnirstoc
    LEFT JOIN nirstoc1 ns1 ON ns1.codnirstoc = NS.CodNirStoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocOrig
    LEFT JOIN nir n ON n.codnir = ns.codnir&apos;||
    gSuplJoins||&apos;
  WHERE io1.mg &lt;&gt; 5
    AND (m.an * 12 + m.luna) BETWEEN io1.ALStart and io1.ALStop&apos;;

  LIST_EXECUTE_IMMEDIATE(pInsert||sqlmiscari, 0, 0);
  COMMIT;
END;

PROCEDURE MakeSQLNedes ( tmpname IN VARCHAR2, pInsert IN VARCHAR2, pFiltruGest IN BOOLEAN ) IS
  pCond        VARCHAR2(5000)  := &apos;&apos;;
	sqlNedes     VARCHAR2(32000);
  pColSerii    VARCHAR2(10000);
  pColTG       VARCHAR2(10000);
  pJoinSerii   VARCHAR2(10000);
  pCol         VARCHAR2(10000);
  pPreturi     VARCHAR2(10000);
  pGroup       VARCHAR2(10000);
BEGIN
-- crs_miscari
  IF pkg_list_selfisamag.isToateArt = 0 THEN
    pCond := pCond||&apos;
        AND lv.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos; ;
  END IF;
--  IF NOT pkg_list_selfisamag.isAllTipCont THEN
--    pCond := pCond||&apos;
--        AND LV.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos; ;
--  END IF;
  IF pFiltruGest THEN
    pCond := pCond||&apos;
        AND LV.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;

  IF vGroup THEN
    pCol   := &apos;,
      Sum(intrare)  intrare,  Sum(iesire)  iesire,  Sum(intrare - iesire) stoc_fake,
      Sum(intr_um1) intr_um1, Sum(ies_um1) ies_um1, Sum(intr_um1-ies_um1) stoc_fake1,
      Sum(intr_um2) intr_um2, Sum(ies_um2) ies_um2, Sum(intr_um2-ies_um2) stoc_fake2,
      Sum((intrare-iesire)*Coalesce(PAchiz,0)) pAchiz, Sum((intrare-iesire)*Coalesce(PUVal,0)) PUVal, Sum((intrare-iesire)*Coalesce(PInreg,0)) PInreg, MAX(pumaximal) pumaximal,
      NULL dataexp, -1 furn, NULL pmpdoc, NULL pmpvalutadoc, NULL pmp, NULL pmpvaluta, NULL codnirstoc, NULL codnirstocparinte, NULL codlivr1&apos;;
    pGroup := &apos;
    GROUP BY
      sign(intrare), sign(iesire), coddoc, coddoc1,
      codobiect,tipmiscare,datadoc,datamisc,prefixdoc,nrdoc,
      gest,partener,codsubunit,codgestprod,an,luna,codioart,codlocatie,ordine,subunitatea_doc,userid,d1,d2,d3,codlocatiep,sursadest,contasoc,delegat,
      obsdoc, obslin, datacreare, codcentru&apos;;
    pPreturi := &apos;,
    m.pAchiz/CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END,
    m.PUVal /CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END,
    m.pInreg/CASE stoc_fake WHEN 0 THEN 1 ELSE stoc_fake END&apos;;
  ELSE
    pCol   := &apos;,
      intrare, iesire, (intrare - iesire) stoc_fake, intr_um1, ies_um1, (intr_um1-ies_um1) stoc_fake1, intr_um2,ies_um2,(intr_um2-ies_um2) stoc_fake2,
      Coalesce(PAchiz,0) PAchiz, Coalesce(puval,0) puval, Coalesce(pInreg,0) pInreg, Coalesce(pumaximal,0) pumaximal, dataexp, Coalesce(furn,0) furn,
      pmpdoc,pmpvalutadoc,pmp,pmpvaluta,codnirstoc,codnirstocparinte, codlivr1&apos;;
    pPreturi := &apos;,
    m.pAchiz, m.puval, m.pInreg&apos;;
  END IF;

  IF vSerii THEN
    pColSerii  := &apos;,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_ies
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_ies
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_ies
    END SERII,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii_obs
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_obs
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_obs
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii_obs
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_obs
    END SERII_OBS,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.serii_aux1
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.serii_aux1
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.serii_aux1
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.serii_aux1
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.serii_aux1
    END SERNOCANT&apos;;

    pColTG := &apos;,
    CASE
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &gt;= 0) THEN tmp.TG
      WHEN m.TIPMISCARE IN (1,2,3,4,5,6,7,8,9,13) AND (m.INTRARE &lt; 0) THEN series.TG
      WHEN m.TIPMISCARE IN (12) and ordine = 2 THEN series.TG
      WHEN m.TIPMISCARE IN (12) and ordine = 3 THEN tmp.TG
      WHEN m.TIPMISCARE IN (14,15,16,19,20,21,22,23,24,26) THEN series.TG
    END dataexp&apos;;

    pJoinSerii  := &apos;
    LEFT JOIN tmp_manevra_serii TMP ON TMP.CODNIRSTOC = M.CODNIRSTOC
    LEFT JOIN tmp_manevra_serii SERIES ON SERIES.CODLIVR1 = M.CODLIVR1&apos;;
  ELSE
    pColTG := &apos;,to_char(m.dataexp,&apos;&apos;dd.mm.yyyy&apos;&apos;) dataexp&apos;;
    pColSerii  := &apos;,
    NULL SERII, NULL SERII_OBS, NULL SERNOCANT&apos;;
  END IF;

  sqlNedes := &apos;
  WITH crs_nedes AS (
    SELECT
      codobiect,coddoc1,tipmiscare,datadoc,datamisc,prefixdoc,nrdoc,
      coddoc, gest, partener,codsubunit,codgestprod,an,luna,codioart,
      codlocatie,ordine,subunitatea_doc,userid,d1,d2,d3,codlocatiep,
      sursadest, contasoc, delegat, obsdoc, obslin, datacreare, codcentru &apos;||
      pCol||&apos;
    FROM (
      SELECT
        0 codnirstoc,0 codnirstocparinte,lv.codobiect,i.codies coddoc,i.datadoc,l.datalivr datamisc,i.prefixdoc,i.nrdoc,
        i1.codies1 coddoc1, l1.codlivr1,
        0 intrare, l1.cant iesire, 0 intr_um1, l1.cantum1 ies_um1, 0 intr_um2, l1.cantum2 ies_um2, i.tipdoc tipmiscare, 2 ordine,
        lv.pretachiz PAchiz, lv.pretinreg PUVal, lv.pretinreg pInreg, 0 pumaximal, cast(null as date) dataexp, 0 furn, lv.gest, &apos;&apos; &apos;&apos; sursadest,
        i.partener, i.codsubunit, i.codgestprod,i.an,i.luna,lv.codioart,0 codlocatie,i.subunitatea subunitatea_doc,i.userid, cast (null as number) d1, cast (null as number) d2, cast (null as number) d3,
        null PMPDOC,null PMPVALUTADOC, NULL PMP,NULL PMPVALUTA,i.codlocatie codlocatiep,
        NULL contasoc, del.delegat, i.obs obsdoc, i1.obs obslin, i.datacreare, i1.codcentru
      FROM
         LIVRVAL LV,
         LIVR1 L1,
         LIVR L,
         IESIRI1 I1,
         IESIRI I
         LEFT JOIN nparttr del ON I.delegat = del.codparttr,
         IOART1 IOALUNA,
         NART1 NART1LUNA,
         NTVA1 NTVALUNA,
         NARTOBJ O,
         NART A
      WHERE
        A.CODARTICOL = O.CODARTICOL AND
        LV.CODOBIECT = O.CODOBIECT AND
        LV.CODLIVR1 = L1.CODLIVR1 AND
        L1.CODIES1 = I1.CODIES1 AND
        L.CODLIVR = L1.CODLIVR AND
        L.TIPLIVR &lt;&gt; 12 AND
        L.TIPLIVR &lt;&gt; 13 AND
        I.CODIES = L.CODIES AND
        IOALUNA.CODIOART = LV.CODIOART AND I.AN*12+I.LUNA BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP AND
        NART1LUNA.CODARTICOL = A.CODARTICOL AND I.AN*12+I.LUNA BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP AND
        NTVALUNA.CODTVA = NART1LUNA.CODTVA AND I.AN*12+I.LUNA BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP AND
        COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
        I.OPERAT = 1 AND I.ANULAT = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||pCond||&apos; AND
        COALESCE(IOALUNA.DESCARCAREG, 0) = 0 AND
        COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,I.An,I.Luna)),0) AND
        L1.RESTIESVAL &lt;&gt; 0
      union all
      SELECT
        0 codnirstoc,0 codnirstocparinte,lv.codobiect,i.codintr coddoc,i.datadoc,l.datalivr datamisc,i.prefixdoc,i.nrdoc,
        i1.codintr1 coddoc1, l1.codlivr1,
        0 intrare, l1.cant iesire, 0 intr_um1, l1.cantum1 ies_um1, 0 intr_um2, l1.cantum2 ies_um2, i.tipdoc tipmiscare, 2 ordine,
        lv.pretachiz PAchiz, lv.pretinreg PUVal, lv.pretinreg pInreg, 0 pumaximal, cast(null as date) dataexp, 0 furn, lv.gest, &apos;&apos; &apos;&apos; sursadest,
        i.partener, i.codsubunit, i.codgestprod,i.an,i.luna,lv.codioart,0 codlocatie,i.subunitatea subunitatea_doc,i.userid, cast (null as number) d1, cast (null as number) d2, cast (null as number) d3,
        null PMPDOC,null PMPVALUTADOC, NULL PMP,NULL PMPVALUTA,i.codlocatie codlocatiep,
        NULL contasoc, del.delegat, i.obs obsdoc, i1.obs obslin, i.datacreare, i1.codcentru
      FROM
         LIVRVAL LV,
         LIVR1 L1,
         INTRARI1 I1,
         LIVR L,
         INTRARI I
         LEFT JOIN nparttr del ON I.delegat = del.codparttr,
         IOART1 IOALUNA,
         NARTOBJ O,
         NART A,
         NART1 NART1LUNA,
         NTVA1 NTVALUNA
      WHERE
        A.CODARTICOL = O.CODARTICOL AND
        LV.CODOBIECT = O.CODOBIECT AND
        LV.CODLIVR1 = L1.CODLIVR1 AND
        L1.CODINTR1 = I1.CODINTR1 AND
        L.CODLIVR = L1.CODLIVR AND
        L.TIPLIVR &lt;&gt; 12 AND
        L.TIPLIVR &lt;&gt; 13 AND
        I.CODINTR = L.CODINTR AND
        I.CODINTR = I1.CODINTR AND
        IOALUNA.CODIOART = LV.CODIOART AND I.AN*12+I.LUNA BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP AND
        NART1LUNA.CODARTICOL = A.CODARTICOL AND I.AN*12+I.LUNA BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP AND
        NTVALUNA.CODTVA = NART1LUNA.CODTVA AND I.AN*12+I.LUNA BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP AND
        COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
        I.OPERAT = 1 AND I.ANULAT = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||pCond||&apos; AND
        COALESCE(IOALUNA.DESCARCAREG, 0) = 0 AND
        COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,I.An,I.Luna)),0) AND
        L1.RESTIESVAL &lt;&gt; 0
      union all
      SELECT
        0 codnirstoc,0 codnirstocparinte,lv.codobiect,t.codtransf coddoc,T.datadoc,l.datalivr datamisc,T.prefixdoc,T.nrdoc,
        T1.codtransf1 coddoc1, l1.codlivr1,
        0 intrare, l1.cant iesire, 0 intr_um1, l1.cantum1 ies_um1, 0 intr_um2, l1.cantum2 ies_um2, t.tipdoc tipmiscare, 2 ordine,
        lv.pretachiz PAchiz, lv.pretinreg PUVal, lv.pretinreg pInreg, 0 pumaximal, cast(null as date) dataexp, 0 furn, lv.gest, &apos;&apos; &apos;&apos; sursadest,
        cast(null as number) partener, t.subunitdest codsubunit, 0 codgestprod,t.an,t.luna,lv.codioart,0 codlocatie,t.subunitatea subunitatea_doc,t.userid, cast (null as number) d1, cast (null as number) d2, cast (null as number) d3,
        null PMPDOC,null PMPVALUTADOC, NULL PMP,NULL PMPVALUTA,0 codlocatiep,
        NULL contasoc, del.delegat, t.obs obsdoc, null obslin, t.datacreare, t1.codcentru
      FROM
        LIVRVAL LV,
        LIVR1 L1,
        TRANSF1 T1,
        LIVR L,
        TRANSF T
        LEFT JOIN nparttr del ON t.delegat = del.codparttr,
        IOART1 IOALUNA,
        NARTOBJ O,
        NART A,
        NART1 NART1LUNA,
        NTVA1 NTVALUNA
      WHERE
        L1.CODLIVR1 = LV.CODLIVR1 AND
        T1.CODTRANSF1 = L1.CODIES1 AND
        L.CODLIVR   = L1.CODLIVR AND
        L.TIPLIVR IN (12, 13) AND
        T.CODTRANSF    = L.CODTRANSF AND
        T.CODTRANSF    = T1.CODTRANSF AND
        IOALUNA.CODIOART = LV.CODIOART AND
        O.CODOBIECT = LV.CODOBIECT AND
        A.CODARTICOL = O.CODARTICOL AND
        IOALUNA.CODIOART = LV.CODIOART AND T.AN*12+T.LUNA BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP AND
        NART1LUNA.CODARTICOL = A.CODARTICOL AND T.AN*12+T.LUNA BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP AND
        NTVALUNA.CODTVA = NART1LUNA.CODTVA AND T.AN*12+T.LUNA BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP AND
        COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
        T.OPERAT = 1 AND T.ANULAT = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||pCond||&apos; AND
        COALESCE(IOALUNA.DESCARCAREG, 0) = 0 AND
        COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,T.An,T.Luna)),0) AND
        L1.RESTIESVAL &lt;&gt; 0
    )&apos;||
    pGroup||&apos;
  )
  SELECT
    m.coddoc, m.tipmiscare, m.codnirstoc, m.codobiect, nobj.denumire, m.intrare,m.iesire, m.stoc_fake, m.intr_um1, m.ies_um1 , m.stoc_fake1, m.intr_um2, m.ies_um2, m.stoc_fake2&apos;||
    pPreturi||&apos;, m.pumaximal&apos;||pColTG||&apos;, CASE m.furn WHEN 0 THEN gestprod.den_gest ELSE furn.den_part END denfurn, prod.den_part,
    m.datadoc, m.datamisc, m.nrdoc, m.prefixdoc, pkg_list_base_utils.decode_tipdoc(m.tipmiscare) tipdoc, m.ordine,
    CASE
      WHEN m.tipmiscare IN (6,23) THEN nsub.den_subunit
      WHEN m.tipmiscare IN (7,24) THEN gestprod.den_gest
      WHEN m.tipmiscare IN (12)   THEN m.sursadest||gestdest.den_gest
      WHEN m.tipmiscare IN (13)   THEN &apos;&apos;Modificare de pret &apos;&apos;|| gestiunea.den_gest
      WHEN m.tipmiscare IN (14)   THEN &apos;&apos;Diminuare stoc pe contul &apos;&apos;||casoc.simbol||&apos;&apos; &apos;&apos;||gestiunea.den_gest
      WHEN m.tipmiscare IN (15)   THEN &apos;&apos;Marire stoc pe contul &apos;&apos;||casoc.simbol||&apos;&apos; &apos;&apos;||gestiunea.den_gest
      WHEN m.tipmiscare IN (16)   THEN (SELECT string_agg(DISTINCT nrcont) FROM moduriplati mp inner join nbankcont b ON b.codbankcont = mp.codbankcont where mp.codies = m.coddoc)
      ELSE m.prefixdoc||m.nrdoc||&apos;&apos;/&apos;&apos;||to_char(m.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)||&apos;&apos; &apos;&apos;||partener.den_part
    END sursadest,
    CASE
      WHEN m.tipmiscare IN (6,23) THEN nsub.den_subunit
      WHEN m.tipmiscare IN (7,24) THEN gestprod.den_gest
      WHEN m.tipmiscare IN (12)   THEN gestdest.den_gest
      WHEN m.tipmiscare IN (13,14,15) THEN gestiunea.den_gest
      ELSE partener.den_part
    END partener,
    gestiunea.den_gest, io.den_ioart, ncont.simbol, loc.denumire denlocatie&apos;||pColSerii||&apos;,
    m.codlivr1,SUB.DEN_SUBUNIT SUBUNITATEA_DOC, UM_PRINC.DEN_UM UM_PRINC,UM_ALT1.DEN_UM UM_ALT1, UM_ALT2.DEN_UM UM_ALT2,m.d1,m.d2 ,m.d3, NCLS.DEN_CLASEAS,
    m.pmp,m.pmpvaluta, m.PMPDOC, m.PMPVALUTADOC, m.delegat, m.obsdoc, m.obslin, trunc(m.datacreare), to_char(m.datacreare,&apos;&apos;hh24:mi&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM crs_NEDES m
    INNER JOIN nartobj nobj ON m.codobiect = nobj.codobiect
    INNER JOIN nart a ON nobj.codarticol = a.codarticol
    LEFT JOIN npart furn ON m.furn = furn.codpart
    LEFT JOIN npart prod ON prod.codpart = nobj.codproducator
    LEFT JOIN npart partener ON m.partener = partener.codpart
    LEFT JOIN nsubunit nsub ON m.codsubunit = nsub.codsubunit
    LEFT JOIN ngest gestprod ON m.codgestprod = gestprod.codgest
    LEFT JOIN ngest gestiunea ON m.gest = gestiunea.codgest
    LEFT JOIN ioart io ON m.codioart = io.codioart
    LEFT JOIN ioart1 io1 ON io.codioart = io1.codioart
    LEFT JOIN ncont ON io1.cont = ncont.codcont
    LEFT JOIN ncont casoc ON casoc.codcont = COALESCE(m.contasoc, CASE m.tipmiscare WHEN 14 THEN io1.minusinventar WHEN 15 THEN io1.plusinventar END, 0)
    LEFT JOIN nlocatii loc ON m.codlocatie = loc.codlocatie
    LEFT JOIN ngest gestdest on m.partener = gestdest.codgest&apos;||
    pJoinSerii||&apos;
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = m.SUBUNITATEA_DOC
    LEFT JOIN NUM UM_PRINC ON UM_PRINC.CODUM = A.UM
    LEFT JOIN NUM UM_ALT1 ON UM_ALT1.CODUM = A.UM1
    LEFT JOIN NUM UM_ALT2 ON UM_ALT2.CODUM = A.UM2
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = A.CLASA
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = A.CLASASTATIST
    LEFT JOIN NUM1 ON NUM1.CODUM = A.UM AND NUM1.SECUNDARA = 0
    LEFT JOIN NARTAMB AA ON aa.codobiect = m.codobiect AND aa.umsec = num1.codum1
    LEFT JOIN tmp_utilizator utilizator on m.userid = utilizator.codutilizator
    LEFT JOIN nagenda sediu ON m.codlocatiep = sediu.codagenda
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sediu.codlocalit
    LEFT JOIN nirstoc ns on ns.codnirstoc = m.codnirstoc
    LEFT JOIN nirstoc1 ns1 ON ns1.codnirstoc = NS.CodNirStoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocOrig
    LEFT JOIN nir n ON n.codnir = ns.codnir&apos;||
    gSuplJoins||&apos;
  WHERE (m.an * 12 + m.luna) BETWEEN io1.ALStart and io1.ALStop&apos;;

  LIST_EXECUTE_IMMEDIATE(pInsert||sqlNedes, 0, 0);
  COMMIT;
END;

FUNCTION VerFiltruGest RETURN BOOLEAN IS
  bResult    BOOLEAN;
  cntGestDed INTEGER := 0;
  vGestAcces INTEGER := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;GestAccesListeStoc&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),&apos;2&apos;));
BEGIN
  IF vGestAcces &lt;&gt; 1 THEN
    SELECT COUNT(CODGEST) INTO cntGestDed FROM TMP_GESTDEDICATE;
  END IF;
  bResult := (cntGestDed &gt; 0) OR (NOT pkg_list_selfisamag.isAllGest);
  IF cntGestDed &gt; 0 THEN
    IF pkg_list_selfisamag.isAllGest THEN
      INSERT INTO TMP_MANEVRA_LISTE(VALOARE, FILTRU) SELECT CODGEST, &apos;CODGEST&apos; FROM TMP_GESTDEDICATE;
    ELSE
      DELETE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; AND NOT VALOARE IN (SELECT CODGEST FROM TMP_GESTDEDICATE);
    END IF;
  END IF;
  RETURN bResult;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(1000);
  bFiltruGest BOOLEAN;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=
    &apos;nartobj nobj, npart furn, npart prod, nsubunit nsub, ngest gestprod, ncont ncont, nartamb aa, nirstoc ns, nirstoc nsroot, nart a, nclasea nca, nir n, ngest gestiunea, nlocatii loc,&apos;||
     -- coloane suplimentare doar pt partea cu miscari astea trebuie manevrate cu grija in parte de stoc initial
    &apos;npart partener, ngest gestdest, tmp_utilizator utilizator, nagenda sediu, nlocalit sedloc, &apos; || tmpname || &apos; TMP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;,    &apos;CCOST.CODCENTRU = M.CODCENTRU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,     &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,  &apos;IES&apos;,  &apos;IES.CODIES = M.CODDOC AND IES.TIPDOC = M.TIPMISCARE&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;, &apos;IES1&apos;, &apos;IES1.CODIES = IES.CODIES AND IES1.CODIES1 = M.CODDOC1&apos;, 1);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;, &apos;INTR&apos;,  &apos;INTR.CODINTR = M.CODDOC AND INTR.TIPDOC = M.TIPMISCARE&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,&apos;INTR1&apos;, &apos;INTR1.CODINTR = INTR.CODINTR AND INTR1.CODINTR1 = M.CODDOC1&apos;, 1);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF&apos;,  &apos;TRANSF&apos;,  &apos;TRANSF.CODTRANSF = M.CODDOC AND TRANSF.TIPDOC = M.TIPMISCARE&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF1&apos;, &apos;TRANSF1&apos;, &apos;TRANSF1.CODTRANSF = TRANSF.CODTRANSF AND TRANSF1.CODTRANSF1 = M.CODDOC1&apos;, 1);

  IF Coalesce(pkg_categconst.GetValConstanta(&apos;CumulezBCAR&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru),&apos;2&apos;) = &apos;2&apos; THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;, &apos;BCAR&apos;, &apos;BCAR.CODDOC1 = M.CODDOC1 AND BCAR.TIPDOC = M.TIPMISCARE&apos;, 1);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BCAREXT&apos;, &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vSint  := (aLISTID = 231);
  vSerii := pkg_list_selfisamag.areSerii AND NOT vSint ;
  vGroup := pkg_list_selfisamag.areSerii AND vSint;

  SELECT ANINITIAL*12+LUNAINITIALA INTO AnLunaMin FROM FIRMALUNI;

  DELETE FROM tmp_manevra_serii;
  COMMIT;
  IF vSerii
  THEN maketmpSerii;
  END IF;

  IF pkg_list_selfisamag.calculeaza_pmp THEN
    pkg_list_base_utils.CalculeazaPmpListe;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CODDOC, NAV_TIPDOC, NAV_NIRSTOC, CODOBIECT, DENUMIRE, INTRARE, IESIRE, STOC_FAKE, INTR_UM1, IES_UM1, STOC_FAKE1, INTR_UM2, IES_UM2, STOC_FAKE2,
    PACHIZ, PUVAL, PINREG, PUMAXIMAL, DATAEXP, DENFURN, DENPROD,
    DATADOC, DATAMISC ,NRDOC, PREFIXDOC, TIPDOC, ORDINE,
    SURSADEST,
    PARTENER,
    DEN_GEST, DEN_IOART, SIMBOL, DENLOCATIE, SERII, SEROBS, SERNOCANT,
    CODLIVR1,SUBUNITATEA_DOC, UM_PRINC, UM_ALT1, UM_ALT2, D1, D2, D3, CLASAS,
    PMP, PMPVALUTA, PMPDOC, PMPVALDOC, DELEGAT, OBSDOC, OBSLIN, DATACREARE, ORACREARE &apos;||gUserFields||&apos;)&apos;;

  bFiltruGest := VerFiltruGest;
  MakeSQLStocIni(tmpname, sInsert, bFiltruGest);
  MakeSQLMiscari(tmpname, sInsert, bFiltruGest);
  IF pkg_list_selfisamag.inclNedes THEN
    MakeSQLNedes(tmpname, sInsert, bFiltruGest);
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_fisamag2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15DE8E478172FDA651BFE82743EB5E14BB7A7393</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAMAS IS

  vCodFisaMas FISAMAS.CODFISAMAS%TYPE;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodFisaMas IN NUMBER)  IS
BEGIN
  vCodFisaMas := pCodFisaMas;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;NARTOBJ OBJ, FISAMAS1 FM1, PRODMAS PM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(VALOARE, STARE, OBS, DESCRIERE, FRECVENTA, METODA, DENUMIRE&apos;||gUserFields||&apos;)
  SELECT FM1.VALOARE, DECODE(STARE,1,&apos;&apos;In curs&apos;&apos;,2,&apos;&apos;Admis&apos;&apos;,3,&apos;&apos;Respins&apos;&apos;), FM1.OBS, PM.DESCRIERE, PM.FRECVENTA, PM.METODA, OBJ.DENUMIRE&apos;||gUserAlias||&apos;
  FROM FISAMAS1 FM1
    INNER JOIN PRODMAS PM ON FM1.CodProdMas = PM.CodProdMas
    LEFT  JOIN NARTOBJ OBJ ON PM.CodObiect = OBJ.CodObiect&apos;||
    gSuplJoins||&apos;
  WHERE FM1.CodFisaMas = &apos;||vCodFisaMas;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END pkg_list_base_fisamas;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAMENTENANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3D8C54DD2D04DCD201F0B5A04BAA42A219C5410</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAMENTENANTA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vCodUtilaj20 NUMBER(20);
 
  vDataS       DATE;
  vDataF       DATE;
function AduDescriere(aCodUtilaj2 in number) return varchar2 is
Descriere CLOB;
Rezultat varchar2(3200);
Linie varchar2(1000);
Poz number;
begin
  BEGIN
    select pc.descriere into Descriere
    from utilaje2 u2
         inner join ninterventiiauto i on u2.interventie = i.codinterventiiauto
         inner join prodcomp pc on i.codreteta = pc.codprodcomp
    where u2.codutilaj2 = aCodUtilaj2;
  EXCEPTION WHEN OTHERS THEN DESCRIERE := &apos;&apos;;
  END;

  if Length(Descriere) = 0 then Return &apos;&apos;; end if;

  Rezultat := &apos;&apos;;
  Poz := instr(Descriere,chr(13),1,1);
  if Poz &gt; 0 then
    Linie := SubStr(Descriere, 1, Poz - 1);
    Rezultat := Rezultat||Linie;
    while Poz &gt; 0 loop
      Poz := instr(Descriere,chr(13),1,1);
      if Poz &gt; 0 then
        Linie := SubStr(Descriere, 1, Poz - 1);
        if Rezultat = &apos;&apos; then
          Rezultat := Rezultat||Linie;
        else
          Rezultat := Rezultat||&apos;|&apos;||Linie;
        end if;
        Descriere := SubStr(Descriere, Poz + 2, Length(Descriere) - Poz);
      end if;
    end loop;
  end if;
  Rezultat := Rezultat||&apos;|&apos;||Descriere;
  return Rezultat;
end;

PROCEDURE SETPARAMS(aCODUTILAJ20 IN NUMBER,
					            V_CODJOB1 IN NUMBER  DEFAULT 0, 
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2
                      )IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  vCodUtilaj20 := aCodUtilaj20;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  
  FOR v_rec IN (
    SELECT
      OBJ.DENUMIRE,
      U.TIPUTILAJ,
      CASE 
        WHEN U.TIP = 0 THEN &apos;Utilaj propriu&apos;
        WHEN U.TIP = 1 THEN &apos;Utilaj in custodie la client&apos;
        WHEN U.TIP = 2 THEN &apos;Utilaj client&apos;
      END TIP,
      U.ETICHETA,
      U.FLOTA,
      CASE WHEN U.INACTIV = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END INACTIV,
      CASE WHEN U.APROBAT = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END APROBAT,
      CLI.DEN_PART CLIENT,
      U.NRCONTR,
      TO_CHAR(U.DATACONTR,&apos;DD.MM.YYYY&apos;) DATACONTR,
      case when U.DOC is null and U.CODIES1 &gt; 0 then I.NRDoc||&apos;/&apos;||to_char(I.DataDoc,&apos;DD.MM.YYYY&apos;) else U.DOC end DOC,
      FURN.DEN_PART FURNIZOR,
      U.MODEL,
      U.ANF,
      U.SERIEF,
      U.INCARCARE,
      TO_CHAR(U.DATAGARANTIEI,&apos;DD.MM.YYYY&apos;) DATAGI,
      TO_CHAR(U.DATAGARANTIE,&apos;DD.MM.YYYY&apos;) DATAGF,
      CASE WHEN U.INGARANTIE = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END INGARANTIE,
      TO_CHAR(U.DATASTART,&apos;DD.MM.YYYY&apos;) DATAPUNERE,  
      LOC.DEN_LOCALIT LOCALITATE,
      U.ADRESA,
      AG.NUME||&apos; &apos;||AG.PRENUME AGENT,
      UM.DEN_UM,
      U.PLAFONCANTF,
      U.LUNGIME,
      U.LATIME,
      U.INALTIME,
      U.OBS,
      U20.NRDOC NRP,
      TO_CHAR(U20.DATADOC,&apos;DD.MM.YYYY&apos;) DATAP,
      U20.DESCRIERE DESCRIEREP,
      CASE
        WHEN U20.STARE = 1 THEN &apos;initiala&apos;
        WHEN U20.STARE = 2 THEN &apos;in asteptare piese&apos;
        WHEN U20.STARE = 3 THEN &apos;in asteptare tehnician&apos;
        WHEN U20.STARE = 4 THEN &apos;in lucru&apos;
        WHEN U20.STARE = 7 THEN &apos;montaj&apos;
        WHEN U20.STARE = 5 THEN &apos;facturat&apos;
        WHEN U20.STARE = 6 THEN &apos;finalizat&apos;
      END STAREP,
      UT.USERNAME USERNAMEP,
      U20.OBS OBSP,
      I.NRDOC||&apos;/&apos;||TO_CHAR(I.DATADOC,&apos;DD.MM.YYYY&apos;) FACTURAP,
      LOCP.DEN_LOCALIT LOCALITATEP,
      U20.ADRESA ADRESAP,
      PC.NUME||&apos; &apos;||PC.PRENUME CONTACTP,
      PC.TELEFON TELEFONP   
    FROM UTILAJE20 U20
         INNER JOIN UTILAJE U ON U.CODUTILAJ = U20.CODUTILAJ
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = U.CODOBIECT
         LEFT JOIN NPART CLI ON CLI.CODPART = U.CODPART
         LEFT JOIN NPART FURN ON FURN.CODPART = U.CODFURNIZOR
         LEFT JOIN NLOCALIT LOC ON U.CODLOCALIT = LOC.CODLOCALIT
         LEFT JOIN NPERS AG ON AG.CODPERS = U.AGENT
         LEFT JOIN NUM UM ON UM.CODUM = U.UM
         LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = U20.OPERATOR
         LEFT JOIN IESIRI I ON I.CODIES = U20.CODIES
         LEFT JOIN NLOCALIT LOCP ON LOCP.CODLOCALIT = U20.CODLOCALIT
         LEFT JOIN NPERSCONTACT PC ON PC.CODPERSC = U20.CODPERSC
    WHERE U20.CODUTILAJ20 = vCodUtilaj20
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj&apos;, v_rec.Denumire);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - tip utilaj&apos;, v_rec.TipUtilaj);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - tip&apos;, v_rec.Tip);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - eticheta&apos;, v_rec.Eticheta);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - flota&apos;, v_rec.Flota);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - inactiv&apos;, v_rec.Inactiv);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - aprobat&apos;, v_rec.Aprobat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - client&apos;, v_rec.Client);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - contract&apos;, v_rec.NrContr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - data contract&apos;, v_rec.DataContr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - document&apos;, v_rec.Doc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - furnizor&apos;, v_rec.Furnizor);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - model&apos;, v_rec.Model);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - an fabricatie&apos;, v_rec.AnF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - serie fabricatie&apos;, v_rec.SerieF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - incarcare ore pe zi&apos;, v_rec.Incarcare);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - data inceput garantie&apos;, v_rec.DataGI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - data sfarsit garantie&apos;, v_rec.DataGF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - in garantie&apos;, v_rec.InGarantie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - data punere in functiune&apos;, v_rec.DataPunere);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - localitate&apos;, v_rec.Localitate);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - adresa&apos;, v_rec.Adresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - agent&apos;, v_rec.Agent);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - UM index&apos;, v_rec.den_um);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - plafon facturare index&apos;, v_rec.plafoncantf);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - lungime&apos;, v_rec.Lungime);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - latime&apos;, v_rec.Latime);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - inaltime&apos;, v_rec.Inaltime);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Utilaj - observatii&apos;, v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - numar&apos;, v_rec.NrP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - data&apos;, v_rec.DataP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - descriere&apos;, v_rec.DescriereP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - stare&apos;, v_rec.StareP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - operator&apos;, v_rec.UserNameP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - observatii&apos;, v_rec.ObsP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - factura&apos;, v_rec.FacturaP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - localitate&apos;, v_rec.LocalitateP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - adresa&apos;, v_rec.AdresaP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - contact&apos;, v_rec.ContactP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Problema - telefon contact&apos;, v_rec.TelefonP);
    EXIT;
  END LOOP;
END;  

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  varchar2(10000);
  sWhere   varchar2(200) := &apos;UTILAJE20 U20,UTILAJE2 U2,COMANDA1 C1,COMANDA C,NINTERVENTIIAUTO I,NARTOBJ SERV&apos;;
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
     DATAV,
     INDEXV,
     DATAC,
     INDEXC,
     NRDOC,
     DATADOC,
     SECTIE,
     DATASTART,
     DATASTOP,
     DURATA,
     INTERVENTIE,
     SERVICIU,
     PERSONAL,
     AUTO,
     KM &apos;||gUserFields||&apos;)
   SELECT
     U2C.DATAV,
     U2C.INDEXV,
     U2C.DATAINDEXC,
     U2C.INDEXC,
     C.NRDOC,
     C.DATADOC,
     G.DEN_GEST SECTIE,
     U2C.DATASTART,
     U2C.DATAEND,
     TRUNC(TO_NUMBER (TO_DATE(TO_CHAR(U2C.DATAEND, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;) - 
                      TO_DATE(TO_CHAR(U2C.DATASTART, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;)) * 24 * 60) DURATA,
     I.DENUMIRE INTERVENTIE,
     SERV.DENUMIRE SERVICIU,
     (
      SELECT stragg3200(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME)
      FROM UTILAJE2P U2P
           INNER JOIN NPERS P ON P.CODPERS = U2P.CODPERS
      WHERE U2P.CODUTILAJ2 = U2.CODUTILAJ2
     ) PERSONAL,
     AUTO.NRINREG,
     U2.KMPARCURSI &apos;||gUserAlias||&apos;
  FROM UTILAJE20 U20
       LEFT JOIN UTILAJE2 U2 ON U2.CODUTILAJ20 = U20.CODUTILAJ20
       LEFT JOIN UTILAJE2C U2C ON U2C.CODUTILAJ2 = U2.CODUTILAJ2
       LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = U2C.CODCOMANDA1
       LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       LEFT JOIN NGEST G ON C.CODGEST = G.CODGEST
       LEFT JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
       LEFT JOIN NARTOBJ SERV ON SERV.CODOBIECT = I.SERVICIU
       LEFT JOIN NPARCAUT AUTO ON AUTO.CODNPARCAUT = U2.CODAUTO
  &apos;||gSuplJoins||&apos;
  WHERE U20.CODUTILAJ20 = &apos;||vCodUtilaj20;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
    
  PKG_LIST_BASE_FISAMENTENANTA.ADD_LIST_PARAMS;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_FISAMENTENANTA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>537D5FE145C0CA25A3FD826134082094EAE45405</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAMF is

p_Tabla VARCHAR2(250);
pCodMifix number(20);
gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams (v_Tabla IN VARCHAR2, vCodMifix in number) IS
BEGIN
  p_Tabla := Upper(v_Tabla);
  pCodMifix := vCodMifix;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString VARCHAR2(5000);
BEGIN
  gSuplCols :=
    &apos;MIFIX M, MIFIX1 M1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString := &apos;insert into &apos;||tmpName||&apos;(
    NAV_CODDOC,
    NAV_TIPDOC,
    NAV_NIRSTOC,
    DENUMIRE,
    NRINVENTAR,
    DEN_PART,
    DATAOPERATIE,
    GEST,
    PRETE,
    PREFIXDOC,
    NRDOC,
    CANT,
    VALOARE,
    TVA,
    DATADOC,
    OBS,
    TIPOPERATIE,
    JURNAL,
    DIRTY,
    AN,
    LUNA,
    CENTRU&apos;||gUserFields||&apos;)
  select
    tmp.CODDOC,
    tmp.TIPDOC,
    tmp.CODNIRSTOC,
    tmp.DENUMIRE,
    tmp.NRINVENTAR,
    tmp.DEN_PART,
    tmp.DATAOPERATIE,
    g.den_gest,
    tmp.PRETE,
    tmp.PREFIXDOC,
    tmp.NRDOC,
    tmp.CANT,
    tmp.VALOARE,
    tmp.TVA,
    tmp.DATADOC,
    tmp.OBS,
    tmp.TIPOPERATIE,
    tmp.JURNAL,
    case when tmp.DIRTY &gt; 0 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    tmp.AN,
    tmp.LUNA,
    cc.denumire&apos;||gUserAlias||&apos;
  from &apos;||p_Tabla||&apos; tmp
       left join mifix m on m.nrinventar = tmp.nrinventar and m.tip = &apos;&apos;MF&apos;&apos;
       left join mifix1 m1 on m1.codmifix = m.codmifix and m1.anstart = tmp.an and m1.lunastart = tmp.luna
       left join ngest g on tmp.gestdest = g.codgest
       left join centrecost cc on cc.codcentru = tmp.codcentru&apos;||gSuplJoins;

  --delete x;
  --insert into x(test) values(sstring);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);
  Commit;
  PROCESSPARAMS;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT tmp.Denumire, tmp.NrInventar, tmp.Den_Clasif, c.simbol,
           CASE WHEN MF.ANINTRARE*12+MF.LUNAINTRARE &gt; MF1.ANSTART*12+MF1.LUNASTART THEN MF.ANINTRARE+Trunc((MF.LUNAINTRARE+MF1.DURATAF-1)/12) ELSE MF1.ANSTART+Trunc((MF1.LUNASTART+MF1.DURATAF-1)/12) END AnAmort,
           MOD(Greatest(MF.ANINTRARE * 12 + MF.LUNAINTRARE, MF1.ANSTART * 12 + MF1.LUNASTART) + MF1.DURATAF - 1,12) + 1 LunaAmort,
           (select round(mf2.amo,2) from mifix1 mf2
            where mf2.codmifix = mf.codmifix and
                  mf2.anstart*12+mf2.lunastart = (select max(anstart*12+lunastart) from mifix1 where codmifix = mf.codmifix)) amocumul,
           round(tmp.valintrare,2) valintrare,
           round(
           PKG_INCHIDERI.GETAMOLUNA(
             Coalesce(MF1.ANSTART,0), Coalesce(MF1.LUNASTART,0), Coalesce(MF1.AMO,0), Coalesce(MF1.NEUTIL,0), Coalesce(MF1.DURATAF,0),
             Coalesce(MF1.PRET,0), Coalesce(MF1.CANT,0), Coalesce(MF1.GRADU,0)/100, Coalesce(MF.ANINTRARE,0), Coalesce(MF.LUNAINTRARE,0), Coalesce(MF1.TIPAMO,0), Coalesce(MF1.DURATAN,0), MF.TIP
           ),2) AmortLun, f.prefixdoc||f.nrdoc||&apos;/&apos;||f.dataoperatie docintrare, substr(c.simbol,1,1) grupa, mf1.duratan
    FROM tmp_evidentamf tmp
         left join mifix1 mf1 on tmp.codmifix1 = mf1.codmifix1 and mf1.anstart*12+mf1.lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.getlunalucru
         left join mifix mf on mf.codmifix = mf1.codmifix
         left join mfclasif c on c.codclasif = mf1.codclasif
         left join fisamf f on f.codmifix = mf1.codmifix
    WHERE tmp.CodMifix = pCodMifix
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DENUMIRE&apos;,               v_rec.Denumire);
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR. INVENTAR&apos;,           v_rec.NrInventar);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLASIFICARE&apos;,            v_rec.Den_Clasif);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COD CLASIFICARE&apos;,        v_rec.Simbol);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AN FINAL&apos;,               v_rec.AnAmort);
    pkg_list_Struct.ADAUGA_PARAM(&apos;LUNA FINALA&apos;,            v_rec.LunaAmort);

    pkg_list_Struct.ADAUGA_PARAM(&apos;AMORTIZARE LUNARA&apos;,      TO_CHAR(v_rec.amortlun,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;AMORTIZARE CUMULATA&apos;,    TO_CHAR(v_rec.amocumul,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE INTRARE&apos;,        TO_CHAR(v_rec.valintrare,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC. INTRARE&apos;,           v_rec.docintrare);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GRUPA CLASIFICARE&apos;,      v_rec.grupa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DURATA NORMALA DE FUNCTIONARE&apos;, v_rec.duratan);
    exit;
  END LOOP;
end;

end PKG_LIST_BASE_FISAMF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A18C7CEDED195E6DB1B7D5ACC825284B5203FB5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAPERS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

function GetSimbolCor(aCodObligPif in number, aCODNBANKCONT in number) return varchar2 is
  aICont number(20);
  aSemnificatie number(10);
  aSemnificatie2 number(20);
  aCodPart number(20);
  aSimbolCont varchar2(100);
  aIOBank number(20);
  aCont number(20);
begin
  aSimbolCont := &apos;@&apos;;

  select ICont, Semnificatie, CodPart into aICont, aSemnificatie, aCodPart
  from obligpif
  where codobligpif = aCodObligPif;

  begin
    SELECT Coalesce(OO.SEMNIFICATIE, 0) into aSemnificatie2
    FROM STINGERE SS
         LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
    WHERE SS.CODSTINGATORPIF = aCODOBLIGPIF;
  exception when others then
    aSemnificatie2 := 0;
  end;

  if aSemnificatie in (300, 320) and aSemnificatie2 = 500 then
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(aICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU));
  end if;

  begin
    SELECT Coalesce(OO.SEMNIFICATIE, 0) into aSemnificatie2
    FROM STINGERE SS
         LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
    WHERE SS.CODSTINGATORPIF = aCODOBLIGPIF AND ROWNUM &lt;=1;
  exception when others then
    aSemnificatie2 := 0;
  end;

  if aSemnificatie in (300, 320) and aSemnificatie2 = 600 then
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(aICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU));
  end if;

  if aSemnificatie in (800, 801) THEN
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(aICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU));
  end if;

  if aSemnificatie in (900, 901, 950, 951) THEN
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(aICONT);
  end if;

  if aSemnificatie in (1100, 1101) THEN
    aIOBank := PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(aCODNBANKCONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    begin
      select cont into aCont from iobank1 where codiobank1 = aiobank;
    exception when others then aCont := 0;
    end;
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(aCont);
  end if;

  if aSimbolCont = &apos;@&apos; then
    aSimbolCont := PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(aSEMNIFICATIE, aICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(aCODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)));
  end if;

  return aSimbolCont;
end;

PROCEDURE UmpleTMP(tmpname IN VARCHAR2, aLISTID IN NUMBER, aLISTVER IN NUMBER, aHolding IN NUMBER) IS
  sInsert       VARCHAR2(600);
  sSelect0      VARCHAR2(20000);
  sSelect1      VARCHAR2(20000);
  sSelect2_1    VARCHAR2(20000);
  sSelect2_2    VARCHAR2(20000);
  sSelect3_as   VARCHAR2(20000);
  sSelect4_1    VARCHAR2(20000);
  sSelect4_2    VARCHAR2(20000);
  sSelect4_3    VARCHAR2(20000);
  sSelect4_4    VARCHAR2(20000);
  sSelect4_reg  VARCHAR2(20000);

  sCondPers     VARCHAR2(1000);
  sCondMon      VARCHAR2(1000);
  sCondCont     VARCHAR2(1000);

  sCursRef      VARCHAR2(100);
  sCursRefReg   VARCHAR2(100);
  sCursRefNC    VARCHAR2(100);
  sCursRefConv  VARCHAR2(100);
  sDebit        VARCHAR2(500);
  sCredit       VARCHAR2(500);

  aSitV         NUMBER(1);
  aBancaV       NUMBER(20);
  aMonedaV      NUMBER(20);

  vALIni        NUMBER(5) := PKG_LIST_SELFISAPERS.AnLunaIni;
  vALFin        NUMBER(5) := PKG_LIST_SELFISAPERS.AnLunaFin;
  vAnIni        NUMBER(4);
  vLunaIni      NUMBER(2);
  vDataIni      DATE;
  SoldAnLunaMin NUMBER(20);
  vALInitiala   NUMBER(5);
  vAnInitial    NUMBER(4);
  vLunaInitiala NUMBER(2);
BEGIN
  --pkg_globals.setdebugmode(true);  
  gSuplCols := &apos;NPERS NP, NPERS1 NP1, NCONT NCONT, NMONEDE MON, TREZOR T, TREZOR1 T1, &apos; || tmpname || &apos; TMP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  SELECT AnInitial, LunaInitiala, AnInitial*12+LunaInitiala
  INTO   vAnInitial, vLunaInitiala, vALInitiala
  FROM firmaluni;

  PKG_LIST_BASE_UTILS.ExtractAnLuna(vALIni, vAnIni, vLunaIni);
  vDataIni := to_date(&apos;01.&apos;||to_char(vLunaIni,&apos;FM00&apos;)||&apos;.&apos;||to_char(vAnIni, &apos;FM0000&apos;),&apos;DD.MM.YYYY&apos;);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef     := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, t1.datadoc)&apos;;
    sCursRefConv := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, CV.datadoc)&apos;;
    sCursRefNC   := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, n.datadoc)&apos;;
    sCursRefReg  := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, REG.datadoc)&apos;;
  ELSE
    sCursRef     := &apos;1&apos;;
    sCursRefConv := &apos;1&apos;;
    sCursRefNC   := &apos;1&apos;;
    sCursRefReg  := &apos;1&apos;;
  END IF;

  IF PKG_LIST_SELFISAPERS.CODPERS &lt;&gt; 0 THEN
    sCondPers := &apos; AND NP.CODPERS = &apos;||PKG_LIST_SELFISAPERS.CODPERS;
  END IF;
  IF NOT PKG_LIST_SELFISAPERS.isAllMon THEN
    sCondMon := &apos;
    AND MON.CODMONEDA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;) &apos;;
  END IF;
  IF NOT PKG_LIST_SELFISAPERS.isAllTipC THEN
    sCondCont := &apos;
    AND NCONT.CODCONT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;) &apos;;
  END IF;

  SELECT Min(an*12+luna) INTO SoldAnLunaMin FROM nperssoldluna;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos; (
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, DATADOC, PREFIXDOC, NRDOC, VALDOC, MONEDA, CURS,
    DEBIT,
    CREDIT,
    SOLD_COL,
    TIPSOLD,
    CONT, ORDINE, ANGAJAT,
    EXPLICATII, CURS_REF, SUBUNITATEA,
    Obs, Doc, DocTrezor, ObsJ, ContCor &apos;||gUserFields||&apos;)&apos;;

  -- sold initial
  IF PKG_LIST_SELFISAPERS.isSubunit then
    sSelect0 := &apos;
    SELECT
      NULL NAV_CodDoc, NULL NAV_CodDoc1, NULL NAV_TipDoc, to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DATADOC, null DOC, NULL NRDOC, NULL  VALDOC, MON.SIMBOL MONEDA, NULL CURS,
      CASE WHEN NCONT.tipcont =  1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END DEBIT,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END CREDIT,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN 1     ELSE -1    END * &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; SOLD,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
      NCONT.SIMBOL, 0 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
      &apos;&apos;Sold initial &apos;&apos; EXPLICATII, null, NSUB.Den_Subunit, NULL,
      NULL, T.NumeDoc, NULL, NULL &apos;||gUserAlias||&apos;
    FROM &apos;||CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;nperssoldlunasub&apos; ELSE &apos;nperssoldluna&apos; END||&apos; NPS
      INNER JOIN NPERS NP ON NP.CODPERS = NPS.CODPERS &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NPS.CODPERS AND &apos;||to_char(vALIni)||&apos; BETWEEN NP1.ALSTART AND NP1.ALSTOP
      --INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS, 0, Greatest(nps.luna+nps.an*12,&apos;||vALInitiala||&apos;)))
      INNER JOIN NCONT NCONT ON NCONT.CodCont = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;, pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(NPS.CODMONEDA, 0)
      LEFT JOIN TREZOR T ON T.CodTrezor = -1
      LEFT JOIN TREZOR1 T1 ON T1.CodTrezor = -1
      LEFT JOIN NSUBUNIT NSUB ON NSUB.CodSubunit = &apos;||CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;NPS.SUBUNITATEA&apos; ELSE &apos;1&apos; END||
    gSuplJoins||&apos;
    WHERE (NPS.AN*12+NPS.LUNA) = &apos;||to_char(vALIni-1)||
      CASE WHEN aHOLDING = 1 AND pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos;
      AND NPS.SUBUNITATEA = &apos;||pkg_globals.GETSUBUNITATE END||
      sCondCont||
      sCondMon;
  ELSIF pkg_globals.GETSUBUNITATE &gt; 1 THEN
    sSelect0 := &apos;
    SELECT
      NULL NAV_CodDoc, NULL NAV_CodDoc1, NULL NAV_TipDoc, to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DATADOC, null DOC, NULL NRDOC, NULL VALDOC, MON.SIMBOL MONEDA, NULL CURS,
      CASE WHEN NCONT.tipcont =  1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END DEBIT,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END CREDIT,
      CASE WHEN NCONT.tipcont =  1 AND PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN -1 ELSE 1 END * &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; SOLD,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
      NCONT.SIMBOL, 0 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
      &apos;&apos;Sold initial &apos;&apos; EXPLICATII, null, NSUB.Den_Subunit, NULL,
      NULL, T.NumeDoc, NULL, NULL &apos;||gUserAlias||&apos;
    FROM nperssoldlunasub NPS
      INNER JOIN NPERS NP ON NP.CODPERS = NPS.CODPERS &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NPS.CODPERS AND &apos;||to_char(vALIni)||&apos; BETWEEN NP1.ALSTART AND NP1.ALSTOP
      --INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS, 0, Greatest(nps.luna+nps.an*12,&apos;||vALInitiala||&apos;)))
      INNER JOIN NCONT NCONT ON NCONT.CodCont = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;, pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(NPS.CODMONEDA, 0)
      INNER JOIN NSUBUNIT NSUB ON NSUB.CodSubunit = nps.subunitatea
      LEFT JOIN TREZOR T ON T.CodTrezor = -1
      LEFT JOIN TREZOR1 T1 ON T1.CodTrezor = -1&apos;||
      gSuplJoins||&apos;
    WHERE (NPS.AN *12 + NPS.LUNA) = &apos;||to_char(vALIni-1)||
      sCondCont||
      sCondMon||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NPS&apos;);
  ELSE
    sSelect0 := &apos;
    SELECT
      NULL NAV_CodDoc, NULL NAV_CodDoc1, NULL NAV_TipDoc, to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) DATADOC, null DOC, NULL NRDOC, &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;nps.soldvaluta&apos; END||&apos; VALDOC, MON.SIMBOL MONEDA, CASE Coalesce(NPS.SOLDVALUTA, 0) WHEN 0 THEN 1 ELSE NPS.SOLDLEI/NPS.SOLDVALUTA END CURS,
      CASE WHEN NCONT.tipcont =  1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END DEBIT,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 THEN 0 ELSE &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; END CREDIT,
      CASE WHEN NCONT.tipcont =  1 AND PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN -1 ELSE 1 END * &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;nps.soldlei&apos; ELSE &apos;CASE WHEN Coalesce(NPS.CODMONEDA,0) = 0 THEN nps.soldlei ELSE nps.soldvaluta END&apos; END||&apos; SOLD,
      CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
      NCONT.SIMBOL, 0 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
      &apos;&apos;Sold initial &apos;&apos; EXPLICATII, null, NSUB.den_subunit, NULL,
      NULL, T.NumeDoc, NULL, NULL &apos;||gUserAlias||&apos;
    FROM nperssoldluna NPS
      INNER JOIN NPERS NP ON NP.CODPERS = NPS.CODPERS &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NPS.CODPERS AND &apos;||to_char(vALIni)||&apos; BETWEEN NP1.ALSTART AND NP1.ALSTOP
      --INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS, 0, Greatest(nps.luna+nps.an*12,&apos;||vALInitiala||&apos;)))
      INNER JOIN NCONT NCONT ON NCONT.CodCont = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, nps.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(nps.CODPERS,decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; -1 ,&apos;||vAnInitial||&apos;,pkg_list_base_balsintpers.getanu(nps.an,nps.luna)),decode(nps.luna + nps.an * 12,&apos;||vAnInitial||&apos;*12+&apos;||vLunaInitiala||&apos; - 1, &apos;||vLunaInitiala||&apos;, pkg_list_base_balsintpers.getlunau(nps.an,nps.luna))))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(NPS.CODMONEDA, 0)
      LEFT JOIN TREZOR T ON T.CodTrezor = -1
      LEFT JOIN TREZOR1 T1 ON T1.CodTrezor = -1
      LEFT JOIN NSUBUNIT NSUB ON NSUB.CodSubunit = 1&apos;||
      gSuplJoins||&apos;
    WHERE (NPS.AN *12 + NPS.LUNA) = &apos;||to_char(vALIni-1)||
      sCondCont||
      sCondMon;
  END IF;

  -- justificari decont
  sSelect1 := &apos;
  SELECT
    T.CODTREZOR NAV_CodDoc, T1.CODTREZOR1 NAV_CodDoc1, 33 NAV_TipDoc, T1.DATADOC, T1.DOC, T1.NRDOC, CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE Coalesce(o.valoare,t1.valdoc) END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; VALDOC, MON.SIMBOL MONEDA, T1.CURS,
    CASE WHEN T1.TIPTRANZ = 1 THEN Coalesce(o.valoare,t1.valdoc) ELSE 0 END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; DEBIT,
    CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE Coalesce(o.valoare,t1.valdoc) END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; CREDIT,
    CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE Coalesce(o.valoare,t1.valdoc) END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; * CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN CASE WHEN T1.TIPTRANZ = 1 THEN 1 ELSE -1 END ELSE CASE WHEN T1.TIPTRANZ = 0 THEN 1 ELSE -1 END END SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 1 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    &apos;&apos;Decont &apos;&apos;||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC EXPLICATII, &apos;||sCursRef||&apos; CURS_REF, NSUB.Den_Subunit, T1.Obs,
    &apos;&apos;Decont &apos;&apos;||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC Doc, T.NumeDoc, JR.Obs, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA) &apos;||gUserAlias||&apos;
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN NPERS NP ON NP.CODPERS = T.CODBANCA &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T.CODBANCA AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, T.ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, T.an, T.luna))
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(T.MONEDAPERS, 0)
    LEFT JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.TIPDOC = T.TIPDOC
    LEFT JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    LEFT JOIN NSUBUNIT NSUB ON T.SUBUNITATEA = NSUB.CodSubunit
    LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1&apos;||
    gSuplJoins||&apos;
  WHERE T.TIPDOC = 33 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
    AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;);

  --trenzactii casa - banca
  sSelect2_1 := &apos;
  SELECT
    T.CODTREZOR NAV_CodDoc, T1.CODTREZOR1 NAV_CodDoc1, G.TIPDOC NAV_TipDoc, T1.DATADOC, T1.DOC, T1.NRDOC, 
		CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; VALDOC, MON.SIMBOL MONEDA, T1.CURS,
    CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; DEBIT,
    CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; CREDIT,
    CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END&apos;
		||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; * CASE WHEN NCONT.tipcont = 1 AND PKG_LIST_SELFISAPERS.isAllTipCN &lt;&gt; 1 THEN CASE WHEN T1.TIPTRANZ = 0 THEN -1 ELSE 1 END ELSE CASE WHEN T1.TIPTRANZ = 1 THEN -1 ELSE 1 END END SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 2 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    CASE WHEN T1.TIPTRANZ = 0 THEN &apos;&apos;Plata &apos;&apos; ELSE &apos;&apos;Incasare &apos;&apos; END||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC EXPLICATII, &apos;||sCursRef||&apos; CURS_REF, NSUB.Den_Subunit, T1.Obs,
    CASE WHEN T1.TIPTRANZ = 0 THEN &apos;&apos;Plata &apos;&apos; ELSE &apos;&apos;Incasare &apos;&apos; END||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC Doc, T.NumeDoc, JR.OBS, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA) &apos;||gUserAlias||&apos;
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.SEMNIFICATIE IN (1100, 1101)
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    INNER JOIN NPERS NP ON NP.CODPERS = T1.CODPART &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T1.CODPART AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, T.an, T.luna))
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(G.MONEDA, 0)
    LEFT JOIN NSUBUNIT NSUB ON T.SUBUNITATEA = NSUB.CodSubunit
    LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1&apos;||
    gSuplJoins||&apos;
  WHERE T.TIPDOC &lt;&gt; 33 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
    AND T1.obiecttranz = 2
    AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;);

  sSelect2_2 := &apos;
  SELECT
    T.CODTREZOR NAV_CodDoc, T1.CODTREZOR1 NAV_CodDoc1, G.TIPDOC NAV_TipDoc, T1.DATADOC, T1.DOC, T1.NRDOC, CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END valdoc, MON.SIMBOL MONEDA, T1.CURS,
    CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; DEBIT,
    CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; CREDIT,
    CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END&apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos; * Coalesce(NULLIF(T1.Curs,0),1)&apos; END||&apos; * CASE WHEN NCONT.tipcont = 1 AND PKG_LIST_SELFISAPERS.isAllTipCN &lt;&gt; 1 THEN CASE WHEN T1.TIPTRANZ = 0 THEN -1 ELSE 1 END ELSE CASE WHEN T1.TIPTRANZ = 1 THEN -1 ELSE 1 END END SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 2 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    &apos;&apos;Decont &apos;&apos;||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC EXPLICATII, &apos;||sCursRef||&apos; CURS_REF, NSUB.Den_Subunit, T1.Obs,
    &apos;&apos;Decont &apos;&apos;||T1.DOC||&apos;&apos; &apos;&apos;||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC Doc, T.NumeDoc, JR.OBS, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA)  &apos;||gUserAlias||&apos;
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.SEMNIFICATIE IN (1100, 1101)
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    INNER JOIN NPERS NP ON NP.CODPERS = T1.CODPART &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T1.CODPART AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, T.an, T.luna))
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(G.MONEDA, 0)
    LEFT JOIN NSUBUNIT NSUB ON T.SUBUNITATEA = NSUB.CodSubunit
    LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1&apos;||
    gSuplJoins||&apos;
  WHERE T.TIPDOC = 33 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
    AND T1.obiecttranz = 2
    AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;);

  sSelect3_AS := &apos;
  SELECT
    NULL NAV_CodDoc, NULL NAV_CodDoc1, NULL NAV_TipDoc, DATADOC, DOC, NRDOC, VALDOC, MONEDA,
    (sum(debit)/CASE WHEN sum(debitv) = 0 THEN 1 ELSE sum(debitv) END + sum(credit)/CASE WHEN sum(creditv) = 0 THEN 1 ELSE sum(creditv) END)/ CASE WHEN SUM(debit) = 0 THEN 1 WHEN SUM(credit) = 0 THEN 1 ELSE 2 END CURS,
    &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;SUM(DEBIT)&apos;  ELSE &apos;SUM(DEBITV)&apos;  END||&apos; DEBIT,
    &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;SUM(CREDIT)&apos; ELSE &apos;SUM(CREDITV)&apos; END||&apos; CREDIT,
    CASE WHEN TIPCONT = 1 AND PKG_LIST_SELFISAPERS.isAllTipCN &lt;&gt; 1 THEN -1 ELSE 1 END * &apos;||CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 THEN &apos;sum(debit)-sum(credit)&apos; ELSE &apos;sum(debitv)-sum(creditv)&apos; END||&apos; SOLD,
    CASE WHEN tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    CONT, 3 ORDINE, ANGAJAT,
    &apos;&apos;Tranzactii din alte subunitati&apos;&apos; EXPLICATII, NULL curs_ref, &apos;&apos;Alte subunitati&apos;&apos; SUBUNITATEA, NULL,
    NULL, NULL, obsj, simbolc &apos;||gNullAlias||&apos;
  FROM (
    SELECT
      NCONT.tipcont, MON.SIMBOL MONEDA,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END DEBITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END*Coalesce(NULLIF(T1.Curs,0),1) DEBIT,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END CREDITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END*Coalesce(NULLIF(T1.Curs,0),1) CREDIT,
      NCONT.Simbol cont, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT, JR.OBS obsj, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA) SIMBOLC,
      T1.DATADOC, T1.DOC, T1.NRDOC, CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END valdoc
    FROM TREZOR T
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.SEMNIFICATIE IN (1100, 1101)
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN NPERS NP ON NP.CODPERS = T1.CODPART &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T1.CODPART AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
      INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS,T.an,T.luna))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(G.MONEDA, 0)
      LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1
    WHERE T.TIPDOC &lt;&gt; 33 AND T.SUBUNITATEA &lt;&gt; &apos;||pkg_globals.GETSUBUNITATE||&apos;
      AND T1.obiecttranz = 2 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
      AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
      sCondCont||
      sCondMon||&apos;
    UNION ALL
    SELECT
      NCONT.tipcont, MON.SIMBOL MONEDA,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END DEBITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END*Coalesce(NULLIF(T1.Curs,0),1) DEBIT,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END CREDITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END*Coalesce(NULLIF(T1.Curs,0),1) CREDIT,
      NCONT.Simbol CONT, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,JR.OBS obsj, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA) SIMBOLC,
      T1.DATADOC, T1.DOC, T1.NRDOC, CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END valdoc
    FROM TREZOR T
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.TIPDOC = T.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN NPERS NP ON NP.CODPERS = T.CODBANCA &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T.CODBANCA AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
      INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, T.ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS,T.an,T.luna))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(T.MONEDAPERS, 0)
      LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1
    WHERE T.TIPDOC = 33 AND T.SUBUNITATEA &lt;&gt; &apos;||pkg_globals.GETSUBUNITATE||&apos; AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
      AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
      sCondCont||
      sCondMon||&apos;
    UNION ALL
    SELECT
      NCONT.tipcont, MON.SIMBOL MONEDA,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END DEBITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN 0 WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END*Coalesce(NULLIF(T1.Curs,0),1) DEBIT,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END CREDITV,
      CASE WHEN T1.TIPTRANZ = 1 THEN o.valoare ELSE 0 END*Coalesce(NULLIF(T1.Curs,0),1) CREDIT,
      NCONT.Simbol CONT, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,JR.OBS obsj, PKG_LIST_BASE_FISAPERS.GETSIMBOLCOR(O.CODOBLIGPIF, T.CODBANCA) SIMBOLC,
      T1.DATADOC, T1.DOC, T1.NRDOC, CASE WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.DinCareTVA,0) ELSE o.valoare END valdoc
    FROM TREZOR T
      LEFT JOIN NSUBUNIT NSUB ON T.SUBUNITATEA = NSUB.CodSubunit
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      INNER JOIN GENERAL G ON G.CODDOC = T1.CODTREZOR1 AND G.SEMNIFICATIE IN (1100, 1101)
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN NPERS NP ON NP.CODPERS = T1.CODPART &apos;||sCondPers||&apos;
      INNER JOIN NPERS1 NP1 ON NP1.CODPERS=T1.CODPART AND (T.AN*12+T.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
      INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, O.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, T.an, T.luna))
      INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(G.MONEDA, 0)
      LEFT JOIN (select max(obs) obs, coddoc, tipdoc, indexlocal from jurnal group by coddoc, tipdoc, indexlocal) JR ON T.CODTREZOR = JR.CODDOC AND JR.TIPDOC = T.TIPDOC AND JR.INDEXLOCAL = T1.CodTrezor1
    WHERE T.TIPDOC = 33 AND T.SUBUNITATEA &lt;&gt; &apos;||pkg_globals.GETSUBUNITATE||&apos; AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1
      AND T1.obiecttranz = 2
      AND (t.an*12+t.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
      sCondCont||
      sCondMon||&apos;
  ) GROUP BY ANGAJAT, CONT, MONEDA, TIPCONT, OBSJ, SIMBOLC, DATADOC, DOC, NRDOC, VALDOC&apos;;

  -- note contabile - debit
  sSelect4_1 := &apos;
  SELECT
    N.CodNC NAV_CodDoc, NULL NAV_CodDoc1, 35 NAV_TipDoc, N.DATADOC, &apos;&apos;NC&apos;&apos; DOC, N.NRDOC, N1.VALOARE, MON.SIMBOL MONEDA, N.CURS,
    N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN Coalesce(N.Curs,1) ELSE 1 END Debit,
    0 Credit,
    CASE
      WHEN PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN 1
      WHEN NCONT.tipcont = 1 THEN -1
      ELSE 1
    END * N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN Coalesce(N.Curs,1) ELSE 1 end Sold,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 4 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    N.NRDOC||&apos;&apos;/&apos;&apos;||N.DATADOC EXPLICATII, &apos;||sCursRefNC||&apos; CURS_REF, NSUB.Den_Subunit, N1.Obs,
    N.NRDOC||&apos;&apos;/&apos;&apos;||N.DATADOC  Doc,  NULL, NULL, case when Coalesce(n1.contc,0) = 0 then CC1.SIMBOL else CC.SIMBOL end &apos;||gUserAlias||&apos;
  FROM NC N
    INNER JOIN NMONEDE MON ON MON.CodMoneda = Coalesce(N.Moneda,0)
    INNER JOIN NSUBUNIT NSUB ON N.SUBUNITATEA = NSUB.CodSubunit
    INNER JOIN NC1 N1 ON N1.CodNC = N.CodNC
    INNER JOIN NPERS NP ON NP.CODPERS = N1.AGENT &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=N1.AGENT AND (N.An*12+N.Luna) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.ICONTD, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, N.an, N.luna))
    LEFT JOIN NCONT CC ON CC.CODCONT = N1.CONTC
    LEFT JOIN NCONT CC1 ON CC1.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.ICONTC, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, N.an, N.luna))
    LEFT JOIN TREZOR T ON T.CODTREZOR = 0
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR = 0&apos;||
    gSuplJoins||&apos;
  WHERE Coalesce(N1.AGENT, 0) &lt;&gt; 0 AND Coalesce(N1.ICONTD, 0) &lt;&gt; 0 AND Coalesce(N1.PERSD, 0) &lt;&gt; 0
    AND (N.An*12+N.Luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondMon||
    sCondCont||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;);

  -- note contabile - credit
  sSelect4_2 := &apos;
  SELECT
    N.CodNC NAV_CodDoc, NULL NAV_CodDoc1, 35 NAV_TipDoc, N.DATADOC, &apos;&apos;NC&apos;&apos; DOC, N.NRDOC, N1.VALOARE, MON.SIMBOL MONEDA, N.CURS,
    0 Debit,
    N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN Coalesce(N.Curs,1) ELSE 1 END Credit,
    CASE
      WHEN PKG_LIST_SELFISAPERS.isAllTipCN = 1 then -1
      WHEN NCONT.tipcont = 1 THEN 1
      ELSE -1
    END * N1.Valoare * CASE PKG_LIST_SELFISAPERS.Lei WHEN 1 THEN Coalesce(N.Curs,1) ELSE 1 end Sold,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 4 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    N.NRDOC||&apos;&apos;/&apos;&apos;||N.DATADOC EXPLICATII, &apos;||sCursRefNC||&apos; CURS_REF, NSUB.Den_Subunit, N1.Obs,
    N.NRDOC||&apos;&apos;/&apos;&apos;||N.DATADOC  Doc,  NULL, NULL, case when Coalesce(n1.contd,0) = 0 then CC1.SIMBOL else CC.SIMBOL end&apos;||gUserAlias||&apos;
  FROM NC N
    INNER JOIN NMONEDE MON ON MON.CodMoneda = Coalesce(N.Moneda,0)
    INNER JOIN NSUBUNIT NSUB ON N.SUBUNITATEA = NSUB.CodSubunit
    INNER JOIN NC1 N1 ON N1.CodNC = N.CodNC
    INNER JOIN NPERS NP ON NP.CODPERS = N1.AGENT &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=N1.AGENT AND (N.An*12+N.Luna) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.ICONTC, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, N.an, N.luna))
    LEFT  JOIN NCONT CC ON CC.CODCONT = N1.CONTD
    LEFT  JOIN NCONT CC1 ON CC1.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, N1.ICONTD, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, N.an, N.luna))
    LEFT JOIN TREZOR T ON T.CODTREZOR = 0
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR = 0&apos;||
    gSuplJoins||&apos;
  WHERE Coalesce(N1.AGENT, 0) &lt;&gt; 0 AND Coalesce(N1.ICONTC, 0) &lt;&gt; 0 AND Coalesce(N1.PERSC, 0) &lt;&gt; 0
    AND (N.An*12+N.Luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondMon||
    sCondCont||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;);

  sDebit  := &apos;CV.SOLDVALUTA_OUT / CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND CV.moneda_out &lt;&gt; 0 THEN CV.CURSCONVERSIE ELSE 1 END&apos;;
  sCredit := &apos;CV.SOLDVALUTA_IN * CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND mon.codmoneda &lt;&gt; 0 THEN CV.CURSCONVERSIE ELSE 1 END&apos;;
  if PKG_LIST_SELFISAPERS.Lei = 1 then
    sDebit  := &apos;CASE WHEN CV.MONEDA_IN &gt; 0 AND CV.MONEDA_OUT &gt; 0 THEN CV.SOLDLEI ELSE CV.SOLDVALUTA_OUT / CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND CV.moneda_out &lt;&gt; 0 THEN CV.CURSCONVERSIE ELSE 1 END END&apos;;
    sCredit := &apos;CASE WHEN CV.MONEDA_IN &gt; 0 AND CV.MONEDA_OUT &gt; 0 THEN CV.SOLDLEI ELSE CV.SOLDVALUTA_IN * CASE WHEN PKG_LIST_SELFISAPERS.Lei = 1 AND mon.codmoneda &lt;&gt; 0 THEN CV.CURSCONVERSIE ELSE 1 END END&apos;;
  end if;

  -- conversii valutare de personal in
  sSelect4_3 := &apos;
  SELECT
    null NAV_CodDoc, NULL NAV_CodDoc1, null NAV_TipDoc, CV.DATADOC, &apos;&apos;CONV&apos;&apos; DOC, null NRDOC, CV.SOLDVALUTA_IN, MON.SIMBOL MONEDA, CV.CURSCONVERSIE,
    0 DEBIT,
    &apos;||sCredit||&apos; CREDIT,
    - &apos;||sCredit||&apos; SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 4 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    MON.SIMBOL||&apos;&apos;--&gt;&apos;&apos;||MON_OUT.SIMBOL EXPLICATII, &apos;||sCursRefConv||&apos; CURS_REF, NSUB.Den_Subunit, CV.OBS,
    MON.SIMBOL||&apos;&apos;--&gt;&apos;&apos;||MON_OUT.SIMBOL Doc, NULL, NULL, NULL &apos;||gUserAlias||&apos;
  FROM CONVERTCURSPERS CV
    INNER JOIN NSUBUNIT NSUB ON CV.SUBUNITATEA = NSUB.CodSubunit
    INNER JOIN NPERS NP ON NP.CODPERS = CV.CODPERS &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NP.CODPERS AND (CV.AN*12+CV.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, CV.ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, CV.an, CV.luna))
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(CV.MONEDA_IN, 0)
    INNER JOIN NMONEDE MON_OUT ON MON_OUT.CODMONEDA = Coalesce(CV.MONEDA_OUT, 0)
    LEFT JOIN TREZOR T ON T.CODTREZOR = 0
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR = 0&apos;||
    gSuplJoins||&apos;
  WHERE (CV.an*12+CV.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CV&apos;);

  -- conversii valutare de personal out
  sSelect4_4 := &apos;
  SELECT
    null NAV_CodDoc, NULL NAV_CodDoc1, null NAV_TipDoc, CV.DATADOC, &apos;&apos;CONV&apos;&apos; DOC, null NRDOC, CV.SOLDVALUTA_IN, 
		MON.SIMBOL MONEDA, CV.CURSCONVERSIE,
    &apos;||sDebit||&apos; DEBIT,
    0 CREDIT,
    &apos;||sDebit||&apos; SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.simbol, 4 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    MON.SIMBOL||&apos;&apos;&lt;--&apos;&apos;||MON_OUT.SIMBOL EXPLICATII, &apos;||sCursRefConv||&apos; CURS_REF, NSUB.Den_Subunit, CV.OBS,
    MON.SIMBOL||&apos;&apos;&lt;--&apos;&apos;||MON_OUT.SIMBOL Doc, NULL, NULL, NULL &apos;||gUserAlias||&apos;
  FROM CONVERTCURSPERS CV
    INNER JOIN NSUBUNIT NSUB ON CV.SUBUNITATEA = NSUB.CodSubunit
    INNER JOIN NPERS NP ON NP.CODPERS = CV.CODPERS &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NP.CODPERS AND (CV.AN*12+CV.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, CV.ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(np1.CODPERS, CV.an, CV.luna))
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = Coalesce(CV.MONEDA_OUT, 0)
    INNER JOIN NMONEDE MON_OUT ON MON_OUT.CODMONEDA = Coalesce(CV.MONEDA_IN, 0)
    LEFT JOIN TREZOR T ON T.CODTREZOR = 0
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR = 0&apos;||
    gSuplJoins||&apos;
  WHERE (CV.an*12+CV.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CV&apos;);

  -- regularizari
  sSelect4_Reg := &apos;
  SELECT
    reg.codreg NAV_CodDoc, NULL NAV_CodDoc1, reg.tipreg NAV_TipDoc, reg.DATADOC, &apos;&apos;REG&apos;&apos; DOC, reg.NRDOC, reg1.SOLDDOCREG - reg1.solddocval, MON.SIMBOL MONEDA, reg.CURS,
    CASE
      WHEN NCONT.tipcont = 1      AND reg1.SOLDDOCREG - reg1.solddocval &lt;  0 THEN reg1.SOLDDOCVAL - reg1.SOLDDOCREG
      WHEN NCONT.tipcont in (0,2) AND reg1.SOLDDOCREG - reg1.solddocval &gt;= 0 THEN reg1.SOLDDOCREG - reg1.SOLDDOCVAL
      ELSE 0
    END DEBIT,
    CASE
      WHEN NCONT.tipcont = 1      AND reg1.SOLDDOCREG - reg1.solddocval &gt;= 0 THEN reg1.SOLDDOCREG - reg1.SOLDDOCVAL
      WHEN NCONT.tipcont in (0,2) AND reg1.SOLDDOCREG - reg1.solddocval &lt;  0 THEN reg1.SOLDDOCVAL - reg1.SOLDDOCREG
      ELSE 0
    END CREDIT,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN 1     ELSE -1    END * (reg1.SOLDDOCREG - reg1.solddocval) SOLD,
    CASE WHEN NCONT.tipcont &lt;&gt; 1 OR PKG_LIST_SELFISAPERS.isAllTipCN = 1 THEN &apos;&apos;D&apos;&apos; ELSE &apos;&apos;C&apos;&apos; END TIPSOLD,
    NCONT.SIMBOL, 4 ORDINE, NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME ANGAJAT,
    reg.obs EXPLICATII, &apos;||sCursRefReg||&apos; CURS_REF, S.Den_Subunit, REG.OBS,
    &apos;&apos;REG &apos;&apos;||reg.nrdoc, NULL, JR.obs, NULL  &apos;||gUserAlias||&apos;
  FROM REG
    INNER JOIN REGPERS1 REG1 ON REG1.CODREG = REG.CODREG &apos;||CASE WHEN pkg_globals.GETSUBUNITATE &gt; 1 THEN &apos; AND REG1.SUBUNITATEA = &apos;||pkg_globals.GETSUBUNITATE END||&apos;
    INNER JOIN NPERS NP ON NP.CODPERS = REG1.CODPERS &apos;||sCondPers||&apos;
    INNER JOIN NPERS1 NP1 ON NP1.CODPERS=NP.CODPERS AND (REG.AN*12+REG.LUNA) BETWEEN NP1.ALSTART AND NP1.ALSTOP
    INNER JOIN NCONT NCONT ON NCONT.CODCONT = REG1.CODCONT
    INNER JOIN NMONEDE MON ON MON.CODMONEDA = REG.CODMONEDA
    INNER JOIN NSUBUNIT S ON REG1.SUBUNITATEA = S.CODSUBUNIT
    LEFT  JOIN TREZOR T ON T.CodTrezor = 0
    LEFT  JOIN TREZOR1 T1 ON T1.CodTrezor = T.CodTrezor
    LEFT JOIN (select max(obs) obs, coddoc, tipdoc from jurnal group by coddoc, tipdoc) JR ON REG.CODREG = JR.CODDOC AND JR.TIPDOC = REG.TIPREG&apos;||
    gSuplJoins||&apos;
  WHERE (REG.an*12+REG.luna) BETWEEN &apos;||vALIni||&apos; AND &apos;||vALFin||
    sCondCont||
    sCondMon;

  --pkg_list_base_utils.UMPLE_TMP_NPERS1_LST;
  PRC_AL_CHECK(&apos;NPERS1&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect0, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2_1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2_2, aListID, aListVer);
  IF PKG_LIST_SELFISAPERS.isSubunit AND pkg_globals.GETSUBUNITATE &gt; 1 AND aHolding = 0 then
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3_as, aListID, aListVer);
  END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4_1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4_2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4_3, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4_4, aListID, aListVer);
  IF pkg_list_selfisapers.Lei = 1 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4_reg, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE processList(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  UmpleTMP(tmpname, aLISTID, aLISTVER, 0);
END;

PROCEDURE processListHolding(tmpname IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  UmpleTMP(tmpname, aLISTID, aLISTVER, 1);
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_FISAPERS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISASAH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6458CF4E37AA44C3B350093C99C5A4F99EBABA49</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISASAH IS

  xCodCont  NUMBER(20);
  gAnLuna   NUMBER(5);
  gTip      NUMBER(1) := 0; -- 0 lunar; 1 anual

PROCEDURE SetParams  (pTip IN NUMBER) -- pentru joburi
IS
BEGIN
  gTip := pTip;
  IF gTip = 0
  THEN gAnLuna := pkg_globals.AnLunaLucru;
  ELSE gAnLuna := pkg_globals.GetAnLucru;
  END IF;
END;

PROCEDURE BagaDinamicCols  IS
  sInsertTMP  VARCHAR2(10000);
  sFiltru  varchar2(10000);
BEGIN
  sFiltru := &apos;
      AND &apos;;
  IF gTip = 0
  THEN sFiltru := sFiltru||&apos; j.an * 12 + j.luna = &apos;||gAnLuna;
  ELSE sFiltru := sFiltru||&apos; j.an = &apos;||gAnLuna;
  END IF;
  sFiltru := sFiltru || &apos;
      AND (J.SUBUNITATEA = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;,&apos;SUBUNITATEA&apos;,&apos;OR&apos;)||&apos;)&apos;;

  DELETE FROM tmp_dinamic_cols;

  sInsertTMP := &apos;
  INSERT INTO tmp_dinamic_cols(fieldname, display, indexlocal, cod)
  SELECT &apos;&apos;D&apos;&apos;||ROWNUM, NAME||SIMBOL, ROWNUM, codcont
  FROM (
    SELECT 1 ord, &apos;&apos;D_&apos;&apos; name, n.simbol, n.codcont
    FROM tmp_manevra_liste tmp
      INNER JOIN jurnal j on tmp.filtru = j.contd
      INNER JOIN ncont n on n.CODCONT = j.contc
    WHERE tmp.valoare = &apos;&apos;D&apos;&apos; &apos;||sFiltru||&apos;
    UNION
    SELECT 2 ord, &apos;&apos;C_&apos;&apos; name, n.simbol, n.codcont
    FROM tmp_manevra_liste tmp
      INNER JOIN jurnal j on tmp.filtru = j.contc
      INNER JOIN ncont n on n.codcont = j.contd
    WHERE tmp.valoare = &apos;&apos;C&apos;&apos; &apos;||sFiltru||&apos;
  )
  ORDER BY ord, simbol &apos;;

  EXECUTE IMMEDIATE sInsertTMP;
  COMMIT;

END;

FUNCTION getConturi(pTip IN NUMBER DEFAULT 0, pAnLuna IN NUMBER DEFAULT 0) return crsConturi IS
  cResult     crsConturi;
  sSqlConturi VARCHAR2(10000);
  sFiltru     VARCHAR2(10000);
BEGIN
  gTip    := pTip;
  gAnLuna := pAnLuna;
  sFiltru := &apos;
    WHERE &apos;;
  IF gTip = 0
  THEN sFiltru := sFiltru||&apos; j.an * 12 + j.luna = &apos;||gAnLuna;
  ELSE sFiltru := sFiltru||&apos; j.an = &apos;||gAnLuna;
  END IF;
  sFiltru := sFiltru || &apos;
      AND (J.SUBUNITATEA = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;,&apos;SUBUNITATEA&apos;,&apos;OR&apos;)||&apos;)&apos;;

  sSqlConturi := &apos;
  SELECT n.codcont, n.simbol, n.den_cont , decode(n.tipcont,0,&apos;&apos;Activ&apos;&apos;,1,&apos;&apos;Pasiv&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;) tip, 0 debit,0 credit
  FROM (
    SELECT DISTINCT j.contc cont
    FROM jurnal j&apos;||
    sFiltru||&apos;
    UNION
    SELECT DISTINCT j.contd cont
    FROM jurnal j&apos;||
    sFiltru||&apos;
  ) j INNER JOIN ncont n on j.cont = n.codcont
  order by n.simbol&apos;;

  OPEN cResult FOR sSqlConturi;
  RETURN cResult;
end;

FUNCTION  getCodCont RETURN NUMBER IS
BEGIN
  RETURN xCodCont;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) is
  sInsert  varchar2(30000);
  sSelectD varchar2(30000);
  sSelectC varchar2(30000);
  sFiltru  varchar2(10000);
BEGIN
  sFiltru := &apos;
      AND &apos;;
  IF gTip = 0
  THEN sFiltru := sFiltru||&apos; j.an * 12 + j.luna = &apos;||gAnLuna;
  ELSE sFiltru := sFiltru||&apos; j.an = &apos;||gAnLuna;
  END IF;
  sFiltru := sFiltru || &apos;
      AND (J.SUBUNITATEA = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;,&apos;SUBUNITATEA&apos;,&apos;OR&apos;)||&apos;)&apos;;

  sSelectD := &apos;
  SELECT
    j.coddoc,j.tipdoc,cc.simbol,nc.simbol,j.document,j.datadoc,nsub.den_subunit,j.obs,j.an,
    to_char(j.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(j.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(j.Luna) luna,
    j.valoare,0,j.valoare
  FROM jurnal j
    INNER JOIN ncont nc on nc.codcont = j.contc
    INNER JOIN ncont cc on cc.codcont = j.contd
    INNER JOIN nsubunit nsub on nsub.codsubunit = j.subunitatea
  WHERE j.contc = PKG_LIST_BASE_FISASAH.GetCodCont
    AND j.an * 12 + j.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND j.contd IN (SELECT filtru FROM tmp_manevra_liste WHERE valoare = &apos;&apos;D&apos;&apos;)&apos;||
    sFiltru;

  sSelectC := &apos;
  SELECT
    j.coddoc,j.tipdoc,cc.simbol,nc.simbol,j.document,j.datadoc,nsub.den_subunit,j.obs,j.an,
    to_char(j.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(j.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(j.Luna) luna,
    0,j.valoare,j.valoare
  FROM jurnal j
    INNER JOIN ncont nc on nc.codcont = j.contd
    INNER JOIN ncont cc on cc.codcont = j.contc
    INNER JOIN nsubunit nsub on nsub.codsubunit = j.subunitatea
  WHERE j.contd = PKG_LIST_BASE_FISASAH.GetCodCont
    AND j.an * 12 + j.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND j.contc IN (SELECT filtru FROM tmp_manevra_liste WHERE valoare = &apos;&apos;C&apos;&apos;)&apos;||
    sFiltru;

  --BagaDinamicCols;
  FOR v_rec IN ( select fieldname, display, cod from tmp_dinamic_cols ) LOOP
    sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc,NAV_TipDoc,SIMBOL,SIMBASOC,DOCUMENT,DATADOC,SUBUNITATEA,OBS,AN,LUNA,RULDEBIT,RULCREDIT,&apos;||v_rec.fieldname||&apos;)&apos;;
    xCodCont := v_rec.Cod;
    IF SubStr(v_rec.display,1,1) = &apos;D&apos;
    THEN
      LIST_EXECUTE_IMMEDIATE(sInsert||sSelectd, aListID, aListVer);
    ELSE
      LIST_EXECUTE_IMMEDIATE(sInsert||sSelectc, aListID, aListVer);
    END IF;
  END LOOP;

  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_FISASAH;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FISAURMINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D21A9ACBD7C7087CDC270FF2EADE1A11B3B8A93</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_FISAURMINC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(2000);
  sSelect     VARCHAR2(30000);
  sSelect_Ini VARCHAR2(30000);
  An          NUMBER(4);
  Luna        NUMBER(2);
  sAux        VARCHAR2(30000);
  sDataS      VARCHAR2(10) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
  sDataF      VARCHAR2(10) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
  sSubAvans   VARCHAR2(2000);
BEGIN
  gSuplCols := &apos;iesiri ies, trezor1 t1, trezor t, npart p, nclasep clsp, nmonede mon, nsubunit SubInc, nsubunit SubDoc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_setluni.GetLunaInitiala(an, luna);

  sSubAvans := &apos;null as subavans &apos;;
  if pkg_list_alegperioada.optiunea1 then
    sSubAvans := &apos;(select xi.SUBUNITATEA
                   from trezor1 xt1
                        INNER JOIN trezor xt ON xt1.codtrezor = xt.codtrezor
                        INNER JOIN general xg ON xt1.codtrezor1 = xg.coddoc and xg.tipdoc = xt.tipdoc
                        INNER JOIN obligpif xo ON xo.codgeneral = xg.codgeneral
                        INNER JOIN stingere xs ON xs.codstingatorpif = xo.codobligpif
                        INNER JOIN obligpif xos ON xos.codobligpif = xs.codstinspif
                        inner join general xgs on xgs.codgeneral = xos.codgeneral
                        inner join iesiri xi on xi.codies = xgs.coddoc and xi.tipdoc = xgs.tipdoc
                   WHERE xt1.CODtrezor1 = t1.CODtrezor1 AND ROWNUM = 1
                  ) subavans &apos;;
  end if;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,
    Partener, PrefDoc, NrDoc, DataDoc,
    PrefInc, NrInc, DataInc, ValInc, ValIncBanca, ValIncCasa, ValIncBO, ValAvans, ValCompens &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH Incasari as (
    SELECT
      &apos;||sSubAvans||&apos;,o.semnificatie semnif,
      t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc pref, t1.nrdoc nr, t1.datadoc data, o.codpart, t.Subunitatea,
      Decode(os.semnificatie, 1303, os.codobligasociat, os.codobligpif) codstinspif, NVL(g.moneda,0) Moneda, Decode(g.curs, NULL, 1, 0, 1, g.curs) curs,
      case when g.semnificatie = 410 then o.valoare else Nvl(s.valoare, t1.valdoc) end valinc,
      CASE WHEN t.tipdoc = 30 AND g.semnificatie IN (400) THEN o.valoare ELSE 0 END ValIncBanca,
      CASE WHEN t.tipdoc = 29 AND g.semnificatie IN (400) THEN o.valoare ELSE 0 END ValIncCasa,
      CASE WHEN t.tipdoc = 31 AND g.semnificatie IN (400) THEN o.valoare ELSE 0 END ValIncBO,
      CASE WHEN g.semnificatie IN (410) THEN o.valoare ELSE 0 END  ValAvans,
      0 ValCompens,
      Decode(os.semnificatie, 1303, 1, 0) stingLit
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      LEFT JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE T.TIPDOC IN (29, 30, 31)
      AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND g.semnificatie IN (400, 410) &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END ||&apos;
    UNION ALL
    SELECT
      0 subavans, 0 semnif,
      g.CodDoc, NULL CodDoc1, g.TipDoc, &apos;&apos;PV&apos;&apos; pref, c.nrdoc nr, c.datadoc data, o.codpart, c.Subunitatea,
      Decode(os.semnificatie, 1303, os.codobligasociat, os.codobligpif) codstinspif, NVL(g.moneda,0) Moneda, Decode(g.curs, NULL, 1, 0, 1, g.curs) curs,
      s.valoare*DECODE(g.semnificatie,1350,1,1351,1,-1) valinc,
      0 ValIncBanca,
      0 ValIncCasa,
      0 ValIncBO,
      0 ValAvans,
      s.valoare*DECODE(g.semnificatie,1350,1,1351,1,-1) ValCompens,
      Decode(os.semnificatie, 1303, 1, 0) stingLit
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens AND G.TipDoc = 28
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND o.icont IN (3,5,7,10,11,18) &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      0 subavans, 0 semnif,
      e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, &apos;&apos;BON&apos;&apos; pref, e.nrbon nr, e.databon data, i.partener, i.subunitatea,
      o.codobligpif codstinspif, NVL(g.moneda,0) Moneda, Decode(g.curs, NULL, 1, 0, 1, g.curs) curs,
      es.valoare valstins,
      0 ValIncBanca,
      0 ValIncCasa,
      0 ValIncBO,
      0 ValAvans,
      0 ValCompens,
      0 stingLit
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      0 subavans, 0 semnif,
      e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, &apos;&apos;BON&apos;&apos; pref, e.nrbon nr, e.databon data, i.partener, i.subunitatea,
      --o.codobligpif codstinspif, NVL(g.moneda,0) Moneda, Decode(g.curs, NULL, 1, 0, 1, g.curs) curs,
      (SELECT Min(o.codobligpif) FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral WHERE g.coddoc = i.codies AND g.tipdoc = i.tipdoc) codstinspif, 0 Moneda, 1 curs,
      e.valoare valstins,
      0 ValIncBanca,
      0 ValIncCasa,
      0 ValIncBO,
      0 ValAvans,
      0 ValCompens,
      0 stingLit
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies
      --INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      --INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
  )
  SELECT
    DECODE(tmps.codsubunit, NULL,NULL,inc.coddoc) NAV_CodDoc, DECODE(tmps.codsubunit, NULL,NULL,inc.coddoc1) NAV_CodDoc1, DECODE(tmps.codsubunit, NULL,NULL,inc.tipdoc) NAV_TipDoc,
    P.Den_Part, Decode(inc.stingLit,1,&apos;&apos;Litigiu &apos;&apos;)||Nvl(t1.doc, ies.prefixdoc), Nvl(t1.NrDoc, ies.NrDoc), Nvl(t1.DataDoc, ies.DataDoc),
    inc.Pref, inc.Nr, inc.Data, inc.ValInc, inc.ValIncBanca, inc.ValIncCasa, inc.ValIncBO, inc.ValAvans, inc.ValCompens &apos;||gUserAlias||&apos;
  FROM Incasari inc
    LEFT JOIN obligpif os ON os.codobligpif = inc.codstinspif
    LEFT JOIN general gs ON gs.codgeneral = os.codgeneral
    LEFT JOIN iesiri ies On ies.codies = gs.coddoc AND ies.tipdoc = gs.tipdoc
    LEFT JOIN trezor1 t1 On t1.codtrezor1 = gs.coddoc AND gs.tipdoc = 31
    LEFT JOIN trezor t On t.codtrezor = t1.codtrezor
    LEFT JOIN npart p on p.codpart = inc.codpart
    LEFT JOIN nclasep clsp on clsp.codclasep = NVL(p.codclasa, 0)
    LEFT JOIN nmonede mon ON mon.codmoneda = inc.moneda
    LEFT JOIN nsubunit SubInc ON SubInc.codsubunit = inc.subunitatea
    LEFT JOIN tmp_subunitdedicate tmps ON tmps.codsubunit = inc.subunitatea
    LEFT JOIN nsubunit SubDoc ON SubDoc.codsubunit = case when inc.semnif = 410 then inc.subavans else Nvl(t.subunitatea,ies.subunitatea) end &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_fisaurminc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_FUZIONARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24F50ED9E0974F15AB53EF271BE1E209F4B97ADE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_fuzionare IS

TipFuz NUMBER(2);

PROCEDURE SetParams(aTip IN NUMBER) IS
BEGIN
	TipFuz := aTip;
END;

PROCEDURE SetJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(4096);
BEGIN
	IF TipFuz = 0 THEN -- PARTENERI
    sInsert :=
    &apos;INSERT INTO &apos; || tmpName || &apos; (PartInit, CodExtInit, CodFiscInit, LocalitInit, PartFin, CodExtFin, CodFiscFin, LocalitFin)
    SELECT INIT.Den_Part, FUZ.CodExtInit, FUZ.CodFiscInit, FUZ.LocalitInit, FIN.Den_Part, FUZ.CodExtFin, FUZ.CodFiscFin, FUZ.LocalitFin
    FROM FUZPART FUZ
      INNER JOIN NPART INIT ON INIT.CodPart = FUZ.CodPartInit
      INNER JOIN NPART FIN ON FIN.CodPart = FUZ.CodPartFin&apos;;
	ELSIF TipFuz = 1 THEN -- LOCATII
		sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (Part, LocInit, LocFin)
		SELECT NP.Den_Part, NAI.Obs, NAF.Obs
    FROM FUZPART FUZ
			INNER JOIN NPART NP ON NP.CodPart = FUZ.CodPartInit
			LEFT OUTER JOIN NAGENDA NAI ON NAI.CodAgenda = FUZ.CodLocInit
			LEFT OUTER JOIN NAGENDA NAF ON NAF.CodAgenda = FUZ.CodLocFin&apos;;
	ELSIF TipFuz = 2 THEN -- LOCALITATI
		sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (LocalitInit, LocalitFin, SimbAutoInit, SimbAutoFin, DenSupInit, DenSupFin)
		SELECT NLI.Den_Localit, NLF.Den_Localit, FUZ.SimbAutoInit, FUZ.SimbAutoFin, FUZ.DenSupInit, FUZ.DenSupFin
    FROM FUZLOCALIT FUZ
      INNER JOIN NLOCALIT NLI ON NLI.CodLocalit = FUZ.CodLocalitInit
      INNER JOIN NLOCALIT NLF ON NLF.CodLocalit = FUZ.CodLocalitFin&apos;;
	ELSIF TipFuz = 3 THEN -- GESTIUNI
		sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (GestInit, SubunitInit, GestFin, SubunitFin)
    SELECT NGI.Den_Gest, FUZ.SubunitInit, NGF.Den_Gest, FUZ.SubunitFin
    FROM FUZGEST FUZ
      INNER JOIN NGEST NGI ON NGI.CodGest = FUZ.CodGestInit
      INNER JOIN NGEST NGF ON NGF.CodGest = FUZ.CodGestFin&apos;;
	ELSIF TipFuz = 4 THEN -- ARTICOLE
		sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (ArtInit, ArtFin, CodExternInit, CodExternFin, ProdInit, ProdFin)
    SELECT NAI.Den_Articol, NAF.Den_Articol, FUZ.CodExternInit, FUZ.CodExternFin, FUZ.ProdInit, FUZ.ProdFin
    FROM FUZART FUZ
      INNER JOIN NART NAI ON NAI.CodArticol = FUZ.CodArtInit
      INNER JOIN NART NAF ON NAF.CodArticol = FUZ.CodArtFin&apos;;
  ELSIF TipFuz = 5 THEN -- PERSONAL
    sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (PersInit, SubunitInit, PersFin, SubunitFin)
    SELECT NPI.Prenume || &apos;&apos; &apos;&apos; || NPI.Nume, FUZ.SubunitInit, NPF.Prenume || &apos;&apos; &apos;&apos; || NPF.Nume, FUZ.SubunitFin
    FROM FUZPERS FUZ
      INNER JOIN NPERS NPI ON NPI.CodPers = FUZ.CodPersInit
      INNER JOIN NPERS NPF ON NPF.CodPers = FUZ.CodPersFin&apos;;
  ELSIF TipFuz = 6 THEN -- AUTO
		sInsert := 
    &apos;INSERT INTO &apos; || tmpName || &apos; (AutoInit, AutoFin)
    SELECT NAI.NrInreg, NAF.NrInreg
    FROM FUZAUTO FUZ
      INNER JOIN NPARCAUT NAI ON NAI.CodNParcAut = FUZ.CodAutoInit
      INNER JOIN NPARCAUT NAF ON NAF.CodNParcAut = FUZ.CodAutoFin&apos;;    
	END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_FUZIONARE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_GANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2399FD0B0C0E2144172F56BA94148D90901CEF25</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_gant is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sDataRef VARCHAR2(10);
BEGIN
  gSuplCols := &apos;COMANDA C, COMANDA1 C1&apos;;
  pkg_list_struct.StartSuplCols;
  
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;comandi&apos;,       &apos;CI&apos;,    &apos;CI.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;comandi1&apos;,      &apos;CI1&apos;,   &apos;CI1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sDataRef := to_char(PKG_LIST_ALEGPERIOADA.getDataRef, &apos;dd.mm.yyyy&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
     NAV_CODDOC,
     NAV_TIPDOC,
     DEN_GEST,                                                                         
     LOCMUNCA,                                                                            
     NRSCHIMBURI,
     ORESCHIMB, 
     TIPLM,       
     OREZI,      
     LANSAT, 
     DEN_PART,                                                                         
     DOCUMENTCLI,
     DOCUMENT,
     DATADOC,
     DENOBIECT,
     RETETA,
     ACCEPTAT,
     RESTACCEPTAT,
     TERMEN,
     UM,
     EXECUTAT,
     ZILE,
     ZILEREST,
     ORE,
     OREREST,
     REALIZAT,
     REBUTAT,
     REFACUT,
     MATERIALE,
     DATASTART,
     PRIORITATE &apos;||gUserFields||&apos;)&apos;;

   sSelect := 
   &apos;select
      A.CODCOMANDA NAV_CODDOC,
      A.TIPDOC NAV_TIPDOC, 
      A.DEN_GEST,
      A.LOCMUNCA,
      A.NRSCHIMBURI,
      A.ORESCHIMB,
      A.TIPLM,
      A.OREZI,
      A.LANSAT,
      A.DEN_PArt,
      A.DOCUMENTCli,
      A.DOCUMENT,
      A.DATADOC,
      A.DENOBIECT,
      A.RETETA,
      A.CANTACCEPTAT,
      A.RESTACCEPTAT,
      A.TERMEN,
      A.UM,
      A.Executat,
      A.ZILE,
      A.ZILEREST,
      A.ORE,
      A.OREREST,
      A.REALIZAT,
      A.REBUTAT,
      A.REFACUT,
      MAT.MATERIALE,
      A.DATASTART,
      A.PRIORITATE &apos;||gUserAlias||&apos;
    from (  
    Select 
      CODCOMANDA1  ,
      CODCOMANDA   ,
      TIPDOC       ,
      CODGEST      ,
      CODLOC       ,
      CODRETETA    ,
      DEN_GEST     ,
      LOCMUNCA     ,
      IDXGEST      ,
      NRSCHIMBURI  ,
      ORESCHIMB    ,
      TIPLM        ,
      OREZI        ,
      0 Nevid      ,
      0 TU         ,
      0 CODOPERATIE ,
      &apos;&apos;?&apos;&apos; OPERATIE,
      IDX        ,
      0 Codcmdprodman,
      LANSAT       ,
      DEN_PArt     ,
      DOCUMENTCli  ,
      DOCUMENT     ,
      DATADOC      ,
      DENOBIECT    ,
      RETETA       ,
      CANTACCEPTAT ,
      RESTACCEPTAT ,
      TERMEN       ,
      UM           ,
      Executat     ,
      DATASTART,
      PRIORITATE,
      SUM(ZILE         )  ZILE         ,
      SUM(ZILEREST     )  ZILEREST     ,
      SUM(ORE          )  ORE          ,
      SUM(OREREST      )  OREREST      ,
      SUM(REALIZAT     )  REALIZAT     ,
      SUM(REBUTAT      )  REBUTAT      ,
      SUM(REFACUT      )  REFACUT       
    from ( 
          SELECT 
            x.codcomanda1, 
            x.codcomanda,
            X.TIPDOC, 
            x.CodGest, 
            x.CodLoc, 
            x.CodReteta, 
            x.Den_Gest, 
            x.LocMunca, 
            X.codcmdprodman,
            Round(x.tu / DECODE(NVL(x.OreZi, 0), 0, 8, x.OreZi) / 60 * x.cantacceptat / x.cantprod, 5) zile,
            Round(x.tu / DECODE(NVL(x.OreZi, 0), 0, 8, x.OreZi) / 60 * (x.CantAcceptat - nvl(x.realizat,0) + nvl(x.rebutat,0)) / x.cantprod, 5) ZileRest,
            Round(x.tu / 60 * (x.cantacceptat / x.cantprod), 5) Ore,
            Round(x.tu / 60 * (x.CantAcceptat - nvl(x.realizat,0) + nvl(x.rebutat,0)) / x.cantprod, 5) OreRest,
            x.CodOperatie, 
            nvl(x.realizat,0) realizat, 
            nvl(x.realizat,0) Executat, 
            nvl(x.rebutat, 0) rebutat, 
            nvl(x.Refacut, 0) Refacut, 
            x.idxgest, 
            Nvl(x.nrschimburi,1) nrschimburi, 
            Nvl(x.oreschimb,8) oreschimb, 
            x.operatie, 
            x.tiplm, 
            x.tu, 
            x.orezi,
            X.Idx, 
            x.Lansat, 
            x.DocumentCli, 
            x.Den_Part, 
            x.Document, 
            X.DataDoc, 
            x.DenObiect, 
            x.Reteta, 
            x.CantAcceptat, 
            x.RestAcceptat, 
            x.Termen, 
            x.UM, 
            x.CantAcceptat - nvl(x.realizat,0) + nvl(x.rebutat,0) rest,
            X.DATASTART,
            X.PRIORITATE 
          from (
                select V.*, C1.PRIORITATE, C.TIPDOC 
                from V_MANOPERAGANTT V
                     inner join (
                                 select 
                                   distinct codcomanda1 
                                 from  
                                   V_CmdIntActive 
                                 where 
                                   Termen &gt;= TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)
                                ) x on x.CodComanda1 = V.CodComanda1
                     INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = X.CODCOMANDA1
                     INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA            
               where NVL(V.CodLoc,0) &gt; 0 
               ) x
) 
Group by 
  DEN_GEST,
  LOCMUNCA,
  IDXGEST,
  NRSCHIMBURI,
  ORESCHIMB,
  TIPLM,
  OREZI,
  LANSAT,
  DEN_PArt,
  DOCUMENTCli,
  DOCUMENT,
  DATADOC,
  DENOBIECT,
  RETETA,
  CANTACCEPTAT,
  RESTACCEPTAT,
  TERMEN,
  UM,
  Executat,
  CODCOMANDA,
  TIPDOC,
  CODCOMANDA1,
  CODGEST,
  CODLOC,
  CODRETETA,
  IDX,
  DATASTART,
  PRIORITATE ) A
  LEFT JOIN COMANDA C ON A.CODCOMANDA = C.CODCOMANDA
  LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = A.CODCOMANDA1
  LEFT JOIN (SELECT STRING_AGG(&apos;&apos; &apos;&apos;||OBJ.DENUMIRE||&apos;&apos; - &apos;&apos;||MAT.CANT||&apos;&apos; &apos;&apos;) MATERIALE, MAT.CODCOMANDA1
             FROM COMANDA1 C1
                  INNER JOIN CMDPRODMAT MAT ON MAT.CODCOMANDA1 = C1.CODCOMANDA1
                  INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = MAT.CODOBIECT
             WHERE (C1.CONSUM = 1 AND MAT.TIP = 1) OR (C1.CONSUM = 2 AND MAT.TIP IN (0,1))
             GROUP BY MAT.CODCOMANDA1
             ) MAT ON C1.CODCOMANDA1 = MAT.CODCOMANDA1     
  &apos;||gSuplJoins;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;  

end pkg_list_base_gant; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_GEND39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAD1BF6EECBDCBE5640E1412E33B9D08A4E9AFBF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_GEND39416 IS

  vTip     INTEGER;
  vLuna    INTEGER;
  vAn      INTEGER;
  vSubunit INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
 
  vDataS       DATE;
  vDataF       DATE;
  
PROCEDURE SETPARAMS( pTip INTEGER, pLuna INTEGER, pAn INTEGER, pSubunit INTEGER,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 )IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vTip     := pTip;
  vLuna    := pLuna;
  vAn      := pAn;
  vSubunit := pSubunit;
  PKG_D39416.UmpleGEN( vTip, vLuna, vAn, vSubunit);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  gSuplCols := &apos;TMP_D39416_GEN T, CATEGARTTI CTI, INTRARI INTR, IESIRI IES, NPART P&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  PKG_D39416.ActualizGEN;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    NAV_CodDoc, NAV_TipDoc,
    Tip,
    Cui, DenP, RegScutire,
    CuiOK,
    PartAreRO,
    ANAFAreRO,
    ValidANAF,
    PartTVAInc,
    F, BI, TVA, Cota,
    DenCatTXInv, CodPR,
    TipDoc, PrefixDoc, NRDoc, DataDoc&apos;||
    gUserFields||&apos;)
  SELECT
    T.CodDoc NAV_CodDoc, T.TipDoc NAV_TipDoc,
    CASE
      WHEN TipTranz =  1 THEN &apos;&apos;L&apos;&apos;
      WHEN TipTranz =  2 THEN &apos;&apos;LS&apos;&apos;
      WHEN TipTranz =  3 THEN &apos;&apos;A&apos;&apos;
      WHEN TipTranz =  4 THEN &apos;&apos;AI&apos;&apos;
      WHEN TipTranz =  5 THEN &apos;&apos;AS&apos;&apos;
      WHEN TipTranz =  7 THEN &apos;&apos;V&apos;&apos;
      WHEN TipTranz =  8 THEN &apos;&apos;C&apos;&apos;
      WHEN TipTranz =  9 THEN &apos;&apos;N&apos;&apos;
      WHEN TipTranz = 10 THEN &apos;&apos;I1&apos;&apos;
      WHEN TipTranz = 11 THEN &apos;&apos;I2&apos;&apos;
    END Tip,
    T.cui, T.denp, T.regscutire,
    CASE
      WHEN t.cuivalid = 7             THEN &apos;&apos;?&apos;&apos;
      WHEN t.cuivalid IN (1, 2, 3, 5) THEN &apos;&apos;DA&apos;&apos;
      ELSE                                 &apos;&apos;NU&apos;&apos;
    END CuiOK,
    CASE WHEN SUBSTR(t.cui,1,2) = &apos;&apos;RO&apos;&apos; THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END PartAreRO,
    CASE t.cuivalid WHEN 3 THEN &apos;&apos;NU&apos;&apos; WHEN 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;-&apos;&apos; END ANAFAreRO,
    CASE t.cuivalid
      WHEN 7 THEN &apos;&apos;Partener strain (neverificabil)&apos;&apos;
      WHEN 6 THEN &apos;&apos;CNP Inalid conform algoritm de verificare&apos;&apos;
      WHEN 5 THEN &apos;&apos;CNP Valid conform algoritm de verificare&apos;&apos;
      WHEN 4 THEN &apos;&apos;Partener invalid (ANAF)&apos;&apos;
      WHEN 3 THEN &apos;&apos;Partener neplatitor de TVA (ANAF)&apos;&apos;
      WHEN 2 THEN &apos;&apos;Partener platitor de TVA (ANAF)&apos;&apos;
      WHEN 1 THEN &apos;&apos;CUI Valid conform algoritm de verificare&apos;&apos;
      WHEN 0 THEN &apos;&apos;CUI invalid&apos;&apos;
    END ValidANAF,
    CASE WHEN COALESCE(p.tvalaincasare,0) = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END PartTVAInc,
    T.F, T.baza*T.curs AS BI, T.tva*T.curs AS TVA, T.proctva AS Cota,
    CTI.denumire DenCatTXInv, T.codd394 AS CodPR,
    pkg_list_base_utils.decode_tipdoc(T.TipDoc) TipDoc,
    Coalesce(ies.prefixdoc, intr.prefixdoc) PrefixDoc, Coalesce(ies.NRDoc, intr.NRDoc) NRDoc, Coalesce(ies.DataDoc, intr.DataDoc) DataDoc&apos;||
    gUserAlias||&apos;
  FROM TMP_D39416_GEN T
    LEFT JOIN categartti cti ON cti.CodCategArtTI = t.categtxinv
    LEFT JOIN iesiri ies ON ies.codies = t.coddoc AND ies.tipdoc = t.tipdoc
    LEFT JOIN intrari intr ON intr.codintr = t.coddoc AND intr.tipdoc = t.tipdoc
    LEFT JOIN npart p ON p.codpart = t.codpart &apos;||
    gSuplJoins||&apos;
  WHERE T.TipTranz IS NOT NULL&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_gend39416;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_GENDINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A19A45AA44B42DAC1F13C18BDD1F9D63662D3A04</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_GENDINTRASTAT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  gSuplCols := &apos;TMP_DINTRASTAT_GEN T, INTRARI INTR, IESIRI IES, NPART P, NARTOBJ O&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    NAV_CodDoc, NAV_TipDoc,
    Tip,
    TipDoc, PrefixDoc, NRDoc, DataDoc,
    DenPart, DenArt,
    Cn8Code, InvoiceValue, StatisticalValue, NetMass, NatureOfTransactionACode, NatureOfTransactionBCode, DeliveryTermsCode, ModeOfTransportCode,
    CountryOfOrigin, SupplUnitCode, QtyInSupplUnits, CountryOfConsignment, CountryOfDestination, PartnerCountryCode, PartnerVatNr &apos;||gUserFields||&apos;)
  SELECT
    T.CodDoc NAV_CodDoc, T.TipDoc NAV_TipDoc,
    CASE TipOper WHEN  1 THEN &apos;&apos;Intrare&apos;&apos; WHEN 2 THEN &apos;&apos;Expediere&apos;&apos; END Tip,
    pkg_list_base_utils.decode_tipdoc(T.TipDoc) TipDoc, Coalesce(ies.prefixdoc, intr.prefixdoc) PrefixDoc, Coalesce(ies.NRDoc, intr.NRDoc) NRDoc, Coalesce(ies.DataDoc, intr.DataDoc) DataDoc,
    p.Den_Part DenPart, o.Denumire DenArt,
    t.Cn8Code, t.InvoiceValue, t.StatisticalValue, t.NetMass, t.NatureOfTransactionACode, t.NatureOfTransactionBCode, t.DeliveryTermsCode, t.ModeOfTransportCode,
    t.CountryOfOrigin, t.SupplUnitCode, t.QtyInSupplUnits, t.CountryOfConsignment, t.CountryOfDestination, t.PartnerCountryCode, t.PartnerVatNr &apos;||gUserAlias||&apos;
  FROM TMP_DINTRASTAT_GEN T
    LEFT JOIN intrari intr ON intr.codintr = t.coddoc AND intr.tipdoc = t.tipdoc
    LEFT JOIN iesiri ies ON ies.codies = t.coddoc AND ies.tipdoc = t.tipdoc
    LEFT JOIN npart p ON p.codpart = t.codpart
    LEFT JOIN nartobj o ON o.codobiect = t.codobiect&apos;||
    gSuplJoins;

  PKG_DINTRASTAT.UmpleGEN( PKG_LIST_BASE_SELANLUNAREF.An, PKG_LIST_BASE_SELANLUNAREF.Luna, PKG_LIST_BASE_SELANLUNAREF.Sub);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_GENDINTRASTAT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_GRADI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2320E12E2A81F22665BEA1D59A6BD0203E27A4B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_GRADI is

vCodLansProd LANSPROD.CODLANSPROD%TYPE;
gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodLansProd := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    select
     SAPTAMANA,
     OBS,
     to_char(trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7, &apos;dd.mm.yyyy&apos;) DataStart,
     to_char(trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + Saptamana  * 7 - 1, &apos;dd.mm.yyyy&apos;) DataStop
    from lansprod
    where codlansprod = vCodLansProd
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;SAPTAMANA&apos;,    v_rec.Saptamana);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,   v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATA INCEPUT&apos;, v_rec.DataStart);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DATA SFARSIT&apos;, v_rec.DataStop);
    exit;
  END LOOP;
  for v_rec in (select * from lansgest where codlansprod = vcodlansprod) loop
    pkg_list_Struct.ADAUGA_PARAM(v_rec.simbol||&apos; - nr.schimburi&apos;, v_rec.NRSCHIMBURI);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.simbol||&apos; - capacitate&apos;, v_rec.CAPACITATE);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.simbol||&apos; - incarcare&apos;, v_rec.INCARCARE);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.simbol||&apos; - incarcare dupa redistribuire&apos;, v_rec.INCARCARER);
    pkg_list_Struct.ADAUGA_PARAM(v_rec.simbol||&apos; - ore pe schimb&apos;, v_rec.ORESCHIMB);
  end loop;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(10000);
sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;LANSPROD1 L1,NARTOBJ OBJ,NART ART,NGEST GI,NCLASEA CLS,LANSPROD2 L2&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    CODLANSPROD1,
    DENUMIRE,
    CODEXTERN,
    LANSAT,
    RESTD,
    EXCLUS,
    DEN_GESTI&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    L1.CODLANSPROD1,
    OBJ.DENUMIRE,
    OBJ.CODEXTERN,
    L1.NECESAR,
    L1.RESTD,
    CASE WHEN L1.EXCLUS = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    GI.DEN_GEST &apos;||gUserAlias||&apos;
  FROM LANSPROD L
    INNER JOIN LANSPROD1 L1 ON L1.CODLANSPROD = L.CODLANSPROD
    INNER JOIN LANSPROD2 L2 ON L2.CODLANSPROD1 = L1.CODLANSPROD1
    INNER JOIN NARTOBJ OBJ ON L1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
    INNER JOIN NUM NUM ON NUM.CODUM = ART.UM
    INNER JOIN NGEST GI ON GI.CODGEST = L1.CODGEST
    LEFT JOIN NCLASEA CLS ON ART.CLASA = CLS.CODCLASEA &apos;||gSuplJoins||&apos;
  WHERE L.codlansprod = &apos;||vCodlansprod;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  for v_rec in (select * from lansprod2s where codlansprod = vCodLansProd) loop
    sSelect := &apos;update &apos;||TMPNAME||&apos; set t&apos;||v_rec.codgest||&apos; = &apos;||v_rec.timpest||&apos; where codlansprod1 = &apos;||v_rec.codlansprod1;
    execute immediate sSelect;
    if nvl(v_rec.cant,0) &gt; 0 then
      sSelect := &apos;update &apos;||TMPNAME||&apos; set s&apos;||v_rec.codgest||&apos; = &apos;||v_rec.cant||&apos; where codlansprod1 = &apos;||v_rec.codlansprod1;
      execute immediate sSelect;
    end if;
  end loop;

  ProcessParams;
  COMMIT;
END;

end PKG_LIST_BASE_GRADI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_GRAD_INC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66E131C063BBC1BC935D4A7CF951CB82303F8140</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_GRAD_INC IS

  sZi1 VARCHAR2(50);
  sZi2 VARCHAR2(50);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
 
  vDataS       DATE;
  vDataF       DATE;
  
PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 )IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;

FUNCTION TOTAL_M(aCodGest IN NUMBER, aCodGrEchiv IN NUMBER, aZi IN DATE) RETURN Number IS
  CATE number;
	GrupaAuto  Number;
BEGIN
  GrupaAuto := PKG_RAC_REZ.IndexGrupaAuto;
  PKG_RAC_REZ.SET_RAC_DATASTART(To_Char(aZi, &apos;DD.MM.YYYY hh24:mi&apos;));

  SELECT Count(1) into CATE
  FROM (
    SELECT A.CodAuto
    FROM V_RAC_CARS A
    WHERE A.Inactiv = 0 AND A.Extern = 0 AND A.Generic = 0 AND A.CodGest &gt; 0 AND Ind = GrupaAuto 
      AND A.CodGest = aCodGest
      AND A.CodGrEchiv = aCodGrEchiv
  )	;

  RETURN  Nvl(CATE,0);
END;

FUNCTION TOTAL_I(aCodGest IN NUMBER, aCodGrEchiv IN NUMBER, aZi IN DATE) RETURN Number IS
  CATE number;
	GrupaAuto  Number;
BEGIN
  GrupaAuto := PKG_RAC_REZ.IndexGrupaAuto;
  PKG_RAC_REZ.SET_RAC_DATASTART(To_Char(aZi, &apos;DD.MM.YYYY hh24:mi&apos;));

  SELECT COUNT(1) INTO CATE
  FROM (
    SELECT Nvl(C.Mijltransp, 0) CodAuto
    FROM  Comanda c INNER JOIN RAC_REZ R ON R.codcomanda = c.codcomanda
    WHERE c.codcomanda &gt; 0 AND c.tipdoc = 94 and Nvl(C.Operat, 0) = 1 and Nvl(C.Mijltransp, 0) &gt; 0 and R.TipRezervare not in (5, 7)
			AND ( Nvl(R.Predat, 0) = 0 OR Pkg_Rac_Rez.RAC_DATASTART &lt;= trunc(R.DataPred))
			AND Pkg_Rac_Rez.RAC_DATASTART &gt;= trunc(R.DataStart)
  ) C
  INNER JOIN (
    SELECT A.CodAuto, A.Clasa, A.NrAuto, A.Marca, A.Model, A.Inactiv, A.CodGest, A.AnF
    FROM V_RAC_CARS A
    WHERE A.Inactiv = 0 AND A.Extern = 0 AND A.Generic = 0 AND A.CodGest &gt; 0 AND A.Ind = GrupaAuto
      AND A.CodGest = aCodGest
      AND A.CodGrEchiv = aCodGrEchiv
  ) A ON A.CodAuto = C.CodAuto ;

  RETURN Coalesce(CATE,0);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsertTMP CLOB;
  sInsert    CLOB;
  vZi        DATE;
	GrupaAuto  Number;
	
BEGIN
  GrupaAuto := PKG_RAC_REZ.IndexGrupaAuto;
  gSuplCols := &apos;NGEST G, GRECHIV GRE, NAGENDA NA, NLOCALIT NL, NJUDET NJ&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  umple_tmp_zile(PKG_LIST_ALEGPERIOADA.getDataS, PKG_LIST_ALEGPERIOADA.getDataF);

  LIST_EXECUTE_IMMEDIATE( &apos;TRUNCATE TABLE TMP_LST_GRAD_INC&apos;, aLISTID, aLISTVER);

  FOR v_Rec IN (SELECT ZIUA FROM TMP_ZILE ORDER BY ZIUA)
  LOOP
    PKG_RAC_REZ.SET_RAC_DATASTART(To_Char(v_Rec.Ziua, &apos;DD.MM.YYYY hh24:mi&apos;),1 );  --1 inseamna ca baga si in tmp valori
    INSERT INTO TMP_LST_GRAD_INC (CODGEST, CODGRECHIV, ZIUA, MASINI_TOT, MASINI_INC )
    SELECT G.CodGest, GRE.CodGrEchiv, v_Rec.Ziua, 
		       cate + (Select Count(*) from TMP_V_RAC_CARS x where x.inactiv=0 and x.Codgest = G.CodGest and x.codgrechiv = GRE.CodGrEchiv)  masini_tot, Coalesce(z.m_inc,0)  masini_inc
    FROM NGEST G
      CROSS JOIN (SELECT CodGrEchiv FROM GREchiv Where IND = GrupaAuto) GRE
      LEFT JOIN 
			(
        SELECT CodGest, CodGrEchiv, Sum(cnt_tot) Cate,  Sum(cnt_mt) m_inc  FROM (
select distinct CodGest, CodGrEchiv, CodAuto, Sum(Plusul)  cnt_tot, Case when Nvl(CodAuto, 0) &gt; 0 then 1 else 0 end cnt_mt
--1           
				from (
				 SELECT A.CodGest, A.CodGrEchiv, mt.CodAuto, 0 Plusul 
          FROM TMP_V_RAC_CARS A
            LEFT JOIN 
          (
            SELECT DISTINCT CodAuto, TIP
            FROM
            (
              SELECT 
              C.Mijltransp CodAuto, 
              Case
                when Trunc(R.DataStart) = v_Rec.Ziua or Trunc(R.DataPred) = v_Rec.Ziua then 1
                else 0
              end Tip
              FROM  Comanda c INNER JOIN RAC_REZ R ON R.codcomanda = c.codcomanda
              WHERE c.tipdoc = 94 and Nvl(C.Operat, 0) = 1 and Nvl(C.Mijltransp, 0) &gt; 0 and R.TipRezervare not in (4, 5, 7)
                AND ( Nvl(R.Predat, 0) = 0 OR Pkg_Rac_Rez.RAC_DATASTART &lt;= trunc(R.DataPred))
                AND Pkg_Rac_Rez.RAC_DATASTART &gt;= trunc(R.DataStart)
            )
          ) mt ON mt.CodAuto = A.CodAuto
          WHERE 
                Trunc(A.Data) &lt;&gt; v_Rec.Ziua and --v_Rec.Ziua --masini transferate in gestiune in alta zi decat ziua de analiza
                A.CodGest &gt; 0 and 
                A.Inactiv = 0 
--2
          union all
          SELECT A.CodGest, A.CodGrEchiv, mt.CodAuto, 0 Plusul 
          FROM TMP_V_RAC_CARS A
            LEFT JOIN 
          (
            SELECT DISTINCT CodAuto, TIP
            FROM
            (
              SELECT 
              C.Mijltransp CodAuto, 
              Case
                when Trunc(R.DataStart) = v_Rec.Ziua or Trunc(R.DataPred) = v_Rec.Ziua then 1
                else 0
              end Tip
              FROM  Comanda c INNER JOIN RAC_REZ R ON R.codcomanda = c.codcomanda
              WHERE c.tipdoc = 94 and Nvl(C.Operat, 0) = 1 and Nvl(C.Mijltransp, 0) &gt; 0 and R.TipRezervare not in (4, 5, 7)
                AND ( Nvl(R.Predat, 0) = 0 OR Pkg_Rac_Rez.RAC_DATASTART &lt;= trunc(R.DataPred))
                AND Pkg_Rac_Rez.RAC_DATASTART &gt;= trunc(R.DataStart)
            )
          ) mt ON mt.CodAuto = A.CodAuto
          WHERE 
                Trunc(A.Data) = v_Rec.Ziua and --v_Rec.Ziua --masini transferate in gestiune in alta zi decat ziua de analiza
                A.CodGest &gt; 0 and 
                A.Inactiv = 0 
--3
          union all
          SELECT 
                 (
                  SELECT
                    CodGest
                  from NParcG NPG
                  WHERE NPG.CodNParcAut = mt.CodAuto
                  and   NPG.Data = ( SELECT Max(xNPG.DATA)
                                     FROM NParcG xNPG WHERE xNPG.CodNParcAut = NPG.CodNParcAut
                                     AND Trunc(xNPG.Data) &lt; Trunc(A.data))
                 ) CodGest, 
                 A.CodGrEchiv, mt.CodAuto, 1 Plusul
          FROM TMP_V_RAC_CARS A
            LEFT JOIN 
          (
            SELECT DISTINCT CodAuto, TIP
            FROM
            (
              SELECT 
              C.Mijltransp CodAuto, 
              Case
                when Trunc(R.DataStart) = v_Rec.Ziua or Trunc(R.DataPred) = v_Rec.Ziua then 1
                else 0
              end Tip
              FROM  Comanda c INNER JOIN RAC_REZ R ON R.codcomanda = c.codcomanda
              WHERE c.tipdoc = 94 and Nvl(C.Operat, 0) = 1 and Nvl(C.Mijltransp, 0) &gt; 0 and R.TipRezervare not in (4, 5, 7)
                AND Trunc(R.DataPred) = v_Rec.Ziua
            )
          ) mt ON mt.CodAuto = A.CodAuto
          WHERE 
                Trunc(A.Data) = v_Rec.Ziua and --v_Rec.Ziua --masini transferate in gestiune in alta zi decat ziua de analiza
            		A.CodGest &gt; 0 and 
								A.Inactiv = 0 
        )GROUP BY  CodGest, CodGrEchiv, CodAuto
				) 
				 GROUP BY CodGest, CodGrEchiv
      ) Z ON Z.CodGest = G.CodGest AND Z.CodGrEchiv = GRE.CodGrEchiv;
  END LOOP; 

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     GESTIUNE, CLASA, DATA, ZIUA, LUNA, Anul, Judet, masini_tot, masini_inc &apos;||gUserFields||&apos;)
  SELECT
    G.Den_gest, GRE.CodGrEchiv, X.Ziua data,
    Extract(DAY from X.Ziua) Ziua, Extract(MONTH from X.Ziua) LUNA, Extract(YEAR from X.Ziua) Anul,
	  Nvl(NJ.SIMBAUTO,&apos;&apos;?&apos;&apos;) JUDET,
    X.masini_tot,
    X.masini_inc &apos;||gUserAlias||&apos;
  FROM TMP_LST_GRAD_INC X
	  INNER JOIN NGEST G on X.Codgest = G.CodGest
    INNER JOIN GRECHIV GRE ON GRE.CodGrEchiv = X.CodGrEchiv
    left JOIN NAGENDA NA on G.Codgest = NA.CodGest
    left JOIN NLOCALIT NL on Nvl(NA.CODLOCALIT,0) = NL.CODLOCALIT
    left JOIN NJUDET NJ on NJ.CODJUDET = Nvl(NL.CODJUDET,0)&apos;||
    gSuplJoins||&apos;
	WHERE X.masini_tot &lt;&gt; 0&apos;;
  LIST_EXECUTE_IMMEDIATE( sInsert, aLISTID, aLISTVER);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_GRAD_INC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C41BAEB73B5949C7ADFBD8F38F59E45DF13089A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IESEXT IS

  gSuplCols   VARCHAR2(3000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(3000);
  gUserAlias  VARCHAR2(3000);
  gNullAlias  VARCHAR2(3000);
  sFiltru     VARCHAR2(3000);
  sTMPUtils   CLOB;
  sTruncTMP   CLOB;
  sInsertTMP  CLOB;
  sInsert     CLOB;
  pUsername   VARCHAR2(100);
  pFirmeExt   VARCHAR2(3000) := pkg_categconst.GetValConstanta(&apos;StocExternFirma&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pCampExt    VARCHAR2(100)  := PKG_LIST_BASE_UTILS.Get_StocExternCamp;
BEGIN
  gSuplCols :=
    &apos;TMP_LST_IESIRI I1, IESIRI IES, IESIRI AE, NARTOBJ NAO, NART NA, NCONT NCV, NCLASEAS CS, NCLASEA NCA, NPART NP, IOPART1 IOP1, NCONT CCLI, NCONT CSERV, &apos;||
    &apos;NPARTCODFISC FISC, NGEST NG, NSUBUNIT NS, NSUBUNIT NSUB, NMONEDE MON, NMONEDE MONT, COMANDA1 COM1, NARTOBJ1 NAO1, PROMO P&apos;
    ||&apos;, NAGENDA SLIVR, NLOCALIT LOCLIVR, NJUDET JUDLIVR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;IES1&apos;,        &apos;IES1.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,            &apos;UM1&apos;,         &apos;UM1.CODUM = NA.UM1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,            &apos;UM2&apos;,         &apos;UM2.CODUM = NA.UM2&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEP&apos;,        &apos;NCP&apos;,         &apos;NCP.CODCLASEP = NP.CODCLASA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,          &apos;CREP&apos;,        &apos;CREP.CODCONT = IO1.CONT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;,     &apos;DC&apos;,          &apos;DC.CODCARNET = IES.CARNETDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,          &apos;PROD&apos;,        &apos;PROD.CODPART = NAO.CODPRODUCATOR&apos;);
--  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SLIVR&apos;,       &apos;SLIVR.CODAGENDA = IES.CODLOCATIE&apos;);
--  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCLIVR&apos;,     &apos;LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT&apos;);
--  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;,         &apos;JUDLIVR&apos;,     &apos;JUDLIVR.CODJUDET = LOCLIVR.CODJUDET&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;,          &apos;ZONALIVR&apos;,    &apos;ZONALIVR.CODZONA = LOCLIVR.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARALIVR&apos;,    &apos;TARALIVR.CODTARA = LOCLIVR.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRASEULIVR&apos;,     &apos;TLIVR&apos;,       &apos;TLIVR.CODTRASEULIVR = SLIVR.CODTRASEU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTIPSEDII&apos;,      &apos;TIPSLIVR&apos;,    &apos;TIPSLIVR.CODTIPSEDIU = SLIVR.CODTIPSEDIU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SSOC&apos;,        &apos;SSOC.CODPART = IES.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCSOC&apos;,      &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;,         &apos;JUDSOC&apos;,      &apos;JUDSOC.CODJUDET = LOCSOC.CODJUDET&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;,          &apos;ZONASOC&apos;,     &apos;ZONASOC.CODZONA = LOCSOC.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARASOC&apos;,     &apos;TARASOC.CODTARA = LOCSOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARAORIG&apos;,    &apos;TARAORIG.CODTARA = NAO.TARAORIGINE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NGEST&apos;,          &apos;NGSERV&apos;,      &apos;NGSERV.CODGEST = I1.GESTACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;COM&apos;,         &apos;COM.CODCOMANDA = COM1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,       &apos;CC1&apos;,         &apos;CC1.CODCOMANDA1 = I1.CODLINIECOMANDACC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,       &apos;DL1&apos;,         &apos;DL1.CODCOMANDA1 = I1.CODLINIECOMANDADL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;CC&apos;,          &apos;CC.CODCOMANDA = CC1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;DL&apos;,          &apos;DL.CODCOMANDA = DL1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,        &apos;NPTR&apos;,        &apos;NPTR.CODPARTTR = I1.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,        &apos;AA&apos;,          &apos;AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,          &apos;PM&apos;,          &apos;PM.CODOBIECT = I1.CODOBIECT AND PM.SUBUNITATEA = IES.SUBUNITATEA AND PM.IMPLICIT = 1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,     &apos;CCOST&apos;,       &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;ISTORN1&apos;,     &apos;ISTORN1.CODIES1 = I1.CODIES1STORNO&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;ISTORN&apos;,      &apos;ISTORN.CODIES = ISTORN1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;DOCIMP1&apos;,     &apos;DOCIMP1.CODIES1 = I1.CODLINIEDOCIMP AND I1.TIPDOCIMP IN (19, 20, 21, 26 )&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;DOCIMP&apos;,      &apos;DOCIMP.CODIES = DOCIMP1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,     &apos;ANOD&apos;,        &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,     &apos;ANALIZ&apos;,      &apos;ANALIZ.CODANALIZA = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;,   &apos;ADESC1&apos;,      &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;,    &apos;ADESC&apos;,       &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,       &apos;PD&apos;,          &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJSUBUNIT&apos;, &apos;NAOS&apos;,        &apos;NAOS.CODOBIECT = NAO.CODOBIECT AND NAOS.SUBUNITATE = IES.SUBUNITATEA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SPROD&apos;,       &apos;SPROD.CODPART = NAO.CODPRODUCATOR AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SPROD.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCPROD&apos;,     &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARAPROD&apos;,    &apos;TARAPROD.CODTARA = LOCPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;,      &apos;CONTR1&apos;,      &apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT&apos;,       &apos;CONTR&apos;,       &apos;CONTR.CODCONTRACT = COALESCE(CONTR1.CODCONTRACT,AE.CODCONTRACT,IES.CODCONTRACT)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT2&apos;,      &apos;CONTR2&apos;,      &apos;CONTR2.CODDOC = I1.CODIES AND CONTR2.TIPDOC = I1.TIPDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,          &apos;COMIS&apos;,       &apos;COMIS.CODPART = IES.PARTCUSTODIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,          &apos;AG_DOC&apos;,      &apos;AG_DOC.CODPERS = COALESCE(DECODE(IES.TIPDOC,16,I1.CODAGENTEMULARE,IES.AGENT),0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,        &apos;ACLI&apos;,        &apos;ACLI.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(I1.CODOBIECT, IES.PARTENER, NP.CODCLASA)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;
  WHERE Coalesce(i1.cant,0) &lt;&gt; 0 AND i.anulat = 0
    AND i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;,&apos;&apos;R&apos;&apos;)
    AND Coalesce(i.initializari,0) = 0&apos;;

  IF PKG_LIST_SELDOCEXT.DupaData
  THEN
    sFiltru := sFiltru||&apos;
    AND i.datadoc &apos; || PKG_LIST_SELDOCEXT.Perioada||&apos; &apos;;
  ELSE
    sFiltru := sFiltru||&apos;
    AND (i.luna + i.an * 12) &apos; || PKG_LIST_SELDOCEXT.Perioada||&apos; &apos;;
  END IF;
  sFiltru := sFiltru||&apos;
    AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; )&apos;;

  sTruncTMP := &apos;TRUNCATE TABLE tmp_lst_iessimpl&apos;;
  sInsertTMP:= PKG_LIST_BASE_IESIRI.Sql_tmp_lst_iessimpl(sFiltru, InStr(gSuplJoins,&apos;IOP1.CODIOPART1 = I1.CODIOPART1&apos;), InStr(gSuplJoins,&apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;));

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    CODFIRMA, DEN_FIRMA,
    CODDOC, TIPDOC, CODOBIECT,TIPART,DEN_ARTICOL,DEN_ORIGINAL,DEN_UM,CANT,
    DOCUMENT, MON_DOC, MON_TRANSF, CURS_DOC, CURS_TRANSF,
    PU,ADDIM,DISCUNIT,PUDISC,PROC_TVA,
    DISCTOTAL,DISCTOT_TVA,DISCTOTCUTVA,
    VALOARE,VAL_TVA,VALCUTVA,
    DEN_PART,
    TIPTVA, TIPTRANZ, TIPFACTURA,
    DATASCAD,ZILESCAD,TRANSPORT,
    ANDOC,LUNADOC,LUNA,
    SUBUNITATE, CostTransport, CUICorect,
    IndexLinie,DENCLASEAS,DenClasaA,SimbClasaA,ObsArt,
    GARANTIE, OPERAT, CADOU,
    TIPPROMO, NRPROMO, NRAE, ZILEDISCT, PROCDISCTOT,
    DISCOFF2,
    DISCOFF3,
    X_JUDET, X_CODCLASAP, X_CODSUBUNIT&apos;||gUserFields||&apos;)
  SELECT
    TPG.FIRMAID, TPG.FIRMANAME,
    i1.codies CodDoc, i1.tipdoc , i1.CODOBIECT, i1.tipart, nao.denumire DEN_ARTICOL, i1.denobiectorig DEN_ORIGINAL, um.den_um1 DEN_UM, i1.cant/um.paritate cant,
    ies.prefixdoc||ies.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(ies.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) document, mon.den_moneda MON_DOC, mont.den_moneda MON_TRANSF, Coalesce(ies.curs,1) CURS_DOC, ies.cursdoc CURS_TRANSF,
    i1.pu * um.paritate PU, i1.addim, (i1.pies-i1.pu) * um.paritate DISCUNIT, i1.pies * um.paritate PUDISC, i1.coef_tva*100 PROC_TVA,
    i1.cant*(i1.pies - i1.pu) DISCTOTAL,
    CASE WHEN i1.tipdoc = 16 THEN i1.tvalin - i1.tvau ELSE i1.cant*(i1.pies - i1.pu) * i1.coef_tva END DISCTOT_TVA,
    CASE WHEN i1.tipdoc = 16 THEN i1.cant*(i1.pies - i1.pu) + i1.tvalin - i1.tvau ELSE i1.cant*(i1.pies - i1.pu) * (1+i1.coef_tva) END DISCTOTCUTVA,
    i1.cant * i1.pies VALOARE,
    CASE WHEN i1.tipdoc = 16 THEN i1.tvalin WHEN i1.pu = i1.pies THEN i1.tvalin ELSE i1.cant*i1.pies*i1.coef_tva END VAL_TVA,
    CASE WHEN i1.tipdoc = 16 THEN i1.cant*i1.pies+i1.tvalin WHEN i1.pu = i1.pies THEN i1.cant*i1.pies+i1.tvalin ELSE i1.cant*i1.pies*(1+i1.coef_tva) END VALCUTVA,
    CASE
      WHEN i1.tipdoc = 14 THEN &apos;&apos;-&apos;&apos;
      WHEN i1.tipdoc = 16 THEN &apos;&apos;Vanzari cu amanuntul&apos;&apos;
      WHEN i1.tipdoc = 23 THEN ns.den_subunit
      WHEN i1.tipdoc = 24 THEN ng.den_gest
      ELSE np.den_part
    END DEN_PART,
    CASE
      WHEN ies.tiptva = 1 THEN &apos;&apos;Taxare Normala&apos;&apos;
      WHEN ies.tiptva = 2 THEN &apos;&apos;Taxare Inversa&apos;&apos;
      WHEN ies.tiptva = 3 THEN &apos;&apos;Taxare Triunghiulara&apos;&apos;
      WHEN ies.tiptva = 4 THEN &apos;&apos;Prestari in afara Romaniei&apos;&apos;
      WHEN ies.tiptva = 5 THEN &apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;
      WHEN ies.tiptva = 6 THEN &apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;
      WHEN ies.tiptva = 7 THEN &apos;&apos;regim special(art.1521, 1522)&apos;&apos;
    END TIPTVA,
    CASE
      WHEN ies.tiptranzactie = 1 THEN &apos;&apos;Tranzactie interna&apos;&apos;
      WHEN ies.tiptranzactie = 2 THEN &apos;&apos;Livrare intracomunitara&apos;&apos;
      WHEN ies.tiptranzactie = 3 THEN &apos;&apos;Export&apos;&apos;
    END TIPTRANZ,
    CASE
      WHEN ies.infocm     = 1 THEN &apos;&apos;InfoCM&apos;&apos;
      WHEN ies.tipfactura = 8 THEN &apos;&apos;Nota cantar&apos;&apos;
      WHEN ies.tipfactura = 7 THEN &apos;&apos;Cu incasare imediata prin CM&apos;&apos;
      WHEN ies.tipfactura = 5 THEN &apos;&apos;Stingere nota credit&apos;&apos;
      WHEN ies.tipfactura = 4 THEN &apos;&apos;Service auto&apos;&apos;
      WHEN ies.tipfactura = 3 THEN &apos;&apos;Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 2 THEN &apos;&apos;Contract Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 1 THEN &apos;&apos;Abonament&apos;&apos;
      ELSE &apos;&apos;Normala&apos;&apos;
    END TIPFACTURA,
    i1.termen DATASCAD, CASE WHEN i1.termen IS NULL THEN 0 ELSE i1.termen - ies.datadoc END ZILESCAD, i1.transport,
    ies.an andoc, ies.luna lunadoc, to_char(ies.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(ies.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(ies.Luna) luna,
    nsub.den_subunit SUBUNITATE, I1.CostTransport, CASE WHEN cif_valid(FISC.CodFiscal) = 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect,
    I1.IndexLocal IndexLinie, cs.den_claseas DENCLASEAS, nca.den_clasea DenClasaA, nca.simbol SimbClasaA, i1.obsart,
    CASE WHEN IES.TIPCONSUMATOR = 2 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END GARANTIE, CASE WHEN IES.OPERAT = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END OPERAT, CASE WHEN I1.CADOU = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END CADOU,
    CASE
      WHEN p.tippromotie = 1 THEN &apos;&apos;marime pret&apos;&apos;
      WHEN p.tippromotie = 2 THEN &apos;&apos;% discount&apos;&apos;
      WHEN p.tippromotie = 3 THEN &apos;&apos;articole promotionale (cadou)&apos;&apos;
    END TIPPROMO, p.nrdoc NRPROMO, ae.nrdoc NRAE, null ziledisct, (i1.coefdiscmaj-1)*100 procdisctot,
    i1.pies*i1.cant*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 2 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF2,
    i1.pies*i1.cant*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 3 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF3,
    JUDLIVR.simbauto, np.codclasa, nsub.codsubunit&apos;||
    gUserAlias||&apos;
  FROM TMP_LST_IESSIMPL I1
    CROSS JOIN TMP_PKG_GLOBALS TPG
	  LEFT JOIN IESIRI       IES     ON ies.codies         = i1.codies
	  LEFT JOIN IESIRI       AE      ON ae.codies          = CASE WHEN i1.tipdoc = 20 THEN i1.codies ELSE i1.codae END
    LEFT JOIN NARTOBJ      NAO     ON nao.codobiect      = i1.codobiect
    LEFT JOIN NART         NA      ON na.codarticol      = nao.codarticol
    LEFT JOIN NCLASEAS     CS      ON cs.codclaseas      = na.clasastatist
    LEFT JOIN NCLASEA      NCA     ON nca.codclasea      = na.clasa
    LEFT JOIN NUM1         UM      ON um.codum1          = i1.umsec
    LEFT JOIN NPART        NP      ON np.codpart         = ies.partener
    LEFT JOIN NPARTCODFISC FISC    ON fisc.codpart       = ies.partener AND fisc.principal = 1
    LEFT JOIN NGEST        NG      ON ng.codgest         = ies.codgestprod
    LEFT JOIN NSUBUNIT     NS      ON ns.codsubunit      = ies.codsubunit
    LEFT JOIN NSUBUNIT     NSUB    ON nsub.codsubunit    = ies.subunitatea
    LEFT JOIN NMONEDE      MON     ON mon.codmoneda      = ies.moneda
    LEFT JOIN NMONEDE      MONT    ON mont.codmoneda     = ies.monedatransf
    LEFT JOIN promo        p       ON p.codpromo         = i1.codpromo
    LEFT JOIN nartobj1     nao1    ON nao1.codobiect1    = i1.codobiect1
    LEFT JOIN NAGENDA      SLIVR   ON SLIVR.CODAGENDA    = IES.CODLOCATIE
    LEFT JOIN NLOCALIT     LOCLIVR ON LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT
    LEFT JOIN NJUDET       JUDLIVR ON JUDLIVR.CODJUDET   = LOCLIVR.CODJUDET&apos;||
    gSuplJoins;


  sTMPUtils := &apos;BEGIN &apos;||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NARTOBJ1&apos;&apos;); &apos;||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NART1&apos;&apos;); &apos;   ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NTVA1&apos;&apos;); &apos;   ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NTAXE1&apos;&apos;); &apos;  ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NPERS1&apos;&apos;); &apos;  ||CHR(10)||
               &apos;END;&apos;;

  LIST_EXECUTE_IMMEDIATE(sTMPUtils , aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sTruncTmp , aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsertTmp, aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsert   , aLISTID, aLISTVER);

  IF pFirmeExt IS NOT NULL THEN
    SELECT USERNAME INTO pUSERNAME FROM user_users;
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_START;
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sTMPUtils , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sTruncTmp , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sInsertTmp, aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sInsert   , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_GETDATE(pUSERNAME, pFirmeExt, tmpName);
  END IF;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END PKG_LIST_BASE_IESEXT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42A63450EEEDF99CD8E485AEA2CDD844FB6835FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iesfurn IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  sInsTMP      VARCHAR2(10000);
  vToateGest   BOOLEAN         := PKG_LIST_SELECTGEST.ToateGest;
  vDataIni     DATE            := PKG_LIST_SELECTGEST.DataIni;
  vDataFin     DATE            := PKG_LIST_SELECTGEST.DataFin;
  vCateGest    INTEGER;
  vCateLGest   INTEGER;
  sArtIncas    VARCHAR2(300);
  sFiltruData  VARCHAR2(300);
BEGIN

  gSuplCols := &apos;IESIRI IES, IESIRI1 IES1, LIVR L, LIVR1 L1, NIRSTOC NS, NIRSTOC NSINI, NIR N, NIR NINI, NGEST NG, NPART FURN, NPART CLI, NARTOBJ NAO, NART NA, NUM NUM, INTRARI INTR, NAGENDA NAG, NLOCALIT NL, NJUDET NJ, &apos;||
               &apos;NLOCATII NLG, NCLASEA CA, IOART1 IO1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;AGENT&apos;,&apos;AGENT.CODPERS = IES.AGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;INTR1&apos;,&apos;INTR1.CODINTR = INTR.CODINTR AND INTR1.CODINTR1 = NSINI.CODINTR1&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;,&apos;);
  SELECT STRING_AGG(x) INTO sArtIncas
  FROM (
    SELECT Nvl(pkg_categconst.GetValConstanta(&apos;ArtIncasImediat&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) x FROM dual
    UNION
    SELECT Nvl(pkg_categconst.GetValConstanta(&apos;ArtIncasUlterior&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;) x FROM dual);

  IF vDataIni = vDataFin
  THEN sFiltruData := &apos; = To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  ELSE sFiltruData := &apos; BETWEEN To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  vCateGest    := 0;
  vCateLGest   := 0;
  IF NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
  END IF;
  IF    vCateLGest = 0  AND vCateGest &lt;&gt; 0 THEN
    sInsTMP := &apos;
    AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  ELSIF vCateLGest &lt;&gt; 0 AND vCateGest = 0  THEN
    sInsTMP := &apos;
    AND S.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
  ELSIF vCateLGest &lt;&gt; 0 AND vCateGest &lt;&gt; 0 THEN
    sInsTMP := &apos;
    AND (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR
         S.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;))&apos;;
  END IF;

  sInsTMP :=
  &apos;INSERT INTO TMP_IESFURN (
    CODIES, CODIES1, CODLIVR, CODLIVR1, CODNIRSTOC, CODNIRSTOCPARINTE, CODNIRSTOCROOT,
    PIES)
  WITH x AS (
    SELECT i.codies, SUM(i1.pu*i1.cant) val, SUM(i1.tva) tva
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    WHERE i.anulat = 0 AND i.operat = 1 AND i.tipdoc = 16
      AND I.DATADOC &apos;||sFiltruData||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND I1.CODOBIECT IN (&apos;||sArtIncas||&apos;)
    GROUP BY i.codies)
  SELECT
    I.CODIES, I1.CODIES1, L.CODLIVR, L1.CODLIVR1, NS.CODNIRSTOC, NVL(NS.CODNIRSTOCPARINTE,0) CODNIRSTOCPARINTE, NVL(NS1.CODNIRSTOCORIG,0) CODNIRSTOCROOT,
    CASE
      WHEN i.tipdoc = 16 THEN i1.pu - Decode(i1.cant,0,0,NVL(i1.tva,0)/i1.cant)
      ELSE PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret)
    END *
    CASE
      WHEN I.TIPDOC &lt;&gt; 16 THEN 1
      WHEN I1.CODOBIECT IN (&apos;||sArtIncas||&apos;) THEN 1
      WHEN i.valdoc-i.valdiscount-Nvl(x.val,0)-i.tvadoc+i.tvadiscount+Nvl(x.tva,0) = 0 THEN 1
      WHEN i.valdoc-i.valdiscount-Nvl(x.val,0)-i.tvadoc+i.tvadiscount+Nvl(x.tva,0) = I.valdiscount - I.tvadiscount THEN 0
      ELSE 1 + (I.valdiscount - I.tvadiscount)/(i.valdoc-i.valdiscount-Nvl(x.val,0)-i.tvadoc+i.tvadiscount+Nvl(x.tva,0))
    END PIES
  FROM IESIRI I
    INNER JOIN IESIRI1  I1  ON I1.CODIES      = I.CODIES
    INNER JOIN LIVR     L   ON L.CODIES       = I.CODIES   AND L.TIPLIVR  = I.TIPDOC
    INNER JOIN LIVR1    L1  ON L1.CODIES1     = I1.CODIES1 AND L1.CODLIVR = L.CODLIVR
    INNER JOIN NIRSTOC  NS  ON NS.CODNIRSTOC  = L1.CODNIRSTOC
    INNER JOIN NIR      N   ON N.CODNIR       = NS.CODNIR
    LEFT  JOIN X            ON X.CODIES       = I.CODIES
    LEFT  JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
  WHERE I.ANULAT = 0 /*AND I.BLOCAT = 0*/ AND I.OPERAT = 1
    AND I.TIPDOC &lt;&gt; 15 AND I.DATADOC &apos;||sFiltruData||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    sInsTMP;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos; (
    NAV_CodDoc, NAV_TipDoc,
    Jud, Furn, Cli, Gest, LGest, Art, UM, Cant,
    DataAch, PretAch, ValAch,
    DocIntr, DocIes,
    PretIes, ValIes, ValAdaos, Scadenta,
    X_Judet, X_Codclasap, X_Codgest &apos;||gUserFields||&apos;)
  SELECT
    IES.CODIES, IES.TIPDOC,
    NJ.DEN_JUDET, COALESCE(FURN.DEN_PART,GPROD.DEN_GEST), CLI.DEN_PART, NG.DEN_GEST, NLG.DENUMIRE LGEST, NAO.DENUMIRE, NUM.DEN_UM, L1.CANT,
    NS.DATAACHIZ, NSINI.Pret - NSINI.Adaos, L1.CANT * (NSINI.Pret - NSINI.Adaos) ValAch,
    CASE 
      WHEN INTR.CODINTR &gt; 0 THEN INTR.PREFIXDOC||INTR.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(INTR.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      WHEN IESINI.CODIES &gt; 0 THEN IESINI.PREFIXDOC||IESINI.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(IESINI.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)   
    END, IES.PREFIXDOC||IES.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(IES.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;),
    T.PIES, L1.CANT * T.PIES, L1.CANT * (T.PIES - NSINI.Pret + NSINI.Adaos), SCAD.Termen,
    NJ.Simbauto, FURN.codclasa, NG.CODGEST &apos;||gUserAlias||&apos;
  FROM TMP_IESFURN T
    LEFT JOIN (
      SELECT STRING_AGG(TO_CHAR(O.TERMEN, &apos;&apos;DD.MM.YYYY&apos;&apos;)||&apos;&apos; - &apos;&apos;||O.VALOARE) TERMEN, IESIRI.CODIES
      FROM (
        SELECT SUM(OO.VALOARE) VALOARE, OO.CODGENERAL, OO.TERMEN
        FROM OBLIGPIF OO GROUP BY OO.CODGENERAL, OO.TERMEN) O
          INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
          INNER JOIN IESIRI ON IESIRI.CODIES = G.CODDOC AND IESIRI.TIPDOC = G.TIPDOC
        GROUP BY IESIRI.CODIES
    )                  SCAD   ON SCAD.CODIES      = T.CODIES
    LEFT JOIN IESIRI   IES    ON IES.CODIES       = T.CODIES
    LEFT JOIN IESIRI1  IES1   ON IES1.CODIES1     = T.CODIES1
    LEFT JOIN LIVR     L      ON L.CODLIVR        = T.CODLIVR
    LEFT JOIN LIVR1    L1     ON L1.CODLIVR1      = T.CODLIVR1
    LEFT JOIN NIRSTOC  NS     ON NS.CODNIRSTOC    = T.CODNIRSTOC
    LEFT JOIN NIRSTOC  NSINI  ON NSINI.CODNIRSTOC = T.CODNIRSTOCROOT
    LEFT JOIN NIR      N      ON N.CODNIR         = NS.CODNIR
    LEFT JOIN NIR      NINI   ON NINI.CODNIR      = NSINI.CODNIR
    LEFT JOIN NGEST    NG     ON NG.CODGEST       = N.GEST
    LEFT JOIN NPART    FURN   ON FURN.CODPART     = NS.FURN
    LEFT JOIN NGEST    GPROD  ON GPROD.CODGEST    = NS.CODGESTPROD
    LEFT JOIN NPART    CLI    ON CLI.CODPART      = IES.PARTENER
    LEFT JOIN NARTOBJ  NAO    ON NAO.CODOBIECT    = NS.CODOBIECT
    LEFT JOIN NART     NA     ON NA.CODARTICOL    = NAO.CODARTICOL
    LEFT JOIN NUM             ON NUM.CODUM        = NA.UM
    LEFT JOIN INTRARI  INTR   ON INTR.CODINTR     = NINI.CODINTR AND INTR.TIPDOC = NINI.TIPNIR
    LEFT JOIN IESIRI   IESINI ON IESINI.CODIES    = NINI.CODIES AND NINI.CODINTR &gt; 0
    LEFT JOIN NAGENDA  NAG    ON NAG.CODPART      = NS.FURN AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(NAG.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT NL     ON NL.CODLOCALIT    = NAG.CODLOCALIT
    LEFT JOIN NJUDET   NJ     ON NJ.CODJUDET      = NL.CODJUDET
    LEFT JOIN NLOCATII NLG    ON NLG.CODLOCATIE   = NS.CODLOCATIE
    LEFT JOIN NCLASEA  CA     ON CA.CODCLASEA     = NA.CLASA
    LEFT JOIN IOART1   IO1    ON NS.CODIOART      = IO1.CODIOART1 AND (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU) BETWEEN IO1.ALStart and IO1.ALStop &apos;||
    gSuplJoins;

  --delete x;
  --insert into x(test) values(sInsTMP);
  --insert into x(test) values(sInsert);
  --commit;
  DELETE TMP_IESFURN;
  LIST_EXECUTE_IMMEDIATE(sInstmp, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_IESFURN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0375ACC6F38E1CB87394F0D2C764E55412EDEA43</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iesgest IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vToateGest   BOOLEAN         := PKG_LIST_SELECTGEST.ToateGest;
  vDataIni     DATE            := PKG_LIST_SELECTGEST.DataIni;
  vDataFin     DATE            := PKG_LIST_SELECTGEST.DataFin;
  vCateGest    INTEGER;
  vCateLGest   INTEGER;
BEGIN

  sInsert:=
   &apos;INSERT INTO &apos;|| tmpName ||&apos; ( Gest, DocIes, Val, ValCuTva, Operat )
    WITH SINTEZA AS (
      SELECT I.CODIES, N.GEST, SUM((L1.CANT * I1.PU) * NVL(I1.COEFDISCMAJ,1)) VAL, SUM(DECODE(I1.CANT,0,0,L1.CANT/I1.CANT*I1.TVA)*NVL(I1.COEFDISCMAJ,1)) TVA
      FROM IESIRI1 I1
           INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
           INNER JOIN LIVR1 L1 ON L1.CODIES1 = I1.CODIES1
           INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
           INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      WHERE I.ANULAT = 0 AND I.BLOCAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      sInsert := sInsert ||&apos;
      AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      sInsert := sInsert ||&apos;
      AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      sInsert := sInsert ||&apos;
      AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR
           EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
    end if;
  end if;
  sInsert:= sInsert||&apos;
      AND I.DATADOC BETWEEN :1 AND :2
      GROUP BY I.CODIES, N.GEST)
    SELECT NG.DEN_GEST, (I.PREFIXDOC||&apos;&apos;/&apos;&apos;||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)), S.VAL, S.VAL + S.TVA, DECODE(I.OPERAT,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;)
    FROM SINTEZA S
         INNER JOIN IESIRI I ON I.CODIES = S.CODIES
         INNER JOIN NGEST NG ON NG.CODGEST = S.GEST &apos;;

  pkg_globals.CheckDebugMode(sInsert, aListID, aListVer);
  EXECUTE IMMEDIATE sInsert USING vDataIni, vDataFin;
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_IESGEST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4E52D2DB2D54196F9A12CA52BA485C79E3143AC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IESIRI IS
  vFiltru     VARCHAR2(1000):=&apos;&apos;;
  vFiltruData VARCHAR2(1000):=&apos;&apos;;
  vUm         NUMBER(1);
  vLista      NUMBER(1);
  sCursRef    VARCHAR2(500);
	sCursPrest  VARCHAR2(500);

  xCodIes     NUMBER;
  xCoef       NUMBER;

  CT_UM_ART   CONSTANT NUMBER := 1;
  CT_IESIRI   CONSTANT NUMBER := 2;
  CT_IES_SINT CONSTANT NUMBER := 3;

  LST_SIMPL   NUMBER(1) := 0;

  gSuplCols   VARCHAR2(10000);
  gSuplJoins  VARCHAR2(10000);

function GetTop30(aCodAgent in number) return varchar2 is
sInsert CLOB;
sRez varchar2(3000);
pToateArt BOOLEAN       := PKG_LIST_SELINTIES.ToateArt;
pDupaData BOOLEAN       := PKG_LIST_SELINTIES.DupaData;
sData     VARCHAR2(500) := PKG_LIST_SELINTIES.Perioada;
pLista    NUMBER        := PKG_LIST_SELINTIES.Lista;
pUM       NUMBER        := PKG_LIST_SELINTIES.Um;
pInclNeop BOOLEAN       := PKG_LIST_SELINTIES.Extra1;
begin
  --return &apos;&apos;;
  vFiltru := &apos;
  WHERE i.anulat = 0 &apos;;
  IF NOT pInclNeop THEN
    vFiltru := vFiltru||&apos;AND i.operat = 1 &apos;;
  END IF;
  IF vLista &lt;&gt; CT_IES_SINT THEN
    vFiltru := vFiltru||&apos;
    AND i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;,&apos;&apos;R&apos;&apos;)&apos;;
  END IF;

  IF vLista &lt;&gt; CT_IES_SINT AND LST_SIMPL = 0 THEN
    vFiltru := vFiltru||&apos;
    AND CASE WHEN ae.initializari = 1 THEN 0 WHEN Coalesce(i.operat,0) = 1 AND Coalesce(i.infocm,0) = 0 AND i1.tiplinie = &apos;&apos;=&apos;&apos; THEN l.codlivr ELSE 0 END = CASE WHEN ae.initializari = 1 THEN 0 WHEN Coalesce(i.operat,0) = 1 AND Coalesce(i.infocm,0) = 0 AND i1.tiplinie = &apos;&apos;=&apos;&apos; THEN l1.codlivr ELSE 0 END&apos;;
  END IF;
  vFiltru := vFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;);
  vFiltru := vFiltru||&apos;
    AND Coalesce(i.initializari,0) = 0 &apos;;
  if pDupaData
  then vFiltruData := &apos;AND i.datadoc &apos; || sData||&apos; &apos;;
  else vFiltruData := &apos;AND (i.luna + i.an * 12) &apos; || sData||&apos; &apos;;
  end if;

  vFiltru := vFiltru||&apos;
    AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; )
    &apos;||vFiltruData;
  IF NOT pToateArt THEN
    vFiltru := vFiltru||&apos;
    AND I1.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;
  vFiltru := vFiltru||&apos; AND I.AGENT = &apos;||to_char(aCodAgent);

  sInsert := &apos;
  select stragg3200(partener||&apos;&apos;(&apos;&apos;||cant||&apos;&apos;)&apos;&apos;)
  from
  (
  select cant, partener
  FROM (
    SELECT sum(i1.cant) cant, p.den_part partener
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies    = i.codies
      inner join livr    l    on i.codies     = l.codies
      inner join livr1   l1   on l1.codlivr   = l.codlivr and l1.codies1 = i1.codies1
      LEFT  JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      LEFT  JOIN iesiri1 ae1  ON ae1.codies1  = ilae.codlinieaviz
      LEFT  JOIN iesiri  ae   ON ae.codies    = ae1.codies
      LEFT  JOIN NPART   P    ON I.PARTENER   = P.CODPART &apos;||
    vFiltru||&apos;
    GROUP BY P.DEN_PART
  )
  order by cant desc
  fetch first 30 rows only
  )&apos;;

  execute immediate sInsert into sRez;
  return sRez;
end;

PROCEDURE setSimpl IS
BEGIN
  LST_SIMPL := 1;
END;

PROCEDURE unsetSimpl IS
BEGIN
  LST_SIMPL := 0;
END;

PROCEDURE setVar IS
  pToateArt BOOLEAN       := PKG_LIST_SELINTIES.ToateArt;
  pDupaData BOOLEAN       := PKG_LIST_SELINTIES.DupaData;
  sData     VARCHAR2(500) := PKG_LIST_SELINTIES.Perioada;
  pLista    NUMBER        := PKG_LIST_SELINTIES.Lista;
  pUM       NUMBER        := PKG_LIST_SELINTIES.Um;
  pInclNeop BOOLEAN       := PKG_LIST_SELINTIES.Extra1;
  aSitV     NUMBER(1);
  aBancaV   NUMBER(20);
  aMonedaV  NUMBER(20);

  TYPE        t_tab_codies IS TABLE OF NUMBER(20);
  bulk_codies t_tab_codies;
  sIesDisc    CLOB;
BEGIN
  vUm    := pUm;
  vLista := pLista;
  vFiltru := &apos;
  WHERE i.anulat = 0 &apos;;
  IF NOT pInclNeop THEN
    vFiltru := vFiltru||&apos;AND i.operat = 1 &apos;;
  END IF;
  IF vLista &lt;&gt; CT_IES_SINT THEN
    vFiltru := vFiltru||&apos;
    AND i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;,&apos;&apos;R&apos;&apos;)&apos;;
  END IF;

  IF vLista &lt;&gt; CT_IES_SINT AND LST_SIMPL = 0 THEN
    vFiltru := vFiltru||&apos;
    AND CASE WHEN ae.initializari = 1 THEN 0 WHEN Coalesce(i.operat,0) = 1 AND Coalesce(i.infocm,0) = 0 AND i1.tiplinie = &apos;&apos;=&apos;&apos; THEN l.codlivr ELSE 0 END = CASE WHEN ae.initializari = 1 THEN 0 WHEN Coalesce(i.operat,0) = 1 AND Coalesce(i.infocm,0) = 0 AND i1.tiplinie = &apos;&apos;=&apos;&apos; THEN l1.codlivr ELSE 0 END&apos;;
  END IF;
  vFiltru := vFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;);
  vFiltru := vFiltru||&apos;
    AND Coalesce(i.initializari,0) = 0 &apos;;
  if pDupaData
  then vFiltruData := &apos;AND i.datadoc &apos; || sData||&apos; &apos;;
  else vFiltruData := &apos;AND (i.luna + i.an * 12) &apos; || sData||&apos; &apos;;
  end if;

  vFiltru := vFiltru||&apos;
    AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; )
    &apos;||vFiltruData;
  IF NOT pToateArt THEN
    vFiltru := vFiltru||&apos;
    AND I1.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCursRef   := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, ies.datadoc ) CURS_REF&apos;;
	  sCursPrest := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(NAO1.CODMONEDA,&apos;||aBancaV||&apos;, ies.datadoc ) CURS_PREST&apos;;
  ELSE
    sCursRef   := &apos;, 1&apos;;
	  sCursPrest := &apos;, 1&apos;;
  END IF;

  sIesDisc :=
    &apos;SELECT DISTINCT i.codies
    FROM iesiri i
    WHERE i.anulat = 0 AND i.anulat = 1 &apos;||vFiltruData||&apos;
      AND BITAND(i.Flags, 1) = 0
      AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; )&apos;;
  EXECUTE IMMEDIATE sIesDisc BULK COLLECT INTO bulk_codies;
  FOR i IN 1..bulk_codies.Count LOOP
    PKG_IESIRI.SetValFin(bulk_codies(i), 0);
  END LOOP;
  COMMIT;
  bulk_codies := t_tab_codies();
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  sInsert CLOB;
BEGIN
  -- folosita la IESIRISINTEZA
  DELETE tmp_dinamic_cols;
  setVar;
  sInsert := &apos;
  INSERT INTO tmp_dinamic_cols(fieldname,display,indexlocal, cod)
  SELECT &apos;&apos;D&apos;&apos;||rownum, &apos;&apos;Disc.&apos;&apos;||dencriteriu, rownum, codcriteriu
  FROM (
    SELECT DISTINCT cd.codcriteriu, cd.dencriteriu
    FROM iesiri i
      INNER JOIN iesiri1      i1 ON i1.codies = i.codies
      INNER JOIN criteriidisc cd ON cd.codcriteriu = i1.codcriteriu&apos;||
    vFiltru||&apos;
    ORDER BY cd.codcriteriu
  )&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  COMMIT;
END;

FUNCTION CALCPIES (pCodIes IN NUMBER, pTipDoc IN NUMBER, pCant IN NUMBER, pPU IN NUMBER, pTVA IN NUMBER, pADDim IN NUMBER, pCoefDiscMaj IN NUMBER, pValDiscPret IN NUMBER, pInclTVA IN NUMBER DEFAULT 0)
RETURN NUMBER IS
pIes NUMBER;
vCoef number(20,7);
BEGIN
  IF pCoefDiscmaj IS NULL -- atentie ca zero e posibil daca avem PrcoDisc -100
  THEN vCoef := 1;
  ELSE vCoef := pCoefDiscmaj;
  END IF;

  IF pADDim = -100 THEN
    pIes := 0;
  ELSE
    pIes := pPU/(1+Coalesce(pADDim/100,0)) * vCoef;
    IF Coalesce(pValDiscPret,0) &lt;&gt; 0 AND Coalesce(pCant,0) &lt;&gt; 0 THEN
      pIes := pIes - Coalesce(pValDiscPret,0)/pCant;
    END IF;
    IF pTipDoc IN (16,21) AND Coalesce(pCant*pPU,0) &lt;&gt; 0 AND (pInclTVA=0) THEN
      pIes := pIes * (1-pTva/(pCant*pPU));
    END IF;
    IF pTipDoc NOT IN (16,21) AND Coalesce(pCant*pPU,0) &lt;&gt; 0 AND (pInclTVA=1) THEN
      pIes := pIes * (1+pTva/(pCant*pPU));
    END IF;
  END IF;
  RETURN pIes;
END;

PROCEDURE INSERTSINTEZA(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pSuplJoins IN VARCHAR2) IS
  sInsert     CLOB;
  sWithGest   VARCHAR2(20000);
  sInsDC      VARCHAR2(20000);
  sSelDC      VARCHAR2(20000);
  sColDc      VARCHAR2(20000);
  sSold       VARCHAR2( 1000)  := &apos;, 0 sold&apos;;
BEGIN
  pkg_globals.SetSeparator(&apos;,&apos;);
  IF PKG_LIST_SELINTIES.Extra2 THEN -- rest sold
    sSold := &apos;,
    CASE
      WHEN ies.operat = 0 THEN 0
      WHEN ies.valdoc = 0 THEN 0
      ELSE (
        SELECT Sum(Coalesce(ol.rest,o.rest))
        FROM general g
          INNER JOIN obligpif o  ON o.codgeneral       = g.codgeneral
          LEFT  JOIN obligpif ol ON ol.codobligasociat = o.codobligpif AND ol.semnificatie = 1303
        WHERE g.tipdoc = ies.tipdoc AND g.coddoc = ies.codies AND g.semnificatie = 200 )
    END sold&apos;;
  END IF;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols)
  LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, I1.&apos;||vRec.FIELDNAME;
    sColDC := sColDC||&apos;,
      SUM(DECODE(cd.codcriteriu,&apos;||vRec.COD||&apos;,i1.restfact,0)) &apos;||vRec.FIELDNAME;
  END LOOP;

  IF PKG_LIST_SELINTIES.Extra3 THEN
    sWithGest := &apos;,
    G AS (SELECT
      i.codies,
      vc2_nt_to_string(CAST(collect(g.den_gest ORDER BY g.den_gest) AS vc2_nt)) den_gest,
      vc2_nt_to_string(CAST(collect(g.simbol ORDER BY g.simbol) AS vc2_nt)) simb_gest
    FROM (
      SELECT distinct i.codies, COALESCE(lv.gest,n.gest,ae1.gestact,i1.gestact) codgest
      FROM iesiri i
        INNER JOIN iesiri1 i1   ON i1.codies     = i.codies
        LEFT  JOIN ieslink ilae ON ilae.codies1  = i1.codies1
        LEFT  JOIN iesiri1 ae1  ON ae1.codies1   = ilae.codlinieaviz
        LEFT  JOIN livr    l    ON l.codies      = Coalesce(ae1.codies,i.codies)
        LEFT  JOIN livr1   l1   ON l1.codlivr    = l.codlivr AND l1.codies1 = Coalesce(ae1.codies1,i1.codies1)
        LEFT  JOIN livrval lv   ON lv.codlivr1   = l1.codlivr1
        LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
        LEFT  JOIN nir     n    ON n.codnir      = ns.codnir&apos;||
      vFiltru||&apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos;
    ) i LEFT JOIN ngest g ON g.codgest = i.codgest
    GROUP BY i.codies )&apos;;
  ELSE
    sWithGest := &apos;,
    G AS ( SELECT NULL codies, null den_gest,null simb_gest FROM dual)&apos;;
  END IF;

  sInsert := &apos;
  INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, X_CODSUBUNIT,X_CODCLASAP,X_JUDET,
    PARTENER,CODFISCAL,CODEXTERNP,CODINTERNP,DEN_CLASEP,
    TIPDOC,NRDOC,DATADOC,DENCARNET,SIMBCARNET,SERCARNET,
    MARFA,
    DISCMAJ,
    VALADDIM,
    EXCLTVA,TVADOC,VALDOC,OPERAT,BLOCAT,
    DEN_MONEDA, MON_TRANSF, CURS_DOC, CURS_TRANSF,
    DATASCAD,ZILESCAD,OBSDOC,
    ANDOC,LUNADOC,LUNA,
    TIPTVA,TIPTRANZ,TIPFACTURA,
    SSOC_DEN,SSOC_ADR,
    SSOC_LOC,SSOC_JUD,SSOC_TARA,SSOC_ZONA,
    SLIVR_TIP,SLIVR_DEN,SLIVR_ADR,
    SLIVR_LOC,SLIVR_JUD,SLIVR_TARA,SLIVR_ZONA,
    AGENT_IMPL,AGENT_DOC,DELEGAT,TRANSPORT,SUBUNITATE,
    LISTAT, LISTATCERTIF, CostTransport,
    CUICorect, GLIVR_DEN, GLIVR_SIMB, DISCONIV, DISCOFFIV,
    TARGETCLI,
    STARERESTIT,
    TIPPROMO, NRPROMO,
    DISCOFF2,
    DISCOFF3,
    IDDESCARCARE,IDINCARCARE,TIPSAFT,
    BancaCursPUV,MonedaFactinValuta,
    SOLD,
    CURS_REF &apos;||sInsDC||pUserFields||&apos;)
  WITH
    I1 AS (SELECT
      i.codies, i.tipdoc, MAX(p1.codpromo) codpromo,
      SUM(CASE WHEN i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) THEN i1.cant * i1.pu ELSE 0 END) val,
      SUM(CASE WHEN i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) THEN i1.cant * i1.pretorig*Coalesce(i1.addim/100,0) ELSE 0 END) valaddim,
      SUM(CASE WHEN i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) THEN Coalesce(i1.tva,0) ELSE 0 END) tva,
      SUM(CASE WHEN i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) THEN i1.costtransport ELSE 0 END) costtransport,
      SUM(CASE WHEN cd.codcriteriu IS NOT NULL AND Coalesce(cd.offinvoice,0) = 1 THEN i1.restfact ELSE 0 END) DOFFIV,
      SUM(CASE WHEN cd.codcriteriu IS NOT NULL AND Coalesce(cd.offinvoice,0) = 0 THEN i1.restfact ELSE 0 END) DONIV,
      ( SELECT MAX(o.termen)
        FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
        WHERE o.termen IS NOT NULL AND o.semnificatie = 200 AND g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      ) termen&apos;||sColDC||&apos;
    FROM iesiri i
      INNER JOIN iesiri1      i1  ON i1.codies      = i.codies
      LEFT  JOIN criteriidisc cd  ON cd.codcriteriu = i1.codcriteriu
      LEFT  JOIN promo1cadou  p1c ON p1c.codcadou   = i1.codcadou
      LEFT  JOIN promo1       p1  ON p1.codpromo1   = p1c.codpromo1&apos;||
    vFiltru||&apos;
    GROUP BY i.codies, i.tipdoc)&apos;||sWithGest||&apos;
  SELECT
    IES.CODIES, IES.TIPDOC, nsub.codsubunit, np.codclasa, JUDLIVR.simbauto,
    DECODE(ies.tipdoc,24,ng.den_gest,23,ns.DEN_SUBUNIT,np.den_part), fisc.codfiscal, np.codextern, np.codintern, ncp.den_clasep,
    pkg_list_base_utils.decode_tipdoc_scurt(ies.tipdoc), ies.nrdoc, ies.datadoc, dc.denumire, dc.simbol, dc.serie,
    CASE WHEN ies.tipdoc IN (16,21) THEN i1.val - Coalesce(i1.tva,0) ELSE i1.val END marfa,
    CASE WHEN ies.tipdoc IN (16,21) THEN (ies.valdoc - ies.tvadoc) - (i1.val - i1.tva) ELSE (ies.valdoc - ies.tvadoc) - i1.val END discmaj,
    i1.valaddim,
    ROUND(ies.valdoc - ies.tvadoc,2), ROUND(ies.tvadoc,2), ROUND(ies.valdoc,2), DECODE(Ies.OPERAT,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;), decode(ies.blocat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;),
    mon.simbol, mont.simbol, Coalesce(ies.curs,1), ies.cursdoc,
    i1.termen,Coalesce(i1.termen,ies.datadoc)-ies.datadoc, ies.obs,
    ies.an andoc, ies.luna lunadoc, to_char(ies.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(ies.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(ies.Luna) luna,
    CASE WHEN ies.tipdoc IN (16,23,24) THEN NULL ELSE
      DECODE(ies.tiptva,1,&apos;&apos;Taxare Normala&apos;&apos;,2,&apos;&apos;Taxare Inversa&apos;&apos;,3,&apos;&apos;Taxare Triunghiulara&apos;&apos;,4,&apos;&apos;Prestari in afara Romaniei&apos;&apos;,7,&apos;&apos;regim special(art.1521, 1522)&apos;&apos;,
             5,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;,6,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;) END,
    CASE WHEN ies.tipdoc IN (16,23,24) THEN NULL ELSE DECODE(ies.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Livrare intracomunitara&apos;&apos;,3,&apos;&apos;Export&apos;&apos;) END,
    CASE
      WHEN ies.infocm     = 1 THEN &apos;&apos;InfoCM&apos;&apos;
      WHEN ies.tipfactura = 8 THEN &apos;&apos;Nota cantar&apos;&apos;
      WHEN ies.tipfactura = 7 THEN &apos;&apos;Cu incasare imediata prin CM&apos;&apos;
      --WHEN ies.tipfactura = 6 THEN &apos;&apos;XX&apos;&apos;
      WHEN ies.tipfactura = 5 THEN &apos;&apos;Stingere nota credit&apos;&apos;
      WHEN ies.tipfactura = 4 THEN &apos;&apos;Service auto&apos;&apos;
      WHEN ies.tipfactura = 3 THEN &apos;&apos;Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 2 THEN &apos;&apos;Contract Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 1 THEN &apos;&apos;Abonament&apos;&apos;
      ELSE &apos;&apos;Normala&apos;&apos;
    END,
    ssoc.obs, getadresa(ssoc.sector, ssoc.strada, ssoc.nr1, ssoc.nr2, ssoc.bloc, ssoc.scara, ssoc.etaj, ssoc.apart, ssoc.codpostal),
    locsoc.den_localit, judsoc.den_judet, tarasoc.den_tara, zonasoc.den_zona,
    tipslivr.denumire , slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal),
    loclivr.den_localit, judlivr.den_judet, taralivr.den_tara, zonalivr.den_zona,
    ag_livr.nume||&apos;&apos; &apos;&apos;||ag_livr.prenume, ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume, nptr.delegat, ies.mijltransp||&apos;&apos; &apos;&apos;||ies.nrtransp, nsub.den_subunit,
    DECODE(ies.listat,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), DECODE(ies.listatcertif,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), I1.CostTransport,
    DECODE(cif_valid(FISC.CodFiscal),0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), g.den_gest, g.simb_gest, i1.doniv, i1.doffiv,
    (SELECT SUM(Coalesce(T1.VALOARE,0))
     FROM TARGETAG T
       INNER JOIN TARGETAG1 T1 ON T1.CODTARGETAG = T.CODTARGETAG
     WHERE T.TIPDOC = 65
       AND T.TIPTARGET = 1
       AND T.ANULAT = 0 AND T.OPERAT = 1 AND T.ACTIV = 1
       AND T.SUBUNITATEA = IES.SUBUNITATEA
       AND T.CLIENT = IES.PARTENER
       AND T.DATASTART &lt;= IES.DATADOC
       AND T.DATASTOP  &gt;= IES.DATADOC
    ) VALTARGET,
    CASE
      WHEN ies.tipdoc = 16 THEN NULL
      WHEN ies.starerestituire = 0 THEN &apos;&apos;Exemplar 2 nerestituit&apos;&apos;
      WHEN ies.starerestituire = 1 THEN &apos;&apos;Exemplar 2 restituit nestampilat&apos;&apos;
      WHEN ies.starerestituire = 2 THEN &apos;&apos;Exemplar 2 restituit stampilat&apos;&apos;
      WHEN ies.starerestituire = 3 THEN &apos;&apos;Livrare curier&apos;&apos;
      ELSE NULL
    END,
    DECODE(p.tippromotie, 1, &apos;&apos;marime pret&apos;&apos;, 2,  &apos;&apos;% discount&apos;&apos;, 3, &apos;&apos;articole promotionale (cadou)&apos;&apos;), p.nrdoc,
    (
      SELECT Coalesce(SUM(CASE WHEN Coalesce(x.codobiect,0) = 0 THEN (ies.valdoc-ies.tvadoc) ELSE i1.pretorig*i1.cant*Coalesce(i1.CoefDiscmaj,1) END*X.PROCENT/100),0)
      FROM IesDisc x LEFT JOIN iesiri1 i1 ON i1.codies = x.codies and i1.codobiect = Coalesce(x.codobiect,0)
      WHERE x.codies = ies.codies AND x.offinvoice = 2
    ) DISCOFF2,
    (
      SELECT Coalesce(SUM(CASE WHEN Coalesce(x.codobiect,0) = 0 THEN (ies.valdoc-ies.tvadoc) ELSE i1.pretorig*i1.cant*Coalesce(i1.CoefDiscmaj,1) END*X.PROCENT/100),0)
      FROM IesDisc x LEFT JOIN iesiri1 i1 ON i1.codies = x.codies and i1.codobiect = Coalesce(x.codobiect,0)
      WHERE x.codies = ies.codies AND x.offinvoice = 3
    ) DISCOFF3,
    DECL.IDDESCARCARE,DECL.IDINCARCARE,case when coalesce(IES.TIPSAFT,0) = 0 THEN &apos;&apos;380&apos;&apos; when coalesce(IES.TIPSAFT,0) = 1 THEN &apos;&apos;381&apos;&apos; when coalesce(IES.TIPSAFT,0) = 2 THEN &apos;&apos;384&apos;&apos; when coalesce(IES.TIPSAFT,0) = 3 THEN &apos;&apos;389&apos;&apos; when coalesce(IES.TIPSAFT,0) = 5 THEN &apos;&apos;751&apos;&apos; END,
    pkg_list_base_utils.GET_Den_BancaCursPUV(IES.An, IES.Luna), pkg_list_base_utils.GET_Simb_MonedaFactInValuta(IES.An, IES.Luna)&apos;||
    sSold||sCursRef||sSelDC||pUserAlias||&apos;
  FROM i1
    LEFT JOIN IESIRI         IES        ON IES.CodIes           = i1.codies
    LEFT JOIN                g          ON g.codies             = i1.codies
    LEFT JOIN tmp_utilizator UTILIZATOR on utilizator.codutilizator = IES.userid
    LEFT JOIN NPART          NP         ON np.codpart           = ies.partener
    LEFT JOIN NPARTCODFISC   FISC       ON fisc.codpart         = ies.partener AND fisc.principal = 1
    LEFT JOIN NCLASEP        NCP        ON ncp.codclasep        = np.codclasa
    LEFT JOIN NGEST          NG         ON ng.codgest           = ies.codgestprod
    LEFT JOIN NSUBUNIT       NS         ON ns.codsubunit        = ies.codsubunit
    LEFT JOIN DOCCARNETE     DC         ON dc.codcarnet         = ies.carnetdoc
    LEFT JOIN NMONEDE        MON        ON mon.codmoneda        = ies.moneda
    LEFT JOIN NMONEDE        MONT       ON mont.codmoneda       = ies.monedatransf
    LEFT JOIN NAGENDA        SSOC       ON ssoc.codpart         = ies.partener AND ssoc.SEDIUSOCIAL between 4 and 7 AND Coalesce(ssoc.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT       LOCSOC     ON locsoc.codlocalit    = ssoc.codlocalit
    LEFT JOIN NJUDET         JUDSOC     ON judsoc.codjudet      = locsoc.codjudet
    LEFT JOIN NZONE          ZONASOC    ON zonasoc.codzona      = locsoc.codzona
    LEFT JOIN NTARI          TARASOC    ON tarasoc.codtara      = locsoc.codtara
    LEFT JOIN NAGENDA        SLIVR      ON slivr.codagenda      = ies.codlocatie
    LEFT JOIN NLOCALIT       LOClivr    ON loclivr.codlocalit   = slivr.codlocalit
    LEFT JOIN NJUDET         JUDlivr    ON judlivr.codjudet     = loclivr.codjudet
    LEFT JOIN NZONE          ZONAlivr   ON zonalivr.codzona     = loclivr.codzona
    LEFT JOIN NTARI          TARAlivr   ON taralivr.codtara     = loclivr.codtara
    LEFT JOIN TRASEULIVR     Tlivr      ON tlivr.codtraseulivr  = slivr.codtraseu
    LEFT JOIN NTIPSEDII      TipSlivr   ON tipslivr.codtipsediu = slivr.codtipsediu
    LEFT JOIN NSUBUNIT       NSUB       ON nsub.codsubunit      = ies.subunitatea
    LEFT JOIN NPERS          AG_DOC     ON ag_doc.codpers       = ies.agent
    LEFT JOIN NPERS          AG_LIVR    ON ag_livr.codpers      = slivr.codagent
    LEFT JOIN NPARTTR        NPTR       ON nptr.codparttr       = ies.delegat
    LEFT JOIN PROMO          P          ON p.codpromo           = i1.codpromo
    LEFT JOIN NPART          COMIS      ON comis.codpart        = ies.partcustodie
    LEFT JOIN STATUSDECL     DECL       ON DECL.CODDOC          = ies.CODIES AND DECL.TIPDOC = IES.TIPDOC &apos;||
    pSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  COMMIT;
END;

FUNCTION  Sql_tmp_lst_iessimpl (pFiltru IN VARCHAR2, pInclCodIOPART1 IN NUMBER DEFAULT 0, pInclCodContr1 IN NUMBER DEFAULT 0) RETURN CLOB IS
  sCodIOPart1 VARCHAR2(  500)  := &apos;NULL&apos;;
  sCodContr1  VARCHAR2(  500)  := &apos;NULL&apos;;
BEGIN
  IF pInclCodIOPART1 &gt; 0 THEN
    sCodIOPart1 := &apos;(
      SELECT y.codiopart1
      FROM npart1 x INNER JOIN iopart1 y ON y.codiopart = x.codiopart
      WHERE x.codpart = i.partener
        AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop
        AND (i.an*12+i.luna) BETWEEN y.ALStart and y.ALStop
    )&apos;;
  END IF;

  IF pInclCodContr1 &gt; 0 THEN
    sCodContr1 := &apos;COALESCE(ae1.codcontract1, i1.codcontract1, CASE WHEN Coalesce(ae.CodContract,i.codcontract,0) &gt; 0 THEN (SELECT Min(X.CodContract1) FROM Contract1 X WHERE X.CodContract = Coalesce(ae.CodContract,i.codcontract,0) AND X.CodObiect = i1.CodObiect) ELSE 0 END)&apos;;
  END IF;

  RETURN
  &apos;INSERT INTO tmp_lst_iessimpl (
    codies, tipdoc, coefdiscmaj,
    delegat, codlocatie,
    codliniecomanda, codliniecomandacc, codliniecomandadl,
    transport,
    codies1, indexlocal, tiplinie, codobiect, codobiectorig, denobiectorig, umsec, gestact, contserv, obsart,
    pu, addim,
    pies,
    coef_tva,
    tvalin, tvau,
    cant, tipart, garantie, costtransport, cadou, codcadou, codae,
    codobiect1,
    termen,
    codiopart1,
    codpromo,
    codagentemulare, tipdocimp, codliniedocimp, codcentru, codanalizanod, codoferta1, codies1storno,
    codcontract1)
  SELECT
    i.codies, i.tipdoc, i1.coefdiscmaj,
    Coalesce(ae.delegat,i.delegat) delegat, Coalesce(ae.codlocatie, i.codlocatie) codlocatie,
    ilcom.codliniecomanda, CASE WHEN clc.codcomanda1 IS NOT NULL THEN clc.codliniecomanda WHEN i.tipdoc IN (23,24) THEN cl.codliniecomanda ELSE ilcom.codliniecomanda END codliniecomandac, clc.codcomanda1 codliniecomandadl,
    CASE WHEN AE.CODIES IS NOT NULL THEN ae.mijltransp||&apos;&apos; &apos;&apos;||ae.nrtransp ELSE i.mijltransp||&apos;&apos; &apos;&apos;||i.nrtransp END transport,
    i1.codies1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.codobiectorig, oo.denumire denobiectorig, i1.umsec, i1.gestact, coalesce(i1.contserv,0), i1.obs obsart,
    (CASE WHEN i.tipdoc IN (16,21) THEN i1.pu - Decode(i1.cant,0,0,Coalesce(i1.tva,0)/i1.cant) ELSE i1.pu END) pu, i1.addim,
    CASE
      WHEN i.tipdoc = 16
      THEN (Coalesce(I1.VALFIN,I1.CANT*I1.PU,0) - Coalesce(I1.TVAFIN,I1.TVA,0))/ Coalesce(NULLIF(i1.cant,0),1)
      ELSE PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret)
    END pies,
    ROUND(CASE
      WHEN Coalesce(i1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = Coalesce(i1.tva,0) THEN 0
      WHEN i.tipdoc IN (16,21) THEN Coalesce(i1.tva,0) / decode(  (i1.pu * i1.cant-Coalesce(i1.tva,0)),0,1,(i1.pu * i1.cant-Coalesce(i1.tva,0))  )
      WHEN i1.pu * i1.cant = 0 THEN 0
      ELSE Coalesce(i1.tva,0) / decode ( (i1.pu * i1.cant),0,1,(i1.pu * i1.cant) )
    END,2) coef_tva,
    Coalesce(I1.TVAFIN,I1.TVA,0) tvalin, i1.tva tvau,
    i1.cant, DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,&apos;&apos;Stoc&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;Avans&apos;&apos;,&apos;&apos;Serviciu&apos;&apos;) tipart, i1.garantie, i1.costtransport,
    CASE WHEN COALESCE(i1.cadou,0) &gt; 0 THEN 1 ELSE 0 END,
    i1.codcadou, ae.codies codae,
    ( SELECT x.codobiect1 FROM nartobj1 x WHERE x.codobiect = i1.codobiect AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop) codobiect1,
    ( SELECT MAX(o.termen) FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral WHERE o.termen IS NOT NULL AND o.semnificatie = 200 AND g.coddoc = i.codies AND g.tipdoc = i.tipdoc ) termen,
    &apos;||sCodIOPart1||&apos; codiopart1,
    CASE WHEN Coalesce(p1c.codpromo,0) = 0 THEN p1.codpromo ELSE p1c.codpromo END codpromo,
    i1.codagentemulare, i1.tipdocimp, i1.codliniedocimp, i1.codcentru, i1.codanalizanod, Coalesce(ae1.codoferta1, i1.codoferta1) codoferta1, Coalesce(ae1.codies1storno, i1.codies1storno) codies1storno,
    &apos;||sCodContr1||&apos; codcontract1
  FROM iesiri i
    INNER JOIN iesiri1    i1    ON i1.codies       = i.codies
    LEFT JOIN ieslink     ilae  ON ilae.codies1    = i1.codies1
    LEFT JOIN iesiri1     ae1   ON ae1.codies1     = ilae.codlinieaviz
    LEFT JOIN iesiri      ae    ON ae.codies       = ae1.codies
    LEFT JOIN ieslink     ilcom ON ilcom.codies1   = Coalesce(ilae.codlinieaviz, i1.codies1)
    LEFT JOIN cmdlink     cl    ON cl.codcomanda1  = ilcom.codliniecomanda
    LEFT JOIN cmdlivrlink clc   ON clc.codcomanda1 = COALESCE(cl.codliniecomanda, ilcom.codliniecomanda)
    LEFT JOIN promo1cadou p1c   ON p1c.codcadou    = i1.codcadou
    LEFT JOIN promo1      p1    ON p1.codpromo1    = Coalesce(p1c.codpromo1,i1.codpromo1)
    LEFT JOIN nartobj     oo    ON oo.codobiect    = i1.codobiectorig &apos;||
  pFiltru;
END;

FUNCTION  Sql_tmp_lst_iesiri   (pFiltru IN VARCHAR2) RETURN CLOB IS
sRes CLOB;
BEGIN
  sRes :=
  &apos;INSERT INTO tmp_lst_iesiri (
    codies, tipdoc, curs, partener, pretorig,
    delegat, codlocatie, codliniecomanda,
    codliniecomandadl,
    codliniecomandacc,
    transport,
    codies1, indexlocal, tiplinie, codobiect, codobiectorig, denobiectorig, umsec, gestact, contserv, obsart, pumaximal,
    pu, addim,
    pies,
    coef_tva,
    tvalin, tvau,
    cant, cantlivr,
    tipart,
    valachiz,
    pumaxns,
    garantie,
    serii,
    tg,
    tipserie,
    cantum1, cantum2, costtransport,
    cadou, codcadou, codae,
    termen,
    codobiect1,
    codiopart1,
    codpromo,
    codioart,
    codioart1,
    codagentemulare, tipdocimp, codliniedocimp, codcentru, codanalizanod, codoferta1, codies1storno,
    codcontract1)
  SELECT
    i.codies, i.tipdoc, Coalesce(i.curs,1) curs, i.partener, i1.coefdiscmaj,
    Coalesce(ae.delegat,i.delegat) delegat, Coalesce(ae.codlocatie, i.codlocatie) codlocatie, ilcom.codliniecomanda, clc.codcomanda1 codliniecomandadl,
    CASE WHEN clc.codcomanda1 IS NOT NULL THEN clc.codliniecomanda WHEN i.tipdoc IN (23,24) THEN cl.codliniecomanda ELSE ilcom.codliniecomanda END codliniecomandacc,
    CASE WHEN AE.CODIES IS NOT NULL THEN ae.mijltransp||&apos;&apos; &apos;&apos;||ae.nrtransp ELSE i.mijltransp||&apos;&apos; &apos;&apos;||i.nrtransp END transport,
    i1.codies1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.codobiectorig, oo.denumire, i1.umsec, i1.gestact, coalesce(i1.contserv,0), i1.obs obsart, i1.pumaximal,
    (CASE WHEN i.tipdoc IN (16,21) THEN i1.pu - Decode(i1.cant,0,0,Coalesce(i1.tva,0)/i1.cant) ELSE i1.pu END) pu, i1.addim,
    CASE
      WHEN i.tipdoc = 16
      THEN (Coalesce(I1.VALFIN,I1.CANT*I1.PU,0) - Coalesce(I1.TVAFIN,I1.TVA,0))/ Coalesce(NULLIF(i1.cant,0),1)
      ELSE PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret)
    END pies,
    ROUND(CASE
      WHEN Coalesce(i1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = Coalesce(i1.tva,0) THEN 0
      WHEN i.tipdoc IN (16,21) THEN Coalesce(i1.tva,0) / decode(  (i1.pu * i1.cant-Coalesce(i1.tva,0)),0,1,(i1.pu * i1.cant-Coalesce(i1.tva,0))  )
      WHEN i1.pu * i1.cant = 0 THEN 0
      ELSE Coalesce(i1.tva,0) / decode ( (i1.pu * i1.cant),0,1,(i1.pu * i1.cant) )
    END,2) coef_tva,
    Coalesce(I1.TVAFIN,I1.TVA,0) tvalin, i1.tva tvau,
    i1.cant, CASE WHEN Coalesce(ae1.cant,i1.cant) = 0 THEN 0 ELSE CASE WHEN ae.initializari = 1 and ae.custodie = 1 THEN i1.cant ELSE SUM(Coalesce(l1.cant,0))*i1.cant/Coalesce(ae1.cant,i1.cant) END END cantlivr,
    DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,&apos;&apos;Stoc&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;Avans&apos;&apos;,&apos;&apos;Serviciu&apos;&apos;) tipart,
    CASE
      WHEN Coalesce(ae1.cant,i1.cant) = 0 THEN 0
      WHEN iesval.codies1 &gt; 0 AND ae.initializari = 1 and ae.custodie = 1 THEN iesval.val * i1.cant
      WHEN iesval.codies1 &gt; 0 THEN iesval.val * SUM(Coalesce(l1.cant,0))*i1.cant/Coalesce(ae1.cant,i1.cant)
      ELSE SUM(COALESCE(ns.pret - ns.adaos, lv.pretachiz, ae1.pucorelat, 0)* COALESCE(l1.cant,ae1.cant,0))*i1.cant/Coalesce(ae1.cant,i1.cant)
    END valachiz,
    MAX(Coalesce(ns.pumaximal,0)) pumaxns,
    i1.garantie,
    CASE MAX(Coalesce(ns.tipserie,0))
      WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))&apos;;
    IF PKG_LIST_SELINTIES.SERIIFARACANT THEN
      sRes := sRes||&apos;
      WHEN 2 THEN vc2_nt_to_vc3200(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))&apos;;
    ELSE
      sRes := sRes||&apos;
      WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))&apos;;
    END IF;
    sRes := sRes||&apos;
      ELSE NULL
    END SERII,
    vc2_nt_to_vc3200(CAST(collect(DISTINCT to_char(Coalesce(nser.tg,NS.TG))) AS vc2_nt)) tg,
    DECODE(MAX(Coalesce(ns.tipserie,0)),1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
    SUM(l1.cantum1) cantum1, SUM(l1.cantum2) cantum2, MAX(i1.costtransport) costtransport,
    CASE WHEN COALESCE(i1.cadou,0) &gt; 0 THEN 1 ELSE 0 END,
    i1.codcadou, ae.codies codae,
    ( SELECT MAX(o.termen)
      FROM general g INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      WHERE o.termen IS NOT NULL AND o.semnificatie = 200 AND g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    ) termen,
    ( SELECT x.codobiect1 FROM nartobj1 x WHERE x.codobiect = i1.codobiect AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop) codobiect1,
    ( SELECT y.codiopart1
      FROM npart1 x INNER JOIN iopart1 y ON y.codiopart = x.codiopart
      WHERE x.codpart = i.partener
        AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop
        AND (i.an*12+i.luna) BETWEEN y.ALStart and y.ALStop
    ) codiopart1,
    CASE WHEN Coalesce(p1c.codpromo,0) = 0 THEN p1.codpromo ELSE p1c.codpromo END codpromo,
    CASE
      WHEN ae.initializari = 1 and ae.custodie = 1 then ae1.CODIOARTCUST
      ELSE Coalesce(lv.codioart,ns.codioart)
    END codioart,
    CASE
      WHEN ae.initializari = 1 AND ae.custodie = 1
      THEN (SELECT x.codioart1 FROM ioart1 x WHERE x.codioart = ae1.codioartcust                  AND (ae.an*12+ae.luna + 1) BETWEEN x.ALStart and x.ALStop)
      ELSE (SELECT x.codioart1 FROM ioart1 x WHERE x.codioart = Coalesce(lv.codioart,ns.codioart) AND (i.an*12+i.luna)       BETWEEN x.ALStart and x.ALStop)
    END codioart1,
    i1.codagentemulare, i1.tipdocimp, i1.codliniedocimp, i1.codcentru, i1.codanalizanod, Coalesce(ae1.codoferta1, i1.codoferta1), Coalesce(ae1.codies1storno, i1.codies1storno),
    COALESCE(ae1.codcontract1, i1.codcontract1, DECODE(Coalesce(ae.CodContract,i.codcontract,0),0,0,(SELECT Min(X.CodContract1) FROM Contract1 X WHERE X.CodContract = Coalesce(ae.CodContract,i.codcontract,0) AND X.CodObiect = i1.CodObiect)))
  FROM iesiri i
    INNER JOIN iesiri1    i1    ON i1.codies    = i.codies
    LEFT JOIN ieslink     ilae  ON ilae.codies1 = i1.codies1
    LEFT JOIN iesiri1     ae1   ON ae1.codies1  = ilae.codlinieaviz
    LEFT JOIN iesiri      ae    ON ae.codies    = ae1.codies
    LEFT JOIN (
      SELECT SUM(I1.CANT * (NS.PRET - Coalesce(NS.ADAOS,0)))/SUM(i1.cant) VAL, II1.CODIES1
      FROM IESIRI1 I1
        INNER JOIN LIVR1      LL1 ON LL1.CODIES1    = I1.CODIES1
        INNER JOIN NIRSTOC    NS  ON LL1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN IESVALLINK IVL ON IVL.CODIES1    = I1.CODIES1
        INNER JOIN LIVR1      L1  ON IVL.CODLIVR1   = L1.CODLIVR1
        INNER JOIN IESIRI1    II1 ON L1.CODIES1     = II1.CODIES1
      GROUP BY II1.CODIES1
    ) IESVAL                    ON IESVAL.CODIES1  = I1.CODIES1
    LEFT JOIN livr        l     ON l.codies        = Coalesce(ae.codies,i.codies) AND l.tiplivr = Coalesce(ae.tipdoc,i.tipdoc)
    LEFT JOIN livr1       l1    ON l1.codies1      = Coalesce(ae1.codies1,i1.codies1) AND l1.codlivr = l.codlivr AND l1.cant &lt;&gt; 0
    LEFT JOIN livrval     lv    ON lv.codlivr1     = l1.codlivr1
    LEFT JOIN nirstoc     ns    ON ns.codnirstoc   = l1.codnirstoc
    LEFT JOIN nir         n     ON n.codnir        = ns.codnir
    LEFT JOIN ieslink     ilcom ON ilcom.codies1   = Coalesce(ilae.codlinieaviz, i1.codies1)
    LEFT JOIN cmdlink     cl    ON cl.codcomanda1  = ilcom.codliniecomanda
    LEFT JOIN cmdlivrlink clc   ON clc.codcomanda1 = COALESCE(cl.codliniecomanda, ilcom.codliniecomanda)
    LEFT JOIN nirser      nser  ON nser.codnirser  = l1.codnirser
    LEFT JOIN nserii      s     on s.codserie      = nser.codserie
    LEFT JOIN promo1cadou p1c   ON p1c.codcadou    = i1.codcadou
    LEFT JOIN promo1      p1    ON p1.codpromo1    = Coalesce(p1c.codpromo1,i1.codpromo1)
    LEFT JOIN nartobj     oo    ON oo.codobiect    = i1.codobiectorig &apos;||
  pFiltru||&apos;
  GROUP BY
    i.codies, i.tipdoc, i.partener, i.curs, i.delegat, i.mijltransp, i.nrtransp, i.codlocatie, i.an, i.luna, i.valdoc, i.tvadoc, i.valdiscount, i.tvadiscount,
    i1.codies1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.codobiectorig, i1.umsec, i1.tva, i1.pretorig, i1.pu, i1.cant, i1.coefdiscmaj, i1.valdiscpret, 
    i1.codagentemulare,  i1.codies1storno, i1.garantie, i1.gestact, i1.addim, coalesce(i1.contserv,0), i1.obs, i1.pumaximal, i1.cadou, i1.codcadou, i1.tipdocimp,
    i1.codliniedocimp, i1.codcentru, i1.codanalizanod, i1.codoferta1, i1.codcontract1, i1.valfin, i1.tvafin,
    p1c.codpromo, p1.codpromo, ae.codies, ae.codlocatie, ae.delegat, ae.mijltransp, ae.nrtransp, ae1.cant, ae1.codoferta1, ae1.codcontract1, ae1.codies1storno,
    ilcom.codliniecomanda, cl.codliniecomanda, clc.codcomanda1, clc.codliniecomanda,
    oo.denumire, Coalesce(lv.codioart,ns.codioart), ae.initializari, ae.custodie, ae1.codioartcust,ae.luna,ae.an,ae.CodContract,i.codcontract,IESVAL.CODIES1,IESVAL.VAL&apos;;

  RETURN sRes;
END;

PROCEDURE INSERTIESSIMPL(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pSuplJoins IN VARCHAR2) IS
  sTruncTMP   CLOB;
  sInsertTMP  CLOB;
  sInsert     CLOB;
  sInsertDC   VARCHAR2( 5000);
  sSelectDC   VARCHAR2( 5000);
  sJoinDC     VARCHAR2( 5000);
  sJoinUM     VARCHAR2( 5000);
  sJoinCadou  VARCHAR2( 5000);
  sSold       VARCHAR2( 5000)  := &apos;, 0 sold&apos;;
  sDiscContr  VARCHAR2( 5000)  := &apos;, NULL contrpret, NULL ContrTermTip, NULL ContrTerm1, NULL ContrTerm2, NULL ContrTerm3, NULL ContrTerm1Disc, NULL ContrTerm2Disc, NULL ContrTerm3Disc, 0 contraddim, 0 contrpjdisc&apos;||
                                  &apos;, NULL contranexa, NULL contrdstart, NULL contrdstop, 0 disct, 0 discc, 0 discv, NULL ArtCadou, 0 CantCadou&apos;;
  sDiscNC     VARCHAR2( 5000)  := &apos;, 0 disctnc, 0 disccnc, 0 discvnc, NULL ArtCadouNC, NULL UMCadouNC, 0 CantCadouNC, 0 PretCadouNC&apos;;
  jDiscNC     VARCHAR2( 5000)  := &apos;&apos;;
  sArtAtrib1  VARCHAR2( 5000)  := &apos;, NULL ARTATRIB1&apos;;
  bOrdObiect  BOOLEAN;
BEGIN
  xCodies := 0;
  xCoef   := 1;
  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;i1.cant&apos;,&apos;i1.codobiect&apos;,sInsertDC,sSelectDC,sJoinDC,PKG_LIST_SELINTIES.Extra4);
  bOrdObiect := PKG_LIST_SELINTIES.Extra4 AND (sSelectDC IS NOT NULL);
  IF vUM = CT_UM_ART THEN
    sJoinUM := &apos;
    LEFT JOIN NUM1 UMSEC ON umsec.codum1 = i1.umsec
    LEFT JOIN NUM1 UM ON um.codum = umsec.codum AND um.secundara = 0&apos;;
  ELSE
    sJoinUM := &apos;
    LEFT JOIN NUM1 UM ON um.codum1 = i1.umsec&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra2 THEN -- rest sold
    sSold := &apos;,
    CASE
      WHEN ies.operat = 0 THEN 0
      WHEN ies.valdoc = 0 THEN 0
      WHEN i1.cant * i1.pies = 0 THEN 0
      ELSE Decode(i1.pu,i1.pies,i1.cant*(i1.pu+i1.tvalin/i1.cant),i1.cant*i1.pies*(1+i1.coef_tva)) / ies.valdoc * (
        SELECT Sum(Coalesce(ol.rest,o.rest))
        FROM general g
          INNER JOIN obligpif o  ON o.codgeneral = g.codgeneral
          LEFT  JOIN obligpif ol ON ol.codobligasociat = o.codobligpif AND ol.semnificatie = 1303
        WHERE g.tipdoc = ies.tipdoc AND g.coddoc = ies.codies AND g.semnificatie = 200 )
    END sold&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra3 THEN -- dicount conform contract
    PKG_CONTRACT.SIMULEAZA_DISCV(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);
    PKG_CONTRACT.SIMULEAZA_DISCC(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);
    PKG_CONTRACT.SIMULEAZA_CADOU(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);

    sDiscContr := &apos;,
    pkg_contract.GETPRET    (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrpret,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Tip     ContrTermTip,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen1 AS ContrTerm1,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen2 AS ContrTerm2,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen3 AS ContrTerm3,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc1   AS ContrTerm1Disc,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc2   AS ContrTerm2Disc,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc3   AS ContrTerm3Disc,
    pkg_contract.GETADDIM   (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contraddim,
    pkg_contract.GETPROCDISC(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrpjdisc,
    pkg_contract.GETC1ANEXA (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contranexa,
    pkg_contract.GETC1DSTART(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrdstart,
    pkg_contract.GETC1DSTOP (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrdstop,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN i1.pies = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.DISCMAXTERMEN(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc, I1.Cant, I1.PIes)
      ELSE 0
    END disct,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN (
        SELECT
          Coalesce(MAX(
            CASE
              WHEN T.DISCUNITAR &lt;&gt; 0 THEN i1.cant * t.discunitar
              ELSE i1.cant * i1.pies * t.pjdisc / 100
            END),0)
        FROM TMP_IESDISCC T
        WHERE T.PARTENER = Ies.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = Ies.CODLOCATIE)
          AND T.SUBUNITATEA = Ies.SUBUNITATEA
          AND T.CODOBIECT = I1.CODOBIECT
          AND T.DATASTART &lt;= Ies.DATADOC AND T.DATASTOP &gt;= Ies.DATADOC )
      ELSE 0
    END discc,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN i1.TipDoc IN (19,26)
      THEN (
        SELECT Coalesce(MAX(i1.cant * i1.pies *t.disc/t.baza),0)
        FROM TMP_IESDISCV T
        WHERE T.PARTENER = Ies.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = Ies.CODLOCATIE)
          AND T.SUBUNITATEA = Ies.SUBUNITATEA
          AND (T.CODOBIECT = 0 OR T.CODOBIECT = I1.CODOBIECT)
          AND T.DATASTART &lt;= Ies.DATADOC AND T.DATASTOP &gt;= Ies.DATADOC )
      ELSE 0
    END discv,
    CASE
      WHEN Ies.operat = 0 THEN NULL
      WHEN I1.Cant = 0    THEN NULL
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_DEN(2, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)
      ELSE NULL
    END ArtCadou,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_CANT(2, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc, I1.Cant)
      ELSE 0
    END CantCadou&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra4 THEN -- discount conform note credit
    sJoinCadou :=&apos;
    LEFT JOIN (
      SELECT
        i1.codies1, o.denumire dencadou, Sum(i1.cant) over (PARTITION BY ncc.codnccadouri) cantasoc,
        ncc.diferente/u1.paritate cantcadou, u1.den_um1 umcadou, pm.lei * u1.paritate pretcadou, Coalesce(u1.zecimale,7) zeccadou
      FROM NCCADOURI NCC
        INNER JOIN NOTECREDIT  NC  ON NC.CODNCREDIT  = NCC.CODNCREDIT
        INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NCC.CODNCREDIT
        INNER JOIN IESIRI1     I1  ON NC1.CODDOC     = I1.CodIes1 AND I1.CODOBIECT = NCC.CODOBIECTASOC
        INNER JOIN IESIRI      I   ON I.CODIES       = I1.CODIES  AND I.TIPDOC     = NC1.TIPDOC
        LEFT  JOIN NARTOBJ     O   ON O.CODOBIECT    = NCC.CODOBIECT
        LEFT  JOIN NUM1        U1  ON U1.CODUM1      = NCC.UMSEC
        LEFT  JOIN PRETM       PM  ON PM.CODOBIECT   = NCC.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = I.SUBUNITATEA
      WHERE NC.TIPDOC = 58
        AND NC1.TIPOPER = &apos;&apos;C&apos;&apos;
    ) Cad ON cad.codies1 = i1.codies1&apos;;

    sDiscNC := &apos;,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      ELSE Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;T&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
    END disctnc,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      ELSE Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;C&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
    END disccnc,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      WHEN i1.cant * i1.pies = 0     THEN 0
      WHEN ies.valdoc = 0            THEN 0
      WHEN ies.valdoc = ies.tvadoc   THEN 0
      ELSE Coalesce((
        SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
        WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; AND NC1.CODDOC = I1.CodIes  AND NC1.TIPDOC = I1.TipDoc ),0) * i1.cant * i1.pies / (ies.valdoc-ies.tvadoc)
    END discvnc,
    cad.dencadou, cad.umcadou,
    CASE
      WHEN Coalesce(cad.cantasoc,0) = 0 OR Coalesce(i1.cant,0) = 0 THEN 0
      WHEN i1.cant = cad.cantasoc THEN cad.cantcadou
      ELSE Round(cad.cantcadou*i1.cant/cad.cantasoc,cad.zeccadou)
    END CantCadouNC,
    cad.pretcadou&apos;;

    jDiscNC := &apos;
    LEFT JOIN NOTECREDITFACT ncf ON ncf.coddoc = ies.codies AND ncf.tipdoc = ies.tipdoc AND Coalesce(ncf.codncredit,0) &gt; 0&apos;;

  END IF;

  IF Coalesce(PKG_LIST_SELINTIES.Atrib1,0) &lt;&gt; 0 THEN
    sArtAtrib1 := &apos;,
    ( SELECT Min(aa1.valoare)
      FROM nartatr aa
        LEFT JOIN natrobj ao  ON ao.codartatr  = aa.codartatr
        LEFT JOIN natrib1 aa1 ON aa1.codvalatr = ao.codvalatr
      WHERE aa.codarticol = nao.codarticol AND ao.codobiect = nao.codobiect AND aa.codatribut = &apos;||Coalesce(PKG_LIST_SELINTIES.Atrib1,0)||&apos;
    ) ARTATRIB1&apos;;
  END IF;

  sTruncTMP  := &apos;TRUNCATE TABLE tmp_lst_iessimpl&apos;;
  sInsertTMP := Sql_tmp_lst_iessimpl(vFiltru, InStr(pSuplJoins,&apos;IOP1.CODIOPART1 = I1.CODIOPART1&apos;), InStr(pSuplJoins,&apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;));

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, X_CODSUBUNIT, X_CODCLASAP, X_JUDET,
    CODOBIECT,TIPART,DEN_ARTICOL,DEN_ORIGINAL,DEN_UM,CANT,
    DOCUMENT, MON_DOC, MON_TRANSF, CURS_DOC, CURS_TRANSF,
    PU,ADDIM,DISCUNIT,PUDISC,PROC_TVA,
    DISCTOTAL,DISCTOT_TVA,DISCTOTCUTVA,
    VALOARE,VAL_TVA,VALCUTVA,
    DEN_PART,
    TIPTVA, TIPTRANZ, TIPFACTURA,
    DATASCAD,ZILESCAD,TRANSPORT,
    ANDOC,LUNADOC,LUNA,
    SUBUNITATE, CostTransport, CUICorect,
    IndexLinie,DENCLASEAS,DenClasaA,SimbClasaA,ObsArt,
    GARANTIE, OPERAT, CADOU, TAXCODE_SAFT,
    TIPPROMO, NRPROMO, NRAE, ZILEDISCT, PROCDISCTOT,
    DISCOFF2,
    DISCOFF3,
    IDDESCARCARE,IDINCARCARE,TIPSAFT,
    ARTATRIB1,
    SOLD, CONTRPRET,
    ContrTermTip, ContrTerm1, ContrTerm2, ContrTerm3, ContrTerm1Disc, ContrTerm2Disc, ContrTerm3Disc,
    CONTRADDIM, CONTRPJDISC, CONTRANEXA, CONTRDSTART, CONTRDSTOP, DISCT, DISCC, DISCV, ARTCADOU, CANTCADOU, DISCTNC, DISCCNC, DISCVNC,
    ARTCADOUNC, UMCADOUNC, CANTCADOUNC, PRETCADOUNC,
    CURS_REF, CURS_PREST&apos;||sInsertDC||pUserFields||&apos;)
  SELECT
    i1.codies NAV_CodDoc, i1.tipdoc NAV_TipDoc, nsub.codsubunit, np.codclasa, JUDLIVR.simbauto,
    i1.CODOBIECT, i1.tipart, nao.denumire DEN_ARTICOL, i1.denobiectorig DEN_ORIGINAL, um.den_um1 DEN_UM, i1.cant/um.paritate cant,
    ies.prefixdoc||ies.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(ies.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) document, mon.den_moneda MON_DOC, mont.den_moneda MON_TRANSF, Coalesce(ies.curs,1) CURS_DOC, ies.cursdoc CURS_TRANSF,
    i1.pu * um.paritate PU, i1.addim, (i1.pies-i1.pu) * um.paritate DISCUNIT, i1.pies * um.paritate PUDISC, i1.coef_tva*100 PROC_TVA,
    i1.cant*(i1.pies - i1.pu) DISCTOTAL,
    DECODE(i1.tipdoc,16,i1.tvalin - i1.tvau, i1.cant*(i1.pies - i1.pu) * i1.coef_tva) DISCTOT_TVA,
    DECODE(i1.tipdoc,16,i1.cant*(i1.pies - i1.pu) + i1.tvalin - i1.tvau, i1.cant*(i1.pies - i1.pu) * (1+i1.coef_tva)) DISCTOTCUTVA,
    i1.cant * i1.pies VALOARE,
    CASE WHEN i1.tipdoc = 16 THEN i1.tvalin WHEN i1.pu = i1.pies THEN i1.tvalin ELSE i1.cant*i1.pies*i1.coef_tva END VAL_TVA,
    CASE WHEN i1.tipdoc = 16 THEN i1.cant*i1.pies+i1.tvalin WHEN i1.pu = i1.pies THEN i1.cant*i1.pies+i1.tvalin ELSE i1.cant*i1.pies*(1+i1.coef_tva) END VALCUTVA,
    DECODE(i1.tipdoc,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;Vanzari cu amanuntul&apos;&apos;,23,ns.den_subunit,24,ng.den_gest,np.den_part) DEN_PART,
    DECODE(ies.tiptva,1,&apos;&apos;Taxare Normala&apos;&apos;,2,&apos;&apos;Taxare Inversa&apos;&apos;,3,&apos;&apos;Taxare Triunghiulara&apos;&apos;,4,&apos;&apos;Prestari in afara Romaniei&apos;&apos;,7,&apos;&apos;regim special(art.1521, 1522)&apos;&apos;,
             5,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;,6,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;) TIPTVA,
    DECODE(ies.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Livrare intracomunitara&apos;&apos;,3,&apos;&apos;Export&apos;&apos;) TIPTRANZ,
    CASE
      WHEN ies.infocm = 1     THEN &apos;&apos;InfoCM&apos;&apos;
      WHEN ies.tipfactura = 8 THEN &apos;&apos;Nota cantar&apos;&apos;
      WHEN ies.tipfactura = 7 THEN &apos;&apos;Cu incasare imediata prin CM&apos;&apos;
      WHEN ies.tipfactura = 5 THEN &apos;&apos;Stingere nota credit&apos;&apos;
      WHEN ies.tipfactura = 4 THEN &apos;&apos;Service auto&apos;&apos;
      WHEN ies.tipfactura = 3 THEN &apos;&apos;Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 2 THEN &apos;&apos;Contract Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 1 THEN &apos;&apos;Abonament&apos;&apos;
      ELSE &apos;&apos;Normala&apos;&apos;
    END TIPFACTURA,
    i1.termen DATASCAD, CASE WHEN i1.termen IS NULL THEN 0 ELSE i1.termen - ies.datadoc END ZILESCAD, i1.transport,
    ies.an andoc, ies.luna lunadoc, to_char(ies.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(ies.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(ies.Luna) luna,
    nsub.den_subunit SUBUNITATE, I1.CostTransport, DECODE(cif_valid(FISC.CodFiscal),0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) CUICorect,
    I1.IndexLocal IndexLinie, cs.den_claseas DENCLASEAS, nca.den_clasea DenClasaA, nca.simbol SimbClasaA, i1.obsart,
    Decode(IES.TIPCONSUMATOR,2,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) GARANTIE, Decode(IES.OPERAT,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) OPERAT, Decode(I1.CADOU,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) CADOU, TXDCL.TAXCODE AS TAXCODE_SAFT,
    DECODE(p.tippromotie, 1, &apos;&apos;marime pret&apos;&apos;, 2,  &apos;&apos;% discount&apos;&apos;, 3, &apos;&apos;articole promotionale (cadou)&apos;&apos;) TIPPROMO, p.nrdoc NRPROMO, ae.nrdoc NRAE, null ziledisct, (i1.coefdiscmaj-1)*100 procdisctot,
    i1.pies*i1.cant*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 2 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF2,
    i1.pies*i1.cant*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 3 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF3,
    DECL.IDDESCARCARE,DECL.IDINCARCARE,case when coalesce(IES.TIPSAFT,0) = 0 THEN &apos;&apos;380&apos;&apos; when coalesce(IES.TIPSAFT,0) = 1 THEN &apos;&apos;381&apos;&apos; when coalesce(IES.TIPSAFT,0) = 2 THEN &apos;&apos;384&apos;&apos; when coalesce(IES.TIPSAFT,0) = 3 THEN &apos;&apos;389&apos;&apos; when coalesce(IES.TIPSAFT,0) = 5 THEN &apos;&apos;751&apos;&apos; END &apos;||
    sArtAtrib1||sSold||sDiscContr||sDiscNc||sCursRef||sCursPrest||sSelectDC||pUserAlias||&apos;
  FROM TMP_LST_IESSIMPL    I1
	  LEFT JOIN IESIRI       IES     ON ies.codies    = i1.codies
	  LEFT JOIN IESIRI       AE      ON ae.codies     = DECODE(i1.tipdoc,20,i1.codies,i1.codae)
    LEFT JOIN NARTOBJ      NAO     ON nao.codobiect = i1.codobiect
    LEFT JOIN NART         NA      ON na.codarticol = nao.codarticol
    LEFT JOIN NCLASEAS     CS      ON cs.codclaseas = na.clasastatist
    LEFT JOIN NCLASEA      NCA     ON nca.codclasea = na.clasa &apos;||
    sJoinUM||sJoinDC||sJoinCadou||&apos;
    LEFT JOIN NPART        NP      ON np.codpart         = ies.partener
    LEFT JOIN NPARTCODFISC FISC    ON fisc.codpart       = ies.partener AND fisc.principal = 1
    LEFT JOIN NGEST        NG      ON ng.codgest         = ies.codgestprod
    LEFT JOIN NSUBUNIT     NS      ON ns.codsubunit      = ies.codsubunit
    LEFT JOIN NSUBUNIT     NSUB    ON nsub.codsubunit    = ies.subunitatea
    LEFT JOIN NMONEDE      MON     ON mon.codmoneda      = ies.moneda
    LEFT JOIN NMONEDE      MONT    ON mont.codmoneda     = ies.monedatransf
    LEFT JOIN promo        p       ON p.codpromo         = i1.codpromo
    LEFT JOIN nartobj1     nao1    ON nao1.codobiect1    = i1.codobiect1
    LEFT JOIN NAGENDA      SLIVR   ON SLIVR.CODAGENDA    = I1.CODLOCATIE
    LEFT JOIN NLOCALIT     LOCLIVR ON LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT
    LEFT JOIN TAXDECL      TXDCL   ON TXDCL.TIPDOC = IES.TIPDOC AND TXDCL.CODDOC = IES.CODIES AND TXDCL.CODDOC1 = I1.CODIES1
    LEFT JOIN NJUDET       JUDLIVR ON JUDLIVR.CODJUDET   = LOCLIVR.CODJUDET
    LEFT JOIN STATUSDECL   DECL    ON DECL.CODDOC        = ies.CODIES AND DECL.TIPDOC = IES.TIPDOC &apos;||
    jDiscNC||
    pSuplJoins;

  IF bOrdObiect THEN
    sInsert := sInsert||&apos;
    ORDER BY i1.codobiect&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sTruncTmp , 0, 0);
  LIST_EXECUTE_IMMEDIATE(sInsertTmp, 0, 0);
  LIST_EXECUTE_IMMEDIATE(sInsert   , 0, 0);

  COMMIT;

END;

PROCEDURE INSERTIESIRI(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pSuplJoins IN VARCHAR2) IS
  sTruncTMP   CLOB;
  sInsertTMP  CLOB;
  sInsert     CLOB;
  sInsertDC   VARCHAR2( 5000);
  sSelectDC   VARCHAR2( 5000);
  sJoinDC     VARCHAR2( 5000);
  sJoinUM     VARCHAR2( 5000);
  sJoinCadou  VARCHAR2( 5000);
  sSold       VARCHAR2( 5000)  := &apos;, 0 sold&apos;;
  sDiscContr  VARCHAR2( 5000)  := &apos;, NULL contrpret, NULL ContrTermTip, NULL ContrTerm1, NULL ContrTerm2, NULL ContrTerm3, NULL ContrTerm1Disc, NULL ContrTerm2Disc, NULL ContrTerm3Disc, 0 contraddim, 0 contrpjdisc&apos;||
                                  &apos;, NULL contranexa, NULL contrdstart, NULL contrdstop, 0 disct, 0 discc, 0 discv, NULL ArtCadou, 0 CantCadou&apos;;
  sDiscNC     VARCHAR2( 5000)  := &apos;, 0 disctnc, 0 disccnc, 0 discvnc, NULL ArtCadouNC, NULL UMCadouNC, 0 CantCadouNC, 0 PretCadouNC&apos;;
  jDiscNC     VARCHAR2( 5000)  := &apos;&apos;;
  sArtAtrib1  VARCHAR2( 5000)  := &apos;, NULL ARTATRIB1&apos;;
  bOrdObiect  BOOLEAN;
BEGIN
-- stef 30.01.2011
-- pt aramis a trebuit sa fac niste compromisuri findca lista crapa cu ora-00600
-- teoretic ar trebuii facut un patch de baza de data dar am vazut ca daca reduc numarul de joinuri se rezolva ceva
-- din acest motiv daca calculez cadourile, iar selecturile pt. UMA le inlocuiesc cu functii

  xCodies := 0;
  xCoef   := 1;
  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;i1.cant&apos;,&apos;i1.codobiect&apos;,sInsertDC,sSelectDC,sJoinDC,PKG_LIST_SELINTIES.Extra4);
  bOrdObiect := PKG_LIST_SELINTIES.Extra4 AND (sSelectDC IS NOT NULL);
  IF vUM = CT_UM_ART THEN
    sJoinUM := &apos;
    LEFT JOIN NUM1 UMSEC ON umsec.codum1 = i1.umsec
    LEFT JOIN NUM1 UM    ON um.codum     = umsec.codum AND um.secundara = 0&apos;;
  ELSE
    sJoinUM := &apos;
    LEFT JOIN NUM1 UM ON um.codum1 = i1.umsec&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra2 THEN -- rest sold
    sSold := &apos;,
    CASE
      WHEN ies.operat = 0 THEN 0
      WHEN ies.valdoc = 0 THEN 0
      WHEN i1.cant * i1.pies = 0 THEN 0
      ELSE Decode(i1.pu,i1.pies,DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*(i1.pu+i1.tvalin/i1.cant),DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*i1.pies*(1+i1.coef_tva)) / ies.valdoc * (
        SELECT Sum(Coalesce(ol.rest,o.rest))
        FROM general g
          INNER JOIN obligpif o  ON o.codgeneral       = g.codgeneral
          LEFT  JOIN obligpif ol ON ol.codobligasociat = o.codobligpif AND ol.semnificatie = 1303
        WHERE g.tipdoc = ies.tipdoc AND g.coddoc = ies.codies AND g.semnificatie = 200 )
    END sold&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra3 THEN -- dicount conform contract
    PKG_CONTRACT.SIMULEAZA_DISCV(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);
    PKG_CONTRACT.SIMULEAZA_DISCC(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);
    PKG_CONTRACT.SIMULEAZA_CADOU(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,2);

    sDiscContr := &apos;,
    pkg_contract.GETPRET    (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrpret,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Tip     AS ContrTermTip,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen1 AS ContrTerm1,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen2 AS ContrTerm2,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Termen3 AS ContrTerm3,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc1   AS ContrTerm1Disc,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc2   AS ContrTerm2Disc,
    pkg_contract.GETTERMEN  (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc).Disc3   AS ContrTerm3Disc,
    pkg_contract.GETADDIM   (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contraddim,
    pkg_contract.GETPROCDISC(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrpjdisc,
    pkg_contract.GETC1ANEXA (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contranexa,
    pkg_contract.GETC1DSTART(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrdstart,
    pkg_contract.GETC1DSTOP (Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)         AS contrdstop,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN i1.pies = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.DISCMAXTERMEN(Ies.TipDoc, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc, I1.Cant, I1.PIes)
      ELSE 0
    END * CASE I1.Cant WHEN 0 THEN 1 ELSE I1.CantLivr / I1.Cant END disct,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN (
        SELECT
          Coalesce(MAX(
            CASE
              WHEN T.DISCUNITAR &lt;&gt; 0 THEN i1.cant * t.discunitar
              ELSE i1.cant * i1.pies * t.pjdisc / 100
            END),0)
        FROM TMP_IESDISCC T
        WHERE T.PARTENER = Ies.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = Ies.CODLOCATIE)
          AND T.SUBUNITATEA = Ies.SUBUNITATEA
          AND T.CODOBIECT = I1.CODOBIECT
          AND T.DATASTART &lt;= Ies.DATADOC AND T.DATASTOP &gt;= Ies.DATADOC )
      ELSE 0
    END * CASE I1.Cant WHEN 0 THEN 1 ELSE I1.CantLivr / I1.Cant END discc,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN i1.TipDoc IN (19,26)
      THEN (
        SELECT Coalesce(MAX(i1.cant * i1.pies *t.disc/t.baza),0)
        FROM TMP_IESDISCV T
        WHERE T.PARTENER = Ies.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = Ies.CODLOCATIE)
          AND T.SUBUNITATEA = Ies.SUBUNITATEA
          AND (T.CODOBIECT = 0 OR T.CODOBIECT = I1.CODOBIECT)
          AND T.DATASTART &lt;= Ies.DATADOC AND T.DATASTOP &gt;= Ies.DATADOC )
      ELSE 0
    END * CASE I1.Cant WHEN 0 THEN 1 ELSE I1.CantLivr / I1.Cant END discv,
    CASE
      WHEN Ies.operat = 0 THEN NULL
      WHEN I1.Cant = 0    THEN NULL
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_DEN(2, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc)
      ELSE NULL
    END ArtCadou,
    CASE
      WHEN Ies.operat = 0 THEN 0
      WHEN I1.Cant = 0    THEN 0
      WHEN Ies.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_CANT(2, I1.CodObiect, Ies.Partener, Ies.CodLocatie, Ies.Subunitatea, Ies.DataDoc, I1.Cant)
      ELSE 0
    END CantCadou&apos;;
  END IF;


  IF PKG_LIST_SELINTIES.Extra4 THEN -- dicount conform note credit
    sJoinCadou :=&apos;
    LEFT JOIN (
      SELECT
        i1.codies1, o.denumire dencadou, Sum(i1.cant) over (PARTITION BY ncc.codnccadouri) cantasoc,
        ncc.diferente/u1.paritate cantcadou, u1.den_um1 umcadou, pm.lei * u1.paritate pretcadou, Coalesce(u1.zecimale,7) zeccadou
      FROM NCCADOURI NCC
        INNER JOIN NOTECREDIT  NC  ON NC.CODNCREDIT  = NCC.CODNCREDIT
        INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NCC.CODNCREDIT
        INNER JOIN IESIRI1     I1  ON NC1.CODDOC     = I1.CodIes1 AND I1.CODOBIECT = NCC.CODOBIECTASOC
        INNER JOIN IESIRI      I   ON I.CODIES       = I1.CODIES AND I.TIPDOC = NC1.TIPDOC
        LEFT  JOIN NARTOBJ     O   ON O.CODOBIECT    = NCC.CODOBIECT
        LEFT  JOIN NUM1        U1  ON U1.CODUM1      = NCC.UMSEC
        LEFT  JOIN PRETM       PM  ON PM.CODOBIECT   = NCC.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = I.SUBUNITATEA
      WHERE NC.TIPDOC = 58
        AND NC1.TIPOPER = &apos;&apos;C&apos;&apos;
    ) Cad ON cad.codies1 = i1.codies1&apos;;

    sDiscNC := &apos;,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      ELSE Coalesce((SELECT SUM(NC1.VALOARE)
                     FROM NOTECREDIT NC
                          INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                     WHERE COALESCE(NC.CORECTIE,0) = 0 and NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;T&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
         + Coalesce((SELECT SUM(NC1.VALOARE - NC1.VALOAREOLD)
                     FROM NOTECREDIT NC
                          INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                     WHERE NC.CORECTIE = 1 AND NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;T&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
    END disctnc,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      ELSE Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;C&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
           + Coalesce((SELECT SUM(NC1.VALOARE - NC1.VALOAREOLD)
                     FROM NOTECREDIT NC
                          INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                     WHERE NC.CORECTIE = 1 AND NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;C&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I1.TipDoc ),0)
    END disccnc,
    CASE
      WHEN ncf.codncfact IS NOT NULL then 0
      WHEN i1.cant * i1.pies = 0 THEN 0
      WHEN ies.valdoc = 0 THEN 0
      WHEN ies.valdoc = ies.tvadoc THEN 0
      ELSE Coalesce((
        SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
        WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;V&apos;&apos; AND NC1.CODDOC = I1.CodIes  AND NC1.TIPDOC = I1.TipDoc ),0) * i1.cant * i1.pies / (ies.valdoc-ies.tvadoc)
    END discvnc,
    cad.dencadou, cad.umcadou,
    CASE
      WHEN Coalesce(cad.cantasoc,0) = 0 OR Coalesce(i1.cant,0) = 0 THEN 0
      WHEN i1.cant = cad.cantasoc THEN cad.cantcadou
      ELSE Round(cad.cantcadou*i1.cant/cad.cantasoc,cad.zeccadou)
    END CantCadouNC,
    cad.pretcadou&apos;;

    jDiscNC := &apos;
    LEFT JOIN NOTECREDITFACT ncf ON ncf.coddoc = ies.codies AND ncf.tipdoc = ies.tipdoc AND Coalesce(ncf.codncredit,0) &gt; 0&apos;;

  END IF;

  IF Coalesce(PKG_LIST_SELINTIES.Atrib1,0) &lt;&gt; 0 THEN
    sArtAtrib1 := &apos;,
    ( SELECT Min(aa1.valoare)
      FROM nartatr aa
        LEFT JOIN natrobj ao  ON ao.codartatr  = aa.codartatr
        LEFT JOIN natrib1 aa1 ON aa1.codvalatr = ao.codvalatr
      WHERE aa.codarticol = nao.codarticol AND ao.codobiect = nao.codobiect AND aa.codatribut = &apos;||Coalesce(PKG_LIST_SELINTIES.Atrib1,0)||&apos;
    ) ARTATRIB1&apos;;
  END IF;

  sTruncTMP  := &apos;TRUNCATE TABLE tmp_lst_iesiri&apos;;
  sInsertTMP := Sql_tmp_lst_iesiri(vFiltru);
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, X_CODSUBUNIT,X_CODCLASAP,X_JUDET,
    CODOBIECT,TIPART,DEN_ARTICOL,DEN_ORIGINAL,DEN_UM,CANT,DOCUMENT,
    MON_DOC, MON_TRANSF, CURS_DOC, CURS_TRANSF,
    PACHIZ,PU,ADDIM,DISCUNIT,PUDISC,PROC_TVA,
    DISCTOTAL,DISCTOT_TVA,DISCTOTCUTVA,
    VALOARE,VAL_TVA,VALCUTVA,
    DEN_PART,
    AGENT_DOC,
    CANTUM1,CANTUM2,
    TIPTVA, TIPTRANZ, TIPFACTURA,
    PUMAX,
    TIPSERIE,SERII,DataExp,DATASCAD,ZILESCAD,TRANSPORT,
    ANDOC,LUNADOC,LUNA,
    COM_TERMEN, SUBUNITATE, CostTransport, CUICorect,
    IndexLinie,DENCLASEAS,DenClasaA,SimbClasaA,ObsArt,ContCli,ContServ,SLIVR_JUD,
    GARANTIE, OPERAT, CADOU,
    TIPPROMO, NRPROMO, NRAE, ZILEDISCT, PROCDISCTOT, CONTVENITURI,
    DISCOFF2,
    DISCOFF3,
    BancaCursPUV,MonedaFactinValuta,EFACTSTARE,IDDESCARCARE,IDINCARCARE,TipSaft,
    ARTATRIB1,
    SOLD, CONTRPRET,
    ContrTermTip, ContrTerm1, ContrTerm2, ContrTerm3, ContrTerm1Disc, ContrTerm2Disc, ContrTerm3Disc,
    CONTRADDIM, CONTRPJDISC, CONTRANEXA, CONTRDSTART, CONTRDSTOP, DISCT, DISCC, DISCV, ARTCADOU, CANTCADOU, DISCTNC, DISCCNC, DISCVNC,
    ARTCADOUNC, UMCADOUNC, CANTCADOUNC, PRETCADOUNC,
    CURS_REF, CURS_PREST&apos;||sInsertDC||pUserFields||&apos;)
  SELECT
    i1.codies NAV_CodDoc, i1.tipdoc NAV_TipDoc, nsub.codsubunit, np.codclasa, JUDLIVR.simbauto,
    i1.codobiect, i1.tipart, nao.denumire DEN_ARTICOL, i1.denobiectorig DEN_ORIGINAL,um.den_um1 DEN_UM, DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)/um.paritate cant, ies.prefixdoc||ies.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(ies.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) document,
    mon.den_moneda MON_DOC, mont.den_moneda MON_TRANSF, i1.curs, ies.cursdoc CURS_TRANSF,
    i1.valachiz * um.paritate/DECODE(i1.cantlivr,0,1,i1.cantlivr) PACHIZ, i1.pu * um.paritate PU, i1.addim, (i1.pies-i1.pu) * um.paritate DISCUNIT, i1.pies * um.paritate PUDISC, i1.coef_tva*100 PROC_TVA,
    DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*(i1.pies - i1.pu) DISCTOTAL,
    DECODE(i1.tipdoc,16,i1.tvalin - i1.tvau, DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*(i1.pies - i1.pu) * i1.coef_tva) DISCTOT_TVA,
    DECODE(i1.tipdoc,16,i1.cant*(i1.pies - i1.pu) + i1.tvalin - i1.tvau, i1.cant*(i1.pies - i1.pu) * (1+i1.coef_tva)) * CASE WHEN i1.cantlivr = 0 THEN 1 WHEN i1.cant = 0 THEN 1 ELSE i1.cantlivr/i1.cant END DISCTOTCUTVA,
    DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr) * i1.pies VALOARE,
    CASE WHEN i1.tipdoc = 16 THEN i1.tvalin WHEN i1.pu = i1.pies THEN i1.tvalin ELSE i1.cant*i1.pies*i1.coef_tva END * CASE WHEN i1.cantlivr = 0 THEN 1 WHEN i1.cant = 0 THEN 1 ELSE i1.cantlivr/i1.cant END VAL_TVA,
    CASE WHEN i1.tipdoc = 16 THEN i1.cant*i1.pies+i1.tvalin WHEN i1.pu = i1.pies THEN i1.cant*i1.pies+i1.tvalin ELSE i1.cant*i1.pies*(1+i1.coef_tva) END * CASE WHEN i1.cantlivr = 0 THEN 1 WHEN i1.cant = 0 THEN 1 ELSE i1.cantlivr/i1.cant END VALCUTVA,
    DECODE(i1.tipdoc,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;Vanzari cu amanuntul&apos;&apos;,23,ns.den_subunit,24,ng.den_gest,np.den_part) DEN_PART,
    DECODE(ag_doc.codpers,0, ag_doc.nume, ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume) AGENT_DOC,
    DECODE(i1.cantlivr,0,0,i1.cant,i1.cantum1,i1.cantum1*i1.cant/i1.cantlivr) CANTUM1,DECODE(i1.cantlivr,0,0,i1.cant,i1.cantum2,i1.cantum2*i1.cant/i1.cantlivr) CANTUM2,
    DECODE(ies.tiptva,1,&apos;&apos;Taxare Normala&apos;&apos;,2,&apos;&apos;Taxare Inversa&apos;&apos;,3,&apos;&apos;Taxare Triunghiulara&apos;&apos;,4,&apos;&apos;Prestari in afara Romaniei&apos;&apos;,7,&apos;&apos;regim special(art.1521, 1522)&apos;&apos;,
             5,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;,6,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;) TIPTVA,
    DECODE(ies.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Livrare intracomunitara&apos;&apos;,3,&apos;&apos;Export&apos;&apos;) TIPTRANZ,
    CASE
      WHEN ies.infocm = 1 THEN &apos;&apos;InfoCM&apos;&apos;
      WHEN ies.tipfactura = 8 THEN &apos;&apos;Nota cantar&apos;&apos;
      WHEN ies.tipfactura = 7 THEN &apos;&apos;Cu incasare imediata prin CM&apos;&apos;
      --WHEN ies.tipfactura = 6 THEN &apos;&apos;XX&apos;&apos;
      WHEN ies.tipfactura = 5 THEN &apos;&apos;Stingere nota credit&apos;&apos;
      WHEN ies.tipfactura = 4 THEN &apos;&apos;Service auto&apos;&apos;
      WHEN ies.tipfactura = 3 THEN &apos;&apos;Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 2 THEN &apos;&apos;Contract Leasing financiar&apos;&apos;
      WHEN ies.tipfactura = 1 THEN &apos;&apos;Abonament&apos;&apos;
      ELSE &apos;&apos;Normala&apos;&apos;
    END TIPFACTURA,
    CASE
      WHEN i1.tipdoc = 23 AND Coalesce(nao1.tippretmax,0) = 3 THEN decode (Coalesce(i1.pumaxns,0),-1,0,Coalesce(i1.pumaxns,0))
      WHEN i1.tipdoc = 23 AND Coalesce(nao1.tippretmax,0) = 6 THEN decode (Coalesce(nao1.pretmaximal,0),-1,0,Coalesce(nao1.pretmaximal,0))
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2) THEN decode (Coalesce(i1.pumaximal, i1.pumaxns),-1,0,Coalesce(i1.pumaximal, i1.pumaxns) )
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5) THEN decode (Coalesce(nao1.pretmaximal,0),-1,0,Coalesce(nao1.pretmaximal,0))
      ELSE 0
    END PUMAX,
    i1.tipserie, i1.serii, i1.tg DataExp, i1.termen DATASCAD, CASE WHEN i1.termen IS NULL THEN 0 ELSE i1.termen - ies.datadoc END ZILESCAD, i1.transport,
    ies.an andoc, ies.luna lunadoc, to_char(ies.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(ies.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(ies.Luna) luna,
    com1.termen COM_TERMEN, nsub.den_subunit SUBUNITATE, I1.CostTransport, DECODE(cif_valid(FISC.CodFiscal),0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) CUICorect,
    I1.IndexLocal IndexLinie, cs.den_claseas DENCLASEAS, nca.den_clasea DenClasaA, nca.simbol SimbClasaA, i1.obsart, ccli.simbol ContCli, cserv.simbol ContServ, JUDlivr.den_judet SLIVR_JUD,
    Decode(IES.TIPCONSUMATOR,2,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) GARANTIE, Decode(IES.OPERAT,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) OPERAT, Decode(I1.CADOU,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) CADOU,
    DECODE(p.tippromotie, 1, &apos;&apos;marime pret&apos;&apos;, 2,  &apos;&apos;% discount&apos;&apos;, 3, &apos;&apos;articole promotionale (cadou)&apos;&apos;) TIPPROMO, p.nrdoc NRPROMO, ae.nrdoc NRAE, null ziledisct, (i1.pretorig-1)*100 procdisctot, ncv.simbol,
    i1.pies*DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 2 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF2,
    i1.pies*DECODE(i1.cantlivr,0,i1.cant,i1.cantlivr)*(SELECT Coalesce(SUM(X.PROCENT/100),0) FROM IesDisc x WHERE x.codies = ies.codies AND x.offinvoice = 3 AND Coalesce(NullIF(x.codobiect,0),i1.codobiect) = i1.codobiect) DISCOFF3,
    pkg_list_base_utils.GET_Den_BancaCursPUV(IES.An, IES.Luna), pkg_list_base_utils.GET_Simb_MonedaFactInValuta(IES.An, IES.Luna),EFACT.STARE,EFACT.IDDESCARCARE,EFACT.IDINCARCARE,
    case when coalesce(IES.TIPSAFT,0) = 0 THEN &apos;&apos;380&apos;&apos; when coalesce(IES.TIPSAFT,0) = 1 THEN &apos;&apos;381&apos;&apos; when coalesce(IES.TIPSAFT,0) = 2 THEN &apos;&apos;384&apos;&apos; when coalesce(IES.TIPSAFT,0) = 3 THEN &apos;&apos;389&apos;&apos; when coalesce(IES.TIPSAFT,0) = 5 THEN &apos;&apos;751&apos;&apos; END &apos;||
    sArtAtrib1||sSold||sDiscContr||sDiscNc||sCursRef||sCursPrest||sSelectDC||pUserAlias||&apos;
  FROM TMP_LST_IESIRI      I1
	  LEFT JOIN IESIRI       IES     ON ies.codies         = i1.codies
	  LEFT JOIN IESIRI       AE      ON ae.codies          = DECODE(i1.tipdoc,20,i1.codies,i1.codae)
    LEFT JOIN NARTOBJ      NAO     ON nao.codobiect      = i1.codobiect
    LEFT JOIN NART         NA      ON na.codarticol      = nao.codarticol
    LEFT JOIN ioart        io      ON io.codioart        = i1.codioart
    LEFT JOIN ioart1       io1     ON io1.codioart1      = i1.codioart1
    LEFT JOIN NCONT        NCV     ON ncv.codcont        = io1.venituri
    LEFT JOIN NCLASEAS     CS      ON cs.codclaseas      = na.clasastatist
    LEFT JOIN NCLASEA      NCA     ON nca.codclasea      = na.clasa &apos;||
    sJoinUM||sJoinDC||sJoinCadou||&apos;
    LEFT JOIN NPART        NP      ON np.codpart         = ies.partener
    LEFT JOIN IOPART1      IOP1    ON iop1.codiopart1    = i1.codiopart1
    LEFT JOIN NCONT        CCLI    ON ccli.codcont       = iop1.contclient
    LEFT JOIN NCONT        CSERV   ON cserv.codcont      = coalesce(i1.contserv,0)
    LEFT JOIN NAGENDA      SLIVR   ON slivr.codagenda    = i1.codlocatie
    LEFT JOIN NLOCALIT     LOClivr ON loclivr.codlocalit = slivr.codlocalit
    LEFT JOIN NJUDET       JUDlivr ON judlivr.codjudet   = loclivr.codjudet
    LEFT JOIN NPARTCODFISC FISC    ON fisc.codpart       = ies.partener AND fisc.principal = 1
    LEFT JOIN NGEST        NG      ON ng.codgest         = ies.codgestprod
    LEFT JOIN NSUBUNIT     NS      ON ns.codsubunit      = ies.codsubunit
    LEFT JOIN NSUBUNIT     NSUB    ON nsub.codsubunit    = ies.subunitatea
    LEFT JOIN NMONEDE      MON     ON mon.codmoneda      = ies.moneda
    LEFT JOIN NMONEDE      MONT    ON mont.codmoneda     = ies.monedatransf
    LEFT JOIN COMANDA1     COM1    ON com1.codcomanda1   = i1.codliniecomanda
    LEFT JOIN nartobj1     nao1    ON nao1.codobiect1    = i1.codobiect1
    LEFT JOIN promo        p       ON p.codpromo         = i1.codpromo
    LEFT JOIN statusdecl   EFACT   ON EFACT.CODDOC       = ies.codies and efact.tipdoc = ies.tipdoc
    LEFT JOIN NPERS        AG_DOC  ON ag_doc.codpers     = Coalesce(DECODE(ies.tipdoc,16,i1.codagentemulare,ies.agent),0)&apos;||
    jDiscNC||
    pSuplJoins;

  IF bOrdObiect THEN
    sInsert := sInsert||&apos;
    ORDER BY i1.codobiect&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sTruncTmp , 0, 0);
  LIST_EXECUTE_IMMEDIATE(sInserttmp, 0, 0);
  LIST_EXECUTE_IMMEDIATE(sInsert,    0, 0);

  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(10000);
  gUserAlias  VARCHAR2(10000);
  gNullAlias  VARCHAR2(3000);
BEGIN
  setVar;
  gSuplCols :=
    &apos;TMP_LST_IESIRI I1, IESIRI IES, IESIRI AE, NARTOBJ NAO, NART NA, IOART IO, IOART1 IO1, NCONT NCV, NCLASEAS CS, NCLASEA NCA, NPART NP, IOPART1 IOP1, NCONT CCLI, NCONT CSERV, &apos;||
    &apos;NAGENDA SLIVR, NLOCALIT LOCLIVR, NJUDET JUDLIVR, NPARTCODFISC FISC, NGEST NG, NSUBUNIT NS, NSUBUNIT NSUB, NMONEDE MON, NMONEDE MONT, COMANDA1 COM1, NARTOBJ1 NAO1, PROMO P, &apos;||
    &apos;NPERS AG_DOC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;IES1&apos;,        &apos;IES1.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,            &apos;UM1&apos;,         &apos;UM1.CODUM = NA.UM1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;,            &apos;UM2&apos;,         &apos;UM2.CODUM = NA.UM2&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEP&apos;,        &apos;NCP&apos;,         &apos;NCP.CODCLASEP = NP.CODCLASA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,          &apos;CREP&apos;,        &apos;CREP.CODCONT = IO1.CONT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;,     &apos;DC&apos;,          &apos;DC.CODCARNET = IES.CARNETDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,          &apos;PROD&apos;,        &apos;PROD.CODPART = NAO.CODPRODUCATOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;,          &apos;ZONALIVR&apos;,    &apos;ZONALIVR.CODZONA = LOCLIVR.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARALIVR&apos;,    &apos;TARALIVR.CODTARA = LOCLIVR.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRASEULIVR&apos;,     &apos;TLIVR&apos;,       &apos;TLIVR.CODTRASEULIVR = SLIVR.CODTRASEU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTIPSEDII&apos;,      &apos;TIPSLIVR&apos;,    &apos;TIPSLIVR.CODTIPSEDIU = SLIVR.CODTIPSEDIU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,          &apos;AG_LIVR&apos;,     &apos;AG_LIVR.CODPERS = SLIVR.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;AGLIVR_ADR&apos;,  &apos;AGLIVR_ADR.CODAGENDA = AG_LIVR.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;,         &apos;AG1_LIVR&apos;,    &apos;ag1_livr.codpers = slivr.codagent AND ag1_livr.alstart &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND ag1_livr.alstop &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;,       &apos;AGLIVR_FORM&apos;, &apos;AGLIVR_FORM.CODFORMATIE = AG1_LIVR.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;,        &apos;AGLIVR_FUNC&apos;, &apos;AGLIVR_FUNC.CODFUNCTIE = AG1_LIVR.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;,       &apos;AGLIVR_MES&apos;,  &apos;AGLIVR_MES.CODMESERIE = AG1_LIVR.CODMESERIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;AGDOC_ADR&apos;,   &apos;AGDOC_ADR.CODAGENDA = AG_DOC.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;,         &apos;AG1_DOC&apos;,     &apos;AG1_DOC.codpers = slivr.codagent AND AG1_DOC.alstart &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND AG1_DOC.alstop &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;,       &apos;AGDOC_FORM&apos;,  &apos;AGDOC_FORM.CODFORMATIE = AG1_DOC.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;,        &apos;AGDOC_FUNC&apos;,  &apos;AGDOC_FUNC.CODFUNCTIE = AG1_DOC.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;,       &apos;AGDOC_MES&apos;,   &apos;AGDOC_MES.CODMESERIE = AG1_DOC.CODMESERIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SSOC&apos;,        &apos;SSOC.CODPART = IES.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCSOC&apos;,      &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;,         &apos;JUDSOC&apos;,      &apos;JUDSOC.CODJUDET = LOCSOC.CODJUDET&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;,          &apos;ZONASOC&apos;,     &apos;ZONASOC.CODZONA = LOCSOC.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARASOC&apos;,     &apos;TARASOC.CODTARA = LOCSOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARAORIG&apos;,    &apos;TARAORIG.CODTARA = NAO.TARAORIGINE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NGEST&apos;,          &apos;NGSERV&apos;,      &apos;NGSERV.CODGEST = I1.GESTACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;COM&apos;,         &apos;COM.CODCOMANDA = COM1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,       &apos;CC1&apos;,         &apos;CC1.CODCOMANDA1 = I1.CODLINIECOMANDACC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,       &apos;DL1&apos;,         &apos;DL1.CODCOMANDA1 = I1.CODLINIECOMANDADL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;CC&apos;,          &apos;CC.CODCOMANDA = CC1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,        &apos;DL&apos;,          &apos;DL.CODCOMANDA = DL1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,        &apos;NPTR&apos;,        &apos;NPTR.CODPARTTR = I1.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,        &apos;AA&apos;,          &apos;AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,          &apos;PM&apos;,          &apos;PM.CODOBIECT = I1.CODOBIECT AND PM.SUBUNITATEA = IES.SUBUNITATEA AND PM.IMPLICIT = 1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,     &apos;CCOST&apos;,       &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;, &apos;UTILIZATOR&apos;,  &apos;UTILIZATOR.CODUTILIZATOR = IES.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;ISTORN1&apos;,     &apos;ISTORN1.CODIES1 = I1.CODIES1STORNO&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;ISTORN&apos;,      &apos;ISTORN.CODIES = ISTORN1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,        &apos;DOCIMP1&apos;,     &apos;DOCIMP1.CODIES1 = I1.CODLINIEDOCIMP AND I1.TIPDOCIMP IN (19, 20, 21, 26 )&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;DOCIMP&apos;,      &apos;DOCIMP.CODIES = DOCIMP1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,     &apos;ANOD&apos;,        &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,     &apos;ANALIZ&apos;,      &apos;ANALIZ.CODANALIZA = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;,   &apos;ADESC1&apos;,      &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;,    &apos;ADESC&apos;,       &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1&apos;,        &apos;OFE1&apos;,        &apos;OFE1.CODOFERTA1 = COALESCE(CC1.CODOFERTA1,DECODE(CC1.TIPSURSA,50,CC1.CODSURSA,NULL),I1.CODOFERTA1,PKG_OFERTA.GETCODOFERTA1(I1.CODOBIECT,IES.DATADOC,IES.PARTENER,IES.CODLOCATIE,IES.SUBUNITATEA,50,I1.CANT))&apos;,1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA&apos;,         &apos;OFE&apos;,         &apos;OFE1.CODOFERTA = OFE.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,       &apos;PD&apos;,          &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,      &apos;IEXT&apos;,        &apos;IEXT.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1EXT&apos;,     &apos;I1EXT&apos;,       &apos;I1EXT.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;MONETAREXT&apos;,     &apos;MEXT&apos;,        &apos;MEXT.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;MONETAR1EXT&apos;,    &apos;M1EXT&apos;,       &apos;M1EXT.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;,        &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;,        &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;,        &apos;CCEXT&apos;,       &apos;CCEXT.CODCOMANDA = CC1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;,       &apos;CC1EXT&apos;,      &apos;CC1EXT.CODCOMANDA1 = CC1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJSUBUNIT&apos;, &apos;NAOS&apos;,        &apos;NAOS.CODOBIECT = NAO.CODOBIECT AND NAOS.SUBUNITATE = IES.SUBUNITATEA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SPROD&apos;,       &apos;SPROD.CODPART = NAO.CODPRODUCATOR AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SPROD.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCPROD&apos;,     &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARAPROD&apos;,    &apos;TARAPROD.CODTARA = LOCPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;,      &apos;CONTR1&apos;,      &apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT&apos;,       &apos;CONTR&apos;,       &apos;CONTR.CODCONTRACT = COALESCE(CONTR1.CODCONTRACT,AE.CODCONTRACT,IES.CODCONTRACT)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT2&apos;,      &apos;CONTR2&apos;,      &apos;CONTR2.CODDOC = I1.CODIES AND CONTR2.TIPDOC = I1.TIPDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,          &apos;COMIS&apos;,       &apos;COMIS.CODPART = IES.PARTCUSTODIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,        &apos;ACLI&apos;,        &apos;ACLI.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(I1.CODOBIECT, IES.PARTENER, NP.CODCLASA)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  PRC_AL_CHECK(&apos;NPERS1&apos;);

  InsertIesiri(tmpName, gUserFields, gUserAlias, gNullAlias, gSuplJoins);
  -- InsertSinteza este apelat din PKG_LIST_BASE_IESIRISINT
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END PKG_LIST_BASE_IESIRI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESIRISIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D50789E61F4E058684C657C0A106DD36960F238</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IESIRISIMPL IS

  gSuplCols   VARCHAR2(2500);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
BEGIN
  gSuplCols :=
    &apos;TMP_LST_IESSIMPL I1, IESIRI IES, IESIRI AE, NARTOBJ NAO, NART NA, NCLASEAS CS, NCLASEA NCA, NPART NP, NPARTCODFISC FISC, NGEST NG, NSUBUNIT NS, NSUBUNIT NSUB, NMONEDE MON, &apos;||
    &apos;NMONEDE MONT, PROMO P, NARTOBJ1 NAO1, NAGENDA SLIVR, NLOCALIT LOCLIVR, NJUDET JUDLIVR, TAXDECL TXDCL&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;, &apos;IES1&apos;, &apos;IES1.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;, &apos;UM1&apos;, &apos;UM1.CODUM = NA.UM1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NUM&apos;, &apos;UM2&apos;, &apos;UM2.CODUM = NA.UM2&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEP&apos;, &apos;NCP&apos;, &apos;NCP.CODCLASEP = NP.CODCLASA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;, &apos;DC&apos;, &apos;DC.CODCARNET = IES.CARNETDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;, &apos;PROD&apos;, &apos;PROD.CODPART = NAO.CODPRODUCATOR&apos;);

  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SLIVR&apos;, &apos;SLIVR.CODAGENDA = I1.CODLOCATIE&apos;);
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;, &apos;LOCLIVR&apos;, &apos;LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT&apos;);
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;, &apos;JUDLIVR&apos;, &apos;JUDLIVR.CODJUDET = LOCLIVR.CODJUDET&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;, &apos;ZONALIVR&apos;, &apos;ZONALIVR.CODZONA = LOCLIVR.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARALIVR&apos;, &apos; TARALIVR.CODTARA = LOCLIVR.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRASEULIVR&apos;, &apos;TLIVR&apos;, &apos;TLIVR.CODTRASEULIVR = SLIVR.CODTRASEU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTIPSEDII&apos;, &apos;TIPSLIVR&apos;, &apos;TIPSLIVR.CODTIPSEDIU = SLIVR.CODTIPSEDIU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;, &apos;AG_DOC&apos;, &apos;AG_DOC.CODPERS = Coalesce(DECODE(IES.TIPDOC,16,I1.CODAGENTEMULARE,IES.AGENT),0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;, &apos;AG_LIVR&apos;, &apos;AG_LIVR.CODPERS = SLIVR.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;AGLIVR_ADR&apos;, &apos;AGLIVR_ADR.CODAGENDA = AG_LIVR.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;, &apos;AG1_LIVR&apos;, &apos;ag1_livr.codpers = slivr.codagent AND ag1_livr.alstart &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND ag1_livr.alstop &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;, &apos;AGLIVR_FORM&apos;, &apos;AGLIVR_FORM.CODFORMATIE = AG1_LIVR.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;, &apos;AGLIVR_FUNC&apos;, &apos;AGLIVR_FUNC.CODFUNCTIE = AG1_LIVR.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;, &apos;AGLIVR_MES&apos;, &apos;AGLIVR_MES.CODMESERIE = AG1_LIVR.CODMESERIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;AGDOC_ADR&apos;, &apos;AGDOC_ADR.CODAGENDA = AG_DOC.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;, &apos;AG1_DOC&apos;, &apos;AG1_DOC.codpers = slivr.codagent AND AG1_DOC.alstart &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND AG1_DOC.alstop &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;, &apos;AGDOC_FORM&apos;, &apos;AGDOC_FORM.CODFORMATIE = AG1_DOC.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;, &apos;AGDOC_FUNC&apos;, &apos;AGDOC_FUNC.CODFUNCTIE = AG1_DOC.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;, &apos;AGDOC_MES&apos;, &apos;AGDOC_MES.CODMESERIE = AG1_DOC.CODMESERIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SSOC&apos;, &apos;SSOC.CODPART = IES.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;, &apos;LOCSOC&apos;, &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;, &apos;JUDSOC&apos;, &apos;JUDSOC.CODJUDET = LOCSOC.CODJUDET&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;, &apos;ZONASOC&apos;, &apos;ZONASOC.CODZONA = LOCSOC.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARASOC&apos;, &apos;TARASOC.CODTARA = LOCSOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARAORIG&apos;, &apos;TARAORIG.CODTARA = NAO.TARAORIGINE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NGEST&apos;, &apos;NGSERV&apos;, &apos;NGSERV.CODGEST = I1.GESTACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;, &apos;COM1&apos;, &apos;COM1.CODCOMANDA1 = I1.CODLINIECOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;, &apos;COM&apos;, &apos;COM.CODCOMANDA = COM1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;, &apos;CC1&apos;, &apos;CC1.CODCOMANDA1 = I1.CODLINIECOMANDACC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;, &apos;DL1&apos;, &apos;DL1.CODCOMANDA1 = I1.CODLINIECOMANDADL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;, &apos;CC&apos;, &apos;CC.CODCOMANDA = CC1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;, &apos;DL&apos;, &apos;DL.CODCOMANDA = DL1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;, &apos;NPTR&apos;, &apos;NPTR.CODPARTTR = I1.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;, &apos;AA&apos;, &apos;AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;, &apos;PM&apos;, &apos;PM.CODOBIECT = I1.CODOBIECT AND PM.SUBUNITATEA = IES.SUBUNITATEA AND PM.IMPLICIT = 1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;, &apos;UTILIZATOR&apos;, &apos;UTILIZATOR.CODUTILIZATOR = IES.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;, &apos;ISTORN1&apos;, &apos;ISTORN1.CODIES1 = I1.CODIES1STORNO&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;, &apos;ISTORN&apos;, &apos;ISTORN.CODIES = ISTORN1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;, &apos;DOCIMP1&apos;, &apos;DOCIMP1.CODIES1 = I1.CODLINIEDOCIMP AND I1.TIPDOCIMP IN (19, 20, 21, 26 )&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;, &apos;DOCIMP&apos;, &apos;DOCIMP.CODIES = DOCIMP1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;, &apos;ANOD&apos;, &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;, &apos;ANALIZ&apos;, &apos;ANALIZ.CODANALIZA = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;, &apos;ADESC1&apos;, &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;, &apos;ADESC&apos;, &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1&apos;, &apos;OFE1&apos;, &apos;OFE1.CODOFERTA1 = COALESCE(CC1.CODOFERTA1,DECODE(CC1.TIPSURSA,50,CC1.CODSURSA,NULL),I1.CODOFERTA1,PKG_OFERTA.GETCODOFERTA1(I1.CODOBIECT,IES.DATADOC,IES.PARTENER,IES.CODLOCATIE,IES.SUBUNITATEA,50,I1.CANT))&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA&apos;, &apos;OFE&apos;, &apos;OFE1.CODOFERTA = OFE.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;, &apos;IEXT&apos;, &apos;IEXT.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1EXT&apos;, &apos;I1EXT&apos;, &apos;I1EXT.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;MONETAREXT&apos;, &apos;MEXT&apos;, &apos;MEXT.CODIES = I1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;MONETAR1EXT&apos;, &apos;M1EXT&apos;, &apos;M1EXT.CODIES1 = I1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;, &apos;CCEXT&apos;, &apos;CCEXT.CODCOMANDA = CC1.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;, &apos;CC1EXT&apos;, &apos; CC1EXT.CODCOMANDA1 = CC1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJSUBUNIT&apos;, &apos;NAOS&apos;, &apos;NAOS.CODOBIECT = NAO.CODOBIECT AND NAOS.SUBUNITATE = IES.SUBUNITATEA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SPROD&apos;, &apos;SPROD.CODPART = NAO.CODPRODUCATOR AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SPROD.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;, &apos;LOCPROD&apos;, &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARAPROD&apos;, &apos;TARAPROD.CODTARA = LOCPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;, &apos;CONTR1&apos;, &apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT&apos;, &apos;CONTR&apos;, &apos;CONTR.CODCONTRACT = COALESCE(CONTR1.CODCONTRACT,AE.CODCONTRACT,IES.CODCONTRACT)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT2&apos;, &apos;CONTR2&apos;, &apos;CONTR2.CODDOC = I1.CODIES AND CONTR2.TIPDOC = I1.TIPDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;, &apos;COMIS&apos;, &apos;COMIS.CODPART = IES.PARTCUSTODIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;, &apos;ACLI&apos;, &apos;ACLI.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(I1.CODOBIECT, IES.PARTENER, NP.CODCLASA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IOPART1&apos;, &apos;IOP1&apos;, &apos;IOP1.CODIOPART1 = I1.CODIOPART1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;, &apos;CCLI&apos;, &apos;CCLI.CODCONT = IOP1.CONTCLIENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;, &apos;CSERV&apos;, &apos;CSERV.CODCONT = I1.CONTSERV&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  --pkg_list_base_utils.UMPLE_TMP_NPERS1_LST;
  PRC_AL_CHECK(&apos;NPERS1&apos;);

  pkg_list_base_iesiri.SetSimpl;
  pkg_list_base_iesiri.SetVar;
  pkg_list_base_iesiri.UnsetSimpl;
  pkg_list_base_iesiri.InsertIesSimpl(tmpName, gUserFields, gUserAlias, gNullAlias, gSuplJoins);
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_iesirisimpl;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESIRISINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D88C4CB200261E9E00C5A42A9CCEB6DB24BEC6C8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iesirisint IS

  gSuplCols   VARCHAR2(2500) :=
      &apos;NPART NP, NGEST NG, DOCCARNETE DC, NAGENDA SSOC,NAGENDA SLIVR,NPARTTR NPTR,NPERS AG_DOC,NPERS AG_LIVR,NLOCALIT LOCSOC,NJUDET JUDSOC,&apos;||
      &apos;NLOCALIT LOClivr, NJUDET JUDlivr, TRASEULIVR TLIVR, NTIPSEDII TIPSLIVR, IESIRI IES, TMP_UTILIZATOR UTILIZATOR, NTARI TARALIVR, &apos;||
      &apos;NTARI TARASOC, NPARTCODFISC FISC&apos;;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
BEGIN
  -- separat de pkg_list_base_iesiri pt ca daca se lans in paralel list iesiri si iesirisinteza erau probleme cu coloanele suplimentare
  gSuplCols :=
    &apos;NPART NP, NGEST NG, DOCCARNETE DC, NAGENDA SSOC, NAGENDA SLIVR, NPARTTR NPTR, NPERS AG_DOC, NPERS AG_LIVR, NLOCALIT LOCSOC, NJUDET JUDSOC, &apos;||
    &apos;NLOCALIT LOClivr, NJUDET JUDlivr, TRASEULIVR TLIVR, NTIPSEDII TIPSLIVR, IESIRI IES, TMP_UTILIZATOR UTILIZATOR, NTARI TARALIVR, NTARI TARASOC, NPARTCODFISC FISC, &apos;||
    &apos;NPART COMIS, TMP_MANEVRA_IESSINT I1&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,      &apos;IEXT&apos;,        &apos;IEXT.CODIES = IES.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;MONETAREXT&apos;,     &apos;MEXT&apos;,        &apos;MEXT.CODIES = IES.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,       &apos;PD&apos;,          &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;AGLIVR_ADR&apos;,  &apos;AGLIVR_ADR.CODAGENDA = AG_LIVR.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;,         &apos;AG1_LIVR&apos;,    &apos;AG1_LIVR.CODPERS = SLIVR.CODAGENT AND AG1_LIVR.ALSTART &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND AG1_LIVR.ALSTOP &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;,       &apos;AGLIVR_FORM&apos;, &apos;AGLIVR_FORM.CODFORMATIE = AG1_LIVR.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;,        &apos;AGLIVR_FUNC&apos;, &apos;AGLIVR_FUNC.CODFUNCTIE = AG1_LIVR.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;,       &apos;AGLIVR_MES&apos;,  &apos;AGLIVR_MES.CODMESERIE = AG1_LIVR.CODMESERIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;AGDOC_ADR&apos;,   &apos;AGDOC_ADR.CODAGENDA = AG_DOC.AGENDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS1&apos;,         &apos;AG1_DOC&apos;,     &apos;AG1_DOC.CODPERS = SLIVR.CODAGENT AND AG1_DOC.ALSTART &lt;= &apos;||pkg_globals.ANLUNALUCRU||&apos; AND AG1_DOC.ALSTOP &gt;= &apos;||pkg_globals.ANLUNALUCRU);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;,       &apos;AGDOC_FORM&apos;,  &apos;AGDOC_FORM.CODFORMATIE = AG1_DOC.CODFORMATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FUNCTII&apos;,        &apos;AGDOC_FUNC&apos;,  &apos;AGDOC_FUNC.CODFUNCTIE = AG1_DOC.CODFUNCTIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMESERII&apos;,       &apos;AGDOC_MES&apos;,   &apos;AGDOC_MES.CODMESERIE = AG1_DOC.CODMESERIE&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_list_base_iesiri.SetVar;
  pkg_list_base_iesiri.InsertSinteza(tmpName, gUserFields, gUserAlias, gNullAlias, gSuplJoins);
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_iesirisint;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F97F063F00F57EDA93028C5DB372E986B3E0D034</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IESMF is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(2000);
sSelect VARCHAR2(10000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NARTOBJ OBJ, NART ART, IESIRI I, IESIRI1 I1, MIFIX MF, MIFIX1 MF1, NIRSTOC NS, TRANSF T, TRANSF1 T1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    TipOperatie,
    Partener,   
    Doc,        
    Articol,    
    NrInventar, 
    Cant,       
    Pret,       
    Valoare,    
    TVA,        
    An,          
    Luna,       
    Cont &apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    CASE
      WHEN MF1.STARE = 3 THEN &apos;&apos;Casare&apos;&apos;
      WHEN MF1.STARE = 4 THEN &apos;&apos;Vanzare&apos;&apos;
      WHEN MF1.STARE = 6 THEN &apos;&apos;Cedat ca aport la capital&apos;&apos;
      WHEN MF1.STARE = 7 THEN &apos;&apos;Transferat ca marfa&apos;&apos;
    END TIPOPERATIE,
    &apos;&apos; &apos;&apos; Partener,   
    I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    I1.Cant,       
    I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)),       
    I1.Cant * I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) Valoare,    
    I1.TVA,        
    I.An,          
    I.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM MIFIX1 MF1
    INNER JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC AND L1.CODNIRSER = MF1.CODNIRSER
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
    INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND L.CODIES = I.CODIES
    INNER JOIN NARTOBJ OBJ ON I1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (I.AN * 12 + I.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT
    LEFT  JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODNIRSTOC - NS.CODNIRSTOC
    LEFT  JOIN TRANSF T ON T.CODTRANSF = NS.CODNIRSTOC - NS.CODNIRSTOC
    &apos;||gSuplJoins||&apos;
  WHERE mf.tip = &apos;&apos;MF&apos;&apos; AND NS.TIPSERIE &gt; 0 AND MF1.STARE IN (3,4,6,7) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||
  &apos; union all
  SELECT
    &apos;&apos;Transfer la marfa&apos;&apos; TIPOPERATIE,
    &apos;&apos; &apos;&apos; Partener,   
    T.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    T1.Cant,       
    T1.PU,       
    T1.Cant * T1.PU Valoare,    
    T1.TVA,        
    T.An,          
    T.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM MIFIX1 MF1
    INNER JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC AND L1.CODNIRSER = MF1.CODNIRSER
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = L1.CODIES1
    INNER JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF AND L.CODTRANSF = T.CODTRANSF
    INNER JOIN NARTOBJ OBJ ON T1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (T.AN * 12 + T.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT
    LEFT  JOIN IESIRI1 I1 ON I1.CODIES1 = NS.codnirstoc - NS.codnirstoc
    LEFT  JOIN IESIRI I ON I.CODIES = NS.codnirstoc - NS.codnirstoc
    LEFT  JOIN NPART P ON I.PARTENER = P.CODPART
    &apos;||gSuplJoins||&apos;
  WHERE mf.tip = &apos;&apos;MF&apos;&apos; AND NS.TIPSERIE &gt; 0 AND MF1.STARE IN (3,4,6,7) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;);

  --delete x;
  --insert into x(test) values(sselect);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  sSelect := &apos;
  with nss as 
  (
  SELECT
    distinct ns.codnirstoc
  FROM MIFIX1 MF1
    INNER JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC 
    INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
    INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND L.CODIES = I.CODIES
    INNER JOIN NARTOBJ OBJ ON I1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (I.AN * 12 + I.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT
    LEFT  JOIN NPART P ON I.PARTENER = P.CODPART
  WHERE MF1.STARE IN (3,4,6,7) AND I.SUBUNITATEA = 2 and mf.tip = &apos;&apos;MF&apos;&apos;
  union all
  SELECT 
    distinct ns.codnirstoc 
  FROM MIFIX1 MF1 
    INNER JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC  
    INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC 
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR 
    Inner JOIN TRANSF1 T1 ON T1.CODTRANSF1 =  L1.CODIES1 
    INNER JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF AND L.CODTRANSF = T.CODTRANSF 
    INNER JOIN NARTOBJ OBJ ON T1.CODOBIECT = OBJ.CODOBIECT 
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL 
    INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX 
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (t.AN * 12 + t.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop 
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT 
    WHERE MF1.STARE IN (3,4,6,7) AND T.SUBUNITATEA = 2 and mf.tip = &apos;&apos;MF&apos;&apos;
  ),
  mif as 
  (
  select distinct nss.codnirstoc, mf1.codmifix
  from nss
       inner join mifix1 mf1 on mf1.codnirstoc = nss.codnirstoc
  order by nss.codnirstoc
  ),
  ies as
  (
  select distinct nss.codnirstoc, i1.codies1
  from nss
       inner join livr1 l1 on l1.codnirstoc = nss.codnirstoc
       inner join iesiri1 i1 on i1.codies1 = l1.codies1
       inner join livr l on l.codlivr = l1.codlivr
       inner join iesiri i on i.codies = i1.codies and l.codies = i.codies
  ),
  tr as
  (
  select distinct nss.codnirstoc, t1.codtransf1
  from nss
       inner join livr1 l1 on l1.codnirstoc = nss.codnirstoc
       inner join transf1 t1 on t1.codtransf1 = l1.codies1
       inner join livr l on l.codlivr = l1.codlivr
       inner join transf t on t.codtransf = t1.codtransf and t.codtransf = l.codtransf
  ),
  mifx as (select codnirstoc, codmifix, row_number() over (partition by codnirstoc order by codmifix) nr from mif),
  iesx as (select codnirstoc, codies1, row_number() over (partition by codnirstoc order by codies1) nr from ies),
  trx as (select codnirstoc, codtransf1, row_number() over (partition by codnirstoc order by codtransf1) nr from tr)
  SELECT
    CASE 
      WHEN i.tipdoc = 14 and MF1.STARE = 3 THEN &apos;&apos;Casare&apos;&apos; 
      WHEN i.tipdoc = 14 and MF1.STARE = 6 THEN &apos;&apos;Cedat aport&apos;&apos;
      else &apos;&apos;Vanzare&apos;&apos; 
    END TIPOPERATIE, 
    P.DEN_PART Partener,   
    I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    I1.Cant,       
    I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)),       
    I1.Cant * I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) Valoare,    
    I1.TVA,        
    I.An,          
    I.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM mifx
    inner join iesx on iesx.codnirstoc = mifx.codnirstoc and mifx.nr = iesx.nr
    INNER JOIN IESIRI1 I1 ON I1.CODIES1 = iesx.CODIES1
    INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
    INNER JOIN NARTOBJ OBJ ON I1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX MF ON MF.CODMIFIX = mifx.CODMIFIX
    INNER JOIN NIRSTOC NS ON MIFX.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (I.AN * 12 + I.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT
    LEFT  JOIN TRANSF1 T1 ON T1.CODTRANSF1 = I1.CODIES1 - I1.CODIES1
    LEFT  JOIN TRANSF T ON T.CODTRANSF = I1.CODIES1 - I1.CODIES1
    LEFT  JOIN NPART P ON I.PARTENER = P.CODPART
    LEFT  JOIN MIFIX1 MF1 ON MF.CODMIFIX = MF1.CODMIFIX AND MF1.STARE IN (3,4,6,7)
    &apos;||gSuplJoins||&apos;
  WHERE mf.tip = &apos;&apos;MF&apos;&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||
  &apos; union all 
  SELECT
    &apos;&apos;Transfer la marfa&apos;&apos; TIPOPERATIE, 
    &apos;&apos; &apos;&apos; Partener,   
    T.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    T1.Cant,       
    T1.PU,       
    T1.Cant * T1.PU Valoare,    
    T1.TVA,        
    T.An,          
    T.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM mifx
    inner join trx on trx.codnirstoc = mifx.codnirstoc and mifx.nr = trx.nr
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = TRX.CODTRANSF1
    INNER JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF
    INNER JOIN NARTOBJ OBJ ON T1.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX MF ON MF.CODMIFIX = mifx.CODMIFIX
    INNER JOIN NIRSTOC NS ON MIFX.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND (T.AN * 12 + T.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT C ON C.CODCONT = IOA1.CONT
    LEFT  JOIN IESIRI1 I1 ON I1.CODIES1 = trx.codnirstoc - trx.codnirstoc
    LEFT  JOIN IESIRI I ON I.CODIES = trx.codnirstoc - trx.codnirstoc
    LEFT  JOIN MIFIX1 MF1 ON MF.CODMIFIX = MF1.CODMIFIX AND MF1.STARE IN (3,4,6,7)
    &apos;||gSuplJoins||&apos;
  WHERE mf.tip = &apos;&apos;MF&apos;&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;,&apos;SUBUNITATEA&apos;);
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  COMMIT;
END;

end PKG_LIST_BASE_IESMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IESPU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0F17E13940A8AF03AEE3FF09D3FEE7FBD473156</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IESPU is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);
  
PROCEDURE PROCESSLIST( tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 ) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NARTOBJ O, NART A, NUM UM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  
  sInsert:=&apos;INSERT INTO &apos;||tmpName||&apos;(
    Articol,
    CodIntern,
    UM,
    Cant,
    Pret,
    NrZile,
    Medie,
    ZileInPer   
   &apos;||gUserFields||&apos;)
  select o.denumire, o.codintern, um.den_um, x.cant, x.pu, x.nrzile, x.cant/x.nrzile, x.datamax - x.datamin + 1 &apos;||gUserAlias||&apos;
  from
  (
    select codobiect, denumire, codintern, pu, sum(cant) cant, count(datavanz) nrzile, min(trunc(datavanz)) datamin, max(trunc(datavanz)) datamax
    from
    (
      select codobiect, denumire, codintern, pu, sum(cant) cant, datavanz
      from
      (
        select o.codobiect, o.denumire, o.codintern, l1.cant, round(case when i.tipdoc = 16 then i1.pu - i1.tva/i1.cant else i1.pu end,2) pu, i.datadoc datavanz
        from iesiri i
             inner join iesiri1 i1 on i1.codies = i.codies
             inner join nartobj o on o.codobiect = i1.codobiect
             left  join livr l on l.codies = i.codies
             left  join livr1 l1 on l1.codies1 = i1.codies1 and l.codlivr = l1.codlivr
             left  join nirstoc ns on ns.codnirstoc = l1.codnirstoc
             left  join livrval lv on lv.codlivr1 = l1.codlivr1
        where i.operat = 1 and i.anulat = 0 and i.tipdoc in (19,20,16) and nvl(i.infocm,0) = 0 and coalesce(ns.codioart,lv.codioart,0) &lt;&gt; coalesce(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETlunalucru),&apos;&apos;0&apos;&apos;)
              and i.datadoc between to_date(&apos;&apos;&apos;||to_char(pkg_list_selectperioada.DataIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||to_char(pkg_list_selectperioada.DataFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;
              ||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos;
      )
      group by codobiect, denumire, codintern, pu, datavanz
    )
    group by codobiect, denumire, codintern, pu
    order by denumire, codintern
  ) x
    inner join nartobj o on o.codobiect = x.codobiect
    inner join nart a on o.codarticol = a.codarticol
    inner join num um on um.codum = a.um&apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;    

end PKG_LIST_BASE_IESPU; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IMBMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6063BCB79018C5F85D4A08A9BE147281799537CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IMBMIFIX IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sPrepare CLOB;
  sInsert  CLOB;
  vALLucru NUMBER(5)   := pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLUNALUCRU;
  sALLucru VARCHAR2(10):= To_Char(vALLucru, &apos;fm00000&apos;);
  sALMax   VARCHAR2(10);
  vCSintC  VARCHAR2(250);
BEGIN
--PKG_GLOBALS.SetDebugMode(TRUE);
  SELECT To_Char(AnMaxim*12+LunaMaxima, &apos;fm00000&apos;) INTO sALMax FROM firmaluni;
  SELECT SubStr(STRING_AGG(NC.SIMBOL), 1, 250)     INTO vCSintC FROM NCONT NC WHERE PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(NC.CODCONT) = 1;

  gSuplCols := &apos;INTRARI I, IESIRI IES, NC NC, MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NIRSTOC NSA, NARTOBJ OBJ, NPART P, NARTOBJ OBJM, NARTAMB AA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART      = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT  = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT  = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTM&apos;,&apos;OEXTM.CODOBIECT = OBJM.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRM&apos;,&apos;OATRM.CODOBIECT = OBJM.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  DELETE FROM intrari1_man;
  sPrepare :=
  &apos;INSERT INTO intrari1_man
  SELECT i1.* FROM intrari1 i1 inner join intrari i on i1.codintr = i.codintr
  WHERE i1.tiplinie = &apos;&apos;S&apos;&apos; AND i1.ContServ &gt; 0 AND i1.CodMifix &gt; 0 AND i.an * 12 + i.luna &lt;= &apos;||sALLucru;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc, NAV_TipDoc, Art, Cant, Pret, Val, Rest, Mifix, NrInventar, DocIntr, Data, Partener, Subunitate, CImb, ObsLinie &apos;||gUserFields||&apos;)
  WITH amortizari as (
    select I1.CodIntr1, sum(L.Cant) Amo, I1.Obs
    from TRANSF1 T1
      INNER JOIN TRANSF   T ON T1.CodTransf = T.CodTransf
      INNER JOIN IMBMIFIXLINK L ON T1.CodTransf1 = L.CodTransf1
      INNER JOIN INTRARI1 I1 ON L.CodIntr1 = I1.CodIntr1
    where (T.An * 12 + T.Luna &gt; &apos;||sALLucru||&apos;)
      and (T.An * 12 + T.Luna &lt;= &apos;||sALMax||&apos;)
      and T.Anulat &lt;&gt; 1 and T.Blocat &lt;&gt; 1 and T.Operat = 1
    GROUP BY I1.CodIntr1, I1.Obs )
  SELECT
    I.CODINTR, I.TIPDOC, OBJ.Denumire, I1.Cant, (CASE WHEN I.TIPDOC = 3 THEN I1.PU - I1.TVA ELSE I1.PU END) * case when nvl(i.moneda,0) = 0 then 1 else i.curs end Pret,
    I1.Cant * (CASE WHEN I.TIPDOC = 3 THEN I1.PU - I1.TVA ELSE I1.PU END) * case when nvl(i.moneda,0) = 0 then 1 else i.curs end Val,
    I1.RestImbMF + NVL(am.Amo, 0), OBJM.Denumire, MF.NrInventar, I.PrefixDoc||&apos;&apos;.&apos;&apos;||I.NrDoc||&apos;&apos;/&apos;&apos;||I.DataDoc, I.DataDoc, P.Den_Part, S.Den_Subunit, CIMB.SIMBOL, I1.Obs &apos;||gUserAlias||&apos;
  FROM INTRARI1_MAN I1
    INNER JOIN INTRARI I ON I1.CodIntr = I.CodIntr
    INNER JOIN MIFIX MF ON I1.CodMifix = MF.CodMifix
    INNER JOIN MIFIX1 MF1 ON MF.CodMifix = MF1.CodMifix
    INNER JOIN NIRSTOC NS ON MF1.CodNirStoc = NS.CodNirStoc
    INNER JOIN NARTOBJ OBJM ON NS.CodObiect = OBJM.CodObiect
    INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
    INNER JOIN NPART P ON P.CodPart = I.Partener
    LEFT  JOIN IESIRI IES ON IES.CODIES = I.CODINTR AND I.TIPDOC = IES.TIPDOC
    LEFT  JOIN NIRSTOC NSA ON NSA.CODNIRSTOC = I.CODINTR - I.CODINTR
    LEFT  JOIN NC NC ON IES.CODIES = NC.CODNC
    LEFT  JOIN NCONT CIMB ON CIMB.CODCONT = I1.CONTSERV
    LEFT  JOIN AMORTIZARI AM ON I1.CodIntr1 = am.CodIntr1
    LEFT  JOIN NSUBUNIT S ON I.Subunitatea = S.CodSubunit
    LEFT  JOIN NARTAMB AA ON AA.CODOBIECT = NS.CODOBIECT AND AA.UMSEC = NS.UMSEC&apos;||
    gSuplJoins||&apos;
  WHERE MF1.AnStart * 12 + MF1.LunaStart = (Select max(X1.AnStart * 12 + X1.LunaStart) from mifix1 X1 where X1.CodMifix = MF.CodMifix )&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  LIST_EXECUTE_IMMEDIATE(sPrepare, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert,  aListID, aListVer);

  DELETE FROM iesiri1_man;
  sPrepare :=
  &apos;INSERT INTO iesiri1_man
  SELECT i1.* FROM iesiri1 i1 INNER JOIN iesiri i on i1.codies = i.codies
  WHERE i1.CodMifix &gt; 0 AND i.an * 12 + i.luna &lt;= &apos;||sALLucru;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc, NAV_TipDoc, Art, Cant, Pret, Val, Rest, Mifix, NrInventar, DocIntr, Data, Partener, Subunitate, CImb, ObsLinie &apos;||gUserFields||&apos;)
  WITH amortizari as (
    select I1.CodIes1, sum(L.Cant) Amo, I1.Obs
    from TRANSF1 T1
      INNER JOIN TRANSF   T ON T1.CodTransf = T.CodTransf
      INNER JOIN IMBMIFIXLINK L ON T1.CodTransf1 = L.CodTransf1
      INNER JOIN IESIRI1 I1 ON L.CodIes1 = I1.CodIes1
    where (T.An * 12 + T.Luna &gt; &apos;||sALLucru||&apos;)
      and (T.An * 12 + T.Luna &lt;= &apos;||sALMax||&apos;)
      and T.Anulat &lt;&gt; 1 and T.Blocat &lt;&gt; 1 and T.Operat = 1
    GROUP BY I1.CodIes1, I1.Obs )
  SELECT
    IES.CODIES, IES.TIPDOC, OBJ.Denumire, COALESCE(L1.CANT,I1.Cant), (CASE WHEN IES.TIPDOC = 3 THEN I1.PU - I1.TVA ELSE I1.PU END),
    COALESCE(L1.CANT,I1.Cant) * (CASE WHEN IES.TIPDOC = 3 THEN I1.PU - I1.TVA ELSE I1.PU END), ((I1.RestImbMF + NVL(am.Amo, 0))/I1.Cant)*COALESCE(L1.CANT,I1.Cant),
    OBJM.Denumire, MF.NrInventar, IES.PrefixDoc||&apos;&apos;.&apos;&apos;||IES.NrDoc||&apos;&apos;/&apos;&apos;||IES.DataDoc, IES.DataDoc, P.Den_Part, S.Den_Subunit, CIMB.SIMBOL, I1.Obs &apos;||gUserAlias||&apos;
  FROM IESIRI1_MAN I1
    INNER JOIN IESIRI IES ON I1.CodIes = IES.CodIes
    INNER JOIN MIFIX MF ON I1.CodMifix = MF.CodMifix
    INNER JOIN MIFIX1 MF1 ON MF.CodMifix = MF1.CodMifix
    INNER JOIN NIRSTOC NS ON MF1.CodNirStoc = NS.CodNirStoc
    INNER JOIN NARTOBJ OBJM ON NS.CodObiect = OBJM.CodObiect
    INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
    LEFT  JOIN (
      SELECT L1.CODIES1, L.CODIES, L.TIPLIVR, L1.CANT, L1.CODNIRSTOC
      FROM LIVR1 L1 INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    ) L1 ON L1.CODIES1 = I1.CODIES1 AND L1.CODIES = IES.CODIES AND L1.TIPLIVR = IES.TIPDOC
    LEFT  JOIN NIRSTOC NSA ON NSA.CODNIRSTOC = L1.CODNIRSTOC
    LEFT  JOIN INTRARI I ON IES.CODIES = I.CODINTR AND I.TIPDOC = IES.TIPDOC
    LEFT  JOIN NC NC ON IES.CODIES = NC.CODNC
    LEFT  JOIN NCONT CIMB ON CIMB.CODCONT = I1.CONT
    LEFT  JOIN NPART P ON P.CodPart = NSA.FURN
    LEFT  JOIN AMORTIZARI AM ON I1.CodIes1 = am.CodIes1
    LEFT  JOIN NSUBUNIT S ON I.Subunitatea = S.CodSubunit
    LEFT  JOIN NARTAMB AA ON AA.CODOBIECT = NS.CODOBIECT AND AA.UMSEC = NS.UMSEC&apos;||
    gSuplJoins||&apos;
  WHERE MF1.AnStart * 12 + MF1.LunaStart = (Select max(X1.AnStart * 12 + X1.LunaStart) from mifix1 X1 where X1.CodMifix = MF.CodMifix )&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;Ies&apos;);

  LIST_EXECUTE_IMMEDIATE(sPrepare, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert,  aListID, aListVer);

  DELETE FROM nc1_man;
  sPrepare :=
  &apos;INSERT INTO nc1_man
  SELECT nc1.*
  FROM nc1 INNER JOIN nc ON nc1.codnc = NC.codnc
  WHERE nc1.CodMifix &gt; 0 AND nc.an * 12 + nc.luna &lt;= &apos;||sALLucru;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc, NAV_TipDoc, Art, Cant, Pret, Val, Rest, Mifix, NrInventar, DocIntr, Data, Partener, Subunitate, CImb, ObsLinie &apos;||gUserFields||&apos;)
  WITH amortizari as (
    select NC1.CodNC1, sum(L.Cant) Amo, NC1.Obs
    from TRANSF1 T1
      INNER JOIN TRANSF   T ON T1.CodTransf = T.CodTransf
      INNER JOIN IMBMIFIXLINK L ON T1.CodTransf1 = L.CodTransf1
      INNER JOIN NC1 ON L.CodNC1 = NC1.CodNC1
    where (T.An * 12 + T.Luna &gt; &apos;||sALLucru||&apos;)
      and (T.An * 12 + T.Luna &lt;= &apos;||sALMax||&apos;)
      and T.Anulat &lt;&gt; 1 and T.Blocat &lt;&gt; 1 and T.Operat = 1
    GROUP BY NC1.CodNC1, NC1.Obs
  )
  SELECT
    NC.CODNC, 35, NC1.Obs, 1 Cant, NC1.VALOARE PU,
    NC1.VALOARE,
    NC1.RestImbMF + NVL(am.Amo, 0), OBJM.Denumire, MF.NrInventar, &apos;&apos;NC.&apos;&apos;||NC.NrDoc||&apos;&apos;/&apos;&apos;||NC.DataDoc, NC.DataDoc, P.Den_Part, S.Den_Subunit, CIMB.Simbol, NC1.Obs &apos;||gUserAlias||&apos;
  FROM NC1_MAN NC1
    INNER JOIN NC NC ON NC.CodNC = NC1.CodNC
    INNER JOIN MIFIX MF ON NC1.CodMifix = MF.CodMifix
    INNER JOIN MIFIX1 MF1 ON MF.CodMifix = MF1.CodMifix
    INNER JOIN NIRSTOC NS ON MF1.CodNirStoc = NS.CodNirStoc
    INNER JOIN NARTOBJ OBJM ON NS.CodObiect = OBJM.CodObiect
    INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
    LEFT  JOIN IESIRI IES ON IES.CODIES = NC.CODNC AND IES.TIPTRANZACTIE = -99999
    LEFT  JOIN NIRSTOC NSA ON NSA.CODNIRSTOC = NC.CODNC - NC.CODNC
    LEFT  JOIN INTRARI I ON IES.CODIES = I.CODINTR AND IES.TIPDOC = I.TIPDOC
    LEFT  JOIN NCONT CIMB ON CIMB.CODCONT = NC1.CONTD
    LEFT  JOIN NPART P ON NC1.CODPART = P.CodPart
    LEFT  JOIN AMORTIZARI AM ON NC1.CodNC1 = am.CodNC1
    LEFT  JOIN NSUBUNIT S ON NC.Subunitatea = S.CodSubunit
    LEFT  JOIN NARTAMB AA ON AA.CODOBIECT = NS.CODOBIECT AND AA.UMSEC = NS.UMSEC&apos;||
    gSuplJoins||&apos;
  WHERE MF1.AnStart * 12 + MF1.LunaStart = (Select max(X1.AnStart * 12 + X1.LunaStart) from mifix1 X1 where X1.CodMifix = MF.CodMifix )&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;);

  LIST_EXECUTE_IMMEDIATE(sPrepare, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert,  aListID, aListVer);
  IF vCSintC IS NOT NULL THEN
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET CSintC = :vCSintC&apos; USING vCSintC;
  END IF;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


end pkg_list_base_imbmifix;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IMOBILIZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E87859CDB24512E615301232304ED2CBDEBB8D46</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IMOBILIZARI is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(2000);
  sSelect     VARCHAR2(10000);
  vCodNirStoc NUMBER(20);
  RecId       NUMBER(10);
  aLuna       NUMBER(2);
  aAn         NUMBER(4);
  aAL         NUMBER(5);
  dDataMax    DATE;
  aUserID     NUMBER(20);

  TYPE codmifix_tab IS TABLE OF NUMBER(20) INDEX BY PLS_INTEGER; 
  bulk_codmifix  codmifix_tab;
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NARTOBJ OBJ, NART ART, NARTOBJ IMB&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  aUserID  := pkg_globals.getuserid;
  aLuna    := pkg_list_selectluna.LunaFin;
  aAn      := pkg_globals.GetANLUCRU;
  aAL      := aAn*12+aLuna;
  dDataMax := LAST_DAY(TO_DATE(&apos;01.&apos;||TO_CHAR(ALUNA,&apos;fm00&apos;)||&apos;.&apos;||TO_CHAR(AAN,&apos;fm0000&apos;),&apos;DD.MM.YYYY&apos;));

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  PKG_CATEGCONST.UMPLE_TMP_CODCONT_CONST(
    ESTEMIFIX             =&gt; TRUE,
    ESTEIMBUNATATIREMIFIX =&gt; TRUE
  );

  DELETE TMP_LST_FISAIMOB WHERE USERID = PKG_GLOBALS.GETUSERID;

  --FISAMF -&gt; CODOPERATIE 
  -- 1 &apos;Creare mijloc fix&apos;
  -- 2 &apos;Transfer intre gestiuni&apos;
  -- 3 &apos;Modificare de pret&apos;
  -- 4 &apos;Casare&apos;
  -- 5 &apos;Vanzare&apos;
  -- 6 &apos;Reevaluare - valoare MF&apos;
  -- 7 &apos;Reevaluare - amortizare prec&apos;
  -- 8 &apos;Marire de stoc&apos;
  -- 9 &apos;Modificare gestiune&apos;
  --10 &apos;Modificare centru de cost&apos;
  --11 &apos;Modificare tip contabil&apos;
  --12 &apos;Punere in functiune&apos;

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, IES.CODIES CODDOC, IES.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, IES1.CODIES1 IndexLocal,
    nvl(OBJ.DENUMIRE,objmf.denumire) denumire, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC, F.CANT,
    nvl(F.CANT,1) * F.PRETI VALOARE, IES1.TVA, IES.DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    &apos;Intrare in firma&apos; TIPOPERATIE,
    0 Dirty, IES.AN, IES.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    0 IMBUNATATIRE, IES.DATADOC DATAOP, 1 ORDINE, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 1 AND FMF.tipdoc = 15
  ) F
    INNER JOIN MIFIX M ON m.codmifix = f.codmifix
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsmf on nsmf.codnirstoc = mf1.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsmf.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    INNER JOIN nartobj objmf on objmf.codobiect = nsmf.codobiect
    LEFT JOIN IESIRI1 IES1 ON IES1.CODIES1 = F.CODDOC1
    LEFT JOIN IESIRI IES ON IES.CODIES = IES1.CODIES AND IES.TIPDOC = F.TIPDOC AND Coalesce(IES.AN*12+IES.LUNA,0) &lt;= aAL
    LEFT JOIN NIR NIR ON NIR.CODIES = IES.CODIES
    LEFT JOIN INTRARI I ON I.CODINTR = NIR.CODINTR
    LEFT JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR AND IES1.CODOBIECT = I1.CODOBIECT
    LEFT JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODINTR1 = I1.CODINTR1
    LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND IES.AN*12+IES.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC, F.CANT CANT,
    F.CANT * F.PRETE VALOARE, T1.TVA, T.DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    &apos;Transfer intre gestiuni&apos; TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    0 IMBUNATATIRE, F.DATAOPERATIE DATAOP, CASE WHEN Coalesce(TCC.ESTEMIFIX, 0) &gt; 0 THEN 12 ELSE 2 END ORDINE, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 2 AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsmf on nsmf.codnirstoc = mf1.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsmf.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN*12+T.LUNA &lt;= aAL
    AND (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, II.CODINTR CODDOC, II.TIPDOC TIPDOC, T.CODTRANSF CODDOCSEC, T.TIPDOC TIPDOCSEC, II1.CODINTR1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, P.DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, II1.PU * case when nvl(II.Moneda,0) = 0 then 1 else II.Curs end PRETE, II.PREFIXDOC, II.NRDOC, II1.CANT CANT,
    II1.CANT * II1.PU * case when nvl(II.Moneda,0) = 0 then 1 else II.Curs end VALOARE, II1.TVA, II.DATADOC DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    CASE
      WHEN II.TIPDOC = 1 AND II.TIPFACTURA = 2 THEN &apos;Leasing&apos;
      WHEN II.TIPDOC = 1 AND nvl(II.TIPFACTURA,0) = 0 THEN &apos;Factura intrare&apos;
      WHEN II.TIPDOC = 5 THEN &apos;Factura intrare din import&apos;
    END TIPOPERATIE,
    0 Dirty, II.AN, II.LUNA, NVL(P.CODPART,0) CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    II1.CODOBIECT IMBUNATATIRE, F.DATAOPERATIE DATAOP, CASE WHEN Coalesce(TCC.ESTEMIFIX, 0) &gt; 0 THEN 12 ELSE 2 END ORDINE, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 3 AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN IMBMIFIXLINK L ON L.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN INTRARI1 II1 ON II1.CODINTR1 = L.CODINTR1
    INNER JOIN INTRARI II ON II.CODINTR = II1.CODINTR
    INNER JOIN NPART P ON P.CODPART = II.PARTENER
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN IOART IOA ON IOA.CODIOART = IOA1.CODIOART
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsmf on nsmf.codnirstoc = mf1.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsmf.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN*12+T.LUNA &lt;= aAL
    AND (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    obj.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC, F.CANT,
    F.CANT * F.PRETE VALOARE, T1.TVA, T.DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    CASE
      WHEN F.CODOPERATIE = 6 THEN &apos;Reevaluare - valoare MF&apos;
      WHEN F.CODOPERATIE = 7 THEN &apos;Reevaluare - amortizare prec&apos;
      WHEN F.CODOPERATIE = 9 THEN &apos;Modificare gestiune&apos;
      WHEN F.CODOPERATIE = 10 THEN &apos;Modificare centru de cost&apos;
      WHEN F.CODOPERATIE = 11 THEN &apos;Modificare tip contabil&apos;
    END TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    0 IMBUNATATIRE, F.DATAOPERATIE DATAOP, CASE WHEN Coalesce(TCC.ESTEMIFIX, 0) &gt; 0 THEN 12 ELSE 2 END ORDINE, aUserID
  FROM  (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE IN (6,7,9,10,11) AND FMF.TIPDOC IN (12, 13)
  ) F
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    INNER JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF
    INNER JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsmf on nsmf.codnirstoc = mf1.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsmf.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE T.AN * 12 + T.LUNA &lt;= aAL
    AND (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, T.CODTRANSF CODDOC, T.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, T1.CODTRANSF1 IndexLocal,
    objm.DENUMIRE, M.NrInventar, &apos; &apos; DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE PRETE, F.PREFIXDOC PREFIXDOC, F.NRDOC NrDoc, F.CANT CANT,
    F.CANT * F.PRETE VALOARE, T1.TVA, nvl(T.DATADOC,F.dataoperatie) DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    &apos;Punere in functiune&apos; TIPOPERATIE,
    0 Dirty, T.AN, T.LUNA, 0 CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CodNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    0 IMBUNATATIRE, F.DATAOPERATIE DATAOP, 3 ORDINE, aUserID
  FROM (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE = 12 AND tipdoc = 12 AND FMF.DATAOPERATIE &lt;= dDataMax
  ) F
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsm on mf1.codnirstoc = nsm.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsm.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    INNER JOIN nartobj objm on objm.codobiect = nsm.codobiect
    LEFT JOIN TRANSF1 T1 ON T1.CODTRANSF1 = F.CODDOC1
    LEFT JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF AND F.TIPDOC = T.TIPDOC
    LEFT JOIN NIR NIR ON NIR.CODTRANSF = T.CODTRANSF
    LEFT JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
    LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  INSERT INTO TMP_LST_FISAIMOB (
    codnirstoc, coddoc, tipdoc, coddocsec, tipdocsec, indexlocal,
    denumire, nrinventar, den_part,
    codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant,
    valoare, tva, datadoc, obs,
    mf,
    imbmf,
    tipoperatie,
    dirty, an, luna, codpart, codpartsec, coddoc1, codns, codioart1, codmifix1,
    IMBUNATATIRE, DATAOP, ORDINE, userid
  )
  SELECT
    NS.CODNIRSTOC, IES.CODIES CODDOC, IES.TIPDOC TIPDOC, 0 CODDOCSEC, 0 TIPDOCSEC, IES1.CODIES1 IndexLocal,
    OBJ.DENUMIRE, M.NrInventar, P.DEN_PART,
    F.CODMIFIX, F.CODOPERATIE, F.DATAOPERATIE, F.GESTSURSA, F.GESTDEST, F.PRETI, F.PRETE, F.PREFIXDOC, F.NRDOC, F.CANT,
    F.CANT * F.PRETE VALOARE, CASE WHEN f.codoperatie = 5 THEN 0 ELSE IES1.TVA END TVA, IES.DATADOC, F.OBS,
    Coalesce(TCC.ESTEMIFIX, 0) MF,
    Coalesce(TCC.ESTEIMBUNATATIREMIFIX, 0) IMBMF,
    CASE
      WHEN F.CODOPERATIE = 4 THEN &apos;Casare&apos;
      WHEN F.CODOPERATIE = 5 THEN &apos;Vanzare&apos;
    END TIPOPERATIE,
    0 Dirty, IES.AN, IES.LUNA, NVL(P.CODPART,0) CODPART, 0 CODPARTSEC, F.CodDoc1, 0 CODNS, IOA1.CODIOART1, mf1.CODMIFIX1,
    0 IMBUNATATIRE, F.DATAOPERATIE, CASE WHEN Coalesce(TCC.ESTEMIFIX, 0) &gt; 0 THEN 12 ELSE 2 END ORDINE, aUserID
  FROM  (
    SELECT FMF.*, (SELECT Min(MF1.ANSTART*12+MF1.LUNASTART) FROM mifix1 mf1 WHERE mf1.codmifix = fmf.codmifix) al_mf1
    FROM FISAMF FMF
    WHERE FMF.CODOPERATIE IN (4,5)AND tipdoc IN (14, 19, 20, 21, 22, 23) 
  ) F
    INNER JOIN IESIRI1 IES1 ON IES1.CODIES1 = F.CODDOC1
    INNER JOIN IESIRI IES ON IES.CODIES = IES1.CODIES AND IES.TIPDOC = F.TIPDOC
    INNER JOIN LIVR L ON L.CODIES = IES1.CODIES AND L.TIPLIVR = F.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = IES1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND IES.AN*12+IES.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR AND Coalesce(NIR.CODIES,0) &lt;&gt; IES.CODIES
    INNER JOIN MIFIX M ON M.CODMIFIX = F.CODMIFIX
    INNER JOIN MIFIX1 MF1 on mf1.codmifix = f.codmifix AND mf1.anstart*12+mf1.lunastart = f.al_mf1
    INNER JOIN nirstoc nsmf on nsmf.codnirstoc = mf1.codnirstoc
    INNER JOIN nir nirmf on nirmf.codnir = nsmf.codnir
    INNER JOIN ngest g on g.codgest = nirmf.gest
    LEFT JOIN NPART P ON P.CODPART = IES.PARTENER
    LEFT JOIN TMP_CODCONT_CONST TCC ON TCC.CODCONT = IOA1.CONT
  WHERE IES.AN * 12 + IES.LUNA &lt;= aAL
    and (pkg_globals.getsubunitate = 1 or pkg_globals.getsubunitate = g.codsubunit);

  DELETE tmp_lst_fisaimob WHERE CodOperatie IN (4, 5, 6, 7);
  DELETE tmp_lst_fisaimob WHERE MF = 1 AND codoperatie &lt;&gt; 12;

  SELECT codmifix
  BULK COLLECT INTO bulk_codmifix
  FROM tmp_lst_fisaimob
  GROUP by codmifix
  HAVING count(1) = 1 AND Max(codoperatie) = 12;

  FORALL indx IN 1 .. bulk_codmifix.COUNT DELETE tmp_lst_fisaimob WHERE codmifix = bulk_codmifix(indx);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     NrInventar, Articol, Cont, Den_IOArt, ValIntr, Clasificare, TimpNormat, Durata,
     TipAmo,
     DataPunere, Tip, Partener, Doc,
     Cant, Pret, Valoare, TVA, DATAOP, ORDINE,
     Rest_fake1 &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    tmp.NrInventar, tmp.denumire Articol, c.simbol Cont, ioa.Den_IOArt, mfl.cant * mfl.pret ValIntr, cls.denumire Clasificare, cls.durata TimpNormat, cls.durata*12 Durata,
    case
      when mf1.tipamo = 1 then &apos;&apos;Liniara&apos;&apos;
      when mf1.tipamo = 2 then &apos;&apos;Accelerata&apos;&apos;
      when mf1.tipamo = 3 then &apos;&apos;Degresiva 1&apos;&apos;
      when mf1.tipamo = 4 then &apos;&apos;Degresiva 2&apos;&apos;
    end TipAmo,
    ev.datastart DataPunere, tmp.tipoperatie Tip, tmp.den_part Partener, tmp.nrdoc||&apos;&apos;/&apos;&apos;||to_char(tmp.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) Doc,
    tmp.cant, tmp.prete Pret, tmp.Valoare, tmp.TVA, TMP.DATAOP, nvl(TMP.ORDINE,0) ORDINE,
    CASE
      WHEN TMP.CODOPERATIE = 12 THEN - TMP.VALOARE
      WHEN TMP.CODOPERATIE IN (4,5) THEN 0
      WHEN TMP.CODOPERATIE IN (6,7,9,10,11) THEN 0
      WHEN TMP.CODOPERATIE = 3 THEN TMP.VALOARE
      WHEN TMP.CODOPERATIE = 1 THEN TMP.VALOARE
      ELSE 0
    END REST_FAKE1 &apos;||gUserAlias||&apos;
  FROM tmp_lst_fisaimob tmp
    LEFT JOIN transf1 t1 on tmp.coddoc1 = t1.codtransf1 and tmp.codoperatie = 3
    LEFT JOIN nartobj imb on tmp.imbunatatire = imb.codobiect
    LEFT JOIN ioart1 ioa1 on ioa1.codioart1 = tmp.codioart1
    LEFT JOIN ioart ioa on ioa.codioart = ioa1.codioart
    LEFT JOIN ncont c on ioa1.cont = c.codcont
    LEFT JOIN mifix1 mf1 on tmp.codmifix1 = mf1.codmifix1
    LEFT JOIN mifix1 mfl on mfl.codmifix = tmp.codmifix
    LEFT JOIN mfclasif cls on cls.codclasif = mfl.codclasif
    LEFT JOIN evidentamf ev on ev.codmifix = tmp.codmifix
    LEFT JOIN nirstoc ns on mfl.codnirstoc = ns.codnirstoc
    LEFT JOIN nartobj obj on obj.codobiect = ns.codobiect
    LEFT JOIN nart art on art.codarticol = obj.codarticol &apos;||
    gSuplJoins||&apos;
  WHERE userid = pkg_globals.getuserid
    AND mfl.anstart*12+mfl.lunastart=(select max(mf2.anstart*12+mf2.lunastart) from mifix1 mf2 where mf2.codmifix = mfl.codmifix)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_IMOBILIZARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IMPORTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7349D52CB3AB125460D1F8CC44895B29A2B1CD6C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_importuri IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION getaccizelinie(acoddvi1 in number) return number is
  aCodDVI number(20);
  aIndexLocal number(10);
  aProc number(20,7);
  gasittaxe number(1);
begin
  select nvl(coddvi, 0) into aCodDVI from dvi1 where coddvi1 = acoddvi1;
  select nvl(indexlocal, 0) into aIndexLocal from dvi1 where coddvi1 = acoddvi1;
  aProc := 0;
  gasittaxe := 0;
  for v_rec in (select * from dvi1 where coddvi = aCodDVI and indexlocal &gt;= aindexlocal order by indexlocal) loop
    exit when (v_Rec.Tiplinie in (&apos;=&apos;, &apos;S&apos;)) and (gasittaxe = 1);
    if v_Rec.Tiplinie in (&apos;A&apos;, &apos;X&apos;, &apos;C&apos;) then
      gasittaxe := 1;
    end if;
    if v_Rec.Tiplinie = &apos;A&apos; then
      aProc := aProc + v_Rec.Cant;
    end if;
  end loop;
  return aProc;
end;

function getcomisionlinie(acoddvi1 in number) return number is
  aCodDVI number(20);
  aIndexLocal number(10);
  aProc number(20,7);
  gasittaxe number(1);
begin
  select nvl(coddvi, 0) into aCodDVI from dvi1 where coddvi1 = acoddvi1;
  select nvl(indexlocal, 0) into aIndexLocal from dvi1 where coddvi1 = acoddvi1;
  aProc := 0;
  gasittaxe := 0;
  for v_rec in (select * from dvi1 where coddvi = aCodDVI and indexlocal &gt;= aindexlocal order by indexlocal) loop
    exit when (v_Rec.Tiplinie in (&apos;=&apos;, &apos;S&apos;)) and (gasittaxe = 1);
    if v_Rec.Tiplinie in (&apos;A&apos;, &apos;X&apos;, &apos;C&apos;) then
      gasittaxe := 1;
    end if;
    if v_Rec.Tiplinie = &apos;C&apos; then
      aProc := aProc + v_Rec.Cant;
    end if;
  end loop;
  return aProc;
end;

function gettaxelinie(acoddvi1 in number) return number is
  aCodDVI number(20);
  aIndexLocal number(10);
  aProc number(20,7);
  gasittaxe number(1);
begin
  select nvl(coddvi, 0) into aCodDVI from dvi1 where coddvi1 = acoddvi1;
  select nvl(indexlocal, 0) into aIndexLocal from dvi1 where coddvi1 = acoddvi1;
  aProc := 0;
  gasittaxe := 0;
  for v_rec in (select * from dvi1 where coddvi = aCodDVI and indexlocal &gt;= aindexlocal order by indexlocal) loop
    exit when (v_Rec.Tiplinie in (&apos;=&apos;, &apos;S&apos;)) and (gasittaxe = 1);
    if v_Rec.Tiplinie in (&apos;A&apos;, &apos;X&apos;, &apos;C&apos;) then
      gasittaxe := 1;
    end if;
    if v_Rec.Tiplinie = &apos;X&apos; then
      aProc := aProc + v_Rec.Cant;
    end if;
  end loop;
  return aProc;
end;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(5000);
  sSelect  VARCHAR2(20000);
  vLunaIni INTEGER;
  vLunaFin INTEGER;
  vAn      INTEGER;
BEGIN

  gSuplCols := &apos;DVI DVI, DVI1 DVI1, INTRARI I, INTRARI1 I1, NARTOBJ OBJ, NART ART, NUM1, NMONEDE MON, NPART P, NAGENDA AG, NLOCALIT LOC, NTARI T, NPART VAMA,&apos;||
               &apos;OBLIGPIF O, NCLASEA CLA, NCLASEP CLP, NARTAMB AA, NTARI TARAORIG&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vLunaIni    := PKG_LIST_SELECTLUNAAN.LunaStart;
  vLunaFin    := PKG_LIST_SELECTLUNAAN.LunaStop;
  vAn         := Pkg_GLOBALS.ANLUCRU;


  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, Denumire, UM, Cant, PUInvoice, Moneda, ValInvoice, CursVama,
    TaxaVamala, ValTaxaVamala,
    ComVamal, ValComVamal,
    AccizeVamale, ValAccizeVamale,
    PUImport, PUImpValuta, ValImport, ValTVAImport, TaraPart, UE, Obs,
    ClasaArt, ClasaPart, Partener, NrInvoice, DataInvoice, Vama, NrDVI, DataDVI, Doc, Masa, Volum,
    CodExtern, Operat, Majorari, Scadenta, CodIntern,
    TipInvoice, Supliment, SuplimentProc,
    ANDOC,LUNADOC,LUNA &apos;||gUserFields||&apos;) &apos;;

  sSelect := &apos;
  WITH
    Scadente as (
      select dvi.coddvi, MAX(o.codobligpif) keep (dense_rank last ORDER BY o.termen) codobligpif
      from dvi
        inner join intrari i on dvi.codintr = i.codintr
        inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
        inner join obligpif o on o.codgeneral = g.codgeneral
      where i.an * 12 + i.luna between &apos;||vLunaIni||&apos; and &apos;||vLunaFin||&apos;
        and i.anulat &lt;&gt; 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      group by dvi.coddvi ),
    MasaVolum as (
      SELECT dvi1.coddvi1, SUM(nvl(O.MASA, 0) * I1.CANT) MASA, SUM(nvl(O.VOLUM, 0)* I1.CANT) VOLUM
      FROM dvi
        inner join dvi1 on dvi.coddvi = dvi1.coddvi
        inner join intrari1 i1 on dvi1.codintr1 = i1.codintr1
        inner join intrari i on dvi.codintr = i.codintr and i1.codintr = i.codintr
        inner join NARTOBJ O on dvi1.codobiect = o.codobiect
      WHERE i1.tiplinie = &apos;&apos;=&apos;&apos;
        and i.an * 12 + i.luna between &apos;||vLunaIni||&apos; and &apos;||vLunaFin||&apos;
        and i.anulat &lt;&gt; 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      group by dvi1.coddvi1 )
  SELECT
    I.CodIntr, I.TipDoc, OBJ.Denumire, num1.den_UM1, dvi1.Cant, i1.PU PUInvoice, mon.den_moneda, i1.PU * i1.Cant, I.curs,
    pkg_list_base_importuri.gettaxelinie(dvi1.coddvi1),
    pkg_list_base_importuri.gettaxelinie(dvi1.coddvi1)/100 * DVI1.PretOriginal * DVI1.Cant,
    pkg_list_base_importuri.getcomisionlinie(dvi1.coddvi1),
    pkg_list_base_importuri.getcomisionlinie(dvi1.coddvi1)/100 * DVI1.PretOriginal * DVI1.Cant,
    pkg_list_base_importuri.getaccizelinie(dvi1.coddvi1),
    pkg_list_base_importuri.getaccizelinie(dvi1.coddvi1)/100 * DVI1.PretOriginal * DVI1.Cant,
    DVI1.PretImport, DVI1.PretValuta, DVI1.PretImport * DVI1.Cant, DVI1.TVA, t.den_tara, DECODE(t.statcomunitar,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), DVI.Obs,
    cla.den_clasea, clp.den_clasep, p.den_part, i.nrdoc, i.datadoc, vama.den_part, dvi.nrdoc, dvi.datadoc, i.prefixdoc, MV.Masa, MV.Volum,
    OBJ.CodExtern, DECODE(i.operat,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), o.Majorari, o.termen, OBJ.CodIntern,
    DECODE(DVI.TipImport,0,&apos;&apos;Import definitiv&apos;&apos;,&apos;&apos;Import temporar&apos;&apos;), DVI1.ADDIM * DVI1.PretOriginal * DVI1.Cant / 100, DVI1.ADDIM,
    i.an andoc, i.luna lunadoc, to_char(i.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(i.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(i.Luna) luna &apos;||gUserAlias||&apos;
  FROM DVI
    inner join dvi1 on dvi.coddvi = dvi1.coddvi
    inner join intrari   I on DVI.CodIntr  = I.CodIntr
    inner join intrari1 I1 on I.CodIntr    = I1.CodIntr and i1.codintr1 = dvi1.codintr1
    inner join nartobj OBJ on dvi1.codobiect = OBJ.CodObiect
    inner join nart art on obj.codarticol = art.CodArticol
    inner join num1 on dvi1.umsec = num1.codum1
    inner join nmonede mon on nvl(i.moneda, 0) = mon.codmoneda
    inner join npart p on i.partener = p.codpart
    inner join Scadente SC on dvi.coddvi = sc.coddvi
    inner join obligpif o on sc.codobligpif = o.codobligpif
    left  join nagenda ag on ag.codpart = p.codpart and ag.sediusocial BETWEEN 4 AND 7 AND NVL(ag.INACTIV, 0) = 0
    left  join nlocalit loc on ag.codlocalit = loc.codlocalit
    left  join ntari t on loc.codtara = t.codtara
    left  join npart vama on dvi.codvama = vama.codpart
    left  join nclasea cla on art.clasa = cla.codclasea
    left  join nclasep clp on p.codclasa = clp.codclasep
    left  join MasaVolum MV on DVI1.CodDvi1 = MV.CodDvi1
    left  join NTARI TARAORIG on OBJ.TARAORIGINE = TARAORIG.CodTara
    left  join nartamb aa ON aa.codobiect = dvi1.codobiect AND aa.umsec = dvi1.umsec
    left  join (select DVI.CodDVI, sum(DVI1.PretImport * DVI1.Cant) VAL from DVI1 inner join DVI on DVI1.CodDVI = DVI.CodDVI group by DVI.CodDVI) ValImport on DVI.CodDVI = ValImport.CodDVI&apos;||
    gSuplJoins||&apos;
  where i.an *12 + i.luna between &apos;||vLunaIni||&apos; and &apos;||vLunaFin||&apos;
    and i.anulat &lt;&gt; 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_importuri; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INCFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB4AE61EEC3F73C7007F41480B4A40AEB6D6243D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INCFACT IS

  gUserFields    VARCHAR2(2500);
  gUserAlias     VARCHAR2(2500);
  gNullAlias     VARCHAR2(2500);
  gSuplCols      VARCHAR2(2500);
  gSuplJoins     VARCHAR2(5000);

  sInsert        VARCHAR2(2000);
  sSel           VARCHAR2(30000);
  sSelI          VARCHAR2(30000);
  sSelect        VARCHAR2(30000);
  sSelectI       VARCHAR2(30000);
  sSelect_Ini    VARCHAR2(30000);
  sSelect_Tip7   VARCHAR2(30000);
  sSelect_Mon    VARCHAR2(30000);
  sSelect_Doc0   VARCHAR2(30000);
  sSelect_InfoCM VARCHAR2(30000);
  sSelect_Fact   VARCHAR2(30000);
  sSelectFN      VARCHAR2(30000);
  sAnP           VARCHAR2(    4);
  sLunaP         VARCHAR2(    4);
  sFAdaosDoc     VARCHAR2( 5000);
  sTrezorData    VARCHAR2(  100);
  an             NUMBER(4);
  luna           NUMBER(2);
  sFiltruAG      VARCHAR2(  500) := &apos;&apos;;
  sFiltruPart    VARCHAR2(  500) := &apos;&apos;;

  gDataS         VARCHAR2(   10);
  gDataF         VARCHAR2(   10);
  gAnual         BOOLEAN;
  gOpt1          BOOLEAN;
  gOpt2          BOOLEAN;
  gOpt3          BOOLEAN;
  gOpt4          BOOLEAN;
  gDataRef       VARCHAR2(   10);
  gAllAg         BOOLEAN;
  gAllPart       BOOLEAN;
  gCriteriu      NUMBER(1);
  gSumarIncFact  BOOLEAN;
  gTotFact       BOOLEAN;

PROCEDURE setParams(pDataS    IN VARCHAR2 DEFAULT NULL,
                      pDataF    IN VARCHAR2 DEFAULT NULL,
                      pAnual    IN NUMBER DEFAULT 0,
                      pOpt1     IN NUMBER DEFAULT 0,
                      pOpt2     IN NUMBER DEFAULT 0,
                      pOpt3     IN NUMBER DEFAULT 0,
                      pOpt4     IN NUMBER DEFAULT 0,
                      V_CODJOB1 IN NUMBER  DEFAULT 0,
                      pDataRef IN VARCHAR2 DEFAULT NULL,
                      pAllAg    IN NUMBER DEFAULT 1,
                      pAllPart  IN NUMBER DEFAULT 1,
                      pCriteriu IN NUMBER  DEFAULT 0,
                      pSumarIncFact IN NUMBER DEFAULT 0,
                      pTotFact  IN NUMBER DEFAULT 0
                      )
IS
  xLunaAnIni integer;
  xLunaAnFin integer;
BEGIN
  gDataS     := pDataS;
  gDataF     := pDataF;
  xLunaAnIni := Extract(Year from to_date(gDataS,&apos;dd.mm.yyyy&apos;))*12 + 1;
  xLunaAnFin := Extract(Year from to_date(gDataF,&apos;dd.mm.yyyy&apos;))*12;

  if V_CODJOB1 &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,gDataS,gDataF,xLunaAnIni,xLunaAnFin);
  end if;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(to_date(gDataS,&apos;dd.mm.yyyy&apos;), to_date(gDataF,&apos;dd.mm.yyyy&apos;));

  gAnual        := pAnual = 1;
  gOpt1         := pOpt1 = 1;
  gOpt2         := pOpt2 = 1;
  gOpt3         := pOpt3 = 1;
  gOpt4         := pOpt4 = 1;
  gDataRef      := pDataRef;
  gAllAg        := pAllAg = 1;
  gAllPart      := pAllPart = 1;
  gCriteriu     := pCriteriu;
  gSumarIncFact := pSumarIncFact = 1;
  gTotFact      := pTotFact = 1;
END;

FUNCTION GetAdaos2(aCodies number, aTipDoc number) return number is
  vAdaos NUMBER(20, 7);
BEGIN
  IF aTipDoc = 26 THEN
    BEGIN
      SELECT
        SUM( ( i1.pretorig * NVL(i1.coefdiscmaj, 1) * Decode(I.Curs, NULL, 1, 0, 1, I.Curs) - DECODE(lv.codlivrval, NULL, ns.pret - ns.adaos, lv.pretachiz) ) * l1.cant * i1.cant / decode(nvl(a1.cant, 0), 0, 1, a1.cant) )
      INTO vAdaos
      FROM iesiri1 i1
        INNER JOIN iesiri i ON i1.codies = i.codies
        INNER JOIN ieslink il ON il.codies1 = i1.codies1
        INNER JOIN iesiri1 a1 ON a1.codies1 = il.codlinieaviz
        INNER JOIN livr l ON l.codies = a1.codies
        INNER JOIN livr1 l1 ON l1.codies1 = a1.codies1 AND l1.codlivr = l.codlivr
        LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
      WHERE i1.codies = aCodIes AND i1.tiplinie = &apos;=&apos;;
    exception WHEN others THEN
      vAdaos := 0;
    END;
  ELSE
    BEGIN
      SELECT
        SUM( ( i1.pretorig * NVL(i1.coefdiscmaj, 1) * Decode(I.Curs, NULL, 1, 0, 1, I.Curs) - DECODE(lv.codlivrval, NULL, ns.pret - ns.adaos, lv.pretachiz) -
               (CASE
                  WHEN aTipDoc IN (16, 21) THEN NVL(i1.tva, 0) * Decode(i1.pu, 0, 1, i1.pretorig/i1.pu) * NVL(i1.coefdiscmaj, 1) * Decode(I.Curs, NULL, 1, 0, 1, I.Curs) / i1.cant
                  ELSE 0
                END ) ) * l1.cant )
      INTO vAdaos
      FROM iesiri1 i1
        INNER JOIN iesiri i ON i1.codies = i.codies
        INNER JOIN livr l ON l.codies = i1.codies
        INNER JOIN livr1 l1 ON l1.codies1 = i1.codies1 AND l1.codlivr = l.codlivr
        LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
      WHERE i1.codies = aCodIes  AND i1.tiplinie = &apos;=&apos;;
    exception WHEN others THEN
      vAdaos := 0;
    END;
  END IF;
  return vAdaos;
END;

function GetValAchiz(aCodIes number) return number is
aVal number(20,7);
begin
  aVal := 0;
  begin
    select sum(nvl(va,0)) into aVal from
    (
    select
      sum(
      case
        when i1.tiplinie = &apos;S&apos; then i1.cant * i1.pu
        else
          case
            when ns.codnirstoc &gt; 0 then (ns.pret - nvl(adaos,0)) * l1.cant
            else lv.pretachiz * l1.cant
          end
      end) va
    from iesiri i
         inner join iesiri1 i1 on i.codies = i1.codies
         inner join livr l on l.codies = i.codies
         inner join livr1 l1 on l1.codlivr = l.codlivr and l1.codies1 = i1.codies1
         left join nirstoc ns on ns.codnirstoc = l1.codnirstoc
         left join livrval lv on lv.codlivr1 = l1.codlivr1
    where i.codies = aCodIes and
          not exists (select lk.codies1
                      from ieslink lk
                           inner join iesiri1 i1 on i1.codies1 = lk.codlinieaviz
                      where i1.codies1 = lk.codies1
                      )
    union all
    select
      sum(
      case
        when i1.tiplinie = &apos;S&apos; then i1.cant * i1.pu
        else
          case
            when ns.codnirstoc &gt; 0 then (ns.pret - nvl(adaos,0)) * l1.cant
            else lv.pretachiz * l1.cant
          end
      end) va
    from iesiri ii
         inner join iesiri1 ii1 on ii.codies = ii1.codies
         inner join ieslink ll on ll.codies1 = ii1.codies1
         inner join iesiri1 i1 on i1.codies1 = ll.codlinieaviz
         inner join iesiri i on i.codies = i1.codies
         inner join livr l on l.codies = i.codies
         inner join livr1 l1 on l1.codlivr = l.codlivr and l1.codies1 = i1.codies1
         left join nirstoc ns on ns.codnirstoc = l1.codnirstoc
         left join livrval lv on lv.codlivr1 = l1.codlivr1
    where ii.codies = aCodIes
    );
  exception when others then aVal := 0;
  end;
  return aVal;
end;

FUNCTION GetValMarfa(aCodies number) return number is
vVal NUMBER(20, 7);
BEGIN
  BEGIN
    SELECT
      SUM((i1.pu * i1.cant * NVL(i1.coefdiscmaj, 1) + i1.tva) * Decode(I.Curs, NULL, 1, 0, 1, I.Curs))
    INTO vVal
    FROM iesiri1 i1
      INNER JOIN iesiri i ON i1.codies = i.codies
    WHERE i1.codies = aCodIes AND i1.tiplinie = &apos;=&apos;;
  exception WHEN others THEN
    vVal := 0;
  END;

  return vVal;
END;

FUNCTION doc0(aCodIes NUMBER) return number is
acount number(10);
BEGIN
  SELECT count(g.codgeneral) into acount
  FROM general g
       INNER JOIN iesiri i ON i.tipdoc = g.tipdoc AND i.codies = g.coddoc
  where g.semnificatie = 211 AND i.codies = acodies;
  return acount;
END;

FUNCTION StingereValida(aCodDoc in number, aTipDoc in number) return number is
semnif number(20);
BEGIN
  BEGIN
    SELECT semnificatie into semnif FROM general where coddoc = acoddoc AND tipdoc = atipdoc;
  exception WHEN others THEN semnif := 600;
  END;
  IF semnif &lt;&gt; 600 THEN
    Return 1;
  ELSE
    return 0;
  END IF;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;npers ag, nagenda sed, npart p, npart1 p1, nmonede mon, centrecost cc, ngest g, nclaseg cg, nclasep cp, nlocalit sedloc, &apos;||
               &apos;njudet sedjud, ntipsedii sedtip, nsubunit ssting, nsubunit sstins, nsubunit scec, trezor1 t1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,       &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;ISTINS&apos;,   &apos;ISTINS.CODIES = X.CODDOCS&apos;,        1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OBLIGPIF&apos;,   &apos;OSTINS&apos;,   &apos;OSTINS.CODOBLIGPIF = X.CODOBLIGS&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NBANKCONT&apos;,  &apos;BC&apos;,       &apos;BC.CODBANKCONT = X.CODBANKCONT&apos;,   1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NBANK&apos;,      &apos;B&apos;,        &apos;B.CODBANK = BC.CODBANK&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;, &apos;STINS_CC&apos;, &apos;STINS_CC.CODCARNET = X.CDSTINS&apos;,   1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;, &apos;STING_DC&apos;, &apos;STING_DC.CODCARNET = X.CDSTING&apos;,   1);

  pkg_list_struct.GetSuplCols(aLISTID, alistver, gUserFields, gUserAlias, gNullAlias, gSuplJoins, gSuplCols);

  pkg_setluni.GetLunaInitiala(an, luna);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, sAnP, sLunaP);

  IF gOpt2 THEN
    sTrezorData := &apos;t1.datadoc&apos;;
  ELSE
    sTrezorData := &apos;CASE WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END&apos;;
  END IF;

  sFiltruAG := &apos;&apos;;
  IF NOT gAllAg THEN
    sFiltruAG :=&apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPERS&apos;&apos; and I.AGENT = VALOARE)&apos;;
  END IF;
  sFiltruPart := &apos;&apos;;
  IF NOT gAllPart THEN
    sFiltruPart :=&apos;
      AND EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; and I.PARTENER = VALOARE)&apos;;
  END IF;

  if gCriteriu = 0 then
  sFAdaosDoc := &apos;
      CASE
        WHEN nvl(stinsi.AdaosDoc, 0) &lt;&gt; 0 THEN stinsi.AdaosDoc * (stinsi.restval - (
          SELECT Nvl(SUM(s.valoare * (CASE WHEN OS.SEMNIFICATIE IN (211, 420, 751, 1300) AND O.SEMNIFICATIE &lt;&gt; 600 THEN -1 ELSE 1 END)),0)
          FROM stingere s
            INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
            INNER JOIN obligpif o ON o.codobligpif = s.codstinspif
            INNER JOIN general g ON  g.codgeneral = os.codgeneral
            LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
            LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
            LEFT JOIN iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
          WHERE s.codstinspif = stinsi.codobligpif
            AND Coalesce(i.an * 12 + i.luna, t1.an * 12 + t1.luna, c.an * 12 + c.luna) = &apos;||pkg_globals.AnLunaLucru||&apos;
            AND Coalesce(i.infocm, 0) &lt;&gt; 1
          GROUP BY s.codstinspif ))/Decode(stinsi.Valoares,NULL,1,0,1,stinsi.Valoares)
        ELSE PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stingatori.valstins)
      END * stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc)&apos;;

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, CodObligS, CodDocS, CodPart, PARTENER, LOCATIE, FACT_Doc, FACT_SCADENTA, FACT_DATA, FACT_VAL, INC_DOC, INC_DATA, INC_VAL, INC_VALFTVA, DIFZILE,
    INC_VAL1, INC_VAL2, INC_VAL3, INC_VAL4, INC_VAL5,
    INC_VAL_0_7, INC_VAL_8_21, INC_VAL_22_40, INC_VAL_61_70, INC_VAL_61_75, INC_VAL_71_85, INC_VAL_40p, INC_VAL_75p, INC_VAL_85p,
    MONEDA, DEPZILE,
    CEC_Doc, CEC_DATA, CEC_SCADENTA, CEC_VALNED, TREZOR_Doc, TREZOR_DATA, Adaos, DEPZILEF, DEPZILEDEC, REST, ORDINE, NRDOC, SERIEDOC, UTILIZATOR,
    SIMBCCOST, DENCCOST, SIMBGEST, DENGEST, CLSGEST,RESTPART &apos;||gUserFields||&apos; )&apos; ||chr(13);

  sSelI := &apos;
  SELECT
    X.NAV_CodDoc, X.NAV_TipDoc,
    X.CodObligS, X.CodDocS, nvl(X.CodPart,0) CodPart,
    P.DEN_PART, SED.OBS, X.FACT_Doc, X.FACT_SCADENTA, X.FACT_DATA, X.FACT_VAL, X.INC_DOC, X.INC_DATA, X.INC_VAL, X.INC_VAL * X.COEFFTVA, trunc(X.TREZOR_DATA - X.FACT_DATA) DIFZILE,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &lt;=              1 THEN X.INC_VAL ELSE 0 END INC_VAL1,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  2 AND 30 THEN X.INC_VAL ELSE 0 END INC_VAL2,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 31 AND 45 THEN X.INC_VAL ELSE 0 END INC_VAL3,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 46 AND 60 THEN X.INC_VAL ELSE 0 END INC_VAL4,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              60 THEN X.INC_VAL ELSE 0 END INC_VAL5,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  0 AND  7 THEN X.INC_VAL ELSE 0 END INC_VAL_0_7,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  8 AND 21 THEN X.INC_VAL ELSE 0 END INC_VAL_8_21,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 22 AND 40 THEN X.INC_VAL ELSE 0 END INC_VAL_22_40,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 70 THEN X.INC_VAL ELSE 0 END INC_VAL_61_70,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 75 THEN X.INC_VAL ELSE 0 END INC_VAL_61_75,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 71 AND 85 THEN X.INC_VAL ELSE 0 END INC_VAL_71_85,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              40 THEN X.INC_VAL ELSE 0 END INC_VAL_40p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              75 THEN X.INC_VAL ELSE 0 END INC_VAL_75p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              85 THEN X.INC_VAL ELSE 0 END INC_VAL_85p,
    MON.SIMBOL, NVL(X.DEPZILE, 0),
    X.CEC_Doc, X.CEC_DATA, X.CEC_SCADENTA, X.CEC_VALNED, X.TREZOR_Doc, X.TREZOR_DATA, X.Adaos, X.DEPZILEF, X.DEPZILEDEC, X.REST, X.Ordine, X.nrdoc, x.seriedoc, x.username,
    cc.simbol, cc.denumire, g.simbol, g.den_gest, cg.den_claseg,X.RESTPART &apos;||gUserAlias||&apos;
  FROM x
    LEFT JOIN npers ag ON ag.codpers = Nvl(x.agent,0)
    LEFT JOIN nagenda sed ON sed.codagenda = Nvl(x.codlocatie,0)
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sed.codlocalit
    LEFT JOIN njudet sedjud ON sedjud.codjudet = sedloc.codjudet
    LEFT JOIN ntipsedii sedtip ON sedtip.codtipsediu = sed.codtipsediu
    LEFT JOIN npart p ON p.codpart = Nvl(x.codpart,0)
    LEFT JOIN NPART1 p1 ON p1.codpart1 = x.codpart AND &apos;||to_char(an*12+luna)||&apos; BETWEEN p1.alstart AND p1.alstop
    LEFT JOIN nmonede mon ON mon.codmoneda = Nvl(x.moneda,0)
    LEFT JOIN centrecost cc ON cc.codcentru = Nvl(x.codcentru,0)
    LEFT JOIN ngest g ON g.codgest = Nvl(x.codgest,0)
    LEFT JOIN nclaseg cg ON cg.codclaseg = NVL(g.codclasa,0)
    LEFT JOIN nclasep cp ON cp.codclasep = NVL(p.codclasa,0)
    LEFT JOIN nsubunit ssting ON ssting.codsubunit = Nvl(x.substing,0)
    LEFT JOIN nsubunit sstins ON sstins.codsubunit = Nvl(x.substins,0)
    LEFT JOIN nsubunit scec ON scec.codsubunit = Nvl(x.CEC_Sub,0)
    LEFT JOIN trezor1 t1 ON x.codtrezor1 = t1.codtrezor1 &apos;||
    gSuplJoins;

  sSel := &apos;
  SELECT
    X.NAV_CodDoc, X.NAV_TipDoc,
    X.CodObligS, X.CodDocS, nvl(X.CodPart,0) CodPart,
    P.DEN_PART, SED.OBS, X.FACT_Doc, X.FACT_SCADENTA, X.FACT_DATA, X.FACT_VAL, X.INC_DOC, X.INC_DATA, X.INC_VAL, X.INC_VAL * X.COEFFTVA, trunc(X.TREZOR_DATA - X.FACT_DATA) DIFZILE,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &lt;=              1 THEN X.INC_VAL ELSE 0 END INC_VAL1,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  2 AND 30 THEN X.INC_VAL ELSE 0 END INC_VAL2,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 31 AND 45 THEN X.INC_VAL ELSE 0 END INC_VAL3,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 46 AND 60 THEN X.INC_VAL ELSE 0 END INC_VAL4,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              60 THEN X.INC_VAL ELSE 0 END INC_VAL5,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  0 AND  7 THEN X.INC_VAL ELSE 0 END INC_VAL_0_7,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  8 AND 21 THEN X.INC_VAL ELSE 0 END INC_VAL_8_21,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 22 AND 40 THEN X.INC_VAL ELSE 0 END INC_VAL_22_40,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 70 THEN X.INC_VAL ELSE 0 END INC_VAL_61_70,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 75 THEN X.INC_VAL ELSE 0 END INC_VAL_61_75,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 71 AND 85 THEN X.INC_VAL ELSE 0 END INC_VAL_71_85,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              40 THEN X.INC_VAL ELSE 0 END INC_VAL_40p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              75 THEN X.INC_VAL ELSE 0 END INC_VAL_75p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              85 THEN X.INC_VAL ELSE 0 END INC_VAL_85p,
    MON.SIMBOL, NVL(X.DEPZILE, 0),
    X.CEC_Doc, X.CEC_DATA, X.CEC_SCADENTA, X.CEC_VALNED, X.TREZOR_Doc, X.TREZOR_DATA, X.Adaos, X.DEPZILEF, X.DEPZILEDEC, X.REST, X.Ordine,X.nrdoc, x.seriedoc, x.username,
    cc.simbol, cc.denumire, g.simbol, g.den_gest, cg.den_claseg,X.RESTPART &apos;||gUserAlias||&apos;
  FROM x
    LEFT JOIN npers ag ON ag.codpers = Nvl(x.agent,0)
    LEFT JOIN nagenda sed ON sed.codagenda = Nvl(x.codlocatie,0)
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sed.codlocalit
    LEFT JOIN njudet sedjud ON sedjud.codjudet = sedloc.codjudet
    LEFT JOIN ntipsedii sedtip ON sedtip.codtipsediu = sed.codtipsediu
    LEFT JOIN npart p ON p.codpart = Nvl(x.codpart,0)
    LEFT JOIN NPART1 p1 ON p1.codpart1 = x.codpart AND x.AnLuna BETWEEN p1.alstart AND p1.alstop
    LEFT JOIN nmonede mon ON mon.codmoneda = Nvl(x.moneda,0)
    LEFT JOIN centrecost cc ON cc.codcentru = Nvl(x.codcentru,0)
    LEFT JOIN ngest g ON g.codgest = Nvl(x.codgest,0)
    LEFT JOIN nclaseg cg ON cg.codclaseg = NVL(g.codclasa,0)
    LEFT JOIN nclasep cp ON cp.codclasep = NVL(p.codclasa,0)
    LEFT JOIN nsubunit ssting ON ssting.codsubunit = Nvl(x.substing,0)
    LEFT JOIN nsubunit sstins ON sstins.codsubunit = Nvl(x.substins,0)
    LEFT JOIN nsubunit scec ON scec.codsubunit = Nvl(x.CEC_Sub,0)
    LEFT JOIN trezor1 t1 ON x.codtrezor1 = t1.codtrezor1 &apos;||
    gSuplJoins;

  sSelect := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, i.prefixdoc tipdocstinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0
      AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 and abs(i.valdoc) &gt; 0.01 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      s.codstinspif,
      case when t1.tiptranz = 0 then -1 else 1 end * CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN s.valoare ELSE 0 END valstins,
      case when t1.tiptranz = 0 then -1 else 1 end * CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN NVL(g.tva,0) ELSE 0 END tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub,
      t.codbanca codbankcont, t1.carnetdoc, t1.codtrezor1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND t1.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((t1.tiptranz = 0) OR (t1.TipTranz = 1))
      AND g.semnificatie NOT IN (410,801, 750)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      s.codstinspif, CASE WHEN os.valoare &lt; 0 THEN -1 ELSE 1 END * s.valoare valstins, nvl(g.tva,0) tvastins, o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, g.TipDoc, &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, c.datadoc DATA, 0 Agent, o.semnificatie, c.subunitatea, &apos;&apos;PV&apos;&apos; tipdocstingatori, c.nrdoc nrdocstingatori, c.datadoc datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, c.carnetdoc, 0 codtrezor1
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, es.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, i.carnetdoc, 0 codtrezor1
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE E.DATABON &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, e.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, i.carnetdoc, 0 codtrezor1
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE E.DATABON  &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
      ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.data dataref, stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valstins INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEC_Sub, stingatori.CEC_VALNED, stingatori.TREZOR_Doc, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart, stingatori.codbankcont,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.codtrezor1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSel||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

--  sSelectI := &apos;WITH
--  stinsi AS (
--    SELECT
--      I.PARTENER,I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
--      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
--      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
--      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
--      obstins.valoare,
--      obstins.valoare valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
--      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
--      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
--      i.an*12+i.luna AnLuna, i.carnetdoc
--    FROM iesiri i
--      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (210,410,500)
--      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
--      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
--      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
--      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
--    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
--      sFiltruAG||sFiltruPart||&apos;
--      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
--      AND Coalesce(i.valdoc, 0) &lt;&gt; 0
--    UNION ALL
--    SELECT -- cu cec in curs din initializare
--      distinct I.PARTENER,I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
--      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
--      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) restval,
--      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
--      ocec.valoare,
--      ocec.valoare valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
--      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
--      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
--      i.an*12+i.luna AnLuna, i.carnetdoc
--    FROM iesiri i
--      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (210,410,500)
--      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
--      INNER JOIN stingere s ON s.codstinspif = obstins.codobligpif
--      INNER JOIN obligpif osting ON osting.codobligpif = s.codstingatorpif
--      INNER JOIN general gsting ON gsting.codgeneral = osting.codgeneral
--      INNER JOIN general gcec ON gcec.coddoc = gsting.coddoc AND gcec.tipdoc = gsting.tipdoc AND gcec.semnificatie &lt;&gt; gsting.semnificatie
--      INNER JOIN obligpif ocec ON ocec.codgeneral = gcec.codgeneral
--      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
--      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
--      LEFT  JOIN obligpifluna ol ON ol.codobligpif = ocec.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
--    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
--      sFiltruAG||sFiltruPart||&apos;
--      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
--      AND Coalesce(i.valdoc, 0) = 0
--    ),


  sSelectI := &apos;WITH
  stinsi AS (
    SELECT 
      I.PARTENER,I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
      ox.valoare,
      ox.valoare valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM (
      SELECT codobligpif, SUM(valoare) valoare
      FROM ( 
        SELECT
          obstins.codobligpif, obstins.valoare
        FROM iesiri i
          INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (210,410,500)
          INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
        WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
          PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
          sFiltruAG||sFiltruPart||&apos;
          AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          AND Coalesce(i.valdoc, 0) &lt;&gt; 0
        /*UNION ALL
        SELECT
          obstins.codobligpif, osting.valoare  
        FROM iesiri i
          INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (210,410,500)
          INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
          INNER JOIN stingere s ON s.codstinspif = obstins.codobligpif
          INNER JOIN obligpif osting ON osting.codobligpif = s.codstingatorpif
          INNER JOIN general gsting ON gsting.codgeneral = osting.codgeneral
          INNER JOIN general gcec ON gcec.coddoc = gsting.coddoc AND gcec.tipdoc = gsting.tipdoc AND gcec.semnificatie &lt;&gt; gsting.semnificatie
          INNER JOIN obligpif ocec ON ocec.codgeneral = gcec.codgeneral
          LEFT  JOIN obligpifluna ol ON ol.codobligpif = ocec.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
        WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
          PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
          sFiltruAG||sFiltruPart||&apos;
          AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)*/
      ) GROUP BY codobligpif
    ) ox
      LEFT JOIN obligpif obstins ON obstins.codobligpif = ox.codobligpif
      LEFT JOIN general g ON g.codgeneral = obstins.codgeneral
      LEFT JOIN iesiri i ON i.codies = g.coddoc   
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    ),
  stingatori AS (
    SELECT
      s.codstinspif,
      case when t1.initializari = 1 THEN o.valoare  ELSE s.valoare end valstins,
      --case when t1.initializari = 1 THEN OFCT.VALOARE ELSE s.valoare end valstins,
      NVL(g.tva,0) tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub,
      t.codbanca codbankcont, t1.carnetdoc, t1.codtrezor1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
      LEFT JOIN OBLIGPIF OFCT ON OFCT.CODOBLIGPIF = S.CODSTINSPIF
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND t1.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((t1.tiptranz = 0 AND g.semnificatie &lt;&gt; 420) OR (t1.TipTranz = 1))
      AND g.semnificatie NOT IN (410,801,750)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      s.codstinspif, CASE WHEN os.valoare &lt; 0 THEN -1 ELSE 1 END * s.valoare valstins, nvl(g.tva,0) tvastins, o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, g.TipDoc, &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, c.datadoc DATA, 0 Agent, o.semnificatie, c.subunitatea, &apos;&apos;PV&apos;&apos; tipdocstingatori, c.nrdoc nrdocstingatori, c.datadoc datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, c.carnetdoc, 0 codtrezor1
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, es.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, i.carnetdoc, 0 codtrezor1
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE E.DATABON &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, e.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, 0 codbankcont, i.carnetdoc, 0 codtrezor1
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE E.DATABON  &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
      ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS,  stinsi.CodDoc CodDocS,
      stingatori.data dataref, stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valstins INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEC_Sub, stingatori.CEC_VALNED, stingatori.TREZOR_Doc, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valdoc - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart, stingatori.codbankcont,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.codtrezor1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSelI||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  sSelect_ini := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (410,500)
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      s.codstinspif,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN s.valoare ELSE 0 END valstins,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN NVL(g.tva,0) ELSE 0 END tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 AND (gc.tipdoc = 31 OR t1c.codtrezor1 IS NULL) THEN 0 ELSE o.valoare END valoare,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub,
      t.codbanca codbankcont, t1.carnetdoc, t1.codtrezor1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND g.semnificatie NOT IN (410, 700, 701, 751) &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos; ),
  x AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS,  stinsi.CodDoc CodDocS,
      stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA,
      SUM(stingatori.valoare) over (PARTITION BY stingatori.codstinspif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valoare INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEL_valned,stingatori.CEC_Sub, stingatori.TREZOR_Doc, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart, stingatori.codbankcont,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.codtrezor1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSel;

  sSelect_Tip7 := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.codgeneral,  i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstingator, e.databon datadocstingatori,
      i.valdoc valoares, 0 restval, obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda,
      obstins.codobligpif, i.valdoc valoare, i.valdoc, i.tvadoc tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare,0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN emulare e ON e.codies = i.codies
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipfactura = 7 AND NVL(i.anulat, 0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND i.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  x AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.codpart, stinsi.codlocatie, stinsi.moneda,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stinsi.docstingator INC_DOC, stinsi.datadocstingatori INC_DATA, stinsi.valoare INC_VAL, stinsi.tva INC_TVA, 0 DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc,stinsi.valoare)*stinsi.valoare/decode(stinsi.valdoc,0,1,stinsi.valdoc) Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      0 rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      stinsi.subunitatea substing, stinsi.subunitatea substins,0 restpart, 0 codbankcont,
      0 cdsting, stinsi.carnetdoc cdstins, 0 codtrezor1
    FROM stinsi ) &apos;||sSel;

  sSelect_Mon := &apos;WITH
  stingeri AS (
    SELECT stingere.*, general.codgeneral, NVL(general.tva,0) tva, Nvl(obligpif.codcentru,0) codcentru, nvl(obligpif.codgest,0) codgest
    FROM stingere
      INNER JOIN obligpif ON stingere.codstingatorpif = obligpif.codobligpif
      INNER JOIN general ON obligpif.codgeneral = general.codgeneral),
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins, obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      &apos;&apos;sold initial &apos;&apos; TipDocStinsi, i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
    UNION ALL
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      o.codobligpif, o.Codgeneral, i.codies CodDoc, g.TipDoc, i.prefixdoc||&apos;&apos; &apos;&apos; ||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, i.datadoc DATA, i.Agent, o.semnificatie, i.subunitatea, i.tipdoc tipdocstingatori, i.nrdoc nrdocstingatori, i.datadoc datadocstingatori, 
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest, i.carnetdoc, 0 codtrezor1
    FROM iesiri i
      INNER JOIN general g ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      LEFT JOIN emulare e ON e.codies = i.codies
    WHERE i.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND i.tipdoc = 16
      AND e.codemulare IS NULL &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;  ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL, stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA,
      stingeri.valoare INC_VAL, stingeri.tva INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stingatori.data TREZOR_DATA,
      PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stingeri.valoare)*stinsi.valoare/stinsi.valdoc Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins,0 restpart, 0 codbankcont,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.codtrezor1
    FROM stinsi
      INNER JOIN stingeri ON stingeri.codstinspif = stinsi.codobligpif
      INNER JOIN stingatori ON stingeri.codstingatorpif = stingatori.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea )&apos;||
  sSel;

  sSelect_Doc0 := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie,210,-1,1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest,0) END * DECODE(obstins.semnificatie,210,-1,1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare,0) rest, i.an*12+i.luna AnLuna, rest.trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
                              AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 AND g.semnificatie &lt;&gt; 211
                              AND g.semnificatie &lt;&gt; 240
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif,t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND abs(I.ValDoc) &lt; 0.01 AND pkg_list_base_incfact.DOC0(I.CodIes) &gt; 0 AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
   ),
  X AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.data_stins dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      null INC_DOC, null INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      --PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc,stinsi.TIPDOC) ADAOS,
      null ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      0 substing, stinsi.subunitatea substins,rpart.restpart, 0 codbankcont,
      0 cdsting, stinsi.carnetdoc cdstins, 0 codtrezor1
    FROM stinsi
      INNER JOIN (SELECT sum(rest) restpart, partener from stinsi group by partener) rpart on rpart.partener = stinsi.partener)&apos;||
  sSel||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;

  sSelect_fact := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      &apos;&apos;sold initial &apos;&apos; TipDocStinsi, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipdoc &lt;&gt; 20 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      --AND i.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240 and abs(i.valdoc) &gt; 0.01
    UNION ALL
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
      DECODE(i.operat,1,obstins.valoare,i.valdoc), i.valdoc, Decode(i.operat,1,Nvl(g.tva,0),i.tvadoc) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipdoc &lt;&gt; 20 AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      --AND i.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240 and abs(i.valdoc) &gt; 0.01 ),
  x AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.data_stins dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      null INC_DOC, null INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE, null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc, stinsi.TIPDOC)*stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc) ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      0 substing, stinsi.subunitatea substins,0 restpart, 0 codbankcont,
      0 cdsting, stinsi.carnetdoc cdstins, 0 codtrezor1
    FROM stinsi
    WHERE NOT EXISTS (
            SELECT 1
            FROM stingere s
              INNER JOIN obligpif o ON s.codstingatorpif = o.codobligpif
              INNER JOIN general g ON o.codgeneral = g.codgeneral
              LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
              LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
              LEFT JOIN iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc&apos;;
    IF gOpt2 THEN
      sSelect_fact := sSelect_fact || &apos;
            WHERE s.codstinspif = stinsi.codobligpif
              AND Coalesce( t1.datadoc, c.datadoc, i.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    ELSE
      sSelect_fact := sSelect_fact || &apos;
              LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
              LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
              LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
              LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
              LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
              LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc
            WHERE s.codstinspif = stinsi.codobligpif
              AND Coalesce( t1c.datadoc, t1.datadoc, c.datadoc, i.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    END IF;
    sSelect_fact := sSelect_fact || &apos;
          )
  ) &apos;||
  sSel;

  sSelect_InfoCM := &apos;WITH
  stinsi AS (
    SELECT
      distinct I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, g.codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      i.valdoc valoares,
      i.valdoc restval,
      null adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, null codobligpif, i.valdoc valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      i.partener codpart, i.codlocatie, i.datadoc termen, i.agent, g.semnificatie,
      null cont,
      i.prefixdoc tipdocstinsi, i.valdoc + i.tvadoc rest, i.an*12+i.luna AnLuna, i.datadoc trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i.codies = i1.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 AND g.semnificatie &lt;&gt; 211
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
    WHERE i1.tiplinie = &apos;&apos;=&apos;&apos; AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND i.infocm = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
  ),
  stingatori AS (
    SELECT
      null codobligpif, null Codgeneral, 0 CodDoc, 0 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, e.codies,
      null DATADECONT, e.databon DATA, 0 Agent, null semnificatie, 0 subunitatea, 0 tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, 
      0 codcentru, 0 codgest, i.carnetdoc, 0 codtrezor1
    FROM emulare e INNER JOIN iesiri i on e.codies = i.codies
    WHERE e.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      &apos;||CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos; ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc,
      DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA,
      stinsi.valoare FACT_VAL, stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA,
      stinsi.valoare INC_VAL, stinsi.tva INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stingatori.data TREZOR_DATA,
      case when nvl(stinsi.valdoc,0) = 0 then 0 else PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stinsi.valoare)*stinsi.valoare/stinsi.valdoc end Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      0 rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stinsi.subunitatea substing, stinsi.subunitatea substins,rpart.restpart, 0 codbankcont,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.codtrezor1
    FROM stinsi
      INNER JOIN stingatori ON stinsi.coddoc = stingatori.codies
      INNER JOIN (SELECT sum(rest) restpart, partener from stinsi group by partener) rpart on rpart.partener = stinsi.partener
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stinsi.subunitatea )&apos;||
  sSel;
  else
    AduStringuriCriteriu1(TmpName);
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect,      aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelecti,     aListID, aListVer);
  --insert into x(test) values(sselecti);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_tip7, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_doc0, aListID, aListVer);
  IF gOpt4 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_infocm, aListID, aListVer);
  end if;
  IF gOpt1 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_fact, aListID, aListVer);
  END IF;

  sSelect :=
  &apos;begin
     for v_rec in (
       select tmp.codpart, nvl(fact.SumF,0) - nvl(inc.SumS,0) RestPart
       from &apos;||tmpName||&apos; tmp
         left join (select sum(fact_val) SumF, codpart from (select distinct codobligs, codpart, fact_val from &apos;||tmpName||&apos;) group by codpart) fact on fact.codpart = tmp.codpart
         left join (select sum(inc_val)  SumS, codpart from &apos;||tmpName||&apos; group by codpart) inc on inc.codpart = tmp.codpart
     ) loop
       update &apos;||tmpName||&apos; set restpart = v_rec.restpart where codpart = v_rec.codpart;
     end loop;
   end;&apos;;
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

  sSelect :=
  &apos;begin
     update &apos;||tmpName||&apos; tmp set rest1 = case
                                            when tmp.fact_val &gt; 0 then (select min(t.rest) from &apos;||tmpName||&apos; t where t.codobligs = tmp.codobligs)
                                            else (select max(t.rest) from &apos;||tmpName||&apos; t where t.codobligs = tmp.codobligs)
                                          end;
   end;&apos;;
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

  if not gSumarIncFact then
    sSelect :=
    &apos;begin
       for v_rec in (
         select distinct tmp.codobligs, tmp.fact_val, tmp.rest1
         from &apos;||tmpName||&apos; tmp
       ) loop
         update &apos;||tmpName||&apos; set fact_val = 0, rest1 = 0 where codobligs = v_rec.codobligs;
         update &apos;||tmpName||&apos; set fact_val = v_rec.fact_val, rest1 = v_rec.rest1 where codobligs = v_rec.codobligs and Ordine = (select max(ordine) from &apos;||tmpName||&apos; where codobligs = v_rec.codobligs);
       end loop;
     end;&apos;;
  end if;
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

  if gSumarIncFact then
    sSelect :=
    &apos;begin
       update &apos;||tmpName||&apos; tmp set rest = case
                                             when tmp.fact_val &gt; 0 then (select min(t.rest) from &apos;||tmpName||&apos; t where t.codobligs = tmp.codobligs group by t.codobligs)
                                             else (select max(t.rest) from &apos;||tmpName||&apos; t where t.codobligs = tmp.codobligs group by t.codobligs)
                                           end;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect :=
    &apos;begin
       delete from &apos;||tmpName||&apos; tmp where rest = 0.0;
       --delete from &apos;||tmpName||&apos; tmp where CEC_VALNED = 0.0 and not CEC_Doc is null;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect :=
    &apos;begin
       update &apos;||tmpName||&apos; tmp
       set
         INC_DOC = null,
         INC_DATA = null,
         INC_VAL = null,
         INC_VALFTVA = null,
         DIFZILE = null,
         INC_VAL1 = null,
         INC_VAL2 = null,
         INC_VAL3 = null,
         INC_VAL4 = null,
         INC_VAL5 = null,
         INC_VAL_0_7 = null,
         INC_VAL_8_21 = null,
         INC_VAL_22_40 = null,
         INC_VAL_61_70 = null,
         INC_VAL_61_75 = null,
         INC_VAL_71_85 = null,
         INC_VAL_40p = null,
         INC_VAL_75p = null,
         INC_VAL_85p = null
       where CEC_Doc is null;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect :=
    &apos;begin
       update &apos;||tmpName||&apos; tmp
       set
         INC_DOC = null,
         INC_DATA = null,
         INC_VAL = null,
         INC_VALFTVA = null,
         DIFZILE = null,
         INC_VAL1 = null,
         INC_VAL2 = null,
         INC_VAL3 = null,
         INC_VAL4 = null,
         INC_VAL5 = null,
         INC_VAL_0_7 = null,
         INC_VAL_8_21 = null,
         INC_VAL_22_40 = null,
         INC_VAL_61_70 = null,
         INC_VAL_61_75 = null,
         INC_VAL_71_85 = null,
         INC_VAL_40p = null,
         INC_VAL_75p = null,
         INC_VAL_85p = null,
         CEC_Doc = null,
         CEC_DATA = null,
         CEC_SCADENTA = null,
         CEC_VALNED = null
       where CEC_VALNED = 0.0 and not CEC_Doc is null and rest &lt;&gt; 0.0;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect :=
    &apos;declare i number;
     begin
       for v_rec in (select distinct count(*) nr, tmp.codobligs, max(ordine) ordine
                     from &apos;||tmpName||&apos; tmp
                     group by tmp.codobligs) loop
         if v_rec.nr &gt; 1 then
           for i in 1..v_rec.nr - 1 loop
             delete from &apos;||tmpName||&apos; tmp where codobligs = v_rec.codobligs and INC_DOC is null and CEC_Doc is null and rownum = 1;
           end loop;
         end if;
       end loop;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect :=
    &apos;begin
       for v_rec in (select distinct count(*) nr, tmp.codobligs, max(ordine) ordine
                     from &apos;||tmpName||&apos; tmp
                     group by tmp.codobligs) loop
         if v_rec.nr &gt; 1 then
           update &apos;||tmpName||&apos; tmp set fact_val = 0 where codobligs = v_rec.codobligs;
           update &apos;||tmpName||&apos; tmp set fact_val = (select valoare from obligpif where codobligpif = v_rec.codobligs) where codobligs = v_rec.codobligs and tmp.ordine = v_rec.ordine;
         end if;
       end loop;
     end;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect :=
    &apos;begin
       for v_rec in (select distinct tmp.coddocs, tmp.rest1
                     from &apos;||tmpName||&apos; tmp) loop
         update &apos;||tmpName||&apos; set rest1 = 0 where coddocs = v_rec.coddocs;
         update &apos;||tmpName||&apos; set rest1 = v_rec.rest1
         where coddocs = v_rec.coddocs
               and Ordine = (select max(ordine) from &apos;||tmpName||&apos; where coddocs = v_rec.coddocs);
       end loop;
     end;&apos;;
     LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
  end if;

  if gTotfact then
    sSelectFN :=&apos;WITH
    STINSI AS (
      SELECT
        I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
        obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
        CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
        obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
        DECODE(i.operat,1,obstins.valoare,i.valdoc), i.valdoc, Decode(i.operat,1,Nvl(g.tva,0),i.tvadoc) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
        obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
        PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
        i.prefixdoc tipdocstinsi, obstins.valoare, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
      FROM iesiri i
        INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
        INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
        LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
        LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
        LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
        LEFT  JOIN (
          SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
          FROM obligpif obs
            INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
            INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
            INNER JOIN general g ON obg.codgeneral = g.codgeneral
            LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
            LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
            LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
          where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
      WHERE i.tipdoc &lt;&gt; 20 AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sFiltruAG||sFiltruPart||&apos;
        AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND obstins.valoare - nvl(REST.VALOARE,0) &lt;&gt; 0
        AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240 and abs(i.valdoc) &gt; 0.01 ),
    x AS (
      SELECT
        stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
        stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
        stinsi.data_stins dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
        stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
        null INC_DOC, null INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE, null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
        PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc, stinsi.TIPDOC)*stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc) ADAOS,
        trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
        0 DEPZILEDEC,
        stinsi.rest,
        1 Ordine,
        stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
        0 codcentru, 0 codgest,
        0 substing, stinsi.subunitatea substins,0 restpart,
      0 cdsting, stinsi.carnetdoc cdstins, 0 codtrezor1
      FROM stinsi
      WHERE NOT EXISTS (SELECT TMP.NAV_CODDOC FROM &apos;||TmpName||&apos; TMP WHERE stinsi.CODDOC = TMP.NAV_CODDOC AND stinsi.TIPDOC = TMP.NAV_TIPDOC)
      ) &apos;||sSel;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectfn, aListID, aListVer);
  end if;

  COMMIT;
END;

procedure AduStringuriCriteriu1(TmpName in varchar2) is
begin
  sFAdaosDoc := &apos;
      CASE
        WHEN nvl(stinsi.AdaosDoc, 0) &lt;&gt; 0 THEN stinsi.AdaosDoc * (stinsi.restval - (
          SELECT Nvl(SUM(s.valoare * (CASE WHEN OS.SEMNIFICATIE IN (211, 420, 751, 1300) AND O.SEMNIFICATIE &lt;&gt; 600 THEN -1 ELSE 1 END)),0)
          FROM stingere s
            INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
            INNER JOIN obligpif o ON o.codobligpif = s.codstinspif
            INNER JOIN general g ON  g.codgeneral = os.codgeneral
            LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
            LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
            LEFT JOIN iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
          WHERE s.codstinspif = stinsi.codobligpif
            AND Coalesce(i.an * 12 + i.luna, t1.an * 12 + t1.luna, c.an * 12 + c.luna) = &apos;||pkg_globals.AnLunaLucru||&apos;
            AND Coalesce(i.infocm, 0) &lt;&gt; 1
          GROUP BY s.codstinspif ))/Decode(stinsi.Valoares,NULL,1,0,1,stinsi.Valoares)
        ELSE PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stingatori.valstins)
      END * stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc)&apos;;

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, CodObligS, CodDocS, CodPart, PARTENER, LOCATIE, FACT_Doc, FACT_SCADENTA, FACT_DATA, FACT_VAL, INC_DOC, INC_DATA, INC_VAL, INC_VALFTVA, DIFZILE,
    INC_VAL1, INC_VAL2, INC_VAL3, INC_VAL4, INC_VAL5,
    INC_VAL_0_7, INC_VAL_8_21, INC_VAL_22_40, INC_VAL_61_70, INC_VAL_61_75, INC_VAL_71_85, INC_VAL_40p, INC_VAL_75p, INC_VAL_85p,
    MONEDA, DEPZILE,
    CEC_Doc, CEC_DATA, CEC_SCADENTA, CEC_VALNED, TREZOR_Doc, TREZOR_DATA, Adaos, DEPZILEF, DEPZILEDEC, REST, ORDINE, NRDOC, SERIEDOC, UTILIZATOR,
    SIMBCCOST, DENCCOST, SIMBGEST, DENGEST, CLSGEST,RESTPART &apos;||gUserFields||&apos; )&apos; ||chr(13);

  sSelI := &apos;
  SELECT
    X.NAV_CodDoc, X.NAV_TipDoc,
    X.CodObligS, X.CodDocS, nvl(X.CodPart,0) CodPart,
    P.DEN_PART, SED.OBS, X.FACT_Doc, X.FACT_SCADENTA, X.FACT_DATA, X.FACT_VAL, X.INC_DOC, X.INC_DATA, X.INC_VAL, X.INC_VAL * X.COEFFTVA, trunc(X.TREZOR_DATA - X.FACT_DATA) DIFZILE,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &lt;=              1 THEN X.INC_VAL ELSE 0 END INC_VAL1,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  2 AND 30 THEN X.INC_VAL ELSE 0 END INC_VAL2,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 31 AND 45 THEN X.INC_VAL ELSE 0 END INC_VAL3,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 46 AND 60 THEN X.INC_VAL ELSE 0 END INC_VAL4,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              60 THEN X.INC_VAL ELSE 0 END INC_VAL5,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  0 AND  7 THEN X.INC_VAL ELSE 0 END INC_VAL_0_7,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  8 AND 21 THEN X.INC_VAL ELSE 0 END INC_VAL_8_21,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 22 AND 40 THEN X.INC_VAL ELSE 0 END INC_VAL_22_40,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 70 THEN X.INC_VAL ELSE 0 END INC_VAL_61_70,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 75 THEN X.INC_VAL ELSE 0 END INC_VAL_61_75,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 71 AND 85 THEN X.INC_VAL ELSE 0 END INC_VAL_71_85,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              40 THEN X.INC_VAL ELSE 0 END INC_VAL_40p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              75 THEN X.INC_VAL ELSE 0 END INC_VAL_75p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              85 THEN X.INC_VAL ELSE 0 END INC_VAL_85p,
    MON.SIMBOL, NVL(X.DEPZILE, 0),
    X.CEC_Doc, X.CEC_DATA, X.CEC_SCADENTA, X.CEC_VALNED, X.TREZOR_Doc, X.TREZOR_DATA, X.Adaos, X.DEPZILEF, X.DEPZILEDEC, X.REST, X.Ordine, X.nrdoc, x.seriedoc, x.username,
    cc.simbol, cc.denumire, g.simbol, g.den_gest, cg.den_claseg,X.RESTPART &apos;||gUserAlias||&apos;
  FROM x
    LEFT JOIN npers ag ON ag.codpers = Nvl(x.agent,0)
    LEFT JOIN nagenda sed ON sed.codagenda = Nvl(x.codlocatie,0)
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sed.codlocalit
    LEFT JOIN njudet sedjud ON sedjud.codjudet = sedloc.codjudet
    LEFT JOIN ntipsedii sedtip ON sedtip.codtipsediu = sed.codtipsediu
    LEFT JOIN npart p ON p.codpart = Nvl(x.codpart,0)
    LEFT JOIN NPART1 p1 ON p1.codpart1 = x.codpart AND &apos;||to_char(an*12+luna)||&apos; BETWEEN p1.alstart AND p1.alstop
    LEFT JOIN nmonede mon ON mon.codmoneda = Nvl(x.moneda,0)
    LEFT JOIN centrecost cc ON cc.codcentru = Nvl(x.codcentru,0)
    LEFT JOIN ngest g ON g.codgest = Nvl(x.codgest,0)
    LEFT JOIN nclaseg cg ON cg.codclaseg = NVL(g.codclasa,0)
    LEFT JOIN nclasep cp ON cp.codclasep = NVL(p.codclasa,0)
    LEFT JOIN nsubunit ssting ON ssting.codsubunit = Nvl(x.substing,0)
    LEFT JOIN nsubunit sstins ON sstins.codsubunit = Nvl(x.substins,0)
    LEFT JOIN nsubunit scec ON scec.codsubunit = Nvl(x.CEC_Sub,0)
    LEFT JOIN trezor1 t1 ON x.codtrezor1 = t1.codtrezor1 &apos;||
    gSuplJoins;

  sSel := &apos;
  SELECT
    X.NAV_CodDoc, X.NAV_TipDoc,
    X.CodObligS, X.CodDocS, nvl(X.CodPart,0) CodPart,
    P.DEN_PART, SED.OBS, X.FACT_Doc, X.FACT_SCADENTA, X.FACT_DATA, X.FACT_VAL, X.INC_DOC, X.INC_DATA, X.INC_VAL, X.INC_VAL * X.COEFFTVA, trunc(X.TREZOR_DATA - X.FACT_DATA) DIFZILE,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &lt;=              1 THEN X.INC_VAL ELSE 0 END INC_VAL1,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  2 AND 30 THEN X.INC_VAL ELSE 0 END INC_VAL2,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 31 AND 45 THEN X.INC_VAL ELSE 0 END INC_VAL3,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 46 AND 60 THEN X.INC_VAL ELSE 0 END INC_VAL4,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              60 THEN X.INC_VAL ELSE 0 END INC_VAL5,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  0 AND  7 THEN X.INC_VAL ELSE 0 END INC_VAL_0_7,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN  8 AND 21 THEN X.INC_VAL ELSE 0 END INC_VAL_8_21,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 22 AND 40 THEN X.INC_VAL ELSE 0 END INC_VAL_22_40,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 70 THEN X.INC_VAL ELSE 0 END INC_VAL_61_70,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 61 AND 75 THEN X.INC_VAL ELSE 0 END INC_VAL_61_75,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) BETWEEN 71 AND 85 THEN X.INC_VAL ELSE 0 END INC_VAL_71_85,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              40 THEN X.INC_VAL ELSE 0 END INC_VAL_40p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              75 THEN X.INC_VAL ELSE 0 END INC_VAL_75p,
    CASE WHEN trunc(X.TREZOR_DATA - X.FACT_DATA) &gt;              85 THEN X.INC_VAL ELSE 0 END INC_VAL_85p,
    MON.SIMBOL, NVL(X.DEPZILE, 0),
    X.CEC_Doc, X.CEC_DATA, X.CEC_SCADENTA, X.CEC_VALNED, X.TREZOR_Doc, X.TREZOR_DATA, X.Adaos, X.DEPZILEF, X.DEPZILEDEC, X.REST, X.Ordine,X.nrdoc, x.seriedoc, x.username,
    cc.simbol, cc.denumire, g.simbol, g.den_gest, cg.den_claseg,X.RESTPART &apos;||gUserAlias||&apos;
  FROM x
    LEFT JOIN npers ag ON ag.codpers = Nvl(x.agent,0)
    LEFT JOIN nagenda sed ON sed.codagenda = Nvl(x.codlocatie,0)
    LEFT JOIN nlocalit sedloc ON sedloc.codlocalit = sed.codlocalit
    LEFT JOIN njudet sedjud ON sedjud.codjudet = sedloc.codjudet
    LEFT JOIN ntipsedii sedtip ON sedtip.codtipsediu = sed.codtipsediu
    LEFT JOIN npart p ON p.codpart = Nvl(x.codpart,0)
    LEFT JOIN NPART1 p1 ON p1.codpart1 = x.codpart AND x.AnLuna BETWEEN p1.alstart AND p1.alstop
    LEFT JOIN nmonede mon ON mon.codmoneda = Nvl(x.moneda,0)
    LEFT JOIN centrecost cc ON cc.codcentru = Nvl(x.codcentru,0)
    LEFT JOIN ngest g ON g.codgest = Nvl(x.codgest,0)
    LEFT JOIN nclaseg cg ON cg.codclaseg = NVL(g.codclasa,0)
    LEFT JOIN nclasep cp ON cp.codclasep = NVL(p.codclasa,0)
    LEFT JOIN nsubunit ssting ON ssting.codsubunit = Nvl(x.substing,0)
    LEFT JOIN nsubunit sstins ON sstins.codsubunit = Nvl(x.substins,0)
    LEFT JOIN nsubunit scec ON scec.codsubunit = Nvl(x.CEC_Sub,0)
    LEFT JOIN trezor1 t1 ON x.codtrezor1 = t1.codtrezor1 &apos;||
    gSuplJoins;

  sSelect := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, i.prefixdoc tipdocstinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0
      AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND obstins.TERMEN between TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      s.codstinspif,
      case when t1.tiptranz = 0 then -1 else 1 end * CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN s.valoare ELSE 0 END valstins,
      case when t1.tiptranz = 0 then -1 else 1 end * CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN NVL(g.tva,0) ELSE 0 END tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub,
      OSTINS.TERMEN, t1.carnetdoc, T1.CODTREZOR1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN OBLIGPIF OSTINS ON OSTINS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND OSTINS.TERMEN between TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((t1.tiptranz = 0) OR (t1.TipTranz = 1))
      AND g.semnificatie NOT IN (410,801,750)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      s.codstinspif, CASE WHEN os.valoare &lt; 0 THEN -1 ELSE 1 END * s.valoare valstins, nvl(g.tva,0) tvastins, o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, g.TipDoc, &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, c.datadoc DATA, 0 Agent, o.semnificatie, c.subunitatea, &apos;&apos;PV&apos;&apos; tipdocstingatori, c.nrdoc nrdocstingatori, c.datadoc datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub,O.TERMEN, c.carnetdoc, 0 CODTREZOR1
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE OS.TERMEN between TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, es.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub,O.TERMEN, i.carnetdoc, 0 CODTREZOR1
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE O.TERMEN between TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, e.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub,O.TERMEN, i.carnetdoc, 0 CODTREZOR1
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies

      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE O.TERMEN between TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
      ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.TERMEN dataref, stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valstins INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEC_Sub, stingatori.CEC_VALNED, stingatori.TREZOR_Doc, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY nvl(stingatori.data, to_date(&apos;&apos;30.12.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY nvl(stingatori.data, to_date(&apos;&apos;30.12.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, stingatori.CODTREZOR1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSel||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  sSelectI := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER,I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (210,410,500)
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
    ),
  stingatori AS (
    SELECT
      s.codstinspif,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN s.valoare ELSE 0 END valstins,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN NVL(g.tva,0) ELSE 0 END tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub, OSTINS.TERMEN, t1.carnetdoc, T1.CODTREZOR1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN OBLIGPIF OSTINS ON OSTINS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND OSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((t1.tiptranz = 0 AND g.semnificatie &lt;&gt; 420) OR (t1.TipTranz = 1))
      AND g.semnificatie NOT IN (410,801)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      s.codstinspif, CASE WHEN os.valoare &lt; 0 THEN -1 ELSE 1 END * s.valoare valstins, nvl(g.tva,0) tvastins, o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, g.TipDoc, &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, c.datadoc DATA, 0 Agent, o.semnificatie, c.subunitatea, &apos;&apos;PV&apos;&apos; tipdocstingatori, c.nrdoc nrdocstingatori, c.datadoc datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, OS.TERMEN, c.carnetdoc, 0 CODTREZOR1
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE OS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, es.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, O.TERMEN, i.carnetdoc, 0 CODTREZOR1
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE O.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.codobligpif codstinspif, e.valoare valstins, nvl(g.tva,0) tvastins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, 64 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, e.databon DATA, 0 Agent, o.semnificatie, i.Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      NULL CEC_Doc, NULL CEC_DATA, NULL CEC_Scadenta, NULL TREZOR_Doc, 0 CEC_VALNED, 0 CEC_Sub, OBSTINS.TERMEN, i.carnetdoc, 0 CODTREZOR1
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN STINGERE S ON O.CODOBLIGPIF = S.CODSTINGATORPIF
      INNER JOIN OBLIGPIF OBSTINS ON S.CODSTINSPIF = OBSTINS.CODOBLIGPIF
    WHERE OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;
      ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.TERMEN dataref, stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valstins INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEC_Sub, stingatori.CEC_VALNED, stingatori.TREZOR_Doc, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, STINGATORI.CODTREZOR1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSelI||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  sSelect_ini := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont, &apos;&apos;sold initial &apos;&apos; TipDocStinsi,
      i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie NOT IN (410,500)
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      s.codstinspif,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN s.valoare ELSE 0 END valstins,
      CASE WHEN (g.tipdoc &lt;&gt; 31) or (gc.tipdoc &lt;&gt; 31 AND t1.codtrezor IS NOT NULL) THEN NVL(g.tva,0) ELSE 0 END tvastins,
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, g.TipDoc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc||&apos;&apos; &apos;&apos; ||t1c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) END DOCSTINGATOR,
      Nvl(t1c.Datadecont,t1.datadecont) DataDecont, &apos;||sTrezorData||&apos; DATA, Nvl(t1c.Agent,t1.Agent) Agent, o.semnificatie,
      CASE WHEN t.tipdoc = 31 THEN Nvl(tc.subunitatea,0) ELSE t.Subunitatea END subunitatea,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.doc ELSE t1.doc END tipdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.nrdoc ELSE t1.nrdoc END nrdocstingatori,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN NULL WHEN t.tipdoc = 31 THEN t1c.datadoc ELSE t1.datadoc END datadocstingatori,
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest,
      CASE WHEN t.tipdoc = 31 THEN t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END CEC_Doc,
      CASE WHEN t.tipdoc = 31 AND t1c.codtrezor IS NULL THEN s.valoare ELSE 0 END CEC_VALNED,
      CASE WHEN t.tipdoc = 31 THEN t1.datadoc ELSE NULL END CEC_Data, CASE WHEN t.tipdoc = 31 THEN t1.datadecont ELSE NULL END CEC_Scadenta, CASE WHEN t.tipdoc = 31 THEN t.numedoc ELSE NULL END TREZOR_Doc,
      CASE WHEN t.tipdoc = 31 AND (gc.tipdoc = 31 OR t1c.codtrezor1 IS NULL) THEN 0 ELSE o.valoare END valoare,
      CASE WHEN t.tipdoc = 31 THEN t.subunitatea ELSE 0 END CEC_Sub, t1.carnetdoc, T1.CODTREZOR1
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN OBLIGPIF OBSTINS ON OBSTINS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
      LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
      LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
      LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
      LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
      LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc AND t1c.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      LEFT JOIN trezor tc ON tc.codtrezor = t1c.codtrezor
    WHERE t.tipdoc IN (29, 30, 31, 33)
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND g.semnificatie NOT IN (410, 700, 701, 751) &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos; ),
  x AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.semnificatie,
      stinsi.codpart, stinsi.codlocatie, stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA,
      SUM(stingatori.valoare) over (PARTITION BY stingatori.codstinspif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) FACT_VAL,
      stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA, stingatori.valoare INC_VAL, stingatori.tvastins INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      stingatori.CEC_Doc, stingatori.CEC_DATA, stingatori.CEC_Scadenta, stingatori.CEC_Sub, stingatori.TREZOR_Doc, stingatori.CEC_VALNED, stinsi.Agent, stingatori.Data TREZOR_DATA,&apos;||
      sFAdaosDoc||&apos; ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      trunc(COALESCE(stingatori.datadecont,stingatori.data)-stinsi.termen) DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins, 0 restpart,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, STINGATORI.CODTREZOR1
    FROM stinsi
      INNER JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea)&apos;||
  sSel;

  sSelect_Tip7 := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.codgeneral,  i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstingator, e.databon datadocstingatori,
      i.valdoc valoares, 0 restval, obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda,
      obstins.codobligpif, i.valdoc valoare, i.valdoc, i.tvadoc tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare,0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN emulare e ON e.codies = i.codies
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipfactura = 7 AND NVL(i.anulat, 0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  x AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.codpart, stinsi.codlocatie, stinsi.moneda,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stinsi.docstingator INC_DOC, stinsi.datadocstingatori INC_DATA, stinsi.valoare INC_VAL, stinsi.tva INC_TVA, 0 DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc,stinsi.valoare)*stinsi.valoare/decode(stinsi.valdoc,0,1,stinsi.valdoc) Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      0 rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      stinsi.subunitatea substing, stinsi.subunitatea substins,0 restpart,
      0 cdsting, stinsi.carnetdoc cdstins, 0 CODTREZOR1
    FROM stinsi ) &apos;||sSel;

  sSelect_Mon := &apos;WITH
  stingeri AS (
    SELECT stingere.*, general.codgeneral, NVL(general.tva,0) tva, Nvl(obligpif.codcentru,0) codcentru, nvl(obligpif.codgest,0) codgest
    FROM stingere
      INNER JOIN obligpif ON stingere.codstingatorpif = obligpif.codobligpif
      INNER JOIN general ON obligpif.codgeneral = general.codgeneral),
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins, obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      &apos;&apos;sold initial &apos;&apos; TipDocStinsi, i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
    UNION ALL
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, i.an*12+i.luna AnLuna, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) ),
  stingatori AS (
    SELECT
      o.codobligpif, o.Codgeneral, i.codies CodDoc, g.TipDoc, i.prefixdoc||&apos;&apos; &apos;&apos; ||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
      null DATADECONT, i.datadoc DATA, i.Agent, o.semnificatie, i.subunitatea, i.tipdoc tipdocstingatori, i.nrdoc nrdocstingatori, i.datadoc datadocstingatori, 
      Nvl(o.codcentru,0) codcentru, nvl(o.codgest,0) codgest, i.carnetdoc, 0 CODTREZOR1
    FROM iesiri i
      INNER JOIN general g ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN STINGERI S ON O.CODOBLIGPIF = S.CODSTINGATORPIF
      INNER JOIN OBLIGPIF OBSTINS ON S.CODSTINSPIF = OBSTINS.CODOBLIGPIF
      LEFT JOIN emulare e ON e.codies = i.codies
    WHERE OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND i.tipdoc = 16
      AND e.codemulare IS NULL &apos;||
      CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos;  ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL, stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA,
      stingeri.valoare INC_VAL, stingeri.tva INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stingatori.data TREZOR_DATA,
      PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stingeri.valoare)*stinsi.valoare/stinsi.valdoc Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.valoare - nvl(SUM(stingatori.valstins) OVER (PARTITION BY stingatori.codstinspif ORDER BY stingatori.data ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) rest,
      ROW_NUMBER() OVER(PARTITION BY stingatori.codstinspif ORDER BY stingatori.data) Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stingatori.subunitatea substing, stinsi.subunitatea substins,0 restpart,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins,STINGATORI.CODTREZOR1
    FROM stinsi
      INNER JOIN stingeri ON stingeri.codstinspif = stinsi.codobligpif
      INNER JOIN stingatori ON stingeri.codstingatorpif = stingatori.codobligpif
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea )&apos;||
  sSel;

  sSelect_Doc0 := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie,210,-1,1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest,0) END * DECODE(obstins.semnificatie,210,-1,1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare,0) rest, i.an*12+i.luna AnLuna, rest.trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i.codies = i1.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 AND g.semnificatie &lt;&gt; 211
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif,t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i1.tiplinie = &apos;&apos;=&apos;&apos; AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND abs(I.ValDoc) &lt; 0.01 AND pkg_list_base_incfact.DOC0(I.CodIes) &gt; 0
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
   ),
  X AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.TERMEN dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      stinsi.docstins INC_DOC, stinsi.data_stins INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc,stinsi.TIPDOC) ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      0 substing, stinsi.subunitatea substins,rpart.restpart,
      0 cdsting, stinsi.carnetdoc cdstins,0 CODTREZOR1
    FROM stinsi
         INNER JOIN (SELECT sum(rest) restpart, partener from stinsi group by partener) rpart on rpart.partener = stinsi.partener)&apos;||
  sSel||&apos;
  WHERE x.dataref BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;

  sSelect_fact := &apos;WITH
  stinsi AS (
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      &apos;&apos;sold initial &apos;&apos; TipDocStinsi, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        WHERE OBS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipdoc &lt;&gt; 20 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 1 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240
    UNION ALL
    SELECT
      I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
      CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
      obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
      DECODE(i.operat,1,obstins.valoare,i.valdoc), i.valdoc, Decode(i.operat,1,Nvl(g.tva,0),i.tvadoc) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
      PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
      i.prefixdoc tipdocstinsi, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
      LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
      LEFT  JOIN (
        SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
        FROM obligpif obs
          INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
          INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
          INNER JOIN general g ON obg.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
          LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
          LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
        where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
    WHERE i.tipdoc &lt;&gt; 20 AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND OBSTINS.TERMEN BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240 ),
  x AS (
    SELECT
      stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stinsi.TERMEN dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
      null INC_DOC, null INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE, null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
      PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc, stinsi.TIPDOC)*stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc) ADAOS,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      stinsi.rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      0 codcentru, 0 codgest,
      0 substing, stinsi.subunitatea substins,0 restpart,
      0 cdsting, stinsi.carnetdoc cdstins, 0 CODTREZOR1
    FROM stinsi
    WHERE NOT EXISTS (
            SELECT 1
            FROM stingere s
              INNER JOIN obligpif o ON s.codstingatorpif = o.codobligpif
              INNER JOIN general g ON o.codgeneral = g.codgeneral
              LEFT JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29, 30, 31, 33)
              LEFT JOIN compens c ON c.codcompens = g.coddoc AND g.tipdoc = 28
              LEFT JOIN iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc&apos;;
    IF gOpt2 THEN
      sSelect_fact := sSelect_fact || &apos;
            WHERE s.codstinspif = stinsi.codobligpif
              AND Coalesce( t1.datadoc, c.datadoc, i.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    ELSE
      sSelect_fact := sSelect_fact || &apos;
              LEFT JOIN general gx ON g.tipdoc = 31 AND gx.coddoc = g.coddoc AND gx.tipdoc = g.tipdoc AND gx.semnificatie IN (500,600)
              LEFT JOIN obligpif ox ON ox.codgeneral = gx.codgeneral
              LEFT JOIN stingere sc ON sc.codstinspif = ox.codobligpif
              LEFT JOIN obligpif oc ON oc.codobligpif = sc.codstingatorpif
              LEFT JOIN general gc ON gc.codgeneral = oc.codgeneral AND gc.tipdoc IN (29, 30, 31)
              LEFT JOIN trezor1 t1c ON t1c.codtrezor1 = gc.coddoc
            WHERE s.codstinspif = stinsi.codobligpif
              AND Coalesce( t1c.datadoc, t1.datadoc, c.datadoc, i.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    END IF;
    sSelect_fact := sSelect_fact || &apos;
          )
  )&apos;||
  sSel||&apos;
  WHERE 1=1 &apos;;

  sSelect_InfoCM := &apos;WITH
  stinsi AS (
    SELECT
      distinct I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, g.codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      i.valdoc valoares,
      i.valdoc restval,
      null adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, null codobligpif, i.valdoc valoare, i.valdoc, Nvl(g.tva,0) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
      i.partener codpart, i.codlocatie, i.datadoc termen, i.agent, g.semnificatie,
      null cont,
      i.prefixdoc tipdocstinsi, i.valdoc + i.tvadoc rest, i.an*12+i.luna AnLuna, i.datadoc trezor_data, i.carnetdoc
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i.codies = i1.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210 AND g.semnificatie &lt;&gt; 211
      LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
      LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
    WHERE i1.tiplinie = &apos;&apos;=&apos;&apos; AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND i.infocm = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sFiltruAG||sFiltruPart||&apos;
      AND I.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||gDataS||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
  ),
  stingatori AS (
    SELECT
      null codobligpif, null Codgeneral, 0 CodDoc, 0 TipDoc, &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, e.codies,
      null DATADECONT, e.databon DATA, 0 Agent, null semnificatie, 0 subunitatea, 0 tipdocstingatori, e.nrbon nrdocstingatori, e.databon datadocstingatori, 
      0 codcentru, 0 codgest, i.carnetdoc
    FROM emulare e
         inner join iesiri i on e.codies = i.codies
    WHERE 1 = 1
      &apos;||CASE WHEN NOT gOpt3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ELSE NULL END||&apos; ),
  X AS (
    SELECT
      DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc,
      DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc,
      stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
      stingatori.semnificatie, stinsi.codpart, stinsi.codlocatie,
      stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA,
      stinsi.valoare FACT_VAL, stingatori.docstingator INC_DOC, stingatori.datadocstingatori INC_DATA,
      stinsi.valoare INC_VAL, stinsi.tva INC_TVA, stinsi.moneda, trunc(stingatori.Data - stinsi.termen) DEPZILE,
      null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stingatori.data TREZOR_DATA,
      PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(Stinsi.CodDoc, stinsi.valoare)*stinsi.valoare/stinsi.valdoc Adaos,
      trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) - stinsi.termen) DEPZILEF,
      0 DEPZILEDEC,
      0 rest,
      1 Ordine,
      stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
      stingatori.codcentru, stingatori.codgest,
      stinsi.subunitatea substing, stinsi.subunitatea substins,rpart.restpart,
      stingatori.carnetdoc cdsting, stinsi.carnetdoc cdstins, 0 CODTREZOR1
    FROM stinsi
      INNER JOIN stingatori ON stinsi.coddoc = stingatori.codies
      INNER JOIN (SELECT sum(rest) restpart, partener from stinsi group by partener) rpart on rpart.partener = stinsi.partener
      LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stinsi.subunitatea )&apos;||
  sSel;

  if gTotfact then
    sSelectFN :=&apos;WITH
    STINSI AS (
      SELECT
        I.PARTENER, I.NrDoc, doc.serie, ut.username, I.CodIes CodDoc, I.TipDoc, obstins.Codgeneral, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
        obstins.valoare * DECODE(obstins.semnificatie, 210, -1, 1) valoares,
        CASE WHEN i.an * 12 + i.luna = &apos;||pkg_globals.AnLunaLucru||&apos; THEN obstins.valoare ELSE NVL(ol.rest, 0) END * DECODE(obstins.semnificatie, 210, -1, 1) restval,
        obstins.adaosdoc, i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif,
        DECODE(i.operat,1,obstins.valoare,i.valdoc), i.valdoc, Decode(i.operat,1,Nvl(g.tva,0),i.tvadoc) tva, i.tvadoc, 1-Decode(i.valdoc,0,0,i.tvadoc/i.valdoc) coefftva,
        obstins.codpart, i.codlocatie, obstins.termen, i.agent, obstins.semnificatie,
        PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna, obstins.semnificatie) cont,
        i.prefixdoc tipdocstinsi, obstins.valoare, obstins.valoare - nvl(rest.valoare, 0) rest, i.an*12+i.luna AnLuna, rest.TREZOR_DATA, i.carnetdoc
      FROM iesiri i
        INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 500 AND g.semnificatie &lt;&gt; 410 AND g.semnificatie &lt;&gt; 210
        INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
        LEFT  JOIN doccarnete doc ON i.carnetdoc = doc.codcarnet
        LEFT  JOIN tmp_utilizator ut ON ut.codutilizator = i.userid
        LEFT  JOIN obligpifluna ol ON ol.codobligpif = obstins.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
        LEFT  JOIN (
          SELECT obs.codobligpif, sum(CASE WHEN obs.valoare &lt; 0 THEN -1 ELSE 1 END * st.valoare) valoare, NVL(t.datadoc, c.datadoc) trezor_data
          FROM obligpif obs
            INNER JOIN stingere st ON obs.codobligpif = st.codstinspif
            INNER JOIN obligpif obg ON st.codstingatorpif = obg.codobligpif
            INNER JOIN general g ON obg.codgeneral = g.codgeneral
            LEFT JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1
            LEFT JOIN trezor t ON t1.codtrezor = t.codtrezor AND g.tipdoc = t.tipdoc
            LEFT JOIN compens c ON g.tipdoc = 28 AND c.codcompens = g.coddoc
          where NVL(t.datadoc, c.datadoc) &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
          group by obs.codobligpif, t.datadoc, c.datadoc ) rest ON rest.codobligpif = obstins.codobligpif
      WHERE i.tipdoc &lt;&gt; 20 AND i.tipfactura &lt;&gt; 7 AND NVL(i.anulat, 0) = 0 AND nvl(i.initializari,0) = 0 AND Nvl(i.ExclusPlata,0) = 0 AND Nvl(i.infocm,0) = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sFiltruAG||sFiltruPart||&apos;
        AND i.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||gDataF||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND obstins.valoare - nvl(REST.VALOARE,0) &lt;&gt; 0
        AND obstins.semnificatie &lt;&gt; 210 AND obstins.semnificatie &lt;&gt; 211 AND obstins.semnificatie &lt;&gt; 240 and abs(i.valdoc) &gt; 0.01 ),
    x AS (
      SELECT
        stinsi.coddoc NAV_CodDoc, stinsi.tipdoc NAV_TipDoc,
        stinsi.CodObligPif CodObligS, stinsi.CodDoc CodDocS,
        stinsi.data_stins dataref, 0 semnificatie, stinsi.codpart, stinsi.codlocatie,
        stinsi.docstins FACT_Doc, stinsi.termen FACT_SCADENTA, stinsi.data_stins FACT_DATA, stinsi.valoare FACT_VAL,
        null INC_DOC, null INC_DATA, null INC_VAL, null INC_TVA, stinsi.moneda, 0 DEPZILE, null CEC_Doc, null CEC_DATA, NULL CEC_Scadenta, 0 CEC_Sub, 0 CEC_VALNED, null TREZOR_Doc, stinsi.Agent, stinsi.TREZOR_DATA,
        PKG_LIST_BASE_INCFACT.GETADAOS2(Stinsi.CodDoc, stinsi.TIPDOC)*stinsi.valoare/decode(stinsi.valdoc, null, 1, 0, 1, stinsi.valdoc) ADAOS,
        trunc(to_date(&apos;&apos;&apos;||gDataRef||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)-stinsi.termen) DEPZILEF,
        0 DEPZILEDEC,
        stinsi.rest,
        1 Ordine,
        stinsi.nrdoc, stinsi.serie seriedoc, stinsi.username, Stinsi.AnLuna, STINSI.COEFFTVA,
        0 codcentru, 0 codgest,
        0 substing, stinsi.subunitatea substins,0 restpart,
        0 cdsting, stinsi.carnetdoc cdstins, 0 CODTREZOR1
      FROM stinsi
      WHERE NOT EXISTS (SELECT TMP.NAV_CODDOC FROM &apos;||TmpName||&apos; TMP WHERE X.CODDOC = stinsi.CODDOC AND X.TIPDOC = stinsi.TIPDOC)
      )
      &apos;||sSel;
  end if;
end;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_incfact; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INLOCUIREAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16C4E3BBF03782D08EBE02F0D4625087691401DE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_inlocuireagent IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;npers oa, npers na&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMP_NAME|| &apos;(OldAgent, NewAgent&apos;||gUserFields||&apos;)
  SELECT oa.nume||&apos;&apos; &apos;&apos;||oa.prenume, na.nume||&apos;&apos; &apos;&apos;||na.prenume &apos;||gUserAlias||&apos;
  FROM TMP_InlocuireAgent t
    LEFT JOIN npers oa ON oa.codpers  = t.oldcodagent
    LEFT JOIN npers na ON na.codpers  = t.newcodagent&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_INLOCUIREAGENT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INTERVUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E24AAD4306CF7564DC77FAE8CA90CAC4D2DAA005</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_intervutilaje IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  varchar2(15000);
  sWhere   varchar2(5000);
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  gSuplCols := &apos;NARTOBJ NOBJ, NGEST G, NPART NP, NLOCALIT LOC, NINTERVENTIIAUTO I, NARTOBJ SERVICIU,
                NCLASEA CLSI, NCLASEINT CLSINT, UTILAJE U, UTILAJE2C U2C, UTILAJE2 U2, UTILAJE20 U20&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF NOT pkg_list_selutilaje.IsAllUtilaje THEN
    sWhere := sWhere||&apos; AND U.CODUTILAJ IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODUTILAJ&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selutilaje.IsAllInterventii THEN
    sWhere := sWhere||&apos; AND I.CODINTERVENTIIAUTO IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODINTERVENTIIAUTO&apos;&apos;)&apos;;
  END IF;
  if pkg_list_selutilaje.PerDataInterv = 1 then
    if not pkg_list_selutilaje.IsExtra1 then
      sWhere := sWhere||&apos; AND U2C.DATAINDEXC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataIni||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
    else
      sWhere := sWhere||&apos; AND ((U2C.DATAINDEXC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataIni||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)) or  &apos;||chr(13)||
                        &apos;       u2c.dataindexc is null) &apos;;
    end if;  
  end if;
  sWhere := sWhere||&apos; AND (PKG_LIST_SELUTILAJE.IsAllTipUtilaje = 1 OR U.TIP IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPUTILAJ&apos;&apos;))&apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_TipDoc,NAV_CodDoc1,TIP,
    DENUMIRE,NRINVENTAR,ETICHETA,TIPUTILAJ,FLOTA,
    INDEXC, DATAC, indexv, datav, NrDoc, Datadoc, Sectie, DATASTART, DATASTOP,
    DURATA, INTERVENTIE, SERVICIU, PERSONAL&apos;||
    gUserFields||&apos;)
  SELECT
    coalesce(C.CODCOMANDA,U.CODUTILAJ), coalesce(C.TIPDOC,508),case when c.codcomanda &gt; 0 then 0 else U2C.codutilaj2c end, &apos;&apos;PROPRIU&apos;&apos;,
    NOBJ.DENUMIRE, U.NRINVENTAR,U.ETICHETA,U.TIPUTILAJ,U.FLOTA,
    U2C.INDEXC, U2C.DATAINDEXC, U2C.INDEXV, U2C.DATAV, C.NRDOC, C.DATADOC, G.DEN_GEST, U2C.DATASTART, U2C.DATAEND,
    TO_NUMBER (TO_DATE(TO_CHAR(U2C.DATAEND, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;) - TO_DATE(TO_CHAR(U2C.DATASTART, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;)) * 24,
    I.DENUMIRE, SERVICIU.DENUMIRE, 
    (SELECT STRING_AGG(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME) 
     FROM UTILAJE2P U2P
          INNER JOIN NPERS P ON U2P.CODPERS = P.CODPERS
     WHERE U2P.CODUTILAJ2 = U2.CODUTILAJ2
     )&apos;||
    gUserAlias||&apos;
  FROM UTILAJE U
    INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT&apos;;
  IF pkg_list_selutilaje.IsExtra1 THEN --left join
    sInsert := sInsert||&apos;
    LEFT JOIN UTILAJE2C U2C ON U2C.CODUTILAJ = U.CODUTILAJ
    LEFT JOIN UTILAJE2 U2 ON U2.CODUTILAJ2 = U2C.CODUTILAJ2
    LEFT JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN COMANDA1 C1 ON U2C.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    LEFT JOIN NGEST G ON G.CODGEST = C.CODGEST&apos;;
  ELSE -- inner join
    sInsert := sInsert||&apos;
    INNER JOIN UTILAJE2C U2C ON U2C.CODUTILAJ = U.CODUTILAJ
    INNER JOIN UTILAJE2 U2 ON U2.CODUTILAJ2 = U2C.CODUTILAJ2
    INNER JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
    INNER JOIN COMANDA1 C1 ON U2C.CODCOMANDA1 = C1.CODCOMANDA1
    INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    INNER JOIN NGEST G ON G.CODGEST = C.CODGEST&apos;;
  END IF;
    sInsert := sInsert||&apos;
    LEFT JOIN UTILAJE20 U20 ON U20.CODUTILAJ20 = U.CODUTILAJ - U.CODUTILAJ
    LEFT JOIN NPART NP ON NP.CODPART = U.CODUTILAJ - U.CODUTILAJ
    LEFT JOIN NLOCALIT LOC ON LOC.CODLOCALIT = U.CODUTILAJ - U.CODUTILAJ
    LEFT JOIN NARTOBJ SERVICIU ON I.SERVICIU = SERVICIU.CODOBIECT
    LEFT JOIN NART ASERV ON ASERV.CODARTICOL = SERVICIU.CODARTICOL
    LEFT JOIN NCLASEA CLSI ON CLSI.CODCLASEA = ASERV.CLASA
    LEFT JOIN NCLASEINT CLSINT ON I.CLASA = CLSINT.CODCLASEINT &apos;||
    gSuplJoins||
  &apos; where COALESCE(U.TIP,0) &lt;&gt; 3 &apos;||sWhere;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sWhere := &apos; WHERE CASE 
                      WHEN U.TIP IS NULL AND U.CODPART &gt; 0 THEN 2 
                      WHEN U.TIP = 3 THEN 2
                      ELSE       
                        CASE 
                          WHEN (SELECT COUNT(*) FROM UTILAJE1 WHERE CODUTILAJ = U.CODUTILAJ) &gt; 0 AND U.TIP IS NULL THEN 1
                          ELSE NVL(U.TIP,0)
                        END
                    END = 2 &apos;;

  IF NOT pkg_list_selutilaje.IsAllUtilaje THEN
    sWhere := sWhere||&apos; AND U.CODUTILAJ IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODUTILAJ&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selutilaje.IsAllInterventii THEN
    sWhere := sWhere||&apos; AND I.CODINTERVENTIIAUTO IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODINTERVENTIIAUTO&apos;&apos;)&apos;;
  END IF;
  if pkg_list_selutilaje.PerDataInterv = 1 then
    if not pkg_list_selutilaje.IsExtra1 then
      sWhere := sWhere||&apos; AND U2C.DATAINDEXC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataIni||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
    else
      sWhere := sWhere||&apos; AND ((U2C.DATAINDEXC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataIni||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_selutilaje.DataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;)) or  &apos;||chr(13)||
                        &apos;       u2c.dataindexc is null) &apos;;
    end if;  
  end if;
  sWhere := sWhere||&apos; AND (PKG_LIST_SELUTILAJE.IsAllTipUtilaje = 1 OR U.TIP IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPUTILAJ&apos;&apos;))&apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc,NAV_TipDoc,NAV_CodDoc1,TIP,
    DENUMIRE,NRINVENTAR,ETICHETA,TIPUTILAJ,FLOTA,
    INDEXC, DATAC, indexv, datav, NrDoc, Datadoc, Sectie, DATASTART, DATASTOP,
    DURATA, INTERVENTIE, SERVICIU, PERSONAL,
    P_NRDOC, P_DATADOC, P_DESCRIERE, P_STARE, P_OPERATOR, P_OBS, P_FACTURA, P_DEVIZ, P_LOCALITATE, P_ADRESA&apos;||
    gUserFields||&apos;)
  SELECT
    coalesce(C.CODCOMANDA,U.CODUTILAJ), coalesce(C.TIPDOC,508),case when c.codcomanda &gt; 0 then 0 else U2C.codutilaj2c end, &apos;&apos;CLIENT&apos;&apos;,
    NOBJ.DENUMIRE, U.NRINVENTAR,U.ETICHETA,U.TIPUTILAJ,U.FLOTA,
    U2C.INDEXC, U2C.DATAINDEXC, U2C.INDEXV, U2C.DATAV, C.NRDOC, C.DATADOC, G.DEN_GEST, U2C.DATASTART, U2C.DATAEND,
    TO_NUMBER (TO_DATE(TO_CHAR(U2C.DATAEND, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;) - TO_DATE(TO_CHAR(U2C.DATASTART, &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;), &apos;&apos;DDMMYYYY:HH24:MI:SS&apos;&apos;)) * 24,
    I.DENUMIRE, SERVICIU.DENUMIRE, 
    (SELECT STRING_AGG(P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME) 
     FROM UTILAJE2P U2P
          INNER JOIN NPERS P ON U2P.CODPERS = P.CODPERS
     WHERE U2P.CODUTILAJ2 = U2.CODUTILAJ2
     ),
     U20.NRDOC, U20.DATADOC, U20.DESCRIERE, 
     CASE U20.STARE
       WHEN 1 THEN &apos;&apos;initiala&apos;&apos;
       WHEN 2 THEN &apos;&apos;in asteptare piese&apos;&apos;
       WHEN 3 THEN &apos;&apos;in asteptare tehnician&apos;&apos;
       WHEN 4 THEN &apos;&apos;in lucru&apos;&apos;
       WHEN 7 THEN &apos;&apos;montaj&apos;&apos;
       WHEN 5 THEN &apos;&apos;facturat&apos;&apos;
       WHEN 6 THEN &apos;&apos;finalizat&apos;&apos;
       WHEN 8 THEN &apos;&apos;in asteptare accept oferta/deviz client&apos;&apos;
       WHEN 9 THEN &apos;&apos;in asteptare solutie producator&apos;&apos;
       WHEN 10 THEN &apos;&apos;in atelier&apos;&apos;  
     END,
     (SELECT USERNAME FROM tmp_UTILIZATOR WHERE CODUTILIZATOR = U20.OPERATOR),
     U20.OBS, CASE WHEN IES.CODIES &gt; 0 THEN IES.PREFIXDOC||IES.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(IES.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) END,
     CASE WHEN (SELECT COUNT(*) FROM UTILAJEDEV WHERE CODUTILAJ20 = U20.CODUTILAJ20) &gt; 0 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
     LOC.DEN_LOCALIT, U20.ADRESA  &apos;||
    gUserAlias||&apos;
  FROM UTILAJE U
    INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT&apos;;
  IF pkg_list_selutilaje.IsExtra1 THEN --left join
    sInsert := sInsert||&apos;
    LEFT JOIN UTILAJE20 U20 ON U20.CODUTILAJ = U.CODUTILAJ
    LEFT JOIN UTILAJE2 U2 ON U2.CODUTILAJ20 = U20.CODUTILAJ20
    LEFT JOIN UTILAJE2C U2C ON U2C.CODUTILAJ = U.CODUTILAJ AND U2C.CODUTILAJ2 = U2.CODUTILAJ2
    LEFT JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
    LEFT JOIN COMANDA1 C1 ON U2C.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    LEFT JOIN NGEST G ON G.CODGEST = C.CODGEST&apos;;
  ELSE -- inner join
    sInsert := sInsert||&apos;
    INNER JOIN UTILAJE20 U20 ON U20.CODUTILAJ = U.CODUTILAJ
    INNER JOIN UTILAJE2 U2 ON U2.CODUTILAJ20 = U20.CODUTILAJ20
    INNER JOIN UTILAJE2C U2C ON U2C.CODUTILAJ = U.CODUTILAJ AND U2C.CODUTILAJ2 = U2.CODUTILAJ2
    INNER JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
    INNER JOIN COMANDA1 C1 ON U2C.CODCOMANDA1 = C1.CODCOMANDA1
    INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
    INNER JOIN NGEST G ON G.CODGEST = C.CODGEST&apos;;
  END IF;
    sInsert := sInsert||&apos;
    LEFT JOIN IESIRI IES ON IES.CODIES = U20.CODIES
    LEFT JOIN NPART NP ON (IES.PARTENER = NP.CODPART AND COALESCE(U.CODPART,0) = 0) OR (U.CODPART = NP.CODPART AND COALESCE(U.CODPART,0) &gt; 0)
    LEFT JOIN NLOCALIT LOC ON LOC.CODLOCALIT = U20.CODLOCALIT
    LEFT JOIN NARTOBJ SERVICIU ON I.SERVICIU = SERVICIU.CODOBIECT
    LEFT JOIN NART ASERV ON ASERV.CODARTICOL = SERVICIU.CODARTICOL
    LEFT JOIN NCLASEA CLSI ON CLSI.CODCLASEA = ASERV.CLASA
    LEFT JOIN NCLASEINT CLSINT ON I.CLASA = CLSINT.CODCLASEINT &apos;||
    gSuplJoins||
  sWhere;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_intervutilaje; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E93E3112B491816E3CBAA9FAC8764D53F5A9A305</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INTRARI IS

  vLista       NUMBER(1);
  vUm          NUMBER(1);
  vFiltru      VARCHAR2(1000):=&apos;&apos;;
  sCursRef     VARCHAR2(1000);

  CT_UM_ART    CONSTANT NUMBER := 1;

  gSuplCols    VARCHAR2(2000);

  pLISTID      NUMBER;
  pLISTVER     NUMBER;

PROCEDURE setVar(aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  pToateArt BOOLEAN       := PKG_LIST_SELINTIES.ToateArt;
  pDupaData BOOLEAN       := PKG_LIST_SELINTIES.DupaData;
  sData     VARCHAR2(500) := PKG_LIST_SELINTIES.Perioada;
  pLista    NUMBER        := PKG_LIST_SELINTIES.Lista;
  pUM       NUMBER        := PKG_LIST_SELINTIES.Um;
  pInclNeop BOOLEAN       := PKG_LIST_SELINTIES.Extra1;
  aSitV     NUMBER(1);
  aBancaV   NUMBER(20);
  aMonedaV  NUMBER(20);
BEGIN
  pLISTID  := aLISTID;
  pLISTVER := aLISTVER;
  vUm      := pUm;
  vLista   := pLista;

  vFiltru  := &apos;
  WHERE Coalesce(i1.cant,0) &lt;&gt; 0 AND i.anulat = 0&apos;;
  IF NOT pInclNeop THEN
    vFiltru := vFiltru||&apos; AND i.operat = 1 &apos;;
  END IF;
  vFiltru := vFiltru||&apos;
    AND NOT (i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(i1.contdiscount,0) = 0) &apos;;
  vFiltru := vFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;);
  vFiltru := vFiltru||&apos;
    AND Coalesce(i.initializari,0) = 0 &apos;;
  IF pDupaData THEN
    vFiltru := vFiltru||&apos;
    AND i.datadoc &apos; || sData||&apos; &apos;;
  ELSE
    vFiltru := vFiltru||&apos;
    AND (i.luna + i.an * 12) &apos; || sData||&apos; &apos;;
  END IF;
  vFiltru := vFiltru||&apos;
    AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; ) &apos;;
  IF NOT pToateArt THEN
    vFiltru := vFiltru||&apos;
    AND I1.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i.datadoc )&apos;;
  ELSE sCursRef := &apos;, 1 &apos;;
  END IF;
END;

FUNCTION  Sql_tmp_lst_intrari   (pFiltru IN VARCHAR2) RETURN CLOB IS
BEGIN 
  RETURN
  &apos;INSERT INTO tmp_lst_intrari
  SELECT
    i.codintr, i.tipdoc, Coalesce(ae.nrdoc,i.nraviz) nraviz, Coalesce(ae.delegat,i.delegat) delegat,
    i1.codintr1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.umsec, i1.gestact, i1.obs obsart, i1.addim, i1.codcentru, i1.codanalizanod,
    CASE WHEN Coalesce(i1.codauto,0) &lt;&gt; 0 THEN i1.codauto WHEN Coalesce(i.codauto,0) &lt;&gt; 0 THEN i.codauto ELSE 0 END codauto,
    CASE
      WHEN (i1.tiplinie = &apos;&apos;=&apos;&apos;) OR (ae1.codintr1 IS NOT NULL) THEN 0
      WHEN i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;) THEN i1.contserv
      ELSE i1.contdiscount
    END codcont,
    CASE
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 3 THEN (i1.restfact - Coalesce(i1.tva,0)) / i1.cant
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN i1.restfact / i1.cant
      WHEN i.tipdoc = 3 THEN (i1.pu - Coalesce(i1.tva,0) / i1.cant)
      ELSE i1.pu
    END pu,
    CASE
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN 0
      WHEN i1.pu = i1.pretorig THEN 0
      WHEN i.tipdoc = 3 THEN (i1.pu - Coalesce(i1.tva,0) / i1.cant) * i1.pretorig / i1.pu
      ELSE i1.pu - i1.pretorig
    END discu,
    ROUND(CASE
      WHEN COALESCE(dvi1.tva,i1.tva,0) = 0 THEN 0
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.restfact = 0 THEN 0
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i.tipdoc = 3 THEN i1.tva / (i1.restfact-i1.tva)
      WHEN i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN COALESCE(dvi1.tva/DECODE(i.curs,NULL,1,0,1,i.curs),i1.tva,0) / i1.restfact
      WHEN dvi1.pretimport*i1.cant = 0 THEN 0
      WHEN i1.pu * i1.cant = 0 THEN 0
      WHEN i.tipdoc = 3 AND i1.pu * i1.cant = i1.tva THEN 0
      WHEN i.tipdoc = 3 THEN i1.tva / (i1.pu * i1.cant-i1.tva)
      ELSE COALESCE(dvi1.tva/(dvi1.pretimport*i1.cant),i1.tva/(i1.pu*i1.cant),0)
    END,2) coef_tva, Coalesce(ila.cant,i1.cant) cant,
    CASE
      WHEN Coalesce(i1.cant,0) = 0 THEN 0
      WHEN Coalesce(dvi1.tva,0) = 0 THEN Coalesce(i1.tva,0)/i1.cant
      WHEN dvi1.pretoriginal = dvi1.pretimport THEN dvi1.tva/DECODE(i.curs,NULL,1,0,1,i.curs)/i1.cant
      WHEN dvi1.pretimport &lt;&gt; 0 THEN dvi1.tva*dvi1.pretoriginal/dvi1.pretimport/DECODE(i.curs,NULL,1,0,1,i.curs)/i1.cant
      ELSE 0
    END tvau,
    DECODE(i1.tvaneded,3,1/2,1,1,0) + CASE WHEN Coalesce(i.tiptva,0) &lt;&gt; 4 THEN 0 WHEN Coalesce(i1.tvaneded,0) = 0 THEN 1-Coalesce(i.prorata,0)/100 WHEN i1.tvaneded = 3 THEN 1/2*(1-Coalesce(i.prorata,0)/100) ELSE 0 END coeftned,
    DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,Coalesce(SUM(Coalesce(-l1.cant,Coalesce(nser.cantnir*DECODE(ns.cantnir,0,1,Coalesce(ns.cantfurn,0)/ns.cantnir),ns.cantfurn)) * Decode(ae1.cant,NULL,1,0,1,Coalesce(ila.cant,i1.cant)/ae1.cant)),Coalesce(ila.cant,i1.cant)),Coalesce(ila.cant,i1.cant)) cantrec,
    DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,&apos;&apos;Stoc&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;Avans&apos;&apos;,&apos;&apos;Serviciu&apos;&apos;) tipart,
    SUM(Coalesce(-l1.cant,Coalesce(nser.cantnir*DECODE(ns.cantnir,0,1,Coalesce(ns.cantfurn,0)/ns.cantnir),ns.cantfurn)) * Coalesce(ns.pret - ns.adaos,0) * Decode(ae1.cant,NULL,1,0,1,Coalesce(ila.cant,i1.cant)/ae1.cant)) valachiz,
    SUM(Coalesce(-l1.cant,Coalesce(nser.cantnir*DECODE(ns.cantnir,0,1,Coalesce(ns.cantfurn,0)/ns.cantnir),ns.cantfurn)) * Coalesce(ns.pret,0) * Decode(ae1.cant,NULL,1,0,1,Coalesce(ila.cant,i1.cant)/ae1.cant)) valinreg,
    MAX(Coalesce(ns.pumaximal,0)) pumaximal,
    CASE MAX(Coalesce(ns.tipserie,0))
      WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))
      WHEN 2 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||Coalesce(l1.cant,nser.cantnir)||&apos;&apos;#~)&apos;&apos; ORDER BY s.serie) AS vc2_nt))
      ELSE NULL
    END SERII,
    vc2_nt_to_string(CAST(collect(DISTINCT to_char(Coalesce(nser.tg, ns.tg))) AS vc2_nt)) tg,
    decode(MAX(Coalesce(ns.tipserie,0)),1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
    SUM(Coalesce(-l1.cantum1, Coalesce(nser.cantum1,ns.cantum1)) * Decode(ae1.cant,NULL,1,0,1,Coalesce(ila.cant,i1.cant)/ae1.cant)) cantum1, SUM(Coalesce(-l1.cantum2, Coalesce(nser.cantum2,ns.cantum2)) * Decode(ae1.cant,NULL,1,0,1,Coalesce(ila.cant,i1.cant)/ae1.cant)) cantum2,
    string_agg(distinct(n.datanir)) datanir,
    (SELECT x.codioart1 FROM ioart1 x WHERE x.codioart = ns.codioart AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop ) codioart1,
    (SELECT x.codpart1  FROM npart1 x WHERE x.codpart  = i.partener  AND (i.an*12+i.luna) BETWEEN x.ALStart and x.ALStop ) codpart1,
    Coalesce(ae.codcontract, i.codcontract, 0) codcontract,
    Coalesce(
      ae1.codcontract1,
      i1.codcontract1,
      CASE
        WHEN Coalesce(ae.CodContract,i.codcontract,0) = 0 THEN 0
        ELSE (SELECT Min(X.CodContract1) FROM Contract1 X WHERE X.CodContract = Coalesce(ae.CodContract,i.codcontract,0) AND X.CodObiect = i1.CodObiect)
      END,
      0
    ) codcontract1,
    0 codoferta, Coalesce(pkg_oferta.GetCodOferta1(I1.CODOBIECT, I.DATADOC, I.PARTENER, I.CODLOCATIE, I.SUBUNITATEA, 51, I1.cant), 0) codoferta1,
    0 codcomanda, Coalesce((SELECT ilcom.codliniecomanda FROM intrlink ilcom WHERE ilcom.codintr1 = Coalesce(ae1.codintr1, i1.codintr1) AND ilcom.codliniecomanda IS NOT NULL), 0) codcomanda1,
    ( SELECT Coalesce(SUM(J1.VALOARE),0)
      FROM JURNAL1 J1 INNER JOIN NTAXE1 TT1 ON TT1.CODTAXA = J1.CODDESCRC
      WHERE J1.TIPCONTC = 900 AND J1.CODDOC = I.CODINTR AND J1.TIPDOC = I.TIPDOC AND J1.INDEXLOCAL = I1.CODINTR1
        AND TT1.ALSTART &lt;= I.AN *12+ I.LUNA
        AND TT1.ALSTOP  &gt;= I.AN *12+ I.LUNA
        AND Coalesce(TT1.STOPAJ,0) = 1
    ) / i1.cant TaxaStopajU
  FROM intrari i
    INNER JOIN intrari1       i1   ON i1.codintr = i.codintr
    LEFT  JOIN intrlink       il   ON il.codintr1= i1.codintr1 AND il.codlinieaviz IS NOT NULL
    LEFT  JOIN intrasteptlink ila  ON ila.codliniefactura = i1.codintr1 AND Coalesce(i.tipfactura, 0) = 9
    LEFT  JOIN intrari1       ae1  ON ae1.codintr1 = COALESCE( ila.codintr1, il.codlinieaviz )
    LEFT  JOIN intrari        ae   ON ae.codintr = ae1.codintr
    LEFT  JOIN dvi                 ON dvi.codintr = i.codintr
    LEFT  JOIN dvi1                ON dvi1.coddvi = dvi.coddvi AND dvi1.codintr1 = i1.codintr1
    LEFT  JOIN livr1          l1   ON l1.codintr1 = i1.codintr1
    LEFT  JOIN nirstoc        ns   ON ns.codobiect = i1.codobiect
    AND ( ((l1.codlivr1 IS NOT NULL) AND (ns.codnirstoc = l1.codnirstoc)) OR
          ((l1.codlivr1 IS NULL) AND ((ns.codintr1 = Coalesce(ae1.codintr1,i1.codintr1)) OR (ns.coddvi1 = dvi1.coddvi1))))
    LEFT  JOIN nir            n    ON n.codintr = Coalesce(ae.codintr, i.codintr) AND n.codnir = ns.codnir
    LEFT  JOIN nirser         nser ON (((l1.codlivr1 IS NOT NULL) AND (nser.codnirser = l1.codnirser)) OR
                                      ((l1.codlivr1 IS NULL)     AND (nser.codnirstoc = ns.codnirstoc)) )
    LEFT  JOIN nserii         s    on s.codserie = nser.codserie&apos;||
  pFiltru||&apos;
  GROUP BY
    i.codintr, i.tipdoc, i.delegat, ae.delegat, i.nraviz, ae.nrdoc, i.codauto, i.an, i.luna, i.curs, i.datadoc, i.partener, i.codlocatie, i.subunitatea, i.tiptva, i.prorata,
    i1.codintr1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.umsec, i1.tva, i1.pretorig, i1.pu, ila.cant, i1.cant, i1.coefdiscmaj,
    i1.gestact, i1.contserv, i1.contdiscount, i1.obs, i1.restfact, i1.codauto, i1.addim, i1.codcentru, i1.codanalizanod, i1.tvaneded,
    dvi1.tva, dvi1.pretimport, dvi1.pretoriginal, ae1.codintr1, ns.codioart, ae1.codcontract1, i1.codcontract1,ae.codcontract,i.codcontract&apos;;
END;


PROCEDURE INSERTINTRARI(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pJoinExt IN VARCHAR2) IS
  sInsert     VARCHAR2(30000);
  sInsertTMP  VARCHAR2(30000);
  sUpdateTMP  VARCHAR2(30000);
  sJoinUM     VARCHAR2( 5000);
  sInsertDC   VARCHAR2( 5000);
  sWithDc     VARCHAR2( 5000);
  sSelectDC   VARCHAR2( 5000);
  sJoinDC     VARCHAR2( 5000);
  sJoinCadou  VARCHAR2( 5000);
  sSold       VARCHAR2( 5000)  := &apos;, 0 sold&apos;;
  sDiscContr  VARCHAR2( 5000)  := &apos;, NULL contrpret, NULL ContrTermTip, NULL ContrTerm1, NULL ContrTerm2, NULL ContrTerm3, NULL ContrTerm1Disc, NULL ContrTerm2Disc, NULL ContrTerm3Disc, 0 contraddim, 0 disct, 0 discc, 0 discv, NULL ArtCadou, 0 CantCadou&apos;;
  sDiscNC     VARCHAR2( 5000)  := &apos;, 0 discnct, 0 discncc, 0 discvcc, NULL ArtCadouNC, NULL UMCadouNC, 0 CantCadouNC, 0 PretCadouNC&apos;;
  vMax        INTEGER          := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;

BEGIN
  pkg_globals.SetSeparator(&apos;,&apos;);
  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;i1.cant&apos;,&apos;i1.codobiect&apos;,sInsertDC,sSelectDC,sJoinDC);

  IF vUM = CT_UM_ART THEN
    sJoinUM := &apos;
    LEFT JOIN NUM1 UMSEC ON umsec.codum1 = i1.umsec
    LEFT JOIN NUM1 UM    ON um.codum = umsec.codum AND um.secundara = 0&apos;;
  ELSE
    sJoinUM := &apos;
    LEFT JOIN NUM1 UM ON um.codum1 = i1.umsec&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra2 THEN -- rest sold
    sSold := &apos;,
    CASE
      WHEN i.operat = 0 THEN 0
      WHEN i.valdoc = 0 THEN 0
      WHEN i1.cant*i1.pu = 0 THEN 0
      ELSE i1.cant*(i1.pu+i1.tvau) / i.valdoc * (
        SELECT Sum(Coalesce(ol.rest,o.rest))
        FROM general g
          INNER JOIN obligpif o  ON o.codgeneral = g.codgeneral
          LEFT  JOIN obligpif ol ON ol.codobligasociat = o.codobligpif AND ol.semnificatie = 1353
        WHERE g.tipdoc = i.tipdoc AND g.coddoc = i.codintr AND g.semnificatie = 100 )
    END sold&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra3 THEN -- dicount conform contract
    PKG_CONTRACT.SIMULEAZA_DISCV(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,1);
    PKG_CONTRACT.SIMULEAZA_DISCC(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,1);
    PKG_CONTRACT.SIMULEAZA_CADOU(PKG_LIST_SELINTIES.DataS,PKG_LIST_SELINTIES.DataF,1);

    sDiscContr := &apos;,
    pkg_contract.GETPRET(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc) contrpret,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Tip     ContrTermTip,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Termen1 ContrTerm1,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Termen2 ContrTerm2,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Termen3 ContrTerm3,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Disc1   ContrTerm1Disc,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Disc2   ContrTerm2Disc,
    pkg_contract.GETTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc).Disc3   ContrTerm3Disc,
    pkg_contract.GETADDIM(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc) contraddim,
    --pkg_contract.CALCULEAZA_DISCT_LINIE(I.TipDoc, I1.CodIntr1, I.DataDoc) disct,
    CASE
      WHEN I.operat = 0 THEN 0
      WHEN I1.Cant = 0 THEN 0
      WHEN I1.PU = 0 THEN 0
      WHEN I.TipDoc IN (1,9) THEN pkg_contract.DISCMAXTERMEN(I.TipDoc, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc, I1.Cant, I1.PU)
      ELSE 0
    END disct,
    CASE
      WHEN I.operat = 0 THEN 0
      WHEN I1.Cant = 0 THEN 0
      WHEN I.TipDoc IN (1,9) THEN (
        SELECT
          Coalesce(MAX(
            CASE
              WHEN T.DISCUNITAR &lt;&gt; 0 THEN i1.cant * t.discunitar
              ELSE i1.cant * i1.pu * t.pjdisc / 100
            END),0)
        FROM TMP_INTRDISCC T
        WHERE T.PARTENER = I.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = I.CODLOCATIE)
          AND T.SUBUNITATEA = I.SUBUNITATEA
          AND T.CODOBIECT = I1.CODOBIECT
          AND T.DATASTART &lt;= I.DATADOC AND T.DATASTOP &gt;= I.DATADOC )
      ELSE 0
    END discc,
    CASE
      WHEN I.operat = 0 THEN 0
      WHEN I1.Cant = 0 THEN 0
      WHEN i.TipDoc IN (1,9)
      THEN (
        SELECT Coalesce(MAX(i1.cant*i1.pu*t.disc/t.baza),0)
        FROM TMP_INTRDISCV T
        WHERE T.PARTENER = I.PARTENER
          AND (T.LOCATIE = 0 OR T.LOCATIE = I.CODLOCATIE)
          AND T.SUBUNITATEA = I.SUBUNITATEA
          AND (T.CODOBIECT = 0 OR T.CODOBIECT = I1.CODOBIECT)
          AND T.DATASTART &lt;= I.DATADOC AND T.DATASTOP &gt;= I.DATADOC
          AND Coalesce(T.BAZA,0) &lt;&gt; 0
        )
      ELSE 0
    END discv,
    CASE
      WHEN I.operat = 0 THEN NULL
      WHEN I1.Cant = 0 THEN NULL
      WHEN I.TipDoc IN (1,9) THEN pkg_contract.SIMCADOU_DEN(1, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc)
      ELSE NULL
    END ArtCadou,
    CASE
      WHEN I.operat = 0 THEN 0
      WHEN I1.Cant = 0 THEN 0
      WHEN I.TipDoc IN (1,9) THEN pkg_contract.SIMCADOU_CANT(1, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc, I1.Cant)
      ELSE 0
    END CantCadou&apos;;
  END IF;

  IF PKG_LIST_SELINTIES.Extra4 THEN -- dicount conform note credit
    sJoinCadou :=&apos;
    LEFT JOIN (
      SELECT
        i1.codintr1, o.denumire dencadou, Sum(i1.cant) over (PARTITION BY ncc.codnccadouri) cantasoc,
        ncc.diferente/u1.paritate cantcadou, u1.den_um1 umcadou, pm.lei * u1.paritate pretcadou, Coalesce(u1.zecimale,7) zeccadou
      FROM NCCADOURI NCC
        INNER JOIN NOTECREDIT  NC  ON NC.CODNCREDIT  = NCC.CODNCREDIT
        INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NCC.CODNCREDIT
        INNER JOIN INTRARI1    I1  ON NC1.CODDOC = I1.CODINTR1 AND I1.CODOBIECT = NCC.CODOBIECTASOC
        INNER JOIN INTRARI     I   ON I.CODINTR  = I1.CODINTR AND I.TIPDOC = NC1.TIPDOC
        LEFT  JOIN NARTOBJ     O   ON O.CODOBIECT = NCC.CODOBIECT
        LEFT  JOIN NUM1        U1  ON U1.CODUM1 = NCC.UMSEC
        LEFT  JOIN PRETM       PM  ON PM.CODOBIECT = NCC.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = I.SUBUNITATEA
      WHERE NC.TIPDOC = 59
        AND NC1.TIPOPER = &apos;&apos;C&apos;&apos;
    ) Cad ON cad.codintr1 = i1.codintr1&apos;;

    sDiscNC := &apos;,
    Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
         WHERE NC.TIPDOC = 59 AND NC1.TIPOPER = &apos;&apos;T&apos;&apos; AND NC1.CODDOC = I1.CodIntr1 AND NC1.TIPDOC = I1.TipDoc ),0) disctnc,
    Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
         WHERE NC.TIPDOC = 59 AND NC1.TIPOPER = &apos;&apos;C&apos;&apos; AND NC1.CODDOC = I1.CodIntr1 AND NC1.TIPDOC = I1.TipDoc ),0) disccnc,
    CASE
      WHEN i1.cant*i1.pu = 0 THEN 0
      WHEN i.valdoc = 0 THEN 0
      ELSE PKG_NOTECREDIT.GetDiscVolLinie(I1.CODINTR1, 59)
    END discvnc,
    cad.dencadou, cad.umcadou,
    CASE
      WHEN Coalesce(cad.cantasoc,0) = 0 OR Coalesce(i1.cant,0) = 0 THEN 0
      WHEN i1.cant = cad.cantasoc THEN cad.cantcadou
      ELSE Round(cad.cantcadou*i1.cant/cad.cantasoc,cad.zeccadou)
    END CantCadouNC,
    cad.pretcadou&apos;;
  END IF;

  FOR i in 1..Coalesce(vMax,0) loop
    sInsertDC := sInsertDC||&apos;, CLS&apos;   ||to_char(i)||&apos;, CLSS&apos;  ||to_char(i);
    sSelectDC := sSelectDC||&apos;, CLSC.D&apos;||to_char(i)||&apos;, CLSC.S&apos;||to_char(i);
  END LOOP;

  sWithDC := &apos;
  WITH&apos;;
  IF Coalesce(vMax,0) &gt; 0 THEN
    sWithDC := sWithDC||&apos; Clase AS (
    SELECT codclasea &apos;;
    IF Coalesce(vMax,0) &gt; 0 THEN
      for i in 1..Coalesce(vMax,0) loop
        sWithDC := sWithDC ||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE &apos;&apos;&apos;&apos; end) d&apos;||to_char(i)||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN simbol ELSE &apos;&apos;&apos;&apos; end) s&apos;||to_char(i);
      end loop;
    END IF;
    sWithDC := sWithDC||&apos;
    FROM TMP_PROFIT_NCLASEA
    GROUP BY codclasea)&apos;;

    sJoinDC := sJoinDC||&apos;
    LEFT JOIN CLASE CLSC ON CLSC.CodClasea = na.clasa &apos;;
  ELSE
    sWithDC := &apos;&apos;;
  END IF;

  sInsertTMP := Sql_tmp_lst_intrari(vFiltru);
  sUpdateTMP :=
  &apos;UPDATE tmp_lst_intrari t
  SET t.codcontract = CASE
                        WHEN t.codcontract1 = 0 THEN t.codcontract
                        ELSE Coalesce ( (SELECT c1.codcontract FROM contract1 c1 WHERE c1.codcontract1 = t.codcontract1), t.codcontract )
                      END,
      t.codcomanda  = CASE
                        WHEN t.codcomanda1 = 0 THEN t.codcomanda
                        ELSE Coalesce ( (SELECT c1.codcomanda FROM comanda1 c1 WHERE c1.codcomanda1 = t.codcomanda1), t.codcomanda )
                      END,
      t.codoferta   = CASE
                        WHEN t.codoferta1 = 0 THEN t.codoferta
                        ELSE Coalesce ( (SELECT o1.codoferta FROM oferta1 o1 WHERE o1.codoferta1 = t.codoferta1), t.codoferta )
                      END&apos;;

  sInsert:=&apos;
  INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, CODOBIECT, TIPART, DEN_ARTICOL,
    IOART, SIMBOL, DEN_CONT, DEN_UM1, CANT,
    PU, PU_CU_TVA, PU_CU_TVAN, ADDIM,
    PROC_TVA, PROC_TVA_NART, DISCTOTAL, DISCTOT_TVA, DISCTOTCUTVA,
    VALOARE, VAL_TVA, VAL_CU_TVA, VAL_TVAN, VAL_CU_TVAN,
    DEN_PART, DATADOC, TIPDOC, NRDOC,
    DOCUMENT, NRAVIZ, SERDOC,
    BLOCAT, MONEDA, CURS, MASA, VOLUM, CODVAMAL, OBSLINIE, DEN_CLASEA,
    CODINTERNA, CODEXTERNA, DEN_PROD, UMALT1, UMALT2,
    CANTUM1, CANTUM2,
    PRETMAXIMAL,
    DEN_LOCALIT, DEN_JUDET, DEN_ZONA,
    TIPTVA, TIPTRANZ,
    DEN_CLASEP, CODFISCAL, CODEXTERNP, CODINTERNP, GESTACT, TIPSERIE, SERIE,
    ZILESCADENTE, TERMEN, MAJORARI, OBSDOC, INDEXLINIE,
    ANDOC, LUNADOC, LUNA, SUBUNITATEA, PRETINREG,
    CUICorect, clasas, nrinreg, datanir, EXCLUSPLATA,
    TRANSPORT, CONTRACT, ZILEDISCT,
    TaxaStopajU, TaxaStopajV, TAXCODE_SAFT,
    SOLD, CONTRPRET,
    CONTRTERMTIP, CONTRTERM1, CONTRTERM2, CONTRTERM3, CONTRTERM1DISC, CONTRTERM2DISC, CONTRTERM3DISC,
    CONTRADDIM, DISCT, DISCC, DISCV, ARTCADOU, CANTCADOU,
    DISCTNC, DISCCNC, DISCVNC, ARTCADOUNC, UMCADOUNC, CANTCADOUNC, PRETCADOUNC,
    curs_ref &apos;||sInsertDC||pUserFields||&apos;)&apos;||
  sWithDC||&apos;
  SELECT
    i1.codintr, i1.tipdoc , i1.codobiect, i1.tipart, DECODE(i1.tiplinie, &apos;&apos;T&apos;&apos;,&apos;&apos;Majorare direct pe cont (de total)&apos;&apos; ,&apos;&apos;G&apos;&apos;,&apos;&apos;Majorare direct pe cont (de grup)&apos;&apos;, nao.denumire),
    ioa.den_ioart, nc.simbol, Coalesce(nc.den_cont,&apos;&apos;-&apos;&apos;), DECODE(i1.tiplinie,&apos;&apos;T&apos;&apos;,&apos;&apos;%&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;%&apos;&apos;,um.den_um1), i1.cantrec/Coalesce(um.paritate,1),
    i1.pu*Coalesce(um.paritate,1), (i1.pu+i1.tvau)*Coalesce(um.paritate,1), (i1.pu+i1.tvau*i1.coeftned)*Coalesce(um.paritate,1), i1.addim,
    i1.coef_tva * 100, nt1.procent,i1.cantrec*i1.discu, i1.cantrec*i1.discu*i1.coef_tva, i1.cantrec*i1.discu*(1+i1.coef_tva),
    i1.cantrec*i1.pu, i1.cantrec*i1.tvau, i1.cantrec*(i1.pu+i1.tvau), i1.cantrec*i1.tvau*i1.coeftned, i1.cantrec*(i1.pu+i1.tvau*i1.coeftned),
    DECODE(i1.tipdoc,6,ns.den_subunit,7,ng.den_gest,np.den_part), i.datadoc, DECODE(i1.tipdoc,9,&apos;&apos;FA&apos;&apos;,i.prefixdoc), i.nrdoc,
    i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), i1.nraviz, i.seriadoc,
    DECODE (i.blocat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), mon.simbol, DECODE(i.curs,NULL,1,0,1,i.curs), nao.masa, nao.volum, nao.codvamal, i1.obsart, nca.den_clasea,
    nao.codintern, nao.codextern, prod.den_part, um1.den_um, um2.den_um,
    DECODE(i1.cantrec,0,0,i1.cant,i1.cantum1,i1.cantum1*i1.cant/i1.cantrec),DECODE(i1.cantrec,0,0,i1.cant,i1.cantum2,i1.cantum2*i1.cant/i1.cantrec),
    CASE WHEN Coalesce(nao1.tippretmax,0) IN (1,2,3) THEN i1.pumaximal WHEN Coalesce(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
    locsoc.den_localit,judsoc.den_judet, zonasoc.den_zona,
    DECODE(i.tiptva,1,&apos;&apos;Taxare normala&apos;&apos;,2,&apos;&apos;Taxare inversa&apos;&apos;,3,&apos;&apos;Tranzactie triunghiulara&apos;&apos;,4,&apos;&apos;Suspendare temporara&apos;&apos;),
    CASE
      WHEN i.tiptranzactie = 2 THEN &apos;&apos;Achizitie intracomunitara&apos;&apos;
      WHEN i.tiptranzactie = 3 THEN &apos;&apos;Import servicii&apos;&apos;
      WHEN i1.tipdoc = 5 THEN &apos;&apos;Import&apos;&apos;
      WHEN i.tiptranzactie = 1 THEN &apos;&apos;Tranzactie interna&apos;&apos;
    END,
    ncp.den_clasep, fisc.codfiscal, np.codextern, np.codintern,ngserv.den_gest,i1.tipserie,i1.serii,
    t.termen - i.datadoc,t.termen,t.majorari,i.obs, i1.indexlocal,
    i.an andoc, i.luna lunadoc, to_char(i.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(i.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(i.Luna) luna,
    nsub.den_subunit, i1.valinreg / Decode(i1.cantrec,0,1,i1.cantrec),
    DECODE(cif_valid(FISC.CodFiscal),0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), NCLS.DEN_CLASEAS, I.NRI, I1.datanir, DECODE(i.exclusplata,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;),
    paut.nrinreg, contr.seriadoc||contr.nrdoc||&apos;&apos;/&apos;&apos;||to_char(contr.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), null ziledisct,
    i1.TaxaStopajU*Coalesce(um.paritate,1) TaxaStopajU, i1.TaxaStopajU*i1.cantrec TaxaStopajV, TXDCL.TAXCODE AS TAXCODE_SAFT &apos;||
    sSold||sDiscContr||sDiscNc||sCursRef||sSelectDC||pUserAlias||&apos;
  FROM tmp_lst_intrari I1
    LEFT JOIN COMANDA      C       ON C.CODCOMANDA = I1.CODCOMANDA
    LEFT JOIN INTRARI      I       ON I.CodIntr = I1.CodIntr
    LEFT JOIN NARTOBJ      NAO     ON nao.codobiect = i1.codobiect
    LEFT JOIN NART         NA      ON na.codarticol = nao.codarticol
    LEFT JOIN NCLASEA      NCA     ON nca.codclasea = na.clasa &apos;||
    sJoinUM||sJoinDC||sJoinCadou||&apos;
    LEFT JOIN NUM          UM1     ON um1.codum = na.um1
    LEFT JOIN NUM          UM2     ON um2.codum = na.um2
    LEFT JOIN NPART        NP      ON np.codpart = i.partener
    LEFT JOIN NAGENDA      SSOC    ON ssoc.codpart = i.partener AND ssoc.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(ssoc.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT     LOCSOC  ON locsoc.codlocalit = ssoc.codlocalit
    LEFT JOIN NJUDET       JUDSOC  ON judsoc.codjudet = locsoc.codjudet
    LEFT JOIN NZONE        ZONASOC ON zonasoc.codzona = locsoc.codzona
    LEFT JOIN NPARTCODFISC FISC    ON fisc.codpart = i.partener AND fisc.principal = 1
    LEFT JOIN NCLASEP      NCP     ON ncp.codclasep = np.codclasa
    LEFT JOIN NGEST        NG      ON ng.codgest = i.codgestprod
    LEFT JOIN NGEST        NGSERV  ON ngserv.codgest = i1.gestact
    LEFT JOIN NSUBUNIT     NS      ON ns.codsubunit = i.codsubunit
    LEFT JOIN NSUBUNIT     NSUB    ON nsub.codsubunit = i.subunitatea
    LEFT JOIN NMONEDE      MON     ON mon.codmoneda = i.moneda
    LEFT JOIN NPART        PROD    ON prod.codpart = nao.codproducator
    LEFT JOIN NCLASEAS     NCLS    ON NCLS.CODCLASEAS = NA.CLASASTATIST
    LEFT JOIN (
      SELECT g.coddoc, g.tipdoc, MAX(o.termen) termen, MAX(o.majorari) majorari
      FROM obligpif o INNER JOIN general g ON g.codgeneral = o.codgeneral
      WHERE o.termen IS NOT NULL AND o.semnificatie = 100
      GROUP BY g.coddoc, g.tipdoc) T on t.coddoc = i1.codintr AND t.tipdoc = i1.tipdoc
    LEFT JOIN NARTOBJ1     NAO1    ON nao1.codobiect = i1.codobiect AND (i.an*12+i.luna) BETWEEN nao1.alstart AND nao1.alstop
    LEFT JOIN NART1        NA1     ON na1.codarticol = nao.codarticol AND (i.an*12+i.luna) BETWEEN na1.alstart AND na1.alstop
    LEFT JOIN NTVA1        NT1     ON nt1.codtva = na1.codtva AND (i.an*12+i.luna) BETWEEN nt1.alstart AND nt1.alstop
    LEFT JOIN NPART1       NP1     ON np1.codpart1 = i1.codpart1
    LEFT JOIN IOART1       IOA1    ON IOA1.CodIOArt1 = I1.CodIOArt1
    LEFT JOIN IOART        IOA     ON IOA.CodIOArt = IOA1.CodIOArt
    LEFT JOIN IOPART       IOP     ON IOP.CodIOPart = NP1.CodIOPart
    LEFT JOIN NCONT        NC      ON nc.codcont = COALESCE(ioa1.cont,i1.codcont,0)
    LEFT JOIN NPARCAUT     PAUT    ON PAUT.CODNPARCAUT = I1.CODAUTO
    LEFT JOIN OFERTA       O       ON O.CODOFERTA = I1.CODOFERTA
    LEFT JOIN TAXDECL      TXDCL   ON TXDCL.TIPDOC = I.TIPDOC AND TXDCL.CODDOC = I.CODINTR AND TXDCL.CODDOC1 = I1.CODINTR1
    LEFT JOIN CONTRACT     CONTR   ON contr.codcontract = i1.codcontract&apos;||
    pJoinExt;

  --pkg_list_base_utils.UMPLE_TMP_NARTOBJ1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NART1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NTVA1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NTAXE1_LST;
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);
  PRC_AL_CHECK(&apos;NTAXE1&apos;);

  DELETE tmp_lst_intrari;
  LIST_EXECUTE_IMMEDIATE(sInsertTMP, pLISTID, pLISTVER);
  LIST_EXECUTE_IMMEDIATE(sUpdateTMP, pLISTID, pLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsert,    pLISTID, pLISTVER);
  COMMIT;
END;

PROCEDURE INSERTSINTEZA(TmpName IN VARCHAR2, pUserFields IN VARCHAR2, pUserAlias IN VARCHAR2, pNullAlias IN VARCHAR2, pJoinExt IN VARCHAR2) IS
  sInsert    VARCHAR2(30000);
  sInsertTMP VARCHAR2(30000);
  sSold      VARCHAR2( 1000) := &apos;, 0 sold&apos;;
BEGIN
  IF PKG_LIST_SELINTIES.Extra2 THEN -- rest sold
    sSold := &apos;,
    CASE
      WHEN i.operat = 0 THEN 0
      WHEN i.valdoc = 0 THEN 0
      ELSE (
        SELECT Sum(Coalesce(ol.rest,o.rest))
        FROM general g
          INNER JOIN obligpif o  ON o.codgeneral = g.codgeneral
          LEFT  JOIN obligpif ol ON ol.codobligasociat = o.codobligpif AND ol.semnificatie = 1353
        WHERE g.tipdoc = i.tipdoc AND g.coddoc = i.codintr AND g.semnificatie = 100 )
    END sold&apos;;
  END IF;

  sInsertTMP := &apos;
  INSERT INTO tmp_lst_intrsint
  SELECT
    i.codintr,
    SUM((CASE WHEN i.tipdoc IN (3) THEN (i1.pu - Coalesce(i1.tva,0) / i1.cant) ELSE i1.pu END)* i1.cant) val,
    SUM(Coalesce(i1.tva,0)) tva,
    SUM(i1.cant*i1.pretorig * Coalesce(i1.coefdiscmaj,1) * (CASE WHEN i.tipdoc IN (3) THEN (1 - CASE WHEN COALESCE(I1.PU,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0) / (i1.cant * i1.pu) END) ELSE 1 END)) valint
  FROM intrari i INNER JOIN intrari1 i1 ON i1.codintr = i.codintr &apos;||
  vFiltru||&apos;
  GROUP BY i.codintr&apos;;

  sInsert:=&apos;
  INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_TipDoc,
    PARTENER,DEN_LOCALIT,DEN_JUDET,DEN_ZONA,DEN_CLASEP,
    TIPDOC, TIPTVA, TIPTRANZ,
    PREFIXDOC,NRDOC,DATADOC,DOCUMENT,NRAVIZ,SERDOC,
    MARFA,DISCMAJ,PJ_DISC,
    VALOARE,VAL_TVA,VAL_CU_TVA,
    BLOCAT,DEN_MONEDA,CURS,TERMEN,OBS,
    ANDOC,LUNADOC,LUNA,
    SUBUNITATEA,CODFISC,CUICorect,NRINREG,
    EXCLUSPLATA,
    TRANSPORT,CONTRACT,
    SOLD,CURS_REF&apos;||pUserFields||&apos;)
  SELECT
    i.codintr, i.tipdoc ,
    DECODE(i.tipdoc,6,ns.den_subunit,7,ng.den_gest,np.den_part), locsoc.den_localit, judsoc.den_judet, zonasoc.den_zona,ncp.den_clasep,
    DECODE (i.tipdoc, 1,&apos;&apos;Facturi&apos;&apos;,   2,&apos;&apos;Avize exped.&apos;&apos;, 3,&apos;&apos;Chit. fisc.&apos;&apos;,   4,&apos;&apos;Pers. fiz.&apos;&apos;, 5,&apos;&apos;Importuri&apos;&apos;, 6,&apos;&apos;Subunit.&apos;&apos;, 7,&apos;&apos;Note predare&apos;&apos;, 9,&apos;&apos;Fact. la avize&apos;&apos; ) ,
    DECODE(i.tiptva,1,&apos;&apos;Taxare normala&apos;&apos;,2,&apos;&apos;Taxare inversa&apos;&apos;,3,&apos;&apos;Tranzactie triunghiulara&apos;&apos;,4,&apos;&apos;Suspendare temporara&apos;&apos;),
    DECODE(i.tipdoc, 5,&apos;&apos;Import&apos;&apos;, DECODE(i.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Achizitie intracomunitara&apos;&apos;,3,&apos;&apos;Import servicii&apos;&apos;)),
    i.prefixdoc, i.nrdoc, i.datadoc, i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), i.nraviz, i.seriadoc,
    i1.val, (i.valdoc - i.tvadoc) - i1.val, DECODE(i1.val,i.valdoc - i.tvadoc,0,0,0,((i.valdoc - i.tvadoc)/i1.val - 1)*100),
    i.valdoc - i.tvadoc, i.tvadoc, i.valdoc,
    DECODE (i.blocat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), mon.simbol, DECODE(i.curs,NULL,1,0,1,i.curs), t.termen, i.obs,
    i.an andoc, i.luna lunadoc, to_char(i.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(i.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(i.Luna) luna,
    nsub.den_subunit, fisc.codfiscal, DECODE(cif_valid(FISC.CodFiscal),0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;), I.NRI, DECODE(i.exclusplata,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;),
    paut.nrinreg, contr.seriadoc||contr.nrdoc||&apos;&apos;/&apos;&apos;||to_char(contr.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
    sSold||sCursRef||pUserAlias||&apos;
  FROM tmp_lst_intrsint I1
    LEFT JOIN INTRARI        I          ON I.CodIntr = I1.CodIntr
    LEFT JOIN TMP_UTILIZATOR UTILIZATOR ON utilizator.codutilizator = i.userid
    LEFT JOIN NPART          NP         ON np.codpart = i.partener
    LEFT JOIN NAGENDA        SSOC       ON ssoc.codpart = i.partener AND ssoc.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(ssoc.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT       LOCSOC     ON locsoc.codlocalit = ssoc.codlocalit
    LEFT JOIN NTARI          TARASOC    ON LOCSOC.codtara = TARASOC.codtara
    LEFT JOIN NJUDET         JUDSOC     ON judsoc.codjudet = locsoc.codjudet
    LEFT JOIN NZONE          ZONASOC    ON zonasoc.codzona = locsoc.codzona
    LEFT JOIN NPARTCODFISC   FISC       ON fisc.codpart = i.partener AND fisc.principal = 1
    LEFT JOIN NCLASEP        NCP        ON ncp.codclasep = np.codclasa
    LEFT JOIN NGEST          NG         ON ng.codgest = i.codgestprod
    LEFT JOIN NSUBUNIT       NS         ON ns.codsubunit = i.codsubunit
    LEFT JOIN NSUBUNIT       NSUB       ON nsub.codsubunit = i.subunitatea
    LEFT JOIN NMONEDE        MON        ON mon.codmoneda = Coalesce(i.moneda,0)
    LEFT JOIN NPARTTR        NPTR       ON nptr.codparttr = i.delegat
    LEFT JOIN NPARCAUT       PAUT       ON PAUT.CODNPARCAUT = Coalesce(I.CODAUTO,0)
    LEFT JOIN CONTRACT       CONTR      ON CONTR.CODCONTRACT = I.CODCONTRACT
    LEFT JOIN (
      SELECT g.coddoc, g.tipdoc, MAX(o.termen) termen, MAX(o.majorari) majorari
      FROM obligpif o INNER JOIN general g ON g.codgeneral = o.codgeneral
      WHERE o.termen IS NOT NULL AND o.semnificatie = 100
      GROUP BY g.coddoc, g.tipdoc) T on t.coddoc = i.codintr AND t.tipdoc = i.tipdoc &apos;||
    pJoinExt;

  DELETE tmp_lst_intrsint;
  LIST_EXECUTE_IMMEDIATE(sInsertTMP, pLISTID, pLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsert,    pLISTID, pLISTVER);
  COMMIT;
END;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
BEGIN
  gSuplCols :=
    &apos;TMP_LST_INTRARI I1, INTRARI I, NARTOBJ NAO, NART NA, NCLASEA NCA, NUM UM1, NUM UM2, NPART NP, NAGENDA SSOC, NLOCALIT LOCSOC, NJUDET JUDSOC, NZONE ZONASOC,&apos;||
    &apos;NPARTCODFISC FISC, NCLASEP NCP, NGEST NG, NGEST NGSERV, NSUBUNIT NS, NSUBUNIT NSUB, NMONEDE MON, NPART PROD, NARTOBJ1 NAO1, NART1 NA1,&apos;||
    &apos;NTVA1 NT1, NCONT NC, CONTRACT CONTR, COMANDA C, OFERTA O, IOART IOA, IOPART IOP, TAXDECL TXDCL&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;,&apos;UTILIZATOR&apos;,&apos;UTILIZATOR.CODUTILIZATOR = I.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTCODFISC&apos;,  &apos;CFF&apos;,       &apos;CFF.COD_CODFISCAL = I.CODFISCAL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,      &apos;PD&apos;,        &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,       &apos;NPTR&apos;,      &apos;NPTR.CODPARTTR = I1.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,    &apos;OEXT&apos;,      &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,    &apos;OATR&apos;,      &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,       &apos;ACLI&apos;,      &apos;ACLI.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(I1.CODOBIECT, I.PARTENER, NP.CODCLASA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,       &apos;AA&apos;,        &apos;AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;,     &apos;CONTR1&apos;,    &apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1&apos;,       &apos;O1&apos;,        &apos;O1.CODOFERTA1 = I1.CODOFERTA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,      &apos;C1&apos;,        &apos;C1.CODCOMANDA1 = I1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,    &apos;CC&apos;,        &apos;CC.CODCENTRU = I1.CODCENTRU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,      &apos;INTR1&apos;,     &apos;INTR1.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,      &apos;INTRF&apos;,     &apos;INTRF.CODINTR = I1.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF1&apos;,     &apos;INTRF1&apos;,    &apos;INTRF1.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF&apos;,       &apos;CFEXT&apos;,     &apos;CFEXT.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF1&apos;,      &apos;CF1EXT&apos;,    &apos;CF1EXT.CODCOMANDA1 = I1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,    &apos;ANOD&apos;,      &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZA&apos;,       &apos;ANALIZ&apos;,    &apos;ANALIZA.CODANALIZ = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;,  &apos;ADESC1&apos;,    &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;,   &apos;ADESC&apos;,     &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,         &apos;TARASOC&apos;,   &apos;TARASOC.CODTARA = LOCSOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,       &apos;SPROD&apos;,     &apos;SPROD.CODPART = NAO.CODPRODUCATOR AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,      &apos;LOCPROD&apos;,   &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,         &apos;TARAPROD&apos;,  &apos;TARAPROD.CODTARA = LOCPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJTRAD&apos; ,  &apos;TRAD&apos;,      &apos;TRAD.CODOBIECT = NAO.CODOBIECT AND TRAD.CODLIMBA = &apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;LimbaDenArt&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),0));
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  setVar(aLISTID, aLISTVER);
  InsertIntrari(tmpName, gUserFields, gUserAlias, gNullAlias, gSuplJoins);
  -- INSERTSINTEZA se apeleaza din PKG_LIST_BASE_INTRARISINT (am facut aceasta rupere pt ca am probleme la coloanele suplimentare

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_INTRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INTRARISINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFED7CC8C9E8C84B9BA5B82173D1826F48EABF58</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_intrarisint IS

  gSuplCols   VARCHAR2(2500);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
BEGIN
  -- separat de pkg_list_base_intrari pt ca daca se lans in paralel list intrari si intrarisinteza erau probleme cu coloanele suplimentare
  gSuplCols :=
    &apos;INTRARI I, NPART NP, NAGENDA SSOC, NLOCALIT LOCSOC, NJUDET JUDSOC, NZONE ZONASOC, NPARTCODFISC FISC, NCLASEP NCP, NGEST NG, NSUBUNIT NS,&apos;||
    &apos;NSUBUNIT NSUB, NMONEDE MON, TMP_UTILIZATOR UTILIZATOR, NTARI TARASOC, NPARTTR NPTR, CONTRACT CONTR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTCODFISC&apos;, &apos;CFF&apos;,   &apos;CFF.COD_CODFISCAL = I.CODFISCAL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,     &apos;PD&apos;,    &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,     &apos;INTRF&apos;, &apos;INTRF.CODINTR = I.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRFAST&apos;,     &apos;IFAST&apos;, &apos;IFAST.CODINTR = I.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRAST&apos;,      &apos;IAST&apos;,  &apos;IAST.CODINTR = I.CODINTR&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_list_base_intrari.setVar(aLISTID, aLISTVER);
  pkg_list_base_intrari.InsertSinteza(tmpName, gUserFields, gUserAlias, gNullAlias, gSuplJoins);
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_intrarisint;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INTREXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCC661EC56346760382ED578695E2FEFA685E2D6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INTREXT IS
  gSuplCols   VARCHAR2(3000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  gUserFields VARCHAR2(3000);
  gUserAlias  VARCHAR2(3000);
  gNullAlias  VARCHAR2(3000);
  sFiltru     VARCHAR2(3000);
  sTMPUtils   CLOB;
  sTruncTMP   CLOB;
  sInsertTMP  CLOB;
  sInsert     CLOB;
  pUsername   VARCHAR2(100);
  pFirmeExt   VARCHAR2(3000) := pkg_categconst.GetValConstanta(&apos;StocExternFirma&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pCampExt    VARCHAR2(100)  := PKG_LIST_BASE_UTILS.Get_StocExternCamp;
BEGIN
  gSuplCols :=
    &apos;TMP_LST_INTRARI I1, INTRARI I, NARTOBJ NAO, NART NA, NCLASEA NCA, NUM UM1, NUM UM2, NPART NP, NAGENDA SSOC, NLOCALIT LOCSOC, NJUDET JUDSOC, NZONE ZONASOC,&apos;||
    &apos;NPARTCODFISC FISC, NCLASEP NCP, NGEST NG, NGEST NGSERV, NSUBUNIT NS, NSUBUNIT NSUB, NMONEDE MON, NPART PROD, NARTOBJ1 NAO1, NART1 NA1,&apos;||
    &apos;NTVA1 NT1, NCONT NC, CONTRACT CONTR, COMANDA C, OFERTA O, IOART IOA, IOPART IOP&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;,&apos;UTILIZATOR&apos;,&apos;UTILIZATOR.CODUTILIZATOR = I.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTCODFISC&apos;,  &apos;CFF&apos;,       &apos;CFF.COD_CODFISCAL = I.CODFISCAL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,      &apos;PD&apos;,        &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,       &apos;NPTR&apos;,      &apos;NPTR.CODPARTTR = I1.DELEGAT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,    &apos;OEXT&apos;,      &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,    &apos;OATR&apos;,      &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,       &apos;ACLI&apos;,      &apos;ACLI.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(I1.CODOBIECT, I.PARTENER, NP.CODCLASA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,       &apos;AA&apos;,        &apos;AA.CODOBIECT = I1.CODOBIECT AND AA.UMSEC = I1.UMSEC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;,     &apos;CONTR1&apos;,    &apos;CONTR1.CODCONTRACT1 = I1.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1&apos;,       &apos;O1&apos;,        &apos;O1.CODOFERTA1 = I1.CODOFERTA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,      &apos;C1&apos;,        &apos;C1.CODCOMANDA1 = I1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,    &apos;CC&apos;,        &apos;CC.CODCENTRU = I1.CODCENTRU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,      &apos;INTR1&apos;,     &apos;INTR1.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,      &apos;INTRF&apos;,     &apos;INTRF.CODINTR = I1.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF1&apos;,     &apos;INTRF1&apos;,    &apos;INTRF1.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF&apos;,       &apos;CFEXT&apos;,     &apos;CFEXT.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF1&apos;,      &apos;CF1EXT&apos;,    &apos;CF1EXT.CODCOMANDA1 = I1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,    &apos;ANOD&apos;,      &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZA&apos;,       &apos;ANALIZ&apos;,    &apos;ANALIZA.CODANALIZ = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;,  &apos;ADESC1&apos;,    &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;,   &apos;ADESC&apos;,     &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,         &apos;TARASOC&apos;,   &apos;TARASOC.CODTARA = LOCSOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,       &apos;SPROD&apos;,     &apos;SPROD.CODPART = NAO.CODPRODUCATOR AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,      &apos;LOCPROD&apos;,   &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,         &apos;TARAPROD&apos;,  &apos;TARAPROD.CODTARA = LOCPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJTRAD&apos; ,  &apos;TRAD&apos;,      &apos;TRAD.CODOBIECT = NAO.CODOBIECT AND TRAD.CODLIMBA = &apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;LimbaDenArt&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),0));
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;
  WHERE Coalesce(i1.cant,0) &lt;&gt; 0 AND i.anulat = 0
    AND NOT (i1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)
    AND Coalesce(i1.contdiscount,0) = 0)
    AND Coalesce(i.initializari,0) = 0&apos;;

  IF PKG_LIST_SELDOCEXT.DupaData
  THEN
    sFiltru := sFiltru||&apos;
    AND i.datadoc &apos; || PKG_LIST_SELDOCEXT.Perioada||&apos; &apos;;
  ELSE
    sFiltru := sFiltru||&apos;
    AND (i.luna + i.an * 12) &apos; || PKG_LIST_SELDOCEXT.Perioada||&apos; &apos;;
  END IF;
  sFiltru := sFiltru||&apos;
    AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; )&apos;;   

  sTruncTMP := &apos;TRUNCATE TABLE tmp_lst_intrari&apos;;
  sInsertTMP:= PKG_LIST_BASE_INTRARI.Sql_tmp_lst_intrari(sFiltru);

  sInsert:=&apos;
  INSERT INTO &apos;||tmpName||&apos;(
    CODFIRMA, DEN_FIRMA,
    CodDoc, TipDoc, CODOBIECT, TIPART, DEN_ARTICOL,
    IOART, SIMBOL, DEN_CONT, DEN_UM1, CANT,
    PU, PU_CU_TVA, PU_CU_TVAN, ADDIM,
    PROC_TVA, PROC_TVA_NART, DISCTOTAL, DISCTOT_TVA, DISCTOTCUTVA,
    VALOARE, VAL_TVA, VAL_CU_TVA, VAL_TVAN, VAL_CU_TVAN,
    DEN_PART, DATADOC, TIPDOCUMENT, NRDOC,
    DOCUMENT, NRAVIZ, SERDOC,
    BLOCAT, MONEDA, CURS, MASA, VOLUM, CODVAMAL, OBSLINIE, DEN_CLASEA,
    CODINTERNA, CODEXTERNA, DEN_PROD, UMALT1, UMALT2,
    CANTUM1, CANTUM2,
    PRETMAXIMAL,
    DEN_LOCALIT, DEN_JUDET, DEN_ZONA,
    TIPTVA, TIPTRANZ,
    DEN_CLASEP, CODFISCAL, CODEXTERNP, CODINTERNP, GESTACT, TIPSERIE, SERIE,
    ZILESCADENTE, TERMEN, MAJORARI, OBSDOC, INDEXLINIE,
    ANDOC, LUNADOC, LUNA, SUBUNITATEA, PRETINREG,
    CUICorect, clasas, nrinreg, datanir, EXCLUSPLATA&apos;||gUserFields||&apos;)
  SELECT
    TPG.FIRMAID, TPG.FIRMANAME,
    i1.codintr, i1.tipdoc , i1.codobiect, i1.tipart, DECODE(i1.tiplinie, &apos;&apos;T&apos;&apos;,&apos;&apos;Majorare direct pe cont (de total)&apos;&apos; ,&apos;&apos;G&apos;&apos;,&apos;&apos;Majorare direct pe cont (de grup)&apos;&apos;, nao.denumire),
    ioa.den_ioart, nc.simbol, Coalesce(nc.den_cont,&apos;&apos;-&apos;&apos;), DECODE(i1.tiplinie,&apos;&apos;T&apos;&apos;,&apos;&apos;%&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;%&apos;&apos;,um.den_um1), i1.cantrec/Coalesce(um.paritate,1),
    i1.pu*Coalesce(um.paritate,1), (i1.pu+i1.tvau)*Coalesce(um.paritate,1), (i1.pu+i1.tvau*i1.coeftned)*Coalesce(um.paritate,1), i1.addim,
    i1.coef_tva * 100, nt1.procent,i1.cantrec*i1.discu, i1.cantrec*i1.discu*i1.coef_tva, i1.cantrec*i1.discu*(1+i1.coef_tva),
    i1.cantrec*i1.pu, i1.cantrec*i1.tvau, i1.cantrec*(i1.pu+i1.tvau), i1.cantrec*i1.tvau*i1.coeftned, i1.cantrec*(i1.pu+i1.tvau*i1.coeftned),
    DECODE(i1.tipdoc,6,ns.den_subunit,7,ng.den_gest,np.den_part), i.datadoc, DECODE(i1.tipdoc,9,&apos;&apos;FA&apos;&apos;,i.prefixdoc), i.nrdoc,
    i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;), i1.nraviz, i.seriadoc,
    DECODE (i.blocat,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), mon.simbol, DECODE(i.curs,NULL,1,0,1,i.curs), nao.masa, nao.volum, nao.codvamal, i1.obsart, nca.den_clasea,
    nao.codintern, nao.codextern, prod.den_part, um1.den_um, um2.den_um,
    CASE WHEN i1.cantrec = 0 THEN 0 WHEN i1.cantrec = i1.cant THEN i1.cantum1 ELSE i1.cantum1*i1.cant/i1.cantrec END CANTUM1, CASE WHEN i1.cantrec = 0 THEN 0 WHEN i1.cantrec = i1.cant THEN i1.cantum2 ELSE i1.cantum2*i1.cant/i1.cantrec END CANTUM2,
    CASE WHEN Coalesce(nao1.tippretmax,0) IN (1,2,3) THEN i1.pumaximal WHEN Coalesce(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
    locsoc.den_localit,judsoc.den_judet, zonasoc.den_zona,
    CASE WHEN i.tiptva = 1 THEN &apos;&apos;Taxare normala&apos;&apos; WHEN i.tiptva = 2 THEN &apos;&apos;Taxare inversa&apos;&apos; WHEN i.tiptva = 3 THEN &apos;&apos;Tranzactie triunghiulara&apos;&apos; WHEN i.tiptva = 4 THEN &apos;&apos;Suspendare temporara&apos;&apos; END TIPTVA,
    CASE
      WHEN i.tiptranzactie = 2 THEN &apos;&apos;Achizitie intracomunitara&apos;&apos;
      WHEN i.tiptranzactie = 3 THEN &apos;&apos;Import servicii&apos;&apos;
      WHEN i1.tipdoc = 5       THEN &apos;&apos;Import&apos;&apos;
      WHEN i.tiptranzactie = 1 THEN &apos;&apos;Tranzactie interna&apos;&apos;
    END TIPTRANZ,
    ncp.den_clasep, fisc.codfiscal, np.codextern, np.codintern,ngserv.den_gest,i1.tipserie,i1.serii,
    t.termen - i.datadoc, t.termen, t.majorari, i.obs, i1.indexlocal,
    i.an andoc, i.luna lunadoc, to_char(i.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(i.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(i.Luna) luna, nsub.den_subunit, i1.valinreg / Decode(i1.cantrec,0,1,i1.cantrec) PRETINREG,
    CASE WHEN cif_valid(FISC.CodFiscal) = 0 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END CUICorect, NCLS.DEN_CLASEAS, I.NRI, I1.datanir, CASE WHEN i.exclusplata = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END EXCLUSPLATA&apos;||
    gUserAlias||&apos;
  FROM tmp_lst_intrari I1
    CROSS JOIN TMP_PKG_GLOBALS TPG
    LEFT JOIN COMANDA C ON C.CODCOMANDA = I1.CODCOMANDA
    LEFT JOIN INTRARI I ON I.CodIntr = I1.CodIntr
    LEFT JOIN NARTOBJ NAO ON nao.codobiect = i1.codobiect
    LEFT JOIN NART NA ON na.codarticol = nao.codarticol
    LEFT JOIN NCLASEA NCA ON nca.codclasea = na.clasa
    LEFT JOIN NUM1 UM ON um.codum1 = i1.umsec
    LEFT JOIN NUM UM1 ON um1.codum = na.um1
    LEFT JOIN NUM UM2 ON um2.codum = na.um2
    LEFT JOIN NPART NP ON np.codpart = i.partener
    LEFT JOIN NAGENDA SSOC ON ssoc.codpart = i.partener AND ssoc.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(ssoc.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LOCSOC ON locsoc.codlocalit = ssoc.codlocalit
    LEFT JOIN NJUDET JUDSOC ON judsoc.codjudet = locsoc.codjudet
    LEFT JOIN NZONE ZONASOC ON zonasoc.codzona = locsoc.codzona
    LEFT JOIN NPARTCODFISC FISC ON fisc.codpart = i.partener AND fisc.principal = 1
    LEFT JOIN NCLASEP NCP ON ncp.codclasep = np.codclasa
    LEFT JOIN NGEST NG ON ng.codgest = i.codgestprod
    LEFT JOIN NGEST NGSERV ON ngserv.codgest = i1.gestact
    LEFT JOIN NSUBUNIT NS ON ns.codsubunit = i.codsubunit
    LEFT JOIN NSUBUNIT NSUB ON nsub.codsubunit = i.subunitatea
    LEFT JOIN NMONEDE MON ON mon.codmoneda = i.moneda
    LEFT JOIN NPART PROD ON prod.codpart = nao.codproducator
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = NA.CLASASTATIST
    LEFT JOIN (
      SELECT g.coddoc, g.tipdoc, MAX(o.termen) termen, MAX(o.majorari) majorari
      FROM obligpif o INNER JOIN general g ON g.codgeneral = o.codgeneral
      WHERE o.termen IS NOT NULL AND o.semnificatie = 100
      GROUP BY g.coddoc, g.tipdoc) T on t.coddoc = i1.codintr AND t.tipdoc = i1.tipdoc
    LEFT JOIN NARTOBJ1 NAO1 ON nao1.codobiect = i1.codobiect AND (i.an*12+i.luna) BETWEEN nao1.alstart AND nao1.alstop
    LEFT JOIN NART1 NA1 ON na1.codarticol = nao.codarticol AND (i.an*12+i.luna) BETWEEN na1.alstart AND na1.alstop
    LEFT JOIN NTVA1 NT1 ON nt1.codtva = na1.codtva AND (i.an*12+i.luna) BETWEEN nt1.alstart AND nt1.alstop
    LEFT JOIN NPART1 NP1 ON np1.codpart1 = i1.codpart1
    LEFT JOIN IOART1 IOA1 ON IOA1.CodIOArt1 = I1.CodIOArt1
    LEFT JOIN IOART IOA ON IOA.CodIOArt = IOA1.CodIOArt
    LEFT JOIN IOPART IOP ON IOP.CodIOPart = NP1.CodIOPart
    LEFT JOIN NCONT NC ON nc.codcont = COALESCE(ioa1.cont,i1.codcont,0)
    LEFT JOIN NPARCAUT PAUT ON PAUT.CODNPARCAUT = I1.CODAUTO
    LEFT JOIN OFERTA O ON O.CODOFERTA = I1.CODOFERTA
    LEFT JOIN CONTRACT CONTR ON contr.codcontract = i1.codcontract&apos;||
    gSuplJoins;

  sTMPUtils := &apos;BEGIN &apos;||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NARTOBJ1&apos;&apos;); &apos;||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NART1&apos;&apos;); &apos;   ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NTVA1&apos;&apos;); &apos;   ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NTAXE1&apos;&apos;); &apos;  ||CHR(10)||
               &apos;  PRC_AL_CHECK(&apos;&apos;NPERS1&apos;&apos;); &apos;  ||CHR(10)||
               &apos;END;&apos;;

  LIST_EXECUTE_IMMEDIATE(sTMPUtils , aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sTruncTmp , aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsertTmp, aLISTID, aLISTVER);
  LIST_EXECUTE_IMMEDIATE(sInsert   , aLISTID, aLISTVER);

  IF pFirmeExt IS NOT NULL THEN
    SELECT USERNAME INTO pUSERNAME FROM user_users;
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_START;
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sTMPUtils , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sTruncTmp , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sInsertTmp, aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_ADDSQL(sInsert   , aLISTID, aLISTVER);
    WINMADMIN.PKG_USERFIRME.LST_EXTERNE_GETDATE(pUSERNAME, pFirmeExt, tmpName);
  END IF;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END PKG_LIST_BASE_INTREXT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INTRMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A0318E5E5A0FB3FB6031FC49C622360F6AA41E6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INTRMF is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;nartobj obj, nart art, nartobj imb&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    TipOperatie,
    Partener,   
    Doc,        
    Articol,    
    NrInventar, 
    Cant,       
    Pret,       
    Valoare,    
    TVA,        
    An,          
    Luna,       
    Cont &apos;||
    gUserFields||&apos;)&apos;;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
  sSelect := &apos;
  SELECT
    CASE
      WHEN F.CODOPERATIE = 1 THEN &apos;&apos;Intrare in firma&apos;&apos;
      WHEN F.CODOPERATIE = 2 THEN &apos;&apos;Transfer intre gestiuni&apos;&apos;
      WHEN F.CODOPERATIE = 3 AND I.TIPDOC = 1 AND I.TIPFACTURA = 2 THEN &apos;&apos;Leasing&apos;&apos;
      WHEN F.CODOPERATIE = 3 AND I.TIPDOC = 1 AND nvl(I.TIPFACTURA,0) = 0 THEN &apos;&apos;Factura intrare&apos;&apos;
      WHEN F.CODOPERATIE = 3 AND I.TIPDOC = 5 THEN &apos;&apos;Factura intrare din import&apos;&apos;
      WHEN F.CODOPERATIE = 4 THEN &apos;&apos;Casare&apos;&apos;
      WHEN F.CODOPERATIE = 5 THEN &apos;&apos;Vanzare&apos;&apos;
      WHEN F.CODOPERATIE = 6 THEN &apos;&apos;Reevaluare - valoare MF&apos;&apos;
      WHEN F.CODOPERATIE = 7 THEN &apos;&apos;Reevaluare - amortizare prec&apos;&apos;
      WHEN F.CODOPERATIE = 8 THEN &apos;&apos;Marire de stoc&apos;&apos;
      WHEN F.CODOPERATIE = 9 THEN &apos;&apos;Modificare gestiune&apos;&apos;
      WHEN F.CODOPERATIE = 10 THEN &apos;&apos;Modificare centru de cost&apos;&apos;
      WHEN F.CODOPERATIE = 11 THEN &apos;&apos;Modificare tip contabil&apos;&apos;
    END TIPOPERATIE,
    P.DEN_PART Partener,   
    I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    I1.Cant,       
    I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) PRET,       
    I1.Cant * I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) Valoare,    
    I1.TVA * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)),        
    I.An,          
    I.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM FISAMF F
    INNER JOIN TRANSF       T    ON T.TIPDOC       = F.TIPDOC
    INNER JOIN TRANSF1      T1   ON T1.CODTRANSF   = T.CODTRANSF AND F.CODDOC1 = T1.CODTRANSF1
    INNER JOIN IMBMIFIXLINK L    ON L.CODTRANSF1   = T1.CODTRANSF1
    INNER JOIN INTRARI1     I1   ON I1.CODINTR1    = L.CODINTR1
    INNER JOIN INTRARI      I    ON I.CODINTR      = I1.CODINTR
    INNER JOIN NPART        P    ON I.PARTENER     = P.CODPART
    INNER JOIN NARTOBJ      OBJ  ON T1.CODOBIECT   = OBJ.CODOBIECT
    INNER JOIN NART         ART  ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX        MF   ON MF.CODMIFIX    = I1.CODMIFIX
    INNER JOIN NIRSTOC      NS   ON T1.CODTRANSF1  = NS.CODTRANSF1
    INNER JOIN IOART1       IOA1 ON NS.CODIOART    = IOA1.CODIOART AND (I.AN * 12 + I.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT        C    ON C.CODCONT      = IOA1.CONT
    INNER JOIN NARTOBJ      IMB  ON I1.CODOBIECT   = IMB.CODOBIECT
    &apos;||gSuplJoins||&apos;
  WHERE 1=1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos;
  UNION ALL
  SELECT
    &apos;&apos;Punere in functiune&apos;&apos; TIPOPERATIE,
    &apos;&apos; &apos;&apos; Partener,   
    T.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    M.NrInventar, 
    T1.Cant,       
    T1.PU,       
    T1.Cant * T1.PU Valoare,    
    T1.TVA,        
    T.An,          
    T.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM FISAMF F
    INNER JOIN TRANSF  T    ON T.TIPDOC       = F.TIPDOC
    INNER JOIN TRANSF1 T1   ON T1.CODTRANSF   = T.CODTRANSF AND F.CODDOC1 = T1.CODTRANSF1
    INNER JOIN NARTOBJ OBJ  ON T1.CODOBIECT   = OBJ.CODOBIECT
    INNER JOIN NIRSTOC NS   ON T1.CODTRANSF1  = NS.CODTRANSF1
    INNER JOIN NART    ART  ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN IOART1  IOA1 ON NS.CODIOART    = IOA1.CODIOART
    INNER JOIN NCONT   C    ON C.CODCONT      = IOA1.CONT
    INNER JOIN MIFIX   M    ON M.CODMIFIX     = F.CODMIFIX
    INNER JOIN MIFIX1  M1   ON M1.CODMIFIX    = F.CODMIFIX
    LEFT JOIN NARTOBJ  IMB  ON IMB.CODOBIECT  = OBJ.CODOBIECT - OBJ.CODOBIECT
    &apos;||gSuplJoins||&apos;
  WHERE F.codoperatie = 12 
        and (M1.ANSTART * 12 + M1.LUNASTART) = (SELECT MAX(ANSTART*12+LUNASTART) FROM MIFIX1 WHERE CODMIFIX = M.CODMIFIX)
        AND (M1.ANSTART * 12 + M1.LUNASTART) BETWEEN IOA1.ALStart and IOA1.ALStop &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);      
  else
  sSelect := &apos;
  WITH NSS AS
  (
   SELECT DISTINCT NS1.CODNIRSTOCORIG CODNIRSTOC, MF1.CODMIFIX, mf1.cant
   FROM MIFIX1 MF1
        INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = MF1.CODNIRSTOC
   WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
  )
  SELECT
    &apos;&apos;Intrare in firma&apos;&apos; TIPOPERATIE,
    P.DEN_PART Partener,   
    I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,        
    OBJ.DENUMIRE Articol,    
    MF.NrInventar, 
    nss.Cant,       
    I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) PRET,       
    nss.Cant * I1.PU * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) Valoare,    
    case when coalesce(i1.cant,0) = 0 then 0 else nss.cant/i1.cant*I1.TVA * DECODE(NVL(I.MONEDA,0),0,1,NVL(I.CURS,1)) end,
    I.An,          
    I.Luna,       
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos;
  FROM NSS
    INNER JOIN NIRSTOC NS ON NSS.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN INTRARI1     I1   ON I1.CODINTR1    = NS.CODINTR1
    INNER JOIN INTRARI      I    ON I.CODINTR      = I1.CODINTR
    INNER JOIN NPART        P    ON I.PARTENER     = P.CODPART
    INNER JOIN NARTOBJ      OBJ  ON NS.CODOBIECT   = OBJ.CODOBIECT
    INNER JOIN NART         ART  ON ART.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN MIFIX        MF   ON MF.CODMIFIX    = NSS.CODMIFIX
    INNER JOIN IOART1       IOA1 ON NS.CODIOART    = IOA1.CODIOART AND (I.AN * 12 + I.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
    INNER JOIN NCONT        C    ON C.CODCONT      = IOA1.CONT
    LEFT JOIN NARTOBJ       IMB  ON OBJ.CODOBIECT - OBJ.CODOBIECT = IMB.CODOBIECT
    &apos;||gSuplJoins||&apos;
  WHERE 1=1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;);  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  sSelect := &apos;
  WITH NSS AS
  (
   SELECT DISTINCT NS.CODNIRSTOC CODNIRSTOC, MF1.CODMIFIX, mf1.cant 
   FROM MIFIX1 MF1 
        INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX 
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC 
   WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
  )
  SELECT 
    case when t.tipdoc = 12 then &apos;&apos;TRANSFER DIN MARFA&apos;&apos; 
         when t.tipdoc = 13 then &apos;&apos;MODIFICARE DE PRET&apos;&apos; 
    end TIPOPERATIE,
    &apos;&apos; &apos;&apos; Partener,
    T.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,         
    OBJ.DENUMIRE Articol,     
    MF.NrInventar,  
    nss.Cant,        
    case when t.tipdoc = 13 then T1.PU - NSP.PRET else t1.pu end PRET,        
    nss.Cant * T1.PU Valoare,     
    case when coalesce(T1.cant,0) = 0 then 0 else nss.cant/T1.cant*T1.TVA  end, 
    T.An,           
    T.Luna,        
    C.SIMBOL Cont&apos;||
    gUserAlias||&apos; 
  FROM NSS 
    INNER JOIN NIRSTOC NS ON NSS.CODNIRSTOC = NS.CODNIRSTOC 
    INNER JOIN TRANSF1     T1   ON T1.CODTRANSF1    = NS.CODTRANSF1 
    INNER JOIN TRANSF      T    ON T.CODTRANSF      = T1.CODTRANSF 
    INNER JOIN NARTOBJ      OBJ  ON NS.CODOBIECT   = OBJ.CODOBIECT 
    INNER JOIN NART         ART  ON ART.CODARTICOL = OBJ.CODARTICOL 
    INNER JOIN MIFIX        MF   ON MF.CODMIFIX    = NSS.CODMIFIX 
    INNER JOIN IOART1       IOA1 ON NS.CODIOART    = IOA1.CODIOART AND (T.AN * 12 + T.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop 
    INNER JOIN NCONT        C    ON C.CODCONT      = IOA1.CONT
    INNER JOIN NIRSTOC NSP ON NS.CODNIRSTOCPARINTE = NSP.CODNIRSTOC
    INNER JOIN NIR      NP ON NP.CODNIR = NSP.CODNIR
    INNER JOIN NIR       N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST GP ON GP.CODGEST = NP.GEST
    INNER JOIN NGEST G ON G.CODGEST = N.GEST
    LEFT JOIN NARTOBJ       IMB  ON OBJ.CODOBIECT - OBJ.CODOBIECT = IMB.CODOBIECT 
    &apos;||gSuplJoins||&apos;
  WHERE GP.CODSUBUNIT = G.CODSUBUNIT &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;,&apos;SUBUNITATEA&apos;);  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
    IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1 THEN
      sSelect := &apos;
      WITH NSS AS
      (
       SELECT DISTINCT NS.CODNIRSTOC CODNIRSTOC, MF1.CODMIFIX, mf1.cant 
       FROM MIFIX1 MF1 
            INNER JOIN MIFIX MF ON MF.CODMIFIX = MF1.CODMIFIX 
            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC 
       WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
      )
      SELECT 
        case when t.tipdoc = 12 then &apos;&apos;TRANSFER DIN MARFA&apos;&apos; 
             when t.tipdoc = 13 then &apos;&apos;MODIFICARE DE PRET&apos;&apos; 
        end TIPOPERATIE,
        &apos;&apos; &apos;&apos; Partener,
        T.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) Doc,         
        OBJ.DENUMIRE Articol,     
        MF.NrInventar,  
        nss.Cant,        
        T1.PU PRET,        
        nss.Cant * T1.PU Valoare,     
        case when coalesce(T1.cant,0) = 0 then 0 else nss.cant/T1.cant*T1.TVA  end, 
        T.An,           
        T.Luna,        
        C.SIMBOL Cont&apos;||
        gUserAlias||&apos; 
      FROM NSS 
        INNER JOIN NIRSTOC NS ON NSS.CODNIRSTOC = NS.CODNIRSTOC 
        INNER JOIN TRANSF1     T1   ON T1.CODTRANSF1    = NS.CODTRANSF1 
        INNER JOIN TRANSF      T    ON T.CODTRANSF      = T1.CODTRANSF 
        INNER JOIN NARTOBJ      OBJ  ON NS.CODOBIECT   = OBJ.CODOBIECT 
        INNER JOIN NART         ART  ON ART.CODARTICOL = OBJ.CODARTICOL 
        INNER JOIN MIFIX        MF   ON MF.CODMIFIX    = NSS.CODMIFIX 
        INNER JOIN IOART1       IOA1 ON NS.CODIOART    = IOA1.CODIOART AND (T.AN * 12 + T.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop 
        INNER JOIN NCONT        C    ON C.CODCONT      = IOA1.CONT
        INNER JOIN NIRSTOC NSP ON NS.CODNIRSTOCPARINTE = NSP.CODNIRSTOC
        INNER JOIN NIR      NP ON NP.CODNIR = NSP.CODNIR
        INNER JOIN NIR       N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST GP ON GP.CODGEST = NP.GEST
        INNER JOIN NGEST G ON G.CODGEST = N.GEST
        LEFT JOIN NARTOBJ       IMB  ON OBJ.CODOBIECT - OBJ.CODOBIECT = IMB.CODOBIECT 
        &apos;||gSuplJoins||&apos;
      WHERE GP.CODSUBUNIT &lt;&gt; G.CODSUBUNIT &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;,&apos;SUBUNITATEA&apos;);  
      LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
    end if; 
  end if;

  COMMIT;
END;

end PKG_LIST_BASE_INTRMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDE1E0DBEA09916D87D39CDCC0BE11BCCEBB7FE7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INVENTAR IS

  p_CodInventar NUMBER(   20);
  vID           NUMBER(   20);
  gUserFields VARCHAR2( 5000);
  gUserAlias  VARCHAR2( 5000);
  gNullAlias  VARCHAR2( 5000);
  gSuplCols   VARCHAR2( 5000);
  gSuplJoins  VARCHAR2(20000);
  
  vDataS       DATE;
  vDataF       DATE;
 
PROCEDURE SetParams(aCodInventar IN NUMBER, pID IN NUMBER,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      ) IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  p_CodInventar := aCodInventar;
  vID := pID;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  sInsert1 CLOB;
BEGIN
  IF vID = 92 THEN
    gSuplCols := &apos;NARTOBJ OBJ, NART A, INVENTAR1 IV1, IOART1 IO1, NCONT CONT, NCLASEA CLS, NIRSER NSE, NSERII SER, NPART PROD, INVENTREZ IVZ, INVENTSTOC IVS&apos;;
  ELSE
    gSuplCols := &apos;NARTOBJ OBJ, NART A, INVENTAR1 I1, NUM1 NUM1, NPART PROD, NUM UM1, NUM UM2, NSERII SER, NCLASEA CLS, NLOCATII LOC&apos;;
  END IF;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vID = 92 THEN
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
       Pret, Art, Serie, UM, ExpiraLa, StocS, StocF, Dif, ValS, ValF, CodExt, Clasa, CodInt, Loc, ValDif, Dim, Mar, Cont, UM1,
       StocSUM1, StocFUM1, CantNUM1, UM2, StocSUM2, StocFUM2, CantNUM2, StocFL, StocFL1, StocFL2, NrInv, SerieInv &apos;||gUserFields||&apos; )
     WITH MFIX AS (
       select mfx1.codnirstoc, substr(vc2_nt_to_vc3200_dist(CAST(COLLECT(to_char(mfx.nrinventar) ORDER BY mfx.codmifix) AS vc2_nt)),1,2500) nrinv,
       substr(vc2_nt_to_vc3200_dist(CAST(COLLECT(to_char(mfx.serieinv) ORDER BY mfx.codmifix) AS vc2_nt)),1,2500) serieinv
       FROM tmp_inventstoc INV1
            INNER JOIN TMP_INVENTAR INV  ON INV.CODINVENTAR = INV1.CODINVENTAR
            inner join nirstoc      ns   on inv1.codnirstoc = ns.codnirstoc
            inner join mifix1       mfx1 on mfx1.codnirstoc = ns.codnirstoc
            inner join mifix        mfx  on mfx.codmifix    = mfx1.codmifix
       where MFX1.ANSTART * 12 + MFX1.LUNASTART = extract(year from inv.datainventar) * 12 + extract(month from inv.datainventar)
       group by mfx1.codnirstoc
     )
    SELECT
      INV1.pret, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, nvl(Inv1.rest, 0), nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), nvl(INV1.rest, 0) * nvl(INV1.pret, 0),
      (nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0))*inv1.pret, I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when nvl(rez.Rezolvat, 0) &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when nvl(rez.Rezolvat, 0) &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, nvl(INV1.restum1, 0), nvl(Inv1.restum1, 0) + nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1, 0), I1.Den_UM2,
      nvl(INV1.restum2, 0), nvl(Inv1.restum2, 0) + nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2, 0), i1.faptic, i1.fapticUM1, i1.fapticUM2,
      mfix.nrinv, mfix.serieinv &apos;||gUserAlias||&apos;
    FROM tmp_inventstoc INV1
      inner join tmp_inventar1 i1   on inv1.codinventar1 = i1.codinventar1
      inner join tmp_inventar  i    on i.codinventar     = i1.codinventar
      inner join nirstoc       ns   on inv1.codnirstoc   = ns.codnirstoc
      inner join ioart1        io1  on io1.codioart      = ns.codioart AND (extract(year from i.datainventar)*12+extract(month from i.datainventar)) BETWEEN io1.ALStart and io1.ALStop
      inner join NARTOBJ       OBJ  ON ns.codobiect      = OBJ.codObiect
      INNER JOIN NART          A    ON OBJ.codarticol    = A.codarticol
      INNER JOIN INVENTAR1     IV1  on iv1.codinventar1  = INV1.COdinventar1
      INNER JOIN INVENTSTOC    IVS  ON INV1.CODINVENTSTOC = IVS.CODINVENTSTOC
      left join mfix                on mfix.codnirstoc   = inv1.codnirstoc
      left join NCLASEA        CLS  on A.CLASA           = CLS.codclasea
      left join ncont          cont on cont.codcont      = io1.cont
      left join nirser         nse  on inv1.codnirser    = nse.codnirser
      left join nserii         ser  on nse.codserie      = ser.codserie
      left join tmp_inventrez  rez  on rez.codnirstoc    = inv1.codnirstoc and nvl(rez.codnirser,0) = nvl(inv1.codnirser,0) and rez.codinventar1 = i1.codinventar1
      LEFT JOIN INVENTREZ      IVZ  ON IVZ.CODREZOLVARE  = REZ.CODREZOLVARE
      left join npart          prod on prod.codpart      = obj.codproducator&apos;||
      gSuplJoins||&apos;
    WHERE i1.scriptic &lt;&gt; 0 
    UNION ALL
    SELECT
      INV1.pret, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, nvl(Inv1.rest, 0), nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), nvl(INV1.rest, 0) * nvl(INV1.pret, 0),
      (nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0))*inv1.pret, I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when nvl(rez.Rezolvat, 0) &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when nvl(rez.Rezolvat, 0) &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, nvl(INV1.restum1, 0), nvl(Inv1.restum1, 0) + nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1, 0), I1.Den_UM2,
      nvl(INV1.restum2, 0), nvl(Inv1.restum2, 0) + nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2, 0), i1.faptic, i1.fapticUM1, i1.fapticUM2,
      mfix.nrinv, mfix.serieinv &apos;||gUserAlias||&apos;
    FROM tmp_inventar1 i1
      left join tmp_inventstoc INV1 on inv1.codinventar1 = i1.codinventar1
      LEFT JOIN INVENTSTOC    IVS  ON INV1.CODINVENTSTOC = IVS.CODINVENTSTOC
      left join tmp_inventar   i    on i.codinventar     = i1.codinventar
      left join nirstoc        ns   on inv1.codnirstoc   = ns.codnirstoc
      left join ioart1         io1  on io1.codioart      = ns.codnirstoc - ns.codnirstoc
      left join NARTOBJ        OBJ  ON i1.codobiect      = OBJ.codObiect
      left join NART           A    ON OBJ.codarticol    = A.codarticol
      left join INVENTAR1      IV1  on iv1.codinventar1  = INV1.COdinventar1
      left join mfix                on mfix.codnirstoc   = inv1.codnirstoc
      left join NCLASEA        CLS  on A.CLASA           = CLS.codclasea
      left join ncont          cont on cont.codcont      = io1.cont
      left join nirser         nse  on inv1.codnirser    = nse.codnirser
      left join nserii         ser  on nse.codserie      = ser.codserie
      left join tmp_inventrez  rez  on rez.codnirstoc    = inv1.codnirstoc and nvl(rez.codnirser,0) = nvl(inv1.codnirser,0) and rez.codinventar1 = i1.codinventar1
      LEFT JOIN INVENTREZ      IVZ  ON IVZ.CODREZOLVARE  = REZ.CODREZOLVARE
      left join npart          prod on prod.codpart      = obj.codproducator&apos;||
      gSuplJoins||&apos;
    WHERE nvl(i1.scriptic,0) = 0 and inv1.codnirstoc &gt; 0
    UNION ALL
    SELECT
      rez.pretinreg, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, nvl(Inv1.rest, 0), nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), nvl(INV1.rest, 0) * nvl(rez.pretinreg, 0),
      (nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0))*rez.pretinreg, I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when nvl(rez.Rezolvat, 0) &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when nvl(rez.Rezolvat, 0) &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, nvl(INV1.restum1, 0), nvl(Inv1.restum1, 0) + nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1, 0), I1.Den_UM2,
      nvl(INV1.restum2, 0), nvl(Inv1.restum2, 0) + nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2, 0), i1.faptic, i1.fapticUM1, i1.fapticUM2,
      mfix.nrinv, serieinv &apos;||gUserAlias||&apos;
    FROM tmp_inventar1 i1
      inner join tmp_inventrez rez  on rez.codinventar1  = i1.codinventar1
      LEFT JOIN INVENTREZ      IVZ  ON IVZ.CODREZOLVARE  = REZ.CODREZOLVARE
      left join tmp_inventstoc INV1 on inv1.codinventar1 = i1.codinventar1
      LEFT JOIN INVENTSTOC    IVS  ON INV1.CODINVENTSTOC = IVS.CODINVENTSTOC
      left join tmp_inventar   i    on i.codinventar     = i1.codinventar
      left join nirstoc        ns   on rez.codnirstoc    = ns.codnirstoc
      left join ioart1         io1  on io1.codioart     = rez.codioart
      left join NARTOBJ        OBJ  ON i1.codobiect      = OBJ.codObiect
      left join NART           A    ON OBJ.codarticol    = A.codarticol
      left join INVENTAR1      IV1  on iv1.codinventar1  = INV1.COdinventar1
      left join mfix                on mfix.codnirstoc   = inv1.codnirstoc
      left join NCLASEA        CLS  on A.CLASA           = CLS.codclasea
      left join ncont          cont on cont.codcont      = io1.cont
      left join nirser         nse  on rez.codnirser     = nse.codnirser
      left join nserii         ser  on nse.codserie      = ser.codserie
      left join npart          prod on prod.codpart      = obj.codproducator&apos;||
      gSuplJoins||&apos;
    WHERE nvl(i1.scriptic,0) = 0 and rez.codnirstoc &gt; 0 and nvl(inv1.codinventar1,0) = 0
          AND (extract(year from i.datainventar)*12+extract(month from i.datainventar)) BETWEEN io1.ALStart and io1.ALStop 
    UNION ALL
    SELECT
      rez.pretinreg, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, nvl(Inv1.rest, 0), nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), nvl(INV1.rest, 0) * nvl(rez.pretinreg, 0),
      (nvl(Inv1.rest, 0) + nvl(rez.rezolvat,0))*rez.pretinreg, I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when nvl(rez.Rezolvat, 0) &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when nvl(rez.Rezolvat, 0) &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, nvl(INV1.restum1, 0), nvl(Inv1.restum1, 0) + nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1, 0), I1.Den_UM2,
      nvl(INV1.restum2, 0), nvl(Inv1.restum2, 0) + nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2, 0), i1.faptic, i1.fapticUM1, i1.fapticUM2,
      mfix.nrinv, mfix.serieinv &apos;||gUserAlias||&apos;
    FROM tmp_inventar1 i1
      inner join tmp_inventrez rez  on rez.codinventar1  = i1.codinventar1
      LEFT JOIN INVENTREZ      IVZ  ON IVZ.CODREZOLVARE  = REZ.CODREZOLVARE
      left join tmp_inventstoc INV1 on inv1.codinventar1 = i1.codinventar1 and inv1.codnirstoc = rez.codnirstoc and nvl(inv1.codnirser,0) = nvl(rez.codnirser,0)
      LEFT JOIN INVENTSTOC    IVS  ON INV1.CODINVENTSTOC = IVS.CODINVENTSTOC
      left join tmp_inventar   i    on i.codinventar     = i1.codinventar
      left join nirstoc        ns   on rez.codnirstoc    = ns.codnirstoc
      left join ioart1         io1  on io1.codioart      = ns.codnirstoc - ns.codnirstoc
      left join NARTOBJ        OBJ  ON i1.codobiect      = OBJ.codObiect
      left join NART           A    ON OBJ.codarticol    = A.codarticol
      left join INVENTAR1      IV1  on iv1.codinventar1  = INV1.COdinventar1
      left join mfix                on mfix.codnirstoc   = inv1.codnirstoc
      left join NCLASEA        CLS  on A.CLASA           = CLS.codclasea
      left join ncont          cont on cont.codcont      = io1.cont
      left join nirser         nse  on rez.codnirser     = nse.codnirser
      left join nserii         ser  on nse.codserie      = ser.codserie
      left join npart          prod on prod.codpart      = obj.codproducator&apos;||
      gSuplJoins||&apos;
    WHERE nvl(i1.scriptic,0) &gt; 0 and rez.codnirstoc &gt; 0 and nvl(inv1.codinventar1,0) = 0
    &apos;;

    sInsert1 :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
      Pret, Art, Serie, UM, ExpiraLa, StocS, StocF, Dif, ValS, ValF, CodExt, Clasa, CodInt, Loc, ValDif, Dim, Mar, Cont, UM1,
      StocSUM1, StocFUM1, CantNUM1, UM2, StocSUM2, StocFUM2, CantNUM2, StocFL, StocFL1, StocFL2 &apos;||gUserFields||&apos; )
    SELECT
      rez.pretinreg, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, 0, nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), 0,
      nvl(rez.rezolvat, 0)* nvl(rez.pretinreg,0), I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when I1.Diferente &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when I1.Diferente &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, 0, nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1,0), I1.Den_UM2, 0,
      nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2,0), i1.faptic, i1.fapticUM1, i1.fapticUM2 &apos;||gUserAlias||&apos;
    FROM tmp_inventrez rez
      inner join tmp_inventar1 i1   on i1.codinventar1  = rez.codinventar1
      inner join tmp_inventar  i    on i.codinventar    = i1.codinventar
      inner join NARTOBJ       OBJ  ON i1.codobiect     = OBJ.codObiect
      INNER JOIN NART          A    ON OBJ.codarticol   = A.codarticol
      INNER JOIN INVENTAR1     IV1  on iv1.codinventar1 = I1.COdinventar1
      inner join ioart1        io1  on io1.codioart     = rez.codioart AND (extract(year from i.datainventar)*12+extract(month from i.datainventar)) BETWEEN io1.ALStart and io1.ALStop
      LEFT JOIN INVENTREZ      IVZ  ON IVZ.CODREZOLVARE = REZ.CODREZOLVARE
      left join ncont          cont on cont.codcont     = io1.cont
      left join NCLASEA        CLS  on A.CLASA          = CLS.codclasea
      left join nirser         nse  on rez.codnirser     = nse.codnirser
      left join nserii         ser  on i1.codserie      = ser.codserie
      left join npart          prod on prod.codpart     = obj.codproducator
      LEFT JOIN INVENTSTOC    IVS  ON REZ.CODINVENTAR1 - REZ.CODINVENTAR1 = IVS.CODINVENTSTOC&apos;||
      gSuplJoins||&apos;
    WHERE nvl(rez.codnirstoc,0)=0 and nvl(i1.scriptic,0) &lt;&gt; 0
    UNION ALL
    SELECT
      rez.pretinreg, obj.Denumire, ser.Serie, I1.Den_UMSec, I1.Expirare, 0, nvl(rez.rezolvat,0), nvl(rez.rezolvat,0), 0,
      nvl(rez.rezolvat, 0)* nvl(rez.pretinreg,0), I1.CodExtern, CLS.den_clasea, obj.codintern, I1.Den_Locatie, nvl(rez.Rezolvat, 0) * nvl(rez.pretInreg, 0),
      case when I1.Diferente &lt; 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      case when I1.Diferente &gt;= 0 then ABS(nvl(rez.Rezolvat, 0)) else 0 end,
      cont.simbol, I1.Den_UM1, 0, nvl(rez.rezolvatum1,0), nvl(rez.rezolvatum1,0), I1.Den_UM2, 0,
      nvl(rez.rezolvatum2,0), nvl(rez.rezolvatum2,0), i1.faptic, i1.fapticUM1, i1.fapticUM2 &apos;||gUserAlias||&apos;
    FROM tmp_inventar1 i1
      left join tmp_inventrez rez  on i1.codinventar1  = rez.codinventar1
      left join tmp_inventar  i    on i.codinventar    = i1.codinventar
      LEFT JOIN INVENTREZ     IVZ  ON IVZ.CODREZOLVARE = REZ.CODREZOLVARE
      left join NARTOBJ       OBJ  ON i1.codobiect     = OBJ.codObiect
      left JOIN NART          A    ON OBJ.codarticol   = A.codarticol
      left JOIN INVENTAR1     IV1  on iv1.codinventar1 = I1.COdinventar1
      left join ioart1        io1  on io1.codioart     = rez.codioart
      left join ncont         cont on cont.codcont     = io1.cont
      left join NCLASEA       CLS  on A.CLASA          = CLS.codclasea
      left join nirser         nse  on rez.codnirser     = nse.codnirser
      left join nserii        ser  on i1.codserie      = ser.codserie
      left join npart         prod on prod.codpart     = obj.codproducator
      LEFT JOIN INVENTSTOC    IVS  ON REZ.CODINVENTAR1 - REZ.CODINVENTAR1 = IVS.CODINVENTSTOC&apos;||
      gSuplJoins||&apos;
    WHERE nvl(rez.codnirstoc,0)=0 and nvl(i1.scriptic,0) = 0
      AND (extract(year from i.datainventar)*12+extract(month from i.datainventar)) BETWEEN io1.ALStart and io1.ALStop &apos;;
  ELSE
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
       Art, Serie, UM, Expirala, StocS, StocF, Dif, CodExt, Clasa, CodInt, Loc,
       UM1, StocSUM1, StocFUM1, DifM1, UM2, StocSUM2, StocFUM2, DifUM2 &apos;||gUserFields||&apos; )
    SELECT
      obj.Denumire, ser.Serie, num1.Den_UM1, I1.Expirare, i1.scriptic, i1.faptic, nvl(i1.faptic,0) - i1.scriptic, OBJ.CodExtern, CLS.den_clasea, obj.codintern, LOC.Denumire,
      um1.Den_UM, i1.scripticUM1, i1.fapticUM1, nvl(i1.fapticUM1,0) - i1.scripticUM1, um2.Den_UM, i1.scripticUM2, i1.fapticUM2, nvl(i1.fapticUM2,0) - i1.scripticUM2 &apos;||gUserAlias||&apos;
    FROM inventar1 i1
      inner join NARTOBJ OBJ  ON i1.codobiect   = OBJ.codObiect
      INNER JOIN NART    A    ON OBJ.codarticol = A.codarticol
      inner join num1         on num1.codum1    = i1.um1
      left join npart    prod on prod.codpart   = obj.codproducator
      left join num      um1  on a.um1          = um1.codum
      left join num      um2  on a.um2          = um2.codum
      left join nserii   ser  on i1.codserie    = ser.codserie
      left join NCLASEA  CLS  on A.CLASA        = CLS.codclasea
      left join nlocatii loc  on i1.codlocatie  = loc.codlocatie&apos;||
      gSuplJoins||&apos;
    WHERE i1.codinventar = &apos;||p_CodInventar;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  IF vID = 92 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert1, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
end;

end pkg_list_base_inventar; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_INVENTAR_REST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43595A57A2647AFD327FD73CB97D74EE5E181944</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_INVENTAR_REST IS

vCodRestaurant number(20);

procedure SetRestaurant(aCodRestaurant in number) is
begin
  vCodRestaurant := aCodRestaurant;
end;  

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
S VARCHAR2(4000);
BEGIN
--  pkg_list_struct.GetSuplCols(aLISTID,alistver, gUserFields,gUserAlias,gNullAlias, gSuplCols);
  S := &apos;INSERT INTO &apos;          || TMPNAME || &apos;(DENUMIRE, DENUM, STOCINITIAL, INTRARI, IESIRI, PRET, DIMINUATE, TRANSFERATE, VANDUTE, CONSUMATE, DISCOUNT, NEPRELUATE) &apos; || CHR(13) ||
 &apos; SELECT &apos;                    ||  CHR(13) ||
 &apos;   O.DENUMIRE, &apos;             ||  CHR(13) ||
 &apos;   U1.DEN_UM1, &apos;             ||  CHR(13) ||
 &apos;   NVL(BS.STOCINITIAL, 0), &apos; ||  CHR(13) ||
 &apos;   NVL(BS.INTRARI, 0), &apos;     ||  CHR(13) ||
 &apos;   NVL(BS.IESIRI, 0), &apos;      ||  CHR(13) ||
 &apos;   BS.PRET,   &apos;              ||  CHR(13) ||
 &apos;   NVL(BS.DIMINUATE, 0), &apos;   ||  CHR(13) ||
 &apos;   NVL(BS.TRANSFERATE, 0), &apos; ||  CHR(13) ||
 &apos;   NVL(BS.VANDUTE, 0), &apos;     ||  CHR(13) ||
 &apos;   NVL(BS.CONSUMATE, 0), &apos;   ||  CHR(13) ||
 &apos;   NVL(BS.DISCOUNT, 0), &apos;    ||  CHR(13) ||
 &apos;   NVL(BS.NEPRELUATE, 0) &apos;   ||  CHR(13) ||
 &apos; FROM &apos;                      ||  CHR(13) ||
 &apos;   TMP_BALANTA_STOC BS, &apos;    ||  CHR(13) ||
 &apos;   NARTOBJ O, &apos;              ||  CHR(13) ||
 &apos;   NART A,&apos;                  ||  CHR(13) ||
 &apos;   NUM1 U1 &apos;                 ||  CHR(13) ||
 &apos;WHERE &apos;                      ||  CHR(13) ||
 &apos;   O.CODOBIECT = BS.CODOBIECT &apos; ||  CHR(13) ||
 &apos;   AND A.CODARTICOL = O.CODARTICOL &apos; ||  CHR(13)||
 &apos;   AND U1.CODUM = A.UM &apos; ||  CHR(13) ||
 &apos;   AND NOT EXISTS (SELECT RA.COD FROM restartinactive RA WHERE RA.CODOBIECT = BS.CODOBIECT AND RA.CODRESTAURANT = &apos;||vCodRestaurant||&apos;) &apos; ||  CHR(13) ||
 &apos;   AND U1.SECUNDARA = 0&apos;;   
  
 LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 COMMIT; 
  
END;

end PKG_LIST_BASE_INVENTAR_REST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF8758DE922F1DCBB425A49B16447B44D1FA1B0F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_ioart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;IOART IO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
   &apos;INSERT INTO &apos;||tmpName||&apos;(
      DENUMIRE,REPREZ,DIFERENTE,CHELTUIELI,VENITURI,PLUSINVENTAR, MINUSINVENTAR,CHELTTVACOLECTAT,PROVIZION,CHELTPROVIZION,CONTROTUNJIRI,DIVERSE,
      ACCIZELATRANSFER,DESCARCAREG,CONTABGEST,BAZA,DIFPRET,ARETVANEEX,TVANEEX,MG,DELA,PANALA&apos;||gUserFields||&apos;)
    WITH IO1 AS (
      SELECT
        CODIOART,
        CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT,PROVIZION,CHELTPROVIZION, CONTROTUNJIRI, DIVERSE,
        ACCIZELATRANSFER, DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG,
        ANSTART * 12 + LUNASTART AnLunaStart, ANSTART, LUNASTART,
        NVL(Lead(ANSTART *12 +LUNASTART) OVER (PARTITION BY CODIOART ORDER BY ANSTART, LUNASTART) - 1,PKG_LIST_SELECTLUNAAN.LunaStop) AnLunaStop
      FROM IOART1
      WHERE (ANSTART *12 +LUNASTART) &lt;= PKG_LIST_SELECTLUNAAN.LunaStop AND 
            (ANSTART *12 +LUNASTART) &gt;= PKG_LIST_SELECTLUNAAN.LunaStart
      ORDER BY CODIOART)
    SELECT
      IO.DEN_IOART,
      NVL(NCCONT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCDIF.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCCHELT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCVENIT.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCPLINV.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCMIINV.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCTVAC.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCPROV.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCPROVK.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCROT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCDIV.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(decode(io1.accizelatransfer,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;), NVL(decode(io1.descarcareg,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;),
      NVL(decode(io1.contabgest,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;), NVL(decode(io1.baza,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;),
      NVL(decode(io1.difpret,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;), NVL(decode(io1.aretvaneex,0,&apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;),&apos;&apos;--&apos;&apos;), NVL(IO1.TVANEEX,&apos;&apos;--&apos;&apos;),
      decode (NVL(io1.mg,0), 1,&apos;&apos;FIFO&apos;&apos;, 2,&apos;&apos;LIFO&apos;&apos;, 3,&apos;&apos;PMP&apos;&apos;, 4,&apos;&apos;IDS&apos;&apos;, 5,&apos;&apos;VAL&apos;&apos;, &apos;&apos;nedef.&apos;&apos;),
      to_char(IO1.AnStart,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(IO1.LunaStart,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(IO1.LunaStart),
      DECODE (MOD(IO1.AnLunaStop,12),0,
              to_char(Trunc(IO1.AnLunaStop/12-1),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.12.&apos;&apos;||pkg_list_base_utils.decode_luna(12),
              to_char(Trunc(IO1.AnLunaStop/12),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(MOD(IO1.AnLunaStop,12),&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(MOD(IO1.AnLunaStop,12)))
      &apos;||gUserAlias||&apos;
    FROM IO1
      INNER JOIN IOART IO ON IO.CODIOART = IO1.CODIOART
      LEFT JOIN NCONT NCCONT ON NCCONT.CODCONT   = IO1.CONT
      LEFT JOIN NCONT NCDIF ON NCDIF.CODCONT     = IO1.DIFERENTE
      LEFT JOIN NCONT NCCHELT ON NCCHELT.CODCONT = IO1.CHELTUIELI
      LEFT JOIN NCONT NCVENIT ON NCVENIT.CODCONT = IO1.VENITURI
      LEFT JOIN NCONT NCPLINV ON NCPLINV.CODCONT = IO1.PLUSINVENTAR
      LEFT JOIN NCONT NCMIINV ON NCMIINV.CODCONT = IO1.MINUSINVENTAR
      LEFT JOIN NCONT NCTVAC  ON NCTVAC.CODCONT  = IO1.CHELTTVACOLECTAT
      LEFT JOIN NCONT NCPROV  ON NCPROV.CODCONT  = IO1.PROVIZION
      LEFT JOIN NCONT NCPROVK ON NCPROVK.CODCONT  = IO1.CHELTPROVIZION
      LEFT JOIN NCONT NCROT ON NCROT.CODCONT     = IO1.CONTROTUNJIRI
      LEFT JOIN NCONT NCDIV ON NCDIV.CODCONT     = IO1.DIVERSE &apos;||
      gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_IOART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A0212A06841F578E6D94449013FF665CF1D5D54</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iobank IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;IOBANK IO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sInsert:=
   &apos;INSERT INTO &apos;||tmpName||&apos;(DENUMIRE, CONT, CONTDOBANDA, CONTCOMISION, CONTCHELTUIELI, CONTVENITURI, DELA, PANALA&apos;||gUserFields||&apos;)
    WITH IO1 AS (
      SELECT
        CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV,
        ANSTART * 12 + LUNASTART AnLunaStart, ANSTART, LUNASTART,
        NVL(Lead(ANSTART *12 +LUNASTART) OVER (PARTITION BY CODIOBANK ORDER BY ANSTART, LUNASTART) - 1,PKG_LIST_SELECTLUNAAN.LunaStop) AnLunaStop
      FROM IOBANK1
      WHERE (ANSTART *12 +LUNASTART) &lt;= PKG_LIST_SELECTLUNAAN.LunaStop
      ORDER BY CODIOBANK
    )
    SELECT
      IO.DEN_IOBANK, NVL(NC.SIMBOL,&apos;&apos;-&apos;&apos;), NVL(NCDob.SIMBOL,&apos;&apos;-&apos;&apos;), NVL(NCCom.SIMBOL,&apos;&apos;-&apos;&apos;), NVL(NCChe.SIMBOL,&apos;&apos;-&apos;&apos;), NVL(NCVen.SIMBOL,&apos;&apos;-&apos;&apos;),
      to_char(IO1.AnStart,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(IO1.LunaStart,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(IO1.LunaStart),
      DECODE (MOD(IO1.AnLunaStop,12),0,
              to_char(Trunc(IO1.AnLunaStop/12-1),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.12.&apos;&apos;||pkg_list_base_utils.decode_luna(12),
              to_char(Trunc(IO1.AnLunaStop/12),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(MOD(IO1.AnLunaStop,12),&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(MOD(IO1.AnLunaStop,12)))
      &apos;||gUserAlias||&apos;
    FROM IO1
      INNER JOIN IOBANK IO ON IO.CODIOBANK = IO1.CODIOBANK
		  LEFT JOIN NCONT NC ON NC.CODCONT = IO1.CONT
      LEFT JOIN NCONT NCDob ON NCDob.CODCONT = IO1.DOBANDA
      LEFT JOIN NCONT NCCom ON NCCom.CODCONT = IO1.COMISION
      LEFT JOIN NCONT NCChe ON NCChe.CODCONT = IO1.CHELTUIELICV
      LEFT JOIN NCONT NCVen ON NCVen.CODCONT = IO1.VENITURICV&apos;||
    gSuplJoins||&apos;
		WHERE ((IO1.AnLunaStart &lt;= PKG_LIST_SELECTLUNAAN.LunaStop) AND (IO1.AnLunaStop  &gt;= PKG_LIST_SELECTLUNAAN.LunaStart))&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_IOBANK;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>206B3A8BBBAC8578107175D500D77104A508C21E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iopart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;IOPART IO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sInsert:=
   &apos;INSERT INTO &apos;||tmpName||&apos;(
      DENUMIRE,CONTFURNIZOR,CONTCLIENT,CONTFURNAVANS,CONTCLIENTAVANS,CONTFURNAVIZ, CONTCLIENTAVIZ,CONTFURNMF,CONTCREDITD,
      CONTDEBITD,CONTLITIGII,CONTFURNAVS,CONTFURNAVIC,CONTFURNAVIN,CONTTERTI,TVANEEXF,TVANEEXC,TIP,DELA,PANALA&apos;||gUserFields||&apos;)
    WITH IO1 AS (
      SELECT
        CODIOPART,
        CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD,
        CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, TVANEEXF, TVANEEXC, TIP,
        ANSTART * 12 + LUNASTART AnLunaStart, ANSTART, LUNASTART,
        NVL(Lead(ANSTART *12 +LUNASTART) OVER (PARTITION BY CODIOPART ORDER BY ANSTART, LUNASTART) - 1,PKG_LIST_SELECTLUNAAN.LunaStop) AnLunaStop
      FROM IOPART1
      WHERE (ANSTART *12 +LUNASTART) &lt;= PKG_LIST_SELECTLUNAAN.LunaStop AND 
            (ANSTART *12 +LUNASTART) &gt;= PKG_LIST_SELECTLUNAAN.LunaStart 
      ORDER BY CODIOPART)
    SELECT
      IO.DEN_IOPART, NVL(NCFURN.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCCL.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCFAV.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCCLAV.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCFAVIZ.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCCLAVIZ.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCFMF.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCCRD.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCDEBD.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCLIT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCFAVS.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCFAVC.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCFAVIN.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCTERTI.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(IO1.TVANEEXF,&apos;&apos;--&apos;&apos;), NVL(IO1.TVANEEXC,&apos;&apos;--&apos;&apos;),
      DECODE (NVL(IO1.TIP,0), 0, &apos;&apos;--&apos;&apos;, 1, &apos;&apos;Clasic&apos;&apos;, 2, &apos;&apos;Leasing&apos;&apos;, &apos;&apos;nedef.&apos;&apos;),
      to_char(IO1.AnStart,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(IO1.LunaStart,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(IO1.LunaStart),
      DECODE (MOD(IO1.AnLunaStop,12),0,
              to_char(Trunc(IO1.AnLunaStop/12-1),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.12.&apos;&apos;||pkg_list_base_utils.decode_luna(12),
              to_char(Trunc(IO1.AnLunaStop/12),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(MOD(IO1.AnLunaStop,12),&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(MOD(IO1.AnLunaStop,12)))
      &apos;||gUserAlias||&apos;
    FROM IO1
      INNER JOIN IOPART IO      ON IO.CODIOPART     = IO1.CODIOPART
      LEFT  JOIN NCONT NCFURN   ON NCFURN.CODCONT   = IO1.CONTFURNIZOR
      LEFT  JOIN NCONT NCCL     ON NCCL.CODCONT     = IO1.CONTCLIENT
      LEFT  JOIN NCONT NCFAV    ON NCFAV.CODCONT    = IO1.CONTFURNAVANS
      LEFT  JOIN NCONT NCCLAV   ON NCCLAV.CODCONT   = IO1.CONTCLIENTAVANS
      LEFT  JOIN NCONT NCFAVIZ  ON NCFAVIZ.CODCONT  = IO1.CONTFURNAVIZ
      LEFT  JOIN NCONT NCCLAVIZ ON NCCLAVIZ.CODCONT = IO1.CONTCLIENTAVIZ
      LEFT  JOIN NCONT NCFMF    ON NCFMF.CODCONT    = IO1.Contfurnmf
      LEFT  JOIN NCONT NCCRD    ON NCCRD.CODCONT    = IO1.CONTCREDITD
      LEFT  JOIN NCONT NCDEBD   ON NCDEBD.CODCONT   = IO1.CONTDEBITD
      LEFT  JOIN NCONT NCLIT    ON NCLIT.CODCONT    = IO1.CONTLITIGII
      LEFT  JOIN NCONT NCFAVS   ON NCFAVS.CODCONT   = IO1.CONTFURNAVS
      LEFT  JOIN NCONT NCFAVC   ON NCFAVC.CODCONT   = IO1.CONTFURNAVIC
      LEFT  JOIN NCONT NCFAVIN  ON NCFAVIN.CODCONT  = IO1.CONTFURNAVIN
      LEFT  JOIN NCONT NCTERTI  ON NCTERTI.CODCONT  = IO1.CONTTERTI&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_iopart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>190FFA57AD50DD4B50BB533B834502AC236F3783</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_iopers IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;IOPERS IO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sInsert:=
   &apos;INSERT INTO &apos;||tmpName||&apos;(
      DENUMIRE,CONTAVANSDECONT,CONTIMPUTATII,CONTGARANTII,CONTALTERETINERI,CONTAVANS,CONTLIKI,CONTNERIDICATE,CONTBOALA,
      CONTPARTSAL,CONTNATURA,CONTECHIPAMENT,CONTIMPOZIT,DELA,PANALA&apos;||gUserFields||&apos;)
    WITH IO1 AS (
      SELECT
        CODIOPERS,
        CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA,
        CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT,
        ANSTART * 12 + LUNASTART AnLunaStart, ANSTART, LUNASTART,
        NVL(Lead(ANSTART *12 +LUNASTART) OVER (PARTITION BY CODIOPERS ORDER BY ANSTART, LUNASTART) - 1,PKG_LIST_SELECTLUNAAN.LunaStop) AnLunaStop
      FROM IOPERS1
      WHERE (ANSTART *12 +LUNASTART) &lt;= PKG_LIST_SELECTLUNAAN.LunaStop
      ORDER BY CODIOPERS)
    SELECT
      IO.DEN_IOPERS, NVL(NCDEC.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCIMPUT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCGAR.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCRET.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCAV.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCLIK.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCNERID.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCBO.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCPSAL.SIMBOL,&apos;&apos;--&apos;&apos;),
      NVL(NCNAT.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCEKIP.SIMBOL,&apos;&apos;--&apos;&apos;), NVL(NCIMP.SIMBOL,&apos;&apos;--&apos;&apos;),
      to_char(IO1.AnStart,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(IO1.LunaStart,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(IO1.LunaStart),
      DECODE (MOD(IO1.AnLunaStop,12),0,
              to_char(Trunc(IO1.AnLunaStop/12-1),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.12.&apos;&apos;||pkg_list_base_utils.decode_luna(12),
              to_char(Trunc(IO1.AnLunaStop/12),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(MOD(IO1.AnLunaStop,12),&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(MOD(IO1.AnLunaStop,12)))
      &apos;||gUserAlias||&apos;
    FROM IO1
      INNER JOIN IOPERS IO     ON IO.CODIOPERS    = IO1.CODIOPERS
      LEFT  JOIN NCONT NCDEC   ON NCDEC.CODCONT   = IO1.CONTAVANSDECONT
      LEFT  JOIN NCONT NCIMPUT ON NCIMPUT.CODCONT = IO1.CONTIMPUTATII
      LEFT  JOIN NCONT NCGAR   ON NCGAR.CODCONT   = IO1.CONTGARANTII
      LEFT  JOIN NCONT NCRET   ON NCRET.CODCONT   = IO1.CONTALTERETINERI
      LEFT  JOIN NCONT NCAV    ON NCAV.CODCONT    = IO1.CONTAVANS
      LEFT  JOIN NCONT NCLIK   ON NCLIK.CODCONT   = IO1.CONTLIKI
      LEFT  JOIN NCONT NCNERID ON NCNERID.CODCONT = IO1.CONTNERIDICATE
      LEFT  JOIN NCONT NCBO    ON NCBO.CODCONT    = IO1.CONTBOALA
      LEFT  JOIN NCONT NCPSAL  ON NCPSAL.CODCONT  = IO1.CONTPARTSAL
      LEFT  JOIN NCONT NCNAT   ON NCNAT.CODCONT   = IO1.CONTNATURA
      LEFT  JOIN NCONT NCEKIP  ON NCEKIP.CODCONT  = IO1.CONTECHIPAMENT
	    LEFT  JOIN NCONT NCIMP   ON NCIMP.CODCONT   = IO1.CONTIMPOZIT&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_IOPERS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_IPOASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5D5536A6BE15208D469FEF32100D9EF246FEC34</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_IPOASIG is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;nartobj obj, nart art&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NrInventar,  
    Articol,     
    Gestiune,    
    ValIn,       
    ValRest,     
    DataAchiz,   
    DataPunere,  
    Cont,        
    Ipoteca1,    
    Ipoteca2,    
    Ipoteca3,    
    NrAsig,      
    DataAsig,    
    ScadentaAsig,
    Clasa,       
    Asigurator,  
    ValAsig&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;

  select 
    mfix.NrInventar,  
    obj.denumire Articol,     
    g.den_gest Gestiune,    
    ns.pret ValIn,
    NS.Pret -
    case 
     when MFIX1.TIPREEVAL = 1 THEN 0 
     else 
        case 
          when nvl(MFIX1.DURATAF,0)&lt;&gt;0 and  MFIX.ANINTRARE *12 + MFIX.LUNAINTRARE &lt;= PKG_GLOBALS.AnLunaLucru and MFIX1.STARE = 1 then MFIX1.AMO + (NS.PRET - MFIX1.AMO)/MFIX1.DURATAF
          else MFIX1.AMO
        end 
    end ValRest,
    NS.DataAchiz,   
    ev.datastart DataPunere,  
    C.Simbol Cont,        
    p1.den_part Ipoteca1,    
    p2.den_part Ipoteca2,    
    p3.den_part Ipoteca3,    
    nvl(asg.nrdoc,&apos;&apos;...nedefinit...&apos;&apos;) NrAsig,      
    asg.datastart DataAsig,    
    asg.termen ScadentaAsig,
    cls.den_clasemf Clasa,       
    pasg.den_part Asigurator,  
    asg1.valasig ValAsig &apos;||gUserAlias||&apos;

  from mifix mfix

       left join mifix1     mfix1 on mfix.codmifix    = mfix1.codmifix
       left join nirstoc    ns    on mfix1.codnirstoc = ns.codnirstoc
       left join nartobj    obj   on obj.codobiect    = ns.codobiect
       left join nart       art   on obj.codarticol   = art.codarticol
       left join nir              on nir.codnir       = ns.codnir
       left join ngest      g     on g.codgest        = nir.gest
       LEFT JOIN IOART1     IOA1  ON NS.CODIOART      = IOA1.CODIOART
       LEFT JOIN NCONT      C     ON C.CODCONT        = IOA1.CONT
       left join evidentamf ev    on ev.codmifix      = mfix.codmifix
       left join npart      p1    on p1.codpart       = ev.codpart1
       left join npart      p2    on p2.codpart       = ev.codpart2
       left join npart      p3    on p3.codpart       = ev.codpart3
       left join asigurari1 asg1  on asg1.codmifix    = mfix.codmifix
       left join asigurari  asg   on asg.codasigurare = asg1.codasigurare
       left join nclasemf   cls   on cls.codclasemf   = asg.codclasemf
       left join npart      pasg  on pasg.codpart     = asg.codpart
  where (mfix1.anstart*12 + mfix1.lunastart) = (select max(mfix2.anstart*12+mfix2.lunastart) from mifix1 mfix2 where mfix2.codmifix = mfix.codmifix)  
    and (mfix1.anstart*12 + mfix1.lunastart) BETWEEN IOA1.ALStart and IOA1.ALStop &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;  

end PKG_LIST_BASE_IPOASIG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ISTORICPRETIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04CB0B54AB44CC276455D578F5FA1BC7BF985809</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ISTORICPRETIES IS

  vCodObiect  NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);

PROCEDURE SETPARAMS( pCodObiect IN NUMBER) IS
BEGIN
  vCodObiect := pCodObiect;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  sSelect     VARCHAR2(20000);
  sUserJoin   VARCHAR2(1000);
  pNrPretIntr NUMBER;
  sArticol    VARCHAR2(100);
BEGIN
--  gSuplCols := &apos;&apos;;
--  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias, gSuplCols);
 --umplere sUserJoin cu tablele care se folosesc in coloane suplimentare si nu sunt in join
--  IF InStr(gUserAlias, &apos;&apos;) &gt; 0 THEN
--    sUserJoin := sUserJoin||&apos;
--    LEFT JOIN ... ON ...&apos;;
--  END IF;

  pNrPretIntr  := pkg_categconst.GetValConstanta(&apos;NrPretIntr&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  IF Nvl(pNrPretIntr,0) = 0
  THEN pNrPretIntr := 10;
  END IF;

  sArticol := PKG_NOM_ARTICOL.SET_CODOBIECT_ANALIZAT(vCodObiect);
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(PREFIXDOC, NRDOC, DATADOC, CLIENT, PU_DOC, CANT, DEN_UM1, PACHIZ_RON, DEN_MONEDA, CURS, PACHIZ_VAL, MONTRANSF, CURSTRANSF, PUTRANSF, DATANIR, DEN_SUBUNIT, DEN_GEST&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT PREFIXDOC, NRDOC, DATADOC, CLIENT, PU_DOC, CANT, DEN_UM1, PACHIZ_RON, DEN_MONEDA, CURS, PACHIZ_VAL, MONTRANSF, CURSTRANSF, PUTRANSF, DATANIR, DEN_SUBUNIT, DEN_GEST&apos;||gUserFields||&apos;
  FROM V_URMARIRE_PRETURI_VANZARE
  WHERE ROWNUM &lt;= :1&apos;;

  pkg_globals.CheckDebugMode(sInsert||sSelect, aListID, aListVer);
  EXECUTE IMMEDIATE sInsert||sSelect USING pNrPretIntr;

  pkg_list_Struct.GOLESTE_PARAM;
  pkg_list_Struct.ADAUGA_PARAM(&apos;ARTICOL&apos;, sArticol);
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;NARTOBJEXT&apos;, &apos;CODOBIECT&apos;, vCodObiect);
  COMMIT;
END;

end PKG_LIST_BASE_ISTORICPRETIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ISTORICPRETINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31412BC2BC64F3FCAE22BFD6637553635132364D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ISTORICPRETINTR IS

  vCodObiect  NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);

  vDataS       DATE;
  vDataF       DATE;

PROCEDURE SETPARAMS( pCodObiect IN NUMBER)IS
BEGIN
  vCodObiect := pCodObiect;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  sSelect1    VARCHAR2(20000);
  sSelect2    VARCHAR2(20000);
  sUserJoin   VARCHAR2(1000);
  pNrPretIntr NUMBER;
  sArticol    VARCHAR2(100);
BEGIN
--  gSuplCols := &apos;&apos;;
--  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias, gSuplCols);
 --umplere sUserJoin cu tablele care se folosesc in coloane suplimentare si nu sunt in join
--  IF InStr(gUserAlias, &apos;&apos;) &gt; 0 THEN
--    sUserJoin := sUserJoin||&apos;
--    LEFT JOIN ... ON ...&apos;;
--  END IF;

  pNrPretIntr  := pkg_categconst.GetValConstanta(&apos;NrPretIntr&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  IF Nvl(pNrPretIntr,0) = 0
  THEN pNrPretIntr := 10;
  END IF;

  sArticol := PKG_NOM_ARTICOL.SET_CODOBIECT_ANALIZAT(vCodObiect);
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(PREFIXDOC, NRDOC, DATADOC, FURNIZOR, CANT, DEN_UM1, PACHIZ_RON, DEN_MONEDA, CURS, PACHIZ_VAL, PVAL_DOC, PACHIZ_RON_FS, DATANIR, DEN_SUBUNIT, DEN_GEST&apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT PREFIXDOC, NRDOC, DATADOC, FURNIZOR, CANT, DEN_UM1, PACHIZ_RON, DEN_MONEDA, CURS, PACHIZ_VAL, PVAL_DOC, PACHIZ_RON_FS, DATANIR, DEN_SUBUNIT, DEN_GEST&apos;||gUserFields||&apos;
  FROM V_URMARIRE_PRETURI
  WHERE ROWNUM &lt;= :1&apos;;

  sSelect2 := &apos;
  SELECT PREFIXDOC, NRDOC, DATADOC, FURNIZOR, CANT, DEN_UM1, PACHIZ_RON, DEN_MONEDA, CURS, PACHIZ_VAL, PVAL_DOC, PACHIZ_RON_FS, DATANIR, DEN_SUBUNIT, DEN_GEST&apos;||gUserFields||&apos;
  FROM V_URMARIRE_PRETURI_TRANSFVAL
  WHERE ROWNUM &lt;= :1&apos;;

  pkg_globals.CheckDebugMode(sInsert||sSelect1, aListID, aListVer);
  EXECUTE IMMEDIATE sInsert||sSelect1 USING pNrPretIntr;
  EXECUTE IMMEDIATE &apos;SELECT &apos;||pNrPretIntr||&apos; - COUNT(*) FROM &apos;||TMPNAME INTO pNrPretIntr;
  IF pNrPretIntr &gt; 0 THEN
    pkg_globals.CheckDebugMode(sInsert||sSelect2, aListID, aListVer);
    EXECUTE IMMEDIATE sInsert||sSelect2 USING pNrPretIntr;
  END IF;

  pkg_list_Struct.GOLESTE_PARAM;
  pkg_list_Struct.ADAUGA_PARAM(&apos;ARTICOL&apos;, sArticol);
  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;NARTOBJEXT&apos;, &apos;CODOBIECT&apos;, vCodObiect);
  COMMIT;
END;

end PKG_LIST_BASE_ISTORICPRETINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_JOBCORELREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D1FB97CAB92DF9E09BF4E7547C23F0C22E65E70</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_jobcorelrez is

  vCodJob JOBLISTE.CODJOB%TYPE DEFAULT NULL;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
 
  vDataS       DATE;
  vDataF       DATE;
  
PROCEDURE SETPARAMS(pCodJob IN NUMBER DEFAULT NULL,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0 )IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vCodJob := pCodJob;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert  VARCHAR2(13000);
BEGIN
  gSuplCols := &apos;JOBCORELREZ JCZ, JOBCOREL JC, JOBLISTE1 JL1, JOBLISTE1 JL2&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    IDENTIFICATOR,
    VALOARE1,
    VALOARE2,
    TABLA1,
    LOOKUPFIELD1,
    VALDESCRIP1,
    LISTA1,
    TABLA2,
    LOOKUPFIELD2,
    VALDESCRIP2,
    LISTA2
  &apos;||gUserFields||&apos;)
  SELECT
    JCZ.IDENTIFICATOR,
    JCZ.VALOARE1,
    JCZ.VALOARE2,
    JC.TABLA1,
    JC.LOOKUPFIELD1||&apos;&apos; + &apos;&apos;||JC.LOOKUPFIELD11,
    JC.VALDESCRIP1,
    L1.NAME LISTA1,
    JC.TABLA2,
    JC.LOOKUPFIELD2||&apos;&apos; + &apos;&apos;||JC.LOOKUPFIELD21,
    JC.VALDESCRIP2,
    L2.NAME LISTA2 &apos;||gUserAlias||&apos;
  FROM JOBCORELREZ JCZ
    INNER JOIN JOBCOREL JC ON JCZ.CODCOREL = JC.CODCOREL
    INNER JOIN JOBLISTE1 JL1 ON JL1.CODJOB1 = JC.CODJOB1_1
    INNER JOIN JOBLISTE1 JL2 ON JL2.CODJOB1 = JC.CODJOB1_2
    INNER JOIN WINMADMIN.LISTS L1 ON JL1.LISTAID = L1.LISTID AND JL1.LISTAVER = L1.LISTVER
    INNER JOIN WINMADMIN.LISTS L2 ON JL2.LISTAID = L2.LISTID AND JL2.LISTAVER = L2.LISTVER&apos;||
    gSuplJoins||&apos;
  WHERE JC.CODJOB = &apos;||nvl(vCodJob, &apos;0&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_jobcorelrez;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_JURNCUMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2938380F2E6DBBEA7D355624054610A45520FA68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_JURNCUMP IS

  vAnLunaIni      INTEGER;
  vAnLunaFin      INTEGER;
  vAnLista        INTEGER;
  vLunaLista      INTEGER;
  vSubunit        NUMBER(20);
  vTip            NUMBER(1);
  bExclNEA        BOOLEAN;
  vISIVB          BOOLEAN;
  vIMFEStoc       BOOLEAN;
  sServAICB       VARCHAR2(10000);
  sCImbMifix      VARCHAR2(10000);
  sFiltruCodArt   VARCHAR2(10000);

  gUserFields     VARCHAR2(2500);
  gUserAlias      VARCHAR2(2500);
  gNullAlias      VARCHAR2(2500);
  gSuplCols       VARCHAR2(2500);
  gSuplJoins      VARCHAR2(5000);

PROCEDURE SetPerioada (pAn NUMBER, pLuna NUMBER, pTip INTEGER, pSubunit NUMBER DEFAULT NULL, pExclNoEconomicActiv BOOLEAN DEFAULT FALSE) IS
BEGIN
  vAnLista   := pAn;
  vLunaLista := pLuna;
  vAnLunaFin := pAn*12+pLuna;
  vTip       := pTip;
  IF    pTip = 3/*anual      */ THEN vAnLunaIni := pAn*12+ 1;
  ELSIF pTip = 2/*semestrial */ THEN vAnLunaIni := pAn*12+ CASE WHEN pLuna &gt; 6 THEN 7 ELSE 1 END;
  ELSIF pTip = 1/*trimestrial*/ THEN vAnLunaIni := pAn*12+ CASE WHEN pLuna &gt; 9 THEN 10 WHEN pLuna &gt; 6 THEN 7 WHEN pLuna &gt; 3 THEN 4 ELSE 1 END;
  ELSIF pTip = 0/*lunar      */ THEN vAnLunaIni := pAn*12+ pLuna;
  END IF;
  vSubunit   := Coalesce(pSubunit,PKG_GLOBALS.GETSUBUNITATE);
  bExclNEA   := pExclNoEconomicActiv;
END;

FUNCTION  GetAnLunaIni RETURN NUMBER IS
BEGIN
  RETURN vAnLunaIni;
END;

FUNCTION  GetAnLunaFin RETURN NUMBER IS
BEGIN
  RETURN vAnLunaFin;
END;

FUNCTION  GetAnLista   RETURN NUMBER IS
BEGIN
  RETURN vAnLista;
END;

FUNCTION  GetLunaLista RETURN NUMBER IS
BEGIN
  RETURN vLunaLista;
END;

PROCEDURE pregateste_TMP_LST_TVAINCAS (aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsAux1 CLOB;
  sInsAux2 CLOB;
  sDebug   CLOB;
  sAL_OL   CLOB;
BEGIN
  sDebug := &apos;BEGIN&apos;||Chr(10)||
            &apos;  pkg_list_base_jurncump.SetPerioada(&apos;||vAnLista||&apos;,&apos;||vLunaLista||&apos;,&apos;||vTip||&apos;,&apos;||vSubunit||&apos;);&apos;||Chr(10)||
            &apos;END;&apos;;
  PKG_GLOBALS.CheckDebugMode(sDebug, aLISTID, aLISTVER);

  SELECT Least (ancurent*12+lunacurenta,vAnLunaIni) INTO sAL_OL FROM firmaluni;

  sInsAux1 :=
  &apos;INSERT INTO TMP_LST_TVAINCAS(
    coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, valstinsa, datastop, coef, coefbaza, coeftva, tipstingere, prefixstingere, nrstingere,
    coefdoc,
    coefdocbaza,
    coefdoctva,
    orddoc, countdoc, coefplata, coefplatabaza, coefplatatva, restdoc)
  WITH
  I AS (
    SELECT CODINTR, TIPDOC, VALDOC, TVADOC, SPLITTVA
    -- exista cazuri mai dubioase pe facturile din initializate cu cecuri in curs din initializare cand valdoc si valoare obligatie nu e real, e rest de incasat
    FROM (
      SELECT I.CODINTR, I.TIPDOC, Sum(Coalesce(i1.pu*i1.cant, 0)+Coalesce(i1.tva,0)) ValDoc, Sum(Coalesce(i1.tva,0)) TVADoc, I.SPLITTVA
      FROM INTRARI I INNER JOIN INTRARI1 i1 ON I1.CODINTR = I.CODINTR
      WHERE Coalesce(I.INITIALIZARI,0) = 1 AND I.TVAINCASARE = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
        AND EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODINTR AND G.TIPDOC = I.TIPDOC)
      GROUP BY I.CODINTR, I.TIPDOC, I.SPLITTVA
    )
    WHERE TVADOC &lt;&gt; 0 AND VALDOC &lt;&gt; 0
    UNION
    SELECT I.CODINTR, I.TIPDOC, I.VALDOC, I.TVADOC, I.SPLITTVA
    FROM INTRARI I
    WHERE I.AN*12+I.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
      AND I.AN*12+I.LUNA &gt;= (SELECT ancurent*12+lunacurenta FROM firmaluni)
      AND Coalesce(I.INITIALIZARI,0) = 0
      AND I.TVAINCASARE = 1 AND I.TVADOC &lt;&gt; 0 AND I.VALDOC &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      AND EXISTS (SELECT 1 FROM INTRARI1 I1 WHERE I1.CODINTR = I.CODINTR AND Coalesce(I1.TVANEDED,0) &lt;&gt; 1)
    UNION
    SELECT DISTINCT I.CODINTR, I.TIPDOC, I.VALDOC, I.TVADOC, I.SPLITTVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN GENERAL  G ON G.CODGENERAL  = O.CODGENERAL
      INNER JOIN INTRARI  I ON I.CODINTR     = G.CODDOC AND I.TIPDOC = G.TIPDOC
    WHERE OL.AN*12+OL.LUNA+1 = &apos;||sAL_OL||&apos;
      AND OL.REST &lt;&gt; 0
      AND I.AN*12+I.LUNA &lt; (SELECT ancurent*12+lunacurenta FROM firmaluni)
      AND Coalesce(I.INITIALIZARI,0) = 0
      AND I.TVAINCASARE = 1 AND I.TVADOC &lt;&gt; 0 AND I.VALDOC &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      AND NOT O.SEMNIFICATIE IN (110)
      AND EXISTS (SELECT 1 FROM INTRARI1 I1 WHERE I1.CODINTR = I.CODINTR AND Coalesce(I1.TVANEDED,0) &lt;&gt; 1)
    UNION
    SELECT DISTINCT I.CODINTR, I.TIPDOC, I.VALDOC, I.TVADOC, I.SPLITTVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O_CEC   ON O_CEC.CODOBLIGPIF  = OL.CODOBLIGPIF AND O_CEC.SEMNIFICATIE IN (500,600)
      INNER JOIN GENERAL  G_CEC   ON G_CEC.CODGENERAL   = O_CEC.CODGENERAL
      INNER JOIN GENERAL  G_STING ON G_STING.TIPDOC     = 31 AND G_STING.CODDOC = G_CEC.CODDOC AND G_STING.SEMNIFICATIE &lt;&gt;  G_CEC.SEMNIFICATIE
      INNER JOIN OBLIGPIF O_STING ON O_STING.CODGENERAL = G_STING.CODGENERAL
      INNER JOIN STINGERE S       ON S.CODSTINGATORPIF  = O_STING.CODOBLIGPIF
      INNER JOIN OBLIGPIF O       ON O.CODOBLIGPIF      = S.CODSTINSPIF
      INNER JOIN GENERAL  G       ON G.CODGENERAL       = O.CODGENERAL
      INNER JOIN INTRARI  I       ON I.CODINTR          = G.CODDOC AND I.TIPDOC = G.TIPDOC
    WHERE OL.AN*12+OL.LUNA+1 = &apos;||sAL_OL||&apos;
      AND OL.REST &lt;&gt; 0
      AND Coalesce(I.INITIALIZARI,0) = 0
      AND I.AN*12+I.LUNA &lt; (SELECT ancurent*12+lunacurenta FROM firmaluni)
      AND I.TVAINCASARE = 1 AND I.TVADOC &lt;&gt; 0 AND I.VALDOC &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      AND EXISTS (SELECT 1 FROM INTRARI1 I1 WHERE I1.CODINTR = I.CODINTR AND Coalesce(I1.TVANEDED,0) &lt;&gt; 1)
  ),
  S AS (
    SELECT
      I.CODINTR, I.TIPDOC, I.VALDOC, I.TVADOC, I.SPLITTVA,
      SUM(
        ( --STINS TREZOR
          SELECT Coalesce(SUM(S.VALOARE),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
            INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND Coalesce(T1.ANULAT, 0) = 0 AND T1.AN * 12 + T1.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND S.VALOARE &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END +
        ( --STINS CEC INCASAT
          SELECT Coalesce(SUM(CASE WHEN Coalesce(T1.Initializari, 0) = 1 THEN I.VALDOC ELSE S.VALOARE END),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
            INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
            INNER JOIN GENERAL  G_CEC       ON G_CEC.TIPDOC            = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600)
            INNER JOIN OBLIGPIF O_CEC       ON O_CEC.CODGENERAL        = G_CEC.CODGENERAL
            INNER JOIN STINGERE S_CEC       ON S_CEC.CODSTINSPIF       = O_CEC.CODOBLIGPIF
            INNER JOIN OBLIGPIF O_CURENT    ON O_CURENT.CODOBLIGPIF    = S_CEC.CODSTINGATORPIF
            INNER JOIN GENERAL  G_CURENT    ON G_CURENT.CODGENERAL     = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
            INNER JOIN TREZOR1  T1_CURENT   ON T1_CURENT.CODTREZOR1    = G_CURENT.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND Coalesce(T1.ANULAT, 0) = 0
            AND T1.AN * 12 + T1.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND T1_CURENT.AN * 12 + T1_CURENT.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND S_CEC.VALOARE &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END +
        ( -- STINS COMPENSARI
          SELECT Coalesce(SUM(S.VALOARE),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
            INNER JOIN COMPENS  C           ON C.CODCOMPENS            = G_STINGATOR.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND C.AN * 12 + C.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND S.VALOARE &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END
      ) STINSDOC,
      SUM(
        ( --STINS TREZOR
          SELECT Coalesce(SUM(S.DINCARETVA),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
            INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND Coalesce(T1.ANULAT, 0) = 0 AND T1.AN * 12 + T1.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND Coalesce(S.DINCARETVA,0) &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END +
        ( --STINS CEC INCASAT
          SELECT Coalesce(SUM(CASE WHEN Coalesce(T1.Initializari, 0) = 1 AND COALESCE(S_CEC.DINCARETVA,0) &lt;&gt; 0 THEN I.TVADOC ELSE S.DINCARETVA END),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
            INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
            INNER JOIN GENERAL  G_CEC       ON G_CEC.TIPDOC            = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600)
            INNER JOIN OBLIGPIF O_CEC       ON O_CEC.CODGENERAL        = G_CEC.CODGENERAL
            INNER JOIN STINGERE S_CEC       ON S_CEC.CODSTINSPIF       = O_CEC.CODOBLIGPIF
            INNER JOIN OBLIGPIF O_CURENT    ON O_CURENT.CODOBLIGPIF    = S_CEC.CODSTINGATORPIF
            INNER JOIN GENERAL  G_CURENT    ON G_CURENT.CODGENERAL     = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
            INNER JOIN TREZOR1  T1_CURENT   ON T1_CURENT.CODTREZOR1    = G_CURENT.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND Coalesce(T1.ANULAT, 0) = 0
            AND T1.AN * 12 + T1.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND T1_CURENT.AN * 12 + T1_CURENT.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND Coalesce(S_CEC.DINCARETVA,0) &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END +
        ( -- STINS COMPENSARI
          SELECT Coalesce(SUM(S.DINCARETVA),0)
          FROM STINGERE S
            INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
            INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
            INNER JOIN COMPENS  C           ON C.CODCOMPENS            = G_STINGATOR.CODDOC
          WHERE S.CODSTINSPIF = O.CODOBLIGPIF AND C.AN * 12 + C.LUNA &lt; &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND Coalesce(S.DINCARETVA,0) &lt;&gt; 0
        ) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END
      ) STINSDINCARETVA
    FROM I
      INNER JOIN GENERAL  G ON G.CODDOC     = I.CODINTR AND G.TIPDOC = I.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    GROUP BY I.CODINTR, I.TIPDOC, I.VALDOC, I.TVADOC, I.SPLITTVA),
  TVAI AS (
    SELECT
      TMP.CODDOC, TMP.TIPDOC, TMP.NRDOC, TMP.PREFIXDOC, TMP.SERIADOC, TMP.DATADOC, TMP.DATASTINGERE, TMP.VALSTINSA, TMP.DATASTOP, TMP.COEF, TMP.COEFBAZA, TMP.COEFTVA, TMP.TIPSTINGERE, TMP.PREFIXSTINGERE, TMP.NRSTINGERE,
      Row_Number()      OVER (PARTITION BY TMP.CODDOC, TMP.TIPDOC ORDER BY TMP.DATASTINGERE) OrdDoc,
      COUNT(1)          OVER (PARTITION BY TMP.CODDOC, TMP.TIPDOC) CountDoc,
      SUM(TMP.Coef)     OVER (PARTITION BY TMP.CODDOC, TMP.TIPDOC ORDER BY TMP.DATASTINGERE ROWS UNBOUNDED PRECEDING) CoefPlata,
      SUM(TMP.CoefBaza) OVER (PARTITION BY TMP.CODDOC, TMP.TIPDOC ORDER BY TMP.DATASTINGERE ROWS UNBOUNDED PRECEDING) CoefPlataBaza,
      SUM(TMP.CoefTVA)  OVER (PARTITION BY TMP.CODDOC, TMP.TIPDOC ORDER BY TMP.DATASTINGERE ROWS UNBOUNDED PRECEDING) CoefPlataTva
    FROM TMP_TVAINCAS TMP
    WHERE (COEFTVA &lt;&gt; 0 OR SPLITTVA = 1) )
  SELECT
    S.CODINTR, S.TIPDOC, TVAI.NRDOC, TVAI.PREFIXDOC, TVAI.SERIADOC, TVAI.DATADOC, TVAI.DATASTINGERE, TVAI.VALSTINSA, TVAI.DATASTOP, TVAI.COEF, TVAI.COEFBAZA, TVAI.COEFTVA, TVAI.TIPSTINGERE, TVAI.PREFIXSTINGERE, TVAI.NRSTINGERE,
    1 - ((S.STINSDOC+S.STINSDINCARETVA)/S.VALDOC) COEFDOC,
    1 - CASE WHEN Coalesce(S.SPLITTVA,0) = 0 THEN ((S.STINSDOC+S.STINSDINCARETVA)/S.VALDOC) WHEN S.TVADOC = 0 THEN 1 ELSE (S.STINSDOC/(S.VALDOC-S.TVADOC)) END COEFDOCBAZA,
    1 - CASE WHEN Coalesce(S.SPLITTVA,0) = 0 THEN ((S.STINSDOC+S.STINSDINCARETVA)/S.VALDOC) WHEN S.TVADOC = 0 THEN 1 ELSE (S.STINSDINCARETVA/S.TVADOC)     END COEFDOCTVA,
    TVAI.ORDDOC, TVAI.COUNTDOC, Coalesce(TVAI.COEFPLATA,0) COEFPLATA, Coalesce(TVAI.COEFPLATABAZA,0) COEFPLATABAZA, Coalesce(TVAI.COEFPLATATVA,0) COEFPLATATVA, ABS(S.VALDOC-S.STINSDOC-S.STINSDINCARETVA) RESTDOC
  FROM S LEFT JOIN TVAI ON TVAI.CODDOC = S.CODINTR AND TVAI.TIPDOC = S.TIPDOC&apos;;

  sInsAux2 :=
  &apos;INSERT INTO TMP_LST_TVAINCAS(
    coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, valstinsa, datastop, coef, coefbaza, coeftva, tipstingere, prefixstingere, nrstingere,
    coefdoc,
    coefdocbaza,
    coefdoctva,
    orddoc, countdoc,
    coefplata,
    coefplatabaza,
    coefplatatva)
  SELECT
    coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, valstinsa, datastop, coef, coefbaza, coeftva, tipstingere, prefixstingere, nrstingere,
    1 CoefDoc,
    1 CoefDocBaza,
    1 CoefDocTva,
    Row_Number()  OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE, TIPSTINGERE, NRSTINGERE) OrdDoc, COUNT(1) OVER (PARTITION BY CODDOC, TIPDOC) CountDoc,
    SUM(Coef)     OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE, TIPSTINGERE, NRSTINGERE ROWS UNBOUNDED PRECEDING) CoefPlata,
    SUM(CoefBaza) OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE, TIPSTINGERE, NRSTINGERE ROWS UNBOUNDED PRECEDING) CoefPlataBaza,
    SUM(CoefTva)  OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE, TIPSTINGERE, NRSTINGERE ROWS UNBOUNDED PRECEDING) CoefPlataTva
  FROM TMP_TVAINCAS
  WHERE COEFTVA &lt;&gt; 0 OR SPLITTVA = 1&apos;;

  sDebug :=
    &apos;BEGIN&apos;||Chr(10)||
    &apos;  DELETE TMP_LST_TVAINCAS;&apos;||Chr(10)||
    &apos;  DELETE TMP_JURNAL1;&apos;||Chr(10)||
    &apos;  DELETE TMP_TVAINCAS;&apos;;
  IF vAnLista &gt; 2012 THEN
    sDebug := sDebug||Chr(10)||
    &apos;  PKG_INCHIDERI.MAKE_TMP_StingereTVADed(1);&apos;||Chr(10)||
    &apos;  DELETE TMP_TVAINCAS T&apos;||Chr(10)||
    &apos;  WHERE 0 = (SELECT Coalesce(Max( Abs(PKG_INCHIDERI.CalcTVADed(I.TipTVA, I1.TVANeded, I.ProRata, I1.TVA))),-1) FROM Intrari1 I1, Intrari I WHERE  I.CodIntr = T.CodDoc AND I.TipDoc = T.TipDoc AND I1.CodIntr = I.CodIntr);&apos;||Chr(10)||
    &apos;  &apos;|| sInsAux1 ||&apos;;&apos;||Chr(10)||
    &apos;  DELETE TMP_TVAINCAS     WHERE CODDOC IN (SELECT CODDOC FROM TMP_LST_TVAINCAS);&apos;||Chr(10)||
    &apos;  DELETE TMP_LST_TVAINCAS WHERE COEFPLATA = 0 AND RESTDOC &lt; 0.01;&apos;||Chr(10)||
    &apos;  &apos;|| sInsAux2 ||&apos;;&apos;;
  END IF;
  sDebug := sDebug||Chr(10)||
    &apos;END;&apos;;

  LIST_EXECUTE_IMMEDIATE(sDebug, aListID, aListVer);
END;

FUNCTION sXIntr(sPjTva VARCHAR2) RETURN VARCHAR2 IS
BEGIN
  RETURN &apos;
    SELECT
      I.CODINTR, Coalesce(I.TVAINCASARE,0) TVAINC, I1.TIPLINIE, I.TIPTVA,
      CASE
        WHEN                                                                                              I.TIPTVA = 9                                                                   THEN &apos;&apos;RS315&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0                                       THEN &apos;&apos;AICBS&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0                                       THEN &apos;&apos;AICBS&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0 AND T1.PROCENT = 0                    THEN &apos;&apos;AICBS&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0 AND T1.PROCENT = 0                    THEN &apos;&apos;AICBS&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0                                       THEN &apos;&apos;AICBN&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0                                       THEN &apos;&apos;AICBN&apos;&apos;&apos;||
    CASE
      WHEN sServAICB &lt;&gt; &apos;-1&apos; THEN &apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;)             AND Coalesce(I.TIPTRANZACTIE,1) = 2                                                                AND I1.CODOBIECT IN (&apos;||sServAICB||&apos;) THEN &apos;&apos;AICB&apos;&apos;&apos;
      ELSE &apos;&apos;
    END||
    CASE
      WHEN vISIVB THEN &apos;
        WHEN I1.TIPLINIE = &apos;&apos;S&apos;&apos;                AND Coalesce(I.TIPTRANZACTIE,1) = 2
         AND MAX(CASE WHEN I1.TIPLINIE = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY I.CodIntr) = 1                                                                                      THEN &apos;&apos;AICB&apos;&apos;&apos;
      ELSE &apos;&apos;
    END||&apos;
        WHEN                                                                            I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
        WHEN                                                                            I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;)             AND Coalesce(I.TIPTRANZACTIE,1) = 2                   AND I.TIPTVA = 8                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                               AND I.TIPDOC  = 5 AND I.TIPTVA = 2                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 3             AND I.TIPTVA = 2                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 3                                                          AND Coalesce(I1.IMPOZABIL,0) = 3      THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2                   AND I.TIPTVA = 2                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2                                                                AND Coalesce(I1.IMPOZABIL,0) = 3      THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                                     AND I.TIPDOC  = 5                                              AND Coalesce(I1.IMPOZABIL,0) = 3      THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 1                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 8                                                                   THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 2                                                                   THEN &apos;&apos;BS160&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 3                                                                   THEN &apos;&apos;BS160&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5                                              AND Coalesce(I1.IMPOZABIL,0) = 3      THEN &apos;&apos;BS160&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 2                                                                   THEN &apos;&apos;BS160&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;,&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5                                              AND Coalesce(I1.IMPOZABIL,0) = 3      THEN &apos;&apos;BS160&apos;&apos;&apos;||
    CASE
      WHEN vIMFEStoc AND sCImbMifix &lt;&gt; &apos;-1&apos;
      THEN &apos;
        WHEN I1.TIPLINIE = &apos;&apos;S&apos;&apos; AND A.CONTSERVICIU IN (&apos;||sCImbMifix||&apos;) THEN
          CASE
            WHEN                                    Coalesce(I.TIPTRANZACTIE,1) = 1 AND I.TIPDOC &lt;&gt; 5 AND I.TIPTVA = 3                                                                   THEN &apos;&apos;BS160&apos;&apos;
            WHEN                                                                        I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
            WHEN                                                                        I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
            WHEN                                    Coalesce(I.TIPTRANZACTIE,1) = 2                                                                                                      THEN &apos;&apos;AICB&apos;&apos;
            ELSE                                                                                                                                                                              &apos;&apos;NTVA&apos;&apos;
          END&apos;
      ELSE &apos;&apos;
    END||&apos;
        WHEN EXISTS(SELECT 1 FROM General G INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL WHERE G.CodDoc = i.CodIntr AND G.TipDoc = I.TipDoc AND G.SEMNIFICATIE IN (110,111) AND O.Icont IN (12,19))
         AND I1.TIPLINIE IN (&apos;&apos;V&apos;&apos;)             AND Coalesce(I.TIPTRANZACTIE,1) = 2                                                                                                      THEN &apos;&apos;BS150&apos;&apos;
        WHEN I1.TIPLINIE IN (&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;)       AND Coalesce(I.TIPTRANZACTIE,1) = 2                                                                                                      THEN &apos;&apos;AICB&apos;&apos;
        WHEN                                                                            I.TIPDOC  = 5                  AND Coalesce(D1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
        WHEN                                                                            I.TIPDOC &lt;&gt; 5                  AND Coalesce(I1.TVA, 0) = 0                                       THEN &apos;&apos;N0&apos;&apos;
        ELSE                                                                                                                                                                                  &apos;&apos;NTVA&apos;&apos;
      END CAZ,
      PKG_LIST_BASE_UTILS.MATCH_TVA(
        CASE
          WHEN I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;) AND (Coalesce(I1.CANT * I1.PU,0) = 0)               THEN T1.PROCENT
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)             AND Coalesce(I1.RESTFACT,0) = 0                     THEN &apos;||sPjTva||&apos;
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                                                                 THEN Coalesce(I1.TVA,0)/I1.RESTFACT*100
          WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) AND Coalesce(D1.VALOARETAXA,0) = 0     THEN &apos;||sPjTva||&apos;
          WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;)                                        THEN Coalesce(D1.TVA,0)/D1.VALOARETAXA*100
          WHEN I.TIPDOC = 5 AND Coalesce(D1.CANT * D1.PRETIMPORT,0) = 0                                     THEN T1.PROCENT
          WHEN I.TIPDOC = 5                                                                                 THEN Coalesce(D1.TVA,0)/(D1.CANT*D1.PRETIMPORT) *100
          ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT)
        END,
        &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
      ) xMATCH_TVA,
      ROUND(CASE
        WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) THEN Coalesce(D1.VALOARETAXA,0)
        WHEN I.TIPDOC = 5 AND I.TIPTRANZACTIE = 2 THEN Coalesce(D1.CANT * D1.PRETVALUTA,0) * Coalesce(NULLIf(I.Curs,0),1)
        WHEN I.TIPDOC = 5 THEN Coalesce(D1.CANT * D1.PRETIMPORT,0)
        WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN (I1.RESTFACT - CASE WHEN I.TIPDOC = 3 THEN Coalesce(I1.TVA,0) ELSE 0 END)* Coalesce(NULLIf(I.Curs,0),1)
        ELSE ((Coalesce(I1.PU,0) * I1.CANT) - CASE WHEN I.TIPDOC = 3 THEN Coalesce(I1.TVA,0) ELSE 0 END) * Coalesce(NULLIf(I.Curs,0),1)
      END,7) BAZA,
      ROUND(CASE WHEN I.TIPDOC = 5 THEN Coalesce(d1.TVA,0) ELSE Coalesce(I1.TVA,0) * Coalesce(NULLIf(I.Curs,0),1) END,7) TVA,
      CASE WHEN Coalesce(I.TIPTVA,0) = 4 AND COALESCE(D1.TVANEDED, I1.TVANEDED,0) IN (0,3) THEN Coalesce(I.PRORATA,0) ELSE 0 END PRORATA,
      CASE COALESCE(D1.TVANEDED, I1.TVANEDED,0) WHEN 3 THEN 1/2 WHEN 1 THEN 1 ELSE 0 END +
      CASE WHEN Coalesce(I.TIPTVA,0) &lt;&gt; 4 THEN 0 WHEN COALESCE(D1.TVANEDED, I1.TVANEDED,0) = 0 THEN 1-Coalesce(I.PRORATA,0)/100 WHEN COALESCE(D1.TVANEDED, I1.TVANEDED,0) = 3 THEN 1/2*(1-Coalesce(I.PRORATA,0)/100) ELSE 0 END COEFNEDED,
      CASE WHEN Coalesce(I.TIPTVA,0) &lt;&gt; 4 THEN 0 ELSE CASE COALESCE(D1.TVANEDED, I1.TVANEDED,0) WHEN 3 THEN 1/2 WHEN 1 THEN 1 ELSE 0 END * (1-Coalesce(I.PRORATA,0) / 100) END COEFNPRORATA,
      CASE WHEN Coalesce(I.TIPTVA,0) &lt;&gt; 4 THEN 0 ELSE CASE COALESCE(D1.TVANEDED, I1.TVANEDED,0) WHEN 3 THEN 1/2 WHEN 1 THEN 1 ELSE 0 END END COEFMPRORATA,
      COALESCE(D1.TVANEDED, I1.TVANEDED,0) TVANEDED, Coalesce(I.SPLITTVA, 0) SPLITTVA,
      CASE WHEN Coalesce(i.an*100+i.luna, 0) = To_Number(Coalesce(To_Char(Coalesce(i.datatva, i.datadoc), &apos;&apos;yyyymm&apos;&apos;),&apos;&apos;0&apos;&apos;)) THEN 0 ELSE 1 END DOC_REG
    FROM INTRARI I
      LEFT JOIN DVI       D    ON D.CODINTR     = I.CODINTR
      LEFT JOIN DVI1      D1   ON D1.CODDVI     = D.CODDVI
      LEFT JOIN INTRARI1  I1   ON I1.CODINTR    = I.CODINTR AND I1.CODINTR1 = CASE I.TIPDOC WHEN 5 THEN D1.CODINTR1 ELSE I1.CODINTR1 END
      LEFT JOIN NARTOBJ   O    ON O.CODOBIECT   = I1.CODOBIECT
      LEFT JOIN NART      A    ON A.CODARTICOL  = O.CODARTICOL
      LEFT JOIN NART1     A1   ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT JOIN NTVA1     T1   ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      LEFT JOIN INTRARI1  I1ST ON I1ST.CODINTR1 = I1.CODINTR1STORNO
      LEFT JOIN INTRARI   IST  ON IST.CODINTR   = I1ST.CODINTR
      LEFT JOIN CONTRACT0 C0 ON C0.CODDOC = I.CODINTR AND C0.TIPDOC = I.TIPDOC AND I.TIPFACTURA = 2 AND C0.TIPLINIE = 1
    WHERE I.TIPDOC IN (1,3,4,5,9) AND I.OPERAT = 1 AND I.ANULAT = 0
      AND EXISTS (SELECT 1 FROM GENERAL G WHERE G.CODDOC = I.CODINTR AND G.TIPDOC = I.TIPDOC)
      AND (
            (I.TIPTVA &lt;&gt; 3) OR
            (I.TIPTVA = 3 AND Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;))&apos;||
      CASE
        WHEN sServAICB &lt;&gt; &apos;-1&apos; THEN &apos; OR
            (I.TIPTVA = 3 AND Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;S&apos;&apos;) AND Coalesce(I.TIPTRANZACTIE,1) = 2 AND I1.CODOBIECT IN (&apos;||sServAICB||&apos;))&apos;
        ELSE &apos;&apos;
      END||&apos;
          )
      AND NOT Coalesce(I.TIPTRANZACTIE,1)  IN (4, 5) AND Coalesce(i1.impozabil, 0) &lt;&gt; 4
      AND NOT (Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I1.CONTDISCOUNT,0) = 0)
      AND NOT (Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I1.RESTFACT,0) = 0)
      AND NOT (Coalesce(D1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;A&apos;&apos;,&apos;&apos;C&apos;&apos;,&apos;&apos;X&apos;&apos;) AND Coalesce(D.TAXEINCLUSE,0) = 1)
      AND Coalesce(D.TIPIMPORT,0) = 0
      AND C0.CODCONTRACT IS NULL &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit)||
      sFiltruCodArt;
END;

FUNCTION sJCIntr RETURN VARCHAR2 IS
BEGIN
  RETURN &apos;
    SELECT
      CODINTR,
      MAX(TVAINC) TVAINC, MAX(TIPTVA) TIPTVA,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 3 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BMAX,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 3 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TMAX,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 2 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BMIN,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 2 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TMIN,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 1 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BMED,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 1 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TMED,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 4 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BREG,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 4 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TREG,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 5 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BREG2,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 5 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TREG2,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 6 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BREG3,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 6 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TREG3,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 7 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BREG4,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 7 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TREG4,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 8 THEN 0 WHEN TVAINC = 1 THEN Round(BAZA*COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN BAZA ELSE 0 END) BREG5,
      SUM(CASE WHEN xMATCH_TVA &lt;&gt; 8 THEN 0 WHEN TVAINC = 1 THEN Round(TVA* COEFNEDED,7) WHEN CAZ = &apos;&apos;NTVA&apos;&apos; THEN TVA  ELSE 0 END) TREG5,
      SUM(CASE WHEN CAZ = &apos;&apos;N0&apos;&apos; OR (CAZ = &apos;&apos;NTVA&apos;&apos; AND xMATCH_TVA = 0) THEN BAZA ELSE 0 END) T0,
      SUM(CASE WHEN CAZ = &apos;&apos;AICB&apos;&apos;  THEN BAZA ELSE 0 END) AICB_BAZA,  SUM(CASE WHEN CAZ = &apos;&apos;AICB&apos;&apos;  THEN TVA  ELSE 0 END) AICB_TVA,
      SUM(CASE WHEN CAZ = &apos;&apos;AICBS&apos;&apos; THEN BAZA ELSE 0 END) AICB_SCUT,  SUM(CASE WHEN CAZ = &apos;&apos;AICBN&apos;&apos; THEN BAZA ELSE 0 END) AICB_NEIMP,
      SUM(CASE WHEN CAZ = &apos;&apos;AICBS&apos;&apos; AND TIPLINIE = &apos;&apos;S&apos;&apos; THEN BAZA ELSE 0 END) AICS_SCUT, SUM(CASE WHEN CAZ = &apos;&apos;AICBN&apos;&apos; AND TIPLINIE = &apos;&apos;S&apos;&apos; THEN BAZA ELSE 0 END) AICS_NEIMP,
      SUM(CASE WHEN CAZ = &apos;&apos;RS315&apos;&apos; THEN BAZA ELSE 0 END) RS315_BAZA, SUM(CASE WHEN CAZ = &apos;&apos;RS315&apos;&apos; THEN TVA  ELSE 0 END) RS315_TVA,
      SUM(CASE WHEN CAZ = &apos;&apos;BS150&apos;&apos; THEN BAZA ELSE 0 END) BS150_BAZA, SUM(CASE WHEN CAZ = &apos;&apos;BS150&apos;&apos; THEN TVA  ELSE 0 END) BS150_TVA,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; THEN BAZA ELSE 0 END) BS160_BAZA, SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; THEN TVA  ELSE 0 END) BS160_TVA,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 3 THEN BAZA ELSE 0 END) BS160_BMAX,  SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 3 THEN TVA  ELSE 0 END) BS160_TMAX,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 2 THEN BAZA ELSE 0 END) BS160_BMIN,  SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 2 THEN TVA  ELSE 0 END) BS160_TMIN,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 1 THEN BAZA ELSE 0 END) BS160_BMED,  SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 1 THEN TVA  ELSE 0 END) BS160_TMED,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 4 THEN BAZA ELSE 0 END) BS160_BREG,  SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 4 THEN TVA  ELSE 0 END) BS160_TREG,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 5 THEN BAZA ELSE 0 END) BS160_BREG2, SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 5 THEN TVA  ELSE 0 END) BS160_TREG2,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 6 THEN BAZA ELSE 0 END) BS160_BREG3, SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 6 THEN TVA  ELSE 0 END) BS160_TREG3,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 7 THEN BAZA ELSE 0 END) BS160_BREG4, SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 7 THEN TVA  ELSE 0 END) BS160_TREG4,
      SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 8 THEN BAZA ELSE 0 END) BS160_BREG5, SUM(CASE WHEN CAZ = &apos;&apos;BS160&apos;&apos; AND xMATCH_TVA = 8 THEN TVA  ELSE 0 END) BS160_TREG5,
      MAX(PRORATA) PRORATA, SUM(TVA*COEFNPRORATA) TNPRORATA, SUM(TVA*COEFMPRORATA) TMPRORATA,
      SUM(CASE WHEN xMATCH_TVA = 3 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNMAX,  SUM(CASE WHEN xMATCH_TVA = 3 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXMAX,
      SUM(CASE WHEN xMATCH_TVA = 3 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNMAX,  SUM(CASE WHEN xMATCH_TVA = 3 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXMAX,
      SUM(CASE WHEN xMATCH_TVA = 2 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNMIN,  SUM(CASE WHEN xMATCH_TVA = 2 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXMIN,
      SUM(CASE WHEN xMATCH_TVA = 2 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNMIN,  SUM(CASE WHEN xMATCH_TVA = 2 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXMIN,
      SUM(CASE WHEN xMATCH_TVA = 1 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNMED,  SUM(CASE WHEN xMATCH_TVA = 1 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXMED,
      SUM(CASE WHEN xMATCH_TVA = 1 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNMED,  SUM(CASE WHEN xMATCH_TVA = 1 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXMED,
      SUM(CASE WHEN xMATCH_TVA = 4 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNREG,  SUM(CASE WHEN xMATCH_TVA = 4 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXREG,
      SUM(CASE WHEN xMATCH_TVA = 4 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNREG,  SUM(CASE WHEN xMATCH_TVA = 4 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXREG,
      SUM(CASE WHEN xMATCH_TVA = 5 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNREG2, SUM(CASE WHEN xMATCH_TVA = 5 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXREG2,
      SUM(CASE WHEN xMATCH_TVA = 5 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNREG2, SUM(CASE WHEN xMATCH_TVA = 5 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXREG2,
      SUM(CASE WHEN xMATCH_TVA = 6 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNREG3, SUM(CASE WHEN xMATCH_TVA = 6 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXREG3,
      SUM(CASE WHEN xMATCH_TVA = 6 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNREG3, SUM(CASE WHEN xMATCH_TVA = 6 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXREG3,
      SUM(CASE WHEN xMATCH_TVA = 7 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNREG4, SUM(CASE WHEN xMATCH_TVA = 7 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXREG4,
      SUM(CASE WHEN xMATCH_TVA = 7 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNREG4, SUM(CASE WHEN xMATCH_TVA = 7 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXREG4,
      SUM(CASE WHEN xMATCH_TVA = 8 THEN Round(BAZA*(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) BNREG5, SUM(CASE WHEN xMATCH_TVA = 8 THEN BAZA*(1-COEFNEDED) ELSE 0 END) BXREG5,
      SUM(CASE WHEN xMATCH_TVA = 8 THEN Round(TVA *(COEFNEDED - COEFNPRORATA),7) ELSE 0 END) TNREG5, SUM(CASE WHEN xMATCH_TVA = 8 THEN TVA *(1-COEFNEDED) ELSE 0 END) TXREG5,
      MAX(CASE WHEN TVA = 0 THEN 0 WHEN BAZA*(1-COEFNEDED) = 0 THEN 1 ELSE 1 END) AUX_X,
      SUM(CASE WHEN TVA = 0 THEN 0 ELSE BAZA*(1-COEFNEDED) END) BAZAX, SUM(TVA*(1-COEFNEDED)) TVAX, SUM(Round(TVA * (COEFNEDED - COEFNPRORATA) ,7)) TNEDED,
      CASE WHEN Max(SPLITTVA) = 0 THEN 1 WHEN Sum(BAZA)     = 0 THEN 0 ELSE Sum(CASE WHEN TVA = 0 THEN 0 ELSE BAZA     END)/Sum(BAZA    ) END COEF_B,
      CASE WHEN Max(SPLITTVA) = 0 THEN 1 WHEN Sum(BAZA+TVA) = 0 THEN 0 ELSE Sum(CASE WHEN TVA = 0 THEN 0 ELSE BAZA+TVA END)/Sum(BAZA+TVA) END COEF_D,
      MAX(TVANEDED) TVANEDED, MAX(DOC_REG) DOC_REG
    FROM X
    GROUP BY CODINTR&apos;;
END;

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert         CLOB;
  sSelect1        CLOB;
  sInsAux1        CLOB;
  sUpdate1        CLOB;
  sSelect2        CLOB;
  sSelect3        CLOB;
  sSelect4        CLOB;
  sSelect5        CLOB;
  sCondLuna       VARCHAR2(200);
  vCodTvaImplicit NUMBER;
  sPjTva          VARCHAR2(3);
  cModEditJurn    NUMBER;
  vTVA0FaraJurnal VARCHAR2(10000);
  vCountArt       NUMBER := 0;
BEGIN
  --PKG_GLOBALS.SETDEBUGMODE(TRUE);

  gSuplCols := &apos;INTRARI I, NPART P, NPARTCODFISC CFP, NPARTCODFISC CFD, NSUBUNIT SUB, NAGENDA SDOC, NAGENDA SSOC, NLOCALIT L, NTARI T, DOCCARNETE DC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  pkg_globals.SetSeparator(&apos;,&apos;);

  PRC_AL_CHECK(&apos;NSUBUNIT1&apos;);
  IF (aLISTID &gt; 0 OR tmpName &lt;&gt; &apos;TMP_JC_D300&apos;) THEN
    vSubunit := PKG_GLOBALS.GETSUBUNITATE;
    BEGIN
      SELECT Coalesce(ModEditareJurnal, 0)
      INTO cModEditJurn
      FROM NSUBUNIT1
      WHERE CodSubunit = vSubunit AND pkg_globals.AnLunaLucru BETWEEN ALSTART and ALSTOP;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN cModEditJurn := 0;
    END;
    cModEditJurn := Coalesce(cModEditJurn,0);
    IF cModEditJurn = 0 THEN
      cModEditJurn := pkg_categconst.GetValConstanta(&apos;ModEditareJurnal&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU);
      cModEditJurn := Coalesce(cModEditJurn,0);
    END IF;

    vTip := CASE WHEN cModEditJurn = 2 AND Mod(pkg_globals.GetLUNALUCRU,3) = 0 THEN 1 ELSE 0 END;
    SetPerioada(pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU,vTip,vSubunit);
  END IF;

  vTVA0FaraJurnal := Coalesce(pkg_categconst.GetValConstanta(&apos;TVA0FaraJurnal&apos;,     vAnLista,vLunaLista),&apos;-1&apos;);
  vISIVB          := Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos;,vAnLista,vLunaLista), &apos;0&apos;) = &apos;1&apos;;
  vCodTvaImplicit := Coalesce(pkg_categconst.GetValConstanta(&apos;TIPTVAImplicit&apos;,     vAnLista,vLunaLista), &apos;0&apos;);
  SELECT To_Char(Coalesce(Max(PROCENT),0)) INTO sPjTva FROM NTVA1 WHERE CODTVA = vCodTvaImplicit AND vAnLista*12+vLunaLista BETWEEN ALSTART AND ALSTOP;

  sPjTva          := Coalesce(pkg_categconst.GetValConstanta(&apos;TIPTVAImplicit&apos;,     vAnLista,vLunaLista), &apos;0&apos;);
  sServAICB       := Coalesce(pkg_categconst.GetValConstanta(&apos;ServAICB&apos;,           vAnLista,vLunaLista),&apos;-1&apos;);
  vIMFEStoc       := Coalesce(pkg_categconst.GetValConstanta(&apos;ImbMiFixEStoc&apos;,      vAnLista,vLunaLista), &apos;0&apos;) = &apos;1&apos;;
  sCImbMifix      := Coalesce(pkg_categconst.GetValConstanta(&apos;CImbMifix&apos;,          vAnLista,vLunaLista),&apos;-1&apos;);
  IF vTVA0FaraJurnal &lt;&gt; &apos;-1&apos; THEN
    PRC_AL_CHECK(&apos;NART1&apos;);

    DELETE FROM TMP_MANEVRA;
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO TMP_MANEVRA SELECT DISTINCT CodArticol FROM NART1 WHERE CodTva IN (&apos;||vTVA0FaraJurnal||&apos;) AND &apos;||To_Char(vAnLunaFin, &apos;FM00000&apos;)||&apos; BETWEEN ALSTART AND ALSTOP&apos;, aListID, aListVer);
    FOR vRec IN (SELECT CodUnic FROM TMP_MANEVRA) LOOP
      IF vCountArt = 0
      THEN sFiltruCodArt := To_Char(vrec.CodUnic);
      ELSE sFiltruCodArt := sFiltruCodArt||&apos;,&apos;||To_Char(vrec.CodUnic);
      END IF;
      vCountArt := vCountArt + 1;
    END LOOP;
    IF vCountArt &gt; 0 THEN
      sInsAux1 := sFiltruCodArt;
      sFiltruCodArt := &apos;
      AND NOT o.CodArticol IN (&apos;||sFiltruCodArt||&apos;)&apos;;
    ELSE
      sFiltruCodArt := &apos;&apos;;
    END IF;
  END IF;

  IF vAnLunaIni = vAnLunaFin
  THEN sCondLuna := &apos;= &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;);
  ELSE sCondLuna := &apos;BETWEEN &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CODDOC, NAV_CodDoc1, NAV_TIPDOC, ORDDOC,
    PREFIXDOC, TIPDOC, NRDOC, NRI, DATADOC, SERIADOC, DEN_PART, CODFISCAL,
    VALDOC, BAZA_MAX, TVA_MAX, BAZA_MIN, TVA_MIN, BAZA_MED, TVA_MED,
    BAZA_REGMAX, TVA_REGMAX, BAZA_REGMIN, TVA_REGMIN,
    BAZA_REG,  TVA_REG, BAZA_REG2, TVA_REG2, BAZA_REG3, TVA_REG3, BAZA_REG4, TVA_REG4, BAZA_REG5, TVA_REG5,
    TVA_0,
    AICB_BAZA,   AICB_TVA,
    AICB_SCUT,   AICB_NEIMP,
    AICS_SCUT,   AICS_NEIMP,
    RS315_BAZA,  RS315_TVA,
    BS150_BAZA,  BS150_TVA,
    BS160_BAZA,  BS160_TVA,
    BS160_BMAX,  BS160_TMAX,
    BS160_BMIN,  BS160_TMIN,
    BS160_BMED,  BS160_TMED,
    BS160_BREG,  BS160_TREG,
    BS160_BREG2, BS160_TREG2,
    BS160_BREG3, BS160_TREG3,
    BS160_BREG4, BS160_TREG4,
    BS160_BREG5, BS160_TREG5,
    PRORATA, TVAN_MAX, TVAN_MIN, TVAN_MED, TVAN_REG, TVAN_REG2, TVAN_REG3, TVAN_REG4, TVAN_REG5, TVANEDED, TVANPRORATA, TVAMPRORATA,
    OBS, SUBUNITATE, UE, TI,
    DATACDOC, OPERATOR, ANDOC, LUNADOC, TVALAINC, TVALAINCF,
    RESTOL, BAZAOBLIG, TVANOBLIG,
    PLATAPREFIX, PLATATIP, PLATANR, PLATADATA,
    PLATAVAL, PLATAVFT, PLATATVA,
    RESTVAL, RESTTVA, SOLDVAL, SOLDTVA,
    DOCVAL, DOCBAZA, DOCTVA,
    TIPTVADOC,
    TVA_RET&apos;||gUserFields||&apos;)&apos;;
  -- STEF -- orice adaugare de camp trebuie sa se adauge si in TMP_JC_D300

  sSelect1 := &apos;
  WITH X AS (&apos;||
    sXIntr(sPjTva)||&apos;
      AND I.CODINTR NOT IN (SELECT DISTINCT CODDOC FROM TMP_LST_TVAINCAS)
      AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos;),
  JC AS (&apos;||sJCIntr||&apos;)
  SELECT
    I.CODINTR, NULL NAV_CodDoc1, I.TIPDOC, 1 ORDDOC,
    I.PREFIXDOC, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(I.TIPDOC) TIPDOC, I.NRDOC, I.NRI, I.DATADOC, Coalesce(I.SERIADOC,DC.SERIE) SERIADOC, P.DEN_PART, COALESCE(CFD.CODFISCAL,SDOC.CODFISCAL,CFP.CODFISCAL) CODFISCAL,
    CASE
      WHEN JC.TVAINC = 0
      THEN I.VALDOC * Coalesce(NULLIf(I.Curs,0),1) + CASE WHEN Coalesce(I.TIPTRANZACTIE, 0) = 2 THEN Coalesce(d.TVADOCVAMA,0) ELSE Coalesce(d.VALSUPLIM,0) + Coalesce(d.VALDOCVAMA,0) END
      ELSE JC.BMAX + JC.TMAX + JC.BMIN + JC.TMIN + JC.BMED + JC.TMED + JC.BREG + JC.TREG + JC.BREG2 + JC.TREG2 + JC.BREG3 + JC.TREG3 + JC.BREG4 + JC.TREG4 + JC.BREG5 + JC.TREG5 + JC.T0
    END VALDOC,
    CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE JC.BMAX END BAZA_MAX, CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE JC.TMAX END TVA_MAX,
    CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE JC.BMIN END BAZA_MIN, CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE JC.TMIN END TVA_MIN,
    JC.BMED BAZA_MED, JC.TMED TVA_MED,
    CASE WHEN JC.DOC_REG = 0 THEN 0 ELSE JC.BMAX END BAZA_REGMAX, CASE WHEN JC.DOC_REG = 0 THEN 0 ELSE JC.TMAX END TVA_REGMAX,
    CASE WHEN JC.DOC_REG = 0 THEN 0 ELSE JC.BMIN END BAZA_REGMIN, CASE WHEN JC.DOC_REG = 0 THEN 0 ELSE JC.TMIN END TVA_REGMIN,
    JC.BREG BAZA_REG, JC.TREG TVA_REG, JC.BREG2 BAZA_REG2, JC.TREG2 TVA_REG2, JC.BREG3 BAZA_REG3, JC.TREG3 TVA_REG3, JC.BREG4 BAZA_REG4, JC.TREG4 TVA_REG4, JC.BREG5 BAZA_REG5, JC.TREG5 TVA_REG5, JC.T0 TVA_0,
    CASE WHEN JC.TVAINC = 0 THEN JC.AICB_BAZA   END AICB_BAZA,   CASE WHEN JC.TVAINC = 0 THEN JC.AICB_TVA    END AICB_TVA,
    CASE WHEN JC.TVAINC = 0 THEN JC.AICB_SCUT   END AICB_SCUT,   CASE WHEN JC.TVAINC = 0 THEN JC.AICB_NEIMP  END AICB_NEIMP,
    CASE WHEN JC.TVAINC = 0 THEN JC.AICS_SCUT   END AICS_SCUT,   CASE WHEN JC.TVAINC = 0 THEN JC.AICS_NEIMP  END AICS_NEIMP,
    CASE WHEN JC.TVAINC = 0 THEN JC.RS315_BAZA  END RS315_BAZA,  CASE WHEN JC.TVAINC = 0 THEN JC.RS315_TVA   END RS315_TVA,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS150_BAZA  END BS150_BAZA,  CASE WHEN JC.TVAINC = 0 THEN JC.BS150_TVA   END BS150_TVA,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BAZA  END BS160_BAZA,  CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TVA   END BS160_TVA,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BMAX  END BS160_BMAX,  CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TMAX  END BS160_TMAX,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BMIN  END BS160_BMIN,  CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TMIN  END BS160_TMIN,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BMED  END BS160_BMED,  CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TMED  END BS160_TMED,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BREG  END BS160_BREG,  CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TREG  END BS160_TREG,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BREG2 END BS160_BREG2, CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TREG2 END BS160_TREG2,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BREG3 END BS160_BREG3, CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TREG3 END BS160_TREG3,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BREG4 END BS160_BREG4, CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TREG4 END BS160_TREG4,
    CASE WHEN JC.TVAINC = 0 THEN JC.BS160_BREG5 END BS160_BREG5, CASE WHEN JC.TVAINC = 0 THEN JC.BS160_TREG5 END BS160_TREG5,
    JC.PRORATA, JC.TNMAX TVAN_MAX, JC.TNMIN TVAN_MIN, JC.TNMED TVAN_MED, JC.TNREG TVAN_REG, JC.TNREG2 TVAN_REG2, JC.TNREG3 TVAN_REG3, JC.TNREG4 TVAN_REG4, JC.TNREG5 TVAN_REG5,
    JC.TNEDED TVANEDED, JC.TNPRORATA TVANPRORATA, JC.TMPRORATA TVAMPRORATA,
    I.OBS, SUB.DEN_SUBUNIT SUBUNITATE, CASE WHEN t.statcomunitar = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE WHEN jc.tiptva = 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI,
    I.DATACREARE, UT.USERNAME, I.AN, I.LUNA, CASE WHEN JC.TVAINC = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TVALAINC, CASE WHEN I.TVAINCASARE_F = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TVALAINCF,
    CASE WHEN JC.TVAINC = 1 THEN JC.BAZAX+JC.TVAX END RESTOL, CASE WHEN JC.TVAINC = 1 THEN JC.BAZAX END BAZAOBLIG, CASE WHEN JC.TVAINC = 1 THEN JC.TVAX END TVANOBLIG,
    NULL PLATAPREFIX, NULL PLATATIP, NULL PLATANR, NULL PLATADATA,
    NULL PLATAVAL, NULL PLATAVFT, NULL PLATATVA,
    CASE WHEN JC.TVAINC = 1 THEN JC.BAZAX+JC.TVAX END RESTVAL, CASE WHEN JC.TVAINC = 1 THEN JC.TVAX END RESTTVA,
    CASE WHEN JC.TVAINC = 1 THEN JC.BAZAX+JC.TVAX END SOLDVAL, CASE WHEN JC.TVAINC = 1 THEN JC.TVAX END SOLDTVA,
    I.VALDOC * Coalesce(NULLIf(I.Curs,0),1) DOCVAL, (I.VALDOC-I.TVADOC) * Coalesce(NULLIf(I.Curs,0),1) DOCBAZA, I.TVADOC * Coalesce(NULLIf(I.Curs,0),1) DOCTVA,
    CASE i.tiptva WHEN 1 THEN &apos;&apos;Taxare normala&apos;&apos; WHEN 2 THEN &apos;&apos;Taxare inversa&apos;&apos; WHEN 3 THEN &apos;&apos;Tranzactie triunghiulara&apos;&apos; WHEN 4 THEN &apos;&apos;Suspendare temporara&apos;&apos; END TIPTVADOC,
    0 TVA_RET &apos;||gUserAlias||&apos;
  FROM JC
    INNER JOIN INTRARI        I    ON I.CODINTR         = JC.CODINTR
    LEFT  JOIN NPART          P    ON P.CODPART         = I.PARTENER
    LEFT  JOIN NPARTCODFISC   CFP  ON CFP.CODPART       = I.PARTENER AND CFP.PRINCIPAL = 1
    LEFT  JOIN NPARTCODFISC   CFD  ON CFD.COD_CODFISCAL = I.CODFISCAL
    LEFT  JOIN DVI            D    ON D.CODINTR         = JC.CODINTR
    LEFT  JOIN NSUBUNIT       SUB  ON SUB.CODSUBUNIT    = I.SUBUNITATEA
    LEFT  JOIN NAGENDA        SDOC ON SDOC.CODAGENDA    = I.CODLOCATIE
    LEFT  JOIN NAGENDA        SSOC ON SSOC.CODPART      = I.PARTENER AND Coalesce(SSOC.INACTIV,0) = 0 AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND SSOC.TIP = 0
    LEFT  JOIN NLOCALIT       L    ON L.CODLOCALIT      = Coalesce(SDOC.CODLOCALIT, SSOC.CODLOCALIT)
    LEFT  JOIN NTARI          T    ON T.CODTARA         = Coalesce(L.CODTARA, 0)
    LEFT  JOIN DOCCARNETE     DC   ON DC.CODCARNET      = I.CARNETDOC
    LEFT  JOIN TMP_UTILIZATOR UT   ON UT.CODUTILIZATOR  = I.USERID&apos;||
    gSuplJoins;

  sInsAux1 :=
  &apos;INSERT INTO TMP_JC_AUX1
  SELECT t.nav_coddoc, t.nav_tipdoc, (i.valdoc-Sum(I1.CANT*I1.PRETORIG*I1.COEFDISCMAJ))/i.valdoc
  FROM &apos;||tmpName||&apos; t
    INNER JOIN intrari  i  ON i.codintr   = t.nav_coddoc and i.tipdoc = t.nav_tipdoc
    INNER JOIN intrari1 i1 ON i1.codintr  = i.codintr
    INNER JOIN nartobj  o  ON o.codobiect = i1.codobiect
  WHERE i.valdoc &lt;&gt; 0
    AND o.codarticol IN (&apos;||sInsAux1||&apos;)
  GROUP BY t.nav_coddoc, t.nav_tipdoc, i.valdoc&apos;;

  sUpdate1 := &apos;UPDATE &apos;||tmpName||&apos; t SET t.valdoc = t.valdoc* Coalesce((SELECT a.coefdoc FROM TMP_JC_AUX1 a WHERE a.nav_coddoc = t.nav_coddoc AND a.nav_tipdoc = t.nav_tipdoc),1)&apos;;

  sSelect2 := &apos;
  WITH X AS (
    SELECT
      t1.codtrezor1, t1.codtrezor, g.tipdoc, g.semnificatie, Coalesce(t1.codpart,0) codpart, o.icont, CASE g.semnificatie WHEN 900 THEN o.icont ELSE Coalesce(t1.codpart,0) END destinatie,
      t1.doc, t1.nrdoc, t1.datadoc, t1.carnetdoc, t1.seriedoc seriadoc, t1.obs,
      CASE WHEN Coalesce(o.valoare - g.tva,0) = 0 THEN &apos;||sPjTva||&apos; ELSE g.tva*100/(o.valoare - g.tva) END PJTVA, &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; ALTVA,
      (o.valoare - Coalesce(g.tva,0)) * Coalesce(NullIF(g.curs,0),1) * CASE WHEN g.semnificatie IN (320,430) THEN -1 ELSE 1 END baza ,
      g.tva * Coalesce(NullIF(g.curs,0),1) * CASE WHEN g.semnificatie IN (320,430) THEN -1 ELSE 1 END tva ,
      o.valoare * Coalesce(NullIF(g.curs,0),1) * CASE WHEN g.semnificatie IN (320,430) THEN -1 ELSE 1 END val,
      t.subunitatea, t.datacreare, Coalesce(o.tvaneded,0) tvaneded, t.userid, t.an, t.luna,
      t1.valdoc*Coalesce(NullIF(g.curs,0),1) DOCVAL,
      0 TVA_RET
    FROM trezor1 t1
      INNER JOIN trezor   t  ON t.codtrezor       = t1.codtrezor
      INNER JOIN general  g  ON g.coddoc          = t1.codtrezor1 AND g.tipdoc IN (29,30,33)
      INNER JOIN obligpif o  ON o.codgeneral      = g.codgeneral
      LEFT  JOIN STINGERE S  ON S.CODSTINGATORPIF = O.CODOBLIGPIF
      LEFT  JOIN OBLIGPIF OS ON OS.CODOBLIGPIF    = S.CODSTINSPIF
    WHERE T1.AN*12+T1.LUNA &apos;||sCondLuna||&apos;
      AND ((G.SEMNIFICATIE = 900) OR ((Coalesce(G.TVA,0) &lt;&gt; 0 ) AND ((G.SEMNIFICATIE IN (310,430,700)) OR (G.SEMNIFICATIE = 320 AND OS.SEMNIFICATIE &lt;&gt; 330) OR (G.SEMNIFICATIE = 420 AND OS.SEMNIFICATIE = 430)))) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    UNION ALL
    SELECT
      t1.codtrezor1, t1.codtrezor, g.tipdoc, g.semnificatie, Coalesce(t1.codpart,0) codpart, o.icont, o.icont destinatie,
      t1.doc, t1.nrdoc, t1.datadoc, t1.carnetdoc, t1.seriedoc seriadoc, t1.obs,
      0 PJTVA, &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; ALTVA,
      0 baza ,
      0 tva ,
      o.valoare * Coalesce(NullIF(g.curs,0),1) val,
      t.subunitatea, t.datacreare, Coalesce(o.tvaneded,0) tvaneded, t.userid, t.an, t.luna,
      t1.valdoc*Coalesce(NullIF(g.curs,0),1) DOCVAL, o.valoare * Coalesce(NullIF(g.curs,0),1) TVA_RET
    FROM trezor t
      INNER JOIN trezor1  t1     ON t1.codtrezor       = t.codtrezor
      INNER JOIN general  g      ON g.coddoc           = t1.codtrezor1 AND g.tipdoc = t.tipdoc
			INNER JOIN obligpif o      ON o.codgeneral       = g.codgeneral
      LEFT  JOIN stingere s      ON s.codstingatorpif  = o.codobligpif
      LEFT  JOIN obligpif ostins ON ostins.codobligpif = s.codstinspif
    WHERE T.OPERAT = 1 AND T1.ANULAT = 0  &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      AND T.AN*12+T.LUNA &apos;||sCondLuna||&apos;
      AND O.SEMNIFICATIE = 950 AND T1.OBIECTTRANZ IN (4,5) AND G.FARAREG = 1
  ),
  JC_TREZ AS (
    SELECT
      codtrezor1, codtrezor, tipdoc, 1 tiptva, 0 codlocatie, semnificatie, codpart, icont, doc, nrdoc, datadoc, carnetdoc, seriadoc, obs,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 3 THEN BAZA ELSE 0 END) BMAX,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 3 THEN TVA  ELSE 0 END) TMAX,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 2 THEN BAZA ELSE 0 END) BMIN,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 2 THEN TVA  ELSE 0 END) TMIN,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 1 THEN BAZA ELSE 0 END) BMED,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 1 THEN TVA  ELSE 0 END) TMED,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 4 THEN BAZA ELSE 0 END) BREG,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 4 THEN TVA  ELSE 0 END) TREG,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 5 THEN BAZA ELSE 0 END) BREG2,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 5 THEN TVA  ELSE 0 END) TREG2,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 6 THEN BAZA ELSE 0 END) BREG3,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 6 THEN TVA  ELSE 0 END) TREG3,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 7 THEN BAZA ELSE 0 END) BREG4,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 7 THEN TVA  ELSE 0 END) TREG4,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 8 THEN BAZA ELSE 0 END) BREG5,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 8 THEN TVA  ELSE 0 END) TREG5,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 0 THEN BAZA ELSE 0 END) T0,
      SUM (VAL) VALDOC,
      0 AICB_BAZA, 0 AICB_TVA, 0 AICB_SCUT, 0 AICB_NEIMP, 0 AICS_SCUT, 0 AICS_NEIMP,
      0 RS315_BAZA, 0 RS315_TVA, 0 BS150_BAZA, 0 BS150_TVA, 0 BS160_BAZA, 0 BS160_TVA, 0 BS160_BMAX, 0 BS160_TMAX, 0 BS160_BMIN, 0 BS160_TMIN, 0 BS160_BMED, 0 BS160_TMED,
      0 BS160_BREG, 0 BS160_TREG, 0 BS160_BREG2, 0 BS160_TREG2, 0 BS160_BREG3, 0 BS160_TREG3, 0 BS160_BREG4, 0 BS160_TREG4, 0 BS160_BREG5, 0 BS160_TREG5,
      0 PRORATA, SUM(CASE WHEN TVANEDED = 2 THEN TVA ELSE 0 END) TVANPRORATA, 0 TVAMPRORATA,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 3 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANMAX,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 2 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANMIN,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 1 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANMED,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 4 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANREG,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 5 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANREG2,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 6 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANREG3,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 7 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANREG4,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 8 THEN CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END  ELSE 0 END) TVANREG5,
      SUM(CASE TVANEDED WHEN 1 THEN TVA WHEN 3 THEN TVA/2 ELSE 0 END) TVANEDED,
      SUBUNITATEA, DATACREARE, USERID, AN, LUNA,
      DOCVAL, SUM (BAZA) DOCBAZA, SUM (TVA) DOCTVA,
      SUM(TVA_RET) TVA_RET
    FROM X
    GROUP BY codtrezor1, codtrezor, tipdoc, semnificatie, codpart, icont, doc, nrdoc, datadoc, carnetdoc, seriadoc, obs, subunitatea, datacreare, userid, an, luna, docval
  )
  SELECT
    jc.codtrezor NAV_CodDoc, jc.codtrezor1 NAV_CodDoc1, jc.tipdoc NAV_TipDoc, 1 ORDDOC,
    jc.doc, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(JC.TIPDOC) TIPDOC, jc.nrdoc, null NRI, jc.datadoc, Coalesce(jc.seriadoc,dc.serie) SERIADOC,
    CASE
      WHEN jc.codpart &lt;&gt; 0 THEN p.den_part
      WHEN jc.semnificatie = 900 AND jc.obs LIKE &apos;&apos;%/%&apos;&apos; THEN SUBSTR(jc.OBS,1, LEAST(INSTR(jc.OBS,&apos;&apos;/&apos;&apos;)-1,197-length(nc.den_cont))) || &apos;&apos; / &apos;&apos; ||nc.den_cont
      WHEN jc.semnificatie = 900 THEN nc.den_cont
      ELSE p.den_part
    END DEN_PART,
    CASE
      WHEN jc.TIPDOC IN (29,33) AND jc.obs LIKE &apos;&apos;%/%&apos;&apos; AND INSTR(jc.OBS,&apos;&apos;/&apos;&apos;,1,2) = 0 THEN SUBSTR(jc.OBS,INSTR(jc.OBS,&apos;&apos;/&apos;&apos;)+1,100)
      WHEN jc.TIPDOC IN (29,33) AND jc.obs LIKE &apos;&apos;%/%&apos;&apos; THEN SUBSTR(jc.OBS,INSTR(jc.OBS,&apos;&apos;/&apos;&apos;)+1,Least(INSTR(jc.OBS,&apos;&apos;/&apos;&apos;,1,2)-INSTR(jc.OBS,&apos;&apos;/&apos;&apos;)-1, 100))
      ELSE cfp.codfiscal
    END CODFISCAL,
    JC.VALDOC,
    JC.BMAX BAZA_MAX, JC.TMAX TVA_MAX, JC.BMIN BAZA_MIN, JC.TMIN TVA_MIN, JC.BMED BAZA_MED, JC.TMED TVA_MED,
    0 BAZA_REGMAX, 0 TVA_REGMAX, 0 BAZA_REGMIN, 0 TVA_REGMIN,
    JC.BREG BAZA_REG, JC.TREG TVA_REG, JC.BREG2 BAZA_REG2, JC.TREG2 TVA_REG2, JC.BREG3 BAZA_REG3, JC.TREG3 TVA_REG3, JC.BREG4 BAZA_REG4, JC.TREG4 TVA_REG4, JC.BREG5 BAZA_REG5, JC.TREG5 TVA_REG5, JC.T0 TVA_0,
    JC.AICB_BAZA, JC.AICB_TVA, JC.AICB_SCUT, JC.AICB_NEIMP, 0 AICS_SCUT, 0 AICS_NEIMP,
    JC.RS315_BAZA,  JC.RS315_TVA,
    JC.BS150_BAZA,  JC.BS150_TVA,
    JC.BS160_BAZA,  JC.BS160_TVA,
    JC.BS160_BMAX,  JC.BS160_TMAX,
    JC.BS160_BMIN,  JC.BS160_TMIN,
    JC.BS160_BMED,  JC.BS160_TMED,
    JC.BS160_BREG,  JC.BS160_TREG,
    JC.BS160_BREG2, JC.BS160_TREG2,
    JC.BS160_BREG3, JC.BS160_TREG3,
    JC.BS160_BREG4, JC.BS160_TREG4,
    JC.BS160_BREG5, JC.BS160_TREG5,
    JC.PRORATA, JC.TVANMAX, JC.TVANMIN, JC.TVANMED, JC.TVANREG, JC.TVANREG2, JC.TVANREG3, JC.TVANREG4, JC.TVANREG5, JC.TVANEDED, JC.TVANPRORATA, JC.TVAMPRORATA,
    JC.OBS, SUB.DEN_SUBUNIT SUBUNITATE, CASE WHEN t.statcomunitar = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE WHEN jc.tiptva = 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI,
    JC.DATACREARE, UT.USERNAME, JC.AN, JC.LUNA, &apos;&apos;NU&apos;&apos; TVALAINC, &apos;&apos;NU&apos;&apos; TVALAINCF,
    NULL RESTOL, NULL BAZAOBLIG, NULL TVANOBLIG,
    NULL PLATAPREFIX, NULL PLATATIP, NULL PLATANR, NULL PLATADATA,
    NULL PLATAVAL, NULL PLATAVFT, NULL PLATATVA,
    NULL RESTVAL, NULL RESTTVA, NULL SOLDVAL, NULL SOLDTVA,
    JC.DOCVAL, JC.DOCBAZA, JC.DOCTVA,
    NULL TIPTVADOC,
    JC.TVA_RET &apos;||gUserAlias||&apos;
  FROM JC_TREZ jc
    LEFT JOIN INTRARI        I    ON I.CODINTR         = jc.codtrezor - jc.codtrezor
    LEFT JOIN NCONT          NC   ON NC.CODCONT        = JC.ICONT AND JC.SEMNIFICATIE = 900
    LEFT JOIN NPART          P    ON P.CODPART         = JC.CODPART
    LEFT JOIN NPARTCODFISC   CFP  ON CFP.CODPART       = P.CODPART AND CFP.PRINCIPAL = 1
    LEFT JOIN NPARTCODFISC   CFD  ON CFD.COD_CODFISCAL = CFP.COD_CODFISCAL
    LEFT JOIN NSUBUNIT       SUB  ON SUB.CODSUBUNIT    = JC.SUBUNITATEA
    LEFT JOIN NAGENDA        SDOC ON SDOC.CODAGENDA    = JC.CODLOCATIE
    LEFT JOIN NAGENDA        SSOC ON SSOC.CODPART      = P.CODPART  AND Coalesce(SSOC.INACTIV,0) = 0 AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND SSOC.TIP = 0
    LEFT JOIN NLOCALIT       L    ON L.CODLOCALIT      = SSOC.CODLOCALIT
    LEFT JOIN NTARI          T    ON T.CODTARA         = Coalesce(L.CODTARA, 0)
    LEFT JOIN DOCCARNETE     DC   ON DC.CODCARNET      = JC.CARNETDOC
    LEFT JOIN TMP_UTILIZATOR UT   ON UT.CODUTILIZATOR  = JC.USERID&apos;||
    gSuplJoins;

  sSelect3 := &apos;
  WITH X AS (
    SELECT
      NC.CODNC, NC.NRDOC, NC.DATADOC, NC.CARNETDOC, NC.TIPTRANZ, NC.TIPTVA, NC.SUBUNITATEA, NC.DATACREARE, NC.USERID, NC.AN, NC.LUNA, NC.OBS, NC.VALOARE DOCVAL,
      COALESCE(
        CASE WHEN NC.TIPTVA = 2 THEN NULL ELSE Coalesce(NULLIF(NC.PART,0),NC1.CODPART,0) END,
        Max(Coalesce(NULLIF(NC.PART,0),NC1.CODPART,0))
      ) PART,
      SUM(NC1.VALOARE) * Coalesce(NullIF(nc.curs,0),1) VALOARE,
      SUM(CASE WHEN NC1.TIPLINIETVA = 1 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) BAZA_X,
      CASE
        WHEN NC.TIPTVA = 2 AND Coalesce(NC.TIPTRANZ,1) = 1 THEN &apos;&apos;BS160&apos;&apos;
        WHEN NC.TIPTRANZ = 2 THEN &apos;&apos;AICB&apos;&apos;
        ELSE &apos;&apos;N0&apos;&apos;
      END CAZ_X,
      SUM(CASE WHEN NC1.TIPLINIETVA = 2 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) BAZA_STOC,
      SUM(CASE WHEN NC1.TIPLINIETVA = 3 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) TVA_STOC,
      &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; ALTVA,
      CASE
        WHEN NC.TIPTVA = 2 AND Coalesce(NC.TIPTRANZ,1) = 1 THEN &apos;&apos;BS160&apos;&apos;
        WHEN NC.TIPTRANZ = 2 THEN &apos;&apos;AICB&apos;&apos;
        WHEN SUM(CASE WHEN NC1.TIPLINIETVA = 2 THEN NC1.VALOARE ELSE 0 END) = 0 OR SUM(CASE WHEN NC1.TIPLINIETVA = 3 THEN NC1.VALOARE ELSE 0 END) = 0 THEN &apos;&apos;N0&apos;&apos;
        ELSE &apos;&apos;NTVA&apos;&apos;
      END CAZ_STOC,
      SUM(CASE WHEN NC1.TIPLINIETVA = 4 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) BAZA_SERV,
      SUM(CASE WHEN NC1.TIPLINIETVA = 5 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) TVA_SERV,
      CASE
        WHEN NC.TIPTVA = 2 AND NC.TIPTRANZ IN (2,3) THEN &apos;&apos;BS150&apos;&apos;
        WHEN NC.TIPTVA = 1 AND NC.TIPTRANZ = 2 THEN &apos;&apos;BS150&apos;&apos;
        WHEN NC.TIPTVA = 1 AND NC.TIPTRANZ = 3 THEN &apos;&apos;N0&apos;&apos;
        WHEN SUM(CASE WHEN NC1.TIPLINIETVA = 4 THEN NC1.VALOARE ELSE 0 END) =0 OR SUM(CASE WHEN NC1.TIPLINIETVA = 5 THEN NC1.VALOARE ELSE 0 END) = 0 THEN &apos;&apos;N0&apos;&apos;
        ELSE &apos;&apos;NTVA&apos;&apos;
      END CAZ_SERV,
      SUM(CASE WHEN NC1.TIPLINIETVA = 6 THEN NC1.VALOARE ELSE 0 END) * Coalesce(NullIF(nc.curs,0),1) BAZA_SCUTIT
    FROM NC INNER JOIN NC1 ON NC1.CODNC = NC.CODNC
    WHERE NC.AN*12+NC.LUNA &apos;||sCondLuna||&apos;
      AND NC.JURNALTVA = 2 AND NC.TIPTVA IN (1,2)
      AND NC1.TIPLINIETVA BETWEEN 2 AND 6 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
    GROUP BY
      NC.CODNC, NC.NRDOC, NC.DATADOC, NC.CARNETDOC, NC.TIPTRANZ, NC.TIPTVA, NC.SUBUNITATEA, NC.DATACREARE, NC.USERID, NC.AN, NC.LUNA, NC.OBS, NC.VALOARE, NC.CURS,
      CASE WHEN NC.TIPTVA = 2 THEN NULL ELSE Coalesce(NULLIF(NC.PART,0),NC1.CODPART,0) END
  ),
  JC_NC AS (
    SELECT
      CODNC, TIPTVA, NRDOC, 0 CODLOCATIE, DATADOC, CARNETDOC, PART, VALOARE, OBS,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 3 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 3 THEN BAZA_SERV ELSE 0 END
      BMAX,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 3 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 3 THEN TVA_SERV ELSE 0 END
      TMAX,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 2 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 2 THEN BAZA_SERV ELSE 0 END
      BMIN,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 2 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 2 THEN TVA_SERV ELSE 0 END
      TMIN,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 1 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 1 THEN BAZA_SERV ELSE 0 END
      BMED,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 1 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 1 THEN TVA_SERV ELSE 0 END
      TMED,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 4 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 4 THEN BAZA_SERV ELSE 0 END
      BREG,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 4 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 4 THEN TVA_SERV ELSE 0 END
      TREG,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 5 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 5 THEN BAZA_SERV ELSE 0 END
      BREG2,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 5 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 5 THEN TVA_SERV ELSE 0 END
      TREG2,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 6 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 6 THEN BAZA_SERV ELSE 0 END
      BREG3,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 6 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 6 THEN TVA_SERV ELSE 0 END
      TREG3,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 7 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 7 THEN BAZA_SERV ELSE 0 END
      BREG4,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 7 THEN TVA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 7 THEN TVA_SERV ELSE 0 END
      TREG4,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 8 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 8 THEN BAZA_SERV ELSE 0 END
      BREG5,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 8 THEN TVA_STOC ELSE 0 END +
      CASE WHEN CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 8 THEN TVA_SERV ELSE 0 END
      TREG5,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;N0&apos;&apos; OR (CAZ_STOC = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 0) THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;N0&apos;&apos; OR (CAZ_SERV = &apos;&apos;NTVA&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 0) THEN BAZA_SERV ELSE 0 END +
      CASE WHEN CAZ_X    = &apos;&apos;N0&apos;&apos; THEN BAZA_X ELSE 0 END +
      BAZA_SCUTIT
      T0,
      CASE WHEN CAZ_STOC = &apos;&apos;AICB&apos;&apos;  THEN BAZA_STOC ELSE 0 END + CASE WHEN CAZ_X = &apos;&apos;AICB&apos;&apos;  THEN BAZA_X ELSE 0 END AICB_BAZA,
      CASE WHEN CAZ_STOC = &apos;&apos;AICB&apos;&apos;  THEN TVA_STOC  ELSE 0 END AICB_TVA,
      0 AICB_SCUT, 0 AICB_NEIMP, 0 AICS_SCUT, 0 AICS_NEIMP,
      0 RS315_BAZA, 0 RS315_TVA,
      CASE WHEN CAZ_SERV = &apos;&apos;BS150&apos;&apos; THEN BAZA_SERV ELSE 0 END BS150_BAZA,
      CASE WHEN CAZ_SERV = &apos;&apos;BS150&apos;&apos; THEN TVA_SERV  ELSE 0 END BS150_TVA,
      CASE WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; THEN BAZA_STOC ELSE 0 END +
      CASE WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; THEN BAZA_SERV ELSE 0 END +
      CASE WHEN CAZ_X    = &apos;&apos;BS160&apos;&apos; THEN BAZA_X ELSE 0 END
      BS160_BAZA,
      CASE WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; THEN TVA_STOC  ELSE 0 END +
      CASE WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; THEN TVA_SERV  ELSE 0 END
      BS160_TVA,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 3 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 3 THEN BAZA_SERV ELSE 0 END
      BS160_BMAX,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 3 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 3 THEN TVA_SERV  ELSE 0 END
      BS160_TMAX,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 2 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 2 THEN BAZA_SERV ELSE 0 END
      BS160_BMIN,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 2 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 2 THEN TVA_SERV  ELSE 0 END
      BS160_TMIN,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 1 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 1 THEN BAZA_SERV ELSE 0 END
      BS160_BMED,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 1 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 1 THEN TVA_SERV  ELSE 0 END
      BS160_TMED,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 4 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 4 THEN BAZA_SERV ELSE 0 END
      BS160_BREG,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 4 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 4 THEN TVA_SERV  ELSE 0 END
      BS160_TREG,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 5 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 5 THEN BAZA_SERV ELSE 0 END
      BS160_BREG2,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 5 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 5 THEN TVA_SERV  ELSE 0 END
      BS160_TREG2,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 6 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 6 THEN BAZA_SERV ELSE 0 END
      BS160_BREG3,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 6 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 6 THEN TVA_SERV  ELSE 0 END
      BS160_TREG3,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 7 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 7 THEN BAZA_SERV ELSE 0 END
      BS160_BREG4,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 7 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 7 THEN TVA_SERV  ELSE 0 END
      BS160_TREG4,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 8 THEN BAZA_STOC ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 8 THEN BAZA_SERV ELSE 0 END
      BS160_BREG5,
      CASE WHEN BAZA_STOC = 0 THEN 0 WHEN CAZ_STOC = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_STOC*100/BAZA_STOC,ALTVA) = 8 THEN TVA_STOC  ELSE 0 END +
      CASE WHEN BAZA_SERV = 0 THEN 0 WHEN CAZ_SERV = &apos;&apos;BS160&apos;&apos; AND PKG_LIST_BASE_UTILS.MATCH_TVA(TVA_SERV*100/BAZA_SERV,ALTVA) = 8 THEN TVA_SERV  ELSE 0 END
      BS160_TREG5,
      SUBUNITATEA, DATACREARE, USERID, AN, LUNA,
      DOCVAL, (BAZA_STOC+BAZA_SERV) DOCBAZA, (TVA_STOC+TVA_SERV ) DOCTVA
    FROM x)
  SELECT
    jc.CODNC NAV_CodDoc, NULL NAV_CodDoc1, 35 NAV_TipDoc, 1 ORDDOC,
    &apos;&apos;NC&apos;&apos; PREFIXDOC, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(35) TIPDOC, jc.nrdoc, NULL NRI, jc.datadoc, dc.serie, p.den_part, cfp.codfiscal,
    jc.valoare VALDOC,
    JC.BMAX BAZA_MAX, JC.TMAX TVA_MAX, JC.BMIN BAZA_MIN, JC.TMIN TVA_MIN, JC.BMED BAZA_MED, JC.TMED TVA_MED,
    0 BAZA_REGMAX, 0 TVA_REGMAX, 0 BAZA_REGMIN, 0 TVA_REGMIN,
    JC.BREG BAZA_REG, JC.TREG TVA_REG, JC.BREG2 BAZA_REG2, JC.TREG2 TVA_REG2, JC.BREG3 BAZA_REG3, JC.TREG3 TVA_REG3, JC.BREG4 BAZA_REG4, JC.TREG4 TVA_REG4, JC.BREG5 BAZA_REG5, JC.TREG5 TVA_REG5, JC.T0 TVA_0,
    JC.AICB_BAZA, JC.AICB_TVA, JC.AICB_SCUT, JC.AICB_NEIMP, JC.AICS_SCUT, JC.AICS_NEIMP,
    JC.RS315_BAZA,  JC.RS315_TVA,
    JC.BS150_BAZA,  JC.BS150_TVA,
    JC.BS160_BAZA,  JC.BS160_TVA,
    JC.BS160_BMAX,  JC.BS160_TMAX,
    JC.BS160_BMIN,  JC.BS160_TMIN,
    JC.BS160_BMED,  JC.BS160_TMED,
    JC.BS160_BREG,  JC.BS160_TREG,
    JC.BS160_BREG2, JC.BS160_TREG2,
    JC.BS160_BREG3, JC.BS160_TREG3,
    JC.BS160_BREG4, JC.BS160_TREG4,
    JC.BS160_BREG5, JC.BS160_TREG5,
    0 PRORATA, 0 TVANMAX, 0 TVANMIN, 0 TVANMED, 0 TVANREG, 0 TVANREG2, 0 TVANREG3, 0 TVANREG4, 0 TVANREG5, 0 TVANEDED, 0 TVANPRORATA, 0 TVAMPRORATA,
    JC.OBS, SUB.DEN_SUBUNIT, CASE WHEN t.statcomunitar = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE WHEN jc.tiptva = 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI,
    JC.DATACREARE, UT.USERNAME, JC.AN, JC.LUNA, &apos;&apos;NU&apos;&apos; TVALAINC, &apos;&apos;NU&apos;&apos; TVALAINCF,
    NULL RESTOL, NULL BAZAOBLIG, NULL TVANOBLIG,
    NULL PLATAPREFIX, NULL PLATATIP, NULL PLATANR, NULL PLATADATA,
    NULL PLATAVAL, NULL PLATAVFT, NULL PLATATVA,
    NULL RESTVAL, NULL RESTTVA, NULL SOLDVAL, NULL SOLDTVA,
    JC.DOCVAL, JC.DOCBAZA, JC.DOCTVA,
    NULL TIPTVADOC,
    0 TVA_RET&apos;||gUserAlias||&apos;
  FROM JC_NC jc
    LEFT JOIN INTRARI        I    ON I.CODINTR         = jc.codnc - jc.codnc
    LEFT JOIN NPART          P    ON P.CODPART         = JC.PART
    LEFT JOIN NPARTCODFISC   CFP  ON CFP.CODPART       = JC.PART AND CFP.PRINCIPAL = 1
    LEFT JOIN NPARTCODFISC   CFD  ON CFD.COD_CODFISCAL = CFP.COD_CODFISCAL
    LEFT JOIN NSUBUNIT       SUB  ON SUB.CODSUBUNIT    = JC.SUBUNITATEA
    LEFT JOIN NAGENDA        SDOC ON SDOC.CODAGENDA    = JC.CODLOCATIE
    LEFT JOIN NAGENDA        SSOC ON SSOC.CODPART      = JC.PART AND Coalesce(SSOC.INACTIV,0) = 0 AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND SSOC.TIP = 0
    LEFT JOIN NLOCALIT       L    ON L.CODLOCALIT      = SSOC.CODLOCALIT
    LEFT JOIN NTARI          T    ON T.CODTARA         = Coalesce(L.CODTARA, 0)
    LEFT JOIN DOCCARNETE     DC   ON DC.CODCARNET      = JC.CARNETDOC
    LEFT JOIN TMP_UTILIZATOR UT   ON UT.CODUTILIZATOR  = JC.USERID&apos;||
    gSuplJoins;

  sSelect4 := &apos;
  WITH x AS (
    SELECT
      C.CODCOMPENS,
      CASE
        WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 5 THEN 1
        WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 5 THEN 2
        ELSE NULL
      END coddoc1,
      P.CODPART PART, C.NRDOC, C.DATADOC, C.CARNETDOC, C.SUBUNITATEA, C.OBSC,
      Sign(O.VALOARE) * CASE O.SEMNIFICATIE WHEN 1350 THEN -1 ELSE 1 END * Abs(O.VALOARE)                * Coalesce(NullIF(g.curs,0),1) VALOARE,
      Sign(O.VALOARE) * CASE O.SEMNIFICATIE WHEN 1350 THEN -1 ELSE 1 END * Abs(G.TVA)                    * Coalesce(NullIF(g.curs,0),1) TVA,
      Sign(O.VALOARE) * CASE O.SEMNIFICATIE WHEN 1350 THEN -1 ELSE 1 END * (Abs(O.VALOARE) - Abs(G.TVA)) * Coalesce(NullIF(g.curs,0),1) BAZA,
      CASE WHEN Coalesce(Abs(o.valoare) - Abs(g.tva),0) = 0 THEN &apos;||sPjTva||&apos; ELSE Abs(G.TVA)*100/(Abs(O.VALOARE)-Abs(G.TVA)) END PJTVA, &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; ALTVA,
      C.DATACREARE, C.USERID, C.AN, C.LUNA
    FROM COMPENS C
      INNER JOIN GENERAL  G  ON C.CODCOMPENS      = G.CODDOC AND G.TIPDOC = 28
      INNER JOIN OBLIGPIF O  ON O.CODGENERAL      = G.CODGENERAL
      INNER JOIN STINGERE S  ON S.CODSTINGATORPIF = O.CODOBLIGPIF
      INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF    = S.CODSTINSPIF
      INNER JOIN NPART    P  ON P.CODPART         = CASE WHEN O.SEMNIFICATIE = 1350 THEN C.PARTC ELSE C.PARTD END
    WHERE C.AN*12+C.LUNA &apos;||sCondLuna||&apos;
      AND G.SEMNIFICATIE IN (1350,1300)
      AND CASE
            WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 5 AND     OS.SEMNIFICATIE IN (210)      THEN 0
            WHEN G.SEMNIFICATIE = 1350                                  AND NOT OS.SEMNIFICATIE IN (330,1303) THEN 1
            WHEN G.SEMNIFICATIE = 1300                                  AND     OS.SEMNIFICATIE IN (310,430)  THEN 1
            WHEN G.SEMNIFICATIE = 1300 AND Coalesce(C.TIPCOMPENS,0) = 5 AND     OS.SEMNIFICATIE IN (110)      THEN 1
            ELSE 0
          END = 1
      AND Coalesce(G.TVA,0) &lt;&gt; 0
      AND P.CODPART &lt;&gt; 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, pSUBUNIT =&gt; vSubunit)||&apos;),
  JC_COMPENS AS (
    SELECT
      CODCOMPENS, CODDOC1, 1 TIPTVA, 0 CODLOCATIE, PART, NRDOC, DATADOC, CARNETDOC, SUBUNITATEA, OBSC,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 3 THEN BAZA ELSE 0 END) BMAX,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 3 THEN TVA  ELSE 0 END) TMAX,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 2 THEN BAZA ELSE 0 END) BMIN,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 2 THEN TVA  ELSE 0 END) TMIN,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 1 THEN BAZA ELSE 0 END) BMED,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 1 THEN TVA  ELSE 0 END) TMED,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 4 THEN BAZA ELSE 0 END) BREG,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 4 THEN TVA  ELSE 0 END) TREG,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 5 THEN BAZA ELSE 0 END) BREG2,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 5 THEN TVA  ELSE 0 END) TREG2,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 6 THEN BAZA ELSE 0 END) BREG3,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 6 THEN TVA  ELSE 0 END) TREG3,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 7 THEN BAZA ELSE 0 END) BREG4,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 7 THEN TVA  ELSE 0 END) TREG4,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 8 THEN BAZA ELSE 0 END) BREG5,
      SUM(CASE WHEN PKG_LIST_BASE_UTILS.MATCH_TVA(PJTVA, ALTVA) = 8 THEN TVA  ELSE 0 END) TREG5,
      0 T0,
      0 AICB_BAZA, 0 AICB_TVA, 0 AICB_SCUT, 0 AICB_NEIMP, 0 AICS_SCUT, 0 AICS_NEIMP,
      0 RS315_BAZA, 0 RS315_TVA, 0 BS150_BAZA, 0 BS150_TVA, 0 BS160_BAZA, 0 BS160_TVA, 0 BS160_BMAX, 0 BS160_TMAX, 0 BS160_BMIN, 0 BS160_TMIN, 0 BS160_BMED, 0 BS160_TMED,
      0 BS160_BREG, 0 BS160_TREG, 0 BS160_BREG2, 0 BS160_TREG2, 0 BS160_BREG3, 0 BS160_TREG3, 0 BS160_BREG4, 0 BS160_TREG4, 0 BS160_BREG5, 0 BS160_TREG5,
      SUM(VALOARE) VALOARE, DATACREARE, USERID, AN, LUNA,
      SUM(BAZA+TVA) DOCVAL, SUM (BAZA) DOCBAZA, SUM (TVA) DOCTVA
    FROM X
    GROUP BY CODCOMPENS, CODDOC1, PART, NRDOC, DATADOC, CARNETDOC, SUBUNITATEA, OBSC, DATACREARE, USERID, AN, LUNA
  )
  SELECT
    JC.CODCOMPENS, JC.CODDOC1 NAV_CodDoc1, 28, 1 ORDDOC,
    &apos;&apos;PV&apos;&apos; PREFIXDOC, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(28) TIPDOC, JC.NRDOC, NULL NRI, JC.DATADOC, DC.SERIE, P.DEN_PART, CFP.CODFISCAL ,
    JC.VALOARE VALDOC,
    JC.BMAX BAZA_MAX, JC.TMAX TVA_MAX, JC.BMIN BAZA_MIN, JC.TMIN TVA_MIN, JC.BMED BAZA_MED, JC.TMED TVA_MED,
    0 BAZA_REGMAX, 0 TVA_REGMAX, 0 BAZA_REGMIN, 0 TVA_REGMIN,
    JC.BREG BAZA_REG, JC.TREG TVA_REG, JC.BREG2 BAZA_REG2, JC.TREG2 TVA_REG2, JC.BREG3 BAZA_REG3, JC.TREG3 TVA_REG3, JC.BREG4 BAZA_REG4, JC.TREG4 TVA_REG4, JC.BREG5 BAZA_REG5, JC.TREG5 TVA_REG5, JC.T0 TVA_0,
    JC.AICB_BAZA, JC.AICB_TVA, JC.AICB_SCUT, JC.AICB_NEIMP, JC.AICS_SCUT, JC.AICS_NEIMP,
    JC.RS315_BAZA,  JC.RS315_TVA,
    JC.BS150_BAZA,  JC.BS150_TVA,
    JC.BS160_BAZA,  JC.BS160_TVA,
    JC.BS160_BMAX,  JC.BS160_TMAX,
    JC.BS160_BMIN,  JC.BS160_TMIN,
    JC.BS160_BMED,  JC.BS160_TMED,
    JC.BS160_BREG,  JC.BS160_TREG,
    JC.BS160_BREG2, JC.BS160_TREG2,
    JC.BS160_BREG3, JC.BS160_TREG3,
    JC.BS160_BREG4, JC.BS160_TREG4,
    JC.BS160_BREG5, JC.BS160_TREG5,
    0 PRORATA, 0 TVANMAX, 0 TVANMIN, 0 TVANMED, 0 TVANREG, 0 TVANREG2, 0 TVANREG3, 0 TVANREG4, 0 TVANREG5, 0 TVANEDED, 0 TVANPRORATA, 0 TVAMPRORATA,
    JC.OBSC, SUB.DEN_SUBUNIT, CASE WHEN t.statcomunitar = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END  ue, CASE WHEN jc.tiptva = 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END  ti,
    JC.DATACREARE, UT.USERNAME, JC.AN, JC.LUNA, &apos;&apos;NU&apos;&apos; TVALAINC, &apos;&apos;NU&apos;&apos; TVALAINCF,
    NULL RESTOL, NULL BAZAOBLIG, NULL TVANOBLIG,
    NULL PLATAPREFIX, NULL PLATATIP, NULL PLATANR, NULL PLATADATA,
    NULL PLATAVAL, NULL PLATAVFT, NULL PLATATVA,
    NULL RESTVAL, NULL RESTTVA, NULL SOLDVAL, NULL SOLDTVA,
    JC.DOCVAL, JC.DOCBAZA, JC.DOCTVA,
    NULL TIPTVADOC,
    0 TVA_RET&apos;||gUserAlias||&apos;
  FROM JC_COMPENS JC
    LEFT JOIN INTRARI        I    ON I.CODINTR         = jc.codcompens - jc.codcompens
    LEFT JOIN NPART          P    ON P.CODPART         = JC.PART
    LEFT JOIN NPARTCODFISC   CFP  ON CFP.CODPART       = JC.PART AND CFP.PRINCIPAL = 1
    LEFT JOIN NPARTCODFISC   CFD  ON CFD.COD_CODFISCAL = CFP.COD_CODFISCAL
    LEFT JOIN NSUBUNIT       SUB  ON SUB.CODSUBUNIT    = JC.SUBUNITATEA
    LEFT JOIN NAGENDA        SDOC ON SDOC.CODAGENDA    = JC.CODLOCATIE
    LEFT JOIN NAGENDA        SSOC ON SSOC.CODPART      = JC.PART AND Coalesce(SSOC.INACTIV,0) = 0 AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND SSOC.TIP = 0
    LEFT JOIN NLOCALIT       L    ON L.CODLOCALIT      = SSOC.CODLOCALIT
    LEFT JOIN NTARI          T    ON T.CODTARA         = Coalesce(L.CODTARA, 0)
    LEFT JOIN DOCCARNETE     DC   ON DC.CODCARNET      = JC.CARNETDOC
    LEFT JOIN TMP_UTILIZATOR UT   ON UT.CODUTILIZATOR  = JC.USERID&apos;||
    gSuplJoins;

  -- stef -- atentie la datele din TMP_LST_TVAINCAS folosesc in si nu join ca sa nu se duplice liniile
  sSelect5 := &apos;
  WITH X AS (&apos;||
    sXIntr(sPjTva)||&apos;
      AND I.CODINTR IN (SELECT DISTINCT CODDOC FROM TMP_LST_TVAINCAS) ),
  JC AS (&apos;||sJCIntr||&apos;)
  SELECT
    I.CODINTR, NULL NAV_CodDoc1, I.TIPDOC, TVAI.ORDDOC,
    I.PREFIXDOC, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(I.TIPDOC) TIPDOC, I.NRDOC, I.NRI, I.DATADOC, Coalesce(I.SERIADOC,DC.SERIE) SERIADOC, P.DEN_PART, COALESCE(CFD.CODFISCAL,SDOC.CODFISCAL,CFP.CODFISCAL) CODFISCAL,
    CASE
      WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.CoefDocTva,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL
      ELSE JC.BMAX + JC.TMAX + JC.BMIN + JC.TMIN + JC.BMED + JC.TMED + JC.BREG + JC.TREG + JC.BREG2 + JC.TREG2 + JC.BREG3 + JC.TREG3 + JC.BREG4 + JC.TREG4 + JC.BREG5 + JC.TREG5 + JC.T0 END
    VALDOC,
    (CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE 1 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNMAX  ELSE JC.BXMAX  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BMAX  ELSE 0 END) BAZA_MAX,
    (CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE 1 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNMAX  ELSE JC.TXMAX  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TMAX  ELSE 0 END) TVA_MAX,
    (CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE 1 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNMIN  ELSE JC.BXMIN  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BMIN  ELSE 0 END) BAZA_MIN,
    (CASE WHEN JC.DOC_REG = 1 THEN 0 ELSE 1 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNMIN  ELSE JC.TXMIN  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TMIN  ELSE 0 END) TVA_MIN,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNMED  ELSE JC.BXMED  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BMED  ELSE 0 END) BAZA_MED,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNMED  ELSE JC.TXMED  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TMED  ELSE 0 END) TVA_MED,
    (CASE WHEN JC.DOC_REG = 1 THEN 1 ELSE 0 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNMAX  ELSE JC.BXMAX  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BMAX  ELSE 0 END) BAZA_REGMAX,
    (CASE WHEN JC.DOC_REG = 1 THEN 1 ELSE 0 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNMAX  ELSE JC.TXMAX  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TMAX  ELSE 0 END) TVA_REGMAX,
    (CASE WHEN JC.DOC_REG = 1 THEN 1 ELSE 0 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNMIN  ELSE JC.BXMIN  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BMIN  ELSE 0 END) BAZA_REGMIN,
    (CASE WHEN JC.DOC_REG = 1 THEN 1 ELSE 0 END) *
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNMIN  ELSE JC.TXMIN  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TMIN  ELSE 0 END) TVA_REGMIN,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNREG  ELSE JC.BXREG  END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BREG  ELSE 0 END) BAZA_REG,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNREG  ELSE JC.TXREG  END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TREG  ELSE 0 END) TVA_REG,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNREG2 ELSE JC.BXREG2 END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BREG2 ELSE 0 END) BAZA_REG2,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNREG2 ELSE JC.TXREG2 END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TREG2 ELSE 0 END) TVA_REG2,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNREG3 ELSE JC.BXREG3 END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BREG3 ELSE 0 END) BAZA_REG3,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNREG3 ELSE JC.TXREG3 END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TREG3 ELSE 0 END) TVA_REG3,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNREG4 ELSE JC.BXREG4 END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BREG4 ELSE 0 END) BAZA_REG4,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNREG4 ELSE JC.TXREG4 END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TREG4 ELSE 0 END) TVA_REG4,
    (CASE WHEN JC.AUX_X = 0 THEN JC.BNREG5 ELSE JC.BXREG5 END*TVAI.COEFBAZA+CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.BREG5 ELSE 0 END) BAZA_REG5,
    (CASE WHEN JC.AUX_X = 0 THEN JC.TNREG5 ELSE JC.TXREG5 END*TVAI.COEFTVA +CASE WHEN JC.AUX_X &lt;&gt; 0 AND i.an*12+luna &apos;||sCondLuna||&apos; AND Coalesce(TVAI.ORDDOC,1) = 1 THEN JC.TREG5 ELSE 0 END) TVA_REG5,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.T0 END TVA_0,
    NULL AICB_BAZA, NULL AICB_TVA, NULL AICB_SCUT, NULL AICB_NEIMP, NULL AICS_SCUT, NULL AICS_NEIMP,
    NULL RS315_BAZA,  NULL RS315_TVA,
    NULL BS150_BAZA,  NULL BS150_TVA,
    NULL BS160_BAZA,  NULL BS160_TVA,
    NULL BS160_BMAX,  NULL BS160_TMAX,
    NULL BS160_BMIN,  NULL BS160_TMIN,
    NULL BS160_BMED,  NULL BS160_TMED,
    NULL BS160_BREG,  NULL BS160_TREG,
    NULL BS160_BREG2, NULL BS160_TREG2,
    NULL BS160_BREG3, NULL BS160_TREG3,
    NULL BS160_BREG4, NULL BS160_TREG4,
    NULL BS160_BREG5, NULL BS160_TREG5,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.PRORATA   END PRORATA,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNMAX     END TVAN_MAX,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNMIN     END TVAN_MIN,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNMED     END TVAN_MED,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNREG     END TVAN_REG,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNREG2    END TVAN_REG2,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNREG3    END TVAN_REG3,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNREG4    END TVAN_REG4,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNREG5    END TVAN_REG5,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNEDED    END TVANEDED,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TNPRORATA END TVANPRORATA,
    CASE WHEN Coalesce(TVAI.CoefDoc,1) &lt;&gt; 1 OR Coalesce(TVAI.ORDDOC,1) &gt; 1 OR &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &gt; i.an*12+luna THEN NULL ELSE JC.TMPRORATA END TVAMPRORATA,
    I.OBS, SUB.DEN_SUBUNIT, CASE WHEN t.statcomunitar = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE WHEN jc.tiptva = 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI,
    I.DATACREARE, UT.USERNAME, I.AN, I.LUNA, &apos;&apos;DA&apos;&apos; TVALAINC, CASE WHEN I.TVAINCASARE_F = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TVALAINCF,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN JC.BAZAX*Coalesce(TVAI.CoefDocBaza,1)+JC.TVAX*Coalesce(TVAI.CoefDocTva,1) ELSE NULL END RESTOL,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN JC.BAZAX*Coalesce(TVAI.CoefDocBaza,1)                                     ELSE NULL END BAZAOBLIG,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN                                       JC.TVAX*Coalesce(TVAI.CoefDocTva,1) ELSE NULL END TVANOBLIG,
    TVAI.PREFIXSTINGERE PLATAPREFIX, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(TVAI.TIPSTINGERE) PLATATIP, TVAI.NRSTINGERE PLATANR, TVAI.DATASTINGERE PLATADATA,
    Round(JC.BAZAX*TVAI.COEFBAZA+JC.TVAX*TVAI.COEFTVA, 7) PLATAVAL, Round(JC.BAZAX*TVAI.COEFBAZA, 7) PLATAVFT, Round(JC.TVAX*TVAI.COEFTVA, 7) PLATATVA,
    Round(JC.BAZAX*(Coalesce(TVAI.CoefDocBaza,1)-TVAI.CoefPlataBaza) + JC.TVAX*(Coalesce(TVAI.CoefDocTva,1)-TVAI.CoefPlataTva),7) RESTVAL, Round(JC.TVAX*(Coalesce(TVAI.CoefDocTva,1)-TVAI.CoefPlataTva),7) RESTTVA,
    Round(CASE WHEN TVAI.ORDDOC IS NULL OR TVAI.ORDDOC = TVAI.CountDoc THEN JC.BAZAX*(Coalesce(TVAI.CoefDocBaza,1)-TVAI.CoefPlataBaza)+JC.TVAX*(Coalesce(TVAI.CoefDocTva,1)-TVAI.CoefPlataTva) ELSE NULL END,7) SOLDVAL,
    Round(CASE WHEN TVAI.ORDDOC IS NULL OR TVAI.ORDDOC = TVAI.CountDoc THEN                                                            JC.TVAX*(Coalesce(TVAI.CoefDocTva,1)-TVAI.CoefPlataTva) ELSE NULL END,7) SOLDTVA,
    I.VALDOC * Coalesce(NULLIf(I.Curs,0),1) DOCVAL, (I.VALDOC-I.TVADOC) * Coalesce(NULLIf(I.Curs,0),1) DOCBAZA, I.TVADOC * Coalesce(NULLIf(I.Curs,0),1) DOCTVA,
    CASE i.tiptva WHEN 1 THEN &apos;&apos;Taxare normala&apos;&apos; WHEN 2 THEN &apos;&apos;Taxare inversa&apos;&apos; WHEN 3 THEN &apos;&apos;Tranzactie triunghiulara&apos;&apos; WHEN 4 THEN &apos;&apos;Suspendare temporara&apos;&apos; END TIPTVADOC,
    0 TVA_RET &apos;||gUserAlias||&apos;
  FROM JC
    INNER JOIN INTRARI          I    ON I.CODINTR         = JC.CODINTR
    INNER JOIN TMP_LST_TVAINCAS TVAI ON TVAI.CodDoc       = I.CodIntr AND TVAI.TIPDOC = I.TIPDOC
    LEFT JOIN NPART             P    ON P.CODPART         = I.PARTENER
    LEFT JOIN NPARTCODFISC      CFP  ON CFP.CODPART       = I.PARTENER AND CFP.PRINCIPAL = 1
    LEFT JOIN NPARTCODFISC      CFD  ON CFD.COD_CODFISCAL = I.CODFISCAL
    LEFT JOIN NSUBUNIT          SUB  ON SUB.CODSUBUNIT    = I.SUBUNITATEA
    LEFT JOIN NAGENDA           SDOC ON SDOC.CODAGENDA    = I.CODLOCATIE
    LEFT JOIN NAGENDA           SSOC ON SSOC.CODPART      = I.PARTENER AND Coalesce(SSOC.INACTIV,0) = 0 AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND SSOC.TIP = 0
    LEFT JOIN NLOCALIT          L    ON L.CODLOCALIT      = Coalesce(SDOC.CODLOCALIT, SSOC.CODLOCALIT)
    LEFT JOIN NTARI             T    ON T.CODTARA         = Coalesce(L.CODTARA, 0)
    LEFT JOIN DOCCARNETE        DC   ON DC.CODCARNET      = I.CARNETDOC
    LEFT JOIN TMP_UTILIZATOR    UT   ON UT.CODUTILIZATOR  = I.USERID&apos;||
    gSuplJoins;

  Pregateste_TMP_LST_TVAINCAS( aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  IF vCountArt &gt; 0 THEN
    DELETE FROM TMP_JC_AUX1;
    LIST_EXECUTE_IMMEDIATE(sInsAux1, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sUpdate1, aListID, aListVer);
  END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect5, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_jurnCump;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_JURNVANZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1FCD01364BB114C03284D0BCC4B74F6193C0AA0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_JURNVANZ IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vAnLunaIni  INTEGER;
  vAnLunaFin  INTEGER;
  vAnLista    INTEGER;
  vLunaLista  INTEGER;
  vDataIni    DATE;
  vDataFin    DATE;
  vSubunit    NUMBER(20);
  vTip        NUMBER(1);
  bExclNEA    BOOLEAN;

  sDRTVAInc   VARCHAR2(300);

PROCEDURE SetPerioada (pAn NUMBER, pLuna NUMBER, pTip INTEGER, pSubunit NUMBER DEFAULT NULL, pExclNoEconomicActiv BOOLEAN DEFAULT FALSE) IS
  vLunaIni NUMBER(4);
BEGIN
  vAnLista   := pAn;
  vLunaLista := pLuna;
  vAnLunaFin := pAn*12+pLuna;
  vTip       := pTip;
  IF    pTip = 3/*anual      */ THEN vLunaIni := 1;
  ELSIF pTip = 2/*semestrial */ THEN vLunaIni := CASE WHEN pLuna &gt; 6 THEN 7 ELSE 1 END;
  ELSIF pTip = 1/*trimestrial*/ THEN vLunaIni := CASE WHEN pLuna &gt; 9 THEN 10 WHEN pLuna &gt; 6 THEN 7 WHEN pLuna &gt; 3 THEN 4 ELSE 1 END;
  ELSIF pTip = 0/*lunar      */ THEN vLunaIni := pLuna;
  END IF;
  vAnLunaIni := pAn*12+vLunaIni;
  vDataIni   := To_Date( To_Char(pAn,&apos;fm0000&apos;)||&apos;.&apos;||To_Char(vLunaIni,&apos;fm00&apos;), &apos;yyyy.mm&apos; );
  vDataFin   := Last_Day(To_Date( To_Char(pAn,&apos;fm0000&apos;)||&apos;.&apos;||To_Char(pLuna,&apos;fm00&apos;), &apos;yyyy.mm&apos; ));
  vSubunit   := Coalesce(pSubunit,PKG_GLOBALS.GETSUBUNITATE);
  bExclNEA   := pExclNoEconomicActiv;

  UMPLE_TMP_AL_CURSLINIE(vAnLunaIni, vAnLunaFin);
END;

FUNCTION  GetAnLunaIni RETURN NUMBER IS
BEGIN
  RETURN vAnLunaIni;
END;

FUNCTION  GetAnLunaFin RETURN NUMBER IS
BEGIN
  RETURN vAnLunaFin;
END;

FUNCTION  GetDataIni RETURN DATE IS
BEGIN
  RETURN vDataIni;
END;

FUNCTION  GetDataFin RETURN DATE IS
BEGIN
  RETURN vDataFin;
END;

FUNCTION  GetAnLista   RETURN NUMBER IS
BEGIN
  RETURN vAnLista;
END;

FUNCTION  GetLunaLista RETURN NUMBER IS
BEGIN
  RETURN vLunaLista;
END;

FUNCTION getStinsDoc(pCodObligPif IN NUMBER, pAL IN NUMBER) RETURN NUMBER IS
  vTrezor  NUMBER;
  vCEC     NUMBER;
  vCompens NUMBER;
  vLitig   NUMBER;
BEGIN
  SELECT Coalesce(SUM(O_STINGATOR.VALOARE),0)
  INTO vTrezor
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0 AND T1.AN * 12 + T1.LUNA &lt; pAL;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE),0)
  INTO vCEC
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN TREZOR1  T1          ON T1.CODTREZOR1           = G_STINGATOR.CODDOC
    INNER JOIN GENERAL  G_CEC       ON G_CEC.TIPDOC            = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600)
    INNER JOIN OBLIGPIF O_CEC       ON O_CEC.CODGENERAL        = G_CEC.CODGENERAL
    INNER JOIN STINGERE S_CEC       ON S_CEC.CODSTINSPIF       = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT    ON O_CURENT.CODOBLIGPIF    = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL  G_CURENT    ON G_CURENT.CODGENERAL     = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN TREZOR1  T1_CURENT   ON T1_CURENT.CODTREZOR1    = G_CURENT.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0
    AND T1.AN * 12 + T1.LUNA &lt; pAL
    AND T1_CURENT.AN * 12 + T1_CURENT.LUNA &lt; pAL;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE),0)
  INTO vCompens
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL  = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
    INNER JOIN COMPENS  C           ON C.CODCOMPENS            = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND C.AN * 12 + C.LUNA &lt; pAL;

  vLitig := 0;
  FOR lREC IN (
    SELECT OL.CodObligPif, OL.VALOARE
    FROM OBLIGPIF OL
      INNER JOIN GENERAL GL ON GL.CODGENERAL = OL.CODGENERAL
      INNER JOIN COMPENS CL ON CL.CODCOMPENS = GL.CODDOC
    WHERE OL.CODOBLIGASOCIAT = pCodObligPif AND OL.SEMNIFICATIE = 1303 AND CL.AN * 12 + CL.LUNA &lt; pAL
  ) LOOP
    vLitig := vLitig + lREC.VALOARE;
    vLitig := vLitig - PKG_LIST_BASE_JURNVANZ.getStinsDoc(lREC.CodObligPif, pAL);
  END LOOP;

  RETURN vTrezor + vCEC + vCompens - vLitig;
END;

PROCEDURE pregateste_TMP_LST_TVAINCAS (aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsAux1 CLOB;
  sInsAux2 CLOB;
  sDebug   CLOB;
BEGIN
  sDebug := &apos;BEGIN&apos;||Chr(10)||
            &apos;  pkg_list_base_jurnvanz.SetPerioada(&apos;||vAnLista||&apos;,&apos;||vLunaLista||&apos;,&apos;||vTip||&apos;,&apos;||vSubunit||&apos;);&apos;||Chr(10)||
            &apos;END;&apos;;
  PKG_GLOBALS.CheckDebugMode(sDebug, aLISTID, aLISTVER);

  sInsAux1 :=
  &apos;INSERT INTO TMP_LST_TVAINCAS(
    coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, valstinsa, datastop, coeftva, tipstingere, prefixstingere, nrstingere,
    coefdoc, orddoc, countdoc, coefplata, restdoc)
  WITH
  II AS ( -- exista cazuri mai dubioase pet facturile din initializate cu cecuri in cecuri in curs din initializare can valdoc nu e real, e rest de incasat
    SELECT I.CODIES, Sum(I1.PU*I1.CANT+Coalesce(I1.TVA,0)) ValDoc
    FROM IESIRI I INNER JOIN IESIRI1 i1 ON I1.CODIES = I.CODIES
    WHERE I.INITIALIZARI = 1
    GROUP BY I.CODIES
  ),
  S AS (
    SELECT
      I.CODIES, I.TIPDOC, Coalesce(II.VALDOC,I.VALDOC) VALDOC,
      SUM( PKG_LIST_BASE_JURNVANZ.getStinsDoc(O.CODOBLIGPIF, &apos;||vAnLunaIni||&apos;) * CASE WHEN O.VALOARE &lt; 0 THEN -1 ELSE 1 END ) STINSDOC
    FROM IESIRI I
      INNER JOIN GENERAL  G ON G.CODDOC     = I.CODIES AND G.TIPDOC = I.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      LEFT  JOIN II         ON II.CODIES    = I.CODIES
    WHERE I.AN*12+I.LUNA &lt; &apos;||vAnLunaIni||&apos;
      AND I.TVAINCASARE = 1
      AND I.TIPDOC IN (19, 26)
      AND Coalesce(II.VALDOC, I.VALDOC) &lt;&gt; 0
      AND G.DataTVA &gt;= To_Date(&apos;&apos;&apos;||sDRTVAInc||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND NOT EXISTS (SELECT 1 FROM TMP_PER_TVAColectat T WHERE G.DataTVA BETWEEN T.Data1 AND T.Data2) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
    GROUP BY I.CODIES, I.TIPDOC, Coalesce(II.VALDOC,I.VALDOC)),
  TVAI AS (
    SELECT
      CODDOC, TIPDOC, NRDOC, PREFIXDOC, SERIADOC, DATADOC, DATASTINGERE, VALSTINSA, DATASTOP, COEFTVA, TIPSTINGERE, PREFIXSTINGERE, NRSTINGERE,
      Row_Number() OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE) OrdDoc,
      COUNT(1) OVER (PARTITION BY CODDOC, TIPDOC) CountDoc,
      SUM(CoefTva) OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE ROWS UNBOUNDED PRECEDING) CoefPlata
    FROM TMP_TVAINCAS
    WHERE COEFTVA &lt;&gt; 0)
  SELECT
    S.CODIES, S.TIPDOC, TVAI.NRDOC, TVAI.PREFIXDOC, TVAI.SERIADOC, TVAI.DATADOC, TVAI.DATASTINGERE, TVAI.VALSTINSA, TVAI.DATASTOP, TVAI.COEFTVA, TVAI.TIPSTINGERE, TVAI.PREFIXSTINGERE, TVAI.NRSTINGERE,
    1 - (S.STINSDOC/S.VALDOC) COEFDOC, TVAI.ORDDOC, TVAI.COUNTDOC, Coalesce(TVAI.COEFPLATA,0), ABS(S.VALDOC-S.STINSDOC)
  FROM S LEFT JOIN TVAI ON TVAI.CODDOC = S.CODIES AND TVAI.TIPDOC = S.TIPDOC&apos;;

  sInsAux2 :=
  &apos;INSERT INTO TMP_LST_TVAINCAS(
    CodDoc, TipDoc, NrDoc, PrefixDoc, SeriaDoc, DataDoc, DataStingere, ValStinsa, DataStop, CoefTVA, TipStingere, PrefixStingere, NrStingere,
    CoefDoc,
    OrdDoc,
    CountDoc,
    CoefPlata)
  SELECT
    CodDoc, TipDoc, NrDoc, PrefixDoc, SeriaDoc, DataDoc, DataStingere, ValStinsa, DataStop, CoefTVA, TipStingere, PrefixStingere, NrStingere,
    1 CoefDoc,
    Row_Number() OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE) OrdDoc,
    COUNT(1) OVER (PARTITION BY CODDOC, TIPDOC) CountDoc,
    SUM(CoefTva) OVER (PARTITION BY CODDOC, TIPDOC ORDER BY DATASTINGERE ROWS UNBOUNDED PRECEDING) CoefPlata
  FROM TMP_TVAINCAS
  WHERE COEFTVA &lt;&gt; 0&apos;;

  sDebug := &apos;
  BEGIN
    DELETE TMP_LST_TVAINCAS;
    DELETE TMP_JURNAL1;
    DELETE TMP_TVAINCAS;&apos;;

  sDebug :=
    &apos;BEGIN&apos;||Chr(10)||
    &apos;  DELETE TMP_LST_TVAINCAS;&apos;||Chr(10)||
    &apos;  DELETE TMP_JURNAL1;&apos;||Chr(10)||
    &apos;  DELETE TMP_TVAINCAS;&apos;;
  IF vAnLista &gt; 2012 THEN
    sDebug := sDebug||Chr(10)||
    &apos;  PKG_INCHIDERI.MAKE_TMP_StingereTVACole(1);&apos;||Chr(10)||
    &apos;  PKG_INCHIDERI.MAKE_TMP_InchidereTVACole(1);&apos;||Chr(10)||Chr(10)||

    &apos;  DELETE TMP_TVAINCAS T WHERE NOT EXISTS (SELECT J1.CODDOC FROM TMP_JURNAL1 J1 WHERE J1.TIPDOC = T.TIPDOC AND J1.CODDOC = T.CODDOC);&apos;||Chr(10)||Chr(10)||

    &apos;  UPDATE TMP_TVAINCAS SET TIPSTINGERE = -81 WHERE TIPSTINGERE = 81;&apos;||Chr(10)||Chr(10)||

    &apos;  INSERT INTO TMP_TVAINCAS(coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, valstinsa, datastop, coeftva, tipstingere, prefixstingere, nrstingere)&apos;||Chr(10)||
    &apos;  SELECT coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, Sum(valstinsa), datastop, Sum(coeftva), -tipstingere, prefixstingere, nrstingere&apos;||Chr(10)||
    &apos;  FROM TMP_TVAINCAS&apos;||Chr(10)||
    &apos;  WHERE TIPSTINGERE = -81&apos;||Chr(10)||
    &apos;  GROUP BY coddoc, tipdoc, nrdoc, prefixdoc, seriadoc, datadoc, datastingere, datastop, tipstingere, prefixstingere, nrstingere;&apos;||Chr(10)||Chr(10)||

    &apos;  DELETE TMP_TVAINCAS WHERE TIPSTINGERE = -81;&apos;||Chr(10)||Chr(10)||

    &apos;  &apos;|| sInsAux1 ||&apos;;&apos;||Chr(10)||Chr(10)||

    &apos;  DELETE TMP_TVAINCAS     WHERE CODDOC IN (SELECT CODDOC FROM TMP_LST_TVAINCAS);&apos;||Chr(10)||Chr(10)||

    &apos;  DELETE TMP_LST_TVAINCAS WHERE COEFPLATA = 0 AND RESTDOC &lt; 0.01;&apos;||Chr(10)||Chr(10)||

    &apos;  &apos;|| sInsAux2 ||&apos;;&apos;;
  END IF;
  sDebug := sDebug||Chr(10)||
    &apos;END;&apos;;

  LIST_EXECUTE_IMMEDIATE(sDebug, aListID, aListVer);
END;

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sSelWith        CLOB;

  sSelTranz1      CLOB;
  sSelTranz2      CLOB;
  sSelTranz3      CLOB;
  sSelTranz4      CLOB;
  sSelTranz5      CLOB;
  sSelTranz6      CLOB;

  sSelTranzX      CLOB;

  sInsert         CLOB;
  sSelA           CLOB;
  sSelX           CLOB;
  sTIPTVADOC      CLOB;
  sCondLuna       VARCHAR2(200);
  vISIVB          BOOLEAN;
  vCodTvaImplicit NUMBER;
  sPjTva          VARCHAR2(3);

  sIDisc          CLOB;
  sXDisc          CLOB;

  auxWhere        VARCHAR2(100);
  sWhere          VARCHAR2(10000) := &apos;&apos;;
  cModEditJurn    NUMBER;
  vTVA0FaraJurnal VARCHAR2(10000);
  sFiltruCodArt   CLOB;
  vCountArt       NUMBER := 0;
  vZileTVAInc     INTEGER;

  vCountDebug     INTEGER;

  TYPE t_tab_codies IS TABLE OF NUMBER(20);
  bulk_codies t_tab_codies;
BEGIN
  --PKG_GLOBALS.SETDEBUGMODE(TRUE);
  sTIPTVADOC := &apos;,
    CASE
      WHEN Coalesce(intr.tiptva, 0) = 1 THEN &apos;&apos;Taxare normala&apos;&apos;
      WHEN Coalesce(intr.tiptva, 0) = 2 THEN &apos;&apos;Taxare inversa&apos;&apos;
      WHEN Coalesce(intr.tiptva, 0) = 3 THEN &apos;&apos;Tranzactie triunghiulara&apos;&apos;
      WHEN Coalesce(intr.tiptva, 0) = 4 THEN &apos;&apos;Suspendare temporara&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 1 THEN &apos;&apos;Taxare normala&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 2 THEN &apos;&apos;Taxare inversa&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 3 THEN &apos;&apos;Taxare triunghiulara&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 4 THEN &apos;&apos;Prestari in afara Romaniei&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 5 THEN &apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 6 THEN &apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;
      WHEN Coalesce(ies.tiptva,  0) = 7 THEN &apos;&apos;regim special(art.1521, 1522)&apos;&apos;
      ELSE NULL
    END TIPTVADOC &apos;;

  gSuplCols := &apos;NPART NP, NPARTCODFISC FISCD, NPARTCODFISC FISCP, NCONT N, NSUBUNIT SUB, NAGENDA SDOC, NAGENDA SSOC, NLOCALIT L, NTARI T, DOCCARNETE DC, INTRARI INTR, IESIRI IES&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  pkg_globals.SetSeparator(&apos;,&apos;);

  PRC_AL_CHECK(&apos;NSUBUNIT1&apos;);
  IF (aLISTID &gt; 0 OR tmpName &lt;&gt; &apos;TMP_JV_D300&apos;) THEN
    vSubunit := PKG_GLOBALS.GETSUBUNITATE;
    BEGIN
      SELECT Coalesce(ModEditareJurnal, 0)
      INTO cModEditJurn
      FROM NSUBUNIT1
      WHERE CodSubunit = vSubunit AND pkg_globals.AnLunaLucru BETWEEN ALSTART and ALSTOP;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN cModEditJurn := 0;
    END;
    cModEditJurn := Coalesce(cModEditJurn,0);
    IF cModEditJurn = 0 THEN
      cModEditJurn := pkg_categconst.GetValConstanta(&apos;ModEditareJurnal&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU);
      cModEditJurn := Coalesce(cModEditJurn,0);
    END IF;

    vTip := CASE WHEN cModEditJurn = 2 AND Mod(pkg_globals.GetLUNALUCRU,3) = 0 THEN 1 ELSE 0 END;
    SetPerioada(pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU,vTip,vSubunit);
  END IF;

  vTVA0FaraJurnal := Coalesce(pkg_categconst.GetValConstanta(&apos;TVA0FaraJurnal&apos;,     vAnLista,vLunaLista),&apos;-1&apos;);
  vISIVB          := Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos;,vAnLista,vLunaLista), &apos;0&apos;) = &apos;1&apos;;
  vCodTvaImplicit := Coalesce(pkg_categconst.GetValConstanta(&apos;TIPTVAImplicit&apos;,     vAnLista,vLunaLista), &apos;0&apos;);
  SELECT To_Char(Coalesce(Max(PROCENT),0)) INTO sPjTva FROM NTVA1 WHERE CODTVA = vCodTvaImplicit AND vAnLista*12+vLunaLista BETWEEN ALSTART AND ALSTOP;
  IF vTVA0FaraJurnal &lt;&gt; &apos;-1&apos; THEN
    IF vAnLunaIni = vAnLunaFin
    THEN sCondLuna := &apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; BETWEEN ALSTART AND ALSTOP&apos;;
    ELSE sCondLuna := &apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos; &gt;= ALSTART AND &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; &lt;= ALSTOP&apos;;
    END IF;

    DELETE FROM TMP_MANEVRA;
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO TMP_MANEVRA SELECT DISTINCT CodArticol FROM NART1 WHERE CodTva IN (&apos;||vTVA0FaraJurnal||&apos;)&apos;||sCondLuna, aListID, aListVer);
    FOR vRec IN (SELECT CodUnic FROM TMP_MANEVRA) LOOP
      IF vCountArt = 0
      THEN sFiltruCodArt := To_Char(vrec.CodUnic);
      ELSE sFiltruCodArt := sFiltruCodArt||&apos;,&apos;||To_Char(vrec.CodUnic);
      END IF;
      vCountArt := vCountArt + 1;
    END LOOP;
    IF vCountArt &gt; 0 THEN
      sFiltruCodArt := &apos;
      AND NOT Coalesce(o.CodArticol, 0) IN (&apos;||sFiltruCodArt||&apos;)&apos;;
    ELSE
      sFiltruCodArt := &apos;&apos;;
    END IF;
  END IF;

  auxWhere := &apos;
  WHERE &apos;;

  IF bExclNEA THEN
    sWhere := sWhere||auxWhere ||&apos;Coalesce(SUB.NoEconomicActiv, 0) = 0&apos;;
    auxWhere := &apos;
    AND &apos;;
  END IF;

  IF vAnLunaIni = vAnLunaFin
  THEN sCondLuna := &apos;= &apos;||vAnLunaFin;
  ELSE sCondLuna := &apos;BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin;
  END IF;

  sIDisc :=&apos;
  SELECT DISTINCT i.codies
  FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE I.TIPDOC IN (16,19,26) AND Coalesce(I.INFOCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.TIPFACTURA,0) &lt;&gt; 7 AND BITAND(Coalesce(i.Flags, 0), 1) = 0
    AND I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)
    AND Coalesce(I1.TVA,0) &lt;&gt; 0
    AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos;
    AND NOT EXISTS (SELECT J1.CODDOC FROM TMP_JURNAL1 J1 WHERE J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODIES) &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ;

  sXDisc :=&apos;
  SELECT DISTINCT i.codies
  FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
  WHERE I.TIPDOC IN (16,19,26) AND Coalesce(I.INFOCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.TIPFACTURA,0) &lt;&gt; 7 AND BITAND(Coalesce(i.Flags, 0), 1) = 0
    AND I.CODIES IN (SELECT DISTINCT CODDOC FROM TMP_LST_TVAINCAS WHERE TIPDOC IN (16,19,26))
    AND I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CODDOC,NAV_CodDoc1,NAV_TIPDOC,ORDDOC,
    DATADOC,NRDOC,NRI,PREFIXDOC,SERIADOC,
    DEN_PART,
    CODFISCAL,
    VALDOC,
    BAZA_MED,    TVA_MED,
    BAZA_MIN,    TVA_MIN,
    BAZA_MAX,    TVA_MAX,
    BAZA_REGMIN, TVA_REGMIN,
    BAZA_REGMAX, TVA_REGMAX,
    BAZA_REG,    TVA_REG,
    BAZA_REG2,   TVA_REG2,
    BAZA_REG3,   TVA_REG3,
    BAZA_REG4,   TVA_REG4,
    BAZA_REG5,   TVA_REG5,
    BUNURI_CU_TI, TVA_BUNURI_CU_TI,
    BUNURI_CU_TI_BMED, BUNURI_CU_TI_TMED,
    BUNURI_CU_TI_BMIN, BUNURI_CU_TI_TMIN,
    BUNURI_CU_TI_BMAX, BUNURI_CU_TI_TMAX,
    BUNURI_CU_TI_BREG, BUNURI_CU_TI_TREG,
    BUNURI_CU_TI_BREG2,BUNURI_CU_TI_TREG2,
    BUNURI_CU_TI_BREG3,BUNURI_CU_TI_TREG3,
    BUNURI_CU_TI_BREG4,BUNURI_CU_TI_TREG4,
    BUNURI_CU_TI_BREG5,BUNURI_CU_TI_TREG5,
    NONRO_DED,   SERV_NONRO_DED,
    NONRO_NONDED,SERV_NONRO_NONDED,
    RO_DED,RO_NONDED,
    A_1521_22, TVA_A_311_322, A_311_322_BMED, A_311_322_TMED, A_311_322_BMIN, A_311_322_TMIN, A_311_322_BMAX, A_311_322_TMAX,
    ART143AD, ART143BC, SERV143BC,
    ART294AB, ART294CD,
    ART292,
    BAZA_SERV_278, TVA_SERV_278,
    BAZA_OSS, TVA_OSS,
    OPER_NEIMP, OBS,
    SUBUNITATEA,UE,TI,DATACDOC,OPERATOR,ANDOC,LUNADOC,TVALAINC,
    RESTOL,
    BAZAOBLIG,
    TVANOBLIG,
    INCPREFIX, INCTIP, INCNR, INCDATA,
    INCVAL, INCVFT, INCTVA,
    RESTVAL, RESTTVA,
    SOLDVAL,
    SOLDTVA,
    DOCVAL, DOCBAZA, DOCTVA,
    TIPTVADOC &apos;||gUserFields||&apos;)&apos;;
  -- STEF -- orice adaugare de camp trebuie sa se adauge si in TMP_JV_D300

  sSelWith := &apos;
  WITH
  CRS_JV_TRANZACTII AS (&apos;;

  sSelTranz1 := &apos;
    SELECT
      I1.codies coddoc, NULL coddoc1, I.tipdoc, I.datadoc, I.nrdoc, I.Nri, I.prefixdoc, I.carnetdoc, I.seriadoc, I.partener, I.codlocatie, I.codfiscal, CASE WHEN I.tipdoc IN (19, 26) THEN Coalesce(i.tvaincasare,0) ELSE 0 END tvainc,
      Coalesce(
        CASE
          WHEN I.TIPTVA IN (7,8) AND I.AN*12+I.LUNA&gt;=2016*12+7 AND I.TIPDOC = 19
          THEN (
            SELECT SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0))
            FROM livr1 l1
              INNER JOIN livr    l  ON l1.codlivr    = l.codlivr
              LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
              LEFT  JOIN livrval lv ON lv.codlivr1   = l1.codlivr1
            WHERE L1.CODIES1 = I1.CODIES1 AND L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
          )
          WHEN I.TIPTVA IN (7,8) AND I.AN*12+I.LUNA&gt;=2016*12+7 AND I.TIPDOC = 26
          THEN (
            SELECT SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0))
            FROM ieslink ilae
              INNER JOIN iesiri1 ae1  ON ae1.codies1   = ilae.codlinieaviz
              INNER JOIN livr1   l1   ON l1.codies1    = ae1.codies1
              INNER JOIN livr    l    ON l.codlivr     = l1.codlivr AND l.codies = ae1.codies AND l.tiplivr = 20
              LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
              LEFT  JOIN livrval lv   ON lv.codlivr1   = l1.codlivr1
            WHERE ilae.codies1  = i1.codies1
          )
          ELSE 0
        END, 0
      ) VA_311_312,
      CASE
        WHEN I.TIPDOC IN (14)    THEN L1.BAZA
        WHEN I.TIPDOC IN (16,21) THEN Coalesce(I1.VALFIN,I1.CANT*I1.PU,0) - Coalesce(I1.TVAFIN,I1.TVA,0)
        ELSE                          Coalesce(I1.VALFIN,I1.CANT*I1.PU,0)
      END *
      CASE WHEN I1.VALFIN IS NULL THEN 1+Coalesce(i1.procdisc/100,0) ELSE 1 END *
      Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) baza,
      CASE
        WHEN I.TipDoc = 14 AND L1.NR_L1 = 1 THEN Coalesce(I1.TVA,0)
        WHEN I.TipDoc = 14 AND L1.NR_LX = 0 THEN Coalesce(I1.TVA,0)
        WHEN I.TipDoc = 14 AND L1.BAZATOT &lt;&gt; 0 THEN Coalesce(I1.TVA,0) * L1.Baza/L1.BAZATOT
        WHEN I.TipDoc = 14 THEN Coalesce(I1.TVA,0)/L1.NR_L1
        ELSE Coalesce(I1.TVAFIN, I1.TVA,0)
      END *
      CASE WHEN I1.VALFIN IS NULL THEN 1+Coalesce(i1.procdisc/100,0) ELSE 1 END *
      Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) tva,
      PKG_LIST_BASE_UTILS.MATCH_TVA(
        CASE
          WHEN I.TIPDOC = 14                AND L1.Baza = 0               THEN &apos;||sPjTva||&apos;
          WHEN I.TipDoc = 14                AND L1.NR_L1 = 1              THEN Coalesce(I1.TVA,0) * 100 /L1.BAZA
          WHEN I.TipDoc = 14                AND L1.BAZATOT &lt;&gt; 0           THEN Coalesce(I1.TVA,0) * 100 /L1.BAZATOT
          WHEN I.TIPDOC = 14                                              THEN Coalesce(I1.TVA,0)/L1.NR_LX * 100 / L1.BAZA
          WHEN I.TIPTVA IN (7,8)            AND I.AN*12+I.LUNA&gt;=2016*12+7 THEN T1.PROCENT
          ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT)
        END,
        &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
      ) CAZTVA,
      i1.tiplinie, Coalesce(i1.taxa, 0) taxa,
      CASE WHEN I.tipdoc = 14 AND Coalesce(I1.TVA,0)&lt;&gt;0 THEN 1 ELSE I.tiptva        END tiptva,
      CASE WHEN I.tipdoc = 14 AND Coalesce(I1.TVA,0)&lt;&gt;0 THEN 1 ELSE I.tiptranzactie END tiptranzactie,
      CASE
        WHEN (Coalesce(I1.TVA,0) = 0) AND (I1.tiplinie IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;)) THEN PKG_LIST_BASE_UTILS.getTipTVA0(I1.codobiect,I.an,I.luna)
        ELSE 0
      END TIPTVA0,
      CASE
        WHEN I.TIPDOC = 14 THEN SUM( (L1.BAZATOT + Coalesce(I1.TVA,0)) / l1.nr_l1) OVER (PARTITION BY I.CODIES)
        ELSE &apos;||CASE
                  WHEN vCountArt = 0
                  THEN &apos;I.VALDOC&apos;
                  ELSE &apos;Sum((I1.CANT*I1.PU+Coalesce(I1.TVA,0)) * I1.COEFDISCMAJ * CASE WHEN I1.PU = 0 THEN 0 WHEN I1.PU = I1.PRETORIG THEN 1 ELSE I1.PRETORIG / I1.PU END) OVER (PARTITION BY I.CODIES)&apos;
                END||&apos;
      END * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) valdoc,
      i.obs, 0 codcont, i.subunitatea, i.datacreare, i.userid, i.an, i.luna,
      i.valdoc            * Coalesce(NULLIF(I.Curs,0),1) docval,
      (i.valdoc-i.tvadoc) * Coalesce(NULLIF(I.Curs,0),1) docbaza,
      i.tvadoc            * Coalesce(NULLIF(I.Curs,0),1) doctva,
      CASE WHEN CL.VAL = 1 THEN 1 ELSE 0 END calc,
      0 CAZ_B_CU_TI,
      &apos;||CASE WHEN vISIVB THEN &apos;Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codies)&apos; ELSE &apos;0&apos; END||&apos; DoServCaStoc,
      CASE
        WHEN I1.tiplinie &lt;&gt; &apos;&apos;V&apos;&apos;
        THEN I1.tiplinie
        ELSE
          CASE Max(CASE WHEN I1.tiplinie = &apos;&apos;S&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codies) +
               Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 2 ELSE 0 END) OVER (PARTITION BY i.codies)
            WHEN 1 THEN &apos;&apos;S&apos;&apos;
            WHEN 2 THEN I1.tiplinie
            WHEN 3 THEN &apos;||CASE WHEN vISIVB THEN &apos;I1.tiplinie&apos; ELSE &apos;&apos;&apos;B&apos;&apos;&apos; END ||&apos;
            ELSE I1.tiplinie
          END
      END TipLinieEXTRA,
      CASE WHEN Coalesce(i.an*100+i.luna, 0) = To_Number(Coalesce(To_Char(Coalesce(i.datatva, i.datadoc), &apos;&apos;yyyymm&apos;&apos;),&apos;&apos;0&apos;&apos;)) THEN 0 ELSE 1 END DOC_REG
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies     = i.codies
      LEFT  JOIN iesiri1 i1st ON i1st.codies1  = i1.codies1storno
      LEFT  JOIN iesiri  ist  ON ist.codies    = i1st.codies
      LEFT  JOIN nartobj o    ON o.codobiect   = i1.codobiect
      LEFT  JOIN nart1   a1   ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT  JOIN ntva1   t1   ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      LEFT  JOIN (
        SELECT
          I.NrDoc, I.CodIes, L1.Codies1, L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0) BAZA,
          SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0)) OVER (PARTITION BY I.CodIes, L1.Codies1) BAZATOT,
          SUM(CASE WHEN Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0) = 0 THEN 0 ELSE 1 END) OVER (PARTITION BY I.CodIes, L1.Codies1) NR_LX,
          COUNT(1) OVER (PARTITION BY I.CodIes, L1.Codies1) NR_L1
        FROM IESIRI I
          INNER JOIN LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
          INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
          LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
        WHERE I.TIPDOC = 14 AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      ) L1 ON L1.CODIES1 = I1.CODIES1 AND L1.Codies = I1.CODIES
      LEFT  JOIN (
        SELECT I.CodIes, SUM(Coalesce(i1.valdiscpret, 0)) valdisclin
        FROM IESIRI I INNER JOIN IESIRI1 I1 ON i1.codies = i.codies
        WHERE I.TIPDOC = 16 AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
        GROUP BY I.CodIes
      ) MD ON MD.CODIES = I.CODIES
      LEFT  JOIN tmp_al_curslinie cl ON cl.AL = i.an*12+i.luna
    WHERE Coalesce(I.INFOCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.TIPFACTURA,0) &lt;&gt; 7
      AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit)||
      sFiltruCodArt||&apos;
      AND NOT EXISTS (SELECT J1.CODDOC FROM TMP_JURNAL1 J1 WHERE J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODIES)
      AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;)
      AND I.TIPDOC IN (14,16,19,21,22,26)
      AND CASE I.TIPDOC WHEN 14 THEN Coalesce(I1.TVA,0) ELSE 1 END &lt;&gt; 0
      AND CASE I.TIPDOC WHEN 14 THEN L1.NR_L1           ELSE 1 END &lt;&gt; 0
      AND TO_CHAR(Coalesce(I1.CODOBIECT,-100)) &lt;&gt; CASE WHEN I.TIPDOC = 16 THEN Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;&apos;ArtIncasUlterior&apos;&apos;,I.AN,I.LUNA),&apos;&apos;0&apos;&apos;) ELSE &apos;&apos;0&apos;&apos; END
      AND NOT I.CODIES IN (SELECT DISTINCT CODDOC FROM TMP_LST_TVAINCAS WHERE TIPDOC IN (14,16,19,21,22,26))
      AND Coalesce(i.tiptranzactie, 0) &lt;&gt; 5 AND Coalesce(i1.impozabil, 0) &lt;&gt; 4&apos;;

  sSelTranz2 := &apos;
    SELECT
      I1.codintr coddoc, NULL coddoc1, I.tipdoc, I.datadoc, I.nrdoc, I.nri, I.prefixdoc, I.carnetdoc, I.seriadoc, I.partener, I.codlocatie, I.codfiscal, CASE WHEN I.tipdoc IN (1, 9) THEN Coalesce(i.tvaincasare,0) ELSE 0 END tvainc,
      0 VA_311_312,
      CASE
        WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;)    THEN Coalesce(D1.VALOARETAXA,0)
        WHEN I.TIPDOC = 5 AND I.TIPTRANZACTIE = 2                     THEN Coalesce(D1.CANT * D1.PRETIMPORT,0)
        WHEN I.TIPDOC = 5                                             THEN Coalesce(D1.CANT * D1.PRETIMPORT,0)
        WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                             THEN (I1.RESTFACT - Coalesce(CASE WHEN I.TIPDOC= 3 THEN Coalesce(I1.TVA,0) END, 0))*Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1)
        ELSE (Coalesce(I1.PU*I1.CANT,0)-Coalesce(CASE WHEN I.TIPDOC=3 THEN Coalesce(I1.TVA,0) END,0)) * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1)
      END BAZA,
      CASE WHEN I.TIPDOC = 5 THEN Coalesce(d1.TVA,0) ELSE Coalesce(I1.TVA,0) * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) END tva,
      PKG_LIST_BASE_UTILS.MATCH_TVA(
        CASE
          WHEN I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;) AND (I1.CANT * Coalesce(I1.PU,0) = 0)               THEN T1.PROCENT
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)             AND Coalesce(I1.RESTFACT,0) = 0                     THEN &apos;||sPjTva||&apos;
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                                                                 THEN Coalesce(I1.TVA,0)/I1.RESTFACT*100
          WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) AND Coalesce(D1.VALOARETAXA,0) = 0     THEN &apos;||sPjTva||&apos;
          WHEN I.TIPDOC = 5 AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;)                                        THEN Coalesce(d1.TVA,0)/ D1.VALOARETAXA*100
          WHEN I.TIPDOC = 5 AND Coalesce(D1.CANT * D1.PRETIMPORT,0) = 0                                     THEN T1.PROCENT
          WHEN I.TIPDOC = 5                                                                                 THEN Coalesce(d1.TVA,0) / (D1.CANT * D1.PRETIMPORT) *100
          ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT)
        END,
        &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
      ) CAZTVA,
      i1.tiplinie, 0 taxa, 2 TIPTVA, I.tiptranzactie, 0 tiptva0,
      CASE
        WHEN I.VALDOC = 0 THEN 1&apos;||
      CASE
        WHEN vCountArt &lt;&gt; 0 THEN &apos;&apos;
        ELSE &apos;
        WHEN I.TIPTVA IN (2,8) THEN 1&apos;
      END ||&apos;
        ELSE Sum( (I1.CANT*I1.PU+Coalesce(I1.TVA,0)) * I1.COEFDISCMAJ * CASE WHEN I1.PU = 0 THEN 0 WHEN I1.PU = I1.PRETORIG THEN 1 ELSE I1.PRETORIG / I1.PU END) OVER (PARTITION BY I.CODINTR)/I.VALDOC
      END *
      (I.VALDOC * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) + CASE WHEN Coalesce(I.TIPTRANZACTIE, 0) = 2 THEN Coalesce(d.TVADOCVAMA,0) ELSE Coalesce(d.VALSUPLIM,0) + Coalesce(d.VALDOCVAMA,0) END) valdoc,
      i.obs,0 codcont, i.subunitatea, i.datacreare, i.userid, i.an, i.luna,
      i.valdoc            * Coalesce(NULLIF(I.Curs,0),1) docval,
      (i.valdoc-i.tvadoc) * Coalesce(NULLIF(I.Curs,0),1) docbaza,
      i.tvadoc            * Coalesce(NULLIF(I.Curs,0),1) doctva,
      CASE WHEN CL.VAL = 1 THEN 1 ELSE 0 END calc,
      1 CAZ_B_CU_TI,
      &apos;||CASE WHEN vISIVB THEN &apos;Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codintr)&apos; ELSE &apos;0&apos; END||&apos; DoServCaStoc,
      CASE
        WHEN I1.tiplinie &lt;&gt; &apos;&apos;V&apos;&apos;
        THEN I1.tiplinie
        ELSE
          CASE Max(CASE WHEN I1.tiplinie = &apos;&apos;S&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codintr) +
               Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 2 ELSE 0 END) OVER (PARTITION BY i.codintr)
            WHEN 1 THEN &apos;&apos;S&apos;&apos;
            WHEN 2 THEN I1.tiplinie
            WHEN 3 THEN &apos;||CASE WHEN vISIVB THEN &apos;I1.tiplinie&apos; ELSE &apos;&apos;&apos;B&apos;&apos;&apos; END ||&apos;
            ELSE I1.tiplinie
          END
      END TipLinieEXTRA,
      CASE WHEN Coalesce(i.an*100+i.luna, 0) = To_Number(Coalesce(To_Char(Coalesce(i.datatva, i.datadoc), &apos;&apos;yyyymm&apos;&apos;),&apos;&apos;0&apos;&apos;)) THEN 0 ELSE 1 END DOC_REG
    FROM intrari i
      INNER JOIN intrari1 i1   ON I1.codintr    = I.codintr
      LEFT  JOIN intrari1 i1st ON i1st.codintr1 = i1.codintr1storno
      LEFT  JOIN intrari  ist  ON ist.codintr   = i1st.codintr
      LEFT  JOIN nartobj  o    ON o.codobiect   = i1.codobiect
      LEFT  JOIN nart1    a1   ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT  JOIN ntva1    t1   ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      LEFT  JOIN dvi1     d1   ON d1.codintr1   = i1.codintr1
      LEFT  JOIN dvi      d    ON d.codintr     = i.codintr
      LEFT  JOIN tmp_al_curslinie cl ON cl.AL = i.an*12+i.luna
    WHERE I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||
      sFiltruCodArt||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1
      AND (I.TIPTVA IN (2,8) OR Coalesce(i1.impozabil, 0) = 3)
      AND I.TIPDOC NOT IN (2,6)
      AND Coalesce(D.TIPIMPORT,0) = 0
      AND NOT (I.TIPTRANZACTIE = 4 AND I1.TIPLINIE NOT IN (&apos;&apos;G&apos;&apos;))
      AND NOT (Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I1.CONTDISCOUNT,0) = 0)
      AND NOT (Coalesce(I1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I1.RESTFACT,0) = 0)
      AND NOT (Coalesce(D1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) AND Coalesce(D.TAXEINCLUSE,0) = 1)
      AND NOT (Coalesce(D1.TIPLINIE,&apos;&apos;~&apos;&apos;) IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) AND Coalesce(D.TAXEPECHELT,0) = 1)
      AND Coalesce(i.tiptranzactie, 0) &lt;&gt; 5 AND Coalesce(i1.impozabil, 0) &lt;&gt; 4&apos;;

  sSelTranz3 := &apos;
    SELECT
      I.codintr coddoc, NULL coddoc1, I.tipdoc, I.datadoc, I.nrdoc, I.nri, I.prefixdoc, I.carnetdoc, I.seriadoc, I.partener, I.codlocatie, I.codfiscal, CASE WHEN I.tipdoc IN (1, 9) THEN Coalesce(i.tvaincasare,0) ELSE 0 END tvainc,
      0 VA_311_312,
      Coalesce(D1.VALOARETAXA,0) BAZA,
      Coalesce(d1.TVA,0) tva,
      PKG_LIST_BASE_UTILS.MATCH_TVA(CASE WHEN Coalesce(D1.VALOARETAXA,0) = 0 THEN &apos;||sPjTva||&apos; ELSE Coalesce(d1.TVA,0)/ D1.VALOARETAXA*100 END, &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;) CAZTVA,
      D1.tiplinie, 0 taxa, 2 TIPTVA, I.tiptranzactie, 0 tiptva0,
      (I.VALDOC * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) + CASE WHEN Coalesce(I.TIPTRANZACTIE, 0) = 2 THEN Coalesce(d.TVADOCVAMA,0) ELSE Coalesce(d.VALSUPLIM,0) + Coalesce(d.VALDOCVAMA,0) END) valdoc,
      i.obs,0 codcont, i.subunitatea, i.datacreare, i.userid, i.an, i.luna,
      i.valdoc            * Coalesce(NULLIF(I.Curs,0),1) docval,
      (i.valdoc-i.tvadoc) * Coalesce(NULLIF(I.Curs,0),1) docbaza,
      i.tvadoc            * Coalesce(NULLIF(I.Curs,0),1) doctva,
      CASE WHEN CL.VAL = 1 THEN 1 ELSE 0 END calc,
      1 CAZ_B_CU_TI,
      &apos;||CASE WHEN vISIVB THEN &apos;Max(CASE WHEN D1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codintr)&apos; ELSE &apos;0&apos; END||&apos; DoServCaStoc,
      CASE
        WHEN D1.tiplinie &lt;&gt; &apos;&apos;V&apos;&apos;
        THEN D1.tiplinie
        ELSE
          CASE Max(CASE WHEN D1.tiplinie = &apos;&apos;S&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codintr) +
               Max(CASE WHEN D1.tiplinie = &apos;&apos;=&apos;&apos; THEN 2 ELSE 0 END) OVER (PARTITION BY i.codintr)
            WHEN 1 THEN &apos;&apos;S&apos;&apos;
            WHEN 2 THEN D1.tiplinie
            WHEN 3 THEN &apos;||CASE WHEN vISIVB THEN &apos;D1.tiplinie&apos; ELSE &apos;&apos;&apos;B&apos;&apos;&apos; END ||&apos;
            ELSE D1.tiplinie
          END
      END TipLinieEXTRA,
      CASE WHEN Coalesce(i.an*100+i.luna, 0) = To_Number(Coalesce(To_Char(Coalesce(i.datatva, i.datadoc), &apos;&apos;yyyymm&apos;&apos;),&apos;&apos;0&apos;&apos;)) THEN 0 ELSE 1 END DOC_REG
    FROM intrari i
      INNER JOIN dvi      d    ON d.codintr     = i.codintr
      LEFT  JOIN dvi1     d1   ON d1.coddvi     = d.coddvi
      LEFT  JOIN intrari1 i1   ON i1.codintr1   = d1.codintr1 AND i1.codintr = i.codintr
      LEFT  JOIN nartobj  o    ON o.codobiect   = d1.codobiect
      LEFT  JOIN tmp_al_curslinie cl ON cl.AL = i.an*12+i.luna
    WHERE I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||
      sFiltruCodArt||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1
      AND I.TIPTVA IN (2,8)
      AND D1.TIPLINIE IN (&apos;&apos;X&apos;&apos;, &apos;&apos;A&apos;&apos;, &apos;&apos;C&apos;&apos;) AND Coalesce(D.TAXEINCLUSE,0) = 0 AND Coalesce(D.TAXEPECHELT,0) = 1
      AND d1.codintr1 IS NULL&apos;;

  sSelTranz4 := &apos;
    SELECT
      nc.codnc coddoc, NULL coddoc1, 35 tipdoc, nc.datadoc, nc.nrdoc, NULL nri, &apos;&apos;NC&apos;&apos; prefixdoc, nc.carnetdoc, NULL seriadoc, liniiNC.part as partener, 0 codlocatie, 0 codfiscal, 0 tvainc,
      0 VA_311_312,
      liniinc.baza * Coalesce(NULLIF(nc.curs,0),1) baza,
      liniinc.tva  * Coalesce(NULLIF(nc.curs,0),1) tva,
      CASE
        WHEN liniiNC.Scutit = 1 THEN 0
        ELSE PKG_LIST_BASE_UTILS.MATCH_TVA( CASE WHEN Coalesce(liniinc.baza, 0) = 0 THEN &apos;||sPjTva||&apos; ELSE liniinc.tva * 100/liniinc.baza END, &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;)
      END CAZTVA,
      NULL tiplinie, 0 taxa, nc.tiptva, nc.tiptranz as tiptranzactie, 0 tiptva0,
      ( LINIINC.BAZA * Coalesce(NULLIF(nc.curs,0),1)) + (LINIINC.TVA * Coalesce(NULLIF(nc.curs,0),1)) valdoc,
      nc.obs, 0 codcont, nc.subunitatea, nc.datacreare, nc.userid, nc.an, nc.luna,
      nc.valoare * Coalesce(NULLIF(nc.curs,0),1) DOCVAL, 0 DOCBAZA, 0 DOCTVA, 1 CALC,
      CASE WHEN nc.tiptva = 2 AND nc.tiptranz IN (2,3) THEN 1 ELSE 0 END CAZ_B_CU_TI,
      0 DoServCaStoc,
      &apos;&apos;~&apos;&apos; TipLinieEXTRA,
      0 DOC_REG
    FROM (
      SELECT X.CODNC, X.PART, X.SCUTIT, SUM(X.BAZA) baza, SUM(X.TVA) tva
      FROM (
        SELECT
          NC1.CODNC, Coalesce(NULLIF(NC.PART,0), NC1.CODPART) PART,
          CASE WHEN NC1.TIPLINIETVA IN (6)     THEN 1           ELSE 0 END SCUTIT,
          CASE WHEN NC1.TIPLINIETVA IN (2,4,6) THEN NC1.VALOARE ELSE 0 END BAZA,
          CASE WHEN NC1.TIPLINIETVA IN (3,5)   THEN NC1.VALOARE ELSE 0 END TVA
        FROM NC INNER JOIN NC1 ON nc.codnc = nc1.codnc
        WHERE NC.AN*12+NC.LUNA &apos;||sCondLuna||&apos;
          AND Coalesce(NC.SABLON,0) = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
          AND ((NC.JURNALTVA = 3) OR (NC.JURNALTVA = 2 AND NC.TIPTVA = 2))
      ) X
      GROUP BY X.CODNC, X.PART, X.SCUTIT
    ) liniiNC LEFT JOIN nc ON nc.codnc = liniiNC.codnc&apos;;

  sSelTranz5 := &apos;
    SELECT
      t.codtrezor coddoc, t1.codtrezor1 coddoc1, t.tipdoc, t1.datadoc, t1.nrdoc, t1.nri, t1.doc as prefixdoc, t1.carnetdoc, t1.seriedoc seriadoc, t1.codpart as partener, 0 codlocatie, 0 codfiscal, 0 tvainc,
      0 VA_311_312,
      (o.valoare - Coalesce(g.tva,0)) * Coalesce(NULLIF(g.curs,0),1) * (case when g.semnificatie IN (330, 420) then -1 else 1 end) baza,
      Coalesce(g.tva,0) * Coalesce(NULLIF(g.curs,0),1) * (case when g.semnificatie IN (330, 420) then -1 else 1 end) tva,
      PKG_LIST_BASE_UTILS.MATCH_TVA(Coalesce(Coalesce(g.tva*100,0)/NULLIF(o.valoare-Coalesce(g.tva,0),0),&apos;||sPjTva||&apos;), &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;) CAZTVA,
      NULL tiplinie, 0 taxa, 1 tiptva ,1 tiptranzactie, 0 tiptva0, o.valoare * Coalesce(NULLIF(g.curs,0),1) * (case when g.semnificatie in(330, 420) then -1 else 1 end) valdoc,
      T1.OBS, CASE WHEN G.SEMNIFICATIE = 901 THEN O.ICONT ELSE 0 END CODCONT, t.subunitatea, t.datacreare, t.userid, t.an, t.luna,
      t1.valdoc * Coalesce(NULLIF(t1.curs,0),1) DOCVAL, 0 DOCBAZA, 0 DOCTVA, 1 CALC,
      0 CAZ_B_CU_TI,
      0 DoServCaStoc,
      &apos;&apos;~&apos;&apos; TipLinieEXTRA,
      0 DOC_REG
    FROM trezor t
      INNER JOIN trezor1  t1     ON t1.codtrezor       = t.codtrezor
      INNER JOIN general  g      ON g.coddoc           = t1.codtrezor1 AND g.tipdoc = t.tipdoc
      INNER JOIN obligpif o      ON o.codgeneral       = g.codgeneral
      LEFT  JOIN stingere s      ON s.codstingatorpif  = o.codobligpif
      LEFT  JOIN obligpif ostins ON ostins.codobligpif = s.codstinspif
    WHERE T.OPERAT = 1 AND T1.ANULAT = 0  &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      AND T.AN*12+T.LUNA &apos;||sCondLuna||&apos;
      AND ( (O.SEMNIFICATIE IN (330,410,420) AND Coalesce(G.TVA,0) &gt; 0) OR
            (O.SEMNIFICATIE = 901) OR
            (O.SEMNIFICATIE = 320 AND OSTINS.SEMNIFICATIE = 330)
          )&apos;;

  sSelTranz6 := &apos;
    SELECT
      c.codcompens coddoc,
      CASE
        WHEN G.SEMNIFICATIE = 1300 AND Coalesce(C.TIPCOMPENS,0) = 5 THEN 1
        WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 5 THEN 2
        ELSE NULL
      END coddoc1,
      28 tipdoc, c.datadoc, c.nrdoc, NULL nri, &apos;&apos;PV&apos;&apos; prefixdoc, c.carnetdoc, NULL seriadoc, o.codpart as partener, 0 codlocatie, 0 codfiscal, 0 tvainc,
      0 VA_311_312,
      CASE
        WHEN OS.SEMNIFICATIE = 210 AND O.SEMNIFICATIE = 1350 THEN 1
        WHEN OS.SEMNIFICATIE = 330                           THEN 1
        ELSE -1
      END * Sign(O.VALOARE) * (ABS(o.valoare)-ABS(g.tva)) * Coalesce(NULLIF(g.curs,0),1) baza,
      CASE
        WHEN OS.SEMNIFICATIE = 210 AND O.SEMNIFICATIE = 1350 THEN 1
        WHEN OS.SEMNIFICATIE = 330                           THEN 1
        ELSE -1
      END * Sign(O.VALOARE) * ABS(g.tva) * Coalesce(NULLIF(g.curs,0),1) TVA ,
      PKG_LIST_BASE_UTILS.MATCH_TVA(CASE WHEN Coalesce(Abs(o.valoare) - Abs(g.tva),0) = 0 THEN &apos;||sPjTva||&apos; ELSE Abs(G.TVA)*100/(Abs(O.VALOARE)-Abs(G.TVA)) END,&apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;) CAZTVA,
      NULL tiplinie, 0 taxa, 1 tiptva, 1 tiptranzactie, 0 tiptva0,
      Sum(
        o.valoare * Sign(O.VALOARE) *
        CASE
          WHEN OS.SEMNIFICATIE = 210 AND O.SEMNIFICATIE = 1350 THEN 1
          WHEN OS.SEMNIFICATIE = 330                           THEN 1
          ELSE -1
        END *
        Coalesce(NULLIF(g.curs,0),1)
      ) OVER (PARTITION BY c.codcompens) valdoc,
      c.obsd||&apos;&apos; ; &apos;&apos;||c.obsc obs, 0 codcont,c.subunitatea, c.datacreare, c.userid, c.an, c.luna,
      0 DOCVAL, 0 DOCBAZA, 0 DOCTVA, 1 CALC,
      0 CAZ_B_CU_TI,
      0 DoServCaStoc,
      &apos;&apos;~&apos;&apos; TipLinieEXTRA,
      0 DOC_REG
    FROM compens c
      INNER JOIN general  g  ON c.codcompens      = g.coddoc AND g.tipdoc = 28
      INNER JOIN obligpif o  ON g.codgeneral      = o.codgeneral
      LEFT  JOIN STINGERE S  ON S.CODSTINGATORPIF = O.CODOBLIGPIF
      LEFT  JOIN OBLIGPIF OS ON OS.CODOBLIGPIF    = S.CODSTINSPIF
      INNER JOIN NPART    P  ON P.CODPART         = CASE WHEN O.SEMNIFICATIE = 1350 THEN C.PARTC ELSE C.PARTD END
    WHERE C.AN*12+C.LUNA &apos;||sCondLuna||&apos;
      AND G.SEMNIFICATIE IN (1300,1350)
      AND CASE
            WHEN G.SEMNIFICATIE = 1300 AND Coalesce(C.TIPCOMPENS,0) = 5 AND     OS.SEMNIFICATIE IN (110)      THEN 0
            WHEN G.SEMNIFICATIE = 1300                                  AND NOT OS.SEMNIFICATIE IN (430,1353) THEN 1
            WHEN G.SEMNIFICATIE = 1350                                  AND     OS.SEMNIFICATIE IN (330,410)  THEN 1
            WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 5 AND     OS.SEMNIFICATIE IN (210)      THEN 1
            WHEN G.SEMNIFICATIE = 1350 AND Coalesce(C.TIPCOMPENS,0) = 2                                       THEN 1
            ELSE 0
          END = 1
      AND Coalesce(G.TVA,0) &lt;&gt; 0
      AND P.CODPART &lt;&gt; 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, pSUBUNIT =&gt; vSubunit);

  sSelA := &apos;
  ),
  CRS AS (
    SELECT
      CODDOC, CODDOC1, TIPDOC, DATADOC, NRDOC, NRI, PREFIXDOC, CARNETDOC, SERIADOC, PARTENER, OBS, CODCONT, SUBUNITATEA, CODLOCATIE, CODFISCAL, TVAINC, TIPTVA,
      SUM(baza) baza, SUM(CASE WHEN tva = 0 THEN 0 ELSE baza END) bazax, SUM(tva) tva, CASE WHEN TIPDOC = 16 THEN SUM(baza) + SUM(tva) ELSE valdoc END valdoc, -- din cauza ArtIncasUlterior
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0                         ELSE baza END) bunuri_cu_ti,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0                         ELSE tva  END) tva_bunuri_cu_ti,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 1 THEN 0 ELSE baza END) BUNURI_CU_TI_BMED,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 1 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMED,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 2 THEN 0 ELSE baza END) BUNURI_CU_TI_BMIN,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 2 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMIN,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 3 THEN 0 ELSE baza END) BUNURI_CU_TI_BMAX,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 3 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMAX,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 4 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 4 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 5 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG2,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 5 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG2,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 6 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG3,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 6 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG3,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 7 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG4,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 7 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG4,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 8 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG5,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN tva = 0 THEN 0 WHEN CAZTVA &lt;&gt; 8 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG5,
      SUM(CASE WHEN tiptranzactie in (1,2,4) AND tiptva =  5     THEN baza ELSE 0 END) art143ad,
      SUM(CASE WHEN tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) art143bc,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;)  = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) serv143bc,
      SUM(CASE WHEN tiptranzactie in (1,2)   AND tiptva =  7     AND AN*12+LUNA &lt;2016*12+7 THEN baza
               WHEN tiptranzactie in (1,2)   AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 THEN baza+tva
               ELSE 0
          END )                                                                            rss_311_322,
      SUM(CASE WHEN tiptranzactie in (1,2)   AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 THEN tva
               ELSE 0
          END)                                                                         tva_rss_311_322,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 1 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMED,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 1 THEN tva               ELSE 0 END) A_311_322_TMED,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 2 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMIN,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 2 THEN tva               ELSE 0 END) A_311_322_TMIN,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 3 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMAX,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 3 THEN tva               ELSE 0 END) A_311_322_TMAX,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva =  9     THEN baza ELSE 0 END) serv278b,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva =  9     THEN tva  ELSE 0 END) serv278t,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva = 10     THEN baza ELSE 0 END) baza_oss,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva = 10     THEN tva  ELSE 0 END) tva_oss,
      SUM(CASE WHEN                              tiptva = 11     THEN baza ELSE 0 END) art294ab,
      SUM(CASE WHEN                              tiptva = 12     THEN baza ELSE 0 END) art294cd,
      SUM(CASE WHEN tiptranzactie = 1        AND tiptva = 13     THEN baza ELSE 0 END) art292,
      SUM(CASE WHEN CAZTVA = 1 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_med,
      SUM(CASE WHEN CAZTVA = 1 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_med,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN baza ELSE 0 END) baza_min,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN tva  ELSE 0 END) tva_min,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN baza ELSE 0 END) baza_max,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN tva  ELSE 0 END) tva_max,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN baza ELSE 0 END) baza_regmin,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN tva  ELSE 0 END) tva_regmin,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN baza ELSE 0 END) baza_regmax,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN tva  ELSE 0 END) tva_regmax,
      SUM(CASE WHEN CAZTVA = 4 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg,
      SUM(CASE WHEN CAZTVA = 4 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg,
      SUM(CASE WHEN CAZTVA = 5 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg2,
      SUM(CASE WHEN CAZTVA = 5 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg2,
      SUM(CASE WHEN CAZTVA = 6 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg3,
      SUM(CASE WHEN CAZTVA = 6 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg3,
      SUM(CASE WHEN CAZTVA = 7 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg4,
      SUM(CASE WHEN CAZTVA = 7 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg4,
      SUM(CASE WHEN CAZTVA = 8 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg5,
      SUM(CASE WHEN CAZTVA = 8 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg5,
      SUM(CASE WHEN CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) nonro_ded,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) =  &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) serv_nonro_ded,
      SUM(CASE WHEN CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) nonro_nonded,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) =  &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) serv_nonro_nonded,
      SUM(
        CASE
          WHEN CAZTVA = 0
           AND NOT tipdoc in (5,14,35)
           AND Coalesce(tiptva0,0) = 0
           AND (
                 (tiptranzactie IN (1,2,3) AND tiptva = 1) OR
                 (tiptranzactie IN (1,2,3) AND tiptva = 2) OR
                 (tiptranzactie IN (1,2)   AND tiptva = 3)
               )
          THEN baza
          ELSE 0
        END
      ) ro_ded,
      SUM(
        CASE
          WHEN CAZTVA = 0 AND tipdoc = 35 THEN baza
          WHEN CAZTVA = 0
           AND tipdoc &lt;&gt; 14
           AND Coalesce(tiptva0,0) = 1
           AND (
                 (tiptranzactie IN (1,2,3) AND tiptva IN (1,2)) OR
                 (tiptranzactie = 2        AND tiptva = 3     )
               )
           AND NOT taxa IN (3,4,5)
          THEN baza
          ELSE 0
        END
      ) ro_nonded,
      SUM(CASE WHEN CAZTVA = 0 AND (tipdoc = 14 OR Coalesce(tiptva0,0) = 2) THEN baza ELSE 0 END) oper_neimp,
      SUM(CASE WHEN CAZTVA = 0 THEN baza ELSE 0 END) baza_0,
      datacreare, userid, an, luna,
      CASE WHEN tipdoc = 28 THEN SUM(baza+tva) ELSE docval END docval, CASE Calc WHEN 1 THEN SUM(baza) ELSE docbaza END docbaza, CASE Calc WHEN 1 THEN SUM(tva) ELSE doctva END doctva,
      DOC_REG
    FROM CRS_JV_TRANZACTII
    GROUP BY
      CODDOC, CODDOC1, TIPDOC, DATADOC, NRDOC, NRI, PREFIXDOC, CARNETDOC, SERIADOC, PARTENER, VALDOC, OBS, CODCONT, SUBUNITATEA, CODLOCATIE, CODFISCAL, TVAINC, TIPTVA,
      DATACREARE, USERID, AN, LUNA, DOCVAL, DOCBAZA, DOCTVA, CALC, DOC_REG
  )
  SELECT
    crs.CODDOC, crs.CODDOC1, crs.TIPDOC, 1 ORDDOC,
    crs.DATADOC, crs.NRDOC, crs.NRI, crs.PREFIXDOC, Coalesce(crs.SERIADOC,dc.SERIE) SERIADOC,
    CASE WHEN CRS.TIPDOC = 16 THEN &apos;&apos;Borderou vanzari zilnice &apos;&apos; WHEN CRS.TIPDOC = 14 THEN &apos;&apos;Diminuare de stoc &apos;&apos; ELSE Coalesce(NP.den_part,N.DEN_CONT) END DEN_PART,
    CASE
      WHEN crs.TIPDOC IN (29,33) AND crs.obs LIKE &apos;&apos;%/%&apos;&apos; AND INSTR(crs.OBS,&apos;&apos;/&apos;&apos;,1,2) = 0 THEN SUBSTR(crs.OBS,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)+1)
      WHEN crs.TIPDOC IN (29,33) AND crs.obs LIKE &apos;&apos;%/%&apos;&apos; THEN SUBSTR(crs.OBS,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)+1,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;,1,2)-INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)-1)
      WHEN Coalesce(CRS.CODFISCAL,0) = 0 THEN fiscp.codfiscal
      ELSE fiscd.codfiscal
    END CODFISCAL,
    CASE WHEN CRS.TVAINC = 0 THEN Coalesce(NULLIF(crs.valdoc,0),crs.baza+crs.tva) ELSE crs.ro_ded+crs.ro_nonded END VALDOC,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_med    END BAZA_MED,    CASE WHEN CRS.TVAINC = 0 THEN crs.tva_med    END TVA_MED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_min    END BAZA_MIN,    CASE WHEN CRS.TVAINC = 0 THEN crs.tva_min    END TVA_MIN,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_max    END BAZA_MAX,    CASE WHEN CRS.TVAINC = 0 THEN crs.tva_max    END TVA_MAX,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_regmin END BAZA_REGMIN, CASE WHEN CRS.TVAINC = 0 THEN crs.tva_regmin END TVA_REGMIN,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_regmax END BAZA_REGMAX, CASE WHEN CRS.TVAINC = 0 THEN crs.tva_regmax END TVA_REGMAX,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_reg    END BAZA_REG,    CASE WHEN CRS.TVAINC = 0 THEN crs.tva_reg    END TVA_REG,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_reg2   END BAZA_REG2,   CASE WHEN CRS.TVAINC = 0 THEN crs.tva_reg2   END TVA_REG2,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_reg3   END BAZA_REG3,   CASE WHEN CRS.TVAINC = 0 THEN crs.tva_reg3   END TVA_REG3,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_reg4   END BAZA_REG4,   CASE WHEN CRS.TVAINC = 0 THEN crs.tva_reg4   END TVA_REG4,
    CASE WHEN CRS.TVAINC = 0 THEN crs.baza_reg5   END BAZA_REG5,   CASE WHEN CRS.TVAINC = 0 THEN crs.tva_reg5   END TVA_REG5,
    CASE WHEN CRS.TVAINC = 0 THEN crs.bunuri_cu_ti END BUNURI_CU_TI, CASE WHEN CRS.TVAINC = 0 THEN crs.tva_bunuri_cu_ti END TVA_BUNURI_CU_TI,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BMED END  BUNURI_CU_TI_BMED,  CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TMED END  BUNURI_CU_TI_TMED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BMIN END  BUNURI_CU_TI_BMIN,  CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TMIN END  BUNURI_CU_TI_TMIN,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BMAX END  BUNURI_CU_TI_BMAX,  CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TMAX END  BUNURI_CU_TI_TMAX,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BREG END  BUNURI_CU_TI_BREG,  CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TREG END  BUNURI_CU_TI_TREG,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BREG2 END BUNURI_CU_TI_BREG2, CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TREG2 END BUNURI_CU_TI_TREG2,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BREG3 END BUNURI_CU_TI_BREG3, CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TREG3 END BUNURI_CU_TI_TREG3,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BREG4 END BUNURI_CU_TI_BREG4, CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TREG4 END BUNURI_CU_TI_TREG4,
    CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_BREG5 END BUNURI_CU_TI_BREG5, CASE WHEN CRS.TVAINC = 0 THEN crs.BUNURI_CU_TI_TREG5 END BUNURI_CU_TI_TREG5,
    CASE WHEN CRS.TVAINC = 0 THEN crs.nonro_ded    END NONRO_DED,    CASE WHEN CRS.TVAINC = 0 THEN crs.serv_nonro_ded    END SERV_NONRO_DED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.nonro_nonded END NONRO_NONDED, CASE WHEN CRS.TVAINC = 0 THEN crs.serv_nonro_nonded END SERV_NONRO_NONDED,
    crs.RO_DED, crs.RO_NONDED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.rss_311_322     END a_1521_22,
    CASE WHEN CRS.TVAINC = 0 THEN crs.tva_rss_311_322 END tva_rss_311_322,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_BMED  END A_311_322_BMED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_TMED  END A_311_322_TMED,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_BMIN  END A_311_322_BMIN,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_TMIN  END A_311_322_TMIN,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_BMAX  END A_311_322_BMAX,
    CASE WHEN CRS.TVAINC = 0 THEN crs.A_311_322_TMAX  END A_311_322_TMAX,
    CASE WHEN CRS.TVAINC = 0 THEN crs.art143ad END ART143AD, CASE WHEN CRS.TVAINC = 0 THEN crs.art143bc END ART143BC, CASE WHEN CRS.TVAINC = 0 THEN crs.serv143bc END SERV143BC,
    CASE WHEN CRS.TVAINC = 0 THEN crs.art294ab END ART294AB, CASE WHEN CRS.TVAINC = 0 THEN crs.art294cd END ART294CD,
    CASE WHEN CRS.TVAINC = 0 THEN crs.art292   END ART292,
    crs.serv278b, crs.serv278t,
    crs.baza_oss, crs.tva_oss,
    CASE WHEN CRS.TVAINC = 0 THEN crs.oper_neimp END OPER_NEIMP, crs.obs,
    sub.den_subunit SUBUNITATEA, CASE t.statcomunitar WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE crs.tiptva WHEN 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI, crs.datacreare DATACDOC, ut.username, crs.an ANDOC, crs.luna LUNADOC, CASE CRS.TVAINC WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TVALAINC,
    CASE CRS.TVAINC WHEN 1 THEN crs.bazax + crs.tva END RESTOL,
    CASE CRS.TVAINC WHEN 1 THEN crs.baza-crs.ro_ded-crs.ro_nonded END BAZAOBLIG,
    CASE CRS.TVAINC WHEN 1 THEN crs.tva END TVANOBLIG,
    NULL INCPREFIX, NULL INCTIP, NULL INCNR, NULL INCDATA,
    NULL INCVAL, NULL INCVFT, NULL INCTVA,
    CASE CRS.TVAINC WHEN 1 THEN crs.bazax + crs.tva END RESTVAL, CASE CRS.TVAINC WHEN 1 THEN crs.tva END RESTTVA,
    CASE CRS.TVAINC WHEN 1 THEN crs.bazax + crs.tva END SOLDVAL,
    CASE CRS.TVAINC WHEN 1 THEN crs.tva END SOLDTVA,
    CRS.DOCVAL, CRS.DOCBAZA, CRS.DOCTVA&apos;||
    sTIPTVADOC||gUserAlias||&apos;
  FROM CRS
    LEFT JOIN NPART          NP    ON NP.CODPART       = CRS.PARTENER
    LEFT JOIN NPARTCODFISC   FISCD ON FISCD.COD_CODFISCAL = CRS.CODFISCAL
    LEFT JOIN NPARTCODFISC   FISCP ON FISCP.CODPART    = CRS.PARTENER AND FISCP.PRINCIPAL = 1
    LEFT JOIN NCONT          N     ON N.CODCONT        = CRS.CODCONT
    LEFT JOIN NSUBUNIT       SUB   ON SUB.CODSUBUNIT   = CRS.SUBUNITATEA
    LEFT JOIN NAGENDA        SDOC  ON SDOC.CODAGENDA   = CRS.CODLOCATIE
    LEFT JOIN NAGENDA        SSOC  ON SSOC.CODPART     = CRS.PARTENER AND Coalesce(SSOC.INACTIV,0) = 0 AND ssoc.SEDIUSOCIAL between 4 and 7 AND SSOC.TIP = 0
    LEFT JOIN NLOCALIT       L     ON L.CODLOCALIT     = Coalesce(SDOC.CODLOCALIT, SSOC.CODLOCALIT)
    LEFT JOIN NTARI          T     ON T.CODTARA        = Coalesce(L.CODTARA, 0)
    LEFT JOIN DOCCARNETE     DC    ON DC.CODCARNET     = CRS.CARNETDOC
    LEFT JOIN TMP_UTILIZATOR UT    ON UT.CODUTILIZATOR = CRS.USERID
    LEFT JOIN INTRARI        INTR  ON INTR.CODINTR     = crs.CODDOC AND INTR.TIPDOC = crs.TIPDOC
    LEFT JOIN IESIRI         IES   ON IES.CODIES       = crs.CODDOC AND IES.TIPDOC = crs.TIPDOC &apos;||
    gSuplJoins;

  vZileTVAInc := Coalesce(To_Number(pkg_categconst.GetValConstanta(&apos;ZileTVAIncasare&apos;,vAnLista,vLunaLista)), 0);
  vZileTVAInc := CASE WHEN vZileTVAInc &lt; 0 THEN 0 WHEN vZileTVAInc &gt; 9999 THEN 9999 ELSE vZileTVAInc END;
  sDRTVAInc := To_Char( Trunc(To_Date(vAnLista||&apos;.&apos;||vLunaLista,&apos;yyyy.mm&apos;),&apos;mm&apos;) - 1 - vZileTVAInc , &apos;dd.mm.yyyy&apos;);

  sSelTranzX := &apos;
    SELECT
      I1.codies coddoc, NULL coddoc1, I.tipdoc, I.datadoc, I.nrdoc, I.nri, I.prefixdoc, I.carnetdoc, I.seriadoc, I.partener, I.codlocatie, I.codfiscal, NULL TVAINC,
      CASE
        WHEN I.TIPTVA IN (7,8) AND I.AN*12+I.LUNA&gt;=2016*12+7 AND I.TIPDOC = 19
        THEN (
          SELECT SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0))
          FROM livr1 l1
            INNER JOIN livr    l  ON l1.codlivr    = l.codlivr
            LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
            LEFT  JOIN livrval lv ON lv.codlivr1   = l1.codlivr1
          WHERE L1.CODIES1 = I1.CODIES1 AND L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
        )
        WHEN I.TIPTVA IN (7,8) AND I.AN*12+I.LUNA&gt;=2016*12+7 AND I.TIPDOC = 26
        THEN (
          SELECT SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0))
          FROM ieslink ilae
            INNER JOIN iesiri1 ae1  ON ae1.codies1   = ilae.codlinieaviz
            INNER JOIN livr1   l1   ON l1.codies1    = ae1.codies1
            INNER JOIN livr    l    ON l.codlivr     = l1.codlivr AND l.codies = ae1.codies AND l.tiplivr = 20
            LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
            LEFT  JOIN livrval lv   ON lv.codlivr1   = l1.codlivr1
          WHERE ilae.codies1  = i1.codies1
        )
        ELSE 0
      END VA_311_312,
      CASE
        WHEN I.TIPDOC IN (14)    THEN L1.BAZA
        WHEN I.TIPDOC IN (16,21) THEN Coalesce(I1.VALFIN,I1.CANT*I1.PU,0) - Coalesce(I1.TVAFIN,I1.TVA,0)
        ELSE                          Coalesce(I1.VALFIN,I1.CANT*I1.PU,0)
      END *
      CASE WHEN I1.VALFIN IS NULL THEN 1+Coalesce(i1.procdisc/100,0) ELSE 1 END *
      Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) baza,
      CASE
        WHEN I.TipDoc = 14 AND L1.NR_L1 = 1 THEN Coalesce(I1.TVA,0)
        WHEN I.TipDoc = 14 AND L1.NR_LX = 0 THEN Coalesce(I1.TVA,0)
        WHEN I.TipDoc = 14 AND L1.BAZATOT &lt;&gt; 0 THEN Coalesce(I1.TVA,0) * L1.Baza/L1.BAZATOT
        WHEN I.TipDoc = 14 THEN Coalesce(I1.TVA,0)/L1.NR_L1
        ELSE Coalesce(I1.TVAFIN, I1.TVA,0)
      END *
      CASE WHEN I1.VALFIN IS NULL THEN 1+Coalesce(i1.procdisc/100,0) ELSE 1 END *
      Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) tva,
      PKG_LIST_BASE_UTILS.MATCH_TVA(
        CASE
          WHEN I.TIPDOC = 14 AND L1.Baza = 0                              THEN &apos;||sPjTva||&apos;
          WHEN I.TipDoc = 14 AND L1.NR_L1 = 1                             THEN Coalesce(I1.TVA,0) * 100 /L1.BAZA
          WHEN I.TipDoc = 14 AND L1.BAZATOT &lt;&gt; 0                          THEN Coalesce(I1.TVA,0) * 100 /L1.BAZATOT
          WHEN I.TIPDOC = 14                                              THEN Coalesce(I1.TVA,0)/L1.NR_LX * 100 / L1.BAZA
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND Coalesce(I1.RESTFACT,0)=0 THEN &apos;||sPjTva||&apos;
          WHEN I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)                               THEN Coalesce(I1.TVA,0)/I1.RESTFACT*100
          WHEN I.TIPTVA IN (7,8)            AND I.AN*12+I.LUNA&gt;=2016*12+7 THEN T1.PROCENT
          ELSE PKG_LIST_BASE_UTILS.CALC_PROC_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT)
        END,
        &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
      ) CAZTVA,
      I1.tiplinie,
      CASE WHEN I.tipdoc = 14 AND Coalesce(I1.TVA,0)&lt;&gt;0 THEN 1 ELSE Coalesce(I.tiptva,1) END tiptva,
      CASE WHEN I.tipdoc = 14 AND Coalesce(I1.TVA,0)&lt;&gt;0 THEN 1 ELSE Coalesce(I.tiptranzactie,1) END tiptranzactie,
      CASE
        WHEN (Coalesce(I1.TVA,0) = 0) AND (I1.tiplinie IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;)) THEN PKG_LIST_BASE_UTILS.getTipTVA0(I1.codobiect,I.an,I.luna)
        ELSE 0
      END TIPTVA0,
      CASE
        WHEN I.TIPDOC = 14 THEN SUM( (L1.BAZATOT + Coalesce(I1.TVA,0)) / l1.nr_l1) OVER (PARTITION BY I.CODIES)
        ELSE I.VALDOC
      END * Coalesce(NULLIF(CASE WHEN CL.VAL = 1 THEN I1.CursFacturaAvans END,0), NULLIF(I.Curs,0),1) valdoc,
      i.obs, 0 codcont, i.subunitatea, i.datacreare, i.userid, i.an, i.luna,
      i.valdoc            * Coalesce(NULLIF(I.Curs,0),1) docval,
      (i.valdoc-i.tvadoc) * Coalesce(NULLIF(I.Curs,0),1) docbaza,
      i.tvadoc            * Coalesce(NULLIF(I.Curs,0),1) doctva,
      CASE WHEN CL.VAL = 1 THEN 1 ELSE 0 END CALC,
      0 CAZ_B_CU_TI,
      &apos;||CASE WHEN vISIVB THEN &apos;Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codies)&apos; ELSE &apos;0&apos; END||&apos; DoServCaStoc,
      CASE
        WHEN I1.tiplinie &lt;&gt; &apos;&apos;V&apos;&apos;
        THEN I1.tiplinie
        ELSE
          CASE Max(CASE WHEN I1.tiplinie = &apos;&apos;S&apos;&apos; THEN 1 ELSE 0 END) OVER (PARTITION BY i.codies) +
               Max(CASE WHEN I1.tiplinie = &apos;&apos;=&apos;&apos; THEN 2 ELSE 0 END) OVER (PARTITION BY i.codies)
            WHEN 1 THEN &apos;&apos;S&apos;&apos;
            WHEN 2 THEN I1.tiplinie
            WHEN 3 THEN &apos;||CASE WHEN vISIVB THEN &apos;I1.tiplinie&apos; ELSE &apos;&apos;&apos;B&apos;&apos;&apos; END ||&apos;
            ELSE I1.tiplinie
          END
      END TipLinieEXTRA,
      CASE WHEN Coalesce(i.an*100+i.luna, 0) = To_Number(Coalesce(To_Char(Coalesce(i.datatva, i.datadoc), &apos;&apos;yyyymm&apos;&apos;),&apos;&apos;0&apos;&apos;)) THEN 0 ELSE 1 END DOC_REG
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies     = i.codies
      LEFT  JOIN iesiri1 i1st ON i1st.codies1  = i1.codies1storno
      LEFT  JOIN iesiri  ist  ON ist.codies    = i1st.codies
      LEFT  JOIN nartobj o    ON o.codobiect   = i1.codobiect
      LEFT  JOIN nart1   a1   ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
      LEFT  JOIN ntva1   t1   ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      LEFT  JOIN (
        SELECT
          I.nrdoc, I.CodIes, L1.Codies1, L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0) BAZA,
          SUM(L1.CANT * Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0)) OVER (PARTITION BY I.CodIes, L1.Codies1) BAZATOT,
          SUM(CASE WHEN Coalesce(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0) = 0 THEN 0 ELSE 1 END) OVER (PARTITION BY I.CodIes, L1.Codies1) NR_LX,
          COUNT(1) OVER (PARTITION BY I.CodIes, L1.Codies1) NR_L1
        FROM IESIRI I
          INNER JOIN LIVR    L  ON L.CODIES      = I.CODIES AND L.TIPLIVR = I.TIPDOC
          INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
          LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          LEFT  JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
        WHERE I.TIPDOC = 14
          AND I.AN*12+I.LUNA &apos;||sCondLuna||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||&apos;
      ) L1 ON L1.CODIES1 = I1.CODIES1 AND L1.Codies = I1.CODIES
      LEFT  JOIN tmp_al_curslinie cl ON cl.AL = i.an*12+i.luna
    WHERE I.TIPDOC IN (14,16,19,21,22,26)
      AND Coalesce(I.INFOCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.TIPFACTURA,0) &lt;&gt; 7
      AND I.CODIES IN (SELECT DISTINCT CODDOC FROM TMP_LST_TVAINCAS WHERE TIPDOC IN (14,16,19,21,22,26))
      AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;R&apos;&apos;)
      AND CASE I.TIPDOC WHEN 14 THEN Coalesce(I1.TVA,0) ELSE 1 END &lt;&gt; 0
      AND CASE I.TIPDOC WHEN 14 THEN L1.NR_L1           ELSE 1 END &lt;&gt; 0
      AND TO_CHAR(Coalesce(I1.CODOBIECT,-100)) &lt;&gt; CASE WHEN I.TIPDOC = 16 THEN Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;&apos;ArtIncasUlterior&apos;&apos;,I.AN,I.LUNA),&apos;&apos;0&apos;&apos;) ELSE &apos;&apos;0&apos;&apos; END &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;, pSUBUNIT =&gt; vSubunit) ||
      sFiltruCodArt;

  sSelX := &apos;
  ),
  CRS AS (
    SELECT
      CODDOC, CODDOC1, TIPDOC, DATADOC, NRDOC, NRI, PREFIXDOC, CARNETDOC, SERIADOC, PARTENER, OBS, CODCONT, SUBUNITATEA, CODLOCATIE, CODFISCAL, TIPTVA,
      SUM(baza) baza, SUM(CASE WHEN tva = 0 THEN 0 ELSE baza END) bazax, SUM(tva) tva, CASE WHEN TIPDOC = 16 THEN SUM(baza) + SUM(tva) ELSE valdoc END valdoc, -- din cauza ArtIncasUlterior
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0                         ELSE baza END) bunuri_cu_ti,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0                         ELSE tva  END) tva_bunuri_cu_ti,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 1 THEN 0 ELSE baza END) BUNURI_CU_TI_BMED,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 1 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMED,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 2 THEN 0 ELSE baza END) BUNURI_CU_TI_BMIN,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 2 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMIN,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 3 THEN 0 ELSE baza END) BUNURI_CU_TI_BMAX,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 3 THEN 0 ELSE tva  END) BUNURI_CU_TI_TMAX,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 4 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 4 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 5 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG2,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 5 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG2,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 6 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG3,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 6 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG3,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 7 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG4,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 7 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG4,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 8 THEN 0 ELSE baza END) BUNURI_CU_TI_BREG5,
      SUM(CASE WHEN caz_b_cu_ti = 0 THEN 0 WHEN CAZTVA &lt;&gt; 8 THEN 0 ELSE tva  END) BUNURI_CU_TI_TREG5,
      SUM(CASE WHEN tiptranzactie in (1,2,4) AND tiptva =  5     THEN baza ELSE 0 END) art143ad,
      SUM(CASE WHEN tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) art143bc,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;)  = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND tiptranzactie in (1,2,4) AND tiptva = 6 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND tiptranzactie in (1,2,4) AND tiptva =  6     THEN baza ELSE 0 END) serv143bc,
      SUM(CASE WHEN tiptranzactie in (1,2)   AND tiptva =  7     AND AN*12+LUNA &lt;2016*12+7 THEN baza
               WHEN tiptranzactie in (1,2)   AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 THEN baza+tva
               ELSE 0
          END )                                                                        rss_311_322,
      SUM(CASE WHEN tiptranzactie in (1,2)   AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 THEN tva
               ELSE 0
          END)                                                                         tva_rss_311_322,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 1 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMED,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 1 THEN tva               ELSE 0 END) A_311_322_TMED,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 2 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMIN,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 2 THEN tva               ELSE 0 END) A_311_322_TMIN,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 3 THEN baza - VA_311_312 ELSE 0 END) A_311_322_BMAX,
      SUM(CASE WHEN tiptranzactie in (1,2) AND tiptva IN (7,8) AND AN*12+LUNA&gt;=2016*12+7 AND CAZTVA = 3 THEN tva               ELSE 0 END) A_311_322_TMAX,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva =  9     THEN baza ELSE 0 END) serv278b,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva =  9     THEN tva  ELSE 0 END) serv278t,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva = 10     THEN baza ELSE 0 END) baza_oss,
      SUM(CASE WHEN tiptranzactie = 2        AND tiptva = 10     THEN tva  ELSE 0 END) tva_oss,
      SUM(CASE WHEN                              tiptva = 11     THEN baza ELSE 0 END) art294ab,
      SUM(CASE WHEN                              tiptva = 12     THEN baza ELSE 0 END) art294cd,
      SUM(CASE WHEN tiptranzactie = 1        AND tiptva = 13     THEN baza ELSE 0 END) art292,
      SUM(CASE WHEN CAZTVA = 1 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_med,
      SUM(CASE WHEN CAZTVA = 1 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_med,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN baza ELSE 0 END) baza_min,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN tva  ELSE 0 END) tva_min,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN baza ELSE 0 END) baza_max,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 0 THEN tva  ELSE 0 END) tva_max,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN baza ELSE 0 END) baza_regmin,
      SUM(CASE WHEN CAZTVA = 2 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN tva  ELSE 0 END) tva_regmin,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN baza ELSE 0 END) baza_regmax,
      SUM(CASE WHEN CAZTVA = 3 AND tiptranzactie in (1,2,4) AND tiptva = 1 AND doc_reg = 1 THEN tva  ELSE 0 END) tva_regmax,
      SUM(CASE WHEN CAZTVA = 4 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg,
      SUM(CASE WHEN CAZTVA = 4 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg,
      SUM(CASE WHEN CAZTVA = 5 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg2,
      SUM(CASE WHEN CAZTVA = 5 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg2,
      SUM(CASE WHEN CAZTVA = 6 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg3,
      SUM(CASE WHEN CAZTVA = 6 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg3,
      SUM(CASE WHEN CAZTVA = 7 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg4,
      SUM(CASE WHEN CAZTVA = 7 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg4,
      SUM(CASE WHEN CAZTVA = 8 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN baza ELSE 0 END) baza_reg5,
      SUM(CASE WHEN CAZTVA = 8 AND tiptranzactie in (1,2,4) AND tiptva = 1                 THEN tva  ELSE 0 END) tva_reg5,
      SUM(CASE WHEN CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) nonro_ded,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) =  &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 0 THEN baza ELSE 0 END) serv_nonro_ded,
      SUM(CASE WHEN CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) nonro_nonded,
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) +
      CASE
        WHEN SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) = 0 THEN 1
        ELSE SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) =  &apos;&apos;S&apos;&apos; AND DoServCaStoc = 0 AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) /
             SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) &lt;&gt; &apos;&apos;B&apos;&apos;                      AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END)
      END *
      SUM(CASE WHEN Coalesce(TipLinieExtra, &apos;&apos;~&apos;&apos;) = &apos;&apos;B&apos;&apos; AND DoServCaStoc = 0
                AND CAZTVA = 0 AND tiptva = 4 AND Coalesce(tiptva0,0) = 1 THEN baza ELSE 0 END) serv_nonro_nonded,
      SUM(CASE WHEN CAZTVA = 0 AND tipdoc not in (5,14) AND Coalesce(tiptva0,0) = 0 AND ((tiptranzactie IN (1,2,3) AND tiptva IN (1,2)) OR (tiptranzactie IN (1,2) AND tiptva = 3)) THEN baza ELSE 0 END) ro_ded,
      SUM(CASE WHEN CAZTVA = 0 AND tipdoc &lt;&gt; 14 AND Coalesce(tiptva0,0) = 1 AND ((tiptranzactie IN (1,2,3) AND tiptva IN (1,2)) OR (tiptranzactie = 2 AND tiptva = 3)) THEN baza ELSE 0 END) ro_nonded,
      SUM(CASE WHEN CAZTVA = 0 AND (tipdoc = 14 OR Coalesce(tiptva0,0) = 2) THEN baza ELSE 0 END) oper_neimp,
      SUM(CASE WHEN CAZTVA = 0 THEN baza ELSE 0 END) baza_0,
      datacreare, userid, an, luna,
      docval, docbaza, doctva
    FROM CRS_JV_TRANZACTII
    GROUP BY CODDOC, CODDOC1, TIPDOC, DATADOC, NRDOC, NRI, PREFIXDOC, CARNETDOC, SERIADOC, PARTENER, VALDOC, OBS, CODCONT, SUBUNITATEA, CODLOCATIE, CODFISCAL,  TIPTVA, DATACREARE, USERID, AN, LUNA, DOCVAL, DOCBAZA, DOCTVA, DOC_REG
  )
  SELECT
    crs.CODDOC, crs.CODDOC1, crs.TIPDOC, TVAI.ORDDOC,
    crs.DATADOC, crs.NRDOC, crs.NRI, crs.PREFIXDOC, Coalesce(crs.SERIADOC,dc.SERIE) SERIADOC,
    CASE WHEN CRS.TIPDOC = 16 THEN &apos;&apos;Borderou vanzari zilnice &apos;&apos; WHEN CRS.TIPDOC = 14 THEN &apos;&apos;Diminuare de stoc &apos;&apos; ELSE Coalesce(NP.den_part,N.DEN_CONT) END DEN_PART,
    CASE
      WHEN crs.TIPDOC IN (29,33) AND crs.obs LIKE &apos;&apos;%/%&apos;&apos; AND INSTR(crs.OBS,&apos;&apos;/&apos;&apos;,1,2) = 0 THEN SUBSTR(crs.OBS,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)+1)
      WHEN crs.TIPDOC IN (29,33) AND crs.obs LIKE &apos;&apos;%/%&apos;&apos; THEN SUBSTR(crs.OBS,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)+1,INSTR(crs.OBS,&apos;&apos;/&apos;&apos;,1,2)-INSTR(crs.OBS,&apos;&apos;/&apos;&apos;)-1)
      WHEN Coalesce(CRS.CODFISCAL,0) = 0 THEN fiscp.codfiscal
      ELSE fiscd.codfiscal
    END CODFISCAL,
    NULL valdoc,
    crs.baza_med   *TVAI.COEFTVA BAZA_MED,    crs.tva_med   *TVAI.COEFTVA TVA_MED,
    crs.baza_min   *TVAI.COEFTVA BAZA_MIN,    crs.tva_min   *TVAI.COEFTVA TVA_MIN,
    crs.baza_max   *TVAI.COEFTVA BAZA_MAX,    crs.tva_max   *TVAI.COEFTVA TVA_MAX,
    crs.baza_regmin*TVAI.COEFTVA BAZA_REGMIN, crs.tva_regmin*TVAI.COEFTVA TVA_REGMIN,
    crs.baza_regmax*TVAI.COEFTVA BAZA_REGMAX, crs.tva_regmax*TVAI.COEFTVA TVA_REGMAX,
    crs.baza_reg   *TVAI.COEFTVA BAZA_REG,    crs.tva_reg   *TVAI.COEFTVA TVA_REG,
    crs.baza_reg2  *TVAI.COEFTVA BAZA_REG2,   crs.tva_reg2  *TVAI.COEFTVA TVA_REG2,
    crs.baza_reg3  *TVAI.COEFTVA BAZA_REG3,   crs.tva_reg3  *TVAI.COEFTVA TVA_REG3,
    crs.baza_reg4  *TVAI.COEFTVA BAZA_REG4,   crs.tva_reg4  *TVAI.COEFTVA TVA_REG4,
    crs.baza_reg5  *TVAI.COEFTVA BAZA_REG5,   crs.tva_reg5  *TVAI.COEFTVA TVA_REG5,
    crs.bunuri_cu_ti, crs.tva_bunuri_cu_ti,
    crs.BUNURI_CU_TI_BMED,  crs.BUNURI_CU_TI_TMED,
    crs.BUNURI_CU_TI_BMIN,  crs.BUNURI_CU_TI_TMIN,
    crs.BUNURI_CU_TI_BMAX,  crs.BUNURI_CU_TI_TMAX,
    crs.BUNURI_CU_TI_BREG,  crs.BUNURI_CU_TI_TREG,
    crs.BUNURI_CU_TI_BREG2, crs.BUNURI_CU_TI_TREG2,
    crs.BUNURI_CU_TI_BREG3, crs.BUNURI_CU_TI_TREG3,
    crs.BUNURI_CU_TI_BREG4, crs.BUNURI_CU_TI_TREG4,
    crs.BUNURI_CU_TI_BREG5, crs.BUNURI_CU_TI_TREG5,
    crs.nonro_ded,    crs.serv_nonro_ded,
    crs.nonro_nonded, crs.serv_nonro_nonded,
    crs.ro_ded, crs.ro_nonded,
    crs.rss_311_322, crs.tva_rss_311_322, crs.A_311_322_BMED, crs.A_311_322_TMED, crs.A_311_322_BMIN, crs.A_311_322_TMIN, crs.A_311_322_BMAX, crs.A_311_322_TMAX,
    crs.art143ad, crs.art143bc, crs.serv143bc,
    crs.art294ab, crs.art294cd,
    crs.art292,
    crs.serv278b, crs.serv278t,
    crs.baza_oss, crs.tva_oss,
    crs.oper_neimp, crs.obs,
    sub.den_subunit SUBUNITATEA, CASE t.statcomunitar WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END UE, CASE crs.tiptva WHEN 2 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TI, crs.datacreare DATACDOC, ut.username, crs.an ANDOC, crs.luna LUNADOC, &apos;&apos;DA&apos;&apos; TVALAINC,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN (crs.bazax + crs.tva) * Coalesce(TVAI.CoefDoc,1) ELSE NULL END RESTOL,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN crs.bazax * Coalesce(TVAI.CoefDoc,1) ELSE NULL END BAZAOBLIG,
    CASE WHEN TVAI.ORDDOC = 1 OR TVAI.ORDDOC IS NULL THEN crs.tva * Coalesce(TVAI.CoefDoc,1) ELSE NULL END TVANOBLIG,
    TVAI.PREFIXSTINGERE INCPREFIX, PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(TVAI.TIPSTINGERE) INCTIP, CASE WHEN TVAI.TIPSTINGERE &lt;&gt; 81 THEN TVAI.NRSTINGERE END INCNR, TVAI.DATASTINGERE INCDATA,
    CASE WHEN TVAI.TIPSTINGERE = 81 THEN (crs.bazax + crs.tva) * TVAI.COEFTVA ELSE TVAI.VALSTINSA END INCVAL, crs.bazax * TVAI.COEFTVA INCVFT, crs.Tva * TVAI.COEFTVA INCTVA,
    (crs.bazax + crs.tva) * (Coalesce(TVAI.CoefDoc,1) - Coalesce(TVAI.CoefPlata,0)) RESTVAL, crs.tva * (Coalesce(TVAI.CoefDoc,1) - Coalesce(TVAI.CoefPlata,0)) RESTTVA,
    CASE WHEN TVAI.ORDDOC IS NULL OR TVAI.ORDDOC = TVAI.CountDoc THEN (crs.bazax + crs.tva) * (Coalesce(TVAI.CoefDoc,1) - Coalesce(TVAI.CoefPlata,0)) ELSE NULL END SOLDVAL,
    CASE WHEN TVAI.ORDDOC IS NULL OR TVAI.ORDDOC = TVAI.CountDoc THEN crs.tva * (Coalesce(TVAI.CoefDoc,1) - Coalesce(TVAI.CoefPlata,0)) ELSE NULL END SOLDTVA,
    CRS.DOCVAL, CRS.DOCBAZA, CRS.DOCTVA&apos;||
    sTIPTVADOC||gUserAlias||&apos;
  FROM CRS
    INNER JOIN TMP_LST_TVAINCAS TVAI  ON TVAI.CodDoc      = crs.CODDOC AND TVAI.TIPDOC = crs.TIPDOC
    LEFT  JOIN NPART            NP    ON NP.CODPART       = CRS.PARTENER
    LEFT  JOIN NPARTCODFISC     FISCD ON FISCD.COD_CODFISCAL = CRS.CODFISCAL
    LEFT  JOIN NPARTCODFISC     FISCP ON FISCP.CODPART    = CRS.PARTENER AND FISCP.PRINCIPAL = 1
    LEFT  JOIN NCONT            N     ON N.CODCONT        = CRS.CODCONT
    LEFT  JOIN NSUBUNIT         SUB   ON SUB.CODSUBUNIT   = CRS.SUBUNITATEA
    LEFT  JOIN NAGENDA          SDOC  ON SDOC.CODAGENDA   = CRS.CODLOCATIE
    LEFT  JOIN NAGENDA          SSOC  ON SSOC.CODPART     = CRS.PARTENER AND Coalesce(SSOC.INACTIV,0) = 0 AND ssoc.SEDIUSOCIAL between 4 and 7 AND SSOC.TIP = 0
    LEFT  JOIN NLOCALIT         L     ON L.CODLOCALIT     = Coalesce(SDOC.CODLOCALIT, SSOC.CODLOCALIT)
    LEFT  JOIN NTARI            T     ON T.CODTARA        = Coalesce(L.CODTARA, 0)
    LEFT  JOIN DOCCARNETE       DC    ON DC.CODCARNET     = CRS.CARNETDOC
    LEFT  JOIN TMP_UTILIZATOR   UT    ON UT.CODUTILIZATOR = CRS.USERID
    LEFT  JOIN INTRARI          INTR  ON INTR.CODINTR     = crs.CODDOC AND INTR.TIPDOC = crs.TIPDOC
    LEFT  JOIN IESIRI           IES   ON IES.CODIES       = crs.CODDOC AND IES.TIPDOC = crs.TIPDOC &apos;||
    gSuplJoins;

  pregateste_TMP_LST_TVAINCAS( aListID, aListVer);

  EXECUTE IMMEDIATE sIDisc BULK COLLECT INTO bulk_codies;
  FOR i IN 1..bulk_codies.Count LOOP
    PKG_IESIRI.SetValFin(bulk_codies(i), 0);
  END LOOP;
  COMMIT;
  bulk_codies := t_tab_codies();

  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz1||sSelA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz2||sSelA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz3||sSelA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz4||sSelA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz5||sSelA, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE( sInsert|| sSelWith|| sSelTranz6||sSelA, aListID, aListVer);

  EXECUTE IMMEDIATE sXDisc BULK COLLECT INTO bulk_codies;
  FOR i IN 1..bulk_codies.Count LOOP
    PKG_IESIRI.SetValFin(bulk_codies(i), 0);
  END LOOP;
  COMMIT;
  bulk_codies := t_tab_codies();
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelWith||sSelTranzX||sSelX, aListID, aListVer);
  COMMIT;

  EXECUTE IMMEDIATE &apos;SELECT count(1) FROM  &apos;||tmpname INTO vCountDebug;
  PKG_GLOBALS.CheckDebugMode(&apos;Numar linii &apos;||To_Char(vCountDebug), aLISTID, aLISTVER);
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_jurnVanz;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LANSETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>043C482D6BA33180BB28F71342CC0C70E662739B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_lansetichete IS

  vCodDoc   LANSARE.CODLANSARE%TYPE;
  vNrAtrib  INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  
  vDataS       DATE;
  vDataF       DATE;
 
PROCEDURE SETPARAMS(pCodDoc IN NUMBER ,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      )  IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vCodDoc := pCodDoc;

  SELECT Nvl(Max(OA.IndexLocal),0)
  INTO   vNrAtrib
  FROM LANSARE L
       INNER JOIN PROIECT PR ON L.CODPROIECT = PR.CODPROIECT
       INNER JOIN PROIECTNOD PN ON PR.CODPROIECT = PN.CODPROIECT AND PN.NODORIGINAL = 0
       INNER JOIN LANSARE1 L1 ON L1.CODPROIECTNOD = PN.CODPROIECTNOD
       INNER JOIN comanda1 c1 ON L1.CODCMD1 = c1.CODCOMANDA1
       INNER JOIN nartobj o ON o.codobiect = c1.codobiect
       INNER JOIN natrobj oa ON oa.codobiect = o.codobiect
  WHERE L.CodLansare = vCodDoc;

  DELETE tmp_dinamic_cols;

  FOR k IN 1..vNrAtrib
  LOOP
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2-1),&apos;fm999&apos;), &apos;Den.ATRIBUT&apos;||To_Char(k*2-1));
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(To_Char(k*2)  ,&apos;fm999&apos;), &apos;Val.ATRIBUT&apos;||To_Char(k*2));
  END LOOP;

  COMMIT;
END;

FUNCTION DenAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2 IS
  sAux VARCHAR2(50);
BEGIN
  SELECT a.Denumire
  INTO sAux
  FROM natrobj oa
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
    INNER JOIN natrib  a  ON a.codatribut = a1.codatribut
  WHERE oa.codobiect = pCodObiect AND oa.indexlocal = pIDX;

  RETURN sAux;
EXCEPTION
  WHEN No_Data_Found THEN RETURN NULL;
END;

FUNCTION ValAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2 IS
  sAux VARCHAR2(50);
BEGIN
  SELECT a1.Valoare
  INTO sAux
  FROM natrobj oa
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
  WHERE oa.codobiect = pCodObiect AND oa.indexlocal = pIDX;

  RETURN sAux;
EXCEPTION
  WHEN No_Data_Found THEN RETURN NULL;
END;


FUNCTION CodAtrib(pCodObiect IN NUMBER, pIDX IN NUMBER) RETURN VARCHAR2 IS
  sAux VARCHAR2(50);
BEGIN
  SELECT a1.CODEXTERN
  INTO sAux
  FROM natrobj oa
    INNER JOIN natrib1 a1 ON a1.codvalatr = oa.codvalatr
  WHERE oa.codobiect = pCodObiect AND oa.indexlocal = pIDX;

  RETURN sAux;
EXCEPTION
  WHEN No_Data_Found THEN RETURN NULL;
END;


FUNCTION get_NrAtrib RETURN Integer IS
BEGIN
  RETURN vNrAtrib;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(5000);
  sSelect     VARCHAR2(20000);
  sInsertDC   VARCHAR2(1000);
  sSelectDC   VARCHAR2(5000);
  sSelectDC1  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;comanda1 c1, nartobj nao, nart na, nartcli acli, nlocalit LocS, nlocalit LocL&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  FOR k IN 1..vNrAtrib LOOP

    sInsertDC := sInsertDC||&apos;, DenAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||
                            &apos;, ValAtrib_&apos; || to_char(k,&apos;fm999&apos;) ||
                            &apos;, CodAtrib_&apos; || to_char(k, &apos;fm999&apos;);



    sSelectDC := sSelectDC ||
               &apos;, PKG_LIST_BASE_LANSETICHETE.DenAtrib(c1.codobiect,&apos; || k ||&apos;),
                  PKG_LIST_BASE_LANSETICHETE.ValAtrib(c1.codobiect,&apos; || k ||&apos;),
                  PKG_LIST_BASE_LANSETICHETE.CodAtrib(c1.codobiect,&apos; || k ||&apos;)&apos;;


    sSelectDC1 := sSelectDC1 ||
               &apos;, PKG_LIST_BASE_LANSETICHETE.DenAtrib(codobiect,&apos; || k ||&apos;),
                  PKG_LIST_BASE_LANSETICHETE.ValAtrib(codobiect,&apos; || k ||&apos;),
                  PKG_LIST_BASE_LANSETICHETE.CodAtrib(codobiect,&apos; || k ||&apos;)&apos;;

  END LOOP;

 sInsert :=
  &apos;INSERT INTO &apos; || TMPNAME || &apos;(
      ART, CODCATALOG, NUMARCOLET, CLIENT, CODCLIENT, CODCOLET, IDFirma, NrComanda, SediuClient, ObsComanda, PozaClient,
      NrComandaInt,CodIntern,An,Formatie,DataCmdInt,Gest,Sapt,Schimb,CodExtern,Nivel, Adresaclient, Adresalivrare,
      DenLaClient,Cant,IndexLocal &apos;||sInsertDC||gUserFields||&apos;)&apos;;
/*
  -- liniile de pe iesiri
  sSelect := &apos;SELECT denumire, CODEXTERNART, NUMARCOLET, CLIENT, CODCLIENT, TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;&apos;00009&apos;&apos;), PKG_GLOBALS.GETFIRMA_ID, NRCOMANDA&apos; || sSelectDC1 || gUserAlias ||
  &apos;FROM &apos;||
  &apos;(SELECT
     O.CODOBIECT, o.denumire, CC.NRDOC AS NRCOMANDA, A.CODEXTERNART,  NRCOLET || &apos;&apos;/&apos;&apos; || NVL(O.NUMARCOLETE, 1) AS NUMARCOLET, P.DEN_PART AS CLIENT, P.CODEXTERN AS CODCLIENT &apos; ||
  &apos; FROM
      comanda1 c1
      LEFT  OUTER JOIN CMDLINK K ON K.CODCOMANDA1 = C1.CODCOMANDA1
      LEFT  OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = K.CODLINIECOMANDA
      LEFT  OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
      LEFT  OUTER JOIN NPART    P   ON P.CODPART       = CC.PARTENER
      INNER JOIN nartobj o ON o.codobiect = c1.codobiect
      INNER JOIN nart a ON a.codarticol = o.codarticol
      INNER JOIN (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) x ON x.NrColet &lt;= Nvl(o.NumarColete,1)
    WHERE c1.codcomanda =&apos; || vCodDoc || &apos; ORDER BY C1.INDEXLOCAL, NRCOLET ) SUBSL &apos;;

*/

sSelect := &apos;SELECT x.DENUMIRE, x.CODEXTERNART, x.INDEXLOCALCOL || &apos;&apos;/&apos;&apos; || DECODE(x.NRMAX, 0, 1, x.NRMAX) AS NUMARCOLET, x.CLIENT, x.CODCLIENT,  x.IDCOLET,  PKG_GLOBALS.GETFIRMA_ID,  x.NRCOMANDA, x.SediuClient, x.ObsComanda, x.PozaClient,
 x.NrComandaInt,x.CodIntern,x.An,x.Formatie,x.DataCmdInt,x.Gest,x.Sapt,x.Schimb,x.CodExtern,x.Nivel, X.AdresaClient, X.Adresalivrare, x.DenLaClient,x.Cant, x.nrcolet &apos; || sSelectDC1 || gUserAlias ||
&apos; FROM&apos;||
&apos; ( SELECT
      C1.codcomanda CodComandaCI,
      c1.codcomanda1 CodComandaCI1,
      cc1.codcomanda CodComandaCC,
      cc1.codcomanda1 CodComandaCC1,
      O.CODOBIECT,
      O.DENUMIRE,
      CC.NRDOC AS NRCOMANDA,
      A.CODEXTERNART,
      NVL(CO.INDEXLOCAL, 1) AS INDEXLOCALCOL,
      (SELECT COUNT(*) FROM NARTOBJCOLET WHERE CODOBIECT = O.CODOBIECT) AS NRMAX,
      P.DEN_PART AS CLIENT,
      P.CODEXTERN AS CODCLIENT,
      CO.IDCOLET,
      AG.OBS AS SEDIUCLIENT,
      CC.OBS AS OBSCOMANDA,
      P.POZA AS POZACLIENT,
      CC.NRDOC AS NRCOMANDAINT,
      O.CODINTERN,
      substr(to_char(C.An),3,2) an,
      FM.den_formatie formatie,
      C.DataDoc DataCmdInt,
      g.den_gest gest,
      to_number(to_char(c.datadoc, &apos;&apos;WW&apos;&apos;)) sapt,
      c.schimb,
      o.codextern,
      nvl(pnod.nivel,0) nivel,
      GetAdresa(ASS.sector, ASS.strada, ASS.nr1, ASS.nr2, ASS.bloc, ASS.scara, ASS.etaj, ASS.apart, ASS.codpostal) AdresaClient,
      GetAdresa(AG.sector, AG.strada, AG.nr1, AG.nr2, AG.bloc, AG.scara, AG.etaj, AG.apart, AG.codpostal) AdresaLivrare,
      COALESCE(ac.denumire,ntrad.denumiretrad,nao.denumire) denlaclient,
      ASS.CodLocalit lags,
      AG.CodLocalit lagl,
      1 Cant, Y.NrColet
    FROM
      LANSARE L
      --INNER JOIN (SELECT NVL(L0.CODPROIECT, L.CODPROIECT) CODPROIECT, L.CODLANSARE FROM LANSARE L LEFT JOIN LANSARE0 L0 ON L0.CODLANSARE = L.CODLANSARE) L0P ON L0P.CODLANSARE = L.CODLANSARE
      --INNER JOIN PROIECT PR ON L0P.CODPROIECT = PR.CODPROIECT
      --INNER JOIN PROIECTNOD PN ON PR.CODPROIECT = PN.CODPROIECT
      INNER JOIN LANSARE1 L1 ON L1.CODLANSARE = L.CODLANSARE
      INNER JOIN comanda1 c1 ON L1.CODCMD1 = c1.CODCOMANDA1
      INNER JOIN NARTOBJ O ON O.CODOBIECT = c1.codobiect
      INNER JOIN NART A ON a.codarticol = o.codarticol
      inner join comanda c on c1.codcomanda = c.codcomanda
      INNER JOIN (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= Nvl(c1.cantacceptat, 0)
      left join ngest g on c.codgest = g.codgest
      left join formatii FM on FM.codformatie = c.codformatie
      left join lansare1 lans1 on lans1.codcmd1 = c1.codcomanda1 AND L.CODLANSARE = LANS1.CODLANSARE
      left join proiectnod pnod on lans1.codproiectnod = pnod.codproiectnod AND PNOD.NODORIGINAL = 0
      LEFT  OUTER JOIN CMDLINK K    ON K.CODCOMANDA1 = C1.CODCOMANDA1
      LEFT  OUTER JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = K.CODLINIECOMANDA
      LEFT  OUTER JOIN COMANDA  CC  ON CC.CODCOMANDA   = CC1.CODCOMANDA
      LEFT  OUTER JOIN NPART    P   ON P.CODPART       = CC.PARTENER
      LEFT  OUTER JOIN NAGENDA ASS  ON ASS.CODPART     = CC.PARTENER AND ASS.SEDIUSOCIAL IN (4,5,6,7)
      LEFT  OUTER JOIN NAGENDA AG   ON AG.CODAGENDA    = CC.CODLOCATIE
      LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = cc.partener
      left join nartobj nao on nao.codobiect = c1.codobiect
      LEFT JOIN nagenda nag ON nag.codagenda = cc.codlocatie
      LEFT JOIN nlocalit nloc ON nag.codlocalit = nloc.codlocalit
      LEFT JOIN ntari ON ntari.codtara = nloc.codtara
      LEFT JOIN nartobjtrad ntrad ON ntrad.codlimba = ntari.codlimba and ntrad.codobiect = c1.codobiect
      LEFT OUTER JOIN NARTOBJCOLET CO ON CO.CODOBIECT =  O.CODOBIECT&apos;||
      gSuplJoins||&apos;
    WHERE L.CODLANSARE = &apos; || vCodDoc || &apos;
    ORDER BY
      O.CODOBIECT, NVL(CO.INDEXLOCAL, 1)) x
      left join comanda1 c1 on x.codcomandaci1 = c1.codcomanda1
      left join nartobj nao on x.codobiect = nao.codobiect
      left join nart na on nao.codarticol = na.codarticol
      left join nlocalit LocS on x.lags = LocS.CodLocalit
      left join nlocalit LocL on x.lagl = LocL.CodLocalit
      &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end pkg_list_base_lansetichete;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90FFC9303A442A2C63BD52D28133958811D164CE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_lansz IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vSetimanaIni NUMBER(10);
  vSetimanaFin NUMBER(10);
  vAn number(4);

PROCEDURE setParams(pSetimanaIni in number, pSetimanaFin in number, pAn in number)
IS
Aux number(10);
BEGIN
  vSetimanaIni := pSetimanaIni;
  vSetimanaFin := pSetimanaFin;
  vAn := pAn;
  if vSetimanaIni &gt; vSetimanaFin then
    Aux := vSetimanaIni;
    vSetimanaIni := vSetimanaFin;
    vSetimanaFin := Aux;
  end if;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString  VARCHAR2(20000);
vUserID number(20);  
BEGIN
  vUserID := pkg_globals.GETUSERID;
  gSuplCols := &apos;nartobj obj, prodcomp pc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  delete tmp_lansz;
  INSERT INTO TMP_LANSZ (CODLANSZ, CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, OBS,
                         DATASTART, DATASTOP, AN, LUNA, SAPTAMANA, Finalizat)
  SELECT LZ.CODLANSZ, LZ.CODGEST, LZ.CODPLANIFPROD, LZ.SUBUNITATEA, LZ.OPERAT, LZ.ANULAT, LZ.BLOCAT, LZ.OBS,
         trunc(trunc(to_date(LZ.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (LZ.Saptamana - 1) * 7,
         trunc(trunc(to_date(LZ.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + LZ.Saptamana  * 7 - 1,
         LZ.AN, LZ.LUNA, LZ.Saptamana, LZ.FINALIZAT
  FROM LANSZ LZ
  WHERE lZ.saptamana between vSetimanaIni and vSetimanaFin and lZ.an = vAn;

  delete lansz1_manevra1_l where userid = vUSERID;
  insert into lansz1_manevra1_l(codlansz1, Userid)
  select l1.codlansz1, vUserID
  from lansz1 l1
  where exists (select tmp.codlansz from tmp_lansz tmp where tmp.codlansz = l1.codlansz)
        and l1.codformatie &gt; 0 and l1.schimb &gt; 0;

  delete lansz1_manevra_l where userid = vUserID;
  insert into lansz1_manevra_l (codlansz1, codlansz, codformatie, schimb, codreteta, codobiect,
                          luni, marti, miercuri, joi, vineri, sambata, duminica,
                          report, codplanifnod,
                          codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
                          total, lastweek, totaldelansat, NextWeek, RefWeek,
                          lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                          codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
                          obs1, obs2, obs3, obs4, obs5, obs6,
                          codnorma, codextern, codintern,CODGEST, UserID)
  select
    l1.codlansz1, l1.codlansz, l1.codformatie, l1.schimb, l1.codreteta, l1.codobiect,
    l1.luni, l1.marti, l1.miercuri, l1.joi, l1.vineri, l1.sambata, l1.duminica,
    l1.report, l1.codplanifnod,
    l1.codcmd1_luni, l1.codcmd1_marti, l1.codcmd1_miercuri, l1.codcmd1_joi, l1.codcmd1_vineri, l1.codcmd1_sambata, l1.codcmd1_duminica,
    l1.total, l1.lastweek, l1.totaldelansat, l1.nextweek, l1.RefWeek,
    l1.lans_luni, l1.lans_marti, l1.lans_miercuri, l1.lans_joi, l1.lans_vineri, l1.lans_sambata, l1.lans_duminica,
    l1.codreteta, obj.denumire, clsp.den_claseprod, pc.obs, clss.den_claseas, gimp.den_gest,gret.den_gest,
    pc.obs1, pc.obs2, pc.obs3, pc.obs4, pc.obs5, pc.obs6,
    nor.codnorma, obj.codextern, obj.codintern,GRET.CODGEST, vUserID
  from lansz1_manevra1_l m1
       inner join lansz1 l1 on l1.codlansz1 = m1.codlansz1
       inner join lansz l on l.codlansz = l1.codlansz
       inner join nartobj obj on l1.codobiect = obj.codobiect
       inner join prodcomp pc on pc.codprodcomp = l1.codreteta
       inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and coalesce(pg.timpest,0) = 0
       inner JOIN NGEST GRET ON PG.CODGEST = GRET.CODGEST
       inner join nart art on obj.codarticol = art.codarticol
       LEFT JOIN NARTIMPLICITE AIMP ON ART.CODARTICOL = AIMP.CODARTICOL AND AIMP.CODSUBUNIT = l.subunitatea
       LEFT JOIN NGEST GIMP ON AIMP.GESTIMPLICITA = GIMP.CODGEST
       left join prodnorme nor on nor.codprodcomp = pc.codprodcomp and nor.implicit = 1
       left join nclaseprod clsp on clsp.codclaseprod = pc.codclasaprod
       left join nclasea cls on cls.codclasea = art.clasa
       left join nclaseas clss on clss.codclaseas = art.clasastatist
  where m1.userid = vuserid;

  delete lansz1_manevra_l ll1
  where NVL(LL1.REPORT,0) + NVL(Ll1.LUNI,0) + NVL(Ll1.MARTI,0) + NVL(Ll1.MIERCURI,0) + NVL(Ll1.JOI,0) + NVL(Ll1.VINERI,0) + NVL(Ll1.SAMBATA,0) + NVL(Ll1.DUMINICA,0)
        + NVL(LL1.CODCMD1_LUNI,0) + NVL(LL1.CODCMD1_MARTI,0) + NVL(LL1.CODCMD1_MIERCURI,0) + NVL(LL1.CODCMD1_JOI,0) + NVL(LL1.CODCMD1_VINERI,0) + NVL(LL1.CODCMD1_SAMBATA,0)
        + NVL(LL1.CODCMD1_DUMINICA,0) = 0
        and ll1.userid = vuserid;

  DELETE lansz1_manevra1_l WHERE USERID = VUSERID;
  INSERT INTO lansz1_manevra1_l(CODOBIECT, CODRETETA, TOTALLANSAT, USERID, CODLANSZ, REPORT)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.LUNI,0) + NVL(L1.MARTI,0) + NVL(L1.MIERCURI,0) + NVL(L1.JOI,0) + NVL(L1.VINERI,0) + NVL(L1.SAMBATA,0) + NVL(L1.DUMINICA,0)),
         VUSERID, TMP.CODLANSZ, SUM(L1.REPORT)
  FROM TMP_LANSZ TMP
       INNER JOIN LANSZ L ON TMP.CODLANSZ &lt;&gt; L.CODLANSZ AND TMP.SAPTAMANA = L.SAPTAMANA AND TMP.AN = L.AN
       INNER JOIN LANSZ1 L1 ON L1.CODLANSZ = L.CODLANSZ
  WHERE L1.CODFORMATIE &gt; 0 AND L1.SCHIMB &gt; 0
  GROUP BY L1.CODOBIECT, L1.CODRETETA, TMP.CODLANSZ;
  
  UPDATE lansz1_manevra_l TMP
  SET ALTE = (SELECT M.TOTALLANSAT
              FROM lansz1_manevra1_l M
              WHERE M.CODOBIECT = TMP.CODOBIECT and M.CODRETETA = TMP.CODRETETA AND
                    M.CODLANSZ = TMP.CODLANSZ and m.userid = vuserid
             )
  WHERE USERID = VUSERID;
             
  UPDATE lansz1_manevra_l TMP
  SET REPORTALTE = (SELECT M.REPORT
                    FROM lansz1_manevra1_l M
                    WHERE M.CODOBIECT = TMP.CODOBIECT and M.CODRETETA = TMP.CODRETETA AND
                          M.CODLANSZ = TMP.CODLANSZ and m.userid = vuserid
                   )
  WHERE USERID = VUSERID;

  update lansz1_manevra_l set
    TOTALLANSAT = nvl(LUNI,0) + nvl(MARTI,0) + nvl(MIERCURI,0) + nvl(JOI,0) + nvl(VINERI,0) + nvl(SAMBATA,0) + nvl(DUMINICA,0)
  where userid = vuserid;

  update lansz1_manevra_l set
  luni = null where luni = 0;
  update lansz1_manevra_l set
  lans_luni = null where lans_luni = 0;
  update lansz1_manevra_l set
  marti = null where marti = 0;
  update lansz1_manevra_l set
  lans_marti = null where lans_marti = 0;
  update lansz1_manevra_l set
  miercuri = null where miercuri = 0;
  update lansz1_manevra_l set
  lans_miercuri = null where lans_miercuri = 0;
  update lansz1_manevra_l set
  joi = null where joi = 0;
  update lansz1_manevra_l set
  lans_joi = null where lans_joi = 0;
  update lansz1_manevra_l set
  vineri = null where vineri = 0;
  update lansz1_manevra_l set
  lans_vineri = null where lans_vineri = 0;
  update lansz1_manevra_l set
  sambata = null where sambata = 0;
  update lansz1_manevra_l set
  lans_sambata = null where lans_sambata = 0;
  update lansz1_manevra_l set
  duminica = null where duminica = 0;
  update lansz1_manevra_l set
  lans_duminica = null where lans_duminica = 0;
  update lansz1_manevra_l set
  nextweek = null where nextweek = 0;
  update lansz1_manevra_l set
  total = null where total = 0;
  update lansz1_manevra_l set
  alte = null where alte = 0;
  update lansz1_manevra_l set
  lastweek = null where lastweek = 0;
  update lansz1_manevra_l set
  refweek = null where refweek = 0;
  update lansz1_manevra_l set
  report = null where report = 0;
  update lansz1_manevra_l set
  reportalte = null where reportalte = 0;
  
  sString :=
  &apos;insert into &apos;||tmpName||&apos;(
     CODLANSZ,
     FORMATIE,
     SCHIMB,
     LUNI,
     MARTI,
     MIERCURI,
     JOI,
     VINERI,
     SAMBATA,
     DUMINICA,
     NEXTWEEK,
     CMD1_LUNI,
     CMD1_MARTI,
     CMD1_MIERCURI,
     CMD1_JOI,
     CMD1_VINERI,
     CMD1_SAMBATA,
     CMD1_DUMINICA,
     TOTAL,
     ALTE,
     LASTWEEK,
     REFWEEK,
     DENUMIRE,
     DEN_CLASEPROD,
     RETETA,
     DEN_CLASEAS,
     TOTALDELANSAT,
     TOTALLANSAT,
     RESTDELANSAT,
     LANS_LUNI,
     LANS_MARTI,
     LANS_MIERCURI,
     LANS_JOI,
     LANS_VINERI,
     LANS_SAMBATA,
     LANS_DUMINICA,
     SUBUNITATEA,
     OPERAT,
     ANULAT,
     BLOCAT,
     OBS,
     AN,
     LUNA,
     SAPTAMANA,
     DATASTART,
     DATASTOP,
     SECTIE,
     REPORT,
     REPORTALTE &apos;||gUserFields||&apos;)
  select
     L.CODLANSZ,
     f.den_formatie FORMATIE,
     l1.SCHIMB,
     l1.LUNI,
     l1.MARTI,
     l1.MIERCURI,
     l1.JOI,
     l1.VINERI,
     l1.SAMBATA,
     l1.DUMINICA,
     l1.NEXTWEEK,
     case when cluni.codcomanda &gt; 0 then CLUNI.PrefixDoc||CLUNI.NrDoc||&apos;&apos;/&apos;&apos;||CLUNI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cmarti.codcomanda &gt; 0 then CMARTI.PrefixDoc||CMARTI.NrDoc||&apos;&apos;/&apos;&apos;||CMARTI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cmiercuri.codcomanda &gt; 0 then CMIERCURI.PrefixDoc||CMIERCURI.NrDoc||&apos;&apos;/&apos;&apos;||CMIERCURI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cjoi.codcomanda &gt; 0 then CJOI.PrefixDoc||CJOI.NrDoc||&apos;&apos;/&apos;&apos;||CJOI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cvineri.codcomanda &gt; 0 then CVINERI.PrefixDoc||CVINERI.NrDoc||&apos;&apos;/&apos;&apos;||CVINERI.DataDoc else &apos;&apos;&apos;&apos; end,
     case when csambata.codcomanda &gt; 0 then CSAMBATA.PrefixDoc||CSAMBATA.NrDoc||&apos;&apos;/&apos;&apos;||CSAMBATA.DataDoc else &apos;&apos;&apos;&apos; end,
     case when cduminica.codcomanda &gt; 0 then CDUMINICA.PrefixDoc||CDUMINICA.NrDoc||&apos;&apos;/&apos;&apos;||CDUMINICA.DataDoc else &apos;&apos;&apos;&apos; end,
     l1.TOTAL,
     l1.ALTE,
     l1.LASTWEEK,
     l1.REFWEEK,
     obj.DENUMIRE,
     l1.DEN_CLASEPROD,
     l1.RETETA,
     l1.DEN_CLASEAS,
     l1.TOTALDELANSAT,
     l1.TOTALLANSAT,
     l1.RESTDELANSAT,
     L1.LANS_LUNI,
     L1.LANS_MARTI,
     L1.LANS_MIERCURI,
     L1.LANS_JOI,
     L1.LANS_VINERI,
     L1.LANS_SAMBATA,
     L1.LANS_DUMINICA,
     sub.den_subunit SUBUNITATEA,
     case when l.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end OPERAT,
     case when l.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ANULAT,
     case when l.blocat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end BLOCAT,
     l.OBS,
     l.AN,
     l.LUNA,
     l.SAPTAMANA,
     to_char(trunc(trunc(to_date(l.AN,&apos;&apos;yyyy&apos;&apos;),&apos;&apos;yyyy&apos;&apos;),&apos;&apos;iw&apos;&apos;) + (l.Saptamana - 1) * 7, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStart,
     to_char(trunc(trunc(to_date(l.AN,&apos;&apos;yyyy&apos;&apos;),&apos;&apos;yyyy&apos;&apos;),&apos;&apos;iw&apos;&apos;) + l.Saptamana  * 7 - 1, &apos;&apos;dd.mm.yyyy&apos;&apos;) DataStop,
     g.den_gest SECTIE,
     L1.REPORT,
     L1.REPORTALTE &apos;||gUserAlias||&apos;
  from lansz1_manevra_l l1
    inner join tmp_lansz l on l1.codlansz = l.codlansz
    inner join ngest g on l.codgest = g.codgest
    inner join formatii f on f.codformatie = l1.codformatie
    inner join nartobj obj on l1.codobiect = obj.codobiect
    inner join nart art on obj.codarticol = art.codarticol
    inner join num um on um.codum = art.um
    inner join nartobj prod on l1.codobiect = prod.codobiect
    inner join prodcomp pc on pc.codprodcomp = l1.codreteta
    inner join nsubunit sub on l.subunitatea = sub.codsubunit
    left join comanda1 c1luni on c1luni.codcomanda1 = l1.codcmd1_luni
    left join comanda  cluni  on c1luni.codcomanda = cluni.codcomanda
    left join comanda1 c1marti on c1marti.codcomanda1 = l1.codcmd1_marti
    left join comanda  cmarti  on c1marti.codcomanda = cmarti.codcomanda
    left join comanda1 c1miercuri on c1miercuri.codcomanda1 = l1.codcmd1_miercuri
    left join comanda  cmiercuri  on c1miercuri.codcomanda = cmiercuri.codcomanda
    left join comanda1 c1joi on c1joi.codcomanda1 = l1.codcmd1_joi
    left join comanda  cjoi  on c1joi.codcomanda = cjoi.codcomanda
    left join comanda1 c1vineri on c1vineri.codcomanda1 = l1.codcmd1_vineri
    left join comanda  cvineri  on c1vineri.codcomanda = cvineri.codcomanda
    left join comanda1 c1sambata on c1sambata.codcomanda1 = l1.codcmd1_sambata
    left join comanda  csambata  on c1sambata.codcomanda = csambata.codcomanda
    left join comanda1 c1duminica on c1duminica.codcomanda1 = l1.codcmd1_duminica
    left join comanda  cduminica  on c1duminica.codcomanda  = cduminica.codcomanda&apos;||
    gSuplJoins||&apos;
  where f.codformatie &gt; 0 and l1.userid = pkg_globals.getuserid &apos;;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);
  
  --delete tmp_lansz;
  --delete lansz1_manevra_l where userid = vuserid;
  --delete lansz1_manevra1_l where userid = vuserid;
  
  Commit;
END;

procedure test is
vUserID number(20);  
begin
  vUserID := 1;
  delete tmp_lansz;
  INSERT INTO TMP_LANSZ (CODLANSZ, CODGEST, CODPLANIFPROD, SUBUNITATEA, OPERAT, ANULAT, BLOCAT, OBS,
                         DATASTART, DATASTOP, AN, LUNA, SAPTAMANA, Finalizat)
  SELECT LZ.CODLANSZ, LZ.CODGEST, LZ.CODPLANIFPROD, LZ.SUBUNITATEA, LZ.OPERAT, LZ.ANULAT, LZ.BLOCAT, LZ.OBS,
         trunc(trunc(to_date(LZ.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (LZ.Saptamana - 1) * 7,
         trunc(trunc(to_date(LZ.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + LZ.Saptamana  * 7 - 1,
         LZ.AN, LZ.LUNA, LZ.Saptamana, LZ.FINALIZAT
  FROM LANSZ LZ
  WHERE lZ.saptamana between 41 and 41 and lZ.an = 2020;
  commit;

  delete lansz1_manevra1_l where userid = vUSERID;
  insert into lansz1_manevra1_l(codlansz1, Userid)
  select l1.codlansz1, vUserID
  from lansz1 l1
  where exists (select tmp.codlansz from tmp_lansz tmp where tmp.codlansz = l1.codlansz)
        and l1.codformatie &gt; 0 and l1.schimb &gt; 0 and l1.codobiect = 31244;

  commit;

  delete lansz1_manevra_l where userid = vUserID;
  insert into lansz1_manevra_l (codlansz1, codlansz, codformatie, schimb, codreteta, codobiect,
                          luni, marti, miercuri, joi, vineri, sambata, duminica,
                          report, codplanifnod,
                          codcmd1_luni, codcmd1_marti, codcmd1_miercuri, codcmd1_joi, codcmd1_vineri, codcmd1_sambata, codcmd1_duminica,
                          total, lastweek, totaldelansat, NextWeek, RefWeek,
                          lans_luni, lans_marti, lans_miercuri, lans_joi, lans_vineri, lans_sambata, lans_duminica,
                          codprodcomp, denumire, den_claseprod, reteta, den_claseas, gestimplicita,gestreteta,
                          obs1, obs2, obs3, obs4, obs5, obs6,
                          codnorma, codextern, codintern,CODGEST, UserID)
  select
    l1.codlansz1, l1.codlansz, l1.codformatie, l1.schimb, l1.codreteta, l1.codobiect,
    l1.luni, l1.marti, l1.miercuri, l1.joi, l1.vineri, l1.sambata, l1.duminica,
    l1.report, l1.codplanifnod,
    l1.codcmd1_luni, l1.codcmd1_marti, l1.codcmd1_miercuri, l1.codcmd1_joi, l1.codcmd1_vineri, l1.codcmd1_sambata, l1.codcmd1_duminica,
    l1.total, l1.lastweek, l1.totaldelansat, l1.nextweek, l1.RefWeek,
    l1.lans_luni, l1.lans_marti, l1.lans_miercuri, l1.lans_joi, l1.lans_vineri, l1.lans_sambata, l1.lans_duminica,
    l1.codreteta, obj.denumire, clsp.den_claseprod, pc.obs, clss.den_claseas, gimp.den_gest,gret.den_gest,
    pc.obs1, pc.obs2, pc.obs3, pc.obs4, pc.obs5, pc.obs6,
    nor.codnorma, obj.codextern, obj.codintern,GRET.CODGEST, vUserID
  from lansz1_manevra1_l m1
       inner join lansz1 l1 on l1.codlansz1 = m1.codlansz1
       inner join lansz l on l.codlansz = l1.codlansz
       inner join nartobj obj on l1.codobiect = obj.codobiect
       inner join prodcomp pc on pc.codprodcomp = l1.codreteta
       inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and coalesce(pg.timpest,0) = 0
       inner JOIN NGEST GRET ON PG.CODGEST = GRET.CODGEST
       inner join nart art on obj.codarticol = art.codarticol
       LEFT JOIN NARTIMPLICITE AIMP ON ART.CODARTICOL = AIMP.CODARTICOL AND AIMP.CODSUBUNIT = l.subunitatea
       LEFT JOIN NGEST GIMP ON AIMP.GESTIMPLICITA = GIMP.CODGEST
       left join prodnorme nor on nor.codprodcomp = pc.codprodcomp and nor.implicit = 1
       left join nclaseprod clsp on clsp.codclaseprod = pc.codclasaprod
       left join nclasea cls on cls.codclasea = art.clasa
       left join nclaseas clss on clss.codclaseas = art.clasastatist
  where m1.userid = vuserid;

  commit;

  delete lansz1_manevra_l ll1
  where NVL(Ll1.LUNI,0) + NVL(Ll1.MARTI,0) + NVL(Ll1.MIERCURI,0) + NVL(Ll1.JOI,0) + NVL(Ll1.VINERI,0) + NVL(Ll1.SAMBATA,0) + NVL(Ll1.DUMINICA,0)
        + NVL(LL1.CODCMD1_LUNI,0) + NVL(LL1.CODCMD1_MARTI,0) + NVL(LL1.CODCMD1_MIERCURI,0) + NVL(LL1.CODCMD1_JOI,0) + NVL(LL1.CODCMD1_VINERI,0) + NVL(LL1.CODCMD1_SAMBATA,0)
        + NVL(LL1.CODCMD1_DUMINICA,0) = 0
        and ll1.userid = vuserid;
  
  commit;      

  DELETE lansz1_manevra1_l WHERE USERID = VUSERID;
  INSERT INTO lansz1_manevra1_l(CODOBIECT, CODRETETA, TOTALLANSAT, USERID, CODLANSZ, REPORT)
  SELECT L1.CODOBIECT, L1.CODRETETA, SUM(NVL(L1.LUNI,0) + NVL(L1.MARTI,0) + NVL(L1.MIERCURI,0) + NVL(L1.JOI,0) + NVL(L1.VINERI,0) + NVL(L1.SAMBATA,0) + NVL(L1.DUMINICA,0)),
         VUSERID, TMP.CODLANSZ, SUM(L1.REPORT)
  FROM TMP_LANSZ TMP
       INNER JOIN LANSZ L ON TMP.CODLANSZ &lt;&gt; L.CODLANSZ AND TMP.SAPTAMANA = L.SAPTAMANA AND TMP.AN = L.AN
       INNER JOIN LANSZ1 L1 ON L1.CODLANSZ = L.CODLANSZ
  WHERE L1.CODFORMATIE &gt; 0 AND L1.SCHIMB &gt; 0 and l1.codobiect = 31244
  GROUP BY L1.CODOBIECT, L1.CODRETETA, TMP.CODLANSZ;
  
  commit;
  
  UPDATE lansz1_manevra_l TMP
  SET ALTE = (SELECT M.TOTALLANSAT
              FROM lansz1_manevra1_l M
              WHERE M.CODOBIECT = TMP.CODOBIECT and M.CODRETETA = TMP.CODRETETA AND
                    M.CODLANSZ = TMP.CODLANSZ and m.userid = vuserid
             )
  WHERE USERID = VUSERID;
  commit;
end;  

end PKG_LIST_BASE_LANSZ; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LEADS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>497D34D7DB805D64EDD37F48BD99A31FCFE19071</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LEADS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(10000);
sSelect   VARCHAR2(20000);
sZi       VARCHAR2(2);  
sLuna     VARCHAR2(2);
sAn       VARCHAR2(4);
sData     varchar2(10);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NPART P, NCATPRET CAT, NPARTCODFISC F, NAGENDA A, NLOCALIT L, NTARI T, NJUDET J, DOMENIIACT DA, NPARTTR RESP, CAMPANII CAMP, NPART1CRM CRM&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,     &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OPORTUNITATI&apos;, &apos;OPOR&apos;, &apos;OPOR.CODPARTENER = P.CODPART&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  select to_char(extract(day from sysdate)) into sZi from dual;
  sLuna := to_char(pkg_globals.GetLUNALUCRU);
  sAn   := to_char(pkg_globals.GetANLUCRU);

  begin
    sData := to_char(to_date(lpad(sZi, 2, &apos;0&apos;)||&apos;.&apos;||lpad(sLuna,2,&apos;0&apos;)||&apos;.&apos;||sAn));
  exception when others then 
    sData := to_char(last_day(to_date(&apos;01.&apos;||lpad(sLuna,2,&apos;0&apos;)||&apos;.&apos;||sAn,&apos;dd.mm.yyyy&apos;)));
  end;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DEN_PART, CODEXTERN, CODINTERN, DEN_LOCALIT, CODFISCAL, BLOCAT,
    AUTORIZATIE, STRATEGIC, SIMBAUTO, CifraAfaceri,
    DenDomeniuAct, Responsabil, DENCAMPANIE,
    CONCURENTI&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    P.DEN_PART, P.CODEXTERN, P.CODINTERN, L.DEN_LOCALIT, F.CODFISCAL, Decode(P.BLOCAT,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) Blocat,
    P.AUTORIZATIE, Decode(P.STRATEGIC,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) STRATEGIC, J.SIMBAUTO, P.CifraAfaceri,
    DA.DenDomeniuAct, RESP.Delegat, CAMP.DENCAMPANIE, vCP.Concurenti&apos;||
    gUserAlias||&apos;
  FROM NPART P
    INNER JOIN NPART1CRM CRM ON CRM.CODPART = P.CODPART
    LEFT JOIN NCATPRET CAT   ON CAT.CODCATPRET = P.CODCATEGPRET
    LEFT JOIN NPARTCODFISC F ON F.CODPART = P.CODPART AND F.PRINCIPAL = 1
 	  LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART AND Nvl(a.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 4) &lt;&gt; 0)
    LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT JOIN NTARI T ON T.CODTARA = L.CODTARA
    LEFT JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
    LEFT JOIN DOMENIIACT DA ON DA.CodDomeniuAct = P.CodDomeniuAct
    LEFT JOIN NPARTTR RESP ON RESP.CodPartTr = P.CodResponsabil
    LEFT JOIN CAMPANII CAMP ON CAMP.CodCampanie = P.SursaLead
    LEFT JOIN (
      SELECT pc.CodPart, vc2_nt_to_vc3200(CAST(COLLECT(C.DENCONCURENT) AS vc2_nt)) Concurenti
      FROM NPARTCONCURENTI PC INNER JOIN CONCURENTI C ON C.CODCONCURENT = PC.CODCONCURENT
      GROUP BY pc.CodPart
    ) vCP ON vCP.CodPart = P.CodPart &apos;||
    gSuplJoins||&apos;
  WHERE CRM.Lead = 1 and 
        CRM.DATASTART = (SELECT MAX(P1.DATASTART) 
                         FROM NPART1CRM P1 
                         WHERE P1.CODPART = P.CODPART AND 
                               P1.DATASTART&lt;= TO_DATE(&apos;&apos;&apos;||sData||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) 
                        )&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_LEADS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LISTDISPLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D79F9EA071C94490B7E489D91E6AC91E24FDE333</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LISTDISPLIVR is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(1000);
  sSelect       VARCHAR2(9000);
  sFiltru       VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;comanda c, comanda1 c1, nartobj obj, nart art, num1 num1, num us, nparcaut auto, pachete pak, COMANDA CC, COMANDA1 C1C&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;
    AND c.tipdoc = 18 and c.displivrare = 1 &apos;;

  sFiltru := sFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;c.subunitatea&apos;);

  sFiltru := sFiltru||&apos; AND c.datadoc between pkg_list_selectper.dataini and pkg_list_selectper.datafin &apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPnAME||&apos;(
     NAV_CodDoc, 
     NAV_TipDoc, 
     DOC,
     NRDOC,
     DATADOC,
     ART,        
     UM,         
     CANTCOM,    
     CANTACC,    
     CANTREST,   
     PRET,       
     VALCOM,     
     VALACC,     
     VALREST,    
     TERMEN,       
     OBSART,     
     OBSCOM,     
     CodIntern,  
     CodExtern,  
     DenClasaA,  
     SimbClasaA, 
     Masa,       
     Volum,      
     UMPrinc,    
     UM1,
     CANTUM1,
     D1,         
     D2,         
     D3,
     AUTO, 
     DATACREARE &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    c.codcomanda, 
    c.tipdoc,
    c.prefixdoc,
    c.nrdoc,
    c.datadoc,
    obj.denumire, 
    num1.den_um1, 
    c1.cantcomandat/num1.paritate, 
    c1.cantacceptat/num1.paritate, 
    c1.restacceptat/num1.paritate,
    c1.pu*num1.paritate, 
    c1.pu*c1.cantcomandat,
    c1.pu*c1.cantacceptat,
    c1.pu*c1.restacceptat,
    c1.termen,
    c1.OBS,
    c.OBS,  
    obj.codintern,
    obj.codextern,
    cla.den_clasea,
    cla.simbol,
    nvl(obj.masa,0) * c1.cantacceptat,
    nvl(obj.volum,0) * c1.cantacceptat,
    UMP.DEN_UM,
    US.DEN_UM,
    C1.ACCEPTUM1,
    C1.D1,
    C1.D2,
    C1.D3,
    auto.nrinreg, 
    c.datacreare &apos;||gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
    INNER JOIN nartobj obj ON obj.codobiect = c1.codobiect
    INNER JOIN nart art ON obj.codarticol = art.codarticol
    INNER JOIN num UMP ON ART.UM = UMP.CODUM
    INNER JOIN num1 ON num1.codum1 = c1.umsec
    LEFT JOIN nparcaut auto ON auto.CODNPARCAUT = c.MIJLTRANSP
    LEFT JOIN PACHETEDLLINK PLINK ON PLINK.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT JOIN PACHETEOBJ POBJ ON POBJ.CODPACHETEOBJ = PLINK.CODPACHETEOBJ
    LEFT JOIN PACHETE PAK ON PAK.CODPACHETE = POBJ.CODPACHETE
    LEFT JOIN num us ON us.codum = art.um1
    LEFT JOIN nmonede mon ON mon.codmoneda = c.moneda
    LEFT JOIN npers ag on c.agent = ag.codpers
    LEFT JOIN nagenda sedl ON sedl.codagenda = c.codlocatie
    LEFT JOIN nlocalit locl ON locl.codlocalit = sedl.codlocalit
    LEFT JOIN njudet judl ON judl.codjudet = locl.codjudet
    LEFT JOIN nzone zonal ON zonal.codzona = locl.codzona
    LEFT JOIN ntari taral ON taral.codtara = locl.codtara
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN CMDLIVRLINK L ON L.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT JOIN COMANDA1 C1C ON C1C.CODCOMANDA1 = L.CODLINIECOMANDA
    LEFT JOIN COMANDA CC ON CC.CODCOMANDA = C1C.CODCOMANDA &apos;||gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 &apos;||sFiltru;

  --delete x;
  --insert into x(test) values (sselect);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_LISTDISPLIVR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54EC9A07555587AA59E30AEFDFC72D59D5056DF6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRARI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  -- atentie - aici trebuie sa se regaseasca tabele care sunt in toate cele trei selecturi cu aliasurile corespunzatoare
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(20000);
  sSelectComun VARCHAR2(20000);
  sSelectIes   VARCHAR2(20000);
  sSelectT     VARCHAR2(20000);
  sSelectInt   VARCHAR2(20000);
  sColSerii    VARCHAR2(  500)  := &apos;, ns.tg, NULL serie&apos;;
  sGrupSerii   VARCHAR2(  500)  := &apos;, ns.tg&apos; ;
  sJoinSerii   VARCHAR2(  500);
  sCursRef     VARCHAR2(  100)  := &apos;, 1 &apos;;
  sCondDataI   VARCHAR2(  500);
  sCondDataT   VARCHAR2(  500);
  vFiltru      VARCHAR2( 1000);
  sPMP         VARCHAR2(  300)  := &apos;, NULL PMP, NULL PMPVALUTA, NULL PMPDOC, NULL PMPVALUTADOC&apos;;
  sInsertDC    VARCHAR2( 2000);
  sWithDc      VARCHAR2( 2000);
  sSelectDC    VARCHAR2( 2000);
  sJoinDC      VARCHAR2( 2000);
  aSitV        NUMBER(1);
  aBancaV      NUMBER(20);
  aMonedaV     NUMBER(20);
  vMax         INTEGER          := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;
  vInfoOferte  Boolean;
  vInfoPart    Boolean;
BEGIN
  vInfoPart   := PKG_LIST_SELECTGEST.Extra2;
  vInfoOferte := PKG_LIST_SELECTGEST.Extra3;

  gSuplCols :=
    &apos;num1 u1, nartobj nao, nartobj1 nao1 ,nart na, num um1, num um2, ngest g, ngest go, nlocatii nl, nsubunit ss, nmonede mon, nclasea ca, nclaseas cs, &apos;||
    &apos;ncont nc, ncont ncv, nclaseg cg, npart prod, npart furn, ngest gfurn, nartamb aa, pretm pm, npers ag_doc, nparttr del, centrecost cc,&apos;||
    &apos;npart np, nagenda slivr, nlocalit locl, njudet judl, nzone zonal, ntari taral, ntari torig, livr l&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,    &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,      &apos;NCLIN&apos;, &apos;NCLIN.CODCONT = LG.CONTLIN&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;IES1&apos;,  &apos;IES1.CODIES1 = LG.CODDOC1 AND LG.ISIES = 1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;INTR1&apos;, &apos;INTR1.CODINTR1 = LG.CODDOC1 AND LG.ISINTR = 1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF1&apos;,    &apos;TRAN1&apos;, &apos;TRAN1.CODTRANSF1 = LG.CODDOC1 AND LG.ISTRANF = 1&apos;, 1);

  IF vInfoPart THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;, &apos;ACLI&apos;, &apos;ACLI.CODOBIECT  = LG.CODOBIECT AND ACLI.CODPART = LG.PARTENER&apos;, 1);
  END IF;
  IF vInfoOferte THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1&apos;, &apos;O1&apos;, &apos;O1.CODOFERTA1 = pkg_oferta.GetCodOferta1(LG.CODOBIECT, LG.DATADOC, LG.PARTENER, LG.locatielivr, LG.SUBUNITATEA, 50, LG.CANT)&apos;, 1);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA&apos;, &apos;O&apos;, &apos;O1.CODOFERTA = O.CODOFERTA&apos;);
  END IF;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NIRSTOC&apos;, &apos;NSMAX&apos;, &apos;NSMAX.CODNIRSTOC = LG.MAXCODNIRSTOC&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;, &apos;COMIS&apos;, &apos;LG.PARTCUSTODIE = COMIS.CODPART&apos;, 1);

  IF Coalesce(PKG_CATEGCONST.GETVALCONSTANTA(&apos;CUMULEZBCAR&apos;,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;, &apos;BCAR&apos;, &apos;BCAR.CODDOC1 = LG.CODDOC1 AND BCAR.TIPDOC = LG.TIPDOC&apos;, 1);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BCAREXT&apos;, &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  END IF;

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  --pkg_list_base_utils.UMPLE_TMP_NART1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NTVA1_LST;
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;lg.cant&apos;,&apos;lg.codobiect&apos;,sInsertDC,sSelectDC,sJoinDC);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, lg.datadoc )&apos;;
  END IF;

  IF PKG_LIST_SELECTGEST.DupaData THEN
    sCondDataI := &apos;
      AND   l.datalivr BETWEEN to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTGEST.DataIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTGEST.DataFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
    sCondDataT := sCondDataI;
  ELSIF PKG_LIST_SELECTGEST.LunaAnIni = PKG_LIST_SELECTGEST.LunaAnFin THEN
    sCondDataI := &apos;
      AND   (i.luna + i.an * 12) = &apos;||PKG_LIST_SELECTGEST.LunaAnIni||&apos; &apos;;
    sCondDataT := &apos;
      AND   (t.luna + t.an * 12) = &apos;||PKG_LIST_SELECTGEST.LunaAnIni||&apos; &apos;;
  ELSE
    sCondDataI := &apos;
      AND   (i.luna + i.an * 12) BETWEEN &apos;||PKG_LIST_SELECTGEST.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELECTGEST.LunaAnFin||&apos; &apos;;
    sCondDataT := &apos;
      AND   (t.luna + t.an * 12) BETWEEN &apos;||PKG_LIST_SELECTGEST.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELECTGEST.LunaAnFin||&apos; &apos;;
  END IF;

  IF    PKG_LIST_SELECTGEST.AduSerii = 1 THEN
    sColSerii := &apos;, To_Char(Coalesce(nser.tg, ns.tg), &apos;&apos;dd.mm.yyyy&apos;&apos;) tg, s.serie &apos;;
    sJoinSerii := &apos;
        LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
        LEFT JOIN nserii s on s.codserie = nser.codserie&apos;;
    sGrupSerii := &apos;,Coalesce(nser.tg, ns.tg), s.serie&apos;;
  ELSIF PKG_LIST_SELECTGEST.AduSerii = 2 THEN
    sColSerii := &apos;,
        vc2_nt_to_vc3200(CAST(COLLECT(To_Char(Coalesce(nser.tg, ns.tg), &apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY s.serie ) AS vc2_nt)) tg,
        CASE MAX(Coalesce(ns.tipserie,0))
          WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
          ELSE &apos;&apos;&apos;&apos;
        END serie &apos;;
    sJoinSerii := &apos;
        LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
        LEFT JOIN nserii s on s.codserie = nser.codserie&apos;;
  END IF;

  if NOT PKG_LIST_SELECTGEST.ToateGest THEN
    vFiltru := &apos;
    AND COALESCE(l1.codgestorig, lv.gest, n.gest) IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; ) &apos;;
  end if;

  --PKG_LIST_BASE_UTILS.CalculeazaPmpListe;
  sPMP := &apos;, lg.pmp, lg.pmpvaluta, lg.pmpdoc, lg.pmpvalutadoc &apos;;

  FOR i in 1..Coalesce(vMax,0) loop
    sInsertDC := sInsertDC||&apos;, CLS&apos;   ||to_char(i)||&apos;, CLSS&apos;  ||to_char(i);
    sSelectDC := sSelectDC||&apos;, CLSC.D&apos;||to_char(i)||&apos;, CLSC.S&apos;||to_char(i);
  END LOOP;

  IF Coalesce(vMax,0) &gt; 0 THEN
    sWithDC := sWithDC||&apos;
    Clase AS (
    SELECT codclasea &apos;;
    IF Coalesce(vMax,0) &gt; 0 THEN
      for i in 1..Coalesce(vMax,0) loop
        sWithDC := sWithDC ||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE &apos;&apos;&apos;&apos; end) d&apos;||to_char(i)||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN simbol ELSE &apos;&apos;&apos;&apos; end) s&apos;||to_char(i);
      end loop;
    END IF;
    sWithDC := sWithDC||&apos;
    FROM TMP_PROFIT_NCLASEA
    GROUP BY codclasea),&apos;;

    sJoinDC := sJoinDC||&apos;
    LEFT JOIN clase clsc ON clsc.codclasea = na.clasa&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc,NAV_FiltruLivr,
    DenArt,DenUM,DenGest,DenGestOrig,DenLGest,DenSub,SimbolCont,ContVenituri,ContCheltuieli,Document,PrefixDoc,NrDoc,DataDoc,NumeDoc,
    DocLivr, NRLIVR,DATALIVR,DENCARNETLIVR,SIMBCARNETLIVR,SERCARNETLIVR,
    TIPTVA,TIPTRANZ,
    CantIes,CantLivr,PMInreg,ValLivr,ValTVALivr,
    ProcAdaos,AdaosUnit,ValAdaos,
    PretRef, ProcAdaosRef,
    PretAch,ValAch, PUAchVal,
    PUMAX,
    PU,PU_Lei,ProcDisc,
    PIes,PIesLei,ValIes,ValIesLei,
    ProcTVA,ValTVA,ValTVALei,
    ValDisc,ValDiscLei,TVADisc,TVADiscLei,
    MonDoc,CURS,Destinatie,Serii,DataExp,
    DENIOART,CODEXTERNA,CODINTERNA,CODVAMAL,FURNIZOR,PRODUCATOR,OBSART,UM1,UM2,CANTUM1,CANTUM2,GARIES,GARART,MASA,VOLUM,
    SLIVR_TIP,SLIVR_DEN,SLIVR_ADR,SLIVR_LOC,SLIVR_JUD,SLIVR_TARA,SLIVR_ZONA,
    AGENT_DOC,GR_PRET,UPLIFT,Dim1,Dim2,Dim3,
    DENCLASEAS,DenClasaA,SimbClasaA,DenClasaP,SimbClasaP,
    DataAchiz,SerieLot,NrCertif,STipDoc,ObsDoc,Custodie,CENTRUCOST,
    ANDOC,LUNADOC,LUNA,
    IOARTINTERM, CONTINTERM, CONTVINTERM, CONTCINTERM,
    PIesDVal,
    PIesVal,MonTransf,CursTransf, CURS_REF, PMP, PMPVALUTA, PMPDOC, PMPVALUTADOC&apos;||sInsertDC||gUserFields||&apos;)&apos;;

  sSelectComun := &apos;
  WITH &apos;||sWithDC;

  sSelectIes := &apos;
    LG AS (
      SELECT
        1 isies, 0 istranf, 0 isintr,
        l.codlivr, i.codies coddoc, i.tipdoc, i.prefixdoc, Coalesce(i.curs,1) curs, Decode(i.cursdoc,NULL,1,0,1,i.cursdoc) cursdoc, i.nrdoc, i.datadoc, i.partener, i.an, i.luna,
        i.codgestprod, i.codsubunit, i.moneda, Coalesce(i1.codagentemulare,i.agent,0) agent, i.codlocatie locatielivr, i.subunitatea, Coalesce(i.monedatransf,0) monedatransf, i.tiptva, i.tiptranzactie,
        CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN Coalesce(i.contintermed,0) ELSE l1.contintermed END contintermed,
        Coalesce(dvi1.coddvi1,i1.codies1) codlinie,  i1.codies1 coddoc1, i1.indexlocal, i1.codobiect, Coalesce(lv.gest, n.gest, 0) gest, Coalesce(l1.codgestorig, lv.gest, n.gest, 0) gestorig,
        Coalesce(ns.codlocatie,0) codlocatie, l1.umsec, i1.obs obsart, i.delegat, i.obs obsdoc, i.custodie,
        CASE WHEN i.tipdoc IN (16,21) THEN (i1.pu - i1.tva / decode(i1.cant,0,1,i1.cant) ) ELSE i1.pu END pu,
        CASE
          WHEN i.tipdoc = 16 THEN i1.pu - Decode(i1.cant,0,0,Coalesce(i1.tva,0)/i1.cant)
          ELSE PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret)
        END *
        CASE
          WHEN I.TIPDOC &lt;&gt; 16 THEN 1
          WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
          WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
          ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, Coalesce(lv.codioart, ns.codioart), 1, i1.pu * i1.cant, i1.TVA)
        END pies,
        CASE
          WHEN i1.tva = 0 THEN 0
          WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = i1.tva THEN 0
          WHEN i.tipdoc IN (16,21) THEN i1.tva / (i1.pu * decode(i1.cant,0,1,i1.cant)-i1.tva)
          WHEN i1.pu * i1.cant = 0 THEN 0
          ELSE i1.tva / (i1.pu * decode(i1.cant,0,1,i1.cant ))
        END coef_tva,
        CASE
          WHEN I.TIPDOC &lt;&gt; 16 THEN 1
          WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
          WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
          ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, Coalesce(lv.codioart, ns.codioart), 2, i1.pu * i1.cant, i1.TVA)
        END * Coalesce(i1.tva,0) tvalin, Coalesce(i1.tva,0) tvau,
        l.carnetlivr, l.nrlivr, l.datalivr, i1.garantie, i1.codcentru, i1.contserv contlin,
        SUM(CASE WHEN IESVAL.CODLIVR1 &gt; 0 THEN IESVAL.VAL ELSE DECODE(lv.codlivrval,NULL,ns.pret,lv.pretinreg) * l1.cant END) * decode(i.tipdoc,15,-1,1) valinreg,
        SUM(DECODE(Coalesce(ns.tva,0),0,0,ns.pret*l1.cant*ns.tva/(1+ns.tva))) tvaneex,
        SUM(CASE WHEN IESVAL.CODLIVR1 &gt; 0 THEN IESVAL.VAL ELSE Coalesce(DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz)*l1.cant,0) END) * decode(i.tipdoc,15,-1,1) valachiz,
        SUM(Coalesce(ns.puval,0)*l1.cant) * decode(i.tipdoc,15,-1,1) valachizval,
        Coalesce(lv.codioart,ns.codioart) codioart, Coalesce(i1.pumaximal,MAX(ns.pumaximal)) pumaximal,
        i1.cant * decode(i.tipdoc,15,-1,1) canti, sum(l1.cant) * decode(i.tipdoc,15,-1,1) cant, sum(l1.cantum1) * decode(i.tipdoc,15,-1,1) cantum1, sum(l1.cantum2) * decode(i.tipdoc,15,-1,1) cantum2,
        ns.d1, ns.d2, ns.d3, ns.tipserie, Coalesce(ns.furn,0) furn, Coalesce(ns.codgestprod,0) gestfurn,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        ns.DataAchiz, ns.SerieLot, max(l1.pmpvaluta) pmpvaluta, max(l1.pmpdoc) pmpdoc, max(l1.pmpvalutadoc) pmpvalutadoc, max(l1.pmp) pmp, max(l1.codnirstoc) maxcodnirstoc,
        SUM(CASE WHEN IESVAL.CODLIVR1 &gt; 0 THEN IESVAL.VAL ELSE 0 END) viesdval, SUM(CASE WHEN IESVAL.CODLIVR1 &gt; 0 THEN l1.cant ELSE 0 END) ciesdval, i.partcustodie &apos;||sColSerii||&apos;
      FROM iesiri1 i1
        INNER JOIN iesiri i  ON i.codies = i1.codies
        INNER JOIN livr   l  ON l.codies = i1.codies
        INNER JOIN livr1  l1 ON l1.codies1 = i1.codies1 AND l1.codlivr = l.codlivr
        LEFT JOIN (
          SELECT SUM(L1.CANT * Decode(LV.CODLIVR1,NULL,NS.PRET - Coalesce(NS.ADAOS,0),Coalesce(LV.PRETACHIZ,0))) VAL, IVL.CODLIVR1
          FROM IESVALLINK IVL
            INNER JOIN IESIRI1 I1 ON IVL.CODIES1 = I1.CODIES1
            INNER JOIN LIVR    L  ON L.CODIES    = I1.CODIES
            INNER JOIN LIVR1   L1 ON L1.CODLIVR  = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
            LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT  JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
          GROUP BY IVL.CODLIVR1
        ) IESVAL ON IESVAL.CODLIVR1 = L1.CODLIVR1
        LEFT JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT JOIN nirstoc1 ns1  ON ns1.codnirstoc  = l1.codnirstoc
        LEFT JOIN nirstoc  nsin ON nsin.codnirstoc = ns1.codnirstocorig
        LEFT JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT JOIN intrari1 int1 ON int1.codintr1   = Coalesce(dvi1.codintr1, nsin.codintr1)
        LEFT JOIN nir      n    ON n.codnir        = ns.codnir&apos;||
        sJoinSerii||&apos;
      WHERE (l.codies IS NOT NULL) AND (l.operat = 1) AND (l.anulat = 0) &apos;||
        sCondDataI||
        vFiltru||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;)||&apos;
      GROUP BY
        i.codies, i.tipdoc, i.prefixdoc, i.curs, i.cursdoc, i.nrdoc, i.datadoc, i.partener, i.an, i.luna, i.obs, i.custodie, i.tiptva, i.tiptranzactie, i.valdoc, i.valdiscount,
        i.tvadoc, i.tvadiscount, i.codgestprod, i.codsubunit, i.moneda, i.agent, i.delegat, i.codlocatie, i.subunitatea, i.monedatransf, i.contintermed, i.partcustodie, dvi1.coddvi1,
        i1.codies1, i1.indexlocal, i1.tiplinie, i1.codobiect, i1.tva, i1.pretorig, i1.pu, i1.cant, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, i1.garantie, i1.obs, i1.pumaximal, i1.addim, i1.codcentru, i1.contserv, i1.codagentemulare,
        l.codlivr, l.carnetlivr, l.nrlivr, l.datalivr, l1.umsec, SIGN(l1.cant), i.contintermed, l1.contintermed, Coalesce(lv.codioart, ns.codioart),
        COALESCE(l1.codgestorig, lv.gest, n.gest, 0), COALESCE(lv.gest, n.gest, 0),
        Coalesce(ns.codlocatie,0), Coalesce(ns.furn,0), Coalesce(ns.codgestprod,0), ns.tipserie, ns.d1, ns.d2, ns.d3, ns.DataAchiz, ns.SerieLot &apos;||sGrupSerii||&apos;
    )
  SELECT
    lg.coddoc, lg.tipdoc,
    PKG_LIST_BASE_SERII.FILTRU_LIVR(lg.tipdoc,lg.coddoc,lg.codlinie,lg.tipserie,lg.umsec,lg.codioart,lg.gest,lg.codlocatie,lg.gestfurn,lg.furn,Coalesce(lg.d1,0),Coalesce(lg.d2,0),Coalesce(lg.d3,0),Coalesce(to_char(lg.dataachiz),&apos;&apos;0&apos;&apos;)),
    nao.denumire, u1.den_um1, g.den_gest, go.den_gest, nl.denumire, ss.den_subunit, nc.simbol, ncv.simbol, ncc.simbol,
    lg.prefixdoc||&apos;&apos;.&apos;&apos;||lg.nrdoc||&apos;&apos; / &apos;&apos;||lg.datadoc||&apos;&apos; - &apos;&apos;||DECODE(lg.tipdoc,15,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,sd.den_subunit,24,gd.den_gest,np.den_part),
    lg.prefixdoc, lg.nrdoc, lg.datadoc, PKG_LIST_BASE_UTILS.decode_tipdoc(lg.tipdoc),
    &apos;&apos;LIVR &apos;&apos;||lg.nrlivr||&apos;&apos; / &apos;&apos;||lg.datalivr, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie,
    DECODE(lg.tiptva,1,&apos;&apos;Taxare Normala&apos;&apos;,2,&apos;&apos;Taxare Inversa&apos;&apos;,3,&apos;&apos;Taxare Triunghiulara&apos;&apos;,4,&apos;&apos;Prestari in afara Romaniei&apos;&apos;,5,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;,
           6,&apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;,7,&apos;&apos;regim special de scutire art 311 CF&apos;&apos;,8,&apos;&apos;regim special de scutire art 312 CF&apos;&apos;),
    CASE
      WHEN LG.TIPDOC = 24 THEN &apos;&apos;Tranzactie interna&apos;&apos;
      ELSE DECODE(lg.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Livrare intracomunitara&apos;&apos;,3,&apos;&apos;Export&apos;&apos;)
    END,
    lg.cant / u1.paritate, lg.cant / u1.paritate, lg.valinreg * u1.paritate / decode(lg.cant,0,1,lg.cant ), lg.valinreg, lg.tvaneex,
    round(DECODE(lg.valachiz,0,100,(lg.pies*lg.cant*lg.curs-lg.valachiz)*100/lg.valachiz),2), (lg.pies*lg.curs-lg.valachiz/decode(lg.cant,0,1,lg.cant))*u1.paritate, lg.pies*lg.cant*lg.curs-lg.valachiz,nao1.pretreferinta, round(DECODE(nao1.pretreferinta,NULL,NULL,0,100,(lg.pies*lg.curs-nao1.pretreferinta)*100/nao1.pretreferinta),2) ProcAdaosRef,
    lg.valachiz * u1.paritate / decode(lg.cant,0,1,lg.cant), lg.valachiz, lg.valachizval * u1.paritate / decode(lg.cant,0,1,lg.cant),
    CASE
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal
      ELSE NULL
    END pumax,
    lg.pu, lg.pu * lg.curs PU_Lei, round(DECODE(lg.pu,0,0,(lg.pies - lg.pu) * 100 / decode(lg.pu,0,1,lg.pu )),2) ProcDisc,
    lg.pies * u1.paritate PIes, lg.pies * u1.paritate * lg.curs PIesLei, lg.pies * lg.cant ValIes, lg.pies * lg.cant * lg.curs ValIesLei,
    lg.coef_tva * 100 ProcTVA,
    CASE
      WHEN lg.tipdoc = 15 AND lg.canti = 0 THEN 0
      WHEN lg.tipdoc = 15 THEN lg.tvalin*lg.cant/lg.canti
      ELSE lg.cant * lg.pies * lg.coef_tva
    END ValTVA,
    CASE
      WHEN lg.tipdoc = 15 AND lg.canti = 0 THEN 0
      WHEN lg.tipdoc = 15 THEN lg.tvalin*lg.cant/lg.canti
      ELSE lg.cant * lg.pies * lg.coef_tva
    END * lg.curs ValTVALei,
    lg.cant * (lg.pies - lg.pu) ValDisc, lg.curs * lg.cant * (lg.pies - lg.pu) ValDiscLei,
    CASE
      WHEN lg.tipdoc = 15 AND lg.canti = 0 THEN 0
      WHEN lg.tipdoc = 15 THEN (lg.tvalin-lg.tvau)*lg.cant/lg.canti
      ELSE lg.coef_tva * lg.cant * (lg.pies - lg.pu)
    END TVADisc,
    CASE
      WHEN lg.tipdoc = 15 AND lg.canti = 0 THEN 0
      WHEN lg.tipdoc = 15 THEN (lg.tvalin-lg.tvau)*lg.cant/lg.canti
      ELSE lg.coef_tva * lg.cant * (lg.pies - lg.pu)
    END * lg.curs TVADiscLei,
    mon.simbol, lg.curs, DECODE(lg.tipdoc,15,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,sd.den_subunit,24,gd.den_gest,np.den_part), lg.serie, lg.tg,
    io.den_ioart, nao.codextern, nao.codintern, nao.codvamal, DECODE(lg.furn,0,gfurn.den_gest,furn.den_part), prod.den_part, lg.obsart, um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, lg.garantie, nao.lunigarantie, nao.masa, nao.volum,
    tsl.denumire, slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal), locl.den_localit, judl.den_judet, taral.den_tara, zonal.den_zona,
    CASE WHEN ag_doc.codpers = 0 THEN ag_doc.nume ELSE ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume END, nao1.grupa, nao1.uplift,lg.d1,lg.d2,lg.d3,
    cs.den_claseas, ca.den_clasea, ca.simbol, DECODE(lg.tipdoc,24,cg.den_claseg,cp.den_clasep), DECODE(lg.tipdoc,24,cg.simbol,cp.simbol),
    lg.DataAchiz,lg.SerieLot,lg.NrCertif, pkg_list_base_utils.decode_tipdoc_scurt(lg.tipdoc), lg.obsdoc,DECODE(lg.custodie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), cc.denumire,
    lg.an andoc, lg.luna lunadoc, to_char(lg.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(lg.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(lg.Luna) luna,
    ioi.den_ioart, nci.simbol, ncvi.simbol, ncci.simbol,
    CASE WHEN Coalesce(lg.ciesdval,0) = 0 THEN NULL ELSE lg.viesdval/lg.ciesdval*u1.paritate END PIesDVal,
    DECODE(lg.monedatransf,0,0,lg.pies * u1.paritate/lg.cursdoc), DECODE(lg.monedatransf,0,NULL, mt.simbol), lg.cursdoc&apos;||sCursRef||sPMP||sSelectDC||gUserAlias||&apos;
  FROM lg
    INNER JOIN num1 u1       ON u1.codum1       = lg.umsec
    INNER JOIN nartobj nao   ON nao.codobiect   = lg.codobiect
    INNER JOIN nart na       ON na.codarticol   = nao.codarticol
    LEFT  JOIN livr l        ON l.codlivr       = lg.codlivr
    LEFT  JOIN NUM UM1       ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2       ON um2.codum       = na.um2
    LEFT  JOIN ngest g       ON g.codgest       = lg.gest
    LEFT  JOIN ngest go      ON go.codgest      = lg.gestorig
    LEFT  JOIN nlocatii nl   ON nl.codlocatie   = lg.codlocatie
    LEFT  JOIN nsubunit ss   ON ss.codsubunit   = lg.subunitatea
    LEFT  JOIN doccarnete dc ON dc.codcarnet    = lg.carnetlivr
    LEFT  JOIN nmonede mon   ON mon.codmoneda   = lg.moneda
    LEFT  JOIN nmonede mt    ON mt.codmoneda    = lg.monedatransf
    LEFT  JOIN nclasea ca    ON ca.codclasea    = na.clasa
    LEFT  JOIN nclaseas cs   ON cs.codclaseas   = na.clasastatist
    LEFT  JOIN ioart io      ON io.codioart     = lg.codioart
    LEFT  JOIN ioart1 io1    ON io1.codioart    = lg.codioart AND (lg.an*12+lg.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT  JOIN ncont nc      ON nc.codcont      = io1.cont
    LEFT  JOIN centrecost cc ON cc.codcentru    = lg.codcentru
    LEFT  JOIN ncont ncv     ON ncv.codcont     = Coalesce(io1.venituri,0)
    LEFT  JOIN ncont ncc     ON ncc.codcont     = Coalesce(io1.cheltuieli,0)
    LEFT  JOIN ioart ioi     ON ioi.codioart    = lg.contintermed
    LEFT  JOIN ioart1 ioi1   ON ioi1.codioart   = lg.contintermed AND (lg.an*12+lg.luna) BETWEEN ioi1.ALStart and ioi1.ALStop
    LEFT  JOIN ncont nci     ON nci.codcont     = ioi1.cont
    LEFT  JOIN ncont ncvi    ON ncvi.codcont    = Coalesce(ioi1.venituri,0)
    LEFT  JOIN ncont ncci    ON ncci.codcont    = Coalesce(ioi1.cheltuieli,0)
    LEFT  JOIN npart np      ON np.codpart      = lg.partener
    LEFT  JOIN nclasep cp    ON cp.codclasep    = np.codclasa
    LEFT  JOIN ngest gd      ON gd.codgest      = lg.codgestprod
    LEFT  JOIN nclaseg cg    ON cg.codclaseg    = gd.codclasa
    LEFT  JOIN nsubunit sd   ON sd.codsubunit   = lg.codsubunit
    LEFT  JOIN NAGENDA SLIVR ON slivr.codagenda = lg.locatielivr
    LEFT  JOIN NLOCALIT LOCl ON locl.codlocalit = slivr.codlocalit
    LEFT  JOIN NJUDET JUDl   ON judl.codjudet   = locl.codjudet
    LEFT  JOIN NZONE ZONAl   ON zonal.codzona   = locl.codzona
    LEFT  JOIN NTARI TARAl   ON taral.codtara   = locl.codtara
    LEFT  JOIN NTIPSEDII tsl ON tsl.codtipsediu = slivr.codtipsediu
    LEFT  JOIN npart prod    ON prod.codpart    = nao.codproducator
    LEFT  JOIN npart furn    ON furn.codpart    = lg.furn
    LEFT  JOIN ngest gfurn   ON gfurn.codgest   = lg.gestfurn
    LEFT  JOIN NPERS AG_DOC  ON ag_doc.codpers  = lg.agent
    LEFT  JOIN nparttr del   ON lg.delegat      = del.codparttr
    LEFT  JOIN NTARI TOrig   ON TOrig.CodTara   = nao.taraorigine
    LEFT  JOIN nartobj1 nao1 ON nao1.codobiect  = lg.codobiect AND (lg.an*12+lg.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN nartamb aa    ON aa.codobiect    = lg.codobiect AND aa.umsec = lg.umsec
    LEFT  JOIN pretm pm      ON pm.codobiect    = lg.codobiect AND pm.subunitatea = lg.subunitatea AND pm.implicit = 1&apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE lg.cant &lt;&gt; 0&apos;;

  sSelectInt := &apos;
    LG AS (
      SELECT
        0 isies, 0 istranf, 1 isintr,
        l.codlivr, i.codintr coddoc, i.tipdoc, i.prefixdoc, Coalesce(i.curs,1) curs, i.nrdoc, i.datadoc, i.partener, i.an, i.luna,
        i.codgestprod, i.codsubunit, i.moneda, 0 agent, i.codlocatie locatielivr, i.subunitatea, i.tiptva, i.tiptranzactie,
        i1.codintr1 coddoc1, i1.indexlocal, i1.codobiect, Coalesce(lv.gest, n.gest,0) gest, Coalesce(lv.gest, n.gest,0) gestorig,
        Coalesce(ns.codlocatie,0) codlocatie, l1.umsec, i1.obs obsart, 0 delegat, i.obs obsdoc,
        CASE WHEN i.tipdoc = 3 THEN (i1.pu - i1.tva / decode(i1.cant,0,1,i1.cant) ) ELSE i1.pu END pu,
        i1.pretorig * Coalesce(i1.coefdiscmaj,1) * (CASE WHEN i.tipdoc = 3 THEN (1 - i1.tva / decode((i1.cant * i1.pu),0,1,(i1.cant * i1.pu) )  ) ELSE 1 END)  pies,
        CASE
          WHEN i1.tva = 0 THEN 0
          WHEN i.tipdoc = 3 AND i1.pu * i1.cant = i1.tva THEN 0
          WHEN i.tipdoc = 3 THEN i1.tva / (i1.pu * decode(i1.cant,0,1,i1.cant)-i1.tva)
          WHEN i1.pu * i1.cant = 0 THEN 0
          ELSE i1.tva / (i1.pu * decode(i1.cant,0,1,i1.cant ))
        END coef_tva,
        l.carnetlivr, l.nrlivr, l.datalivr, i1.codcentru, i1.contserv contlin,
        SUM(DECODE(lv.codlivrval,NULL,ns.pret,lv.pretinreg) * l1.cant) valinreg,
        SUM(DECODE(Coalesce(ns.tva,0),0,0,ns.pret*l1.cant*ns.tva/(1+ns.tva))) tvaneex,
        SUM(Coalesce(DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz)*l1.cant,0)) valachiz,
        SUM(Coalesce(ns.puval,0)*l1.cant) valachizval,
        Coalesce(lv.codioart,ns.codioart) codioart, Coalesce(i1.pumaximal,MAX(ns.pumaximal)) pumaximal,
        i1.cant canti, sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2,
        ns.d1, ns.d2, ns.d3, ns.tipserie, Coalesce(ns.furn,0) furn, Coalesce(ns.codgestprod,0) gestfurn,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        ns.DataAchiz, ns.SerieLot, max(l1.pmpvaluta) pmpvaluta, max(l1.pmpdoc) pmpdoc, max(l1.pmpvalutadoc) pmpvalutadoc, max(l1.pmp) pmp, max(l1.codnirstoc) maxcodnirstoc,
        0 PARTCUSTODIE&apos;||sColSerii||&apos;
      FROM intrari1 i1
        INNER JOIN intrari  i    ON i.codintr = i1.codintr
        INNER JOIN livr     l    ON l.codintr = i1.codintr
        LEFT  JOIN dvi1          ON dvi1.codintr1   = i1.codintr1
        LEFT  JOIN livr1    l1   ON l1.codlivr      = l.codlivr
        LEFT  JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT  JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT  JOIN nirstoc1 ns1  ON ns1.codnirstoc  = l1.codnirstoc
        LEFT  JOIN nirstoc  nsin ON nsin.codnirstoc = ns1.codnirstocorig
        LEFT  JOIN dvi1     d1   ON d1.coddvi1 = nsin.coddvi1
        LEFT  JOIN intrari1 int1 ON int1.codintr1   = Coalesce(d1.codintr1, nsin.codintr1)
        LEFT  JOIN nir      n    ON n.codnir        = ns.codnir&apos;||
        sJoinSerii||&apos;
      WHERE (l.codintr IS NOT NULL) AND (l.operat = 1) AND (l.anulat = 0)
      AND (l1.codintr1 = i1.codintr1 OR l1.coddvi1 = dvi1.coddvi1) &apos;||
      sCondDataI||
      vFiltru||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;)||&apos;
      GROUP BY
        i.codintr, i.tipdoc, i.prefixdoc, i.curs, i.nrdoc, i.datadoc, i.partener, i.an, i.luna, i.obs,
        i.codgestprod, i.codsubunit, i.moneda, i.codlocatie, i.subunitatea, i.tiptva, i.tiptranzactie,
        i1.codintr1, i1.indexlocal, i1.codobiect, i1.tva, i1.pretorig, i1.pu, i1.cant, i1.coefdiscmaj, i1.obs, i1.pumaximal, i1.codcentru, i1.contserv,
        l.codlivr, l.carnetlivr, l.nrlivr, l.datalivr, l1.umsec, SIGN(l1.cant), Coalesce(lv.codioart,ns.codioart), Coalesce(lv.gest, n.gest,0),
        Coalesce(ns.codlocatie,0), Coalesce(ns.furn,0), Coalesce(ns.codgestprod,0), ns.tipserie, ns.d1, ns.d2, ns.d3, ns.DataAchiz, ns.SerieLot &apos;||sGrupSerii||&apos;
    )
  SELECT
    lg.coddoc, lg.tipdoc,
    PKG_LIST_BASE_SERII.FILTRU_LIVR(lg.tipdoc,lg.coddoc,lg.coddoc1,lg.tipserie,lg.umsec,lg.codioart,lg.gest,lg.codlocatie,lg.gestfurn,lg.furn,Coalesce(lg.d1,0),Coalesce(lg.d2,0),Coalesce(lg.d3,0),Coalesce(to_char(lg.dataachiz),&apos;&apos;0&apos;&apos;)),
    nao.denumire, u1.den_um1, g.den_gest, go.den_gest, nl.denumire, ss.den_subunit, nc.simbol, ncv.simbol, ncc.simbol,
    lg.prefixdoc||&apos;&apos;.&apos;&apos;||lg.nrdoc||&apos;&apos; / &apos;&apos;||lg.datadoc||&apos;&apos; - &apos;&apos;||DECODE(lg.tipdoc,6,sd.den_subunit,7,gd.den_gest,np.den_part),
    lg.prefixdoc, lg.nrdoc, lg.datadoc, PKG_LIST_BASE_UTILS.decode_tipdoc(lg.tipdoc),
    &apos;&apos;LIVR &apos;&apos;||lg.nrlivr||&apos;&apos; / &apos;&apos;||lg.datalivr, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie,
    DECODE(lg.tiptva,1,&apos;&apos;Taxare normala&apos;&apos;,2,&apos;&apos;Taxare inversa&apos;&apos;,3,&apos;&apos;Tranzactie triunghiulara&apos;&apos;,4,&apos;&apos;Taxare normala ProRata&apos;&apos;,5,&apos;&apos;Regim special (art. 1521, 1522)&apos;&apos;,
           6,&apos;&apos;Regim special de scutire art 311 CF&apos;&apos;,7,&apos;&apos;Regim special de scutire art 312 CF&apos;&apos;,8,&apos;&apos;Achizitii UE de bunuri cu instalare/montaj&apos;&apos;),
    DECODE(lg.tipdoc, 5,&apos;&apos;Import&apos;&apos;, DECODE(lg.tiptranzactie,1,&apos;&apos;Tranzactie interna&apos;&apos;,2,&apos;&apos;Achizitie intracomunitara&apos;&apos;,3,&apos;&apos;Import servicii&apos;&apos;)),
    lg.cant / u1.paritate, lg.cant / u1.paritate, lg.valinreg * u1.paritate / decode(lg.cant,0,1,lg.cant ), lg.valinreg, lg.tvaneex,
    round(DECODE(lg.valachiz,0,100,(lg.pies*lg.cant*lg.curs-lg.valachiz)*100/lg.valachiz),2), (lg.pies*lg.curs-lg.valachiz/decode(lg.cant,0,1,lg.cant))*u1.paritate, lg.pies*lg.cant*lg.curs-lg.valachiz,nao1.pretreferinta, round(DECODE(nao1.pretreferinta,NULL,NULL,0,100,(lg.pies*lg.curs-nao1.pretreferinta)*100/nao1.pretreferinta),2) ProcAdaosRef,
    lg.valachiz * u1.paritate / decode(lg.cant,0,1,lg.cant), lg.valachiz, lg.valachizval * u1.paritate / decode(lg.cant,0,1,lg.cant),
    CASE
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal
      ELSE NULL
    END pumax,
    lg.pu, lg.pu * lg.curs, round(DECODE(lg.pu,0,0,(lg.pies - lg.pu) * 100 / decode(lg.pu,0,1,lg.pu )),2),
    lg.pies * u1.paritate, lg.pies * u1.paritate * lg.curs, lg.pies * lg.cant, lg.pies * lg.cant * lg.curs,
    lg.coef_tva * 100, lg.cant * lg.pies * lg.coef_tva, lg.cant * lg.pies * lg.coef_tva * lg.curs,
    lg.cant * (lg.pies - lg.pu), lg.curs * lg.cant * (lg.pies - lg.pu), lg.coef_tva * lg.cant * (lg.pies - lg.pu), lg.coef_tva * lg.curs * lg.cant * (lg.pies - lg.pu),
    mon.simbol, lg.curs, DECODE(lg.tipdoc,6,sd.den_subunit,7,gd.den_gest,np.den_part), lg.serie, lg.tg,
    io.den_ioart, nao.codextern, nao.codintern, nao.codvamal, DECODE(lg.furn,0,gfurn.den_gest,furn.den_part), prod.den_part, lg.obsart, um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, 0, nao.lunigarantie, nao.masa, nao.volum,
    tsl.denumire, slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal), locl.den_localit, judl.den_judet, taral.den_tara, zonal.den_zona,
    CASE WHEN ag_doc.codpers = 0 THEN ag_doc.nume ELSE ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume END, nao1.grupa, nao1.uplift,lg.d1,lg.d2,lg.d3,
    cs.den_claseas, ca.den_clasea, ca.simbol, DECODE(lg.tipdoc,7,cg.den_claseg,cp.den_clasep), DECODE(lg.tipdoc,7,cg.simbol,cp.simbol),
    lg.DataAchiz,lg.SerieLot,lg.NrCertif, pkg_list_base_utils.decode_tipdoc_scurt(lg.tipdoc), lg.obsdoc, &apos;&apos;Nu&apos;&apos; custodie, cc.denumire,
    lg.an andoc, lg.luna lunadoc, to_char(lg.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(lg.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(lg.Luna) luna,
    NULL, NULL, NULL, NULL,
    NULL PIesDVal,
    0, NULL, NULL &apos;||sCursRef||sPMP||sSelectDC||gUserAlias||&apos;
  FROM lg
    INNER JOIN num1 u1       ON u1.codum1       = lg.umsec
    INNER JOIN nartobj nao   ON nao.codobiect   = lg.codobiect
    INNER JOIN nart na       ON na.codarticol   = nao.codarticol
    LEFT  JOIN livr l        ON l.codlivr       = lg.codlivr
    LEFT  JOIN NUM UM1       ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2       ON um2.codum       = na.um2
    LEFT  JOIN ngest g       ON g.codgest       = lg.gest
    LEFT  JOIN ngest go      ON go.codgest      = lg.gestorig
    LEFT  JOIN nlocatii nl   ON nl.codlocatie   = lg.codlocatie
    LEFT  JOIN nsubunit ss   ON ss.codsubunit   = lg.subunitatea
    LEFT  JOIN doccarnete dc ON dc.codcarnet    = lg.carnetlivr
    LEFT  JOIN nmonede mon   ON mon.codmoneda   = lg.moneda
    LEFT  JOIN nclasea ca    ON ca.codclasea    = na.clasa
    LEFT  JOIN nclaseas cs   ON cs.codclaseas   = na.clasastatist
    LEFT  JOIN ioart io      ON io.codioart     = lg.codioart
    LEFT  JOIN ioart1 io1    ON io1.codioart    = lg.codioart AND (lg.an*12+lg.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT  JOIN ncont nc      ON nc.codcont      = io1.cont
    LEFT  JOIN centrecost cc ON cc.codcentru    = lg.codcentru
    LEFT  JOIN ncont ncv     ON ncv.codcont     = Coalesce(io1.venituri,0)
    LEFT  JOIN ncont ncc     ON ncc.codcont     = Coalesce(io1.cheltuieli,0)
    LEFT  JOIN npart np      ON np.codpart      = lg.partener
    LEFT  JOIN nclasep cp    ON cp.codclasep    = np.codclasa
    LEFT  JOIN nparttr del   ON lg.delegat      = del.codparttr
    LEFT  JOIN ngest gd      ON gd.codgest      = lg.codgestprod
    LEFT  JOIN nclaseg cg    ON cg.codclaseg    = gd.codclasa
    LEFT  JOIN nsubunit sd   ON sd.codsubunit   = lg.codsubunit
    LEFT  JOIN NAGENDA SLIVR ON slivr.codagenda = lg.locatielivr
    LEFT  JOIN NLOCALIT LOCl ON locl.codlocalit = slivr.codlocalit
    LEFT  JOIN NJUDET JUDl   ON judl.codjudet   = locl.codjudet
    LEFT  JOIN NZONE ZONAl   ON zonal.codzona   = locl.codzona
    LEFT  JOIN NTARI TARAl   ON taral.codtara   = locl.codtara
    LEFT  JOIN NTIPSEDII tsl ON tsl.codtipsediu = slivr.codtipsediu
    LEFT  JOIN npart prod    ON prod.codpart    = nao.codproducator
    LEFT  JOIN npart furn    ON furn.codpart    = lg.furn
    LEFT  JOIN ngest gfurn   ON gfurn.codgest   = lg.gestfurn
    LEFT  JOIN NPERS AG_DOC  ON ag_doc.codpers  = lg.agent
    LEFT  JOIN NTARI TOrig   ON TOrig.CodTara   = nao.taraorigine
    LEFT  JOIN nartobj1 nao1 ON nao1.codobiect  = lg.codobiect AND (lg.an*12+lg.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN nartamb aa    ON aa.codobiect    = lg.codobiect AND aa.umsec = lg.umsec
    LEFT  JOIN pretm pm      ON pm.codobiect    = lg.codobiect AND pm.subunitatea = lg.subunitatea AND pm.implicit = 1&apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE lg.cant &lt;&gt; 0&apos;;

  sSelectT := &apos;
    LG AS (
      SELECT
        0 isies, 1 istranf, 0 isintr,
        l.codlivr, t.codtransf coddoc, t.tipdoc, t.prefixdoc, t.nrdoc, t.datadoc, 0 partener, t.an, t.luna, t.subunitatea,
        nd.gest gestd, Coalesce(nsd.codlocatie,0) codlocatied, 0 moneda, 0 agent, 0 locatielivr,
        t1.codtransf1 coddoc1, t1.indexlocal, t1.codobiect, Coalesce(lv.gest, n.gest,0) gest, Coalesce(lv.gest, n.gest,0) gestorig,
        Coalesce(ns.codlocatie,0) codlocatie, t1.umsec, t1.pu, dbms_lob.substr(t1.obs,300,1) obsart, t.obs obsdoc,
        CASE WHEN t1.tva = 0 THEN 0 WHEN t1.pu * t1.cant = 0 THEN 0 ELSE t1.tva / decode( (t1.pu * t1.cant),0,1,(t1.pu * t1.cant) )END coef_tva,
        l.carnetlivr, l.nrlivr, l.datalivr, t.delegat, t1.codcentru, t1.codcont contlin,
        SUM(DECODE(lv.codlivrval,NULL,ns.pret,lv.pretinreg) * l1.cant) valinreg,
        SUM(DECODE(Coalesce(ns.tva,0),0,0,ns.pret*l1.cant*ns.tva/decode( (1+ns.tva),0,1,(1+ns.tva) ))) tvaneex,
        SUM(Coalesce(DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz)*l1.cant,0)) valachiz,
        SUM(Coalesce(ns.puval,0)*l1.cant) valachizval,
        Coalesce(lv.codioart,ns.codioart) codioart, Coalesce(t1.pumaximal,MAX(ns.pumaximal)) pumaximal,
        t1.cant cantt, sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2,
        ns.d1, ns.d2, ns.d3, ns.tipserie, Coalesce(ns.furn,0) furn, Coalesce(ns.codgestprod,0) gestfurn,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        ns.DataAchiz, ns.SerieLot, max(l1.pmpvaluta) pmpvaluta, max(l1.pmpdoc) pmpdoc, max(l1.pmpvalutadoc) pmpvalutadoc,max(l1.pmp) pmp, max(l1.codnirstoc) maxcodnirstoc,
        0 PARTCUSTODIE&apos;||sColSerii||&apos;
      FROM transf1 t1
        INNER JOIN transf   t    ON t.codtransf     = t1.codtransf
        INNER JOIN livr     l    ON l.codtransf     = t1.codtransf
        INNER JOIN livr1    l1   ON l1.codies1      = t1.codtransf1 AND l1.codlivr = l.codlivr
        LEFT  JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT  JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT  JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT  JOIN nirstoc  nsd  ON nsd.codlivr1    = l1.codlivr1
        LEFT  JOIN nirstoc1 ns1  ON ns1.codnirstoc  = l1.codnirstoc
        LEFT  JOIN nirstoc  nsin ON nsin.codnirstoc = ns1.codnirstocorig
        LEFT  JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT  JOIN intrari1 int1 ON int1.codintr1   = Coalesce(dvi1.codintr1, nsin.codintr1)
        LEFT  JOIN nir      nd   ON nd.codnir       = nsd.codnir&apos;||
        sJoinSerii||&apos;
      WHERE (l.codtransf IS NOT NULL)  AND (l.operat = 1) AND (l.anulat = 0) &apos;||
      sCondDataT||
      vFiltru||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;T&apos;)||&apos;
      GROUP BY
        t.codtransf, t.tipdoc, t.prefixdoc, t.nrdoc, t.datadoc, t.an, t.luna, t.subunitatea, t.delegat, t.obs,
        t1.codtransf1, t1.indexlocal, t1.codobiect, t1.tva, t1.pu, t1.cant, t1.umsec, dbms_lob.substr(t1.obs,300,1), t1.pumaximal, t1.codcentru, t1.codcont,
        l.codlivr, l.carnetlivr, l.nrlivr, l.datalivr, l1.umsec, SIGN(l1.cant), Coalesce(lv.codioart, ns.codioart), Coalesce(lv.gest, n.gest,0),
        Coalesce(ns.codlocatie,0), Coalesce(ns.furn,0), Coalesce(ns.codgestprod,0), nd.gest, nsd.codlocatie, ns.tipserie, ns.d1, ns.d2, ns.d3, ns.DataAchiz, ns.SerieLot &apos;||sGrupSerii||&apos;
    )
  SELECT
    lg.coddoc, lg.tipdoc,
    PKG_LIST_BASE_SERII.FILTRU_LIVR(lg.tipdoc,lg.coddoc,lg.coddoc1,lg.tipserie,lg.umsec,lg.codioart,lg.gest,lg.codlocatie,lg.gestfurn,lg.furn,Coalesce(lg.d1,0),Coalesce(lg.d2,0),Coalesce(lg.d3,0),Coalesce(to_char(lg.dataachiz),&apos;&apos;0&apos;&apos;), lg.gestd, lg.codlocatied),
    nao.denumire, u1.den_um1, g.den_gest, go.den_gest, nl.denumire, ss.den_subunit, nc.simbol, ncv.simbol, ncc.simbol,
    lg.prefixdoc||&apos;&apos;.&apos;&apos;||lg.nrdoc||&apos;&apos; / &apos;&apos;||lg.datadoc||&apos;&apos; - &apos;&apos;||DECODE(lg.codlocatied,0,gd.den_gest,gd.den_gest ||&apos;&apos; (&apos;&apos;||nld.denumire||&apos;&apos;)&apos;&apos;),
    lg.prefixdoc, lg.nrdoc, lg.datadoc, PKG_LIST_BASE_UTILS.decode_tipdoc(lg.tipdoc),
    &apos;&apos;LIVR &apos;&apos;||lg.nrlivr||&apos;&apos; / &apos;&apos;||lg.datalivr, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie,
    NULL,
    &apos;&apos;Tranzactie interna&apos;&apos; ,
    lg.cant / u1.paritate, lg.cant / u1.paritate, lg.valinreg * u1.paritate / decode(lg.cant,0,1,lg.cant), lg.valinreg, lg.tvaneex,
    round(DECODE(lg.valachiz,0,100,(lg.pu*lg.cant-lg.valachiz)*100/decode(lg.valachiz,0,1,lg.valachiz )),2), (lg.pu-lg.valachiz/DECODE(lg.cant,0,1,lg.cant))*u1.paritate, lg.pu*lg.cant-lg.valachiz, nao1.pretreferinta, round(DECODE(nao1.pretreferinta,NULL,NULL,0,100,(lg.pu-nao1.pretreferinta)*100/nao1.pretreferinta),2) ProcAdaosRef,
    lg.valachiz * u1.paritate / DECODE(lg.cant,0,1,lg.cant), lg.valachiz, lg.valachizval * u1.paritate / DECODE(lg.cant,0,1,lg.cant),
    CASE
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal
      ELSE NULL
    END pumax,
    lg.pu, lg.pu, 0,
    lg.pu * u1.paritate, lg.pu * u1.paritate, lg.pu * lg.cant, lg.pu * lg.cant,
    lg.coef_tva * 100, lg.cant * lg.pu * lg.coef_tva, lg.cant * lg.pu * lg.coef_tva,
    0, 0, 0, 0,
    mon.simbol, 1, DECODE(lg.codlocatied,0,gd.den_gest,gd.den_gest ||&apos;&apos; (&apos;&apos;||nld.denumire||&apos;&apos;)&apos;&apos;), lg.serie, lg.tg,
    io.den_ioart, nao.codextern, nao.codintern, nao.codvamal, DECODE(lg.furn,0,gfurn.den_gest,furn.den_part), prod.den_part, lg.obsart, um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, 0, nao.lunigarantie, nao.masa, nao.volum,
    NULL, slivr.obs, getadresa(slivr.sector, slivr.strada, slivr.nr1, slivr.nr2, slivr.bloc, slivr.scara, slivr.etaj, slivr.apart, slivr.codpostal), locl.den_localit, judl.den_judet, taral.den_tara, zonal.den_zona,
    CASE WHEN ag_doc.codpers = 0 THEN ag_doc.nume ELSE ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume END, nao1.grupa, nao1.uplift,lg.d1,lg.d2,lg.d3,
    cs.den_claseas, ca.den_clasea, ca.simbol, cg.den_claseg, cg.simbol,
    lg.DataAchiz,lg.SerieLot,lg.NrCertif, pkg_list_base_utils.decode_tipdoc_scurt(lg.tipdoc), lg.obsdoc, &apos;&apos;Nu&apos;&apos; custodie, cc.denumire,
    lg.an andoc, lg.luna lunadoc, to_char(lg.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(lg.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(lg.Luna) luna,
    NULL, NULL, NULL, NULL,
    NULL PIesDVal,
    0, NULL, NULL &apos;||sCursRef||sPMP||sSelectDC||gUserAlias||&apos;
  FROM lg
    INNER JOIN num1 u1       ON u1.codum1       = lg.umsec
    INNER JOIN nartobj nao   ON nao.codobiect   = lg.codobiect
    INNER JOIN nart na       ON na.codarticol   = nao.codarticol
    LEFT  JOIN livr l        ON l.codlivr       = lg.codlivr
    LEFT  JOIN NUM UM1       ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2       ON um2.codum       = na.um2
    LEFT  JOIN ngest g       ON g.codgest       = lg.gest
    LEFT  JOIN ngest go      ON go.codgest      = lg.gestorig
    LEFT  JOIN nlocatii nl   ON nl.codlocatie   = lg.codlocatie
    LEFT  JOIN nsubunit ss   ON ss.codsubunit   = lg.subunitatea
    LEFT  JOIN doccarnete dc ON dc.codcarnet    = lg.carnetlivr
    LEFT  JOIN nmonede mon   ON mon.codmoneda   = lg.moneda
    LEFT  JOIN nclasea ca    ON ca.codclasea    = na.clasa
    LEFT  JOIN nclaseas cs   ON cs.codclaseas   = na.clasastatist
    LEFT  JOIN ioart io      ON io.codioart     = lg.codioart
    LEFT  JOIN ioart1 io1    ON io1.codioart    = lg.codioart AND (lg.an*12+lg.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT  JOIN ncont nc      ON nc.codcont      = io1.cont
    LEFT  JOIN centrecost cc ON cc.codcentru    = lg.codcentru
    LEFT  JOIN ncont ncv     ON ncv.codcont     = Coalesce(io1.venituri,0)
    LEFT  JOIN ncont ncc     ON ncc.codcont     = Coalesce(io1.cheltuieli,0)
    LEFT  JOIN npart np      ON np.codpart      = lg.partener
    LEFT  JOIN ngest gd      ON gd.codgest      = lg.gestd
    LEFT  JOIN nclaseg cg    ON cg.codclaseg    = gd.codclasa
    LEFT  JOIN NAGENDA SLIVR ON slivr.codgest   = lg.gestd
    LEFT  JOIN NLOCALIT LOCl ON locl.codlocalit = slivr.codlocalit
    LEFT  JOIN NJUDET JUDl   ON judl.codjudet   = locl.codjudet
    LEFT  JOIN NZONE ZONAl   ON zonal.codzona   = locl.codzona
    LEFT  JOIN NTARI TARAl   ON taral.codtara   = locl.codtara
    LEFT  JOIN nlocatii nld  ON nld.codlocatie  = lg.codlocatied
    LEFT  JOIN npart prod    ON prod.codpart    = nao.codproducator
    LEFT  JOIN npart furn    ON furn.codpart    = lg.furn
    LEFT  JOIN ngest gfurn   ON gfurn.codgest   = lg.gestfurn
    LEFT  JOIN npers ag_doc  ON ag_doc.codpers  = lg.agent
    LEFT  JOIN nparttr del   ON lg.delegat      = del.codparttr
    LEFT  JOIN NTARI TOrig   ON TOrig.CodTara   = nao.taraorigine
    LEFT  JOIN nartobj1 nao1 ON nao1.codobiect  = lg.codobiect AND (lg.an*12+lg.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN nartamb aa    ON aa.codobiect    = lg.codobiect AND aa.umsec = lg.umsec
    LEFT  JOIN pretm pm      ON pm.codobiect    = lg.codobiect AND pm.subunitatea = lg.subunitatea AND pm.implicit = 1&apos;||
    sJoinDC||
    gSuplJoins||&apos;
 WHERE lg.cant &lt;&gt; 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectcomun||sselecties, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectcomun||sselectint, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelectcomun||sselectt, aListID, aListVer);

  COMMIT;
END;

FUNCTION GET_PROCENT_TVA(ACODOBIECT IN NUMBER, ACODINTR1 IN NUMBER, ACODTRANSF1 IN NUMBER, ACODIES1 IN NUMBER) RETURN NUMBER IS
proc number(20,7);
anluna number(20);
BEGIN
  proc := -1;
  anluna := 0;
  begin
    select coalesce(i.an, 0)*12+coalesce(i.luna, 0) into anluna
    from iesiri1 i1
         inner join iesiri i on i.codies = i1.codies
    where i1.codies1 = acodies1;
  exception when others then anluna := 0; proc := -2;
  end;
  if anluna = 0 then
    begin
      select coalesce(t.an, 0)*12+coalesce(t.luna, 0) into anluna
      from transf1 t1
           inner join transf t on t.codtransf = t1.codtransf
      where t1.codtransf1 = acodtransf1;
    exception when others then anluna := 0; proc := -3;
    end;
    if anluna = 0 then
      begin
        select coalesce(i.an, 0)*12+coalesce(i.luna, 0) into anluna
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
        where i1.codintr1 = acodintr1;
      exception when others then anluna := 0; proc := -4;
      end;
    end if;
  end if;

  if anluna &gt; 0 then
    begin
      select tva1.procent into proc
      from ntva1 tva1
           inner join nart1 a1 on a1.codtva = tva1.codtva
           inner join nartobj o on a1.codarticol = o.codarticol
      where o.codobiect = acodobiect and anluna between a1.alstart and a1.alstop
            and anluna between tva1.alstart and tva1.alstop;
    exception when others then proc := -5;
    end;
  end if;
  return proc;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_LIVRARI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5063109BE49253ED58E50054076B3F52200F374</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRDOC IS

  vCodIes     IESIRI.CODIES%TYPE;
  vCodGest    NGEST.CODGEST%TYPE;
  vSubCur     NSUBUNIT.CodSubunit%TYPE;
  vCntFLivr   NUMBER;
  vAuxNSIN    VARCHAR2( 1000);
  sATRIB      VARCHAR2( 1000);

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  sSQL VARCHAR2(10000);
BEGIN
  sSQL :=
  &apos;INSERT INTO tmp_dinamic_cols(FIELDNAME, DISPLAY,INDEXLOCAL,COD)
  WITH x AS (
    SELECT Row_Number() OVER (ORDER BY A1.CODATRIBUT, A1.VALOARE, A1.CODVALATR) Nr, A1.CODVALATR, A.DENUMIRE||&apos;&apos; - &apos;&apos;||A1.VALOARE Display
    FROM NATRIB1 A1 INNER JOIN NATRIB A ON A.CODATRIBUT = A1.CODATRIBUT
    WHERE A1.CODATRIBUT IN (&apos;||sATRIB||&apos;)
  )
  SELECT &apos;&apos;A&apos;&apos;||NR, DISPLAY, NR, CODVALATR
  FROM x&apos;;

  DELETE tmp_dinamic_cols;

  EXECUTE IMMEDIATE sSQL;
  COMMIT;
END;

PROCEDURE SETPARAMS( pCodIes     IN IESIRI.CODIES%TYPE DEFAULT NULL,
                     pCodGest    IN NGEST.CODGEST%TYPE DEFAULT NULL,
                     pDoarInRosu IN BOOLEAN DEFAULT FALSE) IS
BEGIN
  vCodIes   := pCodIes;
  vCntFLivr := 0;
  IF nvl(pCodGest,-1) &gt;= 0
  THEN vCodGest := pCodGest;
  ELSE vCodGest := -1;
  END IF;
  vSubCur  := pkg_globals.getSubunitate;

  DELETE iesiri1_man;
  IF vCodIes &gt; 0 THEN
    IF pDoarInRosu THEN
      INSERT INTO IESIRI1_MAN
      SELECT * FROM IESIRI1
      WHERE CodIes = vCodIes
        AND Cant &lt; 0;
    ELSE
      INSERT INTO IESIRI1_MAN
      SELECT * FROM IESIRI1
      WHERE CodIes = vCodIes;
    END IF;

    vAuxNSIN := &apos;
          WHERE L.CODIES = &apos;||vCodIes;
  ELSE
    SELECT Count(1) INTO vCntFLivr
    FROM TMP_MANEVRA_LISTE TMP
    WHERE UPPER(tmp.filtru) = &apos;CODLIVR&apos;;

    IF vCntFLivr &gt; 0 THEN -- filtru dupa codlivr
      IF pDoarInRosu THEN
        INSERT INTO IESIRI1_MAN
        WITH L1G AS (
          SELECT DISTINCT L1.CODIES1
          FROM TMP_MANEVRA_LISTE TMP INNER JOIN LIVR1 L1 ON L1.CODLIVR = TMP.VALOARE
          WHERE UPPER(tmp.filtru) = &apos;CODLIVR&apos;
        )
        SELECT I1.*
        FROM L1G
             INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1G.CODIES1
        WHERE I1.CANT &lt; 0;
      ELSE
        INSERT INTO IESIRI1_MAN
        WITH L1G AS (
          SELECT DISTINCT L1.CODIES1
          FROM TMP_MANEVRA_LISTE TMP INNER JOIN LIVR1 L1 ON L1.CODLIVR = TMP.VALOARE
          WHERE UPPER(tmp.filtru) = &apos;CODLIVR&apos;
        )
        SELECT I1.*
        FROM L1G INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1G.CODIES1;
      END IF;

      vAuxNSIN := &apos;
            INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = L.CODLIVR AND UPPER(tmp.filtru) = &apos;&apos;CODLIVR&apos;&apos;&apos;;
    ELSE
      IF pDoarInRosu THEN
        INSERT INTO IESIRI1_MAN
        SELECT I1.*
        FROM TMP_MANEVRA_LISTE TMP
          INNER JOIN IESIRI1 I1 ON I1.CODIES = TMP.VALOARE
        WHERE UPPER(tmp.filtru) = &apos;CODIES&apos; AND I1.CANT &lt; 0;
      ELSE
        INSERT INTO IESIRI1_MAN
        SELECT I1.*
        FROM TMP_MANEVRA_LISTE TMP
          INNER JOIN IESIRI1 I1 ON I1.CODIES = TMP.VALOARE
        WHERE UPPER(tmp.filtru) = &apos;CODIES&apos;;
      END IF;

      vAuxNSIN := &apos;
            INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = L.CODIES AND UPPER(tmp.filtru) = &apos;&apos;CODIES&apos;&apos;&apos;;
    END IF;
  END IF;

  pkg_globals.SetSeparator(&apos;,&apos;);
  sATRIB := Nvl(pkg_categconst.GetValConstanta(&apos;AtribArtDinColLivr&apos;,pkg_globals.GetANLUCRU,pkg_globals.GetLUNALUCRU),&apos;0&apos;);
  PKG_LIST_BASE_LIVRDOC.BAGA_DINAMIC_COLS;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
 vCodDoc     NUMBER;
 vTipDoc     NUMBER;
 vCodLocatie NUMBER;
 vPartener   NUMBER;
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  IF Nvl(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;

  FOR v_rec IN (
    SELECT G.DEN_GEST, NumePrenume(NP.Nume,NP.Prenume) Gestionar
    FROM NGEST G LEFT JOIN NPERS NP ON G.CODGESTIONAR = NP.CODPERS
    WHERE G.CODGEST = vCodGest
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE&apos;  ,         v_rec.Den_Gest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE GESTIONAR&apos;, v_rec.Gestionar);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT stragg3200(I.PREFIXDOC) PrefixDoc, stragg3200(I.NRDOC) NrDoc, stragg3200(To_Char(I.DATADOC,&apos;dd.mm.yyyy&apos;)) DataDoc, stragg3200(I.OBS) ObsDoc, Min(i.CodIes) CodDoc, Min(i.TipDoc) TipDoc
    FROM (SELECT DISTINCT codies FROM IESIRI1_MAN) tmp
      INNER JOIN IESIRI I ON i.codies = tmp.codies
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT&apos;                 , v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;           , v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;            , v_rec.DataDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT OBS&apos;             , v_rec.ObsDoc);

    vCodDoc := v_rec.CodDoc;
    vTipDoc := v_rec.TipDoc;
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT stragg3200(NrLivr) NrLivr, stragg3200(DataLivr) DataLivr, stragg3200(ObsLivr) ObsLivr, stragg3200(ZiLivr) ZiLivr
    FROM (
      SELECT
        DISTINCT L.NRLIVR, To_Char(L.DATALIVR,&apos;dd.mm.yyyy&apos;) DataLivr, L.OBS ObsLivr, EXTRACT(DAY FROM L.DATALIVR) ZiLivr
      FROM IESIRI1_MAN tmp
        INNER JOIN livr l ON l.codies = tmp.codies
        INNER JOIN livr1 l1 ON l1.codies1 = tmp.codies1 AND l1.codlivr = l.codlivr
        LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
        LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        LEFT JOIN nir n ON n.codnir = ns.codnir
      WHERE ( vCntFLivr = 0 OR l.codlivr IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE UPPER(filtru) = &apos;CODLIVR&apos;) )
        AND ( vCodGest = -1 OR COALESCE(l1.CodGestOrig, lv.gest, n.Gest, 0) = vCodGest)
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.NUMAR&apos;, v_rec.NrLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.DATA&apos;,  v_rec.DataLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.OBS&apos;,   v_rec.ObsLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.ZI&apos;,    v_rec.ZiLivr);
    EXIT;
  END LOOP;


  FOR v_rec IN (
    SELECT
      n.nume, n.prenume, n.cnp,
      d.delegat, d.doc deldoc, d.nrdoc nrdoctransp, d.seriedoc, d.eliberat, d.cnp delcnp, d.mijltransp, d.nrtransp, d.datadoc deldatadoc,
      A.NUME NUMEA, A.PRENUME PRENUMEA, A.CNP CNPA
    FROM IESIRI I
      LEFT JOIN NPERS N ON I.USERID = N.LOGONNAME
      LEFT JOIN NPARTTR D ON I.DELEGAT = D.CODPARTTR
      LEFT JOIN NPERS A ON A.CODPERS = I.AGENT
    WHERE i.codies = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;           , v_rec.NUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;         , v_rec.PRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;             , v_rec.CNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Agent nume &apos;              , v_rec.NUMEA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Agent prenume&apos;            , v_rec.PRENUMEA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Agent CNP&apos;                , v_rec.CNPA);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;        , v_rec.DELEGAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;    , v_rec.DELCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;       , v_rec.DELDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;   , v_rec.NRDOCTRANSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos; , v_rec.SERIedoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;   , v_rec.ELIBERAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos; , v_rec.DELDATADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;            , v_rec.MIJLTRANSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;      , v_rec.NRTRANSP);

    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT SUM(L1.CANT * Nvl(O.MASA,0)) Masa, SUM(L1.CANT * Nvl(O.Volum,0)) Volum
    FROM LIVR L
      INNER JOIN LIVR1 L1 ON L.CODLIVR = L1.CODLIVR
      INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
      LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
      LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
    WHERE L.CODIES = vCodIes
      AND (vCodGest = -1 OR COALESCE(l1.CodGestOrig, lv.gest, n.Gest, 0) = vCodGest)
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA FACTURATA&apos;, TO_CHAR(v_rec.Masa,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM FACTURAT&apos;, TO_CHAR(v_rec.Volum,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      PK.NRDOC, DC.SERIE, PK.NRPACHETE, PK.IDENTIFICATORP, PK.DATAP,
      Numeprenume(PC.NUME,PC.PRENUME) PCC, Numeprenume(PV.NUME,PV.PRENUME) PVV, Numeprenume(PT.NUME,PT.PRENUME) PTT,
      PK.DATACOLECTARE, PK.DATAVERIFICARE, PK.DATATRANSPORT
    FROM IESIRI I
      LEFT JOIN PACHETE1 PK1 ON I.CODIES = PK1.CODDOC AND PK1.TIPDOC = I.TipDoc
      LEFT JOIN PACHETE  PK ON PK1.CODPACHETE = PK.CODPACHETE
      LEFT JOIN DOCCARNETE DC ON PK.CARNETDOC = DC.CODCARNET
      LEFT JOIN NPERS PC ON PK.COLECTOR = PC.CODPERS
      LEFT JOIN NPERS PV ON PK.VERIFICATOR = PV.CODPERS
      LEFT JOIN NPERS PT ON PK.TRANSPORTATOR = PT.CODPERS
    WHERE I.CODIES = vCodDoc
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET SERIE&apos;                  , v_rec.SERIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR&apos;                  , v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR PACHETE&apos;          , v_rec.NRPACHETE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA&apos;                   , v_rec.DATACOLECTARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET Identificator&apos;          , v_rec.IDENTIFICATORP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA COLECTARE&apos;     , v_rec.DATACOLECTARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA COLECTARE&apos;         , v_rec.PCC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA VERIFICATOARE&apos; , v_rec.PVV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA VERIFICARE&apos;        , v_rec.DATAVERIFICARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT PERSOANA&apos;     , v_rec.PTT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT DATA&apos;         , v_rec.DATATRANSPORT);

    EXIT;
  END LOOP;

  IF vTipDoc IN (19,20,21,22,26) THEN -- parametrii client

    SELECT CODLOCATIE, PARTENER
    INTO vCodLocatie, vPartener
    FROM IESIRI
    WHERE CodIes = vCodDoc;

    FOR v_rec IN (
      SELECT
        PB.CONTBANCA, B.DENUMIRE, B.SIMBOL, I.VALDOC, I.TVADOC
      FROM IESIRI I
        LEFT JOIN NPARTB PB ON PB.CODPART = I.PARTENER AND PB.IMPLICIT = 1
        LEFT JOIN NBANK B ON B.CODBANK = PB.CODBANK
      WHERE I.CODIES = vCodDoc
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;, v_rec.CONTBANCA);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;, v_rec.DENUMIRE);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;, v_rec.SIMBOL);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;, TO_CHAR(COALESCE(v_rec.TVADOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VALOARE&apos;, TO_CHAR(COALESCE(v_rec.VALDOC,0)-COALESCE(v_rec.TVADOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;, TO_CHAR(COALESCE(v_rec.VALDOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      EXIT;
    END LOOP;

    FOR v_rec IN (
      SELECT A.Obs, J.Den_Judet, A.TELEFON, GetAdresa(A.sector, A.strada, A.nr1, A.nr2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) AS ADRESA, L.DEN_LOCALIT, J.SIMBAUTO, A.CODCLIENT
      FROM NAGENDA A
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
        LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET
      WHERE CODAGENDA = vCodLocatie
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;        , v_rec.Adresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;      , v_rec.OBS);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;    , v_rec.Den_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;         , v_rec.DEN_JUDET);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;       , v_rec.Telefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos; , v_rec.CodClient);

      EXIT;
    END LOOP;

    FOR v_rec IN (
      SELECT P.DEN_PART, C.CODFISCAL, P.AUTORIZATIE, A.OBS, L.DEN_LOCALIT, J.Den_Judet, Decode(P.PERSOANAFIZICA,1,NULL,P.REGCOM) REGCOM, PC.NUME||&apos; &apos;||PC.PRENUME PERSC
      FROM NPART P
        LEFT JOIN NPARTCODFISC C ON C.CODPART = P.CODPART AND C.PRINCIPAL = 1
        LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART AND Nvl(a.Inactiv,0) = 0 AND A.SEDIUSOCIAL IN (4,5,6,7)
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
        LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET
        LEFT JOIN NPERSCONTACT PC ON PC.CODPART = P.CODPART
      WHERE P.CODPART = vPartener
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;               , v_rec.Den_Part);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD FISCAL&apos;             , v_rec.CodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;        , v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE SPECIALA&apos;   , v_rec.Autorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SEDIU SOCIAL&apos;           , v_rec.Obs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT LOCALITATE SEDIU SOCIAL&apos;, v_rec.Den_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT JUDET SEDIU SOCIAL&apos;     , v_rec.Den_Judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT PERSOANA CONTACT IMPLICITA&apos; , v_rec.PersC);

      EXIT;
    END LOOP;
  ELSIF vTipDoc = 12 THEN -- parametrii transfer
    NULL;
  ELSIF vTipDoc = 24 THEN -- parametrii consum intern
    FOR v_rec IN (
      SELECT
        CASE Nvl(TIPCONSUMATOR,0)
          WHEN 1 THEN &apos;GESTIUNE&apos;
          WHEN 2 THEN &apos;PERSOANA&apos;
          WHEN 3 THEN  &apos;AUTO&apos;
        END TIPCONSUMATOR,
        CASE Nvl(TIPCONSUMATOR,0)
          WHEN 1 THEN G.DEN_GEST
          WHEN 2 THEN NumePrenume(P.NUME,P.PRENUME)
          WHEN 3 THEN OB.DENUMIRE||&apos;-&apos;||PA.NRINREG
        END CONSUMATOR
      FROM IESIRI I
        LEFT JOIN NGEST G ON I.CODGESTPROD = G.CODGEST
        LEFT JOIN NPERS P ON I.CODPERS = P.CODPERS
        LEFT JOIN NPARCAUT PA ON I.CODAUTO = PA.CODNPARCAUT
        LEFT JOIN NARTOBJ OB ON PA.CODART = OB.CODOBIECT

      WHERE CODIES  = vCodDoc
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIP CONSUMATOR&apos;         , v_rec.TIPCONSUMATOR);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CONSUMATOR&apos;             , v_rec.CONSUMATOR);

      EXIT;
    END LOOP;

  ELSIF vTipDoc = 23 THEN -- parametrii subunitati
    FOR v_rec IN (
      SELECT S.Den_Subunit, L.DEN_LOCALIT, S.RegCom, BK.DENUMIRE as banca, BC.nrCONT as contbanca, GetAdresa(A.sector, A.strada, A.nr1, A.nr2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) ADRESA, S.CIF
      FROM IESIRI I
        LEFT JOIN NSUBUNIT S ON I.CODSUBUNIT = S.CODSUBUNIT
        LEFT JOIN NAGENDA A ON S.CODSUBUNIT = A.CODSUBUNIT
        LEFT JOIN nbankcont BC ON S.codbankcont = BC.codbankcont
        LEFT JOIN nbank BK ON BC.codbank = BK.codbank
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
      WHERE I.Codies = vCodDoc
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE DENUMIRE&apos;   , v_rec.DEN_SUBUNIT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE LOCALITATE&apos; , v_rec.DEN_LOCALIT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE ADRESA&apos;     , v_rec.ADRESA);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE CIF&apos;        , v_rec.CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE R.C.&apos;       , v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE BANCA&apos;      , v_rec.banca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE CONT&apos;       , v_rec.contbanca);

      EXIT;
    END LOOP;

  END IF;

  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;IESIRIEXT&apos;, &apos;CODIES&apos;, vCodDoc);
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(20000);
  sSelect     VARCHAR2(20000);
  vWhere      VARCHAR2( 1000);
  sPMP        VARCHAR2( 1000);
  sInsertPlus VARCHAR2( 2000);
  sSelectPlus VARCHAR2( 9000);
  sSelectXATR VARCHAR2( 9000);
  sJoinPlus   VARCHAR2( 2000);
  vXATR       BOOLEAN;
  sXATR       VARCHAR2(10000);
BEGIN
  gSuplCols :=
    &apos;IESIRI I, NARTOBJ NAO, NART NA, NUM1 UM, NGEST NG, NLOCATII NL, DOCCARNETE DC, NUM1 UM1, NUM1 UM2, NPART PROD, NPART FURN, NCLASEA CA, TMP_UTILIZATOR UT,&apos;||
    &apos;IOART IO, IOART1 IO1, NCONT NC, NARTOBJ1 NAO1, NIRSTOC NS, COMANDA1 C1, COMANDA C, IESLINK IL, NARTCLI FOBJ&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,      &apos;P&apos;,    &apos;P.CODPART = I.PARTENER&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,   &apos;C1I&apos;,  &apos;C1I.CODCOMANDA1 = LG.CODCMDINT1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,    &apos;CI&apos;,   &apos;CI.CODCOMANDA = C1I.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,    &apos;CIO&apos;,  &apos;CIO.CODOBIECT = C1I.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CMDLINK&apos;,    &apos;CL1&apos;,  &apos;CL1.CODCOMANDA1 = IL.CODLINIECOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CMDLIVRLINK&apos;,&apos;CL2&apos;,  &apos;CL2.CODCOMANDA1 = COALESCE(CL1.CODLINIECOMANDA,IL.CODLINIECOMANDA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,   &apos;C1C&apos;,  &apos;C1C.CODCOMANDA1 = COALESCE(CL1.CODLINIECOMANDA,CL1.CODLINIECOMANDA,IL.CODLINIECOMANDA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,    &apos;CC&apos;,   &apos;CC.CODCOMANDA = C1C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,    &apos;AC&apos;,   &apos;AC.CODARTCLI = PKG_LIST_BASE_UTILS.GETCODARTCLI(LG.CODOBIECT, I.PARTENER, P.CODCLASA)&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1EXT&apos;, &apos;I1EXT&apos;,&apos;I1EXT.CODIES1 = LG.CODIES1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,  &apos;IEXT&apos;, &apos;IEXT.CODIES = LG.CODIES&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,    &apos;INOR&apos;, &apos;INOR.CODINTR = LG.CODINTR&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;I1&apos;,   &apos;I1.CODIES1 = LG.CODIES1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;LIVR1&apos;,      &apos;L1&apos;,   &apos;L1.CODLIVR1 = LG.CODLIVR1&apos;, 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  --pkg_list_base_utils.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);

  IF vCodGest &gt;= 0 THEN
    vWhere :=&apos;
      WHERE COALESCE(l1.CodGestOrig, lv.gest, n.Gest, 0) = &apos;||vCodGest;
  END IF;

  IF pkg_globals.ANCURENT * 12 + pkg_globals.LUNACURENTA &lt; pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU THEN
    sPMP := &apos;,
    DECODE(io1.mg,3,pkg_PMP.GET_PMP_LEI(lg.codobiect,i.subunitatea,i.an,i.luna),NULL), DECODE(io1.mg,3,pkg_PMP.GET_PMP_VALUTA_FROM_VAR,NULL), lg.pmpdoc, lg.pmpvalutadoc &apos;;
  ELSE
    sPMP := &apos;,
    lg.pmp, lg.pmpvaluta, lg.pmpdoc, lg.pmpvalutadoc &apos;;
  END IF;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;lg.cant&apos;,&apos;lg.codobiect&apos;,sInsertPlus,sSelectPlus,sJoinPlus);

  vXATR       := FALSE;
  sSelectXATR := &apos;&apos;;
  FOR vRec IN (SELECT FIELDNAME, COD, INDEXLOCAL FROM tmp_dinamic_cols ORDER BY INDEXLOCAL)
  LOOP
    vXATR := TRUE;
    sInsertPlus := sInsertPlus||&apos;, &apos;||vRec.FIELDNAME;
    sSelectPlus := sSelectPlus||&apos;, Nvl(X.&apos;||vRec.FIELDNAME||&apos;*lg.cant/um.paritate,0) &apos;||vRec.FIELDNAME;
    sSelectXATR := sSelectXATR||&apos;, Max(DECODE(A1.CODVALATR,&apos;||vRec.COD||&apos;,1,0)) &apos;||vRec.FIELDNAME;
  END LOOP;

  sXATR := &apos;
  X AS (
    SELECT I1.CODOBIECT&apos;||sSelectXATR||&apos;
    FROM IESIRI1_MAN I1
      INNER JOIN NATROBJ AO ON AO.CODOBIECT = I1.CODOBIECT
      LEFT  JOIN NARTATR AA ON AA.CODARTATR = AO.CODARTATR AND AA.CODATRIBUT IN (&apos;||sATRIB||&apos;)
      LEFT  JOIN NATRIB1 A1 ON A1.CODVALATR = AO.CODVALATR
    GROUP BY I1.CODOBIECT),&apos;;

  IF vXATR THEN
    sJoinPlus := sJoinPlus ||&apos;
    LEFT JOIN X ON x.codobiect = lg.codobiect&apos;;
  ELSE
    sXATR := &apos;&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    ART, UM, CANTDOC, CANTLIVR,
    PACH, PINREG, PVANZ,
    VALACH, VALINREG, VALVANZ,
    GESTIUNE, GESTORIG, LOCATIE, NRLIVR, DATALIVR, DENCARNET, SIMBCARNET, SERCARNET, OBSLIVR, GAR, DATAEXP, DATAPROD, CODINTERN, CODEXTERN,
    DENCLASAA, SIMBCLASAA, MASA, VOLUM, PRODUCATOR, FURNIZOR, ARTFURN, UM1, UM2, CANT1, CANT2,
    TIPSERIE, SERII, SER, SEROBS, SEROBSDIST, CERTIFSER, CERTIFSERD, DENIOART, SIMBCONT,
    PREFIXDOC, NRDOC, DATADOC, NRCERTIF, PUMAXIMAL, D1, D2, D3, DENCLASEAS, NRCOM, DATACOM, OBSDOC, CUSTODIE, CENTRUCOST,
    TIPLIVRARE,
    PMP, PMPVALUTA, PMPDOC, PMPVALUTADOC&apos;||sInsertPlus||gUserFields||&apos; )&apos;;

  sSelect := &apos;
  WITH &apos;||
  sXatr||&apos;
  NSIN AS (
    SELECT ns.codintr1, ns.coddvi1, connect_by_root ns.codnirstoc codnirstoc
    FROM nirstoc ns
    WHERE ns.codnirstocparinte IS NULL
    START WITH ns.codnirstoc IN (SELECT DISTINCT l1.codnirstoc FROM livr l INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr&apos;||vAuxNSIN||&apos;)
    CONNECT BY ns.codnirstoc = PRIOR ns.codnirstocparinte),
  LG AS (
    SELECT
      l1.codlivr1,ns.codnirstoc,i1.codies, i1.codies1, i1.indexlocal, i1.codobiect,i1.codcmdint1,
      COALESCE(lv.gest, n.gest, 0) gest, COALESCE(l1.codgestorig, lv.gest, n.gest, 0) gestorig, ns.codlocatie, l1.umsec,
      i1.pu, i1.cant canti, i1.obs obsdoc, i1.garantie, l.carnetlivr, l.nrlivr, l.datalivr, l.obs obslivr, i1.codcentru,
      NVL(ns.codioart,lv.codioart) codioart, ns.furn, ns.codgestprod gestfurn,
      SUM(NVL(lv.pretinreg,ns.pret)*l1.cant) valinreg,
      SUM(NVL(lv.pretachiz,ns.pret - ns.adaos)*l1.cant) valachiz,
      sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2, ns.d1, ns.d2, ns.d3,
      CASE nvl(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_vc3200(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt))
        ELSE NULL
      END SERII,
      vc2_nt_to_vc3200(CAST(COLLECT(s.serie) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(COLLECT(nser.obs) AS vc2_nt)) serobs,
      vc2_nt_to_vc3200_dist(CAST(COLLECT(nser.obs) AS vc2_nt)) serobsdist,
      NVL(i1.pumaximal,max(NVL(ns.pumaximal,0))) pumaximal,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg))) AS vc2_nt)) tg,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.nrcertif)) AS vc2_nt)) certifser,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.dataprimire,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) certifserd,
      decode(ns.tipserie,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
      i1.tiplivrare,
      max(l1.pmp) pmp, max(l1.pmpvaluta) pmpvaluta, max(l1.pmpdoc) pmpdoc, max(l1.pmpvalutadoc) pmpvalutadoc,
      int1.codintr
    FROM IESIRI1_MAN i1
      INNER JOIN nartobj nao  ON nao.codobiect   = i1.codobiect
      INNER JOIN livr    l    ON l.codies        = i1.codies
      INNER JOIN livr1   l1   ON l1.codies1      = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
      LEFT JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
      LEFT JOIN nir      n    ON n.codnir        = ns.codnir
      LEFT JOIN NSIN          ON nsin.codnirstoc = ns.codnirstoc
      LEFT JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
      LEFT JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
      LEFT JOIN nirser   nser ON nser.codnirser  = l1.codnirser
      LEFT JOIN nserii   s    on s.codserie      = nser.codserie
      LEFT JOIN certif   c    ON c.codcertif     = nser.codcertif&apos;||
    vWhere ||&apos;
    GROUP BY
      l1.codlivr1,i1.codies, i1.codies1, i1.indexlocal, i1.codobiect, i1.cant, i1.garantie, i1.pu, i1.pumaximal, i1.obs,  i1.codcentru, i1.tiplivrare,
      l.carnetlivr, l.nrlivr, l.datalivr, l.obs, l1.umsec, lv.codioart, ns.codnirstoc, i1.codcmdint1,
      ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, ns.d1, ns.d2, ns.d3,
      COALESCE(lv.gest, n.gest, 0), COALESCE(l1.codgestorig, lv.gest, n.gest, 0), int1.codintr)
  SELECT
    nao.denumire, um.den_um1, lg.canti / um.paritate, lg.cant/um.paritate,
    DECODE(lg.cant,0,0,lg.valachiz*um.paritate/lg.cant), DECODE(lg.cant,0,0,lg.valinreg*um.paritate/lg.cant), lg.pu*um.paritate,
    lg.valachiz, lg.valinreg, lg.pu * lg.cant,
    ng.den_gest, ngo.den_gest, nl.denumire, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie, lg.obslivr, lg.garantie, lg.tg, lg.dp, nao.codintern, nao.codextern,
    ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part,
    case when gfurn.codgest &gt; 0 then gfurn.den_gest else furn.den_part end, fobj.denumire,
    um1.den_um, um2.den_um, lg.cantum1, lg.cantum2,
    lg.tipserie, lg.serii, lg.ser, lg.serobs, lg.serobsdist, lg.certifser, lg.certifserd, io.den_ioart, nc.simbol,
    i.prefixdoc, i.nrdoc, i.datadoc, lg.nrcertif,
    CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
    lg.d1,lg.d2,lg.d3,cs.den_claseas,c.nrdoc,c.datadoc,lg.obsdoc,DECODE(i.custodie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), cec.denumire,
    DECODE(lg.tiplivrare,1,&apos;&apos;Ridicata&apos;&apos;,2,&apos;&apos;Custodie&apos;&apos;,3,&apos;&apos;Nesosita&apos;&apos;,4,&apos;&apos;De ridicat&apos;&apos;)&apos;||
    sPMP||sSelectPlus||gUserAlias||&apos;
  FROM lg
    INNER JOIN iesiri        i     ON i.codies         = lg.codies
    INNER JOIN nartobj       nao   ON nao.codobiect    = lg.codobiect
    INNER JOIN nart          na    ON na.codarticol    = nao.codarticol
    INNER JOIN num1          um    ON um.codum1        = lg.umsec
    INNER JOIN ngest         ng    ON ng.codgest       = lg.gest
    INNER JOIN ngest         ngo   ON ngo.codgest      = lg.gestorig
    LEFT JOIN nirstoc        ns    on lg.codnirstoc    = ns.codnirstoc
    LEFT JOIN nlocatii       nl    ON nl.codlocatie    = lg.codlocatie
    LEFT JOIN doccarnete     dc    ON dc.codcarnet     = lg.carnetlivr
    LEFT JOIN num            um1   ON um1.codum        = na.um1
    LEFT JOIN num            um2   ON um2.codum        = na.um2
    LEFT JOIN npart          prod  ON prod.codpart     = nao.codproducator
    LEFT JOIN npart          furn  ON furn.codpart     = lg.furn
    LEFT JOIN ngest          gfurn ON gfurn.codgest    = lg.gestfurn
    LEFT JOIN nclasea        ca    ON ca.codclasea     = na.clasa
    LEFT JOIN nclaseas       cs    ON cs.codclaseas    = na.clasastatist
    LEFT JOIN ioart          io    ON io.codioart      = lg.codioart
    LEFT JOIN ioart1         io1   ON io1.codioart     = lg.codioart  AND (i.an*12+i.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT JOIN ncont          nc    ON nc.codcont       = io1.cont
    LEFT JOIN nartobj1       nao1  ON nao1.codobiect   = lg.codobiect AND (i.an*12+i.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT JOIN ieslink        il    ON il.codies1       = lg.codies1
    LEFT JOIN comanda1       c1    ON c1.codcomanda1   = il.codliniecomanda
    LEFT JOIN comanda        c     ON c.codcomanda     = c1.codcomanda
    LEFT JOIN nartcli        fobj  ON fobj.codartcli   = PKG_LIST_BASE_UTILS.GetCodArtCli(lg.codobiect, lg.furn, furn.codclasa)
    LEFT JOIN centrecost     cec   ON cec.codcentru    = lg.codcentru
    LEFT JOIN tmp_utilizator ut    ON ut.codutilizator = i.userid &apos;||
    sJoinPlus||
    gSuplJoins||&apos;
  ORDER BY lg.codies, lg.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  processparams;
  COMMIT;
END;

END PKG_LIST_BASE_LIVRDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRFROMNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A975641AC47EAA08E24E987D02E64BF044E64041</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRFROMNIR IS

  vConditieStocNegativ varchar2(500);
  vTipAnaliza number(1);
  vCodDocAnalizat varchar2(500);

PROCEDURE SETPARAMS(pConditieStocNegativ IN VARCHAR2, pTipAnaliza IN NUMBER, pCodDocAnalizat IN VARCHAR2) IS
BEGIN
  vConditieStocNegativ := pConditieStocNegativ;
  vTipAnaliza          := pTipAnaliza;
  vCodDocAnalizat      := pCodDocAnalizat;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 ) IS
  sInsert VARCHAR2(20000);
BEGIN
  sInsert:= &apos;INSERT INTO &apos;||tmpName||
            &apos;(DENOBIECT,&apos;||chr(13)||
            &apos; NRNIR,&apos;||chr(13)||
            &apos; DATAACHIZ,&apos;||chr(13)||
            &apos; CANTNIR,&apos;||chr(13)||
            &apos; LIVRAT,&apos;||chr(13)||
            &apos; REST,&apos;||chr(13)||
            &apos; PREFIXDOC,&apos;||chr(13)||
            &apos; NRDOC,&apos;||chr(13)||
            &apos; DATADOC&apos;||chr(13)||
              &apos;) &apos;||chr(13)||
                &apos;SELECT &apos;||chr(13)||
                &apos; ANALIZA.DENOBIECT, &apos;||chr(13)||
                &apos; ANALIZA.NRNIR, &apos;||chr(13)||
                &apos; ANALIZA.DATAACHIZ, &apos;||chr(13)||
                &apos; ANALIZA.CANTNIR, &apos;||chr(13)||
                &apos; ANALIZA.LIVRAT, &apos;||chr(13)||
                &apos; ANALIZA.REST, &apos;||chr(13)||
                &apos; ANALIZA.PREFIXDOC, &apos;||chr(13)||
                &apos; ANALIZA.NRDOC, &apos;||chr(13)||
                &apos; ANALIZA.DATADOC &apos;||chr(13)||
                &apos; FROM &apos;||chr(13)||
                &apos;(&apos;||chr(13)||
                &apos;   SELECT&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.DENOBIECT,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.CODNIRSTOC,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.CODLIVR1,&apos;||chr(13)||
                &apos;       (CASE&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPNIR BETWEEN 1   AND 9 THEN   LIVR_DIN_NIRSTOC.CODINTR&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPNIR BETWEEN 12  AND 13 THEN  LIVR_DIN_NIRSTOC.CODTRANSF&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPNIR IN (14, 15, 16) OR  LIVR_DIN_NIRSTOC.TIPNIR BETWEEN 19  AND 26 THEN  LIVR_DIN_NIRSTOC.CODIES&apos;||chr(13)||
                &apos;          ELSE NULL&apos;||chr(13)||
                &apos;        END) CODDOCRECEPTIE,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.CODINTR,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.NRNIR,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.TIPNIR,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.DATAACHIZ,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.CANTNIR,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.CANT AS LIVRAT,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.REST,&apos;||chr(13)||
                &apos;       LIVR_DIN_NIRSTOC.TIPLIVR,&apos;||chr(13)||
                &apos;       (&apos;||chr(13)||
                &apos;        CASE&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 1   AND 9 THEN PREFIXDOCINTR&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 12 AND 13 THEN PREFIXDOCTRANSF&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR IN (14, 15, 16) OR LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 19 AND 26 THEN PREFIXDOCIES&apos;||chr(13)||
                &apos;          ELSE NULL&apos;||chr(13)||
                &apos;        END&apos;||chr(13)||
                &apos;       ) PREFIXDOC,&apos;||chr(13)||
                &apos;       (CASE&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 1   AND 9 THEN   LIVR_DIN_NIRSTOC.CODINTRLIVR&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 12  AND 13 THEN  LIVR_DIN_NIRSTOC.CODTRANSFLIVR&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR IN (14, 15, 16) OR LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 19  AND 26 THEN  LIVR_DIN_NIRSTOC.CODIESLIVR&apos;||chr(13)||
                &apos;          ELSE NULL&apos;||chr(13)||
                &apos;        END) CODDOCLIVRARE,&apos;||chr(13)||
                &apos;      (&apos;||chr(13)||
                &apos;        CASE&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 1   AND 9 THEN NRDOCINTR&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 12 AND 13 THEN NRDOCTRANSF&apos;||chr(13)||
                &apos;          WHEN  LIVR_DIN_NIRSTOC.TIPLIVR IN (14, 15, 16) OR LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 19 AND 26 THEN NRDOCIES&apos;||chr(13)||
                &apos;          ELSE NULL&apos;||chr(13)||
                &apos;        END&apos;||chr(13)||
                &apos;      ) NRDOC,&apos;||chr(13)||
                &apos;      (&apos;||chr(13)||
                &apos;         CASE&apos;||chr(13)||
                &apos;           WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 1   AND 9 THEN DATADOCINTR&apos;||chr(13)||
                &apos;           WHEN  LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN 12 AND 13 THEN DATADOCTRANSF&apos;||chr(13)||
                &apos;           WHEN  LIVR_DIN_NIRSTOC.TIPLIVR IN (14, 15, 16) OR LIVR_DIN_NIRSTOC.TIPLIVR BETWEEN  19 AND 26 THEN DATADOCIES&apos;||chr(13)||
                &apos;         ELSE NULL&apos;||chr(13)||
                &apos;       END&apos;||chr(13)||
                &apos;      ) DATADOC&apos;||chr(13)||
                &apos;   FROM&apos;||chr(13)||
                &apos;   (&apos;||chr(13)||
                &apos;    SELECT&apos;||chr(13)||
                &apos;      NS.CODNIRSTOC,&apos;||chr(13)||
                &apos;      O.DENUMIRE AS DENOBIECT,&apos;||chr(13)||
                &apos;      NS.DATAACHIZ,&apos;||chr(13)||
                &apos;      NS.CANTNIR,&apos;||chr(13)||
                &apos;      NS.REST,&apos;||chr(13)||
                &apos;      N.CODINTR,&apos;||chr(13)||
                &apos;      N.CODIES,&apos;||chr(13)||
                &apos;      N.CODTRANSF,&apos;||chr(13)||
                &apos;      N.TIPNIR,&apos;||chr(13)||
                &apos;      N.NRNIR,&apos;||chr(13)||
                &apos;      L1.CANT,&apos;||chr(13)||
                &apos;      L1.CODLIVR1,&apos;||chr(13)||
                &apos;      L.TIPLIVR,&apos;||chr(13)||
                &apos;      IES.CODIES AS CODIESLIVR,&apos;||chr(13)||
                &apos;      IES.NRDOC AS NRDOCIES,&apos;||chr(13)||
                &apos;      IES.DATADOC AS DATADOCIES,&apos;||chr(13)||
                &apos;      IES.PREFIXDOC AS PREFIXDOCIES,&apos;||chr(13)||
                &apos;      INTR.CODINTR AS CODINTRLIVR ,&apos;||chr(13)||
                &apos;      INTR.NRDOC AS NRDOCINTR ,&apos;||chr(13)||
                &apos;      INTR.DATADOC AS DATADOCINTR,&apos;||chr(13)||
                &apos;      INTR.PREFIXDOC AS PREFIXDOCINTR,&apos;||chr(13)||
                &apos;      TRANSF.CODTRANSF AS CODTRANSFLIVR,&apos;||chr(13)||
                &apos;      TRANSF.NRDOC AS NRDOCTRANSF,&apos;||chr(13)||
                &apos;      TRANSF.DATADOC AS DATADOCTRANSF,&apos;||chr(13)||
                &apos;      TRANSF.PREFIXDOC AS PREFIXDOCTRANSF&apos;||chr(13)||
                &apos;   FROM&apos;||chr(13)||
                &apos;     NIRSTOC NS,&apos;||chr(13)||
                &apos;     NIR   N,&apos;||chr(13)||
                &apos;     LIVR1 L1,&apos;||chr(13)||
                &apos;     LIVR L&apos;||chr(13)||
                &apos;     LEFT OUTER JOIN IESIRI  IES ON IES.CODIES = L.CODIES&apos;||chr(13)||
                &apos;     LEFT OUTER JOIN INTRARI INTR ON INTR.CODINTR = L.CODINTR&apos;||chr(13)||
                &apos;     LEFT OUTER JOIN TRANSF  TRANSF ON TRANSF.CODTRANSF = L.CODTRANSF,&apos;||chr(13)||
                &apos;     NARTOBJ O&apos;||chr(13)||
                &apos;   WHERE&apos;||chr(13)||
                &apos;     N.CODNIR      = NS.CODNIR AND&apos;||chr(13)||
                &apos;     L1.CODNIRSTOC = NS.CODNIRSTOC AND&apos;||chr(13)||
                &apos;     L1.CODLIVR    = L.CODLIVR AND&apos;||chr(13)||
                vConditieStocNegativ||chr(13)||
                &apos;     O.CODOBIECT   = NS.CODOBIECT&apos;||chr(13)||
                &apos;   ) LIVR_DIN_NIRSTOC&apos;||chr(13)||
                &apos;     ORDER BY DENOBIECT, DATADOC&apos;||chr(13)||
                &apos;)&apos;||chr(13)||
                &apos; ANALIZA&apos;;

     if vTipAnaliza = 1 then
       sInsert := sInsert||
                  &apos; WHERE EXISTS&apos;||chr(13)||
                  &apos;   (SELECT CODNIRSTOC FROM NIRSTOC NS, NIR N WHERE NS.CODNIR = N.CODNIR AND &apos;||vCodDocAnalizat||&apos; AND NS.CODNIRSTOC = ANALIZA.CODNIRSTOC)&apos;||chr(13)||
                  &apos; ORDER BY  PREFIXDOC, NRDOC, DATADOC&apos;;
     end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_LIVRFROMNIR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRINTRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>65A760B315C23C685BAD3840D0BB3C53EDF53D40</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_livrintrdoc IS

  vCodIntr    INTRARI.CODINTR%TYPE;
  vCodGest    NGEST.CODGEST%TYPE;
  vSubCur     NSUBUNIT.CodSubunit%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodIntr IN NUMBER DEFAULT NULL,
                     pCodGest IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodIntr := pCodIntr;
  vSubCur  := pkg_globals.getSubunitate;
  IF nvl(pCodGest,-1) &gt;= 0 THEN
    vCodGest := pCodGest;
  ELSE
    vCodGest := -1;
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


PROCEDURE PROCESSPARAMS IS
 vTipDoc     NUMBER;
 vCodLocatie NUMBER;
 vPartener   NUMBER;
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  IF Nvl(pkg_globals.getSubunitate,0) = 0 -- se intampla ceva straniu la listele de documente
  THEN pkg_globals.SetSubunitate(vSubCur);
  END IF;


  FOR v_rec IN (
    SELECT G.DEN_GEST, NumePrenume(NP.Nume,NP.Prenume) Gestionar
    FROM NGEST G LEFT JOIN NPERS NP ON G.CODGESTIONAR = NP.CODPERS
    WHERE G.CODGEST = vCodGest
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE&apos;  ,         v_rec.Den_Gest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE GESTIONAR&apos;, v_rec.Gestionar);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.OBS, I.PARTENER, I.CODLOCATIE
    FROM INTRARI I
    WHERE I.CODINTR = vCodIntr
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT&apos;                 , v_rec.PrefixDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;           , v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;            , v_rec.DataDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT OBS&apos;             , v_rec.Obs);

    vTipDoc     := v_rec.TipDoc;
    vPartener   := v_rec.Partener;
    vCodLocatie := v_rec.CodLocatie;
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT stragg3200(NrLivr) NrLivr, stragg3200(DataLivr) DataLivr, stragg3200(ObsLivr) ObsLivr, stragg3200(ZiLivr) ZiLivr
    FROM (
      SELECT
        DISTINCT L.NRLIVR, To_Char(L.DATALIVR,&apos;dd.mm.yyyy&apos;) DataLivr, L.OBS ObsLivr, EXTRACT(DAY FROM L.DATALIVR) ZiLivr
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
        LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        LEFT JOIN nir n ON n.codnir = ns.codnir
      WHERE L.CodIntr = vCodIntr
        AND ( vCodGest = -1 OR Coalesce(lv.gest,n.gest,0) = vCodGest)
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.NUMAR&apos;, v_rec.NrLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.DATA&apos;,  v_rec.DataLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.OBS&apos;,   v_rec.ObsLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.ZI&apos;,    v_rec.ZiLivr);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      n.nume, n.prenume, n.cnp,
      d.delegat, d.doc deldoc, d.nrdoc nrdoctransp, d.seriedoc, d.eliberat, d.cnp delcnp, d.mijltransp, d.nrtransp, d.datadoc deldatadoc
    FROM INTRARI I
      LEFT JOIN NPERS N ON I.USERID = N.LOGONNAME
      LEFT JOIN NPARTTR D ON I.DELEGAT = D.CODPARTTR
    WHERE  I.CODINTR  = vCodIntr
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;           , v_rec.NUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;         , v_rec.PRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;             , v_rec.CNP);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;        , v_rec.DELEGAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;    , v_rec.DELCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;       , v_rec.DELDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;   , v_rec.NRDOCTRANSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos; , v_rec.SERIedoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;   , v_rec.ELIBERAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos; , v_rec.DELDATADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;            , v_rec.MIJLTRANSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;      , v_rec.NRTRANSP);

    EXIT;
  END LOOP;

  pkg_list_Struct.ADAUGA_PARAM(&apos;MASA FACTURATA&apos;               , TO_CHAR(0,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM FACTURAT&apos;               , TO_CHAR(0,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));

  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET SERIE&apos;                  , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR&apos;                  , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR PACHETE&apos;          , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA&apos;                   , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET Identificator&apos;          , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA COLECTARE&apos;     , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA COLECTARE&apos;         , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA VERIFICATOARE&apos; , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA VERIFICARE&apos;        , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT PERSOANA&apos;     , &apos;&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT DATA&apos;         , &apos;&apos;);

  IF vTipDoc IN (1,2,3,5) THEN -- parametrii client
    FOR v_rec IN (
      SELECT
        PB.CONTBANCA, B.DENUMIRE, B.SIMBOL, I.VALDOC, I.TVADOC
      FROM INTRARI I
        LEFT JOIN NPARTB PB ON PB.CODPART = I.PARTENER AND PB.IMPLICIT = 1
        LEFT JOIN NBANK B ON B.CODBANK = PB.CODBANK
      WHERE I.CODINTR = vCodIntr
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;, v_rec.CONTBANCA);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;, v_rec.DENUMIRE);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;, v_rec.SIMBOL);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;, TO_CHAR(COALESCE(v_rec.TVADOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VALOARE&apos;, TO_CHAR(COALESCE(v_rec.VALDOC,0)-COALESCE(v_rec.TVADOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;, TO_CHAR(COALESCE(v_rec.VALDOC,0), &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      EXIT;
    END LOOP;

    FOR v_rec IN (
      SELECT A.Obs, J.Den_Judet, A.TELEFON, GetAdresa(A.sector, A.strada, A.nr1, A.nr2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) AS ADRESA, L.DEN_LOCALIT, J.SIMBAUTO, A.CODCLIENT
      FROM NAGENDA A
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
        LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET
      WHERE CODAGENDA = vCodLocatie
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;        , v_rec.Adresa);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;      , v_rec.OBS);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;    , v_rec.Den_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;         , v_rec.DEN_JUDET);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;       , v_rec.Telefon);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos; , v_rec.CodClient);

      EXIT;
    END LOOP;

    FOR v_rec IN (
      SELECT P.DEN_PART, C.CODFISCAL, P.AUTORIZATIE, A.OBS, L.DEN_LOCALIT, J.Den_Judet, Decode(P.PERSOANAFIZICA,1,NULL,P.REGCOM) REGCOM, PC.NUME||&apos; &apos;||PC.PRENUME PERSC
      FROM NPART P
        LEFT JOIN NPARTCODFISC C ON C.CODPART = P.CODPART AND C.PRINCIPAL = 1
        LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART AND Nvl(a.Inactiv,0) = 0 AND A.SEDIUSOCIAL IN (4,5,6,7)
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
        LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET
        LEFT JOIN NPERSCONTACT PC ON PC.CODPART = P.CODPART
      WHERE P.CODPART = vPartener
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;               , v_rec.Den_Part);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD FISCAL&apos;             , v_rec.CodFiscal);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;        , v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE SPECIALA&apos;   , v_rec.Autorizatie);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SEDIU SOCIAL&apos;           , v_rec.Obs);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT LOCALITATE SEDIU SOCIAL&apos;, v_rec.Den_Localit);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT JUDET SEDIU SOCIAL&apos;     , v_rec.Den_Judet);
      pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT PERSOANA CONTACT IMPLICITA&apos; , v_rec.PersC);

      EXIT;
    END LOOP;
  ELSIF vTipDoc = 6 THEN -- parametrii subunitati
    FOR v_rec IN (
      SELECT S.Den_Subunit, L.DEN_LOCALIT, S.RegCom, BK.DENUMIRE as banca, BC.nrCONT contbanca, GetAdresa(A.sector, A.strada, A.nr1, A.nr2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) ADRESA, S.CIF
      FROM INTRARI I
        INNER JOIN NSUBUNIT S ON I.CODSUBUNIT = S.CODSUBUNIT
        LEFT JOIN NAGENDA A ON S.CODSUBUNIT = A.CODSUBUNIT
        LEFT JOIN nbankcont BC ON S.codbankcont = BC.codbankcont
        LEFT JOIN nbank BK ON BC.codbank = BK.codbank
        LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT
      WHERE I.CODINTR  = vCodIntr
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE DENUMIRE&apos;   , v_rec.DEN_SUBUNIT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE LOCALITATE&apos; , v_rec.DEN_LOCALIT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE ADRESA&apos;     , v_rec.ADRESA);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE CIF&apos;        , v_rec.CIF);
      pkg_list_Struct.ADAUGA_PARAM(&apos;SUBUNITATE DESTINATIE R.C.&apos;       , v_rec.RegCom);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE BANCA&apos;      , v_rec.banca);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate DESTINATIE CONT&apos;       , v_rec.contbanca);

      EXIT;
    END LOOP;

  ELSIF vTipDoc = 7 THEN -- parametrii productie proprie
    FOR v_rec IN (
      SELECT G.DEN_GEST
      FROM INTRARI I LEFT JOIN NGEST G ON I.CODGESTPROD = G.CODGEST
      WHERE I.CODINTR  = vCodIntr
    ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE PRODUCATOARE&apos;   , v_rec.DEN_GEST);

      EXIT;
    END LOOP;

  END IF;

  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;INTRARIF&apos;, &apos;CODINTR&apos;, vCodIntr);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(20000);
  sSelect    VARCHAR2(20000);
  vWhere     VARCHAR2( 1000);
  sPMP       VARCHAR2( 1000);
  sInsertUMA VARCHAR2( 1000);
  sSelectUMA VARCHAR2( 5000);
  sJoinUMA   VARCHAR2( 1000);
BEGIN

  gSuplCols := &apos;intrari i, nartobj nao, num1 um, ngest ng, nlocatii nl, doccarnete dc, num1 um1, num1 um2, npart prod, npart furn, nclasea ca, ioart io, ioart1 io1, ncont nc, nartobj1 nao1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;I1&apos;,   &apos;I1.CODINTR1 = LG.CODINTR1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vCodGest &gt;= 0 THEN
    vWhere := &apos;
        AND NVL(lv.gest,n.gest) = &apos;||vCodGest;
  END IF;

  IF pkg_globals.ANCURENT * 12 + pkg_globals.LUNACURENTA &lt; pkg_globals.ANLUCRU * 12 + pkg_globals.LUNALUCRU THEN
    sPMP := &apos;,
    DECODE(io1.mg,3,pkg_PMP.GET_PMP_LEI(lg.codobiect,i.subunitatea,i.an,i.luna),NULL), DECODE(io1.mg,3,pkg_PMP.GET_PMP_VALUTA_FROM_VAR,NULL), lg.pmpdoc, lg.pmpvalutadoc &apos;;
  ELSE
    sPMP := &apos;,
    lg.pmp, lg.pmpvaluta, lg.pmpdoc, lg.pmpvalutadoc &apos;;
  END IF;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;lg.cant&apos;,&apos;lg.codobiect&apos;,sInsertUMA,sSelectUMA,sJoinUMA);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    ART, UM, CANTDOC, CANTLIVR,
    PACH, PINREG, PVANZ,
    VALACH, VALINREG, VALVANZ,
    GESTIUNE, LOCATIE, NRLIVR, DATALIVR, DENCARNET, SIMBCARNET, SERCARNET, OBSLIVR, DATAEXP, DATAPROD, CODINTERN, CODEXTERN,
    DENCLASAA, SIMBCLASAA, MASA, VOLUM, PRODUCATOR, FURNIZOR, UM1, UM2, CANT1, CANT2,
    TIPSERIE, SERII, SER, DENIOART, SIMBCONT,
    PREFIXDOC, NRDOC, DATADOC, NRCERTIF, PUMAXIMAL, D1, D2, D3, DENCLASEAS, NRCOM, DATACOM, OBSDOC, CUSTODIE, CENTRUCOST,NIR,
    PMP, PMPVALUTA, PMPDOC, PMPVALUTADOC&apos;||sInsertUMA||gUserFields||&apos; )&apos;;

  sSelect := &apos;
  WITH
    LG AS (
      SELECT
        i.codintr, i1.codintr1, i1.indexlocal, i1.codobiect, NVL(lv.gest, n.gest) gest, ns.codlocatie, l1.umsec,
        i1.pu, i1.cant canti, i1.obs obsdoc, l.carnetlivr, l.nrlivr, l.datalivr, l.obs obslivr, i1.codcentru,
        NVL(ns.codioart,lv.codioart) codioart, ns.furn, ns.codgestprod gestfurn,
        SUM(NVL(lv.pretinreg,ns.pret)*l1.cant) valinreg,
        SUM(NVL(lv.pretachiz,ns.pret - ns.adaos)*l1.cant) valachiz,
        sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2, ns.d1, ns.d2, ns.d3,
        CASE nvl(ns.tipserie,0)
          WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
          ELSE NULL
        END SERII,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT s.serie) AS vc2_nt)) ser,
        NVL(i1.pumaximal,max(NVL(ns.pumaximal,0))) pumaximal,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg, ns.tg))) AS vc2_nt)) tg,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
        i1.nrcertif,
        decode(ns.tipserie,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
        max(l1.pmp) pmp, max(l1.pmpvaluta) pmpvaluta, max(l1.pmpdoc) pmpdoc, max(l1.pmpvalutadoc) pmpvalutadoc,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(N.NRNIR)) AS vc2_nt)) nir
      FROM intrari i
        INNER JOIN intrari1 i1   ON i1.codintr     = i.codintr
        INNER JOIN nartobj  nao  ON nao.codobiect  = i1.codobiect
        INNER JOIN livr     l    ON l.codintr      = i1.codintr
        LEFT  JOIN dvi1          ON dvi1.codintr1  = i1.codintr1
        LEFT  JOIN livr1    l1   ON l1.codlivr     = l.codlivr
        LEFT  JOIN livrval  lv   ON lv.codlivr1    = l1.codlivr1
        LEFT  JOIN nirstoc  ns   ON ns.codnirstoc  = l1.codnirstoc
        LEFT  JOIN nir      n    ON n.codnir       = ns.codnir
        LEFT  JOIN nirser   nser ON nser.codnirser = l1.codnirser
        LEFT  JOIN nserii   s    on s.codserie     = nser.codserie
      WHERE (l1.codintr1 = i1.codintr1 OR l1.coddvi1 = dvi1.coddvi1)
        AND L.CODINTR = &apos;||vCodIntr||vWhere ||&apos;
      GROUP BY
        i.codintr, i1.codintr1, i1.indexlocal, i1.codobiect, i1.cant, i1.pu, i1.pumaximal, i1.nrcertif, i1.obs,  i1.codcentru,
        l.carnetlivr, l.nrlivr, l.datalivr, l.obs, l1.umsec, lv.codioart, lv.gest,
        ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, n.gest, ns.d1, ns.d2, ns.d3
    )
  SELECT
    nao.denumire, um.den_um1, lg.canti / um.paritate, lg.cant/um.paritate,
    lg.valachiz*um.paritate/lg.cant, lg.valinreg*um.paritate/lg.cant, lg.pu*um.paritate, lg.valachiz, lg.valinreg, lg.pu * lg.cant,
    ng.den_gest, nl.denumire, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie, lg.obslivr, lg.tg, lg.dp, nao.codintern, nao.codextern,
    ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part, NVL(gfurn.den_gest,furn.den_part), um1.den_um, um2.den_um, lg.cantum1, lg.cantum2,
    lg.tipserie, lg.serii, lg.ser, io.den_ioart, nc.simbol,
    i.prefixdoc, i.nrdoc, i.datadoc, lg.nrcertif,
    CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
    lg.d1,lg.d2,lg.d3,cs.den_claseas,c.nrdoc,c.datadoc,lg.obsdoc, &apos;&apos;Nu&apos;&apos; custodie, cc.denumire,LG.NIR&apos;||
    sPMP||sSelectUMA||gUserAlias||&apos;
  FROM lg
    INNER JOIN intrari    i     ON i.codintr      = lg.codintr
    INNER JOIN nartobj    nao   ON nao.codobiect  = lg.codobiect
    INNER JOIN nart       na    ON na.codarticol  = nao.codarticol
    INNER JOIN num1       um    ON um.codum1      = lg.umsec
    INNER JOIN ngest      ng    ON ng.codgest     = lg.gest
    LEFT  JOIN nlocatii   nl    ON nl.codlocatie  = lg.codlocatie
    LEFT  JOIN doccarnete dc    ON dc.codcarnet   = lg.carnetlivr
    LEFT  JOIN num        um1   ON um1.codum      = na.um1
    LEFT  JOIN num        um2   ON um2.codum      = na.um2
    LEFT  JOIN npart      prod  ON prod.codpart   = nao.codproducator
    LEFT  JOIN npart      furn  ON furn.codpart   = lg.furn
    LEFT  JOIN ngest      gfurn ON gfurn.codgest  = lg.gestfurn
    LEFT  JOIN nclasea    ca    ON ca.codclasea   = na.clasa
    LEFT  JOIN nclaseas   cs    ON cs.codclaseas  = na.clasastatist
    LEFT  JOIN ioart      io    ON io.codioart    = lg.codioart
    LEFT  JOIN ioart1     io1   ON io1.codioart   = lg.codioart  AND (i.an*12+i.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT  JOIN ncont      nc    ON nc.codcont     = io1.cont
    LEFT  JOIN nartobj1   nao1  ON nao1.codobiect = lg.codobiect AND (i.an*12+i.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT  JOIN intrlink   il    ON il.codintr1    = lg.codintr1
    LEFT  JOIN comanda1   c1    ON c1.codcomanda1 = il.codliniecomanda
    LEFT  JOIN comanda    c     ON c.codcomanda   = c1.codcomanda
    LEFT  JOIN centrecost cc    ON cc.codcentru   = lg.codcentru&apos;||
    sJoinUMA||
    gSuplJoins||&apos;
  ORDER BY lg.codintr, lg.indexlocal&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  processparams;
  COMMIT;
END;

end PKG_LIST_BASE_LIVRINTRDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRNEREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51BE718928328D32309FD855977CE936D83E6BE1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRNEREZ IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
PRAGMA AUTONOMOUS_TRANSACTION;
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;tmp_livr_nerezolvate tmp&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,     &apos;O&apos;,    &apos;O.CODOBIECT = TMP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,  &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,  &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,       &apos;P&apos;,    &apos;P.CODPART = TMP.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    SERIEFACTURA, NRFACTURA, DENOBIECT, CANT, DENUM, CLIENT, COMANDA &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    tmp.seriefactura, tmp.nrfactura, tmp.denobiect, tmp.cant, tmp.denum, tmp.client, tmp.comanda &apos;||gUserAlias||&apos;
  FROM tmp_livr_nerezolvate tmp &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT tmp.seriefactura, tmp.nrfactura, tmp.client, tmp.comanda
    FROM tmp_livr_nerezolvate tmp
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.client);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FACTURA&apos;,                         v_rec.nrfactura);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA&apos;,                         v_rec.comanda);
    EXIT;
  END LOOP;

  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_LIVRNEREZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRPKDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B18D760820551C12E2E8E22246D4AAB766F4B93D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRPKDOC IS

  vCodPachete NUMBER(20);
  vTipPachet number(1);
  vTipLivrare number(5);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE SETPARAMS(pCodPachete IN NUMBER)  IS
BEGIN
  vCodPachete := pCodPachete;
  SELECT nvl(tippachet,0), nvl(tiplivrare,4) INTO vTipPachet, vTipLivrare
  FROM pachete
  WHERE codpachete = vCodPachete;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(15000);
  sSelect1 VARCHAR2(15000);
BEGIN
  gSuplCols := &apos;nartobj nao, num1 um, ngest ng, nlocatii nl, doccarnete dc, num1 um1, num1 um2, npart prod, npart furn, nclasea ca,&apos;||
               &apos;ioart io, ioart1 io1, ncont nc, nartobj1 nao1&apos;;

  IF vTipPachet = 1 THEN
    gSuplCols := gSuplCols||&apos;,pachete pk&apos;;
  else
    gSuplCols := gSuplCols||&apos;,pachete1 pk1,pachete pk, PACHETEOBJL POBJL&apos;;
  end if;  
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  IF vTipPachet = 1 THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PACHETEEXT&apos;, &apos;PKEXT&apos;, &apos;PKEXT.CODPACHETE = LG.CODPACHETE&apos;, 1);
  ELSE
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PACHETEEXT&apos;, &apos;PKEXT&apos;, &apos;PKEXT.CODPACHETE = PK1.CODPACHETE&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=&apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTDOC, CANTLIVR, PACH, PINREG, PVANZ,
    VALACH, VALINREG, VALVANZ, GESTIUNE, LOCATIE, NRLIVR, DATALIVR, DENCARNET, SIMBCARNET, SERCARNET, GAR, DATAEXP, DATAPROD,
    CODINTERN, CODEXTERN, DENCLASAA, SIMBCLASAA, MASA, VOLUM, PRODUCATOR, FURNIZOR, UM1, UM2, CANT1, CANT2, TIPSERIE,
    SERII, DENIOART, SIMBCONT, PREFIXDOC, NRDOC, DATADOC, NRCERTIF,
    PUMAXIMAL,
    D1, D2, D3&apos;||gUserFields||&apos;)&apos;;

  IF vTipPachet = 0 THEN
    DELETE IESIRI1_MAN;

    INSERT INTO IESIRI1_MAN
    SELECT I1.*
    FROM IESIRI1 I1 WHERE I1.TIPLIVRARE = vTipLivrare and EXISTS (select * from TMP_MANEVRA_LISTE TMP WHERE TMP.VALOARE = I1.CODIES and UPPER(tmp.filtru) = &apos;CODIES&apos;);

    sSelect := &apos;with 
    LG AS (
      SELECT
        pobj.codpacheteobjl, pk1.codpachete1, i.codies coddoc, i.tipdoc, i1.indexlocal, i1.codobiect, NVL(lv.gest, n.gest) gest, ns.codlocatie, l1.umsec, i1.pu, i1.cant canti, i1.garantie, l.carnetlivr, l.nrlivr, l.datalivr, NVL(ns.codioart,lv.codioart) codioart,
        ns.furn, ns.codgestprod gestfurn, SUM(NVL(lv.pretinreg,ns.pret)*l1.cant) valinreg, SUM(NVL(lv.pretachiz,ns.pret - ns.adaos)*l1.cant) valachiz,
        pobj.cant, pobj.cantum1, sum(l1.cantum2) cantum2,
        CASE nvl(ns.tipserie,na.tipserie)
          WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_string(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt))
          ELSE NULL
        END SERII,
        NVL(i1.pumaximal,max(NVL(ns.pumaximal,0))) pumaximal,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg))) AS vc2_nt)) tg,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        decode(nvl(ns.tipserie,na.tipserie),0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie,
        na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3
      FROM pacheteobjl pobj
        inner join pachete pk   on pk.codpachete   = pobj.codpachete
        INNER JOIN livr1   l1   ON l1.codlivr1     = pobj.codlivr1
        INNER JOIN livr    l    ON l.codlivr       = l1.codlivr
        INNER JOIN iesiri1 i1   on i1.codies1      = l1.codies1
        INNER JOIN iesiri  i    ON i.codies        = i1.codies and i.codies = l.codies
        INNER JOIN nartobj nao  ON nao.codobiect   = i1.codobiect
        INNER JOIN nart    na   ON na.codarticol   = nao.codarticol
        left JOIN pachete1 pk1  ON pk1.coddoc      = i.codies and pk1.tipdoc = i.tipdoc and PK1.CODPACHETE = pk.codpachete
        LEFT JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT JOIN NIRSTOC1 NS1  ON NS1.CODNIRSTOC  = NS.CODNIRSTOC
        LEFT JOIN NIRSTOC  NSIN ON nsin.codnirstoc = ns1.CODNIRSTOCORIG
        LEFT JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
        LEFT JOIN nirser   nser ON nser.codnirser  = l1.codnirser
        LEFT JOIN nserii   s on s.codserie         = nser.codserie
      WHERE PK.CODPACHETE = &apos;||vCodPachete||&apos;
      GROUP BY
        i.codies, i.tipdoc, i1.indexlocal, i1.codobiect, i1.cant, i1.garantie, i1.pu, i1.pumaximal,l.carnetlivr, l.nrlivr, l.datalivr, l1.umsec, lv.codioart, lv.gest,
        ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, n.gest, na.tipserie, na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3, pobj.cant, pobj.cantum1,
        pk1.codpachete1, pobj.codpacheteobjl
        )
    SELECT
      nao.denumire, um.den_um1, lg.canti / nvl(um.paritate, 1), lg.cant/nvl(um.paritate, 1), lg.valachiz*nvl(um.paritate, 1)/lg.cant, lg.valinreg*nvl(um.paritate, 1)/lg.cant, lg.pu*nvl(um.paritate, 1),
      lg.valachiz, lg.valinreg, lg.pu * lg.cant, ng.den_gest, nl.denumire, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie, lg.garantie, lg.tg,  lg.dp,
      nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part, NVL(gfurn.den_gest,furn.den_part), um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, lg.tipserie,
      lg.serii, io.den_ioart, nc.simbol, i.prefixdoc, i.nrdoc, i.datadoc, lg.nrcertif,
      CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
      lg.D1, lg.D2, lg.D3 &apos;||gUserAlias||&apos;
    FROM lg
      INNER JOIN iesiri      i     ON i.codies        = lg.coddoc
      INNER JOIN nartobj     nao   ON nao.codobiect   = lg.codobiect
      INNER JOIN num1        um    ON um.codum1       = lg.umsec
      INNER JOIN ngest       ng    ON ng.codgest      = lg.gest
      LEFT  JOIN PACHETE1    PK1   ON PK1.CODPACHETE1 = LG.CODPACHETE1
      LEFT  JOIN PACHETE     PK    ON PK.CODPACHETE   = PK1.CODPACHETE
      left  join pacheteobjl pobjl on pobjl.codpacheteobjl = lg.codpacheteobjl
      LEFT  JOIN nlocatii    nl    ON nl.codlocatie  = lg.codlocatie
      LEFT  JOIN doccarnete  dc    ON dc.codcarnet   = lg.carnetlivr
      LEFT  JOIN num         um1   ON um1.codum      = lg.um1
      LEFT  JOIN num         um2   ON um2.codum      = lg.um2
      LEFT  JOIN npart       prod  ON prod.codpart   = nao.codproducator
      LEFT  JOIN npart       furn  ON furn.codpart   = lg.furn
      LEFT  JOIN ngest       gfurn ON gfurn.codgest  = lg.gestfurn
      LEFT  JOIN nclasea     ca    ON ca.codclasea   = lg.clasa
      LEFT  JOIN ioart       io    ON io.codioart    = lg.codioart
      LEFT  JOIN ioart1      io1   ON io1.codioart   = lg.codioart  AND (i.an*12+i.luna) BETWEEN  io1.ALStart and  io1.ALStop
      LEFT  JOIN ncont       nc    ON nc.codcont     = io1.cont
      LEFT  JOIN nartobj1    nao1  ON nao1.codobiect = lg.codobiect AND (i.an*12+i.luna) BETWEEN nao1.ALStart and nao1.ALStop &apos;||
      gSuplJoins||&apos;
    ORDER BY lg.coddoc, lg.indexlocal&apos;;

    DELETE TRANSF1_MAN;

    INSERT INTO TRANSF1_MAN (CODTRANSF1,CODTRANSF,INDEXLOCAL,TIPLINIE,UMSEC,CODOBIECT,PU,CANT,TVA,OBS,CODCONT,PUMAXIMAL,COSTTRANSPORT,CODOBIECTORIG,CODAUTO)
           SELECT T1.CODTRANSF1,T1.CODTRANSF,T1.INDEXLOCAL,T1.TIPLINIE,T1.UMSEC,T1.CODOBIECT,T1.PU,T1.CANT,T1.TVA,T1.OBS,T1.CODCONT,T1.PUMAXIMAL,T1.COSTTRANSPORT,
                  TMP.VALOARE1, TMP.VALOARE2
           FROM TRANSF1 T1 
                INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = T1.CODTRANSF and UPPER(tmp.filtru) = &apos;CODTRANSF&apos;;

    sSelect1 := &apos;
    WITH LG AS (
      SELECT
        0 codpacheteobjl, t1.CODOBIECTORIG codpachete1, t.codtransf coddoc, t.tipdoc, t1.indexlocal, t1.codobiect, NVL(lv.gest, n.gest) gest, ns.codlocatie, l1.umsec, t1.pu, t1.cant cantt, l.carnetlivr, l.nrlivr, l.datalivr, NVL(lv.codioart,ns.codioart) codioart,
        ns.furn, ns.codgestprod gestfurn, SUM(NVL(lv.pretinreg,ns.pret)*l1.cant) valinreg, SUM(NVL(lv.pretachiz,ns.pret - ns.adaos)*l1.cant) valachiz,
        sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2,
        CASE nvl(ns.tipserie,na.tipserie) WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie) AS vc2_nt)) WHEN 2 THEN vc2_nt_to_string(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt)) ELSE NULL END SERII,
        NVL(t1.pumaximal,max(ns.pumaximal)) pumaximal,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg))) AS vc2_nt)) tg,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        decode(nvl(ns.tipserie,na.tipserie),0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie,
        na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3
      FROM TRANSF1_MAN t1
        INNER JOIN transf   t    ON t.codtransf     = t1.codtransf
        INNER JOIN nartobj  nao  ON nao.codobiect   = t1.codobiect
        INNER JOIN nart     na   ON na.codarticol   = nao.codarticol
        INNER JOIN livr     l    ON l.codtransf     = t1.codtransf
        INNER JOIN livr1    l1   ON l1.codies1      = t1.codtransf1 AND l1.codlivr = l.codlivr
        LEFT  JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT  JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT  JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT  JOIN NIRSTOC1 NS1  ON NS1.CODNIRSTOC  = NS.CODNIRSTOC
        LEFT  JOIN NIRSTOC  NSIN ON nsin.codnirstoc = ns1.CODNIRSTOCORIG
        LEFT  JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT  JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
        LEFT  JOIN nirser   nser ON nser.codnirser  = l1.codnirser
        LEFT  JOIN nserii   s    on s.codserie      = nser.codserie
      GROUP BY
        t.codtransf, t.tipdoc, t1.indexlocal, t1.codobiect, t1.pu, t1.cant, t1.pumaximal, l.carnetlivr, l.nrlivr, l.datalivr, l1.umsec, lv.codioart, lv.gest,
        ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, n.gest, na.tipserie, na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3,t1.CODOBIECTORIG )
    SELECT
      nao.denumire, um.den_um1, lg.cantt / nvl(um.paritate, 1), lg.cant/nvl(um.paritate, 1), lg.valachiz*nvl(um.paritate, 1)/lg.cant, lg.valinreg*nvl(um.paritate, 1)/lg.cant, lg.pu*um.paritate,
      lg.valachiz, lg.valinreg, lg.pu * lg.cant, ng.den_gest, nl.denumire, lg.nrlivr, lg.datalivr, dc.denumire, dc.simbol, dc.serie, nao.lunigarantie, lg.tg, lg.dp,
      nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part, NVL(gfurn.den_gest,furn.den_part), um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, lg.tipserie,
      lg.serii, io.den_ioart, nc.simbol, t.prefixdoc, t.nrdoc, t.datadoc, lg.nrcertif,
      CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
      lg.D1, lg.D2, lg.D3 &apos;||gUserAlias||&apos;
    FROM LG
      INNER JOIN transf      t     ON t.codtransf       = lg.coddoc
      INNER JOIN nartobj     nao   ON nao.codobiect     = lg.codobiect
      INNER JOIN nart        na    ON na.codarticol     = nao.codarticol
      INNER JOIN num1        um    ON um.codum1         = lg.umsec
      INNER JOIN ngest       ng    ON ng.codgest        = lg.gest
      LEFT  JOIN PACHETE1    PK1   ON PK1.CODPACHETE1   = LG.CODPACHETE1
      LEFT  JOIN PACHETE     PK    ON PK.CODPACHETE     = PK1.CODPACHETE
      LEFT  JOIN PACHETEOBJL POBJL ON LG.CODPACHETEOBJL = POBJL.CODPACHETEOBJL
      LEFT  JOIN nlocatii    nl    ON nl.codlocatie     = lg.codlocatie
      LEFT  JOIN doccarnete  dc    ON dc.codcarnet      = lg.carnetlivr
      LEFT  JOIN num         um1   ON um1.codum         = lg.um1
      LEFT  JOIN num         um2   ON um2.codum         = lg.um2
      LEFT  JOIN npart       prod  ON prod.codpart      = nao.codproducator
      LEFT  JOIN npart       furn  ON furn.codpart      = lg.furn
      LEFT  JOIN ngest       gfurn ON gfurn.codgest     = lg.gestfurn
      LEFT  JOIN nclasea     ca    ON ca.codclasea      = lg.clasa
      LEFT  JOIN ioart       io    ON io.codioart       = lg.codioart
      LEFT  JOIN ioart1      io1   ON io1.codioart      = lg.codioart  AND (t.an*12+t.luna) BETWEEN  io1.ALStart and  io1.ALStop
      LEFT  JOIN ncont       nc    ON nc.codcont        = io1.cont
      LEFT  JOIN nartobj1    nao1  ON nao1.codobiect    = lg.codobiect AND (t.an*12+t.luna) BETWEEN nao1.ALStart and nao1.ALStop &apos;||
      gSuplJoins||&apos;
    ORDER BY lg.coddoc, lg.indexlocal&apos;;

    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
    
    sSelect := &apos;
    WITH LG AS (
      SELECT
        pobj.codpacheteobjl, 0 codpachete1, c.codcomanda coddoc, c.tipdoc, c1.indexlocal, c1.codobiect, n.gest, ns.codlocatie, ns.umsec, c1.pu, c1.cantacceptat canti, null garantie, c.carnetdoc, c.nrdoc, c.datadoc, ns.codioart,
        ns.furn, ns.codgestprod gestfurn, SUM(ns.pret*pobj.cant) valinreg, SUM((ns.pret - coalesce(ns.adaos,0))*pobj.cant) valachiz,
        pobj.cant, pobj.cantum1, sum(case when coalesce(ns.cantnir,0) = 0 then 0 else ns.cantum2*pobj.cant/ns.cantnir end) cantum2,
        CASE nvl(ns.tipserie,na.tipserie)
          WHEN 1 THEN vc2_nt_to_string(CAST(collect(distinct s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_string(CAST(collect(distinct s.serie||&apos;&apos;(&apos;&apos;||pobj.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt))
          ELSE NULL
        END SERII,
        max(coalesce(ns.pumaximal,0)) pumaximal,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg))) AS vc2_nt)) tg,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        decode(nvl(ns.tipserie,na.tipserie),0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie,
        na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3
      FROM pacheteobjl pobj
        inner join pachete  pk  on pk.codpachete   = pobj.codpachete
        INNER JOIN rezervats r  ON r.codrezervats  = pobj.codrezervats
        INNER JOIN comanda1 c1  on c1.codcomanda1  = r.codcomanda1
        INNER JOIN comanda   c  ON c.codcomanda    = c1.codcomanda
        INNER JOIN nartobj nao  ON nao.codobiect   = c1.codobiect
        INNER JOIN nart    na   ON na.codarticol   = nao.codarticol
        left JOIN pachete1 pk1  ON pk1.coddoc      = na.codarticol - na.codarticol
        LEFT JOIN nirstoc  ns   ON ns.codnirstoc   = r.codnirstoc
        LEFT JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT JOIN NIRSTOC1 NS1  ON NS1.CODNIRSTOC  = NS.CODNIRSTOC
        LEFT JOIN NIRSTOC  NSIN ON nsin.codnirstoc = ns1.CODNIRSTOCORIG
        LEFT JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
        LEFT JOIN nirser   nser ON nser.codnirser  = r.codnirser
        LEFT JOIN nserii   s on s.codserie         = nser.codserie
      WHERE PK.CODPACHETE = &apos;||vCodPachete||&apos;
      GROUP BY
        pobj.codpacheteobjl, c.codcomanda, c.tipdoc, c1.indexlocal, c1.codobiect, n.gest, ns.codlocatie, ns.umsec, 
        c1.pu, c1.cantacceptat, c.carnetdoc, c.nrdoc, c.datadoc, ns.codioart, ns.furn, ns.codgestprod, pobj.cant, pobj.cantum1,
        ns.tipserie, na.tipserie, na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3
        )
    SELECT
      nao.denumire, um.den_um1, lg.canti / nvl(um.paritate, 1), lg.cant/nvl(um.paritate, 1), lg.valachiz*nvl(um.paritate, 1)/lg.cant, lg.valinreg*nvl(um.paritate, 1)/lg.cant, lg.pu*nvl(um.paritate, 1),
      lg.valachiz, lg.valinreg, lg.pu * lg.cant, ng.den_gest, nl.denumire, c.nrdoc nrlivr, c.datadoc datalivr, dc.denumire, dc.simbol, dc.serie, lg.garantie, lg.tg,  lg.dp,
      nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part, NVL(gfurn.den_gest,furn.den_part), um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, lg.tipserie,
      lg.serii, io.den_ioart, nc.simbol, c.prefixdoc, c.nrdoc, c.datadoc, lg.nrcertif,
      CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
      lg.D1, lg.D2, lg.D3 &apos;||gUserAlias||&apos;
    FROM lg
      INNER JOIN comanda     c     ON c.codcomanda    = lg.coddoc and c.tipdoc = lg.tipdoc
      INNER JOIN nartobj     nao   ON nao.codobiect   = lg.codobiect
      INNER JOIN num1        um    ON um.codum1       = lg.umsec
      INNER JOIN ngest       ng    ON ng.codgest      = lg.gest
      left  join pacheteobjl pobjl on pobjl.codpacheteobjl = lg.codpacheteobjl
      LEFT  JOIN PACHETE1    PK1   ON PK1.CODPACHETE1 = LG.CODPACHETE1
      LEFT  JOIN PACHETE     PK    ON PK.CODPACHETE   = POBJL.CODPACHETE
      LEFT  JOIN nlocatii    nl    ON nl.codlocatie  = lg.codlocatie
      LEFT  JOIN doccarnete  dc    ON dc.codcarnet   = lg.codlocatie - lg.codlocatie
      LEFT  JOIN num         um1   ON um1.codum      = lg.um1
      LEFT  JOIN num         um2   ON um2.codum      = lg.um2
      LEFT  JOIN npart       prod  ON prod.codpart   = nao.codproducator
      LEFT  JOIN npart       furn  ON furn.codpart   = lg.furn
      LEFT  JOIN ngest       gfurn ON gfurn.codgest  = lg.gestfurn
      LEFT  JOIN nclasea     ca    ON ca.codclasea   = lg.clasa
      LEFT  JOIN ioart       io    ON io.codioart    = lg.codioart
      LEFT  JOIN ioart1      io1   ON io1.codioart   = lg.codioart  AND (c.an*12+c.luna) BETWEEN  io1.ALStart and  io1.ALStop
      LEFT  JOIN ncont       nc    ON nc.codcont     = io1.cont
      LEFT  JOIN nartobj1    nao1  ON nao1.codobiect = lg.codobiect AND (c.an*12+c.luna) BETWEEN nao1.ALStart and nao1.ALStop  &apos;||
      gSuplJoins||&apos;
    ORDER BY lg.coddoc, lg.indexlocal&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  ELSE
    sSelect := &apos;
    WITH 
    LG AS (
      SELECT
        ns.codobiect, n.gest, ns.codlocatie, ns.umsec, pobj.cant canti, ns.codioart,
        ns.furn, ns.codgestprod gestfurn, ns.pret*pobj.cant valinreg, (ns.pret - nvl(ns.adaos,0)) * pobj.cant valachiz,
        pobj.cant, ns.pret pu,
        round(CASE
                WHEN na.RELATIEUM1 IN (1, 7) AND NVL(ns.D1, 0) &lt;&gt; 0 THEN pobj.cant/ns.D1
                WHEN na.RELATIEUM1 IN (2, 8) AND NVL(ns.D1, 0) * NVL(ns.D2, 0) &lt;&gt; 0 THEN pobj.cant / (NVL(ns.D1,0) * NVL(ns.D2,0))
                WHEN na.RELATIEUM1 IN (3, 9) AND NVL(ns.D1, 0) * NVL(ns.D2, 0) * NVL(ns.D3, 0) &lt;&gt; 0 THEN pobj.cant / (NVL(ns.D1,0) * NVL(ns.D2,0) * NVL(ns.D3,0))
                WHEN na.RELATIEUM1 IN (4, 10) THEN pobj.cant * NVL(ns.D1,0)
                WHEN na.RELATIEUM1 IN (5, 11) THEN pobj.cant * NVL(ns.D1, 0) * NVL(ns.D2, 0)
                WHEN na.RELATIEUM1 IN (6, 12) THEN pobj.cant * NVL(ns.D1, 0) * NVL(ns.D2, 0) * NVL(ns.D3, 0)
              END,7) cantum1,
        0 cantum2,
        nvl(ns.pumaximal,0) pumaximal,
        ns.tg,
        to_char(int1.nrcertif) nrcertif,
        decode(nvl(ns.tipserie,na.tipserie),0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie,
        na.um1, na.um2, na.clasa, ns.D1, ns.D2, ns.D3, pk.an, pk.luna, pk.codpachete
      FROM pacheteobj pobj
        INNER JOIN pachete  pk   ON pobj.codpachete = pk.codpachete
        INNER JOIN nirstoc  ns   ON ns.codnirstoc   = pobj.codnirstoc
        INNER JOIN nartobj  nao  ON nao.codobiect   = ns.codobiect
        INNER JOIN nart     na   ON na.codarticol   = nao.codarticol
        LEFT  JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT JOIN NIRSTOC1  NS1  ON NS1.CODNIRSTOC  = NS.CODNIRSTOC
        LEFT JOIN NIRSTOC   NSIN ON nsin.codnirstoc = ns1.CODNIRSTOCORIG
        LEFT  JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT  JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
      WHERE pk.codpachete = &apos;||vCodPachete||&apos;
      )
    SELECT
      nao.denumire, um.den_um1, lg.canti / nvl(um.paritate, 1), lg.cant/nvl(um.paritate, 1), lg.valachiz*nvl(um.paritate, 1)/lg.cant, lg.valinreg*nvl(um.paritate, 1)/lg.cant, lg.pu*nvl(um.paritate, 1),
      lg.valachiz, lg.valinreg, lg.pu * lg.cant, ng.den_gest, nl.denumire, null nrlivr, null datalivr, null denumire, null simbol, null serie, null garantie, lg.tg, null dp,
      nao.codintern, nao.codextern, ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part, NVL(gfurn.den_gest,furn.den_part), um1.den_um, um2.den_um, lg.cantum1, lg.cantum2, lg.tipserie,
      null serii, io.den_ioart, nc.simbol, null prefixdoc, null nrdoc, null datadoc, lg.nrcertif,
      CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN lg.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
      lg.D1, lg.D2, lg.D3 &apos;||gUserAlias||&apos;
    FROM lg
      INNER JOIN nartobj  nao   ON nao.codobiect  = lg.codobiect
      INNER JOIN num1     um    ON um.codum1      = lg.umsec
      INNER JOIN ngest    ng    ON ng.codgest     = lg.gest
      INNER JOIN PACHETE  PK    ON LG.CODPACHETE  = PK.CODPACHETE
      LEFT  JOIN nlocatii nl    ON nl.codlocatie  = lg.codlocatie
      LEFT  JOIN num      um1   ON um1.codum      = lg.um1
      LEFT  JOIN num      um2   ON um2.codum      = lg.um2
      LEFT  JOIN npart    prod  ON prod.codpart   = nao.codproducator
      LEFT  JOIN npart    furn  ON furn.codpart   = lg.furn
      LEFT  JOIN ngest    gfurn ON gfurn.codgest  = lg.gestfurn
      LEFT  JOIN nclasea  ca    ON ca.codclasea   = lg.clasa
      LEFT  JOIN ioart    io    ON io.codioart    = lg.codioart
      LEFT  JOIN ioart1   io1   ON io1.codioart   = lg.codioart  AND (lg.an*12+lg.luna) BETWEEN io1.ALStart and io1.ALStop
      LEFT  JOIN ncont    nc    ON nc.codcont     = io1.cont
      LEFT  JOIN nartobj1 nao1  ON nao1.codobiect = lg.codobiect AND (lg.an*12+lg.luna) BETWEEN nao1.ALStart and nao1.ALStop &apos;||
      gSuplJoins||&apos;
    &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  END IF;

  COMMIT;
END;

end pkg_list_base_livrpkdoc; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRSIMPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3989E492F7C1537CAAA5D3D783D61191A70F5ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRSIMPL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  -- atentie - aici trebuie sa se regaseasca tabele care sunt in toate cele trei selecturi cu aliasurile corespunzatoare
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      CLOB;
  sSelectIes   CLOB;
  sSelectT     CLOB;
  sSelectInt   CLOB;
  sCondDataI   VARCHAR2(  100);
  sCondDataT   VARCHAR2(  100);
  sJoinUM      VARCHAR2( 1000);
  vFiltru      VARCHAR2( 5000);
  sTipIes      VARCHAR2( 1000);
  sTipIntr     VARCHAR2( 1000);
  sTipT        VARCHAR2( 1000);
  vFiltruIes   VARCHAR2( 1000);
  vFiltruIntr  VARCHAR2( 1000);
  vFiltruT     VARCHAR2( 1000);
BEGIN
  gSuplCols :=
    &apos;livr l, iesiri ies, intrari intr, transf t, livr1 l1, livrval lv, nirstoc ns, nir n, num1 u1, nartobj nao, nart na, NUM UM1, NUM UM2, ngest g, nlocatii nl, nsubunit ss, doccarnete dc, &apos;||
    &apos;ioart io, ioart1 io1, ncont nc, ioart ioi, npart np, ngest gd, nsubunit sd&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,    &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);

  IF    PKG_LIST_SELLIVRARI.TipData = 2 THEN
    vFiltruIes := &apos;
    AND ies.an*12+ies.luna &apos;||PKG_LIST_SELLIVRARI.Perioada;
    vFiltruIntr := &apos;
    AND intr.an*12+intr.luna &apos;||PKG_LIST_SELLIVRARI.Perioada;
    vFiltruT := &apos;
    AND t.an*12+t.luna &apos;||PKG_LIST_SELLIVRARI.Perioada;
  ELSIF PKG_LIST_SELLIVRARI.TipData = 1 THEN
    vFiltruIes := &apos;
    AND ies.datadoc &apos;||PKG_LIST_SELLIVRARI.Perioada;
    vFiltruIntr := &apos;
    AND intr.datadoc &apos;||PKG_LIST_SELLIVRARI.Perioada;
    vFiltruT := &apos;
    AND t.datadoc &apos;||PKG_LIST_SELLIVRARI.Perioada;
  ELSE
    vFiltru := &apos;
    AND l.datalivr &apos;||PKG_LIST_SELLIVRARI.Perioada;
  END IF;

  IF NOT PKG_LIST_SELLIVRARI.ToateGest THEN
    vFiltru := vFiltru||&apos;
    AND COALESCE(l1.codgestorig, lv.gest, n.gest) IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; ) &apos;;
  END IF;

  IF NOT PKG_LIST_SELLIVRARI.ToateArt THEN
    vFiltru := vFiltru||&apos;
    AND Coalesce(lv.codobiect, ns.codobiect) IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;

  IF PKG_LIST_SELLIVRARI.Um = 0 THEN 
    sJoinUM := &apos;
    LEFT  JOIN num1 u1            ON u1.codum1       = l1.umsec&apos;;
  ELSE
    sJoinUM := &apos;
    LEFT  JOIN num1 u1            ON u1.codum        = na.um AND secundara = 0&apos;;
  END IF;

  IF PKG_LIST_SELLIVRARI.ToateDoc THEN 
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipIntr FROM (SELECT DISTINCT tipdoc FROM intrari) WHERE TIPDOC &lt;&gt; 9;
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipIes  FROM (SELECT DISTINCT tipdoc FROM iesiri ) WHERE TIPDOC &lt;&gt; 26;
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipT    FROM (SELECT DISTINCT tipdoc FROM transf );
  ELSE
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipIntr FROM (SELECT DISTINCT tipdoc FROM intrari) WHERE TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;TIPDOC&apos; );
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipIes  FROM (SELECT DISTINCT tipdoc FROM iesiri ) WHERE TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;TIPDOC&apos; );
    SELECT listagg(tipdoc, &apos;,&apos;) WITHIN GROUP (ORDER BY tipdoc) INTO sTipT    FROM (SELECT DISTINCT tipdoc FROM transf ) WHERE TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;TIPDOC&apos; );
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    DenArt, DenUM, DenGest, DenLGest, SimbolCont,
    Document, PrefixDoc, NrDoc, DataDoc, NumeDoc,
    DocLivr, NrLivr, DataLivr, DenCarnetLivr, SimbCarnetLivr, SerCarnetLivr,
    CantLivr, PInreg, PretAch,
    Destinatie,
    DenIOART, UM1,UM2,CantUM1,CantUM2, MASA,VOLUM,
    DataAchiz, STipDoc, AnDoc,LunaDoc, Luna,
    IOARTInterm &apos;||gUserFields||&apos;)&apos;;

  sSelectIes := &apos;
  SELECT
    ies.codies NAV_CodDoc, ies.tipdoc NAV_TipDoc,
    nao.denumire DenArt, u1.den_um1 DenUM, g.den_gest DenGest, nl.denumire DenLGest, nc.simbol SimbolCont,
    ies.prefixdoc||&apos;&apos;.&apos;&apos;||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc Document, ies.PrefixDoc, ies.NrDoc, ies.DataDoc, PKG_LIST_BASE_UTILS.decode_tipdoc(ies.tipdoc) NumeDoc,
    &apos;&apos;LIVR &apos;&apos;||l.nrlivr||&apos;&apos; / &apos;&apos;||l.datalivr DocLivr, l.NrLivr, l.DataLivr, dc.denumire DenCarnetLivr, dc.simbol SimbCarnetLivr, dc.serie SerCarnetLivr,
    l1.cant / u1.paritate, Coalesce(lv.pretinreg,ns.pret) * u1.paritate * CASE WHEN ies.tipdoc = 15 THEN -1 ELSE 1 END PInreg, Coalesce(lv.pretachiz,ns.pret - ns.adaos) * u1.paritate * CASE WHEN ies.tipdoc = 15 THEN -1 ELSE 1 END PretAch,
    CASE WHEN ies.tipdoc IN (15,16) THEN &apos;&apos;-&apos;&apos; WHEN ies.tipdoc = 23 THEN sd.den_subunit WHEN ies.tipdoc = 24 THEN gd.den_gest ELSE np.den_part END Destinatie,
    io.den_ioart DenIOART, um1.den_um UM1, um2.den_um UM2, l1.CantUM1, l1.CantUM2, nao.masa, nao.volum,
    ns.DataAchiz, pkg_list_base_utils.decode_tipdoc_scurt(ies.tipdoc) STipDoc, ies.an AnDoc, ies.luna LunaDoc, to_char(ies.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(ies.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(ies.Luna) Luna,
    ioi.den_ioart IOARTInterm&apos;||gUserAlias||&apos;
  FROM livr l
    INNER JOIN iesiri ies         ON ies.codies      = l.codies AND l.tiplivr = ies.tipdoc
    LEFT  JOIN intrari intr       ON intr.codintr    = 0
    LEFT  JOIN transf t           ON t.codtransf     = 0
    INNER JOIN livr1 l1           ON l1.codlivr      = l.codlivr
    LEFT  JOIN livrval lv         ON lv.codlivr1     = l1.codlivr1
    LEFT  JOIN nirstoc ns         ON ns.codnirstoc   = l1.codnirstoc
    LEFT  JOIN nir n              ON n.codnir        = ns.codnir
    LEFT  JOIN nartobj nao        ON nao.codobiect   = Coalesce(lv.codobiect, ns.codobiect)
    LEFT  JOIN nart na            ON na.codarticol   = nao.codarticol&apos;||
    sJoinUM||&apos;
    LEFT  JOIN NUM UM1            ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2            ON um2.codum       = na.um2
    LEFT  JOIN ngest g            ON g.codgest       = Coalesce(lv.gest, n.gest, 0)
    LEFT  JOIN nlocatii nl        ON nl.codlocatie   = ies.codlocatie
    LEFT  JOIN nsubunit ss        ON ss.codsubunit   = ies.subunitatea
    LEFT  JOIN doccarnete dc      ON dc.codcarnet    = l.carnetlivr
    LEFT  JOIN ioart io           ON io.codioart     = Coalesce(lv.codioart,ns.codioart)
    LEFT  JOIN ioart1         io1 ON io1.codioart    = io.codioart AND io1.alstart &lt;= ies.an*12+ies.luna AND io1.alstop &gt;= ies.an*12+ies.luna
    LEFT  JOIN ncont nc           ON nc.codcont      = io1.cont
    LEFT  JOIN ioart ioi          ON ioi.codioart    = Coalesce(NULLIF(l1.contintermed,0),ies.contintermed,0)
    LEFT  JOIN npart np           ON np.codpart      = ies.partener
    LEFT  JOIN ngest gd           ON gd.codgest      = ies.codgestprod
    LEFT  JOIN nsubunit sd        ON sd.codsubunit   = ies.codsubunit&apos;||
    gSuplJoins||&apos;
  WHERE (l.codies IS NOT NULL) AND (l.operat = 1) AND (l.anulat = 0)
    AND l.tiplivr  IN (&apos;||sTipIes||&apos;)
    AND ies.tipdoc IN (&apos;||sTipIes||&apos;) &apos;||
    vFiltru||
    vFiltruIes||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;IES&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;IES&apos;);

  sSelectInt := &apos;
  SELECT
    intr.codintr NAV_CodDoc, intr.tipdoc NAV_TipDoc,
    nao.denumire DenArt, u1.den_um1 DenUM, g.den_gest DenGest, nl.denumire DenLGest, nc.simbol SimbolCont,
    intr.prefixdoc||&apos;&apos;.&apos;&apos;||intr.nrdoc||&apos;&apos; / &apos;&apos;||intr.datadoc Document, intr.PrefixDoc, intr.NrDoc, intr.DataDoc, PKG_LIST_BASE_UTILS.decode_tipdoc(intr.tipdoc) NumeDoc,
    &apos;&apos;LIVR &apos;&apos;||l.nrlivr||&apos;&apos; / &apos;&apos;||l.datalivr DocLivr, l.NrLivr, l.DataLivr, dc.denumire DenCarnetLivr, dc.simbol SimbCarnetLivr, dc.serie SerCarnetLivr,
    l1.cant / u1.paritate, Coalesce(lv.pretinreg,ns.pret) * u1.paritate * CASE WHEN intr.tipdoc = 15 THEN -1 ELSE 1 END PInreg, Coalesce(lv.pretachiz,ns.pret - ns.adaos) * u1.paritate * CASE WHEN intr.tipdoc = 15 THEN -1 ELSE 1 END PretAch,
    CASE WHEN intr.tipdoc = 6 THEN sd.den_subunit WHEN intr.tipdoc = 7 THEN gd.den_gest ELSE np.den_part END Destinatie,
    io.den_ioart DenIOART, um1.den_um UM1, um2.den_um UM2, l1.CantUM1, l1.CantUM2, nao.masa, nao.volum,
    ns.DataAchiz, pkg_list_base_utils.decode_tipdoc_scurt(intr.tipdoc) STipDoc, intr.an AnDoc, intr.luna LunaDoc, to_char(intr.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(intr.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(intr.Luna) Luna,
    ioi.den_ioart IOARTInterm&apos;||gUserAlias||&apos;
  FROM livr l
    INNER JOIN intrari intr       ON intr.codintr    = l.codintr AND intr.tipdoc = l.tiplivr
    LEFT  JOIN iesiri ies         ON ies.codies      = 0
    LEFT  JOIN transf t           ON t.codtransf     = 0
    INNER JOIN livr1 l1           ON l1.codlivr      = l.codlivr
    LEFT  JOIN livrval lv         ON lv.codlivr1     = l1.codlivr1
    LEFT  JOIN nirstoc ns         ON ns.codnirstoc   = l1.codnirstoc
    LEFT  JOIN nir n              ON n.codnir        = ns.codnir
    LEFT  JOIN nartobj nao        ON nao.codobiect   = Coalesce(lv.codobiect, ns.codobiect)
    LEFT  JOIN nart na            ON na.codarticol   = nao.codarticol&apos;||
    sJoinUM||&apos;
    LEFT  JOIN NUM UM1            ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2            ON um2.codum       = na.um2
    LEFT  JOIN ngest g            ON g.codgest       = Coalesce(lv.gest, n.gest, 0)
    LEFT  JOIN nlocatii nl        ON nl.codlocatie   = intr.codlocatie
    LEFT  JOIN nsubunit ss        ON ss.codsubunit   = intr.subunitatea
    LEFT  JOIN doccarnete dc      ON dc.codcarnet    = l.carnetlivr
    LEFT  JOIN ioart io           ON io.codioart     = Coalesce(lv.codioart,ns.codioart)
    LEFT  JOIN ioart1         io1 ON io1.codioart    = io.codioart AND io1.alstart &lt;= intr.an*12+intr.luna AND io1.alstop &gt;= intr.an*12+intr.luna
    LEFT  JOIN ncont nc           ON nc.codcont      = io1.cont
    LEFT  JOIN ioart ioi          ON ioi.codioart    = 0
    LEFT  JOIN npart np           ON np.codpart      = intr.partener
    LEFT  JOIN ngest gd           ON gd.codgest      = intr.codgestprod
    LEFT  JOIN nsubunit sd        ON sd.codsubunit   = intr.codsubunit&apos;||
    gSuplJoins||&apos;
  WHERE (l.codintr IS NOT NULL) AND (l.operat = 1) AND (l.anulat = 0)
    AND l.tiplivr   IN (&apos;||sTipIntr||&apos;)
    AND intr.tipdoc IN (&apos;||sTipIntr||&apos;) &apos;||
    vFiltru||
    vFiltruIntr||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;INTR&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;INTR&apos;);

  sSelectT := &apos;
  SELECT
    t.codtransf NAV_CodDoc, t.tipdoc NAV_TipDoc,
    nao.denumire DenArt, u1.den_um1 DenUM, g.den_gest DenGest, nl.denumire DenLGest, nc.simbol SimbolCont,
    t.prefixdoc||&apos;&apos;.&apos;&apos;||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc Document, t.PrefixDoc, t.NrDoc, t.DataDoc, PKG_LIST_BASE_UTILS.decode_tipdoc(t.tipdoc) NumeDoc,
    &apos;&apos;LIVR &apos;&apos;||l.nrlivr||&apos;&apos; / &apos;&apos;||l.datalivr DocLivr, l.NrLivr, l.DataLivr, dc.denumire DenCarnetLivr, dc.simbol SimbCarnetLivr, dc.serie SerCarnetLivr,
    l1.cant / u1.paritate, Coalesce(lv.pretinreg,ns.pret) * u1.paritate * CASE WHEN t.tipdoc = 15 THEN -1 ELSE 1 END PInreg, Coalesce(lv.pretachiz,ns.pret - ns.adaos) * u1.paritate * CASE WHEN t.tipdoc = 15 THEN -1 ELSE 1 END PretAch,
    gd.den_gest||CASE WHEN Coalesce(nld.codlocatie,0) &lt;&gt; 0 THEN &apos;&apos; (&apos;&apos;||nld.denumire||&apos;&apos;)&apos;&apos; END Destinatie,
    io.den_ioart DenIOART, um1.den_um UM1, um2.den_um UM2, l1.CantUM1, l1.CantUM2, nao.masa, nao.volum,
    ns.DataAchiz, pkg_list_base_utils.decode_tipdoc_scurt(t.tipdoc) STipDoc, t.an AnDoc, t.luna LunaDoc, to_char(t.an,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(t.luna,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(t.Luna) Luna,
    ioi.den_ioart IOARTInterm&apos;||gUserAlias||&apos;
  FROM livr l
    INNER JOIN transf t           ON t.codtransf     = l.codtransf AND l.tiplivr = t.tipdoc
    LEFT  JOIN iesiri ies         ON ies.codies      = 0
    LEFT  JOIN intrari intr       ON intr.codintr    = 0
    INNER JOIN livr1 l1           ON l1.codlivr      = l.codlivr
    LEFT  JOIN livrval lv         ON lv.codlivr1     = l1.codlivr1
    LEFT  JOIN nirstoc ns         ON ns.codnirstoc   = l1.codnirstoc
    LEFT  JOIN nir n              ON n.codnir        = ns.codnir
    LEFT  JOIN nirstoc nsd        ON nsd.codlivr1    = l1.codlivr1
    LEFT  JOIN nir nd             ON nd.codnir       = nsd.codnir
    LEFT  JOIN nartobj nao        ON nao.codobiect   = Coalesce(lv.codobiect, ns.codobiect)
    LEFT  JOIN nart na            ON na.codarticol   = nao.codarticol&apos;||
    sJoinUM||&apos;
    LEFT  JOIN NUM UM1            ON um1.codum       = na.um1
    LEFT  JOIN NUM UM2            ON um2.codum       = na.um2
    LEFT  JOIN ngest g            ON g.codgest       = Coalesce(lv.gest, n.gest, 0)
    LEFT  JOIN nlocatii nl        ON nl.codlocatie   = ns.codlocatie
    LEFT  JOIN nsubunit ss        ON ss.codsubunit   = t.subunitatea
    LEFT  JOIN doccarnete dc      ON dc.codcarnet    = l.carnetlivr
    LEFT  JOIN ioart io           ON io.codioart     = Coalesce(lv.codioart,ns.codioart)
    LEFT  JOIN ioart1         io1 ON io1.codioart    = io.codioart AND io1.alstart &lt;= t.an*12+t.luna AND io1.alstop &gt;= t.an*12+t.luna
    LEFT  JOIN ncont nc           ON nc.codcont      = io1.cont
    LEFT  JOIN ioart ioi          ON ioi.codioart    = 0
    LEFT  JOIN npart np           ON np.codpart      = 0
    LEFT  JOIN ngest gd           ON gd.codgest      = nd.gest
    LEFT  JOIN nlocatii nld       ON nld.codlocatie  = nsd.codlocatie
    LEFT  JOIN nsubunit sd        ON sd.codsubunit   = 0&apos;||
    gSuplJoins||&apos;
  WHERE (l.codtransf IS NOT NULL) AND (l.operat = 1) AND (l.anulat = 0)
    AND l.tiplivr IN (&apos;||sTipT||&apos;)
    AND t.tipdoc  IN (&apos;||sTipT||&apos;) &apos;||
    vFiltru||
    vFiltruT||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;T&apos;);

  pkg_globals.SetDebugMode(TRUE);

  IF sTipIes  IS NOT NULL THEN LIST_EXECUTE_IMMEDIATE(sInsert||sselecties, aListID, aListVer); END IF;
  IF sTipIntr IS NOT NULL THEN LIST_EXECUTE_IMMEDIATE(sInsert||sselectint, aListID, aListVer); END IF;
  IF sTipT    IS NOT NULL THEN LIST_EXECUTE_IMMEDIATE(sInsert||sselectt,   aListID, aListVer); END IF;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_LIVRSIMPL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LIVRTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31021F2359BAA83B1CD69EBD5195754EFDAEF2C1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LIVRTRANSF IS
  vCodTransf TRANSF.CODTRANSF%TYPE;
  vCodGest   NGEST.CODGEST%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataS       DATE;
  vDataF       DATE;

PROCEDURE SETPARAMS( pCodTransf IN NUMBER DEFAULT NULL,
                     pCodGest   IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodTransf  := pCodTransf;
  IF nvl(pCodGest,-1) &gt;= 0
  THEN vCodGest := pCodGest;
  ELSE vCodGest := -1;
  END IF;
END;

PROCEDURE PROCESSPARAMS IS
  vDGest  VARCHAR2(500);
  vGGest  VARCHAR2(500);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  IF vCodGest &gt; 0 THEN
    SELECT G.Den_Gest, NP.Nume||&apos; &apos;||NP.Prenume
    INTO vDGest, vGGest
    FROM NGEST G LEFT JOIN NPERS NP ON G.CODGESTIONAR = NP.CODPERS
    WHERE G.CODGEST = vCodGest;
  ELSE
    vDGest := &apos;&apos;;
    vGGest := &apos;&apos;;
  END IF;
  pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE&apos;,               vDGest);
  pkg_list_Struct.ADAUGA_PARAM(&apos;GESTIUNE GESTIONAR&apos;,     vGGest);

  IF vCodTransf &gt; 0 THEN
    DELETE tmp_manevra_liste WHERE filtru = &apos;CODTRANSF&apos;;
    INSERT INTO tmp_manevra_liste (FILTRU, VALOARE) VALUES (&apos;CODTRANSF&apos;, vCodTransf);
  END IF;

  FOR v_rec IN (
    SELECT
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (T.PREFIXDOC                     ORDER BY T.PREFIXDOC, T.NRDOC, T.DATADOC) AS vc2_nt)) PREFIXDOC,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (to_char(T.NRDOC)                ORDER BY T.PREFIXDOC, T.NRDOC, T.DATADOC) AS vc2_nt)) NRDOC,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (To_Char(T.DATADOC,&apos;dd.mm.yyyy&apos;) ORDER BY T.PREFIXDOC, T.NRDOC, T.DATADOC) AS vc2_nt)) DATADOC,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (T.OBS                           ORDER BY T.PREFIXDOC, T.NRDOC, T.DATADOC) AS vc2_nt)) OBS
    FROM tmp_manevra_liste tmp
      LEFT JOIN TRANSF T ON T.CODTRANSF = tmp.valoare
    WHERE tmp.filtru = &apos;CODTRANSF&apos;
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT&apos;,       v_rec.PREFIXDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;, v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,  v_rec.DataDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT OBS&apos;,   v_rec.OBS);
    EXIT;
  END LOOP;

  FOR v_rec IN (SELECT
                  VC2_NT_TO_VC3200_DIST(CAST(COLLECT (L.NRLIVR||&apos;/&apos;||TO_CHAR(L.DATALIVR,&apos;DD.MM.YYYY&apos;) ORDER BY L.NRLIVR) AS vc2_nt)) DOCLIVR
                FROM tmp_manevra_liste tmp
                     LEFT JOIN TRANSF T ON  T.CODTRANSF = tmp.valoare
                     left join LIVR L on L.CODTRANSF = T.CODTRANSF
                WHERE tmp.filtru = &apos;CODTRANSF&apos;
               )
  LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARE DOCUMENT&apos;, v_rec.DOCLIVR);
    EXIT ;
  END LOOP; 

  pkg_list_Struct.ADAUGA_PARAM(&apos;MASA FACTURATA&apos;, &apos;0.00&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM FACTURAT&apos;, &apos;0.00&apos;);
  pkg_list_Struct.ADAUGA_PARAM(&apos;FILTRU&apos;,         &apos;&apos;);

  FOR v_rec IN (
    SELECT
      T.TIPDOC, T.SERIADOC, T.NRDOC, T.DATADOC, T.VALDOC, T.NRAE, T.OBS,
      CG.Den_Gest CMDGest, CS.TELEFON CMDTelefon, CL.DEN_LOCALIT CMDLocalit, CJ.Den_Judet CMDJudet,
      GetAdresa(CS.sector, CS.strada, CS.nr1, CS.nr2, CS.bloc, CS.scara, CS.etaj, CS.apart, CS.codpostal) CMDAdresa,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      D.Delegat DEL, D.DOC DELDOC, D.NRDOC DELNRDOC, D.SERIEDOC DELSERIEDOC, D.ELIBERAT DELELIBERAT, D.CNP DELCNP, D.DATADOC DELDATADOC, T.MIJLTRANSP DELMIJLTRANSP, T.NRTRANSP DELNRTRANSP
    FROM tmp_manevra_liste tmp
      LEFT JOIN TRANSF T ON T.CODTRANSF = tmp.valoare
      LEFT JOIN NPARTTR D ON T.DELEGAT = D.CODPARTTR
      LEFT JOIN NGEST CG ON CG.CODGEST = T.CODGESTCMD
      LEFT JOIN NAGENDA CS ON CS.CODGEST = CG.CODGEST
      LEFT JOIN NLOCALIT CL ON CL.CODLOCALIT = NVL(CS.CODLOCALIT, 0)
      LEFT JOIN NJUDET CJ ON CJ.CODJUDET = NVL(CL.CODJUDET, 0)
      LEFT JOIN NPERS U ON U.LOGONNAME = T.USERID
    WHERE tmp.filtru = &apos;CODTRANSF&apos;
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE&apos;,             v_rec.CMDGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE JUDET&apos;,       v_rec.CMDJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE LOCALITATE&apos;,  v_rec.CMDLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE ADRESA&apos;,      v_rec.CMDAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE TELEFON&apos;,     v_rec.CMDTelefon);

    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,            v_rec.DEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,        v_rec.DELCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,           v_rec.DELDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,       v_rec.DELNRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,     v_rec.DELSERIEDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,       v_rec.DELELIBERAT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,     v_rec.DELDATADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                v_rec.DELMIJLTRANSP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,          v_rec.DELNRTRANSP);

    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,               v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,             v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                 v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                  v_rec.UBI);
    EXIT;
  END LOOP;
  
    FOR v_rec IN (
    SELECT stragg3200(NrLivr) NrLivr, stragg3200(DataLivr) DataLivr, stragg3200(ObsLivr) ObsLivr, stragg3200(ZiLivr) ZiLivr
    FROM (
      SELECT
        DISTINCT L.NRLIVR, To_Char(L.DATALIVR,&apos;dd.mm.yyyy&apos;) DataLivr, L.OBS ObsLivr, EXTRACT(DAY FROM L.DATALIVR) ZiLivr
      FROM LIVR1_MAN tmp
        INNER JOIN livr l ON l.CODLIVR = tmp.CODLIVR
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.NUMAR&apos;, v_rec.NrLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.DATA&apos;,  v_rec.DataLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.OBS&apos;,   v_rec.ObsLivr);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOC.LIVR.ZI&apos;,    v_rec.ZiLivr);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      PK.NRDOC, DC.SERIE, PK.NRPACHETE, PK.IDENTIFICATORP, PK.DATAP, PC.NUME||&apos; &apos;||PC.PRENUME PCC,
      PV.NUME||&apos; &apos;||PV.PRENUME PVV, PT.NUME||&apos; &apos;||PT.PRENUME PTT, PK.DATACOLECTARE, PK.DATAVERIFICARE, PK.DATATRANSPORT
    FROM tmp_manevra_liste tmp
      LEFT JOIN TRANSF T ON T.CODTRANSF = tmp.valoare
      LEFT JOIN PACHETE1 PK1 ON T.CODTRANSF = PK1.CODDOC
      LEFT JOIN PACHETE  PK ON PK1.CODPACHETE = PK.CODPACHETE
      LEFT JOIN DOCCARNETE DC ON PK.CARNETDOC = DC.CODCARNET
      LEFT JOIN NPERS PC ON PK.COLECTOR = PC.CODPERS
      LEFT JOIN NPERS PV ON PK.VERIFICATOR = PV.CODPERS
      LEFT JOIN NPERS PT ON PK.TRANSPORTATOR = PT.CODPERS
    WHERE tmp.filtru = &apos;CODTRANSF&apos;
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET SERIE&apos;,                  v_rec.SERIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR&apos;,                  v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET NUMAR PACHETE&apos;,          v_rec.NRPACHETE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA&apos;,                   v_rec.DATACOLECTARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET Identificator&apos;,          v_rec.IDENTIFICATORP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA COLECTARE&apos;,     v_rec.DATACOLECTARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA COLECTARE&apos;,         v_rec.PCC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET PERSOANA VERIFICATOARE&apos;, v_rec.PVV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET DATA VERIFICARE&apos;,        v_rec.DATAVERIFICARE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT PERSOANA&apos;,     v_rec.PTT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COLET TRANSPORT DATA&apos;,         v_rec.DATATRANSPORT);
    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(20000);
  sSelect    VARCHAR2(20000);
  sInsMAN    VARCHAR2(10000);
  sInsertUMA VARCHAR2( 1000);
  sSelectUMA VARCHAR2( 5000);
  sJoinUMA   VARCHAR2( 1000);
BEGIN
  gSuplCols :=
    &apos;transf t, nartobj nao, nart na, num1 um, ngest ng, nlocatii nl, doccarnete dc, num1 um1, num1 um2, npart prod, npart furn, nclasea ca, &apos;||
    &apos;ioart io, ioart1 io1, ncont nc, nartobj1 nao1, nirstoc ns, comanda1 c1, comanda c&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  DELETE LIVR1_MAN;

  sInsMAN :=
  &apos;INSERT INTO LIVR1_MAN(
    CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODDVI1, CODNIRSTOC, CANT, CODNIRSER, PMP, UMSEC,
    CANTUM1, CANTUM2, RESTIESVAL, CANTREZERVAT, CODCERTIF, CODPRODCOMP,
    PMPVALUTA, PMPDOC, PMPVALUTADOC, CONTINTERMED, CODPROIECT)
  SELECT
    L1.CODLIVR1, L1.CODLIVR, L1.CODIES1, L1.CODINTR1, L1.CODDVI1, L1.CODNIRSTOC, L1.CANT, L1.CODNIRSER, L1.PMP, L1.UMSEC,
    L1.CANTUM1, L1.CANTUM2, L1.RESTIESVAL, L1.CANTREZERVAT, L1.CODCERTIF, L1.CODPRODCOMP,
    L1.PMPVALUTA, L1.PMPDOC, L1.PMPVALUTADOC, L1.CONTINTERMED, L1.CODPROIECT
  FROM TRANSF1 t1
    INNER JOIN livr  l  ON l.codtransf = t1.codtransf
    INNER JOIN livr1 l1 ON l1.codies1  = t1.codtransf1 AND l1.codlivr = l.codlivr&apos;;
  IF vCodGest &gt; 0 THEN
    sInsMAN := sInsMAN ||&apos;
    LEFT JOIN livrval lv ON lv.codlivr1   = l1.codlivr1
    LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
    LEFT JOIN nir     n  ON n.codnir      = ns.codnir&apos;;
  END IF;
  sInsMAN := sInsMAN ||&apos;
  WHERE T1.CodTransf&apos;;
  IF vCodTransf &gt; 0
  THEN sInsMAN := sInsMAN ||&apos; = &apos;||vCodTransf;
  ELSE sInsMAN := sInsMAN ||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE UPPER(FILTRU) = &apos;&apos;CODTRANSF&apos;&apos;)&apos;;
  END IF;
  IF vCodGest &gt; 0 THEN
    sInsMAN := sInsMAN ||&apos;
    AND NVL(lv.gest,n.gest) = &apos;||vCodGest;
  END IF;

  EXECUTE IMMEDIATE sInsMAN;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;lg.cant&apos;,&apos;t1.codobiect&apos;,sInsertUMA,sSelectUMA,sJoinUMA);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    ART, UM, CANTDOC, CANTLIVR,
    PACH, PINREG, PVANZ,
    VALACH, VALINREG, VALVANZ,
    GESTIUNE, LOCATIE, NRLIVR, DATALIVR, DENCARNET, SIMBCARNET, SERCARNET, OBSLIVR, GAR, DATAEXP, DATAPROD, CODINTERN, CODEXTERN,
    DENCLASAA, SIMBCLASAA, MASA, VOLUM, PRODUCATOR, FURNIZOR, ARTFURN, UM1, UM2, CANT1, CANT2,
    TIPSERIE, SERII, SER, CERTIFSER, DENIOART, SIMBCONT,
    PREFIXDOC, NRDOC, DATADOC, NRCERTIF, PUMAXIMAL,D1,D2,D3,DENCLASEAS,NRCOM,DATACOM,OBSDOC,CUSTODIE&apos;||sInsertUMA||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    NSIN AS (
      SELECT connect_by_root ns.codnirstoc codnirstoc, ns.codintr1, ns.coddvi1
      FROM nirstoc ns
      WHERE Nvl(NS.CODNIRSTOCPARINTE,0) = 0
      START WITH NS.CODNIRSTOC IN (SELECT DISTINCT CODNIRSTOC FROM LIVR1_MAN)
      CONNECT BY NS.CODNIRSTOC = PRIOR NS.CODNIRSTOCPARINTE),
    LG AS (
      SELECT
        ns.codnirstoc, l1.codies1 codtransf1, NVL(lv.gest, n.gest) gest, ns.codlocatie, l1.umsec, l1.codlivr,
        NVL(lv.codioart,ns.codioart) codioart, ns.furn, ns.codgestprod gestfurn,
        SUM(NVL(lv.pretinreg,ns.pret)*l1.cant) valinreg,
        SUM(NVL(lv.pretachiz,ns.pret - ns.adaos)*l1.cant) valachiz,
        sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2, ns.d1, ns.d2, ns.d3,
        CASE nvl(ns.tipserie,0)
          WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_vc3200(CAST(collect(s.serie||&apos;&apos;(&apos;&apos;||l1.cant||&apos;&apos;)&apos;&apos;) AS vc2_nt))
          ELSE NULL
        END SERII,
        vc2_nt_to_vc3200(CAST(COLLECT(s.serie) AS vc2_nt)) ser,
        max(ns.pumaximal) pumaximal,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg, ns.tg))) AS vc2_nt)) tg,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dp,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(int1.nrcertif)) AS vc2_nt)) nrcertif,
        vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.nrcertif)) AS vc2_nt)) certifser,
        ns.tipserie
      FROM livr1_man l1
        LEFT JOIN livrval  lv   ON lv.codlivr1     = l1.codlivr1
        LEFT JOIN nirstoc  ns   ON ns.codnirstoc   = l1.codnirstoc
        LEFT JOIN nir      n    ON n.codnir        = ns.codnir
        LEFT JOIN NSIN          ON nsin.codnirstoc = ns.codnirstoc
        LEFT JOIN dvi1          ON dvi1.coddvi1    = nsin.coddvi1
        LEFT JOIN intrari1 int1 ON int1.codintr1   = NVL(dvi1.codintr1, nsin.codintr1)
        LEFT JOIN nirser   nser ON nser.codnirser  = l1.codnirser
        LEFT JOIN nserii   s    on s.codserie      = nser.codserie
        LEFT JOIN certif   c    ON c.codcertif     = nser.codcertif
      GROUP BY
        l1.codies1, l1.codlivr, l1.umsec, lv.codioart, lv.gest, ns.codnirstoc, ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod,
        ns.tipserie, ns.d1, ns.d2, ns.d3, n.gest)
  SELECT
    nao.denumire, um.den_um1, t1.cant / um.paritate, lg.cant/um.paritate,
    lg.valachiz*um.paritate/lg.cant, lg.valinreg*um.paritate/lg.cant, t1.pu*um.paritate, lg.valachiz, lg.valinreg, t1.pu * lg.cant,
    ng.den_gest, nl.denumire, l.nrlivr, l.datalivr, dc.denumire, dc.simbol, dc.serie,
    l.obs, nao.lunigarantie, lg.tg, lg.dp, nao.codintern, nao.codextern,
    ca.den_clasea, ca.simbol, nao.masa, nao.volum, prod.den_part,
    case when nvl(gfurn.codgest, 0) = 0 then furn.den_part else gfurn.den_gest end, fobj.denumire,
    um1.den_um, um2.den_um, lg.cantum1, lg.cantum2,
    decode(lg.tipserie,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;), lg.serii, lg.ser, lg.certifser, io.den_ioart, nc.simbol,
    t.prefixdoc, t.nrdoc, t.datadoc, lg.nrcertif,
    CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) THEN NVL(t1.pumaximal,lg.pumaximal) WHEN NVL(nao1.tippretmax,0) IN (4,5,6) THEN nao1.pretmaximal ELSE NULL END,
    lg.d1,lg.d2,lg.d3,cs.den_claseas,c.nrdoc,c.datadoc,dbms_lob.substr(t1.obs,200,1), &apos;&apos;Nu&apos;&apos; custodie&apos;||sSelectUMA||gUserAlias||&apos;
  FROM LG
    LEFT JOIN transf1    t1    ON t1.codtransf1  = lg.codtransf1
    LEFT JOIN transf     t     ON t.codtransf    = t1.codtransf
    LEFT JOIN livr       l     ON l.codlivr      = lg.codlivr
    LEFT JOIN nartobj    nao   ON nao.codobiect  = t1.codobiect
    LEFT JOIN nart       na    ON na.codarticol  = nao.codarticol
    LEFT JOIN num1       um    ON um.codum1      = lg.umsec
    LEFT JOIN ngest      ng    ON ng.codgest     = lg.gest
    LEFT JOIN nirstoc    ns    ON ns.codnirstoc  = lg.codnirstoc
    LEFT JOIN nlocatii   nl    ON nl.codlocatie  = lg.codlocatie
    LEFT JOIN doccarnete dc    ON dc.codcarnet   = l.carnetlivr
    LEFT JOIN num        um1   ON um1.codum      = na.um1
    LEFT JOIN num        um2   ON um2.codum      = na.um2
    LEFT JOIN npart      prod  ON prod.codpart   = nao.codproducator
    LEFT JOIN npart      furn  ON furn.codpart   = lg.furn
    LEFT JOIN ngest      gfurn ON gfurn.codgest  = lg.gestfurn
    LEFT JOIN nclasea    ca    ON ca.codclasea   = na.clasa
    LEFT JOIN nclaseas   cs    ON cs.codclaseas  = na.clasastatist
    LEFT JOIN ioart      io    ON io.codioart    = lg.codioart
    LEFT JOIN ioart1     io1   ON io1.codioart   = lg.codioart  AND (t.an*12+t.luna) BETWEEN  io1.ALStart and  io1.ALStop
    LEFT JOIN ncont      nc    ON nc.codcont     = io1.cont
    LEFT JOIN nartobj1   nao1  ON nao1.codobiect = t1.codobiect AND (t.an*12+t.luna) BETWEEN nao1.ALStart and nao1.ALStop
    LEFT JOIN transflink tl    ON tl.codtransf1  = lg.codtransf1
    LEFT JOIN comanda1   c1    ON c1.codcomanda1 = tl.codliniecomanda
    LEFT JOIN comanda    c     ON c.codcomanda   = c1.codcomanda
    LEFT JOIN nartcli    fobj  ON fobj.codobiect = t1.codobiect AND fobj.codpart = lg.furn&apos;||
    sJoinUMA||
    gSuplJoins||&apos;
  &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  ProcessParams;
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_LIVRTRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LOGIMPORTCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D453D2A05AC1DD37646F9B04DF8DCF67EA31D6DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LOGIMPORTCOM IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(1000);
  sSelect   VARCHAR2(9000);
BEGIN
  gSuplCols := &apos;LOGIMPORTDOC L, NPART P, NARTOBJ O, COMANDA C&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos; (NRDOC, DATADOC, DATAIMP, PART, ART, OPER, CANTO, CANTN&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    L.NRDOC, L.DATADOC, L.DATAIMPORT, P.DEN_PART, O.DENUMIRE,
    DECODE(L.TIPOPERATIE,&apos;&apos;A&apos;&apos;,&apos;&apos;Adaugare&apos;&apos;,&apos;&apos;M&apos;&apos;,&apos;&apos;Modificare&apos;&apos;),
    L.CANTVECHI, L.CANTNOU &apos;||gUserAlias||&apos;
  FROM LOGIMPORTDOC L
    LEFT JOIN NPART P ON P.CODPART = L.CODPART
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = L.CODOBIECT
    LEFT JOIN COMANDA C ON C.TIPDOC = L.TIPDOC AND C.NRDOC = L.NRDOC AND C.DATADOC = L.DATADOC AND C.PARTENER = L.CODPART&apos;||
    gSuplJoins||&apos;
  WHERE L.TIPDOC = 18  &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

END PKG_LIST_BASE_LOGIMPORTCOM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_LOGUSERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18882AA67FB77C15AE1683598501EACE9A9A776B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_LOGUSERI IS

  G_DATAS varchar2(50);
  G_DATAF varchar2(50);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(ADATAS IN varchar2 ,ADATAF IN varchar2, v_codjob1 in number) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  G_DATAS := ADATAS;
  G_DATAF := ADATAF;
  /* Datfaf este plus 1 pentru ca in log inregistrarile sunt sun cu tot cu ora si
    pentru DATAF = 01.01.2010 =&gt; format timestamp 01.01.2010 00:00:00 deci nu mai prinde si
    logurile de pe 01.01.2010
  */
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,G_DATAS,G_DATAF,xLunaAnIni,xLunaAnFin);
  END IF;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(G_DATAS,G_DATAF);
END;

PROCEDURE processList(tmpname in varchar2, listid in number default 0, listver in number default 0) IS
  sInsert varchar2(2000);
BEGIN
  gSuplCols := &apos;WINMADMIN.LOG LG, NSUBUNIT S&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(LISTID,listver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos; (
    UTILIZATOR,FIRMA,SUBUNITATE,
    TIPOPER,
    DATA_ORA,DATADOC,DOCUMENT,TABELA,CODDOC,OBS&apos;||gUserFields||&apos;)
  SELECT
    LG.UTILIZATOR,LG.FIRMA,S.DEN_SUBUNIT,
    CASE LG.OPERATIE
      WHEN &apos;&apos;A&apos;&apos;     THEN &apos;&apos;Adaugare&apos;&apos;
      WHEN &apos;&apos;M&apos;&apos;     THEN &apos;&apos;Modificare&apos;&apos;
      WHEN &apos;&apos;S&apos;&apos;     THEN &apos;&apos;Stergere&apos;&apos;
      WHEN &apos;&apos;R&apos;&apos;     THEN &apos;&apos;Refacere&apos;&apos;
      WHEN &apos;&apos;F&apos;&apos;     THEN &apos;&apos;Fixare&apos;&apos;
      WHEN &apos;&apos;C&apos;&apos;     THEN &apos;&apos;Actualizare&apos;&apos;
      WHEN &apos;&apos;V&apos;&apos;     THEN &apos;&apos;Verificare&apos;&apos;
      WHEN &apos;&apos;I&apos;&apos;     THEN &apos;&apos;Inchidere luna&apos;&apos;
      WHEN &apos;&apos;D&apos;&apos;     THEN &apos;&apos;Deschidere luna&apos;&apos;
      WHEN &apos;&apos;REGB&apos;&apos;  THEN &apos;&apos;Regularizare casa/banca&apos;&apos;
      WHEN &apos;&apos;REGPA&apos;&apos; THEN &apos;&apos;Regularizare parteneri&apos;&apos;
      WHEN &apos;&apos;REGPE&apos;&apos; THEN &apos;&apos;Regularizare personal&apos;&apos;
      WHEN &apos;&apos;LST&apos;&apos;   THEN &apos;&apos;Vizualizare lista&apos;&apos;
      ELSE &apos;&apos;Operatie neidentificata&apos;&apos;
    END TIPOPER,
    To_Char(LG.DATA,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) DATA_ORA, LG.DATADOC, LG.DOCUMENT, LG.TABELA, LG.CODDOC, LG.OBS &apos;||gUserAlias||&apos;
  FROM WINMADMIN.LOG LG
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = LG.SUBUNITATEA &apos;||
    gSuplJoins||&apos;
  WHERE UPPER(LG.FIRMA) = &apos;&apos;&apos;||Upper(pkg_globals.FIRMANAME)||&apos;&apos;&apos;
    AND LG.DATA BETWEEN to_date(&apos;&apos;&apos;||G_DATAS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||G_DATAF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)+1&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, ListID, ListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_loguseri;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FDF398F060684022B99AE677339E09EC3148D5D2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_MAIL IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

sZi1 VARCHAR2(50);
sZi2 VARCHAR2(50);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE)
IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sZIstart VARCHAR2(100):=  PKG_LIST_ALEGPERIOADA.getDataS;
  sZIstop  VARCHAR2(100):=  PKG_LIST_ALEGPERIOADA.getDataF;
BEGIN
  gSuplCols := &apos;mailuri m&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
          NAV_CodDoc,
          NAV_TipDoc,
		      CODMAIL,       
          SENDER,           
          RECIPIENTS,       
          SUBJECT,          
          MESSAGE,          
          DATA,             
          STATUS,           
          EROARE,           
          HOST,             
          DOMAIN&apos;||gUserFields||&apos; )&apos;;

  sSelect := 
  &apos;
  SELECT
        M.CodDoc,
        M.TipDoc,
        M.CODMAIL,    
        M.SENDER,     
        M.RECIPIENTS, 
        M.SUBJECT,    
        M.MESSAGE,    
        M.DATA,       
        M.STATUS,     
        M.EROARE,     
        M.HOST,       
        M.DOMAIN&apos;||gUserAlias||&apos; 
  FROM mailuri M&apos;||
    gSuplJoins||&apos;
    WHERE M.Data between TO_DATE(&apos;&apos;&apos;||sZIstart||&apos;&apos;&apos;, &apos;&apos;dd/mm/yyyy&apos;&apos;) and TO_DATE(&apos;&apos;&apos;||sZIstop||&apos;&apos;&apos;, &apos;&apos;dd/mm/yyyy&apos;&apos;)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_MAIL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MANCONFORMNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B8091FD610975B92F59D294D27824A477DEC389</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_manconformnp IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;intrari i, intrari1 i1, comanda1 c1, cmdprodman man, prodcomp pc, nartobj prod, nart artp, prodgest pg, ngest g, noper op, locmunca lm&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
     NAV_CodDoc, NAV_TipDoc, Doc,
     Reteta, Produs, CantPredata, SectieExec, Ordine, NrOp, Operatie, LocMunca, DenTarif,
     tarif, tu, valoare,
     dsv, bps, tpi, obs, detalii &apos;||gUserFields||&apos;)
  SELECT
    i.codintr, i.tipdoc, i.prefixdoc||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc,
    pc.obs Reteta, prod.denumire Produs, i1.cant, G.Den_Gest SectieExec, man.IndexLocal Ordine, man.NrOp, op.denumire Operatie, lm.denumire LocMunca, t.denumire DenTarif,
    t.tarif, i1.cant/man.bps * man.tu, round(i1.cant/man.bps * (man.tu * t.tarif)/60,5) valoare,
    man.dsv, man.bps, man.tpi, man.obs, man.detalii &apos;||gUserAlias||&apos;
  FROM intrari i
    INNER JOIN intrari1   i1   on i1.codintr      = i.codintr
    INNER JOIN comanda1   c1   on c1.codcomanda1  = i1.codcmdint1
    INNER JOIN cmdprodman man  on i1.codcmdint1   = man.codcomanda1
    INNER JOIN prodcomp   pc   on c1.codreteta    = pc.codprodcomp
    INNER JOIN nartobj    prod on prod.codobiect  = pc.codobiect
    INNER JOIN nart       artp on prod.codarticol = artp.codarticol
    LEFT  JOIN prodgest   pg   on pc.codprodcomp  = pg.codprodcomp and man.codprodgest = pg.codprodgest
    LEFT  JOIN ngest      g    on i.codgestprod   = g.codgest
    LEFT  JOIN noper      op   on man.codop       = op.codop
    LEFT  JOIN locmunca   lm   on lm.codloc       = man.codloc
    LEFT  JOIN ( 
      SELECT T1.codtarif, T1.Tarif, t.denumire
      from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND (pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU) BETWEEN T1.ALSTART and T1.ALSTOP
    ) T                        ON MAN.CODTARIF      = T.CODTARIF
    LEFT  JOIN NCLASEA    CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA&apos;||
    gSuplJoins||&apos;
  WHERE nvl(pc.anulat, 0) = 0 and i.an*12+i.luna = pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU
    and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 and i.tipdoc = 7
    and ((pkg_globals.getsubunitate = 1) or (pkg_globals.getsubunitate = i.subunitatea))&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_manconformnp;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MANPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11E2A79F2F2C5BB8B54BA6EDF379E5AB76CC6CCC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_manprod IS

p_flgAllArt NUMBER(1);
p_Tip NUMBER(1);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Tip IN NUMBER) IS
BEGIN
  p_flgAllArt := v_flgAllArt;
  p_Tip := v_Tip;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  vUserID number(20);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  vUserID := pkg_globals.GETUSERID; 
  gSuplCols := &apos;NARTOBJ PROD, PRODCOMP PC, NCLASEA CLSP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = PROD.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = PROD.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if p_flgAllArt = 1 then
    delete tmp_prodcomp_man where userid = vuserid;
    delete tmp_proiectnod_man where userid = vUserID;
    if p_Tip = 0 then
      insert into tmp_prodcomp_man (codprodcomp, cant, pret, userid)
      (select PC.codprodcomp, PC.cant, PC.Pret, vUserID
       from prodcomp PC where coalesce(pc.ascuns,0) = 0
      );
    else
      insert into tmp_proiectnod_man(codproiectnod,necesar,cant,codobiect,codproiect,userid)
      select pn.codproiectnod,pn.cant,pn.cant,pn.codobiect,pn.codproiect,vuserid
      from proiectnod pn
           inner join proiect p on p.codproiect = pn.codproiect
      where pn.nodoriginal = 0 and coalesce(p.ascuns,0) = 0;
    end if;
    COMMIT;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
    SYSCOD,
    NAV_CodDoc,
    NAV_TipDoc,
    Reteta,
    Produs,
    SectieExec,
    Ordine,
    NrOp,
    Operatie,
    LocMunca,
    DenTarif,
    tarif,
    tu,
    valoare,
    dsv,
    bps,
    tpi,
    obs,
    detalii,
    tip,
    nivel,
    Nod,
    Parinte,
    CantP &apos;||gUserFields||&apos;)&apos;;

   sSelect := &apos;
  select
    pc.codprodcomp,
    pc.codprodcomp,
    504,
    pc.obs Reteta,
    prod.denumire Produs,
    G.Den_Gest SectieExec,
    pm.Ordine,
    pm.NrOp,
    op.denumire Operatie,
    lm.denumire LocMunca,
    t.denumire DenTarif,
    t.tarif,
    tmp.cant/pm.bps * pm.tu,
    round(tmp.cant/pm.bps * (pm.tu * t.tarif)/60,5) valoare,
    pm.dsv,
    pm.bps,
    pm.tpi,
    pm.obs,
    pm.detalii,
    &apos;&apos;Reteta&apos;&apos;,
    1,
    LPAD(pm.ordine, 2, &apos;&apos;0&apos;&apos;),
    prod.denumire,
    tmp.cant/pc.cant &apos;||gUserAlias||&apos;
  from prodcomp pc
    INNER JOIN TMP_PRODCOMP_MAN TMP ON PC.CodProdComp   = TMP.CodProdComp
    inner join nartobj          prod on prod.codobiect  = pc.codobiect
    inner join nart             artp on prod.codarticol = artp.codarticol
    inner join prodgest         pg on pc.codprodcomp    = pg.codprodcomp
    inner join ngest            g on nvl(pg.codgest, 0) = g.codgest
    inner join (select m.*, Rownum Ordine from prodman m order by m.nrop, m.detalii) pm on pm.codprodcomp = pc.codprodcomp and pm.codprodgest = pg.codprodgest
    inner join noper            op on pm.codop  = op.codop
    inner join locmunca         lm on lm.codloc = pm.codloc
    inner JOIN (
      select T1.codtarif, T1.Tarif, t.denumire
      from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t .codtarif AND (pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU) BETWEEN T1.ALSTART and T1.ALSTOP
    ) T                     ON PM.CODTARIF       = T.CODTARIF
    LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA&apos;||
    gSuplJoins||&apos;
  where nvl(pc.anulat, 0) = 0
  and tmp.userid = &apos;||vuserid||&apos;
  union all
  select
    p.codproiect,
    p.codproiect,
    507,
    p.versiune Reteta,
    prod.denumire Produs,
    G.Den_Gest SectieExec,
    pm.Ordine,
    NVL(PN.ordine,0),
    op.denumire Operatie,
    lm.denumire LocMunca,
    t.denumire DenTarif,
    t.tarif,
    tmp.cant/PN0.cant*PN.cant/pm.bps * pm.tu,
    round(tmp.cant/PN0.cant*PN.cant/pm.bps * (pm.tu * t.tarif)/60,5) valoare,
    pm.dsv,
    pm.bps,
    pm.tpi,
    pm.obs,
    pm.detalii,
    &apos;&apos;Proiect&apos;&apos;,
    NVL(PN.nivel,0),
    X.IND,
    case when nvl(pnp.codproiectnod,0) = 0 then pp.denumire else objp.denumire end,
    case when nvl(pnp.codproiectnod,0) = 0 then tmp.cant else tmp.cant/PN0.cant*PNP.cant end &apos;||gUserAlias||&apos;
  from PROIECT P
    INNER JOIN TMP_PROIECTNOD_MAN TMP  ON P.CodProiect       = TMP.CodProiect
    INNER JOIN PROIECTNOD         PN   ON P.CODPROIECT       = PN.CODPROIECT
    INNER JOIN PROIECTNOD         PN0  ON P.CODPROIECT       = PN0.CODPROIECT AND NVL(PN0.nodoriginal,0) = 0
    inner join prodcomp           pc   on PN.codreteta       = pc.codprodcomp
    inner join nartobj            prod on prod.codobiect     = p.codobiectprod
    inner join nart               artp on prod.codarticol    = artp.codarticol
    inner join prodgest           pg   on pc.codprodcomp     = pg.codprodcomp
    inner join ngest              g    on nvl(pg.codgest, 0) = g.codgest
    inner join (select m.*, Rownum Ordine from prodman m order by m.nrop, m.detalii) pm on pm.codprodcomp = pc.codprodcomp and pm.codprodgest = pg.codprodgest
    inner join noper              op   on pm.codop  = op.codop
    inner join locmunca           lm   on lm.codloc = pm.codloc
    inner JOIN (
      select T1.codtarif, T1.Tarif, t.denumire
      from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t .codtarif AND (pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLunaLUCRU) BETWEEN T1.ALSTART and T1.ALSTOP 
    ) T                                ON PM.CODTARIF       = T.CODTARIF
    LEFT  JOIN PROIECTNOD         PNP  ON PN.NODORIGINAL    = PNP.CODPROIECTNOD
    left  join nartobj            pp   on pn0.codobiect     = pp.codobiect
    left  join nartobj            objp on pnp.codobiect     = objp.codobiect
    LEFT  JOIN NCLASEA            CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
    LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = PN.CodProiectNod&apos;||
    gSuplJoins||&apos;
  where nvl(pc.anulat, 0) = 0 and pn.codreteta &gt; 0
  and tmp.userid = &apos;||vuserid;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  DELETE TMP_PRODCOMP_MAN WHERE USERID = VUSERID;
  DELETE TMP_PROIECTNOD_MAN WHERE USERID = VUSERID;
  
  COMMIT;
END;

end pkg_list_base_manprod;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MARIRIDIMIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BD7F0DE88C20D9D82FB958C40B7849DA473C5A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_mariridimin IS

  vTipLista NUMBER(2);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setTipLista (p_tipLista IN NUMBER) IS
BEGIN
  /*Adica 14 sau 15 ...Diminuari respectiv mariri*/
  vTipLista := p_tipLista;
END;

PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(2000);
BEGIN
  gSuplCols := &apos;livr l, livr1 l1, nirstoc ns, nir nir, nartobj nobj, nart nart, num num, nclasea nca, ngest ng, ioart io, ioart1 io1, iesiri ies, ncont ncont, intrari1 intr1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_TipDoc,DOCUMENT,PREFIXDOC,NRDOC,DATADOC,DENUMIRE,CANT,DEN_UM,CLASA,GEST_SURSA,GEST_DEST,CONT_SURSA,CONT_DEST,
    pretinreg,pretachiz,OPERAT &apos;||gUserFields||&apos;)
  SELECT
    ies.codies NAV_CodDoc, ies.tipdoc NAV_TipDoc,
    CASE
      WHEN l.tiplivr = 14 THEN &apos;&apos;Dimin. &apos;&apos;||ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc
      WHEN l.tiplivr = 15 THEN &apos;&apos;Marire &apos;&apos;||ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc
      ELSE ies.prefixdoc||ies.nrdoc||&apos;&apos; / &apos;&apos;||ies.datadoc
    END document,
    ies.prefixdoc,ies.nrdoc,ies.datadoc, nobj.denumire,l1.cant,num.den_um,nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;),
    ng.den_gest AS gest_sursa,ng.den_gest AS gest_dest, ncont.simbol cont_sursa,ncont.simbol AS cont_dest,
    ns.pret pretinreg ,intr1.pu pretachiz ,decode(ies.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat &apos;||gUserAlias||&apos;
  FROM livr l
    LEFT JOIN livr1    l1    ON l.codlivr       = l1.codlivr
    LEFT JOIN nirstoc  ns    ON ns.codnirstoc   = l1.codnirstoc
    LEFT JOIN nir            ON nir.codnir      = ns.codnir
    LEFT JOIN nartobj  nobj  ON nobj.codobiect  = ns.codobiect
    LEFT JOIN nart           ON nart.codarticol = nobj.codarticol
    LEFT JOIN num            ON num.codum       = nart.um
    LEFT JOIN nclasea  nca   ON nca.codclasea   = nart.clasa
    LEFT JOIN ngest    ng    ON ng.codgest      = nir.gest
    LEFT JOIN ioart    io    ON ns.codioart     = io.codioart 
    LEFT JOIN ioart1   io1   ON io.codioart     = io1.codioart AND (ies.an * 12 +ies.luna) BETWEEN io1.ALStart and io1.ALStop
    LEFT JOIN iesiri   ies   ON ies.codies      = l.codies
    LEFT JOIN ncont          ON io1.cont        = ncont.codcont
    LEFT JOIN intrari1 intr1 ON intr1.codintr1  = ns.codintr1&apos;||
    gSuplJoins||
  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;subunitatea&apos;,&apos;
  WHERE&apos;)||&apos;
    AND l.tiplivr  = &apos;||vTipLista||&apos;
    AND TO_DATE(IES.DATADOC,&apos;&apos;DD/MM/YYYY&apos;&apos;) BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)
    AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;;

	IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
	  sInsert := sInsert || &apos;
    AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NOBJ.CODOBIECT ) &apos;;
	END IF;

	IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
	  sInsert := sInsert || &apos;
    AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NG.CODGEST) &apos;;
	END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_maririDimin;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MATRCV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F6A2C94947F697CC357BC7A14552E2FF34AA952</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_matrcv IS

  sCod711     VARCHAR2(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsTmp   VARCHAR2(30000);
  sInsert   VARCHAR2(30000);
  vCVenitN  NUMBER(20);
  vCNeterm  NUMBER(20);
  vCSemif   NUMBER(20);
  vCProdR   NUMBER(20);
  vCPartS   NUMBER(20);
BEGIN
  PRC_AL_CHECK(&apos;NGEST1&apos;);

  gSuplCols := &apos;ncont c, ngest g, centrecost cc, ncont c9&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vCVenitN := Nvl(pkg_categconst.GetValConstanta(&apos;CVenitNetermin&apos;  ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),-1);
  vCNeterm := Nvl(pkg_categconst.GetValConstanta(&apos;CNeterm&apos;         ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),-1);
  vCSemif  := Nvl(pkg_categconst.GetValConstanta(&apos;CSemifab&apos;        ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),-1);
  vCProdR  := Nvl(pkg_categconst.GetValConstanta(&apos;CProdRezid&apos;      ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),-1);
  vCPartS  := Nvl(pkg_categconst.GetValConstanta(&apos;CPartidaSimpla&apos;  ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),-1);
  IF vCVenitN &lt;= 0 THEN
    SELECT Nvl(Max(CODCONT),-1) INTO vCVenitN FROM NCONT WHERE SIMBOL = &apos;711&apos;;
  END IF;
  
-- Codificari Tip Linie
-- 100 -&gt; 01.Cheltuieli                             -&gt; Denumire Cont
-- 199 -&gt; 01.Cheltuieli                             -&gt; Total Cheltuieli
-- 200 -&gt; 02.Venituri                               -&gt; Denumire Cont
-- 299 -&gt; 02.Venituri                               -&gt; Total Venituri
-- 311 -&gt; 03.711-productie in curs si semifabricate -&gt; Productie neterminata_sfarsit perioada_Credit (+)           &lt;= CNeterm = CVenitNetermin
-- 312 -&gt; 03.711-productie in curs si semifabricate -&gt; Productie neterminata_consum productie_Debit (-)            &lt;= CVenitNetermin = CNeterm
-- 321 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Productie Cost standard_Credit (+)       &lt;= CSemifab = CVenitNetermin        (Note de predare)
-- 322 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Vanzari Cost standard_Debit (-)          &lt;= CVenitNetermin = CSemifab        (Avize, Facturi de iesire, Monetare)
-- 323 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Consum productie Cost standard_Debit (-) &lt;= CVenitNetermin = CSemifab        (Bonuri de consum)
-- 331 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Dif Inventar_Credit (+)                  &lt;= CSemifab = CVenitNetermin        (Diminuari sau Mariri de stoc)
-- 332 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Dif Inventar_Debit (-)                   &lt;= CVenitNetermin = CSemifab        (Diminuari sau Mariri de stoc)
-- 341 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Abateri semifinite_Credit (+)            &lt;= CSemifab = CVenitNetermin        (Modificari de pret)
-- 342 -&gt; 03.711-productie in curs si semifabricate -&gt; Produse semifinite_Abateri semifinite Debit (-)             &lt;= CVenitNetermin = CSemifab        (Modificari de pret)
-- 399 -&gt; 03.711-productie in curs si semifabricate -&gt; Total 711-productie in curs si semifabricate
-- 411 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite - Productie Cost standard_Credit (+)         &lt;= CProduseAnimale = CVenitNetermin (Note de predare)
-- 412 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite - Vanzari Cost standard_Debit (-)            &lt;= CVenitNetermin = CProduseAnimale (Avize, Facturi de iesire, Monetare)
-- 421 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite - Abateri_Credit (+)                         &lt;= CProduseAnimale = CVenitNetermin (Modificari de pret)
-- 422 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite - Abateri_Debit (-)                          &lt;= CVenitNetermin = CProduseAnimale (Modificari de pret)
-- 431 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite_Dif Inventar_Credit (+)                      &lt;= CProduseAnimale = CVenitNetermin (Diminuari sau Mariri de stoc)
-- 432 -&gt; 04.711-produse finite si reziduale        -&gt; Produse finite_Dif Inventar_Debit (-)                       &lt;= CVenitNetermin = CProduseAnimale (Diminuari sau Mariri de stoc)
-- 451 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale - Productie Cost standard_Credit (+)      &lt;= CProdRezid = CVenitNetermin      (Note de predare)
-- 452 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale - Vanzari Cost standard_Debit (-)         &lt;= CVenitNetermin = CProdRezid      (Avize, Facturi de iesire, Monetare)
-- 453 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale - Consum Cost standard_Debit (-)          &lt;= CVenitNetermin = CProdRezid      (Bonuri de consum)
-- 461 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale - Abateri_Credit (+)                      &lt;= CProdRezid = CVenitNetermin      (Modificari de pret)
-- 462 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale - Abateri_Debit (-)                       &lt;= CVenitNetermin = CProdRezid      (Modificari de pret)
-- 471 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale_Dif Inventar_Credit (+)                   &lt;= CProdRezid = CVenitNetermin      (Diminuari sau Mariri de stoc)
-- 472 -&gt; 04.711-produse finite si reziduale        -&gt; Produse reziduale_Dif Inventar_Debit (+)                    &lt;= CVenitNetermin = CProdRezid      (Diminuari sau Mariri de stoc)
-- 499 -&gt; 04.711-produse finite si reziduale        -&gt; Total 711- produse finite si reziduale
-- 599 -&gt; 05.Rezultat luna                          -&gt; Total rezultat luna                                         &lt;= -199+299+399+499
-- 699 -&gt; 06.Cost Preliminar                        -&gt; Cost productie preliminar                                   &lt;= 199-299-399
-- 710 -&gt; 07.Decontari interne                      -&gt; Distributii faza 1
-- 720 -&gt; 07.Decontari interne                      -&gt; Distributii faza 2
-- 730 -&gt; 07.Decontari interne                      -&gt; Distributii faza 3
-- 740 -&gt; 07.Decontari interne                      -&gt; Distributii faza 4
-- 750 -&gt; 07.Decontari interne                      -&gt; Post calcul
-- 799 -&gt; 07.Decontari interne                      -&gt; Total Decontari interne
-- 899 -&gt; 08.Cost final                             -&gt; Cost productie final                                        &lt;= 699+799


  sInsTMP:=
  &apos;INSERT INTO tmp_lst_matrcv(
   tiplinie, codcont, codgest, codcentru, codcont9,
   valaloc,
   valnealoc,
   vanzari,
   marfuri,
   alteactiv,
   elemfinanc,
   elemexcept,
   chimpprof,
   valtot,
   totaltip )
  WITH G1 AS (
    SELECT
      codgest,
      cheltuieli      codcont9_01,
      cheltuieliind   codcont9_02,
      cheltuieliind   codcont9_03,
      cheltuieliaux   codcont9_11,
      cheltuieliadmin codcont9_12,
      cheltuielidesf  codcont9_13
    FROM ngest1
    WHERE &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN ALSTART and ALSTOP
    ),
  J AS (
    SELECT
      CASE
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCNeterm||&apos; THEN 312
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCSemif ||&apos; AND j.tipdoc IN (16,19,20) THEN 322
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCSemif ||&apos; AND j.tipdoc IN (24)       THEN 323
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCSemif ||&apos; AND j.tipdoc IN (14,15)    THEN 332
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCSemif ||&apos; AND j.tipdoc IN (13)       THEN 342
        WHEN j.contd = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contc, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (16,19,20) THEN 412
        WHEN j.contd = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contc, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (13)       THEN 422
        WHEN j.contd = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contc, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (14,15)    THEN 432
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCProdR ||&apos; AND j.tipdoc IN (16,19,20) THEN 452
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCProdR ||&apos; AND j.tipdoc IN (24)       THEN 453
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCProdR ||&apos; AND j.tipdoc IN (13)       THEN 462
        WHEN j.contd = &apos;||vCVenitN||&apos; AND j.contc = &apos;||vCProdR ||&apos; AND j.tipdoc IN (14,15)    THEN 472
        WHEN j.tipdoc = 76 AND dc.faza = 1 THEN 710
        WHEN j.tipdoc = 76 AND dc.faza = 2 THEN 720
        WHEN j.tipdoc = 76 AND dc.faza = 3 THEN 730
        WHEN j.tipdoc = 76 AND dc.faza = 4 THEN 740
        WHEN j.tipdoc = 72 THEN 750
        WHEN c.clasa  =  6 THEN 100
        WHEN c.clasa  =  7 THEN 200
      END tiplinie,
      c.codcont, g.codgest, Nvl(j.codcentru,0) codcentru, Nvl(cc.tipaloc,-1) tipaloc, CASE WHEN c.clasa = 7 THEN -j.valoare ELSE j.valoare END valoare, c.simbol,
      Nvl(DECODE(cc.tipchelt,1,g1.codcont9_01,2,g1.codcont9_02,3,g1.codcont9_03,11,g1.codcont9_11,12,g1.codcont9_12,13,g1.codcont9_13),0) codcont9
    FROM jurnal j
      INNER JOIN ncont        c  ON c.codcont    = j.contd
      INNER JOIN ngest        g  ON g.codgest    = j.gest
      LEFT  JOIN centrecost   cc ON cc.codcentru = j.codcentru
      LEFT  JOIN g1              ON g1.codgest   = j.gest
      LEFT  JOIN DistribChelt dc On dc.CodDistribChelt = J.CodDoc AND j.tipdoc = 76
    WHERE j.LUNA = &apos;||pkg_globals.getlunalucru||&apos; AND j.AN = &apos;||pkg_globals.getanlucru||&apos; AND c.clasa IN (6,7,9) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;)||&apos;
      AND CASE WHEN c.clasa = 9 AND j.tipdoc IN (72,76) AND c.codcont &lt;&gt; &apos;||vCPartS||&apos; THEN 1 WHEN c.clasa = 9 THEN 0 ELSE 1 END = 1
      AND j.TIPDOC &lt;&gt; 32
    UNION ALL
    SELECT
      CASE
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCNeterm||&apos; THEN 311
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCSemif||&apos; AND j.tipdoc IN (7)     THEN 321
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCSemif||&apos; AND j.tipdoc IN (14,15) THEN 331
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCSemif||&apos; AND j.tipdoc IN (13)    THEN 341
        WHEN j.contc = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contd, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (7)     THEN 411
        WHEN j.contc = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contd, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (13)    THEN 421
        WHEN j.contc = &apos;||vCVenitN||&apos; AND PKG_CATEGCONST.ESTECONTPENTRU(j.contd, &apos;&apos;CPRODUSEANIMALE&apos;&apos;) &gt; 0 AND j.tipdoc IN (14,15) THEN 431
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCProdR||&apos; AND j.tipdoc IN (7)     THEN 451
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCProdR||&apos; AND j.tipdoc IN (13)    THEN 461
        WHEN j.contc = &apos;||vCVenitN||&apos; AND j.contd = &apos;||vCProdR||&apos; AND j.tipdoc IN (14,15) THEN 471
        WHEN j.tipdoc = 76 AND dc.faza = 1 THEN 710
        WHEN j.tipdoc = 76 AND dc.faza = 2 THEN 720
        WHEN j.tipdoc = 76 AND dc.faza = 3 THEN 730
        WHEN j.tipdoc = 76 AND dc.faza = 4 THEN 740
        WHEN j.tipdoc = 72 THEN 750
        WHEN c.clasa  =  6 THEN 100
        WHEN c.clasa  =  7 THEN 200
      END tiplinie,
      c.codcont, g.codgest, Nvl(j.codcentru,0) codcentru, Nvl(cc.tipaloc,-1) tipaloc, CASE WHEN c.clasa = 7 THEN j.valoare ELSE -j.valoare END valoare, c.simbol,
      Nvl(DECODE(cc.tipchelt,1,g1.codcont9_01,2,g1.codcont9_02,3,g1.codcont9_03,11,g1.codcont9_11,12,g1.codcont9_12,13,g1.codcont9_13),0) codcont9
    FROM jurnal j
      INNER JOIN ncont        c  ON c.codcont    = j.contc
      INNER JOIN ngest        g  ON g.codgest    = j.gest
      LEFT  JOIN centrecost   cc ON cc.codcentru = j.codcentru
      LEFT  JOIN g1              ON g1.codgest   = j.gest
      LEFT  JOIN DistribChelt dc On dc.CodDistribChelt = J.CodDoc AND j.tipdoc = 76
    WHERE j.LUNA = &apos;||pkg_globals.getlunalucru||&apos; AND j.AN = &apos;||pkg_globals.getanlucru||&apos; AND c.clasa IN (6,7,9) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;)||&apos;
      AND CASE WHEN c.clasa = 9 AND j.tipdoc IN (72,76) AND c.codcont &lt;&gt; &apos;||vCPartS||&apos; THEN 1 WHEN c.clasa = 9 THEN 0 ELSE 1 END = 1
      AND j.TIPDOC &lt;&gt; 32
  )
  SELECT
    tiplinie, codcont, codgest, codcentru, codcont9,
    sum(Decode(tipaloc,0,valoare,0)) valaloc,
    sum(Decode(tipaloc,1,valoare,0)) valnealoc,
    sum(CASE WHEN tipaloc IN (0,1) THEN 0 WHEN simbol IN (&apos;&apos;701&apos;&apos;,&apos;&apos;702&apos;&apos;,&apos;&apos;703&apos;&apos;) THEN valoare ELSE 0 END) vanzari,
    sum(CASE WHEN tipaloc IN (0,1) THEN 0 WHEN simbol IN (&apos;&apos;607&apos;&apos;,&apos;&apos;707&apos;&apos;) THEN valoare ELSE 0 END) marfuri,
    sum(CASE
          WHEN tipaloc IN (0,1) THEN 0
          WHEN simbol IN (&apos;&apos;701&apos;&apos;,&apos;&apos;702&apos;&apos;,&apos;&apos;703&apos;&apos;,                          -- vanzari
                          &apos;&apos;607&apos;&apos;,&apos;&apos;707&apos;&apos;,                                  -- marfuri
                          &apos;&apos;665&apos;&apos;,&apos;&apos;666&apos;&apos;,&apos;&apos;667&apos;&apos;,&apos;&apos;765&apos;&apos;,&apos;&apos;766&apos;&apos;,&apos;&apos;767&apos;&apos;,  -- elemfinanc
                          &apos;&apos;000.000&apos;&apos;,                                      -- elemexcept
                          &apos;&apos;623&apos;&apos;,&apos;&apos;691&apos;&apos;                                   -- chimpprof
                         ) THEN 0
          ELSE valoare
        END
    ) alteactiv,
    sum(CASE WHEN tipaloc IN (0,1) THEN 0 WHEN simbol IN (&apos;&apos;665&apos;&apos;,&apos;&apos;666&apos;&apos;,&apos;&apos;667&apos;&apos;,&apos;&apos;765&apos;&apos;,&apos;&apos;766&apos;&apos;,&apos;&apos;767&apos;&apos;) THEN valoare ELSE 0 END) elemfinanc,
    sum(CASE WHEN tipaloc IN (0,1) THEN 0 WHEN simbol IN (&apos;&apos;000.000&apos;&apos;) THEN valoare ELSE 0 END) elemexcept,
    sum(CASE WHEN tipaloc IN (0,1) THEN 0 WHEN simbol IN (&apos;&apos;623&apos;&apos;,&apos;&apos;691&apos;&apos;) THEN valoare ELSE 0 END) chimpprof,
    sum(valoare) valtot,
    0 totaltip
  FROM j
  GROUP BY tiplinie, codcont, codgest, codcentru, codcont9&apos;;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    Cont,
    Denumire,
    TipLinie,
    ContAsoc, Gest, CentruCost,
    totaloc, totnealoc, vanzari, marfuri, alteactiv, elemfinanc, elemexcept, chimpprof,
    totalalt, total, totaltip, ord &apos;||gUserFields||&apos;)
  SELECT
    c.Simbol,
    CASE
      WHEN tmp.tiplinie = 100 THEN c.Den_Cont
      WHEN tmp.tiplinie = 199 THEN &apos;&apos;Total cheltuieli&apos;&apos;
      WHEN tmp.tiplinie = 200 THEN c.Den_Cont
      WHEN tmp.tiplinie = 299 THEN &apos;&apos;Total venituri&apos;&apos;
      WHEN tmp.tiplinie = 311 THEN &apos;&apos;Productie neterminata_sfarsit perioada_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 312 THEN &apos;&apos;Productie neterminata_consum productie_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 321 THEN &apos;&apos;Produse semifinite_Productie Cost standard_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 322 THEN &apos;&apos;Produse semifinite_Vanzari Cost standard_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 323 THEN &apos;&apos;Produse semifinite_Consum productie Cost standard_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 331 THEN &apos;&apos;Produse semifinite_Dif Inventar_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 332 THEN &apos;&apos;Produse semifinite_Dif Inventar_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 341 THEN &apos;&apos;Produse semifinite_Abateri semifinite_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 342 THEN &apos;&apos;Produse semifinite_Abateri semifinite Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 399 THEN &apos;&apos;Total productie in curs si semifabricate&apos;&apos;
      WHEN tmp.tiplinie = 411 THEN &apos;&apos;Produse finite - Productie Cost standard_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 412 THEN &apos;&apos;Produse finite - Vanzari Cost standard_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 421 THEN &apos;&apos;Produse finite - Abateri_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 422 THEN &apos;&apos;Produse finite - Abateri_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 431 THEN &apos;&apos;Produse finite_Dif Inventar_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 432 THEN &apos;&apos;Produse finite_Dif Inventar_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 451 THEN &apos;&apos;Produse reziduale - Productie Cost standard_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 452 THEN &apos;&apos;Produse reziduale - Vanzari Cost standard_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 453 THEN &apos;&apos;Produse reziduale - Consum Cost standard_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 461 THEN &apos;&apos;Produse reziduale - Abateri_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 462 THEN &apos;&apos;Produse reziduale - Abateri_Debit (-)&apos;&apos;
      WHEN tmp.tiplinie = 471 THEN &apos;&apos;Produse reziduale_Dif Inventar_Credit (+)&apos;&apos;
      WHEN tmp.tiplinie = 472 THEN &apos;&apos;Produse reziduale_Dif Inventar_Debit (+)&apos;&apos;
      WHEN tmp.tiplinie = 499 THEN &apos;&apos;Total produse finite si reziduale&apos;&apos;
      WHEN tmp.tiplinie = 599 THEN &apos;&apos;Total rezultat luna&apos;&apos;
      WHEN tmp.tiplinie = 699 THEN &apos;&apos;Cost productie preliminar&apos;&apos;
      WHEN tmp.tiplinie = 710 THEN &apos;&apos;Distributii faza 1&apos;&apos;
      WHEN tmp.tiplinie = 720 THEN &apos;&apos;Distributii faza 2&apos;&apos;
      WHEN tmp.tiplinie = 730 THEN &apos;&apos;Distributii faza 3&apos;&apos;
      WHEN tmp.tiplinie = 740 THEN &apos;&apos;Distributii faza 4&apos;&apos;
      WHEN tmp.tiplinie = 750 THEN &apos;&apos;post calcul&apos;&apos;
      WHEN tmp.tiplinie = 799 THEN &apos;&apos;Total decontari&apos;&apos;
      WHEN tmp.tiplinie = 899 THEN &apos;&apos;Cost productie final&apos;&apos;
    END denumire,
    CASE
      WHEN trunc(tmp.tiplinie/100) = 1 THEN &apos;&apos;01.Cheltuieli&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 2 THEN &apos;&apos;02.Venituri&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 3 THEN &apos;&apos;03.711-productie in curs si semifabricate&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 4 THEN &apos;&apos;04.711-produse finite si reziduale&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 5 THEN &apos;&apos;05.Rezultat luna&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 6 THEN &apos;&apos;06.Cost Preliminar&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 7 THEN &apos;&apos;07.Decontari interne&apos;&apos;
      WHEN trunc(tmp.tiplinie/100) = 8 THEN &apos;&apos;08.Cost final&apos;&apos;
    END tiplinie,
    c9.simbol, g.den_gest, cc.denumire,
    tmp.valaloc, tmp.valnealoc, tmp.vanzari, tmp.marfuri, tmp.alteactiv, tmp.elemfinanc, tmp.elemexcept, tmp.chimpprof,
    tmp.vanzari+tmp.marfuri+tmp.alteactiv+tmp.elemfinanc+tmp.elemexcept+tmp.chimpprof, tmp.valaloc + tmp.valnealoc, tmp.totaltip, tmp.TipLinie &apos;||gUserAlias||&apos;
  FROM tmp_lst_matrcv tmp
    LEFT JOIN ncont      c  ON c.codcont    = tmp.codcont
    LEFT JOIN ngest      g  ON g.codgest    = tmp.codgest
    LEFT JOIN centrecost cc ON cc.codcentru = tmp.codcentru
    LEFT JOIN ncont      c9 ON c9.codcont   = tmp.codcont9&apos;||
    gSuplJoins;

  DELETE tmp_lst_matrcv;

  EXECUTE IMMEDIATE sInsTmp;
  DELETE tmp_lst_matrcv
  WHERE valaloc = 0 AND valnealoc = 0 AND vanzari = 0 AND marfuri = 0 AND alteactiv = 0 AND elemfinanc = 0 AND elemexcept = 0 AND chimpprof = 0 AND valtot = 0;

  INSERT INTO tmp_lst_matrcv
  SELECT Trunc(tiplinie/100)*100+99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Sum(valtot)
  FROM tmp_lst_matrcv
  GROUP BY Trunc(tiplinie/100);

  INSERT INTO tmp_lst_matrcv
  SELECT 599, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Sum(totaltip * Decode(tiplinie,199,-1,1))
  FROM tmp_lst_matrcv
  WHERE tiplinie IN (199,299,399,499);

  INSERT INTO tmp_lst_matrcv
  SELECT 699, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Sum(totaltip * Decode(tiplinie,199,1,-1))
  FROM tmp_lst_matrcv
  WHERE tiplinie IN (199,299,399);

  INSERT INTO tmp_lst_matrcv
  SELECT 899, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Sum(totaltip)
  FROM tmp_lst_matrcv
  WHERE tiplinie IN (699,799);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_matrcv; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MATSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6CB641771678A9B0BC489F1AB937F5349490B61</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_MATSA IS

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sPer     VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;comanda c, Comanda2 C2, Comanda3 C3, CMDProdMat CPM, Nartobj NAO, NUM UM, Nparccom NPC, NparcAut NPA&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
      NAV_CodDoc,
      NAV_TipDoc,
      SERIADOC,
      NRDOC,
      DATADOC,
      ANULAT,
      OPERAT,
      INCHIS,
      CodExtern,
      ARTICOL,
      UM,
      CANTPROIECTATA,
      PRETARTICOL,
      REST,
      CLIENT,
      CIFCLIENT,
      MODEL,
      MARCA,
      NRINREG,
      ANFABRICATIE,
      CULOAREC,
      SERIECAROSERIE,
      SERIEMOTOR,
      LUCRARE,
      OBSERVATII,
      PLATITOR,
      CIFPLATITOR,
      GARANTIE,
      OPERATIE,
      DESCRIERE,
      DATAFIN,
      TIP,
      EXECUTAT,
      GESTIUNE,
      TIPCOLOANA&apos;||gUserFields||&apos;)&apos;;
/*
        Decode(C.Operat,0,&apos;&apos;Da&apos;&apos;,1,&apos;&apos;Nu&apos;&apos;) Operat,    
        Decode(C.Anulat,0,&apos;&apos;Da&apos;&apos;,1,&apos;&apos;Nu&apos;&apos;) Anulat,
        Decode(C.Inchisa,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Inchis,
        
        Silvia zice ca la operat si anulat erau inversate valorile, la inchisa nu...
*/

  sSelect := &apos;
SELECT
        C.CodComanda,
        C.TipDoc,
        C.SeriaDoc,
        C.NrDoc,
        C.DataDOC,
        Decode(Nvl(C.Anulat,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Anulat,
        Decode(Nvl(C.Operat,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Operat,
        Decode(Nvl(C.Inchisa,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Inchis,
        NAO.CodExtern,
        NAO.Denumire Articol,
        UM.Den_UM UM,
        CPM.Cant CantProiectata,
        CPM.Pret PretArticol,
        CPM.Rest Rest,
        Case when C.FaraFactura = 1 then &apos;&apos;Comanda interna&apos;&apos; else NPart.Den_Part end Client,
        CIF.CodFiscal CIFClient,
        NMo.Model,
        NMa.Marca,
        NPA.NRINREG,
        NPA.ANF AnFabricatie,
        NPA.CULOAREC,
        NPA.SERIEC SerieCaroserie,
        NPA.Seriem SerieMotor,
        LS.Denumire Lucrare,
        C2.Obs Observatii,
        NVL(NP.DEN_PART,NPart.Den_Part) Platitor,
        NVL(CIF2.CodFiscal,CIF.CodFiscal) CIFPlatitor,
        Decode(Nvl(C2.Garantie,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Garantie,
        NO.Denumire Operatie,
        C3.Obs Descriere,
        C3.Data DataFin,
        Decode(Nvl(C3.Tip,0),0,&apos;&apos;Solicitare&apos;&apos;,1,&apos;&apos;Constatare&apos;&apos;,2,&apos;&apos;Nefacturabila&apos;&apos;) Tip,
        Decode(Nvl(C3.Executat,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Executat,
        NG.Den_gest Gestiune,
        NPC.TIPCOMANDA TIPCOLOANA&apos;||gUserAlias||&apos;
      from comanda c
        Left join Comanda2 C2 on C2.CodComanda = C.CodComanda
        Left join Comanda3 C3 on C3.CodComanda2 = C2.CodComanda2
        Left join CMDProdMat CPM on CPM.CodComanda3 = C3.CodComanda3
        Left join Nartobj NAO on NAO.CodObiect = CPM.CodObiect
        Left join NUM UM on Um.CodUm = CPM.UMsec
        left join Nparccom NPC on NPC.CodComanda = C.CodComanda
        Left join NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
        Left join Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
        Left join NModeleauto NMo on NMo.CodModeleauto=NPA.Model
        Left join Tiplucrarisa LS on LS.Codtiplucrare=C2.Codlucrare
        Left join Npart NPart on NPart.CodPart = C.Partener
        Left join NPartCodFisc CIF on CIF.CODPART = C.Partener
        Left join Npart NP on NP.CodPart = C2.Codpart
        Left join NPartCodFisc CIF2 on CIF2.CODPART = C2.Codpart
        Left join NGest NG on NG.CodGest = C.CodGest
        Left join NOper NO on NO.CODOP = C3.CodOperatie &apos;||gSuplJoins||&apos;
      WHERE C.TipDoc = 92
      AND C.DataDoc &apos;||sPer||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
 
  EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_MATSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87B1C88724896F4C82A7D5736A17F9E997203ADF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_MIFIX IS

  v_ToateMF   BOOLEAN;
  v_TipSelMF  NUMBER;
  v_Amo       NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams (
  p_ToateMF  IN NUMBER DEFAULT 1,
  p_TipSelMF IN NUMBER DEFAULT 0,
  p_Amo      IN NUMBER DEFAULT 0)
IS
BEGIN
  v_ToateMF  := p_ToateMF = 1;
  v_TipSelMF := p_TipSelMF;
  v_Amo      := p_Amo;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
  sInsert   CLOB;
  sFiltru1  VARCHAR2(200);
  sFiltru2  VARCHAR2(200);
  dAuxDate  DATE;
  cCMifix   CLOB := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;CMifix&apos;, PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU), &apos;-2&apos;);
  cCMF1     CLOB := &apos;&apos;;
  cCMF2     CLOB := &apos;&apos;;
BEGIN
  gSuplCols := &apos;MIFIX MF, MIFIX1 MF1, MFCLASIF MFC, NIRSTOC NS, NIR NIR, NGEST NG, NARTOBJ NAO, NGEST NG_S, NGEST NG_D, NPART PC, NPART FURN, NLOCATII L, NARTAMB AA, CENTRECOST CC, NIRSER NSER, NSERII SER, FISAMF FMF&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  dAuxDate := To_Date(To_Char(PKG_GLOBALS.GETANLUCRU*100+PKG_GLOBALS.GETLUNALUCRU,&apos;fm000000&apos;),&apos;yyyymm&apos;);
  dAuxDate := Add_Months(dAuxDate, 1);
  dAuxDate := Trunc(dAuxDate,&apos;mm&apos;);

  IF    NOT v_ToateMF AND v_TipSelMF = 0 THEN
    sFiltru2 := &apos;
    AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  ELSIF NOT v_ToateMF AND v_TipSelMF = 1  THEN
    sFiltru1 := &apos;
      AND MF.CODMIFIX IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMIFIX&apos;&apos;)&apos;;
  END IF;

  IF cCMifix &lt;&gt; &apos;-2&apos;THEN 
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
    EXECUTE IMMEDIATE
    &apos;INSERT INTO TMP_MANEVRA (CODUNIC)
    WITH /*RECURSIVE*/ tmpc (CODCONT) AS (
      SELECT codcont
      FROM ncont
      WHERE codcont IN (&apos;||cCMifix||&apos;)
        AND codcont &lt;&gt; 0
      UNION ALL
      SELECT c.codcont
      FROM tmpc INNER JOIN ncont c ON c.codparinte = tmpc.codcont
    )
    SELECT codcont FROM tmpc &apos;;

    cCMF1 := &apos;  
        WHEN FMF.CODOPERATIE = 2 AND CMF.CODUNIC IS NULL        THEN FMF.PretI&apos;;
    cCMF2 := &apos;  
      LEFT JOIN NIRSTOC     NSP   ON NSP.CODNIRSTOC   = NS.CODNIRSTOCPARINTE
      LEFT JOIN NIR         NP    ON NP.CODNIR        = NSP.CODNIR
      LEFT JOIN IOART1      IOA1P ON IOA1P.CODIOART   = NSP.CODIOART AND MF1.ANSTART*12+MF1.LUNASTART BETWEEN IOA1P.ALSTART AND IOA1P.ALSTOP
      LEFT JOIN TMP_MANEVRA CMF   ON CMF.CODUNIC      = IOA1P.CONT&apos;;
  END IF;


  if v_Amo &gt; 0 then
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
      Denumire,Categoria,CodClasif,AnFolos,LunaFolos,CodExtern,CodIntern,
      AnAmort,LunaAmort,
      DurataNorm,DurataUtil,NrInv,
      Document,DataDoc,
      Operatii,
      NrBuc,
      Debit,
      Credit,
      Ord,
      Sold,
      Obs,
      AmortLun,
      CentruCost, PretInitial&apos;||gUserFields||&apos;)
    SELECT
      NAO.DENUMIRE, MFC.DENUMIRE Categoria, MFC.SIMBOL CodClasif, MF.ANINTRARE, MF.LUNAINTRARE,NAO.CODEXTERN, NAO.CODINTERN,
      CASE WHEN MF.ANINTRARE*12+MF.LUNAINTRARE &gt; MF1.ANSTART*12+MF1.LUNASTART THEN MF.ANINTRARE+Trunc((MF.LUNAINTRARE+MF1.DURATAF-1)/12) ELSE MF1.ANSTART+Trunc((MF1.LUNASTART+MF1.DURATAF-1)/12) END AnAmort,
      MOD(Greatest(MF.ANINTRARE * 12 + MF.LUNAINTRARE, MF1.ANSTART * 12 + MF1.LUNASTART) + MF1.DURATAF - 1,12) + 1 LunaAmort,
      MF1.DURATAN DurataNorm, MF1.DURATAF DurataUtil, MF.NRINVENTAR,
      TMP.doc, TMP.DATAOPERATIE DataDoc,
      CASE
        WHEN FMF.CODOPERATIE IS NULL THEN
          case
            when m1.stare = 3 then &apos;&apos;Casat in luna&apos;&apos;
            when m1.stare = 4 then &apos;&apos;Vandut in luna&apos;&apos;
            when m1.tipreeval in (0,1) then case when (TMP.icontd = 4 and TMP.icontc = 10) or (TMP.icontd = 3 and TMP.icontc = 0) then
              &apos;&apos;Amortizare &apos;&apos;||to_char(to_date(m1.lunastart,&apos;&apos;mm&apos;&apos;),&apos;&apos;mon&apos;&apos;)||&apos;&apos; &apos;&apos;||to_char(m1.anstart) else &apos;&apos;Reevaluare &apos;&apos;||to_char(to_date(m1.lunastart,&apos;&apos;mm&apos;&apos;),&apos;&apos;mon&apos;&apos;)||&apos;&apos; &apos;&apos;||to_char(m1.anstart) end
            when m1.tipreeval is null then &apos;&apos;Amortizare &apos;&apos;||to_char(to_date(m1.lunastart,&apos;&apos;mm&apos;&apos;),&apos;&apos;mon&apos;&apos;)||&apos;&apos; &apos;&apos;||to_char(m1.anstart)
          end
        ELSE
        CASE WHEN TMP.INIT = 1 THEN &apos;&apos;Amortizare precedenta&apos;&apos;
        ELSE
        CASE FMF.CODOPERATIE
          WHEN  1 THEN &apos;&apos;Intrare in firma - &apos;&apos;||NG_D.DEN_GEST
          WHEN  2 THEN &apos;&apos;Transfer intre gestiuni - &apos;&apos;||NG_S.DEN_GEST||&apos;&apos; - &apos;&apos;||NG_D.DEN_GEST
          WHEN  3 THEN &apos;&apos;Modificare de pret&apos;&apos;
          WHEN  4 THEN &apos;&apos;Casare&apos;&apos;
          WHEN  5 THEN &apos;&apos;Vanzare&apos;&apos;
          WHEN  6 THEN &apos;&apos;Reevaluare - valoare MF&apos;&apos;
          WHEN  7 THEN &apos;&apos;Reevaluare - amortizare prec&apos;&apos;
          WHEN  8 THEN &apos;&apos;Marire de stoc - &apos;&apos;||NG_D.DEN_GEST
          WHEN  9 THEN &apos;&apos;Modificare gestiune - &apos;&apos;||NG_S.DEN_GEST||&apos;&apos; - &apos;&apos;||NG_D.DEN_GEST
          WHEN 10 THEN &apos;&apos;Modificare centru de cost&apos;&apos;
          WHEN 11 THEN &apos;&apos;Modificare tip contabil&apos;&apos;
          WHEN 12 THEN &apos;&apos;Punere in functiune&apos;&apos;
        END END
      END Operatie,
      coalesce(FMF.CANT,1) NrBuc,
      CASE
        WHEN TMP.INIT = 1 THEN 0
        WHEN FMF.CODFISAMF IS NULL                              THEN 0
        WHEN FMF.CODOPERATIE IN (1,8)                           THEN FMF.PretI&apos;||
        cCMF1||&apos;
        WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
        WHEN FMF.CODOPERATIE = 3      AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
        ELSE 0
      END Debit,
      CASE
        WHEN TMP.CODFISAMF = 0 THEN
          round(
            PKG_INCHIDERI.AMORTIZARELUNARA(M1.CODMIFIX, M1.ANSTART, M1.LUNASTART),2)
        WHEN TMP.CODFISAMF &gt; 0 and tmp.init = 1 THEN MF1M.amo
        WHEN FMF.CODOPERATIE IN (4,5) THEN FMF.PretE
        WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
        WHEN FMF.CODOPERATIE = 3 AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
        ELSE 0
      END Credit,
      ROW_NUMBER() OVER (PARTITION BY MF.CODMIFIX ORDER BY TMP.DATAOPERATIE, TMP.CODFISAMF) Ord,
      SUM(
        CASE
          WHEN TMP.INIT = 1 THEN 0
          WHEN FMF.CODFISAMF IS NULL THEN 0
          WHEN FMF.CODOPERATIE IN (1,8) THEN FMF.PretI
          WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
          WHEN FMF.CODOPERATIE = 3 AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
          ELSE 0
        END
        -
        CASE
          WHEN TMP.CODFISAMF = 0 THEN
            round(
              PKG_INCHIDERI.AMORTIZARELUNARA(M1.CODMIFIX, M1.ANSTART, M1.LUNASTART),2)
          WHEN TMP.CODFISAMF &gt; 0 and tmp.init = 1 THEN MF1M.amo
          WHEN FMF.CODOPERATIE IN (4,5) THEN FMF.PretE
          WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
          WHEN FMF.CODOPERATIE = 3 AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
          ELSE 0
        END
      ) OVER (PARTITION BY MF.CODMIFIX ORDER BY TMP.DATAOPERATIE, TMP.CODFISAMF RANGE UNBOUNDED PRECEDING) Sold,
      TMP.OBS,
      PKG_INCHIDERI.GETAMOLUNA(
        Coalesce(MF1.ANSTART,0), Coalesce(MF1.LUNASTART,0), Coalesce(MF1.AMO,0), Coalesce(MF1.NEUTIL,0), Coalesce(MF1.DURATAF,0),
        Coalesce(MF1.PRET,0), Coalesce(MF1.CANT,0), Coalesce(MF1.GRADU,0)/100, Coalesce(MF.ANINTRARE,0), Coalesce(MF.LUNAINTRARE,0), Coalesce(MF1.TIPAMO,0), Coalesce(MF1.DURATAN,0), MF.TIP
      ) AmortLun,
      cc.denumire, nsmin.pret &apos;||gUserAlias||&apos;
    FROM (
      SELECT
        MF.CODMIFIX, FMF.CODFISAMF,
        (
          SELECT Max(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            --AND MF1.PRET = FMF.PRETI
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) AL_MF1, 0 CODMIFIX1, NULL ICONTD, NULL ICONTC,
        FMF.PREFIXDOC||FMF.NRDOC||&apos;&apos;/&apos;&apos;||FMF.DATAOPERATIE doc, FMF.DATAOPERATIE, FMF.DATAOPERATIE DATAORDINE, FMF.OBS, 0 Init,
        (
          SELECT Min(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            --AND MF1.PRET = FMF.PRETI
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) MIN_MF1
      FROM MIFIX MF INNER JOIN FISAMF FMF ON FMF.CODMIFIX = MF.CODMIFIX
      WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
        AND FMF.DATAOPERATIE &lt; to_date(&apos;&apos;&apos;||To_Char(dAuxDate,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
        sFiltru1||&apos;
      UNION ALL
      SELECT
        MF.CODMIFIX, 0 CODFISAMF,
        (
          SELECT Max(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) AL_MF1,
        MF1.CODMIFIX1, J1.ICONTD, J1.ICONTC, J1.DOCUMENT doc, J1.DATADOC DATAOPERATIE, J1.DATADOC DATAORDINE, J1.OBS, 0 Init,
        (
          SELECT Min(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) MIN_MF1
      FROM (SELECT * FROM JURNAL1 WHERE DATADOC &lt; to_date(&apos;&apos;&apos;||To_Char(dAuxDate,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TIPDOC = 36 AND ICONTD = 4) J1
           INNER JOIN MIFIX MF ON MF.CODMIFIX = J1.CODDOC
           INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = MF.CODMIFIX AND MF1.Stare &lt;&gt; 3 AND MF1.Stare &lt;&gt; 4 AND MF1.ANSTART*12+MF1.LUNASTART = J1.AN*12+J1.LUNA
      WHERE MF.TIP = &apos;&apos;MF&apos;&apos; &apos;||sFiltru1||&apos;
      UNION ALL
      SELECT
        MF.CODMIFIX, FMF.CODFISAMF,
        (
          SELECT MAX(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            AND MF1.PRET = FMF.PRETI
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) AL_MF1, 0 CODMIFIX1, NULL ICONTD, NULL ICONTC,
        FMF.PREFIXDOC||FMF.NRDOC||&apos;&apos;/&apos;&apos;||FMF.DATAOPERATIE doc, FMF.DATAOPERATIE, FMF.DATAOPERATIE + 1/24/60/60 DATAORDINE, FMF.OBS, 1 Init,
        (
          SELECT MIN(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            AND MF1.PRET = FMF.PRETI
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) MIN_MF1
      FROM MIFIX MF
           INNER JOIN FISAMF FMF ON FMF.CODMIFIX = MF.CODMIFIX
      WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
        AND extract(year from FMF.DATAOPERATIE) * 12 + extract(month from FMF.DATAOPERATIE) &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI) &apos;||
        sFiltru1||&apos;
    ) tmp
      INNER JOIN MIFIX     MF    ON MF.CODMIFIX      = tmp.CODMIFIX
      INNER JOIN MIFIX1    MF1   ON MF1.CODMIFIX     = tmp.CODMIFIX AND MF1.ANSTART*12+MF1.LUNASTART = tmp.AL_MF1
      INNER JOIN MIFIX1    MF1M  ON MF1M.CODMIFIX    = tmp.CODMIFIX AND MF1M.ANSTART*12+MF1M.LUNASTART = tmp.MIN_MF1
      INNER JOIN MFCLASIF  MFC   ON MFC.CODCLASIF    = MF1.CODCLASIF
      INNER JOIN NIRSTOC   NS    ON NS.CODNIRSTOC    = MF1.CODNIRSTOC
      INNER JOIN NIR             ON NIR.CODNIR       = NS.CODNIR
      INNER JOIN NGEST     NG    ON NG.CODGEST       = NIR.GEST
      INNER JOIN NARTOBJ   NAO   ON NAO.CODOBIECT    = NS.CODOBIECT
      LEFT JOIN MIFIX1     M1    ON TMP.CODMIFIX1    = M1.CODMIFIX1
      LEFT JOIN FISAMF     FMF   ON FMF.CODFISAMF    = tmp.CODFISAMF
      LEFT JOIN NGEST      NG_S  ON NG_S.CODGEST     = FMF.GESTSURSA
      LEFT JOIN NGEST      NG_D  ON NG_D.CODGEST     = FMF.GESTDEST
      LEFT JOIN NPART      PC    ON PC.CODPART       = MF1.CODPART
      LEFT JOIN NPART      FURN  ON FURN.CODPART     = NS.FURN
      LEFT JOIN NLOCATII   L     ON L.CODLOCATIE     = MF1.CODLOCATIE
      LEFT JOIN NARTAMB    AA    ON AA.CODOBIECT     = NS.CODOBIECT AND AA.UMSEC = NS.UMSEC
      LEFT JOIN CENTRECOST CC    ON CC.CODCENTRU     = Coalesce(MF1.CODCENTRU,0)
      LEFT JOIN (
        select min(mf1.codnirstoc) codnirstoc, mf1.codmifix from mifix1 mf1 group by mf1.codmifix
      )                    mfmin ON mf1.codmifix     = mfmin.codmifix
      LEFT JOIN nirstoc    nsmin ON mfmin.codnirstoc = nsmin.codnirstoc
      LEFT JOIN nirser     nser  ON nser.codnirser   = mf1.codnirser
      LEFT JOIN nserii     ser   ON ser.codserie     = nser.codserie&apos;||
      cCMF2||
      gSuplJoins||&apos;
    WHERE 1=1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
      sFiltru2||&apos;
    ORDER BY MF.CODMIFIX, TMP.DATAORDINE, TMP.CODFISAMF&apos;;
  ELSE
    sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
      Denumire,Categoria,CodClasif,AnFolos,LunaFolos,CodExtern,CodIntern,
      AnAmort,LunaAmort,
      DurataNorm,DurataUtil,NrInv,
      Document,DataDoc,
      Operatii,
      NrBuc,
      Debit,
      Credit,
      Ord,
      Sold,
      Obs,
      AmortLun,
      CentruCost, PretInitial&apos;||gUserFields||&apos;)
    SELECT
      NAO.DENUMIRE, MFC.DENUMIRE Categoria, MFC.SIMBOL CodClasif, MF.ANINTRARE, MF.LUNAINTRARE,NAO.CODEXTERN, NAO.CODINTERN,
      CASE WHEN MF.ANINTRARE*12+MF.LUNAINTRARE &gt; MF1.ANSTART*12+MF1.LUNASTART THEN MF.ANINTRARE+Trunc((MF.LUNAINTRARE+MF1.DURATAF-1)/12) ELSE MF1.ANSTART+Trunc((MF1.LUNASTART+MF1.DURATAF-1)/12) END AnAmort,
      MOD(Greatest(MF.ANINTRARE * 12 + MF.LUNAINTRARE, MF1.ANSTART * 12 + MF1.LUNASTART) + MF1.DURATAF - 1,12) + 1 LunaAmort,
      MF1.DURATAN DurataNorm, MF1.DURATAF DurataUtil, MF.NRINVENTAR,
      FMF.PREFIXDOC||FMF.NRDOC||&apos;&apos;/&apos;&apos;||FMF.DATAOPERATIE doc, FMF.DATAOPERATIE DataDoc,
      CASE FMF.CODOPERATIE
        WHEN  1 THEN &apos;&apos;Intrare in firma - &apos;&apos;||NG_D.DEN_GEST
        WHEN  2 THEN &apos;&apos;Transfer intre gestiuni - &apos;&apos;||NG_S.DEN_GEST||&apos;&apos; - &apos;&apos;||NG_D.DEN_GEST
        WHEN  3 THEN &apos;&apos;Modificare de pret&apos;&apos;
        WHEN  4 THEN &apos;&apos;Casare&apos;&apos;
        WHEN  5 THEN &apos;&apos;Vanzare&apos;&apos;
        WHEN  6 THEN &apos;&apos;Reevaluare - valoare MF&apos;&apos;
        WHEN  7 THEN &apos;&apos;Reevaluare - amortizare prec&apos;&apos;
        WHEN  8 THEN &apos;&apos;Marire de stoc - &apos;&apos;||NG_D.DEN_GEST
        WHEN  9 THEN &apos;&apos;Modificare gestiune - &apos;&apos;||NG_S.DEN_GEST||&apos;&apos; - &apos;&apos;||NG_D.DEN_GEST
        WHEN 10 THEN &apos;&apos;Modificare centru de cost&apos;&apos;
        WHEN 11 THEN &apos;&apos;Modificare tip contabil&apos;&apos;
        WHEN 12 THEN &apos;&apos;Punere in functiune&apos;&apos;
      END Operatie,
      Coalesce(FMF.CANT,1) NrBuc,
      CASE
        WHEN FMF.CODOPERATIE IN (1,8)                           THEN FMF.PretI&apos;||
        cCMF1||&apos;
        WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
        WHEN FMF.CODOPERATIE = 3      AND FMF.PretE &gt; FMF.PretI THEN FMF.PretE - FMF.PretI
        ELSE 0
      END Debit,
      CASE
        WHEN FMF.CODOPERATIE IN (4,5) THEN FMF.PretE
        WHEN FMF.CODOPERATIE IN (2,6) AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
        WHEN FMF.CODOPERATIE = 3 AND FMF.PretI &gt; FMF.PretE THEN FMF.PretI - FMF.PretE
        ELSE 0
      END Credit,
      ROW_NUMBER() OVER (PARTITION BY MF.CODMIFIX ORDER BY FMF.DATAOPERATIE, FMF.CODFISAMF) Ord,
      SUM(
        CASE FMF.CODOPERATIE
          WHEN 1 THEN FMF.PRETI
          WHEN 2 THEN FMF.PRETE-FMF.PRETI
          WHEN 3 THEN FMF.PRETE-FMF.PRETI
          WHEN 4 THEN - FMF.PRETE
          WHEN 5 THEN -FMF.PRETE
          WHEN 6 THEN FMF.PRETE-FMF.PRETI
          WHEN 8 THEN FMF.PRETI
        ELSE 0 END
      ) OVER (PARTITION BY MF.CODMIFIX ORDER BY FMF.DATAOPERATIE, FMF.CODFISAMF RANGE UNBOUNDED PRECEDING) Sold,
      FMF.OBS,
      PKG_INCHIDERI.AMORTIZARELUNARA(MF1.CODMIFIX, MF1.ANSTART, MF1.LUNASTART) AmortLun,
      cc.denumire, nsmin.pret &apos;||gUserAlias||&apos;
    FROM (
      SELECT
        MF.CODMIFIX, FMF.CODFISAMF,
        (
          SELECT Max(MF1.AnStart*12+MF1.LunaStart)
          FROM MIFIX1 MF1
          WHERE MF1.CODMIFIX = MF.CODMIFIX
            --AND MF1.PRET = FMF.PRETI
            AND MF1.ANSTART*12+MF1.LUNASTART &lt;= &apos;||PKG_GLOBALS.ANLUNALUCRU||&apos;
        ) AL_MF1
      FROM MIFIX MF INNER JOIN FISAMF FMF ON FMF.CODMIFIX = MF.CODMIFIX
      WHERE MF.TIP = &apos;&apos;MF&apos;&apos;
        AND FMF.DATAOPERATIE &lt; to_date(&apos;&apos;&apos;||To_Char(dAuxDate,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
        sFiltru1||&apos;
    ) tmp
      INNER JOIN MIFIX     MF    ON MF.CODMIFIX      = tmp.CODMIFIX
      INNER JOIN FISAMF    FMF   ON FMF.CODFISAMF    = tmp.CODFISAMF
      INNER JOIN MIFIX1    MF1   ON MF1.CODMIFIX     = tmp.CODMIFIX AND MF1.ANSTART*12+MF1.LUNASTART = tmp.AL_MF1
      INNER JOIN MFCLASIF  MFC   ON MFC.CODCLASIF    = MF1.CODCLASIF
      INNER JOIN NIRSTOC   NS    ON NS.CODNIRSTOC    = MF1.CODNIRSTOC
      INNER JOIN NIR             ON NIR.CODNIR       = NS.CODNIR
      INNER JOIN NGEST     NG    ON NG.CODGEST       = NIR.GEST
      INNER JOIN NARTOBJ   NAO   ON NAO.CODOBIECT    = NS.CODOBIECT
      LEFT JOIN NGEST      NG_S  ON NG_S.CODGEST     = FMF.GESTSURSA
      LEFT JOIN NGEST      NG_D  ON NG_D.CODGEST     = FMF.GESTDEST
      LEFT JOIN NPART      PC    ON PC.CODPART       = MF1.CODPART
      LEFT JOIN NPART      FURN  ON FURN.CODPART     = NS.FURN
      LEFT JOIN NLOCATII   L     ON L.CODLOCATIE     = MF1.CODLOCATIE
      LEFT JOIN NARTAMB    AA    ON AA.CODOBIECT     = NS.CODOBIECT AND AA.UMSEC = NS.UMSEC
      LEFT JOIN CENTRECOST CC    ON CC.CODCENTRU     = Coalesce(MF1.CODCENTRU,0)
      LEFT JOIN (
        SELECT min(mf1.codnirstoc) codnirstoc, mf1.codmifix FROM mifix1 mf1 GROUP BY mf1.codmifix
      )                     MFMIN ON mf1.codmifix = mfmin.codmifix
      LEFT JOIN nirstoc     NSMIN ON mfmin.codnirstoc = nsmin.codnirstoc
      LEFT JOIN nirser      NSER  ON nser.codnirser   = mf1.codnirser
      LEFT JOIN nserii      SER   ON ser.codserie     = nser.codserie&apos;||
      cCMF2||
      gSuplJoins||&apos;
    WHERE 1=1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||
      sFiltru2||&apos;
    ORDER BY MF.CODMIFIX, FMF.DATAOPERATIE, FMF.CODFISAMF &apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

 PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_MIFIX;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MISCARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B91FA48F108E543CB120ADBE00789097E5A23C4C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_MISCARI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE GetNirCuSerii IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert :=
  &apos;INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
  SELECT DISTINCT &apos;&apos;CODNIRSTOC&apos;&apos;, ns.codnirstoc
  FROM (
    SELECT codtransf
    FROM transf&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;subunitatea&apos;,&apos;
    WHERE&apos;);
  IF PKG_LIST_SELECTPER.DupaData THEN
    sInsert := sInsert ||&apos;
        AND TRUNC(DATADOC) BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
        AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSIF PKG_LIST_SELECTPER.LunaAnIni = PKG_LIST_SELECTPER.LunaAnFin THEN
    sInsert := sInsert ||&apos;
        AND (AN*12 + LUNA) = &apos;||PKG_LIST_SELECTPER.LunaAnIni;
  ELSE
    sInsert := sInsert ||&apos;
        AND (AN*12 + LUNA) BETWEEN &apos;||PKG_LIST_SELECTPER.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELECTPER.LunaAnFin;
  END IF;
	sInsert := sInsert||&apos;
    ) t
    INNER JOIN transf1 t1 ON t.codtransf = t1.codtransf
    INNER JOIN nirstoc ns ON t1.codtransf1 = ns.codtransf1 AND ns.tipserie &gt; 0
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
  WHERE 1 = 1 &apos;;

 	IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
	  sInsert := sInsert || &apos;
    AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
	END IF;

	IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
	  sInsert := sInsert || &apos;
    AND NIR.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
	END IF;

  EXECUTE IMMEDIATE sInsert;
  COMMIT;

  sInsert :=
  &apos;INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
  SELECT DISTINCT  &apos;&apos;CODNIRSTOC&apos;&apos;, l1.codnirstoc
  FROM (
    SELECT codies
    FROM iesiri &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;subunitatea&apos;,&apos;
    WHERE&apos;);
  IF PKG_LIST_SELECTPER.DupaData THEN
    sInsert := sInsert ||&apos;
      AND DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSIF PKG_LIST_SELECTPER.LunaAnIni = PKG_LIST_SELECTPER.LunaAnFin THEN
    sInsert := sInsert ||&apos;
      AND (AN*12 + LUNA) = &apos;||PKG_LIST_SELECTPER.LunaAnIni;
  ELSE
    sInsert := sInsert ||&apos;
      AND (AN*12 + LUNA) BETWEEN &apos;||PKG_LIST_SELECTPER.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELECTPER.LunaAnFin;
  END IF;

  sInsert := sInsert ||&apos;
    ) ies
    INNER JOIN livr l ON ies.codies = l.codies
    INNER JOIN livr1 l1 ON l.codlivr = l1.codlivr1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
  WHERE 1 = 1 &apos;;
	IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
	  sInsert := sInsert ||&apos;
    AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NS.CODOBIECT ) &apos;;
	END IF;

	IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
	  sInsert := sInsert || &apos;
    AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NIR.GEST) &apos;;
	END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  COMMIT;

END;

FUNCTION GetCondData(pAlias VARCHAR2) RETURN VARCHAR2 IS
  vResult VARCHAR2(2000);
BEGIN
  IF PKG_LIST_SELECTPER.DupaData THEN
    vResult := &apos;
    AND TRUNC(&apos;||pAlias||&apos;.DATADOC) BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSIF PKG_LIST_SELECTPER.LunaAnIni = PKG_LIST_SELECTPER.LunaAnFin THEN
    vResult := &apos;
    AND (&apos;||pAlias||&apos;.AN*12 + &apos;||pAlias||&apos;.LUNA) = &apos;||PKG_LIST_SELECTPER.LunaAnIni;
  ELSE
    vResult := &apos;
    AND (&apos;||pAlias||&apos;.AN*12+ &apos;||pAlias||&apos;.LUNA) BETWEEN &apos;||PKG_LIST_SELECTPER.LunaAnIni||&apos; AND &apos;||PKG_LIST_SELECTPER.LunaAnFin;
  END IF;
  RETURN vResult;
END;

FUNCTION GetCondArt(pCamp VARCHAR2) RETURN VARCHAR2 IS
  vResult VARCHAR2(2000);
BEGIN
  IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
    vResult := &apos;
    AND &apos;||pCamp||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;
  RETURN vResult;
END;

FUNCTION GetCondGest(pCamp VARCHAR2) RETURN VARCHAR2 IS
  vResult VARCHAR2(2000);
BEGIN
  IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
    vResult := &apos;
    AND &apos;||pCamp||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;
  RETURN vResult;
END;


PROCEDURE processlist (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols :=
    &apos;NARTOBJ NOBJ, NART N, NPART PROD, NPART FURN, NARTAMB AA, NCONT CDOC, NCONT CS, NCONT CD, &apos;||
    &apos;NGEST NGS, NGEST NGD, NAGENDA AGS, NAGENDA AGD, TRANSF T, TRANSF1 T1, IESIRI I, IESIRI1 I1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,    &apos;OEXT&apos;,       &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,    &apos;OATR&apos;,       &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZANOD&apos;,    &apos;ANOD&apos;,       &apos;ANOD.CODANALIZANOD = I1.CODANALIZANOD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;ANALIZA&apos;,       &apos;ANALIZ&apos;,     &apos;ANALIZ.CODANALIZA = ANOD.CODANALIZA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI1&apos;,  &apos;ADESC1&apos;,     &apos;ADESC1.CODDESCRIPTOR1 = ANOD.CODDESCRIPTOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DESCRIPTORI&apos;,   &apos;ADESC&apos;,      &apos;ADESC.CODDESCRIPTOR = ADESC1.CODDESCRIPTOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEG&apos;,       &apos;CGS&apos;,        &apos;CGS.CODCLASEG = NGS.CODCLASA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEG&apos;,       &apos;CGD&apos;,        &apos;CGD.CODCLASEG = NGD.CODCLASA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NACTIVIT&apos;,      &apos;ACTD&apos;,       &apos;ACTD.CODACTIVIT = NGD.CODACTIVIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NACTIVIT&apos;,      &apos;ACTS&apos;,       &apos;ACTS.CODACTIVIT = NGS.CODACTIVIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,         &apos;OPER&apos;,       &apos;OPER.LOGONNAME = COALESCE(I.USERID, T.USERID)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;,&apos;UTILIZATOR&apos;, &apos;UTILIZATOR.CODUTILIZATOR = COALESCE(I.USERID, T.USERID)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;,    &apos;DOC&apos;,        &apos;DOC.CODCARNET = COALESCE(I.CARNETDOC, T.CARNETDOC)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  --PKG_GLOBALS.SETDEBUGMODE(TRUE);

  DELETE FROM tmp_manevra_serii;
  COMMIT;
  IF pkg_list_selectper.AduSerii THEN
    GetNirCuSerii;
    pkg_list_base_utils.BAGA_SERII_IN_TMP;
  END IF;

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NART1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NTVA1_LST;
  PRC_AL_CHECK(&apos;IOART1&apos;);
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);

	sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_TipDoc,DOCUMENT,SeriaDoc,PREFIXDOC,NRDOC,NRI,DATADOC,DENUMIRE,CANTS,CANTD,DEN_UMS,DEN_UMD,CLASA,GEST_SURSA,GEST_DEST,CONT_SURSA,CONT_DEST,
    PUINREGS,PUINREGD,PUACHIZS,PUACHIZD,PMAXS,PMAXD,PRODUCATOR,FURNIZOR,TG,OPERAT,VALINREGS,VALACHIZS,VALINREGD,VALACHIZD,BLOCAT,OBS,
    STORNO,TIPINREG,CODINTERN,CODEXTERN,PROCENT,TIPSERIE,SERII,SEROBS,TVACOLECTAT,SUBUNITATEA,
    UMALT1, UMALT2, S_CANTUM1, S_CANTUM2, S_D1, S_D2, S_D3, D_CANTUM1, D_CANTUM2, D_D1, D_D2, D_D3,
    CLASAS,DEN_CONTS,DEN_CONTD,PROVIZION, ADGESTS, ADGESTD,
    CONT_DOC, PIESDVAL, LOCNIR, LOCLIVR &apos;||gUserFields||&apos;)
  WITH
   surse AS (
    SELECT
      l1.codlivr1,t1.umsec,nsdest.codnirstoc,NSDEST.TIPSERIE ,nsdest.furn,nsdest.tg,nsdest.codnirstocparinte,t1.codcont contdoc, NVL(lv.gest,nir.gest) codgest, io.den_ioart,
      io1.cont,t.codtransf,tt1.codtransf1,tt1.codobiect,nsdest.cantfurn / num1s.paritate cantS,nsdest.cantnir / num1d.paritate cantD, num1s.den_um1 den_um1s,NUM1D.DEN_UM1 DEN_UM1d ,num1s.paritate,
      NVL(NSSURSA.PRET,LV.PRETINREG) * num1s.paritate PUINREGS, nsdest.pret* num1d.paritate PUInregD,
      NVL((NSSURSA.PRET - NSSURSA.ADAOS),LV.PRETACHIZ) * num1s.paritate puAchizS,(NSdest.pret - nsdest.adaos) * num1d.paritate PUACHIZD,
      nssursa.pumaximal pmaxS,nsdest.pumaximal pmaxd,t.subunitatea,T.USERID,L1.CANTUM1,L1.CANTUM2,NSSURSA.D1,NSSURSA.D2,NSSURSA.D3,loc.denumire locatie
    FROM transf t
      inner join transf1 tt1 on tt1.codtransf = t.codtransf
      LEFT JOIN livr l ON l.codtransf = t.codtransf AND l.tiplivr = t.tipdoc
      LEFT JOIN livr1 l1 ON l1.codlivr = l.codlivr and l1.codies1 = tt1.codtransf1
			LEFT JOIN LIVRVAL LV ON L1.CODLIVR1 = LV.CODLIVR1
      LEFT JOIN nirstoc nsdest ON nsdest.codlivr1 = l1.codlivr1
			LEFT JOIN transf1 t1 ON t1.codtransf1 = nsdest.codtransf1
      LEFT JOIN nirstoc nssursa ON nsdest.codnirstocparinte = nssursa.codnirstoc
      LEFT JOIN nir ON nir.codnir = nssursa.codnir
      LEFT JOIN ioart io ON io.codioart = NVL(lv.codioart, nssursa.codioart)
      LEFT JOIN ioart1 io1 on io1.codioart = io.codioart and t.an*12+t.luna between io1.alstart and io1.alstop
			LEFT JOIN num1 num1s on num1s.codum1 = l1.umsec
      LEFT JOIN num1 num1d ON num1d.codum1 = nsdest.umsec
      LEFT JOIN nlocatii loc on loc.codlocatie = nvl(nssursa.codlocatie,0)
    WHERE 1 = 1 &apos;||
    GetCondData(&apos;T&apos;)||
    GetCondArt(&apos;T1.CODOBIECT&apos;)||
    GetCondGest(&apos;NVL(nir.gest,lv.gest)&apos;)||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;),
   dest AS (
    SELECT
      l1.codlivr1,t.codtransf,t1.codtransf1,nir.gest codgest,ns.codioart,io.den_ioart,io1.cont,ns.codnirstoc,t.subunitatea,t.userid,ns.provizion,
      NS.CANTUM1,NS.CANTUM2,NS.D1,NS.D2,NS.D3,loc.denumire locatie
    FROM transf t
      LEFT JOIN transf1 t1 ON t1.codtransf = t.codtransf
      LEFT JOIN nir ON t.codtransf = nir.codtransf
      LEFT JOIN nirstoc ns ON ns.codtransf1 = t1.codtransf1 AND ns.codnir = nir.codnir
      LEFT JOIN ioart io ON ns.codioart = io.codioart
      LEFT JOIN ioart1 io1 on io1.codioart = io.codioart and t.an*12+t.luna between io1.alstart and io1.alstop
      LEFT JOIN livr1 l1 ON ns.codlivr1 = l1.codlivr1
      LEFT JOIN nlocatii loc on loc.codlocatie = nvl(ns.codlocatie,0)
    WHERE 1 = 1 &apos;||
    GetCondData(&apos;T&apos;)||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
    GetCondArt(&apos;T1.CODOBIECT&apos;)||&apos;)
  SELECT
    t.codtransf NAV_CodDoc, t.TIPDOC NAV_TipDoc,
    CASE WHEN t.tipdoc = 12 THEN &apos;&apos;Transf. &apos;&apos; WHEN t.tipdoc = 13 THEN &apos;&apos;Modif. pret &apos;&apos; END ||t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc document,
    t.seriadoc,t.prefixdoc,t.nrdoc, NULL nri, t.datadoc, nobj.denumire,surse.cants,surse.cantd,surse.den_um1s,surse.den_um1d,nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;),
    ngs.den_gest, ngd.den_gest, cs.simbol,cd.simbol, surse.PUInregS, surse.PUInregD, surse.puachizs, surse.puachizd,
    surse.PMAXS, surse.pMaxD, PROD.DEN_PART PRODUCATOR,FURN.DEN_PART FURNIZOR, TMP.TG, decode(t.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat,
    surse.cants * surse.puInregS valInregS, surse.cants * surse.puachizS valAchizS , surse.cantd * surse.puInregD valInregD, surse.cantd * surse.puAchizD ValAchizD,
    decode (t.blocat,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) blocat,t.obs,
    CASE WHEN t.TIPDOC = 12 THEN decode(nvl(t.storno,0),0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) ELSE &apos;&apos;-&apos;&apos; END storno,
    CASE
      WHEN t.TIPDOC &lt;&gt; 13 THEN &apos;&apos;-&apos;&apos;
			WHEN t.TIPMODIFPRET = 0 THEN &apos;&apos;PU inreg. nou fara reevaluare PU achizitie &apos;&apos;
			WHEN t.TIPMODIFPRET = 1 THEN &apos;&apos;PU inreg. nou + reevaluare PU achizitie astfel incat adaos = 0  &apos;&apos;
			WHEN t.TIPMODIFPRET = 2 THEN &apos;&apos;PU inreg. nou + reevaluare PU achizitie numai daca adaos &lt; 0 &apos;&apos;
			WHEN t.TIPMODIFPRET = 3 THEN &apos;&apos;PU achiz. nou fara afectarea PU inregistrare &apos;&apos;
		  ELSE &apos;&apos;-&apos;&apos;
		END tipinreg,
    nobj.codintern,nobj.codextern,NTVA1.PROCENT, decode(SURSE.TIPSERIE,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie, TMP.SERII, TMP.SERII_OBS,
    0 TVACOLECTAT,sub.den_subunit subunitatea,
    UMALT1.DEN_UM, UMALT2.DEN_UM, SURSE.CANTUM1, SURSE.CANTUM2, SURSE.D1, SURSE.D2, SURSE.D3, DEST.CANTUM1, DEST.CANTUM2, DEST.D1, DEST.D2, DEST.D3,
    NCLS.DEN_CLASEAS,
    surse.den_ioart den_conts, dest.den_ioart den_contd,dest.PROVIZION,
    GETADRESA (ags.SECTOR,ags.STRADA,ags.NR1,ags.NR2,ags.BLOC,ags.SCARA,ags.ETAJ,ags.APART,ags.CODPOSTAL) AdGestS,
    GETADRESA (agd.SECTOR,agd.STRADA,agd.NR1,agd.NR2,agd.BLOC,agd.SCARA,agd.ETAJ,agd.APART,agd.CODPOSTAL) AdGestD,
    cdoc.simbol, NULL piesdval, surse.locatie, dest.locatie &apos;||gUserAlias||&apos;
  FROM surse
    LEFT JOIN dest ON dest.codnirstoc = surse.codnirstoc
    LEFT JOIN transf t ON t.codtransf = surse.codtransf
    LEFT JOIN transf1 t1 ON t1.codtransf1 = surse.codtransf1
    LEFT JOIN iesiri i ON i.codies = t.codtransf-t.codtransf
    LEFT JOIN iesiri1 i1 ON i1.codies1 = t.codtransf-t.codtransf
    LEFT JOIN nartobj nobj ON nobj.codobiect = surse.codobiect
    LEFT JOIN nart n ON n.codarticol = nobj.codarticol
    LEFT JOIN NPART PROD ON PROD.CODPART = NOBJ.CODPRODUCATOR
    LEFT JOIN NPART FURN ON FURN.CODPART = SURSE.FURN
    LEFT JOIN nclasea nca ON nca.codclasea = n.clasa
    LEFT JOIN ngest ngs ON ngs.codgest = surse.codgest
    LEFT JOIN ngest ngd ON ngd.codgest = dest.codgest
    LEFT JOIN ncont cs ON cs.codcont = surse.cont
    LEFT JOIN ncont cd ON cd.codcont = dest.cont
    LEFT JOIN nagenda ags ON ags.codgest = ngs.codgest
    LEFT JOIN nagenda agd ON agd.codgest = ngs.codgest
    LEFT JOIN NART1 N1 ON N1.CODARTICOL = N.CODARTICOL AND t.an*12+t.luna between N1.alstart and N1.alstop
    LEFT JOIN NTVA1 NTVA1 on NTVA1.CODTVA = N1.CODTVA AND t.an*12+t.luna between NTVA1.alstart and NTVA1.alstop
    LEFT JOIN NUM UMALT1 ON N.UM1 = UMALT1.CODUM
    LEFT JOIN NUM UMALT2 ON N.UM2 = UMALT2.CODUM
    LEFT JOIN TMP_MANEVRA_SERII TMP ON TMP.CODNIRSTOC = SURSE.CODNIRSTOC
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = SURSE.SUBUNITATEA
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = N.CLASASTATIST
    LEFT JOIN nartamb aa ON aa.codobiect = surse.codobiect AND aa.umsec = surse.umsec
    LEFT JOIN ncont cdoc ON cdoc.codcont = surse.contdoc&apos;||
    gSuplJoins||&apos;
  WHERE 1 = 1 &apos;||
    GetCondData(&apos;t&apos;)||
    GetCondArt(&apos;t1.CODOBIECT&apos;)||
    GetCondGest(&apos;NGS.CODGEST&apos;)||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;,&apos;SUBUNITATEA&apos;)||&apos;
  UNION ALL
  SELECT ------- diminuari si mariri ----
    i.codies NAV_CodDoc, i.tipdoc NAV_TipDoc,
    CASE WHEN l.tiplivr = 14 THEN &apos;&apos;Dimin. &apos;&apos; WHEN l.tiplivr = 15 THEN &apos;&apos;Marire &apos;&apos; END || i.prefixdoc||i.nrdoc||&apos;&apos; / &apos;&apos;||i.datadoc document,
    i.seriadoc,i.prefixdoc,i.nrdoc,i.nri,i.datadoc, nobj.denumire,l1.cant/num1.paritate cants,null cantd,num1.den_um1,null den_um1d,nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;),
    ngs.den_gest, ngd.den_gest, cs.simbol,cd.simbol, nvl(NS.PRET,lv.pretinreg) * num1.paritate PUInreg, nvl(NS.PRET,lv.pretachiz) * num1.paritate pretRec,
    CASE WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * NUM1.PARITATE ELSE LV.PRETACHIZ * NUM1.PARITATE END * num1.paritate puachizs,
    0 puachizd , 0 pmaxs ,ns.pumaximal pmaxd, PROD.DEN_PART PRODUCATOR,FURN.DEN_PART FURNIZOR, TMP.TG, decode(i.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat,
    l1.cant * CASE WHEN LV.CODLIVR1 IS NULL THEN NS.PRET ELSE LV.PRETINREG END valInregS ,
    l1.cant * CASE WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) ELSE LV.PRETACHIZ END ValAchizS, 0 ValInregD,0 ValAchizD,
    decode (i.blocat,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) blocat, i.obs, null storno,
    tc.denumire tipinreg, nobj.codintern,nobj.codextern,ntva1.PROCENT,
    decode(NS.TIPSERIE,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie, TMP.SERII, TMP.SERII_OBS, t1.TVA TVACOLECTAT,SUB.DEN_SUBUNIT SUBUNITATEA,
    UMALT1.DEN_UM, UMALT2.DEN_UM, DECODE(i.TIPDOC,14,L1.CANTUM1,0), DECODE(i.TIPDOC,14,L1.CANTUM2,0), NS.D1, NS.D2, NS.D3, DECODE(i.TIPDOC,15,L1.CANTUM1,0), DECODE(i.TIPDOC,15,L1.CANTUM2,0), NS.D1, NS.D2, NS.D3,
    NCLS.DEN_CLASEAS, io.den_ioart den_consts,io.den_ioart den_constd,NULL PROVIZION,
    GETADRESA (ags.SECTOR,ags.STRADA,ags.NR1,ags.NR2,ags.BLOC,ags.SCARA,ags.ETAJ,ags.APART,ags.CODPOSTAL) AdGestS,
    GETADRESA (agd.SECTOR,agd.STRADA,agd.NR1,agd.NR2,agd.BLOC,agd.SCARA,agd.ETAJ,agd.APART,agd.CODPOSTAL) AdGestD,
    cdoc.simbol, iesval.val/l1.cant*num1.paritate piesval, case when i.tipdoc = 14 then loc.denumire else &apos;&apos;...nedefinita...&apos;&apos; end, 
    case when i.tipdoc = 15 then loc.denumire else &apos;&apos;...nedefinita...&apos;&apos; end &apos;||gUserAlias||&apos;
  FROM iesiri i
    INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    LEFT JOIN transf t ON t.codtransf = i.codies - i.codies
    LEFT JOIN transf1 t1 ON t1.codtransf1 = i.codies - i.codies
    LEFT JOIN livr1 l1 ON l.codlivr = l1.codlivr
    LEFT JOIN (
      SELECT SUM(I1.CANT * I1.PU) VAL, IVL.CODLIVR1
      FROM IESIRI1 I1 INNER JOIN IESVALLINK IVL ON IVL.CODIES1 = I1.CODIES1
      GROUP BY IVL.CODLIVR1
    ) IESVAL ON IESVAL.CODLIVR1 = L1.CODLIVR1
    LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
    LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
    LEFT JOIN iesiri1 i1 ON l1.codies1 = i1.codies1
    LEFT JOIN nir ON nir.codnir = ns.codnir
    LEFT JOIN nartobj nobj ON nobj.codobiect = i1.codobiect
    LEFT JOIN nart n ON n.codarticol = nobj.codarticol
    LEFT JOIN NUM UMALT1 ON N.UM1 = UMALT1.CODUM
    LEFT JOIN NUM UMALT2 ON N.UM2 = UMALT2.CODUM
    LEFT JOIN nclasea nca ON nca.codclasea = n.clasa
    LEFT JOIN ioart io ON io.codioart = NVL(lv.codioart,ns.codioart)
    LEFT JOIN ioart1 io1 ON io1.codioart = io.codioart AND I.an*12+I.luna between IO1.alstart and IO1.alstop
    LEFT JOIN ngest ngs ON ngs.codgest = nvl(nir.gest,lv.gest)
    LEFT JOIN ngest ngd ON ngd.codgest = nvl(nir.gest,lv.gest)
    LEFT JOIN ncont cs ON cs.codcont = io1.cont
    LEFT JOIN ncont cd ON cd.codcont = io1.cont
    LEFT JOIN nagenda ags ON ags.codgest = ngs.codgest
    LEFT JOIN nagenda agd ON agd.codgest = ngs.codgest
    LEFT JOIN num1 on L1.umsec = num1.codum1
    LEFT JOIN NPART PROD ON PROD.CODPART = NOBJ.CODPRODUCATOR
    LEFT JOIN NPART FURN ON FURN.CODPART = NS.FURN
    LEFT JOIN NART1 N1 ON N1.CODARTICOL = N.CODARTICOL AND I.an*12+I.luna between N1.alstart and N1.alstop
    LEFT JOIN NTVA1 NTVA1 on NTVA1.CODTVA = N1.CODTVA AND I.an*12+I.luna between NTVA1.alstart and NTVA1.alstop
    LEFT JOIN TMP_MANEVRA_SERII TMP ON TMP.CODNIRSTOC = NS.CODNIRSTOC
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = i.SUBUNITATEA
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = N.CLASASTATIST
    LEFT JOIN nartamb aa ON aa.codobiect = i1.codobiect AND aa.umsec = i1.umsec
    LEFT JOIN tipchelt tc ON tc.codtipchelt = i.tipchelt
    LEFT JOIN ncont cdoc ON cdoc.codcont = i1.cont
    LEFT JOIN nlocatii loc on loc.codlocatie = nvl(ns.codlocatie,0)&apos;||
    gSuplJoins||&apos;
  WHERE i.tipdoc IN (14,15) &apos;||
    GetCondData(&apos;I&apos;)||
    GetCondArt(&apos;I1.CODOBIECT&apos;)||
    GetCondGest(&apos;NGS.CODGEST&apos;)||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_miscari; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MODIFPRETDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E08FC774E0FC2E3478CB79D5999410819D08CA5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_modifpretdoc IS

  vCodDoc     TRANSF.CODTRANSF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE bagaNirCuSerii IS
BEGIN
  DELETE tmp_manevra_liste
  WHERE filtru = &apos;CODLIVR1&apos;;

  INSERT INTO tmp_manevra_liste(filtru,valoare)
  SELECT &apos;CODLIVR1&apos;,L1.CODLIVR1
  FROM LIVR L INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
  WHERE L.CODTRANSF = vCodDoc ;

  PKG_LIST_BASE_UTILS.BAGA_SERII_IN_TMP(pkg_list_base_utils.CT_MODIFPRET);

END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(500);
  sSelect    VARCHAR2(30000);
  vAux       NUMBER        := PKG_LIST_BASE_UTILS.CT_MODIFPRET;
BEGIN
  gSuplCols := &apos;TRANSF T, TRANSF1 T1, NARTOBJ NAO, NART NA, NUM1 UM, NUM UM1, NUM UM2, NCLASEA NCA, NPART PROD, NGEST NGS, NCONT NCS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  bagaNirCuSerii ;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Document,PrefixDoc,Nrdoc,DataDoc,ART,
    Cant,CantUM1,CantUM2,UM,UMALT1,UMALT2,
    ClasaA,Gest_Sursa,Cont_sursa,CONTDIFPRET,
    PUAchiz_S,PUAchiz_D,PUInreg_S,PUInreg_D,
    PretMax_S,PretMax_D,
    VALACH_S,VALACH_D,VALINREG_S,VALINREG_D,
    Operat, TIPSERIE,
    SERII,DATAEXP,SERIEDATA,
    PROCTVA, PRODUCATOR, PUInregTVA_S, NrUnic&apos;||
    gUserFields||&apos;) &apos;;

  sSelect := &apos;
  WITH tg AS (
    SELECT
      CASE
        WHEN t.tipdoc = 12 THEN &apos;&apos;Transf. &apos;&apos;||t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc
        WHEN t.tipdoc = 13 THEN &apos;&apos;Modif. pret &apos;&apos;||t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc
        ELSE t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc
      END document,
      t.codtransf, t.prefixdoc,t.nrdoc,t.datadoc,decode(t.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat, t.codpart, t.an, t.luna,
      t1.codtransf1, t1.indexlocal, t1.codobiect, t1.umsec, t1.codcont, NVL(lv.gest,n_s.gest) gests, NVL(lv.codioart,ns_s.codioart) codioarts,
      MAX(ns_d.tipserie) tipserie,
      SUM(ns_d.cantnir) cant, SUM(NVL(ns_d.cantum1,0)) cantum1, SUM(NVL(ns_d.cantum2,0)) cantum2,
      MAX(NVL(ns_s.pumaximal,0)) pumaximals, MAX(NVL(ns_d.pumaximal,0)) pumaximald,
      SUM(NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir) valinregs, SUM(NVL(lv.pretachiz, ns_s.pret - ns_s.adaos)*ns_d.cantnir) valachizs,
      SUM(ns_d.pret*ns_d.cantnir) valinregd, SUM((ns_d.pret - ns_d.adaos)*ns_d.cantnir) valachizd,
      SUM(DECODE( nvl(io1s.aretvaneex, 0), 0, NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir, 0)) vpinrtvas_ftva,
      SUM(DECODE( nvl(io1s.aretvaneex, 0), 0, 0, NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir)) vpinrtvas_ctva
    FROM transf t
      INNER JOIN transf1 t1   ON t1.codtransf    = t.codtransf
      INNER JOIN livr    l    ON l.codtransf     = t.codtransf
      INNER JOIN livr1   l1   ON l1.codlivr      = l.codlivr     AND l1.codies1 = t1.codtransf1
      INNER JOIN nartobj nobj ON nobj.codobiect  = t1.codobiect
      LEFT  JOIN nirstoc ns_s ON ns_s.codnirstoc = l1.codnirstoc
      LEFT  JOIN nir     n_s  ON n_s.codnir      = ns_s.codnir
      LEFT  JOIN ioart1  io1s ON io1s.codioart   = ns_s.codioart AND (t.an * 12 + t.luna) between io1s.alstart and io1s.alstop
      LEFT  JOIN livrval lv   on l1.codlivr1     = lv.codlivr1
      INNER JOIN nirstoc ns_d ON ns_d.codlivr1   = l1.codlivr1
      INNER JOIN nir     n_d  ON n_d.codnir = ns_d.codnir
    WHERE L.CODTRANSF =&apos;||vCodDoc||&apos;
    GROUP BY
      t.codtransf, t.tipdoc, t.prefixdoc, t.nrdoc, t.datadoc, t.codpart, t.operat, t.an, t.luna,
      t1.codtransf1, t1.indexlocal, t1.codobiect, t1.umsec, t1.codcont,NVL(lv.gest,n_s.gest), NVL(lv.codioart,ns_s.codioart) )
  SELECT
    tg.document, tg.prefixdoc, tg.nrdoc, tg.datadoc, nao.denumire ,
    tg.cant/um.paritate, tg.cantum1, tg.cantum2, um.den_um1, um1.den_um, um2.den_um,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), ngs.den_gest, ncs.simbol, ncdif.simbol,
    DECODE(tg.cant,0,0,tg.valachizs*um.paritate/tg.cant), DECODE(tg.cant,0,0,tg.valachizd*um.paritate/tg.cant),
    DECODE(tg.cant,0,0,tg.valinregs*um.paritate/tg.cant), DECODE(tg.cant,0,0,tg.valinregd*um.paritate/tg.cant),
    tg.pumaximals*um.paritate, tg.pumaximald*um.paritate,
    tg.valachizs, tg.valachizd, tg.valinregs, tg.valinregd,
    tg.operat, decode(tg.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;),
    NVL(tmp_s.serii,&apos;&apos;-&apos;&apos;),  NVL(tmp_tg.serii,&apos;&apos;-&apos;&apos;),  NVL(tmp_stg.serii,&apos;&apos;-&apos;&apos;),
    tva1.procent, prod.den_part,
    DECODE(tg.cant,0,0,(vpinrtvas_ctva + vpinrtvas_ftva *  (100 + tva1.procent) / 100)*um.paritate/tg.cant),
    rownum &apos;||
    gUserAlias||&apos;
  FROM tg
    LEFT JOIN transf            t       ON t.codtransf   = tg.codtransf
    LEFT JOIN transf1           t1      ON t1.codtransf1 = tg.codtransf1
    LEFT JOIN nartobj           nao     ON nao.codobiect = tg.codobiect
    LEFT JOIN nart              na      ON na.codarticol = nao.codarticol
    LEFT JOIN num1              um      on um.codum1 = tg.umsec
    LEFT JOIN num               um1     on um1.codum = na.um1
    LEFT JOIN num               um2     on um2.codum = na.um2
    LEFT JOIN nclasea           nca     ON nca.codclasea  = na.clasa
    LEFT JOIN nart1             na1     ON na1.codarticol = nao.codarticol AND (tg.an*12+tg.luna) between  na1.alstart and  na1.alstop
    LEFT JOIN ntva1             tva1    ON tva1.codtva    = na1.codtva     AND (tg.an*12+tg.luna) between tva1.alstart and tva1.alstop
    LEFT JOIN npart             prod    ON prod.codpart   = nao.codproducator
    LEFT JOIN ngest             ngs     ON ngs.codgest    = tg.gests
    LEFT JOIN tmp_ioart_luna    io1s    ON io1s.codioart  = tg.codioarts
    LEFT JOIN ncont             ncs     ON ncs.codcont    = io1s.cont
    LEFT JOIN ncont             ncdif   ON ncdif.codcont  = tg.codcont
    LEFT JOIN tmp_manevra_serii tmp_s   ON tmp_s.codnirstoc   = tg.codtransf1 AND tmp_s.codlivr1   = tg.gests AND tmp_s.codaux1   = tg.codioarts AND tmp_s.flag   = &apos;||to_char(vAux)||&apos;
    LEFT JOIN tmp_manevra_serii tmp_tg  ON tmp_tg.codnirstoc  = tg.codtransf1 AND tmp_tg.codlivr1  = tg.gests AND tmp_tg.codaux1  = tg.codioarts AND tmp_tg.flag  = &apos;||to_char(vAux+2000)||&apos;
    LEFT JOIN tmp_manevra_serii tmp_stg ON tmp_stg.codnirstoc = tg.codtransf1 AND tmp_stg.codlivr1 = tg.gests AND tmp_stg.codaux1 = tg.codioarts AND tmp_stg.flag = &apos;||to_char(vAux+1000)||
    gSuplJoins||&apos;
  ORDER BY tg.indexlocal &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  pkg_list_base_transfdoc.ProcessParams(vCodDoc);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_MODIFPRETDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MODIPBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>690AF58EBB659EAA9ED3DEB9F65BAB52589E89B3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_MODIPBCAR is

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(25000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(15000);
  gSuplJoins  VARCHAR2(15000);
  pTipBCAR    NUMBER(10);
  pCodSediu   NUMBER(20);
  pCodPart    NUMBER(20);
  pDataStart  varchar2(50);
  pDataStop   varchar2(50);
  pCodObiect  number(20);
  pObs        varchar2(500);
  
PROCEDURE SETPARAMS(aTipBCAR in NUMBER, aCodSediu in NUMBER, aCodPart in NUMBER, aDataStart in varchar2, aDataStop in varchar2, aCodObiect in number, aObs in varchar2)
IS
BEGIN
  pTipBCAR   := aTipBCAR;
  pCodSediu  := aCodSediu; 
  pCodPart   := aCodPart;
  pDataStart := aDataStart;
  pDataStop  := aDataStop;
  pCodObiect := aCodObiect;
  pObs       := aObs;      
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(10000);
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  gSuplCols := &apos;nartobj o, bcar b&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||
    &apos;(NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,DataDoc,IaUmiditate,IaStraine,IaIncoltit,IaHectolitrica,
      IaGluten,IaFuzaritate,IaCadere,IaDeformare,IaSticlozitate,IaSparturi,NetKg,UtilKg,PretAchiz,
      PretUscare,IaProteina,IaAflatoxina,IaAtac_Plosnita,IaContinut_Ulei,IaAciditate,IaSistave,
      IaRefractie,IaIndice_W,IaToxina_Don,IaBoabe_Toxice,PretLaStas,PretAchizNou, Ordine&apos;||
      gUserFields||&apos;)
  SELECT
    m1.CODBCAR,67,m1.PrefixDoc,m1.NrDoc,m1.DataDoc,m1.IaUmiditate,m1.IaStraine,m1.IaIncoltit,m1.IaHectolitrica,
    m1.IaGluten,m1.IaFuzaritate,m1.IaCadere,m1.IaDeformare,m1.IaSticlozitate,m1.IaSparturi,m1.NetKg,m1.UtilKg,m1.PretAchiz,
    m1.PretUscare,m1.IaProteina,m1.IaAflatoxina,m1.IaAtac_Plosnita,m1.IaContinut_Ulei,m1.IaAciditate,m1.IaSistave,
    m1.IaRefractie,m1.IaIndice_W,m1.IaToxina_Don,m1.IaBoabe_Toxice,m1.PretLaStas,m1.PretAchizNou, 1&apos;||
    gUserAlias||&apos;
  FROM tmp_bcar_man1 m1
    INNER JOIN nartobj o ON o.codobiect = m1.codobiect
    INNER JOIN bcar b ON b.codbcar = m1.codbcar&apos;||
    gSuplJoins||&apos;
   UNION ALL
   SELECT 0 ,67,&apos;&apos;Medie&apos;&apos;,null NrDoc,null DataDoc,m2.IaUmiditate,m2.IaStraine,m2.IaIncoltit,m2.IaHectolitrica,
    m2.IaGluten,m2.IaFuzaritate,m2.IaCadere,m2.IaDeformare,m2.IaSticlozitate,m2.IaSparturi,null NetKg,null UtilKg,null PretAchiz,
    null PretUscare,m2.IaProteina,m2.IaAflatoxina,m2.IaAtac_Plosnita,m2.IaContinut_Ulei,m2.IaAciditate,m2.IaSistave,
    m2.IaRefractie,m2.IaIndice_W,m2.IaToxina_Don,m2.IaBoabe_Toxice,null PretLaStas,null PretAchizNou, 2&apos;||
    gUserAlias||&apos;
  FROM tmp_bcar_man2 m2
    LEFT JOIN nartobj o ON o.codobiect = m2.IaGluten - m2.IaGluten
    LEFT JOIN bcar b ON b.codbcar = m2.IaGluten - m2.IaGluten&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_MODIPBCAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MONETARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5147EDC98A57687C9A5354E08C3E0DAB663C92CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_monetare IS
  vFiltru    VARCHAR2(500):=&apos;&apos;;
  vFiltruArt VARCHAR2(500):=&apos;&apos;;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setFiltre ( pToateArt IN BOOLEAN,
                      pDupaData IN BOOLEAN DEFAULT FALSE,
                      sData     IN VARCHAR2) IS
BEGIN
  vFiltru := &apos;
    WHERE i.tipdoc = 16 AND i.operat = 1 AND i.anulat = 0 &apos;;
  vFiltru := vFiltru||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
  vFiltru := vFiltru||&apos;
      AND nvl(i.initializari,0) = 0 &apos;;
  if pDupaData then
    vFiltru := vFiltru||&apos;
      AND i.datadoc &apos; || sData||&apos; &apos;;
  else
    vFiltru := vFiltru||&apos;
      AND (i.luna + i.an * 12) &apos; || sData||&apos; &apos;;
  end if;
  vFiltru := vFiltru||&apos; AND (COALESCE(N.GEST,LV.GEST) IN (SELECT CODGEST FROM TMP_GESTDEDICATE) OR I1.tiplinie = &apos;&apos;S&apos;&apos; OR I1.tiplinie = &apos;&apos;V&apos;&apos;)&apos;;

  IF NOT pToateArt THEN
    vFiltruArt := &apos;
      AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = I1.CODOBIECT ) &apos;;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect1 VARCHAR2(5000);
  sSelect2 VARCHAR2(5000);
  sCursRef VARCHAR2(100);
  aSitV    NUMBER(1);
  aBancaV  NUMBER(20);
  aMonedaV NUMBER(20);
BEGIN
  gSuplCols := &apos;nartobj nao, nart na, nclasea nca, num1 um, num um1, num um2, pretm p, ngest ng, ncont nc, nsubunit nsub&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;IES&apos;,  &apos;IES.CODIES     = I1.CODIES&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;IES1&apos;, &apos;IES1.CODIES1   = I1.CODIES1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  setFiltre( PKG_LIST_SELINTIES.ToateArt,
             PKG_LIST_SELINTIES.DupaData,
             PKG_LIST_SELINTIES.Perioada
           );

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN sCursRef  := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i1.datadoc )&apos;;
  ELSE sCursRef  := &apos; 1 &apos;;
  END IF;

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, NRDOC, DATADOC, ART, UM, CANT, PRET, VAL, PJTVA,
    VALTVA, VALFARATVA,
    ADAOSUNIT, ADAOSTOT,
    OBSART, CodIntern, CodExtern, PuAchiz, PuMAX, PretV,
    GEST, DenCONT, SimbCONT, DenClasaA, SimbClasaA,
    UM1, UM2, CANT1, CANT2, SERII, GAR, TG, SUBUNITATEA, VALDISC,COMIS, CURS_REF&apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  WITH I1 AS (
    SELECT
      i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.prefixdoc, NVL(i.curs,1) curs, i.an, i.luna,  i.obs obsdoc, i.subunitatea,
      i1.indexlocal, i1.tiplinie, i1.codobiect, i1.umsec, i1.contserv, i1.obs obsart, i1.pu, NVL(i1.tva,0) tvalin, i1.cant cantlin,
      DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,NVL(lv.gest, n.gest),i1.gestact) Gest,
      ROUND(CASE
        WHEN NVL(i1.tva,0) = 0 THEN 0
        WHEN i1.pu * i1.cant = NVL(i1.tva,0) THEN 0
        ELSE NVL(i1.tva,0) / (i1.pu * i1.cant-NVL(i1.tva,0))
      END,2) coef_tva,
      DECODE(i1.tiplinie,&apos;&apos;=&apos;&apos;,SUM(l1.cant),i1.cant) cant,
      SUM(NVL(DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz)*l1.cant,0)) valachiz,
      MAX(NVL(ns.pumaximal,0)) pumaximal, i1.garantie,
      CASE 
        WHEN i1.tiplinie = &apos;&apos;=&apos;&apos; THEN (SELECT io1.cont FROM IOART1 IO1 WHERE IO1.CODIOART = NVL(lv.codioart,ns.codioart) AND (I.AN*12+I.LUNA) BETWEEN IO1.ALStart and IO1.ALStop )
        ELSE i1.contserv
      END CodCont,  
      CASE nvl(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos;) AS vc2_nt))
        ELSE NULL
      END SERII,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nvl(nser.tg,ns.tg))) AS vc2_nt)) tg,
      SUM(l1.cantum1) cantum1, SUM(l1.cantum2) cantum2, i1.codies1, i1.valdiscpret,i1.CODPARTCOMISEMUL
    FROM iesiri i
      INNER JOIN iesiri1 i1   ON i1.codies      = i.codies
      LEFT JOIN livr     l    ON l.codies       = i1.codies
      LEFT JOIN livr1    l1   ON l1.codies1     = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT JOIN livrval  lv   ON lv.codlivr1    = l1.codlivr1
      LEFT JOIN nirstoc  ns   ON ns.codnirstoc  = l1.codnirstoc
      LEFT JOIN nir      n    ON n.codnir       = ns.codnir
      LEFT JOIN nirser   nser ON nser.codnirser = l1.codnirser
      LEFT JOIN nserii   s    on s.codserie     = nser.codserie&apos;||
    vFiltru||vFiltruArt||&apos;
    GROUP BY
      i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.prefixdoc, i.curs, i.an, i.luna, i.subunitatea, i.obs,
      i1.indexlocal, i1.tiplinie, i1.codobiect, i1.umsec, i1.tva, i1.pu, i1.cant,
      i1.garantie, i1.gestact, i1.contserv, i1.obs,i1.codies1,
      lv.codioart, lv.gest, ns.codioart, n.gest, ns.tipserie, i1.valdiscpret,i1.CODPARTCOMISEMUL)
  SELECT
    i1.codies, i1.tipdoc, i1.nrdoc, i1.datadoc, nao.denumire, um.den_um1, i1.cant/um.paritate, i1.pu*um.paritate, i1.pu * i1.cant, i1.coef_tva*100,
    DECODE(i1.cantlin,0,0,i1.cant,i1.tvalin,i1.tvalin*i1.cant/i1.cantlin), i1.pu * i1.cant - DECODE(i1.cantlin,0,0,i1.cant,i1.tvalin,i1.tvalin*i1.cant/i1.cantlin),
    DECODE(i1.cant,0,0, (i1.pu*i1.cant-i1.tvalin-i1.valachiz)/i1.cant*um.paritate), i1.pu* i1.cant- i1.tvalin  - i1.valachiz,
    i1.obsart, nao.codintern, nao.codextern, DECODE(i1.cant,0,0,i1.valachiz*um.paritate/i1.cant), i1.pumaximal, p.lei,
    ng.den_gest, nc.den_cont, nc.simbol, nca.den_clasea, nca.simbol,
    um1.den_um, um2.den_um, i1.cantum1, i1.cantum2, i1.serii, i1.garantie, i1.tg, nsub.den_subunit, i1.VALDISCPRET,coms.den_part,&apos;||sCursRef||gUserAlias||&apos;
  FROM I1
    LEFT JOIN NARTOBJ  NAO  ON nao.codobiect = i1.codobiect
    LEFT JOIN NART     NA   ON na.codarticol = nao.codarticol
    LEFT JOIN NCLASEA  NCA  ON nca.codclasea = na.clasa
    LEFT JOIN NUM1     UM   ON um.codum1 = i1.umsec
    LEFT JOIN NUM      UM1  ON um1.codum = na.um1
    LEFT JOIN NUM      UM2  ON um2.codum = na.um2
    LEFT JOIN pretm    p    ON p.codobiect = i1.codobiect AND p.implicit = 1 AND p.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NGEST    NG   ON ng.codgest  = i1.gest
    LEFT JOIN NCONT    NC   ON nc.codcont  = i1.codcont 
    LEFT JOIN NSUBUNIT NSUB ON nsub.codsubunit = i1.subunitatea
    LEFT JOIN npart coms    on coms.codpart   = i1.CODPARTCOMISEMUL&apos;||
    gSuplJoins;

  sSelect2 := &apos;
  WITH I1 AS (
    SELECT
      i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.contdiscount, i.subunitatea, i.moneda,
      0 CodObiect, 0 UmSec, 
      decode(i1.tiplinie,&apos;&apos;=&apos;&apos;,NVL(lv.gest, n.gest),i1.gestact) gest,
      CASE WHEN i.valdoc = i.valdiscount THEN 0 ELSE i.valdiscount * SUM(I1.PU  * NVL(L1.CANT, I1.CANT)) / (i.valdoc - i.valdiscount) END valdiscg,
      CASE WHEN i.tvadoc = i.tvadiscount THEN 0 ELSE i.tvadiscount * SUM(I1.TVA * NVL(L1.CANT, I1.CANT) / I1.CANT) / (i.tvadoc - i.tvadiscount) END tvadiscg,
      i1.codies1,i1.CODPARTCOMISEMUL  
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies     = i.codies
      LEFT JOIN livr     l  ON l.codies      = i1.codies
      LEFT JOIN livr1    l1 ON l1.codies1    = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT JOIN livrval  lv ON lv.codlivr1   = l1.codlivr1
      LEFT JOIN nirstoc  ns ON ns.codnirstoc = l1.codnirstoc
      LEFT JOIN nir      n  ON n.codnir      = ns.codnir &apos;||
    vFiltru||&apos;
      AND NVL(I.VALDISCOUNT,0) &lt;&gt; 0 AND I1.CANT &lt;&gt; 0
      AND (COALESCE(N.GEST,LV.GEST) IN (SELECT CODGEST FROM TMP_GESTDEDICATE) OR I1.tiplinie = &apos;&apos;S&apos;&apos;)
    GROUP BY i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.valdiscount, i.tvadiscount, i.valdoc, i.tvadoc, i.contdiscount, i.subunitatea, i.moneda, decode(i1.tiplinie,&apos;&apos;=&apos;&apos;,NVL(lv.gest, n.gest),i1.gestact),
             i1.codies1,i1.CODPARTCOMISEMUL
    )
  SELECT
    I1.CODIES, I1.TIPDOC, I1.NRDOC, I1.DATADOC, &apos;&apos;Discount/Majorare&apos;&apos;, M.SIMBOL, 1,
    I1.VALDISCG, I1.VALDISCG,
    DECODE(I1.TVADISCG,0,0,I1.TVADISCG/(I1.VALDISCG - I1.TVADISCG) * 100),
    I1.TVADISCG, I1.VALDISCG - I1.TVADISCG ,
    0, 0,
    NULL, NULL, NULL, 0, 0, NULL,
    NG.DEN_GEST, NC.DEN_CONT, NC.SIMBOL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NSUB.DEN_SUBUNIT, 0, coms.den_part,&apos;||sCursRef||gUserAlias||&apos;
  FROM I1
    LEFT JOIN NARTOBJ  NAO  ON nao.codobiect = i1.codobiect
    LEFT JOIN NART     NA   ON na.codarticol = nao.codarticol
    LEFT JOIN NCLASEA  NCA  ON nca.codclasea = na.clasa
    LEFT JOIN NUM1     UM   ON um.codum1 = i1.umsec
    LEFT JOIN NUM      UM1  ON um1.codum = na.um1
    LEFT JOIN NUM      UM2  ON um2.codum = na.um2
    LEFT JOIN PRETM    P    ON p.codobiect = i1.codobiect AND p.implicit = 1 AND p.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NGEST    NG   ON NG.CODGEST  = I1.GEST
    LEFT JOIN NCONT    NC   ON NC.CODCONT  = I1.CONTDISCOUNT
    LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I1.SUBUNITATEA
    LEFT JOIN NMONEDE  M    ON M.CODMONEDA = I1.MONEDA
    LEFT JOIN npart coms    on coms.codpart   = i1.CODPARTCOMISEMUL&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  IF PKG_LIST_SELINTIES.ToateArt THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer); 
  END IF;
  COMMIT;

END;
 PROCEDURE setJoinuri IS
 BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
 END;
end PKG_LIST_BASE_MONETARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MONETAREMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C655E2FAA463E8A8B63AF73AFF547564920617B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_MONETAREMP IS
  vFiltru    VARCHAR2(500):=&apos;&apos;;
  vFiltruArt VARCHAR2(500):=&apos;&apos;;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
BEGIN
  DELETE tmp_dinamic_cols;
  INSERT INTO tmp_dinamic_cols (FIELDNAME, DISPLAY)
  SELECT &apos;D&apos;||Row_Number() OVER (ORDER BY Display) FieldName, Display
  FROM (
    SELECT DISTINCT Coalesce(REPLACE(mp.denmodplata,&apos; &apos;,&apos;&apos;),&apos;...&apos;) Display
    FROM iesiri i INNER JOIN moduriplati mp ON mp.codies = i.codies
    WHERE i.tipdoc = 16 AND mp.tipplata &lt;&gt; 0 AND Nvl(mp.valoare,0) &lt;&gt; 0
    AND i.an = PKG_GLOBALS.ANLUCRU
    AND i.luna BETWEEN PKG_LIST_SELECTLUNA.LUNASTART AND PKG_LIST_SELECTLUNA.LUNAFIN
  );

  if pkg_list_selectluna.ColFix then
    INSERT INTO tmp_dinamic_cols (FIELDNAME, DISPLAY)
    SELECT &apos;C&apos;||CODCARD, DENUMIRE
    FROM CARDURI
    WHERE CODCARD &gt; 0;  
  end if;

  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;iesiri i&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, NRDOC, DATADOC, VAL, Cash &apos;;

  sSelect := &apos;
  SELECT i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.valdoc, SUM(DECODE(mp.tipplata,0,mp.valoare,0))&apos;;

  FOR vRec IN (SELECT FIELDNAME, DISPLAY FROM tmp_dinamic_cols ORDER BY FIELDNAME)
  LOOP
    IF SUBSTR(VREC.FIELDNAME,1,1) = &apos;D&apos; THEN
      sInsert := sInsert||&apos;, &apos;||vRec.FieldName;
      sSelect := sSelect||&apos;, SUM(CASE WHEN Coalesce(REPLACE(mp.denmodplata,&apos;&apos; &apos;&apos;,&apos;&apos;&apos;&apos;),&apos;&apos;...&apos;&apos;) = &apos;&apos;&apos;||vRec.Display||&apos;&apos;&apos; THEN mp.valoare ELSE 0 END)&apos;;
    END IF;
  END LOOP;
  sInsert:= sInsert||gUserFields||&apos;)&apos;;

  sSelect := sSelect||gUserAlias||&apos;
  FROM iesiri i
    INNER JOIN moduriplati mp ON mp.codies = i.codies&apos;||
    gSuplJoins||&apos;
  WHERE i.tipdoc = 16
    AND i.an = &apos;||PKG_GLOBALS.ANLUCRU||&apos;
    AND i.luna BETWEEN &apos;||PKG_LIST_SELECTLUNA.LUNASTART||&apos; AND &apos;||PKG_LIST_SELECTLUNA.LUNAFIN||&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
  GROUP BY i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.valdoc&apos;||gUserAlias;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  if pkg_list_selectluna.ColFix then
    FOR V_REC IN (SELECT CODCARD FROM CARDURI WHERE CODCARD &gt; 0) LOOP
      EXECUTE IMMEDIATE &apos;UPDATE &apos;||TMPNAME||&apos; T SET C&apos;||V_REC.CODCARD||&apos; = (select M.valoare from modplata2 M where codies = T.NAV_CODDOC AND M.CODCARD = &apos;||V_REC.CODCARD||&apos;)&apos;;  
    END LOOP;
  end if;  
  
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_MONETAREMP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MPCD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA5E9858D216F14F5C0E3AA5AB672614F347B9FE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_mpcd is

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
  CodPretM,
  DenObj,
  Den_CatPret,
  Den_UM,
  Rot,
  Lei,
  Valuta,
  PretNou,
  PretNouV)
  select
    CodPretM,
    DenObj,
    Den_CatPret,
    Den_UM,
    Rot,
    Lei,
    Valuta,
    PretNou,
    PretNouV
  FROM tmp_lst_293&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_MPCD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MPCP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39CAD6D856494F766E31A455DB9C8385F9B2DD3A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_mpcp is

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
  CodPretM,
  DenObj,
  Den_CatPret,
  Den_UM,
  Rot,
  Lei,
  Valuta,
  PretNou,
  PretNouV)
  select
    CodPretM,
    DenObj,
    Den_CatPret,
    Den_UM,
    Rot,
    Lei,
    Valuta,
    PretNou,
    PretNouV
  FROM tmp_lst_292&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_MPCP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MPVD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>722FEF4BA251458C261B3597C6DCC231BAF7349D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_mpvd is

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
  CodPretM,
  DenObj,
  Den_CatPret,
  Den_UM,
  Rot,
  PretReferinta,
  Lei,
  PAdaosLei,
  Valuta,
  PretNou,
  PAdaosNou,
  PretNouV)
  select
    CodPretM,
    DenObj,
    Den_CatPret,
    Den_UM,
    Rot,
    PretReferinta,
    Lei,
    PAdaosLei,
    Valuta,
    PretNou,
    PAdaosNou,
    PretNouV
  FROM tmp_lst_291&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_mpvd;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_MPVP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46F99BEFDDB9538FD2D338C719BA27DCB0BDA3B7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_mpvp IS

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
  CodPretM,
  DenObj,
  Den_CatPret,
  Den_UM,
  Rot,
  PretReferinta,
  Lei,
  PAdaosLei,
  Valuta,
  PretNou,
  PAdaosNou,
  PretNouV)
  select
    CodPretM,
    DenObj,
    Den_CatPret,
    Den_UM,
    Rot,
    PretReferinta,
    Lei,
    PAdaosLei,
    Valuta,
    PretNou,
    PAdaosNou,
    PretNouV
  FROM tmp_lst_290&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_MPVP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6CA85BB7E19E2943419F1D1F1A41D022C4FD482</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ1 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vToateGest    BOOLEAN;
  vToateIoart   BOOLEAN;
  vDataIni      VARCHAR2(10);
  vDataScad     VARCHAR2(10);
  vSubCurenta   BOOLEAN;
  vExtra1       BOOLEAN;
  vExtra2       BOOLEAN;
  vCentralizat  INTEGER;
  vCodProiect   NUMBER(20);
  vCant         NUMBER(20);

function CodProiect return number is
begin
  return vCodProiect;
end;

function Cant return number is
begin
  return vCant;
end;

function SubCurenta return number is
begin
  if vSubCurenta then return 1; else return 0; end if; 
end;  

function AllGest return number is
begin
  if vToateGest then return 1; else return 0; end if;
end;

function AllIOArt return number is 
begin
  if vToateIoart then return 1; else return 0; end if;
end;  

PROCEDURE SETPARAMS(
  pToateGest    IN INTEGER  DEFAULT 1,
  pToateIoart   IN INTEGER  DEFAULT 1,
  pDataIni      IN VARCHAR2 DEFAULT NULL,                          
  pDataScad     IN VARCHAR2 DEFAULT NULL,
  pSubCurenta   IN INTEGER  DEFAULT 1,
  pExtra1       IN INTEGER  DEFAULT 0,                             
  pExtra2       IN INTEGER  DEFAULT 0,
  pCentralizat  IN INTEGER  DEFAULT 0,                             
  pCodJob1      IN NUMBER   DEFAULT 0,
  pCodProiect   IN NUMBER   DEFAULT 0,
  pCant         IN NUMBER   DEFAULT 1                              
) IS
xALS INTEGER;
xALF INTEGER;
BEGIN
  vToateGest    := Coalesce(pToateGest,  1) = 1;
  vToateIoart   := Coalesce(pToateIoart, 1) = 1;
  vDataIni      := pDataIni;
  vDataScad     := pDataScad;
  vSubCurenta   := Coalesce(pSubCurenta, 1) = 1;
  vExtra1       := Coalesce(pExtra1, 1) = 1;
  vExtra2       := Coalesce(pExtra2, 1) = 1;
  vCentralizat  := pCentralizat;
  vCodProiect   := pCodProiect;
  vCant         := pCant;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni, vDataScad, xALS,xALF);
  END IF;
  if vSubCurenta then
    if vToateGest then 
      delete tmp_manevra_liste where filtru = &apos;CODGEST&apos;;
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODGEST&apos;, G.CodGest
      from tmp_subunitdedicate t
           inner join ngest g on g.codsubunit = t.codsubunit
      where pkg_globals.GETSUBUNITATE = 1 or t.codsubunit = pkg_globals.GETSUBUNITATE;
    else
      delete tmp_manevra_liste t
      where filtru = &apos;CODGEST&apos; 
            and not exists (select ts.valoare from tmp_manevra_liste ts, ngest g where ts.valoare = g.codsubunit and tS.filtru = &apos;CODSUBUNIT&apos; and t.valoare = g.codgest);
    end if;
  else
    if vToateGest then 
      delete tmp_manevra_liste where filtru = &apos;CODGEST&apos;;
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODGEST&apos;, G.CodGest
      from tmp_subunitdedicate t
           inner join ngest g on g.codsubunit = t.codsubunit
           inner join tmp_gestdedicate tg on tg.codgest = g.codgest
      where exists (select ts.valoare from tmp_manevra_liste ts where ts.valoare = g.codsubunit and tS.filtru = &apos;CODSUBUNIT&apos;);
    else
      delete tmp_manevra_liste t
      where filtru = &apos;CODGEST&apos; 
            and not exists (select ts.valoare from tmp_manevra_liste ts, ngest g where ts.valoare = g.codsubunit and tS.filtru = &apos;CODSUBUNIT&apos; and t.valoare = g.codgest);
    end if;
  end if;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert                VARCHAR2(20000);
  sSelect                VARCHAR2(30000);
  sWhere                 VARCHAR2( 2000);
  sColMinMax             VARCHAR2(  500):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  vCuNecesarZero         BOOLEAN;
  vAducStocMinMaxGest    BOOLEAN;
  vSelStocReal           VARCHAR2(1500);
  vCond_Subunit_C        VARCHAR2(1000);
  vCond_Subunit_CS       VARCHAR2(1000);
  vCond_Subunit_G        VARCHAR2(1000);
  vUserID                NUMBER(20);
  sFiltruCMD             VARCHAR2(1000);
  sDataIni               VARCHAR2(200);
  sDataFin               VARCHAR2(200);
  sStocMinMaxJoin        VARCHAR2(2000);
  pUsername              VARCHAR2(100);
  pStocExternFirma       VARCHAR2(3000) := pkg_categconst.GetValConstanta(&apos;StocExternFirma&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pStocExternCamp        VARCHAR2( 100) := PKG_LIST_BASE_UTILS.Get_StocExternCamp;
  sSubunitMinMax         VARCHAR2(250);
  sSubunitMinMaxGroupBy  VARCHAR2(250);
BEGIN
  vUserId          := COALESCE(pkg_globals.GETUSERID,0);
  vCond_Subunit_C  := &apos; AND EXISTS (SELECT TMPS.VALOARE FROM TMP_MANEVRA_LISTE TMPS WHERE TMPS.FILTRU = &apos;&apos;CODSUBUNIT&apos;&apos; AND TMPS.VALOARE = C.SUBUNITATEA) &apos;;
  vCond_Subunit_CS := &apos; AND EXISTS (SELECT TMPS.VALOARE FROM TMP_MANEVRA_LISTE TMPS WHERE TMPS.FILTRU = &apos;&apos;CODSUBUNIT&apos;&apos; AND TMPS.VALOARE = C.SubunitSursa) &apos;;
  vCond_Subunit_G  := &apos; AND G.CODSUBUNIT IN (SELECT TMPS.VALOARE FROM TMP_MANEVRA_LISTE TMPS WHERE TMPS.FILTRU = &apos;&apos;CODSUBUNIT&apos;&apos;) &apos;;
  pkg_globals.SetSeparator(&apos;/&apos;);

  gSuplCols := &apos;NARTOBJ NAO, NARTOBJSUBUNIT NAOS, NART NA, NUM NUM, NPART PROD, NCLASEA CLSA, PRETM PM, NGEST GIMP, NPART FURNP, NGEST FURNG&apos;;
  
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_STOCEXTERN&apos;, &apos;TSE&apos;,  &apos;TSE.CODCOMUN = NAO.&apos;||pStocExternCamp);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF InStr(gSuplJoins, &apos;TMP_STOCEXTERN&apos;) &gt; 0 THEN
    SELECT USERNAME INTO pUSERNAME FROM user_users;
    WINMADMIN.PKG_USERFIRME.POPULEAZA_STOCURI_EXTERNE(pUSERNAME,pStocExternFirma,pStocExternCamp);
  END IF;

  vCuNecesarZero      := vExtra1;
  vAducStocMinMaxGest := vExtra2;
  sFiltruCMD          := &apos;&apos;;
  if vCentralizat &gt; 0 then
    sDataIni := &apos;TO_DATE(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
    sDataFin := &apos;TO_DATE(&apos;&apos;&apos;||vDataScad||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
    sFiltruCMD := &apos; AND C1.TERMEN BETWEEN &apos;||sDataIni||&apos; AND &apos;||sDataFin||&apos; &apos;;
  end if;

  sSubunitMinMax := &apos; SUBUNITATE, &apos;;
  sSubunitMinMaxGroupBy := &apos; , SUBUNITATE &apos;;
  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sSubunitMinMax        := &apos; 1 as  SUBUNITATE, &apos;;
    sSubunitMinMaxGroupBy := &apos;&apos;;
  END IF;
  IF NOT vAducStocMinMaxGest THEN
    sStocMinMaxJoin := &apos; LEFT JOIN (
                                    SELECT 0 AS CODS,
                                       CODOBIECT, 
                                       1 as  SUBUNITATE,
                                       SUM (STOCMIN)     AS STOCMIN, 
                                       SUM (STOCMAX)     AS STOCMAX, 
                                       SUM (STOCMED)     AS STOCMED, 
                                       MIN (PROCSTOCMIN) AS PROCSTOCMIN, 
                                       MIN (PROCSTOCMAX) AS PROCSTOCMAX, 
                                       MIN (PROCSTOCMED) AS PROCSTOCMED, 
                                       NULL AS CODGEST 
                                       FROM NARTOBJSUBUNIT NSBN
                                            INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = NSBN.SUBUNITATE AND TMP.FILTRU = &apos;&apos;CODSUBUNIT&apos;&apos;
                                       WHERE  (NSBN.codgest is null or NSBN.codgest = 0)
                                                     AND NSBN.SUBUNITATE  IN (SELECT CodSubunit FROM tmp_subunitdedicate)
                                       GROUP BY  CODOBIECT) NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT &apos;;    

  ELSE
    sStocMinMaxJoin := &apos; LEFT JOIN (SELECT 0 AS CODS,
                                           CODOBIECT, 
                                           SUM (STOCMIN)     AS STOCMIN, 
                                           SUM (STOCMAX)     AS STOCMAX, 
                                           SUM (STOCMED)     AS STOCMED, 
                                           MIN (PROCSTOCMIN) AS PROCSTOCMIN, 
                                           MIN (PROCSTOCMAX) AS PROCSTOCMAX, 
                                           MIN (PROCSTOCMED) AS PROCSTOCMED, 
                                           NULL AS CODGEST 
                                     FROM NARTOBJSUBUNIT NSBN 
                                     WHERE NSBN.CODGEST is NOT NULL &apos;;
   sStocMinMaxJoin := sStocMinMaxJoin || 
              &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = NSBN.CODGEST) &apos;;                              
    /*IF NOT PKG_GLOBALS.GETSUBUNITATE = 1 THEN
          sStocMinMaxJoin := sStocMinMaxJoin || 
              &apos;  AND NSBN.SUBUNITATE = PKG_GLOBALS.GETSUBUNITATE &apos;;                              
    END IF;*/
    sStocMinMaxJoin := sStocMinMaxJoin || 
                         &apos; GROUP BY  CODOBIECT) NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT&apos;;
                                                         
  END IF;

  vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT
      FROM NIRSTOC NS
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST 
        INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect 
      WHERE COALESCE(O.INACTIV,0) = 0 &apos;;
  vSelStocReal := vSelStocReal || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;

  sWhere := &apos;
  WHERE ((
    COALESCE(SR.Cant,0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) - COALESCE(CG.RESTA,0) &lt; COALESCE(NAOS.STOCMIN,0) OR
    COALESCE(SR.Cant,0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) - COALESCE(CG.RESTA,0) &lt; COALESCE(NAOS.STOCMAX,0) ) AND
    COALESCE(SR.Cant,0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) - COALESCE(CG.RESTA,0) &gt;= 0) OR
    COALESCE(SR.Cant,0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) - COALESCE(CG.RESTA,0) &lt; 0
    AND COALESCE(NA.TIPARTICOL,&apos;&apos;0&apos;&apos;) = &apos;&apos;0&apos;&apos; &apos;;

  IF vCuNecesarZero THEN
    sWhere := &apos; WHERE COALESCE(NA.TIPARTICOL,&apos;&apos;0&apos;&apos;) = &apos;&apos;0&apos;&apos; &apos;;
  END IF;
  sWhere := sWhere||&apos; AND COALESCE(NAO.INACTIV,0) = 0 &apos;;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Articol, UM, PretAch, CantAch, PretMedAch,
    Cant,
    Val,
    Sursa, Data, Furn, StocMIN, StocMED, StocMAX, StocReal,
    CantC_CF, CantA_CF, RestA_CF,
    CantC_CC, CantA_CC, RestA_CC,
    CantC_CSERV, CantA_CSERV, RestA_CSERV,
    CantC_CSIn, CantA_CSIn, RestA_CSIn,
    CantC_CSIes, CantA_CSIes, RestA_CSIes,
    CantC_CG, CantA_CG, RestA_CG,
    CantC_CIIn, CantA_CIIn, RestA_CIIn,
    CantC_CIIes, CantA_CIIes, RestA_CIIes,
    CodExtern, CodIntern, Producator, Rezervat,RestCCMat,RestAstept &apos;||gUserFields||&apos;)&apos;;

  DELETE TMP_STOCREAL;
  sSelect := &apos;insert into tmp_stocreal(codobiect,cant) &apos;||vSelStocReal;
  LIST_EXECUTE_IMMEDIATE(sselect, aListID, aListVer);
--  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_STOCREZ;
  sSelect := &apos;insert into tmp_stocrez(codobiect,rezervat) &apos;||&apos;SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
      FROM REZERVATS R
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect
      WHERE COALESCE(R.REST,0) &gt; 0 AND COALESCE(O.INACTIV,0) = 0 &apos;;
  if NOT vToateGest THEN
    sSelect := sSelect||&apos;
      AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;
  sSelect := sSelect||&apos;    GROUP BY NS.CODOBIECT&apos;;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_CMD WHERE USERID = vUserId;
  DELETE TMP_CMDTL WHERE USERID = vUserId;
  delete tmp_manevra_consum;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1 
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect := &apos;insert into tmp_cmdtl(codcmdtl,codobiect,cantc, userid) &apos;||
  &apos;SELECT SEQ_CMDTL_CODCMDTL.nextval,CodObiect, cantc, &apos;||vUserId||&apos;
   from (
   select c1.codobiect, SUM(I1.RESTASTEPTARE) cantc
      FROM COMANDA1 C1
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN INTRLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
           INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L.CODINTR1
           INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND COALESCE(O.INACTIV,0) = 0 AND
            I.TIPFACTURA = 9 AND I.OPERAT = 1 AND I.ANULAT = 0 AND I1.RESTASTEPTARE &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect
      )&apos;;
  EXECUTE IMMEDIATE sSelect;

  --------------------------- materiale din proiecte comenzi client
  sSelect := &apos;insert into tmp_cmd(codobiect,resta,tip,userid) &apos;||
  &apos;select codobiect, sum(COALESCE(cant,0)) resta, &apos;&apos;CCMAT&apos;&apos;,&apos;||vUserId||&apos; from (select pn.codobiect, (c1.cantacceptat-COALESCE(lansari.cant,0)) / pn0.cant * pn.cant cant
    from proiectnod pn
         inner join proiectnod pn0 on pn.codproiect = pn0.codproiect and pn0.nodoriginal = 0
         inner join comanda1 c1 on c1.codproiect = pn.codproiect
         inner join comanda c on c.codcomanda = c1.codcomanda
         left join (select sum(cant) cant, cmdlink.codliniecomanda codcomanda1, c1.codobiect
                    from cmdlink
                         inner join comanda1 c1 on c1.codcomanda1 = cmdlink.codcomanda1
                    group by cmdlink.codliniecomanda, c1.codobiect
                   ) lansari on lansari.codcomanda1 = c1.codcomanda1 and c1.codobiect = lansari.codobiect
    where c.tipdoc = 18 and c.anulat = 0 and c.operat = 1 and COALESCE(C.INCHISA, 0) = 0&apos;||sFiltruCMD||&apos;) group by codobiect&apos;;

  EXECUTE IMMEDIATE sSelect;
  --------------------------------------
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1 
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 18 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1 
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 92 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1 
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 44 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1 
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 44 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_CS||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;,&apos;||vUserId||&apos;
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON C.CodGest = G.CodGest
        INNER JOIN NARTOBJ O ON O.CodObiect = C1.CodObiect
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND COALESCE(O.INACTIV,0) = 0 AND
            C.TipDoc = 43 AND C1.RestAcceptat &gt; 0 &apos;||sFiltruCMD||vCond_Subunit_C||&apos;
      GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT CMDMAT.CodObiect, SUM(CMDMAT.Cant) CantC, SUM(CMDMAT.Cant) CantA, SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;,&apos;||vUserId||&apos;
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53
        AND CMDMAT.Rest &gt; 0 &apos;||vCond_Subunit_C||&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))&apos;||sFiltruCMD||&apos;
      GROUP BY CMDMAT.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
  &apos;SELECT CMDMAT.CodObiect, SUM(CMDMAT.Cant) CantC, SUM(CMDMAT.Cant) CantA, SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;,&apos;||vUserId||&apos;
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0
        AND CMDMAT.Rest &gt; 0 &apos;||vCond_Subunit_C||&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))&apos;||sFiltruCMD||&apos;
      GROUP BY CMDMAT.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect := &apos;insert into tmp_manevra_consum(codobiect,codcomanda1) &apos;||
  &apos;SELECT distinct CMDMAT.CodObiect, c1.codcomanda
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
      WHERE COALESCE(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0
        AND CMDMAT.Rest &gt; 0 &apos;||vCond_Subunit_C||&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))&apos;||sFiltruCMD;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_PRETACH;
  sSelect := &apos;insert into tmp_PRETACH(CODOBIECT,PRETACH,DATAPRET,DEN_PART,SURSA,CANT,CODPART,CODGEST) &apos;||CHR(13)||
    &apos;SELECT CODOBIECT, PRETACH, DATANIR DATAPRET, CASE WHEN I.TIPDOC = 7 THEN S.DEN_GEST ELSE FURN.DEN_PART END DEN_PART, &apos;&apos;STOC&apos;&apos; SURSA, CANT, FURN.CODPART, S.CODGEST &apos;||CHR(13)||
    &apos;FROM ( &apos;||CHR(13)||
    &apos;  SELECT NS.CODOBIECT, &apos;||CHR(13)||
    &apos;         FIRST_VALUE(NS.PRET - COALESCE(NS.ADAOS, 0)) OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) PRETACH, &apos;||CHR(13)||
    &apos;         FIRST_VALUE(N.DATANIR)                  OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) DATANIR, &apos;||CHR(13)||
    &apos;         FIRST_VALUE(N.CODINTR)                  OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) CODINTR, &apos;||CHR(13)||
    &apos;         FIRST_VALUE(NS.CANTNIR)                 OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) CANT, &apos;||CHR(13)||
    &apos;         ROW_NUMBER()                            OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) ROWNR &apos;||CHR(13)||
    &apos;  FROM NIRSTOC NS &apos;||CHR(13)||
    &apos;       INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect &apos;||CHR(13)||
    &apos;       INNER JOIN ( &apos;||CHR(13)||
    &apos;                   SELECT N.CODNIR, N.DATANIR, N.CODINTR, G.CODSUBUNIT &apos;||CHR(13)||
    &apos;                   FROM NIR N &apos;||CHR(13)||
    &apos;                        INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||CHR(13)||
    &apos;                   WHERE TIPNIR IN (1,2,3,4,5,6,7,8,9) AND OPERAT = 1 AND ANULAT = 0 &apos;||CHR(13)||
    &apos;                  ) N ON N.CODNIR = NS.CODNIR &apos;||CHR(13)||
    &apos;  WHERE COALESCE(O.INACTIV,0) = 0 &apos;||CHR(13)||
    &apos;  ) PRET &apos;||CHR(13)||
    &apos;    INNER JOIN INTRARI I ON I.CODINTR = PRET.CODINTR &apos;||CHR(13)||
    &apos;    LEFT JOIN NPART FURN ON FURN.CODPART = I.PARTENER &apos;||CHR(13)||
    &apos;    LEFT JOIN NGEST S ON S.CODGEST = I.CODGESTPROD &apos;||CHR(13)||
    &apos;  WHERE ROWNR = 1 &apos;||CHR(13)||
    &apos;UNION ALL &apos;||CHR(13)||
    &apos;SELECT CODOBIECT, PRETACH, NULL DATAPRET, NULL DEN_PART, &apos;&apos;MED&apos;&apos; SURSA, 0 CANT, 0 CODPART, 0 CODGEST &apos;||CHR(13)||
    &apos;FROM ( &apos;||CHR(13)||
    &apos;  SELECT NS.CODOBIECT, &apos;||CHR(13)||
    &apos;         SUM(NS.CANTNIR * (COALESCE(NS.PRET,0) - COALESCE(NS.ADAOS,0)))/DECODE(SUM(NS.CANTNIR),0,1,SUM(NS.CANTNIR)) PRETACH &apos;||CHR(13)||
    &apos;  FROM NIRSTOC NS &apos;||CHR(13)||
    &apos;       INNER JOIN NIR N ON NS.CODNIR = N.CODNIR&apos;||CHR(13)||
    &apos;       INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect&apos;||CHR(13)||
    &apos;       INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||CHR(13)||
    &apos;  WHERE TIPNIR IN (1,2,3,4,5,6,7,8,9) AND OPERAT = 1 AND ANULAT = 0 AND COALESCE(O.INACTIV,0) = 0 &apos;||CHR(13)||
    &apos;  GROUP BY NS.CODOBIECT &apos;||CHR(13)||
    &apos;  )&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect := &apos;
  SELECT
    NAO.DENUMIRE, NUM.DEN_UM, PA.PRETACH, PA.CANT, PAM.PRETACH,
    CASE
      WHEN COALESCE(SR.Cant, 0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) - COALESCE(CG.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) &gt; 0 then 0
      ELSE -(COALESCE(SR.Cant, 0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) - COALESCE(CG.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0))
    END CANT,
    CASE
      WHEN COALESCE(SR.Cant, 0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CG.RESTA,0) - COALESCE(CSIES.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0) &gt; 0 then 0
      ELSE -(COALESCE(SR.Cant, 0) + COALESCE(CF.RESTA,0) - COALESCE(CC.RESTA,0) - COALESCE(CSERV.RESTA,0) + COALESCE(CSIN.RESTA,0) - COALESCE(CSIES.RESTA,0) - COALESCE(CG.RESTA,0) + COALESCE(CIIN.RESTA,0) - COALESCE(CIIES.RESTA,0)) * COALESCE(PA.PRETACH, 0)
    END VAL,
    PA.SURSA, PA.DATAPRET, PA.DEN_PART FURN&apos;||sColMinMax||&apos;, COALESCE(SR.CANT,0),
    COALESCE(CF.CANTC,0), COALESCE(CF.CANTA,0), COALESCE(CF.RESTA,0),
    COALESCE(CC.CANTC,0), COALESCE(CC.CANTA,0), COALESCE(CC.RESTA,0),
    COALESCE(CSERV.CANTC,0), COALESCE(CSERV.CANTA,0), COALESCE(CSERV.RESTA,0),
    COALESCE(CSIN.CANTC,0), COALESCE(CSIN.CANTA,0), COALESCE(CSIN.RESTA,0),
    COALESCE(CSIES.CANTC,0), COALESCE(CSIES.CANTA,0), COALESCE(CSIES.RESTA,0),
    COALESCE(CG.CANTC,0), COALESCE(CG.CANTA,0), COALESCE(CG.RESTA,0),
    COALESCE(CIIN.CANTC,0), COALESCE(CIIN.CANTA,0), COALESCE(CIIN.RESTA,0),
    COALESCE(CIIES.CANTC,0), COALESCE(CIIES.CANTA,0), COALESCE(CIIES.RESTA,0),
    NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART, SREZ.REZERVAT, COALESCE(CCMat.RestA,0), COALESCE(AST.CANTC,0) &apos;||gUserAlias||&apos;
  FROM NARTOBJ NAO
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    INNER JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN PRETM PM ON PM.CODOBIECT = NAO.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND PM.IMPLICIT = 1
    LEFT JOIN NARTIMPLICITE ARTIMP ON ARTIMP.CODARTICOL = NA.CODARTICOL AND ARTIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
    LEFT JOIN NGEST GIMP ON GIMP.CODGEST = ARTIMP.GESTIMPLICITA
    &apos; || sStocMinMaxJoin || &apos;
    LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN TMP_STOCREZ SREZ ON SRez.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD CCMAT ON CCMAT.CODOBIECT = NAO.CODOBIECT AND CCMAT.TIP = &apos;&apos;CCMAT&apos;&apos; AND CCMAT.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMDTL AST ON NAO.CODOBIECT = AST.CODOBIECT AND AST.USERID = &apos;||vUserId||&apos;
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN TMP_PRETACH PA ON PA.CODOBIECT = NAO.CODOBIECT AND PA.SURSA = &apos;&apos;STOC&apos;&apos;
    LEFT JOIN NPART FURNP ON FURNP.CODPART = PA.CODPART
    LEFT JOIN NGEST FURNG ON FURNG.CODGEST = PA.CODGEST
    LEFT JOIN TMP_PRETACH PAM ON PAM.CODOBIECT = NAO.CODOBIECT AND PAM.SURSA = &apos;&apos;MED&apos;&apos;
    LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA&apos;||
    gSuplJoins||
  sWhere;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

  DELETE TMP_CMD WHERE USERID = vUserId;
  DELETE TMP_CMDTL WHERE USERID = vUserId;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NAPROVIZ1;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6729461621D98C6D86F26B942AE8E852DDD9E8B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ2 IS

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(10000);
  gNullAlias  VARCHAR2(10000);
  gSuplCols   VARCHAR2(10000);
  gSuplJoins  VARCHAR2(10000);

  vToateGest  BOOLEAN;
  vToateIoart BOOLEAN;
  vZiuaIniC   DATE;
  vZiuaFinC   DATE;
  vAnLucru    INTEGER;
  vTipVanz    VARCHAR2(200);
  vZiuaIni    DATE;
  vZiuaFin    DATE;
  vUltAchiz   BOOLEAN;
  vCuTermen   BOOLEAN;
  VTermen     DATE;
  vPeZile     BOOLEAN;
  vNrZile     NUMBER;
  vAfectare   NUMBER;
  vClasa      NUMBER;
  vClasaS     NUMBER;
  vClasaW     NUMBER;
  vProd       NUMBER;
  vZileStoc   NUMBER(5);
  vPeLuni     BOOLEAN;
  vRestCmd    BOOLEAN;
  vDim        BOOLEAN;
  vVanzEmul   BOOLEAN;
  vCuComenzi  NUMBER;
  vCuArtFaraVanz NUMBER;
  vDefalcare   BOOLEAN;
  vAllCls     NUMBER(1);
  vStocuriGest NUMBER(1);

PROCEDURE SETPARAMS(
    pToateGest    IN NUMBER   DEFAULT 1,
    pToateIoart   IN NUMBER   DEFAULT 1,
    pDataCIni     IN VARCHAR2 DEFAULT NULL,
    pDataCFin     IN VARCHAR2 DEFAULT NULL,
    pTipVanz      IN VARCHAR2 DEFAULT NULL,
    pPerVanz      IN NUMBER   DEFAULT 0,
    pDataVIni     IN VARCHAR2 DEFAULT NULL,
    pDataVFin     IN VARCHAR2 DEFAULT NULL,
    pUltAchiz     IN NUMBER   DEFAULT 0,
    pCuTermen     IN NUMBER   DEFAULT 0,
    pTermen       IN VARCHAR2 DEFAULT NULL,
    pPeZile       IN NUMBER   DEFAULT 0,
    pNrZile       IN NUMBER   DEFAULT 0,
    pAfectare     IN NUMBER   DEFAULT 0,
    pClasa        IN NUMBER   DEFAULT 0,
    pClasaS       IN NUMBER   DEFAULT 0,
    pProd         IN NUMBER   DEFAULT 0,
    pZileStoc     IN NUMBER   DEFAULT 0,
    V_CODJOB1     IN NUMBER   DEFAULT 0,
    pPeLuni       IN NUMBER   DEFAULT 0,
    pRestCmd      IN NUMBER   DEFAULT 0,
    pDim          IN NUMBER   DEFAULT 0,
    pVanzEmul     IN NUMBER   DEFAULT 0,
    pClasaW       IN NUMBER   DEFAULT 0,
    pCuComenzi    IN NUMBER   DEFAULT 1,
    pCuArtFaraVanz IN NUMBER  DEFAULT 1,
    pDefalcat     IN NUMBER   DEFAULT 0,
    pAllCls       IN NUMBER   DEFAULT 1,
    pStocuriGest  IN NUMBER   DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vAllCls      := pAllCls;
  vToateGest   := pToateGest  = 1;
  vToateIoart  := pToateIoart = 1;
  vDefalcare   := pDefalcat = 1;
  vZiuaIniC    := To_Date(pDataCIni,&apos;DD.MM.YYYY&apos;);
  vZiuaFinC    := To_Date(pDataCFin,&apos;DD.MM.YYYY&apos;);
  vTipVanz     := pTipVanz;
  vStocuriGest := pStocuriGest;
  vAnLucru     := PKG_GLOBALS.ANLUCRU;
  IF pPerVanz = 1 THEN
    vZiuaIni  := To_Date(pDataVIni,&apos;DD.MM.YYYY&apos;);
    vZiuaFin  := To_Date(pDataVFin,&apos;DD.MM.YYYY&apos;);
  ELSE
    vZiuaIni  := To_Date(&apos;01.&apos;||to_char(extract(month from vZiuaIniC),&apos;00&apos;)||&apos;.&apos;||vAnLucru,&apos;DD.MM.YYYY&apos;);
    vZiuaFin  := Last_Day(to_date(&apos;01.&apos;||to_char(extract(month from vZiuaFinC),&apos;00&apos;)||&apos;.&apos;||vAnLucru,&apos;DD.MM.YYYY&apos;));
  END IF;
  vUltAchiz  := pUltAchiz = 1;
  vCuTermen  := pCuTermen = 1;
  BEGIN
    vTermen    := To_Date(pTermen,&apos;DD.MM.YYYY&apos;);
  EXCEPTION WHEN OTHERS THEN
    vTermen := null;
  END;
  vPeZile    := pPeZile = 1;
  vNrZile    := pNrZile;
  vAfectare  := pAfectare;
  vClasa     := pClasa;
  vClasaS    := pClasaS;
  vClasaW    := pClasaW;
  vProd      := pProd;
  vZileStoc  := pZileStoc;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vZiuaIni, vZiuaFin, xLunaAnIni,xLunaAnFin);
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vZiuaIniC,vZiuaFinC,xLunaAnIni,xLunaAnFin);
    PKG_ORA_LISTS.SET_DATA_DINAMIC(V_CODJOB1,vTermen);
  END IF;
  vPeLuni    := pPeLuni = 1;
  vRestCmd   := pRestCmd = 1;
  vDim       := pDim = 1;
  vVanzEmul  := pVanzEmul = 1;
  vCuComenzi := coalesce(pCuComenzi,1);
  vCuArtFaraVanz := coalesce(pCuArtFaraVanz,1);
END;

FUNCTION GETDIM RETURN BOOLEAN IS
BEGIN
  RETURN VDIM;
END;  

FUNCTION GETVANZEMUL RETURN BOOLEAN IS
BEGIN
  RETURN VVANZEMUL;
END;  

FUNCTION GETPELUNI RETURN BOOLEAN IS
BEGIN
  RETURN VPELUNI;
END;  

FUNCTION GETPEZILE RETURN NUMBER IS
BEGIN
  IF vPeZile THEN RETURN 1; ELSE RETURN 0; END IF;
END;

FUNCTION GETNRZILE RETURN NUMBER IS
BEGIN
  RETURN vNrZile;
END;

FUNCTION GETCUCOMENZI RETURN NUMBER IS
BEGIN
  RETURN vCUCOMENZI;
END;

FUNCTION GETCLASA RETURN NUMBER IS
BEGIN
  RETURN vClasa;
END;

FUNCTION GETCLASAS RETURN NUMBER IS
BEGIN
  RETURN vClasaS;
END;

FUNCTION GETCLASAW RETURN NUMBER IS
BEGIN
  RETURN vClasaW;
END;

FUNCTION GETPROD RETURN NUMBER IS
BEGIN
  RETURN vProd;
END;

FUNCTION GETAFECTARE RETURN NUMBER IS
BEGIN
  RETURN vAfectare;
END;

FUNCTION GETTIPVANZ RETURN VARCHAR2 IS
BEGIN
  RETURN vTipVanz;
END;

FUNCTION GETDATACINI RETURN DATE IS
BEGIN
  RETURN vZiuaIniC;
END;

FUNCTION GETDATACFIN RETURN DATE IS
BEGIN
  RETURN vZiuaFinC;
END;

FUNCTION GETDATAVINI RETURN DATE IS
BEGIN
  RETURN vZiuaIni;
END;

FUNCTION GETDATAVFIN RETURN DATE IS
BEGIN
  RETURN vZiuaFin;
END;

FUNCTION GETALLGEST RETURN NUMBER IS
BEGIN
  IF vToateGest THEN RETURN 1; ELSE RETURN 0; END IF;
END;

FUNCTION GETALLIOART RETURN NUMBER IS
BEGIN
  IF vToateIoart THEN RETURN 1; ELSE RETURN 0; END IF;
END;

FUNCTION GETCUTERMEN RETURN NUMBER IS
BEGIN
  IF vCuTermen THEN RETURN 1; ELSE RETURN 0; END IF;
END;

FUNCTION GETTERMEN RETURN DATE IS
BEGIN
  RETURN vTermen;
END;

FUNCTION GETULTACHIZ RETURN BOOLEAN IS
BEGIN
  return vUltAchiz;
END;

FUNCTION GETRESTCMD RETURN BOOLEAN IS
BEGIN
  return vRestCmd;
END;

FUNCTION ALLCLS RETURN BOOLEAN IS
BEGIN
  return vAllCls = 1;
END;

FUNCTION GETZILESTOC RETURN NUMBER IS
BEGIN
  return vZileStoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(32000);
  sSelect      VARCHAR2( 2000);
  sColMinMax   VARCHAR2(  100):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  vAux         VARCHAR2( 1000):= &apos;&apos;;
  vSelStocReal VARCHAR2( 3000);
  vSelStocInit VARCHAR2( 3000);
  vSelIes_Per  VARCHAR2( 3000);
  vSelIes_Prec VARCHAR2( 3000);
  vSelTr_Per   VARCHAR2( 3000);
  vSelIes_Emul VARCHAR2( 3000);
  vAnPrec      NUMBER(4);
  vLunaPrec    NUMBER(2);
  vNrLuni      INTEGER        := extract(year from vZiuaFin)*12+extract(month from vZiuaFin) - extract(year from vZiuaIni)*12-extract(month from vZiuaIni) +1;
  vNrZilePer   INTEGER        := vZiuaFin - vZiuaIni + 1;
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  vCondSub_C   VARCHAR2(  100);
  vCondSub_CS  VARCHAR2(  100);
  vCondSub_G   VARCHAR2(  100);
  sUltNirstoc  VARCHAR2( 1000);
  vUserID      NUMBER(20);
  sAfectare    VARCHAR2(50):= &apos;&apos;;
  pUsername        VARCHAR2(100);
  pStocExternFirma VARCHAR2(3000) := pkg_categconst.GetValConstanta(&apos;StocExternFirma&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pStocExternCamp  VARCHAR2( 100) := PKG_LIST_BASE_UTILS.Get_StocExternCamp;
  vFiltruTermen    VARCHAR2(1000);
  Luni number(5);
  vAnV number(4);
  vLunaV number(2);
  vZiV number(2);
  sLuna varchar2(3);
  sJoinRestCmd varchar2(1000);
  sJoinSub varchar2(1000);
  vCodIdent varchar2(250);
  oSkema varchar2(100);
  acount number(20);
  vZiuaIniP date;
  vZiuaFinP date;
  vSub number(20);
BEGIN
  if vNrLuni &lt;= 0 then vNrLuni := 1; end if;
  if vNrZilePer &lt;= 0 then vNrZilePer := 1; end if;
  vUserId          := Nvl(pkg_globals.GETUSERID,0);
  vCondSub_C  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  vCondSub_CS := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, &apos;SubunitSursa&apos;);
  vCondSub_G  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);

  delete tmp_stocreal;

  if tmpName &lt;&gt; &apos;TMP_LST_NAPR2&apos; then
    gSuplCols := &apos;NARTOBJ NAO, NART NA, NARTOBJSUBUNIT NAOS, NUM NUM, NPART PROD, NCLASEA CLSA, NCLASEAS CLSAS&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_STOCEXTERN&apos;, &apos;TSE&apos;,  &apos;TSE.CODCOMUN = NAO.&apos;||pStocExternCamp);
    pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
    IF InStr(gSuplJoins, &apos;TMP_STOCEXTERN&apos;) &gt; 0 THEN
      SELECT USERNAME INTO pUSERNAME FROM user_users;
      WINMADMIN.PKG_USERFIRME.POPULEAZA_STOCURI_EXTERNE(pUSERNAME,pStocExternFirma,pStocExternCamp);
    END IF;
  else
    gUserFields := &apos;&apos;;
    gUserAlias  := &apos;&apos;;
    gNullAlias  := &apos;&apos;;
    gSuplCols   := &apos;&apos;;
    gSuplJoins  := &apos;&apos;;
  end if;

  sJoinSub := &apos;&apos;;
  if tmpName = &apos;TMP_LST_NAPR2&apos; then
    vSub := PKG_GLOBALS.GETSUBUNITATE;
    if vSub = 1 then vSub := 2; end if; 
    if vStocuriGest &gt; 0 then
      sJoinSub := &apos;LEFT JOIN (
                     select sum(OBJS.STOCMIN) STOCMIN, sum(OBJS.STOCMED) STOCMED, sum(OBJS.STOCMAX) STOCMAX, OBJS.CODOBIECT
                     from NARTOBJSUBUNIT OBJS, TMP_MANEVRA_LISTE TMP, TMP_GESTDEDICATE TD
                     WHERE TD.CODGEST = TMP.VALOARE AND TMP.FILTRU = &apos;&apos;CODGEST&apos;&apos;
                           AND OBJS.CODGEST = TD.CODGEST
                     GROUP BY OBJS.CODOBIECT
                   ) NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT &apos;||CHR(13);
    else
      sJoinSub := &apos;LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                      and (NAOS.codgest is null or NAOS.codgest = 0)
                                      AND NAOS.SUBUNITATE = &apos;||vSub||CHR(13);
    end if;
  end if;  
  
  if Length(pStocExternFirma) &gt; 0 and tmpName &lt;&gt; &apos;TMP_LST_NAPR2&apos; then
    oSkema := SYS_CONTEXT(&apos;userenv&apos;,&apos;current_schema&apos;);
    WINMADMIN.PKG_USERFIRME.SetGranturiN2(pStocExternFirma,oSkema);
    vZiV := extract(day from vZiuaIni);
    vLunaV := extract(month from vZiuaIni);
    vAnV := extract(year from vZiuaIni) - 1;
    begin
      vZiuaIniP := to_date(LPAD(to_char(vZiV),2,&apos;0&apos;)||&apos;.&apos;||LPAD(to_char(vLunaV),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnV),&apos;dd.mm.yyyy&apos;);
    exception when others then
      vZiuaIniP := Last_day(to_date(&apos;01.&apos;||LPAD(to_char(vLunaV),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnV),&apos;dd.mm.yyyy&apos;));
    end;  

    vZiV := extract(day from vZiuaFin);
    vLunaV := extract(month from vZiuaFin);
    vAnV := extract(year from vZiuaFin) - 1;
    begin
      vZiuaFinP := to_date(LPAD(to_char(vZiV),2,&apos;0&apos;)||&apos;.&apos;||LPAD(to_char(vLunaV),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnV),&apos;dd.mm.yyyy&apos;);
    exception when others then
      vZiuaFinP := Last_day(to_date(&apos;01.&apos;||LPAD(to_char(vLunaV),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAnV),&apos;dd.mm.yyyy&apos;));
    end;

    if vDim then
      vSelIes_Prec  := &apos;
      SELECT O.CODOBIECT, SUM(I1.CANT) CANT, &apos;&apos;IESPREC&apos;&apos;, I1.D1, I1.D2, I1.D3
      FROM &apos;||pStocExternFirma||&apos;.IESIRI I
           INNER JOIN &apos;||pStocExternFirma||&apos;.IESIRI1 I1 ON I1.CODIES = I.CODIES
           INNER JOIN &apos;||pStocExternFirma||&apos;.NARTOBJ OS ON OS.CODOBIECT = I1.CODOBIECT
           INNER JOIN NARTOBJ O ON OS.CODINTERN = O.CODINTERN
      WHERE I.DATADOC BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniP)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinP)||&apos;&apos;&apos;
            AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)
      GROUP BY O.CODOBIECT, I1.D1, I1.D2, I1.D3&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelIes_Prec;  
    else
      vSelIes_Prec  := &apos;
      SELECT O.CODOBIECT, SUM(I1.CANT) CANT, &apos;&apos;IESPREC&apos;&apos;
      FROM &apos;||pStocExternFirma||&apos;.IESIRI I
           INNER JOIN &apos;||pStocExternFirma||&apos;.IESIRI1 I1 ON I1.CODIES = I.CODIES
           INNER JOIN &apos;||pStocExternFirma||&apos;.NARTOBJ OS ON OS.CODOBIECT = I1.CODOBIECT
           INNER JOIN NARTOBJ O ON OS.CODINTERN = O.CODINTERN
      WHERE I.DATADOC BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniP)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinP)||&apos;&apos;&apos;
        AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)
      GROUP BY O.CODOBIECT&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Prec;  
    end if;    
  end if;

  IF PKG_GLOBALS.GETSUBUNITATE = 1 and not vDefalcare THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  pkg_globals.Calculeaza_Luna_Precedenta(Extract(Year from vZiuaIni), Extract(Month from vZiuaIni), vAnPrec, vLunaPrec);
  pkg_globals.SetLunaTemp(Extract(Year from vZiuaIni), Extract(Month from vZiuaIni));
  pkg_globals.SetLunaPrecedenta(vAnPrec, vLunaPrec);

  PKG_LIST_SELFISAMAG.setAllParams(null, null, vZiuaIni, 0, 0, 0);

  if vDim and tmpName &lt;&gt; &apos;TMP_LST_NAPR2&apos; then
    if vDefalcare then
      vSelStocInit := &apos;
      SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT
      FROM V_STOC_INI_NECESAR2 V
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE V.REST &lt;&gt; 0&apos;;

      vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT
      FROM NIRSTOC NS
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NS.REST &lt;&gt; 0&apos;;

      vSelIes_Per  := &apos;
      SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT
      FROM LIVR L
        INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN IESIRI I ON L.CODIES = I.CODIES
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
        AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

      vSelTr_Per := &apos;&apos;;
      if Instr(vTipVanz,&apos;12&apos;) &gt; 0 then
        vSelTr_Per  := &apos;
          SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
            INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
          WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
            AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
      end if;

      IF NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        vAux := &apos;
        AND&apos;;
        IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
        ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
        ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
        END IF;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      IF NOT vToateIOArt THEN
        vAux := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT&apos;;
      vSelStocInit := vSelStocInit ||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT&apos;;
      vSelIes_Per  := vSelIes_Per||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT&apos;;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per  := vSelTr_Per||&apos;
        GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3, G.CODSUBUNIT&apos;;
      end if;

      sJoinRestCmd := &apos;&apos;;
      if vRestCmd then
        sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
      end if;
        
      vFiltruTermen := &apos;&apos;;
      if vCuTermen then
        vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(vTermen)||&apos;&apos;&apos; &apos;;
      end if;

      /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

      PKG_GLOBALS.SetSeparator(&apos;,&apos;);
      DELETE TMP_CMD_TMP;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;, String_Agg(to_char(C.nrdoc)),C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        &apos;||vFiltruTermen||&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;,C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;,C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;,C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;,C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;,C1.D1,C1.D2,C1.D3,C.Subunitatea
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.Subunitatea
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))
      GROUP BY CMDMAT.CodObiect,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CodSubunit)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.Subunitatea
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))
      GROUP BY CMDMAT.CodObiect,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;

      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3,codgest) &apos;||vSelStocReal;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3,codgest) &apos;||vSelStocInit;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3,codgest) &apos;||vSelIes_Per;
      if Length(vSelTr_Per) &gt; 0 then
        EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3,codgest) &apos;||vSelTr_Per;
      end if;

      Luni := 0;
      if vPeLuni then
        for v_rec in (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) .. (extract(year from vZiuaFin)*12+extract(month from vZiuaFin)) loop
          if Luni &gt; 12 then Exit; end if;
          Luni := Luni + 1;
          if v_rec/12 = trunc(v_rec/12) then
            vLunaV := 12;
            vAnV   := v_rec/12 - 1;
          else
            vLunaV := v_rec - trunc(v_rec/12)*12;
            vAnV   := trunc(v_rec/12);
          end if;
          if vLunaV =  1 then sLuna := &apos;Ian&apos;; end if;
          if vLunaV =  2 then sLuna := &apos;Feb&apos;; end if;
          if vLunaV =  3 then sLuna := &apos;Mar&apos;; end if;
          if vLunaV =  4 then sLuna := &apos;Apr&apos;; end if;
          if vLunaV =  5 then sLuna := &apos;Mai&apos;; end if;
          if vLunaV =  6 then sLuna := &apos;Jun&apos;; end if;
          if vLunaV =  7 then sLuna := &apos;Jul&apos;; end if;
          if vLunaV =  8 then sLuna := &apos;Aug&apos;; end if;
          if vLunaV =  9 then sLuna := &apos;Sep&apos;; end if;
          if vLunaV = 10 then sLuna := &apos;Oct&apos;; end if;
          if vLunaV = 11 then sLuna := &apos;Nov&apos;; end if;
          if vLunaV = 12 then sLuna := &apos;Dec&apos;; end if;

          vSelIes_Per  := &apos;
          SELECT I1.CODOBIECT, SUM(L1.CANT) CANT,&apos;&apos;&apos;||sLuna||&apos;&apos;&apos;,I1.D1,I1.D2,I1.D3,G.CODSUBUNIT
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN IESIRI I ON L.CODIES = I.CODIES
            INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
            LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
            LEFT JOIN NGEST G ON G.CODGEST = COALESCE(N.GEST,LV.GEST) &apos;||vCondSub_G||&apos;
          WHERE I.AN*12+I.LUNA = &apos;||to_char(vAnV*12+vLunaV)||&apos;
            AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

          vAux := &apos;&apos;;
          IF NOT vToateGest THEN
            SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
            SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
            vAux := &apos;
            AND&apos;;
            IF    vCateLGest = 0 THEN vAux := vAux||&apos; COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
            ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
            ELSE vAux := vAux||&apos; (COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
            END IF;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;

          IF NOT vToateIOArt THEN
            vAux := &apos;
            AND COALESCE(NS.CODIOART,LV.CODIOART) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;
          vSelIes_Per  := vSelIes_Per||&apos;
          GROUP BY I1.CODOBIECT,I1.D1,I1.D2,I1.D3,G.CODSUBUNIT&apos;;
          EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3,codgest) &apos;||vSelIes_Per;
        end loop;
      end if;

      DELETE TMP_STOCREZ;
      sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat,D1,D2,D3,codgest)
      SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT,NS.D1,NS.D2,NS.D3,G.CODSUBUNIT
      FROM REZERVATS R
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NVL(R.REST,0) &gt; 0&apos;;

      if NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        if vCateLGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
        elsif vCateGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
        else
          sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                                &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
        end if;
      end if;
      if NOT vToateIOArt then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
      end if;
      sSelect := sSelect ||&apos; GROUP BY NS.CODOBIECT,NS.D1,NS.D2,NS.D3,G.CODSUBUNIT&apos;;
      EXECUTE IMMEDIATE sSelect;

      IF vUltAchiz
      THEN sUltNirstoc := &apos;SELECT CODOBIECT,D1,D2,D3,MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT,D1,D2,D3&apos;;
      ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
      END IF;
    else
      vSelStocInit := &apos;
      SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;, NS.D1, NS.D2, NS.D3
      FROM V_STOC_INI_NECESAR2 V
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE V.REST &lt;&gt; 0&apos;;

      vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;, NS.D1, NS.D2, NS.D3
      FROM NIRSTOC NS
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NS.REST &lt;&gt; 0&apos;;

      vSelIes_Per  := &apos;
      SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3
      FROM LIVR L
        INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN IESIRI I ON L.CODIES = I.CODIES
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
        AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

      vSelTr_Per := &apos;&apos;;
      if Instr(vTipVanz,&apos;12&apos;) &gt; 0 then
        vSelTr_Per  := &apos;
          SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
            INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
          WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
            AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
      end if;

      IF NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        vAux := &apos;
        AND&apos;;
        IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
        ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
        ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
        END IF;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      IF NOT vToateIOArt THEN
        vAux := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;
      vSelStocInit := vSelStocInit ||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;
      vSelIes_Per  := vSelIes_Per||&apos;
      GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per  := vSelTr_Per||&apos;
        GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;
      end if;

      sJoinRestCmd := &apos;&apos;;
      if vRestCmd then
        sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
      end if;
        
      vFiltruTermen := &apos;&apos;;
      if vCuTermen then
        vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(vTermen)||&apos;&apos;&apos; &apos;;
      end if;

      /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

      PKG_GLOBALS.SetSeparator(&apos;,&apos;);
      DELETE TMP_CMD_TMP;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;, String_Agg(to_char(C.nrdoc)),C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        &apos;||vFiltruTermen||&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;,C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;,C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;,C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;,C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;,C1.D1,C1.D2,C1.D3
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))
      GROUP BY CMDMAT.CodObiect,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))
      GROUP BY CMDMAT.CodObiect,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3&apos;;
      EXECUTE IMMEDIATE sSelect;

      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelStocReal;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelStocInit;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelIes_Per;
      if Length(vSelTr_Per) &gt; 0 then
        EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelTr_Per;
      end if;

      Luni := 0;
      if vPeLuni then
        for v_rec in (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) .. (extract(year from vZiuaFin)*12+extract(month from vZiuaFin)) loop
          if Luni &gt; 12 then Exit; end if;
          Luni := Luni + 1;
          if v_rec/12 = trunc(v_rec/12) then
            vLunaV := 12;
            vAnV   := v_rec/12 - 1;
          else
            vLunaV := v_rec - trunc(v_rec/12)*12;
            vAnV   := trunc(v_rec/12);
          end if;
          if vLunaV =  1 then sLuna := &apos;Ian&apos;; end if;
          if vLunaV =  2 then sLuna := &apos;Feb&apos;; end if;
          if vLunaV =  3 then sLuna := &apos;Mar&apos;; end if;
          if vLunaV =  4 then sLuna := &apos;Apr&apos;; end if;
          if vLunaV =  5 then sLuna := &apos;Mai&apos;; end if;
          if vLunaV =  6 then sLuna := &apos;Jun&apos;; end if;
          if vLunaV =  7 then sLuna := &apos;Jul&apos;; end if;
          if vLunaV =  8 then sLuna := &apos;Aug&apos;; end if;
          if vLunaV =  9 then sLuna := &apos;Sep&apos;; end if;
          if vLunaV = 10 then sLuna := &apos;Oct&apos;; end if;
          if vLunaV = 11 then sLuna := &apos;Nov&apos;; end if;
          if vLunaV = 12 then sLuna := &apos;Dec&apos;; end if;

          vSelIes_Per  := &apos;
          SELECT I1.CODOBIECT, SUM(L1.CANT) CANT,&apos;&apos;&apos;||sLuna||&apos;&apos;&apos;,I1.D1,I1.D2,I1.D3
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN IESIRI I ON L.CODIES = I.CODIES
            INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
            LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
            LEFT JOIN NGEST G ON G.CODGEST = COALESCE(N.GEST,LV.GEST) &apos;||vCondSub_G||&apos;
          WHERE I.AN*12+I.LUNA = &apos;||to_char(vAnV*12+vLunaV)||&apos;
            AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

          vAux := &apos;&apos;;
          IF NOT vToateGest THEN
            SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
            SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
            vAux := &apos;
            AND&apos;;
            IF    vCateLGest = 0 THEN vAux := vAux||&apos; COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
            ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
            ELSE vAux := vAux||&apos; (COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
            END IF;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;

          IF NOT vToateIOArt THEN
            vAux := &apos;
            AND COALESCE(NS.CODIOART,LV.CODIOART) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;
          vSelIes_Per  := vSelIes_Per||&apos;
          GROUP BY I1.CODOBIECT,I1.D1,I1.D2,I1.D3&apos;;
          EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelIes_Per;
        end loop;
      end if;

      DELETE TMP_STOCREZ;
      sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat,D1,D2,D3)
      SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT,NS.D1,NS.D2,NS.D3
      FROM REZERVATS R
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NVL(R.REST,0) &gt; 0&apos;;

      if NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        if vCateLGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
        elsif vCateGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
        else
          sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                                &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
        end if;
      end if;
      if NOT vToateIOArt then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
      end if;
      sSelect := sSelect ||&apos; GROUP BY NS.CODOBIECT,NS.D1,NS.D2,NS.D3&apos;;
      EXECUTE IMMEDIATE sSelect;

      IF vUltAchiz
      THEN sUltNirstoc := &apos;SELECT CODOBIECT,D1,D2,D3,MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT,D1,D2,D3&apos;;
      ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
      END IF;
    end if;  
  else
    if vDefalcare then
      vSelStocInit := &apos;
      SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;, G.CODSUBUNIT
      FROM V_STOC_INI_NECESAR2 V
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE V.REST &lt;&gt; 0&apos;;

      vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;, G.CODSUBUNIT
      FROM NIRSTOC NS
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NS.REST &lt;&gt; 0&apos;;

      vSelIes_Per  := &apos;
      SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, G.CODSUBUNIT
      FROM LIVR L
        INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN IESIRI I ON L.CODIES = I.CODIES
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
        AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

      vSelTr_Per := &apos;&apos;;
      if Instr(vTipVanz,&apos;12&apos;) &gt; 0 then
        vSelTr_Per  := &apos;
          SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;, G.CODSUBUNIT
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
            INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
          WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
            AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
      end if;

      IF NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        vAux := &apos;
        AND&apos;;
        IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
        ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
        ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
        END IF;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      IF NOT vToateIOArt THEN
        vAux := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT, G.CODSUBUNIT&apos;;
      vSelStocInit := vSelStocInit ||&apos;
      GROUP BY NS.CODOBIECT, G.CODSUBUNIT&apos;;
      vSelIes_Per  := vSelIes_Per||&apos;
      GROUP BY NS.CODOBIECT, G.CODSUBUNIT&apos;;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per  := vSelTr_Per||&apos;
        GROUP BY NS.CODOBIECT, G.CODSUBUNIT&apos;;
      end if;

      sJoinRestCmd := &apos;&apos;;
      if vRestCmd then
        sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
      end if;
        
      vFiltruTermen := &apos;&apos;;
      if vCuTermen then
        vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(vTermen)||&apos;&apos;&apos; &apos;;
      end if;

      /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

      PKG_GLOBALS.SetSeparator(&apos;,&apos;);
      DELETE TMP_CMD_TMP;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;, String_Agg(to_char(C.nrdoc)),C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        &apos;||vFiltruTermen||&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;,C.Subunitatea
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT C1.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
        SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;,C.Subunitatea
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
      GROUP BY C1.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;,C.Subunitatea
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))
      GROUP BY CMDMAT.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CodSubunit)
      SELECT CMDMAT.CodObiect,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
        SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
        SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;,C.Subunitatea
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))
      GROUP BY CMDMAT.CodObiect,C.Subunitatea&apos;;
      EXECUTE IMMEDIATE sSelect;

      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,codgest) &apos;||vSelStocReal;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,codgest) &apos;||vSelStocInit;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,codgest) &apos;||vSelIes_Per;
      if Length(vSelTr_Per) &gt; 0 then
        EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,codgest) &apos;||vSelTr_Per;
      end if;

      Luni := 0;
      if vPeLuni then
        for v_rec in (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) .. (extract(year from vZiuaFin)*12+extract(month from vZiuaFin)) loop
          if Luni &gt; 12 then Exit; end if;
          Luni := Luni + 1;
          if v_rec/12 = trunc(v_rec/12) then
            vLunaV := 12;
            vAnV   := v_rec/12 - 1;
          else
            vLunaV := v_rec - trunc(v_rec/12)*12;
            vAnV   := trunc(v_rec/12);
          end if;
          if vLunaV =  1 then sLuna := &apos;Ian&apos;; end if;
          if vLunaV =  2 then sLuna := &apos;Feb&apos;; end if;
          if vLunaV =  3 then sLuna := &apos;Mar&apos;; end if;
          if vLunaV =  4 then sLuna := &apos;Apr&apos;; end if;
          if vLunaV =  5 then sLuna := &apos;Mai&apos;; end if;
          if vLunaV =  6 then sLuna := &apos;Jun&apos;; end if;
          if vLunaV =  7 then sLuna := &apos;Jul&apos;; end if;
          if vLunaV =  8 then sLuna := &apos;Aug&apos;; end if;
          if vLunaV =  9 then sLuna := &apos;Sep&apos;; end if;
          if vLunaV = 10 then sLuna := &apos;Oct&apos;; end if;
          if vLunaV = 11 then sLuna := &apos;Nov&apos;; end if;
          if vLunaV = 12 then sLuna := &apos;Dec&apos;; end if;

          vSelIes_Per  := &apos;
          SELECT I1.CODOBIECT, SUM(L1.CANT) CANT,&apos;&apos;&apos;||sLuna||&apos;&apos;&apos;,G.CODSUBUNIT
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN IESIRI I ON L.CODIES = I.CODIES
            INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
            LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
            LEFT JOIN NGEST G ON G.CODGEST = COALESCE(N.GEST,LV.GEST) &apos;||vCondSub_G||&apos;
          WHERE I.AN*12+I.LUNA = &apos;||to_char(vAnV*12+vLunaV)||&apos;
            AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

          vAux := &apos;&apos;;
          IF NOT vToateGest THEN
            SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
            SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
            vAux := &apos;
            AND&apos;;
            IF    vCateLGest = 0 THEN vAux := vAux||&apos; COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
            ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
            ELSE vAux := vAux||&apos; (COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
            END IF;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;

          IF NOT vToateIOArt THEN
            vAux := &apos;
            AND COALESCE(NS.CODIOART,LV.CODIOART) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;
          vSelIes_Per  := vSelIes_Per||&apos;
          GROUP BY I1.CODOBIECT,I1.D1,I1.D2,I1.D3,G.CODSUBUNIT&apos;;
          EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,codgest) &apos;||vSelIes_Per;
        end loop;
      end if;

      DELETE TMP_STOCREZ;
      sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat,codgest)
      SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT,G.CODSUBUNIT
      FROM REZERVATS R
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NVL(R.REST,0) &gt; 0&apos;;

      if NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        if vCateLGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
        elsif vCateGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
        else
          sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                                &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
        end if;
      end if;
      if NOT vToateIOArt then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
      end if;
      sSelect := sSelect ||&apos; GROUP BY NS.CODOBIECT,G.CODSUBUNIT&apos;;
      EXECUTE IMMEDIATE sSelect;

      IF vUltAchiz
      THEN sUltNirstoc := &apos;SELECT CODOBIECT,MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT&apos;;
      ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
      END IF;
    else
      vSelStocInit := &apos;
      SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;
      FROM V_STOC_INI_NECESAR2 V
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE V.REST &lt;&gt; 0&apos;;

      vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;
      FROM NIRSTOC NS
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NS.REST &lt;&gt; 0&apos;;

      vSelIes_Per  := &apos;
      SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;
      FROM LIVR L
        INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN IESIRI I ON L.CODIES = I.CODIES
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
        AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

      if vVanzEmul then
        vSelIes_Emul  := &apos;
        SELECT E1.CODOBIECT, SUM(E1.CANT) CANT, &apos;&apos;EMUL&apos;&apos;
        FROM EMULARE1 E1
          INNER JOIN EMULARE E ON E.CODEMULARE = E1.CODEMULARE
          INNER JOIN NGEST G ON G.CODGEST = E1.CODGEST &apos;||vCondSub_G||&apos;
        WHERE E.DATABON BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
          AND NVL(E.PRELUAT, 0) = 0 
          AND NVL(E.FACTURARE, 0) = 0
        GROUP BY E1.CODOBIECT&apos;;
      end if;
      commit;

      vSelTr_Per := &apos;&apos;;
      if Instr(vTipVanz,&apos;12&apos;) &gt; 0 then
        vSelTr_Per  := &apos;
          SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
            INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
          WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
            AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
      end if;

      IF NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        vAux := &apos;
        AND&apos;;
        IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
        ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
        ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
        END IF;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      IF NOT vToateIOArt THEN
        vAux := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
        vSelStocReal := vSelStocReal ||vAux;
        vSelStocInit := vSelStocInit ||vAux;
        vSelIes_Per := vSelIes_Per   ||vAux;
        if Length(vSelTr_Per) &gt; 0 then
          vSelTr_Per := vSelTr_Per   ||vAux;
        end if;
      END IF;

      vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;
      vSelStocInit := vSelStocInit ||&apos;
      GROUP BY NS.CODOBIECT&apos;;
      vSelIes_Per  := vSelIes_Per||&apos;
      GROUP BY NS.CODOBIECT&apos;;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per  := vSelTr_Per||&apos;
        GROUP BY NS.CODOBIECT&apos;;
      end if;

      sJoinRestCmd := &apos;&apos;;
      if vRestCmd then
        sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
      end if;
        
      vFiltruTermen := &apos;&apos;;
      if vCuTermen then
        vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(vTermen)||&apos;&apos;&apos; &apos;;
      end if;

      /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

      PKG_GLOBALS.SetSeparator(&apos;,&apos;);
      DELETE TMP_CMD_TMP;
      
      if vCuComenzi &gt; 0 then
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;, String_Agg(to_char(C.nrdoc))
        FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          &apos;||vFiltruTermen||&apos;
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;
        FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;
        FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;
        FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;
        FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT C1.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantComandat else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end) CantA,
          SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;
        FROM COMANDA1 C1
          INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
          INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
          AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        GROUP BY C1.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT CMDMAT.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
          SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;
        FROM CMDPRODMAT CMDMAT
          INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
          INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
          AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))
        GROUP BY CMDMAT.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
        sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip)
        SELECT CMDMAT.CodObiect,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantC,
          SUM(case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end) CantA,
          SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;
        FROM CMDPRODMAT CMDMAT
          INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
          INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
        WHERE Nvl(C.INCHISA, 0) = 0 AND COALESCE(C1.EXCEPTIONAL,0) = 0
          AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
          AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))
        GROUP BY CMDMAT.CodObiect&apos;;
        EXECUTE IMMEDIATE sSelect;
      end if;
      
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,resta,tip)
      SELECT I1.CodObiect,
        SUM(L1.RestIESVAL) RestA, &apos;&apos;IESNED&apos;&apos;
      FROM LIVR1 L1
        INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
        INNER JOIN IESIRI I ON I.CODIES = L.CODIES
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
        INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||chr(13);
      if NOT vToateGest THEN  
        sSelect := sSelect||&apos;INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = LV.GEST AND FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;||chr(13);
      end if;
      sSelect := sSelect||&apos;
      WHERE I.Operat = 1 AND I.Anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND L1.RestIESVAL &lt;&gt; 0
      GROUP BY I1.CodObiect&apos;;
      commit;
      EXECUTE IMMEDIATE sSelect;

      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelStocReal;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelStocInit;
      EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Per;
      if Length(vSelTr_Per) &gt; 0 then
        EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelTr_Per;
      end if;

      if vVanzEmul then
        EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Emul;
      end if;

      Luni := 0;
      if vPeLuni then
        for v_rec in (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) .. (extract(year from vZiuaFin)*12+extract(month from vZiuaFin)) loop
          if Luni &gt; 12 then Exit; end if;
          Luni := Luni + 1;
          if v_rec/12 = trunc(v_rec/12) then
            vLunaV := 12;
            vAnV   := v_rec/12 - 1;
          else
            vLunaV := v_rec - trunc(v_rec/12)*12;
            vAnV   := trunc(v_rec/12);
          end if;
          if vLunaV =  1 then sLuna := &apos;Ian&apos;; end if;
          if vLunaV =  2 then sLuna := &apos;Feb&apos;; end if;
          if vLunaV =  3 then sLuna := &apos;Mar&apos;; end if;
          if vLunaV =  4 then sLuna := &apos;Apr&apos;; end if;
          if vLunaV =  5 then sLuna := &apos;Mai&apos;; end if;
          if vLunaV =  6 then sLuna := &apos;Jun&apos;; end if;
          if vLunaV =  7 then sLuna := &apos;Jul&apos;; end if;
          if vLunaV =  8 then sLuna := &apos;Aug&apos;; end if;
          if vLunaV =  9 then sLuna := &apos;Sep&apos;; end if;
          if vLunaV = 10 then sLuna := &apos;Oct&apos;; end if;
          if vLunaV = 11 then sLuna := &apos;Nov&apos;; end if;
          if vLunaV = 12 then sLuna := &apos;Dec&apos;; end if;

          vSelIes_Per  := &apos;
          SELECT I1.CODOBIECT, SUM(L1.CANT) CANT,&apos;&apos;&apos;||sLuna||&apos;&apos;&apos;
          FROM LIVR L
            INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
            INNER JOIN IESIRI I ON L.CODIES = I.CODIES
            INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
            LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
            LEFT JOIN NGEST G ON G.CODGEST = COALESCE(N.GEST,LV.GEST) &apos;||vCondSub_G||&apos;
          WHERE I.AN*12+I.LUNA = &apos;||to_char(vAnV*12+vLunaV)||&apos;
            AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

          vAux := &apos;&apos;;
          IF NOT vToateGest THEN
            SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
            SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
            vAux := &apos;
            AND&apos;;
            IF    vCateLGest = 0 THEN vAux := vAux||&apos; COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
            ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
            ELSE vAux := vAux||&apos; (COALESCE(N.GEST,LV.GEST) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
            END IF;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;

          IF NOT vToateIOArt THEN
            vAux := &apos;
            AND COALESCE(NS.CODIOART,LV.CODIOART) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
            vSelIes_Per := vSelIes_Per   ||vAux;
          END IF;
          vSelIes_Per  := vSelIes_Per||&apos;
          GROUP BY I1.CODOBIECT&apos;;
          EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Per;
        end loop;
      end if;

      DELETE TMP_STOCREZ;
      sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat)
      SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
      FROM REZERVATS R
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
      WHERE NVL(R.REST,0) &gt; 0&apos;;

      if NOT vToateGest THEN
        SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        if vCateLGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
        elsif vCateGest = 0 then
          sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
        else
          sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                                &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
        end if;
      end if;
      if NOT vToateIOArt then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
      end if;
      sSelect := sSelect ||&apos; GROUP BY NS.CODOBIECT&apos;;
      EXECUTE IMMEDIATE sSelect;

      IF vUltAchiz
      THEN sUltNirstoc := &apos;SELECT CODOBIECT, MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT&apos;;
      ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
      END IF;
    end if;  
  end if;  

  if tmpName &lt;&gt; &apos;TMP_LST_NAPR2&apos; then
    if vDefalcare then
      sAfectare := &apos;&apos;;
      --if pkg_list_base_naproviz2.GETPEZILE = 1 then
        if pkg_list_base_naproviz2.getafectare = 1 then
          sAfectare := &apos; - NVL(NAOS.STOCMIN,0) &apos;;
        end if;
        if pkg_list_base_naproviz2.getafectare = 2 then
          sAfectare := &apos; - NVL(NAOS.STOCMED,0) &apos;;
        end if;
        if pkg_list_base_naproviz2.getafectare = 3 then
          sAfectare := &apos; - NVL(NAOS.STOCMAX,0) &apos;;
        end if;
      --end if;
      for v_sub in (select t.codsubunit, s.den_subunit
                    from tmp_subunitdedicate t
                         inner join nsubunit s on s.codsubunit = t.codsubunit
                   ) loop
        if vDim then
          INSERT INTO TMP_CMD_TMP(CODOBIECT, TIP, D1, D2, D3)
          SELECT DISTINCT CODOBIECT, &apos;OBJ&apos;, D1, D2, D3
          FROM 
          (SELECT CODOBIECT, D1, D2, D3
           FROM TMP_CMD_TMP
           UNION ALL
           SELECT CODOBIECT, D1, D2, D3 
           FROM TMP_STOCREAL
          );
          sInsert:=
          &apos;INSERT INTO &apos;||tmpName||&apos;(
            CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
            Necesar,
            StocReal,
            CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
            CantC_CF, CantA_CF, RestA_CF,
            CantC_CC, CantA_CC, RestA_CC,
            CantC_CSERV, CantA_CSERV, RestA_CSERV,
            CantC_CSIn, CantA_CSIn, RestA_CSIn,
            CantC_CSIes, CantA_CSIes, RestA_CSIes,
            CantC_CG, CantA_CG, RestA_CG,
            CantC_CIIn, CantA_CIIn, RestA_CIIn,
            CantC_CIIes, CantA_CIIes, RestA_CIIes,
            Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec, D1, D2, D3, CodSubunit, Subunitatea, VanzPrec&apos;||gUserFields||&apos;)
          SELECT
            NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
            COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
            --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,
            GREATEST(CEIL(COALESCE(COALESCE(IP.CANT,0),0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
          sInsert := sInsert||&apos;
            NVL(SR.CANT,0) STOCREAL,
            NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
            NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
            NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
            NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
            NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
            NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
            NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
            NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
            NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
            SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||&apos;,
            TMP.D1, TMP.D2, TMP.D3,&apos;||to_char(v_sub.codsubunit)||&apos;,&apos;&apos;&apos;||v_sub.den_subunit||&apos;&apos;&apos;, IPP.CANT&apos;||gUserAlias||&apos;
          FROM (SELECT CODOBIECT, D1, D2, D3 FROM TMP_CMD_TMP WHERE TIP = &apos;&apos;OBJ&apos;&apos;) TMP 
            INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = TMP.CODOBIECT
            INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
            INNER JOIN NUM ON NUM.CODUM = NA.UM
            LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
            LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
            LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
            LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
            LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
            LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
            LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                          and (NAOS.codgest is null or NAOS.codgest = 0)
                                          AND NAOS.SUBUNITATE = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos; AND SR.D1 = TMP.D1 AND SR.D2 = TMP.D2 AND SR.D3 = TMP.D3 AND SR.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT AND SREZ.D1 = TMP.D1 AND SREZ.D2 = TMP.D2 AND SREZ.D3 = TMP.D3 AND SREZ.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos; AND SI.D1 = TMP.D1 AND SI.D2 = TMP.D2 AND SI.D3 = TMP.D3 AND SI.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.D1 = TMP.D1 AND CF.D2 = TMP.D2 AND CF.D3 = TMP.D3 AND CF.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.D1 = TMP.D1 AND CC.D2 = TMP.D2 AND CC.D3 = TMP.D3 AND CC.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.D1 = TMP.D1 AND CSERV.D2 = TMP.D2 AND CSERV.D3 = TMP.D3 AND CSERV.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.D1 = TMP.D1 AND CSIN.D2 = TMP.D2 AND CSIN.D3 = TMP.D3 AND CSIN.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.D1 = TMP.D1 AND CSIES.D2 = TMP.D2 AND CSIES.D3 = TMP.D3 AND CSIES.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.D1 = TMP.D1 AND CG.D2 = TMP.D2 AND CG.D3 = TMP.D3 AND CG.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.D1 = TMP.D1 AND CIIN.D2 = TMP.D2 AND CIIN.D3 = TMP.D3 AND CIIN.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.D1 = TMP.D1 AND CIIES.D2 = TMP.D2 AND CIIES.D3 = TMP.D3 AND CIIES.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
            LEFT JOIN (select codobiect, sum(cant) cant, tip, D1, D2, D3 from TMP_STOCREAL where tip = &apos;&apos;IES&apos;&apos;  AND CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos; group by codobiect, tip, D1, D2, D3) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
                      AND IP.D1 = TMP.D1 AND IP.D2 = TMP.D2 AND IP.D3 = TMP.D3
            LEFT JOIN (select codobiect, sum(cant) cant, tip, D1, D2, D3 from TMP_STOCREAL where tip = &apos;&apos;IESPREC&apos;&apos; group by codobiect, tip, D1, D2, D3) IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESPREC&apos;&apos;
                      AND IPP.D1 = TMP.D1 AND IPP.D2 = TMP.D2 AND IPP.D3 = TMP.D3          
            LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
            LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
            gSuplJoins||&apos;
          WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
        else
          sInsert:=
          &apos;INSERT INTO &apos;||tmpName||&apos;(
            CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
            Necesar,
            StocReal,
            CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
            CantC_CF, CantA_CF, RestA_CF,
            CantC_CC, CantA_CC, RestA_CC,
            CantC_CSERV, CantA_CSERV, RestA_CSERV,
            CantC_CSIn, CantA_CSIn, RestA_CSIn,
            CantC_CSIes, CantA_CSIes, RestA_CSIes,
            CantC_CG, CantA_CG, RestA_CG,
            CantC_CIIn, CantA_CIIn, RestA_CIIn,
            CantC_CIIes, CantA_CIIes, RestA_CIIes,
            Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec, CodSubunit, Subunitatea, VanzPrec&apos;||gUserFields||&apos;)
          SELECT
            NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
            COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
            --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,
            GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
          sInsert := sInsert||&apos;
            NVL(SR.CANT,0) STOCREAL,
            NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
            NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
            NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
            NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
            NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
            NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
            NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
            NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
            NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
            SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||
            &apos;,&apos;||to_char(v_sub.codsubunit)||&apos;,&apos;&apos;&apos;||v_sub.den_subunit||&apos;&apos;&apos;, IPP.CANT&apos;||gUserAlias||&apos;
          FROM NARTOBJ NAO
            INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
            INNER JOIN NUM ON NUM.CODUM = NA.UM
            LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
            LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
            LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
            LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
            LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
            LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
            LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                          and (NAOS.codgest is null or NAOS.codgest = 0)
                                          AND NAOS.SUBUNITATE = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos; AND SR.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT AND SREZ.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos; AND SI.CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos;
            LEFT JOIN TMP_CMD_TMP CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN TMP_CMD_TMP CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos; 
            LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
            LEFT JOIN (select codobiect, sum(cant) cant, tip from TMP_STOCREAL where tip = &apos;&apos;IES&apos;&apos; AND CODGEST = &apos;||to_char(v_sub.codsubunit)||&apos; group by codobiect, tip) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
            LEFT JOIN (select codobiect, sum(cant) cant, tip from TMP_STOCREAL where tip = &apos;&apos;IESPREC&apos;&apos; group by codobiect, tip) IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESPREC&apos;&apos;
            LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
            LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
            gSuplJoins||&apos;
          WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
        end if;
        if vProd &gt; 0 then
          sInsert := sInsert||&apos; and nao.codproducator = &apos;||to_char(vProd);
        end if;
        if vAllCls = 0 then
          sInsert := sInsert||&apos; and exists (select tmp.valoare from tmp_manevra_liste tmp, nclasea clsx 
                                            where tmp.filtru = &apos;&apos;CODCLASEA&apos;&apos; and tmp.valoare = clsx.codclasea 
                                                  and INSTRB(CLSA.CODIDENT, clsx.codident) = 1) &apos;;
        end if;
        LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
      end loop;  
    else
      sAfectare := &apos;&apos;;
      --if pkg_list_base_naproviz2.GETPEZILE = 1 then
        if pkg_list_base_naproviz2.getafectare = 1 then
          sAfectare := &apos; - NVL(NAOS.STOCMIN,0) &apos;;
        end if;
        if pkg_list_base_naproviz2.getafectare = 2 then
          sAfectare := &apos; - NVL(NAOS.STOCMED,0) &apos;;
        end if;
        if pkg_list_base_naproviz2.getafectare = 3 then
          sAfectare := &apos; - NVL(NAOS.STOCMAX,0) &apos;;
        end if;
      --end if;
      if vDim then
        INSERT INTO TMP_CMD_TMP(CODOBIECT, TIP, D1, D2, D3)
        SELECT DISTINCT CODOBIECT, &apos;OBJ&apos;, D1, D2, D3
        FROM 
        (SELECT CODOBIECT, D1, D2, D3
         FROM TMP_CMD_TMP
         UNION ALL
         SELECT CODOBIECT, D1, D2, D3 
         FROM TMP_STOCREAL
        );
        sInsert:=
        &apos;INSERT INTO &apos;||tmpName||&apos;(
          CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
          Necesar,
          StocReal,
          CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
          CantC_CF, CantA_CF, RestA_CF,
          CantC_CC, CantA_CC, RestA_CC,
          CantC_CSERV, CantA_CSERV, RestA_CSERV,
          CantC_CSIn, CantA_CSIn, RestA_CSIn,
          CantC_CSIes, CantA_CSIes, RestA_CSIes,
          CantC_CG, CantA_CG, RestA_CG,
          CantC_CIIn, CantA_CIIn, RestA_CIIn,
          CantC_CIIes, CantA_CIIes, RestA_CIIes,
          Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec, D1, D2, D3, VanzPrec&apos;||gUserFields||&apos;)
        SELECT
          NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
          COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
          --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,&apos;;
        if pkg_list_base_naproviz2.GETPEZILE = 1 then
          sInsert := sInsert||&apos;
            GREATEST(CEIL(COALESCE(COALESCE(IP.CANT,0),0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
        else
          sInsert := sInsert||&apos;
            GREATEST(CEIL(COALESCE(COALESCE(IP.CANT,0),0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar,&apos;;
        end if;
        sInsert := sInsert||&apos;
          NVL(SR.CANT,0) STOCREAL,
          NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
          NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
          NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
          NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
          NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
          NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
          NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
          NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
          NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
          SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||&apos;,TMP.D1, TMP.D2, TMP.D3, IPP.CANT&apos;||gUserAlias||&apos;
        FROM (SELECT CODOBIECT, D1, D2, D3 FROM TMP_CMD_TMP WHERE TIP = &apos;&apos;OBJ&apos;&apos;) TMP 
          INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = TMP.CODOBIECT
          INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
          INNER JOIN NUM ON NUM.CODUM = NA.UM
          LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
          LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
          LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
          LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
          LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
          LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
          LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                        and (NAOS.codgest is null or NAOS.codgest = 0)
                                        AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
          LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos; AND SR.D1 = TMP.D1 AND SR.D2 = TMP.D2 AND SR.D3 = TMP.D3
          LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT AND SREZ.D1 = TMP.D1 AND SREZ.D2 = TMP.D2 AND SREZ.D3 = TMP.D3
          LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos; AND SI.D1 = TMP.D1 AND SI.D2 = TMP.D2 AND SI.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.D1 = TMP.D1 AND CF.D2 = TMP.D2 AND CF.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.D1 = TMP.D1 AND CC.D2 = TMP.D2 AND CC.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.D1 = TMP.D1 AND CSERV.D2 = TMP.D2 AND CSERV.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.D1 = TMP.D1 AND CSIN.D2 = TMP.D2 AND CSIN.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.D1 = TMP.D1 AND CSIES.D2 = TMP.D2 AND CSIES.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.D1 = TMP.D1 AND CG.D2 = TMP.D2 AND CG.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.D1 = TMP.D1 AND CIIN.D2 = TMP.D2 AND CIIN.D3 = TMP.D3
          LEFT JOIN TMP_CMD_TMP CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.D1 = TMP.D1 AND CIIES.D2 = TMP.D2 AND CIIES.D3 = TMP.D3
          LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
          LEFT JOIN (select codobiect, sum(cant) cant, tip, D1, D2, D3 from TMP_STOCREAL where tip = &apos;&apos;IES&apos;&apos; group by codobiect, tip, D1, D2, D3) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
                    AND IP.D1 = TMP.D1 AND IP.D2 = TMP.D2 AND IP.D3 = TMP.D3
          LEFT JOIN (select codobiect, sum(cant) cant, tip, D1, D2, D3 from TMP_STOCREAL where tip = &apos;&apos;IESPREC&apos;&apos; group by codobiect, tip, D1, D2, D3) IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESPREC&apos;&apos;
                      AND IPP.D1 = TMP.D1 AND IPP.D2 = TMP.D2 AND IPP.D3 = TMP.D3                    
          LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
          LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
          gSuplJoins||&apos;
        WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
      else
        sInsert:=
        &apos;INSERT INTO &apos;||tmpName||&apos;(
          CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
          Necesar,
          StocReal,
          CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
          CantC_CF, CantA_CF, RestA_CF,
          CantC_CC, CantA_CC, RestA_CC,
          CantC_CSERV, CantA_CSERV, RestA_CSERV,
          CantC_CSIn, CantA_CSIn, RestA_CSIn,
          CantC_CSIes, CantA_CSIes, RestA_CSIes,
          CantC_CG, CantA_CG, RestA_CG,
          CantC_CIIn, CantA_CIIn, RestA_CIIn,
          CantC_CIIes, CantA_CIIes, RestA_CIIes,
          Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec, VanzPrec&apos;||gUserFields||&apos;)
        SELECT
          NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
          COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
          --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,&apos;;
        if pkg_list_base_naproviz2.GETPEZILE = 1 then
          sInsert := sInsert||&apos;
            GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
        else
          sInsert := sInsert||&apos;
            GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar,&apos;;
        end if;
        sInsert := sInsert||&apos;
          NVL(SR.CANT,0) STOCREAL,
          NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
          NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
          NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
          NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
          NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
          NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
          NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
          NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
          NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
          SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||&apos;, IPP.CANT&apos;||gUserAlias||&apos;
        FROM NARTOBJ NAO
          INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
          INNER JOIN NUM ON NUM.CODUM = NA.UM
          LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
          LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
          LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
          LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
          LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
          LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
          LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                        and (NAOS.codgest is null or NAOS.codgest = 0)
                                        AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
          LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos;
          LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT
          LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos;
          LEFT JOIN TMP_CMD_TMP CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; 
          LEFT JOIN TMP_CMD_TMP CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; 
          LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
          LEFT JOIN (select codobiect, sum(cant) cant, tip from TMP_STOCREAL where tip = &apos;&apos;IES&apos;&apos; group by codobiect, tip) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
          LEFT JOIN (select codobiect, sum(cant) cant, tip from TMP_STOCREAL where tip = &apos;&apos;IESPREC&apos;&apos; group by codobiect, tip) IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESPREC&apos;&apos;
          LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
          LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
          gSuplJoins||&apos;
        WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
      end if;
      if vProd &gt; 0 then
        sInsert := sInsert||&apos; and nao.codproducator = &apos;||to_char(vProd);
      end if;
      if vAllCls = 0 then
        sInsert := sInsert||&apos; and exists (select tmp.valoare from tmp_manevra_liste tmp, nclasea clsx 
                                          where tmp.filtru = &apos;&apos;CODCLASEA&apos;&apos; and tmp.valoare = clsx.codclasea 
                                                and INSTRB(CLSA.CODIDENT, clsx.codident) = 1) &apos;;
      end if;
      LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
    end if;  
  else
    delete tmp_lst_napr2;
    sAfectare := &apos;&apos;;
    --if pkg_list_base_naproviz2.GETPEZILE = 1 then
      if pkg_list_base_naproviz2.getafectare = 1 then
        sAfectare := &apos; NVL(NAOS.STOCMIN,0) &apos;;
      end if;
      if pkg_list_base_naproviz2.getafectare = 2 then
        sAfectare := &apos; NVL(NAOS.STOCMED,0) &apos;;
      end if;
      if pkg_list_base_naproviz2.getafectare = 3 then
        sAfectare := &apos; NVL(NAOS.STOCMAX,0) &apos;;
      end if;
    --end if;
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      codobiect, codum1, Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
      Necesar,
      StocReal,
      CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
      CantC_CF, CantA_CF, RestA_CF,
      CantC_CC, CantA_CC, RestA_CC,
      CantC_CSERV, CantA_CSERV, RestA_CSERV,
      CantC_CSIn, CantA_CSIn, RestA_CSIn,
      CantC_CSIes, CantA_CSIes, RestA_CSIes,
      CantC_CG, CantA_CG, RestA_CG,
      CantC_CIIn, CantA_CIIn, RestA_CIIn,
      CantC_CIIes, CantA_CIIes, RestA_CIIes,
      Rezervat, UltFurn, UltPrAchiz, CodUltFurn, IesNed &apos;||gUserFields||&apos;)
    SELECT
      nao.codobiect, num1.codum1,NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0) TOTVANZ, CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
      (COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
      --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,&apos;;
    if pkg_list_base_naproviz2.getafectare = 3 then
      if pkg_list_base_naproviz2.GETPEZILE = 1 then
        sInsert := sInsert||&apos;
          case when GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) &gt; &apos;||sAfectare||&apos; then &apos;||sAfectare||&apos; 
               else GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0)
          end Necesar, &apos;||chr(13);
      else
        sInsert := sInsert||&apos;
          case when GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrLuni||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) &gt; &apos;||sAfectare||&apos; then &apos;||sAfectare||&apos;
               else GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrLuni||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0)
          end Necesar,&apos;;
      end if;
    else
      if pkg_list_base_naproviz2.GETPEZILE = 1 then
        sInsert := sInsert||&apos;
          GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + &apos;||sAfectare||&apos; + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
      else
        sInsert := sInsert||&apos;
          GREATEST(CEIL((COALESCE(IP.CANT,0)+NVL(EMUL.CANT,0)) / &apos;||vNrLuni||&apos;) - (NVL(SR.Cant, 0)-NVL(EMUL.CANT,0)) + &apos;||sAfectare||&apos; + NVL(IESNED.RESTA,0) + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar,&apos;;
      end if;
    end if;  
    sInsert := sInsert||&apos;
      NVL(SR.CANT,0)- NVL(EMUL.CANT,0),
      NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
      NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
      NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
      NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
      NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
      NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
      NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
      NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
      NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
      SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), nvl(UF.CODPART,0) CodUltFurn, IESNED.RESTA&apos;||gUserAlias||&apos;
    FROM NARTOBJ NAO
      INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT JOIN NUM1 ON NUM.CODUM = NUM1.CODUM AND NVL(NUM1.SECUNDARA,0) = 0
      LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
      LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
      LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
      LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
      LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT &apos;||chr(13)||
      sJoinSub||chr(13)||&apos;
      LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos;
      LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos;
      LEFT JOIN TMP_CMD_TMP CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; 
      LEFT JOIN TMP_CMD_TMP IESNED ON IESNED.CODOBIECT = NAO.CODOBIECT AND IESNED.TIP = &apos;&apos;IESNED&apos;&apos; 
      LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
      LEFT JOIN (select codobiect, sum(cant) cant from TMP_STOCREAL where tip = &apos;&apos;IES&apos;&apos; group by codobiect) IP ON IP.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN (select codobiect, sum(cant) cant from TMP_STOCREAL where tip = &apos;&apos;EMUL&apos;&apos; group by codobiect) EMUL ON EMUL.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
      LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST
      LEFT JOIN NCLASEAS CLSW ON CLSW.CODCLASEAS = NA.CLASAW &apos;||
      gSuplJoins||&apos;
    WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3)&apos;;
    if vClasa &gt; 0 then
      begin
        select codident into vCodIdent
        from nclasea
        where codclasea = vClasa;
      exception when others then vClasa := 0;
      end;
      if vClasa &gt; 0 then  
        sInsert := sInsert||&apos; and INSTRB(CLSA.CODIDENT, &apos;&apos;&apos;||vCodIdent||&apos;&apos;&apos;) = 1 &apos;;
      end if;
    end if;
    if vClasaS &gt; 0 then
      begin
        select codident into vCodIdent
        from nclaseas
        where codclaseas = vClasaS;
      exception when others then vClasaS := 0;
      end;
      if vClasas &gt; 0 then  
        sInsert := sInsert||&apos; and INSTRB(CLSAS.CODIDENT, &apos;&apos;&apos;||vCodIdent||&apos;&apos;&apos;) = 1 &apos;;
      end if;
    end if;
    if vClasaW &gt; 0 then
      begin
        select codident into vCodIdent
        from nclaseaS
        where codclaseas = vClasaW;
      exception when others then vClasaW := 0;
      end;
      if vClasaW &gt; 0 then  
        sInsert := sInsert||&apos; and INSTRB(CLSW.CODIDENT, &apos;&apos;&apos;||vCodIdent||&apos;&apos;&apos;) = 1 &apos;;
      end if;
    end if;
    if vProd &gt; 0 then
      sInsert := sInsert||&apos; and NAO.CodProducator = &apos;||vProd;
    end if;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  end if;
  
  if tmpName = &apos;TMP_LST_NAPR2&apos; and coalesce(vCuArtFaraVanz,0) &lt;&gt; 1 then
    execute immediate &apos;delete TMP_LST_NAPR2 where coalesce(totvanz,0) = 0&apos;;
    COMMIT;
  end if;

  --DELETE TMP_CMD WHERE USERID = VUSERID;
  if PKG_LIST_BASE_NAPROVIZ2.GetZileStoc &gt; 0 then
    CalculeazaZileStoc(tmpName);
  end if;

  select
    (extract(year from vZiuaFin)*12+extract(month from vZiuaFin)) - (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) + 1
  into Luni
  from dual;

  if vPeLuni and tmpName &lt;&gt; &apos;TMP_LST_NAPR2&apos; then
    execute immediate &apos;update &apos;||tmpName||&apos; set luni = &apos;||Luni;
    if (extract(year from vZiuaIni)*12+extract(month from vZiuaIni))/12 = trunc((extract(year from vZiuaIni)*12+extract(month from vZiuaIni))/12) then
      vLunaV := 12;
      vAnV   := (extract(year from vZiuaIni)*12+extract(month from vZiuaIni))/12 - 1;
    else
      vLunaV := (extract(year from vZiuaIni)*12+extract(month from vZiuaIni)) - trunc((extract(year from vZiuaIni)*12+extract(month from vZiuaIni))/12)*12;
      vAnV   := trunc((extract(year from vZiuaIni)*12+extract(month from vZiuaIni))/12);
    end if;
    Luni := 0;
    Loop
      Luni := Luni + 1;
      if Luni &gt; 12 then Exit; end if;
      if vDim then
        if vLunaV =  1 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Ian = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Ian&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Ian = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Ian&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  2 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Feb = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Feb&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Feb = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Feb&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  3 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mar = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mar&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mar = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mar&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  4 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Apr = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Apr&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Apr = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Apr&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  5 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mai = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mai&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mai = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mai&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  6 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jun = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jun&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jun = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jun&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  7 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jul = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jul&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jul = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jul&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  8 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Aug = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Aug&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Aug = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Aug&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  9 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Sep = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Sep&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Sep = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Sep&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 10 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Oct = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Oct&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Oct = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Oct&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 11 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Nov = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Nov&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Nov = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Nov&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 12 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Dec = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Dec&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3 and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Dec = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Dec&apos;&apos; and tmp.codobiect = t.codobiect and t.d1 = tmp.d1 and t.d2 = tmp.d2 and t.d3 = tmp.d3),0)&apos;;
          end if;  
          COMMIT;
        end if;
      else
        if vLunaV =  1 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Ian = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Ian&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Ian = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Ian&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  2 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Feb = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Feb&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Feb = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Feb&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  3 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mar = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mar&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mar = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mar&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  4 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Apr = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Apr&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Apr = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Apr&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  5 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mai = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mai&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Mai = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Mai&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  6 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jun = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jun&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jun = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jun&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  7 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jul = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jul&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Jul = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Jul&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  8 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Aug = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Aug&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Aug = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Aug&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV =  9 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Sep = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Sep&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Sep = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Sep&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 10 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Oct = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Oct&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Oct = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Oct&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 11 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Nov = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Nov&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Nov = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Nov&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
        if vLunaV = 12 then
          if vDefalcare then
            execute immediate &apos;update &apos;||tmpName||&apos; t set Dec = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Dec&apos;&apos; and tmp.codobiect = t.codobiect and tmp.codgest = t.codsubunit),0)&apos;;
          else
            execute immediate &apos;update &apos;||tmpName||&apos; t set Dec = NVL((select sum(nvl(tmp.cant,0)) from tmp_stocreal tmp where tmp.tip = &apos;&apos;Dec&apos;&apos; and tmp.codobiect = t.codobiect),0)&apos;;
          end if;  
          COMMIT;
        end if;
      end if;  
      vLunaV := vLunaV + 1;
      if vLunaV = 13 then
        vLunaV := 1;
        vAnV   := vAnV + 1; 
      end if;
    end loop;
  end if;
END;

PROCEDURE CalculeazaZileStoc(tmpName IN VARCHAR2) IS
aCount number(5);
aZi date;
StocP number(20,7);
Intrari number(20,7);
Iesiri number(20,7);
vSel varchar2(20000);
vAux varchar2(1000);
vCateGest number(5);
vCateLGest number(5);
BEGIN
  --vZiuaIni := to_date(&apos;01.07.2008&apos;,&apos;dd.mm.yyyy&apos;);
  --vZiuaFin := to_date(&apos;31.07.2008&apos;,&apos;dd.mm.yyyy&apos;);
  for v_obj in (select o.codobiect
                from nartobj o
                     inner join nart a on a.codarticol = o.codarticol
                where a.tiparticol = &apos;0&apos;-- and o.codobiect = 5010
                ) loop
    if vDefalcare then             
      for v_sub in (select t.codsubunit, s.den_subunit
                    from tmp_subunitdedicate t
                         inner join nsubunit s on s.codsubunit = t.codsubunit
                   ) loop
        aCount := 0;
        aZi := vZiuaIni;
        while aZi &lt;= vZiuaFin loop
          if aZi = vZiuaIni then
            begin
              select nvl(cant,0) into StocP
              from tmp_stocreal where codobiect = v_obj.codobiect and tip = &apos;INIT&apos;;
            exception when others then StocP := 0;
            end;
          end if;
          -- intrari in zi
          vSel :=
          &apos;SELECT
             SUM(CASE
               WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
               ELSE NSE.CANTNIR
             END)
           FROM
             NIRSTOC NS
             INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
             INNER JOIN NGEST G ON G.CODGEST = N.GEST
             LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
           WHERE
             N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 15) AND  N.ANULAT = 0 AND N.OPERAT = 1
             AND N.DATANIR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
             AND G.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
             AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
          IF NOT vToateGest THEN
            SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
            SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
            vAux := &apos;
            AND&apos;;
            IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
            ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
            ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
            END IF;
            vSel := vSel||vAux;
          END IF;

          IF NOT vToateIOArt THEN
            vAux := &apos;
            AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
            vSel := vSel||vAux;
          END IF;
          begin
            execute immediate vSel into Intrari;
          exception when others then Intrari := 0;
          end;
          if Intrari is null then Intrari := 0; end if;
          -- iesiri in zi
          vSel :=
          &apos;SELECT
             sum(CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END)
           FROM
             LIVR1 L1
             INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
             INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
             INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
             INNER JOIN NGEST G ON G.CODGEST = N.GEST
             LEFT JOIN NIRSER NE ON L1.CODNIRSER = NE.CODNIRSER
           WHERE
             L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
             L.DATALIVR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
             AND G.CODSUBUNIT = &apos;||to_char(v_sub.codsubunit)||&apos;
             AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
          vSel := vSel||vAux;
          begin
            execute immediate vSel into Iesiri;
          exception when others then Iesiri := 0;
          end;
          if Iesiri is null then Iesiri := 0; end if;
          if Intrari &gt; 0 then aCount := aCount + 1;
          else
            if Iesiri &gt; 0 then aCount := aCount + 1;
            else if StocP &gt; 0 then aCount := aCount + 1; end if;
            end if;
          end if;
          StocP := StocP + Intrari - Iesiri;
          aZi := aZi + 1;
        end loop;
        execute immediate &apos;update &apos;||tmpName||&apos; set nrzile = &apos;||aCount||&apos; where codobiect = &apos;||v_obj.codobiect||&apos; and codsubunit = &apos;||to_char(v_sub.codsubunit);
        commit;
      end loop;  
    else
      aCount := 0;
      aZi := vZiuaIni;
      while aZi &lt;= vZiuaFin loop
        if aZi = vZiuaIni then
          begin
            select nvl(cant,0) into StocP
            from tmp_stocreal where codobiect = v_obj.codobiect and tip = &apos;INIT&apos;;
          exception when others then StocP := 0;
          end;
        end if;
        -- intrari in zi
        vSel :=
        &apos;SELECT
           SUM(CASE
             WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
             ELSE NSE.CANTNIR
           END)
         FROM
           NIRSTOC NS
           INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
           INNER JOIN NGEST G ON G.CODGEST = N.GEST
           LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
         WHERE
           N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 15) AND  N.ANULAT = 0 AND N.OPERAT = 1
           AND N.DATANIR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
           AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE)
           AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
        IF NOT vToateGest THEN
          SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
          SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
          vAux := &apos;
          AND&apos;;
          IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
          ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
          ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
          END IF;
          vSel := vSel||vAux;
        END IF;

        IF NOT vToateIOArt THEN
          vAux := &apos;
          AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
          vSel := vSel||vAux;
        END IF;
        begin
          execute immediate vSel into Intrari;
        exception when others then Intrari := 0;
        end;
        if Intrari is null then Intrari := 0; end if;
        -- iesiri in zi
        vSel :=
        &apos;SELECT
           sum(CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END)
         FROM
           LIVR1 L1
           INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
           INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
           INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
           INNER JOIN NGEST G ON G.CODGEST = N.GEST
           LEFT JOIN NIRSER NE ON L1.CODNIRSER = NE.CODNIRSER
         WHERE
           L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
           L.DATALIVR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
           AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE)
           AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
        vSel := vSel||vAux;
        begin
          execute immediate vSel into Iesiri;
        exception when others then Iesiri := 0;
        end;
        if Iesiri is null then Iesiri := 0; end if;
        if Intrari &gt; 0 then aCount := aCount + 1;
        else
          if Iesiri &gt; 0 then aCount := aCount + 1;
          else if StocP &gt; 0 then aCount := aCount + 1; end if;
          end if;
        end if;
        StocP := StocP + Intrari - Iesiri;
        aZi := aZi + 1;
      end loop;
      execute immediate &apos;update &apos;||tmpName||&apos; set nrzile = &apos;||aCount||&apos; where codobiect = &apos;||v_obj.codobiect;
      commit;
    end if;  
  end loop;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NAPROVIZ2; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>503DC1E1FACCD80C75CE22F523EBA0CCF847366D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ3 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sSelect          VARCHAR2(30000);
  vDataStart       DATE;
  vDataFin         DATE;
  vDataStartAux    DATE;
  vDataFinAux      DATE;
  sAux             VARCHAR2(1000);
  sFiltru          VARCHAR2(1000);
  sColMinMax       VARCHAR2(100)    := &apos;, Nvl(NAOS.STOCMIN,0), Nvl(NAOS.STOCMED,0), Nvl(NAOS.STOCMAX,0)&apos;;
  sTransf          VARCHAR2(100)    := &apos;&apos;;
  vCond_Subunit_C  VARCHAR2(100);
  vCond_Subunit_CS VARCHAR2(100);
  vCond_Subunit_G  VARCHAR2(100);
  vUserID          NUMBER(20);
  vAnPrec          NUMBER(4);
  vLunaPrec        NUMBER(2);
BEGIN
  vUserId          := Nvl(pkg_globals.GETUSERID,0);
  vCond_Subunit_C  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  vCond_Subunit_CS := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, &apos;SubunitSursa&apos;);
  vCond_Subunit_G  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM, NPART PROD, NCLASEA CA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, Nvl(NAO.STOCMIN,0), Nvl(NAO.STOCMED,0), Nvl(NAO.STOCMAX,0)&apos;;
  END IF;

  vDataStart := pkg_list_selectgestart.DataStart;
  vDataFin   := pkg_list_selectgestart.DataFin;

  DELETE TMP_MANEVRA_LISTE WHERE FILTRU = &apos;GESTCODCMD&apos;;
  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllGest THEN
    sFiltru := &apos;
    AND C1.GESTACT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND C1.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_manevra_liste(valoare, filtru)
  SELECT DISTINCT C1.GESTACT, &apos;&apos;GESTCODCMD&apos;&apos;
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND Nvl(C.Anulat, 0) &lt;&gt; 1 AND C.TipDoc = 18 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru;
  EXECUTE IMMEDIATE sSelect;

  DELETE tmp_stocreal;
  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllGest THEN
    sFiltru := &apos;
    AND n.gest IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
    sTransf := &apos;, 12, 13&apos;;
  END IF;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  
  pkg_globals.Calculeaza_Luna_Precedenta(Extract(Year from vDataStart), Extract(Month from vDataStart), vAnPrec, vLunaPrec);
  pkg_globals.SetLunaTemp(Extract(Year from vDataStart), Extract(Month from vDataStart));
  pkg_globals.SetLunaPrecedenta(vAnPrec, vLunaPrec);
  PKG_LIST_SELFISAMAG.setAllParams(null, null, vDataStart, 0, 0, 0);

  sSelect :=
  &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||&apos;
  SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;
    FROM V_STOC_INI_NECESAR2 V
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST&apos;||vCond_Subunit_G||&apos;
  WHERE V.rest &lt;&gt; 0&apos;||
    sFiltru||&apos;
  GROUP BY ns.codobiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||&apos;
  SELECT NS.CODOBIECT, SUM(NSE.REST) CANT, &apos;&apos;BLOCAT&apos;&apos;
  FROM NIRSER NSE
    INNER JOIN NIRSTOC NS ON NSE.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
  WHERE NSE.STARE = 4
    AND NIR.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;GESTCODCMD&apos;&apos;)&apos;||
    sFiltru||&apos;
  GROUP BY NS.CODOBIECT&apos;;
  EXECUTE IMMEDIATE sSelect;

  DELETE tmp_miscari;
  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllGest THEN
    sFiltru := &apos;
      AND n.gest IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_miscari(codobiect,cantintr,canties)
  SELECT codobiect, sum(cantintr) cantintr, sum(canties) canties
  FROM (
    SELECT ns.codobiect,
      CASE WHEN n.tipnir IN (1, 2, 3, 4, 5, 6, 7&apos;||sTransf||&apos;) THEN ns.cantfurn ELSE 0 END cantintr,
      CASE WHEN n.tipnir IN (19, 20, 21, 22, 23, 24, 25) THEN -ns.cantfurn ELSE 0 END canties
    FROM nir n
      INNER JOIN ngest   g  ON g.codgest   = n.gest &apos;||vCond_Subunit_G||&apos;
      INNER JOIN nirstoc ns ON ns.codnir   = n.codnir
      INNER JOIN ioart1  io ON io.codioart = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
    WHERE n.tipnir IN (1, 2, 3, 4, 5, 6, 7, 19, 20, 21, 22, 23, 24, 25&apos;||sTransf||&apos;)
      AND io.mg &lt;&gt; 5
      AND n.operat = 1 AND n.anulat = 0
      AND n.datanir BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;||
      sFiltru||&apos;
    UNION ALL
    SELECT ns.codobiect,
      CASE WHEN l.tiplivr IN (1, 2, 3, 4, 5, 6, 7) THEN -l1.cant WHEN l.tiplivr = 15 THEN l1.cant ELSE 0 END cantintr,
      CASE WHEN l.tiplivr IN (14, 16, 19, 20, 21, 22, 23, 24, 25&apos;||sTransf||&apos;) THEN l1.cant ELSE 0 END canties
    FROM livr l
      INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
      INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      INNER JOIN nir     n  ON n.codnir      = ns.codnir
      INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
      INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
    WHERE l.tiplivr IN (1, 2, 3, 4, 5, 6, 7, 14, 15, 16, 19, 20, 21, 23, 24&apos;||sTransf||&apos;)
      AND io.mg &lt;&gt; 5
      AND l.operat = 1 AND l.anulat = 0
      AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;||
      sFiltru||&apos;)
  GROUP BY codobiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  DELETE tmp_cmd WHERE USERID = VUSERID;
  if pkg_list_selectgestart.Analiza &gt; 0 then
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VC&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStart - 7;
    vDataFinAux   := vDataFin - 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VM1&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStartAux - 7;
    vDataFinAux   := vDataFinAux - 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VM2&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStartAux - 7;
    vDataFinAux   := vDataFinAux - 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VM3&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT ns.codobiect,
             l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStartAux - 7;
    vDataFinAux   := vDataFinAux - 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VM4&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 22, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, count(codlocatie), &apos;&apos;LOC&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT DISTINCT ns.codobiect, I.CODLOCATIE
      FROM livr l
        INNER JOIN IESIRI  I ON L.CODIES = I.CODIES
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    
    vDataStartAux := iso_week_to_date(pkg_globals.GetANLUCRU - 1, pkg_list_selectgestart.Saptamana) + 7;
    vDataFinAux   := vDataStartAux + 6;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VP1&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    
    vDataStartAux := vDataStartAux + 7;
    vDataFinAux   := vDataFinAux + 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VP2&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStartAux + 7;
    vDataFinAux   := vDataFinAux + 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VP3&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    vDataStartAux := vDataStartAux + 7;
    vDataFinAux   := vDataFinAux + 7;
    sSelect :=
    &apos;INSERT INTO tmp_cmd(codobiect,resta,tip,userid)
    SELECT codobiect, sum(cant), &apos;&apos;VP4&apos;&apos;,&apos;||vUserId||&apos;
    FROM (
      SELECT 
        ns.codobiect,
        l1.cant
      FROM livr l
        INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir     n  ON n.codnir      = ns.codnir
        INNER JOIN ngest   g  ON g.codgest     = n.gest &apos;||vCond_Subunit_G||&apos;
        INNER JOIN ioart1  io ON io.codioart   = ns.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io.ALStart and io.ALStop
      WHERE l.tiplivr IN (16, 19, 20, 21, 23, 24)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||vDataStartAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFinAux||&apos;&apos;&apos;&apos;||
        sFiltru||&apos;)
    GROUP BY codobiect&apos;;
    EXECUTE IMMEDIATE sSelect;
  end if;
  
  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND C1.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat - Nvl(STORNO.CANT,0) ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat - Nvl(STORNO.CANT,0) ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1
    INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
    LEFT JOIN (
      SELECT SUM(L.CANT) CANT, L.CODLINIECOMANDA
      FROM CMDLIVRLINK L
        INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
        INNER JOIN COMANDA  C  ON C.CODCOMANDA   = C1.CODCOMANDA
      WHERE C.TIPDOC = 66 AND C.ANULAT &lt;&gt; 1 AND C.OPERAT = 1
      GROUP BY L.CODLINIECOMANDA
    ) STORNO ON STORNO.CODLINIECOMANDA = C1.CODCOMANDA1
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCond_Subunit_C||&apos;
    AND COALESCE(C.DISPLIVRARE,0) = 0 AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat - Nvl(STORNO.CANT,0) ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat - Nvl(STORNO.CANT,0) ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CC&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1
    INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
    LEFT  JOIN (
      SELECT SUM(L.CANT) CANT, L.CODLINIECOMANDA
      FROM CMDLIVRLINK L
        INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
        INNER JOIN COMANDA  C  ON C.CODCOMANDA   = C1.CODCOMANDA
      WHERE C.TIPDOC = 65 AND C.ANULAT &lt;&gt; 1 AND C.OPERAT = 1
      GROUP BY L.CODLINIECOMANDA
    ) STORNO ON STORNO.CODLINIECOMANDA = C1.CODCOMANDA1
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCond_Subunit_C||&apos;
    AND COALESCE(C.DISPLIVRARE,0) = 0 AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat - Nvl(STORNO.CANT,0) ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat - Nvl(STORNO.CANT,0) ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CSERV&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1
    INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
    LEFT  JOIN (
      SELECT SUM(L.CANT) CANT, L.CODLINIECOMANDA
      FROM CMDLIVRLINK L
        INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
        INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C.TIPDOC = 65 AND C.ANULAT &lt;&gt; 1 AND C.OPERAT = 1
      GROUP BY L.CODLINIECOMANDA
    ) STORNO ON STORNO.CODLINIECOMANDA = C1.CODCOMANDA1
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIN&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CSIES&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCond_Subunit_CS||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllGest THEN
    sFiltru := &apos;
    AND C.CodGest IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND C1.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    C1.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantComandat ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN C1.CantAcceptat ELSE 0 END) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CG&apos;&apos;,&apos;||vUserId||&apos;
  FROM COMANDA1 C1
    INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
    INNER JOIN NGEST   G ON C.CodGest     = G.CodGest
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 43 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;
    AND Nvl(G.Tip,0) = 1&apos;||
    sFiltru||&apos;
  GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    CMDMAT.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN CMDMAT.Cant ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN CMDMAT.Cant ELSE 0 END) CantA,
    SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIN&apos;&apos;,&apos;||vUserId||&apos;
  FROM CMDPRODMAT CMDMAT
    INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
    INNER JOIN COMANDA  C  ON C1.CodComanda      = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;
    AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))
  GROUP BY CMDMAT.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sFiltru||&apos;
    AND CMDMAT.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  sSelect :=
  &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
  SELECT
    CMDMAT.CodObiect,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN CMDMAT.Cant ELSE 0 END) CantC,
    SUM(CASE WHEN C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; THEN CMDMAT.Cant ELSE 0 END) CantA,
    SUM(CMDMAT.Rest) RestA, &apos;&apos;CIIES&apos;&apos;,&apos;||vUserId||&apos;
  FROM CMDPRODMAT CMDMAT
    INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
    INNER JOIN COMANDA  C  ON C1.CodComanda      = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
    AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCond_Subunit_C||&apos;
    AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;
    AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))&apos;||
    sFiltru||&apos;
  GROUP BY CMDMAT.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;

  sAux    := &apos;
  WHERE &apos;;
  sFiltru := &apos;&apos;;
  IF NOT pkg_list_selectgestart.AllArt THEN
    sFiltru := sAux||&apos;NAO.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
    sAux    := &apos;
    AND &apos;;
  END IF;

  sSelect :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Articol, UM, Clasa, Prod, StocMIN, StocMED, StocMAX,
    StocIni, CantIntr, CantIes, StocFin,
    CantC_CF, CantA_CF, RestA_CF,
    CantC_CC, CantA_CC, RestA_CC,
    CantC_CSERV, CantA_CSERV, RestA_CSERV,
    CantC_CSIn, CantA_CSIn, RestA_CSIn,
    CantC_CSIes, CantA_CSIes, RestA_CSIes,
    CantC_CG, CantA_CG, RestA_CG,
    CantC_CIIn, CantA_CIIn, RestA_CIIn,
    CantC_CIIes, CantA_CIIes, RestA_CIIes,
    StocEst,
    Necesar, GESTCMD, STOCGESTCMD, 
    VanzS,VanzSM1,VanzSM2,VanzSM3,VanzSM4,
    VanzSP1,VanzSP2,VanzSP3,VanzSP4,SediiVanz &apos;||gUserFields||&apos;)
  WITH GESTCMD AS (
    SELECT C1.CodObiect, string_agg(DISTINCT G.DEN_GEST) GEST
    FROM COMANDA1 C1
      INNER JOIN COMANDA C ON C1.CodComanda     = C.CodComanda
      LEFT  JOIN NGEST   G ON Nvl(C1.GESTACT,0) = Nvl(G.CODGEST,0)
    WHERE Nvl(C.INCHISA, 0) = 0 AND C.DATADOC &lt;= &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCond_Subunit_C||&apos;
      AND C.DATADOC &gt;= &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;
    GROUP BY C1.CodObiect)
  SELECT
    NAO.DENUMIRE, NUM.DEN_UM, CA.DEN_CLASEA, PROD.DEN_PART&apos;||sColMinMax||&apos;,
    Nvl(SI.CANT,0), Nvl(M.CANTINTR,0), Nvl(M.CANTIES,0), Nvl(SI.CANT,0) + Nvl(M.CANTINTR,0) - Nvl(M.CANTIES,0),
    Nvl(CF.CANTC,0), Nvl(CF.CANTA,0), Nvl(CF.RESTA,0),
    Nvl(CC.CANTC,0), Nvl(CC.CANTA,0), Nvl(CC.RESTA,0),
    Nvl(CSERV.CANTC,0), Nvl(CSERV.CANTA,0), Nvl(CSERV.RESTA,0),
    Nvl(CSIN.CANTC,0), Nvl(CSIN.CANTA,0), Nvl(CSIN.RESTA,0),
    Nvl(CSIES.CANTC,0), Nvl(CSIES.CANTA,0), Nvl(CSIES.RESTA,0),
    Nvl(CG.CANTC,0), Nvl(CG.CANTA,0), Nvl(CG.RESTA,0),
    Nvl(CIIN.CANTC,0), Nvl(CIIN.CANTA,0), Nvl(CIIN.RESTA,0),
    Nvl(CIIES.CANTC,0), Nvl(CIIES.CANTA,0), Nvl(CIIES.RESTA,0),
    CASE
      WHEN Nvl(SI.CANT,0) + Nvl(M.CANTINTR,0) - Nvl(M.CANTIES,0) - Nvl(CG.RESTA,0) + Nvl(CF.RESTA,0) - Nvl(CC.RESTA,0) - Nvl(CSERV.RESTA,0) + Nvl(CSIN.RESTA,0) - Nvl(CSIES.RESTA,0) + Nvl(CIIN.RESTA,0) - Nvl(CIIES.RESTA,0) &lt; 0 THEN 0
      ELSE Nvl(SI.CANT,0) + Nvl(M.CANTINTR,0) - Nvl(M.CANTIES,0) - Nvl(CG.RESTA,0) + Nvl(CF.RESTA,0) - Nvl(CC.RESTA,0) - Nvl(CSERV.RESTA,0) + Nvl(CSIN.RESTA,0) - Nvl(CSIES.RESTA,0) + Nvl(CIIN.RESTA,0) - Nvl(CIIES.RESTA,0)
    END,
    CASE
      WHEN Nvl(SI.CANT,0) + Nvl(M.CANTINTR,0) - Nvl(M.CANTIES,0) - Nvl(CG.RESTA,0) + Nvl(CF.RESTA,0) - Nvl(CC.RESTA,0) - Nvl(CSERV.RESTA,0) + Nvl(CSIN.RESTA,0) - Nvl(CSIES.RESTA,0) + Nvl(CIIN.RESTA,0) - Nvl(CIIES.RESTA,0) &gt; 0 THEN 0
      ELSE Nvl(SI.CANT,0) + Nvl(M.CANTINTR,0) - Nvl(M.CANTIES,0) - Nvl(CG.RESTA,0) + Nvl(CF.RESTA,0) - Nvl(CC.RESTA,0) - Nvl(CSERV.RESTA,0) + Nvl(CSIN.RESTA,0) - Nvl(CSIES.RESTA,0) + Nvl(CIIN.RESTA,0) - Nvl(CIIES.RESTA,0)
    END * -1, GESTCMD.GEST, Nvl(STOCBLOCAT.CANT,0), VC.RESTA, VM1.RESTA, VM2.RESTA, VM3.RESTA, VM4.RESTA,
    VP1.RESTA, VP2.RESTA, VP3.RESTA, VP4.RESTA, SV.RESTA &apos;||gUserAlias||&apos;
  FROM NARTOBJ NAO
    INNER JOIN NART          NA         ON NA.CODARTICOL        = NAO.CODARTICOL
    INNER JOIN NUM                      ON NUM.CODUM            = NA.UM
    LEFT JOIN NARTOBJSUBUNIT NAOS       ON NAO.CODOBIECT        = NAOS.CODOBIECT 
                                           and (NAOS.codgest is null or NAOS.codgest = 0)
                                           AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NPART          PROD       ON PROD.CODPART         = NAO.CODPRODUCATOR
    LEFT JOIN NCLASEA        CA         ON CA.CODCLASEA         = NA.CLASA
    LEFT JOIN TMP_STOCREAL   SI         ON SI.CODOBIECT         = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos;
    LEFT JOIN TMP_MISCARI    M          ON M.CODOBIECT          = NAO.CODOBIECT
    LEFT JOIN TMP_CMD        CF         ON CF.CODOBIECT         = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CC         ON CC.CODOBIECT         = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CSERV      ON CSERV.CODOBIECT      = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CSIN       ON CSIN.CODOBIECT       = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CSIES      ON CSIES.CODOBIECT      = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CG         ON CG.CODOBIECT         = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CIIN       ON CIIN.CODOBIECT       = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        CIIES      ON CIIES.CODOBIECT      = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VC         ON VC.CODOBIECT         = NAO.CODOBIECT AND VC.TIP = &apos;&apos;VC&apos;&apos; AND VC.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VM1        ON VM1.CODOBIECT        = NAO.CODOBIECT AND VM1.TIP = &apos;&apos;VM1&apos;&apos; AND VM1.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VM2        ON VM2.CODOBIECT        = NAO.CODOBIECT AND VM2.TIP = &apos;&apos;VM2&apos;&apos; AND VM2.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VM3        ON VM3.CODOBIECT        = NAO.CODOBIECT AND VM3.TIP = &apos;&apos;VM3&apos;&apos; AND VM3.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VM4        ON VM4.CODOBIECT        = NAO.CODOBIECT AND VM4.TIP = &apos;&apos;VM4&apos;&apos; AND VM4.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VP1        ON VP1.CODOBIECT        = NAO.CODOBIECT AND VP1.TIP = &apos;&apos;VP1&apos;&apos; AND VP1.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VP2        ON VP2.CODOBIECT        = NAO.CODOBIECT AND VP2.TIP = &apos;&apos;VP2&apos;&apos; AND VP2.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VP3        ON VP3.CODOBIECT        = NAO.CODOBIECT AND VP3.TIP = &apos;&apos;VP3&apos;&apos; AND VP3.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD        VP4        ON VP4.CODOBIECT        = NAO.CODOBIECT AND VP4.TIP = &apos;&apos;VP4&apos;&apos; AND VP4.USERID = &apos;||vUserId||&apos;
    LEFT JOIN TMP_CMD         SV        ON SV.CODOBIECT         = NAO.CODOBIECT AND  SV.TIP = &apos;&apos;LOC&apos;&apos; AND  SV.USERID = &apos;||vUserId||&apos;
    LEFT JOIN GESTCMD                   ON GESTCMD.CODOBIECT    = NAO.CODOBIECT
    LEFT JOIN TMP_STOCREAL   STOCBLOCAT ON STOCBLOCAT.CODOBIECT = NAO.CODOBIECT AND STOCBLOCAT.TIP = &apos;&apos;BLOCAT&apos;&apos; &apos;||
    gSuplJoins||
  sFiltru;

  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
  DELETE tmp_cmd WHERE USERID = VUSERID;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NAPROVIZ3; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B3E9835EC937346592230647862B003AFB2F5D2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ4 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

procedure UmpleTemporarGenerator(vCodNecesar in number) is
sSelect      VARCHAR2(32000);
vToateGest   BOOLEAN;
vToateIOArt  BOOLEAN;
vAux         VARCHAR2(100);
vSelStocReal VARCHAR2(2000);
vCateGest    INTEGER := 0;
vCateLGest   INTEGER := 0;
vProductie   BOOLEAN;
vCondIntrari VARCHAR2(500) := &apos;&apos;;
vCondIesiri  VARCHAR2(500) := &apos;&apos;;
vNrZileStocMed NUMBER(10);

vGestString varchar2(500) := &apos;&apos;;
vIOArtString varchar2(500):= &apos;&apos;;
vCond_Subunit_C varchar2(100);
vCond_Subunit_G varchar2(100);
vSetimana INTEGER;
vUserID number(20);
vAn number(4);
vPrevAn number(4);
vPrevSetimana number(4);
vPPrevAn number(4);
vPPrevSetimana number(4);
vCount number;
vSupliment number(1);
begin
  vUserId        := Nvl(pkg_globals.GETUSERID,0);
  vToateGest     := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt    := PKG_LIST_SELECTSCAD.ToateIoart;
  vProductie     := PKG_LIST_SELECTSCAD.Centralizat = 1;
  vSetimana      := PKG_LIST_SELECTSCAD.Setimana;
  vAn            := pkg_globals.ANLUCRU;

  begin
    select nvl(Supliment,0) into vSupliment from necesar where codnecesar = vCodNecesar;
  exception when others then
    vSupliment := 0;
  end;

  vCondIntrari := &apos; AND C1.TERMEN &lt; PKG_LIST_SELECTSCAD.DATAINI &apos;;
  if PKG_LIST_SELECTSCAD.DATAINI = PKG_LIST_SELECTSCAD.DATASCAD then
    vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD - 1 &apos;;
  else
    vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD &apos;;
  end if;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrZileStocMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrZileStocMed FROM DUAL;
  vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NIRSTOC NS
        INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
      WHERE (NROBJ.NR = 1 OR (NROBJ.NR &gt; 1 AND EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT))) 
            and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4 &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;

  vSelStocReal := vSelStocReal||&apos;
      UNION ALL
      SELECT OBJ.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NARTOBJ OBJ
        INNER JOIN NARTOBJ O ON OBJ.CODARTICOL = O.CODARTICOL
        INNER JOIN NIRSTOC NS ON O.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
        WHERE (NROBJ.NR &gt; 1 AND NOT EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT)) 
              and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4 &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY OBJ.CODOBIECT&apos;;

  DELETE TMP_STOCREAL;
  sSelect := &apos;insert into tmp_stocreal(codobiect,cant) &apos;||vSelStocReal;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_STOCREZ;
  sSelect := &apos;insert into tmp_stocrez(codobiect,rezervat) &apos;||&apos;SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT &apos;||
      &apos;FROM REZERVATS R &apos;||
        &apos;INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC &apos;||
        &apos;INNER JOIN NIR N ON NS.CODNIR = N.CODNIR &apos;||
        &apos;INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||
      &apos;WHERE NVL(R.REST,0) &gt; 0 &apos;||
      vGestString||
      vIOArtString||
      &apos;GROUP BY NS.CODOBIECT&apos;;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_CMD WHERE USERID = vUserId;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||chr(13)||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CF&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;  SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA &apos;||chr(13)||
    &apos;  FROM COMANDA1 C1&apos;||chr(13)||
    &apos;       INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||chr(13)||
    &apos;  WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||chr(13)||
    &apos; ) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||chr(13)||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CFNEXT&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;  SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA &apos;||chr(13)||
    &apos;  FROM COMANDA1 C1 &apos;||chr(13)||
    &apos;       INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||chr(13)||
    &apos;  WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||chr(13)||
    &apos;        AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATASCAD AND PKG_LIST_SELECTSCAD.DATASCAD + 6 &apos;||chr(13)||
    &apos;) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,resta,tip, userid) &apos;||
    &apos;SELECT C1.CodObiect, SUM(C1.CantAcceptat - NVL(Storno.Cant,0)) RestA, &apos;&apos;CFN&apos;&apos;, &apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 &apos;||
    &apos;     INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||
    &apos;     INNER JOIN NECESARCMD NC ON NC.CodComanda = C.CodComanda &apos;||
    &apos;     LEFT  JOIN (SELECT SUM(L.CANT) CANT, CODLINIECOMANDA &apos;||
    &apos;                 FROM CMDLIVRLINK L &apos;||
    &apos;                      INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1 &apos;||
    &apos;                      INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA &apos;||
    &apos;                 WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66 &apos;||
    &apos;                 GROUP BY CODLINIECOMANDA) STORNO ON STORNO.CodLINIECOMANDA = C1.CodComanda1 &apos;||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||
    &apos;      AND NC.CODNECESAR = &apos;||vCodNecesar||&apos; &apos;||
    &apos;GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||chr(13)||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CFPER&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;  SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA &apos;||chr(13)||
    &apos;  FROM COMANDA1 C1 &apos;||chr(13)||
    &apos;       INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||chr(13)||
    &apos;  WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||chr(13)||
    &apos;) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CC&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIES&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0  AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIESPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;

  /*informatii aduse din planificari*/
  if vSetimana = 1 then
    vPrevAn := vAn - 1;
    vPrevSetimana := 53;
  else
    vPrevAn := vAn;
    vPrevSetimana := vSetimana - 1;
  end if;
  if vPrevSetimana = 1 then
    vPPrevAn := vPrevAn - 1;
    vPPrevSetimana := 53;
  else
    vPPrevAn := vPrevAn;
    vPPrevSetimana := vPrevSetimana - 1;
  end if;

  if vSupliment = 0 then
    select count(*) into vCount
    from planifprod
    where ((saptamana = vSetimana and an = vAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPrevSetimana and an = vPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPPrevSetimana and an = vPPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1))
          )
          and anulat = 0;
    if vCount &gt; 0 then
      DELETE TMP_PLANIFNODZ;
      INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
      SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
           INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
      WHERE PP.An = vAn and PP.Saptamana = vSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
            PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
            AND NECP.CODNECESAR = vCodNecesar
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
           INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
      WHERE PP.An = vAn and PP.Saptamana = vSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
            AND NECP.CODNECESAR = vCodNecesar
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
           INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
      WHERE PP.An = vAn and PP.Saptamana = vSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
            AND NECP.CODNECESAR = vCodNecesar
      UNION ALL
      select codreteta, codobiect, NEXTWEEK necesar from
      (SELECT L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
       from LANSZ1 L1
            inner join LANSZ l on l.codlansz = l1.codlansz
       where l.operat = 1 and l.anulat = 0 and l.blocat = 0
             and l.an = vPrevAn and l.saptamana = vPrevSetimana
             and l1.nextweek &gt; 0
             AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
       group by l1.codreteta, l1.codobiect
       ))
       group by codobiect, codreteta;

       sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
        &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR)/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
        &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
        &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
        &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
        &apos;     LEFT JOIN ( &apos;||CHR(13)||
        &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
        &apos;                from LANSZ1 L1 &apos;||CHR(13)||
        &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
        &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
        &apos;                      and l.an = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||CHR(13)||
        &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;               group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
        &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
        &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
        &apos;WHERE NVL(MAT.TIP,3) &gt; 2 &apos;||CHR(13)||
        &apos;GROUP BY MAT.CodObiect, NVL(LANS.STINS,0)&apos;;
        EXECUTE IMMEDIATE sSelect;

        DELETE TMP_PLANIFNODZ;
        INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
        SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
        SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
        FROM PLANIFNOD PNOD
             INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
             INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
        WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
              PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
              PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
              PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
              AND PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
        UNION ALL
        SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
        FROM PLANIFNOD PNOD
             INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
             INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
        WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
              PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
              PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
              AND PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
        UNION ALL
        SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
        FROM PLANIFNOD PNOD
             INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
             INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
        WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
              PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
              PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
              AND PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
        UNION ALL
      (
      select codreteta, codobiect, nextweek necesar from
      (SELECT distinct L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
       from LANSZ1 L1
            inner join LANSZ l on l.codlansz = l1.codlansz
       where l.operat = 1 and l.anulat = 0 and l.blocat = 0
             and l.an = vPPrevAn and l.saptamana = vPPrevSetimana
             and l1.nextweek &gt; 0
             AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
       group by l1.codreteta, l1.codobiect
       )))
       group by codobiect, codreteta;

       sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
        &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR)/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPREV&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
        &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
        &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
        &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
        &apos;     LEFT JOIN ( &apos;||CHR(13)||
        &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
        &apos;                from LANSZ1 L1 &apos;||CHR(13)||
        &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
        &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
        &apos;                      and l.an = &apos;||vPPrevAn||&apos; and l.saptamana = &apos;||vPPrevSetimana||CHR(13)||
        &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
        &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
        &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                union all &apos;||CHR(13)||
        &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
        &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
        &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
        &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
        &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
        &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
        &apos;                group by cmd.codobiect &apos;||CHR(13)||
        &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
        &apos;WHERE NVL(MAT.TIP,3) &gt; 2 &apos;||CHR(13)||
        &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
        EXECUTE IMMEDIATE sSelect;
    end if;
  else
    DELETE TMP_PLANIFNODZ;
    INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
    SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
         INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
          PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
          AND NECP.CODNECESAR = vCodNecesar
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
         INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
          AND NECP.CODNECESAR = vCodNecesar
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
         INNER JOIN NECESARDOC NECP ON NECP.CODPLANIFPROD = PP.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
          AND NECP.CODNECESAR = vCodNecesar
    )
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR)/PC.CANT*MAT.CANT) CantC, 0 CantA, SUM(TMP.NECESAR/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                      AND L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect, NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;
  end if;
  commit;
end;

procedure UmpleTemporar is
sSelect      VARCHAR2(32000);
vToateGest   BOOLEAN;
vToateIOArt  BOOLEAN;
vAux         VARCHAR2(100);
vSelStocReal VARCHAR2(2000);
vCateGest    INTEGER        := 0;
vCateLGest   INTEGER        := 0;
vProductie   BOOLEAN;
vCondIntrari VARCHAR2(500) := &apos;&apos;;
vCondIesiri  VARCHAR2(500) := &apos;&apos;;
vNrZileStocMed NUMBER(10);

vGestString varchar2(500) := &apos;&apos;;
vIOArtString varchar2(500):= &apos;&apos;;
vCond_Subunit_C varchar2(100);
vCond_Subunit_G varchar2(100);
vSetimana INTEGER;
vUserID number(20);
vAn number(4);
vPrevAn number(4);
vPrevSetimana number(4);
vPPrevAn number(4);
vPPrevSetimana number(4);
vNextAn number(4);
vNextSetimana number(4);
vCount number;
begin
  vUserId        := Nvl(pkg_globals.GETUSERID,0);
  vToateGest     := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt    := PKG_LIST_SELECTSCAD.ToateIoart;
  vProductie     := PKG_LIST_SELECTSCAD.Centralizat = 1;
  vSetimana      := PKG_LIST_SELECTSCAD.Setimana;
  vAn            := pkg_globals.ANLUCRU;

  if vProductie then
    vCondIntrari := &apos; AND C1.TERMEN &lt; PKG_LIST_SELECTSCAD.DATAINI &apos;;
    if PKG_LIST_SELECTSCAD.DATAINI = PKG_LIST_SELECTSCAD.DATASCAD then
      vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD - 1 &apos;;
    else
      vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD &apos;;
    end if;
  end if;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrZileStocMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrZileStocMed FROM DUAL;
  vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NIRSTOC NS
        INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
      WHERE (NROBJ.NR = 1 OR (NROBJ.NR &gt; 1 AND EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT))) 
            and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4  &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;

  vSelStocReal := vSelStocReal||&apos;
      UNION ALL
      SELECT OBJ.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NARTOBJ OBJ
        INNER JOIN NARTOBJ O ON OBJ.CODARTICOL = O.CODARTICOL
        INNER JOIN NIRSTOC NS ON O.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
        WHERE (NROBJ.NR &gt; 1 AND NOT EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT)) 
              and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4 &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY OBJ.CODOBIECT&apos;;

  DELETE TMP_STOCREAL;
  sSelect := &apos;insert into tmp_stocreal(codobiect,cant) &apos;||vSelStocReal;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_STOCREZ;
  sSelect := &apos;insert into tmp_stocrez(codobiect,rezervat) &apos;||&apos;SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT &apos;||
      &apos;FROM REZERVATS R &apos;||
        &apos;INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC &apos;||
        &apos;INNER JOIN NIR N ON NS.CODNIR = N.CODNIR &apos;||
        &apos;INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||
      &apos;WHERE NVL(R.REST,0) &gt; 0 &apos;||
      vGestString||
      vIOArtString||
      &apos;GROUP BY NS.CODOBIECT&apos;;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_CMD WHERE USERID = vUserId;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||chr(13)||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CF&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;  SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA &apos;||chr(13)||
    &apos;  FROM COMANDA1 C1&apos;||chr(13)||
    &apos;       INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||chr(13)||
    &apos;  WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||chr(13)||
    &apos; ) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,resta,tip, userid) &apos;||
    &apos;select codobiect, sum(resta) resta, &apos;&apos;CFN&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;SELECT C1.CodObiect, C1.RestAcceptat RestA, &apos;&apos;CFN&apos;&apos;, &apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||&apos; &apos;||
    &apos;     AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATASCAD + 1 AND PKG_LIST_SELECTSCAD.DATASCAD + 7 &apos;||
    &apos;) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CFT&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA, &apos;&apos;CFT&apos;&apos;,&apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||&apos; &apos;||
    &apos;) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;select codobiect, sum(cantc) cantc, sum(canta) canta, sum(resta) resta, &apos;&apos;CFPER&apos;&apos;, &apos;||vUserId||&apos; from (&apos;||chr(13)||
    &apos;SELECT C1.CodObiect, C1.CantComandat CantC, C1.CantAcceptat CantA, C1.RestAcceptat RestA, &apos;&apos;CFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
    &apos;) GROUP BY CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CC&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIES&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0  AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIESPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        &apos;AND C1.RestLansat &gt; 0 and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;

  /*informatii aduse din planificari*/
  if vSetimana = 1 then
    vPrevAn := vAn - 1;
    vPrevSetimana := 53;
  else
    vPrevAn := vAn;
    vPrevSetimana := vSetimana - 1;
  end if;
  if vPrevSetimana = 1 then
    vPPrevAn := vPrevAn - 1;
    vPPrevSetimana := 53;
  else
    vPPrevAn := vPrevAn;
    vPPrevSetimana := vPrevSetimana - 1;
  end if;
  if vSetimana = 53 then
    vNextAn := vAn + 1;
    vNextSetimana := 1;
  else
    vNextAn := vAn;
    vNextSetimana := vSetimana + 1;
  end if;

  select count(*) into vCount
  from planifprod
  where ((saptamana = vSetimana and an = vAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPrevSetimana and an = vPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPPrevSetimana and an = vPPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vNextSetimana and an = vNextAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1))
        )
        and anulat = 0;

  if vCount &gt; 0 then
    DELETE TMP_PLANIFNODZ;
    INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
    SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
          PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    select codreteta, codobiect, NEXTWEEK necesar from
    (SELECT L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vPrevAn and l.saptamana = vPrevSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     ))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;               group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;

      DELETE TMP_PLANIFNODZ;
      INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
      SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
            PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
    (
    select codreteta, codobiect, nextweek necesar from
    (SELECT distinct L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vPPrevAn and l.saptamana = vPPrevSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     )))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPREV&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vPPrevAn||&apos; and l.saptamana = &apos;||vPPrevSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;                group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;

      DELETE TMP_PLANIFNODZ;
      INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
      SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
            PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
    (
    select codreteta, codobiect, 0 necesar from
    (SELECT distinct L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vAn and l.saptamana = vSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     )))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) - NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFNEXT&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;                group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;
  end if;
  commit;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(20000);
  sSelect      VARCHAR2(32000);
  sColMinMax   VARCHAR2(  100):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  vToateGest   BOOLEAN;
  vToateIOArt  BOOLEAN;
  vCuNecesarZero BOOLEAN;
  vAux         VARCHAR2(100);
  vSelStocReal VARCHAR2(2000);
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  vProductie   BOOLEAN;
  vCondIntrari VARCHAR2(500) := &apos;&apos;;
  vCondIesiri  VARCHAR2(500) := &apos;&apos;;
  vCondIesiriD  VARCHAR2(500) := &apos;&apos;;
  vNrZileStocMed NUMBER(10);
  vScadNeop NUMBER(1);
  vDataRef VARCHAR2(20);
  vStocAux VARCHAR2(100);

  vGestString varchar2(500) := &apos;&apos;;
  vIOArtString varchar2(500):= &apos;&apos;;
  sJoinExt     VARCHAR2(1000);
  vCond_Subunit_C varchar2(100);
  vCond_Subunit_G varchar2(100);
  vSetimana INTEGER;
  vUserID number(20);
  vAn number(4);
  vPrevAn number(4);
  vPrevSetimana number(4);
  vNextAn number(4);
  vNextSetimana number(4);
  vCount number;
  vPPrevAn number(4);
  vPPrevSetimana number(4);
  vCondLansat varchar2(500) := &apos;&apos;;
  vCampLansat varchar2(10);
  sFieldNeop varchar2(100);
  sJoinNeop varchar2(200);
BEGIN
  vUserId         := Nvl(pkg_globals.GETUSERID,0);
  vCond_Subunit_C := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  vCond_Subunit_G := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  gSuplCols := &apos;NARTOBJ NAO, NARTOBJSUBUNIT NAOS, NART NA, NUM NUM, NPART PROD, NCLASEA CLSA, NCLASEAS CLSAS, NARTCLI NACLI, NPART PART, NUM1 NUM1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vToateGest     := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt    := PKG_LIST_SELECTSCAD.ToateIoart;
  vCuNecesarZero := PKG_LIST_SELECTSCAD.Extra1;
  vProductie     := PKG_LIST_SELECTSCAD.Centralizat = 1;
  vSetimana      := PKG_LIST_SELECTSCAD.Setimana;
  vAn            := pkg_globals.ANLUCRU;

  vStocAux := &apos;0&apos;;
  if PKG_LIST_SELECTSCAD.TipNecesar = 1 then
    vStocAux := &apos; nvl(NAOS.STOCMIN,0) &apos;;
  else if PKG_LIST_SELECTSCAD.TipNecesar = 2 then
    vStocAux := &apos; nvl(NAOS.STOCMED,0) &apos;;
  else if PKG_LIST_SELECTSCAD.TipNecesar = 3 then
    vStocAux := &apos; nvl(NAOS.STOCMAX,0) &apos;;
  end if;
  end if;
  end if;

  vCondLansat := &apos; AND C1.RestLansat &gt; 0 &apos;;
  vCampLansat := &apos;RestA&apos;;
  if PKG_LIST_SELECTSCAD.Extra3 then
    vCondLansat := &apos;&apos;;
    vCampLansat := &apos;CantA&apos;;
  end if;

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NIRSTOC NS
        INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
      WHERE (NROBJ.NR = 1 OR (NROBJ.NR &gt; 1 AND EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT))) 
            and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4 &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;

  vSelStocReal := vSelStocReal||&apos;
      UNION ALL
      SELECT OBJ.CODOBIECT, SUM(case when n.operat = 0 then ns.cantnir else ns.rest end) CANT
      FROM NARTOBJ OBJ
        INNER JOIN NARTOBJ O ON OBJ.CODARTICOL = O.CODARTICOL
        INNER JOIN NIRSTOC NS ON O.CODOBIECT = NS.CODOBIECT
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST &apos;||vCond_Subunit_G||&apos;
        INNER JOIN (SELECT A.CODARTICOL, COUNT(O.CODOBIECT) NR
                    FROM NART A
                         INNER JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
                    GROUP BY A.CODARTICOL) NROBJ ON OBJ.CODARTICOL = NROBJ.CODARTICOL
        WHERE (NROBJ.NR &gt; 1 AND NOT EXISTS (SELECT ATR.CODOBIECT FROM NATROBJ ATR WHERE ATR.CODOBIECT = OBJ.CODOBIECT)) 
              and ((ns.rest &lt;&gt; 0 and n.operat = 1) or (ns.rest = 0 and n.operat = 0 and n.tipnir = 12)) and g.tip &lt;&gt; 4 &apos;;
  vAux := &apos;
      AND &apos;;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
    elsif vCateGest = 0 then
      vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE) &apos;;
    else
      vSelStocReal := vSelStocReal || vAux||&apos; (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR &apos;||
                                   &apos;EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)) &apos;;
    end if;
    vAux := &apos;
        AND&apos;;
    vGestString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;
  end if;

  if NOT vToateIOArt then
    vSelStocReal := vSelStocReal || vAux||&apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    vIOArtString := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY OBJ.CODOBIECT&apos;;

  vDataRef := to_char(Last_Day(To_Date(&apos;01.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;99&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;9999&apos;),&apos;dd.mm.yyyy&apos;)), &apos;DD.MM.YYYY&apos;);
  --if vProductie then
    if PKG_LIST_SELECTSCAD.ModSelectie = 0 then
      vDataRef     := PKG_LIST_SELECTSCAD.DATASCAD;
      vCondIntrari := &apos; AND C1.TERMEN &lt; PKG_LIST_SELECTSCAD.DATAINI &apos;;
      --if PKG_LIST_SELECTSCAD.DATAINI = PKG_LIST_SELECTSCAD.DATASCAD then
      --  vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD - 1 &apos;;
      --else
        vCondIesiri  := &apos; AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD &apos;;
      --end if;
      vCondIesiriD  := &apos; AND C1.TERMEN &lt;= PKG_LIST_SELECTSCAD.DATAINI &apos;;
    else
      vDataRef     := PKG_LIST_SELECTSCAD.DATASCAD;
      vCondIntrari := &apos; AND C.DATADOC &lt; PKG_LIST_SELECTSCAD.DATAINI &apos;;
      --if PKG_LIST_SELECTSCAD.DATAINI = PKG_LIST_SELECTSCAD.DATASCAD then
      --  vCondIesiri  := &apos; AND C.DATADOC BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD - 1 &apos;;
      --else
        vCondIesiri  := &apos; AND C.DATADOC BETWEEN PKG_LIST_SELECTSCAD.DATAINI AND PKG_LIST_SELECTSCAD.DATASCAD &apos;;
      --end if;
      vCondIesiriD  := &apos; AND C.DATADOC &lt;= PKG_LIST_SELECTSCAD.DATAINI &apos;;
    end if;  
  --end if;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrZileStocMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrZileStocMed FROM DUAL;
  SELECT PKG_CATEGCONST.GetValConstanta(&apos;ScadAcceptatNeopFurn&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vScadNeop FROM DUAL;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Articol,
    UM,
    PretAch,
    Cant,
    Val,
    Sursa,
    Data,
    Furn,
    StocMIN,
    StocMED,
    StocMAX,
    StocReal,
    CantC_CF,
    CantA_CF,
    RestA_CF,
    CantC_CFT,
    CantA_CFT,
    RestA_CFT,
    CantC_CC,
    CantA_CC,
    RestA_CC,
    CantC_CIIes,
    CantA_CIIes,
    RestA_CIIes,
    CantC_CCPANALA,
    CantA_CCPANALA,
    RestA_CCPANALA,
    CantC_CIIesLA,
    CantA_CIIesLA,
    RestA_CIIesLA,
    CodExtern,
    CodIntern,
    Producator,
    Rezervat,
    ZileStocMED,
    PartOf,
    UMOf,
    CantMinOf,
    ZileLOf,
    ZileLNom,
    RestA_CF_Next,
    CantC_CCPER,
    CantA_CCPER,
    RestA_CCPER,
    CantC_CIPER,
    CantA_CIPER,
    RestA_CIPER,
    CantC_CFPER,
    CantA_CFPER,
    RestA_CFPER,
    CantC_PlanifPrev,
    CantA_PlanifPrev,
    RestA_PlanifPrev,
    BC_PlanifPrev,
    CantC_PlanifPer,
    CantA_PlanifPer,
    RestA_PlanifPer,
    BC_PlanifPer,
    CantC_PlanifNext,
    CantA_PlanifNext,
    RestA_PlanifNext,
    BC_PlanifNext,
    CodObiect,
    Saptamana &apos;||gUserFields||&apos;)&apos;;

  DELETE TMP_MANEVRA_LISTE WHERE FILTRU = &apos;MATERIALE&apos;;
  INSERT INTO TMP_MANEVRA_LISTE(VALOARE, FILTRU)
  SELECT DISTINCT CODOBIECT, &apos;MATERIALE&apos;
  FROM NARTOBJ
  WHERE NVL(PRODUSPROPRIU,0) = 0;

  DELETE TMP_STOCREAL;
  DELETE TMP_CMD WHERE USERID = vUserId;
  
  sFieldNeop := &apos;&apos;;
  sJoinNeop  := &apos;&apos;;
  if vScadNeop = 1 then
    sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT C1.CodObiect, 0 CantC, 0 CantA, SUM(l.cant) RestA, &apos;&apos;NEOP&apos;&apos;, &apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 &apos;||
    &apos;INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||
    &apos;INNER JOIN INTRLINK L ON C1.CodComanda1 = L.CodLinieComanda &apos;||
    &apos;INNER JOIN INTRARI1 I1 ON I1.CodINTR1 = L.CodINTR1 &apos;||
    &apos;INNER JOIN INTRARI I ON I.CodINTR = I1.CodINTR &apos;||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||
    &apos;      AND COALESCE(I.OPERAT,0) = 0 &apos;|| 
    &apos;GROUP BY C1.CodObiect&apos;;
    EXECUTE IMMEDIATE sSelect;
    sFieldNeop := &apos; + coalesce(neop.resta,0) &apos;;
    sJoinNeop  := chr(13)||&apos;  LEFT JOIN TMP_CMD NEOP ON NEOP.CODOBIECT = C1.CODOBIECT AND NEOP.TIP = &apos;&apos;NEOP&apos;&apos; AND NEOP.USERID = &apos;||vUserId||CHR(13);
  end if;
  
  sSelect := &apos;insert into tmp_stocreal(codobiect,cant) &apos;||vSelStocReal;
  EXECUTE IMMEDIATE sSelect;

  DELETE TMP_STOCREZ;
  sSelect := &apos;insert into tmp_stocrez(codobiect,rezervat) &apos;||&apos;SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT &apos;||
      &apos;FROM REZERVATS R &apos;||
        &apos;INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC &apos;||
        &apos;INNER JOIN NIR N ON NS.CODNIR = N.CODNIR &apos;||
        &apos;INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||
      &apos;WHERE NVL(R.REST,0) &gt; 0 &apos;||
      vGestString||
      vIOArtString||
      &apos;GROUP BY NS.CODOBIECT&apos;;
  EXECUTE IMMEDIATE sSelect;

  
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat&apos;||sFieldNeop||&apos;) RestA, &apos;&apos;CF&apos;&apos;, &apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||sJoinNeop||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
    &apos;GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,resta,tip, userid) &apos;||
    &apos;SELECT C1.CodObiect, SUM(C1.RestAcceptat&apos;||sFieldNeop||&apos;) RestA, &apos;&apos;CFN&apos;&apos;, &apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||sJoinNeop||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||&apos; &apos;||
    &apos;     AND C1.TERMEN BETWEEN PKG_LIST_SELECTSCAD.DATASCAD + 1 AND PKG_LIST_SELECTSCAD.DATASCAD + 7 &apos;||
    &apos;GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat&apos;||sFieldNeop||&apos;) RestA, &apos;&apos;CFT&apos;&apos;,&apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||sJoinNeop||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||&apos; &apos;||
    &apos;GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT C1.CodObiect, SUM(C1.CantComandat) CantC, SUM(C1.CantAcceptat) CantA, SUM(C1.RestAcceptat&apos;||sFieldNeop||&apos;) RestA, &apos;&apos;CFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
    &apos;FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda &apos;||sJoinNeop||
    &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 AND C1.RestAcceptat &gt; 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
    &apos;GROUP BY C1.CodObiect&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CC&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIES&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0  AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIIESPANALA&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIntrari||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CCPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND NVL(C.DispLivrare, 0) = 0 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||
    &apos;SELECT nvl(NE.CODOBIECT,PN.CodObiect), SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantComandat else PN.Cant/PN0.Cant*C1.CantComandat end) CantC, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.CantAcceptat else PN.Cant/PN0.Cant*C1.CantAcceptat end) CantA, SUM(case when NE.codobiect &gt; 0 then NE.Paritate * PN.Cant/PN0.Cant*C1.RestLansat else PN.Cant/PN0.Cant*C1.RestLansat end) RestA,
            &apos;&apos;CIPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||
      &apos;FROM COMANDA C &apos;||
        &apos;INNER JOIN COMANDA1 C1 ON C.CodComanda = C1.CodComanda &apos;||
        &apos;INNER JOIN PROIECTNOD PN ON C1.CODPROIECT = PN.CODPROIECT AND PN.TIP = 3 &apos;||
        &apos;INNER JOIN PROIECTNOD PN0 ON C1.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0 &apos;||
        &apos;LEFT  JOIN NODECHIV NE ON C1.CODCOMANDA1 = NE.CODCOMANDA1 AND PN.CODPROIECTNOD = NE.CODPROIECTNOD &apos;||
      &apos;WHERE Nvl(C.INCHISA, 0) = 0 AND C.Operat = 1 AND C.Anulat = 0 AND C.DispLivrare = 2 AND C.TipDoc = 18 &apos;||
        vCondLansat||&apos; and NVL(c1.exceptional,0) = 0 &apos;||vCond_Subunit_C||vCondIesiri||&apos; &apos;||
      &apos;GROUP BY nvl(NE.CODOBIECT,PN.CodObiect)&apos;;
  EXECUTE IMMEDIATE sSelect;

  /*informatii aduse din planificari*/
  if vSetimana = 1 then
    vPrevAn := vAn - 1;
    vPrevSetimana := 53;
  else
    vPrevAn := vAn;
    vPrevSetimana := vSetimana - 1;
  end if;
  if vPrevSetimana = 1 then
    vPPrevAn := vPrevAn - 1;
    vPPrevSetimana := 53;
  else
    vPPrevAn := vPrevAn;
    vPPrevSetimana := vPrevSetimana - 1;
  end if;
  if vSetimana = 53 then
    vNextAn := vAn + 1;
    vNextSetimana := 1;
  else
    vNextAn := vAn;
    vNextSetimana := vSetimana + 1;
  end if;

  select count(*) into vCount
  from planifprod
  where ((saptamana = vSetimana and an = vAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPrevSetimana and an = vPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vPPrevSetimana and an = vPPrevAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1)) or
         (saptamana = vNextSetimana and an = vNextAn and (subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1))
        )
        and anulat = 0;

  if vCount &gt; 0 then
    DELETE TMP_PLANIFNODZ;
    INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
    SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
          PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
    FROM PLANIFNOD PNOD
         INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
         INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
    WHERE PP.An = vAn and PP.Saptamana = vSetimana and
          PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
          PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
          AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
    UNION ALL
    select codreteta, codobiect, NEXTWEEK necesar from
    (SELECT L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vPrevAn and l.saptamana = vPrevSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     ))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPER&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;               group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect, NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;

      DELETE TMP_PLANIFNODZ;
      INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
      SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
            PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vPrevAn and PP.Saptamana = vPrevSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
    (
    select codreteta, codobiect, nextweek necesar from
    (SELECT distinct L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vPPrevAn and l.saptamana = vPPrevSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     )))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFPREV&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vPPrevAn||&apos; and l.saptamana = &apos;||vPPrevSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;                group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;

      DELETE TMP_PLANIFNODZ;
      INSERT INTO TMP_PLANIFNODZ (CODRETETA, CODOBIECT, NECESAR)
      SELECT CODRETETA, CODOBIECT, SUM(NECESAR) FROM (
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 0 AND
            PP1.CUPROIECT = 1 AND PNOD.NIVEL &gt; 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 1 AND PNOD.NIVEL = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
      SELECT PNOD.CODRETETA, PNOD.CODOBIECT, PNOD.NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An = vNextAn and PP.Saptamana = vNextSetimana and
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 and
            PNOD.Codreteta &gt; 0 and PNOD.Versiune = 1 AND PP1.CUPROIECT = 0
            AND (PP.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
      UNION ALL
    (
    select codreteta, codobiect, nextweek necesar from
    (SELECT distinct L1.CODRETETA, L1.CODOBIECT, sum(nvl(l1.nextweek,0)) nextweek
     from LANSZ1 L1
          inner join LANSZ l on l.codlansz = l1.codlansz
     where l.operat = 1 and l.anulat = 0 and l.blocat = 0
           and l.an = vAn and l.saptamana = vSetimana
           and l1.nextweek &gt; 0
           AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
     group by l1.codreteta, l1.codobiect
     )))
     group by codobiect, codreteta;

     sSelect := &apos;insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid) &apos;||CHR(13)||
      &apos;SELECT MAT.CodObiect, SUM((TMP.NECESAR - NVL(REPORT.NEXTWEEK,0))/PC.CANT*MAT.CANT) CantC, SUM(NVL(REPORT.NEXTWEEK,0)/PC.CANT*MAT.CANT) CantA, NVL(LANS.STINS,0) RestA, &apos;&apos;PLANIFNEXT&apos;&apos;,&apos;||vUserId||&apos; &apos;||CHR(13)||
      &apos;FROM TMP_PLANIFNODZ TMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODCOMP PC ON TMP.CODRETETA = PC.CODPRODCOMP &apos;||CHR(13)||
      &apos;     INNER JOIN PRODMAT MAT ON PC.CODPRODCOMP = MAT.CODPRODCOMP &apos;||CHR(13)||
      &apos;     LEFT JOIN ( &apos;||CHR(13)||
      &apos;                SELECT L1.CODRETETA, L1.CODOBIECT, SUM(NVL(L1.NEXTWEEK,0)) NEXTWEEK &apos;||CHR(13)||
      &apos;                from LANSZ1 L1 &apos;||CHR(13)||
      &apos;                     inner join LANSZ l on l.codlansz = l1.codlansz &apos;||CHR(13)||
      &apos;                where l.operat = 1 and l.anulat = 0 and l.blocat = 0 &apos;||CHR(13)||
      &apos;                      and l.an = &apos;||vAn||&apos; and l.saptamana = &apos;||vSetimana||CHR(13)||
      &apos;                      and l1.nextweek &gt; 0 &apos;||CHR(13)||
      &apos;                      AND (L.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1) &apos;||CHR(13)||
      &apos;               group by l1.codreteta, l1.codobiect &apos;||CHR(13)||
      &apos;               ) REPORT ON REPORT.CODRETETA = TMP.CODRETETA&apos;||CHR(13)||
      &apos;     LEFT JOIN (SELECT CODOBIECT, SUM(STINS) STINS FROM ( &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                union all &apos;||CHR(13)||
      &apos;                SELECT CMD.CODOBIECT, SUM(IL.CANT) STINS &apos;||CHR(13)||
      &apos;                FROM IESPRODLINK IL &apos;||CHR(13)||
      &apos;                     INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA &apos;||CHR(13)||
      &apos;                     INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ &apos;||CHR(13)||
      &apos;                WHERE NVL(L.ANULAT,0) = 0 AND L.AN = &apos;||vPrevAn||&apos; and l.saptamana = &apos;||vPrevSetimana||&apos; AND CMD.TIP = 1 &apos;||CHR(13)||
      &apos;                group by cmd.codobiect &apos;||CHR(13)||
      &apos;                ) GROUP BY CODOBIECT) LANS ON LANS.CODOBIECT = MAT.CODOBIECT  &apos;||CHR(13)||
      &apos;GROUP BY MAT.CodObiect,NVL(LANS.STINS,0)&apos;;
      EXECUTE IMMEDIATE sSelect;
  end if;



  DELETE TMP_PRETACH;
  sSelect := &apos;insert into tmp_PRETACH(CODOBIECT,PRETACH,DATAPRET,DEN_PART,SURSA) &apos;||
    &apos;SELECT CODOBIECT, PRETACH, DATANIR DATAPRET, DEN_PART, &apos;&apos;STOC&apos;&apos; SURSA &apos;||
      &apos;FROM ( &apos;||
        &apos;SELECT NS.CODOBIECT, &apos;||
        &apos;FIRST_VALUE(NS.PRET - NVL(NS.ADAOS, 0)) OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) PRETACH, &apos;||
        &apos;FIRST_VALUE(N.DATANIR)                  OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) DATANIR, &apos;||
        &apos;FIRST_VALUE(N.CODINTR)                  OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) CODINTR, &apos;||
        &apos;ROW_NUMBER()                            OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR DESC) ROWNR &apos;||
        &apos;FROM NIRSTOC NS &apos;||
          &apos;INNER JOIN ( &apos;||
            &apos;SELECT N.CODNIR, N.DATANIR, N.CODINTR, G.CODSUBUNIT &apos;||
            &apos;FROM NIR N &apos;||
              &apos;INNER JOIN NGEST G ON N.GEST = G.CodGest &apos;||vCond_Subunit_G||&apos; &apos;||
            &apos;WHERE TIPNIR IN (1,2,3,4,5,6,7,8,9) AND OPERAT = 1 AND ANULAT = 0 &apos;||
          &apos;) N ON N.CODNIR = NS.CODNIR &apos;||
      &apos;) PRET &apos;||
        &apos;INNER JOIN INTRARI I ON I.CODINTR = PRET.CODINTR &apos;||
        &apos;LEFT JOIN NPART FURN ON FURN.CODPART = I.PARTENER &apos;||
      &apos;WHERE ROWNR = 1&apos;;
  EXECUTE IMMEDIATE sSelect;

  sSelect :=
  &apos;SELECT &apos;||
    &apos;NAO.DENUMIRE, NUM.DEN_UM, PA.PRETACH, &apos;||
    &apos;CASE &apos;||
      &apos;WHEN NVL(SR.Cant, 0)-&apos;||vStocAux||&apos;- NVL(SREZ.REZERVAT, 0) + NVL(CF.RESTA,0) + NVL(CFPER.RESTA,0) - NVL(CC.&apos;||vCampLansat||&apos;,0) - NVL(CIIES.&apos;||vCampLansat||&apos;,0) - NVL(CCPANALA.&apos;||vCampLansat||&apos;,0) - NVL(CIIESPANALA.&apos;||vCampLansat||&apos;,0) - (NVL(PLANIFPREV.CANTC,0) - NVL(PLANIFPREV.RESTA,0)) - (NVL(PLANIFPER.CANTC,0) - NVL(PLANIFPER.RESTA,0))  &gt; 0 then 0 &apos;||
      &apos;ELSE -(NVL(SR.Cant, 0)-&apos;||vStocAux||&apos; - NVL(SREZ.REZERVAT, 0) + NVL(CF.RESTA,0) + NVL(CFPER.RESTA,0) - NVL(CC.&apos;||vCampLansat||&apos;,0) - NVL(CIIES.&apos;||vCampLansat||&apos;,0) - NVL(CCPANALA.&apos;||vCampLansat||&apos;,0) - NVL(CIIESPANALA.&apos;||vCampLansat||&apos;,0) - (NVL(PLANIFPREV.CANTC,0) - NVL(PLANIFPREV.RESTA,0)) - (NVL(PLANIFPER.CANTC,0) - NVL(PLANIFPER.RESTA,0))) &apos;||
    &apos;END CANT, &apos;||
    &apos;CASE &apos;||
      &apos;WHEN NVL(SR.Cant, 0)-&apos;||vStocAux||&apos; + NVL(CF.RESTA,0) + NVL(CFPER.RESTA,0) - NVL(CC.&apos;||vCampLansat||&apos;,0) - NVL(CIIES.&apos;||vCampLansat||&apos;,0) - NVL(CCPANALA.&apos;||vCampLansat||&apos;,0) - NVL(CIIESPANALA.&apos;||vCampLansat||&apos;,0) - (NVL(PLANIFPREV.CANTC,0) - NVL(PLANIFPREV.RESTA,0)) - (NVL(PLANIFPER.CANTC,0) - NVL(PLANIFPER.RESTA,0)) &gt; 0 then 0 &apos;||
      &apos;ELSE -(NVL(SR.Cant, 0)-&apos;||vStocAux||&apos; + NVL(CF.RESTA,0) + NVL(CFPER.RESTA,0) - NVL(CC.&apos;||vCampLansat||&apos;,0) - NVL(CIIES.&apos;||vCampLansat||&apos;,0) - NVL(CCPANALA.&apos;||vCampLansat||&apos;,0) - NVL(CIIESPANALA.&apos;||vCampLansat||&apos;,0) - (NVL(PLANIFPREV.CANTC,0) - NVL(PLANIFPREV.RESTA,0)) - (NVL(PLANIFPER.CANTC,0) - NVL(PLANIFPER.RESTA,0))) * NVL(PA.PRETACH, 0) &apos;||
    &apos;END VAL, &apos;||
    &apos;PA.SURSA, PA.DATAPRET, PA.DEN_PART FURN&apos;||sColMinMax||&apos;, NVL(SR.CANT,0), &apos;||
    &apos;NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0), &apos;||
    &apos;NVL(CFT.CANTC,0), NVL(CFT.CANTA,0), NVL(CFT.RESTA,0), &apos;||
    &apos;NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0), &apos;||
    &apos;NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0), &apos;||
    &apos;NVL(CCPANALA.CANTC,0), NVL(CCPANALA.CANTA,0), NVL(CCPANALA.RESTA,0), &apos;||
    &apos;NVL(CIIESPANALA.CANTC,0), NVL(CIIESPANALA.CANTA,0), NVL(CIIESPANALA.RESTA,0), &apos;||
    &apos;NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART, NVL(SREZ.REZERVAT, 0), NVL(NA.NRZILESTOCMEDIU,&apos;||vNrZileStocMed||&apos;), &apos;||
    &apos;PART.DEN_PART, NUM1.DEN_UM1, OFE1.CANTMIN, OFE1.ZileL, COALESCE(NAOIMP.DURMAXAPROV,NAO.DURMAXAPROV), NVL(CFN.RESTA,0),&apos;||
    &apos;NVL(CCPER.CANTC,0), NVL(CCPER.CANTA,0), NVL(CCPER.RESTA,0), &apos;||
    &apos;NVL(CIPER.CANTC,0), NVL(CIPER.CANTA,0), NVL(CIPER.RESTA,0), &apos;||
    &apos;NVL(CFPER.CANTC,0), NVL(CFPER.CANTA,0), NVL(CFPER.RESTA,0), &apos;||
    &apos;NVL(PLANIFPREV.CANTC,0), NVL(PLANIFPREV.CANTA,0), NVL(PLANIFPREV.CANTC,0) - NVL(PLANIFPREV.RESTA,0), NVL(PLANIFPREV.RESTA,0), &apos;||
    &apos;NVL(PLANIFPER.CANTC,0), NVL(PLANIFPER.CANTA,0), NVL(PLANIFPER.CANTC,0) - NVL(PLANIFPER.RESTA,0), NVL(PLANIFPER.RESTA,0), &apos;||
    &apos;NVL(PLANIFNEXT.CANTC,0), NVL(PLANIFNEXT.CANTA,0), NVL(PLANIFNEXT.CANTC,0) - NVL(PLANIFNEXT.RESTA,0), NVL(PLANIFNEXT.RESTA,0), &apos;||
    &apos;NAO.CodObiect, &apos;||vSetimana||&apos; &apos;||gUserAlias||&apos; &apos;||
  &apos;FROM NARTOBJ NAO &apos;||
    &apos;INNER JOIN TMP_MANEVRA_LISTE MAT ON NAO.CODOBIECT = MAT.VALOARE AND MAT.FILTRU = &apos;&apos;MATERIALE&apos;&apos; &apos;||
    &apos;INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL &apos;||
    &apos;INNER JOIN NUM ON NUM.CODUM = NA.UM &apos;||
    &apos;LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT &apos;||
    &apos;                              and ( NAOS.codgest is null or NAOS.codgest = 0) &apos;||
    &apos;                              AND NAOS.SUBUNITATE = PKG_GLOBALS.GETSUBUNITATE &apos;||
    &apos;LEFT JOIN NARTOBJIMP NAOIMP ON NAO.CODOBIECT = NAOIMP.CODOBIECT AND NAOIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE &apos;||
    &apos;LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT &apos;||
    &apos;LEFT JOIN TMP_STOCREZ SREZ ON SRez.CODOBIECT = NAO.CODOBIECT &apos;||
    &apos;LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CFN ON CFN.CODOBIECT = NAO.CODOBIECT AND CFN.TIP = &apos;&apos;CFN&apos;&apos; AND CFN.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CFT ON CFT.CODOBIECT = NAO.CODOBIECT AND CFT.TIP = &apos;&apos;CFT&apos;&apos; AND CFT.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CCPANALA ON CCPANALA.CODOBIECT = NAO.CODOBIECT AND CCPANALA.TIP = &apos;&apos;CCPANALA&apos;&apos; AND CCPANALA.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CIIESPANALA ON CIIESPANALA.CODOBIECT = NAO.CODOBIECT AND CIIESPANALA.TIP = &apos;&apos;CIIESPANALA&apos;&apos; AND CIIESPANALA.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CCPER ON CCPER.CODOBIECT = NAO.CODOBIECT AND CCPER.TIP = &apos;&apos;CCPER&apos;&apos; AND CCPER.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CIPER ON CIPER.CODOBIECT = NAO.CODOBIECT AND CIPER.TIP = &apos;&apos;CIPER&apos;&apos; AND CIPER.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD CFPER ON CFPER.CODOBIECT = NAO.CODOBIECT AND CFPER.TIP = &apos;&apos;CFPER&apos;&apos; AND CFPER.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD PLANIFPREV ON PLANIFPREV.CODOBIECT = NAO.CODOBIECT AND PLANIFPREV.TIP = &apos;&apos;PLANIFPREV&apos;&apos; AND PLANIFPREV.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD PLANIFPER ON PLANIFPER.CODOBIECT = NAO.CODOBIECT AND PLANIFPER.TIP = &apos;&apos;PLANIFPER&apos;&apos; AND PLANIFPER.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN TMP_CMD PLANIFNEXT ON PLANIFNEXT.CODOBIECT = NAO.CODOBIECT AND PLANIFNEXT.TIP = &apos;&apos;PLANIFNEXT&apos;&apos; AND PLANIFNEXT.USERID = &apos;||vUserId||&apos; &apos;||
    &apos;LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR &apos;||
    &apos;LEFT JOIN TMP_PRETACH PA ON PA.CODOBIECT = NAO.CODOBIECT &apos;||
    &apos;LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = nvl(NA.CLASA,0) &apos;||
    &apos;LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = nvl(NA.CLASASTATIST,0)  &apos;||
    &apos;LEFT JOIN NARTCLI NACLI ON NAO.CODOBIECT = NACLI.CODOBIECT AND NACLI.IMPLICIT = 1 &apos;||
    &apos;LEFT JOIN NPART PART ON NACLI.CODPART = PART.CODPART &apos;||
    &apos;LEFT JOIN OFERTA OFE ON OFE.Partener = NACLI.CODPART AND OFE.DATASTART &lt;= Last_Day(To_Date(&apos;&apos;&apos;||vDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AND OFE.DATAEND &gt;= To_Date(&apos;&apos;&apos;||vDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
    &apos;LEFT JOIN OFERTA1 OFE1 ON OFE1.CODOFERTA = OFE.CODOFERTA AND OFE1.CODOBIECT = NAO.CODOBIECT  &apos;||
    &apos;LEFT JOIN NUM1 ON NUM1.CODUM1 = OFE1.UMSEC &apos;||gSuplJoins||
    sJoinExt;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  sSelect := &apos;update &apos;||tmpName||&apos; set RestA_PlanifNext = 0 where RestA_PlanifNext &lt; 0&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;update &apos;||tmpName||&apos; set RestA_PlanifPrev = 0 where RestA_PlanifPrev &lt; 0&apos;;
  EXECUTE IMMEDIATE sSelect;
  sSelect := &apos;update &apos;||tmpName||&apos; set RestA_PlanifPer = 0 where RestA_PlanifPer &lt; 0&apos;;
  EXECUTE IMMEDIATE sSelect;

  IF NOT vCuNecesarZero THEN
    sSelect := &apos;delete from &apos;||tmpName||&apos; where cant = 0&apos;;
    EXECUTE IMMEDIATE sSelect;
  END IF;

  if PKG_LIST_SELECTSCAD.Extra2 then
    sSelect := &apos;update &apos;||tmpName||&apos; set PretMedAch = pkg_intrari.getpretmediuachiz(CodObiect)&apos;;
    EXECUTE IMMEDIATE sSelect;
  end if;

  --DELETE TMP_CMD WHERE USERID = vUserId;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NAPROVIZ4; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ5</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71B0653290896E2B684DBCE47272EAB74AA2472A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_naproviz5 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vUserID number(20);
  vSubunitatea number(20);
  vAnLucru number(4);
  vLunaLucru number(2);
  vDataRef Date;

procedure MakeIesiri is
BEGIN
  for vLuna in 1..12 loop
    insert into tmp_stocreal_nec5(codobiect, tip, userid)
    select valoare, &apos;IES&apos;||to_char(vLuna), vuserid
    from tmp_manevra_liste
    where filtru = &apos;CODOBIECT&apos;;

    insert into tmp_stocreal_nec5(codobiect, tip, userid)
    select valoare, &apos;IES&apos;||to_char(vLuna)||&apos;P&apos;, vuserid
    from tmp_manevra_liste
    where filtru = &apos;CODOBIECT&apos;;
  end loop;
  for vLuna in 1..12 loop
    update tmp_stocreal_nec5 tmp set cant =
    (select nvl(sum(i1.cant),0)
    from iesiri1 i1
         inner join tmp_manevra_liste tmp on tmp.valoare = i1.codobiect and tmp.filtru = &apos;CODOBIECT&apos;
         inner join iesiri i on i.codies = i1.codies
    where nvl(i.anulat, 0) = 0 and i.operat = 1 and i.an * 12 + i.luna = vAnLucru * 12 + vLuna
          and tmp.codobiect = i1.codobiect and (vSubunitatea = 1 or vSubunitatea = i.subunitatea)
    )
    where tmp.tip = &apos;IES&apos;||to_char(vLuna) and userid = vuserid;

    update tmp_stocreal_nec5 tmp set cant =
    (select nvl(sum(i1.cant),0)
    from iesiri1 i1
         inner join tmp_manevra_liste tmp on tmp.valoare = i1.codobiect and tmp.filtru = &apos;CODOBIECT&apos;
         inner join iesiri i on i.codies = i1.codies
    where nvl(i.anulat, 0) = 0 and i.operat = 1 and i.an * 12 + i.luna = (vAnLucru - 1) * 12 + vLuna
          and tmp.codobiect = i1.codobiect  and (vSubunitatea = 1 or vSubunitatea = i.subunitatea))
    where tmp.tip = &apos;IES&apos;||to_char(vLuna)||&apos;P&apos; and userid = vuserid;
  end loop;
END;

procedure MakeConsumuri is
BEGIN
  for vLuna in 1..12 loop
    insert into tmp_stocreal_nec5(codobiect, tip, userid)
    select tmp.valoare, &apos;C&apos;||to_char(vLuna), vuserid
    from tmp_manevra_liste tmp where tmp.filtru = &apos;CODOBIECT&apos;;
  end loop;
  for vLuna in 1..12 loop
    update tmp_stocreal_nec5 tmp set cant =
    (select nvl(sum(cant),0) from (
    select mat.codobiect, mat.rest cant, &apos;C&apos;||to_char(vLuna) tip
    from cmdprodmat mat
         inner join comanda1 c1 on c1.codcomanda1 = mat.codcomanda1
         inner join comanda c on c.codcomanda = c1.codcomanda
    where c.anulat = 0 and c.operat = 1 and extract(year from c1.termen) * 12 + extract(month from c1.termen) = vAnLucru * 12 + vLuna
          and (pkg_list_selfisamag.isToateArt = 1 or exists (select valoare from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos; and valoare = mat.CODOBIECT))
          and (vSubunitatea = 1 or vSubunitatea = c.subunitatea) and mat.tip = 1
    UNION ALL
    select pn.codobiect, (c1.cantacceptat-nvl(lansari.cant,0)) / pn0.cant * pn.cant cant, &apos;C&apos;||to_char(vLuna) tip
    from proiectnod pn
         inner join proiectnod pn0 on pn.codproiect = pn0.codproiect and pn0.nodoriginal = 0
         inner join comanda1 c1 on c1.codproiect = pn.codproiect
         inner join comanda c on c.codcomanda = c1.codcomanda
         left join (select sum(cant) cant, cmdlink.codliniecomanda codcomanda1, c1.codobiect
                    from cmdlink
                         inner join comanda1 c1 on c1.codcomanda1 = cmdlink.codcomanda1
                    group by cmdlink.codliniecomanda, c1.codobiect
                   ) lansari on lansari.codcomanda1 = c1.codcomanda1 and lansari.codobiect = c1.codobiect
    where c.tipdoc = 18 and c.anulat = 0 and c.operat = 1 and extract(year from c1.termen) * 12 + extract(month from c1.termen) = vAnLucru * 12 + vLuna
          and (pkg_list_selfisamag.isToateArt = 1 or exists (select valoare from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos; and valoare = pn.CODOBIECT))
          and (vSubunitatea = 1 or vSubunitatea = c.subunitatea)
    )
    where codobiect = tmp.codobiect)
    where tmp.tip = &apos;C&apos;||to_char(vLuna) and userid = vuserid;
  end loop;
END;

procedure MakeComenzi is
BEGIN
  for vLuna in 1..12 loop
    insert into tmp_stocreal_nec5(codobiect, tip, userid)
    select tmp.valoare, &apos;COM&apos;||to_char(vLuna) tip, vuserid
    from tmp_manevra_liste tmp where tmp.filtru = &apos;CODOBIECT&apos;;
  end loop;
  for vLuna in 1..12 loop
    update tmp_stocreal_nec5 tmp set cant =
    (select nvl(sum(c1.restacceptat),0)
    from comanda1 c1
         inner join comanda c on c.codcomanda = c1.codcomanda
    where c.tipdoc = 8 and c.anulat = 0 and c.operat = 1 and extract(year from c1.termen) * 12 + extract(month from c1.termen) = vAnLucru * 12 + vLuna
          and c1.codobiect = tmp.codobiect and (vSubunitatea = 1 or vSubunitatea = c.subunitatea)
    )
    where tmp.tip = &apos;COM&apos;||to_char(vLuna) and userid = vuserid;
  end loop;
END;

procedure MakeStocuri IS
  anlunamax INTEGER;
BEGIN
  for vLuna in 1..12 loop
    insert into tmp_stocreal_nec5(codobiect, tip, userid)
    select valoare, &apos;S&apos;||to_char(vLuna), vuserid
    from tmp_manevra_liste
    where filtru = &apos;CODOBIECT&apos;;
  end loop;

  SELECT anmaxim*12+lunamaxima INTO anlunamax FROM FirmaLuni;

  for vLuna in 1..12 loop
    if vLuna &lt; anlunamax /*pkg_globals.GetLUNALUCRU*/ then
      update tmp_stocreal_nec5 tmp set cant =
      (SELECT nvl(sum(NL.REST),0)
      FROM
        NIRLUNA NL,
        NIRSTOC NS,
        NIR N,
        NGEST G,
        IOART1 IO1
      WHERE
        NS.CODNIR = N.CODNIR
        AND N.GEST = G.CODGEST
        AND NL.AN = vAnLucru
        AND NL.LUNA = vLuna
        AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
        AND NL.CODNIRSTOC = NS.CODNIRSTOC
        AND NS.CODIOART = IO1.CODIOART
        AND IO1.MG &lt;&gt; 5
        and (pkg_list_selfisamag.getNumToateGest = 1 or exists (select valoare from tmp_manevra_liste where filtru = &apos;CODGEST&apos; and valoare = N.GEST))
        and tmp.codobiect = ns.codobiect
        and (vSubunitatea = 1 or vSubunitatea = G.CODSUBUNIT)
        and (vAnLucru*12+vLuna) BETWEEN IO1.ALStart and IO1.ALStop
        and tmp.codobiect = ns.codobiect)
        where &apos;S&apos;||to_char(vLuna) = tmp.tip and userid = vuserid;
    elsif vLuna = anlunamax /*pkg_globals.GetLUNALUCRU*/ then
      update tmp_stocreal_nec5 tmp set cant =
      (SELECT nvl(sum(NS.REST),0)
      FROM
        NIRSTOC NS,
        NIR N,
        NGEST G,
        IOART1 IO1
      WHERE
        NS.CODNIR = N.CODNIR
        AND N.GEST = G.CODGEST
        AND NVL(NS.REST, 0) + NVL(NS.RESTUM1, 0) + NVL(NS.RESTUM2, 0) &lt;&gt; 0
        AND NS.CODIOART = IO1.CODIOART
        AND IO1.MG &lt;&gt; 5
        and (pkg_list_selfisamag.getNumToateGest = 1 or exists (select valoare from tmp_manevra_liste where filtru = &apos;CODGEST&apos; and valoare = N.GEST))
        and tmp.codobiect = ns.codobiect
        and (vSubunitatea = 1 or vSubunitatea = G.CODSUBUNIT)
        and (vAnLucru*12+vLuna) BETWEEN IO1.ALStart and IO1.ALStop
        and tmp.codobiect = ns.codobiect)
        where &apos;S&apos;||to_char(vLuna) = tmp.tip and userid = vuserid;
    end if;
  end loop;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
aSQL varchar2(1000);
sInsert varchar2(10000);
BEGIN
  vUserID := pkg_globals.GETUserID;
  vSubunitatea := pkg_globals.GETSUBUNITATE;
  vAnLucru := pkg_globals.GETANLUCRU;
  vLunaLucru := pkg_globals.GETLUNALUCRU;
  vDataRef := pkg_list_selfisamag.getDataRef;
  DELETE tmp_stocreal_nec5 where userid = vuserid;
  DELETE NECESAR5 WHERE USERID = vUserID;
  if PKG_LIST_SELFISAMAG.isToateArt = 1 then
    delete from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos;;
    if PKG_LIST_SELFISAMAG.RezUM1 then
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODOBIECT&apos;, CodObiect
      from nartobj
      where nvl(produspropriu,0) = 0;
    else
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODOBIECT&apos;, CodObiect
      from nartobj;
    end if;
  end if;

  MakeStocuri;
  MakeIesiri;
  MakeConsumuri;
  MakeComenzi;

  for v_rec in (select obj.codobiect, obj.denumire, nvl(objs.stocmin,0) stocmin, pkg_oferta.GetCodOferta1PretMin(obj.codobiect, vDataRef) CodOferta1
                from tmp_manevra_liste tmp
                     inner join nartobj obj on obj.codobiect = tmp.valoare
                     left join nartobjsubunit objs on objs.codobiect = obj.codobiect 
                                                   and (objs.codgest is null or objs.codgest = 0)
                                                   and objs.subunitate = vSUBUNITATEA
                where tmp.filtru = &apos;CODOBIECT&apos;) loop
    insert into necesar5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Consum an precedent&apos;,1,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Consum efectiv an curent&apos;,2,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Stoc la moment&apos;,3,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Consum rezervat&apos;,4,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Comenzi in curs&apos;,5,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Propunere de cumparare&apos;,6,v_rec.stocmin,0,vUserID);
    insert into NECESAR5 (codobiect,denumire,indicator,nrindicator,stocmin,cantmin,userid)
    values (v_rec.codobiect,v_rec.denumire,&apos;Stoc prognozat&apos;,7,v_rec.stocmin,0,vUserID);

    for v_luni in 1..12 loop
      aSQL := &apos;update NECESAR5 NEC5 set &apos;||
              &apos;  L&apos;||v_luni||&apos; = case nrindicator &apos;||
              &apos;                    when 1 then (SELECT NVL(CANT,0) FROM tmp_stocreal_nec5 TMP WHERE TMP.USERID = &apos;||VUSERID||&apos; AND TMP.CODOBIECT = NEC5.CODOBIECT AND TMP.TIP = &apos;&apos;IES&apos;||V_LUNI||&apos;P&apos;&apos;)&apos;||
              &apos;                    when 2 then (SELECT NVL(CANT,0) FROM tmp_stocreal_nec5 TMP WHERE TMP.USERID = &apos;||VUSERID||&apos; AND TMP.CODOBIECT = NEC5.CODOBIECT AND TMP.TIP = &apos;&apos;IES&apos;||V_LUNI||&apos;&apos;&apos;)&apos;||
              &apos;                    when 3 then (SELECT NVL(CANT,0) FROM tmp_stocreal_nec5 TMP WHERE TMP.USERID = &apos;||VUSERID||&apos; AND TMP.CODOBIECT = NEC5.CODOBIECT AND TMP.TIP = &apos;&apos;S&apos;||V_LUNI||&apos;&apos;&apos;)&apos;||
              &apos;                    when 4 then (SELECT NVL(CANT,0) FROM tmp_stocreal_nec5 TMP WHERE TMP.USERID = &apos;||VUSERID||&apos; AND TMP.CODOBIECT = NEC5.CODOBIECT AND TMP.TIP = &apos;&apos;C&apos;||V_LUNI||&apos;&apos;&apos;)&apos;||
              &apos;                    when 5 then (SELECT NVL(CANT,0) FROM tmp_stocreal_nec5 TMP WHERE TMP.USERID = &apos;||VUSERID||&apos; AND TMP.CODOBIECT = NEC5.CODOBIECT AND TMP.TIP = &apos;&apos;COM&apos;||V_LUNI||&apos;&apos;&apos;)&apos;||
              &apos;                  end &apos;||
              &apos;where codobiect = &apos;||v_rec.codobiect||&apos; and userid = &apos;||vUserID||&apos; and nec5.codobiect = &apos;||v_rec.codobiect;
      DELETE X;
      INSERT INTO X(TEST) VALUES(aSQL);
      COMMIT;
      execute immediate aSQL;
    end loop;

    for v_luni in vLunaLucru..12 loop
      aSQL := &apos;update NECESAR5 NEC5 set &apos;||
              &apos;  L&apos;||v_luni||&apos; = 0&apos;||
              &apos;where L&apos;||v_luni||&apos; is null and userid = &apos;||vUserID||&apos; and nec5.codobiect = &apos;||v_rec.codobiect;
      execute immediate aSQL;
    end loop;

    for v_luni in vLunaLucru..12 loop
      aSQL := &apos;update NECESAR5 NEC5 set &apos;||
              &apos;  L&apos;||v_luni||&apos; = StocMin - (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 3 and tmp.userid = nec5.userid )&apos;||
              &apos;                          + (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 4 and tmp.userid = nec5.userid )&apos;||
              &apos;                          - (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 5 and tmp.userid = nec5.userid )&apos;||
              &apos;where nrindicator = 6 and userid = &apos;||vUserID||&apos; and nec5.codobiect = &apos;||v_rec.codobiect;
      execute immediate aSQL;
      aSQL := &apos;update NECESAR5 NEC5 set &apos;||
              &apos;  L&apos;||v_luni||&apos; = 0 &apos;||
              &apos;where nrindicator = 6 and L&apos;||v_luni||&apos; &lt; 0 and userid = &apos;||vUserID||&apos; and nec5.codobiect = &apos;||v_rec.codobiect;
      execute immediate aSQL;
    end loop;

    for v_luni in vLunaLucru..12 loop
      aSQL := &apos;update NECESAR5 NEC5 set &apos;||
              &apos;  L&apos;||v_luni||&apos; = (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 3 and tmp.userid = nec5.userid )&apos;||
              &apos;                - (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 4 and tmp.userid = nec5.userid )&apos;||
              &apos;                + (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 5 and tmp.userid = nec5.userid )&apos;||
              &apos;                + (select tmp.L&apos;||v_luni||&apos; from NECESAR5 tmp where tmp.codobiect = nec5.codobiect and tmp.nrindicator = 6 and tmp.userid = nec5.userid )&apos;||
              &apos;where nrindicator = 7 and userid = &apos;||vUserID||&apos; and nec5.codobiect = &apos;||v_rec.codobiect;
      execute immediate aSQL;
    end loop;

    update NECESAR5 tmp set
      pret = (select nvl(o1.pret,0)
              from oferta1 o1
              where v_rec.codoferta1 = o1.codoferta1),
      furnizor = (select nvl(p.den_part,&apos;&apos;)
                  from oferta1 o1
                       inner join oferta o on o1.codoferta = o.codoferta
                       inner join npart p on o.partener= p.codpart
                  where v_rec.codoferta1 = o1.codoferta1),
      cantmin = (select nvl(o1.cantmin,0)
                 from oferta1 o1
                 where v_rec.codoferta1 = o1.codoferta1)
    where tmp.userid = vUserid and tmp.codobiect = v_rec.codobiect;
  end loop;

  gSuplCols := &apos;NARTOBJ OBJ&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;
  INSERT INTO &apos;||tmpName ||&apos;(
    DENUMIRE,
    INDICATOR,
    STOCMIN,
    PRET,
    FURNIZOR,
    CANTMIN,
    ORDINE,
    L1,
    L2,
    L3,
    L4,
    L5,
    L6,
    L7,
    L8,
    L9,
    L10,
    L11,
    L12 &apos;||gUserFields||&apos;)
  SELECT
    tmp.DENUMIRE,
    tmp.INDICATOR,
    tmp.STOCMIN,
    tmp.PRET,
    tmp.FURNIZOR,
    tmp.CANTMIN,
    tmp.NRINDICATOR,
    tmp.L1,
    tmp.L2,
    tmp.L3,
    tmp.L4,
    tmp.L5,
    tmp.L6,
    tmp.L7,
    tmp.L8,
    tmp.L9,
    tmp.L10,
    tmp.L11,
    tmp.L12 &apos;||gUserAlias||&apos;
  FROM NECESAR5 tmp
    inner join nartobj obj on tmp.codobiect = obj.codobiect&apos;||
    gSuplJoins||&apos;
  where tmp.userid = &apos;||vUserID||&apos;
  order by nrindicator&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  DELETE tmp_stocreal_nec5 where userid = vuserid;
  DELETE NECESAR5 WHERE USERID = vUserID;
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

procedure Test is
begin
  delete tmp_manevra_liste;
  delete tmp_stocreal_nec5;
  insert into tmp_manevra_liste(filtru, valoare)
  values (&apos;CODOBIECT&apos;, &apos;288&apos;);
  MakeConsumuri;
  commit;
end;

end pkg_list_base_naproviz5;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ6</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>891E580F3B2B24DA1FA470EF76B844A8086C2594</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ6 is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(32000);
sSelect   VARCHAR2( 2000);
vSelStocReal VARCHAR2( 2000);
vUserID     number(20);
vCondSub_G  varchar2(100);
vSelIes_Per VARCHAR2( 3000);
vSelIes_PerP VARCHAR2( 3000);
vSelIes_Per12 VARCHAR2( 3000);
vSelIes_Per3 VARCHAR2( 3000);
vZiuaIniC   DATE;
vZiuaFinC   DATE;
vZiuaIni    DATE;
vZiuaFin    DATE;
vTipVanz    varchar2(200);
vToateGest boolean;
vToateIOArt boolean;
vCateGest NUMBER(10);
vCatelGest NUMBER(10);
vAux VARCHAR2(100);
sUltCant VARCHAR2( 50);
vUltAchiz BOOLEAN;
vFiltruTermen VARCHAR2(1000);
vCondSub_C VARCHAR2(  100);
LastPret number(1);
BEGIN
  BEGIN
    SELECT TO_NUMBER(COALESCE(PKG_CATEGCONST.GetValConstanta(&apos;LastPretGenCmdF&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),&apos;0&apos;)) INTO LastPret FROM DUAL;
    EXCEPTION WHEN OTHERS THEN LastPret := 0;
  END;
  vUserId     := Nvl(pkg_globals.GETUSERID,0);
  vCondSub_G  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);

  gSuplCols := &apos;NARTOBJ NAO, NART NA, NARTOBJSUBUNIT NAOS, NUM NUM, NPART PROD, NCLASEA CLSA, NCLASEAS CLSAS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vZiuaIniC   := pkg_list_base_naproviz2.GETDATACINI;
  vZiuaFinC   := pkg_list_base_naproviz2.GETDATACFIN;
  vZiuaIni    := pkg_list_base_naproviz2.GETDATAVINI;
  vZiuaFin    := pkg_list_base_naproviz2.GETDATAVFIN;
  vTipVanz    := pkg_list_base_naproviz2.GetTipVanz;
  vToateGest  := pkg_list_base_naproviz2.GetAllGest  = 1;
  vToateIOArt := pkg_list_base_naproviz2.GetAllIOArt = 1;
  vUltAchiz   := pkg_list_base_naproviz2.GETULTACHIZ;
  vCondSub_C  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  vFiltruTermen := &apos;&apos;;
  if pkg_list_base_naproviz2.GETCUTERMEN = 1 then
    vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(pkg_list_base_naproviz2.gettermen)||&apos;&apos;&apos; &apos;;
  end if;
  DELETE TMP_STOCREAL;
  DELETE TMP_CMD WHERE USERID = VUSERID;

  sSelect := &apos;INSERT INTO tmp_cmd(codobiect,cantc,canta,resta,tip,userid,auxfield,D1,D2,D3)
  SELECT C1.CodObiect,
    SUM(C1.CantComandat) CantC,
    SUM(C1.CantAcceptat) CantA,
    SUM(C1.RestAcceptat) RestA, &apos;&apos;CF&apos;&apos;,&apos;||vUserId||&apos;, String_Agg(to_char(C.nrdoc)),C1.D1,C1.D2,C1.D3
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
  WHERE Nvl(C.INCHISA, 0) = 0
    AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
    AND C1.RestAcceptat &gt; 0
  GROUP BY C1.CodObiect,C1.D1,C1.D2,C1.D3&apos;;
  EXECUTE IMMEDIATE sSelect;

  vSelStocReal := &apos;
  SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
  WHERE NS.REST &lt;&gt; 0&apos;;

  vSelIes_Per  := &apos;
  SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES&apos;&apos;
  FROM LIVR L
    INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN IESIRI I ON L.CODIES = I.CODIES
    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
  WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIniC)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFinC)||&apos;&apos;&apos;
    AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

  vSelIes_Per12  := &apos;
  SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES12&apos;&apos;
  FROM LIVR L
    INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN IESIRI I ON L.CODIES = I.CODIES
    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
  WHERE L.DATALIVR BETWEEN to_date(&apos;&apos;&apos;||to_char(add_months(vZiuaIniC,-12),&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND
    to_date(&apos;&apos;&apos;||to_char(vZiuaIniC-1,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

  --insert into x(test) values (vSelIes_Per12);

  vSelIes_Per3  := &apos;
  SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IES3&apos;&apos;
  FROM LIVR L
    INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN IESIRI I ON L.CODIES = I.CODIES
    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
  WHERE L.DATALIVR BETWEEN to_date(&apos;&apos;&apos;||to_char(add_months(vZiuaIniC,-3),&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND
    to_date(&apos;&apos;&apos;||to_char(vZiuaIniC-1,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

  vSelIes_PerP  := &apos;
  SELECT NS.CODOBIECT, SUM(L1.CANT) CANT, &apos;&apos;IESP&apos;&apos;
  FROM LIVR L
    INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN IESIRI I ON L.CODIES = I.CODIES
    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST G ON G.CODGEST = N.GEST
  WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(vZiuaIni)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(vZiuaFin)||&apos;&apos;&apos;
    AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||vTipVanz||&apos;)&apos;;

  IF NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    vAux := &apos;
    AND&apos;;
    IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
    ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
    END IF;
    vSelStocReal  := vSelStocReal ||vAux;
    vSelIes_Per   := vSelIes_Per  ||vAux;
    vSelIes_Per12 := vSelIes_Per12||vAux;
    vSelIes_Per3  := vSelIes_Per3 ||vAux;
    vSelIes_PerP  := vSelIes_PerP ||vAux;
  END IF;

  IF NOT vToateIOArt THEN
    vAux := &apos;
    AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
    vSelStocReal  := vSelStocReal ||vAux;
    vSelIes_Per   := vSelIes_Per  ||vAux;
    vSelIes_Per12 := vSelIes_Per12||vAux;
    vSelIes_Per3  := vSelIes_Per3 ||vAux;
    vSelIes_PerP  := vSelIes_PerP ||vAux;
  END IF;

  vSelStocReal := vSelStocReal ||&apos;
  GROUP BY NS.CODOBIECT&apos;;
  vSelIes_Per  := vSelIes_Per||&apos;
  GROUP BY NS.CODOBIECT&apos;;
  vSelIes_Per12  := vSelIes_Per12||&apos;
  GROUP BY NS.CODOBIECT&apos;;
  vSelIes_Per3  := vSelIes_Per3||&apos;
  GROUP BY NS.CODOBIECT&apos;;
  vSelIes_PerP := vSelIes_PerP||&apos;
  GROUP BY NS.CODOBIECT&apos;;


  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelStocReal;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Per;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Per12;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_Per3;
  EXECUTE IMMEDIATE &apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelIes_PerP;

  IF vUltAchiz
  THEN
    sSelect := &apos;INSERT INTO tmp_cmd(codobiect,D1,tip,UserID)&apos;||chr(13)||
               &apos;SELECT NS.CODOBIECT, MAX(NS.CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY NS.DATAACHIZ, NS.CODNIRSTOC) CODNIRSTOC,&apos;&apos;ULT&apos;&apos;,&apos;||vUserID||CHR(13)||
               &apos;FROM (SELECT CODNIRSTOC,CODNIR,FURN,CODNIRSTOCPARINTE,CODOBIECT,DATAACHIZ FROM NIRSTOC WHERE NOT DATAACHIZ IS NULL) NS &apos;||CHR(13)||
               &apos;     INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||chr(13)||
               &apos;     INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||chr(13);
    if tmpName = &apos;TMP_LST_NAPR6&apos; then
      if LastPret &lt;&gt; 1 then
        sSelect := sSelect||vCondSub_G||chr(13);
      end if;
    else
      sSelect := sSelect||vCondSub_G||chr(13);
    end if;  
    sSelect := sSelect||&apos;WHERE NS.FURN &gt; 0 AND Nvl(NS.CODNIRSTOCPARINTE,0) = 0 AND N.TIPNIR IN (1,2,3,4,5,6) GROUP BY NS.CODOBIECT&apos;;
    EXECUTE IMMEDIATE sSelect;
    sSelect := &apos;INSERT INTO tmp_cmd(codobiect,D1,tip,UserID)&apos;||chr(13)||
               &apos;SELECT NS.CODOBIECT, MAX(NS.CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY NS.DATAACHIZ, NS.CODNIRSTOC) CODNIRSTOC,&apos;&apos;PULT&apos;&apos;,&apos;||vUserID||CHR(13)||
               &apos;FROM (SELECT CODNIRSTOC,CODNIR,FURN,CODNIRSTOCPARINTE,CODOBIECT,DATAACHIZ FROM NIRSTOC WHERE NOT DATAACHIZ IS NULL &apos;||chr(13)||
               &apos;      MINUS&apos;||chr(13)||
               &apos;      SELECT T.D1 codnirstoc, NSS.CODNIR,NSS.FURN,NSS.CODNIRSTOCPARINTE,NSS.CODOBIECT,NSS.DATAACHIZ&apos;||CHR(13)||
               &apos;      FROM TMP_CMD T&apos;||CHR(13)||
               &apos;           INNER JOIN NIRSTOC NSS ON NSS.CODNIRSTOC = T.D1&apos;||CHR(13)||
               &apos;      WHERE T.USERID = &apos;||VUSERID||&apos; AND T.TIP = &apos;&apos;ULT&apos;&apos; &apos;||CHR(13)||
               &apos;     ) NS &apos;||CHR(13)||
               &apos;     INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||chr(13)||
               &apos;     INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||chr(13);
    if tmpName = &apos;TMP_LST_NAPR6&apos; then           
      if LastPret &lt;&gt; 1 then
        sSelect := sSelect||vCondSub_G||chr(13);
      end if;
    else
      sSelect := sSelect||vCondSub_G||chr(13);
    end if;  
    sSelect := sSelect||&apos;WHERE NS.FURN &gt; 0 AND Nvl(NS.CODNIRSTOCPARINTE,0) = 0 AND N.TIPNIR IN (1,2,3,4,5,6) GROUP BY NS.CODOBIECT&apos;;
    EXECUTE IMMEDIATE sSelect;
    sUltCant := &apos;UNS.CANTNIR ULTCANT&apos;;
  ELSE
    sUltCant := &apos;0 ULTCANT&apos;;
  END IF;

  if tmpName = &apos;TMP_LST_NAPR6&apos; then
    DELETE TMP_LST_NAPR6;
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      DENUMIRE,
      STOCMIN,
      STOC,
      CANT,
      CANTPREC,
      RATA,
      NECESAR,
      CODINTERN,
      CODEXTERN,
      UM,
      CODUM1,
      CODOBIECT,
      PRODUCATOR,
      ULTFURN,
      ULTPRACHIZ,
      CODULTFURN,
      CODLOCATIE,
      CODMONEDA,
      CODCATALOG,
      IES12,
      IES3,
      NECESAR2,
      PULTFURN,
      PULTPRACHIZ,
      RESTA_CF,
      ULTCANT
       )
    SELECT
      DENUMIRE,
      STOCMIN,
      STOC,
      CANT,
      CANTPREC,
      case when cantprec = 0 then 0 else CANT/CANTPREC end,
      case when cantprec = 0 then 0 else ROUND((CANT - STOC)*CANT/CANTPREC) end,
      CODINTERN,
      CODEXTERN,
      UM,
      CODUM1,
      CODOBIECT,
      PRODUCATOR,
      ULTFURN,
      ULTPRACHIZ,
      CODULTFURN,
      CODLOCATIE,
      CODMONEDA,
      CODCATALOG,
      IES12,
      IES3,
      NECESAR2,
      PULTFURN,
      PULTPRACHIZ,
      RESTA_CF,
      ULTCANT
    FROM (
    SELECT
      NAO.DENUMIRE,
      NAOS.STOCMIN,
      NVL(SR.CANT,0) STOC,
      NVL(IP.CANT,0) CANT,
      NVL(IPP.CANT,0) CANTPREC,
      NAO.CODINTERN,
      NAO.CODEXTERN,
      NUM.DEN_UM UM,
      NUM1.CODUM1,
      NAO.CODOBIECT,
      PROD.DEN_PART PRODUCATOR,
      UF.DEN_PART ULTFURN,
      NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0) ULTPRACHIZ,
      UF.CODPART CODULTFURN,
      UINTR.CODLOCATIE,
      UINTR.MONEDA CODMONEDA,
      case
        when NA.codexternart is null then NA.sufixcodextern
        when NA.sufixcodextern is null then NA.codexternart
        else NA.codexternart||&apos;&apos;_&apos;&apos;||NA.sufixcodextern
      end CODCATALOG,
      Round(NVL(I12.CANT,0)/12,2) IES12,
      Round(NVL(I3.CANT,0)/3,2) IES3,
      case when (NVL(IP.CANT,0)+NVL(IPP.CANT,0))/2 - NVL(SR.CANT,0) &lt; 0 then 0 else (NVL(IP.CANT,0)+NVL(IPP.CANT,0))/2 - NVL(SR.CANT,0) end NECESAR2,
      PUF.DEN_PART PULTFURN,
      NVL(PUNS.PRET,0) - Nvl(PUNS.ADAOS,0) PULTPRACHIZ,
      CF.RESTA RESTA_CF,
      &apos;||sUltCant||&apos;
    FROM NARTOBJ NAO
      INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT JOIN TMP_CMD X ON X.CODOBIECT = NAO.CODOBIECT AND X.TIP = &apos;&apos;ULT&apos;&apos; AND X.USERID = &apos;||VUSERID||&apos;
      LEFT JOIN TMP_CMD PX ON PX.CODOBIECT = NAO.CODOBIECT AND PX.TIP = &apos;&apos;PULT&apos;&apos; AND PX.USERID = &apos;||VUSERID||&apos;
      LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.D1
      LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
      LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR
      LEFT JOIN NPART UF ON UF.CODPART = UNS.FURN
      LEFT JOIN NIRSTOC PUNS ON PUNS.CODNIRSTOC = PX.D1
      LEFT JOIN NPART PUF ON PUF.CODPART = PUNS.FURN
      LEFT JOIN NUM1 ON NUM.CODUM = NUM1.CODUM AND NVL(NUM1.SECUNDARA,0) = 0
      LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT AND (NAOS.codgest is null or NAOS.codgest = 0) AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos;
      LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
      LEFT JOIN TMP_STOCREAL IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
      LEFT JOIN TMP_STOCREAL I12 ON I12.CODOBIECT = NAO.CODOBIECT AND I12.TIP = &apos;&apos;IES12&apos;&apos;
      LEFT JOIN TMP_STOCREAL I3 ON I3.CODOBIECT = NAO.CODOBIECT AND I3.TIP = &apos;&apos;IES3&apos;&apos;
      LEFT JOIN TMP_STOCREAL IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESP&apos;&apos;
      LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
      LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST
      LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||VUSERID||&apos;
    WHERE NA.TIPARTICOL = 0 AND NVL(NAO.INACTIV,0) = 0 &apos;;
    if pkg_list_base_naproviz2.GETCLASA &gt; 0 then
      sInsert := sInsert||&apos; and na.clasa = &apos;||pkg_list_base_naproviz2.GETCLASA;
    end if;
    if pkg_list_base_naproviz2.GETCLASAS &gt; 0 then
      sInsert := sInsert||&apos; and na.clasastatist = &apos;||pkg_list_base_naproviz2.GETCLASAS;
    end if;
    if pkg_list_base_naproviz2.GETPROD &gt; 0 then
      sInsert := sInsert||&apos; and nao.codproducator = &apos;||pkg_list_base_naproviz2.GETPROD;
    end if;
    sInsert := sInsert||&apos;)&apos;;
  else
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      DENUMIRE,
      STOCMIN,
      STOC,
      CANT,
      CANTPREC,
      RATA,
      NECESAR,
      ULTFURN,
      ULTPRACHIZ,
      IES12,
      IES3,
      NECESAR2,
      PULTFURN,
      PULTPRACHIZ,
      RESTA_CF,
      ULTCANT &apos;||gUserFields||&apos;)
    SELECT
      NAO.DENUMIRE,
      NAOS.STOCMIN,
      NVL(SR.CANT,0) STOC,
      NVL(IP.CANT,0) CANT,
      NVL(IPP.CANT,0) CANTPREC,
      case when NVL(IPP.CANT,0) = 0 then 0 else NVL(IP.CANT,0)/NVL(IPP.CANT,0) end RATA,
      case when NVL(IPP.CANT,0) = 0 then 0 else ROUND((NVL(IP.CANT,0) - NVL(SR.CANT,0))*NVL(IP.CANT,0)/NVL(IPP.CANT,0)) end NECESAR,
      UF.DEN_PART ULTFURN,
      NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0) ULTPRACHIZ,
      Round(NVL(I12.CANT,0)/12,2) IES12,
      Round(NVL(I3.CANT,0)/3,2) IES3,
      case when (NVL(IP.CANT,0)+NVL(IPP.CANT,0))/2 - NVL(SR.CANT,0) &lt; 0 then 0 else (NVL(IP.CANT,0)+NVL(IPP.CANT,0))/2 - NVL(SR.CANT,0) end NECESAR2,
      PUF.DEN_PART PULTFURN,
      NVL(PUNS.PRET,0) - Nvl(PUNS.ADAOS,0) PULTPRACHIZ,
      CF.RESTA RESTA_CF,
      &apos;||sUltCant||&apos;
      &apos;||gUserAlias||&apos;
    FROM NARTOBJ NAO
      INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT JOIN TMP_CMD X ON X.CODOBIECT = NAO.CODOBIECT AND X.TIP = &apos;&apos;ULT&apos;&apos; AND X.USERID = &apos;||VUSERID||&apos;
      LEFT JOIN TMP_CMD PX ON PX.CODOBIECT = NAO.CODOBIECT AND PX.TIP = &apos;&apos;PULT&apos;&apos; AND PX.USERID = &apos;||VUSERID||&apos;
      LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.D1
      LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
      LEFT JOIN NIRSTOC PUNS ON PUNS.CODNIRSTOC = PX.D1
      LEFT JOIN NPART PUF ON PUF.CODPART = PUNS.FURN
      LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT and (NAOS.codgest is null or NAOS.codgest = 0) AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos;
      LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
      LEFT JOIN TMP_STOCREAL IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
      LEFT JOIN TMP_STOCREAL IPP ON IPP.CODOBIECT = NAO.CODOBIECT AND IPP.TIP = &apos;&apos;IESP&apos;&apos;
      LEFT JOIN TMP_STOCREAL I12 ON I12.CODOBIECT = NAO.CODOBIECT AND I12.TIP = &apos;&apos;IES12&apos;&apos;
      LEFT JOIN TMP_STOCREAL I3 ON I3.CODOBIECT = NAO.CODOBIECT AND I3.TIP = &apos;&apos;IES3&apos;&apos;
      LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
      LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST
      LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||VUSERID||&apos;&apos;||
      gSuplJoins||&apos;
    WHERE NA.TIPARTICOL = 0 AND NVL(NAO.INACTIV,0) = 0 &apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert := &apos;update &apos;||tmpName||&apos; set necesar = 0 where necesar &lt; 0&apos;;
  EXECUTE IMMEDIATE sInsert;
  sInsert := &apos;update &apos;||tmpName||&apos; set necesar2 = case when trunc(necesar2) = necesar2 then necesar2 else trunc(necesar2) + 1 end&apos;;
  EXECUTE IMMEDIATE sInsert;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

procedure UmpleTabela6Z(aDataRef in varchar2,
                        pClasa IN NUMBER DEFAULT 0,
                        pClasaS IN NUMBER DEFAULT 0,
                        pProd IN NUMBER DEFAULT 0,
                        pClasaW IN NUMBER DEFAULT 0) is
begin
  delete tmp_lst_napr6;
  insert into tmp_lst_napr6(denumire,stocmin,stoc,codintern,codextern,um,codum1,
                            codobiect,subunitatea,den_subunit,producator,
                            zile,datacmd,codpart,peraproviz,ULTPRACHIZ,codcatalog)
  with Ach as (
    select distinct i1.codobiect, i.partener, nvl(ps.peraproviz,0) peraproviz
    from intrari i
         inner join intrari1 i1 on i1.codintr = i.codintr
         inner join npart p on p.codpart = i.partener
         inner join nartobj obj on obj.codobiect = i1.codobiect
         inner join nart art on art.codarticol = obj.codarticol
         left join npartsubunit ps on ps.codpart = p.codpart and ps.subunitatea = i.subunitatea
    where i.anulat = 0 and p.codpart &gt; 0 and i.subunitatea = pkg_globals.GETSUBUNITATE
      and art.tiparticol = &apos;0&apos; and (pClasa = 0 or art.clasa = pClasa) and (pClasaS = 0 or art.clasastatist = pClasaS)
      and (pClasaW = 0 or art.clasaw = pClasaW)and (pProd = 0 or obj.codproducator = pProd)
      and i.tipdoc in (1,2,3,4,5)
    order by i.partener, i1.codobiect
  ),
  LastCmd as (
    select distinct partener, codobiect, datadoc, LastPretCmd
    from
    (
      select x.partener, x.codobiect, x.datadoc, min(c1.pu) LastPretCmd
      from (
        select c.partener, c1.codobiect, max(c.datadoc) datadoc
        from comanda c inner join comanda1 c1 on c1.codcomanda = c.codcomanda
        where c.tipdoc = 8 and c.subunitatea = pkg_globals.GETSUBUNITATE
        group by c.partener, c1.codobiect
      ) x
        inner join comanda c on c.datadoc = x.datadoc and c.partener = x.partener
        inner join comanda1 c1 on c1.codcomanda = c.codcomanda and c1.codobiect = x.codobiect
      where c.tipdoc = 8 and c.subunitatea = pkg_globals.GETSUBUNITATE
      group by x.partener, x.codobiect, x.datadoc
    )
  ),
  Stoc as (
    SELECT ns.codobiect, SUM(CASE WHEN NS.TIPSERIE &gt; 0 THEN  NSE.REST ELSE NS.REST END) CANT
    FROM nirstoc ns
      inner join nir on nir.codnir = ns.codnir
      inner join ngest g on nir.gest = g.codgest
      left join nirser nse on ns.codnirstoc = nse.codnirstoc
      left join ioart1 io1 ON io1.codioart = ns.codioart AND pkg_globals.AnLunaLucru BETWEEN io1.ALStart AND io1.ALStop 
    WHERE nir.operat = 1 AND g.codsubunit = pkg_globals.getsubunitate
      AND io1.mg &lt;&gt; 5
    group by ns.codobiect
  )
  select obj.denumire,objs.stocmin,stoc.cant,obj.codintern,obj.codextern,num1.den_um1,num1.codum1,
         obj.codobiect,pkg_globals.getsubunitate,(select den_subunit from nsubunit where codsubunit = pkg_globals.GETSUBUNITATE) den_subunit,
         prod.den_part,trunc(to_date(aDataRef,&apos;dd.mm.yyyy&apos;) - lastcmd.datadoc) zile,lastcmd.datadoc datacmd, ach.partener codpart,ach.peraproviz,
         lastcmd.LastPretCmd,
         case
           when art.codexternart is null then art.sufixcodextern
           when art.sufixcodextern is null then art.codexternart
           else art.codexternart||&apos;_&apos;||art.sufixcodextern
         end
  from Ach
       inner join nartobj obj on obj.codobiect = ach.codobiect
       inner join nart art on obj.codarticol = art.codarticol
       inner join npart p on p.codpart = ach.partener
       inner join num on num.codum = art.um
       inner join num1 on num1.codum = num.codum and num1.secundara = 0
       left join lastcmd on lastcmd.partener = ach.partener and lastcmd.codobiect = ach.codobiect
       left join nartobjsubunit objs on objs.codobiect = obj.codobiect and (objs.codgest is null or objs.codgest = 0) and objs.subunitate = pkg_globals.GETSUBUNITATE
       left join stoc on stoc.codobiect = obj.codobiect
       left join npart prod on prod.codpart = nvl(obj.codproducator,0)
  where exists (select valoare from tmp_manevra_liste where valoare = ach.partener and filtru = &apos;CODPART&apos;);

  update tmp_lst_napr6 tmp
  set
    vanzari = (select sum(i1.cant)
               from iesiri1 i1
                    inner join iesiri i on i.codies = i1.codies
               where i.anulat = 0 and i.datadoc between tmp.datacmd + 1 and aDataRef
                     and i1.codobiect = tmp.codobiect and i.subunitatea = pkg_globals.GETSUBUNITATE
                     and i.tipdoc in (16,19,20,21)
               );
  update tmp_lst_napr6
  set
    rata = nvl(vanzari,0) / zile
  where nvl(zile,0) &gt; 0;

  update tmp_lst_napr6 tmp
  set
    necesar = case
                when nvl(vanzari,0) + nvl(stocmin,0) - nvl(stoc,0) &lt; 0 then 0
                else nvl(vanzari,0) + nvl(stocmin,0) - nvl(stoc,0)
              end;

  update tmp_lst_napr6
  set
    necesart = necesar;
end;

end PKG_LIST_BASE_NAPROVIZ6;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NAPROVIZ7</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3885D2B00C6BDC12F3688A71F906666FF9FFF460</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NAPROVIZ7 is

gUserFields VARCHAR2(5000);
gUserAlias  VARCHAR2(10000);
gNullAlias  VARCHAR2(10000);
gSuplCols   VARCHAR2(10000);
gSuplJoins  VARCHAR2(10000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(32000);
  sSelect      VARCHAR2( 2000);
  sColMinMax   VARCHAR2(  100):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  vAux         VARCHAR2( 1000):= &apos;&apos;;
  vSelStocReal VARCHAR2( 3000);
  vSelStocInit VARCHAR2( 3000);
  vSelIes_Per  VARCHAR2( 3000);
  vSelTr_Per   VARCHAR2( 3000);
  vSelIes_Emul VARCHAR2( 3000);
  vAnPrec      NUMBER(4);
  vLunaPrec    NUMBER(2);
  vNrLuni      INTEGER        := extract(year from PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)*12+extract(month from PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN) - extract(year from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)*12-extract(month from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI) +1;
  vNrZilePer   INTEGER        := PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN - PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI + 1;
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  vCondSub_C   VARCHAR2(  100);
  vCondSub_CS  VARCHAR2(  100);
  vCondSub_G   VARCHAR2(  100);
  sUltNirstoc  VARCHAR2( 1000);
  sAfectare    VARCHAR2(50):= &apos;&apos;;
  pUsername        VARCHAR2(100);
  pStocExternFirma VARCHAR2(3000) := pkg_categconst.GetValConstanta(&apos;StocExternFirma&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pStocExternCamp  VARCHAR2( 100) := PKG_LIST_BASE_UTILS.Get_StocExternCamp;
  vFiltruTermen    VARCHAR2(1000);
  sJoinRestCmd varchar2(1000);
  vUserID number(20);
BEGIN
  if vNrLuni &lt;= 0 then vNrLuni := 1; end if;
  if vNrZilePer &lt;= 0 then vNrZilePer := 1; end if;
  vCondSub_C  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);
  vCondSub_CS := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, &apos;SubunitSursa&apos;);
  vCondSub_G  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);

  delete tmp_stocreal;

  gSuplCols := &apos;NARTOBJ NAO, NART NA, NARTOBJSUBUNIT NAOS, NUM NUM, NPART PROD, NCLASEA CLSA, NCLASEAS CLSAS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_STOCEXTERN&apos;, &apos;TSE&apos;,  &apos;TSE.CODCOMUN = NAO.&apos;||pStocExternCamp);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF InStr(gSuplJoins, &apos;TMP_STOCEXTERN&apos;) &gt; 0 THEN
    SELECT USERNAME INTO pUSERNAME FROM user_users;
    WINMADMIN.PKG_USERFIRME.POPULEAZA_STOCURI_EXTERNE(pUSERNAME,pStocExternFirma,pStocExternCamp);
  END IF;

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  pkg_globals.Calculeaza_Luna_Precedenta(Extract(Year from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI), Extract(Month from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI), vAnPrec, vLunaPrec);
  pkg_globals.SetLunaTemp(Extract(Year from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI), Extract(Month from PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI));
  pkg_globals.SetLunaPrecedenta(vAnPrec, vLunaPrec);

  PKG_LIST_SELFISAMAG.setAllParams(null, null, PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI, 0, 0, 0);

  if PKG_LIST_BASE_NAPROVIZ2.GETDIM then
    vSelStocInit := &apos;
    SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;, NS.D1, NS.D2, NS.D3
    FROM V_STOC_INI_NECESAR2 V
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE V.REST &lt;&gt; 0&apos;;

    vSelStocReal := &apos;
    SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;, NS.D1, NS.D2, NS.D3
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE NS.REST &lt;&gt; 0&apos;;

    vSelIes_Per  := &apos;
    SELECT NS.CODOBIECT, L1.CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3, I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC
    FROM LIVR L
      INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN IESIRI I ON L.CODIES = I.CODIES
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)||&apos;&apos;&apos;
      AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||PKG_LIST_BASE_NAPROVIZ2.GETTipVanz||&apos;)&apos;;

    vSelTr_Per := &apos;&apos;;
    if Instr(PKG_LIST_BASE_NAPROVIZ2.GETTipVanz,&apos;12&apos;) &gt; 0 then
      vSelTr_Per  := &apos;
        SELECT NS.CODOBIECT, L1.CANT, &apos;&apos;IES&apos;&apos;, NS.D1, NS.D2, NS.D3, T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC
        FROM LIVR L
          INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
          INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
          INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
        WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)||&apos;&apos;&apos;
          AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
    end if;

    IF PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN
      SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
      SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
      vAux := &apos;
      AND&apos;;
      IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
      ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
      END IF;
      vSelStocReal := vSelStocReal ||vAux;
      vSelStocInit := vSelStocInit ||vAux;
      vSelIes_Per := vSelIes_Per   ||vAux;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per := vSelTr_Per   ||vAux;
      end if;
    END IF;

    IF PKG_LIST_BASE_NAPROVIZ2.GETALLIOArt = 0 THEN
      vAux := &apos;
      AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
      vSelStocReal := vSelStocReal ||vAux;
      vSelStocInit := vSelStocInit ||vAux;
      vSelIes_Per := vSelIes_Per   ||vAux;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per := vSelTr_Per   ||vAux;
      end if;
    END IF;

    vSelStocReal := vSelStocReal ||&apos;
    GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;
    vSelStocInit := vSelStocInit ||&apos;
    GROUP BY NS.CODOBIECT, NS.D1, NS.D2, NS.D3&apos;;

    sJoinRestCmd := &apos;&apos;;
    if PKG_LIST_BASE_NAPROVIZ2.getRestCmd then
      sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
    end if;
      
    vFiltruTermen := &apos;&apos;;
    if PKG_LIST_BASE_NAPROVIZ2.getCuTermen = 1 then
      vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(PKG_LIST_BASE_NAPROVIZ2.getTermen)||&apos;&apos;&apos; &apos;;
    end if;

    /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

    PKG_GLOBALS.SetSeparator(&apos;,&apos;);
    DELETE TMP_CMD_TMP;
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CF&apos;&apos;, to_char(C.nrdoc),C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;
      &apos;||vFiltruTermen;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CC&apos;&apos;,C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CSERV&apos;&apos;,C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CSIN&apos;&apos;,C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CSIES&apos;&apos;,C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT C1.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
      C1.RestAcceptat RestA, &apos;&apos;CG&apos;&apos;,C1.D1,C1.D2,C1.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM COMANDA1 C1
      INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
      INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
      AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT CMDMAT.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantA,
      CMDMAT.Rest RestA, &apos;&apos;CIIN&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM CMDPRODMAT CMDMAT
      INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
      INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
      AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;
      AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT CMDMAT.CodObiect,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantC,
      case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantA,
      CMDMAT.Rest RestA, &apos;&apos;CIIES&apos;&apos;,CMDMAT.D1,CMDMAT.D2,CMDMAT.D3,C.CODCOMANDA,C.TIPDOC,C.PREFIXDOC,C.SERIADOC,C.NRDOC,C.DATADOC
    FROM CMDPRODMAT CMDMAT
      INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
      INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
    WHERE Nvl(C.INCHISA, 0) = 0
      AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
      AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;
      AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    DELETE TMP_STOCREAL;
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelStocReal, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_stocreal(codobiect,cant,tip,D1,D2,D3) &apos;||vSelStocInit, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_cmd_tmp(codobiect,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC) &apos;||vSelIes_Per, aListID, aListVer);
    if Length(vSelTr_Per) &gt; 0 then
      LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_cmd_tmp(codobiect,resta,tip,D1,D2,D3,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC) &apos;||vSelTr_Per, aListID, aListVer);
    end if;

    DELETE TMP_STOCREZ;
    sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat,D1,D2,D3)
    SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT,NS.D1,NS.D2,NS.D3
    FROM REZERVATS R
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE NVL(R.REST,0) &gt; 0&apos;;

    if PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN
      SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
      SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
      if vCateLGest = 0 then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
      elsif vCateGest = 0 then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
      else
        sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                              &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
      end if;
    end if;
    if PKG_LIST_BASE_NAPROVIZ2.GETALLIOART = 0 then
      sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    end if;
    sSelect := sSelect||&apos; GROUP BY NS.CODOBIECT,NS.D1,NS.D2,NS.D3&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    IF PKG_LIST_BASE_NAPROVIZ2.GETULTACHIZ
    THEN sUltNirstoc := &apos;SELECT CODOBIECT,D1,D2,D3,MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT,D1,D2,D3&apos;;
    ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
    END IF;
  else
    vSelStocInit := &apos;
    SELECT NS.CODOBIECT, SUM(V.REST) CANT, &apos;&apos;INIT&apos;&apos;
    FROM V_STOC_INI_NECESAR2 V
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = V.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE V.REST &lt;&gt; 0&apos;;

    vSelStocReal := &apos;
    SELECT NS.CODOBIECT, SUM(NS.REST) CANT, &apos;&apos;REAL&apos;&apos;
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE NS.REST &lt;&gt; 0&apos;;

    vSelIes_Per  := &apos;
    SELECT NS.CODOBIECT, L1.CANT, &apos;&apos;IES&apos;&apos;, I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC
    FROM LIVR L
      INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN IESIRI I ON L.CODIES = I.CODIES
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)||&apos;&apos;&apos;
      AND NVL(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I.TIPDOC IN (&apos;||PKG_LIST_BASE_NAPROVIZ2.GETTIPVANZ||&apos;)&apos;;

    if PKG_LIST_BASE_NAPROVIZ2.GETVANZEMUL then
      vSelIes_Emul  := &apos;
      SELECT E1.CODOBIECT, SUM(E1.CANT) CANT, &apos;&apos;EMUL&apos;&apos;, E.CODEMULARE, 64 TIPDOC, &apos;&apos; PREFIXDOC, &apos;&apos; SERIADOC, E.NRBON NRDOC, E.DATABON DATADOC
      FROM EMULARE1 E1
        INNER JOIN EMULARE E ON E.CODEMULARE = E1.CODEMULARE
        INNER JOIN NGEST G ON G.CODGEST = E1.CODGEST &apos;||vCondSub_G||&apos;
      WHERE E.DATABON BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)||&apos;&apos;&apos;
        AND NVL(E.PRELUAT, 0) = 0 
        AND NVL(E.FACTURARE, 0) = 0&apos;;
    end if;
    commit;

    vSelTr_Per := &apos;&apos;;
    if Instr(PKG_LIST_BASE_NAPROVIZ2.GETTIPVANZ,&apos;12&apos;) &gt; 0 then
      vSelTr_Per  := &apos;
        SELECT NS.CODOBIECT, L1.CANT, &apos;&apos;IES&apos;&apos;, T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC
        FROM LIVR L
          INNER JOIN LIVR1 l1 ON L1.CODLIVR = L.CODLIVR
          INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
          INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND L1.CODIES1 = T1.CODTRANSF1
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
        WHERE L.DATALIVR BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN)||&apos;&apos;&apos;
          AND NVL(T.ANULAT,0) = 0 AND T.OPERAT = 1 AND T.TIPDOC = 12 &apos;;
    end if;

    IF PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN
      SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
      SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
      vAux := &apos;
      AND&apos;;
      IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
      ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
      END IF;
      vSelStocReal := vSelStocReal ||vAux;
      vSelStocInit := vSelStocInit ||vAux;
      vSelIes_Per := vSelIes_Per   ||vAux;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per := vSelTr_Per   ||vAux;
      end if;
    END IF;

    IF PKG_LIST_BASE_NAPROVIZ2.GETALLIOART = 0 THEN
      vAux := &apos;
      AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
      vSelStocReal := vSelStocReal ||vAux;
      vSelStocInit := vSelStocInit ||vAux;
      vSelIes_Per := vSelIes_Per   ||vAux;
      if Length(vSelTr_Per) &gt; 0 then
        vSelTr_Per := vSelTr_Per   ||vAux;
      end if;
    END IF;

    vSelStocReal := vSelStocReal ||&apos;
    GROUP BY NS.CODOBIECT&apos;;
    vSelStocInit := vSelStocInit ||&apos;
    GROUP BY NS.CODOBIECT&apos;;

    sJoinRestCmd := &apos;&apos;;
    if PKG_LIST_BASE_NAPROVIZ2.GETRESTCMD then
      sJoinRestCmd := &apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C1.GESTACT AND FILTRU = &apos;&apos;CODGEST&apos;&apos; &apos;;
    end if;
      
    vFiltruTermen := &apos;&apos;;
    if PKG_LIST_BASE_NAPROVIZ2.GETCUTERMEN = 1 then
      vFiltruTermen := &apos; AND C1.TERMEN &lt;= &apos;&apos;&apos;||TO_CHAR(PKG_LIST_BASE_NAPROVIZ2.GETTERMEN)||&apos;&apos;&apos; &apos;;
    end if;

    /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/

    PKG_GLOBALS.SetSeparator(&apos;,&apos;);
    DELETE TMP_CMD_TMP;
    
    if PKG_LIST_BASE_NAPROVIZ2.GETCUCOMENZI &gt; 0 then
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,auxfield,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CF&apos;&apos;, to_char(C.nrdoc), C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 8 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        &apos;||vFiltruTermen;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CC&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 18 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CSERV&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 92 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CSIN&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CSIES&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 44 &apos;||vCondSub_CS||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT C1.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantComandat else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then C1.CantAcceptat else 0 end CantA,
        C1.RestAcceptat RestA, &apos;&apos;CG&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON C.CodGest = G.CodGest&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND G.Tip = 1 AND C.TipDoc = 43 &apos;||vCondSub_C||&apos;
        AND C1.RestAcceptat &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT CMDMAT.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantA,
        CMDMAT.Rest RestA, &apos;&apos;CIIN&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 AND C.TipDoc = 53 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2))&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
      sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,cantc,canta,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
      SELECT CMDMAT.CodObiect,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantC,
        case when C.DataDoc BETWEEN &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACINI)||&apos;&apos;&apos; AND &apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos; then CMDMAT.Cant else 0 end CantA,
        CMDMAT.Rest RestA, &apos;&apos;CIIES&apos;&apos;, C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.SERIADOC, C.NRDOC, C.DATADOC
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda&apos;||sJoinRestCmd||&apos;
      WHERE Nvl(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND C.Anulat = 0 &apos;||vCondSub_C||&apos;
        AND CMDMAT.Rest &gt; 0 AND C.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2))&apos;;
      LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    end if;
    
    sSelect := &apos;INSERT INTO TMP_CMD_TMP(codobiect,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC)
    SELECT I1.CodObiect,
      L1.RestIESVAL RestA, &apos;&apos;IESNED&apos;&apos;, I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC
    FROM LIVR1 L1
      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
      INNER JOIN IESIRI I ON I.CODIES = L.CODIES
      INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1
      INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||chr(13);
    if PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN  
      sSelect := sSelect||&apos;INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = LV.GEST AND FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;||chr(13);
    end if;
    sSelect := sSelect||&apos;
    WHERE I.Operat = 1 AND I.Anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND L1.RestIESVAL &lt;&gt; 0 AND I.DataDoc &lt;= to_date(&apos;&apos;&apos;||to_char(PKG_LIST_BASE_NAPROVIZ2.GETDATACFIN)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    commit;

    DELETE TMP_STOCREAL;
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelStocReal, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_stocreal(codobiect,cant,tip) &apos;||vSelStocInit, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_cmd_tmp(codobiect,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC) &apos;||vSelIes_Per, aListID, aListVer);
    if Length(vSelTr_Per) &gt; 0 then
      LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_cmd_tmp(codobiect,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC) &apos;||vSelTr_Per, aListID, aListVer);
    end if;

    if PKG_LIST_BASE_NAPROVIZ2.GETVANZEMUL then
      LIST_EXECUTE_IMMEDIATE(&apos;INSERT INTO tmp_cmd_tmp(codobiect,resta,tip,CODDOC,TIPDOC,PREFIXDOC,SERIADOC,NRDOC,DATADOC) &apos;||vSelIes_Emul, aListID, aListVer);
    end if;

    DELETE TMP_STOCREZ;
    sSelect := &apos;INSERT INTO tmp_stocrez(codobiect,rezervat)
    SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
    FROM REZERVATS R
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||vCondSub_G||&apos;
    WHERE NVL(R.REST,0) &gt; 0&apos;;

    if PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN
      SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
      SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
      if vCateLGest = 0 then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST)&apos;;
      elsif vCateGest = 0 then
        sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE)&apos;;
      else
        sSelect := sSelect || &apos; AND (EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) OR&apos;||
                              &apos; EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = NS.CODLOCATIE))&apos;;
      end if;
    end if;
    if NOT PKG_LIST_BASE_NAPROVIZ2.GETALLIOART = 0 then
      sSelect := sSelect || &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
    end if;
    sSelect := sSelect||&apos; GROUP BY NS.CODOBIECT,NS.D1,NS.D2,NS.D3&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    IF PKG_LIST_BASE_NAPROVIZ2.GETULTACHIZ
    THEN sUltNirstoc := &apos;SELECT CODOBIECT, MAX(CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY DATAACHIZ, CODNIRSTOC) CODNIRSTOC FROM NIRSTOC WHERE FURN &gt; 0 AND Nvl(CODNIRSTOCPARINTE,0) = 0 GROUP BY CODOBIECT&apos;;
    ELSE sUltNirstoc := &apos;SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
    END IF;
  end if;  

  sAfectare := &apos;&apos;;
  --if pkg_list_base_naproviz2.GETPEZILE = 1 then
    if pkg_list_base_naproviz2.getafectare = 1 then
      sAfectare := &apos; - NVL(NAOS.STOCMIN,0) &apos;;
    end if;
    if pkg_list_base_naproviz2.getafectare = 2 then
      sAfectare := &apos; - NVL(NAOS.STOCMED,0) &apos;;
    end if;
    if pkg_list_base_naproviz2.getafectare = 3 then
      sAfectare := &apos; - NVL(NAOS.STOCMAX,0) &apos;;
    end if;
  --end if;
  vUserid := pkg_globals.GETUSERID;
  delete tmp_cmd where userid = vUSERID;
  
  if PKG_LIST_BASE_NAPROVIZ2.GETDIM then
    INSERT INTO TMP_CMD_TMP(CODOBIECT, TIP, D1, D2, D3)
    SELECT DISTINCT CODOBIECT, &apos;OBJ&apos;, D1, D2, D3
    FROM 
    (SELECT CODOBIECT, D1, D2, D3
     FROM TMP_CMD_TMP
     UNION ALL
     SELECT CODOBIECT, D1, D2, D3 
     FROM TMP_STOCREAL
    );
    insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid,d1,d2,d3)
    select codobiect, sum(coalesce(cantc,0)), sum(coalesce(canta,0)), sum(coalesce(resta,0)), tip, vuserid, d1, d2, d3
    from tmp_cmd_tmp
    group by codobiect, tip, vuserid, d1, d2, d3;
    
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
      Necesar,
      StocReal,
      CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
      CantC_CF, CantA_CF, RestA_CF,
      CantC_CC, CantA_CC, RestA_CC,
      CantC_CSERV, CantA_CSERV, RestA_CSERV,
      CantC_CSIn, CantA_CSIn, RestA_CSIn,
      CantC_CSIes, CantA_CSIes, RestA_CSIes,
      CantC_CG, CantA_CG, RestA_CG,
      CantC_CIIn, CantA_CIIn, RestA_CIIn,
      CantC_CIIes, CantA_CIIes, RestA_CIIes,
      Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec, D1, D2, D3&apos;||gUserFields||&apos;)
    SELECT
      NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
      COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
      --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,&apos;;
    if pkg_list_base_naproviz2.GETPEZILE = 1 then
      sInsert := sInsert||&apos;
        GREATEST(CEIL(COALESCE(COALESCE(IP.CANT,0),0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
    else
      sInsert := sInsert||&apos;
        GREATEST(CEIL(COALESCE(COALESCE(IP.CANT,0),0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar,&apos;;
    end if;
    sInsert := sInsert||&apos;
      NVL(SR.CANT,0) STOCREAL,
      NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
      NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
      NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
      NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
      NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
      NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
      NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
      NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
      NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
      SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||&apos;,TMP.D1, TMP.D2, TMP.D3&apos;||gUserAlias||&apos;
    FROM (SELECT CODOBIECT, D1, D2, D3 FROM TMP_CMD_TMP WHERE TIP = &apos;&apos;OBJ&apos;&apos;) TMP 
      INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = TMP.CODOBIECT
      INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
      LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
      LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
      LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
      LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
      LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                    and (NAOS.codgest is null or NAOS.codgest = 0)
                                    AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos; AND SR.D1 = TMP.D1 AND SR.D2 = TMP.D2 AND SR.D3 = TMP.D3
      LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT AND SREZ.D1 = TMP.D1 AND SREZ.D2 = TMP.D2 AND SREZ.D3 = TMP.D3
      LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos; AND SI.D1 = TMP.D1 AND SI.D2 = TMP.D2 AND SI.D3 = TMP.D3
      LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.D1 = TMP.D1 AND CF.D2 = TMP.D2 AND CF.D3 = TMP.D3 AND CF.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.D1 = TMP.D1 AND CC.D2 = TMP.D2 AND CC.D3 = TMP.D3 AND CC.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.D1 = TMP.D1 AND CSERV.D2 = TMP.D2 AND CSERV.D3 = TMP.D3 AND CSERV.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.D1 = TMP.D1 AND CSIN.D2 = TMP.D2 AND CSIN.D3 = TMP.D3 AND CSIN.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.D1 = TMP.D1 AND CSIES.D2 = TMP.D2 AND CSIES.D3 = TMP.D3 AND CSIES.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.D1 = TMP.D1 AND CG.D2 = TMP.D2 AND CG.D3 = TMP.D3 AND CG.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.D1 = TMP.D1 AND CIIN.D2 = TMP.D2 AND CIIN.D3 = TMP.D3 AND CIIN.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.D1 = TMP.D1 AND CIIES.D2 = TMP.D2 AND CIIES.D3 = TMP.D3 AND CIIES.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
      LEFT JOIN (select codobiect, sum(resta) cant, tip, D1, D2, D3 from TMP_CMD_TMP where tip = &apos;&apos;IES&apos;&apos; group by codobiect, tip, D1, D2, D3) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
                AND IP.D1 = TMP.D1 AND IP.D2 = TMP.D2 AND IP.D3 = TMP.D3
      LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
      LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
      gSuplJoins||&apos;
    WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
    if not pkg_list_base_naproviz2.AllCls then
      sInsert := sInsert||&apos; and exists (select tmp.valoare from tmp_manevra_liste tmp, nclasea clsx 
                                        where tmp.filtru = &apos;&apos;CODCLASEA&apos;&apos; and tmp.valoare = clsx.codclasea 
                                              and INSTRB(CLSA.CODIDENT, clsx.codident) = 1) &apos;;
    end if;
  else
    insert into tmp_cmd(codobiect,cantc,canta,resta,tip,userid)
    select codobiect, sum(coalesce(cantc,0)), sum(coalesce(canta,0)), sum(coalesce(resta,0)), tip, vuserid
    from tmp_cmd_tmp
    group by codobiect, tip, vuserid;
    sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;(
      CodObiect,Articol, UM, TotVanz, MedieVanz, MedieVanzZ,
      Necesar,
      StocReal,
      CodExtern, CodIntern, Producator, StocMIN, StocMED, StocMAX,
      CantC_CF, CantA_CF, RestA_CF,
      CantC_CC, CantA_CC, RestA_CC,
      CantC_CSERV, CantA_CSERV, RestA_CSERV,
      CantC_CSIn, CantA_CSIn, RestA_CSIn,
      CantC_CSIes, CantA_CSIes, RestA_CSIes,
      CantC_CG, CantA_CG, RestA_CG,
      CantC_CIIn, CantA_CIIn, RestA_CIIn,
      CantC_CIIes, CantA_CIIes, RestA_CIIes,
      Rezervat, UltFurn, UltPrAchiz, NrComFurn, NrZile, NrZileNec&apos;||gUserFields||&apos;)
    SELECT
      NAO.CODOBIECT, NAO.DENUMIRE, NUM.DEN_UM, COALESCE(IP.CANT,0) TOTVANZ, CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) MEDIEVANZ,
      COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; MEDIEVANZZ,
      --GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0) - NVL(SI.Cant, 0) - NVL(CG.RESTA,0) + NVL(CF.RESTA,0) - NVL(CC.RESTA,0) - NVL(CSERV.RESTA,0) + NVL(CSIN.RESTA,0) - NVL(CSIES.RESTA,0) + NVL(CIIN.RESTA,0) - NVL(CIIES.RESTA,0),0) Necesar,&apos;;
    if pkg_list_base_naproviz2.GETPEZILE = 1 then
      sInsert := sInsert||&apos;
        GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrZilePer||&apos; * &apos;||pkg_list_base_naproviz2.GETNRZILE||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar, &apos;||chr(13);
    else
      sInsert := sInsert||&apos;
        GREATEST(CEIL(COALESCE(IP.CANT,0) / &apos;||vNrLuni||&apos;) - NVL(SR.Cant, 0)&apos;||sAfectare||&apos; + NVL(CG.RESTA,0) - NVL(CF.RESTA,0) + NVL(CC.RESTA,0) + NVL(CSERV.RESTA,0) - NVL(CSIN.RESTA,0) + NVL(CSIES.RESTA,0) - NVL(CIIN.RESTA,0) + NVL(CIIES.RESTA,0),0) Necesar,&apos;;
    end if;
    sInsert := sInsert||&apos;
      NVL(SR.CANT,0) STOCREAL,
      NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART&apos;||sColMinMax||&apos;,
      NVL(CF.CANTC,0), NVL(CF.CANTA,0), NVL(CF.RESTA,0),
      NVL(CC.CANTC,0), NVL(CC.CANTA,0), NVL(CC.RESTA,0),
      NVL(CSERV.CANTC,0), NVL(CSERV.CANTA,0), NVL(CSERV.RESTA,0),
      NVL(CSIN.CANTC,0), NVL(CSIN.CANTA,0), NVL(CSIN.RESTA,0),
      NVL(CSIES.CANTC,0), NVL(CSIES.CANTA,0), NVL(CSIES.RESTA,0),
      NVL(CG.CANTC,0), NVL(CG.CANTA,0), NVL(CG.RESTA,0),
      NVL(CIIN.CANTC,0), NVL(CIIN.CANTA,0), NVL(CIIN.RESTA,0),
      NVL(CIIES.CANTC,0), NVL(CIIES.CANTA,0), NVL(CIIES.RESTA,0),
      SREZ.REZERVAT, UF.DEN_PART, NVL(UNS.PRET,0) - Nvl(UNS.ADAOS,0), CF.AuxField,&apos;||vNrZilePer||&apos;,&apos;||to_char(pkg_list_base_naproviz2.GETNRZILE)||gUserAlias||&apos;
    FROM NARTOBJ NAO
      INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT JOIN (&apos;||sUltNirstoc||&apos;) X ON X.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = X.CODNIRSTOC
      LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
      LEFT JOIN NIR UNIR ON UNIR.CODNIR = UNS.CODNIR
      LEFT JOIN INTRARI UINTR ON UINTR.CODINTR = UNIR.CODINTR AND UINTR.TIPDOC = 6
      LEFT JOIN NSUBUNIT USUB ON USUB.CODSUBUNIT = UINTR.CODSUBUNIT
      LEFT JOIN NARTOBJSUBUNIT NAOS ON NAO.CODOBIECT = NAOS.CODOBIECT 
                                    and (NAOS.codgest is null or NAOS.codgest = 0)
                                    AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      LEFT JOIN TMP_STOCREAL SR ON SR.CODOBIECT = NAO.CODOBIECT AND SR.TIP = &apos;&apos;REAL&apos;&apos;
      LEFT JOIN TMP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT
      LEFT JOIN TMP_STOCREAL SI ON SI.CODOBIECT = NAO.CODOBIECT AND SI.TIP = &apos;&apos;INIT&apos;&apos;
      LEFT JOIN TMP_CMD CF ON CF.CODOBIECT = NAO.CODOBIECT AND CF.TIP = &apos;&apos;CF&apos;&apos; AND CF.USERID = &apos;||TO_CHAR(VUSERID)||&apos; 
      LEFT JOIN TMP_CMD CC ON CC.CODOBIECT = NAO.CODOBIECT AND CC.TIP = &apos;&apos;CC&apos;&apos; AND CC.USERID = &apos;||TO_CHAR(VUSERID)||&apos; 
      LEFT JOIN TMP_CMD CSERV ON CSERV.CODOBIECT = NAO.CODOBIECT AND CSERV.TIP = &apos;&apos;CSERV&apos;&apos; AND CSERV.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CSIN ON CSIN.CODOBIECT = NAO.CODOBIECT AND CSIN.TIP = &apos;&apos;CSIN&apos;&apos; AND CSIN.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CSIES ON CSIES.CODOBIECT = NAO.CODOBIECT AND CSIES.TIP = &apos;&apos;CSIES&apos;&apos; AND CSIES.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CG ON CG.CODOBIECT = NAO.CODOBIECT AND CG.TIP = &apos;&apos;CG&apos;&apos; AND CG.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CIIN ON CIIN.CODOBIECT = NAO.CODOBIECT AND CIIN.TIP = &apos;&apos;CIIN&apos;&apos; AND CIIN.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN TMP_CMD CIIES ON CIIES.CODOBIECT = NAO.CODOBIECT AND CIIES.TIP = &apos;&apos;CIIES&apos;&apos; AND CIIES.USERID = &apos;||TO_CHAR(VUSERID)||&apos;
      LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
      LEFT JOIN (select codobiect, sum(resta) cant, tip from TMP_CMD_TMP where tip = &apos;&apos;IES&apos;&apos; group by codobiect, tip) IP ON IP.CODOBIECT = NAO.CODOBIECT AND IP.TIP = &apos;&apos;IES&apos;&apos;
      LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = NA.CLASA
      LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = NA.CLASASTATIST&apos;||
      gSuplJoins||&apos;
    WHERE NA.TIPARTICOL = 0 and coalesce(NAO.Blocat,0) in (0,3) &apos;;
    if not pkg_list_base_naproviz2.AllCls then
      sInsert := sInsert||&apos; and exists (select tmp.valoare from tmp_manevra_liste tmp, nclasea clsx 
                                        where tmp.filtru = &apos;&apos;CODCLASEA&apos;&apos; and tmp.valoare = clsx.codclasea 
                                              and INSTRB(CLSA.CODIDENT, clsx.codident) = 1) &apos;;
    end if;
  end if;  
  

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  --DELETE TMP_CMD WHERE USERID = VUSERID;
  if PKG_LIST_BASE_NAPROVIZ2.GetZileStoc &gt; 0 then
    CalculeazaZileStoc(tmpName);
  end if;

  if PKG_LIST_BASE_NAPROVIZ2.GETDIM then
  sInsert := 
  &apos;begin
     for v_rec in (
     select 
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,TotVanz,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
       CantC_CF,CantA_CF,RestA_CF,
       CantC_CC,CantA_CC,RestA_CC,
       CantC_CSERV,CantA_CSERV,RestA_CSERV,
       CantC_CSIn,CantA_CSIn,RestA_CSIn,
       CantC_CSIes,CantA_CSIes,RestA_CSIes,
       CantC_CG,CantA_CG,RestA_CG,
       CantC_CIIn,CantA_CIIn,RestA_CIIn,
       CantC_CIIes,CantA_CIIes,RestA_CIIes,
       REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec,D1,D2,D3
     from &apos;||tmpName||&apos;) loop
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,TotVanz,CodExtern,CodIntern,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,RESTA,v_rec.CodExtern,v_rec.CodIntern,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;IES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CF,CantA_CF,RestA_CF,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CF&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CC,CantA_CC,RestA_CC,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CC&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSERV,CantA_CSERV,RestA_CSERV,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSERV&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSIn,CantA_CSIn,RestA_CSIn,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSIN&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSIes,CantA_CSIes,RestA_CSIes,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSIES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CG,CantA_CG,RestA_CG,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CG&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CIIn,CantA_CIIn,RestA_CIIn,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CIIN&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CIIes,CantA_CIIes,RestA_CIIes,
       D1,D2,D3
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA,
       v_rec.D1,v_rec.D2,v_rec.D3
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CIIES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT AND D1 = V_REC.D1 AND D2 = V_REC.D2 AND D3 = V_REC.D3;
       UPDATE &apos;||TMPNAME||&apos; SET
       TotVanz = NULL,
       CantC_CF = NULL,CantA_CF = NULL,RestA_CF = NULL,
       CantC_CC = NULL,CantA_CC = NULL,RestA_CC = NULL,
       CantC_CSERV = NULL,CantA_CSERV = NULL,RestA_CSERV = NULL,
       CantC_CSIn = NULL,CantA_CSIn = NULL,RestA_CSIn = NULL,
       CantC_CSIes = NULL,CantA_CSIes = NULL,RestA_CSIes = NULL,
       CantC_CG = NULL,CantA_CG = NULL,RestA_CG = NULL,
       CantC_CIIn = NULL,CantA_CIIn = NULL,RestA_CIIn = NULL,
       CantC_CIIes = NULL,CantA_CIIes = NULL,RestA_CIIes = NULL
       WHERE NAV_CODDOC IS NULL AND NAV_TIPDOC IS NULL;
     end loop;
     COMMIT;
   end;&apos;;
  else
    sInsert := 
  &apos;begin
     for v_rec in (
     select 
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,TotVanz,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
       CantC_CF,CantA_CF,RestA_CF,
       CantC_CC,CantA_CC,RestA_CC,
       CantC_CSERV,CantA_CSERV,RestA_CSERV,
       CantC_CSIn,CantA_CSIn,RestA_CSIn,
       CantC_CSIes,CantA_CSIes,RestA_CSIes,
       CantC_CG,CantA_CG,RestA_CG,
       CantC_CIIn,CantA_CIIn,RestA_CIIn,
       CantC_CIIes,CantA_CIIes,RestA_CIIes,
       REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     from &apos;||tmpName||&apos;) loop
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,TotVanz,CodExtern,CodIntern
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,RESTA,v_rec.CodExtern,v_rec.CodIntern
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;IES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CF,CantA_CF,RestA_CF
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CF&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CC,CantA_CC,RestA_CC
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CC&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSERV,CantA_CSERV,RestA_CSERV
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSERV&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSIn,CantA_CSIn,RestA_CSIn
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSIN&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CSIes,CantA_CSIes,RestA_CSIes
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CSIES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CG,CantA_CG,RestA_CG
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CG&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CIIn,CantA_CIIn,RestA_CIIn
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CIIN&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       INSERT INTO &apos;||TMPNAME||&apos;
       (
       NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       Articol,UM,CodExtern,CodIntern,
       CantC_CIIes,CantA_CIIes,RestA_CIIes
       )
       SELECT 
       CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
       v_rec.Articol,v_rec.UM,v_rec.CodExtern,v_rec.CodIntern,
       CantC,CantA,RestA
       FROM TMP_CMD_TMP
       WHERE TIP = &apos;&apos;CIIES&apos;&apos; AND CODOBIECT = V_REC.CODOBIECT;
       UPDATE &apos;||TMPNAME||&apos; SET
       TotVanz = NULL,
       CantC_CF = NULL,CantA_CF = NULL,RestA_CF = NULL,
       CantC_CC = NULL,CantA_CC = NULL,RestA_CC = NULL,
       CantC_CSERV = NULL,CantA_CSERV = NULL,RestA_CSERV = NULL,
       CantC_CSIn = NULL,CantA_CSIn = NULL,RestA_CSIn = NULL,
       CantC_CSIes = NULL,CantA_CSIes = NULL,RestA_CSIes = NULL,
       CantC_CG = NULL,CantA_CG = NULL,RestA_CG = NULL,
       CantC_CIIn = NULL,CantA_CIIn = NULL,RestA_CIIn = NULL,
       CantC_CIIes = NULL,CantA_CIIes = NULL,RestA_CIIes = NULL
       WHERE NAV_CODDOC IS NULL AND NAV_TIPDOC IS NULL;
     end loop;
     COMMIT;
   end;&apos;;
  end if;
  execute immediate sInsert;
  commit;
END;

PROCEDURE CalculeazaZileStoc(tmpName IN VARCHAR2) IS
aCount number(5);
aZi date;
StocP number(20,7);
Intrari number(20,7);
Iesiri number(20,7);
vSel varchar2(20000);
vAux varchar2(1000);
vCateGest number(5);
vCateLGest number(5);
BEGIN
  --PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI := to_date(&apos;01.07.2008&apos;,&apos;dd.mm.yyyy&apos;);
  --PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN := to_date(&apos;31.07.2008&apos;,&apos;dd.mm.yyyy&apos;);
  for v_obj in (select o.codobiect
                from nartobj o
                     inner join nart a on a.codarticol = o.codarticol
                where a.tiparticol = &apos;0&apos;-- and o.codobiect = 5010
                ) loop
    aCount := 0;
    aZi := PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI;
    while aZi &lt;= PKG_LIST_BASE_NAPROVIZ2.GETDATAVFIN loop
      if aZi = PKG_LIST_BASE_NAPROVIZ2.GETDATAVINI then
        begin
          select nvl(cant,0) into StocP
          from tmp_stocreal where codobiect = v_obj.codobiect and tip = &apos;INIT&apos;;
        exception when others then StocP := 0;
        end;
      end if;
      -- intrari in zi
      vSel :=
      &apos;SELECT
         SUM(CASE
           WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
           ELSE NSE.CANTNIR
         END)
       FROM
         NIRSTOC NS
         INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
         INNER JOIN NGEST G ON G.CODGEST = N.GEST
         LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
       WHERE
         N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 15) AND  N.ANULAT = 0 AND N.OPERAT = 1
         AND N.DATANIR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
         AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE)
         AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
      IF PKG_LIST_BASE_NAPROVIZ2.GETALLGEST = 0 THEN
        SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
        SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
        vAux := &apos;
        AND&apos;;
        IF    vCateLGest = 0 THEN vAux := vAux||&apos; N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
        ELSIF vCateGest  = 0 THEN vAux := vAux||&apos; NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
        ELSE vAux := vAux||&apos; (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
        END IF;
        vSel := vSel||vAux;
      END IF;

      IF PKG_LIST_BASE_NAPROVIZ2.GETALLIOART = 0 THEN
        vAux := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
        vSel := vSel||vAux;
      END IF;
      begin
        execute immediate vSel into Intrari;
      exception when others then Intrari := 0;
      end;
      if Intrari is null then Intrari := 0; end if;
      -- iesiri in zi
      vSel :=
      &apos;SELECT
         sum(CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END)
       FROM
         LIVR1 L1
         INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
         INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
         INNER JOIN NGEST G ON G.CODGEST = N.GEST
         LEFT JOIN NIRSER NE ON L1.CODNIRSER = NE.CODNIRSER
       WHERE
         L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
         L.DATALIVR = to_date(&apos;&apos;&apos;||to_char(aZi,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
         AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE)
         AND NS.CODOBIECT = &apos;||V_OBJ.CODOBIECT;
      vSel := vSel||vAux;
      begin
        execute immediate vSel into Iesiri;
      exception when others then Iesiri := 0;
      end;
      if Iesiri is null then Iesiri := 0; end if;
      if Intrari &gt; 0 then aCount := aCount + 1;
      else
        if Iesiri &gt; 0 then aCount := aCount + 1;
        else if StocP &gt; 0 then aCount := aCount + 1; end if;
        end if;
      end if;
      StocP := StocP + Intrari - Iesiri;
      aZi := aZi + 1;
    end loop;
    execute immediate &apos;update &apos;||tmpName||&apos; set nrzile = &apos;||aCount||&apos; where codobiect = &apos;||v_obj.codobiect;
    commit;
  end loop;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;  

procedure test is
begin
  return;
   /*for v_rec in (
   select 
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,TotVanz,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CF,CantA_CF,RestA_CF,
     CantC_CC,CantA_CC,RestA_CC,
     CantC_CSERV,CantA_CSERV,RestA_CSERV,
     CantC_CSIn,CantA_CSIn,RestA_CSIn,
     CantC_CSIes,CantA_CSIes,RestA_CSIes,
     CantC_CG,CantA_CG,RestA_CG,
     CantC_CIIn,CantA_CIIn,RestA_CIIn,
     CantC_CIIes,CantA_CIIes,RestA_CIIes,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
   from TMP_LST_1267_13952) loop
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,TotVanz,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,RESTA,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;IES&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CF,CantA_CF,RestA_CF,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CF&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CC,CantA_CC,RestA_CC,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CC&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CSERV,CantA_CSERV,RestA_CSERV,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CSERV&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CSIn,CantA_CSIn,RestA_CSIn,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CSIN&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CSIes,CantA_CSIes,RestA_CSIes,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CSIES&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CG,CantA_CG,RestA_CG,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CG&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CIIn,CantA_CIIn,RestA_CIIn,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CIIN&apos; AND CODOBIECT = V_REC.CODOBIECT;
     INSERT INTO TMP_LST_1267_13952
     (
     NAV_CodDoc,NAV_TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     Articol,UM,MedieVanz,Necesar,StocReal,CodExtern,CodIntern,Producator,StocMIN,StocMED,StocMAX,
     CantC_CIIes,CantA_CIIes,RestA_CIIes,
     REZERVAT,UltFurn,UltPrAchiz,NrComFurn,NrZile,MedieVanzZ,NrZileNec
     )
     SELECT 
     CodDoc,TipDoc,PrefixDoc,NrDoc,SeriaDoc,DataDoc,CodObiect,
     v_rec.Articol,v_rec.UM,v_rec.MedieVanz,v_rec.Necesar,v_rec.StocReal,v_rec.CodExtern,v_rec.CodIntern,v_rec.Producator,v_rec.StocMIN,v_rec.StocMED,v_rec.StocMAX,
     CantC,CantA,RestA,
     v_rec.REZERVAT,v_rec.UltFurn,v_rec.UltPrAchiz,v_rec.NrComFurn,v_rec.NrZile,v_rec.MedieVanzZ,v_rec.NrZileNec
     FROM TMP_CMD_TMP
     WHERE TIP = &apos;CIIES&apos; AND CODOBIECT = V_REC.CODOBIECT;
     DELETE FROM TMP_LST_1267_13952 WHERE NAV_CODDOC IS NULL AND NAV_TIPDOC IS NULL;
   end loop;
   COMMIT;*/
end;  

end PKG_LIST_BASE_NAPROVIZ7;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67080BAACCB2B5F5DA98CD6DAF5F43976B920844</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nart IS
  vToateArt       BOOLEAN ;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(25000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(15000);
  gSuplJoins  VARCHAR2(15000);

PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1)
IS
BEGIN
  vToateArt := pToateArt = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(32000);
  sColMinMax VARCHAR2(  100):= &apos;, os.stocmin, os.stocmed, os.stocmax&apos;;
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  gSuplCols := &apos;nartobj o, nart a, nart1 a1, num u, num u1, num u2, num1 uamb, ngest ng, nclasea c, npart p, ncont nc, nclaseas cs, ncarsupart s, ioart ioa, ntari t, nartobj1 o1, pretm pm,&apos;||
               &apos;nlocatii locimp, NAGENDA NAG, NLOCALIT LOC, NJUDET JUD&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,    &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,    &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTVA1&apos;     ,    &apos;T1&apos;  , &apos;T1.CODTVA = A1.CODTVA AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN T1.ALSTART AND T1.ALSTOP&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, o.stocmin, o.stocmed, o.stocmax&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||
    &apos;(DenArt, TipSer, DenUM, DenClasaA, SimbolClasaA, Masa, Volum,
      StocMinim, StocMediu, StocMaxim, TipArticol, TipContabil, ContImplicit,
      CodIntern, CodExtern, Producator, GestImpl,
      Promotie, UMAmb, ParAmb, CNAS, AreTG, TipPretMax, Accize, TaxeSupl1, TaxeSupl2,
      NRCOLETE
      , x_Judet, X_CodSubunit,X_CodGest,X_CodClasaP&apos;||
      gUserFields||&apos;)
  WITH
    NAI AS (
      SELECT CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA
      FROM nartimplicite
      WHERE codsubunit = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)
  SELECT
    o.denumire, decode(a.tipserie,0,&apos;&apos;fara serie&apos;&apos;, 1, &apos;&apos;serie pe bucata&apos;&apos;, 2, &apos;&apos;serie pe lot&apos;&apos;) tipser,
    u.den_um , c.Den_Clasea, c.simbol, o.Masa, o.Volum&apos;||sColMinMax||&apos;, decode(a.tiparticol,0,&apos;&apos;Stoc&apos;&apos;,2, &apos;&apos;Mijloc fix&apos;&apos;,&apos;&apos;Serviciu&apos;&apos;) TipArt,
    ioa.den_ioart TipContabil, nc.simbol, o.codintern, o.codextern, p.den_part,
    ng.den_gest, decode(o.promotie,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;), uamb.den_um1, uamb.paritate, o.codcnas, decode(a.aretg,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) aretg,
    decode(o1.tippretmax,1,&apos;&apos;din stoc * Impus&apos;&apos;, 2,&apos;&apos;din stoc * Recomandat&apos;&apos;, 3,&apos;&apos;din stoc * Netransmisibil&apos;&apos;,
                         4,&apos;&apos;lunar * Impus&apos;&apos;, 5,&apos;&apos;lunar * Recomandat&apos;&apos;, 6,&apos;&apos;lunar * Netransmisibil&apos;&apos;,
                         7,&apos;&apos;nu se foloseste&apos;&apos;), ntacc.den_taxa, ntax1.den_taxa, ntax2.den_taxa,
    (SELECT COUNT(1) FROM nartobjcolet oc WHERE oc.codobiect = o.codobiect)
    , coalesce(JUD.SIMBAUTO,&apos;&apos;XX&apos;&apos;), &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;, ng.codgest, p.codclasa&apos;||
    gUserAlias||&apos;
  FROM NARTOBJ o
    INNER JOIN nart            a      ON a.codarticol = o.codarticol
    LEFT JOIN nai                     ON nai.codarticol = a.codarticol
    LEFT JOIN nart1            a1     ON a1.codarticol = o.codarticol AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN a1.alstart AND a1.alstop
    LEFT JOIN nartobjsubunit   os     ON os.codobiect = o.codobiect 
                                      and (os.codgest is null or os.codgest = 0)
                                      AND os.subunitate = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN nartimplicite    aimp   ON aimp.codarticol = a.codarticol AND aimp.codsubunit = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN nlocatii         locimp on locimp.codlocatie = aimp.locatieimplicita
    LEFT JOIN num              u      ON a.um = u.codum
    LEFT JOIN num              u1     ON u1.codum = a.um1
    LEFT JOIN num              u2     ON u2.codum = a.um2
    LEFT JOIN num1             uamb   ON uamb.codum1 = o.umambalare
    LEFT JOIN ngest            ng     ON ng.codgest = nai.gestimplicita
    LEFT JOIN nclasea          c      ON c.codclasea = nvl(a.clasa,0)
    LEFT JOIN npart            p      ON p.codpart  = o.codproducator
    LEFT JOIN NAGENDA          NAG    ON p.codpart = NAG.CODPART AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND coalesce(NAG.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT         LOC    ON NAG.CODLOCALIT = LOC.CODLOCALIT
    LEFT JOIN NJUDET           JUD    ON JUD.CODJUDET   = LOC.CODJUDET
    LEFT JOIN ioart            ioa    ON ioa.codioart = nai.contimplicit
    LEFT JOIN ioart1           ioa1   ON ioa1.codioart = nai.contimplicit AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN ioa1.alstart AND ioa1.alstop
    LEFT JOIN ncont            nc     ON nc.codcont = DECODE(a.tiparticol,0,ioa1.cont,2,ioa1.cont,a.contserviciu)
    LEFT JOIN nclaseas         cs     ON cs.codclaseas = a.clasastatist
    LEFT JOIN ncarsupart       s      ON s.codcarsupart = o.codcaract
    LEFT JOIN ntari            t      ON t.codtara = o.taraorigine
    LEFT JOIN nartobj1         o1     ON o1.codobiect = o.codobiect AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN o1.alstart AND o1.alstop
    LEFT JOIN pretm            pm     ON pm.codobiect = o.codobiect AND pm.implicit = 1 AND pm.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN ntaxe            ntacc  ON ntacc.codtaxa = a1.codaccize
    LEFT JOIN ntaxe            ntax1  ON ntax1.codtaxa = a1.codtaxa1
    LEFT JOIN ntaxe            ntax2  ON ntax2.codtaxa = a1.codtaxa2&apos;||
    gSuplJoins||&apos;
  WHERE  a.codarticol &gt; 0 &apos;;

  if not vToateArt then
    sInsert := sInsert|| &apos;
    AND O.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; )&apos;;
  end if;

  --pkg_list_base_utils.UMPLE_TMP_NARTOBJ1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NART1_LST;
  --pkg_list_base_utils.UMPLE_TMP_IOART1_LST;
  --pkg_list_base_utils.UMPLE_TMP_NTVA1_LST;
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;IOART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NARTOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDEB9B3A70F033FB4D2FEE51D79F723A2126480A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NARTOFE IS

  vToateArt     BOOLEAN ;
  vPretImplicit BOOLEAN;
  vStocSubCur   BOOLEAN;
  vCatPret      PRETM.CODCATPRET%TYPE;
  vNrCol        INTEGER;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(25000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(15000);
  gSuplJoins  VARCHAR2(15000);

PROCEDURE BAGA_DINAMIC_COLS IS
  K     INTEGER := 0;
BEGIN
  DELETE tmp_dinamic_cols;
  IF NOT vPretImplicit AND vCatPret &lt;= 0 AND PKG_GLOBALS.GETSUBUNITATE &gt; 1 THEN
		if NVL(vCatPret,0) = -1 then
			if vToateArt then
				FOR v_rec IN (
					SELECT CODCATPRET, DEN_CATPRET
					FROM ncatpret
					WHERE CODCATPRET in
					( select distinct CODCATPRET from PretM p)
					ORDER BY CODCATPRET)
				LOOP
					k := k + 1;
					INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;L&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Lei&apos;,v_rec.CODCATPRET);
					INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Valuta&apos;,v_rec.CODCATPRET);
				END LOOP;
			else
				FOR v_rec IN (
					SELECT CODCATPRET, DEN_CATPRET
					FROM ncatpret
					WHERE CODCATPRET in
					(
						select distinct CODCATPRET from PretM p
						where CodObiect in ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos;))
					ORDER BY CODCATPRET)
				LOOP
					k := k + 1;
					INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;L&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Lei&apos;,v_rec.CODCATPRET);
					INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Valuta&apos;,v_rec.CODCATPRET);
				END LOOP;
			end if;
		else
			FOR v_rec IN (
				SELECT CODCATPRET, DEN_CATPRET
				FROM ncatpret
				WHERE CODCATPRET &lt;&gt; 0
				ORDER BY CODCATPRET)
			LOOP
				k := k + 1;
				INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;L&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Lei&apos;,v_rec.CODCATPRET);
				INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos;||to_char(k), v_rec.DEN_CATPRET||&apos;/Valuta&apos;,v_rec.CODCATPRET);
			END LOOP;
	  end if;
  END IF;
  COMMIT;
  vNrCol := k;
END;

PROCEDURE SETPARAMS( pToateArt     IN NUMBER DEFAULT 1,
                     pPretImplicit IN NUMBER DEFAULT 1,
                     pCatPret      IN NUMBER DEFAULT 0,
                     pStocSubCur   IN NUMBER DEFAULT 0)
IS
BEGIN
  vToateArt     := pToateArt = 1;
  vPretImplicit := pPretImplicit = 1;
  vCatPret      := pCatPret;
  vStocSubCur   := pStocSubCur = 1;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert         VARCHAR2(20000);
  sJoinDC         VARCHAR2(10000) := &apos;&apos;;
  sJoinPA         VARCHAR2(10000) := &apos;&apos;;
  sCursPA         VARCHAR2(10000) := &apos;&apos;;
  sInsertDC       VARCHAR2( 5000) := &apos;&apos;;
  sSelectDC       VARCHAR2( 5000) := &apos;&apos;;
  sMultimeCatPret VARCHAR2( 5000) := &apos;&apos;;
	sCondCatPret    VARCHAR2(  100);
  sColMinMax      VARCHAR2(  100) := &apos;, os.stocmin, os.stocmed, os.stocmax&apos;;
  AnPrec          NUMBER(4);
  LunaPrec        NUMBER(2);
  k               INTEGER;
  aSitV           NUMBER(1);
  aBancaV         NUMBER(20);
  aMonedaV        NUMBER(20);
BEGIN

  gSuplCols := &apos;nartobj o, nart a, pretm p, nsubunit sub, ncatpret ncp, nartimplicite nai, num u, num1 u1, num1 uamb, ngest ng, nmonede mon, nclasea c, npart npart, &apos;
            || &apos;ntaxe ntacc, ntaxe ntax1, ntaxe ntax2, ncont nc, nagenda nag, nlocalit loc, njudet jud&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, o.stocmin, o.stocmed, o.stocmax&apos;;
  END IF;

  IF PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 AND pkg_categconst.GetValConstanta(&apos;PretAchizSubunit&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru)  = 2 THEN
    sJoinPA := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST AND NG.CODSUBUNIT = &apos;||PKG_GLOBALS.GETSUBUNITATE;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCursPA   := &apos;/ PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, pa.dataachizlast )&apos;;
  END IF;

	IF vPretImplicit OR NVL(vCatPret,0) &lt;= 0
  THEN sCondCatPret := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;p&apos;)||&apos; AND p.implicit = 1 &apos;;
  ELSE sCondCatPret := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;p&apos;)||&apos; AND p.codcatpret = &apos;||vCatPret;
  END IF;

  pkg_globals.SetLunaTemp(pkg_globals.AnLucru,pkg_globals.LunaLucru);
  pkg_globals.Calculeaza_Luna_Precedenta(pkg_globals.AnLucru,pkg_globals.LunaLucru, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);
  pkg_list_base_utils.make_config_luna_ioart;

  IF vNrCol &gt; 0 THEN
    sJoinDC := &apos;
    LEFT JOIN (
      SELECT p.codobiect&apos;;
    FOR k IN 1..vNrCol LOOP
      sJoinDC := sJoinDC||&apos;,Max(Decode(c.x,&apos;||k||&apos;,p.lei,0)) l&apos;||k||&apos;, Max(Decode(c.x,&apos;||k||&apos;,p.valuta,0)) v&apos;||k;
      sInsertDC := sInsertDC||&apos;,L&apos;||k||&apos;, V&apos;||k;
      sSelectDC := sSelectDC||&apos;,dc.L&apos;||k||&apos;, dc.V&apos;||k;
    END LOOP;
    sMultimeCatPret := &apos;&lt;&gt; 0&apos;;
		if NVL(vCatPret,0) = -1 then
			if vToateArt then
  			sMultimeCatPret := &apos;in ( select distinct CODCATPRET from PretM )&apos;;
		  else
  			sMultimeCatPret := &apos;in ( select distinct CODCATPRET from PretM where codobiect IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;))&apos;;
	    end if;
		else
			sMultimeCatPret := &apos;&lt;&gt; 0&apos;;
	  end if;
    sJoinDC := sJoinDC||&apos;
      FROM ( SELECT Dense_Rank() OVER (ORDER BY CODCATPRET) x, CODCATPRET FROM ncatpret WHERE CODCATPRET &apos;||sMultimeCatPret||&apos;) c
        LEFT JOIN pretm p ON p.codcatpret = c.codcatpret
      WHERE p.subunitatea = PKG_GLOBALS.GETSUBUNITATE &apos;;
      IF not vToateArt THEN
        sJoinDC := sJoinDC||&apos;
        AND p.codobiect IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; )&apos;;
      END IF;
    sJoinDC := sJoinDC||&apos;
      GROUP BY p.codobiect
    ) dc ON dc.codobiect = o.codobiect&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    CodObiect, DenArt, CodExtern, TipSer, DenUM, DenClasaA,
    Masa, Volum, PretVinz, PretValuta, TVAPret, ProcTVA, Moneda,
    TipUM, PretMaximal, StocMinim, StocMediu, StocMaxim, TipArticol, TipContabil,
    ContImplicit, CodArt, StocCurent, PretPrestab, CodIntern, Producator, SimbolClasaA,
    GestImpl, CodVamal, Accize, TaxeSupl1, TaxeSupl2,
    Promotie, UMAmb, ParAmb, CNAS, ARETG,
    tippretmax,
    PRETMIN, SUBUNITATEA,
    PRACHIZLAST, PRACHIZLASTV, PRACHIZMAX
    , x_Judet, X_CodSubunit,X_CodGest,X_CodClasaP &apos;||sInsertDC||gUserFields||&apos; )
  WITH S AS (
    SELECT ns.codobiect, SUM(vs.rest) rest
    FROM v_stocluna vs
      INNER JOIN nirstoc ns ON ns.codnirstoc = vs.codnirstoc
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN ngest g ON g.codgest = n.gest&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;,&apos;
    WHERE&apos;)||&apos;
    GROUP BY ns.codobiect),
  PA AS (
    SELECT
      NS.CODOBIECT,
      MAX(NS.PRET-NS.ADAOS) KEEP (DENSE_RANK LAST ORDER BY N.DATANIR) PRACHIZLAST,
      MAX(N.DATANIR) DATAACHIZLAST,
      MAX(NS.PRET-NS.ADAOS) PRACHIZMAX
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||
      sJoinPA||&apos;
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0&apos;;

  IF not vToateArt THEN
    sInsert := sInsert|| &apos;
      AND ns.codobiect IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; )&apos;;
  END IF;

  sInsert := sInsert|| &apos;
    GROUP BY NS.CODOBIECT )
  SELECT
    o.codobiect, o.denumire, o.codextern, CASE a.tipserie WHEN 0 THEN &apos;&apos;fara serie&apos;&apos; WHEN 1 THEN &apos;&apos;serie pe bucata&apos;&apos; WHEN 2 THEN &apos;&apos;serie pe lot&apos;&apos; ELSE &apos;&apos;&apos;&apos; END, u.den_um , c.Den_Clasea,
    o.Masa, o.Volum, p.lei as PretVanz, p.valuta, CASE ncp.tip WHEN 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END, t.procent, mon.den_moneda,
    u.tip, o1.pretmaximal&apos;||sColMinMax||&apos;, CASE a.tiparticol WHEN &apos;&apos;0&apos;&apos; THEN &apos;&apos;Stoc&apos;&apos; ELSE &apos;&apos;Serviciu&apos;&apos; END, ioa.den_ioart,
    nc.simbol, a.codarticol, Nvl(s.rest,0), o1.pretreferinta, o.codintern, npart.den_part, c.simbol ,
    ng.den_gest, o.codvamal, ntacc.den_taxa, ntax1.den_taxa, ntax2.den_taxa,
    CASE o.promotie WHEN 0 THEN &apos;&apos;Nu&apos;&apos; ELSE &apos;&apos;Da&apos;&apos; END, uamb.den_um1, uamb.paritate, o.codcnas, CASE a.aretg WHEN 0 THEN &apos;&apos;Nu&apos;&apos; ELSE &apos;&apos;Da&apos;&apos; END aretg,
		CASE o1.tippretmax
      WHEN 1 THEN &apos;&apos;din stoc * Impus&apos;&apos;
      WHEN 2 THEN &apos;&apos;din stoc * Recomandat&apos;&apos;
      WHEN 3 THEN &apos;&apos;din stoc * Netransmisibil&apos;&apos;
      WHEN 4 THEN &apos;&apos;lunar * Impus&apos;&apos;
      WHEN 5 THEN &apos;&apos;lunar * Recomandat&apos;&apos;
      WHEN 6 THEN &apos;&apos;lunar * Netransmisibil&apos;&apos;
      WHEN 7 THEN &apos;&apos;nu se foloseste&apos;&apos;
      ELSE &apos;&apos; &apos;&apos;
    END TIPPRETMAX,
    o.pretminim, sub.den_subunit,
    pa.prachizlast, pa.prachizlast &apos;||sCursPA||&apos;, pa.prachizmax,
    coalesce(JUD.SIMBAUTO,&apos;&apos;XX&apos;&apos;), sub.codsubunit, ng.codgest, npart.codclasa &apos;||sSelectDC||gUserAlias||&apos;
  FROM nartobj o
    LEFT JOIN nart             a     ON a.codarticol   = o.codarticol
    LEFT JOIN nartobjsubunit   os    ON os.codobiect   = o.codobiect AND (os.codgest is null or os.codgest = 0) AND os.subunitate = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN pretm            p     ON p.codobiect    = o.codobiect &apos;||sCondCatPret||&apos;
    LEFT JOIN nsubunit         sub   ON sub.codsubunit = NVL(p.subunitatea,&apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)
    LEFT JOIN ncatpret         ncp   ON ncp.codcatpret = p.codcatpret
    LEFT JOIN nartobj1         o1    ON o.codobiect    = o1.codobiect  AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN o1.ALStart AND o1.ALStop
    LEFT JOIN nart1            a1    on a.codarticol   = a1.codarticol AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN a1.ALStart AND a1.ALStop
    LEFT JOIN nartimplicite    nai   ON nai.codarticol = a.codarticol AND nai.codsubunit = Coalesce(p.subunitatea,&apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)
    LEFT JOIN nartobjimp       noi   ON noi.codobiect  = o.codobiect  AND noi.codsubunit = Coalesce(p.subunitatea,&apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)
    LEFT JOIN num              u     ON a.um           = u.codum
    LEFT JOIN num1             u1    ON u1.codum1      = a.um1
    LEFT JOIN num1             uamb  ON uamb.codum1    = o.umambalare
    LEFT JOIN ngest            ng    ON ng.codgest     = nai.gestimplicita
    LEFT JOIN nmonede          mon   ON mon.codmoneda  = p.moneda
    LEFT JOIN nclasea          c     ON c.codclasea    = a.clasa
    LEFT JOIN npart                  ON npart.codpart  = o.codproducator
    LEFT JOIN NAGENDA          NAG   ON npart.codpart  = NAG.CODPART AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND coalesce(NAG.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT         LOC   ON NAG.CODLOCALIT = LOC.CODLOCALIT
    LEFT JOIN NJUDET           JUD   ON JUD.CODJUDET   = LOC.CODJUDET
    LEFT JOIN ntaxe            ntacc ON ntacc.codtaxa  = a1.codaccize
    LEFT JOIN ntaxe            ntax1 ON ntax1.codtaxa  = a1.codtaxa1
    LEFT JOIN ntaxe            ntax2 ON ntax2.codtaxa  = a1.codtaxa2
    LEFT JOIN ioart1           i1    ON i1.codioart    = case when coalesce(noi.contimplicit,0) = 0 then nai.contimplicit else coalesce(noi.contimplicit,0) end AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN i1.ALStart AND i1.ALStop
    LEFT JOIN ioart            ioa   ON i1.codioart    = ioa.codioart
    LEFT JOIN ncont            nc    ON nc.codcont     = CASE a.tiparticol WHEN &apos;&apos;0&apos;&apos; THEN i1.cont ELSE a.contserviciu END
    LEFT JOIN ntva1            t     ON t.codtva       = a1.codtva  AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN t.ALStart AND t.ALStop
    LEFT JOIN s                      ON s.codobiect    = o.codobiect
    LEFT JOIN pa                     ON pa.codobiect   = o.codobiect&apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE o.codarticol &gt; 0 &apos;;

  IF not vToateArt THEN
    sInsert := sInsert|| &apos;
    AND o.codobiect IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; )&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
--  pkg_globals.ResetAllRecordsLunaFlags;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NARTOFE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NARTPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F1B85F9C3B965CB9EAA70843B825A13A7023830</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nartpart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sColMinMax VARCHAR2(  100):= &apos;, os.stocmin, os.stocmed, os.stocmax&apos;;
BEGIN

  gSuplCols := &apos;npart p, nartobj o, nart a, nartcli ac, num u, num1 u1, num1 uamb, ngest ng, nclasea c, npart prod, ncont nc, nclaseas cs, ncarsupart s, ioart ioa, ntari t, nartobj1 o1, pretm pm&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, o.stocmin, o.stocmed, o.stocmax&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    DenPart, DenArt, ArtPart, TipSer,
    DenUM, DenClasaA, SimbolClasaA, Masa, Volum, StocMinim, StocMediu, StocMaxim, TipArticol, TipContabil, ContImplicit,
    CodIntern, CodExtern, CodExtPart,
    CodListat,
    Producator, GestImpl, Promotie, UMAmb, ParAmb, CNAS, AreTG,
    TipPretMax,
    Accize, TaxeSupl1, TaxeSupl2,
    NRCOLETE&apos;||
    gUserFields||&apos;)
  WITH
    NAI AS (
      SELECT O.CODOBIECT, COALESCE(NOI.CODSUBUNIT,0) CODSUBUNIT, 
      CASE WHEN COALESCE(NOI.CONTIMPLICIT,0) = 0 THEN NAI.CONTIMPLICIT ELSE COALESCE(NOI.CONTIMPLICIT,0) END CONTIMPLICIT, 
      CASE WHEN COALESCE(NOI.GESTIMPLICITA,0) = 0 THEN NAI.GESTIMPLICITA ELSE COALESCE(NOI.GESTIMPLICITA,0) END GESTIMPLICITA, 
      CASE WHEN COALESCE(NOI.LOCATIEIMPLICITA,0) = 0 THEN NAI.LOCATIEIMPLICITA ELSE COALESCE(NOI.LOCATIEIMPLICITA,0) END LOCATIEIMPLICITA
      FROM NARTOBJ O
           INNER JOIN NART          A   ON A.CODARTICOL = O.CODARTICOL
           LEFT  JOIN NARTIMPLICITE NAI ON A.CODARTICOL = NAI.CODARTICOL AND NAI.CODSUBUNIT = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
           LEFT  JOIN NARTOBJIMP    NOI ON O.CODOBIECT  = NOI.CODOBIECT  AND NOI.CODSUBUNIT = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    )
  SELECT
    p.den_part, o.denumire, COALESCE(ac.denumire,ntrad.denumiretrad,o.denumire), decode(a.tipserie,0,&apos;&apos;fara serie&apos;&apos;, 1, &apos;&apos;serie pe bucata&apos;&apos;, 2, &apos;&apos;serie pe lot&apos;&apos;) tipser,
    u.den_um1, c.Den_Clasea, c.simbol, o.Masa, o.Volum&apos;||sColMinMax||&apos;, decode(a.tiparticol,0,&apos;&apos;Stoc&apos;&apos;,&apos;&apos;Serviciu&apos;&apos;) TipArt, ioa.den_ioart TipContabil, nc.simbol,
    o.codintern, o.codextern, ac.codextern,
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu/*,7,o1.codextofe*/),o.codextern),
    prod.den_part, ng.den_gest, decode(o.promotie,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;), uamb.den_um1, uamb.paritate, o.codcnas, decode(a.aretg,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) aretg,
    decode(o1.tippretmax,1,&apos;&apos;din stoc * Impus&apos;&apos;, 2,&apos;&apos;din stoc * Recomandat&apos;&apos;, 3,&apos;&apos;din stoc * Netransmisibil&apos;&apos;,
                         4,&apos;&apos;lunar * Impus&apos;&apos;, 5,&apos;&apos;lunar * Recomandat&apos;&apos;, 6,&apos;&apos;lunar * Netransmisibil&apos;&apos;,
                         7,&apos;&apos;nu se foloseste&apos;&apos;),
    ntacc.den_taxa, ntax1.den_taxa, ntax2.den_taxa,
    (SELECT COUNT(1) FROM nartobjcolet oc WHERE oc.codobiect = o.codobiect)&apos;||
    gUserAlias||&apos;
  FROM nartcli ac
    INNER JOIN npart          p     ON p.codpart       = ac.codpart
    INNER JOIN nartobj        o     ON o.codobiect     = ac.codobiect
    INNER JOIN nart           a     ON a.codarticol    = o.codarticol
    LEFT  JOIN nagenda        ssoc  ON ssoc.codpart    = p.codpart     AND ssoc.sediusocial BETWEEN 4 AND 7 AND NVL(ssoc.inactiv, 0) = 0
    LEFT  JOIN nlocalit       lsoc  ON ssoc.codlocalit = lsoc.codlocalit
    LEFT  JOIN ntari          tsoc  ON tsoc.codtara    = lsoc.codtara
    LEFT  JOIN nartobjtrad    ntrad ON ntrad.codlimba  = tsoc.codlimba and ntrad.codobiect = o.codobiect
    LEFT  JOIN nai                  ON nai.codobiect   = o.codobiect
    LEFT  JOIN nechiv         e     ON e.codobiect     = o.codobiect
    LEFT  JOIN grechiv        gre   ON gre.codgrechiv  = e.codgrupa
    LEFT  JOIN nart1          a1    on a.codarticol    = a1.codarticol AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN a1.ALSTART and a1.ALSTOP
    LEFT  JOIN nartobjsubunit os    ON os.codobiect    = o.codobiect  
                                    and ( os.codgest is null or os.codgest = 0) 
                                    AND os.subunitate = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT  JOIN num1           u     ON u.codum1        = ac.umsec
    LEFT  JOIN num1           u1    ON u1.codum1       = a.um1
    LEFT  JOIN num1           uamb  ON uamb.codum1     = o.umambalare
    LEFT  JOIN ngest          ng    ON ng.codgest      = nai.gestimplicita
    LEFT  JOIN nclasea        c     ON c.codclasea     = a.clasa
    LEFT  JOIN npart          prod  ON prod.codpart    = o.codproducator
    LEFT  JOIN ioart          ioa   ON ioa.codioart    = nai.contimplicit
    LEFT  JOIN ioart1         ioa1  ON ioa1.codioart   = nai.contimplicit AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN ioa1.ALSTART and ioa1.ALSTOP
    LEFT  JOIN ncont          nc    ON nc.codcont      = DECODE(a.tiparticol,0,ioa1.cont,a.contserviciu)
    LEFT  JOIN nclaseas       cs    ON cs.codclaseas   = a.clasastatist
    LEFT  JOIN ncarsupart     s     ON s.codcarsupart  = o.codcaract
    LEFT  JOIN ntari          t     ON t.codtara       = o.taraorigine
    LEFT  JOIN nartobj1       o1    ON o1.codobiect    = o.codobiect   AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN o1.ALSTART and o1.ALSTOP
    LEFT  JOIN pretm          pm    ON pm.codobiect    = o.codobiect   AND pm.implicit = 1 AND pm.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT  JOIN ntaxe          ntacc ON ntacc.codtaxa   = a1.codaccize
    LEFT  JOIN ntaxe          ntax1 ON ntax1.codtaxa   = a1.codtaxa1
    LEFT  JOIN ntaxe          ntax2 ON ntax2.codtaxa   = a1.codtaxa2&apos;||
    gSuplJoins||&apos;
  WHERE nvl(ac.codpart,0) &gt; 0 AND NVL(ac.codobiect,0) &gt; 0&apos;;

  IF NOT pkg_list_selpart.IsAllPart THEN
    sInsert := sInsert|| &apos;
    AND ac.CODPART IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; )&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_nartpart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NARTUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84A8FFC734B264C65CE5388CDE791E2D10B03362</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nartum IS
  vToateArt       BOOLEAN ;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1)
IS
BEGIN
  vToateArt := pToateArt = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sJoinExt   VARCHAR2(1000);
BEGIN

  gSuplCols := &apos;nartobj o, nart a, num u, num1 u1, nclasea c, nclaseas cs, npart prod, NAGENDA NAG, NLOCALIT LOC, NJUDET JUD&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    DenArt, DenUM, DenUM1, Princ, Par, DenClasaA, SimbolClasaA, Masa, Volum
    , x_Judet, X_CodSubunit, X_CodClasaP &apos;||
    gUserFields||&apos;)
  SELECT
    o.denumire, u.den_um, u1.den_um1, Decode(u1.secundara,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), u1.paritate, c.Den_Clasea, c.simbol, o.Masa, o.Volum
    , coalesce(JUD.SIMBAUTO,&apos;&apos;XX&apos;&apos;), &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;, prod.codclasa &apos;||
    gUserAlias||&apos;
  FROM NARTOBJ o
    INNER JOIN nart    a    ON a.codarticol   = o.codarticol
    LEFT JOIN num      u    ON u.codum        = a.um
    LEFT JOIN num1     u1   ON u1.codum       = a.um
    LEFT JOIN nclasea  c    ON c.codclasea    = nvl(a.clasa,0)
    LEFT JOIN nclaseas cs   ON cs.codclaseas  = nvl(a.clasastatist,0)
    LEFT JOIN npart    prod ON prod.codpart   = o.codproducator
    LEFT JOIN NAGENDA  NAG  ON prod.codpart   = NAG.CODPART AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND coalesce(NAG.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LOC  ON NAG.CODLOCALIT = LOC.CODLOCALIT
    LEFT JOIN NJUDET   JUD  ON JUD.CODJUDET   = LOC.CODJUDET &apos;||
    gSuplJoins||&apos;
  WHERE a.codarticol &gt; 0 &apos;;

  IF NOT vToateArt THEN
    sInsert := sInsert|| &apos;
    AND O.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NARTUM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD0AEC3344B56F22DBDCA420490F799A68267918</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols :=
    &apos;NC N, NC1 N1, NMONEDE M, NGEST G, NPARCAUT PAUT, NPART NPD, NPART NPC, NCONT NCD, NCONT NCC, NCONT1 NC1D, NCONTS CSD, NCONT1 NC1C, NCONTS CSC, CENTRECOST CC, &apos;||
    &apos;ANALIZANOD ANOD, ANALIZA ANALIZ, DESCRIPTORI1 ADESC1, DESCRIPTORI ADESC, NPERS AGENT, FORMATII FORM&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CODDOC,NAV_TIPDOC, DOC, NUMAR, DataDoc, Observatii, MONEDA, CURS, NrLinie,
    TipLTva,
    SimbContDebit, SimbContCredit, PartDebit, PartCredit,
    Valoare, Gestiune, Obs1, Subunit, SimbContSD, SimbContSC, CentruCost, Transport&apos;||gUserFields||&apos;)
  SELECT
    N.CODNC, 35 as TIPD, N.NRDOC as DOC, N.NRDOC, N.DATADOC, N.OBS, M.SIMBOL, N.CURS, N1.INDEXLOCAL,
    DECODE(N1.TIPLINIETVA, 2, &apos;&apos;Baza TVA stocuri&apos;&apos;, 3, &apos;&apos;Val. TVA stocuri&apos;&apos;, 4, &apos;&apos;Baza TVA servicii&apos;&apos;, 5, &apos;&apos;Val. TVA servicii&apos;&apos; , &apos;&apos;-&apos;&apos;),
    NCD.SIMBOL, NCC.SIMBOL, DECODE(N1.PARTD,1,NPD.DEN_PART,&apos;&apos;--&apos;&apos;), DECODE(N1.PARTC,1,NPC.DEN_PART,&apos;&apos;--&apos;&apos;),
    N1.VALOARE, G.DEN_GEST ,N1.Obs, NS.DEN_SUBUNIT, CSD.Simbol, CSC.Simbol, CC.Denumire, PAUT.NRINREG &apos;||gUserAlias||&apos;
  FROM NC N
    LEFT JOIN NC1          N1 ON N1.CODNC                  = N.CODNC
    LEFT JOIN NMONEDE      M ON M.CODMONEDA                = N.Moneda
    LEFT JOIN NSUBUNIT     NS ON NS.CODSUBUNIT             = N.SUBUNITATEA
	  LEFT JOIN NGEST        G ON G.CODGEST                  = N1.CODGEST
    LEFT JOIN NPARCAUT     PAUT ON PAUT.CODNPARCAUT        = N1.CODAUTO
	  LEFT JOIN NPART        NPD ON NPD.CODPART              = CASE WHEN COALESCE(N1.PARTD,0) = 0 THEN 0 WHEN COALESCE(N1.CODPART,0) &lt;&gt; 0 THEN N1.CODPART ELSE N.PART END
	  LEFT JOIN NCONT        NCD ON NCD.CODCONT              = CASE
                                                               WHEN N1.PARTD = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTD, NPD.CODPART, N.AN*12+N.LUNA, 1200)
                                                               WHEN N1.PERSD = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTD, N1.AGENT,    N.AN*12+N.LUNA, 1100)
                                                               ELSE N1.CONTD
                                                             END
    LEFT JOIN NCONT1       NC1D ON NC1D.CODCONT            = NCD.CODCONT AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN NC1D.ALSTART and NC1D.ALSTOP
    LEFT JOIN NCONTS       CSD ON CSD.CODCONTS             = NC1D.CONTSECUNDAR
	  LEFT JOIN NPART        NPC ON NPC.CODPART              = CASE WHEN COALESCE(N1.PARTC,0) = 0 THEN 0 WHEN COALESCE(N1.CODPART,0) &lt;&gt; 0 THEN N1.CODPART ELSE N.PART END
	  LEFT JOIN NCONT        NCC ON NCC.CODCONT              = CASE  
                                                               WHEN N1.PARTC = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTC, NPC.CODPART, N.AN*12+N.LUNA, 1201)
                                                               WHEN N1.PERSC = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTC, N1.AGENT,    N.AN*12+N.LUNA, 1101)
                                                               ELSE N1.CONTC
                                                             END
    LEFT JOIN NCONT1       NC1C ON NC1C.CODCONT            = NCC.CODCONT AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN NC1C.ALSTART and NC1C.ALSTOP
    LEFT JOIN NCONTS       CSC ON CSC.CODCONTS             = NC1C.CONTSECUNDAR
    LEFT JOIN CENTRECOST   CC ON CC.CODCENTRU              = CASE WHEN Nvl(N1.CODCENTRU,0) &gt; 0 THEN N1.CODCENTRU WHEN NVL(NC1D.CODCENTRU,0) &gt; 0 THEN NC1D.CODCENTRU ELSE NVL(NC1C.CODCENTRU,0) END
    LEFT JOIN ANALIZANOD   ANOD ON anod.codanalizanod      = n1.codanalizanod
    LEFT JOIN ANALIZA      ANALIZ ON analiz.codanaliza     = anod.codanaliza
    LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
    LEFT JOIN DESCRIPTORI  ADESC ON adesc.coddescriptor    = adesc1.coddescriptor
    LEFT JOIN NPERS        AGENT ON AGENT.CODPERS          = N1.AGENT
    LEFT JOIN FORMATII     FORM ON FORM.CODFORMATIE        = N1.CODFORMATIE&apos;||
    gSuplJoins||&apos;
  WHERE N.AN*12+N.LUNA = &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos;
    AND Nvl(N.SABLON,0) = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;) ;

  if not pkg_globals.GET_DREPT_SALARIZARE = 1 then
    sInsert := sInsert||&apos; AND N.JurnalTVA &lt;&gt; 5&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NCDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45F33034247D0FAE0FD9832EF9A1AF0D4BD0D3D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NCDOC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodNC IN NUMBER) IS
BEGIN
  vCodNC := pCodNC;
END;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols :=
    &apos;NC N, NC1 N1, NMONEDE M, NGEST G, NPARCAUT PAUT, NPART NPD, NPART NPC, NCONT NCD, NCONT NCC, NCONT1 NC1D, NCONTS CSD, NCONT1 NC1C, NCONTS CSC, CENTRECOST CC, &apos;||
    &apos;ANALIZANOD ANOD, ANALIZA ANALIZ, DESCRIPTORI1 ADESC1, DESCRIPTORI ADESC, NPERS AGENT, FORMATII FORM&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Observatii, Moneda, Curs, NrLinie, TipLTva, SimbContDebit, SimbContCredit,
    Valoare, Gestiune, ObservatiiLinie, DenContDebit, DenContCredit, CentruCost&apos;||gUserFields||&apos;)
  SELECT
    N.OBS, M.SIMBOL, N.CURS, N1.INDEXLOCAL,
    DECODE(N1.TIPLINIETVA, 2, &apos;&apos;Baza TVA stocuri&apos;&apos;, 3, &apos;&apos;Val. TVA stocuri&apos;&apos;, 4, &apos;&apos;Baza TVA servicii&apos;&apos;, 5, &apos;&apos;Val. TVA servicii&apos;&apos; , &apos;&apos;-&apos;&apos;),
    NCD.SIMBOL, NCC.SIMBOL, N1.VALOARE, G.DEN_GEST, N1.Obs, NCD.DEN_CONT, NCC.DEN_CONT, CC.DENUMIRE &apos;||gUserAlias||&apos;
  FROM NC N
    LEFT JOIN NC1          N1     ON N1.CODNC              = N.CODNC
    LEFT JOIN NMONEDE      M      ON M.CODMONEDA           = N.MONEDA
    LEFT JOIN NGEST        G      ON G.CODGEST             = N1.CODGEST
    LEFT JOIN NPARCAUT     PAUT   ON PAUT.CODNPARCAUT      = N1.CODAUTO
	  LEFT JOIN NPART        NPD    ON NPD.CODPART           = CASE WHEN COALESCE(N1.PARTD,0) = 0 THEN 0 WHEN COALESCE(N1.CODPART,0) &lt;&gt; 0 THEN N1.CODPART ELSE N.PART END
	  LEFT JOIN NPART        NPC    ON NPC.CODPART           = CASE WHEN COALESCE(N1.PARTC,0) = 0 THEN 0 WHEN COALESCE(N1.CODPART,0) &lt;&gt; 0 THEN N1.CODPART ELSE N.PART END
	  LEFT JOIN NCONT        NCD    ON NCD.CODCONT           = CASE
                                                               WHEN N1.PARTD = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTD, NPD.CODPART, N.AN*12+N.LUNA, 1200)
                                                               WHEN N1.PERSD = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTD, N1.AGENT,    N.AN*12+N.LUNA, 1100)
                                                               ELSE N1.CONTD
                                                             END
	  LEFT JOIN NCONT        NCC    ON NCC.CODCONT           = CASE
                                                               WHEN N1.PARTC = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTC, NPC.CODPART, N.AN*12+N.LUNA, 1201)
                                                               WHEN N1.PERSC = 1 THEN PKG_LIST_BASE_UTILS.iCont_CodCont(N1.ICONTC, N1.AGENT,    N.AN*12+N.LUNA, 1101)
                                                               ELSE N1.CONTC
                                                             END
    LEFT JOIN NCONT1       NC1D   ON NC1D.CODCONT          = N1.CONTD AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN NC1D.ALSTART and NC1D.ALSTOP
    LEFT JOIN NCONTS       CSD    ON CSD.CODCONTS          = NC1D.CONTSECUNDAR
    LEFT JOIN NCONT1       NC1C   ON NC1C.CODCONT          = N1.CONTC AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN NC1C.ALSTART and NC1C.ALSTOP
    LEFT JOIN NCONTS       CSC    ON CSC.CODCONTS          = NC1C.CONTSECUNDAR
    LEFT JOIN CENTRECOST   CC     ON CC.CODCENTRU          = CASE WHEN Nvl(N1.CODCENTRU,0) &gt; 0 THEN N1.CODCENTRU WHEN NVL(NC1D.CODCENTRU,0) &gt; 0 THEN NC1D.CODCENTRU ELSE NVL(NC1C.CODCENTRU,0) END
    LEFT JOIN ANALIZANOD   ANOD   ON anod.codanalizanod    = n1.codanalizanod
    LEFT JOIN ANALIZA      ANALIZ ON analiz.codanaliza     = anod.codanaliza
    LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
    LEFT JOIN DESCRIPTORI  ADESC  ON adesc.coddescriptor   = adesc1.coddescriptor
    LEFT JOIN NPERS        AGENT  ON AGENT.CODPERS         = N1.AGENT
    LEFT JOIN FORMATII     FORM   ON FORM.CODFORMATIE      = N1.CODFORMATIE&apos;||
    gSuplJoins||&apos;
	WHERE N.CodNC = &apos;||vCodNC;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      P.DEN_PART, NC.OBS, NC.NRDOC, NC.DATADOC,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI
    FROM NC
      LEFT JOIN NPART P ON NVL(NC.PART, 0) = P.CODPART
      LEFT JOIN NPERS U ON U.LOGONNAME     = NC.USERID
    WHERE NC.CodNC = vCodNC
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,                        v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr NC&apos;,                           v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data NC&apos;,                         To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);

    EXIT;
  END LOOP;
  COMMIT;

END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


end PKG_LIST_BASE_NCDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29BF3B169926F8906C2FD96581D972D5E5315525</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NCLASEA IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(500);
BEGIN
  gSuplCols := &apos;nclasea nc&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos; ( DENUMIRE,SIMBOL, NIVEL, NRANALITICE &apos;||gUserFields||&apos;)&apos;||
	  &apos;SELECT lpad(&apos;&apos; &apos;&apos;,LEVEL*2,&apos;&apos; &apos;&apos;)||nc.den_clasea,nc.simbol,LEVEL AS nivel, nc.nranalitice&apos;||gUserAlias||&apos; &apos;||
    &apos;FROM nclasea nc &apos;||
    gSuplJoins||
    &apos;START WITH nc.codparinte IS NULL &apos;|| 
		&apos;CONNECT BY PRIOR nc.codclasea = nc.codparinte &apos;;
    
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;		
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NCLASEA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2F1597CFF9B75560222455626F8B53BDB47181D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_ncont IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
	sInsert VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols := &apos;NCont NC, NContS NCS, CentreCost CC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

	sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    SIMBOL, DEN_CONT, CLASA, TIP,
    BALANTASINTETICA, BALANTAANALITICA, CODCONT,
    SIMBOLS, TIPS,
    SIMBOLT, TIPT,
    NAME_CONT, SIMB_TransfSF, SIMB_SincrRul, SIMB_TransfD, SIMB_TransfCDim, SIMB_TransfC, CentruCost&apos;||gUserFields||&apos;)
  SELECT
    LPAD(&apos;&apos; &apos;&apos;,DECODE(NC.NIVEL,1,0,NC.NIVEL-1)*2)||nc.simbol simbol, nc.den_cont, nc.clasa, decode(nc.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;),
    decode(nc.balantasintetica,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), decode(nc.vizibilbalanta,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), nc.codcont,
    ncs.simbol, decode(ncs.codconts,NULL,NULL,decode(ncs.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;)),
    nct.simbol, decode(nct.codcontt,NULL,NULL,decode(nct.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;)),
    nc.name, nc_t.simbol, nc_s.simbol, nc_b.simbol, nc_d.simbol, nc_c.simbol, cc.denumire&apos;||gUserAlias||&apos;
  FROM ncont nc
    INNER JOIN ncont1     nc1  ON nc1.codcont  = nc.codcont AND PKG_GLOBALS.AnLunaLucru BETWEEN nc1.ALSTART and nc1.ALSTOP
    LEFT  JOIN nconts     ncs  ON ncs.codconts = nc1.CONTSECUNDAR  
    LEFT  JOIN ncontt     nct  ON nct.codcontt = nc1.CONTTERTIAR   
    LEFT  JOIN ncont      nc_t ON nc_t.codcont = nc1.continkidsold
    LEFT  JOIN ncont      nc_s ON nc_s.codcont = nc1.sincronizare
    LEFT  JOIN ncont      nc_b ON nc_b.codcont = nc1.conttransfd
    LEFT  JOIN ncont      nc_d ON nc_d.codcont = nc1.conttransfcdim
    LEFT  JOIN ncont      nc_c ON nc_c.codcont = nc1.conttransfc
    LEFT  JOIN centrecost cc   ON cc.codcentru = nc1.codcentru&apos;||
    gSuplJoins||&apos;
	ORDER BY ltrim (nc.simbol) &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

	COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_NCONT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E44836EAF8F18CC42DCD31A896376234CED3AFD4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NCONTS is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NContS NC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    SIMBOL, DEN_CONT, CLASA, TIP,
    BALANTASINTETICA, BALANTAANALITICA, CODCONTS,
    SIMBOLP, TIPP,
    NAME_CONT &apos;||gUserFields||&apos;)
  WITH nc1 AS (
    SELECT
      CODCONTS,
      Max(CODCONT)   KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) CODCONT
    FROM nconts1
    WHERE (ANSTART * 12 + LUNASTART) &lt;= PKG_GLOBALS.AnLunaLucru
    GROUP BY CODCONTS
  )
  SELECT
    LPAD(&apos;&apos; &apos;&apos;,DECODE(NC.NIVEL,1,0,NC.NIVEL-1)*2)||nc.simbol simbol, nc.den_cont, nc.clasa, decode(nc.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;),
    decode(nc.balantasintetica,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), decode(nc.vizibilbalanta,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), nc.codconts,
    ncp.simbol, decode(ncp.codcont,NULL,NULL,decode(ncp.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;)),
    nc.name &apos;||gUserAlias||&apos;
  FROM nconts nc
    INNER JOIN nc1 ON nc1.codconts = nc.codconts
    LEFT JOIN ncont ncp ON ncp.codcont = nc1.codcont&apos;||
    gSuplJoins||&apos;
  ORDER BY ltrim(nc.simbol) &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;  

end PKG_LIST_BASE_NCONTS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B0B1BF8126F07C2FEFE6414CAB1696286B38C2B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NCONTT is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NContT NC&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    SIMBOL, DEN_CONT, CLASA, TIP,
    BALANTASINTETICA, BALANTAANALITICA, CODCONTT,
    NAME_CONT &apos;||gUserFields||&apos;)
  SELECT
    LPAD(&apos;&apos; &apos;&apos;,DECODE(NC.NIVEL,1,0,NC.NIVEL-1)*2)||nc.simbol simbol, nc.den_cont, nc.clasa, decode(nc.tipcont,0,&apos;&apos;A&apos;&apos;,1,&apos;&apos;P&apos;&apos;,2,&apos;&apos;Bifunc.&apos;&apos;,&apos;&apos;nedef.&apos;&apos;),
    decode(nc.balantasintetica,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), decode(nc.vizibilbalanta,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;nedef.&apos;&apos;), nc.codcontt,
    nc.name &apos;||gUserAlias||&apos;
  FROM ncontt nc &apos;||
    gSuplJoins||&apos;
  ORDER BY ltrim(nc.simbol) &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;  

end PKG_LIST_BASE_NCONTT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NECCMDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F42F6EBDAC1093524023FB83BF981BAA9CFB174</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NECCMDCLI is

gUserFields  VARCHAR2(2500);
gUserAlias   VARCHAR2(2500);
gNullAlias   VARCHAR2(2500);
gSuplCols    VARCHAR2(2500);
gSuplJoins   VARCHAR2(5000);
vCodAtribut  number(20);
Par2 varchar2(500);

procedure setparams(aCodAtribut in number) is
begin
  vCodAtribut := aCodAtribut;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

function GetSume(aCodArticol in number, aCodComanda in number, Idx in number) return varchar2 is
aRez varchar2(3000);
aTotal number(20,7);
i number(10);
begin
  aTotal := 0;
  i := 0;
  Par2 := &apos;&apos;;
  aRez := &apos;&apos;;
  for v_rec in (
                select a1.valoare, sum(c1.restacceptat) cant, obj.codarticol, c1.codcomanda
                from natrib1 a1
                     inner join natrib at on a1.codatribut = at.codatribut
                     left join
                       (select * from natrobj ato 
                        where exists (select c1.codobiect from comanda1 c1 where c1.codcomanda = aCodComanda and c1.codobiect = ato.codobiect and
                                                                           c1.codobiect in (select codobiect from nartobj where codarticol = aCodArticol))
                       ) ao on ao.codvalatr = a1.codvalatr
                     left join nartobj obj on ao.codobiect = obj.codobiect
                     left join comanda1 c1 on c1.codobiect = ao.codobiect and c1.codcomanda = aCodComanda and c1.codobiect in (select codobiect from nartobj where codarticol = aCodArticol)
                where at.codatribut = vCodAtribut 
                group by a1.valoare, obj.codarticol, c1.codcomanda
                order by a1.valoare
               ) loop
    aTotal := aTotal + nvl(v_rec.Cant,0);
    if v_rec.cant &gt; 0 then
    i := i+1;
    if i &lt; 15 then 
      if i = 1 then
        aRez := v_rec.valoare||&apos;: &apos;||nvl(v_rec.cant,0);
      else
        aRez := aRez||&apos; | &apos;||v_rec.valoare||&apos;: &apos;||nvl(v_rec.cant,0); 
      end if;  
    else
      Par2 := Par2||&apos; | &apos;||v_rec.valoare||&apos;: &apos;||nvl(v_rec.cant,0);
    end if;
    end if;
  end loop;
  aRez := &apos;TOTAL: &apos;||aTotal||&apos; | &apos;||aRez;
  if Idx = 1 then
    return aRez;
  else
    return Par2;
  end if;    
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert varchar2(25000);  
BEGIN
  gSuplCols := &apos;&apos;;
  if PKG_LIST_STRUCT.TmpExists(&apos;COMANDC&apos;) = 1 then
    gSuplCols := &apos;COMANDC CEXT&apos;;
  end if;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      NAV_CodDoc,
      NAV_TipDoc,
      CodProiectNod,
      CodArticol,
      Client,
      Produs,
      CodInternP,
      NrDoc,
      DataDoc,
      Termen,
      Material,
      UM,
      Cant,
      CantU,
      IndexP,
      CodInternM,
      MatEchiv,
      Nivel,
      ObsMat &apos;||gUserFields||&apos;)
    select
      x.NAV_CodDoc,
      x.NAV_TipDoc,
      x.CodProiectNod,
      x.codarticol,
      x.Client,
      x.Produs,
      X.CodInternP,
      x.NrDoc,   
      x.DataDoc,
      x.Termen,
      x.Material,
      x.UM,
      x.Cant,    
      x.CantU,  
      x.indexparinte,
      x.CodInternM,
      x.MatEchiv,
      X.Nivel,
      X.ObsMat &apos;||gUserAlias||&apos;
    from (  
    select 
      c.codcomanda NAV_CodDoc,
      c.tipdoc NAV_TipDOc,
      nod.codproiectnod,
      ac.codarticol,
      p.den_part client,
      ac.den_articol produs,
      oc.codintern codinternp,
      c.nrdoc,
      c.datadoc,
      c1.termen,
      om.denumire material,
      um.den_um UM,
      sum(nod.cant*c1.restlansat/nod0.cant) Cant,
      mat.cant cantu,
      nod.indexparinte,
      om.codintern codinternm,
      case when oech.codobiect &gt; 0 and oech.codobiect &lt;&gt; nod.codobiect then oech.denumire end MatEchiv,
      nvl(nod.nivel,0) Nivel,
      mat.Obs ObsMat  
    from (select codobiect from tmp_cmd1 where userid = pkg_globals.getuserid) tmp
         inner join comanda c on tmp.codobiect = c.codcomanda
         inner join comanda1 c1 on c1.codcomanda = c.codcomanda
         inner join nartobj oc on oc.codobiect = c1.codobiect
         inner join nart ac on ac.codarticol = oc.codarticol
         inner join proiectnod nod0 on nod0.codproiect = c1.codproiect and nvl(nod0.nodoriginal,0)=0
         inner join proiectnod nod on nod.codproiect = c1.codproiect and nvl(nod.codreteta,0)=0
         inner join nartobj om on om.codobiect = nod.codobiect
         inner join nart am on om.codarticol = am.codarticol
         inner join num um on um.codum = am.um
         inner join npart p on p.codpart = c.partener
         left join prodmat mat on mat.codmat = nod.codprodmat
         left join nodechiv ech on ech.codcomanda1 = c1.codcomanda1 and ech.codproiectnod = nod.codproiectnod
         left join nartobj oech on oech.codobiect = ech.codobiect
    group by c.codcomanda,c.tipdoc,nod.codproiectnod,ac.codarticol,p.den_part,ac.den_articol,oc.codintern,c.nrdoc,c.datadoc,c1.termen,om.denumire,um.den_um,
             mat.cant,nod.indexparinte,om.codintern,oech.codobiect,nod.codobiect,oech.denumire,nvl(nod.nivel,0),mat.obs
    ) x &apos;||chr(13);
  if PKG_LIST_STRUCT.TmpExists(&apos;COMANDC&apos;) = 1 then
    sInsert := sInsert||&apos;   left join comandc cext on cext.codcomanda = x.NAV_CodDoc &apos;||chr(13);
  end if;  
  sInsert := sInsert||gSuplJoins;
  
  --delete x;
  --insert into x(test) values(sinsert);
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sinsert := 
  &apos;begin
    for v_rec in (select * from &apos;||TMPNAME||&apos;) loop
      update &apos;||TMPNAME||&apos;
      set total = PKG_LIST_BASE_NECCMDCLI.getsume(codarticol,nav_coddoc,1)
      where nav_coddoc = v_rec.nav_coddoc and nav_tipdoc = v_rec.nav_tipdoc and
            codarticol = v_rec.codarticol and codproiectnod = v_rec.codproiectnod;
      update &apos;||TMPNAME||&apos;
      set total2 = PKG_LIST_BASE_NECCMDCLI.getsume(codarticol,nav_coddoc,2)
      where nav_coddoc = v_rec.nav_coddoc and nav_tipdoc = v_rec.nav_tipdoc and
            codarticol = v_rec.codarticol and codproiectnod = v_rec.codproiectnod;
    end loop;
    commit;
  end;&apos;;
  execute immediate sinsert;  
end;
  
end PKG_LIST_BASE_NECCMDCLI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52B3D78E0050D1F68D32CC444E4493BC95E67270</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NIR IS

  vCodNir NUMBER;
	vTipDoc NUMBER;
  vVerso  BOOLEAN;
  vCodNirStoc NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodNir IN NUMBER, pTipDoc IN NUMBER, pVerso IN NUMBER DEFAULT 1, pCodNirStoc in number default 0) IS
BEGIN
  IF Coalesce(pCodNir,-1) &gt;= 0
  THEN vCodNir := pCodNir;
  END IF;
	vTipDoc := pTipDoc;
	vVerso  := pVerso = 1;
  vCodNirStoc := pCodNirStoc;
END;

FUNCTION GET_SIMBOL(IO_COD NUMBER) RETURN VARCHAR2 IS
  SIMBOL VARCHAR2(10);
BEGIN
  SELECT C.SIMBOL INTO SIMBOL
  FROM TMP_IOART1 T INNER JOIN NCONT C ON C.CODCONT = T.CONT
  WHERE T.CODIOART1=IO_COD;

  RETURN SIMBOL;
END;

PROCEDURE GetSeriiNIR IS
BEGIN
  INSERT INTO tmp_manevra_liste(filtru,valoare) SELECT &apos;CODNIRSTOC&apos;,codnirstoc FROM nirstoc_man;
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(32000);
  sInsertUMA VARCHAR2( 5000);
  sInsertDez VARCHAR2( 1000);
  sSelectUMA VARCHAR2( 9000);
  sSelectDez VARCHAR2( 5000);
  sJoinUMA   VARCHAR2( 5000);
  sJoinDez   VARCHAR2( 5000);
	aTipNir    NUMBER(5);
BEGIN
  gSuplCols :=
    &apos;NIR NIR, NGEST NG, NCONT NC, NLOCATII NL, NUM1 NUM1, NARTOBJ NOBJ, NART NART, NPART NP, NPART PROD, NPART FURN, NCLASEA NCA, NCLASEAS NCLS, NUM UM1, NUM UM2, &apos;||
    &apos;INTRARI1 I1, INTRARI I, NARTCLI AC, COMANDA1 CF1, COMANDA CF, COMANDA1 CCL1, COMANDA CCL, COMANDA1 CINT1, COMANDA CINT, NPART PARTCMDCL&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,       &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,     &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SDOC&apos;,     &apos;SDOC.CODAGENDA = I.CODLOCATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCDOC&apos;,   &apos;LOCDOC.CODLOCALIT = SDOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARADOC&apos;,  &apos;LOCDOC.CODTARA = TARADOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SSOC&apos;,     &apos;SSOC.CODPART = NP.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCSOC&apos;,   &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARASOC&apos;,  &apos;LOCSOC.CODTARA = TARASOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SPROD&apos;,    &apos;SPROD.CODPART = PROD.CODPART AND SPROD.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SPROD.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOCPROD&apos;,  &apos;LOCPROD.CODLOCALIT = SPROD.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,      &apos;TARAPROD&apos;, &apos;LOCPROD.CODTARA = TARAPROD.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;,       &apos;BCAR&apos;,     &apos;BCAR.TIPDOC = NIR.TIPNIR AND BCAR.CODDOC1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTTR&apos;,    &apos;DEL_BCAR&apos;, &apos;BCAR.CODDELEGAT = DEL_BCAR.CODPARTTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;,    &apos;BCAREXT&apos;,  &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CCOST&apos;,      &apos;CCOST&apos;,    &apos;CCOST.CODCENTRU = Coalesce(I1.CODCENTRU,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;OPER&apos;,     &apos;OPER.LOGONNAME = I.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NIRSTOC&apos;,    &apos;NS&apos;,       &apos;NS.CODNIRSTOC = N.CODNIRSTOC&apos;, 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsertDez := &apos;&apos;;
  sSelectDez := &apos;&apos;;
  sJoinDez := &apos;&apos;;
  IF vTipDoc = 7 THEN
    sInsertDez := &apos;,BC_NrDoc,BC_DataDoc,DEZ_INCHIS,BC_NrDocIntr,BC_DataDocIntr&apos;;
    sSelectDez := &apos;,DEZ.BC_NrDoc, DEZ.BC_DataDoc, case when dez.inchisa = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end DEZ_INCHIS, DEZ.BC_NrDocIntr, DEZ.BC_DataDocIntr&apos;;
    sJoinDez := &apos;
    LEFT JOIN (
      SELECT i.nrdoc BC_NrDoc, i.datadoc BC_DataDoc, Coalesce(dz.inchisa,0) inchisa, int.nrdoc BC_NrDocIntr, int.datadoc BC_DataDocIntr, nir.codnir
      FROM nir
        INNER JOIN intrari intr on nir.codintr = intr.codintr
        INNER JOIN dezasamblari1 dz1 on dz1.codintrlink = intr.codintr
        LEFT JOIN dezasamblari dz on dz.codlivr1 = dz1.codlivr1
        LEFT JOIN livr1 l1 on l1.codlivr1 = dz.codlivr1
        LEFT JOIN livr l on l.codlivr = l1.codlivr
        LEFT JOIN iesiri1 i1 on i1.codies1 = l1.codies1
        LEFT JOIN iesiri i on i.codies = l.codies and i.codies = i1.codies
        LEFT JOIN nirstoc1 ns1 on dz.codnirstoc = ns1.codnirstoc
        LEFT JOIN nirstoc nso on nso.codnirstoc = ns1.codnirstocorig
        LEFT JOIN intrari1 int1 on nso.codintr1 = int1.codintr1
        LEFT JOIN intrari int on int.codintr = int1.codintr
      WHERE nir.codnir = &apos;||vCodNir||&apos;
    ) DEZ on DEZ.codnir = nir.codnir &apos;;
  END IF;

  BEGIN
    SELECT tipnir INTO aTipNir FROM nir WHERE CODNIR = vCodNir;
  EXCEPTION when OTHERS THEN
    aTipNir := 0;
  END;

  DELETE FROM tmp_manevra_liste;
  DELETE FROM nirstoc_man;

  if vCodNirStoc &gt; 0 then
    INSERT INTO nirstoc_man SELECT ns.* FROM nirstoc ns WHERE ns.codnirstoc = vCodnirstoc;
    INSERT INTO intrari1_man
    SELECT i1.*
    FROM intrari1 i1
    WHERE i1.codintr1 IN (SELECT codintr1 FROM nirstoc_man);
  else
    IF vVerso
    THEN INSERT INTO nirstoc_man SELECT ns.* FROM nirstoc ns WHERE ns.codnir = vCodnir AND ns.cantfurn &lt;&gt; ns.cantnir;
    ELSE INSERT INTO nirstoc_man SELECT ns.* FROM nirstoc ns WHERE ns.codnir = vCodnir;
    END IF;
    COMMIT;

    DELETE FROM intrari1_man;
    IF aTipNir = 5 THEN
      INSERT INTO intrari1_man
      SELECT i1.*
      FROM intrari1 i1 INNER JOIN dvi1 ON i1.codintr1 = dvi1.codintr1
      WHERE dvi1.coddvi1 IN (SELECT coddvi1 FROM nirstoc_man);
    ELSE
      INSERT INTO intrari1_man
      SELECT i1.*
      FROM intrari1 i1
      WHERE i1.codintr1 IN (SELECT codintr1 FROM nirstoc_man);
    END IF;
  end if;

  COMMIT;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;n.cantnir&apos;,&apos;n.codobiect&apos;,sInsertUMA,sSelectUMA,sJoinUMA);

	sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DOCUMENT,ORD,DENUMIRE,DENARTPART,SIMBOL,DEN_UM1,CANT,CANTNIR,PU,PRET,PROCADAOS,ADAOSUNITAR,VALOARE,PROCTVA,TVA_UNITAR,TVA_TOTAL,ADAOSTOTAL,
		DEN_GEST,LOCATIE,PROD,PRETMAXIMAL,TIPSERIE,SERII,SERNOCANT,SERCANT,SERTG,TG,CERTIF,DATACERTIF,DATAPROD,DIVIZOR,BUCATI,
    CODEXTERN,CODINTERN,DEN_CLASEA,NRCERTIF,PRETFARATVA,VALFARATVA,
    CANTUM1,DENUM1,CANTUM2,DENUM2,ADAOSSTOC,DATAACHIZ,furnizor,AdaosInvers,valachiz,adaosFurn,adaosmaximal,suplunitar,d1,d2,d3,clasas,TVADED,
    NRCMDFURN, DATACMDFURN, NRCMDINT, DATACMDINT, NRCMDCL, DATACMDCL, PARTCMDCL, PROVIZION, SERIELOT, OPERATOR, EUDR_RN, EUDR_VN &apos;||sInsertDez||sInsertUMA||gUserFields||&apos;)
  WITH
  MAN1 AS (
    SELECT
      ns.codnirstoc,
      CASE Coalesce(ns.tipserie,0)
        WHEN 1 THEN vc2_nt_to_vc3200(CAST(collect(s.serie) AS vc2_nt))
        WHEN 2 THEN vc2_nt_to_vc3200_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||nser.cantnir||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
        ELSE NULL
      END serii,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(Coalesce(nser.tg,ns.tg),&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) tg,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.nrcertif)) AS vc2_nt)) nrcertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(c.dataprimire,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) datacertif,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.dataprod)) AS vc2_nt)) dataprod,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.divizor)) AS vc2_nt)) divizor,
      vc2_nt_to_string(CAST(collect(DISTINCT to_char(nser.bucati)) AS vc2_nt)) bucati
    FROM NIRSTOC_MAN NS
      INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
	    INNER JOIN nserii s ON s.codserie = nser.codserie
      LEFT JOIN certif c ON c.codcertif = nser.codcertif
    GROUP BY ns.codnirstoc, ns.tipserie
  ),
  MAN2 AS (
    SELECT
      codnirstoc,
      vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) sernocant,
      vc2_nt_to_vc3200(CAST(COLLECT(to_char(tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) sertg,
      vc2_nt_to_vc3200(CAST(COLLECT(To_Char(cant)) AS vc2_nt)) sercant
    FROM (
      SELECT ns.codnirstoc, s.serie, sum(nser.cantnir) cant, Coalesce(nser.tg, ns.tg) tg
      FROM NIRSTOC_MAN NS
        INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
	      INNER JOIN nserii s ON s.codserie = nser.codserie
        LEFT JOIN certif c ON c.codcertif = nser.codcertif
      WHERE Coalesce(ns.tipserie,0) &gt; 0
      GROUP BY ns.codnirstoc, s.serie, Coalesce(nser.tg, ns.tg)
    )
    GROUP BY codnirstoc
  ),
  N AS (
    SELECT
      NIR.CodNir, Row_Number() OVER (ORDER BY nir.codnir, Coalesce(d1.indexlocal,0), Coalesce(d1.coddvi1,0), Coalesce(i1.indexlocal,0), i1.codintr1, ns.codnirstoc) Ord,
      CASE
        WHEN nir.tipnir BETWEEN 1 AND 9 THEN i.prefixdoc ||&apos;&apos;.&apos;&apos;||i.nrdoc ||&apos;&apos;.&apos;&apos;||i.datadoc
			  ELSE t.prefixdoc ||&apos;&apos;.&apos;&apos;||t.nrdoc||&apos;&apos;.&apos;&apos;||t.datadoc
			END AS document,
      CASE WHEN nir.tipnir BETWEEN 1 AND 5 THEN i.partener ELSE NULL END partener,
			NS.CODNIRSTOC, NS.CANTNIR, NIR.GEST, NS.CODIOART, Coalesce(NS.CODLOCATIE,0) CODLOCATIE, NS.UMSEC, NS.CODOBIECT, NS.TG,
      NS.PRET, NS.ADAOS, NS.CANTFURN,ns.tva tvanir,ns.procentadaos,
      Coalesce(T1.INDEXLOCAL,D1.INDEXLOCAL,I1.INDEXLOCAL) INDEXLOCAL,
      Coalesce(T1.CANT,D1.CANT,I1.CANT) CANT, Coalesce(T1.TVA,D1.TVA,I1.TVA,0) TVA , Coalesce(T1.PU,D1.PRETIMPORT,I1.PU) PU,
      Coalesce(T.AN*12+T.LUNA,I1.AN*12+I1.LUNA,I.AN*12+I.LUNA) AL,
      i1.nrcertif,ns.cantum1,ns.cantum2, Coalesce(i1.dataachizavizsubunit,ns.dataachiz) dataachiz , Coalesce(i1.furnavizsubunit, ns.furn) codfurn, i1.addim,
			ns.pumaximal,CASE Coalesce(ns.cantnir,0) WHEN 0 THEN 0 ELSE ns.supliment/ns.cantnir END suplunitar,
      ns.d1, ns.d2, ns.d3,i1.codintr1,ns.provizion, ns.serielot, ns.eudr_rn, ns.eudr_vn
    FROM NIRSTOC_MAN NS
      INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
      LEFT JOIN DVI1 D1 ON D1.CODDVI1 = NS.CODDVI1
      LEFT JOIN INTRARI1_MAN I1 ON I1.CODINTR1 = Coalesce(D1.CODINTR1,NS.CODINTR1)
      LEFT JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1
      LEFT JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF
  	  LEFT JOIN INTRARI I ON NIR.CODINTR = I.CODINTR
  )
  SELECT
    n.document, n.ord, nobj.denumire, ac.denumire, nc.simbol, num1.den_um1,
		n.cantfurn/num1.paritate cant, n.cantnir/num1.paritate cantnir, (n.pret - n.adaos) * num1.paritate PU, n.pret * num1.paritate pret,
		CASE
      WHEN io1.difpret = 1 THEN
        Round(
          CASE
            WHEN io1.aretvaneex = 0 THEN 100*(n.pret-n.pu)                                       /Coalesce(NULLIF(n.pu            ,0),1)
            WHEN io1.aretvaneex = 1 THEN 100*(n.pret/(1+(ntva1.procent/100))-(n.pret - n.adaos)) /Coalesce(NULLIF(n.pret - n.adaos,0),1)
            WHEN io1.aretvaneex = 2 THEN 100*((n.pret-(n.pret-n.pu)/(1+ntva1.procent/100) )-n.pu)/Coalesce(NULLIF(n.pu            ,0),1)
          END,2)
      ELSE 0
    END procadaos,
    CASE WHEN io1.aretvaneex = 1 THEN  n.adaos -((n.pret*ntva1.procent)/Coalesce(NULLIF(100+ntva1.procent,0),1)) ELSE n.adaos END * num1.paritate adaosunitar,
    n.pret * n.cantnir valoare, ntva1.procent procTVA,
    CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)/(100+ntva1.procent) ELSE 0 END * num1.paritate tva_unitar,
    CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)*n.cantnir/(100+ntva1.procent) ELSE 0 END tva_total,
    CASE WHEN io1.aretvaneex = 1 THEN (n.adaos -((n.pret*ntva1.procent)/(100+ntva1.procent))) * n.cantnir ELSE n.adaos * n.cantnir END adaostotal,
		ng.den_gest, nl.denumire locatie, prod.den_part prod, n.pumaximal * num1.paritate PRETMAXIMAL,
    CASE nart.tipserie WHEN 0 THEN &apos;&apos;fara serie&apos;&apos; WHEN 1 THEN &apos;&apos;serie pe bucata&apos;&apos; WHEN 2 THEN &apos;&apos;serie pe lot&apos;&apos; ELSE &apos;&apos;&apos;&apos; END tipserie,
    MAN1.SERII, MAN2.SERNOCANT, MAN2.SERCANT, MAN2.SERTG, Coalesce(MAN1.TG,to_char(N.TG,&apos;&apos;dd.mm.yyyy&apos;&apos;)), MAN1.NRCERTIF, MAN1.DATACERTIF, MAN1.DATAPROD, MAN1.DIVIZOR, MAN1.BUCATI,
    nobj.codextern,nobj.codintern,nca.den_clasea,n.nrcertif,
    (n.pret - CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)/(100+ntva1.procent) ELSE 0 END) * num1.paritate pretfaratva,
    (n.pret * n.cantnir - CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)*n.cantnir/(100+ntva1.procent) ELSE 0 END) valfaratva,
    n.cantum1 CANTUM1, um1.den_um denum1, n.cantum2 CANTUM2, um2.den_um denum2, n.procentadaos adaosstoc, n.dataachiz, furn.Den_Part,
		((((n.pret - n.adaos)/(Coalesce(NULLIF(n.pret,0),1) - CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)/(100+ntva1.procent) ELSE 0 END )) - 1 ) * 100 )  AdaosInvers,
		((n.pret - n.adaos)) * n.cantnir valachiz,
    CASE WHEN Coalesce(n.pret,0) = 0 THEN 1 ELSE 1-(n.pret - n.adaos)/(n.pret - CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)/(100+ntva1.procent) ELSE 0 END) END*100 AdaosFurn,
		CASE WHEN Coalesce(n.pret,0) = 0 THEN 1 ELSE n.pumaximal /(1+ntva1.procent/100)/(n.pret - CASE WHEN io1.aretvaneex = 1 THEN (n.pret*ntva1.procent)/(100+ntva1.procent) ELSE 0 END)-1 END*100 adaosmaximal,
    n.suplunitar, n.d1, n.d2,n.d3,NCLS.DEN_CLASEAS,N.TVA,
    CF.NRDOC, CF.DATADOC, CINT.NRDOC, CINT.DATADOC, CCL.NRDOC, CCL.DATADOC, PARTCMDCL.DEN_PART,n.provizion, n.serielot, UT.USERNAME, N.eudr_rn, N.eudr_vn &apos;||sSelectDez||sSelectUMA||gUserAlias||&apos;
  FROM N
    INNER JOIN nir            nir       ON n.codnir = nir.codnir
    INNER JOIN ngest          ng        ON ng.codgest = n.gest
    INNER JOIN ioart1         io1       ON io1.codioart = n.codioart          AND n.al BETWEEN io1.ALStart   AND io1.ALStop
    INNER JOIN ncont          nc        ON nc.codcont = io1.cont
    INNER JOIN nlocatii       nl        ON nl.codlocatie = n.codlocatie
    INNER JOIN num1           num1      ON num1.codum1 = n.umsec
    INNER JOIN nartobj        nobj      ON nobj.codobiect = n.codobiect
    INNER JOIN nart           nart      ON nart.codarticol = nobj.codarticol
    INNER JOIN nart1          nart1     ON nart1.codarticol = nobj.codarticol AND n.al BETWEEN nart1.ALStart AND nart1.ALStop
    INNER JOIN ntva1          ntva1     ON ntva1.codtva = nart1.codtva        AND n.al BETWEEN ntva1.ALStart AND ntva1.ALStop
    INNER JOIN nartobj1       nobj1     ON nobj1.codobiect = nobj.codobiect   AND n.al BETWEEN nobj1.ALStart AND nobj1.ALStop
    LEFT  JOIN nclasea        nca       ON nca.codclasea = Coalesce(nart.clasa,0)
    LEFT  JOIN num            um1       ON um1.codum = Coalesce(nart.um1,0)
    LEFT  JOIN num            um2       ON um2.codum = Coalesce(nart.um2,0)
    LEFT  JOIN npart          prod      ON prod.codpart = Coalesce(nobj.codproducator,0)
		LEFT  JOIN npart          furn      ON furn.codpart = Coalesce(n.codfurn,0)
    LEFT  JOIN intrari1       i1        ON i1.codintr1 = n.codintr1
    LEFT  JOIN intrari        i         ON i.codintr = i1.codintr
    LEFT  JOIN tmp_utilizator ut        ON ut.codutilizator = i.userid
    LEFT  JOIN nclaseas       ncls      ON ncls.codclaseas = nart.clasastatist
	  LEFT  JOIN man1           man1      ON man1.codnirstoc = n.codnirstoc
	  LEFT  JOIN man2           man2      ON man2.codnirstoc = n.codnirstoc
    LEFT  JOIN intrprodlink   iprodlink ON iprodlink.codintr1 = n.codintr1
    LEFT  JOIN intrlink       il        ON il.codintr1 = n.codintr1
    LEFT  JOIN comanda1       cf1       ON cf1.codcomanda1 = Coalesce(i1.codcmd1ae,il.codliniecomanda)
    LEFT  JOIN comanda        cf        ON cf.codcomanda = cf1.codcomanda
    LEFT  JOIN cmdprodmat     cmdpm     ON iprodlink.codliniecomanda = cmdpm.codcmdprodmat
    LEFT  JOIN cmdlink        clink     ON clink.codcomanda1 = Coalesce(i1.codcmd1ae,cmdpm.codcomanda1)
    LEFT  JOIN comanda1       ccl1      ON ccl1.codcomanda1 = clink.codliniecomanda
    LEFT  JOIN comanda        ccl       ON ccl1.codcomanda = ccl.codcomanda
    LEFT  JOIN comanda1       cint1     ON cint1.codcomanda1 = cmdpm.codcomanda1
    LEFT  JOIN comanda        cint      ON cint.codcomanda = cint1.codcomanda
    LEFT  JOIN npart          partcmdcl ON partcmdcl.codpart = ccl.partener
    LEFT  JOIN npart          np        ON np.codpart = n.partener
    LEFT  JOIN nartcli        ac        ON ac.codobiect = n.codobiect AND ac.codpart = n.partener &apos;||
    sJoinDez||
    sJoinUMA||
    gSuplJoins||&apos;
  ORDER BY n.indexlocal &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_NIR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NIRIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E871CB6B3CE6D93486797337A24C18FF6AB1BBA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_niries IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(3000);
BEGIN

  gSuplCols := &apos;nirstoc ns, nartobj nao, num1 num1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(ART, UM, CANTDOC, CANTNIR, PACH, PINREG ,PVANZ, VALACH, VALINREG, VALVANZ &apos;||gUserFields||&apos;)
  SELECT nao.denumire, num1.den_um1, i1.cant , l1.cant, ns.pret - ns.adaos, ns.pret, i1.pu, (ns.pret - ns.adaos) * l1.cant, ns.pret * l1.cant, i1.pu * l1.cant &apos;||gUserAlias||&apos;
  FROM TMP_LIVR1 l1
    INNER JOIN tmp_iesiri1 i1 ON i1.codies1 = l1.codies1
    INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
    INNER JOIN nartobj nao ON nao.codobiect = i1.codobiect
    INNER JOIN num1 ON num1.codum1 = i1.umsec &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

procedure setJoinuri is
begin
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
end;

end PKG_LIST_BASE_NIRIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NIRSERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>474BB7C006EA8E8D83AF8A5695FAA87DB909422C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NIRSERII IS

  vCodNirStoc NIRSTOC.CODNIRSTOC%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodNirStoc IN NUMBER) IS
BEGIN
  vCodNirStoc := pCodNirStoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN

  gSuplCols := &apos;NIRSTOC NS, NARTOBJ O, NUM1 UM, NIRSER NSER, NSERII SER&apos; ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

	sINSERT :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ARTICOL, CODINTERN, CODEXTERN, SERIE, UM,
    CANT, BUCATI, DIVIZOR, LOCATIE &apos;||gUserFields||&apos;)
  SELECT
    O.DENUMIRE, O.CODINTERN, O.CODEXTERN, SER.SERIE, UM.DEN_UM1,
    NSER.CANTNIR/UM.PARITATE, NSER.BUCATI, NSER.DIVIZOR, LOC.DENUMIRE &apos;||gUserAlias||&apos;
  FROM NIRSTOC NS
    INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
    INNER JOIN NUM1 UM ON UM.CODUM1 = NS.UMSEC
    INNER JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
    LEFT  JOIN NLOCATII LOC ON NS.CODLOCATIE = LOC.CODLOCATIE&apos;||
    gSuplJoins||&apos;
  WHERE NS.CODNIRSTOC = &apos;||vCodNirStoc;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END pkg_list_base_nirserii;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NMVSHISTORY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EF0C22826183C9E762C33A51015B528AB5ECA3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NMVSHISTORY is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sCondSupl varchar2(1000);
  sKey      varchar2(10);
  sJoinObj  varchar2(500);
BEGIN
  gSuplCols := &apos;NMVS N, TMP_UTILIZATOR U, NSUBUNIT S, NARTOBJ O&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sKey := pkg_categconst.GetValConstanta(&apos;NMVSKey&apos;,pkg_globals.GETANLUCRU, pkg_globals.GETlunalucru);
  if sKey = &apos;1&apos; then
    sJoinObj := chr(13)||&apos; LEFT JOIN NARTOBJ O ON UPPER(O.CODEXTERN) = UPPER(N.GTIN) &apos;||chr(13);
  else
    sJoinObj := chr(13)||&apos; LEFT JOIN NARTOBJ O ON UPPER(O.CODINTERN) = UPPER(N.GTIN) &apos;||chr(13);
  end if;  

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
   USERX,
   SUBUNITATEA,
   DATAVERIF,
   GTIN,
   DATAEXP,
   LOT,
   SN,
   SKEMETYPE,
   MESAJ,
   CODMESAJ,
   STATUS,
   MOTIV,
   CODFUNCTIE,
   GLN &apos;||gUserFields||&apos;)
  SELECT
   U.USERNAME,
   S.DEN_SUBUNIT,
   N.DATAVERIF,
   N.GTIN,
   N.DATAEXP,
   N.LOT,
   N.SN,
   N.SKEMETYPE,
   N.MESAJ,
   N.CODMESAJ,
   N.STATUS,
   N.MOTIV,
   N.CODFUNCTIE,
   N.GLN &apos;||gUserAlias||&apos;
  FROM NMVS N
       LEFT JOIN TMP_UTILIZATOR U ON U.CODUTILIZATOR = N.USERID
       LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = N.SUBUNITATEA &apos;||sJoinObj||gSuplJoins||&apos;
  WHERE trunc(N.DATAVERIF) BETWEEN pkg_list_selectper.DATAINI and pkg_list_selectper.DATAFIN&apos;;

  --delete x;
  --insert into x(test) values(sinsert);
  --commit;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NMVSHISTORY;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOMARTAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>089EDAAEC6B7155BB3D9DABE4C56C1E4FFABF95C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOMARTAMB IS

  vToateArt       BOOLEAN ;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pToateArt IN NUMBER DEFAULT 1)
IS
BEGIN
  vToateArt := pToateArt = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NARTOBJ OBJ, NARTOBJ OBJR, NART ART, NCLASEA CA, NUM UMPRINC, NUM1 UM1PRINC, NUM1 UMAMB, NARTAMB AMB&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTR&apos;,&apos;OEXTR.CODOBIECT = OBJR.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRR&apos;,&apos;OATRR.CODOBIECT = OBJR.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(DenArt, DenAmbRet, CodExtern, DenUMP, DenUMAmb, TipArticol&apos;||gUserFields||&apos; )
  SELECT OBJ.denumire, OBJR.denumire, OBJ.CodExtern, UMPrinc.Den_UM, UMAmb.Den_UM1, Decode(ART.tiparticol, 0 ,&apos;&apos;Stoc&apos;&apos;, &apos;&apos;Serviciu&apos;&apos;) TipArticol&apos;||gUserAlias||&apos;
  FROM NARTOBJ OBJ
    INNER JOIN NART ART ON ART.codarticol = OBJ.codarticol
    LEFT JOIN NCLASEA CA ON CA.codclasea = ART.clasa
    LEFT JOIN NARTAMB AMB ON AMB.codobiect = OBJ.CodObiect
    LEFT JOIN NARTOBJ OBJR ON OBJR.CODOBIECT = AMB.CODOBIECTRETURN
    LEFT JOIN NUM  UMPrinc ON UMPrinc.codum = ART.UM
    LEFT JOIN NUM1 UM1Princ ON UM1Princ.codum = ART.UM AND UM1Princ.secundara = 0
    LEFT JOIN NUM1 UMAmb ON UMAmb.codum1 = AMB.umsec&apos;||
    gSuplJoins||&apos;
  WHERE 1 = 1 &apos;;

  IF not vToateArt THEN
    sInsert := sInsert|| &apos;
    AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = OBJ.CODOBIECT )&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_NOMARTAMB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOMGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>095289D4D53FCF279FFE9A7B70FEF395372848DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nomgest IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols :=&apos;ngest g,nlocatii loc,nagenda a,nlocalit l,njudet j,nactivit act,npers p,ioart i,ncont c,ncatpret cp,DOCUMENTE DD&apos; ;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_CAMERE_LST&apos;, &apos;TCL&apos;, &apos;TCL.CODGEST = G.CODGEST&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Den, Locatie,SimbGest , Loc, Jud, Clasa, Activit, Gest, Custodie, TipCont, SimbCont, CatPret,
    sector, strada, nr1, nr2, bloc, scara, etaj, apart, telefon&apos;||gUserFields||&apos;
  )
  SELECT
    g.den_gest, loc.denumire locatie ,g.simbol, l.den_localit, j.den_judet, cg.den_claseg , act.den_activit,
    p.nume ||&apos;&apos; &apos;&apos;||p.prenume as Gestionar, DECODE(g.custodie,0,&apos;&apos;NU&apos;&apos;,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;--&apos;&apos;),
    i.den_ioart, c.simbol, cp.den_catpret,
    a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart ,a.telefon &apos;||gUserAlias||&apos;
  FROM ngest g
    LEFT JOIN DOCUMENTE DD  ON g.codgest      = DD.codDOC AND DD.TIPDOC = 506
    LEFT JOIN nlocatii  loc ON g.codgest      = loc.codgest
    LEFT JOIN nagenda   a   ON a.codgest      = g.codgest
    LEFT JOIN nlocalit  l   ON l.codlocalit   = a.codlocalit
    LEFT JOIN njudet    j   ON j.codjudet     = l.codjudet
    LEFT JOIN nactivit  act ON act.codactivit = g.codactivit
    LEFT JOIN nclaseg   cg  ON cg.codclaseg   = g.codclasa
    LEFT JOIN npers     p   ON p.codpers      = g.codgestionar
    LEFT JOIN ioart     i   ON i.codioart     = g.codcont
    LEFT JOIN ioart1    i1  ON i1.codioart    = g.codcont AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN i1.ALStart and i1.ALStop
    LEFT JOIN ncont     c   ON c.codcont      = i1.cont
    LEFT JOIN ncatpret  cp  ON cp.codcatpret  = g.codcatpret &apos;||
    gSuplJoins||&apos;
  WHERE g.codgest &lt;&gt; 0&apos;;

  IF InStr(gSuplJoins,&apos;TMP_CAMERE_LST&apos;) &gt; 0 THEN 
    PKG_LIST_BASE_UTILS.UMPLE_TMP_CAMERE_LST;
  END IF;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
Pkg_List_Struct.SetTableSpec(gSuplCols);
pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NOMGEST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOMOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA2310B1D8C5BDB8831D3849168CE95410261AA2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nomoper IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 ) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NOPER OP, NCLASEOP CLOP&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=&apos;INSERT INTO &apos;||tmpName||&apos;(CODEXTERN,
                                      DENUMIRE,
                                      CLASAOP,
                                      ACTIV&apos;||gUserFields||&apos;) 
  SELECT
      OP.CODEXTERN,
      OP.DENUMIRE,
      CLOP.DEN_CLASEOP,
      case when OP.ACTIV = 1 then &apos;&apos;DA&apos;&apos;
            else &apos;&apos;NU&apos;&apos;
      end &apos;||gUserAlias||&apos;
  FROM NOPER OP
    LEFT JOIN NCLASEOP CLOP ON OP.CLASAOP = CLOP.CODCLASEOP &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_nomoper;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOMPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42C5FAA4EBDE7BACEED171494359BCF2A26BB886</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOMPART IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vAllPart    BOOLEAN;

procedure setparams(aAllPart in number) is
begin
  vAllPart := aAllPart = 1;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 ) IS
  sInsert   VARCHAR2(30000);
  AnC       NUMBER(4);
  LunaC     NUMBER(2);
  AnT       NUMBER(4);
  LunaT     NUMBER(2);
  AnP       NUMBER(4);
  LunaP     NUMBER(2);
  sSoldPart VARCHAR2(500);
  sCondPart VARCHAR2(1000);
BEGIN
  gSuplCols :=
    &apos;NPART N, NPART1 N1, NPARTCODFISC FISC, NAGENDA NAG, NLOCALIT LOC, NJUDET JUD, NTARI TARA, NPARTB PARTB, NBANK NBANK, NLOCALIT LOCBANK, NCATPRET NPRET, NCLASEP NCL, IOPART IO, NPERS AGENT, NTIPSEDII TS&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = N.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_STRUCT.SPLIT_COLUMN(&apos;NCLASEP&apos;,&apos;SIMBOL&apos;,&apos;.&apos;,&apos;TMP_LEVEL1&apos;)	;

  AnT   := pkg_globals.GetANLUCRU;
  LunaT := pkg_globals.GetLUNALUCRU;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AnT, LunaT, AnP, LunaP);
  PKG_GLOBALS.SetLunaPRECEDENTA(AnP, LunaP);
  PKG_GLOBALS.SetLunaTEMP(AnT, LunaT);

  SELECT AnCurent, LunaCurenta INTO AnC, LunaC FROM FirmaLuni;

  IF AnC*12+LunaC &gt; AnT*12+LunaT THEN
    sSoldPart := &apos;npartsoldluna
    WHERE AN = pkg_globals.GetAnLUCRU AND LUNA = pkg_globals.GetLunaLUCRU&apos;;
  ELSE
    PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
    sSoldPart := &apos;v_soldpart_ext&apos;;
  END IF;

  sCondPart := &apos;&apos;;
  if not vAllPart then
    sCondPart := &apos; and exists (select valoare from tmp_manevra_liste where valoare = N.CodPart and filtru = &apos;&apos;CODPART&apos;&apos;) &apos;;
  end if;

	sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    DENUMIRE,CODFISCAL,REGCOM,LOCALITATE,JUDET,
    ADRESA,
    TELEFON,EMAIL,CREDITF,CREDITC,
    SIMBOLBANCA,CONTBANCA,DISCOUNT,PERSFIZICA,
    CATEGPRET,CLASAPART,VOLUMTRANZC,VOLUMTRANZF,
    TIPCONT,SOLDREAL,SCADENTAC,SCADENTAV,DISTANTA,
    CUIVALID, POPRIREANAF, TVALAINC,InstP,
    NIVEL_1,NIVEL_2,NIVEL_3,NIVEL_4,NIVEL_5,NIVEL_6,NIVEL_7,NIVEL_8
    ,X_CodClasaP,x_Judet &apos;||gUserFields||&apos;)
  WITH NPS AS (
    SELECT codpart, SUM(soldlei) soldlei
    FROM &apos;||sSoldPart||&apos;
    GROUP BY codpart),
  VT AS (
    SELECT CODPART, SUM(VOLTRANZC) VOLTRANZC, SUM(VOLTRANZF) VOLTRANZF
    FROM (
      SELECT P1.CODPART, (Coalesce(VOLUMTRANZC, 0)) VOLTRANZC, (Coalesce(VOLUMTRANZF, 0)) VOLTRANZF
      FROM FIRMALUNI FL INNER JOIN NPART1 P1 ON P1.ANSTART = FL.ANINITIAL AND P1.LUNASTART = FL.LUNAINITIALA
      WHERE P1.CODPART &lt;&gt; 0
      UNION ALL
      SELECT O.CODPART, (Coalesce(VALTRANZC,0)) VOLTRANZC, (Coalesce(VALTRANZF,0)) VOLTRANZF
      FROM OBLIGPIF O INNER JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
      WHERE O.CODPART &lt;&gt; 0
      UNION ALL
      SELECT CODPART, (CASE WHEN SEMNIFICATIE = 410 THEN Coalesce(REST,0) ELSE 0 END) VOLTRANZC, (CASE WHEN SEMNIFICATIE = 310 THEN Coalesce(REST,0) ELSE 0 END) VOLTRANZF
      FROM OBLIGPIF
      WHERE SEMNIFICATIE IN (310, 410) AND CODPART &lt;&gt; 0
      UNION ALL
      SELECT CODPART, (Coalesce(VALOARE,0)) VOLTRANZC, 0 VOLTRANZF
      FROM EMULARE
      WHERE CODPART &lt;&gt; 0
    )
    GROUP BY CODPART
  )
  SELECT
    N.DEN_PART, NVL(FISC.CODFISCAL,&apos;&apos;nedef.&apos;&apos;) ,NVL(N.REGCOM,&apos;&apos;nedef.&apos;&apos;), NVL(LOC.DEN_LOCALIT,&apos;&apos;nedef.&apos;&apos;),NVL(JUD.DEN_JUDET,&apos;&apos;nedef.&apos;&apos;),
    NVL(GETADRESA(NAG.SECTOR,NAG.STRADA,NAG.NR1,NAG.NR2,NAG.BLOC,NAG.SCARA,NAG.ETAJ,NAG.APART,NAG.CODPOSTAL),&apos;&apos;nedef.&apos;&apos;),
    NAG.TELEFON,NAG.EMAIL, NVL(N1.CREDITFURN,0), NVL(N1.CREDITCLIENT,0),
    NVL(NBANK.SIMBOL,&apos;&apos;nedef.&apos;&apos;), NVL(partb.contbanca,&apos;&apos;nedef.&apos;&apos;),NVL(N.DISCOUNT,0), TO_CHAR(N.TIPPART),
    NVL(NPRET.DEN_CATPRET,&apos;&apos;nedef.&apos;&apos;), NVL(NCL.DEN_CLASEP,&apos;&apos;nedef.&apos;&apos;), NVL(VT.VOLTRANZC,0), NVL(VT.VOLTRANZF,0),
    NVL(IO.DEN_IOPART,&apos;&apos;nedef.&apos;&apos;),NVL(NPS.SOLDLEI,0), NVL(N.SCADENTAC,0), NVL(N.SCADENTAV,0), NVL(NAG.KM,0),
    DECODE(cif_valid(FISC.CodFiscal),1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) CUIValid, DECODE(n.poprire_anaf,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) POPRIREANAF, DECODE(n.tvalaincasare,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) TVALAINC,
    case when bitand(n.tippartener,64) = 64 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    LVL1.NIVEL_1,LVL1.NIVEL_2,LVL1.NIVEL_3,LVL1.NIVEL_4,LVL1.NIVEL_5,LVL1.NIVEL_6,LVL1.NIVEL_7,LVL1.NIVEL_8
    , N.CODCLASA, coalesce(JUD.SIMBAUTO,&apos;&apos;XX&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM NPART N
    LEFT JOIN NPART1 N1 ON N.CODPART = N1.CODPART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP 
    LEFT JOIN NPARTCODFISC FISC ON N.CODPART =  FISC.CODPART AND FISC.PRINCIPAL = 1
    LEFT JOIN NAGENDA NAG ON N.CODPART = NAG.CODPART AND NAG.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(NAG.INACTIV, 0) = 0
    LEFT JOIN NTIPSEDII TS ON TS.CODTIPSEDIU = NAG.CODTIPSEDIU
    LEFT JOIN NPERS AGENT ON NAG.CODAGENT = AGENT.CODPERS
    LEFT JOIN NLOCALIT LOC ON NAG.CODLOCALIT = LOC.CODLOCALIT
    LEFT JOIN NJUDET JUD ON JUD.CODJUDET = LOC.CODJUDET
    LEFT JOIN NTARI TARA ON TARA.CODTARA = LOC.CODTARA
    LEFT JOIN NPARTB PARTB ON N.CODPART = PARTB.CODPART AND PARTB.IMPLICIT = 1
    LEFT JOIN NBANK ON PARTB.CODBANK = NBANK.CODBANK
    LEFT JOIN NLOCALIT LOCBANK ON LOCBANK.CODLOCALIT = PARTB.CODLOCALIT
    LEFT JOIN NCATPRET NPRET ON N.CODCATEGPRET = NPRET.CODCATPRET
    LEFT JOIN NCLASEP NCL ON N.CODCLASA = NCL.CODCLASEP
    LEFT JOIN IOPART IO ON N1.CODIOPART = IO.CODIOPART
    LEFT JOIN TMP_LEVEL1 LVL1 ON LVL1.SIMBOL = NCL.SIMBOL
    LEFT JOIN NPS ON N.CODPART = NPS.CODPART
    LEFT JOIN VT ON VT.CODPART = N.CODPART&apos;||
    gSuplJoins||&apos;
  WHERE N.CODPART &gt; 0 &apos;||
    sCondPart;

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NPART1_LST;
  PRC_AL_CHECK(&apos;NPART1&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_NOMPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOMPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE33A7BB6CFBDFA571B33FA2C564582C799B7789</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_nompers IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDetaliere  number(1);
  vAllPers    number(1);
  vAllTeme    number(1);
  vAllCursuri number(1);
  vPerDataPlanif number(1);
  vDataIni varchar2(10);
  vDataFin varchar2(10);
  vGDPR number(1);

PROCEDURE SETPARAMS(
  aDetaliere in number, 
  aAllPers in number, 
  aAllTeme in number, 
  aAllCursuri in number, 
  aPerDataPlanif in number, 
  aDataIni in varchar2, 
  aDataFin in varchar2, 
  pCodJob1 in number,
  aGDPR in number default 1
) is
AnLunaIni   number(10) := 0;
AnLunafin   number(10) := 0;  
begin
  vDetaliere := aDetaliere;
  vAllPers := aAllPers;
  vAllTeme := aAllTeme;
  vAllCursuri := aAllCursuri;
  vPerDataPlanif := aPerDataPlanif;
  vDataIni := aDataIni;
  vDataFin := aDataFin;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,AnLunaIni,AnLunaFin);
  END IF;
  vGDPR := aGDPR;
end;

function isDetaliere return number is
begin
  return vDetaliere;
end;

function isAllPers return number is
begin
  return vAllPers;
end;

function isAllTeme return number is
begin
  return vAllTeme;
end;

function isAllCursuri return number is
begin
  return vAllCursuri;
end;

function isPerDataPlanif return number is
begin
  return vPerDataPlanif;
end;

function DataIni return varchar2 is
begin
  return vDataIni;
end;

function DataFin return varchar2 is
begin
  return vDataFin;
end;

PROCEDURE PROCESSLIST( tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0 ) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;&apos;;
  if vGDPR &gt; 0 then
    gSuplCols := &apos;NPERS P, NPERS1 P1, NAGENDA NAG, NLOCALIT LOC, NJUDET JUD, NTARI T, NLOCALIT LOCAG, NSUBUNIT SUB, NGEST G&apos;;
    if vDetaliere = 1 then
      gSuplCols := gSuplCols||&apos;,NPERSCURS CV,CURSURI CS,TEME TM&apos;;
    end if;
  end if;  

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NPERS1&apos;);

  delete tmp_nperscurs;
  delete tmp_nperscurs0;
  if vDetaliere = 1 then
    --PKG_TEME.TEME_GETPERS
    INSERT INTO TMP_NPERSCURS0
		( CODPERS ,
			NUME    ,
			PRENUME ,
			FORMATIE,
			FUNCTIE ,
			MESERIE ,
			SCHIMB  ,
			DataPlecarii,
			Plecat,
			ACTIV, selectat
		)
    select
		  CODPERS ,
			NUME    ,
			PRENUME ,
			FORMATIE,
			FUNCTIE ,
			MESERIE ,
			SCHIMB  ,
			DataPlecarii,
      case when LuniRamase &lt;0 then 1 else 0 end,
			ACTIV, 1
    FROM
		(Select
       P.CodPers, P.Nume, P.Prenume, C.Den_Formatie formatie, F.DENUMIRE functie, M.DEN_MESERIE meserie, P1.Schimb, p.DataPlecarii,
       Extract (YEAR from NVL(DataPlecarii, Sysdate)) *12 + Extract (MONTH from NVL(DataPlecarii, sysdate)) - PKG_GLOBALS.AnLunaLucru LuniRamase, nvl(p.ACTIV,1) Activ
		 from NPers P
		      inner join NPERS1  P1 on P1.CodPers    = P.CodPers AND (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop
		      left  join Formatii C on C.CodFormatie = P1.CodFormatie
		      left  join Functii  F on F.CodFunctie  = P1.CodFunctie
		      left  join NMESERII M on M.CodMeserie  = P1.CodMeserie
		where ((nvl(p.ACTIV,1) = 1) or  (p.ACTIV=0 and Extract (YEAR from DataPlecarii) *12 + Extract (MONTH from DataPlecarii)  &gt;= PKG_GLOBALS.AnLunaLucru ))
          and (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPERS&apos; AND valoare = P.CODPERS) OR
          PKG_LIST_BASE_NOMPERS.isAllPers = 1)
    )
	  where LuniRamase &gt;=-1;

    -- PKG_TEME.TEME_GOTORECORD
    INSERT INTO TMP_NPERSCURS
    ( CODNPERSCURS,
      CODPERS     ,
      CODFUNCTIE  ,
      CODCURS     ,
      CODTEMA     ,
      STARE       ,
      DATA        ,
      NOTA        ,
      DATAPLAN    ,
      ORE_REALIZ  ,
      SUPLIM      ,
      DEN_CURS    ,
      DEN_TEMA    ,
      SSTARE      ,
      ORE_AFER    ,
      Nume        ,
      Prenume     ,
      Activ, DataPlecarii, Plecat, TipFormare, NivelFormare, CodObiectiv, Den_Obiectiv,
      Sel
      )
    with CF as
          (
            Select distinct P1.CodPers, F1.CodCurs, F1.CodTema, x.Activ, x.DataPlecarii, x.Plecat, 0 Suplim
            from NPERS1 P1
                inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie
                inner join ( select CodPers, Activ, DataPlecarii, Plecat
                             from TMP_NPERSCURS0
                           ) X on X.CodPers = P1.CodPers),
         PC as
          (Select NP.CodPers, NP.CODNPERSCURS, Nvl(NP.codfunctie,0) codfunctie,  NP.CodCurs, NP.CodTema,
                  Nvl(NP.STARE,0) Stare, Case when Nvl(NP.codfunctie,0) = 0 then 1 else 0 end Suplim ,
                  NP.Nota,
                  NP.Data,
                  NP.DataPlan, NP.TipFormare, NP.NivelFormare, NP.CodObiectiv,
									NP.ORE_REALIZ, x.Activ, x.DataPlecarii, x.Plecat
           from NPERSCURS NP
								inner join ( select CodPers, Activ, DataPlecarii, Plecat
								             from TMP_NPERSCURS0
														 where Selectat = 1) X on X.CodPers = NP.CodPers)
    Select TMP.CODNPERSCURS, TMP.CODPERS, TMP.CodFunctie, TMP.CODCURS, TMP.CODTEMA, TMP.STARE, TMP.DATA, TMP.NOTA, TMP.DATAPLAN, TMP.ORE_REALIZ, TMP.Suplim,
           CC.DEN_CURS, TT.DEN_TEMA,
           &apos;xxxxxxxxxx&apos;, TT.ORE, P.Nume, P.Prenume, TMP.Activ, TMP.DataPlecarii, TMP.Plecat, TMP.TipFormare, TMP.NivelFormare, TMP.CodObiectiv, O.Den_Obiectiv, 0 sel
    from
    (
    Select PC.CODNPERSCURS,
		       PC.CodPers,
    			 Nvl(PC.CodFunctie, 0) CodFunctie,
					 PC.CodCurs,
					 PC.CodTema,
					 PC.DATA,
					 PC.DATAPLAN,
					 PC.ORE_REALIZ,
					 nvl(PC.STARE,0) STARE,
					 PC.Nota,
					 PC.Activ, PC.DataPlecarii, PC.Plecat, PC.Suplim, Nvl(PC.TipFormare,0) TipFormare, Nvl(PC.NivelFormare,0) NivelFormare, Nvl(PC.CodObiectiv,0) CodObiectiv
    from PC
    union all
		Select  -RowNum CODNPERSCURS,
		        CF.CODPERS,
						-1 CodFunctie,
						Nvl(CF.CodCurs, 0) CodCurs,
						Nvl(CF.CodTema, 0) CodTema,
						null Data,
						null DATAPLAN,
						0 ORE_REALIZ,
						0 STARE,
						null Nota,
						CF.Activ, CF.DataPlecarii, CF.Plecat, 0 Suplim, 0 TipFormare, 0 NivelFormare, 0 CodObiectiv
    from CF
    where not Exists ( select CodNPERSCURS
		                   from NPERSCURS
											 where Nvl(CodFunctie,0) &lt;&gt; 0 and
											       CodCurs = CF.CodCurs and
														 CodTema = CF.CodTema and
														 Codpers = CF.CodPers)
		) TMP
    inner join Npers     P  on P.Codpers  = TMP.CodPers
    left  join CURSURI   CC on CC.CodCurs = TMP.CodCurs
    left  join TEME      TT on TT.CodTema = TMP.CodTEMA
    left  join OBIECTIVE O  on O.CodObiectiv = TMP.CodObiectiv
    where (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPERS&apos; AND valoare = P.CODPERS) OR
           PKG_LIST_BASE_NOMPERS.isAllPers = 1);

    if vAllCursuri + vAllTeme = 2 then
      sInsert:=&apos;INSERT INTO &apos;||tmpName||&apos;(
        MARCA, NUME, PRENUME, CNP, BISERIA, BINR, LOCNASTERE, ADRESA, PRENUMET, PRENUMEM, DATAN,
        SCIVILA,
        STRAINATATE,
        AGENT,
        DELEGAT,
        A_LOCALITATE,
        A_ADRESA, A_TELEFON, A_EMAIL,
        BIELIBERATDE, LADATADE, TARAN,
        CETATENIE,
        Den_IOPers,
        Formatie,
        Functie,
        Den_meserie,
        Schimb,
        Den_curs,
        Den_tema,
        Stare,
        Nota,
        DEN_OBIECTIV,
        STIPFORMARE,
        SNIVELFORMARE, AnPlanif, LunaPlanif, An, Luna &apos;||gUserFields||&apos;)
      SELECT
        P.MARCA, P.NUME, P.PRENUME, P.CNP, P.BISERIA, P.BINR, LOC.DEN_LOCALIT, P.ADRESA, P.PRENUMET, P.PRENUMEM, PKG_NOMPERS.GETDATAN(P.CNP),
        Decode(P.SCIVILA,-1,&apos;&apos;CASATORIT&apos;&apos;,&apos;&apos;NECASATORIT&apos;&apos;) SCivila,
        CASE WHEN P.STRAINATATE = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        CASE WHEN P.AGENT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        CASE WHEN P.DELEGAT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        LOCAG.DEN_LOCALIT, GETADRESA(NAG.SECTOR,NAG.STRADA,NAG.NR1,NAG.NR2,NAG.BLOC,NAG.SCARA,NAG.ETAJ,NAG.APART,NAG.CODPOSTAL) Adresa, NAG.TELEFON, NAG.EMAIL,
        P.BIELIBERATDE, P.LADATADE, T.DEN_TARA,
        DECODE(P.CETATENIE,0,&apos;&apos;Stat Extra Comunitar (non UE)&apos;&apos;,1,&apos;&apos;Stat Comunitar (UE)&apos;&apos;,-1,&apos;&apos;Romana&apos;&apos;) Cetatenie,
        IO.Den_IOPers, F.DEN_FORMATIE, FT.DENUMIRE, M.DEN_MESERIE, P1.SCHIMB, CS.DEN_CURS, TM.DEN_TEMA,
        CASE WHEN NVL(CV.STARE,0) = 0 THEN &apos;&apos;?&apos;&apos;
             WHEN NVL(CV.STARE,0) = 1 THEN &apos;&apos;Planificat&apos;&apos;
             WHEN NVL(CV.STARE,0) = 2 THEN &apos;&apos;Suspendat&apos;&apos;
             WHEN NVL(CV.STARE,0) = 9 THEN &apos;&apos;Efectuat&apos;&apos;
        END,
        CV.NOTA,
        OBIECTIVE.DEN_OBIECTIV,
        CASE CV.TIPFORMARE
          WHEN 1 THEN &apos;&apos;Ex-cunostintele exista&apos;&apos;
          WHEN 2 THEN &apos;&apos;Ie-instruit extern&apos;&apos;
          WHEN 3 THEN &apos;&apos;Ii-instruit intern&apos;&apos;
          WHEN 4 THEN &apos;&apos;Si-studiu individual&apos;&apos;
        END,
        CASE CV.NIVELFORMARE
          WHEN 0 THEN &apos;&apos;Ou-bligatoriu si urgent&apos;&apos;
          WHEN 1 THEN &apos;&apos;O-obligatoriu&apos;&apos;
          WHEN 2 THEN &apos;&apos;U-Util&apos;&apos;
        END,
        extract(year from CV.DataPlan),
        extract(month from CV.DataPlan),
        extract(year from CV.Data),
        extract(month from CV.Data)&apos;||gUserAlias||&apos;
      FROM NPERS P
        LEFT JOIN (SELECT CVV.*
                    FROM TMP_NPERSCURS CVV
                    WHERE (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODTEMA&apos;&apos; AND valoare = CVV.CODTEMA) OR
                           PKG_LIST_BASE_NOMPERS.isAllTeme = 1) and
                          (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODCURS&apos;&apos; AND valoare = CVV.CODCURS) OR
                           PKG_LIST_BASE_NOMPERS.isAllCursuri = 1) ) CV ON CV.CODPERS = P.CODPERS
        LEFT JOIN NPERS1    P1    ON P.CODPERS             = P1.CODPERS AND (pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop
        LEFT JOIN NAGENDA   NAG   ON NAG.CODAGENDA         = P.AGENDA
        LEFT JOIN NLOCALIT  LOC   ON P.LOCNASTERE          = LOC.CODLOCALIT
        LEFT JOIN NJUDET    JUD   ON LOC.CODJUDET          = JUD.CODJUDET
        LEFT JOIN NTARI     T     ON P.TARAN               = T.CODTARA
        LEFT JOIN NLOCALIT  LOCAG ON NAG.CODLOCALIT        = LOCAG.CODLOCALIT
        LEFT JOIN IOPERS    IO    ON P1.CODIOPERS          = IO.CODIOPERS
        LEFT JOIN FORMATII  F     ON P1.CODFORMATIE        = F.CODFORMATIE
        LEFT JOIN FUNCTII   FT    ON P1.CODFUNCTIE         = FT.CODFUNCTIE
        LEFT JOIN NMESERII  M     ON P1.CODMESERIE         = M.CODMESERIE
        LEFT JOIN OBIECTIVE       ON OBIECTIVE.CODOBIECTIV = CV.CODOBIECTIV
        LEFT JOIN CURSURI   CS    ON CS.CODCURS            = CV.CODCURS
        LEFT JOIN TEME      TM    ON TM.CODTEMA            = CV.CODTEMA
        LEFT JOIN NSUBUNIT  SUB   ON SUB.CODSUBUNIT        = P.CODSUBUNIT
        LEFT JOIN NGEST     G     ON P.CODGEST             = G.CODGEST
        LEFT JOIN (
          SELECT sold.CODPERS , SUM(sold.soldlei) soldlei
          FROM nperssoldluna sold
          WHERE sold.luna = pkg_globals.GetLUNALUCRU AND sold.an = pkg_globals.GetANLUCRU
          GROUP BY sold.codpers
        ) NPS ON P.CODPERS = NPS.CODPERS&apos;||
        gSuplJoins||&apos;
      WHERE P.CODPERS &gt; 0
        AND (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODPERS&apos;&apos; AND valoare = P.CODPERS) OR
             PKG_LIST_BASE_NOMPERS.isAllPers = 1) &apos;;
    else
      sInsert:=&apos;INSERT INTO &apos;||tmpName||&apos;(
        MARCA, NUME, PRENUME, CNP, BISERIA, BINR, LOCNASTERE, ADRESA, PRENUMET, PRENUMEM, DATAN,
        SCIVILA,
        STRAINATATE,
        AGENT,
        DELEGAT,
        A_LOCALITATE,
        A_ADRESA, A_TELEFON, A_EMAIL,
        BIELIBERATDE, LADATADE, TARAN,
        CETATENIE,
        Den_IOPers,
        Formatie,
        Functie,
        Den_meserie,
        Schimb,
        Den_curs,
        Den_tema,
        Stare,
        Nota,
        DEN_OBIECTIV,
        STIPFORMARE,
        SNIVELFORMARE, AnPlanif, LunaPlanif, An, Luna &apos;||gUserFields||&apos;)
      SELECT
        P.MARCA, P.NUME, P.PRENUME, P.CNP, P.BISERIA, P.BINR, LOC.DEN_LOCALIT, P.ADRESA, P.PRENUMET, P.PRENUMEM, PKG_NOMPERS.GETDATAN(P.CNP),
        Decode(P.SCIVILA,-1,&apos;&apos;CASATORIT&apos;&apos;,&apos;&apos;NECASATORIT&apos;&apos;) SCivila,
        CASE WHEN P.STRAINATATE = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        CASE WHEN P.AGENT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        CASE WHEN P.DELEGAT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
        LOCAG.DEN_LOCALIT, GETADRESA(NAG.SECTOR,NAG.STRADA,NAG.NR1,NAG.NR2,NAG.BLOC,NAG.SCARA,NAG.ETAJ,NAG.APART,NAG.CODPOSTAL) Adresa, NAG.TELEFON, NAG.EMAIL,
        P.BIELIBERATDE, P.LADATADE, T.DEN_TARA,
        DECODE(P.CETATENIE,0,&apos;&apos;Stat Extra Comunitar (non UE)&apos;&apos;,1,&apos;&apos;Stat Comunitar (UE)&apos;&apos;,-1,&apos;&apos;Romana&apos;&apos;) Cetatenie,
        IO.Den_IOPers, F.DEN_FORMATIE, FT.DENUMIRE, M.DEN_MESERIE, P1.SCHIMB, CS.DEN_CURS, TM.DEN_TEMA,
        CASE WHEN NVL(CV.STARE,0) = 0 THEN &apos;&apos;?&apos;&apos;
             WHEN NVL(CV.STARE,0) = 1 THEN &apos;&apos;Planificat&apos;&apos;
             WHEN NVL(CV.STARE,0) = 2 THEN &apos;&apos;Suspendat&apos;&apos;
             WHEN NVL(CV.STARE,0) = 9 THEN &apos;&apos;Efectuat&apos;&apos;
        END,
        CV.NOTA,
        OBIECTIVE.DEN_OBIECTIV,
        CASE CV.TIPFORMARE
          WHEN 1 THEN &apos;&apos;Ex-cunostintele exista&apos;&apos;
          WHEN 2 THEN &apos;&apos;Ie-instruit extern&apos;&apos;
          WHEN 3 THEN &apos;&apos;Ii-instruit intern&apos;&apos;
          WHEN 4 THEN &apos;&apos;Si-studiu individual&apos;&apos;
        END,
        CASE CV.NIVELFORMARE
          WHEN 0 THEN &apos;&apos;Ou-bligatoriu si urgent&apos;&apos;
          WHEN 1 THEN &apos;&apos;O-obligatoriu&apos;&apos;
          WHEN 2 THEN &apos;&apos;U-Util&apos;&apos;
        END,
        extract(year from CV.DataPlan),
        extract(month from CV.DataPlan),
        extract(year from CV.Data),
        extract(month from CV.Data)&apos;||gUserAlias||&apos;
      FROM NPERS P
        INNER JOIN (SELECT CVV.*
                    FROM TMP_NPERSCURS CVV
                    WHERE (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODTEMA&apos;&apos; AND valoare = CVV.CODTEMA) OR
                           PKG_LIST_BASE_NOMPERS.isAllTeme = 1) and
                          (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODCURS&apos;&apos; AND valoare = CVV.CODCURS) OR
                           PKG_LIST_BASE_NOMPERS.isAllCursuri = 1) ) CV ON CV.CODPERS = P.CODPERS
        LEFT JOIN NPERS1    P1    ON P.CODPERS             = P1.CODPERS AND (pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop
        LEFT JOIN NAGENDA   NAG   ON NAG.CODAGENDA         = P.AGENDA
        LEFT JOIN NLOCALIT  LOC   ON P.LOCNASTERE          = LOC.CODLOCALIT
        LEFT JOIN NJUDET    JUD   ON LOC.CODJUDET          = JUD.CODJUDET
        LEFT JOIN NTARI     T     ON P.TARAN               = T.CODTARA
        LEFT JOIN NLOCALIT  LOCAG ON NAG.CODLOCALIT        = LOCAG.CODLOCALIT
        LEFT JOIN IOPERS    IO    ON P1.CODIOPERS          = IO.CODIOPERS
        LEFT JOIN FORMATII  F     ON P1.CODFORMATIE        = F.CODFORMATIE
        LEFT JOIN FUNCTII   FT    ON P1.CODFUNCTIE         = FT.CODFUNCTIE
        LEFT JOIN NMESERII  M     ON P1.CODMESERIE         = M.CODMESERIE
        LEFT JOIN OBIECTIVE       ON OBIECTIVE.CODOBIECTIV = CV.CODOBIECTIV
        LEFT JOIN CURSURI   CS    ON CS.CODCURS            = CV.CODCURS
        LEFT JOIN TEME      TM    ON TM.CODTEMA            = CV.CODTEMA
        LEFT JOIN NSUBUNIT  SUB   ON SUB.CODSUBUNIT        = P.CODSUBUNIT
        LEFT JOIN NGEST     G     ON P.CODGEST             = G.CODGEST
        LEFT JOIN (
          SELECT sold.CODPERS , SUM(sold.soldlei) soldlei
          FROM nperssoldluna sold
          WHERE sold.luna = pkg_globals.GetLUNALUCRU AND sold.an = pkg_globals.GetANLUCRU
          GROUP BY sold.codpers
        ) NPS ON P.CODPERS = NPS.CODPERS&apos;||
        gSuplJoins||&apos;
      WHERE P.CODPERS &gt; 0
        AND (EXISTS (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;&apos;CODPERS&apos;&apos; AND valoare = P.CODPERS) OR
             PKG_LIST_BASE_NOMPERS.isAllPers = 1) &apos;;
    end if;
    if vPerDataPlanif = 1 then
      sInsert := sInsert||&apos;
        AND CV.DATAPLAN BETWEEN TO_DATE(&apos;&apos;&apos;||DataIni||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||DataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
    end if;
  else
    sInsert:=&apos;INSERT INTO &apos;||tmpName||&apos;(
      MARCA, NUME, PRENUME, CNP, BISERIA, BINR, LOCNASTERE, ADRESA, PRENUMET, PRENUMEM, DATAN,
      SCIVILA,
      STRAINATATE,
      AGENT,
      DELEGAT,
      A_LOCALITATE,
      A_ADRESA, A_TELEFON, A_EMAIL,
      BIELIBERATDE, LADATADE, TARAN,
      CETATENIE,
      Den_IOPers,
      Formatie,
      Functie,
      Den_meserie,
      Schimb &apos;||gUserFields||&apos;)
    SELECT
      P.MARCA, P.NUME, P.PRENUME, P.CNP, P.BISERIA, P.BINR, LOC.DEN_LOCALIT, P.ADRESA, P.PRENUMET, P.PRENUMEM, PKG_NOMPERS.GETDATAN(P.CNP),
      Decode(P.SCIVILA,-1,&apos;&apos;CASATORIT&apos;&apos;,&apos;&apos;NECASATORIT&apos;&apos;) SCivila,
      CASE WHEN P.STRAINATATE = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
      CASE WHEN P.AGENT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
      CASE WHEN P.DELEGAT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
      LOCAG.DEN_LOCALIT, GETADRESA(NAG.SECTOR,NAG.STRADA,NAG.NR1,NAG.NR2,NAG.BLOC,NAG.SCARA,NAG.ETAJ,NAG.APART,NAG.CODPOSTAL) Adresa, NAG.TELEFON, NAG.EMAIL,
      P.BIELIBERATDE, P.LADATADE, T.DEN_TARA,
      DECODE(P.CETATENIE,0,&apos;&apos;Stat Extra Comunitar (non UE)&apos;&apos;,1,&apos;&apos;Stat Comunitar (UE)&apos;&apos;,-1,&apos;&apos;Romana&apos;&apos;) Cetatenie,
      IO.Den_IOPers, F.DEN_FORMATIE, FT.DENUMIRE, M.DEN_MESERIE, P1.SCHIMB &apos; ||gUserAlias||&apos;
    FROM NPERS P
      LEFT JOIN NPERS1   P1    ON P.CODPERS      = P1.CODPERS AND (pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop
      LEFT JOIN NAGENDA  NAG   ON NAG.CODAGENDA  = P.AGENDA
      LEFT JOIN NLOCALIT LOC   ON P.LOCNASTERE   = LOC.CODLOCALIT
      LEFT JOIN NJUDET   JUD   ON LOC.CODJUDET   = JUD.CODJUDET
      LEFT JOIN NTARI    T     ON P.TARAN        = T.CODTARA
      LEFT JOIN NLOCALIT LOCAG ON NAG.CODLOCALIT = LOCAG.CODLOCALIT
      LEFT JOIN IOPERS   IO    ON P1.CODIOPERS   = IO.CODIOPERS
      LEFT JOIN FORMATII F     ON P1.CODFORMATIE = F.CODFORMATIE
      LEFT JOIN FUNCTII  FT    ON P1.CODFUNCTIE  = FT.CODFUNCTIE
      LEFT JOIN NMESERII M     ON P1.CODMESERIE  = M.CODMESERIE
      LEFT JOIN NSUBUNIT SUB   ON SUB.CODSUBUNIT = P.CODSUBUNIT
      LEFT JOIN NGEST    G     ON P.CODGEST      = G.CODGEST
      LEFT JOIN (
        SELECT sold.CODPERS , SUM(sold.soldlei) soldlei
        FROM nperssoldluna sold
        WHERE sold.luna = pkg_globals.GetLUNALUCRU AND sold.an = pkg_globals.GetANLUCRU
        GROUP BY sold.codpers
      ) NPS ON P.CODPERS = NPS.CODPERS&apos;||
      gSuplJoins||&apos;
    WHERE P.CODPERS &gt; 0 &apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  if vGDPR = 0 then
    sInsert := &apos;update &apos;||tmpName||&apos; set 
                  CNP = &apos;&apos;***&apos;&apos;,
                  BISERIA = &apos;&apos;***&apos;&apos;,
                  BINR = &apos;&apos;***&apos;&apos;,
                  BIELIBERATDE = &apos;&apos;***&apos;&apos;,
                  LADATADE = NULL,
                  LOCNASTERE = &apos;&apos;***&apos;&apos;,
                  SCIVILA = &apos;&apos;***&apos;&apos;,
                  A_EMAIL = &apos;&apos;***&apos;&apos;,
                  A_TELEFON = &apos;&apos;***&apos;&apos;,
                  CETATENIE = &apos;&apos;***&apos;&apos;,
                  TARAN = &apos;&apos;***&apos;&apos;
                   &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);              
  end if;
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_nompers;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOM_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E0745C6AAE7A09E3719BF303DEB126D29C28760</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOM_UTILAJE is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  varchar2(10000);
BEGIN
  gSuplCols := &apos;NARTOBJ NOBJ,NUM NUM,NPART CLI,NPART FURN,NLOCALIT LOC,MIFIX MF,UTILAJE U&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := 
  &apos;INSERT INTO &apos;||tmpName||&apos; (
     NAV_CODDOC,
     NAV_TIPDOC,
     DENUMIRE,
     NRINVENTAR,
     ETICHETA,
     TIPUTILAJ,
     FLOTA,
     MODEL,
     ANF,
     SERIEF,
     INCARCARE,
     DATAGARANTIE,
     INGARANTIE,
     LUNGIME,
     LATIME,
     INALTIME,
     OBS,
     INACTIV,
     UM,
     PLAFONCANTF,
     GESTIUNE,      
     CLIENT,
     DATAGARANTIEI,
     APROBAT,
     DATASTART,
     NRCONTR,
     DATACONTR,
     FURNIZOR,
     DOC,
     TIP,
     LOCALIT,
     ADRESA &apos;||gUserFields||&apos;)
   SELECT
     U.CODUTILAJ,
     508,
     NOBJ.DENUMIRE,
     U.NRINVENTAR,
     U.ETICHETA,
     U.TIPUTILAJ,
     U.FLOTA,
     U.MODEL,
     U.ANF,
     U.SERIEF,
     U.INCARCARE,
     U.DATAGARANTIE,
     CASE WHEN U.INGARANTIE = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
     U.LUNGIME,
     U.LATIME,
     U.INALTIME,
     U.OBS,
     CASE WHEN U.INACTIV = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
     NUM.DEN_UM,
     U.PLAFONCANTF,
     GU.DEN_GEST,      
     CLI.DEN_PART,
     U.DATAGARANTIEI,
     CASE WHEN U.APROBAT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
     U.DATASTART,
     U.NRCONTR,
     U.DATACONTR,
     FURN.DEN_PART,
     case when U.DOC is null and U.CODIES1 &gt; 0 then I.NRDoc||&apos;&apos;/&apos;&apos;||to_char(I.DataDoc,&apos;&apos;DD.MM.YYYY&apos;&apos;) else U.DOC end,
     CASE
       CASE 
         WHEN U.TIP IS NULL AND U.CODPART &gt; 0 THEN 2 
         ELSE       
           CASE 
             WHEN (SELECT COUNT(*) FROM UTILAJE1 WHERE CODUTILAJ = U.CODUTILAJ) &gt; 0 AND U.TIP IS NULL THEN 1
             ELSE NVL(U.TIP,0)
           END    
       END
     WHEN 0 THEN &apos;&apos;Utilaj propriu&apos;&apos;
     WHEN 1 THEN &apos;&apos;Utilaj in custodie la client&apos;&apos;
     WHEN 2 THEN &apos;&apos;Utilaj client&apos;&apos;
     WHEN 3 THEN &apos;&apos;Utilaj client cu alt furnizor&apos;&apos;  
     WHEN 4 THEN &apos;&apos;Utilaj inchiriat clientului&apos;&apos;  
     END,
     LOC.DEN_LOCALIT,
     U.ADRESA
     &apos;||gUserAlias||&apos;
   FROM UTILAJE U
        INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT
        LEFT JOIN NUM NUM ON NUM.CODUM = U.UM
        LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = U.CODIES1
        LEFT JOIN IESIRI I ON I1.CODIES = I.CODIES
        LEFT JOIN LIVR L ON L.CODIES = I.CODIES
        LEFT JOIN LIVR1 L1 ON I1.CODIES1 = L1.CODIES1 AND L1.CODLIVR = L.CODLIVR
        LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NPART P ON NS.FURN = P.CODPART
        LEFT JOIN CONTRACT1 C1 ON C1.CODCONTRACT1 = I1.CODCONTRACT1
        LEFT JOIN CONTRACT C ON C.CODCONTRACT = I.CODCONTRACT
        LEFT JOIN NGEST GU ON GU.CODGEST = U.CODGEST
        LEFT JOIN NPART CLI ON CLI.CODPART = U.CODPART
        LEFT JOIN NPART FURN ON FURN.CODPART = U.CODFURNIZOR
        LEFT JOIN NLOCALIT LOC ON U.CODLOCALIT = LOC.CODLOCALIT
        LEFT JOIN MIFIX MF ON MF.NRINVENTAR = U.NRINVENTAR AND MF.TIP = &apos;&apos;MF&apos;&apos;
        &apos;||gSuplJoins;
  
 LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
 COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NOM_UTILAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NORMEAP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21AE6DDA3D39B3DF559B91534E951B18DC09C9F6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_normeap is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert     VARCHAR2(10000);
sSelect     VARCHAR2(20000);
AnLunaLucru NUMBER(20);
sSelect0    VARCHAR2(20000);
sSelect1    VARCHAR2(20000);
gStocField  varchar2(50);
gStocAlias  varchar2(50);
vUserID number(20);
BEGIN
  vUserID := pkg_globals.GETUSERID;
  gStocField := &apos; &apos;;
  gStocAlias := &apos; &apos;;

  gSuplCols := &apos;NARTOBJ OBJP, NARTOBJ OBJC, PRODCOMP PC, NCLASEA CLSCOMP, NGEST SECTIE&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTP&apos;, &apos;OEXTP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRP&apos;, &apos;OATRP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTC&apos;, &apos;OEXTC.CODOBIECT = OBJC.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRC&apos;, &apos;OATRC.CODOBIECT = OBJC.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if PKG_LIST_BASE_CONSUM_PROD.GetAllArt = 1 then
    delete tmp_prodcomp_man where userid = vuserid;
    insert into tmp_prodcomp_man (codprodcomp, cant, pret, userid)
      (select PC.codprodcomp, PC.cant, PC.Pret, vUserID
       from prodcomp PC
      );
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos; (
    NAV_CodDoc,
    NAV_TipDoc,
    Tab,
    DenTab,
    CODNORMA,
    CODPRODCOMP,
    PR_ART,
    PR_CODEXTERN,
    PR_CODINTERN,
    SECTIE,
    PR_CANT,
    PR_PRET,
    PR_PRET_REF,
    COMP_ART,
    COMP_CODEXTERN,
    COMP_CODINTERN,
    COMP_CODCATALOG,
    COMP_UM,
    COMP_CANT,
    COMP_PRET,
    COMP_VALOARE,
    COMP_TIP,
    COMP_IOART,
    COMP_UM1,
    COMP_CANTUM1,
    COMP_D1,
    COMP_D2,
    COMP_D3,
    COMP_INLOCUIT,
    RETETAIMP,
    NORMAIMP,
    RETETAACTIVA,
    NORMAACTIVA,
    DATACREARE,
    DATAMODIFICARE&apos;||gUserFields||&apos;)&apos;;

  sSelect0 := &apos;
  SELECT
    PC.CODPRODCOMP NAV_CodDoc,
    504 NAV_TipDoc,
    &apos;&apos;Reteta&apos;&apos; Tab,
    PC.Obs DenTab,
    null CODNORMA,
    PC.CODPRODCOMP,
    OBJP.DENUMIRE PR_ART,
    OBJP.CODEXTERN PR_CODEXTERN,
    OBJP.CODINTERN PR_CODINTERN,
    SECTIE.DEN_GEST SECTIE,
    PC.CANT PR_CANT,
    PC.PRET PR_PRET,
    P1.PRETREFERINTA PR_PRET_REF,
    OBJC.DENUMIRE COMP_ART,
    OBJC.CODEXTERN COMP_CODEXTERN,
    OBJC.CODINTERN COMP_CODINTERN,
    ARTC.CODEXTERNART||&apos;&apos;_&apos;&apos;||ARTC.SUFIXCODEXTERN COMP_CODCATALOG,
    NUMC.DEN_UM COMP_UM,
    MAT.CANT COMP_CANT,
    MAT.PRET COMP_PRET,
    MAT.PRET*MAT.CANT COMP_VALOARE,
    case
      when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos;
      when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos;
      when MAT.Tip = 3 then &apos;&apos;Material&apos;&apos;
      when MAT.Tip = 4 then &apos;&apos;Lohn&apos;&apos;
      when MAT.Tip = 5 then &apos;&apos;Fix&apos;&apos;
      else &apos;&apos;Material&apos;&apos;
    end COMP_TIP,
    CONTC.SIMBOL COMP_IOART,
    NUMC1.DEN_UM COMP_UM1,
    case when nvl(MAT.CANTUM1,0) = 0 then null else MAT.CANTUM1 end COMP_CANTUM1,
    case when nvl(MAT.D1,0) = 0 then null else MAT.D1 end COMP_D1,
    case when nvl(MAT.D2,0) = 0 then null else MAT.D2 end COMP_D2,
    case when nvl(MAT.D3,0) = 0 then null else MAT.D3 end COMP_D3,
    CASE
      WHEN NORNR.NRNORME = 0 THEN &apos;&apos;NU&apos;&apos;
      WHEN NORNR.NRNORME = NORNROBJ.NRNORME THEN &apos;&apos;NU&apos;&apos;
      ELSE &apos;&apos;DA&apos;&apos;
    END COMP_INLOCUIT,
    CASE WHEN PC.IMPLICIT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END RETETAIMP,
    NULL NORMAIMP,
    CASE WHEN PC.INACTIV = 1 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END RETETAACTIVA,
    NULL NORMAACTIVA,
    PC.DATACREARE DATACREARE,
    NULL DATAMODIFICARE &apos;||gUserAlias||&apos;
  FROM
    PRODCOMP PC
    INNER JOIN TMP_PRODCOMP_MAN TMP ON PC.CodProdComp = TMP.CodProdComp
    INNER JOIN PRODMAT MAT  ON PC.CODPRODCOMP = MAT.CODPRODCOMP
    INNER JOIN (SELECT MIN(INDEXLOCAL) INDEXLOCAL, CODPRODCOMP FROM PRODGEST GROUP BY CODPRODCOMP) MINIDX ON MINIDX.CODPRODCOMP = PC.CODPRODCOMP
    INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = MINIDX.CODPRODCOMP AND PG.INDEXLOCAL = MINIDX.INDEXLOCAL
    INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
    INNER JOIN NARTOBJ OBJP ON PC.CODOBIECT = OBJP.CODOBIECT
    INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
    INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
    INNER JOIN NARTOBJ OBJC ON MAT.CODOBIECT = OBJC.CODOBIECT
    INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
    INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
    LEFT  JOIN (SELECT COUNT(*) NRNORME, CODPRODCOMP FROM NORMEMAT GROUP BY CODPRODCOMP) NORNR ON NORNR.CODPRODCOMP = PC.CODPRODCOMP
    LEFT  JOIN (SELECT COUNT(*) NRNORME, CODPRODCOMP, CODOBIECT FROM NORMEMAT GROUP BY CODPRODCOMP, CODOBIECT
               ) NORNROBJ ON NORNROBJ.CODPRODCOMP = PC.CODPRODCOMP AND NORNROBJ.CODOBIECT = MAT.CODOBIECT
    LEFT  JOIN NARTIMPLICITE CIMP ON CIMP.CODARTICOL = ARTC.CODARTICOL AND CIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
    LEFT  JOIN NARTOBJIMP OIMP ON OIMP.CODOBIECT = OBJC.CODOBIECT AND OIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
    LEFT  JOIN IOART IOC ON IOC.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN CIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
    LEFT  JOIN IOART1 IOCLUNA ON IOCLUNA.CODIOART = IOC.CODIOART AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN IOCLUNA.ALStart and IOCLUNA.ALStop
    LEFT  JOIN NCONT CONTC ON CONTC.CODCONT = IOCLUNA.CONT
    LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
    LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
    LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
    LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
    LEFT  JOIN NARTOBJ1  P1 ON P1.CodObiect  = OBJP.CodObiect AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop 
    LEFT  JOIN NARTOBJ1  C1 ON C1.CodObiect  = OBJC.CodObiect AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN C1.ALStart and C1.ALStop &apos;||gSuplJoins||&apos;
  WHERE 1=1
    --NVL(P1.AnStart*12 + P1.LunaStart, 0) = (SELECT NVL(MAX(AnStart * 12 + LunaStart), 0) FROM NARTOBJ1 WHERE CodObiect = P1.CodObiect AND AnStart*12 + LunaStart &lt;= PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU)
    --AND NVL(C1.AnStart*12 + C1.LunaStart, 0) = (SELECT NVL(MAX(AnStart * 12 + LunaStart), 0) FROM NARTOBJ1 WHERE CodObiect = C1.CodObiect AND AnStart*12 + LunaStart &lt;= PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU)
    AND TMP.USERID = &apos;||vUserID;

  sSelect1 := &apos;
  SELECT
    PC.CODPRODCOMP NAV_CodDoc,
    504 NAV_TipDoc,
    &apos;&apos;Norma&apos;&apos; Tab,
    NOR.NORMA DenTab,
    NOR.CODNORMA,
    PC.CODPRODCOMP,
    OBJP.DENUMIRE PR_ART,
    OBJP.CODEXTERN PR_CODEXTERN,
    OBJP.CODINTERN PR_CODINTERN,
    SECTIE.DEN_GEST SECTIE,
    PC.CANT PR_CANT,
    PC.PRET PR_PRET,
    P1.PRETREFERINTA PR_PRET_REF,
    OBJC.DENUMIRE COMP_ART,
    OBJC.CODEXTERN COMP_CODEXTERN,
    OBJC.CODINTERN COMP_CODINTERN,
    ARTC.CODEXTERNART||&apos;&apos;_&apos;&apos;||ARTC.SUFIXCODEXTERN COMP_CODCATALOG,
    NUMC.DEN_UM COMP_UM,
    MAT.CANT COMP_CANT,
    MAT.PRET COMP_PRET,
    MAT.PRET*MAT.CANT COMP_VALOARE,
    null COMP_TIP,
    CONTC.SIMBOL COMP_IOART,
    NUMC1.DEN_UM COMP_UM1,
    case when nvl(MAT.CANTUM1,0) = 0 then null else MAT.CANTUM1 end COMP_CANTUM1,
    case when nvl(MAT.D1,0) = 0 then null else MAT.D1 end COMP_D1,
    case when nvl(MAT.D2,0) = 0 then null else MAT.D2 end COMP_D2,
    case when nvl(MAT.D3,0) = 0 then null else MAT.D3 end COMP_D3,
    CASE
      WHEN NORNR.NRNORME = 0 THEN &apos;&apos;NU&apos;&apos;
      WHEN NORNR.NRNORME = NORNROBJ.NRNORME AND NVL(MT.CODMAT,0) &gt; 0 THEN &apos;&apos;NU&apos;&apos;
      WHEN NVL(MT.CODMAT,0) = 0 THEN &apos;&apos;DA&apos;&apos;
      ELSE &apos;&apos;DA&apos;&apos;
    END COMP_INLOCUIT,
    CASE WHEN PC.IMPLICIT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END RETETAIMP,
    CASE WHEN NOR.IMPLICIT = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END NORMAIMP,
    CASE WHEN PC.INACTIV = 1 THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END RETETAACTIVA,
    CASE WHEN NOR.ACTIV = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END NORMAACTIVA,
    PC.DATACREARE,
    CASE WHEN NOR.DATAACTIV &gt; NOR.DATAINACTIV THEN NOR.DATAACTIV ELSE NOR.DATAINACTIV END &apos;||gUserAlias||&apos;
  FROM
    PRODCOMP PC
    INNER JOIN TMP_PRODCOMP_MAN TMP ON PC.CodProdComp = TMP.CodProdComp
    INNER JOIN PRODNORME NOR ON PC.CODPRODCOMP = NOR.CODPRODCOMP
    INNER JOIN NORMEMAT MAT  ON PC.CODPRODCOMP = MAT.CODPRODCOMP AND NOR.CODNORMA = MAT.CODNORMA
    INNER JOIN (SELECT MIN(INDEXLOCAL) INDEXLOCAL, CODPRODCOMP FROM PRODGEST GROUP BY CODPRODCOMP) MINIDX ON MINIDX.CODPRODCOMP = PC.CODPRODCOMP
    INNER JOIN PRODGEST PG ON PG.CODPRODCOMP = MINIDX.CODPRODCOMP AND PG.INDEXLOCAL = MINIDX.INDEXLOCAL
    INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
    INNER JOIN NARTOBJ OBJP ON PC.CODOBIECT = OBJP.CODOBIECT
    INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
    INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
    INNER JOIN NARTOBJ OBJC ON MAT.CODOBIECT = OBJC.CODOBIECT
    INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
    INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
    LEFT  JOIN (SELECT COUNT(*) NRNORME, CODPRODCOMP FROM PRODNORME GROUP BY CODPRODCOMP) NORNR ON NORNR.CODPRODCOMP = PC.CODPRODCOMP
    LEFT  JOIN (SELECT COUNT(*) NRNORME, CODPRODCOMP, CODOBIECT FROM NORMEMAT GROUP BY CODPRODCOMP, CODOBIECT
               ) NORNROBJ ON NORNROBJ.CODPRODCOMP = PC.CODPRODCOMP AND NORNROBJ.CODOBIECT = MAT.CODOBIECT
    LEFT  JOIN PRODMAT MT ON MT.CODPRODCOMP = PC.CODPRODCOMP AND MT.CODOBIECT = MAT.CODOBIECT
    LEFT  JOIN NARTIMPLICITE CIMP ON CIMP.CODARTICOL = ARTC.CODARTICOL AND CIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
    LEFT  JOIN NARTOBJIMP OIMP ON OIMP.CODOBIECT = OBJC.CODOBIECT AND OIMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
    LEFT  JOIN IOART IOC ON IOC.CODIOART = CASE WHEN COALESCE(OIMP.CONTIMPLICIT,0) = 0 THEN CIMP.CONTIMPLICIT ELSE COALESCE(OIMP.CONTIMPLICIT,0) END
    LEFT  JOIN IOART1 IOCLUNA ON IOCLUNA.CODIOART = IOC.CODIOART AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN IOCLUNA.ALStart and IOCLUNA.ALStop
    LEFT  JOIN NCONT CONTC ON CONTC.CODCONT = IOCLUNA.CONT
    LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
    LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
    LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
    LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
    LEFT  JOIN NARTOBJ1  P1 ON P1.CodObiect  = OBJP.CodObiect AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN P1.ALStart and P1.ALStop 
    LEFT  JOIN NARTOBJ1  C1 ON C1.CodObiect  = OBJC.CodObiect AND (PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU) BETWEEN C1.ALStart and C1.ALStop &apos;||gSuplJoins||&apos;
  WHERE 1=1
    --NVL(P1.AnStart*12 + P1.LunaStart, 0) = (SELECT NVL(MAX(AnStart * 12 + LunaStart), 0) FROM NARTOBJ1 WHERE CodObiect = P1.CodObiect AND AnStart*12 + LunaStart &lt;= PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU)
    --AND NVL(C1.AnStart*12 + C1.LunaStart, 0) = (SELECT NVL(MAX(AnStart * 12 + LunaStart), 0) FROM NARTOBJ1 WHERE CodObiect = C1.CodObiect AND AnStart*12 + LunaStart &lt;= PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLUNALUCRU)
    AND TMP.USERID = &apos;||vUserID;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect0, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_normeap; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEF428382FE0E09795FA58CF087CE8649FDD9394</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_notacantarcom IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols   := &apos;TMP_ONORCOM_COMENZI TC, TMP_ONORCOM_ARTICOLE TA, COMANDA C, NPARTTR D, NAGENDA SED, NLOCALIT SEDL&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NrCom, DataCom, Com,
    NrIes, DataIes, Ies,
    Dest, Sediu, Localit, Delegat,
    Art, Net, Brut,
    CantA1, CantA2, CantA3, CantA4, CantA5, CantA6, KgA1, KgA2, KgA3, KgA4, KgA5, KgA6  &apos;||gUserFields||&apos;)
  SELECT
    TC.Nrcomanda, TC.DataComanda, C.PrefixDoc||C.Nrdoc||&apos;&apos;/&apos;&apos;||To_Char(C.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),
    TC.NrDoc, TC.DataDoc, CASE WHEN T.CodTransf IS NULL THEN I.PrefixDoc ELSE T.PrefixDoc END||TC.Nrdoc||&apos;&apos;/&apos;&apos;||To_Char(TC.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),
    TC.DenClient, TC.DenSediu, SEDL.Den_Localit, D.Delegat,
    TA.DenObiect, NVL(TA.Net,0), NVL(TA.Brut,0),
    NVL(TA.A1,0), NVL(TA.A2,0), NVL(TA.A3,0), NVL(TA.A4,0), NVL(TA.A5,0), NVL(TA.A6,0), 
    NVL(TA.KGA1,0), NVL(TA.KGA2,0), NVL(TA.KGA3,0), NVL(TA.KGA4,0), NVL(TA.KGA5,0), NVL(TA.KGA6,0) &apos;||gUserAlias||&apos;
  FROM TMP_ONORCOM_COMENZI TC
    INNER JOIN TMP_ONORCOM_ARTICOLE TA ON TA.CODCOMANDA = TC.CODCOMANDA
    LEFT JOIN COMANDA C ON C.CODCOMANDA = TC.CODCOMANDA
    LEFT JOIN IESIRI I ON I.CODIES = TC.CODDOC AND I.TIPDOC = TC.TIPDOC
    LEFT JOIN TRANSF T ON T.CODTRANSF = TC.CODDOC AND T.TIPDOC = TC.TIPDOC
    LEFT JOIN NPARTTR D ON D.CODPARTTR = TC.CODDELEGAT
    LEFT JOIN NAGENDA SED ON SED.CODAGENDA = TC.CODSEDIU
    LEFT JOIN NLOCALIT SEDL ON SEDL.CODLOCALIT = SED.CODLOCALIT&apos;||
    gSuplJoins||&apos;
  WHERE TC.GDI = 1 AND NVL(TA.NET,0) &lt;&gt; 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NOTACANTARCOM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D532E9443BC472FDE753BB84A76A1291B0032608</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_notacantaries IS

  vCodDoc INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN INTEGER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN

  gSuplCols := &apos;iesiri i, iesiri1 i1, nartobj o, cantar c&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     Art, IDX, Net, Brut,
     CantA1, CantA2, CantA3, CantA4, CantA5, CantA6,
     KgA1, KgA2, KgA3, KgA4, KgA5, KgA6,
     KgP, CantT1, CantT2, KgT1, KgT2  &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    o.denumire, i1.indexlocal, Nvl(c.net_kg,0), Nvl(c.total_kg,0),
    Nvl(c.amb1_cant,0), Nvl(c.amb2_cant,0), Nvl(c.amb3_cant,0), Nvl(c.amb4_cant,0), Nvl(c.amb5_cant,0), Nvl(c.amb6_cant,0),
    Nvl(c.amb1_kg,0), Nvl(c.amb2_kg,0), Nvl(c.amb3_kg,0), Nvl(c.amb4_kg,0), Nvl(c.amb5_kg,0), Nvl(c.amb6_kg,0),
    Nvl(c.palet_kg,0), Nvl(c.transp1_cant,0), Nvl(c.transp2_cant,0), Nvl(c.transp1_kg,0), Nvl(c.transp2_kg,0) &apos;||gUserAlias||&apos;
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN cantar c ON c.coddoc1 = i1.codies1 AND c.tipdoc = i.tipdoc AND c.codobiect = i1.codobiect
    INNER JOIN nartobj o ON o.codobiect = c.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND i.codies =&apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

end PKG_LIST_BASE_NOTACANTARIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A0B9E0785803FCF68096E14D161EA04FA86D59E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOTACANTARINTR is

  vCodDoc INTEGER;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN INTEGER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;intrari i, intrari1 i1, nartobj o, cantar c&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     Art, IDX, Net, Brut,
     CantA1, CantA2, CantA3, CantA4, CantA5, CantA6,
     KgA1, KgA2, KgA3, KgA4, KgA5, KgA6,
     KgP, CantT1, CantT2, KgT1, KgT2,
     Client, CmdCli &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    o.denumire, i1.indexlocal, Nvl(c.net_kg,0), Nvl(c.total_kg,0),
    Nvl(c.amb1_cant,0), Nvl(c.amb2_cant,0), Nvl(c.amb3_cant,0), Nvl(c.amb4_cant,0), Nvl(c.amb5_cant,0), Nvl(c.amb6_cant,0),
    Nvl(c.amb1_kg,0), Nvl(c.amb2_kg,0), Nvl(c.amb3_kg,0), Nvl(c.amb4_kg,0), Nvl(c.amb5_kg,0), Nvl(c.amb6_kg,0),
    Nvl(c.palet_kg,0), Nvl(c.transp1_cant,0), Nvl(c.transp2_cant,0), Nvl(c.transp1_kg,0), Nvl(c.transp2_kg,0),
    P.DEN_PART, CC.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(CC.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM intrari i
    INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    INNER JOIN cantar c ON c.coddoc1 = i1.codintr1 AND c.tipdoc = i.tipdoc AND c.codobiect = i1.codobiect
    INNER JOIN nartobj o ON o.codobiect = c.codobiect
    LEFT JOIN COMANDA1 CC1 ON CC1.CODCOMANDA1 = PKG_COMANDA.DINCMDCLI(I1.CODCMDINT1)
    LEFT JOIN COMANDA CC ON CC.CODCOMANDA = CC1.CODCOMANDA
    LEFT JOIN NPART P ON P.CODPART = CC.PARTENER &apos;||gSuplJoins||&apos;
  WHERE c.anulat = 0 AND i.codintr =&apos;||vCodDoc;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  pkg_list_base_docintr.SETPARAMS(vCodDoc);
  pkg_list_base_docintr.ProcessParams(tmpName);
  COMMIT;
END;

end PKG_LIST_BASE_NOTACANTARINTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTACANTARTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>979F0B59114CB60E5434F4172E44908F799B2732</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_notacantartransf IS

  vCodDoc INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDoc IN INTEGER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sJoinExt   VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;transf t, transf1 t1, nartobj o, cantar c&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Art, IDX, Net, Brut,
    CantA1, CantA2, CantA3,
    CantA4, CantA5, CantA6, KgA1, KgA2, KgA3, KgA4, KgA5, KgA6,
    KgP, CantT1, CantT2, KgT1, KgT2  &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    o.denumire, t1.indexlocal, Nvl(c.net_kg,0), Nvl(c.total_kg,0),
    Nvl(c.amb1_cant,0), Nvl(c.amb2_cant,0), Nvl(c.amb3_cant,0), Nvl(c.amb4_cant,0), Nvl(c.amb5_cant,0), Nvl(c.amb6_cant,0),
    Nvl(c.amb1_kg,0), Nvl(c.amb2_kg,0), Nvl(c.amb3_kg,0), Nvl(c.amb4_kg,0), Nvl(c.amb5_kg,0), Nvl(c.amb6_kg,0),
    Nvl(c.palet_kg,0), Nvl(c.transp1_cant,0), Nvl(c.transp2_cant,0), Nvl(c.transp1_kg,0), Nvl(c.transp2_kg,0) &apos;||gUserAlias||&apos;
  FROM transf t
    INNER JOIN transf1 t1 ON t1.codtransf = t.codtransf
    INNER JOIN cantar c ON c.coddoc1 = t1.codtransf1 AND c.tipdoc = t.tipdoc
    LEFT JOIN nartobj o ON o.codobiect = c.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE t.codtransf =&apos;||vCodDoc;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  pkg_list_base_transfdoc.ProcessParams(vCodDoc);
  COMMIT;

END;

end PKG_LIST_BASE_NOTACANTARTRANSF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC0A5B382F239948C32567248D679F2BA773EC29</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOTACONT IS

  vTipDoc NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pTipDoc IN NUMBER) IS
BEGIN
  vTipDoc := pTipDoc;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  vCODUSERID NUMBER(20) := 0;
BEGIN
  gSuplCols := &apos;NCont cont_d, NCont cont_c, NGest g, Jurnal j, NSubunit sub, CentreCost cc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  -- stef - filtrul dupa an si luna l-am pus pt. imobilizari, sa aduca doar de pe luna curenta
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (DEBIT,CREDIT,VALOARE,OBS, Doc, Ordine, CentruCost, Subunitatea &apos;||gUserFields||&apos;)
  SELECT cont_d.simbol debit, cont_c.simbol credit, j.valoare, j.obs, j.Document, j.Codjurnal, cc.Denumire, sub.Den_Subunit &apos;||gUserAlias||&apos;
  FROM JURNAL j
    INNER JOIN TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc
    LEFT JOIN NCont cont_d ON j.contd = cont_d.codcont
    LEFT JOIN NCont cont_c ON j.contc = cont_c.codcont
    LEFT JOIN NGest g ON j.gest = g.codgest
    LEFT JOIN NSubunit sub ON j.subunitatea = sub.codsubunit
    LEFT JOIN CentreCost cc ON cc.codcentru = j.codcentru&apos;||
    gSuplJoins||&apos;
  WHERE J.TipDoc = &apos;||vTipDoc||&apos;
    AND J.CodDoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODDOC&apos;&apos;)&apos;;

  IF vTipDoc IN (36,52) THEN -- [mMifix, mCheltuieliInAvans]
    sInsert := sInsert||&apos;
    AND J.An*12+J.Luna = &apos;||pkg_globals.ANLUNALUCRU;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  IF vTipDoc = 35 THEN
    SELECT Max(Nvl(CODPERS,0)) INTO vCODUSERID
    FROM TMP_MANEVRA_LISTE T
      LEFT JOIN NC ON NC.CODNC = T.VALOARE
      LEFT JOIN NPERS U ON U.LOGONNAME = NC.USERID
    WHERE T.FILTRU = &apos;CODDOC&apos;;
  END IF;

  FOR v_rec IN (
    SELECT Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI
    FROM NPERS U
    WHERE U.CODPERS = vCODUSERID
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,   v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;, v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,     v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,      v_rec.UBI);
    EXIT;
  END LOOP;
  FOR V_REC IN (
    SELECT STRAGG3200(OBS) OBS FROM (
    SELECT DISTINCT pkg_list_utilfisacont.GetObsDocJurnal(J.CODJURNAL) OBS
    FROM JURNAL J
         INNER JOIN TMP_MANEVRA_LISTE TMP on TMP.VALOARE = J.CodDoc
    WHERE J.TIPDOC = VTIPDOC AND J.CodDoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODDOC&apos;)
    )
    )
  LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII DOCUMENT&apos;, v_rec.OBS);
    EXIT;
  END LOOP;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_notacont;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE366FB8BD49DA3D8871185DF127C09278F71365</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_notecredit IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION  GetDiscV (pCodContract IN NUMBER, pValM IN NUMBER, pValTot IN NUMBER) RETURN NUMBER IS
  vProcDisc NUMBER;
  vValDisc  NUMBER;
  vResult   NUMBER;
BEGIN
  vResult := 0;
  IF Nvl(pCodContract, 0) &lt;&gt; 0 THEN
    vProcDisc  := pkg_notecredit.getproccontractvolum(pValTot, pCodContract);
    IF Nvl(vProcDisc, 0) &lt;&gt; 0 THEN
      vRESULT  := pValM * vProcDisc / 100;
    ELSIF Nvl(pValTot, 0) &lt;&gt; 0 THEN
      vValDisc := pkg_notecredit.getvaldisccontractvolum(pValTot, pCodContract);
      vRESULT  := pValM / pValTot * vValDisc;
    END IF;
  END IF;
  RETURN vResult;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sSelectT  VARCHAR2(30000);
  sSelectV  VARCHAR2(30000);
  sSelectC  VARCHAR2(30000);
  sSelectP  VARCHAR2(30000);

  sTipNC    INTEGER;
  sFiltruNC VARCHAR2(1000);
  sTable    VARCHAR2(100);
  sTable1   VARCHAR2(100);
  sCamp     VARCHAR2(100);
  sCamp1    VARCHAR2(100);
  sWhenObj  VARCHAR2(1000);
  sDisc     VARCHAR2(1000);
BEGIN
  sFiltruNC := &apos;
    AND nc.datastart &lt;= TO_DATE(&apos;&apos;&apos;||PKG_LIST_ALEGPERIOADA.getDataF||&apos;&apos;&apos;)
    AND nc.datastop  &gt;= TO_DATE(&apos;&apos;&apos;||PKG_LIST_ALEGPERIOADA.getDataS||&apos;&apos;&apos;)
    AND i.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_ALEGPERIOADA.getDataS||&apos;&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_ALEGPERIOADA.getDataF||&apos;&apos;&apos;)&apos;;

  IF aLISTID = 253
  THEN -- clienti
    sTipNC    := 58;
    sTable    := &apos;IESIRI&apos;;
    sTable1   := &apos;IESIRI1&apos;;
    sCamp     := &apos;CODIES&apos;;
    sCamp1    := &apos;CODIES1&apos;;
    gSuplCols := &apos;notecredit nc, notecredit1 nc1, iesiri i, npart p, nartobj o, ncont c, ncont casoc,nclasedisc clsdisc&apos;;
  ELSE -- furnitzori
    sTipNC    := 59;
    sTable    := &apos;INTRARI&apos;;
    sTable1   := &apos;INTRARI1&apos;;
    sCamp     := &apos;CODINTR&apos;;
    sCamp1    := &apos;CODINTR1&apos;;
    gSuplCols := &apos;notecredit nc, notecredit1 nc1, intrari i, npart p, nartobj o, ncont c, ncont casoc,nclasedisc clsdisc&apos;;
  END IF;


  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;, &apos;);
  WITH x AS (
              SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
    UNION ALL SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
    UNION ALL SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
  )
  SELECT string_agg(cod)||PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO sWhenObj
  FROM x
  WHERE Nvl(x.cod, 0) &gt; 0;

  IF sWhenObj IS NOT NULL THEN
    sWhenObj := &apos;
          WHEN I1.CodObiect IN (&apos;||sWhenObj||&apos;) THEN 0&apos;;
  END IF;

  sSelectV :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
     NAV_CodDoc, NAV_TipDoc, NCDATAI, NCDATAS, TIPOPER, DOC,
     PART, ART, SUBUNITATEA, CONT, MONEDA, LOCATIE,
     CURS,
     VAL, VALLEI, DISCOUNT &apos;||gUserFields||&apos;)
  WITH ValAaux AS (
    SELECT codncredit1, ValM, Sum(ValM) over (PARTITION BY codncredit) ValTot
    FROM (
      SELECT
        nc.codncredit, nc1.codncredit1,
        SUM (
          CASE
            WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;, &apos;&apos;G&apos;&apos;) AND i.tipdoc IN (3, 16, 21) THEN I1.RESTFACT - I1.TVA
            WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;, &apos;&apos;G&apos;&apos;) THEN I1.RESTFACT&apos;||
            sWhenObj||&apos;
            WHEN i.tipdoc IN (3, 16, 21) THEN I1.Cant*I1.PU - I1.TVA
            ELSE I1.Cant*I1.PU
          END) ValM
      FROM NOTECREDIT NC
        INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
        INNER JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = nc1.coddoc AND nc1.tipdoc = i.tipdoc
        INNER JOIN &apos;||sTable1||&apos; I1 ON i1.&apos;||sCamp||&apos; = i.&apos;||sCamp||&apos;
      WHERE nc.tipdoc = &apos;||sTipNC||
        sFiltruNC||&apos;
        AND nc1.tipoper = &apos;&apos;V&apos;&apos;
      GROUP BY nc.codncredit, nc1.codncredit1
    )
  )
  SELECT
    nc.codncredit, &apos;||sTipNC||&apos;, nc.datastart, nc.datastop, &apos;&apos;VOLUM&apos;&apos;,  i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    p.den_part, o.denumire, s.den_subunit, c.simbol, m.simbol, a.obs,
    DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    ROUND(VA.ValM, 4),
    ROUND(VA.ValM * DECODE(NVL(G.CURS, 0), 0, 1, G.CURS), 4),
    coalesce(nc1.valoare,0) - coalesce(nc1.valoareold,0) &apos;||gUserAlias||&apos;
  FROM NOTECREDIT NC
    INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
    LEFT JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = NC1.Coddoc AND I.TipDoc = NC1.TipDoc
    LEFT JOIN VALAAUX VA ON VA.CODNCREDIT1 = NC1.CODNCREDIT1
    LEFT JOIN NCONT C ON C.CODCONT = NC.CODCONTV
    LEFT JOIN NCONT CASOC ON CASOC.CODCONT = 0
    LEFT JOIN NPART P ON P.CODPART = NC.CODPART
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = NC.SUBUNITATEA
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = 0
    LEFT JOIN GENERAL G ON G.CODDOC = NC1.Coddoc AND G.TipDoc = NC1.TipDoc
    LEFT JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
    LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
    LEFT JOIN CONTRACT2 C2 ON C2.CODCONTRACT2 = NC.CODCONTRACT2
    left join nclasedisc clsdisc on clsdisc.codclasedisc = nc1.codclasedisc &apos;||
    gSuplJoins||&apos;
  WHERE NC.TIPDOC = &apos;||sTipNC||
    sFiltruNC||&apos;
    AND NC1.TipOper = &apos;&apos;V&apos;&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;);

  IF sTipNC = 58
  THEN
    sSelectV := sSelectV||&apos;
    AND G.Semnificatie = 200&apos;;
  ELSE
    sSelectV := sSelectV||&apos;
    AND G.Semnificatie &lt;&gt; 500 and G.Semnificatie &lt;&gt; 111 and G.Semnificatie &lt;&gt; 200 and G.Semnificatie &lt;&gt; 140&apos;;
  END IF;

  sDisc := &apos;COALESCE(NC1.VALOARE,0) - COALESCE(NC1.VALOAREOLD,0), &apos;;

  sSelectT :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
     NCDATAI, NCDATAS, TIPOPER, DOC,
     PART, ART, SUBUNITATEA, CONT, MONEDA, LOCATIE,
     CURS,
     VAL,
     VALLEI,
     DISCOUNT,
     CANT,
     CONTASOC, TERMEN,
     DOCPLATA,
     VALPLATA,
     ZILEPLATA &apos;||gUserFields||&apos;)
  SELECT
    nc.datastart, nc.datastop, &apos;&apos;TERMEN&apos;&apos;,  i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    p.den_part, o.denumire, s.den_subunit, c.simbol, m.simbol, a.obs,
    DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    CASE WHEN i.tipdoc IN (3, 16, 21) THEN i1.pu*i1.cant ELSE i1.pu*i1.cant+i1.tva END,
    CASE WHEN i.tipdoc IN (3, 16, 21) THEN i1.pu*i1.cant ELSE i1.pu*i1.cant+i1.tva END * DECODE(NVL(G.CURS, 0), 0, 1, G.CURS), &apos;||
    sDisc||&apos;
    I1.CANT,
    CASOC.SIMBOL, OB.TERMEN,
    T1.DOC||T1.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T1.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    STG.VALOARE * (CASE WHEN i.tipdoc IN (3, 16, 21) THEN i1.pu*i1.cant ELSE i1.pu*i1.cant+i1.tva END) / I.VALDOC,
    T1.DATADOC - I.DATADOC &apos;||gUserAlias||&apos;
  FROM NOTECREDIT NC
    INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
    LEFT JOIN &apos;||sTable1||&apos; I1 ON i1.&apos;||sCamp1||&apos; = NC1.Coddoc
    LEFT JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = i1.&apos;||sCamp||&apos; AND I.TipDoc = NC1.TipDoc
    LEFT JOIN GENERAL G ON G.CODDOC = i.&apos;||sCamp||&apos; AND G.TipDoc = NC1.TipDoc
    LEFT JOIN OBLIGPIF OB ON OB.CODOBLIGPIF = NC1.CODOBLIGSTINS
    LEFT JOIN OBLIGPIF OBS ON OBS.CODOBLIGPIF = NC1.CODOBLIGSTINGATOR
    LEFT JOIN STINGERE STG ON STG.CODSTINSPIF = OB.CODOBLIGPIF AND STG.CODSTINGATORPIF = OBS.CODOBLIGPIF
    LEFT JOIN GENERAL GS ON OBS.CODGENERAL = GS.CODGENERAL
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = GS.CODDOC
    LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR AND GS.TIPDOC = T.Tipdoc
    LEFT JOIN NARTOBJ O ON O.CodObiect = I1.CodObiect
    LEFT JOIN NPART P ON P.CODPART = NC.CODPART
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = NC.SUBUNITATEA
    LEFT JOIN NCONT C ON C.CODCONT = NC.CODCONTT
    LEFT JOIN NCONT CASOC ON CASOC.CODCONT = PKG_LIST_BASE_UTILS.iCont_CodCont(OB.icont, OB.codpart, i.an*12+i.luna, OB.semnificatie)
    LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(G.MONEDA, 0)
    LEFT JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
    LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
    left join nclasedisc clsdisc on clsdisc.codclasedisc = nc1.codclasedisc &apos;||
    gSuplJoins||&apos;
  WHERE NC.TIPDOC = &apos;||sTipNC||
    sFiltruNC||&apos;
    AND NC1.TipOper = &apos;&apos;T&apos;&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;);


  IF sTipNC = 58
  THEN
    sSelectT := sSelectT||&apos;
    AND G.semnificatie &lt;&gt; 240 and G.semnificatie &lt;&gt; 500 and G.semnificatie &lt;&gt; 211 and G.semnificatie &lt;&gt; 210&apos;;
  ELSE
    sSelectT := sSelectT||&apos;
    AND G.semnificatie &lt;&gt; 140 and G.semnificatie &lt;&gt; 600 and G.semnificatie &lt;&gt; 130&apos;;
  END IF;

  sSelectC :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
     NCDATAI, NCDATAS, TIPOPER, DOC,
     PART, ART, SUBUNITATEA, CONT, MONEDA, LOCATIE,
     CURS,
     VAL,
     VALLEI,
     DISCOUNT,
     CANT,
     PRET,
     PROCDISC &apos;||gUserFields||&apos;)
  WITH CumulCant AS (
    SELECT
      nc.codncredit, i1.codobiect, c1.codcontract1,
      sum(i1.cant * i1.pu - CASE WHEN i.tipdoc IN (3, 16, 21) THEN i1.tva ELSE 0 END)/sum(i1.cant) pretmediu,
      sum(i1.cant) totalcant
    FROM NOTECREDIT NC
      INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
      INNER JOIN &apos;||sTable1||&apos; I1 ON i1.&apos;||sCamp1||&apos; = NC1.Coddoc
      INNER JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = i1.&apos;||sCamp||&apos; AND I.TipDoc = NC1.TipDoc
      LEFT JOIN contract2 c2 ON c2.codcontract2 = nc.codcontract2
      LEFT JOIN contract1 c1 on c1.codcontract = c2.codcontract AND c1.codobiect = i1.codobiect
    WHERE nc.tipdoc = &apos;||sTipNC||
      sFiltruNC||&apos;
      AND nc1.tipoper = &apos;&apos;C&apos;&apos;
    GROUP BY nc.codncredit, i1.codobiect, c1.codcontract1
  )
  SELECT
    nc.datastart, nc.datastop, &apos;&apos;CANTITATE&apos;&apos;,  i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    p.den_part, o.denumire, s.den_subunit, c.simbol, m.simbol, a.obs,
    DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    I1.cant * I1.PU,
    I1.cant * I1.PU * DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    COALESCE(NC1.VALOARE,0) - COALESCE(NC1.VALOAREOLD,0),
    i1.cant, i1.pu,
    100 * CASE WHEN i1.cant = 0 THEN 1 WHEN i1.pu = 0 THEN 1 ELSE NC1.Valoare/(I1.cant * I1.PU * DECODE(NVL(G.CURS, 0), 0, 1, G.CURS)) END &apos;||gUserAlias||&apos;
  FROM NOTECREDIT NC
    INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
    LEFT JOIN &apos;||sTable1||&apos; I1 ON i1.&apos;||sCamp1||&apos; = NC1.Coddoc
    LEFT JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = i1.&apos;||sCamp||&apos; AND I.TipDoc = NC1.TipDoc
    LEFT JOIN CumulCant CC ON CC.CODNCREDIT = NC.CODNCREDIT AND CC.CODOBIECt = I1.CODOBIECT
    LEFT JOIN NARTOBJ O ON O.CodObiect = I1.CodObiect
    LEFT JOIN NCONT C ON C.CODCONT = NC.CODCONTC
    LEFT JOIN NCONT CASOC ON CASOC.CODCONT = 0
    LEFT JOIN NPART P ON P.CODPART = NC.CODPART
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = NC.SUBUNITATEA
    LEFT JOIN GENERAL G ON G.CODDOC = I.&apos;||sCamp||&apos; AND G.TipDoc = I.TipDoc
    LEFT JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
    LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
    LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
    left join nclasedisc clsdisc on clsdisc.codclasedisc = nc1.codclasedisc &apos;||
    gSuplJoins||&apos;
  WHERE NC.TIPDOC = &apos;||sTipNC||
    sFiltruNC||&apos;
    AND NC1.TipOper = &apos;&apos;C&apos;&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;);

  IF sTipNC = 58
  THEN
    sSelectC := sSelectC||&apos;
    AND g.semnificatie not in (500, 240, 211, 100, 140, 400)&apos;;
  ELSE
    sSelectC := sSelectC||&apos;
    AND g.semnificatie not in (500, 111, 200, 140, 300)&apos;;
  END IF;

  sSelectP :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
     NCDATAI, NCDATAS, TIPOPER, DOC,
     PART, ART, SUBUNITATEA, CONT, MONEDA, LOCATIE,
     CURS,
     VAL,
     VALLEI,
     DISCOUNT,
     CONTASOC, TERMEN,
     DOCPLATA,
     VALPLATA,
     ZILEPLATA &apos;||gUserFields||&apos;)
  SELECT
    nc.datastart, nc.datastop, &apos;&apos;PENALIZARI&apos;&apos;,  i.prefixdoc||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    p.den_part, o.denumire, s.den_subunit, c.simbol, m.simbol, a.obs,
    DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    OB.VALOARE,
    OB.VALOARE * DECODE(NVL(G.CURS, 0), 0, 1, G.CURS),
    COALESCE(NC1.VALOARE,0) - COALESCE(NC1.VALOAREOLD,0),
    CASOC.SIMBOL, OB.TERMEN,
    T1.DOC||T1.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(T1.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;),
    STG.VALOARE,
    T1.DATADOC - I.DATADOC &apos;||gUserAlias||&apos;
  FROM NOTECREDIT NC
    INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NC.CODNCREDIT
    LEFT JOIN &apos;||sTable ||&apos; I ON i.&apos;||sCamp||&apos; = NC1.Coddoc AND I.TipDoc = NC1.TipDoc
    LEFT JOIN GENERAL G ON G.CODDOC = NC1.Coddoc AND G.TipDoc = NC1.TipDoc
    LEFT JOIN OBLIGPIF OB ON OB.CODOBLIGPIF = NC1.CODOBLIGSTINS
    LEFT JOIN OBLIGPIF OBS ON OBS.CODOBLIGPIF = NC1.CODOBLIGSTINGATOR
    LEFT JOIN STINGERE STG ON STG.CODSTINSPIF = OB.CODOBLIGPIF AND STG.CODSTINGATORPIF = OBS.CODOBLIGPIF
    LEFT JOIN GENERAL GS ON OBS.CODGENERAL = GS.CODGENERAL
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = GS.CODDOC
    LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR AND GS.TIPDOC = T.Tipdoc
    LEFT JOIN NARTOBJ O ON O.CodObiect = 0
    LEFT JOIN NPART P ON P.CODPART = NC.CODPART
    LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = NC.SUBUNITATEA
    LEFT JOIN NCONT C ON C.CODCONT = NC.CODCONTP
    LEFT JOIN NCONT CASOC ON CASOC.CODCONT = PKG_LIST_BASE_UTILS.iCont_CodCont(OB.icont, OB.codpart, i.an*12+i.luna, OB.semnificatie)
    LEFT JOIN NMONEDE M ON M.CODMONEDA = NVL(G.MONEDA, 0)
    LEFT JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
    LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
    left join nclasedisc clsdisc on clsdisc.codclasedisc = nc1.codclasedisc &apos;||
    gSuplJoins||&apos;
  WHERE NC.TIPDOC = &apos;||sTipNC||
    sFiltruNC||&apos;
    AND NC1.TipOper = &apos;&apos;P&apos;&apos; &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;);

  LIST_EXECUTE_IMMEDIATE(sSelectv, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sselectt, aListID, aListVer);
  EXECUTE IMMEDIATE &apos;DELETE FROM &apos;|| tmpName ||&apos; WHERE NVL(discount, 0) = 0 AND TIPOPER = &apos;&apos;TERMEN&apos;&apos; &apos;;
  LIST_EXECUTE_IMMEDIATE(sSelectc, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sSelectp, aListID, aListVer);

  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_NOTECREDIT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NOTECREDITT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7A4CE7CF20075D1BBDA2A92D07EE98BE1F60122</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_NOTECREDITT is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  pCodNoteCredit NUMBER(20);

PROCEDURE setParams (vCodNoteCredit IN NUMBER) IS
BEGIN
  pCodNoteCredit := vCodNoteCredit;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      nc.nrdoc,
      nc.datastart,
      nc.datastop,
      nc.obs,
      nc.seriadoc,
      TO_CHAR(nc.curs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) curs,
      case when nc.trimestriala = 1 then &apos;DA&apos; else &apos;NU&apos; end trimestriala,
      case when nc.inchisa = 1 then &apos;DA&apos; else &apos;NU&apos; end inchisa,
      p.den_part
    FROM NOTECREDIT NC
         LEFT JOIN NPART P ON NC.CODPART = P.CODPART
         LEFT JOIN NMONEDE MON ON MON.CODMONEDA = NC.CODMONEDA
    WHERE nc.CodNCredit = pCodNoteCredit
  ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document - numar&apos;, v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document - data start&apos;, v_rec.datastart);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document - data stop&apos;, v_rec.datastop);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Document - serie&apos;, v_rec.seriadoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Trimestriala&apos;, v_rec.trimestriala);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INCHISA&apos;, v_rec.inchisa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;, v_rec.den_part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Curs&apos;, v_rec.curs);
    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(10000);
sInsert1  VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    Articol,
    Doc,
    Moneda,
    Termen,
    Sediu,
    Curs,
    ValDoc,
    ValLei,
    ValPlata,
    DocPlata,
    ZilePlata,
    Discount,
    ValoareOld,
    Valoare,
    Obs,
    Den_ClaseDisc,
    Previzionat,
    ProcTVA &apos;||gUserFields||&apos;)
  SELECT
    tmp.articol,
    tmp.doc,
    tmp.moneda,
    tmp.termen,
    tmp.sediu,
    tmp.curs,
    tmp.valdoc,
    tmp.vallei,
    tmp.valplata,
    tmp.docplata,
    tmp.zileplata,
    tmp.discount,
    tmp.valoareold,
    tmp.valoare,
    tmp.obs,
    cls.den_clasedisc,
    tmp.previzionat,
    tmp.proctva &apos;||gUserAlias||&apos;
  FROM tmp_notecreditt tmp
       left join nclasedisc cls on cls.codclasedisc = tmp.codclasedisc &apos;||gSuplJoins||&apos;
  WHERE tmp.CodNCredit = &apos;||pCodNoteCredit;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  PROCESSPARAMS;

  COMMIT;
END;

end PKG_LIST_BASE_NOTECREDITT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0F047A4553A017FB1B64B863535A9188FB3E828</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_np IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);


PROCEDURE processlist(tmpTable IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(32000);
  sFiltru VARCHAR2(1500);
BEGIN
  gSuplCols := &apos;nartobj nobj, num1 num1, nart nart, ngest ng, nartamb aa, formatii f, comanda c, nclasea nca, nclaseg ncg, nclasea ca1, nclasea ca2, nclasea ca3, nclasea ca4, ncont cimpl,NARTOBJ OBJGENK,&apos;||
               &apos;ncont contp, comanda1 ci1, comanda1 cc1, comanda cc,LANSARE LANS,prodcomp pc,intrari i,intrari1 i1,nirstoc ns&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  delete from tmp_manevra_liste where filtru = &apos;CODNIRSTOC&apos;;
  delete from tmp_manevra_serii;

  IF PKG_LIST_SELECTPER.DataIni = PKG_LIST_SELECTPER.DataFin THEN
    sFiltru := &apos;
      AND i.datadoc = TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sFiltru := &apos;
      AND i.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

	IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
	  sFiltru := sFiltru || &apos;
      AND I1.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
	END IF;

	IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
	  sFiltru := sFiltru || &apos;
      AND I.CODGESTPROD IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
	END IF;

	sInsert :=
  &apos;INSERT INTO &apos;||TMPTABLE||&apos; (
    NAV_CODDOC,NAV_TIPDOC,DOCUMENT,PREFIXDOC,NRDOC,DATADOC,DENUMIRE,CANT,PU,UM,CLASA_ART,GEST,CLASA_GEST,
    D1, D2, D3, SERII, SEROBS, SCHIMB, FORMATIE, CMD_INTERNA, UMTRANSF, COEFTRANSF, PRETIMP, MONIMP, ANULAT, OPERAT, OPERATOR, ContPredare, Rest,
    BC_NrDoc, BC_DataDoc, DEZ_INCHIS, BC_NrDocIntr, BC_DataDocIntr &apos;||gUserFields||&apos;)
  WITH
    CA AS (
      SELECT x.cod CODCLASEA, c.den_clasea, c.simbol, c.prefix, c.nranalitice, c.codparinte, 
             c.VERLISTSUPLFACT, c.VERLISTSUPLTOALL, c.CODIDENT, c.VERLISTSUPLAVIZ, c.DISCOFE,
             Row_Number() OVER (PARTITION BY x.COD ORDER BY x.nivel) nivel
      FROM(
        SELECT connect_by_root codclasea cod, codclasea, nivel
        FROM nclasea
        START WITH Coalesce(codparinte,0) &lt;&gt; 0
        CONNECT BY NOCYCLE PRIOR codparinte = codclasea
        ) x INNER JOIN nclasea c ON c.codclasea = x.codclasea
      UNION ALL
      SELECT c.codclasea cod, c.den_clasea, c.simbol, c.prefix, c.nranalitice, c.codparinte, 
             c.VERLISTSUPLFACT, c.VERLISTSUPLTOALL, c.CODIDENT, c.VERLISTSUPLAVIZ, c.DISCOFE,
             c.nivel
      FROM nclasea c
      WHERE Coalesce(codparinte,0) = 0
    ),
    IG AS (
      SELECT
        ns.codnirstoc, i.codintr, i1.codintr1, ns.d1, ns.d2, ns.d3,
        SUM(COALESCE(-l1.cant,nser.cantnir*DECODE(ns.cantnir,0,1,NVL(ns.cantfurn,0)/ns.cantnir),ns.cantfurn) ) cant,
        SUM(COALESCE(-l1.cantum1, nser.cantum1,ns.cantum1)) cantum1,
        SUM(COALESCE(-l1.cantum2, nser.cantum2,ns.cantum2)) cantum2,
        DECODE(MAX(NVL(ns.tipserie,0)),1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
        CASE MAX(NVL(ns.tipserie,0))
          WHEN 1 THEN vc2_nt_to_string(CAST(collect(s.serie ORDER BY s.serie) AS vc2_nt))
          WHEN 2 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||NVL(l1.cant,nser.cantnir)||&apos;&apos;#~)&apos;&apos; ORDER BY s.serie) AS vc2_nt))
          ELSE NULL
        END SERII,
        vc2_nt_to_string(CAST(collect(nser.obs ORDER BY s.serie) AS vc2_nt)) SEROBS
      FROM intrari i
        INNER JOIN intrari1 i1   ON i1.codintr   = i.codintr
        LEFT  JOIN livr1    l1   ON l1.codintr1  = i1.codintr1
        LEFT  JOIN nirstoc  ns   ON ns.codobiect = i1.codobiect 
                                    AND (((l1.codlivr1 IS NOT NULL) AND (ns.codnirstoc = l1.codnirstoc)) OR
                                         ((l1.codlivr1 IS     NULL) AND (ns.codintr1   = i1.codintr1)) )
        LEFT  JOIN nir      n    ON n.codintr    = i.codintr AND n.codnir = ns.codnir
        LEFT  JOIN nirser   nser ON (((l1.codlivr1 IS NOT NULL) AND (nser.codnirser  = l1.codnirser)) OR
                                     ((l1.codlivr1 IS     NULL) AND (nser.codnirstoc = ns.codnirstoc)) )
        LEFT  JOIN nserii   s    on s.codserie   = nser.codserie
      WHERE i.tipdoc = 7 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sFiltru||&apos;
      GROUP BY i.codintr, i1.codintr1, ns.d1, ns.d2, ns.d3, ns.codnirstoc )
  SELECT
    i.codintr,
    i.tipdoc,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) AS document,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END,
    i.nrdoc,
    i.datadoc,
    nobj.denumire,
    ig.cant/num1.paritate,
    nvl(i1.pu,0)*num1.paritate,
    num1.den_um1,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), nvl(ng.den_gest,&apos;&apos;-&apos;&apos;), nvl(ncg.den_claseg,&apos;&apos;-&apos;&apos;),
    ig.D1,
    ig.D2,
    ig.D3,
    ig.SERII,
    ig.SEROBS,
    i.schimb,
    f.den_formatie,
    c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc,
    case
      when num.tipum = 1 then &apos;&apos;Kg&apos;&apos;
      when num.tipum = 2 then &apos;&apos;Cm3&apos;&apos;
      when num.tipum = 3 then &apos;&apos;M2&apos;&apos;
      when num.tipum = 4 then &apos;&apos;M&apos;&apos;
      when num.tipum = 5 then &apos;&apos;Buc&apos;&apos;
    end,
    num.coef,
    PM.Lei,
    MON.SIMBOL,
    case when i.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    case when i.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    UT.NUME,
    CONTP.Simbol,
    cp.rest,
    DEZ.BC_NrDoc, DEZ.BC_DataDoc, case when dez.inchisa = 0 then &apos;&apos;NU&apos;&apos; else &apos;&apos;DA&apos;&apos; end DEZ_INCHIS, DEZ.BC_NrDocIntr, DEZ.BC_DataDocIntr
    &apos;||gUserAlias||&apos;
  FROM ig
    INNER JOIN intrari        i       ON i.codintr        = ig.codintr
    INNER JOIN intrari1       i1      ON i1.codintr1      = ig.codintr1
    INNER JOIN nartobj        nobj    ON i1.codobiect     = nobj.codobiect
    INNER JOIN nart                   ON nobj.codarticol  = nart.codarticol
    INNER JOIN num1                   ON i1.umsec         = num1.codum1
    INNER JOIN num                    ON num1.codum       = num.codum
    INNER JOIN NIRSTOC        NS      ON NS.CODINTR1      = I1.CODINTR1 and ns.codnirstoc = ig.codnirstoc
    INNER JOIN IOART1         IO1     ON IO1.CODIOART1    = PKG_CONFIGART.GETCODCARACTLUNA(NS.CODIOART, I.AN, I.LUNA)
    INNER JOIN NCONT          CONTP   ON CONTP.CODCONT    = IO1.CONT
    LEFT  JOIN NECHIV         EKGEN   ON EKGEN.CODOBIECT  = NOBJ.CODOBIECT AND EKGEN.GENERIC = 1
    LEFT  JOIN NARTOBJ        OBJGENK ON EKGEN.CODOBIECT  = OBJGENK.CODOBIECT
    LEFT  JOIN nclasea        nca     ON nart.clasa       = nca.codclasea
    LEFT  JOIN ngest          ng      ON ng.codgest       = i.codgestprod
    LEFT  JOIN nclaseg        ncg     ON ncg.codclaseg    = ng.codclasa
    LEFT  JOIN nartamb        aa      ON aa.codobiect     = i1.codobiect AND aa.umsec = i1.umsec
    LEFT  JOIN formatii       f       ON f.codformatie    = i.codformatie
    LEFT  JOIN intrprodlink   il      ON il.codintr1      = i1.codintr1 and il.codliniecomanda is not NULL
    LEFT  JOIN cmdprodmat     cp      ON CP.Codcmdprodmat = il.CODLINIECOMANDA
    LEFT  JOIN comanda1       cl1     ON cl1.codcomanda1  = CP.codcomanda1
    LEFT  JOIN comanda1       ci1     ON ci1.codcomanda1  = i1.codcmdint1
    left  join prodcomp       pc      on ci1.codreteta    = pc.codprodcomp
    LEFT  JOIN comanda        c       ON c.codcomanda     = nvl(cl1.codcomanda,ci1.codcomanda)
    LEFT  JOIN COMANDA1       CC1     ON CC1.CODCOMANDA1  = PKG_COMANDA.DinCmdCli(CI1.CodComanda1)
    LEFT  JOIN COMANDA        CC      ON CC.CODCOMANDA    = CC1.CODCOMANDA
    LEFT  JOIN ca             ca1     ON ca1.nivel        = 1 AND ca1.codclasea = nca.codclasea
    LEFT  JOIN ca             ca2     ON ca2.nivel        = 2 AND ca2.codclasea = nca.codclasea
    LEFT  JOIN ca             ca3     ON ca3.nivel        = 3 AND ca3.codclasea = nca.codclasea
    LEFT  JOIN ca             ca4     ON ca4.nivel        = 4 AND ca4.codclasea = nca.codclasea
    LEFT  JOIN pretm          pm      ON nobj.codobiect   = pm.codobiect AND pm.implicit = 1 AND pm.subunitatea = i.subunitatea
    LEFT  JOIN nmonede        mon     ON mon.codmoneda    = pm.moneda
    LEFT  JOIN nartimplicite  nai     ON nai.codarticol   = nart.codarticol AND nai.codsubunit = i.subunitatea
    LEFT  JOIN nartobjimp     noi     ON noi.codobiect    = nobj.codobiect AND noi.codsubunit = i.subunitatea
    LEFT  JOIN ioart1         ioa1    ON ioa1.codioart    = case when coalesce(noi.contimplicit,0) = 0 then nai.contimplicit else coalesce(noi.contimplicit,0) end
                                         AND (i.An*12+i.Luna) BETWEEN ioa1.ALStart and ioa1.ALStop
    LEFT  JOIN ncont          cimpl   ON cimpl.codcont    = DECODE(nart.tiparticol,0,ioa1.cont,nart.contserviciu)
    LEFT  JOIN TMP_UTILIZATOR UT      ON I.USERID         = UT.CODUTILIZATOR
    LEFT  JOIN LANSARE1       LANS1   ON LANS1.CODCMD1    = CI1.CODCOMANDA1
    LEFT  JOIN LANSARE        LANS    ON LANS1.CODLANSARE = LANS.CODLANSARE
    LEFT  JOIN (select distinct ies.nrdoc BC_NrDoc, ies.datadoc BC_DataDoc, nvl(dz.inchisa,0) inchisa, int.nrdoc BC_NrDocIntr, int.datadoc BC_DataDocIntr,
                       i.codintr
                from intrari i
                     inner join intrari1      i1   on i1.codintr      = i.codintr 
                     inner join dezasamblari1 dz1  on dz1.codintrlink = i.codintr
                     left  join dezasamblari  dz   on dz.codlivr1     = dz1.codlivr1
                     left  join livr1         l1   on l1.codlivr1     = dz.codlivr1
                     left  join livr          l    on l.codlivr       = l1.codlivr
                     left  join iesiri1       ies1 on ies1.codies1    = l1.codies1
                     left  join iesiri        ies  on ies.codies      = l.codies and ies.codies = ies1.codies
                     left  join nirstoc1      ns1  on dz.codnirstoc   = ns1.codnirstoc
                     left  join nirstoc       nso  on nso.codnirstoc  = ns1.codnirstocorig
                     left  join intrari1      int1 on nso.codintr1    = int1.codintr1
                     left  join intrari       int  on int.codintr     = int1.codintr
                where i.tipdoc = 7 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||sFiltru||&apos;
               ) DEZ on DEZ.codintr = i.codintr &apos;||
    gSuplJoins||&apos;
  &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  -- BAG SI RETURURILE
  sInsert :=
  &apos;INSERT INTO &apos;||TMPTABLE||&apos; (
    NAV_CODDOC,NAV_TIPDOC,DOCUMENT,PREFIXDOC,NRDOC,DATADOC,DENUMIRE,CANT,PU,UM,CLASA_ART,GEST,CLASA_GEST,
    D1, D2, D3, SERII, SEROBS, SCHIMB, FORMATIE, CMD_INTERNA, UMTRANSF, COEFTRANSF, PRETIMP, MONIMP, ANULAT, OPERAT, OPERATOR, ContPredare, Rest &apos;||gUserFields||&apos;)
  WITH
    CA AS (
      SELECT c.codca, c.codclasea, c.den_clasea, c.prefix, c.nivel, c.nranalitice, c.codparinte, c.verlistsuplfact, c.verlistsupltoall,
        CASE WHEN cp.simbol IS NULL THEN c.simbol ELSE SubStr(c.simbol,Length(cp.simbol)+2) END SIMBOL,
        c.CODIDENT, c.VERLISTSUPLAVIZ, c.DISCOFE
      FROM(
        SELECT
          connect_by_root codclasea codca,
          codclasea, den_clasea, prefix, nivel, nranalitice, codparinte, verlistsuplfact, verlistsupltoall, simbol,
          CODIDENT, VERLISTSUPLAVIZ, DISCOFE
        FROM nclasea
        CONNECT BY NOCYCLE PRIOR codparinte = codclasea
      ) c LEFT JOIN nclasea cp ON cp.codclasea = c.codparinte
    ),
    IG AS (
      SELECT
        ns.codnirstoc, i.codintr, i1.codintr1, ns.d1, ns.d2, ns.d3, l1.codlivr1,
        COALESCE(-l1.cant,nser.cantnir*DECODE(ns.cantnir,0,1,NVL(ns.cantfurn,0)/ns.cantnir),ns.cantfurn) cant,
        COALESCE(-l1.cantum1, nser.cantum1,ns.cantum1) cantum1,
        COALESCE(-l1.cantum2, nser.cantum2,ns.cantum2) cantum2,
        DECODE(NVL(ns.tipserie,0),1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;,&apos;&apos;fara serie&apos;&apos;) tipserie,
        CASE NVL(ns.tipserie,0)
          WHEN 1 THEN s.serie
          WHEN 2 THEN s.serie
          ELSE NULL
        END SERII,
        nser.obs SEROBS,
        ns.pret - nvl(ns.adaos,0) pret
      FROM intrari i
        INNER JOIN intrari1 i1   ON i1.codintr   = i.codintr
        LEFT  JOIN livr1    l1   ON l1.codintr1  = i1.codintr1
        LEFT  JOIN nirstoc  ns   ON ns.codobiect = i1.codobiect AND
          (((l1.codlivr1 IS NOT NULL) AND (ns.codnirstoc = l1.codnirstoc)) OR
          ((l1.codlivr1 IS     NULL) AND (ns.codintr1 = i1.codintr1)) )
        LEFT  JOIN nir      n    ON n.codintr    = i.codintr AND n.codnir = ns.codnir
        LEFT  JOIN nirser   nser ON
          (((l1.codlivr1 IS NOT NULL) AND (nser.codnirser = l1.codnirser)) OR
          ((l1.codlivr1 IS     NULL) AND (nser.codnirstoc = ns.codnirstoc)) )
        LEFT  JOIN nserii   s    on s.codserie   = nser.codserie
      WHERE i.tipdoc = 7 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sFiltru||&apos;)
  SELECT
    i.codintr,
    i.tipdoc,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) AS document,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END,
    i.nrdoc,
    i.datadoc,
    nobj.denumire,
    ig.cant/num1.paritate,
    nvl(ig.pret,0)*num1.paritate,
    num1.den_um1,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), nvl(ng.den_gest,&apos;&apos;-&apos;&apos;), nvl(ncg.den_claseg,&apos;&apos;-&apos;&apos;),
    ig.D1,
    ig.D2,
    ig.D3,
    ig.SERII,
    ig.SEROBS,
    i.schimb,
    f.den_formatie,
    c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc,
    case
      when num.tipum = 1 then &apos;&apos;Kg&apos;&apos;
      when num.tipum = 2 then &apos;&apos;Cm3&apos;&apos;
      when num.tipum = 3 then &apos;&apos;M2&apos;&apos;
      when num.tipum = 4 then &apos;&apos;M&apos;&apos;
      when num.tipum = 5 then &apos;&apos;Buc&apos;&apos;
    end,
    num.coef,
    PM.Lei,
    MON.SIMBOL,
    case when i.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    case when i.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    UT.NUME,
    CONTP.Simbol,
    cp.rest
    &apos;||gUserAlias||&apos;
  FROM ig
    INNER JOIN intrari        i       ON i.codintr        = ig.codintr
    INNER JOIN intrari1       i1      ON i1.codintr1      = ig.codintr1
    INNER JOIN nartobj        nobj    ON i1.codobiect     = nobj.codobiect
    INNER JOIN nart                   ON nobj.codarticol  = nart.codarticol
    INNER JOIN num1                   ON i1.umsec         = num1.codum1
    INNER JOIN num                    ON num1.codum       = num.codum
    INNER JOIN LIVR                   ON I.CODINTR        = LIVR.CODINTR
    INNER JOIN LIVR1                  ON LIVR1.CODLIVR    = LIVR.CODLIVR AND LIVR1.CODINTR1 = I1.CODINTR1 and ig.codlivr1 = livr1.codlivr1
    INNER JOIN NIRSTOC        NS      ON NS.CODNIRSTOC    = LIVR1.CODNIRSTOC and ns.codnirstoc = ig.codnirstoc
    INNER JOIN IOART1         IO1     ON IO1.CODIOART1    = PKG_CONFIGART.GETCODCARACTLUNA(NS.CODIOART, I.AN, I.LUNA)
    INNER JOIN NCONT          CONTP   ON CONTP.CODCONT    = IO1.CONT
    LEFT  JOIN NECHIV         EKGEN   ON EKGEN.CODOBIECT  = NOBJ.CODOBIECT AND EKGEN.GENERIC = 1
    LEFT  JOIN NARTOBJ        OBJGENK ON EKGEN.CODOBIECT  = OBJGENK.CODOBIECT
    LEFT  JOIN nclasea        nca     ON nart.clasa       = nca.codclasea
    LEFT  JOIN ngest          ng      ON ng.codgest       = i.codgestprod
    LEFT  JOIN nclaseg        ncg     ON ncg.codclaseg    = ng.codclasa
    LEFT  JOIN nartamb        aa      ON aa.codobiect     = i1.codobiect AND aa.umsec = i1.umsec
    LEFT  JOIN formatii       f       ON f.codformatie    = i.codformatie
    LEFT  JOIN intrprodlink   il      ON il.codintr1      = i1.codintr1 and il.codliniecomanda is not NULL
    LEFT  JOIN cmdprodmat     cp      ON CP.Codcmdprodmat = il.CODLINIECOMANDA
    LEFT  JOIN comanda1       cl1     ON cl1.codcomanda1  = CP.codcomanda1
    LEFT  JOIN comanda1       ci1     ON ci1.codcomanda1  = i1.codcmdint1
    left  join prodcomp       pc      on ci1.codreteta    = pc.codprodcomp
    LEFT  JOIN comanda        c       ON c.codcomanda     = nvl(cl1.codcomanda,ci1.codcomanda)
    LEFT  JOIN COMANDA1       CC1     ON CC1.CODCOMANDA1  = PKG_COMANDA.DinCmdCli(CI1.CodComanda1)
    LEFT  JOIN COMANDA        CC      ON CC.CODCOMANDA    = CC1.CODCOMANDA
    LEFT  JOIN ca             ca1     ON ca1.nivel        = 1 AND ca1.codclasea = nca.codclasea
    LEFT  JOIN ca             ca2     ON ca2.nivel        = 2 AND ca2.codclasea = nca.codclasea
    LEFT  JOIN ca             ca3     ON ca3.nivel        = 3 AND ca3.codclasea = nca.codclasea
    LEFT  JOIN ca             ca4     ON ca4.nivel        = 4 AND ca4.codclasea = nca.codclasea
    LEFT  JOIN pretm          pm      ON nobj.codobiect   = pm.codobiect AND pm.implicit = 1 AND pm.subunitatea = i.subunitatea
    LEFT  JOIN nmonede        mon     ON mon.codmoneda    = pm.moneda
    LEFT  JOIN nartimplicite  nai     ON nai.codarticol   = nart.codarticol AND nai.codsubunit = i.subunitatea
    LEFT  JOIN nartobjimp     noi     ON noi.codobiect    = nobj.codobiect AND noi.codsubunit = i.subunitatea
    LEFT  JOIN ioart1         ioa1    ON ioa1.codioart    = case when coalesce(noi.contimplicit,0) = 0 then nai.contimplicit else coalesce(noi.contimplicit,0) end
                                         AND (i.An*12+i.Luna) BETWEEN ioa1.ALStart and ioa1.ALStop
    LEFT  JOIN ncont          cimpl   ON cimpl.codcont    = DECODE(nart.tiparticol,0,ioa1.cont,nart.contserviciu)
    LEFT  JOIN TMP_UTILIZATOR UT      ON I.USERID         = UT.CODUTILIZATOR
    LEFT  JOIN LANSARE1       LANS1   ON LANS1.CODCMD1    = CI1.CODCOMANDA1
    LEFT  JOIN LANSARE        LANS    ON LANS1.CODLANSARE = LANS.CODLANSARE&apos;||
    gSuplJoins||&apos;
  &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

	COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_NP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_NP_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D514527036A56536C209E957C22CE874B0FF060</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_np_m IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpTable IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(32000);
  sFiltru VARCHAR2(1500);
BEGIN

  gSuplCols := &apos;nartobj nobj, num1 num1, nart nart, ngest ng, nartamb aa, formatii f, comanda c, nclasea nca, nclaseg ncg, nclasea ca1, nclasea ca2, nclasea ca3, nclasea ca4, ncont cimpl,NARTOBJ OBJGENK,&apos;||
               &apos;utilaje2c ut2c,utilaje ut,utilaje2 ut2,ninterventiiauto interv,nartobj intervserv,nartobj utilajobj,NCLASEINT CLSINT&apos;;


  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  delete from tmp_manevra_liste where filtru = &apos;CODNIRSTOC&apos;;
  delete from tmp_manevra_serii;

  IF PKG_LIST_SELECTPER.DataIni = PKG_LIST_SELECTPER.DataFin THEN
    sFiltru := &apos;
      AND i.datadoc = TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sFiltru := &apos;
      AND i.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_SELECTPER.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
    sFiltru := sFiltru || &apos;
      AND I1.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  END IF;

  IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
    sFiltru := sFiltru || &apos;
      AND I.CODGESTPROD IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPTABLE||&apos; (
    NAV_CODDOC,NAV_TIPDOC,DOCUMENT,PREFIXDOC,NRDOC,DATADOC,DENUMIRE,CANT,PU,UM,CLASA_ART,GEST,CLASA_GEST,
    D1, D2, D3, SCHIMB, FORMATIE, CMD_INTERNA, UMTRANSF, COEFTRANSF, PRETIMP, MONIMP, ANULAT, OPERAT, OPERATOR, INTERVENTIE, UTILAJ, DATASTART, DATASTOP &apos;||gUserFields||&apos;)
  WITH
    CA AS (
      SELECT c.codca, c.codclasea, c.den_clasea, c.prefix, c.nivel, c.nranalitice, c.codparinte, c.verlistsuplfact, c.verlistsupltoall,
        CASE WHEN cp.simbol IS NULL THEN c.simbol ELSE SubStr(c.simbol,Length(cp.simbol)+2) END SIMBOL
      FROM(
        SELECT
          connect_by_root codclasea codca,
          codclasea, den_clasea, prefix, nivel, nranalitice, codparinte, verlistsuplfact, verlistsupltoall, simbol
        FROM nclasea
        CONNECT BY PRIOR codparinte = codclasea
      ) c LEFT JOIN nclasea cp ON cp.codclasea = c.codparinte
    ),
    IG AS (
      SELECT
        i.codintr, i1.codintr1, ns.d1, ns.d2, ns.d3,
        SUM(COALESCE(-l1.cant,nser.cantnir*DECODE(ns.cantnir,0,1,NVL(ns.cantfurn,0)/ns.cantnir),ns.cantfurn,i1.cant) ) cant,
        SUM(COALESCE(-l1.cantum1, nser.cantum1,ns.cantum1)) cantum1,
        SUM(COALESCE(-l1.cantum2, nser.cantum2,ns.cantum2)) cantum2
      FROM intrari i
        INNER JOIN intrari1 i1   ON i1.codintr    = i.codintr
        INNER JOIN COMANDA1 C1   ON I1.CODCMDINT1 = C1.CODCOMANDA1
        INNER JOIN COMANDA  C    ON C1.CODCOMANDA = C.CODCOMANDA
        LEFT  JOIN livr1    l1   ON l1.codintr1   = i1.codintr1
        LEFT  JOIN nirstoc  ns   ON ns.codobiect  = i1.codobiect AND
          (((l1.codlivr1 IS NOT NULL) AND (ns.codnirstoc = l1.codnirstoc)) OR
          ((l1.codlivr1 IS     NULL) AND (ns.codintr1 = i1.codintr1)) )
        LEFT  JOIN nir      n    ON n.codintr = i.codintr AND n.codnir = ns.codnir
        LEFT  JOIN nirser   nser ON
          (((l1.codlivr1 IS NOT NULL) AND (nser.codnirser = l1.codnirser)) OR
          ((l1.codlivr1 IS     NULL) AND (nser.codnirstoc = ns.codnirstoc)) )
        LEFT  JOIN nserii   s    on s.codserie = nser.codserie
      WHERE i.tipdoc = 7 AND C.TIPTRANZACTIE = 1 AND C.ANULAT = 0 AND C.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sFiltru||&apos;
      GROUP BY i.codintr, i1.codintr1, ns.d1, ns.d2, ns.d3 )
  SELECT
    i.codintr,
    i.tipdoc,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) AS document,
    case when I.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN I.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE I.PrefixDoc END,
    i.nrdoc,
    i.datadoc,
    nobj.denumire,
    ig.cant/num1.paritate,
    nvl(i1.pu,0)*num1.paritate,
    num1.den_um1,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), nvl(ng.den_gest,&apos;&apos;-&apos;&apos;), nvl(ncg.den_claseg,&apos;&apos;-&apos;&apos;),
    ig.D1,
    ig.D2,
    ig.D3,
    i.schimb,
    f.den_formatie,
    c.prefixdoc||c.nrdoc||&apos;&apos;/&apos;&apos;||c.datadoc,
    case
      when num.tipum = 1 then &apos;&apos;Kg&apos;&apos;
      when num.tipum = 2 then &apos;&apos;Cm3&apos;&apos;
      when num.tipum = 3 then &apos;&apos;M2&apos;&apos;
      when num.tipum = 4 then &apos;&apos;M&apos;&apos;
      when num.tipum = 5 then &apos;&apos;Buc&apos;&apos;
    end,
    num.coef,
    PM.Lei,
    MON.SIMBOL,
    case when i.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    case when i.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
    UT.NUME,
    intervserv.denumire,
    utilajobj.denumire,
    ut2c.datastart,
    ut2c.dataend
    &apos;||gUserAlias||&apos;
  FROM ig
    INNER JOIN intrari         i          ON i.codintr        = ig.codintr
    INNER JOIN intrari1        i1         ON i1.codintr1      = ig.codintr1
    INNER JOIN nartobj         nobj       ON i1.codobiect     = nobj.codobiect
    INNER JOIN nart                       ON nobj.codarticol  = nart.codarticol
    INNER JOIN num1                       ON i1.umsec         = num1.codum1
    INNER JOIN num                        ON num1.codum       = num.codum
    LEFT JOIN NECHIV           EKGEN      ON EKGEN.CODOBIECT  = NOBJ.CODOBIECT AND EKGEN.GENERIC = 1
    LEFT JOIN NARTOBJ          OBJGENK    ON EKGEN.CODOBIECT  = OBJGENK.CODOBIECT
    LEFT JOIN nclasea          nca        ON nart.clasa       = nca.codclasea
    LEFT JOIN ngest            ng         ON ng.codgest       = i.codgestprod
    LEFT JOIN nclaseg          ncg        ON ncg.codclaseg    = ng.codclasa
    LEFT JOIN nartamb          aa         ON aa.codobiect     = i1.codobiect AND aa.umsec = i1.umsec
    LEFT JOIN formatii         f          ON f.codformatie    = i.codformatie
    LEFT JOIN intrprodlink     il         ON il.codintr1      = i1.codintr1 and il.codliniecomanda is not NULL
    LEFT JOIN cmdprodmat       cp         ON CP.Codcmdprodmat = CODLINIECOMANDA
    LEFT JOIN comanda1         cl1        ON cl1.codcomanda1  = CP.codcomanda1
    LEFT JOIN comanda1         ci1        ON ci1.codcomanda1  = i1.codcmdint1
    LEFT JOIN comanda          c          ON c.codcomanda     = nvl(cl1.codcomanda,ci1.codcomanda)
    left join utilaje2c        ut2c       on ut2c.codcomanda1 = ci1.codcomanda1
    left join utilaje          ut         on ut2c.codutilaj   = ut.codutilaj
    left join utilaje2         ut2        on ut2.codutilaj2   = ut2c.codutilaj2
    left join ninterventiiauto interv     on interv.CODINTERVENTIIAUTO = ut2.interventie
    left join nartobj          intervserv on intervserv.codobiect      = interv.serviciu
    LEFT JOIN NCLASEINT        CLSINT     ON INTERV.CLASA              = CLSINT.CODCLASEINT
    left join nartobj          utilajobj  on utilajobj.codobiect       = ut.codobiect
    LEFT JOIN ca               ca1        ON ca1.nivel = 1 AND ca1.codca = nca.codclasea
    LEFT JOIN ca               ca2        ON ca2.nivel = 2 AND ca2.codca = nca.codclasea
    LEFT JOIN ca               ca3        ON ca3.nivel = 3 AND ca3.codca = nca.codclasea
    LEFT JOIN ca               ca4        ON ca4.nivel = 4 AND ca4.codca = nca.codclasea
    LEFT JOIN pretm            pm         ON nobj.codobiect = pm.codobiect AND pm.implicit = 1 AND pm.subunitatea = i.subunitatea
    LEFT JOIN nmonede          mon        ON mon.codmoneda  = pm.moneda
    LEFT JOIN nartimplicite    nai        ON nai.codarticol = nart.codarticol AND nai.codsubunit = i.subunitatea
    LEFT JOIN nartobjimp       noi        ON noi.codobiect  = nobj.codobiect AND noi.codsubunit = i.subunitatea
    LEFT JOIN ioart1           ioa1       ON ioa1.codioart  = case when coalesce(noi.contimplicit,0) = 0 then nai.contimplicit else coalesce(noi.contimplicit,0) end
                                             AND (i.An*12+i.Luna) BETWEEN ioa1.ALStart and ioa1.ALStop
    LEFT JOIN ncont            cimpl      ON cimpl.codcont  = DECODE(nart.tiparticol,0,ioa1.cont,nart.contserviciu)
    LEFT JOIN TMP_UTILIZATOR   UT         ON I.USERID       = UT.CODUTILIZATOR&apos;||
    gSuplJoins||&apos;
  &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_NP_M;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_OFEPROFORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E92E53A3A9DC83E69C7E4829AC95A614C2979108</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_OFEPROFORMA IS

  vCodDoc IESIRI.CODIES%TYPE;
  vNrDC   INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pListareDiscLangaTot  VARCHAR2(10);
  pListareLiniiDiscPart VARCHAR2(10);
  pListareUMAmbPretCant VARCHAR2(10);
  pBancaCursPUV         INTEGER;

PROCEDURE BAGA_DINAMIC_COLS IS
  vCursor  crs_cols  := get_cursor_coloane;
  vDen     VARCHAR2(30);
BEGIN
  DELETE tmp_dinamic_cols;

  LOOP
    FETCH vCursor INTO vDen;
    EXIT WHEN vCursor%NOTFOUND;
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+1,&apos;fm999&apos;), &apos;Cant.&apos;||vDen);
    INSERT INTO tmp_dinamic_cols(FieldName, Display) VALUES (&apos;D&apos;||to_char(vNrDC+2,&apos;fm999&apos;), &apos;Pret/&apos;||vDen);
    vNrDC := vNrDC + 2;
  END LOOP;
  CLOSE vCursor;

  COMMIT;

END;

PROCEDURE SETPARAMS(pCodDoc IN NUMBER)  IS
BEGIN
  vCodDoc := pCodDoc;
  pListareDiscLangaTot  := pkg_categconst.GetValConstanta(&apos;ListareDiscLangaTot&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareLiniiDiscPart := pkg_categconst.GetValConstanta(&apos;ListareLiniiDiscPart&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pListareUMAmbPretCant := pkg_categconst.GetValConstanta(&apos;ListareUMAmbPretCant&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
  pBancaCursPUV         := To_Number(pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru));

  vNrDC := 0;
  IF pListareUMAmbPretCant = &apos;1&apos; THEN
    BAGA_DINAMIC_COLS;
  END IF;
END;

FUNCTION get_cursor_coloane RETURN crs_cols IS
  crs crs_cols;
BEGIN
  OPEN crs FOR
    SELECT den_um1 || Decode(idxobj,1,NULL,&apos;(&apos;||idxobj||&apos;)&apos;) DEN
    FROM (
      SELECT Upper(U1.DEN_UM1) den_um1, Dense_Rank() OVER (PARTITION BY p1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
      FROM tmp_list_proforma1 p1
        INNER JOIN nartamb amb ON amb.codobiect = p1.codobiect
        INNER JOIN num1    u1  ON u1.codum1     = amb.umsec
    )
    GROUP BY den_um1, idxobj
    ORDER BY den_um1, idxobj;

  RETURN crs;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
  sCondDiscP    VARCHAR2(  100);
  sInsertDC     VARCHAR2(10000);
  sSelectDC     VARCHAR2(10000);
  sJoinDC       VARCHAR2(10000);
  sCurs         VARCHAR2(  100);
  vMoneda       INTEGER;
  sDataDoc      VARCHAR2(   10);

  SitV          VARCHAR2(2);
  aSitV         NUMBER(1);
  aBancaV       NUMBER(20);
  aMonedaV      NUMBER(20);

  vCantBuc      NUMBER;
  vCantCut      NUMBER;
  vGSpCut       NUMBER;
  vCantPal      NUMBER;

  vVal          NUMBER;
  vTva          NUMBER;
  vValDisc      NUMBER;
  vTvaDisc      NUMBER;
  vCurs         NUMBER;

  aModulCereale NUMBER :=  2;
BEGIN
  gSuplCols :=
    &apos;tmp_list_proforma1 p1, oferta o, oferta1 o1, nartobj nao, nartobj1 nao1, nart na, num1 um, num um1, num um2, nclasea c, nclaseas cs, npart prod, nartcli ac, nechiv e, grechiv gre,&apos;||
    &apos;nagenda nag, nlocalit nloc, ntari ntari, nartobjtrad ntrad&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,      &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,      &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_NARTATR_LST&apos;, &apos;TAA&apos;,  &apos;TAA.CODARTICOL = NA.CODARTICOL&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  
  IF pListareLiniiDiscPart &lt;&gt; 1 THEN
    sCondDiscP := &apos;
    AND NOT p1.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)&apos;;
  END IF;

  SELECT
    Nvl(o.Moneda,0), To_Char(o.DataOferta,&apos;dd.mm.yyyy&apos;),
    CASE WHEN UPPER(SubStr(trim(cf.codfiscal),1,2)) = &apos;RO&apos; AND pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.GETANLUCRU,pkg_globals.GETLUNALUCRU) = &apos;1&apos; THEN 1 ELSE 2 END
  INTO
    vMoneda, sDataDoc,
    aModulCereale
  FROM oferta o LEFT JOIN npartcodfisc cf ON cf.cod_codfiscal = o.codfiscal
  WHERE o.codoferta = vCodDoc;

  IF vMoneda = 0
  THEN sCurs := &apos;1&apos;;
  ELSE
    IF sCurs IS NULL
    THEN sCurs := To_Char(PKG_MONEDE.GETCURSMONEDA(vMoneda, pBancaCursPUV, sDataDoc),&apos;FM9999999999999D9999999&apos;, &apos;NLS_NUMERIC_CHARACTERS = &apos;&apos;.,&apos;&apos;&apos;);
    END IF;
  END IF;

  IF vNrDC &gt; 0 THEN
    FOR k IN 1..vNrDC LOOP
      sInsertDC := sInsertDC||&apos;, D&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    FOR k IN 1..vNrDC/2 LOOP
      sJoinDC   := sJoinDC   ||&apos;, Max(Decode(idx,&apos;||to_char(k,&apos;fm999&apos;)||&apos;,p)) p&apos;||to_char(k,&apos;fm999&apos;);
      sSelectDC := sSelectDC ||&apos;, p1.cant*p1.paritate/dc.p&apos;||to_char(k,&apos;fm999&apos;)||&apos;, p1.pu/p1.paritate*dc.p&apos;||to_char(k,&apos;fm999&apos;);
    END LOOP;

    sJoinDC := &apos;
    LEFT JOIN (
      SELECT codobiect&apos;||sJoinDC||&apos;
      FROM (
        SELECT codobiect, den_um1, idxobj, p, Dense_Rank() OVER (ORDER BY den_um1, idxobj) idx
        FROM (
          SELECT DISTINCT p1.CODOBIECT, Upper(U1.DEN_UM1) den_um1, u1.paritate p, Dense_Rank() OVER (PARTITION BY p1.CODOBIECT, Upper(U1.DEN_UM1) ORDER BY u1.paritate) idxobj
          FROM tmp_list_proforma1 p1
            INNER JOIN nartamb amb ON amb.codobiect = p1.codobiect
            INNER JOIN num1    u1  ON u1.codum1     = amb.umsec
        )
      ) GROUP BY codobiect
    ) DC ON dc.codobiect = p1.codobiect&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, OBSART, CANT, CodIntern,CodExtern,Producator,Masa,Volum,CodVamal,
    PRET, PU, PD, VAL, VALADAOS,
    PRET_LEI, PU_LEI, PD_LEI,
    VAL_LEI, VALADAOS_LEI,
    PROCADAOS,PROCDISC,
    PROCTVA,
    GARART, DenClasaA, SimbClasaA, UM1, CANT1, TipSerie,
    DiscAfis, ARTCli, CodExtCli,
    CodListat,
    DenClaseAS, IDX,
    Dim, Dim1, Dim2, Dim3,
    CantUMPrinc, CutiePar, CutieExt, CutieGSp, PaletPar &apos;||sInsertDC||gUserFields||&apos;)&apos;;

  -- liniile de pe iesiri
  sSelect := &apos;
  WITH UMCP AS (
    SELECT codoferta1, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,upar)) cutiepar, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,aext)) cutieext, Max(Decode(uext,&apos;&apos;CUTIE&apos;&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;&apos;PALET&apos;&apos;,upar)) paletpar
    FROM (
      SELECT
        o1.codoferta1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
        Dense_Rank() OVER (PARTITION BY o1.codoferta1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = o1.umsec THEN 0 ELSE u1.paritate END) idxobj
      FROM OFERTA1 O1
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = O1.CODOBIECT
        INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
      WHERE O1.CODOFERTA = &apos;||vCodDoc||&apos; AND Upper(U1.codextern) IN (&apos;&apos;CUTIE&apos;&apos;,&apos;&apos;PALET&apos;&apos;)
    )
    WHERE idxobj = 1
    GROUP BY codoferta1)
  SELECT
    p1.DenObiect, p1.denum, p1.obs, p1.cant, nao.codintern, nao.codextern, prod.den_part, nao.masa, nao.volum, nao.codvamal,
    p1.pretorig, p1.pu, p1.pretorig * p1.coefdiscmaj, p1.valoare, (p1.pu - p1.pretorig) * p1.cant,
    p1.pretorig*&apos;||sCurs||&apos;, p1.pu*&apos;||sCurs||&apos;, p1.pretorig * p1.coefdiscmaj*&apos;||sCurs||&apos;,
    p1.valoare*&apos;||sCurs||&apos;, (p1.pu - p1.pretorig) * p1.cant*&apos;||sCurs||&apos;,
    DECODE(p1.pretorig,0,0,(p1.pu - p1.pretorig)*100/p1.pretorig), p1.procdisc,
    p1.proctva,
    nao.lunigarantie, c.den_clasea, c.simbol, um1.den_um, p1.cantum1, decode(na.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;),
    Decode(nvl(p1.procdisc,0),0,&apos;&apos; &apos;&apos;,to_char(p1.procdisc)||&apos;&apos;%&apos;&apos;), NVL(ac.denumire,nao.denumire), NVL(ac.codextern, nao.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,nao.codextern,4,nao.codintern,5,nao.codvamal,6,nao.codplu,7,o1.codextofe),nao.codextern),
    cs.den_claseas, p1.indexlocal,
    decode(
      na.relatieum1,
       1,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / &apos;&apos;||o1.d1,
       2,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos;)&apos;&apos;,
       3,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; / (&apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos; x &apos;&apos;||o1.d3||&apos;&apos;)&apos;&apos;,
       4,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||o1.d1,
       5,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2,
       6,um1.den_um||&apos;&apos; = &apos;&apos;||num.den_um||&apos;&apos; x &apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos; x &apos;&apos;||o1.d3,
       7,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||o1.d1,
       8,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2,
       9,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; x &apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos; x &apos;&apos;||o1.d3,
      10,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / &apos;&apos;||o1.d1,
      11,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / (&apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos;)&apos;&apos;,
      12,num.den_um||&apos;&apos; = &apos;&apos;||um1.den_um||&apos;&apos; / (&apos;&apos;||o1.d1||&apos;&apos; x &apos;&apos;||o1.d2||&apos;&apos; x &apos;&apos;||o1.d3||&apos;&apos;)&apos;&apos;
    ),
    o1.d1, o1.d2, o1.d3,
    p1.cant cantumprinc, umcp.cutiepar, umcp.cutieext, umcp.cutiegsp, umcp.paletpar &apos;||sSelectDC||gUserAlias||&apos;
  FROM tmp_list_proforma1 p1
    LEFT JOIN oferta1     o1    ON o1.codoferta1   = p1.codsursa
    LEFT JOIN oferta      o     ON o.codoferta     = o1.codoferta
    LEFT JOIN nartobj     nao   ON nao.codobiect   = p1.codobiect
    LEFT JOIN nart        na    ON na.codarticol   = nao.codarticol
    LEFT JOIN num1        um    ON um.codum1       = p1.umsec
    LEFT JOIN num               ON num.codum       = na.um
    LEFT JOIN num         um1   ON um1.codum       = na.um1
    LEFT JOIN num         um2   ON um2.codum       = na.um2
    LEFT JOIN nclasea     c     ON c.codclasea     = na.clasa
    LEFT JOIN nclaseas    cs    ON cs.codclaseas   = na.clasastatist
    LEFT JOIN npart       prod  ON prod.codpart    = nao.codproducator
    LEFT JOIN nartcli     ac    ON ac.codobiect    = p1.codobiect AND ac.codpart = o.partener
    LEFT JOIN nechiv      e     ON e.codobiect     = p1.codobiect
    LEFT JOIN grechiv     gre   ON gre.codgrechiv  = e.codgrupa
    LEFT JOIN umcp              ON umcp.codoferta1 = p1.codsursa
    LEFT JOIN nagenda     nag   ON nag.codagenda   = o.codlocatie
    LEFT JOIN nlocalit    nloc  ON nag.codlocalit  = nloc.codlocalit
    LEFT JOIN ntari             ON ntari.codtara   = nloc.codtara
    LEFT JOIN nartobjtrad ntrad ON ntrad.codlimba  = ntari.codlimba and ntrad.codobiect = nao.codobiect
    LEFT JOIN nartobj1    nao1  ON nao1.codobiect  = p1.codobiect AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN nao1.ALStart and nao1.ALStop &apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE 1=1  &apos;|| 
    sCondDiscP||&apos;
  ORDER BY p1.indexlocal&apos;;


  IF InStr(Upper(gSuplJoins),&apos;TMP_NARTATR_LST&apos;) &gt; 0 THEN
    pkg_globals.SetSeparator(&apos;;&apos;);
    PKG_LIST_BASE_UTILS.UMPLE_TMP_NARTATR_LST;
  END IF;

  PKG_GLOBALS.SetSeparator(&apos;, &apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;


  WITH UMCP AS (
    SELECT codoferta1, Max(Decode(uext,&apos;CUTIE&apos;,upar)) cutiepar, Max(Decode(uext,&apos;CUTIE&apos;,gsp)) cutiegsp, Max(Decode(uext,&apos;PALET&apos;,upar)) paletpar
    FROM (
      SELECT
        o1.codoferta1, amb.codextern aext, Upper(u1.codextern) uext, u1.paritate upar, amb.greutspecifica gsp,
        Dense_Rank() OVER (PARTITION BY o1.codoferta1, Upper(u1.codextern) ORDER BY CASE WHEN u1.codum1 = o1.umsec THEN 0 ELSE u1.paritate END) idxobj
      FROM oferta1 o1
        INNER JOIN NARTAMB AMB ON AMB.CODOBIECT = o1.CODOBIECT
        INNER JOIN NUM1    U1  ON U1.CODUM1     = AMB.UMSEC
      WHERE o1.CODoferta = vCodDoc AND Upper(U1.codextern) IN (&apos;CUTIE&apos;,&apos;PALET&apos;)
    )
    WHERE idxobj = 1
    GROUP BY codoferta1)
  SELECT NVL(CEIL(SUM(Nvl(p1.cant,0))),0), Nvl(CEIL(SUM(Nvl(p1.cant/UMCP.CutiePar,0))),0), Nvl(Round(SUM(Nvl(p1.cant*UMCP.CutieGSp/UMCP.CutiePar,0))),0), Nvl(CEIL(SUM(Nvl(p1.cant/UMCP.PaletPar,0))),0)
  INTO vCantBuc, vCantCut, vGSpCut, vCantPal
  FROM oferta1 o1
    LEFT JOIN tmp_list_proforma1 p1 ON p1.codsursa     = o1.codoferta1
    LEFT JOIN UMCP                  ON UMCP.codoferta1 = o1.codoferta1
  WHERE o1.codoferta = vCodDoc;

  SELECT
    Sum(CASE WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0       ELSE valoare END),
    Sum(CASE WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN 0       WHEN aModulCereale = 1 AND Trim(o.codd394) IS NOT NULL THEN 0 ELSE valoare * Nvl(t.proctva,0)/100 END),
    Sum(CASE WHEN tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN valoare ELSE valoare *(1+Nvl(t.procdisc/100,0)) END)
  INTO
    vVal,
    vTva,
    vValDisc
  FROM tmp_list_proforma1 t LEFT JOIN nartobj o ON o.codobiect = t.codobiect;

  vTvaDisc := CASE WHEN vVal = 0 OR vValDisc =0 OR vTva = 0 THEN 0 ELSE vValDisc * vTva / vVal END;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN SitV := &apos;DA&apos;;
  ELSE SitV := &apos;NU&apos;;
  END IF;

  FOR v_rec IN (
    SELECT
      O.TIPDOC, O.NRDOC, O.DATAOFERTA, O.SERIADOC, O.CODLOCATIE, O.NRI,
      O.AGENT, O.OBS, CODF.CODFISCAL, P.DEN_PART, P.CODEXTERN, P.CODSTATISTICBNR,
      Decode(P.PERSOANAFIZICA,1,NULL,P.REGCOM) REGCOM, P.PERSOANAFIZICA, P.CODPART, P.AUTORIZATIE, M.CODMONEDA, M.SIMBOL SIMBMONEDA, M.SSIMBOL SSIMBMONEDA, M.DEN_MONEDA, M.SDENUMIRE, O.USERID,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      --Decode(P.PERSOANAFIZICA,1,TR.SerieDoc,NULL) PFSerieDoc, Decode(P.PERSOANAFIZICA,1,TR.NrDoc,NULL) PFNrDoc,
      SLIVR.OBS SLivrObs, SLIVR.TELEFON SLivrTelefon, SLIVR.CODPOSTAL SLivrCodPostal, SLIVR.CODFISCAL SLivrCodFiscal, SLIVR.CODCLIENT SLivrCodClient, SLIVR.EMAIL SLIVREmail,
      GetAdresa(SLIVR.sector, SLIVR.strada, SLIVR.nr1, SLIVR.nr2, SLIVR.bloc, SLIVR.scara, SLIVR.etaj, SLIVR.apart, SLIVR.codpostal) SLivrAdresa,
      LLIVR.DEN_LOCALIT SLivrLocalit, JLIVR.SIMBAUTO SLivrSimbAuto, JLIVR.Den_Judet SLivrJudet, TLIVR.Den_Tara SLivrTara,
      SFACT.OBS SFACTObs, SFACT.TELEFON SFACTTelefon, SFACT.CODPOSTAL SFACTCodPostal, SFACT.CODFISCAL SFACTCodFiscal, SFACT.CODCLIENT SFACTCodClient, SFACT.EMAIL SFACTEmail,
      GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) SFACTAdresa,
      LFACT.DEN_LOCALIT SFACTLocalit, JFACT.SIMBAUTO SFACTSimbAuto, JFACT.Den_Judet SFACTJudet, TFACT.Den_Tara SFACTTara,
      SSOC.OBS SSOCObs, SSOC.TELEFON SSOCTelefon, SSOC.CODPOSTAL SSOCCodPostal, SSOC.CODFISCAL SSOCCodFiscal, SSOC.CODCLIENT SSOCCodClient, SSOC.EMAIL SSOCEmail,
      GetAdresa(SSOC.sector, SSOC.strada, SSOC.nr1, SSOC.nr2, SSOC.bloc, SSOC.scara, SSOC.etaj, SSOC.apart, SSOC.codpostal) SSOCAdresa,
      LSOC.DEN_LOCALIT SSOCLocalit, JSOC.SIMBAUTO SSOCSimbAuto, JSOC.Den_Judet SSOCJudet, TSOC.Den_Tara SSOCTara,
      B.CONTBANCA, B.SUCURSALA, BK.DENUMIRE DENBANCA, BK.SIMBOL SIMBBANCA,
      AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
      --DEL.DELegat DelNume, DEL.DOC DelDoc, DEL.NRdoc DelNrDoc, DEL.SERIedoc DelSerDoc, DEL.ELIBERAT DelElib, DEL.CNP DelCNP,
      --DEL.MIJLTRANSP DelMTransp, DEL.NRTRANSP DelNrTransp, DEL.DATADoc DelDataDoc,
      case when p.persoanafizica = 1 then p.den_part else PC.Nume||&apos; &apos;||PC.Prenume end PCNume,
      case when p.persoanafizica = 1 then slivr.telefon else PC.TELEFON end PCTel,
      case when p.persoanafizica = 1 then slivr.email else PC.EMAIL end PCEmail,
      CASE WHEN Nvl(aMonedaV,0) = 0 OR Nvl(aBancaV,0) = 0 THEN 1 ELSE PKG_LIST_BASE_UTILS.GETCURSREFERINTA(aMonedaV,aBancaV,O.dataoferta) END CursSitV,
      (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = Nvl(aMonedaV,0)) MonedaSitV,
      (SELECT DENUMIRE FROM NBANK WHERE CODBANK = Nvl(aBancaV,0)) BancaSitV
    FROM oferta o
      INNER JOIN NPART        P     ON P.CODPART        = O.PARTENER
      INNER JOIN NMONEDE      M     ON M.CODMONEDA      = NVL(O.MONEDA,0)
      LEFT  JOIN NPARTCODFISC CODF  ON CODF.COD_CODFISCAL = O.CODFISCAL
      LEFT  JOIN NPERS        U     ON U.LOGONNAME      = O.USERID
      LEFT  JOIN NAGENDA      SLIVR ON SLIVR.CODAGENDA  = O.CODLOCATIE AND SLIVR.CODPART = O.PARTENER
      LEFT  JOIN NLOCALIT     LLIVR ON LLIVR.CODLOCALIT = NVL(SLIVR.CODLOCALIT, 0)
      LEFT  JOIN NJUDET       JLIVR ON JLIVR.CODJUDET   = NVL(LLIVR.CODJUDET, 0)
      LEFT  JOIN NTARI        TLIVR ON TLIVR.CODTARA    = NVL(LLIVR.CODTARA, 0)
      LEFT  JOIN NAGENDA      SFACT ON SFACT.CODAGENDA  = CASE WHEN SLIVR.SediuSocial = 1 THEN SLIVR.CODCORESP WHEN SLIVR.SediuSocial IN (3,7) THEN SLIVR.CODAGENDA ELSE 0 END
      LEFT  JOIN NLOCALIT     LFACT ON LFACT.CODLOCALIT = NVL(SFACT.CODLOCALIT, 0)
      LEFT  JOIN NJUDET       JFACT ON JFACT.CODJUDET   = NVL(LFACT.CODJUDET, 0)
      LEFT  JOIN NTARI        TFACT ON TFACT.CODTARA    = NVL(LFACT.CODTARA, 0)
      LEFT  JOIN NAGENDA      SSOC  ON SSOC.CODPART     = O.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0
      LEFT  JOIN NLOCALIT     LSOC  ON LSOC.CODLOCALIT  = NVL(SSOC.CODLOCALIT, 0)
      LEFT  JOIN NJUDET       JSOC  ON JSOC.CODJUDET    = NVL(LSOC.CODJUDET, 0)
      LEFT  JOIN NTARI        TSOC  ON TSOC.CODTARA     = NVL(LSOC.CODTARA, 0)
      LEFT  JOIN NPARTB       B     ON B.CODPART        = P.CODPART AND B.IMPLICIT = 1
      LEFT  JOIN NBANK        BK    ON B.CODBANK        = BK.CODBANK
      LEFT  JOIN NPERS        AG    ON AG.CODPERS       = O.AGENT
      LEFT  JOIN NPERSCONTACT PC    ON PC.CodPart       = P.CodPart
    WHERE O.codoferta = vCodDoc
  ) LOOP
    --vCurs := v_rec.Curs;
    IF v_rec.codmoneda = 0 THEN
      vCurs := 1;
    ELSIF vCurs IS NULL THEN
      vCurs := Nvl(pkg_monede.getcursmoneda(v_rec.codmoneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), v_rec.DataOferta),1);
    END IF;

    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT DENUMIRE&apos;,                 v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODEXTERN&apos;,                v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT AUTORIZATIE&apos;,              v_rec.Autorizatie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CODFISCAL/CNP&apos;,            v_rec.CodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT REGISTRU COMERT&apos;,          v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT COD STATISTIC BNR&apos;,        v_rec.CodStatisticBNR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                   To_Char(v_rec.DataOferta,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR INREGISTRARE&apos;,     v_rec.NrI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL&apos;,                           TO_CHAR(vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE&apos;,                    NumarRO(Round(vVal,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LITERE ENG&apos;,                NumarUK(Round(vVal,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA&apos;,                    TO_CHAR(vVal+vTva,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA LITERE&apos;,             NumarRO(Round(vVal+vTva,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA LITERE ENG&apos;,         NumarUK(Round(vVal+vTva,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA&apos;,                       TO_CHAR(vTVA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE&apos;,                NumarRO(Round(vTVA,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA LITERE ENG&apos;,            NumarUK(Round(vTVA,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC&apos;,                   TO_CHAR(vValDisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC LITERE&apos;,            NumarRO(Round(vValDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC LITERE ENG&apos;,        NumarUK(Round(vValDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA&apos;,            TO_CHAR(vValDisc+vTvaDisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LITERE&apos;,     NumarRO(Round(vValDisc+vTvaDisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LITERE ENG&apos;, NumarUK(Round(vValDisc+vTvaDisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA&apos;,               TO_CHAR(vTVADisc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LITERE&apos;,        NumarRO(Round(vTVADisc,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LITERE ENG&apos;,    NumarUK(Round(vTVADisc,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA CURS&apos;,                     TO_CHAR(vCurs,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MONEDA&apos;,                          v_rec.Den_Moneda);
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI&apos;,                TO_CHAR(vVal*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE&apos;,      NumarRO(Round(vVal*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL VAL IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vVal*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI&apos;,             TO_CHAR((vVal+vTva)*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI LITERE&apos;,      NumarRO(Round((vVal+vTva)*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU TVA IN LEI LITERE ENG&apos;,  NumarUK(Round((vVal+vTva)*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI&apos;,                TO_CHAR(vTVA*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE&apos;,      NumarRO(Round(vTVA*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL TVA IN LEI SI LITERE ENG&apos;,  NumarUK(Round(vTVA*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI&apos;,           TO_CHAR(vValDisc*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI LITERE&apos;,    NumarRO(Round(vValDisc*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC VAL LEI ENG&apos;,       NumarUK(Round(vValDisc*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI&apos;,        TO_CHAR((vValDisc+vTvaDisc)*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI LITERE&apos;, NumarRO(Round((vValDisc+vTvaDisc)*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC CU TVA LEI ENG&apos;,    NumarUK(Round((vValDisc+vTvaDisc)*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI&apos;,           TO_CHAR(vTVADisc*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI LITERE&apos;,    NumarRO(Round(vTVADisc*vCurs,2), v_rec.Den_Moneda, &apos;&apos;, v_rec.SDenumire, &apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CU DISC TVA LEI ENG&apos;,       NumarUK(Round(vTVADisc*vCurs,2), v_rec.SIMBMONEDA, v_rec.SSIMBMONEDA));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL FACT.VALUTA IN LEI&apos;,        TO_CHAR(vVal*vCurs,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN BUCATI&apos;,       TO_CHAR(vCantBuc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN CUTII&apos;,        TO_CHAR(vCantCut,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL GREUTATE SPECIFICA CUTII&apos;,  TO_CHAR(vGSpCut, &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL CANTITATE IN PALETI&apos;,       TO_CHAR(vCantPal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,                  v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                     v_rec.UBI);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;SERIE CARTE IDENTITATE&apos;,          v_rec.PFSerieDoc);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;NUMAR CARTE IDENTITATE&apos;,          v_rec.PFNrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.SLivrObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.SLivrAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.SLivrLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.SLivrTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE EMAIL&apos;,             v_rec.SLivrEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SLivrSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.SLivrJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.SLivrCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.SLivrCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.SLivrCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.SLivrTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE&apos;,        v_rec.SFactObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE ADRESA&apos;,          v_rec.SFactAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE LOCALITATE&apos;,      v_rec.SFactLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TELEFON&apos;,         v_rec.SFactTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE EMAIL&apos;,           v_rec.SFactEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE JUDET&apos;,           v_rec.SFactSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE DENUMIRE JUDET&apos;,  v_rec.SFactJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD POSTAL&apos;,      v_rec.SFactCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD FISCAL&apos;,      v_rec.SFactCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE COD LA CLIENT&apos;,   v_rec.SFactCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU FACTURARE TARA&apos;,            v_rec.SFactTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.SSocObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.SSocAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.SSocLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.SSocTelefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL EMAIL&apos;,              v_rec.SSocEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SSocSimbAuto);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.SSocJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.SSocCodPostal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.SSocCodFiscal);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.SSocCodClient);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.SSocTara);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT CONT&apos;,                     v_rec.ContBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT BANCA&apos;,                    v_rec.DenBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SIMBOL BANCA&apos;,             v_rec.SimbBanca);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SUCURSALA BANCA&apos;,          v_rec.Sucursala);
    IF pkg_categconst.GetValConstanta(&apos;GetSoldListFact&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = &apos;1&apos;
    THEN pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                TO_CHAR(PKG_LIST_BASE_UTILS.GetSoldPart(v_rec.CodPart, v_rec.CodLocatie) ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    ELSE pkg_list_Struct.ADAUGA_PARAM(&apos;CLIENT SOLD&apos;,                &apos;0&apos;);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.ANUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                       v_rec.ACNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                        v_rec.ABI);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,               v_rec.DelNume);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,           v_rec.DelCNP);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,              v_rec.DelDOC);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,          v_rec.DelNRdoc);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,        v_rec.DelSerDoc);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,          v_rec.DelElib);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,        To_Char(v_rec.DelDATADoc,&apos;dd.mm.yyyy&apos;));
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,                   v_rec.DelMTransp);
    --pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,             v_rec.DelNrTransp);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATII&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,             v_rec.PCNume);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT TELEFON&apos;,     v_rec.PCTel);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT EMAIL&apos;,       v_rec.PCEmail);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA&apos;         ,      SitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - MONEDA&apos;,      v_rec.MonedaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - BANCA&apos; ,      v_rec.BancaSitV);
    pkg_list_Struct.ADAUGA_PARAM(&apos;BALANTA IN VALUTA - CURS&apos;  ,      TO_CHAR(v_rec.CursSitV,&apos;fm9G999G999G990&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));

    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      Max(CASE WHEN Idx =  1 THEN Den ELSE NULL END) Den1,
      Max(CASE WHEN Idx =  1 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val1,
      Max(CASE WHEN Idx =  2 THEN Den ELSE NULL END) Den2,
      Max(CASE WHEN Idx =  2 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val2,
      Max(CASE WHEN Idx =  3 THEN Den ELSE NULL END) Den3,
      Max(CASE WHEN Idx =  3 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val3,
      Max(CASE WHEN Idx =  4 THEN Den ELSE NULL END) Den4,
      Max(CASE WHEN Idx =  4 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val4,
      Max(CASE WHEN Idx =  5 THEN Den ELSE NULL END) Den5,
      Max(CASE WHEN Idx =  5 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val5,
      Max(CASE WHEN Idx =  6 THEN Den ELSE NULL END) Den6,
      Max(CASE WHEN Idx =  6 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val6,
      Max(CASE WHEN Idx =  7 THEN Den ELSE NULL END) Den7,
      Max(CASE WHEN Idx =  7 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val7,
      Max(CASE WHEN Idx =  8 THEN Den ELSE NULL END) Den8,
      Max(CASE WHEN Idx =  8 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val8,
      Max(CASE WHEN Idx =  9 THEN Den ELSE NULL END) Den9,
      Max(CASE WHEN Idx =  9 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val9,
      Max(CASE WHEN Idx = 10 THEN Den ELSE NULL END) Den10,
      Max(CASE WHEN Idx = 10 THEN TO_CHAR(Val,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ELSE NULL END) Val10,
      TO_CHAR(Nvl(Sum(Val),0),&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;) ValTot
    FROM (
      SELECT Row_Number() OVER (ORDER BY Sign(cant), Denobiect) Idx, Denobiect den, Sum(valoare) val
      FROM tmp_list_proforma1
      WHERE tiplinie IN (&apos;G&apos;, &apos;T&apos;)
      GROUP BY Sign(cant), denobiect
      ORDER BY Sign(cant), denobiect
    )
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_DEN&apos;,                     v_rec.Den1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC1_VAL&apos;,                     v_rec.Val1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_DEN&apos;,                     v_rec.Den2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC2_VAL&apos;,                     v_rec.Val2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_DEN&apos;,                     v_rec.Den3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC3_VAL&apos;,                     v_rec.Val3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_DEN&apos;,                     v_rec.Den4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC4_VAL&apos;,                     v_rec.Val4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_DEN&apos;,                     v_rec.Den5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC5_VAL&apos;,                     v_rec.Val5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_DEN&apos;,                     v_rec.Den6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC6_VAL&apos;,                     v_rec.Val6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_DEN&apos;,                     v_rec.Den7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC7_VAL&apos;,                     v_rec.Val7);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_DEN&apos;,                     v_rec.Den8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC8_VAL&apos;,                     v_rec.Val8);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_DEN&apos;,                     v_rec.Den9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC9_VAL&apos;,                     v_rec.Val9);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_DEN&apos;,                    v_rec.Den10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISC10_VAL&apos;,                    v_rec.Val10);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DISCOUNT&apos;,                      v_rec.ValTot);
  END LOOP;

  FOR v_rec IN (
    SELECT
      SUM(p1.pu * p1.cant) ValBruta,
      SUM(CASE WHEN p1.cant &gt; 0 THEN p1.cant * nvl(o.volum,0) ELSE 0 END) Volum,
      SUM(CASE WHEN p1.cant &gt; 0 THEN p1.cant * nvl(o.masa,0) ELSE 0 END) Masa,
      SUM(CASE WHEN p1.cant &gt; 0 THEN p1.cant * nvl(o.masa,0) * nvl(u.coef, 1) ELSE 0 END) MasaM,
      SUM(Ceil(p1.cant) * (SELECT count(1) FROM nartobjcolet oc WHERE oc.codobiect = p1.codobiect) ) NrCol
    FROM tmp_list_proforma1 p1
      INNER JOIN nartobj o ON o.codobiect  = p1.codobiect
      INNER JOIN nart    a ON a.codarticol = o.codarticol
      INNER JOIN num     u ON u.codum = a.um
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE BRUTA&apos;,                 TO_CHAR(v_rec.ValBruta,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,                   TO_CHAR(v_rec.Masa,    &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA MULTIPLA&apos;,                 TO_CHAR(v_rec.MasaM,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,                   TO_CHAR(v_rec.Volum,   &apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;NR COLETE TOTAL&apos;,               TO_CHAR(v_rec.NrCol,   &apos;fm9G999G999G990&apos;,    &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  END LOOP;

  FOR v_rec IN (
    SELECT
      PA.NRINREG,
      (SELECT Max( Nvl(PA0.KMBORD,0) ) FROM NPARC0 PA0 WHERE PA0.CODNPARCAUT = O.CODNPARCAUT) KMBORD,
      PA.SERIEC, MA.MARCA, MO.MODEL, CA.NRDOC, CA.DATADOC, CA.SERIADOC,
      O.DATAOFERTA + (SELECT Max(Nvl(O1.ZileL, 0)) FROM OFERTA1 O1 WHERE O1.CODOFERTA = O.CODOFERTA) TERMEN
    FROM OFERTA O
      LEFT JOIN NPARCAUT    PA  ON PA.CODNPARCAUT   = O.CODNPARCAUT
      LEFT JOIN NPARCCOM    PCA ON PCA.CODNPARCAUT  = O.CODNPARCAUT
      LEFT JOIN COMANDA     CA  ON CA.CODCOMANDA    = PCA.CODCOMANDA AND CA.DATADOC &lt; O.DATAOFERTA
      LEFT JOIN NMARCIAUTO  MA  ON MA.CODMARCIAUTO  = PA.MARCA
      LEFT JOIN NMODELEAUTO MO  ON MO.CODMODELEAUTO = PA.MODEL
    WHERE o.codoferta = vCodDoc AND Nvl(O.CODNPARCAUT,0) &gt; 0
    ORDER BY CA.DATADOC DESC
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - NUMAR&apos;           ,  v_rec.NRINREG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - KM BORD&apos;         ,  v_rec.KMBORD);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - SERIE CAROSERIE&apos; ,  v_rec.SERIEC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - MARCA&apos;           ,  v_rec.MARCA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO - MODEL&apos;           ,  v_rec.MODEL);


    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - SERDOC&apos; ,  v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - NRDOC&apos;  ,  v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SERV AUTO ANTERIOR - DATADOC&apos;,  To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));

    pkg_list_Struct.ADAUGA_PARAM(&apos;TERMEN FINAL&apos;                ,  To_Char(v_rec.Termen,&apos;dd.mm.yyyy&apos;));

    EXIT;
  END LOOP;


  COMMIT;

END;

END pkg_list_base_ofeproforma;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_OFERTADOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>976582D43B1AADB5B9CA8B40AC206768D238A207</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_OFERTADOC IS

  vCodOferta  OFERTA.CODOFERTA%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodOferta IN NUMBER DEFAULT NULL)  IS
BEGIN
  vCodOferta := pCodOferta;
END;

function GetCodOferta return number is
begin
  return vCodOferta;
end;

FUNCTION GETCODOFERTA1FURN(aCodObiect in number, aDataStart in Date, aDataEnd in Date, aCantMin in number) return number is
vCodOferta1 number(20);
begin
  vCodOferta := 0;
  for v_rec in (
    SELECT O1.CODOFERTA1
    FROM OFERTA1 O1
         INNER JOIN OFERTA O ON O.CODOFERTA = O1.CODOFERTA
    WHERE O.TIPDOC = 51 AND O1.CODOBIECT = aCodObiect AND O1.CANTMIN &lt;= aCantMin AND
          (O.DATASTART BETWEEN aDataStart AND aDataEnd OR O.DATAEND BETWEEN aDataStart AND aDataEnd) AND
          decode(Coalesce(o.moneda,0),0,O1.PRET,
                 PKG_LIST_BASE_UTILS.GETCURSREFERINTA(o.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataEnd)*O1.PRET
                )
          =
          (SELECT MAX(
                      case
                        when Coalesce(oo.moneda,0) &gt; 0 then PKG_LIST_BASE_UTILS.GETCURSREFERINTA(oo.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),aDataEnd)*O2.PRET
                        else O2.PRET
                      end
                      )
           from OFERTA1 O2
                INNER JOIN OFERTA OO ON OO.CODOFERTA = O2.CODOFERTA
           WHERE OO.TIPDOC = 51 AND O2.CODOBIECT = aCodObiect AND O2.CANTMIN &lt;= aCantMin AND
          (OO.DATASTART BETWEEN aDataStart AND aDataEnd OR OO.DATAEND BETWEEN aDataStart AND aDataEnd)
          )
                ) loop
    vCodOferta1 := v_rec.codoferta1;
    Exit;
  end loop;
  return vCodOferta1;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(30000);
  vDataOfe DATE           := SYSDATE;
  vMoneda  NUMBER(20)     := 0;
  vVal     NUMBER;
  vVCT     NUMBER;
  sInsAchiz VARCHAR2(100);
  sSelAchiz VARCHAR2(1000);
  vAnLuna  NUMBER(20);
BEGIN
  PRC_AL_CHECK(&apos;NPERS1&apos;);

  pkg_globals.SetSeparator(&apos;;&apos;);
  gSuplCols := &apos;OFERTA1 O1, OFERTA O, NPART PART, NARTOBJ OBJ, NARTCLI ARTCLI, NART NA, NUM1 UM, NUM UM1, NPART PROD, NCLASEA CA, NECHIV E, GRECHIV GRE&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,     &apos;PD&apos;,    &apos;PD.CODPART = PART.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,   &apos;OEXT&apos;,  &apos;O1.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,   &apos;OATR&apos;,  &apos;O1.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTAEXT&apos;,    &apos;OFEXT&apos;, &apos;OFEXT.CODOFERTA = O1.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1EXT&apos;,   &apos;OF1EXT&apos;,&apos;OF1EXT.CODOFERTA1 = O1.CODOFERTA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_LST_CURS&apos;, &apos;CURS&apos;,  &apos;CURS.CODMONEDA = O.MONEDA&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF InStr(gSuplJoins, &apos;TMP_LST_CURS&apos;) &gt; 0 THEN
    BEGIN
      SELECT DATAOFERTA, MONEDA INTO vDataOfe, vMoneda FROM OFERTA WHERE CodOferta = vCodOferta;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
    PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS(NULL, vDataOfe, vMoneda);
  END IF;

  sInsAchiz := &apos;&apos;;
  sSelAchiz := &apos;&apos;;
  if aLISTID = 128 then
    sInsAchiz := &apos;,PretAchiz,ValAchiz,Marja,ValMarja&apos;;
    sSelAchiz := &apos;,O1.PretAchiz,O1.PretAchiz*O1.CantMin,case when Coalesce(O1.PretAchiz,0) &gt; 0 then (O1.Pret - O1.PretAchiz)/O1.Pret*100 else 0 end, case when Coalesce(O1.PretAchiz,0) &gt; 0 then O1.Pret - O1.PretAchiz else 0 end&apos;;
  end if;

  BEGIN
    SELECT AN*12+LUNA INTO VANLUNA FROM OFERTA WHERE CODOFERTA = VCODOFERTA;
  EXCEPTION WHEN OTHERS THEN VANLUNA := 0;
  END;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART, UM, CANTMIN, PRET, ADAOS, DISC, OBS, ZileC, ZileL,
    DenLaCli, CodLaCli,
    CodListat,
    UM1, CANT1, D1, D2, D3,
    InCoTerms&apos;||sInsAchiz||gUserFields||&apos;)
  SELECT
    OBJ.Denumire, UM.Den_UM1, O1.CantMin/UM.Paritate, O1.Pret*UM.Paritate*(100+Coalesce(O1.ProcAdaos,0))/100, O1.ProcAdaos, O1.ProcDiscount, O1.Obs, O1.ZileC, O1.ZileL,
    Coalesce(artcli.denumire,obj.denumire), Coalesce(artcli.codextern,obj.codextern),
    Coalesce(DECODE(artcli.tipcodafisat,1,gre.cod,2,artcli.codextern,3,obj.codextern,4,obj.codintern,5,obj.codvamal,6,obj.codplu,7,o1.codextofe),obj.codextern),
    um1.den_um, o1.CantMinUM1, o1.d1, o1.d2, o1.d3,
    CASE o.tiplivrare
      WHEN  0 THEN &apos;&apos;...&apos;&apos;
      WHEN  1 THEN &apos;&apos;EXW - Ex Works&apos;&apos;
      WHEN  2 THEN &apos;&apos;FCA - Free Carrier&apos;&apos;
      WHEN  3 THEN &apos;&apos;CPT - Carriage Paid To&apos;&apos;
      WHEN  4 THEN &apos;&apos;CIP - Carriage and Insurance Paid to&apos;&apos;
      WHEN  5 THEN &apos;&apos;DAT - Delivered at Terminal&apos;&apos;
      WHEN  6 THEN &apos;&apos;DAP - Delivered at Place&apos;&apos;
      WHEN  7 THEN &apos;&apos;DDP - Delivered Duty Paid&apos;&apos;
      WHEN  8 THEN &apos;&apos;FAS - Free alongside ship&apos;&apos;
      WHEN  9 THEN &apos;&apos;FOB - Free on Board&apos;&apos;
      WHEN 10 THEN &apos;&apos;CFR - Cost and Freight&apos;&apos;
      WHEN 11 THEN &apos;&apos;CIF - Cost, Insurance and Freight&apos;&apos;
    END InCoTerms&apos;||sSelAchiz||gUserAlias||&apos;
  FROM OFERTA1 O1
    INNER JOIN OFERTA  O      ON O1.CodOferta     = O.CodOferta
    LEFT  JOIN NPART   PART   ON PART.CodPart     = O.Partener
    LEFT  JOIN NARTOBJ OBJ    ON OBJ.CodObiect    = O1.CodObiect
    LEFT  JOIN NArtCli ACP    ON ACP.CodObiect    = O1.CodObiect AND ACP.CodPart = O.Partener AND Coalesce(ACP.CodPart,0) &lt;&gt; 0
    LEFT  JOIN NArtCli ARTCLI ON ARTCLI.CodObiect = O1.CodObiect AND ARTCLI.CodArtCli = Coalesce(ACP.CodArtCli, ARTCLI.CodArtCli)
                                 AND Coalesce(ACP.CodArtCli,PART.CodClasa,O.CodClaseP, 0) = COALESCE(ACP.CodArtCli, Decode(ARTCLI.CodClaseP, NULL,-1, 0, -1, ARTCLI.CodClaseP))
    LEFT  JOIN NART    NA     ON NA.CodArticol    = OBJ.CodArticol
    LEFT  JOIN NUM1    UM     ON UM.CodUM1        = O1.UMSec
    LEFT  JOIN NUM     UM1    ON UM1.CODUM        = NA.UM1
    LEFT  JOIN NPART   PROD   ON PROD.CodPart     = OBJ.CodProducator
    LEFT  JOIN NCLASEA CA     ON CA.CodClaseA     = NA.Clasa
    LEFT  JOIN NECHIV  E      ON e.codobiect      = o1.codobiect
    LEFT  JOIN GRECHIV GRE    ON gre.codgrechiv   = e.codgrupa&apos;||
    gSuplJoins||&apos;
  WHERE O.CodOferta = &apos;||vCodOferta||&apos;
  ORDER BY O1.CodOferta1&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  SELECT
    SUM(O1.CANTMIN*O1.PRET*(1+Coalesce(O1.PROCADAOS/100,0))*(1+Coalesce(O1.PROCDISCOUNT/100,0))) VAL,
    SUM(O1.CANTMIN*O1.PRET*(1+Coalesce(O1.PROCADAOS/100,0))*(1+Coalesce(O1.PROCDISCOUNT/100,0))*(1+PKG_SELECTARTICOLE.GETPROCENTTVA(NO.CodArticol,O.AN,O.LUNA)/100)) VALCUTVA
  INTO
    vVal,
    vVCT
  FROM OFERTA O
    INNER JOIN OFERTA1 O1 ON O1.CODOFERTA = O.CODOFERTA
    INNER JOIN NARTOBJ NO ON NO.CODOBIECT = O1.CODOBIECT
  WHERE O.CodOferta = vCodOferta;


  FOR v_rec IN (
    WITH FUNCT AS (
      SELECT P1.CODPERS, F.DENUMIRE FUNCTIE
      FROM NPERS1 P1
           LEFT JOIN FUNCTII F ON P1.CODFUNCTIE = F.CODFUNCTIE
      WHERE VANLUNA BETWEEN P1.ALStart and P1.ALStop
    )
    SELECT
      O.TipDoc, O.NrDoc, O.DataCerere, O.DataOferta, O.DataStart, O.DataEnd, O.Obs, O.Agent,O.CodPersC,
      UT.UserName, Coalesce(U.Nume,&apos;...nedefinit...&apos;) UNume, Coalesce(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Coalesce(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      AGU.EMAIL, AGU.Telefon UTelefon1, AGU.TelefonP UTelefon2,
      AG.NUME||&apos; &apos;||AG.PRENUME ANUME, AG.CNP ACNP, AG.BISERIA||&apos; &apos;||AG.BINR ABI,
      PCF.CodFiscal as CIF, P.CodPart, P.Den_Part, P.Autorizatie, P.RegCom, P.Obs PartObs, M.Simbol,
      GetAdresa(SS.sector,SS.strada,SS.nr1,SS.nr2,SS.bloc,SS.scara,SS.etaj,SS.apart,SS.codpostal) AdresaS,
      GetAdresa(SS.sector,SS.strada,SS.nr1,SS.nr2,SS.bloc,SS.scara,SS.etaj,SS.apart,NULL)         AdresaS_NO_CP,
      SS.OBS OBSS, LS.Den_Localit LOCALITS, SS.TELEFON TELEFONS, SS.FAX FaxS, JS.DEN_JUDET JudetS, JS.SimbAuto SimbAutoS, TS.Den_Tara TaraS,
      SS.CODPOSTAL CODPOSTALS, SS.CODFISCAL CODFISCALS, SS.CODCLIENT CODCLIENTS,
      GetAdresa(SL.sector,SL.strada,SL.nr1,SL.nr2,SL.bloc,SL.scara,SL.etaj,SL.apart,SL.codpostal) AdresaL,
      GetAdresa(SL.sector,SL.strada,SL.nr1,SL.nr2,SL.bloc,SL.scara,SL.etaj,SL.apart,NULL)         AdresaL_NO_CP,
      SL.OBS OBSL, LL.Den_Localit LOCALITL, SL.TELEFON TELEFONL, SL.FAX FaxL, JL.DEN_JUDET JudetL, JL.SimbAuto SimbAutoL, TL.Den_Tara TaraL,
      SL.CODPOSTAL CODPOSTALL, SL.CODFISCAL CODFISCALL, SL.CODCLIENT CODCLIENTL,
      PC.Nume||&apos; &apos;||PC.Prenume PersContact, PC.TELEFON PersContactTel, PC.EMAIL PersContactEmail,
      CASE O.tiplivrare
        WHEN  0 THEN &apos;...&apos;
        WHEN  1 THEN &apos;EXW&apos;
        WHEN  2 THEN &apos;FCA&apos;
        WHEN  3 THEN &apos;CPT&apos;
        WHEN  4 THEN &apos;CIP&apos;
        WHEN  5 THEN &apos;DAT&apos;
        WHEN  6 THEN &apos;DAP&apos;
        WHEN  7 THEN &apos;DDP&apos;
        WHEN  8 THEN &apos;FAS&apos;
        WHEN  9 THEN &apos;FOB&apos;
        WHEN 10 THEN &apos;CFR&apos;
        WHEN 11 THEN &apos;CIF&apos;
      END InCoTerms,
      CASE O.tiplivrare
        WHEN  0 THEN &apos;...&apos;
        WHEN  1 THEN &apos;Ex Works&apos;
        WHEN  2 THEN &apos;Free Carrier&apos;
        WHEN  3 THEN &apos;Carriage Paid To&apos;
        WHEN  4 THEN &apos;Carriage and Insurance Paid to&apos;
        WHEN  5 THEN &apos;Delivered at Terminal&apos;
        WHEN  6 THEN &apos;Delivered at Place&apos;
        WHEN  7 THEN &apos;Delivered Duty Paid&apos;
        WHEN  8 THEN &apos;Free alongside ship&apos;
        WHEN  9 THEN &apos;Free on Board&apos;
        WHEN 10 THEN &apos;Cost and Freight&apos;
        WHEN 11 THEN &apos;Cost, Insurance and Freight&apos;
      END InCoTermsDesc, AGA.TELEFON, AGA.TELEFONP, AGF.FUNCTIE AGFUNCTIE, UF.FUNCTIE UFUNCTIE
    FROM OFERTA O
      LEFT JOIN NPERS          U   ON U.LOGONNAME   = O.USERID
      LEFT JOIN TMP_UTILIZATOR UT  ON UT.CODUTILIZATOR = O.USERID
      LEFT JOIN NMONEDE        M   ON O.Moneda      = M.CodMoneda
      LEFT JOIN NPARTCODFISC   PCF ON O.CodFiscal   = PCF.Cod_CodFiscal
      LEFT JOIN NPART          P   ON O.Partener    = P.CodPart
      LEFT JOIN NAGENDA        SL  ON SL.CodAgenda  = O.CodLocatie
      LEFT JOIN NLOCALIT       LL  ON LL.CodLocalit = SL.CodLocalit
      LEFT JOIN NJUDET         JL  ON JL.CodJudet   = LL.CodJudet
      LEFT JOIN NTARI          TL  ON TL.CodTara    = Coalesce(LL.CodTara, 0)
      LEFT JOIN NAGENDA        SS  ON SS.CodPart    = O.Partener AND SS.SEDIUSOCIAL IN (4,5,6,7) AND Coalesce(SS.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT       LS  ON LS.CodLocalit = SS.CodLocalit
      LEFT JOIN NJUDET         JS  ON JS.CodJudet   = LS.CodJudet
      LEFT JOIN NTARI          TS  ON TS.CodTara    = Coalesce(LS.CodTara, 0)
      LEFT JOIN NPERS          AG  ON AG.CODPERS    = O.AGENT
      LEFT JOIN NAGENDA        AGA ON AGA.CODAGENDA = AG.AGENDA
      LEFT JOIN NAGENDA        AGU ON AGU.CODAGENDA = U.AGENDA
      LEFT JOIN NPERSCONTACT   PCx ON PCx.CodPart   = P.CodPart
      LEFT JOIN NPERSCONTACT   PC  ON PC.CodPersC   = Decode(O.CodPersC , NULL, PCx.CodPersC, 0, PCx.CodPersC, O.CodPersC)
      LEFT JOIN FUNCT          AGF ON AGF.CODPERS   = O.AGENT
      LEFT JOIN FUNCT          UF  ON UF.CODPERS    = U.CODPERS
    WHERE O.CodOferta = vCodOferta
      AND ROWNUM = 1
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT DE&apos;,                     v_rec.USERNAME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,                   v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT MAIL&apos;,                   v_rec.EMAIL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT TELEFON 1&apos;,              v_rec.utelefon1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT TELEFON 2&apos;,              v_rec.utelefon2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT FUNCTIE&apos;,                v_rec.UFUNCTIE);

    pkg_list_Struct.ADAUGA_PARAM(&apos;Numar oferta&apos;,                    v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Perioada de valabilitate&apos;,        To_Char(v_rec.DataStart,&apos;dd.mm.yyyy&apos;) ||&apos; - &apos;||To_Char(v_rec.DataEnd,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data cerere oferta&apos;,              To_Char(v_rec.DataCerere,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data oferta&apos;,                     To_Char(v_rec.DataOferta,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data inceput oferta&apos;,             To_Char(v_rec.DataStart,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data sfarsit oferta&apos;,             To_Char(v_rec.DataEnd,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener &apos;,                       v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CUI&apos;,                    v_rec.CIF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Reg Com&apos;,                v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener autorizatie&apos;,            v_rec.Autorizatie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener observatii&apos;,             v_rec.PartObs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                          v_rec.Simbol);

    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE&apos;,           v_rec.ObsS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA&apos;,             v_rec.AdresaS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL ADRESA FARA CP&apos;,     v_rec.AdresaS_NO_CP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL LOCALITATE&apos;,         v_rec.LocalitS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TELEFON&apos;,            v_rec.TelefonS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL FAX&apos;,                v_rec.FaxS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL JUDET&apos;,              v_rec.SimbAutoS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL DENUMIRE JUDET&apos;,     v_rec.JudetS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL TARA&apos;,               v_rec.TaraS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD POSTAL&apos;,         v_rec.CodPostalS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD FISCAL&apos;,         v_rec.CodFiscalS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU SOCIAL COD LA CLIENT&apos;,      v_rec.CodClientS);

    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE&apos;,          v_rec.ObsL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA&apos;,            v_rec.AdresaL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE ADRESA FARA CP&apos;,    v_rec.AdresaL_NO_CP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE LOCALITATE&apos;,        v_rec.LocalitL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TELEFON&apos;,           v_rec.TelefonL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE FAX&apos;,               v_rec.FaxL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE JUDET&apos;,             v_rec.SimbAutoL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE TARA&apos;,              v_rec.TaraL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE DENUMIRE JUDET&apos;,    v_rec.JudetL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD POSTAL&apos;,        v_rec.CodPostalL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD FISCAL&apos;,        v_rec.CodFiscalL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;SEDIU LIVRARE COD LA CLIENT&apos;,     v_rec.CodClientL);

    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT&apos;,                           v_rec.ANUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT CNP&apos;,                       v_rec.ACNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT BI&apos;,                        v_rec.ABI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT TELEFON 1&apos;,                 v_rec.TELEFON);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT TELEFON 2&apos;,                 v_rec.TELEFONP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;AGENT FUNCTIE&apos;,                   v_rec.AGFUNCTIE);

    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE&apos;,                         TO_CHAR(vVal,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE CU TVA&apos;,                  TO_CHAR(vVCT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));

    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT&apos;,             v_rec.PersContact);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT TELEFON&apos;,     v_rec.PersContactTel);
    pkg_list_Struct.ADAUGA_PARAM(&apos;PERSOANA DE CONTACT EMAIL&apos;,       v_rec.PersContactEmail);

    pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTerms&apos;,                       v_rec.InCoTerms);
    pkg_list_Struct.ADAUGA_PARAM(&apos;InCoTermsDesc&apos;,                   v_rec.InCoTermsDesc);

    EXIT;
  END LOOP;

  pkg_list_Struct.ADAUGA_PARAM_EXT(&apos;OFERTAEXT&apos;, &apos;CODOFERTA&apos;, vCodOferta);

  COMMIT;
END;


end PKG_LIST_BASE_OFERTADOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_OFERTERAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8591F4443C6D9867F593724B28B97135BC2C3A21</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_OFERTERAC IS

  vCodDoc NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER)  IS
BEGIN
  vCodDoc := pCodDoc;
END;


PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  FOR V_REC in (
    SELECT
    C.OBS,
    NP.DEN_PART,
    NA.OBS OBSSEDIU,
    NS.DEN_SUBUNIT,
    NG.DEN_GEST,
   Case when P.TIP = 0 THEN &apos;zile&apos;
        when P.TIP = 1 THEN &apos;km&apos;
        when P.TIP = 2 THEN &apos;ore&apos;
        when P.TIP = 3 THEN &apos;buc&apos;
   end TIPOFERTA,
    NM.DEN_MONEDA
    FROM RAC_CATP C
     INNER JOIN Rac_CatP1 C1 on C1.CODRAC_CatP =NVL(C.CODRAC_CatP,0)
     INNER JOIN Rac_P P on P.CODRAC_P = NVL(C1.CODRAC_P,0)
     INNER JOIN Rac_P0 P0 on P0.CODRAC_P = NVL(P.CODRAC_P  ,0)
     INNER JOIN Rac_P1 P1 on P1.CODRAC_P0 = NVL(P0.CODRAC_P0,0)
     INNER JOIN NPART NP on NP.CODPART = NVL(C.CODPARTENER,0)
     INNER JOIN NAgenda NA on NA.CODAGENDA = NVL(C.CODSEDIU,0)
     INNER JOIN NGest NG on NG.CODGEST = NVL(C.CODGEST,0)
     INNER JOIN NSubunit NS on NS.CODSUBUNIT = NVL(C.CODSUBUNITATE,0)
     INNER JOIN NMonede NM on NM.CODMONEDA = NVL(P.MONEDA,0)
     WHERE C.CODRAC_CATP = vCodDoc)
    LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Denumire oferta&apos;,    v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,           v_rec.DEN_PART);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu&apos;,              v_rec.OBSSEDIU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitate&apos;,         v_rec.DEN_SUBUNIT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Gestiune&apos;,           v_rec.DEN_GEST);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip oferta&apos;,         v_rec.TIPOFERTA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,             v_rec.DEN_MONEDA);
      EXIT;
    END LOOP;
END;



PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
          PART,
          SEDIU,
          GEST,
          SUBUNIT,
          DATASTARTcat,
          DATASTOPcat,
          OBS,
          TIP,
          MONEDA,
          DATASTARTp,
          Grupa,
          I1,
          P1,
          I2,
          P2,
          I3,
          P3,
          I4,
          P4,
          I5,
          P5,
          I6,
          P6,
          VALFIXA
)&apos;;

  sSelect := &apos;
  SELECT
    NP.DEN_PART,
    NA.OBS,
    NG.DEN_GEST,
    NS.DEN_SUBUNIT,
    C.DATASTART CatStart,
    C.DATASTOP CatStop,
    C.OBS Interval,
    Case when P.TIP = 0 THEN &apos;&apos;zile&apos;&apos;
         when P.TIP = 1 THEN &apos;&apos;km&apos;&apos;
         when P.TIP = 2 THEN &apos;&apos;ore&apos;&apos;
         when P.TIP = 3 THEN &apos;&apos;buc&apos;&apos;
    end,
    NM.DEN_MONEDA,
    P0.DATASTART,
    G.DENUMIRE Grupa,
    P.I1,
    P1.P1,
    P.I2,
    P1.P2,
    P.I3,
    P1.P3,
    P.I4,
    P1.P4,
    P.I5,
    P1.P5,
    P.I6,
    P1.P6,
    P1.FIX
  FROM Rac_CatP C
  INNER JOIN Rac_CatP1 C1 on C1.CODRAC_CatP =NVL(C.CODRAC_CatP,0)
  INNER JOIN Rac_P P on P.CODRAC_P = NVL(C1.CODRAC_P,0)
  INNER JOIN Rac_P0 P0 on P0.CODRAC_P = NVL(P.CODRAC_P  ,0)
  INNER JOIN Rac_P1 P1 on P1.CODRAC_P0 = NVL(P0.CODRAC_P0,0)
  INNER JOIN NPART NP on NP.CODPART = NVL(C.CODPARTENER,0)
  INNER JOIN NAgenda NA on NA.CODAGENDA = NVL(C.CODSEDIU,0)
  INNER JOIN NGest NG on NG.CODGEST = NVL(C.CODGEST,0)
  INNER JOIN NSubunit NS on NS.CODSUBUNIT = NVL(C.CODSUBUNITATE,0)
  INNER JOIN NMonede NM on NM.CODMONEDA = NVL(P.MONEDA,0)
  INNER JOIN GRECHIV G ON G.CODGRECHIV = NVL(P1.CODGRUPA,0)
  WHERE C.CODRAC_CATP = &apos;||vCodDoc ;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  pkg_list_base_OFERTERAC.add_list_params;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_OFERTERAC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BDAC1399CB4D770BCE1DFE0909F294ADADBF37BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_oportunitati IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE UMPLETMPLISTA IS
aAlStop number(20);  
aMax number(20);
BEGIN
  FOR V_P IN (
    SELECT CODPART FROM NPART WHERE CODPART &gt; 0) 
  LOOP
    FOR V_REC IN (
      SELECT CRM1.CODPART, CRM1.ANSTART*12+CRM1.LUNASTART ALSTART, ACT.DEN_ACTIVIT, ROW_NUMBER() OVER (PARTITION BY CRM1.CODPART, CRM1.ANSTART, CRM1.LUNASTART ORDER BY PACT.CODACTIVIT) INDEXLOCAL
      FROM NPART1CRM CRM1
           INNER JOIN NPARTACTIVIT PACT ON PACT.CODPART1CRM = CRM1.CODPART1CRM
           INNER JOIN NACTIVIT ACT ON ACT.CODACTIVIT = PACT.CODACTIVIT
      WHERE CRM1.CODPART = V_P.CODPART
      ORDER BY CRM1.ANSTART, CRM1.LUNASTART
    ) LOOP
      select max(anstart*12+lunastart) into aMax from npart1crm where codpart = v_p.codpart;
      if aMax = v_rec.alstart then  
        aAlStop := 9999*12+12;
      else
        select min(anstart*12+lunastart) - 1 into aAlStop from npart1crm where codpart = v_p.codpart and anstart*12+lunastart &gt; v_rec.alstart;
      end if;
      INSERT INTO TMP_LST_PART1CRM(CODPART,INDEXLOCAL,DEN_ACTIVIT,ALSTART,ALSTOP)
      values (v_p.codpart, v_rec.indexlocal, v_rec.den_activit, v_rec.alstart, aAlStop);
    END LOOP;
  END LOOP;
  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(20000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;OPORTUNITATI O, NPART P, NPARTCODFISC F, NAGENDA A, NLOCALIT L, DOMENIIACT DA, NMONEDE M, NPERSCONTACT PC, OPORTUNITATI1 O1, CAMPANII C, NPARTTR DEL&apos;;

  DELETE TMP_LST_PART1CRM;
  UMPLETMPLISTA;

  pkg_list_struct.StartSuplCols;

  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CODDOC,NAV_TIPDOC,
    PrefixDoc, NrDoc, DataDoc, DenCampanie,
    Den_Part, CodFiscal, Den_Localit, CifraAfaceri, NrAngajati, DenDomeniuAct,
    Den_Moneda, NumePersC, TelefonC, EMailC, DataSemnare, VenitEst, VenitProb, ProbVanz,
    TipOportunitate,
    Stadiu,
    Potential,
    IndexLocal, Delegat, Info, DataC, Obs&apos;||
    gUserFields||&apos;)&apos;;


  sSelect := &apos;
  SELECT
    O.CODOPORTUNITATE, 82,
    COALESCE(O.PrefixDoc,&apos;&apos;OP&apos;&apos;), O.NrDoc, O.DataDoc, C.DenCampanie,
    P.Den_Part, F.CodFiscal, L.Den_Localit, PP.CifraAfaceri, PP.NrAngajati, PP.DenDomeniuAct,
    M.Den_Moneda, PC.Prenume || &apos;&apos; &apos;&apos; || PC.Nume NumePersC, PC.Telefon TelefonC, PC.EMail EMailC, O.DataSemnare, O.VenitEst, O.VenitProb, O.ProbVanz,
    Decode(O.Tip, 0, &apos;&apos;Vanzare directa&apos;&apos;, 1, &apos;&apos;Servicii&apos;&apos;, 2, &apos;&apos;prin parteneri&apos;&apos;, &apos;&apos;-&apos;&apos;) TipOportunitate,
    Decode(O1.Stadiu, 1, &apos;&apos;1.Prezentare&apos;&apos;, 2, &apos;&apos;2.Ofertare&apos;&apos;, 3, &apos;&apos;3.Negociere&apos;&apos;, 4, &apos;&apos;4.Vanzare&apos;&apos;, 0, &apos;&apos;5.Pierdut&apos;&apos;, 7, &apos;&apos;7.Vizita&apos;&apos;) Stadiu,
    Decode(O1.Stadiu, -1, &apos;&apos;Zero&apos;&apos;, 0, &apos;&apos;Fara potential&apos;&apos;, 1, &apos;&apos;Scazut&apos;&apos;, 2, &apos;&apos;Mediu&apos;&apos;, 3, &apos;&apos;Ridicat&apos;&apos;, 4, &apos;&apos;Foarte ridicat&apos;&apos;) Potential,
    O1.IndexLocal, DEl.nume||&apos;&apos; &apos;&apos;||del.prenume, O1.Info, O1.DataC, O.Obs&apos;||
    gUserAlias||&apos;
  FROM OPORTUNITATI O
    LEFT JOIN V_NPART PP ON PP.CodPart = O.CodPartener
    LEFT JOIN NPART P ON PP.CODPART = P.CODPART
    LEFT JOIN NPARTCODFISC F ON F.CODPART = P.CODPART AND F.PRINCIPAL = 1
    LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART  AND Nvl(A.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 4) &lt;&gt; 0)
    LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT JOIN NMONEDE M ON M.CodMoneda = O.CodMoneda
    LEFT JOIN NPERSCONTACT PC ON PC.CodPersC = O.CodAgent
    LEFT JOIN OPORTUNITATI1 O1 ON O1.CodOportunitate = O.CodOportunitate
    LEFT JOIN CAMPANII C ON C.CodCampanie = O.CodCampanie
    LEFT JOIN NPERS DEL ON DEL.CodPers = O1.CodAgent&apos;||
    gSuplJoins||&apos;
  WHERE O.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||TO_CHAR(pkg_list_selectperioada.DATAINI,&apos;DD.MM.YYYY&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND 
        TO_DATE(&apos;&apos;&apos;||TO_CHAR(pkg_list_selectperioada.DATAFIN,&apos;DD.MM.YYYY&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;O&apos;,&apos;CODSUBUNITATE&apos;);
  
  if pkg_list_selectperioada.optiunea1 then
    sSelect := sSelect||&apos; and not exists (select o2.stadiu from oportunitati1 o2 where o2.codoportunitate = o.codoportunitate and o2.stadiu = 0)&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_OPORTUNITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_ORDONANTARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CFF23E6CD8A17365527A8E9DD6CBD67E77D25EE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_ORDONANTARI is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(2000);
  sInsertAux  VARCHAR2(2000);
  sSelect     VARCHAR2(10000);
  aDataIni    varchar2(10);
  aDataFin    varchar2(10);
  aDataIniSold date;
  aDataFinSold date;
  sFiltru     VARCHAR2(1000);
  sFiltruSold  VARCHAR2(1000);
  aAn         number(4);
  aLuna       number(2);
  aAnC        number(4);
  aLunaC      number(2);
  aUserID     number(20);
BEGIN
  gSuplCols := &apos;plati p, plati1 p1, analiza a, nmonede m, analizanod nod&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  aDataIni := to_char(pkg_list_selectper.dataini, &apos;dd.mm.yyyy&apos;);
  aDataFin := to_char(pkg_list_selectper.datafin, &apos;dd.mm.yyyy&apos;);
  aDataIniSold := to_date(&apos;01.&apos;||to_char(pkg_list_selectper.dataini,&apos;MM.YYYY&apos;),&apos;DD.MM.YYYY&apos;);
  aDataFinSold := Trunc(pkg_list_selectper.dataini) - 1;

  select Extract(Year from pkg_list_selectper.dataini) into aAn from dual;
  select Extract(Month from pkg_list_selectper.dataini) into aLuna from dual;
  aAnC := aAn;
  aLunaC := aLuna;

  if aLuna = 1 then
    aLuna := 12;
    aAn := aAn - 1;
  else
    aLuna := aLuna - 1;
  end if;

  sFiltru := &apos; and p.data between to_date(&apos;&apos;&apos;||aDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||aDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     CodAnalizaNod,
     Banca, 
     Cont, 
     Moneda, 
     NrDoc, 
     DataDoc, 
     Aprobat,
     PrjAnaliza,
     Destinatar,
     DocP,
     NrDocP,
     ValDoc,
     Termen,
     Platit,
     SimbolNod,
     DenNod,
     TipLinie,
     Rest,
     SoldLinie &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  select p.codplata, 105, nod.codanalizanod,
       bk.simbol, bc.nrcont, m.simbol, p.nrdoc, p.data, case when nvl(p.aprobat,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
       a.den_analiza, p.den_part, i.prefixdoc, i.nrdoc, o.valoare, o.termen, p1.valoare, nod.simbolnod, nod.dennod,
       &apos;&apos; &apos;&apos; TipLinie, p1.valoare - nvl((select sum(s.valoare) from stingere s where s.codplata1 = p1.codplata1),0), - p1.valoare
        &apos;||gUserAlias||&apos;
  from plati p
       inner join plati1 p1 on p1.codplata = p.codplata 
       inner join obligpif o on o.codobligpif = p1.codobligpif
       inner join general g on g.codgeneral  = o.codgeneral and g.tipdoc &lt;&gt; 5
       inner join intrari i on g.tipdoc = i.tipdoc and g.coddoc = i.codintr
       inner join npart p on p.codpart = o.codpart
       left join nbankcont bc on bc.codbankcont = p.codbankcont
       left join nbank bk on bc.codbank = bk.codbank
       left join nmonede m on m.codmoneda = bc.codmoneda
       left join analiza a on a.codanaliza = p.codanaliza
       left join analizanod nod on nod.codanalizanod = o.codanalizanod
       &apos;||gSuplJoins||&apos;
  where Nvl(p.TipDoc,0) = 1 &apos;||chr(13)||sFiltru||chr(13)||&apos;
  union all
  select p.codplata, 105, nod.codanalizanod,
         bk.simbol, bc.nrcont, m.simbol, p.nrdoc, p.data, case when nvl(p.aprobat,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
         a.den_analiza, p.den_part, &apos;&apos;DVOT&apos;&apos; prefixdoc, d.nrdoc, o.valoare, o.termen, p1.valoare, nod.simbolnod, nod.dennod,
         &apos;&apos; &apos;&apos; TipLinie, p1.valoare - nvl((select sum(s.valoare) from stingere s where s.codplata1 = p1.codplata1),0), - p1.valoare &apos;||gUserAlias||&apos;
  from plati p
       inner join plati1 p1 on p.codplata = p1.codplata
       inner join obligpif o on o.codobligpif = p1.codobligpif
       inner join general g on g.codgeneral  = o.codgeneral and g.tipdoc = 5
       inner join dvi d on g.coddoc = d.coddvi
       inner join intrari i on d.codintr = i.codintr
       inner join npart p on p.codpart = o.codpart
       left join analizanod nod on nod.codanalizanod = o.codanalizanod
       left join nbankcont bc on bc.codbankcont = p.codbankcont
       left join nbank bk on bc.codbank = bk.codbank
       left join nmonede m on m.codmoneda = bc.codmoneda
       left join analiza a on a.codanaliza = p.codanaliza
       &apos;||gSuplJoins||&apos;
  where Nvl(p.TipDoc,0) = 1 &apos;||chr(13)||sFiltru||chr(13)||&apos;
  union all
  select p.codplata, 105, nod.codanalizanod,
         bk.simbol, bc.nrcont, m.simbol, p.nrdoc, p.data, case when nvl(p.aprobat,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end,
         a.den_analiza, 
         Case when P1.CODOBLIGPIF = 0 then P.DEN_PART 
              when P1.CODOBLIGPIF = 1 then A.NUME ||&apos;&apos; &apos;&apos;|| A.PRENUME 
              when P1.CODOBLIGPIF = 2 then C.Simbol 
         end, null, null, 0, null, p1.valoare, nod.simbolnod, nod.dennod,
         case P1.CODOBLIGPIF + 1 
           when 0 then &apos;&apos;Plata obligatie&apos;&apos;
           when 1 then &apos;&apos;Avans furnizor&apos;&apos;
           when 2 then &apos;&apos;Avans decont&apos;&apos;
           when 3 then &apos;&apos;Direct pe cont&apos;&apos;
         end TipLinie, p1.valoare - nvl((select sum(t1.valdoc) from trezor1 t1 where t1.codplata1 = p1.codplata1),0), - p1.valoare &apos;||gUserAlias||&apos;
  from plati p
       inner join plati1 p1 on p1.codplata = p.codplata
       left join analizanod nod on nod.codanalizanod = p1.codanalizanodx
       left join nbankcont bc on bc.codbankcont = p.codbankcont
       left join nbank bk on bc.codbank = bk.codbank
       left join nmonede m on m.codmoneda = bc.codmoneda
       left join analiza a on a.codanaliza = p.codanaliza
       left join npart p on p.codpart = p1.codpart
       left join npers a on a.codpers = p1.codpers
       left join ncont c on c.codcont = p1.codcont
       &apos;|| gSuplJoins||&apos;
  where Nvl(p.TipDoc,0) = 1 and p1.codobligpif &lt; 10 &apos;||chr(13)||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  /*delete tmp_manevra_liste where filtru = &apos;CODANALIZANOD&apos;;
  sInsertAux := &apos;insert into tmp_manevra_liste(filtru,valoare) &apos;||chr(13)||
                &apos;select distinct &apos;&apos;CODANALIZANOD&apos;&apos;, codanalizanod&apos;||chr(13)||
                &apos;from &apos;||TMPNAME;
  execute immediate sInsertAux;*/
  aUserID := pkg_globals.getuserid;
  delete tmp_cmd where userid = aUserID;
  insert into tmp_cmd(codobiect, cantc, userid)
  select a.codanalizanod, nvl(x.buget,0), aUserID
  from analizanod a
       left join (
  select b.codanalizanod, b.buget
  from bugetanaliza b
  where b.an*12+b.luna = (select max(t.an*12+t.luna) from bugetanaliza t where t.codanalizanod = b.codanalizanod and t.an*12+t.luna &lt;= aAnC *12 + aLunaC)
  ) x on x.codanalizanod = a.codanalizanod;
  commit;
  
  for v_rec in (select sum(Buget) Buget, CodAnalizaNod
                from
                (
                select Nvl(R1.CodNodDest,0) CodAnalizanod, R1.VCredit Buget
                from Bugetrectif1 R1
                     inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
                WHERE R.DataDoc &lt; pkg_list_selectper.dataini and r.an = aAnC
                      and Nvl(R1.CodNodDest,0) &gt; 0 and Nvl(R1.VCredit,0) &gt; 0
                UNION ALL
                select Nvl(R1.CodNodSursa,0) CodAnalizanod, -R1.VCredit Buget
                from Bugetrectif1 R1
                     inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
                WHERE R.DataDoc &lt; pkg_list_selectper.dataini and r.an = aAnC
                      and Nvl(R1.CodNodSursa,0) &gt; 0 and Nvl(R1.VCredit,0) &gt; 0
                ) group by CodAnalizaNod
               ) loop
    update tmp_cmd set
      cantc = cantc + v_rec.buget
    where codobiect = v_rec.codanalizanod;
  end loop;
  
  for v_rec in (select nod.codanalizanod, p1.valoare
                from plati p
                     inner join plati1 p1 on p1.codplata = p.codplata 
                     inner join obligpif o on o.codobligpif = p1.codobligpif
                     inner join general g on g.codgeneral  = o.codgeneral
                     inner join intrari i on g.tipdoc = i.tipdoc and g.coddoc = i.codintr and g.tipdoc &lt;&gt; 5
                     inner join npart p on p.codpart = o.codpart
                     left join nbankcont bc on bc.codbankcont = p.codbankcont
                     left join nbank bk on bc.codbank = bk.codbank
                     left join nmonede m on m.codmoneda = bc.codmoneda
                     left join analiza a on a.codanaliza = p.codanaliza
                     left join analizanod nod on nod.codanalizanod = o.codanalizanod
                where Nvl(p.TipDoc,0) = 1 and p.data &lt; pkg_list_selectper.dataini and p.an = aAnC
                union all
                select nod.codanalizanod, p1.valoare
                from plati p
                     inner join plati1 p1 on p.codplata = p1.codplata
                     inner join obligpif o on o.codobligpif = p1.codobligpif
                     inner join general g on g.codgeneral  = o.codgeneral and g.tipdoc = 5
                     inner join dvi d on g.coddoc = d.coddvi
                     inner join intrari i on d.codintr = i.codintr
                     inner join npart p on p.codpart = o.codpart
                     left join analizanod nod on nod.codanalizanod = o.codanalizanod
                     left join nbankcont bc on bc.codbankcont = p.codbankcont
                     left join nbank bk on bc.codbank = bk.codbank
                     left join nmonede m on m.codmoneda = bc.codmoneda
                     left join analiza a on a.codanaliza = p.codanaliza
                where Nvl(p.TipDoc,0) = 1 and p.data &lt; pkg_list_selectper.dataini and p.an = aAnC
                union all
                select nod.codanalizanod, p1.valoare
                from plati p
                     inner join plati1 p1 on p1.codplata = p.codplata
                     left join analizanod nod on nod.codanalizanod = p1.codanalizanodx
                     left join nbankcont bc on bc.codbankcont = p.codbankcont
                     left join nbank bk on bc.codbank = bk.codbank
                     left join nmonede m on m.codmoneda = bc.codmoneda
                     left join analiza a on a.codanaliza = p.codanaliza
                     left join npart p on p.codpart = p1.codpart
                     left join npers a on a.codpers = p1.codpers
                     left join ncont c on c.codcont = p1.codcont 
                where Nvl(p.TipDoc,0) = 1 and p1.codobligpif &lt; 10 and p.data &lt; pkg_list_selectper.dataini and p.an = aAnC
               ) loop
    update tmp_cmd
    set
      cantc = cantc - v_rec.valoare
    where codobiect = v_rec.codanalizanod;
  end loop;
  
  sInsertAux :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     DataDoc,
     CodAnalizaNod,
     Destinatar,
     Platit,
     SoldLinie,
     SimbolNod,
     DenNod &apos;||gUserFields||&apos;)&apos;||chr(13)||
  &apos;select 0, 0, to_date(&apos;&apos;&apos;||aDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), tmp.codobiect, &apos;&apos;Sold initial&apos;&apos;, tmp.cantc, tmp.cantc, nod.simbolnod, nod.dennod &apos;||gNullAlias||&apos;
   from tmp_cmd tmp 
        left join analizanod nod on nod.codanalizanod = tmp.codobiect 
   where userid = &apos;||aUserID;
  LIST_EXECUTE_IMMEDIATE(sInsertAux, aListID, aListVer);
  
  COMMIT;
END;

end PKG_LIST_BASE_ORDONANTARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>296FC340891B492665A2928687D426420EF23018</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_parcauto IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN

  gSuplCols := &apos;nparcaut pa, npers s, mifix mf, nirstoc ns, ngest g, nartobj o &apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,    
    NAV_TipDoc,
    Den, NrInv, Sofer, GestMifix, GestExploat, Tip,
    NrInreg, DataInreg, Marca, Model, AnFab, SerieC, Culoare, Lung, Lat, Inalt,
    TipMotor, SerieMotor, Combustibil, Cilindree, Putere, Rezervor, CMM, CMU, CME,
    TipIncarc, Greutate, MasaMax, MasaUtil, MasaURDF, MasaURFDF,
    VolumUtil, LocTot, LocFata, LocSpate, LocPic, Status,
    PartLeas, 
		MONEDA, DATAACHIZ, DATAENDLEAS, NRCONTR,
		RataLeas, RataCasco, RataRCA, KMBORD, DATABORD &apos;||gUserFields||&apos;)

  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)

  SELECT
    pa.codnparcaut, 505,
    o.denumire, pa.nrinv, (s.nume||&apos;&apos; &apos;&apos;||s.prenume) sofer, g.den_gest, gt.den_gest,Decode(pa.tip,0,&apos;&apos;MOTORIZAT&apos;&apos;,&apos;&apos;TRACTAT&apos;&apos;) tip,
    pa.nrinreg, pa.datainreg, ma.marca, mo.model, pa.anf, pa.seriec, pa.culoareC, pa.lung, pa.lat, pa.inalt,
    pa.tipmotor, pa.seriem, pa.sursae, pa.cilindree, pa.putere, pa.rezervor, pa.cmm, pa.cmu, pa.cme,
    Decode(tipincarc,1,&apos;&apos;Marfa&apos;&apos;,2,&apos;&apos;Persoane&apos;&apos;,3,&apos;&apos;Mixta&apos;&apos;) tipincarc, pa.greutate, pa.masam, pa.masau, pa.masaurdf, pa.masaurfdf,
    pa.volumu, pa.loct, pa.locf, pa.locs, pa.locp, 
    Decode(PA.INACTIV,0,&apos;&apos;Activ&apos;&apos;,2,&apos;&apos;Conservare&apos;&apos;,3,&apos;&apos;Dauna totala&apos;&apos;,4,&apos;&apos;La vanzare&apos;&apos;,1,&apos;&apos;Vandut&apos;&apos;,5,&apos;&apos;Radiat&apos;&apos;) Status,
    NP.Den_part, 
		M.Simbol, PA.DATAACHIZ, PA.DATAENDLEAS, PA.NRCONTR,
		PA.RataLeas, PA.RataCasco,PA.RataRca,p0.kmbord,p0.databord &apos;||gUserAlias||&apos;
  FROM nparcaut pa
    LEFT JOIN NMonede M on M.CodMoneda = PA.Moneda 
    LEFT JOIN npers s on s.codpers = pa.sofer
    LEFT JOIN NPART NP on NP.CodPart = PA.PartLeas
    LEFT JOIN (select nrinventar, max(codmifix) codmifix from mifix where tip = &apos;&apos;MF&apos;&apos; group by nrinventar) mfx ON mfx.nrinventar = pa.nrinv
    left join mifix mf on mf.codmifix = mfx.codmifix
    LEFT JOIN (select distinct CodMifix, CodNirStoc from mifix1) mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN ngest gt ON gt.codgest = pa.codgest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model
    LEFT JOIN (
      SELECT codnparcaut, Max(databord) databord, Max(kmbord) Keep (Dense_Rank Last ORDER BY databord) kmbord
      FROM nparc0
      WHERE Nvl(kmbord,0) &lt;&gt; 0
      GROUP BY codnparcaut
    ) p0 ON p0.codnparcaut = pa.codnparcaut
    &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PARCAUTO; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOANV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2D488BB94DF1B6B3EC279D37DC004BD0EE45BBC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_parcautoanv IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN

  gSuplCols := &apos;nparcaut pa, nparc1 p1, nartobj anv, nart nart, num um, npers s, mifix mf, nirstoc ns, ngest g, nartobj o &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    Den, NrInv, Sofer, Gest, Tip,
    NrInreg, DataInreg, Marca, Model, AnFab, SerieC, Culoare, Lung, Lat, Inalt,
    TipMotor, SerieMotor, Combustibil, Cilindree, Putere, Rezervor, CMM, CMU, CME,
    TipIncarc, Greutate, MasaMax, MasaUtil, MasaURDF, MasaURFDF,
    VolumUtil, LocTot, LocFata, LocSpate, LocPic,
    AnvRecF, AnvRecS, AnvOp1F, AnvOp1S, AnvOp2F, AnvOp2S,
    Anvelopa, UM, Cant, Poz, BordInstal, Atentie,
    Montat,Anotimp,Hotel&apos;||
    gUserFields||&apos;)
  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)
  SELECT
    pa.codnparcaut, 505,
    o.denumire, pa.nrinv, (s.nume||&apos;&apos; &apos;&apos;||s.prenume) sofer, g.den_gest, Decode(pa.tip,0,&apos;&apos;TRACTAT&apos;&apos;,&apos;&apos;MOTORIZAT&apos;&apos;) tip,
    pa.nrinreg, pa.datainreg, ma.marca, mo.model, pa.anf, pa.seriec, pa.culoarec, pa.lung, pa.lat, pa.inalt,
    pa.tipmotor, pa.seriem, pa.sursae, pa.cilindree, pa.putere, pa.rezervor, pa.cmm, pa.cmu, pa.cme,
    Decode(tipincarc,1,&apos;&apos;Marfa&apos;&apos;,2,&apos;&apos;Persoane&apos;&apos;,3,&apos;&apos;Mixta&apos;&apos;) tipincarc, pa.greutate, pa.masam, pa.masau, pa.masaurdf, pa.masaurfdf,
    pa.volumu, pa.loct, pa.locf, pa.locs, pa.locp,
    pa.anvrecomf, pa.anvrecoms, pa.anvopt1f, pa.anvopt1s, pa.anvopt2f, pa.anvopt2s,
    anv.denumire, um.den_um, p1.cant, p1.pozitie, p1.bordinstal, p1.atentie,
    p1.Montat, p1.Anotimp, HT.DEN_PART&apos;||
    gUserAlias||&apos;
  FROM nparcaut pa
    INNER JOIN nparc1 p1 ON p1.cod = pa.codnparcaut
    LEFT JOIN nartobj anv on anv.codobiect = p1.art
    LEFT JOIN nart nart on nart.codarticol = anv.codarticol
    LEFT JOIN num um on um.codum = nart.um
    LEFT JOIN npers s on s.codpers = pa.sofer
    LEFT JOIN mifix mf ON mf.nrinventar = pa.nrinv
    LEFT JOIN mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model
    LEFT JOIN NPART HT ON HT.CODPART = P1.CODPART&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PARCAUTOANV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>737DE60852CD398114D9B2426FD572E17862AEFA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PARCAUTOAUT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;nparcaut pa, nparc2 p2, npers s, mifix mf, nirstoc ns, ngest g, nartobj o &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,    
    NAV_TipDoc,
    Den, NrInv, Sofer, Gest, Tip,
    NrInreg, DataInreg, Marca, Model, AnFab, SerieC, Culoare, Lung, Lat, Inalt,
    TipMotor, SerieMotor, Combustibil, Cilindree, Putere, Rezervor, CMM, CMU, CME,
    TipIncarc, Greutate, MasaMax, MasaUtil, MasaURDF, MasaURFDF,
    VolumUtil, LocTot, LocFata, LocSpate, LocPic,
    Aut, Sn, Eliberat, Expira, Atentie &apos;||
    gUserFields||&apos;)
  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)
  SELECT
    pa.codnparcaut, 505,
    o.denumire, pa.nrinv, (s.nume||&apos;&apos; &apos;&apos;||s.prenume) sofer, g.den_gest, Decode(pa.tip,0,&apos;&apos;TRACTAT&apos;&apos;,&apos;&apos;MOTORIZAT&apos;&apos;) tip,
    pa.nrinreg, pa.datainreg, ma.marca, mo.model, pa.anf, pa.seriec, pa.culoare, pa.lung, pa.lat, pa.inalt,
    pa.tipmotor, pa.seriem, pa.sursae, pa.cilindree, pa.putere, pa.rezervor, pa.cmm, pa.cmu, pa.cme,
    Decode(tipincarc,1,&apos;&apos;Marfa&apos;&apos;,2,&apos;&apos;Persoane&apos;&apos;,3,&apos;&apos;Mixta&apos;&apos;) tipincarc, pa.greutate, pa.masam, pa.masau, pa.masaurdf, pa.masaurfdf,
    pa.volumu, pa.loct, pa.locf, pa.locs, pa.locp,
    nvl(aut.denumire, auti.denumire), p2.sn, p2.eliberat, p2.expira, p2.atentie &apos;||
    gUserAlias||&apos;
  FROM nparcaut pa
    INNER JOIN nparc2 p2 ON p2.cod = pa.codnparcaut
    LEFT JOIN nautorizatiiauto aut ON aut.codautorizatii = p2.doc
    LEFT JOIN intrari1 i1 on p2.codintr1 = i1.codintr1
    LEFT JOIN nautorizatiiauto auti ON auti.codserviciu = i1.codobiect
    LEFT JOIN npers s on s.codpers = pa.sofer
    LEFT JOIN mifix mf ON mf.nrinventar = pa.nrinv AND mf.tip = &apos;&apos;MF&apos;&apos;
    LEFT JOIN mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PARCAUTOAUT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOCARB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>179D88C9994E9BA7303D702AAEEB4224C6BCA3B5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PARCAUTOCARB IS

  vAnLunaIni  INTEGER;
  vAnLunaFin  INTEGER;
  vDistZile   BOOLEAN;
  vConsZile   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  vAn     NUMBER;
  vLuna   NUMBER;
  vNrZile NUMBER := 31;
  vTipA   NUMBER := 2;
  vTipB   NUMBER := 1;
BEGIN
  DELETE tmp_dinamic_cols;
  IF vDistZile OR vConsZile THEN
    pkg_list_base_utils.ExtractAnLuna(vAnLunaIni, vAn, vLuna);
    vNrZile := EXTRACT (DAY FROM LAST_DAY(To_Date(vAn||&apos;.&apos;||vLuna,&apos;yyyy.mm&apos;)));

    IF vDistZile THEN vTipA := 1; END IF;
    IF vConsZile THEN vTipB := 2; END IF;

    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, COD, COD2)
    SELECT &apos;D&apos;||ROWNUM, CASE WHEN TIP = 1 THEN &apos;KM/&apos; ELSE &apos;CONS./&apos; END||ZI, ROWNUM, ZI, TIP
    FROM (
      SELECT Z.ZI, T.TIP
      FROM (SELECT LEVEL ZI FROM DUAL CONNECT BY LEVEL &lt;= 31) Z
      CROSS JOIN (SELECT LEVEL TIP FROM DUAL CONNECT BY LEVEL &lt;= 2) T
      WHERE T.TIP BETWEEN vTipA AND vTipB
      ORDER BY Z.ZI, T.TIP
    );
  END IF;
END;

PROCEDURE SETPARAMS(
  pAnLunaIni IN NUMBER DEFAULT NULL,
  pAnLunaFin IN NUMBER DEFAULT NULL,
  pDistZile  IN NUMBER DEFAULT 0,
  pConsZile  IN NUMBER DEFAULT 0,
  v_CodJob1  IN NUMBER DEFAULT 0
) IS
  dDataS Date;
  dDataF Date;
BEGIN
  vAnLunaIni := pAnLunaIni;
  vAnLunaFin := pAnLunaFin;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(v_CodJob1,dDataS,dDataF,vAnLunaIni,vAnLunaFin);
  END IF;
  vDistZile   := pDistZile = 1 AND (pAnLunaIni = pAnLunaFin);
  vConsZile   := pConsZile = 1 AND (pAnLunaIni = pAnLunaFin);
  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(30000);
  sInsDC     VARCHAR2(10000);
  sSelDC     VARCHAR2(10000);
  sColDc     VARCHAR2(10000);
  sKMZi      VARCHAR2(10000);
  pStocComb  VARCHAR2(10000);
  pServComb  VARCHAR2(10000);
BEGIN

  gSuplCols := &apos;nparcaut pa, npers s, nartobj o, nart a, nclasea ca&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;,&apos;);
  pStocComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtStocCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;
  pServComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtServCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;

  IF vDistZile OR vConsZile THEN
    FOR i IN 1..31 LOOP
      sKMZi := sKMZi||&apos;,SUM(DECODE(zi,&apos;||i||&apos;,km,0)) Z&apos;||i;
    END LOOP;
  END IF;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD2 = 1 ORDER BY COD) LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, Nvl(kml.z&apos;||vRec.COD||&apos;,0)&apos;;
  END LOOP;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD2 = 2 ORDER BY COD) LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, Nvl(pa.cmm*kml.z&apos;||vRec.COD||&apos;,0)&apos;;
  END LOOP;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NRAUTO, SOFER, ART, CLASA, AN, LUNA, KMLUNA, COMBCANT, COMBVAL,
    CONSUMMEDIU,
    PRETMEDIU,
    TOTALROLKM &apos;||sInsDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  AG AS (
    SELECT codauto, an, luna, sum(combcant) combcant, sum(combval) combval&apos;||sColDC||&apos;
    FROM (
      SELECT
        CASE WHEN NVL(i1.codauto,0) = 0 THEN i.codauto ELSE i1.codauto END codauto, i.an, i.luna,
        i1.cant combcant, (i1.pu * i1.cant - CASE WHEN i.tipdoc IN (3) then nvl(i1.tva,0) ELSE 0 END) * DECODE(i.curs,NULL,1,0,1,i.curs) combval
      FROM intrari i
        INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
      WHERE (Nvl(i1.codauto,0) &lt;&gt; 0 OR Nvl(i.codauto,0) &lt;&gt; 0)
        AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND i1.codobiect IN (&apos;||pServComb||&apos;)
      UNION ALL
      SELECT
        i.codauto, i.an, i.luna,
        i1.cant combcant, (i1.pu * i1.cant - CASE WHEN i.tipdoc IN (16,21) then nvl(i1.tva,0) ELSE 0 END) * DECODE(i.curs,NULL,1,0,1,i.curs) combval
      FROM iesiri i
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      WHERE Nvl(i.codauto,0) &lt;&gt; 0
        AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND i1.tiplinie = &apos;&apos;=&apos;&apos;
        AND i1.codobiect IN (&apos;||pStocComb||&apos;)
    )
    GROUP BY codauto, an, luna),
  KMLUN AS (
    SELECT codnparcaut, an, luna, Sum(km) kmluna &apos;||sKMZi||&apos;
    FROM (
      SELECT
        p.codnparcaut, p0.luna, p0.an, EXTRACT (DAY FROM p0.databord) zi,
        p0.kmbord - COALESCE(Lag(p0.kmbord) OVER (PARTITION BY p.codnparcaut ORDER BY p0.databord),p.kmpornire,0) km
      FROM nparc0 p0 INNER JOIN nparcaut p ON p.codnparcaut = p0.codnparcaut)
    WHERE an*12+luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
    GROUP BY codnparcaut, an, luna)
  SELECT
    PA.NRINREG, S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME, O.DENUMIRE, CA.DEN_CLASEA, AG.AN, AG.LUNA, KML.KMLUNA, AG.COMBCANT, AG.COMBVAL,
    CASE WHEN Nvl(KML.KMLUNA,0) =0 THEN 0 ELSE (AG.COMBCANT/KML.KMLUNA)*100 END CONSUMMEDIU,
    CASE WHEN Nvl(AG.COMBCANT,0)=0 THEN 0 ELSE (AG.COMBVAL/AG.COMBCANT)*100 END PRETMEDIU,
    CASE WHEN Nvl(KML.KMLUNA,0) =0 THEN 0 ELSE (AG.COMBVAL/KML.KMLUNA) *100 END TOTALROLKM &apos;||sSelDC||gUserAlias||&apos;
  FROM AG
    INNER JOIN nparcaut pa ON pa.codnparcaut = ag.codauto
    LEFT JOIN npers s ON s.codpers = NVL(pa.sofer,0)
    LEFT JOIN nartobj o ON o.codobiect = pa.codart
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = NVL(a.clasa,0)
    LEFT JOIN kmlun kml ON kml.codnparcaut = ag.codauto AND kml.an = ag.an AND kml.luna = ag.luna&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_PARCAUTOCARB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E9174439D6FEDE7E919A1C9E485C907B99CEAAC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_parcautochelt IS

  vAnLunaIni  INTEGER;
  vAnLunaFin  INTEGER;
  vCC0        BOOLEAN;
  vExclCont   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
BEGIN
  DELETE tmp_dinamic_cols;
  INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2) VALUES (&apos;CC0&apos;,  &apos;Total&apos;, 0, 0, 0);

  INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal, Cod, Cod2)
  SELECT &apos;CC&apos;||ROWNUM, Denumire, ROWNUM, CodCentru, 0
  FROM (
    SELECT CODCENTRU, DENUMIRE
    FROM CENTRECOST
    WHERE CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
      AND CODCENTRU &gt; 0
    ORDER BY CODCENTRU
  );
END;

FUNCTION  xCodCentru(     pCodCont IN NUMBER,
                          pAnLuna IN NUMBER)
RETURN NUMBER IS
  vResult NUMBER;
BEGIN
  SELECT Nvl(NC1.CODCENTRU,0)
  INTO vResult
  FROM NCONT1 NC1
  WHERE nc1.codcont = pCodCont
    AND pAnLuna BETWEEN NC1.ALSTART and NC1.ALSTOP;

  RETURN vResult;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION  ContCodCentru(  pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pCodCont1 IN NUMBER,
                          pCodCont2 IN NUMBER DEFAULT NULL)
RETURN NUMBER IS
  vResult NUMBER;
BEGIN
  vResult := Nvl(pCodAuto,0);
  IF vResult = 0 THEN
    vResult := PKG_LIST_BASE_PARCAUTOCHELT.xCodCentru(pCodCont1,pAnLuna);
  END IF;
  IF vResult = 0 AND Nvl(pCodCont2,0) &lt;&gt; 0 THEN
    vResult := PKG_LIST_BASE_PARCAUTOCHELT.xCodCentru(pCodCont2,pAnLuna);
  END IF;
  RETURN vResult;
END;


FUNCTION  IContCodCentru( pCodAuto  IN NUMBER,
                          pAnLuna   IN NUMBER,
                          pICont    IN NUMBER,
                          pCodPart  IN NUMBER,
                          pSemnif   IN NUMBER)
RETURN NUMBER IS
  vResult   NUMBER;
BEGIN
  vResult := Nvl(pCodAuto,0);
  IF vResult = 0 THEN
    vResult := PKG_LIST_BASE_PARCAUTOCHELT.xCodCentru(pkg_list_base_utils.iCont_CodCont(pICont,pCodPart,pAnLuna,pSemnif),pAnLuna);
  END IF;
  RETURN vResult;
END;

PROCEDURE SETPARAMS(pAnLunaIni IN NUMBER DEFAULT NULL,
                    pAnLunaFin IN NUMBER DEFAULT NULL,
                    pCC0       IN NUMBER DEFAULT 0,
                    V_CODJOB1  IN NUMBER,
                    pExclCont  IN NUMBER DEFAULT 0
                    ) IS
xLunaAnIni INTEGER;
xLunaAnFin INTEGER;
sDataS     VARCHAR2(10);
sDataF     VARCHAR2(10);
xAn        number(4);
xLuna      number(2);
gDataS     date;
gDataF     date;
BEGIN
  xLunaAnIni  := pAnLunaIni;
  xLunaAnFin  := pAnLunaFin;
  if Trunc(xLunaAnIni/12) = xLunaAnIni/12 then
    xAn := xLunaAnIni/12 - 1;
    xLuna := 12;
  else
    xAn := Trunc(xLunaAnIni/12);
    xLuna := xLunaAnIni - Trunc(xLunaAnIni/12) * 12;
  end if;
  sDataS := &apos;01.&apos;||LPAD(to_char(xLuna),2,&apos;0&apos;)||&apos;.&apos;||to_char(xAn);
  
  if Trunc(xLunaAnFin/12) = xLunaAnFin/12 then
    xAn := xLunaAnFin/12 - 1;
    xLuna := 12;
  else
    xAn := Trunc(xLunaAnFin/12);
    xLuna := xLunaAnFin - Trunc(xLunaAnFin/12) * 12;
  end if;
  sDataF := to_char(LAST_DAY(to_date(&apos;01.&apos;||LPAD(to_char(xLuna),2,&apos;0&apos;)||&apos;.&apos;||to_char(xAn),&apos;dd.mm.yyyy&apos;)),&apos;dd.mm.yyyy&apos;);
  
  vCC0        := pCC0 = 1;
  vExclCont   := pExclCont = 1;
  BAGA_DINAMIC_COLS;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vAnLunaIni  := xLunaAnIni;
  vAnLunaFin  := xLunaAnFin;
  gDataS := to_date(sDataS,&apos;dd.mm.yyyy&apos;);
  gDataF := to_date(sDataF,&apos;dd.mm.yyyy&apos;);
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(gDataS,gDataF);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(30000);
  sInsDC     VARCHAR2(10000);
  sSelDC     VARCHAR2(10000);
  sColDc     VARCHAR2(10000);
  sKMZi      VARCHAR2(10000);
  pStocComb  VARCHAR2(10000);
  pServComb  VARCHAR2(10000);
  sFiltruCC0 VARCHAR2( 1000);
  sFiltruCont VARCHAR2( 1000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols := &apos;nparcaut pa, npers s, nartobj o, nart a, nclasea ca&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_globals.SetSeparator(&apos;,&apos;);
  pStocComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtStocCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;
  pServComb  := Nvl(pkg_categconst.GetValConstanta(&apos;ArtServCombustibil&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),0) ;

  sInsDC := &apos;, CC0&apos;;
  sSelDC := &apos;, AG.CC0&apos;;
  sColDC := &apos;, SUM(valoare) CC0&apos;;

  FOR vRec IN (SELECT FIELDNAME, COD FROM tmp_dinamic_cols WHERE COD &lt;&gt; 0 AND COD2 = 0 ORDER BY COD)
  LOOP
    sInsDC := sInsDC||&apos;, &apos;||vRec.FIELDNAME;
    sSelDC := sSelDC||&apos;, AG.&apos;||vRec.FIELDNAME;
    sColDC := sColDC||&apos;,
      SUM(DECODE(codcentru,&apos;||vRec.COD||&apos;,valoare,0)) &apos;||vRec.FIELDNAME;
  END LOOP;

  IF NOT vCC0 THEN
    sFiltruCC0 := &apos;
    WHERE Nvl(codcentru,0) &lt;&gt; 0&apos;;
  END IF;
  sFiltruCont := &apos;&apos;;
  if vExclCont then
    sFiltruCont := &apos; and not exists &apos;||chr(13)||
                   &apos;      (select cv.valoare from constval cv, constluna cl, const1 cc &apos;||chr(13)||
                   &apos;       where cc.simbol = &apos;&apos;CContCheltAvans&apos;&apos; and cl.codconst1 = cc.codconst1 and cv.codconstluna = cl.codconstluna &apos;||chr(13)||
                   &apos;       and i.an*12+i.luna between cl.alstart and cl.alstop and cv.valoare = a.contimplicit) &apos;;
  end if;
  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||
   &apos;(NRAUTO, SOFER, ART, CLASA, AN, LUNA&apos;||sInsDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH COSTURI AS (
    SELECT
      CASE WHEN NVL(i1.codauto,0) = 0 THEN i.codauto ELSE i1.codauto END codauto,
      PKG_LIST_BASE_PARCAUTOCHELT.ContCodCentru(i1.codcentru,i.an*12+i.luna,i1.contserv) codcentru,
      i.an, i.luna, (i1.pu * i1.cant - DECODE(i.tipdoc,3,nvl(i1.tva,0),0)) * DECODE(i.curs,NULL,1,0,1,i.curs) valoare
    FROM intrari i
      INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
      inner join nartobj o on o.codobiect = i1.codobiect
      inner join nart a on a.codarticol = o.codarticol
    WHERE (Nvl(i1.codauto,0) &lt;&gt; 0 OR Nvl(i.codauto,0) &lt;&gt; 0)
      AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||sFiltruCont||&apos;
    UNION ALL
    SELECT
      i.codauto, Nvl(j.codcentru,0) codcentru, j.an, j.luna, j.valoare
    FROM iesiri i
      INNER JOIN jurnal j ON j.coddoc = i.codies AND j.tipdoc = i.tipdoc
    WHERE Nvl(i.codauto,0) &lt;&gt; 0
      AND i.an*12+i.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      o.codnparcaut codauto,
      PKG_LIST_BASE_PARCAUTOCHELT.IContCodCentru (o.codcentru,t.an*12+t.luna,o.icont,o.codpart,o.semnificatie) codcentru,
      t.an, t.luna, o.valoare
    FROM trezor t
      inner join trezor1  t1 ON t1.codtrezor = t.codtrezor
      inner join general  g  ON g.coddoc     = t1.codtrezor1 AND g.tipdoc = t.tipdoc
      inner join obligpif o  ON o.codgeneral = g.codgeneral
    WHERE Nvl(o.codnparcaut,0) &lt;&gt; 0
      AND t.an*12+t.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
      AND T1.ANULAT = 0 AND T.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
    UNION ALL
    SELECT
      nc1.codauto,
      PKG_LIST_BASE_PARCAUTOCHELT.ContCodCentru(nc1.codcentru,nc1.an*12+nc1.luna,nc1.contd,nc1.contc) codcentru,
      nc1.an, nc1.luna, nc1.valoare * DECODE(nc.curs,NULL,1,0,1,nc.curs)
    FROM nc1
      INNER JOIN nc ON nc.codnc = nc1.codnc
    WHERE Nvl(nc1.codauto,0) &lt;&gt; 0
      AND nc1.an*12+nc1.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;)||&apos;
    UNION ALL
    SELECT
      pa.codnparcaut codauto, Nvl(j.codcentru,0) codcentru, j.an, j.luna, j.valoare
    FROM jurnal j
      INNER JOIN mifix    mf ON mf.codmifix = j.coddoc
      INNER JOIN nparcaut pa ON pa.nrinv    = mf.nrinventar
    WHERE j.tipdoc = 36
      AND j.an*12+j.luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;J&apos;)||&apos;
  ),
  AG AS (
    SELECT codauto, an, luna&apos;||sColDC||&apos;
    FROM Costuri&apos;||
    sFiltruCC0||&apos;
    GROUP BY codauto, an, luna),
  KMLUN AS (
    SELECT codnparcaut, an, luna, Sum(km) kmluna &apos;||sKMZi||&apos;
    FROM (
      SELECT
        p.codnparcaut, p0.luna, p0.an, EXTRACT (DAY FROM p0.databord) zi,
        p0.kmbord - COALESCE(Lag(p0.kmbord) OVER (PARTITION BY p.codnparcaut ORDER BY p0.databord),p.kmpornire,0) km
      FROM nparc0 p0 INNER JOIN nparcaut p ON p.codnparcaut = p0.codnparcaut)
    WHERE an*12+luna BETWEEN &apos;||vAnLunaIni||&apos; AND &apos;||vAnLunaFin||&apos;
    GROUP BY codnparcaut, an, luna)
  SELECT
    PA.NRINREG, S.NUME||&apos;&apos; &apos;&apos;||S.PRENUME, O.DENUMIRE, CA.DEN_CLASEA, AG.AN, AG.LUNA &apos;||sSelDC||gUserAlias||&apos;
  FROM AG
    INNER JOIN nparcaut pa  ON pa.codnparcaut  = ag.codauto
    LEFT  JOIN npers    s   ON s.codpers       = NVL(pa.sofer,0)
    LEFT  JOIN nartobj  o   ON o.codobiect     = pa.codart
    LEFT  JOIN nart     a   ON a.codarticol    = o.codarticol
    LEFT  JOIN nclasea  ca  ON ca.codclasea    = NVL(a.clasa,0)
    LEFT  JOIN kmlun    kml ON kml.codnparcaut = ag.codauto AND kml.an = ag.an AND kml.luna = ag.luna&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_PARCAUTOCHELT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PARCAUTOINTERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB3EA1C1A550543F024FAD6B475963F51E749076</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_parcautointerv IS
  sZi1 VARCHAR2(50);
  sZi2 VARCHAR2(50);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE)
IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;nparcaut pa, nparc3 p3, ninterventiiauto interv, npers s, mifix mf, nirstoc ns, ngest g, nartobj o &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    Den, NrInv, Sofer, Gest, Tip,
    NrInreg, DataInreg, Marca, Model, AnFab, SerieC, Culoare, Lung, Lat, Inalt,
    TipMotor, SerieMotor, Combustibil, Cilindree, Putere, Rezervor, CMM, CMU, CME,
    TipIncarc, Greutate, MasaMax, MasaUtil, MasaURDF, MasaURFDF,
    VolumUtil, LocTot, LocFata, LocSpate, LocPic,
    interv, datau, kmu, datav, kmv, dataa, kma, kmbord, databord &apos;||
    gUserFields||&apos;)
  WITH mf1 AS (SELECT codmifix, Max(codnirstoc) codnirstoc FROM mifix1 GROUP BY codmifix)
  SELECT
    pa.codnparcaut, 505,
    o.denumire, pa.nrinv, (s.nume||&apos;&apos; &apos;&apos;||s.prenume) sofer, g.den_gest, Decode(pa.tip,0,&apos;&apos;TRACTAT&apos;&apos;,&apos;&apos;MOTORIZAT&apos;&apos;) tip,
    pa.nrinreg, pa.datainreg, ma.marca, mo.model, pa.anf, pa.seriec, pa.culoare, pa.lung, pa.lat, pa.inalt,
    pa.tipmotor, pa.seriem, pa.sursae, pa.cilindree, pa.putere, pa.rezervor, pa.cmm, pa.cmu, pa.cme,
    Decode(tipincarc,1,&apos;&apos;Marfa&apos;&apos;,2,&apos;&apos;Persoane&apos;&apos;,3,&apos;&apos;Mixta&apos;&apos;) tipincarc, pa.greutate, pa.masam, pa.masau, pa.masaurdf, pa.masaurfdf,
    pa.volumu, pa.loct, pa.locf, pa.locs, pa.locp,
    interv.denumire, p3.datau, p3.kmu, p3.datav, p3.kmv, p3.dataa, p3.kma, p0.kmbord, p0.databord&apos;||gUserAlias||&apos;
  FROM nparcaut pa
    INNER JOIN nparc3 p3 ON p3.cod = pa.codnparcaut
    LEFT JOIN ninterventiiauto interv ON interv.codinterventiiauto = p3.interventie
    LEFT JOIN npers s on s.codpers = pa.sofer
    LEFT JOIN mifix mf ON mf.nrinventar = pa.nrinv
    LEFT JOIN (select m1.codnirstoc, m1.codmifix from mifix1 m1 where m1.anstart*12+m1.lunastart = (select max(m11.anstart*12+m11.lunastart) from mifix1 m11 where m11.codmifix = m1.codmifix)) mf1 ON mf1.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON ns.codnirstoc = mf1.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest g ON g.codgest = n.gest
    LEFT JOIN nartobj o on o.codobiect = pa.codart
    LEFT JOIN nmarciauto ma ON ma.codmarciauto = pa.marca
    LEFT JOIN nmodeleauto mo ON mo.codmodeleauto = pa.model
    LEFT JOIN 
    (
      SELECT codnparcaut, Max(databord) databord, Max(kmbord) Keep (Dense_Rank Last ORDER BY databord) kmbord
      FROM nparc0
      WHERE Nvl(kmbord,0) &lt;&gt; 0
      GROUP BY codnparcaut
    ) p0 ON p0.codnparcaut = pa.codnparcaut
    &apos;||gSuplJoins||&apos; where ((PKG_LIST_ALEGPERIOADA.getDataS between P3.DataV and P3.DataU) 
                      or PKG_LIST_ALEGPERIOADA.getDataF between P3.DataV and P3.DataU)
                      or(P3.DataV between PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
                      or P3.DataU between PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PARCAUTOINTERV; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PENALITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A26303E56C0B91B4C2097EA23197B4CCF359D83</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PENALITATI is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  p_CodProdComp NUMBER(20) default 0;
  p_CodComanda1 NUMBER(20) default 0;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELDATA.ChkExtra1 THEN
    PKG_NOTECREDIT.GEN_TMP_PEN(0,TO_CHAR(PKG_LIST_SELDATA.GetDataRef,&apos;DD.MM.YYYY&apos;),0,1,1,TO_CHAR(PKG_LIST_SELDATA.GetDataRef,&apos;DD.MM.YYYY&apos;),1,1,0);
  ELSE
    PKG_NOTECREDIT.GEN_TMP_PEN(0,TO_CHAR(PKG_LIST_SELDATA.GetDataRef,&apos;DD.MM.YYYY&apos;),0,1,1,TO_CHAR(PKG_LIST_SELDATA.GetDataRef,&apos;DD.MM.YYYY&apos;),1,0,0);
  END IF;  

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    CODOBLIGPIF,                                       
    PREFIXDOC,                                         
    NRDOC,                                             
    DATADOC,                                           
    VALDOC,                                            
    TERMEN,                                            
    REST,                                              
    MAJORARI,                                          
    LOCATIE,                                           
    DEN_PART,                                          
    DEN_SUBUNIT,                                       
    MONEDA,                                            
    MAJANTERIOARE,                                     
    DATA_LAST_FACTMAJ,                                 
    DATA_LAST_PLATA,                                   
    GRATIEDOC,                                         
    STORNO,                                            
    SCADENTAV,
    VALMAJ,
    RESTLADATA,
    ZILE &apos;||gUserFields||&apos;)                       
  SELECT                                               
    tmp.CODOBLIGPIF,                                       
    tmp.PREFIXDOC,                                         
    tmp.NRDOC,                                             
    tmp.DATADOC,                                           
    tmp.VALDOC,                                            
    tmp.TERMEN,                                            
    tmp.REST,                                              
    tmp.MAJORARI,                                          
    tmp.LOCATIE,
    tmp.DEN_PART,        
    tmp.DEN_SUBUNIT,     
    m.simbol MONEDA,          
    tmp.MAJANTERIOARE,   
    tmp.DATA_LAST_FACTMAJ,
    tmp.DATA_LAST_PLATA, 
    tmp.GRATIEDOC,
    tmp.STORNO,
    tmp.SCADENTAV,
    tmp.VALMAJ,
    tmp.RESTLADATA,
    tmp.Zile &apos;||gUserAlias||&apos;
  FROM tmp_gen_penalitati tmp 
       left join nmonede m on m.codmoneda = coalesce(tmp.moneda,0)&apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_PENALITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F070CF8D95BF171A53A1F5F4D9F4C51C72D0161</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_perscontact IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);



PROCEDURE processlist (tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
BEGIN
  gSuplCols := &apos;npart p, nperscontact pc, nagenda a, npers ag, nparttr del&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

	sInsert :=
  &apos;INSERT INTO &apos;||tmp_name||&apos; (
    DEN_PART,
    ADRESAP,
    NUME,PRENUME,TELEFON,EMAIL,FUNCTIE,DATANASTERE,ID,RZONA&apos;||
    gUserFields||&apos;)
  SELECT
    p.den_part,
    GetAdresa(a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal) adresaP,
    pc.nume,pc.prenume,pc.telefon,pc.email,pc.functie,pc.datanastere,pc.id,decode(pc.rzona,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;) RZONA&apos;||
    gUserAlias||&apos;
  FROM npart p
    INNER JOIN nperscontact pc ON p.codpart = pc.codpart
    LEFT JOIN nagenda a ON a.codpart = p.codpart AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0
    LEFT JOIN npers ag ON ag.codpers = a.codagent
    left join nparttr del on del.codparttr = p.codpart - p.codpart &apos;||
    gSuplJoins||&apos;
  UNION ALL
  SELECT
    p.den_part,
    GetAdresa(a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal) adresaP,
    del.delegat,cast(null as varchar2(200)),del.telefon,del.email,cast(null as varchar2(100)),del.datadoc,cast(null as number(27,7)),&apos;&apos;Da&apos;&apos; &apos;||
    gUserAlias||&apos;
  FROM NPARTTR DEL
    INNER JOIN npart p ON p.codpart = del.codpart
    LEFT JOIN nagenda a ON a.codpart = del.codpart AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0
    LEFT JOIN npers ag ON ag.codpers = a.codagent
    left join nperscontact pc on pc.codpersc = p.codpart - p.codpart&apos;||
    gSuplJoins;  
    
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_perscontact; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PERSLEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA86B5BE615833C8E40C4DC997B4693608D501BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PERSLEG IS

 PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID in NUMBER default 0 ,aListVer in NUMBER default 0) IS
  sInsert VARCHAR2(500);
 BEGIN
   sInsert := &apos;INSERT INTO &apos;||tmpName||&apos; (DEN_PART,NUME,PRENUME,TELEFON,EMAIL,FUNCTIE,DATANASTERE,RZONA,ID) &apos;||
	            &apos;SELECT np.den_part, &apos;||
                     &apos;pc.nume,pc.prenume,pc.telefon,pc.email,pc.functie,pc.datanastere, &apos;||
			               &apos;decode(pc.rzona,1,&apos;&apos;Da&apos;&apos;,0,&apos;&apos;Nu&apos;&apos;) rzona,pc.ID &apos;||
              &apos;FROM npart np INNER JOIN nperscontact pc ON np.codpart = pc.codpart &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);            
	COMMIT;
 
 END;	
 
procedure  setJoinuri is 
begin 
   Pkg_List_Struct.SetTableSpec(&apos;&apos;);
   pkg_list_struct.AdunaColoanele;
end; 
end PKG_LIST_BASE_PERSLEG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EC0C593F3E55D324D3A2DDE52A1F984EC46A42E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PF IS

  vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
  vTabla   VARCHAR2(50);
BEGIN
  gSuplCols := &apos;NGEST NG, COMANDA1 C1, COMANDA C, NARTOBJ NOBJ, NUM1 NUM1, COMANDA1 C1CLIENT, COMANDA CCLIENT, NPART NP, PROGRAMF1 PF1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla, &apos;CCV&apos;, &apos;CCV.CODCOMANDA = CCLIENT.CODCOMANDA&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    PRIORITATE,
    CANTPROGRAMAT,
    DEN_GEST,
    NRCMD,
    DEN_OBIECT,
    CODEXTERN,
    UM,
    TERMENEXEC,
    DEN_CLIENT,
    TERMENLIVR,
    DURATA,
    DataOraStart,
    DataOraStop,
    Formatie,
    Schimb,
    Rest
    &apos;||gUserFields||&apos;)
  SELECT PF1.PRIORITATE,
    PF1.CANTPROGRAMAT,
    NG.DEN_GEST,
    C.NRDOC,
    NOBJ.DENUMIRE,
    NOBJ.CODEXTERN,
    NUM1.DEN_UM1,
    NVL(PF1.TERMEN,C1.TERMEN),
    NP.DEN_PART,
    c1client.termen,
    PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * PC.DURATA,
    PF.VDELA
    - (PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (PC.DURATA/60) / 24)
    + SUM(PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (PC.DURATA/60) / 24)
    over (PARTITION BY PF1.CODGEST ORDER BY PF1.PRIORITATE ROWS BETWEEN unbounded preceding AND CURRENT ROW ),
    PF.VDELA
    + SUM(PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (PC.DURATA/60) / 24)
    over (PARTITION BY PF1.CODGEST ORDER BY PF1.PRIORITATE ROWS BETWEEN unbounded preceding AND CURRENT ROW ),
    FR.Den_Formatie,
    PF1.Schimb,
    PF1.CANTPROGRAMAT - nvl((select sum(l.cant) from intrprodlink l where l.codprogramf1 = pf1.CODPROGRAMF1),0) &apos;||gUserAlias||&apos;
  FROM PROGRAMF1 PF1
    INNER JOIN PROGRAMF PF ON PF1.CODPROGRAMF = PF.CODPROGRAMF
    INNER JOIN NGEST NG ON NG.CODGEST = PF1.CODGEST
    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
    INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
    INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
    INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
    INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
    LEFT  JOIN FORMATII FR ON PF1.CodFormatie = FR.CodFormatie
    LEFT  JOIN CMDLINK CLINK ON CLINK.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT  JOIN COMANDA1 C1CLIENT ON C1CLIENT.CODCOMANDA1 = CLINK.CODLINIECOMANDA
    LEFT  JOIN COMANDA CCLIENT ON CCLIENT.CODCOMANDA = C1CLIENT.CODCOMANDA
    LEFT  JOIN NPART NP ON NP.CODPART = CCLIENT.PARTENER&apos;||
    gSuplJoins||&apos;
  WHERE PF1.CODPROGRAMF = &apos;||vCodProgramF||&apos; ORDER BY PF1.PRIORITATE &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pf;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PFGANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E0D37AA9B60DB2002745057B3C6C3B41B7C9768</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PFGANTT IS

  vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
  vTabla   VARCHAR2(50);
BEGIN
  gSuplCols := &apos;CMDPRODMAN MAN, NOPER OP, LOCMUNCA LM&apos;;
  
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos;(
		LOCMUNCA        ,                                                                              
		NROP 			      ,
		OPERATIE        ,                                                               
		TU              ,
		CODCMDPRODMAN   ,
		SAPT  ,
		TOTAL           ,
		LUNI            ,
		MARTI           ,
		MIERCURI        ,
		JOI             ,
		VINERI          ,
		SAMBATA         ,
		DUMINICA        ,  
		CODPROGRAMF     ,
		PRIORITATE      ,    
		CODCOMANDA1     ,
		NrCMD           ,
		IDENTIFICATOR   ,                                                                
		OBS             ,                                                                
		DEN_GEST        ,                                                                
		DENUMIRE        ,                                                                
		CODEXTERN       ,                                                                
		DEN_UM1         ,        
		CANTPROGRAMAT   ,
		TERMEN          ,
		DEN_FORMATIE    ,     
		SCHIMB  &apos;||gUserFields||&apos;)
with  PF as 
  (SELECT 
    PF1.CODPROGRAMF,
	  PF1.PRIORITATE,
    C1.CodComanda1,
    Round(C.NRDOC + C1.IndexLocal/100, 2) NRDOC,
    PC.IDENTIFICATOR,
    PC.OBS,
    NG.DEN_GEST,
    NOBJ.DENUMIRE,
    NOBJ.CODEXTERN,
    NUM1.DEN_UM1,
    PF1.CANTPROGRAMAT,
    C1.TERMEN,
    FR.Den_Formatie,
    PF1.Schimb
  FROM PROGRAMF1 PF1
    INNER JOIN PROGRAMF PF ON PF1.CODPROGRAMF = PF.CODPROGRAMF
    INNER JOIN NGEST NG ON NG.CODGEST = PF1.CODGEST
    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
    INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
    INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
    INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
    INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
    LEFT  JOIN FORMATII FR ON PF1.CodFormatie = FR.CodFormatie
    WHERE PF1.CODPROGRAMF = &apos;||vCodProgramF||&apos;),
	G as
	( Select CODCMDPRODMAN, Saptamana, Total, Sum(Luni) Luni, Sum(Marti) Marti, Sum(Miercuri) Miercuri, Sum(Joi) Joi, Sum(Vineri) Vineri, Sum(Sambata) Sambata,Sum(Duminica) Duminica  
		from(
		Select  CODCMDPRODMAN, Saptamana, Total, 
						Case when Z = 1 then CantZi else 0 end Luni, 
						Case when Z = 2 then CantZi else 0 end Marti, 
						Case when Z = 3 then CantZi else 0 end Miercuri, 
						Case when Z = 4 then CantZi else 0 end Joi, 
						Case when Z = 5 then CantZi else 0 end Vineri, 
						Case when Z = 6 then CantZi else 0 end Sambata, 
						Case when Z = 7 then CantZi else 0 end Duminica
		from( Select G.CODCMDPRODMAN,  G.CANT Total, TO_NUMBER(TO_CHAR(G.DStart,&apos;&apos;IW&apos;&apos;)) Saptamana,	 TRUNC(G.DStart - TRUNC(G.DStart,&apos;&apos;IW&apos;&apos;)) + 1 +G1.DEPLASARE Z, G1.CANT CantZi
			from Gantt G  
			LEFT JOIN Gantt1 G1  ON G1.CODGANTT = G.CodGantt
		)) Group by CODCMDPRODMAN, Saptamana, Total
	 )	
	Select Lm.Denumire LocMunca, Man.nrop, op.denumire operatie, Man.TU, 
				 G.*, PF.*&apos;||gUserAlias||&apos;
  from pf
	inner join CMDPRODMAN Man on Man.CodComanda1 = PF.CodComanda1
  LEFT JOIN noper op ON op.codop = Man.codop
  LEFT JOIN locmunca lm ON lm.codloc = Man.codloc
  LEFT JOIN G on G.CodCmdProdMan = MAn.Codcmdprodman&apos;||
    gSuplJoins||&apos;
  WHERE PF.CODPROGRAMF = &apos;||vCodProgramF;
--  insert into debug_liste(sql_lista) values (sInsert); commit;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pfGANTT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PFLOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03907985845F11E6B132B321A199847E32E4609C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PFLOCM IS

  vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  sInsert :=
     &apos;INSERT INTO &apos;||TMPNAME||&apos;(
        LocMunca,
        Disp,
        Necesar,
        Dif,
        Sectie,
        DispS,
        NecesarS,
        DifS,
        NrCmd,
        DataProg,
        Prioritate,
        Produs,
        NecesarCmd,
        Programat)
      SELECT TMP_B.DENUMIRE,
             TMP_B.DISPONIBIL,
             TMP_B.NECESAR,
             TMP_B.DIFERENTE,
             TMP_G.SECTIE,
             TMP_G.DISPONIBIL,
             TMP_G.NECESAR,
             TMP_G.DIFERENTE,
             TMP_C.NRCMD,
             TMP_C.DATAPROGRAMARE,
             TMP_C.PRIORITATE,
             TMP_C.DEN_OBIECT,
             TMP_C.NECESAR,
             TMP_C.CANTPROD
      FROM TMP_PF_LOCM_CMD TMP_C
           LEFT JOIN TMP_PF_LOCM TMP_B ON TMP_C.CODLOC = TMP_B.CODLOCMUNCA
           LEFT JOIN TMP_PF_LOCM_GEST TMP_G ON TMP_G.CODGEST = TMP_C.CODGEST AND TMP_G.CODLOCMUNCA = TMP_C.CODLOC &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pflocm;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PFMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF6D99F3901BEEEC48EC7F67F73D5B917E1E7149</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PFMAN IS

  vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  sInsert :=
     &apos;INSERT INTO &apos;||TMPNAME||&apos;(
        Operatie,
        DenumireTarif,
        Tarif,
        Ore,
        Valoare,
        Sectie,
        OreS,
        ValoareS,
        NrCmd,
        DataCmd,
        Produs,
        CodExtern,
        Necesar)
      SELECT TMP_B.DEN_OP,
             TMP_B.DEN_TARIF,
             TMP_B.Tarif,
             TMP_B.Ore,
             TMP_B.Valoare,
             TMP_G.DEN_GEST,
             TMP_G.ORE,
             TMP_G.Valoare,
             TMP_C.NrDoc,
             TMP_C.DATADOC,
             TMP_C.DENUMIRE,
             TMP_C.CodExtern,
             TMP_C.Necesar
      FROM TMP_PF_MAN_CMD TMP_C
           INNER JOIN TMP_PF_MAN TMP_B ON TMP_C.CODOP = TMP_B.CODOP
           INNER JOIN TMP_PF_MAN_GEST TMP_G ON TMP_G.CODGEST = TMP_C.CODGEST AND TMP_G.CODOP = TMP_C.CODOP &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pfman;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PFMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C764302040D15704A56375060E660830258AA6AD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PFMAT IS

vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL)  IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(13000);
vTabla  VARCHAR2(50);
BEGIN
  vTabla    := &apos;COMANDC&apos;;
  gSuplCols := &apos;PROGRAMF PF, COMANDA1 C1CLIENT, COMANDA CCLIENT&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, vTabla, &apos;CCV&apos;, &apos;CCV.CODCOMANDA = CCLIENT.CODCOMANDA&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
     &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      Mat,
      CodExternMat,
      UMMat,
      NecesarMat,
      RezervatMat,
      StocDispMat,
      ComFurnMat,
      AlteRezMat,
      Sectie,
      NecesarPr,
      RestAsigPr,
      NrCmd,
      DataCmd,
      Produs,
      CodExternProdus,
      NecesarProdus,
      RezervatProdus,
      UMProd,
      CantProdProg
      &apos;||gUserFields||&apos;)
      SELECT TMP_B.DENUMIRE,
             TMP_B.CODEXTERN,
             TMP_B.DEN_UM1,
             TMP_B.NECESAR,
             TMP_B.REZERVAT,
             TMP_B.STOCDISP,
             TMP_B.STOCFURN,
             TMP_B.ALTEREZ,
             TMP_G.DEN_GEST,
             TMP_G.CANTPROGRAMAT,
             TMP_G.RESTASIGURAT,
             TMP_C.NRDOC,
             TMP_C.DATADOC,
             TMP_C.DENOBJ,
             TMP_C.CODEXTERN,
             TMP_C.CANT,
             TMP_C.STOCREZ,
             TMP_C.DEN_UM,
             TMP_C.CANTPROD&apos;||gUserAlias||&apos;
      FROM TMP_PF_MAT_CMD TMP_C
           INNER JOIN TMP_PF_MAT TMP_B ON TMP_C.CODOBIECT = TMP_B.CODOBIECT
           INNER JOIN TMP_PF_MAT_GEST TMP_G ON TMP_G.CODGEST = TMP_C.CODGEST AND TMP_G.CODOBIECT = TMP_C.CODOBIECT
           INNER JOIN PROGRAMF PF ON PF.CodProgramF = &apos;||vCodProgramF||&apos;
           INNER JOIN COMANDA1 C1 ON TMP_C.CODCOMANDA1 = C1.CODCOMANDA1
           LEFT  JOIN CMDLINK CLINK ON CLINK.CODCOMANDA1 = C1.CODCOMANDA1
           LEFT  JOIN COMANDA1 C1CLIENT ON C1CLIENT.CODCOMANDA1 = CLINK.CODLINIECOMANDA
           LEFT  JOIN COMANDA CCLIENT ON CCLIENT.CODCOMANDA = C1CLIENT.CODCOMANDA
           &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pfmat;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PFSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A242D9B2B5E88DB4E4AA3E4BC291A6198FDD33E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PFSDV IS

vCodProgramF PROGRAMF.CODPROGRAMF%TYPE;

PROCEDURE SETPARAMS(pCodProgramF IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodProgramF := pCodProgramF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(13000);
BEGIN
  sInsert :=
     &apos;INSERT INTO &apos;||TMPNAME||&apos;(
        SDV,
        CodExternSDV,
        UMSDV,
        NecesarSDV,
        NecesarStabilit,
        StocDisp,
        ComFurn,
        Sectie,
        NecesarPr,
        StocExistent,
        NrCmd,
        Prioritate,
        Produs,
        CodExternProdus,
        UMProdus,
        CantProgramat)
      SELECT TMP_B.DENUMIRE,
             TMP_B.CODEXTERN,
             TMP_B.DEN_UM,
             TMP_B.CANTDOC,
             TMP_B.CANTACT,
             TMP_B.REST,
             TMP_B.STOCFURN,
             TMP_G.DEN_GEST,
             TMP_G.CANT,
             TMP_G.STOC,
             TMP_C.NrCmd,
             TMP_C.Prioritate,
             TMP_C.DEN_OBIECT,
             TMP_C.CodExtern,
             TMP_C.UM,
             TMP_C.CantProgramat
      FROM TMP_PF_SDV_CMD TMP_C
           LEFT JOIN TMP_PF_SDV TMP_B ON TMP_C.CODOBIECT = TMP_B.CODOBIECT
           LEFT JOIN TMP_PF_SDV_GEST TMP_G ON TMP_G.CODGEST = TMP_C.SECTIE AND TMP_G.CODOBIECT = TMP_C.CODOBIECT &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_pfsdv;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PF_LOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F41E4F08C50FC4670610C288841493A4016D8B6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_pf_locm IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);


PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(2000);
sSelect   VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;prodcomp pc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
       CodLoc,
       LOCM,
       CI,
       Client,
       Produs,
       Cant,
       Disponibil,
       Necesar,
       CodIntern,
       CodExtern,
       DataProgramare,
       NrCmdCli,
       TermenLivrare,
       TermenExecutie
       &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;

  with
CRS_NECESAR AS
  (
    SELECT
      SUM( CASE
            WHEN PC.CANT &lt;&gt; 1 THEN
                PF1.CANTPROGRAMAT / PMAN.CANT * NVL(PMAN.TPI, 0)  + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
            ELSE
                NVL(PMAN.TPI, 0) + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
            END
          ) NECESAR,
      NVL(PMAN.CODLOC,0) CODLOC,
      C1.CODCOMANDA1,
      NVL(PMAN.CODOP,0) CODOP,
      pflmc.dataprogramare
    FROM programflmc pflmc
         inner join programf pf on pflmc.codprogramf = pf.codprogramf
         inner join comanda1 c1 on c1.codcomanda1 = pflmc.codcomanda1
         inner join programf1 pf1 on pf1.codprogramf = pflmc.codprogramf and pf1.codcomanda1 = pflmc.codcomanda1
         INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
         inner join comanda c on c.codcomanda = c1.codcomanda
         inner join ngest g on c.codgest = g.codgest
         inner join locmunca lm on lm.codloc = pflmc.codloc
         left join cmdprodman pman on pman.codcomanda1 = c1.codcomanda1 and pflmc.codloc = pman.codloc and pflmc.codop = pman.codop
    WHERE PFLMC.DATAPROGRAMARE between PKG_LIST_ALEGPERIOADA.GetDataS AND PKG_LIST_ALEGPERIOADA.GetDataF
    GROUP BY c1.codcomanda1, pman.codloc, pflmc.dataprogramare, pman.codop
  )
  select
    pflmc.codloc,
    lm.denumire,
    c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),
    p.den_part,
    obj.denumire,
    pf1.cantprogramat,
    pkg_locmunca.GetDisponibilPeZi(pflmc.codloc) * 60,
    crs_Necesar.necesar,
    obj.CodIntern,
    obj.CodExtern,
    pflmc.dataprogramare,
    cc.prefixdoc||&apos;&apos; &apos;&apos;||cc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(cc.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),
    cc1.termen,
    c1.termen&apos;||gUserAlias||&apos;
  from programflmc pflmc
       inner join programf pf on pflmc.codprogramf = pf.codprogramf
       inner join comanda1 c1 on c1.codcomanda1 = pflmc.codcomanda1
       inner join programf1 pf1 on pf1.codprogramf = pflmc.codprogramf and pf1.codcomanda1 = pflmc.codcomanda1
       inner join comanda c on c.codcomanda = c1.codcomanda
       inner join ngest g on c.codgest = g.codgest
       inner join locmunca lm on lm.codloc = pflmc.codloc
       inner join nartobj obj on c1.codobiect = obj.codobiect
       left join prodcomp pc on c1.codreteta = pc.codprodcomp
       left join cmdprodman pman on pman.codcomanda1 = c1.codcomanda1 and pflmc.codloc = pman.codloc and pflmc.codop = pman.codop
       left join comanda1 cc1 on cc1.codcomanda1 = pkg_comanda.DinCmdCli(c1.CodComanda1)
       left join comanda cc on cc1.codcomanda = cc.codcomanda
       left join npart p on p.codpart = nvl(cc.partener,0)
       left join crs_necesar on crs_necesar.codloc = pflmc.codloc and crs_necesar.codcomanda1 = pflmc.codcomanda1 and crs_necesar.dataprogramare = pflmc.dataprogramare
                                and crs_necesar.codop = pflmc.codop&apos;||
    gSuplJoins||&apos;
  where pflmc.dataprogramare between PKG_LIST_ALEGPERIOADA.GetDataS AND PKG_LIST_ALEGPERIOADA.GetDataF
  order by pflmc.dataprogramare&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  sSelect := &apos;begin
                for v_rec in (select sum(tmp.necesar) tot, tmpp.dataprogramare, tmp.codloc
                              from (select distinct dataprogramare from &apos;||TMPNAME||&apos;) tmpp
                                   inner join &apos;||TMPNAME||&apos; tmp on tmpp.dataprogramare = tmp.dataprogramare
                              group by tmpp.dataprogramare, tmp.codloc
                             ) loop
                  update &apos;||TMPNAME||&apos; set dif = nvl(disponibil,0) - nvl(v_rec.tot,0) where dataprogramare = v_rec.dataprogramare and codloc = v_rec.codloc;
                end loop;
              end;&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);            
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PF_LOCM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PF_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15B592187D5900C1720A9B10642DEA049A6B4D7B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PF_LUNA is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(2000);
sSelect   VARCHAR2(20000);
sSubunitatea varchar2(250);
sDataS    varchar2(100);
sDataF    varchar2(100);
BEGIN
  gSuplCols := &apos;PROGRAMF PF, COMANDA1 C1, COMANDA C, PRODCOMP PC, NARTOBJ NOBJ, PROGRAMF1 PF1, COMANDA1 C1CLIENT, COMANDA CCLIENT&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sSubunitatea := to_char(PKG_GLOBALS.GETSUBUNITATE);
  sDataS := PKG_LIST_ALEGPERIOADA.GetDataS;
  sDataF := PKG_LIST_ALEGPERIOADA.GetDataF;

  sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos;(
       NAV_CODDOC,
       NAV_TIPDOC,
       PRIORITATE,
       CANTPROGRAMAT,
       DEN_GEST,
       NRCMD,
       DEN_OBIECT,
       CODEXTERN,
       UM,
       TERMENEXEC,
       DEN_CLIENT,
       TERMENLIVR,
       DURATA,
       DataOraStart,
       DataOraStop,
       Formatie,
       Schimb,
       Stoc,
       Rest &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    PF.CODPROGRAMF,
    68,
    PF1.PRIORITATE,
    PF1.CANTPROGRAMAT,
    NG.DEN_GEST,
    C.NRDOC,
    NOBJ.DENUMIRE,
    NOBJ.CODEXTERN,
    NUM1.DEN_UM1,
    NVL(PF1.TERMEN,C1.TERMEN),
    NP.DEN_PART,
    c1client.termen,
    PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * PC.DURATA,
    PF.VDELA
    - (PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (nvl(PC.DURATA,0)/60) / 24)
    + SUM(PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (nvl(PC.DURATA,0)/60) / 24)
    over (PARTITION BY PF1.CODGEST ORDER BY PF1.PRIORITATE ROWS BETWEEN unbounded preceding AND CURRENT ROW ),
    PF.VDELA
    + SUM(PF1.CANTPROGRAMAT * NUM1.Paritate / PC.CANT * (nvl(PC.DURATA,0)/60) / 24)
    over (PARTITION BY PF1.CODGEST ORDER BY PF1.PRIORITATE ROWS BETWEEN unbounded preceding AND CURRENT ROW ),
    FR.Den_Formatie,
    PF1.Schimb,
    NVL(Stoc.Cant,0),
    PF1.CANTPROGRAMAT - nvl((select sum(l.cant) from intrprodlink l where l.codprogramf1 = pf1.CODPROGRAMF1),0) &apos;||gUserAlias||&apos;
  FROM PROGRAMF1 PF1
    INNER JOIN PROGRAMF PF ON PF1.CODPROGRAMF = PF.CODPROGRAMF
    INNER JOIN NGEST NG ON NG.CODGEST = PF1.CODGEST
    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
    INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
    INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
    INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
    INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
    LEFT  JOIN (SELECT SUM(NS.REST) CANT, NS.CODOBIECT
                FROM NIRSTOC NS
                     INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                     INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
                WHERE (&apos;||sSubunitatea||&apos; = 1 OR G.CODSUBUNIT = &apos;||sSubunitatea||&apos;) and NS.REST &lt;&gt; 0
                      AND NS.CODOBIECT IN (
                        SELECT DISTINCT C1.CODOBIECT
                        FROM PROGRAMF1 PF1
                             INNER JOIN PROGRAMF PF ON PF1.CODPROGRAMF = PF.CODPROGRAMF
                             INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
                        WHERE (&apos;||sSubunitatea||&apos; = 1 OR PF.SUBUNITATEA = &apos;||sSubunitatea||&apos;) 
                               AND PF1.TERMEN between to_date(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) 
                               AND to_date(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
                        )     
                GROUP BY NS.CODOBIECT      
               ) STOC ON STOC.CODOBIECT = C1.CODOBIECT
    LEFT  JOIN FORMATII FR ON PF1.CodFormatie = FR.CodFormatie
    LEFT  JOIN CMDLINK CLINK ON CLINK.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT  JOIN COMANDA1 C1CLIENT ON C1CLIENT.CODCOMANDA1 = CLINK.CODLINIECOMANDA
    LEFT  JOIN COMANDA CCLIENT ON CCLIENT.CODCOMANDA = C1CLIENT.CODCOMANDA
    LEFT  JOIN NPART NP ON NP.CODPART = CCLIENT.PARTENER&apos;||
    gSuplJoins||&apos;
  WHERE (&apos;||sSubunitatea||&apos; = 1 OR PF.SUBUNITATEA = &apos;||sSubunitatea||&apos;) 
  AND PF1.TERMEN between to_date(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) 
  AND to_date(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  
  --EXECUTE IMMEDIATE (sInsert||sSelect);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);            
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

  
end PKG_LIST_BASE_PF_LUNA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PLANACHIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1B829BCA62D005E3955F8E80B208F4C73DE77C3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PLANACHIZ IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(25000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sAn       VARCHAR2(4) := PKG_GLOBALS.GetAnLucru;
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;CENTRECOST CC&apos;;
  pkg_list_struct.StartSuplCols;
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(CCDENUMIRE, VAL_BUGET, VAL_PLATI, DIFERENTA &apos;||gUserFields||&apos;)
  SELECT CC.Denumire, coalesce(v_b.val_buget, 0) val_buget, coalesce(v_p.val_plati, 0) val_plati, coalesce(v_b.val_buget, 0) - coalesce(v_p.val_plati, 0) dif &apos;||gUserAlias||&apos;
  FROM (
    select codcentru, Sum(buget) val_buget
    from bugetanaliza
    where Coalesce(codcentru, 0) &lt;&gt; 0 AND an = &apos;||sAn||&apos;
    group by codcentru
  ) v_b
  FULL JOIN (
    select op.codcentru, sum(p1.valoare) val_plati
    from plati p
      inner join plati1 p1 on p1.codplata = p.codplata
      inner join obligpif op on op.codobligpif = p1.codobligpif
    where coalesce(op.codcentru, 0) &lt;&gt; 0 AND p.an = &apos;||sAn||&apos; AND p.tipdoc = 1
    group by op.codcentru
  ) v_p ON v_p.codcentru = v_b.codcentru
  LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = Coalesce(v_b.codcentru, v_p.codcentru)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_PLANACHIZ;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17F191A46914CE185829E2B513E58893597AE0EE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PLANIFCMD is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  pAn NUMBER(4);
  pSet number(2);
  pAnG number(4);
  pSetG number(2);

PROCEDURE setParams(aAn IN number, aSet in number, aAnG in number, aSetG in number) IS
BEGIN
  pAn   := aAn;
  pSet  := aSet;
  pAnG  := aAnG;
  pSetG := aSetG;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sString  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;stareestimari1 se1, nartobj obj&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sString :=
  &apos;insert into &apos;||tmpName||&apos; (
    stocmin,
    stocini,
    StocPrec,
    Estimari,
    Consum,
    CmdF,
    CmdFP,
    Necesar,
    StocFinal,
    Pret,
    StocVal,
    denumire,
    INDEXLOCAL,
    RESTPRECMD,
    RESTPRECMDA,
    RESTNECESAR &apos;||gUserFields||&apos;
  )
  select
    tse1.stocmin,
    tse1.stocini,
    tse1.StocPrec,
    tse1.Estimari,
    tse1.Consum,
    tse1.CmdF,
    tse1.CmdFP,
    tse1.Necesar,
    tse1.StocFinal,
    tse1.Pret,
    tse1.StocVal,
    tse1.denumire,
    tse1.INDEXLOCAL,
    tse1.RESTPRECMD,
    tse1.RESTPRECMDA,
    tse1.RESTNECESAR
  &apos;||gUserAlias||&apos;
  from tmp_stareestimari1 tse1
       inner join stareestimari1 se1 on tse1.codstare1 = se1.codstare1
       inner join stareestimari se on se1.codstare = se.codstare
       inner join nartobj obj on se1.codobiect = obj.codobiect
  &apos;||gSuplJoins;

  Execute Immediate (sString);
  PROCESSPARAMS(tmpName);
  Commit;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
  sSet  VARCHAR2(5000);
  sSetG VARCHAR2(3000);
  sOferta VARCHAR2(3000);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      to_char(se.saptamana)||&apos;/&apos;||to_char(se.an) SetC, to_char(se.saptamanaG)||&apos;/&apos;||to_char(se.anG) SetG,
      o.nrdoc||&apos; - &apos;||p.den_part oferta
    FROM stareestimari se
         inner join tmp_stareestimari1 se1 on se1.codstare = se.codstare
         left join oferta o on se.codoferta = o.codoferta
         left join npart p on p.codpart = o.partener
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Saptamana curenta&apos;,  v_rec.SetC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Saptamana generare&apos;, v_rec.SetG);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Oferta&apos;,             v_rec.oferta);
    Exit;
  END LOOP;
END;

end PKG_LIST_BASE_PLANIFCMD;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFCMD_CENTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56C437EAA42B6A2F367D04D5854D9F3E663731F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PLANIFCMD_CENTR is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  pAn NUMBER(4);
  pSet number(2);

PROCEDURE setParams(aAn IN number, aSet in number) IS
BEGIN
  pAn  := aAn;
  pSet := aSet;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString VARCHAR2(5000);
sTable VARCHAR2(100);
BEGIN
  gSuplCols := &apos;stareestimari1 se1, nartobj obj&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_PLANIFCMD.MakeTemporarCentralizat(pSet, pAn);

  sString :=
  &apos;insert into &apos;||tmpName||&apos; (
    stocmin,
    stocini,
    StocPrec,
    Estimari,
    Consum,
    CmdF,
    CmdFP,
    Necesar,
    StocFinal,
    Pret,
    StocVal,
    denumire,
    INDEXLOCAL,
    RESTPRECMD,
    RESTPRECMDA,
    RESTNECESAR,
    AN,
    SAPTAMANA &apos;||gUserFields||&apos;
  )
  select
    tse1.stocmin,
    tse1.stocini,
    tse1.StocPrec,
    tse1.Estimari,
    tse1.Consum,
    tse1.CmdF,
    tse1.CmdFP,
    tse1.Necesar,
    tse1.StocFinal,
    tse1.Pret,
    tse1.StocVal,
    tse1.denumire,
    tse1.INDEXLOCAL,
    tse1.RESTPRECMD,
    tse1.RESTPRECMDA,
    tse1.RESTNECESAR,
    tse1.an,
    tse1.saptamana&apos;||gUserAlias||&apos;
  from tmp_stareestimari1_centr tse1
       inner join stareestimari1 se1 on tse1.codstare1 = se1.codstare1
       inner join stareestimari se on se1.codstare = se.codstare
       inner join nartobj obj on se1.codobiect = obj.codobiect
  &apos;||gSuplJoins||&apos;
  where tse1.userid = &apos;||pkg_globals.GETUSERID;

  Execute Immediate (sString);
  delete tmp_stareestimari1_centr where userid = pkg_globals.GETUSERID;
  PROCESSPARAMS(tmpName);
  Commit;
END;

PROCEDURE PROCESSPARAMS(tmpName IN VARCHAR2) IS
sSet  VARCHAR2(5000);
sSetG VARCHAR2(3000);
sOferta VARCHAR2(3000);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      to_char(se.saptamana)||&apos;/&apos;||to_char(se.an) SetC, o.nrdoc||&apos; - &apos;||p.den_part oferta
    FROM stareestimari se
         left join oferta o on se.codoferta = o.codoferta
         left join npart p on p.codpart = o.partener
    WHERE SE.AN = PAN AND SE.SAPTAMANA = PSET
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Saptamana curenta&apos;,  v_rec.SetC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Oferta&apos;,             v_rec.oferta);
    Exit;
  END LOOP;
END;

end PKG_LIST_BASE_PLANIFCMD_CENTR;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA155074DDE0A08B816D3A53F3B93E6CA1D66BD0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PLANIFPROD IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  pSetimana NUMBER(20);
  pAn number(4);

PROCEDURE setParams(aSetimana IN number, aAn in number)
IS
BEGIN
  pSetimana := aSetimana;
  pAn := aAn;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sString  VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;nartobj comp, nartobj prod,prodcomp ppc,IOART IOAP,planifprod pp,prodcomp pc,nartobj objsemip,num um,prodcomp pcimp,prodmat mat,nartobj1 comp1,pretm pretm&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  sString :=
  &apos;insert into &apos;||tmpName||&apos;(NAV_CodDoc, NAV_TipDoc, nrdoc, datadoc, Produs, Necesar, Component, UM, Cant, Pozitie, Nivel, ordine, obs, varianta&apos;||gUserFields||&apos;)
  select pp.codplanifprod, 85, pp.nrdoc, pp.datadoc, prod.denumire, pp1.necesar, comp.denumire, UM.den_um, nod.necesar, nod.Pozitie, nod.Nivel, substr(x.ind,5, length(x.ind)-3), mat.obs,
         case when nvl(pp1.cuproiect,0) = 1 and nvl(nodp.nodoriginal,0) = 0 then pr.versiune else pc.obs end&apos;||gUserAlias||&apos;
  from planifprod pp
    inner join planifprod1    pp1      on pp.codplanifprod   = pp1.codplanifprod
    inner join planifnod      nod      on nod.codplanifprod1 = pp1.codplanifprod1 and nod.codplanifprod = pp.codplanifprod
    inner join planifnod      nodp     on nodp.codplanifnod  = nod.nodoriginal
    inner join nartobj        comp     on nod.codobiect      = comp.codobiect
    inner join nartobj1       comp1    on comp.codobiect     = comp1.codobiect AND pkg_globals.anlunalucru BETWEEN comp1.ALStart and comp1.ALStop
    inner join nart           art      on comp.codarticol    = art.codarticol
    inner join num            um       on um.codum           = art.um
    inner join nartobj        prod     on pp1.codobiect      = prod.codobiect
    inner join nart           aprod    on prod.codarticol    = aprod.codarticol
    left  join nartobjsubunit objsub   on nod.codobiect      = objsub.codobiect
                                       and (objsub.codgest is null or objsub.codgest = 0)
                                       and objsub.subunitate = pkg_globals.getsubunitate
    left  join nclasea        cls      on cls.codclasea      = art.clasa
    left  join prodmat        mat      on nod.codprodmat     = mat.codmat
    left  join prodcomp       pc       on pc.codprodcomp     = nod.codreteta and pc.codprodcomp &gt; 0
    left  join nartobj        objsemi  on objsemi.codobiect  = pc.codobiect
    left  join pretm          pretm    on pretm.codobiect    = objsemi.codobiect and pretm.implicit = 1 and pretm.subunitatea = pp.subunitatea
    left  join prodcomp       pcimp    on pcimp.codobiect    = objsemi.codobiect and pcimp.implicit = 1
    left  join nartobj        objsemip on nodp.codobiect     = objsemip.codobiect
    left  join prodcomp       ppc      on ppc.codprodcomp    = decode(nvl(nodp.codreteta,0),-1,nod.codreteta,nodp.codreteta) and ppc.codprodcomp &gt; 0
    left  join proiect        pr       on pr.codproiect      = nod.codreteta and pr.codproiect &gt; 0
    LEFT  JOIN NARTIMPLICITE  IMP      ON Aprod.CODARTICOL   = IMP.CODARTICOL AND IMP.CODSUBUNIT = pp.subunitatea
    LEFT  JOIN nartobjimp     impo     on prod.codobiect     = impo.codobiect and impo.codsubunit = pp.subunitatea
    LEFT  JOIN IOART          IOAP     ON IOAP.CODIOART      = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
    LEFT  JOIN (
      SELECT CodPlanifNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND
      FROM PLANIFNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPLANIFNOD = NODORIGINAL
    ) X on x.CodPlanifNod = nod.CodPlanifNod&apos;||
    gSuplJoins||&apos;
  WHERE ((nod.versiune = 1 and nod.tip &lt;&gt; 3) or nod.tip = 3) and nvl(nod.nodoriginal, 0) &gt; 0  and pp.saptamana = &apos;||pSetimana||&apos; and pp.An = &apos;||pAn;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);
  Commit;
END;

end PKG_LIST_BASE_PLANIFPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PLANIFSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5610EF7A5D24183C72EAB39D70B81EA20FCF3B8E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PLANIFSTOC IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataStart   DATE;
  vDataFin     DATE;
  vAllGestStoc BOOLEAN;
  vAllGestCmd  BOOLEAN;
  vNoTermen    BOOLEAN;

procedure SetParams(aDataStart in varchar2, aDataFin in varchar2, AllGestStoc in number, AllGestCmd in number, NoTermen in number, v_codjob1 in number) is
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
begin
  vDataStart   := To_Date(aDataStart, &apos;dd.mm.yyyy&apos;);
  vDataFin     := To_Date(aDataFin,   &apos;dd.mm.yyyy&apos;);
  vAllGestStoc := AllGestStoc = 1;
  vAllGestCmd  := AllGestCmd = 1;
  vNoTermen    := NoTermen = 1;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataStart,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
end;

function GETPARBYCODEXTERN(aCodExtern in varchar2, aCodObiect in number) return number is
aParitate number(20,7);
begin
  begin
    select num1.paritate into aParitate
    from nartamb amb
         inner join num1 on num1.codum1 = amb.umsec
    where amb.codobiect = aCodObiect and upper(num1.codextern) = upper(aCodExtern) and rownum = 1
    order by amb.codamb;
  exception when others then aParitate := 1;
  end;

  return aParitate;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(10000);
sSelect    VARCHAR2(30000);
sSelect1   VARCHAR2(30000);
vAnPrec    NUMBER(4);
vLunaPrec  NUMBER(2);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM, NPART PROD, NCLASEA CA&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_list_base_utils.make_config_luna_ioart;

  pkg_globals.Calculeaza_Luna_Precedenta(Extract(Year from vDataStart), Extract(Month from vDataStart), vAnPrec, vLunaPrec);
  pkg_globals.SetLunaTemp(Extract(Year from vDataStart), Extract(Month from vDataStart));
  pkg_globals.SetLunaPrecedenta(vAnPrec, vLunaPrec);

  PKG_LIST_SELFISAMAG.setAllParams(null, null, to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;), 0, 0, 0);

  DELETE TMP_GESTCMD;
  sSelect := &apos;INSERT INTO TMP_GESTCMD (CODGEST, CODOBIECT, DEN_GEST)
  SELECT DISTINCT C1.GESTACT, C1.CODOBIECT, G.DEN_GEST
  FROM COMANDA1 C1
       INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
       INNER JOIN NGEST G ON G.CODGEST = C1.GESTACT &apos;;
  if not vAllGestCmd then
    sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTCMD&apos;&apos; &apos;;
  end if;
  sSelect := sSelect||
  &apos;WHERE NVL(C.INCHISA, 0) = 0
    AND C.Operat = 1 AND NVL(C.Anulat, 0) &lt;&gt; 1 AND C.TipDoc = 18 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos; AND C1.GESTACT &gt; 0 &apos;||chr(13);
  if not vNoTermen then
    sSelect := sSelect||&apos; AND C1.TERMEN BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;;
  end if;
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

  DELETE TMP_PLANIFSTOC;
  if not vNoTermen then
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, CANTREZ, SERIE, TG)
    SELECT
      V.CODOBIECT,
      sum(V.REST),
      V.CODGEST,
      &apos;&apos;STOCINISER&apos;&apos;,
      sum(nvl(V.CANTREZ,0)),
      SER.SERIE,
      to_char(V.TG, &apos;&apos;dd.mm.yyyy&apos;&apos;)
    FROM v_stoc_ini_planif v
         inner join ngest g on v.codgest = g.codgest &apos;||pkg_list_base_utils.COND_SUBUNIT(&apos;g&apos;, &apos;codsubunit&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos; left join nserii ser on v.codserie = ser.codserie
    WHERE v.rest &lt;&gt; 0
    group by v.codobiect, v.codgest, ser.serie, v.tg&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    delete tmp_planifstoc_clona;
    insert into tmp_planifstoc_clona
    select * from tmp_planifstoc;

    --constructie SER/TG INI
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, SERIE, TG)
    SELECT
      V.CODOBIECT,
      SUM(V.REST),
      g.codgest,
      &apos;&apos;SERTGINI&apos;&apos;,
      SER.SERIE,
      CASE WHEN V.TG IS NULL THEN &apos;&apos;&apos;&apos;
           ELSE to_char(V.TG, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      END
    FROM v_stoc_ini_planif v
         inner join ngest g on v.codgest = g.codgest &apos;||pkg_list_base_utils.COND_SUBUNIT(&apos;g&apos;, &apos;codsubunit&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos; left join nserii ser on v.codserie = ser.codserie
    WHERE v.rest &lt;&gt; 0
    group by v.codobiect, g.codgest, ser.serie, v.tg&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, CANTREZ)
    SELECT
      V.CODOBIECT,
      sum(V.CANT),
      V.CODGEST,
      &apos;&apos;STOCINI&apos;&apos;,
      sum(nvl(V.CANTREZ,0))
    FROM tmp_planifstoc_clona v
    group by v.codobiect, v.codgest&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT CODOBIECT, sum(REST), CODGEST, &apos;&apos;INTRARI&apos;&apos; FROM (
    SELECT
      NS.CODOBIECT,
      CASE
        WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
        ELSE NSE.CANTNIR
      END REST,
      N.GEST CODGEST
    FROM
      NIRSTOC NS
      INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||pkg_list_base_utils.COND_SUBUNIT(&apos;g&apos;, &apos;codsubunit&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos; LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
    WHERE
      N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
      AND N.DATANIR BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
      last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos; AND IO.MG &lt;&gt; 5
    )
    GROUP BY codobiect, codgest&apos;;/*UNION ALL
    SELECT
        ns.codobiect,
        L1.CANT CANT,
        G.CODGEST
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
      WHERE l.tiplivr = 15
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;
     UNION ALL
     SELECT
        ns.codobiect,
        -L1.CANT CANT,
        G.CODGEST
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
      WHERE l.tiplivr IN (1, 2, 3, 4, 5, 6, 7)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;)
     GROUP BY codobiect, codgest&apos;;*/
    --DELETE X;
    --INSERT INTO X(TEST) VALUES (SSELECT);
    --COMMIT;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
    --insert into x(test) values(sselect);

    -- CONSTRUCTIE SERTGIN
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, SERIE, TG)
    SELECT CODOBIECT, sum(REST), codgest, &apos;&apos;SERTGIN&apos;&apos;, SERIE, TG FROM (
    SELECT
      NS.CODOBIECT,
      CASE
        WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
        ELSE NSE.CANTNIR
      END REST,
      g.codgest,
      SER.SERIE,
      case
        when ns.tg is null then
          case
            when nse.tg is null then &apos;&apos;&apos;&apos;
            else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          end
        else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      end TG
    FROM
      NIRSTOC NS
      INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||pkg_list_base_utils.COND_SUBUNIT(&apos;g&apos;, &apos;codsubunit&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos; LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
      LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
    WHERE
      N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
      AND N.DATANIR BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
      last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos; AND IO.MG &lt;&gt; 5
      ) GROUP BY codobiect, codgest, serie, tg&apos;;/*
    UNION ALL
    SELECT
      ns.codobiect,
      L1.CANT CANT,
      g.codgest,
      SER.SERIE,
      case
        when ns.tg is null then
          case
            when nse.tg is null then &apos;&apos;&apos;&apos;
            else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          end
        else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      end TG
    FROM livr l
      INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
      INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC and l1.codnirser = nse.codnirser
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE l.tiplivr = 15
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;
     UNION ALL
     SELECT
        ns.codobiect,
        -L1.CANT CANT,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
    if not vAllGestStoc then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC and l1.codnirser = nse.codnirser
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE l.tiplivr IN (1, 2, 3, 4, 5, 6, 7, 12)
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;)
     GROUP BY codobiect, codgest, serie, tg&apos;;*/
    --DELETE X;
    --INSERT INTO X(TEST) VALUES (SSELECT);
    --COMMIT;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT codobiect, sum(canties) canties, codgest, &apos;&apos;IES&apos;&apos;
    FROM (
      SELECT
        ns.codobiect,
        CASE WHEN L.TIPLIVR = 15 THEN - L1.CANT ELSE L1.CANT END canties,
        GESTCMD.CODGEST
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_GESTCMD GESTCMD ON G.CODGEST = GESTCMD.CODGEST  AND GESTCMD.CODOBIECT = NS.CODOBIECT
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;)
    GROUP BY codobiect, codgest&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    -- construiesc SERTGIES
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, SERIE, TG)
    SELECT codobiect, sum(canties) canties, codgest, &apos;&apos;SERTGIES&apos;&apos;, SERIE, TG
    FROM (
      SELECT
        ns.codobiect,
        CASE WHEN L.TIPLIVR = 15 THEN - L1.CANT ELSE L1.CANT END canties,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_GESTCMD GESTCMD ON G.CODGEST = GESTCMD.CODGEST  AND GESTCMD.CODOBIECT = NS.CODOBIECT
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC and l1.codnirser = nse.codnirser
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
        AND io.mg &lt;&gt; 5
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;)
    GROUP BY codobiect, codgest, serie, tg&apos;;
    /*SELECT
        ns.codobiect,
        ns.cantfurn canties,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM nir n
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_GESTCMD GESTCMD ON G.CODGEST = GESTCMD.CODGEST
        INNER JOIN nirstoc ns ON ns.codnir = n.codnir AND GESTCMD.CODOBIECT = NS.CODOBIECT
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE n.tipnir IN (19, 20, 21, 22, 23, 24, 25)
        AND io.mg &lt;&gt; 5
        AND n.datanir BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;
      UNION ALL*/
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT codobiect, sum(canties) canties, gest, &apos;&apos;IES0&apos;&apos;
    FROM (
      SELECT
        ns.codobiect,
        -ns.cantfurn canties,
        n.gest
      FROM nir n
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN nirstoc ns ON ns.codnir = n.codnir
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart &apos;;
    if not vAllGestCmd then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos; WHERE n.tipnir IN (19, 20, 21, 22, 23, 24, 25)
        and not exists (select gestcmd.codgest from TMP_gestcmd GESTCMD where gestcmd.codgest = g.codgest AND GESTCMD.CODOBIECT = NS.CODOBIECT)
        AND io.mg &lt;&gt; 5
        AND n.datanir BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;
      UNION ALL
      SELECT
        ns.codobiect,
        l1.cant canties,
        n.gest
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart&apos;;
    if not vAllGestCmd then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
      WHERE l.tiplivr IN (14, 16, 19, 20, 21, 22, 23, 24, 25)
        and not exists (select gestcmd.codgest from tmp_gestcmd gestcmd where gestcmd.codgest = g.codgest AND GESTCMD.CODOBIECT = NS.CODOBIECT )
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
      last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos; )
    GROUP BY codobiect, gest&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    -- construiesc SERTGIES0
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, SERIE, TG)
    SELECT codobiect, sum(canties) canties, codgest, &apos;&apos;SERTGIES0&apos;&apos;, SERIE, TG
    FROM (
      SELECT
        ns.codobiect,
        ns.cantfurn canties,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM nir n
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN nirstoc ns ON ns.codnir = n.codnir
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart &apos;;
    if not vAllGestCmd then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE n.tipnir IN (19, 20, 21, 22, 23, 24, 25)
        and not exists (select gestcmd.codgest from TMP_gestcmd GESTCMD where gestcmd.codgest = g.codgest AND GESTCMD.CODOBIECT = NS.CODOBIECT)
        AND io.mg &lt;&gt; 5
        AND n.datanir BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
        last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos;
      UNION ALL
      SELECT
        ns.codobiect,
        -l1.cant canties,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM livr l
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart&apos;;
    if not vAllGestCmd then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC and l1.codnirser = nse.codnirser
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE l.tiplivr IN (14, 16, 19, 20, 21, 22, 23, 24, 25)
        and not exists (select gestcmd.codgest from tmp_gestcmd gestcmd where gestcmd.codgest = g.codgest AND GESTCMD.CODOBIECT = NS.CODOBIECT )
        AND io.mg &lt;&gt; 5
        AND l.operat = 1 AND l.anulat = 0
        AND l.datalivr BETWEEN &apos;&apos;&apos;||to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; AND &apos;&apos;&apos;||
      last_day(to_date(&apos;01&apos;||&apos;.&apos;||to_char(pkg_globals.GetLUNALUCRU, &apos;00&apos;)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU, &apos;0000&apos;), &apos;dd.mm.yyyy&apos;))||&apos;&apos;&apos; )
    GROUP BY codobiect, codgest, serie, tg&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    insert into tmp_planifstoc(codobiect, tg, cant, serie, codgest, filtru)
    select codobiect, tg, cant, serie, codgest, &apos;SG&apos;
    from (
      select codobiect, tg, sum(cant) cant, serie, codgest
      from (select codobiect, tg, sum(cant) cant, serie, codgest
            from tmp_planifstoc
            where filtru = &apos;SERTGINI&apos;
            group by codobiect, tg, serie, codgest
            union all
            select codobiect, tg, sum(cant) cant, serie, codgest
            from tmp_planifstoc
            where filtru = &apos;SERTGIN&apos;
            group by codobiect, tg, serie, codgest
            union all
            select codobiect, tg, sum(cant) cant, serie, codgest
            from tmp_planifstoc
            where filtru = &apos;SERTGIES&apos;
            group by codobiect, tg, serie, codgest
            union all
            select codobiect, tg, sum(cant) cant, serie, codgest
            from tmp_planifstoc
            where filtru = &apos;SERTGIES0&apos;
            group by codobiect, tg, serie, codgest
           )
      group by codobiect, codgest, tg, serie
    )
    where cant &gt; 0;
    delete tmp_planifstoc where filtru = &apos;SERTGINI&apos;;
    delete tmp_planifstoc where filtru = &apos;SERTGIN&apos;;
    delete tmp_planifstoc where filtru = &apos;SERTGIES&apos;;
    delete tmp_planifstoc where filtru = &apos;SERTGIES0&apos;;
  else
    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU, SERIE, TG)
    SELECT codobiect, sum(REST) cant, codgest, &apos;&apos;SG&apos;&apos;, SERIE, TG
    FROM (
      SELECT
        ns.codobiect,
        NVL(ns.rest,0) rest,
        g.codgest,
        SER.SERIE,
        case
          when ns.tg is null then
            case
              when nse.tg is null then &apos;&apos;&apos;&apos;
              else to_char(nse.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            end
          else to_char(ns.tg,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        end TG
      FROM NIRSTOC NS
        INNER JOIN nir n ON N.CODNIR = NS.CODNIR
        INNER JOIN ngest g ON g.codgest = n.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN TMP_IOART_LUNA io ON io.codioart = ns.codioart &apos;;
    if not vAllGestCmd then
      sSelect := sSelect||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = G.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect := sSelect||&apos;
        LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT  JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE N.OPERAT = 1 AND NVL(N.ANULAT,0) = 0
        AND io.mg &lt;&gt; 5 )
    GROUP BY codobiect, codgest, serie, tg&apos;;
    --commit;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT codobiect, sum(CANT), codgest, &apos;&apos;STOCINI&apos;&apos;
    FROM TMP_PLANIFSTOC
    WHERE FILTRU = &apos;&apos;SG&apos;&apos;
    GROUP BY codobiect, codgest&apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT DISTINCT codobiect, 0, codgest, &apos;&apos;INTRARI&apos;&apos;
    FROM TMP_PLANIFSTOC
    WHERE FILTRU = &apos;&apos;SG&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT DISTINCT codobiect, 0, codgest, &apos;&apos;IES&apos;&apos;
    FROM TMP_PLANIFSTOC
    WHERE FILTRU = &apos;&apos;SG&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);

    sSelect := &apos;
    INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT, CODGEST, FILTRU)
    SELECT DISTINCT codobiect, 0, codgest, &apos;&apos;IES0&apos;&apos;
    FROM TMP_PLANIFSTOC
    WHERE FILTRU = &apos;&apos;SG&apos;&apos; &apos;;
    LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
  end if;

  insert into tmp_planifstoc(codobiect, tg, cant, serie, codgest, filtru)
  select tmp.codobiect, tgcursor.tg, cantcursor.cant, sercursor.serie, tmp.codgest, &apos;SERTG&apos;
  from (select distinct codobiect, codgest from tmp_planifstoc where filtru = &apos;SG&apos;) tmp
       left join (select stragg3200(tg) tg, codobiect, codgest from (
                  select distinct tg, codobiect, codgest
                  from tmp_planifstoc
                  where filtru = &apos;SG&apos; )
                  group by codobiect, codgest
                  ) tgcursor on tgcursor.codobiect = tmp.codobiect and tmp.codgest = tgcursor.codgest
       left join (select stragg3200(serie) serie, codobiect, codgest from (
                  select distinct serie, codobiect, codgest
                  from tmp_planifstoc
                  where filtru = &apos;SG&apos; )
                  group by codobiect, codgest
                  ) sercursor on sercursor.codobiect = tmp.codobiect and tmp.codgest = sercursor.codgest
       left join (select sum(cant) cant, codobiect, codgest
                  from tmp_planifstoc
                  where filtru = &apos;SG&apos;
                  group by codobiect, codgest ) cantcursor on cantcursor.codobiect = tmp.codobiect and tmp.codgest = cantcursor.codgest;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     Articol,
     UM,
     Clasa,
     GestCmd,
     Masa,
     CODINTERN,
     CODEXTERN,
     StocIni,
     StocBlocat,
     CantAcc,
     Rest,
     CantIes,
     Intrari,
     StocFin,
     Rez,
     Serie,
     TG,
     GestStoc,
     ParPalet,
     ParCutie
   &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    CC AS (
      SELECT C1.CodObiect,
        SUM(C1.CantComandat) CantC,
        SUM(C1.CantAcceptat) CantA,
        SUM(C1.RestAcceptat) RestA,
        C1.GESTACT CODGEST,
        CMDSERTG.REST
      FROM COMANDA1 C1
           INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
           INNER JOIN TMP_GESTCMD GESTCMD ON C1.GESTACT = GESTCMD.CODGEST AND GESTCMD.CODOBIECT = C1.CODOBIECT
           LEFT  JOIN (SELECT C1.CODCOMANDA1, SUM(R.REST) REST
                       FROM REZERVATS R
                            INNER JOIN COMANDA1 C1 ON R.CODCOMANDA1 = C1.CODCOMANDA1
                            INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                            INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
                            INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR&apos;||chr(13);
  if not vAllGestStoc then
    sSelect := sSelect||&apos;   INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = NIR.GEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;||chr(13);
  end if;
  sSelect := sSelect||&apos;
                       WHERE NVL(C.INCHISA, 0) = 0
                             AND C.Operat = 1 AND NVL(C.Anulat, 0) = 0 AND C.TipDoc = 18 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||chr(13);
  if not vNoTermen then
    sSelect := sSelect||&apos;    AND C1.TERMEN BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;||chr(13);
  end if;
  sSelect := sSelect||&apos;GROUP BY C1.CODCOMANDA1) CMDSERTG ON C1.CODCOMANDA1 = CMDSERTG.CODCOMANDA1
      WHERE NVL(C.INCHISA, 0) = 0
        AND C.Operat = 1 AND NVL(C.Anulat, 0) &lt;&gt; 1 AND C.TipDoc = 18 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        AND C1.TERMEN BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
      GROUP BY C1.CodObiect, C1.GESTACT, CMDSERTG.REST),
    STOCBLOCAT AS (
      SELECT SUM(NSE.REST) CANT, NS.CODOBIECT, GESTCMD.CODGEST
      FROM NIRSER NSE
           INNER JOIN NIRSTOC NS ON NSE.CODNIRSTOC = NS.CODNIRSTOC
           INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
           INNER JOIN TMP_GESTCMD GESTCMD ON GESTCMD.CODGEST = NIR.GEST AND GESTCMD.CODOBIECT = NS.CODOBIECT
      WHERE NSE.STARE = 4
      GROUP BY NS.CODOBIECT, GESTCMD.CODGEST
      )
  SELECT
    OBJ.DENUMIRE,
    NUM.DEN_UM,
    CA.DEN_CLASEA,
    GestCmd.DEN_GEST,
    nvl(OBJ.Masa,0),
    OBJ.CODINTERN,
    OBJ.CODEXTERN,
    nvl(SI.CANT,0),
    nvl(StocBlocat.CANT,0),
    nvl(CC.CantA,0),
    nvl(CC.RestA,0),
    nvl(IES.Cant,0),
    nvl(INTR.Cant,0),
    CASE
      WHEN NVL(SI.CANT,0) + nvl(INTR.Cant,0) - NVL(IES.Cant,0) &lt; 0 THEN 0
      ELSE NVL(SI.CANT,0) + nvl(INTR.Cant,0) - NVL(IES.Cant,0)
    END,
    CC.REST,
    SERTG.SERIE,
    SERTG.TG,
    GestCmd.DEN_GEST,
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;PALET&apos;&apos;, OBJ.CODOBIECT),
    PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;CUTIE&apos;&apos;, OBJ.CODOBIECT) &apos;||gUserAlias||&apos;
  FROM TMP_GESTCMD GESTCMD
    INNER JOIN CC ON CC.CODGEST = GESTCMD.CODGEST AND CC.CODOBIECT = GESTCMD.CODOBIECT
    INNER JOIN NARTOBJ OBJ ON CC.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NUM ON NUM.CODUM = NA.UM
    LEFT  JOIN NCLASEA CA ON CA.CODCLASEA = NA.CLASA
    LEFT  JOIN TMP_PLANIFSTOC SI ON GESTCMD.CODGEST = SI.CODGEST AND SI.CODOBIECT = OBJ.CODOBIECT AND SI.FILTRU = &apos;&apos;STOCINI&apos;&apos;
    LEFT  JOIN TMP_PLANIFSTOC INTR ON GESTCMD.CODGEST = INTR.CODGEST AND INTR.CODOBIECT = OBJ.CODOBIECT AND INTR.FILTRU = &apos;&apos;INTRARI&apos;&apos;
    LEFT  JOIN TMP_PLANIFSTOC IES ON IES.CODOBIECT = OBJ.CODOBIECT AND GESTCMD.CODGEST = IES.CODGEST AND IES.FILTRU = &apos;&apos;IES&apos;&apos;
    LEFT  JOIN TMP_PLANIFSTOC SERTG ON SERTG.CODOBIECT = OBJ.CODOBIECT AND GESTCMD.CODGEST = SERTG.CODGEST AND SERTG.FILTRU = &apos;&apos;SERTG&apos;&apos;
    LEFT  JOIN STOCBLOCAT ON STOCBLOCAT.CODOBIECT = OBJ.CODOBIECT AND STOCBLOCAT.CODGEST = GESTCMD.CODGEST &apos;||
    gSuplJoins||&apos;
  WHERE
    nvl(na.tiparticol,0) = 0 and
    (nvl(SI.CANT,0) &lt;&gt; 0 OR
     nvl(INTR.CANT,0) &lt;&gt; 0 OR
     nvl(StocBlocat.CANT,0) &lt;&gt; 0 OR
     nvl(CC.CantA,0) &lt;&gt; 0 OR
     nvl(CC.RestA,0) &lt;&gt; 0 OR
     nvl(IES.Cant,0) &lt;&gt; 0) &apos;;

  if vAllGestCmd then
    sSelect1 := &apos;
    WITH
      CC AS (
        SELECT C1.CodObiect,
          SUM(C1.CantComandat) CantC,
          SUM(C1.CantAcceptat) CantA,
          SUM(C1.RestAcceptat) RestA,
          CMDSERTG.REST
        FROM COMANDA1 C1
             INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
             LEFT  JOIN (SELECT C1.CODCOMANDA1, SUM(R.REST) REST
                         FROM REZERVATS R
                              INNER JOIN COMANDA1 C1 ON R.CODCOMANDA1 = C1.CODCOMANDA1
                              INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                              INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
                              INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR&apos;||chr(13);
    if not vAllGestStoc then
      sSelect1 := sSelect1||&apos; INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = NIR.GEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;||chr(13);
    end if;
    sSelect1 := sSelect1||&apos;WHERE NVL(C.INCHISA, 0) = 0
                               AND C.Operat = 1 AND NVL(C.Anulat, 0) = 0 AND C.TipDoc = 18 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||chr(13);
    if not vNoTermen then
      sSelect1 := sSelect1||&apos;  AND C1.TERMEN BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;||chr(13);
    end if;
    sSelect1 := sSelect1||&apos;GROUP BY C1.CODCOMANDA1) CMDSERTG ON C1.CODCOMANDA1 = CMDSERTG.CODCOMANDA1
        WHERE NVL(C.INCHISA, 0) = 0
              AND C.Operat = 1 AND NVL(C.Anulat, 0) &lt;&gt; 1 AND C.TipDoc = 18 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
              AND C1.TERMEN BETWEEN &apos;&apos;&apos;||vDataStart||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;
              and not exists (select gestcmd.codgest from tmp_gestcmd gestcmd where gestcmd.codgest = c1.gestact AND GESTCMD.CODOBIECT = C1.CODOBIECT)
        GROUP BY C1.CodObiect, CMDSERTG.REST),
      STOCBLOCAT AS (
      SELECT SUM(NSE.REST) CANT, NS.CODOBIECT, GESTCMD.CODGEST
      FROM NIRSER NSE
           INNER JOIN NIRSTOC NS ON NSE.CODNIRSTOC = NS.CODNIRSTOC
           INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
           INNER JOIN TMP_GESTCMD GESTCMD ON GESTCMD.CODGEST = NIR.GEST AND GESTCMD.CODOBIECT = NS.CODOBIECT
      WHERE NSE.STARE = 4
      GROUP BY NS.CODOBIECT, GESTCMD.CODGEST
      )
    SELECT
      OBJ.DENUMIRE,
      NUM.DEN_UM,
      CA.DEN_CLASEA,
      &apos;&apos;...nedefinita...&apos;&apos;,
      nvl(OBJ.Masa,0),
      OBJ.CODINTERN,
      OBJ.CODEXTERN,
      nvl(SI.CANT,0),
      nvl(StocBlc.CANT,0),
      nvl(CC.CantA,0),
      nvl(CC.RestA,0),
      nvl(IES.Cant,0),
      nvl(INTR.Cant,0),
      CASE
        WHEN NVL(SI.CANT,0) + nvl(INTR.Cant,0) - NVL(IES.Cant,0) &lt; 0 THEN 0
        ELSE NVL(SI.CANT,0) + nvl(INTR.Cant,0) - NVL(IES.Cant,0)
      END,
      CC.REST,
      SERTG.SERIE,
      SERTG.TG,
      GI.DEN_GEST,
      PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;PALET&apos;&apos;, OBJ.CODOBIECT),
      PKG_LIST_BASE_PLANIFSTOC.GETPARBYCODEXTERN(&apos;&apos;CUTIE&apos;&apos;, OBJ.CODOBIECT) &apos;||gUserAlias||&apos;
    FROM (SELECT OBJ.CODOBIECT, G.CODGEST FROM NARTOBJ OBJ, NGEST G WHERE OBJ.CODOBIECT &gt; 0 AND G.CODGEST &gt; 0) OBJGEST
      INNER JOIN NGEST GI ON GI.CODGEST = OBJGEST.CODGEST&apos;;
    if not vAllGestStoc then
      sSelect1 := sSelect1||&apos;
        INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = GI.CODGEST AND TMP.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect1 := sSelect1||&apos;
      INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = OBJGEST.CODOBIECT
      INNER JOIN NART NA ON NA.CODARTICOL = OBJ.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = NA.UM
      LEFT  JOIN CC ON CC.CODOBIECT = OBJ.CODOBIECT
      LEFT  JOIN NCLASEA CA ON CA.CODCLASEA = NA.CLASA
      LEFT  JOIN TMP_PLANIFSTOC IES ON IES.CODOBIECT = OBJGEST.CODOBIECT AND IES.CODGEST = OBJGEST.CODGEST AND IES.FILTRU = &apos;&apos;IES0&apos;&apos;
      LEFT  JOIN TMP_PLANIFSTOC SERTG ON SERTG.CODOBIECT = OBJ.CODOBIECT AND GI.CODGEST = SERTG.CODGEST AND SERTG.FILTRU = &apos;&apos;SERTG&apos;&apos;
      LEFT  JOIN (SELECT TMP.CANT, TMP.CODOBIECT, TMP.CODGEST
                  FROM TMP_PLANIFSTOC TMP &apos;;
    if not vAllGestStoc then
      sSelect1 := sSelect1||&apos;
                       INNER JOIN TMP_MANEVRA_LISTE TM ON TMP.CODGEST = TM.VALOARE AND TM.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect1 := sSelect1||&apos;
                  WHERE TMP.FILTRU = &apos;&apos;STOCINI&apos;&apos;
                 ) SI ON SI.CODOBIECT = OBJ.CODOBIECT AND GI.CODGEST = SI.CODGEST
       LEFT  JOIN (SELECT TMP.CANT, TMP.CODOBIECT, TMP.CODGEST
                  FROM TMP_PLANIFSTOC TMP &apos;;
    if not vAllGestStoc then
      sSelect1 := sSelect1||&apos;
                       INNER JOIN TMP_MANEVRA_LISTE TM ON TMP.CODGEST = TM.VALOARE AND TM.FILTRU = &apos;&apos;CODGESTSTOC&apos;&apos; &apos;;
    end if;
    sSelect1 := sSelect1||&apos;
                  WHERE TMP.FILTRU = &apos;&apos;INTRARI&apos;&apos;
                 ) INTR ON INTR.CODOBIECT = OBJ.CODOBIECT AND GI.CODGEST = INTR.CODGEST
      LEFT  JOIN (SELECT SUM(CANT) CANT,CODOBIECT, CODGEST FROM STOCBLOCAT GROUP BY CODOBIECT,CODGEST ) STOCBLC ON STOCBLC.CODOBIECT = OBJ.CODOBIECT AND STOCBLC.CODGEST = GI.CODGEST
      &apos;||gSuplJoins||&apos;
    WHERE
      nvl(na.tiparticol,0) = 0 and
      (nvl(SI.CANT,0) &lt;&gt; 0 OR
       nvl(INTR.CANT,0) &lt;&gt; 0 OR
       nvl(CC.CantA,0) &lt;&gt; 0 OR
       nvl(CC.RestA,0) &lt;&gt; 0 OR
       nvl(IES.Cant,0) &lt;&gt; 0) AND NVL(GI.CODGEST,0) &gt; 0&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  if vAllGestCmd then
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
    sSelect := &apos;delete &apos;||tmpName||&apos; where CantAcc = 0 and GestCmd = &apos;&apos;...nedefinita...&apos;&apos; &apos;;
    EXECUTE IMMEDIATE sSelect;
  end if;

--  pkg_globals.ResetAllRecordsLunaFlags;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PLANIFSTOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A6E98ADBE6BF4DEEF6C65B8C8A6CB45E132370E0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PMP IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(30000);
  sInsertTMP    VARCHAR2(30000);
  vAnPrec       NUMBER(4);
  vLunaPrec     NUMBER(2);
  vAnCur        NUMBER(4);
  vLunaCur      NUMBER(2);
  vAnFin        NUMBER(4);
  vLunaFin      NUMBER(2);
BEGIN
  gSuplCols := &apos;nartobj o, nart a&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vLunaCur  := mod(PKG_LIST_SELECTLUNAAN.LunaStart,12);
  IF vLunaCur = 0 THEN vLunaCur := 12; END IF;
  vAnCur    := (PKG_LIST_SELECTLUNAAN.LunaStart - vLunaCur) /12;

  vLunaFin  := mod(PKG_LIST_SELECTLUNAAN.LunaStop,12);
  IF vLunaFin = 0 THEN vLunaFin := 12; END IF;
  vAnFin    := (PKG_LIST_SELECTLUNAAN.LunaStop - vLunaFin) /12;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(DenArt, TipLinie, Doc, An, Luna, Ord, CANT, VACHIZLEI, VACHIZVAL, VPMPLEI, VPMPVAL&apos;||gUserFields||&apos; )
  SELECT o.denumire, t.tiplinie, t.document, t.an, t.luna, t.tip, t.cant, t.vachizlei, t.vachizval, t.vpmplei, t.vpmpval &apos;||gUserAlias||&apos;
  FROM tmp_list_pmp t
    LEFT JOIN nartobj o ON o.codobiect = t.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol &apos;||
    gSuplJoins||&apos;
  WHERE t.tip &gt;= 0&apos;;

  pkg_globals.Calculeaza_Luna_Precedenta(vAnCur,vLunaCur, vAnPrec,vLunaPrec);

  sInsertTMP :=
  &apos;INSERT INTO tmp_list_pmp ( CODOBIECT, AN, LUNA, TIP, TIPLINIE, CANT, VACHIZLEI, VACHIZVAL, VPMPLEI, VPMPVAL )
  WITH
    SI AS (
      SELECT NS.CODOBIECT, SUM(NL.REST) CANT, SUM(NL.REST * (NS.PRET - NS.ADAOS)) VACHIZLEI, SUM(NL.REST * NS.PUVAL) VACHIZVAL
      FROM nirluna nl
        INNER JOIN nirstoc ns  ON ns.codnirstoc = nl.codnirstoc
        INNER JOIN nir     n   ON n.codnir      = ns.codnir
        INNER JOIN ngest   g   ON g.codgest     = n.gest
        INNER JOIN ioart1  ioa ON ioa.codioart  = ns.codioart AND &apos;||To_Char(vANPrec * 12 + vLunaPrec)||&apos; BETWEEN ioa.ALStart and ioa.ALStop AND ioa.mg = 3
      WHERE nl.an = &apos;||vANPrec||&apos; AND nl.luna = &apos;||vLunaPrec||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;g&apos;,&apos;codsubunit&apos;)||&apos;
      GROUP BY NS.CODOBIECT
    ),
    PMP AS (
      SELECT CODOBIECT,
        CASE WHEN SUM(CANTINTR) = 0 THEN 0 ELSE SUM(VALINTR)  /SUM(CANTINTR) END PMPLEI,
        CASE WHEN SUM(CANTINTR) = 0 THEN 0 ELSE SUM(VALVALUTA)/SUM(CANTINTR) END PMPVAL
      FROM pmpluna p
      WHERE p.an = &apos;||vANPrec||&apos; AND p.luna = &apos;||vLunaPrec||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;p&apos;,&apos;codsubunit&apos;)||&apos;
      GROUP BY P.CODOBIECT
    )
    SELECT si.codobiect, &apos;||vAnCur||&apos;, &apos;||vLunaCur||&apos;, 0, &apos;&apos;Stoc initial&apos;&apos;, si.cant, si.vachizlei, si.vachizval, si.cant * pmp.pmplei, si.cant * pmp.pmpval
    FROM SI LEFT JOIN PMP ON PMP.CODOBIECT = SI.CODOBIECT&apos;;
  LIST_EXECUTE_IMMEDIATE(sInserttmp, aListID, aListVer);  

  WHILE vAnCur*12+vLunaCur &lt;= vAnFin*12+vLunaFin
  LOOP
    sInsertTMP :=
    &apos;INSERT INTO tmp_list_pmp ( CODOBIECT, AN, LUNA, TIP, CANT, VACHIZLEI, VACHIZVAL, TIPLINIE, DOCUMENT )
    WITH
      IOA AS (
        SELECT codioart, mg
        FROM (
          SELECT codioart, Max(mg) KEEP (Dense_Rank last ORDER BY ANSTART, LUNASTART) mg
          FROM ioart1
          WHERE ANSTART * 12 + LUNASTART &lt;= &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos;
          GROUP BY codioart)
        WHERE mg = 3 ),
      M AS (
        SELECT -- NIR Intrari
          NS.CODOBIECT, 1 TIP, NS.CANTNIR CANT,
          NS.CANTNIR * (NS.PRET - NS.ADAOS) VACHIZLEI, NS.CANTNIR * NS.PUVAL VACHIZVAL,
          &apos;&apos;Intrari luna &apos;&apos;||I.An||&apos;&apos;.&apos;&apos;||I.Luna TIPLINIE,
          I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||To_Date(I.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOC
        FROM NIRSTOC NS
          INNER JOIN NIR     N   ON N.CODNIR     = NS.CODNIR
          INNER JOIN INTRARI I   ON I.CODINTR    = N.CODINTR
          INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg = 3
        WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7)
          AND N.ANULAT = 0 AND N.OPERAT = 1
          AND I.AN = &apos;||vAnCur||&apos; AND I.LUNA = &apos;||vLunaCur||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT -- NIR-uri din MISCARI INTERNE
          NS.CODOBIECT, 1 TIP, NS.CANTNIR CANT,
          NS.CANTNIR * (NS.PRET - NS.ADAOS) VACHIZLEI, NS.CANTNIR * NS.PUVAL VACHIZVAL,
          &apos;&apos;Intrari luna &apos;&apos;||T.An||&apos;&apos;.&apos;&apos;||T.Luna TIPLINIE,
          T.PREFIXDOC||T.NRDOC||&apos;&apos;/&apos;&apos;||To_Date(T.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOC
        FROM NIRSTOC NS
          INNER JOIN NIR     N ON N.CODNIR = NS.CODNIR
          INNER JOIN TRANSF  T ON T.CODTRANSF = N.CODTRANSF
          INNER JOIN NIRSTOC NSP ON NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
          INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART  AND &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg = 3
          LEFT  JOIN ioart1  I2  ON IOA.CODIOART = NSP.CODIOART AND &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos; BETWEEN  I2.ALStart and  I2.ALStop AND  I2.mg = 3
        WHERE N.TIPNIR IN (12, 13)
          AND N.ANULAT = 0 AND N.OPERAT = 1
          AND T.AN = &apos;||vAnCur||&apos; AND T.LUNA = &apos;||vLunaCur||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
          AND I2.CODIOARt IS NULL
        UNION ALL
        SELECT -- RETURURI INTRARI
          NS.CODOBIECT, -1 TIP, -L1.CANT,
          -L1.CANT * (NS.PRET - NS.ADAOS) VACHIZLEI, -L1.CANT * NS.PUVAL VACHIZVAL,
          NULL TIPLINIE,
          NULL DOC
        FROM LIVR1 L1
          INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
          INNER JOIN INTRARI I   ON I.CODINTR = L.CODINTR
          INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg = 3
        WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7)
          AND L.OPERAT = 1 AND L.ANULAT = 0
          AND I.AN = &apos;||vAnCur||&apos; AND I.LUNA = &apos;||vLunaCur||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL -- IESIRI
        SELECT
          NS.CODOBIECT, CASE WHEN N.CODIES = I.CODIES THEN 1 ELSE -1 END TIP, -L1.CANT CANT,
          -L1.CANT * (NS.PRET - NS.ADAOS) VACHIZLEI, -L1.CANT * NS.PUVAL VACHIZVAL,
          CASE WHEN N.CODIES = I.CODIES THEN &apos;&apos;Iesiri in rosu cu creare de stoc luna &apos;&apos;||I.An||&apos;&apos;.&apos;&apos;||I.Luna ELSE NULL END TIPLINIE,
          CASE WHEN N.CODIES = I.CODIES THEN I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||To_Date(I.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE NULL END DOC
        FROM LIVR1 L1
          INNER JOIN LIVR    L   ON L.CODLIVR = L1.CODLIVR
          INNER JOIN IESIRI  I   ON I.CODIES = L.CODIES
          INNER JOIN IESIRI1 I1  ON I1.CODIES1 = L1.CODIES1
          INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN ioart1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||To_Char(vAnCur*12 + vLunaCur)||&apos; BETWEEN IOA.ALStart and IOA.ALStop AND IOA.mg = 3
          INNER JOIN NIR     N   ON N.CODNIR = NS.CODNIR
        WHERE L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24)
          AND L.OPERAT = 1 AND L.ANULAT = 0
          AND I.AN = &apos;||vAnCur||&apos; AND I.LUNA = &apos;||vLunaCur||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      )
    SELECT m.codobiect, &apos;||vAnCur||&apos;, &apos;||vLunaCur||&apos;, m.tip, Sum(m.cant), Sum(m.vachizlei), Sum(m.vachizval), m.tiplinie, m.doc
    FROM m
    GROUP BY m.codobiect, m.tip, m.tiplinie, m.doc&apos;;

    LIST_EXECUTE_IMMEDIATE(sInserttmp, aListID, aListVer);

    INSERT INTO  tmp_list_pmp (CODOBIECT, AN, LUNA, TIP, CANT, VACHIZLEI, VACHIZVAL, VPMPLEI , VPMPVAL, TIPLINIE)
    SELECT codobiect,  vAnCur, vLunaCur, 3, Sum(cant), Sum(VACHIZLEI), Sum(VACHIZVAL),
      CASE WHEN Sum(DECODE(TIP,-1,0,CANT)) = 0 THEN 0 ELSE Sum(CANT) * Sum(DECODE(TIP,1,VACHIZLEI,-1,0,VPMPLEI)) / Sum(DECODE(TIP,-1,0,CANT)) END vpmplei,
      CASE WHEN Sum(DECODE(TIP,-1,0,CANT)) = 0 THEN 0 ELSE Sum(CANT) * Sum(DECODE(TIP,1,VACHIZVAL,-1,0,VPMPVAL)) / Sum(DECODE(TIP,-1,0,CANT)) END vpmpval,
      &apos;Sold final &apos;||vAnCur||&apos;.&apos;||vLunaCur
    FROM tmp_list_pmp
    GROUP BY codobiect;

    INSERT INTO  tmp_list_pmp (CODOBIECT, AN, LUNA, TIP, CANT, VACHIZLEI, VACHIZVAL, TIPLINIE)
    SELECT codobiect,  vAnCur, vLunaCur, 2, Sum(cant), Sum(VACHIZLEI), Sum(VACHIZVAL),
      &apos;Total intrari &apos;||vAnCur||&apos;.&apos;||vLunaCur
    FROM tmp_list_pmp
    WHERE tip = 1
    GROUP BY codobiect;

    DELETE tmp_list_pmp WHERE an&lt;&gt;vAnCur OR luna&lt;&gt;vLunaCur;
    EXECUTE IMMEDIATE sInsert;
    DELETE tmp_list_pmp WHERE tip&lt;3;

    IF vLunaCur &lt; 12
    THEN vLunaCur := vLunaCur + 1;
    ELSE vAnCur := vAnCur + 1; vLunaCur := 1;
    END IF;
  END LOOP;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PMP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PONTAJESA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F2E9ACA9A2B70E40B91F9FCEE77748FF1EB0B84</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PontajeSA IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
sPer     VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;comanda4 c4, comanda2 c2, comanda3 c3, comanda c, iesiri i, iesiri bc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
      NAV_CodDoc,
      NAV_TipDoc,
      SERIADOC,
      NRDOC,
      DATADOC,
      OPERATIE,
      NumeAngajat,
      Formatie,
      LocMunca,
      OreLucrate,
      DataStart,
      DataStop,
      NumePartener,
      TIPComanda,
      SerieCaroserie,
      SerieMotor,
      StareComanda,
      Facturat,
      NrFact,
      DataFact,
      AnFact,
      LunaFact,
      Consumat,
      NrBC,
      DataBC,
      AnBC,
      LunaBC  &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
      with CA as (
        select sum(Coalesce(c1.cantacceptat,0)) cant, c1.codcomanda
        from comanda c
             inner join comanda1 c1 on c1.codcomanda = c.codcomanda
        WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) in (0,1)
              AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda      
      ),
      RA as (
        select sum(Coalesce(c1.restacceptat,0)) cant, c1.codcomanda
        from comanda c
             inner join comanda1 c1 on c1.codcomanda = c.codcomanda
        WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) in (0,1)
              AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda
      ),
      CU_REST as (
        SELECT NVL(COUNT(*),0) cant, c1.codcomanda 
        FROM COMANDA1 c1
             inner join comanda c on c.codcomanda = c1.codcomanda  
        WHERE NVL(CANTACCEPTAT, 0) &gt; 0 AND NVL(RESTACCEPTAT, 0) &gt; 0
              and C.TipDoc = 92 and nvl(c1.modinchidere,0) in (0,1)
              AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda
      ),  
      BC_CA as (
        select sum(Coalesce(c1.cantacceptat,0)) cant, c1.codcomanda
        from comanda1 c1
             inner join comanda c on c.codcomanda = c1.codcomanda
             inner join nartobj o on o.codobiect = c1.codobiect
             inner join nart a on a.codarticol = o.codarticol
        WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) = 2
              and a.tiparticol = &apos;&apos;0&apos;&apos; AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda      
      ),
      BC_RA as (
        select sum(Coalesce(c1.restacceptat,0)) cant, c1.codcomanda
        from comanda1 c1
             inner join comanda c on c.codcomanda = c1.codcomanda
             inner join nartobj o on o.codobiect = c1.codobiect
             inner join nart a on a.codarticol = o.codarticol
        WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) = 2
              and a.tiparticol = &apos;&apos;0&apos;&apos; AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda      
      ),
      BC_CU_REST as (
        SELECT NVL(COUNT(*),0) cant, c1.codcomanda 
        FROM COMANDA1 c1
             inner join comanda c on c.codcomanda = c1.codcomanda
             inner join nartobj o on o.codobiect = c1.codobiect
             inner join nart a on a.codarticol = o.codarticol
        WHERE NVL(c1.CANTACCEPTAT, 0) &gt; 0 AND NVL(c1.RESTACCEPTAT, 0) &gt; 0
              and C.TipDoc = 92 and nvl(c1.modinchidere,0) = 2
              and a.tiparticol = &apos;&apos;0&apos;&apos; AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
        group by c1.codcomanda
      ),
      Last_Fact as (
        select max(i.codies) codies, cc1.codcomanda
        from iesiri i
             inner join iesiri1 i1 on i.codies = i1.codies
             inner join ieslink l on l.codies1 = i1.codies1
             inner join comanda1 cc1 on cc1.codcomanda1 = l.codliniecomanda
             inner join (SELECT max(ii.datadoc) datadoc, c1.codcomanda 
                         FROM comanda1 c1
                              inner join comanda c on c.codcomanda = c1.codcomanda 
                              inner join ieslink li on li.codliniecomanda = c1.codcomanda1
                              inner join iesiri1 ii1 on ii1.codies1 = li.codies1
                              inner join iesiri ii on ii.codies = ii1.codies
                         WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) in (0,1)
                               AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
                               and ii.anulat = 0 and ii.operat = 1
                         group by c1.codcomanda) maxd on maxd.datadoc = i.datadoc and cc1.codcomanda = maxd.codcomanda
        where i.anulat = 0 and i.operat = 1                 
        group by cc1.codcomanda
      ),
      Last_BC as (
        select max(i.codies) codies, cc1.codcomanda
        from iesiri i
             inner join iesiri1 i1 on i.codies = i1.codies
             inner join comanda1 cc1 on cc1.codcomanda1 = i1.codcmdint1
             inner join (SELECT max(ii.datadoc) datadoc, c1.codcomanda
                         FROM comanda1 c1
                              inner join comanda c on c.codcomanda = c1.codcomanda 
                              inner join iesiri1 ii1 on ii1.codcmdint1 = c1.codcomanda1
                              inner join iesiri ii on ii.codies = ii1.codies
                         WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) = 2 and ii.tipdoc = 24
                               AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
                               and ii.anulat = 0 and ii.operat = 1
                               and not exists (select l.codies1 from ieslink l where l.codies1 = ii1.codies1)
                         group by c1.codcomanda) maxd on maxd.datadoc = i.datadoc and cc1.codcomanda = maxd.codcomanda
        where i.anulat = 0 and i.operat = 1 and i.tipdoc = 24
        and not exists (select l.codies1 from ieslink l where l.codies1 = i1.codies1)
        group by cc1.codcomanda
        union all
        select max(i.codies) codies, cc1.codcomanda
        from iesiri i
             inner join iesiri1 i1 on i.codies = i1.codies
             inner join ieslink l on l.codies1 = i1.codies1
             inner join comanda1 cc1 on cc1.codcomanda1 = l.codliniecomanda
             inner join (SELECT max(ii.datadoc) datadoc, c1.codcomanda
                         FROM comanda1 c1
                              inner join comanda c on c.codcomanda = c1.codcomanda
                              inner join ieslink l on l.codliniecomanda = c1.codcomanda1
                              inner join iesiri1 ii1 on ii1.codies1 = l.codies1
                              inner join iesiri ii on ii.codies = ii1.codies
                         WHERE C.TipDoc = 92 and nvl(c1.modinchidere,0) = 2 and ii.tipdoc = 24
                               AND C.DataDoc &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
                               and ii.anulat = 0 and ii.operat = 1
                         group by c1.codcomanda) maxd on maxd.datadoc = i.datadoc and cc1.codcomanda = maxd.codcomanda
        where i.anulat = 0 and i.operat = 1 and i.tipdoc = 24
        group by cc1.codcomanda
      )
      SELECT
        C.CodComanda,
        C.TipDoc,
        C.SeriaDoc,
        C.NrDoc,
        C.DataDOC,
        NO.Denumire Operatie,
        P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME NumeAngajat,
        F.Den_Formatie Formatie,
        L.DENUMIRE LocMunca,
        C4.Ore OreLucrate,
        C4.datastart,
        C4.datastop,
        Pa.Den_Part NumePartener,
        Npc.TipComanda,
        NPA.SERIEC SerieCaroserie,
        NPA.Seriem SerieMotor,
        --Decode(C.Verificat ,0,&apos;&apos;Initiala&apos;&apos;,1,&apos;&apos;Spre devizare&apos;&apos;,2,&apos;&apos;Finalizata&apos;&apos;) StareComanda,
				CASE WHEN C.Anulat = 1 THEN &apos;&apos;ANULATA&apos;&apos;
														   WHEN C.OPERAT = 0 THEN &apos;&apos;NEPRELUATA&apos;&apos;
														   ELSE CASE WHEN C.Verificat &lt;&gt; 0 and nvl(CU_REST.CANT,0) &lt;&gt; 0 THEN &apos;&apos;FINALIZATA&apos;&apos;
																			   WHEN C.Verificat &lt;&gt; 0 and nvl(CU_REST.CANT,0) = 0  THEN &apos;&apos;INCHISA&apos;&apos;
																			   ELSE &apos;&apos;PRELUATA&apos;&apos; END
				END StareComanda, 
        CASE
          WHEN C.FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos;
          WHEN CA.Cant = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
          WHEN CA.Cant = RA.Cant THEN &apos;&apos;NEFACTURATA&apos;&apos;
          WHEN CA.CANT &gt; RA.CANT AND nvl(CU_REST.CANT,0) &gt; 0 THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
          WHEN CA.CANT &lt;&gt; 0 AND nvl(CU_REST.CANT,0) = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
          ELSE NULL
        END,
        i.nrdoc,
        i.datadoc,
        i.an,
        i.luna,
        CASE
          WHEN BC_CA.Cant = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
          WHEN BC_CA.Cant = BC_RA.Cant THEN &apos;&apos;NECONSUMATA&apos;&apos;
          WHEN BC_CA.CANT &gt; BC_RA.CANT AND nvl(BC_CU_REST.CANT,0) &gt; 0 THEN &apos;&apos;CONSUMATA PARTIAL&apos;&apos;
          WHEN BC_CA.CANT &lt;&gt; 0 AND nvl(BC_CU_REST.CANT,0) = 0 THEN &apos;&apos;CONSUMATA INTEGRAL&apos;&apos;
          ELSE NULL
        END,
        bc.nrdoc,
        bc.datadoc,
        bc.an,
        bc.luna &apos;||gUserAlias||&apos;
      FROM comanda4 c4
        Left join Comanda C on   C.CodComanda = C4.CodComanda
        Left join Comanda3 C3 on C3.CodComanda3 = C4.CodComanda3
        Left join Comanda2 C2 on C2.CodComanda2 = C3.CodComanda2
        Left join NOper NO on NO.CODOP = C3.CodOperatie
        left join Nparccom NPC on NPC.CodComanda = C.CodComanda
        Left join NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
        LEFT JOIN FORMATII F on F.CodFormatie = C.CodFormatie
        LEFT JOIN FORMATII1 F1 on F1.CodFormatie = F.CodFormatie
        LEFT JOIN LocMunca L on L.CodLoc = F1.LocMunca
        LEFT JOIN NPers P on P.CodPers = C4.CodPers
        LEFT JOIN NPart Pa on Pa.CodPart = C2.CodPart
        LEFT JOIN CA ON CA.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN RA ON RA.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN CU_REST ON CU_REST.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN BC_CA ON BC_CA.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN BC_RA ON BC_RA.CODCOMANDA = C.CODCOMANDA
        LEFT JOIN BC_CU_REST ON BC_CU_REST.CODCOMANDA = C.CODCOMANDA
        left join last_fact on last_fact.codcomanda = c.codcomanda
        left join last_bc on last_bc.codcomanda = c.codcomanda
        left join iesiri i on i.codies = last_fact.codies
        left join iesiri bc on bc.codies = last_bc.codies &apos;||gSuplJoins||&apos;
      WHERE C.TipDoc = 92
      AND C.DataDoc &apos;||sPer||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PontajeSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_POSTCALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66E38050020F39CB1244EAF177CA3A023757A84F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_POSTCALCUL IS

  vCodPC  PCALCUL.CODPC%TYPE;
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodPC IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodPC := pCodPC;
END;

function GetCodPC return number is
begin
  return vCodPC;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(32000);
BEGIN
  gSuplCols :=&apos;COMANDA C, COMANDA1 C1, COMANDA CLI, COMANDA1 CLI1, NGEST G, PRODCOMP PC, NARTOBJ OBJ, NARTOBJ1 OBJ1, NART ART, NUM UM, IOART IOA, NPART PCLI&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     ARTICOL,
     DENUM,
     CANT,
     VAL,
     VALS,
     VALi,
     VALa,
     ValG,
     ValC,
     MAT,
     SECTIE,
     COEF,
     MAN,
     VALMAN,
     REST,
     PUCALC,
     PretMat,
     PUNCTE,
     CENTRU,
     DENIOART,
     PRETREFERINTA,
     PRETRETETA,
     PUMEDINREG  &apos;||gUserFields||&apos; )
   with PUMED As (
     select sum(i1.cant * ns.pret)/sum(i1.cant) Pret, PCA.CodCmd1
     from intrari1 i1
          inner join PCART   PCA on PCA.CodCmd1 = i1.CodCmdInt1
          inner join nirstoc ns  on ns.codintr1 = i1.codintr1
     where PCA.CODPC = &apos;||vCodPC||&apos;
     group by PCA.CodCmd1
   )
   SELECT
     OBJ.DENUMIRE,
     Substr(UM.DEN_UM,1,15),
     Nvl(PCA.CANT, 0),
     PCA.VAL,
     PCA.VALS,
     PCA.VALi,
     PCA.VALa,
     PCA.ValG,
     PCA.ValC,
     PCA.MAT,
     G.DEN_GEST,
     PCA.COEF,
     PCA.MAN,
     PCA.VALMAN,
     MAT.REST,
     Round(CASE WHEN NVL(PCA.CANT, 0) = 0 THEN 0 ELSE (NVL(PCA.MAT, 0)+NVL(PCA.MAN, 0)+NVL(PCA.VALS, 0))/NVL(PCA.CANT, 0) END,5),
     Round(CASE WHEN NVL(PCA.CANT, 0) = 0 THEN 0 ELSE NVL(PCA.MAT, 0)/NVL(PCA.CANT, 0) END,5),
     PCA.PUNCTE,
     CC.Simbol,
     Substr(IOA.DEN_IOART,1,50),
     OBJ1.PRETREFERINTA,
     PC.PRET,
     nvl(PUMED.Pret,0) &apos;||gUserAlias||&apos;
   FROM PCART PCA
        INNER JOIN PCALCUL    PCC  ON PCC.CODPC         = PCA.CODPC
        INNER JOIN COMANDA1   C1   ON PCA.CODCMD1       = C1.CODCOMANDA1
        INNER JOIN COMANDA    C    ON C.CODCOMANDA      = C1.CODCOMANDA
        LEFT  JOIN CMDLINK    L    ON L.CODCOMANDA1     = C1.CODCOMANDA1
        LEFT  JOIN COMANDA1   CLI1 ON L.CODLINIECOMANDA = CLI1.CODCOMANDA1
        LEFT  JOIN COMANDA    CLI  ON CLI1.CODCOMANDA   = CLI.CODCOMANDA
        LEFT  JOIN NPART      PCLI ON PCLI.CODPART      = CLI.PARTENER
        LEFT  JOIN PUMED           on PUMED.CodCmd1     = PCA.CodCmd1
        LEFT  JOIN NGEST      G    ON G.CODGEST         = PCA.CODGEST
        LEFT  JOIN CENTRECOST CC   ON CC.CODCENTRU      = PCA.CODCC
        LEFT  JOIN CMDPRODMAT MAT  ON MAT.CODCOMANDA1   = C1.CODCOMANDA1 AND MAT.TIP = 0
        LEFT  JOIN PRODCOMP   PC   ON PC.CODPRODCOMP    = C1.CODRETETA
        LEFT  JOIN CMDPRODMAT PCM  ON PCM.CODCMDPRODMAT = PCA.CODCMDPRODMAT
        LEFT  JOIN NARTOBJ    OBJ  ON OBJ.CODOBIECT     = COALESCE(PCM.CODOBIECT,C1.CODOBIECT)
        LEFT  JOIN NARTOBJ1   OBJ1 ON OBJ1.CODOBIECT    = OBJ.CODOBIECT AND (PCC.AN*12+PCC.LUNA) BETWEEN OBJ1.ALStart and OBJ1.ALStop
        LEFT  JOIN NART       ART  ON OBJ.CODARTICOL    = ART.CODARTICOL
        LEFT  JOIN NUM        UM   ON UM.CODUM          = ART.UM
        LEFT  JOIN IOART      IOA  ON PCA.CODIOART      = IOA.CODIOART
        LEFT JOIN PCDIR       PCD  ON PCC.CODPC         = PCD.CODPC AND PCD.CODNEST = 742
        LEFT JOIN PCDIR       PCD1 ON PCC.CODPC         = PCD1.CODPC AND PCD1.CODNEST = 934&apos; || gSuplJoins ||
   &apos;WHERE PCA.CODPC = &apos;||vCodPC;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_postcalcul;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DAF8E1F717AA2741035C59CF2D4A3371F8E0AB0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PRODCOMP IS
  gUserFields   VARCHAR2(2500);
  gUserAlias    VARCHAR2(2500);
  gNullAlias    VARCHAR2(2500);
  gSuplCols     VARCHAR2(2500);
  gSuplJoins    VARCHAR2(5000);
  p_CodProdComp NUMBER(20) default 0;
  p_CodComanda1 NUMBER(20) default 0;

PROCEDURE setParams (v_CodProdComp IN NUMBER, v_CodComanda1 in number)
IS
BEGIN
  p_CodProdComp := v_CodProdComp;
  p_CodComanda1 := v_CodComanda1;
END;

function GetCod return number is
begin
  return p_CodProdComp;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSPARAMS IS
  SSQL        VARCHAR2(10000);
  ValCamp     number(20);
  vCodProiect number(20);
  Display     varchar2(500);
  ValDisplay  varchar2(1000);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      OBJ.CodObiect, OBJ.Denumire, P.Obs, P.Data, C1.Cantacceptat, P.D1, P.D2, P.D3, NUM.Den_UM, case when P.TipReteta = 1 then &apos;Agregare&apos; else &apos;Dezagregare&apos; end TipReteta,
      P.CantUM1, P.Coefindirecte, P.Pret,
      c1.cantacceptat/p.cant * nvl(P.ValMat,0) ValMat,
      c1.cantacceptat/p.cant * nvl(P.ValMan,0) ValMan,
      c1.cantacceptat/p.cant * nvl(P.ValRegie,0) ValRegie,
      OBJ.CODINTERN, OBJ.CODEXTERN,
      to_char(P.DATA,&apos;dd.mm.yyyy&apos;) dataI, P.Arhiva, PE.NUME||&apos; &apos;||PE.PRENUME nume_prenume
    FROM COMANDA1 C1
      INNER JOIN PRODCOMP P   ON C1.CODRETETA   = P.CODPRODCOMP
      INNER JOIN NARTOBJ  OBJ ON P.CodObiect    = OBJ.CodObiect
      INNER JOIN NART     ART ON OBJ.CodArticol = ART.CodArticol
      INNER JOIN NUM          ON ART.UM         = NUM.CodUM
      LEFT  JOIN NPERS    PE  ON PE.CodPers     = P.PROIECTANT
    WHERE C1.CodComanda1 = p_CodComanda1
  ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;DenArt&apos;                        , v_rec.Denumire);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CodObiect&apos;                     , v_rec.CodObiect);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Obs&apos;                           , v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cantitati pe&apos;                  , v_rec.Cantacceptat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data&apos;                          , v_rec.Data);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D1&apos;                            , v_rec.D1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D2&apos;                            , v_rec.D2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D3&apos;                            , v_rec.D3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;UM&apos;                            , v_rec.Den_UM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip reteta&apos;                    , v_rec.TipReteta);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cant UM specifica&apos;             , v_rec.CantUM1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Indice cheltuieli indirecte&apos;   , v_rec.Coefindirecte);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Pret&apos;                          , v_rec.Pret);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare materiale pe UM produs&apos;, v_rec.ValMat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare manopera pe UM produs&apos; , v_rec.ValMan);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare regie pe UM produs&apos;    , v_rec.ValRegie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod extern produs finit&apos;       , v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod intern produs finit&apos;       , v_rec.CodIntern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Numar desen/iso&apos;               , v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data intocmirii retetei&apos;       , v_rec.DataI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr arhiva&apos;                     , v_rec.Arhiva);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume si prenume&apos;      , v_rec.Nume_Prenume);
    EXIT;
  END LOOP;
  /*
    1 : aTblName := &apos;NARTOBJ&apos;;
    2 : aTblName := &apos;NPART&apos;;
    3 : aTblName := &apos;NPERS&apos;;
    4 : aTblName := &apos;CONTRACT&apos;;
    5 : aTblName := &apos;NAGENDA&apos;;
  */
  begin
    select nvl(cc1.codproiect,0)
    into vCodProiect
    from COMANDA1 C1
         INNER JOIN CMDLINK  CMDL ON CMDL.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA1 CC1  ON CC1.CODCOMANDA1  = CMDL.CODLINIECOMANDA
    where c1.codcomanda1 = p_CodComanda1;
  exception when others then vCodProiect := 0;
  end;
  if vCodProiect &gt; 0 then
    if PKG_LIST_STRUCT.TmpExists(&apos;PROIECTEXT&apos;) = 1 THEN
      FOR V_CFG IN (SELECT CFG1.NUMECAMP, NVL(CFG1.NOMLINK,0) NOMLINK, CFG1.LOOKUPDISPLAY
                    FROM CFGTABLES1 CFG1
                         INNER JOIN CFGTABLES CFG ON CFG.CODCFGTABLE = CFG1.CODCFGTABLE
                    WHERE CFG.NUMETABELA = &apos;PROIECTEXT&apos;) LOOP
        IF V_CFG.NOMLINK = 0 THEN
          SSQL := &apos;BEGIN
                     FOR V_REC IN (SELECT PEXT.&apos;||V_CFG.NUMECAMP||&apos;
                                   FROM COMANDA1 C1
                                        INNER JOIN CMDLINK    CMDL ON CMDL.CODCOMANDA1 = C1.CODCOMANDA1
                                        INNER JOIN COMANDA1   CC1  ON CC1.CODCOMANDA1  = CMDL.CODLINIECOMANDA
                                        INNER JOIN PROIECTEXT PEXT ON CC1.CODPROIECT   = PEXT.CODPROIECT
                                   WHERE C1.CODCOMANDA1 = &apos;||p_CodComanda1||&apos;
                                   ) LOOP
                       pkg_list_Struct.ADAUGA_PARAM(&apos;&apos;&apos;||V_CFG.NUMECAMP||&apos;&apos;&apos;, v_rec.&apos;||V_CFG.NUMECAMP||&apos;);
                       EXIT;
                     END LOOP;
                   END;&apos;;
          EXECUTE IMMEDIATE SSQL;
        ELSE
          begin
            execute immediate &apos;select PEXT.&apos;||V_CFG.NUMECAMP||&apos;
                               FROM COMANDA1 C1
                                    INNER JOIN CMDLINK    CMDL ON CMDL.CODCOMANDA1 = C1.CODCOMANDA1
                                    INNER JOIN COMANDA1   CC1  ON CC1.CODCOMANDA1  = CMDL.CODLINIECOMANDA
                                    INNER JOIN PROIECTEXT PEXT ON CC1.CODPROIECT   = PEXT.CODPROIECT
                               WHERE C1.CODCOMANDA1 = &apos;||p_CodComanda1 into ValCamp;
          exception when others then ValCamp := 0;
          end;
          if ValCamp &gt; 0 then
            Display := REPLACE(v_cfg.lookupdisplay,&apos;;&apos;,&apos;||&apos;&apos;;&apos;&apos;||&apos;);
            if V_CFG.NOMLINK = 1 THEN
              begin
                execute immediate &apos;select &apos;||Display||&apos; from nartobj where codobiect = &apos;||ValCamp into ValDisplay;
              exception when others then ValDisplay := &apos;&apos;;
              end;
            ELSE IF V_CFG.NOMLINK = 2 THEN
              begin
                execute immediate &apos;select &apos;||Display||&apos; from npart where codpart = &apos;||ValCamp into ValDisplay;
              exception when others then ValDisplay := &apos;&apos;;
              end;
            ELSE IF V_CFG.NOMLINK = 3 THEN
              begin
                execute immediate &apos;select &apos;||Display||&apos; from npers where codpers = &apos;||ValCamp into ValDisplay;
              exception when others then ValDisplay := &apos;&apos;;
              end;
            ELSE IF V_CFG.NOMLINK = 4 THEN
              begin
                execute immediate &apos;select &apos;||Display||&apos; from contract where codcontract = &apos;||ValCamp into ValDisplay;
              exception when others then ValDisplay := &apos;&apos;;
              end;
            ELSE IF V_CFG.NOMLINK = 5 THEN
              begin
                execute immediate &apos;select &apos;||Display||&apos; from nagenda where codagenda = &apos;||ValCamp into ValDisplay;
              exception when others then ValDisplay := &apos;&apos;;
              end;
            END IF; END IF; END IF; END IF; END IF;
            pkg_list_Struct.ADAUGA_PARAM(V_CFG.NUMECAMP, ValDisplay);
          end if;
        END IF;
      END LOOP;
    END IF;
  end if;
END;

PROCEDURE PROCESSPARAMSRET IS
BEGIN
  for v_rec in (
    SELECT
      OBJ.CodObiect, OBJ.Denumire, P.Obs, P.Data, P.Cant, P.D1, P.D2, P.D3, NUM.Den_UM,
      CASE WHEN P.TipReteta = 1 then &apos;Agregare&apos; else &apos;Dezagregare&apos; end TipReteta,
      P.Den_UMSpec, P.CantUM1, P.Coefindirecte, P.Pret,
      nvl(P.ValMat,0) ValMat, nvl(P.ValMan,0) ValMan, nvl(P.ValRegie,0) ValRegie,
      OBJ.CODINTERN, OBJ.CODEXTERN,
      to_char(P.DATA,&apos;dd.mm.yyyy&apos;) dataI, P.Arhiva, PE.NUME||&apos; &apos;||PE.PRENUME nume_prenume,
      ( SELECT max(l.data)
        FROM winmadmin.Log l where l.tabela = &apos;PRODCOMP&apos; AND l.operatie = &apos;M&apos; and l.coddoc = p.codprodcomp
      ) dataU,
      P.Descriere,P.OBS1,P.OBS2,P.OBS3,P.OBS4,P.OBS5,P.OBS6,CLS.DEN_CLASEPROD
    FROM TMP_PRODCOMP P
      INNER JOIN NARTOBJ    OBJ ON P.CodObiect      = OBJ.CodObiect
      INNER JOIN NART       ART ON OBJ.CodArticol   = ART.CodArticol
      INNER JOIN NUM            ON ART.UM           = NUM.CodUM
      LEFT  JOIN NPERS      PE  ON PE.CodPers       = P.PROIECTANT
      LEFT  JOIN NCLASEPROD CLS ON CLS.CODCLASEPROD = P.CODCLASAPROD
    WHERE P.CodProdComp = p_CodProdComp
  ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;DenArt&apos;,                            v_rec.Denumire);
    pkg_list_Struct.ADAUGA_PARAM(&apos;CodObiect&apos;,                         v_rec.CodObiect);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Obs&apos; ,                              v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii1&apos; ,                      v_rec.Obs1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii2&apos; ,                      v_rec.Obs2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii3&apos; ,                      v_rec.Obs3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii4&apos; ,                      v_rec.Obs4);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii5&apos; ,                      v_rec.Obs5);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii6&apos; ,                      v_rec.Obs6);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Clasa&apos; ,                            v_rec.den_claseprod);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Descriere&apos;,                         v_rec.Descriere);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cantitati pe&apos;,                      v_rec.Cant);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data&apos;,                              v_rec.Data);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D1&apos;,                                v_rec.D1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D2&apos;,                                v_rec.D2);
    pkg_list_Struct.ADAUGA_PARAM(&apos;D3&apos;,                                v_rec.D3);
    pkg_list_Struct.ADAUGA_PARAM(&apos;UM&apos;,                                v_rec.Den_UM);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip reteta&apos;,                        v_rec.TipReteta);
    pkg_list_Struct.ADAUGA_PARAM(&apos;UM specifica&apos;,                      v_rec.Den_UMSpec);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cant UM specifica&apos;,                 v_rec.CantUM1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Indice cheltuieli indirecte&apos;,       v_rec.Coefindirecte);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Pret&apos;,                              v_rec.Pret);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare materiale pe UM produs&apos;,    v_rec.ValMat);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare manopera pe UM produs&apos;,     v_rec.ValMan);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Valoare regie pe UM produs&apos;,        v_rec.ValRegie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod extern produs finit&apos;,           v_rec.CodExtern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod intern produs finit&apos;,           v_rec.CodIntern);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Numar desen/iso&apos;,                   v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data intocmirii retetei&apos;,           v_rec.DataI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data ultimei modificari a retetei&apos;, v_rec.DataU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr arhiva&apos;,                         v_rec.Arhiva);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume si prenume&apos;,          v_rec.Nume_Prenume);
    Exit;
  end loop;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sInsert1  VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;NART ART, NARTOBJ OBJ, NCLASEA CLASA, IOART IOART, NPART PROD &apos;;
  if p_CodProdComp &gt; 0 then
    gSuplCols := gSuplCols||&apos;,PRODCOMP P, PRODMAT MAT, PRODREZ REZ&apos;;
  else
    if p_CodComanda1 &gt; 0 then
      gSuplCols := gSuplCols||&apos;,PRODCOMP PC, COMANDA1 C1, CMDPRODMAT CMD&apos;;
    END IF;
  end if;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if p_CodProdComp &gt; 0 then
    sInsert :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos; (
      DenArt, UM, Cant, Pret, D1, D2, D3, UM1, CantUM1, Atribut, IndexLocal,
      ValMat, ValMan, ValRegie, SectieExec, Obs, Tip, Reteta, Proc, ProcTransp &apos;||gUserFields||&apos;)
    SELECT
      obj.Denumire DenArt, NUM.Den_UM, MAT.Cant, MAT.Pret, MAT.D1, MAT.D2, MAT.D3, NUM1.Den_UM, Mat.CantUM1, atr.denumire, mat.indexlocal,
      mat.valmat, mat.valman, mat.valregie, g.den_gest, mat.obs, &apos;&apos;Articol folosit&apos;&apos; tip, P.OBS, mat.adddim, mat.adddim_transp &apos;||gUserAlias||&apos;
    FROM ProdComp P
      INNER JOIN prodgest      pg    on pg.codprodcomp    = p.codprodcomp
      INNER JOIN prodmat       mat   on p.codprodcomp     = mat.codprodcomp and mat.codprodgest = pg.codprodgest
      INNER JOIN ngest         g     on pg.codgest        = g.codgest
      INNER JOIN nartobj       obj   on mat.codobiect     = obj.codobiect
      INNER JOIN nart          art   on obj.codarticol    = art.codarticol
      INNER JOIN num                 on art.um            = num.codum
      LEFT  JOIN PRODREZ       REZ   on REZ.CODPRODCOMP   = P.CODPRODCOMP - P.CODPRODCOMP
      LEFT  JOIN num           NUM1  on art.um1           = num1.codum
      LEFT  JOIN natrib        atr   on mat.codatribut    = atr.codatribut
      LEFT  JOIN nclasea       clasa on clasa.codclasea   = art.clasa
      LEFT  JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
      LEFT  JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
      LEFT  JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
      LEFT  JOIN npart         prod  on obj.codproducator = prod.codpart &apos;||
      gSuplJoins||&apos;
    WHERE P.CodProdComp = &apos;||p_CodProdComp||&apos;
    UNION ALL
    SELECT
      obj.Denumire DenArt, NUM.Den_UM, rez.Cant, rez.Pret, rez.D1, rez.D2, rez.D3, NUM1.Den_UM, rez.CantUM1, &apos;&apos;&apos;&apos; denumire, rez.indexlocal,
      0 valmat, 0 valman, 0 valregie, g.den_gest, NULL Obs, &apos;&apos;Articol rezultat&apos;&apos; tip, P.OBS, null addim , null adddim_transp &apos;||gUserAlias||&apos;
    FROM ProdComp P
      INNER JOIN prodgest      pg    on pg.codprodcomp    = p.codprodcomp
      INNER JOIN prodrez       rez   on p.codprodcomp     = rez.codprodcomp and rez.codprodgest = pg.codprodgest
      INNER JOIN ngest         g     on pg.codgest        = g.codgest
      INNER JOIN nartobj       obj   on rez.codobiect     = obj.codobiect
      INNER JOIN nart          art   on obj.codarticol    = art.codarticol
      INNER JOIN num                 on art.um            = num.codum
      LEFT  JOIN PRODMAT       MAT   on MAT.CODPRODCOMP   = P.CODPRODCOMP - P.CODPRODCOMP
      LEFT  JOIN num           NUM1  on art.um1           = num1.codum
      LEFT  JOIN nclasea       clasa on clasa.codclasea   = art.clasa
      LEFT  JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
      LEFT  JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
      LEFT  JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
      LEFT  JOIN npart         prod  on obj.codproducator = prod.codpart &apos;||
      gSuplJoins||&apos;
    WHERE P.CodProdComp = &apos;||p_CodProdComp;

    sInsert1 :=
    &apos;INSERT INTO &apos;||TMPNAME||&apos; (
      SectieExec, Ordine, NrOp, Operatie, LocMunca, DenTarif, tarif, tu, valoare, dsv, bps, tpi, obs, detalii, tip &apos;||gUserFields||&apos;)
    SELECT
      X.SectieExec, X.Ordine, X.NrOp, X.Operatie, X.LocMunca, X.DenTarif, X.tarif, X.tu, X.valoare, X.dsv, X.bps, X.tpi, X.obs, X.detalii, X.tip &apos;||gUserAlias||&apos;
    FROM (
      SELECT
       pc.codprodcomp, G.Den_Gest SectieExec, pm.Ordine, pm.NrOp, op.denumire Operatie, lm.denumire LocMunca, t.denumire DenTarif, t.tarif, pm.tu, round((pm.tu * t.tarif)/60,5) valoare,
        pm.dsv, pm.bps, pm.tpi, pm.obs, pm.detalii,  &apos;&apos;Manopera&apos;&apos; tip, 0 codobiect, 0 codarticol
      FROM prodcomp pc
        INNER JOIN prodgest pg on pc.codprodcomp     = pg.codprodcomp
        INNER JOIN ngest    g  on nvl(pg.codgest, 0) = g.codgest
        INNER JOIN (select m.*, Rownum Ordine from prodman m order by m.nrop, m.detalii) pm on pm.codprodcomp = pc.codprodcomp and pm.codprodgest = pg.codprodgest
        INNER JOIN noper    op on pm.codop  = op.codop
        INNER JOIN locmunca lm on lm.codloc = pm.codloc
        INNER JOIN (
          SELECT T1.codtarif, T1.Tarif, t.denumire
          FROM TARIFEMAN1 T1 INNER JOIN tarifeman t on t1.codtarif = t.codtarif AND (pkg_globals.getanlucru * 12 + pkg_globals.GetLunaLUCRU) BETWEEN T1.ALSTART and T1.ALSTOP 
        ) T ON PM.CODTARIF = T.CODTARIF
      WHERE PC.CodProdComp = &apos;||p_CodProdComp||&apos;
    ) x
      INNER JOIN PRODCOMP      P     ON X.CODPRODCOMP     = P.CODPRODCOMP
      LEFT  JOIN PRODMAT       MAT   on MAT.CODPRODCOMP   = P.CODPRODCOMP - P.CODPRODCOMP
      LEFT  JOIN PRODREZ       REZ   on REZ.CODPRODCOMP   = P.CODPRODCOMP - P.CODPRODCOMP
      LEFT  JOIN nartobj       obj   on x.codobiect       = obj.codobiect
      LEFT  JOIN nart          art   on obj.codarticol    = art.codarticol
      LEFT  JOIN nclasea       clasa on clasa.codclasea   = art.clasa
      LEFT  JOIN nartimplicite imp   on x.codarticol      = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
      LEFT  JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
      LEFT  JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
      LEFT  JOIN npart         prod  on obj.codproducator = prod.codpart&apos;||gSuplJoins;

    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsert1, aListID, aListVer);
    PROCESSPARAMSRET;
  else
    if p_CodComanda1 &lt; 0 then
      sInsert :=
      &apos;INSERT INTO &apos;||TMPNAME||&apos; (
        DenArt, UM, Cant, D1, D2, D3,
        ValMat, ValMan, ValRegie, SectieExec, Tip, Stoc, Rezervat, AlteRez, Necesar, NecesarCalc &apos;||gUserFields||&apos;)
      SELECT
        x.DenArt, x.UM, x.Cant, x.D1, x.D2, x.D3,
        x.ValMat, x.ValMan, x.ValRegie, x.SectieExec, x.Tip, NVL(X.STOC,0), NVL(X.REZERVAT,0), NVL(X.REZALTE,0), NVL(X.NECESAR,0), NVL(X.NECESARCALC,0) &apos;||gUserAlias||&apos;
      from (
      select
        obj.codobiect, obj.Denumire DenArt, NUM.Den_UM UM, sum(cmd.Cant) Cant, nvl(CMD.D1,0) D1, nvl(CMD.D2,0) D2, nvl(CMD.D3,0) D3,
        sum(cmd.cant/pc.cant*mat.valmat) ValMat, sum(cmd.cant/pc.cant*mat.valman) ValMan, sum(cmd.cant/pc.cant*mat.valregie) ValRegie,
        g.den_gest SectieExec, &apos;&apos;Articol folosit&apos;&apos; Tip, NVL(CMD.STOC,0) STOC, SUM(NVL(CMD.REZERVAT,0)) REZERVAT, SUM(NVL(CMD.ALTEREZERVARI,0)) REZALTE, SUM(NVL(CMD.NECESAR,0)) NECESAR,
        NVL(CMD.STOC,0) - SUM(NVL(CMD.ALTEREZERVARI,0)) - SUM(NVL(CMD.NECESAR,0)) NECESARCALC
      FROM comanda1 cc1
        INNER JOIN COMANDA1       C1  ON CC1.CODCOMANDA  = C1.CODCOMANDA
        INNER JOIN COMANDA        C   ON C.CODCOMANDA    = C1.CODCOMANDA
        INNER JOIN TMP_CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1
        INNER JOIN prodmat        mat on CMD.CODPRODMAT  = MAT.CODMAT
        inner join prodcomp       pc  on mat.codprodcomp = pc.codprodcomp
        INNER JOIN ngest          g   on c.codgest       = g.codgest
        INNER JOIN nartobj        obj on cmd.codobiect   = obj.codobiect
        INNER JOIN nart           art on obj.codarticol  = art.codarticol
        INNER JOIN num                on art.um          = num.codum
      WHERE cmd.tip = 1 and cc1.CodCOMANDA1 = &apos;||-p_CodComanda1||&apos;
      group by obj.codobiect, obj.denumire, num.den_um, nvl(CMD.D1,0), nvl(CMD.D2,0), nvl(CMD.D3,0), g.den_gest, CMD.STOC
      ) x
      left join nartobj       obj   on obj.codobiect     = x.codobiect
      LEFT JOIN nart          art   on obj.codarticol    = art.codarticol
      LEFT JOIN nclasea       clasa on clasa.codclasea   = art.clasa
      LEFT JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
      LEFT JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
      LEFT JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
      LEFT JOIN npart         prod  on obj.codproducator = prod.codpart
      &apos;||gSuplJoins||&apos;
      UNION ALL
      SELECT
        x.DenArt, x.UM, x.Cant, x.D1, x.D2, x.D3,
        x.ValMat, x.ValMan, x.ValRegie, x.SectieExec, x.Tip, NVL(x.STOC,0) STOC, NVL(x.REZERVAT,0) REZERVAT, NVL(x.REZALTE,0) REZALTE, 0 NECESAR,
        0 NECESARCALC &apos;||gUserAlias||&apos;
      from (
      select
        c1.codreteta, obj.codobiect, obj.Denumire DenArt, NUM.Den_UM UM, sum(cmd.Cant) Cant, nvl(CMD.D1,0) D1, nvl(CMD.D2,0) D2, nvl(CMD.D3,0) D3,
        0 ValMat, 0 ValMan, 0 ValRegie,
        g.den_gest SectieExec, &apos;&apos;Articol rezultat&apos;&apos; Tip,
        sum(NVL(CMD.STOC,0)) STOC, sum(NVL(CMD.REZERVAT,0)) REZERVAT, sum(NVL(CMD.ALTEREZERVARI,0)) REZALTE
      FROM comanda1 cc1
        INNER JOIN COMANDA1       C1  ON Cc1.CODCOMANDA = C1.CODCOMANDA
        INNER JOIN COMANDA        C   ON C.CODCOMANDA   = C1.CODCOMANDA
        inner join TMP_CMDPRODMAT CMD on c1.codcomanda1 = cmd.codcomanda1
        INNER JOIN ngest          g   on c.codgest      = g.codgest
        INNER JOIN nartobj        obj on cmd.codobiect  = obj.codobiect
        INNER JOIN nart           art on obj.codarticol = art.codarticol
        INNER JOIN num on art.um = num.codum
      WHERE cmd.tip = 2 and Cc1.CodCOMANDA1 = &apos;||-p_CodComanda1||&apos;
      group by c1.codreteta, obj.codobiect, obj.denumire, num.den_um, nvl(CMD.D1,0), nvl(CMD.D2,0), nvl(CMD.D3,0), g.den_gest) x
      left join nartobj       obj   on obj.codobiect     = x.codobiect
      LEFT JOIN nart          art   on obj.codarticol    = art.codarticol
      LEFT JOIN nclasea       clasa on clasa.codclasea   = art.clasa
      LEFT JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
      LEFT JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
      LEFT JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
      LEFT JOIN npart         prod  on obj.codproducator = prod.codpart
      left join prodcomp      pc    on x.codreteta       = pc.codprodcomp
      &apos;||gSuplJoins;

      LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
    else
      sInsert :=
      &apos;INSERT INTO &apos;||TMPNAME||&apos; (
        DenArt, UM, Cant, Pret, D1, D2, D3, UM1, CantUM1, Atribut, IndexLocal,
        ValMat, ValMan, ValRegie, SectieExec, Obs, Tip, Stoc, Rezervat, AlteRez, Necesar, NecesarCalc &apos;||gUserFields||&apos;)
      SELECT
        obj.Denumire DenArt, NUM.Den_UM, cmd.Cant, cmd.Pret, MAT.D1, MAT.D2, MAT.D3, NUM1.Den_UM, Mat.CantUM1, atr.denumire, mat.indexlocal,
        cmd.cant/pc.cant*mat.valmat, cmd.cant/pc.cant*mat.valman, cmd.cant/pc.cant*mat.valregie, g.den_gest, mat.obs, &apos;&apos;Articol folosit&apos;&apos;,
        NVL(CMD.STOC,0) STOC, NVL(CMD.REZERVAT,0) REZERVAT, NVL(CMD.ALTEREZERVARI,0) REZALTE, NVL(CMD.NECESAR,0) NECESAR,
        NVL(CMD.STOC,0) - NVL(CMD.ALTEREZERVARI,0) - NVL(CMD.NECESAR,0) NECESARCALC &apos;||gUserAlias||&apos;
      FROM TMP_CMDPRODMAT CMD
        INNER JOIN prodmat       mat   on CMD.CODPRODMAT    = MAT.CODMAT
        inner join prodcomp      pc    on mat.codprodcomp   = pc.codprodcomp
        INNER JOIN COMANDA1      C1    ON CMD.CODCOMANDA1   = C1.CODCOMANDA1
        INNER JOIN COMANDA       C     ON C.CODCOMANDA      = C1.CODCOMANDA
        INNER JOIN ngest         g     on c.codgest         = g.codgest
        INNER JOIN nartobj       obj   on cmd.codobiect     = obj.codobiect
        INNER JOIN nart          art   on obj.codarticol    = art.codarticol
        INNER JOIN num                 on art.um            = num.codum
        LEFT  JOIN num           NUM1  on art.um1           = num1.codum
        LEFT  JOIN natrib        atr   on mat.codatribut    = atr.codatribut
        LEFT  JOIN nclasea       clasa on clasa.codclasea   = art.clasa
        LEFT  JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
        LEFT  JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
        LEFT  JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
        LEFT  JOIN npart         prod  on obj.codproducator = prod.codpart
      &apos;||gSuplJoins||&apos;
      WHERE cmd.tip = 1 and CMD.CodCOMANDA1 = &apos;||p_CodComanda1||&apos;
      UNION ALL
      SELECT
        obj.Denumire DenArt, NUM.Den_UM, cmd.Cant, cmd.Pret, rez.D1, rez.D2, rez.D3, NUM1.Den_UM, rez.CantUM1, &apos;&apos;&apos;&apos;, rez.indexlocal,
        0, 0, 0, g.den_gest, NULL Obs, &apos;&apos;Articol rezultat&apos;&apos;, NVL(CMD.STOC,0) STOC, NVL(CMD.REZERVAT,0) REZERVAT, NVL(CMD.ALTEREZERVARI,0) REZALTE, 0 NECESAR,
        0 &apos;||gUserAlias||&apos;
      FROM TMP_CMDPRODMAT CMD
        INNER JOIN prodrez       rez   on CMD.CODPRODMAT    = rez.CODrez
        inner join prodcomp      pc    on rez.codprodcomp   = pc.codprodcomp
        INNER JOIN COMANDA1      C1    ON CMD.CODCOMANDA1   = C1.CODCOMANDA1
        INNER JOIN COMANDA       C     ON C.CODCOMANDA      = C1.CODCOMANDA
        INNER JOIN ngest         g     on c.codgest         = g.codgest
        INNER JOIN nartobj       obj   on cmd.codobiect     = obj.codobiect
        INNER JOIN nart          art   on obj.codarticol    = art.codarticol
        INNER JOIN num                 on art.um            = num.codum
        LEFT  JOIN num           NUM1  on art.um1           = num1.codum
        LEFT  JOIN nclasea       clasa on clasa.codclasea   = art.clasa
        LEFT  JOIN nartimplicite imp   on art.codarticol    = imp.codarticol and imp.codsubunit  = pkg_globals.getsubunitate
        LEFT  JOIN nartobjimp    impo  on obj.codobiect     = impo.codobiect and impo.codsubunit = pkg_globals.getsubunitate
        LEFT  JOIN ioart         ioart on ioart.codioart    = case when coalesce(impo.contimplicit,0) = 0 then imp.contimplicit else coalesce(impo.contimplicit,0) end
        LEFT  JOIN npart         prod  on obj.codproducator = prod.codpart
      &apos;||gSuplJoins||&apos;
      WHERE cmd.tip = 2 and CMD.CodCOMANDA1 = &apos;||p_CodComanda1;

      LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
      PROCESSPARAMS;
    end if;
  end if;

  COMMIT;
END;

end pkg_list_base_prodcomp;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PRODESTPRJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2CE6FF75583E403E6A7FCBBB956EF97951B2E732</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PRODESTPRJ is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END; 

procedure RezProd(aCodProiectNod in number, aRez in out boolean) is
aStoc number(20,7);  
begin
  for v_rec in (select codproiectnod, codobiect, cant, tip
                from tmp_proiectnod_lans
                where nodoriginal = aCodProiectNod
               ) loop
    if v_rec.tip = 3 then
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        aRez := False;
        Exit;
      else
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    else
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        -- nu am stoc, merg pe productie
        RezProd(v_rec.CodProiectNod, aRez);
        if not aRez then
          Exit;
        else
          update tmp_proiectnod_lans set totalrealizat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      else
        -- am stoc
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    end if;
  end loop;
end;  

procedure Rezolva is
rez boolean;
aCod number(20);
aCant number(20,7);
i number(10);
begin
  i := 0;
  begin
    select codproiectnod, cant into aCod, aCant from tmp_proiectnod_lans where coalesce(nodoriginal,0) = 0;
  exception when others then aCod := 0;
  end;
  rez := True;
  while rez loop
    RezProd(aCod, rez);
    if rez then
      i:=i+1;
      update x set test = to_char(i);
      commit;
      update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + aCant, NecesarAut = coalesce(NecesarAut,0) + aCant where codproiectnod = aCod;
      for v_rec in (select codproiectnod, totalrezervat, totalrealizat, codobiect, cant, tip
                    from tmp_proiectnod_lans
                    where codproiectnod &lt;&gt; aCod
                    order by indexparinte) loop
        if v_rec.totalrezervat &gt; 0 then
          update tmp_stocreal set cant = cant - v_rec.totalrezervat where codobiect = v_rec.codobiect;
          update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_rec.totalrezervat where codproiectnod = v_rec.Codproiectnod;
          if v_rec.tip = 1 then
            update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrezervat where codproiectnod = v_rec.codproiectnod;
          end if;  
        end if;
        if v_rec.totalrealizat &gt; 0 then
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrealizat, NecesarAut = coalesce(NecesarAut,0) + v_rec.totalrealizat where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
    end if;
    update tmp_proiectnod_lans set totalrezervat = 0, totalrealizat = 0;
    update tmp_stocreal set cantum1 = 0;
  end loop;
end;

procedure EstimeazaNod(aCodProiectNod in number, aCant in number, aRez in out boolean) is
aStoc number(20,7);
aProd number(20,7);  
begin
  for v_rec in (select n.codproiectnod, n.codobiect, aCant*n.cant cant, n.cant cant_p, n.tip
                from tmp_proiectnod_lans n
                     inner join tmp_proiectnod_lans p on p.codproiectnod = n.nodoriginal
                where n.nodoriginal = aCodProiectNod
               ) loop
    if v_rec.tip = 3 then
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &lt; v_rec.cant then
        aRez := False;
        Exit;
      else
        update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
      end if;
    else
      begin
        select coalesce(cant,0) - coalesce(cantum1,0) into aStoc from tmp_stocreal where codobiect = v_rec.codobiect;
      exception when others then aStoc := 0;
      end;
      if aStoc &gt; 0 then
        -- am stoc
        if aStoc &gt;= v_rec.cant then
          -- am stoc suficient
          update tmp_proiectnod_lans set totalrezervat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
          update tmp_stocreal set cantum1 = coalesce(cantum1,0) + v_rec.cant where codobiect = v_rec.codobiect;
        else
          -- stoc insuficient, vad cat se poate aloca
          aProd := Trunc(aStoc/v_rec.cant_p);
          if aProd &gt; 0 then
            update tmp_proiectnod_lans set totalrezervat = aProd * v_rec.cant_p where codproiectnod = v_rec.codproiectnod;
            update tmp_stocreal set cantum1 = coalesce(cantum1,0) + aProd * v_rec.cant_p where codobiect = v_rec.codobiect;
            EstimeazaNod(v_rec.CodProiectNod, aCant - aProd, aRez);
            if not aRez then
              Exit;
            else
              update tmp_proiectnod_lans set totalrealizat = (aCant - aProd)*v_rec.cant_p where codproiectnod = v_rec.codproiectnod;  
            end if;
          else
            EstimeazaNod(v_rec.CodProiectNod, aCant, aRez);
            if not aRez then
              Exit;
            end if;
          end if;  
        end if;
      else
        EstimeazaNod(v_rec.CodProiectNod, aCant, aRez);
        if not aRez then
          Exit;
        else
          update tmp_proiectnod_lans set totalrealizat = v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      end if;
    end if;
  end loop;
end;

function Estimeaza return boolean is
vCod number(20);
vCodObiect number(20);
vRez boolean;
vCant number(20,7);
begin
  vRez := True;
  begin
    select codproiectnod, codobiect into vCod, vCodObiect from proiectnod where nodoriginal = 0 and codproiect = PKG_LIST_BASE_NAPROVIZ1.CodProiect;
  exception when others then vCod := 0;
  end;
  if vCod &gt; 0 then
    begin
      select cant into vCant from tmp_stocreal where codobiect = vCodObiect;
    exception when others then vCant := 0;
    end;
    vCant := PKG_LIST_BASE_NAPROVIZ1.Cant - vCant;
    if vCant &lt; 0 then vCant := 0; end if;
    if vCant &gt; 0 then
      EstimeazaNod(vCod, PKG_LIST_BASE_NAPROVIZ1.Cant, vRez);
    end if;  
    if vrez then
      update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + PKG_LIST_BASE_NAPROVIZ1.Cant, NecesarAut = coalesce(NecesarAut,0) + vCant where codproiectnod = vCod;
      if vCant = 0 then
        update tmp_proiectnod_lans set Necesar = PKG_LIST_BASE_NAPROVIZ1.Cant where codproiectnod = vCod;
        update tmp_stocreal set cant = cant - PKG_LIST_BASE_NAPROVIZ1.Cant where codobiect = vCodobiect;
      end if;
      for v_rec in (select codproiectnod, totalrezervat, totalrealizat, codobiect, cant, tip
                    from tmp_proiectnod_lans
                    where codproiectnod &lt;&gt; vCod
                    order by indexparinte) loop
        if v_rec.totalrezervat &gt; 0 then
          update tmp_stocreal set cant = cant - v_rec.totalrezervat where codobiect = v_rec.codobiect;
          update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_rec.totalrezervat where codproiectnod = v_rec.Codproiectnod;
          if v_rec.tip = 1 then
            update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrezervat where codproiectnod = v_rec.codproiectnod;
          end if;  
        end if;
        if v_rec.totalrealizat &gt; 0 then
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.totalrealizat, NecesarAut = coalesce(NecesarAut,0) + v_rec.totalrealizat where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
    end if;
    return vRez;
  else 
    return False;
  end if;
end;  

procedure testEstimeaza is
vCod number(20);
vRez boolean;
begin
  vRez := True;
  begin
    select codproiectnod into vCod from proiectnod where nodoriginal = 0 and codproiect = 3187;
  exception when others then vCod := 0;
  end;
  if vCod &gt; 0 then
    EstimeazaNod(vCod, 10, vRez);
  end if;
end;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert     VARCHAR2(1000);
sSelect     VARCHAR2(30000);
vSelStocReal VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;tmp_proiectnod_lans tmp, nartobj o&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  delete tmp_proiectnod_lans;
  insert into tmp_proiectnod_lans(
    codproiectnod,codproiect,cant,nodoriginal,pozitie,codreteta,
    tip,codobiect,indexparinte,codprodmat,nivel,ordine,decalaj,
    denumire,obs,identificator,datadocumentatie,arhiva,
    proiectant,necesar,codgest,denum,umsec,codextern,
    d1,d2,d3,relatieum1,paritated1,paritated2,paritated3,cantum1,
    totalrezervat, totalrealizat)
  SELECT
    PN.CODPROIECTNOD,PN.CODPROIECT,PN.CANT,coalesce(PN.NODORIGINAL,0),coalesce(PN.POZITIE,0),PN.CODRETETA,
    PN.TIP,OBJ.CodObiect,PN.IndexParinte,PN.CODPRODMAT,coalesce(PN.Nivel,0), PN.Ordine,PN.DECALAJ,
    OBJ.DENUMIRE,PC.OBS,PC.IDENTIFICATOR,PC.DATADOCUMENTATIE,PC.ARHIVA,
    PC.PROIECTANT,0,retete.CodGest,NUM.DEN_UM,NUM1.CodUM1,OBJ.CODEXTERN,
    PMAT.D1,PMAT.D2,PMAT.D3,NART.RELATIEUM1,NVL(NART.PARITATED1,0),NVL(NART.PARITATED2,0),NVL(NART.PARITATED3,0),nart.um1,
    0,0
  FROM PROIECTNOD PN
       INNER JOIN PROIECT P ON PN.Codproiect = P.CodProiect
       INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND nvl(PN0.NODORIGINAL, 0) = 0
       INNER JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
       INNER JOIN NART ON OBJ.CODARTICOL = NART.CodARTICOL
       INNER JOIN NUM ON NART.Um = NUM.CODUM
       INNER JOIN NUM1 ON NUM.CODUM = NUM1.CODUM and NVL(NUM1.SECUNDARA, 0) = 0
       LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
       LEFT  JOIN PRODMAT PMAT ON PMAT.CodMAT = PN.CodProdMAT
       LEFT  JOIN (select RET.CodProdComp, PG.CodGest
                   from prodcomp ret
                        left join prodgest pg on pg.codprodcomp = ret.codprodcomp and NVL(pg.indexlocal,1) = 1
                  ) retete on PN.Codreteta = retete.codprodcomp 
  WHERE pn.codproiect = PKG_LIST_BASE_NAPROVIZ1.CodProiect AND COALESCE(PMAT.TIP,0) &lt;&gt; 6;
  update tmp_proiectnod_lans set denumire = lpad(denumire,length(denumire)+nivel*4, &apos; &apos;);
  update tmp_proiectnod_lans set indexparinte = case when substr(indexparinte,1,1) = &apos;.&apos; then substr(indexparinte,2,length(indexparinte) - 1) else indexparinte end;
  update tmp_proiectnod_lans l set copii = (select sum(1) from tmp_proiectnod_lans c where c.nodoriginal = l.codproiectnod);
  vSelStocReal := &apos;
      SELECT NS.CODOBIECT, SUM(NS.REST) CANT
      FROM NIRSTOC NS
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON G.CodGest = N.GEST 
        INNER JOIN NARTOBJ O ON O.CodObiect = NS.CodObiect 
      WHERE NS.REST &gt; 0 AND COALESCE(O.INACTIV,0) = 0 AND NS.CODOBIECT IN (SELECT CODOBIECT FROM TMP_PROIECTNOD_LANS)&apos;;
  vSelStocReal := vSelStocReal || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = N.GEST) &apos;;

  if PKG_LIST_BASE_NAPROVIZ1.AllIOArt = 0 then
    vSelStocReal := vSelStocReal || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART ) &apos;;
  end if;
  vSelStocReal := vSelStocReal ||&apos;
      GROUP BY NS.CODOBIECT&apos;;

  DELETE TMP_STOCREAL;
  sSelect := &apos;insert into tmp_stocreal(codobiect,cant) &apos;||vSelStocReal;
  LIST_EXECUTE_IMMEDIATE(sselect, aListID, aListVer);
  
  update tmp_proiectnod_lans tmp 
  set 
    tip = case
            when coalesce(tmp.nodoriginal,0) = 0 then 0
            when (select count(*) from proiectnod p where p.nodoriginal = tmp.codproiectnod) &gt; 0 then 1
            else 3
          end;
  update tmp_proiectnod_lans tmp 
  set        
    stoc = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect); 
  
  if Estimeaza then
    update tmp_proiectnod_lans tmp 
    set        
      stocmin = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect);
  else
    update tmp_proiectnod_lans set totalrezervat = 0, totalrealizat = 0, necesar = 0, necesaraut = 0;
    update tmp_stocreal set cantum1 = 0;
    Rezolva;
    update tmp_proiectnod_lans tmp 
    set
      stocmin = (select s.cant from tmp_stocreal s where s.codobiect = tmp.codobiect);
  end if;    
  
  sInsert :=
   &apos;INSERT INTO &apos;||tmpName ||&apos;
     (
      Denumire,
      UM,
      Cant,
      CodExtern,
      CodIntern,
      Producator,
      Nivel,
      Pozitie,
      IndexParinte,
      Stoc,
      StocMin,
      Lansat,
      Necesar,
      NecesarAut,
      Copii &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
    select
      tmp.Denumire,
      tmp.denUM,
      tmp.Cant,
      o.CodExtern,
      o.CodIntern,
      prod.den_part,
      tmp.Nivel,
      tmp.Pozitie,
      tmp.IndexParinte,
      coalesce(tmp.stoc,0),
      coalesce(s.cant,0),
      tmp.Lansat,
      tmp.necesar,
      tmp.necesaraut,
      tmp.Copii &apos;||gUserAlias||&apos;
      from tmp_proiectnod_lans tmp
           inner join nartobj o on tmp.codobiect = o.codobiect
           left join npart prod on prod.codpart = o.codproducator
           left join tmp_stocreal s on s.codobiect = tmp.codobiect
        &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set codextern = lpad(codextern,length(codextern)+nivel*4, &apos;&apos; &apos;&apos;)&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set codintern = lpad(codintern,length(codintern)+nivel*4, &apos;&apos; &apos;&apos;)&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set stocs = case when stoc &gt; 0 then case when stoc = trunc(stoc) then to_char(stoc,&apos;&apos;fm9999999999&apos;&apos;) else to_char(stoc,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set stocmins = case when stocmin &gt; 0 then case when stocmin = trunc(stocmin) then to_char(stocmin,&apos;&apos;fm9999999999&apos;&apos;) else to_char(stocmin,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set lansats = case when lansat &gt; 0 then case when lansat = trunc(lansat) then to_char(lansat,&apos;&apos;fm9999999999&apos;&apos;) else to_char(lansat,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set necesars = case when necesar &gt; 0 then case when necesar = trunc(necesar) then to_char(necesar,&apos;&apos;fm9999999999&apos;&apos;) else to_char(necesar,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set necesarauts = case when necesaraut &gt; 0 then case when necesaraut = trunc(necesaraut) then to_char(necesaraut,&apos;&apos;fm9999999999&apos;&apos;) else to_char(necesaraut,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;update &apos;||tmpName||&apos; set cants = case when cant &gt; 0 then case when cant = trunc(cant) then to_char(cant,&apos;&apos;fm9999999999&apos;&apos;) else to_char(cant,&apos;&apos;fm9999999990D9999999&apos;&apos;) end end&apos;, aListID, aListVer);
  COMMIT;
END;

procedure test as
NivelMaxim number(5);
CanProd boolean;
vStoc number(20,7);
i number(5);  
begin
  begin
    select max(nivel) into NivelMaxim from tmp_proiectnod_lans;
  exception when others then NivelMaxim := -1;
  end;
  CanProd := True;
  while CanProd loop
    for i in reverse 0..NivelMaxim loop
      for v_rec in (select tip, codproiectnod, cant, codobiect
                    from tmp_proiectnod_lans
                    where nivel = i and tip in (0,1)
                    order by indexparinte
                   ) loop
        for v_mat in (
          select tip, codproiectnod, cant, necesar, codobiect
          from tmp_proiectnod_lans
          where nodoriginal = v_rec.codproiectnod and tip = 3
        ) loop 
          if v_mat.tip = 3 then
            --material, caut sa vad daca mai am stoc
            begin
              select cant into vStoc from tmp_stocreal where codobiect = v_mat.codobiect;
            exception when others then vStoc := 0;
            end;
            if vStoc &lt; v_mat.cant then
              CanProd := False;
              Exit;
            else
              update tmp_proiectnod_lans set necesar = coalesce(necesar,0) + v_mat.cant where codproiectnod = v_mat.Codproiectnod;
              update tmp_stocreal set cant = cant - v_mat.cant where codobiect = v_mat.codobiect;
            end if;
          end if;
        end loop;
        if not CanProd then
          Exit;
        else
          update tmp_proiectnod_lans set Lansat = coalesce(lansat,0) + v_rec.cant, NecesarAut = coalesce(NecesarAut,0) + v_rec.cant where codproiectnod = v_rec.codproiectnod;
        end if;
      end loop;
      if not CanProd then
        Exit;
      end if;             
    end loop;
  end loop;
end;  



end PKG_LIST_BASE_PRODESTPRJ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PRODETICHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2781050069D8268DB6CAA89F0E3DCFEF421E7AF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PRODETICHETE is

vCoduri varchar2(1000);
gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

procedure SETPARAMS(aCoduri in varchar2) IS
BEGIN
  vCoduri := aCoduri;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(5000);
sSelect    VARCHAR2(20000);
sCantField VARCHAR2(1000);
sCompare   VARCHAR2(2000);
BEGIN
  gSuplCols := &apos;nart art,nartobj obj,npart p,npers ag,nartcli acli,comanda ccli, intrari1 i1&apos;;

  if Nvl(pkg_categconst.GetValConstanta(&apos;LiniiEticheteProd&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru),1) = 1 then
    sCantField := &apos; 1, &apos;;
    sCompare   := &apos; x.cant &apos;;
  else if Nvl(pkg_categconst.GetValConstanta(&apos;LiniiEticheteProd&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru),1) = 2 then
    sCantField :=
    &apos; case
        when y.nrcolet = trunc(x.cant/decode(nvl(x.d1,0),0,1,nvl(x.d1,0))) + 1 then x.cant - trunc(x.cant/decode(nvl(x.d1,0),0,1,nvl(x.d1,0)))*decode(nvl(x.d1,0),0,1,nvl(x.d1,0))
        else decode(nvl(x.d1,0),0,1,nvl(x.d1,0))
      end, &apos;;
    sCompare   :=
    &apos; CASE
        WHEN TRUNC(x.cant/decode(nvl(x.d1,0),0,1,nvl(x.d1,0)))*decode(nvl(x.d1,0),0,1,nvl(x.d1,0)) = x.cant then trunc(x.cant/decode(nvl(x.d1,0),0,1,nvl(x.d1,0)))
        else trunc(x.cant/decode(nvl(x.d1,0),0,1,nvl(x.d1,0))) + 1
      end &apos;;
  else
    sCantField := &apos; x.cant, &apos;;
    sCompare   := &apos; 1 &apos;;
  end if;
  end if;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos; || TMPNAME || &apos;(
     Art,
     CodExtern,
     Responsabil,
     NrCmdInt,
     NrCmdCli,
     Client,
     Cant,
     CodExternCli,
     DenCli,
     D1,
     D2,
     D3,
     D1S,
     D2S,
     D3S&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    x.denumire,
    x.codextern,
    x.agent,
    x.nrcmdi,
    x.nrcmdcli,
    x.den_part,&apos;||chr(13)||
    sCantField||chr(13)||
    &apos;x.codlaclient,
    x.denlaclient,
    x.d1,
    x.d2,
    x.d3,
    x.d1s,
    x.d2s,
    x.d3s&apos;||gUserAlias ||&apos;
  from (
  select
    obj.codobiect,
    obj.codarticol,
    p.codpart,
    ag.codpers,
    acli.codartcli,
    obj.denumire,
    obj.codextern,
    ag.nume||&apos;&apos; &apos;&apos;||ag.prenume agent,
    ci.nrdoc nrcmdi,
    cli.nrdoc nrcmdcli,
    p.den_part,
    sum(ns.cantnir) cant,
    acli.CODLACLIENT,
    acli.denumire denlaclient,
    art.d1,
    art.d2,
    art.d3,
    ns.d1 d1s,
    ns.d2 d2s,
    ns.d3 d3s,
    cli.codcomanda,
    i1.codintr1
  FROM intrari i
       inner join intrari1 i1 on i.codintr = i1.codintr
       inner join nartobj obj on obj.codobiect = i1.codobiect
       inner join nart art on obj.codarticol = art.codarticol
       inner join nir on i.codintr = nir.codintr
       inner join nirstoc ns on ns.codnir = nir.codnir and ns.codintr1 = i1.codintr1
       left join npers ag on ag.codpers = i.agent
       left join intrprodlink l on l.codintr1 = i1.codintr1
       left join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
       left join comanda1 ci1 on ci1.codcomanda1 = prod.codcomanda1
       left join comanda ci on ci1.codcomanda = ci.codcomanda
       left join cmdlink cmdl on cmdl.codcomanda1 = ci1.codcomanda1
       left join comanda1 cli1 on cli1.codcomanda1 = cmdl.codliniecomanda
       left join comanda cli on cli1.codcomanda = cli.codcomanda
       left join npart p on p.codpart = cli.partener
       left join nartcli acli on acli.codobiect = obj.codobiect and acli.codpart = cli.partener
  WHERE i.codintr in (&apos;||vCoduri||&apos;)
  group by
    obj.codobiect,
    obj.codarticol,
    p.codpart,
    ag.codpers,
    acli.CODARTCLI,
    obj.denumire,
    obj.codextern,
    ag.nume,ag.prenume,
    ci.nrdoc,
    cli.nrdoc,
    p.den_part,
    acli.CODLACLIENT,
    acli.denumire,
    art.d1,
    art.d2,
    art.d3,
    ns.d1,
    ns.d2,
    ns.d3,
    cli.codcomanda,
    i1.codintr1
  ) x
    inner join (SELECT level NrColet FROM DUAL connect by level &lt;= 10000) Y ON Y.NrColet &lt;= &apos;||sCompare||&apos; and y.nrcolet &gt; 0
    left join intrari1 i1 on i1.codintr1 = x.codintr1
    left join comanda ccli on ccli.codcomanda = x.codcomanda
    left join nart art on art.codarticol = x.codarticol
    left join nartobj obj on obj.codobiect = x.codobiect
    left join npart p on p.codpart = x.codpart
    left join npers ag on ag.codpers = x.codpers
    left join nartcli acli on acli.codartcli = x.codartcli&apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_PRODETICHETE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PRODNETMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>626DC758EE7FF086051E233EEA8F975153CBC3DE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PRODNETMAN is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(32000);
BEGIN
  gSuplCols := &apos;prodnet pn, prodnet1 pn1, comanda1 c1, nartobj obj, comanda c, noper op, centrecost cc, prodcomp pc&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos; (OBSERVATII, SECTIE, EXPLICATII, VALMAN, DIFCANT, CANTREAL, PRET, CANT, NRDOC, DATADOC, DENUMIRE, OPERATIE, CENTRU, SUBUNITATEA &apos;||gUserFields||&apos;)
  SELECT PN.Obs, G.DEN_GEST, PN1.EXPLICATII, PN1.VALMAN, PN1.DIFCANT, PN1.CANTREAL, PN1.PRET, Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0), c.nrdoc, c.datadoc, obj.denumire, op.denumire, cc.simbol, S.DEN_SUBUNIT &apos;||gUserAlias||&apos;
  FROM PRODNET PN
    INNER JOIN NGEST G ON PN.CODGEST = G.CODGEST
    INNER JOIN PRODNET1 PN1 ON PN1.CODPRODNET = PN.CODPRODNET
    INNER join comanda1 c1 on pn1.coddoc1 = c1.codcomanda1
    INNER join prodcomp pc on c1.codreteta = pc.codprodcomp
    INNER join nartobj obj on c1.codobiect = obj.codobiect
    INNER join comanda c on c1.codcomanda = c.codcomanda
    INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = PN.SUBUNITATEA
    left join cmdprodman man on man.codcmdprodman = pn1.codcmdprodmat
    left join noper op on op.codop = man.codop
    left  join centrecost cc on nvl(PN1.codcentru,0) = cc.codcentru&apos;||
    gSuplJoins||&apos;
  WHERE PN.AN*12+PN.LUNA = PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU AND nvl(PN1.Tip,0) = 1&apos;;

  if PKG_GLOBALS.GETSUBUNITATE &gt; 1 then
    sInsert := sInsert||&apos; AND PN.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_prodnetman;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PRODNETMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>73BED352515D18EB29E1E143952E2FBBBBF1F3B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PRODNETMAT is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(32000);
BEGIN
  gSuplCols := &apos;prodnet pn, prodnet1 pn1, comanda1 c1, nartobj obj, comanda c, iesiri1 i1, nartobj objmat, centrecost cc,prodcomp pc&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos; (OBSERVATII, SECTIE, EXPLICATII, VALMAT, DIFCANT, CANTREAL, PRET, CANT, NRDOC, DATADOC, DENUMIRE, MATERIAL, CENTRU, SUBUNITATEA &apos;||gUserFields||&apos;)
  SELECT PN.Obs, G.DEN_GEST, PN1.EXPLICATII, PN1.VALMAT, PN1.DIFCANT, PN1.CANTREAL, PN1.PRET, Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0), c.nrdoc, c.datadoc, obj.denumire, objmat.denumire, cc.simbol, S.DEN_SUBUNIT &apos;||gUserAlias||&apos;
  FROM PRODNET PN
    INNER JOIN NGEST G ON PN.CODGEST = G.CODGEST
    INNER JOIN PRODNET1 PN1 ON PN1.CODPRODNET = PN.CODPRODNET
    INNER join comanda1 c1 on pn1.coddoc1 = c1.codcomanda1
    INNER join nartobj obj on c1.codobiect = obj.codobiect
    INNER join comanda c on c1.codcomanda = c.codcomanda
    INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = PN.SUBUNITATEA
    INNER join prodcomp pc on c1.codreteta = pc.codprodcomp
    left join iesiri1 i1 on pn1.codies1 = i1.codies1
    left join nartobj objmat on i1.codobiect = objmat.codobiect
    left  join centrecost cc on nvl(PN1.codcentru,0) = cc.codcentru&apos;||
    gSuplJoins||&apos;
  WHERE PN.AN*12+PN.LUNA = PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU AND nvl(PN1.Tip,0) = 0&apos;;

  if PKG_GLOBALS.GETSUBUNITATE &gt; 1 then
    sInsert := sInsert||&apos; AND PN.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE&apos;;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_prodnetmat;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B1E2BB8B58F65FA38D8578F395A86CB6E4BF969</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROFIT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GetValNC(aCodIntr1 IN NUMBER, aTip IN NUMBER) return number is
  vTipDoc   NUMBER;
  vCodIntr1 NUMBER;
  vDisc     NUMBER;
BEGIN
  vDisc := 0;
  BEGIN
    SELECT i.tipdoc INTO vTipDoc
    FROM intrari i
         inner join intrari1 i1 on i1.codintr = i.codintr
    WHERE i1.codintr1 = aCodIntr1;
  EXCEPTION WHEN OTHERS THEN
    vTipDoc := 0;
  END;

  IF vTipDoc = 2 THEN
    -- suntem de pe avize
    SELECT Coalesce(SUM(NC1.VALOARE),0) INTO vDisc
    FROM NOTECREDIT NC
      INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
      INNER JOIN intrari1 i1 on nc1.coddoc = i1.codintr1
      INNER JOIN intrari i on i1.codintr = i.codintr and nc1.tipdoc = i.tipdoc
      INNER JOIN intrlink l on l.codintr1 = i1.codintr1
    WHERE NC.TIPDOC = 59 AND NC1.TIP = aTip and l.codlinieaviz = aCodIntr1;
  ELSIF vTipDoc &gt; 0 THEN
    SELECT Coalesce(SUM(NC1.VALOARE),0) INTO vDisc
    FROM NOTECREDIT NC
      INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
      INNER JOIN intrari1 i1 on nc1.coddoc = i1.codintr1
      INNER JOIN intrari i on i1.codintr = i.codintr and nc1.tipdoc = i.tipdoc
    WHERE NC.TIPDOC = 59 AND NC1.TIP = aTip and i1.codintr1 = aCodIntr1;
  END IF;
  RETURN vDisc;
END;

FUNCTION GETTERIES(vCodIes IN NUMBER) RETURN NUMBER IS
aAVG NUMBER(10);
aData Date;
begin
  IF Coalesce(vCodIes, 0) = 0 THEN
    Return 0;
  ELSE
    select I.Datadoc into aData from iesiri i where i.codies = vCodIes;
    begin
      select round(Coalesce(AVG(O.Termen - I.DataDoc), 0), 0) into aAVG
      from iesiri i
           inner join general g on i.codies = g.coddoc and i.tipdoc = g.tipdoc
           inner join obligpif o on o.codgeneral = g.codgeneral
      where i.codies = vCodIes;
    exception when others THEN aAVG := 0;
    end;
    return aAVG;
  END IF;
end;

FUNCTION GETTERIN(vCodIntr IN NUMBER) RETURN NUMBER IS
aAVG NUMBER(10);
aData Date;
begin
  IF Coalesce(vCodIntr, 0) = 0 THEN
    Return 0;
  ELSE
    select I.Datadoc into aData from intrari i where i.codintr = vCodIntr;
    select round(Coalesce(AVG(O.Termen - I.DataDoc), 0), 0) into aAVG
    from intrari i
         inner join general g on i.codintr = g.coddoc and i.tipdoc = g.tipdoc
         inner join obligpif o on o.codgeneral = g.codgeneral
    where i.codintr = vCodIntr;
    return aAVG;
  END IF;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(20000);
  sWith        VARCHAR2(25000);
  sWithIni     VARCHAR2(25000);
  sLG1         VARCHAR2(25000);
  sLG2         VARCHAR2(25000);
  sLG2Ini      VARCHAR2(25000);
  sLG3         VARCHAR2(25000);
  sLG4         VARCHAR2(25000);
  sLGMon       VARCHAR2(25000);

  sSelect      VARCHAR2(30000);

  vToateGest   BOOLEAN         := PKG_LIST_SELECTIEPROFIT.ToateGest;
  vDupaData    BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DupaData;
  vDataIni     DATE            := PKG_LIST_SELECTIEPROFIT.DataIni;
  vDataFin     DATE            := PKG_LIST_SELECTIEPROFIT.DataFin;
  vLunaAnIni   INTEGER         := PKG_LIST_SELECTIEPROFIT.LunaAnIni;
  vLunaAnFin   INTEGER         := PKG_LIST_SELECTIEPROFIT.LunaAnFin;

  vFactInt     BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCINTERNE;
  vFactExt     BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCEXTERNE;
  vTransf      BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCTRANSF;
  vSubunit     BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCSUBUNIT;
  vFactAviz    BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCFACTAVIZ;
  vMon         BOOLEAN         := PKG_LIST_SELECTIEPROFIT.DOCMON;
  sCondI       VARCHAR2(10000) := &apos;&apos;;
  sCondT       VARCHAR2(10000) := &apos;&apos;;

  vCondGest    VARCHAR2(10000) := &apos;&apos;;
  vMax         INTEGER;
  i            INTEGER;

  sDiscContr0  VARCHAR2(10000) := &apos;&apos;;
  sDiscNC0     VARCHAR2(10000) := &apos;&apos;;
  sDiscContr   VARCHAR2(10000) := &apos;&apos;;
  sDiscNC      VARCHAR2(10000) := &apos;&apos;;
  sJoinCadou   VARCHAR2(10000) := &apos;&apos;;
BEGIN
  gSuplCols := &apos;TMP_LST_PROFIT LG, NARTOBJ OBJ, NUM1 UM1, PACHETE C, TRANSPORT T, NMONEDE MONREF, NPART PROD, NGEST GPROD, NART ART, NCLASEA CLASAA, NAGENDA SED, NLOCALIT LOC, NJUDET J, CENTRECOST CC, NCONT CIO&apos;||
               &apos;,NIRSTOC NS,LIVR1 L1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,   &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,   &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;AG_SED&apos;, &apos;AG_SED.CODPERS = SED.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NZONE&apos;,      &apos;Z&apos;,      &apos;Z.CODZONA = LOC.CODZONA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,      &apos;CVENIT&apos;, &apos;CVENIT.CODCONT = Coalesce(IO1.VENITURI,0)&apos;  , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,      &apos;CCHELT&apos;, &apos;CCHELT.CODCONT = Coalesce(IO1.CHELTUIELI,0)&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NGEST&apos;,      &apos;GLIVR&apos;,  &apos;LG.CODGEST = GLIVR.CODGEST&apos;            , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,      &apos;FURN&apos;,   &apos;FURN.CODPART = LG.FURN&apos;                , 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vMax := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;

  sDiscContr0 := &apos;,
        0 cdisct,  0 cdiscc,  0 cdiscv,  0 cCodArtCad,  0 cCantArtCad,
        0 cdisctF, 0 cdisccF, 0 cdiscvF, 0 cCodArtCadF, 0 cCantArtCadF&apos;;

  IF PKG_LIST_SELECTIEPROFIT.Extra1 THEN -- calcul disc cf. contracte
    PKG_CONTRACT.SIMULEAZA_DISCV(PKG_LIST_SELECTIEPROFIT.DataIni,PKG_LIST_SELECTIEPROFIT.DataFin,0);
    PKG_CONTRACT.SIMULEAZA_DISCC(PKG_LIST_SELECTIEPROFIT.DataIni,PKG_LIST_SELECTIEPROFIT.DataFin,0);
    PKG_CONTRACT.SIMULEAZA_CADOU(PKG_LIST_SELECTIEPROFIT.DataIni,PKG_LIST_SELECTIEPROFIT.DataFin,0);

    sDiscContr := &apos;,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN Coalesce(pkg_contract.CALCULEAZA_DISCT_LINIE(I.TipDoc, I1.CodIes1, I.DataDoc),0) * L1.Cant /I1.Cant
          ELSE 0
        END cdisct,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN (
            SELECT Coalesce(MAX(CASE WHEN T.DISCUNITAR &lt;&gt; 0 THEN l1.cant * t.discunitar ELSE l1.cant * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) * t.pjdisc / 100 END),0)
            FROM TMP_IESDISCC T
            WHERE T.PARTENER = I.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = I.CODLOCATIE) AND T.SUBUNITATEA = I.SUBUNITATEA AND T.CODOBIECT = I1.CODOBIECT AND T.DATASTART &lt;= I.DATADOC AND T.DATASTOP &gt;= I.DATADOC )
          ELSE 0
        END cdiscc,
        CASE
          WHEN I1.Cant  = 0 THEN 0
          WHEN II1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN (
            SELECT Coalesce(MAX(l1.cant*i1.cant/ii1.cant * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) *t.disc/t.baza),0)
            FROM TMP_IESDISCV T
            WHERE T.PARTENER = I.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = I.CODLOCATIE) AND T.SUBUNITATEA = I.SUBUNITATEA AND (T.CODOBIECT = 0 OR T.CODOBIECT = I1.CODOBIECT) AND T.DATASTART &lt;= I.DATADOC AND T.DATASTOP &gt;= I.DATADOC )
          ELSE 0
        END cdiscv,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_COD(2, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc)
          ELSE 0
        END cCodArtCad,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN pkg_contract.SIMCADOU_CANT(2, I1.CodObiect, I.Partener, I.CodLocatie, I.Subunitatea, I.DataDoc, L1.Cant)
          ELSE 0
        END cCantArtCad,
        CASE
          WHEN In1.Cant = 0 THEN 0
          WHEN Intr.operat = 1 AND Intr.TipDoc IN (1,2,9) THEN Coalesce(pkg_contract.CALCULEAZA_DISCT_LINIE(Intr.TipDoc, In1.CodIntr1, Intr.DataDoc),0) * L1.Cant/In1.Cant
          ELSE 0
        END cdisctF,
        CASE
          WHEN In1.Cant = 0 THEN 0
          WHEN Intr.TipDoc IN (1,9) THEN (
            SELECT Coalesce(MAX( CASE WHEN T.DISCUNITAR &lt;&gt; 0 THEN l1.cant * t.discunitar ELSE l1.cant * in1.pu * t.pjdisc / 100 END),0)
            FROM TMP_INTRDISCC T
            WHERE T.PARTENER = Intr.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = Intr.CODLOCATIE) AND T.SUBUNITATEA = Intr.SUBUNITATEA AND T.CODOBIECT = In1.CODOBIECT AND T.DATASTART &lt;= Intr.DATADOC AND T.DATASTOP &gt;= Intr.DATADOC )
          WHEN Intr.TipDoc = 2 THEN (
            SELECT
              SUM(
                l1.cant / in1.cant * (
                SELECT Coalesce(MAX(CASE WHEN T.DISCUNITAR &lt;&gt; 0 THEN f1.cant * t.discunitar ELSE f1.cant * f1.pu * t.pjdisc / 100 END),0)
                FROM TMP_INTRDISCC T
                WHERE T.PARTENER = F.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = F.CODLOCATIE) AND T.SUBUNITATEA = F.SUBUNITATEA AND T.CODOBIECT = F1.CODOBIECT AND T.DATASTART &lt;= F.DATADOC AND T.DATASTOP &gt;= F.DATADOC )
              )
            FROM INTRLINK IL
              INNER JOIN INTRARI1 F1 ON F1.Codintr1 = IL.CodIntr1
              INNER JOIN INTRARI F ON F.Codintr = F1.CodIntr
            WHERE IL.CODLINIEAVIZ = In1.CodIntr1)
          ELSE 0
        END cdisccF,
        CASE
          WHEN In1.Cant = 0 THEN 0
          WHEN Intr.TipDoc IN (1,9) THEN (
            SELECT Coalesce(MAX(l1.cant*in1.pu*t.disc/t.baza),0)
            FROM TMP_INTRDISCV T
            WHERE T.PARTENER = Intr.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = Intr.CODLOCATIE) AND T.SUBUNITATEA = Intr.SUBUNITATEA AND (T.CODOBIECT = 0 OR T.CODOBIECT = In1.CODOBIECT) AND T.DATASTART &lt;= Intr.DATADOC AND T.DATASTOP &gt;= Intr.DATADOC )
          WHEN Intr.TipDoc = 2 THEN (
            SELECT
              SUM(
                l1.cant / in1.cant * (
                SELECT Coalesce(MAX(f1.cant*f1.pu*t.disc/t.baza),0)
                FROM TMP_INTRDISCV T
                WHERE T.PARTENER = F.PARTENER AND (T.LOCATIE = 0 OR T.LOCATIE = F.CODLOCATIE) AND T.SUBUNITATEA = F.SUBUNITATEA AND (T.CODOBIECT = 0 OR T.CODOBIECT = F1.CODOBIECT) AND T.DATASTART &lt;= F.DATADOC AND T.DATASTOP &gt;= F.DATADOC )
              )
            FROM INTRLINK IL
              INNER JOIN INTRARI1 F1 ON F1.Codintr1 = IL.CodIntr1
              INNER JOIN INTRARI F ON F.Codintr = F1.CodIntr
            WHERE IL.CODLINIEAVIZ = In1.CodIntr1)
          ELSE 0
        END cdiscvf,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (1,9) THEN pkg_contract.SIMCADOU_COD(1, In1.CodObiect, Intr.Partener, Intr.CodLocatie, Intr.Subunitatea, Intr.DataDoc)
          ELSE 0
        END cCodArtCadF,
        CASE
          WHEN I1.Cant = 0 THEN 0
          WHEN I.TipDoc IN (1,9) THEN pkg_contract.SIMCADOU_CANT(1, In1.CodObiect, Intr.Partener, Intr.CodLocatie, Intr.Subunitatea, Intr.DataDoc, L1.Cant)
          ELSE 0
        END cCantArtCadF&apos;;
  ELSE
    sDiscContr := sDiscContr0;
  END IF;

  sDiscNC0 := &apos;,
        0 ncdisct,  0 ncdiscc,  0 ncdiscv,  NULL ncDenCad,  NULL ncUMCad,  NULL ncCantCad,  0 ncCantAsocCad,  0 ncZecCad,  0 ncPretCad,
        0 ncdisctf, 0 ncdisccf, 0 ncdiscvf, NULL ncDenCadF, NULL ncUMCadF, NULL ncCantCadF, 0 ncCantAsocCadF, 0 ncZecCadF, 0 ncPretCadF&apos;;


  IF PKG_LIST_SELECTIEPROFIT.Extra2 THEN -- calcul disc cf. note credit
    sJoinCadou :=&apos;
        LEFT JOIN (
          SELECT
            i1.codies1, o.denumire dencad, Sum(i1.cant) over (PARTITION BY ncc.codnccadouri) cantasoc,
            ncc.diferente/Coalesce(NULLIF(u1.paritate,0),1) cantcad, u1.den_um1 umcad, pm.lei * u1.paritate pretcad, Coalesce(u1.zecimale,7) zeccad
          FROM NCCADOURI NCC
            INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NCC.CODNCREDIT
            INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NCC.CODNCREDIT
            INNER JOIN IESIRI1 I1 ON NC1.CODDOC = I1.CodIes1 AND I1.CODOBIECT = NCC.CODOBIECTASOC
            INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND I.TIPDOC = NC1.TIPDOC
            LEFT JOIN NARTOBJ O ON O.CODOBIECT = NCC.CODOBIECT
            LEFT JOIN NUM1 U1 ON U1.CODUM1 = NCC.UMSEC
            LEFT JOIN PRETM PM ON PM.CODOBIECT = NCC.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = I.SUBUNITATEA
          WHERE NC.TIPDOC = 58
            AND NC1.TIPOPER = &apos;&apos;C&apos;&apos;
        ) Cad ON cad.codies1 = i1.codies1
        LEFT JOIN (
          SELECT
            i1.codintr1, o.denumire dencad, Sum(i1.cant) over (PARTITION BY ncc.codnccadouri) cantasoc,
            ncc.diferente/Coalesce(NULLIF(u1.paritate,0),1) cantcad, u1.den_um1 umcad, pm.lei * u1.paritate pretcad, Coalesce(u1.zecimale,7) zeccad
          FROM NCCADOURI NCC
            INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NCC.CODNCREDIT
            INNER JOIN NOTECREDIT1 NC1 ON NC1.CODNCREDIT = NCC.CODNCREDIT
            INNER JOIN INTRARI1 I1 ON NC1.CODDOC = I1.CODINTR1 AND I1.CODOBIECT = NCC.CODOBIECTASOC
            INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR AND I.TIPDOC = NC1.TIPDOC
            LEFT JOIN NARTOBJ O ON O.CODOBIECT = NCC.CODOBIECT
            LEFT JOIN NUM1 U1 ON U1.CODUM1 = NCC.UMSEC
            LEFT JOIN PRETM PM ON PM.CODOBIECT = NCC.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = I.SUBUNITATEA
          WHERE NC.TIPDOC = 59
            AND NC1.TIPOPER = &apos;&apos;C&apos;&apos;
        ) CadF ON cadf.codintr1 = in1.codintr1&apos;;

    sDiscNC := &apos;,
        CASE
          WHEN Coalesce(I1.Cant,0) = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN
            L1.Cant/I1.Cant*
            Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;T&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I.TipDoc ),0)
          ELSE 0
        END ncdisct,
        CASE
          WHEN Coalesce(I1.Cant,0) = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN
            L1.Cant/I1.Cant*
            Coalesce((SELECT SUM(NC1.VALOARE) FROM NOTECREDIT NC INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                WHERE NC.TIPDOC = 58 AND NC1.TIPOPER = &apos;&apos;C&apos;&apos; AND NC1.CODDOC = I1.CodIes1 AND NC1.TIPDOC = I.TipDoc ),0)
          ELSE 0
        END ncdiscc,
        CASE
          WHEN Coalesce(i1.cant,0) = 0 THEN 0
          WHEN Coalesce(i.valdoc,0) - Coalesce(i.tvadoc,0) = 0 THEN 0
          WHEN PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) = 0 THEN 0
          WHEN I.TipDoc IN (19,26) THEN
            pkg_notecredit.GetValDiscNCVol(i1.codies1, l1.cant, i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, i.valdoc, i.tvadoc)
          ELSE 0
        END ncdiscv,
        cad.dencad ncDenCad, cad.umcad ncUMCad, cad.cantcad ncCantCad, cad.cantasoc ncCantAsocCad, cad.zeccad ncZecCad, cad.pretcad ncPretCad,
        CASE
          WHEN Coalesce(In1.Cant,0) = 0 THEN 0
          WHEN Intr.TipDoc IN (1,2,9) THEN
            L1.Cant/In1.Cant*pkg_list_base_profit.getvalnc(ns.codintr1, 1)
          ELSE 0
        END ncdisctf,
        CASE
          WHEN Coalesce(In1.Cant,0) = 0 THEN 0
          WHEN Intr.TipDoc IN (1,2,9) THEN
            L1.Cant/In1.Cant*pkg_list_base_profit.getvalnc(ns.codintr1, 3)
          ELSE 0
        END ncdisccf,
        CASE
          WHEN Coalesce(in1.cant,0) = 0 THEN 0
          WHEN Coalesce(intr.valdoc,0) - Coalesce(intr.tvadoc,0) = 0 THEN 0
          WHEN Intr.TipDoc = 1 THEN
            (select sum(l1.cant/inf1.cant*
                    Coalesce((
                      SELECT SUM(NC1.VALOARE)
                      FROM NOTECREDIT NC
                           INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
                      WHERE ((NC.CODCONTRACT &gt; 0 AND Coalesce(C.TIPTARGETV,0) &lt; 2 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Intrf.CodIntr AND NC1.TIPDOC = Intrf.TipDoc)
                            OR (NC.CODCONTRACT &gt; 0 AND Coalesce(C.TIPTARGETV,0) = 2 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Inf1.CodIntr1 AND NC1.TIPDOC = Intrf.TipDoc)
                            OR (Coalesce(NC.CODCONTRACT,0) = 0 AND Coalesce(NC.VOLUMPEARTICOLE,0) = 0 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Intrf.CodIntr AND NC1.TIPDOC = Intrf.TipDoc)
                            OR (Coalesce(NC.CODCONTRACT,0) = 0 AND NC.VOLUMPEARTICOLE = 1 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Inf1.CodIntr1 AND NC1.TIPDOC = Intrf.TipDoc)
                            )
                       ),0))
             from INTRARI1 INF1
                  INNER JOIN INTRARI INTRF ON INF1.CodIntr  = INTRF.CodIntr
             where inf1.codintr1 = in1.codintr1
            )
          WHEN Intr.TipDoc IN (2,9) THEN
            l1.cant/ns.cantnir*(select sum(--l1.cant/Coalesce(INF1.CANT,in1.cant)*
                    Coalesce((
                      SELECT SUM(NC1.VALOARE)
                      FROM NOTECREDIT NC
                           INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
                      WHERE ((NC.CODCONTRACT &gt; 0 AND Coalesce(C.TIPTARGETV,0) &lt; 2 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Coalesce(INTRF.CODINTR,Intr.CodIntr) AND NC1.TIPDOC = Coalesce(INTRF.TIPDOC,Intr.TipDoc))
                            OR (NC.CODCONTRACT &gt; 0 AND Coalesce(C.TIPTARGETV,0) = 2 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Coalesce(INF1.CODINTR1,In1.CodIntr1) AND NC1.TIPDOC = Coalesce(INTRF.TIPDOC,Intr.TipDoc))
                            OR (Coalesce(NC.CODCONTRACT,0) = 0 AND Coalesce(NC.VOLUMPEARTICOLE,0) = 0 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Coalesce(INTRF.CODINTR,Intr.CodIntr) AND NC1.TIPDOC = Coalesce(INTRF.TIPDOC,Intr.TipDoc))
                            OR (Coalesce(NC.CODCONTRACT,0) = 0 AND NC.VOLUMPEARTICOLE = 1 AND NC.TIPDOC = 59 AND NC1.TIP = 2 AND NC1.CODDOC = Coalesce(INF1.CODINTR1,In1.CodIntr1) AND NC1.TIPDOC = Coalesce(INTRF.TIPDOC,Intr.TipDoc))
                            )
                       ),0))
             from INTRARI1 INF1
                  INNER JOIN INTRARI INTRF ON INF1.CodIntr  = INTRF.CodIntr
                  INNER JOIN INTRLINK LNK ON LNK.CODINTR1 = INF1.CODINTR1
             where LNK.CODLINIEAVIZ = IN1.CODINTR1
            )
          ELSE 0
        END ncdiscvf,
        cadf.dencad ncDenCadF, cadf.umcad ncUMCadF, cadf.cantcad ncCantCadF, cadf.cantasoc ncCantAsocCadF, cadf.zeccad ncZecCadF, cadf.pretcad ncPretCadF&apos;;
  ELSE
    sDiscNC := sDiscNC0;
  END IF;


  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, Articol, Cant, UM, PretFurn, PretAchiz, DiscIn, ProcDiscIn, PretClient, PretVanz, DiscVanz, ProcDiscVanz,
    Transport, PretRef, MonPretRef, Curs, UpLift, Client, ProfitUnitar, Doc, DocColet, DocTransport, Supliment, Subunitatea, PretMax, PretAchizC, PretInregC,
    Clasa, Agent, Producator, Judet, TerMedIes, TerMedIn, TipContLivr, ProcProfit, ADDIM, PROCTVA,
    DiscVol,   DiscTer,   DiscCant,   ArtCadou,   UMCadou,   PretCadou,
    DiscVolF,  DiscTerF,  DiscCantF,  ArtCadouF,  UMCadouF,  PretCadouF,
    CantCadou,
    CantCadouF,
    CDiscVol,  CDiscTer,  CDiscCant,  CArtCadou,  CUMCadou,  CCantCadou,  CPretCadou,
    CDiscVolF, CDiscTerF, CDiscCantF, CArtCadouF, CUMCadouF, CCantCadouF, CPretCadouF, CursDoc, CursRefAchiz, CursRefVanz,
    ContIOArt&apos;;


  FOR i in 1..Coalesce(vMax,0) loop
    sInsert := sInsert||&apos;, CLS&apos;||to_char(i);
  END LOOP;

  sInsert := sInsert||gUserFields||&apos;) &apos;;

  IF vDupaData THEN
    sCondI := &apos;
        AND L.DataLivr &apos;;
    IF vDataIni = vDataFin
    THEN sCondI := sCondI ||&apos;= To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
    ELSE sCondI := sCondI ||&apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    END IF;
    sCondT := sCondI;
  ELSE
    IF vDataIni = vDataFin
    THEN sCondI := &apos;= &apos;||vLunaAnIni||&apos; &apos;;
    ELSE sCondI := &apos;BETWEEN &apos;||vLunaAnIni||&apos; AND &apos;||vLunaAnFin||&apos; &apos;;
    END IF;
    sCondT := &apos;
        AND (T.luna+T.an*12) &apos;||sCondI;
    sCondI := &apos;
        AND (I.luna+I.an*12) &apos;||sCondI;
  END IF;
  sCondI := &apos; AND I.operat = 1 AND Coalesce(I.anulat, 0) = 0&apos;||sCondI||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
  sCondT := &apos; AND T.operat = 1 &apos;||                        sCondT||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;);

  IF NOT vToateGest THEN
    vCondGest := &apos;
        AND Coalesce(n.gest,lv.gest) IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;

  sWith := &apos;
  WITH &apos;;

  IF Coalesce(vMax,0) &gt; 0 THEN
    sWith := sWith||&apos;
    Clase AS (
      SELECT codclasea &apos;;
    IF Coalesce(vMax,0) &gt; 0 THEN
      for i in 1..Coalesce(vMax,0) loop
        sWith := sWith ||&apos;,Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE &apos;&apos;&apos;&apos; end) d&apos;||to_char(i);
      end loop;
    END IF;
    swith := sWith||&apos;
      FROM TMP_PROFIT_NCLASEA
      GROUP BY codclasea), &apos;;
  END IF;
  sWithIni := sWith;
  sWith := sWith||&apos;
    DISCFACTAVIZ as (
      SELECT SUM(Coalesce(F1.PRETORIG, 0)*Coalesce(NULLIF(F.Curs, 0), 1)*(1-Coalesce(F1.coefdiscmaj,1))) DISCOUNT, AV1.CODINTR1
      FROM INTRARI1 AV1
        INNER JOIN INTRARI AV ON AV1.CODINTR = AV.CODINTR
        INNER JOIN INTRLINK L ON L.CODLINIEAVIZ = AV1.CODINTR1
        INNER JOIN INTRARI1 F1 ON L.CODINTR1 = F1.CODINTR1
        INNER JOIN INTRARI F ON F1.CODINTR = F.CODINTR
      WHERE AV.TIPDOC = 2 AND AV.ANULAT = 0 AND AV.OPERAT = 1 AND F.TIPDOC = 9 AND F.ANULAT = 0 AND F.OPERAT = 1
      GROUP BY AV1.CODINTR1),&apos;;

  sLG1 := &apos;
    LG AS (
      SELECT
        L1.CODLIVR1, NSC.CODNIRSTOC, I.Curs, I.TipDoc, I1.CodObiect, P.Den_Part Client, I1.CoefDiscMaj, I1.PretOrig, IN1.ADDIM, I.Agent, I.Subunitatea, L1.cant / I1.Cant *Coalesce(I1.CostTransport, 0) Transport,
        I.DataDoc, I.NrDoc, I.PrefixDoc, I.An, I.Luna, I.CodIes CodDoc, I1.CodIes1 CodDoc1, L1.Cant, I1.Cant CantIes, In1.Cant CantIn, I1.UMSec,
        i1.pretorig  * Coalesce(NULLIF(I.Curs, 0), 1) PretClient, I1.PRETORIG * Coalesce(i1.coefdiscmaj,1) * Coalesce(NULLIF(I.Curs, 0), 1) PretVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * I1.PRETORIG * Coalesce(NULLIF(I.Curs, 0), 1) DiscVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * 100 ProcDiscVanz,
        CASE
          WHEN Coalesce(NS.CodNirStoc, 0) = 0 THEN Coalesce(LV.PretAchiz, 0)
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN
            CASE WHEN COALESCE(in1.pretorig,0) = 0 THEN Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ) ELSE Coalesce(in1.pretorig * Coalesce(NULLIF(intr.Curs, 0), 1) * Coalesce(in1.coefdiscmaj,1), Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ)) END
                + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1)
                - case when INTR.TIPDOC = 2 then Coalesce(discfactaviz.discount,0) else 0 end
                , 0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU, Coalesce(ns.pret - ns.adaos, LV.PRETACHIZ)) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretImport, Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ)) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretAchiz,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1), Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
        END PretFurn, NS.Furn,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC &lt;&gt; 2 THEN Coalesce(IN1.PRETORIG, 0)*Coalesce(NULLIF(intr.Curs, 0), 1)*(1-Coalesce(in1.coefdiscmaj,1))
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC = 2 THEN Coalesce(DISCFACTAVIZ.DISCOUNT,0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal,0)*(1-Coalesce(in1.coefdiscmaj,1))
        END ValDiscIntr,
        NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1) SUPLIMENT, Coalesce(NS.PUMaximal, 0) PretMax,
        Coalesce(nsc.pret - nsc.adaos, LV.PretAchiz) PretAchizC, Coalesce(nsc.pret, LV.PretInreg) PretInregC,
        PKG_LIST_BASE_PROFIT.GETTERIES(I.CodIes) TerMedIes,
        pkg_LIST_BASE_PROFIT.GETTERIN(INTR.CodIntr) TerMedIn,
        Coalesce(lv.codioart,nsc.codioart) codioart, I.CodLocatie CodAgenda, i1.codcentru, Coalesce(NULLIF(i.curs, 0), 1) cursdoc,
        case when INTR.AN*12+INTR.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI WHERE ROWNUM = 1) THEN NSC.CODGESTPROD ELSE INTR.CodGestProd END CODGESTPROD,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(intr.an,Coalesce(t.an, ies.an)), Coalesce(intr.luna,t.luna,ies.luna)),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             N.DataNIR) CursRefAchiz,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,I.An, I.Luna),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,I.An, I.Luna),
                                             L.DataLivr) CursRefVanz,G.CodGest&apos;||
        sDiscContr||
        sDiscNC||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1   I1 ON I1.CodIes      = I.CodIes
        INNER JOIN IESIRI1  II1 ON II1.CodIes1    = I1.CodIes1
        INNER JOIN LIVR       L ON I.CodIes       = L.CodIes
        INNER JOIN LIVR1     L1 ON I1.CodIes1     = L1.CodIes1 AND L1.CodLivr = L.CodLivr
        LEFT  JOIN NIRSTOC  NSC ON L1.codnirstoc  = NSC.CodNIRStoc
        LEFT  JOIN NIRSTOC1 nsr ON nsr.codnirstoc = nsc.codnirstoc
        LEFT  JOIN NIRSTOC   NS ON NS.CodNIRStoc  = nsr.codnirstocOrig
        LEFT  JOIN NIR        N ON N.CodNIR       = NSC.CodNIR
        LEFT  JOIN IESIRI   IES ON IES.CODIES     = N.CODIES
        LEFT  JOIN NPART      P ON I.Partener     = P.CodPart
        LEFT  JOIN LIVRVAL   LV ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIR       NO ON NO.CodNIR      = NS.CodNIR
        LEFT  JOIN NGEST      G ON G.CodGest      = Coalesce(N.Gest,LV.Gest)
        LEFT  JOIN DVI1    DVI1 ON DVI1.CodDVI1   = NS.CodDVI1
        LEFT  JOIN INTRARI1 IN1 ON IN1.CodIntr1   = Coalesce(DVI1.CodIntr1,NS.CodIntr1)
        LEFT  JOIN DISCFACTAVIZ ON DISCFACTAVIZ.CODINTR1 = IN1.CODINTR1
        LEFT  JOIN INTRARI INTR ON IN1.CodIntr    = INTR.CodIntr
        LEFT  JOIN TRANSF1   T1 ON T1.CodTransf1  = NS.CodTransf1
        LEFT  JOIN TRANSF     T ON T1.CodTransf   = T.CodTransf&apos;||
        sJoinCadou||&apos;
      WHERE I.TipDoc IN (19, 21, 22) &apos;||sCondI||&apos;
        AND L.codies IS NOT NULL AND L.operat = 1 AND Coalesce(L.anulat, 0) = 0
        AND I1.TipLinie = &apos;&apos;=&apos;&apos;&apos;||
        vCondGest||&apos;)&apos;;

  sLG2 := &apos;
    LG AS (
      SELECT
        L1.CODLIVR1, NSC.CODNIRSTOC, I.Curs, I.TipDoc, I1.CodObiect, P.Den_Part Client, I1.CoefDiscMaj, I1.PretOrig, IN1.ADDIM, I.Agent, I.Subunitatea, L1.Cant / I1.Cant * Coalesce(I1.CostTransport, 0) + L1.Cant / II1.Cant * Coalesce(II1.CostTransport, 0) Transport,
        I.DataDoc, I.NrDoc, I.PrefixDoc, I.An, I.Luna, I.CodIes CodDoc, I1.CodIes1 CodDoc1, round(L1.Cant*IL.Cant/II1.Cant, 7) Cant, I1.Cant CantIes, In1.Cant CantIn, I1.UMSec,
        i1.pretorig * Coalesce(NULLIF(I.Curs, 0), 1) PretClient, I1.PRETORIG * Coalesce(i1.coefdiscmaj,1) * Coalesce(NULLIF(I.Curs, 0), 1) PretVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * I1.PRETORIG * Coalesce(NULLIF(I.Curs, 0), 1) DiscVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * 100 ProcDiscVanz,
        CASE
          WHEN Coalesce(NS.CodNirStoc, 0) = 0 THEN Coalesce(LV.PretAchiz, 0)
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN CASE WHEN COALESCE(in1.pretorig,0) = 0 THEN Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ) ELSE Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1)*Coalesce(in1.coefdiscmaj,1), Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0) END
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretImport, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretAchiz,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1), Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
        END PretFurn, NS.Furn,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC &lt;&gt; 2 THEN Coalesce(IN1.PRETORIG, 0)*Coalesce(NULLIF(intr.Curs, 0), 1)*(1-Coalesce(in1.coefdiscmaj,1))
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC = 2 THEN Coalesce(DISCFACTAVIZ.DISCOUNT,0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal,0)*(1-Coalesce(in1.coefdiscmaj,1))
        END ValDiscIntr,
        NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1) SUPLIMENT, Coalesce(NS.PUMaximal, 0) PretMax,
        Coalesce(nsc.pret - nsc.adaos, LV.PretAchiz) PretAchizC, Coalesce(nsc.pret, LV.PretInreg) PretInregC,
        pkg_LIST_BASE_PROFIT.GETTERIES(I.CodIes) TerMedIes,
        pkg_LIST_BASE_PROFIT.GETTERIN(INTR.CodIntr) TerMedIn,
        Coalesce(lv.codioart,nsc.codioart) codioart, I.CodLocatie CodAgenda, i1.codcentru, Coalesce(NULLIF(i.curs, 0), 1) cursdoc,
        case when INTR.AN*12+INTR.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI WHERE ROWNUM = 1) THEN NSC.CODGESTPROD ELSE INTR.CodGestProd END CODGESTPROD,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(intr.an,Coalesce(t.an, ies.an)), Coalesce(intr.luna,t.luna,ies.luna)),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             N.DataNIR) CursRefAchiz,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,I.An, I.Luna),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,I.An, I.Luna),
                                             L.DataLivr) CursRefVanz,G.CodGest&apos;||
        sDiscContr||
        sDiscNC||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1   I1 ON I1.CodIes      = I.CodIes
        INNER JOIN IESLINK   IL ON I1.CodIes1     = IL.CodIes1
        INNER JOIN IESIRI1  II1 ON II1.CodIes1    = IL.CodLinieAviz
        INNER JOIN IESIRI    II ON II1.CodIes     = II.CodIes
        INNER JOIN LIVR       L ON II.CodIes      = L.CodIes
        INNER JOIN LIVR1     L1 ON II1.CodIes1    = L1.CodIes1 AND L1.CodLivr = L.CodLivr
        LEFT  JOIN LIVRVAL   LV ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIRSTOC  NSC ON L1.codnirstoc  = NSC.CodNIRStoc
        LEFT  JOIN NIR        N ON N.CodNIR       = NSC.CodNIR
        LEFT  JOIN NGEST      G ON G.CodGest      = Coalesce(N.Gest,LV.Gest)
        LEFT  JOIN NIRSTOC1 nsr ON nsr.codnirstoc = nsc.codnirstoc
        LEFT  JOIN NIRSTOC   NS ON NS.CodNIRStoc  = nsr.codnirstocOrig
        LEFT  JOIN NIR       NO ON NO.CodNIR      = NS.CodNIR
        LEFT  JOIN IESIRI   IES ON IES.CODIES     = NO.CODIES
        LEFT  JOIN NPART      P ON I.Partener     = P.CodPart
        LEFT  JOIN DVI1    DVI1 ON DVI1.CodDVI1   = NS.CodDVI1
        LEFT  JOIN INTRARI1 IN1 ON IN1.CodIntr1   = Coalesce(DVI1.CodIntr1,NS.CodIntr1)
        LEFT  JOIN INTRARI INTR ON IN1.CodIntr    = INTR.CodIntr
        LEFT  JOIN DISCFACTAVIZ ON DISCFACTAVIZ.CODINTR1 = IN1.CODINTR1
        LEFT  JOIN TRANSF1   T1 ON T1.CodTransf1  = NS.CodTransf1
        LEFT  JOIN TRANSF     T ON T1.CodTransf   = T.CodTransf&apos;||
        sJoinCadou||&apos;
      WHERE I.TipDoc = 26 &apos;||sCondI||&apos;
        AND L.codies IS NOT NULL AND L.operat = 1 AND Coalesce(L.anulat, 0) = 0
        AND I1.TipLinie = &apos;&apos;=&apos;&apos;&apos;||
        vCondGest||&apos;)&apos;;

  sLG2Ini := &apos;
    LG AS (
      SELECT
        0 CODLIVR1, 0 CODNIRSTOC, I.Curs, I.TipDoc, I1.CodObiect, P.Den_Part Client, I1.CoefDiscMaj, I1.PretOrig, 0 ADDIM, I.Agent, I.Subunitatea, Coalesce(I1.CostTransport, 0) Transport,
        I.DataDoc, I.NrDoc, I.PrefixDoc, I.An, I.Luna, I.CodIes CodDoc, I1.CodIes1 CodDoc1, IL.Cant Cant, I1.Cant CantIes, 0 CantIn, I1.UMSec,
        i1.pretorig * Coalesce(NULLIF(I.Curs, 0), 1) PretClient, I1.PRETORIG * Coalesce(i1.coefdiscmaj,1) * Coalesce(NULLIF(I.Curs, 0), 1) PretVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * I1.PRETORIG * Coalesce(NULLIF(I.Curs, 0), 1) DiscVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * 100 ProcDiscVanz,
        II1.PUCORELAT PretAchiz,
        II1.PUCORELAT PretFurn, 0 Furn,
        0 ValDiscIntr,
        0 SUPLIMENT, 0 PretMax,
        II1.PUCORELAT PretAchizC, II1.PU PretInregC,
        pkg_LIST_BASE_PROFIT.GETTERIES(I.CodIes) TerMedIes,
        NULL TerMedIn,
        II1.CODIOARTCUST codioart, I.CodLocatie CodAgenda, i1.codcentru, Coalesce(NULLIF(i.curs, 0), 1) cursdoc,
        0 CODGESTPROD,
        1 CursRefAchiz,
        1 CursRefVanz, 0 CodGest&apos;||
        sDiscContr0||
        sDiscNC0||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1   I1 ON I1.CodIes      = I.CodIes
        INNER JOIN IESLINK   IL ON I1.CodIes1     = IL.CodIes1
        INNER JOIN IESIRI1  II1 ON II1.CodIes1    = IL.CodLinieAviz
        INNER JOIN IESIRI    II ON II1.CodIes     = II.CodIes
        LEFT  JOIN NPART      P ON I.Partener     = P.CodPart
      WHERE I.TipDoc = 26 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND II.INITIALIZARI = 1 AND II.CUSTODIE = 1&apos;;

  IF vDupaData THEN
    sLG2Ini := sLG2Ini||&apos;
        AND I.DataDoc &apos;;
    IF vDataIni = vDataFin
    THEN sLG2Ini := sLG2Ini||&apos;= To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
    ELSE sLG2Ini := sLG2Ini||&apos;BETWEEN To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_Date(&apos;&apos;&apos;||To_Char(vDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    END IF;
  ELSE
    sLG2Ini := sLG2Ini||&apos;
        AND (I.LUNA+I.AN*12) &apos;;
    IF vDataIni = vDataFin
    THEN sLG2Ini := sLG2Ini||&apos;= &apos;||vLunaAnIni||&apos; &apos;;
    ELSE sLG2Ini := sLG2Ini||&apos;BETWEEN &apos;||vLunaAnIni||&apos; AND &apos;||vLunaAnFin||&apos; &apos;;
    END IF;
  END IF;
  sLG2Ini := sLG2Ini||&apos;
        AND I.operat = 1 AND Coalesce(I.anulat, 0) = 0&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND I1.TipLinie = &apos;&apos;=&apos;&apos;)&apos;;

  sLG3 := &apos;
    LG AS (
      SELECT
        L1.CODLIVR1, NSC.CODNIRSTOC, I.Curs, I.TipDoc, I1.CodObiect, S.Den_Subunit Client, I1.CoefDiscMaj, I1.PretOrig, IN1.ADDIM, I.Agent, I.Subunitatea,L1.Cant / I1.Cant * Coalesce(I1.CostTransport, 0) Transport,
        I.DataDoc,I.NrDoc, I.PrefixDoc, I.An, I.Luna, I.CodIes CodDoc, I1.CodIes1 CodDoc1, L1.Cant, I1.Cant CantIes, In1.Cant CantIn, I1.UMSec,
        i1.pretorig  * Coalesce(NULLIF(I.Curs, 0), 1) PretClient, I1.PRETORIG * Coalesce(i1.coefdiscmaj,1) * Coalesce(NULLIF(I.Curs, 0), 1) PretVanz,
        0 DiscVanz, 0 ProcDiscVanz,
        CASE
          WHEN Coalesce(NS.CodNirStoc, 0) = 0 THEN Coalesce(LV.PretAchiz, 0)
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN CASE WHEN COALESCE(in1.pretorig,0) = 0 THEN Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ) ELSE Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1)*Coalesce(in1.coefdiscmaj,1), Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0) END
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretImport, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretAchiz,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1) , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
        END PretFurn, NS.Furn,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC &lt;&gt; 2 THEN Coalesce(IN1.PRETORIG, 0)*Coalesce(NULLIF(intr.Curs, 0), 1)*(1-Coalesce(in1.coefdiscmaj,1))
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC = 2 THEN Coalesce(DISCFACTAVIZ.DISCOUNT,0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal,0)*(1-Coalesce(in1.coefdiscmaj,1))
        END ValDiscIntr,
        NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1) SUPLIMENT, Coalesce(NS.PUMaximal, 0) PretMax,
        Coalesce(nsc.pret - nsc.adaos, LV.PretAchiz) PretAchizC, Coalesce(nsc.pret, LV.PretInreg) PretInregC,
        null TerMedIes,
        pkg_LIST_BASE_PROFIT.GETTERIN(INTR.CodIntr) TerMedIn,
        Coalesce(lv.codioart,nsc.codioart) codioart, I.CodLocatie CodAgenda, i1.codcentru, Coalesce(NULLIF(i.curs, 0), 1) cursdoc,
        case when INTR.AN*12+INTR.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI WHERE ROWNUM = 1) THEN NSC.CODGESTPROD ELSE INTR.CodGestProd END CODGESTPROD,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(intr.an,Coalesce(t.an, ies.an)), Coalesce(intr.luna,t.luna,ies.luna)),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             N.DataNIR) CursRefAchiz,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,I.An, I.Luna),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,I.An, I.Luna),
                                             L.DataLivr) CursRefVanz,G.CodGest&apos;||
        sDiscContr0||
        sDiscNC0||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1   I1 ON I1.CodIes      = I.CodIes
        INNER JOIN NSUBUNIT   S ON I.CodSubunit   = S.CodSubunit
        INNER JOIN LIVR       L ON I.CodIes       = L.CodIes
        INNER JOIN LIVR1     L1 ON I1.CodIes1     = L1.CodIes1 AND L1.CodLivr = L.CodLivr
        LEFT  JOIN LIVRVAL   LV ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIRSTOC  NSC ON L1.codnirstoc  = NSC.CodNIRStoc
        LEFT  JOIN NIR        N ON N.CodNIR       = NSC.CodNIR
        LEFT  JOIN NGEST      G ON G.CodGest      = Coalesce(N.Gest,LV.Gest)
        LEFT  JOIN NIRSTOC1 nsr ON nsr.codnirstoc = nsc.codnirstoc
        LEFT  JOIN NIRSTOC   NS ON NS.CodNIRStoc  = nsr.codnirstocOrig
        LEFT  JOIN NIR       NO ON NO.CodNIR      = NS.CodNIR
        LEFT  JOIN IESIRI   IES ON IES.CODIES     = NO.CODIES
        LEFT  JOIN DVI1    DVI1 ON DVI1.CodDVI1   = NS.CodDVI1
        LEFT  JOIN INTRARI1 IN1 ON NS.CodIntr1    = Coalesce(DVI1.CodIntr1,IN1.CodIntr1)
        LEFT  JOIN DISCFACTAVIZ ON DISCFACTAVIZ.CODINTR1 = IN1.CODINTR1
        LEFT  JOIN INTRARI INTR ON IN1.CodIntr    = INTR.CodIntr
        LEFT  JOIN TRANSF1   T1 ON T1.CodTransf1  = NS.CodTransf1
        LEFT  JOIN TRANSF     T ON T1.CodTransf   = T.CodTransf
      WHERE I.TipDoc = 23 &apos;||sCondI||&apos;
        AND L.codies IS NOT NULL AND L.operat = 1 AND Coalesce(L.anulat, 0) = 0&apos;||
        vCondGest||&apos;)&apos;;

  sLG4 := &apos;
    LG AS (
      SELECT
        L1.CODLIVR1, NSC.CODNIRSTOC, 1 Curs, T.TipDoc, T1.CodObiect, G.Den_gest Client, 0 CoefDiscMaj, NS.Pret PretOrig, IN1.ADDIM, 0 Agent, T.Subunitatea, L1.Cant / T1.Cant * Coalesce(T1.CostTransport, 0) Transport,
        T.DataDoc, T.NrDoc, T.PrefixDoc, T.An, T.Luna, T.CodTransf CodDoc, T1.CodTransf1 CodDoc1, T1.Cant, T1.Cant CantIes, IN1.Cant CantIn, T1.UMSec,
        NS.Pret PretClient, NS.Pret PretVanz,
        0 DiscVanz, 0 ProcDiscVanz,
        CASE
          WHEN Coalesce(NS.CodNirStoc, 0) = 0 THEN Coalesce(LV.PretAchiz, 0)
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN CASE WHEN COALESCE(in1.pretorig,0) = 0 THEN Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ) ELSE Coalesce(in1.pretorig*Coalesce(NULLIF(intr.Curs, 0), 1)*Coalesce(in1.coefdiscmaj,1), Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0) END
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(TI1.PU, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretImport, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0))) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretAchiz,
        CASE
          WHEN Coalesce(LV.CodLivrVal, 0) &lt;&gt; 0 THEN Coalesce(LV.PretAchiz, 0)
          ELSE Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretFurn, NS.Furn,
        CASE
          WHEN Coalesce(LV.CodLivrVal, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC &lt;&gt; 2 THEN Coalesce(IN1.PRETORIG, 0)*Coalesce(NULLIF(intr.Curs, 0), 1)*(1-Coalesce(in1.coefdiscmaj,1))
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC = 2 THEN Coalesce(DISCFACTAVIZ.DISCOUNT,0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal,0)*(1-Coalesce(in1.coefdiscmaj,1))
        END ValDiscIntr,
        NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1) SUPLIMENT, Coalesce(NS.PUMaximal, 0) PretMax,
        Coalesce(nsc.pret - nsc.adaos, LV.PretAchiz) PretAchizC, Coalesce(nsc.pret, LV.PretInreg) PretInregC,
        null TerMedIes,
        pkg_LIST_BASE_PROFIT.GETTERIN(INTR.CodIntr) TerMedIn,
        Coalesce(lv.codioart,nsc.codioart) codioart, AG.CodAgenda, T1.codcentru, 1 cursdoc,
        case when INTR.AN*12+INTR.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI WHERE ROWNUM = 1) THEN NSC.CODGESTPROD ELSE INTR.CodGestProd END CODGESTPROD,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos; ,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             N.DataNIR) CursRefAchiz,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,T.An, T.Luna),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,T.An, T.Luna),
                                             L.DataLivr) CursRefVanz,G.CodGest&apos;||
        sDiscContr0||
        sDiscNC0||&apos;
      FROM TRANSF T
        INNER JOIN TRANSF1   T1 ON T1.CodTransf   = T.CodTransf
        INNER JOIN LIVR       L ON L.CodTransf    = T.CodTransf
        INNER JOIN LIVR1     L1 ON L1.CodIes1     = T1.CodTransf1 AND L1.CodLivr = L.CodLivr
        LEFT  JOIN LIVRVAL   LV ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIRSTOC  NSC ON L1.codnirstoc  = NSC.CodNIRStoc
        LEFT  JOIN NIR        N ON N.CodNIR       = NSC.CodNIR
        LEFT  JOIN NGEST      G ON G.CodGest      = Coalesce(N.Gest,LV.Gest)
        LEFT  JOIN NIRSTOC1 nsr ON nsr.codnirstoc = nsc.codnirstoc
        LEFT  JOIN NIRSTOC   NS ON NS.CodNIRStoc  = nsr.codnirstocOrig
        LEFT  JOIN NIR       NO ON NO.CodNIR      = NS.CodNIR
        LEFT  JOIN IESIRI   IES ON IES.CODIES     = NO.CODIES
        LEFT  JOIN DVI1    DVI1 ON DVI1.CodDVI1   = NS.CodDVI1
        LEFT  JOIN INTRARI1 IN1 ON IN1.CodIntr1   = Coalesce(DVI1.CodIntr1,NS.CodIntr1)
        LEFT  JOIN DISCFACTAVIZ ON DISCFACTAVIZ.CODINTR1 = IN1.CODINTR1
        LEFT  JOIN INTRARI INTR ON IN1.CodIntr    = INTR.CodIntr
        LEFT  JOIN TRANSF1  TI1 ON TI1.CodTransf1 = NS.CodTransf1
        LEFT  JOIN TRANSF    TI ON TI1.CodTransf  = TI.CodTransf
        LEFT  JOIN NAGENDA   AG ON AG.CodSubunit  = T.Subunitatea
      WHERE T.TipDoc = 12 &apos;||sCondT||&apos;
        AND L.codies IS NOT NULL AND L.operat = 1 AND Coalesce(L.anulat, 0) = 0 &apos;||
        vCondGest||&apos;)&apos;;

  sLGMon := &apos;
    LG AS (
      SELECT
        L1.CODLIVR1, NSC.CODNIRSTOC, I.Curs, I.TipDoc, I1.CodObiect, P.Den_Part Client, I1.CoefDiscMaj, I1.PretOrig - i1.tva/i1.cant pretorig, IN1.ADDIM, I.Agent, I.Subunitatea, L1.cant / I1.Cant *Coalesce(I1.CostTransport, 0) Transport,
        I.DataDoc, I.NrDoc, I.PrefixDoc, I.An, I.Luna, I.CodIes CodDoc, I1.CodIes1 CodDoc1, L1.Cant, I1.Cant CantIes, In1.Cant CantIn, I1.UMSec,
        i1.pretorig PretClient, (I1.PRETORIG * Coalesce(i1.coefdiscmaj,1) - i1.tva/i1.cant) PretVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * I1.PRETORIG DiscVanz,
        (1-Coalesce(i1.coefdiscmaj,1)) * 100 ProcDiscVanz,
        CASE
          WHEN Coalesce(NS.CodNirStoc, 0) = 0 THEN Coalesce(LV.PretAchiz, 0)
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN
            CASE WHEN COALESCE(in1.pretorig,0) = 0 THEN Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ) ELSE Coalesce(in1.pretorig * Coalesce(in1.coefdiscmaj,1), Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ)) END
                + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1)
                - case when INTR.TIPDOC = 2 then Coalesce(discfactaviz.discount,0) else 0 end
                , 0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU, Coalesce(ns.pret - ns.adaos, LV.PRETACHIZ)) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretImport, Coalesce(NS.PRET - NS.ADAOS, LV.PRETACHIZ)) + Coalesce(NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1), 0)
        END PretAchiz,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 THEN Coalesce(in1.pretorig, Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN Coalesce(T1.PU , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal , Coalesce(ns.pret - ns.adaos, Coalesce(LV.PretAchiz, 0)))
        END PretFurn, NS.Furn,
        CASE
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC &lt;&gt; 2 THEN Coalesce(IN1.PRETORIG, 0)*(1-Coalesce(in1.coefdiscmaj,1))
          WHEN Coalesce(NS.CodIntr1, 0) &lt;&gt; 0 AND INTR.TIPDOC = 2 THEN Coalesce(DISCFACTAVIZ.DISCOUNT,0)
          WHEN Coalesce(NS.CodTransf1, 0) &lt;&gt; 0 THEN 0
          WHEN Coalesce(NS.CodDVI1, 0) &lt;&gt; 0 THEN Coalesce(DVI1.PretOriginal,0)*(1-Coalesce(in1.coefdiscmaj,1))
        END ValDiscIntr,
        NS.SUPLIMENT/Coalesce(NULLIF(NS.CANTNIR, 0), 1) SUPLIMENT, Coalesce(NS.PUMaximal, 0) PretMax,
        Coalesce(nsc.pret - nsc.adaos, LV.PretAchiz) PretAchizC, Coalesce(nsc.pret, LV.PretInreg) PretInregC,
        PKG_LIST_BASE_PROFIT.GETTERIES(I.CodIes) TerMedIes,
        pkg_LIST_BASE_PROFIT.GETTERIN(INTR.CodIntr) TerMedIn,
        Coalesce(lv.codioart,nsc.codioart) codioart, I.CodLocatie CodAgenda, i1.codcentru, Coalesce(NULLIF(i.curs, 0), 1) cursdoc,
        case when INTR.AN*12+INTR.LUNA &lt; (SELECT ANINITIAL*12+LUNAINITIALA FROM FIRMALUNI WHERE ROWNUM = 1) THEN NSC.CODGESTPROD ELSE INTR.CodGestProd END CODGESTPROD,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(intr.an,Coalesce(t.an, ies.an)), Coalesce(intr.luna,t.luna,ies.luna)),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,Coalesce(intr.an,t.an, ies.an), Coalesce(intr.luna,t.luna,ies.luna)),
                                             N.DataNIR) CursRefAchiz,
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,I.An, I.Luna),
                                             pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,I.An, I.Luna),
                                             L.DataLivr) CursRefVanz,G.CodGest&apos;||
        sDiscContr0||
        sDiscNC0||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1   I1 ON I1.CodIes      = I.CodIes
        INNER JOIN LIVR       L ON I.CodIes       = L.CodIes
        INNER JOIN LIVR1     L1 ON I1.CodIes1     = L1.CodIes1 AND L1.CodLivr = L.CodLivr
        LEFT  JOIN NIRSTOC  NSC ON L1.codnirstoc  = NSC.CodNIRStoc
        LEFT  JOIN NIRSTOC1 nsr ON nsr.codnirstoc = nsc.codnirstoc
        LEFT  JOIN NIRSTOC   NS ON NS.CodNIRStoc  = nsr.codnirstocOrig
        LEFT  JOIN NIR        N ON N.CodNIR       = NS.CodNIR
        LEFT  JOIN IESIRI   IES ON IES.CODIES     = N.CODIES
        LEFT  JOIN NPART      P ON I.Partener     = P.CodPart
        LEFT  JOIN LIVRVAL   LV ON L1.CodLivr1    = LV.CodLivr1
        LEFT  JOIN NIR       NN ON NN.CodNIR      = NSC.CodNIR
        LEFT  JOIN NGEST      G ON G.CodGest      = Coalesce(NN.Gest,LV.Gest)
        LEFT  JOIN DVI1    DVI1 ON DVI1.CodDVI1   = NS.CodDVI1
        LEFT  JOIN INTRARI1 IN1 ON IN1.CodIntr1   = Coalesce(DVI1.CodIntr1,NS.CodIntr1)
        LEFT  JOIN DISCFACTAVIZ ON DISCFACTAVIZ.CODINTR1 = IN1.CODINTR1
        LEFT  JOIN INTRARI INTR ON IN1.CodIntr    = INTR.CodIntr
        LEFT  JOIN TRANSF1   T1 ON T1.CodTransf1  = NS.CodTransf1
        LEFT  JOIN TRANSF     T ON T1.CodTransf   = T.CodTransf&apos;||
        sJoinCadou||&apos;
      WHERE I.TipDoc = 16 &apos;||sCondI||&apos;
        AND L.codies IS NOT NULL AND L.operat = 1 AND Coalesce(L.anulat, 0) = 0 and Coalesce(i1.cant,0) &lt;&gt; 0
        AND I1.TipLinie = &apos;&apos;=&apos;&apos;&apos;||
        vCondGest||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    LG.CodDoc, LG.TipDoc, OBJ.Denumire, LG.Cant, UM1.Den_Um1, Coalesce(LG.PretFurn, 0), case when lg.coefdiscmaj = 0 then 0 else Coalesce(LG.PretAchiz, 0) end, Coalesce(LG.ValDiscIntr, 0) DiscIn,
    Coalesce(LG.ValDiscIntr, 0) / Coalesce(NULLIF(LG.PRETAchiz, 0), 1) * 100 ProcDiscIn,
    LG.PretClient, LG.PretVanz, LG.DiscVanz, LG.ProcDiscVanz, LG.Transport, Coalesce(NO1.PretReferinta, 0) PretRef, MONREF.Simbol MonPretRef,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(NO1.CodMoneda, pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos;,LG.An, LG.Luna), LG.datadoc ) Curs,
    Coalesce(NO1.UpLift, 0) UpLift, LG.Client,
    CASE
      WHEN LG.CANT = 0 THEN 0
      WHEN LG.TipDoc &lt;&gt; 12 THEN Coalesce((LG.pretorig * Coalesce(lg.coefdiscmaj,1) * Coalesce(LG.Curs, 1)) - LG.PretAchiz  - Coalesce(LG.Transport, 0) / LG.Cant, 0)
      ELSE Coalesce(LG.Pretorig - LG.PretAchiz  - Coalesce(LG.Transport, 0) / LG.Cant, 0)
    END ProfitUnitar,
    LG.PrefixDoc||&apos;&apos;-&apos;&apos;||LG.NrDoc||&apos;&apos;/&apos;&apos;||LG.DataDoc Doc,
    CASE
      WHEN Coalesce(C.CodPachete, 0) &gt; 0 THEN C.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(C.DataP, &apos;&apos;dd.mm.yyyy&apos;&apos;)
      ELSE null
    END DocColet,
    CASE
      WHEN Coalesce(T.CodTransport, 0) &gt; 0 THEN T.Indicativ||&apos;&apos;/&apos;&apos;||T.DataTransport
      ELSE null
    END DocTransport,
    Coalesce(LG.Supliment,0) Supliment, SUB.Den_Subunit, LG.PretMax, LG.PretAchizC, LG.PretInregC, CLASAA.Den_ClaseA,
    NP.Nume||&apos;&apos; &apos;&apos;||NP.Prenume, Coalesce(GPROD.Den_Gest, PROD.Den_Part) Producator, CASE WHEN NOT LG.TipDoc IN (12,23) THEN J.Den_Judet END Den_Judet,
    LG.TerMedIes, LG.TerMedIn, io.den_ioart,
    CASE
      WHEN LG.PretAchiz = 0 THEN 0
      WHEN LG.TipDoc &lt;&gt; 12 THEN Coalesce((LG.pretorig * Coalesce(lg.coefdiscmaj,1) * Coalesce(LG.Curs, 1)) - LG.PretAchiz  - Coalesce(LG.Transport, 0), 0)/Coalesce(NULLIF(LG.PRETAchiz, 0), 1) * 100
      ELSE Coalesce(LG.Pretorig - LG.PretAchiz  - Coalesce(LG.Transport, 0), 0)/Coalesce(NULLIF(LG.PRETAchiz, 0), 1)*100
    END ProcProfit,
    LG.ADDIM, NT1.PROCENT,
    lg.ncdiscv , lg.ncdisct , lg.ncdiscc , lg.ncdenCad,  lg.ncumCad,  lg.ncPretCad,
    lg.ncdiscvF, lg.ncdisctF, lg.ncdisccF, lg.ncdencadF, lg.ncumcadF, lg.ncpretcadF,
    CASE
      WHEN Coalesce(lg.ncCantAsocCad,0) = 0 THEN 0
      WHEN lg.cant = lg.ncCantAsocCad THEN lg.ncCantCad
      ELSE Round(lg.ncCantCad*lg.cant/lg.ncCantAsocCad,lg.ncZecCad)
    END,
    CASE
      WHEN Coalesce(lg.ncCantAsocCadF,0) = 0 THEN 0
      WHEN lg.cant = lg.ncCantAsocCadF THEN lg.ncCantCadF
      ELSE Round(lg.ncCantCadF*lg.cant/lg.ncCantAsocCadF,lg.ncZecCadF)
    END,
    lg.cdiscv , lg.cdisct , lg.cdiscc , cad.denumire,  ucad.den_um , lg.cCantArtCad , pcad.lei,
    lg.cdiscvF, lg.cdisctF, lg.cdisccF, cadF.denumire, ucadF.den_um, lg.cCantArtCadF, pcadF.lei, LG.CursDoc, LG.CursRefAchiz, LG.CursRefVanz, CIO.SIMBOL &apos;;

  FOR i in 1..Coalesce(vMax,0) loop
    sSelect := sSelect||&apos;, CLSC.D&apos;||to_char(i);
  END loop;

  sSelect := sSelect||gUserAlias||&apos;
  FROM LG
    LEFT JOIN NIRSTOC           NS ON NS.CODNIRSTOC     = LG.CODNIRSTOC
    LEFT JOIN LIVR1             L1 ON L1.CODLIVR1       = LG.CODLIVR1
    LEFT JOIN NARTOBJ          OBJ ON LG.Codobiect      = OBJ.CodObiect
    LEFT JOIN NART             ART ON OBJ.CodArticol    = ART.CodArticol
    LEFT JOIN NUM1             UM1 ON LG.UMSec          = UM1.Codum1
    LEFT JOIN IOART             IO ON IO.CODIOART       = LG.CODIOART
    LEFT JOIN NCLASEA       CLASAA ON ART.Clasa         = CLASAA.CodClaseA
    LEFT JOIN NPART           PROD ON OBJ.CodProducator = PROD.CodPart
    LEFT JOIN NGEST          GPROD ON GPROD.Codgest     = LG.CodGestProd
    LEFT JOIN PACHETE1          C1 ON LG.CodDoc         = C1.CodDoc AND LG.TipDoc = C1.Tipdoc
    LEFT JOIN PACHETE            C ON C1.CodPachete     = C.Codpachete
    LEFT JOIN TRANSPORT1        T1 ON LG.CodDoc         = T1.CodDoc AND LG.TipDoc = T1.Tipdoc
    LEFT JOIN TRANSPORT          T ON T1.CodTransport   = T.CodTransport
    LEFT JOIN NARTOBJ1         NO1 ON NO1.CodObiect     = LG.CodObiect   AND LG.An*12+LG.Luna BETWEEN NO1.ALStart AND NO1.ALStop
    LEFT JOIN NART1            NA1 ON NA1.CodArticol    = OBJ.CodArticol AND LG.An*12+LG.Luna BETWEEN NA1.ALStart AND NA1.ALStop
    LEFT JOIN NTVA1            NT1 ON NT1.CodTVA        = NA1.CodTVA     AND LG.An*12+LG.Luna BETWEEN NT1.ALStart AND NT1.ALStop
    LEFT JOIN IOART1           IO1 ON IO1.CODIOART      = LG.CODIOART    AND LG.An*12+LG.Luna BETWEEN IO1.ALStart AND IO1.ALStop
    LEFT JOIN NMONEDE       MONREF ON MONREF.CodMoneda  = Coalesce(NO1.CodMoneda, 0)
    LEFT JOIN NSUBUNIT         SUB ON LG.Subunitatea    = SUB.CodSubunit
    LEFT JOIN NPERS             NP ON LG.Agent          = NP.CodPers
    LEFT JOIN NAGENDA          SED ON SED.CodAgenda     = LG.CodAgenda
    LEFT JOIN NLOCALIT         LOC ON LOC.CodLocalit    = SED.CodLocalit
    LEFT JOIN NJUDET             J ON J.CodJudet        = LOC.CodJudet
    LEFT JOIN CENTRECOST        CC ON LG.CodCentru      = CC.CodCentru
    LEFT JOIN NARTOBJ          CAD ON CAD.CODOBIECT     = LG.cCodArtCad
    LEFT JOIN NART            ACAD ON ACAD.CODARTICOL   = CAD.CodArticol
    LEFT JOIN NUM             UCAD ON UCAD.CODUM        = ACAD.UM
    LEFT JOIN PRETM           PCAD ON PCAD.CODOBIECT    = LG.cCodArtCad AND PCAD.IMPLICIT = 1 AND PCAD.SUBUNITATEA = LG.Subunitatea
    LEFT JOIN NARTOBJ         CADF ON CADF.CODOBIECT    = LG.cCodArtCadF
    LEFT JOIN NART           ACADF ON ACADF.CODARTICOL  = CADF.CodArticol
    LEFT JOIN NUM            UCADF ON UCADF.CODUM       = ACADF.UM
    LEFT JOIN PRETM          PCADF ON PCADF.CODOBIECT   = LG.cCodArtCadF AND PCADF.IMPLICIT = 1 AND PCADF.SUBUNITATEA = LG.Subunitatea
    LEFT JOIN NCONT            CIO ON CIO.CODCONT       = IO1.CONT &apos;||
    gSuplJoins;

  IF Coalesce(vMax,0) &gt; 0 THEN
    sSelect := sSelect||&apos;
    LEFT  JOIN CLASE          CLSC ON CLSC.CodClasea    = ART.Clasa &apos;;
  END IF;

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NARTOBJ1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NART1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NTVA1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);
  PRC_AL_CHECK(&apos;IOART1&apos;);

  --PKG_GLOBALS.SetDebugMode(TRUE);

  IF vFactInt  THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sLG1||sSelect, aListID, aListVer);
  END IF;

  IF vFactAviz THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sLG2||sSelect, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsert||sWithIni||sLG2Ini||sSelect, aListID, aListVer);
  END IF;

  IF vSubunit  THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sLG3||sSelect, aListID, aListVer);
  END IF;
  IF vTransf   THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sLG4||sSelect, aListID, aListVer);
  END IF;

  IF vMon then
    LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sLGMon||sSelect, aListID, aListVer);
  end if;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_profit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROGLUNFAB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E016B5F9E38BB092940946308291B5108F118A0F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROGLUNFAB IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vCentralizare BOOLEAN;
  vNeoperate    BOOLEAN;
  vZiuaIni      VARCHAR2(10);
  vZiuaFin      VARCHAR2(10);
  vLunar        BOOLEAN;

PROCEDURE SETPARAMS(
  pCentralizare IN NUMBER DEFAULT 0,
  pNeoperate    IN NUMBER DEFAULT 0,
  pZiuaIni      IN VARCHAR2 DEFAULT NULL,
  pZiuaFin      IN VARCHAR2 DEFAULT NULL,
  pLunar        IN NUMBER DEFAULT 0,
  V_CODJOB1     IN NUMBER DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vCentralizare := Coalesce(pCentralizare, 0) = 1;
  vNeoperate    := Coalesce(pNeoperate,    0) = 1;
  vLunar        := Coalesce(pLunar,        0) = 1;
  vZiuaIni      := pZiuaIni;
  vZiuaFin      := pZiuaFin;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vZiuaIni,vZiuaFin,xLunaAnIni,xLunaAnFin);
  END IF;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vZiuaIni,vZiuaFin);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(5000);
  sWith     VARCHAR2(10000);
  sSelect   VARCHAR2(20000);
  sCondNeop varchar2(200);
BEGIN
  if not vCentralizare then
    gSuplCols := &apos;PRODCOMP PC, COMANDA C, COMANDA1 C1, NARTOBJ PRODUS, NARTOBJ COMPONENT, FORMATII FORMATII, num umcomponent&apos;;
  else
    gSuplCols := &apos;PRODCOMP PC, COMANDA C, COMANDA1 C1, NARTOBJ PRODUS, FORMATII FORMATII&apos;;
  end if;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTP&apos;, &apos;OEXTP.CODOBIECT = PRODUS.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRP&apos;, &apos;OATRP.CODOBIECT = PRODUS.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTC&apos;, &apos;OEXTC.CODOBIECT = COMPONENT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRC&apos;, &apos;OATRC.CODOBIECT = COMPONENT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;,    &apos;CCEXT&apos;, &apos;CCEXT.CODCOMANDA = COMCLI.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;,   &apos;CC1EXT&apos;,&apos;CC1EXT.CODCOMANDA1 = COMCLI.CODCOMANDA1&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  if not vNeoperate then
    sCondNeop := &apos; and c.operat = 1 &apos;;
  end if;

  if vLunar then
    delete tmp_comcli;
    sWith := &apos;insert into tmp_comcli(CODCOMANDA1,CARNETDOCCLI,NRDOCCLI,DATADOCCLI,SERIEDOCCLI,CLIENT,TERMENLIVR,COMCLOSED,COMCANCELED,CODCOMANDA,CODCOMANDA1C)&apos;||chr(13)||
    &apos;SELECT &apos;||chr(13)||
           &apos;  cli.CodCmdInt1 codcomanda1, &apos;||chr(13)||
           &apos;  doc.simbol CarnetDocCli, &apos;||chr(13)||
           &apos;  cc.NrDoc NrDocCli, &apos;||chr(13)||
           &apos;  cc.DataDoc DataDocCli, &apos;||chr(13)||
           &apos;  doc.serie SerieDocCli, &apos;||chr(13)||
           &apos;  P.den_part client, &apos;||chr(13)||
           &apos;  cc1.Termen TermenLivr, &apos;||chr(13)||
           &apos;  case when cc.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
           &apos;  case when cc.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
           &apos;  cc.codcomanda,CLI.CODCMDCLI1 &apos;||chr(13)||
           &apos;FROM &apos;||chr(13)||
           &apos;  (select &apos;||chr(13)||
           &apos;     ci1.codcomanda1 codcmdint1, &apos;||chr(13)||
           &apos;     cc1.codcomanda1 codcmdcli1 &apos;||chr(13)||
           &apos;   from &apos;||chr(13)||
           &apos;      comanda1 ci1 &apos;||chr(13)||
           &apos;      inner join comanda ci on ci1.codcomanda = ci.codcomanda &apos;||chr(13)||
           &apos;      inner join cmdlink l on l.codcomanda1 = ci1.codcomanda1 &apos;||chr(13)||
           &apos;      inner join comanda1 cc1 on l.codliniecomanda = cc1.codcomanda1 &apos;||chr(13)||
           &apos;      inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
           &apos;   where cc.tipdoc = 18 and ci.tipdoc = 53 &apos;||chr(13)||
           &apos;         and ci.an*12+ci.luna &lt;= Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
           PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CI&apos;,&apos;SUBUNITATEA&apos;)||
           &apos;   START WITH l.codcomanda1 = ci1.CodComanda1 &apos;||chr(13)||
           &apos;   CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1 ) cli &apos;||chr(13)||
           &apos;  inner join comanda1 cc1 on cli.codcmdcli1 = cc1.codcomanda1 &apos;||chr(13)||
           &apos;  inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
           &apos;  inner join npart p on cc.partener = p.codpart
              left join doccarnete doc on cc.carnetdoc = doc.codcarnet &apos;;
    LIST_EXECUTE_IMMEDIATE(sWith, aListID, aListVer);
    Commit;

   if not vCentralizare then
   sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc,
                                NAV_TipDoc,
                                CarnetDocProd,
                                NrDocProd,
                                DataDocProd,
                                SerieDocProd,
                                Articol,
                                Reteta,
                                TermenExec,
                                DenUM,
                                CantLansata,
                                PretLansat,
                                ValLansata,
                                CantRealiz,
                                CantRealizCur,
                                ValRealiz,
                                DifCant,
                                DifVal,
                                Client,
                                CarnetDocCli,
                                NrDocCli,
                                DataDocCli,
                                SerieDocCli,
                                Sectie,
                                TermenLivr,
                                Component,
                                CantComp,
                                UMComp,
                                Schimb,
                                Formatie,
                                GestImp,
                                Facturat,
                                FNrDoc,
                                FDataDoc,
                                ComClosed,
                                Subunitate,
                                CmdSubSerie,
                                CmdSubNrDoc,
                                CmdSubDataDoc,
                                Saptamana,
                                ComCanceled,
                                ComCliClosed,
                                ComCliCanceled,
                                ComCliOperata &apos;||gUserFields||&apos;)&apos;;
   sWith := &apos;WITH &apos;;
   sWith := sWith||&apos;ComProd as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  objc.denumire component, &apos;||chr(13)||
   &apos;  objc.codobiect codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  matc.cant CantComp, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join cmdprodmat matc on c1.codcomanda1 = matc.codcomanda1 and matc.tip &gt; 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join nartobj    objc on matc.codobiect = objc.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;  left  join prodcomp    ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;where c.an*12+c.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||
   /*&apos;union all &apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  objc.denumire component, &apos;||chr(13)||
   &apos;  objc.codobiect codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  matc.cant CantComp, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join cmdprodmat matc on c1.codcomanda1 = matc.codcomanda1 and matc.tip &gt; 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join nartobj    objc on matc.codobiect = objc.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  inner  join prodcomp   ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 1 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restcons on restcons.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 0 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restpred on restpred.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codies1) Nr, i1.codcmdint1 &apos;||chr(13)||
   &apos;               from iesiri1 i1 &apos;||chr(13)||
   &apos;                    inner join iesiri i on i1.codies = i.codies &apos;||chr(13)||
   &apos;               where i.tipdoc = 24 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru group by i1.codcmdint1) BCLC on BCLC.CodCmdInt1 = C1.CodComanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codintr1) Nr, l.codliniecomanda &apos;||chr(13)||
   &apos;               from intrari1 i1 &apos;||chr(13)||
   &apos;                    inner join intrari i on i1.codintr = i.codintr &apos;||chr(13)||
   &apos;                    inner join intrprodlink l on i1.codintr1 = l.codintr1 &apos;||chr(13)||
   &apos;               where i.tipdoc = 7 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;               group by l.codliniecomanda ) NPLC on NPLC.CodLinieComanda = mat.CodCmdProdMat &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc = doc.codcarnet &apos;||chr(13)||
   &apos;where c.an*12+c.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru and  &apos;||chr(13)||
   &apos; (restcons.rest &gt; 0 or restpred.rest &gt; 0 or (restcons.rest + restpred.rest = 0 and (BCLC.Nr&gt;0 or NPLC.Nr&gt;0)))&apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||*/
   &apos;), &apos;;
   sWith := sWith||&apos;ComSub as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocSub, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocSub, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocSub, &apos;||chr(13)||
   &apos;  doc.serie SerieDocSub, &apos;||chr(13)||
   &apos;  s.den_subunit subunitate, &apos;||chr(13)||
   &apos;  c1.Termen TermenLivr &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join nsubunit     s on c.subunitatea   = s.codsubunit &apos;||chr(13)||
   &apos;  inner join comanda1    c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  left  join doccarnete doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;where c.tipdoc = 44 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;)||&apos;), &apos;;
   sWith := sWith||&apos;CantRealLC as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  pl.codliniecomanda &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  intrari i &apos;||chr(13)||
   &apos;  inner join intrari1    i1 on i.codintr = i1.codintr &apos;||chr(13)||
   &apos;  inner join intrprodlink PL on i1.codintr1 = PL.codintr1 &apos;||chr(13)||
   &apos;where i.tipdoc = 7 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by pl.codliniecomanda ), &apos;;
   sWith := sWith||&apos;facturat as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ), &apos;;
   sWith := sWith||&apos;DL as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join cmdlivrlink LL on L.codliniecomanda = LL.codcomanda1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on LL.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ) &apos;;
   sSelect := &apos;
   select ComProd.CodComanda, &apos;||chr(13)||
          &apos;ComProd.TipDoc, &apos;||chr(13)||
          &apos;ComProd.CarnetDocProd, &apos;||chr(13)||
          &apos;ComProd.NrDocProd, &apos;||chr(13)||
          &apos;ComProd.DataDocProd, &apos;||chr(13)||
          &apos;ComProd.SerieDocProd, &apos;||chr(13)||
          &apos;ComProd.Produs, &apos;||chr(13)||
          &apos;ComProd.Reteta, &apos;||chr(13)||
          &apos;ComProd.TermenExec, &apos;||chr(13)||
          &apos;ComProd.DenUM, &apos;||chr(13)||
          &apos;ComProd.CantLansata, &apos;||chr(13)||
          &apos;ComProd.PretLansat, &apos;||chr(13)||
          &apos;ComProd.ValLansata, &apos;||chr(13)||
          &apos;ComProd.CantRealiz, &apos;||chr(13)||
          &apos;CantRealLC.Cant, &apos;||chr(13)||
          &apos;ComProd.ValRealiz, &apos;||chr(13)||
          &apos;ComProd.DifCant, &apos;||chr(13)||
          &apos;ComProd.DifVal, &apos;||chr(13)||
          &apos;ComCli.Client, &apos;||chr(13)||
          &apos;ComCli.CarnetDocCli, &apos;||chr(13)||
          &apos;ComCli.NrDocCli, &apos;||chr(13)||
          &apos;ComCli.DataDocCli, &apos;||chr(13)||
          &apos;ComCli.SerieDocCli, &apos;||chr(13)||
          &apos;ComProd.Sectie, &apos;||chr(13)||
          &apos;ComCli.TermenLivr, &apos;||chr(13)||
          &apos;ComProd.Component, &apos;||chr(13)||
          &apos;ComProd.CantComp, &apos;||chr(13)||
          &apos;umcomponent.den_um, &apos;||chr(13)||
          &apos;ComProd.Schimb, &apos;||chr(13)||
          &apos;formatii.den_formatie, &apos;||chr(13)||
          &apos;gimp.den_gest, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.cant else facturat.cant end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.nrdoc else facturat.nrdoc end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.datadoc else facturat.datadoc end, &apos;||chr(13)||
          &apos;ComProd.ComClosed, &apos;||chr(13)||
          &apos;ComSub.Subunitate, &apos;||chr(13)||
          &apos;ComSub.SerieDocSub, &apos;||chr(13)||
          &apos;ComSub.NrDocSub, &apos;||chr(13)||
          &apos;ComSub.DataDocSub, &apos;||chr(13)||
          &apos;ComProd.Saptamana, &apos;||chr(13)||
          &apos;ComProd.ComCanceled, &apos;||chr(13)||
          &apos;ComCli.ComClosed, &apos;||chr(13)||
          &apos;ComCli.ComCanceled, &apos;||chr(13)||
          &apos;comprod.comoperata &apos;||gUserAlias||&apos;
    from ComProd
      inner join nartobj produs on produs.codobiect = comprod.codprodus
      inner join nartobj component on component.codobiect = comprod.codcomponent
      inner join nart artc on component.codarticol = artc.codarticol
      inner join num umcomponent on artc.um = umcomponent.codum
      inner join comanda c on c.codcomanda = ComProd.codcomanda
      inner join comanda1 c1 on c1.codcomanda1 = ComProd.codcomanda1
      LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
      left join formatii on nvl(comprod.codformatie, 0) = formatii.codformatie
      left join tmp_comcli comcli on comprod.codcomanda1 = comcli.codcomanda1
      left join cmdlink on cmdlink.codcomanda1 = comprod.codcomanda1
      left join comsub on cmdlink.codliniecomanda = comsub.codcomanda1
      left join facturat on facturat.codcomanda1 = comcli.codcomanda1c
      left join DL on DL.codcomanda1 = comcli.codcomanda1
      left join nartimplicite artcimp on artc.codarticol = artcimp.codarticol AND artcimp.codsubunit = pkg_globals.getsubunitate
      left join ngest gimp on artcimp.gestimplicita = gimp.codgest
      left join cantrealLC on cantreallc.codliniecomanda = comprod.codcmdprodmat &apos;||gSuplJoins;
   else
     sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc,
                                NAV_TipDoc,
                                CarnetDocProd,
                                NrDocProd,
                                DataDocProd,
                                SerieDocProd,
                                Articol,
                                Reteta,
                                TermenExec,
                                DenUM,
                                CantLansata,
                                PretLansat,
                                ValLansata,
                                CantRealiz,
                                CantRealizCur,
                                ValRealiz,
                                DifCant,
                                DifVal,
                                Client,
                                CarnetDocCli,
                                NrDocCli,
                                DataDocCli,
                                SerieDocCli,
                                Sectie,
                                TermenLivr,
                                Schimb,
                                Formatie,
                                Facturat,
                                FNrDoc,
                                FDataDoc,
                                ComClosed,
                                Subunitate,
                                CmdSubSerie,
                                CmdSubNrDoc,
                                CmdSubDataDoc,
                                Saptamana,
                                ComCanceled,
                                ComCliClosed,
                                ComCliCanceled,
                                ComCliOperata &apos;||gUserFields||&apos;)&apos;;
   sWith := &apos;WITH &apos;;
   sWith := sWith||&apos;ComProd as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  0 codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;  left  join prodcomp    ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;where c.an*12+c.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||
   /*&apos;union all &apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  0 codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  inner  join prodcomp   ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 1 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restcons on restcons.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 0 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restpred on restpred.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codies1) Nr, i1.codcmdint1 &apos;||chr(13)||
   &apos;               from iesiri1 i1 &apos;||chr(13)||
   &apos;                    inner join iesiri i on i1.codies = i.codies &apos;||chr(13)||
   &apos;               where i.tipdoc = 24 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru group by i1.codcmdint1) BCLC on BCLC.CodCmdInt1 = C1.CodComanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codintr1) Nr, l.codliniecomanda &apos;||chr(13)||
   &apos;               from intrari1 i1 &apos;||chr(13)||
   &apos;                    inner join intrari i on i1.codintr = i.codintr &apos;||chr(13)||
   &apos;                    inner join intrprodlink l on i1.codintr1 = l.codintr1 &apos;||chr(13)||
   &apos;               where i.tipdoc = 7 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;               group by l.codliniecomanda ) NPLC on NPLC.CodLinieComanda = mat.CodCmdProdMat &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc = doc.codcarnet &apos;||chr(13)||
   &apos;where c.an*12+c.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru and  &apos;||chr(13)||
   &apos; (restcons.rest &gt; 0 or restpred.rest &gt; 0 or (restcons.rest + restpred.rest = 0 and (BCLC.Nr&gt;0 or NPLC.Nr&gt;0)))&apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||*/
   &apos;), &apos;;
   sWith := sWith||&apos;ComSub as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocSub, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocSub, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocSub, &apos;||chr(13)||
   &apos;  doc.serie SerieDocSub, &apos;||chr(13)||
   &apos;  s.den_subunit subunitate, &apos;||chr(13)||
   &apos;  c1.Termen TermenLivr &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join nsubunit     s on c.subunitatea   = s.codsubunit &apos;||chr(13)||
   &apos;  inner join comanda1    c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  left  join doccarnete doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;where c.tipdoc = 44 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;)||&apos;), &apos;;
   sWith := sWith||&apos;CantRealLC as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  pl.codliniecomanda &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  intrari i &apos;||chr(13)||
   &apos;  inner join intrari1    i1 on i.codintr = i1.codintr &apos;||chr(13)||
   &apos;  inner join intrprodlink PL on i1.codintr1 = PL.codintr1 &apos;||chr(13)||
   &apos;where i.tipdoc = 7 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by pl.codliniecomanda ), &apos;;
   sWith := sWith||&apos;facturat as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ), &apos;;
   sWith := sWith||&apos;DL as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join cmdlivrlink LL on L.codliniecomanda = LL.codcomanda1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on LL.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ) &apos;;
   sSelect := &apos;
   select ComProd.CodComanda, &apos;||chr(13)||
          &apos;ComProd.TipDoc, &apos;||chr(13)||
          &apos;ComProd.CarnetDocProd, &apos;||chr(13)||
          &apos;ComProd.NrDocProd, &apos;||chr(13)||
          &apos;ComProd.DataDocProd, &apos;||chr(13)||
          &apos;ComProd.SerieDocProd, &apos;||chr(13)||
          &apos;ComProd.Produs, &apos;||chr(13)||
          &apos;ComProd.Reteta, &apos;||chr(13)||
          &apos;ComProd.TermenExec, &apos;||chr(13)||
          &apos;ComProd.DenUM, &apos;||chr(13)||
          &apos;ComProd.CantLansata, &apos;||chr(13)||
          &apos;ComProd.PretLansat, &apos;||chr(13)||
          &apos;ComProd.ValLansata, &apos;||chr(13)||
          &apos;ComProd.CantRealiz, &apos;||chr(13)||
          &apos;CantRealLC.Cant, &apos;||chr(13)||
          &apos;ComProd.ValRealiz, &apos;||chr(13)||
          &apos;ComProd.DifCant, &apos;||chr(13)||
          &apos;ComProd.DifVal, &apos;||chr(13)||
          &apos;ComCli.Client, &apos;||chr(13)||
          &apos;ComCli.CarnetDocCli, &apos;||chr(13)||
          &apos;ComCli.NrDocCli, &apos;||chr(13)||
          &apos;ComCli.DataDocCli, &apos;||chr(13)||
          &apos;ComCli.SerieDocCli, &apos;||chr(13)||
          &apos;ComProd.Sectie, &apos;||chr(13)||
          &apos;ComCli.TermenLivr, &apos;||chr(13)||
          &apos;ComProd.Schimb, &apos;||chr(13)||
          &apos;formatii.den_formatie, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.cant else facturat.cant end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.nrdoc else facturat.nrdoc end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.datadoc else facturat.datadoc end, &apos;||chr(13)||
          &apos;ComProd.ComClosed, &apos;||chr(13)||
          &apos;ComSub.Subunitate, &apos;||chr(13)||
          &apos;ComSub.SerieDocSub, &apos;||chr(13)||
          &apos;ComSub.NrDocSub, &apos;||chr(13)||
          &apos;ComSub.DataDocSub, &apos;||chr(13)||
          &apos;ComProd.Saptamana, &apos;||chr(13)||
          &apos;ComProd.ComCanceled, &apos;||chr(13)||
          &apos;ComCli.ComClosed, &apos;||chr(13)||
          &apos;ComCli.ComCanceled, &apos;||chr(13)||
          &apos;comprod.comoperata &apos;||gUserAlias||&apos;
    from ComProd
      inner join nartobj produs on produs.codobiect = comprod.codprodus
      inner join comanda c on c.codcomanda = ComProd.codcomanda
      inner join comanda1 c1 on c1.codcomanda1 = ComProd.codcomanda1
      left join nartobj component on component.codobiect = comprod.codcomponent
      LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
      left join formatii on nvl(comprod.codformatie, 0) = formatii.codformatie
      left join tmp_comcli comcli on comprod.codcomanda1 = comcli.codcomanda1
      left join cmdlink on cmdlink.codcomanda1 = comprod.codcomanda1
      left join comsub on cmdlink.codliniecomanda = comsub.codcomanda1
      left join facturat on facturat.codcomanda1 = comcli.codcomanda1c
      left join DL on DL.codcomanda1 = comcli.codcomanda1
      left join cantrealLC on cantreallc.codliniecomanda = comprod.codcmdprodmat &apos;||gSuplJoins;
   end if;
 else
   delete tmp_comcli;
    sWith := &apos;insert into tmp_comcli(CODCOMANDA1,CARNETDOCCLI,NRDOCCLI,DATADOCCLI,SERIEDOCCLI,CLIENT,TERMENLIVR,COMCLOSED,COMCANCELED,CODCOMANDA,CODCOMANDA1C)&apos;||chr(13)||
    &apos;SELECT &apos;||chr(13)||
           &apos;  cli.CodCmdInt1 codcomanda1, &apos;||chr(13)||
           &apos;  doc.simbol CarnetDocCli, &apos;||chr(13)||
           &apos;  cc.NrDoc NrDocCli, &apos;||chr(13)||
           &apos;  cc.DataDoc DataDocCli, &apos;||chr(13)||
           &apos;  doc.serie SerieDocCli, &apos;||chr(13)||
           &apos;  P.den_part client, &apos;||chr(13)||
           &apos;  cc1.Termen TermenLivr, &apos;||chr(13)||
           &apos;  case when cc.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
           &apos;  case when cc.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
           &apos;  cC.codcomanda,CLI.CODCMDCLI1 &apos;||chr(13)||
           &apos;FROM &apos;||chr(13)||
           &apos;  (select &apos;||chr(13)||
           &apos;     ci1.codcomanda1 codcmdint1, &apos;||chr(13)||
           &apos;     cc1.codcomanda1 codcmdcli1 &apos;||chr(13)||
           &apos;   from &apos;||chr(13)||
           &apos;      comanda1 ci1 &apos;||chr(13)||
           &apos;      inner join comanda ci on ci1.codcomanda = ci.codcomanda &apos;||chr(13)||
           &apos;      inner join cmdlink l on l.codcomanda1 = ci1.codcomanda1 &apos;||chr(13)||
           &apos;      inner join comanda1 cc1 on l.codliniecomanda = cc1.codcomanda1 &apos;||chr(13)||
           &apos;      inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
           &apos;   where cc.tipdoc = 18 and ci.tipdoc = 53 &apos;||chr(13)||
           &apos;         and ci.datadoc &lt;= to_date(&apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||chr(13)||
           PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CI&apos;,&apos;SUBUNITATEA&apos;)||
           &apos;   START WITH l.codcomanda1 = ci1.CodComanda1 &apos;||chr(13)||
           &apos;   CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1 ) cli &apos;||chr(13)||
           &apos;  inner join comanda1 cc1 on cli.codcmdcli1 = cc1.codcomanda1 &apos;||chr(13)||
           &apos;  inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
           &apos;  inner join npart p on cc.partener = p.codpart
              left join doccarnete doc on cc.carnetdoc = doc.codcarnet &apos;;
    --delete x;
    --insert into x(test) values(swith);
    LIST_EXECUTE_IMMEDIATE(swith, aListID, aListVer);
    Commit;

   if not vCentralizare then
   sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc,
                                NAV_TipDoc,
                                CarnetDocProd,
                                NrDocProd,
                                DataDocProd,
                                SerieDocProd,
                                Articol,
                                Reteta,
                                TermenExec,
                                DenUM,
                                CantLansata,
                                PretLansat,
                                ValLansata,
                                CantRealiz,
                                CantRealizCur,
                                ValRealiz,
                                DifCant,
                                DifVal,
                                Client,
                                CarnetDocCli,
                                NrDocCli,
                                DataDocCli,
                                SerieDocCli,
                                Sectie,
                                TermenLivr,
                                Component,
                                CantComp,
                                UMComp,
                                Schimb,
                                Formatie,
                                GestImp,
                                Facturat,
                                FNrDoc,
                                FDataDoc,
                                ComClosed,
                                Subunitate,
                                CmdSubSerie,
                                CmdSubNrDoc,
                                CmdSubDataDoc,
                                Saptamana,
                                ComCanceled,
                                ComCliClosed,
                                ComCliCanceled,
                                ComCliOperata &apos;||gUserFields||&apos;)&apos;;
   sWith := &apos;WITH &apos;;
   sWith := sWith||&apos;ComProd as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  objc.denumire component, &apos;||chr(13)||
   &apos;  objc.codobiect codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  matc.cant CantComp, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join cmdprodmat matc on c1.codcomanda1 = matc.codcomanda1 and matc.tip &gt; 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join nartobj    objc on matc.codobiect = objc.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;  left  join prodcomp    ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;where c.datadoc between to_date(&apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||
   /*&apos;union all &apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  objc.denumire component, &apos;||chr(13)||
   &apos;  objc.codobiect codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  matc.cant CantComp, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join cmdprodmat matc on c1.codcomanda1 = matc.codcomanda1 and matc.tip &gt; 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join nartobj    objc on matc.codobiect = objc.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  inner  join prodcomp   ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 1 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restcons on restcons.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 0 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restpred on restpred.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codies1) Nr, i1.codcmdint1 &apos;||chr(13)||
   &apos;               from iesiri1 i1 &apos;||chr(13)||
   &apos;                    inner join iesiri i on i1.codies = i.codies &apos;||chr(13)||
   &apos;               where i.tipdoc = 24 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru group by i1.codcmdint1) BCLC on BCLC.CodCmdInt1 = C1.CodComanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codintr1) Nr, l.codliniecomanda &apos;||chr(13)||
   &apos;               from intrari1 i1 &apos;||chr(13)||
   &apos;                    inner join intrari i on i1.codintr = i.codintr &apos;||chr(13)||
   &apos;                    inner join intrprodlink l on i1.codintr1 = l.codintr1 &apos;||chr(13)||
   &apos;               where i.tipdoc = 7 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;               group by l.codliniecomanda ) NPLC on NPLC.CodLinieComanda = mat.CodCmdProdMat &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc = doc.codcarnet &apos;||chr(13)||
   &apos;where c.datadoc between to_date(&apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and  &apos;||chr(13)||
   &apos; (restcons.rest &gt; 0 or restpred.rest &gt; 0 or (restcons.rest + restpred.rest = 0 and (BCLC.Nr&gt;0 or NPLC.Nr&gt;0)))&apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||*/
   &apos;), &apos;;
   sWith := sWith||&apos;ComSub as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocSub, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocSub, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocSub, &apos;||chr(13)||
   &apos;  doc.serie SerieDocSub, &apos;||chr(13)||
   &apos;  s.den_subunit subunitate, &apos;||chr(13)||
   &apos;  c1.Termen TermenLivr &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join nsubunit     s on c.subunitatea   = s.codsubunit &apos;||chr(13)||
   &apos;  inner join comanda1    c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  left  join doccarnete doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;where c.tipdoc = 44 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;)||&apos;), &apos;;
   sWith := sWith||&apos;CantRealLC as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  pl.codliniecomanda &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  intrari i &apos;||chr(13)||
   &apos;  inner join intrari1    i1 on i.codintr = i1.codintr &apos;||chr(13)||
   &apos;  inner join intrprodlink PL on i1.codintr1 = PL.codintr1 &apos;||chr(13)||
   &apos;where i.tipdoc = 7 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by pl.codliniecomanda ), &apos;;
   sWith := sWith||&apos;facturat as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ), &apos;;
   sWith := sWith||&apos;DL as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join cmdlivrlink LL on L.codliniecomanda = LL.codcomanda1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on LL.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ) &apos;;
   sSelect := &apos;
   select ComProd.CodComanda, &apos;||chr(13)||
          &apos;ComProd.TipDoc, &apos;||chr(13)||
          &apos;ComProd.CarnetDocProd, &apos;||chr(13)||
          &apos;ComProd.NrDocProd, &apos;||chr(13)||
          &apos;ComProd.DataDocProd, &apos;||chr(13)||
          &apos;ComProd.SerieDocProd, &apos;||chr(13)||
          &apos;ComProd.Produs, &apos;||chr(13)||
          &apos;ComProd.Reteta, &apos;||chr(13)||
          &apos;ComProd.TermenExec, &apos;||chr(13)||
          &apos;ComProd.DenUM, &apos;||chr(13)||
          &apos;ComProd.CantLansata, &apos;||chr(13)||
          &apos;ComProd.PretLansat, &apos;||chr(13)||
          &apos;ComProd.ValLansata, &apos;||chr(13)||
          &apos;ComProd.CantRealiz, &apos;||chr(13)||
          &apos;CantRealLC.Cant, &apos;||chr(13)||
          &apos;ComProd.ValRealiz, &apos;||chr(13)||
          &apos;ComProd.DifCant, &apos;||chr(13)||
          &apos;ComProd.DifVal, &apos;||chr(13)||
          &apos;ComCli.Client, &apos;||chr(13)||
          &apos;ComCli.CarnetDocCli, &apos;||chr(13)||
          &apos;ComCli.NrDocCli, &apos;||chr(13)||
          &apos;ComCli.DataDocCli, &apos;||chr(13)||
          &apos;ComCli.SerieDocCli, &apos;||chr(13)||
          &apos;ComProd.Sectie, &apos;||chr(13)||
          &apos;ComCli.TermenLivr, &apos;||chr(13)||
          &apos;ComProd.Component, &apos;||chr(13)||
          &apos;ComProd.CantComp, &apos;||chr(13)||
          &apos;umcomponent.den_um, &apos;||chr(13)||
          &apos;ComProd.Schimb, &apos;||chr(13)||
          &apos;formatii.den_formatie, &apos;||chr(13)||
          &apos;gimp.den_gest, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.cant else facturat.cant end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.nrdoc else facturat.nrdoc end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.datadoc else facturat.datadoc end, &apos;||chr(13)||
          &apos;ComProd.ComClosed, &apos;||chr(13)||
          &apos;ComSub.Subunitate, &apos;||chr(13)||
          &apos;ComSub.SerieDocSub, &apos;||chr(13)||
          &apos;ComSub.NrDocSub, &apos;||chr(13)||
          &apos;ComSub.DataDocSub, &apos;||chr(13)||
          &apos;ComProd.Saptamana, &apos;||chr(13)||
          &apos;ComProd.ComCanceled, &apos;||chr(13)||
          &apos;ComCli.ComClosed, &apos;||chr(13)||
          &apos;ComCli.ComCanceled, &apos;||chr(13)||
          &apos;comprod.comoperata &apos;||gUserAlias||&apos;
    from ComProd
      inner join nartobj produs on produs.codobiect = comprod.codprodus
      inner join nartobj component on component.codobiect = comprod.codcomponent
      inner join nart artc on component.codarticol = artc.codarticol
      inner join num umcomponent on artc.um = umcomponent.codum
      inner join comanda c on c.codcomanda = ComProd.codcomanda
      inner join comanda1 c1 on c1.codcomanda1 = ComProd.codcomanda1
      LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
      left join formatii on nvl(comprod.codformatie, 0) = formatii.codformatie
      left join tmp_comcli comcli on comprod.codcomanda1 = comcli.codcomanda1
      left join cmdlink on cmdlink.codcomanda1 = comprod.codcomanda1
      left join comsub on cmdlink.codliniecomanda = comsub.codcomanda1
      left join facturat on facturat.codcomanda1 = comcli.codcomanda1c
      left join DL on DL.codcomanda1 = comcli.codcomanda1
      left join nartimplicite artcimp on artc.codarticol = artcimp.codarticol AND artcimp.codsubunit = pkg_globals.getsubunitate
      left join ngest gimp on artcimp.gestimplicita = gimp.codgest
      left join cantrealLC on cantreallc.codliniecomanda = comprod.codcmdprodmat &apos;||gSuplJoins;
   else
     sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos;(NAV_CodDoc,
                                NAV_TipDoc,
                                CarnetDocProd,
                                NrDocProd,
                                DataDocProd,
                                SerieDocProd,
                                Articol,
                                Reteta,
                                TermenExec,
                                DenUM,
                                CantLansata,
                                PretLansat,
                                ValLansata,
                                CantRealiz,
                                CantRealizCur,
                                ValRealiz,
                                DifCant,
                                DifVal,
                                Client,
                                CarnetDocCli,
                                NrDocCli,
                                DataDocCli,
                                SerieDocCli,
                                Sectie,
                                TermenLivr,
                                Schimb,
                                Formatie,
                                Facturat,
                                FNrDoc,
                                FDataDoc,
                                ComClosed,
                                Subunitate,
                                CmdSubSerie,
                                CmdSubNrDoc,
                                CmdSubDataDoc,
                                Saptamana,
                                ComCanceled,
                                ComCliClosed,
                                ComCliCanceled,
                                ComCliOperata &apos;||gUserFields||&apos;)&apos;;
   sWith := &apos;WITH &apos;;
   sWith := sWith||&apos;ComProd as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  0 codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;  left  join prodcomp    ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;where c.datadoc between to_date(&apos;&apos;&apos;||vZiuaIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||
   /*&apos;union all &apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c.CodComanda, &apos;||chr(13)||
   &apos;  c.TipDoc, &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  mat.CodCmdProdMat, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocProd, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocProd, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocProd, &apos;||chr(13)||
   &apos;  doc.serie SerieDocProd, &apos;||chr(13)||
   &apos;  obj.denumire produs, &apos;||chr(13)||
   &apos;  obj.codobiect codprodus, &apos;||chr(13)||
   &apos;  ret.obs Reteta, &apos;||chr(13)||
   &apos;  c1.Termen TermenExec, &apos;||chr(13)||
   &apos;  num1.den_um1 DenUM, &apos;||chr(13)||
   &apos;  mat.Cant CantLansata, &apos;||chr(13)||
   &apos;  mat.Pret PretLansat, &apos;||chr(13)||
   &apos;  mat.Cant*mat.Pret ValLansata, &apos;||chr(13)||
   &apos;  mat.Cant - mat.Rest CantRealiz, &apos;||chr(13)||
   &apos;  (mat.Cant - mat.Rest)*mat.Pret ValRealiz, &apos;||chr(13)||
   &apos;  mat.Rest DifCant, &apos;||chr(13)||
   &apos;  mat.Rest*mat.Pret DifVal, &apos;||chr(13)||
   &apos;  G.Den_gest Sectie, &apos;||chr(13)||
   &apos;  0 codcomponent, &apos;||chr(13)||
   &apos;  c.CodFormatie, &apos;||chr(13)||
   &apos;  nvl(c.schimb, 0) schimb, &apos;||chr(13)||
   &apos;  case when c.inchisa = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComClosed, &apos;||chr(13)||
   &apos;  to_number(to_char(c1.termen, &apos;&apos;WW&apos;&apos;)) saptamana, &apos;||chr(13)||
   &apos;  case when c.anulat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComCanceled, &apos;||chr(13)||
   &apos;  case when c.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end ComOperata &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join ngest         g on c.codgest      = g.codgest &apos;||chr(13)||
   &apos;  inner join comanda1     c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  inner join cmdprodmat  mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 0 &apos;||chr(13)||
   &apos;  inner join nartobj     obj on mat.codobiect  = obj.codobiect &apos;||chr(13)||
   &apos;  inner join num1            on c1.umsec       = num1.codum1 &apos;||chr(13)||
   &apos;  inner  join prodcomp   ret on c1.codreteta   = ret.codprodcomp &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 1 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restcons on restcons.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  inner join (select cc1.codcomanda1, sum(case when mat.rest &lt; 0 then 0 else mat.rest end) Rest &apos;||chr(13)||
   &apos;              from cmdprodmat mat &apos;||chr(13)||
   &apos;                   inner join comanda1 cc1 on cc1.codcomanda1 = mat.codcomanda1 &apos;||chr(13)||
   &apos;                   inner join comanda cc on cc1.codcomanda = cc.codcomanda &apos;||chr(13)||
   &apos;              where mat.tip = 0 and cc.an*12+cc.luna &lt; Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;              group by cc1.codcomanda1) restpred on restpred.codcomanda1 = c1.codcomanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codies1) Nr, i1.codcmdint1 &apos;||chr(13)||
   &apos;               from iesiri1 i1 &apos;||chr(13)||
   &apos;                    inner join iesiri i on i1.codies = i.codies &apos;||chr(13)||
   &apos;               where i.tipdoc = 24 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru group by i1.codcmdint1) BCLC on BCLC.CodCmdInt1 = C1.CodComanda1 &apos;||chr(13)||
   &apos;  left  join (select count(i1.codintr1) Nr, l.codliniecomanda &apos;||chr(13)||
   &apos;               from intrari1 i1 &apos;||chr(13)||
   &apos;                    inner join intrari i on i1.codintr = i.codintr &apos;||chr(13)||
   &apos;                    inner join intrprodlink l on i1.codintr1 = l.codintr1 &apos;||chr(13)||
   &apos;               where i.tipdoc = 7 and i.operat = 1 and nvl(i.anulat,0) = 0 and nvl(i.blocat,0) = 0 &apos;||chr(13)||
   &apos;                     and i.an*12+i.luna = Pkg_globals.getanlucru*12+ Pkg_globals.getlunalucru &apos;||chr(13)||
   &apos;               group by l.codliniecomanda ) NPLC on NPLC.CodLinieComanda = mat.CodCmdProdMat &apos;||chr(13)||
   &apos;  left  join doccarnete  doc on c.carnetdoc = doc.codcarnet &apos;||chr(13)||
   &apos;where c.datadoc &lt; to_date(&apos;&apos;&apos;||vZiuaFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and  &apos;||chr(13)||
   &apos; (restcons.rest &gt; 0 or restpred.rest &gt; 0 or (restcons.rest + restpred.rest = 0 and (BCLC.Nr&gt;0 or NPLC.Nr&gt;0)))&apos;||sCondNeop||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;)||*/
   &apos;), &apos;;
   sWith := sWith||&apos;ComSub as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.CodComanda1, &apos;||chr(13)||
   &apos;  doc.simbol CarnetDocSub, &apos;||chr(13)||
   &apos;  c.NrDoc NrDocSub, &apos;||chr(13)||
   &apos;  c.DataDoc DataDocSub, &apos;||chr(13)||
   &apos;  doc.serie SerieDocSub, &apos;||chr(13)||
   &apos;  s.den_subunit subunitate, &apos;||chr(13)||
   &apos;  c1.Termen TermenLivr &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  comanda c &apos;||chr(13)||
   &apos;  inner join nsubunit     s on c.subunitatea   = s.codsubunit &apos;||chr(13)||
   &apos;  inner join comanda1    c1 on c1.codcomanda  = c.codcomanda &apos;||chr(13)||
   &apos;  left  join doccarnete doc on c.carnetdoc    = doc.codcarnet &apos;||chr(13)||
   &apos;where c.tipdoc = 44 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITSURSA&apos;)||&apos;), &apos;;
   sWith := sWith||&apos;CantRealLC as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  pl.codliniecomanda &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  intrari i &apos;||chr(13)||
   &apos;  inner join intrari1    i1 on i.codintr = i1.codintr &apos;||chr(13)||
   &apos;  inner join intrprodlink PL on i1.codintr1 = PL.codintr1 &apos;||chr(13)||
   &apos;where i.tipdoc = 7 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by pl.codliniecomanda ), &apos;;
   sWith := sWith||&apos;facturat as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on l.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ), &apos;;
   sWith := sWith||&apos;DL as (&apos;||chr(13)||
   &apos;select &apos;||chr(13)||
   &apos;  c1.Codcomanda1, &apos;||chr(13)||
   &apos;  sum(i1.Cant) cant, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.nrdoc)) nrdoc, &apos;||chr(13)||
   &apos;  string_agg(to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;)) datadoc &apos;||chr(13)||
   &apos;from &apos;||chr(13)||
   &apos;  iesiri i &apos;||chr(13)||
   &apos;  inner join iesiri1 i1 on i.codies = i1.codies &apos;||chr(13)||
   &apos;  inner join ieslink L on i1.codies1 = L.codies1 &apos;||chr(13)||
   &apos;  inner join cmdlivrlink LL on L.codliniecomanda = LL.codcomanda1 &apos;||chr(13)||
   &apos;  inner join comanda1 c1 on LL.codliniecomanda = c1.codcomanda1 &apos;||chr(13)||
   &apos;where 1=1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;,&apos;SUBUNITATEA&apos;)||&apos; group by c1.codcomanda1 ) &apos;;
   sSelect := &apos;
   select ComProd.CodComanda, &apos;||chr(13)||
          &apos;ComProd.TipDoc, &apos;||chr(13)||
          &apos;ComProd.CarnetDocProd, &apos;||chr(13)||
          &apos;ComProd.NrDocProd, &apos;||chr(13)||
          &apos;ComProd.DataDocProd, &apos;||chr(13)||
          &apos;ComProd.SerieDocProd, &apos;||chr(13)||
          &apos;ComProd.Produs, &apos;||chr(13)||
          &apos;ComProd.Reteta, &apos;||chr(13)||
          &apos;ComProd.TermenExec, &apos;||chr(13)||
          &apos;ComProd.DenUM, &apos;||chr(13)||
          &apos;ComProd.CantLansata, &apos;||chr(13)||
          &apos;ComProd.PretLansat, &apos;||chr(13)||
          &apos;ComProd.ValLansata, &apos;||chr(13)||
          &apos;ComProd.CantRealiz, &apos;||chr(13)||
          &apos;CantRealLC.Cant, &apos;||chr(13)||
          &apos;ComProd.ValRealiz, &apos;||chr(13)||
          &apos;ComProd.DifCant, &apos;||chr(13)||
          &apos;ComProd.DifVal, &apos;||chr(13)||
          &apos;ComCli.Client, &apos;||chr(13)||
          &apos;ComCli.CarnetDocCli, &apos;||chr(13)||
          &apos;ComCli.NrDocCli, &apos;||chr(13)||
          &apos;ComCli.DataDocCli, &apos;||chr(13)||
          &apos;ComCli.SerieDocCli, &apos;||chr(13)||
          &apos;ComProd.Sectie, &apos;||chr(13)||
          &apos;ComCli.TermenLivr, &apos;||chr(13)||
          &apos;ComProd.Schimb, &apos;||chr(13)||
          &apos;formatii.den_formatie, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.cant else facturat.cant end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.nrdoc else facturat.nrdoc end, &apos;||chr(13)||
          &apos;case when nvl(facturat.codcomanda1,0) = 0 then DL.datadoc else facturat.datadoc end, &apos;||chr(13)||
          &apos;ComProd.ComClosed, &apos;||chr(13)||
          &apos;ComSub.Subunitate, &apos;||chr(13)||
          &apos;ComSub.SerieDocSub, &apos;||chr(13)||
          &apos;ComSub.NrDocSub, &apos;||chr(13)||
          &apos;ComSub.DataDocSub, &apos;||chr(13)||
          &apos;ComProd.Saptamana, &apos;||chr(13)||
          &apos;ComProd.ComCanceled, &apos;||chr(13)||
          &apos;ComCli.ComClosed, &apos;||chr(13)||
          &apos;ComCli.ComCanceled, &apos;||chr(13)||
          &apos;comprod.comoperata &apos;||gUserAlias||&apos;
    from ComProd
      inner join nartobj produs on produs.codobiect = comprod.codprodus
      inner join comanda c on c.codcomanda = ComProd.codcomanda
      inner join comanda1 c1 on c1.codcomanda1 = ComProd.codcomanda1
      left join nartobj component on component.codobiect = comprod.codcomponent
      LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
      left join formatii on nvl(comprod.codformatie, 0) = formatii.codformatie
      left join tmp_comcli comcli on comprod.codcomanda1 = comcli.codcomanda1
      left join cmdlink on cmdlink.codcomanda1 = comprod.codcomanda1
      left join comsub on cmdlink.codliniecomanda = comsub.codcomanda1
      left join facturat on facturat.codcomanda1 = comcli.codcomanda1c
      left join DL on DL.codcomanda1 = comcli.codcomanda1
      left join cantrealLC on cantreallc.codliniecomanda = comprod.codcmdprodmat &apos;||gSuplJoins;
   end if;
 end if;

 LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sSelect, aListID, aListVer);

 COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_PROGLUNFAB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A92F400E3E572038D923470C90E839C99BF58498</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROIECT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  p_CodProiect NUMBER(20) default 0;
  p_CodComanda1 NUMBER(20) default 0;

PROCEDURE setParams(aCodProiect IN number, aCodComanda1 in number default 0)
IS
BEGIN
  p_CodProiect := aCodProiect;
  p_CodComanda1 := aCodComanda1;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString  VARCHAR2(30000);
aCodComanda number(20);
BEGIN
  gSuplCols := &apos;proiectnod nod, nartobj obj, nart art, num um, nartobjsubunit objsub, nclasea cls, proiect prj, nartobj objprj, prodmat mat&apos;;
  if p_CodComanda1 &gt; 0 then
    gSuplCols := gSuplCols||&apos;,Comanda1 C1&apos;;
  end if;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if p_CodComanda1 &gt; 0 then
    sString :=
    &apos;insert into &apos;||tmpName||&apos;( Obiect, UM, Cant, Pozitie, Nivel, ordine, Obs&apos;||gUserFields||&apos;)
    select nvl(obje.denumire,obj.denumire), nvl(UME.den_um,UM.den_um), nod.Cant * nvl(echiv.paritate,1), nod.Pozitie, nod.Nivel, substr(x.ind,5, length(x.ind)-3),
           mat.obs&apos;||gUserAlias||&apos;
    from comanda1 c1
      inner join proiectnod nod on nod.codproiect = c1.codproiect
      inner join proiect prj on prj.codproiect = nod.codproiect
      inner join nartobj objprj on prj.codobiectprod = objprj.codobiect
      left join prodmat mat on mat.codmat = nod.codprodmat
      left join nodechiv echiv on echiv.codproiectnod = nod.codproiectnod and echiv.codcomanda1 = &apos;||p_CodComanda1||&apos;
      left join nartobj obj on nod.codobiect = obj.codobiect
      left join nartobjsubunit objsub on nod.codobiect = objsub.codobiect 
                                      and (objsub.codgest is null or objsub.codgest = 0)
                                      and objsub.subunitate = pkg_globals.getsubunitate
      left join nartobj obje on echiv.codobiect = obje.codobiect
      left join nart art on obj.codarticol = art.codarticol
      left join nclasea cls on cls.codclasea = art.clasa
      left join nart arte on obje.codarticol = arte.codarticol
      left join num um on um.codum = art.um
      left join num ume on ume.codum = arte.um
      LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND
                  FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = nod.CodProiectNod&apos;||
      gSuplJoins||&apos;
    where nvl(nod.nodoriginal, 0) &gt; 0  and c1.codcomanda1 = &apos;||p_CodComanda1;
  else
    sString :=
    &apos;insert into &apos;||tmpName||&apos;( Obiect, UM, Cant, Pozitie, Nivel, ordine, obs&apos;||gUserFields||&apos;)
    select obj.denumire, UM.den_um, nod.Cant, nod.Pozitie, nod.Nivel, substr(x.ind,5, length(x.ind)-3), mat.obs&apos;||gUserAlias||&apos;
    from proiectnod nod
      inner join proiect prj on prj.codproiect = nod.codproiect
      inner join nartobj objprj on prj.codobiectprod = objprj.codobiect
      left join prodmat mat on mat.codmat = nod.codprodmat
      left join nartobj obj on nod.codobiect = obj.codobiect
      left join nartobjsubunit objsub on nod.codobiect = objsub.codobiect 
                                      and (objsub.codgest is null or objsub.codgest = 0)
                                      and objsub.subunitate = pkg_globals.getsubunitate
      left join nart art on obj.codarticol = art.codarticol
      left join nclasea cls on cls.codclasea = art.clasa
      left join num um on um.codum = art.um
      LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND
                  FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = nod.CodProiectNod&apos;||
      gSuplJoins||&apos;
    where nvl(nod.nodoriginal, 0) &gt; 0  and nod.codproiect = &apos;||p_CodProiect;
  end if;

  LIST_EXECUTE_IMMEDIATE(sstring, aListID, aListVer);

  if p_CodComanda1 &gt; 0 then
    begin
      select codcomanda into aCodComanda from comanda1 where codcomanda1 = p_CodComanda1;
    exception when others then aCodComanda := 0;
    end;
    if aCodComanda &gt; 0 then
      pkg_list_base_comdoc.SETPARAMS(aCodComanda, aListID, 0);
      pkg_list_base_comdoc.ADD_LIST_PARAMS;
    end if;
  end if;

  Commit;
END;

end pkg_list_base_proiect;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROIECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>053B43AD37A28364BDB9DF1C38AF75AB1C58C14D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROIECTE IS

  p_flgAllArt NUMBER(1);
  p_Sursa NUMBER(1);
  p_Tip NUMBER(1);
  p_Stoc number(1);
  p_flgAllGest number(1);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  sSelect     VARCHAR2(20000);
  sSelect0    VARCHAR2(20000);
  sSelect1    VARCHAR2(20000);
  gStocField  VARCHAR2(50);
  gStocAlias  VARCHAR2(50);
  gJoinStoc   VARCHAR2(500);
  gUserId     NUMBER(20);
BEGIN
  p_flgAllArt  := pkg_list_base_consum_prod.GetAllArt;
  p_Sursa      := pkg_list_base_consum_prod.GetSursa;
  p_Tip        := pkg_list_base_consum_prod.GetTip;
  p_Stoc       := pkg_list_base_consum_prod.GetStoc;
  p_flgAllGest := pkg_list_base_consum_prod.GetAllGest;
  gUserID      := pkg_globals.getuserid;

  gStocField := &apos; &apos;;
  gStocAlias := &apos; &apos;;
  gJoinStoc  := &apos; &apos;;

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);

  if p_Stoc = 1 then
    gStocAlias := &apos; ,Stoc &apos;;
    gStocField := &apos; ,nvl(tmpp.Cant,0) &apos;;
    gJoinStoc  := &apos;
                   left join tmp_planifstoc tmpp on tmpp.codobiect = mat.codobiect &apos;;
  end if;

  gSuplCols := &apos;NARTOBJ OBJP, NARTOBJ OBJC, NARTOBJSUBUNIT OBJCS, NARTOBJSUBUNIT OBJPS, PRODCOMP PC, PRODMAT MAT, NCLASEA CLSCOMP, NGEST SECTIE, PROIECTNOD PN, PROIECT P&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTP&apos;, &apos;OEXTP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRP&apos;, &apos;OATRP.CODOBIECT = OBJP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTC&apos;, &apos;OEXTC.CODOBIECT = OBJC.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRC&apos;, &apos;OATRC.CODOBIECT = OBJC.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if p_flgAllArt = 1 then
    delete tmp_proiectnod_man where userid = gUserID;
    insert into TMP_PROIECTNOD_MAN(CodProiect, CodObiect, Cant, necesar, UserID)
    select pn.codproiect, pn.codobiect, pn.cant, pc.pret, gUserID
    from proiectnod pn
         inner join prodcomp pc on pc.codprodcomp = pn.codreteta
    where nodoriginal = 0;

    COMMIT;
  end if;

  DELETE tmp_planifstoc;
  if p_Stoc = 1 then
    IF p_flgAllGest = 1 THEN
      INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT)
      SELECT CODOBIECT, sum(REST)
      FROM (
        SELECT NS.CODOBIECT, CASE WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST ELSE NSE.REST END REST
        FROM NIRSTOC NS
          INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND PKG_GLOBALS.AnLunaLucru BETWEEN IO.ALStart AND IO.ALStop
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST AND (G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE IO.MG &lt;&gt; 5
      )
      GROUP BY CODOBIECT;
    ELSE
      INSERT INTO TMP_PLANIFSTOC (CODOBIECT, CANT)
      SELECT CODOBIECT, sum(REST)
      FROM (
        SELECT NS.CODOBIECT, CASE WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.REST ELSE NSE.REST END REST
        FROM NIRSTOC NS
          INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
          INNER JOIN NGEST G ON G.CODGEST = N.GEST
          LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        WHERE EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGESTSTOC&apos; AND VALOARE = G.CODGEST)
      )
      GROUP BY CODOBIECT;
    end if;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos; (
    SysCod, NAV_CODDOC, NAV_TIPDOC, PR_ART, PR_UM, PR_UM1, PR_CANT, PR_PRET, PR_Data, COMP_ART, COMP_PARINTE, COMP_UM, COMP_UM1, COMP_CANT, COMP_PRET, COMP_TIP,
    EV_Pret_Sursa_min, EV_val_min, EV_Pret_Sursa_max, EV_val_max, EV_Pret_Sursa_med, EV_val_med, EV_Pret_Sursa_PMP, EV_val_PMP, Necesar, Activa, PR_CANT_SELECTATA,
    D1, D2, D3, Tip, CLSP, PR_PRET_REF, COMP_PRET_REF, NIVEL, PR_PRET_IMP, NOD, LotOptim, PretAchizU, Ordine&apos;||gStocAlias||gUserFields||&apos;)&apos;;

  sSelect0 := &apos;
  WITH PMin As (
    SELECT nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0) / U1.PARITATE) END) * nvl(u1.Paritate,0)) , 0) Pret, NS.CODOBIECT
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      LEFT JOIN NUM1 U1 ON NS.Umsec = U1.Codum1
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY NS.CODOBIECT),
  PMin0 as (
    SELECT nvl(Min((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0) / U1.PARITATE) END) * nvl(u1.Paritate,0)) , 0) Pret, NS.CODOBIECT
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      LEFT JOIN NUM1 U1 ON NS.Umsec = U1.Codum1
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &lt;= 0 AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY NS.CODOBIECT),
  PMax as (
    SELECT nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0) / U1.PARITATE) END) * nvl(u1.Paritate,0)) , 0) Pret, NS.CODOBIECT
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      LEFT JOIN NUM1 U1 ON NS.Umsec = U1.Codum1
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &gt; 0 AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY NS.CODOBIECT),
  PMax0 as (
    SELECT nvl(Max((nvl(NS.PRET,0) - nvl(NS.ADAOS,0) - CASE WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0 ELSE NVL(NS.SUPLIMENT, 0) /(nvl(NS.CANTNIR,0) / U1.PARITATE) END) * nvl(u1.Paritate,0)) , 0) Pret, NS.CODOBIECT
    FROM NIRSTOC NS
      INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
      LEFT JOIN NUM1 U1 ON NS.Umsec = U1.Codum1
    WHERE G.Tip &lt;&gt; 4 and NS.Rest &lt;= 0 AND G.CODSUBUNIT = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY NS.CODOBIECT )
  SELECT
    P.CODPROIECT, P.CODPROIECT, 507, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, TMP.cant, TMP.necesar, P.DataProiect, OBJC.Denumire, OBJPP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, PN.Cant, nvl(MAT.Pret,0),
    case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end,
    case when nvl(PMin.Pret,0) = 0 then nvl(PMin0.Pret,0) else nvl(PMin.Pret,0) end,
    MAT.Cant * case when nvl(PMin.Pret,0) = 0 then nvl(PMin0.Pret,0) else nvl(PMin.Pret,0) end,
    case when nvl(PMax.Pret,0) = 0 then nvl(PMax0.Pret,0) else nvl(PMax.Pret,0) end,
    MAT.Cant * case when nvl(PMax.Pret,0) = 0 then nvl(PMax0.Pret,0) else nvl(PMax.Pret,0) end,
    (case when nvl(PMax.Pret,0) = 0 then nvl(PMax0.Pret,0) else nvl(PMax.Pret,0) end +case when nvl(PMin.Pret,0) = 0 then nvl(PMin0.Pret,0) else nvl(PMin.Pret,0) end) / 2,
    MAT.Cant * (case when nvl(PMax.Pret,0) = 0 then nvl(PMax0.Pret,0) else nvl(PMax.Pret,0) end +case when nvl(PMin.Pret,0) = 0 then nvl(PMin0.Pret,0) else nvl(PMin.Pret,0) end) / 2,
    PKG_PMP.GET_PMP_LAST(Mat.CodObiect, decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)),
    MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)),
    TMP.Cant/PN0.CANT * PN.Cant, case when P.ACTIV = 1 then &apos;&apos;Activ&apos;&apos; else &apos;&apos;Inactiv&apos;&apos; end, TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Proiect&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA,
    NVL(PN.Nivel,0), PM.Lei, X.IND, PCP.CANT, pkg_list_base_consum_prod.GETLASTPRETACHIZ(objc.codobiect),
    substr(x.ind,5, length(x.ind)-3)&apos;||gStocField||gUserAlias||&apos;
  FROM PROIECT P
    INNER JOIN TMP_PROIECTNOD_MAN TMP ON P.CodProiect = TMP.CodProiect and tmp.userid = &apos;||gUserID||&apos;
    INNER JOIN PROIECTNOD PN ON P.CODPROIECT = PN.CODPROIECT
    INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0
    INNER JOIN PRODCOMP PC ON PN0.CODRETETA = PC.CODPRODCOMP
    INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
    INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST
    INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
    INNER JOIN NARTOBJ OBJP ON P.CODOBIECTPROD = OBJP.CODOBIECT
    INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
    INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
    INNER JOIN NARTOBJ OBJC ON PN.CODOBIECT = OBJC.CODOBIECT
    INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
    INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
    LEFT  JOIN NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect and (OBJCS.codgest is null or OBJCS.codgest = 0) and objcs.subunitate = pkg_globals.getsubunitate
    LEFT  JOIN NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect and (OBJPS.codgest is null or OBJPS.codgest = 0) and objps.subunitate = pkg_globals.getsubunitate
    LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    LEFT  JOIN PROIECTNOD PNP ON PN.NODORIGINAL = PNP.CODPROIECTNOD
    LEFT  JOIN PRODCOMP PCP ON PCP.CODPRODCOMP = DECODE(NVL(PNP.CODPROIECTNOD,0),0, PN0.CODRETETA, PNP.CODRETETA)
    LEFT  JOIN NARTOBJ OBJPP ON PNP.CODOBIECT = OBJPP.CODOBIECT
    LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
    LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
    LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
    LEFT  JOIN NCLASEA CLSCOMP ON NVL(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
    LEFT  JOIN NARTOBJ1 P1 ON P1.CodObiect  = OBJP.CodObiect AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN P1.ALStart and P1.ALStop
    LEFT  JOIN NARTOBJ1 C1 ON C1.CodObiect  = OBJC.CodObiect AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN C1.ALStart and C1.ALStop
    LEFT  JOIN (SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND FROM PROIECTNOD START WITH NODORIGINAL = 0 CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) X on x.CodProiectNod = PN.CodProiectNod
    LEFT  JOIN PMin on PMin.COdObiect = Mat.CodObiect
    LEFT  JOIN PMin0 on PMin0.COdObiect = Mat.CodObiect
    LEFT  JOIN PMax on PMax.COdObiect = Mat.CodObiect
    LEFT  JOIN PMax0 on PMax0.COdObiect = Mat.CodObiect &apos;||gJoinStoc||
    gSuplJoins;

  sSelect1 := &apos;
  WITH PretMin As (
    SELECT Min(O1.PRET) pret, O1.CodObiect
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
    WHERE (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &lt;= Extract(MONTH FROM nvl(O.Dataend, to_date(&apos;&apos;01.01.2899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))+12*Extract(Year FROM nvl(O.Dataend, to_date(&apos;&apos;01.01.2899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))))
      AND (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &gt;= Extract(MONTH FROM nvl(O.Datastart, to_date(&apos;&apos;01.01.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))+12*Extract(Year FROM nvl(O.Datastart, to_date(&apos;&apos;01.01.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))))
      AND O.SUBUNITATEA = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY O1.CodObiect),
  PretMax as (
    SELECT Min(O1.PRET) pret, O1.CodObiect
    FROM OFERTA1 O1
      INNER JOIN OFERTA O ON O1.CODOFERTA = O.CODOFERTA
    WHERE (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &lt;= Extract(MONTH FROM nvl(O.Dataend, to_date(&apos;&apos;01.01.2899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))+12*Extract(Year FROM nvl(O.Dataend, to_date(&apos;&apos;01.01.2899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))))
    AND (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &gt;= Extract(MONTH FROM nvl(O.Datastart, to_date(&apos;&apos;01.01.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))+12*Extract(Year FROM nvl(O.Datastart, to_date(&apos;&apos;01.01.1899&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))))
      AND O.SUBUNITATEA = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    GROUP BY O1.CodObiect)
  SELECT
    P.CODPROIECT, P.CODPROIECT, 507, OBJP.Denumire, NUMP.Den_UM, NUMP1.Den_UM, TMP.Cant, TMP.necesar, P.DataProiect, OBJC.Denumire, OBJPP.Denumire, NUMC.Den_UM, NUMC1.Den_UM, PN.Cant, nvl(MAT.Pret,0),
    case when MAT.Tip = 1 then &apos;&apos;Complex&apos;&apos; when MAT.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Material&apos;&apos; end, NVL(PretMin.Pret,0), MAT.Cant * NVL(PretMin.Pret,0), NVL(PretMax.Pret,0), MAT.Cant * NVL(PretMax.Pret,0),
    (NVL(PretMax.Pret,0)+NVL(PretMin.Pret,0)) / 2, MAT.Cant * (NVL(PretMax.Pret,0)+NVL(PretMin.Pret,0)) / 2, PKG_PMP.GET_PMP_LAST(Mat.CodObiect, decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)),
    MAT.Cant * PKG_PMP.GET_PMP_LAST(Mat.CodObiect, decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)), TMP.Cant / PN0.CANT * PN.Cant, case when P.ACTIV = 1 then &apos;&apos;Activ&apos;&apos; else &apos;&apos;Inactiv&apos;&apos; end,
    TMP.Cant, MAT.D1, MAT.D2, MAT.D3, &apos;&apos;Proiect&apos;&apos; Tip, CLSP.Den_ClaseA, P1.PRETREFERINTA, C1.PRETREFERINTA, NVL(PN.NIVEL,0), Lei, X.IND, PCP.CANT, pkg_list_base_consum_prod.GETLASTPRETACHIZ(objc.codobiect),
    substr(x.ind,5, length(x.ind)-3) &apos;||gStocField||gUserAlias||&apos;
  FROM
    PROIECT P
    INNER JOIN TMP_PROIECTNOD_MAN TMP ON P.CodProiect = TMP.CodProiect and tmp.userid = &apos;||gUserID||&apos;
    INNER JOIN PROIECTNOD PN ON P.CODPROIECT = PN.CODPROIECT
    INNER JOIN PROIECTNOD PN0 ON P.CODPROIECT = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0
    INNER JOIN PRODCOMP PC ON PN0.CODRETETA = PC.CODPRODCOMP
    INNER JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
    INNER JOIN PRODGEST PG  ON MAT.CODPRODGEST = PG.CODPRODGEST
    INNER JOIN NGEST SECTIE ON SECTIE.CODGEST = PG.CODGEST
    INNER JOIN NARTOBJ OBJP ON P.CODOBIECTPROD = OBJP.CODOBIECT
    INNER JOIN NART ARTP ON OBJP.CODARTICOL = ARTP.CODARTICOL
    INNER JOIN NUM NUMP ON ARTP.UM = NUMP.CODUM
    INNER JOIN NARTOBJ OBJC ON PN.CODOBIECT = OBJC.CODOBIECT
    INNER JOIN NART ARTC ON OBJC.CODARTICOL = ARTC.CODARTICOL
    INNER JOIN NUM NUMC ON ARTC.UM = NUMC.CODUM
    left  join NARTOBJSUBUNIT OBJCS on objc.codobiect = objcs.codobiect and (OBJCS.codgest is null or OBJCS.codgest = 0) and objcs.subunitate = pkg_globals.getsubunitate
    left  join NARTOBJSUBUNIT OBJPS on objp.codobiect = objps.codobiect and (OBJPS.codgest is null or OBJPS.codgest = 0) and objps.subunitate = pkg_globals.getsubunitate
    LEFT  JOIN pretm pm ON pm.codobiect = OBJP.codobiect AND pm.implicit = 1 AND pm.subunitatea = decode(pkg_globals.getsubunitate,1,2,pkg_globals.getsubunitate)
    LEFT  JOIN PROIECTNOD PNP ON PN.NODORIGINAL = PNP.CODPROIECTNOD
    LEFT  JOIN PRODCOMP PCP ON PCP.CODPRODCOMP = DECODE(NVL(PNP.CODPROIECTNOD,0), 0, PN0.CODRETETA, PNP.CODRETETA)
    LEFT  JOIN NARTOBJ OBJPP ON PNP.CODOBIECT = OBJPP.CODOBIECT
    LEFT  JOIN NUM NUMP1 ON ARTP.UM1 = NUMP1.CODUM
    LEFT  JOIN NUM NUMC1 ON ARTC.UM1 = NUMC1.CODUM
    LEFT  JOIN NCLASEA CLSP ON NVL(ARTP.CLASA,0) = CLSP.CODCLASEA
    LEFT  JOIN NCLASEA CLSCOMP ON nvl(ARTC.CLASA,0) = CLSCOMP.CODCLASEA
    LEFT  JOIN NARTOBJ1  P1 ON P1.CodObiect  = OBJP.CodObiect AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN P1.ALStart and P1.ALStop
    LEFT  JOIN NARTOBJ1  C1 ON C1.CodObiect  = OBJC.CodObiect AND &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;)||&apos; BETWEEN C1.ALStart and C1.ALStop
    LEFT  JOIN (
      SELECT CodProiectNod, sys_connect_by_path(LPAD(POZITIE, 2, &apos;&apos;0&apos;&apos;),&apos;&apos;.&apos;&apos;) IND
      FROM PROIECTNOD
      START WITH NODORIGINAL = 0
      CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL
    ) X on x.CodProiectNod = PN.CodProiectNod
    LEFT  JOIN PretMin on PretMin.COdObiect = Mat.CodObiect
    LEFT  JOIN PretMax on PretMax.COdObiect = Mat.CodObiect &apos;||gJoinStoc||
    gSuplJoins;

  IF p_Sursa = 0
  THEN sSelect := sSelect0;
  ELSE sSelect := sSelect1;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  delete tmp_proiectnod_man where userid = gUserID;
  COMMIT;
END;

end PKG_LIST_BASE_PROIECTE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E01880FF250DE9A4F4540ECABFFFC88DDC59E479</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROMO IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataIni     DATE;
  vDataFin     DATE;
  vTotiPart    BOOLEAN;
  vGrupPart    BOOLEAN;

PROCEDURE SETPARAMS(  pDataIni  IN VARCHAR2,
                      pDataFin  IN VARCHAR2,
                      pTotiPart IN NUMBER DEFAULT 1,
                      pGrupPart IN NUMBER DEFAULT 1,
                      V_CODJOB1 IN NUMBER DEFAULT 0
                    ) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vTotiPart := pTotiPart = 1;
  vGrupPart := pGrupPart = 1;
  vDataIni  := To_Date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin  := To_Date(pDataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  sInsTmp1 CLOB;
  sAuxTmp1 CLOB := &apos;&apos;;
  sDelTmp1 CLOB;
  sUpdTmp1 CLOB;
  sInsTmp2 CLOB;
  sGrpTMP  CLOB;
  vFiltruPart CLOB := &apos;&apos;; 
BEGIN
  gSuplCols := &apos;TMP_LST_PROMOPART PP, PROMO P, PROMO1 P1, NARTOBJ O, NART A, NUM1 UM, NCLASEA CA&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_LST_PROMO&apos;,&apos;TP&apos;,    &apos;TP.CODPROMO = P.CODPROMO&apos; );
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,   &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos; );
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,   &apos;OATR&apos;,  &apos;OATR.CODOBIECT = O.CODOBIECT&apos; );
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMO1CADOU&apos;,  &apos;PC&apos;,    &apos;PC.CODCADOU = TMP.CODCADOU&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMOPRAG&apos;,    &apos;PRAG&apos;,  &apos;PRAG.CODPRAG = TMP.CODPRAG&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,      &apos;OC&apos;,    &apos;OC.CODOBIECT = PC.CODOBIECT&apos;,1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,        &apos;PM&apos;,    &apos;PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = TMP.SUBUNITATEA AND PM.IMPLICIT = 1&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 THEN
    sAuxTmp1 := &apos;
    WHERE Subunitatea IN (1, &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;)&apos;;
  END IF;

  sInsTmp1 := &apos;INSERT INTO TMP_LST_PROMO (CodPromo, Subunitatea, NrSubunit)
  SELECT CodPromo, CASE WHEN Count(1) &gt; 1 THEN 0 ELSE Max(Subunitatea) END, Max(NrSubunit)
  FROM (
    SELECT CodPromo, Subunitatea, NrSubunit
    FROM (
      SELECT P.CodPromo, Coalesce(PS.Subunitatea, P.Subunitatea, 1) Subunitatea, Count(1) Over (PARTITION BY P.CodPromo) NrSubunit
      FROM PROMO P LEFT JOIN PROMOSUB PS ON PS.CodPromo = P.CodPromo
      WHERE P.DATASTART &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataFin,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;)
        AND P.DATAEND   &gt;= To_Date(&apos;&apos;&apos;||To_Char(vDataIni,&apos;yyyymmdd&apos;)||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;)
    )&apos;||
    sAuxTmp1||&apos;
  )
  GROUP BY CodPromo&apos;;

  sDelTmp1 := &apos;DELETE TMP_LST_PROMO WHERE NOT CodPromo IN (SELECT DISTINCT CODPROMO FROM TMP_LST_PROMOPART)&apos;;
  sUpdTmp1 :=
  &apos;UPDATE TMP_LST_PROMO T
  SET T.LISTSUBUNIT = CASE
                        WHEN T.NrSubunit = 1 THEN (SELECT S.DEN_SUBUNIT FROM NSubunit S WHERE S.CodSubunit = T.Subunitatea)
                        ELSE (SELECT vc2_nt_to_vc3200(set(CAST(COLLECT(S.Den_Subunit ORDER BY S.Den_Subunit) AS vc2_nt))) FROM PROMOSUB PS, NSubunit S WHERE PS.CodPromo = T.CodPromo AND S.CodSubunit = PS.Subunitatea)
                      END&apos;;

  sInsTmp2 := &apos;INSERT INTO TMP_LST_PROMOPART (CodPromo, Den_Part, Den_ClaseP, CIF, Autorizatie, RegCom, Den_Localit, COD_PART)
  SELECT
    P.CodPromo,&apos;;

  IF vGrupPart THEN
    sInsTmp2 := sInsTmp2||&apos;
    vc2_nt_to_vc3200(set(CAST(COLLECT(NP.Den_Part    ORDER BY pp.codpromopart) AS vc2_nt))) Den_Part,
    vc2_nt_to_vc3200(set(CAST(COLLECT(CP.Den_ClaseP  ORDER BY pp.codpromopart) AS vc2_nt))) Den_ClaseP,
    vc2_nt_to_vc3200(set(CAST(COLLECT(PCF.CodFiscal  ORDER BY pp.codpromopart) AS vc2_nt))) CIF,
    vc2_nt_to_vc3200(set(CAST(COLLECT(NP.Autorizatie ORDER BY pp.codpromopart) AS vc2_nt))) Autorizatie,
    vc2_nt_to_vc3200(set(CAST(COLLECT(NP.RegCom      ORDER BY pp.codpromopart) AS vc2_nt))) RegCom,
    vc2_nt_to_vc3200(set(CAST(COLLECT(L.Den_Localit  ORDER BY pp.codpromopart) AS vc2_nt))) Den_Localit, 
    substr(vc2_nt_to_vc3200(set(CAST(COLLECT(to_char(NP.CODPart)     ORDER BY pp.codpromopart) AS vc2_nt))), 50) Cod_Part&apos;;
  ELSE
    sInsTmp2 := sInsTmp2||&apos;
    NP.Den_Part, CP.Den_ClaseP, PCF.CodFiscal CIF, NP.Autorizatie, NP.RegCom, L.Den_Localit, to_char(NP.CODPART)&apos;;
  END IF;

  sInsTmp2 := sInsTmp2||&apos;
  FROM TMP_LST_PROMO TP
    LEFT JOIN PROMO P ON P.CodPromo = TP.CodPromo
    LEFT JOIN Promopart PP ON PP.CodPromo = TP.CodPromo
    LEFT JOIN NPART NP ON NP.CodPart = Coalesce(P.Partener, PP.Partener)
    LEFT JOIN NPARTCODFISC PCF ON PCF.Cod_CodFiscal = CASE WHEN P.Partener IS NULL THEN PP.CodFiscal ELSE P.CODFISCAL END
    LEFT JOIN NAGENDA AG ON AG.CodAgenda = CASE WHEN P.Partener IS NULL THEN PP.CodLocatie ELSE P.CodLocatie END
    LEFT JOIN NLOCALIT L ON L.CodLocalit = AG.CodLocalit
    LEFT JOIN NCLASEP CP ON CP.CodClaseP = PP.CodClaseP&apos;;

  IF not vTotiPart THEN
    sInsTmp2 := sInsTmp2||&apos;
    AND CASE
          WHEN (SELECT Count(1) FROM promopart pp WHERE pp.codpromo = p.codpromo) = 0 AND Coalesce(P.Partener, 0) = 0 THEN 1
          WHEN Coalesce(P.TIPCLASEP,0) = 0 THEN (SELECT COUNT(1) FROM TMP_MANEVRA_LISTE TF WHERE TF.FILTRU = &apos;&apos;CODPART&apos;&apos; AND TF.VALOARE = Coalesce(P.Partener, PP.Partener))
          ELSE (SELECT COUNT(1) FROM NPART XP WHERE XP.CODPART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;) AND XP.CODCLASA = CP.CodClaseP)
        END &gt; 0&apos;;
    vFiltruPart := &apos; WHERE PP.COD_PART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE TML WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; AND TML.VALOARE = PP.COD_PART)&apos;;
 END IF;

  sGrpTMP := &apos;
  GROUP BY P.CodPromo&apos;;

  IF vGrupPart THEN
    sInsTmp2 := sInsTmp2||sGrpTMP;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    NrDoc, DataStart, DataEnd, Obs, Moneda,
    Tip,
    ExclAltePromo,
    In_functie_de,
    Influenteaza,
    Praguri,
    Tip_sediu_client,
    PeClasePart,
    Den_Part, Den_ClaseP, CIF, Autorizatie, RegCom, Den_Localit,
    ART, UM, CANT, PRET, PRETAMANUNT, DISC, ZILEC,
    TIPLIMITA,
    TG_MAX, ZILE_EXP, SERII,
    CADOU,
    ORDINE&apos;||gUserFields||&apos;)
  WITH TMP AS (
    SELECT
      P1.CODPROMO, P1.CODPROMO1, 0 CODCADOU, Coalesce(PP.CODPRAG, 0) CODPRAG,
      0 ORD1, CASE WHEN Coalesce(PP.CODPRAG, 0) = 0 THEN P1.CODPROMO1 ELSE PP.CODPRAG END ORD2,
      COALESCE(P1.CodObiect,0) CodObiect, Coalesce(P1.UMSec, 0) UMSec, P1.Cant, P1.Pret, P1.PretAmanunt,
      Coalesce(PP.ProcDisc, P1.ProcDisc) ProcDisc, P1.ZileC, P1.TipLimita, P1.TG_Max, P1.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1SER S WHERE S.CodPROMO1 = P1.CodPROMO1) Serii,
      TP.Subunitatea
    FROM TMP_LST_PROMO TP
      INNER JOIN PROMO P ON P.CodPromo = TP.CodPromo
      INNER JOIN PROMO1 P1 ON P1.CodPROMO = P.CodPROMO
      LEFT JOIN PROMOPRAG PP ON PP.CodPROMO = P.CodPROMO
    UNION ALL
    SELECT
      P1.CODPROMO, P1.CODPROMO1, PC.CODCADOU, 0 CODPRAG,
      0 ORD1, P1.CODPROMO1 ORD2,
      PC.CodObiect, Coalesce(PC.UMSec, 0) UMSec, PC.Cant, 0 Pret, 0 PretAmanunt,
      NULL ProcDisc, NULL ZileC, PC.TipLimita, PC.TG_Max, PC.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1CADOUSER S WHERE S.CodCADOU = PC.CodCADOU) Serii,
      TP.Subunitatea
    FROM TMP_LST_PROMO TP
      INNER JOIN PROMO P ON P.CodPromo = TP.CodPromo
      INNER JOIN PROMO1 P1 ON P1.CodPROMO = P.CodPROMO
      INNER JOIN PROMO1CADOU PC ON PC.CodPromo = P.CodPROMO AND PC.CodPROMO1 = CASE WHEN P.DEMANA IN (0,3) THEN P1.CodPROMO1 ELSE 0 END
    WHERE P.DEMANA IN (0,3)
    UNION ALL
    SELECT
      P.CODPROMO, 0 CODPROMO1, PC.CODCADOU, 0 CODPRAG,
      1 ORD1, 0 ORD2,
      PC.CodObiect, Coalesce(PC.UMSec, 0) UMSec, PC.Cant, 0 Pret, 0 PretAmanunt,
      NULL ProcDisc, NULL ZileC, PC.TipLimita, PC.TG_Max, PC.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1CADOUSER S WHERE S.CodCADOU = PC.CodCADOU) Serii,
      TP.Subunitatea
    FROM TMP_LST_PROMO TP
      INNER JOIN PROMO P ON P.CodPromo = TP.CodPromo
      INNER JOIN PROMO1CADOU PC ON PC.CodPromo = P.CodPROMO
    WHERE NOT P.DEMANA IN (0,3)
  )
  SELECT
    TMP.CodPromo, 56,
    P.NrDoc, P.DataStart, P.DataEnd, P.Obs, M.Simbol,
    CASE P.DeMana
      WHEN 0 THEN &apos;&apos;Articole individuale&apos;&apos;
      WHEN 1 THEN &apos;&apos;Pachet PROMO&apos;&apos;
      WHEN 2 THEN &apos;&apos;Optional PROMO&apos;&apos;
      WHEN 3 THEN &apos;&apos;Clase de articole&apos;&apos;
      WHEN 4 THEN &apos;&apos;Toate articolele&apos;&apos;
    END TIP,
    CASE WHEN P.ExclAltePromo = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END ExclAltePromo,
    CASE P.TipConditie
      WHEN 0 THEN &apos;&apos;neconditionat&apos;&apos;
      WHEN 1 THEN &apos;&apos;cantitate minima de livrare&apos;&apos;
      WHEN 2 THEN &apos;&apos;zile credit&apos;&apos;
      WHEN 3 THEN &apos;&apos;valoare minima de livrare&apos;&apos;
    END In_functie_de,
    CASE P.TipPromotie
      WHEN 1 THEN &apos;&apos;marime pret&apos;&apos;
      WHEN 2 THEN &apos;&apos;% discount&apos;&apos;
      WHEN 3 THEN &apos;&apos;articole promotionale (cadou)&apos;&apos;
      WHEN 4 THEN &apos;&apos;valoare discount&apos;&apos;
    END Influenteaza,
    CASE WHEN P.Praguri = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END Praguri,
    CASE P.TipServire
      WHEN 0 THEN &apos;&apos;orice sediu&apos;&apos;
      WHEN 1 THEN &apos;&apos;cu servire indirecta&apos;&apos;
      WHEN 2 THEN &apos;&apos;cu servire directa&apos;&apos;
    END Tip_sediu_client,
    CASE WHEN P.TipClaseP = 1 THEN &apos;&apos;Da&apos;&apos; ELSE &apos;&apos;Nu&apos;&apos; END PeClasePart,
    CASE WHEN P.TipClaseP = 1 THEN PP.Den_ClaseP ELSE PP.Den_Part END,
    PP.Den_ClaseP, PP.CIF, PP.Autorizatie, PP.RegCom, PP.Den_Localit,
    CASE
      WHEN P.DeMana = 3 AND TMP.CodCadou = 0 THEN CA.DEN_CLASEA
      WHEN P.DeMana = 4 AND TMP.CodCadou = 0 THEN &apos;&apos;Toate articolele&apos;&apos;
      ELSE O.Denumire
    END ART,
    UM.Den_UM1, TMP.Cant / UM.Paritate CANT, TMP.Pret * UM.Paritate PRET, TMP.PretAmanunt * UM.Paritate PRETAMANUNT, TMP.ProcDisc, TMP.ZileC,
    CASE TMP.TipLimita
      WHEN 3 THEN &apos;&apos;Serie&apos;&apos;
      WHEN 2 THEN &apos;&apos;Zile expirare &lt;= &apos;&apos;||TMP.Zile_Exp
      WHEN 1 THEN &apos;&apos;Data expirare &lt;= &apos;&apos;||To_Char(TMP.TG_Max,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      ELSE &apos;&apos;Stoc disponibil&apos;&apos;
    END TIPLIMITA,
    TMP.TG_Max, TMP.Zile_Exp, TMP.Serii,
    CASE WHEN TMP.CodCadou = 0 THEN &apos;&apos;Nu&apos;&apos; ELSE &apos;&apos;Da&apos;&apos; END CADOU,
    DENSE_RANK() OVER (PARTITION BY TMP.CodPromo ORDER BY TMP.ORD1, TMP.ORD2, TMP.CodCadou) ORDINE&apos;||gUserAlias||&apos;
  FROM TMP
    LEFT JOIN PROMO P ON P.CodPromo = TMP.CodPromo
    LEFT JOIN PROMO1 P1 ON P1.CodPromo1 = TMP.CodPromo1
    LEFT JOIN TMP_LST_PROMOPART PP ON PP.CodPromo = TMP.CodPromo
    LEFT JOIN NARTOBJ O ON O.CodObiect = TMP.CodObiect
    LEFT JOIN NART A ON A.CodArticol = O.CodArticol
    LEFT JOIN NUM1 UM ON UM.CodUM1 = TMP.UMSec
    LEFT JOIN NMONEDE M ON M.CodMoneda = P.Moneda
    LEFT JOIN NCLASEA CA ON CA.CodClaseA = CASE P.DeMana WHEN 3 THEN P1.CODCLASEA ELSE A.Clasa END&apos;||
    gSuplJoins || vFiltruPart;

  --PKG_GLOBALS.SetDebugMode(True);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_PROMO&apos;    , aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_PROMOPART&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsTmp1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsTmp2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sDelTmp1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdTmp1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert , aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_PROMO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_PROMODOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FA712B368066218D448DCABDF1EA1F1F9DAEBCC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_PROMODOC IS

  vCodPROMO  PROMO.CODPROMO%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodPROMO IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodPROMO := pCodPROMO;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  FOR v_rec IN (
    SELECT
      D.NrDoc, D.DataStart, D.DataEnd, D.CodLocatie, D.Obs, D.TipClaseP, M.Simbol,
      CASE D.DeMana
        WHEN 0 THEN &apos;Articole individuale&apos;
        WHEN 1 THEN &apos;Pachet PROMO&apos;
        WHEN 2 THEN &apos;Optional PROMO&apos;
        WHEN 3 THEN &apos;Clase de articole&apos;
        WHEN 4 THEN &apos;Toate articolele&apos;
      END TIP,
      CASE WHEN D.ExclAltePromo = 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END ExclAltePromo,
      CASE D.TipConditie
        WHEN 0 THEN &apos;neconditionat&apos;
        WHEN 1 THEN &apos;cantitate minima de livrare&apos;
        WHEN 2 THEN &apos;zile credit&apos;
        WHEN 3 THEN &apos;valoare minima de livrare&apos;
      END In_functie_de,
      CASE D.TipPromotie
        WHEN 1 THEN &apos;marime pret&apos;
        WHEN 2 THEN &apos;% discount&apos;
        WHEN 3 THEN &apos;articole promotionale (cadou)&apos;
        WHEN 4 THEN &apos;valoare discount&apos;
      END Influenteaza,
      CASE WHEN D.Praguri = 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END Praguri,
      CASE D.TipServire
        WHEN 0 THEN &apos;orice sediu&apos;
        WHEN 1 THEN &apos;cu servire indirecta&apos;
        WHEN 2 THEN &apos;cu servire directa&apos;
      END Tip_sediu_client,
      CASE WHEN D.TipClaseP = 1 THEN &apos;Da&apos; ELSE &apos;Nu&apos; END PeClasePart,
      Coalesce( PP.Den_Part,    P.Den_Part   ) AS Den_Part,
      PP.Den_ClaseP                            AS Den_ClaseP,
      Coalesce( PP.CIF,         PCF.CodFiscal) AS CIF,
      Coalesce( PP.Autorizatie, P.Autorizatie) AS Autorizatie,
      Coalesce( PP.RegCom,      P.RegCom)      AS RegCom,
      Coalesce( PP.Den_Localit, L.Den_Localit) AS Den_Localit,
      UT.UserName, Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI, US.TELEFON UTEL, US.EMAIL UEMAIL
    FROM Promo D
      LEFT JOIN NMONEDE M ON D.Moneda = M.CodMoneda
      LEFT JOIN NPARTCODFISC PCF ON D.CodFiscal = PCF.Cod_CodFiscal
      LEFT JOIN NPART P ON D.Partener = P.CodPart
      LEFT JOIN NAGENDA AG ON D.CodLocatie = AG.CodAgenda
      LEFT JOIN NLOCALIT L ON AG.CodLocalit = L.CodLocalit
      LEFT JOIN NPERS U ON U.LOGONNAME = D.USERID
      LEFT JOIN NAGENDA US ON US.CODAGENDA = U.AGENDA
  	  LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = D.USERID
      LEFT JOIN (
        SELECT
          D.CodPromo,
          vc2_nt_to_vc3200(set(CAST(COLLECT(P.Den_Part    ORDER BY d.codpromopart) AS vc2_nt))) Den_Part,
          vc2_nt_to_vc3200(set(CAST(COLLECT(CP.Den_ClaseP ORDER BY d.codpromopart) AS vc2_nt))) Den_ClaseP,
          vc2_nt_to_vc3200(set(CAST(COLLECT(PCF.CodFiscal ORDER BY d.codpromopart) AS vc2_nt))) CIF,
          vc2_nt_to_vc3200(set(CAST(COLLECT(P.Autorizatie ORDER BY d.codpromopart) AS vc2_nt))) Autorizatie,
          vc2_nt_to_vc3200(set(CAST(COLLECT(P.RegCom      ORDER BY d.codpromopart) AS vc2_nt))) RegCom,
          vc2_nt_to_vc3200(set(CAST(COLLECT(L.Den_Localit ORDER BY d.codpromopart) AS vc2_nt))) Den_Localit
        FROM  Promopart D
          LEFT JOIN NPARTCODFISC PCF ON D.CodFiscal = PCF.Cod_CodFiscal
          LEFT JOIN NPART P ON D.Partener = P.CodPart
          LEFT JOIN NAGENDA AG ON D.CodLocatie = AG.CodAgenda
          LEFT JOIN NLOCALIT L ON AG.CodLocalit = L.CodLocalit
          LEFT JOIN NCLASEP CP ON CP.CodClaseP = D.CodClaseP
        WHERE D.CodPromo = vCodPromo
        GROUP BY D.CodPromo
      ) PP ON PP.CodPromo = D.CodPromo


    WHERE D.CodPromo = vCodPromo
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT DE&apos;,                     v_rec.USERNAME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT NUME&apos;,                   v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT PRENUME&apos;,                v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT CNP&apos;,                    v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT BI&apos;,                     v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT TELEFON&apos;,                v_rec.UTEL);
    pkg_list_Struct.ADAUGA_PARAM(&apos;INTOCMIT EMAIL&apos;,                  v_rec.UEMAIL);

    pkg_list_Struct.ADAUGA_PARAM(&apos;Numar Promotie&apos;,                  v_rec.NrDoc);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Perioada de valabilitate&apos;,        To_Char(v_rec.DataStart,&apos;dd.mm.yyyy&apos;)||&apos; - &apos;||To_Char(v_rec.DataEnd,&apos;dd.mm.yyyy&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;,                      v_rec.Obs);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,                          v_rec.Simbol);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip&apos;,                             v_rec.Tip);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Exclus alte promotii&apos;,            v_rec.ExclAltePromo);
    pkg_list_Struct.ADAUGA_PARAM(&apos;In functie de&apos;,                   v_rec.In_functie_de);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Influenteaza&apos;,                    v_rec.Influenteaza);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Praguri&apos;,                         v_rec.Praguri);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Pe clase de parteneri&apos;,           v_rec.PeClasePart);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Tip sediu client&apos;,                v_rec.Tip_sediu_client);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener &apos;,                       v_rec.Den_Part);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener CUI&apos;,                    v_rec.CIF);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener Reg Com&apos;,                v_rec.RegCom);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener autorizatie&apos;,            v_rec.Autorizatie);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sediu partener&apos;,                  v_rec.Den_Localit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Clasa partener &apos;,                 v_rec.Den_ClaseP);

    EXIT;
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
BEGIN
  gSuplCols := &apos;PROMO P, PROMO1 P1, NARTOBJ O, NART A, NUM1 UM, NCLASEA CA&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,  &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos; );
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,  &apos;OATR&apos;,  &apos;OATR.CODOBIECT = O.CODOBIECT&apos; );
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMO1CADOU&apos;, &apos;PC&apos;,    &apos;PC.CODCADOU = TMP.CODCADOU&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMOPRAG&apos;,   &apos;PP&apos;,    &apos;PP.CODPRAG = TMP.CODPRAG&apos;,   1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ&apos;,     &apos;OC&apos;,    &apos;OC.CODOBIECT = PC.CODOBIECT&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PROMOSUB&apos;,    &apos;PS&apos;,    &apos;PS.CODPROMO = P.CODPROMO AND PS.SUBUNITATEA = COALESCE(P.SUBUNITATEA,PKG_GLOBALS.GETSUBUNITATE)&apos;,   1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,       &apos;PM&apos;,    &apos;PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = Coalesce(P.SUBUNITATEA,PKG_GLOBALS.GETSUBUNITATE) AND PM.IMPLICIT = 1&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART,
    UM, CANT, PRET, PRETAMANUNT, DISC, ZILEC,
    TIPLIMITA,
    TG_MAX, ZILE_EXP, SERII,
    CADOU,
    ORDINE&apos;||gUserFields||&apos;)
  WITH TMP AS (
    SELECT
      P1.CODPROMO, P1.CODPROMO1, 0 CODCADOU, Coalesce(PP.CODPRAG, 0) CODPRAG,
      0 ORD1, CASE WHEN Coalesce(PP.CODPRAG, 0) = 0 THEN P1.CODPROMO1 ELSE PP.CODPRAG END ORD2,
      COALESCE(P1.CodObiect,0) CodObiect, Coalesce(P1.UMSec, 0) UMSec, P1.Cant, P1.Pret, P1.PretAmanunt,
      Coalesce(PP.ProcDisc, P1.ProcDisc) ProcDisc, P1.ZileC, P1.TipLimita, P1.TG_Max, P1.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1SER S WHERE S.CodPROMO1 = P1.CodPROMO1) Serii
    FROM PROMO P
      INNER JOIN PROMO1 P1 ON P1.CodPROMO = P.CodPROMO
      LEFT JOIN PROMOPRAG PP ON PP.CodPROMO = P.CodPROMO
    WHERE P.CodPROMO = &apos;||vCodPromo||&apos;
    UNION ALL
    SELECT
      P1.CODPROMO, P1.CODPROMO1, PC.CODCADOU, 0 CODPRAG,
      0 ORD1, P1.CODPROMO1 ORD2,
      PC.CodObiect, Coalesce(PC.UMSec, 0) UMSec, PC.Cant, 0 Pret, 0 PretAmanunt,
      NULL ProcDisc, NULL ZileC, PC.TipLimita, PC.TG_Max, PC.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1CADOUSER S WHERE S.CodCADOU = PC.CodCADOU) Serii
    FROM PROMO P
      INNER JOIN PROMO1 P1 ON P1.CodPROMO = P.CodPROMO
      INNER JOIN PROMO1CADOU PC ON PC.CodPromo = P.CodPROMO AND PC.CodPROMO1 = P1.CodPROMO1
    WHERE P.CodPROMO = &apos;||vCodPromo||&apos;
      AND P.DEMANA IN (0,3)
    UNION ALL
    SELECT
      P.CODPROMO, 0 CODPROMO1, PC.CODCADOU, 0 CODPRAG,
      1 ORD1, 0 ORD2,
      PC.CodObiect, Coalesce(PC.UMSec, 0) UMSec, PC.Cant, 0 Pret, 0 PretAmanunt,
      NULL ProcDisc, NULL ZileC, PC.TipLimita, PC.TG_Max, PC.Zile_Exp,
      (SELECT vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) serii FROM PROMO1CADOUSER S WHERE S.CodCADOU = PC.CodCADOU) Serii
    FROM PROMO P
      INNER JOIN PROMO1CADOU PC ON PC.CodPromo = P.CodPROMO
    WHERE P.CodPROMO = &apos;||vCodPromo||&apos;
      AND NOT P.DEMANA IN (0,3)
  )
  SELECT
    CASE
      WHEN P.DeMana = 3 AND TMP.CodCadou = 0 THEN CA.DEN_CLASEA
      WHEN P.DeMana = 4 AND TMP.CodCadou = 0 THEN &apos;&apos;Toate articolele&apos;&apos;
      ELSE O.Denumire
    END ART,
    UM.Den_UM1, TMP.Cant / UM.Paritate CANT, TMP.Pret * UM.Paritate PRET, TMP.PretAmanunt * UM.Paritate PRETAMANUNT, TMP.ProcDisc, TMP.ZileC,
    CASE TMP.TipLimita
      WHEN 3 THEN &apos;&apos;Serie&apos;&apos;
      WHEN 2 THEN &apos;&apos;Zile expirare &lt;= &apos;&apos;||TMP.Zile_Exp
      WHEN 1 THEN &apos;&apos;Data expirare &lt;= &apos;&apos;||To_Char(TMP.TG_Max,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      ELSE &apos;&apos;Stoc disponibil&apos;&apos;
    END TIPLIMITA,
    TMP.TG_Max, TMP.Zile_Exp, TMP.Serii,
    CASE WHEN TMP.CodCadou = 0 THEN &apos;&apos;Nu&apos;&apos; ELSE &apos;&apos;Da&apos;&apos; END CADOU,
    DENSE_RANK() OVER (PARTITION BY TMP.CodPromo ORDER BY TMP.ORD1, TMP.ORD2, TMP.CodCadou) ORDINE&apos;||gUserAlias||&apos;
  FROM TMP
    LEFT JOIN PROMO P    ON P.CodPromo = TMP.CodPromo
    LEFT JOIN PROMO1 P1  ON P1.CodPromo1 = TMP.CodPromo1
    LEFT JOIN NARTOBJ O  ON O.CodObiect = TMP.CodObiect
    LEFT JOIN NART A     ON A.CodArticol = O.CodArticol
    LEFT JOIN NUM1 UM    ON UM.CodUM1 = TMP.UMSec
    LEFT JOIN NCLASEA CA ON CA.CodClaseA = CASE P.DeMana WHEN 3 THEN P1.CODCLASEA ELSE A.Clasa END&apos;||
    gSuplJoins;

  --PKG_GLOBALS.SetDebugMode(True);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  ADD_LIST_PARAMS;
  COMMIT;
END;

end PKG_LIST_BASE_PROMODOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DASHMAN_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7267C781C8A91E2AAF464B061963CCA3F7123D9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_DASHMAN_DOC IS

  vCodDoc     NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
     Cod,gest, data, Analiza, Cantitate, ZileRez, DurataMedie, RPD, VenitTotal)
  SELECT
   Cod,gest, data, Analiza, Decode(Cantitate,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(Cantitate,&apos;&apos;999,999,999.9&apos;&apos;)), Decode(ZileRez,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(ZileRez,&apos;&apos;999,999,999.9&apos;&apos;)),
   Decode(DurataMedie,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(DurataMedie,&apos;&apos;999,999,999.9&apos;&apos;)),Decode(RPD,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(RPD,&apos;&apos;999,999,999.9&apos;&apos;)),Decode(VenitTotal,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(VenitTotal,&apos;&apos;999,999,999.9&apos;&apos;))
  FROM RACDASHMAN_DOC ORDER BY COD asc&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


end PKG_LIST_BASE_RAC_DASHMAN_DOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DASHOP_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AEDCDE652069914F73E1CD14D20400690336134E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_DASHOP_DOC IS

  vCodDoc     NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    Cod,Gest,Data,Detaliu,Valoare)
  SELECT
  Cod,Gest,Data,Detaliu,Decode(Valoare,&apos;&apos;0&apos;&apos;,&apos;&apos;0.0&apos;&apos;,to_char(Valoare,&apos;&apos;999,999,999.9&apos;&apos;))
  FROM RACDASHOP_DOC ORDER BY COD asc&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


end PKG_LIST_BASE_RAC_DASHOP_DOC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E73134CC6B3F2ABCB5B60F79C63A2493895D2C28</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_DetInfo IS

  vCodDoc     NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,AnFab,KmBord,Comb,DataBord,Status)
  SELECT
  Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,AnFab,KmBord,Comb,DataBord,Status
  FROM TMP_RACDetaliereInfo ORDER BY COD asc&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


end PKG_LIST_BASE_RAC_DetInfo; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3983AC8415695CF8FBAB987EA26FA9482CD68C8F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_DetInfoG IS

  vCodDoc     NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,DataSosire,Status)
  SELECT
  Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,DataSosire,Status
  FROM TMP_RACDetaliereInfoG ORDER BY COD asc&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;


end PKG_LIST_BASE_RAC_DetInfoG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_DETINFOLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C4BC87C5A6B7A49D8FC8AC12F6CBE70C659502E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_DetInfoLG is

vCodDoc NUMBER(20);

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,DataSosire,Status)
  SELECT
  Cod,Subunitate, Gestiune, Locatie, Clasa, NRAuto,Marca,Model,DataSosire,Status
  FROM RACDetaliereInfoG ORDER BY COD asc&apos; ;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_RAC_DetInfoLG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINILIBERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17F5BC664EE4DA2BC07070EABE15D08A67F30521</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_rac_masinilibere IS

sZi1 VARCHAR2(50);
sZi2 VARCHAR2(50);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE)
IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
          GESTCURENTA ,
          GESTINITIALA,
          NRMASINA    ,
          MARCA       ,
          MODEL       ,
          GRECHIV     , judet
)&apos;;

  sSelect :=
&apos;  Select
        VA.DEN_GEST,
        VP.DEN_GEST,
        VP.NRINREG,
        VP.MARCAAUTO,
        VP.MODELAUTO,
        GE.Denumire,
        coalesce(J.SIMBAUTO,&apos;&apos;?&apos;&apos;) Judet
  from v_nparcaut VP
  inner join GrEchiv GE  on GE.CODGRECHIV = VP.CodGrupa
  inner join (Select NG.DEN_GEST, X.CODGEST, X.CodAuto, X.Q
                from (Select CodAuto, CodGest, Sum(Q) Q
                        from V_AUTO
                      group by CodAuto, CodGest) X
                INNER JOIN NGest NG on NG.CODGEST = NVL(X.CODGEST,0)
              where Q &gt; 0) VA on VP.codnparcaut = VA.CodAuto
    left join NAGENDA Ax on Nvl(Ax.CodGest,0) = VA.CODGEST
    left join NLocalit Lx on Lx.CodLocalit = Ax.Codlocalit
    left join NJudet J on J.CodJudet = Lx.CodJudet
  where Nvl(VP.Generic, 0) = 0 and VP.Inactiv=0
    and VA.codAuto &gt; 0
    and not VA.codAuto in
          ( select Cod from 
					  ( select Nvl(C.MijlTransp, 0) Cod, trunc(R.DataStart) DataStart, 
							Case when Nvl(R.Predat,0) = 0 then trunc(R.DataStop) else Least(Trunc(R.DataPred), Trunc(R.DataStop))	end  DataStop
							from Comanda c
								inner join RAC_REZ R on R.codcomanda = c.codcomanda
								where c.tipdoc = 94
									and Nvl(C.MijlTransp, 0) &gt; 0
									and Nvl(C.Operat, 0) = 1
									and Nvl(C.Inchisa, 0) = 0
						) where ((PKG_LIST_ALEGPERIOADA.getDataS between DataStart and DataStop)
                or PKG_LIST_ALEGPERIOADA.getDataF between DataStart and DataStop)
                or DataStart between PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
                or DataStop  between PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF)&apos;;
  PKG_RAC_REZ.SET_RAC_DATASTART(PKG_LIST_ALEGPERIOADA.getDataS);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;


END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RAC_MASINILIBERE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINIOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD4FED6E64A85C58EC34BD0B94E27F004C23B7EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAC_MASINIOC IS

sZi1 VARCHAR2(50);
sZi2 VARCHAR2(50);
gUserFields VARCHAR2(5000);
gUserAlias  VARCHAR2(5000);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(25000);
gSuplJoins  VARCHAR2(10000);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE)
IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sALMin  VARCHAR2(100):= Extract(Year from PKG_LIST_ALEGPERIOADA.getDataS)*12+Extract(Month from PKG_LIST_ALEGPERIOADA.getDataS);
  sALMax  VARCHAR2(100):= Extract(Year from PKG_LIST_ALEGPERIOADA.getDataF)*12+Extract(Month from PKG_LIST_ALEGPERIOADA.getDataF);
  sZIMin  VARCHAR2(100):= Extract(DAY from PKG_LIST_ALEGPERIOADA.getDataS);
  sZIMax  VARCHAR2(100):= Extract(DAY from PKG_LIST_ALEGPERIOADA.getDataF);
BEGIN
  gSuplCols := &apos;NGEST G, COMANDA C, RAC_REZ R, NPARCAUT P, CONTRACT CC, NPART NP&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);  

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
     NAV_CodDoc, NAV_TipDoc, REZERVARE, AN, LUNA, ZI, Judet,
     CUSTOMER,
     SHUTTLE,
     COURTESY,
     UZINTERN,
     REPARATII,
     ABONAMENT,
     TRANSFER,
     DATA, GESTIUNE, SUBUNITATE, MARCA, MODEL, CLASA, MaxRezSimultan,
     Partener,
     Contract &apos;||gUserFields||&apos;)&apos;;

--  sSelect := &apos;
--  WITH q(Codcomanda, TipRezervare, NIVEL, DATA) as (
--		SELECT R.Codcomanda, R.TipRezervare, 1 NIVEL, CAST(Trunc(R.DATASTART) AS DATE) DATA
--		FROM RAC_REZ R
--		UNION ALL
--		SELECT R.Codcomanda, R.TipRezervare, Q.NIVEL + 1, CAST(Trunc(R.DATASTART+Q.NIVEL) AS DATE)
--		FROM RAC_REZ R, q
--		WHERE R.Codcomanda = q.Codcomanda AND Q.DATA &lt; Trunc(R.DATASTART) + Q.NIVEL
--		AND Trunc(R.DATASTART) + Q.NIVEL &lt;= Case when Nvl(R.Predat,0) = 0 then Trunc(R.DATASTOP) else Least(Trunc(R.DATASTOP), Trunc(R.DATAPRED)) end
--  ),
--  t as (
--    SELECT
--      q.Codcomanda, q.TipRezervare, q.NIVEL, q.DATA,
--      Extract(Year from q.Data) An,
--      Extract(Month from q.Data) Luna,
--      Extract(Day from q.Data) Zi
--    FROM q
--  )
--  SELECT
--    C.CodComanda, C.TipDoc, C.Seriadoc||C.Nrdoc Rezervare, t.An, t.Luna, t.Zi, J.SimbAuto Judet,
--    Decode(t.TipRezervare, 0, 1, 0) Customer,
--    Decode(t.TipRezervare, 1, 1, 0) Shuttle,
--    Decode(t.TipRezervare, 3, 1, 0) Courtesy,
--    Decode(t.TipRezervare, 4, 1, 0) UzIntern,
--    Decode(t.TipRezervare, 5, 1, 0) Reparatii,
--    Decode(t.TipRezervare, 6, 1, 0) Abonament,
--    Decode(t.TipRezervare, 7, 1, 0) Transfer,
--    t.DATA, G.DEN_GEST Gestiune, S.Den_subunit Subunitate, Coalesce(Ma.Marca, &apos;&apos;?&apos;&apos;) Marca, Coalesce(Mo.Model, &apos;&apos;?&apos;&apos;) Model, Gr.DENUMIRE Clasa, Cc.Maxreplsimultane,
--    CASE WHEN t.TipRezervare IN (0,1,3,6) THEN NP.DEN_PART else &apos;&apos;-&apos;&apos; END,
--    Cc.Seriadoc||CC.Nrdoc||&apos;&apos;/&apos;&apos;||Cc.DataDoc Contract
--  FROM t
--    inner join comanda  c on c.codcomanda  = t.codcomanda
--    inner join Rac_Rez  r on r.codcomanda  = c.codcomanda
--    inner join NParcAut P on P.CODNPARCAUT = Coalesce(C.MijlTransp, 0)
--    inner join NEchiv   E on E.Codobiect   = P.CodArt
--    inner join GrEchiv Gr on Gr.CODGRECHIV = E.CodGrupa
--    inner join NGest   G  on G.codGest     = R.CodGestSursa
--    inner join NAGENDA A on Coalesce(A.CodGest,0) = G.CODGEST
--    inner join NLocalit L on L.CodLocalit = A.Codlocalit
--    inner join NJudet J on J.CodJudet = L.CodJudet
--    inner join Nsubunit S on S.codSubunit = G.CodSubunit
--    left  join Contract Cc on Cc.CodContract = Coalesce(C.CodContract,0)
--    left  join NPart NP on Np.CodPart = Coalesce(C.Partener,0)
--    left  join Nmodeleauto Mo  on Mo.CODMODELEAUTO = Coalesce(p.Model,0)
--    left  join Nmarciauto  Ma  on Ma.CODMarciAuto  = Coalesce(p.Marca,0)
--  WHERE c.tipdoc = 94  and Coalesce(C.Mijltransp,0) &gt; 0 and Coalesce(E.Generic,0) = 0
--    and t.An*12+t.LUNA between &apos;||sALMin||&apos; and &apos;||sALMax||&apos;
--    and t.zi between &apos;||sZIMin||&apos; and &apos;||sZIMax;

  sSelect := &apos;
  WITH q(CodGestSursa, Codcomanda, TipRezervare, NIVEL, DATA) as (
		SELECT R.CodGestSursa, R.Codcomanda, R.TipRezervare, 1 NIVEL, CAST(Trunc(R.DATASTART) AS DATE) DATA
		FROM RAC_REZ R
      INNER JOIN comanda  c on c.codcomanda  = r.codcomanda
      INNER JOIN NParcAut P on P.CODNPARCAUT = Coalesce(C.MijlTransp, 0)
      INNER JOIN NEchiv   E on E.Codobiect   = P.CodArt
    WHERE c.tipdoc = 94 and Coalesce(C.Mijltransp,0) &gt; 0 and Coalesce(E.Generic,0) = 0
      AND R.DATASTART &lt;= PKG_LIST_ALEGPERIOADA.getDataF
      AND R.DATASTOP  &gt;= PKG_LIST_ALEGPERIOADA.getDataS
		UNION ALL
		SELECT R.CodGestSursa, R.Codcomanda, R.TipRezervare, Q.NIVEL + 1, CAST(Trunc(R.DATASTART+Q.NIVEL) AS DATE)
		FROM RAC_REZ R, q
		WHERE R.Codcomanda = q.Codcomanda AND Q.DATA &lt; Trunc(R.DATASTART) + Q.NIVEL
		AND Trunc(R.DATASTART) + Q.NIVEL &lt;= Case when Nvl(R.Predat,0) = 0 then Trunc(R.DATASTOP) else Least(Trunc(R.DATASTOP), Trunc(R.DATAPRED)) end
  )
  SELECT
    C.CodComanda, C.TipDoc, C.Seriadoc||C.Nrdoc Rezervare, 
    Extract(Year  FROM z.Ziua) An,
    Extract(Month FROM z.Ziua) Luna,
    Extract(Day   FROM z.Ziua) Zi,
    J.SimbAuto Judet,
    Decode(q.TipRezervare, 0, 1, 0) Customer,
    Decode(q.TipRezervare, 1, 1, 0) Shuttle,
    Decode(q.TipRezervare, 3, 1, 0) Courtesy,
    Decode(q.TipRezervare, 4, 1, 0) UzIntern,
    Decode(q.TipRezervare, 5, 1, 0) Reparatii,
    Decode(q.TipRezervare, 6, 1, 0) Abonament,
    Decode(q.TipRezervare, 7, 1, 0) Transfer,
    z.Ziua DATA, G.DEN_GEST Gestiune, S.Den_subunit Subunitate, Coalesce(Ma.Marca, &apos;&apos;?&apos;&apos;) Marca, Coalesce(Mo.Model, &apos;&apos;?&apos;&apos;) Model, Gr.DENUMIRE Clasa, Cc.Maxreplsimultane,
    CASE WHEN q.TipRezervare IN (0,1,3,6) THEN NP.DEN_PART else &apos;&apos;-&apos;&apos; END,
    Cc.Seriadoc||CC.Nrdoc||&apos;&apos;/&apos;&apos;||Cc.DataDoc Contract &apos;||gUserAlias||&apos;
  FROM ngest g
    CROSS JOIN tmp_zile z
    INNER JOIN q ON q.CodGestSursa = g.CodGest AND q.Data = z.Ziua
    INNER JOIN comanda  c on c.codcomanda  = q.codcomanda
    LEFT  JOIN Rac_Rez  r on r.codcomanda  = c.codcomanda
    LEFT  JOIN NParcAut P on P.CODNPARCAUT = Coalesce(C.MijlTransp, 0)
    LEFT  JOIN NEchiv   E on E.Codobiect   = P.CodArt
    LEFT  JOIN GrEchiv Gr on Gr.CODGRECHIV = E.CodGrupa
    LEFT  JOIN NAGENDA A on Coalesce(A.CodGest,0) = G.CODGEST
    LEFT  JOIN NLocalit L on L.CodLocalit = A.Codlocalit
    LEFT  JOIN NJudet J on J.CodJudet = L.CodJudet
    LEFT  JOIN Nsubunit S on S.codSubunit = G.CodSubunit
    LEFT  JOIN Contract Cc on Cc.CodContract = Coalesce(C.CodContract,0)
    LEFT  JOIN NPart NP on Np.CodPart = Coalesce(C.Partener,0)
    LEFT  JOIN Nmodeleauto Mo  on Mo.CODMODELEAUTO = Coalesce(p.Model,0)
    LEFT  JOIN Nmarciauto  Ma  on Ma.CODMarciAuto  = Coalesce(p.Marca,0)&apos;||gSuplJoins;

  PKG_RAC_REZ.SET_RAC_DATASTART(PKG_LIST_ALEGPERIOADA.getDataS);
  --pkg_globals.SetDebugMode(true);
  UMPLE_TMP_ZILE(PKG_LIST_ALEGPERIOADA.getDataS, PKG_LIST_ALEGPERIOADA.getDataF);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RAC_MASINIOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAC_MASINIOC_CE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57A82295A75C272108B00017ADDFA18B587C6001</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_rac_masinioc_ce IS

sZi1 VARCHAR2(50);
sZi2 VARCHAR2(50);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE)
IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;



PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
  sALMin  VARCHAR2(100):= Extract(Year from PKG_LIST_ALEGPERIOADA.getDataS)*12+Extract(Month from PKG_LIST_ALEGPERIOADA.getDataS);
  sALMax  VARCHAR2(100):= Extract(Year from PKG_LIST_ALEGPERIOADA.getDataF)*12+Extract(Month from PKG_LIST_ALEGPERIOADA.getDataF);
  sZIMin  VARCHAR2(100):= Extract(DAY from PKG_LIST_ALEGPERIOADA.getDataS);
  sZIMax  VARCHAR2(100):= Extract(DAY from PKG_LIST_ALEGPERIOADA.getDataF);

BEGIN
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
          AN        ,
          LUNA      ,
          ZI        ,
          DATA            ,
          GESTIUNE        ,
          SUBUNITATE      ,
          MARCA           ,
          MODEL           ,
          CLASA           ,
					Judet           ,
          CUSTOMER        ,
          SHUTTLE         ,
          COURTESY        ,
          UZINTERN        ,
          REPARATII       ,
          ABONAMENT       ,
          TRANSFER )&apos;;

  sSelect :=&apos;
  WITH q(Codcomanda, TipRezervare, NIVEL, DATA) as (
		SELECT R.Codcomanda, R.TipRezervare, 1 NIVEL, CAST(Trunc(R.DATASTART) AS DATE) DATA
		FROM RAC_REZ R
		UNION ALL
		SELECT R.Codcomanda, R.TipRezervare, Q.NIVEL + 1, CAST(Trunc(R.DATASTART+Q.NIVEL) AS DATE)
		FROM RAC_REZ R, q
		WHERE R.Codcomanda = q.Codcomanda AND Q.DATA &lt; Trunc(R.DATASTART) + Q.NIVEL 
		AND Trunc(R.DATASTART) + Q.NIVEL &lt;= Case when Nvl(R.Predat,0) = 0 then Trunc(R.DATASTOP) else Least(Trunc(R.DATASTOP), Trunc(R.DATAPRED)) end
		),
  t as (
    SELECT
      q.Codcomanda, q.TipRezervare, q.NIVEL, q.DATA,
      Extract(Year from q.Data) An,
      Extract(Month from q.Data) Luna,
      Extract(Day from q.Data) Zi
    FROM q
  )
  Select An, Luna, Zi, Data, Gestiune, Subunitate, Marca, Model, Clasa, Judet,
    Sum( Customer ) Customer ,
    Sum( Shuttle  ) Shuttle  ,
    Sum( Courtesy ) Courtesy ,
    Sum( UzIntern ) UzIntern ,
    Sum( Reparatii) Reparatii,
    Sum( Abonament) Abonament,
    Sum( Transfer ) Transfer
  FROM(
    Select t.An, t.Luna, t.Zi,
      Decode(t.TipRezervare, 0, 1, 0) Customer,
      Decode(t.TipRezervare, 1, 1, 0) Shuttle,
      Decode(t.TipRezervare, 3, 1, 0) Courtesy,
      Decode(t.TipRezervare, 4, 1, 0) UzIntern,
      Decode(t.TipRezervare, 5, 1, 0) Reparatii,
      Decode(t.TipRezervare, 6, 1, 0) Abonament,
      Decode(t.TipRezervare, 7, 1, 0) Transfer,
      t.DATA, G.DEN_GEST Gestiune, S.Den_subunit Subunitate, Coalesce(Ma.Marca, &apos;&apos;?&apos;&apos;) Marca, Coalesce(Mo.Model, &apos;&apos;?&apos;&apos;) Model,
      Gr.DENUMIRE Clasa, J.SIMBAUTO Judet
    from t
      inner join comanda  c on c.codcomanda  = t.codcomanda
      inner join Rac_Rez  r on r.codcomanda  = c.codcomanda
      inner join NParcAut P on P.CODNPARCAUT = Coalesce(C.MijlTransp, 0)
      inner join NEchiv   E on E.Codobiect   = P.CodArt
      inner join GrEchiv Gr on Gr.CODGRECHIV = E.CodGrupa
      inner join NGest   G  on G.codGest     = R.CodGestSursa
      inner join NAGENDA A on Coalesce(A.CodGest,0) = G.CODGEST
      inner join NLocalit L on L.CodLocalit = A.Codlocalit
      inner join NJudet J on J.CodJudet = L.CodJudet
      inner join Nsubunit S on S.codSubunit = G.CodSubunit
      left  join Nmodeleauto Mo  on Mo.CODMODELEAUTO = Coalesce(p.Model,0)
      left  join Nmarciauto  Ma  on Ma.CODMarciAuto  = Coalesce(p.Marca,0)
    where c.tipdoc = 94  and Coalesce(C.Mijltransp,0) &gt; 0 and Coalesce(E.Generic,0) = 0
      and t.An*12+t.LUNA between &apos;||sALMin||&apos; and &apos;||sALMax||&apos;
      and t.zi between &apos;||sZIMin||&apos; and &apos;||sZIMax||&apos;
  ) 
  GROUP BY An, Luna, Zi, Data, Gestiune, Subunitate, Marca, Model, Clasa, Judet&apos;;

  PKG_RAC_REZ.SET_RAC_DATASTART(PKG_LIST_ALEGPERIOADA.getDataS);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RAC_MASINIOC_CE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPCONSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD1D4D5B9D130B936698BC043AC60EFF7A7B74DB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPCONSPROD is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vAnLuna     number(10);
  vAllArt     number(1);
  vCodComanda number(20); 

procedure SetParams(aAnLuna in number default 0, aAllArt in number default 0, aCodComanda in number default 0) is
begin
  vAnLuna := aAnLuna;
  vAllArt := aAllArt;
  vCodComanda := aCodComanda;
end;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;NARTOBJ PROD, NART APROD, NUM UM, NARTOBJ SEMIF, NARTOBJ MAT, NART AMAT, NUM UMM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  delete MANEVRA_CONSUM;
  UmplePredariSiConsumuri;
  CreazaStructTeoretica;
  if vCodComanda &gt; 0 then
    MERGE INTO MANEVRA_CONSUM C
    USING (
           select i1.codobiect produs, sum(i1.cant) cant_prod
           from nartobj prod
                inner join intrari1 i1 on i1.codobiect = prod.codobiect
                inner join intrari i on i1.codintr = i.codintr
           where i1.codcmdint1 in (select codcomanda1 from comanda1 where codcomanda = vCodComanda)
           group by i1.codobiect      
           ) N
    ON (C.PRODUS = N.PRODUS)
    WHEN MATCHED THEN UPDATE SET C.CANT_PROD = NVL(C.CANT_PROD,0) + N.CANT_PROD;
  else
    MERGE INTO MANEVRA_CONSUM C
    USING (
           select i1.codobiect produs, sum(i1.cant) cant_prod
           from nartobj prod
                inner join intrari1 i1 on i1.codobiect = prod.codobiect
                inner join intrari i on i1.codintr = i.codintr
           where (exists (select valoare from tmp_manevra_liste where valoare = prod.codobiect and filtru = &apos;CODOBIECT&apos;)
                  OR (vAllArt = 1 and prod.produspropriu = 2)) 
                 and i.tipdoc = 7 and nvl(i.anulat,0) = 0 and i.operat = 1
                 and i.an*12 + i.luna = vAnLuna
           group by i1.codobiect      
           ) N
    ON (C.PRODUS = N.PRODUS)
    WHEN MATCHED THEN UPDATE SET C.CANT_PROD = NVL(C.CANT_PROD,0) + N.CANT_PROD;
  end if;  
  
  delete manevra_consum where nvl(cant_prod,0) = 0;
  
  sInsert:=
    &apos;INSERT INTO &apos;||tmpName||&apos;

     (
      PRODUS,
      P_CODEXTERN,
      UM_AMB,
      COEF_UM_AMB,
      SEMIF,
      S_CODEXTERN,
      MATERIAL,
      M_CODEXTERN,
      UM_MAT,
      CANT_MAT,
      PRET_MAT,
      VAL_MAT,
      CANT_PROD,
      CONSUM_MAT,
      MEDIE_MAT,
      PRET_REAL_MAT,
      VAL_REAL_MAT,
      S_IDX &apos;||gUserFields||&apos;)
      select
        PROD.DENUMIRE,
        PROD.CODEXTERN,
        UM.DEN_UM UM_AMB,
        UM.COEF COEF_UM_AMB,
        SEMIF.DENUMIRE SEMIF,
        SEMIF.CODEXTERN S_CODEXTERN,
        MAT.DENUMIRE MATERIAL,
        MAT.CODEXTERN M_CODEXTERN,
        UMM.DEN_UM UM_MAT,
        MC.CANTRET CANT_MAT,
        MC.VALRET / MC.CANTRET PRET_MAT,
        MC.VALRET VAL_MAT,
        MC.CANT_PROD,
        MC.CANT CONSUM_MAT,
        MC.CANT / MC.CANT_PROD MEDIE_MAT,
        CASE WHEN MC.CANT = 0 THEN 0 ELSE MC.VALOARE / MC.CANT END PRET_REAL_MAT,
        MC.VALOARE VAL_REAL_MAT,
        MC.S_IDX &apos;||gUserAlias||&apos;
      FROM MANEVRA_CONSUM MC
           INNER JOIN NARTOBJ PROD ON MC.PRODUS = PROD.CODOBIECT
           INNER JOIN NART APROD ON APROD.CODARTICOL = PROD.CODARTICOL 
           INNER JOIN NUM UM ON UM.CODUM = APROD.UM
           INNER JOIN NARTOBJ SEMIF ON MC.NODPARINTE = SEMIF.CODOBIECT
           INNER JOIN NARTOBJ MAT ON MAT.CODOBIECT = MC.CODOBIECT
           INNER JOIN NART AMAT ON MAT.CODARTICOL = AMAT.CODARTICOL
           INNER JOIN NUM UMM ON UMM.CODUM = AMAT.UM
           &apos;||gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

procedure BagaMaterialeSemi(aProdus in number, aNodParinte in number, aParitate in number, aCodComanda1 in number) is
begin
  if aParitate &lt; 0.0000001 then return; end if;
  for v_rec in (with man_cons as (
                    select aProdus produs, 
                           ies1.codobiect material, 
                           l1.cant, 
                           nvl(ns1.pretmat,0) * l1.cant valoare, 
                           ns1.tipdoc, 
                           nvl(ii1.codcmdint1,0) codcmdint1,
                           ies1.codies1,
                           l1.codlivr1,
                           ns.codnirstoc codnirstocpred,
                           nvl(it1.cant,0) cantpred,
                           it1.codintr1,
                           case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                    from iesiri1 ies1
                         inner join iesiri ies on ies1.codies = ies.codies
                         inner join livr1 l1 on l1.codies1 = ies1.codies1
                         inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                         inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                         left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                         left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                         left join intrprodlink lk on lk.codintr1 = it1.codintr1
                         left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                    where ies.operat = 1 and nvl(ies.anulat,0) = 0 and ns1.tipdoc = 7 and prod.tip = 0
                           and ies1.codcmdint1 = aCodComanda1
                  ),
                  man_cons_mat as (
                    select aProdus produs, 
                           ies1.codobiect material, 
                           l1.cant, 
                           nvl(ns1.pretmat,0) * l1.cant valoare, 
                           ns1.tipdoc, 
                           0 codcmdint1,
                           ies1.codies1,
                           l1.codlivr1,
                           ns.codnirstoc codnirstocpred,
                           nvl(it1.cant,0) cantpred,
                           it1.codintr1,
                           case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                    from iesiri1 ies1
                         inner join iesiri ies on ies1.codies = ies.codies
                         inner join livr1 l1 on l1.codies1 = ies1.codies1
                         inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                         inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                         left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                         left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                         left join intrprodlink lk on lk.codintr1 = it1.codintr1
                         left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                    where ies.operat = 1 and nvl(ies.anulat,0) = 0 and not (ns1.tipdoc = 7 and nvl(prod.tip,-1) = 0)
                           and ies1.codcmdint1 = aCodComanda1
                )
                select produs, material, sum(cant * aparitate) cant, sum(valoare * aparitate) valoare, codcmdint1,
                         totcons, totval, totpred, tip, codlivr1 
                  from (
                    select distinct man_cons_mat.produs, man_cons_mat.material, man_cons_mat.cant, man_cons_mat.valoare, man_cons_mat.codcmdint1,
                           tot_cons.cant totcons, tot_cons.valoare totval, 0 totpred, man_cons_mat.tip, man_cons_mat.codlivr1       
                    from man_cons_mat
                         inner join nartobj obj on obj.codobiect = man_cons_mat.material
                         inner join (select sum(cant) cant, material, produs, codcmdint1, tip, sum(valoare) valoare
                                     from (select distinct cant, codlivr1, material, produs, codcmdint1, tip, valoare from man_cons_mat)
                                     group by material, produs, codcmdint1, tip) 
                                     tot_cons on tot_cons.material = man_cons_mat.material and 
                                                 tot_cons.produs = man_cons_mat.produs and
                                                 tot_cons.codcmdint1 = man_cons_mat.codcmdint1 and
                                                 tot_cons.tip = man_cons_mat.tip
                    union all
                    select distinct man_cons.produs, man_cons.material, man_cons.cant, man_cons.valoare, case when man_cons.tip = 1 then man_cons.codcmdint1 else 0 end codcmdint1,
                           tot_cons.cant totcons, tot_cons.valoare totval, nvl(tot_pred.total,0) totpred, man_cons.tip, 0 codlivr1       
                    from man_cons
                         inner join nartobj obj on obj.codobiect = man_cons.material
                         inner join (select sum(cant) cant, material, produs, codcmdint1, tip, sum(valoare) valoare
                                     from (select distinct cant, codlivr1, material, produs, codcmdint1, tip, valoare from man_cons)
                                     group by material, produs, codcmdint1, tip) 
                                     tot_cons on tot_cons.material = man_cons.material and 
                                                 tot_cons.produs = man_cons.produs and
                                                 tot_cons.codcmdint1 = man_cons.codcmdint1 and
                                                 tot_cons.tip = man_cons.tip
                         left join (select sum(cantpred) total, material, produs, codcmdint1, tip 
                                     from (
                                           select distinct produs, material, codcmdint1, cantpred, codintr1, tip
                                           from man_cons where tipdoc = 7 AND TIP = 1
                                           )
                                     group by produs, material, codcmdint1, tip
                                     ) tot_pred on tot_pred.produs = man_cons.produs and 
                                                   tot_pred.material = man_cons.material and
                                                   tot_pred.codcmdint1 = man_cons.codcmdint1 and
                                                   tot_pred.tip = man_cons.tip
                       )                            
                  group by produs, material, codcmdint1, totcons, totpred, tip, totval, codlivr1 
                ) loop
    /*if v_rec.material = 2256 then
      insert into x(test) values(&apos;codcomanda1:&apos;||acodcomanda1);
    end if;
    /*  insert into tmp_xxx
      with 
                man_cons as (
                  select 
                         aProdus produs,
                         ies1.codobiect material, 
                         l1.cant cant, 
                         ies1.pu * l1.cant valoare, 
                         ns1.tipdoc, 
                         ns1.codnirstocorig codnirstoc,
                         ies1.codies1,
                         l1.codlivr1,
                         NVL(ii1.codcmdint1,0) CODCMDINT1,
                         nvl(it1.cant,0) cantpred,
                         it1.codintr1,
                         obj.denumire,
                         case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                  from iesiri1 ies1
                       inner join iesiri ies on ies1.codies = ies.codies
                       inner join livr1 l1 on l1.codies1 = ies1.codies1
                       inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                       inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                       inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                       inner join nartobj obj on obj.codobiect = ies1.codobiect
                       left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                       left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                       left join intrprodlink lk on lk.codintr1 = it1.codintr1
                       left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                  where ies.operat = 1 and nvl(ies.anulat,0) = 0 and ies1.codcmdint1 = aCodComanda1
                )
                select man_cons.material, sum(man_cons.cant * aParitate) cant, sum(man_cons.valoare * aParitate) valoare,
                       nvl(mat.tip,3) tipmat, man_cons.codcmdint1,
                       tot_cons.cant totcons, tot_cons.valoare totval, nvl(tot_pred.total,0) totpred, man_cons.tip
                from man_cons
                     inner join nartobj obj on obj.codobiect = man_cons.material
                     inner join (select sum(valoare) valoare, sum(cant) cant, material, produs, codcmdint1 
                                 from (select distinct cant, codlivr1, material, produs, codcmdint1, valoare from man_cons)
                                 group by material, produs, codcmdint1) 
                                   tot_cons on tot_cons.material = man_cons.material and 
                                               tot_cons.produs = man_cons.produs and
                                               tot_cons.codcmdint1 = man_cons.codcmdint1
                     left join (select sum(cantpred) total, material, produs, codcmdint1 
                                from (
                                       select distinct produs, material, codcmdint1, cantpred, codintr1
                                       from man_cons where tipdoc = 7
                                      )
                                group by produs, material, codcmdint1
                               ) tot_pred on tot_pred.produs = man_cons.produs and 
                                             tot_pred.material = man_cons.material and
                                             tot_pred.codcmdint1 = man_cons.codcmdint1
                     left join iesprodlink iesl on iesl.codies1 = man_cons.codies1
                     left join cmdprodmat mat on mat.codcmdprodmat = iesl.codcmdprodmat
                     left join prodmat pmat on pmat.codmat = mat.codprodmat
                     left join comanda1 c1 on c1.codcomanda1 = man_cons.codcmdint1
                     left join comanda c on c1.codcomanda = c.codcomanda
                group by man_cons.produs, man_cons.material, nvl(mat.tip,3), man_cons.codcmdint1, tot_cons.cant, tot_cons.valoare, nvl(tot_pred.total,0),
                         man_cons.tip;
      commit;                   
    end if;*/
    if v_rec.codcmdint1 &gt; 0 and v_rec.tip = 1 then 
      BagaMaterialeSemi(aprodus, v_rec.material, aParitate * v_rec.totcons/v_rec.totpred, v_rec.codcmdint1);
    else
      MERGE INTO MANEVRA_CONSUM C
      USING (
             SELECT   
               aProdus Produs, aNodParinte NodParinte, V_REC.MATERIAL MATERIAL, V_REC.cant CANT, V_REC.valoare VALOARE, v_rec.totcons TOTCONS, v_rec.totval TOTVAL
             FROM DUAL
             ) N
      ON (C.CODOBIECT = N.MATERIAL and C.NODPARINTE = N.NODPARINTE and C.PRODUS = N.PRODUS)
      WHEN NOT MATCHED THEN INSERT (CODOBIECT, VALOARE, CANT, NODPARINTE, PRODUS)
                                    VALUES 
                                   (N.MATERIAL, N.VALOARE, N.CANT, N.NODPARINTE, N.PRODUS)
      WHEN MATCHED THEN UPDATE SET C.CANT = nvl(C.CANT,0) + N.CANT, C.VALOARE = NVL(C.VALOARE,0) + N.VALOARE;
    end if;
  end loop;
end;

procedure UmplePredariSiConsumuri is
begin
  DELETE MANEVRA_CONSUM;
  DELETE OBJ_CMDINT1;
  if vCodComanda &gt; 0 then
    INSERT INTO OBJ_CMDINT1(CODCMDINT1, CODOBIECT)
    select distinct i1.codcmdint1, i1.codobiect
    from intrari1 i1 
    where i1.codcmdint1 in (select codcomanda1 from comanda1 where codcomanda = vCodComanda);
  else
    INSERT INTO OBJ_CMDINT1(CODCMDINT1, CODOBIECT)
    select /*+ INDEX(INTRARI IDX_INTRARI_TIPDOC, IDX_INTRARI_OPERAT, IDX_INTRARI_ANULAT, IDX_INTRARI_SUBUNITATEA) */ distinct i1.codcmdint1, i1.codobiect
    from intrari1 i1 
         inner join intrari i on i1.codintr = i.codintr
    where (exists (select valoare from tmp_manevra_liste where valoare = i1.codobiect and filtru = &apos;CODOBIECT&apos;)
           or vAllArt = 1) 
           and i.tipdoc = 7 and nvl(i.anulat,0) = 0 and i.operat = 1
           and i.an*12 + i.luna = vAnLuna   
           and (i.subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1);
  end if;
           
    /*for v_rec in (
                  with man_cons as (
                    select i1.codobiect produs, 
                           ies1.codobiect material, 
                           l1.cant, 
                           ies1.pu * l1.cant valoare, 
                           ns1.tipdoc, 
                           nvl(ii1.codcmdint1,0) codcmdint1,
                           ies1.codies1,
                           l1.codlivr1,
                           ns.codnirstoc codnirstocpred,
                           nvl(it1.cant,0) cantpred,
                           it1.codintr1,
                           case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                    from obj_cmdint1 i1
                         inner join iesiri1 ies1 on ies1.codcmdint1 = i1.codcmdint1
                         inner join iesiri ies on ies1.codies = ies.codies
                         inner join livr1 l1 on l1.codies1 = ies1.codies1
                         inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                         inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                         left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                         left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                         left join intrprodlink lk on lk.codintr1 = it1.codintr1
                         left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                    where ies.operat = 1 and nvl(ies.anulat,0) = 0
                          and nvl(prod.tip,0) = 0
                  )  
                  select man_cons.produs, man_cons.material, sum(man_cons.cant) cant, sum(man_cons.valoare) valoare, nvl(mat.tip,3) tipmat, man_cons.tipdoc, man_cons.codcmdint1,
                         tot_cons.total totcons, tot_pred.total totpred, obj.denumire, c.nrdoc,
                         man_cons.tip
                  from man_cons
                       inner join nartobj obj on obj.codobiect = man_cons.material
                       inner join (select sum(cant) total, material, produs 
                                   from (select distinct cant, codlivr1, material, produs from man_cons)
                                   group by material, produs) tot_cons on tot_cons.material = man_cons.material and tot_cons.produs = man_cons.produs
                       left join (select sum(cantpred) total, material, produs 
                                  from (
                                         select distinct produs, material, codcmdint1, cantpred, codintr1 
                                         from man_cons where tipdoc = 7
                                        )
                                  group by produs, material
                                  ) tot_pred on tot_pred.produs = man_cons.produs and tot_pred.material = man_cons.material
                       left join iesprodlink iesl on iesl.codies1 = man_cons.codies1
                       left join cmdprodmat mat on mat.codcmdprodmat = iesl.codcmdprodmat
                       left join prodmat pmat on pmat.codmat = mat.codprodmat
                       left join comanda1 c1 on c1.codcomanda1 = man_cons.codcmdint1
                       left join comanda c on c.codcomanda = c1.codcomanda
                  group by man_cons.produs, man_cons.material, nvl(mat.tip,3), man_cons.tipdoc, man_cons.codcmdint1, tot_cons.total, tot_pred.total,
                           obj.denumire, c.nrdoc,man_cons.tip 
                  ) loop
      if v_rec.tipdoc = 7 and v_rec.tip = 1 then 
        BagaMaterialeSemi(v_rec.produs, v_rec.material, v_rec.totcons/v_rec.totpred, v_rec.codcmdint1);
      else
        MERGE INTO MANEVRA_CONSUM C
        USING (
               SELECT   
                 V_REC.PRODUS PRODUS, V_REC.MATERIAL MATERIAL, V_REC.CANT CANT, V_REC.VALOARE VALOARE
               FROM DUAL
               ) N
        ON (C.CODOBIECT = N.MATERIAL and C.NODPARINTE = N.PRODUS and C.PRODUS = N.PRODUS)
        WHEN NOT MATCHED THEN INSERT (CODOBIECT, VALOARE, CANT, NODPARINTE, PRODUS)
                                      VALUES 
                                     (N.MATERIAL, N.VALOARE, N.CANT, N.PRODUS, N.PRODUS)
        WHEN MATCHED THEN UPDATE SET C.CANT = NVL(C.CANT,0) + N.CANT, C.VALOARE = NVL(C.VALOARE,0) + N.VALOARE;                             
      end if;
    end loop;
  else
    DELETE OBJ_CMDINT1;
    INSERT INTO OBJ_CMDINT1(CODCMDINT1, CODOBIECT)
    select /*+ INDEX(INTRARI IDX_INTRARI_TIPDOC, IDX_INTRARI_OPERAT, IDX_INTRARI_ANULAT, IDX_INTRARI_SUBUNITATEA) */ --distinct i1.codcmdint1, i1.codobiect
    /*from intrari1 i1 
         inner join intrari i on i1.codintr = i.codintr
    where (exists (select valoare from tmp_manevra_liste where valoare = i1.codobiect and filtru = &apos;CODOBIECT&apos;)
           or vAllArt = 1) 
           and i.tipdoc = 7 and nvl(i.anulat,0) = 0 and i.operat = 1
           and i.an*12 + i.luna = vAnLuna   
           and (i.subunitatea = pkg_globals.GETSUBUNITATE or pkg_globals.GETSUBUNITATE = 1); */
    
    for v_rec in (
                  with man_cons as (
                    select i1.codobiect produs, 
                           ies1.codobiect material, 
                           l1.cant, 
                           nvl(ns1.pretmat,0) * l1.cant valoare, 
                           ns1.tipdoc, 
                           nvl(ii1.codcmdint1,0) codcmdint1,
                           ies1.codies1,
                           l1.codlivr1,
                           ns.codnirstoc codnirstocpred,
                           nvl(it1.cant,0) cantpred,
                           it1.codintr1,
                           case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                    from OBJ_CMDINT1 i1
                         inner join iesiri1 ies1 on ies1.codcmdint1 = i1.codcmdint1
                         inner join iesiri ies on ies1.codies = ies.codies
                         inner join livr1 l1 on l1.codies1 = ies1.codies1
                         inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                         inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                         left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                         left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                         left join intrprodlink lk on lk.codintr1 = it1.codintr1
                         left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                    where ies.operat = 1 and nvl(ies.anulat,0) = 0 and ns1.tipdoc = 7 and prod.tip = 0
                  ),
                  man_cons_mat as (
                    select i1.codobiect produs, 
                           ies1.codobiect material, 
                           l1.cant, 
                           nvl(ns1.pretmat,0) * l1.cant valoare, 
                           ns1.tipdoc, 
                           0 codcmdint1,
                           ies1.codies1,
                           l1.codlivr1,
                           ns.codnirstoc codnirstocpred,
                           nvl(it1.cant,0) cantpred,
                           it1.codintr1,
                           case when ns1.tipdoc = 7 and prod.tip = 0 then 1 else 0 end tip
                    from OBJ_CMDINT1 i1
                         inner join iesiri1 ies1 on ies1.codcmdint1 = i1.codcmdint1
                         inner join iesiri ies on ies1.codies = ies.codies
                         inner join livr1 l1 on l1.codies1 = ies1.codies1
                         inner join livr l on l.codlivr = l1.codlivr and ies.codies = l.codies
                         inner join nirstoc1 ns1 on l1.codnirstoc = ns1.codnirstoc
                         inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
                         left join intrari1 ii1 on ii1.codintr1 = ns.codintr1
                         left join intrari1 it1 on it1.codcmdint1 = ii1.codcmdint1 and it1.codobiect = ies1.codobiect
                         left join intrprodlink lk on lk.codintr1 = it1.codintr1
                         left join cmdprodmat prod on prod.codcmdprodmat = lk.codliniecomanda
                    where ies.operat = 1 and nvl(ies.anulat,0) = 0 and not (ns1.tipdoc = 7 and nvl(prod.tip,-1) = 0)
                  )  
                  select produs, material, sum(cant) cant, sum(valoare) valoare, codcmdint1,
                         totcons, totval, totpred, tip, codlivr1 
                  from (
                    select distinct man_cons_mat.produs, man_cons_mat.material, man_cons_mat.cant, man_cons_mat.valoare, man_cons_mat.codcmdint1,
                           tot_cons.cant totcons, tot_cons.valoare totval, 0 totpred, man_cons_mat.tip, man_cons_mat.codlivr1       
                    from man_cons_mat
                         inner join nartobj obj on obj.codobiect = man_cons_mat.material
                         inner join (select sum(cant) cant, material, produs, codcmdint1, tip, sum(valoare) valoare
                                     from (select distinct cant, codlivr1, material, produs, codcmdint1, tip, valoare from man_cons_mat)
                                     group by material, produs, codcmdint1, tip) 
                                     tot_cons on tot_cons.material = man_cons_mat.material and 
                                                 tot_cons.produs = man_cons_mat.produs and
                                                 tot_cons.codcmdint1 = man_cons_mat.codcmdint1 and
                                                 tot_cons.tip = man_cons_mat.tip
                    union all
                    select distinct man_cons.produs, man_cons.material, man_cons.cant, man_cons.valoare, case when man_cons.tip = 1 then man_cons.codcmdint1 else 0 end codcmdint1,
                           tot_cons.cant totcons, tot_cons.valoare totval, nvl(tot_pred.total,0) totpred, man_cons.tip, 0 codlivr1       
                    from man_cons
                         inner join nartobj obj on obj.codobiect = man_cons.material
                         inner join (select sum(cant) cant, material, produs, codcmdint1, tip, sum(valoare) valoare
                                     from (select distinct cant, codlivr1, material, produs, codcmdint1, tip, valoare from man_cons)
                                     group by material, produs, codcmdint1, tip) 
                                     tot_cons on tot_cons.material = man_cons.material and 
                                                 tot_cons.produs = man_cons.produs and
                                                 tot_cons.codcmdint1 = man_cons.codcmdint1 and
                                                 tot_cons.tip = man_cons.tip
                         left join (select sum(cantpred) total, material, produs, codcmdint1, tip 
                                     from (
                                           select distinct produs, material, codcmdint1, cantpred, codintr1, tip
                                           from man_cons where tipdoc = 7 AND TIP = 1
                                           )
                                     group by produs, material, codcmdint1, tip
                                     ) tot_pred on tot_pred.produs = man_cons.produs and 
                                                   tot_pred.material = man_cons.material and
                                                   tot_pred.codcmdint1 = man_cons.codcmdint1 and
                                                   tot_pred.tip = man_cons.tip
                       )                            
                  group by produs, material, codcmdint1, totcons, totpred, tip, totval, codlivr1
                  ) loop
                  
      /*if v_rec.material = 1736 then
        insert into x(test) values(&apos;codcomanda1:&apos;);
      end if;*/
                  
      if v_rec.codcmdint1 &gt; 0 and v_rec.tip = 1 then 
        BagaMaterialeSemi(v_rec.produs, v_rec.material, v_rec.totcons/v_rec.totpred, v_rec.codcmdint1);
      else
        MERGE INTO MANEVRA_CONSUM C
        USING (
             SELECT   
               v_rec.produs Produs, v_rec.produs NodParinte, V_REC.MATERIAL MATERIAL, V_REC.cant CANT, V_REC.valoare VALOARE, v_rec.totcons TOTCONS, v_rec.totval TOTVAL
             FROM DUAL
             ) N
      ON (C.CODOBIECT = N.MATERIAL and C.NODPARINTE = N.NODPARINTE and C.PRODUS = N.PRODUS)
      WHEN NOT MATCHED THEN INSERT (CODOBIECT, VALOARE, CANT, NODPARINTE, PRODUS)
                                    VALUES 
                                   (N.MATERIAL, N.VALOARE, N.CANT, N.NODPARINTE, N.PRODUS)
      WHEN MATCHED THEN UPDATE SET C.CANT = nvl(C.CANT,0) + N.CANT, C.VALOARE = NVL(C.VALOARE,0) + N.VALOARE;                             
      end if;
    end loop;
  --end if;  
end;

procedure BagaMatRetSemi(aProdus in number, aCodSemif in number, aCant in number, aIDX in varchar2) is
begin
  for v_rec in (
                select pmat.codobiect material, pmat.cant/pc.cant * aCant cantret, pmat.cant / pc.cant * aCant * pmat.pret valret, pmat.tip,
                       aIDX||&apos;.&apos;||LPAD(to_char(pmat.IndexLocal), 2, &apos;0&apos;) S_IDX
                from prodcomp pc
                     inner join prodmat pmat on pmat.codprodcomp = pc.codprodcomp
                where pc.codobiect = aCodSemif
                      and pc.implicit = 1
                ) loop
    if v_rec.tip &lt; 3 then 
      BagaMatRetSemi(aprodus, v_rec.material, v_rec.cantret, v_rec.S_idx);
    else
      MERGE INTO MANEVRA_CONSUM C
      USING (
             SELECT   
               V_REC.MATERIAL MATERIAL, V_REC.CANTRET CANTRET, V_REC.VALRET VALRET, aIDX S_IDX
             FROM DUAL
             ) N
      ON (C.CODOBIECT = N.MATERIAL and C.NODPARINTE = aCodSemif and C.PRODUS = aPRODUS)
      WHEN NOT MATCHED THEN INSERT (CODOBIECT, VALRET, CANTRET, NODPARINTE, PRODUS, S_IDX)
                                    VALUES 
                                   (N.MATERIAL, N.VALRET, N.CANTRET, aCodSemif, aPRODUS, N.S_IDX)
      WHEN MATCHED THEN UPDATE SET C.CANTRET = NVL(C.CANTRET,0) + N.CANTRET, C.VALRET = NVL(C.VALRET,0) + N.VALRET, C.S_IDX = N.S_IDX;
    end if;
  end loop;
end;

procedure CreazaStructTeoretica is
begin
  for v_rec in (
                select pc.codobiect produs, pmat.codobiect material, pmat.cant/pc.cant cantret, pmat.cant / pc.cant * pmat.pret valret, pmat.tip,
                       &apos;00&apos;||&apos;.&apos;||LPAD(to_char(pmat.IndexLocal), 2, &apos;0&apos;) S_IDX
                from prodcomp pc
                     inner join prodmat pmat on pmat.codprodcomp = pc.codprodcomp
                     inner join (select distinct produs from manevra_consum) sel on sel.produs = pc.codobiect
                where pc.implicit = 1
                order by pc.codobiect, pmat.indexlocal
                ) loop
    if v_rec.tip &lt; 3 then
      BagaMatRetSemi(v_rec.produs, v_rec.material, v_rec.cantret, v_rec.S_IDX);
    else            
      MERGE INTO MANEVRA_CONSUM C
      USING (
             SELECT   
               V_REC.PRODUS PRODUS, V_REC.MATERIAL MATERIAL, V_REC.CANTRET CANTRET, V_REC.VALRET VALRET, &apos;00&apos; S_IDX
             FROM DUAL
             ) N
      ON (C.CODOBIECT = N.MATERIAL and C.NODPARINTE = N.PRODUS and C.PRODUS = N.PRODUS)
      WHEN NOT MATCHED THEN INSERT (CODOBIECT, VALRET, CANTRET, NODPARINTE, PRODUS, S_IDX)
                                    VALUES 
                                   (N.MATERIAL, N.VALRET, N.CANTRET, N.PRODUS, N.PRODUS, N.S_IDX)
      WHEN MATCHED THEN UPDATE SET C.CANTRET = NVL(C.CANTRET,0) + N.CANTRET, C.VALRET = NVL(C.VALRET,0) + N.VALRET, C.S_IDX = N.S_IDX;
    end if;  
  end loop;          
end;  

procedure test is
begin
  pkg_globals.SETSUBUNITATE(2); 
  vAnLuna := 2021*12+1;
  vAllArt := 0;
  vCodComanda := 0;
  INSERT INTO tmp_manevra_liste(filtru, valoare) VALUES(&apos;CODOBIECT&apos;,35397);
  UmplePredariSiConsumuri;
  CreazaStructTeoretica;
  commit;
end;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RAPCONSPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPCONSUMPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C7A33EEF4CB2950F64BF671843C8DF32FED2D68</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPCONSUMPROD is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vTouch boolean default false;

PROCEDURE PROCESSPARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;
  for v_rec in
  (
    SELECT P.Descriere
    FROM TMP_RAPORTARE_CONSUM TMP
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = TMP.CODCOMANDA1
         INNER JOIN PRODCOMP P ON C1.CODRETETA = P.CODPRODCOMP
  ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;Descriere&apos;, v_rec.descriere);
    Exit;
  end loop;
END;

PROCEDURE SETPARAMS(aTouch in number default 0) is
begin
  vTouch := Coalesce(aTouch, 0) = 1;
end;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
sInsert  VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;nartobj obj, nart a, COMANDA1 C1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
    &apos;INSERT INTO &apos;||tmpName||&apos; (
       DENUMIRE,
       CODEXTERN,
       UMSEC,
       TOTAL,
       PROGRAMAT,
       CANTUNITAR,
       REALIZAT,
       CONSUMAT,
       UMSpec,
       D1,
       D2,
       D3,
       RAPORTAT,
       RAPORTATUM1,
       Pret,
       STOC&apos;;
    if not vTouch then
      sInsert := sInsert||&apos;,
       STOCT &apos;;
    end if;
    sInsert := sInsert||gUserFields||&apos; )
    SELECT
       TMP.DENUMIRE,
       TMP.CODEXTERN,
       TMP.DEN_UM1,
       TMP.TOTAL,
       TMP.PROGRAMAT,
       TMP.UNITAR,
       TMP.REALIZAT,
       TMP.CONSUMAT,
       NUM1.DEN_UM1,
       TMP.D1,
       TMP.D2,
       TMP.D3,
       TMP.RAPORTAT,
       TMP.RAPORTATUM1,
       TMP.Pret,
       TMP.STOC&apos;;
    if not vTouch then
      sInsert := sInsert||&apos;,
       TMP.STOCT &apos;;
    end if;
    sInsert := sInsert||gUserAlias||&apos;
    FROM TMP_RAPORTARE_CONSUM TMP
      inner join NARTOBJ OBJ ON TMP.codobiect = OBJ.codObiect
      INNER JOIN NART A ON OBJ.codarticol = A.codarticol
      INNER JOIN COMANDA1 C1 ON TMP.CODCOMANDA1 = C1.CODCOMANDA1
      LEFT join num1 on num1.codum1 = TMP.um1&apos;||
      gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  PROCESSPARAMS;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
end;

end PKG_LIST_BASE_RAPCONSUMPROD;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPCREDITCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>784AE0CDE2D5F8BA7CDD54A08DA71BBF19670A77</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPCREDITCLI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  PKG_LIST_STRUCT.SetTableSpec(gSuplCols);
  PKG_LIST_STRUCT.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(30000);
  sTotalSold VARCHAR2(10000);
  sCoefTvaCC VARCHAR2(1000);
  vAnLunaC   INTEGER;
  vAnPrec    INTEGER;
  vLunaPrec  INTEGER;
BEGIN
  gSuplCols := &apos;NPART P, NPART1 P1, IOPART IOP, NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NTARI TSOC, NPERS AG&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_NomPart.SET_CODPART_SOLD_ANALIZAT(0);
  SELECT ancurent*12+lunacurenta INTO vAnLunaC FROM FirmaLuni;
  pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru,vAnPrec,vLunaPrec);
  pkg_globals.SetLunaPRECEDENTA(vAnPrec,vLunaPrec);
  pkg_globals.SetLunaTemp(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru);

  IF pkg_globals.AnLunaLucru&gt;= vAnLunaC THEN
    PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
  END IF;

  -- stef -- trebuie si parantezele fiindca se foloseste si intr-o scadere
  IF Coalesce(pkg_categconst.GetValConstanta(&apos;SoldFaraCECNeinc&apos; ,pkg_globals.anlucru,pkg_globals.lunalucru),&apos;0&apos;) = &apos;1&apos;
  THEN sTotalSold := &apos;(NVL(RESTFACT,0) + NVL(CECCURS,0) - NVL(INCAVANS,0) + NVL(AENEFACT,0) + NVL(AECUSTNEFACT,0))&apos;;
  ELSE sTotalSold := &apos;(NVL(RESTFACT,0) - NVL(INCAVANS,0) + NVL(AENEFACT,0) + NVL(AECUSTNEFACT,0))&apos;;
  END IF;

  IF Coalesce(pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.anlucru,pkg_globals.lunalucru),&apos;2&apos;) = &apos;1&apos;
  THEN sCoefTvaCC := &apos;*(1+CASE WHEN Trim(o.codd394) IS NOT NULL AND Upper(Trim(F.CodFiscal)) LIKE &apos;&apos;RO%&apos;&apos; THEN 0 ELSE NVL(tva1.procent/100,0) END)&apos;;
  ELSE sCoefTvaCC := &apos;*(1+NVL(tva1.procent/100,0))&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    PART, LIMCREDIT, RESTFACT, CECCURS, INCAVANS, AENEFACT,
    AECUSTNEFACT,
    FACTNEOP, COMCURS &apos;||gUserFields||&apos;)
  WITH
  R AS (
    SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
    FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
    WHERE R.TIPREG = 46 AND R.AN * 12 + R.LUNA &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    GROUP BY R1.CODGENERAL
  ),
  SP AS (
    SELECT
      O.CODPART,
      Sum (OL.REST * COALESCE(R.CURS, NULLIF(G.CURS,0), 1) * CASE WHEN O.SEMNIFICATIE = 200 THEN 1 ELSE 0 END) RESTFACT,
      Sum (OL.REST * COALESCE(R.CURS, NULLIF(G.CURS,0), 1) * CASE WHEN O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END) CECCURS,
      Sum (OL.REST * COALESCE(R.CURS, NULLIF(G.CURS,0), 1) * CASE WHEN O.SEMNIFICATIE IN (210,410) THEN 1 WHEN O.SEMNIFICATIE = 330 THEN -1 ELSE 0 END ) INCAVANS,
      Sum (OL.REST * COALESCE(R.CURS, NULLIF(G.CURS,0), 1) * CASE WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 AND NVL(I.CUSTODIE,0) = 0 THEN 1 ELSE 0 END) AENEFACT
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN GENERAL  G ON G.CODGENERAL  = O.CODGENERAL
      LEFT  JOIN IESIRI   I ON I.CODIES      = G.CODDOC AND I.TIPDOC = G.TIPDOC
      LEFT  JOIN (
        SELECT SUM(V1.PU * (V1.CANT - NVL(ST.CANT,0))) REST, V.CODIES
        FROM IESIRI V
          INNER JOIN IESIRI1 V1 ON V.CODIES = V1.CODIES
          LEFT JOIN (SELECT SUM(L.CANT) CANT, L.CODLINIEAVIZ FROM IESLINK L GROUP BY L.CODLINIEAVIZ) ST ON ST.CODLINIEAVIZ = V1.CODIES1 WHERE V.TIPDOC = 20 AND V.CUSTODIE = 1 GROUP BY V.CODIES
      ) CUST ON CUST.CODIES = I.CODIES
      LEFT JOIN R ON R.CODGENERAL = G.CODGENERAL
    WHERE O.SEMNIFICATIE IN (200, 210, 240, 330, 410, 600)
      AND OL.AN = &apos;||pkg_globals.GetAnLucru||&apos; AND OL.LUNA = &apos;||pkg_globals.GetLunaLucru||&apos;
    GROUP BY O.CODPART),
  FN AS (
    SELECT Partener, SUM(Valdoc) FACTNEOP
    FROM iesiri
    WHERE tipdoc IN (19, 26) AND operat = 0 AND anulat = 0 AND an*12+luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    GROUP BY Partener
  ),
  CC AS (
    SELECT C.Partener, SUM(c1.restacceptat*c1.pretorig*coalesce(c1.coefdiscmaj,1)&apos;||sCoefTvaCC||&apos;) COMCURS
    FROM comanda c
      INNER JOIN comanda1     c1   ON c1.codcomanda   = c.codcomanda
      INNER JOIN nartobj      o    ON o.codobiect     = c1.codobiect
      LEFT  JOIN npartcodfisc f    ON f.cod_codfiscal = c.codfiscal
      LEFT  JOIN nart1        a1   ON a1.codarticol   = o.codarticol AND &apos;||pkg_globals.AnLunaLucru||&apos; Between   a1.ALSTART and   a1.ALSTOP
      LEFT  JOIN ntva1        tva1 ON tva1.codtva     = a1.codtva    AND &apos;||pkg_globals.AnLunaLucru||&apos; Between tva1.ALSTART and tva1.ALSTOP
    WHERE c.tipdoc = 18 AND c.operat = 1 AND c.anulat = 0 and coalesce(c.inchisa,0) = 0 AND c1.restacceptat &gt; 0
      AND c.an*12+c.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    GROUP BY C.Partener
  )
  SELECT
    P.DEN_PART, P1.CREDITCLIENT, NVL(SP.RESTFACT,0), NVL(SP.CECCURS,0), NVL(SP.INCAVANS,0), NVL(SP.AENEFACT,0),
    ( SELECT NVL(SUM(v1.pu * v1.cant),0)
      FROM IESIRI V
        INNER JOIN IESIRI1 V1 ON V.CODIES = V1.CODIES
      WHERE V.TIPDOC = 20 AND V.CUSTODIE = 1 AND V.PARTENER = P.CODPART
    ) -
    ( SELECT NVL(SUM(v1.pu * l.cant),0)
      FROM IESIRI V
        INNER JOIN IESIRI1 V1 ON V.CODIES = V1.CODIES
        INNER JOIN IESLINK L ON L.CODLINIEAVIZ = V1.CODIES1
        INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L.CODIES1
        INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
      WHERE V.TIPDOC = 20 AND V.CUSTODIE = 1 AND V.PARTENER = P.CODPART
        AND I.AN*12+I.LUNA &lt;= &apos;||pkg_globals.AnLunaLucru||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0
    ) AECUSTNEFACT,
    NVL(FN.FACTNEOP,0), NVL(CC.COMCURS,0) &apos;||gUserAlias||&apos;
  FROM NPART1 P1 
    INNER JOIN NPART    P    ON P.CODPART       = P1.CODPART AND &apos;||pkg_globals.AnLunaLucru||&apos; Between P1.ALSTART and P1.ALSTOP 
    LEFT  JOIN IOPART   IOP  ON IOP.CODIOPART   = P1.CODIOPART
    LEFT  JOIN NAGENDA  SSOC ON SSOC.CODPART    = P1.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0
    LEFT  JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = NVL(SSOC.CODLOCALIT, 0)
    LEFT  JOIN NJUDET   JSOC ON JSOC.CODJUDET   = NVL(LSOC.CODJUDET, 0)
    LEFT  JOIN NTARI    TSOC ON TSOC.CODTARA    = NVL(LSOC.CODTARA, 0)
    LEFT  JOIN NPERS    AG   ON AG.CODPERS      = NVL(SSOC.CODAGENT, 0)
    LEFT  JOIN SP            ON SP.CODPART      = P1.CODPART
    LEFT  JOIN FN            ON FN.PARTENER     = P1.CODPART
    LEFT  JOIN CC            ON CC.PARTENER     = P1.CODPART&apos;||
    gSuplJoins||&apos;
  WHERE P1.CREDITCLIENT &lt;&gt; 0 &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET TOTALSOLD = &apos;||sTotalSold||&apos;, RESTCREDIT = LIMCREDIT - &apos;||sTotalSold;
  COMMIT;
END;
end PKG_LIST_BASE_RAPCREDITCLI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPGESTTVAVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA5FB66400857A7482FF6C2149612B60B397A8FD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPGESTTVAVAL IS

FUNCTION JOINTMP(vCamp VARCHAR2) RETURN VARCHAR2
IS
BEGIN
  IF PKG_LIST_SELECTGEST2.ToateGest
  THEN RETURN NULL;
  ELSE RETURN &apos;
        INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = &apos;||vcamp||&apos; AND TMP.FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
  sInsert     VARCHAR2(  500);
  sSelect     VARCHAR2(30000);
  sDataIni    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaIni,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sDataFin    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaFin,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sCondData   VARCHAR2(  100);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);

  IF PKG_LIST_SELECTGEST2.ZiuaIni = PKG_LIST_SELECTGEST2.ZiuaFin
  THEN sCondData := &apos; = to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSE sCondData := &apos; BETWEEN to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND to_date(&apos;&apos;&apos;||sDataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  END IF;

  sInsert :=
   &apos;INSERT INTO &apos;||tmpName||&apos; (
      NAV_CodDoc, NAV_TipDoc, PrefixDoc, NrDoc, DataDoc, Document, TipDoc,
      AdDebit,  ValDFTVA, ValDCTVA, TVAD,
      AdCredit, ValCFTVA, ValCCTVA, TVAC,
      SoldFinFTVA, SoldFinCTVA, SursaDest, DenIOART, SoldIn, AchizIn, SoldAd,
      Coef,
      DenGest, DenCONT, SimbCONT, RecLivr, Zi, ZiDoc, PjTVA )&apos;;

  sSelect := &apos;
  WITH
    IOA1 AS (
      SELECT IO.CODIOART, IO.DEN_IOART, NCo.DEN_CONT, NCo.SIMBOL SIMB_CONT
      FROM IOART1 IO1  
           JOIN IOART      IO  on IO.CODIOART = IO1.CODIOART
           LEFT JOIN NCONT NCo on NCo.CODCONT = IO1.CONT
      WHERE 
        IO1.MG = 5
        AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IO1.ALStart and IO1.ALStop
    ),
    SVM AS (
      SELECT GEST, CODIOART, Coalesce(TVA,0) TVA, SOLD, SOLD/(1+Coalesce(TVA,0))-(SOLD-Coalesce(ADAOS,0)) ADAOS, SOLDINTR, ADAOSINTR
      FROM STOCVALLUNA SVL &apos;||JOINTMP(&apos;SVL.GEST&apos;)||&apos;
      WHERE (AN * 12 + LUNA + 1)= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
      UNION ALL -- NIR-URI DIN INTRARI
      SELECT N.GEST, NS.CODIOART, NS.TVA, NS.CANTNIR * NS.PRET SOLD, NS.CANTNIR * NS.ADAOS ADAOS, NS.CANTNIR * NS.PRET SOLDINTR, NS.CANTNIR * NS.ADAOS ADAOSINTR
      FROM NIRSTOC NS
        INNER JOIN NIR     N ON N.CODNIR      = NS.CODNIR &apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
        INNER JOIN INTRARI I ON I.CODINTR     = N.CODINTR
        INNER JOIN IOA1      ON IOA1.CODIOART = NS.CODIOART
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- NIR-URI DIN MISCARI INTERNE
      SELECT N.GEST, NS.CODIOART, NS.TVA, NS.CANTNIR * NS.PRET SOLD, NS.CANTNIR * NS.ADAOS ADAOS, NS.CANTNIR * NS.PRET SOLDINTR, NS.CANTNIR * NS.ADAOS ADAOSINTR
      FROM NIRSTOC NS
        INNER JOIN NIR    N ON N.CODNIR      = NS.CODNIR &apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
        INNER JOIN TRANSF T ON T.CODTRANSF   = N.CODTRANSF
        INNER JOIN IOA1     ON IOA1.CODIOART = NS.CODIOART
      WHERE T.TIPDOC IN (12, 13) AND  T.ANULAT = 0 AND T.OPERAT = 1
        AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- LIVRARI INTRARI
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG * L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1   L1 ON L1.CODLIVR1 = LV.CODLIVR1
        INNER JOIN LIVR    L  ON L.CODLIVR   = L1.CODLIVR
        INNER JOIN INTRARI I  ON I.CODINTR   = L.CODINTR
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- LIVRARI IESIRI
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG * L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
        INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
        INNER JOIN IESIRI I  ON I.CODIES    = L.CODIES
      WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24 ) AND I.OPERAT = 1 AND I.ANULAT = 0
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- LIVRARI MISCARI INTERNE
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG * L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
        INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
        INNER JOIN TRANSF T  ON T.CODTRANSF = L.CODTRANSF
      WHERE T.TIPDOC IN (12, 13) AND T.OPERAT = 1 AND T.ANULAT = 0
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
        AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      UNION ALL -- LIVRARI MARIRI DE STOC
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, LV.PRETINREG * L1.CANT SOLD, (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, LV.PRETINREG * L1.CANT SOLDINTR, (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOSINTR
      FROM  LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
        INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
        INNER JOIN IESIRI I  ON I.CODIES    = L.CODIES
      WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
    )
  SELECT
    NULL CodDoc, NULL TipDoc, &apos;&apos; &apos;&apos; PrefixDoc, NULL NrDoc, to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DataDoc, &apos;&apos;Sold initial&apos;&apos; Doc, &apos;&apos; &apos;&apos; TipDoc,
    0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TVAD, 0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(SVM.Sold / (1 + SVM.Tva)) SoldFinFTva, SUM(SVM.Sold) SoldFinCTva,
    NULL SursaDest, IOA1.DEN_IOART,
    SUM(SVM.SOLDINTR) SoldIn, SUM(SVM.SOLDINTR - SVM.ADAOSINTR) AchizIn, SUM(SVM.ADAOS) SoldAd,
    CASE WHEN SUM(SVM.SOLDINTR - SVM.ADAOSINTR) = 0 THEN 0 ELSE SUM(SVM.SOLDINTR) / SUM(SVM.SOLDINTR - SVM.ADAOSINTR) END Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    NULL RecLivr, &apos;&apos;0&apos;&apos; Zi, &apos;&apos;0&apos;&apos; ZiDoc, SVM.TVA * 100 PjTVA
  FROM SVM
    INNER JOIN IOA1     ON IOA1.CODIOART = SVM.CODIOART
    INNER JOIN NGEST NG ON NG.CODGEST    = SVM.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
  GROUP BY NG.DEN_GEST, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, SVM.TVA
  UNION ALL -- INTRARI
  SELECT
    I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_date(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
    SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA / (1+NS.TVA) )) AdDebit, SUm(NS.CANTNIR * NS.PRET / (1+NS.TVA)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
    SUM(NS.CANTNIR * NS.PRET * NS.TVA / (1+NS.TVA)) TVAD, 0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(NS.CANTNIR * NS.PRET / (1+NS.TVA)) SoldFinFTva, SUM(NS.CANTNIR * NS.PRET) SoldFinCTva,
    CASE I.TIPDOC WHEN 6 THEN S.DEN_SUBUNIT WHEN 7 THEN G.DEN_GEST ELSE NP.DEN_PART END SursaDest, IOA1.DEN_IOART,
    SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn, 0 SoldAd,
    CASE WHEN SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) = 0 THEN 0 ELSE SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) END Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, NS.TVA * 100 PjTva
  FROM NIRSTOC NS
    INNER JOIN IOA1        ON IOA1.CODIOART = NS.CODIOART
    INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
    INNER JOIN NGEST    NG ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    INNER JOIN INTRARI  I  ON I.CODINTR     = N.CODINTR
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
  WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
    AND N.DATANIR&apos;||sCondData||&apos;
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
  GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, N.NRNIR, N.DATANIR, NS.TVA, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL -- INTRARI DIN TRANSFERURI
  SELECT
    T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_date(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
    SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA / (1+NS.TVA) )) AdDebit, SUm(NS.CANTNIR * NS.PRET / (1+NS.TVA)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
    SUM(NS.CANTNIR * NS.PRET * NS.TVA / (1+NS.TVA)) TVAD, 0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(NS.CANTNIR * NS.PRET / (1+NS.TVA)) SoldFinFTva, SUM(NS.CANTNIR * NS.PRET) SoldFinCTva,
    NG_S.DEN_GEST SursaDest, IOA1.DEN_IOART,
    SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn, 0 SoldAd,
    CASE WHEN SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) = 0 THEN 0 ELSE SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) END Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, NS.TVA * 100 PjTva
  FROM TRANSF T
    INNER JOIN NIR     N    ON N.CODTRANSF     = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
    INNER JOIN NIRSTOC NS   ON NS.CODNIR       = N.CODNIR
    INNER JOIN IOA1         ON IOA1.CODIOART   = NS.CODIOART
    INNER JOIN NGEST   NG   ON NG.CODGEST      = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
    LEFT  JOIN NIR     N_S  ON N_S.CODNIR      = NS_S.CODNIR
    LEFT  JOIN LIVRVAL LV_S ON LV_S.CODLIVR1   = NS.CODLIVR1
    LEFT  JOIN NGEST   NG_S ON NG_S.CODGEST    = Coalesce(N_S.GEST,LV_S.GEST)
  WHERE T.TIPDOC = 12 AND T.ANULAT = 0 AND T.OPERAT = 1
    AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND N.DATANIR&apos;||sCondData||&apos;
  GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, NS.TVA, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST
  UNION ALL -- IESIRI DIN TRANSFERURI
  SELECT
    T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_date(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
    0 Addebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD,
    SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdCredit,
    SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(L1.CANT * LV.PRETINREG) ValCCTva,
    SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaC,
    -SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT * LV.PRETINREG) SoldFinCTva,
    NG_D.DEN_GEST SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn, 0 SoldAd,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, Coalesce(LV.TVANEEX, 0) * 100 PjTVA
  FROM TRANSF T
    INNER JOIN LIVR    L    ON L.CODTRANSF   = T.CODTRANSF
    INNER JOIN LIVR1   L1   ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL LV   ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1         ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST   NG   ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN NIRSTOC NS_D ON NS_D.CODLIVR1 = L1.CODLIVR1
    LEFT  JOIN NIR     N_D  ON N_D.CODNIR    = NS_D.CODNIR
    LEFT  JOIN NGEST   NG_D ON NG_D.CODGEST  = N_D.GEST
  WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0
    AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND L.DATALIVR&apos;||sCondData||&apos;
  GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, L.NRLIVR, L.DATALIVR, Coalesce(LV.TVANEEX, 0), IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_D.DEN_GEST
  UNION ALL -- MODIFICARI DE PRET
  SELECT
    T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_date(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
    SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA / (1+NS.TVA))) AdDebit, SUm(NS.CANTNIR * NS.PRET / (1+NS.TVA)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
    SUM(NS.CANTNIR * NS.PRET * NS.TVA / (1+NS.TVA)) TVAD,
    SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG / (1+LV_S.TVANEEX) - LV_S.PRETACHIZ ELSE NS_S.ADAOS - NS_S.PRET * NS_S.TVA / (1+NS_S.TVA) END) AdCredit,
    SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG / (1+LV_S.TVANEEX)                  ELSE NS_S.PRET / (1+NS_S.TVA)                         END) ValCFTva,
    SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG                                     ELSE NS_S.PRET                                        END) ValCCTva,
    SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG * LV_S.TVANEEX / (1+LV_S.TVANEEX)   ELSE NS_S.PRET * NS_S.TVA / (1+NS_S.TVA)              END) TvaC,
    SUM(NS.CANTNIR * NS.PRET / (1+NS.TVA)) - SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG / (1+LV_S.TVANEEX) ELSE NS_S.PRET / (1+NS_S.TVA) END) SoldFinFTva,
    SUM(NS.CANTNIR * NS.PRET)              - SUM(NS.CANTNIR * CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN LV_S.PRETINREG                    ELSE NS_S.PRET                END) SoldFinCTva,
    NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
    SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn, 0 SoldAd,
    CASE WHEN SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) = 0 THEN 0 ELSE SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) END Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, NS.TVA * 100 PjTva
  FROM TRANSF T
    INNER JOIN NIR     N    ON N.CODTRANSF     = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
    INNER JOIN NIRSTOC NS   ON NS.CODNIR       = N.CODNIR
    INNER JOIN IOA1         ON IOA1.CODIOART   = NS.CODIOART
    INNER JOIN NGEST   NG   ON NG.CODGEST      = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
    LEFT  JOIN NIR     N_S  ON N_S.CODNIR      = NS_S.CODNIR
    LEFT  JOIN LIVR1   L1_S ON L1_S.CODLIVR1   = NS.CODLIVR1 AND (NS.CODNIRSTOCPARINTE IS NULL)
    LEFT  JOIN (
      SELECT CODLIVR1, Coalesce(PRETINREG, 0) PRETINREG, Coalesce(PRETACHIZ, 0) PRETACHIZ, Coalesce(TVANEEX, 0) TVANEEX, GEST
      FROM LIVRVAL
    ) LV_S ON LV_S.CODLIVR1 = L1_S.CODLIVR1
    LEFT  JOIN NGEST   NG_S ON NG_S.CODGEST = Coalesce(N_S.GEST,LV_S.GEST)
  WHERE T.TIPDOC = 13 AND T.ANULAT = 0 AND T.OPERAT = 1
    AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND N.DATANIR&apos;||sCondData||&apos;
  GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, NS.TVA, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST
  UNION ALL -- RETUR INTRARI VALORIC
  SELECT
    I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_date(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
    - SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) AdDebit, - SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValDFTva,
    - SUM(L1.CANT * LV.PRETINREG) ValDCTva, - SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaD,
    0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    -SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT * LV.PRETINREG) SoldFinCTva,
    CASE I.TIPDOC WHEN 6 THEN S.DEN_SUBUNIT WHEN 7 THEN G.DEN_GEST ELSE NP.DEN_PART END SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn, 0 SoldAd,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, Coalesce(LV.TVANEEX, 0) * 100 PjTVA
  FROM INTRARI I
    INNER JOIN LIVR     L  ON L.CODINTR     = I.CODINTR
    INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL  LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1        ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST    NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT = I.CODSUBUNIT
  WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND L.DATALIVR&apos;||sCondData||&apos;
  GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, Coalesce(LV.TVANEEX, 0), IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL  -- IESIRI VALORIC
  SELECT
    I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_date(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
    0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD,
    SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) Adcredit, SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(L1.CANT * LV.PRETINREG) ValCCTva,
    SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaC,
    -SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT * LV.PRETINREG) SoldFinCTva,
    CASE I.TIPDOC WHEN 14 THEN &apos;&apos;-&apos;&apos; WHEN 16 THEN &apos;&apos;-&apos;&apos; WHEN 23 THEN S.DEN_SUBUNIT WHEN 24 THEN NG.DEN_GEST ELSE NP.DEN_PART END SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn, 0 SoldAd,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, Coalesce(LV.TVANEEX, 0) * 100 PjTVA
  FROM IESIRI I
    INNER JOIN LIVR     L  ON L.CODIES      = I.CODIES
    INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL  LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1        ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST    NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
  WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND L.DATALIVR&apos;||sCondData||&apos;
  GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, Coalesce(LV.TVANEEX, 0), IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL -- MARIRI DE STOC VALORIC
  SELECT
    I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_date(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
    SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdDebit, SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValDFTva, SUM(L1.CANT * LV.PRETINREG) ValDCTva,
    SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaD, 0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, SUM(L1.CANT * LV.PRETINREG) SoldFinCTva,
    NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
    SUM(L1.CANT * LV.PRETINREG) SoldIn, SUM(L1.CANT * LV.PRETINREG) AchizIn, 0 SoldAd,
    CASE WHEN SUM(L1.CANT * LV.PRETINREG) = 0 THEN 0 ELSE SUM(L1.CANT * LV.PRETINREG) / SUM(L1.CANT * LV.PRETINREG) END Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc, Coalesce(LV.TVANEEX, 0) * 100 PjTVA
  FROM IESIRI I
    INNER JOIN LIVR    L  ON L.CODIES      = I.CODIES
    INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1       ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST   NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
  WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND L.DATALIVR&apos;||sCondData||&apos;
  GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, Coalesce(LV.TVANEEX, 0), IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpName||&apos; SET SoldAd=AdDebit-AdCredit WHERE SoldAd=0&apos;;
  COMMIT;

END;

procedure SetJoinuri is
begin
   Pkg_List_Struct.SetTableSpec(&apos;&apos;);
   pkg_list_struct.AdunaColoanele;
end;

end PKG_LIST_BASE_RAPGESTTVAVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPINCPLATIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2272BA3FA94A26F20EF6BDAB7DB5B5FA0FFD6D74</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPINCPLATIART IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GetCodContract(aCodPart in number, aDataDoc in Date) return number is
aCodContract number(20);
BEGIN
  BEGIN
    select NVL(CodContract, 0) into aCodContract
    from contract c
    where c.partener = aCodPart and aDataDoc between c.datastart and c.datastop;
  EXCEPTION
    when others then aCodContract := 0;
  END;
  RETURN aCodContract;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2( 2000);
  sSelect1     VARCHAR2(32000);
  sSelect2     VARCHAR2(32000);
  sTipJoin     VARCHAR2(  100) := &apos;INNER&apos;;
  sAnS         NUMBER(      4) := EXTRACT(YEAR  FROM pkg_list_alegperioada.getDataS);
  sLunaS       NUMBER(      2) := EXTRACT(MONTH FROM pkg_list_alegperioada.getDataS);
  sDataS       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
  sDataF       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
  AnLunaLucru  NUMBER(     20);
  AnLunaIni    NUMBER(     20);
  sCurs        VARCHAR2( 1000) := &apos;, 1, 1, 1, 1&apos;;
  aBancaV      NUMBER(     20);
  aMonedaV     NUMBER(     20);
BEGIN
  gSuplCols :=
    &apos;nartobj o, npers ag_doc, npers ag_sting, npart npart, nclasep clsp, nagenda ag, nlocalit loc, njudet jud, nmonede mon, nmonede monprest, pretm pm, nsubunit SubSting, nsubunit SubStins, &apos;||
    &apos;npart prod, nart a, nclasea ca, nartcli ac, ncont c, nbankcont bc, nbank b, ngest g1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = NPART.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NBANKCONT1&apos;);
  PRC_AL_CHECK(&apos;IOBANK1&apos;);
  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  SELECT PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLunaLucru, ANINITIAL*12+LUNAINITIALA INTO AnLunaLucru, AnLunaIni FROM FIRMALUNI;

  aBancaV  := pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,      pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  --aMonedaV := pkg_categconst.GetValConstanta(&apos;MonedaFactInValuta&apos;,pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  aMonedaV := pkg_list_base_utils.GET_Cod_MonedaFactInValuta(pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  IF Nvl(aMonedaV,0) &lt;&gt; 0 AND Nvl(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := &apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := &apos;,1, 1&apos;;
  END IF;

  IF Nvl(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := sCurs||&apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := sCurs||&apos;,1, 1&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1 THEN
    sTipJoin := &apos;LEFT&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, TipStingere,
    DSTINSPR, DSTINSNR, DSTINSDATA, TOTAL_LIN, TOTAL_LINFTVA, REST_LIN, REST_LINFTVA, VAL_STINGATOR, VAL_STINGFTVA,
    DSTINGPR, DSTINGNR, DSTINGDATA, PARTENER, LOCATIE,
    SOLD_LIN, SOLD_LINF, SOLD_DOC, SOLD_DOCF,
    DATADECONT, DATAPLATA, ORDINE, ORDDOC, TERMEN, MONEDA, SUBUNIT, SUBUNIT_ST,
    SCADENTA, DIFZILE, DEPZILE, DEPZILEDEC, DEPZILEPLATA, CONT, CONTART, CONTCB, ARTICOL, CODEXTERN, CODINTERN, PRODUCATOR, CLASAARTICOL,
    DSTINSCURS, DSTINSAN, DSTINSLUNA, DSTINGCURS, DSTINGAN, DSTINGLUNA, GESTDEN, GESTSIMB,
    NRCONT,
    DSTINSCURS_REF, DSTINGCURS_REF, DSTINSCURS_PREST, DSTINGCURS_PREST&apos;||gUserFields||&apos;)&apos;;

  -- plati
  sSelect1 := &apos;
  WITH crs_sold as (
    SELECT
      ol.codobligpif codobligpif,
      (ol.rest - (
        SELECT NVL(sum(s.valoare), 0)
        FROM stingere s
          INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
          INNER JOIN general  gs ON gs.codgeneral  = os.codgeneral
          LEFT  JOIN trezor1  t1 on gs.coddoc      = t1.codtrezor1 AND gs.tipdoc &lt;&gt; 28 AND t1.luna = &apos;||sLunaS||&apos; AND t1.an = &apos;||sAnS||&apos; AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          LEFT  JOIN compens  c  ON gs.coddoc      = c.codcompens  AND gs.tipdoc = 28  AND  c.luna = &apos;||sLunaS||&apos; AND  c.an = &apos;||sAnS||&apos; AND  c.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        WHERE s.codstinspif = ol.codobligpif
          AND Nvl(t1.codtrezor,c.codcompens) IS NOT NULL
      )) * DECODE(g.semnificatie,310,-1,1) rest
    FROM obligpifluna ol
      INNER JOIN obligpif op on ol.codobligpif = op.codobligpif
      INNER JOIN general  g  on op.codgeneral  = g.codgeneral
    WHERE (g.tipdoc BETWEEN 1 AND 7 OR g.tipdoc = 35)
      AND ol.luna + ol.an*12 = &apos;||To_Char(sAnS*12+sLunaS-1)||&apos;),
  stinsi as(
    SELECT
      i1.codintr1 coddoc1, i1.indexlocal, i.codintr coddoc, i.tipdoc, i1.codobiect, o.codgeneral, i.prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      CASE
        WHEN o.valoare = 0 THEN 0
        WHEN (i1.pu * i1.cant+DECODE(i.tipdoc,3,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu) = 0 THEN 0
        WHEN Sum((i1.pu * i1.cant+DECODE(i.tipdoc,3,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu)) over (PARTITION BY g.codgeneral, Nvl(i1.codcentru,0)) = 0 THEN 0
        ELSE o.valoare*((i1.pu * i1.cant+DECODE(i.tipdoc,3,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu))/ Sum((i1.pu * i1.cant+DECODE(i.tipdoc,3,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu)) over (PARTITION BY g.codgeneral, Nvl(i1.codcentru,0))
      END valoarelinie,
      CASE
        WHEN i.tipdoc = 3 and I1.PU * I1.CANT &lt;&gt; 0 THEN (I1.PU * I1.CANT-I1.TVA)/(I1.PU * I1.CANT)
        WHEN i.tipdoc &lt;&gt; 3 AND I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT)/(I1.PU * I1.CANT+I1.TVA)
        ELSE 1
      END COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, 0 agent, i.an, i.luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,i.an*12+i.luna,o.semnificatie) codcont, 0 codbanca,
      i1.contserv,
      NULL contbanca
    FROM intrari i
      INNER JOIN intrari1 i1  ON i.codintr    = i1.codintr
      INNER JOIN nartobj  obj ON i1.codobiect = obj.codobiect
      INNER JOIN general  g   ON g.coddoc     = i.codintr    and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif o   ON g.codgeneral = o.codgeneral AND Nvl(o.codcentru,0) = Nvl(i1.codcentru,0)
    WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 0 AND NVL(i1.codobiect,0) &lt;&gt; 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      0 coddoc1, 0 indexlocal, i.codintr coddoc, i.tipdoc, -1 codobiect, o.codgeneral, &apos;&apos;sold initial &apos;&apos; prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      o.valoare valoarelinie,
      1 COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, 0 agent, i.an, i.luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||AnLunaIni||&apos;,o.semnificatie) codcont, 0 codbanca,
      NULL contserv,
      NULL contbanca
    FROM intrari i
      INNER JOIN general  g ON g.coddoc     = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 600 and g.semnificatie &lt;&gt; 140
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
    WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 1 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      t1.CodTrezor1 CodDoc1, t1.indexlocal, t.CodTrezor CodDoc, t.TipDoc, DECODE(g.tipdoc,33,-3,-2) codobiect, o.codgeneral, t1.doc prefixdoc, t1.nrdoc, t1.datadoc, t.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      -o.valoare valoarelinie,
      CASE WHEN NVL(o.valoare,0) = 0 THEN 1 ELSE (o.valoare-nvl(g.tva,0))/o.valoare END COEFTVA,
      -o.valoare, o.codpart, t1.codlocatie, o.termen, t1.agent, t.An, t.Luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,t1.an*12+t1.luna,o.semnificatie) codcont, t.codbanca,
      CASE WHEN g.semnificatie = 900 THEN o.icont ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna)) END contserv,
      CASE WHEN g.tipdoc = 33 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, t.icontpers, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t.codbanca, t.an,t.luna)) END contbanca
    FROM trezor1 t1
      INNER JOIN general  g ON g.coddoc      = t1.codtrezor1 AND g.semnificatie IN (310, 900)
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
      INNER JOIN trezor   t ON t1.codtrezor = t.codtrezor
    WHERE NVL(t1.anulat, 0) = 0 AND t1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;),
  stingatori as (
    SELECT
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc PrefixDoc, t1.nrdoc, t1.datadoc, t1.DATADECONT, COALESCE(t1x.datadoc, t1.datadecont, t1.datadoc) DATAPLATA,
      t1.agent, t.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(t1.curs,NULL,1,0,1,t1.curs) curs, COALESCE(t.monedapers, bc.codmoneda, 0) moneda, t.an, t.luna, t.codbanca,
      CASE WHEN g.tipdoc = 33 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, t.icontpers, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t.codbanca, t.an,t.luna)) END contbanca
    FROM trezor1 t1
      INNER JOIN trezor    t   ON t1.codtrezor      = t.codtrezor
      INNER JOIN general   g   ON t1.codtrezor1     = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif  o   ON o.codgeneral      = g.codgeneral
      INNER JOIN stingere  s   ON s.codstingatorpif = o.codobligpif
      LEFT  JOIN nbankcont bc  ON bc.codbankcont    = t.codbanca
      LEFT  JOIN general   gc  ON gc.coddoc         = g.coddoc AND gc.semnificatie = 600 AND gc.semnificatie &lt;&gt; g.semnificatie
      LEFT  JOIN obligpif  oc  ON oc.codgeneral     = gc.codgeneral
      LEFT  JOIN stingere  sx  ON sx.codstinspif    = Nvl(oc.codobligpif, o.codobligpif)
      LEFT  JOIN obligpif  ox  ON ox.codobligpif    = sx.codstingatorpif
      LEFT  JOIN general   gx  ON gx.codgeneral     = ox.codgeneral
      LEFT  JOIN trezor1   t1x ON t1x.codtrezor1    = gx.coddoc
    WHERE T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((G.TipDoc IN (29, 30, 31, 33) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 1)) AND g.semnificatie &lt;&gt; 800&apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, &apos;&apos;PV&apos;&apos;, c.nrdoc, c.datadoc, null DATADECONT, c.datadoc DATAPLATA,
      0 Agent, c.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, c.an, c.luna, 0 codbanca,
      NULL contbanca
    FROM compens c
      INNER JOIN general  g ON g.coddoc          = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral      = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28 &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;),
  UN AS (
    SELECT
      stingatori.coddoc NAV_CodDoc, stingatori.coddoc1 NAV_CodDoc1, stingatori.tipdoc NAV_TipDoc, x.prefixdoc DSTINSPR, x.nrdoc DSTINSNR, x.datadoc DSTINSDATA, x.valoarelinie TOTAL_LIN,
      sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare, 0), 0, 1, x.valoare) VAL_STINGATOR,
      sign(x.valoare)*Nvl(stingatori.s_valftva,0)*x.valoarelinie/decode(nvl(x.valoare, 0), 0, 1, x.valoare) VAL_STINGFTVA,
      x.rest_lin - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.coddoc1, x.codobligpif),0) REST,
      x.coeftva,
      x.rest_lin - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.coddoc1, x.codobligpif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) SOLD_LIN,
      x.rest_doc - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.codobligpif ORDER BY x.indexlocal, stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) SOLD_DOC,
      ROW_NUMBER() OVER (PARTITION BY x.codobligpif, x.coddoc1 ORDER BY stingatori.codgeneral) ORDINE, COUNT(1) OVER (PARTITION BY x.codobligpif, x.coddoc1) ORDINEMAX,
      ROW_NUMBER() OVER (PARTITION BY x.codobligpif ORDER BY x.indexlocal, stingatori.codgeneral) ORDDOC, COUNT(1) OVER (PARTITION BY x.codobligpif) ORDDOCMAX,
      stingatori.prefixdoc DSTINGPR, stingatori.nrdoc DSTINGNR, stingatori.datadoc DSTINGDATA, stingatori.DATADECONT, stingatori.DATAPLATA, x.TERMEN, x.termen SCADENTA, trunc(stingatori.datadoc - x.datadoc) DIFZILE,
      case when trunc(stingatori.datadoc - x.termen) &gt; 0 then trunc(stingatori.datadoc - x.termen) else 0 end DEPZILE,
      case when trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - x.termen) &gt; 0 then trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - x.termen) else 0 end DEPZILEDEC,
      case when trunc(stingatori.dataplata - x.termen) &gt; 0 then trunc(stingatori.dataplata - x.termen) else 0 end DEPZILEPLATA,
      x.codpart, Nvl(x.agent,0) agent, Nvl(stingatori.agent,0) agent_sting, x.codcont, Nvl(x.codlocatie,0) codlocatie,
      x.curs dstinscurs, x.moneda, x.subunitatea dstinssub, stingatori.subunitatea dstingsub,
      x.coddoc, x.coddoc1, x.tipdoc, x.codobiect, x.an dstinsan, x.luna dstinsluna, stingatori.an dstingan, stingatori.luna dstingluna, stingatori.an * 12 + stingatori.luna dstinganluna, stingatori.curs dstingcurs,
      CASE WHEN x.codobiect &lt;= -2 THEN x.codbanca ELSE stingatori.codbanca END codbanca, x.contserv, NVL(stingatori.contbanca,x.contbanca) contbanca
    FROM (
      SELECT
        stinsi.*,
        CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(stinsi.valoarelinie,0) ELSE NVL(crs_sold.rest,0) END rest_lin,
        SUM(CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(stinsi.valoarelinie,0) ELSE NVL(crs_sold.rest,0) END) OVER (PARTITION BY stinsi.codobligpif) rest_doc
      FROM stinsi LEFT JOIN crs_sold ON crs_sold.codobligpif = stinsi.codobligpif
      WHERE (NVL(crs_sold.rest,0) &lt;&gt; 0 OR crs_sold.rest IS NULL) AND stinsi.valoarelinie &lt;&gt; 0
    ) x &apos;||sTipJoin||&apos; JOIN stingatori ON stingatori.codstinspif = x.codobligpif)
  SELECT
    DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc1) NAV_CodDoc1, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_TipDoc) NAV_TipDoc, &apos;&apos;Plata&apos;&apos;,
    UN.DSTINSPR, UN.DSTINSNR, UN.DSTINSDATA, -UN.TOTAL_LIN, -UN.TOTAL_LIN * UN.COEFTVA, -UN.REST, -UN.REST * UN.COEFTVA, -UN.VAL_STINGATOR, -UN.VAL_STINGATOR * UN.COEFTVA,
    UN.DSTINGPR, UN.DSTINGNR, UN.DSTINGDATA, NPART.DEN_PART, AG.OBS,
    -UN.SOLD_LIN, -DECODE(UN.ORDINE,UN.ORDINEMAX,UN.SOLD_LIN), -UN.SOLD_DOC, -DECODE(UN.ORDDOC,UN.ORDDOCMAX,UN.SOLD_DOC),
    UN.DATADECONT, UN.DATAPLATA, UN.ORDINE, UN.ORDDOC, UN.TERMEN, mon.den_moneda, SubStins.den_subunit, SubSting.den_subunit,
    UN.SCADENTA, UN.DIFZILE, UN.DEPZILE, UN.DEPZILEDEC, UN.DEPZILEPLATA, C.SIMBOL, Nvl(XC.CONTART, CS.SIMBOL), CB.SIMBOL, DECODE(un.codobiect, -1, &apos;&apos;INITIALIZARE&apos;&apos;, -2, &apos;&apos;AVANS TREZORERIE&apos;&apos;, -3, &apos;&apos;DECONT CASA/BANCA&apos;&apos;,o.denumire) ARTICOL, O.CODEXTERN, O.CODINTERN, PROD.DEN_PART, CA.SIMBOL,
    UN.DSTINSCURS, UN.DSTINSAN, UN.DSTINSLUNA, UN.DSTINGCURS, UN.DSTINGAN, UN.DSTINGLUNA, DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.DEN,G1.DEN_GEST), DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.SIMB,G1.SIMBOL),
    DECODE(UN.NAV_TipDoc,33,&apos;&apos;DECONT CASA/BANCA&apos;&apos;,BC.NRCONT) &apos;||
    sCurs||gUserAlias||&apos;
  FROM UN
    LEFT JOIN intrari             i        on i.codintr           = un.coddoc AND i.tipdoc = un.tipdoc
    LEFT JOIN intrari1            i1       on i1.codintr1         = un.coddoc1 AND i1.codintr = i.codintr
    LEFT JOIN nartobj             o        ON o.codobiect         = un.codobiect
    LEFT JOIN npers               ag_doc   on ag_doc.codpers      = UN.agent
    LEFT JOIN npers               ag_sting ON ag_sting.codpers    = UN.agent_sting
    LEFT JOIN npart               npart    ON npart.codpart       = un.codpart
    LEFT JOIN nclasep             clsp     on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda             ag       ON UN.codlocatie       = ag.codagenda
    LEFT JOIN nlocalit            loc      on ag.codlocalit       = loc.codlocalit
    LEFT JOIN njudet              jud      on loc.codjudet        = jud.codjudet
    LEFT JOIN nmonede             mon      ON mon.codmoneda       = nvl(UN.moneda,0)
    LEFT JOIN pretm               pm       on pm.codobiect        = o.CodObiect and pm.implicit = 1 and pm.subunitatea = &apos;||pkg_globals.GETSUBUNITATE||&apos;
    LEFT JOIN nsubunit            SubSting ON SubSting.codsubunit = UN.dstingsub
    LEFT JOIN nsubunit            SubStins ON SubStins.codsubunit = UN.dstinssub
    LEFT JOIN tmp_subunitdedicate ts       ON ts.codsubunit       = UN.dstingsub
    LEFT JOIN npart               prod     ON prod.codpart        = o.codproducator
    LEFT JOIN nart                a        ON a.codarticol        = o.codarticol
    LEFT JOIN nclasea             ca       ON ca.codclasea        = a.clasa
    LEFT JOIN nartobj1            n1       on n1.codobiect        = o.codobiect AND &apos;||AnLunaLucru||&apos; BETWEEN n1.ALStart and n1.ALStop
    LEFT JOIN nmonede             monprest ON monprest.codmoneda  = nvl(n1.codmoneda,0)
    LEFT JOIN nartcli             ac       ON ac.codobiect        = un.codobiect AND ac.codpart = un.codpart
    LEFT JOIN ncont               c        ON c.codcont           = un.codcont
    LEFT JOIN ncont               cs       ON cs.codcont          = un.contserv
    LEFT JOIN nbankcont           bc       ON bc.codbankcont      = un.codbanca
    LEFT JOIN nbank               b        ON b.codbank           = bc.codbank
    LEFT JOIN NBANKCONT1          nbc1     ON nbc1.codbankcont    = un.codbanca     AND un.dstinganluna BETWEEN nbc1.ALStart and nbc1.ALStop
    LEFT JOIN IOBANK1             iob1     ON iob1.codiobank      = nbc1.codiobanca AND un.dstinganluna BETWEEN iob1.ALStart and iob1.ALStop
    LEFT JOIN ncont               cb       ON cb.codcont          = Nvl(un.contbanca,iob1.cont)
    LEFT JOIN ngest               g1       ON g1.codgest          = i1.gestact
    LEFT JOIN (
      SELECT ns.codintr1, n.codintr, n.tipnir, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.den_gest) AS vc2_nt)) DEN, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.simbol) AS vc2_nt)) SIMB
      FROM nirstoc ns
        INNER JOIN nir   n  ON n.codnir   = ns.codnir
        INNER JOIN ngest ng On ng.codgest = n.gest
      WHERE ng.codgest &lt;&gt; 0
      GROUP BY ns.codintr1, n.codintr, n.tipnir
    ) g2 ON g2.codintr1 = i1.codintr1 AND g2.codintr = i.codintr AND g2.tipnir = i.tipdoc
    LEFT JOIN (
      SELECT
        i1.codintr1,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT c.simbol) AS vc2_nt)) contart
      FROM intrari i
        INNER JOIN intrari1       i1   ON i.codintr     = i1.codintr
        LEFT  JOIN intrlink       il   ON il.codintr1   = i1.codintr1 AND il.codlinieaviz IS NOT NULL
        LEFT  JOIN intrasteptlink ila  ON ila.codliniefactura = i1.codintr1 AND NVL(i.tipfactura, 0) = 9
        LEFT  JOIN intrari1       ae1  ON ae1.codintr1  = COALESCE( ila.codintr1, il.codlinieaviz )
        LEFT  JOIN intrari        ae   ON ae.codintr    = ae1.codintr
        LEFT  JOIN dvi                 ON dvi.codintr   = i.codintr
        LEFT  JOIN dvi1                ON dvi1.coddvi   = dvi.coddvi AND dvi1.codintr1 = i1.codintr1
        LEFT  JOIN livr1          l1   ON l1.codintr1   = i1.codintr1
        LEFT  JOIN livrval        lv   ON lv.codlivr1   = l1.codlivr1
        LEFT  JOIN nirstoc        ns   ON ns.codobiect  = i1.codobiect
        AND ( ((l1.codlivr1 IS NOT NULL) AND (ns.codnirstoc = l1.codnirstoc)) OR
              ((l1.codlivr1 IS NULL) AND ((ns.codintr1 = NVL(ae1.codintr1,i1.codintr1)) OR (ns.coddvi1 = dvi1.coddvi1))))
        INNER JOIN ioart1         ioa1 ON ioa1.codioart = Nvl(lv.codioart,ns.codioart) AND (i.an*12+i.luna) BETWEEN ioa1.ALStart and ioa1.ALStop
        INNER JOIN ncont          c    ON c.codcont     = ioa1.cont 
      WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 0 AND NVL(i1.codobiect,0) &lt;&gt; 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos; 
      GROUP BY i1.codintr1
    ) xc ON xc.codintr1 = i1.codintr1&apos;||
    gSuplJoins;

  -- incasari
  sSelect2 := &apos;
  WITH crs_sold as (
    SELECT
      ol.codobligpif codobligpif,
      (ol.rest - (
        SELECT NVL(sum(s.valoare), 0)
        FROM stingere s
          INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
          INNER JOIN general  gs ON gs.codgeneral  = os.codgeneral
          LEFT  JOIN trezor1  t1 on gs.coddoc = t1.codtrezor1 AND gs.tipdoc &lt;&gt; 28 AND t1.luna = &apos;||sLunaS||&apos; AND t1.an = &apos;||sAnS||&apos; AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          LEFT  JOIN compens  c  ON gs.coddoc = c.codcompens  AND gs.tipdoc = 28  AND  c.luna = &apos;||sLunaS||&apos; AND  c.an = &apos;||sAnS||&apos; AND  c.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        WHERE s.codstinspif = ol.codobligpif
          AND Nvl(t1.codtrezor,c.codcompens) IS NOT NULL
      )) * DECODE(g.semnificatie,410,-1,1) rest
    FROM obligpifluna ol
      INNER JOIN obligpif op on ol.codobligpif = op.codobligpif
      INNER JOIN general  g  on op.codgeneral  = g.codgeneral
    WHERE (g.tipdoc BETWEEN 19 AND 26 OR g.tipdoc = 35)
      AND ol.luna + ol.an*12 = &apos;||To_Char(sAnS*12+sLunaS-1)||&apos;),
  stinsi as(
    SELECT
      i1.codies1 coddoc1, i1.indexlocal, i.codies coddoc, i.tipdoc, o.codgeneral, i1.codobiect, i.prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      CASE
        WHEN o.valoare = 0 THEN 0
        WHEN (i1.pu * i1.cant+DECODE(i.tipdoc,21,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu) = 0 THEN 0
        WHEN Sum((i1.pu * i1.cant+DECODE(i.tipdoc,21,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu)) over (PARTITION BY o.codobligpif, Nvl(i1.codcentru,0)) = 0 THEN 0
        ELSE o.valoare * (i1.pu * i1.cant+DECODE(i.tipdoc,21,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu)/Sum((i1.pu * i1.cant+DECODE(i.tipdoc,21,0,i1.tva)) * nvl(i1.coefdiscmaj, 1) * DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu)) over (PARTITION BY o.codobligpif, Nvl(i1.codcentru,0))
      END valoarelinie,
      CASE
        WHEN i.tipdoc = 21  and I1.PU * I1.CANT &lt;&gt; 0        THEN (I1.PU * I1.CANT-I1.TVA)/(I1.PU * I1.CANT)
        WHEN i.tipdoc &lt;&gt; 21 AND I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT)/(I1.PU * I1.CANT+I1.TVA)
        ELSE 1
      END COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, i.agent, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,i.an*12+i.luna,o.semnificatie) codcont, i.an, i.luna, 0 codbanca,
      i1.contserv,
      NULL contbanca
    FROM iesiri i
      INNER JOIN iesiri1  i1 ON i.codies = i1.codies
      INNER JOIN general  g  ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif o  ON g.codgeneral = o.codgeneral AND Nvl(o.codcentru,0) = Nvl(i1.codcentru,0)
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari, 0) = 0 AND NVL(i1.codobiect,0) &lt;&gt; 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      0 coddoc1, 0 indexlocal, i.codies coddoc, i.tipdoc, o.codgeneral, -1 codobiect, &apos;&apos;sold initial &apos;&apos; prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      o.valoare valoarelinie,
      1 COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, i.agent, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||AnLunaIni||&apos;,o.semnificatie) codcont, i.an, i.luna, 0 codbanca,
      NULL contserv,
      NULL contbanca
    FROM iesiri i
      LEFT JOIN general  g ON g.coddoc     = i.codies and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 240
      LEFT JOIN obligpif o ON g.codgeneral = o.codgeneral
    WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 1 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      t1.CodTrezor1 CodDoc1, t1.indexlocal, t.CodTrezor CodDoc, t.TipDoc, o.codgeneral, DECODE(g.tipdoc,33,-3,-2) codobiect, t1.doc prefixdoc, t1.nrdoc, t1.datadoc, t.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      -o.valoare valoarelinie,
      CASE WHEN NVL(o.valoare,0) = 0 THEN 1 ELSE (o.valoare-nvl(g.tva,0))/o.valoare END COEFTVA,
      -o.valoare, o.codpart, t1.codlocatie, o.termen, t1.agent, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,t1.an*12+t1.luna,o.semnificatie) codcont, t.An, t.Luna, t.codbanca,
      CASE WHEN g.semnificatie = 901 THEN o.icont ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna)) END contserv,
      CASE WHEN g.tipdoc = 33 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, t.icontpers, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t.codbanca, t.an,t.luna)) END contbanca
    FROM trezor1 t1
      INNER JOIN general  g ON g.coddoc     = t1.codtrezor1 AND g.semnificatie IN (410,901)
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
      INNER JOIN trezor   t ON t1.codtrezor = t.codtrezor
    WHERE NVL(t1.anulat, 0) = 0 AND t1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;),
  stingatori as (
    SELECT
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc prefixdoc, t1.nrdoc, t1.datadoc, t1.datadecont, COALESCE(t1x.datadoc, t1.datadecont, t1.datadoc) DATAINC,
      t1.agent, t.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(t1.curs,NULL,1,0,1,t1.curs) curs, COALESCE(t.monedapers, bc.codmoneda, 0) moneda, t.an, t.luna, t.codbanca,
      CASE WHEN g.tipdoc = 33 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, t.icontpers, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t.codbanca, t.an,t.luna)) END contbanca
    FROM trezor1 t1
      INNER JOIN trezor    t   ON t1.codtrezor      = t.codtrezor
      INNER JOIN general   g   ON t1.codtrezor1     = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif  o   ON o.codgeneral      = g.codgeneral
      INNER JOIN stingere  s   ON s.codstingatorpif = o.codobligpif
      LEFT  JOIN nbankcont bc  ON bc.codbankcont    = t.codbanca
      LEFT  JOIN general   gc  ON gc.coddoc         = g.coddoc AND gc.semnificatie = 600 AND gc.semnificatie &lt;&gt; g.semnificatie
      LEFT  JOIN obligpif  oc  ON oc.codgeneral     = gc.codgeneral
      LEFT  JOIN stingere  sx  ON sx.codstinspif    = Nvl(oc.codobligpif, o.codobligpif)
      LEFT  JOIN obligpif  ox  ON ox.codobligpif    = sx.codstingatorpif
      LEFT  JOIN general   gx  ON gx.codgeneral     = ox.codgeneral
      LEFT  JOIN trezor1   t1x ON t1x.codtrezor1    = gx.coddoc
    WHERE T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc IN (29, 30, 31, 33)
      AND ((t1.tiptranz = 0) OR (t1.TipTranz = 1))
      AND g.semnificatie NOT IN (410,750,801)&apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, &apos;&apos;PV&apos;&apos; prefixdoc, c.nrdoc, c.datadoc, null DATADECONT, c.datadoc DATAINC,
      0 Agent, c.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, c.an, c.luna, 0 codbanca,
      NULL contbanca
    FROM compens c
      INNER JOIN general  g ON g.coddoc          = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral      = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28 &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;),
  UN AS (
    SELECT
      stingatori.coddoc NAV_CodDoc, stingatori.coddoc1 NAV_CodDoc1, stingatori.tipdoc NAV_TipDoc, x.prefixdoc DSTINSPR, x.nrdoc DSTINSNR, x.datadoc DSTINSDATA, x.valoarelinie TOTAL_LIN,
      sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare, 0), 0, 1, x.valoare) VAL_STINGATOR,
      sign(x.valoare)*Nvl(stingatori.s_valftva,0)*x.valoarelinie/decode(nvl(x.valoare, 0), 0, 1, x.valoare) VAL_STINGFTVA,
      x.rest_lin - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.coddoc1, x.codobligpif),0) REST,
      x.coeftva,
      x.rest_lin - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.coddoc1, x.codobligpif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) SOLD_LIN,
      x.rest_doc - Nvl(SUM(sign(x.valoare)*Nvl(stingatori.s_valoare,0)*x.valoarelinie/decode(nvl(x.valoare,0),0,1, x.valoare)) OVER (PARTITION BY x.codobligpif ORDER BY x.indexlocal, stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW),0) SOLD_DOC,
      ROW_NUMBER() OVER (PARTITION BY x.codobligpif, x.coddoc1 ORDER BY stingatori.codgeneral) ORDINE, COUNT(1) OVER (PARTITION BY x.codobligpif, x.coddoc1) ORDINEMAX,
      ROW_NUMBER() OVER (PARTITION BY x.codobligpif ORDER BY x.indexlocal, stingatori.codgeneral) ORDDOC, COUNT(1) OVER (PARTITION BY x.codobligpif) ORDDOCMAX,
      stingatori.prefixdoc DSTINGPR, stingatori.nrdoc DSTINGNR, stingatori.datadoc DSTINGDATA, stingatori.DATADECONT, stingatori.DATAINC, x.TERMEN, x.termen SCADENTA, trunc(stingatori.datadoc - x.datadoc) DIFZILE,
      case when trunc(stingatori.datadoc - x.termen) &gt; 0 then trunc(stingatori.datadoc - x.termen) else 0 end DEPZILE,
      case when trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - x.termen) &gt; 0 then trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - x.termen) else 0 end DEPZILEDEC,
      case when trunc(stingatori.datainc - x.termen) &gt; 0 then trunc(stingatori.datainc - x.termen) else 0 end DEPZILEINC,
      x.codpart, Nvl(x.agent,0) agent, Nvl(stingatori.agent,0) agent_sting, x.codcont, Nvl(x.codlocatie,0) codlocatie,
      x.curs dstinscurs, x.moneda, x.subunitatea dstinssub, stingatori.subunitatea dstingsub,
      x.coddoc, x.coddoc1, x.tipdoc, x.codobiect, x.an dstinsan, x.luna dstinsluna, stingatori.an dstingan, stingatori.luna dstingluna, stingatori.an * 12 + stingatori.luna dstinganluna, stingatori.curs dstingcurs,
      CASE WHEN x.codobiect &lt;= -2 THEN x.codbanca ELSE stingatori.codbanca END codbanca, x.contserv, NVL(stingatori.contbanca,x.contbanca) contbanca
    FROM (
      SELECT
        stinsi.*,
        CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(stinsi.valoarelinie,0) ELSE NVL(crs_sold.rest,0) END rest_lin,
        SUM(CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(stinsi.valoarelinie,0) ELSE NVL(crs_sold.rest,0) END) OVER (PARTITION BY stinsi.codobligpif) rest_doc
      FROM stinsi LEFT JOIN crs_sold ON crs_sold.codobligpif = stinsi.codobligpif
      WHERE (NVL(crs_sold.rest,0) &lt;&gt; 0 OR crs_sold.rest IS NULL) AND stinsi.valoarelinie &lt;&gt; 0
    ) x &apos;||sTipJoin||&apos; JOIN stingatori ON stingatori.codstinspif = x.codobligpif)
  SELECT
    DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc1) NAV_CodDoc1, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_TipDoc) NAV_TipDoc, &apos;&apos;Incasare&apos;&apos;,
    UN.DSTINSPR, UN.DSTINSNR, UN.DSTINSDATA, UN.TOTAL_LIN, UN.TOTAL_LIN * UN.COEFTVA, UN.REST, UN.REST * UN.COEFTVA, UN.VAL_STINGATOR, UN.VAL_STINGATOR * UN.COEFTVA,
    UN.DSTINGPR, UN.DSTINGNR, UN.DSTINGDATA, NPART.DEN_PART, AG.OBS,
    UN.SOLD_LIN, DECODE(UN.ORDINE,UN.ORDINEMAX,UN.SOLD_LIN), UN.SOLD_DOC, DECODE(UN.ORDDOC,UN.ORDDOCMAX,UN.SOLD_DOC),
    UN.DATADECONT, UN.DATAINC, UN.ORDINE, UN.ORDDOC, UN.TERMEN, MON.DEN_MONEDA, SubStins.den_subunit, SubSting.den_subunit,
    UN.SCADENTA, UN.DIFZILE, UN.DEPZILE, UN.DEPZILEDEC, UN.DEPZILEINC, C.SIMBOL, Nvl(XC.CONTART, CS.SIMBOL), CB.SIMBOL, DECODE(un.codobiect, -1, &apos;&apos;INITIALIZARE&apos;&apos;, -2, &apos;&apos;AVANS TREZORERIE&apos;&apos;, -3, &apos;&apos;DECONT CASA/BANCA&apos;&apos;, o.denumire) ARTICOL, O.CODEXTERN, O.CODINTERN, PROD.DEN_PART, CA.SIMBOL,
    UN.DSTINSCURS, UN.DSTINSAN, UN.DSTINSLUNA, UN.DSTINGCURS, UN.DSTINGAN, UN.DSTINGLUNA, DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.DEN,G1.DEN_GEST), DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.SIMB,G1.SIMBOL),
    DECODE(UN.NAV_TipDoc,33,&apos;&apos;DECONT CASA/BANCA&apos;&apos;,BC.NRCONT) &apos;||
    sCurs||gUserAlias||&apos;
  FROM UN
    LEFT JOIN iesiri              i        ON i.codies            = un.coddoc AND i.tipdoc = un.tipdoc
    LEFT JOIN iesiri1             i1       on i1.codies1          = un.coddoc1 AND i1.codies = i.codies
    LEFT JOIN nartobj             o        ON o.codobiect         = un.codobiect
    LEFT JOIN npers               ag_doc   on ag_doc.codpers      = UN.agent
    LEFT JOIN npers               ag_sting ON ag_sting.codpers    = UN.agent_sting
    LEFT JOIN npart               npart    ON npart.codpart       = UN.codpart
    LEFT JOIN nclasep             clsp     on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda             ag       on UN.codlocatie       = ag.codagenda
    LEFT JOIN nlocalit            loc      on ag.codlocalit       = loc.codlocalit
    LEFT JOIN njudet              jud      on loc.codjudet        = jud.codjudet
    LEFT JOIN nmonede             mon      ON mon.codmoneda       = nvl(UN.moneda,0)
    LEFT JOIN pretm                        on pretm.codobiect     = UN.CodObiect and pretm.implicit = 1 and pretm.subunitatea = &apos;||pkg_globals.GETSUBUNITATE||&apos;
    LEFT JOIN nsubunit            SubSting ON SubSting.codsubunit = UN.dstingsub
    LEFT JOIN nsubunit            SubStins ON SubStins.codsubunit = UN.dstinssub
    LEFT JOIN tmp_subunitdedicate ts       ON ts.codsubunit       = UN.dstingsub
    LEFT JOIN npart               prod     ON prod.codpart        = o.codproducator
    LEFT JOIN nart                a        ON a.codarticol        = o.codarticol
    LEFT JOIN nclasea             ca       ON ca.codclasea        = a.clasa
    LEFT JOIN nartobj1            n1       on n1.codobiect        = un.codobiect AND &apos;||AnLunaLucru||&apos; BETWEEN n1.ALStart and n1.ALStop
    LEFT JOIN nmonede             monprest ON monprest.codmoneda  = nvl(n1.codmoneda,0)
    LEFT JOIN nartcli             ac       ON ac.codobiect        = un.codobiect AND ac.codpart = un.codpart
    LEFT JOIN ncont               c        ON c.codcont           = un.codcont
    LEFT JOIN ncont               cs       ON cs.codcont          = un.contserv
    LEFT JOIN nbankcont           bc       ON bc.codbankcont      = un.codbanca
    LEFT JOIN nbank               b        ON b.codbank           = bc.codbank
    LEFT JOIN NBANKCONT1          nbc1     ON nbc1.codbankcont    = un.codbanca     AND un.dstinganluna BETWEEN nbc1.ALStart and nbc1.ALStop
    LEFT JOIN IOBANK1             iob1     ON iob1.codiobank      = nbc1.codiobanca AND un.dstinganluna BETWEEN iob1.ALStart and iob1.ALStop
    LEFT JOIN ncont               cb       ON cb.codcont          = Nvl(un.contbanca,iob1.cont)
    LEFT JOIN ngest               g1       ON g1.codgest          = i1.gestact
    LEFT JOIN (
      SELECT l1.codies1, l.codies, l.tiplivr, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.den_gest) AS vc2_nt)) DEN, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.simbol) AS vc2_nt)) SIMB
      FROM livr1 l1
        INNER JOIN livr    l  ON l.codlivr     = l1.codlivr
        LEFT  JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        LEFT  JOIN nir     n  ON n.codnir      = ns.codnir
        LEFT  JOIN livrval lv ON lv.codlivr1   = l1.codlivr1
        LEFT  JOIN ngest   ng On ng.codgest    = coalesce(lv.gest, n.gest, 0)
      WHERE ng.codgest &lt;&gt; 0
      GROUP BY l1.codies1, l.codies, l.tiplivr
    ) g2 ON g2.codies1 = i1.codies1 AND g2.codies = i.codies AND g2.tiplivr = i.tipdoc
    LEFT JOIN (
      SELECT
        i1.codies1,
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT c.simbol) AS vc2_nt)) contart
      FROM iesiri i
        INNER JOIN iesiri1 i1   ON i.codies      = i1.codies
        LEFT  JOIN ieslink ilae ON ilae.codies1  = i1.codies1
        LEFT  JOIN iesiri1 ae1  ON ae1.codies1   = ilae.codlinieaviz
        LEFT  JOIN iesiri  ae   ON ae.codies     = ae1.codies
        LEFT  JOIN livr    l    ON l.codies      = NVL(ae.codies,i.codies) AND l.tiplivr = NVL(ae.tipdoc,i.tipdoc)
        LEFT  JOIN livr1   l1   ON l1.codies1    = NVL(ae1.codies1,i1.codies1) AND l1.codlivr = l.codlivr
        LEFT  JOIN livrval lv   ON lv.codlivr1   = l1.codlivr1
        LEFT  JOIN nirstoc ns   ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN ioart1  ioa1 ON ioa1.codioart = Nvl(lv.codioart,ns.codioart) AND (i.an*12+i.luna) BETWEEN ioa1.ALStart and ioa1.ALStop
        INNER JOIN ncont   c    ON c.codcont     = ioa1.cont
      WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 0 AND NVL(i1.codobiect,0) &lt;&gt; 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos; 
      GROUP BY i1.codies1
    ) xc ON xc.codies1 = i1.codies1 &apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_rapincplatiart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTAGENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFFC8E8653176B2E39D2DE0994BCF2319C1B1760</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTAGENTI IS

  vTipData     BOOLEAN;
  vInceput     VARCHAR2(50);
  vSfarsit     VARCHAR2(50);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS  (pTipData IN NUMBER, pInceput IN VARCHAR2, pSfarsit IN VARCHAR2, v_codjob1 in number) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  dDataS     Date;
  dDataF     Date;
BEGIN
  vTipData     := pTipData = 1;
  IF vTipData THEN
    dDataS     := To_Date(pInceput,&apos;dd.mm.yyyy&apos;);
    dDataF     := To_Date(pSfarsit,&apos;dd.mm.yyyy&apos;);
    xLunaAnIni := extract(year from dDataS)*12+extract(month from dDataS);
    xLunaAnFin := extract(year from dDataF)*12+extract(month from dDataF);
  ELSE
    dDataS     := To_Date(&apos;01.&apos;||pInceput||&apos;.&apos;||PKG_GLOBALS.ANLUCRU,&apos;dd.mm.yyyy&apos;); 
    dDataF     := Last_Day(To_Date(pSfarsit||&apos;.&apos;||PKG_GLOBALS.ANLUCRU,&apos;mm.yyyy&apos;));
    xLunaAnIni := PKG_GLOBALS.ANLUCRU*12+To_Number(pInceput); 
    xLunaAnIni := PKG_GLOBALS.ANLUCRU*12+To_Number(pSfarsit); 
  END IF;

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  IF vTipData THEN
    vInceput   := &apos;To_Date(&apos;&apos;&apos;||To_Char(dDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    vSfarsit   := &apos;To_Date(&apos;&apos;&apos;||To_Char(dDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    vInceput   := xLunaAnIni;
    vSfarsit   := xLunaAnIni;
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(20000);
  sSelect    VARCHAR2(20000);
  sWhereP    VARCHAR2(  300);
BEGIN
  gSuplCols := &apos;npers ag&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vTipData
  THEN sWhereP := &apos;I.DATADOC&apos;;
  ELSE sWhereP := &apos;I.An*12 + I.LUNA&apos;;
  END IF;

  IF vInceput = vSfarsit
  THEN sWhereP := sWhereP||&apos; = &apos;||vInceput;
  ELSE sWhereP := sWhereP||&apos; BETWEEN &apos;||vInceput||&apos; AND &apos;||vSfarsit;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(Agent, NrCli, NrIes, NrPromo, Val, Tva&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    CA AS (
      SELECT Min(i.codies) KEEP (Dense_Rank FIRST ORDER BY i.datadoc, i.codies) codies
      FROM iesiri i
      WHERE i.anulat = 0 AND i.operat = 1
        AND i.tipdoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
        AND Nvl(i.partener,0) &lt;&gt; 0 AND Nvl(i.codlocatie,0) &lt;&gt; 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos;
      GROUP BY i.partener, i.codlocatie, i.subunitatea),
    IG AS (
      SELECT
        NVL(I.AGENT,0) AGENT, NVL(I.PARTENER,0) PARTENER, NVL(I.CODLOCATIE,0) CODLOCATIE, I.CODIES,
        MAX(CASE WHEN NVL(I1.CADOU,0) = 1 THEN 1 WHEN NVL(AE1.CADOU,0) = 1 THEN 1 WHEN NVl(I1.PU,0) = 0 THEN 1 ELSE 0 END) Cadou,
        I.ValDoc, I.TVADoc
      FROM IESIRI I
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
        INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
        LEFT JOIN IESLINK IL ON IL.CODIES1 = I1.CODIES1
        LEFT JOIN IESIRI1 AE1 ON AE1.CODIES1 = IL.CODLINIEAVIZ
      WHERE &apos;||sWhereP||&apos;
        AND I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      GROUP BY I.CODIES, NVL(I.AGENT,0), I.PARTENER, I.CODLOCATIE, I.ValDoc, I.TVADoc),
    G AS (
      SELECT
        AGENT,
        --COUNT(DISTINCT PARTENER||&apos;&apos;_&apos;&apos;||CODLOCATIE) NrCli,
        SUM(Decode(CA.CODIES,NULL,0,1)) NrCli,
        COUNT(1) NrIes, Sum(Cadou) NrPromo, Sum(ValDoc) Val, Sum(TvaDoc) Tva
      FROM IG LEFT JOIN CA ON CA.CODIES = IG.CODIES
      GROUP BY AGENT)
  SELECT DECODE(G.AGENT,0,AG.NUME,AG.NUME||&apos;&apos; &apos;&apos;||AG.PRENUME) AGENT, G.NrCli, G.NrIes, G.NrPromo, G.VAL, G.TVA
  FROM G LEFT JOIN NPERS AG ON AG.CODPERS = G.AGENT&apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

END PKG_LIST_BASE_RAPORTAGENTI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTCUMPARARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2D8DA8BB6E9D6CFE52ED845152F21141F8CD2A7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTCUMPARARI IS

  vTipData     BOOLEAN;
  vInceput     VARCHAR2(50);
  vSfarsit     VARCHAR2(50);
  xInceput     VARCHAR2(50);
  xSfarsit     VARCHAR2(50);
  vTipTarget   INTEGER; -- 0 fara analiza ; 1 analiza furnizor
  vValuta      BOOLEAN;
  vCatPret     NUMBER;
  vAllPart     NUMBER;  -- 0 toti, 1 include, 2 exclude

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS  (
  pTipData   IN NUMBER, 
  pInceput   IN VARCHAR2, 
  pSfarsit   IN VARCHAR2, 
  pTipTarget IN NUMBER, 
  pValuta    IN NUMBER, 
  pCatPret   IN NUMBER DEFAULT 0, 
  pAllPart   IN NUMBER DEFAULT 0, 
  V_CODJOB1  IN NUMBER
) IS
  dDataS     DATE;
  dDataF     DATE;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vTipTarget := pTipTarget;
  vValuta    := pValuta = 1;
  vCatPret   := pCatPret;
  vAllPart   := pAllPart;

  vTipData   := pTipData = 1;
  IF vTipData THEN
    dDataS   := To_Date(pInceput,&apos;dd.mm.yyyy&apos;);
    dDataF   := To_Date(pSfarsit,&apos;dd.mm.yyyy&apos;);
  ELSE
    dDataS   :=          Trunc(To_Date(PKG_GLOBALS.ANLUCRU||&apos;.&apos;||pInceput,&apos;yyyy.mm&apos;),&apos;mm&apos;);
    dDataF   := Last_Day(Trunc(To_Date(PKG_GLOBALS.ANLUCRU||&apos;.&apos;||pSfarsit,&apos;yyyy.mm&apos;),&apos;mm&apos;));
  END IF;

	xLunaAnIni := extract(year from dDataS)*12+extract(month from dDataS);
	xLunaAnFin := extract(year from dDataF)*12+extract(month from dDataF);
	IF NVL(v_CodJob1,0) &gt; 0 THEN
		PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,xLunaAnIni,xLunaAnFin);
	END IF;
  xInceput := &apos;To_Date(&apos;&apos;&apos;||TO_Char (dDataS ,&apos;dd.mm.yyyy&apos;) ||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  xSfarsit := &apos;To_Date(&apos;&apos;&apos;||TO_Char (dDataF ,&apos;dd.mm.yyyy&apos;) ||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  IF vTipData THEN
    vInceput := xInceput;
    vSfarsit := xSfarsit;
  ELSE
    vInceput := extract(month from dDataS);
    vSfarsit := extract(month from dDataF);
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  sSelect      VARCHAR2(30000);
  sWhereP      VARCHAR2( 1000);
  sCurs        VARCHAR2(  300);
  sInsertUMA   VARCHAR2( 1000);
  sSelectUMA   VARCHAR2( 5000);
  sSelectIG    VARCHAR2(  500);
  sFiltruPart  VARCHAR2(  500) := &apos;&apos;;
  sFromIG      VARCHAR2( 1000);
  sJoinIG      VARCHAR2( 1000);
  sWhereIG     VARCHAR2( 1000);
  sGroupIG     VARCHAR2(  500);
  sWith        VARCHAR2( 5000);
  sJoin        VARCHAR2( 2000);
  aSitV        NUMBER(1);
  aBancaV      NUMBER(20);
  aMonedaV     NUMBER(20);
  sCondCatPret VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;nartobj nao, nart na, num num, npers ag, nclasea nca, nclaseas ncs, npart prod, npart np, nclasep ncp, nagenda sed, nlocalit sedl, pretm p&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sWhereP :=&apos;
      AND &apos;;

  IF vTipData
  THEN sWhereP := sWhereP||&apos;I.DATADOC&apos;;
  ELSE sWhereP := sWhereP||&apos;I.An = &apos;||PKG_GLOBALS.ANLUCRU||&apos; AND I.LUNA&apos;;
  END IF;

  IF vInceput = vSfarsit
  THEN sWhereP := sWhereP||&apos; = &apos;||vInceput;
  ELSE sWhereP := sWhereP||&apos; BETWEEN &apos;||vInceput||&apos; AND &apos;||vSfarsit;
  END IF;

  IF vAllPart = 1 THEN
    sFiltruPart := &apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  IF vAllPart = 2 THEN
    sFiltruPart := &apos; NOT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  IF sFiltruPart IS NOT NULL THEN
    sWhereP := sWhereP ||&apos;
        AND I.PARTENER&apos;||sFiltruPart;
  END IF;

  IF vValuta AND pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCurs := &apos; / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i1.datadoc )&apos;;
  END IF;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;ig.cant&apos;,&apos;ig.codobiect&apos;,sInsertUMA,sSelectUMA,sJoin);

  IF vTipTarget = 1 THEN -- target furnizor
    sSelectIG := &apos;
        0 AGENT, T.FURNIZOR PARTENER, 0 CODLOCATIE,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END CLASAS,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END CLASA,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT  WHEN 2 THEN O.CODOBIECT    ELSE 0 END CODOBIECT,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET, 1 CountFurn,&apos;;
    sFromIG := &apos;TARGET T
        LEFT JOIN I1 ON T.FURNIZOR = I1.PARTENER AND I1.DATADOC BETWEEN T.DATASTART AND T.DATASTOP AND I1.CANT &lt;&gt; 0
          AND CASE T.TIPTARGET WHEN 0 THEN T.CODOBIECT ELSE I1.CODOBIECT END = I1.CODOBIECT
          AND CASE T.TIPTARGET WHEN 2 THEN T.CLASA     ELSE I1.CLASA     END = I1.CLASA
          AND CASE T.TIPTARGET WHEN 3 THEN T.CLASAS    ELSE I1.CLASAS    END = I1.CLASAS
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = Coalesce(I1.CODOBIECT, T.CODOBIECT)
        LEFT JOIN NART A ON A.CODARTICOL = O.CODOBIECT&apos;;
    sJoinIG  := &apos;&apos;;
    sGroupIG := &apos;T.FURNIZOR,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT  WHEN 2 THEN O.CODOBIECT    ELSE 0 END,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET&apos;;
    sWith := sWith||&apos;TARGET AS (
    SELECT
      T.CLIENT FURNIZOR, T.DATASTART, T.DATASTOP, Coalesce(T.TIPTARGET,0) TIPTARGET,
      T1.CODOBIECT, C.CLASABAZA, C.CLASA, CS.CLASASBAZA, CS.CLASAS,
      Coalesce(T1.CANT,0) CANTTARGET, Coalesce(T1.VALOARE,0) VALTARGET, Coalesce(T1.MASA,0) MASATARGET, Coalesce(T1.Volum,0) VOLUMTARGET
    FROM TARGETAG T
      INNER JOIN TARGETAG1 T1 ON T1.CODTARGETAG = T.CODTARGETAG
      LEFT JOIN (
        SELECT connect_by_root codclasea clasabaza, codclasea clasa
        FROM nclasea
        CONNECT BY codparinte = PRIOR codclasea
      ) C ON C.CLASABAZA = CASE T.TIPTARGET WHEN 2 THEN T1.CODCLASA ELSE 0 END
      LEFT JOIN (
        SELECT connect_by_root codclaseas clasasbaza, codclaseas clasas
        FROM nclaseas
        CONNECT BY codparinte = PRIOR codclaseas
      ) CS ON CS.CLASASBAZA = CASE T.TIPTARGET WHEN 3 THEN T1.CODCLASAS ELSE 0 END
    WHERE T.TIPDOC = 98
      AND T.DATASTART &lt;= &apos;||xSfarsit||&apos;
      AND T.DATASTOP &gt;= &apos;||xInceput||&apos;
      AND T.ANULAT = 0 AND T.OPERAT = 1 AND T.ACTIV = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
    CASE
      WHEN sFiltruPart IS NOT NULL THEN &apos;
      AND T.CLIENT&apos;||sFiltruPart
    END||&apos;),&apos;;
  ELSE
    sSelectIG := &apos;
        I1.AGENT, I1.PARTENER, I1.CODLOCATIE,
        I1.CLASA,
        I1.CLASAS,
        I1.CODOBIECT,
        0 CANTTARGET, 0 VALTARGET, 0 MASATARGET, 0 VOLUMTARGET, 0 TIPTARGET, COUNT(DISTINCT I1.PARTENER||&apos;&apos; &apos;&apos;||I1.CODLOCATIE) CountFurn,&apos;;
    sFromIG := &apos;I1
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT&apos;;
    sWhereIG := &apos;
      WHERE i1.cant &lt;&gt; 0&apos;;
    sGroupIG  := &apos;I1.AGENT, I1.PARTENER, I1.CODLOCATIE, I1.CLASA, I1.CLASAS, I1.CODOBIECT&apos;;
  END IF;

  sCondCatPret := &apos; AND P.Subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE;
	IF Coalesce(vCatPret,0) = 0
  THEN sCondCatPret := sCondCatPret||&apos; AND p.implicit = 1 &apos;;
  ELSE sCondCatPret := sCondCatPret||&apos; AND p.codcatpret = &apos;||vCatPret;
  END IF;


  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    Art,
    UM, Cant, Val, ValCuTva, VU, Masa, Volum,
    DenClasaA, CodInt, CodExt, Prod, PretVinz, PretValuta,
    Agent, NrFurn,
    Furnizor, DenClasaF, SedFurn, AdrSedFurn, NrUtilaje,
    TarTip,
    TarCant, TarVal, TarMasa, TarVolum&apos;||sInsertUMA||gUserFields||&apos;
  )&apos;;

  sSelect := &apos;
  WITH &apos;||sWith||&apos;
  I1 AS (
    SELECT
      I.CODINTR, I1.CODINTR1, I.DATADOC, Coalesce(NULLIF(I.CURS,0),1) CURS, Coalesce(I.AGENT,0) AGENT, I.PARTENER, Coalesce(I.CODLOCATIE,0) CODLOCATIE,
      I1.CODOBIECT, Coalesce(A.CLASA,0) CLASA, Coalesce(A.CLASASTATIST,0) CLASAS, I1.CANT, I1.PU, I.VALDOC-I.TVADOC VALDOC, I.VALDOC VALTDOC,
      CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*(1-CASE WHEN i.tipdoc = 3 THEN Coalesce(i1.tva,0)/(i1.cant*i1.pu) ELSE 0 END) END vallin,
      CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*(1+CASE WHEN i.tipdoc = 3 THEN 0 ELSE Coalesce(i1.tva,0)/(i1.cant*i1.pu) END) END valtlin,
      SUM(CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*(1-CASE WHEN i.tipdoc = 3 THEN Coalesce(i1.tva,0)/(i1.cant*i1.pu) ELSE 0 END) END) OVER (PARTITION BY I.CODINTR) VALINTR,
      SUM(CASE WHEN i1.cant*i1.pu = 0 THEN 0 ELSE i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*(1+CASE WHEN i.tipdoc = 3 THEN 0 ELSE Coalesce(i1.tva,0)/(i1.cant*i1.pu) END) END) OVER (PARTITION BY I.CODINTR) VALTINTR,
      ROW_NUMBER() OVER (PARTITION BY I.CODINTR ORDER BY I1.CODINTR1) IDX
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
      INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
    WHERE I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;) AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
      sWhereP||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;),
  IG AS (
    SELECT &apos;||
      sSelectIG||&apos;
      SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(NS.CANTNIR,0) &lt;&gt; 0 THEN NS.CANTNIR*I1.CANT/AE1.CANT ELSE COALESCE(NS.CANTNIR,I1.CANT,0) END) CANT,
      SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(NS.CANTNIR,0) &lt;&gt; 0 THEN NS.CANTNIR*I1.CANT/AE1.CANT ELSE COALESCE(NS.CANTNIR,I1.CANT,0) END*Coalesce(O.MASA,0)) MASA,
      SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(NS.CANTNIR,0) &lt;&gt; 0 THEN NS.CANTNIR*I1.CANT/AE1.CANT ELSE COALESCE(NS.CANTNIR,I1.CANT,0) END*Coalesce(O.VOLUM,0)) VOLUM,
      Coalesce(SUM(i1.pu*i1.cant*i1.curs&apos;||sCurs||&apos;),0) vu,
      Coalesce(SUM(i1.vallin *CASE WHEN i1.valintr  = 0 THEN 1 ELSE i1.valdoc /i1.valintr  END*i1.curs&apos;||sCurs||&apos;),0) val,
      Coalesce(SUM(i1.valtlin*CASE WHEN i1.valtintr = 0 THEN 1 ELSE i1.valtdoc/i1.valtintr END*i1.curs&apos;||sCurs||&apos;),0) valcutva
    FROM &apos;||sFromIG||&apos;
      LEFT JOIN INTRLINK IL ON IL.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRARI1 AE1 ON AE1.CODINTR1 = IL.CODLINIEAVIZ
      LEFT JOIN NIR N ON N.CODINTR = Coalesce(AE1.CODINTR,I1.CODINTR)
      LEFT JOIN NIRSTOC NS ON NS.CODINTR1 = Coalesce(IL.CODLINIEAVIZ,I1.CODINTR1) AND NS.CODNIR = N.CODNIR&apos;||
      sJoinIG||
    sWhereIG||&apos;
    GROUP BY &apos;||sGroupIG||&apos; )
  SELECT
    CASE
      WHEN Coalesce(NAO.CODOBIECT, 0) &lt;&gt; 0 THEN NAO.DENUMIRE
      WHEN Coalesce(NCA.CODCLASEA, 0) &lt;&gt; 0 THEN NCA.DEN_CLASEA
      WHEN Coalesce(NCS.CODCLASEAS,0) &lt;&gt; 0 THEN NCS.DEN_CLASEAS
      ELSE &apos;&apos;...&apos;&apos;
    END,
    Coalesce(NUM.DEN_UM,&apos;&apos;...&apos;&apos;), CASE WHEN IG.CODOBIECT = 0 THEN 0 ELSE IG.CANT END, IG.VAL, IG.VALCUTVA, IG.VU, IG.MASA, IG.VOLUM,
    NCA.DEN_CLASEA, NAO.CODINTERN, NAO.CODEXTERN, PROD.DEN_PART, P.LEI PRETVANZ, P.VALUTA,
    NUMEPRENUME(AG.NUME,AG.PRENUME) Agent, IG.CountFurn NrFurn,
    NP.DEN_PART Furnizor, NCP.DEN_CLASEP DenClasaF, SED.OBS SedFurn, SEDL.DEN_LOCALIT||&apos;&apos; &apos;&apos;||GETADRESA(SED.SECTOR,SED.STRADA,SED.NR1,SED.NR2,SED.BLOC,SED.SCARA,SED.ETAJ,SED.APART,SED.CODPOSTAL) AdrSedFurn, SED.COEFUTILAJE NrUtilaje,
    CASE IG.TIPTARGET
      WHEN NULL THEN &apos;&apos; &apos;&apos;
      WHEN    3 THEN &apos;&apos;Pe clase statistice de articole&apos;&apos;
      WHEN    2 THEN &apos;&apos;Pe clase de articole&apos;&apos;
      WHEN    1 THEN &apos;&apos;Toate Articolele&apos;&apos;
      WHEN    0 THEN &apos;&apos;Pe articole&apos;&apos;
    END TarTip,
    IG.CANTTARGET TarCant, IG.VALTARGET TarVal, IG.MASATARGET TarMasa, IG.VOLUMTARGET TarVolum &apos;||
    sSelectUMA||gUserAlias||&apos;
  FROM IG
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = IG.CODOBIECT
    LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = IG.CLASA
    LEFT JOIN NCLASEAS NCS ON NCS.CODCLASEAS = IG.CLASAS
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NPART NP ON NP.CODPART = IG.PARTENER
    LEFT JOIN NCLASEP NCP ON NCP.CODCLASEP = NP.CODCLASA
    LEFT JOIN NAGENDA SED ON SED.CODAGENDA = IG.CODLOCATIE
    LEFT JOIN NLOCALIT SEDL ON SEDL.CODLOCALIT = SED.CODLOCALIT
    LEFT JOIN NPERS AG ON AG.CODPERS = IG.AGENT
    LEFT JOIN PRETM P ON P.CODOBIECT = IG.CODOBIECT &apos;||sCondCatPret||
    sJoin||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

END pkg_list_base_raportcumparari;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTCVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>443E2838533E14C9DD4DAA6FF8D98C4BFB2C9A9D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTGESTCVAL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  PKG_LIST_STRUCT.SetTableSpec(gSuplCols);
  PKG_LIST_STRUCT.AdunaColoanele;
END;

FUNCTION JOINTMP(vCamp VARCHAR2) RETURN VARCHAR2
IS
BEGIN
  IF PKG_LIST_SELECTGEST2.ToateGest
  THEN RETURN NULL;
  ELSE RETURN &apos;
        INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = &apos;||vcamp||&apos; AND TMP.FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
  sInsert     CLOB;--VARCHAR2(  500);
  sSelect     CLOB;--VARCHAR2(32000);
  sDataIni    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaIni,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sDataFin    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaFin,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sCondData   VARCHAR2(  100);
  sCondIOArt  VARCHAR2(  500) := &apos;&apos;;
  vGestAcces  INTEGER;
  pGest       VARCHAR2(  500);
BEGIN
  vGestAcces := to_number(Coalesce(pkg_categconst.GetValConstanta(&apos;GestAccesListeStoc&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),&apos;2&apos;));
  if vGestAcces &lt;&gt; 1 then
	  pGest := &apos; AND PKG_NOMGEST.GESTIUNE_DEDICATA(NG.CODGEST) &gt; 0 &apos;;
  end if;

  gSuplCols := &apos;NGEST NG, NPERS OPER&apos;;
  pkg_list_struct.StartSuplCols;
  --pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;,   &apos;&apos;,   &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  IF PKG_LIST_SELECTGEST2.ZiuaIni = PKG_LIST_SELECTGEST2.ZiuaFin
  THEN sCondData := &apos; = to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSE sCondData := &apos; BETWEEN to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND to_date(&apos;&apos;&apos;||sDataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  END IF;

  IF NOT PKG_LIST_SELECTGEST2.ToateIOART THEN
    sCondIOArt := &apos;
        AND IO.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;)&apos;;
  ELSE
    if not AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
      sCondIOArt := &apos;
        AND IO1.DIFPRET = 1 &apos;;
    end if;
  END IF;

  sInsert :=
   &apos;INSERT INTO &apos;||tmpName||&apos; (
      NAV_CodDoc, NAV_TipDoc, PrefixDoc, NrDoc, DataDoc, DataNirLivr, Document, TipDoc, PROVSI,
      AdDebit, ValDFTVA, ValDCTVA, TVAD, PROVD,
      AdCredit, ValCFTVA, ValCCTVA, TVAC, PROVC,
      SoldFinFTVA, SoldFinCTVA, SoldAd,
      SursaDest, DenIOART, SoldIn, AchizIn, Coef,
      DenGest, DenCONT, SimbCONT, RecLivr, Zi, ZiDoc &apos;||gUserFields||&apos; )&apos;;

  sSelect := &apos;
    WITH
     IOA1 AS (
      SELECT IO.CODIOART, IO.DEN_IOART, NC.DEN_CONT, NC.SIMBOL SIMB_CONT
      FROM IOART1 IO1
        INNER JOIN IOART IO ON IO.CODIOART = IO1.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IO1.ALStart and IO1.ALStop &apos;|| sCondIOArt||&apos;
        LEFT  JOIN NCONT NC ON NC.CODCONT  = IO1.CONT
     ),
     SM AS (
      SELECT N.GEST, NS.CODIOART, Coalesce(NS.TVA,0) TVA, NSM.REST * NS.PRET SOLD, NSM.REST * NS.ADAOS ADAOS, NS.CANTNIR * NS.PRET SOLDINTR, NS.CANTNIR * NS.ADAOS ADAOSINTR, NULL USERID, Coalesce(NSM.REST * NS.PROVIZION,0) PROVSI
      FROM (
        SELECT   CODNIRSTOC, SUM (REST) REST
        FROM   (
          SELECT CODNIRSTOC, REST
          FROM NIRLUNA
          WHERE (AN * 12 + LUNA + 1) = &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
          UNION ALL
          SELECT NS.CODNIRSTOC, NS.CANTNIR REST
          FROM NIRSTOC NS
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
          WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
            AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
            AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
          UNION ALL
          SELECT NS.CODNIRSTOC, NS.CANTNIR REST
          FROM NIRSTOC NS
            INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
            INNER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
          WHERE T.TIPDOC IN (12, 13) AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
            AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
            AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
          UNION ALL
          SELECT L1.CODNIRSTOC, - L1.CANT REST
          FROM LIVR1 L1
            INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
            INNER JOIN INTRARI I ON I.CODINTR = L.CODINTR
          WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
            AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
            AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
          UNION ALL
          SELECT L1.CODNIRSTOC, - L1.CANT REST
          FROM LIVR1 L1
            INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
            INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
          WHERE T.TIPDOC IN (12, 13) AND T.OPERAT = 1 AND T.ANULAT = 0
            AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
            AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
          UNION ALL
          SELECT L1.CODNIRSTOC, DECODE(I.TIPDOC,15,1,-1) * L1.CANT REST
          FROM LIVR1 L1
            INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
            INNER JOIN IESIRI I ON I.CODIES = L.CODIES
          WHERE I.TIPDOC IN (14, 15, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
            AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
            AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) )
        GROUP BY CODNIRSTOC ) NSM
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NSM.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST
        &apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      UNION ALL -- STOC INI. VALORIC
      SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, NULL USERID, 0 PROVSI
      FROM STOCVALLUNA SVL &apos;||JOINTMP(&apos;SVL.GEST&apos;)||&apos;
      WHERE (AN * 12 + LUNA + 1)= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
      UNION ALL -- LIVRARI VALORICE
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG * L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR, NULL USERID, 0 PROVSI
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
        INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
        INNER JOIN INTRARI I ON I.CODINTR = L.CODINTR
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- LIVRARI VALORICE
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG * L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR, NULL USERID, 0 PROVSI
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
        INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
        INNER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
      WHERE T.TIPDOC IN (12, 13) AND T.OPERAT = 1 AND T.ANULAT = 0
        AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      UNION ALL -- LIVRARI VALORICE
      SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA,
        DECODE(I.TIPDOC,15,1,-1) * LV.PRETINREG * L1.CANT SOLD, DECODE(I.TIPDOC,15,1,-1) * (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT ADAOS,
        DECODE(I.TIPDOC,15,LV.PRETINREG * L1.CANT,0) SOLDINTR, DECODE(I.TIPDOC,15,(LV.PRETINREG - LV.PRETACHIZ) * L1.CANT,0) ADAOSINTR, NULL USERID, 0 PROVSI
      FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
        INNER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
        INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
        INNER JOIN IESIRI I ON I.CODIES = L.CODIES
      WHERE I.TIPDOC IN (14, 15, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
        AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
        AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) )
    --END WITH
    SELECT
      NULL CodDoc, NULL TipDoc, &apos;&apos; &apos;&apos; PrefixDoc, NULL NrDoc, to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DataDoc, to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DATANIRLIVR, &apos;&apos;Sold initial&apos;&apos; Doc, &apos;&apos; &apos;&apos; TipDoc,  SUM(SM.PROVSI),
      0 AdDebit,  0 ValDFTva, 0 ValDCTva, 0 TVAD, 0 PROVD,
      0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      SUM(SM.SOLD / (1+SM.TVA)) SoldFinFTva, SUM(SM.SOLD) SoldFinCTva, SUM(SM.ADAOS - SM.SOLD*Coalesce(SM.TVA,0)/Coalesce(1+SM.TVA,1)) SoldAd,
      NULL SursaDest, IOA1.DEN_IOART,
      SUM(SM.SOLDINTR) SoldIn, SUM(SM.SOLDINTR - SM.ADAOSINTR) AchizIn,
      DECODE(SUM(SM.SOLDINTR - SM.ADAOSINTR),0,0,  SUM(SM.SOLDINTR) / SUM(SM.SOLDINTR - SM.ADAOSINTR)) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      NULL RecLivr, &apos;&apos;0&apos;&apos; Zi, &apos;&apos;0&apos;&apos; ZiDoc &apos;||gUserAlias||&apos;
    FROM SM
      INNER JOIN IOA1 ON IOA1.CODIOART = SM.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = SM.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = SM.USERID&apos;||
      gSuplJoins||&apos;
    WHERE 1 = 1 &apos;||pGest||&apos;
    GROUP BY NG.DEN_GEST, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT&apos;||gUserAlias||&apos;
    UNION ALL -- INTRARI
    SELECT
      I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, N.DATANIR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) AdDebit, SUM(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
      SUM(NS.CANTNIR * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TVAD, SUM(NS.CANTNIR * Coalesce(NS.PROVIZION,0)) PROVD,
      0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      SUM(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, SUM(NS.CANTNIR * NS.PRET) SoldFinCTva, 0 SoldAd,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
      SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn,
      DECODE(SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)),0,0,SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS))) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM NIRSTOC NS
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||pGest||&apos;
      AND N.DATANIR&apos;||sCondData||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- INTRARI DIN TRANSFERURI
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, N.DATANIR DATANIRLIVR, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), 0 PROVSI,
      SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) AdDebit, SUm(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
      SUM(NS.CANTNIR * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TVAD, SUM(NS.CANTNIR * Coalesce(NS.PROVIZION,0)) PROVD,
      0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      SUM(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, SUM(NS.CANTNIR * NS.PRET) SoldFinCTva, 0 SoldAd,
      NG_S.DEN_GEST SursaDest, IOA1.DEN_IOART,
      SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn,
      DECODE(SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)),0,0,SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS))) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR&apos;||&apos;,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM TRANSF T
      INNER JOIN NIR N ON N.CODTRANSF = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
      LEFT JOIN NIR N_S ON N_S.CODNIR = NS_S.CODNIR
      LEFT JOIN LIVRVAL LV_S ON LV_S.CODLIVR1 = NS.CODLIVR1
      LEFT JOIN NGEST NG_S ON NG_S.CODGEST = Coalesce(N_S.GEST,LV_S.GEST)
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = T.USERID&apos;||
      gSuplJoins||&apos;
    WHERE T.TIPDOC = 12 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1 &apos;||pGest||&apos;
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND N.DATANIR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- IESIRI PRIN TRANSFER STOC
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, L.DATALIVR DATANIRLIVR, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), 0 PROVSI,
      0 Addebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD, 0 PROVD,
      SUM(NS_D.CANTNIR * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) Adcredit, SUM(NS_D.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) ValCFTva, SUM(NS_D.CANTNIR * NS.PRET) ValCCTva,
      SUM(NS_D.CANTNIR * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TvaC, SUM(NS_D.CANTNIR * Coalesce(NS.PROVIZION,0)) PROVC,
      -SUM(NS_D.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, -SUM(NS_D.CANTNIR * NS.PRET) SoldFinCTva, 0 SoldAd,
      NG_D.DEN_GEST SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM TRANSF T
      INNER JOIN LIVR L ON L.CODTRANSF = T.CODTRANSF
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      INNER JOIN NIRSTOC NS_D ON NS_D.CODLIVR1 = L1.CODLIVR1
      INNER JOIN NIR N_D ON N_D.CODNIR = NS_D.CODNIR
      LEFT JOIN NGEST NG_D ON NG_D.CODGEST = N_D.GEST
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = T.USERID&apos;||
      gSuplJoins||&apos;
    WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0 &apos;||pGest||&apos;
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC,  L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_D.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- IESIRI PRIN TRANSFER VALORIC
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, L.DATALIVR DATANIRLIVR, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), 0 PROVSI,
      0 Addebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD, 0 PROVD,
      SUM(NS_D.CANTNIR * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdCredit,
      SUM(NS_D.CANTNIR * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(NS_D.CANTNIR * LV.PRETINREG) ValCCTva,
      SUM(NS_D.CANTNIR * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaC, 0 PROVC,
      -SUM(NS_D.CANTNIR * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(NS_D.CANTNIR * LV.PRETINREG) SoldFinCTva, 0 SoldAd,
      NG_D.DEN_GEST SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM TRANSF T
      INNER JOIN LIVR L ON L.CODTRANSF = T.CODTRANSF
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = LV.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      INNER JOIN NIRSTOC NS_D ON NS_D.CODTRANSF1 = L1.CODIES1
      INNER JOIN NIR N_D ON N_D.CODNIR = NS_D.CODNIR
      LEFT JOIN NGEST NG_D ON NG_D.CODGEST = N_D.GEST
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = T.USERID&apos;||
      gSuplJoins||&apos;
    WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0 &apos;||pGest||&apos;
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_D.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- MODIFICARI DE PRET
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, N.DATANIR DATANIRLIVR, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), 0 PROVSI,
      SUM(NS.CANTNIR * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) AdDebit, SUm(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) ValDFTva, SUM(NS.CANTNIR * NS.PRET) ValDCTva,
      SUM(NS.CANTNIR * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TVAD, SUM(NS.CANTNIR * Coalesce(NS.PROVIZION,0)) PROVD,
      SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,(LV_S.PRETINREG / (1+LV_S.TVANEEX) - LV_S.PRETACHIZ),(NS_S.ADAOS - NS_S.PRET * NS_S.TVA / (1+NS_S.TVA)))) AdCredit,
      SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,LV_S.PRETINREG / (1+LV_S.TVANEEX), NS_S.PRET / (1+NS_S.TVA))) ValCFTva,
      SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,LV_S.PRETINREG,NS_S.PRET)) ValCCTva,
      SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,LV_S.PRETINREG * LV_S.TVANEEX / (1+LV_S.TVANEEX),NS_S.PRET * NS_S.TVA / (1+NS_S.TVA))) TvaC, SUM(NS.CANTNIR * Coalesce(NS_S.PROVIZION,0)) PROVC,
      SUM(NS.CANTNIR * NS.PRET / Coalesce(1+NS.TVA,1)) - SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,LV_S.PRETINREG / (1+LV_S.TVANEEX),NS_S.PRET / (1+NS_S.TVA)))  SoldFinFTva,
      SUM(NS.CANTNIR * NS.PRET) - SUM(NS.CANTNIR * DECODE(NS.CODNIRSTOCPARINTE,NULL,LV_S.PRETINREG,NS_S.PRET)) SoldFinCTva, 0 SoldAd,
      NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
      SUM(NS.CANTNIR * NS.PRET) SoldIn, SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)) AchizIn,
      DECODE(SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS)),0,0,SUM(NS.CANTNIR * NS.PRET) / SUM(NS.CANTNIR * (NS.PRET - NS.ADAOS))) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR&apos;||&apos;,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM TRANSF T
      INNER JOIN NIR N ON N.CODTRANSF = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
      LEFT JOIN NIR N_S ON N_S.CODNIR = NS_S.CODNIR
      LEFT JOIN LIVR1 L1_S ON L1_S.CODLIVR1 = NS.CODLIVR1 AND (NS.CODNIRSTOCPARINTE IS NULL)
      LEFT JOIN LIVRVAL LV_S ON LV_S.CODLIVR1 = L1_S.CODLIVR1
      LEFT JOIN NGEST NG_S ON NG_S.CODGEST = Coalesce(N_S.GEST,LV_S.GEST)
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = T.USERID&apos;||
      gSuplJoins||&apos;
    WHERE T.TIPDOC = 13 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1 &apos;||pGest||&apos;
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND N.DATANIR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- RETUR INTRARI STOC
    SELECT
      I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      - SUM(L1.CANT * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) AdDebit, - SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) ValDFTva,
      - SUM(L1.CANT * NS.PRET) ValDCTva, - SUM(L1.CANT * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TvaD, -SUM(L1.CANT * Coalesce(NS.PROVIZION,0)) PROVD,
      0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      -SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, -SUM(L1.CANT * NS.PRET) SoldFinCTva, 0 SoldAd,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM INTRARI I
      INNER JOIN LIVR L ON L.CODINTR = I.CODINTR
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- RETUR INTRARI VALORIC
    SELECT
      I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      - SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) AdDebit, - SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValDFTva,
      - SUM(L1.CANT * LV.PRETINREG) ValDCTva, - SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaD, 0 PROVD,
      0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      -SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT * LV.PRETINREG) SoldFinCTva, 0 SoldAd,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM INTRARI I
      INNER JOIN LIVR L ON L.CODINTR = I.CODINTR
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = LV.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL  -- IESIRI STOC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD, 0 PROVD,
      SUM(L1.CANT * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) Adcredit, SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) ValCFTva, SUM(L1.CANT * NS.PRET) ValCCTva,
      SUM(L1.CANT * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TvaC, SUM(L1.CANT * Coalesce(NS.PROVIZION,0)) PROVC,
      -SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, -SUM(L1.CANT * NS.PRET) SoldFinCTva, 0 SoldAd,
      DECODE(I.TIPDOC,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,NS.DEN_SUBUNIT,24,NG.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM IESIRI I
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR= L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT NS ON NS.CODSUBUNIT = I.CODSUBUNIT
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, NS.DEN_SUBUNIT, G.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL  -- IESIRI VALORIC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD, 0 PROVD,
      SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) Adcredit, SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(L1.CANT * LV.PRETINREG) ValCCTva,
      SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaC, 0 PROVC,
      -SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT * LV.PRETINREG) SoldFinCTva, 0 SoldAd,
      DECODE(I.TIPDOC,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,NS.DEN_SUBUNIT,24,NG.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
      0 SoldIn, 0 AchizIn,
      0 Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM IESIRI I
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR= L.CODLIVR
      INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = LV.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
      LEFT JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
      LEFT JOIN NSUBUNIT NS ON NS.CODSUBUNIT = I.CODSUBUNIT
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, NS.DEN_SUBUNIT, G.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- MARIRI DE STOC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      SUM(L1.CANT * (NS.ADAOS - NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1) )) AdDebit, SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) ValDFTva, SUM(L1.CANT * NS.PRET) ValDCTva,
      SUM(L1.CANT * NS.PRET * Coalesce(NS.TVA,0) / Coalesce(1+NS.TVA,1)) TVAD, SUM(L1.CANT * Coalesce(NS.PROVIZION,0)) PROVD,
      0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      SUM(L1.CANT * NS.PRET / Coalesce(1+NS.TVA,1)) SoldFinFTva, SUM(L1.CANT * NS.PRET) SoldFinCTva, 0 SoldAd,
      NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
      SUM(L1.CANT * NS.PRET) SoldIn, SUM(L1.CANT * (NS.PRET - NS.ADAOS)) AchizIn,
      DECODE(SUM(L1.CANT * (NS.PRET - NS.ADAOS)),0,0,SUM(L1.CANT * NS.PRET) / SUM(L1.CANT * (NS.PRET - NS.ADAOS))) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM IESIRI I
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST&apos;||gUserAlias||&apos;
    UNION ALL -- MARIRI DE STOC VALORIC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, L.DATALIVR DATANIRLIVR, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), 0 PROVSI,
      SUM(L1.CANT * (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdDebit, SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) ValDFTva, SUM(L1.CANT * LV.PRETINREG) ValDCTva,
      SUM(L1.CANT * LV.PRETINREG * Coalesce(LV.TVANEEX, 0) / (1+Coalesce(LV.TVANEEX, 0))) TvaD, 0 PROVD,
      0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC, 0 PROVC,
      SUM(L1.CANT * LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, SUM(L1.CANT * LV.PRETINREG) SoldFinCTva, 0 SoldAd,
      NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
      SUM(L1.CANT * LV.PRETINREG) SoldIn, SUM(L1.CANT * LV.PRETINREG) AchizIn,
      DECODE(SUM(L1.CANT * LV.PRETINREG),0,0,SUM(L1.CANT * LV.PRETINREG) / SUM(L1.CANT * LV.PRETINREG)) Coef,
      NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc &apos;||gUserAlias||&apos;
    FROM IESIRI I
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN IOA1 ON IOA1.CODIOART = LV.CODIOART
      INNER JOIN NGEST NG ON NG.CODGEST = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT JOIN NPERS OPER ON OPER.LOGONNAME = I.USERID&apos;||
      gSuplJoins||&apos;
    WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0 &apos;||pGest||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST&apos;||gUserAlias;

  DBMS_LOB.APPEND(sInsert,sSelect);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;||tmpName||&apos; SET SoldAd = AdDebit - AdCredit WHERE SoldAd = 0&apos; , aListID, aListVer);

  --EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;

END;

end PKG_LIST_BASE_RAPORTGESTCVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTPMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45BB7EEF0022785DF53E9BB72FE7F73F23ADE146</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTGESTPMP IS

FUNCTION JOINTMP(vCamp VARCHAR2) RETURN VARCHAR2
IS
BEGIN
  IF PKG_LIST_SELECTGEST2.ToateGest
  THEN RETURN NULL;
  ELSE RETURN &apos;
          INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = &apos;||vcamp||&apos; AND TMP.FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
  sDebug    CLOB;
  sInsert   CLOB;
  sSelect   CLOB;
  sDataIni  VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaIni,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sDataFin  VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaFin,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sCondData VARCHAR2(  100);
  sTipPMP   VARCHAR2(    1) := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;TipPMP&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;1&apos;);
  vTipPmp   NUMBER          := To_Number(sTipPMP);
BEGIN
  IF PKG_LIST_SELECTGEST2.ZiuaIni = PKG_LIST_SELECTGEST2.ZiuaFin
  THEN sCondData := &apos; = to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSE sCondData := &apos; BETWEEN to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND to_date(&apos;&apos;&apos;||sDataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_TipDoc, PrefixDoc, NrDoc, DataDoc, Document, TipDoc,
    ValDFTVA, ValCFTVA, SoldFinFTVA,
    SursaDest, DenIOART,
    DenGest, DenCONT, SimbCONT, RecLivr, Zi, ZiDoc )&apos;;

  sSelect := &apos;
  WITH
    IOA AS (
      SELECT IO.CODIOART, IO.DEN_IOART, C.DEN_CONT, C.SIMBOL SIMB_CONT
      FROM ioart1 io1 
        INNER JOIN ioart io ON io.codioart = io1.codioart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN io1.ALStart and io1.ALStop
        LEFT  JOIN ncont c  ON c.codcont   = io1.cont
      WHERE IO1.MG = 3),
    SM AS (
      SELECT CODOBIECT, CODIOART, GEST, SUBUNITATEA, SUM (REST*PRET) VAL
      FROM   (
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, G.CODSUBUNIT SUBUNITATEA, NL.REST,
          CASE WHEN NVL(P.PMPPREC,0) = 0 THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMPPREC END PRET
        FROM NIRLUNA NL
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
          INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
          INNER JOIN NGEST   G  ON G.CODGEST     = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
          JOINTMP(&apos;N.GEST&apos;)||&apos;
          LEFT  JOIN tmp_pmp p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = G.CODSUBUNIT&apos; END||&apos;
        WHERE (NL.AN * 12 + NL.LUNA + 1) = &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, I.SUBUNITATEA, NS.CANTNIR REST,
          NS.PRET - NVL(NS.ADAOS,0) PRET
        FROM NIRSTOC NS
          INNER JOIN IOA       ON IOA.CODIOART = NS.CODIOART
          INNER JOIN NIR     N ON N.CODNIR     = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
          INNER JOIN INTRARI I ON I.CODINTR    = N.CODINTR
        WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
          AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
          AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, T.SUBUNITATEA, NS.CANTNIR REST,
          CASE WHEN NVL(P.PMP,0) = 0 THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMPPREC END PRET
        FROM NIRSTOC NS
          INNER JOIN IOA       ON IOA.CODIOART  = NS.CODIOART
          INNER JOIN NIR     N ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
          INNER JOIN TRANSF  T ON T.CODTRANSF   = N.CODTRANSF
          LEFT  JOIN tmp_pmp p ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = T.SUBUNITATEA&apos; END||&apos;
        WHERE T.TIPDOC IN (12, 13) AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
          AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
          AND N.DATANIR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, I.SUBUNITATEA, - L1.CANT REST,
          CASE WHEN NVL(P.PMP,0) = 0 THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMPPREC END PRET
        FROM LIVR1 L1
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
          INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
          INNER JOIN INTRARI I  ON I.CODINTR     = L.CODINTR
          LEFT  JOIN tmp_pmp p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = I.SUBUNITATEA&apos; END||&apos;
        WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
          AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
          AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, T.SUBUNITATEA, - L1.CANT REST,
          CASE WHEN NVL(P.PMP,0) = 0 THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMPPREC END PRET
        FROM LIVR1 L1
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
          INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
          INNER JOIN TRANSF  T  ON T.CODTRANSF   = L.CODTRANSF
          LEFT  JOIN tmp_pmp p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = T.SUBUNITATEA&apos; END||&apos;
        WHERE T.CODTRANSF IN (12, 13) AND T.OPERAT = 1 AND T.ANULAT = 0
          AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
          AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, I.SUBUNITATEA, DECODE(I.TIPDOC,15,1,-1) * L1.CANT REST,
          CASE
            WHEN I.TIPDOC = 23 AND &apos;||vTipPmp||&apos;=1 THEN NS.PRET - NVL(NS.ADAOS,0)
            WHEN I.TIPDOC = 15 THEN NS.PRET - NVL(NS.ADAOS,0)
            WHEN I.TIPDOC = 14 AND L1.CANT &lt; 0 AND N.CODIES = I.CODIES THEN NS.PRET - NVL(NS.ADAOS,0)
            WHEN NVL(P.PMP,0) = 0 THEN NS.PRET - NVL(NS.ADAOS,0)
            ELSE P.PMP
          END PRET
        FROM LIVR1 L1
          INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
          INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
          INNER JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
          INNER JOIN IESIRI  I  ON I.CODIES      = L.CODIES
          LEFT  JOIN tmp_pmp p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = I.SUBUNITATEA&apos; END||&apos;
        WHERE I.TIPDOC IN (14, 15, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
          AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
          AND L.DATALIVR &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      )
      GROUP BY CODOBIECT, GEST, CODIOART, SUBUNITATEA
    )
    --END WITH
    SELECT
      NULL CodDoc, NULL TipDoc, &apos;&apos; &apos;&apos; PrefixDoc, NULL NrDoc, to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DataDoc, &apos;&apos;Sold initial&apos;&apos; Doc, &apos;&apos; &apos;&apos; TipDoc,
      0 ValDFTva, 0 ValCFTva,
      SUM(SM.VAL) SoldFinFTva,
      NULL SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      NULL RecLivr, &apos;&apos;0&apos;&apos; Zi, &apos;&apos;0&apos;&apos; ZiDoc
    FROM SM
      INNER JOIN IOA        ON IOA.CODIOART = SM.CODIOART
      INNER JOIN NGEST   NG ON NG.CODGEST   = SM.GEST
      LEFT  JOIN tmp_pmp p  ON P.CODOBIECT  = SM.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = SM.SUBUNITATEA&apos; END||&apos;
    GROUP BY NG.DEN_GEST, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT
    UNION ALL -- INTRARI
    SELECT
      I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
      SUM(NS.CANTNIR * (NS.PRET - NVL(NS.ADAOS,0))) ValDFTva, 0 ValCFTva,
      SUM(NS.CANTNIR * (NS.PRET - NVL(NS.ADAOS,0))) SoldFinFTva,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM NIRSTOC NS
      INNER JOIN IOA         ON IOA.CODIOART = NS.CODIOART
      INNER JOIN NIR      N  ON N.CODNIR     = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NGEST    NG ON NG.CODGEST   = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      INNER JOIN INTRARI  I  ON I.CODINTR    = N.CODINTR
      LEFT  JOIN NPART    NP ON NP.CODPART   = I.PARTENER
      LEFT  JOIN NGEST    G  ON G.CODGEST    = I.CODGESTPROD
      LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
      AND N.DATANIR&apos;||sCondData||&apos;
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, N.NRNIR, N.DATANIR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
    UNION ALL -- INTRARI DIN TRANSFERURI
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
      SUM(NS.CANTNIR * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) ValDFTva, 0 ValCFTva,
      SUM(NS.CANTNIR * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) SoldFinFTva,
      NG_S.DEN_GEST SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR&apos;||&apos;,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM TRANSF T
      INNER JOIN NIR     N    ON N.CODTRANSF     = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NIRSTOC NS   ON NS.CODNIR       = N.CODNIR
      INNER JOIN IOA          ON IOA.CODIOART    = NS.CODIOART
      INNER JOIN NGEST   NG   ON NG.CODGEST      = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp p    ON P.CODOBIECT     = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
      LEFT  JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
      LEFT  JOIN NIR     N_S  ON N_S.CODNIR      = NS_S.CODNIR
      LEFT  JOIN LIVRVAL LV_S ON LV_S.CODLIVR1   = NS.CODLIVR1
      LEFT  JOIN NGEST   NG_S ON NG_S.CODGEST    = NVL(N_S.GEST,LV_S.GEST)
    WHERE T.TIPDOC = 12 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND N.DATANIR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST
    UNION ALL -- IESIRI PRIN TRANSFER STOC
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
      0 ValDFTva, SUM(L1.CANT * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) ValCFTva,
      -SUM(L1.CANT * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) SoldFinFTva,
      NG_D.DEN_GEST SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM TRANSF T
      INNER JOIN LIVR    L    ON L.CODTRANSF   = T.CODTRANSF
      INNER JOIN LIVR1   L1   ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC NS   ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N    ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA          ON IOA.CODIOART  = NS.CODIOART
      INNER JOIN NGEST   NG   ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp p    ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
      LEFT  JOIN NIRSTOC NS_D ON NS_D.CODLIVR1 = L1.CODLIVR1
      LEFT  JOIN NIR     N_D  ON N_D.CODNIR    = NS_D.CODNIR
      LEFT  JOIN NGEST   NG_D ON NG_D.CODGEST  = N_D.GEST
    WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC,  L.NRLIVR, L.DATALIVR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST, NG_D.DEN_GEST
    UNION ALL -- MODIFICARI DE PRET
    SELECT
      T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC),
      SUM(NS.CANTNIR * (NS.PRET - NVL(NS.ADAOS,0))) ValDFTva, SUM(NS.CANTNIR * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) ValCFTva,
      SUM(NS.CANTNIR * ((NS.PRET - NVL(NS.ADAOS,0)) - DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP))) SoldFinFTva,
      NG.DEN_GEST SursaDest, IOA.DEN_IOART,
      NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR&apos;||&apos;,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM TRANSF T
      INNER JOIN NIR     N  ON N.CODTRANSF  = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NIRSTOC NS ON NS.CODNIR    = N.CODNIR
      INNER JOIN IOA        ON IOA.CODIOART = NS.CODIOART
      INNER JOIN NGEST   NG ON NG.CODGEST   = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp p  ON P.CODOBIECT  = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
    WHERE T.TIPDOC = 13 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND N.DATANIR&apos;||sCondData||&apos;
    GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, N.NRNIR, N.DATANIR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST
    UNION ALL -- RETUR INTRARI STOC
    SELECT
      I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
      -SUM(L1.CANT * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) ValDFTva, 0 ValCFTva,
      -SUM(L1.CANT * DECODE(NVL(P.PMP,0),0,NS.PRET - NVL(NS.ADAOS,0),P.PMP)) SoldFinFTva,
      DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM INTRARI I
      INNER JOIN LIVR     L  ON L.CODINTR     = I.CODINTR
      INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC  NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA         ON IOA.CODIOART  = NS.CODIOART
      INNER JOIN NGEST    NG ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp  p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
      LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
      LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
      LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
    UNION ALL  -- IESIRI STOC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
      0 ValDFTva, SUM(L1.CANT * CASE WHEN N.CODIES = I.CODIES OR NVL(P.PMP,0) = 0&apos;||CASE WHEN  vTipPmp = 1 THEN &apos; OR I.TIPDOC =23&apos; END||&apos; THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMP END) ValCFTva,
      -SUM(L1.CANT * CASE WHEN N.CODIES = I.CODIES OR NVL(P.PMP,0) = 0&apos;||CASE WHEN  vTipPmp = 1 THEN &apos; OR I.TIPDOC =23&apos; END||&apos; THEN NS.PRET - NVL(NS.ADAOS,0) ELSE P.PMP END) SoldFinFTva,
      DECODE(I.TIPDOC,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,NS.DEN_SUBUNIT,24,NG.DEN_GEST,NP.DEN_PART) SursaDest, IOA.DEN_IOART, NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM IESIRI I
      INNER JOIN LIVR     L  ON L.CODIES      = I.CODIES AND L.TIPLIVR = I.TIPDOC
      INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC  NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA         ON IOA.CODIOART  = NS.CODIOART
      INNER JOIN NGEST    NG ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp  p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
      LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
      LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
      LEFT  JOIN NSUBUNIT NS ON NS.CODSUBUNIT = I.CODSUBUNIT
    WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, NS.DEN_SUBUNIT, G.DEN_GEST
    UNION ALL -- MARIRI DE STOC
    SELECT
      I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC),
      SUM(L1.CANT * CASE WHEN N.CODIES = I.CODIES OR NVL(P.PMP,0) = 0 THEN (NS.PRET - NVL(NS.ADAOS,0)) ELSE P.PMP END) ValDFTva, 0 ValCFTva,
      SUM(L1.CANT * CASE WHEN N.CODIES = I.CODIES OR NVL(P.PMP,0) = 0 THEN (NS.PRET - NVL(NS.ADAOS,0)) ELSE P.PMP END) SoldFinFTva,
      NG.DEN_GEST SursaDest, IOA.DEN_IOART,
      NG.DEN_GEST, IOA.DEN_CONT, IOA.SIMB_CONT,
      L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
    FROM IESIRI I
      INNER JOIN LIVR    L  ON L.CODIES      = I.CODIES AND L.TIPLIVR = I.TIPDOC
      INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN IOA        ON IOA.CODIOART  = NS.CODIOART
      INNER JOIN NGEST   NG ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN tmp_pmp p  ON P.CODOBIECT   = NS.CODOBIECT&apos;||CASE WHEN vTipPmp &lt;&gt; 1 THEN &apos; AND P.CODSUBUNIT = NG.CODSUBUNIT&apos; END||&apos;
    WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND L.DATALIVR&apos;||sCondData||&apos;
    GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC,  L.NRLIVR, L.DATALIVR, IOA.DEN_IOART, IOA.DEN_CONT, IOA.SIMB_CONT, NG.DEN_GEST&apos;;


  --PKG_GLOBALS.SetDebugMode(TRUE);
  pkg_globals.SetLunaTemp(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  DELETE FROM tmp_pmp;
  IF PKG_PMP.AM_MISCARI_CU_PMP &gt; 0 THEN
    PKG_PMP.CALC_PMP2(vTipPmp);
  END IF;

  sDebug :=
    &apos;BEGIN&apos;||Chr(10)||
    &apos;  pkg_globals.SetLunaLucru(&apos;||PKG_GLOBALS.ANLUCRU||&apos;,&apos;||PKG_GLOBALS.LUNALUCRU||&apos;);&apos;||Chr(10)||
    &apos;  pkg_globals.SetLunaTemp (&apos;||PKG_GLOBALS.ANLUCRU||&apos;,&apos;||PKG_GLOBALS.LUNALUCRU||&apos;);&apos;||Chr(10)||
    &apos;  DELETE FROM tmp_pmp;&apos;||Chr(10)||
    &apos;  IF PKG_PMP.AM_MISCARI_CU_PMP &gt; 0 THEN&apos;||Chr(10)||
    &apos;    PKG_PMP.CALC_PMP2(&apos;||vTipPmp||&apos;);&apos;||Chr(10)||
    &apos;  END IF;&apos;||Chr(10)||
    &apos;END;&apos;;
  PKG_GLOBALS.CheckDebugMode(sDebug, aListID, aListVer);

  PKG_LIST_BASE_UTILS.make_config_luna_ioart;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri is
begin
   Pkg_List_Struct.SetTableSpec(&apos;&apos;);
   pkg_list_struct.AdunaColoanele;
end;

end PKG_LIST_BASE_RAPORTGESTPMP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTGESTVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD2EAD1FC59FC9E294E42A4AA3A544B8A5B985AA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTGESTVAL IS

FUNCTION JOINTMP(vCamp VARCHAR2) RETURN VARCHAR2
IS
BEGIN
  IF PKG_LIST_SELECTGEST2.ToateGest THEN
    RETURN NULL;
  ELSE
    RETURN &apos;
      INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = &apos;||vcamp||&apos; AND TMP.FILTRU = &apos;&apos;CODGEST&apos;&apos;&apos;;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
  sInsert     VARCHAR2(  500);
  sSelect     VARCHAR2(30000);
  sDataIni    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaIni,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sDataFin    VARCHAR2(   20) := to_char(PKG_LIST_SELECTGEST2.ZiuaFin,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;);
  sCondData   VARCHAR2(  100);
  sDataI      VARCHAR2(   50);
  sDataT      VARCHAR2(   50);
  sDataL      VARCHAR2(   50);  
  sDataLT     VARCHAR2(   50);
BEGIN

  IF PKG_LIST_SELECTGEST2.TipData = 0 then
    sDataI := &apos;I.DATADOC&apos;;
    sDataT := &apos;T.DATADOC&apos;;
    sDataL := &apos;I.DATADOC&apos;;
    sDataLT := &apos;T.DATADOC&apos;;
  else
    sDataI := &apos;N.DATANIR&apos;;
    sDataT := &apos;N.DATANIR&apos;;
    sDataL := &apos;L.DATALIVR&apos;;
    sDataLT := &apos;L.DATALIVR&apos;;
  end if;

  IF PKG_LIST_SELECTGEST2.ZiuaIni = PKG_LIST_SELECTGEST2.ZiuaFin
  THEN sCondData := &apos; = to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  ELSE sCondData := &apos; BETWEEN to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND to_date(&apos;&apos;&apos;||sDataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_TipDoc, PrefixDoc, NrDoc, DataDoc, Document, TipDoc, ObsDoc,
    AdDebit, ValDFTVA, ValDCTVA, TVAD,
    AdCredit, ValCFTVA, ValCCTVA, TVAC,
    VDocDCTVA, VDocCCTVA,
    SoldFinFTVA, SoldFinCTVA,
    SursaDest, DenIOART,
    SoldIn, AchizIn, Coef,
    DenGest, DenCONT, SimbCONT, RecLivr, Zi, ZiDoc )&apos;;

  sSelect := &apos;
  WITH
  IOA1 AS (
    SELECT IO.CODIOART, IO.DEN_IOART, NCo.DEN_CONT, NCo.SIMBOL SIMB_CONT
    FROM IOART1 IO1
         INNER JOIN IOART IO  ON IO.CODIOART = IO1.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IO1.ALStart and IO1.ALStop
         LEFT  JOIN NCONT NCo ON NCo.CODCONT = IO1.CONT
    WHERE IO1.MG = 5
  ),
  SVM AS (
    SELECT GEST, CODIOART, Coalesce(TVA,0) TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
    FROM STOCVALLUNA SVL &apos;||JOINTMP(&apos;SVL.GEST&apos;)||&apos;
    WHERE (AN*12 + LUNA + 1)= &apos;||PKG_GLOBALS.AnLunaLucru||&apos;
    UNION ALL -- NIR-URI DIN INTRARI
    SELECT N.GEST, NS.CODIOART, NS.TVA, NS.CANTNIR*NS.PRET SOLD, NS.CANTNIR*NS.ADAOS ADAOS, NS.CANTNIR*NS.PRET SOLDINTR, NS.CANTNIR*NS.ADAOS ADAOSINTR
    FROM NIRSTOC NS
      INNER JOIN NIR     N ON N.CODNIR      = NS.CODNIR &apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN INTRARI I ON I.CODINTR     = N.CODINTR
      INNER JOIN IOA1      ON IOA1.CODIOART = NS.CODIOART
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND  I.ANULAT = 0 AND I.OPERAT = 1
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataI||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
    UNION ALL -- NIR-URI DIN MISCARI INTERNE
    SELECT N.GEST, NS.CODIOART, NS.TVA, NS.CANTNIR*NS.PRET SOLD, NS.CANTNIR*NS.ADAOS ADAOS, NS.CANTNIR*NS.PRET SOLDINTR, NS.CANTNIR*NS.ADAOS ADAOSINTR
    FROM NIRSTOC NS
      INNER JOIN NIR    N ON N.CODNIR      = NS.CODNIR &apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN TRANSF T ON T.CODTRANSF   = N.CODTRANSF
      INNER JOIN IOA1     ON IOA1.CODIOART = NS.CODIOART
    WHERE T.TIPDOC IN (12, 13) AND  T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataT||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
    UNION ALL -- LIVRARI INTRARI
    SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG*L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ)*L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
    FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN LIVR1   L1 ON L1.CODLIVR1 = LV.CODLIVR1
      INNER JOIN LIVR    L  ON L.CODLIVR   = L1.CODLIVR
      INNER JOIN INTRARI I  ON I.CODINTR   = L.CODINTR
    WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataL||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
    UNION ALL -- LIVRARI IESIRI
    SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG*L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ)*L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
    FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
      INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
      INNER JOIN IESIRI I  ON I.CODIES    = L.CODIES
    WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24 ) AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataL||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
    UNION ALL -- LIVRARI MISCARI INTERNE
    SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, - LV.PRETINREG*L1.CANT SOLD, - (LV.PRETINREG - LV.PRETACHIZ)*L1.CANT ADAOS, 0 SOLDINTR, 0 ADAOSINTR
    FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
      INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
      INNER JOIN TRANSF T  ON T.CODTRANSF = L.CODTRANSF
    WHERE T.TIPDOC IN (12, 13) AND T.OPERAT = 1 AND T.ANULAT = 0
      AND &apos;||sDataLT||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    UNION ALL -- LIVRARI MARIRI DE STOC
    SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, LV.PRETINREG*L1.CANT SOLD, (LV.PRETINREG - LV.PRETACHIZ)*L1.CANT ADAOS, LV.PRETINREG*L1.CANT SOLDINTR, (LV.PRETINREG - LV.PRETACHIZ)*L1.CANT ADAOSINTR
    FROM LIVRVAL LV &apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
      INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
      INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
      INNER JOIN IESIRI I  ON I.CODIES    = L.CODIES
    WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0
      AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataL||&apos; &lt; to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)
  )
  SELECT
    NULL CodDoc, NULL TipDoc, &apos;&apos; &apos;&apos; PrefixDoc, NULL NrDoc, to_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) DataDoc, &apos;&apos;Sold initial&apos;&apos; Doc, &apos;&apos; &apos;&apos; TipDoc, &apos;&apos; &apos;&apos; ObsDoc,
    0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TVAD,
    0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    0 VDocDCTVA, 0 VDocCCTVA,
    SUM(SVM.Sold/(1 + SVM.Tva)) SoldFinFTva, SUM(SVM.Sold) SoldFinCTva,
    NULL SursaDest, IOA1.DEN_IOART,
    SUM(SVM.SOLDINTR) SoldIn, SUM(SVM.SOLDINTR - SVM.ADAOSINTR) AchizIn,
    DECODE(SUM(SVM.SOLDINTR - SVM.ADAOSINTR),0,0,  SUM(SVM.SOLDINTR)/SUM(SVM.SOLDINTR - SVM.ADAOSINTR)) Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    NULL RecLivr, &apos;&apos;0&apos;&apos; Zi, &apos;&apos;0&apos;&apos; ZiDoc
  FROM SVM
    INNER JOIN IOA1     ON IOA1.CODIOART = SVM.CODIOART
    INNER JOIN NGEST NG ON NG.CODGEST    = SVM.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
  GROUP BY NG.DEN_GEST, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT
  UNION ALL -- INTRARI
  SELECT
    I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), I.Obs,
    SUM(NS.CANTNIR*(NS.ADAOS - NS.PRET*NS.TVA/(1+NS.TVA) )) AdDebit, SUM(NS.CANTNIR*NS.PRET/(1+NS.TVA)) ValDFTva, SUM(NS.CANTNIR*NS.PRET) ValDCTva, SUM(NS.CANTNIR*NS.PRET*NS.TVA/(1+NS.TVA)) TVAD,
    0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(NS.CANTNIR*I1.PRETORIG*I1.COEFDISCMAJ*CASE WHEN I1.TVA = 0 THEN 1 WHEN I.TIPDOC = 3 THEN 1 WHEN I1.CANT*I1.PU = 0 THEN 1 ELSE 1+I1.TVA/(I1.CANT*I1.PU) END) VDocDCTVA, 0 VDocCCTVA,
    SUM(NS.CANTNIR*NS.PRET/(1+NS.TVA)) SoldFinFTva, SUM(NS.CANTNIR*NS.PRET) SoldFinCTva,
    DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
    SUM(NS.CANTNIR*NS.PRET) SoldIn, SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS)) AchizIn,
    DECODE(SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS)),0,0,SUM(NS.CANTNIR*NS.PRET)/SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS))) Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM NIRSTOC NS
    INNER JOIN IOA1        ON IOA1.CODIOART = NS.CODIOART
    INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
    INNER JOIN NGEST    NG ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    INNER JOIN INTRARI  I  ON I.CODINTR     = N.CODINTR
    LEFT  JOIN INTRARI1 I1 ON I1.CODINTR    = I.CODINTR AND I1.CODINTR1 = NS.CODINTR1
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
  WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
    AND &apos;||sDataI||&apos;&apos;||sCondData||&apos;
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
  GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, I.OBS, N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL -- INTRARI DIN TRANSFERURI
  SELECT
    T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), T.Obs,
    SUM(NS.CANTNIR*(NS.ADAOS - NS.PRET*NS.TVA/(1+NS.TVA) )) AdDebit, SUM(NS.CANTNIR*NS.PRET/(1+NS.TVA)) ValDFTva, SUM(NS.CANTNIR*NS.PRET) ValDCTva, SUM(NS.CANTNIR*NS.PRET*NS.TVA/(1+NS.TVA)) TVAD,
    0 AdCredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(NS.CANTNIR*T1.PU*CASE WHEN T1.TVA = 0 THEN 1 WHEN T1.CANT*T1.PU = 0 THEN 1 ELSE 1+T1.TVA/(T1.CANT*T1.PU) END) VDocDCTVA, 0 VDocCCTVA,
    SUM(NS.CANTNIR*NS.PRET/(1+NS.TVA)) SoldFinFTva, SUM(NS.CANTNIR*NS.PRET) SoldFinCTva,
    NG_S.DEN_GEST SursaDest, IOA1.DEN_IOART,
    SUM(NS.CANTNIR*NS.PRET) SoldIn, SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS)) AchizIn,
    DECODE(SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS)),0,0,SUM(NS.CANTNIR*NS.PRET)/SUM(NS.CANTNIR*(NS.PRET - NS.ADAOS))) Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    N.NRNIR||&apos;&apos;/&apos;&apos;||N.DATANIR RecLivr, TO_CHAR(N.DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM TRANSF T
    INNER JOIN NIR     N    ON N.CODTRANSF     = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
    INNER JOIN NIRSTOC NS   ON NS.CODNIR       = N.CODNIR
    INNER JOIN IOA1         ON IOA1.CODIOART   = NS.CODIOART
    INNER JOIN NGEST   NG   ON NG.CODGEST      = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN TRANSF1 T1   ON T1.CODTRANSF    = T.CODTRANSF AND T1.CODTRANSF1 = NS.CODTRANSF1
    LEFT  JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
    LEFT  JOIN NIR     N_S  ON N_S.CODNIR      = NS_S.CODNIR
    LEFT  JOIN LIVRVAL LV_S ON LV_S.CODLIVR1   = NS.CODLIVR1
    LEFT  JOIN NGEST   NG_S ON NG_S.CODGEST    = NVL(N_S.GEST,LV_S.GEST)
  WHERE T.TIPDOC = 12 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
    AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND &apos;||sDataT||&apos;&apos;||sCondData||&apos;
  GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, T.OBS, N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_S.DEN_GEST
  UNION ALL -- IESIRI DIN TRANSFERURI
  SELECT
    T.CODTRANSF CodDoc, T.TIPDOC, T.PREFIXDOC, T.NRDOC, T.DATADOC, t.prefixdoc ||t.seriadoc||t.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(T.TIPDOC), T.Obs,
    0 Addebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD,
    SUM(L1.CANT*(LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdCredit, SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(L1.CANT*LV.PRETINREG) ValCCTva, SUM(L1.CANT*LV.PRETINREG*Coalesce(LV.TVANEEX, 0)/(1+Coalesce(LV.TVANEEX, 0))) TvaC,
    0 VDocDCTVA, - SUM(L1.CANT*T1.PU*CASE WHEN T1.TVA = 0 THEN 1 WHEN T1.CANT*T1.PU = 0 THEN 1 ELSE 1+T1.TVA/(T1.CANT*T1.PU) END) VDocCCTVA,
    -SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT*LV.PRETINREG) SoldFinCTva,
    NG_D.DEN_GEST SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(T.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM TRANSF T
    INNER JOIN LIVR    L    ON L.CODTRANSF   = T.CODTRANSF
    INNER JOIN LIVR1   L1   ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL LV   ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1         ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST   NG   ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN TRANSF1 T1   ON T1.CODTRANSF  = T.CODTRANSF AND T1.CODTRANSF1 = L1.CODIES1
    LEFT  JOIN NIRSTOC NS_D ON NS_D.CODLIVR1 = L1.CODLIVR1
    LEFT  JOIN NIR     N_D  ON N_D.CODNIR    = NS_D.CODNIR
    LEFT  JOIN NGEST   NG_D ON NG_D.CODGEST  = N_D.GEST
  WHERE T.TIPDOC = 12 AND T.ANULAT = 0 AND T.OPERAT = 1
    AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND &apos;||sDataLT||&apos;&apos;||sCondData||&apos;
  GROUP BY T.CODTRANSF, T.TIPDOC, T.PREFIXDOC, T.SERIADOC, T.NRDOC, T.DATADOC, T.OBS, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NG_D.DEN_GEST
  UNION ALL -- MODIFICARI DE PRET
  SELECT
    CODTRANSF CodDoc, TIPDOC, PREFIXDOC, NRDOC, DATADOC, PREFIXDOC||SERIADOC||NRDOC||&apos;&apos;/&apos;&apos;||To_Char(DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(TIPDOC) TipDoc, Obs,
    SUM(NS_CantNIR * (NS_ADAOS - NS_PRET * NS_TVA / (1+NS_TVA))) AdDebit, SUM(NS_CantNIR*NS_PRET/(1+NS_TVA)) ValDFTva, SUM(NS_CantNIR*NS_PRET) ValDCTva, SUM(NS_CantNIR*NS_PRET*NS_TVA/(1+NS_TVA)) TVAD,
    SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN (LV_S_PRETINREG/(1+LV_S_TVANEEX) - LV_S_PRETACHIZ) ELSE (NS_S_ADAOS - NS_S_PRET*NS_S_TVA/(1+NS_S_TVA)) END) AdCredit,
    SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN LV_S_PRETINREG/(1+LV_S_TVANEEX)                    ELSE NS_S_PRET/(1+NS_S_TVA)                         END) ValCFTva,
    SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN LV_S_PRETINREG                                     ELSE NS_S_PRET                                      END) ValCCTva,
    SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN LV_S_PRETINREG*LV_S_TVANEEX/(1+LV_S_TVANEEX)       ELSE NS_S_PRET*NS_S_TVA/(1+NS_S_TVA)                END) TvaC,
    SUM(NS_CantNIR*T1_PU*CASE WHEN T1_TVA = 0 THEN 1 WHEN T1_CANT*T1_PU = 0 THEN 1 ELSE 1+T1_TVA/(T1_CANT*T1_PU) END) VDocDCTVA, -SUM(NS_CantNIR*T1_PU*CASE WHEN T1_TVA = 0 THEN 1 WHEN T1_CANT*T1_PU = 0 THEN 1 ELSE 1+T1_TVA/(T1_CANT*T1_PU) END) VDocCCTVA,
    SUM(NS_CantNIR*NS_PRET/(1+NS_TVA)) - SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN LV_S_PRETINREG/(1+LV_S_TVANEEX) ELSE NS_S_PRET/(1+NS_S_TVA) END) SoldFinFTva,
    SUM(NS_CantNIR*NS_PRET)            - SUM(NS_CantNIR*CASE WHEN CODNIRSTOCPARINTE IS NULL THEN LV_S_PRETINREG                  ELSE NS_S_PRET              END) SoldFinCTva,
    DEN_GEST SursaDest, DEN_IOART,
    SUM(NS_CantNIR*NS_PRET) SoldIn, SUM(NS_CantNIR*(NS_PRET - NS_ADAOS)) AchizIn,
    CASE WHEN SUM(NS_CantNIR*(NS_PRET - NS_ADAOS)) = 0 THEN 0 ELSE SUM(NS_CantNIR*NS_PRET)/SUM(NS_CantNIR*(NS_PRET - NS_ADAOS)) END Coef,
    DEN_GEST, DEN_CONT, SIMB_CONT,
    NRNIR||&apos;&apos;/&apos;&apos;||DATANIR RecLivr, TO_CHAR(DATANIR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM (
    SELECT
      T.CODTRANSF, T.TIPDOC, Coalesce(T.PREFIXDOC,&apos;&apos;&apos;&apos;) PREFIXDOC, Coalesce(T.SERIADOC,&apos;&apos;&apos;&apos;) SERIADOC, T.NRDOC, T.DATADOC, T.OBS, 
      N.NRNIR, N.DATANIR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST,
      NS.CODNIRSTOCPARINTE, NS.CANTNIR NS_CantNIR, Coalesce(NS.ADAOS, 0) NS_ADAOS, Coalesce(NS.PRET, 0) NS_PRET, Coalesce(NS.TVA, 0) NS_TVA,
      Coalesce(T1.CANT, 0) T1_CANT, Coalesce(T1.PU, 0) T1_PU, Coalesce(T1.TVA, 0) T1_TVA,
      Coalesce(NS_S.PRET, 0) NS_S_PRET, Coalesce(NS_S.TVA, 0) NS_S_TVA, Coalesce(NS_S.ADAOS, 0) NS_S_ADAOS,
      Coalesce(LV_S.PRETACHIZ, 0) LV_S_PRETACHIZ, Coalesce(LV_S.PRETINREG, 0) LV_S_PRETINREG, Coalesce(LV_S.TVANEEX, 0) LV_S_TVANEEX
    FROM TRANSF T
      INNER JOIN NIR     N    ON N.CODTRANSF     = T.CODTRANSF&apos;||JOINTMP(&apos;N.GEST&apos;)||&apos;
      INNER JOIN NIRSTOC NS   ON NS.CODNIR       = N.CODNIR
      INNER JOIN IOA1         ON IOA1.CODIOART   = NS.CODIOART
      INNER JOIN NGEST   NG   ON NG.CODGEST      = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      LEFT  JOIN TRANSF1 T1   ON T1.CODTRANSF    = T.CODTRANSF AND T1.CODTRANSF1 = NS.CODTRANSF1
      LEFT  JOIN NIRSTOC NS_S ON NS_S.CODNIRSTOC = NS.CODNIRSTOCPARINTE AND (NS.CODNIRSTOCPARINTE IS NOT NULL)
      LEFT  JOIN NIR     N_S  ON N_S.CODNIR      = NS_S.CODNIR
      LEFT  JOIN LIVR1   L1_S ON L1_S.CODLIVR1   = NS.CODLIVR1 AND (NS.CODNIRSTOCPARINTE IS NULL)
      LEFT  JOIN LIVRVAL LV_S ON LV_S.CODLIVR1   = L1_S.CODLIVR1
    WHERE T.TIPDOC = 13 AND T.ANULAT = 0 AND T.OPERAT = 1 AND N.OPERAT = 1
      AND T.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND T.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
      AND &apos;||sDataT||&apos;&apos;||sCondData||&apos;
  ) 
  GROUP BY CODTRANSF, TIPDOC, PREFIXDOC, SERIADOC, NRDOC, DATADOC, OBS, NRNIR, DATANIR, DEN_IOART, DEN_CONT, SIMB_CONT, DEN_GEST
  UNION ALL -- RETUR INTRARI VALORIC
  SELECT
    I.CODINTR CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), I.Obs,
    - SUM(L1.CANT*(LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) AdDebit, - SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) ValDFTva,
    - SUM(L1.CANT*LV.PRETINREG) ValDCTva, - SUM(L1.CANT*LV.PRETINREG*Coalesce(LV.TVANEEX, 0)/(1+Coalesce(LV.TVANEEX, 0))) TvaD,
    0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    -SUM(L1.CANT*I1.PRETORIG*I1.COEFDISCMAJ*CASE WHEN I1.TVA = 0 THEN 1 WHEN I.TIPDOC = 3 THEN 1 WHEN I1.CANT*I1.PU = 0 THEN 1 ELSE 1+I1.TVA/(I1.CANT*I1.PU) END) VDocDCTVA, 0 VDocCCTVA,
    -SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT*LV.PRETINREG) SoldFinCTva,
    DECODE(I.TIPDOC,6,S.DEN_SUBUNIT,7,G.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM INTRARI I
    INNER JOIN LIVR     L  ON L.CODINTR     = I.CODINTR
    INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL  LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1        ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST    NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN INTRARI1 I1 ON I1.CODINTR    = I.CODINTR AND I1.CODINTR1 = L1.CODINTR1
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
  WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7) AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND &apos;||sDataL||&apos;&apos;||sCondData||&apos;
  GROUP BY I.CODINTR, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, I.OBS, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL  -- IESIRI VALORIC
  SELECT
    I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), I.Obs,
    0 AdDebit, 0 ValDFTva, 0 ValDCTva, 0 TvaD,
    SUM(L1.CANT*(LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) ) Adcredit, SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) ValCFTva, SUM(L1.CANT*LV.PRETINREG) ValCCTva,
    SUM(L1.CANT*LV.PRETINREG*Coalesce(LV.TVANEEX, 0)/(1+Coalesce(LV.TVANEEX, 0))) TvaC,
    0 VDocDCTVA, SUM(L1.CANT*I1.PRETORIG*I1.COEFDISCMAJ*CASE WHEN I1.TVA = 0 THEN 1 WHEN I.TIPDOC IN (16,21) THEN 1 WHEN I1.CANT*I1.PU = 0 THEN 1 ELSE 1+I1.TVA/(I1.CANT*I1.PU) END) VDocCCTVA,
    -SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, -SUM(L1.CANT*LV.PRETINREG) SoldFinCTva,
    DECODE(I.TIPDOC,14,&apos;&apos;-&apos;&apos;,16,&apos;&apos;-&apos;&apos;,23,S.DEN_SUBUNIT,24,NG.DEN_GEST,NP.DEN_PART) SursaDest, IOA1.DEN_IOART,
    0 SoldIn, 0 AchizIn,
    0 Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM IESIRI I
    INNER JOIN LIVR     L  ON L.CODIES      = I.CODIES
    INNER JOIN LIVR1    L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL  LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1        ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST    NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN IESIRI1  I1 ON I1.CODIES     = I.CODIES AND I1.CODIES1 = L1.CODIES1
    LEFT  JOIN NPART    NP ON NP.CODPART    = I.PARTENER
    LEFT  JOIN NGEST    G  ON G.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NSUBUNIT S  ON S.CODSUBUNIT  = I.CODSUBUNIT
  WHERE I.TIPDOC IN (14, 16, 19, 20, 21, 22, 23, 24) AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND &apos;||sDataL||&apos;&apos;||sCondData||&apos;
  GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, I.OBS, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST, NP.DEN_PART, S.DEN_SUBUNIT, G.DEN_GEST
  UNION ALL -- MARIRI DE STOC VALORIC
  SELECT
    I.CODIES CodDoc, I.TIPDOC, I.PREFIXDOC, I.NRDOC, I.DATADOC, i.prefixdoc ||i.seriadoc||i.nrdoc ||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Doc, pkg_list_base_utils.decode_tipdoc(I.TIPDOC), I.Obs,
    SUM(L1.CANT*(LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ)) AdDebit, SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) ValDFTva, SUM(L1.CANT*LV.PRETINREG) ValDCTva, SUM(L1.CANT*LV.PRETINREG*Coalesce(LV.TVANEEX, 0)/(1+Coalesce(LV.TVANEEX, 0))) TvaD,
    0 Adcredit, 0 ValCFTva, 0 ValCCTva, 0 TvaC,
    SUM(L1.CANT*I1.PRETORIG*I1.COEFDISCMAJ*CASE WHEN I1.TVA = 0 THEN 1 WHEN I.TIPDOC IN (16,21) THEN 1 WHEN I1.CANT*I1.PU = 0 THEN 1 ELSE 1+I1.TVA/(I1.CANT*I1.PU) END) VDocDCTVA, 0 VDocCCTVA,
    SUM(L1.CANT*LV.PRETINREG/(1+Coalesce(LV.TVANEEX, 0))) SoldFinFTva, SUM(L1.CANT*LV.PRETINREG) SoldFinCTva,
    NG.DEN_GEST SursaDest, IOA1.DEN_IOART,
    SUM(L1.CANT*LV.PRETINREG) SoldIn, SUM(L1.CANT*LV.PRETINREG) AchizIn,
    DECODE(SUM(L1.CANT*LV.PRETINREG),0,0,SUM(L1.CANT*LV.PRETINREG)/SUM(L1.CANT*LV.PRETINREG)) Coef,
    NG.DEN_GEST, IOA1.DEN_CONT, IOA1.SIMB_CONT,
    L.NRLIVR||&apos;&apos;/&apos;&apos;||L.DATALIVR RecLivr, TO_CHAR(L.DATALIVR,&apos;&apos;DD&apos;&apos;) Zi, TO_CHAR(I.DATADOC,&apos;&apos;DD&apos;&apos;) ZiDoc
  FROM IESIRI I
    INNER JOIN LIVR    L  ON L.CODIES      = I.CODIES
    INNER JOIN LIVR1   L1 ON L1.CODLIVR    = L.CODLIVR
    INNER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1&apos;||JOINTMP(&apos;LV.GEST&apos;)||&apos;
    INNER JOIN IOA1       ON IOA1.CODIOART = LV.CODIOART
    INNER JOIN NGEST   NG ON NG.CODGEST    = LV.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    LEFT  JOIN IESIRI1 I1 ON I1.CODIES     = I.CODIES AND I1.CODIES1 = L1.CODIES1
  WHERE I.TIPDOC = 15 AND I.OPERAT = 1 AND I.ANULAT = 0
    AND I.AN = &apos;||PKG_GLOBALS.GetANLUCRU||&apos; AND I.LUNA = &apos;||PKG_GLOBALS.GETLUNALUCRU||&apos;
    AND &apos;||sDataL||&apos;&apos;||sCondData||&apos;
  GROUP BY I.CODIES, I.TIPDOC, I.PREFIXDOC, I.SERIADOC, I.NRDOC, I.DATADOC, I.OBS, L.NRLIVR, L.DATALIVR, IOA1.DEN_IOART, IOA1.DEN_CONT, IOA1.SIMB_CONT, NG.DEN_GEST&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri is
begin
   Pkg_List_Struct.SetTableSpec(&apos;&apos;);
   pkg_list_struct.AdunaColoanele;
end;

END PKG_LIST_BASE_RAPORTGESTVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD2D841E4D46D6676BBADB8BE8E737926BF3FCCC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTP IS

  vCodRaportP  RaportP.CodRaportP%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodRaportP := pCodRaportP;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;RaportP P, RaportP1 P1, RaportP2 P2, NGEST G, FORMATII F, NSUBUNIT S, NPERS A, NartObj Ob, ProdMan PM, NOper Op, Comanda1 C1, Comanda C,PRODCOMP PC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;RAPORTPDET&apos;, &apos;PDET&apos;, &apos;PDET.CODRAPORTP = P.CODRAPORTP&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, NrDoc, DataI, DataS, PeForm, Sectie, Form, Sub,
    Ang, Ord,
    Com, Art, Oper,
    Realizat, TNorma, TValoare, Rebut&apos;||gUserFields||&apos;)
  SELECT
    P.CodRaportP, 63, P.NrDoc, P.DataI, P.DataS, Decode(P.Pe_Formatie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), G.Den_Gest, F.Den_Formatie, S.Den_Subunit,
    Decode(P1.Angajat,0, A.NUME,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME), ROW_NUMBER() OVER (PARTITION BY P2.CodRaportP1 ORDER BY P2.CODRAPORTP2 ASC),
    C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||C.DATADOC, OB.DENUMIRE, PM.NROP||&apos;&apos;/&apos;&apos;|| OP.DENUMIRE,
    P2.REALIZAT, PM.TU * P2.REALIZAT, T1.Tarif * PM.TU * P2.REALIZAT / 60, P2.REBUT &apos;||gUserAlias||&apos;
  FROM RaportP P
    INNER JOIN RaportP0   P0 ON P0.CodRaportP  = P.CodRaportP
    INNER JOIN RaportP1   P1 ON P1.CodRaportP0 = P0.CodRaportP0
    INNER JOIN RaportP2   P2 ON P2.CodRaportP1 = P1.CodRaportP1
    INNER JOIN ProdMan    PM ON PM.CodMan      = P2.CodMan
    INNER JOIN Tarifeman1 T1 ON T1.CodTarif    = PM.CodTarif AND &apos;||pkg_globals.AnLunalucru||&apos; BETWEEN T1.ALSTART and T1.ALSTOP
    INNER JOIN PRODCOMP   PC ON PM.CODPRODCOMP = PC.CODPRODCOMP
    LEFT  JOIN NGEST      G  ON G.CodGest      = P.Sectie
    LEFT  JOIN FORMATII   F  ON F.CodFormatie  = P.Formatie
    LEFT  JOIN NSUBUNIT   S  ON S.CodSubunit   = P.Subunitatea
    LEFT  JOIN NPERS      A  ON A.CodPers      = P1.Angajat
    LEFT  JOIN NOper      Op ON Op.CodOp       = PM.CodOp
    LEFT  JOIN Comanda1   C1 ON C1.CodComanda1 = P2.CodComanda1
    LEFT  JOIN NartObj    Ob ON Ob.CodObiect   = C1.CodObiect
    LEFT  JOIN Comanda    C  ON C.CodComanda   = C1.CodComanda&apos;||
    gSuplJoins||&apos;
  WHERE P.An*12 + p.Luna BETWEEN PKG_LIST_SELECTLUNAAN.LunaStart AND PKG_LIST_SELECTLUNAAN.LunaStop &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos;
  UNION ALL
  SELECT
    P.CodRaportP, 63, P.NrDoc, P.DataI, P.DataS, Decode(P.Pe_Formatie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), G.Den_Gest, F.Den_Formatie, S.Den_Subunit,
    Decode(P1.Angajat,0, A.NUME,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME), ROW_NUMBER() OVER (PARTITION BY P2.CodRaportP1 ORDER BY P2.CODRAPORTP2 ASC),
    C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||C.DATADOC, OB.DENUMIRE, PM.NROP||&apos;&apos;/&apos;&apos;|| OP.DENUMIRE,
    P2.REALIZAT, P2.TU * P2.REALIZAT, T1.Tarif * P2.TU * P2.REALIZAT / 60, P2.REBUT &apos;||gUserAlias||&apos;
  FROM RaportP P
    INNER JOIN RaportP0   P0 ON P0.CodRaportP  = P.CodRaportP
    INNER JOIN RaportP1   P1 ON P1.CodRaportP0 = P0.CodRaportP0
    INNER JOIN RaportP2   P2 ON P2.CodRaportP1 = P1.CodRaportP1
    INNER JOIN Tarifeman1 T1 ON T1.CodTarif    = P2.CodTarif AND &apos;||pkg_globals.AnLunalucru||&apos; BETWEEN T1.ALSTART and T1.ALSTOP
    LEFT  JOIN ProdMan    PM ON PM.CodMan      = P2.CodMan
    LEFT  JOIN PRODCOMP   PC ON PM.CODPRODCOMP = PC.CODPRODCOMP
    LEFT  JOIN NGEST      G  ON G.CodGest      = P.Sectie
    LEFT  JOIN FORMATII   F  ON F.CodFormatie  = P.Formatie
    LEFT  JOIN NSUBUNIT   S  ON S.CodSubunit   = P.Subunitatea
    LEFT  JOIN NPERS      A  ON A.CodPers      = P1.Angajat
    LEFT  JOIN NOper      Op ON Op.CodOp       = P2.CodOp
    LEFT  JOIN Comanda1   C1 ON C1.CodComanda1 = P2.CodComanda1
    LEFT  JOIN NartObj    Ob ON Ob.CodObiect   = c1.CodObiect
    LEFT  JOIN Comanda    C  ON C.CodComanda   = C1.CodComanda&apos;||
    gSuplJoins||&apos;
  WHERE NVL(PM.CODMAN,0) = 0 AND P.An*12 + p.Luna BETWEEN PKG_LIST_SELECTLUNAAN.LunaStart AND PKG_LIST_SELECTLUNAAN.LunaStop &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;);
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_RAPORTP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTPDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C488C94D46C0A5F69C4C6845EBCB80BBC6E39F66</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTPDOC IS

  vCodRaportP  RaportP.CodRaportP%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodRaportP := pCodRaportP;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(3000);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;RaportP P, RaportP1 P1, RaportP2 P2, NPERS A, NartObj Ob, ProdMan PM, NOper Op, Comanda1 C1, Comanda C&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Ang,
    Ord,
    Com, Art, Oper,
    Realizat, TNorma, TValoare&apos;||gUserFields||&apos;)
  SELECT
    Decode(P1.Angajat,0, A.NUME,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME),
    ROW_NUMBER() OVER (PARTITION BY P2.CodRaportP1 ORDER BY P2.CODRAPORTP2 ASC),
    C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||C.DATADOC, OB.DENUMIRE, PM.NROP||&apos;&apos;/&apos;&apos;|| OP.DENUMIRE,
    P2.REALIZAT, P2.TU * P2.REALIZAT, T1.Tarif * nvl(P2.TU, pm.tu) * P2.REALIZAT / 60&apos;||gUserAlias||&apos;
  FROM RaportP P
    INNER JOIN RaportP0   P0 ON P0.CodRaportP  = P.CodRaportP
    INNER JOIN RaportP1   P1 ON P1.CodRaportP0 = P0.CodRaportP0
    INNER JOIN RaportP2   P2 ON P2.CodRaportP1 = P1.CodRaportP1
    LEFT  JOIN ProdMan    PM ON PM.CodMan      = P2.CodMan
    LEFT  JOIN Tarifeman1 T1 ON T1.CodTarif    = nvl(P2.CodTarif,PM.CodTarif) AND &apos;||pkg_globals.AnLunalucru||&apos; BETWEEN T1.ALSTART and T1.ALSTOP
    LEFT  JOIN NPERS      A  ON A.CodPers      = P1.Angajat
    LEFT  JOIN NartObj    Ob ON Ob.CodObiect   = P2.CodObiect
    LEFT  JOIN NOper      Op ON Op.CodOp       = coalesce(P2.CODOP,PM.CodOp)
    LEFT  JOIN Comanda1   C1 ON C1.CodComanda1 = P2.CodComanda1
    LEFT  JOIN Comanda    C  ON C.CodComanda   = C1.CodComanda&apos;||
    gSuplJoins||&apos;
  WHERE P.CodRaportP = &apos;||vCodRaportP;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_RAPORTPDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTP_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FDB9AF29B4BC626C06D3EA6022C917D48E47FCA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTP_M IS

  vCodRaportP  RaportP.CodRaportP%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodRaportP IN NUMBER DEFAULT NULL) IS
BEGIN
  vCodRaportP := pCodRaportP;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  gSuplCols := &apos;RaportP P, RaportP1 P1, RaportP2 P2, NGEST G, FORMATII F, NSUBUNIT S, NPERS A, NartObj Ob, ProdMan PM, NOper Op, Comanda1 C1, Comanda C,&apos;||
               &apos;utilaje2c ut2c,utilaje ut,utilaje2 ut2,ninterventiiauto interv,nartobj intervserv,nartobj utilajobj,NCLASEINT CLSINT,prodcomp pc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;RAPORTPDET&apos;, &apos;PDET&apos;, &apos;PDET.CODRAPORTP = P.CODRAPORTP&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OB.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, NrDoc, DataI, DataS, PeForm, Sectie, Form, Sub,
    Ang, Ord,
    Com, Art, Oper,
    Realizat, TNorma, TValoare, Rebut, Interventie, Utilaj &apos;||gUserFields||&apos;)
  SELECT
    P.CodRaportP, 63, P.NrDoc, nvl(P2.DataStart,P.DATAI), NVL(P2.DataStop,P.DATAS), Decode(P.Pe_Formatie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), G.Den_Gest, F.Den_Formatie, S.Den_Subunit,
    Decode(P1.Angajat,0, A.NUME,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME), ROW_NUMBER() OVER (PARTITION BY P2.CodRaportP1 ORDER BY P2.CODRAPORTP2 ASC),
    C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||C.DATADOC, OB.DENUMIRE, PM.NROP||&apos;&apos;/&apos;&apos;|| OP.DENUMIRE,
    P2.REALIZAT, PM.TU * P2.REALIZAT, T1.Tarif * PM.TU * P2.REALIZAT / 60, P2.REBUT,
    intervserv.denumire,
    utilajobj.denumire &apos;||gUserAlias||&apos;
  FROM RaportP P
    INNER JOIN RaportP0         P0         ON P0.CodRaportP             = P.CodRaportP
    INNER JOIN RaportP1         P1         ON P1.CodRaportP0            = P0.CodRaportP0
    INNER JOIN RaportP2         P2         ON P2.CodRaportP1            = P1.CodRaportP1
    INNER JOIN ProdMan          PM         ON PM.CodMan                 = P2.CodMan
    INNER JOIN Tarifeman1       T1         ON T1.CodTarif               = PM.CodTarif AND (P.AN*12+P.LUNA) BETWEEN T1.ALSTART and T1.ALSTOP
    INNER JOIN Comanda1         C1         ON C1.CodComanda1            = P2.CodComanda1
    INNER JOIN Comanda          C          ON C.CodComanda              = C1.CodComanda
    INNER JOIN ProdComp         PC         ON PC.CodProdComp            = PM.CodProdComp
    LEFT  JOIN NGEST            G          ON G.CodGest                 = P.Sectie
    LEFT  JOIN FORMATII         F          ON F.CodFormatie             = P.Formatie
    LEFT  JOIN NSUBUNIT         S          ON S.CodSubunit              = P.Subunitatea
    LEFT  JOIN NPERS            A          ON A.CodPers                 = P1.Angajat
    LEFT  JOIN NartObj          Ob         ON Ob.CodObiect              = P2.CodObiect
    LEFT  JOIN NOper            Op         ON Op.CodOp                  = PM.CodOp
    left  join utilaje2c        ut2c       on ut2c.codcomanda1          = c1.codcomanda1
    left  join utilaje          ut         on ut2c.codutilaj            = ut.codutilaj
    left  join utilaje2         ut2        on ut2.codutilaj2            = ut2c.codutilaj2
    left  join ninterventiiauto interv     on interv.CODINTERVENTIIAUTO = ut2.interventie
    LEFT  JOIN NCLASEINT        CLSINT     ON INTERV.CLASA              = CLSINT.CODCLASEINT
    left  join nartobj          intervserv on intervserv.codobiect      = interv.serviciu
    left  join nartobj          utilajobj  on utilajobj.codobiect       = ut.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPTRANZACTIE = 1 AND 
        P.An*12 + p.Luna BETWEEN PKG_LIST_SELECTLUNAAN.LunaStart AND PKG_LIST_SELECTLUNAAN.LunaStop &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos; 
  UNION ALL
  SELECT
    P.CodRaportP, 63, P.NrDoc, nvl(P2.DataStart,P.DATAI), NVL(P2.DataStop,P.DATAS), Decode(P.Pe_Formatie,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;), G.Den_Gest, F.Den_Formatie, S.Den_Subunit,
    Decode(P1.Angajat,0, A.NUME,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME), ROW_NUMBER() OVER (PARTITION BY P2.CodRaportP1 ORDER BY P2.CODRAPORTP2 ASC),
    C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||C.DATADOC, OB.DENUMIRE, PM.NROP||&apos;&apos;/&apos;&apos;|| OP.DENUMIRE,
    P2.REALIZAT, P2.TU * P2.REALIZAT, T1.Tarif * P2.TU * P2.REALIZAT / 60, P2.REBUT,
    intervserv.denumire,
    utilajobj.denumire &apos;||gUserAlias||&apos;
  FROM RaportP P
    INNER JOIN RaportP0         P0         ON P0.CodRaportP             = P.CodRaportP
    INNER JOIN RaportP1         P1         ON P1.CodRaportP0            = P0.CodRaportP0
    INNER JOIN RaportP2         P2         ON P2.CodRaportP1            = P1.CodRaportP1
    INNER JOIN Comanda1         C1         ON C1.CodComanda1            = P2.CodComanda1
    INNER JOIN Comanda          C          ON C.CodComanda              = C1.CodComanda
    INNER JOIN Tarifeman1       T1         ON T1.CodTarif               = P2.CodTarif AND (P.AN*12+P.LUNA) BETWEEN T1.ALSTART and T1.ALSTOP
    LEFT  JOIN ProdMan          PM         ON PM.CodMan                 = P2.CodMan
    LEFT  JOIN ProdComp         PC         ON PC.CodProdComp            = PM.CodProdComp
    LEFT  JOIN NGEST            G          ON G.CodGest                 = P.Sectie
    LEFT  JOIN FORMATII         F          ON F.CodFormatie             = P.Formatie
    LEFT  JOIN NSUBUNIT         S          ON S.CodSubunit              = P.Subunitatea
    LEFT  JOIN NPERS            A          ON A.CodPers                 = P1.Angajat
    LEFT  JOIN NartObj          Ob         ON Ob.CodObiect              = P2.CodObiect
    LEFT  JOIN NOper            Op         ON Op.CodOp                  = P2.CodOp
    left  join utilaje2c        ut2c       on ut2c.codcomanda1          = c1.codcomanda1
    left  join utilaje          ut         on ut2c.codutilaj            = ut.codutilaj
    left  join utilaje2         ut2        on ut2.codutilaj2            = ut2c.codutilaj2
    left  join ninterventiiauto interv     on interv.CODINTERVENTIIAUTO = ut2.interventie
    LEFT  JOIN NCLASEINT        CLSINT     ON INTERV.CLASA              = CLSINT.CODCLASEINT
    left  join nartobj          intervserv on intervserv.codobiect      = interv.serviciu
    left  join nartobj          utilajobj  on utilajobj.codobiect       = ut.codobiect&apos;||
    gSuplJoins||&apos;
  WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPTRANZACTIE = 1 AND NVL(PM.CODMAN,0) = 0 AND 
        P.An*12 + p.Luna BETWEEN PKG_LIST_SELECTLUNAAN.LunaStart AND PKG_LIST_SELECTLUNAAN.LunaStop &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;P&apos;)||&apos; &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_RAPORTP_M; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTSCHIMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>804AECD12BC37CD5C5CBCC828C2EBE1A7699C4C5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTSCHIMB IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataIni varchar2(10);
  vDataFin varchar2(10);

PROCEDURE setParams(aDataIni IN varchar2, aDataFin in varchar2, v_codjob1 in number) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataIni := aDataIni;
  vDataFin := aDataFin;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(5000);
  sSelect  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;comanda c,comanda1 c1,nartobj objprod,nart artprod,nartobj objmat,nart artmat,prodnorme nor,normemat nmat,&apos;||
               &apos;prodcomp pc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;insert into &apos;||tmpName||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     NrDoc,
     DataDoc,
     Schimb,
     Formatie,
     Sectie,
     DenProd,
     Prod_UM,
     Prod_Cant,
     Prod_CodExtern,
     DenComp,
     Comp_UM,
     Comp_UM1,
     Comp_CantN,
     Comp_CantN_UM1,
     Comp_CodIntern,
     Comp_Claseas,
     Comp_Clasea,
     Norma,
     Comp_CantNormata,
     Comp_CantNormataUMs &apos;||gUserFields||&apos;)&apos;||chr(13);

  -- comenzile fara norma asociata liniei
  /*sSelect :=
 &apos;select
    c.codcomanda NAV_CodDoc,
    c.tipdoc NAV_TipDoc,
    c.NrDoc,
    c.DataDoc,
    c.Schimb,
    f.den_formatie Formatie,
    s.den_gest Sectie,
    objprod.denumire DenProd,
    umprod.den_um Prod_UM,
    prod.cant Prod_Cant,
    objprod.codextern Prod_CodExtern,
    objmat.denumire DenComp,
    ummat.den_um Comp_UM,
    um1mat.den_um Comp_UM1,
    mat.cant Comp_Cant,
    nmat.cant Comp_CantN,
    nmat.cantum1 Comp_CantN_UM1,
    objmat.codintern Comp_CodIntern,
    clsasmat.den_claseas Comp_Claseas,
    clsamat.den_clasea Comp_Clasea,
    nor.Norma,
    case when nvl(nmat.cant,0) = 0 then 0 else nvl(mat.cant,0) * nvl(nmat.cantum1,0) / nmat.cant end &apos;||gUserAlias||&apos;
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join prodcomp pc on pc.codprodcomp = c1.codreteta
       inner join ngest s on s.codgest = c.codgest
       inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and prod.tip = 0
       inner join cmdprodmat mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 1
       inner join nartobj objprod on objprod.codobiect = prod.codobiect
       inner join nart artprod on objprod.codarticol = artprod.codarticol
       inner join num umprod on umprod.codum = artprod.um
       inner join nartobj objmat on objmat.codobiect = mat.codobiect
       inner join nart artmat on objmat.codarticol = artmat.codarticol
       inner join num ummat on ummat.codum = artmat.um
       left join prodmat retmat on retmat.codmat = mat.codprodmat
       left join nclasea clsamat on clsamat.codclasea = artmat.clasa
       left join nclaseas clsasmat on clsasmat.codclaseas = artmat.clasastatist
       left join num um1mat on um1mat.codum = artmat.um1
       left join formatii f on f.codformatie = c.codformatie
       left join prodnorme nor on c1.codnorma = nor.codnorma
       left join normemat nmat on nmat.codmat = mat.codprodmat and nor.codnorma = nmat.codnorma
  where c.datadoc between to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        and c.tipdoc = 53 and nvl(c1.codnorma,0) = 0
        and nvl(c.anulat,0) = 0&apos;;

  Execute Immediate (sInsert||sSelect);
  */
  -- comenzile cu norma asociata liniei si cu obiecte din comanda corespondete normei
  sSelect :=
  &apos;select
    c.codcomanda NAV_CodDoc,
    c.tipdoc NAV_TipDoc,
    c.NrDoc,
    c.DataDoc,
    c.Schimb,
    f.den_formatie Formatie,
    s.den_gest Sectie,
    objprod.denumire DenProd,
    umprod.den_um Prod_UM,
    prod.cant Prod_Cant,
    objprod.codextern Prod_CodExtern,
    objmat.denumire DenComp,
    ummat.den_um Comp_UM,
    um1mat.den_um Comp_UM1,
    nmat.cant/decode(nvl(pc.cant,0),0,1,pc.cant) Comp_CantN,
    nmat.cantum1/decode(nvl(pc.cant,0),0,1,pc.cant) Comp_CantN_UM1,
    objmat.codintern Comp_CodIntern,
    clsasmat.den_claseas Comp_Claseas,
    clsamat.den_clasea Comp_Clasea,
    nor.Norma,
    nvl(nmat.cant,0)*c1.cantacceptat/decode(nvl(pc.cant,0),0,1,pc.cant),
    nvl(nmat.cantum1,0)*c1.cantacceptat/decode(nvl(pc.cant,0),0,1,pc.cant) &apos;||gUserAlias||&apos;
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join prodcomp pc on pc.codprodcomp = c1.codreteta
       inner join ngest s on s.codgest = c.codgest
       inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and prod.tip = 0
       inner join nartobj objprod on objprod.codobiect = prod.codobiect
       inner join nart artprod on objprod.codarticol = artprod.codarticol
       inner join num umprod on umprod.codum = artprod.um
       inner join prodnorme nor on c1.codnorma = nor.codnorma
       inner join normemat nmat on nor.codnorma = nmat.codnorma
       inner join nartobj objmat on objmat.codobiect = nmat.codobiect
       inner join nart artmat on objmat.codarticol = artmat.codarticol
       inner join num ummat on ummat.codum = artmat.um
       left join nclasea clsamat on clsamat.codclasea = artmat.clasa
       left join nclaseas clsasmat on clsasmat.codclaseas = artmat.clasastatist
       left join num um1mat on um1mat.codum = artmat.um1
       left join formatii f on f.codformatie = c.codformatie&apos;||
       gSuplJoins||&apos;
  where c.datadoc between to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        and c.tipdoc = 53
        and nvl(c.anulat,0) = 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  -- comenzile cu norma asociata liniei si cu obiecte din comanda necorespondete normei
  /*sSelect :=
  &apos;select
    c.codcomanda NAV_CodDoc,
    c.tipdoc NAV_TipDoc,
    c.NrDoc,
    c.DataDoc,
    c.Schimb,
    f.den_formatie Formatie,
    s.den_gest Sectie,
    objprod.denumire DenProd,
    umprod.den_um Prod_UM,
    prod.cant Prod_Cant,
    objprod.codextern Prod_CodExtern,
    objmat.denumire DenComp,
    ummat.den_um Comp_UM,
    um1mat.den_um Comp_UM1,
    mat.cant Comp_Cant,
    0 Comp_CantN,
    0 Comp_CantN_UM1,
    objmat.codintern Comp_CodIntern,
    clsasmat.den_claseas Comp_Claseas,
    clsamat.den_clasea Comp_Clasea,
    nor.Norma,
    case when nvl(nmat.cant,0) = 0 then 0 else nvl(mat.cant,0) * nvl(nmat.cantum1,0) / nmat.cant end &apos;||gUserAlias||&apos;
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join prodcomp pc on pc.codprodcomp = c1.codreteta
       inner join ngest s on s.codgest = c.codgest
       inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and prod.tip = 0
       inner join cmdprodmat mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 1
       inner join nartobj objprod on objprod.codobiect = prod.codobiect
       inner join nart artprod on objprod.codarticol = artprod.codarticol
       inner join num umprod on umprod.codum = artprod.um
       inner join nartobj objmat on objmat.codobiect = mat.codobiect
       inner join nart artmat on objmat.codarticol = artmat.codarticol
       inner join num ummat on ummat.codum = artmat.um
       inner join prodnorme nor on c1.codnorma = nor.codnorma
       left join prodmat retmat on retmat.codmat = mat.codprodmat
       left join normemat nmat on nmat.codmat = mat.codprodmat and nor.codnorma = nmat.codnorma
       left join nclasea clsamat on clsamat.codclasea = artmat.clasa
       left join nclaseas clsasmat on clsasmat.codclaseas = artmat.clasastatist
       left join num um1mat on um1mat.codum = artmat.um1
       left join formatii f on f.codformatie = c.codformatie
  where c.datadoc between to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        and c.tipdoc = 53 and nvl(nmat.codnormemat,0) = 0
        and nvl(c.anulat,0) = 0&apos;;

  Execute Immediate (sInsert||sSelect);

  -- comenzile cu norma asociata liniei si cu obiecte din norma inexistente in comanda
  sSelect :=
  &apos;select
    c.codcomanda NAV_CodDoc,
    c.tipdoc NAV_TipDoc,
    c.NrDoc,
    c.DataDoc,
    c.Schimb,
    f.den_formatie Formatie,
    s.den_gest Sectie,
    objprod.denumire DenProd,
    umprod.den_um Prod_UM,
    prod.cant Prod_Cant,
    objprod.codextern Prod_CodExtern,
    objmat.denumire DenComp,
    ummat.den_um Comp_UM,
    um1mat.den_um Comp_UM1,
    0 Comp_Cant,
    nmat.cant Comp_CantN,
    nmat.cantum1 Comp_CantN_UM1,
    objmat.codintern Comp_CodIntern,
    clsasmat.den_claseas Comp_Claseas,
    clsamat.den_clasea Comp_Clasea,
    nor.Norma,
    case when nvl(nmat.cant,0) = 0 then 0 else nvl(mat.cant,0) * nvl(nmat.cantum1,0) / nmat.cant end &apos;||gUserAlias||&apos;
  from comanda c
       inner join comanda1 c1 on c1.codcomanda = c.codcomanda
       inner join prodcomp pc on pc.codprodcomp = c1.codreteta
       inner join ngest s on s.codgest = c.codgest
       inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and prod.tip = 0
       inner join nartobj objprod on objprod.codobiect = prod.codobiect
       inner join nart artprod on objprod.codarticol = artprod.codarticol
       inner join num umprod on umprod.codum = artprod.um
       inner join prodnorme nor on c1.codnorma = nor.codnorma
       inner join normemat nmat on nor.codnorma = nmat.codnorma
       inner join nartobj objmat on objmat.codobiect = nmat.codobiect
       inner join nart artmat on objmat.codarticol = artmat.codarticol
       inner join num ummat on ummat.codum = artmat.um
       left join cmdprodmat mat on c1.codcomanda1 = mat.codcomanda1 and mat.tip = 1
       left join prodmat retmat on retmat.codmat = mat.codprodmat
       left join nclasea clsamat on clsamat.codclasea = artmat.clasa
       left join nclaseas clsasmat on clsasmat.codclaseas = artmat.clasastatist
       left join num um1mat on um1mat.codum = artmat.um1
       left join formatii f on f.codformatie = c.codformatie
  where c.datadoc between to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)
        and c.tipdoc = 53 and nvl(mat.codprodmat,0) = 0
        and nvl(c.anulat,0) = 0&apos;;

  Execute Immediate (sInsert||sSelect);
  */
  --delete x;
  --insert into x(test) values(sSelect);
  --commit;

  Commit;
END;

end PKG_LIST_BASE_RAPORTSCHIMB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPORTVANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAEDE5F7253EE8907B130E4C14F88A6916A44D35</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPORTVANZARI IS

  vTipData     BOOLEAN;
  vInceput     VARCHAR2(50);
  vSfarsit     VARCHAR2(50);
  xInceput     VARCHAR2(50);
  xSfarsit     VARCHAR2(50);
  vTipTarget   INTEGER; -- 0 fara analiza ; 1 analiza agent; 2 analiza client
  vValuta      BOOLEAN;
  vCatPret     NUMBER;
  vAllPart     NUMBER;  -- 0 toti, 1 include, 2 exclude

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS  (pTipData IN NUMBER, pInceput IN VARCHAR2, pSfarsit IN VARCHAR2, pTipTarget IN NUMBER, pValuta IN NUMBER, pCatPret IN NUMBER DEFAULT 0, pAllPart IN NUMBER DEFAULT 0, V_CODJOB1 IN NUMBER) IS
  vAuxData   DATE;
  vAuxData1  DATE;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10);
  sDataF     VARCHAR2(10);
BEGIN
  vTipTarget := pTipTarget;
  vValuta    := pValuta = 1;
  vCatPret   := pCatPret;
  vAllPart   := pAllPart;

  sDataS := pInceput;
  sDataF := pSfarsit;
  vTipData   := pTipData = 1;
  IF vTipData THEN
		xLunaAnIni := extract(year from to_date(sDataS,&apos;dd.mm.yyyy&apos;))*12+extract(month from to_date(sDataS,&apos;dd.mm.yyyy&apos;));
		xLunaAnFin := extract(year from to_date(sDataF,&apos;dd.mm.yyyy&apos;))*12+extract(month from to_date(sDataF,&apos;dd.mm.yyyy&apos;));
    vInceput := &apos;To_Date(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    vSfarsit := &apos;To_Date(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
		IF NVL(v_CodJob1,0) &gt; 0 THEN
			PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vInceput,vSfarsit,xLunaAnIni,xLunaAnFin);
		END IF;
    xInceput := vInceput;
    xSfarsit := vSfarsit;
  ELSE
		xLunaAnIni := PKG_GLOBALS.AnLucru*12 + sDataS ;
		xLunaAnFin := PKG_GLOBALS.AnLucru*12 + sDataF ;
    vInceput := sDataS;
    vSfarsit := sDataF;
    vAuxData := Trunc(To_Date(PKG_GLOBALS.ANLUCRU||&apos;.&apos;||sDataS,&apos;yyyy.mm&apos;),&apos;mm&apos;);
    vAuxData1:= Last_Day(Trunc(To_Date(PKG_GLOBALS.ANLUCRU||&apos;.&apos;||sDataF,&apos;yyyy.mm&apos;),&apos;mm&apos;));
		IF NVL(v_CodJob1,0) &gt; 0 THEN
			PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vAuxData,vAuxData1,xLunaAnIni,xLunaAnFin);
		END IF;
    xInceput := &apos;To_Date(&apos;&apos;&apos;||TO_Char (vAuxData,&apos;dd.mm.yyyy&apos;) ||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    xSfarsit := &apos;To_Date(&apos;&apos;&apos;||TO_Char (vAuxData1,&apos;dd.mm.yyyy&apos;) ||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  sSelect      VARCHAR2(30000);
  sWhereP      VARCHAR2( 1000);
  sCurs        VARCHAR2(  300);
  sInsertUMA   VARCHAR2( 1000);
  sSelectUMA   VARCHAR2( 5000);
  sSelectIG    VARCHAR2(  500);
  sFiltruPart  VARCHAR2(  500) := &apos;&apos;;
  sFromIG      VARCHAR2( 1000);
  sJoinIG      VARCHAR2( 1000);
  sWhereIG     VARCHAR2( 1000);
  sGroupIG     VARCHAR2(  500);
  sWith        VARCHAR2( 5000);
  sJoin        VARCHAR2( 2000);
  aSitV        NUMBER(1);
  aBancaV      NUMBER(20);
  aMonedaV     NUMBER(20);
  sCondCatPret VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;nartobj nao, nart na, num num, npers ag, nclasea nca, nclaseas ncs, npart prod, npart np, nclasep ncp, nagenda sed, nlocalit sedl, pretm p&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sWhereP :=&apos;
        AND &apos;;

  IF vTipData
  THEN sWhereP := sWhereP||&apos;I.DATADOC&apos;;
  ELSE sWhereP := sWhereP||&apos;I.An = &apos;||PKG_GLOBALS.ANLUCRU||&apos; AND I.LUNA&apos;;
  END IF;

  IF vInceput = vSfarsit
  THEN sWhereP := sWhereP||&apos; = &apos;||vInceput;
  ELSE sWhereP := sWhereP||&apos; BETWEEN &apos;||vInceput||&apos; AND &apos;||vSfarsit;
  END IF;

  IF vAllPart = 1 THEN
    sFiltruPart := &apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  IF vAllPart = 2 THEN
    sFiltruPart := &apos; NOT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  IF sFiltruPart IS NOT NULL THEN
    sWhereP := sWhereP ||&apos;
        AND I.PARTENER&apos;||sFiltruPart;
  END IF;

  IF vValuta AND pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCurs := &apos; / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i1.datadoc )&apos;;
  END IF;

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;ig.cant&apos;,&apos;ig.codobiect&apos;,sInsertUMA,sSelectUMA,sJoin);

  IF vTipTarget = 1 THEN -- target agent
    sSelectIG := &apos;
        T.AGENT, 0 PARTENER, 0 CODLOCATIE,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END CLASAS,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END CLASA,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT                             ELSE 0 END CODOBIECT,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET, T.NRCLIENTI, COUNT(DISTINCT CA.CODIES) CountCli,&apos;;
    sFromIG := &apos;TARGET T
        LEFT JOIN I1 ON T.AGENT = I1.AGENT AND I1.DATADOC BETWEEN T.DATASTART AND T.DATASTOP AND I1.CANT &lt;&gt; 0
          AND CASE T.TIPTARGET WHEN 0 THEN T.CODOBIECT ELSE I1.CODOBIECT END = I1.CODOBIECT
          AND CASE T.TIPTARGET WHEN 2 THEN T.CLASA     ELSE I1.CLASA     END = I1.CLASA
          AND CASE T.TIPTARGET WHEN 3 THEN T.CLASAS    ELSE I1.CLASAS    END = I1.CLASAS
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = Coalesce(I1.CODOBIECT, T.CODOBIECT)
        LEFT JOIN NART A ON A.CODARTICOL = O.CODOBIECT&apos;;
    sJoinIG  := &apos;
        LEFT JOIN CA ON CA.CODIES = I1.CODIES AND I1.IDX = 1&apos;;
    sGroupIG := &apos;T.AGENT,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT                             ELSE 0 END,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET, T.NRCLIENTI&apos;;

    sWith := sWith||&apos;
    CA AS (
      SELECT Min(i.codies) KEEP (Dense_Rank FIRST ORDER BY i.datadoc, i.codies) codies
      FROM iesiri i
      WHERE i.anulat = 0 AND i.operat = 1
        AND i.tipdoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
        AND Coalesce(i.partener,0) &lt;&gt; 0 AND Coalesce(i.codlocatie,0) &lt;&gt; 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||
    CASE
      WHEN sFiltruPart IS NOT NULL THEN &apos;
        AND I.PARTENER&apos;||sFiltruPart
    END ||&apos;
      GROUP BY i.partener, i.codlocatie, i.subunitatea),
    TARGET AS (
      SELECT
        T.AGENT, T.DATASTART, T.DATASTOP, Coalesce(T.TIPTARGET,0) TIPTARGET, Coalesce(T.NRCLIENTI,0) NRCLIENTI,
        T1.CODOBIECT, C.CLASABAZA, C.CLASA, CS.CLASASBAZA, CS.CLASAS,
        Coalesce(T1.CANT,0) CANTTARGET, Coalesce(T1.VALOARE,0) VALTARGET, Coalesce(T1.MASA,0) MASATARGET, Coalesce(T1.VOLUM,0) VOLUMTARGET
      FROM TARGETAG T
        INNER JOIN TARGETAG1 T1 ON T1.CODTARGETAG = T.CODTARGETAG
        LEFT JOIN (
          SELECT connect_by_root codclasea clasabaza, codclasea clasa
          FROM nclasea
          CONNECT BY codparinte = PRIOR codclasea
        ) C ON C.CLASABAZA = CASE T.TIPTARGET WHEN 2 THEN T1.CODCLASA ELSE 0 END
        LEFT JOIN (
          SELECT connect_by_root codclaseas clasasbaza, codclaseas clasas
          FROM nclaseas
          CONNECT BY codparinte = PRIOR codclaseas
        ) CS ON CS.CLASASBAZA = CASE T.TIPTARGET WHEN 3 THEN T1.CODCLASAS ELSE 0 END
      WHERE T.TIPDOC = 17
        AND T.DATASTART &lt;= &apos;||xSfarsit||&apos;
        AND T.DATASTOP &gt;= &apos;||xInceput||&apos;
        AND T.ANULAT = 0 AND T.OPERAT = 1 AND T.ACTIV = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;),&apos;;
  ELSIF vTipTarget = 2 THEN -- target client
    sSelectIG := &apos;
        0 AGENT, T.CLIENT PARTENER, 0 CODLOCATIE,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END CLASAS,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END CLASA,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT                             ELSE 0 END CODOBIECT,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET, 1 NRCLIENTI, 1 CountCli,&apos;;
    sFromIG := &apos;TARGET T
        LEFT JOIN I1 ON T.CLIENT = I1.PARTENER AND I1.DATADOC BETWEEN T.DATASTART AND T.DATASTOP AND I1.CANT &lt;&gt; 0
          AND CASE T.TIPTARGET WHEN 0 THEN T.CODOBIECT ELSE I1.CODOBIECT END = I1.CODOBIECT
          AND CASE T.TIPTARGET WHEN 2 THEN T.CLASA     ELSE I1.CLASA     END = I1.CLASA
          AND CASE T.TIPTARGET WHEN 3 THEN T.CLASAS    ELSE I1.CLASAS    END = I1.CLASAS
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = Coalesce(I1.CODOBIECT, T.CODOBIECT)
        LEFT JOIN NART A ON A.CODARTICOL = O.CODOBIECT&apos;;
    sJoinIG  := &apos;&apos;;
    sGroupIG := &apos;T.CLIENT,
        CASE T.TIPTARGET WHEN 3 THEN T.CLASASBAZA WHEN 0 THEN A.CLASASTATIST ELSE 0 END,
        CASE T.TIPTARGET WHEN 2 THEN T.CLASABAZA  WHEN 0 THEN A.CLASA        ELSE 0 END,
        CASE T.TIPTARGET WHEN 0 THEN O.CODOBIECT                             ELSE 0 END,
        T.CANTTARGET, T.VALTARGET, T.MASATARGET, T.VOLUMTARGET, T.TIPTARGET&apos;;
    sWith := sWith||&apos;
    TARGET AS (
      SELECT
        T.CLIENT, T.DATASTART, T.DATASTOP, Coalesce(T.TIPTARGET,0) TIPTARGET,
        T1.CODOBIECT, C.CLASABAZA, C.CLASA, CS.CLASASBAZA, CS.CLASAS,
        Coalesce(T1.CANT,0) CANTTARGET, Coalesce(T1.VALOARE,0) VALTARGET, Coalesce(T1.MASA,0) MASATARGET, Coalesce(T1.Volum,0) VOLUMTARGET
      FROM TARGETAG T
        INNER JOIN TARGETAG1 T1 ON T1.CODTARGETAG = T.CODTARGETAG
        LEFT JOIN (
          SELECT connect_by_root codclasea clasabaza, codclasea clasa
          FROM nclasea
          CONNECT BY codparinte = PRIOR codclasea
        ) C ON C.CLASABAZA = CASE T.TIPTARGET WHEN 2 THEN T1.CODCLASA ELSE 0 END
        LEFT JOIN (
          SELECT connect_by_root codclaseas clasasbaza, codclaseas clasas
          FROM nclaseas
          CONNECT BY codparinte = PRIOR codclaseas
        ) CS ON CS.CLASASBAZA = CASE T.TIPTARGET WHEN 3 THEN T1.CODCLASAS ELSE 0 END
      WHERE T.TIPDOC = 65
        AND T.DATASTART &lt;= &apos;||xSfarsit||&apos;
        AND T.DATASTOP &gt;= &apos;||xInceput||&apos;
        AND T.ANULAT = 0 AND T.OPERAT = 1 AND T.ACTIV = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
    CASE
      WHEN sFiltruPart IS NOT NULL THEN &apos;
        AND T.CLIENT&apos;||sFiltruPart
    END||&apos;),&apos;;
  ELSE
    sSelectIG := &apos;
        I1.AGENT, I1.PARTENER, I1.CODLOCATIE,
        I1.CLASA,
        I1.CLASAS,
        I1.CODOBIECT, 
        0 CANTTARGET, 0 VALTARGET, 0 MASATARGET, 0 VOLUMTARGET, 0 TIPTARGET, 0 NRCLIENTI, COUNT(DISTINCT I1.PARTENER||&apos;&apos; &apos;&apos;||I1.CODLOCATIE) CountCli,&apos;;
    sFromIG := &apos;I1
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT&apos;;
    sWhereIG := &apos;
      WHERE i1.cant &lt;&gt; 0&apos;;
    sGroupIG  := &apos;I1.AGENT, I1.PARTENER, I1.CODLOCATIE, I1.CLASA, I1.CLASAS, I1.CODOBIECT&apos;;
  END IF;

  sCondCatPret := &apos; AND P.Subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE;
	IF Coalesce(vCatPret,0) = 0
  THEN sCondCatPret := sCondCatPret||&apos; AND p.implicit = 1 &apos;;
  ELSE sCondCatPret := sCondCatPret||&apos; AND p.codcatpret = &apos;||vCatPret;
  END IF;


  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;(
    Art,
    UM, Cant, Val, ValCuTva, VU, ValAchiz, Masa, Volum,
    DenClasaA, CodInt, CodExt, Prod, PretVinz, PretValuta,
    Agent, NrCli,
    Client, DenClasaC, SedCli, AdrSedCli, NrUtilaje,
    TarTip,
    TarCant, TarVal, TarMasa, TarVolum, TarNrCli&apos;||sInsertUMA||gUserFields||&apos;
  )&apos;;

  sSelect := &apos;
  WITH &apos;||sWith||&apos;
    I1 AS (
      SELECT
        I.CODIES, I1.CODIES1, I.DATADOC,CASE WHEN I.CURS IS NULL THEN 1 WHEN I.CURS = 0 THEN 1 ELSE I.CURS END CURS, Coalesce(I.AGENT,0) AGENT, I.PARTENER, Coalesce(I.CODLOCATIE,0) CODLOCATIE,
        I1.CODOBIECT, Coalesce(A.CLASA,0) CLASA, Coalesce(A.CLASASTATIST,0) CLASAS, I1.CANT, I1.PU, I.VALDOC - I.TVADOC VALDOC, I.VALDOC VALTDOC,
        CASE
          WHEN I1.ADDIM = -100 THEN 0
          WHEN I.TIPDOC IN (16,21) THEN (I1.PU * I1.CANT - I1.TVA) / (1+Coalesce(I1.ADDim/100,0))
          ELSE I1.PU * I1.CANT / (1+Coalesce(I1.ADDim/100,0))
        END * Coalesce(I1.COEFDISCMAJ,1) VALLIN,
        CASE
          WHEN I1.ADDIM = -100 THEN 0
          WHEN I.TIPDOC IN (16,21) THEN I1.PU * I1.CANT / (1+Coalesce(I1.ADDim/100,0))
          ELSE (I1.PU * I1.CANT + I1.TVA) / (1+Coalesce(I1.ADDim/100,0))
        END * Coalesce(I1.COEFDISCMAJ,1) VALTLIN,
        SUM(
          CASE
            WHEN I1.ADDIM = -100 THEN 0
            WHEN I.TIPDOC IN (16,21) THEN (I1.PU * I1.CANT - I1.TVA) / (1+Coalesce(I1.ADDim/100,0))
            ELSE I1.PU * I1.CANT / (1+Coalesce(I1.ADDim/100,0))
          END * Coalesce(I1.COEFDISCMAJ,1)
        ) OVER (PARTITION BY I.CODIES) VALIES,
        SUM(
          CASE
            WHEN I1.ADDIM = -100 THEN 0
            WHEN I.TIPDOC IN (16,21) THEN I1.PU * I1.CANT / (1+Coalesce(I1.ADDim/100,0))
            ELSE (I1.PU * I1.CANT + I1.TVA) / (1+Coalesce(I1.ADDim/100,0))
          END * Coalesce(I1.COEFDISCMAJ,1)
        ) OVER (PARTITION BY I.CODIES) VALTIES,
        ROW_NUMBER() OVER (PARTITION BY I.CODIES ORDER BY I1.CODIES1) IDX
      FROM IESIRI I
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
        INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
        INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      WHERE I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;) AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        sWhereP||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;),
    IG AS (
      SELECT &apos;||
        sSelectIG||&apos;
        SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(L1.CANT,0) &lt;&gt; 0 THEN L1.CANT*I1.CANT/AE1.CANT ELSE COALESCE(L1.CANT,I1.CANT,0) END) CANT,
        SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(L1.CANT,0) &lt;&gt; 0 THEN L1.CANT*I1.CANT/AE1.CANT ELSE COALESCE(L1.CANT,I1.CANT,0) END*Coalesce(O.MASA,0)) MASA,
        SUM(CASE WHEN Coalesce(AE1.CANT,0) &lt;&gt; 0 AND Coalesce(L1.CANT,0) &lt;&gt; 0 THEN L1.CANT*I1.CANT/AE1.CANT ELSE COALESCE(L1.CANT,I1.CANT,0) END*Coalesce(O.VOLUM,0)) VOLUM,
        Coalesce(SUM(i1.pu * COALESCE(L1.CANT,I1.CANT,0)&apos;||sCurs||&apos;* i1.curs),0) vu,
        Coalesce(SUM(i1.vallin *CASE WHEN i1.valies  = 0 THEN 1 ELSE i1.valdoc /i1.valies  END*Coalesce(l1.cant,i1.cant)/i1.cant*i1.curs&apos;||sCurs||&apos;),0) val,
        Coalesce(SUM(i1.valtlin*CASE WHEN i1.valties = 0 THEN 0 ELSE i1.valtdoc/i1.valties END*Coalesce(l1.cant,i1.cant)/i1.cant*i1.curs&apos;||sCurs||&apos;),0) valcutva,
        Coalesce(SUM( COALESCE(LV.PRETACHIZ,NS.PRET - NS.ADAOS,0) * Coalesce(l1.cant,i1.cant)),0) valachiz
      FROM &apos;||sFromIG||&apos;
        LEFT JOIN IESLINK IL ON IL.CODIES1 = I1.CODIES1
        LEFT JOIN IESIRI1 AE1 ON AE1.CODIES1 = IL.CODLINIEAVIZ
        LEFT JOIN LIVR L ON L.CODIES = Coalesce(AE1.CODIES,I1.CODIES)
        LEFT JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = Coalesce(IL.CODLINIEAVIZ,I1.CODIES1)
        LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1&apos;||
        sJoinIG||
      sWhereIG||&apos;
      GROUP BY &apos;||sGroupIG||&apos; )
  SELECT
    CASE
      WHEN Coalesce(NAO.CODOBIECT, 0) &lt;&gt; 0 THEN NAO.DENUMIRE
      WHEN Coalesce(NCA.CODCLASEA, 0) &lt;&gt; 0 THEN NCA.DEN_CLASEA
      WHEN Coalesce(NCS.CODCLASEAS,0) &lt;&gt; 0 THEN NCS.DEN_CLASEAS
      ELSE &apos;&apos;...&apos;&apos;
    END,
    Coalesce(NUM.DEN_UM,&apos;&apos;...&apos;&apos;), CASE WHEN IG.CODOBIECT = 0 THEN 0 ELSE IG.CANT END, IG.VAL, IG.VALCUTVA, IG.VU, IG.VALACHIZ, IG.MASA, IG.VOLUM,
    NCA.DEN_CLASEA, NAO.CODINTERN, NAO.CODEXTERN, PROD.DEN_PART, P.LEI PRETVANZ, P.VALUTA,
    NUMEPRENUME(AG.NUME,AG.PRENUME) Agent, IG.CountCli NrCli, 
    NP.DEN_PART Client, NCP.DEN_CLASEP DenClasaC, SED.OBS SedCli, SEDL.DEN_LOCALIT||&apos;&apos; &apos;&apos;||GETADRESA(SED.SECTOR,SED.STRADA,SED.NR1,SED.NR2,SED.BLOC,SED.SCARA,SED.ETAJ,SED.APART,SED.CODPOSTAL) AdrSedCli, SED.COEFUTILAJE NrUtilaje,
    CASE IG.TIPTARGET
      WHEN NULL THEN &apos;&apos; &apos;&apos;
      WHEN    3 THEN &apos;&apos;Pe clase statistice de articole&apos;&apos;
      WHEN    2 THEN &apos;&apos;Pe clase de articole&apos;&apos;
      WHEN    1 THEN &apos;&apos;Toate Articolele&apos;&apos;
      WHEN    0 THEN &apos;&apos;Pe articole&apos;&apos;
    END TarTip,
    IG.CANTTARGET TarCant, IG.VALTARGET TarVal, IG.MASATARGET TarMasa, IG.VOLUMTARGET TarVolum, IG.NRCLIENTI TarNrCli &apos;||sSelect||sSelectUMA||gUserAlias||&apos;
  FROM IG
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = IG.CODOBIECT
    LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = IG.CLASA
    LEFT JOIN NCLASEAS NCS ON NCS.CODCLASEAS = IG.CLASAS
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NPART NP ON NP.CODPART = IG.PARTENER
    LEFT JOIN NCLASEP NCP ON NCP.CODCLASEP = NP.CODCLASA
    LEFT JOIN NAGENDA SED ON SED.CODAGENDA = IG.CODLOCATIE
    LEFT JOIN NLOCALIT SEDL ON SEDL.CODLOCALIT = SED.CODLOCALIT
    LEFT JOIN NPERS AG ON AG.CODPERS = IG.AGENT
    LEFT JOIN PRETM P ON P.CODOBIECT = IG.CODOBIECT &apos;||sCondCatPret||
    sJoin||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

END PKG_LIST_BASE_RAPORTVANZARI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RAPSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0C9F8A538546F979657A2F96A22195F0ED35926</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RAPSTOC IS

  dDataIni      DATE;
  dDataFin      DATE;
  vPromoSeparat BOOLEAN;
  vToateGest    BOOLEAN ;
  vToateIOArt   BOOLEAN ;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pDataIni      IN VARCHAR2 DEFAULT NULL,
                    pDataFin      IN VARCHAR2 DEFAULT NULL,
                    pPromoSeparat IN NUMBER   DEFAULT 0,
                    pToateGest    IN NUMBER   DEFAULT 1,
                    pToateIOArt   IN NUMBER   DEFAULT 1,
                    V_CODJOB1     IN NUMBER   DEFAULT 0
                   ) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vPromoSeparat := pPromoSeparat = 1;
  vToateGest    := pToateGest = 1;
  vToateIOArt   := pToateIOArt = 1;
  dDataIni      := To_Date(pDataIni,&apos;dd.mm.yyyy&apos;);
  dDataFin      := To_Date(pDataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataIni,dDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

PROCEDURE BagaDinamicCols IS
  sInsert       CLOB;
  vCondAnLuna   VARCHAR2(300);
  vAnStart      NUMBER(4)      := To_Char(dDataIni,&apos;yyyy&apos;);
  vLunaStart    NUMBER(2)      := To_Char(dDataIni,&apos;mm&apos;);
  vAnStop       NUMBER(4)      := To_Char(dDataFin,&apos;yyyy&apos;);
  vLunaStop     NUMBER(2)      := To_Char(dDataFin,&apos;mm&apos;);
  vAnPreced     NUMBER(4);
  vLunaPreced   NUMBER(2);
  vDataIni      VARCHAR2(10)   := To_Char(dDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin      VARCHAR2(10)   := To_Char(dDataFin,&apos;dd.mm.yyyy&apos;);
  vFiltru       VARCHAR2(1000);
  sPromo        VARCHAR2(500);
BEGIN

  IF Trunc(PKG_LIST_SELECTSCAD.DataIni,&apos;MM&apos;) = Trunc(PKG_LIST_SELECTSCAD.DataScad,&apos;MM&apos;)
  THEN vCondAnLuna := &apos;= &apos;||To_Char(vAnStart*12+vLunaStart);
  ELSE vCondAnLuna := &apos;BETWEEN &apos;||To_Char(vAnStart*12+vLunaStart)||&apos; AND &apos;||To_Char(vAnStop*12+vLunaStop);
  END IF;
  pkg_globals.Calculeaza_Luna_Precedenta(vAnStart,vLunaStart,vAnPreced,vLunaPreced);

  if NOT vToateGest THEN
    vFiltru := vFiltru||&apos;
        AND N.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  end if;

  if NOT vToateIOArt THEN
    vFiltru := vFiltru||&apos;
        AND NS.CODIOART IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;)&apos;;
  end if;

  IF vPromoSeparat THEN
    sPromo := &apos;, CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 WHEN NVL(CADOU,0) = 0 AND NVL(PRETPROMO,0) = 0 THEN 0 ELSE 1 END PROMO&apos;;
  ELSE
    sPromo := &apos;, 0 PROMO&apos;;
  END IF;

  DELETE tmp_list_rapstoc;

  sInsert:=
  &apos;INSERT INTO tmp_list_rapstoc( CodGest, CodObiect, CodDoc, TipDoc, Cant, Semn, Promo )
  WITH
    B AS (
      -- Initial
      SELECT
        N.GEST, NS.CODOBIECT, 0 CODDOC, 0 TIPDOC, &apos;&apos; Stoc initial&apos;&apos; DOC, TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) DATADOC, NL.REST CANT, 1 SEMN, 0 PROMO
      FROM NIRLUNA NL
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        INNER JOIN NGEST   G   ON G.CODGEST     = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
      WHERE nl.an = &apos;||vANPreced||&apos; AND nl.luna = &apos;||vLunaPreced||vFiltru||&apos;
      UNION ALL -- NIR Intrari
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.CODINTR END CODDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.TIPDOC END TIPDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||I.DATADOC END DOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE I.DATADOC END DATADOC,
        NS.CANTNIR CANTINT, 1 SEMN, 0 PROMO
      FROM NIRSTOC NS
        INNER JOIN NIR     N   ON N.CODNIR     = NS.CODNIR
        INNER JOIN IOART1  IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN INTRARI I   ON I.CODINTR    = N.CODINTR
      WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND I.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||vFiltru||&apos;
      UNION ALL -- NIR-uri din MISCARI INTERNE
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE T.CODTRANSF END CODDOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE T.TIPDOC END TIPDOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE T.PREFIXDOC||T.NRDOC||&apos;&apos;/&apos;&apos;||T.DATADOC END DOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE T.DATADOC END DATADOC,
        NS.CANTNIR CANTINT,  1 SEMN, 0 PROMO
      FROM NIRSTOC NS
        INNER JOIN NIR    N   ON N.CODNIR     = NS.CODNIR
        INNER JOIN IOART1 IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN TRANSF T   ON T.CODTRANSF  = N.CODTRANSF
      WHERE N.TIPNIR IN (12, 13) AND N.ANULAT = 0 AND N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND T.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||vFiltru||&apos;
      UNION ALL -- RETURURI
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.CODINTR END CODDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.TIPDOC END TIPDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||I.DATADOC END DOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE I.DATADOC END DATADOC,
        -L1.CANT CANTINT,  1 SEMN, 0 PROMO
      FROM LIVR1 L1
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN LIVR    L   ON L.CODLIVR     = L1.CODLIVR
        INNER JOIN INTRARI I   ON I.CODINTR     = L.CODINTR
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND I.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||vFiltru||&apos;
      UNION ALL -- IESIRI
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.CODIES END CODDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.TIPDOC END TIPDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||I.DATADOC END DOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE I.DATADOC END DATADOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN -L1.CANT ELSE L1.CANT END CANT,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 1 ELSE -1 END semn&apos;||sPromo||&apos;
      FROM LIVR1 L1
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN LIVR    L   ON L.CODLIVR     = L1.CODLIVR
        INNER JOIN IESIRI  I   ON I.CODIES      = L.CODIES
        INNER JOIN IESIRI1 I1  ON I1.CODIES1    = L1.CODIES1
      WHERE L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND I.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||vFiltru||&apos;
      UNION ALL -- MISCARI INTERNE
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE T.CODTRANSF END CODDOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE T.TIPDOC END TIPDOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE T.PREFIXDOC||T.NRDOC||&apos;&apos;/&apos;&apos;||T.DATADOC END DOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE T.DATADOC END DATADOC,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN -L1.CANT ELSE L1.CANT END CANT,
        CASE WHEN T.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 1 ELSE -1 END semn, 0 PROMO
      FROM LIVR1 L1
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN LIVR    L   ON L.CODLIVR     = L1.CODLIVR
        INNER JOIN TRANSF  T   ON T.CODTRANSF   = L.CODTRANSF
      WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        AND (T.AN *12 + T.LUNA) &apos;||vCondAnLuna||&apos; AND T.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||vFiltru||&apos;
      UNION ALL -- MARIRI DE STOC
      SELECT
        N.GEST, NS.CODOBIECT,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.CODIES END CODDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN 0 ELSE I.TIPDOC END TIPDOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN &apos;&apos; Stoc initial&apos;&apos; ELSE I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||I.DATADOC END DOC,
        CASE WHEN I.DATADOC &lt; to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) THEN TO_DATE(to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) ELSE I.DATADOC END DATADOC,
        L1.CANT, 1 SEMN, 0 PROMO
      FROM LIVR1 L1
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||To_Char(vAnStop*12+vLunaStop)||&apos; BETWEEN IOA.ALStart and IOA.ALStop  AND IOA.mg &lt;&gt; 5
        INNER JOIN LIVR    L   ON L.CODLIVR     = L1.CODLIVR
        INNER JOIN IESIRI  I   ON I.CODIES      = L.CODIES
      WHERE L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        AND (I.AN *12 + I.LUNA) &apos;||vCondAnLuna||&apos; AND I.DATADOC &lt;= to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||vFiltru||&apos;
    )
  SELECT gest, codobiect, coddoc, tipdoc, sum(cant), decode(tipdoc,0,1,semn), promo
  FROM b
  GROUP BY gest, codobiect, coddoc, tipdoc, semn, promo&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, 0, 0);
  DELETE tmp_list_rapstoc WHERE cant = 0;

  COMMIT;

  DELETE tmp_dinamic_cols;
  INSERT INTO tmp_dinamic_cols(FieldName, Display, INDEXLOCAL)
  SELECT
    &apos;C&apos;||Row_Number() OVER (ORDER BY O.DENUMIRE),
    SubStr(O.DENUMIRE, 1,5)||&apos;/&apos;||SubStr(O.DENUMIRE, 6,5)||&apos;/&apos;||SubStr(O.DENUMIRE,11,5)||&apos;/&apos;||SubStr(O.DENUMIRE,16,5)||&apos;/&apos;||
    SubStr(O.DENUMIRE,21,5)||&apos;/&apos;||SubStr(O.DENUMIRE,26,5)||&apos;/&apos;||SubStr(O.DENUMIRE,31,5)||&apos;/&apos;||SubStr(O.DENUMIRE,36,5)||&apos;/&apos;||O.CODEXTERN,
    O.CODOBIECT
  FROM (
    SELECT DISTINCT CODOBIECT
    FROM tmp_list_rapstoc
    WHERE coddoc &lt;&gt; 0  --STEF -- EXCLUD STOCURI INITIALE FIINDCA SUNT PREA MULTE SI CRAPA LISTA
  ) X INNER JOIN NARTOBJ O ON O.CODOBIECT = X.CODOBIECT;

  COMMIT;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  sDinCol  CLOB;
  sDinSel  CLOB;
  sDinTmp  CLOB;
  vDataIni VARCHAR2(10)   := To_Char(PKG_LIST_SELECTSCAD.DataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin VARCHAR2(10)   := To_Char(PKG_LIST_SELECTSCAD.DataScad,&apos;dd.mm.yyyy&apos;);
BEGIN
  gSuplCols := &apos;ngest g, intrari intr, iesiri ies, transf t, npart p, npers ag&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  FOR v_rec IN (SELECT FIELDNAME, INDEXLOCAL FROM tmp_dinamic_cols ORDER BY INDEXLOCAL) LOOP
    sDinCol := sDinCol||&apos;,&apos;||v_rec.FIELDNAME;
    sDinSel := sDinSel||&apos;, r.&apos;||v_rec.FIELDNAME;
    sDinTmp := sDinTmp||&apos;,SUM(DECODE(CodObiect,&apos;||v_rec.INDEXLOCAL||&apos;,Cant,0)) &apos;||v_rec.FIELDNAME;
  END LOOP;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, DenGest, Part, Promo, TipDoc, Doc, DataDoc, Ord &apos;||sDinCol||gUserFields||&apos;)
  WITH r AS (
    SELECT coddoc, tipdoc, promo, codgest, semn &apos;||sDinTmp||&apos;
    FROM tmp_list_rapstoc
    GROUP BY coddoc, tipdoc, promo, codgest, semn
  )
  SELECT
    r.CODDOC, r.TIPDOC, g.Den_Gest,
    CASE
      WHEN r.TIPDOC =  0 THEN &apos;&apos;Stoc initial la &apos;||vDataIni||&apos;&apos;&apos;
      WHEN r.TIPDOC =  6 THEN &apos;&apos;Intrare de la subunitate&apos;&apos;
      WHEN r.TIPDOC =  7 THEN &apos;&apos;Intrare din productie&apos;&apos;
      WHEN r.TIPDOC = 12 AND r.SEMN = 1 THEN &apos;&apos;Intrare prin transfer&apos;&apos;
      WHEN r.TIPDOC = 12 THEN &apos;&apos;Iesire prin transfer&apos;&apos;
      WHEN r.TIPDOC = 14 THEN &apos;&apos;Minus la inventar&apos;&apos;
      WHEN r.TIPDOC = 15 THEN &apos;&apos;Plus la inventar&apos;&apos;
      WHEN r.TIPDOC = 16 THEN &apos;&apos;Iesiri pe monetar&apos;&apos;
      WHEN r.TIPDOC = 23 THEN &apos;&apos;Iesire catre alta subunitate&apos;&apos;
      WHEN r.TIPDOC = 24 THEN &apos;&apos;Iesire in consum&apos;&apos;
      ELSE p.Den_part
    END,
    DECODE(r.Promo,1,&apos;&apos;Da&apos;&apos;,&apos;&apos;Nu&apos;&apos;),
    Decode(r.TIPDOC,0,&apos;&apos;S&apos;&apos;,12,&apos;&apos;T&apos;&apos;,13,&apos;&apos;PV&apos;&apos;,14,&apos;&apos;PV&apos;&apos;,15,&apos;&apos;PV&apos;&apos;,16,&apos;&apos;M&apos;&apos;,2,&apos;&apos;AE&apos;&apos;,20,&apos;&apos;AE&apos;&apos;,3,&apos;&apos;CF&apos;&apos;,21,&apos;&apos;CF&apos;&apos;,&apos;&apos;F&apos;&apos;),
    CASE
      WHEN r.TIPDOC = 0 THEN &apos;&apos;Stoc initial&apos;&apos;
      ELSE Coalesce(intr.prefixdoc,ies.prefixdoc,t.prefixdoc)||Coalesce(intr.nrdoc,ies.nrdoc,t.nrdoc)||&apos;&apos;/&apos;&apos;||To_Char(Coalesce(intr.datadoc,ies.datadoc,t.datadoc),&apos;&apos;dd.mm.yyyy&apos;&apos;)
    END,
    CASE WHEN r.TIPDOC = 0 THEN to_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) ELSE Coalesce(intr.datadoc,ies.datadoc,t.datadoc) END,
    Decode(r.TIPDOC,0,0,1) &apos;||sDinSel||gUserAlias||&apos;
  FROM r
    LEFT JOIN ngest g ON g.codgest = r.codgest
    LEFT JOIN intrari intr ON intr.codintr = r.coddoc AND intr.tipdoc = r.tipdoc
    LEFT JOIN iesiri ies ON ies.codies = r.coddoc AND ies.tipdoc = r.tipdoc
    LEFT JOIN transf t ON t.codtransf = r.coddoc AND t.tipdoc = r.tipdoc
    LEFT JOIN npart p ON p.codpart = Coalesce(intr.partener,ies.partener,0)
    LEFT JOIN npers ag ON ag.codpers = COALESCE(ies.agent,0) &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, DenGest, Part, Promo, TipDoc, Doc, DataDoc, Ord &apos;||sDinCol||&apos;)
  WITH r AS (
    SELECT codgest &apos;||sDinTmp||&apos;
    FROM ( SELECT codgest, codobiect, SUM(cant * semn) cant FROM tmp_list_rapstoc GROUP BY codgest, codobiect)
    GROUP BY codgest
  )
  SELECT
    0, 0, g.Den_Gest,
    &apos;&apos;Stoc final la &apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;Nu&apos;&apos;, &apos;&apos;S&apos;&apos;, &apos;&apos;Stoc final&apos;&apos;, to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;),2 &apos;||sDinSel||&apos;
  FROM r LEFT JOIN ngest g ON g.codgest = r.codgest&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RAPSTOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EADB156117ACFA2A8F52F26D4865567F556BE867</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REALGEST IS

  p_plan      number(1);
  AnLunaIni   number(5);
  AnLunafin   number(5);
  FaraMiscari BOOLEAN;
  CuConturi   BOOLEAN;
  DetLunara   BOOLEAN;
  DetCCost    BOOLEAN;
  Subunit     NUMBER;
  NiveleANod  NUMBER(5);
  vAllCC      BOOLEAN;
  vCCInactive BOOLEAN;
  vDoc        NUMBER(1);
  vExtra      BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(25000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(25000);
  gSuplJoins  VARCHAR2(25000);

FUNCTION GetPlan RETURN number is
BEGIN
  RETURN p_Plan;
END;

FUNCTION GetAnLunaIni RETURN number is
BEGIN
  RETURN AnLunaIni;
END;

FUNCTION GetAnLunaFin RETURN number is
BEGIN
  RETURN AnLunafin;
END;

FUNCTION GetFaraMiscari RETURN BOOLEAN is
BEGIN
  RETURN FaraMiscari;
END;

FUNCTION GetCuConturi RETURN BOOLEAN is
BEGIN
  RETURN CuConturi;
END;

FUNCTION GetDetLunara RETURN BOOLEAN is
BEGIN
  RETURN DetLunara;
END;

FUNCTION GetDetCCost RETURN BOOLEAN is
BEGIN
  RETURN DetCCost;
END;

FUNCTION GetSubunit RETURN NUMBER is
BEGIN
  RETURN Subunit;
END;

FUNCTION GetAllCC RETURN BOOLEAN is
BEGIN
  RETURN vAllCC;
END;

function GetCuDoc return number is
begin
  return vDoc;
end;  

FUNCTION GetCCInactive RETURN BOOLEAN is
BEGIN
  RETURN vCCInactive;
END;

FUNCTION GetExtra RETURN BOOLEAN is
BEGIN
  RETURN vExtra;
END;

PROCEDURE SetParams(
  vAnLunaIni   IN NUMBER,
  vAnLunaFin   IN NUMBER,
  vPlan        IN NUMBER,
  vFaraMiscari IN NUMBER DEFAULT 0,
  vCuConturi   IN NUMBER DEFAULT 0,
  vDetLunara   IN NUMBER DEFAULT 0,
  vDetCCost    IN NUMBER DEFAULT 0,
  vPeFirma     IN NUMBER DEFAULT 1,
  pCodJob1     IN NUMBER DEFAULT 0,
  pAllCC       IN NUMBER DEFAULT 0,
  pCCInactive  IN NUMBER DEFAULT 0,
  pDoc         IN NUMBER DEFAULT 0,
  pExtra       IN NUMBER DEFAULT 0)
IS
  vDataS DATE;
  vDataF DATE;
BEGIN
  p_plan      := vPlan;
  AnLunaIni   := vAnLunaIni;
  AnLunaFin   := vAnLunaFin;
  FaraMiscari := vFaraMiscari = 1;
  CuConturi   := vCuConturi = 1;
  DetCCost    := vDetCCost = 1;
  DetLunara   := vDetLunara = 1;
  Subunit     := CASE WHEN NOT (vPeFirma = 1) THEN pkg_globals.GETSUBUNITATE WHEN pCodJob1 = 0 THEN 1 ELSE 0 END;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataS,vDataF,AnLunaIni,AnLunaFin);
  END IF;

  NiveleANod  := pkg_list_base_utils.NIVELE_ANALIZA;
  vAllCC      := pAllCC = 1;
  if not (vDetCCost = 1) then
    vAllCC := True;
  end if;  
  vCCInactive := pCCInactive = 1;
  vDoc        := pDoc;
  vExtra      := pExtra = 1; 
END;

PROCEDURE ver_col_analiza (tmpName IN VARCHAR2, nrmax IN NUMBER) IS
  vExista  NUMBER;
  sColList VARCHAR2(2000);
  sSep     VARCHAR2(2);
BEGIN
  sColList := &apos;&apos;;
  sSep     := &apos;&apos;;
  IF Nvl(nrmax,0) &gt; 0 THEN
    FOR i IN 1..nrmax LOOP
      SELECT Count(1) INTO vExista FROM user_tab_columns WHERE table_name = Upper(tmpName) AND COLUMN_NAME = &apos;NA&apos;||to_char(i);
      IF vExista = 0 THEN
        sColList := sColList||sSep||&apos;NA&apos;||to_char(i)||&apos; VARCHAR2(250)&apos;;
        sSep     := &apos;, &apos;;
      END IF;
    END LOOP;
    IF sColList IS NOT NULL THEN
      EXECUTE IMMEDIATE &apos;ALTER TABLE &apos;||tmpName||&apos; ADD (&apos;||sColList||&apos;)&apos;;
    END IF;
  END IF;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(30000);
  sInsertDC VARCHAR2(10000);
  sSelectDC VARCHAR2(10000);
  sJoinDC   VARCHAR2(10000);
  i         NUMBER(5);
  sConditie VARCHAR2( 1000);
  sIn       VARCHAR2(20);
BEGIN
  gSuplCols := &apos;NGEST NG, NSUBUNIT NSUBUNIT, JURNAL J, NCONT CONTD, NCONT CONTC, CENTRECOST CC, NCLASEG CLSG, NCONTS CS, NCONTT CT, ANALIZANOD ANOD, ANALIZA ANALIZ, DESCRIPTORI1 ADESC1, DESCRIPTORI ADESC&apos;;
  pkg_list_base_realgest.ver_col_analiza(tmpName,nvl(NiveleANod,0));

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sConditie := &apos; AND (contd.clasa = 6 OR contd.clasa = 7 OR contc.clasa = 6 OR contc.clasa = 7) &apos;;
  sIn := &apos;(6,7)&apos;;
  if vExtra then
    sConditie := &apos; AND (contd.clasa = 6 OR contd.clasa = 7 OR contc.clasa = 6 OR contc.clasa = 7 OR contd.clasa = 9 or contc.clasa = 9) &apos;;
    sIn := &apos;(6,7,9)&apos;;
  end if;

  IF vAllCC THEN
    delete tmp_manevra_liste where filtru = &apos;CODCENTRU&apos;;
    INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE)
    SELECT &apos;CODCENTRU&apos;, CODCENTRU
    FROM CENTRECOST
    WHERE NVL(INACTIV,0) = 0;
  END IF;

  IF Nvl(NiveleANod,0) &gt; 0 THEN
    sJoinDC := &apos;
    LEFT JOIN (
      SELECT
        CodAnalizaNod&apos;;
    FOR i IN 1..NiveleANod LOOP
      sInsertDC := sInsertDC||&apos;, NA&apos;||to_char(i)||&apos;,COR&apos;||to_char(i);
      sSelectDC := sSelectDC||&apos;, DC.NA&apos;||to_char(i)||&apos;,DC.COR&apos;||to_char(i);
      sJoinDC := sJoinDC ||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN valoare ELSE NULL end) NA&apos;||to_char(i);
      sJoinDC := sJoinDC ||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN PKG_DESCRIPTORI.GetDenAsociat(TIP,CODASOCIAT) ELSE NULL end) COR&apos;||to_char(i);
    END LOOP;
    sJoinDC := sJoinDC ||&apos;
      FROM TMP_TREE_ANALIZANOD
      GROUP BY CodAnalizaNod
    ) DC ON DC.CodAnalizaNod = j.CodAnalizaNod &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,
    Doc, DataDoc,
    SimbCont,
    ValChelt,
    ValVenit,
    ValReal,
    CheltVal,
    VenitVal,
    RealVal,
    DenGest, DenAct, Obs, SimbCont_psec, NameCont_psec, An, Luna, CentruCost,
    DENCONT, TipAloc, TipChelt,
    ObsDoc,
    IFRS,IFRSV&apos;||sInsertDC||gUserFields||&apos;)
  SELECT
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 WHEN j.tipdoc = 36 THEN (SELECT MF1.CODNIRSTOC FROM MIFIX1 MF1 WHERE MF1.CODMIFIX = J.CODDOC AND MF1.ANSTART*12+MF1.LUNASTART=J.AN*12+J.LUNA) ELSE j.coddoc END,
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 WHEN j.tipdoc = 36 THEN (SELECT MF1.CODNIRSTOC FROM MIFIX1 MF1 WHERE MF1.CODMIFIX = J.CODDOC AND MF1.ANSTART*12+MF1.LUNASTART=J.AN*12+J.LUNA) WHEN j.TipDoc IN (29,30,31,33) THEN j.indexlocal ELSE 0 END,
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 ELSE j.tipdoc END,
    j.Document, j.DataDoc,
    CASE when contd.clasa in &apos;||sIn||&apos; then contd.simbol else contc.simbol END,
    CASE when contd.clasa in &apos;||sIn||&apos; then j.valoare else 0 END,
    CASE when contc.clasa in &apos;||sIn||&apos; then j.valoare else 0 END,
    CASE when contc.clasa in &apos;||sIn||&apos; then j.valoare else 0 END - CASE when contd.clasa in &apos;||sIn||&apos; then j.valoare else 0 END,
    CASE when contd.clasa in &apos;||sIn||&apos; then j.valoareV else 0 END as cheltval,
    CASE when contc.clasa in &apos;||sIn||&apos; then j.valoareV else 0 END as venitval,
    CASE when contc.clasa in &apos;||sIn||&apos; then j.valoareV else 0 END - CASE when contd.clasa in &apos;||sIn||&apos; then j.valoareV else 0 END as cheltval,
    NG.den_gest DenGest, ACT.Den_Activit, J.Obs, cs.simbol, cs.name, J.An, J.Luna, CC.Denumire,
    CASE WHEN contd.clasa IN &apos;||sIn||&apos; THEN contd.den_cont ELSE contc.den_cont END,
    CASE WHEN nvl(CC.CodCentru,0) &lt;&gt; 0 THEN DECODE(NVL(CC.TipAloc,0),0,&apos;&apos;Alocabil in calcul pret&apos;&apos;,1,&apos;&apos;Nealocabil in calcul pret&apos;&apos;,2,&apos;&apos;Fara inregistrari clasa 9&apos;&apos;) END,
    CASE
      WHEN CC.TipChelt =  1 then &apos;&apos;Activitate de baza&apos;&apos;
      WHEN CC.TipChelt =  2 then &apos;&apos;Cheltuieli indirecte - regie fixa&apos;&apos;
      WHEN CC.TipChelt =  3 then &apos;&apos;Cheltuieli indirecte - regie variabila&apos;&apos;
      WHEN CC.TipChelt = 11 then &apos;&apos;Cheltuieli auxiliare&apos;&apos;
      WHEN CC.TipChelt = 12 then &apos;&apos;Cheltuieli generale de administratie&apos;&apos;
      WHEN CC.TipChelt = 13 then &apos;&apos;Cheltuieli de desfacere&apos;&apos;
      WHEN CC.TipChelt = 14 then &apos;&apos;Cheltuieli indirecte comune&apos;&apos;
    END,&apos;||
    CASE
      WHEN FaraMiscari THEN &apos;CASE WHEN j.TipDoc IN (29,30,31,33) then pkg_list_base_utils.getobsdoc(j.indexlocal, j.tipdoc) ELSE pkg_list_base_utils.getobsdoc(j.coddoc, j.tipdoc) END &apos;
      ELSE &apos;NULL &apos;
    END||&apos; ObsDoc,
    CASE WHEN contd.clasa in &apos;||sIn||&apos; THEN 1 ELSE -1 END * NVL(j.valoare_ifrs,0), CASE WHEN contd.clasa in &apos;||sIn||&apos; THEN 1 ELSE -1 END * NVL(j.valoarev_ifrs,0)&apos;||
    sSelectDC||gUserAlias||&apos;
  FROM JURNAL J
    INNER JOIN NCONT CONTC ON j.contc = contc.codcont
    INNER JOIN NCONT CONTD ON j.contd = contd.codcont
    LEFT JOIN NC ON NC.CODNC = J.CODDOC AND J.TIPDOC = 35
    LEFT JOIN NGEST NG ON NVL(j.gest, 0) = ng.codgest
    LEFT JOIN NACTIVIT ACT ON ng.codactivit = act.codactivit
    LEFT JOIN CENTRECOST CC ON j.codcentru = cc.codcentru
    LEFT JOIN NSUBUNIT ON j.subunitatea = nsubunit.codsubunit
    LEFT JOIN NCLASEG CLSG ON NG.codclasa = clsg.codclaseg
    LEFT JOIN NCONTS CS ON cs.codconts = pkg_list_base_utils.get_codconts(CASE when contd.clasa in &apos;||sIn||&apos; then contd.codcont else contc.codcont END, j.an, j.luna)
    LEFT JOIN NCONTT CT ON ct.codcontt = pkg_list_base_utils.get_codcontt(CASE when contd.clasa in &apos;||sIn||&apos; then contd.codcont else contc.codcont END, j.an, j.luna)
    LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = j.codanalizanod
    LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
    LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
    LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor
    LEFT JOIN ANALIZANOD ANODP ON anodp.codanalizanod = anod.nodparinte
    LEFT JOIN ANALIZA ANALIZP ON analizp.codanaliza = anodp.codanaliza
    LEFT JOIN DESCRIPTORI1 ADESC1P ON adesc1p.coddescriptor1 = anodp.coddescriptor1
    LEFT JOIN DESCRIPTORI ADESCP ON adescp.coddescriptor = adesc1p.coddescriptor&apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE J.AN*12 + J.LUNA BETWEEN &apos;||AnLunaIni||&apos; AND &apos;||AnLunaFin||sConditie||&apos;
    AND (J.TipDoc &lt;&gt; 32 OR (J.TipDoc = 32 AND J.CodDoc = 1))&apos;;
  if not PKG_LIST_BASE_REALGEST.GetAllCC then  
    sInsert := sInsert||&apos; and
      EXISTS (SELECT T.VALOARE FROM TMP_MANEVRA_LISTE T WHERE CC.CODCENTRU = T.VALOARE AND T.FILTRU = &apos;&apos;CODCENTRU&apos;&apos;) &apos;;
  end if;    
  sInsert := sInsert||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; PKG_LIST_BASE_REALGEST.GetSubunit);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_REALGEST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A650BB55BC744BAF773E798993B9D7202B5C57A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_realgest2 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS_LUN IS
  vAnLunaIni  NUMBER(5) := pkg_list_base_realgest.GetAnLunaIni;
  vAnLunaFin  NUMBER(5) := pkg_list_base_realgest.GetAnLunaFin;
  vNrLuni     NUMBER(5) := vAnLunaFin - vAnLunaIni + 1 ;
BEGIN
  IF pkg_list_base_realgest.GetDetLunara THEN
    INSERT INTO tmp_dinamic_cols(
      fieldname,
      display,
      indexlocal)
    SELECT
      &apos;D&apos;||level,
      &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;),
      level
    FROM dual
    CONNECT BY LEVEL &lt;= vNrLuni;
  END IF;
  COMMIT;
END;

PROCEDURE BAGA_DINAMIC_COLS IS
  vAnLunaIni  NUMBER(5) := pkg_list_base_realgest.GetAnLunaIni;
  vAnLunaFin  NUMBER(5) := pkg_list_base_realgest.GetAnLunaFin;
  vNrLuni     NUMBER(5) := vAnLunaFin - vAnLunaIni + 1 ;
BEGIN
  delete from tmp_dinamic_cols;
  IF pkg_list_base_realgest.GetDetLunara AND pkg_list_base_realgest.GetDetCCost THEN
    if pkg_list_base_realgest.getallcc then
      if pkg_list_base_realgest.getccinactive then
        INSERT INTO tmp_dinamic_cols(
          fieldname,
          display,
          indexlocal)
        select 
          c.fieldname||&apos;_&apos;||d.fieldname, 
          c.display||&apos;_&apos;||d.display, 
          row_number() over (order by c.fieldname||&apos;_&apos;||d.fieldname)
        from 
          (
           SELECT CODCENTRU, &apos;C&apos;||to_char(CODCENTRU) fieldname, DENUMIRE display 
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0
           UNION ALL
           SELECT 0 CODCENTRU, &apos;C0&apos; fieldname, &apos;nedefinit&apos; display
           FROM DUAL
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname,
             &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;) display
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d;  
      else
        INSERT INTO tmp_dinamic_cols(
          fieldname,
          display,
          indexlocal)
        select 
          c.fieldname||&apos;_&apos;||d.fieldname, 
          c.display||&apos;_&apos;||d.display, 
          row_number() over (order by c.fieldname||&apos;_&apos;||d.fieldname)
        from 
          (
           SELECT CODCENTRU, &apos;C&apos;||to_char(CODCENTRU) fieldname, 
           DENUMIRE display
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0 AND NVL(INACTIV,0) = 0
           UNION ALL
           SELECT 0 CODCENTRU, &apos;C0&apos; fieldname, &apos;nedefinit&apos; display
           FROM DUAL
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname,
             &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;) display
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d;  
      end if;
    ELSE
      if pkg_list_base_realgest.getccinactive then
        INSERT INTO tmp_dinamic_cols(
          fieldname,
          display,
          indexlocal)
        select 
          c.fieldname||&apos;_&apos;||d.fieldname, 
          c.display||&apos;_&apos;||d.display, 
          row_number() over (order by c.fieldname||&apos;_&apos;||d.fieldname)
        from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, 
           DENUMIRE display
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0 AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname,
             &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;) display
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d;  
      ELSE
        INSERT INTO tmp_dinamic_cols(
          fieldname,
          display,
          indexlocal)
        select 
          c.fieldname||&apos;_&apos;||d.fieldname, 
          c.display||&apos;_&apos;||d.display, 
          row_number() over (order by c.fieldname||&apos;_&apos;||d.fieldname)
        from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, 
           DENUMIRE display
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0 AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
                 AND NVL(INACTIV,0) = 0
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname,
             &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;) display
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d;  
      END IF;
      COMMIT;    
    END IF;
  ELSE   
    IF pkg_list_base_realgest.GetDetLunara THEN
      INSERT INTO tmp_dinamic_cols(
        fieldname,
        display,
        indexlocal)
      SELECT
        &apos;D&apos;||level,
        &apos;Val./&apos;||To_Char(Trunc((vAnLunaIni+LEVEL-2)/12),&apos;fm0000&apos;)||&apos;.&apos;||To_Char(Mod(vAnLunaIni+LEVEL-2,12)+1 ,&apos;fm00&apos;),
        level
      FROM dual
      CONNECT BY LEVEL &lt;= vNrLuni;
      COMMIT;
    ELSE
      IF pkg_list_base_realgest.GetDetCCost THEN
        if pkg_list_base_realgest.getallcc then
          if pkg_list_base_realgest.getccinactive then
            INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal)
            SELECT &apos;C&apos;||rownum, Denumire, CodCentru
            FROM (
              SELECT CODCENTRU, DENUMIRE
              FROM CENTRECOST
              WHERE CODCENTRU &gt; 0
              ORDER BY CODCENTRU
            )
            UNION ALL
            SELECT &apos;C0&apos;, &apos;nedefinit&apos; DENUMIRE, 0 codcentru
            FROM DUAL;
          else
            INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal)
            SELECT &apos;C&apos;||rownum, Denumire, CodCentru
            FROM (
              SELECT CODCENTRU, DENUMIRE
              FROM CENTRECOST
              WHERE CODCENTRU &gt; 0 AND NVL(INACTIV,0) = 0
              ORDER BY CODCENTRU
            )
            UNION ALL
            SELECT &apos;C0&apos;, &apos;nedefinit&apos; DENUMIRE, 0 CODCENTRU
            FROM DUAL;
          end if;
        ELSE
          if pkg_list_base_realgest.getccinactive then
            INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal)
            SELECT &apos;C&apos;||rownum, Denumire, CodCentru
            FROM (
              SELECT CODCENTRU, DENUMIRE
              FROM CENTRECOST
              WHERE CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
                AND CODCENTRU &gt; 0
              ORDER BY CODCENTRU
            );
          ELSE
            INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal)
            SELECT &apos;C&apos;||rownum, Denumire, CodCentru
            FROM (
              SELECT CODCENTRU, DENUMIRE
              FROM CENTRECOST
              WHERE CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
                AND CODCENTRU &gt; 0 AND NVL(INACTIV,0) = 0
              ORDER BY CODCENTRU
            );
          END IF;
        END IF;
        COMMIT;    
      END IF;
    END IF;
  END IF;  
END;

FUNCTION sWITH(pCondClasa VARCHAR2, pDinWith VARCHAR2) RETURN VARCHAR2 IS
  sResult VARCHAR2(32000);
BEGIN
  sResult := &apos;
  WITH Sintetice as (
    SELECT c.codsint, c.codcont, c.codconts, s.codsints, c.clasa, c.tipcont, coalesce(c.codcentru,0) codcentru
    FROM (
      SELECT connect_by_root(codcont) CodSint, CodCont, CodContS, Clasa, TipCont, codcentru, connect_by_isleaf farafii
      FROM (
        SELECT c.codcont, c.clasa, c.tipcont, Nvl(c.codparinte,0) codparinte,
          MAX(c1.ContSecundar) KEEP (Dense_Rank LAST  ORDER BY c1.AnStart, c1.LunaStart) CodContS,
          MIN(c1.AnStart)      KEEP (Dense_Rank FIRST ORDER BY c1.AnStart, c1.LunaStart) AnStart,
          MIN(c1.LunaStart)    KEEP (Dense_Rank FIRST ORDER BY c1.AnStart, c1.LunaStart) LunaStart,
          MAX(c1.CodCentru)    KEEP (Dense_Rank LAST  ORDER BY c1.AnStart, c1.LunaStart) CodCentru
        FROM ncont c INNER JOIN ncont1 c1 ON c1.codcont = c.codcont
        WHERE c.clasa &apos;||pCondClasa||&apos;
          AND AnStart*12+LunaStart &lt;= &apos;||to_char(pkg_list_base_realgest.GetAnLunaFin)||&apos;
        GROUP BY c.codcont, c.codcont, c.clasa, c.tipcont, c.codparinte
      )
      START WITH codparinte = 0 AND Coalesce(codcont,0) &lt;&gt; 0
      CONNECT BY PRIOR codcont = codparinte --AND codparinte &lt;&gt; 0
    ) c
    LEFT JOIN (
      SELECT connect_by_root(codconts) CodSintS, CodContS
      FROM nconts
      START WITH Nvl(codparinte,0) = 0 AND Coalesce(codconts,0) &lt;&gt; 0
      CONNECT BY PRIOR codconts = codparinte --AND codparinte &lt;&gt; 0
    ) s ON s.CodContS = c.CodContS
    WHERE c.codsint &lt;&gt; c.codcont OR c.farafii = 1),
  x as (
    SELECT codcont, codsint, codconts, codsints, sum(valoare) valoare, gest, den_subunit, MAX(Misc) Misc&apos;||pDinWith||&apos;
    FROM (&apos;;
  RETURN sResult;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(2000);
  sSel        VARCHAR2(32000);
--  sFromChelt  VARCHAR2(30000);
--  sFromVenit  VARCHAR2(30000);
  sFrom67     VARCHAR2(32000);
  sFromAlte   VARCHAR2(32000);
  aSubunitate NUMBER(20);
  vCondMisc   VARCHAR2(500);
  sSold       VARCHAR2(100);
  sPer        VARCHAR2(100);
  CondLunaIni VARCHAR2(1500);
  sDinIns     VARCHAR2(32000);
  sDinSel     VARCHAR2(32000);
  sDinWith    VARCHAR2(32000);
  vAnStart    NUMBER(4) := Trunc((pkg_list_base_realgest.GetAnLunaIni-1)/12);
  vLunaStart  NUMBER(5) := pkg_list_base_realgest.GetAnLunaIni - vAnStart*12;
  sDoc        VARCHAR2(50);
  sSelDoc     VARCHAR2(500);
  sSelWithDoc VARCHAR2(500);
  sSelNullDoc varchar2(200);
  sGrupDoc    varchar2(200);
  vWith VARCHAR2(32000);
  vAnLunaIni  NUMBER(5) := pkg_list_base_realgest.GetAnLunaIni;
  vAnLunaFin  NUMBER(5) := pkg_list_base_realgest.GetAnLunaFin;
  vNrLuni     NUMBER(5) := vAnLunaFin - vAnLunaIni + 1 ;
BEGIN
  gSuplCols := &apos;ncont cont, ncont sint, nconts conts, nconts sints, ngest g&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_realgest.GetAnLunaIni = pkg_list_base_realgest.GetAnLunaFin
  THEN sPer := &apos;= &apos;||pkg_list_base_realgest.GetAnLunaFin;
  ELSE sPer := &apos;BETWEEN &apos;||pkg_list_base_realgest.GetAnLunaIni||&apos; AND &apos;||pkg_list_base_realgest.GetAnLunaFin;
  END IF;

  sDoc := &apos;&apos;;
  sSelNullDoc := &apos;&apos;;
  sSelDoc := &apos;&apos;;
  sSelWithDoc := &apos;&apos;;
  sGrupDoc := &apos;&apos;;
  if pkg_list_base_realgest.GetCuDoc &gt; 0 then
    sDoc        := &apos;,ObsDoc,Document_RG&apos;;
    sSelWithDoc := &apos;,pkg_list_utilfisacont.GetObsDocJurnal(j.codjurnal) ObsDoc,j.document&apos;;
    sSelDoc     := &apos;,x.ObsDoc,x.Document&apos;;
    sSelNullDoc := &apos;,&apos;&apos; &apos;&apos; ObsDoc,&apos;&apos; &apos;&apos; Document&apos;;
    sGrupDoc    := &apos;,stragg3200(ObsDoc) ObsDoc,stragg3200(document) document&apos;;
  end if;

  vCondMisc := &apos;
  WHERE X.Misc &gt; 0 &apos;;
  IF pkg_list_base_realgest.GetFaraMiscari THEN vCondMisc := &apos;&apos;; END if;

  sSold       := &apos;&apos;;
  CondLunaIni := &apos;&apos;;
  DELETE tmp_ncontsold;
  DELETE tmp_ncontrul;

  IF  pkg_list_base_realgest.GetCuConturi
  AND ( vLunaStart = 1) OR (pkg_list_base_realgest.GetAnLunaIni = pkg_globals.GetAnInitial*12+pkg_globals.GETLUNAINITIALA)
  THEN
    INSERT INTO tmp_ncontsold (codcontsold, codcont, soldid, soldic, soldvid, soldvic, an, luna)
    SELECT codcontsold, codcont, soldid, soldic, soldvid, soldvic, an, luna
    FROM ncontsold
    WHERE an = vAnStart AND luna = 1;

    IF aSubunitate = 1 THEN
      INSERT into tmp_ncontrul (codcontrul, codcont, rulajpd, rulajpc)
      WITH c1 AS (
        SELECT
          codcont,
          CASE WHEN anstart*12+lunastart &lt;= pkg_list_base_realgest.GetAnLunaIni THEN vAnStart   ELSE anstart   END an,
          CASE WHEN anstart*12+lunastart &lt;= pkg_list_base_realgest.GetAnLunaIni THEN vLunaStart ELSE lunastart END luna
        FROM (
          SELECT
            codcont,
            MIN(AnStart)   KEEP (Dense_Rank FIRST ORDER BY AnStart, LunaStart) AnStart,
            MIN(LunaStart) KEEP (Dense_Rank FIRST ORDER BY AnStart, LunaStart) LunaStart
          FROM ncont1
          WHERE AnStart*12+LunaStart &lt;= pkg_list_base_realgest.GetAnLunaFin
          GROUP BY codcont
        )
      )
      SELECT rul.codcontrul, rul.codcont, rul.rulajpd, rul.rulajpc
      FROM c1
        INNER JOIN ncontrul rul ON rul.codcont = c1.codcont AND rul.an = c1.an AND rul.luna = c1.luna;
    ELSE
      INSERT into tmp_ncontrul (codcontrul, codcont, rulajpd, rulajpc)
      WITH c1 AS (
        SELECT
          codcont,
          CASE WHEN anstart*12+lunastart &lt;= pkg_list_base_realgest.GetAnLunaIni THEN vAnStart   ELSE anstart   END an,
          CASE WHEN anstart*12+lunastart &lt;= pkg_list_base_realgest.GetAnLunaIni THEN vLunaStart ELSE lunastart END luna
        FROM (
          SELECT
            codcont,
            MIN(AnStart)   KEEP (Dense_Rank FIRST ORDER BY AnStart, LunaStart) AnStart,
            MIN(LunaStart) KEEP (Dense_Rank FIRST ORDER BY AnStart, LunaStart) LunaStart
          FROM ncont1
          WHERE AnStart*12+LunaStart &lt;= pkg_list_base_realgest.GetAnLunaFin
          GROUP BY codcont
        )
      )
      SELECT rul.codcontrul, rul.codcont, ruls.rulajpd, ruls.rulajpc
      FROM c1
        INNER JOIN ncontrul rul ON rul.codcont = c1.codcont AND rul.an = c1.an AND rul.luna = c1.luna
        INNER JOIN ncontrulsub ruls ON ruls.codcontrul = rul.codcontrul
      WHERE ruls.subunitatea = aSubunitate;
    END IF;

    CondLunaIni := &apos;
      LEFT JOIN tmp_ncontsold sold on sold.codcont = s.codcont
      LEFT JOIN tmp_ncontrul rul on rul.codcont = s.codcont&apos;;
    sSold := &apos; + nvl(sold.SoldID,0) - nvl(sold.SoldIC,0) + nvl(rul.rulajpd,0) - nvl(rul.rulajpc,0)&apos;;
  END IF;

  PKG_GLOBALS.SetSeparator(&apos;,&apos;);
  IF pkg_list_base_realgest.GetDetLunara and pkg_list_base_realgest.getdetccost THEN
    if pkg_list_base_realgest.getallcc then
      if pkg_list_base_realgest.getccinactive then
        FOR vRec IN (
          select
          c.fieldname||&apos;_&apos;||d.fieldname field, c.codcentru, d.anluna
          from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, codcentru
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0
           UNION ALL
           SELECT &apos;C0&apos; fieldname, 0 CODCENTRU 
           FROM DUAL
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname, pkg_list_base_realgest.GetAnLunaIni+LEVEL-1 anluna 
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d
        )
        LOOP
          sDinIns  := sDinIns ||&apos;,&apos;||vRec.field;
          sDinSel  := sDinSel ||&apos;,x.&apos;||vRec.field;
          sDinWith := sDinWith||&apos;,SUM(CASE WHEN COALESCE(codcentru,0)=&apos;||vRec.CODCENTRU||&apos; AND ANLUNA = &apos;||vRec.ANLUNA||&apos; THEN NVL(valoare,0) ELSE 0 END) &apos;||vRec.field;
        END LOOP;
      else
        FOR vRec IN (
          select
          c.fieldname||&apos;_&apos;||d.fieldname field, c.codcentru, d.anluna
          from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, codcentru
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0 AND NVL(INACTIV,0) = 0
           UNION ALL
           SELECT &apos;C0&apos; fieldname, 0 CODCENTRU 
           FROM DUAL
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname, pkg_list_base_realgest.GetAnLunaIni+LEVEL-1 anluna 
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d
        )
        LOOP
          sDinIns  := sDinIns ||&apos;,&apos;||vRec.field;
          sDinSel  := sDinSel ||&apos;,x.&apos;||vRec.field;
          sDinWith := sDinWith||&apos;,SUM(CASE WHEN COALESCE(codcentru,0)=&apos;||vRec.CODCENTRU||&apos; AND ANLUNA = &apos;||vRec.ANLUNA||&apos; THEN NVL(valoare,0) ELSE 0 END) &apos;||vRec.field;
        END LOOP;
      end if;
    ELSE
      if pkg_list_base_realgest.getccinactive then
        FOR vRec IN (
          select
          c.fieldname||&apos;_&apos;||d.fieldname field, c.codcentru, d.anluna
          from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, codcentru
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0
                 AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname, pkg_list_base_realgest.GetAnLunaIni+LEVEL-1 anluna 
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d
        )
        LOOP
          sDinIns  := sDinIns ||&apos;,&apos;||vRec.field;
          sDinSel  := sDinSel ||&apos;,x.&apos;||vRec.field;
          sDinWith := sDinWith||&apos;,SUM(CASE WHEN codcentru=&apos;||vRec.CODCENTRU||&apos; AND ANLUNA = &apos;||vRec.ANLUNA||&apos; THEN NVL(valoare,0) ELSE 0 END) &apos;||vRec.field;
        END LOOP;
      ELSE
        FOR vRec IN (
          select
          c.fieldname||&apos;_&apos;||d.fieldname field, c.codcentru, d.anluna
          from 
          (
           SELECT &apos;C&apos;||to_char(CODCENTRU) fieldname, codcentru
           FROM CENTRECOST
           WHERE CODCENTRU &gt; 0
            AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
            AND NVL(INACTIV,0) = 0
           ORDER BY CODCENTRU
          ) c,
          (
           SELECT
             &apos;D&apos;||level fieldname, pkg_list_base_realgest.GetAnLunaIni+LEVEL-1 anluna 
           FROM dual
           CONNECT BY LEVEL &lt;= vNrLuni
          ) d
        )
        LOOP
          sDinIns  := sDinIns ||&apos;,&apos;||vRec.field;
          sDinSel  := sDinSel ||&apos;,x.&apos;||vRec.field;
          sDinWith := sDinWith||&apos;,SUM(CASE WHEN codcentru=&apos;||vRec.CODCENTRU||&apos; AND ANLUNA = &apos;||vRec.ANLUNA||&apos; THEN NVL(valoare,0) ELSE 0 END) &apos;||vRec.field;
        END LOOP;
      END IF;
    END IF;
  ELSE
    IF pkg_list_base_realgest.getdetccost THEN
      if pkg_list_base_realgest.getallcc then
        if pkg_list_base_realgest.getccinactive then
          FOR vRec IN (
            SELECT To_Char(ROWNUM,&apos;fm999&apos;) NR, CODCENTRU
            FROM CENTRECOST
            WHERE CODCENTRU &gt; 0
            UNION ALL
            SELECT &apos;0&apos; NR, 0 CODCENTRU 
            FROM DUAL
            ORDER BY CODCENTRU
          )
          LOOP
            sDinIns  := sDinIns ||&apos;,C&apos;  ||vRec.Nr;
            sDinSel  := sDinSel ||&apos;,x.C&apos;||vRec.Nr;
            sDinWith := sDinWith||&apos;,SUM(DECODE(COALESCE(codcentru,0),&apos;||vRec.CODCENTRU||&apos;,NVL(valoare,0),0)) C&apos;||vRec.Nr;
          END LOOP;  
        else
          FOR vRec IN (
            SELECT To_Char(ROWNUM,&apos;fm999&apos;) NR, CODCENTRU
            FROM CENTRECOST
            WHERE CODCENTRU &gt; 0 AND NVL(INACTIV,0) = 0
            UNION ALL
           SELECT &apos;0&apos; NR, 0 CODCENTRU 
           FROM DUAL
            ORDER BY CODCENTRU
          )
          LOOP
            sDinIns  := sDinIns ||&apos;,C&apos;  ||vRec.Nr;
            sDinSel  := sDinSel ||&apos;,x.C&apos;||vRec.Nr;
            sDinWith := sDinWith||&apos;,SUM(DECODE(COALESCE(codcentru,0),&apos;||vRec.CODCENTRU||&apos;,NVL(valoare,0),0)) C&apos;||vRec.Nr;
          END LOOP;
        end if;
      ELSE
        if pkg_list_base_realgest.getccinactive then
          FOR vRec IN (
            SELECT To_Char(ROWNUM,&apos;fm999&apos;) NR, CODCENTRU
            FROM CENTRECOST
            WHERE CODCENTRU &gt; 0
              AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
            ORDER BY CODCENTRU
          )
          LOOP
            sDinIns  := sDinIns ||&apos;,C&apos;  ||vRec.Nr;
            sDinSel  := sDinSel ||&apos;,x.C&apos;||vRec.Nr;
            sDinWith := sDinWith||&apos;,SUM(DECODE(codcentru,&apos;||vRec.CODCENTRU||&apos;,NVL(valoare,0),0)) C&apos;||vRec.Nr;
          END LOOP;
        ELSE
          FOR vRec IN (
            SELECT To_Char(ROWNUM,&apos;fm999&apos;) NR, CODCENTRU
            FROM CENTRECOST
            WHERE CODCENTRU &gt; 0
              AND CODCENTRU IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE Upper(FILTRU) = &apos;CODCENTRU&apos;)
              AND NVL(INACTIV,0) = 0
            ORDER BY CODCENTRU
          )
          LOOP
            sDinIns  := sDinIns ||&apos;,C&apos;  ||vRec.Nr;
            sDinSel  := sDinSel ||&apos;,x.C&apos;||vRec.Nr;
            sDinWith := sDinWith||&apos;,SUM(DECODE(codcentru,&apos;||vRec.CODCENTRU||&apos;,NVL(valoare,0),0)) C&apos;||vRec.Nr;
          END LOOP;
        END IF;
      END IF;
    ELSE
      IF pkg_list_base_realgest.GetDetLunara THEN
        SELECT
          STRING_AGG(&apos;D&apos;||LEVEL),
          STRING_AGG(&apos;x.D&apos;||LEVEL),
          STRING_AGG(&apos;SUM(DECODE(anluna,&apos;||To_Char(pkg_list_base_realgest.GetAnLunaIni+LEVEL-1)||&apos;,NVL(valoare,0),0)) D&apos;||LEVEL)
        INTO
          sDinIns,
          sDinSel,
          sDinWith
        FROM dual CONNECT BY LEVEL &lt;= pkg_list_base_realgest.GetAnLunaFin - pkg_list_base_realgest.GetAnLunaIni + 1;
        sDinIns  := &apos;,&apos;||sDinIns ;
        sDinSel  := &apos;,&apos;||sDinSel ;
        sDinWith := &apos;,&apos;||sDinWith;
      END IF;  
    END IF;
  END IF;

  sDinWith := sDinWith||sGrupDoc;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    SimbCont, SimbSint, DenCont, DenSint, Valoare, Gest, Den_subunit, Tip &apos;||sDoc||sDinIns||gUserFields||&apos;)&apos;;


--  sFromChelt := &apos;
--      SELECT
--        s.codcont, s.codsint, s.codconts, s.codsints, nvl(j.valoare, 0)*DECODE(s.tipcont,1,-1,1) valoare, j.gest,
--        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc
--      FROM Sintetice s LEFT JOIN jurnal j ON s.codcont = DECODE(s.tipcont,1,j.contc,j.contd) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; PKG_LIST_BASE_REALGEST.getSubunit)||&apos; AND J.AN*12+J.LUNA &apos;||sPer;

--  sFromVenit := &apos;
--      SELECT
--        s.codcont, s.codsint, s.codconts, s.codsints, nvl(j.valoare, 0)*DECODE(s.tipcont,0,1,-1) valoare, j.gest,
--        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc
--      FROM Sintetice s LEFT JOIN jurnal j ON s.codcont = DECODE(s.tipcont,0,j.contd,j.contc) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; PKG_LIST_BASE_REALGEST.getSubunit)||&apos; AND J.AN*12+J.LUNA &apos;||sPer;

  sFrom67 := &apos;
      SELECT
        s.codcont, s.codsint, s.codconts, s.codsints, nvl(j.valoare, 0) valoare, j.gest,
        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc, SUB.DEN_SUBUNIT&apos;||sSelWithDoc||&apos;
      FROM Sintetice s 
           LEFT JOIN jurnal j ON s.tipcont IN (0,2) AND s.codcont = j.contd AND j.tipdoc &lt;&gt; 32 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; PKG_LIST_BASE_REALGEST.getSubunit)||&apos; AND J.AN*12+J.LUNA &apos;||sPer||&apos;
           LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = J.SUBUNITATEA
      UNION ALL
      SELECT
        s.codcont, s.codsint, s.codconts, s.codsints, nvl(-j.valoare, 0) valoare, j.gest,
        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc, SUB.DEN_SUBUNIT&apos;||sSelWithDoc||&apos;
      FROM Sintetice s 
           LEFT JOIN jurnal j ON s.tipcont IN (1,2) AND s.codcont = j.contc AND j.tipdoc &lt;&gt; 32 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; PKG_LIST_BASE_REALGEST.getSubunit)||&apos; AND J.AN*12+J.LUNA &apos;||sPer||&apos;
           LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = J.SUBUNITATEA&apos;;

  sFromAlte := &apos;
      SELECT
        s.codcont, s.codsint, s.codconts, s.codsints, NVL(j.valoare,0)*DECODE(s.tipcont,1,-1,1) valoare, 0 gest,
        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc, SUB.DEN_SUBUNIT&apos;||sSelWithDoc||&apos;
      FROM sintetice s 
           LEFT JOIN JURNAL J ON J.Contd = S.CodCont
           LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = J.SUBUNITATEA
      UNION ALL
      SELECT
        s.codcont, s.codsint, s.codconts, s.codsints, Nvl(j.valoare,0)*DECODE(s.tipcont,1,1,-1) valoare, 0 gest,
        CASE WHEN NVL(j.codcentru,0) = 0 THEN Nvl(s.codcentru,0) ELSE j.codcentru END codcentru, j.an*12+j.luna anluna, DECODE(j.valoare,NULL,0,0,0,1) Misc, SUB.DEN_SUBUNIT&apos;||sSelWithDoc||&apos;
      FROM sintetice s 
           LEFT JOIN JURNAL J ON J.Contc = S.CodCont
           LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = J.SUBUNITATEA
      UNION ALL
      SELECT
        s.codcont, s.codsint, s.codconts, s.codsints, (nvl(sold.SoldID,0) - nvl(sold.SoldIC,0) + nvl(rul.rulajpd,0) - nvl(rul.rulajpc,0))*DECODE(s.tipcont,1,-1,1) valoare, 0 gest,
        Nvl(s.codcentru,0) codcentru, &apos;||pkg_list_base_realgest.GetAnLunaIni||&apos; anluna, 0 Misc, &apos;&apos;...nedefinit...&apos;&apos; den_subunit&apos;||sSelNullDoc||&apos;
      FROM sintetice s
        LEFT JOIN tmp_ncontsold sold on sold.codcont = s.codcont
        LEFT JOIN tmp_ncontrul rul on rul.codcont = s.codcont&apos;;

  sSel := &apos;
    )
    GROUP BY codcont, codsint, codconts, codsints, gest, den_subunit )
  SELECT cont.simbol, sint.simbol, cont.den_cont, sint.den_cont, x.valoare, g.den_gest, x.den_subunit, DECODE(cont.tipcont,0,&apos;&apos;Activ&apos;&apos;,1,&apos;&apos;Pasiv&apos;&apos;,2,&apos;&apos;Bifunctional&apos;&apos;) &apos;||sSelDoc||sDinSel||gUserAlias||&apos;
  FROM x
    LEFT JOIN ncont  cont  ON cont.codcont   = x.codcont
    LEFT JOIN ncont  sint  ON sint.codcont   = x.codsint
    LEFT JOIN nconts conts ON conts.codconts = x.codconts
    LEFT JOIN nconts sints ON sints.codconts = x.codsints
    LEFT JOIN ngest  g     ON g.codgest      = x.gest&apos;||
    gSuplJoins;

  vWith := sWith(&apos;= 6&apos;,sDinWith);
--  LIST_EXECUTE_IMMEDIATE(sInsert||sWith(&apos;= 6&apos;,sDinWith)||sFromChelt||sSel||vCondMisc, aListID, aListVer);
--  LIST_EXECUTE_IMMEDIATE(sInsert||sWith(&apos;= 7&apos;,sDinWith)||sFromVenit||sSel||vCondMisc, aListID, aListVer);
  --insert into x(test) values (sInsert);
  --insert into x(test) values (vWith);
  --insert into x(test) values (sFrom67);
  --insert into x(test) values (sSel);
  --commit;
  LIST_EXECUTE_IMMEDIATE(sInsert||vWith||sFrom67||sSel||vCondMisc, aListID, aListVer);
  vWith := sWith(&apos;= 7&apos;,sDinWith);
  LIST_EXECUTE_IMMEDIATE(sInsert||vWith||sFrom67||sSel||vCondMisc, aListID, aListVer);
  if pkg_list_base_realgest.GetExtra then
    vWith := sWith(&apos;= 8&apos;,sDinWith);
    LIST_EXECUTE_IMMEDIATE(sInsert||vWith||sFrom67||sSel||vCondMisc, aListID, aListVer);
    vWith := sWith(&apos;= 9&apos;,sDinWith);
    LIST_EXECUTE_IMMEDIATE(sInsert||vWith||sFrom67||sSel||vCondMisc, aListID, aListVer);
  end if;  
  IF pkg_list_base_realgest.GetCuConturi THEN
    vWith := sWith(&apos;NOT in (6,7,8,9)&apos;,sDinWith);
    LIST_EXECUTE_IMMEDIATE(sInsert||vWith||sFromAlte ||sSel||vCondMisc, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_realgest2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REALGEST3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1DA0089BC3957AC1F207C1343EEE5849BDEEF12</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REALGEST3 IS

  gUserFields CLOB;
  gUserAlias  CLOB;
  gNullAlias  CLOB;
  gSuplCols   CLOB;
  gSuplJoins  CLOB;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sInsertDC CLOB;
  sSelectDC CLOB := &apos;&apos;;
  sJoinDC   CLOB := &apos;&apos;;
  i         NUMBER(5);
  p_Plan    NUMBER(1);
  p_LunaIni NUMBER(5);
  p_LunaFin NUMBER(5);
  p_Subunit NUMBER(20);
BEGIN
  gSuplCols := &apos;NGEST NG, NSUBUNIT NSUBUNIT, NCONT CONTD, NCONT CONTC, CENTRECOST CC, NCLASEG CLSG, NCONTS CS, ANALIZANOD ANOD, ANALIZA ANALIZ, DESCRIPTORI1 ADESC1, DESCRIPTORI ADESC,&apos;||
               &apos;NARTOBJ OBJ, NART ART, NARTCLI ARTCLI, NCLASEA CLSA, NCLASEAS CLSAS, PRETM PRET, NMONEDE MONLINK, NMONEDE MONDOC, NARTOBJTRAD TRAD, NPART P, NUM NUM,&apos;||
               &apos;NAGENDA SED,NPARTCODFISC CIF,NCLASEP CLSP, tmp_lst_jurnal1 J&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,         &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;IES1&apos;,       &apos;J.CODDOC1 = IES1.CODIES1 AND J.TIPDOC IN (14,15,19,20,21,22,23,24,26)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1EXT&apos;, &apos;IES1EXT&apos;,    &apos;IES1EXT.CODIES1 = IES1.CODIES1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,  &apos;IESEXT&apos;,     &apos;IESEXT.CODIES = IES1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC1&apos;,        &apos;NC1&apos;,        &apos;J.CODDOC1 = NC1.CODNC1 AND J.TIPDOC = 35&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC1EXT&apos;,     &apos;NC1EXT&apos;,     &apos;NC1EXT.CODNC1 = NC1.CODNC1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCEXT&apos;,      &apos;NCEXT&apos;,      &apos;NCEXT.CODNC = NC1.CODNC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;,    &apos;TREZOR1&apos;,    &apos;J.CODDOC1 = TREZOR1.CODTREZOR1 AND J.TIPDOC IN (29,30,31,33)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1EXT&apos;, &apos;TREZOR1EXT&apos;, &apos;TREZOR1EXT.CODTREZOR1 = TREZOR1.CODTREZOR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOREXT&apos;,  &apos;TREZOREXT&apos;,  &apos;TREZOREXT.CODTREZOR = TREZOR1.CODTREZOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;INTR1&apos;,      &apos;J.CODDOC1 = INTR1.CODINTR1 AND J.TIPDOC IN (1,2,3,4,5,6,7,9)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1F&apos;,  &apos;INTR1EXT&apos;,   &apos;INTR1EXT.CODINTR1 = INTR1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,   &apos;INTREXT&apos;,    &apos;INTREXT.CODINTR = INTR1.CODINTR&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  --pkg_list_base_utils.UMPLE_TMP_NPERS1_LST;
  PRC_AL_CHECK(&apos;NPERS1&apos;);

  p_Plan    := pkg_list_base_realgest.GetPlan;
  p_LunaIni := pkg_list_base_realgest.GetAnLunaIni;
  p_LunaFin := pkg_list_base_realgest.GetAnLunaFin;
  p_Subunit := pkg_list_base_realgest.GetSubunit;
  pkg_list_utilfisacont.UMPLE_TMP_LST_JURNAL1(p_Plan, p_LunaIni, p_LunaFin, p_Subunit, aLISTID);

  pkg_list_base_realgest.ver_col_analiza(tmpName,Nvl(pkg_list_base_utils.NIVELE_ANALIZA,0));
  IF nvl(pkg_list_base_utils.NIVELE_ANALIZA,0) &gt; 0 THEN
    sJoinDC := &apos;
    LEFT JOIN (
      SELECT
        CodAnalizaNod&apos;;
    FOR i IN 1..pkg_list_base_utils.NIVELE_ANALIZA LOOP
      sInsertDC := sInsertDC||&apos;, NA&apos;||to_char(i);
      sSelectDC := sSelectDC||&apos;, DC.NA&apos;||to_char(i);
      sJoinDC := sJoinDC ||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN valoare ELSE NULL end) NA&apos;||to_char(i);
    END LOOP;
    sJoinDC := sJoinDC ||&apos;
      FROM TMP_TREE_ANALIZANOD
      GROUP BY CodAnalizaNod
    ) DC ON DC.CodAnalizaNod = j.CodAnalizaNod &apos;;
  END IF;

  sInsert :=
 &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,
    Doc, DataDoc,
    SimbCont,
    ValChelt,
    ValVenit,
    ValReal,
    CheltVal,
    VenitVal,
    RealVal,
    DenGest, DenAct, Obs, SimbCont_psec, NameCont_psec, An, Luna, CentruCost,
    DENCONT, TipAloc, TipChelt,
    ObsDoc,
    Partener, DATACREARE, ARTICOL, DocLegatura, Cant, Pret, CONT, CORESP,
    EXPLICATII, Subunitatea, TIPDOC, ObsLinie,
    IFRS, IFRSV, C_IFRS, V_IFRS, C_IFRSV, V_IFRSV, Doc_TVA, Doc_Val, Doc_Curs &apos;||sInsertDC||gUserFields||&apos;)
  SELECT
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 ELSE j.coddoc END,
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 WHEN j.TipDoc IN (29,30,31,33) THEN j.indexlocal ELSE 0 END,
    CASE WHEN j.tipdoc = 35 AND PKG_GLOBALS.GET_DREPT_SALARIZARE = 0 AND NC.JurnalTVA = 5 THEN 0 ELSE j.tipdoc END,
    j.Document, j.DataDoc,
    CASE when contd.clasa in (6, 7) then contd.simbol else contc.simbol END,
    CASE when contd.clasa in (6, 7) then j.valoare else 0 END,
    CASE when contc.clasa in (6, 7) then j.valoare else 0 END,
    CASE when contc.clasa in (6, 7) then j.valoare else 0 END - CASE when contd.clasa in (6, 7) then j.valoare else 0 END,
    CASE when contd.clasa in (6, 7) then j.valoareV else 0 END as cheltval,
    CASE when contc.clasa in (6, 7) then j.valoareV else 0 END as venitval,
    CASE when contc.clasa in (6, 7) then j.valoareV else 0 END - CASE when contd.clasa in (6, 7) then j.valoareV else 0 END as cheltval,
    NG.den_gest DenGest, ACT.Den_Activit, J.Obs, cs.simbol, cs.name, J.An, J.Luna, CC.Denumire,
    CASE WHEN contd.clasa IN (6, 7) THEN contd.den_cont ELSE contc.den_cont END,
    CASE WHEN nvl(CC.CodCentru,0) &lt;&gt; 0 THEN DECODE(NVL(CC.TipAloc,0),0,&apos;&apos;Alocabil in calcul pret&apos;&apos;,1,&apos;&apos;Nealocabil in calcul pret&apos;&apos;,2,&apos;&apos;Fara inregistrari clasa 9&apos;&apos;) END,
    CASE
      WHEN CC.TipChelt =  1 then &apos;&apos;Activitate de baza&apos;&apos;
      WHEN CC.TipChelt =  2 then &apos;&apos;Cheltuieli indirecte - regie fixa&apos;&apos;
      WHEN CC.TipChelt =  3 then &apos;&apos;Cheltuieli indirecte - regie variabila&apos;&apos;
      WHEN CC.TipChelt = 11 then &apos;&apos;Cheltuieli auxiliare&apos;&apos;
      WHEN CC.TipChelt = 12 then &apos;&apos;Cheltuieli generale de administratie&apos;&apos;
      WHEN CC.TipChelt = 13 then &apos;&apos;Cheltuieli de desfacere&apos;&apos;
      WHEN CC.TipChelt = 14 then &apos;&apos;Cheltuieli indirecte comune&apos;&apos;
    END,&apos;||
    CASE
      WHEN pkg_list_base_realgest.GetFaraMiscari THEN &apos;CASE WHEN j.TipDoc IN (29,30,31,33) then pkg_list_base_utils.getobsdoc(j.indexlocal, j.tipdoc) ELSE pkg_list_base_utils.getobsdoc(j.coddoc, j.tipdoc) END&apos;
      ELSE &apos;NULL&apos;
    END||&apos; ObsDoc,
    P.Den_Part, j.DATACREARE, j.ARTICOL, j.DocLegatura, j.Cant, j.Pret, contd.simbol, contc.simbol,
    j.obs, nsubunit.den_subunit, PKG_LIST_BASE_UTILS.DECODE_TIPDOC(j.TIPDOC), j.ObsLinie,
    CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * j.valoare_ifrs, CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * j.valoarev_ifrs,
    CASE when contd.clasa in (6, 7) then CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * nvl(j.valoare_ifrs,0) else 0 END,
    CASE when contc.clasa in (6, 7) then CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * nvl(j.valoare_ifrs,0) else 0 END,
    CASE when contd.clasa in (6, 7) then CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * nvl(j.valoarev_ifrs,0) else 0 END,
    CASE when contc.clasa in (6, 7) then CASE WHEN contd.clasa in (6, 7) THEN 1 ELSE -1 END * nvl(j.valoarev_ifrs,0) else 0 END,
    j.TVADoc, j.ValDoc, decode(nvl(j.Curs,0),0,1,nvl(j.curs,0)) &apos;||sSelectDC||gUserAlias||&apos;
  FROM tmp_lst_jurnal1 J
    INNER JOIN NCONT CONTC ON j.codcontc = contc.codcont
    INNER JOIN NCONT CONTD ON j.codcontd = contd.codcont
    LEFT JOIN NPART P ON P.CODPART = J.CODPART
    LEFT JOIN NARTOBJ OBJ ON J.CODOBIECT = OBJ.CODOBIECT
    LEFT JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
    LEFT JOIN NUM NUM ON ART.UM = NUM.CODUM
    LEFT JOIN NARTCLI ARTCLI ON ARTCLI.CODOBIECT = OBJ.CODOBIECT AND ARTCLI.CODPART = J.CODPART
    LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = ART.CLASA
    LEFT JOIN NCLASEAS CLSAS ON CLSAS.CODCLASEAS = ART.CLASASTATIST
    LEFT JOIN PRETM PRET ON PRET.CODOBIECT = OBJ.CODOBIECT AND PRET.SUBUNITATEA = J.SUBUNITATEA AND PRET.IMPLICIT = 1
    LEFT JOIN NMONEDE MONLINK ON nvl(J.CODMONEDA,0) = MONLINK.CODMONEDA
    LEFT JOIN NMONEDE MONDOC ON nvl(J.CODMONEDADOC,0) = MONDOC.CODMONEDA
    LEFT JOIN NARTOBJTRAD TRAD ON TRAD.CODOBIECT = OBJ.CODOBIECT AND TRAD.CODLIMBA = nvl(PKG_CATEGCONST.GetValConstanta(&apos;&apos;LimbaDenArt&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0)
    LEFT JOIN NC ON NC.CODNC = J.CODDOC AND J.TIPDOC = 35
    LEFT JOIN NGEST NG ON NVL(j.gest, 0) = ng.codgest
    LEFT JOIN NACTIVIT ACT ON ng.codactivit = act.codactivit
    LEFT JOIN CENTRECOST CC ON j.codcentru = cc.codcentru
    LEFT JOIN NSUBUNIT ON j.subunitatea = nsubunit.codsubunit
    LEFT JOIN NCLASEG CLSG ON NG.codclasa = clsg.codclaseg
    LEFT JOIN NCONTS CS ON cs.codconts = pkg_list_base_utils.get_codconts(CASE when contd.clasa in (6, 7) then contd.codcont else contc.codcont END, j.an, j.luna)
    LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = j.codanalizanod
    LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
    LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
    LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor
    LEFT JOIN NAGENDA SED ON SED.CODAGENDA = J.CODAGENDA
    LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = J.COD_CODFISCAL
    LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA&apos;||
    sJoinDC||
    gSuplJoins||&apos;
  WHERE J.AN*12 + J.LUNA BETWEEN &apos;||p_LunaIni||&apos; AND &apos;||p_LunaFin||&apos;
    AND (J.TipDoc &lt;&gt; 32 OR (J.TipDoc = 32 AND J.CodDoc = 1)) &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; p_Subunit);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_realgest3;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RECEPTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D29EC4056DE74CCEDA8FCCA7612EDA6904A52FDB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RECEPTII IS

  g_toateGest BOOLEAN;
  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(25000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  sSelect     VARCHAR2(20000);
  sFrom       VARCHAR2(20000);
  sFiltruN    VARCHAR2( 1000);
  sFiltruL    VARCHAR2( 1000);
  sFiltruT    VARCHAR2( 1000);
  sFiltruI    VARCHAR2( 1000);
  sInsTmp     VARCHAR2( 5000);
  sSelTmpT    VARCHAR2( 5000);
  sSelTmpI    VARCHAR2( 5000);
  sSelTmpL    VARCHAR2(10000);
  --sWithAUX    VARCHAR2( 5000);
  g_data1     VARCHAR2(   15):= To_Char(PKG_LIST_SELECTGEST.DataIni,&apos;dd.mm.yyyy&apos;);
  g_data2     VARCHAR2(   15):= To_Char(PKG_LIST_SELECTGEST.DataFin,&apos;dd.mm.yyyy&apos;);
  vDupaData   BOOLEAN        := PKG_LIST_SELECTGEST.DupaData;
  vLunaAnIni  INTEGER        := PKG_LIST_SELECTGEST.LunaAnIni;
  vLunaAnFin  INTEGER        := PKG_LIST_SELECTGEST.LunaAnFin;
  vDataDoc    BOOLEAN        := Pkg_List_Selectgest.DataDoc;
  vJoinSeriiN VARCHAR2( 3000);
  vJoinSeriiL VARCHAR2( 3000);
  vColSeriiN  VARCHAR2( 3000);
  vColSeriiL  VARCHAR2( 3000);
  sInsertDC   VARCHAR2( 2000);
  sSelectDC   VARCHAR2( 2000);
  sSelectDCN  VARCHAR2( 2000);
  sSelectDCL  VARCHAR2( 2000);
  sJoinDC     VARCHAR2( 2000);
  sCodNirSerL VARCHAR2( 1000);
  sFiltruDoc  VARCHAR2(50);
  sFiltruDocM VARCHAR2(50);
  sOperat     VARCHAR2(50);
BEGIN
  gSuplCols :=
    &apos;TMP_LST_RECEPTII R, NLOCATII NLOC, NARTOBJ OBJ, NPART NP, NPART FURN, NCONT NCSTOC, NSUBUNIT NSUB, NGEST GESTPROD, IOART IO, NPART PROD, COMANDA CF, NCLASEAS NCLS, &apos;||
    &apos;NCLASEA NCA, INTRARI I, INTRARI1 I1&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NGEST&apos;,          &apos;NG&apos;,       &apos;NG.CODGEST = R.GEST&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,       &apos;PD&apos;,       &apos;PD.CODPART = NP.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;,     &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,       &apos;INTRF&apos;,    &apos;INTRF.CODINTR = I.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF1&apos;,      &apos;INTRF1&apos;,   &apos;INTRF1.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SDOC&apos;,     &apos;SDOC.CODAGENDA = I.CODLOCATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCDOC&apos;,   &apos;LOCDOC.CODLOCALIT = SDOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARADOC&apos;,  &apos;LOCDOC.CODTARA = TARADOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,        &apos;SSOC&apos;,     &apos;SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,       &apos;LOCSOC&apos;,   &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;,          &apos;TARASOC&apos;,  &apos;LOCSOC.CODTARA = TARASOC.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,          &apos;TRANSP&apos;,   &apos;TRANSP.CODPART = I.TRANSPORTATOR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRASTEPTLINK&apos;, &apos;WLINK&apos;,    &apos;WLINK.CODINTR1 = I1.CODINTR1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,       &apos;IW1&apos;,      &apos;IW1.CODINTR1 = WLINK.CODLINIEFACTURA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,        &apos;FASTEPT&apos;,  &apos;FASTEPT.CODINTR = IW1.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NART&apos;,           &apos;N&apos;,        &apos;N.CODARTICOL = R.CODARTICOL&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTVA&apos;,           &apos;T&apos;,        &apos;T.CODTVA = R.CODTVA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NIRSTOC&apos;,        &apos;NS&apos;,       &apos;NS.CODNIRSTOC = R.CODNIRSTOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,          &apos;OPERATOR&apos;, &apos;OPERATOR.LOGONNAME = R.USERID&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,        &apos;AA&apos;,       &apos;AA.CODOBIECT = R.CODOBIECT AND AA.UMSEC = R.CODUMNIR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;FORMATII&apos;,       &apos;FORM&apos;,     &apos;I.CODFORMATIE = FORM.CODFORMATIE AND I.TIPDOC = 7&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;xxxcantxxx&apos;,&apos;r.codobiect&apos;,sInsertDC,sSelectDC,sJoinDC);
  --pkg_list_base_utils.umple_tmp_nart1_lst;
  --pkg_list_base_utils.umple_tmp_ntaxe1_lst;
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTAXE1&apos;);

  IF pkg_list_selectgest.AduSerii = 1
  THEN sSelectDCN := REPLACE(sSelectDC, &apos;xxxcantxxx&apos;, &apos;NVL(nser.cantnir,r.cantfurn)&apos;);
  ELSE sSelectDCN := REPLACE(sSelectDC, &apos;xxxcantxxx&apos;, &apos;r.cantfurn&apos;);
  END IF;

  sSelectDCL := REPLACE(sSelectDC, &apos;xxxcantxxx&apos;, &apos;r.cantnir&apos;);

  g_toateGest := PKG_LIST_SELECTGEST.ToateGest;

  vColSeriiN    :=  &apos;,
    R.CANTFURN/UMDOC.PARITATE CANT,
    R.CANTNIR/UMNIR.PARITATE CANTNIR,
    CASE WHEN R.TIPNIR IN (12,13) THEN 0 WHEN NVL(I1.RESTFACT,0) = I1.CANT THEN 0 WHEN I1.CANT = 0 THEN 0 ELSE R.CANTFURN*(I1.CANT-NVL(I1.RESTFACT,0))/I1.CANT/UMDOC.PARITATE END CANTFACT,
    R.TG, NULL SERIE, NULL CANTSER,NULL OBSSER, NULL NRCERTIFSER, NULL DATAPRIMIRE, NULL DATAPROD, NULL PROVENIENTA, NULL DEN_TARA, NULL OBSCERTIF &apos;;

  vColSeriiL    :=  &apos;,
    R.CANTFURN/UMDOC.PARITATE CANT,
    R.CANTNIR/UMNIR.PARITATE CANTNIR,
    0 CANTFACT,
    R.TG, NULL SERIE, NULL CANTSER,NULL OBSSER, NULL NRCERTIFSER, NULL DATAPRIMIRE, NULL DATAPROD, NULL PROVENIENTA, NULL DEN_TARA, NULL OBSCERTIF &apos;;

  IF pkg_list_selectgest.AduSerii = 1 THEN
    vJoinSeriiN  := &apos;
    LEFT JOIN NIRSER NSER ON NSER.CODNIRSTOC = R.CODNIRSTOC
    LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
    LEFT JOIN CERTIF C ON C.CODCERTIF = NSER.CODCERTIF
    LEFT JOIN NTARI CT ON CT.CODTARA = C.CODTARA &apos;;

    vColSeriiN   :=  &apos;,
    CASE WHEN R.TIPSERIE &lt;&gt; 0 THEN DECODE(R.CANTFURN * NSER.CANTNIR,NULL,0,0,0,R.CANTFURN * NSER.CANTNIR / SUM(NSER.CANTNIR) OVER (PARTITION BY R.CODNIRSTOC)) ELSE R.CANTFURN/UMDOC.PARITATE END CANT,
    CASE WHEN R.TIPSERIE &lt;&gt; 0 THEN NSER.CANTNIR / UMNIR.PARITATE ELSE R.CANTNIR/UMNIR.PARITATE END CANTNIR,
    CASE WHEN R.TIPNIR IN (12,13) THEN 0 WHEN NVL(I1.RESTFACT,0) = I1.CANT THEN 0 WHEN I1.CANT = 0 THEN 0 WHEN R.TIPSERIE &lt;&gt; 0 THEN NSER.CANTNIR*(I1.CANT-NVL(I1.RESTFACT,0))/I1.CANT/UMDOC.PARITATE ELSE R.CANTFURN*(I1.CANT-NVL(I1.RESTFACT,0))/I1.CANT/UMDOC.PARITATE END CANTFACT,
    NVL(R.TG,NSER.TG) TG, SER.SERIE, NSER.CANTNIR CANTSER, NSER.OBS OBSSER, C.NRCERTIF NRCERTIFSER, C.DATAPRIMIRE, NSER.DATAPROD, C.PROVENIENTA, CT.DEN_TARA, C.OBS OBSCERTIF &apos;;

    vJoinSeriiL  := &apos;
    LEFT JOIN NIRSER NSER ON NSER.CODNIRSER = R.CODNIRSER
    LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
    LEFT JOIN CERTIF C ON C.CODCERTIF = NSER.CODCERTIF
    LEFT JOIN NTARI CT ON CT.CODTARA = C.CODTARA &apos;;

    sCodNirSerL := &apos;, l1.codnirser&apos;;

    vColSeriiL   :=  &apos;,
    R.CANTFURN/UMDOC.PARITATE CANT,
    R.CANTNIR/UMNIR.PARITATE CANTNIR,
    0 CANTFACT,
    NVL(R.TG,NSER.TG) TG, SER.SERIE, NSER.CANTNIR CANTSER, NSER.OBS OBSSER, C.NRCERTIF NRCERTIFSER, C.DATAPRIMIRE, NSER.DATAPROD, C.PROVENIENTA, CT.DEN_TARA, C.OBS OBSCERTIF &apos;;
  END IF;

  sFiltruDoc := &apos;&apos;;
  sFiltruDocM := &apos;&apos;;
  if not PKG_LIST_SELECTGEST.ToateTipDoc then
    sFiltruDoc := &apos; and n.tipnir in (&apos;||PKG_LIST_SELECTGEST.Docs||&apos;) &apos;;
    sFiltruDocM := &apos; and i.tipdoc in (&apos;||PKG_LIST_SELECTGEST.Docs||&apos;) &apos;;
  end if;

  IF vDupaData AND vDataDoc AND g_data1 = g_data2 THEN
    sFiltruT := &apos;
    AND t.datadoc = To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sFiltruI := &apos;
    AND i.datadoc = To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF vDupaData AND vDataDoc THEN
    sFiltruT := &apos;
    AND t.datadoc between To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and To_Date(&apos;&apos;&apos;||g_data2||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sFiltruI := &apos;
    AND i.datadoc between To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and To_Date(&apos;&apos;&apos;||g_data2||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF vDupaData AND g_data1 = g_data2 THEN
    sFiltruN := &apos;
    AND n.datanir = To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sFiltruL := &apos;
    AND l.datalivr = To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF vDupaData THEN
    sFiltruN := &apos;
    AND n.datanir between To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and To_Date(&apos;&apos;&apos;||g_data2||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sFiltruL := &apos;
    AND l.datalivr between To_Date(&apos;&apos;&apos;||g_data1||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and To_Date(&apos;&apos;&apos;||g_data2||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF vLunaAnIni = vLunaAnFin THEN
    sFiltruT := &apos;
    AND T.AN*12+T.LUNA = &apos;||vLunaAnIni;
    sFiltruI := &apos;
    AND I.AN*12+I.LUNA = &apos;||vLunaAnIni;
  ELSE
    sFiltruT := &apos;
    AND T.AN*12+T.LUNA BETWEEN &apos;||vLunaAnIni||&apos; AND &apos;||vLunaAnFin;
    sFiltruI := &apos;
    AND I.AN*12+I.LUNA BETWEEN &apos;||vLunaAnIni||&apos; AND &apos;||vLunaAnFin;
  END IF;

  IF NOT g_ToateGest THEN
    sFiltruN := sFiltruN||&apos;
    AND N.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
    sFiltruL := sFiltruL||&apos;
    AND N.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;
  
  sOperat := &apos;&apos;;
  if not PKG_LIST_SELECTGEST.Extra2 then
    sOperat := &apos; AND N.OPERAT = 1 &apos;;
  end if;

  sInsTmp := &apos;INSERT INTO TMP_LST_RECEPTII (
    coddoc, tipdoc, prefixdoc, nrdoc, datadoc, codnirstoc, codnirser, userid,
    codnir, tipnir, codintr, codtransf, codies, carnetnir, nrnir, datanir, gest, den_gest, codclaseg,
    codlocatie, codumnir, cantnir, cantfurn, cantum1, cantum2, tg, pumaximal, codobiect, codioart, pret, adaos, tva,
    tipserie, procentadaos, supliment, serielot, codintr1, codtransf1, coddvi1, furn, dataachiz,
    aretvaneex, difpret, cont, codtva, proctva,
    codarticol, codclasea, codum1, codum2, clasastatist, an, luna, operat)&apos;;

  sSelTmpT := &apos;
  SELECT
    t.codtransf coddoc, t.tipdoc, t.prefixdoc, t.nrdoc, t.datadoc, ns.codnirstoc, null codnirser, t.userid,
    n.codnir, n.tipnir, n.codintr, n.codtransf, n.codies, n.carnetnir, n.nrnir, n.datanir, n.gest, ng.den_gest, ng.codclasa codclaseg,
    ns.codlocatie, ns.umsec codumnir, ns.cantnir, ns.cantfurn, ns.cantum1, ns.cantum2, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, ns.codintr1, ns.codtransf1, ns.coddvi1, ns.furn, ns.dataachiz,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent proctva,
    a.codarticol, a.clasa codclasea, a.um1 codum1, a.um2 codum2, a.clasastatist, t.an, t.luna, case when n.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end
  FROM TRANSF T
    INNER JOIN NIR N ON N.CODTRANSF = T.CODTRANSF AND N.TIPNIR = T.TIPDOC
    INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    LEFT JOIN NART1 A1 ON A1.CODARTICOL = OBJ.CODARTICOL AND T.AN*12+T.LUNA BETWEEN A1.ALSTART AND A1.ALSTOP
    LEFT JOIN IOART1 IO1 ON IO1.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NTVA1 T1 ON T1.CODTVA = A1.CODTVA AND T.AN*12+T.LUNA BETWEEN T1.ALSTART AND T1.ALSTOP
  WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0
    AND N.TIPNIR = 12 &apos;||sOperat||&apos; AND N.ANULAT = 0
    AND N.CODTRANSF IS NOT NULL &apos;||
    sFiltruDoc||
    sFiltruT||
    sFiltruN||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;T&apos;);

  sSelTmpI := &apos;
  SELECT
    i.codintr coddoc, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, ns.codnirstoc, null codnirser, i.userid,
    n.codnir, n.tipnir, n.codintr, n.codtransf, n.codies, n.carnetnir, n.nrnir, n.datanir, n.gest, ng.den_gest, ng.codclasa codclaseg,
    ns.codlocatie, ns.umsec codumnir, ns.cantnir, ns.cantfurn, ns.cantum1, ns.cantum2, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, ns.codintr1, ns.codtransf1, ns.coddvi1, ns.furn, ns.dataachiz,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent proctva,
    a.codarticol, a.clasa codclasea, a.um1 codum1, a.um2 codum2, a.clasastatist, i.an, i.luna, case when n.operat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end
  FROM INTRARI I
    INNER JOIN NIR N ON N.CODINTR = I.CODINTR AND N.TIPNIR = I.TIPDOC
    INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    LEFT JOIN NART1 A1 ON A1.CODARTICOL = OBJ.CODARTICOL AND I.AN*12+I.LUNA BETWEEN A1.ALSTART AND A1.ALSTOP
    LEFT JOIN IOART1 IO1 ON IO1.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NTVA1 T1 ON T1.CODTVA = A1.CODTVA AND I.AN*12+I.LUNA BETWEEN T1.ALSTART AND T1.ALSTOP
  WHERE I.OPERAT = 1 AND I.ANULAT = 0
    &apos;||sOperat||&apos; AND N.ANULAT = 0
    AND N.CODINTR IS NOT NULL
    AND N.TIPNIR BETWEEN 1 AND 9&apos;||
    sFiltruDoc||
    sFiltruI||
    sFiltruN||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;);

  sSelTmpL := &apos;
  SELECT
    i.codintr coddoc, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, ns.codnirstoc&apos;||Nvl(sCodNirSerL,&apos;,NULL codnirser&apos;)||&apos;, i.userid,
    l.codlivr codnir, l.tiplivr tipnir, l.codintr, 0 codtransf, 0 codies, l.carnetlivr carnetnir, l.nrlivr nrnir, l.datalivr datanir, n.gest, ng.den_gest, ng.codclasa codclaseg,
    ns.codlocatie, ns.umsec codumnir, -SUM(l1.cant) cantnir, -SUM(l1.cant) cantfurn, -SUM(l1.cantum1) cantum1, -SUM(l1.cantum2) cantum2, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, l1.codintr1, 0 codtransf1, l1.coddvi1, ns.furn, ns.dataachiz,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent proctva,
    a.codarticol, a.clasa codclasea, a.um1 codum1, a.um2 codum2, a.clasastatist, i.an, i.luna, &apos;&apos;DA&apos;&apos;
  FROM INTRARI I
    INNER JOIN LIVR L ON L.CODINTR = I.CODINTR AND L.TIPLIVR = I.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = L1.CODINTR1 AND I1.CODINTR = I.CODINTR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = I1.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    LEFT JOIN NART1 A1 ON A1.CODARTICOL = OBJ.CODARTICOL AND I.AN*12+I.LUNA BETWEEN A1.ALSTART AND A1.ALSTOP
    LEFT JOIN IOART1 IO1 ON IO1.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NTVA1 T1 ON T1.CODTVA = A1.CODTVA AND I.AN*12+I.LUNA BETWEEN T1.ALSTART AND T1.ALSTOP
  WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND L.OPERAT = 1 AND I1.CANT &lt; 0 &apos;||
    sFiltruDocM||
    sFiltruI||
    sFiltruL||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;)||&apos;
  GROUP BY
    i.codintr, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.userid, l.codlivr, l.tiplivr, l.codintr, l.carnetlivr, l.nrlivr, l.datalivr,
    ns.codnirstoc&apos;||sCodNirSerL||&apos;,ns.codlocatie, ns.umsec, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, l1.codintr1, l1.coddvi1, ns.furn, ns.dataachiz, n.gest, ng.den_gest, ng.codclasa,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent, a.codarticol, a.clasa, a.um1, a.um2, a.clasastatist, i.an, i.luna
  union all
  SELECT
    i.codintr coddoc, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, ns.codnirstoc&apos;||Nvl(sCodNirSerL,&apos;,NULL codnirser&apos;)||&apos;, i.userid,
    l.codlivr codnir, l.tiplivr tipnir, l.codintr, 0 codtransf, 0 codies, l.carnetlivr carnetnir, l.nrlivr nrnir, l.datalivr datanir, n.gest, ng.den_gest, ng.codclasa codclaseg,
    ns.codlocatie, ns.umsec codumnir, -SUM(l1.cant) cantnir, -SUM(l1.cant) cantfurn, -SUM(l1.cantum1) cantum1, -SUM(l1.cantum2) cantum2, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, l1.codintr1, 0 codtransf1, l1.coddvi1, ns.furn, ns.dataachiz,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent proctva,
    a.codarticol, a.clasa codclasea, a.um1 codum1, a.um2 codum2, a.clasastatist, i.an, i.luna, &apos;&apos;DA&apos;&apos;
  FROM INTRARI I
    INNER JOIN LIVR L ON L.CODINTR = I.CODINTR AND L.TIPLIVR = I.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN DVI D ON D.CODINTR = I.CODINTR
    INNER JOIN DVI1 D1 ON D1.CODDVI1 = L1.CODDVI1 AND D1.CODDVI = D.CODDVI
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = D1.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    LEFT JOIN NART1 A1 ON A1.CODARTICOL = OBJ.CODARTICOL AND I.AN*12+I.LUNA BETWEEN A1.ALSTART AND A1.ALSTOP
    LEFT JOIN IOART1 IO1 ON IO1.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NTVA1 T1 ON T1.CODTVA = A1.CODTVA AND I.AN*12+I.LUNA BETWEEN T1.ALSTART AND T1.ALSTOP
  WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND L.OPERAT = 1 AND D1.CANT &lt; 0 &apos;||
    sFiltruDoc||
    sFiltruI||
    sFiltruL||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;I&apos;)||&apos;
  GROUP BY
    i.codintr, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.userid, l.codlivr, l.tiplivr, l.codintr, l.carnetlivr, l.nrlivr, l.datalivr,
    ns.codnirstoc&apos;||sCodNirSerL||&apos;,ns.codlocatie, ns.umsec, ns.tg, ns.pumaximal, ns.codobiect, ns.codioart, ns.pret, ns.adaos, ns.tva,
    ns.tipserie, ns.procentadaos, ns.supliment, ns.serielot, l1.codintr1, l1.coddvi1, ns.furn, ns.dataachiz, n.gest, ng.den_gest, ng.codclasa,
    io1.aretvaneex, io1.difpret, io1.cont, a1.codtva, t1.procent, a.codarticol, a.clasa, a.um1, a.um2, a.clasastatist, i.an, i.luna&apos;;

	sInsert :=
 &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CODDOC,NAV_TIPDOC,NAV_NIRSTOC,OPERATOR,
    NRNIR,DATANIR,GESTIUNE,LOCATIE,UMSEC,ARTICOL,PRET,
    ADAOS,
		TVA_NIR,
    CONT,PROC_TVA,
    PU,TVA_INTR,
    DATADOC,NRDOC,PREFIXDOC,STIPDOC,PARTENER, UMDOC,
    ValIntr,
    ValNIR,
    ValAdaos,
		VALINTRTVA,
    ValNIRTVA,
    procadaos,
    CARNETNIR,DEN_IOART,CODINTERN,CODEXTERN,CODVAMAL,MASA,VOLUM,
    AdaosFurn,
    AdaosMaximal,
		pumaximal,nrcertif,producator,CLASA_ART, CLASA_PART,CLASA_GEST,tipserie,UM_ALT1,UM_ALT2,CANTUM1, CANTUM2,
    supliment,serielot,pretachiznir,valachiznir,procadaosnir,DocNir,Document,MONDOC,CURSDOC,CLASAS,PRETFARATVA,
    NRDVI,DATADVI,FURNIZOR,CMDFURN,
    ANDOC,LUNADOC,LUNA,
    CANT,CANTNIR,CANTFACT,
    TG,SERIE,CANTSER,OBSSER,NRCERTIFSER,DATAPRIMIRE,DATAPROD,PROVENIENTA,DEN_TARA,OBSCERTIF&apos;||sInsertDC||gUserFields||&apos;)&apos;;

  sSelect := &apos;
	SELECT
    R.CODDOC NAV_CODDOC, R.TIPDOC NAV_TIPDOC, R.CODNIRSTOC NAV_NIRSTOC, U.USERNAME OPERATOR,
    R.NRNIR, R.DATANIR, R.DEN_GEST GESTIUNE, Nvl(NLOC.DENUMIRE,&apos;&apos;...&apos;&apos;) LOCATIE,
    Nvl(umnir.den_um1,&apos;&apos;nedef.&apos;&apos;) UMSEC, Nvl(obj.denumire,&apos;&apos;nedef.&apos;&apos;) ARTICOL, r.pret*umnir.paritate PRET,
		CASE WHEN r.aretvaneex = 1 THEN r.adaos - ((r.pret*r.proctva)/Decode(100+r.proctva,0,1,100+r.proctva)) ELSE r.adaos END * umnir.paritate ADAOS,
   	CASE WHEN r.aretvaneex = 1 THEN (r.pret*r.proctva)*r.cantnir/Decode(100+r.proctva,0,1,100+r.proctva) ELSE 0 END TVA_NIR,
		ncstoc.simbol CONT, r.proctva PROC_TVA,
    CASE WHEN R.TIPNIR = 3 AND i1.cant &lt;&gt; 0 THEN i1.pu-(i1.tva/i1.cant) WHEN R.TIPNIR = 12 THEN TR1.PU WHEN R.TIPNIR = 5 THEN I1.PU ELSE I1.PU END * umdoc.paritate PU,
    CASE WHEN R.tipnir = 12 AND tr1.cant &lt;&gt; 0 THEN tr1.tva*r.cantfurn/tr1.cant WHEN NOT R.tipnir IN (5,12) AND i1.cant &lt;&gt; 0 THEN i1.tva*r.cantfurn/i1.cant ELSE 0 END TVA_INTR,
    r.datadoc, r.nrdoc, r.prefixdoc, pkg_list_base_utils.Decode_tipdoc_scurt(r.tipdoc) STIPDOC, Decode(r.tipdoc,6,nsub.den_subunit,7,gestprod.den_gest,np.den_part) DEN_PART, umdoc.den_um1 UMDOC,
    Decode(r.tipnir,3,i1.pu-Decode(i1.cant,0,0,i1.tva/i1.cant),12,tr1.pu, i1.pu) * r.cantfurn  ValIntr,
    r.pret * r.cantnir - (CASE WHEN r.aretvaneex = 1 THEN (r.pret*r.proctva)*r.cantnir/(100+r.proctva) ELSE 0 END) ValNir,
		CASE WHEN r.aretvaneex = 1 THEN r.adaos -((r.pret*r.proctva)/Decode(100+r.proctva,0,1,100+r.proctva)) ELSE r.adaos END * r.cantnir ValAdaos,
    Decode(R.tipnir,12,tr1.pu,i1.pu)  * r.cantfurn + CASE WHEN nvl(i1.pu*i1.cant,0) &lt;&gt; 0 and R.tipnir not in(3,5) then i1.tva/(i1.pu*i1.cant) * Decode(R.tipnir,12,tr1.pu, i1.pu) * r.cantfurn ELSE 0 END VALINTRTVA,
    r.cantnir * r.pret ValNIRTVA,
    CASE
      WHEN r.difpret = 1 THEN round(100*
        CASE
          WHEN r.aretvaneex = 0 THEN r.adaos/Decode(r.pret-r.adaos,0,1,r.pret-r.adaos)
          WHEN r.aretvaneex = 1 THEN (r.pret/(1+(r.proctva/100))-(r.pret - r.adaos))/Decode((r.pret-r.adaos),0,1,(r.pret-r.adaos))
          WHEN r.aretvaneex = 2 THEN ((r.pret-(r.pret - Decode(r.tipnir,5,dvi1.pretimport,12,tr1.pu,i1.pu))* 100/Decode(100+r.proctva,0,1,100+r.proctva)) - Decode(R.tipnir,5,dvi1.pretimport,i1.pu)) / Decode(( Decode(R.tipnir,5,dvi1.pretimport,i1.pu)),0,1,(Decode(R.tipnir,5,dvi1.pretimport,i1.pu)))
        END,2)
      ELSE 0
    END procadaos,
		CARNET.DENUMIRE CARNETNIR, IO.DEN_IOART, OBJ.CODINTERN, OBJ.CODEXTERN, OBJ.CODVAMAL, OBJ.MASA, OBJ.VOLUM ,
    CASE WHEN r.pret = 0 THEN 0 ELSE (1-( (r.pret - r.adaos)/( r.pret - Decode(r.aretvaneex,1,(r.pret*r.proctva)/Decode(100+r.proctva,0,1,100+r.proctva),0) ) ) )*100 END AdaosFurn,
    CASE WHEN r.pret = 0 THEN 0 ELSE (((r.pumaximal * 100 / Decode(100+r.proctva,0,1,100+r.proctva)) - ( r.pret- Decode(r.aretvaneex,1,(r.pret*r.proctva)/Decode(100+r.proctva,0,1,100+r.proctva),0)) ) / ( r.pret - Decode(r.aretvaneex,1,(r.pret*r.proctva)/Decode(100+r.proctva,0,1,100+r.proctva),0)) )*100 END AdaosMaximal,
    r.pumaximal, i1.NRCERTIF,prod.den_part producator,NCA.DEN_CLASEA, NCP.DEN_CLASEP, NCG.DEN_CLASEG,
    Decode(r.TIPSERIE,0,&apos;&apos;Fara serie&apos;&apos;,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie,
    UM1.DEN_UM UM_ALT1, UM2.DEN_UM UM_ALT2,&apos;||chr(13);
    if pkg_list_selectgest.AduSerii = 1 then
      sSelect := sSelect||&apos;case when NSER.CODNIRSER IS NULL THEN R.CANTUM1 ELSE NSER.CANTUM1 END,CASE WHEN NSER.CODNIRSER IS NULL THEN R.CANTUM2 ELSE NSER.CANTUM2 END,&apos;||chr(13);
    else
      sSelect := sSelect||&apos;R.CANTUM1,R.CANTUM2,&apos;||chr(13);
    end if;
    sSelect := sSelect||&apos;
    r.supliment, r.serielot,
    (r.pret- r.adaos ) * umnir.PARITATE, (r.pret - r.adaos )*r.cantfurn ,r.procentadaos ,
    &apos;&apos;NIR&apos;&apos;||R.nrnir||&apos;&apos;/&apos;&apos;|| to_char(R.datanir,&apos;&apos;dd.mm.yyyy&apos;&apos;) DocNir,
    Decode(R.tipnir,12,tr.prefixdoc,i.prefixdoc)||Decode(R.tipnir,12,tr.nrdoc,i.nrdoc)||&apos;&apos;/&apos;&apos;||to_char(Decode(R.tipnir,12,tr.datadoc,i.datadoc),&apos;&apos;dd.mm.yyyy&apos;&apos;)||&apos;&apos;-&apos;&apos;||Decode(R.tipnir,6,NSUB.DEN_SUBUNIT,7,GESTPROD.DEN_GEST,np.den_part) Document,
    MONDOC.DEN_MONEDA MONDOC,NVL(I.CURS,1) CURSDOC,NCLS.DEN_CLASEAS,
    (r.pret - (CASE WHEN r.aretvaneex = 1 THEN (r.pret*r.proctva)/(100+r.proctva) ELSE 0 END) ) * umdoc.paritate pretfaratva,
    DVI.NRDOC, DVI.DATADOC,FURN.DEN_PART,CF.PREFIXDOC||CF.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(CF.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos; ),
    NVL(i.an,tr.an) andoc, NVL(i.luna,tr.luna) lunadoc, to_char(NVL(i.an,tr.an),&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(NVL(i.luna,tr.luna),&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.Decode_luna(NVL(i.luna,tr.luna)) luna&apos;;

  sFrom := &apos;
  FROM TMP_LST_RECEPTII R
    LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = R.CODOBIECT
    LEFT JOIN IOART IO ON IO.CODIOART = R.CODIOART
    LEFT JOIN NCONT NCSTOC ON NCSTOC.CODCONT = R.CONT
		LEFT JOIN DOCCARNETE CARNET ON CARNET.CODCARNET = R.CARNETNIR
    LEFT JOIN NUM1 UMNIR ON UMNIR.CODUM1 = R.CODUMNIR
    LEFT JOIN INTRARI I ON I.CODINTR = R.CODINTR
    LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
		LEFT JOIN DVI1 ON DVI1.CODDVI1 = R.CODDVI1
    LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = DECODE(R.TIPNIR,5,DVI1.CODINTR1,R.CODINTR1) AND I1.CODINTR = I.CODINTR
    LEFT JOIN TRANSF TR ON TR.CODTRANSF = R.CODTRANSF
    LEFT JOIN TRANSF1 TR1 ON TR1.CODTRANSF1 = R.CODTRANSF1
    LEFT JOIN NLOCATII NLOC ON NLOC.CODLOCATIE = R.CODLOCATIE
    LEFT JOIN NUM1 UMDOC ON UMDOC.CODUM1 = COALESCE(DVI1.UMSEC,TR1.UMSEC,I1.UMSEC)
		LEFT JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.CODSUBUNIT
		LEFT JOIN NGEST GESTPROD ON GESTPROD.CODGEST = I.CODGESTPROD
		LEFT JOIN NPART PROD ON OBJ.CODPRODUCATOR = PROD.CODPART
		LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = R.CODCLASEA
		LEFT JOIN NCLASEP NCP ON NCP.CODCLASEP = NP.CODCLASA
		LEFT JOIN NCLASEG NCG ON NCG.CODCLASEG = R.CODCLASEG
		LEFT JOIN TMP_MANEVRA_SERII TMP ON TMP.CODNIRSTOC = R.CODNIRSTOC
    LEFT JOIN NUM UM1 ON UM1.CODUM = R.CODUM1
		LEFT JOIN NUM UM2 ON UM2.CODUM = R.CODUM2
    LEFT JOIN NMONEDE MONDOC ON MONDOC.CODMONEDA = nvl(I.MONEDA,0)
    LEFT JOIN NCLASEAS NCLS ON NCLS.CODCLASEAS = R.CLASASTATIST
    LEFT JOIN DVI DVI ON DVI.CODDVI = DVI1.CODDVI
    LEFT JOIN NPART FURN ON FURN.CODPART = r.furn
    LEFT JOIN TMP_UTILIZATOR U ON U.CODUTILIZATOR = R.USERID
    LEFT JOIN INTRLINK IL ON IL.CODINTR1 = I1.CODINTR1
    LEFT JOIN COMANDA1 CF1 ON CF1.CODCOMANDA1 = IL.CODLINIECOMANDA
    LEFT JOIN COMANDA CF ON CF.CODCOMANDA = CF1.CODCOMANDA &apos;||
    sJoinDC||
    gSuplJoins;

  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NART1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_NTVA1_LST;
  --PKG_LIST_BASE_UTILS.UMPLE_TMP_IOART1_LST;
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);
  PRC_AL_CHECK(&apos;IOART1&apos;);

  DELETE TMP_LST_RECEPTII; -- se para ca la verificare de structuri tabelel temporare se fac cu ON COMMIT PRESERVE ROWS;
  --stef pasul 1 TMP_LST_RECEPTII cu date din transferuri
  LIST_EXECUTE_IMMEDIATE(sInsTmp||sSelTmpT, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect||vColSeriiN||sSelectDCN||gUserAlias||sFrom||vJoinSeriiN, aListID, aListVer);
  DELETE TMP_LST_RECEPTII; -- se para ca la verificare de structuri tabelel temporare se fac cu ON COMMIT PRESERVE ROWS;
  COMMIT; -- ca sa golim TMP_LST_RECEPTII

  --stef pasul 2 TMP_LST_RECEPTII cu date din intrari
  LIST_EXECUTE_IMMEDIATE(sInsTmp||sSelTmpI, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect||vColSeriiN||sSelectDCN||gUserAlias||sFrom||vJoinSeriiN, aListID, aListVer);
  DELETE TMP_LST_RECEPTII; -- se para ca la verificare de structuri tabelel temporare se fac cu ON COMMIT PRESERVE ROWS;
  COMMIT; -- ca sa golim TMP_LST_RECEPTII

  IF PKG_LIST_SELECTGEST.Extra1 THEN
    --stef pasul 3 TMP_LST_RECEPTII cu date din intrari in rosu
    LIST_EXECUTE_IMMEDIATE(sInsTmp||sSelTmpL, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect||vColSeriiL||sSelectDCL||gUserAlias||sFrom||vJoinSeriiL, aListID, aListVer);
    DELETE TMP_LST_RECEPTII; -- se para ca la verificare de structuri tabelel temporare se fac cu ON COMMIT PRESERVE ROWS;
    COMMIT;
  END IF;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RECEPTII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29899B801B5436F338A6ABAC5871B0474F109D06</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RECLAMATII IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(30000);
  vDataStart varchar2(10);
  vDataStop varchar2(10);
BEGIN
  gSuplCols := &apos;npart PA, RECLAMATII R&apos;;--, emulare e,punctaje pj&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = PA.CODPART&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

 
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;
   (NAV_CodDoc,
    NAV_TIPDOC,
    NRDOC,
    SERIADOC,
    DATADOC,
    CARNETDOC,
    Den_subunit,
    Nume,
    Prenume,
    Motiv,
    Reclamatie,
    Rezolvat,
    DataRez&apos;||gUserFields||&apos;
    )
SELECT
    R.CodDOC,
    R.TipDOC,
    R.NRDOC,
    R.SERIADOC,
    R.DATADOC,
    DC.Denumire CARNETDOC,
    S.Den_subunit,
    P.Nume,
    P.Prenume,
    R.Motiv,
    R.Reclamatie,
    DECODE(R.Rezolvat,0,&apos;&apos;Nu&apos;&apos;,1,&apos;&apos;Da&apos;&apos;) Rezolvat,   
    R.DataRez&apos;||gUserAlias||&apos;
FROM RECLAMATII R
 LEFT JOIN NPERS P on P.CodPERS = R.Codutilizator
 LEFT JOIN NSUBUNIT S ON S.CodSubunit = R.Codsubunit
 LEFT JOIN doccarnete DC on DC.CodCarnet = R.CarnetDoc
 LEFT JOIN npart PA on PA.CodPart = R.CodPart &apos;||
-- LEFT JOIN emulare e on E. 
-- LEFT JOIN punctaje pj on PJ. &apos;||
   gSuplJoins;

--  delete from x;
--  insert into x values (&apos;dupa530&apos;,sInsert);
--  commit; 
 
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RECLAMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGANALITIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55B83194846535BF83FEE2CBCD549E210792C68D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGANALITIC is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(TMpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
  p_Plan    NUMBER(1);
  p_LunaIni NUMBER(5);
  p_LunaFin NUMBER(5);
  p_Subunit NUMBER(20);
  p_Index     BOOLEAN;
  Niv       NUMBER(10);
BEGIN
  gSuplCols := &apos;TMP_LST_JURNAL1 T, NPART P,NAGENDA SED,NPARTCODFISC CIF,NCLASEP CLSP,NARTOBJ OBJ, ANALIZANOD ANOD,ANALIZA ANALIZ,DESCRIPTORI1 ADESC1,DESCRIPTORI ADESC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;, &apos;C1D&apos;, &apos;C1D.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(CD.CODCONT, T.AN, T.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSD&apos;, &apos;CSD.CODCONTS = C1D.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;, &apos;C1C&apos;, &apos;C1C.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(CC.CODCONT, T.AN, T.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSC&apos;, &apos;CSC.CODCONTS = C1C.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;, &apos;CSC&apos;, &apos;CSC.CODCONTS = C1C.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;, &apos;UT&apos;, &apos;UT.CODUTILIZATOR = T.USERID&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  p_Plan    := pkg_list_base_regjurnal.Plan;
  p_LunaIni := pkg_list_base_regjurnal.LunaIni;
  p_LunaFin := pkg_list_base_regjurnal.LunaFin;
  p_Index   := pkg_list_base_regjurnal.isIndex;

  p_Subunit := CASE WHEN pkg_list_base_regjurnal.SubCurenta = 1 THEN pkg_globals.GETSUBUNITATE ELSE 1 END;
  pkg_list_utilfisacont.UMPLE_TMP_LST_JURNAL1(p_Plan, p_LunaIni, p_LunaFin, p_Subunit, aLISTID);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     CodAnalizaNod,
     CodAnaliza,
     NodParinte,
     Nivel,
     Partener,
     DOC,
     DATADOC,
     ARTICOL,
     DocLegatura,
     Cant,
     Pret,
     VALOARE,
     CONT,
     CORESP,
     DATACREARE,
     SUBUNITATEA,
     EXPLICATII,
     GESTIUNE,
     ORDINE,
     CENTRUCOST,
     CENTRUCOSTSIMB,
     TIPDOC,
     IDXNOD,
     NOD,
     ANALIZA,
     COPII
    &apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  select
    t.coddoc,
    t.tipdoc,
    v.CodAnalizaNod,
    analiz.codanaliza,
    case when v.nivel = 1 then -1 else v.NodParinte end,
    v.Nivel,
    p.Den_Part,
    t.DOCUMENT,
    t.DATADOC,
    t.ARTICOL,
    t.DocLegatura,
    t.Cant,
    t.Pret,
    t.VALOARE,
    CD.SIMBOL,
    CC.SIMBOL,
    T.DATACREARE,
    S.Den_subunit,
    t.obs,
    ng.den_gest,
    t.tipdoc + DECODE(t.tipdoc,32,100,0),
    c.denumire,
    c.simbol,
    PKG_LIST_BASE_UTILS.DECODE_TIPDOC(t.TIPDOC), 
    v.simbol,
    LPAD(
    case 
      when v.NIVEL=1 then &apos;&apos;• &apos;&apos;
      when v.NIVEL=2 then &apos;&apos;- &apos;&apos;
      when v.NIVEL=3 then &apos;&apos;~ &apos;&apos;
      when v.NIVEL=4 then &apos;&apos;&lt; &apos;&apos;
      when v.NIVEL=5 then &apos;&apos;&gt; &apos;&apos; 
      when v.NIVEL=5 then &apos;&apos;^ &apos;&apos;
      else &apos;&apos;*&apos;&apos;
    end||adesc1.valoare,
    V.NIVEL*5+LENGTH(adesc1.valoare),&apos;&apos; &apos;&apos;
    ),
    ANALIZ.DEN_ANALIZA,
    (SELECT COUNT(*) FROM V_NoduriAnaliza VV WHERE VV.NODPARINTE = V.CODANALIZANOD) &apos;||gUserAlias||&apos;
  from V_NoduriAnaliza v
       left join tmp_lst_jurnal1 t on v.codanalizanod = t.codanalizanod
       left join ncont CD on CD.codcont = t.codcontd
       left join ncont CC on CC.codcont = t.codcontc
       left join nsubunit s on t.subunitatea = s.codsubunit
       LEFT  JOIN ngest ng on ng.codgest = NVL(t.gest,0)
       LEFT  JOIN centrecost c on c.codcentru = t.codcentru
       LEFT JOIN NPART P ON P.CODPART = t.CODPART
       LEFT JOIN NAGENDA SED ON SED.CODAGENDA = t.CODAGENDA
       LEFT JOIN NPARTCODFISC CIF ON CIF.COD_CODFISCAL = t.COD_CODFISCAL
       LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
       LEFT JOIN NARTOBJ OBJ ON T.CODOBIECT = OBJ.CODOBIECT
       LEFT JOIN ANALIZANOD ANOD ON anod.codanalizanod = v.codanalizanod
       LEFT JOIN ANALIZA ANALIZ ON analiz.codanaliza = anod.codanaliza
       LEFT JOIN DESCRIPTORI1 ADESC1 ON adesc1.coddescriptor1 = anod.coddescriptor1
       LEFT JOIN DESCRIPTORI ADESC ON adesc.coddescriptor = adesc1.coddescriptor&apos;||
  gSuplJoins||&apos;
  where v.codanalizanod &gt; 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  execute immediate &apos;insert into &apos;||tmpname||&apos;(CodAnalizaNod,CODANALIZA,Nivel,IDXNOD,NOD,ANALIZA,COPII)
                     select distinct -1, CodAnaliza, 0, &apos;&apos;00&apos;&apos;, analiza, analiza, 1
                     from &apos;||tmpname;
  execute immediate &apos;select max(nivel) from &apos;||TMPNAME into Niv;
  if Niv &gt; 1 then
    for i in REVERSE 0 .. Niv loop
      execute immediate &apos;UPDATE &apos;||TMPNAME||&apos; T SET VALOARE = COALESCE(VALOARE,0) + (SELECT SUM(TT.VALOARE) FROM &apos;||TMPNAME||&apos; TT WHERE TT.NODPARINTE = T.CODANALIZANOD AND TT.CODANALIZA = T.CODANALIZA) WHERE T.COPII &gt; 0 AND T.NIVEL = &apos;||TO_CHAR(I);
    end loop;  
  end if;  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGANALITIC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGCASABANCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A95493E44709CDCD06A1B4CF0DBF2875E5CA1784</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGCASABANCA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(1000);
  sSelect      VARCHAR2(30000);
  sSelReg      VARCHAR2(5000);
  sDocument    VARCHAR2(2000);
  sCursRef     VARCHAR2(100)   := &apos;1 curs_ref&apos;;
  vCodMOneda   INTEGER;
  dataIni      DATE            := pkg_list_casabanka.getDataIni;
  dataFin      DATE            := pkg_list_casabanka.getDataFin;
  sdataIni     VARCHAR2(200)   := &apos;To_DATE(&apos;&apos;&apos;||To_Char(dataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sdataIniSP   VARCHAR2(200)   := &apos;To_DATE(&apos;&apos;&apos;||To_Char(dataIni+1,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sdataFin     VARCHAR2(200)   := &apos;To_DATE(&apos;&apos;&apos;||To_Char(dataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  vTipDoc      VARCHAR2(2)     := pkg_list_casabanka.getTipDoc;
  vAnIni       NUMBER          := To_Char(dataIni,&apos;yyyy&apos;);
  vLunaIni     NUMBER          := To_Char(dataIni,&apos;mm&apos;);
  vAnLunaIni   NUMBER          := vAnIni * 12 + vLunaIni;
  vAnFin       NUMBER          := To_Char(dataFin,&apos;yyyy&apos;);
  vLunaFin     NUMBER          := To_Char(dataFin,&apos;mm&apos;);
  vAnLunaFin   NUMBER          := vAnFin * 12 + vLunaFin;
  vAmReg       INTEGER;

  vAnLunaLucru NUMBER          := pkg_globals.AnLunaLucru;

  aSitV        NUMBER(1);
  aBancaV      NUMBER(20);
  aMonedaV     NUMBER(20);

  sColSold     VARCHAR2(20)    := &apos;soldlei&apos;;
  sIniOrd      VARCHAR2(20)    := CASE WHEN Extract(DAY FROM dataIni) = 1 THEN &apos;1&apos; ELSE &apos;0&apos; END;

  vDenSubunit  VARCHAR2(100);
  vCount       NUMBER;
  vValI        NUMBER;
  vValP        NUMBER;
  vSold_Col    NUMBER;
  vSoldLei_Col NUMBER;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;tmp_lst_rb rb, nbankcont nbc, nbank nb, npers ag, ncont nc, ncont1 nc1, nconts cs, npart part, npers pers, ngest ng&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,   &apos;PD&apos;,   &apos;PD.CODPART = PART.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;OPER&apos;, &apos;OPER.LOGONNAME = RB.USERID&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV)
  THEN sCursRef := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, rb.datadoc ) curs_ref &apos;;
  END IF;

  -- am nevoie de moneda de lucru si nu o mai pasez ca parametru
  SELECT DISTINCT nbc.codmoneda
  INTO vCodMoneda
  FROM TMP_MANEVRA_LISTE tmp
  INNER JOIN  nbankcont nbc ON tmp.VALOARE = nbc.codbankcont
  WHERE FILTRU = &apos;CODBANKCONT&apos;;

  IF vCodMoneda &lt;&gt; 0 THEN
    SELECT Count(1)
    INTO vAmReg
    FROM reg
    WHERE tipreg = 45
      AND (an * 12 + luna) BETWEEN vAnLunaIni AND vAnLunaFin
      AND datadoc BETWEEN dataini AND datafin
      AND codmoneda = vCodMoneda;

    sColSold := &apos;soldvaluta&apos;;
  END IF;

  IF vAmReg &gt; 0 THEN
    sSelReg := &apos;
      UNION ALL
      SELECT
        r.codreg coddoc, NULL coddoc1, r.tipreg tipdoc, r.datadoc datareg, NULL doccumul, NULL prefixdoc, NULL seriedoc, NULL nri, r.nrdoc, r.datadoc, NULL AGENT,
        &apos;&apos;Regularizare valuta&apos;&apos; explicatii, NULL den_part, 0 cont, NULL obs,
        -1 tiptranz, 0 val, 0 valdoc, r.curs, x.CodBankCont codbanca, 0 sold_col,
        CASE bc.credit WHEN 1 THEN -1 ELSE 1 END * ((x.SoldValuta * r.Curs - x.SoldLei) - Coalesce( lag (x.SoldValuta * r.Curs - x.SoldLei,1) OVER (PARTITION BY X.CODBANKCONT ORDER BY r.datadoc),0)) soldlei_col,
        9 ordine, bc.subunitatea, 0 idxloc, r.an * 12 + r.luna anluna, NULL codpart, NULL codpers, NULL codgest, NULL userid, null taxcode_saft
      FROM (
        SELECT CODBANKCONT, CODREG, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
        FROM (
          SELECT
            T.CODBANCA CODBANKCONT, R.CODREG,
            SUM((CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END * T1.VALDOC - Coalesce(T1.COMISION,0)) * T1.CURS * CASE bc.credit WHEN 1 THEN -1 ELSE 1 END) SOLDLEI,
            SUM((CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END * T1.VALDOC - Coalesce(T1.COMISION,0)) * CASE bc.credit WHEN 1 THEN -1 ELSE 1 END) SOLDVALUTA
          FROM  TREZOR T
            INNER JOIN trezor1   t1 ON t1.codtrezor   = t.codtrezor
            INNER JOIN nbankcont bc ON bc.codbankcont = t.codbanca
            INNER JOIN reg       r  ON r.codmoneda    = bc.codmoneda
          WHERE R.TipReg = 45
            AND Coalesce(bc.farareg, 0) = 0
            AND r.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
            AND r.an * 12 + r.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
            AND t.tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
            AND t.an * 12 + t.luna &gt;= &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
            AND t.an * 12 + t.luna &lt;= r.an * 12 + r.luna
            AND t.datadoc &lt;= r.datadoc
            AND Coalesce(t1.tiptranz,-1) IN (0,1)
            AND bc.codmoneda &lt;&gt; 0
            AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
          GROUP BY T.CODBANCA, R.CODREG
          UNION ALL
          SELECT
            BCS.CODBANKCONT, R.CODREG, Coalesce(bcs.SOLDLEI,0) SOLDLEI,  Coalesce(bcs.SOLDVALUTA,0) SOLDVALUTA
          FROM NBANKSOLDLUNA BCS
            INNER JOIN nbankcont bc ON bc.codbankcont = bcs.codbankcont
            INNER JOIN reg       r  ON r.codmoneda    = bc.codmoneda
          WHERE bc.codmoneda &lt;&gt; 0
            AND R.TipReg = 45
            AND Coalesce(bc.farareg, 0) = 0
            AND r.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
            AND r.an * 12 + r.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
            AND bcs.an * 12 + bcs.luna = &apos;||TO_CHAR(vAnLunaIni-1, &apos;fm00000&apos;)||&apos;
            AND bcs.codbankcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
          )
          GROUP BY CODBANKCONT, CODREG
        ) X
        INNER JOIN REG R ON R.CODREG = X.CODREG
        INNER JOIN NBANKCONT BC ON BC.CODBANKCONT = X.CODBANKCONT
      WHERE SOLDLEI &lt;&gt; SOLDVALUTA * R.CURS&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, DATAREG, DOCCUMUL, PREFIXDOC, SERIEDOC, NRI, NRDOC, DATADOC, AGENT,
    EXPLICATII, DEN_PART, SEMNIFICATIE, CONTSEC, OBS,
    INCASARE, PLATA,
    VALDOC, VALDOCLEI, SOLD_COL, SOLDLEI_COL,
    ORDINE, IDXLOC, SIMB_BANCA, DEN_CONT, NRCONT, SUBUNITATEA, CONTREPR, TIPTRANZ,
    CURS, TAXCODE_SAFT, CURS_REF&apos;||gUserFields||&apos;) &apos;;

  sDocument := &apos;
               CASE
                 WHEN o.semnificatie IN (310,410) THEN &apos;&apos;in avans &apos;&apos;
                 WHEN int.codintr IS NOT NULL THEN int.prefixdoc|| &apos;&apos;/&apos;&apos;||int.nrdoc||&apos;&apos;/&apos;&apos;||int.datadoc
                 WHEN ies.codies  IS NOT NULL THEN ies.prefixdoc|| &apos;&apos;/&apos;&apos;||ies.nrdoc||&apos;&apos;/&apos;&apos;||ies.datadoc
               END &apos;;

  sSelect := &apos;
  WITH
    CC AS (
      SELECT
        T1.CODCONTDED, T1.CODCONTCOLE,
        Greatest(C.ALSTART, T1.ALSTART) ALSTART, LEAST(C.ALSTOP, T1.ALSTOP) ALSTOP
      FROM (
        SELECT CV.VALOARE, CL.ALSTART, CL.ALSTOP
        FROM CONST1 C1
          LEFT JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
          LEFT JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
          LEFT JOIN CONSTVAL  CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
        WHERE Upper(C1.simbol) = Upper(&apos;&apos;TIPTVAImplicit&apos;&apos;)
      ) C INNER JOIN NTVA1 T1 ON T1.CODTVA = C.VALOARE AND T1.ALSTART &lt;= C.ALSTOP AND T1.ALSTOP &gt;= C.ALSTART
    ),
    RB AS (
      SELECT
        coddoc, coddoc1, tipdoc, datareg, doccumul, prefixdoc, seriedoc, nri, nrdoc, datadoc, agent, explicatii, den_part, cont, obs,
        tiptranz, val, valdoc, curs, codbanca, sold_col, soldlei_col, ordine, subunitatea, idxloc, anluna, codpart, codpers, codgest, userid, taxcode_saft
      FROM (
        SELECT
          coddoc, coddoc1, tipdoc, datareg, doccumul, prefixdoc, seriedoc, nri, nrdoc, datadoc, agent, obs,
          CASE
            WHEN tiptranz = 0 AND obiecttranz = 0 THEN &apos;&apos;Plata furnizor &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 1 THEN &apos;&apos;Plata retur &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 2 THEN &apos;&apos;Plata angajat &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 3 THEN &apos;&apos;Plata viramente interne &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 4 THEN &apos;&apos;Plata direct pe cheltuieli &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 5 THEN &apos;&apos;Plata datorii / taxe / impozite &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 0 THEN &apos;&apos;Incasare client &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 1 THEN &apos;&apos;Incasare retur &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 2 THEN &apos;&apos;Incasare angajat &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 3 THEN &apos;&apos;Incasare viramente interne &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 4 THEN &apos;&apos;Incasare direct pe venituri &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 5 THEN &apos;&apos;Incasare imprumuturi / subventii &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 6 THEN &apos;&apos;Incasare dobanda &apos;&apos;
            WHEN tiptranz = 2                     THEN &apos;&apos;Plata SPLIT TVA &apos;&apos;
          END ||den_part||&apos;&apos; &apos;&apos;||vc2_nt_to_string(CAST(collect(DISTINCT DOC) AS vc2_nt)) explicatii,
          case when tiptranz = 1 then 2 else 3 end ordine,
          Coalesce(cont,0) cont, tiptranz, sum(val) val, Coalesce(valdoc,0) valdoc, den_part, codbanca, curs,
          sum(sold_col) sold_col, sum(soldlei_col) soldlei_col, subunitatea, idxloc, anluna, codpart, codpers, codgest, userid, taxcode_saft
        FROM (
          SELECT
            t.codtrezor coddoc, t1.codtrezor1 coddoc1, t.tipdoc, t.datadoc datareg, t.numedoc doccumul, t1.doc prefixdoc, t1.seriedoc, t1.nri, t1.nrdoc, t1.datadoc, Coalesce(NullIF(t1.agent,0),t.agent) agent, t1.obs, t1.obiecttranz,
            CAST(&apos;|| sDocument ||&apos; AS VARCHAR2(100)) doc, nc.codcont cont, CASE WHEN t1.platatva = 1 THEN 2 ELSE t1.tiptranz END tiptranz,
            CASE
              -- cica in cazul t1.obiecttranz = 3 am o singura obligatie asociata, nu are TVA si am gasit bube date de diferente de curs
              -- stef 05.03.2014 am gasit si mai multe linii din preluare pt cazul de mai sus si atunci imi bag picioarele ca iese nasol suma
              WHEN t1.obiecttranz = 3 AND COUNT(1) OVER (PARTITION BY t1.codtrezor1) = 1 THEN t1.valdoc
              WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.dincaretva,0)
              ELSE (Coalesce(o.valoare,0) - Coalesce(g.tva,0)) * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN 1 ELSE Coalesce(NullIF(g.curs,0),1) / Coalesce(NullIF(t1.curs,0),1) END
            END val,
            t1.valdoc, CASE t1.obiecttranz WHEN 3 THEN nb.denumire||&apos;&apos; &apos;&apos;||nbc.nrcont WHEN 2 THEN pers.nume||&apos;&apos; &apos;&apos;||pers.prenume WHEN 1 THEN part.den_part WHEN 0 THEN part.den_part ELSE nc.simbol END den_part,
            t.codbanca, Coalesce(NullIF(t1.curs,0),1) curs,
            CASE
              WHEN t1.obiecttranz = 3 AND COUNT(1) OVER (PARTITION BY t1.codtrezor1) = 1 THEN t1.valdoc
              WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.dincaretva,0)
              ELSE (Coalesce(o.valoare,0) - Coalesce(g.tva,0)) * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN 1 ELSE Coalesce(NullIF(g.curs,0),1) / Coalesce(NullIF(t1.curs,0),1) END
            END * CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END sold_col,
            CASE
              WHEN t1.obiecttranz = 3 AND COUNT(1) OVER (PARTITION BY t1.codtrezor1) = 1 THEN t1.valdoc * Coalesce(NullIF(t1.curs,0),1)
              WHEN Coalesce(t1.platatva,0) = 1 THEN Coalesce(o.dincaretva,0)
              ELSE (Coalesce(o.valoare,0) - Coalesce(g.tva,0)) * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN Coalesce(NullIF(t1.curs,0),1) ELSE Coalesce(NullIF(g.curs,0),1) END
            END * CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END soldlei_col,
            t.subunitatea, t1.indexlocal * 10 + 1 idxloc, t.an*12+t.luna anluna, part.codpart, pers.codpers, o.codgest, t.userid,
            (
              SELECT VC2_NT_TO_VC3200(CAST(COLLECT(TO_CHAR(TXD.TAXCODE) ORDER BY TXD.CODDOC1) AS vc2_nt) , &apos;&apos;;&apos;&apos;) AS taxcode_saft
              FROM TAXDECL TXD
              WHERE TXD.TIPDOC = T.TIPDOC AND TXD.CODDOC = T1.CODTREZOR1
            ) AS taxcode_saft
          FROM trezor t
            LEFT JOIN trezor1 t1 ON t.codtrezor = t1.codtrezor
            LEFT JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
            LEFT JOIN obligpif o ON o.codgeneral = g.codgeneral
            LEFT JOIN npart part ON part.codpart = t1.codpart AND t1.obiecttranz IN (0,1)
            LEFT JOIN npers pers ON pers.codpers = t1.codpart AND t1.obiecttranz = 2
            LEFT JOIN nbankcont nbc ON nbc.codbankcont = t1.codpart AND t1.obiecttranz = 3
            LEFT JOIN nbank nb ON nb.codbank = nbc.codbank
            LEFT JOIN stingere s on s.codstingatorpif = o.codobligpif
            LEFT JOIN obligpif os on os.codobligpif = s.codstinspif
            LEFT JOIN general gs on gs.codgeneral = os.codgeneral
            LEFT JOIN intrari int on int.codintr = gs.coddoc and int.tipdoc = gs.tipdoc
            LEFT JOIN iesiri ies on ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
            LEFT JOIN trezor1 ts1 ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
            LEFT JOIN trezor ts ON ts.codtrezor = ts1.codtrezor
            LEFT JOIN ncont nc ON nc.codcont =
              CASE
                WHEN o.semnificatie IN (300,320) AND Coalesce(os.semnificatie, 0) = 500 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
                WHEN o.semnificatie IN (400,420) AND Coalesce(os.semnificatie, 0) = 600 THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
                WHEN o.semnificatie IN (800,801) THEN To_Number(PKG_CATEGCONST.GETVALCONSTBYCODE(o.icont,t.an,t.luna))
                WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
                WHEN o.semnificatie = 1000 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(t.codbanca,t.an,t.luna))
                WHEN o.semnificatie IN (1100,1101) THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
                ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
              END
          WHERE t.tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
            AND t.an * 12 + t.luna  between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
            AND t.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
            AND Coalesce(t1.tiptranz,-1) IN (0,1)
            AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
          )
        GROUP BY
          coddoc, coddoc1, tipdoc, datareg, prefixdoc, seriedoc, nri, nrdoc, datadoc, agent, obs, Coalesce(cont,0), tiptranz, obiecttranz, valdoc, den_part, codbanca, curs, subunitatea, idxloc, anluna, doccumul,
          codpart, codpers, codgest, userid, taxcode_saft
        UNION ALL
        SELECT
          coddoc, coddoc1, tipdoc, datareg, doccumul, prefixdoc, seriedoc, nri, nrdoc, datadoc, agent, obs,
          CASE
            WHEN tiptranz = 0 AND obiecttranz = 0 THEN &apos;&apos;Plata(TVA) furnizor &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 1 THEN &apos;&apos;Plata(TVA) retur &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 2 THEN &apos;&apos;Plata(TVA) angajat &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 3 THEN &apos;&apos;Plata(TVA) viramente interne &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 4 THEN &apos;&apos;Plata(TVA) direct pe cheltuieli &apos;&apos;
            WHEN tiptranz = 0 AND obiecttranz = 5 THEN &apos;&apos;Plata(TVA) datorii / taxe / impozite &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 0 THEN &apos;&apos;Incasare(TVA) client &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 1 THEN &apos;&apos;Incasare(TVA) retur &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 2 THEN &apos;&apos;Incasare(TVA) angajat &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 3 THEN &apos;&apos;Incasare(TVA) viramente interne &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 4 THEN &apos;&apos;Incasare(TVA) direct pe venituri &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 5 THEN &apos;&apos;Incasare(TVA) imprumuturi / subventii &apos;&apos;
            WHEN tiptranz = 1 AND obiecttranz = 6 THEN &apos;&apos;Incasare(TVA) dobanda &apos;&apos;
          END ||den_part||&apos;&apos; &apos;&apos;||vc2_nt_to_string(CAST(collect(DISTINCT DOC) AS vc2_nt)) explicatii,
          case when tiptranz = 1 then 2 else 3 end ordine,
          Coalesce(cont, 0) cont, tiptranz, sum(val) val , Coalesce(valdoc,0) valdoc, den_part, codbanca, curs,
          sum(sold_col) sold_col, sum(soldlei_col) soldlei_col, subunitatea, idxloc, anluna, codpart, codpers, codgest, userid, taxcode_saft
        FROM (
          SELECT
            t.codtrezor coddoc, t1.codtrezor1 coddoc1, t.tipdoc, t.datadoc datareg, t.numedoc doccumul, t1.doc prefixdoc, t1.seriedoc, t1.nri, t1.nrdoc, t1.datadoc, Coalesce(NullIF(t1.agent,0),t.agent) agent, t1.obs, t1.obiecttranz,
            CAST(&apos;|| sDocument ||&apos; AS VARCHAR2(100)) doc, nc.codcont cont, t1.tiptranz,
            g.tva * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN 1 ELSE Coalesce(NullIF(g.curs,0),1) / Coalesce(NullIF(t1.curs,0),1) END val,
            t1.valdoc, CASE t1.obiecttranz WHEN 3 THEN nb.denumire||&apos;&apos; &apos;&apos;||nbc.nrcont WHEN 2 THEN pers.nume||&apos;&apos; &apos;&apos;||pers.prenume WHEN 1 THEN part.den_part WHEN 0 THEN part.den_part ELSE nc.simbol END den_part,
            t.codbanca, Coalesce(NullIF(t1.curs,0),1) curs,
            CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END * g.tva * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN 1 ELSE Coalesce(NullIF(g.curs,0),1) / Coalesce(NullIF(t1.curs,0),1) END sold_col,
            CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END * g.tva * CASE WHEN g.moneda = &apos;||To_Char(vCodMoneda)||&apos; THEN Coalesce(NullIF(t1.curs,0),1) ELSE Coalesce(NullIF(g.curs,0),1) END soldlei_col,
            t.subunitatea, t1.indexlocal * 10 + 2 idxloc, t.an*12+t.luna anluna, part.codpart, pers.codpers, o.codgest, t.userid,
            (
              SELECT VC2_NT_TO_VC3200(CAST(COLLECT(TO_CHAR(TXD.TAXCODE) ORDER BY TXD.CODDOC1) AS vc2_nt) , &apos;&apos;;&apos;&apos;) AS taxcode_saft
              FROM TAXDECL TXD
              WHERE TXD.TIPDOC = T.TIPDOC AND TXD.CODDOC = T1.CODTREZOR1
            ) AS taxcode_saft
          FROM trezor t
            LEFT JOIN trezor1 t1 ON t.codtrezor = t1.codtrezor
            LEFT JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
            LEFT JOIN obligpif o ON o.codgeneral = g.codgeneral
            LEFT JOIN npart part ON part.codpart = t1.codpart AND t1.obiecttranz IN (0,1)
            LEFT JOIN npers pers ON pers.codpers = t1.codpart AND t1.obiecttranz = 2
            LEFT JOIN nbankcont nbc ON nbc.codbankcont = t1.codpart AND t1.obiecttranz = 3
            LEFT JOIN nbank nb ON nb.codbank = nbc.codbank
            LEFT JOIN stingere s on s.codstingatorpif = o.codobligpif
            LEFT JOIN obligpif os on os.codobligpif = s.codstinspif
            LEFT JOIN general gs on gs.codgeneral = os.codgeneral
            LEFT JOIN intrari int on int.codintr = gs.coddoc and int.tipdoc = gs.tipdoc
            LEFT JOIN iesiri ies on ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
            LEFT JOIN cc ON (t.an * 12 + t.luna) between cc.alstart AND cc.alstop
            LEFT JOIN ncont nc ON nc.codcont = CASE WHEN t1.tiptranz = 0 AND t1.obiecttranz =1 THEN cc.codcontcole WHEN t1.tiptranz = 0 OR t1.obiecttranz =1 THEN cc.codcontded ELSE cc.codcontcole END
          WHERE t.tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
            AND (t.an * 12 + t.luna)  between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
            AND t.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
            AND Coalesce(t1.tiptranz,-1) IN (0,1)
            AND (Coalesce (g.tva, 0) &lt;&gt; 0)
            AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
          )
        GROUP BY
          coddoc, coddoc1, tipdoc, datareg, prefixdoc, seriedoc, nri, nrdoc, datadoc, agent, obs, Coalesce(cont,0), tiptranz, obiecttranz, valdoc, den_part, codbanca, curs, subunitatea, idxloc, anluna, doccumul,
          codpart, codpers, codgest, userid, taxcode_saft&apos;;

  IF vTipDoc = 30 THEN -- banca
    sSelect := sSelect||&apos;
        UNION ALL
        SELECT
          t.codtrezor coddoc, t1.codtrezor1 coddoc1, t.tipdoc, t.datadoc datareg, t.numedoc doccumul, t1.doc prefixdoc, t1.seriedoc, t1.nri, t1.nrdoc, t1.datadoc, t.agent, t1.obs,
          &apos;&apos;Comision Bancar &apos;&apos; explicatii, 2 ordine, iob1.comision cont,
          0 tiptranz, t1.comision val, 0 valdoc, Coalesce(part.den_part,pers.nume|| &apos;&apos; &apos;&apos; || pers.prenume) den_part, t.codbanca, Coalesce(NullIF(t1.curs,0),1) curs,
          - t1.comision sold_col, - t1.comision * Coalesce(NullIF(t1.curs,0),1) soldlei_col,
          t.subunitatea, t1.indexlocal * 10 + 3 idxloc, t.an*12+t.luna anluna, part.codpart, pers.codpers, NULL codgest, NULL userid,
          (
            SELECT VC2_NT_TO_VC3200(CAST(COLLECT(TO_CHAR(TXD.TAXCODE) ORDER BY TXD.CODDOC1) AS vc2_nt) , &apos;&apos;;&apos;&apos;) AS taxcode_saft
            FROM TAXDECL TXD
            WHERE TXD.TIPDOC = T.TIPDOC AND TXD.CODDOC = T1.CODTREZOR1
          ) AS taxcode_saft
        FROM trezor t
          LEFT JOIN trezor1 t1 ON t.codtrezor = t1.codtrezor
          LEFT JOIN npart part ON part.codpart = t1.codpart AND t1.obiecttranz IN (0,1)
          LEFT JOIN npers pers ON pers.codpers = t1.codpart AND t1.obiecttranz = 2
          LEFT JOIN nbankcont1 nbc1 ON nbc1.codbankcont = t.codbanca AND nbc1.alstart &lt;= t.an * 12 + t.luna AND nbc1.alstop &gt;= t.an * 12 + t.luna
          LEFT JOIN iobank1 iob1 ON iob1.codiobank = nbc1.codiobanca AND iob1.alstart &lt;= t.an * 12 + t.luna AND iob1.alstop &gt;= t.an * 12 + t.luna
        WHERE t.tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 AND Coalesce(t1.anulat, 0) = 0
          AND t.an * 12 + t.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
          AND Coalesce(t1.tiptranz,-1) IN (0,1)
          AND Coalesce(t1.comision,0) &lt;&gt; 0
          AND t.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
          AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;) &apos;;
  END IF;

  sSelect := sSelect||&apos;
        )&apos;;

  IF vTipDoc = 29 THEN -- casa - trebuie sa apara si monetarele
  sSelect := sSelect||&apos;
      UNION ALL
      SELECT
        i.codies coddoc, NULL coddoc1, i.tipdoc, i.datadoc datareg, Coalesce(i.prefixdoc,&apos;&apos;M&apos;&apos;) doccumul, i.prefixdoc, i.seriadoc seriedoc, i.nri, i.nrdoc, i.datadoc, i.agent,
        &apos;&apos;Incasare Monetar &apos;&apos; explicatii, null den_part, x.cont, i.obs,
        1 tiptranz,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN SUM(mp.valoare) ELSE SUM(mp.valoare) * (i.valdoc - i.tvadoc) / i.valdoc END * x.coef,7) val,
        i.valdoc, Coalesce(NullIF(i.curs,0),1) curs, mp.codbankcont codbanca,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN SUM(mp.valoare) ELSE SUM(mp.valoare) * (i.valdoc - i.tvadoc) / i.valdoc END * x.coef,7) sold_col,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN SUM(mp.valoare) ELSE SUM(mp.valoare) * (i.valdoc - i.tvadoc) / i.valdoc END * x.coef * Coalesce(NullIF(i.curs,0),1),7) soldlei_col,
        2 ORDINE, i.subunitatea, i.codies * 10 idxloc, i.an*12+i.luna anluna, NULL codpart, NULL codpers, NULL codgest, i.userid, null as taxcode_saft
      FROM (
        SELECT
          i.codies, Coalesce(ioa1.venituri,i1.contserv,0) cont,
          Sum (
            CASE
              WHEN coalesce(i1.tva,0) = 0 THEN Coalesce(l1.cant, i1.cant) * i1.pu
              WHEN l1.codlivr1 IS NULL THEN (i1.pu * i1.cant - coalesce(i1.tva,0))
              WHEN i1.pu * i1.cant = 0 THEN 0
              ELSE (i1.pu * i1.cant - coalesce(i1.tva,0)) * l1.cant / i1.cant
            END) / (i.valdoc - i.tvadoc - Coalesce(i.valdiscount,0) + Coalesce(i.tvadiscount,0)) coef
        FROM iesiri i
          LEFT JOIN iesiri1 i1 ON i1.codies = i.codies AND (i.valdoc - i.tvadoc &lt;&gt; 0) AND (i1.pu * i1.cant - coalesce(i1.tva,0) &lt;&gt; 0)
          LEFT JOIN livr1 l1 ON l1.codies1 = i1.codies1
          LEFT JOIN livr l ON l1.codlivr = l.codlivr AND l.codies = i.codies
          LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
          LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
          LEFT JOIN ioart1 ioa1 ON ioa1.codioart = CASE WHEN COALESCE(l1.contintermed, 0) &lt;&gt; 0 THEN l1.contintermed ELSE COALESCE(ns.codioart, lv.codioart,-1) END AND &apos;||To_Char(vAnLunaLucru, &apos;fm00000&apos;)||&apos; BETWEEN ioa1.alstart AND ioa1.alstop
        WHERE i.tipdoc = 16 AND i.anulat = 0 AND i.operat = 1
          AND NOT (i1.tiplinie = &apos;&apos;=&apos;&apos; AND l1.codlivr1 IS NULL)
          AND i.an * 12 + i.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
          AND i.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
          AND EXISTS (SELECT mp.codies
                      FROM moduriplati mp INNER JOIN tmp_manevra_liste tmp ON mp.codbankcont = tmp.valoare
                      WHERE mp.codies = i.codies AND tmp.filtru = &apos;&apos;CODBANKCONT&apos;&apos;)
        GROUP BY i.codies, i.valdoc, i.tvadoc, i.valdiscount, i.tvadiscount, Coalesce(ioa1.venituri,i1.contserv,0) ) x
        INNER JOIN iesiri i ON i.codies = x.codies
        INNER JOIN moduriplati mp ON mp.codies = i.codies
      WHERE mp.codbankcont IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
      GROUP BY i.codies, i.tipdoc, i.prefixdoc, i.seriadoc, i.nri, i.nrdoc, i.datadoc, i.agent, i.obs, i.valdoc, i.tvadoc, i.subunitatea, i.curs, i.an, i.luna, mp.codbankcont, x.cont, x.coef, i.userid
      UNION ALL
      SELECT
        i.codies coddoc, NULL coddoc1, i.tipdoc, i.datadoc datareg, Coalesce(i.prefixdoc,&apos;&apos;M&apos;&apos;) doccumul, i.prefixdoc, i.seriadoc seriedoc, i.nri, i.nrdoc, i.datadoc, i.agent,
        &apos;&apos;Incasare(TVA) Monetar &apos;&apos; explicatii, null den_part, cc.codcontcole cont, i.obs,
        1 tiptranz,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN 0 ELSE SUM(mp.valoare) * i.tvadoc / i.valdoc END,7) val,
        i.valdoc, Coalesce(NullIF(i.curs,0),1) curs, mp.codbankcont codbanca,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN 0 ELSE SUM(mp.valoare) * i.tvadoc / i.valdoc END,7) sold_col,
        Round(CASE WHEN i.tvadoc = 0 OR i.valdoc = 0 THEN 0 ELSE SUM(mp.valoare) * i.tvadoc / i.valdoc END * Coalesce(NullIF(i.curs,0),1),7) soldlei_col,
        2 ORDINE, i.subunitatea, i.codies * 10 +1 idxloc, i.an*12+i.luna anluna, NULL codpart, NULL codpers, NULL codgest, i.userid, null as taxcode_saft
      FROM iesiri i
        LEFT JOIN moduriplati mp ON mp.codies = i.codies
        LEFT JOIN cc ON i.an * 12 + i.luna between cc.alstart AND cc.alstop
      WHERE i.tipdoc = 16 AND i.anulat = 0 AND i.operat = 1
        AND i.an * 12 + i.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
        AND i.datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
        AND mp.codbankcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
      GROUP BY i.codies, i.tipdoc, i.prefixdoc, i.seriadoc, i.nri, i.nrdoc, i.datadoc, i.agent, i.obs, i.valdoc, i.tvadoc, i.subunitatea, i.curs, i.an, i.luna, mp.codbankcont, cc.codcontcole, i.userid&apos;;
  END IF;

  sSelect := sSelect||&apos;
      UNION ALL
      SELECT
        NULL coddoc, NULL coddoc1, NULL tipdoc, to_date(&apos;&apos;&apos;||To_Char(dataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) datareg, NULL doccumul, NULL prefixdoc, NULL seriedoc, NULL nri, NULL nrdoc, NULL DATADOC, NULL AGENT,
        CASE ordine WHEN 1 THEN &apos;&apos;Documente cu data &lt; &apos;&apos;||&apos;&apos;&apos;||To_Char(dataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos; ELSE &apos;&apos;Sold initial&apos;&apos; END explicatii, NULL den_part, NULL semnificatie, NULL obs,
        -1 tiptranz, 0 val, 0 valdoc, NULL curs, NULL codbanca, SUM (sold) sold_col, SUM (soldlei) soldlei_col, ordine,
        PKG_GLOBALS.GETSUBUNITATE subunitatea, 0 idxloc, 0 anluna, NULL codpart, NULL codpers, NULL codgest, NULL userid, null as taxcode_saft
      FROM (
        SELECT 0 ordine, 0 sold, 0 soldlei FROM DUAL
        UNION ALL
        SELECT 0 ordine, Coalesce(&apos;||sColSold||&apos;,0) sold, Coalesce(soldlei,0) soldlei
        FROM nbanksoldluna
        WHERE (an * 12 + luna) = &apos;||to_char(vAnLunaIni-1)||&apos;
          AND codbankcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
        UNION ALL
        SELECT &apos;||sIniOrd||&apos; ordine,
          (t1.valdoc * CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END - Coalesce(t1.comision,0)) * CASE bc.credit WHEN 1 THEN -1 ELSE 1 END sold,
          (t1.valdoc * CASE t1.tiptranz WHEN 1 THEN 1 ELSE -1 END - Coalesce(t1.comision,0)) * Coalesce(NullIF(t1.curs,0),1) * CASE bc.credit WHEN 1 THEN -1 ELSE 1 END soldlei
        FROM trezor t
          LEFT JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
          LEFT JOIN nbankcont bc ON bc.codbankcont = t.codbanca
        WHERE t.tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 AND Coalesce(t1.anulat, 0) = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;
          AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
          AND t.datadoc &lt; &apos;||sdataini||&apos;
          AND (t.an * 12 + t.luna) = &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;);

  IF vTipDoc = 29 THEN -- casa - trebuie sa apara si monetarele
    sSelect := sSelect||&apos;
        UNION ALL
        SELECT &apos;||sIniOrd||&apos; ordine, SUM(mp.valoare) sold , SUM(mp.valoare) * Coalesce(NullIF(i.curs,0),1) soldlei
        FROM iesiri i LEFT JOIN moduriplati mp ON mp.codies = i.codies
        WHERE i.tipdoc = 16 AND i.anulat = 0 AND i.operat = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos;
          AND i.an * 12 + i.luna = &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos;
          AND i.datadoc &lt; &apos;||sdataini||&apos;
          AND mp.codbankcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)
        GROUP BY i.codies, i.tipdoc, i.prefixdoc, i.seriadoc, i.nri, i.nrdoc, i.datadoc, i.agent, i.obs, i.valdoc, i.tvadoc, i.subunitatea, i.curs, mp.codbankcont&apos;;  END IF;

  sSelect := sSelect||&apos;
      )
      GROUP BY ordine
      UNION ALL
      SELECT DISTINCT
        NULL coddoc, NULL coddoc1, NULL tipdoc, datadoc datareg, NULL doccumul, NULL prefixdoc, NULL seriedoc, NULL nri, NULL nrdoc, NULL datadoc, NULL AGENT,
        &apos;&apos;Sold ziua precedenta&apos;&apos; explicatii, NULL den_part, NULL semnificatie, NULL obs,
        -1 tiptranz, 0 val, 0 valdoc, NULL curs, NULL codbanca, 0 sold_col, 0 soldlei_col, 1 ordine,
        PKG_GLOBALS.GETSUBUNITATE subunitatea, 0 idxloc, 0 anluna, NULL codpart, NULL codpers, NULL codgest, NULL userid, null as taxcode_saft
      FROM (
        SELECT datadoc
        FROM  trezor t
        WHERE tipdoc = &apos;||To_Char(vTipDoc)||&apos; AND t.operat = 1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT||&apos;
          AND datadoc between &apos;||sdatainiSP||&apos; AND &apos;||sdatafin||&apos;
          AND t.codbanca IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;)&apos; ;

  IF vTipDoc = 29 THEN -- casa - trebuie sa apara si monetarele
    sSelect := sSelect||&apos;
        UNION
        SELECT i.datadoc
        FROM iesiri i LEFT JOIN moduriplati mp ON mp.codies = i.codies
        WHERE i.tipdoc = 16 AND i.anulat = 0 AND i.operat = 1 &apos;|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos;
          AND i.an * 12 + i.luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
          AND i.datadoc BETWEEN &apos;||sdatainiSP||&apos; AND &apos;||sdatafin||&apos;
          AND mp.codbankcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODBANKCONT&apos;&apos;) &apos;;
  END IF;

  sSelect := sSelect||&apos;
      )&apos;||sSelreg||&apos;
    ),
    R AS (
      SELECT CODBANK, MAX(CURS) KEEP (DENSE_RANK LAST ORDER BY DATADOC) CURS
      FROM reg
      WHERE tipreg = 45
        AND datadoc BETWEEN &apos;||sdataini||&apos; AND &apos;||sdatafin||&apos;
        AND an * 12 + luna between &apos;||To_Char(vAnLunaIni, &apos;fm00000&apos;)||&apos; AND &apos;||To_Char(vAnLunaFin, &apos;fm00000&apos;)||&apos;
        AND codmoneda = &apos;||To_Char(vCodMoneda)||&apos;
      GROUP BY CODBANK)
  SELECT
    rb.coddoc, rb.coddoc1, rb.tipdoc, rb.datareg, rb.doccumul, rb.prefixdoc, rb.seriedoc, rb.nri, rb.nrdoc, rb.datadoc, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume AS agent,
    CAST(rb.explicatii AS VARCHAR2(300)) AS explicatii, rb.den_part, nc.simbol semnificatie, cs.simbol contsec, rb.obs,
    Coalesce(CASE WHEN rb.tiptranz  = 1      THEN rb.val END,0) * Coalesce(CASE nbc.codmoneda WHEN 0 THEN rb.curs ELSE 1 END,0) AS incasare,
    Coalesce(CASE WHEN rb.tiptranz IN (0, 2) THEN rb.val END,0) * Coalesce(CASE nbc.codmoneda WHEN 0 THEN rb.curs ELSE 1 END,0) AS plata,
    rb.valdoc, rb.valdoc * Coalesce(r.curs,rb.curs) AS valdoclei,
    CASE nbc.credit WHEN 1 THEN -1 ELSE 1 END * rb.sold_col AS sold_col, CASE nbc.credit WHEN 1 THEN -1 ELSE 1 END * rb.soldlei_col AS soldlei_col,
    rb.ordine, rb.idxloc, nb.simbol simb_banca, nbc.den_cont, nbc.nrcont, sub.den_subunit, ncb.simbol contrepr, CASE rb.tiptranz WHEN 1 THEN &apos;&apos;Incasare&apos;&apos; ELSE &apos;&apos;Plata&apos;&apos; END tiptranz,
    CASE
      WHEN Coalesce(rb.curs,0) &lt;&gt; 0 THEN rb.curs
      WHEN Coalesce(rb.sold_col,0) &lt;&gt; 0 AND Coalesce(rb.soldlei_col,0) &lt;&gt; 0 THEN rb.soldlei_col/rb.sold_col
      ELSE 1
    END AS curs, rb.taxcode_saft, &apos;||sCursRef||gUserAlias||&apos;
  FROM rb
    LEFT JOIN nbankcont nbc ON nbc.codbankcont = rb.codbanca
    LEFT JOIN nbank nb ON nb.codbank = nbc.codbank
    LEFT JOIN npers ag ON ag.codpers = rb.agent
    LEFT JOIN npart part ON part.codpart = rb.codpart
    LEFT JOIN npers pers ON pers.codpers = rb.codpers
    LEFT JOIN ngest ng ON ng.codgest = rb.codgest
    LEFT JOIN nsubunit sub ON sub.codsubunit = rb.subunitatea
    LEFT JOIN nbankcont1 nbc1 ON nbc1.codbankcont = rb.codbanca AND nbc1.alstart &lt;= rb.anluna AND nbc1.alstop &gt;= rb.anluna
    LEFT JOIN iobank1 iob1 ON iob1.codiobank = nbc1.codiobanca AND iob1.alstart &lt;= rb.anluna AND iob1.alstop &gt;= rb.anluna
    LEFT JOIN ncont nc ON nc.codcont = rb.cont
    LEFT JOIN ncont1 nc1 ON nc1.codcont = rb.cont AND nc1.alstart &lt;= rb.anluna AND nc1.alstop &gt;= rb.anluna
    LEFT JOIN nconts cs ON cs.codconts = nc1.contsecundar
    LEFT JOIN ncont ncb ON ncb.codcont = iob1.cont
    LEFT JOIN r ON r.codbank = nbc.codbank&apos;||
    gSuplJoins||&apos;
  ORDER BY rb.datareg, rb.ordine, rb.idxloc&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  IF PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 AND pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) &lt;&gt; 1
  THEN
    SELECT DEN_SUBUNIT INTO vDenSubunit FROM NSUBUNIT WHERE CodSubunit = PKG_GLOBALS.GETSUBUNITATE;
    EXECUTE IMMEDIATE &apos;SELECT Count(1), Sum(INCASARE), SUM(PLATA), Sum(sold_col), Sum(soldlei_col) FROM &apos;||tmpName||&apos; WHERE SUBUNITATEA &lt;&gt; :1&apos;
    INTO vCount, vValI, vValP, vSold_Col, vSoldLei_Col USING vDenSubunit;
    IF vCount &gt; 0 THEN
      EXECUTE IMMEDIATE &apos;DELETE &apos;||tmpName||&apos; WHERE SUBUNITATEA &lt;&gt; :1&apos; USING vDenSubunit;
      IF vValI &lt;&gt; 0 OR vValP &lt;&gt; 0 OR vSold_Col &lt;&gt; 0 OR vSoldLei_Col &lt;&gt; 0 THEN
        EXECUTE IMMEDIATE
         &apos;INSERT INTO &apos;||tmpName||&apos; (
           DATAREG, AGENT, EXPLICATII, INCASARE, PLATA, VALDOC, VALDOCLEI, SOLD_COL, SOLDLEI_COL, ORDINE, IDXLOC, SUBUNITATEA)
          SELECT to_date(&apos;&apos;&apos;||To_Char(dataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), &apos;&apos; &apos;&apos;, &apos;&apos;Tranzactii alte subunitati&apos;&apos;, :1, :2, 0, 0, :3, :4, 9, 0, &apos;&apos;Altele&apos;&apos;
          FROM DUAL&apos;
        USING vValI, vValP, vSold_Col, vSoldLei_Col;
      END IF;
    END IF;

  END IF;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_REGCASABANCA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGCONTABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0552D788D0A620107AC4699A3F218D9A3493160C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_regcontabil IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sINSERT VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols := &apos;NCONT NC, NCONTS NCS, CENTRECOST C&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME || &apos; (SIMBOL,DEN_GEST,POSTING_KEY,VALOARE&apos;||gUserFields||&apos;)
  SELECT NCS.SIMBOL, C.SIMBOL CENTRUCOST, POSTING_KEY,VALOARE &apos;||gUserAlias||&apos;
  FROM (
    SELECT NC1.CODCONT, Nvl(JC.CODCENTRU,0) CODCENTRU, Nvl(NC1.CONTSECUNDAR,0) CONTSECUNDAR, CASE WHEN SUM(JC.VALOARE) &gt; 0 THEN &apos;&apos;50&apos;&apos; ELSE &apos;&apos;40&apos;&apos; END POSTING_KEY, ABS(SUM(JC.VALOARE)) VALOARE
    FROM JURNAL JC
      INNER JOIN NCONT1 NC1 ON NC1.CODCONT = JC.CONTC AND &apos;||PKG_GLOBALS.AnLunaLucru ||&apos; BETWEEN NC1.ALSTART and NC1.ALSTOP
    WHERE JC.AN * 12 + JC.LUNA = &apos;||PKG_GLOBALS.AnLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;JC&apos;)||&apos;
    GROUP BY NC1.CODCONT, Nvl(JC.CODCENTRU,0), NC1.CONTSECUNDAR 
    UNION ALL
    SELECT NC1.CODCONT, Nvl(JD.CODCENTRU,0) CODCENTRU, Nvl(NC1.CONTSECUNDAR,0) CONTSECUNDAR, CASE WHEN SUM(JD.VALOARE) &gt; 0 THEN &apos;&apos;40&apos;&apos; ELSE &apos;&apos;50&apos;&apos; END POSTING_KEY, ABS(SUM(JD.VALOARE)) VALOARE
    FROM JURNAL JD
      INNER JOIN NCONT1 NC1 ON NC1.CODCONT = JD.CONTD AND &apos;||PKG_GLOBALS.AnLunaLucru ||&apos; BETWEEN NC1.ALSTART and NC1.ALSTOP
    WHERE JD.AN * 12 + JD.LUNA = &apos;||PKG_GLOBALS.AnLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;JD&apos;)||&apos;
    GROUP BY NC1.CODCONT, Nvl(JD.CODCENTRU,0), NC1.CONTSECUNDAR
  ) J
    INNER JOIN NCONT      NC  ON NC.CODCONT   = J.CODCONT
    INNER JOIN NCONTS     NCS ON NCS.CODCONTS = J.CONTSECUNDAR
    LEFT  JOIN CENTRECOST C   ON C.CODCENTRU  = J.CODCENTRU&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGCONTABIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGEVFISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C60A48D533B14F4A95E0C0340B752C90C045827C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGEVFISC is

  vCodDProfit  NUMBER(20);
  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodDProfit IN NUMBER) IS
BEGIN
  vCodDProfit := pCodDProfit;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ADD_LIST_PARAMS IS
aCont number(20);
aRulaj number(20,7);  
BEGIN
  aCont := pkg_categconst.GetValConstanta(&apos;CCheltImpProfit&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru);
  pkg_list_Struct.GOLESTE_PARAM;
  FOR v_rec IN (
    SELECT
      TIPPROFIT,
      TIPAN,
      ELEMSIMVENIT,
      ELEMSIMCHELT,
      DEDUCERI,
      DEDREZLEG,
      DEDPROFITR,
      DEDALTE,
      CHELTAFVENIT,
      CHELTPRADM,
      CHELTPRNEDED,
      PIERDERE,
      PROFITCONTA,
      PROFITIMPOZ,
      SUMAMAX,
      CHELTSPONSOR,
      IMPOZITPROFIT,
      IMPOZITPROFITD,
      AN,
      TRIMESTRU,
      TOTALRULAJV,
      TOTALVENITURI,
      TOTALSUMEV,
      TOTALRULAJC,
      TOTALCHELT,
      TOTALSUMEC,
      OBS,
      SUBUNITATEA,
      AMOFISC,
      CHELTDOBPREC,
      PROVFISC,
      CREDITFISCEXT,
      IMPPROFREINV,
      ALTESCUTIRI,
      CIFRAAFACERI,
      s.den_subunit,
      CREDITFISCAL,
      IMPOZITPROFITC,
      IMPPROFDIF,
      ANGENERARE,
      LUNAGENERARE,
      SPONSORREPORT,
      pkg_categconst.GetValConstanta(&apos;ProcImpProfit&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ProdImpProfit
    FROM dprofit d
         left join nsubunit s on d.subunitatea = s.codsubunit
    WHERE coddprofit = vCodDProfit
  ) LOOP
    if v_rec.tipprofit = 1 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;Tip&apos;, &apos;Trimestrial&apos;);
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;Tip&apos;, &apos;Anual&apos;);
    end if;
    pkg_list_Struct.ADAUGA_PARAM(&apos;Elemente similare veniturilor&apos;, TO_CHAR(v_rec.ELEMSIMVENIT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));


    pkg_list_Struct.ADAUGA_PARAM(&apos;Elemente similare cheltuielilor&apos;, TO_CHAR(v_rec.ELEMSIMCHELT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Deduceri fiscale&apos;, TO_CHAR(v_rec.DEDUCERI,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Rezerva legala deductibila&apos;, TO_CHAR(v_rec.DEDREZLEG,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Profit scutit&apos;, TO_CHAR(v_rec.DEDPROFITR,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Alte sume deductibile&apos;, TO_CHAR(v_rec.DEDALTE,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli aferente veniturilor neimpozabile&apos;, TO_CHAR(v_rec.CHELTAFVENIT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli protocol admise&apos;, TO_CHAR(v_rec.CHELTPRADM,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli protocol nedeductibile&apos;, TO_CHAR(v_rec.CHELTPRNEDED,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Pierdere din anii precedenti&apos;, TO_CHAR(v_rec.PIERDERE,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Profit contabil&apos;, TO_CHAR(v_rec.PROFITCONTA,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Profit impozabil&apos;, TO_CHAR(v_rec.PROFITIMPOZ,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Suma maxima deductibila&apos;, TO_CHAR(v_rec.SUMAMAX,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli sponsorizari deductibile&apos;, TO_CHAR(v_rec.CHELTSPONSOR,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Impozit pe profit&apos;, TO_CHAR(v_rec.IMPOZITPROFIT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Impozit pe profit declarat&apos;, TO_CHAR(v_rec.IMPOZITPROFITD,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;An&apos;, v_rec.An);
    if v_rec.tipprofit = 1 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;Trimestru&apos;, v_rec.trimestru);
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;Trimestru&apos;, &apos;&apos;);
    end if;
    pkg_list_Struct.ADAUGA_PARAM(&apos;Observatii&apos;, v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Subunitatea&apos;, v_rec.den_subunit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Amortizare fiscala&apos;, TO_CHAR(v_rec.AMOFISC,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli cu dobanzile&apos;, TO_CHAR(v_rec.CHELTDOBPREC,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Provizioane fiscale&apos;, TO_CHAR(v_rec.PROVFISC,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Credit fiscal extern&apos;, TO_CHAR(v_rec.CREDITFISCEXT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Impozit pe profit scutit&apos;, TO_CHAR(v_rec.IMPPROFREINV,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Alte scutiri si reduceri&apos;, TO_CHAR(v_rec.ALTESCUTIRI,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cifra de afaceri&apos;, TO_CHAR(v_rec.CIFRAAFACERI,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Credit fiscal&apos;, TO_CHAR(v_rec.CREDITFISCAL,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Impozit profit contabilizat anterior&apos;, TO_CHAR(v_rec.IMPOZITPROFITC,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Impozit pe profit inainte de scaderea sumelor&apos;, TO_CHAR(v_rec.IMPPROFDIF,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Suma din spons. reportata&apos;, TO_CHAR(v_rec.SPONSORREPORT,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Procent impozit pe profit&apos;, TO_CHAR(v_rec.ProdImpProfit,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Total venituri&apos;, TO_CHAR(v_rec.TotalRulajV,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Total cheltuieli&apos;, TO_CHAR(v_rec.TotalRulajC,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Venituri neimpozabile&apos;, TO_CHAR(v_rec.TotalVenituri,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli nedeductibile&apos;, TO_CHAR(v_rec.TotalChelt,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    EXIT;
  END LOOP;
  aRulaj := 0;
  begin
    select sum(coalesce(rulaj,0)) into aRulaj from dprofitc where codcont = aCont;
  exception when others then aRulaj := 0;
  end;
  pkg_list_Struct.ADAUGA_PARAM(&apos;Cheltuieli impozit profit(rulaj)&apos;, TO_CHAR(aRulaj,&apos;fm9G999G999G990D0099&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert varchar2(20000);
BEGIN
  gSuplCols := &apos;ncont c&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    RULAJ,
    VENCHELT,
    SUMA,
    SIMBOL,
    DEN_CONT,
    TIPCONT,
    TIP&apos;||gUserFields||&apos;)
  SELECT
    ch.RULAJ,
    ch.cheltuieli VENCHELT,
    ch.SUMA,
    c.SIMBOL,
    c.DEN_CONT,
    DECODE(C.TIPCONT,0, &apos;&apos;ACTIV&apos;&apos;,1,&apos;&apos;PASIV&apos;&apos;,2,&apos;&apos;BIFUNC&apos;&apos;) TIPCONT,
    &apos;&apos;Cheltuieli&apos;&apos; TIP &apos;||gUserAlias||&apos;
  FROM dprofitc ch
       inner join ncont c on ch.codcont = c.codcont
    &apos;||gSuplJoins||&apos;
  WHERE ch.coddprofit = &apos;||vCodDProfit||&apos;
  union all
  SELECT
    ch.RULAJ,
    ch.venituri VENCHELT,
    ch.SUMA,
    c.SIMBOL,
    c.DEN_CONT,
    DECODE(C.TIPCONT,0, &apos;&apos;ACTIV&apos;&apos;,1,&apos;&apos;PASIV&apos;&apos;,2,&apos;&apos;BIFUNC&apos;&apos;) TIPCONT,
    &apos;&apos;Venituri&apos;&apos; TIP &apos;||gUserAlias||&apos;
  FROM dprofitv ch
       inner join ncont c on ch.codcont = c.codcont
    &apos;||gSuplJoins||&apos;
  WHERE ch.coddprofit = &apos;||vCodDProfit;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  PKG_LIST_BASE_REGEVFISC.add_list_params;
  COMMIT;
END;

end PKG_LIST_BASE_REGEVFISC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGINOUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE567922EB5A62A35BAE7AABD2E6AFE969E61EA9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGINOUT IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  sSelect1     VARCHAR2(20000);
  sSelect2     VARCHAR2(20000);
  vZiuaIni     DATE            := PKG_LIST_ALEGPERIOADA.getDataS;
  vZiuaFin     DATE            := PKG_LIST_ALEGPERIOADA.getDataF;
  sPer    VARCHAR2(  100) := &apos;Null&apos;;
BEGIN
  gSuplCols := &apos;NPART NP, NAGENDA NA, NLOCALIT NL, NJUDET NJ, NPARTCODFISC FISC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF vZiuaIni = vZiuaFin THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(vZiuaIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(vZiuaIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(vZiuaFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, TIPINTR, TIPIES, TIPDOC,
    PREFIXDOC, NRDOC, DATADOC, DATACREARE,
    PARTENER, CODFISCAL,
    LOCALITATE, JUDET,
    ADRESA,
    OBS, OPERATOR &apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    I.CODIES, I.TIPDOC, &apos;&apos;NU&apos;&apos; Intrari, &apos;&apos;DA&apos;&apos; Iesiri, pkg_list_base_utils.decode_tipdoc_scurt(i.tipdoc),
    I.PREFIXDOC, I.NRDOC, I.DATADOC, I.DATACREARE,
    NP.DEN_PART, FISC.CODFISCAL,
    NL.DEN_LOCALIT, NJ.DEN_JUDET,
    getadresa(na.sector, na.strada, na.nr1, na.nr2, na.bloc, na.scara, na.etaj, na.apart, na.codpostal),
    I.OBS, UT.NUME &apos;||gUserAlias||&apos;
  FROM IESIRI I
    LEFT JOIN NPART NP ON np.codpart = i.partener
    LEFT JOIN NAGENDA NA ON NA.codagenda = I.codlocatie
    LEFT JOIN NLOCALIT NL ON NL.codlocalit = NA.codlocalit
    LEFT JOIN NJUDET NJ ON NJ.codjudet = NL.codjudet
    LEFT JOIN NPARTCODFISC FISC ON fisc.cod_codfiscal = i.codfiscal
    LEFT JOIN TMP_UTILIZATOR UT ON ut.codutilizator = i.userid&apos;||
    gSuplJoins||&apos;
  WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
    AND I.DATADOC &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  sSelect2 := &apos;
  SELECT
    I.CODINTR, I.TIPDOC, &apos;&apos;DA&apos;&apos; Intrari, &apos;&apos;NU&apos;&apos; Iesiri, pkg_list_base_utils.decode_tipdoc_scurt(i.tipdoc),
    I.PREFIXDOC, I.NRDOC, I.DATADOC, I.DATACREARE,
    NP.DEN_PART, FISC.CODFISCAL,
    NL.DEN_LOCALIT, NJ.DEN_JUDET,
    getadresa(na.sector, na.strada, na.nr1, na.nr2, na.bloc, na.scara, na.etaj, na.apart, na.codpostal),
    I.OBS, UT.NUME &apos;||gUserAlias||&apos;
  FROM INTRARI I
    LEFT JOIN NPART NP ON np.codpart = i.partener
    LEFT JOIN NAGENDA NA ON NA.codagenda = I.codlocatie
    LEFT JOIN NLOCALIT NL ON NL.codlocalit = NA.codlocalit
    LEFT JOIN NJUDET NJ ON NJ.codjudet = NL.codjudet
    LEFT JOIN NPARTCODFISC FISC ON fisc.cod_codfiscal = i.codfiscal
    LEFT JOIN TMP_UTILIZATOR UT ON ut.codutilizator = i.userid&apos;||
    gSuplJoins||&apos;
  WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
    AND I.DATADOC &apos;||sPer||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGINOUT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B4119B0ECC1424E32406495CD61F2AB86BBE112</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGJURNAL IS

  p_plan       NUMBER(1);
  p_LunaIni    NUMBER(5);
  p_LunaFin    NUMBER(5);
  p_SubCurenta NUMBER(1);
  p_Index      BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SetParams(
  vPlan       IN NUMBER,
  vLunaIni    IN NUMBER,
  vLunaFin    IN NUMBER,
  vSubCurenta IN NUMBER DEFAULT 0,
  v_Index     IN NUMBER DEFAULT 0,
  v_codjob1   IN NUMBER DEFAULT 0)
IS
  vDataS DATE;
  vDataF DATE;
BEGIN
  p_plan       := vPlan;
  p_LunaIni    := vLunaIni;
  p_LunaFin    := vLunaFin;
  p_SubCurenta := vSubCurenta;
  p_Index      := Coalesce(v_Index, 0) = 1;
  IF v_CodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(v_CodJob1,vDataS,vDataF,p_LunaIni,p_LunaFin);
  END IF;
END;

FUNCTION Plan RETURN NUMBER
IS
BEGIN
  RETURN p_Plan;
END;

FUNCTION  LunaIni RETURN NUMBER
IS
BEGIN
  RETURN p_LunaIni;
END;

FUNCTION  LunaFin RETURN NUMBER
IS
BEGIN
  RETURN p_LunaFin;
END;

FUNCTION  SubCurenta RETURN NUMBER
IS
BEGIN
  RETURN p_SubCurenta;
END;

FUNCTION  isIndex    RETURN BOOLEAN
IS
BEGIN
  RETURN p_Index;
END;


PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(30000);
  sJurnal   VARCHAR2(500);
  aSitV     NUMBER(1);
  aBancaV   NUMBER(20);
  aMonedaV  NUMBER(20);
  sCursRef  VARCHAR2(500)  := &apos;, 1&apos;;
  vSubunit  NUMBER(20)     := CASE p_SubCurenta WHEN 0 THEN 1 ELSE NULL END;
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  
  gSuplCols := &apos;v_jurnal j, nsubunit ns, ngest ng, centrecost c&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;         ,&apos;CPD&apos;, &apos;CPD.CODCONT = J.CONTD&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;         ,&apos;CPC&apos;, &apos;CPC.CODCONT = J.CONTC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;        ,&apos;C1D&apos;, &apos;C1D.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(J.CONTD, J.AN, J.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT1&apos;        ,&apos;C1C&apos;, &apos;C1C.CODCONT1 = PKG_PLANCONTURI.GET_CONT_COD_CARACT_LUNA(J.CONTC, J.AN, J.LUNA)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;        ,&apos;CSD&apos;, &apos;CSD.CODCONTS = C1D.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTS&apos;        ,&apos;CSC&apos;, &apos;CSC.CODCONTS = C1C.CONTSECUNDAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTT&apos;        ,&apos;CTD&apos;, &apos;CTD.CODCONTT = C1D.CONTTERTIAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONTT&apos;        ,&apos;CTC&apos;, &apos;CTC.CODCONTT = C1C.CONTTERTIAR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_UTILIZATOR&apos;,&apos;UTD&apos;, &apos;UTD.CODUTILIZATOR = PKG_LIST_BASE_UTILS.GetUserDoc(CASE WHEN j.tipdoc IN (29,30,31,33) THEN j.indexlocal ELSE j.coddoc END, j.tipdoc)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;,         &apos;NP&apos;,  &apos;NP.CODPART = pkg_list_utilfisacont.GetPartJurnal(j.codjurnal)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_UTILS.CLEAR_SIMBOL_LIPSA;
  DELETE TMP_NCONT1_BAL;
  
  IF    p_plan = 2 THEN
    sJurnal := &apos;v_jurnal_s&apos;;
    INSERT INTO TMP_NCONT1_BAL (CODCONT, SIMBOLPLANP)
    SELECT C.CODCONT, C.SIMBOL
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND pkg_list_base_regjurnal.LunaFin BETWEEN C1.ALSTART and C1.ALSTOP
    WHERE Nvl(C1.CONTSECUNDAR,0) = 0;
  ELSIF p_plan = 3 THEN
    sJurnal := &apos;v_jurnal_t&apos;;
    INSERT INTO TMP_NCONT1_BAL (CODCONT, SIMBOLPLANP)
    SELECT C.CODCONT, C.SIMBOL
    FROM NCONT C LEFT JOIN NCONT1 C1 ON C1.CODCONT = C.CODCONT AND pkg_list_base_regjurnal.LunaFin BETWEEN C1.ALSTART and C1.ALSTOP
    WHERE Nvl(C1.CONTTERTIAR,0) = 0;
  ELSE
    sJurnal := &apos;v_jurnal&apos;;
  END IF;

  IF p_plan &gt; 1 THEN
    INSERT INTO TMP_LIPSA_CORESP_PLANP (SIMBOL)
    SELECT DISTINCT t.SIMBOLPLANP
    FROM JURNAL x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.contd
    WHERE an *12 + luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
    UNION
    SELECT DISTINCT t.SIMBOLPLANP
    FROM JURNAL x INNER JOIN TMP_NCONT1_BAL t ON t.codcont = x.contc
    WHERE an *12 + luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCursRef   := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, j.datadoc )&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    NAV_CODDOC,NAV_TIPDOC, TIPINREG,
    CONTDEBIT, CONTCREDIT, SUMADEBIT, SUMACREDIT, VALOAREV, IFRS, IFRSV, GRUP, GRUPV,
    TIPDOC, DOCUMENT_JRN, EXPLICATII,
    DATADOC, GESTIUNE, ORDINE,
    SUBUNITATEA, CENTRUCOST, CENTRUCOSTSIMB, CURS_REF&apos;||gUserFields||&apos;)
  SELECT
		CASE WHEN j.tipdoc IN (32,36) then NULL else j.coddoc end, CASE WHEN j.tipdoc IN (32,36) then NULL else j.tipdoc end, j.tipinreg,
    j.SIMBCONTDEBIT, j.SIMBCONCREDIT, j.v, j.v, j.valoarev, j.valoare_ifrs, j.valoarev_ifrs, j.valoaregrup, j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),
    PKG_LIST_BASE_UTILS.DECODE_TIPDOC(J.TIPDOC), j.document, j.obs,
    CASE
      WHEN j.tipdoc IN (32,36) THEN last_day(to_date(to_char(j.an,&apos;&apos;fm0000&apos;&apos;)||to_char(j.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;))
      ELSE j.datadoc
    END, ng.den_gest, j.tipdoc + DECODE(j.tipdoc,32,100),
    ns.den_subunit, c.denumire, c.simbol &apos;||sCursRef||gUserAlias||&apos;
  FROM &apos;||sJurnal||&apos; j
    INNER JOIN nsubunit   ns ON ns.codsubunit = j.subunitatea &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; &apos;J&apos;, pSUBUNIT =&gt; vSubunit)||&apos;
		LEFT  JOIN ngest      ng on ng.codgest    = NVL(j.gest,0)
    LEFT  JOIN centrecost c  on c.codcentru   = j.CentruCost&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGJURNAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>685ED97F6D754E6E9C72514566593215835F978D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGMF is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(2000);
sSelect VARCHAR2(10000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NARTOBJ OBJ, NART ART&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Articol,
    NrInventar,
    Gestiune,
    CentruCost,
    DataPunere,
    ValIn,
    DurataN,
    RestDurata,
    DurataParcursa,
    AmoLunara,      
    AmoCumulIntr,   
    ValReev,        
    RestDurataLaReev,
    AmoLunaraReev,
    AmoCumulReev,
    ValMF,
    ValAmoLunara,
    AmoCumul,
    DataOperatie&apos;||
    gUserFields||&apos;)&apos;;

  sSelect := 
  &apos;SELECT
    OBJ.DENUMIRE Articol,
    MF.NrInventar,
    G.DEN_GEST Gestiune,
    CC.DENUMIRE CentruCost,
    DataPunere,
    ValIn,
    DurataN,
    RestDurata,
    DurataParcursa,
    AmoLunara,      
    AmoCumulIntr,   
    ValReev,        
    RestDurataLaReev,
    AmoLunaraReev,
    AmoCumulReev,
    ValMF,
    ValAmoLunara,
    AmoCumul,
    DataOperatie &apos;||gUserAlias||&apos;
  FROM MIFIX MF
       INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = MF.CODMIFIX
       INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
       INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
       INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
       INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
       INNER JOIN CENTRECONST CC ON MF1.CODCENTRU = CC.CODCENTRU
    &apos;||gSuplJoins||&apos;
  WHERE MF1.ANSTART*12+MF1.LUNASTART = (SELECT MAX(ANSTART*12+LUNASTART FROM MIFIX1 WHERE CODMIFIX = MF.CODMIFIX)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_REGMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGREEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E995D5CE71819987916445C27BCEC292D50EEB54</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REGREEV is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(2000);
sSelect VARCHAR2(10000);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NARTOBJ OBJ, NART ART&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DataReev,
    Articol,
    Cont,
    NrInventar,
    ValNetaConta,
    Tip,
    ValReev,
    RezReev,
    ReevAnte,
    ValDinRez,
    Jurnal,
    ValChelt,
    JurnalChel,
    ValVenit,
    JurnalVenit &apos;||
    gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    F.DATAOPERATIE DataReev,
    OBJ.DENUMIRE Articol,
    C.SIMBOL Cont,
    MFIX.NrInventar,
    0 ValNetaConta,
    CASE 
      WHEN F.CODOPERATIE = 6 THEN &apos;&apos;Reevaluare - valoare MF&apos;&apos;
      WHEN F.CODOPERATIE = 7 THEN &apos;&apos;Reevaluare - amortizare prec&apos;&apos;
    END Tip,
    0 ValReev,
    0 RezReev,
    0 ReevAnte,
    0 ValDinRez,
    &apos;&apos;&apos;&apos; Jurnal,
    0 ValChelt,
    &apos;&apos;&apos;&apos; JurnalChel,
    0 ValVenit,
    &apos;&apos;&apos;&apos; JurnalVenit&apos;||
    gUserAlias||&apos;
  FROM FISAMF F
       INNER JOIN MIFIX   MFIX ON MFIX.CODMIFIX  = F.CODMIFIX
       INNER JOIN TRANSF1 T1   ON F.CODDOC1      = T1.CODTRANSF1
       INNER JOIN TRANSF  T    ON T.CODTRANSF    = T1.CODTRANSF  AND F.TIPDOC = T.TIPDOC
       INNER JOIN NIR          ON NIR.CODTRANSF  = T.CODTRANSF
       INNER JOIN NIRSTOC NS   ON NS.CODNIR      = NIR.CODNIR    AND NS.CODTRANSF1 = T1.CODTRANSF1
       INNER JOIN IOART1  IOA1 ON NS.CODIOART    = IOA1.CODIOART AND (T.AN*12+T.LUNA) BETWEEN IOA1.ALStart and IOA1.ALStop
       INNER JOIN NARTOBJ OBJ  ON OBJ.CODOBIECT  = NS.CODOBIECT
       INNER JOIN NART    ART  ON OBJ.CODARTICOL = ART.CODARTICOL
       INNER JOIN NCONT   C    ON C.CODCONT      = IOA1.CONT
       &apos;||gSuplJoins||&apos;
  WHERE F.CODOPERATIE in (6,7) 
        &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;,&apos;SUBUNITATEA&apos;);

  --delete x;
  --insert into x(test) values(sselect);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_REGREEV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGULARIZPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83E280045F9DE7A0FAD6C494AFEFDE6C273CEDCA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_regularizpart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert        VARCHAR2(30000);
  sFiltru        VARCHAR2(  500);
  pCFavorabilV   NUMBER(20) := Nvl(pkg_categconst.GetValConstanta(&apos;CFavorabilV&apos;   ,pkg_globals.ANLUCRU, pkg_globals.lunalucru),0) ;
  pCNefavorabilV NUMBER(20) := Nvl(pkg_categconst.GetValConstanta(&apos;CNefavorabilV&apos; ,pkg_globals.ANLUCRU, pkg_globals.lunalucru),0) ;
BEGIN
  gSuplCols := &apos;npart p, nbank b, nmonede m, ncont c, ncont cdif&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;r.TipReg = 46&apos;;
  IF PKG_LIST_SELECTLUNAAN.LunaStart = PKG_LIST_SELECTLUNAAN.LunaStop THEN
    sFiltru := sFiltru||&apos;
      AND r.an * 12 + r.luna = &apos;||PKG_LIST_SELECTLUNAAN.LunaStart;
  ELSE
    sFiltru := sFiltru||&apos;
      AND r.an * 12 + r.luna BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (Nr, Data, Moneda, Curs, Part, Cont, Doc, SoldV, SoldL, SoldReg, Dif, CursVechi, Sub, Gest&apos;||gUserFields||&apos;)
  WITH
  G AS (
    SELECT codsubunit, Max(den_gest) KEEP (Dense_Rank first ORDER BY Nvl(gmaster,0) desc, codgest) den_gest
    FROM ngest
    GROUP BY codsubunit
  ),
  R AS (
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      i.partener, i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(i.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, i.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN intrari i ON i.codintr = g.coddoc AND i.tipdoc = g.tipdoc
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie IN (100, 110, 120, 140)
    UNION ALL
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      i.partener, &apos;&apos;DVI&apos;&apos;||dvi.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(dvi.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, i.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN dvi ON dvi.coddvi = g.coddoc
      INNER JOIN intrari i ON i.codintr = dvi.codintr
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie IN (130)
    UNION ALL
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      i.partener, i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(i.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, i.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN iesiri i ON i.codies = g.coddoc AND i.tipdoc = g.tipdoc
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie IN (200, 210, 220, 240)
    UNION ALL
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      t1.codpart partener, t1.Doc||t1.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(t1.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, t.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN trezor1 t1 ON t1.codtrezor1 = g.coddoc
      INNER JOIN trezor t ON t.codtrezor = t1.codtrezor
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie IN (310, 410, 330, 430)
    UNION ALL
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      nc.part partener, &apos;&apos;NC&apos;&apos;||nc.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(nc.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, nc.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN nc1 ON nc1.codnc1 = g.coddoc
      INNER JOIN nc ON nc.codnc = nc1.codnc
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie IN (1200, 1201)
    UNION ALL
    SELECT
      r.Nrdoc, r.DataDoc, r.codbank, r.codmoneda, r.Curs, r.an, r.luna,
      r1.SoldDocVal, r1.SoldDoc, r1.SoldDocReg, r1.cont, r1.semnificatie,
      i.partener, &apos;&apos;Litigiu &apos;&apos;||i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||To_Char(i.DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, i.subunitatea
    FROM reg1 r1
      INNER JOIN reg r ON r.codreg = r1.codreg
      INNER JOIN general g ON g.codgeneral = r1.codgeneral
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN (
        SELECT CONNECT_BY_ROOT CODOBLIGPIF ROOTCODOBLIGPIF, CODOBLIGPIF, CODGENERAL, ICONT
        FROM OBLIGPIF
        WHERE Nvl(CODOBLIGASOCIAT,0) = 0
        START WITH semnificatie = 1303
        CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
      ) ol ON ol.rootcodobligpif = o.codobligpif
      INNER JOIN general gl ON gl.codgeneral = ol.codgeneral AND gl.tipdoc IN (19,21,22,26)
      INNER JOIN iesiri i ON i.codies = gl.coddoc AND i.tipdoc = gl.tipdoc
    WHERE &apos;||sFiltru||&apos;
      AND r1.semnificatie = 1303
  )
  SELECT
    r.NrDoc, r.dataDoc, m.Simbol SMon, r.Curs,
    p.Den_Part, c.simbol cont, r.Document,
    r.SoldDoc, r.SoldDocVal, r.SoldDocReg, r.SoldDocReg - r.SoldDocVal, r.SoldDocVal / r.SoldDoc ,
    s.den_subunit, g.den_gest &apos;||gUserAlias||&apos;
  FROM R
    LEFT JOIN npart p ON p.codpart = r.partener
    LEFT JOIN nmonede m ON m.codmoneda = r.codmoneda
    LEFT JOIN nsubunit s ON s.codsubunit = r.subunitatea
    LEFT JOIN g ON g.codsubunit = r.subunitatea
    LEFT JOIN ncont c ON c.codcont = PKG_LIST_BASE_UTILS.icont_CodCont(r.cont,r.partener,r.an*12+r.luna,r.semnificatie)
    LEFT JOIN ncont cdif ON cdif.codcont = CASE WHEN r.SoldDocReg - r.SoldDocVal &lt; 0 THEN &apos;||pCNefavorabilV||&apos; ELSE &apos;||pCFavorabilV||&apos; END&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGULARIZPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REGULARIZTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>772ACE4467D304EAFEE0DC858624A47D3147236B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_regulariztrez IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  An       NUMBER(4);
  Luna     NUMBER(2);
  AnPrec   NUMBER(4);
  LunaPrec NUMBER(2);
BEGIN
  gSuplCols := &apos;npart p, nbank b, nmonede m, nbankcont bc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  Luna  := mod(PKG_LIST_SELECTLUNAAN.LunaStart,12);
  IF Luna = 0 THEN Luna := 12; END IF;
  An    := (PKG_LIST_SELECTLUNAAN.LunaStart - Luna) /12;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (Nr, Data, Moneda, Curs, Banca, DenCont, NrCont, SoldV, SoldL, SoldReg, Dif, CursVechi, Sub, Gest, An, Luna&apos;||gUserFields||&apos;)
  SELECT
    r.NrDoc, r.dataDoc, m.Simbol, r.Curs, b.Denumire, bc.Den_Cont, bc.NrCont,
    t1.SoldValuta, t1.SoldLei, t1.SoldValuta * r.Curs, t1.SoldValuta * r.Curs - t1.SoldLei,
    CASE WHEN Nvl(t1.SoldValuta,0) = 0 THEN 0 ELSE t1.SoldLei / t1.SoldValuta END,
    s.den_subunit, g.den_gest, r.an, r.luna&apos;||gUserAlias||&apos;
  FROM REG R
    INNER JOIN nmonede m ON m.codmoneda = r.codmoneda
    INNER JOIN nbankcont bc ON bc.CodMoneda = R.CodMoneda and coalesce(bc.farareg,0) = 0
    INNER JOIN nbank b ON b.CodBank = bc.CodBank
    INNER JOIN v_solduribanciluna t1 ON t1.CodBankCont = bc.CodBankCont
    LEFT JOIN nsubunit s ON s.codsubunit = bc.subunitatea
    LEFT JOIN jurnal1 j1 ON j1.tipdoc = r.tipreg AND j1.coddoc = r.codreg AND j1.codbazad = bc.CodBankCont
    LEFT JOIN ngest g ON g.codgest = j1.gest&apos;||
    gSuplJoins||&apos;
  WHERE R.TipReg = 45
    AND r.an = :AN AND r.luna = :LUNA
    AND	T1.SoldValuta * R.Curs - T1.SoldLei &lt;&gt; 0 &apos;;


  WHILE An*12+Luna&lt;= PKG_LIST_SELECTLUNAAN.LunaStop
  LOOP
	  PKG_GLOBALS.SETLUNATEMP(An, Luna);
	  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(An, Luna, AnPrec, LunaPrec);
	  PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrec, LunaPrec);
    EXECUTE IMMEDIATE sInsert USING An, Luna;
    COMMIT; --PROBLEME DUBIOASE LA BUCEPHALUS NU APARE NIMIC IN LISTA DACA NU PUN COMMIT AICI
    IF Luna = 12 THEN An := An + 1; Luna := 1; ELSE Luna := Luna + 1; END IF;
  END LOOP

  COMMIT;

END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_REGULARIZTREZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RESTLISTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5960FE43A7955FCF3AF7C599F8871FACBAFE030</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_restlistgest is


  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(aCODGEST IN NUMBER, aCODRESTCMD IN NUMBER, aID IN NUMBER, aVER IN NUMBER ) IS
BEGIN
  CODGEST    := aCodGest;
  CODRESTCMD := aCodRestCmd;
  ID         := aID;
  VER        := aVer;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  S VARCHAR2(4000);
BEGIN
  gSuplCols := &apos;RESTCMD1 R1, NARTOBJ O, NART A, NUM1 U1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(DENUMIRE, DENUM, CANT, OBS, ORDINE &apos;||gUserFields||&apos;) &apos; || CHR(13) ||
 &apos; SELECT &apos;         ||  CHR(13) ||
 &apos;   O.DENUMIRE, &apos;  ||  CHR(13) ||
 &apos;   U1.DEN_UM1, &apos;  ||  CHR(13) ||
 &apos;   R1.CANT, &apos;     ||  CHR(13) ||
 &apos;   R1.OBS, &apos;      ||  CHR(13) ||
 &apos;   R1.ORDINE &apos;    ||  CHR(13) ||gUserAlias||
 &apos; FROM &apos;           ||  CHR(13) ||
 &apos;  RESTCMD1 R1                                     &apos;||  CHR(13) ||
 &apos;  JOIN  NARTOBJ O ON O.CODOBIECT = R1.CODOBIECT   &apos;||  CHR(13) ||
 &apos;  JOIN NART A ON A.CODARTICOL = O.CODARTICOL      &apos;||  CHR(13) ||
 &apos;  JOIN NUM1 U1 ON U1.CODUM = A.UM                 &apos;||  CHR(13) || 
    gSuplJoins ||
 &apos; WHERE &apos;           ||  CHR(13) ||
 &apos;   R1.CODRESTCMD = &apos;  || TO_CHAR  (CODRESTCMD)  ||  CHR(13) ||
 &apos;   AND R1.CODGEST = &apos; || TO_CHAR (CODGEST)      ||  CHR(13) ||
 &apos;   AND NVL(R1.LISTAREGEST, 0) = 0 &apos; ||  CHR(13) ||
 &apos;   AND U1.SECUNDARA = 0&apos;;
  LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 COMMIT;

END;

PROCEDURE PROCESSLISTCFG(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
S VARCHAR2(4000);
BEGIN
  gSuplCols := &apos;RESTCMD1 R1, NARTOBJ O, NART A, NUM1 U1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(DENUMIRE, DENUM, CANT, OBS, ORDINE) &apos; || CHR(13) ||
  &apos;VALUES (&apos;&apos;ARTICOL CONFIGURARE&apos;&apos;,&apos;&apos;Buc&apos;&apos;, 10, &apos;&apos;Observatie&apos;&apos;, 1)&apos;;

 LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 COMMIT;

END;

PROCEDURE PROCESSLISTDIF(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
S VARCHAR2(4000);
BEGIN
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(DENUMIRE, DENUM, CANT, OBS, ORDINE) &apos; || CHR(13) ||
 &apos; SELECT &apos;      ||  CHR(13) ||
 &apos;   M.DENUMIRE, &apos; ||  CHR(13) ||
 &apos;   M.DUM, &apos;      ||  CHR(13) ||
 &apos;   M.CANTNOUA - M.CANT, &apos; ||  CHR(13) ||
 &apos;   M.OBS, &apos;       ||  CHR(13) ||
 &apos;   R.ORDINE &apos;       ||  CHR(13) ||
 &apos; FROM &apos;        ||  CHR(13) ||
 &apos;   TMP_MODIRESTCMD1 M INNER JOIN RESTCMD1 R ON R.CODRESTCMD1 = M.CODRESTCMD1&apos;;

 LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RESTLISTGEST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RESTLISTNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>325536D174B8D62E7E7A4104BCDD23AA0C727E4B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_restlistnp is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(aCODRESTNP IN NUMBER, aID IN NUMBER, aVER IN NUMBER ) IS
BEGIN
  CODNP     := aCodRestNP;
  ID         := aID;
  VER        := aVer;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
S VARCHAR2(4000);
BEGIN
  gSuplCols := &apos;RESTNP1 R1, RESTNP R, RESTCMD RCMD, NARTOBJ O, NART A, NUM1 U1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(DENUMIRE, DENUM, CANT, PRET, DISCOUNT, VALDISCOUNT&apos;||gUserFields||&apos;) &apos; || CHR(13) ||
 &apos; SELECT &apos;         ||  CHR(13) ||
 &apos;   O.DENUMIRE, &apos;  ||  CHR(13) ||
 &apos;   U1.DEN_UM1, &apos;  ||  CHR(13) ||
 &apos;   R1.CANT, &apos;     ||  CHR(13) ||
 &apos;   R1.PRET, &apos;     ||  CHR(13) ||
 &apos;   ABS(R1.DISCOUNT),&apos;   ||  CHR(13) ||
 &apos;   R1.PRET * R1.CANT * ABS(NVL(R1.DISCOUNT, 0)) / 100 &apos;||gUserAlias||CHR(13) ||
 &apos; FROM &apos;           ||  CHR(13) ||
 &apos;   RESTNP1 R1 &apos;  ||  CHR(13) ||
 &apos;   INNER JOIN RESTNP R ON R1.CODRESTNP = R.CODRESTNP&apos;  ||CHR(13) ||
 &apos;   INNER JOIN NARTOBJ O ON O.CODOBIECT = R1.CODOBIECT&apos; ||  CHR(13) ||
 &apos;   INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL&apos;   ||  CHR(13) ||
 &apos;   INNER JOIN NUM1 U1 ON U1.CODUM = A.UM AND U1.SECUNDARA = 0&apos;  ||  CHR(13) ||
 &apos;   LEFT JOIN RESTCMD RCMD ON RCMD.CODRESTCMD = R.CODRESTCMD &apos;  ||  CHR(13) ||
 gSuplJoins||
 &apos;WHERE &apos;           ||  CHR(13) ||
 &apos;   R1.CODRESTNP = &apos;  || TO_CHAR  (CODNP);
 
 LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 COMMIT;
END;


end PKG_LIST_BASE_RESTLISTNP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RESTSITLISTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F16387DAC71132FA9C93F92726040E0525DEFA8B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RESTSITLISTGEST IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(
	aCODRESTAURANT IN NUMBER, 
	aDATASTART IN VARCHAR2, 
	aDATAEND IN VARCHAR2, 
	aID IN NUMBER, 
	aVER IN NUMBER,
	pCodJob1     IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  DATASTART     := aDATASTART;
  DATAEND       := aDATAEND;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,DATASTART,DATAEND,xLunaAnIni,xLunaAnFin);
  END IF;
  CODRESTAURANT := aCODRESTAURANT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
S VARCHAR2(4000);
BEGIN
  gSuplCols := &apos;RESTLISTGEST lg, RESTCMD1 rc1, RESTCMD rc, NARTOBJ obj, MESE m, SALI s,  NGEST ng, OSPATARI osp, NPERS prs&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(den_obj, cant, observatii, den_gest, dataora, ospatar, nr_comanda, masa, sala&apos;||gUserFields||&apos;) &apos; || CHR(13) ||
  &apos;SELECT &apos;                                                    ||  CHR(13) ||
  &apos;  obj.denumire as den_obj, &apos;                                ||  CHR(13) ||
  &apos;  lg.cant as cant, &apos;                                        ||  CHR(13) ||
  &apos;  lg.obs as observatii, &apos;                                   ||  CHR(13) ||
  &apos;  ng.den_gest as den_gest, &apos;                                ||  CHR(13) ||
  &apos;  lg.dataora as dataora, &apos;                                  ||  CHR(13) ||
  &apos;  prs.NUME || &apos;&apos; &apos;&apos; ||  prs.PRENUME AS OSPATAR, &apos;           ||  CHR(13) ||
  &apos;  rc.nrcomanda as nr_comanda, &apos;                             ||  CHR(13) ||
  &apos;  coalesce(m.textafisare,to_char(m.indexlocal)) as masa, &apos;  ||  CHR(13) ||
  &apos;  s.denumire as sala  &apos; ||gUserAlias                        ||CHR(13)||
  &apos;FROM &apos;                                                      ||  CHR(13) ||
  &apos;  RESTLISTGEST lg&apos;                                          ||  CHR(13) ||
  &apos;  join RESTCMD1 rc1 on lg.codrestcmd1 = rc1.codrestcmd1 &apos;   ||  CHR(13) ||
  &apos;  join RESTCMD rc on rc.codrestcmd = rc1.codrestcmd&apos;        ||  CHR(13) ||
  &apos;  join NARTOBJ obj on obj.codobiect = rc1.codobiect&apos;        ||  CHR(13) ||
  &apos;  join MESE m on m.codmasa = rc.codmasa&apos;                    ||  CHR(13) ||
  &apos;  join SALI s ON s.codsala      = m.codsala&apos;                ||  CHR(13) ||
  &apos;  left join NGEST ng on ng.codgest = rc1.codgest&apos;           ||  CHR(13) ||
  &apos;  left join OSPATARI osp on osp.cod = rc.codospatar&apos;        ||  CHR(13) ||
  &apos;  left join NPERS prs on prs.codpers = osp.codpers&apos;         ||  CHR(13) ||  gSuplJoins  ||  CHR(13) ||
  &apos;WHERE &apos;                                                                                 ||  CHR(13) ||
  &apos;  lg.dataora     &gt;= TO_DATE(&apos;&apos;&apos; || DATASTART || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
  &apos;  AND lg.dataora     &lt;= TO_DATE(&apos;&apos;&apos; || DATAEND   || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
  &apos;  AND S.CODRESTAURANT = &apos; || TO_CHAR(NVL(CODRESTAURANT, 0));

  LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_RESTSITLISTGEST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REZDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>725133D54B97A1AF41886231BD23D8620B079D16</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REZDOC is

  vCodComanda COMANDA.CODCOMANDA%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCodComanda IN NUMBER) IS
BEGIN
  vCodComanda := pCodComanda;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;TMP_REZERVARI_COMANDA T&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    PRODUS, UMPRODUS, TERMEN, CANTACCEPTAT, COMPONENT, GESTIUNE, TIPCONTABIL, UMCOMPONENT, NECESAR, REZSTOC, CERFURN, NESOSIT, NEACOPERIT&apos;||
    gUserFields||&apos;)
  SELECT
    T.PRODUS, T.UMPRODUS, T.TERMEN, T.CANTACCEPTAT, T.COMPONENT, T.GESTIUNE, T.TIPCONTABIL, T.UMCOMPONENT, T.NECESAR, T.REZSTOC, T.CERFURN, T.NESOSIT, T.NEACOPERIT&apos;||
    gUserAlias||&apos;
  FROM TMP_REZERVARI_COMANDA T&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

end pkg_list_base_rezdoc;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_REZMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>327E7AD5E4DF66CDC5FC041EAE8A3AF7EB56D9FE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_REZMF IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pCod IN NUMBER) IS
BEGIN
  vCod := pCod;
END;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;MF1&apos;);

  gSuplCols :=
    &apos;MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NIRSER  NSER, NSERII  SER&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert :=
  &apos; INSERT INTO &apos;||tmpName||&apos;(
    NrInventar, SerieInv, AnIntrare, LunaIntrare, Amo, DurataF, Neutil,
    Gradu, TipAmo, Stare, Cant, Serie, Responsabil, DenLoc &apos;||gUserFields||&apos;)
    SELECT
        MF.NRINVENTAR,
        MF.SERIEINV,
        MF.ANINTRARE,
        MF.LUNAINTRARE,
        MF1.AMO,
        MF1.DURATAF,
        MF1.NEUTIL,
        MF1.GRADU,
        CASE MF1.TIPAMO 
          when 1 then &apos;&apos;Liniara&apos;&apos; 
          when 2 then &apos;&apos;Accelerata&apos;&apos;
          when 3 then &apos;&apos;Degresiva 1&apos;&apos;
          when 4 then &apos;&apos;Degresiva 2&apos;&apos;
          else &apos;&apos;&apos;&apos; end as TIPAMO ,
        CASE MF1.STARE 
          when 1 then &apos;&apos;in Curs de amortizare&apos;&apos; 
          when 2 then &apos;&apos;Trecut in conservare&apos;&apos;
          when 3 then &apos;&apos;Casat in luna curenta&apos;&apos;
          when 4 then &apos;&apos;Vandut in luna curenta&apos;&apos;
          else &apos;&apos;&apos;&apos; end as STARE ,
        MF1.CANT,
        SER.SERIE,
        PRS.NUME || &apos;&apos; &apos;&apos; || PRS.PRENUME AS RESPONSABIL,
        LOC.DENUMIRE AS DENLOC &apos;||gUserAlias||&apos;
      FROM
        MIFIX MF
        INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = MF.CODMIFIX
        INNER JOIN NIRSTOC  NS   ON NS.CODNIRSTOC  = MF1.CODNIRSTOC
        INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
        LEFT OUTER JOIN NIRSER   NSER ON NSER.CODNIRSER = MF1.CODNIRSER
        LEFT OUTER JOIN NSERII   SER  ON SER.CODSERIE   = NSER.CODSERIE
        LEFT OUTER JOIN NPERS    PRS  ON PRS.CODPERS    = MF1.CODPERS
        LEFT OUTER JOIN NLOCATII LOC  ON LOC.CODLOCATIE = NS.CODLOCATIE &apos;||gSuplJoins||&apos;
      WHERE
        MF1.CODNIRSTOC = &apos;||vCod||&apos; AND
        MF1.ANSTART * 12 + MF1.LUNASTART = &apos;||to_char(PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  pkg_list_Struct.GOLESTE_PARAM;

  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


end PKG_LIST_BASE_REZMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_RPTVANZUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0876003A0B7E8E53A9984E2732746CD6EB307BA8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_RPTVANZUM IS

  gCodUm number(20);

PROCEDURE SETPARAMS(aCodUM in number) is
begin
  gCodUm := aCodUm;
end;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) is
  sInsert varchar2(5000);
  filtre varchar2(200);
BEGIN
  filtre := &apos; AND IES.AN*12+IES.LUNA = PKG_GLOBALS.ANLUNALUCRU AND NUM.CODUM = &apos;||gCodUm||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;IES&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos; (MEASURE,EXPLICATIE,CANTITATEA,ANLUNA,NIVEL)
  SELECT
    CASE
      WHEN NIVEL = 1 THEN &apos;&apos;M1_VBA00R&apos;&apos;
      WHEN NIVEL = 2 THEN &apos;&apos;M1_LTK001&apos;&apos;
      WHEN NIVEL = 3 THEN &apos;&apos;M1_LT0001&apos;&apos;
    END MEASURE,
    CASE
      WHEN NIVEL = 1 THEN &apos;&apos;VANZARI IN BUCATI&apos;&apos;
      WHEN NIVEL = 2 THEN &apos;&apos;VANZARI IN TONE&apos;&apos;
      WHEN NIVEL = 3 THEN &apos;&apos;VANZARI IN LITRI&apos;&apos;
    END EXPLICATIE,
    CASE
      WHEN NIVEL = 1 THEN A.CANTITATE
      WHEN NIVEL = 2 THEN A.MASA
      WHEN NIVEL = 3 THEN A.VOLUM
    END CANTITATEA,
    TO_CHAR(A.AN)||CASE WHEN A.LUNA &lt; 10 THEN &apos;&apos;0&apos;&apos;||TO_CHAR(A.LUNA) ELSE TO_CHAR(A.LUNA) END ANLUNA, X.NIVEL
  FROM (
    SELECT
      SUM(IES1.CANT) Cantitate , SUM(IES1.CANT * NVL(NOBJ.VOLUM,0))/1000 VOLUM,
      SUM(IES1.CANT * NVL(NOBJ.MASA,0)) MASA, IES.AN , IES.LUNA
    FROM IESIRI1 IES1
      INNER JOIN NUM1 ON IES1.UMSEC = NUM1.CODUM1
      INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = IES1.CODOBIECT
      INNER JOIN IESIRI IES ON IES.CODIES = IES1.CODIES
      INNER JOIN NUM ON NUM1.CODUM = NUM.CODUM
    WHERE IES.TIPDOC IN (19,21,22,26) AND IES.OPERAT = 1 &apos;||filtre||&apos;
    GROUP BY IES.AN,IES.LUNA
  ) A, (SELECT LEVEL NIVEL FROM DUAL CONNECT BY LEVEL &lt;=3) X  &apos;;


  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  commit;

END;

PROCEDURE setJoinuri IS
BEGIN
  NULL;
END;

end PKG_LIST_BASE_RPTVANZUM;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SCADCHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69DDF31B7188965D58C3BD82DD610B4429F2B799</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SCADCHELTAVANS IS

  vNrLuni     NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  s     VARCHAR2(20);
  vAn   NUMBER(4) := PKG_GLOBALS.GETANLUCRU ;
  vLuna NUMBER(2) := PKG_GLOBALS.GETLUNALUCRU;
BEGIN
  SELECT Coalesce(Max(CASE WHEN C.DATASTART IS NOT NULL AND C.DATAEND IS NOT NULL THEN (EXTRACT(YEAR FROM C.DATAEND)*12+EXTRACT(MONTH FROM C.DATAEND))-(C1.ANSTART*12+C1.LUNASTART)+1 ELSE Coalesce(C1.DURATAF,0) END), 0)
  INTO vNrLuni
  FROM CHELTAVANS1 C1 INNER JOIN CHELTAVANS C ON C.CODCHELTAVANS = C1.CODCHELTAVANS
  WHERE C1.ANSTART = PKG_GLOBALS.GETANLUCRU AND C1.LUNASTART = PKG_GLOBALS.GETLUNALUCRU;

  FOR i IN 1..vNrLuni LOOP
    S := to_char(vLuna,&apos;fm00&apos;)||&apos;.&apos;||to_char(vAn,&apos;fm0000&apos;);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;D&apos;||To_Char(i,&apos;fm999&apos;), &apos;Amo.&apos;||S, i);
    vLuna := vLuna + 1;
    IF vLuna &gt; 12 THEN
      vAn   := vAn + 1;
      vLuna := 1;
    END IF;
  END LOOP;
END;

PROCEDURE PROCESSLIST (tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2( 5000);
  sSelect    VARCHAR2(25000);
  sXDinSel   VARCHAR2(25000);
  sDinSel    VARCHAR2(10000);
  sDinIns    VARCHAR2(10000);
  sDataStart VARCHAR2(   10):= To_Char(PKG_GLOBALS.GETANLUCRU,&apos;fm0000&apos;)||To_Char(PKG_GLOBALS.GETLUNALUCRU,&apos;fm00&apos;)||&apos;01&apos; ;
  vAL        NUMBER(5)      := PKG_GLOBALS.ANLUNALUCRU ;
  vAn        NUMBER(4)      := PKG_GLOBALS.GETANLUCRU ;
  vLuna      NUMBER(2)      := PKG_GLOBALS.GETLUNALUCRU;
BEGIN
  gSuplCols := &apos;CHELTAVANS CAV, CHELTAVANS1 CAV1, NPART P, NGEST G, IOART IOA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  FOR vRec IN (
    SELECT FieldName , IndexLocal
    FROM tmp_dinamic_cols
    WHERE FieldName LIKE &apos;D%&apos; AND Coalesce (IndexLocal, 0) &gt; 0
    ORDER BY IndexLocal
  ) LOOP
    sDinIns  := sDinIns ||&apos;,&apos;||vRec.FieldName;
    sDinSel  := sDinSel ||&apos;,T.&apos;||vRec.FieldName;
    sXDinSel := sXDinSel||&apos;,Sum(Case WHEN AL =&apos;||To_Char(vAl + vRec.IndexLocal - 1)||&apos; THEN AMOL ELSE 0 END ) &apos;||vRec.FieldName;
  END LOOP;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    TIP, ART,
    NRDOC, DATADOC, GEST, PART, OBS, IOART,
    VALOARE, ANINCEPUT, LUNAINCEPUT, AMO, REST,
    DURATAN, DURATAF&apos;||
    sDinIns||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH T AS (
    SELECT CODCHELTAVANS1&apos;||sXDinSel||&apos;
    FROM (
      SELECT
        cav1.CODCHELTAVANS1, xAl.AL,
        CASE
          WHEN CAV.DATASTART IS NOT NULL AND CAV.DATAEND IS NOT NULL AND CAV.DATAEND   &lt; xAl.DATASTART THEN 0
          WHEN CAV.DATASTART IS NOT NULL AND CAV.DATAEND IS NOT NULL AND CAV.DATASTART &gt; xAl.DATAEND   THEN 0
          WHEN CAV.DATASTART IS NOT NULL AND CAV.DATAEND IS NOT NULL THEN (CAV1.VALOARE - Coalesce(CAV1.AMO,0))/(CAV.DATAEND - GREATEST(xAl.DATASTART, CAV.DATASTART) + 1)*(LEAST(xAl.DATAEND, CAV.DATAEND) - GREATEST(xAl.DATASTART, CAV.DATASTART))
          WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT &gt; xAL.AL THEN 0
          WHEN Coalesce(CAV1.DURATAF,0) = 0 THEN 0
          WHEN CAV.ANINCEPUT*12+CAV.LUNAINCEPUT+CAV1.DURATAF &lt;= xAL.AL THEN 0
          ELSE (CAV1.VALOARE - Coalesce(CAV1.AMO,0)) / CAV1.DURATAF
        END AMOL
      FROM CHELTAVANS1 CAV1
        INNER JOIN CHELTAVANS CAV ON CAV.CODCHELTAVANS = CAV1.CODCHELTAVANS
        CROSS JOIN (
          SELECT EXTRACT(YEAR FROM DATASTART)*12+EXTRACT(MONTH FROM DATASTART) AL, DATASTART, Last_Day(DATASTART) DATAEND
          FROM (
            SELECT Add_Months(To_Date(&apos;&apos;&apos;||sDataStart||&apos;&apos;&apos;,&apos;&apos;yyyymmdd&apos;&apos;),LEVEL-1) DATASTART
            FROM DUAL
            CONNECT BY LEVEL &lt;= &apos;||vNrLuni||&apos;
          )
        ) xAL
      WHERE CAV1.ANSTART = &apos;||vAn||&apos; AND CAV1.LUNASTART = &apos;||vLuna||&apos;
    )
    GROUP BY CODCHELTAVANS1
  )
  SELECT
    CASE WHEN Coalesce(CAV.IsVenit, 0) = 1 THEN &apos;&apos;VENIT&apos;&apos; ELSE &apos;&apos;CHELTUIALA&apos;&apos; END Tip,
    CASE
      WHEN i.codintr  IS NOT NULL THEN OBJ.DENUMIRE
      WHEN ies.codies IS NOT NULL THEN OBJ.DENUMIRE
      WHEN n.codnc    IS NOT NULL THEN &apos;&apos;Chelt Avans din NC &apos;&apos;
      WHEN o.semnificatie = 900   THEN &apos;&apos;Direct pe cheltuieli(TVA)&apos;&apos;
      WHEN o.semnificatie = 950   THEN &apos;&apos;Datorii, taxe, impozite&apos;&apos;
      WHEN o.semnificatie = 901   THEN &apos;&apos;Direct pe venituri(TVA)&apos;&apos;
      WHEN o.semnificatie = 951   THEN &apos;&apos;Imprumuturi, subventii&apos;&apos;
      ELSE NULL
    END DENUMIRE,
    COALESCE(I.NRDOC, IES.NRDOC, N.NRDOC, T1.NRDOC) NRDOC, COALESCE(I.DATADOC, IES.DATADOC, N.DATADOC, T1.DATADOC) DATADOC, G.DEN_GEST, P.DEN_PART, COALESCE(I1.OBS, IES1.OBS, N1.OBS, T1.OBS) OBS, IOA.DEN_IOART,
    CAV1.VALOARE, CAV.ANINCEPUT, CAV.LUNAINCEPUT, Coalesce(CAV1.AMO,0) AMO, (CAV1.VALOARE - Coalesce(CAV1.AMO,0)) REST,
    CASE WHEN CAV.DATASTART IS NOT NULL AND CAV.DATAEND IS NOT NULL THEN MONTHS_BETWEEN(CAV.DATASTART,CAV.DATAEND) + 1 ELSE Coalesce(CAV1.DURATAN,0) END DURATAN,
    CASE WHEN CAV.DATASTART IS NOT NULL AND CAV.DATAEND IS NOT NULL THEN (EXTRACT(YEAR FROM CAV.DATAEND) * 12 + EXTRACT(MONTH FROM CAV.DATAEND)) - (CAV1.ANSTART * 12 + CAV1.LUNASTART) + 1 ELSE Coalesce(CAV1.DURATAF,0) END DURATAF&apos;||
    sDinSel||gUserAlias||&apos;
  FROM T
    INNER JOIN CHELTAVANS1 CAV1 ON CAV1.CODCHELTAVANS1 = T.CODCHELTAVANS1
    INNER JOIN CHELTAVANS CAV ON CAV.CODCHELTAVANS = CAV1.CODCHELTAVANS
    LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = CAV.CODINTR1
    LEFT JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    LEFT JOIN IESIRI1 IES1 ON IES1.CODIES1 = CAV.CODIES1
    LEFT JOIN IESIRI IES ON IES.CODIES = IES1.CODIES
    LEFT JOIN NC1 N1 ON N1.CODNC1 = CAV.CODNC1
    LEFT JOIN NC N ON N.CODNC = N1.CODNC
    LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = CAV.CODOBLIGPIF AND O.SEMNIFICATIE IN (900, 950, 901, 951)
    LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
    LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
    LEFT JOIN NPART P ON P.CODPART = COALESCE(IES.PARTENER, I.PARTENER, N.PART, O.CODPART)
    LEFT JOIN IOART IOA ON IOA.CODIOART = Coalesce(CAV.CODIOART,0)
    LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = Coalesce(IES1.CODOBIECT, I1.CODOBIECT)&apos;||
    gSuplJoins;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;


PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SCADCHELTAVANS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89284AD021D9120A4630410B1F2F76781C0F8EB0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SCADENTARCL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  sConv       VARCHAR2(100);

FUNCTION GetJoinFiltru RETURN CLOB IS
  sJoinFiltru CLOB := &apos;&apos;;
BEGIN
  IF NOT PKG_LIST_SELECTSCADENTAR.ToateClasele THEN
    sJoinFiltru := sJoinFiltru||&apos;
    INNER JOIN npart p ON p.codpart = o.codpart
    INNER JOIN TMP_MANEVRA_LISTE tmpc ON Coalesce(p.codclasa,0) = tmpc.valoare AND tmpc.filtru = &apos;&apos;CODCLASEP&apos;&apos; &apos;;
  END IF;

  IF NOT PKG_LIST_SELECTSCADENTAR.TotiPart THEN
    sJoinFiltru := sJoinFiltru||&apos;
    INNER JOIN TMP_MANEVRA_LISTE tmpp ON o.codpart = tmpp.valoare AND tmpp.filtru = &apos;&apos;CODPART&apos;&apos; &apos;;
  END IF;
  RETURN sJoinFiltru;
END;

FUNCTION  CalcAdaosDoc( pCodDoc IN NUMBER,
                        pRest   IN NUMBER)
          RETURN NUMBER
IS
  vTipDoc NUMBER;
  vValDoc NUMBER;
  vAdaos  NUMBER;
  vCurs   NUMBER;
BEGIN
  IF Coalesce(pRest,0) = 0 THEN
    RETURN 0;
  END IF;

  SELECT tipdoc,  valdoc,  COALESCE(NullIf(curs,0), 1)
  INTO   vTipDoc, vValDoc, vCurs
  FROM   iesiri i
  WHERE  i.codies = pCodDoc;

  IF vTipDoc IS NULL THEN
    RETURN 0;
  ELSIF vTipDoc = 26 THEN
    SELECT SUM( ( i1.pretorig * Coalesce(i1.coefdiscmaj,1) * vCurs - DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz) ) * l1.cant * i1.cant / a1.cant )
    INTO vAdaos
    FROM iesiri1 i1
      INNER JOIN ieslink il ON il.codies1    = i1.codies1
      INNER JOIN iesiri1 a1 ON a1.codies1    = il.codlinieaviz
      INNER JOIN livr    l  on l.codies      = a1.codies
      INNER JOIN livr1   l1 on l1.codies1    = a1.codies1 AND l1.codlivr = l.codlivr
      LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv on lv.codlivr1   = l1.codlivr1
    WHERE i1.codies = pCodDoc AND i1.tiplinie = &apos;=&apos;;
  ELSE
    SELECT
      SUM( ( i1.pretorig * Coalesce(i1.coefdiscmaj,1) * vCurs - DECODE(lv.codlivrval,NULL,ns.pret - ns.adaos,lv.pretachiz) -
             (CASE
                WHEN vTipDoc IN (16,21) THEN Coalesce(i1.tva,0) * Decode(i1.pu,0,1,i1.pretorig/i1.pu) * Coalesce(i1.coefdiscmaj,1) * vCurs / i1.cant
                ELSE 0
              END ) ) * l1.cant )
    INTO vAdaos
    FROM iesiri1 i1
      INNER JOIN livr    l  on l.codies      = i1.codies
      INNER JOIN livr1   l1 on l1.codies1    = i1.codies1 AND l1.codlivr = l.codlivr
      LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
      LEFT  JOIN livrval lv on lv.codlivr1   = l1.codlivr1
    WHERE i1.codies = pCodDoc AND i1.tiplinie = &apos;=&apos;;

  END IF;

  IF Coalesce(vValDoc,0) IN (0,1)
  THEN vAdaos := Coalesce(vAdaos,0) * pRest;
  ELSE vAdaos := Coalesce(vAdaos,0) * (pRest/vValDoc);
  END IF;

  RETURN vAdaos;
END;

PROCEDURE UMPLE_tmp_lst_scad_stins  (aListID IN NUMBER, pFiltruLuna IN VARCHAR2) IS
  sInsTMP     CLOB;
  sJoinFiltru CLOB := PKG_LIST_BASE_SCADENTARCL.GetJoinFiltru;
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_SCAD_STINS&apos;;
  sInsTmp:=
  &apos;INSERT INTO tmp_lst_scad_stins  (codstinspif, valoare, tva)
  SELECT codstinspif, SUM(val*semn) valoare, Sum(tva*semn) tva
  FROM (
    SELECT
      s.codstinspif, Abs(s.valoare) val, Abs(Coalesce(g.tva,0)) tva,
      CASE
        -- la resturi nesemnificative nu poate fi determinat semnul in functie de valoare initiala a obligatiei (posibil sa se fi platit mai mult si atunci e semn invers)
        WHEN OS.SEMNIFICATIE = 1300 AND O.SEMNIFICATIE = 210 THEN -SIGN(s.valoare)
        WHEN OS.SEMNIFICATIE = 1350 AND O.SEMNIFICATIE = 200 THEN  SIGN(s.valoare)
        ELSE
          CASE WHEN Coalesce(o.valoare,0) &lt; 0 THEN -1 ELSE 1 END *
          CASE
            WHEN OS.SEMNIFICATIE = 750                                                                                    THEN -1
            WHEN OS.SEMNIFICATIE = 1350 AND O.ICONT  =  3 AND      O.SEMNIFICATIE IN (           1201) AND O.ICONT  =  3  THEN  1
            WHEN OS.SEMNIFICATIE = 1350 AND O.ICONT  =  3 AND NOT (O.SEMNIFICATIE IN (     1200      )                  ) THEN -1
            WHEN OS.SEMNIFICATIE = 1350 AND OS.ICONT =  5 AND NOT (O.SEMNIFICATIE IN (210, 1200, 1201) AND O.ICONT  =  5) THEN -1
            ELSE                                                                                                                1
          END *
          CASE
            WHEN O.SEMNIFICATIE  IN (1200, 1201)                            AND O.ICONT = 5                THEN -1
            WHEN O.SEMNIFICATIE = 1201           AND OS.SEMNIFICATIE = 1303                                THEN -1
            WHEN O.SEMNIFICATIE = 1301           AND OS.SEMNIFICATIE = 1350 AND O.ICONT NOT IN (   10, 11) THEN -1
            WHEN O.SEMNIFICATIE = 1351                                      AND O.ICONT NOT IN (3, 10    ) THEN -1
            WHEN O.SEMNIFICATIE IN (210,330,410)                                                           THEN -1
            ELSE                                                                                                 1
          END
      END semn
    FROM stingere s
      INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
      INNER JOIN obligpif o  ON o.codobligpif  = s.codstinspif
      INNER JOIN general  g  ON  g.codgeneral  = os.codgeneral&apos;||
      sJoinFiltru||&apos;
      LEFT  JOIN trezor1  t1 ON t1.codtrezor1  = g.coddoc AND g.tipdoc IN (29,30,31,33)
      LEFT  JOIN compens  c  ON c.codcompens   = g.coddoc AND g.tipdoc = 28
      LEFT  JOIN iesiri   i  ON i.codies       = g.coddoc AND i.tipdoc = g.tipdoc --AND os.semnificatie IN (211,400)
    WHERE Coalesce(i.an * 12 + i.luna,t1.an * 12 + t1.luna,c.an * 12 + c.luna)&apos;||pFiltruLuna||&apos;
      AND Coalesce(i.infocm,0) &lt;&gt; 1&apos;||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;i.DataDoc,t1.DataDoc,c.DataDoc&apos;)||&apos;
  )
  GROUP BY codstinspif&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, 0);
END;

PROCEDURE UMPLE_tmp_lst_scad_sertar (aListID  IN NUMBER) IS
  sInsTMP VARCHAR2(10000);
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_SCAD_SERTAR&apos;;
  sInsTmp:=
  &apos;INSERT INTO tmp_lst_scad_sertar  (codobligpif, decont, doc, ser, nrdoc, datadoc, valoare, datadecont, valasoc)
  SELECT
    ns1.codobligpif,
    vc2_nt_to_vc3200(CAST(collect(DISTINCT CASE NS.DECONT WHEN 3 THEN &apos;&apos;Efecte remise&apos;&apos; WHEN 2 THEN &apos;&apos;Efecte acceptate&apos;&apos; ELSE &apos;&apos;Cecuri&apos;&apos; END) AS vc2_nt)) decont,
    vc2_nt_to_vc3200(CAST(collect(NS.DOC||&apos;&apos; &apos;&apos;||NS.NRDOC||&apos;&apos;/&apos;&apos;||To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) doc,
    vc2_nt_to_vc3200(CAST(collect(NS.DOC ORDER BY NS.CODSERTAR) AS vc2_nt)) ser,
    vc2_nt_to_vc3200(CAST(collect(To_char(NS.NRDOC) ORDER BY NS.CODSERTAR) AS vc2_nt)) nrdoc,
    vc2_nt_to_string(CAST(collect(To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadoc,
    SUM(NS.VALOARE  * CASE NS.TIP WHEN 1 THEN 1 ELSE -1 END) VALOARE,
    vc2_nt_to_vc3200(CAST(collect(To_char(NS.DATADECONT,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadecont,
    SUM(NS1.VALOARE * CASE NS.TIP WHEN 1 THEN 1 ELSE -1 END) VALASOC
  FROM nsertar1 ns1
    LEFT JOIN nsertar  ns ON ns.codsertar  = ns1.codsertar
    LEFT JOIN trezor1  t1 ON t1.codsertar  = ns1.codsertar AND (t1.an * 12 + t1.luna) &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    LEFT JOIN obligpif o  ON o.codobligpif = ns1.codobligpif
  WHERE t1.codtrezor IS NULL
  GROUP BY ns1.codobligpif&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, 0);
END;

PROCEDURE UMPLETMP(aLISTID IN NUMBER DEFAULT 0) IS
  sInsTMP        CLOB;
  sSelTMP        CLOB;
  sJoinFiltru    CLOB         := PKG_LIST_BASE_SCADENTARCL.GetJoinFiltru;
  sCoefValCEC    VARCHAR2(200);

  dDataRef       DATE         := PKG_LIST_SELECTSCADENTAR.DataRef;
  dDataNVL       DATE         := LAST_DAY(ADD_MONTHS(dDataRef,-1));
  sDataRef       VARCHAR2(10) := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);
  sDataNVL       VARCHAR2(10) := To_Char(dDataNVL, &apos;dd.mm.yyyy&apos;);

  sZilePlusDoc   VARCHAR2(100);
  sZilePlusTerm  VARCHAR2(100);
  sZilePlusTermC VARCHAR2(100);
  sFiltruLuna    VARCHAR2(200);
  sAnP           NUMBER(4);
  sLunaP         NUMBER(2);
  sAnC           NUMBER(4);
  sLunaC         NUMBER(2);
  sData1PCA      VARCHAR2(10);
  sData2PCA      VARCHAR2(10);

  sIcontS_C      VARCHAR2(2500) := &apos;,30,31,32,33,34&apos;;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_SCADENTARCL&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_SCAD_PARTVAL&apos;;

  SELECT ancurent, lunacurenta INTO sAnC, sLunaC FROM FIRMALUNI;

  sData1PCA  := &apos;01.01.&apos;||to_char(sAnC-1,&apos;fm0000&apos;);
  IF To_Number(To_Char(dDataRef,&apos;yyyy&apos;)) &lt; sAnC
  THEN sData2PCA  := &apos;31.12.&apos;||to_char(sAnC-1,&apos;fm0000&apos;);
  ELSE sData2PCA  := sDataRef;
  END IF;

  sZilePlusDoc := &apos;(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) - Coalesce(D.DATADOC,TO_DATE(&apos;&apos;&apos;||sDataNVL||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))&apos;;
  IF PKG_LIST_SELECTSCADENTAR.CodJob1 &gt; 0 THEN
    pkg_globals.SetLunaLucru_SIMPLA(extract(year from dDataRef), extract(month from dDataRef));
  END IF;

  IF (PKG_LIST_SELECTSCADENTAR.TipPerioada = 0) OR (sAnC*12+sLunaC &gt;= PKG_GLOBALS.ANLUNALUCRU) THEN
    --lista trece pe aici
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, sAnP, sLunaP);
    sFiltruLuna := &apos; = &apos;||pkg_globals.AnLunaLucru;
  ELSE
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(sAnC, sLunaC, sAnP, sLunaP);
    sFiltruLuna := &apos; BETWEEN &apos;|| To_Char(sAnC*12+sLunaC)||&apos; AND &apos;||pkg_globals.AnLunaLucru;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.InLei
  THEN sConv := &apos;*CASE s.moneda WHEN 0 THEN 1 ELSE s.Curs END&apos;;
  ELSE sConv := &apos;&apos;;
  END IF;

  IF aListID = 250 -- pe gestiuni
  THEN sConv := sConv||&apos;*Coalesce(cg.Coef,1)&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.TipIntarziere = 0
  THEN
    sZilePlusTerm  := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-Coalesce(O.TERMEN,D.DATADOC),0)&apos;;
    sZilePlusTermC := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-COALESCE(D.DATADECONT,O.TERMEN,D.DATADOC),0)&apos;;
  ELSE
    sZilePlusTerm  := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-D.DATADOC,0)&apos;;
    sZilePlusTermC := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-D.DATADOC,0)&apos;;
  END IF;

  sInsTMP :=
  &apos;INSERT INTO TMP_SCADENTARCL (
    codobligpif,CodDoc,CodDoc1,TipDoc, codpart, doc, nrdoc, datadoc, nri, blocat, termen,
    valoare, tva,
    restval, resttva,
    majorare, zile_trecute, zile_depasire,
    cont, adaosdoc,
    moneda, cursini, obs, carnetdoc, seriadoc, subunitatea, agent, codlocatie, initializari,
    codgeneral, coefprovizion, exclusplata,
    curs,
    codcentru,  userid, tvamediu, tvaincasare, ansapt, codtippartincert,
    leg_doc, leg_nrdoc, leg_datadoc)&apos;;

 	sSelTMP :=&apos;
  SELECT -- FACTURI PERIOADA CURENTA
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END tva,
    o.valoare * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END restval,
    CASE
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 22 THEN d.valdoc ELSE d.valdoc-d.tvadoc END,0),1)*100,2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM iesiri d
    INNER JOIN general  g ON g.coddoc     = d.codies AND g.tipdoc = d.tipdoc
    INNER JOIN obligpif o ON o.codgeneral = g.codgeneral&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;
    AND d.tipdoc IN (19,21,22,26)
    AND o.semnificatie IN (200,210,220)
    AND NOT (o.semnificatie = 210 AND Coalesce(g.tva,0)=o.valoare)
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- FACTURI CU SOLD LA INCEPUTUL PERIOADEI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END tva,
    Coalesce(ol.rest,0) * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END restval,
    Coalesce(ol.resttva,0) * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 22 THEN d.valdoc ELSE d.valdoc-d.tvadoc END,0),1)*100,2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpifluna ol
    INNER JOIN obligpif o ON o.codobligpif = ol.codobligpif
    INNER JOIN general  g ON g.codgeneral  = o.codgeneral AND g.tipdoc IN (19,21,22,26)
    INNER JOIN iesiri   d ON d.codies      = g.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    AND (Coalesce(ol.rest,0) &lt;&gt; 0 OR Coalesce(ol.resttva,0) &lt;&gt; 0)
    AND o.semnificatie IN (200,210,220)
    AND NOT (o.semnificatie = 210 AND Coalesce(g.tva,0)=o.valoare)
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- FACTURI ANTERIOARE PERIOADEI CU STINGERI IN LUNA CURENTA SI CU SOLD 0 LA INCEPUTUL PERIOADEI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 210 THEN -1 ELSE 1 END tva,
    0 restval, 0 resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 22 THEN d.valdoc ELSE d.valdoc-d.tvadoc END,0),1)*100,2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM (
    SELECT DISTINCT o.codobligpif
    FROM trezor t
      INNER JOIN trezor1      t1 ON t1.codtrezor      = t.codtrezor
      INNER JOIN general      gs ON gs.coddoc         = t1.codtrezor1 AND gs.tipdoc = t.tipdoc
      INNER JOIN obligpif     os ON os.codgeneral     = gs.codgeneral
      INNER JOIN stingere     s  ON s.codstingatorpif = os.codobligpif
      INNER JOIN obligpif     o  ON o.codobligpif     = s.codstinspif
      INNER JOIN general      g  ON g.codgeneral      = o.codgeneral  AND g.tipdoc IN (19,21,22,26)
      LEFT  JOIN obligpifluna ol ON ol.codobligpif    = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE t.tipdoc IN (29,30,31,33)
      AND gs.semnificatie = 750 AND (t.an*12+t.luna&apos;||sFiltruLuna||&apos;)
      AND o.semnificatie IN (200,210,220)
      AND NOT (o.semnificatie = 210 AND Coalesce(g.tva,0)=o.valoare)
      AND Coalesce(ol.rest,0) = 0 AND Coalesce(ol.resttva,0) = 0 &apos;||
      PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;t.DataDoc&apos;)||&apos;
  ) x
    INNER JOIN obligpif o ON o.codobligpif = x.codobligpif
    INNER JOIN general  g ON g.codgeneral  = o.codgeneral
    INNER JOIN iesiri   d ON d.codies      = g.coddoc&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE d.an * 12 + d.luna &lt;= &apos;||To_Char(sAnP*12+sLunaP)||&apos;
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  WITH xStins AS (
    SELECT DISTINCT codstinspif
    FROM obligpif os
      INNER JOIN general  gs ON gs.codgeneral     = os.codgeneral AND gs.tipdoc IN (29,30,31,33)
      INNER JOIN trezor1  t1 ON t1.codtrezor1     = gs.coddoc
      INNER JOIN trezor   t  ON t.codtrezor       = t1.codtrezor
      INNER JOIN stingere s  ON s.codstingatorpif = os.codobligpif
      INNER JOIN obligpif o  ON o.codobligpif     = s.codstinspif&apos;||
      sJoinFiltru||&apos;
    WHERE os.semnificatie = 750 AND (t1.an * 12 + t1.luna&apos;||sFiltruLuna||&apos;) &apos;||
      PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;t.DataDoc&apos;)||&apos;
  )
  SELECT -- FACTURI LITIGII
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;Litigiu &apos;&apos;||Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    o.valoare * DECODE(o.semnificatie,210,-1,1) valoare, Coalesce(g.tva,0) * DECODE(o.semnificatie,210,-1,1) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * DECODE(o.semnificatie,210,-1,1) restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * DECODE(o.semnificatie,210,-1,1) resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, d.agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 22 THEN d.valdoc ELSE d.valdoc-d.tvadoc END,0),1)*100,2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, c.codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpif o
    INNER JOIN (
      SELECT CONNECT_BY_ROOT CODOBLIGPIF ROOTCODOBLIGPIF, CODOBLIGPIF, CODGENERAL, ICONT
      FROM OBLIGPIF
      WHERE Coalesce(CODOBLIGASOCIAT,0) = 0
      START WITH semnificatie = 1303
      CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
    ) olit ON olit.rootcodobligpif = o.codobligpif
    INNER JOIN general g  ON g.codgeneral  = olit.codgeneral AND g.tipdoc IN (19,21,22,26)
    INNER JOIN iesiri  d  ON d.codies      = g.coddoc
    INNER JOIN general gl ON gl.codgeneral = o.codgeneral    AND gl.tipdoc = 28
    INNER JOIN compens c  ON c.codcompens  = gl.coddoc&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif     = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN xStins          ON xStins.codstinspif = o.codobligpif
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = gl.codgeneral
  WHERE o.semnificatie = 1303
    AND d.an * 12 + d.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND (c.an * 12 + c.luna&apos;||sFiltruLuna||&apos; OR Coalesce(ol.rest,0) &lt;&gt; 0 OR Coalesce(ol.resttva,0) &lt;&gt; 0 OR xStins.codstinspif IS NOT NULL)
    AND Coalesce(d.infocm,0) &lt;&gt; 1&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;c.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

  DELETE TMP_SCADCL_COEFG;
  IF aListID = 250 THEN -- pe gestiuni
    INSERT INTO TMP_SCADCL_COEFG ( CODOBLIGPIF, CODGEST, COEF)
    SELECT CODOBLIGPIF, CODGEST, CASE WHEN NRLINII = 1 THEN 1 WHEN VALTOT = VAL THEN 1 WHEN VALTOT = 0 THEN 0 ELSE VAL / VALTOT END
    FROM (
      SELECT
        S.CODOBLIGPIF, COALESCE(N.GEST, LV.GEST, I1.GESTACT, 0) CODGEST,
        Sum(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*COALESCE(L1.CANT,I1.CANT)*CASE WHEN Coalesce(AE1.CANT, I1.CANT) = I1.CANT THEN 1 ELSE I1.CANT/AE1.CANT END) VAL,
        Count(1) OVER (PARTITION BY S.CODOBLIGPIF) NRLINII,
        Sum(Sum(I1.PRETORIG*Coalesce(I1.COEFDISCMAJ,1)*COALESCE(L1.CANT,I1.CANT)* CASE WHEN Coalesce(AE1.CANT, I1.CANT) = I1.CANT THEN 1 ELSE I1.CANT/AE1.CANT END)) OVER (PARTITION BY S.CODOBLIGPIF) VALTOT
      FROM TMP_SCADENTARCL S
        LEFT JOIN IESIRI I     ON I.CODIES      = S.CODDOC AND I.TIPDOC = S.TIPDOC
        LEFT JOIN IESIRI1 I1   ON I1.CODIES     = I.CODIES
        LEFT JOIN IESLINK ILAE ON ILAE.CODIES1  = I1.CODIES1
        LEFT JOIN IESIRI1 AE1  ON AE1.CODIES1   = ILAE.CODLINIEAVIZ
        LEFT JOIN IESIRI AE    ON AE.CODIES     = AE1.CODIES
        LEFT JOIN LIVR L       ON L.CODIES      = Coalesce(AE.CODIES, I.CODIES) AND L.TIPLIVR = Coalesce(AE.TIPDOC, I.TIPDOC)
        LEFT JOIN LIVR1 L1     ON L1.CODLIVR    = L.CODLIVR AND L1.CODIES1 = Coalesce(AE1.CODIES1, I1.CODIES1)
        LEFT JOIN LIVRVAL LV   ON LV.CODLIVR1   = L1.CODLIVR1
        LEFT JOIN NIRSTOC NS   ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NIR N        ON N.CODNIR      = NS.CODNIR
      GROUP BY S.CODOBLIGPIF, COALESCE(N.GEST, LV.GEST, I1.GESTACT, 0)
    );
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.DetTranzInCurs
  THEN sCoefValCEC := &apos;*CASE WHEN o.valoare = 0 THEN 0 ELSE Coalesce(s.valoare, ox.valoare,o.valoare)/o.valoare END&apos;;
  ELSE sCoefValCEC := &apos;&apos;;
  END IF;

	sSelTMP :=&apos;
  SELECT -- TRANZACTII IN CURS -- TREZORERIE
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, &apos;||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.DetTranzInCurs THEN &apos;
    CASE
      WHEN IES_S.CODIES    IS NOT NULL THEN COALESCE(IES_S.PREFIXDOC, &apos;&apos;F&apos;&apos;)
      WHEN INT_S.CODINTR   IS NOT NULL THEN COALESCE(INT_S.PREFIXDOC, &apos;&apos;F&apos;&apos;)
      WHEN NC_S.CODNC      IS NOT NULL THEN &apos;&apos;NC&apos;&apos;
      WHEN T1_S.CODTREZOR1 IS NOT NULL THEN T1_S.DOC
      ELSE d.doc
    END doc,
    CASE
      WHEN IES_S.CODIES    IS NOT NULL THEN IES_S.NRDOC
      WHEN INT_S.CODINTR   IS NOT NULL THEN INT_S.NRDOC
      WHEN NC_S.CODNC      IS NOT NULL THEN NC_S.NRDOC
      WHEN T1_S.CODTREZOR1 IS NOT NULL THEN T1_S.NRDOC
      ELSE d.nrdoc
    END nrdoc,
    CASE
      WHEN IES_S.CODIES    IS NOT NULL THEN IES_S.DATADOC
      WHEN INT_S.CODINTR   IS NOT NULL THEN INT_S.DATADOC
      WHEN NC_S.CODNC      IS NOT NULL THEN NC_S.DATADOC
      WHEN T1_S.CODTREZOR1 IS NOT NULL THEN T1_S.DATADOC
      ELSE d.datadoc
    END datadoc,&apos;
    ELSE &apos;d.doc, d.nrdoc, d.datadoc, &apos;
  END ||&apos;
    d.nri, t.blocat, COALESCE(d.datadecont,o.termen,d.datadoc) termen,
    o.valoare&apos;||sCoefValCEC||&apos; valoare, Coalesce(g.tva,0)&apos;||sCoefValCEC||&apos; tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare         ELSE ol.rest                END&apos;||sCoefValCEC||&apos; restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END&apos;||sCoefValCEC||&apos; resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTermC||&apos; zile_depasire,
    PKG_TREZOR.CODCONTCEC(t.CodBanca, o.Semnificatie, d.Tipdecont, d.obiecttranz, t.an, t.luna) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea, DECODE(d.agent,NULL,t.agent,0,t.agent,d.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, t.userid,
    0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,&apos;||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.DetTranzInCurs THEN &apos;
    d.doc leg_doc, d.nrdoc leg_nrdoc, d.datadoc leg_datadoc&apos;
    ELSE &apos;
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc &apos;
  END||&apos;
  FROM obligpif o
    INNER JOIN general g     ON o.codgeneral      = g.codgeneral AND g.tipdoc = 31
    INNER JOIN trezor1 d     ON d.codtrezor1      = g.coddoc
    INNER JOIN trezor  t     ON t.codtrezor       = d.codtrezor&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral&apos;||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.DetTranzInCurs THEN &apos;
    LEFT JOIN general  gx    ON gx.coddoc         = g.coddoc     AND gx.tipdoc = g.tipdoc AND gx.semnificatie &lt;&gt; g.semnificatie
    LEFT JOIN obligpif ox    ON ox.codgeneral     = gx.codgeneral
    LEFT JOIN STINGERE S     ON S.CODSTINGATORPIF = ox.CODOBLIGPIF
    LEFT JOIN OBLIGPIF O_S   ON O_S.CODOBLIGPIF   = S.CODSTINSPIF
    LEFT JOIN GENERAL  G_S   ON G_S.CODGENERAL    = O_S.CODGENERAL
    LEFT JOIN OBLIGPIF O_F   ON O_F.CODOBLIGPIF   = O_S.CODOBLIGASOCIAT AND O.SEMNIFICATIE = 400 AND O_S.SEMNIFICATIE = 1303
    LEFT JOIN GENERAL  G_F   ON G_F.CODGENERAL    = O_F.CODGENERAL
    LEFT JOIN COMPENS  C_S   ON C_S.CODCOMPENS    = G_S.CODDOC AND G_S.TIPDOC = 28
    LEFT JOIN IESIRI   IES_S ON IES_S.CODIES      = Coalesce(G_F.CODDOC, G_S.CODDOC) AND IES_S.TIPDOC = Coalesce(G_F.TIPDOC, G_S.TIPDOC)
    LEFT JOIN DVI      DVI_S ON DVI_S.CODDVI      = G_S.CODDOC AND O.SEMNIFICATIE = 300 AND O_S.SEMNIFICATIE = 130
    LEFT JOIN INTRARI  INT_S ON INT_S.CODINTR     = Coalesce(DVI_S.CODINTR, G_S.CODDOC) AND INT_S.TIPDOC = G_S.TIPDOC
    LEFT JOIN NC1      NC1_S ON NC1_S.CODNC1      = G_S.CODDOC AND G_S.TIPDOC = 35
    LEFT JOIN NC       NC_S  ON NC_S.CODNC        = NC1_S.CODNC
    LEFT JOIN TREZOR1  T1_S  ON T1_S.CODTREZOR1   = G_S.CODDOC AND G_S.TIPDOC IN (29, 30, 31, 33)
    LEFT JOIN TREZOR   T_S   ON T_S.CODTREZOR     = T1_S.CODTREZOR&apos;
    ELSE &apos;&apos;
  END ||&apos;
  WHERE o.semnificatie = 600
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma AND PKG_GLOBALS.GETSUBUNITATE &gt; 1 THEN &apos;
    AND (
      t.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      OR
      EXISTS (
        SELECT 1
        FROM general gg
          INNER JOIN obligpif og ON og.codgeneral     = gg.codgeneral
          INNER JOIN stingere s  ON s.codstingatorpif = og.codobligpif
          INNER JOIN obligpif os ON os.codobligpif    = s.codstinspif
          INNER JOIN general  gs ON gs.codgeneral     = os.codgeneral
          INNER JOIN iesiri   i  ON i.codies          = gs.coddoc AND i.tipdoc = gs.tipdoc
        WHERE gg.coddoc = g.coddoc AND gg.tipdoc = g.tipdoc AND gg.semnificatie &lt;&gt; g.semnificatie
          AND i.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      )
    )&apos;
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma THEN NULL
    ELSE PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)
  END;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,   &apos;IES_S&apos;, &apos;IES_S.CODIES = Coalesce(G_F.CODDOC, G_S.CODDOC) AND IES_S.TIPDOC = Coalesce(G_F.TIPDOC, G_S.TIPDOC) &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DVI&apos;,      &apos;DVI_S&apos;, &apos;DVI_S.CODDVI = G_S.CODDOC AND O.SEMNIFICATIE = 300 AND O_S.SEMNIFICATIE = 130&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,  &apos;INT_S&apos;, &apos;INT_S.CODINTR = Coalesce(DVI_S.CODINTR, G_S.CODDOC) AND INT_S.TIPDOC = G_S.TIPDOC &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC1&apos;,      &apos;NC1_S&apos;, &apos;NC1_S.CODNC1 = G_S.CODDOC AND G_S.TIPDOC = 35 &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC&apos;,       &apos;NC_S&apos;,  &apos;NC_S.CODNC = NC1_S.CODNC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;,  &apos;T1_S&apos;,  &apos;T1_S.CODTREZOR1 = G_S.CODDOC AND G_S.TIPDOC IN (29, 30, 31, 33) &apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,   &apos;T_S&apos;,   &apos;T_S.CODTREZOR = T1_S.CODTREZOR&apos;);


  IF PKG_LIST_SELECTSCADENTAR.CuTranzInCurs THEN
    LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);
  END IF;

	sSelTMP :=&apos;
  SELECT -- TREZORERIE - PLATI si INCASARI IN AVANS
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, d.doc, d.nrdoc, d.datadoc, d.nri, t.blocat, Coalesce(d.datadecont,o.termen) termen,
    o.valoare * Decode(o.semnificatie,410,-1,1) valoare, Coalesce(g.tva,0) * Decode(o.semnificatie,410,-1,1) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * Decode(o.semnificatie,410,-1,1) restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * Decode(o.semnificatie,410,-1,1) resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini,  d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea, DECODE(d.agent,NULL,t.agent,0,t.agent,d.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, t.userid,
    0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (29,30,31,33)
    INNER JOIN trezor1 d ON d.codtrezor1 = g.coddoc
    INNER JOIN trezor  t ON t.codtrezor  = d.codtrezor&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie IN (410,330)
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- NOTE CONTABILE LEGATE DE PARTENERI
    o.codobligpif, d.codnc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;NC&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    CASE WHEN o.icont = 5 AND o.semnificatie in (1200,1201) THEN -1 ELSE 1 END * o.valoare         valoare,
    CASE WHEN o.icont = 5 AND o.semnificatie in (1200,1201) THEN -1 ELSE 1 END * Coalesce(g.tva,0) tva,
    CASE WHEN o.icont = 5 AND o.semnificatie in (1200,1201) THEN -1 ELSE 1 END * CASE WHEN ol.codobligpif IS NULL THEN o.valoare         ELSE ol.rest                END restval,
    CASE WHEN o.icont = 5 AND o.semnificatie in (1200,1201) THEN -1 ELSE 1 END * CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, nc1.obs, d.carnetdoc, NULL seriadoc, d.subunitatea, nc1.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, NULL codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (35)
    INNER JOIN nc1       ON nc1.codnc1   = g.coddoc
    INNER JOIN nc      d ON d.codnc      = nc1.codnc&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.icont IN (3,5,10,11,18,20,23,24&apos;||sIcontS_C||&apos;)  -- 7 - facturi de intocmit - trebuie exclus
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- NOTE CONTABILE LEGATE DE PARTENERI - LITIGII
    o.codobligpif, d.codnc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;Litigiu NC&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat,  o.termen,
    o.valoare, Coalesce(g.tva,0) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, nc1.obs, d.carnetdoc, NULL seriadoc, d.subunitatea, COALESCE(nc1.agent,c.agent) agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, c.codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpif o
    INNER JOIN general gl ON gl.codgeneral = o.codgeneral AND gl.tipdoc = 28
    INNER JOIN compens c  ON c.codcompens  = gl.coddoc
    INNER JOIN (
      SELECT CONNECT_BY_ROOT CODOBLIGPIF ROOTCODOBLIGPIF, CODOBLIGPIF, CODGENERAL, ICONT
      FROM OBLIGPIF
      WHERE Coalesce(CODOBLIGASOCIAT,0) = 0
      START WITH semnificatie = 1303
      CONNECT BY PRIOR CODOBLIGASOCIAT = CODOBLIGPIF
    ) olit ON olit.rootcodobligpif = o.codobligpif
    INNER JOIN general g ON g.codgeneral = olit.codgeneral AND g.tipdoc IN (35) &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN nc1             ON nc1.codnc1 = g.coddoc
    LEFT JOIN nc           d  ON d.codnc    = nc1.codnc
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = gl.codgeneral
  WHERE o.semnificatie = 1303
    AND olit.icont IN (3,5,10,11,18&apos;||sIcontS_C||&apos;) -- 7 - facturi de intocmit - trebuie exclus
    AND Coalesce(d.an * 12 + d.luna, c.an * 12 + c.luna) &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
    AND ((c.an * 12 + c.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;&apos;, &apos;Coalesce(d.subunitatea, c.subunitatea)&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;&apos;, &apos;Coalesce(d.userid, c.userid)&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;Coalesce(d.DataDoc, c.DataDoc)&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;c.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- COMPENSARI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;PV&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 1351 AND o.icont NOT IN (3, 10) THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini,  d.obsc obs, d.carnetdoc, NULL seriadoc, d.subunitatea, d.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, o.coefprovizion, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    0 TVAMediu,
    0 TvaIncasare, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;) ansapt, d.codtippartincert,
    NULL leg_doc, NULL leg_nrdoc, NULL leg_datadoc
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 28
    INNER JOIN compens d ON d.codcompens = g.coddoc&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie IN (1301,1351)
    AND o.icont IN (3,5,10,11,18&apos;||sIcontS_C||&apos;) -- 7 - facturi de intocmit - trebuie exclus
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

  DELETE tmp_dinamic_cols;
  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    INSERT INTO tmp_dinamic_cols (fieldname, display, indexlocal, cod)
    SELECT &apos;D&apos;||ROWNUM, TRUNC(ANSAPT/100)||&apos; Sapt.&apos;||To_Char(Mod(ANSAPT,100),&apos;fm00&apos;), ROWNUM, ANSAPT
    FROM (
      SELECT DISTINCT ANSAPT
      FROM TMP_SCADENTARCL
      WHERE ANSAPT IS NOT NULL
      ORDER BY ANSAPT
    );
  END IF;

  UMPLE_tmp_lst_scad_stins (aListID, sFiltruLuna);
  UMPLE_tmp_lst_scad_sertar(aListID );

  sInsTmp:=
  &apos;INSERT INTO tmp_lst_scad_partval (partener, partvaliesac, partvaliesap)
  SELECT
    partener,
    SUM(CASE WHEN an = &apos;||To_char(sAnC-1,&apos;fm0000&apos;)||&apos; THEN 0 ELSE (valdoc-tvadoc)*COALESCE(NullIf(curs,0), 1) END) PARTVALIESAC,
    SUM(CASE WHEN an = &apos;||To_char(sAnC-1,&apos;fm0000&apos;)||&apos; THEN (valdoc-tvadoc)*COALESCE(NullIf(curs,0), 1) ELSE 0 END) PARTVALIESAP
  FROM iesiri
  WHERE tipdoc in (19,21,26) AND Coalesce(operat,0) = 1 AND Coalesce(anulat,0) = 0
    AND Coalesce(partener, 0) &lt;&gt; 0
    AND datadoc between TO_DATE(&apos;&apos;&apos;||sData1PCA||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sData2PCA||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
  GROUP BY partener&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, 0);
  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    CLOB;
  sSelect    CLOB;
  sUpdate    CLOB;
  sFAdaosDoc CLOB := &apos;, NULL ADAOS&apos;;
  sValDiscZP CLOB := &apos;, NULL VALDISCZP, NULL VALDISCC&apos;;
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  sCursRef   CLOB := &apos;, 1 &apos;;
  pRegProviz INTEGER;
  i          INTEGER;
  aVTot      NUMBER(20, 7);
  dDataRef   DATE         := PKG_LIST_SELECTSCADENTAR.DataRef;
  sDataRef   VARCHAR2(10) := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);
BEGIN
  PRC_AL_CHECK(&apos;NCONT1&apos;);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  PRC_AL_CHECK(&apos;NAGENDA1&apos;);

  IF NOT PKG_LIST_SELECTSCADENTAR.TMPOk THEN
    UmpleTmp(aListId);
  END IF;
  pRegProviz := Coalesce(pkg_categconst.GetValConstanta(&apos;RegProviz&apos;, EXTRACT (YEAR FROM dDataRef), EXTRACT (MONTH FROM dDataRef)),0) ;

  gSuplCols :=
    &apos;TMP_SCADENTARCL S, TMP_SCADENTARST STINS, NPART NP, NPART1 NP1, IOPART IOP, NMONEDE MON, NPARTCODFISC FISC, CENTRECOST CC, &apos;||
    &apos;NAGENDA SLIVR, NLOCALIT LLIVR, NJUDET JLIVR, NZONE ZLIVR, NTARI TLIVR, NPERS AG_SLIVR, NTIPSEDII TSLIVR, TRASEULIVR TRASLIVR,&apos;||
    &apos;NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NZONE ZSOC, NTARI TSOC, NPERS AG_SSOC, NGEST G,&apos;||
    &apos;NPERS AG_DOC, NCLASEP NCP, NCONT NC, NCONT1 NC1, NCONTS CS, DOCCARNETE DC, NPARTB PB, NBANK B, TMP_UTILIZATOR UTILIZATOR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;,      &apos;PD&apos;,   &apos;PD.CODPART  = S.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,     &apos;IEXT&apos;, &apos;IEXT.CODIES = S.CODDOC AND S.TIPDOC IN (19, 26)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TIPPARTINCERT&apos;, &apos;TPI&apos;,  &apos;TPI.CODTIPPARTINCERT = S.CODTIPPARTINCERT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, s.datadoc )&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcAdaosDoc THEN
    sFAdaosDoc := &apos;,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      WHEN o.semnificatie IN (210,211) THEN 0
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0 AND Coalesce(s.Valoare,0) = 0 THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0 THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))/s.Valoare
      ELSE PKG_LIST_BASE_SCADENTARCL.CalcAdaosDoc(S.CodDoc,s.restval - Coalesce(stins.valoare,0))
    END&apos;||sConv||&apos; ADAOS&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    sValDiscZP := &apos;,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      ELSE Coalesce(PKG_CONTRACT.CALCULEAZA_DISCT_DOC(s.TipDoc, s.CodDoc, &apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,(s.restval - Coalesce(stins.valoare,0))), 0)
    END&apos;||sConv||&apos; VALDISCZP,
    CASE
      WHEN Coalesce(s.TipDoc,0) NOT IN (19,26) THEN 0
      ELSE Coalesce(PKG_CONTRACT.CALCULEAZA_DISCC_DOC(s.TipDoc, s.CodDoc, To_Date(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), (s.restval - Coalesce(stins.valoare,0))), 0)
    END&apos;||sConv||&apos; VALDISCC&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,TipDoc,
    DENPART,DENGEST,CODFISCAL,LIVR_DEN,LIVR_LOC,LIVR_JUD,LIVR_ZONA,DENCLASAP,
    BLOCAT,BLOCATDOC,PREFDOC,NRDOC,DATADOC,NRI,OBSDOC,SERDOC,
    AGDOC,
    TERMEN,TERMENAN,TERMENLUNA,
    VALOARE,
    MAJORARE,
    REST,
    RESTTVA,
    RESTPART,
    VALMAJ,
    ZILE_SCADENTA,ZILE_TRECUTE,ZILE_DEPASIRE,
    DOCUMENT,
    DOCUMENT_LEG,
    MONEDA,CONT,CONTS,
    Z_0,L_1,L_2,L_3,L_4,L_5,L_6,T_2,T_3,T_31,T_32,T_33,T_4,S_1,S_2,S_3,S_4,P_30,P_60,P_90,P_360,TS_1,TS_2,TS_3,TS_4,TS_4p,
    SUBUNITATE, EXCLUSPLATA,
    PROVIZION,
    CREDITC,
    SERTDECONT, SERTDOC, SERTSER, SERTNRDOC, SERTDATADOC, SERTVALDOC, SERTDATADEC, SERTVALASOC,
    CENTRUCOST, SIMBCENTRUCOST,
    AVANS, PROCTVAMEDIU, TVAINCAS,
    PARTVALIESAC, PARTVALIESAP,
    CF_AS, CF_CURS,
    ANSAPT, CURS,CURS_INI,CURS_REF,ADAOSDOC,VALDISCZP, VALDISCC &apos;||gUserFields||&apos;)&apos;;

	sSelect :=&apos;
  SELECT
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc  END AS NAV_CodDoc,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc1 END AS NAV_CodDoc1,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.TipDoc  END AS NAV_TipDoc,
    pkg_list_base_utils.decode_tipdoc(s.TipDoc) AS TipDoc,
    np.den_part, g.den_gest, fisc.codfiscal, slivr.obs LIVR_DEN, llivr.den_localit LIVR_LOC, jlivr.den_judet LIVR_JUD, zlivr.den_zona LIVR_ZONA, ncp.den_clasep,
    DECODE(np.blocat,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) BLOCAT, DECODE(s.blocat,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) BLOCATDOC, s.doc, s.nrdoc, s.datadoc, s.nri, s.obs OBSDOC, Coalesce(s.seriadoc,dc.serie) SERDOC,
    CASE WHEN ag_doc.codpers &lt;&gt; 0 THEN ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume ELSE ag_doc.nume END AGDOC,
    Coalesce(s.termen,s.datadoc) TERMEN, EXTRACT(YEAR FROM Coalesce(s.termen,s.datadoc)) TERMENAN, EXTRACT(MONTH FROM Coalesce(s.termen,s.datadoc)) TERMENLUNA,
    CASE
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 AND Coalesce(stins.valoare,0) &lt; 0 THEN Coalesce(s.restval,0) - Coalesce(stins.valoare,0)
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 THEN Coalesce(s.restval,0)
      ELSE s.valoare
    END &apos;||sConv||&apos; AS VALOARE,
    s.majorare,
    (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; AS REST,
    (s.resttva - Coalesce(stins.tva,0))&apos;    ||sConv||&apos; AS RESTTVA,
    Sum((s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos;) OVER (PARTITION BY s.codpart) AS RESTPART,
    CASE
      WHEN s.zile_depasire &lt;= 0 THEN 0
      ELSE ((s.restval - Coalesce(stins.valoare,0) - CASE WHEN o.semnificatie IN (210,410,430) THEN s.resttva - Coalesce(stins.tva,0) ELSE 0 END) * s.majorare/100 * s.zile_depasire)
    END &apos;||sConv||&apos; AS valmaj,
    DECODE(s.termen,NULL,0,s.termen - s.datadoc) ZILE_SCADENTA, CASE WHEN s.zile_trecute &gt; 0 THEN s.zile_trecute ELSE 0 END ZILE_TRECUTE, s.zile_depasire,
    NULLIF(s.doc    ||s.nrdoc    ||&apos;&apos;/&apos;&apos;||to_char(s.datadoc,    &apos;&apos;dd.mm.yyyy&apos;&apos;),&apos;&apos;/&apos;&apos;) DOCUMENT,
    NULLIF(s.leg_doc||s.leg_nrdoc||&apos;&apos;/&apos;&apos;||to_char(s.leg_datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;),&apos;&apos;/&apos;&apos;) DOCUMENT_LEG,
    mon.den_moneda MONEDA, nc.simbol CONT, cs.simbol CONTS,
    CASE WHEN s.zile_depasire &lt;= 0                THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END Z_0,
    CASE WHEN s.zile_depasire BETWEEN   1 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_1,
    CASE WHEN s.zile_depasire BETWEEN  31 AND  60 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_2,
    CASE WHEN s.zile_depasire BETWEEN  61 AND  90 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_3,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 120 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_4,
    CASE WHEN s.zile_depasire BETWEEN 121 AND 150 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_5,
    CASE WHEN s.zile_depasire BETWEEN 151 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_6,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_2,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_3,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 210 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_31,
    CASE WHEN s.zile_depasire BETWEEN 211 AND 240 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_32,
    CASE WHEN s.zile_depasire BETWEEN 241 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_33,
    CASE WHEN s.zile_depasire BETWEEN 271 AND 360 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_4,
    CASE WHEN s.zile_depasire BETWEEN   1 AND   7 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_1,
    CASE WHEN s.zile_depasire BETWEEN   8 AND  15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_2,
    CASE WHEN s.zile_depasire BETWEEN  16 AND  21 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_3,
    CASE WHEN s.zile_depasire BETWEEN  22 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_4,
    CASE WHEN s.zile_depasire &gt;  30               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_30,
    CASE WHEN s.zile_depasire &gt;  60               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_60,
    CASE WHEN s.zile_depasire &gt;  90               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_90,
    CASE WHEN s.zile_depasire &gt; 360               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_360,
    CASE WHEN s.zile_depasire BETWEEN  -7 AND  -1 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_1,
    CASE WHEN s.zile_depasire BETWEEN -14 AND  -8 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_2,
    CASE WHEN s.zile_depasire BETWEEN -21 AND -15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_3,
    CASE WHEN s.zile_depasire BETWEEN -28 AND -22 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_4,
    CASE WHEN s.zile_depasire &lt; -28               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_4p,
    sub.den_subunit SUBUNITATE, decode(s.exclusplata,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) EXCLUSPLATA,
    (s.restval - Coalesce(stins.valoare,0)) * Coalesce(s.coefprovizion,0) * CASE WHEN &apos;||pRegProviz||&apos; = 2 AND o.semnificatie = 1303 THEN s.cursini ELSE s.curs END PROVIZION,
    COALESCE (xa1.creditclient, np1.creditclient) CREDITC,
    TLSS.DECONT SERTDECONT, TLSS.DOC SERTDOC, TLSS.SER SERTSER, TLSS.NRDOC SERTNRDOC, TLSS.DATADOC SERTDATADOC, TLSS.VALOARE SERTVALDOC, TLSS.DATADECONT SERTDATADEC, TLSS.VALASOC SERTVALASOC,
    CC.DENUMIRE CENTRUCOST, CC.SIMBOL SIMBCENTRUCOST,
    CASE WHEN O.semnificatie IN (110111,210,211,310,330,410,430) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END AVANS, Coalesce(S.TVAMediu,0) PROCTVAMEDIU, DECODE(s.TvaIncasare,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) TVAINCAS,
    Coalesce(PCA.PARTVALIESAC,0) PARTVALIESAC, Coalesce(PCA.PARTVALIESAP,0) PARTVALIESAP,
    TO_CHAR( Coalesce(s.termen,s.datadoc+Coalesce(np.scadentav,0)),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Coalesce(cfc.valoare,1) CF_CURS,
    s.ansapt, s.curs, s.cursini&apos;||sCursRef||sFAdaosDoc||sValDiscZP||gUserAlias ||&apos;
  FROM tmp_scadentarcl s
    LEFT JOIN obligpif             o          ON o.codobligpif            = s.codobligpif
    LEFT JOIN npart                np         ON np.codpart               = s.codpart
    LEFT JOIN tmp_scadcl_coefg     cg         ON cg.codobligpif           = s.codobligpif
    LEFT JOIN ngest                g          ON g.codgest                = Coalesce(cg.codgest,0)
    LEFT JOIN tmp_lst_scad_stins   stins      ON stins.codstinspif        = s.codobligpif
    LEFT JOIN nmonede              mon        ON mon.codmoneda            = s.moneda
    LEFT JOIN ncont                nc         ON nc.codcont               = s.cont
    LEFT JOIN ncont1               nc1        ON nc1.codcont              = s.cont           AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN nc1.ALStart and nc1.ALStop
    LEFT JOIN nconts               cs         ON cs.codconts              = nc1.contsecundar
    LEFT JOIN npart1               np1        ON np1.codpart              = s.codpart        AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN np1.ALStart and np1.ALStop
    LEFT JOIN iopart               iop        ON iop.codiopart            = np1.codiopart
    LEFt JOIN NAGENDA1             xA1        ON xA1.CodAgenda            = s.codlocatie     AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN xA1.ALStart and xA1.ALStop
    LEFT JOIN NPARTCODFISC         FISC       ON fisc.codpart             = s.codpart        AND fisc.principal = 1
    LEFT JOIN NAGENDA              SSOC       ON ssoc.codpart             = s.codpart        AND Coalesce(ssoc.inactiv,0) = 0 AND ssoc.sediusocial Between 4 AND 7
    LEFT JOIN NAGENDA              SLIVR      ON slivr.codagenda          = CASE WHEN Coalesce(s.codlocatie,0) = 0 THEN ssoc.codagenda ELSE s.codlocatie END
    LEFT JOIN TRASEULIVR           TRASLIVR   ON traslivr.codtraseulivr   = slivr.codtraseu
    LEFT JOIN NTIPSEDII            TSLIVR     ON tslivr.codtipsediu       = slivr.codtipsediu
    LEFT JOIN NLOCALIT             LLIVR      ON llivr.codlocalit         = slivr.codlocalit
    LEFT JOIN NJUDET               JLIVR      ON jlivr.codjudet           = llivr.codjudet
    LEFT JOIN NZONE                ZLIVR      ON zlivr.codzona            = llivr.codzona
    LEFT JOIN NTARI                TLIVR      ON tlivr.codtara            = llivr.codtara
    LEFT JOIN NPERS                AG_SLIVR   ON ag_slivr.codpers         = Coalesce(slivr.codagent,0)
    LEFT JOIN NLOCALIT             LSOC       ON lsoc.codlocalit          = ssoc.codlocalit
    LEFT JOIN NJUDET               JSOC       ON jsoc.codjudet            = lsoc.codjudet
    LEFT JOIN NZONE                ZSOC       ON zsoc.codzona             = lsoc.codzona
    LEFT JOIN NTARI                TSOC       ON tsoc.codtara             = lsoc.codtara
    LEFT JOIN NPERS                AG_SSOC    ON ag_ssoc.codpers          = Coalesce(ssoc.codagent,0)
    LEFT JOIN NPERS                AG_DOC     ON ag_doc.codpers           = Coalesce(s.agent,0)
    LEFT JOIN nsubunit             sub        ON sub.codsubunit           = s.subunitatea
    LEFT JOIN NCLASEP              NCP        ON NCP.CODCLASEP            = NP.CODCLASA
    LEFT JOIN tmp_lst_scad_sertar  tlss       ON tlss.codobligpif         = s.codobligpif
    LEFT JOIN doccarnete           dc         ON dc.codcarnet             = s.carnetdoc
    LEFT JOIN CENTRECOST           CC         ON cc.codcentru             = Coalesce(s.codcentru,0)
    LEFT JOIN NPARTB               PB         ON PB.codpart               = s.codpart AND pb.implicit = 1
    LEFT JOIN NBANK                B          ON b.codbank                = pb.codbank
    LEFT JOIN TMP_SUBUNITDEDICATE  TS         ON ts.codsubunit            = s.subunitatea
    LEFT JOIN TMP_LST_CURS         cfc        ON cfc.codmoneda            = s.moneda
    LEFT JOIN TMP_LST_SCAD_PARTVAL pca        ON pca.partener             = s.codpart
	  LEFT JOIN TMP_UTILIZATOR       UTILIZATOR ON utilizator.codutilizator = s.userid&apos;||
    gSuplJoins||&apos;
  WHERE Abs(s.restval - Coalesce(stins.valoare,0)) &gt;= 0.01&apos;||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.DetTranzInCurs THEN &apos;
    AND NOT(o.semnificatie = 600 AND Coalesce(stins.valoare,0) &lt;&gt; 0)&apos;
    ELSE &apos;&apos;
  END;

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpname||&apos; SET CF_VALOARE = CF_CURS*REST&apos;;
  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    EXECUTE IMMEDIATE
     &apos;SELECT sum(valoare)
      FROM &apos;||tmpname||&apos;
      WHERE NAV_TipDoc IN (19,26)&apos;
    INTO aVTot;
    EXECUTE IMMEDIATE
     &apos;UPDATE &apos;||tmpname||&apos;
      SET valdiscv = pkg_contract.CALCULEAZA_DISCV_DOC(NAV_TipDoc,NAV_CodDoc,DataDoc,:VTot,Valoare)
      WHERE NAV_TipDoc IN (19,26)&apos;
    USING aVTot;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    i := 0;
    FOR vrec IN (SELECT fieldname, cod FROM TMP_DINAMIC_COLS ORDER BY INDEXLOCAL)
    LOOP
      i := i+1;
      sUpdate := sUpdate||&apos;,&apos;||vrec.Fieldname||&apos; = (CASE WHEN ansapt=&apos;||vrec.Cod||&apos; THEN rest ELSE 0 END)&apos;;
    END LOOP;
    sUpdate := &apos;UPDATE &apos;||tmpname||&apos; SET &apos;||SubStr(sUpdate,2);
    IF i &gt; 0 THEN
      EXECUTE IMMEDIATE sUpdate;
    END IF;
  END IF;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_List_Struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SCADENTARCL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36A936E1D29F28D705026756F144293ACA1037A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SCADENTARF IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  sConv       VARCHAR2(100);

FUNCTION  CalcAdaosDoc( pCodDoc IN NUMBER,
                        pRest   IN NUMBER)
          RETURN NUMBER
IS
  vTipDoc NUMBER;
  vValDoc NUMBER;
  vAdaos  NUMBER;
  vCurs   NUMBER;
BEGIN
  IF Coalesce(pRest,0) = 0 THEN
    RETURN 0;
  END IF;

  SELECT tipdoc, valdoc, Coalesce(Curs,1)
  INTO   vTipDoc,  vValDoc,  vCurs
  FROM intrari
  WHERE codintr = pCodDoc;

  IF vTipDoc IS NULL THEN
    RETURN 0;
  ELSIF vTipDoc = 9 THEN -- factura la aviz
    SELECT SUM(CASE io1.aretvaneex WHEN 1 THEN ns.adaos - ns.pret*Coalesce(ns.tva,0)/(1+Coalesce(ns.tva,0)) WHEN  2 THEN ns.adaos/(1+Coalesce(ns.tva,0)) ELSE ns.adaos END * ns.cantnir * i1.cant / a1.cant )
    INTO vAdaos
    FROM intrari i
      INNER JOIN intrari1 i1  ON i1.codintr   = i.codintr
      INNER JOIN intrlink il  ON il.codintr1  = i1.codintr1
      INNER JOIN intrari1 a1  ON a1.codintr1  = il.codlinieaviz
      INNER JOIN intrari  a   ON a.codintr    = a1.codintr
      INNER JOIN nir      n   ON n.codintr    = a.codintr   AND n.tipnir = a.tipdoc
      INNER JOIN nirstoc  ns  ON ns.codnir    = n.codnir    AND ns.codintr1 = a1.codintr1
      INNER JOIN ioart1   io1 ON io1.codioart = ns.codioart AND (a.an * 12 + a.luna) BETWEEN io1.ALStart AND io1.ALStop
    WHERE i.codintr = pCodDoc;
  ELSE
    SELECT SUM(CASE io1.aretvaneex WHEN 1 THEN ns.adaos - ns.pret*Coalesce(ns.tva,0)/(1+Coalesce(ns.tva,0)) WHEN 2 THEN ns.adaos/(1+Coalesce(ns.tva,0)) ELSE ns.adaos END * ns.cantnir)
    INTO vAdaos
    FROM intrari i
      INNER JOIN nir     n   ON n.codintr    = i.codintr   AND n.tipnir = i.tipdoc
      INNER JOIN nirstoc ns  ON ns.codnir    = n.codnir
      INNER JOIN ioart1  io1 on io1.codioart = ns.codioart AND (i.an * 12 + i.luna) BETWEEN io1.ALStart AND io1.ALStop
    WHERE i.codintr = pCodDoc;
  END IF;

  IF Coalesce(vValDoc,0) IN (0,1)
  THEN vAdaos := Coalesce(vAdaos,0) * pRest;
  ELSE vAdaos := Coalesce(vAdaos,0) * (pRest/vValDoc);
  END IF;

  RETURN vAdaos;
END;

PROCEDURE UMPLETMP(aLISTID IN NUMBER DEFAULT 0) IS
  sInsTMP        CLOB;
  sSelTMP        CLOB;
  sFiltruLuna    VARCHAR2(200) := &apos;&apos;;
  sAnP           NUMBER(4);
  sLunaP         NUMBER(2);
  sAnC           NUMBER(4);
  sLunaC         NUMBER(2);
  sZilePlusDoc   VARCHAR2(100);
  sZilePlusTerm  VARCHAR2(100);
  sZilePlusTermC VARCHAR2(100);
  dDataRef       DATE           := PKG_LIST_SELECTSCADENTAR.DataRef;
  dDataCoalesce  DATE           := LAST_DAY(ADD_MONTHS(dDataRef,-1));
  sDataRef       VARCHAR2(10)   := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);
  sDataCoalesce  VARCHAR2(10)   := To_Char(dDataCoalesce, &apos;dd.mm.yyyy&apos;);
  sJoinFiltru    VARCHAR2(500)  := &apos;&apos;;
  sIcontS_F      VARCHAR2(2500) := &apos;,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59&apos;;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_SCADENTARF&apos;;

  sZilePlusDoc  := &apos;(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) - Coalesce(D.DATADOC,TO_DATE(&apos;&apos;&apos;||sDataCoalesce||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)))&apos;;

  IF PKG_LIST_SELECTSCADENTAR.CodJob1 &gt; 0 THEN
    pkg_globals.SetLunaLucru_SIMPLA(extract(year from dDataRef), extract(month from dDataRef));
  END IF;
  SELECT ancurent, lunacurenta INTO sAnC, sLunaC FROM FIRMALUNI;
  IF (PKG_LIST_SELECTSCADENTAR.TipPerioada = 0) OR (sAnC*12+sLunaC &gt;= PKG_GLOBALS.ANLUNALUCRU) THEN
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, sAnP, sLunaP);
    sFiltruLuna := &apos; = &apos;||pkg_globals.AnLunaLucru;
  ELSE
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(sAnC, sLunaC, sAnP, sLunaP);
    sFiltruLuna := &apos; BETWEEN &apos;|| To_Char(sAnC*12+sLunaC)||&apos; AND &apos;||pkg_globals.AnLunaLucru;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.InLei
  THEN sConv := &apos;*CASE WHEN s.moneda = 0 THEN 1 ELSE s.Curs END&apos;;
  ELSE sConv := &apos;&apos;;
  END IF;

  IF aListID = 251 -- pe gestiuni
  THEN sConv := sConv||&apos;*Coalesce(cg.Coef,1)&apos;;
  END IF;

  IF NOT PKG_LIST_SELECTSCADENTAR.ToateClasele
  THEN
    sJoinFiltru := sJoinFiltru||&apos;
    INNER JOIN npart p ON p.codpart = o.codpart
    INNER JOIN TMP_MANEVRA_LISTE tmpc ON Coalesce(p.codclasa,0) = tmpc.valoare AND tmpc.filtru = &apos;&apos;CODCLASEP&apos;&apos; &apos;;
  END IF;

  IF NOT PKG_LIST_SELECTSCADENTAR.TotiPart
  THEN
    sJoinFiltru := sJoinFiltru||&apos;
    INNER JOIN TMP_MANEVRA_LISTE tmpp ON o.codpart = tmpp.valoare AND tmpp.filtru = &apos;&apos;CODPART&apos;&apos; &apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.TipIntarziere = 0
  THEN
    sZilePlusTerm  := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-Coalesce(O.TERMEN,D.DATADOC),0)&apos;;
    sZilePlusTermC := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-COALESCE(D.DATADECONT,O.TERMEN,D.DATADOC),0)&apos;;
  ELSE
    sZilePlusTerm  := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-D.DATADOC,0)&apos;;
    sZilePlusTermC := &apos;Coalesce(TO_DATE(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)-D.DATADOC,0)&apos;;
  END IF;

  sInsTMP :=
  &apos;INSERT INTO TMP_SCADENTARF (
    codobligpif,CodDoc,CodDoc1,TipDoc, codpart, doc, nrdoc, datadoc, nri, blocat, termen,
    valoare,
    tva,
    restval,
    restsplittva,
    resttva,
    majorare, zile_trecute, zile_depasire,
    cont, adaosdoc,
    moneda, cursini, obs, carnetdoc, seriadoc, subunitatea, agent, codlocatie, initializari,
    codgeneral, exclusplata,
    curs,
    codcentru, userid, tvamediu, tvaincasare, splittva, ansapt)&apos;;

	sSelTMP :=&apos;
  SELECT --FACTURI PERIOADA CURENTA
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    (o.valoare-
    CASE
      WHEN NOT(d.tiptva = 2 AND o.semnificatie=110) THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN d.tiptva = 2 AND o.semnificatie=110 THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END tva,
    (o.valoare-
    CASE
      WHEN NOT(d.tiptva = 2 AND o.semnificatie=110) THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END restval,
    Coalesce(o.dincaretva,0) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END restsplittva,
    CASE
      WHEN d.tiptva = 2 AND o.semnificatie=110 THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, NULL agent, d.codlocatie, d.Initializari,
    g.CodGeneral, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 5 THEN d.valdoc ELSE d.valdoc-d.tvadoc END*100,0),1),2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM intrari d
    INNER JOIN general g ON g.coddoc = d.codintr AND g.tipdoc = d.tipdoc
    INNER JOIN obligpif o ON o.codgeneral = g.codgeneral&apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE d.tipdoc IN (1,3,4,5,9)
    AND o.semnificatie IN (100,110,120)
    AND NOT (o.semnificatie = 110 AND Coalesce(g.tva,0)=o.valoare)
    AND d.an * 12 + d.luna&apos;||sFiltruLuna||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT --FACTURI CU SOLD LA INCEPUTUL PERIOADEI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    (o.valoare-
    CASE
      WHEN NOT(d.tiptva = 2 AND o.semnificatie=110) THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN d.tiptva = 2 AND o.semnificatie=110 THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END tva,
    (Coalesce(ol.rest,0)-CASE WHEN d.tiptva = 2 AND o.semnificatie=110 THEN Coalesce(ol.resttva,0) ELSE 0 END) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END restval,
    Coalesce(ol.restsplittva,0) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END restsplittva,
    CASE WHEN d.tiptva = 2 AND o.semnificatie=110 THEN 0 ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, NULL agent, d.codlocatie, d.Initializari,
    g.CodGeneral, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 5 THEN d.valdoc ELSE d.valdoc-d.tvadoc END*100,0),1),2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpifluna ol
    INNER JOIN obligpif o ON o.codobligpif = ol.codobligpif
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (1,3,4,5,9)
    INNER JOIN intrari d ON d.codintr = g.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    AND (Coalesce(ol.rest,0) &lt;&gt; 0 OR Coalesce(ol.resttva,0) &lt;&gt; 0)
    AND o.semnificatie IN (100,110,120)
    AND NOT (o.semnificatie = 110 AND Coalesce(g.tva,0)=o.valoare)&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT --FACTURI ANTERIOARE PERIOADEI CU STINGERI IN LUNA CURENTA SI CU SOLD 0 LA INCEPUTUL PERIOADEI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, Coalesce(d.PREFIXDOC,&apos;&apos;F&apos;&apos;) doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, d.nri, d.blocat, o.termen,
    (o.valoare-
    CASE
      WHEN NOT(d.tiptva = 2 AND o.semnificatie=110) THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END) * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END valoare,
    CASE
      WHEN d.tiptva = 2 AND o.semnificatie=110 THEN 0
      WHEN O.VALOARE = 0 THEN 0
      WHEN Coalesce(G.TVA,0) = 0 THEN 0
      WHEN (SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL) = 0 THEN 0
      ELSE Coalesce(G.TVA,0)*O.VALOARE/(SELECT SUM(xO.VALOARE) FROM OBLIGPIF xO WHERE xO.CODGENERAL = O.CODGENERAL)
    END * CASE WHEN o.semnificatie = 110 THEN -1 ELSE 1 END tva,
    0 restval,
    0 restsplitva,
    0 resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriadoc, d.subunitatea, NULL agent, d.codlocatie, d.Initializari,
    g.CodGeneral, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    round(d.tvadoc/Coalesce(NULLIF(CASE WHEN d.tipdoc = 5 THEN d.valdoc ELSE d.valdoc-d.tvadoc END*100,0),1),2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM (
    SELECT DISTINCT o.codobligpif
    FROM trezor t
      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
      INNER JOIN general gs ON gs.coddoc = t1.codtrezor1 AND gs.tipdoc = t.tipdoc
      INNER JOIN obligpif os ON os.codgeneral = gs.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = os.codobligpif
      INNER JOIN obligpif o ON o.codobligpif = s.codstinspif
      INNER JOIN general g ON g.codgeneral = o.codgeneral AND g.tipdoc IN (1,3,4,5,9)
      LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    WHERE t.tipdoc IN (29,30,31,33)
      AND gs.semnificatie = 700 AND (t.an*12+t.luna&apos;||sFiltruLuna||&apos;)
      AND o.semnificatie IN (100,110,120)
      AND NOT (o.semnificatie = 110 AND Coalesce(g.tva,0)=o.valoare)
      AND Coalesce(ol.rest,0) = 0 AND Coalesce(ol.resttva,0) = 0 &apos;||
      PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)||
      PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;t.DataDoc&apos;)||&apos;
  ) x
    INNER JOIN obligpif o ON o.codobligpif = x.codobligpif
    INNER JOIN general g ON g.codgeneral = o.codgeneral
    INNER JOIN intrari d ON d.codintr = g.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE d.an * 12 + d.luna &lt;= &apos;||To_Char(sAnP*12+sLunaP)||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT -- FACTURI EXTERNE  -- PLATI VAMA
    o.codobligpif, i.codintr, NULL coddoc1, i.tipdoc, o.codpart, &apos;&apos;DVI&apos;&apos; doc, Coalesce(d.nrdoc,0) nrdoc, d.datadoc, i.nri, i.blocat, o.termen,
    o.valoare, Coalesce(g.tva,0),
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(o.dincaretva,0) ELSE Coalesce(ol.restsplittva,0) END restsplittva,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare,&apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) curs, i.obs, i.carnetdoc, i.seriadoc, i.subunitatea, NULL agent, i.codlocatie, i.Initializari,
    g.CodGeneral, d.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, i.userid,
    round(i.tvadoc/Coalesce(NULLIF(CASE WHEN i.tipdoc = 5 THEN i.valdoc ELSE i.valdoc-i.tvadoc END*100,0),1),2) TVAMediu,
    Coalesce(d.TvaIncasare,0) TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 5
    INNER JOIN dvi d ON d.coddvi = g.coddoc
    INNER JOIN intrari i ON i.codintr = d.codintr &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie = 130
    AND ((i.an * 12 + i.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;i&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;i&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

  DELETE TMP_SCADF_COEFG;
  IF aListID = 251 THEN -- pe gestiuni
    INSERT INTO TMP_SCADF_COEFG ( CODOBLIGPIF, CODGEST, COEF)
    SELECT CODOBLIGPIF, CODGEST, CASE WHEN NRLINII = 1 THEN 1 WHEN VALTOT = VAL THEN 1 WHEN VALTOT = 0 THEN 0 ELSE VAL / VALTOT END
    FROM (
      SELECT
        S.CODOBLIGPIF, COALESCE(N.GEST, I1.GESTACT, 0) CODGEST, Sum(I1.PRETORIG*I1.COEFDISCMAJ*COALESCE(NS.CANTFURN,I1.CANT)) VAL,
        Count(1) OVER (PARTITION BY S.CODOBLIGPIF) NRLINII, Sum(Sum(I1.PRETORIG*I1.COEFDISCMAJ*COALESCE(NS.CANTFURN,I1.CANT))) OVER (PARTITION BY S.CODOBLIGPIF) VALTOT
      FROM TMP_SCADENTARF S
        LEFT JOIN INTRARI I ON I.CODINTR = S.CODDOC AND I.TIPDOC = S.TIPDOC
        LEFT JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
        LEFT JOIN NIR N ON N.CODINTR = I.CODINTR AND N.TIPNIR = I.TIPDOC
        LEFT JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR AND NS.CODINTR1 = I1.CODINTR1
      GROUP BY S.CODOBLIGPIF, COALESCE(N.GEST, I1.GESTACT, 0)
    );
  END IF;

	sSelTMP :=&apos;
  SELECT --TRANZACTII IN CURS -- TREZORERIE
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, d.doc, d.nrdoc, d.datadoc, d.nri, t.blocat, COALESCE(d.datadecont,o.termen,d.datadoc) termen,
    o.valoare, Coalesce(g.tva,0) tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(o.dincaretva,0) ELSE Coalesce(ol.restsplittva,0) END restsplittva,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTermC||&apos; zile_depasire,
  	PKG_TREZOR.CODCONTCEC(t.CodBanca, o.Semnificatie, d.Tipdecont, d.obiecttranz, t.an, t.luna) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) cursini, d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea, COALESCE(NullIf(d.agent,0),t.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, t.userid,
    0 TVAMediu,
    0 TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 31
    INNER JOIN trezor1 d ON d.codtrezor1 = g.coddoc
    INNER JOIN trezor t ON t.codtrezor = d.codtrezor &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie = 500
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
  CASE
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma AND PKG_GLOBALS.GETSUBUNITATE &gt; 1 THEN &apos;
    AND (
      t.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      OR
      EXISTS (
        SELECT 1
        FROM general gg
          INNER JOIN obligpif og ON og.codgeneral = gg.codgeneral
          INNER JOIN stingere s ON s.codstingatorpif = og.codobligpif
          INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
          INNER JOIN general gs ON gs.codgeneral = os.codgeneral
          INNER JOIN intrari i ON i.codintr = gs.coddoc AND i.tipdoc = gs.tipdoc
        WHERE gg.coddoc = g.coddoc AND gg.tipdoc = g.tipdoc AND gg.semnificatie &lt;&gt; g.semnificatie
          AND i.subunitatea = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
      )
    )&apos;
    WHEN PKG_LIST_SELECTSCADENTAR.TranzCursFirma THEN NULL
    ELSE PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)
  END;

  IF PKG_LIST_SELECTSCADENTAR.CuTranzInCurs THEN
    LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);
  END IF;

	sSelTMP :=&apos;
  SELECT --TREZORERIE - PLATI IN AVANS, RETUR CEC
    o.codobligpif, t.codtrezor, d.codtrezor1 coddoc1, g.tipdoc, o.codpart, d.doc, d.nrdoc, d.datadoc, d.nri, t.blocat, Coalesce(d.datadecont,o.termen) termen,
    o.valoare * CASE WHEN o.semnificatie = 310 THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 310 THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 310 THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(o.dincaretva,0) ELSE Coalesce(ol.restsplittva,0) END * CASE WHEN o.semnificatie = 310 THEN -1 ELSE 1 END restsplittva,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 310 THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) curs,  d.obs, d.carnetdoc, d.seriedoc seriadoc, t.subunitatea,  COALESCE(NullIf(d.agent,0),t.agent) agent, d.codlocatie, d.Initializari,
    g.CodGeneral, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, t.userid,
    0 TVAMediu,
    0 TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(d.datadecont,o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (29,30,31,33)
    INNER JOIN trezor1 d ON d.codtrezor1 = g.coddoc
    INNER JOIN trezor t ON t.codtrezor = d.codtrezor &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie IN (310,430)
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0))&apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;t&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;t&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT --NOTE CONTABILE LEGATE DE PARTENERI
    o.codobligpif, d.codnc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;NC&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    CASE WHEN o.icont IN (4,12) THEN -1 ELSE 1 END*o.valoare , CASE WHEN o.icont IN (4,12) THEN -1 ELSE 1 END*Coalesce(g.tva,0) tva,
    CASE WHEN o.icont IN (4,12) THEN -1 ELSE 1 END*CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END restval,
    CASE WHEN o.icont IN (4,12) THEN -1 ELSE 1 END*CASE WHEN ol.codobligpif IS NULL THEN Coalesce(o.dincaretva,0) ELSE Coalesce(ol.restsplittva,0) END restsplittva,
    CASE WHEN o.icont IN (4,12) THEN -1 ELSE 1 END*CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) curs, nc1.obs, d.carnetdoc, NULL seriadoc, d.subunitatea, nc1.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    0 TVAMediu,
    0 TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc IN (35)
    INNER JOIN nc1 ON nc1.codnc1 = g.coddoc
    INNER JOIN nc d ON d.codnc = nc1.codnc &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.icont IN (2,4,8,9,12,13,14,15,16,19,21,22&apos;||sIcontS_F||&apos;)  -- 6 - facturi de incasat - trebuie exclus
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	sSelTMP :=&apos;
  SELECT --COMPENSARI
    o.codobligpif, g.coddoc, NULL coddoc1, g.tipdoc, o.codpart, &apos;&apos;PV&apos;&apos; doc, d.nrdoc, d.datadoc, &apos;&apos; &apos;&apos; nri, 0 blocat, o.termen,
    o.valoare * CASE WHEN o.semnificatie = 1301 AND o.icont NOT IN (2) THEN -1 ELSE 1 END valoare, Coalesce(g.tva,0) * CASE WHEN o.semnificatie = 1301 AND o.icont NOT IN (2) THEN -1 ELSE 1 END tva,
    CASE WHEN ol.codobligpif IS NULL THEN o.valoare ELSE ol.rest END * CASE WHEN o.semnificatie = 1301 AND o.icont NOT IN (2) THEN -1 ELSE 1 END restval,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(o.dincaretva,0) ELSE Coalesce(ol.restsplittva,0) END * CASE WHEN o.semnificatie = 1301 AND o.icont NOT IN (2) THEN -1 ELSE 1 END restsplittva,
    CASE WHEN ol.codobligpif IS NULL THEN Coalesce(g.tva,0) ELSE Coalesce(ol.resttva,0) END * CASE WHEN o.semnificatie = 1301 AND o.icont NOT IN (2) THEN -1 ELSE 1 END resttva,
    Coalesce(o.majorari,0) majorare, &apos;||sZilePlusDoc||&apos; zile_trecute, &apos;||sZilePlusTerm||&apos; zile_depasire,
  	PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||pkg_globals.AnLunaLucru||&apos;,o.semnificatie) cont, o.adaosdoc,
    Coalesce(g.moneda,0) Moneda, COALESCE(NullIf(g.curs,0), 1) curs,  d.obsd obs, d.carnetdoc, NULL seriadoc, d.subunitatea, d.agent, 0 codlocatie, 0 Initializari,
    g.CodGeneral, g.exclusplata,
    Coalesce(rc.curs, NullIf(g.curs,0), 1) curs,
    o.codcentru, d.userid,
    0 TVAMediu,
    0 TvaIncasare, Coalesce(o.splittva,0) SplitTVA, to_char(Coalesce(o.termen,d.datadoc), &apos;&apos;IYYYIW&apos;&apos;)
  FROM obligpif o
    INNER JOIN general g ON o.codgeneral = g.codgeneral AND g.tipdoc = 28
    INNER JOIN compens d ON d.codcompens = g.coddoc &apos;||
    sJoinFiltru||&apos;
    LEFT JOIN obligpifluna ol ON ol.codobligpif = o.codobligpif AND ol.an = &apos;||sAnP||&apos; AND ol.luna = &apos;||sLunaP||&apos;
    LEFT JOIN (
      SELECT r1.CodGeneral, MAX(r.curs) KEEP (DENSE_RANK LAST ORDER BY r.an * 12 + r.luna, r.datadoc) curs
      FROM reg r INNER JOIN reg1 r1 ON r1.codreg = r.codreg
      WHERE  r.an * 12 + r.luna &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      GROUP BY r1.CodGeneral
    ) rc ON rc.codgeneral = g.codgeneral
  WHERE o.semnificatie IN (1301,1351)
    AND o.icont IN (2,4,8,9,12,13,14,15&apos;||sIcontS_F||&apos;) -- 6 - facturi de incasat - trebuie exclus
    AND ((d.an * 12 + d.luna&apos;||sFiltruLuna||&apos;) OR (Coalesce(ol.rest,0) &lt;&gt; 0) OR (Coalesce(ol.resttva,0) &lt;&gt; 0)) &apos;||
    PKG_LIST_SELECTSCADENTAR.COND_SUBUNIT(&apos;d&apos;)||
    PKG_LIST_BASE_UTILS.COND_USERID (&apos;d&apos;)||
    PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;d.DataDoc&apos;);

  LIST_EXECUTE_IMMEDIATE(sInstmp||sSeltmp, aLISTID, 0);

	DELETE FROM tmp_dinamic_cols;
  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    INSERT INTO tmp_dinamic_cols (fieldname, display, indexlocal, cod)
    SELECT &apos;D&apos;||ROWNUM, TRUNC(ANSAPT/100)||&apos; Sapt.&apos;||To_Char(Mod(ANSAPT,100),&apos;fm00&apos;), ROWNUM, ANSAPT
    FROM (
      SELECT DISTINCT ANSAPT
      FROM TMP_SCADENTARF
      WHERE ANSAPT IS NOT NULL
      ORDER BY ANSAPT
    );
  END IF;

  sInsTmp:=
  &apos;INSERT INTO tmp_lst_scad_stins  (codstinspif, valoare, tva, dincaretva)
  SELECT codstinspif, SUM( valoare * semn) valoare, SUM(tva*semn) tva, SUM(dincaretva*semn) valoare
  FROM (
    SELECT
      s.codstinspif,
      Abs(s.valoare-CASE WHEN Coalesce(i.tiptva,0) = 2 AND o.semnificatie=110 THEN Coalesce(g.tva,0) ELSE 0 END) valoare,
      Abs(Coalesce(s.dincaretva,0)) dincaretva,
      CASE WHEN Coalesce(i.tiptva,0) = 2 AND o.semnificatie=110 THEN 0 ELSE Abs(Coalesce(g.tva,0)) END Tva,
      CASE
        -- la resturi nesemnificative nu poate fi determinat semnul in functie de valoare initiala a obligatiei (posibil sa se fi platit mai mult si atunci e semn invers)
        WHEN OS.SEMNIFICATIE = 1300 AND O.SEMNIFICATIE = 100 AND Coalesce(s.valoare, 0)    &lt;&gt; 0 THEN SIGN(s.valoare)
        WHEN OS.SEMNIFICATIE = 1300 AND O.SEMNIFICATIE = 100 AND Coalesce(s.dincaretva, 0) &lt;&gt; 0 THEN SIGN(s.dincaretva)
        ELSE
          CASE WHEN Coalesce(o.valoare,0) &lt; 0 THEN -1 ELSE 1 END *
          CASE
            WHEN OS.SEMNIFICATIE = 700                                                                                             THEN -1
            WHEN OS.SEMNIFICATIE = 1300 AND O.ICONT  = 2       AND      O.SEMNIFICATIE IN (     1200      ) AND O.ICONT = 2        THEN  1
            WHEN OS.SEMNIFICATIE = 1300 AND O.ICONT  = 2       AND NOT (O.SEMNIFICATIE IN (130,       1201)                      ) THEN -1
            WHEN OS.SEMNIFICATIE = 1300 AND OS.ICONT IN (4,12) AND NOT (O.SEMNIFICATIE IN (110, 1200, 1201) AND O.ICONT IN (4,12)) THEN -1
            ELSE 1
          END *
          CASE
            WHEN O.SEMNIFICATIE IN (1200, 1201) AND     O.ICONT IN ( 4,12)      THEN -1
            WHEN O.SEMNIFICATIE = 1301          AND NOT O.ICONT IN ( 2 )        THEN -1
            WHEN O.SEMNIFICATIE = 1351          AND     O.ICONT IN ( 2 )        THEN -1
            WHEN O.SEMNIFICATIE IN (110,310)                                    THEN -1
            WHEN O.SEMNIFICATIE = 430           AND NOT O.ICONT IN (12, 13, 14) THEN -1
            ELSE 1
          END
      END semn
    FROM stingere s
      INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
      INNER JOIN obligpif o  ON o.codobligpif = s.codstinspif
      INNER JOIN general  g  ON g.codgeneral = os.codgeneral&apos;||
      sJoinFiltru||&apos;
      LEFT JOIN trezor1 t1   ON t1.codtrezor1 = g.coddoc AND g.tipdoc IN (29,30,31,33)
      LEFT JOIN compens c    ON c.codcompens  = g.coddoc AND g.tipdoc = 28
      LEFT JOIN intrari i    ON i.codintr     = g.coddoc AND i.tipdoc = g.tipdoc --AND os.semnificatie IN (111)
    WHERE COALESCE(i.an * 12 + i.luna,t1.an * 12 + t1.luna,c.an * 12 + c.luna)&apos;||sFiltruLuna||
      PKG_LIST_SELECTSCADENTAR.FiltruData(&apos;i.DataDoc,t1.DataDoc,c.DataDoc&apos;)||&apos;
  ) GROUP BY codstinspif&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_lst_scad_stins&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, 0);

  sInsTmp:=
  &apos;INSERT INTO tmp_lst_scad_sertar(codobligpif, decont, doc, ser, nrdoc, datadoc, valoare, datadecont, valasoc)
    SELECT
      ns1.codobligpif,
      vc2_nt_to_vc3200(CAST(collect(DISTINCT CASE NS.DECONT WHEN 3 THEN &apos;&apos;Efecte remise&apos;&apos; WHEN 2 THEN &apos;&apos;Efecte acceptate&apos;&apos; ELSE &apos;&apos;Cecuri&apos;&apos; END) AS vc2_nt)) decont,
      vc2_nt_to_vc3200(CAST(collect(NS.DOC||&apos;&apos; &apos;&apos;||NS.NRDOC||&apos;&apos;/&apos;&apos;||To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) doc,
      vc2_nt_to_vc3200(CAST(collect(NS.DOC ORDER BY NS.CODSERTAR) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.NRDOC) ORDER BY NS.CODSERTAR) AS vc2_nt)) nrdoc,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.DATADOC,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadoc,
      SUM(NS.VALOARE  * CASE WHEN NS.TIP = 1 THEN -1 ELSE 1 END) VALOARE,
      vc2_nt_to_vc3200(CAST(collect(To_char(NS.DATADECONT,&apos;&apos;dd.mm.yyyy&apos;&apos;) ORDER BY NS.CODSERTAR) AS vc2_nt)) datadecont,
      SUM(NS1.VALOARE * CASE WHEN NS.TIP = 1 THEN -1 ELSE 1 END) VALASOC
    FROM nsertar1 ns1
      LEFT JOIN nsertar ns ON ns.codsertar = ns1.codsertar
      LEFT JOIN trezor1 t1 ON t1.codsertar = ns1.codsertar AND (t1.an * 12 + t1.luna) &lt;= &apos;||pkg_globals.AnLunaLucru||&apos;
      LEFT JOIN obligpif o ON o.codobligpif = ns1.codobligpif
    WHERE t1.codtrezor IS NULL
    GROUP BY ns1.codobligpif&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_lst_scad_sertar&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, 0);
  COMMIT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sUpdate    VARCHAR2(30000);
  sFAdaosDoc VARCHAR2(1000)   := &apos;, NULL ADAOS&apos;;
  sValDiscZP VARCHAR2(500)   := &apos;, NULL VALDISCZP, null VALDISCC&apos;;
  sCursRef   VARCHAR2(100)   := &apos;, 1&apos;;
  dDataRef   DATE            := PKG_LIST_SELECTSCADENTAR.DataRef;
  sDataRef   VARCHAR2(10)    := To_Char(dDataRef, &apos;dd.mm.yyyy&apos;);

  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  aVTot      NUMBER(20, 7);
  i          INTEGER;
BEGIN
  IF NOT PKG_LIST_SELECTSCADENTAR.TMPOk THEN
    UmpleTmp(aListId);
  END IF;

  gSuplCols :=
    &apos;TMP_SCADENTARF S, TMP_LST_SCAD_STINS STINS, OBLIGPIF O, NPART NP, NPART1 NP1, IOPART IOP, NMONEDE MON, NPARTCODFISC FISC, CENTRECOST CC, &apos;||
    &apos;NAGENDA SLIVR, NLOCALIT LLIVR, NJUDET JLIVR, NZONE ZLIVR, NTARI TLIVR, NPERS AG_SLIVR,&apos;||
    &apos;NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NZONE ZSOC, NTARI TSOC, NPERS AG_SSOC,&apos;||
    &apos;NPERS AG_DOC, NCLASEP NCP, NCONT NC, NCONT1 NC1, NCONTS CS, DOCCARNETE DC, NPARTB PB, NBANK B, TMP_UTILIZATOR UTILIZATOR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;, &apos;PD&apos;, &apos;pd.codpart = s.codpart&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;, &apos;IEXT&apos;, &apos;iext.codintr = s.coddoc AND s.tipdoc IN (1, 9)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
   sCursRef := &apos;, PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, s.datadoc )&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcAdaosDoc THEN
    sFAdaosDoc := &apos;,
    CASE
      WHEN o.semnificatie IN (110,111)                               THEN 0
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0 AND Coalesce(s.Valoare,0) = 0 THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))
      WHEN Coalesce(s.AdaosDoc,0) &lt;&gt; 0                               THEN s.AdaosDoc * (s.restval - Coalesce(stins.valoare,0))/s.Valoare
      ELSE PKG_LIST_BASE_SCADENTARF.CalcAdaosDoc(S.CodDoc,s.restval - Coalesce(stins.valoare,0))
    END&apos;||sConv||&apos; ADAOS&apos;;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    sValDiscZP := &apos;,
    Coalesce(PKG_CONTRACT.CALCULEAZA_DISCT_DOC(s.TipDoc, s.CodDoc, &apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;, (s.restval - Coalesce(stins.valoare,0))), 0)&apos;||sConv||&apos; VALDISCZP,
    Coalesce(PKG_CONTRACT.CALCULEAZA_DISCC_DOC(s.TipDoc, s.CodDoc, To_date(&apos;&apos;&apos;||sDataRef||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;), (s.restval - Coalesce(stins.valoare,0))), 0)&apos;||sConv||&apos; VALDISCC&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_CodDoc1,NAV_TipDoc,TipDoc,
    DENPART,DENGEST,CODFISCAL,LIVR_DEN,LIVR_LOC, LIVR_JUD, LIVR_ZONA, DENCLASAP,
    BLOCAT,BLOCATDOC,PREFDOC,NRDOC,DATADOC,NRI,OBSDOC,SERDOC,
    AGDOC,
    TERMEN,TERMENAN,TERMENLUNA,
    VALOARE,
    MAJORARE,
    REST,
    RESTSPLITTVA,
    RESTTVA,
    RESTPART,
    VALMAJ,
    ZILE_SCADENTA,ZILE_TRECUTE,ZILE_DEPASIRE,
    DOCUMENT, MONEDA,CONT,CONTS,
    Z_0,L_1,L_2,L_3,L_4,L_5,L_6,T_2,T_3,T_31,T_32,T_33,T_4,S_1,S_2,S_3,S_4,P_30,P_60,P_90,P_360,TS_1,TS_2,TS_3,TS_4,TS_4p,
    SUBUNITATE, EXCLUSPLATA, CREDITF, SERTDECONT, SERTDOC, SERTSER, SERTNRDOC, SERTDATADOC, SERTVALDOC, SERTDATADEC, SERTVALASOC, CENTRUCOST, SIMBCENTRUCOST,
    AVANS, PROCTVAMEDIU,
    TVAINCAS, SPLITTVA,
    VALMT103,
    CF_AS, CF_CURS,
    ANSAPT, CURS,CURS_INI,CURS_REF,ADAOSDOC,VALDISCZP, VALDISCC &apos;||gUserFields||&apos;)&apos;;

	sSelect :=&apos;
  SELECT
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc END NAV_CodDoc,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.CodDoc1 END NAV_CodDoc1,
    CASE WHEN ts.codsubunit IS NULL OR s.initializari = 1 THEN NULL ELSE s.TipDoc END NAV_TipDoc,
    pkg_list_base_utils.decode_tipdoc(s.TipDoc) TipDoc,
    np.den_part, g.den_gest, fisc.codfiscal, slivr.obs LIVR_DEN, llivr.den_localit LIVR_LOC, jlivr.den_judet LIVR_JUD, zlivr.den_zona LIVR_ZONA, ncp.den_clasep,
    CASE WHEN np.blocat = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END BLOCAT, CASE WHEN s.blocat = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END BLOCATDOC, s.doc, s.nrdoc, s.datadoc, s.nri, s.obs OBSDOC, Coalesce(s.seriadoc,dc.serie) SERDOC,
    CASE WHEN ag_doc.codpers &lt;&gt; 0 THEN ag_doc.nume||&apos;&apos; &apos;&apos;||ag_doc.prenume ELSE ag_doc.nume END AGDOC,
    Coalesce(s.termen,s.datadoc) TERMEN, EXTRACT(YEAR FROM Coalesce(s.termen,s.datadoc)) TERMENAN, EXTRACT(MONTH FROM Coalesce(s.termen,s.datadoc)) TERMENLUNA,
    CASE
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 AND Coalesce(stins.valoare,0) &lt; 0 THEN Coalesce(s.restval,0) - Coalesce(stins.valoare,0)
      WHEN s.initializari = 1 AND Coalesce(s.valoare,0) = 0 THEN Coalesce(s.restval,0)
      ELSE s.valoare
    END &apos;||sConv||&apos; VALOARE,
    s.majorare,
    (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; REST,
    (s.restsplittva - Coalesce(stins.dincaretva,0))&apos;||sConv||&apos; RESTTVA,
    (s.resttva - Coalesce(stins.tva,0))&apos;||sConv||&apos; RESTTVA,
    Sum((s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos;) OVER (PARTITION BY s.codpart) RESTPART,
    CASE
      WHEN s.zile_depasire &lt;= 0 THEN 0
      ELSE ((s.restval - Coalesce(stins.valoare,0) - CASE WHEN o.semnificatie IN (110,310,330) THEN s.resttva - Coalesce(stins.tva,0) ELSE 0 END) * s.majorare/100 * s.zile_depasire)
    END &apos;||sConv||&apos; valmaj,
    COALESCE(s.termen - s.datadoc,0) ZILE_SCADENTA, CASE WHEN s.zile_trecute &gt; 0 THEN s.zile_trecute ELSE 0 END ZILE_TRECUTE, s.zile_depasire,
    s.doc||s.nrdoc||&apos;&apos;/&apos;&apos;||to_char(s.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOCUMENT, mon.den_moneda MONEDA, nc.simbol CONT, cs.simbol CONTS,
    CASE WHEN s.zile_depasire &lt;= 0                THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END Z_0,
    CASE WHEN s.zile_depasire BETWEEN   1 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_1,
    CASE WHEN s.zile_depasire BETWEEN  31 AND  60 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_2,
    CASE WHEN s.zile_depasire BETWEEN  61 AND  90 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_3,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 120 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_4,
    CASE WHEN s.zile_depasire BETWEEN 121 AND 150 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_5,
    CASE WHEN s.zile_depasire BETWEEN 151 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END L_6,
    CASE WHEN s.zile_depasire BETWEEN  91 AND 180 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_2,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_3,
    CASE WHEN s.zile_depasire BETWEEN 181 AND 210 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_31,
    CASE WHEN s.zile_depasire BETWEEN 211 AND 240 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_32,
    CASE WHEN s.zile_depasire BETWEEN 241 AND 270 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_33,
    CASE WHEN s.zile_depasire BETWEEN 271 AND 360 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END T_4,
    CASE WHEN s.zile_depasire BETWEEN   1 AND   7 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_1,
    CASE WHEN s.zile_depasire BETWEEN   8 AND  15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_2,
    CASE WHEN s.zile_depasire BETWEEN  16 AND  21 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_3,
    CASE WHEN s.zile_depasire BETWEEN  22 AND  30 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END S_4,
    CASE WHEN s.zile_depasire &gt;  30               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_30,
    CASE WHEN s.zile_depasire &gt;  60               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_60,
    CASE WHEN s.zile_depasire &gt;  90               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_90,
    CASE WHEN s.zile_depasire &gt; 360               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END P_360,
    CASE WHEN s.zile_depasire BETWEEN  -7 AND  -1 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_1,
    CASE WHEN s.zile_depasire BETWEEN -14 AND  -8 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_2,
    CASE WHEN s.zile_depasire BETWEEN -21 AND -15 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_3,
    CASE WHEN s.zile_depasire BETWEEN -28 AND -22 THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_4,
    CASE WHEN s.zile_depasire &lt; -28               THEN (s.restval - Coalesce(stins.valoare,0))&apos;||sConv||&apos; ELSE 0 END TS_4p,
    sub.den_subunit SUBUNITATE, CASE WHEN s.exclusplata = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END EXCLUSPLATA, np1.creditfurn CREDITF,
    TLSS.DECONT SERTDECONT, TLSS.DOC SERTDOC, TLSS.SER SERTSER, TLSS.NRDOC SERTNRDOC, TLSS.DATADOC SERTDATADOC, TLSS.VALOARE SERTVALDOC, TLSS.DATADECONT SERTDATADEC, TLSS.VALASOC SERTVALASOC,
    CC.DENUMIRE CENTRUCOST, CC.SIMBOL SIMBCENTRUCOST,
    CASE WHEN O.semnificatie IN (110,111,210,211,310,330,410,430) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END AVANS, Coalesce(s.TVAMediu,0) PROCTVAMEDIU,
    CASE WHEN s.TvaIncasare = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END TVAINCAS, CASE WHEN s.SplitTVA = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END SPLITTVA,
    Coalesce(
      ( SELECT SUM(Coalesce(p1103.REST,0))
        FROM plati1 p1103 INNER JOIN PLATI P ON P.CODPLATA = P1103.CODPLATA
        WHERE p1103.codobligpif = s.codobligpif AND P1103.REST &lt;&gt; 0
      ), 0) VALMT103,
    TO_CHAR( Coalesce(s.termen,s.datadoc+Coalesce(np.scadentac,0)),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS, Coalesce(cfc.valoare,1) CF_CURS,
    s.ansapt, s.curs,s.cursini&apos;||sCursRef||sFAdaosDoc||sValDiscZP||gUserAlias||&apos;
  FROM tmp_scadentarf s
    LEFT JOIN obligpif            o          ON o.codobligpif            = s.codobligpif
    LEFT JOIN npart               np         ON np.codpart               = s.codpart
    LEFT JOIN tmp_scadf_coefg     cg         ON cg.codobligpif           = s.codobligpif
    LEFT JOIN ngest               g          ON g.codgest                = Coalesce(cg.codgest,0)
    LEFT JOIN tmp_lst_scad_stins  stins      ON stins.codstinspif        = s.codobligpif
    LEFT JOIN nmonede             mon        ON mon.codmoneda            = s.moneda
    LEFT JOIN ncont               nc         ON nc.codcont               = s.cont
    LEFT JOIN ncont1              nc1        ON nc1.codcont              = s.cont    AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN nc1.ALStart and nc1.ALStop
    LEFT JOIN nconts              cs         ON cs.codconts              = nc1.contsecundar
    LEFT JOIN npart1              np1        ON np1.codpart              = s.codpart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN np1.ALStart and np1.ALStop
    LEFT JOIN iopart              iop        ON iop.codiopart            = np1.codiopart
    LEFT JOIN NPARTCODFISC        FISC       ON fisc.codpart             = s.codpart AND fisc.principal = 1
    LEFT JOIN NAGENDA             SSOC       ON ssoc.codpart             = s.codpart AND Coalesce(ssoc.inactiv,0) = 0 AND ssoc.sediusocial Between 4 AND 7
    LEFT JOIN NAGENDA             SLIVR      ON slivr.codagenda          = CASE WHEN Coalesce(s.codlocatie,0) = 0 THEN ssoc.codagenda ELSE s.codlocatie END
    LEFT JOIN NLOCALIT            LLIVR      ON llivr.codlocalit         = slivr.codlocalit
    LEFT JOIN NJUDET              JLIVR      ON jlivr.codjudet           = llivr.codjudet
    LEFT JOIN NZONE               ZLIVR      ON zlivr.codzona            = llivr.codzona
    LEFT JOIN NTARI               TLIVR      ON tlivr.codtara            = llivr.codtara
    LEFT JOIN NPERS               AG_SLIVR   ON ag_slivr.codpers         = Coalesce(slivr.codagent,0)
    LEFT JOIN NLOCALIT            LSOC       ON lsoc.codlocalit          = ssoc.codlocalit
    LEFT JOIN NJUDET              JSOC       ON jsoc.codjudet            = lsoc.codjudet
    LEFT JOIN NZONE               ZSOC       ON zsoc.codzona             = lsoc.codzona
    LEFT JOIN NTARI               TSOC       ON tsoc.codtara             = lsoc.codtara
    LEFT JOIN NPERS               AG_SSOC    ON ag_ssoc.codpers          = Coalesce(ssoc.codagent,0)
    LEFT JOIN NPERS               AG_DOC     ON ag_doc.codpers           = Coalesce(s.agent,0)
    LEFT JOIN nsubunit            sub        ON sub.codsubunit           = s.subunitatea
    LEFT JOIN NCLASEP             NCP        ON ncp.codclasep            = np.codclasa
    LEFT JOIN tmp_lst_scad_sertar tlss       ON tlss.codobligpif         = s.codobligpif
    LEFT JOIN doccarnete          dc         ON dc.codcarnet             = s.carnetdoc
    LEFT JOIN CENTRECOST          CC         ON cc.codcentru             = Coalesce(s.codcentru,0)
    LEFT JOIN NPARTB              PB         ON PB.codpart               = s.codpart AND pb.implicit = 1
    LEFT JOIN NBANK               B          ON b.codbank                = pb.codbank
    LEFT JOIN TMP_SUBUNITDEDICATE TS         ON ts.codsubunit            = s.subunitatea
	  LEFT JOIN TMP_UTILIZATOR      UTILIZATOR ON utilizator.codutilizator = s.userid
    LEFT JOIN TMP_LST_CURS        cfc        ON cfc.codmoneda            = s.moneda&apos;||
    gSuplJoins||&apos;
  WHERE (Abs(s.restval - Coalesce(stins.valoare,0)) &gt;= 0.01 OR Abs(s.restsplittva - Coalesce(stins.dincaretva,0)) &gt;= 0.01)&apos;;

  --PKG_GLOBALS.SetSeparator(&apos;;&apos;);
  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;

  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE tmp_lst_scad_stins SET VALOARE = VALOARE+DINCARETVA&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;||tmpname||&apos; SET CF_VALOARE = CF_CURS*REST&apos;, aListID, aListVer);
  IF PKG_LIST_SELECTSCADENTAR.CalcDiscTermen THEN
    EXECUTE IMMEDIATE &apos;SELECT sum(valoare) FROM &apos;||tmpname||&apos; WHERE NAV_TipDoc IN (1,9)&apos; INTO aVTot;
    EXECUTE IMMEDIATE &apos;UPDATE &apos;||tmpname||&apos; SET valdiscv = pkg_contract.CALCULEAZA_DISCV_DOC(NAV_TipDoc,NAV_CodDoc,DataDoc,:VTot,Valoare) WHERE NAV_TipDoc IN (1, 9)&apos; USING aVTot;
  END IF;

  IF PKG_LIST_SELECTSCADENTAR.ValSapt THEN
    i := 0;
    FOR vrec IN (SELECT fieldname, cod FROM TMP_DINAMIC_COLS ORDER BY INDEXLOCAL)
    LOOP
      i := i+1;
      sUpdate := sUpdate||&apos;,&apos;||vrec.Fieldname||&apos; = CASE WHEN ansapt = &apos;||vrec.Cod||&apos; THEN rest ELSE 0 END&apos;;
    END LOOP;
    sUpdate := &apos;UPDATE &apos;||tmpname||&apos; SET &apos;||SubStr(sUpdate,2);
    IF i &gt; 0 THEN
      EXECUTE IMMEDIATE sUpdate;
    END IF;
  END IF;

  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_List_Struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SCADENTARF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SCADENTARLEASING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD6C845848E43D58ABC09CF36F393D389812EFBA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_scadentarleasing IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(15000);
  sSelect     VARCHAR2(20000);
  sUpdate     VARCHAR2(15000);
  sDoc        VARCHAR2(100);
  sCodDoc     VARCHAR2(100);
  sTipContr   VARCHAR2(100);
  sCondDataC  VARCHAR2(100);
  sCondDataI  VARCHAR2(100);
  sCondDataC2 VARCHAR2(100);
  sCondDataC0 VARCHAR2(100);
  sCondCurs   VARCHAR2(100);
  vDataAux    DATE;

BEGIN
  gSuplCols := &apos;contract c, contract2 c2, npart p, nmonede mc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  CASE PKG_LIST_SELMOMENT.GetTip
    WHEN 2 THEN
      vDataAux    := PKG_LIST_SELMOMENT.GetDataRef;
      sCondDataI  := &apos; AND I.DATADOC &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondDataC  := &apos; AND C.DATASTART &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondDataC2 := &apos; AND NVL(C2.DATADOC,C2.DATA) &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondDataC0 := &apos; AND C0.DATADOC &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondCurs   := &apos; AND C0.DATA &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
    WHEN 1 THEN
      vDataAux    := Last_Day(To_Date(PKG_GLOBALS.GetAnLucru||&apos;.&apos;||PKG_GLOBALS.GetLunaLucru,&apos;YYYY.MM&apos;));
      sCondDataI  := &apos; AND I.AN * 12 + I.LUNA &lt;= &apos;||To_Char(PKG_GLOBALS.AnLunaLucru);
      sCondDataC  := &apos; AND C.DATASTART &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondDataC2 := &apos; AND NVL(C2.DATADOC,C2.DATA) &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondDataC0 := &apos; AND C0.DATADOC &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
      sCondCurs   := &apos; AND C0.DATA &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux)||&apos;&apos;&apos;)&apos;;
    ELSE NULL;
  END CASE;

  IF aLISTID = 256 THEN
    sDoc      := &apos;intrari&apos;;
    sCodDoc   := &apos;codintr&apos;;
    sTipContr := &apos;25&apos;;
  ELSE
    sDoc      := &apos;iesiri&apos;;
    sCodDoc   := &apos;codies&apos;;
    sTipContr := &apos;25&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, CONTRMoneda,
    CONTRCurs,
    FACTCurs,
    CFCurs,
    CF_AS,
    ACTIV, CONTABILIZAT, STORNAT,
    PART, FACTData,
    ART,
    CONTRRata, CONTRDob, CONTRAsig,
    NrFact, DataFact,
    FACTRata, FACTDob, FACTAsig,
    RESTRata, RESTDob, RESTAsig &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH x AS (
    SELECT
      c.codcontract,
      MIN(
        CASE
          WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN 1
          WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN 1
          ELSE 0
        END) Facturat,
      CASE
        WHEN (SELECT COUNT(1) FROM CONTRACT0 c0 WHERE c0.codcontract = c.codcontract AND c0.tiplinie = 1&apos;||sCondDataC0||&apos;) &gt; 0 THEN &apos;&apos;DA&apos;&apos;
        ELSE &apos;&apos;NU&apos;&apos;
      END Contabilizat,
      CASE
        WHEN (SELECT COUNT(1) FROM CONTRACT0 c0 WHERE c0.codcontract = c.codcontract AND c0.tiplinie = 3&apos;||sCondDataC0||&apos;) &gt; 0 THEN &apos;&apos;DA&apos;&apos;
        ELSE &apos;&apos;NU&apos;&apos;
      END Stornat
    FROM contract c
      INNER JOIN contract2 c2 ON c2.codcontract = c.codcontract
      LEFT JOIN &apos;||sDoc||&apos; i ON i.&apos;||sCodDoc||&apos; = c2.coddoc AND i.tipdoc = c2.tipdoc
    WHERE c.tipdoc = &apos;||sTipContr||sCondDataC||&apos; AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    GROUP BY c.codcontract
  )
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, mc.den_moneda,
    CASE
      WHEN mc.codmoneda = 0 THEN 1
      ELSE
        COALESCE(
          ( SELECT Max(c0.curs) KEEP (Dense_Rank LAST ORDER BY c0.data)
            FROM contract0 c0
            WHERE c0.codcontract = x.codcontract AND c0.tiplinie = 2&apos;||sCondCurs||&apos;),
          ( SELECT Max(c0.oldcurs) KEEP (Dense_Rank FIRST ORDER BY c0.data)
            FROM contract0 c0
            WHERE c0.codcontract = x.codcontract AND c0.tiplinie = 2),
          Decode(c.curs,NULL,1,0,1,c.curs)
        )
    END curscontr ,
    CASE
      WHEN mc.codmoneda = 0 THEN 1
      ELSE
        COALESCE(
          ( SELECT Max(c0.curs) KEEP (Dense_Rank LAST ORDER BY c0.data)
            FROM contract0 c0
            WHERE c0.codcontract = x.codcontract AND c0.tiplinie = 2 AND c0.data &lt; c2.data&apos;||sCondCurs||&apos;),
          ( SELECT Max(c0.oldcurs) KEEP (Dense_Rank FIRST ORDER BY c0.data)
            FROM contract0 c0
            WHERE c0.codcontract = x.codcontract AND c0.tiplinie = 2),
          Decode(c.curs,NULL,1,0,1,c.curs)
        )
    END cursfact ,
    Nvl(cfc.valoare, 1) cfcurs,
    TO_CHAR(c2.data+Nvl(p.scadentac,0),&apos;&apos;IYYY.IW&apos;&apos;) CF_AS,
    DECODE(c.activ,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;), x.Contabilizat, x.Stornat,
    p.den_part, c2.data,
    ( SELECT vc2_nt_to_string( CAST( collect(DISTINCT o.denumire ORDER BY o.denumire) AS vc2_nt ) )
      FROM contract1 c1 INNER JOIN nartobj o ON o.codobiect = c1.codobiect
      WHERE c1.codcontract = c.codcontract ),
    Nvl(c2.suma,0) suma, Nvl(c2.dobanda,0) dob, Nvl(c2.asigurare,0) asig,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN i.nrdoc
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN c2.NrDoc
      ELSE NULL
    END NrFact,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN I.DATADOC
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN NVL(C2.DATADOC,C2.DATA)
      ELSE NULL
    END DataFact,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN Nvl(c2.suma,0)
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN Nvl(c2.suma,0)
      ELSE 0
    END FactRata,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN Nvl(c2.dobanda,0)
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN Nvl(c2.dobanda,0)
      ELSE 0
    END FactDob,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN Nvl(c2.asigurare,0)
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN Nvl(c2.asigurare,0)
      ELSE 0
    END FactAsig,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN 0
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN 0
      ELSE Nvl(c2.suma,0)
    END RESTRata,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN 0
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN 0
      ELSE Nvl(c2.dobanda,0)
    END RESTDob,
    CASE
      WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL &apos;||sCondDataI||&apos; THEN 0
      WHEN NVL(c2.NrDoc,0) &lt;&gt; 0 &apos;||sCondDataC2||&apos; THEN 0
      ELSE Nvl(c2.asigurare,0)
    END RESTAsig &apos;||gUserAlias||&apos;
  FROM x
    INNER JOIN contract c ON c.codcontract = x.codcontract
    INNER JOIN contract2 c2 ON c2.codcontract = c.codcontract
    LEFT JOIN &apos;||sDoc||&apos; i ON i.&apos;||sCodDoc||&apos; = c2.coddoc AND i.tipdoc = c2.tipdoc
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nmonede mc ON mc.codmoneda = NVL(c.moneda,0)
    LEFT JOIN TMP_LST_CURS cfc ON cfc.codmoneda = NVL(c.moneda,0)&apos;||
    gSuplJoins||&apos;
  WHERE x.Facturat = 0&apos; ;

  sUpdate :=
  &apos;UPDATE &apos;|| tmpName ||&apos;
  SET
    RESTRataLei = FACTCurs * RESTRata,
    RESTDobLei  = FACTCurs * RESTDob ,
    RESTAsigLei = FACTCurs * RESTAsig,
    CFRestRata  = CFCurs   * RESTRata,
    CFRestDob   = CFCurs   * RESTDob,
    CFRestAsig  = CFCurs   * RESTAsig&apos;;

  PKG_LIST_BASE_UTILS.UMPLE_TMP_LST_CURS;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_SCADENTARLEASING;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SEDIIPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6F26CF40BD9C29CBD3D83918B5191A816C1AEA1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_sediipart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist (tmp_name IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  PRC_AL_CHECK(&apos;NAGENDA1&apos;);
  PRC_AL_CHECK(&apos;NPART1&apos;);
  
  gSuplCols := &apos;npart p, npart1 p1, nagenda a, nagenda1 a1, npartcodfisc, nlocalit l, njudet j, ntari t, npers  np, nzone z, traseulivr tl, ntipsedii tips, nperscontact pc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmp_name||&apos; (
    DEN_PART,REGCOM,CODFISCAL,SEDIU,TELEFON,FAX,EMAIL,
    ADRESA,
    KM,AGENT,
    SEDIUSOCIAL,
    DEN_LOCALIT,DEN_JUDET,DEN_TARA,DEN_ZONA, TRASEU, POZTRASEU,
    TIPSEDIU, X_JUDET&apos;||
    gUserFields||&apos;)
	SELECT
    p.den_part, nvl(p.regcom,&apos;&apos; &apos;&apos;), nvl(cf.codfiscal,&apos;&apos; &apos;&apos;), a.obs sediu, a.telefon, a.fax, a.email,
    getadresa(a.sector, a.strada, a.nr1, a.nr2, a.bloc, a.scara, a.etaj, a.apart, a.codpostal),
    a.km, nvl(np.nume,&apos;&apos;...&apos;&apos;) ||&apos;&apos;;&apos;&apos;||nvl(np.prenume,&apos;&apos;...&apos;&apos;) AGENT,
    case when (A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0) then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end sediusocial,
    l.den_localit, j.den_judet, t.den_tara, z.den_zona, tl.dentraseu, a.poztraseu,
    decode(A.SEDIUSOCIAL, 1,&apos;&apos;S.livrare&apos;&apos;,2,&apos;&apos;S.facturare&apos;&apos;,3,&apos;&apos;S.facturare + livrare&apos;&apos;,4,&apos;&apos;S.social&apos;&apos;,5,&apos;&apos;S.social + livrare&apos;&apos;,6,&apos;&apos;S.social + facturare&apos;&apos;,7,&apos;&apos;S.social + facturare + livrare&apos;&apos;,9,&apos;&apos;livrare la beneficiar&apos;&apos;),
    j.simbauto &apos;||
    gUserAlias||&apos;
  FROM npart p
    INNER JOIN nagenda      a    ON p.codpart        = a.codpart
    LEFT  JOIN nagenda1     a1   ON a1.codagenda     = a.codagenda AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN a1.ALStart and a1.ALStop
    LEFT  JOIN npartcodfisc cf   ON cf.codpart       = p.codpart AND cf.principal = 1
		LEFT  JOIN nlocalit     l    ON l.codlocalit     = a.codlocalit
		LEFT  JOIN njudet       j    ON j.codjudet       = l.codjudet
		LEFT  JOIN ntari        t    ON t.codtara        = l.codtara
		LEFT  JOIN npers        np   ON np.codpers       = a.codagent
		LEFT  JOIN nzone        z    ON z.codzona        = l.codzona
		LEFT  JOIN traseulivr   tl   ON tl.codtraseulivr = a.codtraseu
    LEFT  JOIN npart1       p1   ON p1.codpart1      = a.codpart AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN p1.ALStart and p1.ALStop
    LEFT  JOIN ntipsedii    tips ON tips.codtipsediu = a.codtipsediu
    LEFT  JOIN nperscontact pc   ON pc.codpart       = p.codpart AND pc.implicit = 1&apos;||
    gSuplJoins||&apos;
	WHERE P.CODPART &gt; 0 &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_sediipart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SELANLUNAREF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7792F82184F250E85E3067FEE28BBD5E14F52895</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SELANLUNAREF IS

  vLuna    INTEGER;
  vAn      INTEGER;
  vSubunit INTEGER;

PROCEDURE SETPARAMS( pLuna INTEGER, pAn INTEGER, pSubunit INTEGER ) IS
BEGIN
  vLuna    := pLuna;
  vAn      := pAn;
  vSubunit := pSubunit;
END;

FUNCTION An RETURN NUMBER IS
BEGIN
  return vAn;
END;

FUNCTION Luna RETURN NUMBER IS
BEGIN
  return vLuna;
END;

FUNCTION Sub RETURN NUMBER IS
BEGIN
  return vSubunit;
END;

END PKG_LIST_BASE_SELANLUNAREF;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B611A9443A0C1AA595251936DC5C83CB6110C847</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_serii IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

/* STIPSQL = 0 =&gt; CT_SQL_CANTSER
             1 =&gt; CT_SQL_CANTLIVR
*/

  WHERE_FILTER VARCHAR2(4000):=&apos;&apos;;
  TIP_SQL NUMBER(1);

PROCEDURE SETPARAMS(aConditie IN VARCHAR2, aTipSql IN NUMBER) IS
BEGIN
  Tip_Sql := aTipSql;
  IF    Tip_Sql = 0 THEN WHERE_FILTER := &apos; WHERE NS.CODNIRSTOC = &apos;||aConditie;
  ELSIF Tip_Sql = 1 THEN WHERE_FILTER := aConditie;
  END IF;
END;

FUNCTION  FILTRU_LIVR(pTipDoc       IN NUMBER,
                      pCodDoc       IN NUMBER,
                      pLinieDoc     IN NUMBER,
                      pTipSerie     IN NUMBER,
                      pUmSec        IN NUMBER DEFAULT NULL,
                      pCodIoart     IN NUMBER DEFAULT NULL,
                      pCodGest      IN NUMBER DEFAULT NULL,
                      pCodLocatie   IN NUMBER DEFAULT NULL,
                      pCodGestProd  IN NUMBER DEFAULT NULL,
                      pFurn         IN NUMBER DEFAULT NULL,
                      pD1           IN NUMBER DEFAULT NULL,
                      PD2           IN NUMBER DEFAULT NULL,
                      pD3           IN NUMBER DEFAULT NULL,
                      pDataAchiz    IN VARCHAR2 DEFAULT NULL,
                      pSign         IN NUMBER DEFAULT NULL,
                      pCodGestD     IN NUMBER DEFAULT NULL,
                      pCodLocatieD  IN NUMBER DEFAULT NULL)
RETURN VARCHAR2 IS
  sResult VARCHAR2(2000);
BEGIN
  IF pTipSerie &lt;&gt; 0 THEN
    sResult := &apos; WHERE L.TIPLIVR = &apos;||pTipDoc;
    IF pTipDoc IN (12,13) THEN -- transf
      sResult := sResult||&apos; AND L.CodTransf = &apos;||pCodDoc||
                          &apos; AND L1.CodIes1 = &apos;||pLinieDoc;
    ELSIF pTipDoc = 5 THEN -- dvi
      sResult := sResult||&apos; AND L.CodIntr = &apos;||pCodDoc||
                          &apos; AND L1.CodDvi1 = &apos;||pLinieDoc;
    ELSIF pTipDoc IN (1,2,3,4,6,7) THEN -- intrari
      sResult := sResult||&apos; AND L.CodIntr = &apos;||pCodDoc||
                          &apos; AND L1.CodIntr1 = &apos;||pLinieDoc;
    ELSE
      sResult := sResult||&apos; AND L.CodIes = &apos;||pCodDoc||
                          &apos; AND L1.CodIes1 = &apos;||pLinieDoc;
    END IF;
    IF pTipSerie IN (1,2) THEN
      sResult := sResult||&apos; AND NS.TipSerie = &apos;||pTipSerie;
    ELSE
      sResult := sResult||&apos; AND NS.TipSerie IS NOT NULL&apos;;
    END IF;
    IF pUMSec IS NOT NULL THEN
      sResult := sResult||&apos; AND L1.UmSec = &apos;||pUMSec;
    END IF;
    IF pCodIoart IS NOT NULL THEN
      sResult := sResult||&apos; AND NS.CodIoart = &apos;||pCodIoart;
    END IF;
    IF pCodGest IS NOT NULL THEN
      sResult := sResult||&apos; AND N.Gest = &apos;||pCodGest;
    END IF;
    IF pCodLocatie IS NOT NULL THEN
      sResult := sResult||&apos; AND nvl(NS.CodLocatie,0) = &apos;||pCodLocatie;
    END IF;

    IF pCodGestProd IS NOT NULL THEN
      sResult := sResult||&apos; AND NVL(NS.codgestProd,0) = &apos;||pCodGestProd;
    END IF;
    IF pFurn IS NOT NULL THEN
      sResult := sResult||&apos; AND NVL(NS.Furn,0) = &apos;||pFurn;
    END IF;
    IF pD1 IS NOT NULL THEN
      sResult := sResult||&apos; AND NVL(NS.D1,0) = &apos;||pD1;
    END IF;
    IF pD2 IS NOT NULL THEN
      sResult := sResult||&apos; AND NVL(NS.D2,0) = &apos;||pD2;
    END IF;
    IF pD3 IS NOT NULL THEN
      sResult := sResult||&apos; AND NVL(NS.D3,0) = &apos;||pD3;
    END IF;
    IF pDataAchiz = &apos;0&apos; THEN
      sResult := sResult||&apos; AND NS.DataAchiz IS NULL&apos;;
    ELSIF pDataAchiz IS NOT NULL THEN
      sResult := sResult||&apos; AND NS.DataAchiz = to_date(&apos;&apos;&apos;||pDataAchiz||&apos;&apos;&apos;)&apos;;
    END IF;
    IF pSign IS NOT NULL THEN
      sResult := sResult||&apos; AND SIGN(l1.cant) = &apos;||pSign;
    END IF;
    IF pCodGestD IS NOT NULL THEN
      sResult := sResult||&apos; AND ND.Gest = &apos;||pCodGestD;
    END IF;
    IF pCodLocatieD IS NOT NULL THEN
      sResult := sResult||&apos; AND nvl(NSD.CodLocatie,0) = &apos;||pCodLocatieD;
    END IF;
  END IF;
  RETURN sResult;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) is
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;NIRSER NSER, NIRSTOC NS, NIR N, NSERII SER, NARTOBJ NOBJ, CERTIF C, NTARI TARA, NUM1 UM, NPART FURN&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos; (
      DENUMIRE,SERIE,CANT,OBS,NRCERTIF,DATAPRIMIRE,PROVENIENTA,DEN_TARA,
      TIPSERIE,STARE,
      PREINREG,PRETACHIZ,DEN_UM1,DATAPROD&apos;||gUserFields||&apos;)&apos;;

  IF TIP_SQL = 0 THEN
    sSelect := &apos;
    SELECT
      NOBJ.DENUMIRE,SER.SERIE,NSER.CANTNIR,SER.OBS,C.NRCERTIF,C.DATAPRIMIRE, C.PROVENIENTA,TARA.DEN_TARA,
      DECODE (NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, decode(nser.stare,1,&apos;&apos;Liber&apos;&apos;,2,&apos;&apos;Restrictionat&apos;&apos;,3,&apos;&apos;Blocat&apos;&apos;) stare,
      ns.pret pretinreg, ns.pret - ns.adaos pretachiz,UM.DEN_UM1,NSER.DATAPROD&apos;||gUserAlias||&apos;
    FROM NIRSER NSER
      INNER JOIN NIRSTOC NS ON NSER.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NSERII SER ON SER.CODSERIE   = NSER.CODSERIE
      INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = NS.CODOBIECT
      LEFT JOIN CERTIF C ON C.CODCERTIF = NSER.CODCERTIF
      LEFT JOIN NTARI TARA ON TARA.CODTARA = C.CODTARA
      LEFT JOIN NUM1 UM ON UM.CODUM1 = NS.UMSEC
      LEFT JOIN NPART FURN ON FURN.CODPART = NS.FURN&apos;||
      gSuplJoins;
  END IF;

  IF TIP_SQL = 1 THEN
    sSelect := &apos;
    SELECT
      NOBJ.DENUMIRE,SER.SERIE,L1.CANT,SER.OBS,C.NRCERTIF,C.DATAPRIMIRE, C.PROVENIENTA,TARA.DEN_TARA,
      DECODE (NS.TIPSERIE,1,&apos;&apos;Serie pe bucata&apos;&apos;,2,&apos;&apos;Serie pe lot&apos;&apos;) tipserie, decode(nser.stare,1,&apos;&apos;Liber&apos;&apos;,2,&apos;&apos;Restrictionat&apos;&apos;,3,&apos;&apos;Blocat&apos;&apos;) stare,
      ns.pret pretinreg, ns.pret - ns.adaos pretachiz,UM.DEN_UM1,NSER.DATAPROD&apos;||gUserAlias||&apos;
    FROM NIRSER NSER
      INNER JOIN LIVR1 L1 ON L1.CODNIRSER = NSER.CODNIRSER
      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
      INNER JOIN NIRSTOC NS ON NSER.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NSERII SER ON SER.CODSERIE   = NSER.CODSERIE
      INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = NS.CODOBIECT
      LEFT JOIN CERTIF C ON C.CODCERTIF = NSER.CODCERTIF
      LEFT JOIN NTARI TARA ON TARA.CODTARA = C.CODTARA
      LEFT JOIN NUM1 UM ON UM.CODUM1 = NS.UMSEC
      LEFT JOIN NIRSTOC NSD ON NSD.CODLIVR1 = L1.CODLIVR1
      LEFT JOIN NIR ND ON ND.CODNIR = NSD.CODNIR
      LEFT JOIN NPART FURN ON FURN.CODPART = NS.FURN&apos;||
      gSuplJoins;

  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect||Where_Filter, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SETJOINURI IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


END PKG_LIST_BASE_SERII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F54D77E38B3B265FF182E5CE32C4679D83C056DE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SERTAR IS

  vOriceData  BOOLEAN;
  vDataIni    DATE;
  vDataFin    DATE;
  vPerioada   VARCHAR2(500);
  vDepus0     BOOLEAN;
  vDefalcat   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(
  pOriceData  IN NUMBER   DEFAULT 1,
  pDataIni    IN VARCHAR2 DEFAULT NULL,
  pDataFin    IN VARCHAR2 DEFAULT NULL,
  pDepus0     IN NUMBER   DEFAULT 1,
  pDefalcat   IN NUMBER   DEFAULT 1,
  pCodJob1    IN NUMBER   DEFAULT 0 )
IS
  vAnLunaIni NUMBER;
  vAnLunaFin NUMBER;
BEGIN
  vOriceData := pOriceData = 1;
  IF NOT vOriceData THEN
    vDataIni := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
    vDataFin := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  ELSE
    vDataIni := NULL;
    vDataFin := NULL;
  END IF;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vAnLunaIni,vAnLunaFin);
  END IF;

  IF    vOriceData          THEN vPerioada := &apos;&apos;;
  ELSIF vDataIni = vDataFin THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE                           vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  vDepus0    := pDepus0 = 1;
  vDefalcat  := pDefalcat = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sFiltru VARCHAR2( 1000);
  sCamp   VARCHAR2( 1000);
  sGroup  VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;NSERTAR NS, NSERTAR1 NS1, OBLIGPIF O, NBANK B, NMONEDE MON, NPART NPE, NPART NPP, NSUBUNIT SUB, NPARTCODFISC PCF, NPARTB PB, NBANK BP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NS&apos;,&apos;SUBUNITATE&apos;,&apos;
    WHERE&apos;);

  IF NOT vOriceData THEN
    sFiltru := sFiltru||&apos;
      AND NS.DATADOC &apos;||vPerioada;
  END IF;
  IF vDepus0 THEN
    sFiltru := sFiltru||&apos;
      AND NS.DEPUS = 0&apos;;
  END IF;
  IF vDefalcat THEN
    sCamp  := &apos;, NS1.CodSertar1, NS1.DenDocLegatura, NS1.Valoare&apos;;
    sGroup := &apos;&apos;;
  ELSE
    sCamp  := &apos;, 0 CodSertar1, vc2_nt_to_string(CAST(COLLECT(DISTINCT NS1.DenDocLegatura) AS vc2_nt)) DenDocLegatura, SUM(NS1.Valoare) Valoare&apos;;
    sGroup := &apos;
    GROUP BY NS.CODSERTAR&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, DATAOBLIG,
    TIP, DECONT,
    BANCA, MONEDA, PARTENER, EMITENT, SERDOC, NRDOC, DATADECONT, DECONTAT, DATADOC, VALDOC, OBSDOC,
    DOCLEG, VALASOC, CODSWIFT, CODBNR, CODFISCAL&apos;||gUserFields||&apos;)
  SELECT
    NS.CodSertar, 69, NS.DATAOBLIG,
    DECODE(NS.TIP,1,&apos;&apos;Incasare&apos;&apos;,&apos;&apos;Plata&apos;&apos;) Tip, DECODE(NS.DECONT,3,&apos;&apos;Efecte remise&apos;&apos;,2,&apos;&apos;Efecte acceptate&apos;&apos;,&apos;&apos;Cecuri&apos;&apos;) Decont,
    B.DENUMIRE, MON.SIMBOL, NPP.Den_Part, NPE.Den_Part, NS.Doc, NS.NrDoc, NS.DataDecont, Decode(NS.Depus, 0, &apos;&apos;NU&apos;&apos;,&apos;&apos;DA&apos;&apos;) DECONTAT, NS.DataDoc, NS.Valoare, NS.Obs,
    TMP.DenDocLegatura, TMP.Valoare, B.CODSWIFT, B.CODBNR, PCF.CODFISCAL &apos;||gUserAlias||&apos;
  FROM (
    SELECT NS.CODSERTAR&apos;||sCamp||&apos;
    FROM NSERTAR NS LEFT JOIN NSERTAR1 NS1 ON NS1.CODSERTAR = NS.CODSERTAR&apos;||
    sFiltru||
    sGroup||&apos;
  ) TMP
    LEFT JOIN NSERTAR NS ON NS.CODSERTAR = TMP.CODSERTAR
    LEFT JOIN NSERTAR1 NS1 ON NS1.CODSERTAR1 = TMP.CODSERTAR1
    LEFT JOIN NBANK B ON B.CODBANK = NS.BANCA
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = NVL(NS.MONEDA,0)
    LEFT JOIN NPART NPE ON NPE.CODPART = NS.CODEMITENT
    LEFT JOIN NPART NPP ON NPP.CODPART = NS.CODPARTENER
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = NS.SUBUNITATE
    LEFT JOIN OBLIGPIF O ON O.CODOBLIGPIF = NS1.CODOBLIGPIF
    LEFT JOIN NPARTCODFISC PCF ON PCF.CODPART = NS.CODPARTENER AND PCF.PRINCIPAL = 1
    LEFT JOIN NPARTB PB ON PB.CODPART = NS.CODPARTENER AND PB.IMPLICIT = 1
    LEFT JOIN NBANK BP ON BP.CODBANK = PB.CODBANK&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SERTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SIM406</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D9C77692BD7BB6847B254F1142EDE1AE1D716CB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SIM406 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0) IS
    sInsert VARCHAR2(2000);
    sSelect VARCHAR2(10000);
    condS VARCHAR2(1000); 
    condSubunitHolding  VARCHAR2(1000);
    anLucru Number(4);
    alStart Number;
    alStop  Number;
  BEGIN
    condSubunitHolding := &apos;&apos;;
    IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1 THEN
       condS := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;dcs&apos;,&apos;subunit&apos;, &apos;&apos;);
       if conds is not null then
         condSubunitHolding := &apos; AND ((&apos;||condS||&apos;) OR (dcs.subunit IS NULL))&apos;;
       end if;  
    END IF;
    gSuplCols := &apos;TAXDECL TXDCL, NCONT ncnt, NARTOBJ nobj, NART art, NUM1 um&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,
                                alistver,
                                gUserFields,
                                gUserAlias,
                                gNullAlias,
                                gSuplJoins,
                                gSuplCols);
                                
    anLucru := PKG_GLOBALS.ANLUCRU;
    alStart := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNASTART;
    alStop  := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNAFIN;
    sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(
                       NAV_TipDoc, NAV_CodDoc, TAXCODE, DEN_TAXCODE, TAXBASE, TAXVAL, TIPDOC_STR, MODIF_MANUAL, SIMBOL_CONT, DEN_CONT, 
                       ESTE_IMPOZIT, NRDOC, DATADOC, AN, LUNA, DEN_ARTICOL, PU, CANT, DEN_UM1, CURS, VALOARE, RANDD300, den_part, codfiscal,
                       proctaxa, tiptaxa, COD_SUBUNIT, DEN_SUBUNIT &apos;||gUserFields||&apos; )&apos;;
    sSelect := &apos;
                  with din_iesiri as
                 (select txIes.CODTAXDECL,
                         ies.CODIES as coddoc,
                         ies.NRDOC,
                         ies.DATADOC,
                         ies.AN,
                         ies.LUNA,
                         ies1.CODOBIECT,
                         ies1.CANT,
                         ies1.UMSEC,
                         ies1.pretorig * ies1.coefdiscmaj as pret,
                         ies.curs,
                         ies.partener as codpart,
                         1 as signValue,
                         ies.subunitatea as subunit
                    from TAXDECL txIes
                    join IESIRI ies
                      on ies.CODIES = txIes.CODDOC
                     and ies.TIPDOC = txIes.TIPDOC
                    join IESIRI1 ies1
                      on ies1.CODIES1 = txIes.CODDOC1
                   where txIes.Tipdoc in (14, 19, 20, 21, 26)),
                din_intrari as
                 (select txIntr.CODTAXDECL,
                         intr.CODINTR as coddoc,
                         intr.NRDOC,
                         intr.DATADOC,
                         intr.AN,
                         intr.LUNA,
                         intr1.CODOBIECT,
                         intr1.CANT,
                         intr1.UMSEC,
                         intr1.pretorig * intr1.coefdiscmaj as pret,
                         intr.CURS,
                         intr.partener as codpart,
                         1 as signValue,
                         intr.subunitatea as subunit
                    from TAXDECL txIntr
                    join INTRARI intr
                      on intr.CODINTR = txIntr.CODDOC
                     and intr.TIPDOC = txIntr.TIPDOC
                    join INTRARI1 intr1
                      on intr1.CODINTR1 = abs(txIntr.CODDOC1)
                   where txIntr.Tipdoc in (1, 2, 3, 4, 5, 9)),
                din_monetare as
                 (select txMon.CODTAXDECL,
                         ies.CODIES as coddoc,
                         ies.NRDOC,
                         ies.DATADOC,
                         ies.AN,
                         ies.LUNA,
                         null             as CODOBIECT,
                         null             as CANT,
                         null             as UMSEC,
                         null             as pret,
                         ies.curs         as CURS,
                         ies.partener     as codpart,
                         1 as signValue,
                         ies.subunitatea as subunit
                    from TAXDECL txMon
                    join IESIRI ies
                      on ies.CODIES = txMon.CODDOC
                     and ies.TIPDOC = txMon.TIPDOC
                   where txMon.Tipdoc in (16)),
                din_trezor as 
                (select txTrz.CODTAXDECL,
                         trz1.CODTREZOR as coddoc,
                         trz1.NRDOC,
                         trz1.DATADOC,
                         trz1.AN,
                         trz1.LUNA,
                         null             as CODOBIECT,
                         null             as CANT,
                         null             as UMSEC,
                         null             as pret,
                         trz1.curs        as CURS,
                         trz1.codpart     as codpart,
                         1 as signValue,
                         trz.subunitatea as subunit
                    from TAXDECL txTrz
                    join TREZOR1 trz1 
                      on trz1.CODTREZOR1 = txTrz.CODDOC
                    left join trezor trz on trz1.codtrezor = trz.codtrezor  
                   where txTrz.TIPDOC in (29,30,33)),
                din_nc as 
                (select txTrz.CODTAXDECL,
                         nca.codnc as coddoc,
                         nca.NRDOC,
                         nca.DATADOC,
                         nca.AN,
                         nca.LUNA,
                         null             as CODOBIECT,
                         null             as CANT,
                         null             as UMSEC,
                         null             as pret,
                         nca.curs         as CURS,
                         nca.part         as codpart,
                         1 as signValue,
                         nca.subunitatea as subunit
                    from TAXDECL txTrz
                    join NC nca 
                      on nca.codnc = txTrz.CODDOC
                   where txTrz.TIPDOC in (35)),
                din_compensari as 
                (select txTrz.CODTAXDECL,
                         cmp.CODCOMPENS as coddoc,
                         cmp.NRDOC,
                         cmp.DATADOC,
                         cmp.AN,
                         cmp.LUNA,
                         null             as CODOBIECT,
                         null             as CANT,
                         null             as UMSEC,
                         null             as pret,
                         null             as CURS,
                         null             as codpart,
                         1 as signValue,
                         cmp.subunitatea as subunit
                    from TAXDECL txTrz
                    join compens cmp 
                      on cmp.CODCOMPENS = txTrz.CODDOC
                   where txTrz.TIPDOC in (28)),
                all_docs as
                 (select *
                    from din_iesiri
                  union all
                  select *
                    from din_intrari
                  union all
                  select *
                    from din_monetare
                  union all
                  select *
                    from din_trezor
                  union all
                  select *
                    from din_nc
                  union all
                  select *
                    from din_compensari)
                select txdcl.TIPDOC,
                       dcs.CODDOC,
                       txdcl.TAXCODE,
                       ntax.DENUMIRE,
                       txdcl.TAXBASE * dcs.signValue,
                       txdcl.TAXVAL * dcs.signValue,
                       case txdcl.TIPDOC when  1 then &apos;&apos;Intrari pe factura&apos;&apos;
                                         when  2 then &apos;&apos;Intrari pe aviz&apos;&apos;
                                         when  3 then &apos;&apos;Intrari pe chitanta/bon fiscal&apos;&apos;
                                         when  4 then &apos;&apos;Intrari de la persoane fizice&apos;&apos;
                                         when  5 then &apos;&apos;Intrari din import&apos;&apos;
                                         when  9 then &apos;&apos;Intrari pe factura la aviz&apos;&apos;
                                         when 14 then &apos;&apos;Diminuari de stoc&apos;&apos;
                                         when 16 then &apos;&apos;Monetare&apos;&apos;
                                         when 19 then &apos;&apos;Iesiri pe factura&apos;&apos;
                                         when 20 then &apos;&apos;Iesiri pe aviz&apos;&apos;
                                         when 21 then &apos;&apos;Iesiri pe chitanta/bon fiscal&apos;&apos;
                                         when 26 then &apos;&apos;Iesiri pe factura la aviz&apos;&apos;
                                         when 28 then &apos;&apos;Compensari&apos;&apos;
                                         when 29 then &apos;&apos;Casa&apos;&apos;
                                         when 30 then &apos;&apos;Banca&apos;&apos;
                                         when 33 then &apos;&apos;Justificare decont&apos;&apos;
                                         when 35 then &apos;&apos;Note contabile&apos;&apos;
                                else &apos;&apos;&apos;&apos; end as TIPDOC_STR, 
                       case when coalesce(txdcl.MANUAL,0) = 0 then &apos;&apos;Nu&apos;&apos; else &apos;&apos;Da&apos;&apos; end,
                       ncnt.SIMBOL,
                       ncnt.DEN_CONT,
                       case when coalesce(ncnt.IMPOZIT,0) = 0 then &apos;&apos;Nu&apos;&apos; else &apos;&apos;Da&apos;&apos; end,
                       dcs.NRDOC,
                       dcs.DATADOC,
                       dcs.AN,
                       dcs.LUNA,
                       art.DEN_ARTICOL,
                       case when coalesce(dcs.pret,0) &gt; 0 then dcs.pret*coalesce(um.paritate,1) else 0 end as pret,
                       case when coalesce(dcs.CANT,0) &gt; 0 then dcs.CANT/coalesce(um.paritate,1) else 0 end as cantitate,
                       um.DEN_UM1,
                       dcs.CURS,
                       coalesce(dcs.pret,0) * coalesce(dcs.CANT,0) * coalesce(dcs.CURS,1) as Valoare,
                       txcds.RANDD300,
                       part.den_part, cf.codfiscal,
                       txcds.proctaxa, txcds.tiptaxa,
                       dcs.subunit,
                       nsub.den_subunit &apos;
                ||gUserAlias||       
                &apos; from TAXDECL txdcl
                  left join winmadmin.taxcodesaft ntax on ntax.cod = txdcl.TAXCODE
                  left join NCONT ncnt
                    on ncnt.CODCONT = txdcl.CODCONT
                  left join all_docs dcs
                    on dcs.CODTAXDECL = txdcl.CODTAXDECL
                  left join NARTOBJ nobj
                    on nobj.CODOBIECT = dcs.CODOBIECT
                  left join NART art
                    on art.CODARTICOL = nobj.CODARTICOL
                  left join NUM1 um
                    on um.CODUM1 = dcs.UMSEC
                  left join npart part
                    on part.codpart = dcs.codpart
                  left join npartcodfisc cf
                    on cf.codpart = part.codpart
                    and cf.principal = 1
                  left join winmadmin.taxcodesaft txcds 
                    on txcds.cod = txdcl.taxcode
                  left join  nsubunit nsub on nsub.codsubunit = dcs.subunit&apos; 
                ||gSuplJoins||
                &apos; WHERE ANLUNA  BETWEEN &apos;||alStart||&apos; AND &apos;||alStop||&apos; &apos;||condSubunitHolding||&apos; &apos;; 
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    COMMIT;
  END;

  PROCEDURE setJoinuri IS
  BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
  END;

end PKG_LIST_BASE_SIM406;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SIMULAMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63D911D817A0BD4CFEE971375AA70AE8AA0F51A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SIMULAMO IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vNrLuni     PLS_INTEGER;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
  vAn     PLS_INTEGER := PKG_LIST_BASE_SELANLUNAREF.AN;
  vLuna   PLS_INTEGER := PKG_LIST_BASE_SELANLUNAREF.LUNA;
BEGIN
  gSuplCols := &apos;MIFIX MF, NIRSTOC NS, NARTOBJ OBJ, NUM1 U1, IOART IO, MFCLASIF MFC, NIR N, NGEST NG, NSUBUNIT SUB, NPART FURN, CENTRECOST CC, NIRSTOC1 NS1, NIRSTOC NSO&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos;(
    CODMIFIX, CODNIRSTOC, DENMIFIX, CANT, NRINVENTAR, DEN_UM1, DEN_IOART,
    DENCLASA, SIMBOLCLASA, DEN_GEST, DEN_SUBUNIT, CODINTERN, CODEXTERN, FURNIZOR, OBSMIFIX,
    CentruCost, PretInc, PretInitial, AN, LUNA,
    AE,
    AG&apos;||gUserFields||&apos;)
  SELECT
    mfs.codmifix, mfs.codnirstoc, obj.denumire DENMIFIX, mfs.cant, mf.nrinventar, u1.den_um1, io.den_ioart,
    mfc.denumire DENCLASA, mfc.simbol SIMBOLCLASA, ng.den_gest, sub.den_subunit, OBJ.CODINTERN, OBJ.CODEXTERN, FURN.DEN_PART FURNIZOR, mf.obs obsmifix,
    cc.denumire CentruCost, CASE WHEN mfs.PretVechi = 0 THEN nso.Pret - nso.Adaos ELSE mfs.PretVechi END PretInc, nso.pret PretInitial, mfs.AnStart, mfs.LunaStart,
    mfs.amo - Lag(mfs.amo, 1, 0) OVER (Partition by MFS.CODMIFIX ORDER BY mfs.AnStart, mfs.LunaStart) AE,
    mfs.amog- Lag(mfs.amog,1, 0) OVER (Partition by MFS.CODMIFIX ORDER BY mfs.AnStart, mfs.LunaStart) AG &apos;||gUserAlias||&apos;
  FROM mifix1_simulare mfs
    LEFT JOIN mifix mf ON mfs.codmifix = mf.codmifix
    LEFT JOIN nirstoc ns ON mfs.codnirstoc = ns.codnirstoc
    LEFT JOIN nartobj obj ON obj.codobiect = ns.codobiect
    LEFT JOIN num1 u1 ON u1.codum1 = ns.umsec
    LEFT JOIN ioart io ON ns.codioart = io.codioart
    LEFT JOIN mfclasif mfc ON mfc.codclasif = mfs.codclasif
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN ngest ng ON ng.codgest = n.gest
    LEFT JOIN nsubunit sub ON sub.codsubunit = ng.codsubunit
    LEFT JOIN npart furn ON furn.codpart = ns.furn
    LEFT JOIN centrecost cc ON cc.codcentru = mfs.codcentru
    LEFT JOIN nirstoc1 ns1 on ns1.codnirstoc = ns.codnirstoc
    LEFT JOIN nirstoc nso on nso.codnirstoc = ns1.codnirstocorig&apos;||
    gSuplJoins||&apos;
  WHERE 1 = 1&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);

  pkg_inchideri.SIMULARE_AMORTIZARI(pkg_globals.anlucru,pkg_globals.lunalucru, vAn, vLuna);
  --pkg_globals.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;DELETE FROM &apos;||TMPNAME||&apos; WHERE an*12+luna &lt;= &apos;||To_Char(pkg_globals.AnLunaLucru), aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SIMULAMO;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SINTTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFE6B661A1DAFB74619688BD39C548C7F7D19A59</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SINTTREZ IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  i number(10);
  oData DATE;
BEGIN
  i := 0;
  oData := trunc(pkg_list_selectperioada.dataini);
  WHILE oData &lt;= trunc(pkg_list_selectperioada.datafin) LOOP
    i := i + 1;
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;W&apos;||   TO_CHAR(i), &apos;SOLD_&apos;||   TO_CHAR(oData,&apos;DD_MM_YYYY&apos;), i);
    INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;WLEI&apos;||TO_CHAR(i), &apos;SOLDLEI_&apos;||TO_CHAR(oData,&apos;DD_MM_YYYY&apos;), i);
    oData := oData + 1;
  END LOOP;
  COMMIT;
END;

PROCEDURE TMPPrepare(aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sUpdate     CLOB;
  sExtraSold  CLOB;

  sDataIni    VARCHAR2(100) := &apos;&apos;;
  sDataFin    VARCHAR2(100) := &apos;&apos;;
  sFiltruData VARCHAR2(100) := &apos;&apos;;

  vAnLunaIni  NUMBER;
  vAnLunaFin  NUMBER;
  dDataIni    DATE;

  dDataFin    DATE;
  sAnLunaIni  VARCHAR2(5);
  sAnLunaFin  VARCHAR2(5);
BEGIN
  IF PKG_LIST_SELECTPERIOADA.DupaData THEN
    dDataIni    := PKG_LIST_SELECTPERIOADA.DataIni;
    dDataFin    := PKG_LIST_SELECTPERIOADA.DataFin;
    vAnLunaIni  := Extract(YEAR FROM dDataIni) * 12 + Extract(MONTH FROM dDataIni);
    vAnLunaFin  := Extract(YEAR FROM dDataIni) * 12 + Extract(MONTH FROM dDataIni);
    sDataIni    := &apos;To_Date(&apos;&apos;&apos;||To_Char(dDataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sDataFin    := &apos;To_Date(&apos;&apos;&apos;||To_Char(dDataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sFiltruData := &apos;
    AND d.datadoc &lt;= &apos;||sDataFin;
  ELSE
    vAnLunaIni := PKG_LIST_SELECTPERIOADA.AnLunaIni;
    vAnLunaFin := PKG_LIST_SELECTPERIOADA.AnLunaFin;
  END IF;
  sAnLunaIni  := To_Char(vAnLunaIni, &apos;fm99999&apos;);
  sAnLunaFin  := To_Char(vAnLunaFin, &apos;fm99999&apos;);

  DELETE FROM tmp_stt;

  sInsert := &apos;INSERT INTO tmp_stt(
    An, Luna, CodBankCont, TipDoc, CodDoc, CodDoc1, IndexLocal, CarnetDoc, SerieDoc, DataDoc,
    Document, CursDoc,
    Soldin, SoldInLei,
    Incasari, Plati, Explicatii )
  SELECT
    t.an, t.luna, t.codbanca CodBankCont, t.tipdoc, t.codtrezor CodDoc, d.codtrezor1 CodDoc1, d.IndexLocal, d.CarnetDoc, d.SerieDoc, d.datadoc,
    d.doc||d.nrdoc||&apos;&apos;/&apos;&apos;||to_char(d.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, Coalesce(NULLIF(d.curs,0),1) CursDoc,
    0 Soldin, 0 SoldInLei,
   CASE
     WHEN d.tiptranz = 1 THEN
       coalesce(o.valoare/case when b.codmoneda &lt;&gt; g.moneda then case when Coalesce(d.curs,1) = 0 then 1 else Coalesce(d.curs,1) end/
       case when coalesce(g.curs,1) = 0 then 1 else coalesce(g.curs,1) end else 1 end,d.valdoc)
     ELSE 0
   END Incasari,
   CASE
     WHEN d.tiptranz = 1 THEN 0
     ELSE coalesce(o.valoare/case when b.codmoneda &lt;&gt; g.moneda then case when Coalesce(d.curs,1) = 0 then 1 else Coalesce(d.curs,1) end/
       case when coalesce(g.curs,1) = 0 then 1 else coalesce(g.curs,1) end else 1 end,d.valdoc)
   END + Coalesce(d.comision,0)*coalesce(o.valoare/
     case when coalesce(b.codmoneda,0) &gt; 0 and b.codmoneda &lt;&gt; g.moneda then case when Coalesce(d.curs,1) = 0 then 1 else Coalesce(d.curs,1) end else 1 end,d.valdoc)/d.valdoc Plati,
    CASE
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 0 THEN &apos;&apos;Plata furnizor &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 1 THEN &apos;&apos;Plata retur &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 2 THEN &apos;&apos;Plata angajat &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 3 THEN &apos;&apos;Plata viramente interne &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 4 THEN &apos;&apos;Plata direct pe cheltuieli &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 0 AND d.obiecttranz = 5 THEN &apos;&apos;Plata datorii / taxe / impozite &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 0 THEN &apos;&apos;Incasare client &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 1 THEN &apos;&apos;Incasare retur &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 2 THEN &apos;&apos;Incasare angajat &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 3 THEN &apos;&apos;Incasare viramente interne &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 4 THEN &apos;&apos;Incasare direct pe venituri &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 5 THEN &apos;&apos;Incasare imprumuturi / subventii &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 1 AND d.obiecttranz = 6 THEN &apos;&apos;Incasare dobanda &apos;&apos;
      WHEN CASE WHEN d.platatva = 1 THEN 2 ELSE d.tiptranz END = 2                       THEN &apos;&apos;Plata SPLIT TVA &apos;&apos;
    END ||
    CASE d.obiecttranz
      WHEN 3 THEN nb.denumire||&apos;&apos; &apos;&apos;||nbc.nrcont
      WHEN 2 THEN pers.nume||&apos;&apos; &apos;&apos;||pers.prenume
      WHEN 1 THEN part.den_part
      WHEN 0 THEN part.den_part
      ELSE (
        SELECT nc.simbol
        FROM ncont nc
        WHERE nc.codcont =
          CASE
            WHEN o.semnificatie IN (300,320)
             AND Coalesce(os.semnificatie, 0) = 500    THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
            WHEN o.semnificatie IN (400,420)
             AND Coalesce(os.semnificatie, 0) = 600    THEN PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.obiecttranz, T.an, T.luna)
            WHEN o.semnificatie IN (800,801)           THEN To_Number(PKG_CATEGCONST.GETVALCONSTBYCODE(o.icont,t.an,t.luna))
            WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
            WHEN o.semnificatie = 1000                 THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(t.codbanca,t.an,t.luna))
            WHEN o.semnificatie IN (1100,1101)         THEN PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(d.codpart,t.an,t.luna))
            ELSE                                            PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(d.codpart,t.an,t.luna))
          END
      )
    END ||&apos;&apos; &apos;&apos;||
    CASE
      WHEN o.semnificatie IN (310,410) THEN &apos;&apos;in avans &apos;&apos;
      WHEN int.codintr IS NOT NULL THEN int.prefixdoc|| &apos;&apos;/&apos;&apos;||int.nrdoc||&apos;&apos;/&apos;&apos;||int.datadoc
      WHEN ies.codies  IS NOT NULL THEN ies.prefixdoc|| &apos;&apos;/&apos;&apos;||ies.nrdoc||&apos;&apos;/&apos;&apos;||ies.datadoc
    END
  FROM trezor t
    INNER JOIN trezor1 d ON d.codtrezor = t.codtrezor
    LEFT JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
    LEFT JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = d.codtrezor1
    LEFT JOIN obligpif o ON o.codgeneral = g.codgeneral
    LEFT JOIN npart part ON part.codpart = d.codpart AND d.obiecttranz IN (0,1)
    LEFT JOIN npers pers ON pers.codpers = d.codpart AND d.obiecttranz = 2
    LEFT JOIN nbankcont nbc ON nbc.codbankcont = d.codpart AND d.obiecttranz = 3
    LEFT JOIN nbank nb ON nb.codbank = nbc.codbank
    LEFT JOIN stingere s on s.codstingatorpif = o.codobligpif
    LEFT JOIN obligpif os on os.codobligpif = s.codstinspif
    LEFT JOIN general gs on gs.codgeneral = os.codgeneral
    LEFT JOIN intrari int on int.codintr = gs.coddoc and int.tipdoc = gs.tipdoc
    LEFT JOIN iesiri ies on ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
    LEFT JOIN trezor1 ts1 ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
    LEFT JOIN trezor ts ON ts.codtrezor = ts1.codtrezor
  WHERE t.tipdoc IN (29,30) 
    AND t.operat = 1 AND Coalesce(d.anulat,0) = 0 and coalesce(d.valdoc,0) &lt;&gt; 0&apos;;
  IF PKG_LIST_SELECTPERIOADA.optiunea2 THEN
    sInsert := sInsert||&apos;  AND T.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE&apos;;
  END IF;
  sInsert := sInsert||&apos;
    AND t.an * 12 + t.luna BETWEEN &apos;||sAnLunaIni||&apos; AND &apos;||sAnLunaFin||
    sFiltruData;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert := &apos;INSERT INTO tmp_stt(
    An, Luna, CodBankCont, TipDoc, CodDoc, CodDoc1, IndexLocal, CarnetDoc, SerieDoc, DataDoc,
    Document, CursDoc,
    Soldin, SoldInLei,
    Incasari, Plati )
  SELECT
    d.an, d.luna, m.codbankcont, d.tipdoc, d.codies CodDoc, 0 CodDoc1, 0 IndexLocal, d.CarnetDoc, d.SeriaDoc, d.datadoc,
    d.prefixdoc||d.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(d.Datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) Document, Coalesce(NULLIF(d.curs,0),1) CursDoc,
    0 Soldin, 0 SoldInLei,
    m.valoare Incasari, 0 Plati
  FROM IESIRI d INNER JOIN moduriplati m ON m.codies = d.codies
  WHERE d.tipdoc = 16 AND M.CODBANKCONT &gt; 0
    AND operat = 1 AND d.anulat = 0&apos;;
  if PKG_LIST_SELECTPERIOADA.optiunea2 then
    sInsert := sInsert||&apos;  AND D.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE&apos;;
  end if;
  sInsert := sInsert||&apos;
    AND d.an * 12 + d.luna BETWEEN &apos;||sAnLunaIni||&apos; AND &apos;||sAnLunaFin||
    sFiltruData;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sUpdate := &apos;UPDATE tmp_stt SET IncasariLei = Incasari*CursDoc, PlatiLei = Plati*CursDoc&apos;;
  LIST_EXECUTE_IMMEDIATE(sUpdate, aListID, aListVer);

  DELETE FROM tmp_sttsolddoc;

  sInsert := &apos;INSERT INTO tmp_sttsolddoc ( An, Luna, CodBankCont, DataDoc, SoldIn, SoldInLei)
  SELECT An, Luna, CodBankCont, Max(DataDoc) DataDoc, SUM(Incasari - Plati) SoldIn, Sum(IncasariLei - PlatiLei) SoldInLei
  FROM tmp_stt
  WHERE DataDoc &lt; &apos;||sDataIni||&apos;
  GROUP BY An, Luna, CodBankCont&apos;;

  IF PKG_LIST_SELECTPERIOADA.DupaData THEN
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;DELETE FROM tmp_stt WHERE DataDoc &lt; &apos;||sDataIni, aListID, aListVer);
  END IF;

  sInsert := &apos;INSERT INTO tmp_stt(
    An, Luna, CodBankCont, TipDoc, CodDoc, CodDoc1, IndexLocal, DataDoc,
    Document, CursDoc,
    SoldIn, SoldInLei,
    Incasari, IncasariLei, Plati, PlatiLei)
  SELECT
    An, Luna, CodBankCont, 0 TipDoc, 0 CodDoc, 0 CodDoc1, 0 IndexLocal, Max(DataDoc),
    &apos;&apos;Sold initial&apos;&apos; Document, 1 CursDoc,
    Sum(SoldIn), Sum(SoldInLei),
    0 Incasari, 0 IncasariLei, 0 Plati, 0 PlatiLei
  FROM (
    SELECT
      s.an + CASE s.luna WHEN 12 THEN 1 ELSE 0 END an, CASE s.luna WHEN 12 THEN 1 ELSE s.luna+1 END luna, s.codbankcont,
      last_day(to_date(To_Char(s.an,&apos;&apos;fm0000&apos;&apos;)||To_Char(s.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;)) datadoc,
      CASE WHEN Coalesce(bc.codmoneda,0) = 0 THEN s.soldlei ELSE s.soldvaluta END soldin, s.soldlei soldinlei
    FROM nbanksoldluna s LEFT JOIN nbankcont bc ON bc.codbankcont = s.codbankcont
    WHERE (s.an*12+s.luna+1) BETWEEN &apos;||sAnLunaIni||&apos; AND &apos;||sAnLunaFin;
  if PKG_LIST_SELECTPERIOADA.optiunea2 then
    sInsert := sInsert||&apos;  AND BC.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE&apos;;
  end if;
  sInsert := sInsert||&apos;
    UNION ALL
    SELECT
      An, Luna, CodBankCont,
      DataDoc,
      SoldIn, SoldInLei
    FROM  tmp_sttsolddoc
  ) subs
  GROUP BY An, Luna, CodBankCont&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  DELETE FROM tmp_sttreg;
  sInsert := &apos;INSERT INTO tmp_sttreg( An, Luna, CodMoneda, Curs)
  SELECT An, Luna, CodMoneda, Curs
  FROM (
    SELECT An, Luna, CodMoneda, Curs, Row_Number() OVER (PARTITION BY An, Luna, CodMoneda ORDER BY DataDoc DESC) IDXCurs
    FROM reg
    WHERE tipreg = 45 AND an *12 + luna BETWEEN &apos;||sAnLunaIni||&apos; AND &apos;||sAnLunaFin;
  /*if PKG_LIST_SELECTPERIOADA.optiunea2 then
    sInsert := sInsert||&apos;  AND CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE&apos;;
  end if;*/
  sInsert := sInsert||&apos;
  ) subs
  WHERE IDXCurs = 1&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  oData    DATE;
  oDataFin DATE;
  i        NUMBER(10);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=&apos;nmonede m, nbankcont bc, nbank b, ncont nc, nsubunit sub&apos;  ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_SINTTREZ.TMPPrepare;
  PRC_AL_CHECK(&apos;NBANKCONT1&apos;);
  PRC_AL_CHECK(&apos;IOBANK1&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    AnLuna, An, Luna,
    Banca, Cont, NrCont, Moneda,
    SoldInit, Incasari, Plati, SoldFin,
    SoldInitLEI, IncasariLEI, PlatiLEI, DifRegLEI, SoldFinalLEI,
    ContReprez, UltData, Subunitate, CodBankCont&apos;||gUserFields||&apos; )
  SELECT
    stt.an*12+stt.luna anluna, stt.an,
    CASE stt.luna
      WHEN  1 THEN &apos;&apos;01 - Ianuarie&apos;&apos;
      WHEN  2 THEN &apos;&apos;02 - Februarie&apos;&apos;
      WHEN  3 THEN &apos;&apos;03 - Martie&apos;&apos;
      WHEN  4 THEN &apos;&apos;04 - Aprilie&apos;&apos;
      WHEN  5 THEN &apos;&apos;05 - Mai&apos;&apos;
      WHEN  6 THEN &apos;&apos;06 - Iunie&apos;&apos;
      WHEN  7 THEN &apos;&apos;07 - Iulie&apos;&apos;
      WHEN  8 THEN &apos;&apos;08 - August&apos;&apos;
      WHEN  9 THEN &apos;&apos;09 - Septembrie&apos;&apos;
      WHEN 10 THEN &apos;&apos;10 - Octombrie&apos;&apos;
      WHEN 11 THEN &apos;&apos;11 - Noiembrie&apos;&apos;
      WHEN 12 THEN &apos;&apos;12 - Decembrie&apos;&apos;
    END luna,
    b.simbol banca, bc.den_cont cont, bc.nrcont, m.simbol moneda,
    stt.soldin, stt.incasari, stt.plati, stt.soldin + (stt.incasari - stt.plati) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END soldfin,
    stt.soldinlei, stt.incasarilei, stt.platilei,
    CASE
      WHEN cr.curs IS NULL then 0
      ELSE (stt.soldin    + (stt.incasari    - stt.plati   ) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END) * cr.curs -
           (stt.soldinlei + (stt.incasarilei - stt.platilei) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END)
    END DifRegLei,
    CASE
      WHEN cr.curs IS NULL
      THEN  stt.soldinlei + (stt.incasarilei - stt.platilei) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END
      ELSE (stt.soldin    + (stt.incasari    - stt.plati   ) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END) * cr.curs
    END soldfinlei,
    nc.simbol, stt.ultdata, sub.den_subunit, bc.codbankcont &apos;||gUserAlias||&apos;
  FROM (
    SELECT
      an, luna, codbankcont, Max(datadoc) ultdata,
      sum(incasari)    incasari,    sum(plati)    plati,    sum(soldin)    soldin,
      sum(incasarilei) incasarilei, sum(platilei) platilei, sum(soldinlei) soldinlei
    FROM tmp_stt
    GROUP BY an, luna, codbankcont
  ) STT
    LEFT JOIN nbankcont  bc   ON bc.codbankcont  = stt.codbankcont
    LEFT JOIN nmonede    m    ON m.codmoneda     = bc.codmoneda
    LEFT JOIN nbank      b    ON b.codbank       = bc.codbank
    LEFT JOIN nbankcont1 bc1  ON bc1.codbankcont = bc.codbankcont and stt.an*12+stt.luna between  bc1.Alstart and  bc1.Alstop
    LEFT JOIN iobank1    iob1 ON iob1.codiobank  = bc1.codiobanca and stt.an*12+stt.luna between iob1.Alstart and iob1.Alstop
    LEFT JOIN ncont      nc   ON nc.codcont      = iob1.cont
    LEFT JOIN tmp_sttreg cr   ON cr.codmoneda    = bc.codmoneda   AND cr.luna = stt.luna AND cr.an = stt.an AND Coalesce(bc.farareg, 0) = 0
    LEFT JOIN nsubunit   sub  ON sub.codsubunit  = bc.subunitatea&apos;||
    gSuplJoins|| &apos;
  WHERE b.codbank &lt;&gt; 0
  ORDER BY stt.luna, bc.codbank, bc.codmoneda&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  IF PKG_LIST_SELECTPERIOADA.optiunea1 THEN
    oData    := Trunc(pkg_list_selectperioada.dataini);
    oDataFin := Trunc(pkg_list_selectperioada.datafin);
    i := 0;
    WHILE oData &lt;= oDataFin LOOP
      i := i + 1;
      sInsert :=
      &apos;UPDATE &apos;||tmpName||&apos; TMP SET
       (W&apos;||TO_CHAR(i)||&apos;, WLEI&apos;||TO_CHAR(i)||&apos;)  =
       (
         SELECT
           Coalesce(SUM(stt.soldin   +stt.incasari   -stt.plati   *CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END), 0),
           Coalesce(SUM(stt.soldinlei+stt.incasarilei-stt.platilei*CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END), 0)
         FROM TMP_STT STT LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = STT.CODBANKCONT
         WHERE STT.DATADOC &lt;= TO_DATE(&apos;&apos;&apos;||TO_CHAR(oData,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
           AND TMP.CODBANKCONT = STT.CODBANKCONT AND STT.AN = &apos;||To_Char(oData,&apos;yyyy&apos;)||&apos; AND STT.LUNA = &apos;||To_Char(oData,&apos;mm&apos;)||&apos;
       )&apos;;
      LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

      oData := oData + 1;
    END LOOP;
  END IF;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
 Pkg_List_Struct.SetTableSpec(gSuplCols);
 pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SINTTREZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SINTTREZDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B579A09B62AE3DC01CA1C4037F7EE8300526254</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SINTTREZDET IS

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(25000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    CLOB;
  sSelect    CLOB;
  sFields    VARCHAR2(5000);
  sAlias     VARCHAR2(15000);
  oData      DATE;
  i          NUMBER(10);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=&apos;nmonede m, nbankcont bc, nbank b, ncont nc, nsubunit sub&apos;  ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;trezor1&apos;, &apos;t1&apos;, &apos;t1.codtrezor1 = stt.coddoc1&apos;                          , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;trezor&apos;,  &apos;t&apos;,  &apos;t.codtrezor   = stt.coddoc  AND t.tipdoc = stt.tipdoc&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;iesiri&apos;,  &apos;i&apos;,  &apos;i.codies      = stt.coddoc  AND i.tipdoc = stt.tipdoc&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_SINTTREZ.TMPPrepare;
  PRC_AL_CHECK(&apos;NBANKCONT1&apos;);
  PRC_AL_CHECK(&apos;IOBANK1&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_TipDoc,  NAV_CodDoc,  NAV_CodDoc1,
    Ordine,
    AnLuna, An,
    Luna,
    Banca, Cont, NrCont, Moneda, Document,
    SoldInit,    Incasari,    Plati,    SoldFin,
    SoldInitLEI, IncasariLEI, PlatiLEI, DifRegLEI, SoldFinalLEI,
    ContReprez, DataDoc, Subunitate, CodBankCont, Explicatii&apos;||gUserFields||&apos; )&apos;;

  sSelect := &apos;
  SELECT
    STT.TIPDOC, STT.CODDOC, STT.CODDOC1,
    CASE WHEN STT.TIPDOC = 0 THEN 0 ELSE 1 END Ordine,
    stt.an*12+stt.luna anluna, stt.an,
    CASE stt.luna
      WHEN  1 THEN &apos;&apos;01 - Ianuarie&apos;&apos;
      WHEN  2 THEN &apos;&apos;02 - Februarie&apos;&apos;
      WHEN  3 THEN &apos;&apos;03 - Martie&apos;&apos;
      WHEN  4 THEN &apos;&apos;04 - Aprilie&apos;&apos;
      WHEN  5 THEN &apos;&apos;05 - Mai&apos;&apos;
      WHEN  6 THEN &apos;&apos;06 - Iunie&apos;&apos;
      WHEN  7 THEN &apos;&apos;07 - Iulie&apos;&apos;
      WHEN  8 THEN &apos;&apos;08 - August&apos;&apos;
      WHEN  9 THEN &apos;&apos;09 - Septembrie&apos;&apos;
      WHEN 10 THEN &apos;&apos;10 - Octombrie&apos;&apos;
      WHEN 11 THEN &apos;&apos;11 - Noiembrie&apos;&apos;
      WHEN 12 THEN &apos;&apos;12 - Decembrie&apos;&apos;
    END luna,
    b.simbol banca, bc.den_cont cont, bc.nrcont, m.simbol moneda, stt.document,
    stt.soldin,    stt.incasari,    stt.plati,    0 soldfin,
    stt.soldinlei, stt.incasarilei, stt.platilei,
    0 DifRegLei,
    0 soldfinlei,
    nc.simbol, stt.datadoc, sub.den_subunit, bc.codbankcont, stt.explicatii &apos;||gUserAlias||&apos;
  FROM tmp_stt stt
    LEFT JOIN nbankcont  bc   ON bc.codbankcont  = stt.codbankcont
    LEFT JOIN nmonede    m    ON m.codmoneda     = bc.codmoneda
    LEFT JOIN nbank      b    ON b.codbank       = bc.codbank
    LEFT JOIN nbankcont1 bc1  ON bc1.codbankcont = bc.codbankcont and stt.an*12+stt.luna between  bc1.Alstart and  bc1.Alstop
    LEFT JOIN iobank1    iob1 ON iob1.codiobank  = bc1.codiobanca and stt.an*12+stt.luna between iob1.Alstart and iob1.Alstop
    LEFT JOIN ncont      nc   ON nc.codcont      = iob1.cont
    LEFT JOIN tmp_sttreg cr   ON cr.codmoneda    = bc.codmoneda AND cr.luna = stt.luna AND cr.an = stt.an AND Coalesce(bc.farareg, 0) = 0
    LEFT JOIN nsubunit   sub  ON sub.codsubunit  = bc.subunitatea &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  sSelect := &apos;
  SELECT
    STT.TIPDOC, STT.CODDOC, STT.CODDOC1,
    2 Ordine,
    stt.an*12+stt.luna anluna, stt.an,
    CASE stt.luna
      WHEN  1 THEN &apos;&apos;01 - Ianuarie&apos;&apos;
      WHEN  2 THEN &apos;&apos;02 - Februarie&apos;&apos;
      WHEN  3 THEN &apos;&apos;03 - Martie&apos;&apos;
      WHEN  4 THEN &apos;&apos;04 - Aprilie&apos;&apos;
      WHEN  5 THEN &apos;&apos;05 - Mai&apos;&apos;
      WHEN  6 THEN &apos;&apos;06 - Iunie&apos;&apos;
      WHEN  7 THEN &apos;&apos;07 - Iulie&apos;&apos;
      WHEN  8 THEN &apos;&apos;08 - August&apos;&apos;
      WHEN  9 THEN &apos;&apos;09 - Septembrie&apos;&apos;
      WHEN 10 THEN &apos;&apos;10 - Octombrie&apos;&apos;
      WHEN 11 THEN &apos;&apos;11 - Noiembrie&apos;&apos;
      WHEN 12 THEN &apos;&apos;12 - Decembrie&apos;&apos;
    END luna,
    b.simbol banca, bc.den_cont cont, bc.nrcont, m.simbol moneda, &apos;&apos;Sold final&apos;&apos; document,
    0 soldin, 0 incasari, 0 plati, stt.soldin + (stt.incasari - stt.plati) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END soldfin,
    0 soldinlei, 0 incasarilei, 0 platilei,
    CASE
      WHEN cr.curs IS NULL then 0
      ELSE (stt.soldin    + (stt.incasari    - stt.plati   ) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END) * cr.curs -
           (stt.soldinlei + (stt.incasarilei - stt.platilei) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END)
    END DifRegLei,
    CASE
      WHEN cr.curs IS NULL
      THEN  stt.soldinlei + (stt.incasarilei - stt.platilei) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END
      ELSE (stt.soldin    + (stt.incasari    - stt.plati   ) * CASE WHEN Coalesce(bc.credit,0) = 0 THEN 1 ELSE -1 END) * cr.curs
    END soldfinlei,
    nc.simbol, stt.datadoc, sub.den_subunit, bc.codbankcont, &apos;&apos;&apos;&apos; explicatii &apos;||gUserAlias||&apos;
  FROM (
    SELECT
      an, luna, codbankcont,
      0 tipdoc, 0 coddoc, 0 coddoc1, 0 indexlocal, Max(datadoc) datadoc,
      sum(incasari)    incasari,    sum(plati)    plati,    sum(soldin)    soldin,
      sum(incasarilei) incasarilei, sum(platilei) platilei, sum(soldinlei) soldinlei
    FROM tmp_stt
    GROUP BY an, luna, codbankcont
  ) stt
    LEFT JOIN nbankcont  bc   ON bc.codbankcont  = stt.codbankcont
    LEFT JOIN nmonede    m    ON m.codmoneda     = bc.codmoneda
    LEFT JOIN nbank      b    ON b.codbank       = bc.codbank
    LEFT JOIN nbankcont1 bc1  ON bc1.codbankcont = bc.codbankcont and stt.an*12+stt.luna between  bc1.Alstart and  bc1.Alstop
    LEFT JOIN iobank1    iob1 ON iob1.codiobank  = bc1.codiobanca and stt.an*12+stt.luna between iob1.Alstart and iob1.Alstop
    LEFT JOIN ncont      nc   ON nc.codcont      = iob1.cont
    LEFT JOIN tmp_sttreg cr   ON cr.codmoneda    = bc.codmoneda AND cr.luna = stt.luna AND cr.an = stt.an AND Coalesce(bc.farareg, 0) = 0
    LEFT JOIN nsubunit   sub  ON sub.codsubunit  = bc.subunitatea &apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
 Pkg_List_Struct.SetTableSpec(gSuplCols);
 pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SINTTREZDET;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITACCRUALLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EAE3DE586D9AB66D6655DBE2EB4CC91E1047A0E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITACCRUALLS IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION ExprCurs (pAlias VARCHAR2) RETURN VARCHAR2 IS
  sResuls VARCHAR2(300) := &apos;&apos;;
BEGIN
  IF PKG_LIST_SELPARTART.IsExtra1 THEN
    sResuls := &apos;*Coalesce(NullIF(&apos;||pAlias||&apos;.curs,0),1)&apos;;
  END IF;
  RETURN sResuls;
END;

PROCEDURE umpleTmpPlati(aAnLunaIni in number, aAnLunaFin in number, aFiltru in varchar2, CuTruncate in number default 0) IS
  sInsTMP     CLOB;
  sCondTmp    VARCHAR2( 1000)  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;N&apos;);
  sALIni      VARCHAR2(    5)  := To_Char(PKG_LIST_SELPARTART.AnLunaIni, &apos;fm99999&apos;); 
  sALFin      VARCHAR2(    5)  := To_Char(PKG_LIST_SELPARTART.AnLunaFin, &apos;fm99999&apos;); 
BEGIN
  IF CuTruncate &lt;&gt; 0 THEN
    LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE tmp_platiaccrualls&apos;, 0, 0);
  END IF;

  IF NOT PKG_LIST_SELPARTART.IsAllPart THEN
    sCondTmp := sCondTmp||&apos;
      AND N.CODPART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  IF PKG_LIST_SELPARTART.IsExtra2 THEN
    sCondTmp := sCondTmp||&apos;
      AND Coalesce(N.INCHISA, 0) = 0&apos;;
  END IF;

  sInsTMP := &apos;
  INSERT INTO tmp_platiaccrualls (PARTENER, PROCENT, CODDISCOUNT, OFFINVOICE, CODDOC, TIPDOC, PREFIXDOC, NRDOC, DATADOC, PLATA, ORDINE, MAXORD, FILTRU, CODMONEDA)
  WITH
  D(coddoc, tipdoc, prefixdoc, nrdoc, datadoc, offinvoice, val, curs) AS (
    SELECT i.codintr, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, 3 offinvoice, Sum(i1.pu*i1.cant&apos;||ExprCurs(&apos;i&apos;)||&apos;) val, i.curs
    FROM (
      SELECT ANLUNASTART, ANLUNASTOP, To_Number(VALOARE) AS artF 
      FROM TMP_CONSTVAL_LST
      WHERE SIMBOL = &apos;&apos;ARTDISCOFFINVOICEF&apos;&apos; AND Coalesce(VALOARE, &apos;&apos;0&apos;&apos;) &lt;&gt; &apos;&apos;0&apos;&apos;
    ) da
      INNER JOIN intrari1 i1 ON i1.codobiect = da.artF 
      LEFT  JOIN intrari i ON i.codintr = i1.codintr
    WHERE i.an*12+i.luna BETWEEN da.ANLUNASTART AND da.ANLUNASTOP 
    GROUP BY i.codintr, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.curs
    UNION ALL
    SELECT i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, 2 offinvoice, Sum(i1.pu*i1.cant&apos;||ExprCurs(&apos;i&apos;)||&apos;) val, i.curs
    FROM (
      SELECT ANLUNASTART, ANLUNASTOP, To_Number(VALOARE) AS artC 
      FROM TMP_CONSTVAL_LST
      WHERE SIMBOL = &apos;&apos;ARTDISCOFFINVOICEF&apos;&apos; AND Coalesce(VALOARE, &apos;&apos;0&apos;&apos;) &lt;&gt; &apos;&apos;0&apos;&apos;
    ) da
      INNER JOIN iesiri1 i1 ON i1.codobiect = da.artC 
      LEFT  JOIN iesiri i ON i.codies = i1.codies
    WHERE i.an*12+i.luna BETWEEN da.ANLUNASTART AND da.ANLUNASTOP 
    GROUP BY i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.curs),
  F AS (
    SELECT ncf.codncredit, d.coddoc, d.tipdoc, d.prefixdoc, d.nrdoc, d.datadoc, d.offinvoice, ncf.valdoc&apos;||ExprCurs(&apos;d&apos;)||&apos; val
    FROM d INNER JOIN notecreditfact ncf ON ncf.coddoc = d.coddoc AND ncf.tipdoc = d.tipdoc),
  Y AS (
    SELECT
      nc1.codncredit, n.codpart partener, cd.offinvoice,Coalesce(id.coddiscount,nc1.coddiscount) coddiscount, Coalesce(i.moneda, n.codmoneda, 0) codmoneda,
      Coalesce(id.procent,(SELECT Max(Procent) From discinterval di WHERE di.coddiscount = Coalesce(id.coddiscount,nc1.coddiscount)) ) Procent,
      Sum(Round(nc1.valoare&apos;||ExprCurs(&apos;n&apos;)||&apos;,4)) v1,
      Sum(Sum(Round(nc1.valoare&apos;||ExprCurs(&apos;n&apos;)||&apos;,4))) OVER (PARTITION BY nc1.codncredit, cd.offinvoice) v2
    FROM notecredit n
      INNER JOIN notecredit1 nc1 ON nc1.codncredit = n.codncredit
      LEFT JOIN iesiri i ON i.codies = nc1.codobligstins AND i.tipdoc = nc1.tipdoc
      LEFT JOIN iesdisc id ON id.codiesdisc = nc1.coddoc AND id.codies = i.codies AND id.offinvoice = CASE n.tipdoc WHEN 58 THEN 2 WHEN 59 THEN 3 ELSE 0 END
      LEFT JOIN discount d ON d.coddiscount = Coalesce(id.coddiscount,nc1.coddiscount)
      LEFT JOIN criteriidisc cd ON cd.codcriteriu = d.codcriteriu
    WHERE EXTRACT(YEAR FROM N.DATASTOP) *12 + EXTRACT(MONTH FROM N.DATASTOP) &gt;= &apos;||sALIni||&apos;
      AND EXTRACT(YEAR FROM N.DATASTART)*12 + EXTRACT(MONTH FROM N.DATASTART)&lt;= &apos;||sALFin||
      sCondTmp||&apos;
      AND nc1.tip = 5
    GROUP BY nc1.codncredit, n.codpart, cd.offinvoice, Coalesce(id.coddiscount,nc1.coddiscount), id.procent, i.moneda, n.codmoneda)
  SELECT
    y.partener, y.procent, y.coddiscount, f.offinvoice, f.coddoc, f.tipdoc, f.prefixdoc, f.nrdoc, f.datadoc,
    Round(Sum(case when y.v2 = 0 then f.val else f.val*y.v1/y.v2 end),2) plata,
    ROW_NUMBER() OVER (PARTITION BY y.partener, y.procent, y.coddiscount, f.offinvoice ORDER BY f.datadoc, f.nrdoc, f.coddoc) ordine,
    COUNT(1) OVER (PARTITION BY y.partener, y.procent, y.coddiscount, f.offinvoice) maxord, &apos;&apos;&apos;||aFiltru||&apos;&apos;&apos;, Y.CODMONEDA
  FROM f INNER JOIN y ON y.codncredit = f.codncredit AND y.offinvoice = f.offinvoice
  GROUP BY y.partener, y.procent, y.coddiscount, f.offinvoice, f.coddoc, f.tipdoc, f.prefixdoc, f.nrdoc, f.datadoc, y.codmoneda&apos;;

  pkg_list_base_utils.UMPLE_TMP_CONSTVAL_LST(&apos;ARTDISCOFFINVOICEC, ARTDISCOFFINVOICEF&apos;);
  LIST_EXECUTE_IMMEDIATE(sInstmp, 0, 0);

  sInsTMP := &apos;
  INSERT INTO tmp_platiaccrualls (PARTENER, PROCENT, CODDISCOUNT, OFFINVOICE, CODDOC, TIPDOC, PREFIXDOC, NRDOC, DATADOC, PLATA, ORDINE, MAXORD, FILTRU, CODMONEDA)
  WITH
  D(coddoc, tipdoc, prefixdoc, nrdoc, datadoc, val, curs) AS (
    SELECT i.codintr coddoc, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, Sum(i1.pu*i1.cant&apos;||ExprCurs(&apos;i&apos;)||&apos;) val, i.curs
    FROM (
      SELECT ANLUNASTART, ANLUNASTOP, To_Number(VALOARE) AS artV 
      FROM TMP_CONSTVAL_LST
      WHERE SIMBOL = &apos;&apos;ARTDISCPRIMVOL&apos;&apos; AND Coalesce(VALOARE, &apos;&apos;0&apos;&apos;) &lt;&gt; &apos;&apos;0&apos;&apos;
    ) da
      INNER JOIN intrari1 i1 ON i1.codobiect = da.artV 
      LEFT  JOIN intrari i ON i.codintr = i1.codintr 
    WHERE i.an*12+i.luna BETWEEN da.ANLUNASTART AND da.ANLUNASTOP 
    GROUP BY i.codintr, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.curs),
  F AS (
    SELECT ncf.codncredit, d.coddoc, d.tipdoc, d.prefixdoc, d.nrdoc, d.datadoc, ncf.valdoc&apos;||ExprCurs(&apos;d&apos;)||&apos; val
    FROM d INNER JOIN notecreditfact ncf ON ncf.coddoc = d.coddoc AND ncf.tipdoc = d.tipdoc),
  Y AS (
    SELECT
      nc1.codncredit, n.codpart partener, Coalesce(i.moneda, n.codmoneda, 0) codmoneda,
      Sum(Round(nc1.valoare&apos;||ExprCurs(&apos;n&apos;)||&apos;,4)) v1,
      Sum(Sum(Round(nc1.valoare&apos;||ExprCurs(&apos;n&apos;)||&apos;,4))) OVER (PARTITION BY nc1.codncredit) v2
    FROM notecredit n
      INNER JOIN notecredit1 nc1 ON nc1.codncredit = n.codncredit
      LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = NC1.CODDOC AND N.VOLUMPEARTICOLE = 1
      LEFT JOIN IESIRI  I  ON I.CODIES   = CASE WHEN N.VOLUMPEARTICOLE = 1 THEN I1.CODIES ELSE NC1.CODDOC END
      LEFT JOIN NOTECREDIT1 NC1X ON NC1X.CODNCREDIT1ORIG = NC1.CODNCREDIT1
    WHERE EXTRACT(YEAR FROM N.DATASTOP) *12 + EXTRACT(MONTH FROM N.DATASTOP) &gt;= &apos;||sALIni||&apos;
      AND EXTRACT(YEAR FROM N.DATASTART)*12 + EXTRACT(MONTH FROM N.DATASTART)&lt;= &apos;||sALFin||&apos;
      AND NC1.TIP = 2 AND N.IESIRIPEVOLUM = 1 AND NC1.VALOARE &lt;&gt; 0
      AND Coalesce(NC1.CODDOC, 0) &lt;&gt; 0
      AND Coalesce(N.CORECTIE,0) = 0
      AND NC1X.CODNCREDIT1 IS NULL &apos;||
      sCondTmp||&apos;
    GROUP BY nc1.codncredit, n.codpart, i.moneda, n.codmoneda)
  SELECT
    y.partener, 0 procent, 0 coddiscount, -1 offinvoice, f.coddoc, f.tipdoc, f.prefixdoc, f.nrdoc, f.datadoc,
    -Round(Sum(case when y.v2 = 0 then f.val else f.val*y.v1/y.v2 end),2) plata,
    ROW_NUMBER() OVER (PARTITION BY y.partener ORDER BY f.datadoc, f.nrdoc, f.coddoc) ordine,
    COUNT(1) OVER (PARTITION BY y.partener) maxord, &apos;&apos;&apos;||aFiltru||&apos;&apos;&apos;, Y.CODMONEDA
  FROM f INNER JOIN y ON y.codncredit = f.codncredit
  GROUP BY y.partener, f.coddoc, f.tipdoc, f.prefixdoc, f.nrdoc, f.datadoc, y.codmoneda&apos;;

  pkg_list_base_utils.UMPLE_TMP_CONSTVAL_LST(&apos;ARTDISCPRIMVOL&apos;);
  LIST_EXECUTE_IMMEDIATE(sInstmp, 0, 0);
END;

FUNCTION Cond(vTabelaS IN VARCHAR2, vCampPart IN VARCHAR2) RETURN VARCHAR2 IS
  sCond VARCHAR2(1000);
BEGIN
  sCond := PKG_LIST_BASE_UTILS.COND_SUBUNIT(vTabelaS);
  IF NOT PKG_LIST_SELPARTART.IsAllPart THEN
    sCond := sCond||&apos;
        AND &apos;||vCampPart||&apos; IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  RETURN sCond;
END;

FUNCTION ViewX(vALIni NUMBER, vALFin NUMBER) RETURN VARCHAR2 IS
  sSql   VARCHAR2(10000);
  sALIni VARCHAR2(10)     := To_Char(vALIni);
  sALFin VARCHAR2(10)     := To_Char(vALFin);
BEGIN
  sSql := &apos;
    SELECT
      partener, subunitatea, coddiscount, codmoneda, procent, SUM(CASE WHEN Poz = 1 THEN BazaDisc ELSE 0 END) BazaDisc, Sum(CASE WHEN Poz = 1 THEN ValDisc ELSE 0 END) ValDisc,
      Sum(ValIncDec) ValIncDec
    FROM (
      SELECT
        CASE
          WHEN Coalesce(ID.CODOBIECT, 0) = 0 THEN 1
          ELSE Row_Number() OVER (PARTITION BY ID.CodIes, Coalesce(ID.CODOBIECT, 0), ID.CodDiscount ORDER BY ID.CodIes)
        END Poz,
        i.partener, i.subunitatea, id.coddiscount, Coalesce(i.moneda,0) codmoneda, id.procent,
        CASE
          WHEN Coalesce(ID.CODOBIECT, 0) = 0 THEN i.valdoc-i.tvadoc
          ELSE (SELECT Coalesce(Sum(i1.pretorig*i1.cant*Coalesce(i1.CoefDiscmaj,1)),0) FROM IESIRI1 I1 WHERE I1.CODIES = I.CODIES AND I1.CODOBIECT = ID.CODOBIECT)
        END&apos;||ExprCurs(&apos;i&apos;)||&apos; BazaDisc,
        Round(
          CASE
            WHEN Coalesce(ID.CODOBIECT, 0) = 0 THEN i.valdoc-i.tvadoc
            ELSE (SELECT Coalesce(Sum(i1.pretorig*i1.cant*Coalesce(i1.CoefDiscmaj,1)),0) FROM IESIRI1 I1 WHERE I1.CODIES = I.CODIES AND I1.CODOBIECT = ID.CODOBIECT)
          END&apos;||ExprCurs(&apos;i&apos;)||&apos;*id.procent/100,
          4
        ) ValDisc,
        0 ValIncDec
      FROM iesiri i
        INNER JOIN IESDISC ID ON ID.CODIES = I.CODIES
      WHERE Coalesce(I.Anulat,0) = 0 AND I.Operat = 1 AND Coalesce(I.TipFactura,0) &lt;&gt; 5
        AND i.an*12+i.luna BETWEEN &apos;||sALIni||&apos; AND &apos;||sALFin||
        Cond(&apos;I&apos;, &apos;I.PARTENER&apos;) ||&apos;
      UNION ALL
      SELECT
        1 Poz,
        nc.codpart, nc.subunitatea, nc1.coddiscount, Coalesce(nc.codmoneda,0) codmoneda,
        (SELECT Max(Procent) From discinterval di WHERE di.coddiscount = nc1.coddiscount) procent,
        0 BazaDisc,
        0 ValDisc,
        NC1.VALOARE&apos;||ExprCurs(&apos;nc&apos;)||&apos; + Coalesce(COR.VALOARE,0) ValIncDec
      FROM NOTECREDIT1 NC1
        INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
        LEFT JOIN (
          SELECT
            NCC1.CODNCREDIT1ORIG CODNCREDIT1,
            SUM((Coalesce(NCC1.VALOARE,0) - Coalesce(NCC1.VALOAREOLD,0))&apos;||ExprCurs(&apos;ncc&apos;)||&apos;) VALOARE
          FROM NOTECREDIT1 NCC1 INNER JOIN NOTECREDIT NCC ON NCC.CODNCREDIT = NCC1.CODNCREDIT
          WHERE NCC.CORECTIE = 1
          GROUP BY NCC1.CODNCREDIT1ORIG
        ) COR ON COR.CODNCREDIT1 = NC1.CODNCREDIT1
      WHERE NC1.TIP = 5
        AND Coalesce(NC1.CODDOC, 0) = 0
        AND Coalesce(NC.CORECTIE,0) = 2
        AND nc.an*12+nc.luna BETWEEN &apos;||sALIni||&apos; AND &apos;||sALFin||
        Cond(&apos;NC&apos;, &apos;NC.CODPART&apos;) ||&apos;
      UNION ALL
      SELECT
        1 Poz,
        nc.codpart, nc.subunitatea, 0 coddiscount, Coalesce(nc.codmoneda,0) codmoneda, 0 procent,
        0 BazaDisc,
        NC1.VALOARE&apos;||ExprCurs(&apos;nc&apos;)||&apos; ValDisc,
        0 ValIncDec
      FROM NOTECREDIT1 NC1
        INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
        LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = NC1.CODDOC AND NC.VOLUMPEARTICOLE = 1
        LEFT JOIN IESIRI  I  ON I.CODIES   = CASE WHEN NC.VOLUMPEARTICOLE = 1 THEN I1.CODIES ELSE NC1.CODDOC END
      WHERE NC1.TIP = 2 AND NC.IESIRIPEVOLUM = 1 AND NC1.VALOARE &lt;&gt; 0
        AND Coalesce(NC1.CODDOC, 0) &lt;&gt; 0
        AND Coalesce(NC.CORECTIE,0) = 0
        AND i.an*12+i.luna BETWEEN &apos;||sALIni||&apos; AND &apos;||sALFin||
        Cond(&apos;NC&apos;, &apos;NC.CODPART&apos;) ||&apos;
    )
    GROUP BY partener, subunitatea, coddiscount, codmoneda, procent&apos;;

  RETURN sSql;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sSelect1 VARCHAR2(30000);
  sSelect2 VARCHAR2(30000);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;npart p, nartobj nao, nart na, nclasea ca, nclasedisc clsd&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    Part, Art, ClasaA, Subunit,
    Categ,
    ValStart,
    ValStop,
    Disc,
    ProcDisc, BazaDisc, ValDisc, ValIncDec,
    PlataDoc, PlataVal, RestDisc,
    ValDiscFin, ValIncDecFin, PlataValFin, Moneda &apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    p.Den_Part Part, nao.Denumire Art, ca.Den_Clasea ClasaA, sub.Den_Subunit Subunit,
    &apos;&apos;OnnInvoice&apos;&apos; Categ,
    NULL ValStart,
    NULL ValStop,
    CASE
      WHEN tmp.codcriteriu &lt;&gt; 0 THEN cd.DenCriteriu
      WHEN Sign(tmp.proc) &gt; 0 THEN &apos;&apos;Majorare direct pe cont &apos;&apos;||c.simbol
      ELSE &apos;&apos;Discount direct pe cont &apos;&apos;||c.simbol
    END Disc,
    tmp.Proc ProcDisc, tmp.BazaDisc, tmp.ValDisc, NULL ValIncDec,
    NULL PlataDoc, NULL PlataVal, NULL RestDisc, tmp.valdiscfin, NULL ValIncDecFin, null PlataValFin, MON.SIMBOL Moneda &apos;||gUserAlias||&apos;
  FROM tmp_list_sitoninv tmp
    LEFT JOIN NMONEDE MON ON TMP.CODMONEDA = MON.CODMONEDA
    LEFT JOIN npart p ON p.codpart = tmp.codpart
    LEFT JOIN nartobj nao ON nao.codobiect = tmp.codobiect
    LEFT JOIN nart na ON na.codarticol = nao.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = na.clasa
    LEFT JOIN nsubunit sub ON sub.codsubunit = tmp.subunitatea
    LEFT JOIN criteriidisc cd ON cd.codcriteriu = tmp.codcriteriu
    LEFT JOIN nclasedisc clsd ON clsd.codclasedisc = cd.clasa
    LEFT JOIN ncont c ON c.codcont = tmp.codcont&apos;||
    gSuplJoins;

  sSelect2 := &apos;
  WITH x AS (&apos;||
    ViewX(PKG_LIST_SELPARTART.AnLunaIni, PKG_LIST_SELPARTART.AnLunaFin)||&apos;
  ),
  xfin AS (&apos;||
    ViewX(PKG_LIST_SELPARTART.AnLunaFin, PKG_LIST_SELPARTART.AnLunaFin)||&apos;
  )
  SELECT
    p.Den_Part Part, nao.Denumire Art, ca.Den_Clasea ClasaA, sub.Den_Subunit Subunit,
    CASE WHEN x.coddiscount = 0 THEN &apos;&apos;Volum&apos;&apos; WHEN cd.offinvoice = 3 THEN &apos;&apos;BillBack&apos;&apos; WHEN cd.offinvoice = 2 THEN &apos;&apos;NC&apos;&apos; ELSE &apos;&apos;OffInvoice&apos;&apos; END Categ,
    (SELECT Min(cd1.datastart) FROM criteriidisc1 cd1, discount d, discinterval di WHERE di.procent = x.Procent AND d.coddiscount = x.coddiscount AND d.codcriteriu1 = cd1.codcriteriu1 AND di.coddiscount = d.coddiscount) ValStart,
    NULL ValStop,
    cd.DenCriteriu Disc,
    x.Procent ProcDisc, x.BazaDisc, x.ValDisc, x.ValIncDec,
    tmp.Doc PlataDoc, CASE WHEN cd.offinvoice = 3 THEN -1 ELSE 1 END * tmp.Val PlataVal, x.ValDisc-Coalesce(tmp.Val,0) RestDisc,
    xfin.ValDisc ValDiscFin, xfin.ValIncDec ValIncDecFin, CASE WHEN cd.offinvoice = 3 THEN -1 ELSE 1 END * tmf.val PlataValFin, mon.simbol Moneda &apos;||gUserAlias||&apos;
  FROM x
    left join xfin on x.partener = xfin.partener and x.subunitatea = xfin.subunitatea and x.procent = xfin.procent and x.coddiscount = xfin.coddiscount
    LEFT JOIN nmonede mon on mon.codmoneda = x.codmoneda
    LEFT JOIN npart p ON p.codpart = x.partener
    LEFT JOIN nartobj nao ON nao.codobiect = x.partener - x.partener
    LEFT JOIN nart na ON na.codarticol = nao.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = na.clasa
    LEFT JOIN nsubunit sub ON sub.codsubunit = x.subunitatea
    LEFT JOIN discount d ON d.coddiscount = x.coddiscount
    LEFT JOIN criteriidisc cd ON cd.codcriteriu = d.codcriteriu
    LEFT JOIN nclasedisc clsd ON clsd.codclasedisc = cd.clasa
    LEFT JOIN ncont c ON c.codcont = x.partener - x.partener
    LEFT JOIN (
      SELECT
        partener, procent, coddiscount, offinvoice,
        vc2_nt_to_vc3200(CAST(COLLECT(PrefixDoc||&apos;&apos; &apos;&apos;||nrdoc||&apos;&apos; &apos;&apos;||to_char(DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) Doc,
        SUM(Plata) Val, codmoneda
      FROM tmp_platiaccrualls
      where filtru = &apos;&apos;PER&apos;&apos;
      GROUP BY partener, procent, coddiscount, offinvoice, codmoneda
    ) tmp ON tmp.partener = x.partener AND tmp.procent = x.procent AND tmp.coddiscount = x.coddiscount and tmp.codmoneda = x.codmoneda AND tmp.offinvoice = Coalesce(cd.offinvoice, -1)
    LEFT JOIN (
      SELECT
        partener, procent, coddiscount, offinvoice,
        vc2_nt_to_vc3200(CAST(COLLECT(PrefixDoc||&apos;&apos; &apos;&apos;||nrdoc||&apos;&apos; &apos;&apos;||to_char(DataDoc,&apos;&apos;dd.mm.yyyy&apos;&apos;)) AS vc2_nt)) Doc,
        SUM(Plata) Val, codmoneda
      FROM tmp_platiaccrualls
      where filtru = &apos;&apos;INI&apos;&apos;
      GROUP BY partener, procent, coddiscount, offinvoice, codmoneda
    ) tmf ON tmf.partener = x.partener AND tmf.procent = x.procent AND tmf.coddiscount = x.coddiscount and tmf.codmoneda = x.codmoneda AND tmf.offinvoice = Coalesce(cd.offinvoice, -1)&apos;||
    gSuplJoins;

  PKG_LIST_BASE_SITONINV.UmpleTmp(FALSE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);

  IF PKG_LIST_SELPARTART.IsAllArt THEN
    umpleTmpPlati(PKG_LIST_SELPARTART.AnLunaIni, PKG_LIST_SELPARTART.AnLunaFin, &apos;PER&apos;, 1);
    umpleTmpPlati(PKG_LIST_SELPARTART.AnLunaFin, PKG_LIST_SELPARTART.AnLunaFin, &apos;INI&apos;, 0);
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SITACCRUALLS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITARTFIRMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F29D54FA2ABD48EFFBFAA5878C5DF8F32EDDC9F8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITARTFIRMA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vPerioada    VARCHAR2(100)  := PKG_LIST_SELSITART.Perioada;
  vToateArt    BOOLEAN        := PKG_LIST_SELSITART.ToateArt;
  vTotiPart    BOOLEAN        := PKG_LIST_SELSITART.TotiPart;
  vToateDoc    BOOLEAN        := PKG_LIST_SELSITART.ToateDoc;
  vJoinNir     VARCHAR2(1000);
  vWhereNir    VARCHAR2(1000);
  vWhereArt    VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NIRSTOC&apos;,    &apos;NS&apos;,   &apos;NS.CODNIRSTOC = LISTA.CODNIRSTOC&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NIR&apos;,        &apos;NIR&apos;,  &apos;NIR.CODNIR = NS.CODNIR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,    &apos;INTR&apos;, &apos;INTR.CODINTR = NIR.CODINTR AND INTR.TIPDOC = NIR.TIPNIR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;INTR1&apos;,&apos;INTR1.CODINTR1 = NS.CODINTR1 AND INTR1.CODINTR = INTR.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMONEDE&apos;,    &apos;MINTR&apos;,&apos;MINTR.CODMONEDA = I.MONEDA&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF NOT vTotiPart OR NOT vToateDoc THEN
    vJoinNir := &apos; INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR &apos;;
  END IF;

  IF vPerioada IS NOT NULL THEN
    vWhereNir := vWhereNir || &apos; AND N.DATANIR &apos;||vPerioada;
  END IF;

  IF NOT vTotiPart THEN
    vWhereNir := vWhereNir || &apos;
       AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; AND VALOARE = I.PARTENER) &apos;;
  END IF;

  IF NOT vToateDoc THEN
    vWhereNir := vWhereNir || &apos;
       AND I.TIPDOC IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;) &apos;;
  END IF;

  IF NOT vToateArt THEN
    vWhereArt :=  &apos;
       AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;( Art, UM, Ord, CantIn, CantIes, Stoc, PretIn, PretIes, DataDoc&apos;||gUserFields||&apos; )
  WITH NSINTRARI AS (
    SELECT NS.CODNIRSTOC, CONNECT_BY_ROOT NS.CODNIRSTOC ROOTCODNIRSTOC
    FROM NIRSTOC NS
    CONNECT BY PRIOR NS.CODNIRSTOC = NS.CODNIRSTOCPARINTE
    START WITH Nvl(CODNIRSTOCPARINTE,0) = 0 &apos;||
      vWhereArt;
  IF vWhereNir IS NOT NULL THEN
    sInsert:= sInsert ||&apos;
    AND EXISTS ( SELECT 1 FROM NIR N &apos;||vJoinNir||&apos; WHERE N.CODNIR = NS.CODNIR &apos;||vWhereNir||&apos;)&apos;;
  END IF;
  sInsert:= sInsert ||&apos;)
  SELECT
    NAO.DENUMIRE, NUM.DEN_UM, COUNT(1) OVER (PARTITION BY NAO.DENUMIRE ORDER BY LISTA.CODNIRSTOC, LISTA.DATA_DOC) ORD,
    LISTA.CANTIN, LISTA.CANTIES, SUM(LISTA.CANTIN - LISTA.CANTIES) OVER (PARTITION BY NAO.DENUMIRE, LISTA.CODNIRSTOC ORDER BY LISTA.DATA_DOC) STOC, LISTA.PRETIN, LISTA.PRETIES, LISTA.DATA_DOC&apos;||gUserAlias||&apos;
  FROM (
    SELECT NS.CODOBIECT, N.DATANIR DATA_DOC, NS.CODNIRSTOC, NS.CANTNIR CANTIN, 0 CANTIES, NS.PRET - NS.ADAOS PRETIN, 0 PRETIES
    FROM NIRSTOC NS INNER JOIN NIR N ON N.CODNIR = NS.CODNIR &apos;||vJoinNir||&apos;
    WHERE NS.CODNIRSTOCPARINTE IS NULL &apos;||
      vWhereNir||
      vWhereArt||&apos;
    UNION ALL
    SELECT I1.CODOBIECT, I.DATADOC DATA_DOC, NS.ROOTCODNIRSTOC CODNIRSTOC, 0 CANTIN, L1.CANT CANTIES, 0 PRETIN, I1.PU PRETIES
    FROM NSINTRARI NS
      INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR AND L.CODIES IS NOT NULL
      INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
      INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  ) LISTA
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = LISTA.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_SITARTFIRMA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITBONRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D516862724B626C2781CF9751D8C0777160A10E5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITBONRETAIL is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;EMULARE E, EMULARE1 E1, NARTOBJ O&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      ART,
      UM,
      CANT,
      CODINTERN,
      CODEXTERN,
      PRET,
      PRETRAFT,
      VAL,
      TVA,
      PROCTVA,
      DISCOUNT,
      DEN_IOART,
      DEN_GEST,
      CONTSERV,
      FARASTOC,
      COMANDA,
      TIPLIVRARE,
      CADOU,
      NRBON,
      DATABON,
      VALBON,
      VALDISCBON,
      CASAMARCAT,
      TVATOTAL,
      TVADISCOUNT,
      PARTENER,
      MONETAR,
      OPERATOR,
      SEDIU,
      AGENT,
      OBS,
      DELEGAT,
      INCASARE,
      INCASARE0,
      INCASARE1,
      INCASARE2,
      INCASARE3 &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    MAN_E1 AS 
    (
     SELECT
       E1.CODEMULARE1
     FROM EMULARE1 E1
          INNER JOIN EMULARE E ON E1.CODEMULARE = E.CODEMULARE
     WHERE E.DATACREARE BETWEEN TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAINI, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) AND
                             TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAFIN, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) 
    )
  SELECT
    O.DENUMIRE,
    UM1.DEN_UM1,
    E1.CANT,
    O.CODINTERN,
    O.CODEXTERN,
    E1.PRET,
    E1.PRETART,
    E1.PRET * E1.CANT,
    E1.TVA,
    ROUND(NVL(E1.TVA,0)/E1.CANT * E1.PRET * 100, 2),
    E1.DISCOUNT,
    IOA.DEN_IOART,
    G.DEN_GEST,
    S.SIMBOL,
    CASE WHEN E1.FARASTOC = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    CASE WHEN C.CODCOMANDA &gt; 0 THEN C.PREFIXDOC||C.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(C.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) END,
    CASE 
      WHEN E1.TIPLIVRARE = 1 THEN &apos;&apos;Ridicata&apos;&apos;
      WHEN E1.TIPLIVRARE = 2 THEN &apos;&apos;Custodie&apos;&apos;
      WHEN E1.TIPLIVRARE = 3 THEN &apos;&apos;Nesosita&apos;&apos;
      WHEN E1.TIPLIVRARE = 4 THEN &apos;&apos;De ridicat&apos;&apos;
    END,
    CASE WHEN E1.CADOU = 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    E.NRBON,
    E.DATABON,
    E.VALOARE,
    E.VALOAREDISCOUNT,
    CM.DENUMIRE,
    E.TVATOTAL,
    E.TVADISCOUNT,
    P.DEN_PART,
    CASE WHEN I.CODIES &gt; 0 THEN I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) END,
    CASE WHEN OP.CODPERS &gt; 0 THEN OP.NUME||&apos;&apos; &apos;&apos;||OP.PRENUME END,
    AG.OBS,
    CASE WHEN AGE.CODPERS &gt; 0 THEN AGE.NUME||&apos;&apos; &apos;&apos;||AGE.PRENUME END,
    E.OBS,
    CASE WHEN DEL.CODPERS &gt; 0 THEN DEL.NUME||&apos;&apos; &apos;&apos;||DEL.PRENUME END,
    (SELECT STRAGG3200(E2.DENUMIRE||&apos;&apos;:&apos;&apos;||E2.VALOARE||&apos;&apos; &apos;&apos;) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND NVL(E2.VALOARE,0) &lt;&gt; 0),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 0),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 1),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 2),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 3)
    &apos;||gUserAlias||&apos;
  FROM MAN_E1 
       INNER JOIN EMULARE1 E1 ON MAN_E1.CODEMULARE1 = E1.CODEMULARE1
       INNER JOIN EMULARE E ON E.CODEMULARE = E1.CODEMULARE 
       LEFT JOIN NARTOBJ O ON O.CODOBIECT = E1.CODOBIECT 
       LEFT JOIN NUM1 UM1 ON UM1.CODUM1 = E1.UMSEC 
       LEFT JOIN IOART IOA ON IOA.CODIOART = E1.CODIOART
       LEFT JOIN NGEST G ON G.CODGEST = E1.CODGEST
       LEFT JOIN NCONT S ON S.CODCONT = E1.CONTSERV
       LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = E1.CODCOMANDA1
       LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       LEFT JOIN NCASEMARCAT CM ON CM.CODCASEMARCAT = E.CODCASAMARCAT
       LEFT JOIN NPART P ON P.CODPART = E.CODPART
       LEFT JOIN IESIRI I ON I.CODIES = E.CODMONETAR
       LEFT JOIN NPERS OP ON OP.CODPERS = E.CODPERS
       LEFT JOIN NAGENDA AG ON AG.CODAGENDA = E.CODLOCATIE
       LEFT JOIN NPERS AGE ON AGE.CODPERS = E.CODAGENT
       LEFT JOIN NPERS DEL ON DEL.CODPERS = E.DELEGAT
       &apos;||gSuplJoins||&apos;
  ORDER BY E.DATABON&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITBONRETAIL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITBONRETAILSINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8783EE08ADA3A60C22D88925C3D74E08BF5CA2F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITBONRETAILSINT is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
BEGIN
  if pkg_list_selectperioada.optiunea1 then
    delete tmp_dinamic_cols;
    INSERT INTO tmp_dinamic_cols (FIELDNAME, DISPLAY)
    SELECT &apos;C&apos;||CODCARD, DENUMIRE
    FROM CARDURI
    WHERE CODCARD &gt; 0;  
    COMMIT;
  end if;  
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;EMULARE E&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      NAV_CODDOC,
      NRBON,
      DATABON,
      VALBON,
      VALDISCBON,
      CASAMARCAT,
      TVATOTAL,
      TVADISCOUNT,
      PARTENER,
      MONETAR,
      OPERATOR,
      SEDIU,
      AGENT,
      OBS,
      DELEGAT,
      INCASARE,
      INCASARE0,
      INCASARE1,
      INCASARE2,
      INCASARE3,
      INCASARE4,
      INCASARE5,
      INCASARE6,
      INCASARE7 &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    E.CODEMULARE,
    E.NRBON,
    E.DATABON,
    E.VALOARE,
    E.VALOAREDISCOUNT,
    CM.DENUMIRE,
    E.TVATOTAL,
    E.TVADISCOUNT,
    P.DEN_PART,
    CASE WHEN I.CODIES &gt; 0 THEN I.PREFIXDOC||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC, &apos;&apos;DD.MM.YYYY&apos;&apos;) END,
    CASE WHEN OP.CODPERS &gt; 0 THEN OP.NUME||&apos;&apos; &apos;&apos;||OP.PRENUME END,
    AG.OBS,
    CASE WHEN AGE.CODPERS &gt; 0 THEN AGE.NUME||&apos;&apos; &apos;&apos;||AGE.PRENUME END,
    E.OBS,
    CASE WHEN DEL.CODPERS &gt; 0 THEN DEL.NUME||&apos;&apos; &apos;&apos;||DEL.PRENUME END,
    (SELECT STRAGG3200(E2.DENUMIRE||&apos;&apos;:&apos;&apos;||E2.VALOARE||&apos;&apos; &apos;&apos;) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND NVL(E2.VALOARE,0) &lt;&gt; 0),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 0),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 1),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 2),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 3),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 4),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 5),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 6),
    (SELECT SUM(VALOARE) FROM EMULARE2 E2 WHERE E2.CODEMULARE = E.CODEMULARE AND E2.TIPPLATA = 7)
    &apos;||gUserAlias||&apos;
  FROM EMULARE E  
       LEFT JOIN NCASEMARCAT CM ON CM.CODCASEMARCAT = E.CODCASAMARCAT
       LEFT JOIN NPART P ON P.CODPART = E.CODPART
       LEFT JOIN IESIRI I ON I.CODIES = E.CODMONETAR
       LEFT JOIN NPERS OP ON OP.CODPERS = E.CODPERS
       LEFT JOIN NAGENDA AG ON AG.CODAGENDA = E.CODLOCATIE
       LEFT JOIN NPERS AGE ON AGE.CODPERS = E.CODAGENT
       LEFT JOIN NPERS DEL ON DEL.CODPERS = E.DELEGAT
       &apos;||gSuplJoins||&apos;
  WHERE E.DATACREARE BETWEEN TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAINI, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) AND
                             TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAFIN, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) 
  ORDER BY E.DATABON&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  if pkg_list_selectperioada.optiunea1 then
    FOR V_REC IN (SELECT CODCARD FROM CARDURI where codcard &gt; 0) LOOP
      EXECUTE IMMEDIATE &apos;UPDATE &apos;||TMPNAME||&apos; T SET C&apos;||V_REC.CODCARD||&apos; = (select M.valoare from emulare2 M where m.codemulare = T.NAV_CODDOC AND M.CODCARD = &apos;||V_REC.CODCARD||&apos;)&apos;;  
    END LOOP;
  end if;
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITBONRETAILSINT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12AC0A2D4C0E0BCF8E938D923AA9D08395B1F6BA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_sitconsum IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(20000);
  sColSerii  VARCHAR2(500)    := &apos;, NULL serii, NULL serobs, NULL sercant&apos;;
  sColNP     VARCHAR2(500)    := &apos;, NULL SERIIPROD, NULL NRNP &apos;;
  sColTmpNP  VARCHAR2(500)    := &apos;, NULL SERIIPROD, NULL NRNP &apos;;
  sJoinNP    VARCHAR2(5000);
  sJoinSerii VARCHAR2(500);
  sFiltru    VARCHAR2(500);
BEGIN
  gSuplCols := &apos;ioart io, iesiri i, iesiri1 i1, livr l, livr1 l1, num1 u, nartobj o, nart a, nartamb aa, comanda1 ci1, comanda ci, comanda1 cc1, comanda cc, npart cli, nirstoc nirstoc, nclasea ca, nirser nse, nserii ser,&apos;||
               &apos;centrecost cco,LANSARE LANS,PRODCOMP PC,TMP_LST_SITCONSUM TMP, cmdprodmat mat, cmdprodmat prod&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  IF PKG_LIST_SELECTPER.AduSerii THEN
    sColSerii := &apos;,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) END serii,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string(CAST(collect(nser.obs order by s.serie) AS vc2_nt)) END serobs,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt)) END sercant&apos;;
    sJoinSerii := &apos;
           LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
           LEFT JOIN nserii s on s.codserie = nser.codserie&apos;;
  END IF;

  if PKG_LIST_SELECTPER.InfoNP then
    sColNP := &apos;, TMP.SERIIPROD, TMP.NRNP &apos;;
    sColTmpNP := &apos;, ser_np.serii, nr_np.nrdocs &apos;;
    sJoinNP := &apos;
               LEFT JOIN (select
                 CASE
                   WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||nse.cantnir||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
                 END serii,
                 i1.codcmdint1,
                 i1.codobiect
               from intrari1 i1
                    inner join intrari i on i1.codintr = i.codintr
                    inner join nirstoc ns on ns.codintr1 = i1.codintr1
                    inner join nirser nse on nse.codnirstoc = ns.codnirstoc
                    inner join nserii s on nse.codserie = s.codserie
               where nvl(i.anulat,0) = 0 and i.operat = 1 and i.tipdoc = 7
               group by i1.codcmdint1, i1.codobiect, ns.tipserie
              ) SER_NP on ser_np.codcmdint1 = lg.codcmdint1 and ser_np.codobiect = oc.codobiect
    LEFT JOIN (select
                 vc2_nt_to_string(CAST(collect(to_char(i.nrdoc) order by i.nrdoc) AS vc2_nt)) nrdocs,
                 i1.codcmdint1,
                 i1.codobiect
               from intrari1 i1
                    inner join intrari i on i1.codintr = i.codintr
               where nvl(i.anulat,0) = 0 and i.operat = 1 and i.tipdoc = 7
               group by i1.codcmdint1, i1.codobiect
              ) NR_NP on nr_np.codcmdint1 = lg.codcmdint1 and nr_np.codobiect = oc.codobiect
              &apos;;
  end if;

  IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
    sFiltru := sFiltru || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = i1.CODOBIECT ) &apos;;
  END IF;

	IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
	  sFiltru := sFiltru || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = i.CODGESTPROD) &apos;;
  END IF;
  
  DELETE TMP_LST_SITCONSUM;
  sInsert := 
 &apos;INSERT INTO TMP_LST_SITCONSUM (
    CODLIVR1,codies,codlivr,codies1,codioart1,gest,umsec,codcmdint1,codnirstoc,codnirser,   
    NAV_CodDoc,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCIESIRE,
    GEST_PROD,GEST_SURSA, DENUMIRE,PRODUS,CONT,CHELTUIELI,
    PU,CANT,UM,VALOARE, CANTUM1, CANTUM2, UM1, UM2,
    PERS, MASINA, SERII, SEROBS, SERCANT, TIPRETETA,
    NRCI, DATACI, NRCC, DATACC, CLIENT,
    PMP, PMPVALUTA, PMPPREC, PMPPRECVAL, PRETACHIZ, VALACHIZ, SERIIPROD, NRNP)
  WITH lg As (
    SELECT
      L1.CODLIVR1,i.codies, i1.codies1, l.codlivr, l1.umsec, NVL(NVL(lv.gest, n.gest),0) gest, NVL(ns.codlocatie,0) codlocatie,
      (SELECT x.CodIoart1 FROM ioart1 x WHERE x.codioart = NVL(lv.codioart,ns.codioart) AND (i.an * 12 + i.luna) BETWEEN  x.ALStart and x.ALStop) codioart1,
      ns.furn, ns.codgestprod gestfurn, sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2, ns.d1, ns.d2, ns.d3, ns.codnirstoc, nvl(l1.codnirser,0) codnirser,
      nvl(lv.pretachiz, nvl(ns.pret,0) - nvl(ns.adaos,0)) pretachiz, sum(l1.cant * nvl(lv.pretachiz, nvl(ns.pret,0) - nvl(ns.adaos,0))) valachiz, I1.CODCMDINT1 &apos;||
      sColSerii||&apos;
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      INNER JOIN livr l ON l.codies = i.codies
      INNER JOIN livr1 l1 ON l1.codies1 = i1.codies1 AND l1.codlivr = l.codlivr&apos;;
  if PKG_LIST_SELECTPER.TipPer = 1 then
    sInsert := sInsert||&apos;
    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = I1.CODCMDINT1
    INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA&apos;;
  end if;
  sInsert := sInsert||&apos;
      LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
      LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      LEFT JOIN nir n ON n.codnir = ns.codnir
    &apos;||sJoinSerii||&apos;
    WHERE i.tipdoc = 24 AND (l.operat = 1) AND (l.anulat = 0) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;);
      
    if PKG_LIST_SELECTPER.TipPer = 1 then
      sInsert := sInsert||&apos;
      AND C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)&apos;;
    else
      sInsert := sInsert||&apos;
      AND l.datalivr BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)&apos;;
    end if;
      
    sInsert := sInsert||sFiltru||&apos;
    GROUP BY
      l1.codlivr1,i.codies, i.an, i.luna, i1.codies1, l.codlivr, l1.umsec, SIGN(l1.cant), ns.codnirstoc,l1.codnirser, ns.pret, ns.adaos, lv.pretachiz,
      lv.codioart, lv.gest, n.gest, ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, ns.d1, ns.d2, ns.d3, i1.codcmdint1),
  VALORICE AS (
    SELECT VALLINK.CODIES, VALLINK.CODLIVR1, OBJVAL.DENUMIRE
    FROM IESVALLINK VALLINK
         LEFT JOIN LIVR1 L1VAL ON L1VAL.CODLIVR1 = VALLINK.CODLIVR1
         LEFT JOIN LIVR LVAL ON LVAL.CODLIVR = L1VAL.CODLIVR
         LEFT JOIN IESIRI IVAL ON LVAL.CODIES = IVAL.CODIES
         LEFT JOIN IESIRI1 I1VAL ON I1VAL.CODIES = IVAL.CODIES AND I1VAL.CODIES1 = L1VAL.CODIES1
         LEFT JOIN NARTOBJ OBJVAL ON OBJVAL.CODOBIECT = I1VAL.CODOBIECT
    WHERE VALLINK.CODIES1 IS NULL
  )
  SELECT
    lg.codlivr1,lg.codies,lg.codlivr,lg.codies1,lg.codioart1,lg.gest,lg.umsec,lg.codcmdint1,lg.codnirstoc,lg.codnirser,
    i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc dociesire,
    gp.den_gest, gs.den_gest, o.denumire, NVL(VALORICE.DENUMIRE,oc.denumire), c.simbol,cch.simbol,
    i1.pu, lg.cant, u.den_um1, i1.pu*lg.cant, lg.cantum1, lg.cantum2, u1.den_um, u2.den_um,
    pers.nume||&apos;&apos; &apos;&apos;||pers.prenume, auto.nrinreg, lg.serii, lg.serobs, lg.sercant, DECODE(pc.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,2,&apos;&apos;Dezagregare&apos;&apos;),
    ci.nrdoc, ci.datadoc, cc.nrdoc, cc.datadoc, cli.den_part,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_LEI(i1.codobiect,i.subunitatea,i.an,i.luna) end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_VALUTA_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_VALUTA_FROM_VAR end,
    lg.PretAchiz, lg.ValAchiz&apos;||sColTmpNP||&apos;
  FROM lg
    LEFT JOIN iesiri i ON i.codies = lg.codies
    LEFT JOIN livr l ON l.codlivr = lg.codlivr
    LEFT JOIN iesiri1 i1 ON i1.codies1 = lg.codies1
    LEFT JOIN ioart1 io1 ON io1.codioart1 = lg.codioart1
    LEFT JOIN ioart io ON io1.codioart = io.codioart
    LEFT JOIN ncont c ON c.codcont = io1.cont
    LEFT JOIN ncont cch ON cch.codcont = io1.cheltuieli
    LEFT JOIN ngest gp ON gp.codgest = i.codgestprod
    LEFT JOIN ngest gs ON gs.codgest = lg.gest
    LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN num1 u ON u.codum1 = lg.umsec
    LEFT JOIN num u1 ON u1.codum = a.um1
    LEFT JOIN num u2 ON u2.codum = a.um2
    LEFT JOIN npers pers ON pers.codpers = i.codpers
    LEFT JOIN nparcaut auto ON auto.codnparcaut = i.codauto
    LEFT JOIN nartamb aa ON aa.codobiect = i1.codobiect AND aa.umsec = i1.umsec
    LEFT JOIN iesprodlink ipl ON ipl.codies1 = lg.codies1
    LEFT JOIN cmdprodmat mat ON mat.codcmdprodmat = ipl.codcmdprodmat
    LEFT JOIN cmdprodmat prod ON prod.codcomanda1 = i1.codcmdint1 AND prod.tip = 0
    LEFT JOIN comanda1 c1 ON c1.codcomanda1 = mat.codcomanda1
    LEFT JOIN prodcomp pc ON pc.codprodcomp = c1.codreteta
    LEFT JOIN nartobj oc ON oc.codobiect = prod.codobiect
    LEFT JOIN VALORICE ON VALORICE.CODIES = I1.CODIES AND VALORICE.CODLIVR1 = I1.CODLIVR1PRODVAL &apos;
    ||sJoinNP||
   &apos;LEFT JOIN comanda1 ci1 ON ci1.codcomanda1 = i1.codcmdint1
    LEFT JOIN comanda ci ON ci.codcomanda = ci1.codcomanda
    LEFT JOIN cmdlink cl ON cl.codcomanda1 = ci1.codcomanda1
    LEFT JOIN comanda1 cc1 ON cc1.codcomanda1 = cl.codliniecomanda
    LEFT JOIN comanda cc ON cc.codcomanda = cc1.codcomanda
    LEFT JOIN npart cli ON cli.codpart = cc.partener
    LEFT JOIN nirstoc ON lg.codnirstoc = nirstoc.codnirstoc
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN nirser nse ON nse.codnirser = lg.codnirser
    LEFT JOIN nserii ser ON nse.codserie = ser.codserie
    LEFT JOIN centrecost cco on i1.codcentru = cco.codcentru
    LEFT JOIN LANSARE1 LANS1 ON LANS1.CODCMD1 = CI1.CODCOMANDA1
    LEFT JOIN LANSARE LANS ON LANS1.CODLANSARE = LANS.CODLANSARE
  where lg.cant &lt;&gt; 0&apos;;
    
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    NAV_CodDoc,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCIESIRE,
    GEST_PROD,GEST_SURSA, DENUMIRE,PRODUS,CONT,CHELTUIELI,
    PU,CANT,UM,VALOARE, CANTUM1, CANTUM2, UM1, UM2,
    PERS, MASINA, SERII, SEROBS, SERCANT, TIPRETETA,
    NRCI, DATACI, NRCC, DATACC, CLIENT,
    PMP, PMPVALUTA, PMPPREC, PMPPRECVAL, PRETACHIZ, VALACHIZ, SERIIPROD, NRNP &apos;||gUserFields||&apos; )
  WITH 
  VALORICE AS (
    SELECT VALLINK.CODIES, VALLINK.CODLIVR1, OBJVAL.DENUMIRE
    FROM IESVALLINK VALLINK
         LEFT JOIN LIVR1 L1VAL ON L1VAL.CODLIVR1 = VALLINK.CODLIVR1
         LEFT JOIN LIVR LVAL ON LVAL.CODLIVR = L1VAL.CODLIVR
         LEFT JOIN IESIRI IVAL ON LVAL.CODIES = IVAL.CODIES
         LEFT JOIN IESIRI1 I1VAL ON I1VAL.CODIES = IVAL.CODIES AND I1VAL.CODIES1 = L1VAL.CODIES1
         LEFT JOIN NARTOBJ OBJVAL ON OBJVAL.CODOBIECT = I1VAL.CODOBIECT
    WHERE VALLINK.CODIES1 IS NULL
  )
  SELECT
    i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc dociesire,
    gp.den_gest, gs.den_gest, o.denumire, NVL(VALORICE.DENUMIRE,oc.denumire), c.simbol,cch.simbol,
    i1.pu*u.paritate, TMP.cant/u.paritate, u.den_um1, i1.pu*TMP.cant, TMP.cantum1, TMP.cantum2, u1.den_um, u2.den_um,
    pers.nume||&apos;&apos; &apos;&apos;||pers.prenume, auto.nrinreg, TMP.serii, TMP.serobs, TMP.sercant, DECODE(pc.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,2,&apos;&apos;Dezagregare&apos;&apos;),
    ci.nrdoc, ci.datadoc, cc.nrdoc, cc.datadoc, cli.den_part,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_LEI(i1.codobiect,i.subunitatea,i.an,i.luna) end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_VALUTA_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_VALUTA_FROM_VAR end,
    TMP.PretAchiz, TMP.ValAchiz&apos;||sColNP||gUserAlias||&apos;
  FROM TMP_LST_SITCONSUM TMP
    LEFT JOIN iesiri i ON i.codies = TMP.codies
    LEFT JOIN livr l ON l.codlivr = TMP.codlivr
    LEFT JOIN livr1 l1 ON l1.codlivr1 = TMP.codlivr1
    LEFT JOIN iesiri1 i1 ON i1.codies1 = TMP.codies1
    LEFT JOIN ioart1 io1 ON io1.codioart1 = TMP.codioart1
    LEFT JOIN ioart io ON io1.codioart = io.codioart
    LEFT JOIN ncont c ON c.codcont = io1.cont
    LEFT JOIN ncont cch ON cch.codcont = io1.cheltuieli
    LEFT JOIN ngest gp ON gp.codgest = i.codgestprod
    LEFT JOIN ngest gs ON gs.codgest = TMP.gest
    LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN num1 u ON u.codum1 = TMP.umsec
    LEFT JOIN num u1 ON u1.codum = a.um1
    LEFT JOIN num u2 ON u2.codum = a.um2
    LEFT JOIN npers pers ON pers.codpers = i.codpers
    LEFT JOIN nparcaut auto ON auto.codnparcaut = i.codauto
    LEFT JOIN nartamb aa ON aa.codobiect = i1.codobiect AND aa.umsec = i1.umsec
    LEFT JOIN iesprodlink ipl ON ipl.codies1 = TMP.codies1
    LEFT JOIN cmdprodmat mat ON mat.codcmdprodmat = ipl.codcmdprodmat
    LEFT JOIN cmdprodmat prod ON prod.codcomanda1 = i1.codcmdint1 AND prod.tip = 0
    LEFT JOIN comanda1 c1 ON c1.codcomanda1 = mat.codcomanda1
    LEFT JOIN prodcomp pc ON pc.codprodcomp = c1.codreteta
    LEFT JOIN nartobj oc ON oc.codobiect = prod.codobiect
    LEFT JOIN VALORICE ON VALORICE.CODIES = I1.CODIES AND VALORICE.CODLIVR1 = I1.CODLIVR1PRODVAL
    LEFT JOIN comanda1 ci1 ON ci1.codcomanda1 = i1.codcmdint1
    LEFT JOIN comanda ci ON ci.codcomanda = ci1.codcomanda
    LEFT JOIN cmdlink cl ON cl.codcomanda1 = ci1.codcomanda1
    LEFT JOIN comanda1 cc1 ON cc1.codcomanda1 = cl.codliniecomanda
    LEFT JOIN comanda cc ON cc.codcomanda = cc1.codcomanda
    LEFT JOIN npart cli ON cli.codpart = cc.partener
    LEFT JOIN nirstoc ON tmp.codnirstoc = nirstoc.codnirstoc
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN nirser nse ON nse.codnirser = tmp.codnirser
    LEFT JOIN nserii ser ON nse.codserie = ser.codserie
    LEFT JOIN centrecost cco on i1.codcentru = cco.codcentru
    LEFT JOIN LANSARE1 LANS1 ON LANS1.CODCMD1 = CI1.CODCOMANDA1
    LEFT JOIN LANSARE LANS ON LANS1.CODLANSARE = LANS.CODLANSARE&apos;||
    gSuplJoins||&apos;
  where tmp.cant &lt;&gt; 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  
  if PKG_LIST_SELECTPER.TipPer = 1 then
  DELETE TMP_LST_SITCONSUM;
  sInsert := 
 &apos;INSERT INTO TMP_LST_SITCONSUM (
    codcmdint1,   
    NAV_CodDoc,NAV_TipDoc,
    GEST_PROD,DENUMIRE,PRODUS,
    TIPRETETA,
    NRCI, DATACI, NRCC, DATACC, CLIENT,
    SERIIPROD, NRNP)
  SELECT
    ci1.codcomanda1,
    ci.codcomanda, ci.tipdoc, 
    gp.den_gest, o.denumire, oc.denumire, 
    DECODE(pc.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,2,&apos;&apos;Dezagregare&apos;&apos;),
    ci.nrdoc, ci.datadoc, cc.nrdoc, cc.datadoc, cli.den_part&apos;||sColTmpNP||&apos;
  FROM comanda ci
    INNER JOIN comanda1 ci1 ON ci.codcomanda = ci1.codcomanda
    inner join cmdprodmat mat on mat.codcomanda1 = ci1.codcomanda1 and mat.tip = 1
    inner join cmdprodmat prod on prod.codcomanda1 = ci1.codcomanda1 and prod.tip = 0
    inner JOIN nartobj o ON o.codobiect = mat.codobiect
    inner JOIN nartobj oc ON oc.codobiect = prod.codobiect
    inner JOIN nart a ON a.codarticol = o.codarticol
    inner JOIN num1 u ON u.codum1 = a.um and coalesce(u.secundara,0) = 0
    inner JOIN prodcomp pc ON pc.codprodcomp = ci1.codreteta
    LEFT JOIN iesiri1 i1 ON i1.codcmdint1 = ci1.codcomanda1
    LEFT JOIN ngest gp ON gp.codgest = ci.codgest
    LEFT JOIN num u1 ON u1.codum = a.um1
    LEFT JOIN num u2 ON u2.codum = a.um2
    LEFT JOIN nartamb aa ON aa.codobiect = o.codobiect AND aa.umsec = u.codum1 &apos;;
  if PKG_LIST_SELECTPER.InfoNP then  
   sInsert := sInsert||&apos;
    LEFT JOIN (select
                 CASE
                   WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||nse.cantnir||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt))
                 END serii,
                 i1.codcmdint1,
                 i1.codobiect
               from intrari1 i1
                    inner join intrari i on i1.codintr = i.codintr
                    inner join nirstoc ns on ns.codintr1 = i1.codintr1
                    inner join nirser nse on nse.codnirstoc = ns.codnirstoc
                    inner join nserii s on nse.codserie = s.codserie
               where nvl(i.anulat,0) = 0 and i.operat = 1 and i.tipdoc = 7
               group by i1.codcmdint1, i1.codobiect, ns.tipserie
              ) SER_NP on ser_np.codcmdint1 = ci1.codcomanda1 and ser_np.codobiect = prod.codobiect
    LEFT JOIN (select
                 vc2_nt_to_string(CAST(collect(to_char(i.nrdoc) order by i.nrdoc) AS vc2_nt)) nrdocs,
                 i1.codcmdint1,
                 i1.codobiect
               from intrari1 i1
                    inner join intrari i on i1.codintr = i.codintr
               where nvl(i.anulat,0) = 0 and i.operat = 1 and i.tipdoc = 7
               group by i1.codcmdint1, i1.codobiect
              ) NR_NP on nr_np.codcmdint1 = ci1.codcomanda1 and nr_np.codobiect = mat.codobiect
    &apos;;
  end if;
  sInsert := sInsert||            
   &apos;LEFT JOIN cmdlink cl ON cl.codcomanda1 = ci1.codcomanda1
    LEFT JOIN comanda1 cc1 ON cc1.codcomanda1 = cl.codliniecomanda
    LEFT JOIN comanda cc ON cc.codcomanda = cc1.codcomanda
    LEFT JOIN npart cli ON cli.codpart = cc.partener
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN LANSARE1 LANS1 ON LANS1.CODCMD1 = CI1.CODCOMANDA1
    LEFT JOIN LANSARE LANS ON LANS1.CODLANSARE = LANS.CODLANSARE
  where i1.codies1 is null &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;CI&apos;)||&apos;
     and CI.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    NAV_CodDoc,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCIESIRE,
    GEST_PROD,GEST_SURSA, DENUMIRE,PRODUS,CONT,CHELTUIELI,
    PU,CANT,UM,VALOARE, CANTUM1, CANTUM2, UM1, UM2,
    PERS, MASINA, SERII, SEROBS, SERCANT, TIPRETETA,
    NRCI, DATACI, NRCC, DATACC, CLIENT,
    PMP, PMPVALUTA, PMPPREC, PMPPRECVAL, SERIIPROD, NRNP &apos;||gUserFields||&apos; )
  SELECT
    i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc dociesire,
    gp.den_gest, gs.den_gest, o.denumire, oc.denumire, c.simbol,cch.simbol,
    i1.pu*u.paritate, 0, u.den_um1, 0, 0, 0, u1.den_um, u2.den_um,
    pers.nume||&apos;&apos; &apos;&apos;||pers.prenume, auto.nrinreg, null, null, null, DECODE(pc.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,2,&apos;&apos;Dezagregare&apos;&apos;),
    ci.nrdoc, ci.datadoc, cc.nrdoc, cc.datadoc, cli.den_part,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_LEI(i1.codobiect,i.subunitatea,i.an,i.luna) end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_VALUTA_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_FROM_VAR end,
    case when io1.mg = 3 then pkg_PMP.GET_PMP_PREC_VALUTA_FROM_VAR end&apos;||sColNP||gUserAlias||&apos;
  FROM TMP_LST_SITCONSUM TMP
    INNER JOIN comanda1 ci1 ON ci1.codcomanda1 = tmp.codcmdint1
    INNER JOIN comanda ci ON ci.codcomanda = ci1.codcomanda
    INNER JOIN cmdprodmat mat ON mat.codcomanda1 = ci1.codcomanda1 and mat.tip = 1
    INNER JOIN cmdprodmat prod ON prod.codcomanda1 = ci1.codcomanda1 AND prod.tip = 0
    INNER JOIN ngest gp ON gp.codgest = ci.codgest
    INNER JOIN nartobj o ON o.codobiect = mat.codobiect
    INNER JOIN nart a ON a.codarticol = o.codarticol
    INNER JOIN num1 u ON u.codum = a.um and coalesce(u.secundara,0) = 0
    LEFT JOIN iesiri1 i1 ON i1.codcmdint1 = tmp.codcmdint1
    LEFT JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN livr l ON l.codies = i.codies
    LEFT JOIN livr1 l1 ON l1.codlivr1 = i.codies - i.codies
    LEFT JOIN ioart1 io1 ON io1.codioart1 = tmp.codcmdint1 - tmp.codcmdint1
    LEFT JOIN ioart io ON io1.codioart = tmp.codcmdint1 - tmp.codcmdint1
    LEFT JOIN ncont c ON c.codcont = tmp.codcmdint1 - tmp.codcmdint1
    LEFT JOIN ncont cch ON cch.codcont = tmp.codcmdint1 - tmp.codcmdint1
    LEFT JOIN ngest gs ON gs.codgest = i.codgestprod
    LEFT JOIN num u1 ON u1.codum = a.um1
    LEFT JOIN num u2 ON u2.codum = a.um2
    LEFT JOIN npers pers ON pers.codpers = i.codpers
    LEFT JOIN nparcaut auto ON auto.codnparcaut = i.codauto
    LEFT JOIN nartamb aa ON aa.codobiect = mat.codobiect AND aa.umsec = u.codum1
    LEFT JOIN iesprodlink ipl ON ipl.codies1 = tmp.codies1
    LEFT JOIN prodcomp pc ON pc.codprodcomp = ci1.codreteta
    LEFT JOIN nartobj oc ON oc.codobiect = prod.codobiect
    LEFT JOIN cmdlink cl ON cl.codcomanda1 = ci1.codcomanda1
    LEFT JOIN comanda1 cc1 ON cc1.codcomanda1 = cl.codliniecomanda
    LEFT JOIN comanda cc ON cc.codcomanda = cc1.codcomanda
    LEFT JOIN npart cli ON cli.codpart = cc.partener
    LEFT JOIN nirstoc ON tmp.codnirstoc = nirstoc.codnirstoc
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN nirser nse ON nse.codnirser = tmp.codnirser
    LEFT JOIN nserii ser ON nse.codserie = ser.codserie
    LEFT JOIN centrecost cco on i1.codcentru = cco.codcentru
    LEFT JOIN LANSARE1 LANS1 ON LANS1.CODCMD1 = CI1.CODCOMANDA1
    LEFT JOIN LANSARE LANS ON LANS1.CODLANSARE = LANS.CODLANSARE&apos;||
    gSuplJoins||&apos;
  where i1.codies1 is null &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  end if;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITCONSUM; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUMPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84C79C85D2AC7E2C460B4C921909D6081A13CDD2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITCONSUMPROD IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(10000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sInsTMP   CLOB;
  sSelect   CLOB;
  sCondGest VARCHAR2(1000);
  sJoinAux  VARCHAR2(1000);
  vCuStoc   BOOLEAN;
  vCampStoc VARCHAR2(50);
  sPer      VARCHAR2(500)  := &apos; BETWEEN to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTGESTPER.datadocini,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTGESTPER.datadocfin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sPerCmd   VARCHAR2(500)  := &apos; BETWEEN to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTGESTPER.dataini,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTGESTPER.datafin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sSeriiField VARCHAR2(50);
  sSeriiIes VARCHAR2(1000);
  sSeriiIntr VARCHAR2(1000);
  sSeriiNull VARCHAR2(50);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;comanda c, comanda1 c1, num1 umc, ngest g, nartobj objmat, nart art, num umm, nartobj objret, comanda1 ccli1, comanda ccli, npart p, nirstoc ns,&apos;||
                &apos;cmdprodmat prod, formatii f, nclasea cls, ncont contp, prodcomp pc, cmdprodmat mat, cmdprodman man&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTMAT&apos;, &apos;OEXTMAT.CODOBIECT = OBJMAT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRMAT&apos;, &apos;OATRMAT.CODOBIECT = OBJMAT.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTRET&apos;, &apos;OEXTRET.CODOBIECT = OBJRET.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRRET&apos;, &apos;OATRRET.CODOBIECT = OBJRET.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;,    &apos;CV&apos;,      &apos;CV.CODCOMANDA     = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;,   &apos;CV1&apos;,     &apos;CV1.CODCOMANDA1   = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;,    &apos;CCV&apos;,     &apos;CCV.CODCOMANDA    = CCLI.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;,   &apos;CCV1&apos;,    &apos;CCV1.CODCOMANDA1  = CCLI1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;,   &apos;CCOST.CODCENTRU   = Coalesce(C1.CODCENTRU,0)&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);

  sSeriiField := &apos;&apos;;
  sSeriiIes   := &apos;&apos;;
  sSeriiIntr  := &apos;&apos;;
  if PKG_LIST_SELECTGESTPER.AduSerii then
    sSeriiField := &apos;,Serii&apos;;
    sSeriiIes   := &apos;,(select stragg3200(ser.serie||&apos;&apos;(&apos;&apos;||to_char(l1.cant)||&apos;&apos;)&apos;&apos;) from nirser nse inner join nserii ser on ser.codserie = nse.codserie where nse.codnirser = l1.codnirser)&apos;;
    sSeriiIntr  := &apos;,(select stragg3200(ser.serie||&apos;&apos;(&apos;&apos;||to_char(ns.cantnir)||&apos;&apos;)&apos;&apos;) from nirser nse inner join nserii ser on ser.codserie = nse.codserie where nse.codnirstoc = ns.codnirstoc)&apos;;
    sSeriiNull  := &apos;, null&apos;;
  end if;

  sCondGest := &apos;&apos;;
  IF not PKG_LIST_SELECTGESTPER.ToateGest THEN
    sCondGest := &apos;
    AND c.codgest IN (SELECT valoare FROM tmp_manevra_liste WHERE upper(filtru) = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;
  vCuStoc := PKG_LIST_SELECTGESTPER.Extra1;

  DELETE comanda1_man;
  if PKG_LIST_SELECTGESTPER.Cod &gt; 0 then
    sInsTMP :=
    &apos;INSERT INTO comanda1_man (codcomanda1)
    select c1.codcomanda1
    from comanda1 c1 inner join comanda c on c.codcomanda = c1.codcomanda
    WHERE c1.codcomanda1 = &apos;||PKG_LIST_SELECTGESTPER.Cod;
  else
    sInsTMP :=
    &apos;INSERT INTO comanda1_man (codcomanda1)
    select c1.codcomanda1
    from comanda1 c1 inner join comanda c on c.codcomanda = c1.codcomanda
    WHERE c.tipdoc = 53 AND c.operat = 1 AND c.anulat = 0
      AND c.datadoc&apos;||sPerCmd||&apos;
      AND c1.cantacceptat &gt; 0&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;c&apos;)||
      sCondGest;
  end if;
  LIST_EXECUTE_IMMEDIATE(sInsTMP, aListID, aListVer);

  DELETE tmp_cmd where userid = pkg_globals.GETUSERID;

  sInsTMP :=
  &apos;INSERT INTO TMP_CMD (CODOBIECT, RESTA, USERID, TIP)
  SELECT NS.CODOBIECT,SUM(NS.REST) RESTA, &apos;||pkg_globals.GETUSERID||&apos;, &apos;&apos;STOC&apos;&apos;
  FROM NIRSTOC NS
    INNER JOIN NIR        ON NS.CODNIR    = NIR.CODNIR
    INNER JOIN NGEST  NG  ON NIR.GEST     = NG.CODGEST
    LEFT  JOIN IOART1 IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop
  WHERE NS.REST &gt; 0 AND IOA.MG &lt;&gt; 5 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;, &apos;CODSUBUNIT&apos;)||&apos;
  GROUP BY NS.CODOBIECT, &apos;||pkg_globals.GETUSERID;

  IF vCuStoc THEN
     LIST_EXECUTE_IMMEDIATE(sInsTMP, aListID, aListVer);
     vCampStoc := &apos;, Coalesce(stoc.resta,0) stoc &apos;;
     sJoinAux  := sJoinAux||&apos;
    LEFT JOIN TMP_CMD STOC ON stoc.codobiect = objmat.codobiect and stoc.tip = &apos;&apos;STOC&apos;&apos; and stoc.userid = &apos;||pkg_globals.GETUSERID;
  ELSE
    vCampStoc := &apos;,0 stoc &apos;;
  END IF;

--  sInsTMP :=
--    &apos;INSERT INTO TMP_CMD (CODOBIECT, RESTA, USERID, TIP)
--    SELECT R.CODCMDPRODMAT,SUM(R.REST) RESTA, &apos;||pkg_globals.GETUSERID||&apos;, &apos;&apos;REZ&apos;&apos;
--    FROM REZERVATS R
--      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = R.CODCOMANDA1
--      INNER JOIN CMDPRODMAT MAT ON MAT.CODCMDPRODMAT = R.CODCMDPRODMAT
--    GROUP BY R.CODCMDPRODMAT &apos;;

  sInsTMP :=
  &apos;INSERT INTO TMP_CMD (CODOBIECT, RESTA, USERID, TIP)
  SELECT R.CODCMDPRODMAT,SUM(R.REST) RESTA, &apos;||pkg_globals.GETUSERID||&apos;, &apos;&apos;REZ&apos;&apos;
  FROM COMANDA1_MAN C1M
    INNER JOIN REZERVATS R ON R.CODCOMANDA1 = C1M.CODCOMANDA1
    INNER JOIN CMDPRODMAT MAT ON MAT.CODCMDPRODMAT = R.CODCMDPRODMAT
  GROUP BY R.CODCMDPRODMAT &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsTMP, aListID, aListVer);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc, NAV_TipDoc, Explicatii,
    ValConsum, ValPredare,
    DataComInt, TermenExec, NrComProd, Client,
    NrComCli, DataComCli, TermenCli, ValCmdInt,
    DENUMIRE, SectiePred, ObsComInt, reteta,
    Cant, CantPredata, UM,
    Tip, ObsDoc, ContPredare, ContConsum,
    CantRez, ObsDet, Stoc &apos;||sSeriiField||gUserFields||&apos;)&apos;;

  --**** CONSUM
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, I.PrefixDoc||&apos;&apos; &apos;&apos;||I.NrDoc||&apos;&apos;/&apos;&apos;||I.DataDoc Explicatii,
    L1.Cant * (NS.PRET - COALESCE(NS.ADAOS,0)) ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    mat.cant, L1.CANT cantpredata, case when mat.tip = 0 then UMC.Den_UM1 else UMM.Den_um end um,
    &apos;&apos;CONSUM&apos;&apos; Tip, I.Obs ObsDoc, &apos;&apos; &apos;&apos; ContPredare, CONTP.Simbol ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, I1.Obs ObsDet &apos;||vCampStoc||sSeriiIes||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat     mat on mat.codcomanda1 = c1m.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN IESPRODLINK   LIES on LIES.CodCmdProdMat = mat.codcmdprodmat
    INNER JOIN IESIRI1         I1 ON LIES.CodIes1    = I1.CodIes1
    INNER JOIN IESIRI           I ON I1.CodIes       = I.CodIes
    INNER JOIN livr             L ON L.CodIes        = I.CodIes
    INNER JOIN livr1           L1 ON L1.CodIes1      = I1.CodIes1 and l.codlivr = l1.codlivr
    INNER JOIN NIRSTOC         NS ON L1.CODNIRSTOC   = NS.CODNIRSTOC
    LEFT JOIN IOART1          IO1 ON IO1.CODIOART    = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT   = IO1.CONT
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect   = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum       = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect    = objret.codobiect
    left  join prodcomp        pc on pc.codprodcomp  = c1.codreteta
    left  join nclasea        cls on cls.codclasea   = art.clasa
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1  = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT   = MAT.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux;
  IF not pkg_list_selectgestper.Indiferent THEN
    sSelect := sSelect||&apos;
    WHERE I.DataDoc&apos;||sPer ;
  END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** FARA CONSUM
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, &apos;&apos;Fara consum&apos;&apos; Explicatii,
    0 ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    mat.rest CANT, 0 cantpredata, case when mat.tip = 0 then UMC.Den_UM1 else UMM.Den_um end um,
    &apos;&apos;FARA CONSUM&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat     mat ON c1m.codcomanda1 = mat.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect   = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum      = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect   = objret.codobiect
    left  join prodcomp        pc ON pc.codprodcomp = c1.codreteta
    left  join nclasea        cls ON cls.codclasea  = art.clasa
    LEFT  JOIN NIRSTOC         NS ON NS.CODNIRSTOC  = MAT.TIP - 1
    LEFT  JOIN IESPRODLINK   LIES on LIES.CodCmdProdMat   = mat.codcmdprodmat
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1       = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT   = MAT.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE mat.tip = 1 AND Coalesce(LIES.CodIes1,0) = 0 and mat.rest = mat.cant and Coalesce(ART.TIPARTICOL,&apos;&apos;0&apos;&apos;) = &apos;&apos;0&apos;&apos;&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** SERVICII
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, SERV.FACT Explicatii,
    Coalesce(SERV.VALOARE,0) ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd,
    p.den_part Client, ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire  reteta,
    mat.rest Cant, Coalesce(SERV.CANT,0) cantpredata, case when mat.tip = 0 then UMC.Den_UM1 else UMM.Den_um end um,
    &apos;&apos;SERVICII&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat     mat ON c1m.codcomanda1 = mat.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect   = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum      = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect   = objret.codobiect
    left  join prodcomp       pc on pc.codprodcomp  = c1.codreteta
    left  join nclasea         cls on cls.codclasea = art.clasa
    LEFT  JOIN NIRSTOC         NS ON NS.CODNIRSTOC  = MAT.TIP - 1
    LEFT  JOIN IESPRODLINK   LIES on LIES.CodCmdProdMat   = mat.codcmdprodmat
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1       = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN (
      SELECT INTR1.CODCMDINT1 CODCOMANDA1, INTR1.CODOBIECT, SUM(INTR1.CANT) CANT, SUM(INTR1.CANT * INTR1.PU) VALOARE, stragg3200(INTR.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(INTR.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;)) FACT
      FROM INTRARI1 INTR1
        INNER JOIN NARTOBJ OBJ  ON INTR1.CODOBIECT = OBJ.CODOBIECT
        INNER JOIN NART    ART  ON ART.CODARTICOL  = OBJ.CODARTICOL
        INNER JOIN INTRARI INTR ON INTR.CODINTR    = INTR1.CODINTR
      WHERE Coalesce(ART.TIPARTICOL,&apos;&apos;0&apos;&apos;) = &apos;&apos;1&apos;&apos; AND Coalesce(INTR.ANULAT,0) = 0 AND INTR.OPERAT = 1
      GROUP BY INTR1.CODCMDINT1, INTR1.CODOBIECT
    ) SERV ON SERV.CODCOMANDA1 = C1.CODCOMANDA1 AND SERV.CODOBIECT = MAT.CODOBIECT
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT = MAT.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE mat.tip = 1 AND Coalesce(LIES.CodIes1,0) = 0 and mat.rest = mat.cant and Coalesce(ART.TIPARTICOL,&apos;&apos;0&apos;&apos;) = &apos;&apos;1&apos;&apos;&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** FARA PREDARE
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, &apos;&apos;Fara predare&apos;&apos; Explicatii,
    0 ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd,
    p.den_part Client, ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    mat.rest Cant, 0 cantpredata, UMC.Den_UM1 um,
    &apos;&apos;FARA PREDARE&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat     mat ON c1m.codcomanda1 = mat.codcomanda1 and (mat.tip = 2 or (mat.tip = 0 and c1.consum = 1)) and mat.rest = mat.cant
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0 and prod.rest = prod.cant
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect   = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum      = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect   = objret.codobiect
    left  join prodcomp        pc on pc.codprodcomp = c1.codreteta
    left  join nclasea        cls on cls.codclasea  = art.clasa
    LEFT  JOIN NIRSTOC         NS ON NS.CODNIRSTOC  = MAT.TIP - 1
    LEFT  JOIN INTRPRODLINK LINTR on LINTR.CodLinieComanda = mat.codcmdprodmat and mat.rest &lt;&gt; mat.cant
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1        = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda  = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT   = MAT.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE Coalesce(LINTR.CodIntr1,0) = 0&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** CONSUM SUPLIMENTAR
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, I.PrefixDoc||&apos;&apos; &apos;&apos;||I.NrDoc||&apos;&apos;/&apos;&apos;||I.DataDoc Explicatii,
    L1.Cant * (NS.PRET - COALESCE(NS.ADAOS,0)) ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    0 cant, L1.CANT cantpredata, UMM.Den_um um,
    &apos;&apos;CONSUM SUPLIMENTAR&apos;&apos; Tip, I.Obs ObsDoc, &apos;&apos; &apos;&apos; ContPredare, CONTP.Simbol ContConsum,
    0 CantRez, I1.Obs ObsDet &apos;||vCampStoc||sSeriiIes||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1m.CODCOMANDA1 = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN IESIRI1         I1 ON C1.CodComanda1  = I1.CodCmdInt1
    INNER JOIN IESIRI           I ON I1.CodIes  = I.CodIes
    inner join livr             l on i.codies   = l.codies
    INNER JOIN livr1           L1 ON L1.CodIes1 = I1.CodIes1 and l.codlivr = l1.codlivr
    INNER JOIN NIRSTOC         NS ON L1.CODNIRSTOC = NS.CODNIRSTOC
    LEFT JOIN IOART1          IO1 ON IO1.CODIOART  = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT = IO1.CONT
    INNER JOIN NARTOBJ     OBJmat ON i1.codobiect  = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum      = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect   = objret.codobiect
    left  join prodcomp        pc on pc.codprodcomp = c1.codreteta
    left  join nclasea        cls on cls.codclasea  = art.clasa
    LEFT  JOIN IESPRODLINK   LIES on LIES.CodIes1   = i1.codies1
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda      = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodmat     mat on mat.codcomanda1 = c1.codcomanda1 - c1.codcomanda1
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1&apos;||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE Coalesce(LIES.codcmdprodmat,0) = 0 &apos;;
  if not pkg_list_selectgestper.Indiferent then
    sSelect := sSelect||&apos;
    and I.DataDoc&apos;||sPer;
  end if;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** REBUT/PREDARE
  sSelect := &apos;  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, case when INTR.TIPTRANZACTIE = 10 THEN &apos;&apos;NR&apos;&apos; WHEN INTR.TIPTRANZACTIE = 9 THEN &apos;&apos;NPR&apos;&apos; ELSE INTR.PrefixDoc END||&apos;&apos; &apos;&apos;||INTR.NrDoc||&apos;&apos;/&apos;&apos;||INTR.DataDoc Explicatii,
    0 ValConsum, INTR1.Cant * INTR1.PU ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objmat.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    mat.cant, INTR1.CANT cantpredata, case when mat.tip = 0 then UMC.Den_UM1 else UMM.Den_um end um,
    case when intr.tiptranzactie = 9 then &apos;&apos;REBUT&apos;&apos; else &apos;&apos;PREDARE&apos;&apos; end Tip, INTR.Obs ObsDoc, contp.simbol ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, INTR1.Obs ObsDet &apos;||vCampStoc||sSeriiIntr||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodmat     mat on c1m.codcomanda1 = mat.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN NUM1           UMC ON UMC.codum1      = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN INTRPRODLINK LINTR on LINTR.CodLinieComanda = mat.codcmdprodmat
    INNER JOIN INTRARI1     INTR1 ON LINTR.CodIntr1 = INTR1.CodIntr1
    INNER JOIN INTRARI       INTR ON INTR.CodIntr   = INTR1.CodIntr
    LEFT JOIN LIVR1            L1 ON L1.CODINTR1    = INTR1.CODINTR1
    LEFT JOIN NIRSTOC          NS ON NS.CODINTR1    = INTR1.CODINTR1 OR NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN IOART1          IO1 ON IO1.CODIOART   = NS.CODIOART AND INTR.AN*12+INTR.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT  = IO1.CONT
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect  = objmat.codobiect
    INNER JOIN NART           ART ON objmat.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum      = art.UM
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect   = objret.codobiect
    left  join prodcomp        pc on pc.codprodcomp = c1.codreteta
    left  join nclasea        cls on cls.codclasea  = art.clasa
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT   = MAT.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE intr.anulat = 0 &apos;;
  IF not pkg_list_selectgestper.Indiferent THEN
    sSelect := sSelect||&apos;
    AND Intr.DataDoc&apos;||sPer;
  END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** PREDARE SUPLIMENTARA
  sSelect := &apos;  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, INTR.PrefixDoc||&apos;&apos; &apos;&apos;||INTR.NrDoc||&apos;&apos;/&apos;&apos;||INTR.DataDoc Explicatii,
    0 ValConsum, INTR1.Cant * INTR1.PU ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    objNP.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    0 cant, NS.CANTNIR cantpredata, UMC.Den_UM1 um,
    &apos;&apos;PREDARE SUPLIMENTARA&apos;&apos; Tip, INTR.Obs ObsDoc, contp.simbol ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    Coalesce(REZ.RESTA,0) CantRez, INTR1.Obs ObsDet &apos;||vCampStoc||sSeriiIntr||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1  = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1   = PROD.CODCOMANDA1 AND ((Coalesce(PROD.TIP,0) in (0,2) and c1.consum = 1) or (Coalesce(PROD.TIP,0) = 2 and c1.consum = 2))
    INNER JOIN NUM1           UMC ON UMC.codum1       = c1.UMSEC
    INNER JOIN comanda          c ON c1.codcomanda    = c.codcomanda
    INNER JOIN ngest            g ON c.codgest        = g.codgest
    INNER JOIN INTRARI1     INTR1 ON INTR1.CodCmdInt1 = c1.codcomanda1 AND INTR1.CODOBIECT = PROD.CODOBIECT
    INNER JOIN NIRSTOC         NS ON NS.CODINTR1   = INTR1.CODINTR1
    INNER JOIN INTRARI       INTR ON INTR.CodIntr  = INTR1.CodIntr
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NARTOBJ     ObjNP  ON intr1.codobiect  = objNP.codobiect
    INNER JOIN NART           ART ON objNP.codarticol = art.codarticol
    INNER JOIN NUM            UMM ON UMM.codum        = art.UM
    LEFT  JOIN NARTOBJ     ObjMat ON c1.codobiect - c1.codobiect = objmat.codobiect
    LEFT JOIN IOART1          IO1 ON IO1.CODIOART  = NS.CODIOART AND INTR.AN*12+INTR.LUNA BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT = IO1.CONT
    LEFT  JOIN INTRPRODLINK LINTR on LINTR.CodLinieComanda = prod.codcmdprodmat AND LINTR.CODINTR1 = INTR1.CODINTR1
    left  join prodcomp        pc on pc.codprodcomp = c1.codreteta
    left  join nclasea        cls on cls.codclasea  = art.clasa
    LEFT  JOIN cmdlink       cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT  JOIN comanda1     CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT  JOIN comanda       CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT  JOIN formatii         f ON c.codformatie   = f.codformatie
    LEFT  JOIN npart            p ON p.codpart       = ccli.partener
    left  join cmdprodmat     mat on mat.codcomanda1 = c1.codcomanda1 - c1.codcomanda1
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    LEFT  JOIN TMP_CMD        REZ ON REZ.CODOBIECT   = PROD.CODCMDPRODMAT AND REZ.TIP = &apos;&apos;REZ&apos;&apos; AND REZ.USERID = &apos;||pkg_globals.GETUSERID||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE intr.anulat = 0 and LINTR.CODINTR1 IS NULL &apos;;
  if not pkg_list_selectgestper.Indiferent then
    sSelect := sSelect||&apos;
    AND Intr.DataDoc&apos;||sPer;
  end if;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** RAPORTARE SUPLIMENTARA
  sSelect := &apos;
  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, r.NrDoc||&apos;&apos;/&apos;&apos;||r.DataI Explicatii,
    CASE WHEN r2.codies1 &gt; 0 THEN i1.pu ELSE T1.Tarif END * Coalesce(r2.TU, pm.tu) * r2.REALIZAT / 60 ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    case when Coalesce(OP.codop,0) = 0 then OPMan.DENUMIRE else OP.Denumire end Denumire, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    0 cant, r2.realizat cantpredata, UMC.Den_UM1 um,
    &apos;&apos;RAPORTARE SUPLIMENTARA&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    0 CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN raportp0        r0 ON r0.CodComanda1  = c1m.CodComanda1
    INNER JOIN raportp          r ON r0.CodRaportP   = r.CodRaportP
    INNER JOIN raportp1        r1 ON r1.CodRaportP0  = r0.CodRaportP0
    INNER JOIN raportp2        r2 ON r2.CodRaportP1  = r1.CodRaportP1
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect    = objret.codobiect
    LEFT JOIN nirstoc          ns ON ns.codnirstoc   = ObjRet.CodObiect - ObjRet.CodObiect
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT   = objret.codobiect - objret.codobiect
    LEFT JOIN NARTOBJ      ObjMat ON c1.codobiect - c1.codobiect = objmat.codobiect
    LEFT JOIN NART         ArtMat ON ObjMat.codarticol = ArtMat.codarticol
    left JOIN NUM              UM ON UM.codum       = ArtMat.UM
    left JOIN NUM1            UMC ON UMC.codum1     = c1m.codcomanda1 - c1m.codcomanda1
    left join prodcomp         pc on pc.codprodcomp = c1.codreteta
    LEFT JOIN cmdlink        cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT JOIN comanda1      CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT JOIN comanda        CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT JOIN formatii          f ON c.codformatie   = f.codformatie
    LEFT JOIN npart             p ON p.codpart   = ccli.partener
    LEFT JOIN IESIRI1          I1 ON I1.CODIES1  = R2.CODIES1
    left JOIN ProdMan          PM ON PM.CodMan   = r2.CodMan
    left join locmunca         lm on r2.codloc   = lm.codloc
    LEFT JOIN Tarifeman1       T1 on T1.CodTarif = CASE WHEN Coalesce(r2.CodTarif,0) = 0 THEN Pm.codTarif ELSE r2.CodTarif END
                                     AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop
    LEFT JOIN NOper            Op ON Op.CodOp      = r2.CodOp
    LEFT JOIN NOper         OpMan ON OpMan.CodOp   = PM.CodOp
    left join nclasea         cls ON cls.codclasea = c1m.codcomanda1 - c1m.codcomanda1
    LEFT JOIN manprodlink    manl ON manl.CodRaportP2 = r2.codraportp2
    left JOIN NART            ART ON art.codarticol   = objmat.codarticol - objmat.codarticol
    left  join cmdprodman     man on man.codcmdprodman = c1.codcomanda1 - c1.codcomanda1
    left  join cmdprodmat     mat on mat.codcomanda1  = c1.codcomanda1 - c1.codcomanda1 &apos;||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE Coalesce(manl.codraportp2,0) = 0 &apos;;
  if not pkg_list_selectgestper.Indiferent then
    sSelect := sSelect||&apos;
    AND ( (R.DataI&apos;||sPer||&apos;) or (R.DataS&apos;||sPer||&apos;) ) &apos;;
  end if;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** RAPORTARE
  sSelect := &apos;  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, r.NrDoc||&apos;&apos;/&apos;&apos;||r.DataI Explicatii,
    CASE WHEN r2.codies1 &gt; 0 THEN i1.pu ELSE T1.Tarif END * Coalesce(r2.TU, pm.tu) * r2.REALIZAT / 60 ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    case when Coalesce(OP.codop,0) = 0 then OPMan.DENUMIRE else OP.Denumire end DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    man.cant, r2.realizat cantpredata, UMC.Den_UM1 um,
    &apos;&apos;RAPORTARE&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    0 CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodman     man on man.codcomanda1 = c1m.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN manprodlink   manl on manl.CodCmdProdMan = man.codcmdprodman
    INNER JOIN raportp2        r2 ON manl.CodRaportP2 = r2.CodRaportP2
    INNER JOIN raportp1        r1 ON r1.CodRaportP1   = r2.CodRaportP1
    INNER JOIN raportp0        r0 ON r0.CodRaportP0   = r1.CodRaportP0
    INNER JOIN raportp          r ON r0.CodRaportP = r.CodRaportP
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    LEFT JOIN nirstoc          ns ON ns.codnirstoc = ObjRet.CodObiect - ObjRet.CodObiect
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT = objret.codobiect - objret.codobiect
    LEFT JOIN NARTOBJ      ObjMat ON c1.codobiect - c1.codobiect = objmat.codobiect
    LEFT JOIN NART         ArtMat ON ObjMat.codarticol = ArtMat.codarticol
    left JOIN NUM              UM ON UM.codum   = ArtMat.UM
    left JOIN NUM1            UMC ON UMC.codum1 = c1m.codcomanda1 - c1m.codcomanda1
    left join prodcomp         pc on pc.codprodcomp = c1.codreteta
    LEFT JOIN cmdlink        cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT JOIN comanda1      CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT JOIN comanda        CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT JOIN formatii          f ON c.codformatie   = f.codformatie
    LEFT JOIN npart             p ON p.codpart   = ccli.partener
    LEFT JOIN IESIRI1          I1 ON I1.CODIES1  = R2.CODIES1
    left JOIN ProdMan          PM ON PM.CodMan   = r2.CodMan
    left join locmunca         lm on r2.codloc   = lm.codloc
    LEFT JOIN Tarifeman1       T1 on T1.CodTarif = CASE WHEN Coalesce(r2.CodTarif,0) = 0 THEN Pm.codTarif ELSE r2.CodTarif END
                                     AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop
    LEFT JOIN NOper            Op ON Op.CodOp        = r2.CodOp
    LEFT JOIN NOper         OpMan ON OpMan.CodOp     = PM.CodOp
    left  join nclasea        cls ON cls.codclasea   = c1m.codcomanda1 - c1m.codcomanda1
    left JOIN NART            ART ON art.codarticol  = objmat.codarticol - objmat.codarticol
    left  join cmdprodmat     mat on mat.codcomanda1 = c1.codcomanda1 - c1.codcomanda1 &apos;||
    gSuplJoins||
    sJoinAux;
  IF not pkg_list_selectgestper.Indiferent THEN
    sSelect := sSelect||&apos;
    WHERE ( (R.DataI&apos;||sPer||&apos;) or (R.DataS&apos;||sPer||&apos;) ) &apos;;
  END IF;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  --**** FARA RAPORTARE
  sSelect := &apos;  SELECT
    c.codcomanda NAV_CodDoc, c.tipdoc NAV_TipDoc, &apos;&apos;Fara raportare&apos;&apos; Explicatii,
    0 ValConsum, 0 ValPredare,
    c.datadoc DataComInt, c1.termen TermenExec, c.nrdoc NrComProd, p.den_part Client,
    ccli.nrdoc NrComCli, ccli.datadoc DataComCli, ccli1.termen TermenCli, c.valoare ValCmdInt,
    OPMan.DENUMIRE, g.den_gest SectiePred, c.obs ObsComInt, objret.denumire reteta,
    man.cant, 0 cantpredata, UMC.Den_UM1 um,
    &apos;&apos;FARA RAPORTARE&apos;&apos; Tip, &apos;&apos; &apos;&apos; ObsDoc, &apos;&apos; &apos;&apos; ContPredare, &apos;&apos; &apos;&apos; ContConsum,
    0 CantRez, &apos;&apos; &apos;&apos; ObsDet &apos;||vCampStoc||sSeriiNull||gUserAlias||&apos;
  FROM comanda1_man c1m
    INNER JOIN comanda1        c1 ON c1m.codcomanda1 = c1.codcomanda1
    inner join cmdprodman     man on man.codcomanda1 = c1m.codcomanda1
    INNER JOIN CMDPRODMAT    PROD ON C1.CODCOMANDA1  = PROD.CODCOMANDA1 AND Coalesce(PROD.TIP,0) = 0
    INNER JOIN comanda          c ON c1.codcomanda   = c.codcomanda
    INNER JOIN ngest            g ON c.codgest       = g.codgest
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect    = objret.codobiect
    LEFT JOIN manprodlink   manl on manl.CodCmdProdMan = man.codcmdprodman
    LEFT JOIN raportp2        r2 ON manl.CodRaportP2 = r2.CodRaportP2
    LEFT JOIN raportp1        r1 ON r1.CodRaportP1   = r2.CodRaportP1
    LEFT JOIN raportp0        r0 ON r0.CodRaportP0   = r1.CodRaportP0
    LEFT JOIN raportp          r ON r0.CodRaportP    = r.CodRaportP
    LEFT JOIN nirstoc          ns ON ns.codnirstoc   = ObjRet.CodObiect - ObjRet.CodObiect
    LEFT JOIN NARTOBJ      ObjMat ON c1.codobiect - c1.codobiect = objmat.codobiect
    LEFT JOIN NART         ArtMat ON ObjMat.codarticol = ArtMat.codarticol
    left JOIN NUM              UM ON UM.codum   = ArtMat.UM
    left JOIN NUM1            UMC ON UMC.codum1 = c1m.codcomanda1 - c1m.codcomanda1
    LEFT JOIN NCONT         CONTP ON CONTP.CODCONT  = objret.codobiect - objret.codobiect
    left join prodcomp         pc on pc.codprodcomp = c1.codreteta
    LEFT JOIN cmdlink        cmdl ON c1.codcomanda1 = cmdl.codcomanda1
    LEFT JOIN comanda1      CCli1 ON cmdl.codliniecomanda = ccli1.codcomanda1
    LEFT JOIN comanda        CCli ON ccli.codcomanda = ccli1.codcomanda
    LEFT JOIN formatii          f ON c.codformatie   = f.codformatie
    LEFT JOIN npart             p ON p.codpart   = ccli.partener
    LEFT JOIN IESIRI1          I1 ON I1.CODIES1  = R2.CODIES1
    left JOIN ProdMan          PM ON PM.CodMan   = r2.CodMan
    left join locmunca         lm on r2.codloc   = lm.codloc
    LEFT JOIN Tarifeman1       T1 on T1.CodTarif = CASE WHEN Coalesce(r2.CodTarif,0) = 0 THEN Pm.codTarif ELSE r2.CodTarif END
                                     AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop
    LEFT JOIN NOper         OpMan ON OpMan.CodOp = Man.CodOp
    left  join nclasea        cls on cls.codclasea   = c1m.codcomanda1 - c1m.codcomanda1
    left JOIN NART            ART ON art.codarticol  = objmat.codarticol - objmat.codarticol
    left  join cmdprodmat     mat on mat.codcomanda1 = c1.codcomanda1 - c1.codcomanda1 &apos;||
    gSuplJoins||
    sJoinAux||&apos;
  WHERE man.rest = man.cant &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  DELETE tmp_cmd WHERE userid = pkg_globals.GETUSERID;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_sitconsumprod;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITCONSUM_M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>483C7F8070319E1AAA5EA792EE06FE07EF477D0C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_sitconsum_m IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert    VARCHAR2(9000);
sColSerii  VARCHAR2(500)    := &apos;, NULL serii, NULL serobs, NULL sercant&apos;;
sJoinSerii VARCHAR2(500);
sFiltru    VARCHAR2(500);
BEGIN
  gSuplCols := &apos;ioart io,iesiri i,iesiri1 i1,livr l,num1 u,nartobj o,nart a,nartamb aa,comanda1 ci1,comanda ci,nirstoc nirstoc,nclasea ca,centrecost cc,&apos;||
               &apos;utilaje2c ut2c,utilaje ut,utilaje2 ut2,ninterventiiauto interv,nartobj intervserv,nartobj utilajobj,NCLASEINT CLSINT&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_SELECTPER.AduSerii THEN
    sColSerii := &apos;,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string(CAST(collect(s.serie order by s.serie) AS vc2_nt)) END serii,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string(CAST(collect(nser.obs order by s.serie) AS vc2_nt)) END serobs,
        CASE WHEN nvl(ns.tipserie,0) &lt;&gt; 0 THEN vc2_nt_to_string_sum(CAST(collect(s.serie||&apos;&apos;(~#&apos;&apos;||l1.cant||&apos;&apos;#~)&apos;&apos; order by s.serie) AS vc2_nt)) END sercant&apos;;
    sJoinSerii := &apos;
           LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
           LEFT JOIN nserii s on s.codserie = nser.codserie&apos;;
  END IF;

  IF PKG_LIST_SELECTPER.ToateArt = FALSE THEN
    sFiltru := sFiltru || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = i1.CODOBIECT ) &apos;;
  END IF;

  IF PKG_LIST_SELECTPER.ToateGest = FALSE THEN
    sFiltru := sFiltru || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; AND VALOARE = i.CODGESTPROD) &apos;;
  END IF;

  sInsert :=
 &apos;INSERT INTO &apos;||TMPNAME||&apos; (
    NAV_CodDoc,NAV_TipDoc,PREFIXDOC,NRDOC,DATADOC,DOCIESIRE,
    GEST_PROD,GEST_SURSA, DENUMIRE,PRODUS,CONT,CHELTUIELI,
    PU,CANT,UM,VALOARE, CANTUM1, CANTUM2, UM1, UM2,
    PERS, MASINA, TIPRETETA,
    NRCI, DATACI,
    PRETACHIZ, VALACHIZ, NRNP, UTILAJ, INTERVENTIE &apos;||gUserFields||&apos; )
  WITH lg As (
    SELECT
      i.codies, i1.codies1, l.codlivr, l1.umsec, NVL(NVL(lv.gest, n.gest),0) gest, NVL(ns.codlocatie,0) codlocatie,
      (SELECT x.CodIoart1 FROM ioart1 x WHERE x.codioart = NVL(lv.codioart,ns.codioart) AND (i.an * 12 + i.luna) BETWEEN x.ALStart and x.ALStop) codioart1,
      ns.furn, ns.codgestprod gestfurn, sum(l1.cant) cant, sum(l1.cantum1) cantum1, sum(l1.cantum2) cantum2, ns.d1, ns.d2, ns.d3, ns.codnirstoc, nvl(l1.codnirser,0) codnirser,
      nvl(lv.pretachiz, nvl(ns.pret,0) - nvl(ns.adaos,0)) pretachiz, sum(l1.cant * nvl(lv.pretachiz, nvl(ns.pret,0) - nvl(ns.adaos,0))) valachiz, I1.CODCMDINT1 &apos;||
      sColSerii||&apos;
    FROM iesiri i
      INNER JOIN iesiri1  i1 ON i1.codies     = i.codies
      INNER JOIN livr     l  ON l.codies      = i.codies
      INNER JOIN livr1    l1 ON l1.codies1    = i1.codies1 AND l1.codlivr = l.codlivr
      INNER JOIN COMANDA1 C1 ON I1.CODCMDINT1 = C1.CODCOMANDA1
      INNER JOIN COMANDA  C  ON C1.CODCOMANDA = C.CODCOMANDA
      LEFT JOIN livrval   lv ON lv.codlivr1   = l1.codlivr1
      LEFT JOIN nirstoc   ns ON ns.codnirstoc = l1.codnirstoc
      LEFT JOIN nir       n  ON n.codnir      = ns.codnir&apos;||sJoinSerii||&apos;
    WHERE i.tipdoc = 24 AND (l.operat = 1) AND (l.anulat = 0) AND C.TIPTRANZACTIE = 1 AND C.OPERAT = 1 AND C.ANULAT = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos;
      AND l.datalivr BETWEEN TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataIni||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||PKG_LIST_SELECTPER.DataFin||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)&apos;||
      sFiltru||&apos;
    GROUP BY
      i.codies, i.an, i.luna, i1.codies1, l.codlivr, l1.umsec, SIGN(l1.cant), ns.codnirstoc,l1.codnirser, ns.pret, ns.adaos, lv.pretachiz,
      lv.codioart, lv.gest, n.gest, ns.codlocatie, ns.codioart, ns.furn, ns.codgestprod, ns.tipserie, ns.d1, ns.d2, ns.d3, i1.codcmdint1)
  SELECT
    i.codies, i.tipdoc, i.prefixdoc, i.nrdoc, i.datadoc, i.prefixdoc||&apos;&apos;/&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||i.datadoc dociesire,
    gp.den_gest, gs.den_gest, o.denumire, oc.denumire, c.simbol,cch.simbol,
    i1.pu*u.paritate, lg.cant/u.paritate, u.den_um1, i1.pu*lg.cant, lg.cantum1, lg.cantum2, u1.den_um, u2.den_um,
    pers.nume||&apos;&apos; &apos;&apos;||pers.prenume, auto.nrinreg, DECODE(pc.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,2,&apos;&apos;Dezagregare&apos;&apos;),
    ci.nrdoc, ci.datadoc,
    lg.PretAchiz, lg.ValAchiz, nr_np.nrdocs, utilajobj.denumire, intervserv.denumire &apos;||gUserAlias||&apos;
  FROM lg
    LEFT JOIN iesiri i ON i.codies = lg.codies
    LEFT JOIN livr l ON l.codlivr = lg.codlivr
    LEFT JOIN iesiri1 i1 ON i1.codies1 = lg.codies1
    LEFT JOIN ioart1 io1 ON io1.codioart1 = lg.codioart1
    LEFT JOIN ioart io ON io1.codioart = io.codioart
    LEFT JOIN ncont c ON c.codcont = io1.cont
    LEFT JOIN ncont cch ON cch.codcont = io1.cheltuieli
    LEFT JOIN ngest gp ON gp.codgest = i.codgestprod
    LEFT JOIN ngest gs ON gs.codgest = lg.gest
    LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN num1 u ON u.codum1 = lg.umsec
    LEFT JOIN num u1 ON u1.codum = a.um1
    LEFT JOIN num u2 ON u2.codum = a.um2
    LEFT JOIN npers pers ON pers.codpers = i.codpers
    LEFT JOIN nparcaut auto ON auto.codnparcaut = i.codauto
    LEFT JOIN nartamb aa ON aa.codobiect = i1.codobiect AND aa.umsec = i1.umsec
    LEFT JOIN iesprodlink ipl ON ipl.codies1 = lg.codies1
    LEFT JOIN cmdprodmat cp ON cp.codcmdprodmat = ipl.codcmdprodmat
    LEFT JOIN cmdprodmat cp2 ON cp2.codcomanda1 = cp.codcomanda1 AND cp2.tip = 0
    LEFT JOIN comanda1 c1 ON c1.codcomanda1 = cp.codcomanda1
    LEFT JOIN prodcomp pc ON pc.codprodcomp = c1.codreteta
    LEFT JOIN nartobj oc ON oc.codobiect = cp2.codobiect
    LEFT JOIN (select
                 vc2_nt_to_string(CAST(collect(to_char(i.nrdoc) order by i.nrdoc) AS vc2_nt)) nrdocs,
                 i1.codcmdint1,
                 i1.codobiect
               from intrari1 i1
                    inner join intrari i on i1.codintr = i.codintr
               where nvl(i.anulat,0) = 0 and i.operat = 1 and i.tipdoc = 7
               group by i1.codcmdint1, i1.codobiect
              ) NR_NP on nr_np.codcmdint1 = lg.codcmdint1 and nr_np.codobiect = oc.codobiect
    LEFT JOIN comanda1 ci1 ON ci1.codcomanda1 = i1.codcmdint1
    LEFT JOIN comanda ci ON ci.codcomanda = ci1.codcomanda
    left join utilaje2c ut2c on ut2c.codcomanda1 = ci1.codcomanda1
    left join utilaje ut on ut2c.codutilaj = ut.codutilaj
    left join utilaje2 ut2 on ut2.codutilaj2 = ut2c.codutilaj2
    left join ninterventiiauto interv on interv.CODINTERVENTIIAUTO = ut2.interventie
    left join nartobj intervserv on intervserv.codobiect = interv.serviciu
    left join nartobj utilajobj on utilajobj.codobiect = ut.codobiect
    LEFT JOIN nirstoc ON lg.codnirstoc = nirstoc.codnirstoc
    LEFT JOIN nclasea ca ON ca.codclasea = a.clasa
    LEFT JOIN NCLASEINT CLSINT ON INTERV.CLASA = CLSINT.CODCLASEINT
    LEFT JOIN centrecost cc on i1.codcentru = cc.codcentru&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITCONSUM_M;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITDATORII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5A7B559748B7C81C65ACE21E0780A95D4428308</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITDATORII IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vCodPart    NUMBER(20);
  vCodAgenda  NUMBER(20);
  vCodMoneda  NUMBER(20);

PROCEDURE setParams (pCodPart IN NUMBER, pCodAgenda IN NUMBER, pCodMoneda IN NUMBER) IS
BEGIN
  vCodPart   := pCodPart;
  vCodAgenda := pCodAgenda;
  vCodMoneda := pCodMoneda;
END;

PROCEDURE ProcessParams IS
BEGIN
  FOR v_rec IN (
    SELECT Den_part
    FROM NPART
    WHERE CodPart = vCodPart
    ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,       v_rec.Den_part);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT SIMBOL
    FROM NMONEDE
    WHERE CodMOneda = vCodMoneda
    ) loop
    pkg_list_Struct.ADAUGA_PARAM(&apos;Moneda&apos;,       v_rec.SIMBOL);
    EXIT;
  END LOOP;

END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
BEGIN
  gSuplCols := &apos;PKG_LIST_BASE_SITDATORII TMP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Tab, 
    Doc, NrDoc, DataDoc, Valoare, Rest, Termen, ZileScadente, SimbolCont, Den_Subunit, Sediu, 
    CecNeincasat, 
    Obs, Agent&apos;||gUserFields||&apos;)
  SELECT 
    CASE TMP.Tab WHEN 1 THEN &apos;&apos;Documente&apos;&apos; WHEN 2 THEN &apos;&apos;Cecuri&apos;&apos; WHEN 3 THEN &apos;&apos;Comenzi&apos;&apos; END Tab, 
    TMP.Doc, TMP.NrDoc, TMP.DataDoc, TMP.Valoare, TMP.Rest, TMP.Termen, TMP.ZileScadente, TMP.SimbolCont, TMP.Den_Subunit, TMP.Sediu, 
    CASE TMP.CecNeincasat WHEN 1 THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END CecNeincasat, 
    TMP.Obs, TMP.Agent&apos;||gUserAlias||&apos;
  FROM TMP_LST_SITDATORII TMP&apos;||
  gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  ProcessParams;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SITDATORII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97DC7006904C92A1A54CB3053E8BE9C6E9DA9314</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITFIN IS

p_Tabla    VARCHAR2(250);
p_CodSitFin NUMBER(20) default 0;
  
  vDataS       DATE;
  vDataF       DATE;
 
procedure SetAllSubunit is
begin
  insert into tmp_manevra (codunic)
  select codsubunit
  from nsubunit
  where codsubunit &gt; 1;
  commit;
end;  

function INCHID711CU121 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;711&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0) - nvl(credit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;  

function INCHID712CU121 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;712&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0) - nvl(credit,0)) from 
    (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;)
   )&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;  

function INCHID722CU121 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;722&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0) - nvl(credit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;121%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;  

function INCHID765CU473 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;765&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(credit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;473.02%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;473.02%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;

function INCHID665CU473 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;665&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where simbol like &apos;&apos;473.02%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where simbol like &apos;&apos;473.02%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;

function INCHID665FARA473 return number is
sSelect varchar2(10000);
vRez number(20,7);  
begin
  vRez := 0; 
  sSelect := &apos;
  WITH
    r as (
      SELECT
        r.codcont, rs.rulajpd, rs.rulajpc, rs.rulajcd, rs.rulajcc, rs.rulajvpd, rs.rulajvpc, rs.rulajvcd, rs.rulajvcc,
        rs.rulajp_ifrs, rs.rulajc_ifrs, rs.rulajvp_ifrs, rs.rulajvc_ifrs, rs.rulajp_grup, rs.rulajc_grup, rs.rulajvp_grup, rs.rulajvc_grup, rs.subunitatea, r.an, r.luna
      FROM ncontrul r
        INNER JOIN ncontrulsub rs ON rs.codcontrul = r.codcontrul
      WHERE r.an*12+r.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND r.luna &gt; 1),
    n AS (
      SELECT c.codcont
      FROM ncont c
      WHERE EXISTS (SELECT 1 FROM ncont1 c1 WHERE c1.codcont = c.codcont AND c1.anstart*12+c1.lunastart &lt;= &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetLUNALUCRU||&apos;)
      START WITH c.codcont IN (SELECT codcont from ncont where simbol = &apos;&apos;665&apos;&apos;)
      CONNECT BY PRIOR c.codcont = c.codparinte)
    select sum(nvl(debit,0)) from (
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, sc.codcont, 0 codcoresp,
      0 debit, 0 credit, 0 debitv, 0 creditv, 0 valoare, 0 valoarev,
      nvl(s.soldid,0) - nvl(s.soldic,0) sold, nvl(s.soldvid,0) - nvl(s.soldvic,0) soldv,
      nvl(s.soldi_ifrs,0) ifrs,  nvl(s.soldvi_ifrs,0) ifrsv, nvl(s.soldi_ifrs,0) sold_ifrs, nvl(s.soldvi_ifrs,0) sold_ifrsv,
      nvl(s.soldi_grup,0) grup,  nvl(s.soldvi_grup,0) grupv, nvl(s.soldi_grup,0) sold_grup, nvl(s.soldvi_grup,0) sold_grupv,
      &apos;&apos;Sold initial&apos;&apos; obs, null document, to_date(&apos;&apos;01.&apos;&apos;||sc.luna||&apos;&apos;.&apos;&apos;||sc.an,&apos;&apos;dd.mm.yyyy&apos;&apos;)  datadoc, s.subunitatea, 0 gest, sc.an, sc.luna,
      -1 ordine,
      0 codcentru, 0 indexlocal
    FROM ncontsold sc
      INNER JOIN ncontsoldsub s ON s.codcontsold = sc.codcontsold
      INNER JOIN n ON n.codcont = sc.codcont
    WHERE sc.an * 12 + sc.luna = &apos;||pkg_globals.GetANLUCRU||&apos;*12+1
    UNION ALL
    SELECT
      0 nav_coddoc, 0 nav_tipdoc, r.codcont, 0 codcoresp,
      nvl(r.rulajpd,0) debit, nvl(r.rulajpc,0) credit, nvl(r.rulajvpd,0) debitv, nvl(r.rulajvpc,0) creditv, 0 valoare, 0 valoarev,
      nvl(r.rulajpd,0) - nvl(r.rulajpc,0) sold, nvl(r.rulajvpd,0) - nvl(r.rulajvpc,0) soldv,
      nvl(r.rulajp_ifrs,0) ifrs, nvl(r.rulajvp_ifrs,0) ifrsv, nvl(r.rulajp_ifrs,0) sold_ifrs, nvl(r.rulajvp_ifrs,0) sold_ifrsv,
      nvl(r.rulajp_grup,0) grup, nvl(r.rulajvp_grup,0) grupv, nvl(r.rulajp_grup,0) sold_grup, nvl(r.rulajvp_grup,0) sold_grupv,
      &apos;&apos;Rulaj precedent&apos;&apos; obs, null document, to_date(r.an||&apos;&apos;.&apos;&apos;||r.luna,&apos;&apos;yyyy.mm&apos;&apos;)-1 datadoc, r.subunitatea, 0 gest, r.an, r.luna - 1 luna,
      0 ordine,
      0 codcentru, 0 indexlocal
    FROM r
      INNER JOIN n ON n.codcont = r.codcont
    UNION ALL
    SELECT  -- tipinreg 1 debit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contd codcont,j.contc codcoresp,
      j.valoare debit, 0 credit, j.valoarev debitv, 0 creditv, j.valoare, j.valoarev,
      Nvl(j.valoare,0) sold, Nvl(j.valoarev,0) soldv,
      Nvl(j.valoare_ifrs,0) ifrs, Nvl(j.valoarev_ifrs,0) ifrsv, Nvl(j.valoare_ifrs,0) sold_ifrs, Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      Nvl(j.valoaregrup,0) grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, Nvl(j.valoaregrup,0) sold_grup, Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contd
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contc in (select codcont from ncont where not simbol like &apos;&apos;473.02%&apos;&apos;)
    UNION ALL
    SELECT  -- tipinreg 1 credit
      j.coddoc nav_coddoc, j.tipdoc nav_coddoc, j.contc codcont,j.contd codcoresp,
      0 debit, j.valoare credit, 0 debitv, j.valoarev creditv, j.valoare, j.valoarev,
      Nvl(-j.valoare,0) sold, Nvl(-j.valoarev,0) soldv,
      -Nvl(j.valoare_ifrs,0) ifrs, -Nvl(j.valoarev_ifrs,0) ifrsv, -Nvl(j.valoare_ifrs,0) sold_ifrs, -Nvl(j.valoarev_ifrs,0) sold_ifrsv,
      -Nvl(j.valoaregrup,0) grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) grupv, -Nvl(j.valoaregrup,0) sold_grup, -Nvl(j.valoaregrup/decode(j.valoarev, 0, 1, j.valoare/j.valoarev),0) sold_grupv,
      j.obs, j.document, j.datadoc, j.subunitatea, j.gest, j.an, j.luna,
      CASE
        WHEN j.tipdoc = 81                                       THEN 10000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;SINCRONIZARE%&apos;&apos;) THEN 20000000000000000000
        WHEN TIPDOC = 32 AND UPPER(OBS) LIKE (&apos;&apos;INCHIDERE%&apos;&apos;)    THEN 30000000000000000000
        ELSE 0
      END + j.codjurnal ordine,
      j.codcentru, j.indexlocal
    FROM jurnal j
      INNER JOIN n ON n.codcont = j.contc
    WHERE j.an *12 + j.luna BETWEEN &apos;||pkg_globals.GetANLUCRU||&apos;*12+1 AND &apos;||pkg_globals.GetANLUCRU||&apos;*12+&apos;||pkg_globals.GetlunaLUCRU||&apos;  and j.contd in (select codcont from ncont where not simbol like &apos;&apos;473.02%&apos;&apos;))&apos;;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  begin  
    execute immediate sSelect into vRez;
  exception when others then 
    vRez := 0;
  end;
    
  return vRez;  
end;

PROCEDURE setParams (v_Tabla IN VARCHAR2,
                       V_CODJOB1 IN NUMBER  DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2
                      ) IS
                      
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  p_Tabla := upper(v_Tabla);
END;

procedure SetCod(v_CodSitFin IN NUMBER) is
begin
  p_CodSitFin := v_CodSitFin;
end;

function GetCod return number is
begin
  return p_CodSitFin;
end;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sString VARCHAR2(1000);
sCols VARCHAR2(1000);
BEGIN
  FOR V_REC IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = p_tabla /*AND COLUMN_NAME &lt;&gt; &apos;ROWHEIGHT&apos;*/) LOOP
    SCOLS := SCOLS ||V_REC.COLUMN_NAME||&apos;,&apos;;
  END LOOP;
   SCOLS := SUBSTR(SCOLS,1,LENGTH(SCOLS)-1);
   
  
  sString := &apos;insert into &apos;||tmpName||&apos;(&apos;||scols||&apos;)  select &apos;||scols||&apos; from &apos;||p_Tabla;
 --  insert into x(sql) values (sstring); commit;
  Execute Immediate (sString);
 -- execute immediate &apos;create table ffff as select * from &apos;||tmpName;
  Commit;
END;  

end pkg_list_base_sitfin; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEA2186E346C4E4E7B1E25B556308BCC9672E07B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITIMOB IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  vLunaAnIni  NUMBER(20);
  vLunaAnFin  NUMBER(20);
  vOldMF      NUMBER(10);
  vAllGest    NUMBER(10);
  vAllIOArt   NUMBER(10);
  vAllMF      NUMBER(10);

function AnLunaIni return number is
begin
  return vLunaAnIni;
end;  

function AnLunaFin return number is
begin
  return vLunaAnFin;
end;  

PROCEDURE SETPARAMS (
  pLunaAnIni   IN INTEGER DEFAULT 0,
  pLunaAnFin   IN INTEGER DEFAULT 0,
  pOldMF       IN INTEGER DEFAULT 0,
  pAllGest     IN INTEGER,
  pAllIOArt    IN INTEGER,
  pAllMF       IN INTEGER,
  pCodJob1     IN NUMBER
) IS
  vDataS DATE;
  vDataF DATE;
BEGIN
  vLunaAnIni  := Coalesce(pLunaAnIni,0);
  vLunaAnFin  := Coalesce(pLunaAnFin,0);
  vOldMF      := pOldMF;
  vAllGest    := pAllGest;
  vAllIOArt   := pAllIOArt;
  vAllMF      := pAllMF;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataS,vDataF,vLunaAnIni,vLunaAnFin);
  END IF;
END;

FUNCTION GetCodLivr1Vanz (pStare NUMBER, pCodnirstoc NUMBER, pAn NUMBER, pLuna NUMBER) RETURN NUMBER IS
  vResult NUMBER;
BEGIN
  IF pStare = 4 THEN
    SELECT Min(l1.codlivr1)
    INTO vResult
    FROM nirstoc ns
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN livr1 l1 ON l1.codnirstoc = ns.codnirstoc
      INNER JOIN livr l ON l.codlivr = l1.codlivr
      INNER JOIN IESIRI I ON i.codies = l.codies AND i.tipdoc = l.tiplivr
    WHERE ns.codnirstoc = pCodnirstoc
      AND i.an = pAn
      AND i.luna = pLuna
      AND l.codies &lt;&gt; Coalesce(n.codies, 0);
  END IF;
  RETURN vResult;
END;

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     clob;
  sUpdate1    clob;
  sUpdate2    clob;
  sDifReeval  VARCHAR2( 1000);
  sValRamasa  VARCHAR2( 1000);
  sColCurs    CLOB;
  BancaSitV   NUMBER(20) := 0;
  MonedaSitV  NUMBER(20) := 0;
BEGIN
  gSuplCols := &apos;MIFIX1 MIFIX1, MIFIX MIFIX, NIRSTOC NS, NARTOBJ OBJ, NUM1 NUM1, IOART IO,NCONT N, MFCLASIF CLASA, NIR NIR, NGEST NG, NSUBUNIT SUB, TRANSF TRANSF, JURNAL1 J1, &apos;||
               &apos;MIFIX1 AMO_INI, NCLASEG  NCLG, NPERS PERS, NART ART, NCLASEA NCLA, NCLASEAS NCLAS, NPART NP_CUST, NLOCATII LOC, NPART FURN, NARTAMB AA, CENTRECOST CC, NIRSTOC1 NS1, &apos;||
               &apos;NIRSTOC NSO, NIR NIRO, INTRARI INTRO, IESIRI IESO, NIRSER NSER, NSERII SER&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = OBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;LIVR1&apos;,      &apos;L1&apos;,   &apos;L1.CODLIVR1 = PKG_LIST_BASE_SITIMOB.GetCodLivr1Vanz(MIFIX1.STARE, MIFIX1.CODNIRSTOC, MIFIX1.ANSTART, MIFIX1.LUNASTART)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;LIVR&apos;,       &apos;L&apos;,    &apos;L.CODLIVR = L1.CODLIVR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;IES&apos;,  &apos;IES.CODIES = L.CODIES AND IES.TIPDOC = L.TIPLIVR&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);

  --CASE WHEN mifix1.stare in (2,3,4) THEN 0 ELSE pkg_inchideri.AMORTIZARELUNARA(mifix.codmifix,mifix1.anstart,mifix1.lunastart) END amo_curent, --&gt; j1.valoare
  IF pkg_categconst.GetValConstanta(&apos;UseRezervaReev&apos;,pkg_globals.anlucru,pkg_globals.lunalucru) = &apos;1&apos; THEN
    sDifReeval := &apos;,
    Round(
      CASE
        WHEN mifix1.DataReeval IS NULL THEN 0
        WHEN Coalesce(mifix1.TipReeval,0) = 0 THEN (mifix1.Pret - Coalesce(mifix1.amo,0)) - (mifix1.PretVechi - mifix1.AmoVechi)
        WHEN mifix1.IncludRata = 1 THEN mifix1.Pret - mifix1.PretVechi + Coalesce(mifix1.amo,0) + Coalesce(j1.valoare,0)
        ELSE mifix1.Pret - mifix1.PretVechi
      END,7) DifReeval&apos;;
    sValRamasa  := &apos;,
    Round(
      CASE
        WHEN mifix1.DataReeval IS NOT NULL AND mifix1.TipReeval = 1 AND mifix1.IncludRata = 1 THEN ns.pret * mifix1.cant
        ELSE ns.pret * mifix1.cant - Coalesce(mifix1.amo,0) - Coalesce(j1.valoare,0)
      END,7) val_ramas&apos;;
  ELSE
    sDifReeval  := &apos;,
    0 DifReeval&apos;;
    sValRamasa  := &apos;,
    Round((ns.pret * mifix1.cant) - Coalesce(mifix1.amo,0) - Coalesce(j1.valoare,0),7) val_ramas&apos;;
  END IF;

  -- stef - e un mod defectuos de apelare pe fiecare linie si nu vad logica sa caut valorile MonedaSitV, BancaSitV si lista are un randament foarte prost pentru multe date
--    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
--      pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,Coalesce(ieso.an,intro.an),Coalesce(ieso.luna,intro.luna)),
--      pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos; ,Coalesce(ieso.an,intro.an),Coalesce(ieso.luna,intro.luna)),
--      ns.dataachiz
--    ) CursAchiz,
--    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
--      pkg_categconst.GetValConstanta(&apos;&apos;MonedaSitV&apos;&apos;,transf.an,transf.luna),
--      pkg_categconst.GetValConstanta(&apos;&apos;BancaSitV&apos;&apos; ,transf.an,transf.luna),
--      nir.datanir
--    ) CursModifPret,

  -- am doua solutii (in princpiu merg pe primul caz pana plange cineva)
  -- 1 folosesc Valorile constantelor din luna din care se apeleaza programul
  -- 2 creez un temp cu valorile acestor constante pe toate lunile din firma

  IF Coalesce(PKG_GLOBALS.ANLUCRU,0) &gt; 0 AND Coalesce(PKG_GLOBALS.LUNALUCRU,0) &gt; 0 THEN
    BEGIN
      SELECT pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO BANCASITV  FROM DUAL;
    EXCEPTION
      WHEN OTHERS THEN BANCASITV := 0;
    END;

    BEGIN
      SELECT pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO MONEDASITV FROM DUAL;
    EXCEPTION
      WHEN OTHERS THEN MONEDASITV := 0;
    END;
  END IF;

  IF Coalesce(MonedaSitV, 0) &lt;&gt; 0 AND Coalesce(BancaSitV,0) &lt;&gt; 0 THEN
    sColCurs := &apos;
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||MonedaSitV||&apos;,&apos;||BancaSitV||&apos;,ns.dataachiz) CursAchiz,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||MonedaSitV||&apos;,&apos;||BancaSitV||&apos;,nir.datanir)  CursModifPret,&apos;;
  ELSE
    sColCurs := &apos;
    1 CursAchiz,
    1 CursModifPret,&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos;(
    CODMIFIX,TIMP_RAMAS,
    AMO_CURENT,
    AMO_PREC,AMO_TOTAL,GRADU,PRET_AMO,
    VAL_RAMAS,
    CODNIRSTOC,DENMIFIX,CANT,NRINVENTAR,DEN_UM1,DEN_IOART,CONT,
    DENCLASA,SIMBOLCLASA,DURATAN,
    TIPAMO,
    DEN_GEST,DATAACHIZ,DEN_SUBUNIT,ANLUNAINTR,
    DEN_CLASEG,RESPONSABIL, DEN_CLASEA, CODINTERN, CODEXTERN,
    NEUTILPREC, STARE,
    SERIE,LOCATIE,PART_CUSTODIE,
    FURNIZOR,OBSMIFIX,AMOINCEPUT,
    AMOCUMUL,
    AMO_CURENTF,
    AMOF, TIMP_RAMASF,
    AMOFCUMUL,
    AMO_CURENTG,
    AMOG, TIMP_RAMASG,
    AMOGCUMUL,
    CentruCost, PretInc,
    RezNoua, SoldRez, CReeval, VReeval, Val105,
    Reeval, TipReeval, InclRata,
    Rezerva,
    DifReeval,
    PretInitial,
    LUNA, AN,
    INFOMFIMB,
    CursAchiz,
    CursModifPret,
    DataModifPret,
    NrOrd,
    NrMax&apos;||gUserFields||&apos;)
  SELECT
    mifix1.codmifix, mifix1.durataf AS timp_ramas,
    CASE when mifix1.datareeval is not null and mifix1.Includrata = 1 then 0 else Coalesce(j1.valoare,0) END amo_curent,
    CASE WHEN mifix1.TipReeval = 1 THEN 0 ELSE PKG_INCHIDERI.GET_AMO_MIFIX(mifix1.codmifix, mifix1.anstart, mifix1.lunastart) END amo_prec,
    0 amo_total, mifix1.gradu, ns.pret&apos;||
    sValRamasa||&apos;,
    mifix1.codnirstoc, obj.denumire DENMIFIX, mifix1.cant, mifix.nrinventar, num1.den_um1, io.den_ioart, n.simbol CONT,
    clasa.denumire DENCLASA, clasa.simbol SIMBOLCLASA ,mifix1.duratan,
    CASE
      WHEN mifix1.tipamo = 1                        THEN &apos;&apos;Liniara&apos;&apos;
      WHEN mifix1.tipamo = 2 AND mifix.tip = &apos;&apos;MF&apos;&apos; THEN &apos;&apos;Accelerata&apos;&apos;
      WHEN mifix1.tipamo = 2                        THEN &apos;&apos;100% la punerea in functiune&apos;&apos;
      WHEN mifix1.tipamo = 3 AND mifix.tip = &apos;&apos;MF&apos;&apos; THEN &apos;&apos;Degresiva 1&apos;&apos;
      WHEN mifix1.tipamo = 3                        THEN &apos;&apos;50% la punerea in functiune&apos;&apos;
      WHEN mifix1.tipamo = 4 AND mifix.tip = &apos;&apos;MF&apos;&apos; THEN &apos;&apos;Degresiva 2&apos;&apos;
    END TipAmo,
    ng.den_gest, ns.dataachiz, SUB.DEN_SUBUNIT, MIFIX.LUNAINTRARE||&apos;&apos;/&apos;&apos;||MIFIX.ANINTRARE ANLUNAINTR,
    NCLG.DEN_CLASEG, PERS.NUME||&apos;&apos; &apos;&apos;||PERS.PRENUME RESPONSABIL, NCLA.DEN_CLASEA, OBJ.CODINTERN, OBJ.CODEXTERN,
    mifix1.NEUTIL NEUTILPREC,
    CASE mifix1.stare
      WHEN 1 THEN &apos;&apos;In curs de amortizare&apos;&apos;
      WHEN 2 THEN &apos;&apos;Trecut in conservare&apos;&apos;
      WHEN 3 THEN &apos;&apos;Casat in luna curenta&apos;&apos;
      WHEN 4 THEN &apos;&apos;Vandut in luna curenta&apos;&apos;
      WHEN 5 THEN &apos;&apos;Investitie in curs&apos;&apos;
      WHEN 6 THEN &apos;&apos;Cedat ca aport la capital&apos;&apos;
      WHEN 7 THEN &apos;&apos;Transferat ca marfa&apos;&apos;
    END STARE,
    SER.SERIE,LOC.DENUMIRE LOCATIE, NP_CUST.DEN_PART PART_CUSTODIE, FURN.DEN_PART FURNIZOR, mifix.obs obsmifix, Coalesce(AMO_INI.AMO,0) AMOINCEPUT,
    Round(Coalesce(MIFIX1.AMO,0) - Coalesce(AMO_INI.AMO,0) + Coalesce(j1.valoare,0),7) amocumul,
    Round(CASE when mifix1.stare IN (2,3,4) THEN 0 ELSE pkg_inchideri.AMORTIZARELUNARA_F(mifix.codmifix,mifix1.anstart,mifix1.lunastart) END,7) AS amo_curentf,
    mifix1.amof, mifix1.durataff TIMP_RAMASF,
    Round(Coalesce(MIFIX1.AMOF,0) - Coalesce(AMO_INI.AMOF,0) + CASE WHEN mifix1.stare IN (2,3,4) THEN 0 ELSE pkg_inchideri.AMORTIZARELUNARA_F(mifix.codmifix,mifix1.anstart,mifix1.lunastart) END,7) AS amofcumul,
    Round(CASE WHEN mifix1.stare IN (2,3,4) THEN 0 ELSE pkg_inchideri.AMORTIZARELUNARA_G(mifix.codmifix,mifix1.anstart,mifix1.lunastart) END,7) AS amo_curentg,
    mifix1.amog, mifix1.duratafg TIMP_RAMASG,
    Round(Coalesce(MIFIX1.AMOG,0) - Coalesce(AMO_INI.AMOG,0) + CASE WHEN mifix1.stare IN (2,3,4) THEN 0 ELSE pkg_inchideri.AMORTIZARELUNARA_G(mifix.codmifix,mifix1.anstart,mifix1.lunastart) END,7) AS amogcumul,
    cc.denumire CentruCost, CASE WHEN Coalesce(mifix1.PretVechi,0) &lt;&gt; 0 THEN mifix1.PretVechi WHEN Coalesce(nso.Pret,0) = 0 THEN ns.Pret - Coalesce(ns.Adaos,0) ELSE nso.Pret - Coalesce(nso.Adaos,0) END AS PretInc,
    0 RezNoua, 0 SoldRez, 0 CReeval, 0 VReeval, 0 Val105,
    CASE WHEN mifix1.DataReeval IS NULL THEN &apos;&apos;NU&apos;&apos; ELSE &apos;&apos;DA&apos;&apos; END Reeval,
    CASE WHEN mifix1.DataReeval IS NULL THEN NULL WHEN mifix1.TipReeval = 1 THEN &apos;&apos;pe valori nete&apos;&apos; ELSE &apos;&apos;pe valori brute&apos;&apos; END TipReeval,
    CASE WHEN mifix1.DataReeval IS NULL THEN NULL WHEN mifix1.IncludRata = 1 THEN &apos;&apos;dupa amortizarea curenta&apos;&apos; ELSE &apos;&apos;inainte de amortizarea curenta&apos;&apos; END InclRata,
    coalesce(mifix1.Rezerva,0)&apos;||
    sDifReeval||&apos;,
    CASE WHEN Coalesce(nso.pret,0) = 0 THEN ns.pret ELSE nso.pret END PretInitial,
    mifix1.lunastart, mifix1.anstart,
    Coalesce(PKG_MIFIX.GetINFOMFIMB(mifix.codmifiximb), mifix.nrinventar || &apos;&apos; &apos;&apos; || obj.denumire) INFOMFIMB,&apos;||
    sColCurs||&apos;
    nir.datanir DataModifPret,
    Row_Number() OVER (PARTITION BY mifix.codmifix ORDER BY mifix1.anstart*12+mifix1.lunastart, mifix1.codmifix1) NrOrd,
    Count(1) OVER (PARTITION BY mifix.codmifix) NrMax&apos;||gUserAlias||&apos;
  FROM mifix1
    INNER JOIN mifix              ON mifix1.codmifix   = mifix.codmifix
    INNER JOIN nirstoc    ns      ON mifix1.codnirstoc = ns.codnirstoc
    INNER JOIN nartobj    obj     ON obj.codobiect     = ns.codobiect
    INNER JOIN num1               ON num1.codum1       = ns.umsec
    INNER JOIN ioart      io      ON ns.codioart       = io.codioart
    INNER JOIN ioart1     io1     ON io.codioart       = io1.codioart    AND (mifix1.anstart * 12 + mifix1.lunastart) BETWEEN io1.ALStart and io1.ALStop
    INNER JOIN ncont      n       ON n.codcont         = io1.cont
    INNER JOIN mfclasif   clasa   ON clasa.codclasif   = mifix1.codclasif
    INNER JOIN nir                ON nir.codnir        = ns.codnir
    INNER JOIN ngest      ng      ON ng.codgest        = nir.gest
    INNER JOIN nsubunit   sub     ON sub.codsubunit    = ng.codsubunit
    LEFT  JOIN transf             ON transf.codtransf  = nir.codtransf
    LEFT  JOIN jurnal1    j1      ON j1.indexlocal     = mifix1.codmifix AND j1.tipdoc = 36 AND j1.icontd = 4 AND j1.icontc = 10 AND j1.an*12+j1.luna = mifix1.anstart*12+mifix1.lunastart
    LEFT  JOIN mifix1     amo_ini ON amo_ini.codmifix  = mifix1.codmifix AND amo_ini.anstart = mifix1.anstart AND amo_ini.lunastart = 1
    LEFT  JOIN nclaseg    nclg    ON nclg.codclaseg    = ng.codclasa
    LEFT  JOIN npers      pers    ON pers.codpers      = mifix1.codpers
    LEFT  JOIN nart       art     ON art.codarticol    = obj.codarticol
    LEFT  JOIN nclasea    ncla    ON ncla.codclasea    = art.clasa
    LEFT  JOIN nclaseas   nclas   ON nclas.codclaseas  = art.clasastatist
    LEFT  JOIN npart      np_cust ON np_cust.codpart   = mifix1.codpart
    LEFT  JOIN nlocatii   loc     ON loc.codlocatie    = Coalesce(ns.codlocatie,0)
    LEFT  JOIN npart      furn    ON furn.codpart      = ns.furn
    LEFT  JOIN nartamb    aa      ON aa.codobiect      = ns.codobiect    AND aa.umsec = ns.umsec
    LEFT  JOIN centrecost cc      ON cc.codcentru      = Coalesce(mifix1.codcentru,0)
    LEFT  JOIN nirstoc1   ns1     on ns1.codnirstoc    = ns.codnirstoc
    LEFT  JOIN nirstoc    nso     on nso.codnirstoc    = ns1.codnirstocorig
    LEFT  JOIN nir        niro    on nso.codnir        = niro.codnir
    LEFT  JOIN intrari    intro   on intro.codintr     = niro.codintr
    LEFT  JOIN iesiri     ieso    on ieso.codies       = niro.codies
    LEFT  JOIN nirser     nser    ON nser.codnirser    = mifix1.codnirser
    LEFT  JOIN nserii     ser     ON ser.codserie      = nser.codserie &apos;||
    gSuplJoins||&apos;
  WHERE mifix1.anstart * 12 + mifix1.lunastart &lt;= &apos;||vLunaAnFin||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos; &apos;||
  CASE
    WHEN vOldMF = 1 THEN &apos;
    AND (mifix1.stare IN (3,4) OR mifix1.anstart * 12 + mifix1.lunastart &gt;= &apos;||vLunaAnIni||&apos;)&apos;
    ELSE &apos;
    AND mifix1.anstart * 12 + mifix1.lunastart &gt;= &apos;||vLunaAnIni
  END||
  CASE
    WHEN vAllGest = 0 THEN &apos;
    and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;&apos;CODGEST&apos;&apos; and tmp.valoare = nir.gest)&apos;
  END||
  CASE
    WHEN vAllIOArt = 0 THEN &apos;
    and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;&apos;CODIOART&apos;&apos; and tmp.valoare = ns.codioart)&apos;
  END||
  CASE
    WHEN vAllMF = 0 THEN &apos;
    and exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;&apos;CODMIFIX&apos;&apos; and tmp.valoare = mifix.codmifix)&apos;
  END;

  sUpdate1 :=
  &apos;UPDATE &apos;|| TMPNAME ||&apos;
  SET SoldIni   = CASE WHEN NrOrd = 1     THEN AMO_PREC   END,
      SoldFin   = CASE WHEN NrOrd = NrMax THEN VAL_RAMAS  END,
      AMO_TOTAL = Round(AMO_CURENT + AMO_PREC,7)&apos;;

  sUpdate2 :=
  &apos;UPDATE &apos;|| TMPNAME ||&apos;
  SET RezNoua  = Rezerva + coalesce(DifReeval,0),
      SoldRez  = CASE WHEN Rezerva + DifReeval &lt; 0 THEN 0 ELSE Rezerva + DifReeval END,
      VReeval  = CASE
                    WHEN Rezerva + DifReeval &gt; 0 AND Rezerva &lt; 0 THEN - Rezerva
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva &lt; 0 AND DifReeval &gt; 0 THEN DifReeval
                    ELSE 0
                  END,
      CReeval  = CASE
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva &gt;= 0 THEN - (Rezerva + DifReeval)
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva  &lt; 0 AND DifReeval &lt; 0 THEN - DifReeval
                    ELSE 0
                  END,
      Val105   = DifReeval -
                  CASE --VReeval
                    WHEN Rezerva + DifReeval &gt; 0 AND Rezerva &lt; 0 THEN - Rezerva
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva &lt; 0 AND DifReeval &gt; 0 THEN DifReeval
                    ELSE 0
                  END +
                  CASE --CReeval
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva &gt;= 0 THEN - (Rezerva + DifReeval)
                    WHEN Rezerva + DifReeval &lt; 0 AND Rezerva  &lt; 0 AND DifReeval &lt; 0 THEN - DifReeval
                    ELSE 0
                  END
  WHERE Reeval IS NOT NULL&apos;;

--pkg_globals.setdebugmode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate2, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_SITIMOB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITINIESLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB277F59D19FDFFDA5A22F1EF7BE012B9E219DB8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITINIESLUNA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(30000);
  sJoinCLS   VARCHAR2(1000);
  sTipDocIes VARCHAR2(50);
  sCondGest  VARCHAR2(1000);
  sCondGest1  VARCHAR2(1000);
  sCondGest2  VARCHAR2(1000);
  sCondGestN  VARCHAR2(1000);
  sCondAL    VARCHAR2(500);
  sFiltruClasa VARCHAR2(500);
  sFiltruGest  VARCHAR2(500);
  sFiltru      VARCHAR2(500) := &apos; WHERE 1 = 1 &apos;;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=
    &apos;NARTOBJ O, NART A, NCLASEA CA, NCLASEAS CAS, INTRARI INTR, IESIRI IES, NPART FURN, NPART CLI, NPART PROD, NTVA NTVA, NTVA1 NTVA1, &apos;||
    &apos;NAGENDA SLIVR, NLOCALIT LOClivr, NJUDET JUDlivr, NCLASEP CF, NCLASEP CC, NCLASEP CP,IESIRI1 IES1,INTRARI1 II1,DVI1 DVI1,TRANSF1 TT1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TMP_MEDEX1_LST&apos;, &apos;MED1&apos;, &apos;MED1.CODCIM = O.CODCNAS&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF InStr(gSuplJoins, &apos;TMP_MEDEX1_LST&apos;) &gt; 0 THEN
    pkg_list_base_utils.UMPLE_TMP_MEDEX1_LST;
  END IF;

  IF NOT PKG_LIST_SELECTLUNAAN.AllX THEN
    sJoinCLS := &apos;
    INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOl = O.CODARTICOL AND A.CLASA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;)&apos;;
    sFiltruClasa := &apos;A.CLASA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;)&apos;;
  END IF;

  sCondGest := &apos;&apos;;
  sCondGestN := &apos;&apos;;
  sCondGest1 := &apos;&apos;;
  sCondGest2 := &apos;&apos;;
  sFiltruGest := &apos;&apos;;
  IF PKG_LIST_SELECTLUNAAN.AllY THEN
    sCondGest := sCondGest||&apos; AND NOT N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    sCondGestN := sCondGestN||&apos; AND NOT NN.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    sCondGest1 := sCondGest1||&apos; AND NOT NL.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    sCondGest2 := sCondGest2||&apos; AND NOT LV.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    sFiltruGest := sFiltruGest||&apos; NOT J.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;)&apos;;
  END IF;

  sTipDocIes := &apos;16, 19, 20, 21, 24&apos;;
  if PKG_LIST_SELECTLUNAAN.optiunea1 then
    sTipDocIes := sTipDocIes||&apos;, 14, 15&apos;;
  end if;

  IF PKG_LIST_SELECTLUNAAN.LunaStart = PKG_LIST_SELECTLUNAAN.LunaStop
  THEN sCondAL := &apos; = &apos;||PKG_LIST_SELECTLUNAAN.LunaStart;
  ELSE sCondAL := &apos; BETWEEN &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||&apos; AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop;
  END IF;

  IF sFiltruClasa IS NOT NULL
  THEN IF sFiltruGest IS NOT NULL
       THEN sFiltru := &apos; AND &apos; || sFiltruClasa || &apos; AND &apos; || sFiltruGest;
       ELSE sFiltru := &apos; AND &apos; || sFiltruClasa;
       END IF;
  ELSE IF sFiltruGest IS NOT NULL
       THEN sFiltru := &apos; AND &apos; || sFiltruGest;
       END IF;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| TMPNAME ||&apos;(
    DENUMIRE, PRODUCATOR, SERIE,
    FURNIZOR, INTRPREFIX, INTRNRDOC, INTRDATADOC,
    STOCINIT,
    CANTINT,
    CLIENT, CANTIES, IESPREFIX, IESNRDOC, IESDATADOC,
    STOC, ORDINE &apos;||gUserFields||&apos;)
  WITH
  OINT AS (
    SELECT
      CODOBIECT, CODNIRSTOC, CODIES, CODINTR, DATA DATADOC, FURN, SERIE, GEST, TIPDOC, STOCINIT, CANTINT, 0 CANTIES, 0 ORD, CODINTR1, CODIES1, CODDVI1, CODTRANSF1
    FROM (
      SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, Last_Day(To_Date(NL.AN||&apos;&apos;.&apos;&apos;||NL.LUNA,&apos;&apos;yyyy.mm&apos;&apos;))+1 DATA, 0 CODINTR, 0 CODIES,
        SUM(CASE WHEN Coalesce(NE.CODNIRSER, 0) = 0 THEN NL.REST ELSE NE.REST END) STOCINIT, 0 CANTINT, N.GEST AS GEST, N.TIPNIR TIPDOC, II1.CODINTR1, 0 CODIES1,
        DVI1.CODDVI1, TT1.CODTRANSF1
      FROM NIRLUNA NL
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG&apos;||
        sJoinCLS||&apos;
        INNER JOIN NIR N ON N.CODNIR = NSO.CODNIR
        INNER JOIN NIR NN ON NN.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON NN.GEST = G.CODGEST
        LEFT JOIN INTRARI R ON R.CODINTR = N.CODINTR AND R.TIPDOC = N.TIPNIR
        LEFT JOIN NIRSERLUNA NE ON NL.CODNIRSTOC = NE.CODNIRSTOC AND NL.AN = NE.AN AND NL.LUNA = NE.LUNA
        LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = NE.CODNIRSER
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
        LEFT JOIN INTRARI1 II1 ON II1.CODINTR1 = NS.CODINTR1
        LEFT JOIN TRANSF1 TT1 ON NS.CODTRANSF1 = TT1.CODTRANSF1
        LEFT JOIN DVI1 DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
      WHERE NL.AN*12+NL.LUNA+1 = &apos;||PKG_LIST_SELECTLUNAAN.LunaStart||sCondGestN||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos; AND NL.REST &gt; 0
      GROUP BY NS.CODOBIECT, COALESCE(NSO.FURN,0), SER.SERIE, NL.AN, NL.LUNA, N.GEST, N.TIPNIR, NSO.CODNIRSTOC,
               II1.CODINTR1, DVI1.CODDVI1, TT1.CODTRANSF1
      UNION ALL
      SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, I.DATADOC DATA, I.CODINTR, 0 CODIES,
        0 STOCINIT, CASE WHEN Coalesce(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR ELSE NSE.CANTNIR END CANTINT, NN.GEST AS GEST, NN.TIPNIR TIPDOC, II1.CODINTR1, 0 CODIES1,
        DVI1.CODDVI1, TT1.CODTRANSF1
      FROM INTRARI I
        INNER JOIN NIR N ON N.CODINTR = I.CODINTR AND N.TIPNIR = I.TIPDOC
        INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
        INNER JOIN NIR NN ON NN.CODNIR = NSO.CODNIR
        INNER JOIN NGEST G ON N.GEST = G.CODGEST&apos;||
        sJoinCLS||&apos;
        LEFT JOIN DVI1 D1 ON D1.CODDVI1 = NS.CODDVI1
        LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = Coalesce(NS.CODINTR1,D1.CODINTR1,0) AND I1.CODINTR = I.CODINTR
        LEFT JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
        LEFT JOIN INTRARI1 II1 ON II1.CODINTR1 = NS.CODINTR1
        LEFT JOIN TRANSF1 TT1 ON NS.CODTRANSF1 = TT1.CODTRANSF1
        LEFT JOIN DVI1 DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I1.CODINTR1 IS NOT NULL
        AND I.AN*12+I.LUNA&apos;||sCondAL||sCondGest||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;&apos;;
  if PKG_LIST_SELECTLUNAAN.optiunea1 then
    sInsert := sInsert||&apos;
     UNION ALL
     SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, I.DATADOC DATA, I.CODINTR, IES.CODIES,
        0 STOCINIT, CASE WHEN Coalesce(NSE.CODNIRSER, 0) = 0 THEN IES1.CANT ELSE IES1.CANT END CANTINT, NN.GEST AS GEST, NN.TIPNIR TIPDOC, 0 CODINTR1, IES1.CODIES1,
        0 CODDVI1, 0 CODTRANSF1
      FROM INTRARI I
        INNER JOIN NIR N ON N.CODINTR = I.CODINTR AND N.TIPNIR = 15 AND N.CODIES &gt; 0
        INNER JOIN IESIRI IES ON N.CODIES = IES.CODIES
        INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
        INNER JOIN NIR NN ON NN.CODNIR = NSO.CODNIR
        INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1 AND I1.CODINTR = I.CODINTR
        INNER JOIN IESIRI1 IES1 ON IES1.CODIES = IES.CODIES AND IES1.CODIES1 = L1.CODIES1
        INNER JOIN NGEST G ON N.GEST = G.CODGEST&apos;||
        sJoinCLS||&apos;
        LEFT JOIN DVI1 D1 ON D1.CODDVI1 = NS.CODDVI1
        LEFT JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE N.TIPNIR = 15 AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I1.CODINTR1 IS NOT NULL
        AND IES.AN*12+IES.LUNA&apos;||sCondAL||sCondGest||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  end if;
  if PKG_LIST_SELECTLUNAAN.optiunea2 then
    sInsert := sInsert||&apos;
     UNION ALL
     SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, T.DATADOC DATA, 
        T.CODTRANSF CODINTR, 0 CODIES,
        0 STOCINIT, CASE WHEN Coalesce(NSE.CODNIRSER, 0) = 0 THEN T1.CANT ELSE NSE.CANTNIR END CANTINT, NO.GEST AS GEST, T.TIPDOC, 0 CODINTR1, 0 CODIES1,
        0 CODDVI1, T1.CODTRANSF1
      FROM TRANSF T
        INNER JOIN NIR N ON N.CODTRANSF = T.CODTRANSF
        INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF
        INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR AND NS.CODTRANSF1 = T1.CODTRANSF1
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
        INNER JOIN NIR NO ON NO.CODNIR = NSO.CODNIR 
        INNER JOIN NGEST    G   ON G.CODGEST = N.GEST
        LEFT  JOIN INTRARI  R   ON R.CODINTR = NO.CODINTR AND R.TIPDOC = NO.TIPNIR
        LEFT  JOIN TRANSF  RT   ON RT.CODTRANSF = NO.CODTRANSF AND RT.TIPDOC = NO.TIPNIR&apos;||
        sJoinCLS||&apos;
        LEFT JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE N.TIPNIR = 12 AND T.ANULAT = 0 AND T.OPERAT = 1
        AND T1.CODTRANSF1 IS NOT NULL
        AND T.AN*12+T.LUNA&apos;||sCondAL||sCondGest||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  end if;
  sInsert := sInsert||&apos;
      UNION ALL
      SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, I.DATADOC DATA, I.CODINTR, 0 CODIES,
        0 STOCINIT, -L1.CANT CANTINT, NO.GEST AS GEST, NO.TIPNIR TIPDOC, I1.CODINTR1, 0 CODIES1,
        0 CODDVI1, 0 CODTRANSF1
      FROM INTRARI I
        INNER JOIN LIVR L ON L.CODINTR = I.CODINTR AND L.TIPLIVR = I.TIPDOC
        INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
        INNER JOIN NIR NO ON NO.CODNIR = NSO.CODNIR
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON N.GEST = G.CODGEST&apos;||
        sJoinCLS||&apos;
        LEFT JOIN DVI1 D1 ON D1.CODDVI1 = L1.CODDVI1
        LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = Coalesce(D1.CODINTR1, L1.CODINTR1,0) AND I1.CODINTR = I.CODINTR
        LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = L1.CODNIRSER
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I1.CODINTR1 IS NOT NULL
        AND I.AN*12+I.LUNA&apos;||sCondAL||sCondGest||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
      UNION ALL
      SELECT
        NS.CODOBIECT, COALESCE(NSO.FURN,0) FURN, SER.SERIE, NSO.CODNIRSTOC, I.DATADOC DATA, I.CODINTR, 0 CODIES,
        0 STOCINIT, -L1.CANT CANTINT, NO.GEST AS GEST, NO.TIPNIR TIPDOC, I1.CODINTR1, 0 CODIES1,
        D1.CODDVI1, 0 CODTRANSF1
      FROM INTRARI I
        INNER JOIN LIVR L ON L.CODINTR = I.CODINTR AND L.TIPLIVR = I.TIPDOC
        INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
        INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
        INNER JOIN NIR NO ON NO.CODNIR = NSO.CODNIR
        INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST G ON N.GEST = G.CODGEST&apos;||
        sJoinCLS||&apos;
        LEFT JOIN DVI1 D1 ON D1.CODDVI1 = L1.CODDVI1
        LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = Coalesce(D1.CODINTR1, L1.CODINTR1,0) AND I1.CODINTR = I.CODINTR
        LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = L1.CODNIRSER
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE I.TIPDOC IN (1, 2, 3, 4, 5, 7) AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I1.CODINTR1 IS NOT NULL
        AND I.AN*12+I.LUNA&apos;||sCondAL||sCondGest||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;  
    )
    WHERE (STOCINIT &lt;&gt; 0 OR CANTINT &lt;&gt; 0)
  ),
  OIES AS (
    SELECT
      NSL.CODOBIECT, NS.CODNIRSTOC, I.CODIES, 0 CODINTR, I.DATADOC,
      COALESCE(NS.FURN,0) AS FURN, SER.SERIE, N.GEST, I.TIPDOC, 0 STOCINIT, 0 CANTINT, CASE WHEN I.TIPDOC = 15 THEN -1 ELSE 1 END * L1.CANT AS CANTIES, 1 ORD,
      L1.CODINTR1, L1.CODIES1, L1.CODDVI1, 0 CODTRANSF1
    FROM IESIRI I
      INNER JOIN LIVR     L   ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
      INNER JOIN LIVR1    L1  ON L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC  NSL ON NSL.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR      NL  ON NL.CODNIR = NSL.CODNIR
      INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIRSTOC  NS  ON NS.CODNIRSTOC = NS1.CODNIRSTOCORIG
      INNER JOIN NIR      N   ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST    G   ON NL.GEST = G.CODGEST
      LEFT  JOIN INTRARI  R   ON R.CODINTR = N.CODINTR AND R.TIPDOC = N.TIPNIR
      LEFT  JOIN TRANSF  RT   ON RT.CODTRANSF = N.CODTRANSF AND RT.TIPDOC = N.TIPNIR
      LEFT  JOIN IESIRI   IES ON IES.CODIES = N.CODIES AND IES.TIPDOC = N.TIPNIR
      LEFT  JOIN NIRSER   NSE ON NSE.CODNIRSER = L1.CODNIRSER
      LEFT  JOIN NSERII   SER ON SER.CODSERIE = NSE.CODSERIE
    WHERE I.TIPDOC IN (&apos;||sTipDocIes||&apos;) AND I.OPERAT = 1 AND I.ANULAT = 0 AND (L1.CANT &gt; 0 AND I.TIPDOC &lt;&gt; 15 OR L1.CANT &lt; 0 AND I.TIPDOC = 15)
      AND I.AN*12+I.LUNA&apos;||sCondAL||sCondGest1||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
    &apos;UNION ALL
      SELECT
        NS.CODOBIECT, NSO.CODNIRSTOC, I.CODIES, COALESCE(INTR.CODINTR, T.CODTRANSF) CODINTR, I.DATADOC,
        COALESCE(NSO.FURN,0) FURN, SER.SERIE, N.GEST AS GEST, I.TIPDOC, 0 STOCINIT,0 CANTINT, L1.CANT CANTIES, 1 ORD,
        II1.CODINTR1, L1.CODIES1, DVI1.CODDVI1, TT1.CODTRANSF1
      FROM NIRSTOC NS
           INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = NS.CODNIRSTOC
           INNER JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG&apos;||
           sJoinCLS||&apos; 
           INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
           INNER JOIN NIR N ON N.CODNIR = NSO.CODNIR
           INNER JOIN NIR NN ON NN.CODNIR = NS.CODNIR
           INNER JOIN NGEST G ON NN.GEST = G.CODGEST
           INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
           INNER JOIN IESIRI I ON I.CODIES = L.CODIES
           INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1 AND I1.CODIES = I.CODIES
           LEFT JOIN INTRARI1 II1 ON II1.CODINTR1 = NS.CODINTR1
           LEFT JOIN TRANSF1 TT1 ON NS.CODTRANSF1 = TT1.CODTRANSF1
           LEFT JOIN DVI1 DVI1 ON NS.CODDVI1 = DVI1.CODDVI1
           LEFT JOIN INTRARI1 INTR1 ON NSO.CODINTR1 = INTR1.CODINTR1
           LEFT JOIN INTRARI INTR ON INTR.CODINTR = INTR1.CODINTR
           LEFT JOIN TRANSF1 T1 ON NSO.CODTRANSF1 = T1.CODTRANSF1
           LEFT JOIN TRANSF T ON T1.CODTRANSF = T.CODTRANSF
           LEFT JOIN NIRSER NSE ON L1.CODNIRSER = NSE.CODNIRSER
           LEFT JOIN NSERII SER ON SER.CODSERIE = NSE.CODSERIE
      WHERE I.AN*12+I.LUNA&apos;||sCondAL||sCondGestN||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos; AND L1.CANT &lt; 0
     UNION ALL
     SELECT
      LV.CODOBIECT, 0 CODNIRSTOC, I.CODIES, 0 CODINTR, I.DATADOC,
      COALESCE(NS.FURN,0) AS FURN, SER.SERIE, LV.GEST, I.TIPDOC, 0 STOCINIT, 0 CANTINT, CASE WHEN I.TIPDOC = 15 THEN -1 ELSE 1 END * L1.CANT AS CANTIES, 1 ORD,
      L1.CODINTR1, L1.CODIES1, L1.CODDVI1, 0 CODTRANSF1
    FROM IESIRI I
      INNER JOIN LIVR     L   ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
      INNER JOIN LIVR1    L1  ON L1.CODLIVR = L.CODLIVR
      INNER JOIN LIVRVAL  LV  ON LV.CODLIVR1 = L1.CODLIVR1
      LEFT JOIN NIRSTOC  NSL ON NSL.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIR      NL  ON NL.CODNIR = NSL.CODNIR
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIRSTOC  NS  ON NS.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR      N   ON N.CODNIR = NS.CODNIR
      LEFT JOIN NGEST    G   ON LV.GEST = G.CODGEST
      LEFT  JOIN INTRARI  R   ON R.CODINTR = N.CODINTR AND R.TIPDOC = N.TIPNIR
      LEFT  JOIN TRANSF  RT   ON RT.CODTRANSF = N.CODTRANSF AND RT.TIPDOC = N.TIPNIR
      LEFT  JOIN IESIRI   IES ON IES.CODIES = N.CODIES AND IES.TIPDOC = N.TIPNIR
      LEFT  JOIN NIRSER   NSE ON NSE.CODNIRSER = L1.CODNIRSER
      LEFT  JOIN NSERII   SER ON SER.CODSERIE = NSE.CODSERIE
    WHERE I.TIPDOC IN (&apos;||sTipDocIes||&apos;) AND I.OPERAT = 1 AND I.ANULAT = 0 AND (L1.CANT &gt; 0 AND I.TIPDOC &lt;&gt; 15 OR L1.CANT &lt; 0 AND I.TIPDOC = 15)
      AND I.AN*12+I.LUNA&apos;||sCondAL||sCondGest2||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
      
  if PKG_LIST_SELECTLUNAAN.optiunea2 then
    sInsert := sInsert||&apos;
    UNION ALL
    SELECT
      NS.CODOBIECT, NS.CODNIRSTOC, T.CODTRANSF CODIES, 0 CODINTR, T.DATADOC,
      COALESCE(NS.FURN,0) AS FURN, SER.SERIE, N.GEST, T.TIPDOC,
      0 STOCINIT, 0 CANTINT, L1.CANT AS CANTIES, 1 ORD,
      0 CODINTR1, 0 CODIES1, 0 CODDVI1, T1.CODTRANSF1
    FROM TRANSF T
      INNER JOIN TRANSF1  T1  ON T1.CODTRANSF = T.CODTRANSF
      INNER JOIN LIVR     L   ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
      INNER JOIN LIVR1    L1  ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = T1.CODTRANSF1
      INNER JOIN NIRSTOC  NSL ON NSL.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIR      NL  ON NL.CODNIR = NSL.CODNIR
      INNER JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN NIRSTOC  NS  ON NS.CODNIRSTOC = NS1.CODNIRSTOCORIG
      INNER JOIN NIR      N   ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST    G   ON G.CODGEST = NL.GEST
      LEFT  JOIN INTRARI  R   ON R.CODINTR = N.CODINTR AND R.TIPDOC = N.TIPNIR
      LEFT  JOIN TRANSF  RT   ON RT.CODTRANSF = N.CODTRANSF AND RT.TIPDOC = N.TIPNIR
      LEFT  JOIN NIRSER   NSE ON NSE.CODNIRSER = L1.CODNIRSER
      LEFT  JOIN NSERII   SER ON SER.CODSERIE = NSE.CODSERIE
    WHERE T.TIPDOC = 12 AND T.OPERAT = 1 AND T.ANULAT = 0
      AND T.AN*12+T.LUNA&apos;||sCondAL||sCondGest1||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
  END IF;
  sinsert := sinsert||&apos;
  )
  SELECT
    O.DENUMIRE, PROD.DEN_PART PRODUCATOR, J.SERIE, COALESCE(FURN.DEN_PART,GI.DEN_GEST) FURNIZOR,
    CASE WHEN DIM.CODIES &gt; 0 THEN DIM.PREFIXDOC ELSE COALESCE(INTR.PREFIXDOC,TRI.PREFIXDOC) END,
    CASE WHEN DIM.CODIES &gt; 0 THEN DIM.NRDOC ELSE COALESCE(INTR.NRDOC,TRI.NRDOC) END,
    CASE WHEN DIM.CODIES &gt; 0 THEN DIM.DATADOC ELSE COALESCE(INTR.DATADOC,TRI.DATADOC) END,
    J.STOCINIT,
    J.CANTINT,
    COALESCE(CLI.DEN_PART,GE.DEN_GEST) CLIENT, J.CANTIES, COALESCE(IES.PREFIXDOC,TRE.PREFIXDOC), COALESCE(IES.NRDOC,TRE.NRDOC), COALESCE(IES.DATADOC,TRE.DATADOC),
    Sum(J.STOCINIT+J.CANTINT-J.CANTIES) OVER (PARTITION BY O.CODOBIECT, FURN.CODPART, Coalesce(J.SERIE,&apos;&apos;~&apos;&apos;) 
    ORDER BY J.DATADOC, J.ORD, J.CODIES ROWS UNBOUNDED PRECEDING) STOC,
    Row_Number()                     OVER (PARTITION BY O.CODOBIECT, FURN.CODPART, Coalesce(J.SERIE,&apos;&apos;~&apos;&apos;) 
    ORDER BY J.DATADOC, J.ORD, J.CODIES) ORDINE  &apos;||gUserAlias||&apos;
  FROM (SELECT * FROM OINT
        UNION ALL
        SELECT * FROM OIES
       ) J
    INNER JOIN NARTOBJ  O       ON O.CODOBIECT        = J.CODOBIECT
    INNER JOIN NART     A       ON A.CODARTICOl       = O.CODARTICOL
    INNER JOIN NART1    A1      ON A1.CODARTICOl      = O.CODARTICOL AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop||&apos; BETWEEN    A1.ALSTART and    A1.ALSTOP
    INNER JOIN NGEST    G       ON G.CODGEST          = J.GEST
    LEFT  JOIN NTVA             ON NTVA.CODTVA        = A1.CODTVA
    LEFT  JOIN NTVA1            ON NTVA1.CODTVA       = A1.CODTVA    AND &apos;||PKG_LIST_SELECTLUNAAN.LunaStop||&apos; BETWEEN NTVA1.ALSTART and NTVA1.ALSTOP
    LEFT  JOIN NCLASEA  CA      ON CA.CODCLASEA       = A.CLASA
    LEFT  JOIN NCLASEAS CAS     ON CAS.CODCLASEAS     = A.CLASASTATIST
    LEFT  JOIN INTRARI  INTR    ON INTR.CODINTR       = J.CODINTR AND J.TIPDOC = INTR.TIPDOC
    LEFT  JOIN IESIRI   IES     ON IES.CODIES         = J.CODIES AND J.TIPDOC = IES.TIPDOC
    LEFT  JOIN IESIRI   DIM     ON DIM.CODIES         = J.CODIES AND J.TIPDOC = DIM.TIPDOC AND J.TIPDOC = 15
    LEFT  JOIN TRANSF   TRI     ON TRI.CODTRANSF      = J.CODINTR AND J.TIPDOC = TRI.TIPDOC
    LEFT  JOIN TRANSF   TRE     ON TRE.CODTRANSF      = J.CODIES AND J.TIPDOC = TRE.TIPDOC
    LEFT  JOIN NPART    FURN    ON FURN.CODPART       = J.FURN
    LEFT  JOIN NPART    CLI     ON CLI.CODPART        = IES.PARTENER
    LEFT  JOIN NGEST    GI      ON GI.CODGEST         = TRI.CODGESTCMD
    LEFT  JOIN NGEST    GE      ON GE.CODGEST         = TRE.CODGESTCMD
    LEFT  JOIN NPART    PROD    ON PROD.CODPART       = O.CODPRODUCATOR
    LEFT  JOIN NCLASEP  CF      ON CF.CODCLASEP       = FURN.CODCLASA
    LEFT  JOIN NCLASEP  CC      ON CC.CODCLASEP       = CLI.CODCLASA
    LEFT  JOIN NCLASEP  CP      ON CP.CODCLASEP       = PROD.CODCLASA
    LEFT  JOIN NAGENDA  SLIVR   ON SLIVR.CODAGENDA    = IES.CODLOCATIE
    LEFT  JOIN NLOCALIT LOCLIVR ON LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT
    LEFT  JOIN NJUDET   JUDLIVR ON JUDLIVR.CODJUDET   = LOCLIVR.CODJUDET
    LEFT  JOIN IESIRI1 IES1     ON IES1.CODIES1 = J.CODIES1
    LEFT  JOIN INTRARI1 II1     ON II1.CODINTR1 = J.CODINTR1
    LEFT  JOIN DVI1     DVI1    ON DVI1.CODDVI1 = J.CODDVI1
    LEFT  JOIN TRANSF1  TT1     ON TT1.CODTRANSF1 = J.CODTRANSF1
    &apos;||
    gSuplJoins||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_SITINIESLUNA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITONINV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8EF6E17F04691BB89F55B63565AF40068E1DAF10</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_sitoninv IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE UmpleTmp(pTotAnul BOOLEAN DEFAULT TRUE) IS
  sInsTMP    VARCHAR2(30000);
  sAnLunaIni NUMBER;
  sAnIni     NUMBER;
  sCondTmp   VARCHAR2( 1000)  := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
BEGIN
  IF pTotAnul
  THEN sAnLunaIni := Trunc((PKG_LIST_SELPARTART.AnLunaIni-1)/12)*12+1;
  ELSE sAnLunaIni := PKG_LIST_SELPARTART.AnLunaIni;
  END IF;

  sAnIni := Trunc((PKG_LIST_SELPARTART.AnLunaIni-1)/12);

  IF NOT PKG_LIST_SELPARTART.IsAllPart THEN
    sCondTmp := sCondTmp||&apos;
      AND I.PARTENER IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;
  IF NOT PKG_LIST_SELPARTART.IsAllArt THEN
    sCondTmp := sCondTmp||&apos;
      AND I1A.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;

  sInsTMP :=
  &apos;INSERT INTO  tmp_list_sitoninv (  codpart, codobiect, codcriteriu, codcont, subunitatea, proc, bazadisc, valdisc, valdiscant, valdiscfin, codmoneda )
  WITH
    x AS (
    SELECT
      i1a.codies1, i1d.codies1 codiesd, Row_Number() OVER (PARTITION BY i1a.codies1 ORDER BY i1d.indexlocal) Idx,
      DECODE (t.tip,2,i1a.pu,i1a.pu*i1a.cant) pu, DECODE (t.tip,2,i1a.cant,1) cant, i1d.cant proc, Nvl(cd.codcriteriu,0) CodCriteriu, Nvl(cd.cumulat,0) cumulat,
      CASE WHEN cd.codcriteriu IS NULL THEN Nvl(i1d.ContDiscount,0) ELSE 0 END ContDiscount, nvl(i.moneda,0) codmoneda
    FROM iesiri i
      inner join iesiri1 i1d ON i1d.codies = i.codies AND i1d.tiplinie IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)
      inner join iesiri1 i1a ON i1a.codies = i.codies AND i1a.tiplinie NOT IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1a.indexlocal &lt; i1d.indexlocal
      left join criteriidisc cd ON cd.codcriteriu = i1d.codcriteriu
      left join (SELECT level luna, Nvl(pkg_categconst.GetValConstanta(&apos;&apos;ModAplicProcDisc&apos;&apos; ,0,&apos;||sAnLunaIni||&apos;+level),1) Tip FROM dual CONNECT BY level &lt;= &apos;||To_Char(PKG_LIST_SELPARTART.AnLunaFin-sAnLunaIni)||&apos;) t ON t.luna = i.luna
    WHERE i.tipdoc IN (19,26)
      AND i.an*12+i.luna BETWEEN &apos;||To_Char(sAnLunaIni)||&apos; AND &apos;||To_Char(PKG_LIST_SELPARTART.AnLunaFin)||
      sCondTmp||&apos;
      AND CASE
            WHEN i1d.tiplinie &lt;&gt; &apos;&apos;G&apos;&apos; THEN 0
            WHEN (SELECT Max(x.indexlocal) FROM iesiri1 x WHERE x.codies = i.codies AND x.tiplinie NOT IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND x.indexlocal &gt;= i1a.indexlocal AND x.indexlocal &lt;  i1d.indexlocal) &gt;
                 (SELECT Min(y.indexlocal) FROM iesiri1 y WHERE y.codies = i.codies AND y.tiplinie     IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND y.indexlocal &gt;  i1a.indexlocal AND y.indexlocal &lt;= i1d.indexlocal)
            THEN 1
            ELSE 0
          END = 0
      AND I.OPERAT = 1 AND NVL(I.ANULAT,0) = 0
    ORDER BY i.an*12+i.luna,i.codies, i1a.codies),
    y (codies1, codcriteriu, contdiscount, idx, proc, cumulat, bd, d, d0, d1, d2, codmoneda) AS (
    SELECT
      x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat,
      x.cant * x.pu bd,
      x.cant * Round(x.pu*x.proc/100,2) d,
      Decode (x.cumulat, 0, Round(x.pu*x.proc/100,2),0 ) d0,
      Decode (x.cumulat, 1, Round(x.pu*x.proc/100,2),0 ) d1,
      Decode (x.cumulat, 2, Round(x.pu*x.proc/100,2),0 ) d2,
      x.codmoneda
    FROM x
    WHERE idx=1
    UNION ALL
    SELECT
      x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat,
      x.cant * Decode (x.cumulat, 0, x.pu+y.d0+y.d1+y.d2, 1, x.pu, 2, x.pu+y.d0+y.d1, 0 ) bd,
      x.cant * Decode (x.cumulat, 0, Round( (x.pu+y.d0+y.d1+y.d2)*x.proc/100,2), 1, Round( x.pu*x.proc/100,2), 2, Round( (x.pu+y.d0+y.d1)*x.proc/100,2), 0 ) d,
      y.d0 + Decode (x.cumulat, 0, Round( (x.pu+y.d0+y.d1+y.d2)*x.proc/100,2),0 ) d0,
      y.d1 + Decode (x.cumulat, 1, Round( x.pu*x.proc/100,2),0 ) d1,
      y.d2 + Decode (x.cumulat, 2, Round( (x.pu+y.d0+y.d1)*x.proc/100,2),0 ) d2,
      y.codmoneda
    FROM y INNER JOIN x ON x.codies1 = y.codies1 AND x.idx = y.idx + 1)
  SELECT
    i.partener, i1.codobiect, y.codcriteriu, y.contdiscount, i.subunitatea, y.proc,
    Sum(CASE WHEN i.luna &lt; &apos;||PKG_LIST_SELPARTART.AnLunaIni||&apos; THEN 0   ELSE y.bd END) BazaDisc,
    Sum(CASE WHEN i.luna &lt; &apos;||PKG_LIST_SELPARTART.AnLunaIni||&apos; THEN 0   ELSE y.d  END) Disc,
    Sum(y.d) DiscAnt,
    Sum(CASE WHEN i.luna &lt;&gt; &apos;||PKG_LIST_SELPARTART.AnLunaFin||&apos; THEN 0  ELSE y.d  END) DiscFin,
    y.codmoneda
  FROM y
    left join iesiri1 i1 ON i1.codies1 = y.codies1
    left join iesiri i ON i.codies = i1.codies
  GROUP BY i.partener, i1.codobiect, y.codcriteriu, y.contdiscount, i.subunitatea, y.proc, y.codmoneda&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_list_sitoninv&apos;;
  LIST_EXECUTE_IMMEDIATE(sInstmp, 0, 0);
  COMMIT;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;npart p, nartobj nao, nart na, nclasea ca, nclasedisc clsd&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    Part, Art, ClasaA, Subunit,
    Disc,
    TipBazaC,
    ProcDisc, BazaDisc, ValDisc, ValADisc, Moneda&apos;||gUserFields||&apos;)
  SELECT
    p.Den_Part, nao.Denumire, ca.Den_Clasea, sub.Den_Subunit,
    CASE
      WHEN tmp.codcriteriu &lt;&gt; 0 THEN cd.DenCriteriu
      WHEN Sign(tmp.proc) &gt; 0 THEN &apos;&apos;Majorare direct pe cont &apos;&apos;||c.simbol
      ELSE &apos;&apos;Discount direct pe cont &apos;&apos;||c.simbol
    END,
    DECODE(CUMULAT,0,&apos;&apos;NET= valoare articol cu toate disc.aplicate&apos;&apos;,1,&apos;&apos;BRUT = valoare articol&apos;&apos;,2,&apos;&apos;valoare articol cu disc. de tip BRUT si NET aplicate&apos;&apos;),
    tmp.Proc, tmp.BazaDisc, tmp.ValDisc, tmp.ValDiscAnt, mon.simbol &apos;||gUserAlias||&apos;
  FROM tmp_list_sitoninv tmp
    LEFT JOIN nmonede mon on tmp.codmoneda = mon.codmoneda
    LEFT JOIN npart p ON p.codpart = tmp.codpart
    LEFT JOIN nartobj nao ON nao.codobiect = tmp.codobiect
    LEFT JOIN nart na ON na.codarticol = nao.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = na.clasa
    LEFT JOIN nsubunit sub ON sub.codsubunit = tmp.subunitatea
    LEFT JOIN criteriidisc cd ON cd.codcriteriu = tmp.codcriteriu
    LEFT JOIN nclasedisc clsd ON clsd.codclasedisc = cd.clasa
    LEFT JOIN ncont c ON c.codcont = tmp.codcont&apos;||
    gSuplJoins;

  UmpleTmp;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SITONINV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITPEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>513ED7ACA1A475B56E587778400CAB672A8EA735</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITPEN is

p_Tabla     VARCHAR2(250);
gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);
gShortVer   NUMBER(10);
  
PROCEDURE setParams (v_Tabla IN VARCHAR2,V_CODJOB1 IN NUMBER  DEFAULT 0) IS
BEGIN
  p_Tabla := upper(v_Tabla);
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sSQL varchar2(20000);  
aCount number(20);
BEGIN
  gSuplCols := &apos;nmonede m,npartcodfisc pcf,npart p,nagenda ag&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sSQL := 
  &apos;insert into &apos;||tmpName||&apos;(
    CODOBLIGPIF,
    PREFIXDOC,
    NRDOC,
    DATADOC,
    VALDOC,
    TERMEN,
    REST,
    MAJORARI,
    LOCATIE,
    DEN_PART,        
    DEN_SUBUNIT,     
    MONEDA,          
    MAJANTERIOARE,   
    DATA_LAST_FACTMAJ,
    DATA_LAST_PLATA, 
    GRATIEDOC,
    STORNO,
    SCADENTAV,
    RESTLADATA &apos;||gUserFields||&apos;)  
  select 
    tmp.codobligpif,
    tmp.prefixdoc,
    tmp.nrdoc,
    tmp.datadoc,
    tmp.valdoc,
    tmp.termen,
    tmp.rest,
    tmp.majorari,
    tmp.locatie,
    tmp.den_part,
    tmp.den_subunit,
    m.den_moneda,
    tmp.majanterioare,
    tmp.data_last_factmaj,
    tmp.data_last_plata,
    tmp.gratiedoc,
    tmp.storno,
    tmp.scadentav,
    tmp.restladata &apos;||gUserAlias||&apos;
  from TMP_LST_GENPEN tmp
       left join nmonede m on tmp.moneda = m.codmoneda
       left join npart p on tmp.codpart = p.codpart
       left join nagenda ag on ag.codagenda = tmp.codlocatie&apos;||gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sSQL, aListID, aListVer);
  commit;
END;

end PKG_LIST_BASE_SITPEN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITPUNCTCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FAD54B2726FFF879DEFCA744741C2EBCBB6A697</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITPUNCTCLI is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(10000);
sCondSupl varchar2(1000);
vDataIni      DATE           := PKG_LIST_SELECTPERIOADA.DataOraIni;
vDataFin      DATE           := PKG_LIST_SELECTPERIOADA.DataOraFin;
sDataIni      VARCHAR2(  100);
sDataFin      VARCHAR2(  100);
BEGIN
  gSuplCols := &apos;iesiri i, iespuncte ip, npart p&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sDataIni := &apos;To_date(&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;)&apos;;
  sDataFin := &apos;To_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;)&apos;;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     PrefixDoc,
     NrDoc,
     DataDoc,
     Part,
     PctDoc,
     PctNull,
     PctStinse,
     Blocat,
     Obs &apos;||gUserFields||&apos;)
  SELECT
     i.codies, 
     i.tipdoc, 
     i.prefixdoc,
     i.nrdoc, 
     i.datadoc, 
     p.den_part, 
     ip.punctedoc, 
     ip.puncteanulate, 
     ip.punctestinse, 
     case when ip.blocat = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end, 
     i.obs &apos;||gUserAlias||&apos;
  from iesiri i 
       inner join iespuncte ip on ip.codies = i.codies 
       inner join npart p on i.partener = p.codpart 
       &apos;||gSuplJoins||&apos;
  where i.anulat = 0 and i.operat = 1 and (ip.punctedoc &lt;&gt; 0 or ip.puncteanulate &lt;&gt; 0 or ip.punctestinse &lt;&gt; 0) and
        i.datadoc between &apos;||sDataIni||&apos; AND &apos;||sDataFin||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;,&apos;subunitatea&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITPUNCTCLI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITTRANSP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A03931AB1B5495D48112CCE6C03905B8E6C52CC6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITTRANSP is

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ProcessList(tmpName IN VARCHAR2, aListID IN NUMBER DEFAULT 0, aListVer IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(15000);
BEGIN
  sInsert :=
  &apos;INSERT INTO &apos; || tmpName || &apos;(
     Traseu, Client, SerieDoc, NrDoc, DataDoc, Sofer, MijlTransp, NrTransp,
     MasaDoc, VolumDoc, MasaTraseu, VolumTraseu, MasaUtila, VolumUtil,
     CodTraseu, LungTransp, LatTransp, InaltTransp)
  SELECT
    TL.DenTraseu Traseu, DECODE(C.TipDoc,18,P.Den_Part,43,G.Den_Gest,44,S.Den_Subunit) Client, C.SeriaDoc SerieDoc, C.NrDoc, C.DataDoc,
    NumePrenume( PERS.Prenume, PERS.Nume) Sofer, A.Den_Articol MijlTransp, PA.NrInreg,
    SUM(TTC.Masa) MasaDoc, SUM(TTC.Volum) VolumDoc, 0 MasaTraseu, 0 VolumTraseu, PA.MasaU MasaUtila, PA.VolumU VolumUtil,
    TL.CodTraseuLivr CodTraseu, PA.Lung LungTransp, PA.Lat LatTransp, PA.Inalt InaltTransp
  FROM tmp_traseulivr_allcmd_baza TTC
    LEFT JOIN TraseuLivr TL ON TL.CodTraseuLivr = TTC.CodTraseu
    LEFT JOIN Comanda C ON C.CodComanda = TTC.CodComanda
    LEFT JOIN NPart P ON P.CodPart = C.partener
    LEFT JOIN NSubunit S ON S.CodSubunit = C.Subunitatea
    LEFT JOIN NGest G ON G.CodGest = C.CodGest
    LEFT JOIN NParcAut PA on PA.CodNParcAut = C.MIJLTRANSP
    LEFT JOIN NArtObj AO ON AO.CodObiect = PA.CodArt
    LEFT JOIN NArt A ON A.CodArticol = AO.CodArticol
    LEFT JOIN NPers PERS ON PERS.CodPers = PA.Sofer
  GROUP BY
    TL.DenTraseu, DECODE(C.TipDoc,18,P.Den_Part,43,G.Den_Gest,44,S.Den_Subunit), C.SeriaDoc, C.NrDoc, C.DataDoc,
    PERS.Prenume, PERS.Nume, A.Den_Articol, PA.NrInreg, PA.MasaU, PA.VolumU, TL.CodTraseuLivr, PA.Lung, PA.Lat, PA.Inalt&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert := &apos;update &apos;||tmpname||&apos; tmp set masatraseu = (select sum(t.masa) from TMP_TraseuLivr_Comenzi t where tmp.codtraseu = t.codtraseu),
                                           volumtraseu = (select sum(t.volum) from TMP_TraseuLivr_Comenzi t where tmp.codtraseu = t.codtraseu)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;
  
end PKG_LIST_BASE_SITTRANSP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6852647A879C50D282A062EF2A4395B81F9360E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_situtilaje IS

  V_ToateU BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams (p_ToateU IN NUMBER DEFAULT 1) IS
BEGIN
  v_ToateU := p_ToateU = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  varchar2(5000);
BEGIN
  gSuplCols := &apos;UTILAJE U, UTILAJE1 U1, NARTOBJ NOBJ, NPART NP, NARTAMB AA, NCLASEP CP, TRASEULIVR TL, NPARTCODFISC CF&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos; (
    DEN_PART, COD_PART, TIPOLOGIE, DEN_UTIL, TIP_UTIL, NrUtilAct,
    SedL, SedL_Adr, SedL_Loc, SedL_Jud,
    SedS, SedS_Adr, SedS_Loc, SedS_Jud,
    SedF, SedF_Adr, SedF_Loc, SedF_Jud,
    Operator,
    StatusDepo,
    StatusPart,
    StatusServ,
    StatusEstetic,
    Responsabil,
    DataCreare&apos;||
    gUserFields||&apos;)
  SELECT
    NP.DEN_PART, TRIM(REPLACE(UPPER(CF.CODFISCAL),&apos;&apos;RO&apos;&apos;)) CODCLI, TS.DENUMIRE, NOBJ.DENUMIRE, U.TIPUTILAJ, DECODE(U1.STATUS_PART,2,1,0),
    SL.OBS, GETADRESA(SL.SECTOR, SL.STRADA, SL.NR1, SL.NR2, SL.BLOC, SL.SCARA, SL.ETAJ, SL.APART, SL.CODPOSTAL), LL.DEN_LOCALIT, JL.DEN_JUDET,
    SS.OBS, GETADRESA(SS.SECTOR, SS.STRADA, SS.NR1, SS.NR2, SS.BLOC, SS.SCARA, SS.ETAJ, SS.APART, SS.CODPOSTAL), LS.DEN_LOCALIT, JS.DEN_JUDET,
    SF.OBS, GETADRESA(SF.SECTOR, SF.STRADA, SF.NR1, SF.NR2, SF.BLOC, SF.SCARA, SF.ETAJ, SF.APART, SF.CODPOSTAL), LF.DEN_LOCALIT, JF.DEN_JUDET,
    UTILIZATOR.Nume,
    DECODE(U1.STATUS_DEPO,1,&apos;&apos;Plasat la partener&apos;&apos;,2,&apos;&apos;Plasabil&apos;&apos;,3,&apos;&apos;Defect/Reparatii&apos;&apos;,4,&apos;&apos;Casabil&apos;&apos;,5,&apos;&apos;Donatie&apos;&apos;,6,&apos;&apos;Plasat la partener pt vanzare&apos;&apos;,7,&apos;&apos;Plasat la partener pt depozitare&apos;&apos;),
    DECODE(U1.STATUS_PART,2,&apos;&apos;Da&apos;&apos;,3,&apos;&apos;Nu&apos;&apos;,&apos;&apos;...&apos;&apos;),
    DECODE(U1.STATUS_SERVICE,2,&apos;&apos;Revizie anuala&apos;&apos;,3,&apos;&apos;Incident&apos;&apos;,&apos;&apos;Initial&apos;&apos;),
    DECODE(U1.ESTETIC,1,&apos;&apos;Ok&apos;&apos;,2,&apos;&apos;De colantat integral&apos;&apos;,3,&apos;&apos;De colantat fata&apos;&apos;,4,&apos;&apos;De colantat spate&apos;&apos;,5,&apos;&apos;De colantat laterale&apos;&apos;),
    DECODE(RESP.CODPERS,0,RESP.NUME,RESP.NUME||&apos;&apos; &apos;&apos;||RESP.PRENUME),
    To_Char(U1.DataCreare,&apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;)&apos;||
    gUserAlias||&apos;
  FROM UTILAJE U
    INNER JOIN UTILAJE1 U1 ON U1.CODUTILAJ = U.CODUTILAJ
    INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT
    LEFT JOIN NPART NP ON NP.CODPART = U1.CODPART
    LEFT JOIN NPARTCODFISC CF ON CF.CODPART =  NP.CODPART AND CF.PRINCIPAL = 1
    LEFT JOIN NAGENDA SL ON SL.CODAGENDA = U1.CODLOCATIE
    LEFT JOIN NTIPSEDII TS ON TS.CODTIPSEDIU = SL.CODTIPSEDIU
    LEFT JOIN NLOCALIT LL ON LL.CODLOCALIT = SL.CODLOCALIT
    LEFT JOIN NJUDET JL ON JL.CODJUDET = LL.CODJUDET
    LEFT JOIN NAGENDA SS ON SS.CODPART = U1.CODPART AND SS.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SS.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LS ON LS.CODLOCALIT = SS.CODLOCALIT
    LEFT JOIN NJUDET JS ON JS.CODJUDET = LS.CODJUDET
    LEFT JOIN NAGENDA SF ON SF.CODPART = U1.CODPART AND SF.SEDIUSOCIAL IN (2,3,6,7) AND NVL(SF.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LF ON LF.CODLOCALIT = SF.CODLOCALIT
    LEFT JOIN NJUDET JF ON JF.CODJUDET = LF.CODJUDET
    LEFT JOIN MIFIX M ON M.NRINVENTAR = U.NRINVENTAR
    LEFT JOIN (SELECT DISTINCT CODMIFIX,CODNIRSTOC FROM MIFIX1) M1 ON M1.CODMIFIX = M.CODMIFIX
    LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = U.CODOBIECT AND AA.UMSEC = NS.UMSEC
    LEFT JOIN NCLASEP CP ON CP.CODCLASEP = NP.CODCLASA
    LEFT JOIN TRASEULIVR TL ON TL.CODTRASEULIVR = SL.CODTRASEU
    LEFT JOIN NPERS RESp ON RESP.CODPERS = NVL(U1.CODPERS,0)
	  LEFT JOIN TMP_UTILIZATOR UTILIZATOR ON UTILIZATOR.CODUTILIZATOR = U1.USERID&apos;||
    gSuplJoins||&apos;
  WHERE U1.STATUS_PART = 2
    AND NVL(SF.CODAGENDA,0) =
        CASE
          WHEN SL.SEDIUSOCIAL IN (2,3,6,7) THEN SL.CODAGENDA
          WHEN SS.SEDIUSOCIAL IN (2,3,6,7) THEN SS.CODAGENDA
          ELSE NVL((SELECT MIN(x.CODAGENDA) FROM NAGENDA x WHERE x.CODPART = U1.CODPART AND x.SEDIUSOCIAL IN (2,3,6,7) AND NVL(x.INACTIV, 0) = 0),0)
        END&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);       
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITUTILAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITVANZRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BB328E7A0D7C555547FE9AC5AE011F25A0642F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITVANZRETAIL is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sPjTVA     VARCHAR2(  100):= &apos;CASE WHEN i1.pu*i1.cant = 0 THEN 0 ELSE ROUND(i1.tva*100/(i1.pu*i1.cant)) END&apos;;
  sWithDC    VARCHAR2( 5000);
  sJoinSer   VARCHAR2( 1000);
  sDenDisc   VARCHAR2(  500);
  sJoinAux   VARCHAR2( 5000);
BEGIN
  gSuplCols :=
    &apos;iesiriretail i, iesiri1retail i1, nartobj nao, nart na, num1 um, nclasea c, nclaseas cs, npart prod, ncont nc, ntva1 tmp_tva&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  sDenDisc := pkg_categconst.GetValConstanta(&apos;DenDiscount&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru) ;
  IF Trim(sDenDisc) IS NULL
  THEN sDenDisc := &apos;Discount&apos;;
  ELSE sDenDisc := REPLACE(sDenDisc,&apos;&apos;&apos;&apos;,&apos;&apos;&apos;&apos;&apos;&apos;);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    ART,
    UM, OBSART, CANT, CodIntern, CodExtern, Producator, Masa, Volum, CodVamal,
    PRET, PU, PD,
    PRET_LEI, PU_LEI, PD_LEI,
    VAL, VALADAOS, VALTVA, VAL_LEI, VALADAOS_LEI, VALTVA_LEI, TotalVal,
    PROCADAOS,
    PROCTVA,
    PROCTVAART,
    PROCDISC,
    PretMaximal,
    GARIES, GARART,
    DenClasaA,
    SimbClasaA,
    DiscAfis,
    DenClaseAS,
    IDX, NrUnic,
    NRCOLETE,
    DENATRIB,
    CantUMPrinc,
    TipIncVal,
    TipInc,
    Intocmit_nume, Intocmit_prenume, Intocmit_CNP, Intocmit_BI,
    client_den, carnet_simbol, carnet_serie, carnet_den, client_codext, client_codfisc, client_reg,
    doc_nr, doc_data,
    sediu, sediu_adresa, sediu_loc, sediu_judet, sediu_tara,
    username&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    MAN_IESIRI1 AS (
    SELECT
      I1.codiesretail, I1.CODOBIECT, I1.UMSEC, I1.codies1retail, I1.CANT, I1.PRETORIG, I1.PU, I1.PRETORIG*Coalesce(NullIf(I1.COEFDISCMAJ,0),1) PIES, I1.TVA,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.RESTFACT ELSE I1.CANT*I1.PRETORIG END VORIG,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.RESTFACT ELSE I1.CANT*I1.PU END VU,
      CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN I1.RESTFACT ELSE I1.CANT*I1.PU END*(1+Coalesce(I1.PROCDISC/100,0)) VIESL,
      Coalesce(I1.PROCDISC,0) MINPDISC, Coalesce(I1.PROCDISC,0) MAXPDISC, Coalesce(I1.ADDIM,0) MINADDIM, Coalesce(I1.ADDIM,0) MAXADDIM
    FROM IESIRI1RETAIL I1 INNER JOIN IESIRIRETAIL I ON I1.CODIESRETAIL = I.CODIESRETAIL
    WHERE Coalesce(I.ANULAT,0) = 0
      AND I.DATACREARE BETWEEN TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAINI, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAFIN, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;)
  )
  SELECT
    CASE
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos; client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) = 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare client &apos;&apos;
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &lt;=0 THEN &apos;&apos; &apos;||sDenDisc||&apos;: &apos;&apos; || cd.DENCRITERIU
      WHEN Coalesce(i1.CODCRITERIU,0) &gt; 2 AND i1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1.CANT &gt; 0 THEN &apos;&apos; Majorare: &apos;&apos; || cd.DENCRITERIU
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe grupul de articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;G&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de grup)&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; pe toate articole precedente&apos;&apos;
      WHEN i1.TIPLINIE = &apos;&apos;T&apos;&apos; AND i1.CONTDISCOUNT &lt;&gt; 0 AND i1.CANT &gt;  0 THEN &apos;&apos; Majorare direct pe cont (de total)&apos;&apos;
      ELSE nao.denumire
    END ART,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN &apos;&apos;%&apos;&apos; ELSE um.den_um1 END UM, i1.obs OBSART, mi1.cant/Coalesce(um.paritate,1) CANT, nao.codintern, nao.codextern, prod.den_part Producator, nao.masa, nao.volum, nao.codvamal,
    mi1.pretorig*um.paritate Pret, mi1.pu*um.paritate PU, mi1.pies*um.paritate PD,
    mi1.pretorig*um.paritate*Coalesce(i.curs,1) Pret_LEI, mi1.pu*um.paritate*Coalesce(i.curs,1) PU_LEI, mi1.pies*um.paritate*Coalesce(i.curs,1) PD_LEI,
    mi1.vu VAL, mi1.pu - mi1.pretorig VALADAOS, mi1.tva VALTVA, mi1.vu * Coalesce(i.curs,1) VAL_LEI, (mi1.vu - mi1.vorig) * Coalesce(i.curs,1) VALADAOS_LEI, mi1.tva * Coalesce(i.curs,1) VALTVA_LEI, I.VALDOC TotalVal,
    CASE WHEN mi1.minaddim = mi1.maxaddim THEN mi1.minaddim WHEN mi1.vorig = 0 THEN 0 ELSE (mi1.vu-mi1.vorig)*100/mi1.vorig END PROCADAOS,
    ROUND(CASE WHEN mi1.vu = 0 THEN tmp_tva.procent WHEN Coalesce(mi1.tva,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0) / mi1.vu * 100 END,2) PROCTVA,
    ROUND(CASE WHEN tmp_tva.procent IS NOT NULL THEN tmp_tva.procent WHEN Coalesce(mi1.tva,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0) / mi1.vu * 100 END,2) PROCTVAART,
    CASE WHEN mi1.minpdisc= mi1.maxpdisc THEN mi1.minpdisc WHEN mi1.vu = 0 THEN 0 ELSE (mi1.viesl-mi1.vu)*100/mi1.vu END PROCDISC,
    CASE
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2) AND Coalesce(i1.pumaximal    , 0) &lt;&gt; 0 THEN i1.pumaximal
      WHEN Coalesce(nao1.tippretmax,0) IN (4,5) AND Coalesce(nao1.pretmaximal, 0) &lt;&gt; 0 THEN nao1.pretmaximal
      WHEN Coalesce(nao1.tippretmax,0) IN (1,2,4,5)                                    THEN -1
      ELSE 0
    END PretMaximal,
    i1.garantie GARIES, nao.lunigarantie GARART,
    CASE WHEN NOT I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN c.den_clasea WHEN I1.CANT &lt;= 0 THEN &apos;&apos; &apos;||sDenDisc||&apos; (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos; ELSE &apos;&apos; Majorare (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos; END DenClasaA,
    CASE WHEN NOT I1.TIPLINIE IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) THEN c.simbol     WHEN i1.CANT &lt;= 0 THEN &apos;&apos; D (&apos;&apos;||-i1.CANT||&apos;&apos;%)&apos;&apos; ELSE &apos;&apos; M (&apos;&apos;||i1.CANT||&apos;&apos;%)&apos;&apos; END SimbClasaA,
    case when Coalesce(i1.procdisc,0) = 0 then &apos;&apos; &apos;&apos; else to_char(i1.procdisc)||&apos;&apos;%&apos;&apos; end DiscAfis,
    cs.den_claseas DenClaseAS,
    i1.indexlocal IDX, ROWNUM NrUnic,
    (SELECT COUNT(1) FROM nartobjcolet naoc WHERE naoc.codobiect = nao.codobiect) NRCOLETE,
    (SELECT vc2_nt_to_string(CAST(COLLECT(a.denumire order by aa.indexlocal) AS vc2_nt)) FROM nartatr aa INNER JOIN natrib a ON a.codatribut = aa.codatribut WHERE aa.codarticol = nao.codarticol ) DENATRIB,
    mi1.cant CantUMPrinc,
    (SELECT string_agg(CASE Coalesce(TIPPLATA,0) WHEN 0 THEN &apos;&apos;CASH&apos;&apos; WHEN 1 THEN &apos;&apos;CEC&apos;&apos; WHEN 2 THEN &apos;&apos;CARD&apos;&apos; WHEN 3 THEN &apos;&apos;CREDIT&apos;&apos; END||&apos;&apos;:&apos;&apos;||TO_CHAR(VALOARE)||&apos;&apos; &apos;&apos;) FROM MODPLATAIESRETAIL WHERE CODIESRETAIL = I.CODIESRETAIL) TipIncVal,
    (SELECT string_agg(CASE Coalesce(TIPPLATA,0) WHEN 0 THEN &apos;&apos;CASH&apos;&apos; WHEN 1 THEN &apos;&apos;CEC&apos;&apos; WHEN 2 THEN &apos;&apos;CARD&apos;&apos; WHEN 3 THEN &apos;&apos;CREDIT&apos;&apos; END||&apos;&apos; &apos;&apos;) FROM MODPLATAIESRETAIL WHERE CODIESRETAIL = I.CODIESRETAIL) TipInc,
    Coalesce(U.Nume,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_nume, Coalesce(U.Prenume,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_prenume, Coalesce(U.CNP,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_CNP, U.BISERIA||&apos;&apos; &apos;&apos;||U.BINR Intocmit_BI,
    P.DEN_PART client_den, CAR.SIMBOL carnet_simbol, I.SERIADOC carnet_serie, CAR.DENUMIRE carnet_den, P.CODEXTERN client_codext, CODF.CODFISCAL client_codfisc, P.REGCOM client_reg,
    I.NRDOC doc_nr, I.DATADOC doc_data,
    SFACT.Denumire sediu, GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) sediu_adresa, LFACT.DEN_LOCALIT sediu_loc, JFACT.Den_Judet sediu_judet, TFACT.Den_Tara sediu_tara,
    ut.username&apos;||gUserAlias||&apos;
  FROM man_iesiri1 mi1
    LEFT JOIN iesiri1retail i1 ON i1.codies1retail = mi1.codies1retail
    LEFT JOIN iesiriretail i ON i.codiesretail = i1.codiesretail
    LEFT JOIN NCODFISCRETAIL CODF ON CODF.COD = I.CODFISCALRETAIL
    LEFT JOIN nartobj nao ON nao.codobiect = i1.codobiect
    LEFT JOIN nart na ON na.codarticol = nao.codarticol
    LEFT JOIN num1 um ON um.codum1 = i1.umsec
    LEFT JOIN nclasea c ON c.codclasea = na.clasa
    LEFT JOIN nclaseas cs ON cs.codclaseas = na.clasastatist
    LEFT JOIN npart prod ON prod.codpart = nao.codproducator
    LEFT JOIN npart p ON p.codpart = i.partener
    LEFT JOIN ncont nc ON nc.codcont = i1.contdiscount
    LEFT JOIN nechiv e ON e.codobiect = i1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN NARTOBJ1 nao1 ON nao1.codobiect = i1.codobiect AND i.an*12+i.luna BETWEEN nao1.alstart AND nao1.alstop
    LEFT JOIN criteriidisc cd ON cd.codcriteriu = i1.codcriteriu
    LEFT JOIN NART1 tmp_a ON tmp_a.codarticol = na.codarticol AND i.an*12+i.luna BETWEEN tmp_a.alstart AND tmp_a.alstop
    LEFT JOIN NTVA1 tmp_tva ON tmp_tva.codtva = tmp_a.codtva AND i.an*12+i.luna BETWEEN tmp_tva.alstart AND tmp_tva.alstop
    LEFT JOIN NPERS U ON U.LOGONNAME = I.USERID
    LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = I.CARNETDOC
    LEFT JOIN NSEDIIPARTRETAIL SFACT ON SFACT.CODSEDIU = I.CODSEDIURETAIL
    LEFT JOIN NLOCALIT LFACT ON LFACT.CODLOCALIT = Coalesce(SFACT.CODLOCALIT, 0)
    LEFT JOIN NJUDET JFACT ON JFACT.CODJUDET = Coalesce(LFACT.CODJUDET, 0)
    LEFT JOIN NTARI TFACT ON TFACT.CODTARA = Coalesce(LFACT.CODTARA, 0)
    left join tmp_utilizator ut on i.userid = ut.codutilizator &apos;||
    gSuplJoins||&apos;
  ORDER BY i1.indexlocal&apos;;

  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITVANZRETAIL;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SITVANZRETSINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>844D77294DC2E6F719DC9CB6E24A7AA463C91296</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SITVANZRETSINT is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sWithDC    VARCHAR2( 5000);
  sJoinAux   VARCHAR2( 5000);
BEGIN
  gSuplCols :=
    &apos;iesiriretail i, emulare e&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
      VAL,
      VALTVA,
      VAL_LEI,
      VALTVA_LEI,
      TipIncVal,
      TipInc,
      Intocmit_nume,
      Intocmit_prenume,
      Intocmit_CNP,
      Intocmit_BI,
      client_den,
      carnet_simbol,
      carnet_serie,
      carnet_den,
      client_codext,
      client_codfisc,
      client_reg,
      doc_nr,
      doc_data,
      sediu,
      sediu_adresa,
      sediu_loc,
      sediu_judet,
      sediu_tara,
      username&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
    MAN_IESIRI AS (
    SELECT
      I1.codiesretail,
      sum(I1.TVA) tva,
      sum(CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.RESTFACT ELSE I1.CANT*I1.PU END) VU
    FROM IESIRI1RETAIL I1
         INNER JOIN IESIRIRETAIL I ON I1.CODIESRETAIL = I.CODIESRETAIL
    WHERE NVL(I.ANULAT,0) = 0 AND I.DATACREARE BETWEEN TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAINI, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) AND
                                                    TO_DATE(&apos;&apos;&apos;||TO_CHAR(PKG_LIST_SELECTPERIOADA.DATAORAFIN, &apos;DD.MM.YYYY HH24:MI&apos;)||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY HH24:MI&apos;&apos;) 
    GROUP BY I1.CODIESRETAIL
    )
  SELECT
    mi.vu VAL, 
    mi.tva VALTVA,
    mi.vu * nvl(i.curs,1) VAL_LEI,
    mi.tva * nvl(i.curs,1) VALTVA_LEI,
    (SELECT string_agg(CASE
                         WHEN NVL(TIPPLATA,0) = 0 THEN &apos;&apos;CASH&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 1 THEN &apos;&apos;CEC&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 2 THEN &apos;&apos;CARD&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 3 THEN &apos;&apos;CREDIT&apos;&apos;
                       END||&apos;&apos;:&apos;&apos;||TO_CHAR(VALOARE)||&apos;&apos; &apos;&apos;)
     FROM MODPLATAIESRETAIL
     WHERE CODIESRETAIL = I.CODIESRETAIL) TipIncVal,
    (SELECT string_agg(CASE
                         WHEN NVL(TIPPLATA,0) = 0 THEN &apos;&apos;CASH&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 1 THEN &apos;&apos;CEC&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 2 THEN &apos;&apos;CARD&apos;&apos;
                         WHEN NVL(TIPPLATA,0) = 3 THEN &apos;&apos;CREDIT&apos;&apos;
                       END||&apos;&apos; &apos;&apos;)
     FROM MODPLATAIESRETAIL
     WHERE CODIESRETAIL = I.CODIESRETAIL) TipInc,
    Nvl(U.Nume,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_nume,
    Nvl(U.Prenume,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_prenume,
    Nvl(U.CNP,&apos;&apos;...nedefinit...&apos;&apos;) Intocmit_CNP,
    U.BISERIA||&apos;&apos; &apos;&apos;||U.BINR Intocmit_BI,
    P.DEN_PART client_den,
    CAR.SIMBOL carnet_simbol,
    I.SERIADOC carnet_serie,
    CAR.DENUMIRE carnet_den,
    P.CODEXTERN client_codext,
    CODF.CODFISCAL client_codfisc,
    P.REGCOM client_reg,
    I.NRDOC doc_nr,
    I.DATADOC doc_data,
    SFACT.Denumire sediu,
    GetAdresa(SFACT.sector, SFACT.strada, SFACT.nr1, SFACT.nr2, SFACT.bloc, SFACT.scara, SFACT.etaj, SFACT.apart, SFACT.codpostal) sediu_adresa,
    LFACT.DEN_LOCALIT sediu_loc,
    JFACT.Den_Judet sediu_judet,
    TFACT.Den_Tara sediu_tara, ut.username&apos;
    ||gUserAlias||&apos;
  FROM man_iesiri mi
    LEFT JOIN iesiriretail i ON i.codiesretail = mi.codiesretail
    LEFT JOIN emulare e on e.codiesretail = mi.codiesretail
    LEFT JOIN NCODFISCRETAIL CODF ON CODF.COD = I.CODFISCALRETAIL
    LEFT JOIN npart p ON p.codpart = i.partener
    LEFT JOIN NPERS U ON U.LOGONNAME = I.USERID
    LEFT JOIN DOCCARNETE CAR ON CAR.CODCARNET = I.CARNETDOC
    LEFT JOIN NSEDIIPARTRETAIL SFACT ON SFACT.CODSEDIU = I.CODSEDIURETAIL
    LEFT JOIN NLOCALIT LFACT ON LFACT.CODLOCALIT = NVL(SFACT.CODLOCALIT, 0)
    LEFT JOIN NJUDET JFACT ON JFACT.CODJUDET = NVL(LFACT.CODJUDET, 0)
    LEFT JOIN NTARI TFACT ON TFACT.CODTARA = NVL(LFACT.CODTARA, 0)
    left join tmp_utilizator ut on i.userid = ut.codutilizator &apos;||
    gSuplJoins;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_SITVANZRETSINT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E27C38BEBDBCBBDAC51D8DAB1175553CC2D13523</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SOLDPART IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  PKG_LIST_STRUCT.SetTableSpec(gSuplCols);
  PKG_LIST_STRUCT.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(30000);
  vAnLunaC  INTEGER;
  vAnPrec   INTEGER;
  vLunaPrec INTEGER;
  vDoarSub  BOOLEAN  := False;
BEGIN
  PRC_AL_CHECK(&apos;NPART1&apos;);
  PRC_AL_CHECK(&apos;IOPART1&apos;);
  
  gSuplCols := &apos;NPART P, NPART1 P1, NMONEDE MON, NCont C, NPERS AG&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_NomPart.SET_CODPART_SOLD_ANALIZAT(0);

  SELECT ancurent*12+lunacurenta INTO vAnLunaC FROM FirmaLuni;
  pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru,vAnPrec,vLunaPrec);
  pkg_globals.SetLunaPRECEDENTA(vAnPrec,vLunaPrec);
  pkg_globals.SetLunaTemp(pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru);

  IF pkg_globals.AnLunaLucru&gt;= vAnLunaC THEN
    PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
  END IF;

  IF pkg_globals.GetSubunitate &gt; 1 THEN
    vDoarSub := Nvl(pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetAnLucru,pkg_globals.GetLunaLucru),2) &lt;&gt; 2;
  END IF;

  --STEF constructie case x.icont ....
  --SELECT &apos;        WHEN &apos;||To_Char(column_id-1,&apos;00&apos;)||&apos; THEN io1.&apos;||Column_Name
  --FROM user_tab_columns
  --WHERE table_name = &apos;IOPART1&apos; AND column_name LIKE &apos;CONT%&apos; AND DATA_type = &apos;NUMBER&apos;
  --ORDER BY column_id

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(CODPART, PARTENER, Cont, SOLDL, SOLDV, RTVAL, RTVAV, MONEDA&apos;||gUserFields||&apos;)
  WITH
  iop1 AS (
    SELECT
      io1.codiopart, x.iCont,
      CASE x.iCont
        WHEN 02 THEN io1.ContFurnizor
        WHEN 03 THEN io1.ContClient
        WHEN 04 THEN io1.ContFurnAvans
        WHEN 05 THEN io1.ContClientAvans
        WHEN 06 THEN io1.ContFurnAVIZ
        WHEN 07 THEN io1.ContClientAVIZ
        WHEN 08 THEN io1.ContFurnMF
        WHEN 09 THEN io1.ContCreditD
        WHEN 10 THEN io1.ContDebitD
        WHEN 11 THEN io1.ContLitigii
        WHEN 12 THEN io1.ContFurnAVS
        WHEN 13 THEN io1.ContFurnAVIC
        WHEN 14 THEN io1.ContFurnAVIN
        WHEN 15 THEN io1.ContTerti
        WHEN 16 THEN io1.ContFurnLEAS
        WHEN 17 THEN io1.ContNCRF
        WHEN 18 THEN io1.ContNCRC
        WHEN 19 THEN io1.ContCheltAvans
        WHEN 20 THEN io1.ContVenitAvans
        WHEN 21 THEN io1.ContGarantieEF
        WHEN 22 THEN io1.ContGarantieTF
        WHEN 23 THEN io1.ContGarantieEC
        WHEN 24 THEN io1.ContGarantieTC
        WHEN 25 THEN io1.ContSuplimF1
        WHEN 26 THEN io1.ContSuplimF2
        WHEN 27 THEN io1.ContSuplimF3
        WHEN 28 THEN io1.ContSuplimF4
        WHEN 29 THEN io1.ContSuplimF5
        WHEN 30 THEN io1.ContSuplimC1
        WHEN 31 THEN io1.ContSuplimC2
        WHEN 32 THEN io1.ContSuplimC3
        WHEN 33 THEN io1.ContSuplimC4
        WHEN 34 THEN io1.ContSuplimC5
        WHEN 35 THEN io1.ContSuplimF6
        WHEN 36 THEN io1.ContSuplimF7
        WHEN 37 THEN io1.ContSuplimF8
        WHEN 38 THEN io1.ContSuplimF9
        WHEN 39 THEN io1.ContSuplimF10
        WHEN 40 THEN io1.ContSuplimF11
        WHEN 41 THEN io1.ContSuplimF12
        WHEN 42 THEN io1.ContSuplimF13
        WHEN 43 THEN io1.ContSuplimF14
        WHEN 44 THEN io1.ContSuplimF15
        WHEN 45 THEN io1.ContSuplimF16
        WHEN 46 THEN io1.ContSuplimF17
        WHEN 47 THEN io1.ContSuplimF18
        WHEN 48 THEN io1.ContSuplimF19
        WHEN 49 THEN io1.ContSuplimF20
        WHEN 50 THEN io1.ContSuplimF21
        WHEN 51 THEN io1.ContSuplimF22
        WHEN 52 THEN io1.ContSuplimF23
        WHEN 53 THEN io1.ContSuplimF24
        WHEN 54 THEN io1.ContSuplimF25
        WHEN 55 THEN io1.ContSuplimF26
        WHEN 56 THEN io1.ContSuplimF27
        WHEN 57 THEN io1.ContSuplimF28
        WHEN 58 THEN io1.ContSuplimF29
        WHEN 59 THEN io1.ContSuplimF30
      END codCont
    FROM 
      iopart1 io1 
      CROSS JOIN (SELECT level+1 iCont FROM DUAL connect by level &lt;= 58) x 
    WHERE pkg_globals.AnLunaLucru BETWEEN io1.ALStart and io1.ALStop
  )
  SELECT S.CODPART, P.DEN_PART, C.SIMBOL, S.SOLDLEI, S.SOLDVALUTA, S.RESTTVALEI, S.RESTTVAVALUTA, MON.DEN_MONEDA&apos;||gUserAlias||&apos;
  FROM &apos;||CASE WHEN vDoarSub THEN &apos;V_SOLDPARTSUB_EXT&apos; ELSE &apos;V_SOLDPART_EXT&apos; END||&apos; S
    INNER JOIN NPART   P    ON P.CODPART      = S.CODPART
    INNER JOIN NMONEDE MON  ON MON.CODMONEDA  = S.CODMONEDA
    LEFT  JOIN NPART1  P1   ON P1.CODPART     = P.CODPART    AND pkg_globals.AnLunaLucru BETWEEN P1.ALStart and P1.ALStop
    LEFT  JOIN IOP1         ON IOP1.CODIOPART = P1.CODIOPART AND IOP1.ICont = S.ICont
    LEFT  JOIN NCont   C    ON C.CODCont      = IOP1.CODCont
    LEFT  JOIN NAGENDA SSOC ON SSOC.CODPART   = S.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(ssoc.INACTIV, 0) = 0
    LEFT  JOIN NPERS   AG   ON AG.CODPERS     = SSOC.CODAGENT&apos;||
    gSuplJoins||&apos;
  WHERE (NVL(S.SOLDLEI,0) &lt;&gt; 0 OR NVL(S.SOLDVALUTA,0) &lt;&gt; 0)
    AND S.CODPART &lt;&gt; 0&apos;||CASE WHEN vDoarSub THEN &apos; AND S.SUBUNITATEA = &apos;||pkg_globals.GetSubunitate END;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
end PKG_LIST_BASE_SOLDPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SOLDPARTINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E4EFA4A8D0B61B744001ACA9DDA781A5F0E7A5F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SOLDPARTINI IS

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(30000);
  AnLunaIni     NUMBER;
  filtruPart    VARCHAR2(500);
BEGIN
  SELECT aninitial*12+lunainitiala INTO AnLunaIni FROM firmaluni;

  filtruPart := &apos; &apos;;
  IF NOT pkg_list_selpart.IsAllPart THEN
    filtruPart := &apos;
      AND O.CODPART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; ) &apos;;
  END IF;

--  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(
--    DEN_PART,DATADOC,NRDOC,MONEDA,SIMBOL,TERMEN,DEN_GEST,
--    SOLDLEI,SOLDVALUTA,PROVLEI,PROVVALUTA,
--    DEN_SUBUNIT,DIN_CARE_TVA,CURS,AGENT)
--  WITH crs_soldini AS(
--    SELECT
--      o.codpart,i.datadoc,i.nrdoc,g.moneda,g.curs,o.termen,o.codgest,i.subunitatea,o.semnificatie,o.icont,0 agent,
--      CASE WHEN g.moneda = 0 THEN o.valoare ELSE o.valoare * g.curs END soldlei,
--      CASE WHEN g.moneda = 0 THEN 0 ELSE  o.valoare END soldvaluta,
--      CASE WHEN O.SEMNIFICATIE IN (110,111,210,211,310,330,410,430,701,751) then g.tva ELSE 0 END tva,
--      Nvl(o.coefprovizion,0) coefprovizion
--    FROM intrari i
--      INNER JOIN general g ON g.coddoc = i.codintr AND g.tipdoc = i.tipdoc
--      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
--    WHERE i.an * 12 + i.luna &lt; &apos;||AnLunaIni||
--      filtruPart||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--    UNION ALL
--    SELECT
--      o.codpart,i.datadoc,i.nrdoc,g.moneda,g.curs,o.termen,o.codgest,i.subunitatea,o.semnificatie,o.icont,NVL(i.agent,0) agent,
--      CASE WHEN g.moneda = 0 THEN o.valoare ELSE o.valoare * g.curs END soldlei,
--      CASE WHEN g.moneda = 0 THEN 0 ELSE o.valoare END soldvaluta,
--      CASE WHEN O.SEMNIFICATIE IN (110,111,210,211,310,330,410,430,701,751) then g.tva ELSE 0 END tva,
--      Nvl(o.coefprovizion,0) coefprovizion
--    FROM iesiri i
--      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
--      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
--    WHERE i.an * 12 + i.luna &lt; &apos;||AnLunaIni||
--      filtruPart||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
--    UNION ALL
--    SELECT
--      o.codpart,t1.datadoc,t1.nrdoc,g.moneda,g.curs,o.termen,o.codgest,t.subunitatea,o.semnificatie,o.icont,COALESCE(t1.agent,t.agent,0) agent,
--      CASE WHEN g.moneda = 0 THEN o.valoare ELSE o.valoare * g.curs END soldlei,
--      CASE WHEN g.moneda = 0 THEN 0 ELSE o.valoare END soldvaluta,
--      CASE WHEN O.SEMNIFICATIE IN (110,111,210,211,310,330,410,430,701,751) then g.tva ELSE 0 END tva,
--      Nvl(o.coefprovizion,0) coefprovizion
--    FROM trezor t
--      INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
--      INNER JOIN general g ON g.coddoc = t1.codtrezor1  AND g.tipdoc IN (29,30,31)
--      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
--    WHERE t1.initializari = 1
--      AND t1.an * 12 + t1.luna &lt; &apos;||AnLunaIni||
--      filtruPart||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;)
--  SELECT
--    np.den_part, crs.datadoc, crs.nrdoc, mon.simbol moneda, nc.simbol, crs.termen, ng.den_gest,
--    crs.soldlei, crs.soldvaluta, crs.soldlei*crs.coefprovizion, crs.soldvaluta*crs.coefprovizion,
--    sub.den_subunit, crs.tva, crs.curs,
--    DECODE(crs.agent,0,ag.nume,ag.nume||&apos;&apos; &apos;&apos;||ag.prenume) agent
--  FROM crs_soldini crs
--    LEFT JOIN npart np ON np.codpart = crs.codpart
--    LEFT JOIN ngest ng ON crs.codgest = ng.codgest
--    LEFT JOIN nsubunit sub ON crs.subunitatea = sub.codsubunit
--    LEFT JOIN nmonede mon ON mon.codmoneda = crs.moneda
--    LEFT JOIN ncont nc ON nc.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(crs.icont,crs.codpart,&apos;||AnLunaIni||&apos;,crs.semnificatie)
--    LEFT JOIN npers ag ON ag.codpers = crs.agent&apos;;

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DEN_PART,DATADOC,NRDOC,MONEDA,SIMBOL,TERMEN,DEN_GEST,
    SOLDLEI,SOLDVALUTA,PROVLEI,PROVVALUTA,
    DEN_SUBUNIT,DIN_CARE_TVA,CURS,AGENT)
  WITH crs_soldini AS(
    SELECT
      o.codpart, o.termen, o.codgest, o.semnificatie, o.icont, Nvl(o.coefprovizion,0) coefprovizion, Nvl(g.moneda,0) moneda, DECODE(g.curs,0,1,null,1,g.curs) curs,
      COALESCE(dvi.datadoc, intr.datadoc, ies.datadoc, t1.datadoc, nc.datadoc, c.datadoc) datadoc,  
      COALESCE(dvi.nrdoc, intr.nrdoc, ies.nrdoc, t1.nrdoc, nc.nrdoc, c.nrdoc) nrdoc,  
      COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea) subunitatea,  
      COALESCE(ies.agent, t1.agent,t.agent,0) agent,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 130) THEN -OL.REST
        WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2 THEN -OL.REST
        WHEN O.SEMNIFICATIE = 110 THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120 THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 200 THEN OL.REST
        WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
        WHEN O.SEMNIFICATIE = 210 THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 220 THEN (OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (310, 330) THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (2, 5, 6, 8, 9, 15, 16, 17, 20, 25, 26, 27, 28, 29) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14, 19, 30, 31, 32, 33, 34) THEN OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5, 8, 9, 15, 18) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)  AND O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14, 17) THEN OL.REST
      END SOLD,
      CASE
        WHEN O.SEMNIFICATIE = 110 THEN NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120 THEN -NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 210 THEN -NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 220 THEN  NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (310, 330) THEN NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -NVL(OL.RESTTVA, 0)
        ELSE 0
      END TVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN DVI ON DVI.CODDVI = G.CODDOC AND G.TIPDOC = 5 AND O.SEMNIFICATIE = 130
      LEFT JOIN INTRARI INTR ON INTR.CODINTR = NVL(DVI.CODINTR,G.CODDOC) AND INTR.TIPDOC = G.TIPDOC AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140)
      LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC AND O.SEMNIFICATIE IN (200, 210, 220, 240)
      LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND O.SEMNIFICATIE IN (310, 330, 410, 430)  
      LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR  
      LEFT JOIN NC1 ON NC1.CODNC1 = G.CODDOC AND O.SEMNIFICATIE IN (1200, 1201)  
      LEFT JOIN NC ON NC.CODNC = NC1.CODNC  
      LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND O.SEMNIFICATIE IN (1301, 1351, 1303)  
    WHERE OL.REST &lt;&gt; 0
      AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      AND OL.AN *12+OL.LUNA+1 = &apos;||AnLunaIni||
      filtruPart||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;COALESCE(intr.subunitatea, ies.subunitatea, t.subunitatea, nc.subunitatea, c.subunitatea)&apos;)||&apos;)
  SELECT
    np.den_part, crs.datadoc, crs.nrdoc, mon.simbol moneda, nc.simbol, crs.termen, ng.den_gest,
    crs.sold*crs.curs, crs.sold, crs.sold*crs.curs*crs.coefprovizion, crs.sold*crs.coefprovizion,
    sub.den_subunit, crs.tva, crs.curs,
    DECODE(crs.agent,0,ag.nume,ag.nume||&apos;&apos; &apos;&apos;||ag.prenume) agent
  FROM crs_soldini crs
    LEFT JOIN npart np ON np.codpart = crs.codpart
    LEFT JOIN ngest ng ON crs.codgest = ng.codgest
    LEFT JOIN nsubunit sub ON crs.subunitatea = sub.codsubunit
    LEFT JOIN nmonede mon ON mon.codmoneda = crs.moneda
    LEFT JOIN ncont nc ON nc.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(crs.icont,crs.codpart,&apos;||AnLunaIni||&apos;,crs.semnificatie)
    LEFT JOIN npers ag ON ag.codpers = crs.agent&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_soldpartini;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42A0901C9CDB34D6286945345EC8AF48C6AAC8D1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOC IS

  gUserFields VARCHAR2(10000);
  gUserAlias  VARCHAR2(10000);
  gNullAlias  VARCHAR2(10000);
  gSuplCols   VARCHAR2(10000);
  gSuplJoins  VARCHAR2(20000);

FUNCTION GetFurn (pCodObiect NUMBER, pCodNirstoc NUMBER, pFurn NUMBER) RETURN NUMBER IS
  vRES NUMBER;
BEGIN
  IF pCodNirstoc IS NOT NULL THEN
    vRES := pFurn;
  ELSE
    SELECT Max(Furn) KEEP (Dense_Rank LAST ORDER BY DATAACHIZ, CODNIRSTOC) INTO vRES FROM NirStoc WHERE CodObiect = pCodObiect;
  END IF;
  RETURN Coalesce(vRES, 0);
END;

PROCEDURE PregatireSerii IS
BEGIN
  DELETE FROM TMP_MANEVRA_SERII;
  DELETE FROM TMP_MANEVRA_NIRSER;

  IF pkg_list_selfisamag.areSerii THEN
    IF pkg_list_selfisamag.StocLaZi THEN
      INSERT INTO TMP_MANEVRA_NIRSER(CODNIRSER, CODNIRSTOC, TIPSERIE, TG, SERIE, REST)
      SELECT NSER.CodNirSer, NSER.CodNirStoc, NS.TipSerie, Coalesce(NSER.TG, NS.TG), S.Serie, NSER.Rest
      FROM nirstoc ns
        INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
        INNER JOIN nserii s ON s.codserie = nser.codserie
      WHERE ( PKG_LIST_SELFISAMAG.isToateArt = 1      OR NS.CODOBIECT IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos;) )
        AND ( PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART  IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; ) );
    ELSE
      INSERT INTO TMP_MANEVRA_NIRSER(CODNIRSER, CODNIRSTOC, TIPSERIE, TG, SERIE, REST)
      WITH S AS (
        SELECT NSER.CodNirSer, NSER.CodNirStoc, NS.TipSerie, Coalesce(NSER.TG, NS.TG) TG, S.Serie, NSER.CANTNIR REST
        FROM nirstoc ns
          INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
          INNER JOIN nserii s ON s.codserie = nser.codserie
        WHERE ( PKG_LIST_SELFISAMAG.isToateArt = 1      OR NS.CODOBIECT IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos;) )
          AND ( PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART  IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; ) )
        UNION ALL
        SELECT NSER.CodNirSer, NSER.CodNirStoc, NS.TipSerie, Coalesce(NSER.TG, NS.TG) TG, S.Serie, Decode(L.TIPLIVR,15,1,-1) * L1.CANT REST
        FROM livr l
          INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
          INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
          INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
          INNER JOIN nserii s ON s.codserie = nser.codserie
        WHERE ( PKG_LIST_SELFISAMAG.isToateArt = 1      OR NS.CODOBIECT IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos;) )
          AND ( PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART  IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; ) )
      )
      SELECT * FROM (
        SELECT CODNIRSER, CODNIRSTOC, TIPSERIE, TG, SERIE, Sum(REST) REST
        FROM S
        GROUP BY CODNIRSER, CODNIRSTOC, TIPSERIE, TG, SERIE )
      WHERE REST &lt;&gt; 0;
    END IF;
    pkg_list_base_utils.baga_serii_in_tmp(pkg_list_base_utils.CT_STOC_M);
  END IF;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_List_Struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert         CLOB;
  sInsTmpFields   CLOB;
  sInsTmp         CLOB;
  sUpdTmp         CLOB;
  sInsTmpNedesIes CLOB;
  sInsTmpNedesIn  CLOB;
  sInsTmpNedesTr  CLOB;
  sCursRef      VARCHAR2( 2000) := &apos;, 1 curs_ref, 1 curs_refa&apos;;
  sInsDC        VARCHAR2( 2000);
  sSelDC        VARCHAR2( 2000);
  sJoinDC       VARCHAR2( 2000);
  aSitV         NUMBER(1);
  aBancaV       NUMBER(20);
  aMonedaV      NUMBER(20);
  sSubunitate   VARCHAR2(  100) := CASE PKG_GLOBALS.GETSUBUNITATE WHEN 1 THEN &apos;ng.codsubunit&apos; ELSE To_Char(PKG_GLOBALS.GETSUBUNITATE) END;
  DataStoc      DATE            := pkg_list_selfisamag.getDataStoc;
  AnLunaMin     NUMBER(5);
  AnLunaMax     NUMBER(5);
  AnLunaLista   NUMBER(5);
  AnLista       NUMBER(4);
  LunaLista     NUMBER(2);
  AnPrec        NUMBER(4);
  LunaPrec      NUMBER(2);
  vMaxCl        INTEGER;
  vTabla1       VARCHAR2(100)   := &apos;tmp_lst_stoc s&apos;;
  vTabla2       VARCHAR2(100)   := &apos;nartobj nobj&apos;;
  sJoinRezUM1   VARCHAR2(1000);
  sColRezUM1    VARCHAR2(100);
  vCount        INTEGER;
  sVal          VARCHAR2(100);
  sLimbaDenArt  VARCHAR2(100)   := Coalesce(pkg_categconst.GetValConstanta(&apos;LimbaDenArt&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),&apos;0&apos;);
  vGestAcces    INTEGER;
  sALL          VARCHAR2(5)     := To_Char (PKG_GLOBALS.AnLunaLucru,&apos;fm99999&apos;);
  sTipPMP       VARCHAR2(1);
  sNeconforme   VARCHAR2(100)   := &apos;&apos;;
  sDebug        CLOB;
BEGIN
  --pkg_globals.setdebugmode(TRUE);
  vGestAcces := to_number(Coalesce(pkg_categconst.GetValConstanta(&apos;GestAccesListeStoc&apos;,pkg_globals.GETANLUCRU,pkg_globals.getlunalucru),&apos;2&apos;));
  gSuplCols  :=
    &apos;NART1 NART1, NARTOBJ NOBJ, NGEST NG, NART NART, NPART PROD, NUM NUM, NUM1 NUM1, NARTOBJ1 NOBJ1, NSUBUNIT SUB, NPART FURN, NMONEDE MDOC,&apos;||
    &apos;NLOCATII NLOC, NCONT NCONT, NUM UMALT1, NUM UMALT2, NCLASEAS NCLS, NGEST NGPROD, NCLASEA NCLA, IOART IO, TMP_LST_STOC S&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTVA&apos;,           &apos;NTVA&apos;,         &apos;NTVA.CODTVA = NART1.CODTVA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTAMB&apos;,        &apos;AA&apos;,           &apos;AA.CODOBIECT = NOBJ.CODOBIECT AND AA.UMSEC = num1.codum1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;,     &apos;OEXT&apos;,         &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;,     &apos;OATR&apos;,         &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJTRAD&apos;,    &apos;TRAD&apos;,         &apos;TRAD.CODOBIECT = NOBJ.CODOBIECT AND TRAD.CODLIMBA = &apos;||sLimbaDenArt);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ1&apos;,       &apos;NOBJ1_CURENT&apos;, &apos;NOBJ1_CURENT.CODOBIECT = NOBJ.CODOBIECT AND &apos;||sALL||&apos; BETWEEN NOBJ1_CURENT.ALSTART AND NOBJ1_CURENT.ALSTOP&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,          &apos;PM&apos;,           &apos;PM.CODOBIECT = NOBJ.CODOBIECT AND PM.IMPLICIT = 1 AND PM.SUBUNITATEA = &apos;||sSubunitate);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJSUBUNIT&apos;, &apos;NOBJSUB&apos;,      &apos;NOBJSUB.CODOBIECT = NOBJ.CODOBIECT AND (NOBJSUB.codgest is NULL or NOBJSUB.codgest = 0) AND NOBJSUB.SUBUNITATE = &apos;||sSubunitate);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCARSUPART&apos;,     &apos;NCARSUPART&apos;,   &apos;NCARSUPART.CODCARSUPART = NOBJ.CODCARACT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;,     &apos;CCINTR&apos;,       &apos;CCINTR.CODCENTRU = Coalesce(S.ROOTCC,0)&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IOART1&apos;,         &apos;IO1_CURENT&apos;,   &apos;IO1_CURENT.CODIOART = IO.CODIOART AND &apos;||sALL||&apos; BETWEEN IO1_CURENT.ALSTART AND IO1_CURENT.ALSTOP&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCONT&apos;,          &apos;C_CURENT&apos;,     &apos;C_CURENT.CODCONT = IO1_CURENT.CONT&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF&apos;,         &apos;XTR&apos;,          &apos;XTR.CODTRANSF = S.XCODTRANSF&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSFEXT&apos;,      &apos;XTREXT&apos;,       &apos;XTREXT.CODTRANSF = XTR.CODTRANSF&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,        &apos;XINTR&apos;,        &apos;XINTR.CODINTR = S.XCODINTR&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIF&apos;,       &apos;XINTRF&apos;,       &apos;XINTRF.CODINTR = XINTR.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARIP&apos;,       &apos;XINTRP&apos;,       &apos;XINTRP.CODINTR = XINTR.CODINTR&apos;);

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,         &apos;XIES&apos;,         &apos;XIES.CODIES = S.XCODIES&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRIEXT&apos;,      &apos;XIESEXT&apos;,      &apos;XIESEXT.CODIES = XIES.CODIES&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, s.datadoc) curs_ref,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, s.IntratLa) curs_refa&apos;;
  END IF;

  IF PKG_LIST_SELFISAMAG.inclArtStoc0 THEN
    vTabla1 := &apos;nartobj nobj&apos;;
    vTabla2 := &apos;tmp_lst_stoc s&apos;;
  END IF;

  IF PKG_LIST_SELFISAMAG.exclNeconform then
    sNeconforme := &apos; and coalesce(ng.tip,0) &lt;&gt; 4 &apos;;
  END IF;

  sJoinRezUM1 := &apos;&apos;;
  sColRezUM1  := &apos;NULL rezervatum1,&apos;;
  IF PKG_LIST_SELFISAMAG.RezUM1 THEN
    sColRezUM1  := &apos;rum1.cant rezervatum1,&apos;;
    sJoinRezUM1 := &apos;
    LEFT JOIN (
      SELECT Sum(pkg_jurnal.GetSpecificCantUM1(Coalesce(art.relatieum1,0), ns.D1, ns.D2, ns.D3, r.rest)) cant, ns.codnirstoc, Coalesce(nse.codnirser,0) codnirser
      FROM nirstoc ns
        INNER JOIN nartobj   obj ON obj.codobiect = ns.codobiect
        INNER JOIN nart      art ON art.codarticol = obj.codarticol
        LEFT  JOIN nirser    nse ON nse.codnirstoc = ns.codnirstoc
        LEFT  JOIN rezervats r   ON ns.codnirstoc = r.codnirstoc AND Coalesce(nse.codnirser,0) = Coalesce(r.codnirser,0)
      GROUP BY ns.codnirstoc, Coalesce(nse.codnirser,0)
    ) RUM1 ON RUM1.CODNIRSTOC = NS.CODNIRSTOC AND RUM1.CODNIRSER = Coalesce(NSER.CODNIRSER,0)&apos;;
  END IF;

  SELECT AnMaxim*12+LunaMaxima, AnInitial*12+LunaInitiala INTO AnLunaMax, AnLunaMin FROM firmaluni;

  IF pkg_list_selfisamag.StocLaZi THEN
    AnLunaLista := AnLunaMax;
  ELSE
    AnLunaLista := EXTRACT(YEAR FROM DataStoc)*12 +EXTRACT(MONTH FROM DataStoc);
    IF    AnLunaLista &lt; AnLunaMin THEN AnLunaLista := AnLunaMin;
    ELSIF AnLunaLista &gt; AnLunaMax THEN AnLunaLista := AnLunaMax;
    END IF;
  END IF;
  PKG_LIST_BASE_UTILS.ExtractAnLuna(AnLunaLista,AnLista,LunaLista);
  pkg_globals.SetLunaTemp(AnLista,LunaLista);
  pkg_globals.Calculeaza_Luna_Precedenta(AnLista,LunaLista,AnPrec,LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);

  sDebug := &apos;BEGIN&apos;||Chr(10)||
            &apos;  pkg_globals.SetLunaTemp(&apos;||AnLista||&apos;,&apos;||LunaLista||&apos;);&apos;||Chr(10)||
            &apos;  pkg_globals.SetLunaPRECEDENTA(&apos;||AnPrec||&apos;,&apos;||LunaPrec||&apos;);&apos;||Chr(10)||
            &apos;END;&apos;;
  PKG_GLOBALS.CheckDebugMode(sDebug, aLISTID, aLISTVER);

  sTipPMP := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;TipPMP&apos;, AnLista, LunaLista), &apos;1&apos;);

  PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;s.rest&apos;,&apos;s.CodObiect&apos;,sInsDC,sSelDC,sJoinDC);

  vMaxCl := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;
  IF vMaxCL &gt; 0 THEN
    sJoinDC := sJoinDC||&apos;
    LEFT JOIN (
      SELECT
        CODCLASEA &apos;;

    FOR i in 1..vMaxCL loop
      sInsDC  := sInsDC||&apos;, CL&apos;||to_char(i)  ||&apos;, CS&apos;||to_char(i);
      sSelDC  := sSelDC||&apos;, CL.D&apos;||to_char(i)||&apos;, CL.S&apos;||to_char(i);
      sJoinDC := sJoinDC ||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE &apos;&apos;&apos;&apos; end) D&apos;||to_char(i)||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN simbol ELSE &apos;&apos;&apos;&apos; end) S&apos;||to_char(i);
    END LOOP;

    sJoinDC := sJoinDC||&apos;
      FROM TMP_PROFIT_NCLASEA
      GROUP BY CODCLASEA
    ) CL ON CL.CodClasea = NART.Clasa &apos;;
  END IF;

  sInsTmpFields :=
  &apos;INSERT INTO tmp_lst_stoc (
    codnirstoc, codnirser, codcertif, coddoc, tipdoc, codlocatie, gest, codgestprod, umsec, codioart, codobiect,
    intratla, anluna,
    datadoc, nrdoc, prefixdoc,
    nridoc, obsdoc, obsdoc1,
    doc, xcodtransf, xcodies, xcodintr,
    pret, pretachiz, pumaximal, adaosunitar,
    procentadaos,
    tva, tipserie, furn, codioart1, aretvaneex, mg, cont,
    d1, d2, d3, provizion, serielot, puval, prdoc, monedadoc,
    rezervat, rezervatum1, rest, restum1, restum2,
    cantser,
    serie, obsser, nrcertifser, dataprimire, dataprod, provenienta, den_tara, obscertif, stare,
    tg, zileexp,
    staredd,
    rootcc, pretorig, cursdoc
  )&apos;;

  sInsTmp := sInsTmpFields||&apos;
  SELECT
    ns.codnirstoc, nser.codnirser, c.codcertif, COALESCE(ies.codies, t.codtransf, intr.codintr) coddoc, n.tipnir tipdoc, ns.codlocatie, n.gest, ns.codgestprod, ns.umsec, ns.codioart, ns.codobiect,
    COALESCE(ns.dataachiz, n.datanir, intr.datadoc) IntratLa, COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) AnLuna,
    COALESCE(ies.datadoc,t.datadoc,intr.datadoc) datadoc, COALESCE(ies.nrdoc,t.nrdoc,intr.nrdoc) nrdoc, COALESCE(ies.prefixdoc,t.prefixdoc,intr.prefixdoc) prefixdoc,
    COALESCE(ies.nri,intr.nri) nridoc, COALESCE(ies.obs,t.obs,intr.obs) obsdoc,COALESCE(ies1.obs,dbms_lob.substr(t1.obs,500,1),intr1.obs) obsdoc1,
		CASE
      WHEN n.tipnir IN (12, 13)      THEN t.prefixdoc   ||&apos;&apos;.&apos;&apos;||t.nrdoc   ||&apos;&apos;/&apos;&apos;||TO_CHAR(t.datadoc   ,&apos;&apos;DD.MM.YYYY&apos;&apos;)
			WHEN n.tipnir IN (14,15,19,20) THEN ies.prefixdoc ||&apos;&apos;.&apos;&apos;||ies.nrdoc ||&apos;&apos;/&apos;&apos;||TO_CHAR(Ies.datadoc ,&apos;&apos;DD.MM.YYYY&apos;&apos;)
			ELSE                                intr.prefixdoc||&apos;&apos;.&apos;&apos;||intr.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(intr.datadoc,&apos;&apos;DD.MM.YYYY&apos;&apos;)
		END doc,
    CASE WHEN n.tipnir IN (12, 13)      THEN t.codtransf  ELSE 0 END xcodtransf,
    CASE WHEN n.tipnir IN (14,15,19,20) THEN ies.codies   ELSE 0 END xcodies,
    CASE WHEN n.tipnir = intr.tipdoc    THEN intr.codintr ELSE 0 END xcodintr,
    ns.pret, ns.pret - Coalesce(ns.adaos,0) pretachiz, ns.pumaximal, CASE WHEN (ioa1.difpret = 1) and (ioa1.aretvaneex = 1) THEN (ns.adaos -((ns.PRET*ns.tva*100)/(100+ns.tva*100))) ELSE ns.adaos END adaosunitar,
    Round(
      CASE
        WHEN ioa1.difpret &lt;&gt; 1   THEN 0
        WHEN ioa1.aretvaneex = 0 THEN 100*(Coalesce(ns.adaos,0))/decode((ROUND(ns.pret,4) - ROUND(Coalesce(ns.adaos,0),4)),0,1,(ns.pret - Coalesce(ns.adaos,0)))
        WHEN ioa1.aretvaneex = 1 THEN 100*(ns.pret/(1+ns.tva)-(ROUND(ns.pret,4) - ROUND(COALESCE(ns.adaos,0),4)))/decode ((ROUND(ns.pret,4) - ROUND(COALESCE(ns.adaos,0),4)),0,1,(ns.pret - ns.adaos) )
        WHEN ioa1.aretvaneex = 2 THEN 100*((ROUND(ns.pret,4)-(ROUND(Coalesce(ns.adaos,0),4)/(1+ns.tva) )-(ROUND(ns.pret,4) - ROUND(Coalesce(ns.adaos,0),4)))/decode((ROUND(ns.pret,4) - ROUND(Coalesce(ns.adaos,0),4)),0,1,(ns.pret - Coalesce(ns.adaos,0))))
      END,2) procentadaos,
    CASE WHEN (IOA1.DIFPRET = 1) AND (IOA1.ARETVANEEX = 1) THEN ns.TVA*100 ELSE 0 END tva, ns.tipserie, ns.furn, ioa1.codioart1,ioa1.aretvaneex, ioa1.mg, ioa1.cont,
    ns.d1,ns.d2,ns.d3,ns.provizion, ns.serielot,ns.puval,COALESCE(intr1root.pu,intr1.pu,ies1.pu,t1.pu) prdoc, COALESCE(intrroot.moneda, intr.moneda, ies.moneda, 0) monedadoc,
	  (SELECT SUM(Coalesce(r.rest,0)) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC AND Coalesce(R.CODNIRSER,0) = COALESCE(NSER.CODNIRSER,R.CODNIRSER,0) AND Coalesce(R.REST,0) &lt;&gt; 0) rezervat,
    &apos;||sColRezUM1||&apos;
    &apos;|| CASE WHEN pkg_list_selfisamag.StocLaZi THEN &apos;Coalesce(NSER.REST,NS.REST)&apos; ELSE &apos;VS.REST&apos; END||&apos; REST,
    &apos;|| CASE WHEN pkg_list_selfisamag.StocLaZi THEN &apos;Coalesce(NSER.RESTUM1,NS.RESTUM1)&apos; ELSE &apos;VS.RESTUM1&apos; END||&apos; RESTUM1,
    &apos;|| CASE WHEN pkg_list_selfisamag.StocLaZi THEN &apos;Coalesce(NSER.RESTUM2,NS.RESTUM2)&apos; ELSE &apos;VS.RESTUM2&apos; END||&apos; RESTUM2,
    &apos;|| CASE WHEN NOT pkg_list_selfisamag.StocLaZi AND pkg_list_selfisamag.areSerii THEN &apos;VS.REST&apos; ELSE &apos;NSER.REST&apos; END||&apos; CANTSER,
    SER.SERIE, NSER.OBS OBSSER, C.NRCERTIF NRCERTIFSER, C.DATAPRIMIRE, NSER.DATAPROD, C.PROVENIENTA, TARA.DEN_TARA, C.OBS OBSCERTIF,
    CASE NSER.STARE
      WHEN  1 THEN &apos;&apos;Liber&apos;&apos;
      WHEN  2 THEN &apos;&apos;Restrictionat DI&apos;&apos;
      WHEN  3 THEN &apos;&apos;Restrictionat DD&apos;&apos;
      WHEN  4 THEN &apos;&apos;Blocat&apos;&apos;
      WHEN  5 THEN &apos;&apos;Complet-verificat&apos;&apos;
      WHEN  6 THEN &apos;&apos;Complet-neverificat&apos;&apos;
      WHEN  7 THEN &apos;&apos;Incomplet-verificat&apos;&apos;
      WHEN  8 THEN &apos;&apos;Incomplet-neverificat&apos;&apos;
      WHEN  9 THEN &apos;&apos;Aprobat cant si dim&apos;&apos;
      WHEN 10 THEN &apos;&apos;Aprobat documentatie&apos;&apos;
    END stare,
    Coalesce(nser.tg,ns.tg) tg, Coalesce(nser.tg,ns.tg) - pkg_list_selfisamag.getDataRef zileexp,
    CASE
      WHEN (Coalesce(nser.tg,ns.tg) - pkg_list_selfisamag.getDataRef &gt; 30) OR Coalesce(nser.tg,ns.tg) IS NULL THEN &apos;&apos;Liber&apos;&apos;
      WHEN Coalesce(nser.tg,ns.tg) - pkg_list_selfisamag.getDataRef &lt; 0 THEN &apos;&apos;Blocat&apos;&apos;
      ELSE &apos;&apos;Restrictionat&apos;&apos;
    END staredd,
    COALESCE(intr1root.codcentru,intr1.codcentru,ies1.codcentru,t1.codcentru) rootcc, Coalesce(intr1.pu,ies1.pu,t1.pu) pretorig, Decode(Coalesce(intr.curs,ies.curs,0), 0, 1, Coalesce(intr.curs,ies.curs,0)) cursdoc
  FROM &apos;;

  IF pkg_list_selfisamag.StocLaZi THEN
    sInsTmp := sInsTmp||&apos;nirstoc ns &apos;;
  ELSE
    sInsTmp := sInsTmp||CASE WHEN pkg_list_selfisamag.areSerii THEN &apos;v_stoc_luna_ser&apos; ELSE &apos;v_stoc_luna&apos; END||&apos; vs
    INNER JOIN nirstoc ns ON ns.codnirstoc = vs.codnirstoc&apos;;
  END IF;
  sInsTmp := sInsTmp||&apos;
    INNER JOIN nir n ON n.codnir = ns.codnir
  	INNER JOIN ngest ng ON ng.codgest = n.gest&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
	  LEFT JOIN intrari intr ON intr.codintr = n.codintr AND intr.tipdoc = n.tipnir
    LEFT JOIN dvi1 ON dvi1.coddvi1 = ns.coddvi1
	  LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr AND intr1.codintr1 = Coalesce(dvi1.codintr1,ns.codintr1)
	  LEFT JOIN transf t ON t.codtransf = n.codtransf AND t.tipdoc = n.tipnir
	  LEFT JOIN transf1 t1 ON t1.codtransf = n.codtransf AND t1.codtransf1 = ns.codtransf1
	  LEFT JOIN iesiri ies ON ies.codies = n.codies AND ies.tipdoc = n.tipnir
    LEFT JOIN livr l ON l.codies = n.codies AND l.codlivr = n.codnir
    LEFT JOIN livr1 l1 ON l1.codlivr = l.codlivr AND l1.codnirstoc = ns.codnirstoc AND (l1.cant &lt; 0 OR n.tipnir = 15)
	  LEFT JOIN iesiri1 ies1 ON ies1.codies1 = l1.codies1
    LEFT JOIN nirstoc1 ns1 ON ns1.codnirstoc = NS.CodNirStoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocOrig
    LEFT JOIN nir nroot ON nroot.codnir = nsroot.codnir
	  LEFT JOIN intrari intrroot ON intrroot.codintr = nroot.codintr AND intr.tipdoc = nroot.tipnir
    LEFT JOIN dvi1 dvi1root ON dvi1root.coddvi1 = nsroot.coddvi1
	  LEFT JOIN intrari1 intr1root ON intr1root.codintr = intrroot.codintr AND intr1root.codintr1 = Coalesce(dvi1root.codintr1,nsroot.codintr1)
    LEFT JOIN nirser nser ON &apos;||
      CASE
        WHEN NOT pkg_list_selfisamag.areSerii THEN &apos;nser.codnirser  = (ns.codnirstoc - ns.codnirstoc)&apos;
        WHEN pkg_list_selfisamag.STOCLAZI     THEN &apos;nser.codnirstoc = ns.codnirstoc&apos;
        ELSE                                       &apos;nser.codnirser  = vs.codnirser&apos;
      END||
    sJoinRezUM1||&apos;
    LEFT JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT JOIN certif c ON c.codcertif = nser.codcertif
    LEFT JOIN ntari tara ON tara.codtara = c.codtara
   	LEFT JOIN ioart1 ioa1 ON ioa1.codioart = ns.codioart AND COALESCE(intr.an*12+intr.luna,ies.an*12+ies.luna,t.an*12+t.luna) BETWEEN ioa1.alstart AND ioa1.alstop
  WHERE &apos;||
    CASE
      WHEN NOT pkg_list_selfisamag.StocLaZi THEN &apos;(COALESCE(VS.REST,0) &lt;&gt; 0 OR COALESCE(VS.RESTUM2,0) &lt;&gt; 0)&apos;
      WHEN pkg_list_selfisamag.areSerii     THEN &apos;(COALESCE(NSER.REST,NS.REST,0) &lt;&gt; 0 OR COALESCE(NSER.RESTUM2,NS.RESTUM2,0) &lt;&gt; 0)&apos;
      ELSE                                       &apos;(COALESCE(NS.REST,0) &lt;&gt; 0 OR COALESCE(NS.RESTUM2,0) &lt;&gt; 0)&apos;
    END||&apos;
    AND ioa1.mg &lt;&gt; 5
    AND (ies1.codies IS NULL OR ies1.codies = n.codies)
    AND (l.codlivr IS NULL OR l1.codlivr = l.codlivr)&apos;;
    if vGestAcces &lt;&gt; 1 then
      sInsTmp := sInsTmp||&apos; AND PKG_NOMGEST.GESTIUNE_DEDICATA(N.GEST) &gt; 0 &apos;;
    end if;
    sInsTmp := sInsTmp||sNeconforme;

  if NOT PKG_LIST_SELFISAMAG.isAllTipCont THEN
    SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODIOART&apos; ;
    sInsTmp := sInsTmp||&apos;
    AND NS.CODIOART &apos;;
    IF vCount = 1
    THEN sInsTmp := sInsTmp||&apos;= &apos;||sVal;
    ELSE sInsTmp := sInsTmp||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
    END IF;
  END IF;

  IF NOT PKG_LIST_SELFISAMAG.isAllGest THEN
    SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; ;
    sInsTmp := sInsTmp||&apos;
    AND N.GEST &apos;;
    IF vCount = 1
    THEN sInsTmp := sInsTmp||&apos;= &apos;||sVal;
    ELSE sInsTmp := sInsTmp||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    END IF;
  END IF;

  IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
    SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos; ;
    sInsTmp := sInsTmp||&apos;
    AND NS.CODOBIECT &apos;;
    IF vCount = 1
    THEN sInsTmp := sInsTmp||&apos;= &apos;||sVal;
    ELSE sInsTmp := sInsTmp||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
    END IF;
  END IF;

  if PKG_LIST_SELFISAMAG.inclNedes then
    sInsTmpNedesIes := sInsTmpFields||&apos;
    SELECT
      0 codnirstoc, 0 codnirser, 0 codcertif, i.codies coddoc, i.tipdoc, 0 codlocatie, lv.gest, i.codgestprod, i1.umsec, lv.codioart, lv.codobiect,
      i.datadoc IntratLa, i.an*12+i.luna AnLuna,
      i.datadoc, i.nrdoc, i.prefixdoc,
      i.nri nridoc, i.obs obsdoc,i1.obs obsdoc1,
      i.prefixdoc||&apos;&apos;.&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(I.datadoc,&apos;&apos;DD.MM.YYYY&apos;&apos;) doc, 0 xcodtransf, 0 xcodies, 0 xcodintr,
      lv.pretinreg, lv.pretachiz, NULL pumaximal, lv.pretinreg - lv.pretachiz adaosunitar,
      CASE WHEN coalesce(lv.pretinreg,0) = 0 THEN 0 ELSE (lv.pretinreg - lv.pretachiz)/lv.pretinreg *100 END procentadaos,
      i1.tva, 0 tipserie, 0 furn, ioa1.codioart1,ioa1.aretvaneex, ioa1.mg, ioa1.cont,
      NULL d1, NULL d2, NULL d3, NULL provizion, NULL serielot, 0 puval, NULL prdoc, 0 monedadoc,
      0 rezervat, NULL rezervatum1, -L1.RESTIESVAL REST, 0 RESTUM1, 0 RESTUM2,
      0 CANTSER,
      NULL SERIE, NULL OBSSER, NULL NRCERTIFSER, NULL DATAPRIMIRE, NULL DATAPROD, NULL PROVENIENTA, NULL DEN_TARA, NULL OBSCERTIF, NULL stare,
      NULL tg, 0 zileexp,
      NULL staredd,
      0 rootcc, i1.pu pretorig,i.curs
    FROM LIVRVAL LV,
         LIVR1 L1,
         LIVR L,
         IESIRI1 I1,
         IESIRI I,
         IOART1 IOA1,
         NARTOBJ O,
         NART A,
         NGEST G
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1 AND
      L1.CODIES1 = I1.CODIES1 AND
      L.CODLIVR = L1.CODLIVR AND
      L.TIPLIVR &lt;&gt; 12 AND
      L.TIPLIVR &lt;&gt; 13 AND
      I.CODIES = L.CODIES AND
      IOA1.CODIOART = LV.CODIOART AND I.AN*12+I.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND
      O.CODOBIECT = LV.CODOBIECT AND
      A.CODARTICOL = O.CODARTICOL AND
      G.CodGest = LV.Gest AND
      COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
      I.OPERAT = 1 AND I.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos; AND
      COALESCE(IOA1.DESCARCAREG, 0) = 0 AND
      COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,I.An,I.Luna)),0) AND
      L1.RESTIESVAL &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
    if vGestAcces &lt;&gt; 1 then
      sInsTmpNedesIes := sInsTmpNedesIes||&apos; AND PKG_NOMGEST.GESTIUNE_DEDICATA(LV.GEST) &gt; 0 &apos;;
    end if;

    IF NOT PKG_LIST_SELFISAMAG.isAllGest THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; ;
      sInsTmpNedesIes := sInsTmpNedesIes||&apos;
      AND LV.GEST &apos;;
      IF vCount = 1
      THEN sInsTmpNedesIes := sInsTmpNedesIes||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesIes := sInsTmpNedesIes||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      END IF;
    END IF;

    IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos; ;
      sInsTmpNedesIes := sInsTmpNedesIes||&apos;
      AND LV.CODOBIECT &apos;;
      IF vCount = 1
      THEN sInsTmpNedesIes := sInsTmpNedesIes||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesIes := sInsTmpNedesIes||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
      END IF;
    END IF;

    sInsTmpNedesIn := sInsTmpFields||&apos;
    SELECT
      0 codnirstoc, 0 codnirser, 0 codcertif, i.codintr coddoc, i.tipdoc, 0 codlocatie, lv.gest, i.codgestprod, i1.umsec, lv.codioart, lv.codobiect,
      i.datadoc IntratLa, i.an*12+i.luna AnLuna,
      i.datadoc, i.nrdoc, i.prefixdoc,
      i.nri nridoc, i.obs obsdoc,i1.obs obsdoc1,
      i.prefixdoc||&apos;&apos;.&apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(I.datadoc,&apos;&apos;DD.MM.YYYY&apos;&apos;) doc, 0 xcodtransf, 0 xcodies, 0 xcodintr,
      lv.pretinreg, lv.pretachiz, NULL pumaximal, lv.pretinreg - lv.pretachiz adaosunitar,
      CASE WHEN coalesce(lv.pretinreg,0) = 0 THEN 0 ELSE (lv.pretinreg - lv.pretachiz)/lv.pretinreg *100 END procentadaos,
      i1.tva, 0 tipserie, 0 furn, ioa1.codioart1,ioa1.aretvaneex, ioa1.mg, ioa1.cont,
      NULL d1, NULL d2, NULL d3, NULL provizion, NULL serielot,0 puval, NULL prdoc, 0 monedadoc,
      0 rezervat, NULL rezervatum1, -L1.RESTIESVAL REST, 0 RESTUM1, 0 RESTUM2, 0 CANTSER,
      NULL SERIE, NULL OBSSER, NULL NRCERTIFSER, NULL DATAPRIMIRE, NULL DATAPROD, NULL PROVENIENTA, NULL DEN_TARA, NULL OBSCERTIF, NULL stare,
      NULL tg, 0 zileexp,
      NULL staredd,
      0 rootcc, i1.pu pretorig, i.curs
    FROM LIVRVAL LV,
         LIVR1 L1,
         INTRARI1 I1,
         LIVR L,
         INTRARI I,
         IOART1 IOA1,
         NARTOBJ O,
         NART A,
         NGEST G
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1 AND
      L1.CODINTR1 = I1.CODINTR1 AND
      L.CODLIVR = L1.CODLIVR AND
      L.TIPLIVR &lt;&gt; 12 AND
      L.TIPLIVR &lt;&gt; 13 AND
      I.CODINTR = L.CODINTR AND
      IOA1.CODIOART = LV.CODIOART AND I.AN*12+I.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND
      O.CODOBIECT = LV.CODOBIECT AND
      A.CODARTICOL = O.CODARTICOL AND
      G.CodGest = LV.Gest AND
      COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
      I.OPERAT = 1 AND I.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;i&apos;)||&apos; AND
      COALESCE(IOA1.DESCARCAREG, 0) = 0 AND
      COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,I.An,I.Luna)),0) AND
      L1.RESTIESVAL &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
      if vGestAcces &lt;&gt; 1 then
        sInsTmpNedesIn := sInsTmpNedesIn||&apos; AND PKG_NOMGEST.GESTIUNE_DEDICATA(LV.GEST) &gt; 0 &apos;;
      end if;

    IF NOT PKG_LIST_SELFISAMAG.isAllGest THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; ;
      sInsTmpNedesIn := sInsTmpNedesIn||&apos;
      AND LV.GEST &apos;;
      IF vCount = 1
      THEN sInsTmpNedesIn := sInsTmpNedesIn||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesIn := sInsTmpNedesIn||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      END IF;
    END IF;

    IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos; ;
      sInsTmpNedesIn := sInsTmpNedesIn||&apos;
      AND LV.CODOBIECT &apos;;
      IF vCount = 1
      THEN sInsTmpNedesIn := sInsTmpNedesIn||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesIn := sInsTmpNedesIn||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
      END IF;
    END IF;

    sInsTmpNedesTr := sInsTmpFields||&apos;
    SELECT
      0 codnirstoc, 0 codnirser, 0 codcertif, T.codtransf coddoc, t.tipdoc, 0 codlocatie, lv.gest, 0 codgestprod, t1.umsec, lv.codioart, lv.codobiect,
      t.datadoc IntratLa, t.an*12+t.luna AnLuna,
      t.datadoc, t.nrdoc, t.prefixdoc,
      NULL nridoc, t.obs obsdoc,t1.obs obsdoc1,
      t.prefixdoc||&apos;&apos;.&apos;&apos;||t.nrdoc||&apos;&apos;/&apos;&apos;||TO_CHAR(t.datadoc,&apos;&apos;DD.MM.YYYY&apos;&apos;) doc, 0 xcodtransf, 0 xcodies, 0 xcodintr,
      lv.pretinreg, lv.pretachiz, NULL pumaximal, lv.pretinreg - lv.pretachiz adaosunitar,
      CASE WHEN coalesce(lv.pretinreg,0) = 0 THEN 0 ELSE (lv.pretinreg - lv.pretachiz)/lv.pretinreg *100 END procentadaos,
      t1.tva, 0 tipserie, 0 furn, ioa1.codioart1,ioa1.aretvaneex, ioa1.mg, ioa1.cont,
      NULL d1, NULL d2, NULL d3, NULL provizion, NULL serielot,0 puval,NULL prdoc, 0 monedadoc,
      0 rezervat, NULL rezervatum1, -L1.RESTIESVAL REST, 0 RESTUM1, 0 RESTUM2,
      0 CANTSER,
      NULL SERIE, NULL OBSSER, NULL NRCERTIFSER, NULL DATAPRIMIRE, NULL DATAPROD, NULL PROVENIENTA, NULL DEN_TARA, NULL OBSCERTIF, NULL stare,
      NULL tg, 0 zileexp,
      NULL staredd,
      0 rootcc, t1.pu pretorig, 0 curs
    FROM LIVRVAL LV,
         LIVR1 L1,
         TRANSF1 T1,
         LIVR L,
         TRANSF T,
         IOART1 IOA1,
         NARTOBJ O,
         NART A,
         NGEST G
    WHERE
      L1.CODLIVR1 = LV.CODLIVR1 AND
      T1.CODTRANSF1 = L1.CODIES1 AND
      L.CODLIVR   = L1.CODLIVR AND
      L.TIPLIVR IN (12, 13) AND
      T.CODTRANSF    = L.CODTRANSF AND
      T.CODTRANSF    = T1.CODTRANSF AND
      IOA1.CODIOART = LV.CODIOART AND
      IOA1.CODIOART = LV.CODIOART AND T.AN*12+T.LUNA BETWEEN IOA1.ALSTART AND IOA1.ALSTOP AND
      O.CODOBIECT = LV.CODOBIECT AND
      A.CODARTICOL = O.CODARTICOL AND
      G.CodGest = LV.Gest AND
      COALESCE(L1.CODPRODCOMP, 0) + COALESCE(L1.CODPROIECT, 0) = 0 AND
      T.OPERAT = 1 AND T.ANULAT = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos; AND
      COALESCE(IOA1.DESCARCAREG, 0) = 0 AND
      COALESCE(LV.CODIOART, 0) &lt;&gt; coalesce(to_number(pkg_categconst.GetValConstanta(&apos;&apos;ContIncasareFactura&apos;&apos;,T.An,T.Luna)),0) AND
      L1.RESTIESVAL &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;);
      if vGestAcces &lt;&gt; 1 then
        sInsTmpNedesTr := sInsTmpNedesTr||&apos; AND PKG_NOMGEST.GESTIUNE_DEDICATA(LV.GEST) &gt; 0 &apos;;
      end if;

    IF NOT PKG_LIST_SELFISAMAG.isAllGest THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; ;
      sInsTmpNedesTr := sInsTmpNedesTr||&apos;
      AND LV.GEST &apos;;
      IF vCount = 1
      THEN sInsTmpNedesTr := sInsTmpNedesTr||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesTr := sInsTmpNedesTr||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
      END IF;
    END IF;

    IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
      SELECT Max(Valoare), Count(1) INTO sVal, vCount FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos; ;
      sInsTmpNedesTr := sInsTmpNedesTr||&apos;
      AND LV.CODOBIECT &apos;;
      IF vCount = 1
      THEN sInsTmpNedesTr := sInsTmpNedesTr||&apos;= &apos;||sVal;
      ELSE sInsTmpNedesTr := sInsTmpNedesTr||&apos;IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
      END IF;
    END IF;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CODDOC, NAV_TIPDOC, NAV_NIRSTOC, CODOBIECT, DEN_ARTICOL, UMSEC, DEN_IOART,DEN_GEST,LOCATIE,PRETACHIZ,PRET,TVA,
    TIPSERIE, PROCENTADAOS,DATADOC,NRDOC,PREFIXDOC, NRIDOC,OBSDOC,OBSLIN, DOCUMENT, INTRATLA,
    DEN_PART,PUMAXIMAL,
    PRODUCATOR,CODINTERN,CODEXTERN,UM_PRINC,UMALT1,UMALT2,SUBUNITATEA,CONT,DIM1,DIM2,DIM3,PUVAL,PRDOC,MONDOC,
    CLASAS,CLASA_ART,SIMBCLASA,PROVIZION, SERIELOT,REZERVAT,REZERVATUM1,VALSTOC,VALACHIZ,PROCTVA,
    VALTVA,
    TVA_UNITAR,
    PMP,PMPVALUTA,
    ADAOS,SERIE,CANTSER,OBSSER,NRCERTIFSER,DATAPRIMIRE,DATAPROD,PROVENIENTA,DEN_TARA,OBSCERTIF,STARE,
    STOC,CANT_UM_PRINC,STOC_UMALT1,STOC_UMALT2, TG,ZILEEXP, StareDD,PRETORIG, CURSDOC,
    CURS_REF, CURS_REFA&apos;||sInsDC||gUserFields||&apos;)
  SELECT
    s.coddoc, s.tipdoc, s.codnirstoc, nobj.codobiect, nobj.denumire, num1.den_um1, io.den_ioart, ng.den_gest, nloc.denumire locatie, s.pretachiz * num1.paritate pretachiz, s.pret * num1.paritate pret, s.tva,
	  DECODE(s.TIPSERIE,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;) tipserie, s.procentadaos, s.datadoc, s.nrdoc, s.prefixdoc, s.nridoc, s.obsdoc, s.obsdoc1, s.doc, s.intratla,
    DECODE(furn.codpart,0,ngprod.den_gest,furn.den_part),
    CASE
      WHEN Coalesce(nobj1.tippretmax,0) IN (1,2,3) AND Coalesce(s.pumaximal,0) &gt; 0       THEN s.pumaximal
      WHEN Coalesce(nobj1.tippretmax,0) IN (4,5,6) AND Coalesce(nobj1.pretmaximal,0) &gt; 0 THEN nobj1.pretmaximal
      ELSE 0
    END pumaximal,
    prod.den_part, nobj.codintern, nobj.codextern, num.den_um, umalt1.den_um umalt1, umalt2.den_um umalt2, sub.den_subunit, ncont.simbol, s.d1,s.d2,s.d3,s.puval,s.prdoc,mdoc.simbol,
    ncls.den_claseas,ncla.den_clasea,ncla.simbol,s.provizion, s.serielot, Coalesce(s.rezervat,0), Coalesce(s.rezervatum1,0), s.pret * s.rest valstoc, s.pretachiz*s.rest valachiz, ntva1.procent,
    CASE WHEN s.aretvaneex = 1 THEN (s.pret*ntva1.procent)* s.rest/(100+ntva1.procent) ELSE 0 END valtva,
		CASE WHEN s.aretvaneex = 1 THEN (s.pret*ntva1.procent)/(100+ntva1.procent) * num1.paritate ELSE 0 END tva_unitar,
    CASE WHEN s.mg = 3 THEN Coalesce(PKG_PMP.GET_PMP_LEI(s.codobiect,&apos;||CASE WHEN sTipPMP = &apos;1&apos; THEN &apos;1&apos; ELSE &apos;ng.codsubunit&apos; END||&apos;,&apos;||AnLista||&apos;,&apos;||LunaLista||&apos;),0) ELSE 0 END pmp,
    CASE WHEN s.mg = 3 THEN Coalesce(PKG_PMP.GET_PMP_VALUTA_FROM_VAR,0) ELSE 0 END pmpv,
    Coalesce(s.rest * s.adaosunitar,0), s.serie, s.cantser, s.obsser, s.nrcertifser, s.dataprimire, s.dataprod, s.provenienta, s.den_tara, s.obscertif, s.stare,
    Coalesce(s.rest/num1.paritate,0), Coalesce(s.rest,0), Coalesce(s.restum1,0), Coalesce(s.restum2,0), s.tg, s.zileexp, s.staredd, s.pretorig, s.cursdoc&apos;||
    sCursRef||sSelDC||gUserAlias||&apos;
  FROM &apos;||vTabla1||&apos;
    LEFT JOIN &apos;||vTabla2||&apos; ON nobj.codobiect = s.codobiect
    LEFT JOIN nart ON nart.codarticol = nobj.codarticol
    LEFT JOIN ngest ng ON ng.codgest = Coalesce(s.gest,nart.gestimplicita)
 		LEFT JOIN ioart io ON io.codioart = Coalesce(s.codioart,nart.contimplicit)
    LEFT JOIN num1 ON num1.codum1 = s.umsec
		LEFT JOIN num ON num1.codum = num.codum
    LEFT JOIN nartobj1 nobj1 ON nobj1.codobiect = nobj.codobiect AND Coalesce(s.AnLuna,0) BETWEEN nobj1.alstart AND nobj1.alstop
		LEFT JOIN nart1 nart1 ON nart1.codarticol = nart.codarticol AND Coalesce(s.AnLuna,0) BETWEEN nart1.alstart AND nart1.alstop
		LEFT JOIN ntva1 ntva1 ON ntva1.codtva = nart1.codtva AND Coalesce(s.AnLuna,0) BETWEEN ntva1.alstart AND ntva1.alstop
    LEFT JOIN nsubunit sub ON sub.codsubunit = ng.codsubunit
    LEFT JOIN nmonede mdoc ON mdoc.codmoneda = Coalesce(s.monedadoc,0)
		LEFT JOIN npart furn ON furn.codpart = pkg_list_base_stoc.GetFurn(nobj.codobiect, s.codnirstoc, s.furn)
		LEFT JOIN npart prod ON prod.codpart = nobj.codproducator
		LEFT JOIN nlocatii nloc ON nloc.codlocatie = s.codlocatie
    LEFT JOIN ncont ncont ON ncont.codcont = s.cont
    LEFT JOIN num umalt1 ON nart.um1 = umalt1.codum
    LEFT JOIN num umalt2 ON nart.um2 = umalt2.codum
    LEFT JOIN nclaseas ncls ON ncls.codclaseas = nart.clasastatist
    LEFT JOIN ngest ngprod ON ngprod.codgest = s.codgestprod
    LEFT JOIN nclasea ncla ON ncla.codclasea = nart.clasa&apos;||
    sJoinDC||gSuplJoins||&apos;
  WHERE 1 = 1&apos;;

  IF PKG_LIST_SELFISAMAG.isToateArt = 0 AND PKG_LIST_SELFISAMAG.inclArtStoc0 THEN
    sInsert := sInsert||&apos;
    AND NOBJ.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  END IF;

  PregatireSerii;
  PRC_AL_CHECK(&apos;NART1&apos;);
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  PRC_AL_CHECK(&apos;NTVA1&apos;);
  PRC_AL_CHECK(&apos;IOART1&apos;);

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE tmp_lst_stoc&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);
  IF PKG_LIST_SELFISAMAG.inclNedes then
    LIST_EXECUTE_IMMEDIATE(sInsTmpNedesIes, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsTmpNedesIn,  aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(sInsTmpNedesTr,  aListID, aListVer);
  END IF;
  COMMIT;

  IF NOT pkg_list_selfisamag.areSerii AND (Instr(Upper(gUserAlias), &apos;S.SERII&apos;) &gt; 0) THEN
    sUpdTmp :=
    &apos;UPDATE tmp_lst_stoc tmp
    SET SERII =
        (
          SELECT vc2_nt_to_vc3200(CAST(COLLECT(ser.serie||CASE WHEN nser.rest &lt;&gt; 1 THEN &apos;&apos;(&apos;&apos;||nser.rest||&apos;&apos;)&apos;&apos; ELSE &apos;&apos;&apos;&apos; END ORDER BY ser.serie, nser.rest ) AS vc2_nt))
          FROM&apos;;
    IF pkg_list_selfisamag.StocLaZi THEN
      sUpdTmp := sUpdTmp||&apos; nirser nser LEFT JOIN nserii ser ON ser.codserie = nser.codserie&apos;;
    ELSE
      sUpdTmp := sUpdTmp||&apos; v_stoc_luna_ser nser
            LEFT JOIN nirser xser ON xser.codnirser = nser.codnirser
            LEFT JOIN nserii ser ON ser.codserie = xser.codserie&apos;;
    END IF;
    sUpdTmp := sUpdTmp||&apos;
          WHERE nser.codnirstoc = tmp.codnirstoc AND nser.rest &lt;&gt; 0
        )&apos;;
    LIST_EXECUTE_IMMEDIATE(sUpdTmp, aListID, aListVer);
    COMMIT;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
  pkg_list_Struct.GOLESTE_PARAM;
  pkg_list_Struct.ADAUGA_PARAM(&apos;DATA STOC&apos;, to_char(DataStoc,&apos;DD.MM.YYYY&apos;));
END;
END PKG_LIST_BASE_STOC;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCCONTROL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5073ED6E7A861DD734ED16295ED5B72B3CD3CA23</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stoccontrol IS

  vAnLunaIni  PLS_INTEGER;
  vLunaIni    PLS_INTEGER;
  vAnIni      PLS_INTEGER;
  vAnLunaFin  PLS_INTEGER;
  vLunaFin    PLS_INTEGER;
  vAnFin      PLS_INTEGER;
  vAllClient  BOOLEAN;
  vAllAgent   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(30000);
  sFiltruI   VARCHAR2( 1000);
  sFiltruS   VARCHAR2( 1000);
  sCondCantP VARCHAR2( 1000);
  sIJoin     VARCHAR2( 1000);
  sICant     VARCHAR2(  100);
  sIGest     VARCHAR2(  100);
BEGIN
  gSuplCols := &apos;NPERS AG, NGEST G, NARTOBJ O, NART A, NUM U, NCLASEA CA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  IF PKG_LIST_SELPERART.DupaData THEN
    sFiltruI := &apos;
    WHERE i.datadoc &lt;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELPERART.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sCondCantP := &apos;i.datadoc &gt;= To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELPERART.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sFiltruI := &apos;
      WHERE i.an*12+i.luna &lt;= &apos;||PKG_LIST_SELPERART.LunaAnFin;
    sCondCantP := &apos;i.an*12+i.luna &gt;= &apos;||PKG_LIST_SELPERART.LunaAnIni;
  END IF;

  IF PKG_LIST_SELPERART.FiltruArt = 2 THEN
    sFiltruS := &apos;
    WHERE a.clasa IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;)&apos;;
    sFiltruI := sFiltruI||&apos;
        AND a.clasa IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;)&apos;;
  ELSIF PKG_LIST_SELPERART.FiltruArt = 1 THEN
    sFiltruS := &apos;
    WHERE o.codobiect IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
    sFiltruI := sFiltruI||&apos;
        AND o.codobiect IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  END IF;

  IF PKG_LIST_SELPERART.Extra1 THEN --gestiunea din stoc
    sIGest := &apos;Nvl(n.gest, 0)&apos;;
    sICant := &apos;l1.cant&apos;;
    sIJoin := &apos;
        INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
        INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
        INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN iesiri1 i1 ON i1.codies1 = l1.codies1&apos;;

  ELSE -- gestiunea agentului
    sIGest := &apos;Nvl(ag.codgest, 0)&apos;;
    sICant := &apos;i1.cant&apos;;
    sIJoin := &apos;
        INNER JOIN iesiri1 i1 ON i1.codies = i.codies&apos;;
  END IF;

  sFiltruI := sFiltruI||&apos;
        AND i1.tiplinie = &apos;&apos;=&apos;&apos;&apos;;

  sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(AGENT, ART, UM, CANTIESPER, DATANIR1, STOCMOM, NRSEDII, NRSEDIIX, CANTLIVR1, CANTLIVRX, MEDLUNVANZ, NRZILE&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH
  S AS (
    SELECT n.gest, ns.codobiect, Min(n.datanir) datanir1, Sum(ns.rest) stocmom
    FROM nartobj o
      INNER JOIN nart a ON a.codarticol = o.codarticol
      INNER JOIN nirstoc ns ON ns.codobiect = o.codobiect
      INNER JOIN nir n ON n.codnir = ns.codnir &apos;||
    sFiltruS||&apos;
    GROUP BY n.gest, ns.codobiect
  ),
  I AS (
    SELECT agent, Sum(Sediu1) NRSEDII, Sum(SediuX) NRSEDIIX, codgest, codobiect, Min(primaies) primaies, Sum(cantiesper) cantiesper, Sum(cantlivr1) cantlivr1, Sum(cantlivr) cantlivr
    FROM (
      SELECT
        Nvl(i.agent, 0) agent, &apos;||sIGest||&apos; codgest, i1.codobiect, i.codlocatie,
        Min(i.datadoc) primaies,
        Decode(p.persoanafizica,1,0,1) Sediu1,
        CASE WHEN p.persoanafizica = 1 THEN 0 WHEN Min(i.codies) = Max(i.codies) THEN 0 ELSE 1 END SediuX,
        Sum(CASE WHEN &apos;||sCondCantP||&apos; THEN &apos;||sICant||&apos; ELSE 0 END) cantiesper,
        Sum(Decode(p.persoanafizica,1,0,&apos;||sICant||&apos;)) KEEP (Dense_Rank first ORDER BY i.datadoc, i.codies) cantlivr1,
        Sum(&apos;||sICant||&apos;) cantlivr
      FROM iesiri i
        INNER JOIN npart p ON p.codpart = i.partener
        INNER JOIN npers ag ON ag.codpers = i.agent&apos;||
        sIJoin||&apos;
        INNER JOIN nartobj o ON o.codobiect = i1.codobiect
        INNER JOIN nart a ON a.codarticol = o.codarticol&apos;||
      sFiltruI||&apos;
      GROUP BY Nvl(i.agent, 0), &apos;||sIGest||&apos;, i1.codobiect, i.codlocatie, p.persoanafizica)
    GROUP BY agent, codgest, codobiect
  )
  SELECT
    AG.NUme||DECODE(AG.CodPers,NULL,NULL,&apos;&apos; &apos;&apos;||AG.PRENUME) Agent,
    O.Denumire ART, U.Den_UM UM, Nvl(I.CANTIESPER, 0) CANTIESPER, S.DATANIR1, S.STOCMOM, Nvl(I.NRSEDII,0) NRSEDII, Nvl(I.NRSEDIIX,0) NRSEDIIX,
    Nvl(I.CANTLIVR1,0) CANTLIVR1, Nvl(CANTLIVR-CANTLIVR1,0) CANTLIVRX,
    CASE WHEN PKG_LIST_SELPERART.DataFin &gt; S.DATANIR1 THEN Nvl(CANTLIVR-CANTLIVR1,0)*30/(PKG_LIST_SELPERART.DataFin - S.DATANIR1) ELSE 0 END MEDLUNVANZ,
    To_Date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELPERART.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) - S.DATANIR1 NRZILE &apos;||gUserAlias||&apos;
  FROM S
    LEFT JOIN i ON i.codobiect = s.codobiect AND i.codgest = s.gest
    LEFT JOIN npers ag ON ag.codpers = i.agent
    LEFT JOIN nartobj o ON o.codobiect = s.codobiect
    LEFT JOIN nart a ON a.codarticol = o.codarticol
    LEFT JOIN num u ON u.codum = a.um
    LEFT JOIN nclasea ca On ca.codclasea = a.clasa
    LEFT JOIN ngest g ON g.codgest = s.gest&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCCONTROL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCCRITIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBEC19F14A0730187B322102A09AC7F50F02A224</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stoccritic IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sColMinMax VARCHAR2(  100):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NARTOBJSUBUNIT NAOS, NPART NP, NART NA, NUM NUM&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(ART, UM, STOC, STOCMIN, STOCMED, STOCMAX, DIF, COMENZI, REZERVARI, PROD, CODEXTERN, CODINTERN&apos;||gUserFields||&apos;)
  WITH
    STOCART AS (
      SELECT NS.CODOBIECT, SUM(NS.REST) STOC
      FROM NIRSTOC NS
            INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
            LEFT JOIN INTRARI I ON I.CODINTR = NIR.CODINTR
            LEFT JOIN TRANSF T ON T.CODTRANSF = NIR.CODTRANSF &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(NULL,&apos;NVL(I.SUBUNITATEA, T.SUBUNITATEA)&apos;,&apos;WHERE&apos;)||&apos;
      GROUP BY CODOBIECT),
    STOCREZ AS (
      SELECT CODOBIECT, SUM(DECODE(C.TIPDOC, 8, C1.RESTACCEPTAT,0)) COMENZI, SUM(DECODE(C.TIPDOC, 18, C1.RESTACCEPTAT,0)) REZERVARI
      FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
      WHERE C1.RESTACCEPTAT &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
            AND C.OPERAT = 1 AND COALESCE(C.ANULAT,0) = 0 AND COALESCE(C.INCHISA,0) = 0
            AND COALESCE(C.DISPLIVRARE,0) = 0
      GROUP BY C1.CODOBIECT)
  SELECT
    NAO.DENUMIRE , NUM.DEN_UM ,S.STOC&apos;||sColMinMax;
  
  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
  sInsert := sInsert||&apos;,
    CASE
      WHEN NVL(NAO.STOCMIN,0) &lt;&gt; 0 AND S.STOC &lt; NVL(NAO.STOCMIN,0) THEN S.STOC - NVL(NAO.STOCMIN,0)
      WHEN NVL(NAO.STOCMAX,0) &lt;&gt; 0 AND S.STOC &gt; NVL(NAO.STOCMAX,0) THEN S.STOC - NVL(NAO.STOCMAX,0)
      ELSE 0
    END DIFERENTA,&apos;;
  ELSE
    sInsert := sInsert||&apos;,
    CASE
      WHEN NVL(NAOS.STOCMIN,0) &lt;&gt; 0 AND S.STOC &lt; NVL(NAOS.STOCMIN,0) THEN S.STOC - NVL(NAOS.STOCMIN,0)
      WHEN NVL(NAOS.STOCMAX,0) &lt;&gt; 0 AND S.STOC &gt; NVL(NAOS.STOCMAX,0) THEN S.STOC - NVL(NAOS.STOCMAX,0)
      ELSE 0
    END DIFERENTA,&apos;;
  END IF;
    
  sInsert := sInsert||&apos;  
    NVL(SR.COMENZI,0) COMENZI, NVL(SR.REZERVARI,0) REZERVARI, NP.DEN_PART PRODUCATOR, NAO.CODEXTERN, NAO.CODINTERN&apos;||gUserAlias||&apos;
  FROM STOCART S
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = S.CODOBIECT
    LEFT JOIN NARTOBJSUBUNIT NAOS ON NAOS.CODOBIECT = NAO.CODOBIECT 
                                  and (NAOS.codgest is null or NAOS.codgest = 0)
                                  AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN STOCREZ SR ON SR.CODOBIECT = S.CODOBIECT
    LEFT JOIN NPART NP ON NP.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM&apos;||
    gSuplJoins;
  if pkg_globals.GETSUBUNITATE &lt; 2 then
    sInsert := sInsert||&apos;
    WHERE (NVL(NAO.STOCMIN,0) &lt;&gt; 0 AND S.STOC &lt; NVL(NAO.STOCMIN,0)) OR (NVL(NAO.STOCMAX,0) &lt;&gt; 0 AND S.STOC &gt; NVL(NAO.STOCMAX,0))  &apos;;
  else
    sInsert := sInsert||&apos;
    WHERE (NVL(NAOS.STOCMIN,0) &lt;&gt; 0 AND S.STOC &lt; NVL(NAOS.STOCMIN,0)) OR (NVL(NAOS.STOCMAX,0) &lt;&gt; 0 AND S.STOC &gt; NVL(NAOS.STOCMAX,0))  &apos;;
  end if;  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCCRITIC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>260B773BADA7A3CC5370AE8A65721B0C7A2135ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOCEP IS

  vDataIni       DATE;
  vDataFin       DATE;
  sDataIni       VARCHAR2( 100);
  sDataFin       VARCHAR2( 100);
  vTipMedie      INTEGER;
  vIndCrest      NUMBER;
  vToataFirma    BOOLEAN;
  vToateGest     BOOLEAN;
  vInclEpuiz     BOOLEAN;
  vUltAchiz      BOOLEAN;
  vToateArt      BOOLEAN;
  vToateClaseArt BOOLEAN;
  vToateArticole BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);



PROCEDURE SETPARAMS(
  pDataIni       IN VARCHAR2,
  pDataFin       IN VARCHAR2,
  pTipMedie      IN INTEGER,
  pIndCrest      IN NUMBER,
  pToataFirma    IN NUMBER DEFAULT 1,
  pToateGest     IN NUMBER DEFAULT 1,
  pInclEpuiz     IN NUMBER DEFAULT 0,
  pUltAchiz      IN NUMBER DEFAULT 0,
  pToateArt      IN NUMBER DEFAULT 0,
  pCodJob1       IN NUMBER DEFAULT 0,
  pToateClaseArt IN NUMBER DEFAULT 1,
  pToateArticole IN NUMBER DEFAULT 1  
) IS
  vALIni NUMBER(20) := 0;
  vALFin NUMBER(20) := 0;
BEGIN
  sDataIni    := pDataIni;
  sDataFin    := pDataFin;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,sDataIni,sDataFin,vALIni,vALFin);
  END IF;
  vDataIni       := To_Date(sDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin       := To_Date(sDataFin,&apos;dd.mm.yyyy&apos;);
  sDataIni       := &apos;To_date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin       := &apos;To_date(&apos;&apos;&apos;||sDataFin||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  vTipMedie      := pTipMedie;
  vIndCrest      := pIndCrest;
  vToataFirma    := pToataFirma = 1;
  vToateGest     := pToateGest = 1;
  vInclEpuiz     := pInclEpuiz = 1;
  vUltAchiz      := pUltAchiz = 1;
  vToateArt      := pToateArt = 1;
  vToateClaseArt := pToateClaseArt = 1;
  vToateArticole := pToateArticole = 1;
END;

function GetDataIni return varchar2 is
begin
  return to_char(vDataIni,&apos;dd.mm.yyyy&apos;);
end;

function GetDataFin return varchar2 is
begin
  return to_char(vDataFin,&apos;dd.mm.yyyy&apos;);
end;

function getWhereFilterArt( aliasObj IN Varchar2) return Varchar2 is
  whArtFilter  VARCHAR2(3000) := &apos;&apos;; 
begin
  IF not vToateClaseArt THEN
    whArtFilter := &apos; AND NA.CLASA IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos;) &apos;;
  ELSE
    IF not vToateArticole THEN
      whArtFilter := &apos; AND &apos;||aliasObj||&apos;.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
    END IF;
  END IF; 
  return whArtFilter;
end; 
 
function getJoinFilterArt( aliasObj IN Varchar2) return Varchar2 is
  jnArtFilter  VARCHAR2(3000) := &apos;&apos;;
begin
  IF not vToateClaseArt THEN
    jnArtFilter := &apos; INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = &apos;||aliasObj||&apos;.CODOBIECT
                     LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL &apos; ;
  END IF;
  return jnArtFilter; 
end;  

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  vInsert      CLOB;
  vInsSTOCREAL CLOB;
  vInsSTOCPER  CLOB;
  vInsSTOCREZ  CLOB;
  vInsSTOCCOM  CLOB;
  vInsIES_PER  CLOB;
  vInsFaraIES_PER CLOB;
  vInsLAST_NS  CLOB;

  vItemSGest   VARCHAR2(50)  := &apos; ,NULL GEST, NULL CODLOCATIE&apos;;
  vItemGGest   VARCHAR2(50)  := &apos;&apos;;
  vZile        INTEGER       := vDataFin - vDataIni +1;
  vSelIoArt    VARCHAR2(2000);

  vFromIes_Per VARCHAR2(2000);

  vJoin        VARCHAR2(1000);
  vWhere       VARCHAR2(1000);
  vCateGest    INTEGER;
  vCateLGest   INTEGER;
  sColMinMax   VARCHAR2( 100):= &apos;, NAOS.STOCMIN, NAOS.STOCMED, NAOS.STOCMAX&apos;;
  sUltNirstoc  VARCHAR2( 1000);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NARTOBJSUBUNIT NAOS, NUM NUM, NPART PROD, NCLASEA NCA, NIRSTOC UNS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMED, NAO.STOCMAX&apos;;
  END IF;

  IF not vToataFirma THEN
    IF vToateArt THEN
      vItemSGest := &apos; ,N.GEST, NULL&apos;;
      vItemGGest := &apos; ,N.GEST, NULL&apos;;
    ELSE
      vItemSGest := &apos; ,N.GEST, NVL(NS.CODLOCATIE,0) CODLOCATIE&apos;;
      vItemGGest := &apos; ,N.GEST, NVL(NS.CODLOCATIE,0)&apos;;
    END IF;  
  END IF;
 
  vWhere := &apos;
  WHERE NOT NS.CODIOART IN (SELECT DISTINCT CODIOART FROM IOART1 WHERE MG = 5)&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;,&apos;
    AND&apos;);

  IF NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    if vToateArt then
      vCateLGest := 0;
    else
      SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    end if;  
  END IF;

  IF vToateGest THEN
    NULL;
  ELSIF vCateLGest = 0 THEN
    vWhere := vWhere||&apos;
    AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  ELSIF vCateGest = 0 THEN
    vWhere := vWhere||&apos;
    AND NS.CODLOCATIE IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
  ELSE
    vWhere := vWhere||&apos;
    AND (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
  END IF;

  /*************************** Construiesc Insert STOCREAL ************************************/
  vInsSTOCREAL := &apos;INSERT INTO TMP_LST_STOCEP_STOCREAL(CODOBIECT, GEST, CODLOCATIE, CANT, VALTOTIN)
  SELECT NS.CODOBIECT&apos;||vItemSGest||&apos;, SUM(NS.REST) CANT, SUM(NS.REST * (NS.PRET - NS.ADAOS)) ValTotIn
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST&apos;||
    getJoinFilterArt(&apos;NS&apos;)||
  vWhere||getWhereFilterArt(&apos;NS&apos;)||&apos;
  GROUP BY NS.CODOBIECT&apos;||vItemGGest;

  /*************************** Construiesc Insert STOCPER ************************************/
  vInsSTOCPER := &apos;INSERT INTO TMP_LST_STOCEP_STOCPER(CODOBIECT, GEST, CODLOCATIE, STOCFIN, PZISTOC, UZISTOC)
  SELECT
    NS.CODOBIECT&apos;||vItemSGest||&apos;, SUM(ns.cantnir - nvl(lp.iestot,0)) stocfin,
    CASE
      WHEN SUM(case when n.datanir &lt; &apos;||sDataIni||&apos; then ns.cantnir else 0 end) - sum (nvl(lp.iesprec,0)) = 0
      THEN MIN(CASE WHEN N.DATANIR &gt;= &apos;||sDataIni||&apos; THEN (N.DATANIR + 1 - to_date(&apos;||sDataIni||&apos;)) ELSE &apos;||vZile||&apos; END)
      ELSE 1
    END PZISTOC,
    CASE
      WHEN SUM(ns.cantnir - nvl(lp.iestot,0)) = 0
      THEN MAX(CASE WHEN NVL(lp.ultimalivr,&apos;||sDataIni||&apos;) &lt;= &apos;||sDataIni||&apos; THEN 1 ELSE (lp.ultimalivr + 1 - to_date(&apos;||sDataIni||&apos;))  END)
      ELSE &apos;||vZile||&apos;
    END UZISTOC
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    LEFT JOIN (
      SELECT
        l1.codnirstoc,
        sum (case when l.datalivr &lt; &apos;||sDataIni||&apos; then l1.cant*decode(l.tiplivr,15,-1,1) else 0 end) iesprec,
        sum (l1.cant* decode(l.tiplivr,15,-1,1)) iestot, max(l.datalivr) ultimalivr
      FROM livr l INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
      WHERE L.DATALIVR &lt;= &apos;||sDataFin||&apos;
      GROUP BY l1.codnirstoc
    ) lp ON lp.codnirstoc = ns.codnirstoc &apos;||
    getJoinFilterArt(&apos;NS&apos;)||
  vWhere||getWhereFilterArt(&apos;NS&apos;)||&apos;
    AND n.datanir &lt;= &apos;||sDataFin||&apos;
  GROUP BY NS.CODOBIECT&apos;||vItemGGest;

  /**************************** Construiesc Insert IESIRI PERIOADA ************************************/
  
  vFromIes_Per  := &apos;
  FROM LIVR L
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
    LEFT JOIN NIRSTOC NSD ON NSD.CODLIVR1 = L1.CODLIVR1
    LEFT JOIN IESIRI1 I1 ON I1.CODIES = L.CODIES AND I1.CODIES1 = L1.CODIES1
    LEFT JOIN IESIRI I ON I.CODIES = I1.CODIES
    LEFT JOIN TRANSF1 T1 ON T1.CODTRANSF = L.CODTRANSF AND T1.CODTRANSF1 = L1.CODIES1&apos;||
     getJoinFilterArt(&apos;NS&apos;)||
  vWhere||getWhereFilterArt(&apos;NS&apos;)||&apos;
    AND L.TIPLIVR IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPLIVR&apos;&apos;)
    AND L.DATALIVR BETWEEN &apos;||sDataIni||&apos; AND &apos;||sDataFin||&apos;
    AND (L.TIPLIVR &lt;&gt; 12 OR NSD.CODIOART IN (SELECT DISTINCT CODIOART FROM IOART1 WHERE MG = 5))  &apos;;

  IF vTipMedie = 2 THEN
    EXECUTE IMMEDIATE &apos;SELECT COUNT(DISTINCT L.DATALIVR) &apos;||vFromIes_Per INTO vZile;
  END IF;

  vInsIES_PER := &apos;INSERT INTO TMP_LST_STOCEP_IES_PER(CODOBIECT, GEST, CODLOCATIE, CANT, CANTAS, CANTT, VALTOTACH, VALTOTOUT)
  SELECT NS.CODOBIECT&apos;||vItemSGest||&apos;,
    SUM(L1.CANT) CANT, SUM(DECODE(L.TIPLIVR,23,L1.CANT,0)) CANTAS, SUM(DECODE(L.TIPLIVR,12,L1.CANT,0)) CANTT,
    SUM(L1.CANT * (NS.PRET - NS.ADAOS)) ValTotAch, SUM(case when coalesce(i.moneda,0) in (0,1) then 1 else i.curs end * (L1.CANT * NVL(I1.PU,T1.PU) - case when i.tipdoc = 16 then l1.cant/i1.cant*i1.tva else 0 end)) ValTotOut &apos;||
  vFromIes_Per||&apos;
  GROUP BY NS.CODOBIECT&apos;||vItemGGest||&apos;
  HAVING SUM(L1.CANT) &lt;&gt; 0&apos;;

  if vToateArt then
    IF NOT vToataFirma THEN
      vInsFaraIES_PER := 
      &apos;INSERT INTO TMP_LST_STOCEP_IES_PER(CODOBIECT, GEST, CODLOCATIE, CANT, CANTAS, CANTT, VALTOTACH, VALTOTOUT)
       SELECT O.CODOBIECT, TMP.GEST, 0, 0, 0, 0, 0, 0
       FROM NARTOBJ O
            LEFT JOIN TMP_LST_STOCEP_STOCREAL TMP ON TMP.CODOBIECT = O.CODOBIECT &apos;
            ||getJoinFilterArt(&apos;O&apos;)|| 
      &apos; WHERE NOT EXISTS (SELECT T.CODOBIECT FROM TMP_LST_STOCEP_IES_PER T WHERE T.CODOBIECT = O.CODOBIECT AND T.GEST = TMP.GEST) AND COALESCE(O.INACTIV,0) = 0 &apos;
      || getWhereFilterArt(&apos;O&apos;);
    ELSE
      vInsFaraIES_PER := 
      &apos;INSERT INTO TMP_LST_STOCEP_IES_PER(CODOBIECT, GEST, CODLOCATIE, CANT, CANTAS, CANTT, VALTOTACH, VALTOTOUT)
       SELECT O.CODOBIECT, 0, 0, 0, 0, 0, 0, 0
       FROM NARTOBJ O &apos;
       ||getJoinFilterArt(&apos;O&apos;)|| 
      &apos; WHERE NOT EXISTS (SELECT T.CODOBIECT FROM TMP_LST_STOCEP_IES_PER T WHERE T.CODOBIECT = O.CODOBIECT) AND COALESCE(O.INACTIV,0) = 0&apos;
      || getWhereFilterArt(&apos;O&apos;);
    END IF;  
  end if;  

  /**************************** Construiesc Insert STOCREZ ************************************/
  vInsSTOCREZ := &apos;INSERT INTO TMP_LST_STOCEP_STOCREZ(CODOBIECT, REZERVAT)
  SELECT NS.CODOBIECT, SUM(R.REST) REZERVAT
  FROM REZERVATS R
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC &apos;
       ||getJoinFilterArt(&apos;NS&apos;)|| 
    &apos; WHERE NVL(R.REST,0) &lt;&gt; 0 &apos;
      || getWhereFilterArt(&apos;NS&apos;) || 
    &apos; GROUP BY NS.CODOBIECT&apos;;

  /**************************** Construiesc Insert STOCCOM ************************************/
  vInsSTOCCOM := &apos;INSERT INTO TMP_LST_STOCEP_STOCCOM(CODOBIECT, RESTCOM)
  SELECT C1.CODOBIECT, SUM(C1.RESTACCEPTAT) RestCom
  FROM COMANDA C INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = C.CODCOMANDA &apos;
       ||getJoinFilterArt(&apos;C1&apos;)|| 
  &apos; WHERE NVL(C1.RESTACCEPTAT,0) &lt;&gt; 0 AND C.TipDoc = 18 &apos;
      || getWhereFilterArt(&apos;C1&apos;) || 
  &apos; GROUP BY C1.CODOBIECT&apos;;

  /**************************** Construiesc Insert Ultima Achizitie ************************************/
  vInsLAST_NS := &apos;INSERT INTO TMP_LST_STOCEP_LAST_NS(CODOBIECT, CODNIRSTOC)&apos;;
  IF vUltAchiz THEN
    PRC_AL_CHECK(&apos;NPART1&apos;);
    vInsLAST_NS := vInsLAST_NS||&apos;
    SELECT NS.CODOBIECT, MAX(NS.CODNIRSTOC) KEEP (DENSE_RANK LAST ORDER BY NS.DATAACHIZ, NS.CODNIRSTOC) CODNIRSTOC
    FROM NIRSTOC NS &apos;
       ||getJoinFilterArt(&apos;NS&apos;)|| 
    &apos; WHERE Nvl(NS.CODNIRSTOCPARINTE,0) = 0 &apos;
      || getWhereFilterArt(&apos;NS&apos;) || 
    &apos; GROUP BY NS.CODOBIECT&apos;;
  ELSE
    vInsLAST_NS := vInsLAST_NS||&apos; SELECT 0 CODOBIECT, 0 CODNIRSTOC FROM DUAL&apos;;
  END IF;

  /************************ Sfarsit Constructie Selecturi Auxiliare ***************************/
  IF vToataFirma
  THEN
    SELECT den_subunit INTO vItemSGest
    FROM nsubunit WHERE codsubunit = PKG_GLOBALS.GETSUBUNITATE;

    vItemSGest := &apos;&apos;&apos;&apos;||vItemSGest||&apos;&apos;&apos;, NULL&apos;;
    vJoin      := &apos;
    LEFT JOIN TMP_LST_STOCEP_STOCREAL SR ON SR.CODOBIECT = IP.CODOBIECT
    LEFT JOIN TMP_LST_STOCEP_STOCPER  SP ON SP.CODOBIECT = IP.CODOBIECT&apos;;
  ELSE
    IF vToateArt THEN
      vItemSGest := &apos;NG.DEN_GEST, NULL&apos;;
      vJoin      := &apos;
      LEFT JOIN TMP_LST_STOCEP_STOCREAL SR ON SR.CODOBIECT = IP.CODOBIECT AND SR.GEST = IP.GEST
      LEFT JOIN TMP_LST_STOCEP_STOCPER  SP ON SP.CODOBIECT = IP.CODOBIECT AND SP.GEST = IP.GEST
      LEFT JOIN NGEST    NG ON NG.CODGEST    = IP.GEST&apos;;
    ELSE
      vItemSGest := &apos;NG.DEN_GEST, NL.DENUMIRE&apos;;
      vJoin      := &apos;
      LEFT JOIN TMP_LST_STOCEP_STOCREAL SR ON SR.CODOBIECT = IP.CODOBIECT AND SR.GEST = IP.GEST AND SR.CODLOCATIE = IP.CODLOCATIE
      LEFT JOIN TMP_LST_STOCEP_STOCPER  SP ON SP.CODOBIECT = IP.CODOBIECT AND SP.GEST = IP.GEST AND SP.CODLOCATIE = IP.CODLOCATIE
      LEFT JOIN NGEST    NG ON NG.CODGEST    = IP.GEST
      LEFT JOIN NLOCATII NL ON NL.CODLOCATIE = IP.CODLOCATIE&apos;;
    END IF;  
  END IF;

  vInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    CodObiect, Gest, LGest, Articol, UM, Stoc, TotVanz, TotIesAS, TotIesT, Zile, MedieVanz,
    ZileLich, PmAchiz, PmVanzare,
    CodExtern, CodIntern, Producator, DurataMax, StocMin, StocMed, StocMax, ClasaA,
    StocFinPer, PZiStocPer, UZiStocPer, Rezervat, RestCom, UltFurn, UltPrAchiz, UltIOArt&apos;||gUserFields||&apos;)
  SELECT
    NAO.CodObiect, &apos;||vItemSGest||&apos;, NAO.DENUMIRE, NUM.DEN_UM, SR.CANT, IP.CANT, IP.CANTAS, IP.CANTT, &apos;||vZile||&apos;, (IP.CANT * &apos;||vIndCrest||&apos; / &apos;||vZile||&apos;) MEDIEVANZ,
    CASE WHEN IP.CANT = 0 THEN 0 ELSE SR.CANT / (IP.CANT * &apos;||vIndCrest||&apos; / &apos;||vZile||&apos;) END, CASE WHEN IP.CANT = 0 THEN 0 ELSE IP.VALTOTACH / IP.CANT END, CASE WHEN IP.CANT = 0 THEN 0 ELSE IP.VALTOTOUT / IP.CANT END,
    NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART PRODUCATOR, COALESCE(NAOIMP.DURMAXAPROV,NAO.DURMAXAPROV) &apos;||sColMinMax||&apos;, NCA.DEN_CLASEA,
    SP.STOCFIN, SP.PZISTOC, SP.UZISTOC, SREZ.REZERVAT, SCOM.RESTCOM, UF.DEN_PART, UNS.PRET - Nvl(UNS.ADAOS,0),IOLP.DEN_IOPART&apos;||gUserAlias||&apos;
  FROM TMP_LST_STOCEP_IES_PER IP
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = IP.CODOBIECT&apos;||
    vJoin||&apos;
    LEFT JOIN TMP_LST_STOCEP_LAST_NS LNS ON LNS.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN NIRSTOC UNS ON UNS.CODNIRSTOC = LNS.CODNIRSTOC
    LEFT JOIN NPART1 PLST ON PLST.CODPART = UNS.FURN AND EXTRACT(YEAR FROM UNS.DATAACHIZ)*12+EXTRACT(MONTH FROM UNS.DATAACHIZ) BETWEEN PLST.ALSTART AND PLST.ALSTOP
    LEFT JOIN IOPART IOLP ON IOLP.CODIOPART = PLST.CODIOPART
    LEFt JOIN NPART UF ON UF.CODPART = UNS.FURN
    LEFT JOIN TMP_LST_STOCEP_STOCREZ SREZ ON SREZ.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN TMP_LST_STOCEP_STOCCOM SCOM ON SCOM.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NARTOBJSUBUNIT NAOS ON NAOS.CODOBIECT = NAO.CODOBIECT 
                                  and (NAOS.codgest is null or NAOS.codgest = 0)
                                  AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NARTOBJIMP NAOIMP ON NAOIMP.CODOBIECT = NAO.CODOBIECT AND NAOIMP.CODSUBUNIT = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = NA.CLASA&apos;||
    gSuplJoins||&apos;
  WHERE NA.TIPARTICOL = 0&apos;;

  IF NOT vInclEpuiz AND NOT vToateArt THEN
    vInsert := vInsert||&apos;
    AND SR.CANT &lt;&gt; 0&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_STOCREAL&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_STOCPER&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_IES_PER&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_STOCREZ&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_STOCCOM&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE TMP_LST_STOCEP_LAST_NS&apos;, aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(vInsSTOCREAL, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(vInsSTOCPER,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(vInsSTOCREZ,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(vInsSTOCCOM,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(vInsIES_PER,  aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(vInsLAST_NS,  aListID, aListVer);
  if vToateArt then
    LIST_EXECUTE_IMMEDIATE(vInsFaraIES_PER,  aListID, aListVer);
  end if;  

  LIST_EXECUTE_IMMEDIATE(vInsert,      aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_STOCEP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCEXP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B064D23769892DA5B3AEC6A515F508E9F8DEECDF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stocexp IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GETROOTCODNIR(pCODNIRSTOC IN NUMBER) RETURN NUMBER
IS
  vCodNir NIR.CodNir%TYPE;
BEGIN
  SELECT CODNIR INTO vCodNir
  FROM (
    SELECT CODNIR, CONNECT_BY_ISLEAF FRUNZA
    FROM NIRSTOC
    START WITH CODNIRSTOC = pCODNIRSTOC
    CONNECT BY PRIOR CODNIRSTOCPARINTE = CODNIRSTOC
  )
  WHERE FRUNZA = 1;

  RETURN vCodNir;
END;


PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      CLOB;
  vZiuaFin     DATE           := PKG_LIST_SELECTSCAD.DataScad;
  sZiuaFin     VARCHAR2(  100):= &apos;To_date(&apos;&apos;&apos;||To_Char(vZiuaFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  vToateGest   BOOLEAN        := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt  BOOLEAN        := PKG_LIST_SELECTSCAD.ToateIoart;
  vAduSerii    BOOLEAN        := PKG_LIST_SELECTSCAD.Extra2;
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  sColSerie    VARCHAR2(100)  := &apos;, NULL SERIE&apos;;
  sJoinSerie   VARCHAR2(100)  := &apos;&apos;;
  sGrupSerie   VARCHAR2(100)  := &apos;&apos;;
  sFiltru      VARCHAR2(1000) := &apos;&apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NIR ROOTNIR, NGEST NG, IOART IO, INTRARI I, NLOCATII NL, NUM NUM, NPART NFURN, NSUBUNIT NSUB, NGEST NGP, NPART NPROD&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  IF vAduSerii THEN
    sColSerie   := &apos;, SER.SERIE&apos;;
    sJoinSerie  := &apos;
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE&apos;;
    sGrupSerie  := &apos;, SER.SERIE&apos;;
  END IF;

  if NOT vToateIOArt then
    sFiltru := sFiltru || &apos;
        AND NS.CODIOART IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; ) &apos;;
  end if;
  if NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
    if vCateLGest = 0 then
      sFiltru := sFiltru || &apos;
        AND NIR.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; ) &apos;;
    elsif vCateGest = 0 then
      sFiltru := sFiltru || &apos;
        AND NS.CODLOCATIE IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; ) &apos;;
    else
      sFiltru := sFiltru || &apos;
        AND (NIR.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; ) OR
             NS.CODLOCATIE IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
    end if;
  end if;


  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||
    &apos;( CodObiect, Gest, LGest, Cont, Articol, UM, Stoc, Valoare, TG, Serie, MG, DataIn, PretAchiz, PretInreg, Furn, CodExtern, CodIntern, Producator, Provizion&apos;||gUserFields||&apos;)
  WITH
    STOCTG AS (
      SELECT
        NS.CODOBIECT, NS.CODNIR, NS.CODLOCATIE, NS.CODIOART, IO1.MG, NS.PRET, NS.ADAOS,NS.PROVIZION, NIR.GEST,
        SUM(COALESCE(NSER.REST,NS.REST)) REST, COALESCE(NSER.TG,NS.TG) TG&apos;||sColSerie||&apos;,
        CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN NS.CODNIR ELSE PKG_LIST_BASE_STOCEXP.GETROOTCODNIR(NS.CODNIRSTOCPARINTE) END ROOTCODNIR
      FROM NIRSTOC NS
        INNER JOIN NIR          ON NIR.CODNIR      = NS.CODNIR
        INNER JOIN NARTOBJ NAO  ON NAO.CODOBIECT   = NS.CODOBIECT
        INNER JOIN NART    NA   ON NA.CODARTICOL   = NAO.CODARTICOL
        INNER JOIN IOART1  IO1  ON IO1.CODIOART    = NS.CODIOART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IO1.ALStart and IO1.ALStop
        LEFT  JOIN  NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC &apos;||sJoinSerie||&apos;
      WHERE IO1.MG &lt;&gt; 5
        AND (COALESCE(NSER.TG,NS.TG) IS NOT NULL) AND (COALESCE(NSER.TG,NS.TG) &lt;= &apos;||sZiuaFin||&apos;)
        AND COALESCE(NSER.REST, NS.REST) &gt; 0&apos;||
        sFiltru||&apos;
      GROUP BY
        NS.CODOBIECT, NS.CODNIR, NS.CODLOCATIE, NS.CODIOART, NS.PRET, NS.ADAOS, NS.PROVIZION, COALESCE(NSER.TG,NS.TG)&apos;||sGrupSerie||&apos;,NIR.GEST,
        CASE WHEN NS.CODNIRSTOCPARINTE IS NULL THEN NS.CODNIR ELSE PKG_LIST_BASE_STOCEXP.GETROOTCODNIR(NS.CODNIRSTOCPARINTE) END, IO1.MG
      )
  SELECT
    NAO.CodObiect, NG.DEN_GEST, NL.DENUMIRE, IO.DEN_IOART, NAO.DENUMIRE, NUM.DEN_UM, STG.REST, STG.REST * STG.PRET, STG.TG, STG.SERIE,
    DECODE(STG.MG,1,&apos;&apos;FIFO&apos;&apos;,2,&apos;&apos;LIFO&apos;&apos;,3,&apos;&apos;PMP&apos;&apos;,4,&apos;&apos;IDS&apos;&apos;,NULL), ROOTNIR.DATANIR,
    STG.PRET - STG.ADAOS, STG.PRET, DECODE(I.TIPDOC,6,NSUB.DEN_SUBUNIT,7,NGP.DEN_GEST,NFURN.DEN_PART),
    NAO.CODEXTERN, NAO.CODINTERN, NPROD.DEN_PART, STG.PROVIZION&apos;||gUserAlias||&apos;
  FROM STOCTG STG
    INNER JOIN NARTOBJ  NAO     ON NAO.CODOBIECT   = STG.CODOBIECT
    INNER JOIN NART     NA      ON NA.CODARTICOL   = NAO.CODARTICOL
    INNER JOIN NIR      ROOTNIR ON ROOTNIR.CODNIR  = STG.ROOTCODNIR
    INNER JOIN NGEST    NG      ON NG.CODGEST      = STG.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    INNER JOIN IOART    IO      ON IO.CODIOART     = STG.CODIOART
    LEFT  JOIN INTRARI  I       ON I.CODINTR       = ROOTNIR.CODINTR
    LEFT  JOIN NLOCATII NL      ON NL.CODLOCATIE   = STG.CODLOCATIE
    LEFT  JOIN NUM              ON NUM.CODUM       = NA.UM
    LEFT  JOIN NPART    NFURN   ON NFURN.CODPART   = I.PARTENER
    LEFT  JOIN NSUBUNIT NSUB    ON NSUB.CODSUBUNIT = I.CODSUBUNIT
    LEFT  JOIN NGEST    NGP     ON NGP.CODGEST     = I.CODGESTPROD
    LEFT  JOIN NPART    NPROD   ON NPROD.CODPART   = NAO.CODPRODUCATOR&apos;||
    gSuplJoins||&apos;
  WHERE STG.REST &lt;&gt; 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
 PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCEXP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCFARAMISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFC83EADF6FC008412EF60A0FC863E54AC711A44</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stocfaramisc IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vToateGest   BOOLEAN        := PKG_LIST_SELECTSCAD.ToateGest;
  vToateIOArt  BOOLEAN        := PKG_LIST_SELECTSCAD.ToateIoart;
  vInclNoStoc  BOOLEAN        := PKG_LIST_SELECTSCAD.Extra1;
  vSerii       BOOLEAN        := PKG_LIST_SELECTSCAD.Extra2;
  vCateGest    INTEGER        := 0;
  vCateLGest   INTEGER        := 0;
  vZiuaIni     DATE           := PKG_LIST_SELECTSCAD.DataIni;
  vZiuaFin     DATE           := PKG_LIST_SELECTSCAD.DataScad;
  sZiuaIni     VARCHAR2( 100) := &apos;To_date(&apos;&apos;&apos;||To_Char(vZiuaIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sZiuaFin     VARCHAR2( 100) := &apos;To_date(&apos;&apos;&apos;||To_Char(vZiuaFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  sFiltruStoc  VARCHAR2(5000) := &apos;&apos;;
  sWhere       VARCHAR2(5000) := &apos;&apos;;
  sAux         VARCHAR2( 300) := &apos;&apos;;
  sJoinNIR     VARCHAR2( 200) := &apos;&apos;;
  sJoinNGest   VARCHAR2( 200) := &apos;&apos;;
  sJoinStoc    VARCHAR2( 200) := &apos;INNER&apos;;
  sExclLivrPer VARCHAR2(1000) := &apos;&apos;;
  sExclNirPer  VARCHAR2(1000) := &apos;&apos;;
  sSerie       VARCHAR2( 200) := &apos; 0 &apos;;
  sCantNir     VARCHAR2( 200) := &apos;NS.CANTNIR&apos;;
  sJoinSer     VARCHAR2( 200) := &apos;&apos;;
  sFiltruL     VARCHAR2( 200) := &apos;&apos;;
  sSGroup      VARCHAR2( 200) := &apos;&apos;;
  sDenGest     VARCHAR2( 200) := &apos;&apos;;
  sCampSer     VARCHAR2( 200) := &apos;&apos;;
  sCodGest     VARCHAR2( 200) := &apos;N.Gest&apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM, NPART PROD, NCONT NC, NCLASEA CLS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  IF NOT vToateGest THEN
    SELECT COUNT(1) INTO vCateGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;

    IF    vCateLGest = 0 THEN
      sFiltruStoc := sFiltruStoc || &apos;
        AND N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
    ELSIF vCateGest = 0  THEN
      sFiltruStoc := sFiltruStoc || &apos;
        AND NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;) &apos;;
    ELSE
      sFiltruStoc := sFiltruStoc || &apos;
        AND (N.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
    END IF;
  END IF;

  IF NOT vToateIOArt THEN
    sFiltruStoc := sFiltruStoc || &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
  END IF;

  sAux := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;,&apos;
        AND&apos;);
  IF sAux IS NOT NULL THEN
    sJoinNIR := &apos;
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;;
    sJoinNGest := &apos;
        INNER JOIN NGEST G ON G.CODGEST = N.GEST&apos;;
    sFiltruStoc := sFiltruStoc ||sAux;
  END IF;

  IF vSerii THEN
    sSerie    := &apos; NSER.&apos;;
    sCantNir  := &apos;COALESCE(NSER.CANTNIR,NS.CANTNIR,0)&apos;;
    sCampSer  := &apos;, L1.CODNIRSER&apos;;
    sJoinSer  := &apos;
        LEFT JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC&apos;;
    sFiltruL  := &apos; AND NVL(L.CODNIRSER,0) = NVL(NSER.CODNIRSER,0)&apos;;
    sSGroup   := sSGroup||&apos;, NSER.CODSERIE&apos;;
  END IF;

  CASE PKG_LIST_SELECTSCAD.Centralizat
    WHEN 1 THEN sDenGest  := &apos;NG.&apos;;        sSGroup  := sSGroup||&apos;, N.GEST&apos;;
    WHEN 2 THEN sDenGest  := &apos;NG.&apos;;        sSGroup  := sSGroup||&apos;, N.GEST&apos;;
    ELSE        sDenGest  := &apos;&apos;&apos;FIRMA&apos;&apos; &apos;; sCodGest := &apos;NULL Gest&apos;;
  END CASE;
  sSGroup  := sSGroup||&apos;, NS.CODIOART&apos;;

  IF PKG_LIST_SELECTSCAD.Centralizat &lt;&gt; 0 THEN -- Transferurile, modificarile de pret, iesirile catre subunitati nu ar trebui considerate miscari cand lista este generata &quot;Centralizat, fara evidenta gestiunilor&quot; (Ticket : 25687)
    sExclLivrPer := &apos;
            WHEN L.TIPLIVR IN (6,12,13,23) THEN 0&apos;;
    sExclNirPer  := &apos;
            WHEN N.TIPNIR IN  (6,12,13,23) THEN 0&apos;;
  END IF;

  IF vInclNoStoc THEN --includ articole fara stoc
    sJoinStoc := &apos;LEFT&apos;;
  END IF;
  IF NOT vToateGest AND vInclNoStoc AND vCateGest &lt;&gt; 0 THEN
    sWhere    := &apos;
    AND (S.CODOBIECT IS NOT NULL OR NA.GESTIMPLICITA IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;))&apos;;
  ELSIF NOT vToateGest AND vInclNoStoc AND vCateGest = 0 THEN
    sJoinStoc := &apos;INNER&apos;;
  END IF;

  IF NOT vToateIOArt AND vInclNoStoc THEN
    sWhere := sWhere||&apos;
    AND (S.CODOBIECT IS NOT NULL OR NA.CONTIMPLICIT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;))&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    CodObiect, Art,Ser,Gest,TipCont,Cont,UM,Stoc,PrInreg,ValInreg,MG,
    CodExt,CodInt,Prod,Promise,Last_Furn,Last_DataAchiz,Last_PretAchiz &apos;||gUserFields||&apos;)
  WITH
  PROMISE AS (
    SELECT c1.codobiect, Sum(nvl(c1.restacceptat,0) - nvl(rr.cant,0)) cant
    FROM comanda1 c1
      INNER JOIN comanda c ON c1.codcomanda = c.codcomanda
      LEFT JOIN (
        SELECT r.codcomanda1, CASE WHEN Nvl(r.codobiect,0) = 0 THEN cc1.codobiect ELSE r.codobiect END codobiect, Sum(r.rest) cant
        FROM rezervats r INNER JOIN comanda1 cc1 on r.codcomanda1 = cc1.codcomanda1
        WHERE r.codnirstoc &gt; 0
        GROUP BY r.codcomanda1, CASE WHEN Nvl(r.codobiect,0) = 0 THEN cc1.codobiect ELSE r.codobiect END
      ) rr ON rr.codcomanda1 = c1.codcomanda1 and c1.codobiect = rr.codobiect
    WHERE c.operat = 1 and c.anulat = 0 and c.tipdoc = 18 and nvl(c.tiptranzactie,0) = 0
      AND c1.termen BETWEEN &apos;||sZiuaIni||&apos; AND &apos;||sZiuaFin||&apos;
    GROUP BY c1.codobiect ),
  L AS (
    SELECT l1.codnirstoc&apos;||sCampSer||&apos;,
      SUM(Decode(L.TIPLIVR,15,1,-1) * L1.CANT) CANTIES,
      SUM(CASE&apos;||
            sExclLivrPer ||&apos;
            WHEN L.DATALIVR &gt;= &apos;||sZiuaIni||&apos; THEN 1
            ELSE 0
          END
      ) LIVR_PER
    FROM LIVR L
      INNER JOIN livr1   l1 ON l1.codlivr    = l.codlivr
      INNER JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc&apos;||
      sJoinNIR||
      sJoinNGest||&apos;
    WHERE L.DATALIVR &lt;= &apos;||sZiuaFin||
      sFiltruStoc ||&apos;
    GROUP BY l1.codnirstoc&apos;||sCampSer||&apos; ),
  STOC AS (
    SELECT
      NS.CODOBIECT, &apos;||sSerie||&apos;CODSERIE, &apos;||sCodGest||&apos;, NS.CODIOART,
      SUM(&apos;||sCantNir||&apos;+NVL(L.CANTIES,0)) CANT, SUM((&apos;||sCantNir||&apos;+NVL(L.CANTIES,0)) * NS.PRET) VALINREG,
      SUM(CASE&apos;||
            sExclNirPer||&apos;
            WHEN N.DATANIR &gt;= &apos;||sZiuaIni||&apos; THEN 1
            ELSE 0
          END
      ) INTR_PER,
      SUM(NVL(L.LIVR_PER,0)) LIVR_PER
    FROM NIR N
      INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR&apos;||
      sJoinNGest||
      sJoinSer||&apos;
      LEFT JOIN          L  ON L.CODNIRSTOC = NS.CODNIRSTOC&apos;||sFiltruL||&apos;
    WHERE N.OPERAT = 1 and N.DATANIR &lt;= &apos;||sZiuaFin||
      sFiltruStoc ||&apos;
    GROUP BY NS.CODOBIECT&apos;||sSGroup||&apos;),
  LM AS (
    SELECT
      DISTINCT
      NS.CODOBIECT,
      LAST_VALUE(P.DEN_PART) IGNORE NULLS
      OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
            UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_FURN,
      LAST_VALUE(N.DATANIR) IGNORE NULLS
      OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
            UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_DATAACHIZ,
      LAST_VALUE(NS.PRET) IGNORE NULLS
      OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN
            UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_PRETACHIZ      
    FROM NIR N
      INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
      INNER JOIN NGEST   G  ON G.CODGEST = N.GEST
      LEFT  JOIN INTRARI I  ON I.CODINTR = N.CODINTR
      LEFT  JOIN NPART   P  ON P.CODPART = I.PARTENER
    WHERE N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;)
  SELECT
    NAO.CodObiect, NAO.DENUMIRE, SER.SERIE, &apos;||sDenGest||&apos;DEN_GEST, IO.DEN_IOART, NC.SIMBOL, NUM.DEN_UM, Nvl(S.CANT,0), NVL(S.VALINREG/S.CANT,0), NVL(S.VALINREG,0), DECODE(IO1.MG,1,&apos;&apos;FIFO&apos;&apos;,2,&apos;&apos;LIFO&apos;&apos;,3,&apos;&apos;PMP&apos;&apos;,4,&apos;&apos;IDS&apos;&apos;,5,&apos;&apos;VALORIC&apos;&apos;,NULL),
    NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART PRODUCATOR, Nvl(Promise.Cant,0),LM.Last_Furn,LM.Last_DataAchiz,LM.Last_PretAchiz &apos;||gUserAlias||&apos;
  FROM NARTOBJ NAO
    INNER JOIN NART   NA   ON NA.CODARTICOL     = NAO.CODARTICOL
    &apos;||sJoinStoc||&apos; JOIN STOC S ON S.CODOBIECT  = NAO.CODOBIECT
    LEFT JOIN LM           ON LM.CODOBIECT      = NAO.CODOBIECT
    LEFT JOIN PROMISE      ON PROMISE.CODOBIECT = NAO.CODOBIECT
    LEFT JOIN NCLASEA CLS  ON NA.CLASA          = CLS.CODCLASEA
    LEFT JOIN NSERII  SER  ON SER.CODSERIE      = S.CODSERIE
    LEFT JOIN NGEST   NG   ON NG.CODGEST        = COALESCE(S.GEST, NA.GESTIMPLICITA, 0)
    LEFT JOIN IOART   IO   ON IO.CODIOART       = COALESCE(S.CODIOART, NA.CONTIMPLICIT, 0)
    LEFT JOIN IOART1  IO1  ON IO1.CODIOART      = COALESCE(S.CODIOART, NA.CONTIMPLICIT, 0) AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IO1.ALStart and IO1.ALStop
    LEFT JOIN NUM          ON NUM.CODUM         = NA.UM
    LEFT JOIN NPART   PROD ON PROD.CODPART      = NAO.CODPRODUCATOR
    LEFT JOIN NCONT   NC   ON NC.CODCONT        = IO1.CONT&apos;||
    gSuplJoins||&apos;
  WHERE NVL(S.CANT,-1) &lt;&gt; 0 AND NVL(S.INTR_PER,0) = 0 AND NVL(S.LIVR_PER,0) = 0 AND NA.TIPARTICOL = 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_STOCFARAMISC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFDA27E8F4C74035EC36DC9D4E3FC40892A9705F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stocofe IS

  vAllArt      BOOLEAN;
  vServicii    BOOLEAN;
  vTipPret     INTEGER;
  vTipCalcul   INTEGER;
  vCodMoneda   INTEGER;
  vAllIoart    BOOLEAN;
  vAllGest     BOOLEAN;
  vAllAdaos    BOOLEAN;
  vNrCol       INTEGER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  K     INTEGER := 0;
BEGIN
  DELETE tmp_dinamic_cols;
  IF vTipPret = 1 THEN
    FOR v_rec IN (
      SELECT CODCATPRET, DEN_CATPRET
      FROM ncatpret
      WHERE CODCATPRET &lt;&gt; 0
      ORDER BY CODCATPRET)
    LOOP
      k := k + 1;
      INSERT INTO tmp_dinamic_cols(FieldName, Display, Cod, IndexLocal) VALUES (&apos;P&apos;||to_char(k), v_rec.DEN_CATPRET, v_rec.CODCATPRET, k);
      IF vAllAdaos THEN
        k := k + 1;
        INSERT INTO tmp_dinamic_cols(FieldName, Display, Cod, IndexLocal) VALUES (&apos;P&apos;||to_char(k), &apos;%Adaos/&apos;||v_rec.DEN_CATPRET, v_rec.CODCATPRET, k);
      END IF;
    END LOOP;
  END IF;
  COMMIT;
  vNrCol := k;
END;

PROCEDURE SETPARAMS( pAllArt     IN NUMBER   DEFAULT 1,
                     pServicii   IN NUMBER   DEFAULT 1,
                     pTipPret    IN INTEGER  DEFAULT NULL,
                     pTipCalcul  IN INTEGER  DEFAULT NULL,
                     pCodMoneda  IN INTEGER  DEFAULT NULL,
                     pAllGest    IN NUMBER   DEFAULT 1,
                     pAllIoart   IN NUMBER   DEFAULT 1,
                     pAllAdaos   IN NUMBER   DEFAULT 0,
                     pCodjob1    IN NUMBER   DEFAULT 0)
IS
BEGIN
  vAllArt      := pAllArt = 1;
  vServicii    := pServicii = 1;
  vTipPret     := pTipPret;
  vTipCalcul   := pTipCalcul;
  vCodMoneda   := pCodMoneda;
  vAllIoart    := pAllIoart = 1;
  vAllGest     := pAllGest = 1;
  vAllAdaos    := pAllAdaos = 1;
  BAGA_DINAMIC_COLS;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect1   VARCHAR2(10000);
  sSelect2   VARCHAR2(10000);
  sUpdate1   VARCHAR2(10000) := &apos;&apos;;
  sUpdate2   VARCHAR2(10000) := &apos;&apos;;
  sUpd1Col1  VARCHAR2(10000) := &apos;&apos;;
  sUpd1Col2  VARCHAR2(10000) := &apos;&apos;;
  sUpd2Col1  VARCHAR2(10000) := &apos;&apos;;
  sCondStoc  VARCHAR2( 5000) := &apos;&apos;;
  sCondServ  VARCHAR2( 5000) := &apos;&apos;;
  sCondPM    VARCHAR2( 5000) := &apos;&apos;;
  vLeiVal    VARCHAR2(  100) := &apos;&apos;;
  sTempPret  VARCHAR2(  100) := &apos;&apos;;
  vCateGest  INTEGER         := 0;
  vCateLGest INTEGER         := 0;
  k          INTEGER         := 0;
BEGIN
  gSuplCols := &apos;nart a, nartobj o&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF vCodMoneda = 0
  THEN vLeiVal := &apos;lei&apos;;
  ELSE vLeiVal := &apos;valuta&apos;;
  END IF;

  IF NOT vAllGest THEN
    SELECT COUNT(1) INTO vCateGest  FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos;;
    SELECT COUNT(1) INTO vCateLGest FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODLOCATIE&apos;;
  END IF;

  IF NOT vAllArt THEN
    sCondStoc := sCondStoc||&apos;
      AND ns.codobiect in ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
    sCondServ := sCondServ||&apos;
    AND o.codobiect in ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; ) &apos;;
  END IF;

  IF NOT vAllIoart THEN
    sCondStoc := sCondStoc||&apos;
      AND ns.codioart IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; ) &apos;;
  END IF;

  IF    vCateGest &gt; 0 AND vCateLGest = 0 THEN
    sCondStoc := sCondStoc||&apos;
      AND nir.gest IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  ELSIF vCateGest = 0 AND vCateLGest &gt; 0 THEN
    sCondStoc := sCondStoc||&apos;
      AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; AND VALOARE = ns.codlocatie) &apos;;
  ELSIF vCateGest &gt; 0 AND vCateLGest &gt; 0 THEN
    sCondStoc := sCondStoc||&apos;
      AND (NIR.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR NS.CODLOCATIE IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)) &apos;;
  END IF;

  IF vCateGest &gt; 0 THEN
    sCondServ:=sCondServ||&apos;
    AND a.gestimplicita IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos; ) &apos;;
  END IF;

  CASE vTipCalcul
    WHEN 0 then sTempPret := &apos;sum(ns.rest) cantstoc, max(ns.pret-ns.adaos)&apos;;
    WHEN 1 then sTempPret := &apos;sum(ns.rest) cantstoc, max(ns.pret-ns.adaos) keep (dense_rank last order by nir.datanir)&apos;;
    WHEN 2 then sTempPret := &apos;sum(ns.rest) cantstoc, max(ns.pret)&apos;;
  END CASE;

  if vCodMoneda &lt;&gt; 0 then
    sCondPM := sCondPM||&apos; AND pm.moneda = &apos;||vCodMoneda;
  end if;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(Art, UM, CatPr, PrImplicit, PrInreg, Stoc, ValStoc, ValLivr, Subunit, CodObiect, CodSubunit&apos;||gUserFields||&apos;)&apos;;

  sSelect1:= &apos;
  WITH stoc as (
    SELECT ns.codobiect, ng.codsubunit, &apos;||sTempPret||&apos; temppret
    FROM nirstoc ns
      inner join nir on nir.codnir = ns.codnir
      inner join ngest ng on ng.codgest = nir.gest &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;ng&apos;,&apos;codsubunit&apos;)||&apos;
    WHERE rest &lt;&gt; 0 &apos;||sCondStoc||&apos;
    GROUP BY ns.codobiect, ng.codsubunit )
  SELECT o.denumire, u.den_um, cp.den_catpret, pm.&apos;||vLeiVal||&apos;, s.temppret, s.cantstoc, pm.&apos;||vLeiVal||&apos; * s.cantstoc, s.temppret * s.cantstoc, sub.den_subunit, o.codobiect, sub.codsubunit &apos;||gUserAlias||&apos;
  FROM stoc s
    INNER JOIN nartobj o on o.codobiect = s.codobiect
    INNER JOIN nart a on a.codarticol = o.codarticol
    INNER JOIN num u on u.codum = a.um
    INNER JOIN pretm pm on pm.codobiect = s.codobiect AND pm.subunitatea = s.codsubunit AND pm.implicit = 1 &apos;||sCondPM||&apos;
    INNER JOIN ncatpret cp on cp.codcatpret = pm.codcatpret
    INNER JOIN nsubunit sub ON sub.codsubunit = s.codsubunit&apos;||
    gSuplJoins;

  sSelect2:=&apos;
  SELECT o.denumire, u.den_um, cp.den_catpret, pm.&apos;||vLeiVal||&apos; , 0, 0, 0, 0, sub.den_subunit, o.codobiect, sub.codsubunit &apos;||gUserAlias||&apos;
  FROM nart a
    INNER JOIN nartobj o on o.codarticol = a.codarticol
    INNER JOIN num u on u.codum = a.um
    LEFT  JOIN ngest ng on ng.codgest = a.gestimplicita
    LEFT  JOIN pretm pm on pm.codobiect = o.codobiect AND pm.subunitatea = ng.codsubunit AND pm.implicit = 1 &apos;||sCondPM||&apos;
    LEFT  JOIN ncatpret cp on cp.codcatpret = pm.codcatpret
    LEFT  JOIN nsubunit sub ON sub.codsubunit = Nvl(ng.codsubunit,0)&apos;||
    gSuplJoins||&apos;
  WHERE a.tiparticol = 1 &apos;||sCondServ;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  IF vServicii THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  END IF;

  IF vNrCol &gt; 0 THEN
    k := 0;
    WHILE k &lt; vNrCol LOOP
      k := k + 1;
      sUpd1Col1 := sUpd1Col1||&apos;,P&apos;||k;
      sUpd1Col2 := sUpd1Col2||&apos;,Max(Decode(x.indexlocal,&apos;||k||&apos;,pm.&apos;||vLeiVal||&apos;,0)) &apos;;
      IF vAllAdaos THEN
        k := k + 1;
        sUpd2Col1 := sUpd2Col1||&apos;,P&apos;||k||&apos; = (P&apos;||To_Char(k-1)||&apos; / PrInreg -1) * 100&apos;;
      END IF;
    END LOOP;

    sUpd1Col1 := SUBSTR(sUpd1Col1,2);
    sUpd1Col2 := SUBSTR(sUpd1Col2,2);
    sUpd2Col1 := SUBSTR(sUpd2Col1,2);

    sUpdate1 := &apos;UPDATE &apos;||tmpName||&apos; t SET ( &apos;||sUpd1Col1||&apos; ) = ( SELECT &apos;||sUpd1Col2||&apos; FROM pretm pm INNER JOIN tmp_dinamic_cols x ON x.Cod = pm.CodCatPret WHERE pm.codobiect = t.codobiect AND pm.subunitatea = t.codsubunit &apos;||sCondPM||&apos;)&apos;;
    sUpdate2 := &apos;UPDATE &apos;||tmpName||&apos; SET &apos;||sUpd2Col1||&apos; WHERE Nvl(PrInreg,0) &lt;&gt; 0&apos;;

    LIST_EXECUTE_IMMEDIATE(sUpdate1, aListID, aListVer);
    IF vAllAdaos THEN
      LIST_EXECUTE_IMMEDIATE(sUpdate2, aListID, aListVer);
    END IF;

  END IF;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_StocOfe;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCPROGNOZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE3959EFA9974D965EB5E4AD78B2DFFA720CD712</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOCPROGNOZA IS

  vToateArt       BOOLEAN;
  vComSubunit     BOOLEAN;
  vConsum         BOOLEAN;
  vToateGestStoc  BOOLEAN;
  vExclNeconforme BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pToateArt       IN NUMBER DEFAULT 1,
                     pComSubunit     IN NUMBER DEFAULT 1,
                     pConsum         IN NUMBER DEFAULT 1,
                     pToateGestStoc  IN NUMBER DEFAULT 1,
                     pExclNeconforme IN NUMBER DEFAULT 0)
IS
BEGIN
  vToateArt       := pToateArt = 1;
  vComSubunit     := pComSubunit = 1;
  vConsum         := pConsum = 1;
  vToateGestStoc  := pToateGestStoc = 1;
  vExclNeconforme := pExclNeconforme = 1;
END;

FUNCTION FiltruObj (COL IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
  IF not vToateArt THEN
    RETURN &apos;
        AND &apos;||COL||&apos; IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; )&apos;;
  ELSE
    RETURN NULL;
  END IF;
END;

FUNCTION FiltruGestStoc(COL IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
  IF not vToateGestStoc THEN
    RETURN &apos;
        AND &apos;||COL||&apos; IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos; )&apos;;
  ELSE
    RETURN NULL;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sColMinMax VARCHAR2(  100):= &apos;, NAOS.STOCMIN, NAOS.STOCMAX &apos;;
  sJoinExt   VARCHAR2(1000);
  sNeconforme VARCHAR2(50);
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NARTOBJSUBUNIT NAOS, NUM NUM, NCLASEA CLS, NARTOBJ POBJ&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,    &apos;COM&apos;,  &apos;COM.CODCOMANDA = P.CODCOMANDA&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;,   &apos;COM1&apos;, &apos;COM1.CODCOMANDA1 = P.CODCOMANDA1&apos;, 1);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_GLOBALS.GETSUBUNITATE = 1 THEN
    sColMinMax  := &apos;, NAO.STOCMIN, NAO.STOCMAX&apos;;
  END IF;

  sNeconforme := &apos;&apos;;
  if vExclNeconforme then
    sNeconforme := &apos; and coalesce(g.tip,0) &lt;&gt; 4 &apos;;
  end if;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;( Art,UM,Termen,TipTranz,CantIn,CantIes,Stoc,Obs,PrefDoc,NrCom,DataCom,Ord,CodExt,CodInt, Produs,StocMin,StocMax&apos;||gUserFields||&apos; )
  WITH PROGNOZA AS (
    SELECT
      NS.CODOBIECT, 0 CODCOMANDA, 0 CODCOMANDA1, 0 ORD,
      NULL TERMEN, &apos;&apos;Stoc la moment&apos;&apos; TIPTRANZ, NULL PREFIXDOC, 0 CANTIES, NVL(SUM(REST),0) CANTIN,
      NULL OBS, NULL NRCOM, NULL DATACOM, NULL PRODUS, 0 CODPRODUS
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    WHERE 1 = 1 &apos;||FiltruObj(&apos;NS.CODOBIECT&apos;)||FiltruGestStoc(&apos;N.GEST&apos;)||sNeconforme||&apos;
    GROUP BY CODOBIECT
    UNION ALL
    SELECT
      CODOBIECT, CODCOMANDA, CODCOMANDA1,
      Row_Number() OVER (PARTITION BY CODOBIECT ORDER BY Nvl(TERMEN, DATACOM)) ORD,
      TERMEN, TIPTRANZ, PREFIXDOC, CANTIES, CANTIN, 
      OBS, NRCOM, DATACOM, PRODUS, CODPRODUS
    FROM (
      SELECT -- comenzi clienti / furnizori
        C1.CODOBIECT, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(C.TIPDOC) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        DECODE(C.TIPDOC,18,RESTACCEPTAT,0) CANTIES, DECODE(C.TIPDOC,8,RESTACCEPTAT,0) CANTIN,
        NPART.DEN_PART OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, NULL PRODUS, 0 CODPRODUS
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
        INNER JOIN NPART ON NPART.CODPART = C.PARTENER
      WHERE C.TIPDOC IN (8,18) AND C.OPERAT = 1 AND C.ANULAT = 0
        AND NVL(C.INCHISA,0) = 0 AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
        FiltruObj(&apos;C1.CODOBIECT&apos;)||&apos;
      UNION ALL
      SELECT -- comenzi catre subunitati
        C1.CODOBIECT, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(C.TIPDOC) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        0 CANTIES, RESTACCEPTAT CANTIN,
        S.DEN_SUBUNIT OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, NULL PRODUS, 0 CODPRODUS
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = C.SUBUNITSURSA
      WHERE C.TIPDOC = 44 AND C.OPERAT = 1 AND C.ANULAT = 0
        AND NVL(C.INCHISA,0) = 0 AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
        FiltruObj(&apos;C1.CODOBIECT&apos;)||&apos;
      UNION ALL
      SELECT -- comenzi de la subunitati
        C1.CODOBIECT, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(60) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        RESTACCEPTAT CANTIES, 0 CANTIN,
        S.DEN_SUBUNIT OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, NULL PRODUS, 0 CODPRODUS
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = C.SUBUNITATEA
      WHERE C.TIPDOC = 44 AND C.OPERAT = 1 AND C.ANULAT = 0
        AND NVL(C.INCHISA,0) = 0 AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;, &apos;SubunitSursa&apos;)||
        FiltruObj(&apos;C1.CODOBIECT&apos;)||&apos;
      UNION ALL
      SELECT -- comenzi gestiuni
        C1.CODOBIECT, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(C.TIPDOC) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        RESTACCEPTAT CANTIES, 0 CANTIN,
        G.DEN_GEST OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, NULL PRODUS, 0 CODPRODUS
      FROM COMANDA1 C1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NGEST G ON G.CodGest = C.CodGest
      WHERE C.TIPDOC = 43 AND C.OPERAT = 1 AND C.ANULAT = 0 AND Nvl(G.Tip,0) = 1
        AND NVL(C.INCHISA,0) = 0 AND C1.RESTACCEPTAT &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
        FiltruObj(&apos;C1.CODOBIECT&apos;)||&apos;
      UNION ALL
      SELECT -- comenzi interne intrare
        CMDMAT.CodObiect, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(C.TIPDOC) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        0 CANTIES, CMDMAT.Rest CANTIN,
        G.DEN_GEST OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, O.DENUMIRE PRODUS, O.CODOBIECT
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
        LEFT  JOIN NGEST G ON G.CodGest = C.CodGest
      WHERE C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0 AND NVL(C.INCHISA,0) = 0 AND CMDMAT.REST &gt; 0
        AND ((C1.Consum = 1 AND CMDMAT.Tip &lt;&gt; 1) OR (C1.Consum = 2 AND CMDMAT.Tip = 2)) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
        FiltruObj(&apos;CMDMAT.CODOBIECT&apos;)||&apos;
      UNION ALL
      SELECT -- comenzi interne iesire
        CMDMAT.CodObiect, C.CODCOMANDA, C1.CODCOMANDA1,
        C1.TERMEN TERMEN, pkg_list_base_utils.decode_tipdoc(C.TIPDOC) TIPTRANZ, C.PREFIXDOC PREFIXDOC,
        CMDMAT.Rest CANTIES, 0 CANTIN,
        G.DEN_GEST OBS, C.NRDOC NRCOM, C.DATADOC DATACOM, O.DENUMIRE PRODUS, O.CODOBIECT
      FROM CMDPRODMAT CMDMAT
        INNER JOIN COMANDA1 C1 ON CMDMAT.CodComanda1 = C1.CodComanda1
        INNER JOIN COMANDA C ON C1.CodComanda = C.CodComanda
        INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
        INNER JOIN CMDPRODMAT PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1 AND PROD.TIP = 0
        LEFT  JOIN NGEST G ON G.CodGest = C.CodGest
      WHERE C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0 AND NVL(C.INCHISA,0) = 0 AND PROD.REST &gt; 0 and CMDMAT.REST &gt; 0
        AND ((C1.Consum = 1 AND CMDMAT.Tip = 1) OR (C1.Consum = 2 AND CMDMAT.Tip &lt;&gt; 2)) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||
        FiltruObj(&apos;CMDMAT.CODOBIECT&apos;)||&apos;
    )
  )
  SELECT NAO.DENUMIRE, NUM.DEN_UM, P.TERMEN, P.TIPTRANZ, case when P.CANTIN &lt; 0 then 0 else P.CANTIN end, case when P.CANTIES &lt; 0 then 0 else P.CANTIES end,
    SUM(case when P.CANTIN &lt; 0 then 0 else P.CANTIN end - case when P.CANTIES &lt; 0 then 0 else P.CANTIES end) OVER(PARTITION BY P.CODOBIECT ORDER BY P.ORD,ROWNUM) STOC,
    P.OBS, P.PREFIXDOC, P.NRCOM, P.DATACOM, P.ORD, NAO.CodExtern, NAO.CodIntern,P.PRODUS&apos;||sColMinMax||gUserAlias||&apos;
  FROM PROGNOZA P
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = P.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NARTOBJSUBUNIT NAOS ON NAOS.CODOBIECT = NAO.CODOBIECT 
                                  and (NAOS.codgest is null or NAOS.codgest = 0)
                                  AND NAOS.SUBUNITATE = &apos;||PKG_GLOBALS.GETSUBUNITATE||&apos;
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN NARTOBJ POBJ ON POBJ.CODOBIECT = P.CODPRODUS
    LEFT JOIN NCLASEA CLS ON CLS.CODCLASEA = NA.CLASA&apos;||gSuplJoins||&apos;
  WHERE NA.TIPARTICOL = 0&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCPROGNOZA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCREZERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C4AF3C8DA19A228D63C6264D7FCDAA976B1BB50</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stocrezerv IS

  vToateArt       BOOLEAN ;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pToateArt IN NUMBER DEFAULT 1) IS
BEGIN
  vToateArt := pToateArt = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;comanda c, comanda1 c1, nartobj nao, nart a, num1 num1, npart np, npart prod, npers npe, nirstoc ns, rezervats r&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    PART ,NRDOC, DATADOC, ART, ARTCOM, CANT, PRET, VALOARE,
    REZERVAT, STOC ,TERMEN,
    AGENT, CODEXTERN, CODINTERN, PROD, CANTUM1, UM1, SERIE&apos;||gUserFields||&apos; )
  WITH STOCART AS (
    SELECT NS.CODOBIECT, SUM(NS.REST) STOC
    FROM NIRSTOC NS
      INNER JOIN IOART1 IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop
      INNER JOIN NIR    N   ON N.CODNIR     = NS.CODNIR
      INNER JOIN NGEST  NG  ON NG.CODGEST   = N.GEST
    WHERE IOA.MG &lt;&gt; 5 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;);
  if not vToateArt then
    sInsert := sInsert|| &apos;
      AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  end if;
  sInsert:= sInsert||&apos;
    GROUP BY CODOBIECT)
  SELECT
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 53, NG.Den_Gest, NP.Den_Part) BENEFICIAR,
    C.NRDOC, C.DATADOC, NAOR.DENUMIRE, NAO.DENUMIRE, C1.RESTACCEPTAT CANT, C1.PU PRET, (C1.RESTACCEPTAT * C1.PU) VALOARE,
    R.REST REZERVAT, SA.STOC , C1.TERMEN,
    (NPE.NUME || &apos;&apos;  &apos;&apos;||NPE.PRENUME) AGENT, NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART, C1.CANTUM1, U1.DEN_UM, S.SERIE&apos;||gUserAlias||&apos;
  FROM REZERVATS R
    INNER JOIN COMANDA1 C1   ON C1.CODCOMANDA1 = R.CODCOMANDA1
    INNER JOIN COMANDA  C    ON C.CODCOMANDA   = C1.CODCOMANDA
    INNER JOIN NIRSTOC  NS   ON NS.CODNIRSTOC  = R.CODNIRSTOC
    LEFT  JOIN NARTOBJ  NAOR ON NAOR.CODOBIECT = NS.CODOBIECT
    LEFT  JOIN NARTOBJ  NAO  ON NAO.CODOBIECT  = C1.CODOBIECT
    LEFT  JOIN NART     A    ON A.CODARTICOL   = NAOR.CODARTICOL
		LEFT  JOIN NUM1          ON NUM1.CODUM1    = C1.UMSEC
    LEFT  JOIN NUM      U1   ON U1.CODUM       = A.UM1
    LEFT  JOIN NPART    NP   ON NP.CODPART     = C.PARTENER
    LEFT  JOIN NSUBUNIT NS   ON NS.CODSUBUNIT  = C.SUBUNITATEA
    LEFT  JOIN NGEST    NG   ON NG.CODGEST     = C.CODGEST
    LEFT  JOIN NPART    PROD ON PROD.CODPART   = NAOR.CODPRODUCATOR
    LEFT  JOIN STOCART  SA   ON SA.CODOBIECT   = NAOR.CODOBIECT
    LEFT  JOIN NPERS    NPE  ON NPE.CODPERS    = C.AGENT
    LEFT  JOIN NIRSER   NSER ON NSER.CODNIRSER = R.CODNIRSER
    LEFT  JOIN NSERII   S    ON S.CODSERIE     = NSER.CODSERIE&apos;||
    gSuplJoins||&apos;
  WHERE R.REST &gt; 0 AND R.CODNIRSTOC &gt; 0 AND NVL(R.CODOBIECT, 0) = 0 &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)&apos;);

  if not vToateArt then
    sInsert := sInsert|| &apos;
    AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  end if;

  sInsert:= sInsert||&apos;
  UNION ALL
  SELECT
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 53, NG.Den_Gest, NP.Den_Part) BENEFICIAR,
    C.NRDOC, C.DATADOC, NAOR.DENUMIRE, NAO.DENUMIRE, C1.RESTACCEPTAT CANT, C1.PU PRET, (C1.RESTACCEPTAT * C1.PU) VALOARE,
    R.REST REZERVAT, SA.STOC , C1.TERMEN,
    (NPE.NUME || &apos;&apos;  &apos;&apos;||NPE.PRENUME) AGENT, NAOR.CODEXTERN, NAOR.CODINTERN, PROD.DEN_PART, C1.CANTUM1, U1.DEN_UM, S.SERIE&apos;||gUserAlias||&apos;
  FROM REZERVATS R
    INNER JOIN COMANDA1 C1   ON C1.CODCOMANDA1 = R.CODCOMANDA1
    INNER JOIN COMANDA  C    ON C.CODCOMANDA   = C1.CODCOMANDA
    INNER JOIN NIRSTOC  NS   ON NS.CODNIRSTOC  = R.CODNIRSTOC
    LEFT  JOIN NARTOBJ  NAOR ON NAOR.CODOBIECT = R.CODOBIECT
    LEFT  JOIN NARTOBJ  NAO  ON NAO.CODOBIECT  = C1.CODOBIECT
    LEFT  JOIN NART     A    ON A.CODARTICOL   = NAOR.CODARTICOL
		LEFT  JOIN NUM1          ON NUM1.CODUM1    = C1.UMSEC
    LEFT  JOIN NUM      U1   ON U1.CODUM       = A.UM1
    LEFT  JOIN NPART    NP   ON NP.CODPART     = C.PARTENER
    LEFT  JOIN NSUBUNIT NS   ON NS.CODSUBUNIT  = C.SUBUNITATEA
    LEFT  JOIN NGEST    NG   ON NG.CODGEST     = C.CODGEST
    LEFT  JOIN NPART    PROD ON PROD.CODPART   = NAOR.CODPRODUCATOR
    LEFT  JOIN STOCART  SA   ON SA.CODOBIECT   = R.CODOBIECT
    LEFT  JOIN NPERS    NPE  ON NPE.CODPERS    = C.AGENT
    LEFT  JOIN NIRSER   NSER ON NSER.CODNIRSER = R.CODNIRSER
    LEFT  JOIN NSERII   S    ON S.CODSERIE     = NSER.CODSERIE&apos;||
    gSuplJoins||&apos;
  WHERE R.REST &gt; 0 AND NVL(R.CODOBIECT, 0) &gt; 0 &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)&apos;);

  if not vToateArt then
    sInsert := sInsert|| &apos;AND R.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  end if;

  sInsert:= sInsert||&apos;
  UNION ALL
  SELECT
    NG.Den_Gest,
    I.NRINVENTAR, I.DATAINVENTAR, NAOR.DENUMIRE, NAO.DENUMIRE, I1.FAPTIC, NS.PRET, (R.REST * NS.PRET) VALOARE,
    R.REST REZERVAT, SA.STOC , NULL TERMEN,
    (NPE.NUME || &apos;&apos;  &apos;&apos;||NPE.PRENUME) AGENT, NAOR.CODEXTERN, NAOR.CODINTERN, PROD.DEN_PART, 0, U1.DEN_UM, S.SERIE&apos;||gUserAlias||&apos;
  FROM REZERVATS R
    INNER JOIN INVENTAR1 I1   ON I1.CODINVENTAR1 = R.CODINVENTAR1
    INNER JOIN INVENTAR  I    ON I.CODINVENTAR   = I1.CODINVENTAR
    INNER JOIN NIRSTOC   NS   ON NS.CODNIRSTOC   = R.CODNIRSTOC
    INNER JOIN NPERS     NPE  ON NPE.CODPERS     = I.RESPONSABIL
    LEFT  JOIN NARTOBJ   NAOR ON NAOR.CODOBIECT  = NS.CODOBIECT
    LEFT  JOIN NARTOBJ   NAO  ON NAO.CODOBIECT   = NS.CODOBIECT
    LEFT  JOIN NART      A    ON A.CODARTICOL    = NAOR.CODARTICOL
		LEFT  JOIN NUM1           ON NUM1.CODUM1     = NS.UMSEC
    LEFT  JOIN NUM       U1   ON U1.CODUM        = A.UM1
    LEFT  JOIN NSUBUNIT  NS   ON NS.CODSUBUNIT   = I.SUBUNITATE
    LEFT  JOIN NGEST     NG   ON NG.CODGEST      = I.GESTIUNE
    LEFT  JOIN NPART     PROD ON PROD.CODPART    = NAOR.CODPRODUCATOR
    LEFT  JOIN STOCART   SA   ON SA.CODOBIECT    = R.CODOBIECT
    LEFT  JOIN NIRSER    NSER ON NSER.CODNIRSER  = R.CODNIRSER
    LEFT  JOIN NSERII    S    ON S.CODSERIE      = NSER.CODSERIE
    LEFT  JOIN COMANDA1  C1   ON C1.CODCOMANDA1  = R.CODCOMANDA1
    LEFT  JOIN COMANDA   C    ON C.CODCOMANDA    = C1.CODCOMANDA &apos;||
    gSuplJoins||&apos;
  WHERE R.REST &gt; 0 AND NVL(R.CODINVENTAR1, 0) &gt; 0 &apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;I.SUBUNITATE&apos;);

  if not vToateArt then
    sInsert := sInsert|| &apos;AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)&apos;;
  end if;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_STOCREZERV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCROTATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1E764C9AC8ACD0906AA336012502A72510DA955</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_stocrotatie IS

  vToateArt       BOOLEAN;
  vDataIni        DATE;
  vDataFin        DATE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pDataIni  IN VARCHAR2,
                     pDataFin  IN VARCHAR2,
                     pToateArt IN NUMBER DEFAULT 1,
                     pCodJob1  IN NUMBER DEFAULT 0)
IS
vAnLunaIni NUMBER(10) := 0;
vAnLunaFin NUMBER(10) := 0;
BEGIN
  vToateArt:= pToateArt = 1;
  vDataIni := to_Date(pDataIni,&apos;DD.MM.YYYY&apos;);
  vDataFin := to_Date(pDataFin,&apos;DD.MM.YYYY&apos;);
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vAnLunaIni,vAnLunaFin);
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  vPerioada  VARCHAR2(60) := &apos;&apos;&apos;&apos;||vDataIni||&apos;&apos;&apos; AND &apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;&apos;;
  vCondArt   VARCHAR2(3000);
  sJoinExt   VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;NIR NIR, NIRSTOC NS, INTRARI I, NARTOBJ NAO, NART NA, NUM NUM, NPART NP, NGEST NG&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if NOT vToateArt then
    vCondArt := &apos; AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = NS.CODOBIECT ) &apos;;
  end if;
  vCondArt := vCondArt ;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (Art, Gest, UM, DataRec, CantRec, Stoc, Furn, TipDoc, NrDoc, DataDoc, Per1, Per2, Per3, Per4, Per5 &apos;||gUserFields||&apos;)
  WITH
    PER_IES AS (
      SELECT ROOTCODNIRSTOC,
              SUM(CASE WHEN L.DATALIVR - N.DATANIR BETWEEN  0 AND  30 THEN L1.CANT ELSE 0 END) AS PER1,
              SUM(CASE WHEN L.DATALIVR - N.DATANIR BETWEEN 31 AND  60 THEN L1.CANT ELSE 0 END) AS PER2,
              SUM(CASE WHEN L.DATALIVR - N.DATANIR BETWEEN 61 AND  90 THEN L1.CANT ELSE 0 END) AS PER3,
              SUM(CASE WHEN L.DATALIVR - N.DATANIR BETWEEN 91 AND 120 THEN L1.CANT ELSE 0 END) AS PER4,
              SUM(CASE WHEN L.DATALIVR - N.DATANIR &gt; 120 THEN L1.CANT ELSE 0 END) AS PER5
      FROM ( SELECT NS.CODNIRSTOC, CONNECT_BY_ROOT NS.CODNIRSTOC ROOTCODNIRSTOC, CONNECT_BY_ROOT NS.CODNIR ROOTCODNIR
              FROM NIRSTOC NS
              WHERE NS.REST &lt;&gt; NS.CANTNIR&apos;||
              vCondArt||&apos;
              START WITH (NS.CODNIRSTOCPARINTE IS NULL)
                    AND (NS.REST &lt;&gt; NS.CANTNIR)
                    AND (EXISTS (SELECT CODNIR
                                  FROM NIR INNER JOIN INTRARI I ON I.CODINTR = NIR.CODINTR
                                  WHERE NIR.CODNIR = NS.CODNIR
                                  AND NIR.DATANIR BETWEEN &apos;||vPerioada||&apos; &apos;||
                                  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
                                )
                        )
              CONNECT BY PRIOR CODNIRSTOC = CODNIRSTOCPARINTE
            ) X
            INNER JOIN NIR N ON N.CODNIR = X.ROOTCODNIR
            INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = X.CODNIRSTOC
            INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
      WHERE L.CODIES IS NOT NULL
      GROUP BY ROOTCODNIRSTOC
    )
  SELECT
    NAO.DENUMIRE, NG.DEN_GEST, NUM.DEN_UM ,NIR.DATANIR, NS.CANTNIR, NS.REST, NP.DEN_PART,
    PKG_LIST_BASE_UTILS.DECODE_TIPDOC_SCURT(I.TIPDOC) tipdoc, I.NRDOC, I.DATADOC,
    NVL(PI.PER1,0), NVL(PI.PER2,0), NVL(PI.PER3,0), NVL(PI.PER4,0), NVL(PI.PER5,0)&apos;||gUserAlias||&apos;
  FROM NIR
    INNER JOIN NIRSTOC NS ON NS.CODNIR = NIR.CODNIR
    INNER JOIN INTRARI I ON I.CODINTR = NIR.CODINTR
    INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = NS.CODOBIECT
    INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM
    LEFT JOIN PER_IES PI ON NS.CODNIRSTOC = PI.ROOTCODNIRSTOC
    LEFT JOIN NPART NP ON NP.CODPART = I.PARTENER
    LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST&apos;||
    gSuplJoins||&apos;
  WHERE NIR.DATANIR BETWEEN &apos;||vPerioada||vCondArt||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCROTATIE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40C3C69B63017AD872B99E14FB56F3778C25ABF3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOCVAL IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(10000);
  pAnPrec     NUMBER(4);
  pLunaPrec   NUMBER(2);
  pAnLucru    NUMBER(4);
  pLunaLucru  NUMBER(2);
BEGIN
	pAnLucru   := pkg_globals.GetANLUCRU;
	plunaLucru := pkg_globals.GetLUNALUCRU;
	pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(pAnLucru,pLunaLucru,pAnPrec,pLunaPrec);

  gSuplCols := &apos;IOART IOA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DEN_GEST,DEN_IOART,TVA,
    INIVAL, INITVA, INIADAOS, INIACHIZ,
    INTVAL, INTTVA, INTADAOS, INTACHIZ,
    IESVAL, IESTVA, IESADAOS, IESACHIZ,
    FINVAL, FINTVA, FINADAOS, FINACHIZ, FININTR, FINADINTR&apos;||gUserFields||&apos;)
   WITH
    v AS (
      SELECT
        GEST, CODIOART, TVA,
        SUM(INIVAL) INIVAL, SUM(INIVAL)/(1+TVA)*TVA INITVA, SUM(INIADAOS) INIADAOS,
        SUM(INTVAL) INTVAL, SUM(INTVAL)/(1+TVA)*TVA INTTVA, SUM(INTADAOS) INTADAOS,
        SUM(IESVAL) IESVAL, SUM(IESVAL)/(1+TVA)*TVA IESTVA, SUM(IESADAOS) IESADAOS,
        SUM(SOLDINTR) SOLDINTR, SUM(ADAOSINTR)  ADAOSINTR
      FROM (
        SELECT
          SVL.GEST, SVL.CODIOART, Coalesce(SVL.TVA, 0) TVA,
          SVL.SOLD INIVAL, (SVL.ADAOS - SVL.SOLD / (1+Coalesce(SVL.TVA, 0)) * Coalesce(SVL.TVA, 0) ) INIADAOS,
          0 INTVAL, 0 INTADAOS,
          0 IESVAL, 0 IESADAOS,
          SVL.SOLDINTR, (SVL.ADAOSINTR - SVL.SOLDINTR / (1+Coalesce(SVL.TVA, 0)) ) ADAOSINTR
        FROM STOCVALLUNA SVL INNER JOIN NGEST NG ON NG.CODGEST = SVL.GEST
        WHERE AN = &apos;||pAnPrec||&apos; AND LUNA = &apos;||pLunaPrec||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
        UNION ALL
        SELECT
          N.GEST, NS.CODIOART, NS.TVA,
          0 INIVAL, 0 INIADAOS,
          NS.CANTNIR * NS.PRET INTVAL, NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA/(1 + NS.TVA)) INTADAOS,
          0 IESVAL,0 IESADAOS,
          NS.CANTNIR * NS.PRET SOLDINTR, NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA/(1 + NS.TVA)) ADAOSINTR
        FROM NIRSTOC NS
          INNER JOIN IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA1.ALStart and IOA1.ALStop AND IOA1.MG = 5
          INNER JOIN NIR    N    ON N.CODNIR      = NS.CODNIR
          INNER JOIN TRANSF T    ON T.CODTRANSF   = N.CODTRANSF
        WHERE N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
          AND T.AN = &apos;||pAnLucru||&apos; AND T.LUNA = &apos;||pLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
        UNION ALL
        SELECT
          N.GEST, NS.CODIOART, NS.TVA,
          0 INIVAL, 0 INIADAOS,
          NS.CANTNIR * NS.PRET INTVAL, NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA/(1 + NS.TVA)) INTADAOS,
          0 IESVAL,0 IESADAOS,
          NS.CANTNIR * NS.PRET SOLDINTR, NS.CANTNIR * (NS.ADAOS - NS.PRET * NS.TVA/(1 + NS.TVA)) ADAOSINTR
        FROM NIRSTOC NS
          INNER JOIN IOART1  IOA1 ON IOA1.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA1.ALStart and IOA1.ALStop AND IOA1.MG = 5
          INNER JOIN NIR     N    ON N.CODNIR      = NS.CODNIR
          INNER JOIN INTRARI I    ON I.CODINTR     = N.CODINTR
        WHERE N.TIPNIR IN (1, 2, 3, 4, 6) AND  N.ANULAT = 0 AND N.OPERAT = 1
          AND I.AN = &apos;||pAnLucru||&apos; AND I.LUNA =  &apos;||pLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT
          LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA,
          0 INIVAL, 0 INIADAOS,
          0 INTVAL, 0 INTADAOS,
          LV.PRETINREG * L1.CANT IESVAL, (LV.PRETINREG / (1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) * L1.CANT IESADAOS,
          0 AS SOLDINTR, 0 AS ADAOSINTR
        FROM LIVRVAL LV
          INNER JOIN LIVR1   L1 ON L1.CODLIVR1 = LV.CODLIVR1
          INNER JOIN LIVR    L  ON L.CODLIVR   = L1.CODLIVR
          INNER JOIN INTRARI I  ON I.CODINTR   = L.CODINTR
        WHERE L.TIPLIVR IN (1, 2, 3, 4, 6) AND  L.OPERAT = 1 AND L.ANULAT = 0
          AND I.AN = &apos;||pAnLucru||&apos; AND I.LUNA = &apos;||pLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT
          LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA,
          0 INIVAL, 0 INIADAOS,
          DECODE(L.TIPLIVR,15,LV.PRETINREG * L1.CANT,0) INTVAL,   DECODE(L.TIPLIVR,15,(LV.PRETINREG /(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) * L1.CANT,0) INTADAOS,
          DECODE(L.TIPLIVR,15,0,LV.PRETINREG * L1.CANT) IESVAL,   DECODE(L.TIPLIVR,15,0,(LV.PRETINREG /(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) * L1.CANT) IESADAOS,
          DECODE(L.TIPLIVR,15,LV.PRETINREG * L1.CANT,0) SOLDINTR, DECODE(L.TIPLIVR,15,(LV.PRETINREG /(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) * L1.CANT,0) ADAOSINTR
        FROM LIVRVAL LV
          INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
          INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
          INNER JOIN IESIRI I  ON I.CODIES    = L.CODIES
        WHERE L.OPERAT = 1 AND L.ANULAT = 0
          AND I.AN = &apos;||pAnLucru||&apos; AND I.LUNA = &apos;||pLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
        UNION ALL
        SELECT LV.GEST, LV.CODIOART, Coalesce(LV.TVANEEX, 0) TVA, 0 INIVAL, 0 INIADAOS,
          0 INTRLUNA, 0 ADINTRLUNA,
          LV.PRETINREG * L1.CANT IESLUNA, (LV.PRETINREG /(1+Coalesce(LV.TVANEEX, 0)) - LV.PRETACHIZ) * L1.CANT ADIESLUNA,
          0 SOLDINTR, 0 ADAOSINTR
        FROM LIVRVAL LV
          INNER JOIN LIVR1  L1 ON L1.CODLIVR1 = LV.CODLIVR1
          INNER JOIN LIVR   L  ON L.CODLIVR   = L1.CODLIVR
          INNER JOIN TRANSF T  ON T.CODTRANSF = L.CODTRANSF
        WHERE L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0
          AND T.AN = &apos;||pAnLucru||&apos; AND T.LUNA = &apos;||pLunaLucru||&apos; &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
      )
      GROUP BY GEST, CODIOART, TVA
    )
  SELECT
    g.den_gest,ioa.den_ioart,v.TVA * 100,
    v.INIVAL, v.INITVA, v.INIADAOS, v.INIVAL - v.INITVA - v.INIADAOS,
    v.INTVAL, v.INTTVA, v.INTADAOS, v.INTVAL - v.INTTVA - v.INTADAOS,
    v.IESVAL, v.IESTVA, v.IESADAOS, v.IESVAL - v.IESTVA - v.IESADAOS,
    v.INIVAL + v.INTVAL - v.IESVAL, v.INITVA + v.INTTVA - v.IESTVA, v.INIADAOS + v.INTADAOS - v.IESADAOS,
    (v.INIVAL + v.INTVAL - v.IESVAL) - (v.INITVA + v.INTTVA - v.IESTVA) - (v.INIADAOS + v.INTADAOS - v.IESADAOS),
    v.SOLDINTR, v.ADAOSINTR&apos;||gUserAlias||&apos;
  FROM v
    INNER JOIN ngest  g   ON v.GEST      = g.codgest
    INNER JOIN IOART1 io  ON v.CODIOART  = io.codioart AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IO.ALStart and IO.ALStop AND IO.MG = 5
    INNER JOIN IOART  IOA ON IO.CODIOART = IOA.CODIOART&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

END PKG_LIST_BASE_STOCVAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCVECHIME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BB58D69E7543D5DB6E63D37BA188EA681BE2973</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOCVECHIME IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(25000);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert       VARCHAR2(10000);
  sSelect       VARCHAR2(20000);
  aSubunitate   NUMBER(20);
  sFiltruInterne VARCHAR2(100);

  AnPrec        NUMBER(4);
  LunaPrec      NUMBER(2);

  DataStoc      DATE;
  AnLista       NUMBER(4);
  LunaLista     NUMBER(2);
  sAnIni        VARCHAR2(4);
  sLunaIni      VARCHAR2(2);
  sAnLunaIni    VARCHAR2(5);
BEGIN
--pkg_globals.setdebugmode(TRUE);
  gSuplCols := &apos;NIRSTOC NS, NIR NIR, NARTOBJ NOBJ, NART NART, NUM1 NUM1, IOART IO, IOART1 IO1, NLOCATII NLOC, NGEST NG, NPART PROD, NPART FURN, NCONT C, NCLASEA NCA&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  aSubunitate := pkg_globals.GETSUBUNITATE;

  dataStoc  := pkg_list_selfisamag.getDataStoc;
  LunaLista := EXTRACT(MONTH FROM DataStoc);
  AnLista   := EXTRACT(YEAR FROM DataStoc);

  sFiltruInterne := &apos;&apos;;
  if PKG_LIST_SELFISAMAG.RezUM1 then
    sFiltruInterne := &apos; and ies.tipdoc not in (14,15)&apos;;
  end if;

  pkg_globals.SetLunaTemp(AnLista,LunaLista);
  pkg_globals.Calculeaza_Luna_Precedenta(AnLista,LunaLista, AnPrec,LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec,LunaPrec);

  SELECT to_char(AnInitial,&apos;fm9999&apos;), to_char(LunaInitiala,&apos;fm99&apos;), to_char(AnInitial*12+LunaInitiala,&apos;fm99999&apos;) INTO sAnIni, sLunaIni, sAnLunaIni FROM FirmaLuni;

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(
      NAV_CODDOC,NAV_TIPDOC, NAV_NIRSTOC, CodObiect,
      DEN_GEST, DEN_LGEST, DEN_IOART, DEN_ART, DEN_UM,
      PRETACH, CODINTERN, CODEXTERN,VEKIMEMEDIE,PRODUCATOR,DATAACHIZ, DATAREF, STOC, VAL,
      STOC_0_30, VAL_0_30, STOC_31_60, VAL_31_60, STOC_61_90, VAL_61_90, STOC_91_180, VAL_91_180, STOC_180_360, VAL_180_360, STOC_360_PLUS, VAL_360_PLUS,
      STOC_0_3_LUNI, VAL_0_3_LUNI, STOC_3_6_LUNI, VAL_3_6_LUNI, STOC_6_9_LUNI, VAL_6_9_LUNI, STOC_9_12_LUNI, VAL_9_12_LUNI, STOC_6_12_LUNI, VAL_6_12_LUNI,
      STOC_1_2_ANI, VAL_1_2_ANI, STOC_2_ANI_PLUS, VAL_2_ANI_PLUS&apos;||gUserFields||&apos;)&apos;;

  IF PKG_LIST_SELFISAMAG.STOCLAZI THEN
    sSelect := &apos;
    WITH crs_docs AS(
	    SELECT intr.codintr nav_coddoc,intr.tipdoc nav_tipdoc,intr.nrdoc,intr.datadoc,intr.prefixdoc, intr.subunitatea, intr.userid,
        CASE WHEN (intr.an * 12 + intr.luna) &gt;= &apos;||sAnLunaIni||&apos; then intr.an ELSE &apos;||sAnIni||&apos; END an,
        CASE WHEN (intr.an * 12 + intr.luna) &gt;= &apos;||sAnLunaIni||&apos; then intr.luna ELSE &apos;||sLunaIni||&apos; END luna
	    FROM intrari intr WHERE Coalesce(intr.anulat,0) = 0 AND intr.operat = 1
      UNION ALL
	    SELECT ies.codies nav_coddoc,ies.tipdoc nav_topdoc,ies.nrdoc,ies.datadoc,ies.prefixdoc, ies.subunitatea,ies.userid,
        CASE WHEN (ies.an * 12 + ies.luna) &gt;= &apos;||sAnLunaIni||&apos; then ies.an ELSE &apos;||sAnIni||&apos; END an,
        CASE WHEN (ies.an * 12 + ies.luna) &gt;= &apos;||sAnLunaIni||&apos; then ies.luna ELSE &apos;||sLunaIni||&apos; END luna
	    FROM iesiri ies	WHERE ies.anulat = 0 AND ies.operat = 1&apos;||sFiltruInterne;
      if not PKG_LIST_SELFISAMAG.RezUM1 then
        sSelect := sSelect||&apos;
        UNION ALL
        SELECT tr.codtransf nav_coddoc,tr.tipdoc nav_tipdoc,tr.nrdoc,tr.datadoc,tr.prefixdoc,tr.subunitatea,tr.userid,
          CASE WHEN (tr.an * 12 + tr.luna) &gt;= &apos;||sAnLunaIni||&apos; then tr.an ELSE &apos;||sAnIni||&apos; END an,
          CASE WHEN (tr.an * 12 + tr.luna) &gt;= &apos;||sAnLunaIni||&apos; then tr.luna ELSE &apos;||sLunaIni||&apos; END luna
        FROM transf tr  WHERE tr.anulat = 0 AND tr.operat = 1&apos;;
      end if;
    sSelect := sSelect||&apos;)
    SELECT
      DOC.NAV_CODDOC, DOC.nav_tipdoc, NS.CODNIRSTOC, NOBJ.CODOBIECT,
      NG.DEN_GEST,NLOC.DENUMIRE LOCATIE,IO.DEN_IOART TIPCONTABIL,NOBJ.DENUMIRE,NUM1.DEN_UM1,
      NS.PRET - NS.ADAOS PRETACHIZ, NOBJ.CODINTERN, NOBJ.CODEXTERN, PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) VEKIMEMED,
      PROD.DEN_PART PRODUCATOR,COALESCE(NS.DATAACHIZ,NIR.DATANIR) DATAACHIZ, PL.DATAREF DATAREF, NS.REST, NS.REST * NS.PRET,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN   0 AND  30 THEN NS.REST           ELSE 0 END STOC_0_30,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN   0 AND  30 THEN NS.REST * NS.PRET ELSE 0 END VAL_0_30,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  31 AND  60 THEN NS.REST           ELSE 0 END STOC_31_60,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  31 AND  60 THEN NS.REST * NS.PRET ELSE 0 END VAL_31_60,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  61 AND  90 THEN NS.REST           ELSE 0 END STOC_61_90,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  61 AND  90 THEN NS.REST * NS.PRET ELSE 0 END VAL_61_90,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  91 AND 180 THEN NS.REST           ELSE 0 END STOC_91_180,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN  91 AND 180 THEN NS.REST * NS.PRET ELSE 0 END VAL_91_180,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN 181 AND 360 THEN NS.REST           ELSE 0 END STOC_180_360,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN 181 AND 360 THEN NS.REST * NS.PRET ELSE 0 END VAL_180_360,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) &gt; 360 THEN NS.REST           ELSE 0 END STOC_360_PLUS,
      CASE WHEN PL.DATAREF - COALESCE(NS.DATAACHIZ,NIR.DATANIR) &gt; 360 THEN NS.REST * NS.PRET ELSE 0 END VAL_360_PLUS,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -3)+1 AND PL.DATAREF THEN NS.REST           ELSE 0 END STOC_0_3_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -3)+1 AND PL.DATAREF THEN NS.REST * NS.PRET ELSE 0 END VAL_0_3_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -6)+1 AND ADD_MONTHS(PL.DATAREF, -3) THEN NS.REST           ELSE 0 END STOC_3_6_LUN,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -6)+1 AND ADD_MONTHS(PL.DATAREF, -3) THEN NS.REST * NS.PRET ELSE 0 END VAL_3_6_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -9)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN NS.REST           ELSE 0 END STOC_6_9_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -9)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN NS.REST * NS.PRET ELSE 0 END VAL_6_9_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -9) THEN NS.REST           ELSE 0 END STOC_9_12_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -9) THEN NS.REST * NS.PRET ELSE 0 END VAL_9_12_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN NS.REST           ELSE 0 END STOC_6_12_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN NS.REST * NS.PRET ELSE 0 END VAL_6_12_LUNI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-24)+1 AND ADD_MONTHS(PL.DATAREF,-12) THEN NS.REST           ELSE 0 END STOC_1_2_ANI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-24)+1 AND ADD_MONTHS(PL.DATAREF,-12) THEN NS.REST * NS.PRET ELSE 0 END VAL_1_2_ANI,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) &lt;= ADD_MONTHS(PL.DATAREF,-24) THEN NS.REST ELSE 0 END STOC_2_ANI_PLUS,
      CASE WHEN COALESCE(NS.DATAACHIZ,NIR.DATANIR) &lt;= ADD_MONTHS(PL.DATAREF,-24) THEN NS.REST * NS.PRET ELSE 0 END VAL_2_ANI_PLUS &apos;||gUserAlias||&apos;
    FROM NIRSTOC NS
      CROSS JOIN (SELECT pkg_list_selfisamag.getDataRef DATAREF FROM DUAL) PL   
      INNER JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = NS.CODOBIECT
      INNER JOIN NART     NART ON NART.CODARTICOL = NOBJ.CODARTICOL
      INNER JOIN NIR           ON NIR.CODNIR      = NS.CODNIR
      INNER JOIN crs_docs doc  ON doc.nav_coddoc  = coalesce(nir.codtransf,nir.codies,nir.codintr) AND doc.nav_tipdoc = nir.tipnir
      INNER JOIN NGEST    NG   ON NG.CODGEST      = NIR.GEST
      INNER JOIN NUM1     NUM1 ON NUM1.CODUM1     = NS.UMSEC
      INNER JOIN IOART    IO   ON IO.CODIOART     = NS.CODIOART
    	INNER JOIN IOART1   IO1  ON IO.CODIOART     = IO1.CODIOART AND (doc.an * 12 + doc.luna) BETWEEN IO1.ALStart and IO1.ALStop
      LEFT  JOIN NCLASEA  NCA  ON NCA.CODCLASEA   = NART.CLASA
      LEFT  JOIN NCONT    C    ON C.CODCONT       = IO1.CONT
      LEFT  JOIN NLOCATII NLOC ON NLOC.CODLOCATIE = NS.CODLOCATIE
      LEFT  JOIN NPART    PROD ON PROD.CODPART    = NOBJ.CODPRODUCATOR
      LEFT  JOIN NPART    FURN ON FURN.CODPART    = NS.FURN&apos;||
    gSuplJoins||&apos;
    WHERE IO1.MG &lt;&gt; 5&apos;;
  ELSE
    sSelect :=&apos;
    SELECT
      COALESCE(VLS.CODTRANSF,VLS.CODIES,VLS.CODINTR), VLS.TIPNIR, VLS.CODNIRSTOC, NOBJ.CODOBIECT,
      NG.DEN_GEST,VLS.LOCATIE,IO.DEN_IOART TIPCONTABIL,NOBJ.DENUMIRE,NUM1.DEN_UM1,
      VLS.PRETACHIZ, NOBJ.CODINTERN, NOBJ.CODEXTERN,PL.DATAREF - NS.DATAACHIZ VEKIMEMED,
      PROD.DEN_PART PRODUCATOR, COALESCE(VLS.INTRATLA,NIR.DATANIR) DATAACHIZ, PL.DATAREF, VLS.REST, VLS.REST * VLS.PRET,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN   0 AND  30 THEN VLS.REST            ELSE 0 END STOC_0_30,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN   0 AND  30 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_0_30,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  31 AND  60 THEN VLS.REST            ELSE 0 END STOC_31_60,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  31 AND  60 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_31_60,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  61 AND  90 THEN VLS.REST            ELSE 0 END STOC_61_90,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  61 AND  90 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_61_90,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  91 AND 180 THEN VLS.REST            ELSE 0 END STOC_91_180,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN  91 AND 180 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_91_180,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN 181 AND 360 THEN VLS.REST            ELSE 0 END STOC_180_360,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN 181 AND 360 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_180_360,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) &gt; 360 THEN VLS.REST ELSE 0 END STOC_360_PLUS,
      CASE WHEN PL.DATAREF - COALESCE(VLS.INTRATLA,NIR.DATANIR) &gt; 360 THEN VLS.REST * VLS.PRET ELSE 0 END VAL_360_PLUS,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -3)+1 AND PL.DATAREF THEN VLS.REST            ELSE 0 END STOC_0_3_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -3)+1 AND PL.DATAREF THEN VLS.REST * VLS.PRET ELSE 0 END VAL_0_3_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -6)+1 AND ADD_MONTHS(PL.DATAREF, -3) THEN VLS.REST            ELSE 0 END STOC_3_6_LUN,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -6)+1 AND ADD_MONTHS(PL.DATAREF, -3) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_3_6_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -9)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN VLS.REST            ELSE 0 END STOC_6_9_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF, -9)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_6_9_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -9) THEN VLS.REST            ELSE 0 END STOC_9_12_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -9) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_9_12_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN VLS.REST            ELSE 0 END STOC_6_12_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-12)+1 AND ADD_MONTHS(PL.DATAREF, -6) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_6_12_LUNI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-24)+1 AND ADD_MONTHS(PL.DATAREF,-12) THEN VLS.REST            ELSE 0 END STOC_1_2_ANI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) BETWEEN ADD_MONTHS(PL.DATAREF,-24)+1 AND ADD_MONTHS(PL.DATAREF,-12) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_1_2_ANI,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) &lt;= ADD_MONTHS(PL.DATAREF,-24) THEN VLS.REST ELSE 0 END STOC_2_ANI_PLUS,
      CASE WHEN COALESCE(VLS.INTRATLA,NIR.DATANIR) &lt;= ADD_MONTHS(PL.DATAREF,-24) THEN VLS.REST * VLS.PRET ELSE 0 END VAL_2_ANI_PLUS &apos;||gUserAlias||&apos;
    FROM V_LIST_STOC VLS
      CROSS JOIN (SELECT pkg_list_selfisamag.getDataRef DATAREF FROM DUAL) PL   
      INNER JOIN NIRSTOC  NS   ON NS.CODNIRSTOC   = VLS.CODNIRSTOC
      INNER JOIN NIR      NIR  ON NIR.CODNIR      = VLS.CODNIR
      INNER JOIN NARTOBJ  NOBJ ON NOBJ.CODOBIECT  = NS.CODOBIECT
      INNER JOIN NART     NART ON NART.CODARTICOL = NOBJ.CODARTICOL
      INNER JOIN NUM1     NUM1 ON NUM1.CODUM1     = NS.UMSEC
      INNER JOIN IOART    IO   ON VLS.CODIOART    = IO.CODIOART
      INNER JOIN IOART1   IO1  ON IO.CODIOART     = IO1.CODIOART AND (vls.an * 12 + vls.luna) BETWEEN IO1.ALStart and IO1.ALStop
      LEFT  JOIN NCLASEA  NCA  ON NCA.CODCLASEA   = NART.CLASA
      LEFT  JOIN NCONT    C    ON C.CODCONT       = IO1.CONT
      LEFT  JOIN NLOCATII NLOC ON NLOC.CODLOCATIE = VLS.CODLOCATIE
      LEFT  JOIN NGEST    NG   ON NG.CODGEST      = VLS.GEST
      LEFT  JOIN NPART    PROD ON PROD.CODPART    = NOBJ.CODPRODUCATOR
      LEFT  JOIN NPART    FURN ON FURN.CODPART    = NS.FURN &apos;||
    gSuplJoins||&apos;
    WHERE IO1.MG &lt;&gt; 5&apos;;
    
    IF PKG_LIST_SELFISAMAG.RezUM1 THEN
      sSelect := sSelect||&apos;
      AND VLS.TIPNIR NOT IN (12,13,14,15)&apos;;
    END IF;
  END IF;

  IF  PKG_LIST_SELFISAMAG.isAllTipCont = FALSE THEN
    sSelect := sSelect ||&apos;
      AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
  END IF;

  IF  PKG_LIST_SELFISAMAG.isAllGest = FALSE THEN
    sSelect := sSelect || &apos;
      AND NIR.GEST IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  END IF;

  IF PKG_LIST_SELFISAMAG.isToateArt = 0 THEN
    sSelect := sSelect || &apos;
      AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  END IF;

  IF aSubunitate &gt; 1 THEN
    sSelect := sSelect ||&apos;
      AND NG.CODSUBUNIT = &apos;||aSubunitate;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  Pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_STOCVECHIME;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_STOCVITROT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F5E5E000716AA7EF66DA3CE39B14A7C6771F485</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_STOCVITROT IS

  vData1      DATE;
  vDataIni    DATE;
  vDataFin    DATE;
  vAnual      BOOLEAN;
  vAvizeSub   BOOLEAN;
  vTransfVal  BOOLEAN;
  vIesConsum  BOOLEAN;
  vToateArt   BOOLEAN;
  vToateGest  BOOLEAN;
  vToateIOArt BOOLEAN;
  vCentr      BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(
  pDataIni    IN VARCHAR2,
  pDataFin    IN VARCHAR2,
  pAnual      IN NUMBER DEFAULT 1,
  pAvizeSub   IN NUMBER DEFAULT 1,
  pTransfVal  IN NUMBER DEFAULT 1,
  pIesConsum  IN NUMBER DEFAULT 1,
  pToateArt   IN NUMBER DEFAULT 1,
  pToateGest  IN NUMBER DEFAULT 1,
  pToateIOArt IN NUMBER DEFAULT 1,
  pCentr      IN NUMBER DEFAULT 1,
  V_CODJOB1   IN NUMBER DEFAULT 0)
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataIni    := To_Date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin    := To_Date(pDataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  vData1      := Trunc(vDataIni,&apos;MM&apos;);
  vAnual      := pAnual = 1;
  vAvizeSub   := pAvizeSub = 1;
  vTransfVal  := pTransfVal = 1;
  vIesConsum  := pIesConsum = 1;
  vToateArt   := pToateArt = 1;
  vToateGest  := pToategest = 1;
  vToateIOArt := pToateIOArt = 1;
  vCentr      := pCentr = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    CLOB;
  sWith      CLOB;
  sWithSel1  CLOB;
  sSelect    CLOB;
  vPerioada  CLOB;
  vFiltre    VARCHAR2( 3000);
  vCondVanz  VARCHAR2(  100) := &apos;16,19,20,21,22&apos;;
  vJoinLivr  VARCHAR2( 3000);
  sNrZile    VARCHAR2(   10);
  sLast      VARCHAR2(  500);
  sJoinLM    VARCHAR2(  500);
  sDataIni   VARCHAR2(  100) := &apos;To_Date(&apos;&apos;&apos;||To_Char(vDataIni, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sDataFin   VARCHAR2(  100) := &apos;To_Date(&apos;&apos;&apos;||To_Char(vDataFin, &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sData1     VARCHAR2(  100) := &apos;To_Date(&apos;&apos;&apos;||To_Char(vData1,   &apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NART NA, NUM NUM, NGEST NG, IOART I, NCLASEA CA, NPART PRO, NPART FURN, NSUBUNIT SUB&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);

  if NOT vToateArt then
    vFiltre := vFiltre||&apos;
          AND NS.CODOBIECT IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  end if;
  if NOT vToateGest then
    vFiltre := vFiltre||&apos;
          AND N.GEST IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) &apos;;
  end if;
  if NOT vToateIOArt then
    vFiltre := vFiltre||&apos;
          AND NS.CODIOART IN ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos;;
  end if;

  IF vAnual
  THEN sNrZile := &apos;365&apos;;
  ELSE sNrZile := To_char(vDataFin-vDataIni+1);
  END IF;

  IF vData1 = vDataFin
  THEN vPerioada := &apos;= &apos;||sDataFin;
  ELSE vPerioada := &apos;BETWEEN &apos;||sData1||&apos; AND &apos;||sDataFin;
  END IF;

  IF vAvizeSub THEN
    vCondVanz := vCondVanz||&apos;,23&apos;;
  END IF;
  IF vIesConsum THEN
    vCondVanz := vCondVanz||&apos;,24&apos;;
  END IF;
  vCondVanz := &apos;L.TIPLIVR IN (&apos;||vCondVanz||&apos;)&apos;;
  IF vTransfVal THEN
    vCondVanz := &apos;(&apos;||vCondVanz||&apos; OR (L.TIPLIVR = 12 AND NVL(IOAD.MG,0) = 5))&apos;;
    vJoinLivr := &apos;
          LEFT JOIN NIRSTOC NSD ON NSD.CODLIVR1 = L1.CODLIVR1
          LEFT JOIN IOART1 IOAD ON IOAD.CODIOART = NSD.CODIOART&apos;;
  END IF;

  sLast := &apos;&apos;;
  sJoinLM := &apos;&apos;;
  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    Art, UM, Gest, IoArt, StocIni, StocFin, PretAchiz, IesTot,
    DenClasaA, CodIntern, CodExtern, Producator, Furnizor, ZilePer, VMRot, Subunitatea, ZileStoc&apos;;

  sWith :=&apos;
  WITH &apos;;

  sWithSel1 := &apos;
      SELECT
        CODOBIECT, GEST, CODIOART, PACHIZ, NVL(FURN,0) FURN, Sum(STOCINI) StocIni, Sum(STOCFIN) StocFin, Sum(VANZARI) Vanzari, 
        TRUNC(Least(&apos;||sDataFin||&apos;, MAX(Coalesce(DATALASTLIVR, &apos;||sDataFin||&apos;))) - Min(Coalesce(DATAACHIZ,&apos;||sDataFin||&apos;))) ZILESTOC
      FROM (
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, NS.PRET-NS.ADAOS PACHIZ, NS.FURN,
          NL.REST STOCINI, NL.REST STOCFIN, 0 VANZARI, 
          NS.DATAACHIZ,
          CASE 
            WHEN NS.REST = 0 
            THEN (SELECT MAX(LX.DATALIVR) FROM LIVR LX INNER JOIN LIVR1 LX1 ON LX.CODLIVR = LX1.CODLIVR WHERE LX1.CODNIRSTOC = NS.CODNIRSTOC)
            ELSE &apos;||sDataFin||&apos;
          END DATALASTLIVR
        FROM NIRLUNA NL
          INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = NL.CODNIRSTOC
          INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
          INNER JOIN NGEST   NG  ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
          INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop
        WHERE NL.AN = &apos;||EXTRACT(YEAR FROM (vData1 - 1))||&apos; AND NL.LUNA = &apos;||EXTRACT(MONTH FROM (vData1 - 1))||&apos;
          AND IOA.MG &lt;&gt; 5 &apos;||vFiltre||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, NS.PRET-NS.ADAOS PACHIZ, NS.FURN,
          CASE WHEN N.DATANIR &lt; &apos;||sDataIni||&apos; THEN CANTNIR ELSE 0 END STOCINI, CANTNIR STOCFIN, 0 VANZARI, 
          NS.DATAACHIZ,
          CASE 
            WHEN NS.REST = 0 
            THEN (SELECT MAX(LX.DATALIVR) FROM LIVR LX INNER JOIN LIVR1 LX1 ON LX.CODLIVR = LX1.CODLIVR WHERE LX1.CODNIRSTOC = NS.CODNIRSTOC)
            ELSE &apos;||sDataFin||&apos;
          END DATALASTLIVR
        FROM NIRSTOC NS
          INNER JOIN NIR    N   ON N.CODNIR     = NS.CODNIR
          INNER JOIN NGEST  NG  ON NG.CODGEST   = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
          INNER JOIN IOART1 IOA ON IOA.CODIOART = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop
        WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
          AND N.DATANIR &apos;||vPerioada||&apos;
          AND IOA.MG &lt;&gt; 5 &apos;||vFiltre||&apos;
        UNION ALL
        SELECT
          NS.CODOBIECT, N.GEST, NS.CODIOART, NS.PRET-NS.ADAOS PACHIZ, NS.FURN,
          CASE WHEN L.DATALIVR &lt; &apos;||sDataIni||&apos; THEN L1.CANT ELSE 0 END * Decode(L.TIPLIVR,15,1,-1) STOCINI, L1.CANT * Decode(L.TIPLIVR,15,1,-1) STOCFIN,
          CASE WHEN L.DATALIVR &gt;= &apos;||sDataIni||&apos; AND &apos;||vCondVanz||&apos; THEN L1.CANT ELSE 0 END VANZARI, 
          NS.DATAACHIZ, 
          NS.DATAACHIZ DATALASTLIVR
        FROM LIVR L
          INNER JOIN LIVR1   L1  ON L1.CODLIVR    = L.CODLIVR
          INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
          INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
          INNER JOIN NGEST   NG  ON NG.CODGEST    = N.GEST &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||&apos;
          INNER JOIN IOART1  IOA ON IOA.CODIOART  = NS.CODIOART AND &apos;||PKG_GLOBALS.AnLunaLucru||&apos; BETWEEN IOA.ALStart and IOA.ALStop &apos;
          ||vJoinLivr||&apos;
        WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
          AND L.DATALIVR &apos;||vPerioada||&apos;
          AND IOA.MG &lt;&gt; 5 &apos;||vFiltre||&apos;
      )
      GROUP BY CODOBIECT, GEST, CODIOART, PACHIZ, NVL(FURN,0)&apos;;


  if vCentr then
    --insert into x(test) values(&apos;centralizare&apos;);
    sInsert := sInsert||&apos;,Last_furn,Last_DataAchiz,Last_PretAchiz&apos;;
    sWith := sWith ||&apos;
    S AS (
      SELECT CODOBIECT, 0 GEST, 0 CODIOART, SUM(PACHIZ)/SUM(1) PACHIZ, 0 FURN, Sum(STOCINI) StocIni, Sum(STOCFIN) StocFin, Sum(VANZARI) Vanzari, max(zilestoc) zilestoc
      FROM (&apos;||
      sWithSel1||&apos;
      )
      GROUP BY CODOBIECT
    ),
    LM AS (
      SELECT
        DISTINCT
        NS.CODOBIECT,
        LAST_VALUE(P.DEN_PART) IGNORE NULLS OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_FURN,
        LAST_VALUE(N.DATANIR)  IGNORE NULLS OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_DATAACHIZ,
        LAST_VALUE(NS.PRET)    IGNORE NULLS OVER (PARTITION BY NS.CODOBIECT ORDER BY N.DATANIR ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LAST_PRETACHIZ
      FROM NIR N
        INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
        INNER JOIN NGEST   G  ON G.CODGEST = N.GEST
        LEFT  JOIN INTRARI I  ON I.CODINTR = N.CODINTR
        LEFT  JOIN NPART   P  ON P.CODPART = I.PARTENER
      WHERE N.OPERAT = 1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
    )&apos;;
    sLast := &apos;,LM.LAST_FURN,LM.LAST_DATAACHIZ,LM.LAST_PRETACHIZ&apos;;
    sJoinLM := CHR(13)||&apos;LEFT JOIN LM ON LM.CODOBIECT = S.CODOBIECT&apos;||CHR(13);
  ELSE
    --insert into x(test) values(&apos;necentralizare&apos;);
    sWith := sWith ||&apos;
    S AS (&apos;||
      sWithSel1||&apos;
    )&apos;;
  END IF;
  sInsert := sInsert||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  SELECT
    NAO.DENUMIRE, NUM.DEN_UM, NG.DEN_GEST, I.DEN_IOART, S.STOCINI, S.STOCFIN, S.PACHIZ, S.VANZARI,
    CA.DEN_CLASEA, NAO.CODINTERN, NAO.CODEXTERN, PROD.DEN_PART, FURN.DEN_PART, &apos;||sNrZile||&apos;,
    CASE
      WHEN S.VANZARI = 0 THEN 0
      ELSE (S.STOCINI+S.STOCFIN)/2/S.VANZARI*&apos;||sNrZile||&apos;
    END,
    SUB.DEN_SUBUNIT, S.ZILESTOC &apos;||sLast||gUserAlias||&apos;
  FROM S
    INNER JOIN NARTOBJ  NAO  ON NAO.CODOBIECT  = S.CODOBIECT
    INNER JOIN NART     NA   ON NA.CODARTICOL  = NAO.CODARTICOL
    LEFT  JOIN NUM           ON NUM.CODUM      = NA.UM
    LEFT  JOIN NGEST    NG   ON NG.CODGEST     = S.GEST
    LEFT  JOIN IOART    I    ON I.CODIOART     = S.CODIOART
    LEFT  JOIN NCLASEA  CA   ON CA.CODCLASEA   = NA.CLASA
    LEFT  JOIN NPART    PROD ON PROD.CODPART   = NAO.CODPRODUCATOR
    LEFT  JOIN NPART    FURN ON FURN.CODPART   = S.FURN
    LEFT  JOIN NSUBUNIT SUB  ON SUB.CODSUBUNIT = NG.CODSUBUNIT&apos;||sJoinLM||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_STOCVITROT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_SYNCPRETRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B22C00C338BEFA1296CECACFDE3DE55C7F926F7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_SYNCPRETRETAIL is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vCodCatPret NUMBER(20);

PROCEDURE SetParams(pCodCatPret IN NUMBER DEFAULT 0) IS
BEGIN
  vCodCatPret := Coalesce(pCodCatPret, 0);
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sWhere     VARCHAR2( 1000);
BEGIN
  gSuplCols :=
    &apos;syncpretretail spr, nartobj nao, nart na&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,  &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,  &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    Art, CodIntern, CodExtern, PretVechi, PretNou &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    nao.denumire, nao.codintern, nao.codextern, spr.pretvechi, spr.pretnou &apos;||gUserAlias||&apos;
  FROM syncpretretail spr
    INNER JOIN tmp_manevra m   ON m.codunic     = spr.idpreluare
    LEFT  JOIN nartobj     nao ON nao.codobiect = spr.codobiect
    LEFT  JOIN nart        na  ON na.codarticol = nao.codarticol &apos;||
    gSuplJoins;

  sWhere := &apos;
  WHERE spr.CODCATPRET = &apos;||To_Char(vCodCatPret);

  IF vCodCatPret = 0 THEN
    sWhere := &apos;&apos;;
  END IF;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect||sWhere, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_SYNCPRETRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TASKURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EED0555C5C84BC42D3AED94604D382F632A9ED6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TASKURI IS
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  g_includSterse boolean;
  g_areInterval  boolean;
  g_dataIni      varchar2(30);
  g_dataFin      varchar2(30);
  g_includLog    boolean;

PROCEDURE SETPARAMS(
  includSterse in INTEGER  default 0,
  areInterval  in INTEGER  default 0,
  dataIni      in varchar2 default &apos;&apos;,
  datafin      in varchar2 default &apos;&apos;,
  includLog    in INTEGER  default 0,
  V_CODJOB1    IN NUMBER   DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  g_dataIni      := DataIni;
  g_dataFin      := datafin;
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,g_dataIni,g_dataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  g_includSterse := includSterse = 1;
  g_areInterval  := areInterval = 1;
  g_includLog    := includLog = 1;
END;

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sSterse   VARCHAR2(200);
  sInterval VARCHAR2(200);
	LocTask   varchar2(10);
  TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;

	IF TaskFirma = 2 THEN
    LocTask   := &apos;&apos;;
    gSuplCols := &apos;SETTASK ST, SETTASKLOG L&apos;;
  ELSE
    LocTask   := &apos;WINMADMIN.&apos;;
    gSuplCols := &apos;LST_SETTASK ST, LST_SETTASKLOG L&apos;;
  END IF;

  gSuplCols := gSuplCols||&apos;, NMONEDE MON&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA&apos;,   &apos;COM&apos;,    &apos;COM.CODCOMANDA = ST.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,    &apos;IES&apos;,    &apos;IES.CODIES = ST.CODFACTURA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA&apos;,    &apos;OFE&apos;,    &apos;OFE.CODOFERTA = ST.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;SERVPOST&apos;,  &apos;SERV&apos;,   &apos;SERV.CODSERVICIU = ST.CODSERVICIU&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT1&apos;, &apos;CONTR1&apos;, &apos;CONTR1.CODCONTRACT1 = ST.CODCONTRACT1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT&apos;,  &apos;CONTR&apos;,  &apos;CONTR.CODCONTRACT = CONTR1.CODCONTRACT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CODDOC,NAV_TIPDOC,ORDINE,CREATOR,EXECUTANT,PROBLEMA,DESTINATAR,TERMEN,
    DATATASK,ORATASK,DATAREZ,ORAREZ,
    DOMENIU,TIP,REZOLVARE,OBSERVATII,
    PRIORITATE,REZOLVAT,MODIFICAT,STERS,PROIECT,
    DELA,CATRE,DATA_TRMITERE,
    FACTURABIL,FACTURAT,VALOARE,
    MONEDA, ARTASOC, SERIIASOC, OBSASOC&apos;||
    gUserFields||&apos;)
  SELECT
    ST.CODTASK, 54 NAV_TIPDOC, ST.CODTASK, ST.USERNAME CREATOR, ST.EXECUTANT, SUBSTR(ST.PROBLEMA,1,3200), ST.DESTINATAR, ST.TERMEN,
    Trunc(ST.DATATASK,&apos;&apos;dd&apos;&apos;), TO_CHAR(ST.DATATASK,&apos;&apos;HH24:MI:SS&apos;&apos;), Trunc(ST.DATAREZ,&apos;&apos;dd&apos;&apos;), TO_CHAR(ST.DATAREZ,&apos;&apos;HH24:MI:SS&apos;&apos;),
    ST.DOMENIU, ST.TIP, SUBSTR(ST.REZOLVARE,1,3200),SUBSTR(ST.OBSERVATII,1,3200), ST.PRIORITATE,
    DECODE(ST.DONE,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) REZOLVAT, DECODE(ST.MODIFICAT,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) MODIFICAT, DECODE(ST.STERS,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) STERS , ST.PROIECT,
    L.USER_SRC DELA, L.USER_DST CATRE, TO_CHAR(L.DATA,&apos;&apos;DD.MM.YYYY HH24:MI:SS&apos;&apos;) DATA_TRMITERE,
    DECODE(ST.FACTURABIL,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) FACTURABIL, DECODE(ST.FACTURAT,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) FACTURAT, ST.VALOARE, MON.DEN_MONEDA,
    ASOC.DENUMIRE, ASOC.SERII, ASOC.OBSERVATII &apos;||
    gUserAlias||&apos;
  FROM &apos;||LocTask||&apos;SETTASK ST
    LEFT JOIN &apos;||LocTask||&apos;SETTASKLOG L ON L.CODTASK = ST.CODTASK&apos;||CASE WHEN g_includLog THEN NULL ELSE &apos; AND L.CODLOG = 0&apos; END||&apos;
    LEFT JOIN NMONEDE MON ON ST.CODMONEDA = MON.CODMONEDA
    LEFT JOIN (
      SELECT ASOC.CODTASK, string_agg(O.DENUMIRE) DENUMIRE, string_agg(ASOC.SERII) SERII, string_agg(ASOC.CODINTERN) OBSERVATII
      FROM &apos;||LocTask||&apos;SETTASKOBJASOC ASOC INNER JOIN NARTOBJ O ON O.CODOBIECT = ASOC.CODOBIECT
      GROUP BY ASOC.CODTASK
    ) ASOC ON ASOC.CODTASK = ST.CODTASK&apos;||
    gSuplJoins||&apos;
  WHERE 1=1&apos;;
	IF TaskFirma = 2 THEN
    sInsert := sInsert||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;ST&apos;);
  END IF;
  IF NOT g_includSterse THEN
    sInsert := sInsert|| &apos;
    AND NVL(ST.STERS,0) = 0 &apos;;
  END IF;
  IF g_areInterval THEN
    sInsert := sInsert||&apos;
    AND ST.DATATASK BETWEEN TO_DATE(&apos;&apos;&apos;||G_DATAINI||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||G_DATAFIN||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  END IF;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_taskuri;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TEHPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87BA31D41E8B4303AFC84904D1DB04DAABB000FC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TEHPROD IS

  p_flgAllArt NUMBER(1);
  p_Sursa     NUMBER(1);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE setAllParams(v_flgAllArt IN NUMBER, v_Sursa IN NUMBER) IS
BEGIN
  p_flgAllArt := v_flgAllArt;
  p_Sursa     := v_Sursa;
END;

procedure BagaMateriale(aObservatii in varchar2, aCodObiect in number, aCant in number, aCodProdComp in number, aNivel in number, aCodMoneda in number, aCodOriginal in number) is
begin
  for v_tmp in (select mat.codobiect, mat.tip, case when nvl(mat.tip,3) &lt;= 2 then nvl(pc.codprodcomp,0) else 0 end codprodcomp,
                       aCant/decode(nvl(prod.cant,0),0,1,prod.cant)*mat.cant cant,
                       case when aObservatii &lt;&gt; &apos; &apos; then aObservatii||&apos;.&apos;||LPAD(to_char(IndexLocal), 2, &apos;0&apos;) else LPAD(to_char(IndexLocal), 2, &apos;0&apos;) end Observatii,
                       mat.codmat
                from prodmat mat
                     inner join prodcomp prod on prod.codprodcomp = mat.codprodcomp
                     left  join prodcomp pc   on pc.codobiect     = mat.codobiect and pc.implicit = 1
                where mat.codprodcomp = aCodProdComp
                order by mat.indexlocal
               ) loop
    insert into tmp_prodcomp (CodProdcomp, Codobiect, Cant, Observatii, CodProiect, NrCmd, CodMoneda, ImplicitOld) -- codproiectul imi da codmat pentru SQL lista, NrCmd imi da nivelul
    values (v_tmp.codprodcomp, v_tmp.CodObiect, v_tmp.Cant, v_tmp.Observatii, v_tmp.codmat, aNivel + 1, aCodMoneda, aCodOriginal);
    if v_tmp.CodProdComp &gt; 0 then
      BagaMateriale(v_tmp.Observatii, v_tmp.CodObiect, v_tmp.Cant, v_tmp.CodProdComp, aNivel + 1, aCodMoneda, aCodOriginal);
    end if;
  end loop;
end;

procedure PregatesteStructura is
begin
  -- asta e doar pentru testare
  --delete tmp_prodcomp;
  --insert into tmp_prodcomp (codprodcomp, codobiect, cant)
  --select pc.codprodcomp, pc.codobiect, pc.cant
  --from prodcomp pc
  --     inner join nartobj obj on obj.codobiect = pc.codobiect
  --where rownum &lt;= 100
  --order by obj.denumire;
  --

  update tmp_prodcomp tmp set codobiect = (select pc.codobiect from prodcomp pc where pc.codprodcomp = tmp.codprodcomp);
  update tmp_prodcomp set observatii = &apos; &apos;;
  for v_rec in (select codprodcomp, observatii, codobiect, cant
                from tmp_prodcomp
                order by observatii) loop
    BagaMateriale(v_rec.observatii, v_rec.codobiect, v_rec.cant, v_rec.codprodcomp, 0, v_rec.Codobiect, v_rec.codobiect);
  end loop;
  commit;
end;

procedure make_mat1(acodprodcomp in number, acodsemif in number) is
acount number(10);  
begin
  for v_mat in (select mat.codobiect
                from prodmat mat
                where mat.codprodcomp = acodsemif
               ) loop
    select count(*) into acount 
    from prodcomp 
    where codobiect = v_mat.codobiect and implicit = 1 
          and coalesce(inactiv,0) = 0;
    if acount = 0 then
      merge into manevra_prodcomp_clona m
      using (select acodprodcomp codprodcomp, v_mat.codobiect codobiect from dual) n
      on (m.codprodcomp = n.codprodcomp and m.codobiect = n.codobiect)
      when not matched then insert (codprodcomp,codobiect) values (n.codprodcomp, n.codobiect);
      commit;
    else
      for v_sem in (select codprodcomp
                    from prodcomp 
                    where codobiect = v_mat.codobiect and implicit = 1
                          and coalesce(inactiv,0) = 0
                   ) loop
        make_mat1(acodprodcomp, v_sem.codprodcomp);           
      end loop;             
    end if;
  end loop;              
end;  

procedure make_mat is
begin
  delete manevra_prodcomp_clona;
  for v_rec in (select pc.codprodcomp
                from prodcomp pc
                where not exists (select mat.codobiect from prodmat mat where mat.codobiect = pc.codobiect)
                      and pc.implicit = 1 and coalesce(pc.inactiv,0) = 0
                ) loop
    make_mat1(v_rec.codprodcomp, v_rec.codprodcomp);
  end loop;              
end;  

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert     VARCHAR2(1000);
sWith       VARCHAR2(10000);
sSelect     VARCHAR2(30000);
AnLunaLucru NUMBER(20);
VUSERID     NUMBER(20);
BEGIN
  VUSERID := PKG_GLOBALS.GETUSERID;
  if p_Sursa &lt;&gt; 2 then
    gSuplCols := &apos;prodmat mat,prodcomp pc,nartobj parinte, nartobj comp, num ump, num umc, nclasea clsp, nclasea clsc, nart artc, nart artp,NARTOBJ1  P1, NARTOBJ1  C1, NARTOBJ1 Par1, nartobjsubunit comps, nartobjsubunit prods&apos;;
  else
    gSuplCols := &apos;tmp_prodcomp tmp, prodmat mat,prodcomp pc,nartobj nodp, nartobj comp,num ump,num umc,nclasea clsp,nclasea clsc,nart artc,nart artp,NARTOBJ1 P1,NARTOBJ1 C1, nartobjsubunit comps, nartobjsubunit prods&apos;;
  end if;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTP&apos;, &apos;OEXT.CODOBIECT = PARINTE.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRP&apos;, &apos;OATR.CODOBIECT = PARINTE.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXTC&apos;, &apos;OEXT.CODOBIECT = COMP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATRC&apos;, &apos;OATR.CODOBIECT = COMP.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  AnLunaLucru := pkg_globals.GetANLUCRU * 12 + pkg_globals.GetLunaLUCRU;

  if p_flgAllArt = 1 then
    delete tmp_prodcomp;
    delete tmp_proiectnod;
    if p_Sursa = 0 then
      insert into tmp_prodcomp (codprodcomp, cant, pret)
        (select PC.codprodcomp, PC.cant, PC.Pret
         from prodcomp PC
         where nvl(pc.inactiv,0) = 0 and coalesce(pc.ascuns,0) = 0 
        );
    else if p_Sursa = 1 then
      insert into tmp_proiectnod(codproiectnod,necesar,cant,codobiect,codproiect)
      select pn.codproiectnod,pn.cant,pn.cant,pn.codobiect,pn.codproiect
      from proiectnod pn
           inner join proiect p on pn.codproiect = p.codproiect
      where nvl(pn.nodoriginal,0) = 0 and p.activ = 1 and coalesce(p.ascuns,0) = 0;
    else
      insert into tmp_prodcomp (codprodcomp, codobiect, cant)
      select pc.codprodcomp, pc.codobiect, pc.cant
      from prodcomp pc
           inner join nartobj obj on obj.codobiect = pc.codobiect
      where nvl(pc.inactiv,0) = 0 and coalesce(pc.ascuns,0) = 0
      order by obj.denumire;
    end if;
    end if;
  else 
    delete tmp_prodcomp;
    delete tmp_proiectnod;
    if p_Sursa = 0 then
      insert into tmp_prodcomp (codprodcomp, cant, pret, codobiect)
        (select PC.codprodcomp, man.cant, man.Pret, pc.codobiect
         from prodcomp PC
              inner join tmp_prodcomp_man man on man.codprodcomp = pc.codprodcomp and man.userid = pkg_globals.GETUSERID
        );
    else if p_Sursa = 1 then
      insert into tmp_proiectnod(codproiectnod,necesar,cant,codobiect,codproiect)
      select pn.codproiectnod,man.necesar,man.cant,pn.codobiect,pn.codproiect
      from proiectnod pn
           inner join tmp_proiectnod_man man on man.codproiectnod = pn.codproiectnod and man.userid = pkg_globals.GETUSERID
      where nvl(pn.nodoriginal,0) = 0;
    else
      insert into tmp_prodcomp (codprodcomp, codobiect, cant, pret)
      select pc.codprodcomp, pc.codobiect, man.cant, man.pret
      from prodcomp pc
           inner join nartobj          obj on obj.codobiect   = pc.codobiect
           inner join tmp_prodcomp_man man on man.codprodcomp = pc.codprodcomp and man.userid = pkg_globals.GETUSERID
      order by obj.denumire;
    end if;
    end if;   
  end if;
  COMMIT;

  if p_Sursa = 0 then
    for v_rec in (select codprodcomp from tmp_prodcomp) loop
      update tmp_prodcomp tmp
      set tmp.totalprod =
      (select sum(mat.valmat+man.valman)
        from prodcomp pc
             left join (
                        select sum(nvl(mat.pret,0)*nvl(mat.cant,0))*nvl(pg.coefmat,nvl(g.coefcheltmat,0)) valmat, mat.codprodgest, mat.codprodcomp
                        from prodmat mat
                             left join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest    g  on g.codgest       = pg.codgest
                        group by mat.codprodgest, mat.codprodcomp, g.coefcheltmat, pg.coefmat ) mat on mat.codprodcomp = pc.codprodcomp
             left join (
                        select sum(nvl(pm.tu,0) * nvl(t.tarif,0))*nvl(pg.coefman,nvl(g.coefcheltman,0)) valman, pm.codprodgest, pm.codprodcomp
                        from prodman pm
                             left join prodgest pg on pm.codprodgest = pg.codprodgest
                             left join ngest    g  on g.codgest      = pg.codgest
                             left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                                         from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND AnLunaLucru BETWEEN T1.ALStart and T1.ALStop
                                       ) T ON PM.CODTARIF = T.CODTARIF
                        group by pm.codprodgest, pm.codprodcomp, g.coefcheltman, pg.coefman ) man on man.codprodcomp = pc.codprodcomp
       where v_rec.codprodcomp = pc.codprodcomp
      )
      where tmp.codprodcomp = v_rec.codprodcomp;
    end loop;
  else if p_Sursa = 1 then
    insert into tmp_prodcomp (codprodcomp)
    select distinct pn.codreteta
    from tmp_proiectnod tmp
         inner join proiectnod pn on tmp.codproiect = pn.codproiect
         inner join prodcomp   pc on pn.codreteta   = pc.codprodcomp;

    for v_rec in (select codprodcomp from tmp_prodcomp) loop
      update tmp_prodcomp tmp
      set tmp.totalprod =
      (select sum(mat.valmat+man.valman)
        from prodcomp pc
             left join (
                        select sum(nvl(mat.pret,0)*nvl(mat.cant,0))*nvl(pg.coefmat,nvl(g.coefcheltmat,0)) valmat, mat.codprodgest, mat.codprodcomp
                        from prodmat mat
                             left join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest    g  on g.codgest       = pg.codgest
                        group by mat.codprodgest, mat.codprodcomp, g.coefcheltmat, pg.coefmat ) mat on mat.codprodcomp = pc.codprodcomp
             left join (
                        select sum(nvl(pm.tu,0) * nvl(t.tarif,0))*nvl(pg.coefman,nvl(g.coefcheltman,0)) valman, pm.codprodgest, pm.codprodcomp
                        from prodman pm
                             left join prodgest pg on pm.codprodgest = pg.codprodgest
                             left join ngest    g  on g.codgest      = pg.codgest
                             left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                                         from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND AnLunaLucru BETWEEN T1.ALStart and T1.ALStop
                                       ) T ON PM.CODTARIF = T.CODTARIF
                        group by pm.codprodgest, pm.codprodcomp, g.coefcheltman, pg.coefman ) man on man.codprodcomp = pc.codprodcomp
       where v_rec.codprodcomp = pc.codprodcomp
      )
      where tmp.codprodcomp = v_rec.codprodcomp;
    end loop;
  else
    PregatesteStructura;
  end if;
  end if;

  sInsert :=
   &apos;INSERT INTO &apos;||tmpName ||&apos;
     (
      SYSCOD,
      NAV_CodDoc,
      NAV_TipDoc,
      Reteta,
      DenumireP,
      DenumireC,
      CodExternP,
      CodExternC,
      val_mat,
      val_man,
      Gestiune,
      CoefMat,
      CoefMan,
      Pret,
      PretRef,
      PretVanz,
      Inactiv,
      Implicit,
      Tip,
      TipProdus,
      LotOptim,
      Cant,
      PretC,
      Tarif,
      TU,
      Zecimale,
      Regie,
      Nivel,
      NodP,
      Ordine &apos;;
  if p_Sursa = 2 then
    sInsert := sInsert||&apos;, Prefix &apos;;
  end if;
  sInsert := sInsert||gUserFields||&apos;)&apos;;

  if p_Sursa = 0 then
    sWith := &apos;with Regie as (
      select sum(mat.valmat+man.valman) val, pc.codprodcomp
      from prodcomp pc
           inner join tmp_prodcomp tmp on tmp.codprodcomp = pc.codprodcomp
           left join (
                      select sum(nvl(mat.pret,0)*nvl(mat.cant,0))*nvl(pg.coefmat, nvl(g.coefcheltmat,0)) valmat, mat.codprodgest, mat.codprodcomp
                      from prodmat mat
                           left join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest    g  on g.codgest       = pg.codgest
                      group by mat.codprodgest, mat.codprodcomp, g.coefcheltmat, pg.coefmat ) mat on mat.codprodcomp = pc.codprodcomp
           left join (
                      select sum(nvl(pm.tu,0) * nvl(t.tarif,0))*nvl(pg.coefman, nvl(g.coefcheltman,0)) valman, pm.codprodgest, pm.codprodcomp
                      from prodman pm
                           left join prodgest pg on pm.codprodgest = pg.codprodgest
                           left join ngest    g  on g.codgest      = pg.codgest
                           left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                                       from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart AND T1.ALStop 
                                     ) T ON PM.CODTARIF = T.CODTARIF
                      group by pm.codprodgest, pm.codprodcomp, g.coefcheltman, pg.coefman ) man on man.codprodcomp = pc.codprodcomp
      group by pc.codprodcomp)
    &apos;;
  else
    sWith := &apos;with Regie as (
      select sum(mat.valmat+man.valman) val, pc.codprodcomp
      from tmp_proiect tmp
           INNER JOIN PROIECTNOD PN0 ON TMP.CODPROIECT = PN0.CODPROIECT and nvl(PN0.nodoriginal,0) = 0
           inner join prodcomp   pc  on PN0.codreteta  = pc.codprodcomp
           left join (
                      select sum(nvl(mat.pret,0)*nvl(mat.cant,0))*nvl(pg.coefmat,nvl(g.coefcheltmat,0)) valmat, mat.codprodgest, mat.codprodcomp
                      from prodmat mat
                           left join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest    g  on g.codgest       = pg.codgest
                      group by mat.codprodgest, mat.codprodcomp, g.coefcheltmat, pg.coefmat ) mat on mat.codprodcomp = pc.codprodcomp
           left join (
                      select sum(nvl(pm.tu,0) * nvl(t.tarif,0))*nvl(pg.coefman,nvl(g.coefcheltman,0)) valman, pm.codprodgest, pm.codprodcomp
                      from prodman pm
                           left join prodgest pg on pm.codprodgest = pg.codprodgest
                           left join ngest    g  on g.codgest      = pg.codgest
                           left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                                       from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart AND T1.ALStop 
                                     ) T ON PM.CODTARIF = T.CODTARIF
                      group by pm.codprodgest, pm.codprodcomp, g.coefcheltman, pg.coefman ) man on man.codprodcomp = pc.codprodcomp
      group by pc.codprodcomp)
    &apos;;
  end if;

  if p_Sursa = 0 then
     sSelect := &apos;
      select
        PC.CodProdComp,
        PC.CodProdComp,
        504,
        PC.Obs Reteta,
        prod.denumire DenumireP,
        comp.denumire DenumireC,
        prod.codextern codexternp,
        comp.codextern codexternc,
        tmp.cant/pc.cant*mat.cant * mat.pret val_mat,
        0 val_man,
        ng.den_gest gestiune,
        nvl(pg.coefmat,ng.coefcheltmat) CoefMat,
        nvl(pg.coefman,ng.coefcheltman) CaoefMan,
        pc.Pret,
        p1.pretreferinta PretRef,
        pretm.lei PretVanz,
        case when nvl(pc.inactiv,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
        case when nvl(pc.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
        case when mat.tip = 3 then &apos;&apos;Material&apos;&apos; else case when mat.tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Complex&apos;&apos; end end Tip,
        &apos;&apos;Reteta&apos;&apos; TipProdus,
        pc.cant LotOptim,
        tmp.Cant/pc.cant*mat.Cant,
        mat.Pret PretC,
        0 Tarif,
        0 TU,
        ump.zecimale,
        tmp.cant/pc.cant*tmp.totalprod Regie,
        1 Nivel,
        prod.denumire,
        mat.indexlocal
        &apos;||gUserAlias||&apos;
      from
        prodcomp pc
        inner join tmp_prodcomp tmp on tmp.codprodcomp = pc.codprodcomp
        left join prodgest pg on pc.codprodcomp = pg.codprodcomp
        left join ngest    ng on pg.codgest     = ng.codgest
        left join (select man.codprodgest, sum(man.valoare) valoare
                   from prodman man
                   group by man.codprodgest) valman on valman.codprodgest = pg.codprodgest
        left join prodmat        mat     on pc.codprodcomp  = mat.codprodcomp and pg.codprodgest = mat.codprodgest
        left join nartobj        prod    on prod.codobiect  = pc.codobiect
        left join nart           artp    on prod.codarticol = artp.codarticol
        left join num            ump     on artp.um = ump.codum
        left join pretm                  on prod.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      P1      ON P1.CodObiect    = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart   and P1.ALStop
        LEFT  JOIN NARTOBJ1      Par1    ON Par1.CodObiect  = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN Par1.ALStart and Par1.ALStop
        left join nartobj        comp    on comp.codobiect  = mat.codobiect
        left join nartobjsubunit comps   on comp.codobiect  = comps.codobiect 
                                         and (comps.codgest is null or comps.codgest = 0)
                                         and comps.subunitate = pkg_globals.getsubunitate
        left join nartobjsubunit prods   on prod.codobiect = prods.codobiect 
                                         and (prods.codgest is null or prods.codgest = 0)
                                         and prods.subunitate = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      C1      ON C1.CodObiect    = mat.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop
        left join nart           artc    on comp.codarticol = artc.codarticol
        left join num            umc     on artc.um    = umc.codum
        left join nclasea        clsp    on artp.clasa = clsp.codclasea
        left join nclasea        clsc    on artc.clasa = clsc.codclasea
        left join nartobj        parinte on parinte.codobiect = prod.codobiect&apos;||
        gSuplJoins||&apos;
      where NVL(mat.codmat,0) &gt; 0 and
            nvl(pc.anulat, 0) = 0 and nvl(pc.operat, 0) = 1
      union all
      select
        PC.CodProdComp,
        PC.CodProdComp,
        504,
        PC.Obs Reteta,
        prod.denumire DenumireP,
        comp.denumire DenumireC,
        prod.codextern codexternp,
        comp.codextern codexternc,
        tmp.cant/pc.cant*rez.cant * rez.pret val_mat,
        0 val_man,
        ng.den_gest Gestiune,
        nvl(pg.coefmat,ng.coefcheltmat) CoefMat,
        nvl(pg.coefman,ng.coefcheltman) CaoefMan,
        pc.Pret,
        p1.pretreferinta PretRef,
        pretm.lei PretVanz,
        case when nvl(pc.inactiv,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
        case when nvl(pc.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
        &apos;&apos;Articol rezultat&apos;&apos; Tip,
        &apos;&apos;Reteta&apos;&apos; TipProdus,
        pc.Cant LotOptim,
        tmp.Cant/pc.cant*rez.Cant,
        rez.Pret PretC,
        0 Tarif,
        0 TU,
        ump.zecimale,
        tmp.cant/pc.cant*tmp.totalprod Regie,
        1 Nivel,
        prod.denumire,
        1 &apos;||gUserAlias||&apos;
      from
        prodcomp pc
        inner join tmp_prodcomp tmp on tmp.codprodcomp = pc.codprodcomp
        left join prodgest pg on pc.codprodcomp = pg.codprodcomp
        left join ngest    ng on pg.codgest     = ng.codgest
        left join (select man.codprodgest, sum(man.valoare) valoare
                   from prodman man
                   group by man.codprodgest) valman on valman.codprodgest = pg.codprodgest
        left join prodrez        rez     on pc.codprodcomp  = rez.codprodcomp and pg.codprodgest = rez.codprodgest
        left join prodmat        mat     on mat.codmat      = pc.codprodcomp - pc.codprodcomp
        left join nartobj        prod    on prod.codobiect  = pc.codobiect
        left join nart           artp    on prod.codarticol = artp.codarticol
        left join num            ump     on artp.um         = ump.codum
        left join pretm                  on prod.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      P1      ON P1.CodObiect    = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart   and P1.ALStop 
        LEFT  JOIN NARTOBJ1      Par1    ON Par1.CodObiect  = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN Par1.ALStart and Par1.ALStop
        left join nartobj        comp    on comp.codobiect  = rez.codobiect
        left join nartobjsubunit comps   on comp.codobiect  = comps.codobiect 
                                         and (comps.codgest is null or comps.codgest = 0)
                                         and comps.subunitate = pkg_globals.getsubunitate
        left join nartobjsubunit prods   on prod.codobiect  = prods.codobiect 
                                         and (prods.codgest is null or prods.codgest = 0)
                                         and prods.subunitate = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      C1      ON C1.CodObiect    = comp.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop
        left join nart           artc    on comp.codarticol = artc.codarticol
        left join num            umc     on artc.um    = umc.codum
        left join nclasea        clsp    on artp.clasa = clsp.codclasea
        left join nclasea        clsc    on artc.clasa = clsc.codclasea
        left join nartobj        parinte on parinte.codobiect = prod.codobiect&apos;||
        gSuplJoins||&apos;
      where NVL(rez.codrez,0) &gt; 0 and
            nvl(pc.anulat, 0) = 0 and nvl(pc.operat, 0) = 1
      union all
      select
        PC.CodProdComp,
        PC.CodProdComp,
        504,
        PC.Obs Reteta,
        prod.denumire DenumireP,
        op.denumire DenumireC,
        prod.codextern codexternp,
        &apos;&apos;&apos;&apos; codexternc,
        0 val_mat,
        tmp.cant/pc.cant*round(man.tu * t.tarif/60,5) val_man,
        ng.den_gest Gestiune,
        nvl(pg.coefmat,ng.coefcheltmat) CoefMat,
        nvl(pg.coefman,ng.coefcheltman) CaoefMan,
        pc.Pret,
        p1.pretreferinta PretRef,
        pretm.lei PretVanz,
        case when nvl(pc.inactiv ,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
        case when nvl(pc.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
        &apos;&apos;Manopera&apos;&apos; Tip,
        &apos;&apos;Reteta&apos;&apos; TipProdus,
        pc.Cant LotOptim,
        0 Cant,
        0 PretC,
        T.Tarif,
        tmp.cant/pc.cant*NVL(man.TU,0)/60 TU,
        ump.zecimale,
        tmp.cant/pc.cant*tmp.totalprod Regie,
        1 Nivel,
        prod.denumire,
        man.nrop &apos;||gUserAlias||&apos;
      from
        prodcomp pc
        inner join tmp_prodcomp tmp on tmp.codprodcomp = pc.codprodcomp
        left join prodgest pg on pc.codprodcomp = pg.codprodcomp
        left join ngest    ng on pg.codgest     = ng.codgest
        left join (select man.codprodgest, sum(round(man.tu * t.tarif/60,5)) valoare
                   from prodman man
                        left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                                    from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop 
                                  ) T ON Man.CODTARIF = T.CODTARIF
                   group by man.codprodgest) valman on valman.codprodgest = pg.codprodgest
        left join prodmat        mat   on mat.codmat      = pc.codprodcomp - pc.codprodcomp           
        left join prodman        man   on pc.codprodcomp  = man.codprodcomp and pg.codprodgest = man.codprodgest
        left join noper          op    on op.codop        = man.codop
        left join nartobj        prod  on prod.codobiect  = pc.codobiect
        left join nart           artp  on prod.codarticol = artp.codarticol
        left join num            ump   on artp.um         = ump.codum
        left join nartobj        comp  on comp.codobiect  = prod.codobiect - prod.codobiect
        left join nartobjsubunit comps on comp.codobiect  = comps.codobiect 
                                       and (comps.codgest is null or comps.codgest = 0)
                                       and comps.subunitate = pkg_globals.getsubunitate
        left join nartobjsubunit prods on prod.codobiect  = prods.codobiect 
                                       and (prods.codgest is null or prods.codgest = 0)
                                       and prods.subunitate = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      C1    ON C1.CodObiect    = comp.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop 
        left join nart           artc  on artc.codarticol = 0
        left join num            umc   on umc.codum       = 0
        left join nclasea        clsp  on artp.clasa = clsp.codclasea
        left join nclasea        clsc  on artc.clasa = clsc.codclasea
        left join pretm                on prod.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate
        LEFT JOIN NARTOBJ1       P1    ON P1.CodObiect    = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart and P1.ALStop
        LEFT  JOIN NARTOBJ1      Par1  ON Par1.CodObiect  = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN Par1.ALStart and Par1.ALStop
        left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                    from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop 
                  ) T                  ON Man.CODTARIF = T.CODTARIF
        left join nartobj      parinte on parinte.codobiect = prod.codobiect&apos;||
        gSuplJoins||&apos;
      where nvl(pc.anulat, 0) = 0 and nvl(pc.operat, 0) = 1 &apos;;
  else if p_Sursa = 1 then
    sSelect := &apos;
      select
        p.codproiect,
        p.codproiect,
        507,
        p.versiune Reteta,
        prod.denumire DenumireP,
        op.denumire DenumireC,
        prod.codextern codexternp,
        &apos;&apos;&apos;&apos; codexternc,
        0 val_mat,
        round(PN.cant/pc.cant * (pm.tu * t.tarif)/60,5) val_man,
        g.den_gest Gestiune,
        nvl(pg.coefmat,g.coefcheltmat) CoefMat,
        nvl(pg.coefman,g.coefcheltman) CaoefMan,
        pc0.Pret,
        p1.pretreferinta PretRef,
        pretm.lei PretVanz,
        case when 1-nvl(p.activ,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
        case when nvl(p.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
        &apos;&apos;Manopera&apos;&apos; Tip,
        &apos;&apos;Proiect&apos;&apos; TipProdus,
        pc0.Cant LotOptim,
        0 Cant,
        0 PretC,
        T.Tarif,
        NVL(PM.TU,0)/60 TU,
        ump.zecimale,
        tmp.cant/PN0.Cant*PN.Cant/Pc.Cant*tmpr.totalprod Regie,
        NVL(PN.Nivel,0) Nivel,
        parinte.denumire,
        NVL(PN.ordine,0) &apos;||gUserAlias||&apos;
      from TMP_PROIECTNOD TMP
           INNER JOIN PROIECT       P       ON P.CodProiect = TMP.CodProiect
           INNER JOIN PROIECTNOD    PN      ON P.CODPROIECT = PN.CODPROIECT
           INNER JOIN PROIECTNOD    PN0     ON P.CODPROIECT = PN0.CODPROIECT and nvl(PN0.nodoriginal,0) = 0
           inner join prodcomp      pc      on PN.codreteta = pc.codprodcomp
           inner join prodcomp      pc0     on PN0.codreteta     = pc0.codprodcomp
           inner join nartobj       prod    on prod.codobiect    = p.codobiectprod
           INNER JOIN tmp_prodcomp  tmpr    on tmpr.codprodcomp  = pn.codreteta
           left join nartobj        parinte on parinte.codobiect = PN.codobiect
           left join nart           artp    on prod.codarticol   = artp.codarticol
           left join num            ump     on artp.um        = ump.codum
           left join nartobj        comp    on comp.codobiect = prod.codobiect - prod.codobiect
           left join nartobjsubunit comps   on comp.codobiect = comps.codobiect 
                                            and (comps.codgest is null or comps.codgest = 0)
                                            and comps.subunitate = pkg_globals.getsubunitate
           left join nartobjsubunit prods   on prod.codobiect = prods.codobiect 
                                            and (prods.codgest is null or prods.codgest = 0)
                                            and prods.subunitate = pkg_globals.getsubunitate
           LEFT  JOIN NARTOBJ1      C1      ON C1.CodObiect      = comp.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop 
           left join nart           artc    on artc.codarticol   = comp.codarticol
           left join num            umc     on umc.codum  = 0
           left join nclasea        clsp    on artp.clasa = clsp.codclasea
           left join nclasea        clsc    on artc.clasa = clsc.codclasea
           left join pretm                  on prod.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate
           left join prodgest       pg      on pc.codprodcomp  = pg.codprodcomp
           LEFT JOIN NARTOBJ1       P1      ON P1.CodObiect    = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart and P1.ALStop
           LEFT  JOIN NARTOBJ1      Par1    ON Par1.CodObiect  = PN.codobiect   AND &apos;||AnLunaLucru||&apos; BETWEEN Par1.ALStart and Par1.ALStop
           left join (select man.codprodgest, sum(round(man.tu * t.tarif/60,5)) valoare
                      from prodman man
                        left JOIN (select T1.codtarif, T1.Tarif, t.denumire
                                   from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop
                                  ) T ON Man.CODTARIF = T.CODTARIF
                   group by man.codprodgest) valman on valman.codprodgest = pg.codprodgest
           left join ngest    g   on nvl(pg.codgest, 0) = g.codgest
           left join prodman  pm  on pm.codprodcomp     = pc.codprodcomp and pm.codprodgest = pg.codprodgest
           left join prodmat  mat on mat.codmat         = p.codproiect - p.codproiect
           left join noper    op  on pm.codop           = op.codop
           left join locmunca lm  on lm.codloc          = pm.codloc
           left JOIN ( select T1.codtarif, T1.Tarif, t.denumire
                       from TARIFEMAN1 T1 inner join tarifeman t on t1.codtarif = t.codtarif AND &apos;||AnLunaLucru||&apos; BETWEEN T1.ALStart and T1.ALStop
                     ) T ON PM.CODTARIF = T.CODTARIF&apos;||
        gSuplJoins||&apos;
     where nvl(pc.anulat, 0) = 0 and pn.codreteta &gt; 0
           and nvl(op.codop,0) &gt; 0 &apos;;

    sSelect := sSelect||&apos;union all
    SELECT
      p.codproiect,
      p.codproiect,
      507,
      P.versiune Reteta,
      OBJP.Denumire DenumireP,
      COMP.Denumire DenumireC,
      OBJP.codextern codexternp,
      COMP.codextern codexternc,
      tmp.cant/PN0.Cant*PN.cant * mat.pret val_mat,
      0 val_man,
      g.den_gest Gestiune,
      nvl(pg.coefmat,g.coefcheltmat) CoefMat,
      nvl(pg.coefman,g.coefcheltman) CaoefMan,
      mat.pret,
      p1.pretreferinta PretRef,
      pretm.lei PretVanz,
      case when 1-nvl(p.activ,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
      case when nvl(p.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
      case when PN.tip = 3 then &apos;&apos;Material&apos;&apos; else case when PN.Tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Complex&apos;&apos; end end Tip,
      &apos;&apos;Proiect&apos;&apos; TipProdus,
      pc0.Cant LotOptim,
      tmp.cant/PN0.Cant*pn.Cant,
      mat.pret PretC,
      0 Tarif,
      0 TU,
      ump.zecimale,
      tmp.cant/PN0.Cant*PN.Cant/Pc.Cant*tmpr.totalprod Regie,
      NVL(PN.Nivel,0) Nivel,
      parinte.denumire,
      NVL(Ppar.ordine,0) &apos;||gUserAlias||&apos;
    FROM
      TMP_PROIECTNOD TMP
      INNER JOIN PROIECT       P       ON P.CodProiect  = TMP.CodProiect
      INNER JOIN PROIECTNOD    PN      ON P.CODPROIECT  = PN.CODPROIECT
      INNER JOIN PROIECTNOD    PN0     ON P.CODPROIECT  = PN0.CODPROIECT AND NVL(PN0.NODORIGINAL, 0) = 0
      left JOIN PRODCOMP       PC      ON PN.CODRETETA  = PC.CODPRODCOMP
      left JOIN PRODCOMP       PC0     ON PN0.CODRETETA = PC0.CODPRODCOMP
      left JOIN tmp_prodcomp   tmpr    on tmpr.codprodcomp   = pn.codreteta
      left JOIN PRODMAT        MAT     ON MAT.CODMAT         = PN.CODPRODMAT
      left JOIN PROIECTNOD     PPar    ON PPar.CODPROIECTNOD = nvl(PN.nodoriginal,0)
      left join prodgest       pg      on mat.codprodgest    = pg.codprodgest
      left join ngest          g       on pg.codgest         = g.codgest
      left JOIN NARTOBJ        OBJP    ON P.CODOBIECTPROD    = OBJP.CODOBIECT
      left JOIN NARTOBJ        Prod    ON P.CODOBIECTPROD    = Prod.CODOBIECT
      left join nartobj        parinte on parinte.codobiect  = nvl(ppar.CodObiect, objp.codobiect)
      left join nart           artp    on objp.codarticol    = artp.codarticol
      left join num            ump     on artp.um            = ump.codum
      left JOIN NARTOBJ        comp    ON PN.CODOBIECT       = comp.CODOBIECT
      left join nartobjsubunit comps   on comp.codobiect     = comps.codobiect 
                                       and (comps.codgest is null or comps.codgest = 0)
                                       and comps.subunitate = pkg_globals.getsubunitate
      left join nartobjsubunit prods   on prod.codobiect     = prods.codobiect 
                                       and (prods.codgest is null or prods.codgest = 0)
                                       and prods.subunitate = pkg_globals.getsubunitate
      LEFT JOIN NARTOBJ1       C1      ON C1.CodObiect    = comp.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop
      left join nart           artc    on comp.codarticol = artc.codarticol
      left join num            umc     on artc.um         = umc.codum
      left join nclasea        clsp    on artp.clasa      = clsp.codclasea
      left join nclasea        clsc    on artc.clasa      = clsc.codclasea
      LEFT JOIN NARTOBJ1       P1      ON P1.CodObiect    = OBJP.CodObiect                    AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart and P1.ALStop
      LEFT JOIN NARTOBJ1       Par1    ON Par1.CodObiect  = nvl(ppar.CodObiect, PN.codobiect) AND &apos;||AnLunaLucru||&apos; BETWEEN Par1.ALStart and Par1.ALStop
      left join pretm                  on OBJP.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate&apos;||
      gSuplJoins||&apos;
    WHERE PN.TIP = 3&apos;;
  else
    sSelect := &apos;
      select
        tmp.CodProdComp,
        tmp.CodProdComp,
        504,
        PC.Obs Reteta,
        prod.denumire DenumireP,
        comp.denumire DenumireC,
        prod.codextern codexternp,
        comp.codextern codexternc,
        nvl(tmp.cant,0) * nvl(mat.pret,0) val_mat,
        0 val_man,
        ng.den_gest gestiune,
        nvl(pg.coefmat,ng.coefcheltmat) CoefMat,
        nvl(pg.coefman,ng.coefcheltman) CaoefMan,
        pc.Pret,
        p1.pretreferinta PretRef,
        pretm.lei PretVanz,
        case when nvl(pc.inactiv ,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Inactiv,
        case when nvl(pc.implicit,0) = 1 then &apos;&apos;DA&apos;&apos; else &apos;&apos;NU&apos;&apos; end Implicit,
        case when mat.tip = 3 then &apos;&apos;Material&apos;&apos; else case when mat.tip = 2 then &apos;&apos;Reper&apos;&apos; else &apos;&apos;Complex&apos;&apos; end end Tip,
        &apos;&apos;Reteta&apos;&apos; TipProdus,
        pc.cant LotOptim,
        nvl(tmp.Cant,0),
        mat.Pret PretC,
        0 Tarif,
        0 TU,
        ump.zecimale,
        tmp.cant/pc.cant*tmp.totalprod Regie,
        nvl(tmp.NrCmd,0) Nivel,
        nodp.denumire,
        mat.indexlocal,
        tmp.observatii
        &apos;||gUserAlias||&apos;
      from
        tmp_prodcomp tmp
        inner join prodcomp      pc    on tmp.codprodcomp = pc.codprodcomp
        left join prodmat        mat   on tmp.codproiect  = mat.codmat
        left join prodgest       pg    on mat.codprodgest = pg.codprodgest and pg.codprodcomp = pc.codprodcomp
        left join ngest          ng    on pg.codgest      = ng.codgest
        left join prodcomp       retp  on mat.codprodcomp = retp.codprodcomp
        left join nartobj        nodp  on retp.codobiect  = nodp.codobiect
        left join nartobj        prod  on prod.codobiect  = tmp.implicitold
        left join nart           artp  on prod.codarticol = artp.codarticol
        left join num            ump   on artp.um         = ump.codum
        left join pretm                on prod.codobiect  = pretm.codobiect and nvl(pretm.implicit,0) = 1 and pretm.subunitatea = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      P1    ON P1.CodObiect    = prod.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN P1.ALStart and P1.ALStop
        left join nartobj        comp  on comp.codobiect  = mat.codobiect
        left join nartobjsubunit comps on comp.codobiect  = comps.codobiect 
                                       and (comps.codgest is null or comps.codgest = 0)
                                       and comps.subunitate = pkg_globals.getsubunitate
        left join nartobjsubunit prods on prod.codobiect  = prods.codobiect 
                                       and (prods.codgest is null or prods.codgest = 0)
                                       and prods.subunitate = pkg_globals.getsubunitate
        LEFT  JOIN NARTOBJ1      C1    ON C1.CodObiect    = mat.CodObiect AND &apos;||AnLunaLucru||&apos; BETWEEN C1.ALStart and C1.ALStop
        left join nart           artc  on comp.codarticol = artc.codarticol
        left join num            umc   on artc.um         = umc.codum
        left join nclasea        clsp  on artp.clasa      = clsp.codclasea
        left join nclasea        clsc  on artc.clasa      = clsc.codclasea&apos;||
        gSuplJoins||&apos; &apos;;
  end if;
  end if;

  --delete x;
  --insert into x(test) values(sselect);

  DELETE TMP_PRODCOMP_MAN   WHERE USERID = VUSERID;
  DELETE TMP_PROIECTNOD_MAN WHERE USERID = VUSERID;
  DELETE TMP_CMD            WHERE USERID = VUSERID;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  
  
  COMMIT;
END;

end pkg_list_base_tehprod; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TEME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC5FF9455ACF37A8695A28CD81147DFF3EED1AA2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_teme is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
BEGIN
  gSuplCols :=&apos;NPERS FORMATOR, CURSURI C&apos; ;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(Den_tema, Ore, Pret, Formator &apos;||gUserFields||&apos;)
  SELECT t.den_tema, t.ore, t.pret, formator.nume||&apos;&apos; &apos;&apos;||formator.prenume &apos;||gUserAlias||&apos;
  FROM teme t
    LEFT JOIN npers formator ON formator.codpers = t.codformator
    LEFT JOIN cursuri1 c1 ON c1.codtema = t.codtema
    LEFT JOIN cursuri c ON c.codcurs = c1.codcurs&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_TEME;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TERMEDCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A708EAD3BF1FDD222D671C9C34335D2BCC925B3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_termedcli IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(2000);
  sSelect VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;npart npart&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(PARTENER, MONEDA, &apos;||chr(13)||
                                         &apos;TOTAL, TERMED&apos;||gUserFields||&apos;) &apos;||chr(13);
   sSelect := &apos;with stingeri as (select stingere.*, general.codgeneral from stingere inner join obligpif on stingere.codstingatorpif = obligpif.codobligpif inner JOIN general ON obligpif.codgeneral = general.codgeneral), &apos;||chr(13)||
&apos;stinsi as ( SELECT i.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM iesiri i &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = i.codies and g.semnificatie &lt;&gt; 500 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 1) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
&apos;      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL SELECT &apos;||chr(13)||
&apos;i.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM iesiri i &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = i.codies and g.semnificatie &lt;&gt; 500 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
&apos;      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL SELECT &apos;||chr(13)||
&apos;i.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM intrari i &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie = 100 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
&apos;      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT nc.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM nc1 &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = nc1.codnc1 and g.semnificatie &lt;&gt; 500 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;     INNER JOIN nc ON nc1.codnc = nc.codnc &apos;||chr(13)||
&apos;WHERE g.tipdoc = 35 AND &apos;||chr(13)||
&apos;      nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT tr1.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM trezor1 tr1 &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = tr1.codtrezor1 and g.semnificatie &lt;&gt; 500 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;     INNER JOIN trezor tr ON tr1.codtrezor = tr.codtrezor &apos;||chr(13)||
&apos;WHERE (g.tipdoc in (30, 31)) AND (NVL(tr1.anulat, 0) = 0) AND &apos;||chr(13)||
&apos;      tr1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT cstins.datadoc data_stins, &apos;||chr(13)||
&apos;obstins.codobligpif, &apos;||chr(13)||
&apos;obstins.codpart codpart &apos;||chr(13)||
&apos;FROM compens cstins &apos;||chr(13)||
&apos;     INNER JOIN general g ON g.coddoc = cstins.codcompens and g.semnificatie &lt;&gt; 500 &apos;||chr(13)||
&apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
&apos;WHERE g.tipdoc = 28  AND &apos;||chr(13)||
&apos;      cstins.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) ),&apos;||chr(13)||
&apos;stingatori as (&apos;||chr(13)||
   &apos;  SELECT &apos;||chr(13)||
   &apos;    o.codobligpif CodObligPIF,&apos;||chr(13)||
   &apos;    t1.datadoc DATA, &apos;||chr(13)||
   &apos;    t.Subunitatea, &apos;||chr(13)||
   &apos;    g.moneda &apos;||chr(13)||
   &apos;  FROM trezor1 t1 &apos;||chr(13)||
   &apos;       INNER JOIN general g ON t1.codtrezor1 = g.coddoc &apos;||chr(13)||
   &apos;       INNER JOIN obligpif o ON o.codgeneral = g.codgeneral &apos;||chr(13)||
   &apos;       INNER JOIN trezor t ON t1.codtrezor = t.codtrezor&apos;||chr(13)||
   &apos;  WHERE T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataS||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND ((G.TipDoc IN (29, 30, 31) AND t1.TipTranz = 1) OR (t1.TipTranz = 1 AND t1.ObiectTranz = 1)) &apos;||chr(13)||
   &apos;UNION ALL &apos;||chr(13)||
   &apos;  SELECT &apos;||chr(13)||
   &apos;    o.codobligpif CodObligPIF,&apos;||chr(13)||
   &apos;    c.datadoc DATA, &apos;||chr(13)||
   &apos;    C.Subunitatea, &apos;||chr(13)||
   &apos;    g.moneda &apos;||chr(13)||
   &apos;  FROM compens c &apos;||chr(13)||
   &apos;       INNER JOIN general g ON g.coddoc = c.codcompens &apos;||chr(13)||
   &apos;       INNER JOIN obligpif o ON o.codgeneral = g.codgeneral &apos;||chr(13)||
   &apos;  WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataS||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND G.TipDoc = 28 &apos;||chr(13)||
   &apos;)&apos;||chr(13)||
   &apos;SELECT centralizare.partener, centralizare.Simbolmoneda, sum(centralizare.val_stingator) TOTAL, sum(centralizare.val_stingator*centralizare.difzile)/sum(centralizare.val_stingator) TERMED&apos;||gUserAlias||&apos; FROM ( &apos;||chr(13)||
       &apos;select stingeri.valoare VAL_STINGATOR, &apos;||chr(13)||
       &apos;npart.den_part PARTENER,&apos;||chr(13)||
       &apos;stingatori.Data DATA, &apos;||chr(13)||
       &apos;stinsi.Data_stins DATA_STINS, &apos;||chr(13)||
       &apos;trunc(stingatori.Data - stinsi.data_stins) DIFZILE, &apos;||chr(13)||
       &apos;mon.simbol simbolmoneda &apos;||chr(13)||
 &apos; FROM stingatori &apos;||chr(13)||
 &apos;      INNER JOIN stingeri on stingeri.codstingatorpif = stingatori.codobligpif &apos;||chr(13)||
 &apos;      INNER JOIN stinsi on stingeri.codstinspif = stinsi.codobligpif &apos;||chr(13)||
 &apos;      LEFT  JOIN npart npart on stinsi.codpart = npart.codpart &apos;||chr(13)||
 &apos;      LEFT  JOIN nmonede MON ON stingatori.moneda = MON.CodMoneda&apos; ||
 gSuplJoins||
 PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;stingatori&apos;,&apos;subunitatea&apos;,&apos; WHERE&apos;);
 sSelect := sSelect||&apos;  ) CENTRALIZARE GROUP BY centralizare.partener, centralizare.simbolmoneda &apos;;

 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
 COMMIT;


 END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_termedcli;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TERMEDFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5599A61108256AA98B36258FCFBF4C2636D46CF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_termedfurn IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
 sInsert VARCHAR2(2000);
 sSelect VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;npart npart, nmonede mon, nclasep clsp, nagenda ag, nlocalit loc, njudet jud, npers agent, npers agent_inc, nsubunit substingatori, nsubunit substinsi&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


   sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(PARTENER, MONEDA, &apos;||chr(13)||
                                         &apos;TOTAL, TERMED&apos;||gUserFields||&apos;) &apos;||chr(13);
   sSelect :=
      &apos;with stingeri as ( &apos;||chr(13)||
      &apos;select stingere.*, &apos;||chr(13)||
      &apos;       general.codgeneral &apos;||chr(13)||
      &apos;from stingere &apos;||chr(13)||
      &apos;     inner join obligpif on stingere.codstingatorpif = obligpif.codobligpif &apos;||chr(13)||
      &apos;     inner JOIN general ON obligpif.codgeneral = general.codgeneral &apos;||chr(13)||
      &apos;), &apos;||chr(13)||
      &apos;stinsi as ( &apos;||chr(13)||
      &apos;SELECT &apos;||chr(13)||
      &apos;  i.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM intrari i &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie &lt;&gt; 600 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 1) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
      &apos;      AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;))&apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT &apos;||chr(13)||
      &apos;  i.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM intrari i &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie &lt;&gt; 600 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
      &apos;      AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;))&apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT &apos;||chr(13)||
      &apos;  i.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM iesiri i &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = i.codies and g.semnificatie = 200 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) &apos;||chr(13)||
      &apos;      AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;))&apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT &apos;||chr(13)||
      &apos;  nc.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM nc1 &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = nc1.codnc1 and g.semnificatie &lt;&gt; 600 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;     INNER JOIN nc ON nc1.codnc = nc.codnc &apos;||chr(13)||
      &apos;WHERE g.tipdoc = 35 &apos;||chr(13)||
      &apos;      AND nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)&apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT &apos;||chr(13)||
      &apos;  tr1.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM trezor1 tr1 &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = tr1.codtrezor1 and g.semnificatie &lt;&gt; 600 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;     INNER JOIN trezor tr ON tr1.codtrezor = tr.codtrezor &apos;||chr(13)||
      &apos;WHERE (NVL(tr1.anulat, 0) = 0) and (g.tipdoc = 35 OR g.tipdoc = 31 OR g.tipdoc = 29) &apos;||chr(13)||
      &apos;      AND tr1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
&apos;UNION ALL &apos;||chr(13)||
&apos;SELECT &apos;||chr(13)||
      &apos;  cstins.datadoc data_stins, &apos;||chr(13)||
      &apos;  obstins.codobligpif codobligpif, &apos;||chr(13)||
      &apos;  obstins.codpart codpart &apos;||chr(13)||
      &apos;FROM compens cstins &apos;||chr(13)||
      &apos;     INNER JOIN general g ON g.coddoc = cstins.codcompens and g.semnificatie &lt;&gt; 600 &apos;||chr(13)||
      &apos;     INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral &apos;||chr(13)||
      &apos;WHERE g.tipdoc = 28 &apos;||chr(13)||
      &apos;      AND cstins.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
      &apos; ), &apos;||chr(13)||
      &apos;stingatori as (&apos;||chr(13)||
      &apos;  SELECT &apos;||chr(13)||
      &apos;    o.codobligpif CodObligPIF,&apos;||chr(13)||
      &apos;    t1.datadoc DATA, &apos;||chr(13)||
      &apos;    t.subunitatea Subunitatea, &apos;||chr(13)||
      &apos;    g.moneda &apos;||chr(13)||
      &apos;  FROM trezor1 t1 &apos;||chr(13)||
      &apos;       INNER JOIN trezor t ON t1.codtrezor = t.codtrezor &apos;||chr(13)||
      &apos;       INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc &apos;||chr(13)||
      &apos;       INNER JOIN obligpif o ON o.codgeneral = g.codgeneral &apos;||chr(13)||
      &apos;  WHERE (T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataS||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;)) AND (((G.TipDoc IN (29, 30, 31)) AND (t1.TipTranz = 0)) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 1)) &apos;||chr(13)||
      &apos;  UNION ALL &apos;||chr(13)||
      &apos;  SELECT &apos;||chr(13)||
      &apos;    o.codobligpif CodObligPIF,&apos;||chr(13)||
      &apos;    c.datadoc DATA, &apos;||chr(13)||
      &apos;    c.subunitatea Subunitatea, &apos;||chr(13)||
      &apos;    g.moneda &apos;||chr(13)||
      &apos;  FROM compens c &apos;||chr(13)||
      &apos;       INNER JOIN general g ON g.coddoc = c.codcompens and g.tipdoc = 28 &apos;||chr(13)||
      &apos;       INNER JOIN obligpif o ON o.codgeneral = g.codgeneral &apos;||chr(13)||
      &apos;  WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataS||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||pkg_list_alegperioada.getDataF||&apos;&apos;&apos;,&apos;&apos;DD/MM/YYYY&apos;&apos;) &apos;||chr(13)||
      &apos;)&apos;||chr(13)||
   &apos;SELECT centralizare.partener, centralizare.SimbolMoneda, sum(centralizare.val_stingator) TOTAL, sum(centralizare.val_stingator*centralizare.difzile)/sum(centralizare.val_stingator) TERMED&apos;||gUserAlias||&apos; FROM ( &apos;||chr(13)||
       &apos;select stingeri.valoare VAL_STINGATOR, &apos;||chr(13)||
       &apos;npart.den_part PARTENER,&apos;||chr(13)||
       &apos;stingatori.Data DATA, &apos;||chr(13)||
       &apos;stinsi.Data_stins DATA_STINS, &apos;||chr(13)||
       &apos;trunc(stingatori.Data - stinsi.data_stins) DIFZILE, &apos;||chr(13)||
       &apos;mon.simbol SimbolMoneda &apos;||chr(13)||
 &apos; FROM stingatori &apos;||chr(13)||
 &apos;      INNER JOIN stingeri on stingeri.codstingatorpif = stingatori.codobligpif &apos;||chr(13)||
 &apos;      INNER JOIN stinsi on stingeri.codstinspif = stinsi.codobligpif &apos;||chr(13)||
 &apos;      LEFT  JOIN npart npart on stinsi.codpart = npart.codpart &apos;||chr(13)||
 &apos;      LEFT  JOIN nmonede mon on stingatori.moneda = mon.codmoneda &apos;||
 gSuplJoins||
 PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;stingatori&apos;,&apos;subunitatea&apos;,&apos; WHERE&apos;);
 sSelect := sSelect||&apos;  ) CENTRALIZARE GROUP BY centralizare.partener, centralizare.SimbolMoneda &apos;;

 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
 COMMIT;


 END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_termedfurn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8F40DE5C003BCD3223EA1D72387052BB91D6609</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TOPART IS

  vDataINI  VARCHAR2(10):=&apos;&apos;;
  vDataFIN  VARCHAR2(10):=&apos;&apos;;
  vPeFurn   BOOLEAN;
  vSortType NUMBER(2);
  vDocType  NUMBER(2);
  vCodAtribut NUMBER(20);
  vCondData VARCHAR2(100);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams ( pDataINI  IN VARCHAR2,
                      pDataFIN  IN VARCHAR2,
                      pPeFurn   IN NUMBER,
                      pSortType IN NUMBER,
                      pDocType  IN NUMBER,
                      V_CODJOB1 IN NUMBER  DEFAULT 0,
                      pCodAtribut IN NUMBER DEFAULT 0
										) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataIni;
  sDataF     VARCHAR2(10) := pDataFin;

begin
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  vdataIni      := sDataS;
  vdataFin      := sDataF;

  vPeFurn   := pPeFurn = 1;
  vSortType := pSortType;
  vDocType  := pDocType;
  vCodAtribut := pCodAtribut;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    CLOB;
  sInsert1   CLOB;
  sUpdate    CLOB;
  sOrdine    VARCHAR2(100);
  sMoneda    VARCHAR2(100);
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  sCurs      VARCHAR2(500);
  sCod       VARCHAR2(20);
  aUserID    NUMBER(20);
  vALIni     NUMBER;
  vALFin     NUMBER;
  sFurn      VARCHAR2(1000) := &apos;0 CODFURN, 0 TIPFURN,&apos;;
  sJoinFurn  VARCHAR2(1000) := &apos;&apos;;
  sArtAtrib1 VARCHAR2(5000) := &apos;, NULL ARTATRIB1&apos;;
  sFiltruObj VARCHAR2(5000) := &apos;&apos;;
BEGIN
  IF vCodAtribut &gt; 0 THEN
    sArtAtrib1 := &apos;,
    ( SELECT Min(aa1.valoare)
      FROM nartatr aa
        LEFT JOIN natrobj ao ON ao.codartatr = aa.codartatr
        LEFT JOIN natrib1 aa1 ON aa1.codvalatr = ao.codvalatr
      WHERE aa.codarticol = nao.codarticol AND ao.codobiect = nao.codobiect AND aa.codatribut = &apos;||vCodAtribut||&apos;
    ) ARTATRIB1&apos;;
    sFiltruObj := &apos; and exists (select aa.codatribut from nartatr aa where aa.codarticol = nao.codarticol AND aa.codatribut = &apos;||vCodAtribut||&apos;) &apos;;
  END IF;
  vALIni := EXTRACT (YEAR  FROM To_Date(vDataIni,&apos;DD.MM.YYYY&apos;)) * 12 +
            EXTRACT (MONTH FROM To_Date(vDataIni,&apos;DD.MM.YYYY&apos;));

  vALFin := EXTRACT (YEAR  FROM To_Date(vDataFin,&apos;DD.MM.YYYY&apos;)) * 12 +
            EXTRACT (MONTH FROM To_Date(vDataFin,&apos;DD.MM.YYYY&apos;));

  IF vDocType = 1
  THEN sCod := &apos;, 26&apos;;
  ELSE sCod := &apos;, 20&apos;;
  END IF;

  gSuplCols := &apos;NARTOBJ NAO, NUM NUM, NART NART, NCLASEA CLSA, NCLASEAS CLSAS&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  aUserID := pkg_globals.GETUSERID;

  DELETE TMP_ANLUNA_VAL;
  DELETE TMP_LST_TOPART;
  DELETE TMP_CMD WHERE USERID = aUserID;

  --folosesc tmp_cmd pentru cursorul de valachiz de stingeri la nedescarcate
  insert into tmp_cmd(codobiect,cantc,canta,userid,auxfield)
  SELECT II1.CODIES1, SUM(LL1.CANT * (NS.PRET - Coalesce(NS.ADAOS,0))) VAL, sum(LL1.cant), aUserID,
         STRAGG3200(P.DEN_PART)
  FROM IESIRI1 I1
    INNER JOIN IESIRI     I   ON I.CODIES       = I1.CODIES
    INNER JOIN LIVR1      LL1 ON LL1.CODIES1    = I1.CODIES1
    INNER JOIN NIRSTOC    NS  ON LL1.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN IESVALLINK IVL ON IVL.CODIES1    = I1.CODIES1
    INNER JOIN LIVR1      L1  ON IVL.CODLIVR1   = L1.CODLIVR1
    INNER JOIN IESIRI1    II1 ON L1.CODIES1     = II1.CODIES1
    LEFT  JOIN NPART        P ON P.CODPART      = NS.FURN
  WHERE I.ANULAT = 0 AND I.DATADOC BETWEEN To_Date(vDataIni,&apos;DD.MM.YYYY&apos;) AND To_Date(vDataFin,&apos;DD.MM.YYYY&apos;)
        AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR PKG_GLOBALS.GETSUBUNITATE = I.SUBUNITATEA)
  GROUP BY II1.CODIES1;

  INSERT INTO TMP_ANLUNA_VAL(AL, VALOARE)
  SELECT vALIni+level-1, Coalesce(To_Number(pkg_categconst.GetValConstanta(&apos;ContIncasareFactura&apos; ,0,vALIni+level-1)),-1)
  FROM dual
  CONNECT BY level &lt;= vALFin-vALIni+1;

  IF vSortType IN (3,5) AND pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCurs   := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i.datadoc )&apos;;
    sMoneda := pkg_monede.get_simbol_moneda(aMonedaV);
  ELSE
    sCurs   := &apos;1&apos;;
    sMoneda := pkg_monede.get_simbol_moneda(0);
  END IF;

  sOrdine :=  CASE vSortType
                WHEN 1 THEN &apos;T.CANT&apos;
                WHEN 2 THEN &apos;T.VALLEI&apos;
                WHEN 3 THEN &apos;T.VALLEI/T.CURS&apos;
                WHEN 4 THEN &apos;T.VALADAOSLEI&apos;
                WHEN 5 THEN &apos;T.VALADAOSLEI/T.CURS&apos;
              END;

  IF vPeFurn THEN
    sFurn :=&apos;
      CASE
        WHEN COALESCE(NS_ROOT.CODGESTPROD ,0) &lt;&gt; 0 THEN NS_ROOT.CODGESTPROD
        WHEN COALESCE(NS_ROOT.FURN ,0) &lt;&gt; 0 THEN NS_ROOT.FURN
        WHEN COALESCE(I_ROOT.TIPDOC, 0)= 7 THEN I_ROOT.CODGESTPROD
        ELSE COALESCE(I_ROOT.PARTENER, 0)
      END CODFURN,
      CASE
        WHEN COALESCE(NS_ROOT.CODGESTPROD ,0) &lt;&gt; 0 THEN 1
        WHEN COALESCE(NS_ROOT.FURN ,0) &lt;&gt; 0 THEN 0
        WHEN COALESCE(I_ROOT.TIPDOC, 0)= 7 THEN 1
        ELSE 0
      END TIPFURN,&apos;;
    sJoinFurn :=&apos;
      LEFT  JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
      LEFT  JOIN NIRSTOC NS_ROOT ON NS_ROOT.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT  JOIN INTRARI1 I1_ROOT ON I1_ROOT.CODINTR1 = NS_ROOT.CODINTR1
      LEFT  JOIN INTRARI I_ROOT ON I_ROOT.CODINTR = I1_ROOT.CODINTR&apos;;
  END IF;

  vCondData := &apos;BETWEEN TO_DATE (&apos;&apos;&apos;||vDataINI||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE (&apos;&apos;&apos;||vDataFIN||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  sInsert   :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    CodObiect,DenArt, DenUM, Valuta, Cant, DenFurn, CodExtern, CodIntern, Producator,
    PretLei, ValoareLei, ValAdaosLei, PretAchLei, AdaosLei, ProcAdaosLei,
    PretVal, ValoareVal, ValAdaosVal, PretAchVal, AdaosVal, ProcAdaosVal,
    Ordine,Doc,Subunitatea,ArtAtrib1&apos;||gUserFields||&apos;)
  SELECT
    NAO.CodObiect,NAO.DENUMIRE, NUM.DEN_UM, &apos;&apos;&apos;||sMoneda||&apos;&apos;&apos;, T.CANT, COALESCE(T.FURNIZOR, FURN.DEN_PART, GPROD.DEN_GEST) DENFURN, NAO.CODEXTERN, NAO.CODINTERN, PROD.DEN_PART PRODUCATOR,
    T.VALLEI/T.CANT       , T.VALLEI       , T.VALADAOSLEI       , case when coalesce(t.cantachiz,0) &lt;&gt; 0 then T.VALACHLEI/T.CANTACHIZ else 0 end , T.VALADAOSLEI/T.CANT       , DECODE(T.VALACHLEI,0,0,T.VALLEI*100/T.VALACHLEI - 100),
    T.VALLEI/T.CANT/T.CURS, T.VALLEI/T.CURS, T.VALADAOSLEI/T.CURS, T.VALACHLEI/T.CANT/T.CURS, T.VALADAOSLEI/T.CANT/T.CURS, DECODE(T.VALACHLEI,0,0,T.VALLEI*100/T.VALACHLEI - 100),
    &apos;||sOrdine||&apos; Ordine,T.DOC,T.SUBUNITATEA&apos;||sArtAtrib1||gUserAlias||&apos;
  FROM TMP_LST_TOPART T
    LEFT JOIN NPART FURN ON FURN.CODPART = T.CODFURN AND T.TIPFURN = 0
    LEFT JOIN NGEST GPROD ON GPROD.CODGEST = T.CODFURN AND T.TIPFURN = 1
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = T.CODOBIECT
    LEFT JOIN NPART PROD ON PROD.CODPART = NAO.CODPRODUCATOR
    LEFT JOIN NART NART ON NART.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM NUM ON NART.UM = NUM.CODUM
    LEFT JOIN NCLASEA CLSA ON NART.Clasa = CLSA.CodClaseA
    LEFT JOIN NCLASEAS CLSAS ON NART.ClasaStatist = CLSAS.CodClaseAS&apos;||
    gSuplJoins||&apos;
  WHERE T.CANT &lt;&gt; 0 AND TO_NUMBER(Coalesce(NART.TIPARTICOL,&apos;&apos;0&apos;&apos;)) = TO_NUMBER(T.TIPARTICOL)&apos;||sFiltruObj;

  sInsert1 := &apos;INSERT INTO TMP_LST_TOPART(tiparticol,codobiect,codfurn,tipfurn,cant,valachlei,vallei,tvalei,datadoc,doc,subunitatea,curs,cantachiz,furnizor)
    SELECT
      &apos;&apos;0&apos;&apos; TIPARTICOL, I1.CODOBIECT,&apos;||
      sFurn||&apos;
      L1.CANT,
      CASE
        WHEN Coalesce(L1.codnirstoc, 0) &lt;&gt; 0 then (NS.PRET - NS.ADAOS) * L1.CANT
        ELSE coalesce(LV.PretAchiz,0) * L1.RestIesVal + COALESCE(ST.CANTC,0)
      END VALACHLEI,
      CASE WHEN i1.pu*i1.cant = 0 THEN 0 ELSE (i1.pu*i1.cant-CASE WHEN i.tipdoc = 21 THEN i1.Tva ELSE 0 END)*CASE WHEN Coalesce(G.CURS,0)= 0 THEN 1 ELSE G.CURS END*Coalesce(i1.coefdiscmaj,1)*i1.pretorig*l1.cant/i1.pu/i1.cant END VALLEI,
      CASE WHEN i1.pu*i1.cant = 0 THEN 0 ELSE i1.Tva                                                        *CASE WHEN Coalesce(G.CURS,0)= 0 THEN 1 ELSE G.CURS END*Coalesce(i1.coefdiscmaj,1)*i1.pretorig*l1.cant/i1.pu/i1.cant END TVALEI,
      I.DATADOC, I.PREFIXDOC||&apos;&apos; &apos;&apos;||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) DOC, S.DEN_SUBUNIT SUBUNITATEA,
      &apos;||sCurs||&apos;
      ,CASE
        WHEN Coalesce(L1.codnirstoc, 0) &lt;&gt; 0 then L1.CANT
        ELSE L1.RestIesVal
      END CANTACHIZ, null
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES=I.CODIES
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
      INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
      LEFT  JOIN GENERAL G ON G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODIES AND G.SEMNIFICATIE &lt;&gt; 210 AND G.SEMNIFICATIE &lt;&gt; 211
      LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT  JOIN LIVRVAL LV ON LV.CodLivr1 = L1.CodLivr1
      LEFT  JOIN TMP_CMD ST ON ST.CODOBIECT = I1.CODIES1 AND ST.USERID = &apos;||aUserID||chr(13)||
      sJoinFurn||&apos;
    WHERE I.DATADOC &apos;||vCondData||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos; AND Coalesce(I.INFOCM,0) = 0
      AND NOT I.TIPDOC IN (14, 15, 16, 23, 24&apos;||sCod||&apos;)
      AND Coalesce(I.ANULAT,0) = 0
      AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
    UNION ALL
    SELECT
      &apos;&apos;0&apos;&apos; TIPARTICOL, I1.CODOBIECT,&apos;||
      sFurn||&apos;
      L1.CANT,
      CASE
        WHEN Coalesce(L1.codnirstoc, 0) &lt;&gt; 0 then (NS.PRET - NS.ADAOS) * L1.CANT
        ELSE coalesce(LV.PretAchiz,0) * L1.RestIesVal + COALESCE(ST.CANTC,0)
      END VALACHLEI,
      CASE WHEN i1.cant = 0 THEN i1.pu*l1.cant ELSE (i1.pu*i1.cant-i1.tva)*l1.cant/i1.cant END *
      CASE
        WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
        ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, -1, 1, i1.pu * i1.cant, i1.TVA)
      END VALLEI,
      CASE WHEN i1.cant = 0 THEN 0 ELSE Coalesce(i1.tva,0)*l1.cant/i1.cant END *
      CASE
        WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
        ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, -1, 2, i1.pu * i1.cant, i1.TVA)
      END TVALEI,
      I.DATADOC, I.PREFIXDOC||&apos;&apos; &apos;&apos;||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) DOC, S.DEN_SUBUNIT SUBUNITATEA,
      &apos;||sCurs||&apos;
      ,CASE
        WHEN Coalesce(L1.codnirstoc, 0) &lt;&gt; 0 then L1.CANT
        ELSE ST.CANTA
      END CANTACHIZ,
      ST.AUXFIELD
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES=I.CODIES
      INNER JOIN LIVR L ON L.CODIES = I.CODIES
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
      INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
      LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT  JOIN LIVRVAL LV ON LV.CodLivr1 = L1.CodLivr1
      LEFT  JOIN TMP_CMD ST ON ST.CODOBIECT = I1.CODIES1 AND ST.USERID = &apos;||aUserID||chr(13)||
      sJoinFurn||&apos;
      LEFT  JOIN TMP_ANLUNA_VAL Excl ON Excl.al = i.an*12+i.luna AND EXCL.VALOARE = COALESCE(NS.CodIOArt, LV.CodIOArt, 0)
    WHERE I.DATADOC &apos;||vCondData||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
      AND I.TIPDOC = 16
      AND Coalesce(I.ANULAT,0) = 0
      AND Excl.VALOARE IS NULL
      AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;
    UNION ALL
    SELECT
      &apos;&apos;0&apos;&apos; TIPARTICOL, I1.CODOBIECT,
      0 CODFURN, 0 TIPFURN,
      I1.CANT CANT,
      0 VALACHLEI,
      CASE WHEN i1.pu = 0 THEN 0 ELSE (i1.pu*i1.cant-CASE WHEN i.tipdoc = 21 THEN i1.Tva ELSE 0 END)*CASE WHEN Coalesce(G.CURS,0)= 0 THEN 1 ELSE G.CURS END*i1.pretorig/i1.pu*Coalesce(i1.coefdiscmaj,1) END VALLEI,
      CASE WHEN i1.pu = 0 THEN 0 ELSE i1.Tva                                                        *CASE WHEN Coalesce(G.CURS,0)= 0 THEN 1 ELSE G.CURS END*i1.pretorig/i1.pu*Coalesce(i1.coefdiscmaj,1) END TVALEI,
      I.DATADOC, I.PREFIXDOC||&apos;&apos; &apos;&apos;||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) DOC, S.DEN_SUBUNIT SUBUNITATEA,
      &apos;||sCurs||&apos;,
      0,
      NULL
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES=I.CODIES
      INNER JOIN GENERAL G ON G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODIES
      INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
    WHERE I.DATADOC &apos;||vCondData||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos; AND Coalesce(I.INFOCM,0) = 0
      AND NOT I.TIPDOC IN (14, 15, 16, 23, 24&apos;||sCod||&apos;)
      AND Coalesce(I.ANULAT,0) = 0
      AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos; AND I1.TIPLINIE &lt;&gt; &apos;&apos;G&apos;&apos; AND I1.TIPLINIE &lt;&gt; &apos;&apos;T&apos;&apos;
    UNION ALL
    SELECT
      &apos;&apos;0&apos;&apos; TIPARTICOL, I1.CODOBIECT,
      0 CODFURN, 0 TIPFURN,
      I1.CANT CANT,
      0 VALACHLEI,
      (i1.pu*i1.cant-i1.tva) *
      CASE
        WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
        ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, -1, 1, i1.pu * i1.cant, i1.TVA)
      END VALLEI,
      i1.tva *
      CASE
        WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
        ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, -1, 2, i1.pu * i1.cant, i1.TVA)
      END TVALEI,
      I.DATADOC, I.PREFIXDOC||&apos;&apos; &apos;&apos;||I.NRDOC||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) DOC, S.DEN_SUBUNIT SUBUNITATEA,
      &apos;||sCurs||&apos;,
      0,
      NULL
    FROM IESIRI I
      INNER JOIN IESIRI1 I1 ON I1.CODIES=I.CODIES
      INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
    WHERE I.DATADOC &apos;||vCondData||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
      AND I.TIPDOC = 16
      AND Coalesce(I.ANULAT,0) = 0
      AND I1.TIPLINIE &lt;&gt; &apos;&apos;=&apos;&apos; AND I1.TIPLINIE &lt;&gt; &apos;&apos;G&apos;&apos; AND I1.TIPLINIE &lt;&gt; &apos;&apos;T&apos;&apos;&apos;;

  sUpdate := &apos;UPDATE &apos;||tmpName||&apos; SET Total = (SELECT SUM(ValoareLei) FROM &apos;||tmpName||&apos;)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert1, aListID, aListVer);
  execute immediate &apos;UPDATE TMP_LST_TOPART SET VALADAOSLEI = CASE WHEN TIPARTICOL = &apos;&apos;1&apos;&apos; THEN 0 ELSE VALLEI - VALACHLEI END &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sUpdate , aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_TOPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TOPCLIANI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D715F2C6086E90014047A12D67A70E2EED24E3D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_topcliani IS

  vLunaStart  NUMBER(10);
  vLunaFin    NUMBER(10);
  vTotiPart   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(pLunaStart IN NUMBER   DEFAULT 1,
                    pLunaFin   IN NUMBER   DEFAULT 12,
                    pTotiPart  IN NUMBER   DEFAULT 1,
                    V_CODJOB1 IN NUMBER  DEFAULT 0 
										) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := &apos;01.01.2018&apos;;
  sDataF     VARCHAR2(10) := &apos;12.12.2018&apos;;
begin
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  vLunaStart := pLunaStart;
  vLunaFin   := pLunaFin;
  vTotiPart  := pTotiPart = 1;
END;

FUNCTION LunaIni return number is
begin
  return vLunaStart;
end;  

FUNCTION LunaFin return number is
begin
  return vLunaFin;
end;  

FUNCTION TotiPart return boolean is
BEGIN
  return vTotiPart;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(5000);
BEGIN
  gSuplCols := &apos;npart p, nagenda ss, npers ag&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  if pkg_list_base_topcliani.TotiPart then
    insert into tmp_manevra_liste (filtru, valoare)
    select &apos;CODPART&apos;, codpart from npart where codpart &gt; 0;
  end if;
  
  delete tmp_toppeani;
  if pkg_globals.GETSUBUNITATE &gt; 1 then
    insert into tmp_toppeani (an, val, codpart)
    select to_number(mana.valoare),
           G.ValTot_Val,
           to_number(manp.valoare)
    from tmp_manevra_liste mana,
         tmp_manevra_liste manp,
    (
    SELECT nvl(SUM(S.ValTot_Val), 0) ValTot_Val, S.An, S.Partener
          FROM
          (
          SELECT
              SUM(case when i.moneda &gt; 0 then i.valdoc * decode(nvl(i.curs,0),0,1,nvl(i.curs,0)) else i.valdoc end) ValTot_Val,
                  I.An,
                  I.Partener
            FROM IESIRI I
            WHERE i.subunitatea = pkg_globals.GETSUBUNITATE
            AND I.TipDoc  NOT IN (20, 21)
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            GROUP BY I.An, I.Partener
            UNION ALL
            SELECT
              SUM(case when i.moneda &gt; 0 then i.valdoc * decode(nvl(i.curs,0),0,1,nvl(i.curs,0)) else i.valdoc end) ValTot_Val,
                  I.An,
                  I.Partener
            FROM IESIRI I
            WHERE i.subunitatea = pkg_globals.GETSUBUNITATE
            AND I.TipDoc = 21
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            GROUP BY I.An, I.Partener
           ) S
           GROUP BY S.An, S.Partener
           ) G
    where mana.filtru = &apos;AN&apos; and manp.filtru = &apos;CODPART&apos;
          AND G.An = to_number(mana.valoare) AND G.Partener = to_number(manp.valoare);
  else
    insert into tmp_toppeani (an, val, codpart)
    select to_number(mana.valoare),
           G.ValTot_Val,
           to_number(manp.valoare)
    from tmp_manevra_liste mana,
         tmp_manevra_liste manp,
    (
    SELECT nvl(SUM(S.ValTot_Val), 0) ValTot_Val, S.An, S.Partener
          FROM
          (
          SELECT
              SUM(case when i.moneda &gt; 0 then i.valdoc * decode(nvl(i.curs,0),0,1,nvl(i.curs,0)) else i.valdoc end) ValTot_Val,
                  I.An,
                  I.Partener
            FROM IESIRI I
            WHERE I.TipDoc  NOT IN (20, 21)
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            GROUP BY I.An, I.Partener
            UNION ALL
            SELECT
              SUM(case when i.moneda &gt; 0 then i.valdoc * decode(nvl(i.curs,0),0,1,nvl(i.curs,0)) else i.valdoc end) ValTot_Val,
                  I.An,
                  I.Partener
            FROM IESIRI I
            WHERE I.TipDoc = 21
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            GROUP BY I.An, I.Partener
           ) S
           GROUP BY S.An, S.Partener
           ) G
    where mana.filtru = &apos;AN&apos; and manp.filtru = &apos;CODPART&apos;
          AND G.An = to_number(mana.valoare) AND G.Partener = to_number(manp.valoare);
  end if;

  delete tmp_toppeani where nvl(val, 0) = 0;
  delete tmp_manevra_liste man where man.filtru = &apos;CODPART&apos; and man.Valoare not in (select codpart from tmp_toppeani);

  sInsert := &apos; insert into &apos;||tmpName||&apos; (CodPart, Den_Part, Agent&apos;||gUserFields||&apos;) &apos;||chr(13)||
             &apos; select to_number(man.valoare), p.den_part, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume&apos;||gUserAlias||chr(13)||
             &apos; from tmp_manevra_liste man &apos;||chr(13)||
             &apos;      inner join npart p on to_number(man.valoare) = p.codpart &apos;||chr(13)||
             &apos;      left join nagenda ss on ss.codpart = p.codpart and ss.sediusocial between 4 and 7 and NVL(ss.INACTIV, 0) = 0 &apos;||chr(13)||
             &apos;      left join npers ag on ag.codpers = nvl(ss.codagent,0)&apos;||
             gSuplJoins||chr(13)||
             &apos; where man.filtru = &apos;&apos;CODPART&apos;&apos; &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);           

  for v_rec in (select * from tmp_toppeani) loop
    sInsert := &apos; update &apos;||tmpName||
               &apos; set &apos;||
               &apos;   AN&apos;||v_rec.an||&apos; = &apos;||replace(to_char(v_Rec.Val), &apos;,&apos;, &apos;.&apos;)||
               &apos; where CodPart = &apos;||v_Rec.Codpart;

    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  end loop;

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_topcliani;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TOPCLIENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EE39507C5F4E277C32A18AB9DEB82E906B2ABB0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TOPCLIENTI IS

  vDataINI    VARCHAR2(10);
  vDataFIN    VARCHAR2(10);
  vAllIOA     BOOLEAN;
  vAllCls     BOOLEAN;
  vAvize      BOOLEAN;
  vAduCust    BOOLEAN;
  vAduEmul    BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams (
  pDataINI  IN VARCHAR2,
  pDataFIN  IN VARCHAR2,
  pAllIOArt IN NUMBER DEFAULT 1,
  pAllCls   IN NUMBER DEFAULT 1,
  pAvize    IN NUMBER DEFAULT 1,
  pAduCust  IN NUMBER DEFAULT 0,
  pAduEmul  IN NUMBER DEFAULT 0,
  pCodJob1  IN NUMBER DEFAULT 0)
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataIni := pDataIni;
  vDataFin := pDataFin;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  vAvize   := Coalesce(pAvize,   1) = 1;
  vAllIOA  := Coalesce(pAllIOArt,1) = 1;
  vAllCls  := Coalesce(pAllCls,  1) = 1;
  vAduCust := Coalesce(pAduCust, 0) = 1;
  vAduEmul := Coalesce(pAduEmul, 0) = 1;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsTmp     CLOB;
  sUpdTmp     CLOB;
  sInsert     CLOB;
  vCondData   VARCHAR2(100);
  sCust       VARCHAR2(100)  := &apos;&apos;;
  sTipDocS    VARCHAR2(1000) := &apos;19&apos;;
  sTipDocX    VARCHAR2(1000) := &apos;19&apos;;
  sCondCls    VARCHAR2(1000) := &apos;&apos;;
  sJoinCls    VARCHAR2(1000) := &apos;&apos;;
  sCondIOA    VARCHAR2(1000) := &apos;&apos;;
  eCondIOA    VARCHAR2(1000) := &apos;&apos;;
  vMonedaSitV NUMBER(20);
  vBancaSitV  NUMBER(20);
  sMonedaSitV VARCHAR2(6);
BEGIN

  --pkg_globals.setdebugmode(TRUE);
  gSuplCols := &apos;TMP_TOPCLI T, NSUBUNIT S, NPART CLI, NAGENDA SLIVR, NPERS AGENT, NARTOBJ NAO, NART NA, NUM UM&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vCondData := &apos;BETWEEN TO_DATE (&apos;&apos;&apos;||vDataINI||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE (&apos;&apos;&apos;||vDataFIN||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  IF NOT vAduCust THEN
    sCust := &apos; AND nvl(I.Custodie,0) = 0 &apos;;
  END IF;

  IF NOT vAllCls THEN
    sJoinCls := &apos;
    INNER JOIN NARTOBJ O ON o.codobiect = i1.codobiect
    INNER JOIN NART A ON a.codarticol = o.codarticol &apos;;

    sCondCls := &apos;
    AND a.clasa IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODCLASEA&apos;&apos;)&apos;;
  END IF;

  IF NOT vAllIOA THEN
    sCondIOA := &apos;
    AND Coalesce(ns.codioart, lv.codioart) IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODIOART&apos;&apos;)&apos;;

    eCondIOA := &apos;
    AND i1.codioart IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;&apos;CODIOART&apos;&apos;)&apos;;
  END IF;

  IF vAvize THEN
    sTipDocS := sTipDocS ||&apos;, 20&apos;;
    sTipDocX := sTipDocX ||&apos;, 20&apos;;
  ELSE
    sTipDocS := sTipDocS ||&apos;, 26&apos;;
  END IF;

  DELETE TMP_TOPCLI;

  sInsTmp := &apos;
  INSERT INTO TMP_TOPCLI (
    codsubunit, codclient, codlocatie, codagent, codobiect,
    coddoc, tipdoc, coddoc1, idxloc, tiplinie, nrdoc, datadoc, cant,
    val,
    tva,
    valachiz
  )
  SELECT
    i.subunitatea, Coalesce(i.partener,0), i.codlocatie, Coalesce(i.agent,0), i1.codobiect,
    i.codies, i.tipdoc, i1.codies1, i1.indexlocal, i1.tiplinie, i.nrdoc, i.datadoc, i1.cant,
    i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END Val,
    CASE WHEN i1.pu = 0 THEN 0 ELSE i1.tva*i1.pretorig*Coalesce(i1.coefdiscmaj,1)/i1.pu END*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END tva,
    i1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END valachiz
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies&apos;||
    sJoinCls||&apos;
  WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
    AND I.TipDoc IN (&apos;||sTipDocS||&apos;) AND NVL(I.Anulat, 0) = 0 AND I.Operat = 1 AND NVL(I.Initializari, 0) = 0 &apos;||sCust||&apos;
    AND I1.TIPLINIE IN (&apos;&apos;S&apos;&apos;, &apos;&apos;V&apos;&apos;)&apos;||
    sCondCls;

  IF vAllIOA THEN
    LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);
  END IF;

  sInsTmp := &apos;
  INSERT INTO TMP_TOPCLI (
    codsubunit, codclient, codlocatie, codagent, codobiect,
    coddoc, tipdoc, coddoc1, idxloc, tiplinie, nrdoc, datadoc, cant,
    val,
    tva,
    valachiz
  )
  SELECT
    i.subunitatea, Coalesce(i.partener,0), i.codlocatie, Coalesce(i.agent,0), i1.codobiect,
    i.codies, i.tipdoc, i1.codies1, i1.indexlocal, i1.tiplinie, i.nrdoc, i.datadoc, l1.cant,
    l1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END Val,
    CASE WHEN i1.pu*i1.cant = 0 THEN 0 ELSE i1.tva*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*l1.cant/i1.pu/i1.cant END*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END tva,
    Coalesce(lv.pretachiz,ns.pret-ns.adaos,0)*L1.cant valachiz
  FROM iesiri i
    INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
    INNER JOIN iesiri1 i1 ON i1.codies1 = l1.codies1
    LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
    LEFT  JOIN livrval lv on lv.codlivr1 = l1.codlivr1&apos;||
    sJoinCls||&apos;
  WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
    AND I.TipDoc IN (&apos;||sTipDocX||&apos;) AND NVL(I.Anulat, 0) = 0 AND I.Operat = 1 AND NVL(I.Initializari, 0) = 0 &apos;||sCust||&apos;
    AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;&apos;||
    sCondCls||
    sCondIOA;

  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);

  sInsTmp := &apos;
  INSERT INTO TMP_TOPCLI (
    codsubunit, codclient, codlocatie, codagent, codobiect,
    coddoc, tipdoc, coddoc1, idxloc, tiplinie, nrdoc, datadoc, cant,
    val,
    tva,
    valachiz
  )
  SELECT
    i.subunitatea, Coalesce(i.partener,0), i.codlocatie, Coalesce(i.agent,0), i1.codobiect,
    i.codies, i.tipdoc, i1.codies1, i1.indexlocal, i1.tiplinie, i.nrdoc, i.datadoc, l1.cant,
    l1.cant*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END Val,
    CASE WHEN i1.pu*i1.cant = 0 THEN 0 ELSE i1.tva*i1.pretorig*Coalesce(i1.coefdiscmaj,1)*l1.cant/i1.pu/i1.cant END*CASE WHEN Coalesce(I.MONEDA, 0) = 1 THEN 1 ELSE Coalesce(I.CURS,1) END tva,
    Coalesce(lv.pretachiz,ns.pret-ns.adaos,0)*L1.cant valachiz
  FROM iesiri i
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN ieslink il ON il.codies1 = i1.codies1 AND Coalesce(il.codlinieaviz, 0) &lt;&gt; 0
    INNER JOIN livr1 l1 ON l1.codies1 = il.codlinieaviz
    INNER JOIN livr l ON l.codlivr = l1.codlivr AND l.tiplivr = 20
    LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
    LEFT  JOIN livrval lv on lv.codlivr1 = l1.codlivr1&apos;||
    sJoinCls||&apos;
  WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
    AND I.TipDoc IN (26) AND NVL(I.Anulat, 0) = 0 AND I.Operat = 1 AND NVL(I.Initializari, 0) = 0 &apos;||sCust||&apos;
    AND I1.TIPLINIE = &apos;&apos;=&apos;&apos;&apos;||
    sCondCls||
    sCondIOA;

  IF NOT vAvize THEN
    LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);
  END IF;

  sInsTmp := &apos;
  INSERT INTO TMP_TOPCLI (
    codsubunit, codclient, codlocatie, codagent, codobiect,
    coddoc, tipdoc, coddoc1, idxloc, tiplinie, nrdoc, datadoc, cant,
    val,
    tva,
    valachiz
  )
  SELECT
    c.subunitatea, e.codpart, Coalesce(e.codagent,0), e.codlocatie, i1.codobiect,
    e.codemulare, 64, i1.codemulare1, i1.indexlocal, i1.tiplinie, e.nrbon, e.databon, i1.cant,
    i1.cant * i1.pret - i1.tva,
    i1.tva,
    CASE
      WHEN Coalesce(e.codmonetar,0) = 0 THEN 0
      ELSE (
             SELECT CASE WHEN SUM(L1.cant) = 0 THEN 0 ELSE i1.cant*SUM(Coalesce(lv.pretachiz,ns.pret-ns.adaos,0)*L1.cant)/SUM(L1.cant) END
             FROM livr l
               INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
               LEFT  JOIN nirstoc ns on ns.codnirstoc = l1.codnirstoc
               LEFT  JOIN livrval lv on lv.codlivr1 = l1.codlivr
             WHERE l.codies = e.codmonetar AND l.tiplivr = 16 AND i1.CodObiect = Nvl(lv.CodObiect, Ns.CodObiect)
           )
    END valachiz
  FROM emulare e
    INNER JOIN ncasemarcat c ON c.codcasemarcat = e.codcasamarcat
    INNER JOIN emulare1 i1 ON i1.codemulare = e.codemulare
    LEFT JOIN Iesiri x ON x.codies = e.codIes&apos;||
    sJoinCls||&apos;
  WHERE e.databon &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ||&apos;
    AND (Coalesce(e.CodIes,0) = 0 or Coalesce(x.InfoCM,0) = 1)
		AND Coalesce(e.codpart,0) &gt; 0&apos;||
    sCondCls||
    eCondIOA;

  IF vAduEmul THEN
    LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);
  END IF;

  LIST_EXECUTE_IMMEDIATE(&apos;DELETE TMP_TOPCLI WHERE CANT = 0&apos; , aListID, aListVer);

  --sUpdTmp := &apos;UPDATE TMP_TOPCLI SET val = val - tva WHERE tipdoc = 16&apos;;
  --LIST_EXECUTE_IMMEDIATE(sUpdTmp, aListID, aListVer);

  vMonedaSitV := pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  vBancaSitV  := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos; , PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  sUpdTmp := &apos;UPDATE TMP_TOPCLI SET curs = PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||vMonedaSitV||&apos;,&apos;||vBancaSitV||&apos;,datadoc) &apos;;

  IF Coalesce(vMonedaSitV, 0) &lt;&gt; 0 AND Coalesce(vBancaSitV, 0) &lt;&gt; 0 THEN
    LIST_EXECUTE_IMMEDIATE(sUpdTmp, aListID, aListVer);
    sMonedaSitV := pkg_monede.get_simbol_moneda(vMonedaSitV);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Subunitatea, Client, SediuL, Agent, DenArt, DenUM,
    Cant, Valoare, ValAchiz, ValAdaos,
    Curs, Valuta&apos;||gUserFields||&apos;)
  SELECT
    S.Den_Subunit, CLI.Den_Part, SLIVR.OBS, NumePrenume(AGENT.NUme, AGENT.Prenume), NAO.Denumire, UM.Den_UM,
    T.CANT, T.Val, T.ValAchiz, CASE WHEN T.TIPLINIE = &apos;&apos;=&apos;&apos; THEN T.Val - T.ValAchiz ELSE 0 END ValAdaos,
    T.Curs, &apos;&apos;&apos;||sMonedaSitV||&apos;&apos;&apos;&apos;||gUserAlias||&apos;
  FROM TMP_TOPCLI T
    LEFT JOIN NSUBUNIT S    ON S.COdSubunit = T.CodSubunit
    LEFT JOIN NPART CLI     ON CLI.CodPart = T.CodClient
    LEFT JOIN NAGENDA SLIVR ON SLIVR.CodAgenda = T.CodLocatie
    LEFT JOIN NPERS AGENT   ON AGENT.CodPers = T.CodAgent
    LEFT JOIN NARTOBJ NAO   ON NAO.CodObiect = T.CodObiect
    LEFT JOIN NART NA       ON NA.CodArticol = NAO.CodArticol
    LEFT JOIN NUM UM        ON UM.CodUM = NA.UM&apos;||
    gSuplJoins||&apos;&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert := &apos;update &apos;||tmpName||&apos; set NrFact = (select count(*) from (select distinct coddoc,tipdoc from TMP_TOPCLI))&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_topclienti;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TOPFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E73F9D59679AC4981DC20B53E09F916ECDBE62B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TOPFURN IS

  vDataINI    VARCHAR2(10);
  vDataFIN    VARCHAR2(10);
  InLei       NUMBER(1);
  vAllIOArt   BOOLEAN;
  vAllCls     BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GETALLIOART_N RETURN NUMBER IS
BEGIN
  IF vAllIOArt THEN RETURN 1;
  ELSE RETURN 0;
  END IF;
END;

FUNCTION GETALLCLS_N RETURN NUMBER IS
BEGIN
  IF vAllCls THEN RETURN 1;
  ELSE RETURN 0;
  END IF;
END;

PROCEDURE setParams (
  pDataINI  IN VARCHAR2,
  pDataFIN  IN VARCHAR2,
  pInLei    IN NUMBER,
  pCodJob1  IN NUMBER  DEFAULT 0,
  pAllIOArt IN NUMBER DEFAULT 1,
  pAllCls   IN NUMBER DEFAULT 1)
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vDataIni := pDataIni;
  vDataFin := pDataFin;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  InLei     := pInLei;
  vAllIOArt := pAllIOArt = 1;
  vAllCls   := pAllCls = 1;
  if not vAllCls then
    for v_rec in (
      select tmp.valoare, cls.codident 
      from tmp_manevra_liste tmp
           inner join nclasea cls on cls.codclasea = tmp.valoare
      where tmp.filtru = &apos;CODCLASEA&apos;
    ) loop
      delete tmp_manevra_liste where filtru = &apos;CODCLASEA&apos; and valoare = v_rec.valoare;
      insert into tmp_manevra_liste(filtru, valoare)
      select &apos;CODCLASEA&apos;, codclasea
      from nclasea
      where INSTRB(v_rec.codident, codident) = 1;
    end loop;
    commit;
  end if;
END;

FUNCTION vInLei RETURN NUMBER IS
BEGIN
  RETURN vInLei;
END;

FUNCTION GetNrFact_Art(aCodObiect IN NUMBER, aCodPart IN NUMBER, aTip IN NUMBER) RETURN NUMBER IS
aNr NUMBER(20) := 0;
aCodSubunit NUMBER(20);
BEGIN
  aCodSubunit := PKG_GLOBALS.GETSUBUNITATE;

  if vAllIOArt then
    SELECT COUNT(DISTINCT I.CodIntr) INTO aNr
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NPART P ON I.Partener = P.CodPart
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND P.CodPart = aCodPart
      AND aCodObiect = Decode(aTip,1,I1.CodObiect,I1.ContDiscount)
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea);
  else
    SELECT COUNT(DISTINCT CodIntr) INTO aNr
    FROM (
    SELECT I.CODINTR
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
      INNER JOIN NPART P ON I.Partener = P.CodPart
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND P.CodPart = aCodPart AND I1.TIPLINIE = &apos;=&apos;
      AND aCodObiect = Decode(aTip,1,I1.CodObiect,I1.ContDiscount)
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
      AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
    UNION ALL
    SELECT I.CODINTR
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
      INNER JOIN NPART P ON I.Partener = P.CodPart
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND P.CodPart = aCodPart AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
      AND aCodObiect = Decode(aTip,1,I1.CodObiect,I1.ContDiscount)
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
        );
  end if;
  RETURN aNr;
END;

PROCEDURE SetNrFact_Art IS
aNr NUMBER(20) := 0;
aCodSubunit NUMBER(20);
BEGIN
  aCodSubunit := PKG_GLOBALS.GETSUBUNITATE;

  if vAllIOArt then
    INSERT INTO TMP_CMD_TMP1(COD1,VAL,TIP,COD2)
    SELECT PARTENER, COUNT(DISTINCT CODINTR), &apos;FACTART&apos;,CODOBIECT FROM (
    SELECT DISTINCT I.PARTENER, I.CodIntr,I1.CODOBIECT
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
    ) GROUP BY PARTENER, CODOBIECT;
    INSERT INTO TMP_CMD_TMP1(COD1,VAL,TIP,COD2)
    SELECT PARTENER, COUNT(DISTINCT CODINTR), &apos;-FACTART&apos;,CONTDISCOUNT FROM (
    SELECT DISTINCT I.PARTENER, I.CodIntr,I1.ContDiscount
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
    ) GROUP BY PARTENER, CONTDISCOUNT;
  else
    INSERT INTO TMP_CMD_TMP1(COD1,VAL,TIP,COD2)
    SELECT PARTENER,COUNT(DISTINCT CodIntr),&apos;FACTART&apos;,CODOBIECT
    FROM (
    SELECT DISTINCT I.PARTENER,I.CODINTR,I1.CODOBIECT
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND I1.TIPLINIE = &apos;=&apos;
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
      AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
    UNION ALL
    SELECT I.PARTENER,I.CODINTR,I1.CODOBIECT
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
      INNER JOIN NPART P ON I.Partener = P.CodPart
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
    ) GROUP BY PARTENER,CODOBIECT;
    INSERT INTO TMP_CMD_TMP1(COD1,VAL,TIP,COD2)
    SELECT PARTENER,COUNT(DISTINCT CodIntr),&apos;-FACTART&apos;,CONTDISCOUNT
    FROM (
    SELECT DISTINCT I.PARTENER,I.CODINTR,I1.CONTDISCOUNT
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND I1.TIPLINIE = &apos;=&apos;
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
      AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
    UNION ALL
    SELECT DISTINCT I.PARTENER,I.CODINTR,I1.CONTDISCOUNT
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
      INNER JOIN NPART P ON I.Partener = P.CodPart
    WHERE I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
      AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
      AND aCodSubunit = Decode(aCodSubunit,1,1,I.Subunitatea)
    ) GROUP BY PARTENER,CONTDISCOUNT;
  end if;
END;

FUNCTION GetNrFact_Part(aCodPart IN NUMBER) RETURN NUMBER IS
aCodSubunit NUMBER(20);
aNr NUMBER(20) := 0;
BEGIN
  aCodSubunit := PKG_GLOBALS.GETSUBUNITATE;
  IF vAllIOArt then
    IF aCodSubunit = 1 then
      SELECT
        COUNT(DISTINCT I.CodIntr) INTO aNr
      FROM INTRARI I
           INNER JOIN NPART P ON I.Partener = P.CodPart
      WHERE P.CodPart = aCodPart
            AND I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1;
    ELSE
      SELECT
        COUNT(DISTINCT I.CodIntr) INTO aNr
      FROM INTRARI I
           INNER JOIN NPART P ON I.Partener = P.Codpart
      WHERE P.CodPart = aCodPart
            AND I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1;
    END IF;
  ELSE
    IF aCodSubunit = 1 then
      SELECT
        COUNT(DISTINCT CodIntr) INTO aNr
      FROM (
        SELECT I.CODINTR
        FROM INTRARI I
             INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
             INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
             INNER JOIN NPART P ON I.Partener = P.CodPart
        WHERE P.CodPart = aCodPart
              AND I.TipDoc &lt;&gt; 20
              AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
              AND NVL(I.Anulat, 0) = 0
              AND NVL(I.Initializari, 0) = 0
              AND I.Operat = 1 AND I1.TIPLINIE = &apos;=&apos;
              AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
        UNION ALL
        SELECT I.CODINTR
        FROM INTRARI I
             INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
             INNER JOIN NPART P ON I.Partener = P.CodPart
        WHERE P.CodPart = aCodPart
              AND I.TipDoc &lt;&gt; 20
              AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
              AND NVL(I.Anulat, 0) = 0
              AND NVL(I.Initializari, 0) = 0
              AND I.Operat = 1 AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
           );
    ELSE
      SELECT
        COUNT(DISTINCT CodIntr) INTO aNr
      FROM (
      SELECT I.CODINTR
      FROM INTRARI I
           INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
           INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
           INNER JOIN NPART P ON I.Partener = P.Codpart
      WHERE P.CodPart = aCodPart
            AND I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1 AND I1.TIPLINIE = &apos;=&apos;
            AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
      UNION ALL
      SELECT I.CODINTR
      FROM INTRARI I
           INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
           INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1
           INNER JOIN NPART P ON I.Partener = P.Codpart
      WHERE P.CodPart = aCodPart
            AND I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1 AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
      );
    END IF;
  END IF;
  RETURN aNr;
END;

procedure SetNrFact_Part IS
aCodSubunit NUMBER(20);
aNr NUMBER(20) := 0;
BEGIN
  aCodSubunit := PKG_GLOBALS.GETSUBUNITATE;
  IF vAllIOArt then
    IF aCodSubunit = 1 then
      insert into tmp_cmd_tmp(codobiect,resta,tip)
      SELECT
        P.CODPART,COUNT(DISTINCT I.CodIntr), &apos;FACTPART&apos;
      FROM INTRARI I
           INNER JOIN NPART P ON I.Partener = P.CodPart
      WHERE I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
      GROUP BY P.CODPART;
    ELSE
      insert into tmp_cmd_tmp(codobiect,resta,tip)
      SELECT
        P.CODPART,COUNT(DISTINCT I.CodIntr), &apos;FACTPART&apos;
      FROM INTRARI I
           INNER JOIN NPART P ON I.Partener = P.Codpart
      WHERE I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
      GROUP BY P.CODPART;
    END IF;
  ELSE
    IF aCodSubunit = 1 then
      insert into tmp_cmd_tmp(codobiect,resta,tip)
      SELECT
        CODPART,COUNT(DISTINCT CodIntr),&apos;FACTPART&apos;
      FROM (
        SELECT DISTINCT I.CODINTR, I.PARTENER CODPART
        FROM INTRARI I
             INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
             INNER JOIN NIR ON NIR.CODINTR = I.CODINTR
             INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1 AND NS.CODNIR = NIR.CODNIR
        WHERE I.TipDoc &lt;&gt; 20
              AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
              AND NVL(I.Anulat, 0) = 0
              AND NVL(I.Initializari, 0) = 0
              AND I.Operat = 1 AND I1.TIPLINIE = &apos;=&apos;
              AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
        UNION ALL
        SELECT DISTINCT I.CODINTR, I.PARTENER CODPART
        FROM INTRARI I
             INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
        WHERE I.TipDoc &lt;&gt; 20
              AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
              AND NVL(I.Anulat, 0) = 0
              AND NVL(I.Initializari, 0) = 0
              AND I.Operat = 1 AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
           ) GROUP BY CODPART;
    ELSE
      insert into tmp_cmd_tmp(codobiect,resta,tip)
      SELECT
        CODPART,COUNT(DISTINCT CodIntr),&apos;FACTPART&apos;
      FROM (
      SELECT DISTINCT I.CODINTR, I.PARTENER CODPART
      FROM INTRARI I
           INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
           INNER JOIN NIR ON NIR.CODINTR = I.CODINTR
           INNER JOIN NIRSTOC NS ON NS.CODINTR1 = I1.CODINTR1 AND NS.CODNIR = NIR.CODNIR
      WHERE I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1 AND I1.TIPLINIE = &apos;=&apos;
            AND EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = NS.CODIOART)
      UNION ALL
      SELECT DISTINCT I.CODINTR, I.PARTENER CODPART
      FROM INTRARI I
           INNER JOIN INTRARI1 I1 ON I.CodIntr = I1.CodIntr
      WHERE I.TipDoc &lt;&gt; 20
            AND I.DataDoc BETWEEN TO_DATE(vDataINI,&apos;DD.MM.YYYY&apos;) AND TO_DATE (vDataFIN,&apos;DD.MM.YYYY&apos;)
            AND I.Subunitatea = aCodSubunit
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1 AND I1.TIPLINIE &lt;&gt; &apos;=&apos;
      ) GROUP BY CODPART;
    END IF;
  END IF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(5000);
  sSelect    VARCHAR2(20000);
  vCondData  VARCHAR2(100);
  sCursRef   VARCHAR2(1000) := &apos;1&apos;;
  sMonSitV   VARCHAR2(1000) := pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  sBanSitV   VARCHAR2(1000) := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos; ,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  sMon       VARCHAR2(1000) := &apos;0&apos;;
BEGIN
  gSuplCols := &apos;NARTOBJ NAO, NMONEDE M, NCONT C, NUM NUM, NPART P, NPARTCODFISC CF, NAGENDA AG, NLOCALIT LOC, NJUDET JUD, NMONEDE MON, NART ART, NCLASEA CLSA, NCLASEP CLSP &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;&apos;, &apos;&apos;, &apos;&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vCondData := &apos;BETWEEN TO_DATE (&apos;&apos;&apos;||vDataINI||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE (&apos;&apos;&apos;||vDataFIN||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;

  IF sMonSitV IS NOT NULL AND sBanSitV IS NOT NULL AND InLei &lt;&gt; 1 THEN
    sCursRef := &apos;PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||sMonSitV||&apos;,&apos;||sBanSitV||&apos;, to_char(I.DataDoc, &apos;&apos;dd.mm.yyyy&apos;&apos;))&apos;;
    sMon     := sMonSitV;
  END IF;

  DELETE TMP_CMD_TMP;
  DELETE TMP_CMD_TMP1;
  DELETE TMP_LST_TOP;
  SetNrFact_Part;
  SetNrFact_Art;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    DenArt, DenUM, Cant, Pret, Valoare, ValCuTVA, Pret_Val, Valoare_Val, ValCuTVA_Val, Valuta, Furnizor,
    ValTot, ValTotCuTVA, ValTot_Val, ValTotCuTVA_Val, 
    NrFactPerArt,
    NrFactPerClient &apos;||gUserFields||&apos;)&apos;;

  sSelect :=&apos;
    INSERT INTO TMP_LST_TOP
    SELECT
      I.Partener CodPart,
      SUM( (CASE WHEN I1.TipLinie IN (&apos;&apos;G&apos;&apos;) THEN I1.RestFact ELSE I1.PU*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT) END - CASE WHEN I.TipDOC IN (3) THEN I1.Tva*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT)/I1.CANT ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END ) ValTot,
      SUM( (CASE WHEN I1.TipLinie IN (&apos;&apos;G&apos;&apos;) THEN I1.RestFact ELSE I1.PU*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT) END + CASE WHEN not I.TipDOC IN (3) THEN I1.Tva*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT)/I1.CANT ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END ) ValTotCuTVA,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (CASE WHEN I1.TipLinie IN (&apos;&apos;G&apos;&apos;) THEN I1.RestFact ELSE I1.PU*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT) END - CASE WHEN I.TipDOC IN (3) THEN I1.Tva*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT)/I1.CANT ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END /&apos;||sCursRef||&apos;)&apos; END||&apos; ValTot_Val,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (CASE WHEN I1.TipLinie IN (&apos;&apos;G&apos;&apos;) THEN I1.RestFact ELSE I1.PU*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT) END + CASE WHEN not I.TipDOC IN (3) THEN I1.Tva*COALESCE(sign(i1.cant)*lv1.cant,NS.CANTNIR,I1.CANT)/I1.CANT ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END /&apos;||sCursRef||&apos;)&apos; END||&apos; ValTotCuTVA_Val
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      INNER JOIN NPART P ON I.PARTENER = P.CODPART
      INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
      INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      LEFT JOIN DVI1 ON DVI1.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRLINK L ON L.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRARI1 AE1 ON AE1.CODINTR1 = L.CODLINIEAVIZ
      LEFT JOIN LIVR1 LV1 ON LV1.CODINTR1 = I1.CODINTR1
      LEFT JOIN NIRSTOC NS ON COALESCE(AE1.CODINTR1,I1.CODINTR1) = NS.CODINTR1 OR DVI1.CODDVI1 = NS.CODDVI1 OR LV1.CODNIRSTOC = NS.CODNIRSTOC
    WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
      AND I.TipDoc &lt;&gt; 2 AND NOT (I.TIPDOC &lt;&gt; 9 AND COALESCE(I.TIPFACTURA,0) = 9) AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND ((&apos;||GETALLIOART_N||&apos; = 1) OR (NS.CODNIRSTOC IS NULL) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART)))
      AND (&apos;||GETALLIOART_N||&apos; = 1 OR I1.TIPLINIE = &apos;&apos;=&apos;&apos;) 
      AND (pkg_list_base_topfurn.getallcls_n = 1 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;&apos;CODCLASEA&apos;&apos; AND TMP.VALOARE = A.CLASA))
      AND I.PARTENER &gt; 0 AND COALESCE(I1.CANT,0) &lt;&gt; 0
    GROUP BY I.Partener
  &apos;;
  
  LIST_EXECUTE_IMMEDIATE(sSelect, aListID, aListVer);
  
  sSelect :=&apos;
  SELECT
    NVL(NAO.Denumire,C.Den_Cont), NUM.Den_UM DenUM, V.Cant Cant, NVL(V.Val/V.Cant,0) Pret, 
    NVL(V.Val, 0) Valoare,
    NVL(V.ValCuTVA, 0) ValCuTVA, 
    NVL(V.Val_Val/V.Cant,0) Pret_Val, 
    NVL(V.Val_Val,0)  Valoare_Val, 
    NVL(V.ValCuTVA_Val,0)  ValCuTVA_Val,
    M.SIMBOL Valuta, 
    P.Den_Part,
    ValClient.ValTot,
    ValClient.ValTotCuTVA, 
    ValClient.ValTot_Val,
    ValClient.ValTotCuTVA_Val,
    CASE
      WHEN COALESCE(NAO.CodObiect, -1) = -1 THEN COALESCE(FPAC.VAL,0)
      ELSE COALESCE(FPA.VAL,0)
    end,
    COALESCE(FP.RESTA,0) &apos;||gUserAlias||&apos;
  FROM(
    SELECT
      I.Partener CodPart, I1.CodObiect, NULL CodCont, &apos;||sMon||&apos; Moneda, SUM(coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant)) Cant,
      SUM( (I1.PU*coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant) - CASE WHEN I.TipDOC IN (3) THEN coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant)/I1.CANT*I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END  ) Val,
      SUM( (I1.PU*coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant) + CASE WHEN not I.TipDOC IN (3) THEN coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant)/I1.CANT*I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END  ) ValCuTVA,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (I1.PU*coalesce(ns.Cantnir,i1.cant) - CASE WHEN I.TipDOC IN (3) THEN coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant)/I1.CANT*I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END  /&apos;||sCursRef||&apos;)&apos; END||&apos; Val_Val,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (I1.PU*coalesce(ns.Cantnir,i1.cant) + CASE WHEN not I.TipDOC IN (3) THEN coalesce(sign(i1.cant)*lv1.cant,ns.Cantnir,i1.cant)/I1.CANT*I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END  /&apos;||sCursRef||&apos;)&apos; END||&apos; ValCuTVA_Val
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      INNER JOIN NARTOBJ OBJ ON I1.Codobiect = OBJ.CodObiect
      INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
      INNER JOIN NPART P ON I.PARTENER = P.CODPART
      LEFT JOIN DVI1 ON DVI1.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRLINK L ON L.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRARI1 AE1 ON AE1.CODINTR1 = L.CODLINIEAVIZ
      LEFT JOIN LIVR1 LV1 ON LV1.CODINTR1 = I1.CODINTR1
      LEFT JOIN NIRSTOC NS ON COALESCE(AE1.CODINTR1,I1.CODINTR1) = NS.CODINTR1 OR DVI1.CODDVI1 = NS.CODDVI1 OR LV1.CODNIRSTOC = NS.CODNIRSTOC
    WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
      AND I.TipDoc &lt;&gt; 2 AND NOT (I.TIPDOC &lt;&gt; 9 AND COALESCE(I.TIPFACTURA,0) = 9) AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND (&apos;||GETALLIOART_N||&apos; = 1 OR I1.TIPLINIE = &apos;&apos;=&apos;&apos;) AND I1.TipLinie &lt;&gt; &apos;&apos;G&apos;&apos;
      AND ((&apos;||GETALLIOART_N||&apos; = 1) OR (NS.CODNIRSTOC IS NULL) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos; AND VALOARE = NS.CODIOART)))
      AND (&apos;||GETALLCLS_N||&apos; = 1 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;&apos;CODCLASEA&apos;&apos; AND TMP.VALOARE = A.CLASA))
      AND COALESCE(I1.CANT,0) &lt;&gt; 0
    GROUP BY I1.CODOBIECT, I.Partener, Sign(I1.Cant)
    UNION ALL
    SELECT I.Partener CodPart, null CodObiect, C.CodCont, &apos;||sMon||&apos; Moneda, SUM(I1.Cant) Cant,
      SUM( (I1.RestFact - CASE WHEN I.TipDOC IN (3) THEN I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END ) Val,
      SUM( (I1.RestFact + CASE WHEN not I.TipDOC IN (3) THEN I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END ) ValCuTVA,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (I1.RestFact - CASE WHEN I.TipDOC IN (3) THEN I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END /&apos;||sCursRef||&apos;)&apos; END||&apos; Val_Val,
      &apos;||CASE WHEN InLei = 1 THEN &apos;0&apos; ELSE &apos;SUM( (I1.RestFact + CASE WHEN not I.TipDOC IN (3) THEN I1.Tva ELSE 0 END ) * CASE WHEN Coalesce(I.CURS,0) = 0 THEN 1 ELSE I.CURS END /&apos;||sCursRef||&apos;)&apos; END||&apos; ValCuTVA_Val
    FROM INTRARI I
      INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      INNER JOIN NPART P ON I.PARTENER = P.CODPART
      INNER JOIN NCONT C ON I1.ContDiscount = C.CodCont
    WHERE I.DATADOC &apos;||vCondData|| PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;) ||&apos;
      AND I.TipDoc &lt;&gt; 2 AND NVL(I.Anulat, 0) = 0 AND NVL(I.Initializari, 0) = 0 AND I.Operat = 1
      AND (&apos;||GETALLIOART_N||&apos; = 1 OR I1.TIPLINIE = &apos;&apos;=&apos;&apos;) AND I1.TipLinie = &apos;&apos;G&apos;&apos; AND COALESCE(I1.CANT,0) &lt;&gt; 0
    GROUP BY C.CodCont, I.Partener, Sign(I1.Cant)
  ) V
    LEFT JOIN TMP_LST_TOP ValClient ON V.CodPart = ValClient.CodPart
    LEFT JOIN TMP_CMD_TMP FP ON FP.CODOBIECT = V.CODPART AND FP.TIP = &apos;&apos;FACTPART&apos;&apos;
    LEFT JOIN TMP_CMD_TMP1 FPA ON FPA.COD1 = V.CODPART AND FPA.COD2 = V.CODOBIECT AND FPA.TIP = &apos;&apos;FACTART&apos;&apos;
    LEFT JOIN NMONEDE M ON M.CODMONEDA = V.MONEDA
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = V.CODOBIECT
    LEFT JOIN NART ART ON NAO.CodArticol = ART.CodArticol
    LEFT JOIN NCLASEA CLSA ON ART.Clasa = CLSA.CodClaseA
    LEFT JOIN NUM ON ART.UM = NUM.CODUM
    LEFT JOIN NPART P ON V.CodPart = P.CodPart
    LEFT JOIN NPARTCODFISC CF ON P.CodPart = CF.CodPart AND CF.Principal = 1
    LEFT JOIN NCLASEP CLSP ON P.CodClasa = CLSP.CodClaseP
    LEFT JOIN NAGENDA AG ON AG.CodPart = V.CodPart AND AG.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(AG.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LOC ON AG.CodLocalit = LOC.CodLOcalit
    LEFT JOIN NJUDET JUD ON LOC.CodJudet = JUD.CodJudet
    LEFT JOIN NCONT C ON V.CodCont = C.CodCont
    LEFT JOIN TMP_CMD_TMP1 FPAC ON FPAC.COD1 = V.CODPART AND FPAC.COD2 = C.CODCONT AND FPA.TIP = &apos;&apos;-FACTART&apos;&apos;&apos;||
    gSuplJoins||&apos;
  WHERE V.CANT &lt;&gt; 0
  ORDER BY ValClient.ValTot DESC&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  
  DELETE TMP_CMD_TMP;
  DELETE TMP_CMD_TMP1;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_Base_topFurn; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TOPFURNANI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA3A7AF44C80C5A1A05F5CA340D59641D2937DDF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_topfurnani IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(5000);
  vLunaStart NUMBER(10);
  vLunaFin   NUMBER(10);
BEGIN
  gSuplCols := &apos;NPART P&apos;; 
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  vLunaStart := pkg_list_base_topcliani.LunaIni;
  vLunaFin   := pkg_list_base_topcliani.LunaFin;
  
  if pkg_list_base_topcliani.TotiPart then
    insert into tmp_manevra_liste (filtru, valoare)
    select &apos;CODPART&apos;, codpart from npart where codpart &gt; 0;
  end if;

  delete from tmp_toppeani;
  if pkg_globals.GETSUBUNITATE &gt; 1 then
    insert into tmp_toppeani (an, val, codpart)
    select to_number(mana.valoare),
             G.ValTot_Val,
             to_number(manp.valoare)
      from tmp_manevra_liste mana,
           tmp_manevra_liste manp,
      (
       SELECT SUM(S.ValTot_Val) ValTot_Val, S.An, S.Partener
          FROM
          (
          SELECT
              SUM(I.ValDoc) ValTot_Val,
              I.An,
              I.Partener
            FROM INTRARI I
            WHERE I.Subunitatea = pkg_globals.GETSUBUNITATE
            AND I.TipDoc  NOT IN (2, 3)
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Operat = 1
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            GROUP BY I.An, I.Partener
            UNION ALL
            SELECT
              SUM(I.ValDoc) ValTot_Val,
              I.An,
              I.Partener
            FROM INTRARI I
            WHERE I.Subunitatea = pkg_globals.GETSUBUNITATE
            AND I.TipDoc = 3
            AND NVL(I.Anulat, 0) = 0
            AND NVL(I.Initializari, 0) = 0
            AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
            AND I.Operat = 1
            GROUP BY I.An, I.Partener
           ) S
           GROUP BY S.An, S.Partener
             ) G
      where mana.filtru = &apos;AN&apos; and manp.filtru = &apos;CODPART&apos;
            AND G.An = to_number(mana.valoare) AND G.Partener = to_number(manp.valoare);
  else
    insert into tmp_toppeani (an, val, codpart)
    select to_number(mana.valoare),
           G.ValTot_Val,
           to_number(manp.valoare)
    from tmp_manevra_liste mana,
         tmp_manevra_liste manp,
    (
     SELECT SUM(S.ValTot_Val) ValTot_Val, S.An, S.Partener
        FROM
        (
        SELECT
            SUM(I.ValDoc) ValTot_Val,
            I.An,
            I.Partener
          FROM INTRARI I
          WHERE I.TipDoc  NOT IN (2, 3)
          AND NVL(I.Anulat, 0) = 0
          AND NVL(I.Initializari, 0) = 0
          AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
          AND I.Operat = 1
          GROUP BY I.An, I.Partener
          UNION ALL
          SELECT
            SUM(I.ValDoc) ValTot_Val,
            I.An,
            I.Partener
          FROM INTRARI I
          WHERE I.TipDoc = 3
          AND NVL(I.Anulat, 0) = 0
          AND NVL(I.Initializari, 0) = 0
          AND I.Luna &gt;= vLunaStart AND I.Luna &lt;= vLunaFin
          AND I.Operat = 1
          GROUP BY I.An, I.Partener
         ) S
         GROUP BY S.An, S.Partener
           ) G
    where mana.filtru = &apos;AN&apos; and manp.filtru = &apos;CODPART&apos;
          AND G.An = to_number(mana.valoare) AND G.Partener = to_number(manp.valoare);
  end if;

  sInsert := &apos; insert into &apos;||tmpName||&apos; (CodPart, Den_Part&apos;||gUserFields||&apos;) &apos;||
             &apos; select to_number(man.valoare), p.den_part &apos;||gUserAlias||
             &apos; from tmp_manevra_liste man &apos;||
             &apos;      inner join npart p on to_number(man.valoare) = p.codpart &apos;||gSuplJoins||
             &apos; where man.filtru = &apos;&apos;CODPART&apos;&apos; &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);           

  for v_rec in (select an, nvl(val,0) val, codpart from tmp_toppeani) loop
    sInsert := &apos; update &apos;||tmpName||
               &apos; set &apos;||
               &apos;   AN&apos;||v_rec.an||&apos; = &apos;||replace(to_char(v_Rec.Val), &apos;,&apos;, &apos;.&apos;)||
               &apos; where CodPart = &apos;||v_Rec.Codpart;
    LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  end loop;

  sInsert := &apos;begin &apos;||chr(13)||
             &apos;  for v_rec in (select tmp.codpart, tp.val &apos;||chr(13)||
             &apos;                from &apos;||tmpName||&apos; tmp &apos;||chr(13)||
             &apos;                     left join (select sum(val) val, codpart from tmp_toppeani group by codpart) tp on tp.codpart = tmp.codpart &apos;||chr(13)||
             &apos;               ) loop &apos;||chr(13)||
             &apos;    if nvl(v_rec.val,0) = 0 then &apos;||chr(13)||
             &apos;      delete &apos;||tmpName||&apos; where CodPart = v_rec.CodPart; &apos;||chr(13)||
             &apos;    end if; &apos;||chr(13)||
             &apos;  end loop;             &apos;||chr(13)||
             &apos;end;&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);           
  DELETE FROM tmp_toppeani;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_topfurnani;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRADUCERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F47B491B0D0DD92E6096773650721985B7743083</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_traduceri IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SetParams IS
BEGIN
  NULL;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(4096);
BEGIN
  gSuplCols := &apos;NARTOBJTRAD OT, NARTOBJ O, NLIMBA L&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  sInsert :=
  &apos;INSERT INTO &apos; || tmpName || &apos; (Denumire, DenumireTrad, Limba, CodObiect, CodLimba &apos;||gUserFields||&apos;)
	SELECT O.Denumire, OT.DenumireTrad, L.DenLimba, OT.CodObiect, OT.CodLimba &apos;||gUserAlias||&apos;
  FROM NARTOBJTRAD OT
    INNER JOIN NARTOBJ O ON O.CodObiect = OT.CodObiect
    INNER JOIN NLIMBA L ON L.CodLimba = OT.CodLimba&apos;||
    gSuplJoins;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);  
  COMMIT;
END;

end PKG_LIST_BASE_TRADUCERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRANSFDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C543F563AA6C89E2847A1BD146F506851A9D4A8B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRANSFDOC IS

  vCodDoc     TRANSF.CODTRANSF%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDoc  IN NUMBER)  IS
BEGIN
  vCodDoc := pCodDoc;
END;

FUNCTION GETVALTVA(aCodTransf IN NUMBER) RETURN NUMBER IS
aVal NUMBER(20,7);
BEGIN
  aVal := 0;
  WITH T1 AS (
    SELECT
      t.an, t.luna,
      case when nvl(l1.codnirstoc, 0) &lt;&gt; 0 then ns_s.codioart else lv.codioart end codioarts,
      na.codarticol,
      case when nvl(l1.codnirstoc, 0) &lt;&gt; 0 then ns_s.pret else lv.pretinreg end pinregs,
      t1.umsec, l1.cant
    FROM transf t
      INNER JOIN transf1 t1   ON t1.codtransf    = t.codtransf
      INNER JOIN livr    l    ON l.codtransf     = t.codtransf
      INNER JOIN livr1   l1   ON l1.codlivr      = l.codlivr AND l1.codies1 = t1.codtransf1
      INNER JOIN nartobj nobj ON nobj.codobiect  = t1.codobiect
      INNER JOIN nart    na   ON na.codarticol   = nobj.codarticol
      LEFT  JOIN nirstoc ns_s ON ns_s.codnirstoc = l1.codnirstoc
      LEFT  JOIN nir     n_s  ON n_s.codnir      = ns_s.codnir
      LEFT  JOIN livrval lv   ON l1.codlivr1     = lv.codlivr1
    WHERE L.CODTRANSF = aCodTransf
  )
  SELECT
    sum(
      case
        when nvl(io1s.aretvaneex, 0) in (0, 2) then t1.cant * t1.pinregs * (100 + tva1.procent) / 100 / nvl(um.paritate, 1)
        else t1.cant * t1.pinregs / nvl(um.paritate, 1)
      end) into aVal
  FROM t1
    LEFT JOIN num1           um   on um.codum1      = t1.umsec
    LEFT JOIN tmp_ioart_luna io1s ON io1s.codioart  = t1.codioarts
    LEFT JOIN ncont          ncs  ON ncs.codcont    = io1s.cont
    LEFT JOIN nart1          na1  ON na1.codarticol = t1.codarticol AND (t1.an*12+t1.luna) between  na1.alstart and  na1.alstop
    LEFT JOIN ntva1          tva1 ON tva1.codtva    = na1.codtva    AND (t1.an*12+t1.luna) between tva1.alstart and tva1.alstop
  ;

  RETURN aVal;
END;

PROCEDURE PROCESSPARAMS(vCodTransf IN NUMBER) IS
  mModificaridepret NUMBER(2) := 13;
  vValCuTva         NUMBER    := PKG_LIST_BASE_TRANSFDOC.GETVALTVA(vCodTransf);
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      T.TIPDOC, T.SERIADOC, T.NRDOC, T.DATADOC, T.VALDOC, T.NRAE, T.OBS,
      CG.Den_Gest CMDGest, CS.TELEFON CMDTelefon, CL.DEN_LOCALIT CMDLocalit, CJ.Den_Judet CMDJudet,
      GetAdresa(CS.sector, CS.strada, CS.nr1, CS.nr2, CS.bloc, CS.scara, CS.etaj, CS.apart, CS.codpostal) CMDAdresa,
      CASE WHEN T.STORNO = 1 AND T.TipDoc &lt;&gt; mModificaridepret THEN &apos;DA&apos; ELSE &apos;NU&apos; END STORNO,
      CASE WHEN T.TipDoc = mModificaridepret THEN &apos;Proces verbal de modificare de pret&apos; ELSE &apos;Nota de transfer&apos; END TipTransf,
      Decode(TIPMODIFPRET,
        0, &apos;PU inreg. nou  fara reevaluare PU achizitie&apos;,
        1, &apos;PU inreg. nou  + reevaluare PU achizitie astfel incat Adaos=0&apos;,
        2, &apos;PU inreg. nou  + reevaluare PU achizitie numai daca Adaos &lt; 0&apos;,
        3, &apos;PU achizitie nou fara afectarea PU inregistrare&apos;,
        NULL
      ) TIPMODIFPRET,
      Nvl(U.Nume,&apos;...nedefinit...&apos;) UNume, Nvl(U.Prenume,&apos;...nedefinit...&apos;) UPrenume, Nvl(U.CNP,&apos;...nedefinit...&apos;) UCNP, U.BISERIA||&apos; &apos;||U.BINR UBI,
      D.Delegat DEL, D.DOC DELDOC, D.NRDOC DELNRDOC, D.SERIEDOC DELSERIEDOC, D.ELIBERAT DELELIBERAT, D.CNP DELCNP, D.DATADOC DELDATADOC,
      T.MIJLTRANSP DELMIJLTRANSP, T.NRTRANSP DELNRTRANSP, ETRANS.UIT
    FROM TRANSF T
      LEFT JOIN NPARTTR D ON T.DELEGAT = D.CODPARTTR
      LEFT JOIN NGEST CG ON CG.CODGEST = T.CODGESTCMD
      LEFT JOIN NAGENDA CS ON CS.CODGEST = CG.CODGEST
      LEFT JOIN NLOCALIT CL ON CL.CODLOCALIT = NVL(CS.CODLOCALIT, 0)
      LEFT JOIN NJUDET CJ ON CJ.CODJUDET = NVL(CL.CODJUDET, 0)
      LEFT JOIN NPERS U ON U.LOGONNAME = T.USERID
      LEFT JOIN STATUSDECL ETRANS ON ETRANS.CODDOC = T.CODTRANSF AND ETRANS.TIPDOC = 100 + T.TIPDOC
    WHERE T.CODTRANSF = vCodTransf
  ) LOOP

    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT SERIE&apos;,               v_rec.SERIADOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT NUMAR&apos;,               v_rec.NRDOC);
    pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT DATA&apos;,                To_Char(v_rec.DataDoc,&apos;dd.mm.yyyy&apos;));
    if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT TOTAL&apos;,               TO_CHAR(v_rec.ValDoc,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;DOCUMENT TOTAL&apos;,               &apos;***&apos;);
    end if;  
    pkg_list_Struct.ADAUGA_PARAM(&apos;AVIZ NUMAR&apos;,                   v_rec.NRAE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;OBSERVATIE&apos;,                   v_rec.OBS);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE&apos;,             v_rec.CMDGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE JUDET&apos;,       v_rec.CMDJudet);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE LOCALITATE&apos;,  v_rec.CMDLocalit);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE ADRESA&apos;,      v_rec.CMDAdresa);
    pkg_list_Struct.ADAUGA_PARAM(&apos;COMANDA GESTIUNE TELEFON&apos;,     v_rec.CMDTelefon);

    IF v_rec.TipDoc = mModificaridepret THEN
      pkg_list_Struct.ADAUGA_PARAM(&apos;TIP MODIFICARE PRET&apos;,        v_rec.TIPMODIFPRET);
    ELSE
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DELEGAT&apos;,          v_rec.DEL);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT CNP DELEGAT&apos;,      v_rec.DELCNP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOCUMENT&apos;,         v_rec.DELDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR. DOCUMENT&apos;,     v_rec.DELNRDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT SERIE DOCUMENT&apos;,   v_rec.DELSERIEDOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DOC ELIBERAT&apos;,     v_rec.DELELIBERAT);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT DATA ELIBERARE&apos;,   v_rec.DELDATADOC);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT TIP&apos;,              v_rec.DELMIJLTRANSP);
      pkg_list_Struct.ADAUGA_PARAM(&apos;TRANSPORT NR MIJLOC&apos;,        v_rec.DELNRTRANSP);
    END IF;
    pkg_list_Struct.ADAUGA_PARAM(&apos;TIP DOC&apos;,                      v_rec.TipTransf);
    pkg_list_Struct.ADAUGA_PARAM(&apos;STORNO&apos;,                       v_rec.STORNO);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit nume &apos;,               v_rec.UNUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit prenume&apos;,             v_rec.UPRENUME);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit CNP&apos;,                 v_rec.UCNP);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Intocmit BI&apos;,                  v_rec.UBI);
    pkg_list_Struct.ADAUGA_PARAM(&apos;UIT&apos;,                       v_rec.UIT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;FILTRU&apos;,                       &apos;&apos;);
    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT
      SUM(L1.CANT * NVL(NS.PRET,0)) ValLivr,
      SUM(L1.CANT * Nvl(O.VOLUM,0)) Volum,
      SUM(L1.CANT * Nvl(O.MASA,0)) Masa,
      Sum(L1.CANT * Nvl(CASE WHEN LV.CODLIVR1 IS NULL THEN NS.PRET ELSE LV.PRETINREG END,0)) valinreg,
      Sum(L1.CANT * Nvl(CASE WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) ELSE LV.PRETACHIZ END,0)) valachiz,
      Sum(L1.CANT * Nvl(NS.PUMAXIMAL,0)) valmax,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (NG.DEN_GEST ORDER BY NG.DEN_GEST) AS vc2_nt)) DGest,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (NUMEPRENUME_OBJ(PG.NUME,PG.Prenume).VC2 ORDER BY PG.NUME, PG.PRENUME) AS vc2_nt)) GGest,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (L.NRLIVR||&apos;/&apos;||TO_CHAR(L.DATALIVR,&apos;DD.MM.YYYY&apos;) ORDER BY L.NRLIVR) AS vc2_nt)) LLIVR
    FROM LIVR L
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      LEFT  JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT  JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
      LEFT  JOIN NARTOBJ O ON O.CODOBIECt = COALESCE(LV.CODOBIECT, NS.CODOBIECT,0)
      LEFT  JOIN NIR N  ON N.CODNIR = NS.CODNIR
      LEFT  JOIN NGEST NG ON NG.CODGEST = NVL(N.GEST, LV.GEST)
      LEFT  JOIN NPERS PG ON PG.CODPERS = NG.CODGESTIONAR
    WHERE L.CODTRANSF = vCodTransf
  ) LOOP
    if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LIVRARI&apos;,                TO_CHAR(v_rec.ValLivr  ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;TOTAL LIVRARI&apos;,                &apos;***&apos;);
    end if;  
    pkg_list_Struct.ADAUGA_PARAM(&apos;VOLUM TOTAL&apos;,                  TO_CHAR(v_rec.Volum    ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;MASA TOTALA&apos;,                  TO_CHAR(v_rec.Masa     ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;LIVRARI&apos;, v_rec.LLIVR);
    if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE ACHIZITIE&apos;,            TO_CHAR(v_rec.valachiz ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET MAXIMAL SURSA&apos;,TO_CHAR(v_rec.valmax   ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG SURSA&apos;,  TO_CHAR(v_rec.valinreg ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE ACHIZITIE&apos;,            &apos;***&apos;);
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET MAXIMAL SURSA&apos;,&apos;***&apos;);
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG SURSA&apos;,  &apos;***&apos;);
    end if;  

    pkg_list_Struct.ADAUGA_PARAM(&apos;GEST. LIVRARE&apos;,                v_rec.DGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GEST. LIVRARE GESTIONAR&apos;,      v_rec.GGest);

    EXIT;
  END LOOP;

  FOR v_rec IN (
    SELECT SUM(NS.CANTNIR  * NS.PRET) valinreg
    FROM TRANSF1 T1
      LEFT JOIN NIRSTOC NS ON NS.CODTRANSF1 = T1.CODTRANSF1
    WHERE T1.CODTRANSF  = vCodTransf
  ) LOOP
    if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG DESTINATIE&apos;,  TO_CHAR(v_rec.valinreg ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    else
      pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG DESTINATIE&apos;,  &apos;***&apos;);
    end if;  
    EXIT;
  END LOOP;
  if AccesGranted(pkg_globals.GETUSERID,&apos;BLIND&apos;) &gt; 0 then
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG CU TVA SURSA&apos;,  TO_CHAR(vValCuTva      ,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
  else
    pkg_list_Struct.ADAUGA_PARAM(&apos;VALOARE LA PRET INREG CU TVA SURSA&apos;,  &apos;***&apos;);
  end if;  

  FOR v_rec IN (
    SELECT
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (NG.DEN_GEST ORDER BY NG.DEN_GEST) AS vc2_nt)) DGest,
      VC2_NT_TO_VC3200_DIST(CAST(COLLECT (NUMEPRENUME_OBJ(PG.NUME,PG.Prenume).VC2 ORDER BY PG.NUME, PG.PRENUME) AS vc2_nt)) GGest
    FROM TRANSF T
      lefT JOIN NIR N ON N.CODTRANSF = T.CODTRANSF
      LEFT JOIN NGEST NG ON NG.CODGEST = N.GEST
      LEFT JOIN NPERS PG ON PG.CODPERS = NG.CODGESTIONAR
    WHERE T.CODTRANSF = VCodTransf
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;GEST. RECEPTIE&apos;,                v_rec.DGest);
    pkg_list_Struct.ADAUGA_PARAM(&apos;GEST. RECEPTIE GESTIONAR&apos;,      v_rec.GGest);
    EXIT;
  END LOOP;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelectOK  VARCHAR2(30000);
  sSelectNOK VARCHAR2(30000);
  sInsertUMA VARCHAR2(5000);
  sSelectUMA VARCHAR2(5000);
  sJoinUMA   VARCHAR2(5000);
  vOK        INTEGER;
BEGIN
  gSuplCols := &apos;TRANSF T, TRANSF1 T1, NARTOBJ NAO, PRETM PRETM, NART NA, NUM1 UM, NUM UM1, NUM UM2, NCLASEA NCA, NPART PROD, PRETM PM, NCONT CS, NCONT CD, IOART IOAS, IOART IOAd&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;OPER&apos;, &apos;OPER.LOGONNAME = T.USERID&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PKG_LIST_BASE_UTILS.make_config_luna_ioart;

  SELECT CASE WHEN OPERAT = 1 AND ANULAT = 0 THEN 1 ELSE 0 END INTO vOK FROM TRANSF WHERE CODTRANSF = vCodDoc;

  IF vOk = 1
  THEN PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;tg.cant&apos;,&apos;t1.codobiect&apos;,sInsertUMA,sSelectUMA,sJoinUMA);
  ELSE PKG_LIST_BASE_UTILS.UMA_UTILS(&apos;t1.cant&apos;,&apos;t1.codobiect&apos;,sInsertUMA,sSelectUMA,sJoinUMA);
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    Document,PrefixDoc,Nrdoc,DataDoc,ART,
    Cant,CantUM1,CantUM2,CantUM1D,CantUM2D,UM,UMALT1,UMALT2,
    ClasaA,PUAchiz_S,PUAchiz_D,PUInreg_S,PUInreg_D,
    PretMax_S,PretMax_D,
    VALACH_S,VALACH_D,VALINREG_S,VALINREG_D,
    Operat, TIPSERIE,
    SERII,DATAEXP,SERIEDATA,SER,SERTG,SERCANT,
    PROCTVA, PRODUCATOR, PUInregTVA_S, CONT_S, CONT_D, NrUnic,
    COMP_ART, COMP_UM, COMP_CANT, COMP_PRET, TIPRETETA, GESTSURSA, GESTDEST &apos;||sInsertUMA||gUserFields||&apos;) &apos;;

  sSelectOK := &apos;
  WITH
    tg AS (
      SELECT
        DECODE(t.tipdoc,12,&apos;&apos;Transf. &apos;&apos;,13,&apos;&apos;Modif. pret &apos;&apos;)||t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc document,
        t.codtransf, t.prefixdoc,t.nrdoc,t.datadoc,decode(t.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat, t.codpart, t.an, t.luna,
        t1.codtransf1, t1.indexlocal, t1.codobiect, t1.umsec, t1.codcont, MAX(ns_d.tipserie) tipserie, SUM(ns_d.cantnir) cant,
        SUM(NVL(l1.cantum1,0)) cantum1s, SUM(NVL(l1.cantum2,0)) cantum2s, SUM(NVL(ns_d.cantum1,0)) cantum1d, SUM(NVL(ns_d.cantum2,0)) cantum2d,
        MAX(NVL(ns_s.pumaximal,0)) pumaximals, MAX(NVL(ns_d.pumaximal,0)) pumaximald,
        SUM(NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir) vis, SUM(NVL(lv.pretachiz, ns_s.pret - ns_s.adaos)*ns_d.cantnir) vas,
        SUM(ns_d.pret*ns_d.cantnir) vid, SUM((ns_d.pret - ns_d.adaos)*ns_d.cantnir) vad,
        SUM(DECODE( nvl(io1s.aretvaneex, 0), 0, NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir, 0)) vpinrtvas_ftva,
        SUM(DECODE( nvl(io1s.aretvaneex, 0), 0, 0, NVL(lv.pretinreg,ns_s.pret)*ns_d.cantnir)) vpinrtvas_ctva,
        NVL(lv.codioart,ns_s.codioart) conts, ns_d.codioart contd, Nvl(n_s.gest,0) gest, Nvl(n_d.gest,0) gestdest
      FROM transf t
        INNER JOIN transf1        t1   ON t1.codtransf    = t.codtransf
        INNER JOIN livr           l    ON l.codtransf     = t.codtransf
        INNER JOIN livr1          l1   ON l1.codlivr      = l.codlivr AND l1.codies1 = t1.codtransf1
        INNER JOIN nartobj        nobj ON nobj.codobiect  = t1.codobiect
        INNER JOIN nirstoc        ns_d ON ns_d.codlivr1   = l1.codlivr1
        INNER JOIN nir            n_d  ON n_d.codnir      = ns_d.codnir
        LEFT  JOIN nirstoc        ns_s ON ns_s.codnirstoc = l1.codnirstoc
        LEFT  JOIN nir            n_s  ON n_s.codnir      = ns_s.codnir
        LEFT  JOIN livrval        lv   on lv.codlivr1     = l1.codlivr1
        LEFT  JOIN tmp_ioart_luna io1s ON io1s.codioart   = NVL(lv.codioart,ns_s.codioart)
      WHERE L.CODTRANSF = &apos;||vCodDoc||&apos;
      GROUP BY
        t.codtransf, t.tipdoc, t.prefixdoc, t.nrdoc, t.datadoc, t.codpart, t.operat, t.an, t.luna,
        t1.codtransf1, t1.indexlocal, t1.codobiect, t1.umsec, t1.codcont,
        NVL(lv.codioart,ns_s.codioart), ns_d.codioart, Nvl(n_s.gest,0), Nvl(n_d.gest,0)
    ),
    ser AS (
      SELECT
        codtransf1, conts, contd, gest,
        vc2_nt_to_vc3200(CAST(COLLECT(serie) AS vc2_nt)) serii,
        vc2_nt_to_vc3200(CAST(collect(DISTINCT sertg) AS vc2_nt)) tg,
        vc2_nt_to_vc3200(CAST(COLLECT(serie||&apos;&apos; - &apos;&apos;||sertg) AS vc2_nt)) seriedata,
        vc2_nt_to_vc3200(CAST(COLLECT(ser ORDER BY ser) AS vc2_nt)) ser,
        vc2_nt_to_vc3200(CAST(COLLECT(sertg ORDER BY ser) AS vc2_nt) ) sertg,
        vc2_nt_to_vc3200(CAST(COLLECT(sercant ORDER BY ser) AS vc2_nt)) sercant
      FROM (
        SELECT
          t1.codtransf1, ns_s.codioart conts, ns_d.codioart contd, Nvl(n_s.gest,0) gest,
          S.SERIE||CASE WHEN SUM(L1.CANT) &lt;&gt; 1 THEN &apos;&apos; ( &apos;&apos;||SUM(L1.CANT)||&apos;&apos; )&apos;&apos; END SERIE,
          S.SERIE SER, TO_CHAR(SUM(L1.CANT)) SERCANT, TO_CHAR(NVL(nser.tg, ns_s.tg), &apos;&apos;DD.MM.YYYY&apos;&apos;) SERTG
        FROM transf t
          INNER JOIN transf1 t1   ON t1.codtransf    = t.codtransf
          INNER JOIN livr    l    ON l.codtransf     = t.codtransf
          INNER JOIN livr1   l1   ON l1.codlivr      = l.codlivr AND l1.codies1 = t1.codtransf1
          INNER JOIN nirser  nser ON nser.codnirser  = l1.codnirser
          INNER JOIN nserii  s    ON s.codserie      = nser.codserie
          INNER JOIN nirstoc ns_d ON ns_d.codlivr1   = l1.codlivr1
          INNER JOIN nir     n_d  ON n_d.codnir      = ns_d.codnir
          INNER JOIN nirstoc ns_s ON ns_s.codnirstoc = l1.codnirstoc
          INNER JOIN nir     n_s  ON n_s.codnir      = ns_s.codnir
      WHERE L.CODTRANSF = &apos;||vCodDoc||&apos;
      GROUP BY t1.codtransf1, ns_s.codioart, ns_d.codioart, Nvl(n_s.gest,0), s.serie, Nvl(nser.tg,ns_s.tg)
    )
    GROUP BY codtransf1, conts, contd, gest
  )
  SELECT
    tg.document, tg.prefixdoc, tg.nrdoc, tg.datadoc, nao.denumire ,
    tg.cant/um.paritate, tg.cantum1s, tg.cantum2s, tg.cantum1d, tg.cantum2d, um.den_um1, um1.den_um, um2.den_um,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), DECODE(tg.cant,0,0,tg.vas*um.paritate/tg.cant), DECODE(tg.cant,0,0,tg.vad*um.paritate/tg.cant), DECODE(tg.cant,0,0,tg.vis*um.paritate/tg.cant), DECODE(tg.cant,0,0,tg.vid*um.paritate/tg.cant),
    CASE
      WHEN NVL(nao1.tippretmax,0) IN (1,2,3) AND COALESCE(tg.pumaximals,t1.pumaximal, 0) &gt; 0 THEN NVL(tg.pumaximals,t1.pumaximal)
      WHEN NVL(nao1.tippretmax,0) IN (4,5,6) AND NVL(nao1.pretmaximal,0) &gt; 0                 THEN nao1.pretmaximal
      ELSE 0
    END*um.paritate,
    CASE
      WHEN NVL(nao1.tippretmax,0) IN (1,2,3) AND COALESCE(tg.pumaximald,t1.pumaximal, 0) &gt; 0 THEN NVL(tg.pumaximald,t1.pumaximal)
      WHEN NVL(nao1.tippretmax,0) IN (4,5,6) AND NVL(nao1.pretmaximal,0) &gt; 0                 THEN nao1.pretmaximal
      ELSE 0
    END*um.paritate,
    tg.vas, tg.vad, tg.vis, tg.vid,
    tg.operat, decode(tg.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;),
    NVL(ser.serii,&apos;&apos;-&apos;&apos;), NVL(ser.tg,&apos;&apos;-&apos;&apos;),  NVL(ser.seriedata,&apos;&apos;-&apos;&apos;),  NVL(ser.ser,&apos;&apos;-&apos;&apos;),  NVL(ser.sertg,&apos;&apos;-&apos;&apos;),  NVL(ser.sercant,&apos;&apos;-&apos;&apos;),
    tva1.procent, prod.den_part, DECODE(tg.cant,0,0,(vpinrtvas_ctva + vpinrtvas_ftva *  (100 + tva1.procent) / 100)*um.paritate/tg.cant), cs.simbol, cd.simbol, rownum,
    objmat.denumire, ummat.den_um, mat.cant*tg.cant, mat.pret, DECODE(ret.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,&apos;&apos;Dezagregare&apos;&apos;),n_gs.den_gest, n_gd.den_gest &apos;||sSelectUMA||gUserAlias||&apos;
  FROM tg
    LEFT JOIN transf         t      ON t.codtransf   = tg.codtransf
    LEFT JOIN transf1        t1     ON t1.codtransf1 = tg.codtransf1
    LEFT JOIN nartobj        nao    ON nao.codobiect = tg.codobiect
    LEFT JOIN nart           na     ON na.codarticol = nao.codarticol
    LEFT JOIN num1           um     on um.codum1 = tg.umsec
    LEFT JOIN num            um1    on um1.codum = na.um1
    LEFT JOIN num            um2    on um2.codum = na.um2
    LEFT JOIN nclasea        nca    ON nca.codclasea  = na.clasa
    LEFT JOIN nart1          na1    ON na1.codarticol = nao.codarticol AND (tg.an*12+tg.luna) between  na1.alstart and  na1.alstop
    LEFT JOIN ntva1          tva1   ON tva1.codtva    = na1.codtva     AND (tg.an*12+tg.luna) between tva1.alstart and tva1.alstop
    LEFT JOIN nartobj1       nao1   ON nao1.codobiect = tg.codobiect   AND (tg.an*12+tg.luna) between nao1.alstart and nao1.alstop
    LEFT JOIN npart          prod   ON prod.codpart   = nao.codproducator
    LEFT JOIN pretm          pm     ON pm.codobiect   = tg.codobiect   AND pm.subunitatea = t.subunitatea AND pm.implicit = 1
    LEFT JOIN tmp_ioart_luna io1s   ON io1s.codioart  = tg.conts
    LEFT JOIN IOART          IOAS   ON IOAS.CODIOART  = IO1S.CODIOART
    LEFT JOIN ncont          cs     ON cs.codcont     = io1s.cont
    LEFT JOIN tmp_ioart_luna io1d   ON io1d.codioart  = tg.contd
    LEFT JOIN IOART          IOAD   ON IOAD.CODIOART  = IO1D.CODIOART
    LEFT JOIN ncont          cd     ON cd.codcont     = io1d.cont
    LEFT JOIN prodcomp       ret    ON ret.codprodcomp   = t1.codreteta
    LEFT JOIN prodmat        mat    ON mat.codprodcomp   = t1.codreteta
    LEFT JOIN nartobj        objmat ON objmat.codobiect  = mat.codobiect
    LEFT JOIN nart           artmat ON objmat.codarticol = artmat.codarticol
    LEFT JOIN num            ummat  ON artmat.um    = ummat.codum
    LEFT JOIN ngest          n_gs   ON n_gs.codgest = tg.gest
    LEFT JOIN ngest          n_gd   ON n_gd.codgest = tg.gestdest
    LEFT JOIN ser                   ON ser.codtransf1  = tg.codtransf1 AND ser.conts = tg.conts AND ser.contd = tg.contd AND ser.gest = tg.gest
    LEFT JOIN PRETM          PRETM  ON PRETM.CODOBIECT = NAO.CODOBIECT AND PRETM.IMPLICIT = 1  and PRETM.SUBUNITATEA = T.SUBUNITATEA&apos;||
    sJoinUMA||
    gSuplJoins||&apos;
  ORDER BY tg.indexlocal &apos;;

  sSelectNOK := &apos;
  SELECT
    DECODE(t.tipdoc,12,&apos;&apos;Transf. &apos;&apos;,13,&apos;&apos;Modif. pret &apos;&apos;)||t.prefixdoc||t.nrdoc||&apos;&apos; / &apos;&apos;||t.datadoc document,
    t.prefixdoc, t.nrdoc, t.datadoc, nao.denumire,
    t1.cant/um.paritate, NULL CantUM1, NULL CantUM2, NULL CantUM1D, NULL CantUM2D, um.den_um1, um1.den_um, um2.den_um,
    nvl(nca.den_clasea,&apos;&apos;-&apos;&apos;), t1.pu * um.paritate, t1.pu * um.paritate, t1.pu * um.paritate, t1.pu * um.paritate,
    CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) AND NVL(t1.pumaximal, 0) &gt; 0 THEN t1.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) AND NVL(nao1.pretmaximal,0) &gt; 0 THEN nao1.pretmaximal ELSE 0 END * um.paritate,
    CASE WHEN NVL(nao1.tippretmax,0) IN (1,2,3) AND NVL(t1.pumaximal, 0) &gt; 0 THEN t1.pumaximal WHEN NVL(nao1.tippretmax,0) IN (4,5,6) AND NVL(nao1.pretmaximal,0) &gt; 0 THEN nao1.pretmaximal ELSE 0 END * um.paritate,
    t1.pu * t1.cant, t1.pu * t1.cant, t1.pu * t1.cant, t1.pu * t1.cant,
    decode(t.operat,0,&apos;&apos;Nu&apos;&apos;,&apos;&apos;Da&apos;&apos;) operat, decode(na.tipserie,0,&apos;&apos;fara serie&apos;&apos;,1,&apos;&apos;serie pe bucata&apos;&apos;,2,&apos;&apos;serie pe lot&apos;&apos;),
    &apos;&apos;-&apos;&apos; SERII, &apos;&apos;-&apos;&apos; DATAEXP, &apos;&apos;-&apos;&apos; SERIEDATA, &apos;&apos;-&apos;&apos; SER, &apos;&apos;-&apos;&apos; SERTG, &apos;&apos;-&apos;&apos; SERCANT,
    tva1.procent, prod.den_part, 0, cs.simbol, cd.simbol, rownum,
    objmat.denumire, ummat.den_um, mat.cant*t1.cant, mat.pret, DECODE(ret.tipreteta,1,&apos;&apos;Agregare&apos;&apos;,&apos;&apos;Dezagregare&apos;&apos;), null, null &apos;||sSelectUMA||gUserAlias||&apos;
  FROM transf t
    LEFT JOIN transf1  t1     ON t1.codtransf  = t.codtransf
    LEFT JOIN nartobj  nao    ON nao.codobiect = t1.codobiect
    LEFT JOIN nart     na     ON na.codarticol = nao.codarticol
    LEFT JOIN num1     um     on um.codum1 = t1.umsec
    LEFT JOIN num      um1    on um1.codum = na.um1
    LEFT JOIN num      um2    on um2.codum = na.um2
    LEFT JOIN nclasea  nca    ON nca.codclasea  = na.clasa
    LEFT JOIN nart1    na1    ON na1.codarticol = nao.codarticol AND (t.an*12+t.luna) between  na1.alstart and  na1.alstop
    LEFT JOIN ntva1    tva1   ON tva1.codtva    = na1.codtva     AND (t.an*12+t.luna) between tva1.alstart and tva1.alstop
    LEFT JOIN nartobj1 nao1   ON nao1.codobiect = t1.codobiect   AND (t.an*12+t.luna) between nao1.alstart and nao1.alstop
    LEFT JOIN npart    prod   ON prod.codpart   = nao.codproducator
    LEFT JOIN pretm    pm     ON pm.codobiect   = t1.codobiect   AND pm.subunitatea = t.subunitatea AND pm.implicit = 1
    LEFT JOIN IOART    IOAS   ON IOAS.CODIOART  = (t.codtransf - t.codtransf)
    LEFT JOIN IOART    IOAD   ON IOAD.CODIOART  = (t.codtransf - t.codtransf)
    LEFT JOIN ncont    cs     ON cs.codcont = (t.codtransf - t.codtransf)
    LEFT JOIN ncont    cd     ON cd.codcont = (t.codtransf - t.codtransf)
    LEFT JOIN prodcomp ret    ON ret.codprodcomp   = t1.codreteta
    LEFT JOIN prodmat  mat    ON mat.codprodcomp   = t1.codreteta
    LEFT JOIN nartobj  objmat ON objmat.codobiect  = mat.codobiect
    LEFT JOIN nart     artmat ON objmat.codarticol = artmat.codarticol
    LEFT JOIN num      ummat  ON artmat.um = ummat.codum
    LEFT JOIN PRETM    PRETM  ON PRETM.CODOBIECT = NAO.CODOBIECT AND PRETM.IMPLICIT = 1 and PRETM.SUBUNITATEA = T.SUBUNITATEA&apos;||
    sJoinUMA||
    gSuplJoins||&apos;
  WHERE T.CODTRANSF =&apos;||vCodDoc||&apos;
  ORDER BY t1.indexlocal &apos;;

  IF vOk = 1
  THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectOK, aListID, aListVer);
  ELSE
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectNOK, aListID, aListVer);
  END IF;
  pkg_list_base_transfdoc.ProcessParams(vCodDoc);
--  pkg_globals.ResetAllRecordsLunaFlags;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_TRANSFDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>682798553D28B03E88860FF76E14F24605DAF4FF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRAS IS


  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE maketmpSerii IS
  AnPrec   NUMBER(4);
  LunaPrec NUMBER(2);
	AnTemp   NUMBER(4);
	LunaTemp NUMBER(2);
  vDataIni DATE       := add_months(last_day(PKG_LIST_SELTRAS.getDataIni),-1);
  vDataFin DATE       := PKG_LIST_SELTRAS.getDataFin;
BEGIN
  AnTemp   := EXTRACT (YEAR  FROM PKG_LIST_SELTRAS.getDataIni);
  LunaTemp := EXTRACT (MONTH FROM PKG_LIST_SELTRAS.getDataIni);
  pkg_globals.SetLunaTemp(anTemp,LunaTemp);
  pkg_globals.Calculeaza_Luna_Precedenta(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(Anprec,LunaPrec);

  INSERT INTO tmp_manevra_liste (filtru,valoare)
  SELECT DISTINCT &apos;CODNIRSTOC&apos;,CODNIRSTOC
  FROM(
    SELECT v.codnirstoc
    FROM tmp_manevra_liste tmp
      INNER JOIN nirstoc ns ON ns.codobiect = tmp.valoare
      INNER JOIN v_stoc_luna_prec v ON ns.codnirstoc = v.CODNIRSTOC
    WHERE tmp.filtru = &apos;CODOBIECT&apos;
    UNION
    SELECT ns.codnirstoc
    FROM tmp_manevra_liste tmp
      INNER JOIN nirstoc ns ON ns.codobiect = tmp.valoare
			LEFT JOIN nir n ON ns.codnir = n.codnir
			LEFT JOIN LIVR1 L1 ON NS.CODNIRSTOC = L1.CODNIRSTOC
			LEFT JOIN LIVR L ON  L1.CODLIVR = L.CODLIVR
    WHERE tmp.filtru = &apos;CODOBIECT&apos; AND COALESCE(n.datanir, l.datalivr,vDataIni-1) BETWEEN vDataIni AND vDataFin
	);

  COMMIT;
  pkg_list_base_utils.BAGA_SERII_IN_TMP(pkg_list_base_utils.CT_TOATE);
END;

PROCEDURE MakeSQLStocIni(pInsert IN CLOB, pTipC IN VARCHAR2, pGest IN VARCHAR2) IS
  sqlStocIni CLOB;
	sqlTranz   CLOB;
  fInterval  CLOB;
  AnPrec     NUMBER(4);
  LunaPrec   NUMBER(2);
  AnTemp     NUMBER(4);
  LunaTemp   NUMBER(2);
  AnLunaMin  NUMBER(5);
  aDataI     DATE;
  aDataF     DATE;
  sAux1      VARCHAR2(  500);
  sAux2      VARCHAR2(  500);
  sAnPrec    VARCHAR2(    4);
  sLunaPrec  VARCHAR2(    2);
  sAnTemp    VARCHAR2(    4);
  sLunaTemp  VARCHAR2(    2);
  sALTemp    VARCHAR2(    5);
BEGIN
  SELECT ANINITIAL*12+LUNAINITIALA INTO AnLunaMin FROM FirmaLuni;

  aDataI   := Trunc(PKG_LIST_SELTRAS.getDataIni,&apos;MM&apos;);
  aDataF   := PKG_LIST_SELTRAS.getDataIni - 1;

  IF aDataF = aDataI
  THEN fInterval := &apos;= to_date(&apos;&apos;&apos;||To_Char(aDataI,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  ELSE fInterval := &apos;BETWEEN to_date(&apos;&apos;&apos;||To_Char(aDataI,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||To_Char(aDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  END IF;

  AnTemp   := EXTRACT (YEAR  FROM PKG_LIST_SELTRAS.getDataIni);
  LunaTemp := EXTRACT (MONTH FROM PKG_LIST_SELTRAS.getDataIni);
  pkg_globals.SetLunaTemp(AnTemp,LunaTemp);
  pkg_globals.Calculeaza_Luna_Precedenta(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(Anprec,LunaPrec);

  sAnPrec   := To_Char(AnPrec  , &apos;fm0000&apos;);
  sLunaPrec := To_Char(LunaPrec, &apos;fm90&apos;);
  sAnTemp   := To_Char(AnTemp  , &apos;fm0000&apos;);
  sLunaTemp := To_Char(LunaTemp, &apos;fm90&apos;);
  sALTemp   := To_Char(AnTemp*12+LunaTemp, &apos;fm00000&apos;);

  IF aDataF &gt;= aDataI THEN
    sqlTranz := &apos;
      UNION ALL
      SELECT
        NS.CODNIRSTOC, NS.CODOBIECT, NSER.CODNIRSER, SER.CODSERIE, N.GEST, Coalesce(NS.FURN,0) FURN,
        NS.PRET PINREG, (NS.PRET - NS.ADAOS) PAchiz, Coalesce(NSER.CANTNIR,NS.CANTNIR) CANT, NS.CODIOART, &apos;||sAnTemp||&apos; AN, &apos;||sLunaTemp||&apos; LUNA, NS.UMSEC, IOA1.CODIOART1
      FROM NIRSTOC NS
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST
        INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND &apos;||sALTemp||&apos; BETWEEN IOA1.ALStart AND IOA1.ALStop
        LEFT JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
      WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND N.DATANIR &apos;|| fInterval ||&apos; AND N.ANULAT = 0 AND N.OPERAT = 1 AND IOA1.MG &lt;&gt; 5
        AND EXISTS (
          SELECT 1
          FROM TMP_MANEVRA_LISTE
          WHERE FILTRU  = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = To_Char(NS.CODOBIECT)
            AND FILTRU1 = &apos;&apos;CODSERIE&apos;&apos;  AND Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(NSER.CODSERIE)  END
            AND FILTRU2 = &apos;&apos;SERIELOT&apos;&apos;  AND Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) ELSE NS.SERIELOT             END
            AND FILTRU3 = &apos;&apos;TG&apos;&apos;        AND Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(COALESCE(NSER.TG,NS.TG),&apos;&apos;DD.MM.YYYY&apos;&apos;) END
        )&apos; ||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
        pGest||
        pTipC||&apos;
      UNION ALL
      SELECT
        L1.CODNIRSTOC, NS.CODOBIECT, NSER.CODNIRSER, SER.CODSERIE, N.GEST, Coalesce(NS.FURN,0) FURN,
        NS.PRET PINREG, (NS.PRET - NS.ADAOS) PAchiz, CASE L.TIPLIVR WHEN 15 THEN 1 ELSE -1 END * L1.CANT CANT, NS.CODIOART, &apos;||sAnTemp||&apos; AN, &apos;||sLunaTemp||&apos; LUNA, NS.UMSEC, IOA1.CODIOART1
      FROM LIVR L
        INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST G ON G.CODGEST = N.GEST
        INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND &apos;||sALTemp||&apos; BETWEEN IOA1.ALStart AND IOA1.ALStop
        LEFT JOIN NIRSER NSER ON NSER.CODNIRSER = L1.CODNIRSER
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 19, 20, 23, 24) AND L.DATALIVR &apos;||fInterval||&apos; AND L.OPERAT = 1 AND L.ANULAT = 0 AND IOA1.MG &lt;&gt; 5
        AND EXISTS (
          SELECT 1
          FROM TMP_MANEVRA_LISTE
          WHERE FILTRU  = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = To_Char(NS.CODOBIECT)
            AND FILTRU1 = &apos;&apos;CODSERIE&apos;&apos;  AND Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(NSER.CODSERIE)  END
            AND FILTRU2 = &apos;&apos;SERIELOT&apos;&apos;  AND Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) ELSE NS.SERIELOT             END
            AND FILTRU3 = &apos;&apos;TG&apos;&apos;        AND Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(COALESCE(NSER.TG,NS.TG),&apos;&apos;DD.MM.YYYY&apos;&apos;) END
        )&apos; ||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
        pGest||
        pTipC;
  END IF;

  IF PKG_LIST_SELTRAS.isSICentralizat THEN
    sAux1 := &apos;0 codnirstoc, 0 codnirser, &apos;;
    sAux2 := &apos;&apos;;
  ELSE
    sAux1 := &apos;codnirstoc, codnirser, &apos;;
    sAux2 := &apos;CODNIRSTOC, CODNIRSER, &apos;;
  END IF;

  sqlStocIni := &apos;
  WITH CRS_INI AS (
    SELECT &apos;||sAux1||&apos;codobiect, NULL codintr1, NULL coddvi1, NULL codlivr1, NULL codtransf1, NULL tipmiscare, NULL codies1, NULL codslivr,
      SUM(CANT) intrare, 0 iesire, (SUM(PACHIZ*CANT) )/Coalesce(Nullif(SUM(CANT),0),1) pachiz, pinreg, 0 pumaximal, NULL dataexp, furn,
      NULL coddoc, gest, 0 partener, 0 codsubunit, 0 codgestprod,
      an, luna, codioart, codioart1, 0 codlocatie, 0 ordine, NULL d1, NULL d2, NULL d3, codserie, NULL codcmdint
    FROM (
      SELECT
        NS.CODNIRSTOC, NS.CODOBIECT, NSER.CODNIRSER, SER.CODSERIE, N.GEST, Coalesce(NS.FURN,0) FURN,
        NS.PRET PINREG, (NS.PRET - NS.ADAOS) PAchiz, Coalesce(NSERL.REST,NL.REST) CANT, NS.CODIOART, &apos;||sAnTemp||&apos; AN, &apos;||sLunaTemp||&apos; LUNA, NS.UMSEC, IOA1.CODIOART1
      FROM NIRLUNA NL
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NGEST NG ON NG.CODGEST = N.GEST
        INNER JOIN IOART1 IOA1 ON NS.CODIOART = IOA1.CODIOART AND &apos;||sALTemp||&apos; BETWEEN IOA1.ALStart AND IOA1.ALStop
        LEFT JOIN NIRSERLUNA NSERL ON NSERL.CODNIRSTOC = NL.CODNIRSTOC AND NSERL.AN = &apos;||sAnprec||&apos; AND NSERL.LUNA = &apos;||sLunaPrec||&apos;
        LEFT JOIN NIRSER NSER ON NSER.CODNIRSER = NSERL.CODNIRSER
        LEFT JOIN NSERII SER ON SER.CODSERIE = NSER.CODSERIE
      WHERE NL.AN = &apos;||sAnprec||&apos; AND NL.LUNA = &apos;||sLunaPrec||&apos; AND NL.REST &lt;&gt; 0 AND IOA1.MG &lt;&gt; 5
        AND EXISTS (
          SELECT 1
          FROM TMP_MANEVRA_LISTE
          WHERE FILTRU  = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = To_Char(NS.CODOBIECT)
            AND FILTRU1 = &apos;&apos;CODSERIE&apos;&apos;  AND Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(NSER.CODSERIE)  END
            AND FILTRU2 = &apos;&apos;SERIELOT&apos;&apos;  AND Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) ELSE NS.SERIELOT             END
            AND FILTRU3 = &apos;&apos;TG&apos;&apos;        AND Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(COALESCE(NSER.TG,NS.TG),&apos;&apos;DD.MM.YYYY&apos;&apos;) END
        )&apos; ||
        pTipC ||
        pGest ||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NG&apos;,&apos;CODSUBUNIT&apos;) ||
      sqlTranz||&apos;
    ) a_pg
    GROUP BY &apos;||sAux2||&apos;CODSERIE, CODOBIECT, GEST, PINREG, CODIOART, AN, LUNA, UMSEC, CODIOART1, FURN )
  SELECT
    crs.coddoc, crs.tipmiscare, crs.codnirstoc, nobj.denumire, crs.intrare, crs.iesire, crs.intrare - crs.iesire stoc_fake, crs.pAchiz, crs.pInreg, crs.pumaximal, crs.dataexp,
    furn.den_part denfurn, prod.den_part denprod,
    &apos;&apos;Stoc initial&apos;&apos; PrefixDoc, NULL SeriaDoc, NULL NrDoc, PKG_LIST_SELTRAS.getDataIni DataDoc, PKG_LIST_SELTRAS.getDataIni DataMisc,
    &apos;&apos;Stoc initial&apos;&apos; DIntrPrefix, NULL DIntrSeria, NULL DIntrNR, PKG_LIST_SELTRAS.getDataIni DIntrData,
    NULL DIesPrefix, NULL DIesSeria, NULL DIesNr, NULL DIesData,
    crs.ordine, NULL partener, ng.den_gest, io.den_ioart, ncont.simbol, loc.denumire denlocatie,
    ser.serie serii, crs.codlivr1, sub.den_subunit, crs.d1, crs.d2, crs.d3, ncls.den_claseas, nobj.codextern, um.den_um, um1.den_um, um2.den_um, cint.nrdoc, cint.datadoc &apos;||gUserAlias||&apos;
  FROM crs_ini crs
    LEFT JOIN nartobj nobj   ON crs.codobiect     = nobj.codobiect
    LEFT JOIN nart n         ON n.codarticol      = nobj.codarticol
    LEFT JOIN npart furn     ON furn.codpart      = crs.furn
    LEFT JOIN npart prod     ON prod.codpart      = nobj.codproducator
    LEFT JOIN npart part     ON part.codpart      = crs.partener AND NOT crs.tipmiscare IN (6, 23, 7, 24, 12, 13)
    LEFT JOIN ngest gestdest ON gestdest.codgest  = crs.partener AND crs.tipmiscare IN (12,13)
    LEFT JOIN nsubunit nsub  ON nsub.codsubunit   = crs.codsubunit AND crs.tipmiscare IN (6,23)
    LEFT JOIN ngest gestprod ON gestprod.codgest  = crs.codgestprod AND crs.tipmiscare IN (7,24)
    LEFT JOIN ngest ng       ON ng.codgest        = crs.gest
    LEFT JOIN ioart io       ON crs.codioart      = io.codioart
    LEFT JOIN ioart1 io1     ON io1.codioart1     = crs.codioart1
    LEFT JOIN ncont ncont    ON ncont.codcont     = io1.cont
    LEFT JOIN nlocatii loc   ON loc.codlocatie    = crs.codlocatie
    LEFT JOIN nirstoc ns     ON ns.codnirstoc     = crs.codnirstoc
    LEFT JOIN nirstoc1 ns1   ON ns1.codnirstoc    = crs.codnirstoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocorig
    LEFT JOIN nirser nser    ON nser.codnirser    = crs.codnirser
    LEFT JOIN nserii ser     ON ser.codserie      = crs.codserie
    LEFT JOIN nsubunit sub   ON sub.codsubunit    = ng.codsubunit
    LEFT JOIN nclaseas ncls  ON ncls.codclaseas   = n.clasastatist
    LEFT JOIN num um         ON um.codum          = n.um
    LEFT JOIN num um1        ON um1.codum         = n.um1
    LEFT JOIN num um2        ON um2.codum         = n.um2
    LEFT JOIN num1           ON num1.codum        = n.um and num1.secundara = 0
    LEFT JOIN nartamb aa     ON aa.codobiect      = crs.codobiect and aa.umsec = num1.codum1
    LEFT JOIN comanda cint   ON cint.codcomanda   = crs.codcmdint&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(pInsert||sqlStocIni, 0, 0);
  COMMIT;
END;

PROCEDURE MakeSQLMiscari (pInsert IN CLOB, pTipC IN VARCHAR2, pGest IN VARCHAR2) IS
  pInterval VARCHAR2(200)  := PKG_LIST_SELTRAS.GetInterval;
  sqlWith1  CLOB;
  sqlWith2  CLOB;
  sqlWith3  CLOB;
  sqlWith4  CLOB;
  sqlWith5  CLOB;
  sqlSelect CLOB;
BEGIN
  --intrari
  sqlWith1 := &apos;
  WITH crs_miscari AS (
    SELECT
      ns.codnirstoc, ns.codobiect,nser.codnirser,nser.codserie, COALESCE(ns.tg,nser.tg) dataexp,
      n.codintr coddoc, 1 tipd, intr.prefixdoc, intr.seriadoc, intr.nrdoc, intr.datadoc, n.datanir datamisc,
      ns.codintr1, ns.coddvi1, ns.codlivr1, ns.codtransf1, NULL codies1,
      Coalesce(nser.cantnir,ns.cantnir) intrare, 0 iesire,
      n.tipnir tipmiscare,
      1 ordine, (ns.pret - ns.adaos) PAchiz, ns.pret pInreg, ns.pumaximal, ns.furn, n.gest,
      intr.partener, intr.codsubunit, Coalesce(intr.codgestprod,ns.codgestprod) codgestprod,
      intr.an, intr.luna, ns.codioart, ns.codlocatie, intr.subunitatea subunitatea_doc,
      ns.d1, ns.d2, ns.d3, c1int.codcomanda codcmdint, intr.codlocatie codslivr
    FROM nirstoc ns
      INNER JOIN nir n ON ns.codnir = n.codnir
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN intrari1 intr1 ON ns.codintr1 = intr1.codintr1
      LEFT JOIN dvi1 ON ns.coddvi1 = dvi1.coddvi1
      LEFT JOIN intrari intr ON intr.codintr = n.codintr
      LEFT JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
      LEFT JOIN comanda1 c1int ON c1int.codcomanda1 = intr1.codcmdint1
    WHERE NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)
      AND n.tipnir BETWEEN 1 AND 9 AND INTR.OPERAT = 1
      AND n.datanir BETWEEN &apos;||pInterval||
      pTipC || pGest ||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;intr&apos;)||&apos;
  )&apos;;

  --iesiri, intrari in rosu(pe acelasi codnirstoc), monetare, mariri si diminuare
  sqlWith2 := &apos;
  WITH crs_miscari AS (
    SELECT
      ns.codnirstoc,ns.codobiect,nser.codnirser,nser.codserie,COALESCE(ns.tg,nser.tg) dataexp,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.codintr ELSE ies.codies END coddoc,
      CASE WHEN l.tiplivr in (1,2,5,6,7, 15) THEN 1 ELSE 2 END tipd,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.prefixdoc ELSE ies.prefixdoc END prefixdoc,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.seriadoc ELSE ies.seriadoc END seriadoc,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.nrdoc ELSE ies.nrdoc END nrdoc,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.datadoc ELSE ies.datadoc END datadoc,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN n.datanir ELSE l.DATALIVR END datamisc,
      ns.codintr1, ns.coddvi1, L1.codlivr1, ns.codtransf1, ies1.codies1,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN -l1.cant WHEN L.TIPLIVR = 15 THEN l1.cant ELSE 0 END intrare,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN 0 WHEN L.TIPLIVR = 15 THEN 0 ELSE l1.cant END iesire,
      l.tiplivr AS tipmiscare,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN 1 ELSE 2 END ordine, (ns.pret - ns.adaos) pAchiz, ns.pret pInreg ,ns.pumaximal, ns.furn, n.gest,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.partener ELSE ies.partener END partener,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.codsubunit ELSE ies.codsubunit END codsubunit,
      Coalesce(ies.codgestprod,ns.codgestprod) codgestprod,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.an ELSE ies.an END an,
      CASE WHEN l.tiplivr in (1,2,5,6,7) THEN intr.luna ELSE ies.luna END luna,
      ns.codioart,ns.codlocatie, Coalesce(intr.subunitatea, ies.subunitatea) subunitatea_doc,
      ns.d1, ns.d2, ns.d3, c1int.codcomanda codcmdint, COALESCE(intr.codlocatie, ies.codlocatie) codslivr
    FROM livr1 l1
      INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
      LEFT JOIN iesvallink ivl ON ivl.codies1 = l1.codies1
      LEFT JOIN livr1 lx1 ON lx1.codlivr1 = ivl.codlivr1
      LEFT JOIN livr l ON l.codlivr = Coalesce(lx1.codlivr, l1.codlivr)
      LEFT JOIN iesiri ies ON ies.codies = l.codies
      LEFT JOIN intrari intr ON intr.codintr = l.codintr
      LEFT JOIN nir n ON n.codnir = ns.codnir
      LEFT JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN nirser nser ON nser.codnirser = l1.codnirser
      LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr AND intr1.codintr1 = l1.codintr1
      LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies AND ies1.codies1 = Coalesce(lx1.codies1,l1.codies1)
      LEFT JOIN comanda1 c1int ON c1int.codcomanda1 = Coalesce(intr1.codcmdint1,ies1.codcmdint1)
    WHERE NS.CODOBIECT IN (SELECT DISTINCT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)
      AND ((l.tiplivr BETWEEN 19 AND 26 AND l1.cant &gt; 0 ) OR ( l.tiplivr IN ( 1,2,5,6,7,14,15,16) )) AND COALESCE(ies.operat,intr.operat,0) = 1
      AND Coalesce(l.datalivr,n.datanir) BETWEEN &apos;||pInterval||
      pTipC || pGest ||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;Coalesce(intr.subunitatea,ies.subunitatea)&apos;)||&apos;
  )&apos;;

  -- iesiri in rosu pe codnirstocuri noi
  sqlWith3 := &apos;
  WITH crs_miscari AS (
    SELECT
      ns.codnirstoc,ns.codobiect,nser.codnirser,nser.codserie,COALESCE(ns.tg,nser.tg) dataexp,
      ies.codies coddoc, 2 tipd, ies.prefixdoc, ies.seriadoc, ies.nrdoc, ies.datadoc, l.datalivr datamisc,
      ns.codintr1,ns.coddvi1,l1.codlivr1,ns.codtransf1,ies1.codies1,
      0 intrare, l1.cant iesire,
      l.tiplivr tipmiscare,
      1 ordine, (ns.pret - ns.adaos) pAchiz, ns.pret pInreg, ns.pumaximal, ns.furn, n.gest,
      ies.partener, ies.codsubunit, Coalesce(ies.codgestprod,ns.codgestprod) codgestprod,
      ies.an,ies.luna,ns.codioart,ns.codlocatie, ies.subunitatea subunitatea_doc,
      ns.d1, ns.d2, ns.d3, c1int.codcomanda codcmdint, ies.codlocatie codslivr
    FROM livr1 l1
      INNER JOIN livr l ON l.codlivr = l1.codlivr
      INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
      LEFT JOIN iesiri ies ON ies.codies = l.codies
      LEFT JOIN nir n ON n.codnir = ns.codnir
      LEFT JOIN NGEST G ON G.CODGEST = N.GEST
      LEFT JOIN NIRSER NSER ON NSER.CODNIRSER = L1.CODNIRSER
      LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies AND ies1.codies1 = l1.codies1
      LEFT JOIN comanda1 c1int ON c1int.codcomanda1 = ies1.codcmdint1
    WHERE NS.CODOBIECT IN (SELECT DISTINCT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)
      AND (l.tiplivr BETWEEN 19 AND 26 AND l1.cant &lt; 0 )
      AND IES.OPERAT = 1
      AND l.datalivr BETWEEN &apos;||pInterval||
      pTipC || pGest ||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;ies&apos;)||&apos;
  )&apos;;

  -- transferuri destinatii
  sqlWith4 := &apos;
  WITH crs_miscari AS (
    SELECT
      ns.codnirstoc,ns.codobiect,nser.codnirser,nser.codserie,Coalesce(ns.tg,nser.tg) dataexp,
      t.codtransf coddoc, 1 tipd, t.prefixdoc, t.seriadoc, t.nrdoc, t.datadoc, n.datanir datamisc,
      ns.codintr1,ns.coddvi1,ns.codlivr1,ns.codtransf1,NULL codies1,
      Coalesce(nser.cantnir,ns.cantnir) intrare, 0 iesire,
      n.tipnir AS tipmiscare,
      8 ordine ,(ns.pret - ns.adaos) pAchiz, ns.pret pInreg, ns.pumaximal, ns.furn, n.gest,
      nirs.gest partener, NULL codsubunit, ns.codgestprod,
      t.an, t.luna, ns.codioart,ns.codlocatie, t.subunitatea subunitatea_doc,
      ns.d1, ns.d2, ns.d3, NULL codcmdint, NULL codslivr
    FROM transf1 t1
      INNER JOIN nirstoc ns ON ns.codtransf1 = t1.codtransf1
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      INNER JOIN transf t ON t.codtransf = t1.codtransf
      LEFT JOIN nirstoc nss ON nss.codnirstoc = ns.codnirstocparinte
      LEFT JOIN nir nirs ON nirs.codnir = nss.codnir
      LEFT JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
    WHERE NS.CODOBIECT IN (SELECT DISTINCT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)
      AND T.OPERAT = 1
      AND n.datanir BETWEEN &apos;||pInterval||
      pTipC || pGest ||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;
  )&apos;;

  -- transferuri surse
  sqlWith5 := &apos;
  WITH crs_miscari AS (
    SELECT
      ns.codnirstoc,ns.codobiect,nsd.codnirser,nsd.codserie,COALESCE(nsd.tg, ns.tg) dataexp,
      t.codtransf coddoc, 2 tipd, t.prefixdoc, t.seriadoc, t.nrdoc, t.datadoc,nsd.datalivr datamisc,
      ns.codintr1, ns.coddvi1, nsd.codlivr1, nsd.codtransf1, NULL codies1,
      0 intrare, nsd.cant iesire,
      t.tipdoc tipmiscare,
      7 ordine, (ns.pret - ns.adaos) pAchiz, ns.pret pInreg, ns.pumaximal, ns.furn, n.gest,
      nsd.gest partener, NULL codsubunit, ns.codgestprod,
      t.an,t.luna,ns.codioart,ns.codlocatie, t.subunitatea SUBUNITATEA_DOC,
      ns.d1, ns.d2, ns.d3, NULL codcmdint, NULL codslivr
    FROM (
      SELECT
        ns.codnirstoc, ns.codnirstocparinte, n.tipnir, ns.codtransf1, ns.codlivr1, Coalesce(nser.cantnir,ns.cantnir) cant,
        l.datalivr, t.codtransf, n.gest, nser.codnirser, nser.codserie, nser.tg
      FROM transf t
        INNER JOIN nir n ON n.codtransf = t.codtransf AND n.tipnir = t.tipdoc
        INNER JOIN nirstoc ns ON ns.codnir = n.codnir
        INNER JOIN livr1 l1 ON l1.codlivr1 = ns.codlivr1
        INNER JOIN livr l ON l.codlivr = l1.codlivr
        LEFT JOIN NIRSER NSER ON NSER.CODNIRSTOC = NS.CODNIRSTOC
      WHERE NS.CODOBIECT IN (SELECT DISTINCT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;)
        AND T.OPERAT = 1
        AND l.datalivr BETWEEN &apos;||pInterval||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;
    ) nsd
      INNER JOIN nirstoc ns ON ns.codnirstoc = nsd.codnirstocparinte
      INNER JOIN nir n ON n.codnir = ns.codnir
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
      INNER JOIN transf t ON t.codtransf = nsd.codtransf
    WHERE 1=1 &apos;||
      pTipC||pGest||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;G&apos;,&apos;CODSUBUNIT&apos;)||&apos;
  )&apos;;

  sqlSelect := &apos;
  SELECT
    crs.coddoc, crs.tipmiscare, crs.codnirstoc, nobj.denumire, crs.intrare, crs.iesire, crs.intrare - crs.iesire stoc_fake, crs.pAchiz, crs.pInreg, crs.pumaximal, crs.dataexp,
    CASE crs.furn WHEN 0 THEN gestprod.den_gest ELSE furn.den_part END denfurn, prod.den_part denprod,
    crs.PrefixDoc, crs.SeriaDoc, crs.NrDoc, crs.DataDoc, crs.DataMisc,
    CASE crs.tipd WHEN 1 THEN crs.prefixdoc END DIntrPrefix, CASE crs.tipd WHEN 1 THEN crs.seriadoc END DIntrSeria, CASE crs.tipd WHEN 1 THEN crs.nrdoc END DIntrNR, CASE crs.tipd WHEN 1 THEN crs.datadoc END DIntrData,
    CASE crs.tipd WHEN 2 THEN crs.prefixdoc END DIesPrefix , CASE crs.tipd WHEN 2 THEN crs.seriadoc END DIesSeria,  CASE crs.tipd WHEN 2 THEN crs.nrdoc END DIesNr,  CASE crs.tipd WHEN 2 THEN crs.datadoc END DIesData,
    crs.ordine, COALESCE( nsub.den_subunit, gestprod.den_gest, gestdest.den_gest, part.den_part) partener, ng.den_gest, io.den_ioart,ncont.simbol,loc.denumire denlocatie,
    ser.serie serii, crs.codlivr1, sub.den_subunit,crs.d1, crs.d2, crs.d3, ncls.den_claseas, nobj.codextern, um.den_um, um1.den_um, um2.den_um, cint.nrdoc, cint.datadoc &apos;||
    gUserAlias||&apos;
  FROM crs_miscari crs
    INNER JOIN nartobj nobj  ON nobj.codobiect    = crs.codobiect
    INNER JOIN nart n        ON n.codarticol      = nobj.codarticol
    LEFT JOIN npart furn     ON furn.codpart      = crs.furn
    LEFT JOIN npart prod     ON prod.codpart      = nobj.codproducator
    LEFT JOIN npart part     ON part.codpart      = crs.partener AND NOT crs.tipmiscare IN (6, 23, 7, 24, 12, 13)
    LEFT JOIN ngest gestdest ON gestdest.codgest  = crs.partener AND crs.tipmiscare IN (12,13)
    LEFT JOIN nsubunit nsub  ON nsub.codsubunit   = crs.codsubunit AND crs.tipmiscare IN (6,23)
    LEFT JOIN ngest gestprod ON gestprod.codgest  = crs.codgestprod AND crs.tipmiscare IN (7,24)
    LEFT JOIN ngest ng       ON ng.codgest        = crs.gest
    LEFT JOIN ioart io       ON io.codioart       = crs.codioart
    LEFT JOIN ioart1 io1     ON io1.codioart      = crs.codioart AND crs.an*12+crs.luna BETWEEN io1.alstart AND io1.alstop
    LEFT JOIN ncont ncont    ON ncont.codcont     = io1.cont
    LEFT JOIN nlocatii loc   ON loc.codlocatie    = crs.codlocatie
    LEFT JOIN nirstoc ns     ON ns.codnirstoc     = crs.codnirstoc
    LEFT JOIN nirstoc1 ns1   ON ns1.codnirstoc    = crs.codnirstoc
    LEFT JOIN nirstoc nsroot ON nsroot.codnirstoc = ns1.codnirstocorig
    LEFT JOIN nirser nser    ON nser.codnirser    = crs.codnirser
    LEFT JOIN nserii ser     ON ser.codserie      = crs.codserie
    LEFT JOIN nsubunit sub   ON sub.codsubunit    = crs.subunitatea_doc
    LEFT JOIN nclaseas ncls  ON ncls.codclaseas   = n.clasastatist
    LEFT JOIN num um         ON um.codum          = n.um
    LEFT JOIN num um1        ON um1.codum         = n.um1
    LEFT JOIN num um2        ON um2.codum         = n.um2
    LEFT JOIN num1           ON num1.codum        = n.um and num1.secundara = 0
    LEFT JOIN nartamb aa     ON aa.codobiect      = crs.codobiect and aa.umsec = num1.codum1
    LEFT JOIN comanda cint   ON cint.codcomanda   = crs.codcmdint&apos;||
    gSuplJoins||&apos;
  WHERE io1.mg &lt;&gt; 5
    AND EXISTS (
      SELECT 1
      FROM TMP_MANEVRA_LISTE
      WHERE FILTRU  = &apos;&apos;CODOBIECT&apos;&apos; AND VALOARE = To_Char(CRS.CODOBIECT)
        AND FILTRU1 = &apos;&apos;CODSERIE&apos;&apos;  AND Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE1,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(CRS.CODSERIE)   END
        AND FILTRU2 = &apos;&apos;SERIELOT&apos;&apos;  AND Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE2,&apos;&apos;-1&apos;&apos;) ELSE NS.SERIELOT             END
        AND FILTRU3 = &apos;&apos;TG&apos;&apos;        AND Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = CASE WHEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) = &apos;&apos;-1&apos;&apos; THEN Coalesce(VALOARE3,&apos;&apos;-1&apos;&apos;) ELSE TO_CHAR(COALESCE(NSER.TG,NS.TG),&apos;&apos;DD.MM.YYYY&apos;&apos;) END
    )&apos;;

  LIST_EXECUTE_IMMEDIATE(pInsert||sqlwith1||sqlSelect, 0, 0);
  LIST_EXECUTE_IMMEDIATE(pInsert||sqlwith2||sqlSelect, 0, 0);
  LIST_EXECUTE_IMMEDIATE(pInsert||sqlwith3||sqlSelect, 0, 0);
  LIST_EXECUTE_IMMEDIATE(pInsert||sqlwith4||sqlSelect, 0, 0);
  LIST_EXECUTE_IMMEDIATE(pInsert||sqlwith5||sqlSelect, 0, 0);
  COMMIT;
END;

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert CLOB;
  sTipC   VARCHAR2(1000);
  sGest   VARCHAR2(1000);
BEGIN
  gSuplCols :=
    &apos;nartobj nobj, nart n, npart furn, npart prod, npart part, nsubunit nsub, ngest gestprod, ngest ng, ioart io, ioart1 io1, ncont ncont, nlocatii loc, nirstoc ns, nirstoc nsroot, &apos;||
    &apos;ngest gestdest, nirser nser, nserii ser, nsubunit sub, nclaseas ncls, num um, num um1, num um2, num1 num1, nartamb aa, comanda cint&apos;;

  --IN PG TREBUIE TINUT CONT CA NULL &lt;&gt; &apos;&apos; AS CA PT PG SI CE E MAI JOS
  --UPDATE TMP_MANEVRA_LISTE SET VALOARE1 = NULLIF (VALOARE1, &apos;&apos;), VALOARE2 = NULLIF (VALOARE2, &apos;&apos;);

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;IES1&apos;, &apos;IES1.CODIES1 = CRS.CODIES1&apos;     , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;IES&apos;,  &apos;IES.CODIES = IES1.CODIES&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI1&apos;,   &apos;INTR1&apos;,&apos;INTR1.CODINTR1 = CRS.CODINTR1&apos;  , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;,    &apos;INTR&apos;, &apos;INTR.CODINTR = INTR1.CODINTR&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF1&apos;,    &apos;TR1&apos;,  &apos;TR1.CODTRANSF1 = CRS.CODTRANSF1&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TRANSF&apos;,     &apos;TR&apos;,   &apos;TR.CODTRANSF = TR1.CODTRANSF&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SLIVR&apos;,&apos;SLIVR.CODAGENDA = CRS.CODSLIVR&apos; , 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpname||&apos;(
    NAV_CODDOC, NAV_TIPDOC, CODNIRSTOC, DENUMIRE, INTRARE, IESIRE, STOC_FAKE, PACHIZ, PINREG, PUMAXIMAL, DATAEXP,
    DENFURN, DENPROD,
    PREFIXDOC, SERIADOC, NRDOC, DATADOC, DATAMISC,
    DINTRPREFIX, DINTRSERIA, DINTRNR, DINTRDATA,
    DIESPREFIX, DIESSERIA, DIESNR, DIESDATA,
    ORDINE, PARTENER, DEN_GEST, DEN_IOART, SIMBOL, DENLOCATIE,
    SERII,CODLIVR1,SUBUNITATEA_DOC, D1,D2,D3,CLASAS,CODEXTERN,UM,UM1,UM2, NRCOMINT,DATACOMINT&apos;||gUserFields||&apos;)&apos;;

  IF NOT PKG_LIST_SELTRAS.isAllTipCont THEN
    sTipC := &apos;
        AND NS.CODIOART IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODIOART&apos;&apos;) &apos; ;
  END IF;
  IF NOT PKG_LIST_SELTRAS.isAllGest THEN
    sGest := &apos;
        AND (
          N.GEST        IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODGEST&apos;&apos;) OR
          NS.CODLOCATIE IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODLOCATIE&apos;&apos;)
        ) &apos;;
  END IF;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  PRC_AL_CHECK(&apos;IOART1&apos;);
  MakeSQLStocIni(sInsert, sTipC, sGest);
	MakeSQLMiscari(sInsert, sTipC, sGest);
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_tras;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASCMDINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>519DA96C29C3312D7A37C6ADA1A5528529F93069</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRASCMDINT is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert   VARCHAR2(2000);
sSelect   VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;comanda1 c1,comanda c,cmdprodmat mat,cmdprodman man&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  UmpleTemporar;

  if not PKG_LIST_SELECTPERIOADA.optiunea1 then
    sInsert :=
      &apos;INSERT INTO &apos;||TMPNAME||&apos;(
         COD,
         NRDOC,
         DataDoc,
         PRODUS,
         SERIEPRODUS,
         IOARTPRODUS,
         CANTPRODUS,
         PRETPRODUS,
         VALPRODUS,
         MATERIAL,
         SERIEMATERIAL,
         IOARTMATERIAL,
         CANTMATERIAL,
         PRETMATERIAL,
         VALMATERIAL,
         OPERATIE,
         NROP,
         VALOP
         &apos;||gUserFields||&apos;)&apos;;

    sSelect := &apos;
    select
      tmp.COD,
      c.NRDOC,
      c.DataDoc,
      tmp.PRODUS,
      tmp.SERIEPRODUS,
      tmp.IOARTPRODUS,
      tmp.CANTPRODUS,
      tmp.PRETPRODUS,
      tmp.VALPRODUS,
      tmp.MATERIAL,
      tmp.SERIEMATERIAL,
      tmp.IOARTMATERIAL,
      tmp.CANTMATERIAL,
      tmp.PRETMATERIAL,
      tmp.VALMATERIAL,
      tmp.OPERATIE,
      tmp.NROP,
      tmp.VALOP &apos;||gUserAlias||&apos;
    from tmp_trascmdint tmp
         inner join comanda1  c1  on tmp.codcomanda1   = c1.codcomanda1
         inner join comanda   c   on c1.codcomanda     = c.codcomanda
         left join cmdprodmat mat on mat.codcmdprodmat = tmp.codcmdprodmat
         left join cmdprodman man on man.codcmdprodman = tmp.codcmdprodman&apos;||gSuplJoins;
  else
    sInsert :=
      &apos;INSERT INTO &apos;||TMPNAME||&apos;(
         COD,
         NRDOC,
         DataDoc,
         PRODUS,
         IOARTPRODUS,
         CANTPRODUS,
         PRETPRODUS,
         VALPRODUS,
         MATERIAL,
         IOARTMATERIAL,
         CANTMATERIAL,
         PRETMATERIAL,
         VALMATERIAL,
         OPERATIE,
         NROP,
         VALOP
         &apos;||gUserFields||&apos;)&apos;;

    sSelect := &apos;
    select
      tmp.COD,
      c.NRDOC,
      c.DataDoc,
      tmp.PRODUS,
      tmp.IOARTPRODUS,
      tmp.CANTPRODUS,
      tmp.PRETPRODUS,
      tmp.VALPRODUS,
      tmp.MATERIAL,
      tmp.IOARTMATERIAL,
      tmp.CANTMATERIAL,
      tmp.PRETMATERIAL,
      tmp.VALMATERIAL,
      tmp.OPERATIE,
      tmp.NROP,
      tmp.VALOP &apos;||gUserAlias||&apos;
    from tmp_trascmdint tmp
         inner join comanda1  c1  on tmp.codcomanda1   = c1.codcomanda1
         inner join comanda   c   on c1.codcomanda     = c.codcomanda
         left join cmdprodmat mat on mat.codcmdprodmat = tmp.codcmdprodmat
         left join cmdprodman man on man.codcmdprodman = tmp.codcmdprodman&apos;||gSuplJoins;
  end if;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

procedure UmpleTemporar IS
cnp number(10);
cbc number(10);
crp number(10);  
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  DELETE TMP_TRASCMDINT; 
  DELETE TMP_TRASNP;
  DELETE TMP_TRASBC;
  DELETE TMP_TRASRP;
  if not PKG_LIST_SELECTPERIOADA.optiunea1 then
    INSERT INTO TMP_TRASNP(CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD,CODCMDPRODMAT)
    SELECT C1.CODCOMANDA1,O.DENUMIRE,SER.SERIE,IO.DEN_IOART,SUM(CASE WHEN NSE.CODNIRSTOC IS NULL THEN NS.CANTNIR ELSE NSE.CANTNIR END),NS.PRET,SUM(NSE.CANTNIR*NS.PRET), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC), L.CODLINIECOMANDA
    FROM COMANDA1 C1
         INNER JOIN COMANDA      C   ON C1.CODCOMANDA  = C.CODCOMANDA
         INNER JOIN INTRARI1     I1  ON I1.CODCMDINT1  = C1.CODCOMANDA1
         INNER JOIN INTRARI      I   ON I1.CODINTR     = I.CODINTR
         INNER JOIN NIR              ON I.CODINTR      = NIR.CODINTR
         INNER JOIN NIRSTOC      NS  ON NS.CODNIR      = NIR.CODNIR AND I1.CODINTR1 = NS.CODINTR1
         INNER JOIN NARTOBJ      O   ON I1.CODOBIECT   = O.CODOBIECT
         INNER JOIN IOART        IO  ON NS.CODIOART    = IO.CODIOART
         LEFT  JOIN NIRSER       NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
         LEFT  JOIN NSERII       SER ON SER.CODSERIE   = NSE.CODSERIE
         LEFT  JOIN INTRPRODLINK L ON I1.CODINTR1 = L.CODINTR1
    WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN
    GROUP BY C1.CODCOMANDA1,O.DENUMIRE,SER.SERIE,IO.DEN_IOART,NS.PRET,C.DATADOC,L.CODLINIECOMANDA;
    
    INSERT INTO TMP_TRASBC(CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT)
    SELECT C1.CODCOMANDA1, O.DENUMIRE, stragg3200(SER.SERIE),IO.DEN_IOART,SUM(L1.CANT),SUM(NS.PRET*L1.CANT)/SUM(L1.CANT),SUM(L1.CANT*NS.PRET), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC),LI.CODCMDPRODMAT
    FROM COMANDA1 C1
         INNER JOIN COMANDA     C   ON C.CODCOMANDA  = C1.CODCOMANDA
         INNER JOIN IESIRI1     I1  ON I1.CODCMDINT1 = C1.CODCOMANDA1
         INNER JOIN IESIRI      I   ON I1.CODIES     = I.CODIES
         INNER JOIN LIVR        L   ON L.CODIES      = I.CODIES
         INNER JOIN LIVR1       L1  ON L.CODLIVR     = L1.CODLIVR AND L1.CODIES1 = I1.CODIES1
         INNER JOIN NIRSTOC     NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
         INNER JOIN IOART       IO  ON IO.CODIOART   = NS.CODIOART
         INNER JOIN NARTOBJ     O   ON O.CODOBIECT   = I1.CODOBIECT
         LEFT  JOIN NIRSER      NSE ON NSE.CODNIRSER = L1.CODNIRSER
         LEFT  JOIN NSERII      SER ON SER.CODSERIE  = NSE.CODSERIE
         LEFT  JOIN IESPRODLINK LI  ON I1.CODIES1    = LI.CODIES1
    WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN
    GROUP BY C1.CODCOMANDA1,O.DENUMIRE,IO.DEN_IOART,C.DATADOC,LI.CODCMDPRODMAT;

    INSERT INTO TMP_TRASRP(CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN)
    SELECT C1.CODCOMANDA1, O.DENUMIRE, SUM(R2.REALIZAT), SUM(T1.TARIF*R2.REALIZAT*R2.TU/60), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC),MAN.CODCMDPRODMAN
    FROM COMANDA1 C1
         INNER JOIN COMANDA     C   ON C.CODCOMANDA      = C1.CODCOMANDA
         INNER JOIN CMDPRODMAN  MAN ON MAN.CODCOMANDA1   = C1.CODCOMANDA1
         INNER JOIN MANPRODLINK L   ON MAN.CODCMDPRODMAN = L.CODCMDPRODMAN
         INNER JOIN RAPORTP2    R2  ON R2.CODRAPORTP2    = L.CODRAPORTP2
         INNER JOIN RAPORTP1    R1  ON R2.CODRAPORTP1    = R1.CODRAPORTP1
         INNER JOIN RAPORTP     R   ON R1.CODRAPORTP     = R.CODRAPORTP
         INNER JOIN NOPER       O   ON O.CODOP           = R2.CODOP
         INNER JOIN TARIFEMAN1  T1  ON T1.CODTARIF       = R2.CODTARIF AND (R.AN*12+R.LUNA) BETWEEN T1.ALSTART and T1.ALSTOP
    WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53 
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN 
    GROUP BY C1.CODCOMANDA1, O.DENUMIRE,C.DATADOC,MAN.CODCMDPRODMAN;
    
    COMMIT;
    
    FOR V_REC IN (SELECT C1.CODCOMANDA1 
                  FROM COMANDA1 C1
                       INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
                  WHERE C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN AND C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0
                 ) LOOP
      SELECT COUNT(*) INTO CNP FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      SELECT COUNT(*) INTO CBC FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      SELECT COUNT(*) INTO CRP FROM TMP_TRASRP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      if cnp &gt;= cbc and cnp &gt;= crp  then
        --cnp e cel mai mare
        --inserez
        INSERT INTO TMP_TRASCMDINT(COD,CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS)
        SELECT COD,CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS
        FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
        FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
                     FROM TMP_TRASBC
                     WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                    ) LOOP
          UPDATE TMP_TRASCMDINT 
          SET 
            MATERIAL      = V_BC.MATERIAL,
            SERIEMATERIAL = V_BC.SERIEMATERIAL,
            IOARTMATERIAL = V_BC.IOARTMATERIAL,
            CANTMATERIAL  = V_BC.CANTMATERIAL,
            PRETMATERIAL  = V_BC.PRETMATERIAL,
            VALMATERIAL   = V_BC.VALMATERIAL,
            CODCMDPRODMAT = V_BC.CODCMDPRODMAT
          WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
        END LOOP;
        FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
                     FROM TMP_TRASRP
                     WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                    ) LOOP
          UPDATE TMP_TRASCMDINT 
          SET 
            OPERATIE      = V_RP.OPERATIE,
            NROP          = V_RP.NROP,
            VALOP         = V_RP.VALOP,
            CODCMDPRODMAN = V_RP.CODCMDPRODMAN
          WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
        END LOOP;
      else
        if cbc &gt;= cnp and cbc &gt;= crp  then
          --cnp e cel mai mare
          --inserez
          INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT)
          SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
          FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
          FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                       FROM TMP_TRASNP
                       WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                      ) LOOP
            UPDATE TMP_TRASCMDINT 
            SET 
              PRODUS      = V_NP.PRODUS,
              SERIEPRODUS = V_NP.SERIEPRODUS,
              IOARTPRODUS = V_NP.IOARTPRODUS,
              CANTPRODUS  = V_NP.CANTPRODUS,
              PRETPRODUS  = V_NP.PRETPRODUS,
              VALPRODUS   = V_NP.VALPRODUS
            WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
          END LOOP;
          FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
                       FROM TMP_TRASRP
                       WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                      ) LOOP
            UPDATE TMP_TRASCMDINT 
            SET 
              OPERATIE      = V_RP.OPERATIE,
              NROP          = V_RP.NROP,
              VALOP         = V_RP.VALOP,
              CODCMDPRODMAN = V_RP.CODCMDPRODMAN
            WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
          END LOOP;
        else
          if crp &gt;= cnp and crp &gt;= cbc  then
            --cnp e cel mai mare
            --inserez
            INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN)
            SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
            FROM TMP_TRASrp WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
            FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
                         FROM TMP_TRASBC
                         WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                        ) LOOP
              UPDATE TMP_TRASCMDINT 
              SET 
                MATERIAL      = V_BC.MATERIAL,
                SERIEMATERIAL = V_BC.SERIEMATERIAL,
                IOARTMATERIAL = V_BC.IOARTMATERIAL,
                CANTMATERIAL  = V_BC.CANTMATERIAL,
                PRETMATERIAL  = V_BC.PRETMATERIAL,
                VALMATERIAL   = V_BC.VALMATERIAL,
                CODCMDPRODMAT = V_BC.CODCMDPRODMAT
              WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
            END LOOP;
            FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                         FROM TMP_TRASNP
                         WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                        ) LOOP
              UPDATE TMP_TRASCMDINT 
              SET 
                PRODUS      = V_NP.PRODUS,
                SERIEPRODUS = V_NP.SERIEPRODUS,
                IOARTPRODUS = V_NP.IOARTPRODUS,
                CANTPRODUS  = V_NP.CANTPRODUS,
                PRETPRODUS  = V_NP.PRETPRODUS,
                VALPRODUS   = V_NP.VALPRODUS
              WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
            END LOOP;
          end if;  
        end if;    
      end if;
    END LOOP;
  else
    INSERT INTO TMP_TRASNP(CODCOMANDA1,PRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD,CODCMDPRODMAT)
    SELECT C1.CODCOMANDA1,O.DENUMIRE,IO.DEN_IOART,SUM(NS.CANTNIR),NS.PRET,SUM(NS.CANTNIR*NS.PRET), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC), L.CODLINIECOMANDA
    FROM COMANDA1 C1
         INNER JOIN COMANDA      C  ON C1.CODCOMANDA = C.CODCOMANDA
         INNER JOIN INTRARI1     I1 ON I1.CODCMDINT1 = C1.CODCOMANDA1
         INNER JOIN INTRARI      I  ON I1.CODINTR    = I.CODINTR
         INNER JOIN NIR             ON I.CODINTR     = NIR.CODINTR
         INNER JOIN NIRSTOC      NS ON NS.CODNIR     = NIR.CODNIR AND I1.CODINTR1 = NS.CODINTR1
         INNER JOIN NARTOBJ      O  ON I1.CODOBIECT  = O.CODOBIECT
         INNER JOIN IOART        IO ON NS.CODIOART   = IO.CODIOART
         LEFT  JOIN INTRPRODLINK L  ON I1.CODINTR1   = L.CODINTR1
    WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN
    GROUP BY C1.CODCOMANDA1,O.DENUMIRE,IO.DEN_IOART,NS.PRET,C.DATADOC,L.CODLINIECOMANDA;
    
    INSERT INTO TMP_TRASBC(CODCOMANDA1,MATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT)
    SELECT C1.CODCOMANDA1, O.DENUMIRE, IO.DEN_IOART,SUM(L1.CANT),SUM(NS.PRET*L1.CANT)/SUM(L1.CANT),SUM(L1.CANT*NS.PRET), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC),LI.CODCMDPRODMAT
    FROM COMANDA1 C1
         INNER JOIN COMANDA     C  ON C.CODCOMANDA  = C1.CODCOMANDA
         INNER JOIN IESIRI1     I1 ON I1.CODCMDINT1 = C1.CODCOMANDA1
         INNER JOIN IESIRI      I  ON I1.CODIES     = I.CODIES
         INNER JOIN LIVR        L  ON L.CODIES      = I.CODIES
         INNER JOIN LIVR1       L1 ON L.CODLIVR     = L1.CODLIVR AND L1.CODIES1 = I1.CODIES1
         INNER JOIN NIRSTOC     NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         INNER JOIN IOART       IO ON IO.CODIOART   = NS.CODIOART
         INNER JOIN NARTOBJ     O  ON O.CODOBIECT   = I1.CODOBIECT
         LEFT  JOIN IESPRODLINK LI ON I1.CODIES1    = LI.CODIES1
    WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN
    GROUP BY C1.CODCOMANDA1,O.DENUMIRE,IO.DEN_IOART,C.DATADOC,LI.CODCMDPRODMAT;

    INSERT INTO TMP_TRASRP(CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN)
    SELECT C1.CODCOMANDA1, O.DENUMIRE, SUM(R2.REALIZAT), SUM(T1.TARIF*R2.REALIZAT*R2.TU/60), 
           ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC),MAN.CODCMDPRODMAN
    FROM COMANDA1 C1
         INNER JOIN COMANDA     C   ON C.CODCOMANDA      = C1.CODCOMANDA
         INNER JOIN CMDPRODMAN  MAN ON MAN.CODCOMANDA1   = C1.CODCOMANDA1
         INNER JOIN MANPRODLINK L   ON MAN.CODCMDPRODMAN = L.CODCMDPRODMAN
         INNER JOIN RAPORTP2    R2  ON R2.CODRAPORTP2    = L.CODRAPORTP2
         INNER JOIN RAPORTP1    R1  ON R2.CODRAPORTP1    = R1.CODRAPORTP1
         INNER JOIN RAPORTP     R   ON R1.CODRAPORTP     = R.CODRAPORTP
         INNER JOIN NOPER       O   ON O.CODOP           = R2.CODOP
         INNER JOIN TARIFEMAN1  T1  ON T1.CODTARIF       = R2.CODTARIF AND (R.AN*12+R.LUNA) BETWEEN T1.ALSTART and T1.ALSTOP
    WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53 
          AND C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN 
    GROUP BY C1.CODCOMANDA1, O.DENUMIRE,C.DATADOC,MAN.CODCMDPRODMAN;
    
    COMMIT;
    
    FOR V_REC IN (SELECT C1.CODCOMANDA1 
                  FROM COMANDA1 C1
                       INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
                  WHERE C.DATADOC BETWEEN PKG_LIST_SELECTPERIOADA.DATAINI AND PKG_LIST_SELECTPERIOADA.DATAFIN AND C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0
                 ) LOOP
      SELECT COUNT(*) INTO CNP FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      SELECT COUNT(*) INTO CBC FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      SELECT COUNT(*) INTO CRP FROM TMP_TRASRP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
      if cnp &gt;= cbc and cnp &gt;= crp  then
        --cnp e cel mai mare
        --inserez
        INSERT INTO TMP_TRASCMDINT(COD,CODCOMANDA1,PRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS)
        SELECT COD,CODCOMANDA1,PRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS
        FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
        FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
                     FROM TMP_TRASBC
                     WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                    ) LOOP
          UPDATE TMP_TRASCMDINT 
          SET 
            MATERIAL      = V_BC.MATERIAL,
            IOARTMATERIAL = V_BC.IOARTMATERIAL,
            CANTMATERIAL  = V_BC.CANTMATERIAL,
            PRETMATERIAL  = V_BC.PRETMATERIAL,
            VALMATERIAL   = V_BC.VALMATERIAL,
            CODCMDPRODMAT = V_BC.CODCMDPRODMAT
          WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
        END LOOP;
        FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
                     FROM TMP_TRASRP
                     WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                    ) LOOP
          UPDATE TMP_TRASCMDINT 
          SET 
            OPERATIE      = V_RP.OPERATIE,
            NROP          = V_RP.NROP,
            VALOP         = V_RP.VALOP,
            CODCMDPRODMAN = V_RP.CODCMDPRODMAN
          WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
        END LOOP;
      else
        if cbc &gt;= cnp and cbc &gt;= crp  then
          --cnp e cel mai mare
          --inserez
          INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,MATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT)
          SELECT CODCOMANDA1,MATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
          FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
          FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                       FROM TMP_TRASNP
                       WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                      ) LOOP
            UPDATE TMP_TRASCMDINT 
            SET 
              PRODUS      = V_NP.PRODUS,
              IOARTPRODUS = V_NP.IOARTPRODUS,
              CANTPRODUS  = V_NP.CANTPRODUS,
              PRETPRODUS  = V_NP.PRETPRODUS,
              VALPRODUS   = V_NP.VALPRODUS
            WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
          END LOOP;
          FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
                       FROM TMP_TRASRP
                       WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                      ) LOOP
            UPDATE TMP_TRASCMDINT 
            SET 
              OPERATIE      = V_RP.OPERATIE,
              NROP          = V_RP.NROP,
              VALOP         = V_RP.VALOP,
              CODCMDPRODMAN = V_RP.CODCMDPRODMAN
            WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
          END LOOP;
        else
          if crp &gt;= cnp and crp &gt;= cbc  then
            --cnp e cel mai mare
            --inserez
            INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN)
            SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD,CODCMDPRODMAN
            FROM TMP_TRASrp WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
            FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD,CODCMDPRODMAT
                         FROM TMP_TRASBC
                         WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                        ) LOOP
              UPDATE TMP_TRASCMDINT 
              SET 
                MATERIAL      = V_BC.MATERIAL,
                IOARTMATERIAL = V_BC.IOARTMATERIAL,
                CANTMATERIAL  = V_BC.CANTMATERIAL,
                PRETMATERIAL  = V_BC.PRETMATERIAL,
                VALMATERIAL   = V_BC.VALMATERIAL,
                CODCMDPRODMAT = V_BC.CODCMDPRODMAT
              WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
            END LOOP;
            FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                         FROM TMP_TRASNP
                         WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                        ) LOOP
              UPDATE TMP_TRASCMDINT 
              SET 
                PRODUS      = V_NP.PRODUS,
                IOARTPRODUS = V_NP.IOARTPRODUS,
                CANTPRODUS  = V_NP.CANTPRODUS,
                PRETPRODUS  = V_NP.PRETPRODUS,
                VALPRODUS   = V_NP.VALPRODUS
              WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
            END LOOP;
          end if;  
        end if;  
      end if;
    END LOOP;
  end if;  
  COMMIT;
END;

PROCEDURE TEST IS
cnp number(10);
cbc number(10);
crp number(10);  
BEGIN
  PRC_AL_CHECK(&apos;TARIFEMAN1&apos;);
  
  DELETE TMP_TRASCMDINT;
  DELETE TMP_TRASNP;
  DELETE TMP_TRASBC;
  DELETE TMP_TRASRP;
  INSERT INTO TMP_TRASNP(CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD)
  SELECT C1.CODCOMANDA1,O.DENUMIRE,SER.SERIE,IO.DEN_IOART,SUM(NSE.CANTNIR),NS.PRET,SUM(NSE.CANTNIR*NS.PRET), 
         ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC)
  FROM COMANDA1 C1
       INNER JOIN COMANDA  C   ON C1.CODCOMANDA  = C.CODCOMANDA
       INNER JOIN INTRARI1 I1  ON I1.CODCMDINT1  = C1.CODCOMANDA1
       INNER JOIN INTRARI  I   ON I1.CODINTR     = I.CODINTR
       INNER JOIN NIR          ON I.CODINTR      = NIR.CODINTR
       INNER JOIN NIRSTOC  NS  ON NS.CODNIR      = NIR.CODNIR AND I1.CODINTR1 = NS.CODINTR1
       INNER JOIN NARTOBJ  O   ON I1.CODOBIECT   = O.CODOBIECT
       INNER JOIN IOART    IO  ON NS.CODIOART    = IO.CODIOART
       LEFT  JOIN NIRSER   NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
       LEFT  JOIN NSERII   SER ON SER.CODSERIE   = NSE.CODSERIE
  WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
        AND C.DATADOC BETWEEN TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;) AND TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;)
  GROUP BY C1.CODCOMANDA1,O.DENUMIRE,SER.SERIE,IO.DEN_IOART,NS.PRET,C.DATADOC;
  
  INSERT INTO TMP_TRASBC(CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD)
  SELECT C1.CODCOMANDA1, O.DENUMIRE, SER.SERIE,IO.DEN_IOART,SUM(L1.CANT),NS.PRET,SUM(L1.CANT*NS.PRET), 
         ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC)
  FROM COMANDA1 C1
       INNER JOIN COMANDA C   ON C.CODCOMANDA  = C1.CODCOMANDA
       INNER JOIN IESIRI1 I1  ON I1.CODCMDINT1 = C1.CODCOMANDA1
       INNER JOIN IESIRI  I   ON I1.CODIES     = I.CODIES
       INNER JOIN LIVR    L   ON L.CODIES      = I.CODIES
       INNER JOIN LIVR1   L1  ON L.CODLIVR     = L1.CODLIVR AND L1.CODIES1 = I1.CODIES1
       INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
       INNER JOIN IOART   IO  ON IO.CODIOART   = NS.CODIOART
       INNER JOIN NARTOBJ O   ON O.CODOBIECT   = I1.CODOBIECT
       LEFT  JOIN NIRSER  NSE ON NSE.CODNIRSER = L1.CODNIRSER
       LEFT  JOIN NSERII  SER ON SER.CODSERIE  = NSE.CODSERIE
  WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
        AND C.DATADOC BETWEEN TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;) AND TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;)
  GROUP BY C1.CODCOMANDA1,O.DENUMIRE,SER.SERIE,IO.DEN_IOART,NS.PRET,C.DATADOC;

  INSERT INTO TMP_TRASRP(CODCOMANDA1,OPERATIE,NROP,VALOP,COD)
  SELECT C1.CODCOMANDA1, O.DENUMIRE, SUM(R2.REALIZAT), SUM(T1.TARIF*R2.REALIZAT*R2.TU/60), 
         ROW_NUMBER() OVER (PARTITION BY C1.CODCOMANDA1 ORDER BY C.DATADOC)
  FROM COMANDA1 C1
       INNER JOIN COMANDA     C   ON C.CODCOMANDA      = C1.CODCOMANDA
       INNER JOIN CMDPRODMAN  MAN ON MAN.CODCOMANDA1   = C1.CODCOMANDA1
       INNER JOIN MANPRODLINK L   ON MAN.CODCMDPRODMAN = L.CODCMDPRODMAN
       INNER JOIN RAPORTP2    R2  ON R2.CODRAPORTP2    = L.CODRAPORTP2
       INNER JOIN RAPORTP1    R1  ON R2.CODRAPORTP1    = R1.CODRAPORTP1
       INNER JOIN RAPORTP     R   ON R1.CODRAPORTP     = R.CODRAPORTP
       INNER JOIN NOPER       O   ON O.CODOP           = R2.CODOP
       INNER JOIN TARIFEMAN1  T1  ON T1.CODTARIF       = R2.CODTARIF AND (R.AN*12+R.LUNA) BETWEEN T1.ALSTART and T1.ALSTOP
  WHERE C.ANULAT = 0 AND C.OPERAT = 1 AND C.TIPDOC = 53
        AND C.DATADOC BETWEEN TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;) AND TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;)
  GROUP BY C1.CODCOMANDA1, O.DENUMIRE,C.DATADOC;
  
  COMMIT;
  
  FOR V_REC IN (SELECT C1.CODCOMANDA1 
                FROM COMANDA1 C1
                     INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
                WHERE C.DATADOC BETWEEN TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;) AND TO_DATE(&apos;01.03.2019&apos;,&apos;DD.MM.YYYY&apos;) AND C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0
               ) LOOP
    SELECT COUNT(*) INTO CNP FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
    SELECT COUNT(*) INTO CBC FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
    SELECT COUNT(*) INTO CRP FROM TMP_TRASRP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1;
    if cnp &gt;= cbc and cnp &gt;= crp  then
      --cnp e cel mai mare
      --inserez
      INSERT INTO TMP_TRASCMDINT(COD,CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS)
      SELECT COD,CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS
      FROM TMP_TRASNP WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
      FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD
                   FROM TMP_TRASBC
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          MATERIAL      = V_BC.MATERIAL,
          SERIEMATERIAL = V_BC.SERIEMATERIAL,
          IOARTMATERIAL = V_BC.IOARTMATERIAL,
          CANTMATERIAL  = V_BC.CANTMATERIAL,
          PRETMATERIAL  = V_BC.PRETMATERIAL,
          VALMATERIAL   = V_BC.VALMATERIAL
        WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
      END LOOP;
      FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD
                   FROM TMP_TRASRP
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          OPERATIE = V_RP.OPERATIE,
          NROP     = V_RP.NROP,
          VALOP    = V_RP.VALOP
        WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
      END LOOP;
    end if;
    if cbc &gt;= cnp and cbc &gt;= crp  then
      --cnp e cel mai mare
      --inserez
      INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD)
      SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD
      FROM TMP_TRASBC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
      FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                   FROM TMP_TRASNP
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          PRODUS      = V_NP.PRODUS,
          SERIEPRODUS = V_NP.SERIEPRODUS,
          IOARTPRODUS = V_NP.IOARTPRODUS,
          CANTPRODUS  = V_NP.CANTPRODUS,
          PRETPRODUS  = V_NP.PRETPRODUS,
          VALPRODUS   = V_NP.VALPRODUS
        WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
      END LOOP;
      FOR V_RP IN (SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD
                   FROM TMP_TRASRP
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          OPERATIE = V_RP.OPERATIE,
          NROP     = V_RP.NROP,
          VALOP    = V_RP.VALOP
        WHERE CODCOMANDA1 = V_RP.CODCOMANDA1 AND COD = V_RP.COD;
      END LOOP;
    end if;
    if crp &gt;= cnp and crp &gt;= cbc  then
      --cnp e cel mai mare
      --inserez
      INSERT INTO TMP_TRASCMDINT(CODCOMANDA1,OPERATIE,NROP,VALOP,COD)
      SELECT CODCOMANDA1,OPERATIE,NROP,VALOP,COD
      FROM TMP_TRASrp WHERE CODCOMANDA1 = V_REC.CODCOMANDA1; 
      FOR V_BC IN (SELECT CODCOMANDA1,MATERIAL,SERIEMATERIAL,IOARTMATERIAL,CANTMATERIAL,PRETMATERIAL,VALMATERIAL,COD
                   FROM TMP_TRASBC
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          MATERIAL      = V_BC.MATERIAL,
          SERIEMATERIAL = V_BC.SERIEMATERIAL,
          IOARTMATERIAL = V_BC.IOARTMATERIAL,
          CANTMATERIAL  = V_BC.CANTMATERIAL,
          PRETMATERIAL  = V_BC.PRETMATERIAL,
          VALMATERIAL   = V_BC.VALMATERIAL
        WHERE CODCOMANDA1 = V_BC.CODCOMANDA1 AND COD = V_BC.COD;
      END LOOP;
      FOR V_NP IN (SELECT CODCOMANDA1,PRODUS,SERIEPRODUS,IOARTPRODUS,CANTPRODUS,PRETPRODUS,VALPRODUS,COD
                   FROM TMP_TRASNP
                   WHERE CODCOMANDA1 = V_REC.CODCOMANDA1
                  ) LOOP
        UPDATE TMP_TRASCMDINT 
        SET 
          PRODUS      = V_NP.PRODUS,
          SERIEPRODUS = V_NP.SERIEPRODUS,
          IOARTPRODUS = V_NP.IOARTPRODUS,
          CANTPRODUS  = V_NP.CANTPRODUS,
          PRETPRODUS  = V_NP.PRETPRODUS,
          VALPRODUS   = V_NP.VALPRODUS
        WHERE CODCOMANDA1 = V_NP.CODCOMANDA1 AND COD = V_NP.COD;
      END LOOP;
    end if;
  END LOOP;
  COMMIT;
END;  

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_TRASCMDINT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASEELIVRARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6EFE746B32E27BFEBEDE44F3AE762827B21524F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_traseelivrare IS

PROCEDURE SetParams IS
BEGIN
  null;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(&apos;&apos;);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE InsertRec(tmpName IN VARCHAR2, vLine TMP_LST_PREGLIVR%ROWTYPE, aMasa IN NUMBER, aVolum IN NUMBER) IS
  sInsert VARCHAR2(4000);
BEGIN
  sInsert :=
  &apos;INSERT INTO &apos; || tmpName || &apos;(
     Traseu, PozTraseu, Client, SerieDoc, NrDoc, DataDoc, Sofer, MijlTransp, NrTransp,
     MasaDoc, VolumDoc, MasaTraseu, VolumTraseu, MasaUtila, VolumUtil,
     CodTraseu, LungTransp, LatTransp, InaltTransp)
  VALUES (
    :Traseu, :PozTraseu, :Client, :SerieDoc, :NrDoc, :DataDoc, :Sofer, :MijlTransp, :NrTransp,
    :MasaDoc, :VolumDoc, :MasaTraseu, :VolumTraseu, :MasaUtila, :VolumUtil,
    :CodTraseu, :LungTransp, :LatTransp, :InaltTransp )&apos;;

  EXECUTE IMMEDIATE sInsert
  USING
    vLine.Traseu, vLine.PozTraseu, vLine.Client, vLine.SerieDoc, vLine.NrDoc, vLine.DataDoc, vLine.Sofer, vLine.MijlTransp, vLine.NrTransp,
    vLine.MasaDoc, vLine.VolumDoc, aMasa, aVolum, vLine.MasaUtila, vLine.VolumUtil,
    vLine.CodTraseu, vLine.LungTransp, vLine.LatTransp, vLine.InaltTransp;

  COMMIT;

END;

PROCEDURE ProcessList(tmpName IN VARCHAR2, aListID IN NUMBER DEFAULT 0, aListVer IN NUMBER DEFAULT 0) IS
  sSQL   VARCHAR2(4000);
  sCrs   tCURSOR_PREGLIVR;
  vLine  TMP_LST_PREGLIVR%ROWTYPE;
  lMasa  NUMBER(20,7);
  lVolum NUMBER(20,7);
BEGIN
  sSQL :=
  &apos;SELECT
  	TL.DenTraseu Traseu, TTC.PozTraseu, DECODE(C.TipDoc,18,P.Den_Part,43,G.Den_Gest,44,S.Den_Subunit) Client, C.SeriaDoc SerieDoc, C.NrDoc, C.DataDoc,
    NumePrenume( PERS.Prenume, PERS.Nume) Sofer, A.Den_Articol MijlTransp, PA.NrInreg,
    SUM(TTC.Masa) MasaDoc, SUM(TTC.Volum) VolumDoc, 0 MasaTraseu, 0 VolumTraseu, PA.MasaU MasaUtila, PA.VolumU VolumUtil,
    TL.CodTraseuLivr CodTraseu, PA.Lung LungTransp, PA.Lat LatTransp, PA.Inalt InaltTransp
	FROM TMP_TraseuLivr_Comenzi TTC
    LEFT JOIN TraseuLivr TL ON TL.CodTraseuLivr = TTC.CodTraseu
    LEFT JOIN Comanda C ON C.CodComanda = TTC.CodComanda
    LEFT JOIN NPart P ON P.CodPart = TTC.CodClient
    LEFT JOIN NSubunit S ON S.CodSubunit = C.Subunitatea
    LEFT JOIN NGest G ON G.CodGest = C.CodGest
    LEFT JOIN NParcAut PA on PA.CodNParcAut = TTC.CodMijlTransp
    LEFT JOIN NArtObj AO ON AO.CodObiect = PA.CodArt
    LEFT JOIN NArt A ON A.CodArticol = AO.CodArticol
    LEFT JOIN NPers PERS ON PERS.CodPers = PA.Sofer
  GROUP BY
    TL.DenTraseu, TTC.PozTraseu, DECODE(C.TipDoc,18,P.Den_Part,43,G.Den_Gest,44,S.Den_Subunit), C.SeriaDoc, C.NrDoc, C.DataDoc,
    PERS.Prenume, PERS.Nume, A.Den_Articol, PA.NrInreg, PA.MasaU, PA.VolumU, TL.CodTraseuLivr, PA.Lung, PA.Lat, PA.Inalt&apos;;

  OPEN sCrs FOR sSQL;
  FETCH sCrs INTO vLine;
  WHILE sCrs%FOUND LOOP

    SELECT SUM(NVL(Masa, 0)), SUM(NVL(Volum, 0)) INTO lMasa, lVolum FROM TMP_TraseuLivr_Comenzi WHERE CodTraseu = vLine.CodTraseu;
    InsertRec(tmpName, vLine, lMasa, lVolum);
    FETCH sCrs INTO vLine;

  END LOOP;

  COMMIT;
END;

END PKG_LIST_BASE_TRASEELIVRARE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>920BAC124EF77221762D17F8F6B61ED464C00AFC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRASFACT IS

vCodDistrib DISTRIB.CODDISTRIB%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDistrib IN NUMBER) IS
BEGIN
  vCodDistrib := pCodDistrib;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;iesiri i, nagenda ag, traseulivr tl&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos;
   (DENPERS,
    NRINREG,
    DENTRASEU,
    PREFIXDOC,
    NRDOC,
    DATADOC,
    DEN_PART,
    VALDOC,
    SERIEDOC,
    SIMBOLMONEDA,
    ORA,
    DENTRASEUP &apos;||gUserFields||&apos;)
    SELECT
      df.DEN_PERS,
      i.nrtransp,
      d1.dentraseu,
      df.PREFIXDOC,
      df.NRDOC,
      i.DATADOC,
      df.Den_Part,
      df.ValDoc,
      df.seriedoc,
      df.simbolmoneda,
      df.ora,
      TL.DENTRASEU &apos;||gUserAlias||&apos;
    FROM tmp_distrib_fact df
         inner join iesiri i on df.codies = i.codies
         left  join tmp_distrib1 d1 on i.agent = d1.codpers
         inner join tmp_manevra_liste man on d1.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos;
         left  join nagenda ag on i.codlocatie = ag.codagenda
         left  join traseulivr TL on ag.codtraseu = tl.codtraseulivr&apos;||
         gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;

END;

end pkg_list_base_trasfact;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASFACTINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC3832C040DD534C525A7D2821DB0637F534768F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRASFACTINC IS

  vCodDistrib DISTRIB.CODDISTRIB%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataS       DATE;
  vDataF       DATE;

PROCEDURE SETPARAMS( pCodDistrib IN NUMBER)  IS
BEGIN
  vCodDistrib := pCodDistrib;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(1000);
  sWith      VARCHAR2(32000);
  sSelect    VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;npart p&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos;
   (DENPERSF,
    NRINREGF,
    DENTRASEUF,
    PREFIXDOCF,
    NRDOCF,
    DATADOCF,
    DEN_PART,
    VALDOCF,
    SERIEDOCF,
    SIMBOLMONEDA,
    ORAF,
    DENTRASEUP,
    DENPERSI,
    NRINREGI,
    DENTRASEUI,
    PREFIXDOCI,
    NRDOCI,
    DATADOCI,
    VALDOCI,
    SERIEDOCI,
    ORAI,
    DENTRASEU,
    SOLDPART,
    SEDIU  &apos;||gUserFields||&apos;)&apos;;

  sWith := &apos;with st_in_zi as ( &apos;||
    &apos;select di.codtrezor1, i.codies &apos;||
    &apos;from &apos;||
      &apos;tmp_distrib_inc di &apos;||
      &apos;inner join trezor1 t1 on di.codtrezor1 = t1.codtrezor1 &apos;||
      &apos;inner join trezor t on t1.codtrezor = t.codtrezor &apos;||
      &apos;inner join general gi on gi.coddoc = t1.codtrezor1 and gi.tipdoc = t.tipdoc &apos;||
      &apos;inner join obligpif oi on oi.codgeneral = gi.codgeneral &apos;||
      &apos;inner join stingere st on st.codstingatorpif = oi.codobligpif &apos;||
      &apos;inner join obligpif ofact on st.codstinspif = ofact.codobligpif &apos;||
      &apos;inner join general gf on ofact.codgeneral = gf.codgeneral &apos;||
      &apos;inner join iesiri i on gf.coddoc = i.codies and gf.tipdoc = i.tipdoc &apos;||
      &apos;inner join tmp_distrib_fact df on df.codies = i.codies) &apos;;
  sWith := sWith||&apos;, st_alta_zi as ( &apos;||
    &apos;select di.codtrezor1, i.codies &apos;||
    &apos;from &apos;||
      &apos;tmp_distrib_inc di &apos;||
      &apos;inner join trezor1 t1 on di.codtrezor1 = t1.codtrezor1 &apos;||
      &apos;inner join trezor t on t1.codtrezor = t.codtrezor &apos;||
      &apos;inner join general gi on gi.coddoc = t1.codtrezor1 and gi.tipdoc = t.tipdoc &apos;||
      &apos;inner join obligpif oi on oi.codgeneral = gi.codgeneral &apos;||
      &apos;inner join stingere st on st.codstingatorpif = oi.codobligpif &apos;||
      &apos;inner join obligpif ofact on st.codstinspif = ofact.codobligpif &apos;||
      &apos;inner join general gf on ofact.codgeneral = gf.codgeneral &apos;||
      &apos;inner join iesiri i on gf.coddoc = i.codies and gf.tipdoc = i.tipdoc &apos;||
    &apos;where not exists (select df.codies from tmp_distrib_fact df where df.codies = i.codies)) &apos;;

  sWith := sWith||&apos;, docs as (SELECT &apos;||
      &apos;i.codies, &apos;||
      &apos;i.codlocatie, &apos;||
      &apos;df.DEN_PERS denpersf, &apos;||
      &apos;i.nrtransp nrinregf, &apos;||
      &apos;d1f.dentraseu dentraseuf, &apos;||
      &apos;df.PREFIXDOC prefixdocf, &apos;||
      &apos;df.NRDOC nrdocf, &apos;||
      &apos;i.DATADOC datadocf, &apos;||
      &apos;df.Den_Part, &apos;||
      &apos;df.ValDoc valdocf, &apos;||
      &apos;df.seriedoc seriedocf, &apos;||
      &apos;df.simbolmoneda, &apos;||
      &apos;df.ora oraf, &apos;||
      &apos;TL.DENTRASEU dentraseuP, &apos;||
      &apos;di.DEN_PERS denpersi, &apos;||
      &apos;d1i.nrinreg nrinregi, &apos;||
      &apos;d1i.dentraseu dentraseui, &apos;||
      &apos;di.PREFIXDOC prefixdoci, &apos;||
      &apos;di.NRDOC nrdoci, &apos;||
      &apos;di.DATADOC datadoci, &apos;||
      &apos;di.ValDoc valdoci, &apos;||
      &apos;di.seriedoc seriedoci, &apos;||
      &apos;di.ora orai, &apos;||
      &apos;TZ.DENTRASEU, &apos;||
      &apos;nvl(d2.sold, 0) SOLDPART, &apos;||
      &apos;df.codpers, &apos;||
      &apos;i.partener &apos;||
    &apos; FROM tmp_distrib_fact df &apos;||
         &apos;inner join st_in_zi st on df.codies = st.codies &apos;||
         &apos;inner join tmp_distrib_inc di on di.codtrezor1 = st.codtrezor1 &apos;||
         &apos;inner join iesiri i on df.codies = i.codies &apos;||
         &apos;inner join tmp_distrib1 d1f on i.agent = d1f.codpers &apos;||
         &apos;inner join nagenda ag on i.codlocatie = ag.codagenda &apos;||
         &apos;inner join traseulivr TL on ag.codtraseu = tl.codtraseulivr &apos;||
         &apos;inner join trezor1 t1 on di.codtrezor1 = t1.codtrezor1 &apos;||
         &apos;inner join trezor t on t1.codtrezor = t.codtrezor &apos;||
         &apos;inner join tmp_distrib1 d1i on di.CodPers = d1i.codpers &apos;||
         &apos;inner join tmp_manevra_liste man on d1i.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;                                 and df.codpers = man.valoare1 and man.filtru1 = &apos;&apos;CODPERS&apos;&apos; &apos;||
         &apos;inner join traseulivr TZ on man.valoare = TZ.CodTraseuLivr and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;inner join tmp_distrib2 d2 on d2.codpart = i.partener and i.codlocatie = d2.codagenda &apos;;

  sWith := sWith||&apos;UNION ALL &apos;||
    &apos;SELECT &apos;||
      &apos;i.codies, &apos;||
      &apos;i.codlocatie, &apos;||
      &apos;df.DEN_PERS denpersf, &apos;||
      &apos;i.nrtransp nrinregf, &apos;||
      &apos;d1f.dentraseu dentraseuf, &apos;||
      &apos;df.PREFIXDOC prefixdocf, &apos;||
      &apos;df.NRDOC nrdocf, &apos;||
      &apos;i.DATADOC datadocf, &apos;||
      &apos;df.Den_Part, &apos;||
      &apos;df.ValDoc valdocf, &apos;||
      &apos;df.seriedoc seriedocf, &apos;||
      &apos;df.simbolmoneda, &apos;||
      &apos;df.ora oraf, &apos;||
      &apos;TL.DENTRASEU DENTRASEUP, &apos;||
      &apos;null DENPERSI, &apos;||
      &apos;null NRINREGI, &apos;||
      &apos;null DENTRASEUI, &apos;||
      &apos;null PREFIXDOCI, &apos;||
      &apos;null NRDOCI, &apos;||
      &apos;null DATADOCI, &apos;||
      &apos;null VALDOCI, &apos;||
      &apos;null SERIEDOCI, &apos;||
      &apos;null ORAI, &apos;||
      &apos;TZ.DENTRASEU, &apos;||
      &apos;nvl(d2.sold, 0) SOLDPART, &apos;||
      &apos;df.codpers, &apos;||
      &apos;i.partener &apos;||
    &apos; FROM tmp_distrib_fact df &apos;||
         &apos;left join iesiri i on df.codies = i.codies &apos;||
         &apos;left join tmp_distrib1 d1f on i.agent = d1f.codpers &apos;||
         &apos;left join nagenda ag on i.codlocatie = ag.codagenda &apos;||
         &apos;left join traseulivr TL on ag.codtraseu = tl.codtraseulivr &apos;||
         &apos;left join tmp_manevra_liste man on d1f.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;                                 and df.codpers = man.valoare1 and man.filtru1 = &apos;&apos;CODPERS&apos;&apos; &apos;||
         &apos;left join traseulivr TZ on man.valoare = TZ.CodTraseuLIVR and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;left join tmp_distrib2 d2 on d2.codpart = i.partener and i.codlocatie = d2.codagenda &apos;||
    &apos;where not exists (select st.codies from st_in_zi st where st.codies = i.codies) &apos;;

    --sInsert := sInsert||&apos; WHERE D.CodDistrib = &apos;||vCodDistrib;

  sWith := sWith||&apos;UNION ALL &apos;||
    &apos;SELECT &apos;||
      &apos;i.codies, &apos;||
      &apos;i.codlocatie, &apos;||
      &apos;pers.NUME||&apos;&apos; &apos;&apos;||pers.prenume denpersf, &apos;||
      &apos;i.nrtransp nrinregf, &apos;||
      &apos;TL.DENTRASEU dentraseuf, &apos;||
      &apos;i.PREFIXDOC prefixdocf, &apos;||
      &apos;i.NRDOC nrdocf, &apos;||
      &apos;i.DATADOC datadocf, &apos;||
      &apos;part.Den_Part, &apos;||
      &apos;i.ValDoc valdocf, &apos;||
      &apos;doc.serie, &apos;||
      &apos;mon.simbol, &apos;||
      &apos;case
         when EXTRACT(HOUR FROM i.datainreg) &lt; 10 then &apos;&apos;0&apos;&apos;||to_char(EXTRACT(HOUR FROM i.datainreg))
         else to_char(EXTRACT(HOUR FROM i.datainreg))
       end||&apos;&apos;:&apos;&apos;||
       case
         when EXTRACT(MINUTE FROM i.datainreg) &lt; 10 then &apos;&apos;0&apos;&apos;||to_char(EXTRACT(MINUTE FROM i.datainreg))
         else to_char(EXTRACT(MINUTE FROM i.datainreg))
       end||&apos;&apos;:&apos;&apos;||
       case
         when EXTRACT(SECOND FROM i.datainreg) &lt; 10 then &apos;&apos;0&apos;&apos;||to_char(EXTRACT(SECOND FROM i.datainreg))
         else to_char(EXTRACT(SECOND FROM i.datainreg))
       end oraf, &apos;||
      &apos;TL.DENTRASEU dentraseui, &apos;||
      &apos;di.DEN_PERS denpersi, &apos;||
      &apos;d1i.nrinreg nrinregi, &apos;||
      &apos;d1i.dentraseu dentraseui, &apos;||
      &apos;di.PREFIXDOC prefixdoci, &apos;||
      &apos;di.NRDOC nrdoci, &apos;||
      &apos;di.DATADOC datadoci, &apos;||
      &apos;di.ValDoc valdoci, &apos;||
      &apos;di.seriedoc seriedoci, &apos;||
      &apos;EXTRACT(HOUR FROM T.DataInreg)||&apos;&apos; : &apos;&apos;|| EXTRACT(MINUTE FROM T.DataInreg)||&apos;&apos; : &apos;&apos;||EXTRACT(SECOND FROM T.DataInreg) orai, &apos;||
      &apos;TZ.DENTRASEU, &apos;||
      &apos;nvl(d2.sold, 0) SOLDPART, &apos;||
      &apos;di.codpers, &apos;||
      &apos;i.partener &apos;||
    &apos; FROM tmp_distrib_inc di &apos;||
         &apos;inner join st_alta_zi st on di.codtrezor1 = st.codtrezor1 &apos;||
         &apos;inner join iesiri i on st.codies = i.codies &apos;||
         &apos;inner join doccarnete doc on doc.codcarnet = i.carnetdoc &apos;||
         &apos;inner join npart part on i.partener = part.codpart &apos;||
         &apos;inner join nmonede mon on mon.codmoneda = i.moneda &apos;||
         &apos;inner join nagenda ag on i.codlocatie = ag.codagenda &apos;||
         &apos;inner join traseulivr TL on ag.codtraseu = tl.codtraseulivr &apos;||
         &apos;inner join trezor1 t1 on di.codtrezor1 = t1.codtrezor1 &apos;||
         &apos;inner join trezor t on t1.codtrezor = t.codtrezor &apos;||
         &apos;inner join tmp_distrib1 d1i on di.CodPers = d1i.codpers &apos;||
         &apos;inner join tmp_manevra_liste man on d1i.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;                                 and di.codpers = man.valoare1 and man.filtru1 = &apos;&apos;CODPERS&apos;&apos; &apos;||
         &apos;inner join traseulivr TZ on man.valoare = TZ.CodTraseuLivr and man.filtru = &apos;&apos;CODTRASEU&apos;&apos; &apos;||
         &apos;left  join npers pers on i.agent = pers.codpers &apos;||
         &apos;left  join tmp_distrib2 d2 on d2.codpart = i.partener and i.codlocatie = d2.codagenda  ) &apos;;

  sSelect := &apos;select
                docs.DENPERSF,
                docs.NRINREGF,
                docs.DENTRASEUF,
                docs.PREFIXDOCF,
                docs.NRDOCF,
                docs.DATADOCF,
                p.DEN_PART,
                docs.VALDOCF,
                docs.SERIEDOCF,
                docs.SIMBOLMONEDA,
                docs.ORAF,
                docs.DENTRASEUP,
                docs.DENPERSI,
                docs.NRINREGI,
                docs.DENTRASEUI,
                docs.PREFIXDOCI,
                docs.NRDOCI,
                docs.DATADOCI,
                docs.VALDOCI,
                docs.SERIEDOCI,
                docs.ORAI,
                tmp1.DENTRASEU,
                tmp2.SOLD,
                tmp2.obs SEDIU &apos;||gUserAlias||
             &apos; from docs
                   inner join tmp_distrib1 tmp1 on tmp1.codpers = docs.codpers
                   inner join tmp_manevra_liste man on tmp1.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos;
                                                    and tmp1.codpers = man.valoare1 and man.filtru1 = &apos;&apos;CODPERS&apos;&apos;
                   left join tmp_distrib2 tmp2 on tmp1.coddistrib1 = tmp1.coddistrib1 and tmp2.codagenda = docs.codlocatie
                   left join npart p on docs.partener = p.codpart&apos;||
                   gSuplJoins||&apos;
              union all
              select
                tmp1.DENPERS DENPERSF,
                null NRINREGF,
                null DENTRASEUF,
                null PREFIXDOCF,
                null NRDOCF,
                null DATADOCF,
                p.DEN_PART,
                null VALDOCF,
                null SERIEDOCF,
                null SIMBOLMONEDA,
                null ORAF,
                null DENTRASEUP,
                null DENPERSI,
                null NRINREGI,
                null DENTRASEUI,
                null PREFIXDOCI,
                null NRDOCI,
                null DATADOCI,
                null VALDOCI,
                null SERIEDOCI,
                null ORAI,
                tmp1.DENTRASEU,
                tmp2.SOLD,
                tmp2.obs SEDIU &apos;||gUserAlias||
            &apos; from tmp_distrib2 tmp2
                   inner join tmp_distrib1 tmp1 on tmp1.coddistrib1 = tmp2.coddistrib1
                   inner join tmp_manevra_liste man on tmp1.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos;
                                                   and tmp1.codpers = man.valoare1 and man.filtru1 = &apos;&apos;CODPERS&apos;&apos;
                   left join npart p on tmp2.codpart = p.codpart
                   left join docs on tmp2.codagenda = docs.codlocatie&apos;||
                   gSuplJoins||&apos;
               where nvl(docs.codies, 0) = 0 &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sWith||sSelect, aListID, aListVer);

  COMMIT;

END;

end pkg_list_base_trasfactinc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D955ED6CDBB190408B40E93D0BF6B13BF53489A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRASINC IS

  vCodDistrib DISTRIB.CODDISTRIB%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDistrib IN NUMBER)  IS
BEGIN
  vCodDistrib := pCodDistrib;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;trezor1 t1, trezor t, iesiri i, nagenda ag, traseulivr tl&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos;
   (DENPERS,
    NRINREG,
    DENTRASEU,
    PREFIXDOC,
    NRDOC,
    DATADOC,
    DEN_PART,
    VALDOC,
    SERIEDOC,
    SIMBOLMONEDA,
    ORA,
    PREFIXDOCS,
    NRDOCS,
    DATADOCS,
    VALDOCS,
    DENTRASEUS
   &apos;||gUserFields||&apos;)
    SELECT
      di.DEN_PERS,
      d1.nrinreg,
      d1.dentraseu,
      di.PREFIXDOC,
      di.NRDOC,
      di.DATADOC,
      di.Den_Part,
      di.ValDoc,
      di.seriedoc,
      di.simbolmoneda,
      di.ora,
      i.prefixdoc,
      i.nrdoc,
      i.datadoc,
      i.valdoc,
      tl.dentraseu
       &apos;||gUserAlias||&apos;
    FROM tmp_distrib_inc di
         inner join trezor1 t1 on di.codtrezor1 = t1.codtrezor1
         inner join trezor t on t1.codtrezor = t.codtrezor
         left  join tmp_distrib1 d1 on di.CodPers = d1.codpers
         inner join tmp_manevra_liste man on d1.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos;
         inner join general gt on gt.coddoc = t1.codtrezor1 and gt.tipdoc = t.tipdoc
         inner join obligpif ostingator on gt.codgeneral = ostingator.codgeneral
         inner join stingere st on ostingator.codobligpif = st.codstingatorpif
         inner join obligpif ostins on st.codstinspif = ostins.codobligpif
         inner join general gs on gs.codgeneral = ostins.codgeneral
         inner join iesiri i on i.codies = gs.coddoc and i.tipdoc = gs.tipdoc
         inner join nagenda ag on i.codlocatie = ag.codagenda
         inner join traseulivr tl on tl.codtraseulivr = ag.codtraseu
         &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;

END;

end pkg_list_base_trasinc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_TRASPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C11C68D771003F923F1DD8155E6B976C809EBB92</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_TRASPART IS

  vCodDistrib DISTRIB.CODDISTRIB%TYPE;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pCodDistrib  IN NUMBER) IS
BEGIN
  vCodDistrib := pCodDistrib;
END;

function GetStatusPart(vCodDistrib2 IN NUMBER, vAn IN NUMBER, vLuna IN NUMBER) return VARCHAR2 IS
aCount NUMBER(10);
begin
  select Count(*) into aCount from tmp_distrib3 where coddistrib2 = vCodDistrib2;
  if aCount = 0 then
    Return &apos;SOLD 0&apos;;
  else
    select Count(*) into aCount from tmp_distrib3
    where coddistrib2 = vCodDistrib2
    and NVL(ZILESCADENTE, 0) &gt; to_number(nvl(pkg_categconst.GetValConstanta(&apos;ZileDepasireAccept&apos;, vAn, vLuna), &apos;0&apos;));
    if aCount &gt; 0 then
      Return &apos;BLOCAT&apos;;
    else
      Return &apos;DEBITOR&apos;;
    end if;
  end if;
end;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;tmp_distrib d&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
   &apos;INSERT INTO &apos;||TMPNAME||&apos;
   (DENPERS,
    NRINREG,
    DENTRASEU,
    SOLD,
    POZTRASEU,
    DEN_PART,
    OBS,
    ADRESA,
    DEN_JUDET,
    DEN_LOCALIT,
    DOC,
    PREFIXDOC,
    NRDOC,
    DATADOC,
    VALREAL,
    RESTREAL,
    TERMEN,
    ZILESCADENTE,
    STATUS
   &apos;||gUserFields||&apos;)
    SELECT
      d1.DENPERS,
      d1.NRINREG,
      d1.DENTRASEU,
      d2.SOLD,
      d2.POZTRASEU,
      d2.DEN_PART,
      d2.OBS,
      d2.ADRESA,
      d2.DEN_JUDET,
      d2.DEN_LOCALIT,
      d3.DOC,
      d3.PrefixDoc,
      d3.NRDOC,
      d3.DATADOC,
      d3.VALREAL,
      d3.RESTREAL,
      d3.TERMEN,
      d3.ZILESCADENTE,
      PKG_LIST_BASE_TRASPART.GetStatusPart(d2.coddistrib2, d.an, d.luna)&apos;||gUserAlias||&apos;
    FROM tmp_distrib d
         left JOIN tmp_distrib1 d1 ON d.Coddistrib = d1.Coddistrib
         inner join tmp_manevra_liste man on d1.codtraseu = man.valoare and man.filtru = &apos;&apos;CODTRASEU&apos;&apos;
         left JOIN tmp_distrib2 d2 on d1.Coddistrib1 = d2.coddistrib1
         left JOIN tmp_distrib3 d3 ON d2.Coddistrib2 = d3.Coddistrib2&apos;||
         gSuplJoins;
    sInsert := sInsert||&apos; WHERE D.CodDistrib = &apos;||vCodDistrib;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

end pkg_list_base_traspart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMAECLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A71093C9F7CEF0C6290FD5D90D3A22FDC008C5F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmaecli IS

  vStornoAvize NUMBER;
  vAnF         NUMBER;
  vLunaF       NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
FUNCTION GetValAchiz(
  aCodIes1 IN NUMBER,
  aCantF   IN NUMBER DEFAULT 0,
  aAnF     IN NUMBER DEFAULT 0,
  aLunaF   IN NUMBER DEFAULT 0
) RETURN NUMBER IS
  aVal  NUMBER(20,7);
  aCant NUMBER(20,7);
BEGIN
  SELECT Nvl(sum(l1.cant * (ns.pret - ns.adaos)),0), Nvl(sum(l1.cant),0) INTO aVal, aCant
  FROM livr1 l1
    INNER JOIN livr l ON l.codlivr = l1.codlivr AND l.tiplivr = 20
    INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
  WHERE l1.codies1 = aCodIes1;

  IF aCantF &lt;&gt; 0 THEN
    IF Nvl(vAnF,0) &lt;&gt; aAnF AND Nvl(vLunaF,0) &lt;&gt; aLunaF THEN
      vAnF   := aAnF;
      vLunaF := aLunaF;
      vStornoAvize := Nvl( pkg_categconst.GetValConstanta(&apos;StornoAvize&apos;,vAnF,vLunaF),0);
    END IF;

    IF vStornoAvize = 1 THEN
      SELECT aVal + Nvl(sum(l1.cant * (ns.pret - ns.adaos)),0), aCant + Nvl(sum(l1.cant),0) INTO aVal, aCant
      FROM iesiri1 i1
        INNER JOIN livr1 l1 ON l1.codies1 = i1.CodIes1
        INNER JOIN livr l ON l.codlivr = l1.codlivr AND l.tiplivr = 20
        INNER JOIN nirstoc ns ON l1.codnirstoc = ns.codnirstoc
      WHERE i1.codies1storno = aCodIes1;
    END IF;

    IF aCant = 0
    THEN aVal := 0;
    ELSE aVal := aVal * aCantF / aCant;
    END IF;
  END IF;

  RETURN aVal;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(1000);
  sSelect1  VARCHAR2(9000);
  sSelect2  VARCHAR2(9000);
  sPer      VARCHAR2(1000);
  sNotBcar  VARCHAR2(100);
BEGIN
  gSuplCols :=
    &apos;IESIRI AE, IESIRI1 AE1, IESIRI AX, IESIRI1 AX1, NARTOBJ O, NART ART, NUM1 U, NPART P, IESIRI I, IESIRI1 I1, NCLASEA CLA, NCLASEP CLP, NAGENDA AG, TRASEULIVR T, &apos;||
    &apos;NPART PROD, NCARSUPART CS, NPARTTR D, NARTCLI AC, NLOCALIT LOC, NTARI TARI, NARTOBJTRAD TRAD, NECHIV E, GRECHIV GRE, OFERTA1 O1, BCAR BCAR&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPARTDET&apos;, &apos;PD&apos;, &apos;PD.CODPART = P.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SLIVR&apos;, &apos;SLIVR.CODAGENDA = AE.CODLOCATIE&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;, &apos;LOCLIVR&apos;, &apos;LOCLIVR.CODLOCALIT = SLIVR.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARALIVR&apos;, &apos;LOCLIVR.CODTARA = TARALIVR.CODTARA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SSOC&apos;, &apos;SSOC.CODPART = AE.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;, &apos;LOCSOC&apos;, &apos;LOCSOC.CODLOCALIT = SSOC.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NTARI&apos;, &apos;TARASOC&apos;, &apos;LOCSOC.CODTARA = TARASOC.CODTARA&apos;);
  IF PKG_CATEGCONST.GetValConstanta(&apos;CumulezBcar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 2
  THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;, &apos;BCAR&apos;, &apos;BCAR.CODDOC1 = AE1.CODIES1 AND BCAR.TIPDOC = AE.TIPDOC&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BCAREXT&apos;, &apos;BCAREXT.CODBCAR = BCAR.CODBCAR&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, Ae, Doc, Part,
    Art, UM, Cant, CantAe,
    CantPrel,
    RestC,
    RestV,
    PUAE,
    NrLinAe, Ordine,
    DenLaCli, CodLaCli,
    CodListat, ValAchiz&apos;||
    gUserFields||&apos;)&apos;;

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sSelect1 := &apos;
  SELECT
    ae.Codies, ae.tipdoc,
    CASE WHEN ax.codies IS NOT NULL THEN ax.PrefixDoc||ax.NrDoc||&apos;&apos;/&apos;&apos;||ax.Datadoc ELSE ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc END,
    ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, ae1.cant/u.paritate Cant, ae1.cant/u.paritate CantAe,
    CASE WHEN Nvl(ae1.custodieintrare,0) = 1 OR Nvl(ae.TipConsumator,0) = 2 THEN ae1.cant/u.paritate ELSE 0 END CantPrel,
    CASE WHEN Nvl(ae1.custodieintrare,0) = 1 OR Nvl(ae.TipConsumator,0) = 2 THEN 0 ELSE ae1.cant/u.paritate END RestC,
    CASE WHEN Nvl(ae1.custodieintrare,0) = 1 OR Nvl(ae.TipConsumator,0) = 2 THEN 0 ELSE ae1.cant*Coalesce(ax1.pu,ae1.pu,0) END RestV,
    Coalesce(ax1.pu,ae1.pu,0) * u.paritate,
    CASE
      WHEN ax.codies IS NULL
      THEN (SELECT COUNT(1) FROM IESIRI1 X1 WHERE x1.codies = ae.codies AND x1.IndexLocal &lt;= ae1.IndexLocal)
      ELSE (SELECT COUNT(1) FROM IESIRI1 X1 WHERE x1.codies = ax.codies AND x1.IndexLocal &lt;= ax1.IndexLocal)
    END,
    Decode(ax.codies,NULL,0,1) ,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    pkg_list_base_urmaecli.GetValAchiz(ae1.codies1) &apos;||
    gUserAlias||&apos;
  FROM iesiri ae
    INNER JOIN iesiri1 ae1 ON ae1.codies = ae.codies
    INNER JOIN nartobj o ON o.codobiect = ae1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = ae1.umsec
    INNER JOIN npart p ON p.codpart = ae.partener
    LEFT JOIN iesiri1 ax1 ON ax1.codies1 = Decode(ae1.codies1storno,0,ae1.codliniedocimp,NULL,ae1.codliniedocimp,ae1.codies1storno)
    LEFT JOIN iesiri ax ON ax.codies = ax1.codies
    LEFT JOIN iesiri1 i1 ON i1.codies1 = ax1.codies1
    LEFT JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = ae.codlocatie
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = ae.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = ae1.codobiect AND ac.codpart = ae.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = ae1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = ae1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = ae1.codoferta1&apos;||
    gSuplJoins||&apos;
  WHERE ae.tipdoc = 20 AND ae.operat = 1 AND ae.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
    AND ae.DataDoc &apos;||sPer;

  sSelect2 := &apos;
  SELECT
    i.codies, i.tipdoc,
    CASE WHEN ax.codies IS NOT NULL THEN ax.PrefixDoc||ax.NrDoc||&apos;&apos;/&apos;&apos;||ax.Datadoc ELSE ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc END,
    --ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc Com,
    i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, il.cant/u.paritate Cant, 0 CantAe,
    il.cant/u.paritate CantPrel,
    -il.cant/u.paritate RestC,
    -il.cant*Nvl(ae1.pu,0) RestV,
    Nvl(ae1.pu,0) * u.paritate,
    CASE
      WHEN ax.codies IS NULL
      THEN (SELECT COUNT(1) FROM IESIRI1 X1 WHERE x1.codies = ae.codies AND x1.IndexLocal &lt;= ae1.IndexLocal)
      ELSE (SELECT COUNT(1) FROM IESIRI1 X1 WHERE x1.codies = ax.codies AND x1.IndexLocal &lt;= ax1.IndexLocal)
    END,
    --(SELECT COUNT(1) FROM IESIRI1 X1 WHERE x1.codies = ae.codies AND x1.IndexLocal &lt;= ae1.IndexLocal),
    1 + ROW_NUMBER() OVER (PARTITION BY ae.Codies, ae1.IndexLocal ORDER BY I.DataDoc, I.NrDoc, I.CodIes),
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    CASE WHEN il.cant = 0 THEN 0 WHEN ae1.cant = 0 THEN 0 ELSE pkg_list_base_urmaecli.GetValAchiz(ae1.codies1,i1.cant,i.an,i.luna) END &apos;||
    gUserAlias||&apos;
  FROM iesiri ae
    INNER JOIN iesiri1 ae1 ON ae1.codies = ae.codies
    INNER JOIN nartobj o ON o.codobiect = ae1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = ae1.umsec
    INNER JOIN npart p ON p.codpart = ae.partener
    INNER JOIN ieslink il ON il.codlinieaviz = ae1.codies1
    INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
    INNER JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN iesiri1 ax1 ON ax1.codies1 = Decode(ae1.codies1storno,0,ae1.codliniedocimp,NULL,ae1.codliniedocimp,ae1.codies1storno)
    LEFT JOIN iesiri ax ON ax.codies = ax1.codies
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = ae.codlocatie
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = ae.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = ae1.codobiect AND ac.codpart = ae.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = ae1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = ae1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = ae1.codoferta1&apos;||
    gSuplJoins||&apos;
  WHERE ae.tipdoc = 20 AND ae.operat = 1 AND ae.anulat = 0 AND il.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0
    AND ae.DataDoc &apos;||sPer||CASE WHEN PKG_LIST_ALEGPERIOADA.optiunea1 THEN &apos; AND i.DataDoc &apos;||sPer END;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END pkg_list_base_urmaecli;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMAEFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68CC3364508A0E61299D3A1BC779187508773752</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmaefurn IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(1000);
  sSelect1  VARCHAR2(9000);
  sSelect2  VARCHAR2(9000);
  sSelect3  VARCHAR2(9000);
  sPer      VARCHAR2(1000);
  sNotBcar  VARCHAR2(100);
BEGIN
  gSuplCols :=
    &apos;intrari ae, intrari1 ae1, nartobj o, nart art, num1 u, npart p, intrari i, intrari1 i1, nclasea cla, nclasep clp, nagenda ag, traseulivr t, &apos;||
    &apos;npart prod, ncarsupart cs, nparttr d, nartcli ac, nlocalit loc, ntari tari, nartobjtrad trad, nechiv e, grechiv gre, oferta1 o1, bcar bcar, iesiri ies, iesiri1 ies1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  IF PKG_CATEGCONST.GetValConstanta(&apos;CumulezBcar&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 2
  THEN
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAR&apos;, &apos;BCAR&apos;, &apos;bcar.CODDOC1 = AE1.CODIES1 AND BCAR.TIPDOC = AE.TIPDOC&apos;);
    pkg_list_struct.AddSuplTabs(gSuplCols, &apos;BCAREXT&apos;, &apos;BCAREXT&apos;, &apos;bcarext.codbcar = bcar.codbcar&apos;);
  END IF;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc,
    Ae,
    Doc, Part,
    Art, UM, Cant, CantAe, CantPrel, RestC,
    RestV, PUAE,
    NrLinAe, Ordine,
    DenLaCli, CodLaCli,
    CodListat&apos;||
    gUserFields||&apos;)&apos;;

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sSelect1 := &apos;
  SELECT
    ae.CodIntr, ae.tipdoc,
    CASE
      WHEN i.codintr IS NOT NULL THEN i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc
      ELSE ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc
    END Ae,
    ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc Doc, p.Den_Part Part,
    o.denumire Art, u.den_um1 UM, ae1.cant/u.paritate Cant, ae1.cant/u.paritate CantAe, 0 CantPrel, ae1.cant/u.paritate RestC,
    ae1.cant*Coalesce(i1.pu,ae1.pu,0) RestV, Coalesce(i1.pu,ae1.pu,0) * u.paritate PUAE,
    Coalesce(i1.indexlocal, ae1.indexlocal, 0) NrLinAe, DECODE(i.codintr,NULL,0,1) Ordine,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire) DenLaCli, NVL(ac.codextern,o.codextern) CodLaCli,
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern) CodListat&apos;||
    gUserAlias||&apos;
  FROM intrari ae
    INNER JOIN intrari1 ae1 ON ae1.codintr = ae.codintr
    INNER JOIN nartobj o ON o.codobiect = ae1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = ae1.umsec
    INNER JOIN npart p ON p.codpart = ae.partener
    LEFT JOIN intrari1 i1 ON i1.codintr1 = ae1.codintr1storno
    LEFT JOIN intrari i ON i.codintr = i1.codintr
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = ae.codlocatie
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = ae.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = ae1.codobiect AND ac.codpart = ae.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = ae1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = ae1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = ae1.codoferta1
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = ae.codintr - ae.codintr
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies&apos;||
    gSuplJoins||&apos;
  WHERE ae.tipdoc = 2 AND ae.operat = 1 AND ae.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
    AND ae.DataDoc &apos;||sPer;


  sSelect2 := &apos;
  SELECT
    i.codintr, i.tipdoc,
    ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc Ae,
    i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc Doc, p.Den_Part Part,
    o.denumire Art, u.den_um1 UM, il.cant/u.paritate Cant, 0 CantAe, il.cant/u.paritate CantPrel, -il.cant/u.paritate RestC,
    -il.cant*Nvl(ae1.pu,0) RestV, Nvl(ae1.pu,0) * u.paritate PUAE,
    Nvl(ae1.IndexLocal, 0) NrLinAe, 2 Ordine,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire) DenLaCli, NVL(ac.codextern,o.codextern) CodLaCli,
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern) CodListat&apos;||
    gUserAlias||&apos;
  FROM intrari ae
    INNER JOIN intrari1 ae1 ON ae1.codintr = ae.codintr
    INNER JOIN nartobj o ON o.codobiect = ae1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = ae1.umsec
    INNER JOIN npart p ON p.codpart = ae.partener
    INNER JOIN intrlink il ON il.codlinieaviz = ae1.codintr1
    INNER JOIN intrari1 i1 ON i1.codintr1 = il.codintr1
    INNER JOIN intrari i ON i.codintr = i1.codintr
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = ae.codlocatie
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = ae.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = ae1.codobiect AND ac.codpart = ae.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = ae1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = ae1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = ae1.codoferta1
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = ae.codintr - ae.codintr
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies&apos;||
    gSuplJoins||&apos;
  WHERE ae.tipdoc = 2 AND ae.operat = 1 AND ae.anulat = 0 AND il.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0
    AND ae.DataDoc &apos;||sPer||CASE WHEN PKG_LIST_ALEGPERIOADA.optiunea1 THEN &apos; AND i.DataDoc &apos;||sPer END;

  sSelect3 := &apos;
  SELECT
    ies.codies, ies.tipdoc,
    ae.PrefixDoc||ae.NrDoc||&apos;&apos;/&apos;&apos;||ae.Datadoc Ae,
    ies.PrefixDoc||ies.NrDoc||&apos;&apos;/&apos;&apos;||ies.Datadoc Doc, p.Den_Part Part,
    o.denumire Art, u.den_um1 UM, ies1.cant/u.paritate Cant, 0 CantAE, ies1.cant/u.paritate CantPrel, -ies1.cant/u.paritate RestC,
    -ies1.cant*Nvl(ae1.pu,0) RestV, Nvl(ae1.pu,0) * u.paritate PUAE,
    Nvl(ae1.IndexLocal, 0) NrLinAe, 2 Ordine,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire) DenLaCli, NVL(ac.codextern,o.codextern) CodLaCli,
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern) CodListat&apos;||
    gUserAlias||&apos;
  FROM intrari ae
    INNER JOIN intrari1 ae1 ON ae1.codintr = ae.codintr
    INNER JOIN nartobj o ON o.codobiect = ae1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = ae1.umsec
    INNER JOIN npart p ON p.codpart = ae.partener
    INNER JOIN iesiri1 ies1 ON ies1.codliniedocimp = ae1.codintr1 AND ies1.tipdocimp = ae.tipdoc
    INNER JOIN iesiri ies ON ies.codies = ies1.codies
    LEFT JOIN intrari1 i1 ON i1.codintr1 = ae1.codintr1-ae1.codintr1
    LEFT JOIN intrari i ON i.codintr = i1.codintr
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = ae.codlocatie
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = ae.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = ae1.codobiect AND ac.codpart = ae.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = ae1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = ae1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = ae1.codoferta1&apos;||
    gSuplJoins||&apos;
  WHERE ae.tipdoc = 2 AND ae.operat = 1 AND ae.anulat = 0 AND ies1.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;AE&apos;)||&apos;
    AND Nvl(ies1.custodieintrare,0) = 1
    AND ies.operat = 1 AND ies.anulat = 0
    AND ae.DataDoc &apos;||sPer||CASE WHEN PKG_LIST_ALEGPERIOADA.optiunea1 THEN &apos; AND i.DataDoc &apos;||sPer END;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END pkg_list_base_urmaefurn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMARIREINCASARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E643A39917874C0AB85DF8E0E40F994A3E570703</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMARIREINCASARI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sSelect     CLOB;
  sSelect_Ini CLOB;
  sAux        CLOB         := &apos;&apos;;
  An          NUMBER(4);
  Luna        NUMBER(2);
  dDataS      DATE         := pkg_list_alegperioada.getDataS;
  dDataF      DATE         := pkg_list_alegperioada.getDataF;
  AnS         NUMBER(4)    := EXTRACT(YEAR  FROM dDataS);
  LunaS       NUMBER(2)    := EXTRACT(MONTH FROM dDataS);
  ZiS         NUMBER(2)    := EXTRACT(DAY   FROM dDataS);
  sDataS      VARCHAR2(10) := To_Char(dDataS,&apos;dd.mm.yyyy&apos;);
  sDataF      VARCHAR2(10) := To_Char(dDataF,&apos;dd.mm.yyyy&apos;);
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols :=
    &apos;npart npart, nmonede mon, nclasep clsp, nagenda ag, nlocalit locS, njudet jud, npers agent, npers agent_inc,&apos;||
    &apos;nsubunit substingatori, nsubunit substinsi, ntipsedii ts&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SSOC&apos;,     &apos;SSOC.CODPART = NPART.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;PAG&apos;,      &apos;PAG.CODPERS = SSOC.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;STINS_IES&apos;,&apos;STINSI.CODDOC = STINS_IES.CODIES AND STINSI.TIPDOC = STINS_IES.TIPDOC&apos;,                        1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC&apos;,         &apos;STINS_NC&apos;, &apos;STINSI.CODDOC = STINS_NC.CODNC AND STINSI.TIPDOC = 35&apos;,                                        1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;,    &apos;STINS_TR1&apos;,&apos;STINSI.CODDOC = STINS_TR1.CODTREZOR1 AND STINSI.TIPDOC IN (29,30,31,33)&apos;,                      1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,     &apos;STINS_TR&apos;, &apos;STINS_TR.CODTREZOR = STINS_TR1.CODTREZOR&apos;,                                                     1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMPENS&apos;,    &apos;STINS_C&apos;,  &apos;STINSI.CODDOC = STINS_C.CODCOMPENS AND STINSI.TIPDOC = 28&apos;,                                    1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;,    &apos;STING_TR1&apos;,&apos;STINGATORI.CODDOC1 = STING_TR1.CODTREZOR1 AND STINGATORI.TIPDOC IN (29,30,31,33)&apos;,             1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,     &apos;STING_TR&apos;, &apos;STINGATORI.CODDOC  = STING_TR.CODTREZOR AND STINGATORI.TIPDOC = STING_TR.TIPDOC&apos;,              1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMPENS&apos;,    &apos;STING_C&apos;,  &apos;STINGATORI.CODDOC = STING_C.CODCOMPENS AND STINGATORI.TIPDOC = 28&apos;,                            1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;, &apos;STINS_CC&apos;, &apos;STINS_CC.CODCARNET = STINSI.CARNETDOC&apos;,                                                        1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;DOCCARNETE&apos;, &apos;STING_DC&apos;, &apos;STING_DC.CODCARNET = STINGATORI.CARNETDOC&apos;,                                                    1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OBLIGPIF&apos;,   &apos;STING_OBL&apos;,&apos;STING_OBL.CODOBLIGPIF = STINGATORI.CODOBLIGPIF&apos;,                                               1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;GENERAL&apos;,    &apos;STING_GEN&apos;,&apos;STING_GEN.CODGENERAL = STING_OBL.CODGENERAL&apos;,                                                  1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OBLIGPIF&apos;,   &apos;STINS_OBL&apos;,&apos;STINS_OBL.CODOBLIGPIF = STINSI.CODOBLIGPIF&apos;,                                                   1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;GENERAL&apos;,    &apos;STINS_GEN&apos;,&apos;STINS_GEN.CODGENERAL = STINS_OBL.CODGENERAL&apos;,                                                  1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pkg_setluni.GetLunaInitiala(An, Luna);

  IF ZiS &lt;&gt; 1 THEN
    sAux := &apos;  -
      (
        SELECT Coalesce(sum(s.valoare), 0)
        FROM stingere s
          inner join obligpif o on s.codstingatorpif = o.codobligpif
          inner join general g on o.codgeneral = g.codgeneral
          LEFT JOIN trezor1 t1 on g.coddoc = t1.codtrezor1
          LEFT JOIN compens c ON g.coddoc = c.codcompens
        WHERE s.codstinspif = ol.codobligpif
          AND ( (g.tipdoc &lt;&gt; 28 AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and t1.luna = &apos;||To_Char(LunaS)||&apos; and t1.an = &apos;||To_Char(AnS)||&apos;) OR
                (g.tipdoc  = 28 AND c.datadoc  &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and c.luna  = &apos;||To_Char(LunaS)||&apos; and c.an  = &apos;||To_Char(AnS)||&apos;) )
      )  -
      (
        SELECT Coalesce(sum(es.valoare), 0)
        FROM emulare e
          INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
          INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
          INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
          INNER JOIN general g ON g.codgeneral = o.codgeneral
          INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
          LEFT JOIN  iesiri m ON m.codies = e.codmonetar
        WHERE o.codobligpif = ol.codobligpif
          AND E.DATABON &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          AND (M.CODIES IS NULL OR I.An*12+I.LUNA &gt;= &apos;||To_Char(LunaS*12+AnS)||&apos;)
      )&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, DOCSTINS, TOTAL_DOCUMENT, VAL_NESTINSA_DOCUMENT, VAL_STINGATOR, SOLD_DOC, DOCSTINGATOR, PARTENER, LOCATIE,
    DATADECONT, DATA, DATA_STINS, ORDINE, TERMEN, MONEDA, SUBUNITATEA, SUBUNITATEA_ST, SCADENTA, DIFZILE,
    INC_VAL, INC_VAL1, INC_VAL2, INC_VAL3, INC_VAL4, INC_VAL5,
    DEPZILE, AGENT, AGENT_INCASATOR,
    CONT, TIPDOCSTINS, 
    TIPDOCSTINGATOR, NRDOCSTINGATOR, LOCS, PROCTVAMEDIU&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  crs_sold as (
    SELECT
      ol.codobligpif codobligpif,
      ol.rest&apos;||sAux||&apos; rest
    FROM obligpifluna ol
      INNER JOIN obligpif op on ol.codobligpif = op.codobligpif
      INNER JOIN general g on op.codgeneral = g.codgeneral
    WHERE g.tipdoc IN (19, 20, 21, 22, 26, 35)
      AND ol.luna + ol.an*12 = &apos;||To_Char(AnS*12+Lunas-1)||&apos;
  ),
  stinsi as (
    SELECT
      I.CodIes CodDoc, I.TipDoc, I.CodIes, i.carnetdoc,
      obstins.codgeneral codgeneral, CASE WHEN Coalesce(i.initializari, 0) = 0 THEN i.prefixdoc ELSE &apos;&apos;sold initial &apos;&apos; END||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, obstins.codpart, i.codlocatie, obstins.termen, i.agent,
      obstins.icont, i.an*12+i.luna al, obstins.semnificatie, CASE WHEN Coalesce(i.initializari, 0) = 0 THEN i.prefixdoc ELSE &apos;&apos;sold initial &apos;&apos; END TipDocStinsi,
      round(i.tvadoc/Coalesce(NULLIF(CASE i.tipdoc WHEN 22 THEN i.valdoc ELSE i.valdoc-i.tvadoc END, 0), 1)*100,2) TVAMediu
    FROM iesiri i
      INNER JOIN general   g      ON g.coddoc     = i.codies and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE Coalesce(i.anulat, 0) = 0
      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    UNION ALL
    SELECT
      NC.CodNc CodDoc, 35 TipDoc, 0 CodIes, nc.carnetdoc,
      obstins.codgeneral codgeneral, &apos;&apos;NC &apos;&apos;  ||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      nc.datadoc data_stins, nc.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, obstins.codpart, 0 codlocatie, obstins.termen, nc1.agent,
      obstins.icont, nc1.an*12+nc1.luna al, obstins.semnificatie, &apos;&apos;NC&apos;&apos; tipdocstinsi, 
      0 TVAMediu
    FROM nc
      INNER JOIN nc1 ON nc1.codnc = nc.codnc
      INNER JOIN general g ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35 AND g.semnificatie = 1200
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    UNION ALL
    SELECT
      tr1.CodTrezor1 CodDoc, tr.TipDoc, 0 CodIes, tr1.carnetdoc,
      obstins.codgeneral codgeneral, tr1.doc ||tr1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(tr1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      tr1.datadoc data_stins, tr.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, obstins.codpart, tr1.codlocatie, obstins.termen, Coalesce(NULLIF(tr1.agent,0),tr.agent,0) agent,
      obstins.icont,tr1.an*12+tr1.luna al,obstins.semnificatie, tr1.doc tipdocstinsi, 
      0 TVAMediu
    FROM trezor1 tr1
      INNER JOIN general g ON g.coddoc = tr1.codtrezor1 AND g.tipdoc in (29,30,31) AND g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      INNER JOIN trezor tr ON tr1.codtrezor = tr.codtrezor
    WHERE Coalesce(tr1.anulat, 0) = 0 AND Coalesce(tr1.OBIECTTRANZ,0) &lt;&gt; 3
      AND tr1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie IN (330,410,600)
    UNION ALL
    SELECT
      cstins.CodCompens CodDoc, 28 TipDoc, 0 CodIes, cstins.carnetdoc,
      obstins.codgeneral codgeneral, &apos;&apos;PV &apos;&apos; ||cstins.nrdoc||&apos;&apos;/&apos;&apos;||to_char(cstins.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins,
      cstins.datadoc data_stins, cstins.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, obstins.codpart, 0 codlocatie, obstins.termen, cstins.agent,
      obstins.icont,cstins.an*12+cstins.luna al, obstins.semnificatie, &apos;&apos;PV&apos;&apos; tipdocstinsi, 
      0 TVAMediu
    FROM compens cstins
      INNER JOIN general g ON g.coddoc = cstins.codcompens and g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE g.tipdoc = 28
      AND cstins.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
  ),
  stingatori as (
    SELECT
      t.codtrezor, CASE os.semnificatie WHEN 1303 THEN os.codobligasociat ELSE os.codobligpif END codstinspif, case when t1.obiecttranz = 1 then -1 else 1 end * s.valoare valstins, o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.carnetdoc,
      t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, o.codpart,
      Coalesce(t1.DATADECONT,t.datadoc) DATADECONT, t1.datadoc AS DATA, Coalesce(NULLIF(t1.agent,0),t.agent,0) agent, t.Subunitatea, t1.doc tipdocstingatori, t1.nrdoc nrdocstingatori,
      CASE os.semnificatie WHEN 1303 THEN 1 ELSE 0 END stingLit
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE T.TIPDOC IN (29,30,31,33)
      AND g.semnificatie IN (400,420,750,751)--AND t1.TipTranz IN (0,1) AND t1.ObiectTranz IN (0,1) AND t1.TipTranz &lt;&gt; t1.ObiectTranz
      AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND Coalesce(t1.Initializari,0) = 0 &apos;||
      CASE
        WHEN NOT pkg_list_alegperioada.optiunea3
        THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)
        ELSE &apos;&apos; 
      END ||&apos;
    UNION ALL
    SELECT
      0 codtrezor, s.codstinspif, CASE WHEN os.valoare * s.valoare &lt; 0 THEN -1 ELSE 1 END * s.valoare valstins, o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, c.carnetdoc,
      &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, o.codpart,
      c.datadoc DATADECONT, c.datadoc AS DATA, c.Agent, c.Subunitatea, &apos;&apos;PV&apos;&apos; tipdocstingatori, c.nrdoc nrdocstingatori,
      0 stingLit
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
      INNER JOIN obligpif os ON os.codobligpif = s.codstinspif
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28
      AND os.semnificatie NOT IN (410)
      AND o.icont IN (3,5,7,10,11,18) &apos;||
      CASE
        WHEN NOT pkg_list_alegperioada.optiunea3
        THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)
        ELSE &apos;&apos; 
      END ||&apos;
    UNION ALL
    SELECT
      0 codtrezor, o.codobligpif codstinspif, es.valoare valstins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, i.carnetdoc,
      &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, o.codpart,
      e.databon DATADECONT, e.databon AS DATA, 0 Agent, NULL Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori,
      0 stingLit
    FROM emulare e
      INNER JOIN emulare1 e1 on e1.codemulare = e.codemulare
      INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
      INNER JOIN obligpif o ON o.codobligpif = es.codobligpif
      INNER JOIN general g ON g.codgeneral = o.codgeneral
      INNER JOIN iesiri i ON  g.coddoc = i.codies AND g.tipdoc = i.tipdoc
    WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE
        WHEN NOT pkg_list_alegperioada.optiunea3
        THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)
        ELSE &apos;&apos; 
      END ||&apos;
    UNION ALL
    SELECT
      0 codtrezor, o.codobligpif codstinspif, e.valoare valstins, 0 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, i.carnetdoc,
      &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, o.codpart,
      e.databon DATADECONT, e.databon AS DATA, 0 Agent, NULL Subunitatea, &apos;&apos;BON&apos;&apos; tipdocstingatori, e.nrbon nrdocstingatori,
      0 stingLit
    FROM emulare e
      INNER JOIN iesiri i ON i.codies = e.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;||
      CASE
        WHEN NOT pkg_list_alegperioada.optiunea3
        THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)
        ELSE &apos;&apos; 
      END ||&apos;
  )
  SELECT
    CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.coddoc END NAV_CodDoc, CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.coddoc1 END NAV_CodDoc1, CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.tipdoc END NAV_TipDoc,
    CASE stingatori.stingLit WHEN 1 THEN &apos;&apos;Litigiu &apos;&apos; ELSE &apos;&apos;&apos;&apos; END||stinsi.docstins, stinsi.valoare + Coalesce(e.valoare,0) TOTAL_DOCUMENT,
    Coalesce(
      stingatori.valstins + CASE Coalesce(crs_sold.rest,0) WHEN 0 THEN stinsi.valoare ELSE crs_sold.rest END + Coalesce(e.valoare,0) -
      SUM(stingatori.valstins) over (PARTITION BY stingatori.codstinspif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW )
      , 0
    ) VAL_NESTINSA_DOCUMENT,
    stingatori.valstins VAL_STINGATOR,
    Coalesce(
      CASE Coalesce(crs_sold.rest,0) WHEN 0 THEN stinsi.valoare ELSE crs_sold.rest END + Coalesce(e.valoare,0) -
      SUM(stingatori.valstins) over (PARTITION BY stingatori.codstinspif ORDER BY stingatori.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW )
      , 0
    ) SOLD_DOC,
    stingatori.DOCSTINGATOR, npart.den_part, ag.obs, stingatori.DATADECONT, stingatori.DATA, stinsi.DATA_STINS, stingatori.codgeneral ORDINE, stinsi.TERMEN, mon.den_moneda,
    SubStinsi.den_subunit SUBUNITATEA, SubStingatori.den_subunit SUBUNITATEA_ST, stinsi.termen SCADENTA, trunc(stingatori.Data - stinsi.data_stins) DIFZILE,
    stingatori.valstins INC_VAL,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) &lt;=               1 THEN stingatori.valstins ELSE 0 END INC_VAL1,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN  2 AND  30 THEN stingatori.valstins ELSE 0 END INC_VAL2,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN 31 AND  45 THEN stingatori.valstins ELSE 0 END INC_VAL3,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN 46 AND  60 THEN stingatori.valstins ELSE 0 END INC_VAL4,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) &gt;               60 THEN stingatori.valstins ELSE 0 END INC_VAL5,
    CASE WHEN trunc(stingatori.data - stinsi.termen) &gt; 0 then trunc(stingatori.data - stinsi.termen) else 0 end DEPZILE,
    agent.nume||&apos;&apos; &apos;&apos;||agent.prenume AGENT, agent_inc.nume||&apos;&apos; &apos;&apos;||agent_inc.prenume AGENT_INCASATOR, 
    PKG_LIST_BASE_UTILS.decode_iCont(stinsi.icont, stinsi.codpart, stinsi.al, stinsi.semnificatie) AS cont, stinsi.tipdocstinsi, 
    stingatori.tipdocstingatori, stingatori.nrdocstingatori,locS.den_localit, stinsi.TVAMediu &apos;||gUserAlias||&apos;
  FROM stingatori
    LEFT JOIN stinsi on stinsi.codobligpif = stingatori.codstinspif
    LEFT JOIN crs_sold on stinsi.codobligpif = crs_sold.codobligpif
    LEFT JOIN npers agent on agent.codpers = Coalesce(stinsi.agent,0)
    LEFT JOIN npers agent_inc on agent_inc.codpers = Coalesce(stingatori.agent,0)
    LEFT JOIN npart npart on npart.codpart = Coalesce(stinsi.codpart,stingatori.codpart)
    LEFT JOIN nclasep clsp on clsp.codclasep = Coalesce(npart.codclasa, 0)
    LEFT JOIN nagenda ag on ag.codagenda = Coalesce(stinsi.codlocatie,0)
    LEFT JOIN nmonede mon ON mon.codmoneda = Coalesce(stinsi.moneda,0)
    LEFT JOIN nsubunit SubStingatori ON stingatori.subunitatea = SubStingatori.codsubunit
    LEFT JOIN tmp_subunitdedicate tmps ON tmps.codsubunit = stingatori.subunitatea
    LEFT JOIN nsubunit SubStinsi ON stinsi.subunitatea = SubStinsi.codsubunit
    LEFT JOIN emulare e ON e.codies = stinsi.codies
    LEFT JOIN nlocalit locS on ag.codlocalit = locS.codlocalit
    LEFT JOIN njudet jud on locS.codjudet = jud.codjudet
    LEFT JOIN ntipsedii ts ON ts.codtipsediu = ag.codtipsediu&apos;||
    gSuplJoins;

  sSelect_Ini := &apos;
  WITH
  stingeri as (
    select stingere.*, general.codgeneral
    from stingere
      inner join obligpif on stingere.codstingatorpif = obligpif.codobligpif
      inner JOIN general ON obligpif.codgeneral = general.codgeneral
  ),
  stinsi as (
    SELECT
      i.codies coddoc, i.tipdoc, i.carnetdoc,
      obstins.codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins,
      i.datadoc data_stins, i.subunitatea, g.moneda, obstins.codobligpif, obstins.valoare, obstins.codpart, i.codlocatie, obstins.termen, i.agent,
      obstins.icont, i.an*12+i.luna al, obstins.semnificatie, i.prefixdoc tipdocstinsi,
      round(i.tvadoc/Coalesce(NULLIF(CASE i.tipdoc WHEN 22 THEN i.valdoc ELSE i.valdoc-i.tvadoc END, 0), 1)*100,2) TVAMediu
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 500
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE Coalesce(i.anulat, 0) = 0 and Coalesce(i.initializari, 0) = 1
      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
  ),
  stingatori as (
    SELECT
      t.codtrezor, o.CodObligPIF, s.valoare valstins, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.carnetdoc,
      t1.doc||&apos;&apos; &apos;&apos; ||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, o.codpart,
      Coalesce(t1.DATADECONT,t.datadoc) DATADECONT, t1.datadoc AS DATA, Coalesce(NULLIF(t1.agent,0),t.agent,0) agent, t.Subunitatea, O.Valoare, t1.doc tipdocstingatori, t1.nrdoc nrdocstingatori
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
    WHERE T.TIPDOC IN (29,30,31,33)
      AND g.semnificatie IN (400,420,750,751)
      AND Coalesce(t1.Initializari,0) = 1 &apos;||
      CASE
        WHEN NOT pkg_list_alegperioada.optiunea3
        THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)
        ELSE &apos;&apos; 
      END ||&apos;
  )
  SELECT
    CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.coddoc END NAV_CodDoc, CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.coddoc1 END NAV_CodDoc1, CASE WHEN tmps.codsubunit IS NOT NULL THEN stingatori.tipdoc END NAV_TipDoc,
    stinsi.DOCSTINS,
    stinsi.valoare + SUM(stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) TOTAL_DOCUMENT,
    stinsi.valoare + SUM(stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) VAL_NESTINSA_DOCUMENT,
    stingatori.valoare VAL_STINGATOR,
    stinsi.valoare - stingatori.valoare + SUM(stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) SOLD_DOC,
    stingatori.DOCSTINGATOR, npart.den_part, ag.obs, stingatori.DATADECONT, stingatori.DATA, stinsi.DATA_STINS, stingatori.codgeneral ORDINE, stinsi.TERMEN, mon.den_moneda,
    SubStinsi.den_subunit SUBUNITATEA, SubStingatori.den_subunit SUBUNITATEA_ST, stinsi.termen SCADENTA, trunc(stingatori.Data - stinsi.data_stins) DIFZILE,
    stingatori.valstins INC_VAL,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) &lt;=              1 THEN stingatori.valstins ELSE 0 END INC_VAL1,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN  2 AND 30 THEN stingatori.valstins ELSE 0 END INC_VAL2,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN 31 AND 45 THEN stingatori.valstins ELSE 0 END INC_VAL3,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) BETWEEN 46 AND 60 THEN stingatori.valstins ELSE 0 END INC_VAL4,
    CASE WHEN trunc(stingatori.Data - stinsi.data_stins) &gt;              60 THEN stingatori.valstins ELSE 0 END INC_VAL5,
    case when trunc(stingatori.data - stinsi.termen) &gt; 0 then trunc(stingatori.data - stinsi.termen) else 0 end DEPZILE,
    agent.nume||&apos;&apos; &apos;&apos;||agent.prenume AGENT, agent_inc.nume||&apos;&apos; &apos;&apos;||agent_inc.prenume AGENT_INCASATOR, 
    PKG_LIST_BASE_UTILS.decode_iCont(stinsi.icont, stinsi.codpart, stinsi.al, stinsi.semnificatie) AS cont, stinsi.tipdocstinsi,
    stingatori.tipdocstingatori, stingatori.nrdocstingatori, locS.den_localit, stinsi.TVAMediu &apos;||gUserAlias||&apos;
  FROM stingatori
    LEFT JOIN stingeri on stingeri.codstingatorpif = stingatori.codobligpif
    LEFT JOIN stinsi on stingeri.codstinspif = stinsi.codobligpif
    LEFT JOIN npers agent on agent.codpers = Coalesce(stinsi.agent,0)
    LEFT JOIN npers agent_inc on agent_inc.codpers = Coalesce(stingatori.agent,0)
    LEFT JOIN npart npart on npart.codpart = Coalesce(stinsi.codpart,stingatori.codpart)
    LEFT JOIN nclasep clsp on clsp.codclasep = Coalesce(npart.codclasa, 0)
    LEFT JOIN nagenda ag on ag.codagenda = Coalesce(stinsi.codlocatie,0)
    LEFT JOIN nmonede mon ON mon.codmoneda = Coalesce(stinsi.moneda,0)
    LEFT JOIN nsubunit SubStingatori ON stingatori.subunitatea = SubStingatori.codsubunit
    LEFT JOIN nsubunit SubStinsi ON stinsi.subunitatea = SubStinsi.codsubunit
    LEFT JOIN tmp_subunitdedicate tmps ON tmps.codsubunit = stingatori.subunitatea
    LEFT JOIN nlocalit locS on ag.codlocalit = locS.codlocalit
    LEFT JOIN njudet jud on locS.codjudet = jud.codjudet
    LEFT JOIN ntipsedii ts ON ts.codtipsediu = ag.codtipsediu&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  IF pkg_list_alegperioada.optiunea1 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_Ini, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
end pkg_list_base_urmarireincasari;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMARIREPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D6CEA1A20A4A8D40BD9074AE090F3DB7C556A3A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMARIREPLATI IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(2000);
  sSelect      VARCHAR2(30000);
  sSelect_Ini  VARCHAR2(30000);
  sSelect_Fact VARCHAR2(30000);
  An           NUMBER(4);
  Luna         NUMBER(2);
  AnS          NUMBER(4)    := extract(year from pkg_list_alegperioada.getDataS);
  LunaS        NUMBER(2)    := extract(month from pkg_list_alegperioada.getDataS);
  ZiS          NUMBER(2)    := extract(day from pkg_list_alegperioada.getDataS);
  sAux         VARCHAR2(30000);
  sDataS       VARCHAR2(10) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
  sDataF       VARCHAR2(10) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
BEGIN
  gSuplCols := &apos;npart npart, nmonede mon, nclasep clsp, nagenda ag, nlocalit loc, njudet jud, npers agent, npers agent_inc, nsubunit substingatori, nsubunit substinsi&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,  &apos;STINS_IES&apos;,     &apos;STINSI.CODDOC = STINS_IES.CODIES AND STINSI.TIPDOC = STINS_IES.TIPDOC&apos;,             1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;INTRARI&apos;, &apos;STINS_INTR&apos;,    &apos;STINSI.CODDOC = STINS_INTR.CODINTR AND STINSI.TIPDOC = STINS_INTR.TIPDOC&apos;,          1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NC&apos;,      &apos;STINS_NC&apos;,      &apos;STINSI.CODDOC = STINS_NC.CODNC AND STINSI.TIPDOC = 35&apos;,                             1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;, &apos;STINS_TR1&apos;,     &apos;STINSI.CODDOC = STINS_TR1.CODTREZOR1 AND STINSI.TIPDOC IN (29,30,31,33)&apos;,           1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,  &apos;STINS_TR&apos;,      &apos;STINS_TR.CODTREZOR = STINS_TR1.CODTREZOR&apos;,                                          1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMPENS&apos;, &apos;STINS_C&apos;,       &apos;STINSI.CODDOC = STINS_C.CODCOMPENS AND STINSI.TIPDOC = 28&apos;,                         1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR1&apos;, &apos;STING_TR1&apos;,     &apos;STINGATORI.CODDOC1 = STING_TR1.CODTREZOR1 AND STINGATORI.TIPDOC IN (29,30,31,33)&apos;,  1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;TREZOR&apos;,  &apos;STING_TR&apos;,      &apos;STINGATORI.CODDOC = STING_TR.CODTREZOR AND STINGATORI.TIPDOC = STING_TR.TIPDOC&apos;,    1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMPENS&apos;, &apos;STING_C&apos;,       &apos;STINGATORI.CODDOC = STING_C.CODCOMPENS AND STINGATORI.TIPDOC = 28&apos;,                 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  pkg_setluni.GetLunaInitiala(an, luna);

  IF ZiS &lt;&gt; 1 THEN
    sAux := &apos;   -
      (
        SELECT NVL(sum(stingere.valoare), 0)
        FROM stingere
          inner join obligpif on stingere.codstingatorpif = obligpif.codobligpif
          inner join general on obligpif.codgeneral = general.codgeneral
          left  join trezor1 t1 on general.coddoc = t1.codtrezor1
          LEFT  JOIN compens c ON general.coddoc = c.codcompens
        WHERE stingere.codstinspif = ol.codobligpif
          AND ( (g.tipdoc &lt;&gt; 28 AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and t1.luna = &apos;||LunaS||&apos; and t1.an = &apos;||AnS||&apos;) OR
                (g.tipdoc  = 28 AND c.datadoc  &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) and c.luna  = &apos;||LunaS||&apos; and c.an  = &apos;||AnS||&apos;) )
      )&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, DOCSTINS, TOTAL_DOCUMENT, VAL_NESTINSA_DOCUMENT, VAL_STINGATOR, SOLD_DOC, DOCSTINGATOR, PARTENER, DATADECONT, DATA, DATA_STINS, ORDINE,
    TERMEN,MONEDA, SUBUNITATEA, SUBUNITATEA_ST, SCADENTA, DIFZILE, DEPZILE, CONT, CursDocStins, CursDocStingator &apos;||gUserFields||&apos;) &apos;;
  sSelect :=&apos;
  WITH stingeri AS (
    SELECT stingere.*, general.codgeneral
    FROM stingere
      INNER JOIN obligpif on stingere.codstingatorpif = obligpif.codobligpif
      INNER JOIN general ON obligpif.codgeneral = general.codgeneral),
  crs_sold AS (
    SELECT
      ol.codobligpif codobligpif,
      ol.rest&apos;||sAux||&apos; rest
    FROM obligpifluna ol
      INNER JOIN obligpif op on ol.codobligpif = op.codobligpif
      INNER JOIN general g on op.codgeneral = g.codgeneral
    WHERE g.tipdoc IN (1, 2, 3,  4, 5, 9, 35)
      AND ol.luna + ol.an*12 = &apos;||To_Char(AnS*12+Lunas-1)||&apos;),
  stinsi as (
    SELECT
      I.CodIntr CodDoc, I.TipDoc,
      obstins.codgeneral, &apos;&apos;sold initial &apos;&apos; || i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, 0 agent
    FROM intrari i
      INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 1) and (g.tipdoc = i.tipdoc) AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
          and i.tipdoc &lt;&gt; 2 
    UNION ALL
    SELECT
      I.CodIntr CodDoc, I.TipDoc,
      obstins.codgeneral, i.prefixdoc ||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare,  obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, 0 agent
    FROM intrari i
      INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
          and i.tipdoc &lt;&gt; 2
    UNION ALL
    SELECT
      dvi.CodDvi CodDoc, 5 TipDoc,
      obstins.codgeneral, i.prefixdoc ||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare,  obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, 0 agent
    FROM intrari i
      inner join dvi on dvi.codintr = i.codintr
      INNER JOIN general g ON g.coddoc = dvi.coddvi and g.semnificatie &lt;&gt; 600 and g.tipdoc = 5
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
          and i.tipdoc &lt;&gt; 2
    UNION ALL
    SELECT
      I.CodIes CodDoc, I.TipDoc,
      obstins.codgeneral, i.prefixdoc ||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, abs(obstins.valoare), obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, i.agent
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies and g.semnificatie = 200
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 0) and (g.tipdoc = i.tipdoc) AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))
    UNION ALL
    SELECT
      NC.CodNc CodDoc, 35 TipDoc,
      obstins.codgeneral, &apos;&apos;NC &apos;&apos;||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, nc.datadoc data_stins, nc.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      0 codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,nc1.an*12+nc1.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, nc1.agent
    FROM nc
      INNER JOIN nc1 ON nc1.codnc = nc.codnc
      INNER JOIN general g ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35 AND g.semnificatie = 1201
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.icont IN (2,4,6,8,9,12,13,14,15,16)
    UNION ALL
    SELECT
      tr1.CodTrezor1 CodDoc, tr.TipDoc,
      obstins.codgeneral, tr1.doc||tr1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(tr1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, tr1.datadoc data_stins, tr.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      nvl(tr1.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,tr1.an*12+tr1.luna,obstins.semnificatie) cont, decode(tr1.curs,NULL,1,0,1,tr1.curs) curs,
      case when nvl(tr1.Agent,0) = 0 then nvl(tr.agent,0) else nvl(tr1.agent,0) end agent
    FROM trezor1 tr1
      INNER JOIN general g ON g.coddoc = tr1.codtrezor1 AND g.tipdoc IN (29,30,31) AND g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      INNER JOIN trezor tr ON tr1.codtrezor = tr.codtrezor
    WHERE NVL(tr1.anulat, 0) = 0 AND Nvl(tr1.OBIECTTRANZ,0) &lt;&gt; 3
      AND tr1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie IN (310,430,500)
    UNION ALL
    SELECT
      c.CodCompens CodDoc, 28 TipDoc,
      obstins.codgeneral, &apos;&apos;PV &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, c.datadoc data_stins, c.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      0 codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,c.an*12+c.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, c.agent
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens AND g.tipdoc = 28
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE c.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.icont IN (2,4,6,8,9,12,13,14,15,16) ),
  stingatori as (
    SELECT
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, t1.DATADECONT, t1.datadoc DATA, o.codpart,
      case when nvl(t1.Agent,0) = 0 then nvl(t.agent,0) else nvl(t1.agent,0) end agent, t.Subunitatea, decode(t1.curs,NULL,1,0,1,t1.curs) curs
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE T.TIPDOC IN (29,30,31,33)
      AND g.semnificatie IN (300,320,700,701)--AND t1.TipTranz IN (0,1) AND t1.ObiectTranz IN (0,1) AND t1.TipTranz = t1.ObiectTranz
      AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND Nvl(t1.Initializari,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ||&apos;
    UNION ALL
    SELECT
      o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, null DATADECONT, c.datadoc DATA, o.codpart,
      c.Agent, c.Subunitatea, decode(g.curs,NULL,1,0,1,g.curs) curs
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens AND g.tipdoc = 28
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND o.icont IN (2,4,6,8,9,12,13,14,15) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
  )
  SELECT
    DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc1) NAV_CodDoc1, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc, stinsi.DocStins, stinsi.valoare TOTAL_DOCUMENT,
    CASE
      WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(sign(stinsi.valoare)*stingeri.valoare + stinsi.valoare - SUM(sign(stinsi.valoare)*stingeri.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ), 0)
      ELSE NVL(sign(stinsi.valoare)*stingeri.valoare + crs_sold.rest - SUM(sign(stinsi.valoare)*stingeri.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ), 0)
    END VAL_NESTINSA_DOCUMENT,
    sign(stinsi.valoare)*stingeri.valoare VAL_STINGATOR,
    CASE
      WHEN NVL(crs_sold.rest, 0) = 0 THEN NVL(stinsi.valoare - SUM(sign(stinsi.valoare)*stingeri.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ), 0)
      ELSE NVL(crs_sold.rest - SUM(sign(stinsi.valoare)*stingeri.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ), 0)
    END SOLD_DOC,
    stingatori.DOCSTINGATOR, npart.den_part PARTENER, stingatori.DATADECONT, stingatori.DATA, stinsi.DATA_STINS, stingatori.codgeneral ORDINE, stinsi.TERMEN, mon.den_moneda MONEDA,
    SubStinsi.den_subunit SUBUNITATEA, SubStingatori.den_subunit SUBUNITATEA_ST, stinsi.termen SCADENTA, trunc(stingatori.Data - stinsi.data_stins) DIFZILE,
    CASE WHEN trunc(stingatori.data - stinsi.termen) &gt; 0 THEN trunc(stingatori.data - stinsi.termen) ELSE 0 END DEPZILE, stinsi.cont, stinsi.curs, stingatori.curs &apos;||gUserAlias||&apos;
  FROM stingatori
    LEFT JOIN stingeri on stingeri.codstingatorpif = stingatori.codobligpif
    LEFT JOIN stinsi on stingeri.codstinspif = stinsi.codobligpif
    LEFT JOIN npers agent on agent.codpers = nvl(stinsi.agent,0)
    LEFT JOIN npers agent_inc on agent_inc.codpers = nvl(stingatori.agent,0)
    LEFT JOIN crs_sold on stinsi.codobligpif = crs_sold.codobligpif
    LEFT JOIN npart npart on npart.codpart = Nvl(stinsi.codpart,stingatori.codpart)
    LEFT JOIN nclasep clsp on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda ag on stinsi.codlocatie = ag.codagenda
    LEFT JOIN nlocalit loc on ag.codlocalit = loc.codlocalit
    LEFT JOIN njudet jud on loc.codjudet = jud.codjudet
    LEFT JOIN nmonede mon ON stinsi.codmoneda = mon.codmoneda
    LEFT JOIN nsubunit SubStingatori ON stingatori.subunitatea = SubStingatori.codsubunit
    LEFT JOIN nsubunit SubStinsi ON stinsi.subunitatea = SubStinsi.codsubunit
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea&apos;||
    gSuplJoins||&apos;
  ORDER BY stingatori.codgeneral &apos;;

  sSelect_Fact :=&apos;
  WITH
  stinsi as (
    SELECT
      I.CodIntr CodDoc, I.TipDoc,
      obstins.codgeneral, DECODE(i.initializari,1, &apos;&apos;sold initial&apos;&apos;,i.prefixdoc)||&apos;&apos; &apos;&apos; || i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, 0 agent,
      0 substingatori, 0 agent_inc
    FROM intrari i
      INNER JOIN general g ON g.coddoc = i.codintr AND g.tipdoc = i.tipdoc AND g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT JOIN stingere s ON s.codstinspif = obstins.codobligpif
    WHERE NVL(i.anulat, 0) = 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND Nvl(s.CodStingatorPif,0) = 0
          and i.tipdoc &lt;&gt; 2 and i.operat = 1
    UNION ALL
    SELECT
      I.CodIes CodDoc, I.TipDoc,
      obstins.codgeneral, i.prefixdoc ||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, abs(obstins.valoare), obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, i.agent,
      0 substingatori, 0 agent_inc
    FROM iesiri i
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc AND g.semnificatie = 200
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT JOIN stingere s ON s.codstinspif = obstins.codobligpif
    WHERE NVL(i.anulat, 0) = 0 AND nvl(i.initializari, 0) = 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND Nvl(s.CodStingatorPif,0) = 0
          and i.operat = 1
    UNION ALL
    SELECT
      NC.CodNc CodDoc, 35 TipDoc,
      obstins.codgeneral, &apos;&apos;NC &apos;&apos;||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, nc.datadoc data_stins, nc.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      0 codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,nc1.an*12+nc1.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, nc1.agent,
      0 substingatori, 0 agent_inc
    FROM nc
      INNER JOIN nc1 ON nc1.codnc = nc.codnc
      INNER JOIN general g ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35 AND g.semnificatie = 1201
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT JOIN stingere s ON s.codstinspif = obstins.codobligpif
    WHERE nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.icont IN (2,4,6,8,9,12,13,14,15,16)
      AND Nvl(s.CodStingatorPif,0) = 0
    UNION ALL
    SELECT
      tr1.CodTrezor1 CodDoc, tr.TipDoc,
      obstins.codgeneral, tr1.doc||tr1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(tr1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, tr1.datadoc data_stins, tr.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      nvl(tr1.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,tr1.an*12+tr1.luna,obstins.semnificatie) cont, decode(tr1.curs,NULL,1,0,1,tr1.curs) curs,
      case when nvl(tr1.Agent,0) = 0 then nvl(tr.agent,0) else nvl(tr1.agent,0) end agent,
      0 substingatori, 0 agent_inc
    FROM trezor1 tr1
      INNER JOIN general g ON g.coddoc = tr1.codtrezor1 AND g.tipdoc IN (29,30,31) AND g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      INNER JOIN trezor tr ON tr1.codtrezor = tr.codtrezor
      LEFT JOIN stingere s ON s.codstinspif = obstins.codobligpif
    WHERE NVL(tr1.anulat, 0) = 0 AND tr1.OBIECTTRANZ &lt;&gt; 3
      AND tr1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.semnificatie IN (310,430,500)
      AND Nvl(s.CodStingatorPif,0) = 0
    UNION ALL
    SELECT
      c.CodCompens CodDoc, 28 TipDoc,
      obstins.codgeneral, &apos;&apos;PV &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, c.datadoc data_stins, c.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      0 codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,c.an*12+c.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, c.agent,
      0 substingatori, 0 agent_inc
    FROM compens c
      INNER JOIN general g ON g.coddoc = c.codcompens AND g.tipdoc = 28
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
      LEFT JOIN stingere s ON s.codstinspif = obstins.codobligpif
    WHERE c.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND obstins.icont IN (2,4,6,8,9,12,13,14,15,16)
      AND Nvl(s.CodStingatorPif,0) = 0 )
  SELECT
    NULL NAV_CodDoc, NULL NAV_CodDoc1, NULL NAV_TipDoc, stinsi.DOCSTINS, stinsi.valoare TOTAL_DOCUMENT, stinsi.valoare VAL_NESTINSA_DOCUMENT, 0 VAL_STINGATOR, stinsi.valoare SOLD_DOC, NULL DOCSTINGATOR, npart.DEN_PART, NULL DATADECONT, NULL DATA, stinsi.DATA_STINS, 0 ORDINE,
    stinsi.TERMEN, mon.DEN_MONEDA, SubStinsi.den_subunit SUBUNITATEA, SubStingatori.den_subunit SUBUNITATEA_ST, stinsi.termen SCADENTA,
    trunc(sysdate - stinsi.data_stins) DIFZILE, CASE WHEN trunc(sysdate - stinsi.termen) &gt; 0 THEN trunc(sysdate - stinsi.termen) ELSE 0 END DEPZILE, stinsi.CONT, stinsi.curs CursDocStins, 1 CursDocStingator &apos;||gUserAlias||&apos;
  FROM stinsi
    LEFT JOIN npers agent ON agent.codpers = nvl(stinsi.agent,0)
    LEFT JOIN npers agent_inc ON agent_inc.codpers = stinsi.agent_inc
    LEFT JOIN npart npart ON stinsi.codpart = npart.codpart
    LEFT JOIN nclasep clsp on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda ag on stinsi.codlocatie = ag.codagenda
    LEFT JOIN nlocalit loc on ag.codlocalit = loc.codlocalit
    LEFT JOIN njudet jud on loc.codjudet = jud.codjudet
    LEFT JOIN nmonede mon ON stinsi.codmoneda = mon.codmoneda
    LEFT JOIN nsubunit SubStingatori ON SubStingatori.codsubunit = stinsi.substingatori
    LEFT JOIN nsubunit SubStinsi ON SubStinsi.codsubunit = stinsi.subunitatea
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stinsi.substingatori
    CROSS JOIN (SELECT NULL CodDoc, NULL CodDoc1, NULL TipDoc FROM DUAL) stingatori &apos;||
    gSuplJoins;

  sSelect_Ini := &apos;
  WITH stingeri as (
    SELECT stingere.*, general.codgeneral
    FROM stingere
      INNER JOIN obligpif on stingere.codstingatorpif = obligpif.codobligpif
      INNER JOIN general ON obligpif.codgeneral = general.codgeneral),
  stinsi as (
    SELECT
      NULL CodDoc, NULL TipDoc,
      obstins.codgeneral, &apos;&apos;sold initial &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc data_stins, i.subunitatea, g.moneda codmoneda, obstins.codobligpif, obstins.valoare, obstins.codpart,
      nvl(i.codlocatie, 0) codlocatie, obstins.termen, PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont, obstins.codpart, i.an*12+i.luna,obstins.semnificatie) cont, decode(g.curs,NULL,1,0,1,g.curs) curs, 0 agent
    FROM intrari i
      INNER JOIN general g ON g.coddoc = i.codintr and g.semnificatie &lt;&gt; 600
      INNER JOIN obligpif obstins ON g.codgeneral = obstins.codgeneral
    WHERE (NVL(i.anulat, 0) = 0) and (nvl(i.initializari, 0) = 1) and (g.tipdoc = i.tipdoc) AND (i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) 
          and i.tipdoc &lt;&gt; 2),
  stingatori as (
    SELECT
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR, t1.DATADECONT, t1.datadoc DATA, o.codpart,
      case when nvl(t1.Agent,0) = 0 then nvl(t.agent,0) else nvl(t1.agent,0) end agent, t.Subunitatea, o.valoare, decode(t1.curs,NULL,1,0,1,t1.curs) curs
    FROM trezor1 t1
      INNER JOIN trezor t ON t1.codtrezor = t.codtrezor
      INNER JOIN general g ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
    WHERE T.TIPDOC IN (29,30,31)
      AND g.semnificatie IN (300,320,700,701)--AND t1.TipTranz IN (0,1) AND t1.ObiectTranz IN (0,1) AND t1.TipTranz = t1.ObiectTranz
      --AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND Nvl(T1.Initializari,0) = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos; )
  SELECT
    DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,stingatori.coddoc1) NAV_CodDoc1, DECODE(ts.codsubunit, NULL,NULL,stingatori.tipdoc) NAV_TipDoc, stinsi.DocStins,
    stinsi.valoare + SUM(sign(stinsi.valoare)*stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) TOTAL_DOCUMENT,
    stinsi.valoare + SUM(sign(stinsi.valoare)*stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW )  VAL_NESTINSA_DOCUMENT,
    sign(stinsi.valoare)*stingatori.valoare VAL_STINGATOR,
    stinsi.valoare - sign(stinsi.valoare)*stingatori.valoare + SUM(sign(stinsi.valoare)*stingatori.valoare) over (PARTITION BY stingeri.codstinspif ORDER BY stingeri.codgeneral ROWS BETWEEN unbounded preceding AND CURRENT ROW ) SOLD_DOC,
    stingatori.DocStingator, npart.den_part PARTENER, stingatori.DataDecont, stingatori.Data, stinsi.Data_stins, stingatori.codgeneral ORDINE, stinsi.TERMEN, mon.den_moneda MONEDA,
    SubStinsi.den_subunit SUBUNITATEA, SubStingatori.den_subunit SUBUNITATEA_ST, stinsi.termen SCADENTA, trunc(stingatori.Data - stinsi.data_stins) DIFZILE,
    CASE WHEN trunc(stingatori.data - stinsi.termen) &gt; 0 THEN trunc(stingatori.data - stinsi.termen) ELSE 0 END DEPZILE, stinsi.cont, stinsi.curs, stingatori.curs &apos;||gUserAlias||&apos;
  FROM stingatori
    INNER JOIN stingeri on stingeri.codstingatorpif = stingatori.codobligpif
    INNER JOIN stinsi on stingeri.codstinspif = stinsi.codobligpif
    LEFT JOIN npers agent on agent.codpers = nvl(stinsi.agent,0)
    LEFT JOIN npers agent_inc on agent_inc.codpers = nvl(stingatori.agent,0)
    LEFT JOIN npart npart on npart.codpart = Nvl(stinsi.codpart,stingatori.codpart)
    LEFT JOIN nclasep clsp on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda ag on stinsi.codlocatie = ag.codagenda
    LEFT JOIN nlocalit loc on ag.codlocalit = loc.codlocalit
    LEFT JOIN njudet jud on loc.codjudet = jud.codjudet
    LEFT JOIN nmonede mon ON stinsi.codmoneda = mon.codmoneda
    LEFT JOIN nsubunit SubStingatori ON stingatori.subunitatea = SubStingatori.codsubunit
    LEFT JOIN nsubunit SubStinsi ON stinsi.subunitatea = SubStinsi.codsubunit
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = stingatori.subunitatea&apos;||
    gSuplJoins||&apos;
  ORDER BY stingatori.codgeneral &apos;;


--PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  IF pkg_list_alegperioada.optiunea1 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_Ini, aListID, aListVer);
  END IF;
  IF pkg_list_alegperioada.optiunea2 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect_Fact, aListID, aListVer);
  END IF;
  IF pkg_list_alegperioada.optiunea3 THEN
    LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;||tmpName||&apos; SET TOTAL_DOCUMENT = TOTAL_DOCUMENT*CursDocStins, VAL_NESTINSA_DOCUMENT = VAL_NESTINSA_DOCUMENT*CursDocStins, VAL_STINGATOR = VAL_STINGATOR*CursDocStingator, SOLD_DOC = SOLD_DOC*CursDocStins&apos;, aListID, aListVer);
  END IF;
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_UrmarirePlati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMARIRE_PREDARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F0E763244CEFB750E82FB91B42DFC632927497A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMARIRE_PREDARI is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);
pFiltru     VARCHAR2(1000);

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(30000);
sDataS VARCHAR2(100) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
sDataF VARCHAR2(100) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
BEGIN
  gSuplCols := &apos;comanda c, comanda1 c1, intrari i, intrari1 i1, nartobj o, programf pf, programf1 pf1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
     NAV_CodDoc,
     NAV_TipDoc,
     Doc,
     CmdInt,
     Produs,
     FB,
     Cant,
     Ordine,
     DataDoc,
     restpr,
     restnpr,
     rest&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
    select 
      c.codcomanda NAV_CodDoc,
      c.tipdoc NAV_TipDoc,
      c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) doc, 
      c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) cmdint,
      o.denumire produs, 
      null PF, 
      c1.cantacceptat cant, 
      0 ordine, 
      c.datadoc,
      0 restpr,
      c1.cantacceptat restnpr,
      c1.cantacceptat rest
      &apos;||gUserAlias||&apos;
    from comanda c
         inner join comanda1 c1 on c.codcomanda = c1.codcomanda
         inner join nartobj o on o.codobiect = c1.codobiect
         left join intrari i on i.codintr = o.codobiect - o.codobiect
         left join intrari1 i1 on i1.codintr1 = o.codobiect - o.codobiect
         left join programf pf on pf.codprogramf = o.codobiect - o.codobiect
         left join programf1 pf1 on pf.codprogramf = o.codobiect - o.codobiect
         &apos;||gSuplJoins||&apos;     
    where c.anulat = 0 and c.operat = 1 and c.tipdoc = 53 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;,&apos;AND&apos;)||&apos;
          and c.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) 
    union all
    select
      pf.codprogramf NAV_CodDoc,
      68 NAV_TipDoc, 
      nvl(pf.prefixdoc,&apos;&apos;PF&apos;&apos;)||&apos;&apos; &apos;&apos;||pf.nrdoc||&apos;&apos;/&apos;&apos;||to_char(pf.datainreg,&apos;&apos;dd.mm.yyyy&apos;&apos;) doc, 
      c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) cmdint,
      o.denumire produs, 
      pf.prefixdoc||&apos;&apos; &apos;&apos;||pf.nrdoc||&apos;&apos;/&apos;&apos;||to_char(pf.datainreg,&apos;&apos;dd.mm.yyyy&apos;&apos;) pf, 
      pf1.cantprogramat cant, 
      1 ordine, 
      pf.datainreg datadoc,
      pf1.cantprogramat restpr,
      - pf1.cantprogramat restnpr,
      0 rest
      &apos;||gUserAlias||&apos;
    from programf pf
         inner join programf1 pf1 on pf1.codprogramf = pf.codprogramf
         inner join comanda1 c1 on pf1.codcomanda1 = c1.codcomanda1
         inner join comanda c on c.codcomanda = c1.codcomanda
         inner join nartobj o on o.codobiect = c1.codobiect
         left join intrari i on i.codintr = o.codobiect - o.codobiect
         left join intrari1 i1 on i1.codintr1 = o.codobiect - o.codobiect
         &apos;||gSuplJoins||&apos;     
    where c.anulat = 0 and c.operat = 1 and c.tipdoc = 53 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;,&apos;AND&apos;)||&apos;
          and c.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    union all
    select
      i.codintr NAV_CodDoc,
      i.tipdoc NAV_TipDoc, 
      i.prefixdoc||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) doc, 
      c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) cmdint,
      o.denumire produs, 
      null PF, 
      i1.cant, 
      3 ordine, 
      i.datadoc,
      0 restpr,
      -i1.cant restnpr,
      -i1.cant rest
      &apos;||gUserAlias||&apos;
    from intrari i
         inner join intrari1 i1 on i1.codintr = i.codintr
         inner join comanda1 c1 on i1.codcmdint1 = c1.codcomanda1 and i1.codobiect = c1.codobiect
         inner join cmdprodmat prod on prod.tip = 0 and prod.codcomanda1 = c1.codcomanda1
         inner join comanda c on c.codcomanda = c1.codcomanda
         inner join nartobj o on c1.codobiect = o.codobiect
         left join programf pf on pf.codprogramf = o.codobiect - o.codobiect
         left join programf1 pf1 on pf.codprogramf = o.codobiect - o.codobiect
         left join intrprodlink l on prod.codcmdprodmat = l.codliniecomanda and l.codintr1 = i1.codintr1
         &apos;||gSuplJoins||&apos;     
    where c.anulat = 0 and c.operat = 1 and c.tipdoc = 53 and nvl(l.codprogramf1,0) = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;,&apos;AND&apos;)||&apos;
          and c.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          and i.anulat = 0 and i.operat = 1 and i.tipdoc = 7
    union all
    select
      i.codintr NAV_CodDoc,
      i.tipdoc NAV_TipDoc,
      i.prefixdoc||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) doc, 
      c.prefixdoc||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc,&apos;&apos;dd.mm.yyyy&apos;&apos;) cmdint,
      o.denumire produs, 
      pf.prefixdoc||&apos;&apos; &apos;&apos;||pf.nrdoc||&apos;&apos;/&apos;&apos;||to_char(pf.datainreg,&apos;&apos;dd.mm.yyyy&apos;&apos;) PF, 
      i1.cant, 
      2 ordine, 
      i.datadoc,
      -i1.cant restpr,
      0 restnpr,
      -i1.cant rest
      &apos;||gUserAlias||&apos;
    from intrari i
         inner join intrari1 i1 on i1.codintr = i.codintr
         inner join comanda1 c1 on i1.codcmdint1 = c1.codcomanda1 and i1.codobiect = c1.codobiect
         inner join comanda c on c.codcomanda = c1.codcomanda
         inner join cmdprodmat prod on prod.tip = 0 and prod.codcomanda1 = c1.codcomanda1
         inner join intrprodlink l on prod.codcmdprodmat = l.codliniecomanda and l.codintr1 = i1.codintr1
         inner join programf1 pf1 on pf1.codprogramf1 = l.codprogramf1
         inner join programf pf on pf.codprogramf = pf1.codprogramf
         inner join nartobj o on o.codobiect = c1.codobiect
         &apos;||gSuplJoins||&apos;     
    where c.anulat = 0 and c.operat = 1 and c.tipdoc = 53 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;,&apos;SUBUNITATEA&apos;,&apos;AND&apos;)||&apos;
          and c.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          and i.anulat = 0 and i.operat = 1 and i.tipdoc = 7&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_URMARIRE_PREDARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMARTPEFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30F8DDF177AD0BC6104D86B98C7D178ABF38B59E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMARTPEFURN IS

 g_CodPart   number(20);
 g_DataIni   date;
 g_DataFin   date;
 g_bToateArt boolean;
 
 gUserFields VARCHAR2(2500);
 gUserAlias  VARCHAR2(2500);
 gNullAlias  VARCHAR2(2500);
 gSuplCols   VARCHAR2(2500);
 gSuplJoins  VARCHAR2(5000);

PROCEDURE SetParamsPentruFiltru(dataFin in varchar2) is
  AnTemp    number(4);
  LunaTemp  number(2);
  AnPrec    number(4);
  LunaPrec  number(2);
BEGIN
  g_DataFin := To_Date(DataFin,&apos;dd.mm.yyyy&apos;);
  g_DataIni := Trunc(g_DataFin,&apos;MM&apos;);
  AnTemp    := EXTRACT(YEAR  FROM g_DataFin);
  LunaTemp  := EXTRACT(MONTH FROM g_DataFin);

  pkg_globals.SetLunaTemp(AnTemp, LunaTemp);
  pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec, LunaPrec);

  pkg_list_selfisamag.setAllParams(
    v_dataini    =&gt; GET_DATA_INI ,
    v_dataFin    =&gt; dataFin,
    v_DataStoc   =&gt; datafin,
    v_flgGest    =&gt; 1,
    v_flgTipCont =&gt; 1,
    v_flgArt     =&gt; 1
  );
END;

PROCEDURE SetListaParams(
	DataFin   IN VARCHAR2,
	aCodPart  IN NUMBER,
	bToateArt IN NUMBER DEFAULT 1,
  pCodJob1  IN NUMBER DEFAULT 0 )
IS
  AnTemp    number(4);
  LunaTemp  number(2);
  AnPrec    number(4);
  LunaPrec  number(2);
begin
  g_DataFin := To_Date(DataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_DATA_DINAMIC(pCODJOB1,g_DataFin);
  END IF;
  g_DataIni   := Trunc(g_DataFin,&apos;MM&apos;);
  g_CodPart   := aCodPart;
  g_bToateArt := bToateArt = 1;
  AnTemp      := EXTRACT(YEAR  FROM g_DataFin);
  LunaTemp    := EXTRACT(MONTH FROM g_DataFin);

  pkg_globals.SetLunaTemp(AnTemp, LunaTemp);
  pkg_globals.CALCULEAZA_LUNA_PRECEDENTA(AnTemp, LunaTemp, AnPrec, LunaPrec);
  pkg_globals.SetLunaPRECEDENTA(AnPrec, LunaPrec);

  pkg_list_selfisamag.setAllParams(
    v_dataini    =&gt; GET_DATA_INI ,
    v_dataFin    =&gt; GET_DATA_FIN,
    v_DataStoc   =&gt; GET_DATA_FIN,
    v_flgGest    =&gt; 1,
    v_flgTipCont =&gt; 1,
    v_flgArt     =&gt; bToateArt
  );
END;

FUNCTION GET_DATA_INI RETURN VARCHAR2 IS
BEGIN
  RETURN To_Char(g_DataIni,&apos;dd.mm.yyyy&apos;);
END;

FUNCTION GET_DATA_FIN RETURN VARCHAR2 IS
BEGIN
  RETURN To_Char(g_DataFin,&apos;dd.mm.yyyy&apos;);
END;

FUNCTION GET_CODPART RETURN NUMBER IS
BEGIN
  RETURN g_codpart;
END;

FUNCTION GET_CANT_UMPRINC(CANT in number, CODUMSEC in number) RETURN NUMBER IS
  iResult number(20,6);
BEGIN
  select cant * nvl(num1.paritate,1) into iResult from num1 where num1.codum1 = CODUMSEC;
  return nvl(iResult,CANT);
EXCEPTION
  WHEN others then return CANT;
END;

PROCEDURE setDataCodObiect is
BEGIN
  DELETE FROM TMP_LST_URMARTPEFURN;
  IF G_BTOATEART THEN
    INSERT INTO TMP_LST_URMARTPEFURN(CODOBIECT,DATA)
    SELECT DISTINCT NS.CODOBIECT, T.DATA
    FROM (
      SELECT
        TO_DATE(PKG_LIST_BASE_URMARTPEFURN.GET_DATA_INI,&apos;DD.MM.YYYY&apos;)-1 + LEVEL -1 DATA
        FROM DUAL
        CONNECT BY LEVEL &lt;= g_DataFin + 1 - g_DataIni +1
    ) T,
      NIRSTOC NS
    WHERE NS.FURN = g_CodPart;
  ELSE
    INSERT INTO TMP_LST_URMARTPEFURN(CODOBIECT,DATA)
    SELECT NOBJ.CODOBIECT,T.DATA
    FROM (
      SELECT
        TO_DATE(PKG_LIST_BASE_URMARTPEFURN.GET_DATA_INI,&apos;DD.MM.YYYY&apos;) -1 + LEVEL -1 DATA
        FROM DUAL
        CONNECT BY LEVEL &lt;= g_DataFin + 1 - g_DataIni +1
    ) T,
      NARTOBJ NOBJ
    WHERE NOBJ.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos;);
  END IF;
  COMMIT;
END;

PROCEDURE ProcessList(tmpName in varchar2, aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) is
  sInsert varchar2(25000);
  sArticole varchar2(200) := &apos;&apos;;
BEGIN
  setDataCodObiect;

  gSuplCols := &apos;nartobj nobj, nart nart&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF NOT g_bToateArt THEN
    sArticole := &apos; AND NS.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODOBIECT&apos;&apos;) &apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    DENUMIRE, DATAMISCARE, INTRARI_UM, INTRARI_UM1, INTRARI_UM2,IESIRI_UM, IESIRI_UM1,
    IESIRI_UM2, MANIPULARE_UM, MANIPULARE_UM1, MANIPULARE_UM2, STOC_FAKE_UM,
    STOC_FAKE_UM1, STOC_FAKE_UM2,stoc_data_art,stoc_data_art_um1,stoc_data_art_um2, DEN_UM, DEN_UM1,DEN_UM2&apos;||gUserFields||&apos;)
  WITH CRS_MISCARI AS (
    SELECT
      NS.CODOBIECT CODOBIECT,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN NVL(pkg_list_base_urmArtPeFurn.get_cant_umprinc(ns.cantnir,ns.umsec),0) ELSE 0 END INTRARE_UM,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN NVL(NS.CANTUM1,0) ELSE 0 END INTRARE_UM1,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN NVL(NS.CANTUM2,0) ELSE 0 END INTRARE_UM2,
      0 IESIRE_UM,
      0 IESIRE_UM1,
      0 IESIRE_UM2,
      NIR.DATANIR  DATAMISCARE,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN abs(pkg_list_base_urmArtPeFurn.get_cant_umprinc(NS.CANTNIR,ns.umsec)) ELSE 0 END stoc_fake_UM,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN abs(NS.CANTUM1) ELSE 0 END stoc_fake_UM1,
      CASE WHEN NIR.TIPNIR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) THEN abs(NS.CANTUM2) ELSE 0 END stoc_fake_UM2
    FROM  NIRSTOC NS
      LEFT JOIN NIR ON NS.CODNIR = NIR.CODNIR
      LEFT JOIN INTRARI INTR ON INTR.CODINTR = NIR.CODINTR
      LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST
    WHERE NS.FURN = pkg_list_base_urmArtPeFurn.GET_CODPART &apos;||pkg_list_base_utils.cond_subunit(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||sArticole||&apos;
    UNION ALL
    SELECT
      NS.CODOBIECT CODOBIECT,
      CASE
        WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) AND L1.CANT &lt; 0 THEN -pkg_list_base_urmArtPeFurn.get_cant_umprinc(L1.CANT,L1.UMSEC)
        WHEN L.TIPLIVR = 15 AND L1.CANT &gt; 0 THEN pkg_list_base_urmArtPeFurn.get_cant_umprinc(L1.CANT,L1.UMSEC)
        ELSE 0
      END INTRARE_UM,
      CASE WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) AND L1.CANTUM1 &lt; 0 THEN -L1.CANTUM1 WHEN L.TIPLIVR = 15 AND L1.CANTUM1 &gt; 0 THEN L1.CANTUM1 ELSE 0 END INTRARE_UM1,
      CASE WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,15,16,19,20,21,22,23,24) AND L1.CANTUM2 &lt; 0 THEN -L1.CANTUM2 WHEN L.TIPLIVR = 15 AND L1.CANTUM2 &gt; 0 THEN L1.CANTUM2 ELSE 0 END INTRARE_UM2,
      CASE WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) AND L1.CANT &gt; 0 THEN pkg_list_base_urmArtPeFurn.get_cant_umprinc(L1.CANT,L1.UMSEC) ELSE 0 END IESIRE,
      CASE WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) AND L1.CANTUM1 &gt; 0 THEN L1.CANTUM1 ELSE 0 END IESIRE_UM1,
      CASE WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) AND L1.CANTUM2 &gt; 0 THEN L1.CANTUM2 ELSE 0 END IESIRE_UM2,
      nvl(l.datalivr,nir.datanir) DATAMISCARE,
      CASE
        WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) THEN -pkg_list_base_urmArtPeFurn.get_cant_umprinc(L1.CANT,L1.UMSEC)
        WHEN L.TIPLIVR = 15 THEN ABS(pkg_list_base_urmArtPeFurn.get_cant_umprinc(L1.CANT,L1.UMSEC))
        ELSE 0
      END stoc_fake_UM,
      CASE
        WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) THEN -L1.CANTUM1
        WHEN L.TIPLIVR = 15 THEN ABS(L1.CANTUM1)
        ELSE 0
      END stoc_fake_UM1,
      CASE
        WHEN L.TIPLIVR IN (1,2,3,4,5,6,7,14,16,19,20,21,22,23,24) THEN -L1.CANTUM2
        WHEN L.TIPLIVR = 15 THEN ABS(L1.CANTUM2)
        ELSE 0
      END stoc_fake_UM2
    FROM LIVR L
      LEFT JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIR ON NS.CODNIR = NIR.CODNIR
      LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST
    WHERE NS.FURN = pkg_list_base_urmArtPeFurn.GET_CODPART &apos;||pkg_list_base_utils.cond_subunit(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||sArticole||&apos;
    UNION ALL
    SELECT
      NS.CODOBIECT,
      0 INTRARI_UM,
      0 INTRARI_UM1,
      0 INTRARI_UM2,
      0 IESIRI_UM,
      0 IESIRI_UM1,
      0 IESIRI_UM2,
      TO_DATE(pkg_list_base_urmArtPeFurn.GET_DATA_INI, &apos;&apos;DD.MM.YYYY&apos;&apos;) - 1 DATAMISCARE,
      SUM(NL.REST) STOC_FAKE_UM,
      SUM(NL.RESTUM1) STOC_FAKE_UM1,
      SUM(NL.RESTUM2) STOC_FAKE_UM2
    FROM NIRLUNA NL
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
      LEFT JOIN NIR ON NS.CODNIR = NIR.CODNIR
      LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST
    WHERE NS.FURN = pkg_list_base_urmArtPeFurn.GET_CODPART &apos;||pkg_list_base_utils.cond_subunit(&apos;NG&apos;,&apos;CODSUBUNIT&apos;)||sArticole||&apos;
    GROUP BY NS.CODOBIECT
  ),
  CRS_GRUP AS (
    SELECT
      C_DATA.CODOBIECT,C_DATA.DATA DATAMISCARE,
      NVL(SUM(MISC.INTRARE_UM),0) INTRARI_UM,
      NVL(SUM(MISC.INTRARE_UM1),0) INTRARI_UM1,
      NVL(SUM(MISC.INTRARE_UM2),0) INTRARI_UM2,
      NVL(SUM(MISC.IESIRE_UM),0) IESIRI_UM,
      NVL(SUM(MISC.IESIRE_UM1),0) IESIRI_UM1,
      NVL(SUM(MISC.IESIRE_UM2),0) IESIRI_UM2,
      NVL(SUM(MISC.INTRARE_UM),0) + NVL(SUM(MISC.IESIRE_UM),0) MANIPULARE_UM,
      NVL(SUM(MISC.INTRARE_UM1),0) + NVL(SUM(MISC.IESIRE_UM1),0) MANIPULARE_UM1,
      NVL(SUM(MISC.INTRARE_UM2),0) + NVL(SUM(MISC.IESIRE_UM2),0) MANIPULARE_UM2,
      NVL(SUM(MISC.STOC_FAKE_UM),0) STOC_FAKE_UM,
      NVL(SUM(MISC.STOC_FAKE_UM1),0) STOC_FAKE_UM1,
      NVL(SUM(MISC.STOC_FAKE_UM2),0) STOC_FAKE_UM2
    FROM TMP_LST_URMARTPEFURN C_DATA
      LEFT JOIN CRS_MISCARI MISC ON C_DATA.CODOBIECT = MISC.CODOBIECT AND C_DATA.DATA = MISC.DATAMISCARE
    GROUP BY C_DATA.CODOBIECT,C_DATA.DATA
  )
  SELECT
    NOBJ.DENUMIRE, C_GRUP.DATAMISCARE, C_GRUP.INTRARI_UM, C_GRUP.INTRARI_UM1, C_GRUP.INTRARI_UM2, C_GRUP.IESIRI_UM, C_GRUP.IESIRI_UM1, C_GRUP.IESIRI_UM2,
    C_GRUP.MANIPULARE_UM, C_GRUP.MANIPULARE_UM1, C_GRUP.MANIPULARE_UM2, C_GRUP.STOC_FAKE_UM, C_GRUP.STOC_FAKE_UM1, C_GRUP.STOC_FAKE_UM2 ,
    sum(c_grup.stoc_fake_um)  over (partition by nobj.denumire order by nobj.denumire,c_grup.datamiscare rows between unbounded preceding and current row ) stoc_data_art ,
    sum(c_grup.stoc_fake_um1) over (partition by nobj.denumire order by nobj.denumire,c_grup.datamiscare rows between unbounded preceding and current row ) stoc_data_art_um1 ,
    sum(c_grup.stoc_fake_um2) over (partition by nobj.denumire order by nobj.denumire,c_grup.datamiscare rows between unbounded preceding and current row ) stoc_data_art_um2 ,
    UM.DEN_UM DEN_UM, UM1.DEN_UM DEN_UM1, UM2.DEN_UM DEN_UM2&apos;||gUserAlias||&apos;
  FROM CRS_GRUP C_GRUP
    INNER JOIN NARTOBJ NOBJ ON C_GRUP.CODOBIECT = NOBJ.CODOBIECT
    INNER JOIN NART NART ON NART.CODARTICOL = NOBJ.CODARTICOL
    LEFT JOIN  NUM  UM ON UM.CODUM = NART.UM
    LEFT JOIN  NUM  UM1 ON UM1.CODUM = NART.UM1
    LEFT JOIN  NUM  UM2 ON UM2.CODUM = NART.UM2 &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END pkg_list_base_urmArtPeFurn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>272956A31D6503670DF92B58CD6A6C6A9BA8DFA8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMBUGET is

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);
pFiltru     VARCHAR2(1000);

procedure SetParams(aFiltruNrInv in varchar2) is
begin
  pFiltru := aFiltruNrInv;
end;  

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert VARCHAR2(10000);
sSelect VARCHAR2(20000);
sFiltru VARCHAR2(1100);
BEGIN
  -- initializate coloanele suplimentare aici ca sa nu se duplice Tablele tip extensie la lansari ulterioare
  gSuplCols := &apos;NARTOBJ OBJ, NART ART, NARTOBJ IMB, comanda cmd, intrari intr&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;&apos;;
  if Length(pFiltru) &gt; 0 then
    sFiltru := &apos; and mf.nrinventar in (&apos;||pFiltru||&apos;) &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    NAV_CodDoc,
    NAV_TipDoc,
    NrInventar,
    Articol,   
    TipDocument,
    NrDoc,     
    DataDoc,   
    ValBuget,  
    ValDoc,    
    Rest_fake1,
    Obs,
    TipDocumentCmd,
    NrDocCmd,     
    DataDocCmd,   
    ValDocCmd,    
    Rest_fake2,      
    ObsCmd,
    Stadiu,
    IndexLocal,
    Imbunatatire,
    Partener &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    nvl(NEST.codintr, NEST.CODCOMANDA),
    nvl(NEST.TIPintr, NEST.TIPCOMANDA),
    MF.NrInventar,
    OBJ.DENUMIRE Articol, 
    case when nest.nrdoc is null then &apos;&apos;&apos;&apos; else &apos;&apos;Factura intrare&apos;&apos; end TipDocument,
    NEST.NrDoc,       
    NEST.DataDoc,       
    0 ValBuget,
    NEST.ValDoc,    
    - NEST.ValDoc RestFake1,        
    NEST.Obs, 
    case when nest.nrdoccmd is null then &apos;&apos;&apos;&apos; else &apos;&apos;Comanda furnizor&apos;&apos; end TipDocumentCmd,
    NEST.NrDocCmd,       
    NEST.DataDocCmd,       
    NEST.ValDocCmd,    
    case 
      when nest.codintr &gt; 0 then - NEST.ValDoc 
      else - nvl(NEST.ValDocCmd, NEST.ValDoc)
    end RestFake2,        
    NEST.ObsCmd, 
    &apos;&apos; &apos;&apos; Stadiu, 
    2 IndexLocal,
    NEST.IMBUNATATIRE,
    NEST.Partener &apos;||
    gUserAlias||&apos;
  FROM mifix mf
     inner join bugetmf b on b.codmifix = mf.codmifix
     inner join mifix1 mf1 on mf1.codmifix = mf.codmifix
     inner join nirstoc ns on ns.codnirstoc = mf1.codnirstoc
     inner join nartobj obj on obj.codobiect = ns.codobiect
     left join (
                 select cmd.codmifix codmfcmd, cmd.nrdoc nrdoccmd, cmd.datadoc datadoccmd, cmd.valdoc valdoccmd, cmd.obs obscmd, 
                        nvl(cmd.den_part,intr.den_part) partener,
                        intr.codmifix codmfintr, intr.nrdoc, intr.datadoc, intr.valdoc, intr.obs,
                        nvl(cmd.denumire,intr.denumire) imbunatatire,
                        cmd.codcomanda, cmd.tipdoc tipcomanda,
                        intr.codintr, intr.tipdoc tipintr
                 from 
                   (select c1.codcomanda1, c1.codmifix, l.codintr1, 
                           nvl(l.cant,(c1.cantacceptat - nvl(storno.cant,0))) * c1.pu * decode(nvl(c.moneda,0),0,1,nvl(c.curs,1)) valdoc, p.den_part,
                           obj.denumire, c.obs, c.datadoc, c.nrdoc,
                           c.codcomanda, c.tipdoc
                    from comanda1 c1 
                         inner join comanda c on c.codcomanda = c1.codcomanda
                         inner join npart p on p.codpart = c.partener 
                         inner join nartobj obj on obj.codobiect = c1.codobiect
                         inner join bugetmf b on b.codmifix = c1.codmifix
                         inner join mifix mf on mf.codmifix = b.codmifix
                         INNER JOIN (SELECT MIN(DATABUGET) DATABUGET, CODBUGETMF FROM BUGETMF1 GROUP BY CODBUGETMF) DATAREF ON DATAREF.CODBUGETMF = B.CODBUGETMF
                         left join intrlink l on l.codliniecomanda = c1.codcomanda1
                         left  join (select l.codliniecomanda, sum(l.cant) cant from cmdlivrlink l group by l.codliniecomanda) storno on storno.codliniecomanda = c1.codcomanda1
                    where c.tipdoc = 8 and nvl(c.anulat,0) = 0 and c.datadoc &gt;= dataref.databuget
                    &apos;||sFiltru||&apos;
                    ) cmd 
                    full join (select l.codliniecomanda codcomanda1, i1.codmifix, i1.codintr1, i1.cant * i1.pu * 
                                      decode(nvl(i.moneda,0),0,1,nvl(i.curs,1)) valdoc, p.den_part,
                                      obj.denumire, i.obs, i.datadoc, i.nrdoc,
                                      i.codintr, i.tipdoc
                               from intrari1 i1
                                    inner join intrari i on i.codintr = i1.codintr
                                    inner join npart p on i.partener = p.codpart 
                                    inner join nartobj obj on obj.codobiect = i1.codobiect
                                    inner join bugetmf b on b.codmifix = i1.codmifix
                                    INNER JOIN (SELECT MIN(DATABUGET) DATABUGET, CODBUGETMF FROM BUGETMF1 GROUP BY CODBUGETMF) DATAREF ON DATAREF.CODBUGETMF = B.CODBUGETMF
                                    inner join mifix mf on mf.codmifix = b.codmifix
                                    left join intrlink l on i1.codintr1 = l.codintr1
                                    left join comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
                                    left join comanda c on c1.codcomanda = c.codcomanda
                               where nvl(i.anulat,0) = 0 and i.datadoc &gt;= dataref.databuget
                               &apos;||sFiltru||&apos;
                               ) intr on intr.codcomanda1 = cmd.codcomanda1 and intr.codintr1 = cmd.codintr1 and cmd.codmifix = intr.codmifix
                ) nest on nest.codmfintr = mf.codmifix or nest.codmfcmd = mf.codmifix
     left join comanda cmd on cmd.codcomanda = nest.codcomanda
     left join intrari intr on intr.codintr = nest.codintr           
  &apos;||gSuplJoins||&apos;              
  where mf1.anstart * 12 + mf1.lunastart = (select max(anstart * 12 + lunastart) from mifix1 where codmifix = mf1.codmifix)
  &apos;||sFiltru||&apos;
  UNION ALL
  SELECT
    NEST.CODCOMANDA,
    NEST.TIPCOMANDA,
    MF.NrInventar,
    OBJ.DENUMIRE Articol, 
    &apos;&apos;&apos;&apos; TipDocument,
    NEST.NrDoc,       
    NEST.DataDoc,       
    0 ValBuget,
    NEST.ValDoc,    
    - NEST.ValDoc RestFake1,        
    NEST.Obs, 
    case when nest.nrdoccmd is null then &apos;&apos;&apos;&apos; else &apos;&apos;Comanda furnizor&apos;&apos; end TipDocumentCmd,
    NEST.NrDocCmd,       
    NEST.DataDocCmd,       
    NEST.ValDocCmd,    
    case 
      when nest.codintr &gt; 0 then - NEST.ValDoc 
      else - nvl(NEST.ValDocCmd, NEST.ValDoc)
    end RestFake2,        
    NEST.ObsCmd, 
    &apos;&apos; &apos;&apos; Stadiu, 
    2 IndexLocal,
    NEST.IMBUNATATIRE,
    NEST.Partener &apos;||
    gUserAlias||&apos;
  FROM mifix mf
     inner join bugetmf b on b.codmifix = mf.codmifix
     inner join mifix1 mf1 on mf1.codmifix = mf.codmifix
     inner join nirstoc ns on ns.codnirstoc = mf1.codnirstoc
     inner join nartobj obj on obj.codobiect = ns.codobiect
     inner join (
                 select cmd.codmifix codmfcmd, cmd.nrdoc nrdoccmd, cmd.datadoc datadoccmd, cmd.valdoc valdoccmd, cmd.obs obscmd, 
                        cmd.den_part partener,
                        NULL codmfintr, NULL nrdoc, NULL datadoc, NULL valdoc, NULL obs,
                        cmd.denumire imbunatatire,
                        cmd.codcomanda, cmd.tipdoc tipcomanda,
                        NULL codintr, NULL tipintr
                 from 
                   (select c1.codcomanda1, c1.codmifix, null codintr1, 
                           (c1.cantacceptat - nvl(storno.cant,0) - stinse.cant) * c1.pu * decode(nvl(c.moneda,0),0,1,nvl(c.curs,1)) valdoc, p.den_part,
                           obj.denumire, c.obs, c.datadoc, c.nrdoc,
                           c.codcomanda, c.tipdoc
                    from comanda1 c1 
                         inner join comanda c on c.codcomanda = c1.codcomanda
                         inner join npart p on p.codpart = c.partener 
                         inner join nartobj obj on obj.codobiect = c1.codobiect
                         inner join bugetmf b on b.codmifix = c1.codmifix
                         inner join mifix mf on mf.codmifix = b.codmifix
                         INNER JOIN (SELECT MIN(DATABUGET) DATABUGET, CODBUGETMF FROM BUGETMF1 GROUP BY CODBUGETMF) DATAREF ON DATAREF.CODBUGETMF = B.CODBUGETMF
                         inner join (select sum(l.cant) cant, l.codliniecomanda from intrlink l group by l.codliniecomanda) stinse on stinse.codliniecomanda = c1.codcomanda1
                         left  join (select l.codliniecomanda, sum(l.cant) cant from cmdlivrlink l group by l.codliniecomanda) storno on storno.codliniecomanda = c1.codcomanda1
                    where c.tipdoc = 8 and nvl(c.anulat,0) = 0 and c.datadoc &gt;= dataref.databuget
                          and c1.cantacceptat - stinse.cant &gt; 0
                          &apos;||sFiltru||&apos;
                    ) cmd 
                ) nest on nest.codmfintr = mf.codmifix or nest.codmfcmd = mf.codmifix
     left join comanda cmd on cmd.codcomanda = nest.codcomanda
     left join intrari intr on intr.codintr = nest.codintr           
    &apos;||gSuplJoins||&apos;              
    where mf1.anstart * 12 + mf1.lunastart = (select max(anstart * 12 + lunastart) from mifix1 where codmifix = mf1.codmifix)
    &apos;||sFiltru||&apos;
  UNION ALL
  SELECT
    BMF.CODBUGETMF,
    91,
    MF.NrInventar,
    OBJ.DENUMIRE Articol, 
    BMF1.DENUMIRE TipDocument,
    0 NRDOC,       
    BMF1.DataBuget DataDoc,       
    BMF1.Valoare ValBuget,
    0 ValDoc,    
    CASE WHEN nvl(bmf1.stadiu,0) IN (1,3) THEN BMF1.Valoare ELSE 0 END Rest_fake1,        
    BMF1.Obs, 
    &apos;&apos;&apos;&apos; TipDocumentCmd,
    0 NRDOCCMD,       
    BMF1.DataBuget DataDocCmd,       
    0 ValDocCmd,    
    CASE WHEN nvl(bmf1.stadiu,0) IN (1,3) THEN BMF1.Valoare ELSE 0 END Rest_fake2,        
    BMF1.Obs ObsCmd, 
    case 
      when nvl(bmf1.stadiu,0) = 0 then &apos;&apos;...nedefinit...&apos;&apos;
      when nvl(bmf1.stadiu,0) = 1 then &apos;&apos;Aprobat&apos;&apos;
      when nvl(bmf1.stadiu,0) = 2 then &apos;&apos;Reanaliza&apos;&apos;
      when nvl(bmf1.stadiu,0) = 3 then &apos;&apos;Inchis&apos;&apos;
    end Stadiu, 1 IndexLocal,
    &apos;&apos;&apos;&apos; Imbunatatire,
    &apos;&apos;&apos;&apos; Partener &apos; ||gUserAlias||&apos;
  FROM BUGETMF1 BMF1
       INNER JOIN BUGETMF BMF ON BMF.CODBUGETMF = BMF1.CODBUGETMF
       INNER JOIN MIFIX1 MF1 ON MF1.CODMIFIX = BMF.CODMIFIX
       INNER JOIN MIFIX MF ON MF1.CODMIFIX = MF.CODMIFIX
       INNER JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
       INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
       LEFT JOIN NARTOBJ IMB ON IMB.CODOBIECT = OBJ.CODOBIECT - OBJ.CODOBIECT
       left join comanda cmd on cmd.codcomanda = OBJ.CODOBIECT - OBJ.CODOBIECT
       left join intrari intr on intr.codintr = OBJ.CODOBIECT - OBJ.CODOBIECT
       &apos;||gSuplJoins||&apos;
  WHERE MF1.ANSTART*12+MF1.LUNASTART = (SELECT MAX(MF2.ANSTART*12+MF2.LUNASTART) FROM MIFIX1 MF2 WHERE MF2.CODMIFIX = MF1.CODMIFIX AND MF2.ANSTART*12+MF2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
  &apos;||sFiltru;

  --delete x;
  --insert into x(test) values(sselect);
  --commit;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

end PKG_LIST_BASE_URMBUGET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F70CA9E2582EF6EA4F8E3F9D6CE2D9FCE7A2B57A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCOMCLI IS

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect1 VARCHAR2(9000);
  sSelect2 VARCHAR2(9000);
  sSelect3 VARCHAR2(9000);
  sJoinAux VARCHAR2(1000);
  sPer     VARCHAR2(1000);
  sFiltruInchise varchar2(30) := &apos;&apos;;
BEGIN
  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj o, nart art, num1 u, npart p, iesiri1 i1, iesiri i, comanda cst, comanda1 cst1, nclasea cla, nclasep clp, traseulivr t, &apos;||
    &apos;npart prod, ncarsupart cs, nparttr d, nagenda slvr, nlocalit llivr, njudet jlivr, ntari tlivr&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;, &apos;CV&apos;, &apos;CV.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;, &apos;CV1&apos;, &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  if not PKG_LIST_ALEGPERIOADA.optiunea1 then
    sFiltruInchise := &apos; AND C.INCHISA = 0 &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, Com, Doc, Part,
    Art, UM, Cant, CantCom, CantPrel, RestC, RestV,
    NrLinCom, Ordine,
    DenLaCli, CodLaCli,
    CodListat,
    SUBUNITATEA&apos;||
    gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    c.codcomanda, c.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc,c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, c1.cantacceptat/u.paritate, c1.cantacceptat/u.paritate, 0, c1.cantacceptat/u.paritate, c1.cantacceptat*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 0,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on cla.codclasea =art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on t.codtraseulivr = slvr.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 18 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND c.DataDoc &apos;||sPer;

  sSelect2 := &apos;
  SELECT
    cst.codcomanda, cst.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,cst.PrefixDoc||cst.NrDoc||&apos;&apos;/&apos;&apos;||cst.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, cl.cant/u.paritate, -cl.cant/u.paritate, 0, -cl.cant/u.paritate, -cl.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 1,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    INNER JOIN cmdlivrlink cl ON cl.codliniecomanda = c1.codcomanda1
    INNER JOIN comanda1 cst1 ON cst1.codcomanda1 = cl.codcomanda1
    INNER JOIN comanda cst ON cst.codcomanda = cst1.codcomanda
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on slvr.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 18 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0
    AND cl.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND cst.tipdoc = 65 AND cst.operat = 1 AND cst.anulat = 0
    AND c.DataDoc &apos;||sPer;

  sSelect3 := &apos;
  SELECT
    i.codies, i.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, il.cant/u.paritate, 0, il.cant/u.paritate, -il.cant/u.paritate, -il.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 2,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    INNER JOIN ieslink il ON il.codliniecomanda = c1.codcomanda1
    INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
    INNER JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on slvr.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 18 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0 AND il.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0
    AND c.DataDoc &apos;||sPer;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCOMCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F1ABC3F0F337EAAFB0AF0948A28167F9C9DB786</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCOMENZI IS

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE processlist(tmpname IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect1 VARCHAR2(9000);
  sSelect2 VARCHAR2(9000);
  sSelect3 VARCHAR2(9000);
  sSelect4 VARCHAR2(9000);
  sFiltru  VARCHAR2(1000);
BEGIN
  gSuplCols := 
    &apos;comanda c, comanda1 c1, nartobj o, nart art, num1 u, npart np, ngest ng, nsubunit ns, iesiri1 i1, iesiri i, comanda cst, comanda1 cst1, &apos;||
    &apos;nclasea cla, nclasep clp, traseulivr t, npart prod, ncarsupart cs, nparttr d, npers agent&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;, &apos;CVC&apos;, &apos;CVC.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;, &apos;CVC1&apos;, &apos;CVC1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI&apos;, &apos;CVI&apos;, &apos;CVI.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDI1&apos;, &apos;CVI1&apos;, &apos;CVI1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sFiltru := &apos;
    AND c.tipdoc IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;) &apos;;

  sFiltru := sFiltru||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;, &apos;DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)&apos;, &apos;
    AND &apos; );

  IF PKG_LIST_SELCOMENZI.DupaData THEN
    sFiltru := sFiltru||&apos;
    AND c.datadoc &apos;|| PKG_LIST_SELCOMENZI.Perioada;
  ELSE
    sFiltru := sFiltru||&apos;
    AND (c.luna + c.an * 12) &apos;|| PKG_LIST_SELCOMENZI.Perioada;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, Com, Doc,
    Part,
    Art, UM, Cant, CantCom, CantPrel, RestC, RestV,
    NrLinCom, Ordine,
    DenLaCli, CodLaCli,
    CodListat,
    SUBUNITATEA&apos;||
    gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
	SELECT
    c.codcomanda, c.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc,c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc,
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part),
    o.denumire, u.den_um1, c1.cantacceptat/u.paritate, c1.cantacceptat/u.paritate, 0, c1.cantacceptat/u.paritate, c1.cantacceptat*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 0 ,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    LEFT JOIN npart np ON np.codpart = c.partener
    LEFT JOIN ngest ng ON ng.codgest = c.codgest
    LEFT JOIN nsubunit ns ON ns.codsubunit = c.subunitatea
    LEFT JOIN nclasea cla on cla.codclasea =art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = np.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = c.codlocatie
    LEFT JOIN npers agent ON agent.codpers = ag.codagent
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
   -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 AND (NVL(c.inchisa, 0) = 0 or PKG_LIST_SELCOMENZI.COMINCHISE &gt; 0) &apos;||sFiltru;

  sSelect2 := &apos;
  SELECT
    cst.codcomanda, cst.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,cst.PrefixDoc||cst.NrDoc||&apos;&apos;/&apos;&apos;||cst.Datadoc,
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part),
    o.denumire, u.den_um1, cl.cant/u.paritate, 0, cl.cant/u.paritate, -cl.cant/u.paritate, -cl.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 1,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN cmdlivrlink cl ON cl.codliniecomanda = c1.codcomanda1
    INNER JOIN comanda1 cst1 ON cst1.codcomanda1 = cl.codcomanda1
    INNER JOIN comanda cst ON cst.codcomanda = cst1.codcomanda
    LEFT JOIN npart np ON np.codpart = c.partener
    LEFT JOIN ngest ng ON ng.codgest = c.codgest
    LEFT JOIN nsubunit ns ON ns.codsubunit = c.subunitatea
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = np.codclasa
    LEFT JOIN nagenda ag on c.codlocatie = ag.codagenda
    LEFT JOIN npers agent ON agent.codpers = ag.codagent
    LEFT JOIN traseulivr t on ag.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 AND (NVL(c.inchisa, 0) = 0 or PKG_LIST_SELCOMENZI.COMINCHISE &gt; 0) &apos;||sFiltru||&apos;
    AND NVL(cl.cant,0) &lt;&gt; 0 AND cst.tipdoc = 65 AND cst.operat = 1 AND cst.anulat = 0&apos;;

  sSelect3 := &apos;
  SELECT
    i.codies, i.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc,
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part),
    o.denumire, u.den_um1, il.cant/u.paritate, 0, il.cant/u.paritate, -il.cant/u.paritate, -il.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 2,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN ieslink il ON il.codliniecomanda = c1.codcomanda1
    INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
    INNER JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN npart np ON np.codpart = c.partener
    LEFT JOIN ngest ng ON ng.codgest = c.codgest
    LEFT JOIN nsubunit ns ON ns.codsubunit = c.subunitatea
    LEFT JOIN nclasea cla on cla.codclasea = art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = np.codclasa
    LEFT JOIN nagenda ag on c.codlocatie = ag.codagenda
    LEFT JOIN npers agent ON agent.codpers = ag.codagent
    LEFT JOIN traseulivr t on ag.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 AND (NVL(c.inchisa, 0) = 0 or PKG_LIST_SELCOMENZI.COMINCHISE &gt; 0) &apos;||
    sFiltru||&apos;
    AND NVL(il.cant,0) &lt;&gt; 0 AND i.operat = 1 AND i.anulat = 0&apos;;

  sSelect4 := &apos;
	SELECT
    c.codcomanda, c.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc,T.PrefixDoc||T.NrDoc||&apos;&apos;/&apos;&apos;||T.Datadoc,
    DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part),
    o.denumire, u.den_um1, L.cant/u.paritate, L.cant/u.paritate, 0, -L.cant/u.paritate, -L.cant/u.paritate*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 3 ,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN TRANSFLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
    INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = L.CODTRANSF1
    INNER JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF
    LEFT JOIN npart np ON np.codpart = c.partener
    LEFT JOIN ngest ng ON ng.codgest = c.codgest
    LEFT JOIN nsubunit ns ON ns.codsubunit = c.subunitatea
    LEFT JOIN nclasea cla on cla.codclasea =art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = np.codclasa
    LEFT JOIN nagenda ag on ag.codagenda = c.codlocatie
    LEFT JOIN npers agent ON agent.codpers = ag.codagent
    LEFT JOIN traseulivr t on t.codtraseulivr = ag.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
   -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.anulat = 0 AND c.operat = 1 AND (NVL(c.inchisa, 0) = 0 or PKG_LIST_SELCOMENZI.COMINCHISE &gt; 0) &apos;||sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
  
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_URMCOMENZI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMFACTSA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF7240C9360839E7AB968733AEBDED56918BB57E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCOMFACTSA IS

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect1 VARCHAR2(9000);
  sSelect2 VARCHAR2(9000);
  sSelect3 VARCHAR2(9000);
  sSelect4 VARCHAR2(9000);
  sJoinAux VARCHAR2(1000);
  sPer     VARCHAR2(1000);
  sFiltruInchise varchar2(30) := &apos;&apos;;
BEGIN
  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj o, nart art, num1 u, npart p, iesiri1 i1, iesiri i, comanda cst, comanda1 cst1, nclasea cla, nclasep clp, traseulivr t, &apos;||
    &apos;npart prod, ncarsupart cs, nparttr d, nagenda slvr, nlocalit llivr, njudet jlivr, ntari tlivr&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC&apos;, &apos;CV&apos;, &apos;CV.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDC1&apos;, &apos;CV1&apos;, &apos;CV1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  if not PKG_LIST_ALEGPERIOADA.optiunea1 then
    sFiltruInchise := &apos; AND C.INCHISA = 0 &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, Com, Doc, Part,
    Art, UM, Cant, CantCom, CantPrel, RestC, RestV,
    NrLinCom, Ordine,
    DenLaCli, CodLaCli,
    CodListat,
    SUBUNITATEA,
    TipRez,
    CodExtern,
    MODEL,
    MARCA,
    NRINREG,
    ANFABRICATIE,
    CULOAREC,
    SERIECAROSERIE,
    SERIEMOTOR&apos;||
    gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    c.codcomanda, c.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc,c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, c1.cantacceptat/u.paritate, c1.cantacceptat/u.paritate, 0, c1.cantacceptat/u.paritate, c1.cantacceptat*Nvl(c1.pu,0),
    c1.codcomanda1, 0,
    --ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 0,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern), 
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit, DECODE(C.FaraFactura,0,&apos;&apos;-&apos;&apos;,1,&apos;&apos;Comanda interna&apos;&apos;), o.CodExtern,
    NMo.Model, NMa.Marca, NPA.NRINREG, NPA.ANF AnFabricatie, NPA.CULOAREC,NPA.SERIEC SerieCaroserie, NPA.Seriem SerieMotor &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on cla.codclasea =art.clasa
    LEFT JOIN nclasep clp on clp.codclasep = p.codclasa
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on t.codtraseulivr = slvr.codtraseu
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN Nparccom NPC on NPC.CodComanda = C.CodComanda
    LEFT JOIN NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
    LEFT JOIN Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
    LEFT JOIN NModeleauto NMo on NMo.CodModeleauto=NPA.Model&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 92 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND NOT (C1.MODINCHIDERE=2 AND ART.TIPARTICOL=&apos;&apos;1&apos;&apos;) AND c.DataDoc  &apos;||sPer;
  sSelect2 := &apos;
  SELECT
    cst.codcomanda, cst.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,cst.PrefixDoc||cst.NrDoc||&apos;&apos;/&apos;&apos;||cst.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, cl.cant/u.paritate, -cl.cant/u.paritate, 0, -cl.cant/u.paritate, -cl.cant*Nvl(c1.pu,0),
    c1.codcomanda1, 1,
    --ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 1,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit, DECODE(C.FaraFactura,0,&apos;&apos;-&apos;&apos;,1,&apos;&apos;Comanda interna&apos;&apos;),o.CodExtern,
    NMo.Model, NMa.Marca, NPA.NRINREG, NPA.ANF AnFabricatie, NPA.CULOAREC,NPA.SERIEC SerieCaroserie, NPA.Seriem SerieMotor &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN cmdlivrlink cl ON cl.codliniecomanda = c1.codcomanda1
    INNER JOIN comanda1 cst1 ON cst1.codcomanda1 = cl.codcomanda1
    INNER JOIN comanda cst ON cst.codcomanda = cst1.codcomanda
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on slvr.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN iesiri i ON i.codies = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN iesiri1 i1 ON i1.codies1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN Nparccom NPC on NPC.CodComanda = C.CodComanda
    LEFT JOIN NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
    LEFT JOIN Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
    LEFT JOIN NModeleauto NMo on NMo.CodModeleauto=NPA.Model&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 92 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0
    AND cl.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND cst.tipdoc = 65 AND cst.operat = 1 AND cst.anulat = 0
    AND NOT (C1.MODINCHIDERE=2 AND ART.TIPARTICOL=&apos;&apos;1&apos;&apos;) AND c.DataDoc  &apos;||sPer;
  sSelect3 := &apos;
  SELECT
    i.codies, i.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, il.cant/u.paritate, 0, il.cant/u.paritate, -il.cant/u.paritate, -il.cant*Nvl(c1.pu,0),
    c1.codcomanda1, 2,
    --ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 2,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit,  DECODE(C.FaraFactura,0,&apos;&apos;-&apos;&apos;,1,&apos;&apos;Comanda interna&apos;&apos;),o.CodExtern,
    NMo.Model, NMa.Marca, NPA.NRINREG, NPA.ANF AnFabricatie, NPA.CULOAREC,NPA.SERIEC SerieCaroserie, NPA.Seriem SerieMotor &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN ieslink il ON il.codliniecomanda = c1.codcomanda1
    INNER JOIN iesiri1 i1 ON i1.codies1 = il.codies1
    INNER JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on slvr.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN Nparccom NPC on NPC.CodComanda = C.CodComanda
    LEFT JOIN NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
    LEFT JOIN Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
    LEFT JOIN NModeleauto NMo on NMo.CodModeleauto=NPA.Model&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 92 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0 AND il.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0 AND NOT (C1.MODINCHIDERE=2 AND ART.TIPARTICOL=&apos;&apos;1&apos;&apos;)
    AND c.DataDoc   &apos;||sPer;
  sSelect4 := &apos;
  SELECT
    i.codies, i.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, i1.cant/u.paritate, 0, i1.cant/u.paritate, -i1.cant/u.paritate, -i1.cant*Nvl(c1.pu,0),
    c1.codcomanda1, 3,
    --ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 2,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit,  DECODE(C.FaraFactura,0,&apos;&apos;-&apos;&apos;,1,&apos;&apos;Comanda interna&apos;&apos;),o.CodExtern,
    NMo.Model, NMa.Marca, NPA.NRINREG, NPA.ANF AnFabricatie, NPA.CULOAREC,NPA.SERIEC SerieCaroserie, NPA.Seriem SerieMotor &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN iesiri1 i1 ON i1.codcmdint1 = c1.codcomanda1
    INNER JOIN iesiri i ON i.codies = i1.codies
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda slvr on slvr.codagenda = c.codlocatie
    LEFT JOIN nlocalit llivr ON llivr.codlocalit = slvr.codlocalit
    LEFT JOIN njudet jlivr ON jlivr.codjudet = llivr.codjudet
    LEFT JOIN ntari tlivr ON tlivr.codtara = llivr.codtara
    LEFT JOIN traseulivr t on slvr.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tlivr.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    -- joinuri false pt coloane suplimentare
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN Nparccom NPC on NPC.CodComanda = C.CodComanda
    LEFT JOIN NparcAut NPA on NPA.CodNparcaut = NPC.CodNparcaut
    LEFT JOIN Nmarciauto NMa on Nma.Codmarciauto=NPA.Marca
    LEFT JOIN NModeleauto NMo on NMo.CodModeleauto=NPA.Model&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 92 AND c.operat = 1 &apos;||sFiltruInchise||&apos; AND c.anulat = 0 AND i1.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0 AND NOT (C1.MODINCHIDERE=2 AND ART.TIPARTICOL=&apos;&apos;1&apos;&apos;) 
    AND c.DataDoc  &apos;||sPer;   
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect4, aListID, aListVer);
 COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_URMCOMFACTSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCOMFURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20C2532BF16A48711D39C53CB1231FAC7607BACE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCOMFURN IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(11000);
  sSelect1 VARCHAR2(19000);
  sSelect2 VARCHAR2(19000);
  sSelect3 VARCHAR2(19000);
  sPer     VARCHAR2(11000);
BEGIN
  gSuplCols :=
    &apos;comanda c, comanda1 c1, nartobj o, nart art, num1 u, npart p, intrari1 i1, intrari i, comanda cst, comanda1 cst1, nclasea cla, nclasep clp, traseulivr t,&apos;||
    &apos;npart prod, ncarsupart cs, nparttr d &apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF&apos;, &apos;CVC&apos;, &apos;CVC.CODCOMANDA = C.CODCOMANDA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDF1&apos;, &apos;CVC1&apos;, &apos;CVC1.CODCOMANDA1 = C1.CODCOMANDA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = C1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CENTRECOST&apos;, &apos;CCOST&apos;, &apos;CCOST.CODCENTRU = NVL(C1.CODCENTRU,0)&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc,Com, Doc, Part,
    Art, UM, Cant, CantCom, CantPrel, RestC, RestV,
    NrLinCom, Ordine,
    DenLaCli, CodLaCli,
    CodListat,
    SUBUNITATEA, CATUSER, FACTURABIL,
    NIV1Stare, NIV1User, NIV2Stare, NIV2User, NIV3Stare, NIV3User, NIV4Stare, NIV4User, NIV5Stare, NIV5User, STARE&apos;||
    gUserFields||&apos;)&apos;;

  IF PKG_LIST_ALEGPERIOADA.getDataS = PKG_LIST_ALEGPERIOADA.getDataF THEN
    sPer := &apos;= TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sPer := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sSelect1 := &apos;
  select
    c.codcomanda, c.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, c1.cantacceptat/u.paritate, c1.cantacceptat/u.paritate, 0, c1.cantacceptat/u.paritate, c1.cantacceptat*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 0 ,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit, WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(c.USerId), CASE WHEN Nvl(c.nrmaxaprobari,0) &lt;= Nvl(Aprob.NRAprob,0) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    DECODE(Aprob.Niv1Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv1User,
    DECODE(Aprob.Niv2Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv2User,
    DECODE(Aprob.Niv3Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv3User,
    DECODE(Aprob.Niv4Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv4User,
    DECODE(Aprob.Niv5Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv5User,
    CASE
      WHEN c.FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &lt;&gt; 0 AND (SELECT NVL(COUNT(*), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA AND NVL(CTMP1.CANTACCEPTAT, 0) &gt; 0 AND NVL(CTMP1.RESTACCEPTAT, 0) &gt; 0) = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &gt; (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA)  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
      ELSE &apos;&apos;&apos;&apos;
    END STARE &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda ag on c.codlocatie = ag.codagenda
    LEFT JOIN traseulivr t on ag.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(Decode(ca.stare,1,1,0)) NRAprob,
        Max(Decode(ca.nivel,1,ca.stare)) Niv1Stare, Max(Decode(ca.nivel,1,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv1User,
        Max(Decode(ca.nivel,2,ca.stare)) Niv2Stare, Max(Decode(ca.nivel,2,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv2User,
        Max(Decode(ca.nivel,3,ca.stare)) Niv3Stare, Max(Decode(ca.nivel,3,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv3User,
        Max(Decode(ca.nivel,4,ca.stare)) Niv4Stare, Max(Decode(ca.nivel,4,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv4User,
        Max(Decode(ca.nivel,5,ca.stare)) Niv5Stare, Max(Decode(ca.nivel,5,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv5User
      FROM comanda c INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda
    -- joinuri false pt coloane suplimentare
    LEFT JOIN intrari1 i1 ON i1.codintr1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN intrari i ON i.codintr = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND c.DataDoc &apos;||sPer;

  sSelect2 := &apos;
  SELECT
    cst.codcomanda, cst.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,cst.PrefixDoc||cst.NrDoc||&apos;&apos;/&apos;&apos;||cst.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, cl.cant/u.paritate, -cl.cant/u.paritate, 0, -cl.cant/u.paritate, -cl.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 1,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit,WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(c.USerId), CASE WHEN Nvl(c.nrmaxaprobari,0) &lt;= Nvl(Aprob.NRAprob,0) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    DECODE(Aprob.Niv1Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv1User,
    DECODE(Aprob.Niv2Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv2User,
    DECODE(Aprob.Niv3Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv3User,
    DECODE(Aprob.Niv4Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv4User,
    DECODE(Aprob.Niv5Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv5User,
    CASE
      WHEN c.FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &lt;&gt; 0 AND (SELECT NVL(COUNT(*), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA AND NVL(CTMP1.CANTACCEPTAT, 0) &gt; 0 AND NVL(CTMP1.RESTACCEPTAT, 0) &gt; 0) = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &gt; (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA)  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
      ELSE &apos;&apos;&apos;&apos;
    END STARE &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    INNER JOIN cmdlivrlink cl ON cl.codliniecomanda = c1.codcomanda1
    INNER JOIN comanda1 cst1 ON cst1.codcomanda1 = cl.codcomanda1
    INNER JOIN comanda cst ON cst.codcomanda = cst1.codcomanda
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda ag on c.codlocatie = ag.codagenda
    LEFT JOIN traseulivr t on ag.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(Decode(ca.stare,1,1,0)) NRAprob,
        Max(Decode(ca.nivel,1,ca.stare)) Niv1Stare, Max(Decode(ca.nivel,1,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv1User,
        Max(Decode(ca.nivel,2,ca.stare)) Niv2Stare, Max(Decode(ca.nivel,2,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv2User,
        Max(Decode(ca.nivel,3,ca.stare)) Niv3Stare, Max(Decode(ca.nivel,3,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv3User,
        Max(Decode(ca.nivel,4,ca.stare)) Niv4Stare, Max(Decode(ca.nivel,4,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv4User,
        Max(Decode(ca.nivel,5,ca.stare)) Niv5Stare, Max(Decode(ca.nivel,5,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv5User
      FROM comanda c INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda
    -- joinuri false pt coloane suplimentare
    LEFT JOIN intrari1 i1 ON i1.codintr1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN intrari i ON i.codintr = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 8 AND c.operat = 1 AND NVL(c.inchisa, 0) = 0 AND c.anulat = 0
    AND cl.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND cst.tipdoc = 66 AND cst.operat = 1 AND cst.anulat = 0
    AND c.DataDoc &apos;||sPer;

  sSelect3 := &apos;
  SELECT
    i.codintr, i.tipdoc, c.PrefixDoc||c.NrDoc||&apos;&apos;/&apos;&apos;||c.Datadoc Com,i.PrefixDoc||i.NrDoc||&apos;&apos;/&apos;&apos;||i.Datadoc, p.Den_Part,
    o.denumire, u.den_um1, il.cant/u.paritate, 0, il.cant/u.paritate, -il.cant/u.paritate, -il.cant*Nvl(c1.pu,0),
    ROW_NUMBER() OVER (PARTITION BY C.CodComanda ORDER BY C1.CodComanda1 ASC), 2,
    COALESCE(ac.denumire,trad.denumiretrad,o.denumire), NVL(ac.codextern,o.codextern),
    NVL(DECODE(ac.tipcodafisat,1,gre.cod,2,ac.codextern,3,o.codextern,4,o.codintern,5,o.codvamal,6,o.codplu,7,o1.codextofe),o.codextern),
    s.den_subunit, WINMADMIN.PKG_USERFIRME.GET_NUME_GRUP_USER(c.USerId), CASE WHEN Nvl(c.nrmaxaprobari,0) &lt;= Nvl(Aprob.NRAprob,0) THEN &apos;&apos;DA&apos;&apos; ELSE &apos;&apos;NU&apos;&apos; END,
    DECODE(Aprob.Niv1Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv1User,
    DECODE(Aprob.Niv2Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv2User,
    DECODE(Aprob.Niv3Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv3User,
    DECODE(Aprob.Niv4Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv4User,
    DECODE(Aprob.Niv5Stare,0,&apos;&apos;Incert&apos;&apos;,1,&apos;&apos;Aprobat&apos;&apos;,2, &apos;&apos;Respins&apos;&apos;), Niv5User,
    CASE
      WHEN c.FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) = (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) THEN &apos;&apos;NEFACTURATA&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &lt;&gt; 0 AND (SELECT NVL(COUNT(*), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA AND NVL(CTMP1.CANTACCEPTAT, 0) &gt; 0 AND NVL(CTMP1.RESTACCEPTAT, 0) &gt; 0) = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;
      WHEN (SELECT NVL(SUM(CTMP1.CANTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA) &gt; (SELECT NVL(SUM(CTMP1.RESTACCEPTAT), 0) FROM COMANDA1 CTMP1 WHERE CTMP1.CODCOMANDA = C.CODCOMANDA)  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos;
      ELSE &apos;&apos;&apos;&apos;
    END STARE &apos;||
    gUserAlias||&apos;
  FROM comanda c
    INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
    INNER JOIN nartobj o ON o.codobiect = c1.codobiect
    INNER JOIN nart art ON o.codarticol = art.codarticol
    INNER JOIN num1 u ON u.codum1 = c1.umsec
    INNER JOIN npart p ON p.codpart = c.partener
    INNER JOIN intrlink il ON il.codliniecomanda = c1.codcomanda1
    INNER JOIN intrari1 i1 ON i1.codintr1 = il.codintr1
    INNER JOIN intrari i ON i.codintr = i1.codintr
    LEFT JOIN nclasea cla on art.clasa = cla.codclasea
    LEFT JOIN nclasep clp on p.codclasa = clp.codclasep
    LEFT JOIN nagenda ag on c.codlocatie = ag.codagenda
    LEFT JOIN traseulivr t on ag.codtraseu = t.codtraseulivr
    LEFT JOIN npart prod ON prod.codpart = o.codproducator
    LEFT JOIN ncarsupart cs ON cs.codcarsupart = o.codcaract
    LEFT JOIN nparttr d ON d.codparttr = c.delegat
    LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    LEFT JOIN nlocalit loc ON loc.codlocalit = ag.codlocalit
    LEFT JOIN ntari tari ON tari.codtara = loc.codtara
    LEFT JOIN nartobjtrad trad ON trad.codlimba = tari.codlimba and trad.codobiect = c1.codobiect
    LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
    LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    LEFT JOIN oferta1 o1 ON o1.codoferta1 = c1.codsursa
    LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
    LEFT JOIN (
      SELECT
        c.codcomanda, Sum(Decode(ca.stare,1,1,0)) NRAprob,
        Max(Decode(ca.nivel,1,ca.stare)) Niv1Stare, Max(Decode(ca.nivel,1,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv1User,
        Max(Decode(ca.nivel,2,ca.stare)) Niv2Stare, Max(Decode(ca.nivel,2,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv2User,
        Max(Decode(ca.nivel,3,ca.stare)) Niv3Stare, Max(Decode(ca.nivel,3,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv3User,
        Max(Decode(ca.nivel,4,ca.stare)) Niv4Stare, Max(Decode(ca.nivel,4,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv4User,
        Max(Decode(ca.nivel,5,ca.stare)) Niv5Stare, Max(Decode(ca.nivel,5,WINMADMIN.PKG_USERFIRME.GetUserName(ca.USerId))) Niv5User
      FROM comanda c INNER JOIN cmdaprobari ca ON ca.coddoc = c.codcomanda AND ca.tipdoc = c.tipdoc
      GROUP BY c.codcomanda
    ) Aprob ON Aprob.CodComanda = C.CodComanda
    -- joinuri false pt coloane suplimentare
    LEFT JOIN comanda1 cst1 ON cst1.codcomanda1 = (c1.codcomanda-c1.codcomanda)
    LEFT JOIN comanda cst ON cst.codcomanda = (c1.codcomanda-c1.codcomanda)&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0 AND il.cant &lt;&gt; 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.operat = 1 AND i.anulat = 0
    AND c.DataDoc &apos;||sPer;
 
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
 LIST_EXECUTE_IMMEDIATE(sInsert||sSelect3, aListID, aListVer);
 COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCOMFURN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>343DB8F69B4D044EC9DABA695F480DA3169FED99</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCONTR IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  CLOB;
  sInsIes  CLOB;
  sInsIntr CLOB;
  sInsCom  CLOB;
  sSelect  CLOB;
  sSelectX CLOB;
  sData1   VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sData2   VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
BEGIN
  gSuplCols := &apos;contract c, contract1 c1, intrari intr, intrari1 intr1, iesiri ies, iesiri1 ies1, comanda com, comanda1 com1, npart p, nartobj o, num1 um, ncont ncont, nclasep clsp, npers agent&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  DELETE TMP_LST_URMCONTR;

  sInsIes := &apos;
  INSERT INTO TMP_LST_URMCONTR (
    codcontract, codcontract1,
    tipdoc, coddoc, coddoc1, idxdoc,
    intrare,
    prefixdoc, nrdoc, datadoc,
    cant,
    pretorig, pu, tva, coefdiscmaj,
    codpart, codcont,
    codcomanda1, cantsold, cantdoc
  )
  SELECT
    c.codcontract, c1.codcontract1,
    ies.tipdoc, ies.codies, ies1.codies1, ies1.indexlocal,
    0,
    ies.prefixdoc, ies.nrdoc, ies.datadoc,
    ies1.cant, ies1.pretorig, ies1.pu, ies1.tva, Coalesce(ies1.coefdiscmaj,1),
    ies.partener, Coalesce(ies1.contserv,ies1.contdiscount,0) codcont,
    ( SELECT ilc.codliniecomanda
      FROM ieslink il LEFT JOIN ieslink ilc ON ilc.codies1 = COALESCE(il.codlinieaviz, il.codies1)
      WHERE il.codies1 = ies1.codies1
    ) codcomanda1, ies1.cant, ies1.cant
  FROM iesiri ies
    INNER JOIN iesiri1 ies1 ON ies1.codies = ies.codies
    INNER JOIN contract1 c1 ON c1.codcontract1 = ies1.codcontract1
    INNER JOIN contract c ON  c.codcontract = c1.codcontract
  WHERE ies.operat = 1 AND ies.anulat = 0
    AND ies.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||&apos;
    AND ies.tipdoc &lt;&gt; &apos;||CASE WHEN PKG_LIST_ALEGPERIOADA.getCriteriu = 0 THEN 20 ELSE 26 END||
    PKG_LIST_BASE_UTILS.COND_SUBUNITINCLACTIV(&apos;C&apos;);

  sInsIntr := &apos;
  INSERT INTO TMP_LST_URMCONTR (
    codcontract, codcontract1,
    tipdoc, coddoc, coddoc1, idxdoc,
    intrare,
    prefixdoc, nrdoc, datadoc,
    cant,
    pretorig, pu, tva, coefdiscmaj,
    codpart, codcont,
    codcomanda1, cantdoc, cantsold
  )
  SELECT
    c.codcontract, c1.codcontract1,
    intr.tipdoc, intr.codintr, intr1.codintr1, intr1.indexlocal,
    1,
    intr.prefixdoc, intr.nrdoc, intr.datadoc,
    intr1.cant, intr1.pretorig, intr1.pu, intr1.tva, Coalesce(intr1.coefdiscmaj,1),
    intr.partener, Coalesce(intr1.contserv,intr1.contdiscount,0) codcont,
    ( SELECT ilc.codliniecomanda
      FROM intrlink il LEFT JOIN intrlink ilc ON ilc.codintr1 = COALESCE(il.codlinieaviz, il.codintr1)
      WHERE il.codintr1 = intr1.codintr1
    ) codcomanda1, intr1.cant, intr1.cant
  FROM intrari intr
    INNER JOIN intrari1 intr1 ON intr1.codintr = intr.codintr
    INNER JOIN contract1 c1 ON c1.codcontract1 = intr1.codcontract1
    INNER JOIN contract c ON  c.codcontract = c1.codcontract
  WHERE intr.operat = 1 AND intr.anulat = 0
    AND intr.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||&apos;
    AND intr.tipdoc &lt;&gt; &apos;||CASE WHEN PKG_LIST_ALEGPERIOADA.getCriteriu = 0 THEN 2 ELSE 9 END||
    PKG_LIST_BASE_UTILS.COND_SUBUNITINCLACTIV(&apos;C&apos;);

  sInsCom := &apos;
  INSERT INTO TMP_LST_URMCONTR (
    codcontract, codcontract1,
    tipdoc, coddoc, coddoc1, idxdoc,
    intrare,
    prefixdoc, nrdoc, datadoc,
    cant, pretorig, pu, tva, coefdiscmaj,
    codpart, codcont, cantsold, cantdoc
  )
  SELECT
    c.codcontract, c1.codcontract1,
    com.tipdoc, com.codcomanda, com1.codcomanda1, com1.indexlocal,
    CASE WHEN com.tipdoc = 8 THEN 1 ELSE 0 END,
    com.prefixdoc, com.nrdoc, com.datadoc,
    com1.cantacceptat - coalesce((select sum(l.cant) from cmdlivrlink l where l.codliniecomanda = com1.codcomanda1),0) - Coalesce(fact.cant, 0),
    com1.pretorig, com1.pu, 0 tva, Coalesce(com1.coefdiscmaj,1),
    com.partener, 0 codcont, com1.restacceptat, com1.cantacceptat
  FROM comanda com
    INNER JOIN comanda1 com1 ON com1.codcomanda = com.codcomanda
    INNER JOIN contract1 c1 ON c1.codcontract1 = Coalesce(com1.codcontract1, com1.codsursa)
    INNER JOIN contract c ON  c.codcontract = c1.codcontract
    LEFT JOIN (
      SELECT codcomanda1, sum(cant) cant
      FROM TMP_LST_URMCONTR
      GROUP BY codcomanda1
    ) fact ON fact.codcomanda1 = com1.codcomanda1
  WHERE com.operat = 1 AND com.anulat = 0
    AND coalesce(com.inchisa,0) = 0
    AND CASE WHEN com1.codcontract1 IS NOT NULL THEN 1 WHEN com1.tipsursa IN (10, 27) AND com1.codsursa IS NOT NULL THEN 1 ELSE 0 END = 1
    AND com1.restacceptat &gt; 0
    AND com.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||
    PKG_LIST_BASE_UTILS.COND_SUBUNITINCLACTIV(&apos;C&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS,
    TipDoc,
    PrefixDoc, NrDoc, DataDoc, Part, Art, Cont, UM,
    TipLin,
    NrLinC,
    CantC, CantD,
    Ord,
    RestC,
    RestCNoCom,
    Pret, PU, PD, VAL, VALTVA, CantDoc &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop,
    CASE
      WHEN tmp.intrare = 1 AND com.codcomanda IS NULL THEN &apos;&apos;Intrare&apos;&apos;
      WHEN tmp.intrare = 0 AND com.codcomanda IS NULL THEN &apos;&apos;Iesire&apos;&apos;
      WHEN tmp.intrare = 1                            THEN &apos;&apos;Comanda furnizor&apos;&apos;
      ELSE                                                 &apos;&apos;Comanda client&apos;&apos;
    END tipdoc,
    tmp.prefixdoc, tmp.nrdoc, tmp.datadoc, p.den_part, o.denumire, ncont.simbol, um.den_um1,
    CASE c1.tipobiect
      WHEN 1 THEN &apos;&apos;Avans facturat&apos;&apos;
      WHEN 2 THEN &apos;&apos;Dobanda avans&apos;&apos;
      WHEN 3 THEN &apos;&apos;Asig.baza materiala&apos;&apos;
      WHEN 4 THEN &apos;&apos;Garantie materiala&apos;&apos;
      WHEN 5 THEN &apos;&apos;Plata in natura&apos;&apos;
      ELSE &apos;&apos;Scop contract&apos;&apos;
    END TipLin,
    c1.indexlocal NrLinC,
    c1.cant/Coalesce(um.paritate,1), tmp.cant/Coalesce(um.paritate,1),
    Dense_Rank() OVER (PARTITION BY c1.codcontract1 ORDER BY tmp.datadoc, tmp.tipdoc, tmp.coddoc, tmp.idxdoc, tmp.coddoc1) Ord,
    (Coalesce(c1.cant,0) - SUM(coalesce(tmp.cantsold,0)) OVER (PARTITION BY c1.codcontract1 ORDER BY tmp.datadoc, tmp.tipdoc, tmp.coddoc, tmp.idxdoc, tmp.coddoc1 RANGE UNBOUNDED PRECEDING))/Coalesce(um.paritate,1) RestC,
    (Coalesce(c1.cant,0) - SUM(CASE WHEN com.codcomanda IS NULL THEN coalesce(tmp.cantsold,0) ELSE 0 END) OVER (PARTITION BY c1.codcontract1 ORDER BY tmp.datadoc, tmp.tipdoc, tmp.coddoc, tmp.idxdoc, tmp.coddoc1 RANGE UNBOUNDED PRECEDING))/Coalesce(um.paritate,1) RestCNoCom,
    tmp.pretorig*um.paritate, tmp.pu*um.paritate, tmp.pretorig*um.paritate*tmp.coefdiscmaj, tmp.cant*tmp.pu, tmp.tva, tmp.cantdoc &apos;||gUserAlias||&apos;
  FROM TMP_LST_URMCONTR tmp
    LEFT JOIN contract c ON  c.codcontract = tmp.codcontract
    LEFT JOIN contract1 c1 ON c1.codcontract1 = tmp.codcontract1
    LEFT JOIN intrari intr ON intr.codintr = tmp.coddoc AND intr.tipdoc = tmp.tipdoc
    LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr AND intr1.codintr1 = tmp.coddoc1
    LEFT JOIN iesiri ies ON ies.codies = tmp.coddoc AND ies.tipdoc = tmp.tipdoc
    LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies AND ies1.codies1 = tmp.coddoc1
    LEFT JOIN comanda com ON com.codcomanda = tmp.coddoc AND com.tipdoc = tmp.tipdoc
    LEFT JOIN comanda1 com1 ON com1.codcomanda = com.codcomanda AND com1.codcomanda1 = tmp.coddoc1
    LEFT JOIN npart p ON p.codpart = tmp.codpart
    LEFT JOIN nclasep clsp on p.codclasa = clsp.codclasep
    LEFT JOIN npers agent on agent.codpers = c.agent
    LEFT JOIN nartobj o ON o.codobiect = c1.codobiect
    LEFT JOIN num1 um ON um.codum1 = c1.umsec
    LEFT JOIN ncont ON ncont.codcont = tmp.codcont &apos;||
    gSuplJoins;

  sSelectX := &apos;
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, &apos;&apos;...&apos;&apos; tipdoc, intr.prefixdoc, intr.nrdoc, intr.datadoc, p.den_part, o.denumire, ncont.simbol, um.den_um1,
    Decode(c1.tipobiect,1,&apos;&apos;Avans facturat&apos;&apos;,2,&apos;&apos;Dobanda avans&apos;&apos;,3,&apos;&apos;Asig.baza materiala&apos;&apos;,4,&apos;&apos;Garantie materiala&apos;&apos;,5,&apos;&apos;Plata in natura&apos;&apos;,&apos;&apos;Scop contract&apos;&apos;) TipLin,
    c1.indexlocal NrLinC,
    c1.cant/Coalesce(um.paritate,1), 0 CantD,
    1 Ord,
    c1.cant/Coalesce(um.paritate,1) RestC,
    c1.cant/Coalesce(um.paritate,1) RestCNoCom,
    0 Pret, 0 PU, 0 PD, 0 VAL, 0 VALTVA, c1.cant/Coalesce(um.paritate,1) &apos;||gUserAlias||&apos;
  FROM contract c
    INNER JOIN contract1 c1 ON  c.codcontract = c1.codcontract
    LEFT JOIN intrari intr ON intr.codintr = 0
    LEFT JOIN intrari1 intr1 ON intr1.codintr = intr.codintr
    LEFT JOIN iesiri ies ON ies.codies = 0
    LEFT JOIN iesiri1 ies1 ON ies1.codies = ies.codies
    LEFT JOIN comanda com ON com.codcomanda = 0
    LEFT JOIN comanda1 com1 ON com1.codcomanda = com.codcomanda
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nclasep clsp on p.codclasa = clsp.codclasep
    LEFT JOIN npers agent on agent.codpers = c.agent
    LEFT JOIN nartobj o ON o.codobiect = c1.codobiect
    LEFT JOIN num1 um ON um.codum1 = c1.umsec
    LEFT JOIN ncont ON ncont.codcont = Coalesce(intr1.contserv,intr1.contdiscount,0) &apos;||
    gSuplJoins||&apos;
  WHERE c.operat = 1 AND c.anulat = 0
    AND NOT c1.codcontract1 IN (SELECT DISTINCT CodContract1 FROM TMP_LST_URMCONTR)
    AND Coalesce(c1.DataStart, c.datastart) &lt;= &apos;||sData2||&apos;
    AND Coalesce(c1.DataStop , c.datastop ) &gt;= &apos;||sData1||
    PKG_LIST_BASE_UTILS.COND_SUBUNITINCLACTIV(&apos;C&apos;);

  LIST_EXECUTE_IMMEDIATE(sInsIes , aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsIntr, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsCom , aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  IF PKG_LIST_ALEGPERIOADA.optiunea1 THEN
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelectx, aListID, aListVer);
  END IF;
  EXECUTE IMMEDIATE &apos;UPDATE &apos;|| tmpName ||&apos; SET CantC = 0 WHERE Ord &gt; 1&apos;;

  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCONTR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRABON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A815F126E100BC77A8ED51A022293CB9BAFE701</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCONTRABON IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
  sSelect  VARCHAR2(20000);
  pBancaV  NUMBER;
BEGIN
  gSuplCols := &apos;contract c, contract2 c2, iesiri i, npart p, nmonede mc, nmonede1 mc1, nmonede md &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  pBancaV := Coalesce(pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;) ;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, CONTRDATAF, CONTRMoneda, CONTRVal,
    PrefixDoc, NrDoc, DataDoc, Part, Moneda, ValDoc, TVADoc, VALTOTDOC &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, c2.data, mc.den_moneda, c2.suma,
    i.prefixdoc, i.nrdoc, i.datadoc, p.den_part, md.den_moneda, i.valdoc - i.tvadoc, i.tvadoc, i.valdoc &apos;||gUserAlias||&apos;
  FROM contract c
    INNER JOIN contract2 c2 ON c2.codcontract = c.codcontract
    LEFT JOIN iesiri i ON i.codies = c2.coddoc AND i.tipdoc = c2.tipdoc
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nmonede mc ON mc.codmoneda = c.moneda
    LEFT JOIN nmonede md ON md.codmoneda = i.moneda
    LEFT JOIN (
      SELECT CodMoneda, Max(x.codmoneda1) KEEP (Dense_Rank LAST ORDER BY X.DATA) CodMoneda1
      FROM nmonede1 x
      WHERE Nvl(x.valoare,0) &lt;&gt; 0 AND x.codbanca = &apos;||pBancaV||&apos;
      GROUP BY CodMoneda
    ) xc1 ON xc1.codmoneda = c.moneda
    LEFT JOIN nmonede1 mc1 ON mc1.codmoneda1 = xc1.codmoneda1&apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = 34 AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND c2.data BETWEEN To_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aLISTID, aLISTVER);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCONTRABON;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRARENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE81528720E88F71AF75BB4FDC65AFC319B6956B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCONTRARENDA IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sGolTMP  CLOB := &apos;TRUNCATE TABLE TMP_LST_URMCONTRARENDA&apos;;
  sInsTMP  CLOB;
  sInsert  CLOB;
  sData1    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sData2    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
BEGIN
  gSuplCols := &apos;contract c, contract1 c1, iesiri i, npart p, nmonede mc&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsTMP := &apos;INSERT INTO TMP_LST_URMCONTRARENDA (
    CODCONTRACT, CODCONTRACT1,
    CODBONA,
    CODFPN,
    CODAEPN)
  SELECT
    c.codcontract, c1.codcontract1,
    ( SELECT Nvl(I.CodIntr,0)
      FROM Intrari1 I1 INNER JOIN Intrari I on I.CodIntr = I1.CodIntr
      WHERE I.TipFactura = 20 and I.TipDoc = 4 AND I.CODCONTRACT = C.CODCONTRACT AND I1.CodContract1 = C1.CodContract1 AND RowNum = 1
    ) CODBONA,
    ( SELECT Nvl(I.CodIes, 0)
      FROM Iesiri1 I1 inner join Iesiri I on I.CodIes = I1.CodIes
      WHERE I.TipFactura = 20 and I.TipDoc = 19 AND I.CODCONTRACT = C.CODCONTRACT AND I1.CodContract1 = C1.CodContract1 AND RowNum = 1
    ) CODFPN,
    ( SELECT Nvl(I.CodIes,0)
      FROM Iesiri1 I1 inner join Iesiri I on I.CodIes = I1.CodIes
      WHERE I.TipFactura = 20 and I.TipDoc = 20 AND I.CODCONTRACT = C.CODCONTRACT AND I1.CodContract1 = C1.CodContract1 AND RowNum = 1
    ) CODAEPN
  FROM contract c
    INNER JOIN contract1 c1 ON c1.codcontract = c.codcontract
  WHERE 
		c.tipdoc = 10 AND c.tipcontract = 3 AND c.operat = 1 AND c.anulat = 0
    AND c.DataStart between &apos;||sData1||&apos; and &apos;||sData2||&apos; or c.DataStop between &apos;||sData1||&apos; and &apos;||sData2||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, CONTRPart, CONTRMoneda,
    Stopaj, CASS,
    TipLinie,
    ArtContr, UMContr, 
    PretContr, PUContr, PretStContr,  
    CantContr,
    CantGlobal, CantUnitar,
    CantPlata, ArtPlata, CantEchivPlata,
    BONAPrefixDoc, BONANrDoc, BONADataDoc,
    FPNPrefixDoc , FPNNrDoc,  FPNDataDoc,
    AEPNPrefixDoc, AEPNNrDoc, AEPNDataDoc &apos;||gUserFields||&apos;)
  SELECT
    c.codcontract NAV_CodDoc, c.tipdoc NAV_TipDoc,
    c.NrDoc CONTRNR, c.Datadoc CONTRDATA, c.DataStart CONTRDATAI, c.DataStop CONTRDATAS, p.den_part CONTRPart, mc.den_moneda CONTRMoneda,
    tstopaj.den_taxa Stopaj, tcass.den_taxa CASS,
    CASE c1.tipobiect 
      WHEN 0 THEN &apos;&apos;Scop contract&apos;&apos;
      WHEN 1 THEN &apos;&apos;Avans facturat&apos;&apos;
      WHEN 2 THEN &apos;&apos;Dobanda avans&apos;&apos;
      WHEN 3 THEN &apos;&apos;Asig.baza materiala&apos;&apos;
      WHEN 4 THEN &apos;&apos;Garantie materiala&apos;&apos;
      WHEN 5 THEN &apos;&apos;Plata in natura&apos;&apos;
    END TipLinie,
    obj1.denumire ArtContr, u.den_um1 UMContr, 
    Coalesce(C1.Pret * U.Paritate, 0) PretContr, Coalesce(C1.Pret * U.Paritate * (1 + Coalesce(C1.AdDim/ 100,0)), 0) PUContr, Coalesce(C1.PretStandard * U.Paritate, 0) PretStContr,  
    Sum(C1.Cant/U.Paritate) OVER (PARTITION BY tmp.codcontract, c1.indexlocal) CantContr,
    C1.CantGlobal, Sum(CASE WHEN Coalesce(C1.Cantglobal,0) &lt;&gt; 0 THEN C1.Cant/C1.cantglobal ELSE 0 END) OVER (PARTITION BY tmp.codcontract, c1.indexlocal) CantUnitar,
    C1.Cant/U.Paritate CantPlate, CASE WHEN Coalesce(C1.CodObiectSec,0) = 0 THEN &apos;&apos;...Plata numerar...&apos;&apos; ELSE obj2.denumire END ArtPlata, c1.LimitaCadouSec CantEchivPlata,
    bona.prefixdoc BONAPrefixDoc, bona.nrdoc BONANrDoc, bona.datadoc BONADataDoc,
    fpn.prefixdoc  FPNPrefixDoc , fpn.nrdoc  FPNNrDoc,  fpn.datadoc  FPNDataDoc,
    aepn.prefixdoc AEPNPrefixDoc, aepn.nrdoc AEPNNrDoc, aepn.datadoc AEPNDataDoc &apos;||gUserAlias||&apos;
  FROM TMP_LST_URMCONTRARENDA tmp
    LEFT JOIN contract c ON c.codcontract = tmp.codcontract
    LEFT JOIN contract1 c1 ON c1.codcontract1 = tmp.codcontract1
    LEFT JOIN ntaxe tstopaj ON tstopaj.codtaxa = c.Stopaj
    LEFT JOIN ntaxe tcass   ON tcass.codtaxa = c.CASS
    LEFT JOIN nartobj obj1 ON obj1.codobiect = c1.codobiect
    LEFT JOIN nartobj obj2 ON obj2.codobiect = c1.codobiectsec
    LEFT JOIN num1 u ON u.codum1 = c1.umsec
    LEFT JOIN intrari bona ON bona.codintr = tmp.codbona 
    LEFT JOIN iesiri  fpn  ON fpn.codies   = tmp.codfpn 
    LEFT JOIN iesiri  aepn ON aepn.codies  = tmp.codaepn
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nmonede mc ON mc.codmoneda = c.moneda&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sGolTMP, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsTMP, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCONTRARENDA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46F34D204A363BB8821F113FFF3CBD9CC32FDB54</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmcontrcom IS

  gUserFields VARCHAR2(30000);
  gUserAlias  VARCHAR2(30000);
  gNullAlias  VARCHAR2(30000);
  gSuplCols   VARCHAR2(30000);
  gSuplJoins  VARCHAR2(30000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sSelect1  CLOB;
  sSelect2  CLOB;
  sData1    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sData2    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sTabla    VARCHAR2(  100) := &apos;iesiri&apos;;
  sTabla1   VARCHAR2(  100) := &apos;iesiri1&apos;;
  sCodDoc   VARCHAR2(  100) := &apos;codies&apos;;
  sTipDoc   VARCHAR2(  100) := &apos;27&apos;;
  sAuxWhere VARCHAR2(  500);
BEGIN
  IF aLISTID = 305 THEN
    sTabla   := &apos;intrari&apos;;
    sTabla1  := &apos;intrari1&apos;;
    sCodDoc  := &apos;codintr&apos;;
    sTipDoc  := &apos;10&apos;;
  END IF;
  gSuplCols := &apos;contract c, contract1 c1, contract2 c2, notecredit nc, notecreditfact ncf, &apos;||sTabla||&apos; i, &apos;||sTabla1||&apos; i1, npart p, nartobj o, num1 um, ncont ncont, nclasep clsp, npers agent, nartobj1 objluna&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,    &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,    &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ1&apos;,   &apos;OBJLUNA&apos;, &apos;OBJLUNA.CODOBIECT = O.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF InStr(gSuplJoins,&apos; OBJLUNA &apos; ) &gt; 0  THEN
    PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
    
    sAuxWhere := &apos;
    AND &apos;||pkg_globals.anlunalucru || &apos; BETWEEN objluna.ALStart and objluna.ALStop &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, NCDATAI, NCDATAS,
    PrefixDoc, NrDoc, DataDoc, Part, Art, Cont,
    UM, Cant,
    Pret, PU, PD,
    VAL, VALTVA,
    PROCTVA, CONTRTIP &apos;||gUserFields||&apos;)&apos;;

  sSelect1 := &apos;
  SELECT
    c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, nc.datastart, nc.datastop,
    i.prefixdoc, i.nrdoc, i.datadoc, p.den_part, o.denumire, ncont.simbol,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN &apos;&apos;%&apos;&apos; ELSE um.den_um1 END UM, i1.cant/NVL(um.paritate,1) Cant,
    i1.pretorig*um.paritate Pret, i1.pu*um.paritate PU, i1.pretorig*um.paritate*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) PD,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END VAL, i1.tva VALTVA,
    CASE
      WHEN NVL(i1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = NVL(i1.tva,0) THEN 0
      WHEN i.tipdoc IN (16,21) THEN NVL(i1.tva,0) / decode(  (i1.pu * i1.cant-NVL(i1.tva,0)),0,1,(i1.pu * i1.cant-NVL(i1.tva,0))  )
      WHEN i1.pu * i1.cant = 0 THEN 0
      ELSE NVL(i1.tva,0) / decode ( (i1.pu * i1.cant),0,1,(i1.pu * i1.cant) )
    END * 100 PROCTVA, 
    CASE WHEN (select count(*) from contract cop where cop.codgeneric = c.codcontract) &gt; 0 THEN &apos;&apos;CADRU&apos;&apos; WHEN case when coalesce(c.codgeneric,0) &gt; 0 then 1 else 0 end &gt; 0 THEN &apos;&apos;SUBCONTRACT&apos;&apos; ELSE &apos;&apos;NORMAL&apos;&apos; END
     &apos;||gUserAlias||&apos;
  FROM contract c
    LEFT JOIN contract1       c1    ON c1.codcontract   = c.codcontract-c.codcontract
    INNER JOIN contract2      c2    ON c2.codcontract   = c.codcontract
    INNER JOIN notecredit     nc    ON nc.codncredit    = c2.coddoc AND nc.tipdoc = c2.tipdoc
    INNER JOIN notecreditfact ncf   ON ncf.codncredit   = nc.codncredit
    INNER JOIN &apos;||sTabla ||&apos;  i     ON i.&apos; ||sCodDoc||&apos; = ncf.coddoc AND i.tipdoc = ncf.tipdoc
    INNER JOIN &apos;||sTabla1||&apos;  i1    ON i1.&apos;||sCodDoc||&apos; = i.&apos;||sCodDoc||&apos;
    LEFT  JOIN npart          p     ON p.codpart        = i.partener
    LEFT  JOIN nclasep        clsp  on p.codclasa       = clsp.codclasep
    LEFT  JOIN npers          agent on agent.codpers    = c.agent
    LEFT  JOIN nartobj        o     ON o.codobiect      = i1.codobiect
    LEFT  JOIN num1           um    ON um.codum1        = i1.umsec
    LEFT  JOIN ncont                ON ncont.codcont    = Coalesce(i1.contserv,i1.contdiscount,0) &apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = &apos;||sTipDoc||&apos; AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||
    sAuxWhere;

  sSelect2 := &apos;
  SELECT
    distinct c.codcontract, c.tipdoc, c.NrDoc, c.Datadoc, c.DataStart, c.DataStop, null, null,
    i.prefixdoc, i.nrdoc, i.datadoc, p.den_part, o.denumire, ncont.simbol,
    um.den_um1 UM, c1.cant/NVL(um.paritate,1) CANT,
    c1.pret*um.paritate Pret, c1.pret*Coalesce(1+c1.addim/100,1)*um.paritate PU, c1.pret*Coalesce(1+c1.addim/100,1)*Coalesce(1+c1.procdisc/100,1)*um.paritate PD,
    C1.cant * C1.pret VAL, NULL VALTVA,
    NULL PROCTVA, CASE WHEN (select count(*) from contract cop where cop.codgeneric = c.codcontract) &gt; 0 THEN &apos;&apos;CADRU&apos;&apos; WHEN case when coalesce(c.codgeneric,0) &gt; 0 then 1 else 0 end &gt; 0 THEN &apos;&apos;SUBCONTRACT&apos;&apos; ELSE &apos;&apos;NORMAL&apos;&apos; END &apos;||gUserAlias||&apos;
  FROM contract c
    LEFT JOIN contract1      c1    ON c1.codcontract   = c.codcontract
    LEFT JOIN contract2      c2    ON c2.codcontract   = c.codcontract
    LEFT JOIN notecredit     nc    ON nc.codncredit    = c2.coddoc AND nc.tipdoc = c2.tipdoc
    LEFT JOIN notecreditfact ncf   ON ncf.codncredit   = nc.codncredit
    LEFT JOIN &apos;||sTabla ||&apos;  i     ON i.&apos; ||sCodDoc||&apos; = ncf.coddoc AND i.tipdoc = ncf.tipdoc AND i.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||&apos;
    LEFT JOIN &apos;||sTabla1||&apos;  i1    ON i1.&apos;||sCodDoc||&apos; = i.&apos;||sCodDoc||&apos;
    LEFT JOIN npart          p     ON p.codpart        = c.partener
    LEFT JOIN nclasep        clsp  on p.codclasa       = clsp.codclasep
    LEFT JOIN npers          agent on agent.codpers    = c.agent
    LEFT JOIN nartobj        o     ON o.codobiect      = c1.codobiect
    LEFT JOIN num1           um    ON um.codum1        = c1.umsec
    LEFT JOIN ncont                ON ncont.codcont    = Coalesce(i1.contserv,i1.contdiscount,0) &apos;||
    gSuplJoins||&apos;
  WHERE c.tipdoc = &apos;||sTipDoc||&apos; AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||&apos;
    AND i.&apos;||sCodDoc||&apos; IS NULL
    AND c.DataStop &gt;= &apos;||sData1||&apos;
    AND c.DataStart &lt;= &apos;||sData2||
    sAuxWhere;

  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect1, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect2, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCONTRCOM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRLEASING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2664FE64A0D7B636BC1F7D3249E8B12552859F74</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMCONTRLEASING IS

  vTipSold    INTEGER;   -- 0 la moment, 1 la luna de lucru

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS( pTipSold  IN INTEGER DEFAULT 0) IS
BEGIN
  vTipSold := pTipSold;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     VARCHAR2(15000);
  sSelect     VARCHAR2(20000);
  sDoc        VARCHAR2(100);
  sCodDoc     VARCHAR2(100);
  sCondCurs   VARCHAR2(500) := &apos;&apos;;
  sCondContr  VARCHAR2(500) := &apos;&apos;;
  sTipContr   VARCHAR2(100);
  sALLimita   VARCHAR2(  5) := &apos;99999&apos;;
  sALLucru    VARCHAR2(  5) := pkg_globals.AnLunaLucru;
  vDataAux    DATE;
BEGIN
  --PKG_GLOBALS.SetDebugMode(TRUE);
  gSuplCols := &apos;contract c, npart p, nmonede mc, contract0 c0p&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vDataAux    := Last_Day(To_Date(PKG_GLOBALS.GetAnLucru||&apos;.&apos;||PKG_GLOBALS.GetLunaLucru,&apos;YYYY.MM&apos;));

  IF vTipSold = 1 THEN
    sALLimita := pkg_globals.AnLunaLucru;
    sCondCurs  := &apos; AND c0.data &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
    sCondContr := &apos; AND c.datastart &lt;= To_Date(&apos;&apos;&apos;||To_Char(vDataAux,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  IF aLISTID = 241 THEN
    sDoc      := &apos;intrari&apos;;
    sCodDoc   := &apos;codintr&apos;;
    sTipContr := &apos;25&apos;;
  ELSE
    sDoc      := &apos;iesiri&apos;;
    sCodDoc   := &apos;codies&apos;;
    sTipContr := &apos;25&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, CONTRNR, CONTRDATA, CONTRDATAI, CONTRDATAS, CONTRMoneda,
    PART,
    ART,
    CONTRVal, CONTRDob, CONTRTot, CONTRAsig,
    CONTRCurs,
    FACTRata, FACTDob, FACTVal, FACTAsig,
    LUNARata, LUNADob, LUNAVal, LUNAAsig,
    SOLDRata, SOLDDob, SOLDVal, SOLDAsig &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  tmp0 AS (
    SELECT
      c.codcontract, c2.suma, c2.dobanda, c2.asigurare,
      CASE
        WHEN i.&apos;||sCodDoc||&apos; IS NOT NULL THEN i.an*12+i.luna
        WHEN c2.datadoc IS NOT NULL THEN Extract(YEAR FROM c2.datadoc)*12+Extract(MONTH FROM c2.datadoc)
        WHEN c2.nrdoc   IS NOT NULL 
         AND c2.data    IS NOT NULL THEN Extract(YEAR FROM c2.data   )*12+Extract(MONTH FROM c2.data)
        ELSE 100000
      END ALDoc
    FROM contract c
      INNER JOIN contract2 c2 ON c2.codcontract = c.codcontract
      LEFT JOIN &apos;||sDoc||&apos; i ON i.&apos;||sCodDoc||&apos; = c2.coddoc AND i.tipdoc = c2.tipdoc
    WHERE c.tipdoc = &apos;||sTipContr||&apos; AND c.operat = 1 AND c.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;)||sCondContr||&apos;
  ),
  tmp AS (
    SELECT
      codcontract,
      Sum(CASE WHEN ALDoc &lt;= &apos;||sALLimita||&apos; THEN suma      ELSE 0 END) FactRata,
      Sum(CASE WHEN ALDoc &lt;= &apos;||sALLimita||&apos; THEN dobanda   ELSE 0 END) FactDob,
      Sum(CASE WHEN ALDoc &lt;= &apos;||sALLimita||&apos; THEN asigurare ELSE 0 END) FactAsig,
      Sum(CASE WHEN ALDoc  = &apos;||sALLucru ||&apos; THEN suma      ELSE 0 END) LunaRata,
      Sum(CASE WHEN ALDoc  = &apos;||sALLucru ||&apos; THEN dobanda   ELSE 0 END) LunaDob,
      Sum(CASE WHEN ALDoc  = &apos;||sALLucru ||&apos; THEN asigurare ELSE 0 END) LunaAsig,
      Sum(CASE WHEN ALDoc  &gt; &apos;||sALLimita||&apos; THEN suma      ELSE 0 END) SoldRata,
      Sum(CASE WHEN ALDoc  &gt; &apos;||sALLimita||&apos; THEN dobanda   ELSE 0 END) SoldDob,
      Sum(CASE WHEN ALDoc  &gt; &apos;||sALLimita||&apos; THEN asigurare ELSE 0 END) SoldAsig
    FROM tmp0
    GROUP BY codcontract
  )
  SELECT
    c.codcontract NAV_CodDoc, c.tipdoc NAV_TipDoc, c.NrDoc CONTRNR, c.Datadoc CONTRDATA, c.DataStart CONTRDATAI, c.DataStop CONTRDATAS, mc.den_moneda CONTRMoneda,
    p.den_part part,
    ( SELECT vc2_nt_to_string( CAST( collect(DISTINCT o.denumire ORDER BY o.denumire) AS vc2_nt ) )
      FROM contract1 c1 INNER JOIN nartobj o ON o.codobiect = c1.codobiect
      WHERE c1.codcontract = tmp.codcontract
    ) art,
    tmp.FactRata + tmp.SoldRata CONTRVal, tmp.FactDob + tmp.SoldDob CONTRDob, tmp.FactRata + tmp.SoldRata + tmp.FactDob + tmp.SoldDob CONTRTot, c.asiganual CONTRAsig,
    CASE
      WHEN mc.codmoneda = 0 THEN 1
      ELSE
        COALESCE(
          (SELECT Max(c0.curs)    KEEP (Dense_Rank LAST  ORDER BY c0.data) FROM contract0 c0 WHERE c0.codcontract = tmp.codcontract AND c0.tiplinie = 2&apos;||sCondCurs||&apos;),
          (SELECT Max(c0.oldcurs) KEEP (Dense_Rank FIRST ORDER BY c0.data) FROM contract0 c0 WHERE c0.codcontract = tmp.codcontract AND c0.tiplinie = 2),
          NULLIF(c.curs, 0),
          1
        )
    END CONTRCurs ,
    tmp.FactRata, tmp.FactDob, tmp.FactRata + tmp.FactDob FACTVal, tmp.FactAsig,
    tmp.LunaRata, tmp.LunaDob, tmp.LunaRata + tmp.LunaDob LUNAVal, tmp.LunaAsig,
    tmp.SoldRata, tmp.SoldDob, tmp.SoldRata + tmp.SoldDob SOLDVal, tmp.soldasig&apos;||gUserAlias||&apos;
  FROM tmp
    INNER JOIN contract c ON c.codcontract = tmp.codcontract
    LEFT JOIN npart p ON p.codpart = c.partener
    LEFT JOIN nmonede mc ON mc.codmoneda = c.moneda
    LEFT JOIN contract0 c0p ON c0p.codcontract = tmp.codcontract AND c0p.tiplinie = 2 AND c0p.data &lt;= To_Date(&apos;&apos;01.&apos;||To_Char(vDataAux,&apos;mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
    gSuplJoins||&apos;
  WHERE Coalesce(c0p.codcontract0,0) = (SELECT Coalesce(Max(x.codcontract0) KEEP (Dense_Rank LAST ORDER BY x.data),0) FROM CONTRACT0 x WHERE x.codcontract = tmp.codcontract AND x.tiplinie = 2 AND x.data &lt;= To_Date(&apos;&apos;01.&apos;||To_Char(vDataAux,&apos;mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;))&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMCONTRLEASING;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F629322D1CD552152B86FB3124B802FC0AD6DCE0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmcontrrac IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  D1 date;
  D2 date;
  Luni number;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
  sSelect  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;contract contr, contract1 contr1, nparcaut pauto, nmarciauto amarca, nmodeleauto amodel, nartobj obj, num1 um, nart na, nclasea ca, comanda1 com1, comanda com, &apos;||
               &apos;iesiri1 ies1, iesiri ies, iesiri1 iesx1, iesiri iesx, npart p, nmonede mcontr, nmonede mcom, nmonede mies&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  D1 := PKG_LIST_ALEGPERIOADA.getDataS;
  D2 := PKG_LIST_ALEGPERIOADA.getDataF;
  Luni := Extract(Month from D2) - Extract(Month from D1) + 1;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc,
    CONTRNR, CONTRDATA, CONTRMONEDA, Part,
    COMNR, COMDATA, COMMONEDA,
    IesPrefix, IesNr, IesData, IesMoneda,
    OrdContr1,
    DenObj, SimbClasaA, NrAuto, MarcaAuto, ModelAuto, DenUm1,
    ContrCantX,
		ContrCant,
		ContrPret,
    ComCant, ComPU,
    IesCant, IesPu, MaxRezSimultan, MaxZileRez, TotCantCmd, Zile, TipPr  &apos;||gUserFields||&apos;)&apos;;
-- Urmarire contracte
  sSelect :=
&apos;with
CantCmd as
(Select x1.CodContract1, sum(x1.CantAcceptat) CantTot
 from Comanda1 x1 inner join Comanda x on x.codcomanda = x1.codcomanda
 Inner Join Rac_Rez R ON x.codcomanda = R.codcomanda
 where R.DataStart BETWEEN PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
 and x.Operat = 1  and x.TipDoc = 94
 and Nvl(x1.codcontract1, 0) &gt; 0
 group by x1.CodContract1),
CantCmdAll as
(Select x1.CodContract1, sum(x1.CantAcceptat) CantTot
 from Comanda1 x1 inner join Comanda x on x.codcomanda = x1.codcomanda
 Inner Join Rac_Rez R ON x.codcomanda = R.codcomanda
 where R.DataStart &lt;= PKG_LIST_ALEGPERIOADA.getDataF
 and x.Operat = 1  and x.TipDoc = 94
 and Nvl(x1.codcontract1, 0) &gt; 0
 group by x1.CodContract1)
	 SELECT
    contr.codcontract, contr.tipdoc,
    contr.NrDoc, contr.Datadoc, mcontr.simbol, p.den_part,
    com.NrDoc, com.Datadoc, mcom.simbol,
    Case when Contr1.TipPret = 1 then iesx.prefixdoc else ies.prefixdoc end prefixdoc,
		Case when Contr1.TipPret = 1 then Iesx.NrDoc else Ies.NrDoc end  NrDoc,
		Case when Contr1.TipPret = 1 then iesx.datadoc else ies.datadoc end datadoc,
		Case when Contr1.TipPret = 1 then miesx.simbol else mies.simbol end simbol,
    Row_Number() OVER (Partition BY contr1.codcontract1 ORDER BY com.datadoc, com.nrdoc, com1.codcomanda1, ies.datadoc, ies.nrdoc, iesl.codies1) OrdContr1,
    obj.denumire, ca.simbol, pauto.nrinreg, amarca.marca, amodel.model, um.den_um1,
    0 ContrCantX,
		Case when Contr1.TipPret = 3 then (&apos;||Luni||&apos;*contr1.cant)/um.paritate
		else contr1.cant/um.paritate
		end contrcant,
		contr1.pret*um.paritate contrpret,
    Nvl(com1.cantacceptat/um.paritate,0) comcant, Nvl(com1.pu*um.paritate,0) compret,
    Case when Contr1.TipPret = 1 then Nvl(iesx1.cant/um.paritate,0) else Nvl(ies1.cant/um.paritate,0) end iescant,
		Case when Contr1.TipPret = 1 then Nvl(iesx1.pu*um.paritate,0) else Nvl(ies1.pu*um.paritate,0) end iespret,
		Contr.MAXREPLSIMULTANE MaxRezSimultan, Contr.MAXZILEREPLA MaxZileRez,
		Case when Contr1.TipPret = 4 then cc1All.CantTot else cc1.CantTot end TotCantCmd,
		0 Zile,
		Case when Contr1.TipPret = 1 then &apos;&apos;lunar&apos;&apos;
         when Contr1.TipPret = 2 then &apos;&apos;pe zi&apos;&apos;
         when Contr1.TipPret = 3 then &apos;&apos;cantitativ&apos;&apos;
         when Contr1.TipPret = 4 then &apos;&apos;pachet&apos;&apos;
		end TipPr &apos;||gUserAlias||&apos;
  FROM contract contr
    INNER JOIN contract1 contr1 ON contr1.codcontract = contr.codcontract
  	LEFT JOIN CantCmd cc1 on cc1.codcontract1 = contr1.codcontract1
  	LEFT JOIN CantCmdAll cc1All on cc1All.codcontract1 = contr1.codcontract1
    LEFT JOIN nparcaut pauto ON pauto.codnparcaut = contr1.codauto
    LEFT JOIN nmarciauto amarca ON amarca.codmarciauto = pauto.marca
    LEFT JOIN nmodeleauto amodel ON amodel.codmodeleauto = pauto.model
    LEFT JOIN nartobj obj ON obj.codobiect = contr1.codobiect
    LEFT JOIN num1 um ON um.codum1 = contr1.umsec
    LEFT JOIN nart na ON na.codarticol = obj.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = na.clasa
    LEFT JOIN (select c1.* from comanda1 c1 inner JOIN comanda c ON c.codcomanda = c1.codcomanda
              	where  c.tipdoc=18
								and c.datadoc BETWEEN PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
								and C.Operat = 1
								and nvl(c1.codcontract1,0) &gt; 0) com1 ON com1.codcontract1 = contr1.codcontract1
    LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda
    LEFT JOIN ieslink iesl ON iesl.codliniecomanda = com1.codcomanda1 AND Nvl(iesl.codies1,0) &lt;&gt; 0
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = iesl.codies1
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies
  	LEFT JOIN contract2 c2 ON c2.codcontract = contr.codcontract
	  LEFT JOIN iesiri iesx ON iesx.codies = c2.coddoc AND iesx.tipdoc = c2.tipdoc
	  LEFT JOIN iesiri1 iesx1 ON iesx.codies = iesx1.codies and iesx1.CodContract1 =  Contr1.CodContract1
    LEFT JOIN npart p ON p.codpart = contr.partener
    LEFT JOIN nmonede mcontr ON mcontr.codmoneda = contr.moneda
    LEFT JOIN nmonede mcom ON mcom.codmoneda = com.moneda
    LEFT JOIN nmonede mies ON mies.codmoneda = ies.moneda
    LEFT JOIN nmonede miesx ON miesx.codmoneda = iesx.moneda &apos;||
    gSuplJoins||&apos;
  WHERE contr.tipdoc = 34 AND contr.operat = 1
   AND contr.anulat = 0
   AND contr.activ &lt;&gt; 0
	 and (contr.activ = 3 or (1=1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;contr&apos;)||&apos;))
   AND (Nvl(C2.CodContract, 0) = 0 or (c2.data is not null and c2.data BETWEEN PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF))
   and ( contr1.tippret = 1
	       or (contr1.tippret = 4 and contr1.cant &lt; nvl(cc1All.canttot,0))
	       or (contr1.tippret = 3 and &apos;||Luni||&apos;*contr1.cant &lt; nvl(cc1.canttot,0)))&apos;;
  pkg_globals.CheckDebugMode(sInsert||sSelect, aListID, aListVer);
  pkg_globals.CheckDebugMode(&apos;UPDATE &apos;|| tmpName ||&apos; SET ContrCantX = ContrCant WHERE OrdContr1 = 1&apos;, aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;|| tmpName ||&apos; SET ContrCantX = ContrCant WHERE OrdContr1 = 1&apos;, aListID, aListVer);

  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END pkg_list_base_urmcontrrac;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMCONTRRAC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41D55756BF08F5473F0A16A4D1262CEF7A586A3C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmcontrrac1 IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);
  D1 date;
  D2 date;
  Luni number;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
  sSelect  VARCHAR2(20000);
  aInd     number(20);
BEGIN
  gSuplCols := &apos;contract contr, contract1 contr1, nparcaut pauto, nmarciauto amarca, nmodeleauto amodel, nartobj obj, num1 um, nart na, nclasea ca, comanda1 com1, comanda com, &apos;||
               &apos;iesiri1 ies1, iesiri ies, npart p, nmonede mcontr, nmonede mcom, nmonede mies&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);


  D1 := PKG_LIST_ALEGPERIOADA.getDataS;
  D2 := PKG_LIST_ALEGPERIOADA.getDataF;
  Luni := Extract(Month from D2) - Extract(Month from D1) + 1;

	aInd := 1;

sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc,NAV_TipDoc,
    CONTRNR, CONTRDATA, CONTRMONEDA, Part,
    COMNR, COMDATA, COMMONEDA,
    IesPrefix, IesNr, IesData, IesMoneda,
    OrdContr1,
    DenObj, SimbClasaA, NrAuto, MarcaAuto, ModelAuto, DenUm1,
    ContrCantX,
		ContrCant,
		ContrPret,
    ComCant, ComPU,
    IesCant, IesPu, MaxRezSimultan, MaxZileRez, TotCantCmd, Zile, TipPr &apos;||gUserFields||&apos;)&apos;;
--Profitabilitate Contracte
sSelect :=
&apos;with CantCmd as
(Select x1.CodContract1, sum(x1.CantAcceptat) CantTot
 from Comanda1 x1 inner join Comanda x on x.codcomanda = x1.codcomanda
 Inner Join Rac_Rez R ON x.codcomanda = R.codcomanda
 where R.DataStart BETWEEN PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
 and x.Operat = 1 and x.TipDoc = 94
 and Nvl(x1.codcontract1, 0) &gt; 0
 group by x1.CodContract1)
 SELECT
    contr.codcontract, contr.tipdoc,
    contr.NrDoc, contr.Datadoc, mcontr.simbol, p.den_part,
    crz.NrDoc, crz.Datadoc, mcom.simbol,
    ies.prefixdoc, ies.nrdoc, ies.datadoc, mies.simbol,
    Row_Number() OVER (Partition BY contr1.codcontract1 ORDER BY crz.datadoc, crz.nrdoc, crz.codcomanda1, ies.datadoc, ies.nrdoc, iesl.codies1) OrdContr1,
    obj.denumire, ca.simbol, pauto.nrinreg, amarca.marca, amodel.model, um.den_um1,
    0 ContrCantX,
		Case when Contr1.TipPret = 3 then (&apos;||Luni||&apos;*contr1.cant)/um.paritate
		else contr1.cant/um.paritate
		end contrcant,
		contr1.pret*um.paritate contrpret,
    Nvl(crz.cantacceptat/um.paritate,0) comcant, Nvl(crz.pu*um.paritate,0) compret,
    Nvl(ies1.cant/um.paritate,0) iescant, Nvl(ies1.pu*um.paritate,0) iespret,
		Contr.MAXREPLSIMULTANE MaxRezSimultan, Contr.MAXZILEREPLA MaxZileRez, cc1.CantTot TotCantCmd,
		Case when Nvl(CRZ.TipRezervare,0) = 6 and E.Ind = &apos;||aInd||&apos; then crz.CantAcceptat else 0 end Zile,
		Case when Contr1.TipPret = 1 then &apos;&apos;lunar&apos;&apos;
         when Contr1.TipPret = 2 then &apos;&apos;pe zi&apos;&apos;
         when Contr1.TipPret = 3 then &apos;&apos;cantitativ&apos;&apos;
         when Contr1.TipPret = 4 then &apos;&apos;pachet&apos;&apos;
		end TipPr &apos;||gUserAlias||&apos;
  FROM contract contr
    INNER JOIN contract1 contr1 ON contr1.codcontract = contr.codcontract
    LEFT JOIN nparcaut pauto ON pauto.codnparcaut = contr1.codauto
    LEFT JOIN nmarciauto amarca ON amarca.codmarciauto = pauto.marca
    LEFT JOIN nmodeleauto amodel ON amodel.codmodeleauto = pauto.model
  	LEFT JOIN CantCmd cc1 on cc1.codcontract1 = contr1.codcontract1
    LEFT JOIN nartobj obj ON obj.codobiect = contr1.codobiect
    LEFT JOIN NEchiv E on Obj.CodObiect = E.codobiect
    LEFT JOIN num1 um ON um.codum1 = contr1.umsec
    LEFT JOIN nart na ON na.codarticol = obj.codarticol
    LEFT JOIN nclasea ca ON ca.codclasea = na.clasa
    LEFT JOIN (SELECT COM1.CODCOMANDA1, R.CODRAC_REZ, COM1.CODCONTRACT1,COM.MONEDA,COM.TIPDOC,COM.ANULAT,COM1.CANTACCEPTAT, 
                      COM1.PU,R.TIPREZERVARE,COM.NRDOC,COM.DATADOC 
               FROM comanda1 com1  
                    LEFT JOIN comanda com ON com.codcomanda = com1.codcomanda 
                    LEFT JOIN Rac_Rez R ON com.codcomanda = R.codcomanda  
               WHERE R.dataStart is null or R.dataStart BETWEEN PKG_LIST_ALEGPERIOADA.getDataS and PKG_LIST_ALEGPERIOADA.getDataF
              ) CRZ ON CRZ.CODCONTRACT1 = CONTR1.CODCONTRACT1 
    LEFT JOIN COMANDA1 COM1 ON COM1.CODCOMANDA1 = CRZ.CODCOMANDA1          
    LEFT JOIN COMANDA COM ON COM1.CODCOMANDA = COM.CODCOMANDA   
    LEFT JOIN ieslink iesl ON iesl.codliniecomanda = crz.codcomanda1 AND Nvl(iesl.codies1,0) &lt;&gt; 0
    LEFT JOIN iesiri1 ies1 ON ies1.codies1 = iesl.codies1
    LEFT JOIN iesiri ies ON ies.codies = ies1.codies
    LEFT JOIN npart p ON p.codpart = contr.partener
    LEFT JOIN nmonede mcontr ON mcontr.codmoneda = contr.moneda
    LEFT JOIN nmonede mcom ON mcom.codmoneda = crz.moneda
    LEFT JOIN nmonede mies ON mies.codmoneda = ies.moneda &apos;||
    gSuplJoins||&apos;
  WHERE contr.tipdoc = 34 AND contr.operat = 1 and nvl(crz.anulat,0)=0
	  AND contr.anulat = 0 AND contr.activ &lt;&gt; 0 and (contr.activ = 3 or (1=1 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;contr&apos;)||&apos;))
   	AND (crz.tipdoc is null or crz.tipdoc = 94) AND contr1.tippret in (1,3,4)&apos;;
  

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE &apos;|| tmpName ||&apos; SET ContrCantX = ContrCant WHERE OrdContr1 = 1&apos;, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END pkg_list_base_urmcontrrac1; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMINCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>825704325686E21FC3C53D45CD674779B01ADB35</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMINCART IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

function GetCodContract(aCodPart in number, aDataDoc in Date) return number is
aCodContract number(20);
begin
  BEGIN
    SELECT Coalesce(CodContract, 0) into aCodContract
    FROM contract c
    WHERE c.tipdoc = 27 AND c.partener = aCodPart AND aDataDoc BETWEEN c.datastart and c.datastop;
  EXCEPTION
    WHEN others THEN aCodContract := 0;
  END;
  RETURN aCodContract;
end;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2( 2000);
  sInsAux      VARCHAR2( 2000);
  sSelect      VARCHAR2(32000);
  sInsertMan   VARCHAR2( 2000);
  sSelectMan   VARCHAR2(10000);
  sInsMonet    VARCHAR2(10000);
  sSelMonet    VARCHAR2(10000) := &apos;&apos;;
  sUpdateMan   VARCHAR2(10000);
  sTipJoin     VARCHAR2(  100) := &apos;INNER&apos;;
  sWhereUN     VARCHAR2(  500) := &apos;&apos;;
  sAUX1        VARCHAR2(  100) := &apos;&apos;;
  sUPD1        VARCHAR2( 5000) := &apos;&apos;;
  sUPD2        VARCHAR2( 5000) := &apos;&apos;;
  sAnS         NUMBER(      4) := EXTRACT(YEAR  FROM pkg_list_alegperioada.getDataS);
  sLunaS       NUMBER(      2) := EXTRACT(MONTH FROM pkg_list_alegperioada.getDataS);
  sDataS       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
  sDataF       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
  AnLunaLucru  NUMBER(     20);
  AnLunaIni    NUMBER(     20);
  sCurs        VARCHAR2( 1000) := &apos;, 1, 1, 1, 1&apos;;
  aBancaV      NUMBER(     20);
  aMonedaV     NUMBER(     20);
BEGIN
--pkg_globals.setdebugmode(TRUE);
  gSuplCols := &apos;npart npart, nmonede mon, nagenda ag, npers agent, npers agent_inc, nsubunit substingatori, nsubunit substinsi, nartobj1 n1, nartobj o, nbankcont bc,&apos;||
               &apos;tmp_lst_stingatori TMP_INC, tmp_lst_stinsi TMP_DOC&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,     &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,     &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;,    &apos;SSOC&apos;,     &apos;SSOC.CODPART = UN.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;,      &apos;AGP&apos;,      &apos;AGP.CODPERS = SSOC.CODAGENT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NMONEDE&apos;,    &apos;MONPREST&apos;, &apos;MONPREST.CODMONEDA = Coalesce(N1.CODMONEDA,0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI&apos;,     &apos;I&apos;,        &apos;I.CODIES = UN.CODDOC AND I.TIPDOC = UN.TIPDOC&apos; , 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;IESIRI1&apos;,    &apos;I1&apos;,       &apos;I1.CODIES1 = UN.CODDOC1 AND I1.CODIES = I.CODIES&apos;, 1);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;CONTRACT2&apos;,  &apos;C2&apos;,       &apos;C2.CODDOC = I.CODIES AND C2.TIPDOC = I.TIPDOC&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NBANK&apos;,      &apos;B&apos;,        &apos;B.CODBANK = BC.CODBANK&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;PRETM&apos;,      &apos;PRETM&apos;,    &apos;PRETM.CODOBIECT = O.CODOBIECT AND PRETM.IMPLICIT = 1 AND PRETM.SUBUNITATEA = &apos;||PKG_GLOBALS.GETSUBUNITATE);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTCLI&apos;,    &apos;AC&apos;,       &apos;AC.CODOBIECT = O.CODOBIECT AND AC.CODPART = NPART.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEP&apos;,    &apos;CLSP&apos;,     &apos;CLSP.CODCLASEP = Coalesce(NPART.CODCLASA, 0)&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NLOCALIT&apos;,   &apos;LOC&apos;,      &apos;LOC.CODLOCALIT = AG.CODLOCALIT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NJUDET&apos;,     &apos;JUD&apos;,      &apos;JUD.CODJUDET = LOC.CODJUDET&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  
  SELECT PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLunaLucru, ANINITIAL*12+LUNAINITIALA INTO AnLunaLucru, AnLunaIni FROM FIRMALUNI;

  aBancaV  := pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,      pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  aMonedaV := pkg_list_base_utils.GET_Cod_MonedaFactInValuta(pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  IF Coalesce(aMonedaV,0) &lt;&gt; 0 AND Coalesce(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := &apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := &apos;,1, 1&apos;;
  END IF;

  IF Coalesce(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := sCurs||&apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := sCurs||&apos;,1, 1&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1 THEN
    sTipJoin := &apos;LEFT&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1 AND pkg_list_alegperioada.optiunea2 THEN
    sWhereUN := &apos;
    WHERE ( stingatori.codobligpif IS NOT NULL OR stinsi.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) )&apos;;
    IF pkg_list_alegperioada.optiunea1 THEN
      sWhereUN := sWhereUN||&apos; AND Coalesce(STINSI.INFOCM,0) = 0&apos;;
    END IF;
  ELSE
    IF pkg_list_alegperioada.optiunea1 THEN
      sWhereUN := sWhereUN||&apos; WHERE Coalesce(STINSI.INFOCM,0) = 0&apos;;
    END IF;
  END IF;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_lst_stingatori&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_lst_stinsi&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_lst_urmincmon&apos;;

  sUpdateMan :=&apos;
  SET
    (GESTDEN, GESTSIMB, FURNIZORI, PRETACHIZ) =
    ( SELECT
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.den_gest) AS vc2_nt)),
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.simbol  ) AS vc2_nt)),
        vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT f.den_part ) AS vc2_nt)),
        CASE
          WHEN SUM(COALESCE(L1X.CANT,L1.CANT,I1.CANT)) = 0 THEN 0
          ELSE SUM((Coalesce(NS.PRET,0) - Coalesce(NS.ADAOS,0)) * COALESCE(L1X.CANT,L1.CANT,I1.CANT)) / SUM(COALESCE(L1X.CANT,L1.CANT,I1.CANT))
        END
      FROM iesiri1 i1
        INNER JOIN iesiri    i   ON i.codies        = i1.codies
        LEFT JOIN livr       l   ON l.codies        = i.codies
        LEFT JOIN livr1      l1  ON l1.codies1      = i1.codies1 AND l1.codlivr = l.codlivr
        LEFT JOIN ieslink    il  ON il.codies1      = i1.codies1
        LEFT JOIN IESIRI1    II1 ON IL.CODLINIEAVIZ = II1.CODIES1
        LEFT JOIN IESIRI     II  ON II.CODIES       = II1.CODIES
        LEFT JOIN LIVR       LL  ON LL.CODIES       = II.CODIES
        LEFT JOIN LIVR1      LL1 ON LL1.CODLIVR     = LL.CODLIVR AND LL1.CODIES1 = II1.CODIES1
        LEFT JOIN iesvallink ivl ON ivl.codlivr1    = l1.codlivr1
        LEFT JOIN iesiri1    i1x ON i1x.codies1     = ivl.codies1
        LEFT JOIN livr1      l1x ON l1x.codies1     = i1x.codies1
        LEFT JOIN livr       lx  ON lx.codlivr      = l1x.codlivr
        LEFT JOIN nirstoc    ns  ON ns.codnirstoc   = COALESCE(l1x.codnirstoc, LL1.CODNIRSTOC,l1.codnirstoc)
        LEFT JOIN nirstoc1   ns1 ON ns1.codnirstoc  = ns.codnirstoc
        LEFT JOIN nirstoc    nso ON nso.codnirstoc  = ns1.codnirstocorig
        LEFT JOIN nir        n   ON n.codnir        = ns.codnir
        LEFT JOIN livrval    lv  ON lv.codlivr1     = l1.codlivr1
        LEFT JOIN ngest      ng  ON ng.codgest      = coalesce(n.gest, lv.gest, 0)
        LEFT JOIN npart      f   ON f.codpart       = ns.furn
      WHERE i1.codies1 = t.coddoc1 AND Coalesce(ng.codgest,0) &lt;&gt; 0
    )
  WHERE t.tipstoc = 1 &apos;;

  sInsertMan :=
  &apos;INSERT INTO tmp_lst_stingatori(
    codobligpif, codgeneral, coddoc, coddoc1, tipdoc,coddocs,tipdocs,
    docstingator,
    datadecont, datadoc, datainc, agent, subunitatea, codstinspif, valoare, valftva,
    curs, moneda, an, luna, codbanca)&apos;;

  sSelectMan := &apos;
  SELECT
    o.CodObligPIF, o.Codgeneral, tx.codtrezor CodDoc, t1x.codtrezor1 CodDoc1, g.TipDoc, 0 CodDocS, GD.TIPDOC TipDocS,
    t1x.doc||&apos;&apos; &apos;&apos;||t1x.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1x.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
    t1x.datadecont, t1x.datadoc, t1x.datadoc DATAINC, t1x.agent, t.Subunitatea, s.codstinspif, o.valoare, o.valoare-Coalesce(g.tva,0) valftva,
    Coalesce(NULLIF(t1x.curs,0),1) curs, COALESCE(tx.monedapers, bc.codmoneda, 0) moneda, tx.an, tx.luna, tx.codbanca
  FROM trezor1 t1
    INNER JOIN trezor    t   ON t1.codtrezor      = t.codtrezor
    INNER JOIN general   g   ON g.tipdoc          = t.tipdoc AND g.coddoc = t1.codtrezor1
    INNER JOIN obligpif  o   ON o.codgeneral      = g.codgeneral
    INNER JOIN stingere  s   ON s.codstingatorpif = o.codobligpif
    INNER JOIN general   gc  ON gc.coddoc         = g.coddoc AND gc.semnificatie = 600 AND gc.semnificatie &lt;&gt; g.semnificatie
    INNER JOIN obligpif  oc  ON oc.codgeneral     = gc.codgeneral
    INNER JOIN stingere  sc  ON sc.codstinspif    = Coalesce(oc.codobligpif, o.codobligpif)
    INNER JOIN obligpif  ox  ON ox.codobligpif    = sc.codstingatorpif
    INNER JOIN general   gx  ON gx.codgeneral     = ox.codgeneral AND gx.tipdoc &lt;&gt; 31
    INNER JOIN trezor1   t1x ON t1x.codtrezor1    = gx.coddoc
    INNER JOIN trezor    tx  ON t1x.codtrezor     = tx.codtrezor
    INNER JOIN OBLIGPIF  OD  ON OD.CODOBLIGPIF    = S.CODSTINSPIF
    INNER JOIN GENERAL   GD  ON GD.CODGENERAL     = OD.CODGENERAL
    LEFT  JOIN nbankcont bc  ON bc.codbankcont    = tx.codbanca
  WHERE t.tipdoc = 31
    AND g.semnificatie IN (400,420,750,751)
    AND T1X.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
  UNION ALL&apos;;

  IF pkg_list_alegperioada.optiunea3 THEN
    sSelectMan := &apos;&apos;;
    sAUX1 := &apos;,31&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea4 THEN
    sSelMonet := &apos;
    UNION ALL
    SELECT
      coddoc NAV_CodDoc, coddoc1 NAV_CodDoc1, tipdoc NAV_TipDoc, doc DOCSTINS, vallin TOTAL_DOCUMENT,
      vallin VAL_STINGATOR, vallin - tvalin VAL_STINGFTVA,
      0 VAL_REST, COEFTVA,
      0 CODSTINGATORPIF,
      0 CODSTINSPIF,
      0 SOLD_LIN,
      0 SOLD_DOC,
      1 ORDINE,
      1 ORDINEMAX,
      ROW_NUMBER() OVER (PARTITION BY coddoc, tipdoc ORDER BY indexlocal, coddoc1) ORDDOC,
      COUNT(1)     OVER (PARTITION BY coddoc, tipdoc ) ORDDOCMAX,
      doc DOCSTINGATOR, datadoc DATADECONT, datadoc DSTINGDATA, datadoc DATAINC, datadoc DSTINSDATA, datadoc TERMEN, datadoc SCADENTA, 0 DIFZILE,
      0 DEPZILE,
      0 DEPZILEDEC,
      0 DEPZILEINC,
      codpart, agent, agent agent_inc, cont, codlocatie, curs dstinscurs, moneda,
      subunitatea substinsi, subunitatea substingatori,
      coddoc, coddoc1, tipdoc, codobiect, codobiect1, an dstinsan, luna dstinsluna, an dstingan, luna dstingluna, curs dstingcurs,
      codbanca,
      tipstoc, gestact, pretachiz, pretvanz, cant, gestden, gestsimb, furnizori
    FROM tmp_lst_urmincmon&apos;;

    sInsMonet :=
    &apos;INSERT INTO tmp_lst_urmincmon (
      CODDOC1, INDEXLOCAL, CODDOC, TIPDOC, DATADOC, CODPART, CODLOCATIE, SUBUNITATEA,
      CURS, MONEDA, AGENT, INITIALIZARI, AN, LUNA, DOC,
      CODOBIECT, CODOBIECT1,
      CONT,
      VALDOC, TVADOC, VALLIN, TVALIN,
      COEFTVA,
      PRETVANZ, CANT,
      CODBANCA, TIPSTOC, GESTACT,
      PRETACHIZ, GESTDEN, GESTSIMB, FURNIZORI
    )
    SELECT
      i1.codies1 coddoc1, i1.indexlocal, i.codies coddoc, i.tipdoc, i.datadoc, Coalesce(i.partener,0) codpart, Coalesce(i.codlocatie,0) codlocatie, i.subunitatea,
      i.curs, i.moneda, Coalesce(i1.codagentemulare,0) agent, Coalesce(i.initializari,0) initializari, i.an, i.luna, i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) doc,
      i1.codobiect, o1.codobiect1,
      i1.contserv cont,
      i.valdoc, i.tvadoc, i1.pu * i1.cant + coalesce(i1.valdiscpret,0) vallin, i1.tva tvalin,
      CASE WHEN I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT - I1.TVA)/(I1.PU * I1.CANT) ELSE 1 END COEFTVA,
      i1.pu - CASE WHEN i1.cant = 0 THEN 0 ELSE i1.tva/i1.cant END pretvanz, i1.cant,
      0 codbanca, CASE WHEN i1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END tipstoc, i1.gestact,
      0 PRETACHIZ, NULL GESTDEN, NULL GESTSIMB, NULL FURNIZORI
    FROM iesiri i
      INNER JOIN iesiri1  i1 ON i1.codies    = i.codies
      LEFT  JOIN nartobj1 o1 ON o1.codobiect = i1.codobiect AND &apos;||AnLunaLucru||&apos; BETWEEN o1.ALStart and o1.ALStop
--      (
--        SELECT codobiect, Max(codobiect1) KEEP (DENSE_RANK LAST ORDER BY anstart*12+lunastart) codobiect1
--        FROM nartobj1
--        WHERE anstart*12+lunastart &lt;= &apos;||AnLunaLucru||&apos;
--        GROUP BY codobiect
--      ) o1 ON o1.codobiect = i1.codobiect
    WHERE Coalesce(i.anulat, 0) = 0 AND Coalesce(i.initializari, 0) = 0
      AND I.TIPDOC = 16
      AND i.datadoc BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND Coalesce(i1.codobiect,0) &lt;&gt; 0&apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

    LIST_EXECUTE_IMMEDIATE(sInsmonet, aListID, aListVer);
    LIST_EXECUTE_IMMEDIATE(&apos;UPDATE tmp_lst_urmincmon t&apos;||sUpdateMan, aListID, aListVer);
  END IF;

  sSelectMan := sSelectMan||&apos;
  SELECT
     o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, GS.CODDOC CodDocS, GS.TIPDOC TipDocS,
     t1.doc||&apos;&apos; &apos;&apos;||t1.nrdoc||&apos;&apos;/&apos;&apos;||to_char(t1.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
     t1.datadecont, t1.datadoc, t1.datadoc DATAINC, t1.agent, t.Subunitatea, s.codstinspif, s.valoare, s.valoare-Coalesce(g.tva,0) valftva,
     Coalesce(NULLIF(t1.curs,0),1) curs, COALESCE(t.monedapers, bc.codmoneda, 0) moneda, t.an, t.luna, t.codbanca
   FROM trezor1 t1
     INNER JOIN trezor    t  ON t1.codtrezor      = t.codtrezor
     INNER JOIN general   g  ON g.tipdoc          = t.tipdoc AND g.coddoc = t1.codtrezor1
     INNER JOIN obligpif  o  ON o.codgeneral      = g.codgeneral
     INNER JOIN stingere  s  ON s.codstingatorpif = o.codobligpif
     INNER JOIN OBLIGPIF  OS ON OS.CODOBLIGPIF    = S.CODSTINSPIF
     INNER JOIN GENERAL   GS ON GS.CODGENERAL     = OS.CODGENERAL
     LEFT  JOIN nbankcont bc ON bc.codbankcont    = t.codbanca
   WHERE T.TIPDOC IN (29,30,33&apos;||sAUX1||&apos;)
     AND T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
     AND g.semnificatie IN (400,420,750,751)
     AND s.valoare &lt;&gt; 0
   UNION ALL
   SELECT
     o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, GS.CODDOC CodDocS, GS.TIPDOC TipDocS,
     &apos;&apos;PV&apos;&apos;||&apos;&apos; &apos;&apos;||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
     null DATADECONT, c.datadoc, c.datadoc DATAINC, 0 Agent, c.Subunitatea, s.codstinspif, s.valoare, s.valoare-Coalesce(g.tva,0) valftva,
     Coalesce(NULLIF(g.curs,0),1) curs, Coalesce(g.moneda,0) moneda, c.an, c.luna, 0 codbanca
   FROM compens c
     INNER JOIN general  g  ON G.TipDoc          = 28 AND g.coddoc = c.codcompens
     INNER JOIN obligpif o  ON o.codgeneral      = g.codgeneral
     INNER JOIN stingere s  ON s.codstingatorpif = o.codobligpif
     INNER JOIN obligpif os ON os.codobligpif    = s.codstinspif
     INNER JOIN GENERAL  GS ON GS.CODGENERAL     = OS.CODGENERAL
   WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
     AND OS.SEMNIFICATIE NOT IN (410)
     AND s.valoare &lt;&gt; 0
   UNION ALL
   --stef pentru ca emulare nu are obligpif unic asociat direct fac eu un nr negativ unic, pentru e evita repetiitiile si dublarea liniilor
   SELECT
     -1-RowNum*100  CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, I.CodIes CodDocS, I.TipDoc TipDocS,
     &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
     e.databon DATADECONT, e.databon DATADOC, e.databon DATAINC, 0 Agent, i.Subunitatea, o.codobligpif codstinspif, es.valoare,(e.valoare-e.tvatotal)*es.valoare/e.valoare valftva,
     Coalesce(NULLIF(i.curs,0),1) curs, Coalesce(i.moneda,0) moneda, i.an, i.luna, 0 codbanca
   FROM emulare e
     INNER JOIN emulare1     e1 on e1.codemulare      = e.codemulare
     INNER JOIN emulstingeri es ON es.codemulstingere = e1.codemulstingere
     INNER JOIN obligpif     o  ON o.codobligpif      = es.codobligpif
     INNER JOIN general      g  ON g.codgeneral       = o.codgeneral
     INNER JOIN iesiri       i  ON  g.coddoc          = i.codies AND g.tipdoc = i.tipdoc
   WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
     AND es.valoare &lt;&gt; 0
     AND e.valoare &lt;&gt; 0 
     AND NOT o.semnificatie in (210,211)
   UNION ALL
   SELECT
     -2-RowNum*100 CodObligPIF, 0 Codgeneral, e.codemulare CodDoc, NULL CodDoc1, 64 TipDoc, I.CodIes CodDocS, I.TipDoc TipDocS,
     &apos;&apos;BON&apos;&apos;||&apos;&apos; &apos;&apos; ||e.nrbon||&apos;&apos;/&apos;&apos;||to_char(e.databon, &apos;&apos;dd.mm.yyyy&apos;&apos;) DOCSTINGATOR,
     e.databon DATADECONT, e.databon DATADOC, e.databon DATAINC, 0 Agent, i.Subunitatea, o.codobligpif codstinspif, e.valoare, e.valoare-e.tvatotal valftva,
     Coalesce(NULLIF(i.curs,0),1) curs, Coalesce(i.moneda,0) moneda, i.an, i.luna, 0 codbanca
   FROM emulare e
     INNER JOIN iesiri   i ON i.codies = e.codies
     INNER JOIN general  g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
     INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
   WHERE E.DATABON BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
     AND e.valoare &lt;&gt; 0 and not o.semnificatie in (210,211)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsertman||sSelectman, aListID, aListVer);
  COMMIT;

  sInsertMan :=
  &apos;INSERT INTO tmp_lst_stinsi(
    codobligstingator, coddoc1, indexlocal, coddoc, tipdoc, codgeneral, codobiect, codobiect1, initializari,
    docstins, datadoc, subunitatea, curs, moneda, codobligpif,
    valoarelinie, valdoc,
    valobliglinie,
    coeftva,
    valoare, codpart, codlocatie, termen, agent, cont, an, luna, codbanca,
    tipstoc, gestact, pretvanz, cant, infocm)&apos;;

  sSelectMan := &apos;
  SELECT
    codobligstingator, coddoc1, indexlocal, coddoc, tipdoc, codgeneral, codobiect, codobiect1, initializari,
    docstins, datadoc, subunitatea, curs, moneda, codobligpif,
    valoarelinie, valdoc,&apos;;
  IF not pkg_list_alegperioada.optiunea4 THEN
    sSelectMan := sSelectMan||&apos;
    CASE
      WHEN INFOCM = 1 THEN 0
      WHEN CODOBLIGSTINGATOR &lt; 0 THEN VALOARELINIE
      WHEN valoare = 0 AND infocm &lt;&gt; 1 THEN 0
      WHEN valoarelinie = 0 THEN 0
      WHEN Sum( valoarelinie ) OVER (PARTITION BY codobligstingator, codobligpif) = 0 THEN 0
      ELSE valoarelinie * valoare/ Sum( valoarelinie ) OVER (PARTITION BY codobligstingator, codobligpif)
    END valobliglinie,
    COEFTVA,
    CASE WHEN CODOBLIGSTINGATOR &lt; 0 THEN VALDOC ELSE VALOARE END valoare, &apos;;
  ELSE
    sSelectMan := sSelectMan||&apos;
    CASE 
      WHEN CODOBLIGSTINGATOR = 0 THEN 0
      WHEN INFOCM = 1 THEN 0
      WHEN CODOBLIGSTINGATOR &lt; 0 THEN VALOARELINIE
      WHEN valoare = 0 AND infocm &lt;&gt; 1 THEN 0
      WHEN valoarelinie = 0 THEN 0
      WHEN Sum( valoarelinie ) OVER (PARTITION BY codobligstingator, codobligpif) = 0 THEN 0
      ELSE valoarelinie * valoare/ Sum( valoarelinie ) OVER (PARTITION BY codobligstingator, codobligpif)
    END valobliglinie,
    COEFTVA,
    CASE WHEN CODOBLIGSTINGATOR = 0 THEN 0 ELSE VALOARE END VALOARE, &apos;;
  END IF;
  sSelectMan := sSelectMan||&apos;
    codpart, codlocatie, termen, agent, cont, an, luna, codbanca,
    tipstoc, gestact, pretvanz, cant, infocm
  FROM (
    SELECT
      STG.CODOBLIGPIF CODOBLIGSTINGATOR, i1.codies1 coddoc1, i1.indexlocal, i.codies coddoc, i.tipdoc, o.codgeneral, i1.codobiect, o1.codobiect1, 0 initializari,
      i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc, i.subunitatea, Coalesce(NULLIF(g.curs,0),1) curs, Coalesce(g.moneda,0) moneda, o.codobligpif,
      (i1.pu*i1.cant+CASE WHEN i.tipdoc = 21 THEN 0 ELSE i1.tva END)*Coalesce(i1.coefdiscmaj,1)*CASE i1.pu WHEN i1.pretorig THEN 1 WHEN 0 THEN 0 ELSE i1.pretorig/i1.pu END valoarelinie, i.valdoc, Coalesce(i.infocm,0) infocm,
      CASE
        WHEN i.tipdoc =  21 AND I1.PU * I1.CANT        &lt;&gt; 0 THEN (I1.PU * I1.CANT-I1.TVA)/(I1.PU * I1.CANT)
        WHEN i.tipdoc &lt;&gt; 21 AND I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT)/(I1.PU * I1.CANT+I1.TVA)
        ELSE 1
      END COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, i.agent, PKG_LIST_BASE_UTILS.icont_CodCont(o.icont,o.codpart,i.an*12+i.luna,o.semnificatie) cont, i.an, i.luna, 0 codbanca,
      CASE WHEN i1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END tipstoc, i1.gestact, i1.pu - CASE WHEN i1.cant = 0 THEN 0 WHEN i.tipdoc &lt;&gt; 21 THEN 0 ELSE i1.tva/i1.cant END pretvanz, i1.cant,
      Coalesce(O.CodCentru,0) CodCentruO, Coalesce(i1.codcentru,0) CodCentruI, Max(Coalesce(O.CodCentru,0)) OVER (PARTITION BY i.codies) CodCentruM
    FROM iesiri i
      INNER JOIN general  g  ON g.coddoc     = i.codies and g.tipdoc = i.tipdoc 
      INNER JOIN obligpif o  ON g.codgeneral = o.codgeneral
      LEFT  JOIN iesiri1  i1 ON i.codies     = i1.codies
      &apos;||sTipJoin||&apos; JOIN TMP_AUX_STINGATORI STG ON STG.CODSTINSPIF = O.CODOBLIGPIF OR (STG.CODDOCS = I.CODIES AND STG.TIPDOCS = I.TIPDOC AND STG.CODSTINSPIF IS NULL)
      LEFT  JOIN nartobj1 o1 ON o1.codobiect = i1.codobiect AND &apos;||AnLunaLucru||&apos; BETWEEN o1.ALStart and o1.ALStop
--      (
--        SELECT codobiect, Max(codobiect1) KEEP (DENSE_RANK LAST ORDER BY anstart*12+lunastart) codobiect1
--        FROM nartobj1
--        WHERE anstart*12+lunastart &lt;= &apos;||AnLunaLucru||&apos;
--        GROUP BY codobiect
--      ) o1 ON o1.codobiect = i1.codobiect
    WHERE Coalesce(i.anulat, 0) = 0 AND Coalesce(i.initializari, 0) = 0
      AND I.TIPDOC IN (16,19,21,22,26) 
      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND Coalesce(i1.codobiect,0) &lt;&gt; 0
      AND g.semnificatie NOT IN (210, 211, 240, 500) &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);

  /*
  IF not pkg_list_alegperioada.optiunea4 THEN
    sSelectMan := sSelectMan||&apos;
    UNION ALL
    SELECT
      -1 CODOBLIGSTINGATOR, i1.codies1 coddoc1, i1.indexlocal, i.codies coddoc, i.tipdoc, o.codgeneral, i1.codobiect, o1.codobiect1, 0 initializari,
      i.prefixdoc||&apos;&apos; &apos;&apos;|| i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, i.datadoc, i.subunitatea, Coalesce(NULLIF(g.curs,0),1) curs, Coalesce(g.moneda,0) moneda, o.codobligpif,
      (i1.pu*i1.cant+CASE WHEN i.tipdoc = 21 THEN 0 ELSE i1.tva END)*Coalesce(i1.coefdiscmaj,1)*CASE i1.pu WHEN i1.pretorig THEN 1 WHEN 0 THEN 0 ELSE i1.pretorig/i1.pu END valoarelinie, i.valdoc, Coalesce(i.infocm,0) infocm,
      CASE
        WHEN i.tipdoc =  21 AND I1.PU * I1.CANT        &lt;&gt; 0 THEN (I1.PU * I1.CANT-I1.TVA)/(I1.PU * I1.CANT)
        WHEN i.tipdoc &lt;&gt; 21 AND I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT)/(I1.PU * I1.CANT+I1.TVA)
        ELSE 1
      END COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, i.agent, PKG_LIST_BASE_UTILS.icont_CodCont(o.icont,o.codpart,i.an*12+i.luna,o.semnificatie) cont, i.an, i.luna, 0 codbanca,
      CASE WHEN i1.tiplinie = &apos;&apos;=&apos;&apos; THEN 1 ELSE 0 END tipstoc, i1.gestact, i1.pu - CASE WHEN i1.cant = 0 THEN 0 WHEN i.tipdoc &lt;&gt; 21 THEN 0 ELSE i1.tva/i1.cant END pretvanz, i1.cant,
      Coalesce(O.CodCentru,0) CodCentruO, Coalesce(i1.codcentru,0) CodCentruI, Max( Coalesce(O.CodCentru,0) ) OVER (PARTITION BY i.codies) CodCentruM
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i.codies = i1.codies
      INNER JOIN general g ON g.coddoc = i.codies AND g.tipdoc = i.tipdoc
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
      &apos;||sTipJoin||&apos; JOIN TMP_AUX_STINGATORI STG ON STG.CODSTINSPIF = O.CODOBLIGPIF
      LEFT JOIN (
        SELECT codobiect, Max(codobiect1) KEEP (DENSE_RANK LAST ORDER BY anstart*12+lunastart) codobiect1
        FROM nartobj1
        WHERE anstart*12+lunastart &lt;= &apos;||AnLunaLucru||&apos;
        GROUP BY codobiect
      ) o1 ON o1.codobiect = i1.codobiect
    WHERE Coalesce(i.anulat, 0) = 0 AND Coalesce(i.initializari, 0) = 0
      AND I.TIPDOC IN (16,19,21,22,26)
      AND I.TIPFACTURA = 7
      AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND g.semnificatie &lt;&gt; 500
      AND Coalesce(i1.codobiect,0) &lt;&gt; 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
  END IF;
  */
  sSelectMan := sSelectMan||&apos;
  )
  WHERE CodCentruO = CASE WHEN CodCentruM = 0 THEN 0 ELSE CodCentruI END&apos;;

  sInsAux := &apos;INSERT INTO tmp_aux_stingatori(CODOBLIGPIF, CODDOC, CODDOC1, TIPDOC, CODSTINSPIF, CODDOCS, TIPDOCS)
  SELECT CODOBLIGPIF, CODDOC, CODDOC1, TIPDOC, CODSTINSPIF, CODDOCS, TIPDOCS
  FROM tmp_lst_stingatori
  WHERE TIPDOCS IN (16,19,21,22,26)&apos;;

  LIST_EXECUTE_IMMEDIATE(&apos;TRUNCATE TABLE tmp_aux_stingatori&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsAux, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsertman||sSelectman, aListID, aListVer);

  sSelectMan := &apos;
  SELECT
    STG.CODOBLIGPIF CODOBLIGSTINGATOR, 0 coddoc1, 0 indexlocal, i.codies coddoc, i.tipdoc, o.codgeneral, -1 codobiect, 0 codobiect1, 1 initializari,
    i.prefixdoc||&apos;&apos; &apos;&apos;||i.nrdoc||&apos;&apos;/&apos;&apos;||to_char(i.datadoc, &apos;&apos;DD.MM.YYYY&apos;&apos;) docstins, i.datadoc, i.subunitatea, Coalesce(NULLIF(g.curs,0),1) curs, Coalesce(g.moneda,0) moneda, o.codobligpif,
    o.valoare + Coalesce(CECINI.VALOARE,0) valoarelinie, o.valoare + Coalesce(CECINI.VALOARE,0) valdoc,
    o.valoare + Coalesce(CECINI.VALOARE,0) valobliglinie,
    1 COEFTVA,
    o.valoare + Coalesce(CECINI.VALOARE,0) valoare, o.codpart, i.codlocatie, o.termen, i.agent, PKG_LIST_BASE_UTILS.icont_CodCont(o.icont,o.codpart,&apos;||AnLunaIni||&apos;,o.semnificatie) cont, i.an, i.luna, 0 codbanca,
    0 tipstoc, 0 gestact, 0 pretvanz, 0 cant, i.infocm
  FROM iesiri i
    INNER JOIN general  g ON g.tipdoc     = i.tipdoc AND g.coddoc = i.codies
    INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
    &apos;||sTipJoin||&apos; JOIN tmp_lst_stingatori STG ON STG.CODSTINSPIF = O.CODOBLIGPIF
    LEFT JOIN (
      SELECT S.CODSTINSPIF, SUM(ST.VALOARE) VALOARE
      FROM STINGERE S
        INNER JOIN OBLIGPIF ST     ON S.CODSTINGATORPIF  = ST.CODOBLIGPIF
        INNER JOIN GENERAL  GST    ON GST.CODGENERAL     = ST.CODGENERAL
        INNER JOIN TREZOR1  T1     ON T1.CODTREZOR1      = GST.CODDOC
        INNER JOIN TREZOR   T      ON T1.CODTREZOR       = T.CODTREZOR AND GST.TIPDOC = T.TIPDOC
        INNER JOIN OBLIGPIF OSTINS ON OSTINS.CODOBLIGPIF = S.CODSTINSPIF
        INNER JOIN GENERAL  GSTINS ON GSTINS.CODGENERAL  = OSTINS.CODGENERAL AND GSTINS.SEMNIFICATIE &lt;&gt; 500 AND GSTINS.SEMNIFICATIE &lt;&gt; 240
        INNER JOIN IESIRI   IES    ON IES.CODIES         = GSTINS.CODDOC AND IES.TIPDOC = GSTINS.TIPDOC
      WHERE Coalesce(IES.anulat, 0) = 0 and Coalesce(IES.initializari, 0) = 1 AND IES.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;IES&apos;)||&apos;
        AND NOT IES.TIPDOC IN (14,15,16,20,23,24)
        AND GST.semnificatie IN (400,420,750,751)
        AND GST.TIPDOC = 31
        AND T1.DATADOC &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        AND Coalesce(T1.INITIALIZARI,0) = 1
      GROUP BY CODSTINSPIF
    ) CECINI ON CECINI.CODSTINSPIF = O.CODOBLIGPIF
  WHERE Coalesce(i.anulat, 0) = 0 AND Coalesce(i.initializari, 0) = 1
    AND I.TIPDOC IN (16,19,21,22,26)
    AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND NOT g.semnificatie IN (240, 500)&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsertman||sSelectman, aListID, aListVer);

  sSelectMan := &apos;
  SELECT
    STG.CODOBLIGPIF CODOBLIGSTINGATOR, nc1.codnc1 CodDoc1, nc1.indexlocal, NC.CodNc CodDoc, g.TipDoc, o.codgeneral, -3 codobiect, 0 codobiect1, 0 initializari,
    &apos;&apos;NC &apos;&apos;  ||nc.nrdoc||&apos;&apos;/&apos;&apos;||to_char(nc.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, nc.datadoc, nc.subunitatea, Coalesce(NULLIF(g.curs,0),1) curs, g.moneda, o.codobligpif,
    o.valoare valoarelinie, o.valoare valdoc,
    o.valoare valobliglinie,
    CASE WHEN Coalesce(o.valoare,0) = 0 THEN 1 ELSE (o.valoare-Coalesce(g.tva,0))/o.valoare END COEFTVA,
    o.valoare, o.codpart, 0 codlocatie, o.termen, nc1.agent, PKG_LIST_BASE_UTILS.icont_CodCont(o.icont,o.codpart,nc1.an*12+nc1.luna,o.semnificatie) cont, nc.An, nc.Luna, 0 codbanca,
    0 tipstoc, 0 gestact, 0 pretvanz, 0 cant, 0 infocm
  FROM nc
    INNER JOIN nc1        ON nc1.codnc = nc.codnc
    INNER JOIN general  g ON g.coddoc  = nc1.codnc1 AND g.tipdoc = 35
    INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
    &apos;||sTipJoin||&apos; JOIN tmp_lst_stingatori STG ON STG.CODSTINSPIF = O.CODOBLIGPIF
  WHERE nc.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND g.semnificatie = 1200&apos;||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;nc&apos;);
  LIST_EXECUTE_IMMEDIATE(sInsertman||sSelectman, aListID, aListVer);

  sSelectMan := &apos;
  SELECT
    STG.CODOBLIGPIF CODOBLIGSTINGATOR, NULL CodDoc1, 0 IndexLocal, c.CodCompens CodDoc, g.TipDoc, o.codgeneral, -4 codobiect, 0 codobiect1, 0 initializari,
    &apos;&apos;PV &apos;&apos; ||c.nrdoc||&apos;&apos;/&apos;&apos;||to_char(c.datadoc, &apos;&apos;dd.mm.yyyy&apos;&apos;) docstins, c.datadoc, c.subunitatea, Coalesce(NULLIF(g.curs,0),1) curs, g.moneda, o.codobligpif,
    o.valoare valoarelinie, o.valoare valdoc,
    o.valoare valobliglinie,
    CASE WHEN Coalesce(o.valoare,0) = 0 THEN 1 ELSE (o.valoare-Coalesce(g.tva,0))/o.valoare END COEFTVA,
    o.valoare, o.codpart, 0 codlocatie, o.termen, c.agent, PKG_LIST_BASE_UTILS.icont_CodCont(o.icont,o.codpart,c.an*12+c.luna,o.semnificatie) cont, c.An, c.Luna, 0 codbanca,
    0 tipstoc, 0 gestact, 0 pretvanz, 0 cant, 0 infocm
  FROM compens c
    INNER JOIN general  g ON g.coddoc     = c.codcompens AND g.tipdoc = 28
    INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
    &apos;||sTipJoin||&apos; JOIN tmp_lst_stingatori STG ON STG.CODSTINSPIF = O.CODOBLIGPIF
  WHERE c.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsertman||sSelectman, aListID, aListVer);

  LIST_EXECUTE_IMMEDIATE(&apos;DELETE tmp_lst_stinsi WHERE (valobliglinie = 0 OR valoare = 0) and codobligstingator &lt; 0&apos;, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE tmp_lst_stinsi t&apos;||sUpdateMan, aListID, aListVer);

  IF pkg_list_alegperioada.optiunea3 THEN
    sUpd1 := &apos;Coalesce(Sum(CASE WHEN Coalesce(t1.initializari,0) = 1 AND gs.tipdoc = 31 THEN OS.VALOARE ELSE s.valoare END),0)&apos;;
  ELSE
    sUpd1 := &apos;Coalesce(Sum(CASE WHEN gs.tipdoc = 31 AND tx.codtrezor IS NULL THEN 0 WHEN Coalesce(t1.initializari,0) = 1 AND gs.tipdoc = 31 THEN OS.VALOARE ELSE s.valoare END),0)&apos;;
    sUpd2 := &apos;
                LEFT JOIN general  gc  ON gc.coddoc      = gs.coddoc AND gc.semnificatie = 600 AND gc.semnificatie &lt;&gt; gs.semnificatie
                LEFT JOIN obligpif oc  ON oc.codgeneral  = gc.codgeneral
                LEFT JOIN stingere sc  ON sc.codstinspif = Coalesce(oc.codobligpif, os.codobligpif)
                LEFT JOIN obligpif ox  ON ox.codobligpif = sc.codstingatorpif
                LEFT JOIN general  gx  ON gx.codgeneral  = ox.codgeneral
                LEFT JOIN trezor1  t1x ON t1x.codtrezor1 = gx.coddoc
                LEFT JOIN trezor   tx  ON t1x.codtrezor  = tx.codtrezor AND t1x.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  sUpdateMan :=
  &apos;UPDATE tmp_lst_stinsi man
  SET rest = valdoc -
             (SELECT &apos;||sUpd1||&apos;
              FROM general g
                INNER JOIN obligpif o  on o.codgeneral   = g.codgeneral
                INNER JOIN stingere s  ON s.codstinspif  = o.codobligpif
                INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
                INNER JOIN general  gs ON gs.codgeneral  = os.codgeneral
                LEFT  JOIN trezor1  t1 on gs.coddoc      = t1.codtrezor1 AND gs.tipdoc &lt;&gt; 28 AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
                LEFT  JOIN compens  c  ON gs.coddoc      = c.codcompens  AND gs.tipdoc = 28  AND c.datadoc  &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
                sUpd2||&apos;
              WHERE g.coddoc = man.coddoc AND g.tipdoc = man.tipdoc AND Coalesce(t1.codtrezor,c.codcompens) IS NOT NULL)&apos;;

  LIST_EXECUTE_IMMEDIATE(supdateman, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(&apos;UPDATE tmp_lst_stinsi SET restlinie = CASE WHEN Coalesce(valdoc,0) = 0 THEN 0 ELSE rest*valoarelinie/valdoc END&apos;, aListID, aListVer);

  COMMIT;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,
    DOCSTINS, TOTAL_DOCUMENT, VAL_NESTINSA_DOCUMENT, VAL_STINGATOR, VAL_STINGFTVA,
    DOCSTINGATOR, PARTENER, LOCATIE,
    SOLD_LIN, SOLD_LINF, ORDINE,
    SOLD_DOC, SOLD_DOCF, ORDDOC,
    DATADECONT, DATA, DATAINC, DATA_STINS, TERMEN, MONEDA, SUBUNITATEA, SUBUNITATEA_ST, SCADENTA, DIFZILE,
    INC_VAL1, INC_VAL2, INC_VAL3, INC_VAL4, INC_VAL5, INC_VAL_0_7, INC_VAL_8_21, INC_VAL_22_40, INC_VAL_61_70, INC_VAL_61_75, INC_VAL_71_85, INC_VAL_40p, INC_VAL_75p, INC_VAL_85p, INC_VAL_0_75,
    DEPZILE, DEPZILEDEC, DEPZILEINC, AGENT, AGENT_INCASATOR, CONT,
    ARTICOL,
    CODEXTERN, CODINTERN, PRODUCATOR, CLASAARTICOL,
    DISCTER,
    DSTINSCURS, DSTINSAN, DSTINSLUNA, DSTINGCURS, DSTINGAN, DSTINGLUNA,
    GESTDEN, GESTSIMB, FURNIZORI, NRCONT, PRETACHIZ,PRETVANZ,CANT,
    DSTINSCURS_REF, DSTINGCURS_REF, DSTINSCURS_PREST, DSTINGCURS_PREST&apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH UN AS (
    SELECT
      stingatori.coddoc NAV_CodDoc, stingatori.coddoc1 NAV_CodDoc1, stingatori.tipdoc NAV_TipDoc, stinsi.DOCSTINS, stinsi.valoarelinie TOTAL_DOCUMENT,
      sign(stinsi.valoare) * Coalesce(stingatori.valoare,0)*stinsi.valobliglinie/Coalesce(NULLIF(stinsi.valoare,0),1) VAL_STINGATOR,
      sign(stinsi.valoare) * Coalesce(stingatori.valftva,0)*stinsi.valobliglinie/Coalesce(NULLIF(stinsi.valoare,0),1) VAL_STINGFTVA,
      stinsi.restlinie VAL_REST, stinsi.coeftva, stingatori.codobligpif codstingatorpif, stinsi.codobligpif codstinspif,
      stinsi.restlinie -
      SUM(Coalesce(sign(stinsi.valoare)*Coalesce(stingatori.valoare,0)*stinsi.valobliglinie/Coalesce(NULLIF(stinsi.valoare,0),1),0))
      OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1 ORDER BY stinsi.termen, stinsi.codobligpif, stingatori.codobligpif ROWS BETWEEN unbounded preceding AND CURRENT ROW) SOLD_LIN,
      stinsi.rest -
      SUM(Coalesce(sign(stinsi.valoare)*Coalesce(stingatori.valoare,0)*stinsi.valobliglinie/Coalesce(NULLIF(stinsi.valoare,0),1),0))
      OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc ORDER BY stinsi.indexlocal, stinsi.coddoc1, stinsi.termen, stinsi.codobligpif, stingatori.codobligpif ROWS BETWEEN unbounded preceding AND CURRENT ROW) SOLD_DOC,
      ROW_NUMBER() OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1 ORDER BY stinsi.termen, stinsi.codobligpif, stingatori.codobligpif) ORDINE,
      COUNT(1)     OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1) ORDINEMAX,
      ROW_NUMBER() OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc ORDER BY stinsi.indexlocal, stinsi.coddoc1, stinsi.termen, stinsi.codobligpif, stingatori.codobligpif) ORDDOC,
      COUNT(1)     OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc) ORDDOCMAX,
      stingatori.DOCSTINGATOR, stingatori.DATADECONT, stingatori.datadoc DSTINGDATA, stingatori.DATAINC, stinsi.datadoc DSTINSDATA, stinsi.TERMEN, stinsi.termen SCADENTA, trunc(stingatori.datadoc - stinsi.datadoc) DIFZILE,
      CASE WHEN trunc(stingatori.datadoc - stinsi.termen) &gt; 0 then trunc(stingatori.datadoc - stinsi.termen) ELSE 0 END DEPZILE,
      CASE WHEN trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - stinsi.termen) &gt; 0 then trunc(COALESCE(stingatori.datadecont,stingatori.datadoc) - stinsi.termen) ELSE 0 END DEPZILEDEC,
      CASE WHEN trunc(stingatori.datainc - stinsi.termen) &gt; 0 then trunc(stingatori.datainc - stinsi.termen) ELSE 0 END DEPZILEINC,
      stinsi.codpart, Coalesce(stinsi.agent,0) agent, Coalesce(stingatori.agent,0) agent_inc, stinsi.cont, Coalesce(stinsi.codlocatie,0) codlocatie, stinsi.curs dstinscurs, stinsi.moneda,
      stinsi.subunitatea substinsi, stingatori.subunitatea substingatori,
      stinsi.coddoc, stinsi.coddoc1, stinsi.tipdoc, stinsi.codobiect, stinsi.codobiect1, stinsi.an dstinsan, stinsi.luna dstinsluna, stingatori.an dstingan, stingatori.luna dstingluna, stingatori.curs dstingcurs,
      CASE WHEN stinsi.codobiect = -2 THEN stinsi.codbanca ELSE stingatori.codbanca END codbanca,
      stinsi.TIPSTOC, stinsi.GESTACT, stinsi.PRETACHIZ, stinsi.PRETVANZ, stinsi.CANT, stinsi.GESTDEN, stinsi.GESTSIMB, stinsi.FURNIZORI
    FROM tmp_lst_stinsi stinsi &apos;||sTipJoin||&apos; JOIN tmp_lst_stingatori stingatori ON stingatori.CODOBLIGPIF = stinsi.CODOBLIGSTINGATOR&apos;||
    sWhereUN||
    sSelMonet||&apos;
  )
  SELECT
    CASE WHEN ts.codsubunit IS NOT NULL THEN UN.NAV_CodDoc END NAV_CodDoc, CASE WHEN ts.codsubunit IS NOT NULL THEN UN.NAV_CodDoc1 END NAV_CodDoc1, CASE WHEN ts.codsubunit IS NOT NULL THEN UN.NAV_TipDoc END NAV_TipDoc,
    UN.DOCSTINS, CASE WHEN UN.ORDINE = 1 THEN UN.TOTAL_DOCUMENT ELSE 0 END TOTAL_DOCUMENT, UN.SOLD_LIN + UN.VAL_STINGATOR VAL_NESTINSA_DOCUMENT, UN.VAL_STINGATOR, UN.VAL_STINGATOR * UN.COEFTVA VAL_STINGFTVA,
    UN.DOCSTINGATOR, NPART.DEN_PART, AG.OBS,
    UN.SOLD_LIN, CASE WHEN UN.ORDINE = UN.ORDINEMAX THEN UN.SOLD_LIN ELSE 0 END SOLD_LINF, UN.ORDINE,
    UN.SOLD_DOC, CASE WHEN UN.ORDDOC = UN.ORDDOCMAX THEN UN.SOLD_DOC ELSE 0 END SOLD_DOCF, UN.ORDDOC,
    UN.DATADECONT, UN.DSTINGDATA DATA, UN.DATAINC, UN.DSTINSDATA DATA_STINS, UN.TERMEN, MON.DEN_MONEDA, SUBSTINSI.DEN_SUBUNIT SUBUNITATEA, SUBSTINGATORI.DEN_SUBUNIT SUBUNITATEA_ST, UN.SCADENTA, UN.DIFZILE,
    CASE WHEN UN.DIFZILE &lt;=              1 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL1,
    CASE WHEN UN.DIFZILE BETWEEN  2 AND 30 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL2,
    CASE WHEN UN.DIFZILE BETWEEN 31 AND 45 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL3,
    CASE WHEN UN.DIFZILE BETWEEN 46 AND 60 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL4,
    CASE WHEN UN.DIFZILE &gt;              60 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL5,
    CASE WHEN UN.DIFZILE BETWEEN  0 AND  7 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_0_7,
    CASE WHEN UN.DIFZILE BETWEEN  8 AND 21 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_8_21,
    CASE WHEN UN.DIFZILE BETWEEN 22 AND 40 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_22_40,
    CASE WHEN UN.DIFZILE BETWEEN 61 AND 70 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_61_70,
    CASE WHEN UN.DIFZILE BETWEEN 61 AND 75 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_61_75,
    CASE WHEN UN.DIFZILE BETWEEN 71 AND 85 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_71_85,
    CASE WHEN UN.DIFZILE &gt;              40 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_40p,
    CASE WHEN UN.DIFZILE &gt;              75 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_75p,
    CASE WHEN UN.DIFZILE &gt;              85 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_85p,
    CASE WHEN UN.DIFZILE &lt;              75 THEN UN.VAL_STINGATOR ELSE 0 END INC_VAL_0_75,
    UN.DEPZILE, UN.DEPZILEDEC, UN.DEPZILEINC, NUMEPRENUME(agent.nume,agent.prenume) AGENT, NUMEPRENUME(agent_inc.nume,agent_inc.prenume) AGENT_INCASATOR, nc.simbol CONT,
    CASE un.codobiect WHEN -1 THEN &apos;&apos;INITIALIZARE&apos;&apos; WHEN -2 THEN &apos;&apos;AVANS TREZORERIE&apos;&apos; WHEN -3 THEN &apos;&apos;NOTE CONTABILE&apos;&apos; WHEN -4 THEN &apos;&apos;COMPENSARI&apos;&apos; ELSE o.denumire END,
    O.CODEXTERN, O.CODINTERN, PROD.DEN_PART, CA.DEN_CLASEA ,
    CASE WHEN Coalesce(UN.VAL_STINGATOR,0) &gt; 0 THEN pkg_notecredit.GETDISCTERMENCLI(UN.DSTINGDATA, UN.DIFZILE, pkg_list_base_urmincart.getcodcontract(UN.CODPART, UN.DSTINSDATA), UN.CODDOC1, UN.VAL_STINGATOR ) END DISCTER,
    UN.DSTINSCURS, UN.DSTINSAN, UN.DSTINSLUNA, UN.DSTINGCURS, UN.DSTINGAN, UN.DSTINGLUNA,
    Coalesce(UN.GESTDEN,G1.DEN_GEST) GESTDEN, Coalesce(UN.GESTSIMB,G1.SIMBOL) GESTSIMB, UN.FURNIZORI, BC.NRCONT, UN.PRETACHIZ, UN.PRETVANZ, UN.CANT&apos;||
    sCurs||gUserAlias||&apos;
  FROM UN
    LEFT JOIN tmp_lst_stingatori  TMP_INC       ON TMP_INC.codobligpif = UN.codstingatorpif
    LEFT JOIN tmp_lst_stinsi      TMP_DOC       ON TMP_DOC.codobligpif = UN.codstinspif and UN.coddoc1 = TMP_DOC.coddoc1 and tmp_inc.CODOBLIGPIF = tmp_doc.CODOBLIGSTINGATOR
    LEFT JOIN nartobj             o             ON o.codobiect         = un.codobiect
    LEFT JOIN npers               agent         on UN.agent            = agent.codpers
    LEFT JOIN npers               agent_inc     on UN.agent_inc        = agent_inc.codpers
    LEFT JOIN npart               npart         ON npart.codpart       = UN.codpart
    LEFT JOIN nagenda             ag            on UN.codlocatie       = ag.codagenda
    LEFT JOIN nmonede             mon           ON mon.codmoneda       = Coalesce(UN.moneda,0)
    LEFT JOIN nsubunit            SubStingatori ON UN.substingatori    = SubStingatori.codsubunit
    LEFT JOIN nsubunit            SubStinsi     ON UN.substinsi        = SubStinsi.codsubunit
    LEFT JOIN tmp_subunitdedicate ts            ON ts.codsubunit       = UN.substingatori
    LEFT JOIN npart               prod          ON prod.codpart        = o.codproducator
    LEFT JOIN nart                a             ON a.codarticol        = o.codarticol
    LEFT JOIN nclasea             ca            ON ca.codclasea        = a.clasa
    LEFT JOIN nartobj1            n1            on n1.codobiect1       = un.codobiect1
    LEFT JOIN nbankcont           bc            ON bc.codbankcont      = un.codbanca
    LEFT JOIN ngest               g1            ON g1.codgest          = un.gestact
    LEFT JOIN ncont               nc            ON nc.codcont          = un.cont&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_urmincart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMINCASARIDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44C0DA49FE638F07C5F2C06134C44BEE56CBF602</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmincasaridoc IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(1000);
  sSelect  VARCHAR2(5000);
  aSitV    NUMBER(1);
  aBancaV  NUMBER(20);
  aMonedaV NUMBER(20);
  sCursRef VARCHAR2(200);
  vCursRef NUMBER;
  vSitVal  BOOLEAN;
BEGIN
  gSuplCols := &apos;nmonede mon, nsubunit sub, &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPART&apos;, &apos;NP&apos;, &apos;NP.CODPART = O.CODPART&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SSOC&apos;, &apos;SSOC.CODPART = O.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;, &apos;AGP&apos;, &apos;AGP.CODPERS = SSOC.CODAGENT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vSitVal := pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos;( NAV_CodDoc, NAV_TipDoc, PREFIXDOC, DATADOC, NRDOC, TERMEN, MONEDA, MAJORARE, OBLIG, INCASARE, SOLD, OBS, ORDINE, CURS_REF &apos;||gUserFields||&apos; )&apos;;

  IF vSitVal
  THEN sCursRef := &apos; PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, I.DATADOC)&apos;;
  ELSE sCursRef := &apos; 1 &apos;;
  END IF;

  sSelect := &apos;
  SELECT G.CodDoc, G.TipDoc , I.Prefixdoc , I.Datadoc, I.Nrdoc, O.Termen, M.Simbol, 0 Majorare, O.Valoare, 0 Incasare, O.Valoare, I.Obs, 0 Ordine,&apos;||sCursRef||gUserAlias||&apos;
  FROM IESIRI I
    INNER JOIN GENERAL G ON G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    LEFT JOIN NMONEDE M ON M.CODMONEDA = I.Moneda
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA&apos;||
    gSuplJoins||&apos;
  WHERE I.PARTENER = PKG_LIST_SELURMDOCPART.CODPART
    AND I.NRDOC = PKG_LIST_SELURMDOCPART.NRDOC
    AND I.DATADOC = PKG_LIST_SELURMDOCPART.DATADOC
    AND O.SEMNIFICATIE = 200&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  IF vSitVal
  THEN sCursRef := &apos; PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, COALESCE(C.DATADOC,T1.DATADOC,NC.DATADOC,I.DATADOC))&apos;;
  ELSE sCursRef := &apos; 1 &apos;;
  END IF;

  sSelect := &apos;
  SELECT
    CASE WHEN TS.CODSUBUNIT IS NULL THEN NULL WHEN G.TipDoc IN (29,30,31,33) THEN T.CODTREZOR ELSE G.CODDOC END NAV_CodDoc,
    CASE WHEN ts.codsubunit IS NULL THEN NULL ELSE G.TipDoc END NAV_TipDoc,
    CASE WHEN G.TipDoc = 28 THEN &apos;&apos;PV&apos;&apos; WHEN G.TipDoc IN (29,30,31,33) THEN T1.DOC WHEN G.TipDoc = 35 THEN &apos;&apos;NC&apos;&apos; ELSE I.PREFIXDOC END PREFIXDOC,
    CASE WHEN G.TipDoc = 28 THEN C.DATADOC WHEN G.TipDoc IN (29,30,31,33) THEN T1.DATADOC WHEN G.TipDoc = 35 THEN NC.DATADOC ELSE I.DATADOC END DATADOC,
    CASE WHEN G.TipDoc = 28 THEN C.NRDOC WHEN G.TipDoc IN (29,30,31,33) THEN T1.NRDOC WHEN G.TipDoc = 35 THEN NC.NRDOC ELSE I.NRDOC END NRDOC,
    O.TERMEN, MON.SIMBOL, O.MAJORARI, 0,
    CASE WHEN G.SEMNIFICATIE IN (420,1300) THEN - O.VALOARE ELSE O.VALOARE END VALOARE,
    CASE WHEN G.SEMNIFICATIE IN (420,1300) THEN O.VALOARE ELSE - O.VALOARE END SOLD,
    CASE WHEN G.TipDoc = 28 AND G.SEMNIFICATIE IN (1300) THEN C.OBSD WHEN G.TipDoc = 28 AND G.SEMNIFICATIE IN (1350) THEN C.OBSC WHEN G.TipDoc IN (29,30,31,33) THEN T1.OBS WHEN G.TipDoc = 35 THEN NC.OBS ELSE I.OBS END OBS,
    1 ORDINE,&apos;||sCursRef||gUserAlias||&apos;
  FROM STINGERE S
    INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
    LEFT JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.CODDOC
    LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
    LEFT JOIN TREZOR  T  ON T1.CODTREZOR = T.CODTREZOR
    LEFT JOIN NC ON NC.CODNC = G.CODDOC AND G.CODDOC = 35
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = G.MONEDA
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = COALESCE(NC.SUBUNITATEA, T.SUBUNITATEA, C.SUBUNITATEA, I.SUBUNITATEA)
    LEFT JOIN nsubunit sub ON sub.codsubunit = COALESCE(NC.SUBUNITATEA, T.SUBUNITATEA, C.SUBUNITATEA, I.SUBUNITATEA)&apos;||
    gSuplJoins||&apos;
  WHERE s.codstinspif = :1&apos;;

  FOR vRec IN (
    SELECT O.Codobligpif
    FROM IESIRI I
      INNER JOIN GENERAL G ON G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE I.PARTENER = PKG_LIST_SELURMDOCPART.CODPART
      AND I.NRDOC = PKG_LIST_SELURMDOCPART.NRDOC
      AND I.DATADOC = PKG_LIST_SELURMDOCPART.DATADOC
      AND O.SEMNIFICATIE = 200 )
  LOOP
    EXECUTE IMMEDIATE sInsert||sSelect USING vRec.Codobligpif;
  END LOOP;
  COMMIT;

END;

END PKG_LIST_BASE_URMINCASARIDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMLOHN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2193CC7C7BB40EC03EFF4EB784C62071AC8A3487</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmlohn IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  TYPE t_rows IS TABLE OF rowid INDEX BY PLS_INTEGER;

  CURSOR c_rows IS SELECT Min(ROWID) FROM tmp_list_lohn WHERE coefin = 1 GROUP BY codintr1;

  b_rows    t_rows;
  sInsTmp   VARCHAR2(30000);
  sInsert   VARCHAR2(15000);
  sSelect   VARCHAR2(20000);
  sData1    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataS,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sData2    VARCHAR2(  100) := &apos;to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_ALEGPERIOADA.getDataF,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  sJoinExt  VARCHAR2( 1000);
  sFiltru   VARCHAR2( 1000);
BEGIN
  gSuplCols :=
   &apos;iesiri1 ies1, iesiri ies, npart iesp, npartcodfisc iesfisc, nagenda iesssoc, nlocalit ieslsoc, njudet iesjsoc, nzone ieszsoc, ntari iestsoc, num1 iesu, nartobj oies, livr1 l1, livr l, intrari1 np1, intrari np, &apos;||
   &apos;comanda1 ci1, comanda ci, comanda1 cc1, comanda cc, iesiri1 bc1, iesiri bc, cmdprodmat cpm, prodmat pm, nartobj obc, livr1 bcl1, livr bcl, intrari1 intr1, intrari intr, npart intrp, npartcodfisc intrfisc, &apos;||
   &apos;nagenda intrssoc, nlocalit intrlsoc, njudet intrjsoc, nzone intrzsoc, ntari intrtsoc, num1 intru, ioart1 eioa1, ncont ec, ioart1 iioa1, ncont ic&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OPEXT&apos;, &apos;OPEXT.CODOBIECT = IES1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OPATR&apos;, &apos;OPATR.CODOBIECT = IES1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OMEXT&apos;, &apos;OMEXT.CODOBIECT = INTR1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OMATR&apos;, &apos;OMATR.CODOBIECT = INTR1.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;IOART1&apos;);
  
  IF PKG_LIST_ALEGPERIOADA.optiunea1 THEN
    sFiltru := &apos;
    AND Nvl(ic.clasa,0) = 8&apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CODDOC, NAV_TIPDOC, PRODUS, MATERIAL,
    IESPREF, IESNR, IESDATA, IESPART, IESCIF, IESSSOC_DEN, IESSSOC_LOC, IESSSOC_JUD, IESSSOC_TARA, IESSSOC_ZONA,
    IESSSOC_ADR,
    IESUM, IESCANT, IESPU,
    NPPREF, NPNR, NPDATA, NPCANT,
    CIPREF, CINR, CIDATA,
    CCPREF, CCNR, CCDATA,
    BCPREF, BCNR, BCDATA, BCCANT, RETCANT, RETREST,
    INTRPREF, INTRNR, INTRDATA, INTRPART, INTRCIF, INTRSSOC_DEN, INTRSSOC_LOC, INTRSSOC_JUD, INTRSSOC_TARA, INTRSSOC_ZONA,
    INTRSSOC_ADR,
    INTRUM, INTRCANT, INTRCANTX, INTRPU &apos;||
    gUserFields||&apos;)&apos;;

  sInsTmp := &apos;
  INSERT INTO tmp_list_lohn (
    codies1, codl1, codnp1, codci1, codcc1, codbc1, codbcl1, codcpm, codintr1,
    codiioa1, codeioa1, iescodcif, intrcodcif, iescodssoc, intrcodssoc,
    coefx, coefin)
  SELECT
    ies1.codies1, l1.codlivr1 codl1, np1.codintr1 codnp1, ci1.codcomanda1 codci1, cc1.codcomanda1 codcc1, bc1.codies1 codbc1, bcl1.codlivr1 codbcl1, cpm.codcmdprodmat codcpm, intr1.codintr1,
    iioa1.codioart1 codiioa1,eioa1.codioart1 codeioa1, iesfisc.cod_codfiscal iescodcif, intrfisc.cod_codfiscal intrcodcif, iesssoc.codagenda iescodssoc, intrssoc.codagenda intrcodssoc,
    0 coefx, CASE WHEN ies1.cant &lt; 0 THEN 0 ELSE 1 END coefin
  FROM iesiri ies
    inner join npart        iesp     ON iesp.codpart = ies.partener
    left  join npartcodfisc iesfisc  on iesfisc.codpart = ies.partener and iesfisc.principal = 1
    left  join nagenda      iesssoc  on iesssoc.codpart = ies.partener and iesssoc.sediusocial between 4 and 7 and nvl(iesssoc.inactiv, 0) = 0
    inner join iesiri1      ies1     ON ies1.codies = ies.codies
    inner join nartobj      oies     ON oies.codobiect = ies1.codobiect
    inner join livr1        l1       ON l1.codies1 = ies1.codies1
    inner join livr         l        ON l.codlivr = l1.codlivr AND l.codies = ies.codies AND l.tiplivr = ies.tipdoc
    inner join nirstoc      ens      ON ens.codnirstoc = l1.codnirstoc
    inner join nirstoc1     ens1     ON ens1.codnirstoc = l1.codnirstoc
    inner join nirstoc      eons     ON eons.codnirstoc = ens1.codnirstocorig
    inner join intrari1     np1      ON np1.codintr1 = eons.codintr1
    inner join intrari      np       ON np.codintr = np1.codintr
    inner join comanda1     ci1      ON ci1.codcomanda1 = np1.codcmdint1
    inner join comanda      ci       ON ci.codcomanda = ci1.codcomanda
    left  join cmdlink      cl       ON cl.codcomanda1 = ci1.codcomanda1
    left  join comanda1     cc1      ON cc1.codcomanda1 = cl.codliniecomanda
    left  join comanda      cc       ON cc.codcomanda = cc1.codcomanda
    inner join iesiri1      bc1      ON bc1.codcmdint1 = ci1.codcomanda1
    inner join iesiri       bc       ON bc.codies = bc1.codies
    left  join iesprodlink  ipl      ON ipl.codies1 = bc1.codies1
    left  join cmdprodmat   cpm      ON cpm.codcmdprodmat = ipl.codcmdprodmat
    left  join prodmat      pm       ON pm.codmat = cpm.codprodmat
    inner join nartobj      obc      ON obc.codobiect = bc1.codobiect
    inner join livr1        bcl1     ON bcl1.codies1 = bc1.codies1
    inner join livr         bcl      ON bcl.codlivr = bcl1.codlivr AND bcl.codies = bc.codies AND bcl.tiplivr = bc.tipdoc
    inner join nirstoc1     ins1     ON ins1.codnirstoc = bcl1.codnirstoc
    inner join nirstoc      ins      ON ins.codnirstoc = ins1.codnirstocorig
    inner join nir          inir     ON inir.codnir = ins.codnir
    left  join dvi1         idvi1    on idvi1.coddvi1 = ins.coddvi1
    inner join intrari1     intr1    ON intr1.codintr1 = Nvl(idvi1.codintr1, ins.codintr1)
    inner join intrari      intr     ON intr.codintr = intr1.codintr AND intr.tipdoc = inir.tipnir
    left  join npart        intrp    on intrp.codpart = intr.partener
    left  join npartcodfisc intrfisc on intrfisc.codpart = intr.partener and intrfisc.principal = 1
    left  join nagenda      intrssoc on intrssoc.codpart = intr.partener and intrssoc.sediusocial between 4 and 7 and nvl(intrssoc.inactiv, 0) = 0
    left  join ioart1       eioa1    ON eioa1.codioart = ens.codioart AND (ies.an*12+ies.luna)   BETWEEN eioa1.ALStart and eioa1.ALStop
    left  join ioart1       iioa1    ON iioa1.codioart = ins.codioart AND (intr.an*12+intr.luna) BETWEEN iioa1.ALStart and iioa1.ALStop
    left  join ncont        ic       ON ic.codcont = iioa1.cont
  WHERE ies.operat = 1 AND ies.anulat = 0
    AND ies.DataDoc BETWEEN &apos;||sData1||&apos; AND &apos;||sData2||
    sFiltru||
    PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;ies&apos;);

  sSelect := &apos;
  SELECT
    ies.codies, ies.tipdoc, oies.denumire produs, obc.denumire mat,
    ies.prefixdoc, ies.nrdoc, ies.datadoc, iesp.den_part, iesfisc.codfiscal, iesssoc.obs, ieslsoc.den_localit, iesjsoc.den_judet, iestsoc.den_tara, ieszsoc.den_zona,
    getadresa(iesssoc.sector, iesssoc.strada, iesssoc.nr1, iesssoc.nr2, iesssoc.bloc, iesssoc.scara, iesssoc.etaj, iesssoc.apart, iesssoc.codpostal),
    iesu.den_um1, l1.cant/iesu.paritate, ies1.pu*iesu.paritate,
    np.prefixdoc, np.nrdoc, np.datadoc, tmp.coefin*np1.cant/iesu.paritate,
    ci.prefixdoc, ci.nrdoc, ci.datadoc,
    cc.prefixdoc, cc.nrdoc, cc.datadoc,
    bc.prefixdoc, bc.nrdoc, bc.datadoc, tmp.coefin*bcl1.cant/intru.paritate bccant,
    tmp.coefin*Decode(bc1.cant,0,0,cpm.cant*bcl1.cant/bc1.cant)/intru.paritate retcant, tmp.coefin*Decode(bc1.cant,0,0,cpm.rest*bcl1.cant/bc1.cant)/intru.paritate retrest,
    intr.prefixdoc, intr.nrdoc, intr.datadoc, intrp.den_part, intrfisc.codfiscal, intrssoc.obs, intrlsoc.den_localit, intrjsoc.den_judet, intrtsoc.den_tara, intrzsoc.den_zona,
    getadresa(intrssoc.sector, intrssoc.strada, intrssoc.nr1, intrssoc.nr2, intrssoc.bloc, intrssoc.scara, intrssoc.etaj, intrssoc.apart, intrssoc.codpostal),
    intru.den_um1, tmp.coefin*intr1.cant/intru.paritate, tmp.coefin*tmp.coefx*intr1.cant/intru.paritate, intr1.pu*intru.paritate&apos;||gUserAlias||&apos;
  FROM tmp_list_lohn tmp
    left join iesiri1      ies1     ON ies1.codies1 = tmp.codies1
    left join iesiri       ies      ON ies.codies = ies1.codies
    left join npart        iesp     ON iesp.codpart = ies.partener
    left join npartcodfisc iesfisc  on iesfisc.cod_codfiscal = tmp.iescodcif
    left join nagenda      iesssoc  on iesssoc.codagenda = tmp.iescodssoc
    left join nlocalit     ieslsoc  on ieslsoc.codlocalit = iesssoc.codlocalit
    left join njudet       iesjsoc  on iesjsoc.codjudet = ieslsoc.codjudet
    left join nzone        ieszsoc  on ieszsoc.codzona = ieslsoc.codzona
    left join ntari        iestsoc  on iestsoc.codtara = ieslsoc.codtara
    left join num1         iesu     ON iesu.codum1 = ies1.umsec
    left join nartobj      oies     ON oies.codobiect = ies1.codobiect
    left join livr1        l1       ON l1.codlivr1 = tmp.codl1
    left join livr         l        ON l.codlivr = l1.codlivr
    left join intrari1     np1      ON np1.codintr1 = tmp.codnp1
    left join intrari      np       ON np.codintr = np1.codintr
    left join comanda1     ci1      ON ci1.codcomanda1 = tmp.codci1
    left join comanda      ci       ON ci.codcomanda = ci1.codcomanda
    left join comanda1     cc1      ON cc1.codcomanda1 = tmp.codcc1
    left join comanda      cc       ON cc.codcomanda = cc1.codcomanda
    left join iesiri1      bc1      ON bc1.codies1 = tmp.codbc1
    left join iesiri       bc       ON bc.codies = bc1.codies
    left join cmdprodmat   cpm      ON cpm.codcmdprodmat = tmp.codcpm
    left join prodmat      pm       ON pm.codmat = cpm.codprodmat
    left join nartobj      obc      ON obc.codobiect = bc1.codobiect
    left join livr1        bcl1     ON bcl1.codlivr1 = tmp.codbcl1
    left join livr         bcl      ON bcl.codlivr = bcl1.codlivr
    left join intrari1     intr1    ON intr1.codintr1 = tmp.codintr1
    left join intrari      intr     ON intr.codintr = intr1.codintr
    left join npart        intrp    on intrp.codpart = intr.partener
    left join npartcodfisc intrfisc on intrfisc.cod_codfiscal = tmp.intrcodcif
    left join nagenda      intrssoc on intrssoc.codagenda = tmp.intrcodssoc
    left join nlocalit     intrlsoc on intrlsoc.codlocalit = intrssoc.codlocalit
    left join njudet       intrjsoc on intrjsoc.codjudet = intrlsoc.codjudet
    left join nzone        intrzsoc on intrzsoc.codzona = intrlsoc.codzona
    left join ntari        intrtsoc on intrtsoc.codtara = intrlsoc.codtara
    left join num1         intru    ON intru.codum1 = intr1.umsec
    left join ioart1       eioa1    ON eioa1.codioart1 = tmp.codeioa1
    left join ncont        ec       ON ec.codcont = eioa1.cont
    left join ioart1       iioa1    ON iioa1.codioart1 = tmp.codiioa1
    left join ncont        ic       ON ic.codcont = iioa1.cont&apos;||
    gSuplJoins;

  DELETE tmp_list_lohn;
  LIST_EXECUTE_IMMEDIATE(sInstmp, aListID, aListVer);

  OPEN c_rows;
  LOOP
    FETCH c_rows BULK COLLECT INTO b_rows LIMIT 1000;
    EXIT WHEN b_rows.COUNT = 0;
    FORALL i IN 1 .. b_rows.COUNT UPDATE tmp_list_lohn SET coefx = 1 WHERE rowid = b_rows(i);
  END LOOP;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END pkg_list_base_urmlohn;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMNCCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47994B927D06986713FEBB238741E3DB92E28D5B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmnccli IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(15000);
  sSelect  VARCHAR2(20000);
BEGIN
  gSuplCols := &apos;notecredit nc, notecreditfact ncf, iesiri i, iesiri1 i1, npart p, nartobj o, num1 um, ncont ncont&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NAGENDA&apos;, &apos;SSOC&apos;, &apos;SSOC.CODPART = I.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NPERS&apos;, &apos;PAG&apos;, &apos;PAG.CODPERS = SSOC.CODAGENT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc, NCDATAI, NCDATAS,
    PrefixDoc, NrDoc, DataDoc, Part, Art, Cont,
    UM, Cant,
    Pret, PU, PD,
    VAL, VALTVA,
    PROCTVA &apos;||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  SELECT
    nc.codncredit, 58, nc.datastart, nc.datastop,
    i.prefixdoc, i.nrdoc, i.datadoc, p.den_part, o.denumire, ncont.simbol,
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN &apos;&apos;%&apos;&apos; ELSE um.den_um1 END, i1.cant/NVL(um.paritate,1),
    i1.pretorig*um.paritate, i1.pu*um.paritate, i1.pretorig*um.paritate*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj),
    CASE WHEN i1.tiplinie IN (&apos;&apos;T&apos;&apos;,&apos;&apos;G&apos;&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END, i1.tva,
    CASE
      WHEN NVL(i1.tva,0) = 0 THEN 0
      WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = NVL(i1.tva,0) THEN 0
      WHEN i.tipdoc IN (16,21) THEN NVL(i1.tva,0) / decode(  (i1.pu * i1.cant-NVL(i1.tva,0)),0,1,(i1.pu * i1.cant-NVL(i1.tva,0))  )
      WHEN i1.pu * i1.cant = 0 THEN 0
      ELSE NVL(i1.tva,0) / decode ( (i1.pu * i1.cant),0,1,(i1.pu * i1.cant) )
    END * 100 &apos;||gUserAlias||&apos;
  FROM notecredit nc
    INNER JOIN notecreditfact ncf ON ncf.codncredit = nc.codncredit
    INNER JOIN iesiri i ON i.codies = ncf.coddoc AND i.tipdoc = ncf.tipdoc
    INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    INNER JOIN npart p ON p.codpart = i.partener
    INNER JOIN nartobj o ON o.codobiect = i1.codobiect
    INNER JOIN num1 um ON um.codum1 = i1.umsec
    LEFT JOIN ncont ON ncont.codcont = Coalesce(i1.contserv,i1.contdiscount,0)&apos;||
    gSuplJoins||&apos;
  WHERE i.operat = 1 AND i.anulat = 0 &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;NC&apos;)||&apos;
    AND i.DataDoc BETWEEN :1 AND :2&apos;;

  EXECUTE IMMEDIATE sInsert||sSelect USING PKG_LIST_ALEGPERIOADA.getDataS, PKG_LIST_ALEGPERIOADA.getDataF;
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;
END PKG_LIST_BASE_URMNCCLI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE42D5F7AF1F0F26A065BB4471BE840CBA5BCCE8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMOFE IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(20000);
  sFiltru    VARCHAR2(10000) := &apos;&apos;;
  sPASubunit VARCHAR2(10000) := &apos;&apos;;
  sPAFiltru  VARCHAR2(10000) := &apos;&apos;;
  sJoinPA    VARCHAR2(10000) := &apos;&apos;;
  sCursPA    VARCHAR2(10000) := &apos;&apos;;
  vTipDoc    INTEGER;
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  sInsAchiz VARCHAR2(100);
  sSelAchiz VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;Oferta O, Oferta1 O1, NArtObj AO, NPart P, NUM1 UM, NMonede M, NartCli AC, NClaseA CLSA, NClaseAS CLSS, PretM PM, Oportunitati OPORT &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;,   &apos;OEXT.CODOBIECT = O1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;,   &apos;OATR.CODOBIECT = O1.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTAEXT&apos;,  &apos;OFEXT&apos;,  &apos;OFEXT.CODOFERTA = O1.CODOFERTA&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;OFERTA1EXT&apos;, &apos;OF1EXT&apos;, &apos;OF1EXT.CODOFERTA1 = O1.CODOFERTA1&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ1&apos;,   &apos;AO1&apos;,    &apos;AO1.CODOBIECT = O1.CODOBIECT AND O.An*12+O.Luna BETWEEN AO1.ALSTART AND AO1.ALSTOP&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJ1&apos;,   &apos;AO1M&apos;,   &apos;AO1M.CODOBIECT = O1.CODOBIECT AND &apos;||pkg_globals.AnLunaLucru||&apos; BETWEEN AO1M.ALSTART AND AO1M.ALSTOP&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  IF InStr(gSuplJoins, &apos;NARTOBJ1 &apos;) &gt; 0 THEN
    PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  END IF;

  IF pkg_categconst.GetValConstanta(&apos;PretAchizSubunit&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 2 THEN
    sPASubunit := &apos;, NG.CODSUBUNIT&apos;;
    sPAFiltru  := &apos; AND PA.CODSUBUNIT = O.SUBUNITATEA&apos;;
    sJoinPA    := &apos;
      INNER JOIN NGEST NG ON NG.CODGEST = N.GEST&apos;;
  END IF;

  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
	  sCursPA   := &apos;/ PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, pa.dataachizlast )&apos;;
  END IF;

  IF NOT PKG_LIST_SELURMOFE.TotiPart THEN
    sFiltru := &apos;
    AND O.Partener IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  sInsAchiz := &apos;&apos;;
  sSelAchiz := &apos;&apos;;
  IF aLISTID = 144
  THEN
    vTipDoc := 50;
    sInsAchiz := &apos;,PretAchiz,ValAchiz,Marja,ValMarja&apos;;
    sSelAchiz := &apos;,O1.PretAchiz,O1.PretAchiz*O1.CantMin,case when nvl(O1.PretAchiz,0) &gt; 0 then (O1.Pret - O1.PretAchiz)/O1.Pret*100 else 0 end, case when nvl(O1.PretAchiz,0) &gt; 0 then O1.Pret - O1.PretAchiz else 0 end&apos;;
  ELSE
    vTipDoc := 51;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, NAV_TipDoc,
    Art, Part, UM, CantMin, Pret, DataStart, DataEnd,
    Moneda, NrDoc, ZileL, ZileC, PjAdaos, PjDisc, Agent,
    PRACHIZLAST, PRACHIZLASTV, PRACHIZMAX, PRINREGLAST &apos;||sInsAchiz||gUserFields||&apos;)&apos;;

  sSelect :=&apos;
  WITH PA AS (
    SELECT
      NS.CODOBIECT&apos;||sPASubunit||&apos;,
      MAX(NS.PRET-COALESCE(NS.ADAOS,0)) KEEP (DENSE_RANK LAST ORDER BY N.DATANIR) PRACHIZLAST,
      MAX(NS.PRET) KEEP (DENSE_RANK LAST ORDER BY N.DATANIR) PRINREGLAST,
      MAX(N.DATANIR) DATAACHIZLAST,
      MAX(NS.PRET-NS.ADAOS) PRACHIZMAX
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR&apos;||
      sJoinPA||&apos;
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0
    GROUP BY NS.CODOBIECT&apos;||sPASubunit||&apos;)
  SELECT
    O.CodOferta, O.TipDoc,
    AO.Denumire, P.Den_Part, UM.Den_UM1, O1.CantMin/UM.Paritate, O1.Pret*UM.Paritate, O.DataStart, O.DataEnd,
    M.Den_Moneda, O.NrDoc, O1.ZileL, O1.ZileC, O1.ProcAdaos, O1.ProcDiscount, Decode(AG.CodPers,0,AG.Nume,AG.NUME||&apos;&apos; &apos;&apos;||AG.PRENUME),
    pa.prachizlast, pa.prachizlast &apos;||sCursPA||&apos;, pa.prachizmax, pa.prinreglast &apos;||sSelAchiz||gUserAlias||&apos;
  FROM Oferta O
    INNER JOIN Oferta1 O1 ON O1.CodOferta = O.CodOferta
    INNER JOIN NArtObj AO ON AO.CodObiect = O1.CodObiect
    INNER JOIN NArt A ON AO.CodArticol = A.CodArticol
    LEFT JOIN NClaseA CLSA ON A.Clasa = CLSA.CodClaseA
    LEFT JOIN NClaseAS CLSS ON A.CLASASTATIST = CLSS.CodClaseAS
    LEFT JOIN NPart P ON P.CodPart = O.Partener
    LEFT JOIN NUM1 UM ON UM.CodUM1 = O1.UMSec
    LEFT JOIN NMonede M ON M.CodMoneda = O.Moneda
    LEFT JOIN NartCli AC ON AC.CodObiect = O1.CodObiect AND AC.CodPart = O.Partener
    LEFT JOIN NPERS AG ON AG.CODPERS = Nvl(O.AGENT,0)
    LEFT JOIN PRETM PM ON PM.CodObiect = O1.CodObiect AND PM.Subunitatea = O.Subunitatea AND PM.Implicit = 1
    LEFT JOIN OPORTUNITATI OPORT ON OPORT.CodOferta = O.CodOferta
    LEFT JOIN PA ON PA.CodObiect = O1.CodObiect&apos;||sPAFiltru||
    gSuplJoins||&apos;
  WHERE O.TipDoc = &apos;||vTipDoc||&apos;
    AND O.DataEnd &gt;= to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELURMOFE.DataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
    AND O.DataStart &lt;= to_date(&apos;&apos;&apos;||To_Char(PKG_LIST_SELURMOFE.DataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||
    sFiltru;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;


end PKG_LIST_BASE_URMOFE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMPLATIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A090B7C576C708FDEEF15E994453FD03E37630E9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmplatiart IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

FUNCTION GetCodContract(aCodPart in number, aDataDoc in Date) return number is
aCodContract number(20);
BEGIN
  BEGIN
    select NVL(CodContract, 0) into aCodContract
    from contract c
    where c.partener = aCodPart and aDataDoc between c.datastart and c.datastop;
  EXCEPTION
    when others then aCodContract := 0;
  END;
  RETURN aCodContract;
END;

PROCEDURE processlist(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2( 2000);
  sSelect      VARCHAR2(32000);
  sTipJoin     VARCHAR2(  100) := &apos;INNER&apos;;
  sAnS         NUMBER(      4) := EXTRACT(YEAR  FROM pkg_list_alegperioada.getDataS);
  sLunaS       NUMBER(      2) := EXTRACT(MONTH FROM pkg_list_alegperioada.getDataS);
  sDataS       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataS,&apos;dd.mm.yyyy&apos;);
  sDataF       VARCHAR2(  100) := To_Char(pkg_list_alegperioada.getDataF,&apos;dd.mm.yyyy&apos;);
  AnLunaLucru  NUMBER(     20);
  AnLunaIni    NUMBER(     20);
  sCurs        VARCHAR2( 1000) := &apos;, 1, 1, 1, 1&apos;;
  aBancaV      NUMBER(     20);
  aMonedaV     NUMBER(     20);
  ConstCC      NUMBER(     5);
BEGIN
  ConstCC  := pkg_categconst.GetValConstanta(&apos;ScadenteAutomateCost&apos;,      pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  
  gSuplCols := &apos;tmp_lst_urmplartiart un, intrari1 i1, intrari i, nartobj o, npers agp, npart npart, nclasep clsp, nagenda ag, nlocalit loc, njudet jud, nmonede mon, nmonede monprest, pretm pm, nsubunit SubSting, nsubunit SubStins, &apos;||
               &apos;npart prod, nart a, nclasea ca, nartcli ac, ncont c, nbankcont bc, nbank b&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  PRC_AL_CHECK(&apos;NARTOBJ1&apos;);
  
  SELECT PKG_GLOBALS.GETANLUCRU*12+PKG_GLOBALS.GETLunaLucru, ANINITIAL*12+LUNAINITIALA INTO AnLunaLucru, AnLunaIni FROM FIRMALUNI;

  aBancaV  := pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,      pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  --aMonedaV := pkg_categconst.GetValConstanta(&apos;MonedaFactInValuta&apos;,pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  aMonedaV := pkg_list_base_utils.GET_Cod_MonedaFactInValuta(pkg_globals.ANLUCRU,pkg_globals.LunaLucru);
  IF Nvl(aMonedaV,0) &lt;&gt; 0 AND Nvl(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := &apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := &apos;,1, 1&apos;;
  END IF;

  IF Nvl(aBancaV,0) &lt;&gt; 0 THEN
	  sCurs := sCurs||&apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstinsdata), PKG_LIST_BASE_UTILS.GETCURSREFERINTA(N1.CODMONEDA,&apos;||aBancaV||&apos;, un.dstingdata)&apos;;
  ELSE sCurs := sCurs||&apos;,1, 1&apos;;
  END IF;

  IF pkg_list_alegperioada.optiunea1 THEN
    sTipJoin := &apos;LEFT&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;||tmpName ||&apos;(
    NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc,
    DSTINSPR, DSTINSNR, DSTINSDATA, TOTAL_DOCUMENT, VAL_NESTINSA_DOC, VAL_STINGATOR, VAL_STINGFTVA,
    SOLD_LIN, SOLD_LINF, ORDINE,
    SOLD_DOC, SOLD_DOCF, ORDDOC,
    DSTINGPR, DSTINGNR, DSTINGDATA, PARTENER, LOCATIE, DATADECONT, DATA, DATAPLATA, DATA_STINS, TERMEN, MONEDA, SUBUNIT, SUBUNIT_ST,
    SCADENTA, DIFZILE, DEPZILE, DEPZILEDEC, DEPZILEPLATA, CONT, ARTICOL, CODEXTERN, CODINTERN, PRODUCATOR, CLASAARTICOL,
    DSTINSCURS, DSTINSAN, DSTINSLUNA, DSTINGCURS, DSTINGAN, DSTINGLUNA, GESTDEN, GESTSIMB, NRCONT,
    DSTINSCURS_REF, DSTINGCURS_REF, DSTINSCURS_PREST, DSTINGCURS_PREST&apos;||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH crs_sold as (
    SELECT
      g.coddoc, g.tipdoc,
      SUM(
        (ol.rest - (
          SELECT NVL(sum(s.valoare), 0)
          FROM stingere s
            INNER JOIN obligpif os ON os.codobligpif = s.codstingatorpif
            INNER JOIN general  gs ON gs.codgeneral  = os.codgeneral
            LEFT  JOIN trezor1  t1 on gs.coddoc = t1.codtrezor1 AND gs.tipdoc &lt;&gt; 28 AND t1.luna = &apos;||sLunaS||&apos; AND t1.an = &apos;||sAnS||&apos; AND t1.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
            LEFT  JOIN compens  c  ON gs.coddoc = c.codcompens AND gs.tipdoc = 28 AND c.luna = &apos;||sLunaS||&apos; AND c.an = &apos;||sAnS||&apos; AND c.datadoc &lt; TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
          WHERE s.codstinspif = ol.codobligpif
            AND Nvl(t1.codtrezor,c.codcompens) IS NOT NULL
        )) * DECODE(g.semnificatie,310,-1,1)
      ) rest
    FROM obligpifluna ol
      INNER JOIN obligpif op on ol.codobligpif = op.codobligpif
      INNER JOIN general  g  on op.codgeneral  = g.codgeneral
    WHERE (g.tipdoc BETWEEN 1 AND 7 OR g.tipdoc = 35)
      AND ol.luna + ol.an*12 = &apos;||To_Char(sAnS*12+sLunaS-1)||&apos;
    GROUP BY g.coddoc, g.tipdoc),
  stinsi as(
    SELECT
      coddoc1, coddoc, tipdoc, indexlocal, codobiect, codgeneral, prefixdoc, nrdoc, datadoc, subunitatea, curs, moneda, codobligpif,
      valoarelinie, valdoc,
      CASE
        WHEN valoare = 0 THEN 0
        WHEN valoarelinie = 0 THEN 0
        WHEN Sum( valoarelinie ) OVER (PARTITION BY codobligpif, codcentrui) = 0 THEN 0
        ELSE valoarelinie * valoare/ Sum( valoarelinie ) OVER (PARTITION BY codobligpif, codcentrui)
      END valobliglinie,
      COEFTVA,
      valoare, codpart, codlocatie, termen, an, luna, codcont, codbanca
    FROM (
      SELECT
        i1.codintr1 coddoc1, i.codintr coddoc, i.tipdoc, i1.indexlocal,i1.codobiect, o.codgeneral,i.prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
        (i1.pu*i1.cant+DECODE(i.tipdoc,3,0,i1.tva))*nvl(i1.coefdiscmaj,1)*DECODE(i1.pu,i1.pretorig,1,0,0,i1.pretorig/i1.pu) valoarelinie, i.valdoc,
        CASE
          WHEN i.tipdoc = 3 and I1.PU * I1.CANT &lt;&gt; 0 THEN (I1.PU * I1.CANT-I1.TVA)/(I1.PU * I1.CANT)
          WHEN i.tipdoc &lt;&gt; 3 AND I1.PU * I1.CANT+I1.TVA &lt;&gt; 0 THEN (I1.PU * I1.CANT)/(I1.PU * I1.CANT+I1.TVA)
          ELSE 1
        END COEFTVA,
        o.valoare, o.codpart, i.codlocatie, o.termen, i.an, i.luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,i.an*12+i.luna,o.semnificatie) codcont, 0 codbanca,
        Nvl(O.CodCentru,0) CodCentruO, Nvl(i1.codcentru,0) CodCentruI, Max( Nvl(O.CodCentru,0) ) OVER (PARTITION BY i.codintr) CodCentruM
      FROM intrari i
        INNER JOIN intrari1 i1  ON i.codintr    = i1.codintr
        INNER JOIN nartobj  obj ON i1.codobiect = obj.codobiect
        INNER JOIN general  g   ON g.coddoc     = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 600
        INNER JOIN obligpif o   ON g.codgeneral = o.codgeneral &apos;;
   if ConstCC = 1 then     
     sSelect := sSelect||     
        &apos; AND Nvl(o.codcentru,0) = Nvl(i1.codcentru,0)&apos;;
   end if;     
   sSelect := sSelect||     
    &apos;  WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 0 AND NVL(i1.codobiect,0) &lt;&gt; 0 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    )
    UNION ALL
    SELECT
      0 coddoc1, i.codintr coddoc, i.tipdoc, 0 indexlocal, -1 codobiect, o.codgeneral, &apos;&apos;sold initial &apos;&apos; prefixdoc, i.nrdoc, i.datadoc, i.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      o.valoare valoarelinie, o.valoare valdoc,
      o.valoare valobliglinie,
      1 COEFTVA,
      o.valoare, o.codpart, i.codlocatie, o.termen, i.an, i.luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,&apos;||AnLunaIni||&apos;,o.semnificatie) codcont, 0 codbanca
    FROM intrari i
      INNER JOIN general  g ON g.coddoc     = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie &lt;&gt; 600 and g.semnificatie &lt;&gt; 140
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
    WHERE NVL(i.anulat, 0) = 0 and nvl(i.initializari, 0) = 1 AND i.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    UNION ALL
    SELECT
      t1.CodTrezor1 CodDoc1, t.CodTrezor CodDoc, t.TipDoc, t1.indexlocal, -2 codobiect, o.codgeneral, t1.doc prefixdoc, t1.nrdoc, t1.datadoc, t.subunitatea, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, o.codobligpif,
      -o.valoare valoarelinie, -o.valoare valdoc,
      -o.valoare valobliglinie,
      CASE WHEN NVL(o.valoare,0) = 0 THEN 1 ELSE (o.valoare-nvl(g.tva,0))/o.valoare END COEFTVA,
      -o.valoare, o.codpart, t1.codlocatie, o.termen, t.An, t.Luna, PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart,t1.an*12+t1.luna,o.semnificatie) cont, t.codbanca
    FROM trezor1 t1
      INNER JOIN general  g ON g.coddoc     = t1.codtrezor1 AND g.semnificatie = 310
      INNER JOIN obligpif o ON g.codgeneral = o.codgeneral
      INNER JOIN trezor   t ON t1.codtrezor = t.codtrezor
    WHERE NVL(t1.anulat, 0) = 0 AND t1.datadoc &lt;= TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;t&apos;)||&apos;),
  stingatori as (
    SELECT
      o.CodObligPIF, o.Codgeneral, t.codtrezor CodDoc, t1.codtrezor1 CodDoc1, g.TipDoc, t1.doc PrefixDoc, t1.nrdoc, t1.datadoc, t1.DATADECONT, t1.datadoc DATA, COALESCE(t1x.datadoc, t1.datadecont, t1.datadoc) DATAPLATA,
      t1.agent, t.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(t1.curs,NULL,1,0,1,t1.curs) curs, COALESCE(t.monedapers, bc.codmoneda, 0) moneda, t.an, t.luna, t.codbanca
    FROM trezor1 t1
      INNER JOIN trezor    t   ON t1.codtrezor  = t.codtrezor
      INNER JOIN general   g   ON t1.codtrezor1 = g.coddoc and g.tipdoc = t.tipdoc
      INNER JOIN obligpif  o   ON o.codgeneral  = g.codgeneral
      INNER JOIN stingere  s   ON s.codstingatorpif = o.codobligpif
      LEFT  JOIN nbankcont bc  ON bc.codbankcont = t.codbanca
      LEFT  JOIN general   gc  ON gc.coddoc      = g.coddoc AND gc.semnificatie = 600 AND gc.semnificatie &lt;&gt; g.semnificatie
      LEFT  JOIN obligpif  oc  ON oc.codgeneral  = gc.codgeneral
      LEFT  JOIN stingere  sx  ON sx.codstinspif = Nvl(oc.codobligpif, o.codobligpif)
      LEFT  JOIN obligpif  ox  ON ox.codobligpif = sx.codstingatorpif
      LEFT  JOIN general   gx  ON gx.codgeneral  = ox.codgeneral
      LEFT  JOIN trezor1   t1x ON t1x.codtrezor1 = gx.coddoc
    WHERE T1.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND ((G.TipDoc IN (29, 30, 31, 33) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 1)) AND g.semnificatie &lt;&gt; 800&apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;) ELSE NULL END||&apos;
    UNION ALL
    SELECT
      o.CodObligPIF, o.Codgeneral, c.codcompens CodDoc, NULL CodDoc1, g.TipDoc, &apos;&apos;PV&apos;&apos;, c.nrdoc, c.datadoc, null DATADECONT, c.datadoc DATA, c.datadoc DATAPLATA,
      0 Agent, c.Subunitatea, s.codstinspif, s.valoare s_valoare, s.valoare-Nvl(g.tva,0) s_valftva, Decode(g.curs,NULL,1,0,1,g.curs) curs, Nvl(g.moneda,0) moneda, c.an, c.luna, 0 codbanca
    FROM compens c
      INNER JOIN general  g ON g.coddoc     = c.codcompens
      INNER JOIN obligpif o ON o.codgeneral = g.codgeneral
      INNER JOIN stingere s ON s.codstingatorpif = o.codobligpif
    WHERE C.DATADOC BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
      AND G.TipDoc = 28 &apos;||
      CASE WHEN NOT pkg_list_alegperioada.optiunea3 THEN PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;C&apos;) ELSE NULL END||&apos;),
--  NOBJ1 AS (
--    SELECT codobiect, Max(codobiect1) KEEP (DENSE_RANK LAST ORDER BY anstart, lunastart) codobiect1
--    FROM nartobj1 n1
--    WHERE anstart * 12 + lunastart &lt;= &apos;||AnLunaLucru||&apos;
--    GROUP BY codobiect ),
  UN AS ( --*** structura la fel ca tmp_lst_urmplartiart pt coloane suplimentare ***
    SELECT
      stingatori.coddoc NAV_CodDoc, stingatori.coddoc1 NAV_CodDoc1, stingatori.tipdoc NAV_TipDoc, stinsi.prefixdoc DSTINSPR, stinsi.nrdoc DSTINSNR, stinsi.datadoc DSTINSDATA, stinsi.valoarelinie TOTAL_DOCUMENT,
      sign(stinsi.valoare)*Nvl(stingatori.s_valoare,0)*stinsi.valobliglinie/decode(nvl(stinsi.valoare, 0), 0, 1, stinsi.valoare) VAL_STINGATOR,
      sign(stinsi.valoare)*Nvl(stingatori.s_valftva,0)*stinsi.valobliglinie/decode(nvl(stinsi.valoare, 0), 0, 1, stinsi.valoare) VAL_STINGFTVA,
      stinsi.coeftva,
      CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN Nvl(stinsi.valdoc,0) ELSE crs_sold.rest END -
      Nvl(
        SUM(sign(stinsi.valoare)*Nvl(stingatori.s_valoare,0)*stinsi.valobliglinie/decode(nvl(stinsi.valoare,0),0,1,stinsi.valoare))
        OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc ORDER BY stinsi.indexlocal, stinsi.coddoc1, stinsi.termen, stinsi.codobligpif, stingatori.codobligpif ROWS BETWEEN unbounded preceding AND CURRENT ROW )
        , 0
      ) SOLD_DOC,
      ROW_NUMBER() OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc ORDER BY stinsi.indexlocal, stinsi.coddoc1, stinsi.termen, stinsi.codobligpif, stingatori.codobligpif) ORDDOC,
      CASE WHEN NVL(crs_sold.rest, 0) = 0 THEN Nvl(stinsi.valoarelinie,0) WHEN Nvl(stinsi.valdoc,0) = 0 THEN 0 ELSE crs_sold.rest*stinsi.valoarelinie/stinsi.valdoc END -
      Nvl(
        SUM(sign(stinsi.valoare)*Nvl(stingatori.s_valoare,0)*stinsi.valobliglinie/decode(nvl(stinsi.valoare,0),0,1,stinsi.valoare))
        OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1 ORDER BY stinsi.termen, stinsi.codobligpif, stingatori.codobligpif ROWS BETWEEN unbounded preceding AND CURRENT ROW )
        , 0
      ) SOLD_LIN,
      COUNT(1)     OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc) ORDDOCMAX,
      ROW_NUMBER() OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1 ORDER BY stinsi.termen, stinsi.codobligpif, stingatori.codobligpif) ORDLIN,
      COUNT(1)     OVER (PARTITION BY stinsi.coddoc, stinsi.tipdoc, stinsi.coddoc1) ORDLINMAX,
      stingatori.prefixdoc DSTINGPR, stingatori.nrdoc DSTINGNR, stingatori.datadoc DSTINGDATA, stingatori.DATADECONT, stingatori.DATA, stingatori.DATAPLATA, stinsi.datadoc DATA_STINS,
      stinsi.TERMEN, stinsi.termen SCADENTA, trunc(stingatori.Data - stinsi.datadoc) DIFZILE, CASE WHEN trunc(stingatori.data - stinsi.termen) &gt; 0 then trunc(stingatori.data - stinsi.termen) ELSE 0 END DEPZILE,
      case when trunc(COALESCE(stingatori.datadecont,stingatori.data) - stinsi.termen) &gt; 0 then trunc(COALESCE(stingatori.datadecont,stingatori.data) - stinsi.termen) else 0 end DEPZILEDEC,
      case when trunc(stingatori.dataplata - stinsi.termen) &gt; 0 then trunc(stingatori.dataplata - stinsi.termen) else 0 end DEPZILEPLATA,
      stinsi.codpart, Nvl(stingatori.agent,0) agent_sting, stinsi.codcont, Nvl(stinsi.codlocatie,0) codlocatie, stinsi.coddoc, stinsi.coddoc1, stinsi.tipdoc, stinsi.codobiect,
      stinsi.curs dstinscurs, stinsi.moneda, stinsi.subunitatea dstinssub, stingatori.subunitatea dstingsub,
      stinsi.an dstinsan, stinsi.luna dstinsluna, stingatori.an dstingan, stingatori.luna dstingluna, stingatori.curs dstingcurs, CASE WHEN stinsi.codobiect = -2 THEN stinsi.codbanca ELSE stingatori.codbanca  END codbanca
    FROM stinsi
      &apos;||sTipJoin||&apos; JOIN stingatori ON stingatori.codstinspif = stinsi.codobligpif
      LEFT JOIN crs_sold ON crs_sold.coddoc = stinsi.coddoc AND crs_sold.tipdoc = stinsi.tipdoc
    WHERE (NVL(crs_sold.rest,0) &lt;&gt; 0 OR crs_sold.rest IS NULL) AND stinsi.valobliglinie &lt;&gt; 0)
  SELECT
    DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc) NAV_CodDoc, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_CodDoc1) NAV_CodDoc1, DECODE(ts.codsubunit, NULL,NULL,UN.NAV_TipDoc) NAV_TipDoc,
    UN.DSTINSPR, UN.DSTINSNR, UN.DSTINSDATA, Decode(UN.ORDLIN,1,UN.TOTAL_DOCUMENT,0) TOTAL_DOCUMENT, UN.SOLD_LIN + UN.VAL_STINGATOR VAL_NESTINSA_DOCUMENT, UN.VAL_STINGATOR, UN.VAL_STINGATOR * UN.COEFTVA VAL_STINGFTVA,
    UN.SOLD_LIN, DECODE(UN.ORDLIN,UN.ORDLINMAX,UN.SOLD_LIN) SOLD_LINF, UN.ORDLIN,
    UN.SOLD_DOC, DECODE(UN.ORDDOC,UN.ORDDOCMAX,UN.SOLD_DOC) SOLD_DOCF, UN.ORDDOC,
    UN.DSTINGPR, UN.DSTINGNR, UN.DSTINGDATA, NPART.DEN_PART, AG.OBS, UN.DATADECONT, UN.DATA, UN.DATAPLATA, UN.DATA_STINS, UN.TERMEN, mon.den_moneda, SubStins.den_subunit, SubSting.den_subunit,
    UN.SCADENTA, UN.DIFZILE, UN.DEPZILE, UN.DEPZILEDEC, UN.DEPZILEPLATA, C.SIMBOL, DECODE(un.codobiect, -1, &apos;&apos;INITIALIZARE&apos;&apos;, -2, &apos;&apos;AVANS TREZORERIE&apos;&apos;,o.denumire), O.CODEXTERN, O.CODINTERN, PROD.DEN_PART, CA.SIMBOL,
    UN.DSTINSCURS, UN.DSTINSAN, UN.DSTINSLUNA, UN.DSTINGCURS, UN.DSTINGAN, UN.DSTINGLUNA, DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.DEN,G1.DEN_GEST), DECODE (I1.TIPLINIE,&apos;&apos;=&apos;&apos;,G2.SIMB,G1.SIMBOL), BC.NRCONT &apos;||
    sCurs||gUserAlias||&apos;
  FROM UN
    LEFT JOIN intrari             i        on i.codintr     = un.coddoc AND i.tipdoc = un.tipdoc
    LEFT JOIN intrari1            i1       on i1.codintr1   = un.coddoc1 AND i1.codintr = i.codintr
    LEFT JOIN nartobj             o        ON o.codobiect   = un.codobiect
    LEFT JOIN npers               agp      ON agp.codpers   = un.agent_sting
    LEFT JOIN npart               npart    ON npart.codpart = un.codpart
    LEFT JOIN nclasep             clsp     on NVL(npart.codclasa, 0) = clsp.codclasep
    LEFT JOIN nagenda             ag       ON UN.codlocatie = ag.codagenda
    LEFT JOIN nlocalit            loc      on ag.codlocalit = loc.codlocalit
    LEFT JOIN njudet              jud      on loc.codjudet  = jud.codjudet
    LEFT JOIN nmonede             mon      ON mon.codmoneda = nvl(UN.moneda,0)
    LEFT JOIN pretm               pm       on pm.codobiect  = o.CodObiect and pm.implicit = 1 and pm.subunitatea = &apos;||pkg_globals.GETSUBUNITATE||&apos;
    LEFT JOIN nsubunit            SubSting ON SubSting.codsubunit = UN.dstingsub
    LEFT JOIN nsubunit            SubStins ON SubStins.codsubunit = UN.dstinssub
    LEFT JOIN tmp_subunitdedicate ts       ON ts.codsubunit = UN.dstingsub
    LEFT JOIN npart               prod     ON prod.codpart  = o.codproducator
    LEFT JOIN nart                a        ON a.codarticol  = o.codarticol
    LEFT JOIN nclasea             ca       ON ca.codclasea  = a.clasa
     --LEFT JOIN nobj1       on nobj1.codobiect  = o.codobiect
     --LEFT JOIN nartobj1 n1 on nobj1.codobiect1 = n1.codobiect1
    LEFT JOIN nartobj1            n1       on n1.codobiect  = o.codobiect AND &apos;||AnLunaLucru||&apos; BETWEEN n1.ALStart and n1.ALStop
    LEFT JOIN nmonede             monprest ON monprest.codmoneda = nvl(n1.codmoneda,0)
    LEFT JOIN nartcli             ac       ON ac.codobiect   = un.codobiect AND ac.codpart = un.codpart
    LEFT JOIN ncont               c        ON c.codcont      = un.codcont
    LEFT JOIN nbankcont           bc       ON bc.codbankcont = un.codbanca
    LEFT JOIN nbank               b        ON b.codbank  = bc.codbank
    LEFT JOIN ngest               g1       ON g1.codgest = i1.gestact
    LEFT JOIN (
      SELECT ns.codintr1, n.codintr, n.tipnir, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.den_gest) AS vc2_nt)) DEN, vc2_nt_to_vc3200(CAST(COLLECT(DISTINCT ng.simbol) AS vc2_nt)) SIMB
      FROM nirstoc ns
        INNER JOIN nir n ON n.codnir = ns.codnir
        INNER JOIN ngest ng On ng.codgest = n.gest
      WHERE ng.codgest &lt;&gt; 0
      GROUP BY ns.codintr1, n.codintr, n.tipnir
    ) g2 ON g2.codintr1 = i1.codintr1 AND g2.codintr = i.codintr AND g2.tipnir = i.tipdoc&apos;||
    gSuplJoins;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;

END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_urmplatiart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMPLATIDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BD64687F1E51EF3BD65E9A6F0BD0BC5A99C24D1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmplatidoc IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  VARCHAR2(10000);
  sSelect  VARCHAR2(20000);
  aSitV    NUMBER(1);
  aBancaV  NUMBER(20);
  aMonedaV NUMBER(20);
  sCursRef VARCHAR2(200);
  vCursRef NUMBER;
  vSitVal  BOOLEAN;
BEGIN
  gSuplCols := &apos;nmonede mon, nsubunit sub&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vSitVal := pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV);

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName ||&apos; (NAV_CodDoc, NAV_CodDoc1, NAV_TipDoc, PREFIXDOC, DATADOC, NRDOC, TERMEN, MONEDA, MAJORARE, OBLIG, PLATA, SOLD, OBS, ORDINE, CURS_REF &apos;||gUserFields||&apos; )&apos;;

  IF vSitVal
  THEN sCursRef := &apos; PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, I.DATADOC)&apos;;
  ELSE sCursRef := &apos; 1 &apos;;
  END IF;

  sSelect := &apos;
  SELECT G.CodDoc, NULL CodDoc1, G.TipDoc , I.Prefixdoc , I.Datadoc, I.Nrdoc, O.Termen, MON.Simbol, 0 Majorare, O.Valoare, 0 Plata, O.Valoare, I.Obs, 0 Ordine,&apos;||sCursRef||gUserAlias||&apos;
  FROM INTRARI I
    INNER JOIN GENERAL G ON G.CODDOC = I.CODINTR AND G.TIPDOC = I.TIPDOC
    INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = I.Moneda
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = I.SUBUNITATEA
  WHERE I.PARTENER = PKG_LIST_SELURMDOCPART.CODPART
    AND I.NRDOC = PKG_LIST_SELURMDOCPART.NRDOC
    AND I.DATADOC = PKG_LIST_SELURMDOCPART.DATADOC
    AND O.SEMNIFICATIE IN (100,130)&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  IF vSitVal
  THEN sCursRef := &apos; PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, COALESCE(C.DATADOC,T1.DATADOC,NC.DATADOC,I.DATADOC))&apos;;
  ELSE sCursRef := &apos; 1 &apos;;
  END IF;

  sSelect := &apos;
  SELECT
    CASE WHEN TS.CODSUBUNIT IS NULL THEN NULL WHEN G.TipDoc IN (29,30,31,33) THEN T.CODTREZOR ELSE G.CODDOC END NAV_CodDoc,
    CASE WHEN TS.CODSUBUNIT IS NULL THEN NULL WHEN G.TipDoc IN (29,30,31,33) THEN T1.CODTREZOR1 ELSE NULL END NAV_CodDoc,
    CASE WHEN TS.CODSUBUNIT IS NULL THEN NULL ELSE G.TipDoc END NAV_TipDoc,
    CASE WHEN G.TipDoc = 28 THEN &apos;&apos;PV&apos;&apos; WHEN G.TipDoc IN (29,30,31,33) THEN T1.DOC WHEN G.TipDoc = 35 THEN &apos;&apos;NC&apos;&apos; ELSE I.PREFIXDOC END PREFIXDOC,
    CASE WHEN G.TipDoc = 28 THEN C.DATADOC WHEN G.TipDoc IN (29,30,31,33) THEN T1.DATADOC WHEN G.TipDoc = 35 THEN NC.DATADOC ELSE I.DATADOC END DATADOC,
    CASE WHEN G.TipDoc = 28 THEN C.NRDOC WHEN G.TipDoc IN (29,30,31,33) THEN T1.NRDOC WHEN G.TipDoc = 35 THEN NC.NRDOC ELSE I.NRDOC END NRDOC,
    O.TERMEN, MON.SIMBOL, O.MAJORARI, 0,
    CASE WHEN G.SEMNIFICATIE IN (320,1350) THEN - O.VALOARE ELSE O.VALOARE END VALOARE,
    CASE WHEN G.SEMNIFICATIE IN (320,1350) THEN O.VALOARE ELSE - O.VALOARE END SOLD,
    CASE WHEN G.TipDoc = 28 AND G.SEMNIFICATIE IN (1300) THEN C.OBSD WHEN G.TipDoc = 28 AND G.SEMNIFICATIE IN (1350) THEN C.OBSC WHEN G.TipDoc IN (29,30,31,33) THEN T1.OBS WHEN G.TipDoc = 35 THEN NC.OBS ELSE I.OBS END OBS,
    1 ORDINE,&apos;||sCursRef||gUserAlias||&apos;
  FROM STINGERE S
    INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
    LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.CODDOC
    LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28
    LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29,30,31,33)
    LEFT JOIN TREZOR  T  ON T1.CODTREZOR = T.CODTREZOR
    LEFT JOIN NC ON NC.CODNC = G.CODDOC AND G.CODDOC = 35
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = G.MONEDA
    LEFT JOIN tmp_subunitdedicate ts ON ts.codsubunit = COALESCE(NC.SUBUNITATEA, T.SUBUNITATEA, C.SUBUNITATEA, I.SUBUNITATEA)
    LEFT JOIN nsubunit sub ON sub.codsubunit = COALESCE(NC.SUBUNITATEA, T.SUBUNITATEA, C.SUBUNITATEA, I.SUBUNITATEA)&apos;||
    gSuplJoins||&apos;
  WHERE s.codstinspif = :1&apos;;

  FOR vRec IN (
    SELECT O.Codobligpif
    FROM INTRARI I
      INNER JOIN GENERAL G ON G.CODDOC = I.CODINTR AND G.TIPDOC = I.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE I.PARTENER = PKG_LIST_SELURMDOCPART.CODPART
      AND I.NRDOC = PKG_LIST_SELURMDOCPART.NRDOC
      AND I.DATADOC = PKG_LIST_SELURMDOCPART.DATADOC
      AND O.SEMNIFICATIE IN (100,130) )
  LOOP
    EXECUTE IMMEDIATE sInsert||sSelect USING vRec.CodObligPif ;
  END LOOP;
  COMMIT;

END;

END PKG_LIST_BASE_URMPLATIDOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMREALDEZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FF438C3CE49C58F7680FBAB2586B8DBEA778F63</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_urmrealdez IS

  vAllGest   BOOLEAN;
  vAllArt    BOOLEAN;
  vDataStart VARCHAR2(20);
  vDataFin   VARCHAR2(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST (TMPNAME IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(9000);
  sWith      VARCHAR2(9000);
  sSelect    VARCHAR2(9000);
  sCondGest  VARCHAR2(1000);
  sCondProd  VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;INTRARI INTR, INTRARI1 INTR1, CMDPRODMAT MAT, NGEST G, NARTOBJ OBJMAT, NART ARTMAT, NUM UM, NARTOBJ OBJRET, NART ARTRET,  NUM UMRET&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  vAllGest   := pkg_list_selectgestart.AllGest;
  vAllArt    := pkg_list_selectgestart.AllArt;
  vDataStart := pkg_list_selectgestart.DataStart;
  vDataFin   := pkg_list_selectgestart.DataFin;

  sCondGest := &apos;&apos;;
  if not vAllGest then
    sCondGest := &apos;inner join tmp_manevra_liste tmp on g.codgest = to_number(tmp.valoare) and upper(tmp.filtru) = &apos;&apos;CODGEST&apos;&apos; &apos;;
  end if;

  sCondProd := &apos;&apos;;
  if not vAllArt then
    sCondProd := &apos;inner join tmp_manevra_liste tmp on g.codgest = to_number(tmp.valoare) and upper(tmp.filtru) = &apos;&apos;CODPRODCOMP&apos;&apos; &apos;;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;
        (Articol,
         UM,
         Pret,
         CantCom,
         CantReal,
         DifCant,
         ValCom,
         ValReal,
         DifVal,
         NrBon,
         DataBon,
         Sectie,
         Produs,
         UMProdus,
         CantComProd,
         ValProd,
         PretProd
         &apos;||gUserFields||&apos;) &apos;;

  sWith := &apos;with
             predari as (
             select
               mat.codcmdprodmat,
               i.codintr,
               i1.cant cant
             from cmdprodmat mat
                  inner join intrprodlink intrlink on mat.codcmdprodmat = intrlink.codliniecomanda
                  inner join intrari1 i1 on intrlink.codintr1 = i1.codintr1
             )
            &apos;;
  sSelect :=
  &apos;SELECT
         objmat.DENUMIRE,
         um.den_um,
         mat.pret,
         mat.cant,
         predari.cant,
         nvl(mat.cant, 0) - nvl(consumuri.cant, 0)),
         sum(round(nvl(mat.cant, 0) * nvl(mat.pret, 0), 2)),
         sum(round(nvl(consumuri.cant, 0) * nvl(mat.pret, 0), 2)),
         sum(round(mat.cant * mat.pret, 2) - round(consumuri.cant * mat.pret, 2)),
         BC.NrDoc,
         BC.DataDoc,
         NG.Den_gest,
         ObjRet.denumire,
         umret.den_um,
         realizari.cant,
         realizari.val,
         realizari.pret &apos;||gUserAlias||&apos;
  FROM intrari intr
    INNER JOIN intrari1 intr1 ON intr.codintr = intr11.codintr
    INNER JOIN intrprodlink intrlink ON c1.codcomanda = c.codcomanda
    LEFT  JOIN cmdprodmat mat ON c.carnetdoc = cdoc.codcarnet
    INNER JOIN ngest            g ON c.codgest = g.codgest
    INNER JOIN NARTOBJ     OBJmat ON mat.codobiect  = objmat.codobiect &apos;
    ||sCondgest|| &apos;
    INNER JOIN NART        ArtMat ON objmat.codarticol = artmat.codarticol
    INNER JOIN NUM             UM ON artmat.um = um.codum
    INNER JOIN NARTOBJ     ObjRet ON c1.codobiect  = objret.codobiect
    INNER JOIN NART        ArtRet ON objret.codarticol = artret.codarticol
    INNER JOIN NUM          UMret ON artret.um = umret.codum
    LEFT  JOIN realizari on mat.codcmdprodmat = realizari.codcmdprodmat
    LEFT  JOIN consumuri on mat.codcmdprodmat = consumuri.codcmdprodmat&apos;||
    gSuplJoins||&apos;
  where mat.tip = 1 and c.tipdoc = 53 and INTR.datadoc between to_date(&apos;&apos;&apos;||vDataStart||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) and to_date(&apos;&apos;&apos;||vDataFin||&apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
  if pkg_globals.GETSUBUNITATE &gt; 1 then
    sSelect := sSelect||&apos; and INTR.subunitatea = &apos;||pkg_globals.GETSUBUNITATE;
  end if;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_urmrealdez;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMSUPV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46A150648BA3FD0683027F586DDBF684E3ABA512</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMSUPV is

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert     CLOB;
  sInsertTMP  CLOB;
  sInsertTMP1 CLOB;
  sFiltruDATA VARCHAR2(2000);
  sFiltruCamp VARCHAR2(50);
  sFiltruRetCamp VARCHAR2(50);
BEGIN
  gSuplCols := &apos;NPERS P, PASS_MODIF PM&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic &apos;||gUserFields||&apos;)
  SELECT
    I.CODIES NAV_CodDoc, 
    I.TIPDOC NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    I.PREFIXDOC TipDoc,
    I.NrDoc,
    I.DataDoc,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN IESIRI I ON I.CODIES = PM.CODMASTER
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;IESIRI&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic &apos;||gUserFields||&apos;)
  SELECT
    C.CODCOMANDA NAV_CodDoc, 
    C.TIPDOC NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    C.PREFIXDOC TipDoc,
    C.NrDoc,
    C.DataDoc,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN COMANDA C ON C.CODCOMANDA = PM.CODMASTER
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;COMANDA&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic &apos;||gUserFields||&apos;)
  SELECT
    O.CODOFERTA NAV_CodDoc, 
    O.TIPDOC NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    &apos;&apos;OFERTA&apos;&apos; TipDoc,
    O.NrDoc,
    O.DataOferta,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN OFERTA O ON O.CODOFERTA = PM.CODMASTER
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;OFERTA&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic,
    Fact &apos;||gUserFields||&apos;)
  SELECT
    E.CODEMULARE NAV_CodDoc, 
    -1 NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    &apos;&apos;BON CASA&apos;&apos; TipDoc,
    E.NRBON NrDoc,
    E.DATABON DataDoc,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic,
    I.PREFIXDOC||TO_CHAR(I.NRDOC)||&apos;&apos;/&apos;&apos;||TO_CHAR(I.DATADOC,&apos;&apos;DD.MM.YYYY&apos;&apos;) Fact
     &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS 
    LEFT JOIN EMULARE E ON E.CODEMULARE = PM.CODMASTER
    LEFT JOIN IESIRI I ON E.CODIES = I.CODIES &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;EMULARE&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic,
    Obs &apos;||gUserFields||&apos;)
  SELECT
    NP.CODPERS NAV_CodDoc, 
    502 NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    &apos;&apos;PERSOANA&apos;&apos; TipDoc,
    NULL NrDoc,
    NULL DataDoc,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic,
    NP.NUME||&apos;&apos; &apos;&apos;||NP.PRENUME &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN NPERS NP ON NP.CODPERS = PM.CODMASTER
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;NPERS&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos;(
    NAV_CodDoc, 
    NAV_TipDoc,
    Persoana,
    CampModif,
    TipDoc,
    NrDoc,
    DataDoc,
    Tabela,
    OldVal,
    NewVal,
    Explic,
    Obs &apos;||gUserFields||&apos;)
  SELECT
    PC.CODPRODCOMP NAV_CodDoc, 
    504 NAV_TipDoc,
    P.NUME||&apos;&apos; &apos;&apos;||P.PRENUME Persoana,
    PM.FIELDNAME CampModif,
    &apos;&apos;RETETA&apos;&apos; TipDoc,
    PC.CODPRODCOMP NrDoc,
    NULL DataDoc,
    PM.TABLENAME Tabela,
    PM.OLDVALUE OldVal,
    PM.NEWVALUE NewVal,
    PM.Explic,
    PC.OBS &apos;||gUserAlias||&apos;
  FROM PASS_MODIF PM
    INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = PM.CODMASTER
    INNER JOIN NPERS P ON PM.PERSMODIF = P.CODPERS &apos;||
    gSuplJoins||&apos;
  WHERE PM.TABLENAME = &apos;&apos;PRODCOMP&apos;&apos; AND 
        PM.DataModif between to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;) 
                         and to_date(&apos;&apos;&apos;||to_char(PKG_LIST_SELECTEMULARE.getDataFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy hh24:mi:ss&apos;&apos;)&apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  sInsert:= &apos;
  INSERT INTO &apos;|| tmpName ||&apos; (NAV_CODDOC,NAV_TIPDOC,PERSOANA,CAMPMODIF,TIPDOC,NRDOC,DATADOC,TABELA,OLDVAL,NEWVAL,EXPLIC,OBS,POSTR,FACT) 
  select TMP.NAV_CODDOC,TMP.NAV_TIPDOC,TMP.PERSOANA,TMP.CAMPMODIF,TMP.TIPDOC,TMP.NRDOC,TMP.DATADOC,TMP.TABELA,TMP.OLDVAL,TMP.NEWVAL,TMP.EXPLIC,TMP.OBS,TMP.POSTR,TMP.FACT 
  from TMP_LIST_URMSUPV TMP
       LEFT JOIN PASS_MODIF PM ON PM.PERSMODIF = TMP.NAV_CODDOC - TMP.NAV_CODDOC - 1
       LEFT JOIN NPERS P ON P.CODPERS = TMP.NAV_CODDOC - TMP.NAV_CODDOC - 1 &apos;;
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_URMSUPV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_URMVIRINTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13F565BD5140708F55E7268081BDE52754FFE1B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_URMVIRINTERNE IS

  v_LunaStart NUMBER;
  v_LunaStop  NUMBER;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE setParams IS
BEGIN
  v_LunaStart := PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaStart;
  v_LunaStop  := PKG_GLOBALS.ANLUCRU * 12 + PKG_LIST_SELECTLUNA.LunaFin;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert        VARCHAR2(1000);
  sSelect        VARCHAR2(20000);
  sCursRef       VARCHAR2(100);
  aSitV          NUMBER(1);
  aBancaV        NUMBER(20);
  aMonedaV       NUMBER(20);
BEGIN
  --pkg_globals.SetDebugMode(TRUE);
  gSuplCols := &apos;TREZOR1 T1, TREZOR T, NBANKCONT NBC, NBANK NB, NMONEDE MON, NSUBUNIT SUB, TREZOR1 T1_B, TREZOR T_B, NBANKCONT NBC_B, NBANK NB_B, NMONEDE MON_B, NSUBUNIT SUB_B, NCONT CVIR &apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  SetParams;
  IF pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCursRef := &apos;,
    PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, t1.datadoc )&apos;;
  ELSE
    sCursRef := &apos;,
    1&apos;;
  END IF;

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc,NAV_CodDoc1,NAV_TipDoc,
    SimbOp, DenOp, DenContOp, NrContOp,
    TipTranz,
    Document, TipDoc, NrDoc, Data,
    Moneda, Curs, Valoare, Subunitatea,
    Luna,
    Rest,
    SimbBenef, DenBenef, NrContBenef, DenContBenef,
    B_Document, B_TipDoc, B_NrDoc, B_Data,
    B_Moneda, B_Curs, B_Valoare, B_Subunitatea,
    B_Luna,
    CONTVIR,
    CURS_REF &apos;||gUserFields||&apos;)&apos;;

	sSelect :=&apos;
  SELECT
    DECODE(T1.INITIALIZARI,1,NULL,T.CODTREZOR), DECODE(T1.INITIALIZARI,1,NULL,T1.CODTREZOR1), DECODE(T1.INITIALIZARI,1,NULL,G.TIPDOC),
    NB.SIMBOL, NB.DENUMIRE, NBC.DEN_CONT, NBC.NRCONT,
    DECODE(O.SEMNIFICATIE,800,&apos;&apos;PLATA&apos;&apos;,&apos;&apos;INCASARE&apos;&apos;) TIPTRANZ,
    T1.DOC||T1.NRDOC||&apos;&apos;/&apos;&apos;||T1.DATADOC Doc, T1.DOC TipDoc, T1.NRDOC, T1.DATADOC,
    MON.SIMBOL MONEDA, DECODE(T1.CURS,NULL,1,0,1,T1.CURS) CURS, T1.VALDOC, SUB.DEN_SUBUNIT,
    to_char(T1.An,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(T1.LUNA,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(T1.LUNA),
    (O.VALOARE - CASE WHEN T1_B.CODTREZOR1 IS NULL THEN 0 ELSE S.VALOARE END) * DECODE(O.SEMNIFICATIE,801,1,-1) REST,
    NB_B.SIMBOL, NB_B.DENUMIRE, NBC_B.NRCONT, NBC_B.DEN_CONT,
    DECODE(T1_B.CODTREZOR1,NULL,NULL,T1_B.DOC||T1_B.NRDOC||&apos;&apos;/&apos;&apos;||T1_B.DATADOC) Doc, T1_B.DOC TipDoc, T1_B.NRDOC, T1_B.DATADOC,
    MON_B.SIMBOL MONEDA, DECODE(T1_B.CURS,NULL,1,0,1,T1_B.CURS) CURS, T1_B.VALDOC, SUB_B.DEN_SUBUNIT,
    DECODE(T1_B.CODTREZOR1,NULL,NULL,to_char(T1_B.An,&apos;&apos;fm0000&apos;&apos;)||&apos;&apos;.&apos;&apos;||to_char(T1_B.LUNA,&apos;&apos;fm00&apos;&apos;)||&apos;&apos;.&apos;&apos;||pkg_list_base_utils.decode_luna(T1_B.LUNA)),
    CVIR.SIMBOL&apos;||
    sCursRef||gUserAlias||&apos;
  FROM OBLIGPIF O
    INNER JOIN GENERAL G ON O.CODGENERAL = G.CODGENERAL AND G.TIPDOC IN (29,30)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
    INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    LEFT JOIN NBANKCONT NBC ON NBC.CODBANKCONT = T.CODBANCA
    LEFT JOIN NBANK NB ON NB.CODBANK = NBC.CODBANK
    LEFT JOIN NMONEDE MON ON MON.CODMONEDA = NBC.CODMONEDA
    LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = T.SUBUNITATEA
    LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
    LEFT JOIN OBLIGPIF O_B ON O_B.CODOBLIGPIF = S.CODSTINGATORPIF
    LEFT JOIN GENERAL G_B ON G_B.CODGENERAL = O_B.CODGENERAL
    LEFT JOIN TREZOR1 T1_B ON T1_B.CODTREZOR1 = G_B.CODDOC AND G_B.TIPDOC IN (29,30) AND (T1_B.AN * 12 + T1_B.LUNA) &lt;= &apos;||V_LUNASTOP||&apos;
    LEFT JOIN TREZOR T_B ON T_B.CODTREZOR = T1_B.CODTREZOR
    LEFT JOIN NBANKCONT NBC_B ON NBC_B.CODBANKCONT = T1.CODPART
    LEFT JOIN NBANK NB_B ON NB_B.CODBANK = NBC_B.CODBANK
    LEFT JOIN NMONEDE MON_B ON MON_B.CODMONEDA = NBC_B.CODMONEDA
    LEFT JOIN NSUBUNIT SUB_B ON SUB_B.CODSUBUNIT = T_B.SUBUNITATEA
    LEFT JOIN NCONT CVIR ON CVIR.CODCONT = CASE WHEN O.ICONT &lt; 10000 THEN To_Number(pkg_categconst.GetValConstanta(&apos;&apos;CViramenteInterne&apos;&apos;,T1.AN,T1.LUNA)) ELSE O.ICONT END&apos;||
    gSuplJoins||&apos;
  WHERE O.SEMNIFICATIE IN (800,801)
    AND O.CONTBANKTRANZACTIE IS NOT NULL &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;T&apos;)||&apos;
    AND (T1.AN * 12 + T1.LUNA) &gt;= &apos;||v_LunaStart||&apos; AND (T1.AN * 12 + T1.LUNA) &lt;= &apos;||v_LunaStop||&apos;
    AND ((O.VALOARE - NVL(S.VALOARE,0)) &lt;&gt; 0 OR (T1.AN * 12 + T1.LUNA) &gt;= &apos;||v_LunaStart||&apos; OR NVL(T1_B.AN * 12 + T1_B.LUNA,0) &gt;= &apos;||v_LunaStart||&apos;)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  COMMIT;
END;

PROCEDURE SetJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_UrmVirInterne;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB54521637920670342D70B38DCDA816E1F5A290</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_utilaje IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert  varchar2(5000);
  sWhere   varchar2(1200) := &apos;&apos;;
BEGIN
  gSuplCols := &apos;NIRSTOC NS, NIR NIR, NARTOBJ NOBJ, NGEST NG, NPART NP, NARTAMB AA, NAGENDA NAG, NLOCALIT LAG, NJUDET JAG, TMP_UTILIZATOR UTILIZATOR,&apos;||
               &apos;UTILAJE U, UTILAJE1 U1&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sWhere := &apos;
  WHERE U.CODUTILAJ IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODUTILAJ&apos;&apos;)&apos;;
  IF pkg_list_selutilaje.IsAllUtilaje THEN
    sWhere := &apos;&apos;;
  END IF;
  sWhere := sWhere||&apos;
   AND CASE 
         WHEN U.TIP IS NULL AND U.CODPART &gt; 0 THEN 2 
         ELSE       
           CASE 
             WHEN (SELECT COUNT(*) FROM UTILAJE1 WHERE CODUTILAJ = U.CODUTILAJ) &gt; 0 AND U.TIP IS NULL THEN 1
             ELSE NVL(U.TIP,0)
           END
       END = 1 &apos;;

  sInsert :=
  &apos;INSERT INTO &apos;||tmpName||&apos; (
    DENUMIRE,NRINVENTAR,ETICHETA,TIPUTILAJ,FLOTA,NRCONTR,CARNETCONTR,DATA,
    STATUS_DEPO,
    ACTIV,
    STATUS_SERVICE,
    OBS, Sed_Adr, Sed_Loc, Sed_Jud,
    Operator, DEN_PART,DEN_GEST,OBS_UTILAJ,INDEXLOCAL,
    MAXIM, STARE_ESTETICA &apos;||gUserFields||&apos;)
  SELECT
    NOBJ.DENUMIRE, U.NRINVENTAR,U.ETICHETA,U.TIPUTILAJ,U.FLOTA, U1.NRCONTR,U1.CARNETCONTR,TO_DATE(U1.DATA,&apos;&apos;DD.MM.YYYY&apos;&apos;),
    DECODE(U1.STATUS_DEPO,1,&apos;&apos;plasat la partener&apos;&apos;,2,&apos;&apos;Plasabil&apos;&apos;,3,&apos;&apos;Defect/Reparatii&apos;&apos;,4,&apos;&apos;Casabil&apos;&apos;,5,&apos;&apos;Donatie&apos;&apos;,6,&apos;&apos;Plasat la partener pt vanzare&apos;&apos;,7,&apos;&apos;Plasat la partener pt depozitare&apos;&apos;) STATUS_DEPO,
    DECODE(U1.STATUS_PART,1,&apos;&apos;...&apos;&apos;,2,&apos;&apos;Da&apos;&apos;,3,&apos;&apos;Nu&apos;&apos;) Activ,
    DECODE(U1.STATUS_SERVICE,1,&apos;&apos;Initial&apos;&apos;,2,&apos;&apos;Revizie anuala&apos;&apos;,3,&apos;&apos;Incident&apos;&apos;,&apos;&apos;...&apos;&apos;) STATUS_SERVICE,
    NAG.OBS, GETADRESA(NAG.SECTOR, NAG.STRADA, NAG.NR1, NAG.NR2, NAG.BLOC, NAG.SCARA, NAG.ETAJ, NAG.APART, NAG.CODPOSTAL), LAG.DEN_LOCALIT, JAG.DEN_JUDET,
    UTILIZATOR.Nume, NP.DEN_PART,NG.DEN_GEST,U1.OBS OBS_UTILAJ, u1.indexlocal,
    max(u1.indexlocal) over (partition by u1.codutilaj) maxim,
    DECODE(U1.ESTETIC,1,&apos;&apos;Ok&apos;&apos;,2,&apos;&apos;De colantat integral&apos;&apos;,3,&apos;&apos;De colantat fata&apos;&apos;,4,&apos;&apos;De colantat spate&apos;&apos;,5,&apos;&apos;De colantat laterale&apos;&apos;) &apos;||gUserAlias||&apos;
  FROM UTILAJE U
    INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT
    INNER JOIN UTILAJE1 U1 ON U1.CODUTILAJ = U.CODUTILAJ
    LEFT JOIN MIFIX M ON M.NRINVENTAR = U.NRINVENTAR AND M.TIP = &apos;&apos;MF&apos;&apos;
    LEFT JOIN (SELECT DISTINCT CODMIFIX,CODNIRSTOC FROM MIFIX1 ) M1 ON M1.CODMIFIX = M.CODMIFIX
    LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
    LEFT JOIN NIR NIR ON NIR.CODNIR = NS.CODNIR
    LEFT JOIN NGEST NG ON NG.CODGEST = NIR.GEST
    LEFT JOIN NPART NP ON NP.CODPART = U1.CODPART
    LEFT JOIN NAGENDA NAG ON NAG.CODAGENDA = U1.CODLOCATIE
    LEFT JOIN NLOCALIT LAG ON LAG.CODLOCALIT = NAG.CODLOCALIT
    LEFT JOIN NJUDET JAG ON JAG.CODJUDET = LAG.CODJUDET
    LEFT JOIN NARTAMB AA ON AA.CODOBIECT = U.CODOBIECT AND AA.UMSEC = NS.UMSEC
	  LEFT JOIN TMP_UTILIZATOR UTILIZATOR ON UTILIZATOR.CODUTILIZATOR = U1.USERID&apos;||
    gSuplJoins||
  sWhere;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_utilaje; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_UTILS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01A11BEB642FA9E25D702B7CA552E85EA2010C67</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_UTILS IS

  -- variabile folosite IN SET_UMA
  vCodObjUMA    NUMBER;
  vDUMA1        VARCHAR2(50);
  vDUMA2        VARCHAR2(50);
  vDUMA3        VARCHAR2(50);
  vPUMA1        NUMBER;
  vPUMA2        NUMBER;
  vPUMA3        NUMBER;
  vPUMAC        NUMBER;
  vPUMAP        NUMBER;

  -- variabile folosite in iCont_CodCont
  oldIdx_IOPART1  NUMBER;
  oldDen_IOPART1  VARCHAR2(50);
  oldCod_IOPART1  NUMBER(20);
  oldCodP_IOPART1 NUMBER(20);
  oldCodC_IOPART1 NUMBER(20);
  oldAL_IOPART1   NUMBER( 5);

  oldIdx_IOPERS1  NUMBER;
  oldDen_IOPERS1  VARCHAR2(50);
  oldCod_IOPERS1  NUMBER(20);
  oldCodP_IOPERS1 NUMBER(20);
  oldCodC_IOPERS1 NUMBER(20);
  oldAL_IOPERS1   NUMBER( 5);

  -- variabile folosite in SetDateDoc
  vSDD_TipDoc   NUMBER(20);
  vSDD_CodDoc   NUMBER(20);
  vSDD_ObsDoc   VARCHAR2(500);
  vSDD_DenDoc   VARCHAR2(500);
  vSDD_UserDoc  NUMBER(20);
  vSDD_PartDoc  NUMBER(20);
  vSDD_TablaDoc VARCHAR2(50);
  vSDD_ValDoc   NUMBER(20);

  --variabile folosite in getTipTVA0
  vTT0_Res           NUMBER(1);
  vTT0_CodObiect     NUMBER(20);
  vTT0_AL            NUMBER(5);
  vTT0_CntJVARTNEIMP NUMBER;
  vTT0_TVA0FaraDed   VARCHAR2(100);

  vListSimbLipsa VARCHAR2(4000);

  vAnLunaBCPUV NUMBER;
  vDenBCPUV    VARCHAR2(100);

  vAnLunaMFIV  NUMBER;
  vCodMFIV     VARCHAR2(4000);
  vSimbMFIV    VARCHAR2(4000);

  -- variabile folosite IN MATCH_TVA
  vAnLunaTVA   NUMBER ;
  vPj1TVA      NUMBER;
  vPj2TVA      NUMBER;
  vPj3TVA      NUMBER;
  vPj4TVA      NUMBER;
  vPj5TVA      NUMBER;
  vPj6TVA      NUMBER;
  vPj7TVA      NUMBER;
  vPj8TVA      NUMBER;
  vPj1TIP      NUMBER;
  vPj2TIP      NUMBER;
  vPj3TIP      NUMBER;
  vPj4TIP      NUMBER;
  vPj5TIP      NUMBER;
  vPj6TIP      NUMBER;
  vPj7TIP      NUMBER;
  vPj8TIP      NUMBER;
  vAnLunaMin   INTEGER;

  -- variabile folosite IN GetCoefDiscMonetar
  vCDMCodIes      NUMBER;
  vCDMNr          NUMBER;
  vCDMAn          NUMBER;
  vCDMLuna        NUMBER;
  vCDMCoteDisc    NUMBER;
  vCDMValDoc      NUMBER;
  vCDMTvaDoc      NUMBER;
  vCDMValDisc     NUMBER;
  vCDMTvaDisc     NUMBER;
  vCDMValLin      NUMBER;
  vCDMTvaLin      NUMBER;

  vCDMCIntermedCM NUMBER;
  vCDMConIncFact  NUMBER;

  vCDMProc1       NUMBER;
  vCDMProc2       NUMBER;
  vCDMProc3       NUMBER;
  vCDMProc4       NUMBER;
  vCDMProc5       NUMBER;
  vCDMProc6       NUMBER;
  vCDMProc7       NUMBER;
  vCDMProc8       NUMBER;
  vCDMValDisc1    NUMBER;
  vCDMValDisc2    NUMBER;
  vCDMValDisc3    NUMBER;
  vCDMValDisc4    NUMBER;
  vCDMValDisc5    NUMBER;
  vCDMValDisc6    NUMBER;
  vCDMValDisc7    NUMBER;
  vCDMValDisc8    NUMBER;
  vCDMTvaDisc1    NUMBER;
  vCDMTvaDisc2    NUMBER;
  vCDMTvaDisc3    NUMBER;
  vCDMTvaDisc4    NUMBER;
  vCDMTvaDisc5    NUMBER;
  vCDMTvaDisc6    NUMBER;
  vCDMTvaDisc7    NUMBER;
  vCDMTvaDisc8    NUMBER;
  vCDMValLin1     NUMBER;
  vCDMValLin2     NUMBER;
  vCDMValLin3     NUMBER;
  vCDMValLin4     NUMBER;
  vCDMValLin5     NUMBER;
  vCDMValLin6     NUMBER;
  vCDMValLin7     NUMBER;
  vCDMValLin8     NUMBER;
  vCDMTvaLin1     NUMBER;
  vCDMTvaLin2     NUMBER;
  vCDMTvaLin3     NUMBER;
  vCDMTvaLin4     NUMBER;
  vCDMTvaLin5     NUMBER;
  vCDMTvaLin6     NUMBER;
  vCDMTvaLin7     NUMBER;
  vCDMTvaLin8     NUMBER;

  sCDMArtExcl     VARCHAR2(4000);

function GetValFractie(aFractie IN varchar2) return number is
aSQL varchar2(500);
aDouble number;
BEGIN
  aSQL := &apos;SELECT &apos;||afractie||&apos; FROM dual&apos;;
  BEGIN
    execute immediate aSQL INTO aDouble;
  EXCEPTION WHEN OTHERS THEN aDouble := 1;
  END;
  Return round(aDouble,7);
END;

procedure DropJ130 is
BEGIN
	for v_rec IN (SELECT TABLE_NAME FROM user_tables WHERE TABLE_NAME like &apos;J130_%&apos;) loop
		Execute immediate &apos;Drop table &apos;||v_rec.TABLE_NAME;
	END loop;
END;

FUNCTION GetPartComCli(aCodLinieComanda IN NUMBER) RETURN VARCHAR2 IS
aPart VARCHAR2(200);
BEGIN
  BEGIN
    SELECT
      p.den_part INTO aPart
    FROM cmdlink l
         INNER JOIN comanda1 c1 ON l.codliniecomanda = c1.codcomanda1
         INNER JOIN comanda c ON c1.codcomanda = c.codcomanda
         left  JOIN npart p ON c.partener = p.codpart
    WHERE c.tipdoc = 18
    START WITH l.codcomanda1 = aCodLinieComanda
    CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1;
  EXCEPTION WHEN others THEN
    aPart := null;
  END;
  return aPart;
END;

FUNCTION GetGestCom(aCodLinieComanda IN NUMBER) RETURN VARCHAR2 IS
aPart VARCHAR2(200);
BEGIN
  BEGIN
    SELECT
      g.den_gest INTO aPart
    FROM cmdlink l
         INNER JOIN comanda1 c1 ON l.codliniecomanda = c1.codcomanda1
         INNER JOIN comanda c ON c1.codcomanda = c.codcomanda
         left  JOIN ngest g ON c.codgest = g.codgest
    WHERE c.tipdoc = 43
    START WITH l.codcomanda1 = aCodLinieComanda
    CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1;
  EXCEPTION WHEN others THEN
    aPart := null;
  END;
  return aPart;
END;

function GetDocComCli(aCodLinieComanda IN NUMBER) RETURN VARCHAR2 IS
aDoc VARCHAR2(50);
BEGIN
  BEGIN
    SELECT
      to_char(C.NrDoc)||&apos;/&apos;||to_char(C.DataDoc, &apos;DD.MM.YYYY&apos;) INTO aDoc
    FROM cmdlink l
         INNER JOIN comanda1 c1 ON l.codliniecomanda = c1.codcomanda1
         INNER JOIN comanda c ON c1.codcomanda = c.codcomanda
    WHERE c.tipdoc = 18
    START WITH l.codcomanda1 = aCodLinieComanda
    CONNECT BY PRIOR l.CODliniecomanda = l.CODcomanda1;
  EXCEPTION WHEN others THEN
    aDoc := null;
  END;
  return aDoc;
END;

Function GetPMPObiect(aCodObiect IN number ,
                      aSubunitate IN number default 0,
                      aAn IN number default 0 ,
                      aLuna IN number default 0
                      ) return number  IS
iResult number (20,7);
iValConstanta number(1);
BEGIN

 if aAn = 0 THEN
   iValConstanta := pkg_categconst.GetValConstanta(&apos;TipPMP&apos;, pkg_globals.ANLUCRU , pkg_globals.LUNALUCRU);
 ELSE
   iValConstanta := pkg_categconst.GetValConstanta(&apos;TipPMP&apos;, aAn , aLuna);
 END if;

 if iValConstanta = 1 THEN -- la nivel de firma
  if aAn &lt;&gt; 0 THEN
       SELECT sum(valintr)/sum(cantIntr) INTO IResult FROM
      (
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                  p.valintr
                END  valIntr,
                CASE WHEN p.cantintr = 0 THEN
                  1
                ELSE
                  p.CantIntr
                END  CantIntr
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = aAn        and
                p.luna      = aLuna
      ) ;
     ELSE
          SELECT sum(valintr)/sum(cantIntr) INTO IResult FROM
      (
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                  p.valintr
                END  valIntr,
                CASE WHEN p.cantintr = 0 THEN
                  1
                ELSE
                  p.CantIntr
                END  CantIntr
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = pkg_globals.ANLUCRU        and
                p.luna      = pkg_globals.LUNALUCRU
      );
     END if;
  ELSE
     if aAn &lt;&gt; 0 THEN
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                   p.valintr/ p.cantintr
                END  INTO iResult
                FROM pmpluna p
          WHERE p.codobiect  = aCodObiect and
                p.an         = aAn        and
                p.luna       = aLuna      and
                p.codsubunit = aSubunitate  ;
     ELSE
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                   p.valintr/ p.cantintr
                END  INTO iResult
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = pkg_globals.ANLUCRU        and
                p.luna      = pkg_globals.LUNALUCRU      and
                p.codsubunit = aSubunitate;

     END if;
  END if;

return iResult;

END;


Function GetPMPObiectValuta(aCodObiect IN number ,
                            aSubunitate IN number default 0,
                            aAn IN number default 0 ,
                            aLuna IN number default 0
                      ) return number  IS
iResult number (20,7);
iValConstanta number(1);
BEGIN

 if aAn = 0 THEN
   iValConstanta := pkg_categconst.GetValConstanta(&apos;TipPMP&apos;, pkg_globals.ANLUCRU , pkg_globals.LUNALUCRU);
 ELSE
   iValConstanta := pkg_categconst.GetValConstanta(&apos;TipPMP&apos;, aAn , aLuna);
 END if;

 if iValConstanta = 1 THEN -- la nivel de firma
  if aAn &lt;&gt; 0 THEN
       SELECT sum(valvaluta)/sum(cantIntr) INTO IResult FROM
      (
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                  p.valValuta
                END  valValuta,
                CASE WHEN p.cantintr = 0 THEN
                  1
                ELSE
                  p.CantIntr
                END  CantIntr
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = aAn        and
                p.luna      = aLuna
      ) ;
     ELSE
          SELECT sum(valValuta)/sum(cantIntr) INTO IResult FROM
      (
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                  p.valValuta
                END  valValuta,
                CASE WHEN p.cantintr = 0 THEN
                  1
                ELSE
                  p.CantIntr
                END  CantIntr
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = pkg_globals.ANLUCRU        and
                p.luna      = pkg_globals.LUNALUCRU
      );
     END if;
  ELSE
     if aAn &lt;&gt; 0 THEN
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                   p.valValuta/ p.cantintr
                END  INTO iResult
                FROM pmpluna p
          WHERE p.codobiect  = aCodObiect and
                p.an         = aAn        and
                p.luna       = aLuna      and
                p.codsubunit = aSubunitate  ;
     ELSE
         SELECT CASE WHEN p.cantintr = 0 THEN
                  0
                ELSE
                   p.valValuta/ p.cantintr
                END  INTO iResult
                FROM pmpluna p
          WHERE p.codobiect = aCodObiect and
                p.an        = pkg_globals.ANLUCRU        and
                p.luna      = pkg_globals.LUNALUCRU      and
                p.codsubunit = aSubunitate;
     END if;
  END if;
return iResult;

END;

procedure CalculeazaPmpListe is

 BEGIN
  for v_rec IN(
    SELECT
      CASE
        WHEN TRUNC((luna + nr)/12)*12 &lt;&gt; (luna + nr) THEN an + TRUNC((luna + nr)/12)
        ELSE an + TRUNC((nr)/12)
      END an,
      CASE
        WHEN TRUNC((luna + nr)/12)*12 = (luna + nr) THEN 12
        ELSE luna + nr - TRUNC((luna + nr)/12)*12
      END luna
        FROM
         ( SELECT ancurent an ,lunacurenta luna ,(level-1) nr FROM
          firmaluni f
           connect by level &lt;= (f.anmaxim*12+f.lunamaxima) - (f.ancurent * 12 + f.lunacurenta) + 1
         )
    ) loop

     pkg_globals.SetLunaTemp(v_rec.an,v_rec.luna);
       MAKE_PMP_LUNA_LISTE;
    END loop;
 END;

PROCEDURE MAKE_PMP_LUNA_LISTE
IS
 aCANTINTR    NUMBER(20, 7);
 aCANT        NUMBER(20, 7);
 aVALINTR     NUMBER(20, 7);
 aValValuta   NUMBER(20, 7);
 CANTINTRPREC NUMBER(20, 7) := 0;
 VALINTRPREC  NUMBER(20, 7) := 0;
 NR           NUMBER(20) := 0;
 VALVALUTAPREC NUMBER(20,7) :=0;
 anPrecTemp   number(4);
 lunaPrecTemp number(2);
BEGIN
 /* Analiza e asa:
      - le sterg pe alea de luna asta
      - le preiau pe alea de luna trecuta care nu au miscari IN luna asta ( vezi NOT EXISTS din filtru)
      - apoi analiza pe cele de luna asta
 */
  DELETE FROM PMPLUNA WHERE AN = PKG_GLOBALS.ANTEMP AND LUNA = PKG_GLOBALS.LUNATEMP AND PKG_LIST_BASE_UTILS.EsteObiectValid(codobiect) = 1;
    INSERT INTO PMPLUNA(CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA,VALVALUTA)
    SELECT SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, PKG_GLOBALS.ANTEMP, PKG_GLOBALS.LUNATEMP,VALVALUTA
    FROM
      PMPLUNA p
    WHERE
        (AN  * 12 + Luna ) = (PKG_GLOBALS.ANTEMP * 12 + PKG_GLOBALS.LUNATEMP) -1
    and (not exists (SELECT codobiect FROM v_list_pmp_luna v WHERE p.codobiect = v.CODOBIECT)
         or not exists (SELECT codsubunit FROM v_list_pmp_luna v WHERE p.codsubunit = v.CODSUBUNIT)
        )
    and PKG_LIST_BASE_UTILS.EsteObiectValid(codobiect) = 1 ;
    FOR V_REC IN
    (
      SELECT * FROM V_LIST_PMP_LUNA
    )
    LOOP
      BEGIN
        SELECT Coalesce(CANTINTR,0),  Coalesce(VALINTR, 0) , Coalesce(VALVALUTA,0)INTO CANTINTRPREC, VALINTRPREC, VALVALUTAPREC
        FROM
          PMPLUNA
        WHERE
          AN * 12 + LUNA =   ( PKG_GLOBALS.ANTEMP * 12 + PKG_GLOBALS.LUNATEMP ) -1
          AND CODOBIECT  = V_REC.CODOBIECT
          AND CODSUBUNIT = V_REC.CODSUBUNIT;
        EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0;VALVALUTAPREC := 0;
      END;


      aCANT      := V_REC.CANTINTR + CANTINTRPREC;
      aCANTINTR  := V_REC.RESTLUNA + CANTINTRPREC;
      IF aCANT &lt;&gt; 0 THEN
        aVALINTR   := ((V_REC.VALINTR    + VALINTRPREC) / aCANT)*aCantIntr ;
        aVALValuta := ((V_REC.VALVALUTA  + VALVALUTAPREC) / aCANT)*aCantIntr ;
      ELSE
        aVALINTR      := 0;
        aValValuta    := 0;
      END IF;

      INSERT INTO PMPLUNA
      (
       CODPMPLUNA,
       CODOBIECT,
       CODSUBUNIT,
       CANTINTR,
       VALINTR,
       REST,
       AN,
       LUNA,
       VALVALUTA)
     VALUES
     ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL,
       V_REC.CODOBIECT,
       V_REC.CODSUBUNIT,
       aCANTINTR,
       aVALINTR,
       V_REC.RESTLUNA,
       PKG_GLOBALS.ANTEMP,
       PKG_GLOBALS.LUNATEMP,
       aValValuta
     );
    END LOOP;
 --insert INTO x(sql) values (pkg_globals.ANPRECEDENT||&apos; - &apos;||pkg_globals.LUNAPRECEDENTA);
 COMMIT;
END;


function EsteObiectValid (aCodObiect IN number) return number is
 iResult number(1) := 0;
 cnt number(20);
 BEGIN
   SELECT count(*) INTO cnt FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos;;
    if cnt = 0 THEN
     return 1 ;
    ELSE
      SELECT count(*) INTO cnt FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos; and valoare = aCodObiect;
       if cnt = 0 THEN
         return 0;
       ELSE
         return 1;
       END if;
    END if;
 END;



PROCEDURE BAGA_SERII_IN_TMP(pCant NUMBER  DEFAULT CT_CANT) IS
BEGIN
  DELETE FROM tmp_manevra_serii;

  pkg_globals.SetSeparator(&apos;| &apos;);

  IF pCant = CT_CODNIRSER THEN
    INSERT INTO tmp_manevra_serii (codnirstoc,flag,serii, TG)
    SELECT s.codnirser,pCant,
      CASE
        WHEN s.tipserie = 1 THEN string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.serie)
		  END serie,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.TG)
		  END TG
    FROM (
      SELECT NSER.codnirser,
        row_number() over (PARTITION BY ns.codnirstoc ORDER BY s.serie) nrcrt,
        COUNT(ns.codnirstoc) over (PARTITION BY ns.codnirstoc) total_ns,
	      CASE
				  WHEN tipserie = 1 THEN s.serie
				  WHEN tipserie = 2 THEN s.serie||&apos; ( &apos;||nser.cantnir||&apos; ) &apos;
				  ELSE &apos;&apos;
			  END serie,
			  ns.tipserie, nser.cantnir, to_char(Coalesce(nser.TG, ns.tg)) TG
    FROM nirser nser
      INNER JOIN nserii s ON s.codserie = nser.codserie
      INNER JOIN nirstoc ns ON ns.codnirstoc = nser.codnirstoc
      INNER JOIN livr1 l1 ON l1.codnirser = nser.codnirser
	  WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
	  ORDER BY nser.codnirser, ns.tipserie
    )	s
  WHERE s.nrcrt &lt; = 10
  GROUP BY s.codnirser, s.tipserie ,s.total_ns;

  END IF;

  IF pCant = CT_MODIFPRET THEN
    -- stef am modificat partea asta sa baga serii, serii si termene de garantie
    -- si chiar si termene de garantie cu toate ca aceasta tabla pare dedicata seriilor
    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag,codlivr1,codaux1, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_MODIFPRET,
          S.GEST, S.CODIOART, NULL TG--, string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1, N.GEST, NS.CODIOART,
            CASE MAX(NS.TIPSERIE)
              WHEN 1 THEN S.SERIE
              WHEN 2 THEN S.SERIE||&apos; ( &apos;||SUM(L1.CANT)||&apos; ) &apos;
              ELSE &apos;&apos;
            END SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1, N.GEST, NS.CODIOART) total_ns --, to_char(Coalesce(NSER.TG, NS.TG)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
  	  WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, N.GEST, NS.CODIOART, S.SERIE--, Coalesce(nser.tg, NS.TG)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1, S.GEST, S.CODIOART, s.total_ns;

    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag,codlivr1,codaux1, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_MODIFPRET + 1000,
          S.GEST, S.CODIOART, NULL TG--, string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1, N.GEST, NS.CODIOART,
            CASE MAX(NS.TIPSERIE)
              WHEN 1 THEN S.SERIE
              WHEN 2 THEN S.SERIE||&apos; ( &apos;||SUM(L1.CANT)||&apos; )&apos;
              ELSE &apos;&apos;
            END || DECODE(Coalesce(NSER.TG, NS.TG),NULL,&apos;&apos;,&apos; - &apos; ||Coalesce(NSER.TG, NS.TG)) SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE, Coalesce(NSER.TG, NS.TG)) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1, N.GEST, NS.CODIOART) total_ns--, to_char(Coalesce(nser.TG, ns.tg)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
  	  WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, N.GEST, NS.CODIOART, S.SERIE, Coalesce(nser.TG, ns.tg)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1, S.GEST, S.CODIOART, s.total_ns;

    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag,codlivr1,codaux1, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_MODIFPRET + 2000,
          S.GEST, S.CODIOART, NULL TG--, string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1, N.GEST, NS.CODIOART, TO_CHAR(Coalesce(NSER.TG, NS.TG)) SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE, Coalesce(NSER.TG, NS.TG)) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1, N.GEST, NS.CODIOART) total_ns --,to_char(Coalesce(NSER.TG, NS.TG)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
  	  WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, N.GEST, NS.CODIOART, S.SERIE, Coalesce(NSER.TG, NS.TG)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1, S.GEST, S.CODIOART, s.total_ns;
  END IF;

  IF pCant = CT_TRANSF THEN
    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_TRANSF,
      NULL TG--string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1,
            CASE MAX(NS.TIPSERIE)
              WHEN 1 THEN S.SERIE
              WHEN 2 THEN S.SERIE||&apos; ( &apos;||SUM(L1.CANT)||&apos; ) &apos;
              ELSE &apos;&apos;
            END SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1) total_ns--, to_char(Coalesce(NSER.TG, NS.TG)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
      WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, S.SERIE, Coalesce(nser.tg, NS.TG)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1 ,s.total_ns;

    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_TRANSF + 1000,
      NULL TG--string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1,
            CASE MAX(NS.TIPSERIE)
              WHEN 1 THEN S.SERIE
              WHEN 2 THEN S.SERIE||&apos; ( &apos;||SUM(L1.CANT)||&apos; )&apos;
              ELSE &apos;&apos;
            END || DECODE(Coalesce(nser.tg, NS.TG),NULL,&apos;&apos;,&apos; - &apos; ||Coalesce(nser.tg, NS.TG)) SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE, Coalesce(nser.tg, NS.TG)) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1) total_ns--, to_char(Coalesce(nser.tg, NS.TG)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
      WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, S.SERIE, Coalesce(nser.tg, NS.TG)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1 ,s.total_ns;

    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag, TG)
    SELECT S.CODTRANSF1, string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END serie, CT_TRANSF + 2000,
      NULL TG--string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END TG
    FROM (
      SELECT L1.CODIES1 CODTRANSF1, TO_CHAR(Coalesce(NSER.TG, NS.TG)) SERIE,
            ROW_NUMBER() OVER (PARTITION BY L1.CODIES1 ORDER BY S.SERIE, Coalesce(NSER.TG, NS.TG)) NrCrt,
            COUNT(1) over (PARTITION BY L1.CODIES1) total_ns--,to_char(Coalesce(NSER.TG, NS.TG)) TG
      FROM LIVR1 L1
        INNER JOIN NIRSER NSER ON L1.CODNIRSER = NSER.CODNIRSER
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NSERII S ON S.CODSERIE = NSER.CODSERIE
      WHERE l1.codlivr1 IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODLIVR1&apos;)
      GROUP BY L1.CODIES1, S.SERIE, Coalesce(NSER.TG, NS.TG)
    ) S
    WHERE s.nrcrt &lt; = 10
    GROUP BY S.CODTRANSF1 ,s.total_ns;
  END IF;

  IF pCant = CT_CANT THEN
    INSERT INTO tmp_manevra_serii (codnirstoc,flag,serii,serii_ies,tg,nrcertif,dataprod,serii_aux1,serii_aux2, serii_obs)
    SELECT s.codnirstoc,pCant,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.serie)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.serie)
	    END serie,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.sernocant)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.sernocant)
	    END sernocant,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.TG)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.TG)
	    END tg,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.nrcertif)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.nrcertif)
	    END nrcertif,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.dataprod)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.dataprod)
	    END dataprod,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.divizor)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.divizor)
	    END divizor,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.bucati)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.bucati)
	    END bucati,
      CASE
			  WHEN s.tipserie = 1 THEN string_agg(s.obs)|| CASE WHEN s.total_ns &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN s.tipserie = 2 THEN string_agg(s.obs)
	    END obs
    FROM (
      SELECT
        ns.codnirstoc, ns.tipserie,
        ROW_NUMBER() over (PARTITION BY ns.codnirstoc ORDER BY s.serie) nrcrt,
        COUNT(ns.codnirstoc) over (PARTITION BY ns.codnirstoc) total_ns,
	      s.serie||CASE WHEN tipserie = 2 THEN &apos; ( &apos;||nser.cantnir||&apos; ) &apos; END serie , s.serie sernocant,
			  to_char(Coalesce(NSER.TG, NS.TG)) TG, c.nrcertif, nser.dataprod, nser.divizor, nser.bucati, nser.obs
      FROM nirstoc ns
        INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
	      INNER JOIN nserii s ON s.codserie = nser.codserie
        LEFT JOIN certif c ON c.codcertif = nser.codcertif
  	  WHERE ns.codnirstoc IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODNIRSTOC&apos;)
	    ORDER BY ns.codnirstoc, ns.tipserie
	  )	s
    WHERE s.nrcrt &lt; = 10
    GROUP BY s.codnirstoc, s.tipserie ,s.total_ns;
  END IF;

  IF pCant = CT_STOC_M THEN
    INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag, TG)
    SELECT
      codnirstoc,
      CASE
			  WHEN tipserie = 1 THEN string_agg(serie) || CASE WHEN Max(total_ns) &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN tipserie = 2 THEN string_agg(serie )
		  END serie, CT_STOC_M,
      CASE
			  WHEN tipserie = 1 THEN string_agg(TG) || CASE WHEN Max(total_ns) &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
			  WHEN tipserie = 2 THEN string_agg(TG )
		  END TG
    FROM (
      SELECT codnirstoc, Decode(tipserie,1,serie,2,serie||&apos; ( &apos;||rest||&apos; ) &apos;,&apos;&apos;) serie,
        row_number() over (PARTITION BY codnirstoc ORDER BY serie) nrcrt,
        COUNT(codnirstoc) over (PARTITION BY codnirstoc) total_ns,
		    tipserie, rest, to_char(TG) TG
      FROM TMP_MANEVRA_NIRSER
      WHERE rest &gt; 0
	    ORDER BY codnirstoc, tipserie, serie)
    WHERE nrcrt &lt; = 10
    GROUP BY codnirstoc	,tipserie, rest;
  END IF;

  IF pCant = CT_REST THEN
  INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag, TG)
    SELECT s.codnirstoc,
        CASE
			    WHEN s.tipserie = 1 THEN
			      string_agg(s.serie) || CASE
					                          WHEN s.rest &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
				  WHEN s.tipserie = 2 THEN
				    string_agg(s.serie )
			  END serie,CT_REST,
        CASE
			    WHEN s.tipserie = 1 THEN
			      string_agg(s.TG) || CASE
					                          WHEN s.rest &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
				  WHEN s.tipserie = 2 THEN
				    string_agg(s.TG )
			  END TG
    FROM (
    SELECT ns.codnirstoc,
				  CASE
				    WHEN tipserie = 1 THEN s.serie
					  WHEN tipserie = 2 THEN s.serie||&apos; ( &apos;||nser.cantnir||&apos; ) &apos;
					  ELSE &apos;&apos;
				  END serie
				  , row_number() over (PARTITION BY ns.codnirstoc ORDER BY s.serie) nrcrt,
        COUNT(ns.codnirstoc) over (PARTITION BY ns.codnirstoc) total_ns,
			  ns.tipserie,ns.rest, to_char(Coalesce(NSER.TG, NS.TG)) TG
    FROM nirstoc ns
      INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
	    INNER JOIN nserii s ON s.codserie = nser.codserie
	  WHERE ns.codnirstoc IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODNIRSTOC&apos;)
	  AND ns.rest &gt; 0
	  ORDER BY  ns.codnirstoc	,ns.tipserie,s.serie
	  )	s
  WHERE s.nrcrt &lt; = 10
  GROUP BY s.codnirstoc	,s.tipserie,s.rest;
  END IF;

  IF pCant = CT_LIVR THEN
  INSERT INTO tmp_manevra_serii (codnirstoc,serii,flag,Codlivr1, TG)
    SELECT s.codnirstoc,
        CASE
			    WHEN s.tipserie = 1 THEN
			      string_agg(s.serie) || CASE
					                          WHEN s.cant &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
				  WHEN s.tipserie = 2 THEN
				    string_agg(s.serie )
			  END serie,CT_LIVR,CODLIVR1,
        CASE
			    WHEN s.tipserie = 1 THEN
			      string_agg(s.TG) || CASE
					                          WHEN s.cant &gt; 10 THEN &apos;...&apos; ELSE &apos;&apos; END
				  WHEN s.tipserie = 2 THEN
				    string_agg(s.TG )
			  END TG
    FROM (
    SELECT ns.codnirstoc,
				  CASE
				    WHEN tipserie = 1 THEN s.serie
					  WHEN tipserie = 2 THEN s.serie||&apos; ( &apos;||nser.cantnir||&apos; ) &apos;
					  ELSE &apos;&apos;
				  END serie
				  , row_number() over (PARTITION BY ns.codnirstoc ORDER BY s.serie) nrcrt,
        COUNT(ns.codnirstoc) over (PARTITION BY ns.codnirstoc) total_ns,
			  ns.tipserie,livr1.cant,LIVR1.CODLIVR1,
        to_char(Coalesce(NSER.TG, NS.TG)) TG
    FROM nirstoc ns
      INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
      INNER JOIN nserii s ON s.codserie = nser.codserie
      INNER JOIN livr1 ON ns.codnirstoc = livr1.codnirstoc
	  WHERE ns.codnirstoc IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODNIRSTOC&apos;)
	  ORDER BY  ns.codnirstoc	,ns.tipserie,s.serie
	  )	s
  WHERE s.nrcrt &lt; = 10
  GROUP BY s.codnirstoc	,s.tipserie, s.cant,S.CODLIVR1;

  END IF;

  IF pCant = CT_TOATE THEN
    INSERT INTO tmp_manevra_serii (codnirstoc, serii, serii_aux1, tg, serii_obs, nrcertif)
    SELECT codnirstoc,
      vc2_nt_to_vc3200(CAST(COLLECT(serie||Decode(cant,1,&apos;&apos;,&apos;(&apos;||cant||&apos;)&apos;) ORDER BY SERIE) AS vc2_nt)) serii,
      vc2_nt_to_vc3200(CAST(COLLECT(serie ORDER BY SERIE) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(COLLECT(tg ORDER BY SERIE) AS vc2_nt)) tg,
      vc2_nt_to_vc3200(CAST(COLLECT(obs ORDER BY SERIE) AS vc2_nt)) obs,
      vc2_nt_to_vc3200(CAST(COLLECT(nrcertif ORDER BY SERIE) AS vc2_nt)) nrcertif
    FROM (
      SELECT ns.codnirstoc, Max(ns.tipserie) tipserie, s.serie, Sum(nser.cantnir) cant, TO_CHAR(Coalesce(nser.tg, ns.tg),&apos;dd.mm.yyyy&apos;) tg, nser.obs,c.nrcertif
      FROM nirstoc ns
        INNER JOIN nirser nser ON ns.codnirstoc = nser.codnirstoc
	      INNER JOIN nserii s ON s.codserie = nser.codserie
        LEFT JOIN certif c ON c.codcertif = nser.codcertif
  	  WHERE ns.codnirstoc IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODNIRSTOC&apos;)
	    GROUP BY ns.codnirstoc, s.serie, Coalesce(nser.tg, ns.tg), nser.obs, c.nrcertif )
    GROUP BY codnirstoc;

    INSERT INTO tmp_manevra_serii(codlivr1, serii_ies, serii_aux1, tg, serii_obs, nrcertif)
    SELECT codlivr1,
      vc2_nt_to_vc3200(CAST(COLLECT(serie||Decode(cant,1,&apos;&apos;,&apos;(&apos;||cant||&apos;)&apos;) ORDER BY SERIE) AS vc2_nt)) serii,
      vc2_nt_to_vc3200(CAST(COLLECT(serie ORDER BY SERIE) AS vc2_nt)) ser,
      vc2_nt_to_vc3200(CAST(COLLECT(tg ORDER BY SERIE) AS vc2_nt)) tg,
      vc2_nt_to_vc3200(CAST(COLLECT(obs ORDER BY SERIE) AS vc2_nt)) obs,
      vc2_nt_to_vc3200(CAST(COLLECT(nrcertif ORDER BY SERIE) AS vc2_nt)) nrcertif
    FROM (
      SELECT l1.codlivr1, Max(ns.tipserie) tipserie, s.serie, Sum(l1.cant) cant, TO_CHAR(Coalesce(nser.tg, ns.tg),&apos;dd.mm.yyyy&apos;) tg, nser.obs, c.nrcertif
      FROM nirstoc ns
        INNER JOIN livr1 l1 ON l1.codnirstoc = ns.codnirstoc
        INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
	      INNER JOIN nserii s ON s.codserie = nser.codserie
			  INNER JOIN nartobj nobj ON nobj.codobiect = ns.codobiect
			  INNER JOIN nart n ON n.codarticol = nobj.codarticol
        LEFT JOIN certif c ON c.codcertif = l1.codcertif
  	  WHERE ns.codnirstoc IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODNIRSTOC&apos;)
      GROUP BY l1.codlivr1, s.serie, Coalesce(nser.tg, ns.tg), nser.obs, c.nrcertif )
    GROUP BY codlivr1;
  END IF;

  COMMIT;
  pkg_globals.SetSeparator(&apos;,&apos;);
END;


FUNCTION GetCursReferinta (aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA VARCHAR2) RETURN NUMBER IS
 aCURS NUMBER(20,7) := 0;
BEGIN
  aCurs := 0;
  FOR v_rec IN (
    SELECT Coalesce(VALOARE, 1) Curs
    FROM NMONEDE  N INNER JOIN NMONEDE1 N1 ON N.CODMONEDA = N1.CODMONEDA
    WHERE N1.CODBANCA = aCODBANCA
      AND N.CODMONEDA = aCODMONEDA
      AND N1.DATA &lt;= TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;)
    ORDER BY N1.DATA DESC
  ) LOOP
    aCurs := v_rec.curs;
    EXIT;
  END LOOP;
  aCurs := Coalesce(NULLIF(aCurs,0), 1);
  RETURN aCURS;
END;

/*FUNCTION GetCursReferinta (aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA DATE) RETURN NUMBER IS
BEGIN
  RETURN GetCursReferinta (aCODMONEDA, aCODBANCA, to_char(aDATA, &apos;dd.mm.yyyy&apos;));
END;
*/

FUNCTION GetInfoSitValuta(pSitValuta OUT NUMBER,pBancaValuta OUT NUMBER, pMonedaValuta OUT NUMBER)  RETURN BOOLEAN IS
bResult BOOLEAN := FALSE;
BEGIN

 pSitValuta    := pkg_categconst.GetValConstanta(&apos;SitValuta&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
 pBancaValuta  := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;
 pMonedaValuta := pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;,pkg_globals.ANLUCRU,pkg_globals.lunalucru) ;

 bResult := (pSitValuta = 1) AND (Coalesce(pBancaValuta,0) &gt; 0) AND (Coalesce(pMonedaValuta,0) &gt; 0)	 ;
 RETURN bResult;
END;

PROCEDURE GetSeriiIntrare IS
  NrSeriiRand NUMBER(20);
  idx1 NUMBER(20);
  idx2 NUMBER(20);
  cnt NUMBER(20);
  aCodNirStoc NUMBER(20) := 0 ;
  s VARCHAR2(10) := &apos; &apos;;
BEGIN
  DELETE FROM tmp_manevra_serii;
  COMMIT;

  NrSeriiRand := 10;

  PKG_GLOBALS.SetSeparator(&apos;;&apos;);

  idx1:=0;
  idx2:=NrSeriiRand;



  FOR V_REC IN (
    SELECT DISTINCT NS.CODNIRSTOC
    FROM nirstoc ns
      INNER JOIN nirser nser  ON nser.codnirstoc = ns.codnirstoc
	  	INNER JOIN nserii n ON n.codserie = nser.codserie
    WHERE ns.codnir IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODNIR&apos;)
  ) LOOP
	  SELECT COUNT(*) INTO cnt
    FROM  nirstoc ns INNER JOIN nirser nser  ON nser.codnirstoc = ns.codnirstoc
	  	                INNER JOIN nserii n ON n.codserie = nser.codserie
    WHERE  ns.codnirstoc = v_rec.codnirstoc;

	  IF cnt &gt; 10 THEN
	    cnt := 10;
		  s:=&apos;...&apos;;
	  ELSE
	    s:=&apos;&apos;;
	  END IF;

	  IF aCodNirstoc &lt;&gt;  v_rec.codnirstoc THEN
      idx1 := 0;
	    idx2:=NrSeriiRand;
    END IF;

    BEGIN

	    INSERT INTO tmp_manevra_serii(codnirstoc,serii,FLAG)
	    SELECT CODnirstoc,SERIE||s,idx1
      FROM (
	      SELECT codnirstoc,string_agg(serie) SERIE
        FROM (
          SELECT t1.*, ROWNUM rn
          FROM (
            SELECT ns.codnirstoc , n.serie serie
            FROM  nirstoc ns
              INNER JOIN nirser nser  ON nser.codnirstoc = ns.codnirstoc
	  	        INNER JOIN nserii n ON n.codserie = nser.codserie
            WHERE ns.codnir IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODNIR&apos;)
              AND ns.codnirstoc = v_rec.codnirstoc
						ORDER BY codnirstoc,n.serie
          ) t1
        )
        WHERE rn BETWEEN idx1 AND idx2 GROUP BY codnirstoc
      );
    EXCEPTION
      WHEN VALUE_ERROR THEN Raise_Application_Error(-20001,&apos; Prea multe serii pe rand !  Modificati constanta &apos;||chr(13)||&apos; Listare numar de serii pe un rand &apos;||chr(13) );
      WHEN OTHERS      THEN NULL;
    END;
    aCodnirStoc := v_rec.codnirstoc;
  END LOOP; -- de la FOR

  COMMIT;
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);
END;

PROCEDURE set_filtre (p_filtru IN VARCHAR2,p_val IN VARCHAR2) IS
--v_filtru VARCHAR2(300);
v_val VARCHAR2(500);
tmp VARCHAR2(50);
i NUMBER(10);
BEGIN

 tmp:= p_val;

  IF (length(tmp) &gt; 0 ) THEN
   		tmp := tmp ||&apos;,&apos;;
	END IF;

	i := instr(tmp,&apos;,&apos;);

	WHILE (i &gt; 0) AND (length(tmp) &gt; 1) LOOP

		v_val := substr(tmp,1,i-1);
		tmp := substr(tmp,i+1,length(tmp));
		i := instr(tmp,&apos;,&apos;);

		INSERT INTO tmp_manevra_liste(filtru,valoare) VALUES(p_filtru,v_val);

	END LOOP;
 COMMIT;

END;

FUNCTION decode_luna (pLuna NUMBER) RETURN VARCHAR2 IS
sResult VARCHAR2(25);
BEGIN
  sResult := CASE pLuna
	                WHEN 1  THEN &apos;Ianuarie&apos;
									WHEN 2  THEN &apos;Februarie&apos;
									WHEN 3  THEN &apos;Martie&apos;
									WHEN 4  THEN &apos;Aprilie&apos;
									WHEN 5  THEN &apos;Mai&apos;
									WHEN 6  THEN &apos;Iunie&apos;
									WHEN 7  THEN &apos;Iulie&apos;
									WHEN 8  THEN &apos;August&apos;
									WHEN 9  THEN &apos;Septembrie&apos;
									WHEN 10 THEN &apos;Octombrie&apos;
									WHEN 11 THEN &apos;Noiembrie&apos;
									WHEN 12 THEN &apos;Decembrie&apos;
               END;
	RETURN sResult;
END;

FUNCTION LunaScurta (pLuna NUMBER) RETURN VARCHAR2 IS
sResult VARCHAR2(25);
BEGIN
  sResult := SubStr(decode_luna(pLuna),1,3);
	RETURN sResult;
END;

FUNCTION decode_luna (pData DATE)   RETURN VARCHAR2 IS
sResult VARCHAR2(25);
BEGIN
  sResult := to_char(pData, &apos;Month&apos;, &apos;NLS_DATE_LANGUAGE = romanian&apos;);
	RETURN sResult;
END;

FUNCTION LunaScurta (pData DATE)   RETURN VARCHAR2 IS
sResult VARCHAR2(25);
BEGIN
  sResult := SubStr(decode_luna(pData),1,3);
	RETURN sResult;
END;

FUNCTION decode_zi   (pData DATE)   RETURN VARCHAR2 IS
  sResult VARCHAR2(25);
  engDay  VARCHAR2(25);
BEGIN
  engDay  := Trim(TO_CHAR(pData,&apos;DAY&apos;, &apos;NLS_DATE_LANGUAGE=english&apos;));
  sResult :=  CASE engDay
                WHEN &apos;MONDAY&apos;    THEN &apos;Luni&apos;
                WHEN &apos;TUESDAY&apos;   THEN &apos;Marti&apos;
                WHEN &apos;WEDNESDAY&apos; THEN &apos;Miercuri&apos;
                WHEN &apos;THURSDAY&apos;  THEN &apos;Joi&apos;
                WHEN &apos;FRIDAY&apos;    THEN &apos;Vineri&apos;
                WHEN &apos;SATURDAY&apos;  THEN &apos;Sambata&apos;
                WHEN &apos;SUNDAY&apos;    THEN &apos;Duminica&apos;
              END ;
	RETURN sResult;
END;

FUNCTION decode_tipdoc (vTip IN NUMBER) RETURN VARCHAR2 IS
sResult VARCHAR2(100);
BEGIN
  BEGIN
   SELECT NUMEEXT INTO sResult FROM tmp_machete WHERE vTip = CodMacheta;
	EXCEPTION WHEN others THEN
   sResult := &apos;-&apos;;
  END;
  RETURN sResult;

END;

FUNCTION  decode_tipdoc_scurt(pTipDoc Number) return Varchar2 IS
   sResult Varchar2(20);
  BEGIN
   BEGIN
     SELECT NUMEPRESC INTO sResult FROM tmp_machete WHERE pTipDoc = CodMacheta;
   EXCEPTION WHEN others THEN
     sResult := &apos;-&apos;;
   END;

    return sResult;
  END;

FUNCTION  decode_inchideri(pTipInchidere Number) return Varchar2 IS
    vNume Varchar2(20);
  BEGIN
    vNume :=  CASE pTipInchidere
                WHEN  1  THEN &apos;Corectie adaos marfa&apos;
                WHEN  2  THEN &apos;Participatiune&apos;
                WHEN  3  THEN &apos;Sincronizare conturi&apos;
                WHEN  4  THEN &apos;Inchid.rulaj curent debit&apos;
                WHEN  5  THEN &apos;Inchid.rulaj curent credit&apos;
                WHEN  6  THEN &apos;Inchidere sold&apos;
                ELSE &apos;Alte inchideri&apos;
              END;
    return vNume;
  END;

FUNCTION GET_CONT_IOPART (idx_col IN number,codpart IN number,SEMNIF IN NUMBER)RETURN VARCHAR2 IS
 DEN_COL VARCHAR2(50);
 --SSQL VARCHAR (1000);
 SIMBOL VARCHAR2(10);

 BEGIN
 make_config_luna_iopart;
 IF Coalesce(IDX_COL,-1)&lt;&gt;-1 THEN
   BEGIN
      IF SEMNIF IN (900,901) THEN
        SELECT ncont.simbol INTO simbol FROM ncont WHERE codcont = idx_col;
      ELSE
          SELECT COLUMN_NAME INTO DEN_COL
          FROM USER_TAB_COLUMNS WHERE COLUMN_ID=IDX_COL+1 AND TABLE_NAME=&apos;IOPART1&apos;;

          BEGIN
				    EXECUTE IMMEDIATE &apos;SELECT SIMBOL FROM NCONT WHERE CODCONT IN &apos;||
				         &apos;( SELECT &apos;||DEN_COL||&apos; FROM tmp_iopart_luna WHERE CODPART= &apos;||codpart||&apos;) &apos; INTO SIMBOL;

          END;
     END IF;
		EXCEPTION WHEN OTHERS THEN simbol := &apos;nedefinit&apos;;
		END;
    RETURN SIMBOL;
 ELSE
    RETURN &apos;nedef.&apos;;
 END if;

END;

FUNCTION GET_DENCONT_IOPART (idx_col IN number,codpart IN number,SEMNIF IN NUMBER)RETURN VARCHAR2 IS
 DEN_COL VARCHAR2(50);
 --SSQL VARCHAR (1000);
 SIMBOL VARCHAR2(10);

 BEGIN
 make_config_luna_iopart;
 IF Coalesce(IDX_COL,-1)&lt;&gt;-1 THEN
   BEGIN
      IF SEMNIF IN (900,901) THEN
        SELECT ncont.den_cont INTO simbol FROM ncont WHERE codcont = idx_col;
      ELSE
          SELECT COLUMN_NAME INTO DEN_COL
          FROM USER_TAB_COLUMNS WHERE COLUMN_ID=IDX_COL+1 AND TABLE_NAME=&apos;IOPART1&apos;;

          BEGIN
				    EXECUTE IMMEDIATE &apos;SELECT DEN_CONT FROM NCONT WHERE CODCONT IN &apos;||
				         &apos;( SELECT &apos;||DEN_COL||&apos; FROM tmp_iopart_luna WHERE CODPART= &apos;||codpart||&apos;) &apos; INTO SIMBOL;

          END;
     END IF;
		EXCEPTION WHEN OTHERS THEN simbol := &apos;nedefinit&apos;;
		END;
    RETURN SIMBOL;
 ELSE
    RETURN &apos;nedefinit&apos;;
 END if;

END;

FUNCTION GET_DEN_BANCA(aCodBank IN number)RETURN VARCHAR2 IS
Den_Bank varchar2(50);
BEGIN
  BEGIN
  SELECT denumire INTO Den_Bank FROM nbank WHERE codbank = aCodBank;
  EXCEPTION WHEN OTHERS THEN Den_Bank := &apos;&apos;;
  END;
  return den_bank;
END;

FUNCTION GET_CONT_IOPers (idx_col IN number,codpart IN number,SEMNIF IN NUMBER)RETURN VARCHAR2 IS
 DEN_COL VARCHAR2(50);
 --SSQL VARCHAR (1000);
 SIMBOL VARCHAR2(10);
 BEGIN
 IF Coalesce(IDX_COL,-1)&lt;&gt;-1 THEN
   BEGIN
      IF SEMNIF IN (900,901) THEN
        SELECT ncont.simbol INTO simbol FROM ncont WHERE codcont = idx_col;
      ELSE
          SELECT COLUMN_NAME INTO DEN_COL
          FROM USER_TAB_COLUMNS WHERE COLUMN_ID=IDX_COL+1 AND TABLE_NAME=&apos;IOPERS1&apos;;

          BEGIN
				    EXECUTE IMMEDIATE &apos;SELECT SIMBOL FROM NCONT WHERE CODCONT IN &apos;||
				         &apos;( SELECT &apos;||DEN_COL||&apos; FROM tmp_iopers_luna WHERE CODPERS= &apos;||codpart||&apos;) &apos; INTO SIMBOL;

          END;
     END IF;
		EXCEPTION WHEN OTHERS THEN simbol := &apos;nedefinit&apos;;
		END;
    RETURN SIMBOL;
 ELSE
    RETURN &apos;nedef.&apos;;
 END if;

END;

FUNCTION GETSIMBOLCONT (vCODCONT NUMBER) RETURN VARCHAR2 IS
 vSIMBOL VARCHAR2 (30);
BEGIN
   BEGIN
   SELECT Coalesce(SIMBOL,&apos;nedef.&apos;) INTO vSIMBOL FROM
          NCONT WHERE CODCONT=vCODCONT;
   EXCEPTION WHEN no_data_found THEN
     vSimbol := &apos;nedef.&apos;;
             WHEN others THEN
     vSimbol := &apos;nedef.&apos;;
   END;
   RETURN vSIMBOL;
END;

FUNCTION GET_GEST(v_CODGEST IN NUMBER) RETURN VARCHAR2 IS
    v_gest VARCHAR2(100);
	 BEGIN
	    SELECT Coalesce(den_gest,&apos;nedef.&apos;) INTO v_gest FROM ngest WHERE codgest = v_codgest;
			RETURN v_gest;
	 END;

FUNCTION get_umsec  (v_codum IN NUMBER ) RETURN VARCHAR2  IS
  v_den VARCHAR2(100);
	BEGIN
	  SELECT Coalesce(den_um1,&apos;nedef.&apos;) INTO v_den FROM num1 WHERE v_codum = codum1;
		RETURN v_den;
	END;

FUNCTION get_cont_ioart(v_icont IN NUMBER,v_codioart IN NUMBER, v_an IN NUMBER, v_luna IN NUMBER ) RETURN VARCHAR2 IS
  simbol  VARCHAR2(10);
  den_col VARCHAR2(30);
  vAL     VARCHAR2(5) := To_Char(V_AN*12+V_LUNA, &apos;fm99990&apos;);
BEGIN
  IF Coalesce(v_icont,-1) &gt; -1 THEN
	  SELECT COLUMN_NAME INTO DEN_COL
    FROM USER_TAB_COLUMNS
    WHERE COLUMN_ID=V_ICONT+1 AND TABLE_NAME=&apos;IOART1&apos;;

		EXECUTE IMMEDIATE &apos;SELECT SIMBOL FROM NCONT WHERE CODCONT IN (SELECT &apos;||DEN_COL||&apos; FROM IOART1 I1 WHERE I1.CODIOART = &apos;||v_codioart||&apos; AND &apos;||vAL||&apos; BETWEEN I1.ALSTART AND I1.ALSTOP) &apos;
    INTO SIMBOL;

		RETURN SIMBOL;
	ELSE
	  RETURN &apos;nedef.&apos;;
	END IF;
END;

FUNCTION get_cota_tva_art (v_codobiect IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN NUMBER IS
  v_cota NUMBER;
  vAL    NUMBER := v_an*12+v_luna;
BEGIN
  BEGIN
    SELECT ntva1.procent INTO v_cota
	  FROM nartobj nobj
      INNER JOIN nart1 n1 ON nobj.codarticol = n1.codarticol AND vAL BETWEEN N1.ALSTART AND N1.ALSTOP
	    LEFT JOIN ntva ON n1.codtva = ntva.codtva
			LEFT JOIN ntva1 ON ntva.codtva = ntva1.codtva          AND vAL BETWEEN ntva1.ALSTART AND ntva1.ALSTOP
    WHERE nobj.codobiect = v_codobiect;
	EXCEPTION WHEN OTHERS THEN v_cota := 0;
	END;
	RETURN v_cota;
END;

FUNCTION get_codconts (v_codcont IN NUMBER, v_an IN NUMBER, v_luna IN NUMBER) RETURN NUMBER IS
  v_cod NUMBER(20);
BEGIN
  BEGIN
    SELECT Coalesce(c1.contsecundar,0) INTO v_cod
	  FROM ncont1 c1
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_cod := 0;
	END;
	RETURN v_cod;
END;

FUNCTION get_simbol_sec (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2 IS
  v_simb varchar2(30);
BEGIN
  BEGIN
    SELECT cs.simbol INTO v_simb
	  FROM ncont1 c1 LEFT JOIN nconts cs ON c1.contsecundar = cs.codconts
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_simb := &apos;&apos;;
	END;
	RETURN v_simb;
END;

FUNCTION get_name_sec (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2 IS
  v_name varchar2(50);
BEGIN
  BEGIN
    SELECT cs.name INTO v_name
	  FROM ncont1 c1 LEFT JOIN nconts cs ON c1.contsecundar = cs.codconts
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_name := &apos;&apos;;
	END;
	RETURN v_name;
END;


FUNCTION get_codcontt (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN NUMBER IS
  v_cod NUMBER(20);
BEGIN
  BEGIN
    SELECT Coalesce(c1.conttertiar,0) INTO v_cod
	  FROM ncont1 c1
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_cod := 0;
	END;
	RETURN v_cod;
END;

FUNCTION get_simbol_ter (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2 IS
  v_simb varchar2(30);
BEGIN
  BEGIN
    SELECT ct.simbol INTO v_simb
	  FROM ncont1 c1 LEFT JOIN ncontt ct ON c1.conttertiar = ct.codcontt
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_simb := &apos;&apos;;
	END;
	RETURN v_simb;
END;

FUNCTION get_name_ter (v_codcont IN NUMBER ,v_an IN NUMBER, v_luna IN NUMBER) RETURN varchar2 IS
  v_name varchar2(50);
BEGIN
  BEGIN
    SELECT ct.name INTO v_name
	  FROM ncont1 c1 LEFT JOIN ncontt ct ON c1.conttertiar = ct.codcontt
    WHERE c1.codcont = v_codcont AND v_an*12+v_luna BETWEEN c1.ALSTART AND c1.ALSTOP;
	EXCEPTION
    WHEN OTHERS THEN v_name := &apos;&apos;;
	END;
	RETURN v_name;
END;

FUNCTION get_part (v_cod IN NUMBER) RETURN VARCHAR2 IS
v_den VARCHAR2(200);
BEGIN
  SELECT den_part INTO v_den FROM npart WHERE codpart = v_cod;
	RETURN v_den;
END;

FUNCTION get_tiparticol(v_codobiect IN NUMBER) RETURN NUMBER IS
v_tip NUMBER;
BEGIN
    SELECT tiparticol INTO v_tip FROM
		 nartobj LEFT JOIN nart ON nartobj.codarticol = nart.codarticol
		 WHERE nartobj.codobiect = v_codobiect;
		RETURN v_tip;
END;

FUNCTION GET_DEN_TAXA (pCodTaxa IN NUMBER) RETURN VARCHAR2 IS
  vDenTaxa VARCHAR2(30);
BEGIN
  BEGIN
    SELECT Den_Taxa INTO vDenTaxa FROM NTAXE WHERE CODTAXA = pCodTaxa;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN vDenTaxa;
END;

FUNCTION get_denioart (v_codioart IN NUMBER) RETURN VARCHAR2 IS
  sResult VARCHAR2(100);
BEGIN
  SELECT den_ioart INTO sResult
  FROM v_ioart_luna WHERE codioart = v_codioart;
  RETURN sResult;
END;

FUNCTION COND_SUBUNIT(pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;, pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;, pSUBUNIT IN NUMBER DEFAULT NULL) RETURN VARCHAR2 IS
  sResult  VARCHAR2(1000);
  vSubunit NUMBER(20)      := Coalesce(pSubunit,PKG_GLOBALS.GETSUBUNITATE);
BEGIN
  IF pTABLA IS NULL
  THEN sResult := pPrefix||&apos; &apos;||pCOLOANA;
  ELSE sResult := pPrefix||&apos; &apos;||pTABLA||&apos;.&apos;||pCOLOANA;
  END IF;

  IF vSubunit = 0 THEN
    sResult := NULL;
  ELSIF vSubunit &lt;&gt; 1 THEN
    sResult := sResult ||&apos; = &apos;||vSubunit||&apos; &apos;;
  ELSIF Coalesce(pkg_categconst.GetValConstanta(&apos;CumulatFirmaToateSub&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
    sResult := sResult ||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate)&apos;;
  ELSE
    sResult := NULL;
  END IF;

  IF sResult IS NULL AND (Upper(pPREFIX) LIKE &apos;%WHERE%&apos; OR Upper(pPREFIX) LIKE &apos;%OR%&apos;)
  THEN sResult := pPrefix||&apos; 1=1&apos;;
  END IF;

  RETURN sResult;
END;

FUNCTION COND_SUBUNITINCLACTIV(pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;, pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;, pSUBUNIT IN NUMBER DEFAULT NULL) RETURN VARCHAR2 IS
  sResult  VARCHAR2(1000);
  vSubunit NUMBER(20)      := Coalesce(pSubunit,PKG_GLOBALS.GETSUBUNITATE);
BEGIN
  IF pTABLA IS NULL
  THEN sResult := pPrefix||&apos; (&apos;||pCOLOANA;
  ELSE sResult := pPrefix||&apos; (&apos;||pTABLA||&apos;.&apos;||pCOLOANA;
  END IF;

  IF vSubunit = 0 THEN
    sResult := NULL;
  ELSIF vSubunit &lt;&gt; 1 THEN
    sResult := sResult ||&apos; = &apos;||vSubunit||&apos; OR C.ACTIV = 3&apos;;
  ELSIF Coalesce(pkg_categconst.GetValConstanta(&apos;CumulatFirmaToateSub&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
    sResult := sResult ||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate)&apos;;
  ELSE
    sResult := NULL;
  END IF;

  IF sResult IS NULL AND (Upper(pPREFIX) LIKE &apos;%WHERE%&apos; OR Upper(pPREFIX) LIKE &apos;%OR%&apos;)
  THEN sResult := pPrefix||&apos; 1=1&apos;;
  ELSE IF NOT sResult IS NULL THEN sResult := sResult||&apos;)&apos;;
  END IF;
  END IF;

  RETURN sResult;
END;

FUNCTION COND_USERID (pTABLA IN VARCHAR2 DEFAULT NULL, pCOLOANA IN VARCHAR2 DEFAULT &apos;USERID&apos;, pPREFIX  IN VARCHAR2 DEFAULT &apos; AND&apos;) RETURN VARCHAR2 IS
  vFiltru BOOLEAN;
  sResult VARCHAR2(1000);
BEGIN
  vFiltru := Coalesce(PKG_GLOBALS.USERID,0)&gt;0;
  IF vFiltru THEN vFiltru := Coalesce(pkg_categconst.GetValConstanta(&apos;LstUserCurent&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),0) = 1; END IF;
  IF vFiltru THEN vFiltru := Coalesce(pkg_categconst.GetValConstanta(&apos;DocUserCurent&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),0) = 1; END IF;
  IF vFiltru THEN
    IF pTABLA IS NULL
    THEN sResult := pPrefix||&apos; &apos;||pCOLOANA;
    ELSE sResult := pPrefix||&apos; &apos;||pTABLA||&apos;.&apos;||pCOLOANA;
    END IF;
    sResult := sResult ||&apos; = &apos;||PKG_GLOBALS.USERID||&apos; &apos;;
  END IF;

  IF Upper(pPREFIX) LIKE &apos;%WHERE%&apos; AND sResult IS NULL
  THEN sResult := pPrefix||&apos; 1=1&apos;;
  END IF;

  RETURN sResult;
END;

PROCEDURE make_config_luna_iopart IS
PRAGMA AUTONOMOUS_TRANSACTION ;
  AnLunaLucru  NUMBER(20);
  aIOPART_FLG  NUMBER(1)  := 0;
  aUSER_ID     NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT Coalesce(USERID,  -1), Coalesce(aIOPART_FLG,0)
    INTO  aUSER_ID, aIOPART_FLG
    FROM  LUNA_RECORDS_FLAGS
    WHERE USERID = PKG_GLOBALS.USERID;
  EXCEPTION
    WHEN OTHERS THEN BEGIN
      aUSER_ID     := -1;
			aIOPART_FLG  := 0;
		END;
  END;

  IF aUSER_ID = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(USERID, NTVA_FLG, IOPART_FLG,IOPers_FLG ) VALUES (PKG_GLOBALS.USERID, 0, 0, 0);
  END IF;

  SELECT PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU INTO AnLunaLucru FROM dual;

  IF aIOPART_FLG = 0 THEN
    DELETE FROM tmp_iopart_luna;

    INSERT INTO tmp_iopart_luna(CODPART,CODPART1,DEN_PART,CODIOPART,CREDITCLIENT,VOLUMTRANZC,CREDITFURN,VOLUMTRANZF,CODIOPART1,DEN_IOPART,CONTFURNIZOR,CONTCLIENT,
                                CONTFURNAVANS,CONTCLIENTAVANS,CONTFURNAVIZ,CONTCLIENTAVIZ,CONTFURNMF,CONTCREDITD,CONTDEBITD,CONTLITIGII,CONTFURNAVS,CONTFURNAVIC,CONTFURNAVIN,
                                CONTTERTI,TVANEEXF,TVANEEXC,TVANEEXP,TVANEEXI,TIP)
     SELECT n.codpart, n1.codpart1, n.den_part, Coalesce(n1.codiopart,0)codiopart, n1.creditclient,n1.volumtranzc,n1.creditfurn,n1.volumtranzf,
            io1.codiopart1,io.den_iopart,io1.contfurnizor,io1.contclient,io1.contfurnavans,io1.contclientavans,
            io1.contfurnaviz,io1.contclientaviz,io1.contfurnmf,io1.contcreditd,io1.contdebitd,io1.contlitigii,io1.contfurnavs,
            io1.contfurnavic,io1.contfurnavin,io1.contterti,io1.tvaneexf,io1.tvaneexc,io1.TVANEEXP,io1.TVANEEXI, io1.tip
     FROM npart n
      LEFT JOIN npart1 n1 ON n.codpart = n1.codpart AND PKG_GLOBALS.ANLUNALUCRU BETWEEN n1.ALStart AND n1.ALStop
      LEFT JOIN iopart io ON Coalesce(n1.codiopart,0) = Coalesce(io.codiopart,0)
      LEFT JOIN iopart1 io1 ON io.codiopart = io1.codiopart AND PKG_GLOBALS.ANLUNALUCRU BETWEEN io1.ALStart AND io1.ALStop;

     UPDATE LUNA_RECORDS_FLAGS SET IOPART_FLG = 1 WHERE USERID = PKG_GLOBALS.USERID;
  END IF;
  COMMIT;
END;

PROCEDURE make_config_luna_ioart IS
PRAGMA AUTONOMOUS_TRANSACTION ;
  aUSER_ID    NUMBER(20) := -1;
  aIOART_FLG  NUMBER(1)  := 0;
  AnLunaLucru NUMBER(20);
BEGIN
  BEGIN
    SELECT Coalesce(USERID,-1), Coalesce(IOART_FLG,   0)
    INTO   aUSER_ID,       aIOART_FLG
    FROM   LUNA_RECORDS_FLAGS
    WHERE  USERID = PKG_GLOBALS.USERID;
  EXCEPTION
    WHEN OTHERS  THEN BEGIN
      aUSER_ID     := -1;
      aIOART_FLG   := 0;
    END;
  END;

  IF aUSER_ID = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG) VALUES (PKG_GLOBALS.USERID, 0, 0, 0, 0, 0);
  END IF;

  SELECT PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU INTO AnLunaLucru FROM dual;

  IF aIOART_FLG = 0 THEN
    --IOART1
    DELETE FROM tmp_ioart_luna;

    INSERT INTO tmp_ioart_luna (codioart1,codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,
                                chelttvacolectat,PROVIZION,CHELTPROVIZION,controtunjiri,diverse,accizelatransfer,descarcareg,contabgest,
                                baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,den_ioart)
    SELECT codioart1,io.codioart,cont,diferente,cheltuieli,venituri,plusinventar,minusinventar,chelttvacolectat,PROVIZION,CHELTPROVIZION,controtunjiri,
           diverse,accizelatransfer,descarcareg,contabgest,baza,difpret,aretvaneex,tvaneex,mg,anstart,lunastart,den_ioart
    FROM ioart io INNER JOIN ioart1 io1 ON io.codioart = io1.codioart
    WHERE AnLunaLucru BETWEEN IO1.ALSTART AND IO1.ALSTOP;

    UPDATE LUNA_RECORDS_FLAGS SET IOART_FLG = 1 WHERE USERID = PKG_GLOBALS.USERID;
  END IF;
  COMMIT;
END;

FUNCTION  iCont_CodCont(pIcont   IN NUMBER,
                        pCodPart IN NUMBER,
                        pAnluna  IN NUMBER,
                        pSemnif  IN NUMBER)
          RETURN NUMBER
IS
  pCol     VARCHAR2(50);
  sSelect  VARCHAR2(1000);
  pCodCont NUMBER(20);
  pAux     NUMBER(20);
BEGIN
  IF COALESCE(pIcont, 0) = 0 then Return null; end if;
  IF pSEMNIF IN (900,901,950,951) THEN
    pCodCont := pIcont;
  ELSIF pSEMNIF IN (500,600) THEN
    SELECT Max(cv.valoare)
    INTO pCodCont
    FROM constluna cl INNER JOIN constval cv ON cv.codconstluna = cl.codconstluna
    WHERE cl.codconst1 = pIcont AND pAnluna BETWEEN cl.ALStart AND CL.ALStop;
  ELSIF pIcont &lt; 1 THEN
    pCodCont := 0;
  ELSIF pSEMNIF IN (1100,1101) THEN -- pCodPart = CodPers
    IF (oldDen_IOPERS1 IS NOT NULL) AND Coalesce(oldIdx_IOPERS1,-1) = pIcont THEN
      pCol := oldDen_IOPERS1;
    ELSE
      SELECT column_name INTO pCol FROM User_Tab_Columns WHERE table_name = &apos;IOPERS1&apos; AND COLUMN_ID = pIcont + 1;
    END IF;

    IF Coalesce(oldCodP_IOPERS1,-1) = pCodPart AND Coalesce(oldAL_IOPERS1,-1) = pAnLuna THEN
      pAux := oldCod_IOPERS1;
    ELSE
      SELECT Max(codiopers)
      INTO pAux
      FROM npers1
      WHERE codpers = pCodPart AND pAnluna BETWEEN ALStart AND ALStop;
    END IF;

    IF Coalesce(oldCod_IOPERS1,-1) = pAux AND Coalesce(oldAL_IOPERS1,-1) = pAnluna AND Coalesce(oldDen_IOPERS1,&apos;&apos;) = pCol THEN
      pCodCont := oldCodC_IOPERS1;
    ELSE
      IF Coalesce(pAux,-1) &gt; 0 THEN
        EXECUTE IMMEDIATE &apos;SELECT &apos;||pCol||&apos; FROM iopers1 WHERE &apos;||pAnLuna||&apos; BETWEEN alstart and alstop AND codiopers = &apos;||pAux INTO pCodCont;
      ELSE pCodCont := 0;
      END IF;
    END IF;

    oldIdx_IOPERS1  := pIcont;
    oldDen_IOPERS1  := pCol;
    oldCod_IOPERS1  := pAux;
    oldAL_IOPERS1   := pAnluna;
    oldCodC_IOPERS1 := pCodCont;
    oldCodP_IOPERS1 := pCodPart;
  ELSE
    IF (oldDen_IOPART1 IS NOT NULL) AND Coalesce(oldIdx_IOPART1,-1) = pIcont THEN
      pCol := oldDen_IOPART1;
    ELSE
      SELECT column_name INTO pCol FROM User_Tab_Columns WHERE table_name = &apos;IOPART1&apos; AND COLUMN_ID = pIcont + 1;
    END IF;

    IF Coalesce(oldCodP_IOPART1,-1) = pCodPart AND Coalesce(oldAL_IOPART1,-1) = pAnluna THEN
      pAux := oldCod_IOPART1;
    ELSE
      SELECT Max(codiopart)
      INTO pAux
      FROM npart1
      WHERE codpart = pCodPart AND pAnluna BETWEEN ALStart AND ALStop;
    END IF;

    IF Coalesce(oldCod_IOPART1,-1) = pAux AND Coalesce(oldAL_IOPART1,-1) = pAnluna AND Coalesce(oldDen_IOPART1,&apos;&apos;) = pCol THEN
      pCodCont := oldCodC_IOPART1;
    ELSE
      IF Coalesce(pAux,-1) &gt; 0 THEN
        EXECUTE IMMEDIATE &apos;SELECT Max(&apos;||pCol||&apos;) FROM iopart1 WHERE &apos;||pAnLuna||&apos; BETWEEN ALStart AND ALStop AND codiopart = &apos;||pAux INTO pCodCont;
      ELSE pCodCont := 0;
      END IF;
    END IF;

    oldIdx_IOPART1  := pIcont;
    oldDen_IOPART1  := pCol;
    oldCod_IOPART1  := pAux;
    oldAL_IOPART1   := pAnluna;
    oldCodC_IOPART1 := pCodCont;
    oldCodP_IOPART1 := pCodPart;
  END IF;

  RETURN Coalesce(pCodCont,0);

END;

FUNCTION  decode_iCont( pIcont   IN NUMBER,
                        pCodPart IN NUMBER,
                        pAnluna  IN NUMBER,
                        pSemnif  IN NUMBER)
          RETURN VARCHAR2
IS
  sResult  VARCHAR2(50);
BEGIN
  BEGIN
    SELECT simbol INTO sResult
    FROM ncont
    WHERE codcont = PKG_LIST_BASE_UTILS.icont_CodCont(pIcont,pCodPart,pAnluna,pSemnif);
  EXCEPTION
    WHEN OTHERS THEN sResult := &apos;... Nedefinit ...&apos;;
  END;
	RETURN sResult;
END;

FUNCTION GETCODNIRSTOCPARINTE (vCODNIRSTOC NUMBER) RETURN NUMBER IS
sCodNirStoc number(20);
aCount number(1);
BEGIN
  SELECT count(*) INTO aCount FROM tmp_manevra2 WHERE codunic = vcodnirstoc;
  if aCount &gt; 0 THEN
    return 0;
  END if;
  insert INTO tmp_manevra2(codunic) values(vcodnirstoc);
  begin
    WITH /*RECURSIVE*/ a (codnirstoc, codnirstocparinte) AS (
      SELECT codnirstoc, codnirstocparinte
      FROM nirstoc
      WHERE codnirstoc = vCodNirStoc
      UNION ALL
      SELECT n.codnirstoc, n.codnirstocparinte
      FROM nirstoc n INNER JOIN a ON a.codnirstocparinte = n.codnirstoc
    )
    SELECT min(a.codnirstocparinte) into sCodNirStoc
    FROM a;
  exception when others then sCodNirStoc := vCOdNirStoc;
  end;
  if sCodNirStoc is null then sCodNirStoc := vCODNIRSTOC; end if;
  return sCodNirStoc;
END;

FUNCTION GETCODNIRSTOC_ORIG (vCODNIRSTOC NUMBER) RETURN NUMBER IS
BEGIN
  delete tmp_manevra2;
  return GETCODNIRSTOCPARINTE(vCodNIRSTOC);
END;

PROCEDURE UMA_UTILS(cCant       IN  VARCHAR2,
                    cCodObiect  IN  VARCHAR2,
                    sInsertUMA  OUT VARCHAR2,
                    sSelectUMA  OUT VARCHAR2,
                    sJoinUMA    OUT VARCHAR2,
                    sCuFunctii  IN  BOOLEAN DEFAULT FALSE ) IS
  vConfirm NUMBER(20);
BEGIN
  vConfirm := 0;

  IF pkg_categconst.GetValConstanta(&apos;ListareUMAmbRapVanz&apos;,pkg_globals.anlucru,pkg_globals.lunalucru) = &apos;1&apos; THEN
    DELETE TMP_UMA;
    INSERT INTO TMP_UMA(
      CODOBIECT,
      DUMA1, PUMA1,
      DUMA2, PUMA2,
      DUMA3, PUMA3,
      PUMAC, PUMAP)
    SELECT
      CODOBIECT,
      Max(DECODE(IDX,1,DEN_UM1)) DUMA1, Max(DECODE(IDX,1,paritate)) PUMA1,
      Max(DECODE(IDX,2,DEN_UM1)) DUMA2, Max(DECODE(IDX,2,paritate)) PUMA2,
      Max(DECODE(IDX,3,DEN_UM1)) DUMA3, Max(DECODE(IDX,3,paritate)) PUMA3,
      Max(DECODE(CodExtern,&apos;CUTIE&apos;,paritate)) PUMAC, Max(DECODE(CodExtern,&apos;PALET&apos;,paritate)) PUMAP
    FROM (
      SELECT AMB.CODOBIECT, Dense_Rank() OVER (PARTITION BY AMB.CODOBIECT ORDER BY AMB.CODAMB) IDX, U1.DEN_UM1, u1.paritate, Upper(U1.Codextern) CodExtern
      FROM NARTAMB AMB INNER JOIN NUM1 U1 ON U1.CODUM1 = AMB.UMSEC )
    GROUP BY CODOBIECT;
    COMMIT;
    SELECT COUNT(1) INTO vConfirm FROM TMP_UMA;
  END IF;

  IF vConfirm &gt; 0 THEN
    sInsertUMA := &apos;, DUMA1, CUMA1, DUMA2, CUMA2, DUMA3, CUMA3, CUMAC, CUMAP&apos;;
    sSelectUMA := &apos;, UMA.DUMA1, &apos;||cCant||&apos;/UMA.PUMA1, UMA.DUMA2, &apos;||cCant||&apos;/UMA.PUMA2, UMA.DUMA3, &apos;||cCant||&apos;/UMA.PUMA3, &apos;||cCant||&apos;/UMA.PUMAC, &apos;||cCant||&apos;/UMA.PUMAP&apos;;
    sJoinUMA      := &apos;
    LEFT JOIN TMP_UMA UMA ON UMA.CODOBIECT = &apos;||cCodObiect;

    IF sCuFunctii THEN
      sSelectUMA := &apos;,
      PKG_LIST_BASE_UTILS.DUMA1(&apos;||cCodObiect||&apos;), &apos;||cCant||&apos;/PKG_LIST_BASE_UTILS.PUMA1(&apos;||cCodObiect||&apos;),
      PKG_LIST_BASE_UTILS.DUMA2(&apos;||cCodObiect||&apos;), &apos;||cCant||&apos;/PKG_LIST_BASE_UTILS.PUMA2(&apos;||cCodObiect||&apos;),
      PKG_LIST_BASE_UTILS.DUMA3(&apos;||cCodObiect||&apos;), &apos;||cCant||&apos;/PKG_LIST_BASE_UTILS.PUMA3(&apos;||cCodObiect||&apos;),
      &apos;||cCant||&apos;/PKG_LIST_BASE_UTILS.PUMAC(&apos;||cCodObiect||&apos;), &apos;||cCant||&apos;/PKG_LIST_BASE_UTILS.PUMAP(&apos;||cCodObiect||&apos;)&apos;;
      sJoinUMA := &apos;&apos;;
    END IF;

  END IF;
END;

PROCEDURE SET_UMA(pCodObiect IN NUMBER) IS
BEGIN
  IF Coalesce(pCodObiect,0) &lt;&gt; Coalesce(vCodObjUMA,0) THEN
    vCodObjUMA := Coalesce(pCodObiect,0);
    SELECT
      Max(DECODE(IDX,1,DEN_UM1)) DUMA1, Max(DECODE(IDX,1,paritate)) PUMA1,
      Max(DECODE(IDX,2,DEN_UM1)) DUMA2, Max(DECODE(IDX,2,paritate)) PUMA2,
      Max(DECODE(IDX,3,DEN_UM1)) DUMA3, Max(DECODE(IDX,3,paritate)) PUMA3,
      Max(DECODE(CodExtern,&apos;CUTIE&apos;,paritate)) PUMAC,
      Max(DECODE(CodExtern,&apos;PALET&apos;,paritate)) PUMAP
    INTO vDUMA1, vPUMA1, vDUMA2, vPUMA2, vDUMA3, vPUMA3, vPUMAC, vPUMAP
    FROM (
      SELECT AMB.CODOBIECT, Dense_Rank() OVER (PARTITION BY AMB.CODOBIECT ORDER BY AMB.CODAMB) IDX, U1.DEN_UM1, u1.paritate, Upper(U1.Codextern) CodExtern
      FROM NARTAMB AMB INNER JOIN NUM1 U1 ON U1.CODUM1 = AMB.UMSEC
      WHERE AMB.CODOBIECT = vCodObjUMA
    );
  END IF;
END;

FUNCTION  DUMA1(pCodObiect IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vDUMA1;
END;

FUNCTION  DUMA2(pCodObiect IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vDUMA2;
END;

FUNCTION  DUMA3(pCodObiect IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vDUMA3;
END;

FUNCTION  PUMA1(pCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vPUMA1;
END;

FUNCTION  PUMA2(pCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vPUMA2;
END;

FUNCTION  PUMA3(pCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vPUMA3;
END;

FUNCTION  PUMAC(pCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vPUMAC;
END;

FUNCTION  PUMAP(pCodObiect IN NUMBER) RETURN NUMBER IS
BEGIN
  SET_UMA(pCodObiect);
  RETURN vPUMAP;
END;

FUNCTION  GetCursReg (pCodGeneral IN NUMBER, pCont IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER IS
  vCurs NUMBER;
BEGIN
  SELECT Max(r.curs) KEEP (Dense_Rank LAST ORDER BY r.an, r.luna)
  INTO vCurs
  FROM reg r INNER JOIN reg1 r1 ON r.codreg = r1.codreg
  WHERE r.tipreg = 46
    AND r.an * 12 + r.luna &lt; pAn * 12 + pLuna
    AND r1.cont = pCont
    AND r1.CodGeneral = pCodGeneral;

  IF vCurs = 0
  THEN vCurs := NULL;
  END IF;

  RETURN vCurs;
EXCEPTION
  WHEN OTHERS THEN RETURN NULL;
END;

FUNCTION  GetSoldPart(pCodPart IN NUMBER, pCodLocatie IN NUMBER) RETURN NUMBER IS
  vSql  VARCHAR2(20000);
  vSold NUMBER;
BEGIN
  PKG_NOMPART.SET_PART_CURENT(pCodPart);
  PKG_MONEDE.SET_MONEDA_CURENTA(-1);

  vSql := &apos;
  WITH OBLIG AS (
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_OBLIG_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_INTRARI_ROSU_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
      FROM V_AVANS_FURN_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_AVANS_FURN_FACTURABILE V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_OBLIG_CLIENT V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_IESIRI_ROSU_CLIENT V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_FACTURABILE V
  )
  SELECT Sum (RESTREAL)
  FROM OBLIG &apos;||
  PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;&apos;,&apos;SUBUNITATEA&apos;,&apos;
  WHERE&apos;)||
  CASE WHEN Coalesce(pCodLocatie,0) &lt;&gt; 0 THEN &apos; AND CodLocatie = &apos;||pCodLocatie END;

  EXECUTE IMMEDIATE vSql INTO vSold;
  vSold := Coalesce(vSold,0);
  RETURN vSold;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION GetSoldPartCumulat(pCodPart IN NUMBER, pCodLocatie IN NUMBER) RETURN NUMBER IS
  vSql  VARCHAR2(20000);
  vSold NUMBER;
BEGIN
  PKG_NOMPART.SET_PART_CURENT(pCodPart);
  PKG_MONEDE.SET_MONEDA_CURENTA(-1);

  vSql := &apos;
  WITH OBLIG AS (
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_OBLIG_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_INTRARI_ROSU_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
      FROM V_AVANS_FURN_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_AVANS_FURN_FACTURABILE V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_OBLIG_CLIENT V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_IESIRI_ROSU_CLIENT V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      -V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_FACTURABILE V
  )
  SELECT Sum (RESTREAL)
  FROM OBLIG &apos;||CASE WHEN Coalesce(pCodLocatie,0) &lt;&gt; 0 THEN &apos; WHERE CodLocatie = &apos;||pCodLocatie END;

  EXECUTE IMMEDIATE vSql INTO vSold;
  vSold := Coalesce(vSold,0);
  RETURN vSold;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION GetSoldFurnizor(pCodPart IN NUMBER, pCodLocatie IN NUMBER DEFAULT 0) RETURN NUMBER IS
  vSql  VARCHAR2(20000);
  vSold NUMBER;
BEGIN
  PKG_NOMPART.SET_PART_CURENT(pCodPart);
  PKG_MONEDE.SET_MONEDA_CURENTA(-1);

  vSql := &apos;
  WITH OBLIG AS (
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_OBLIG_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_IESIRI_ROSU_CLIENT V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS) RESTREAL, -V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS) VALREAL
    FROM V_AVANS_CLIENT_FACTURABILE V
  )
  SELECT Sum (RESTREAL)
  FROM OBLIG
  WHERE 1 = 1 &apos;||
  CASE WHEN Coalesce(pCodLocatie,0) &lt;&gt; 0 THEN &apos; AND CodLocatie = &apos;||pCodLocatie END;

  EXECUTE IMMEDIATE vSql INTO vSold;
  vSold := Coalesce(vSold,0);
  RETURN vSold;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION GetSoldClient(pCodPart IN NUMBER, pCodLocatie IN NUMBER DEFAULT 0) RETURN NUMBER IS
  vSql  VARCHAR2(20000);
  vSold NUMBER;
BEGIN
  PKG_NOMPART.SET_PART_CURENT(pCodPart);
  PKG_MONEDE.SET_MONEDA_CURENTA(-1);

  vSql := &apos;
  WITH OBLIG AS (
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_INTRARI_ROSU_FURN V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
      FROM V_AVANS_FURN_TREZOR V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_AVANS_FURN_FACTURABILE V
    UNION ALL
    SELECT
      V.CodLocatie, V.Subunitatea,
      V.REST * DECODE(V.CURS,NULL,1,0,1,V.CURS)  RESTREAL, V.VALOARE * DECODE(V.CURS,NULL,1,0,1,V.CURS)  VALREAL
    FROM V_OBLIG_CLIENT V
  )
  SELECT Sum (RESTREAL)
  FROM OBLIG
  WHERE 1 = 1 &apos;||
  CASE WHEN Coalesce(pCodLocatie,0) &lt;&gt; 0 THEN &apos; AND CodLocatie = &apos;||pCodLocatie END;

  EXECUTE IMMEDIATE vSql INTO vSold;
  vSold := Coalesce(vSold,0);
  RETURN vSold;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION NIVELE_NCLASEA RETURN INTEGER IS
  vMaxCL INTEGER;
BEGIN
  -- folosita ptr afisarea claselor de la radacina
  -- liste -&gt; profit, vanzari periodice, stocuri la moment
  vMaxCl := 0;
  BEGIN
    SELECT max(nivel) INTO vMaxCl FROM nclasea;
  EXCEPTION
    WHEN OTHERS THEN vMaxCl := 0;
  END;
  DELETE TMP_PROFIT_NCLASEA;
  IF vMaxCL &gt; 0 THEN
    INSERT INTO TMP_PROFIT_NCLASEA (CODCLASEA, DEN_CLASEA, SIMBOL, NIVEL)
    SELECT x.cod, c.den_clasea, c.simbol, Row_Number() OVER (PARTITION BY x.COD ORDER BY x.nivel) nivel
    FROM(
      SELECT connect_by_root codclasea cod, codclasea, nivel
      FROM nclasea
      START WITH Coalesce(codparinte,0) &lt;&gt; 0
      CONNECT BY PRIOR codparinte = codclasea
      ) x INNER JOIN nclasea c ON c.codclasea = x.codclasea
    UNION ALL
    SELECT c.codclasea cod, c.den_clasea, c.simbol, c.nivel
    FROM nclasea c
    WHERE Coalesce(codparinte,0) = 0;
  END IF;
  COMMIT;
  RETURN vMaxCl;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

FUNCTION NIVELE_ANALIZA RETURN INTEGER IS
  vMaxCL INTEGER;
BEGIN
  -- folosita ptr afisarea nodurilor din proiecte de analiza de la radacina
  -- liste -&gt; realizari pe gestiuni
  DELETE TMP_TREE_ANALIZANOD;
  INSERT INTO TMP_TREE_ANALIZANOD(CODANALIZANOD, NIVEL, DEN_DESCRIPTOR, SIMBOL, VALOARE, TIP, CODASOCIAT, POZITIE)
  SELECT x.cod, Row_Number() OVER (PARTITION BY x.COD ORDER BY x.ord) nivel, d.den_descriptor, d.simbol, d1.valoare, D.TIP, D1.CODASOCIAT, A.POZITIE
  FROM(
    SELECT connect_by_root codanalizanod cod, codanalizanod, -level ord
    FROM ANALIZANOD
    WHERE POZITIE &lt;&gt; 0
    START WITH Coalesce(nodparinte,0) &lt;&gt; 0
    CONNECT BY PRIOR nodparinte = codanalizanod
    ) x
    INNER JOIN ANALIZANOD a ON a.codanalizanod = x.codanalizanod
    INNER JOIN ANALIZA1 a1 ON a1.codanaliza1 = a.codanaliza1
    INNER JOIN DESCRIPTORI1 D1 ON d1.coddescriptor1 = a.coddescriptor1
    INNER JOIN DESCRIPTORI D ON d.coddescriptor = d1.coddescriptor;

  UPDATE TMP_TREE_ANALIZANOD TMP
  SET
    IDX = (SELECT LISTAGG(TO_CHAR(POZITIE),&apos;.&apos;) WITHIN GROUP (ORDER BY NIVEL) FROM TMP_TREE_ANALIZANOD T WHERE T.CODANALIZANOD = TMP.CODANALIZANOD);

  BEGIN
    SELECT Coalesce(Max(nivel),0) INTO vMaxCl FROM TMP_TREE_ANALIZANOD;
  EXCEPTION
    WHEN OTHERS THEN vMaxCl := 0;
  END;

  COMMIT;
  RETURN vMaxCl;
EXCEPTION
  WHEN OTHERS THEN RETURN 0;
END;

PROCEDURE ExtractAnLuna (pAnLuna IN NUMBER, pAn OUT NUMBER, pLuna OUT NUMBER) IS
BEGIN
  pLuna := Mod(pAnLuna,12);
  pLuna := CASE pLuna WHEN 0 THEN 12 ELSE pLuna END;
  pAn   := (pAnLuna-pLuna)/12;
END;

PROCEDURE CLEAR_SIMBOL_LIPSA IS
BEGIN
  vListSimbLipsa := &apos;&apos;;
  DELETE TMP_LIPSA_CORESP_PLANP;
  COMMIT;
END;

PROCEDURE SET_LISTA_SIMBOL_LIPSA (pLista IN VARCHAR2) IS
  vLength INTEGER;
BEGIN
  vListSimbLipsa := pLista;
  vLength        := CASE
                      WHEN InStr(vListSimbLipsa, &apos;,&apos;, 1, 5) BETWEEN 1 AND 150 THEN InStr(vListSimbLipsa, &apos;,&apos;, 1, 5) - 1
                      WHEN Length(vListSimbLipsa)                       &gt; 150 THEN 150
                      ELSE 0
                    END;
  IF vLength &gt; 0 THEN
    vListSimbLipsa := SubStr(vListSimbLipsa, 1, vLength)||&apos;...&apos;;
  END IF;
END;

PROCEDURE ADD_SIMBOL_LIPSA (pSimbol IN VARCHAR2) IS
BEGIN
  INSERT INTO TMP_LIPSA_CORESP_PLANP (SIMBOL) VALUES (pSimbol);
END;

FUNCTION  SET_SIMBOL_LIPSA (pCodCont IN NUMBER, pSimbol IN VARCHAR2) RETURN NUMBER IS
PRAGMA AUTONOMOUS_TRANSACTION ;
BEGIN
  IF pCodCont = -1 THEN
    INSERT INTO TMP_LIPSA_CORESP_PLANP (SIMBOL) VALUES (pSimbol);
  END IF;
  RETURN 0;
END;

FUNCTION LIST_SIMBOL_LIPSA RETURN VARCHAR2 IS
  vCount NUMBER;
BEGIN
  IF vListSimbLipsa IS NULL THEN
    SELECT Count(1) INTO vCount FROM TMP_LIPSA_CORESP_PLANP;

    IF    vCount =  0
    THEN vListSimbLipsa := &apos;&apos;;
    ELSE
      SELECT vc2_nt_to_vc3200_dist(CAST(COLLECT(simbol ORDER BY simbol) AS vc2_nt)) INTO vListSimbLipsa
      FROM (
        SELECT simbol, Row_Number() OVER (ORDER BY simbol) idx
        FROM TMP_LIPSA_CORESP_PLANP
      ) WHERE idx &lt;= 5;

      IF vCount &gt; 5 THEN
        vListSimbLipsa := vListSimbLipsa||&apos;...&apos;;
      END IF;
    END IF;
  END IF;
  RETURN vListSimbLipsa ;
END;

PROCEDURE UMPLE_TMP_CONSTVAL_LST (pSimbolList VARCHAR2 DEFAULT NULL) IS
  vWhere VARCHAR2(10000);
  cSql   CLOB;
BEGIN
  DELETE FROM TMP_CONSTVAL_LST;

  vWhere := Upper(REPLACE(pSimbolList,&apos; &apos;,&apos;&apos;));

  IF vWhere IS NOT NULL THEN
    vWhere := &apos;
    WHERE UPPER(C1.simbol) IN (&apos;&apos;&apos;||REPLACE(vWhere, &apos;,&apos;,&apos;&apos;&apos;,&apos;&apos;&apos;)||&apos;&apos;&apos;)&apos;;
  END IF;

  cSql := &apos;INSERT INTO TMP_CONSTVAL_LST
  SELECT
    C.SIMBOL,
    CASE
      WHEN LAG(C.ALSTART) OVER (PARTITION BY C.SIMBOL ORDER BY C.ALSTART) IS NOT NULL THEN C.ALSTART
      WHEN C.ALSTART = (SELECT B.ANINITIAL*12+B.LUNAINITIALA FROM FIRMALUNI B) THEN 0
      ELSE C.ALSTART
    END ANLUNASTART,
    Coalesce(LEAD(C.ALSTART) OVER (PARTITION BY C.SIMBOL ORDER BY C.ALSTART) - 1, 99999) ANLUNASTOP,
    LISTAGG(VALOARE, &apos;&apos;,&apos;&apos;) WITHIN GROUP (ORDER BY VALOARE) VALOARE
  FROM (
    SELECT Upper(C1.SIMBOL) AS SIMBOL, CL.ANSTART*12 + CL.LUNASTART AS ALSTART, CV.VALOARE
    FROM CONST1 C1
      INNER JOIN CATEGCONST CT ON CT.CODCATEG     = C1.CODCATEG
      INNER JOIN CONSTLUNA  CL ON CL.CODCONST1    = C1.CODCONST1 AND CL.USERID = CASE WHEN CT.TIPCATEG = &apos;&apos;G&apos;&apos; THEN 0 WHEN CT.TIPCATEG = &apos;&apos;U&apos;&apos; THEN PKG_GLOBALS.GETUSERID END
      LEFT  JOIN CONSTVAL   CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA&apos;||
  vWhere||&apos;
    ) C
  GROUP BY SIMBOL, ALSTART&apos;;
  EXECUTE IMMEDIATE cSql;
END;

PROCEDURE UMPLE_TMP_MEDEX1_LST IS
BEGIN
--********************* STEF - DACA AM EROARE LA COMPILARE PACHET IN ACEST LOC S-A SCHIMBAT STRUCTURA MEDEX1 SI TREBUIE RULAT CE E COMENTAT PE URMATOARELE 2 LINII *******************
--DROP TABLE TMP_MEDEX1_LST;
--CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX1_LST ON COMMIT PRESERVE ROWS AS SELECT A.* FROM MEDEX1 A WHERE 1 = 2;
  DELETE FROM TMP_MEDEX1_LST;

  INSERT INTO TMP_MEDEX1_LST
  SELECT
    CODMEDEX1, CODMEDEX, CODCIM, DENUMIRE, PREZENTARE, NARCOTIC, FRACTIONAL, SPECIAL, AREBIOECHIVALENT, CANT, PRETAM,
    PRETRID, PRESCRIERE, VALIDDELA, VALIDPANALA, DCI, CONC, FORMAFARM, PRODUCATOR, TARA, GRUPA
  FROM (
    SELECT
      CODMEDEX1, CODMEDEX, CODCIM, DENUMIRE, PREZENTARE, NARCOTIC, FRACTIONAL, SPECIAL, AREBIOECHIVALENT, CANT, PRETAM,
      PRETRID, PRESCRIERE, VALIDDELA, VALIDPANALA, DCI, CONC, FORMAFARM, PRODUCATOR, TARA, GRUPA,
      Row_Number() OVER (PARTITION BY CODCIM ORDER BY CODMEDEX1 DESC) XNR
    FROM MEDEX1
  )
  WHERE XNR = 1;
END;

PROCEDURE UMPLE_TMP_NARTATR_LST IS
BEGIN
  DELETE FROM TMP_NARTATR_LST;

  INSERT INTO TMP_NARTATR_LST
  SELECT codarticol, vc2_nt_to_string(CAST(COLLECT(obs ORDER BY indexlocal) AS vc2_nt)) Obs
  FROM nartatr
  GROUP BY codarticol;
END;

PROCEDURE UMPLE_TMP_CAMERE_LST IS
  vLocLib     NUMBER;
  vLocRez     NUMBER;
  vLocContr   NUMBER;
  vDataRef    DATE;
  vCodObjCam  NUMBER;
BEGIN
  DELETE TMP_CAMERE_LST;
  vCodObjCam := Coalesce(pkg_categconst.GetValConstanta(&apos;ArtOcupGestCam&apos;, pkg_globals.ANLUCRU , pkg_globals.LUNALUCRU), 0);

  INSERT INTO TMP_CAMERE_LST
  SELECT codgest, 0, 0, 0, 0
  FROM ngest
  WHERE Coalesce(tip,0) &lt;&gt; 6;

  vDataRef := To_Date(&apos;01&apos;||To_Char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||To_Char(pkg_globals.ANLUCRU,&apos;fm0000&apos;),&apos;ddmmyyyy&apos;);
  IF Trunc(SYSDATE,&apos;mm&apos;) = vDataRef THEN
    vDataRef := Trunc(SYSDATE,&apos;dd&apos;);
  END IF;

  FOR vRec IN (
    SELECT codgest, cantitate locuri
    FROM ngest
    WHERE Coalesce(tip,0) = 6
  ) LOOP
    SELECT Coalesce(Sum(c1.restacceptat),0) INTO vLocRez
    FROM comanda1 c1
      INNER JOIN comanda c ON c.codcomanda = c1.codcomanda
    WHERE c1.GestAct = vRec.CodGest
      AND c1.CodObiect = vCodObjCam
      AND c.An * 12 + c.Luna &lt;= pkg_globals.ANLUNALUCRU
      AND Coalesce(c.anulat,0) = 0
      AND Coalesce(c.operat,0) = 1;

    SELECT Coalesce(Sum(c1.cant),0) INTO vLocContr
    FROM contract1 c1
      INNER JOIN contract c ON c.codcontract = c1.codcontract
    WHERE c1.GestAct = vRec.CodGest
      AND c1.CodObiect = vCodObjCam
      AND vDataRef BETWEEN Coalesce(C1.DataStart,C.DataStart) AND Coalesce(C1.DataStop, C.DataStop)
      AND Coalesce(c.anulat,0) = 0
      AND Coalesce(c.operat,0) = 1;

    vLocLib   := vRec.Locuri - vLocContr;
    INSERT INTO TMP_CAMERE_LST (CODGEST, LOCURI, LOCLIB, LOCREZ, LOCCONTR) VALUES (vRec.CodGest, vRec.Locuri, vLocLib, vLocRez, vLocContr);
  END LOOP;
END;

FUNCTION GET_Den_BancaCursPUV(pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2
IS
  vAnLuna NUMBER := pAn*12+pLuna;
BEGIN
  IF vAnLuna &lt;&gt; Coalesce(vAnLunaBCPUV,-1) THEN
    vAnLunaBCPUV := vAnLuna;
    vDenBCPUV    := pkg_list_base_utils.get_den_banca(pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,pAn, pLuna));
  END IF;
  RETURN vDenBCPUV;
END;


PROCEDURE SET_VAR_MonedaFactInValuta(pAnLuna NUMBER) IS
BEGIN
  vAnLunaMFIV := pAnLuna;
  BEGIN
  SELECT VC2_NT_TO_VC3200(CAST(collect(simbol) AS vc2_nt)), CASE WHEN Count(1) = 1 THEN Max(CodMoneda) ELSE NULL END
  INTO vSimbMFIV, vCodMFIV
  FROM NMONEDE
  WHERE CODMONEDA IN (
    SELECT CV.VALOARE
    FROM CONST1 C1
      INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
      LEFT  JOIN CONSTVAL  CV ON CV.codconstluna = CL.codconstluna
    WHERE UPPER(C1.simbol) = &apos;MONEDAFACTINVALUTA&apos; AND vAnLunaMFIV BETWEEN cl.ALStart AND cl.ALStop
  );
  EXCEPTION WHEN OTHERS THEN vSimbMFIV := &apos;&apos;; vCodMFIV := 0;
  END;
END;

FUNCTION GET_Simb_MonedaFactInValuta(pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2
IS
  vAnLuna NUMBER := pAn*12+pLuna;
BEGIN
  IF vAnLuna &lt;&gt; Coalesce(vAnLunaMFIV,-1) THEN
    SET_VAR_MonedaFactInValuta(vAnLuna);
  END IF;
  RETURN vSimbMFIV;
END;

FUNCTION GET_Cod_MonedaFactInValuta(pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER
IS
  vAnLuna NUMBER := pAn*12+pLuna;
BEGIN
  IF vAnLuna &lt;&gt; Coalesce(vAnLunaMFIV,-1) THEN
    SET_VAR_MonedaFactInValuta(vAnLuna);
  END IF;
  RETURN vCodMFIV;
END;

PROCEDURE SetDateDoc(aCodDoc IN NUMBER, aCodDoc1 IN NUMBER, aTipDoc IN NUMBER) IS
  vCodDoc NUMBER;
  TaskFirma number(1);
begin
  IF aTipDoc IN (11,29,30,31,33) THEN
    vCodDoc := Coalesce(aCodDoc1, aCodDoc);
  ELSE
    vCodDoc := aCodDoc;
  END IF;

	vSDD_TablaDoc := &apos;&apos;;
  IF (Coalesce(vCodDoc,0) &lt;&gt; Coalesce(vSDD_CodDoc,0)) OR (Coalesce(aTipDoc,0) &lt;&gt; Coalesce(vSDD_TipDoc,0)) THEN
    vSDD_TipDoc  := aTipDoc;
    vSDD_CodDoc  := vCodDoc;
		vSDD_ObsDoc  := &apos;&apos;;
		vSDD_DenDoc  := &apos;&apos;;
		vSDD_UserDoc := NULL;
    vSDD_PartDoc := NULL;
    vSDD_ValDoc  := 0;
    -- TipDoc tratate
    -- 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,36,43,44,45,46,47,53,58,59,60,63,64,65,66,71,92,94
    CASE
    WHEN vSDD_TipDoc IN (1,2,3,4,5,6,7,9) THEN
      BEGIN
				vSDD_TablaDoc := &apos;INTRARI&apos;;
        SELECT Obs, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, Partener, ValDoc
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc, vSDD_ValDoc
        FROM intrari
        WHERE codintr = vSDD_CodDoc;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (8,18,43,44,53,60,65,66,92,94) THEN
      BEGIN
				vSDD_TablaDoc := &apos;COMANDA&apos;;
        SELECT Obs, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, Partener, Valoare
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc, vSDD_ValDoc
        FROM comanda WHERE codcomanda = vSDD_CodDoc;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (25,34) THEN
      BEGIN
        SELECT Obs, &apos;NCx&apos;||NrDoc||&apos;/&apos;||To_Char(DataStart,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(DataStop,&apos;dd.mm.yyyy&apos;), UserId, CodPart
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM notecredit WHERE codncredit = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;NOTECREDIT&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 11 THEN
      BEGIN
        SELECT &apos;&apos;, ds.DenDoc||ds.NrDoc||&apos;/&apos;||To_Char(ds.DataDoc,&apos;dd.mm.yyyy&apos;), ds.UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM docsuplim ds INNER JOIN docsuplim1 ds1 ON ds1.coddocsuplim = ds.coddocsuplim
        WHERE ds1.coddocsuplim1 = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;DOCSUPLIM&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (12, 13) THEN
      BEGIN
        SELECT Obs, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, ValDoc
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_ValDoc
        FROM transf WHERE codtransf = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;TRANSF&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (14,15,16,19,20,21,22,23,24,26) THEN
      BEGIN
        SELECT Obs, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, ValDoc, Partener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_ValDoc, vSDD_PartDoc
        FROM iesiri WHERE codies = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;IESIRI&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 28 THEN
      BEGIN
        SELECT &apos;OBS Debit : &apos;||ObsD||&apos; - OBS Credit : &apos;||ObsC, &apos;PV&apos;||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, Coalesce(NUllIF(PartD, 0), NUllIF(PartC, 0))
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM compens WHERE codcompens = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;COMPENS&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (29,30,31,33) THEN
      BEGIN
        SELECT t1.Obs, t1.Doc||&apos;/&apos;||t1.NrDoc||&apos;/&apos;||To_Char(t1.DataDoc,&apos;dd.mm.yyyy&apos;), t.UserId, t1.CodPart, t1.valdoc
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc, vSDD_ValDoc
        FROM trezor t INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
        WHERE t1.codtrezor1 = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;TREZOR&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 35 THEN
      BEGIN
        SELECT Obs, &apos;NC&apos;||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId, Part, Valoare
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc, vSDD_ValDoc
        FROM nc WHERE codnc = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;NC&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 36 THEN
      BEGIN
        SELECT &apos;&apos;, &apos;MF/&apos;||SerieInv||&apos;/&apos;||NrInventar, NULL UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM mifix WHERE codmifix = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;MIFIX&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc IN (45,46,47) THEN
      BEGIN
        SELECT Obs, &apos;REG.&apos;||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), NULL UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM reg WHERE codreg = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;REG&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 58 THEN
      BEGIN
        SELECT Obs, &apos;NCC&apos;||NrDoc||&apos;/&apos;||To_Char(DataStart,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(DataStop,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM notecredit WHERE codncredit = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;NOTECREDIT&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 59 THEN
      BEGIN
        SELECT Obs, &apos;NCF&apos;||NrDoc||&apos;/&apos;||To_Char(DataStart,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(DataStop,&apos;dd.mm.yyyy&apos;), UserId, CodPart
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM notecredit WHERE codncredit = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;NOTECREDIT&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 62 THEN
      BEGIN
        SELECT Obs, &apos;LNP&apos;||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM lansare WHERE codlansare = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;LANSARE&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 63 THEN
      BEGIN
        SELECT &apos;&apos;, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataI,&apos;dd.mm.yyyy&apos;)||&apos;-&apos;||To_Char(DataS,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM raportp WHERE codraportp = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;RAPORTP&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 64 THEN
      BEGIN
        SELECT &apos;&apos;, &apos;Bon&apos;||NrBon||&apos;/&apos;||To_Char(DataBon,&apos;dd.mm.yyyy&apos;), UserId, Valoare
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_ValDoc
        FROM Emulare WHERE codEmulare = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;EMULARE&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 67 THEN
      BEGIN
        SELECT &apos;&apos; Obs, PrefixDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM BCAR WHERE codbcar = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;BCAR&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc in (55,105) THEN
      BEGIN
        SELECT &apos;&apos; Obs, case when vSDD_TipDoc = 55 then &apos;XPL&apos; else &apos;O&apos; end||NrDoc||&apos;/&apos;||To_Char(Data,&apos;dd.mm.yyyy&apos;), UserId, Valoare
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_ValDoc
        FROM PLATI WHERE CODPLATA = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;PLATI&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 97 THEN
      BEGIN
        SELECT Motiv, &apos;RECL&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), CodUtilizator, CodPart
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM Reclamatii WHERE codReclamatie = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;RECLAMATII&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 70 THEN
      BEGIN
        SELECT &apos;&apos; Obs, &apos;CANTAR&apos;||nvl(NrAviz,0)||&apos;/&apos;||to_char(datacreare,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM cantar WHERE codcantar = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;CANTAR&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 71 THEN
      BEGIN
        SELECT Obs, &apos;&apos; DenDoc, NULL UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM prodnet WHERE codprodnet = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;PRODNET&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 82 THEN
      BEGIN
        SELECT Obs, PrefixDoc||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserID, CodPartener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM OPORTUNITATI WHERE CodOportunitate = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;OPORTUNITATI&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 50 THEN
      BEGIN
        SELECT Obs, &apos;OC&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataOferta,&apos;dd.mm.yyyy&apos;), UserID, Partener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM OFERTA WHERE CodOferta = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;OFERTA&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 51 THEN
      BEGIN
        SELECT Obs, &apos;OF&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataOferta,&apos;dd.mm.yyyy&apos;), UserID, Partener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM OFERTA WHERE CodOferta = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;OFERTA&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 27 THEN
      BEGIN
        SELECT Obs, &apos;CcC&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserID, Partener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM CONTRACT WHERE CodContract = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;CONTRACT&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 10 THEN
      BEGIN
        SELECT Obs, &apos;CfC&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,&apos;dd.mm.yyyy&apos;), UserID, Partener
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc, vSDD_PartDoc
        FROM CONTRACT WHERE CodContract = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;CONTRACT&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 54 THEN
      BEGIN
				SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
				INTO TaskFirma from dual;
        IF TaskFirma = 1 THEN
					SELECT SubStr(PROBLEMA,1,200) Obs, MESAJCATRE||&apos;-&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DATATASK,&apos;dd.mm.yyyy&apos;) DenDoc, NULL UserId
					INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
					FROM WinMAdmin.SetTask WHERE CODTASK = vSDD_CodDoc;
					vSDD_TablaDoc := &apos;WinMAdmin.SetTask&apos;;
	      ELSE
					SELECT SubStr(PROBLEMA,1,200) Obs, MESAJCATRE||&apos;-&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DATATASK,&apos;dd.mm.yyyy&apos;) DenDoc, NULL UserId
					INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
					FROM SetTask WHERE CODTASK = vSDD_CodDoc;
					vSDD_TablaDoc := &apos;SetTask&apos;;
        END IF;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 69 THEN
      BEGIN
        SELECT Obs, to_char(NrDoc)||&apos;/&apos;||to_char(datadoc,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM nsertar WHERE codsertar = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;NSERTAR&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    WHEN vSDD_TipDoc = 78 THEN
      BEGIN
        SELECT &apos;&apos;, to_char(NrDoc)||&apos;/&apos;||to_char(datap,&apos;dd.mm.yyyy&apos;), UserId
        INTO vSDD_ObsDoc, vSDD_DenDoc, vSDD_UserDoc
        FROM pachete WHERE codpachete = vSDD_CodDoc;
				vSDD_TablaDoc := &apos;PACHETE&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    ELSE NULL;
    END CASE;
  END IF;
END;

FUNCTION GetObsDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN VARCHAR2 IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
  IF    Coalesce(aCodDoc,0) = 37 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) = 52 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) &lt;&gt; 0 AND Coalesce(aCodDoc1,aCodDoc,0) &lt;&gt; 0 THEN
    SetDateDoc(aCodDoc, aCodDoc1, aTipDoc);
    vResult := vSDD_ObsDoc;
  END IF;
  RETURN vResult;
END;

FUNCTION GetDenDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN VARCHAR2 IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
  IF    Coalesce(aCodDoc,0) = 37 THEN vResult := &apos;Sal&apos;;
  ELSIF Coalesce(aCodDoc,0) = 52 THEN vResult := &apos;CheltuieliInAvans&apos;;
  ELSIF Coalesce(aCodDoc,0) &lt;&gt; 0 AND Coalesce(aCodDoc1,aCodDoc,0) &lt;&gt; 0 THEN
    SetDateDoc(aCodDoc, aCodDoc1, aTipDoc);
    vResult := vSDD_DenDoc;
  END IF;
  RETURN vResult;
END;

FUNCTION GetValDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
  SetDateDoc(aCodDoc, aCodDoc1, aTipDoc);
  vResult := vSDD_ValDoc;
  RETURN vResult;
END;

FUNCTION GetUserDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
  IF    Coalesce(aCodDoc,0) = 37 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) = 52 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) &lt;&gt; 0 AND Coalesce(aCodDoc1,aCodDoc,0) &lt;&gt; 0 THEN
    SetDateDoc(aCodDoc, aCodDoc1, aTipDoc);
    vResult := vSDD_UserDoc;
  END IF;
  RETURN vResult;
END;

FUNCTION GetPartDoc(aCodDoc IN NUMBER, aTipDoc IN NUMBER, aCodDoc1 IN NUMBER DEFAULT NULL) RETURN NUMBER IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
  IF    Coalesce(aCodDoc,0) = 37 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) = 52 THEN vResult := &apos;&apos;;
  ELSIF Coalesce(aCodDoc,0) &lt;&gt; 0 AND Coalesce(aCodDoc1,aCodDoc,0) &lt;&gt; 0 THEN
    SetDateDoc(aCodDoc, aCodDoc1, aTipDoc);
    vResult := vSDD_PartDoc;
  END IF;
  RETURN vResult;
END;

FUNCTION GetTablaDoc(aTipDoc IN NUMBER) RETURN VARCHAR2 IS
  vResult VARCHAR2(500) := &apos;&apos;;
BEGIN
	vSDD_TablaDoc := &apos;&apos;;
  IF Coalesce(aTipDoc,0) &lt;&gt; 0 THEN
    CASE
      WHEN aTipDoc IN (1,2,3,4,5,6,7,9)               THEN vSDD_TablaDoc := &apos;INTRARI&apos;;
      WHEN aTipDoc IN (8,18,43,44,53,60,65,66,92,94)  THEN vSDD_TablaDoc := &apos;COMANDA&apos;;
      WHEN aTipDoc IN (14,15,16,19,20,21,22,23,24,26) THEN vSDD_TablaDoc := &apos;IESIRI&apos;;
      WHEN aTipDoc = 28                               THEN vSDD_TablaDoc := &apos;COMPENS&apos;;
      WHEN aTipDoc = 35                               THEN vSDD_TablaDoc := &apos;NC&apos;;
      WHEN aTipDoc IN (10,25,27,34,58,59)             THEN vSDD_TablaDoc := &apos;NOTECREDIT&apos;;
      WHEN aTipDoc IN (12, 13)                        THEN vSDD_TablaDoc := &apos;TRANSF&apos;;
      WHEN aTipDoc IN (29,30,31,33)                   THEN vSDD_TablaDoc := &apos;TREZOR&apos;;
      WHEN aTipDoc IN (45,46,47)                      THEN vSDD_TablaDoc := &apos;REG&apos;;
      WHEN aTipDoc = 71                               THEN vSDD_TablaDoc := &apos;PRODNET&apos;;
      WHEN aTipDoc = 63                               THEN vSDD_TablaDoc := &apos;RAPORTP&apos;;
      WHEN aTipDoc = 64                               THEN vSDD_TablaDoc := &apos;EMULARE&apos;;
      WHEN aTipDoc = 36                               THEN vSDD_TablaDoc := &apos;MIFIX&apos;;
      WHEN aTipDoc = 97                               THEN vSDD_TablaDoc := &apos;RECLAMATII&apos;;
    END CASE;
  END IF;
  RETURN vSDD_TablaDoc;
END;

PROCEDURE UMPLE_TMP_LST_CURS(aCODBANCA IN NUMBER DEFAULT NULL, aDATA DATE DEFAULT NULL, aCODMONEDA IN NUMBER DEFAULT NULL) IS
  vCodBanca NUMBER(20);
  vData     DATE;
BEGIN
  IF aCODBANCA IS NULL THEN
    vCodBanca := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  ELSE
    vCodBanca := aCODBANCA;
  END IF;

  IF aDATA IS NULL THEN
    vData := SYSDATE;
  ELSE
    vData := aData;
  END IF;

  DELETE TMP_LST_CURS;
  IF vCodBanca IS NOT NULL THEN
    INSERT INTO TMP_LST_CURS
    SELECT CODMONEDA, Max(VALOARE) KEEP (Dense_Rank First ORDER BY DATA DESC)
    FROM NMONEDE1
    WHERE data &lt;= vData
      AND CODMONEDA = Coalesce(aCODMONEDA, CODMONEDA)
    GROUP BY CODMONEDA;

  END IF;
  COMMIT;
END;

FUNCTION Decode_TipPlata(pTipPlata NUMBER) RETURN VARCHAR2 IS
  sTipPlata VARCHAR2(100);
BEGIN
  SELECT Decode(pTipPlata, 2, &apos;Numerar&apos;, 3, &apos;Ordin Plata&apos;, 4, &apos;Cec&apos;, 5, &apos;Bilet la Ordin&apos;, 6, &apos;Compensare&apos;, 7, &apos;Majorari&apos;, &apos;...nedefinit...&apos;)
  INTO sTipPlata
  FROM DUAL;

  RETURN sTipPlata;
END;

FUNCTION Get_StocExternCamp RETURN VARCHAR2 IS
  sStocExternCamp VARCHAR2(100);
BEGIN
  sStocExternCamp := CASE pkg_categconst.GetValConstanta(&apos;StocExternCamp&apos;  ,pkg_globals.ANLUCRU,pkg_globals.lunalucru)
                       WHEN 1 THEN &apos;CODINTERN&apos;
                       WHEN 3 THEN &apos;DENUMIRE&apos;
                       WHEN 4 THEN &apos;CODOBIECT&apos;
                       ELSE &apos;CODEXTERN&apos;
                     END;

  RETURN sStocExternCamp;
END;

PROCEDURE MATCH_TVA_COMBI (p_PJTVA IN NUMBER, p_AnLuna IN NUMBER, out_CAZTVA OUT NUMBER, out_PROCTVA OUT NUMBER) IS
  NR        NUMBER;
  x_AnLuna  NUMBER;
  x_PJTVA   NUMBER := Abs(p_PJTVA);
BEGIN
  IF vAnLunaMin IS NULL THEN
    SELECT AnInitial*12+LunaInitiala INTO vAnLunaMin FROM FirmaLuni;
  END IF;
  x_AnLuna := Greatest(p_AnLuna, vAnLunaMin);

  IF x_AnLuna &lt;&gt; Coalesce(vAnLunaTVA,0) THEN
    vAnLunaTVA := x_AnLuna;
    NR         := 0;
    vPj1TVA    := 0;
    vPj2TVA    := 0;
    vPj3TVA    := 0;
    vPj4TVA    := 0;
    vPj5TVA    := 0;
    vPj6TVA    := 0;
    vPj7TVA    := 0;
    vPj8TVA    := 0;
    vPj1TIP    := 0;
    vPj2TIP    := 0;
    vPj3TIP    := 0;
    vPj4TIP    := 0;
    vPj5TIP    := 0;
    vPj6TIP    := 0;
    vPj7TIP    := 0;
    vPj8TIP    := 0;

    FOR vRec IN (
      SELECT PJ, TIP
      FROM (
        SELECT
          Coalesce(TO_NUMBER(VALOARE),0) PJ,
          CASE Upper(c1.SIMBOL)
            WHEN &apos;PROCTVAMED&apos;    THEN 1
            WHEN &apos;PROCTVAMIN&apos;    THEN 2
            WHEN &apos;PROCTVAMAX&apos;    THEN 3
            WHEN &apos;PROCTVAREG&apos;    THEN 4
            WHEN &apos;PROCTVAREG2&apos;   THEN 5
            WHEN &apos;PROCTVAREG3&apos;   THEN 6
            WHEN &apos;PROCTVAREG4&apos;   THEN 7
            WHEN &apos;PROCTVAREG5&apos;   THEN 8
            ELSE 0
          END Tip
        FROM const1 c1
          INNER JOIN constluna cl ON cl.codconst1 = c1.codconst1
          INNER JOIN constval cv ON cv.codconstluna = cl.codconstluna
        WHERE UPPER(c1.SIMBOL) IN (&apos;PROCTVAMIN&apos;,&apos;PROCTVAMED&apos;,&apos;PROCTVAMAX&apos;,&apos;PROCTVAREG&apos;,&apos;PROCTVAREG2&apos;,&apos;PROCTVAREG3&apos;,&apos;PROCTVAREG4&apos;,&apos;PROCTVAREG5&apos;)
          AND vAnLunaTVA BETWEEN CL.ALSTART AND CL.ALSTOP
          AND NOT (vAnLunaTVA &lt; 2025*12+8 AND UPPER(c1.SIMBOL) IN (&apos;PROCTVAREG3&apos;,&apos;PROCTVAREG4&apos;,&apos;PROCTVAREG5&apos;)   )
      ) sPG
      ORDER BY PJ DESC
    )
    LOOP
      NR := NR + 1;
      CASE
        WHEN NR = 1 THEN vPj1TVA := vRec.Pj; vPj1TIP := vRec.Tip;
        WHEN NR = 2 THEN vPj2TVA := vRec.Pj; vPj2TIP := vRec.Tip;
        WHEN NR = 3 THEN vPj3TVA := vRec.Pj; vPj3TIP := vRec.Tip;
        WHEN NR = 4 THEN vPj4TVA := vRec.Pj; vPj4TIP := vRec.Tip;
        WHEN NR = 5 THEN vPj5TVA := vRec.Pj; vPj5TIP := vRec.Tip;
        WHEN NR = 6 THEN vPj6TVA := vRec.Pj; vPj6TIP := vRec.Tip;
        WHEN NR = 7 THEN vPj7TVA := vRec.Pj; vPj7TIP := vRec.Tip;
        WHEN NR = 8 THEN vPj8TVA := vRec.Pj; vPj8TIP := vRec.Tip;
      END CASE;
    END LOOP;
  END IF;

  IF    Coalesce(x_PJTVA,0) = 0       THEN out_CAZTVA := 0;       out_PROCTVA := 0;
  ELSIF x_PJTVA &lt; vPj8TVA             THEN out_CAZTVA := vPj8TIP; out_PROCTVA := vPj8TVA;
  ELSIF x_PJTVA &lt; (vPj8TVA+vPj7TVA)/2 THEN out_CAZTVA := vPj8TIP; out_PROCTVA := vPj8TVA;
  ELSIF x_PJTVA &lt; (vPj7TVA+vPj6TVA)/2 THEN out_CAZTVA := vPj7TIP; out_PROCTVA := vPj7TVA;
  ELSIF x_PJTVA &lt; (vPj6TVA+vPj5TVA)/2 THEN out_CAZTVA := vPj6TIP; out_PROCTVA := vPj6TVA;
  ELSIF x_PJTVA &lt; (vPj5TVA+vPj4TVA)/2 THEN out_CAZTVA := vPj5TIP; out_PROCTVA := vPj5TVA;
  ELSIF x_PJTVA &lt; (vPj4TVA+vPj3TVA)/2 THEN out_CAZTVA := vPj4TIP; out_PROCTVA := vPj4TVA;
  ELSIF x_PJTVA &lt; (vPj3TVA+vPj2TVA)/2 THEN out_CAZTVA := vPj3TIP; out_PROCTVA := vPj3TVA;
  ELSIF x_PJTVA &lt; (vPj2TVA+vPj1TVA)/2 THEN out_CAZTVA := vPj2TIP; out_PROCTVA := vPj2TVA;
  ELSE                                     out_CAZTVA := vPj1TIP; out_PROCTVA := vPj1TVA;
  END IF;
END;

FUNCTION MATCH_TVA (p_PJTVA IN NUMBER, p_AnLuna IN NUMBER) RETURN NUMBER IS
  vCazTva  NUMBER;
  vProcTVA NUMBER;
BEGIN
  MATCH_TVA_COMBI (p_PJTVA, p_AnLuna, vCazTva, vProcTVA);
  RETURN vCazTva;
END;

FUNCTION MATCH_TVA_PROC (p_PJTVA IN NUMBER, p_AnLuna IN NUMBER) RETURN NUMBER IS
  vCazTva  NUMBER;
  vProcTVA NUMBER;
BEGIN
  MATCH_TVA_COMBI (p_PJTVA, p_AnLuna, vCazTva, vProcTVA);
  RETURN vProcTVA;
END;

FUNCTION CALC_PROC_TVA (
  p_TipDoc     IN NUMBER,
  p_An         IN NUMBER,
  p_Luna       IN NUMBER,
  p_Cant       IN NUMBER,
  p_PU         IN NUMBER,
  p_TVA        IN NUMBER,
  p_CodObiect  IN NUMBER DEFAULT  0,
  p_ProcTvaArt IN NUMBER DEFAULT -1,
  p_RotEfatc   IN NUMBER DEFAULT  0
) RETURN NUMBER IS
  vProcTVA      NUMBER;
  vAL           NUMBER := p_An * 12 + p_Luna;
  vPUIncludeTVA NUMBER := CASE WHEN p_TipDoc IN (3, 16, 21) THEN 1 ELSE 0 END;
  vProcTvaArt   NUMBER := p_ProcTvaArt;
  vCant         NUMBER := Coalesce(p_Cant,0);
  vPU           NUMBER := Coalesce(p_PU,  0);
  vTVA          NUMBER := Coalesce(p_TVA, 0);
  vVal          NUMBER := CASE p_RotEfatc WHEN 1 THEN Round(vCant*vPU,2) ELSE vCant*vPU END;
BEGIN
  vProcTvaArt := Coalesce(p_ProcTvaArt, -1);

  IF vProcTvaArt = -1 AND Coalesce(p_CodObiect, 0) &gt; 0 THEN
    SELECT T1.PROCENT INTO vProcTvaArt
    FROM nartobj o
      LEFT JOIN nart1 a1 ON a1.codarticol = o.codarticol AND vAL BETWEEN a1.alstart AND a1.alstop
      LEFT JOIN ntva1 t1 ON t1.codtva     = a1.codtva    AND vAL BETWEEN t1.alstart AND t1.alstop
    WHERE o.CodObiect = p_CodObiect;
  END IF;

  IF vTva = 0 AND vVal &lt;&gt; 0 THEN
    vProcTVA := 0;
  ELSIF p_ProcTvaArt = -1 THEN
    vProcTVA := CASE
                  WHEN                    vPUIncludeTVA = 1 AND vVal=vTva                                           THEN 0
                  WHEN                    vPUIncludeTVA = 1                                                         THEN 100*vTVA/(vVal-vTva)
                  WHEN                                          vVal = 0                                            THEN 0
                  ELSE                                                                                                   100*vTVA/vVal
                END;
  ELSIF Abs(vVal) &lt; 1 THEN
    vProcTVA := vProcTvaArt;
  ELSE
    vProcTVA := CASE
                  WHEN p_RotEfatc = 1 AND vPUIncludeTVA = 1 AND vTVA = Round(vVal*vProcTvaArt/(100+vProcTvaArt), 2) THEN vProcTvaArt
                  WHEN p_RotEfatc = 1 AND                       vTVA = Round(vVal*vProcTvaArt/100              , 2) THEN vProcTvaArt
                  WHEN vVal = 0       AND                       vTVA = 0                                            THEN vProcTvaArt
                  WHEN                    vPUIncludeTVA = 1 AND vTVA = Round(vVal*vProcTvaArt/(100+vProcTvaArt), 7) THEN vProcTvaArt
                  WHEN                                          vTVA = Round(vVal*vProcTvaArt/100              , 7) THEN vProcTvaArt
                  WHEN                    vPUIncludeTVA = 1 AND vTVA = vVal                                         THEN vProcTvaArt
                  WHEN                    vPUIncludeTVA = 1                                                         THEN 100*vTVA/(vVal-vTva)
                  WHEN                                          vVal = 0                                            THEN vProcTvaArt
                  ELSE                                                                                                   100*vTVA/vVal
                END;
  END IF;
  RETURN vProcTVA;
END;

FUNCTION CALC_MATCH_TVA (
  p_TipDoc     IN NUMBER,
  p_An         IN NUMBER,
  p_Luna       IN NUMBER,
  p_Cant       IN NUMBER,
  p_PU         IN NUMBER,
  p_TVA        IN NUMBER,
  p_CodObiect  IN NUMBER DEFAULT  0,
  p_ProcTvaArt IN NUMBER DEFAULT -1,
  p_RotEfatc   IN NUMBER DEFAULT  0,
  p_ReturnProc IN NUMBER DEFAULT  1
) RETURN NUMBER IS
  vAL           NUMBER := p_An * 12 + p_Luna;
  vProcTVA      NUMBER := PKG_LIST_BASE_UTILS.CALC_PROC_TVA(p_TipDoc, p_An, p_Luna, p_Cant, p_PU, p_TVA, p_CodObiect, p_ProcTvaArt, p_RotEfatc);
  rezCazTva     NUMBER;
  rezProcTVA    NUMBER;
BEGIN
  MATCH_TVA_COMBI (vProcTVA, vAL, rezCazTva, rezProcTVA);

  IF p_ReturnProc = 1
  THEN RETURN rezProcTVA;
  ELSE RETURN rezCazTva ;
  END IF;
END;

function GetFirstNS(aCodNirStoc in number, aAnLuna in number) return number is
vAnLuna number;
vNextCod number;
vCodOrig number;
begin
  begin
    select codluna into vNextCod from tmp_nirstoc1_man where codnirstoc = aCodNirStoc;
  exception when others then vNextCod := 0;
  end;

  if vNextCod = 0 then
    begin
      select codnirstocorig into vCodOrig from nirstoc1 where codnirstoc = aCodNirStoc;
    exception when others then vNextCod := aCodNirStoc;
    end;
    if vCodOrig &gt; 0 then
      insert into tmp_nirstoc1_man(codnirstoc,
                                   codnirstocorig,
                                   an,
                                   luna,
                                   codluna)
      select ns1.codnirstoc, vNextCod, coalesce(i.an, t.an, intr.an), coalesce(i.luna, t.luna, intr.luna), min(ns1.codnirstoc)
      from nirstoc1 ns1
           inner join nirstoc ns on ns.codnirstoc = ns1.codnirstoc
           inner join nir on nir.codnir = ns.codnir
           left join iesiri i on i.codies = nir.codies
           left join transf t on t.codtransf = nir.codtransf
           left join intrari intr on intr.codintr = nir.codintr
      where ns1.codnirstocorig = vCodOrig
      group by ns1.codnirstoc, coalesce(i.an, t.an, intr.an), coalesce(i.luna, t.luna, intr.luna);
    end if;
    begin
      select codluna into vNextCod from tmp_nirstoc1_man where codnirstoc = aCodNirStoc;
    exception when others then vNextCod := aCodNirStoc;
    end;
  end if;
  Return aCodNirStoc;
end;

FUNCTION GetCodArtCli(pCodObiect IN NUMBER, pCodPart IN NUMBER, pCodClaseP IN NUMBER) RETURN NUMBER IS
  vRes NUMBER;
BEGIN
  vRes := 0;
  IF Coalesce(pCodObiect,0) &lt;&gt; 0 AND Coalesce(pCodPart,0) &lt;&gt; 0 THEN
    SELECT Coalesce(Min(CodArtCli),0)
    INTO vRes
    FROM nartcli
    WHERE codobiect = pCodObiect AND codpart = pCodPart;
  END IF;

  IF Coalesce(pCodObiect,0) &lt;&gt; 0 AND Coalesce(pCodClaseP,0) &lt;&gt; 0 AND vRes = 0 THEN
    SELECT Coalesce(Min(CodArtCli),0)
    INTO vRes
    FROM nartcli
    WHERE codobiect = pCodObiect AND codclasep = pCodClaseP;
  END IF;

  RETURN vRes;
END;

FUNCTION GetCoefDiscMonetar(
  pCodIes IN NUMBER, pTipLinie IN VARCHAR2, pCodObiect IN NUMBER, pContServ IN NUMBER, pCodIOArt IN NUMBER, pTipCoef IN NUMBER,
  pValLin IN NUMBER DEFAULT 0, pTVALin IN NUMBER DEFAULT 0
) RETURN NUMBER IS
  vRes     NUMBER;
  vAn      NUMBER;
  vLuna    NUMBER;
  vAVD     NUMBER;
  vATD     NUMBER;
  vProcTva NUMBER;
BEGIN
  vRes := 1;

  IF Coalesce(vCDMCodIes,0) &lt;&gt; Coalesce(pCodIes,0) THEN
    SELECT Count(1) INTO vCDMCoteDisc
    FROM discmonetar
    WHERE codies = pCodIes;

    SELECT
      Sum(Coalesce(i1.valdiscpret,0)),
      Sum(CASE WHEN Coalesce(i1.pu*i1.cant,0) = 0 THEN 0 ELSE Coalesce(i1.tva * i1.valdiscpret/(i1.pu*i1.cant),0) END)
    INTO
      vAVD,
      vATD
    FROM iesiri1 i1
    WHERE i1.codies = pCodIes;

    SELECT
      i.CodIes, i.An, i.Luna, i.ValDoc, i.TvaDoc,
      Round(i.ValDiscount - vAVD,7),
      Round(i.TvaDiscount - vATD,7)
    INTO
      vCDMCodIes, vAn, vLuna, vCDMValDoc, vCDMTvaDoc,
      vCDMValDisc,
      vCDMTvaDisc
    FROM iesiri i
    WHERE codies = pCodIes;

    IF Coalesce(vCDMAn,0) &lt;&gt; vAn OR Coalesce(vCDMLuna,0) &lt;&gt; vLuna THEN
      pkg_globals.SetSeparator(&apos;,&apos;);
      SELECT STRING_AGG(x) INTO sCDMArtExcl
      FROM (
        --SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasImediat&apos;,vAn,vLuna),&apos;0&apos;) x FROM dual UNION
        SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtFaraDiscMonetar&apos;,vAn,vLuna),&apos;0&apos;) x FROM dual UNION
        SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasUlterior&apos;  ,vAn,vLuna),&apos;0&apos;) x FROM dual
      );
      sCDMArtExcl := &apos;,&apos;||sCDMArtExcl||&apos;,&apos;;

      vCDMCIntermedCM := Coalesce(pkg_categconst.GetValConstanta(&apos;CIntermedCM&apos;        ,vAn,vLuna),&apos;0&apos;);
      vCDMConIncFact  := Coalesce(pkg_categconst.GetValConstanta(&apos;ContIncasareFactura&apos;,vAn,vLuna),&apos;0&apos;);
      vCDMAn          := vAn;
      vCDMLuna        := vLuna;
    END IF;

    SELECT SUM(i1.pu*i1.cant) ValLin, SUM(i1.tva) TvaLin
    INTO   vCDMValLin               , vCDMTvaLin
    FROM iesiri1 i1
    WHERE i1.codies = pCodIes
      AND i1.tiplinie &lt;&gt; &apos;V&apos;
      AND Coalesce(i1.ContServ,-1) &lt;&gt; vCDMCIntermedCM
      --AND Coalesce(L1.CodIoart,-1) &lt;&gt; vCDMConIncFact
      AND InStr(sCDMArtExcl, &apos;,&apos;||i1.CodObiect||&apos;,&apos;) = 0
      AND Coalesce(i1.valdiscpret, 0) = 0;

    vCDMProc1 := 0; vCDMValDisc1 := 0; vCDMTvaDisc1 := 0; vCDMValLin1 := 0; vCDMTvaLin1 := 0;
    vCDMProc2 := 0; vCDMValDisc2 := 0; vCDMTvaDisc2 := 0; vCDMValLin2 := 0; vCDMTvaLin2 := 0;
    vCDMProc3 := 0; vCDMValDisc3 := 0; vCDMTvaDisc3 := 0; vCDMValLin3 := 0; vCDMTvaLin3 := 0;
    vCDMProc4 := 0; vCDMValDisc4 := 0; vCDMTvaDisc4 := 0; vCDMValLin4 := 0; vCDMTvaLin4 := 0;
    vCDMProc5 := 0; vCDMValDisc5 := 0; vCDMTvaDisc5 := 0; vCDMValLin5 := 0; vCDMTvaLin5 := 0;
    vCDMProc6 := 0; vCDMValDisc6 := 0; vCDMTvaDisc6 := 0; vCDMValLin6 := 0; vCDMTvaLin6 := 0;
    vCDMProc7 := 0; vCDMValDisc7 := 0; vCDMTvaDisc7 := 0; vCDMValLin7 := 0; vCDMTvaLin7 := 0;
    vCDMProc8 := 0; vCDMValDisc8 := 0; vCDMTvaDisc8 := 0; vCDMValLin8 := 0; vCDMTvaLin8 := 0;

    IF vCDMCoteDisc &gt; 0 THEN
      vCDMNr := 0;
      FOR vRec IN (
        SELECT
          gm.ProcTVA, gm.ValLin, gm.TvaLin,
          Round(dm.Discount    - gm.AVD,7) ValDisc,
          Round(dm.TvaDiscount - gm.ATD,7) TvaDisc
        FROM (
          SELECT ProcTVA, SUM(ValLin) ValLin, SUM(TvaLin) TvaLin, Sum(AVD) AVD, Sum(ATD) ATD
          FROM (
            SELECT
              PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(i1.tva*100/(i1.cant*i1.pu-i1.tva), vAn*12+vLuna) ProcTVA,
              CASE WHEN Coalesce(i1.valdiscpret, 0) = 0 THEN i1.pu*i1.cant ELSE 0 END ValLin,
              CASE WHEN Coalesce(i1.valdiscpret, 0) = 0 THEN i1.tva        ELSE 0 END TvaLin,
              Coalesce(i1.valdiscpret,0) AVD,
              CASE WHEN Coalesce(i1.pu*i1.cant,0) = 0 THEN 0 ELSE Coalesce(i1.tva * i1.valdiscpret/(i1.pu*i1.cant),0) END ATD
            FROM iesiri1 i1
            WHERE i1.codies = pCodIes
              AND i1.tiplinie &lt;&gt; &apos;V&apos;
              AND Coalesce(i1.ContServ,-1) &lt;&gt; vCDMCIntermedCM
              AND InStr(sCDMArtExcl, &apos;,&apos;||i1.CodObiect||&apos;,&apos;) = 0
              AND Coalesce(i1.cant*i1.pu, 0) &lt;&gt; Coalesce(i1.tva, 0)
          ) ssub
          GROUP BY ProcTVA
        ) gm
        INNER JOIN (
          SELECT DM.PROCTVA, DM.DISCOUNT, DM.TVADISCOUNT
          FROM DISCMONETAR DM
          WHERE DM.codies = pCodIes
        ) dm ON DM.ProcTVA = GM.ProcTVA
        ORDER BY gm.ProcTVA
      ) LOOP
        vCDMNr := vCDMNr + 1;
        CASE vCDMNr
          WHEN 1 THEN vCDMProc1 := vRec.ProcTVA; vCDMValDisc1 := vRec.ValDisc; vCDMTvaDisc1 := vRec.TvaDisc; vCDMValLin1 := vRec.ValLin; vCDMTvaLin1 := vRec.TvaLin;
          WHEN 2 THEN vCDMProc2 := vRec.ProcTVA; vCDMValDisc2 := vRec.ValDisc; vCDMTvaDisc2 := vRec.TvaDisc; vCDMValLin2 := vRec.ValLin; vCDMTvaLin2 := vRec.TvaLin;
          WHEN 3 THEN vCDMProc3 := vRec.ProcTVA; vCDMValDisc3 := vRec.ValDisc; vCDMTvaDisc3 := vRec.TvaDisc; vCDMValLin3 := vRec.ValLin; vCDMTvaLin3 := vRec.TvaLin;
          WHEN 4 THEN vCDMProc4 := vRec.ProcTVA; vCDMValDisc4 := vRec.ValDisc; vCDMTvaDisc4 := vRec.TvaDisc; vCDMValLin4 := vRec.ValLin; vCDMTvaLin4 := vRec.TvaLin;
          WHEN 5 THEN vCDMProc5 := vRec.ProcTVA; vCDMValDisc5 := vRec.ValDisc; vCDMTvaDisc5 := vRec.TvaDisc; vCDMValLin5 := vRec.ValLin; vCDMTvaLin5 := vRec.TvaLin;
          WHEN 6 THEN vCDMProc6 := vRec.ProcTVA; vCDMValDisc6 := vRec.ValDisc; vCDMTvaDisc6 := vRec.TvaDisc; vCDMValLin6 := vRec.ValLin; vCDMTvaLin6 := vRec.TvaLin;
          WHEN 7 THEN vCDMProc7 := vRec.ProcTVA; vCDMValDisc7 := vRec.ValDisc; vCDMTvaDisc7 := vRec.TvaDisc; vCDMValLin7 := vRec.ValLin; vCDMTvaLin7 := vRec.TvaLin;
          WHEN 8 THEN vCDMProc8 := vRec.ProcTVA; vCDMValDisc8 := vRec.ValDisc; vCDMTvaDisc8 := vRec.TvaDisc; vCDMValLin8 := vRec.ValLin; vCDMTvaLin8 := vRec.TvaLin;
        END CASE;
      END LOOP;
    END IF;
  END IF;

  vProcTva := 0;
  IF (Coalesce(pValLin, 0) &lt;&gt; 0) AND (Coalesce(pTVALin, 0) &lt;&gt; 0) AND (Coalesce(pValLin, 0) - Coalesce(pTVALin, 0) &lt;&gt; 0) THEN
    vProcTva := PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(pTVALin*100/(pValLin-pTVALin), vCDMAn*12+vCDMLuna);
  END IF;

  vRes :=
    CASE
      WHEN vCDMValDisc = 0 AND vCDMTvaDisc = 0                                      THEN 1
      WHEN pTipLinie   = &apos;V&apos;                                                        THEN 1
      WHEN pContServ   = vCDMCIntermedCM                                            THEN 1
      WHEN pCodIOArt   = vCDMConIncFact                                             THEN 1
      WHEN InStr(sCDMArtExcl, &apos;,&apos;||pCodObiect||&apos;,&apos;) &gt; 0                             THEN 1
      -- pTipCoef = 0 -- pret/val unitar incl.TVA
      WHEN pTipCoef = 0                          AND (vCDMValLin )  = 0             THEN 1
      WHEN pTipCoef = 0 AND vCDMCoteDisc = 0     AND (vCDMValLin ) &lt;&gt; 0             THEN 1 + vCDMValDisc/vCDMValLin

      WHEN pTipCoef = 0 AND vCDMProc1 = vProcTva AND (vCDMValLin1) &lt;&gt; 0             THEN 1 + vCDMValDisc1/vCDMValLin1
      WHEN pTipCoef = 0 AND vCDMProc2 = vProcTva AND (vCDMValLin2) &lt;&gt; 0             THEN 1 + vCDMValDisc2/vCDMValLin2
      WHEN pTipCoef = 0 AND vCDMProc3 = vProcTva AND (vCDMValLin3) &lt;&gt; 0             THEN 1 + vCDMValDisc3/vCDMValLin3
      WHEN pTipCoef = 0 AND vCDMProc4 = vProcTva AND (vCDMValLin4) &lt;&gt; 0             THEN 1 + vCDMValDisc4/vCDMValLin4
      WHEN pTipCoef = 0 AND vCDMProc5 = vProcTva AND (vCDMValLin5) &lt;&gt; 0             THEN 1 + vCDMValDisc5/vCDMValLin5
      WHEN pTipCoef = 0 AND vCDMProc6 = vProcTva AND (vCDMValLin6) &lt;&gt; 0             THEN 1 + vCDMValDisc6/vCDMValLin6
      WHEN pTipCoef = 0 AND vCDMProc7 = vProcTva AND (vCDMValLin7) &lt;&gt; 0             THEN 1 + vCDMValDisc7/vCDMValLin7
      WHEN pTipCoef = 0 AND vCDMProc8 = vProcTva AND (vCDMValLin8) &lt;&gt; 0             THEN 1 + vCDMValDisc8/vCDMValLin8

      -- pTipCoef = 1 -- pret/unitar excl.TVA
      WHEN pTipCoef = 1                          AND (vCDMValLin -vCDMTvaLin )  = 0 THEN 1
      WHEN pTipCoef = 1 AND vCDMCoteDisc = 0     AND (vCDMValLin -vCDMTvaLin ) &lt;&gt; 0 THEN 1 + (vCDMValDisc - vCDMTvaDisc)/(vCDMValLin-vCDMTvaLin)

      WHEN pTipCoef = 1 AND vCDMProc1 = vProcTva AND (vCDMValLin1-vCDMTvaLin1) &lt;&gt; 0 THEN 1 + (vCDMValDisc1 - vCDMTvaDisc1)/(vCDMValLin1-vCDMTvaLin1)
      WHEN pTipCoef = 1 AND vCDMProc2 = vProcTva AND (vCDMValLin2-vCDMTvaLin2) &lt;&gt; 0 THEN 1 + (vCDMValDisc2 - vCDMTvaDisc2)/(vCDMValLin2-vCDMTvaLin2)
      WHEN pTipCoef = 1 AND vCDMProc3 = vProcTva AND (vCDMValLin3-vCDMTvaLin3) &lt;&gt; 0 THEN 1 + (vCDMValDisc3 - vCDMTvaDisc3)/(vCDMValLin3-vCDMTvaLin3)
      WHEN pTipCoef = 1 AND vCDMProc4 = vProcTva AND (vCDMValLin4-vCDMTvaLin4) &lt;&gt; 0 THEN 1 + (vCDMValDisc4 - vCDMTvaDisc4)/(vCDMValLin4-vCDMTvaLin4)
      WHEN pTipCoef = 1 AND vCDMProc5 = vProcTva AND (vCDMValLin5-vCDMTvaLin5) &lt;&gt; 0 THEN 1 + (vCDMValDisc5 - vCDMTvaDisc5)/(vCDMValLin5-vCDMTvaLin5)
      WHEN pTipCoef = 1 AND vCDMProc6 = vProcTva AND (vCDMValLin6-vCDMTvaLin6) &lt;&gt; 0 THEN 1 + (vCDMValDisc6 - vCDMTvaDisc6)/(vCDMValLin6-vCDMTvaLin6)
      WHEN pTipCoef = 1 AND vCDMProc7 = vProcTva AND (vCDMValLin7-vCDMTvaLin7) &lt;&gt; 0 THEN 1 + (vCDMValDisc7 - vCDMTvaDisc7)/(vCDMValLin7-vCDMTvaLin7)
      WHEN pTipCoef = 1 AND vCDMProc8 = vProcTva AND (vCDMValLin8-vCDMTvaLin8) &lt;&gt; 0 THEN 1 + (vCDMValDisc8 - vCDMTvaDisc8)/(vCDMValLin8-vCDMTvaLin8)

      -- pTipCoef = 2 -- TVA
      WHEN pTipCoef = 2 AND vCDMTvaLin = 0                                          THEN 1
      WHEN pTipCoef = 2 AND vCDMCoteDisc = 0     AND  (vCDMValLin) &lt;&gt; 0             THEN 1 + vCDMTvaDisc/vCDMTvaLin

      WHEN pTipCoef = 2 AND vCDMProc1 = vProcTva AND  (vCDMTvaLin1) &lt;&gt; 0            THEN 1 + vCDMTvaDisc1/vCDMTvaLin1
      WHEN pTipCoef = 2 AND vCDMProc2 = vProcTva AND  (vCDMTvaLin2) &lt;&gt; 0            THEN 1 + vCDMTvaDisc2/vCDMTvaLin2
      WHEN pTipCoef = 2 AND vCDMProc3 = vProcTva AND  (vCDMTvaLin3) &lt;&gt; 0            THEN 1 + vCDMTvaDisc3/vCDMTvaLin3
      WHEN pTipCoef = 2 AND vCDMProc4 = vProcTva AND  (vCDMTvaLin4) &lt;&gt; 0            THEN 1 + vCDMTvaDisc4/vCDMTvaLin4
      WHEN pTipCoef = 2 AND vCDMProc5 = vProcTva AND  (vCDMTvaLin5) &lt;&gt; 0            THEN 1 + vCDMTvaDisc5/vCDMTvaLin5
      WHEN pTipCoef = 2 AND vCDMProc6 = vProcTva AND  (vCDMTvaLin6) &lt;&gt; 0            THEN 1 + vCDMTvaDisc6/vCDMTvaLin6
      WHEN pTipCoef = 2 AND vCDMProc7 = vProcTva AND  (vCDMTvaLin7) &lt;&gt; 0            THEN 1 + vCDMTvaDisc7/vCDMTvaLin7
      WHEN pTipCoef = 2 AND vCDMProc8 = vProcTva AND  (vCDMTvaLin8) &lt;&gt; 0            THEN 1 + vCDMTvaDisc8/vCDMTvaLin8

      ELSE 1
    END;

  RETURN vRes;
END;

FUNCTION getStinsOblig(pCodObligPif IN NUMBER) RETURN NUMBER IS
  vTrezor  NUMBER;
  vCEC     NUMBER;
  vCompens NUMBER;
  vLitig   NUMBER;
BEGIN
  SELECT Coalesce(SUM(O_STINGATOR.VALOARE*CASE WHEN G_STINGATOR.CURS IS NULL THEN 1 WHEN G_STINGATOR.CURS = 0 THEN 1 ELSE G_STINGATOR.CURS END),0)
  INTO vTrezor
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0;
    --AND T1.AN * 12 + T1.LUNA &lt; pAL;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE*CASE WHEN G_STINGATOR.CURS IS NULL THEN 1 WHEN G_STINGATOR.CURS = 0 THEN 1 ELSE G_STINGATOR.CURS END),0)
  INTO vCEC
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN GENERAL G_CEC ON G_CEC.TIPDOC = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600)
    INNER JOIN OBLIGPIF O_CEC ON O_CEC.CODGENERAL = G_CEC.CODGENERAL
    INNER JOIN STINGERE S_CEC ON S_CEC.CODSTINSPIF = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT ON O_CURENT.CODOBLIGPIF = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL G_CURENT ON G_CURENT.CODGENERAL = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN TREZOR1 T1_CURENT ON T1_CURENT.CODTREZOR1 = G_CURENT.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0;
    --AND T1.AN * 12 + T1.LUNA &lt; pAL
    --AND T1_CURENT.AN * 12 + T1_CURENT.LUNA &lt; pAL;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE*CASE WHEN G_STINGATOR.CURS IS NULL THEN 1 WHEN G_STINGATOR.CURS = 0 THEN 1 ELSE G_STINGATOR.CURS END),0)
  INTO vCompens
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
    INNER JOIN COMPENS C ON C.CODCOMPENS = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif;
    --AND C.AN * 12 + C.LUNA &lt; pAL;

  vLitig := 0;
  FOR lREC IN (
    SELECT OL.CodObligPif, OL.VALOARE
    FROM OBLIGPIF OL
      INNER JOIN GENERAL GL ON GL.CODGENERAL = OL.CODGENERAL
      INNER JOIN COMPENS CL ON CL.CODCOMPENS = GL.CODDOC
    WHERE OL.CODOBLIGASOCIAT = pCodObligPif
      AND OL.SEMNIFICATIE = 1303
      --AND CL.AN * 12 + CL.LUNA &lt; pAL
  ) LOOP
    vLitig := vLitig + lREC.VALOARE;
    vLitig := vLitig - PKG_LIST_BASE_UTILS.getStinsOblig(lREC.CodObligPif);
  END LOOP;

  RETURN vTrezor + vCEC + vCompens - vLitig;
END;


FUNCTION PondereComanda(pCodIes IN NUMBER, pCodComanda IN NUMBER) RETURN NUMBER IS
  vTipIes  NUMBER;
  vPondere NUMBER;
BEGIN
  vPondere := 0;
  SELECT TipDoc INTO vTipIes FROM iesiri WHERE codies = pCodIes;

  IF vTipIes = 26 THEN
    SELECT Sum(CASE WHEN codcomanda = pCodComanda THEN VLIN ELSE 0 END) / Sum(VLIN)
    INTO vPondere
    FROM (
      SELECT Coalesce(c1.codcomanda, 0) codcomanda,
             CASE
               WHEN I1.PU = 0 THEN
                0
               ELSE
                (I1.PU * I1.CANT + I1.TVA) * I1.PRETORIG *
                DECODE(I1.COEFDISCMAJ, 0, 1, NULL, 1, I1.COEFDISCMAJ) /
                I1.PU
             END VLIN
      FROM iesiri1 i1
        LEFT JOIN ieslink ila ON ila.codies1 = i1.codies1
        LEFT JOIN ieslink ilc ON ilc.codies1 = ila.codlinieaviz
        LEFT JOIN comanda1 c1 ON c1.codcomanda1 = ilc.codliniecomanda
      WHERE i1.codies = pCodIes
    ) WHERE VLIN &lt;&gt; 0;
  ELSE
    SELECT Sum(CASE WHEN codcomanda = pCodComanda THEN VLIN ELSE 0 END) / Sum(VLIN)
    INTO vPondere
    FROM (
      SELECT Coalesce(c1.codcomanda, 0) codcomanda,
             CASE
               WHEN I1.PU = 0 THEN
                0
               ELSE
                (I1.PU * I1.CANT + CASE
                  WHEN vTipIes IN (16, 21) THEN
                   0
                  ELSE
                   I1.TVA
                END) * I1.PRETORIG *
                DECODE(I1.COEFDISCMAJ, 0, 1, NULL, 1, I1.COEFDISCMAJ) /
                I1.PU
             END VLIN
      FROM iesiri1 i1
        LEFT JOIN ieslink ilc ON ilc.codies1 = i1.codies1
        LEFT JOIN comanda1 c1 ON c1.codcomanda1 = ilc.codliniecomanda
      WHERE i1.codies = pCodIes
    ) WHERE VLIN &lt;&gt; 0;
  END IF;

  RETURN vPondere;
END;

FUNCTION getStinsObligMoneda(pCodObligPif IN NUMBER) RETURN NUMBER IS
  vTrezor  NUMBER;
  vCEC     NUMBER;
  vCompens NUMBER;
  vLitig   NUMBER;
BEGIN
  SELECT Coalesce(SUM(case when O_STINGATOR.semnificatie in (320,420) then -1 else 1 end * O_STINGATOR.VALOARE),0)
  INTO vTrezor
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC IN (29, 30, 33)
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE),0)
  INTO vCEC
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 31
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G_STINGATOR.CODDOC
    INNER JOIN GENERAL G_CEC ON G_CEC.TIPDOC = 31 AND G_CEC.CODDOC = G_STINGATOR.CODDOC AND G_CEC.SEMNIFICATIE IN (500,600)
    INNER JOIN OBLIGPIF O_CEC ON O_CEC.CODGENERAL = G_CEC.CODGENERAL
    INNER JOIN STINGERE S_CEC ON S_CEC.CODSTINSPIF = O_CEC.CODOBLIGPIF
    INNER JOIN OBLIGPIF O_CURENT ON O_CURENT.CODOBLIGPIF = S_CEC.CODSTINGATORPIF
    INNER JOIN GENERAL G_CURENT ON G_CURENT.CODGENERAL = O_CURENT.CODGENERAL AND G_CURENT.TIPDOC = 30
    INNER JOIN TREZOR1 T1_CURENT ON T1_CURENT.CODTREZOR1 = G_CURENT.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif AND Coalesce(T1.ANULAT, 0) = 0;

  SELECT Coalesce(SUM(O_STINGATOR.VALOARE),0)
  INTO vCompens
  FROM STINGERE S
    INNER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    INNER JOIN GENERAL  G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL AND G_STINGATOR.TIPDOC = 28
    INNER JOIN COMPENS C ON C.CODCOMPENS = G_STINGATOR.CODDOC
  WHERE S.CODSTINSPIF = pCodObligPif;

  RETURN vTrezor + vCEC + vCompens;
END;

FUNCTION getStinsIes(pCodIes IN NUMBER, pCodComanda IN NUMBER DEFAULT NULL) RETURN NUMBER IS
  vStins   NUMBER;
BEGIN
  vStins := 0;
  FOR cREC IN (
    SELECT Coalesce(I.TipFactura,0) TipFactura, Coalesce(I.ValDoc,0) Valdoc, O.CodObligPif, I.TipDoc
    FROM IESIRI I
      INNER JOIN GENERAL G ON G.CODDOC = I.CODIES AND G.TIPDOC = I.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE I.CODIES = pCodIes
  ) LOOP
    IF cRec.TipFactura = 7
    THEN vStins := cRec.ValDoc;
    ELSE vStins := vStins + PKG_LIST_BASE_UTILS.getStinsObligMoneda(cREC.CodObligPif);
    END IF;
  END LOOP;

  IF Coalesce(pCodComanda,0) &gt; 0 AND vStins &lt;&gt; 0 THEN
    vStins := vStins * PondereComanda(pCodIes, pCodComanda);
  END IF;

  FOR cREC IN (
    SELECT C1.CodComanda, Sum(I1.Cant*I1.PU) ValDoc
    FROM IESIRI1 I1
      INNER JOIN IESLINK L ON L.CODIES1 = I1.CODIES1
      INNER JOIN IESIRI I ON I.CODIES=I1.CODIES
      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODLINIECOMANDA
    WHERE I.TIPDOC = 16 and I1.CODIES = pCodIes AND C1.CodComanda = pCodComanda group by C1.CodComanda
  ) LOOP
     vStins := cRec.ValDoc;
  END LOOP;

  RETURN vStins;
END;

FUNCTION getTipTVA0 (pCodObiect IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER IS
  iResult    NUMBER(1) := 0;
  aTvaObj    NUMBER(20);
  sCodObiect VARCHAR2(20);
  vArtNeimp  NUMBER;
  --0 = cu deducere ; 1 = fara deducere ; 2 = neimpozabil
BEGIN
  vTT0_CodObiect := Coalesce(vTT0_CodObiect,      0);
  vTT0_AL        := Coalesce(vTT0_AL,             0);

  IF vTT0_CodObiect = pCodObiect AND vTT0_AL = pAn*12+pLuna THEN
    iResult := vTT0_Res;
  ELSE
    iResult := 0;
    sCodObiect := pCodObiect;

    IF vTT0_AL &lt;&gt; pAn*12+pLuna THEN
      SELECT Count(1)
      INTO   vTT0_CntJVARTNEIMP
      FROM CONST1 C1
        INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        INNER JOIN CONSTVAL CV ON cv.codconstluna = cl.codconstluna
      WHERE UPPER(C1.simbol) = &apos;JVARTNEIMP&apos; AND pAn*12+pLuna BETWEEN CL.ALSTART AND CL.ALSTOP;

      vTT0_TVA0FaraDed := pkg_categconst.GetValConstanta(&apos;TVA0FaraDed&apos;,pAn,pLuna);
    END IF;

    IF vTT0_CntJVARTNEIMP &gt; 0 THEN
      SELECT Count(1)
      INTO   vArtNeimp
      FROM CONST1 C1
        INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        INNER JOIN CONSTVAL CV ON cv.codconstluna = cl.codconstluna
      WHERE UPPER(C1.simbol) = &apos;JVARTNEIMP&apos; AND pAn*12+pLuna BETWEEN CL.ALSTART AND CL.ALSTOP
        AND CV.VALOARE = sCodObiect;

      IF vArtNeimp &gt; 0 THEN
        iResult := 2;
      END IF;
    END IF;

    IF iResult = 0 THEN
      BEGIN
		    SELECT t.codtva INTO aTVAObj
		    FROM (
          SELECT codarticol
          FROM nartobj nobj
          WHERE nobj.codobiect = pCodObiect  AND rownum  &lt;= 1
        ) obj
			    INNER JOIN nart1 n1 ON n1.codarticol = obj.codarticol AND pAn*12+pLuna BETWEEN n1.ALSTART AND n1.ALSTOP
			    INNER JOIN ntva t ON t.codtva = n1.codtva;

        IF aTvaObj = vTT0_TVA0FaraDed
        THEN iResult := 1;
        END IF;
      EXCEPTION
        WHEN OTHERS THEN NULL;
	    END;

    END IF;
  END IF;
  vTT0_Res       := iResult;
  vTT0_CodObiect := pCodObiect;
  vTT0_AL        := pAn*12+pLuna;

  RETURN iResult;
END;

FUNCTION isGreenTax (pCodObiect IN NUMBER, pTipLinie IN VARCHAR2, pAn IN NUMBER, pLuna IN NUMBER) RETURN NUMBER IS
  iResult NUMBER( 1) := 0;
  vCount  NUMBER(10) := 0;
  vAL     NUMBER(10) := pAn*12+pLuna;
BEGIN
  iResult := 0;

  IF pTipLinie = &apos;S&apos; THEN
    SELECT count(1) INTO vCount
    FROM ntaxe1 t1
    WHERE t1.codservfact = pCodObiect AND vAL BETWEEN t1.ALSTART AND t1.ALSTOP;

    iResult := CASE vCount WHEN 0 THEN 0 ELSE 1 END;
  END IF;

  RETURN iResult;
END;

function GetPretMediu(aCodObiect in number) return number is
PMed number(20,7);
begin
  begin
    select sum(cant*pret)/sum(cant) into PMed
    from
    (
    select ns.cantnir cant,ns.pret
    from nirstoc ns
          inner join intrari1 ii1 on ii1.codintr1 = ns.codintr1
          inner join intrari ii on ii.codintr = ii1.codintr
          inner join nir on ns.codnir = nir.codnir and ii.codintr = nir.codintr and nir.TIPNIR = ii.tipdoc
    where ii.tipdoc in (1,2,3,4,7) and ns.codobiect = acodobiect and ns.rest &gt; 0
    union all
    select ns.cantnir cant,ns.pret
    from nirstoc ns
         inner join dvi1 dvi1 on dvi1.coddvi1 = ns.coddvi1
         inner join dvi on dvi.coddvi = dvi1.coddvi
         inner join intrari1 ii1 on dvi1.codintr1 = ii1.codintr1
         inner join intrari ii on ii1.codintr = ii.codintr and dvi.codintr = ii.codintr
         inner join nir on ns.codnir = nir.codnir and ii.codintr = nir.codintr and nir.TIPNIR = ii.tipdoc
    where ii.tipdoc = 5 and ns.codobiect = acodobiect and ns.rest &gt; 0
    );
  exception when others then PMed := 0;
  end;
  return PMed;
end;

function GetCursMediu(aCodObiect in number) return number is
aCurs number(20,7);
begin
  begin
    select avg(curs) into aCurs
    from (
      select ii.curs
      from nirstoc ns
           inner join intrari1 ii1 on ii1.codintr1 = ns.codintr1
           inner join intrari ii on ii.codintr = ii1.codintr
           inner join nir on ns.codnir = nir.codnir and ii.codintr = nir.codintr and nir.tipnir = ii.tipdoc
      where ii.tipdoc in (1,2,3,4,7) and ns.codobiect = acodobiect and ns.rest &gt; 0
      union all
      select ii.curs
      from nirstoc ns
           inner join dvi1 dvi1 on dvi1.coddvi1 = ns.coddvi1
           inner join dvi on dvi.coddvi = dvi1.coddvi
           inner join intrari1 ii1 on dvi1.codintr1 = ii1.codintr1
           inner join intrari ii on ii1.codintr = ii.codintr and dvi.codintr = ii.codintr
           inner join nir on ns.codnir = nir.codnir and ii.codintr = nir.codintr and nir.TIPNIR = ii.tipdoc
      where ii.tipdoc = 5 and ns.codobiect = acodobiect and ns.rest &gt; 0
    );
  exception when others then aCurs := 0;
  end;
  return aCurs;
end;

function GETLUNADINSAPTAMANA(aSet in number, aAn in number) return number is
aAnI number(4);
aLuna number(2);
begin
  aAnI := extract (month from iso_week_to_date(aAn, aSet));
  aLuna := extract (month from iso_week_to_date(aAn, aSet));
  if aLuna = 12 and aSet = 1 then
    aLuna := 1;
  end if;
  return aLuna;
end;

function GetSecventa return Number is
NextV number(20);
begin
  select seq_list_counter.nextval into nextv from dual;
  return nextv;
end;

function GetPretMinAchiz(vCodObiect in number) return number is
vVal number(20,7);
vIdx number(10);
vNrIntr number(10);
begin
  vIdx := 1;
  vVal := -1;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrPretIntrMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrIntr FROM DUAL;
  if vNrIntr = 0 then return 0.0; end if;
  for v_rec in (
    SELECT  nvl(NS.PRET,0)- nvl(NS.ADAOS,0) pret, ns.cantnir
     FROM
       NIR N,
       NIRSTOC NS,
       NGEST G
     WHERE
       NS.CODOBIECT = vCODOBIECT
       AND NS.CODNIR = N.CODNIR
       AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
       AND OPERAT = 1
       AND ANULAT = 0
       AND G.CODGEST = N.GEST
       AND nvl(G.CODSUBUNIT, 1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
     ORDER BY N.DATANIR DESC) loop
    if vIdx &gt; vNrIntr then Exit; end if;
    if vVal = -1 then
      vVal := v_rec.pret;
    else
      if v_rec.pret &lt; vVal then
        vVal := v_rec.pret;
      end if;
    end if;
    vIdx := vIdx + 1;
  end loop;

  return vVal;
end;

function GetPretMedAchiz(vCodObiect in number) return number is
vCant number(20,7);
vVal number(20,7);
vIdx number(10);
vNrIntr number(10);
begin
  vIdx := 1;
  vCant := 0.0;
  vVal  := 0.0;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrPretIntrMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrIntr FROM DUAL;

  if vNrIntr = 0 then return 0.0; end if;

  for v_rec in (
    SELECT  nvl(NS.PRET,0)- nvl(NS.ADAOS,0) pret, ns.cantnir
     FROM
       NIR N,
       NIRSTOC NS,
       NGEST G
     WHERE
       NS.CODOBIECT = vCODOBIECT
       AND NS.CODNIR = N.CODNIR
       AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
       AND OPERAT = 1
       AND ANULAT = 0
       AND G.CODGEST = N.GEST
       AND nvl(G.CODSUBUNIT, 1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
     ORDER BY N.DATANIR DESC) loop
    if vIdx &gt; vNrIntr then Exit; end if;
    vCant := vCant + v_rec.cantnir;
    vVal := vVal + v_rec.cantnir * v_rec.pret;
    vIdx := vIdx + 1;
  end loop;

  if vCant &lt;&gt; 0 then
    return vVal/vCant;
  else
    return 0;
  end if;
end;

function GetPretMaxAchiz(vCodObiect in number) return number is
vVal number(20,7);
vIdx number(10);
vNrIntr number(10);
begin
  vIdx := 1;
  vVal := 0.0;

  SELECT PKG_CATEGCONST.GetValConstanta(&apos;NrPretIntrMed&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO vNrIntr FROM DUAL;
  if vNrIntr = 0 then return 0.0; end if;
  for v_rec in (
    SELECT  nvl(NS.PRET,0)- nvl(NS.ADAOS,0) pret, ns.cantnir
     FROM
       NIR N,
       NIRSTOC NS,
       NGEST G
     WHERE
       NS.CODOBIECT = vCODOBIECT
       AND NS.CODNIR = N.CODNIR
       AND TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15)
       AND OPERAT = 1
       AND ANULAT = 0
       AND G.CODGEST = N.GEST
       AND nvl(G.CODSUBUNIT, 1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(G.CODSUBUNIT, 1),pkg_globals.GETSUBUNITATE)
     ORDER BY N.DATANIR DESC) loop
    if vIdx &gt; vNrIntr then Exit; end if;
    if v_rec.pret &gt; vVal then
      vVal := v_rec.pret;
    end if;
    vIdx := vIdx + 1;
  end loop;

  return vVal;
end;

function GetParinteNivelClsA(aNivel in number, acodclasea in number) return varchar2 is
vNivel number(20);
vCodParinte number(20);
vRez varchar(100);
vSimbol varchar2(100);
begin
  vrez := &apos;&apos;;
  begin
    select codparinte, nivel, simbol into vCodParinte, vNivel, vSimbol from nclasea where codclasea = acodclasea;
  exception when others then vNivel := 0; vCodParinte := 0;
  end;
  if aNivel = vNivel then vRez := vSimbol;
  else if vCodParinte &gt; 0 then vRez := GetParinteNivelClsA(aNivel, vCodParinte); end if;
  end if;
  return vRez;
end;

function GetParinteNivelClsP(aNivel in number, acodclasep in number) return varchar2 is
vNivel number(20);
vCodParinte number(20);
vRez varchar2(100);
vSimbol varchar2(100);
begin
  vRez := &apos;&apos;;
  begin
    select codparinte, nivel, Simbol into vCodParinte, vNivel, vSimbol from nclasep where codclasep = acodclasep;
  exception when others then vNivel := 0; vCodParinte := 0;
  end;
  if aNivel = vNivel then vRez := vSimbol;
  else if vCodParinte &gt; 0 then vRez := GetParinteNivelClsp(aNivel, vCodParinte); end if;
  end if;
  return vRez;
end;

function Get_termen_concedii(aDataIni in date, xDataFin in date, aCodComanda1 in number, aUserID in number) return date is
nr number(10);
odata date;
aDataFin date;
begin
  if xDataFin is null then
    select termen into aDataFin from comanda1 where codcomanda1 = aCodComanda1;
  else
    aDataFin := xDataFin;
  end if;

  nr := 0;
  for v_tmp in (
    select dela, panala
    from nperscvscol cv
         inner join npers p on p.codpers = cv.codpers
    where (cv.dela between aDataIni and aDataFin or cv.panala between aDataIni and aDataFin or
          aDataIni between cv.dela and cv.panala or aDataFin between cv.dela and cv.panala) and
          p.logonname = aUserID

  ) loop
    odata := v_tmp.dela;
    while odata &lt;= v_tmp.panala loop
      if odata between aDataIni and aDataFin then
        nr := nr + 1;
      end if;
      odata := odata + 1;
    end loop;
  end loop;
  return aDataFin + nr;
end;

procedure import_nc is
aCodNC number(20);
acodnc1 number(20);
aUserID number(20);
aCodCont number(20);
aBug number(1);
aAuxSimbol varchar2(50);
aSimbol varchar2(50);
aAuxCod number(20);
acount number(10);
aVal1 number(20,7);
aVal2 number(20,7);
acodcont1 number(20);
arowid rowid;
begin
  delete x;
  aAuxSimbol := &apos;891&apos;;
  begin
    select codcont into aAuxCod from ncont where simbol = aAuxSimbol;
  exception when others then aAuxCod := 0;
  end;
  if aAuxCod = 0 then
    insert into x(test) values (&apos;Sombolul de cont: &apos;||aAuxSimbol||&apos; nu se regaseste in baza de date.&apos;);
    Return;
  end if;

  /*aUserID := 1;
  for v_rec in (
    select distinct nrdoc, datadoc, descriere from imp_nc
    order by datadoc, nrdoc
  ) loop
    select count(*) into acount from imp_nc
    where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) &lt;&gt; 0;
    if acount = 1 then
      begin
        select to_number(debit), simbol into aVal1, asimbol from imp_nc
        where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) &lt;&gt; 0;
      exception when others then aVal1 := 0;
      end;
      aBug := 0;
      begin
        select nc.codcont into acodcont from ncont nc where nc.simbol = asimbol;
      exception when others then aCodCont := 0;
      end;
      if aCodCont = 0 then
        insert into x(test) values (&apos;Sombolul de cont: &apos;||aSimbol||&apos; nu se regaseste in baza de date. Nota contabila(nr/data/descriere): &apos;||v_rec.nrdoc||&apos;/&apos;||to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||v_rec.descriere||&apos; nu se importa&apos;);
        aBug := 1;
      else
        for v_tmp in
          (
          select i.simbol
          from imp_nc i
               left join ncont nc on nc.simbol = i.simbol
          where nc.codcont is null and i.nrdoc = v_rec.nrdoc and i.datadoc = v_rec.datadoc and to_number(i.debit) = 0
          ) loop
          insert into x(test) values (&apos;Sombolul de cont: &apos;||v_tmp.Simbol||&apos; nu se regaseste in baza de date. Nota contabila(nr/data/descriere): &apos;||v_rec.nrdoc||&apos;/&apos;||to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||v_rec.descriere||&apos; nu se importa&apos;);
          aBug := 1;
        end loop;
      end if;
      if aBug = 0 then
        select sum(to_number(credit)) into aVal2 from imp_nc
        where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) = 0;
        if aVal1 = aVal2 then
          select seq_nc_codnc.nextval into aCodNC from dual;
          insert into nc(codnc,
                         nrdoc,
                         datadoc,
                         jurnaltva,
                         tiptranz,
                         tiptva,
                         valoare,
                         moneda,
                         curs,
                         obs,
                         an,
                         luna,
                         subunitatea,
                         userid,
                         datacreare)
          values (
                         acodnc,
                         to_number(v_rec.nrdoc),
                         v_rec.datadoc,
                         1,
                         1,
                         1,
                         aVal1,
                         0,
                         1,
                         substr(v_rec.descriere,1,95),
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         2,
                         auserid,
                         sysdate
                         );
          for v_tmp in (
            select c.codcont, to_number(i.credit) valoare, rownum indexlocal
            from imp_nc i
                 inner join ncont c on i.simbol = c.simbol
            where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) = 0
          ) loop
            select seq_nc1_codnc1.nextval into acodnc1 from dual;
            insert into nc1(codnc1,
                            codnc,
                            contd,
                            contc,
                            valoare,
                            indexlocal,
                            an,
                            luna,
                            partd,
                            partc)
             values (acodnc1,
                     acodnc,
                     acodcont,
                     v_tmp.codcont,
                     v_tmp.valoare,
                     v_tmp.indexlocal,
                     extract(year from v_rec.datadoc),
                     extract(month from v_rec.datadoc),
                     0,
                     0);
          end loop;
        else
          -- folosesc contul intermediar
          select seq_nc_codnc.nextval into aCodNC from dual;
          insert into nc(codnc,
                         nrdoc,
                         datadoc,
                         jurnaltva,
                         tiptranz,
                         tiptva,
                         valoare,
                         moneda,
                         curs,
                         obs,
                         an,
                         luna,
                         subunitatea,
                         userid,
                         datacreare)
          values (
                         acodnc,
                         to_number(v_rec.nrdoc),
                         v_rec.datadoc,
                         1,
                         1,
                         1,
                         aVal1,
                         0,
                         1,
                         substr(v_rec.descriere,1,95),
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         2,
                         auserid,
                         sysdate
                         );
          select seq_nc1_codnc1.nextval into acodnc1 from dual;
          insert into nc1(codnc1,
                          codnc,
                          contd,
                          contc,
                          valoare,
                          indexlocal,
                          an,
                          luna,
                          partd,
                          partc)
           values (acodnc1,
                   acodnc,
                   acodcont,
                   aAuxCod,
                   aVal1,
                   1,
                   extract(year from v_rec.datadoc),
                   extract(month from v_rec.datadoc),
                   0,
                   0);
          for v_tmp in (
            select c.codcont, to_number(i.credit) valoare, rownum+1 indexlocal
            from imp_nc i
                 inner join ncont c on i.simbol = c.simbol
            where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) = 0
          ) loop
            select seq_nc1_codnc1.nextval into acodnc1 from dual;
            insert into nc1(codnc1,
                            codnc,
                            contd,
                            contc,
                            valoare,
                            indexlocal,
                            an,
                            luna,
                            partd,
                            partc)
             values (acodnc1,
                     acodnc,
                     acodcont,
                     v_tmp.codcont,
                     v_tmp.valoare,
                     v_tmp.indexlocal,
                     extract(year from v_rec.datadoc),
                     extract(month from v_rec.datadoc),
                     0,
                     0);
          end loop;
        end if;
      end if;
    else
      select count(*) into acount from imp_nc
      where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(credit) &lt;&gt; 0;
      if acount = 1 then
        begin
          select to_number(credit), simbol into aVal1, asimbol from imp_nc
          where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(credit) &lt;&gt; 0;
        exception when others then aVal1 := 0;
        end;
        aBug := 0;
        begin
          select nc.codcont into acodcont from ncont nc where nc.simbol = asimbol;
        exception when others then aCodCont := 0;
        end;
        if aCodCont = 0 then
          insert into x(test) values (&apos;Sombolul de cont: &apos;||aSimbol||&apos; nu se regaseste in baza de date. Nota contabila(nr/data/descriere): &apos;||v_rec.nrdoc||&apos;/&apos;||to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||v_rec.descriere||&apos; nu se importa&apos;);
          aBug := 1;
        else
          for v_tmp in
            (
            select i.simbol
            from imp_nc i
                 left join ncont nc on nc.simbol = i.simbol
            where nc.codcont is null and nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(credit) = 0
            ) loop
            insert into x(test) values (&apos;Sombolul de cont: &apos;||v_tmp.Simbol||&apos; nu se regaseste in baza de date. Nota contabila(nr/data/descriere): &apos;||v_rec.nrdoc||&apos;/&apos;||to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;/&apos;||v_rec.descriere||&apos; nu se importa&apos;);
            aBug := 1;
          end loop;
        end if;
        if aBug = 0 then
          select sum(to_number(debit)) into aVal2 from imp_nc
          where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(credit) = 0;
          if aVal1 = aVal2 then
            select seq_nc_codnc.nextval into aCodNC from dual;
            insert into nc(codnc,
                           nrdoc,
                           datadoc,
                           jurnaltva,
                           tiptranz,
                           tiptva,
                           valoare,
                           moneda,
                           curs,
                           obs,
                           an,
                           luna,
                           subunitatea,
                           userid,
                           datacreare)
            values (
                           acodnc,
                           to_number(v_rec.nrdoc),
                           v_rec.datadoc,
                           1,
                           1,
                           1,
                           aVal1,
                           0,
                           1,
                           substr(v_rec.descriere,1,95),
                           extract(year from v_rec.datadoc),
                           extract(month from v_rec.datadoc),
                           2,
                           auserid,
                           sysdate
                           );
            for v_tmp in (
              select c.codcont, to_number(i.debit) valoare, rownum indexlocal
              from imp_nc i
                   inner join ncont c on i.simbol = c.simbol
              where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(credit) = 0
            ) loop
              select seq_nc1_codnc1.nextval into acodnc1 from dual;
              insert into nc1(codnc1,
                              codnc,
                              contd,
                              contc,
                              valoare,
                              indexlocal,
                              an,
                              luna,
                              partd,
                              partc)
               values (acodnc1,
                       acodnc,
                       v_tmp.codcont,
                       acodcont,
                       v_tmp.valoare,
                       v_tmp.indexlocal,
                       extract(year from v_rec.datadoc),
                       extract(month from v_rec.datadoc),
                       0,
                       0);
            end loop;
          else
            -- folosesc contul intermediar
            select seq_nc_codnc.nextval into aCodNC from dual;
            insert into nc(codnc,
                           nrdoc,
                           datadoc,
                           jurnaltva,
                           tiptranz,
                           tiptva,
                           valoare,
                           moneda,
                           curs,
                           obs,
                           an,
                           luna,
                           subunitatea,
                           userid,
                           datacreare)
            values (
                           acodnc,
                           to_number(v_rec.nrdoc),
                           v_rec.datadoc,
                           1,
                           1,
                           1,
                           aVal1,
                           0,
                           1,
                           substr(v_rec.descriere,1,95),
                           extract(year from v_rec.datadoc),
                           extract(month from v_rec.datadoc),
                           2,
                           auserid,
                           sysdate
                           );
            select seq_nc1_codnc1.nextval into acodnc1 from dual;
            insert into nc1(codnc1,
                            codnc,
                            contd,
                            contc,
                            valoare,
                            indexlocal,
                            an,
                            luna,
                            partd,
                            partc)
             values (acodnc1,
                     acodnc,
                     aAuxCod,
                     acodcont,
                     aVal1,
                     1,
                     extract(year from v_rec.datadoc),
                     extract(month from v_rec.datadoc),
                     0,
                     0);
            for v_tmp in (
              select c.codcont, to_number(i.credit) valoare, rownum+1 indexlocal
              from imp_nc i
                   inner join ncont c on i.simbol = c.simbol
              where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc and to_number(debit) = 0
            ) loop
              select seq_nc1_codnc1.nextval into acodnc1 from dual;
              insert into nc1(codnc1,
                              codnc,
                              contd,
                              contc,
                              valoare,
                              indexlocal,
                              an,
                              luna,
                              partd,
                              partc)
               values (acodnc1,
                       acodnc,
                       v_tmp.codcont,
                       acodcont,
                       v_tmp.valoare,
                       v_tmp.indexlocal,
                       extract(year from v_rec.datadoc),
                       extract(month from v_rec.datadoc),
                       0,
                       0);
            end loop;
          end if;
        end if;
      else
        ---multiplu
        select seq_nc_codnc.nextval into aCodNC from dual;
        select sum(debit) into aval1 from imp_nc where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc;
        insert into nc(codnc,
                       nrdoc,
                       datadoc,
                       jurnaltva,
                       tiptranz,
                       tiptva,
                       valoare,
                       moneda,
                       curs,
                       obs,
                       an,
                       luna,
                       subunitatea,
                       userid,
                       datacreare)
        values (
                       acodnc,
                       to_number(v_rec.nrdoc),
                       v_rec.datadoc,
                       1,
                       1,
                       1,
                       aVal1,
                       0,
                       1,
                       substr(v_rec.descriere,1,95),
                       extract(year from v_rec.datadoc),
                       extract(month from v_rec.datadoc),
                       2,
                       auserid,
                       sysdate
                       );
        delete imp_nc_sec;
        insert into imp_nc_sec(simbol,
                               datadoc,
                               nrdoc,
                               descriere,
                               debit,
                               credit,
                               preluat)
        select i.*, 0
        from imp_nc i
        where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc;
        for v_tmp in (
          select i.*, c.codcont, rownum indexlocal
          from imp_nc i
               inner join ncont c on i.simbol = c.simbol
          where nrdoc = v_rec.nrdoc and datadoc = v_rec.datadoc
        ) loop
          acount := 0;
          select count(*) into acount from imp_nc_sec
          where nrdoc = v_tmp.nrdoc and datadoc = v_tmp.datadoc and debit = v_tmp.debit and
                credit = v_tmp.credit and descriere = v_tmp.descriere and simbol = v_tmp.simbol;
          if acount = 1 then
            for v_x in (select preluat from imp_nc_sec where nrdoc = v_tmp.nrdoc and datadoc = v_tmp.datadoc and debit = v_tmp.debit and
                credit = v_tmp.credit and descriere = v_tmp.descriere and simbol = v_tmp.simbol and preluat = 0) loop
              acount := v_x.preluat;
              exit;
            end loop;
          end if;
          if acount = 0 then
            update imp_nc_sec set preluat = 1
            where nrdoc = v_tmp.nrdoc and datadoc = v_tmp.datadoc and debit = v_tmp.debit and
                  credit = v_tmp.credit and descriere = v_tmp.descriere and simbol = v_tmp.simbol;
            if v_tmp.debit &gt; 0 then
              -- caut un credit cu aceeasi valoare
              select seq_nc1_codnc1.nextval into acodnc1 from dual;
              begin
                select i.rowid, c.codcont into arowid, acodcont1
                from imp_nc_sec i
                     inner join ncont c on i.simbol = c.simbol
                where nrdoc = v_tmp.nrdoc and datadoc = v_tmp.datadoc and credit = v_tmp.debit and
                  debit = 0 and descriere = v_tmp.descriere and preluat = 0;
              exception when others then arowid := &apos;&apos;;
              end;
              if length(arowid) &gt; 0 then
                update imp_nc_sec set preluat = 1 where rowid = arowid;
                insert into nc1(codnc1,
                                codnc,
                                contd,
                                contc,
                                valoare,
                                indexlocal,
                                an,
                                luna,
                                partd,
                                partc)
                 values (acodnc1,
                         acodnc,
                         v_tmp.codcont,
                         acodcont1,
                         v_tmp.debit,
                         v_tmp.indexlocal,
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         0,
                         0);
              else
                insert into nc1(codnc1,
                                codnc,
                                contd,
                                contc,
                                valoare,
                                indexlocal,
                                an,
                                luna,
                                partd,
                                partc)
                 values (acodnc1,
                         acodnc,
                         v_tmp.codcont,
                         aauxcod,
                         v_tmp.debit,
                         v_tmp.indexlocal,
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         0,
                         0);
              end if;
            else
              -- caut un debit cu aceeasi valoare
              select seq_nc1_codnc1.nextval into acodnc1 from dual;
              begin
                select i.rowid, c.codcont into arowid, acodcont1
                from imp_nc_sec i
                     inner join ncont c on i.simbol = c.simbol
                where nrdoc = v_tmp.nrdoc and datadoc = v_tmp.datadoc and debit = v_tmp.credit and
                  credit = 0 and descriere = v_tmp.descriere and preluat = 0;
              exception when others then arowid := &apos;&apos;;
              end;
              if length(arowid) &gt; 0 then
                update imp_nc_sec set preluat = 1 where rowid = arowid;
                insert into nc1(codnc1,
                                codnc,
                                contd,
                                contc,
                                valoare,
                                indexlocal,
                                an,
                                luna,
                                partd,
                                partc)
                 values (acodnc1,
                         acodnc,
                         acodcont1,
                         v_tmp.codcont,
                         v_tmp.debit,
                         v_tmp.indexlocal,
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         0,
                         0);
              else
                insert into nc1(codnc1,
                                codnc,
                                contd,
                                contc,
                                valoare,
                                indexlocal,
                                an,
                                luna,
                                partd,
                                partc)
                 values (acodnc1,
                         acodnc,
                         aauxcod,
                         v_tmp.codcont,
                         v_tmp.debit,
                         v_tmp.indexlocal,
                         extract(year from v_rec.datadoc),
                         extract(month from v_rec.datadoc),
                         0,
                         0);
              end if;
            end if;
          end if;
        end loop;
      end if;
    end if;
  end loop;
  commit;
  */
end;

procedure SetSubDedicate is
begin
  insert into tmp_manevra_liste(filtru,valoare)
  select &apos;CODSUBUNIT&apos;, codsubunit
  from tmp_subunitdedicate;
end;

procedure SetGestDedicate is
begin
  delete tmp_manevra_liste where filtru = &apos;CODGEST&apos;;
  insert into tmp_manevra_liste(filtru,valoare)
  select &apos;CODGEST&apos;, codgest
  from tmp_gestdedicate;
end;

procedure CreazaTabela(aSQL in varchar2) is
begin
  begin
    execute immediate aSQL;
  exception when others then null;
  end;
end;

procedure UmpleTempConsAuto is
begin
  delete tmp_cons_auto;

  insert into tmp_cons_auto(codnparc0,codnparcaut,dataprec,bordprec,datacurent,bordcurent,consum,consum_val,consum_tva)
  select x.codnparc0,x.codnparcaut, x.dataprec, x.bordprec, x.datacurent, x.bordcurent,
         (select sum(i1.cant)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum,
         (select sum(i1.cant*i1.pu-coalesce(i1.tva,0))
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_val,
         (select sum(i1.tva)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_tva
  from
  (select npc0.codnparc0,npc0.codnparcaut, trunc(pcl.databord) dataprec, pcl.kmbord bordprec, trunc(npc0.databord) datacurent, npc0.kmbord bordcurent
   from nparc0 npc0
        INNER JOIN NPARCAUT PC ON PC.CODNPARCAUT = NPC0.CODNPARCAUT
        inner join nparc0 pcl on pcl.codnparcaut = npc0.codnparcaut
   where pcl.databord = (select max(pcl0.databord)
                         from nparc0 pcl0
                         where pcl0.codnparcaut = npc0.codnparcaut and
                               pcl0.databord &lt; npc0.databord
                        )
  ) x
  union all
  select x.codnparc0,x.codnparcaut, x.dataprec, x.bordprec, x.datacurent, x.bordcurent,
         (select sum(i1.cant)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum,
         (select sum(i1.cant*i1.pu-coalesce(i1.tva,0))
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_val,
         (select sum(i1.tva)
          FROM INTRARI I, INTRARI1 I1
          WHERE I1.CODOBIECT in (214,8878) AND I1.CODINTR = I.CODINTR AND I.CODAUTO = X.CODNPARCAUT
                AND TRUNC(I.DATADOC) &gt;= TRUNC(x.DATAPREC)+1 AND TRUNC(I.DATADOC) &lt;= TRUNC(x.DATAcurent)
         ) consum_tva
  from
  (select npc0.codnparc0,npc0.codnparcaut, trunc(pc.datainreg) dataprec, 0 bordprec, trunc(npc0.databord) datacurent, npc0.kmbord bordcurent
   from nparc0 npc0
        INNER JOIN NPARCAUT PC ON PC.CODNPARCAUT = NPC0.CODNPARCAUT
   where npc0.databord = (select min(pcl0.databord)
                           from nparc0 pcl0
                           where pcl0.codnparcaut = npc0.codnparcaut)
  ) x;

  for v_rec in (select * from tmp_cons_auto) loop
    update tmp_cons_auto tmp set
    bordprec_c = (
      select MAX(p0.bordcurent) KEEP (DENSE_RANK LAST ORDER BY p0.datacurent)
      from tmp_cons_auto p0
      where p0.codnparcaut = tmp.codnparcaut
            and p0.datacurent &lt; tmp.datacurent
            and coalesce(p0.consum,0) &lt;&gt; 0
    )
    where tmp.codnparc0 = v_rec.codnparc0;
  end loop;

  delete tmp_cons_auto where
  not (datacurent between PKG_GLOBALS.datastart and PKG_GLOBALS.datastop);

  update tmp_cons_auto set bordprec = 0 where bordprec is null;
  update tmp_cons_auto set bordprec_c = 0 where bordprec_c is null;
  update tmp_cons_auto tmp set
    bordmin = (select min(t.bordprec) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut),
    bordmax = (select max(t.bordcurent) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut),
    consum_total = (select sum(t.consum) from tmp_cons_auto t where t.codnparcaut = tmp.codnparcaut);

  commit;
end;

END PKG_LIST_BASE_UTILS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1E95974FE4D6CAB055A3DB1044BDEEDCEC8A4F5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZAGENT IS

  vAnLunaIni  PLS_INTEGER;
  vLunaIni    PLS_INTEGER;
  vAnIni      PLS_INTEGER;
  vAnLunaFin  PLS_INTEGER;
  vLunaFin    PLS_INTEGER;
  vAnFin      PLS_INTEGER;
  vAllClient  BOOLEAN;
  vAllAgent   BOOLEAN;

  gUserFields VARCHAR2(5000);
  gUserAlias  VARCHAR2(5000);
  gNullAlias  VARCHAR2(5000);
  gSuplCols   VARCHAR2(5000);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  S      VARCHAR2(25000);
  L1     PLS_INTEGER;
  L2     PLS_INTEGER;
  K      PLS_INTEGER   := 0;
BEGIN
  DELETE tmp_dinamic_cols;
  FOR i IN vAnIni..vAnFin LOOP
    IF i = vAnIni THEN L1 := vLunaIni; ELSE L1 := 1;  END IF;
    IF i = vAnFin THEN L2 := vLunaFin; ELSE L2 := 12; END IF;
    FOR j IN L1..L2 LOOP
      S := to_char(j,&apos;fm00&apos;)||&apos;.&apos;||to_char(i,&apos;fm0000&apos;);
      K := K + 1;
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanzari&apos;||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VI&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Incasari&apos;||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;XV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanz.(TVA excl.)&apos;||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;NV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanz.(disc.incl.)&apos;||S, k);
    END LOOP;
  END LOOP;
  COMMIT;
END;

PROCEDURE SETPARAMS(  pLunaIni     IN NUMBER  DEFAULT NULL,
                      pAnIni       IN NUMBER  DEFAULT NULL,
                      pLunaFin     IN NUMBER  DEFAULT NULL,
                      pAnFin       IN NUMBER  DEFAULT NULL,
                      pAllClient   IN NUMBER  DEFAULT 1,
                      pAllAgent    IN NUMBER  DEFAULT 1,
                      pCodJob1     IN NUMBER  DEFAULT 0 )
IS
  vDataIni  DATE;
  vDataFin  DATE;
BEGIN
  vAnLunaIni := pAnIni*12+pLunaIni;
  vAnLunaFin := pAnFin*12+pLunaFin;

  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vAnLunaIni,vAnLunaFin);
  END IF;

  PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaIni, vAnIni, vLunaIni);
  PKG_LIST_BASE_UTILS.ExtractAnLuna(vAnLunaFin, vAnFin, vLunaFin);

  vAllClient   := pAllClient = 1;
  vAllAgent    := pAllAgent = 1;

  baga_dinamic_cols;
END;

FUNCTION CAMPURI(pTIP VARCHAR2) RETURN VARCHAR2 IS
  S      VARCHAR2(25000);
  vCamp  VARCHAR2(200);
  K      PLS_INTEGER   := 0;

  PROCEDURE CompleteazaS(vAnLuna INTEGER, vLabel VARCHAR2) IS
  BEGIN
    IF pTIP = &apos;SELECT&apos; THEN
      IF vAnLuna = 0
      THEN vCamp := &apos;SUM(T.&apos;||SubStr(vLabel,3)||&apos;) &apos;;
      ELSE vCamp := &apos;SUM(CASE WHEN T.AL = &apos;||vAnLuna||&apos; THEN T.&apos;||vLabel||&apos; ELSE 0 END) &apos;;
      END IF;
    END IF;
    S := S ||&apos;,
    &apos;||vCamp||vLabel;
    IF vAnLuna &lt;&gt; 0 THEN S := S||To_Char(k); END IF;
  END;
BEGIN
  CompleteazaS(0,&apos;T_VV&apos;);
  CompleteazaS(0,&apos;T_VI&apos;);
  CompleteazaS(0,&apos;T_XV&apos;);
  CompleteazaS(0,&apos;T_NV&apos;);
  FOR i IN vAnIni*12+vLunaIni..vAnFin*12+vLunaFin LOOP
    K := K + 1;
    CompleteazaS(i,&apos;VV&apos;);
    CompleteazaS(i,&apos;VI&apos;);
    CompleteazaS(i,&apos;XV&apos;);
    CompleteazaS(i,&apos;NV&apos;);
  END LOOP;
  RETURN S;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
  sUpdate   VARCHAR2(30000);
  sWherePer VARCHAR2(100);
  sWhereAux VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;NPERS NPERS, NPART NPART, NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NTARI TSOC, NPERS AGI, NCLASEP NCP&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF (vLunaIni = vLunaFin) AND (vAnIni = vAnFin)
  THEN sWherePer := &apos;= &apos;||(vAnFin *12 + vLunaFin);
  ELSE sWherePer := &apos;BETWEEN &apos;||(vAnIni *12 + vLunaIni)||&apos; AND &apos;||(vAnFin * 12 + vLunaFin);
  END IF;

  IF NOT vAllClient THEN
    sWhereAux := sWhereAux||&apos;
      AND I.PARTENER IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  IF NOT vAllAgent THEN
    sWhereAux := sWhereAux||&apos;
      AND Coalesce(I.AGENT,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPERS&apos;&apos;)&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(Agent, AgentI, Client, DenClasaC, SoldI, SoldF &apos;||CAMPURI(&apos;INSERT&apos;)||gUserFields||&apos;)&apos;;
  sSelect := &apos;
  WITH TMP AS (
    SELECT
      0 cod, 0 codaux,
      Coalesce(I.AGENT,0) AGENT, I.PARTENER, 0 AL,
      (OL.REST + CASE WHEN O.SEMNIFICATIE IN (210, 1303) THEN 0 ELSE OL.RESTTVA END) *
      Coalesce(Nullif(G.CURS, 0), 1) SI,
      0 VV, 0 VI, 0 XV, 0 NV
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = CASE WHEN O.SEMNIFICATIE = 1303 THEN O.CODOBLIGASOCIAT ELSE O.CODOBLIGPIF END
      INNER JOIN GENERAL G ON G.CODGENERAL = OS.CODGENERAL
      INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
    WHERE (OL.AN*12+OL.LUNA) = &apos;||(vAnIni *12 + vLunaIni - 1)||&apos;
      AND O.SEMNIFICATIE &lt;&gt; 210
      AND I.TIPDOC IN (19,21,22,26)
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
    UNION ALL
    SELECT
      i.codies cod, 0 codaux,
      Coalesce(I.AGENT,0) AGENT, I.PARTENER, (I.AN *12 +I.LUNA) AL,
      0 SI, I.VALDOC * Coalesce(Nullif(I.CURS, 0), 1) VV, CASE WHEN I.TIPFACTURA = 7 THEN I.VALDOC * Coalesce(Nullif(I.CURS, 0), 1) ELSE 0 END VI,
      ( SELECT SUM(I1.CANT * I1.PU - CASE WHEN I.TIPDOC = 21 THEN I1.TVA ELSE 0 END)
        FROM IESIRI1 I1
        WHERE I1.CODIES = I.CODIES AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;S&apos;&apos;)
      ) * Coalesce(Nullif(I.CURS, 0), 1) XV,
      (I.VALDOC - I.TVADOC) * Coalesce(Nullif(I.CURS, 0), 1) NV
    FROM IESIRI I
    WHERE I.TIPDOC IN (19,21,22,26)
      AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.INFOCM,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
      AND ( I.An * 12 + I.LUNA ) &apos;||sWherePer||&apos;
    UNION ALL
    SELECT
      i.codies cod, 0 codaux,
      Coalesce(I1.CODAGENTEMULARE,0) AGENT, I.PARTENER, (I.AN *12 +I.LUNA) AL,
      0 SI, SUM(I1.CANT * I1.PU) * Coalesce(Nullif(I.CURS, 0), 1) VV, SUM(I1.CANT * I1.PU) * Coalesce(Nullif(I.CURS, 0), 1) VI,
      SUM(I1.CANT * I1.PU - I1.TVA) * Coalesce(Nullif(I.CURS, 0), 1) XV,
      SUM(I1.CANT * I1.PU - I1.TVA) * Coalesce(Nullif(I.CURS, 0), 1) NV
    FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    WHERE I.TIPDOC = 16
      AND I.ANULAT = 0 AND I.OPERAT = 1 AND Coalesce(I.INFOCM,0) = 0 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
      AND ( I.An * 12 + I.LUNA ) &apos;||sWherePer||&apos;
    GROUP BY i.codies, Coalesce(I1.CODAGENTEMULARE,0), I.PARTENER, I.AN, I.LUNA, I.CURS
    UNION ALL
    SELECT -- stingeri trezorerie
      i.codies cod, t1.codtrezor1 codaux,
      Coalesce(I.AGENT,0) AGENT, I.PARTENER, t1.an * 12 + t1.luna AL,
      0 SI, 0 VV,
      (S.VALOARE + Coalesce(GS.TVA,0)) * Sign(o.valoare) * Coalesce(Nullif(GS.CURS, 0), 1) VI,
      0 XV, 0 NV
    FROM TREZOR T
      INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      INNER JOIN GENERAL GS ON GS.TIPDOC = T.TIPDOC AND GS.CODDOC = T1.CODTREZOR1
      INNER JOIN OBLIGPIF OS ON OS.CODGENERAL = GS.CODGENERAL
      INNER JOIN STINGERE S ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
      INNER JOIN OBLIGPIF OL ON OL.CODOBLIGPIF = S.CODSTINSPIF
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = CASE WHEN OL.SEMNIFICATIE = 1303 THEN OL.CODOBLIGASOCIAT ELSE OL.CODOBLIGPIF END
      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
    WHERE I.TIPDOC IN (19,21,22,26)
      AND O.SEMNIFICATIE NOT IN (800, 801)
      AND T.TIPDOC IN (29,30,31,33)
      AND T.OPERAT = 1
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
      AND (t1.an * 12 + t1.luna) &apos;||sWherePer||&apos;
    UNION ALL
    SELECT -- stingeri compensari
      i.codies cod, c.codcompens codaux,
      Coalesce(I.AGENT,0) AGENT, I.PARTENER, c.an * 12 + c.luna AL,
      0 SI, 0 VV,
      (S.VALOARE + CASE WHEN C.TipCompens = 2 THEN 0 ELSE Coalesce(GS.TVA,0) END) * Sign(o.valoare) * Coalesce(Nullif(G.CURS, 0), 1) VI,
      0 XV, 0 NV
    FROM COMPENS C
      INNER JOIN GENERAL GS ON GS.CODDOC = C.CODCOMPENS AND GS.TIPDOC = 28
      INNER JOIN OBLIGPIF OS ON OS.CODGENERAL = GS.CODGENERAL
      INNER JOIN STINGERE S ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
      INNER JOIN OBLIGPIF OX ON OX.CODOBLIGPIF = S.CODSTINSPIF
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = COalesce(Nullif(OX.CODOBLIGASOCIAT,0),OX.CODOBLIGPIF)
      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL AND G.TIPDOC IN (19,21,22,26)
      INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
    WHERE Coalesce(C.TipCompens,0) IN (0,2)
      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
      AND (c.an * 12 + c.luna) &apos;||sWherePer||&apos;
    UNION ALL
    SELECT -- stingeri retur
      i.codies cod, i2.codies codaux,
      Coalesce(I.AGENT,0) AGENT, I.PARTENER, i2.an * 12 + i2.luna AL,
      0 SI, 0 VV,
      S.VALOARE * Sign(o.valoare) * Coalesce(Nullif(G.CURS, 0), 1) VI,
      0 XV, 0 NV
    FROM IESIRI I
      INNER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
      INNER JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
      INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
      INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
      INNER JOIN IESIRI I2 ON I2.CODIES = GS.CODDOC AND I2.TIPDOC = GS.TIPDOC
    WHERE I.TIPDOC IN (19,21,22,26)
      AND GS.SEMNIFICATIE IN (/*211,*/ 400)
      AND I.ANULAT = 0 AND I.OPERAT = 1
      AND I2.ANULAT = 0 AND I2.OPERAT = 1 &apos;||
      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
      sWhereAux||&apos;
      AND (i2.an * 12 + i2.luna) &apos;||sWherePer||&apos;
      AND Coalesce(i2.infocm,0) &lt;&gt; 1
  )
  SELECT
    CASE WHEN T.AGENT = 0 THEN &apos;&apos; &apos;&apos; ELSE NPERS.NUME||&apos;&apos; &apos;&apos;||NPERS.PRENUME END AGENT, AGI.NUME||&apos;&apos; &apos;&apos;||AGI.PRENUME AGENTI, NPART.DEN_PART, NCP.DEN_CLASEP, SUM(T.SI), SUM(T.SI + T.VV - T.VI)&apos;||
    CAMPURI(&apos;SELECT&apos;)||gUserAlias||&apos;
  FROM TMP T
    INNER JOIN NPERS ON NPERS.CODPERS = T.AGENT
    INNER JOIN NPART ON NPART.CODPART = T.PARTENER
    LEFT JOIN NAGENDA SSOC ON SSOC.CODPART = NPART.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = Coalesce(SSOC.CODLOCALIT, 0)
    LEFT JOIN NJUDET JSOC ON JSOC.CODJUDET = Coalesce(LSOC.CODJUDET, 0)
    LEFT JOIN NTARI TSOC ON TSOC.CODTARA = Coalesce(LSOC.CODTARA, 0)
    LEFT JOIN NPERS AGI ON AGI.CODPERS = Coalesce(SSOC.CODAGENT,0)
    LEFT JOIN NCLASEP NCP ON NCP.CODCLASEP = NPART.CODCLASA&apos;||
    gSuplJoins||&apos;
  GROUP BY T.AGENT, NPERS.NUME, NPERS.PRENUME, AGI.NUME, AGI.PRENUME, NPART.DEN_PART, NCP.DEN_CLASEP &apos;||gUserAlias;

--    UNION ALL
--    SELECT
--      i.codies cod, i.codies codaux,
--      Coalesce(I.AGENT,0) AGENT, I.PARTENER, i.an * 12 + i.luna AL,
--      0 SI, 0 VV,
--      -o.valoare * Coalesce(Nullif(G.CURS, 0), 1) VI,
--      0 XV, 0 NV
--    FROM IESIRI I
--      INNER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
--      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
--    WHERE I.TIPDOC IN (19,21,22,26)
--      AND G.SEMNIFICATIE IN (210)
--      AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
--      PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
--      sWhereAux||&apos;
--      AND (i.an * 12 + i.luna) &apos;||sWherePer||&apos;

  sUpdate :=&apos;
  UPDATE &apos;|| tmpName ||&apos; A
  SET (S_VV, S_VI, S_XV, S_NV) = (SELECT Sum(B.T_VV), Sum(B.T_VI), Sum(B.T_XV), Sum(B.T_NV) FROM &apos;|| tmpName ||&apos; B WHERE B.Agent = A.Agent AND B.Client = A.Client)&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(supdate, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_VANZAGENT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZAGENTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D2879B5985482EB9E33FABE885F7FC1A72CFB8D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_vanzagentart IS

  vLunaIni    PLS_INTEGER;
  vAnIni      PLS_INTEGER;
  vLunaFin    PLS_INTEGER;
  vAnFin      PLS_INTEGER;
  vAllClient  BOOLEAN;
  vAllAgent   BOOLEAN;

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  S      VARCHAR2(25000);
  L1     PLS_INTEGER;
  L2     PLS_INTEGER;
  K      PLS_INTEGER   := 0;
BEGIN
  DELETE tmp_dinamic_cols;
  FOR i IN vAnIni..vAnFin LOOP
    IF i = vAnIni THEN L1 := vLunaIni; ELSE L1 := 1;  END IF;
    IF i = vAnFin THEN L2 := vLunaFin; ELSE L2 := 12; END IF;
    FOR j IN L1..L2 LOOP
      S := to_char(j,&apos;fm00&apos;)||&apos;.&apos;||to_char(i,&apos;fm0000&apos;);
      K := K + 1;
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanzari&apos;          ||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VI&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Incasari&apos;         ||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;XV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanz.(TVA excl.)&apos; ||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;NV&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Vanz.(disc.incl.)&apos;||S, k);
      INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VA&apos;||To_Char(k,&apos;fm999&apos;), &apos;Val.Adaos&apos;            ||S, k);
    END LOOP;
  END LOOP;
  COMMIT;
END;

PROCEDURE SETPARAMS(  pLunaIni     IN NUMBER  DEFAULT NULL,
                      pAnIni       IN NUMBER  DEFAULT NULL,
                      pLunaFin     IN NUMBER  DEFAULT NULL,
                      pAnFin       IN NUMBER  DEFAULT NULL,
                      pAllClient   IN NUMBER  DEFAULT 1,
                      pAllAgent    IN NUMBER  DEFAULT 1,
                      pCodJob1     IN NUMBER  DEFAULT 0 )
IS
  aTipInterval  NUMBER(1) := 0;
BEGIN
  IF pCODJOB1 &gt; 0 THEN
    --SELECT TIPINTERVAL INTO ATIPINTERVAL FROM JOBLISTE1 WHERE CODJOB1 = pCodJob1;
    -- Tip interval fix e o prostie, fortez TipInterval = 1, adica dinamic
    aTipInterval  := 1;
  END IF;

  IF ATIPINTERVAL = 0 THEN
    vLunaIni     := pLunaIni;
    vAnIni       := pAnIni;
    vLunaFin     := pLunaFin;
    vAnFin       := pAnFin;
  ELSE
    SELECT AnMaxim,LunaMaxima,AnMaxim,LunaMaxima INTO vAnIni,vLunaIni,vAnFin,vLunaFin FROM FIRMALUNI ;
  END IF ;
  vAllClient   := pAllClient = 1;
  vAllAgent    := pAllAgent = 1;

  baga_dinamic_cols;
END;

FUNCTION CAMPURI(pTIP VARCHAR2) RETURN VARCHAR2 IS
  S      VARCHAR2(25000);
  vCamp  VARCHAR2(200);
  K      PLS_INTEGER   := 0;

  PROCEDURE CompleteazaS(vAnLuna INTEGER, vLabel VARCHAR2) IS
  BEGIN
    IF pTIP = &apos;SELECT&apos; THEN
      IF vAnLuna = 0
      THEN vCamp := &apos;SUM(T.&apos;||SubStr(vLabel,3)||&apos;) &apos;;
      ELSE vCamp := &apos;SUM(CASE WHEN T.AL = &apos;||vAnLuna||&apos; THEN T.&apos;||vLabel||&apos; ELSE 0 END) &apos;;
      END IF;
    END IF;
    S := S ||&apos;,
    &apos;||vCamp||vLabel;
    IF vAnLuna &lt;&gt; 0 THEN S := S||To_Char(k); END IF;
  END;


BEGIN
  CompleteazaS(0,&apos;T_VV&apos;);
  CompleteazaS(0,&apos;T_VI&apos;);
  CompleteazaS(0,&apos;T_XV&apos;);
  CompleteazaS(0,&apos;T_NV&apos;);
  CompleteazaS(0,&apos;T_VA&apos;);
  FOR i IN vAnIni*12+vLunaIni..vAnFin*12+vLunaFin LOOP
    K := K + 1;
    CompleteazaS(i,&apos;VV&apos;);
    CompleteazaS(i,&apos;VI&apos;);
    CompleteazaS(i,&apos;XV&apos;);
    CompleteazaS(i,&apos;NV&apos;);
    CompleteazaS(i,&apos;VA&apos;);
  END LOOP;
  RETURN S;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   VARCHAR2(10000);
  sSelect   VARCHAR2(30000);
  sUpdate   VARCHAR2(30000);
  sWherePer VARCHAR2(100);
  sWhereAux VARCHAR2(1000);
BEGIN
  gSuplCols := &apos;NPERS NPERS, NPART NPART, NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NTARI TSOC, NARTOBJ NOBJ, NART NART, NCLASEP NCP, NCLASEA NCA&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NOBJ.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NCLASEAS&apos;, &apos;NCAS&apos;, &apos;NCAS.CODCLASEAS = NART.CLASASTATIST&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  IF (vLunaIni = vLunaFin) AND (vAnIni = vAnFin)
  THEN sWherePer := &apos;= &apos;||(vAnFin *12 + vLunaFin);
  ELSE sWherePer := &apos;BETWEEN &apos;||(vAnIni *12 + vLunaIni)||&apos; AND &apos;||(vAnFin * 12 + vLunaFin);
  END IF;

  IF NOT vAllClient THEN
    sWhereAux := sWhereAux||&apos;
        AND I.PARTENER IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos;)&apos;;
  END IF;

  IF NOT vAllAgent THEN
    sWhereAux := sWhereAux||&apos;
        AND NVL(I.AGENT,0) IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPERS&apos;&apos;)&apos;;
  END IF;

  sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(Agent, Client, DenClasaC, Art, DenClasaA, SoldI, SoldF &apos;||CAMPURI(&apos;INSERT&apos;)||gUserFields||&apos;)&apos;;

  sSelect := &apos;
  WITH
  DOC AS (
    SELECT codies, al, sum(si) si, sum(VV) vv, sum(VI) vi, sum(XV) xv, sum(NV) nv
    FROM (
      SELECT
        i.codies, 0 AL,
        (OL.REST + CASE WHEN O.SEMNIFICATIE IN (210, 1303) THEN 0 ELSE OL.RESTTVA END) * DECODE(G.CURS,NULL,1,0,1,G.CURS) SI,
        0 VV, 0 VI, 0 XV, 0 NV
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
        INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = Decode(O.SEMNIFICATIE,1303,O.CODOBLIGASOCIAT,O.CODOBLIGPIF)
        INNER JOIN GENERAL G ON G.CODGENERAL = OS.CODGENERAL
        INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      WHERE (OL.AN*12+OL.LUNA) = &apos;||(vAnIni *12 + vLunaIni - 1)||&apos;
        AND O.SEMNIFICATIE &lt;&gt; 210
        AND I.TIPDOC IN (19,21,22,26)
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
      UNION ALL
      SELECT
        i.codies, (i.an *12 +i.luna) AL,
        0 SI, I.VALDOC * DECODE(I.CURS,NULL,1,0,1,I.CURS) VV, CASE WHEN I.TIPFACTURA = 7 THEN I.VALDOC * DECODE(I.CURS,NULL,1,0,1,I.CURS) ELSE 0 END VI,
        ( SELECT SUM(I1.CANT * I1.PU - DECODE(I.TIPDOC,21,I1.TVA,0))
          FROM IESIRI1 I1
          WHERE I1.CODIES = I.CODIES AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;S&apos;&apos;)
        ) * DECODE(I.CURS,NULL,1,0,1,I.CURS) XV,
        (I.VALDOC - I.TVADOC) * DECODE(I.CURS,NULL,1,0,1,I.CURS) NV
      FROM IESIRI I
      WHERE I.TIPDOC IN (16,19,21,22,26)
        AND I.ANULAT = 0 AND I.OPERAT = 1 AND NVL(I.INFOCM,0) = 0 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND ( I.An * 12 + I.LUNA ) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri trezorerie
        i.codies, t1.an * 12 + t1.luna AL,
        0 SI, 0 VV,
        (S.VALOARE + NVL(GS.TVA,0)) * Sign(o.valoare) * DECODE(GS.CURS,NULL,1,0,1,GS.CURS) VI,
        0 XV, 0 NV
      FROM TREZOR T
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
        INNER JOIN GENERAL GS ON GS.TIPDOC = T.TIPDOC AND GS.CODDOC = T1.CODTREZOR1
        INNER JOIN OBLIGPIF OS ON OS.CODGENERAL = GS.CODGENERAL
        INNER JOIN STINGERE S ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
        INNER JOIN OBLIGPIF OL ON OL.CODOBLIGPIF = S.CODSTINSPIF
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = Decode(OL.SEMNIFICATIE,1303,OL.CODOBLIGASOCIAT,OL.CODOBLIGPIF)
        INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
        INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      WHERE I.TIPDOC IN (19,21,22,26)
        AND O.SEMNIFICATIE NOT IN (800, 801)
        AND T.TIPDOC IN (29,30,31,33)
        AND T.OPERAT = 1
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (t1.an * 12 + t1.luna) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri compensari
        i.codies, c.an * 12 + c.luna AL,
        0 SI, 0 VV,
        (S.VALOARE + Decode(C.TipCompens,2,0,NVL(GS.TVA,0))) * Sign(o.valoare) * DECODE(G.CURS,NULL,1,0,1,G.CURS) VI,
        0 XV, 0 NV
      FROM COMPENS C
        INNER JOIN GENERAL GS ON GS.CODDOC = C.CODCOMPENS AND GS.TIPDOC = 28
        INNER JOIN OBLIGPIF OS ON OS.CODGENERAL = GS.CODGENERAL
        INNER JOIN STINGERE S ON S.CODSTINGATORPIF = OS.CODOBLIGPIF
        INNER JOIN OBLIGPIF OX ON OX.CODOBLIGPIF = S.CODSTINSPIF
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = DECODE(OX.CODOBLIGASOCIAT,NULL,OX.CODOBLIGPIF,0,OX.CODOBLIGPIF,OX.CODOBLIGASOCIAT)
        INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL AND G.TIPDOC IN (19,21,22,26)
        INNER JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      WHERE Nvl(C.TipCompens,0) IN (0,2)
        AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (c.an * 12 + c.luna) &apos;||sWherePer||&apos;
      UNION ALL
      SELECT -- stingeri retur
        i.codies, i2.an * 12 + i2.luna AL,
        0 SI, 0 VV,
        S.VALOARE * Sign(o.valoare) * DECODE(G.CURS,NULL,1,0,1,G.CURS) VI,
        0 XV, 0 NV
      FROM IESIRI I
        INNER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
        INNER JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
        INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
        INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        INNER JOIN IESIRI I2 ON I2.CODIES = GS.CODDOC AND I2.TIPDOC = GS.TIPDOC
      WHERE I.TIPDOC IN (16,19,21,22,26)
        AND GS.SEMNIFICATIE IN (/*211, */400)
        AND I.ANULAT = 0 AND I.OPERAT = 1
        AND I2.ANULAT = 0 AND I2.OPERAT = 1 &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        sWhereAux||&apos;
        AND (i2.an * 12 + i2.luna) &apos;||sWherePer||&apos;
        AND Coalesce(i2.infocm,0) &lt;&gt; 1
    )
    GROUP BY CODIES, AL),
  TMP AS (
    SELECT
      CASE WHEN i.tipdoc = 16 THEN NVL(I1.CODAGENTEMULARE,0) ELSE NVL(I.AGENT,0) END AGENT, I.PARTENER, NVL(I1.CODOBIECT,0) CODOBIECT, DOC.AL,
      CASE
        WHEN I1.CODIES1 IS NULL THEN DOC.SI
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.SI / I.VALDOC * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, 1) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END SI,
      CASE
        WHEN I1.CODIES1 IS NULL THEN DOC.VV
        WHEN I1.CANT = 0 THEN 0
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.VV / I.VALDOC * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, 1) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END VV,
      CASE
        WHEN I1.CODIES1 IS NULL THEN DOC.VI
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.VI / I.VALDOC * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret, 1) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END VI,
      CASE
        WHEN I1.CODIES1 IS NULL THEN DOC.XV
        WHEN I1.CANT = 0 THEN 0
        WHEN I.VALDOC - I.TVADOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.XV / (I.VALDOC - I.TVADOC) * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END XV,
      CASE
        WHEN I1.CODIES1 IS NULL THEN DOC.NV
        WHEN I.VALDOC - I.TVADOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.NV / (I.VALDOC - I.TVADOC) * PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END NV,
      CASE
        WHEN I1.CODIES1 IS NULL THEN 0
        WHEN I.VALDOC = 0 OR i1.addim = -100 OR COALESCE(l1.cant, i1.cant) = 0 THEN 0
        ELSE DOC.VV / I.VALDOC * (PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim, i1.coefdiscmaj, i1.valdiscpret) - COALESCE(lv.pretachiz, ns.pret-ns.adaos,0)/ DECODE(I.CURS,NULL,1,0,1,I.CURS)) * COALESCE(l1.cant*i1.cant/Nvl(ae1.cant,i1.cant), i1.cant)
      END VA
    FROM doc
      INNER JOIN iesiri i ON i.codies = doc.codies
      LEFT JOIN iesiri1 i1 ON i1.codies = i.codies
      LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      LEFT JOIN iesiri1 ae1 ON ae1.codies1 = ilae.codlinieaviz
      LEFT JOIN iesiri ae ON ae.codies = ae1.codies
      LEFT JOIN livr l ON l.codies = Nvl(ae1.codies,i.codies) AND l.tiplivr = Nvl(ae.tipdoc,i.tipdoc)
      LEFT JOIN livr1 l1 ON l1.codlivr = l.codlivr AND l1.codies1 = Nvl(ae1.codies1,i1.codies1)
      LEFT JOIN nirstoc ns ON ns.codnirstoc = l1.codnirstoc
      LEFT JOIN livrval lv ON lv.codlivr1 = l1.codlivr1
    WHERE (i1.tiplinie IN (&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;,&apos;&apos;=&apos;&apos;) OR i1.codies IS NULL)
  )
  SELECT
    DECODE(T.AGENT,0,NULL,NPERS.NUME||&apos;&apos; &apos;&apos;||NPERS.PRENUME) AGENT, NPART.DEN_PART, NCP.DEN_CLASEP,
    NVL(NOBJ.DENUMIRE,NART.DEN_ARTICOL), NCA.DEN_CLASEA,
    SUM(T.SI), SUM(T.SI + T.VV - T.VI)&apos;||
    CAMPURI(&apos;SELECT&apos;)||gUserAlias||&apos;
  FROM TMP T
    INNER JOIN NPERS ON NPERS.CODPERS = T.AGENT
    INNER JOIN NPART ON NPART.CODPART = T.PARTENER
    LEFT JOIN NAGENDA SSOC ON SSOC.CODPART = NPART.CODPART AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0
    LEFT JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = NVL(SSOC.CODLOCALIT, 0)
    LEFT JOIN NJUDET JSOC ON JSOC.CODJUDET = NVL(LSOC.CODJUDET, 0)
    LEFT JOIN NTARI TSOC ON TSOC.CODTARA = NVL(LSOC.CODTARA, 0)
    LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = T.CODOBIECT
    LEFT JOIN NART ON NART.CODARTICOL = NVL(NOBJ.CODARTICOL,0)
    LEFT JOIN NCLASEP NCP ON NCP.CODCLASEP = NPART.CODCLASA
    LEFT JOIN NCLASEA NCA ON NCA.CODCLASEA = NART.CLASA&apos;||
    gSuplJoins||&apos;
  GROUP BY T.AGENT, NPERS.NUME, NPERS.PRENUME, NPART.DEN_PART, NCP.DEN_CLASEP, NOBJ.DENUMIRE, NART.DEN_ARTICOL, NCA.DEN_CLASEA&apos;||gUserAlias;

--        UNION ALL
--        SELECT
--          i.codies cod, i.an * 12 + i.luna AL,
--          0 SI, 0 VV,
--          -o.valoare * DECODE(G.CURS,NULL,1,0,1,G.CURS) VI,
--          0 XV, 0 NV
--        FROM IESIRI I
--          INNER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
--          INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
--        WHERE I.TIPDOC IN (19,21,22,26)
--          AND G.SEMNIFICATIE IN (210)
--          AND I.ANULAT = 0 AND I.OPERAT = 1 &apos;||
--          PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
--          sWhereAux||&apos;
--          AND (i.an * 12 + i.luna) &apos;||sWherePer||&apos;

  sUpdate :=&apos;
  MERGE INTO &apos;|| tmpName ||&apos; A
    USING (
      SELECT ROWID,
        Sum(T_VV) OVER (PARTITION BY Agent, Client, Art) xS_VV,
        Sum(T_VI) OVER (PARTITION BY Agent, Client, Art) xS_VI,
        Sum(T_XV) OVER (PARTITION BY Agent, Client, Art) xS_XV,
        Sum(T_NV) OVER (PARTITION BY Agent, Client, Art) xS_NV,
        Sum(T_VA) OVER (PARTITION BY Agent, Client, Art) xS_VA
      FROM &apos;|| tmpName ||&apos;
    ) B ON (A.ROWID = B.ROWID)
  WHEN MATCHED THEN UPDATE SET A.S_VV = B.xS_VV, A.S_VI = B.xS_VI, A.S_XV = B.xS_XV, A.S_NV = B.xS_NV, A.S_VA = B.xS_VA&apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(supdate, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_VANZAGENTART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C398BCEBD06337BC58094FD99DAFA7DC56FC04C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZARI IS

gUserFields VARCHAR2(2500);
gUserAlias  VARCHAR2(2500);
gNullAlias  VARCHAR2(2500);
gSuplCols   VARCHAR2(2500);
gSuplJoins  VARCHAR2(5000);

PROCEDURE SETPARAMS(
	aCODRESTAURANT IN NUMBER, 
	aDATASTART IN VARCHAR2, 
	aDATAEND IN VARCHAR2, 
	aID IN NUMBER, 
	aVER IN NUMBER,
	pCodJob1     IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  DATASTART     := aDATASTART;
  DATAEND       := aDATAEND;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,DATASTART,DATAEND,xLunaAnIni,xLunaAnFin);
  END IF;
  CODRESTAURANT := aCODRESTAURANT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
S VARCHAR2(4000);
BEGIN
  gSuplCols := &apos;RESTCMD C,RESTNP NP,EMULARE E,RESTNP1 NP1,NARTOBJ O,NUM1 U1,OSPATARI OS,NPERS PE,SALI S,MESE M,NPART P&apos;;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(SALA, MASA, OSPATAR, NRCOMANDA, DESCHIDERE, INCHIDERE, NRNOTAPLATA, DENART, DENUM, CANT, PRET, DISCOUNT, VALARTICOL, PRELPEMONETAR&apos;||gUserFields||&apos;) &apos; || CHR(13) ||
  &apos;SELECT &apos;                                                 ||  CHR(13) ||
  &apos;  S.DENUMIRE AS SALA, &apos;                                  ||  CHR(13) ||
  &apos;  CASE &apos;                                                 ||  CHR(13) ||
  &apos;    WHEN M.TEXTAFISARE IS NOT NULL THEN M.TEXTAFISARE &apos;   ||  CHR(13) ||
  &apos;    ELSE TO_CHAR(M.INDEXLOCAL) &apos;                         ||  CHR(13) ||
  &apos;  END AS MASA, &apos;                                         ||  CHR(13) ||
  &apos;  PE.NUME || &apos;&apos; &apos;&apos; ||  PE.PRENUME AS OSPATAR, &apos;          ||  CHR(13) ||
  &apos;  C.NRCOMANDA, &apos;                                         ||  CHR(13) ||
  &apos;  TO_CHAR(C.DESCHIDERE, &apos;&apos;DD.MM.YYYY:HH24:MI&apos;&apos;) AS DESCHIDERE, &apos;  ||  CHR(13) ||
  &apos;  TO_CHAR(C.INCHIDERE,  &apos;&apos;DD.MM.YYYY:HH24:MI&apos;&apos;) AS INCHIDERE,  &apos;  ||  CHR(13) ||
  &apos;  NP.NRDOC AS NRNOTAPLATA,&apos;                              ||  CHR(13) ||
  &apos;  O.DENUMIRE AS DENART,&apos;                                 ||  CHR(13) ||
  &apos;  U1.DEN_UM1 AS DENUM,&apos;                                  ||  CHR(13) ||
  &apos;  NP1.CANT,&apos;                                             ||  CHR(13) ||
  &apos;  NP1.PRET,&apos;                                             ||  CHR(13) ||
  &apos;  NP1.DISCOUNT,&apos;                                         ||  CHR(13) ||
  &apos;  NP1.CANT * NP1.PRET * (100 + NVL(NP1.DISCOUNT, 0)) / 100 AS VALARTICOL,&apos;         ||  CHR(13) ||
  &apos;  DECODE(NVL(E.PRELUAT, 0), 0, &apos;&apos;NU&apos;&apos;, &apos;&apos;DA&apos;&apos;)&apos;||gUserAlias||CHR(13)||
  &apos;FROM &apos;                                                    ||  CHR(13) ||
  &apos;  RESTCMD C&apos;                                              ||  CHR(13) ||
  &apos;  INNER JOIN RESTNP NP ON NP.CODRESTCMD = C.CODRESTCMD&apos;   ||  CHR(13) ||
  &apos;  INNER JOIN RESTNP1 NP1 ON NP1.CODRESTNP = NP.CODRESTNP&apos; ||  CHR(13) ||
  &apos;  INNER JOIN NARTOBJ O ON O.CODOBIECT = NP1.CODOBIECT&apos;    ||  CHR(13) ||
  &apos;  INNER JOIN NUM1 U1 ON U1.CODUM1 = NP1.UMSEC&apos;            ||  CHR(13) ||
  &apos;  INNER JOIN MESE M ON M.CODMASA = C.CODMASA&apos;             ||  CHR(13) ||
  &apos;  INNER JOIN SALI S ON S.CODSALA      = M.CODSALA&apos;        ||  CHR(13) ||
  &apos;  LEFT  JOIN OSPATARI OS ON OS.COD = C.CODOSPATAR&apos;        ||  CHR(13) ||
  &apos;  LEFT  JOIN NPERS PE ON PE.CODPERS = OS.CODPERS&apos;         ||  CHR(13) ||
  &apos;  LEFT  JOIN EMULARE E ON E.CODRESTNP= NP.CODRESTNP&apos; ||  CHR(13) ||
  &apos;  LEFT  JOIN NPART P ON P.CODPART = NP.CODPART&apos; ||  CHR(13) ||
  gSuplJoins||  CHR(13) ||
  &apos;WHERE &apos;                                                   ||  CHR(13) ||
  &apos;  NVL(C.INCHISA, 0)    = 1&apos;                                 ||  CHR(13) ||
  &apos;  AND C.DESCHIDERE     &gt;= TO_DATE(&apos;&apos;&apos; || DATASTART || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
  &apos;  AND C.INCHIDERE      &lt;= TO_DATE(&apos;&apos;&apos; || DATAEND   || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
  &apos;  AND S.CODRESTAURANT = &apos; || TO_CHAR(NVL(CODRESTAURANT, 0));
  
  LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
  
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  Pkg_List_Struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_VANZARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZARIDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D9580EAF17121DD4359737E7A957916F0D530F9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZARIDISCOUNT IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  sDiscOff     VARCHAR2(200);
BEGIN
  PKG_GLOBALS.SetSeparator(&apos;,&apos;);
  WITH x AS (
              SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
    UNION ALL SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
    UNION ALL SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) COD FROM DUAL
  )
  SELECT string_agg(cod)||PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) INTO sDiscOff
  FROM x
  WHERE Nvl(x.cod,0) &gt; 0;

  IF sDiscOff IS NOT NULL THEN
    sDiscOff := &apos;SUM (CASE WHEN IES1.CODOBIECT IN (&apos;||sDiscOff||&apos;) THEN NVL(L1.CANT,IES1.CANT) * IES1.PU ELSE 0 END)&apos;;

  ELSE sDiscOff := 0;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME ||&apos; (MEASURE, EXPLICATIE, ANLUNA, VALORI, NIVEL)
  WITH
    A AS (
      SELECT
        SUM( DECODE (IES1.TIPLINIE , &apos;&apos;=&apos;&apos;,IES1.PU * L1.CANT, 0 ) ) VALFARADISC,
        SUM( DECODE (IES1.TIPLINIE , &apos;&apos;=&apos;&apos;,IES1.PU * L1.CANT,0)) - SUM(DECODE(IES1.TIPLINIE,&apos;&apos;=&apos;&apos;,IES1.PU * L1.CANT * IES1.COEFDISCMAJ,0)) DISCINVOICE,
        SUM( DECODE (IES1.TIPLINIE , &apos;&apos;=&apos;&apos;,(NS.PRET - NS.ADAOS)*L1.CANT,0)) COSTDESC ,
        &apos;||sDiscOff||&apos; DISCOFFINVOICE,
        IES.AN,IES.LUNA
      FROM IESIRI1 IES1
        INNER JOIN IESIRI IES ON IES1.CODIES = IES.CODIES
        LEFT JOIN LIVR1 L1 ON L1.CODIES1 = IES1.CODIES1
        LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      WHERE IES.TIPDOC IN (19,21,22, 20) AND IES.ANULAT &lt;&gt; 1 AND IES.OPERAT = 1
        AND IES.AN = PKG_GLOBALS.GetANLUCRU AND IES.LUNA = PKG_GLOBALS.GetLUNALUCRU &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;IES&apos;)||&apos;
      GROUP BY IES.AN,IES.LUNA),
    T AS (SELECT LEVEL NIVEL FROM DUAL CONNECT BY LEVEL &lt;=4)
  SELECT
    DECODE(T.NIVEL,1,&apos;&apos;M1_GSV001&apos;&apos;,2,&apos;&apos;M1_OG00ON&apos;&apos;,3,&apos;&apos;M1_OG00OF&apos;&apos;,4,&apos;&apos;M2_BIPC0R&apos;&apos;) MEASURE,
    DECODE(T.NIVEL,1,&apos;&apos;pret*cantitate fara discount&apos;&apos;,2,&apos;&apos;discountul on invoice total&apos;&apos;,3,&apos;&apos;discountul off invoice total&apos;&apos;,4,&apos;&apos;cost descarcare&apos;&apos;) EXPLICATIE,
    TO_CHAR(A.AN)||TO_CHAR(A.LUNA,&apos;&apos;00&apos;&apos;) ANLUNA,
    DECODE(T.NIVEL,1,A.VALFARADISC,2,- A.DISCINVOICE,3,A.DISCOFFINVOICE,4,A.COSTDESC) VALORI,
    T.NIVEL
  FROM A CROSS JOIN T &apos;;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  NULL;
END;
END PKG_LIST_BASE_VANZARIDISCOUNT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZARI_SINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91E6D8FCA77D313225D523A36D866EB3DDB26C6B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZARI_SINT is

PROCEDURE SETPARAMS(
          aCODRESTAURANT IN NUMBER, 
					aDATASTART IN VARCHAR2, 
					aDATAEND IN VARCHAR2, 
					aID IN NUMBER, 
					aVER IN NUMBER, 
	        pCodJob1 IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  DATASTART     := aDATASTART;
  DATAEND       := aDATAEND;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,DATASTART,DATAEND,xLunaAnIni,xLunaAnFin);
  END IF;
  CODRESTAURANT := aCODRESTAURANT;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0)
IS
S VARCHAR2(4000);
BEGIN
  S := &apos;INSERT INTO &apos; || TMPNAME || &apos;(OSPATAR, VANZARI, DISCOUNT, DISCFACT, PROTOCOL, FACTURARE,
          PLATA0,
          PLATA1,  
          PLATA2,
          PLATA3,
          PLATA4,
          PLATA5,
          PLATA6,
          ALTMODPLATA
       ) &apos; || CHR(13) ||
       &apos;SELECT &apos;                                                 ||  CHR(13) ||
       &apos;  P.NUME || &apos;&apos; &apos;&apos; || P.PRENUME AS OSPATAR,&apos;  ||  CHR(13) ||
       &apos;  VANZARI,&apos;                                  ||  CHR(13) ||
       &apos;  ABS(DISCOUNT) AS DISCOUNT,&apos;                ||  CHR(13) ||
       &apos;  ABS(DISCFACT) AS DISCFACT,&apos;                ||  CHR(13) ||
       &apos;  PROTOCOL,&apos;                                 ||  CHR(13) ||
       &apos;  FACTURARE,&apos;                                ||  CHR(13) ||
       &apos;  PLATA0,&apos;                                   ||  CHR(13) ||
       &apos;  PLATA1,&apos;                                   ||  CHR(13) ||  
       &apos;  PLATA2,&apos;                                   ||  CHR(13) ||
       &apos;  PLATA3,&apos;                                   ||  CHR(13) ||
       &apos;  PLATA4,&apos;                                   ||  CHR(13) ||
       &apos;  PLATA5,&apos;                                   ||  CHR(13) ||
       &apos;  PLATA6,&apos;                                   ||  CHR(13) ||
       &apos;  ALTMODPLATA&apos;                               ||  CHR(13) ||
       &apos;FROM&apos;                                        ||  CHR(13) ||
       &apos;(&apos;                                           ||  CHR(13) ||
       &apos;   SELECT&apos;                                   ||  CHR(13) ||
       &apos;    CODOSPATAR,&apos;                             ||  CHR(13) ||
       &apos;    SUM(VALARTICOL) AS VANZARI,&apos;             ||  CHR(13) ||
       &apos;    SUM(DISCOUNT) AS DISCOUNT,&apos;              ||  CHR(13) ||
       &apos;    SUM(DISCFACT) AS DISCFACT,&apos;              ||  CHR(13) ||
       &apos;    SUM(PROTOCOL) AS PROTOCOL,&apos;              ||  CHR(13) ||
       &apos;    SUM(FACTURARE) AS FACTURARE&apos;             ||  CHR(13) ||
       &apos;   FROM&apos;                                     ||  CHR(13) ||
       &apos;   ( &apos;                                       ||  CHR(13) ||
       &apos;   SELECT &apos;                                  ||  CHR(13) ||
       &apos;     C.CODOSPATAR,&apos;                          ||  CHR(13) ||
       &apos;     NP1.CANT * NP1.PRET AS VALARTICOL,&apos;     ||  CHR(13) ||
       &apos;     CASE &apos;                                  ||  CHR(13) ||
       &apos;       WHEN NVL(NP.FACTURARE, 0) = 0 THEN NP1.CANT * NP1.PRET * (NVL(DISCOUNT, 0)) / 100 &apos; ||
       &apos;       ELSE 0 &apos;||
       &apos;     END  AS DISCOUNT,&apos; ||
       &apos;     CASE &apos;                                   ||  CHR(13) ||
       &apos;       WHEN NVL(NP.FACTURARE, 0) = 1 THEN NP1.CANT * NP1.PRET * (NVL(DISCOUNT, 0)) / 100 &apos; ||
       &apos;       ELSE 0 &apos;||
       &apos;     END  AS DISCFACT,&apos; ||
       &apos;     CASE&apos;                                   ||  CHR(13) ||
       &apos;       WHEN NVL(NP.PROTOCOL, 0) = 1 THEN NP1.CANT * NP1.PRET&apos; ||
       &apos;       ELSE 0 &apos;                              ||  CHR(13) ||
       &apos;     END AS PROTOCOL,&apos;                       ||  CHR(13) ||
       &apos;     CASE&apos;                                   ||  CHR(13) ||
       &apos;       WHEN NVL(NP.FACTURARE, 0) = 1 THEN NP1.CANT * NP1.PRET&apos; ||
       &apos;       ELSE 0 &apos;                              ||  CHR(13) ||
       &apos;     END AS FACTURARE&apos;                       ||  CHR(13) ||
       &apos;   FROM&apos;                                     ||  CHR(13) ||
       &apos;      RESTCMD C,&apos;                            ||  CHR(13) ||
       &apos;      RESTNP NP,&apos;                            ||  CHR(13) ||
       &apos;      RESTNP1 NP1,&apos;                          ||  CHR(13) ||
       &apos;      MESE M,&apos;                               ||  CHR(13) ||
       &apos;      SALI S&apos;                                ||  CHR(13) ||
       &apos;   WHERE &apos;                                   ||  CHR(13) ||
       &apos;      NVL(C.INCHISA, 0)   = 1&apos;               ||  CHR(13) ||
       &apos;      AND C.DESCHIDERE     &gt;= TO_DATE(&apos;&apos;&apos;    || DATASTART || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos;
                                                     ||  CHR(13) ||
       &apos;      AND C.INCHIDERE      &lt;= TO_DATE(&apos;&apos;&apos;    || DATAEND  || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos;
                                                     ||  CHR(13) ||
       &apos;      AND NP.CODRESTCMD = C.CODRESTCMD &apos;     ||  CHR(13) ||
       &apos;      AND NP1.CODRESTNP = NP.CODRESTNP&apos;      ||  CHR(13) ||
       &apos;      AND M.CODMASA     = C.CODMASA&apos;         ||  CHR(13) ||
       &apos;      AND S.CODSALA     = M.CODSALA&apos;         || CHR(13)  ||
       &apos;     AND S.CODRESTAURANT = &apos;                 || TO_CHAR(NVL(CODRESTAURANT, 0))
                                                     ||  CHR(13) ||
       &apos;   )&apos;                                        ||  CHR(13) ||
       &apos;   GROUP BY CODOSPATAR&apos;                      ||  CHR(13) ||
       &apos;) VANZ&apos;                                      ||  CHR(13) ||
       &apos; LEFT OUTER JOIN &apos;                           ||  CHR(13) ||
       &apos;( &apos;                                          ||  CHR(13) ||
       &apos;  SELECT &apos;                                   ||  CHR(13) ||
       &apos;    C.CODOSPATAR,&apos;                           ||  CHR(13) ||
       &apos;    SUM(case when coalesce(np2.tipplata,0) = 0 then NP2.VALOARE else 0 end) AS PLATA0, &apos;||  CHR(13) ||
       &apos;    SUM(case when np2.tipplata = 1 then NP2.VALOARE else 0 end) AS PLATA1, &apos;||  CHR(13) ||
       &apos;    SUM(case when np2.tipplata = 2 then NP2.VALOARE else 0 end) AS PLATA2, &apos;||  CHR(13) ||
       &apos;    SUM(case when np2.tipplata = 3 then NP2.VALOARE else 0 end) AS PLATA3, &apos;||  CHR(13) ||
       &apos;    SUM(case when np2.tipplata = 4 then NP2.VALOARE else 0 end) AS PLATA4, &apos;||  CHR(13) ||
       &apos;    SUM(case when np2.tipplata = 5 then NP2.VALOARE else 0 end) AS PLATA5, &apos;||  CHR(13) ||     
       &apos;    SUM(case when np2.tipplata = 6 then NP2.VALOARE else 0 end) AS PLATA6, &apos;||  CHR(13) ||   
       &apos;    SUM(case when np2.tipplata &gt; 6 then NP2.VALOARE else 0 end) AS ALTMODPLATA &apos;||  CHR(13) ||
       &apos;  FROM &apos;                                     ||  CHR(13) ||
       &apos;     RESTCMD C,&apos;                             ||  CHR(13) ||
       &apos;     RESTNP NP,&apos;                             ||  CHR(13) ||
       &apos;     RESTNP2 NP2,&apos;                           ||  CHR(13) ||
       &apos;     MESE M,&apos;                                ||  CHR(13) ||
       &apos;     SALI S&apos;                                 ||  CHR(13) ||
       &apos;  WHERE&apos;                                     ||  CHR(13) ||
       &apos;     NVL(C.INCHISA, 0)   = 1 &apos;                 ||  CHR(13) ||
       &apos;     AND C.DESCHIDERE     &gt;= TO_DATE(&apos;&apos;&apos;       || DATASTART || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
       &apos;     AND C.INCHIDERE      &lt;= TO_DATE(&apos;&apos;&apos;       || DATAEND  || &apos;&apos;&apos;, &apos;&apos;DD.MM.YYYY:HH24:MI:SS&apos;&apos;)&apos; || CHR(13) ||
       &apos;     AND NP.CODRESTCMD = C.CODRESTCMD&apos;       ||  CHR(13) ||
       &apos;     AND NP2.CODRESTNP = NP.CODRESTNP&apos;       ||  CHR(13) ||
       &apos;     AND M.CODMASA     = C.CODMASA &apos;         ||  CHR(13) ||
       &apos;     AND S.CODSALA     = M.CODSALA&apos;          ||  CHR(13) ||
       &apos;     AND S.CODRESTAURANT = &apos;                 || TO_CHAR(NVL(CODRESTAURANT, 0)) ||  CHR(13) ||
       &apos;  GROUP BY C.CODOSPATAR &apos;                      ||  CHR(13) ||
       &apos;) ALTMP ON ALTMP.CODOSPATAR = VANZ.CODOSPATAR,&apos;||  CHR(13) ||
       &apos;  OSPATARI O, &apos;                              ||  CHR(13) ||
       &apos;  NPERS P &apos;                                  ||  CHR(13) ||
       &apos;WHERE &apos;                                      ||  CHR(13) ||
       &apos;  P.CODPERS = O.CODPERS&apos;                     ||  CHR(13) ||
       &apos;  AND VANZ.CODOSPATAR = O.COD&apos;;
 LIST_EXECUTE_IMMEDIATE(s, aListID, aListVer);
 
 COMMIT;
END;
end PKG_LIST_BASE_VANZARI_SINT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZCLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6F22899701F408105A2A24A0310A46FAB1738B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_base_vanzclaseart IS

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert      VARCHAR2(10000);
  vPerioada    VARCHAR2(100)  := PKG_LIST_SELCLASEART.Perioada;
  vToateClaseA BOOLEAN        := PKG_LIST_SELCLASEART.ToateClaseA;
  vTotiPart    BOOLEAN        := PKG_LIST_SELCLASEART.TotiPart;
  vWhereIG     VARCHAR2(1000);
BEGIN
  IF NOT vTotiPart THEN
    vWhereIG := vWhereIG || &apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODPART&apos;&apos; AND VALOARE = I.PARTENER) &apos;;
  END IF;

  IF NOT vToateClaseA THEN
    vWhereIG := vWhereIG ||&apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCLASEA&apos;&apos; AND VALOARE = NVL(NA.CLASA,0)) &apos;;
  END IF;

  sInsert:=
   &apos;INSERT INTO &apos;|| tmpName ||&apos;(ClasaA, DenClasaA, Client, CodExtCli, LocCli, JudCli, ZonaCli, Val, ValTVA, Adaos, NrDoc )
    WITH IESGRUP AS (
      SELECT
        NA.CLASA, NVL(I.PARTENER,0) PARTENER,
        SUM(I1.PRETORIG * I1.CANT * NVL(I1.COEFDISCMAJ,1)*DECODE(I.MONEDA,0,1,NVL(I.CURS,1))) VALLEI ,
        SUM(DECODE(I1.PU,0,0,I1.TVA*I1.PRETORIG/I1.PU) * NVL(I1.COEFDISCMAJ,1)*DECODE(I.MONEDA,0,1,NVL(I.CURS,1))) TVALEI,
        SUM(I1.CANT * I1.PRETORIG * NVL(I1.ADDIM/100,0)) ADAOS,
        COUNT(DISTINCT I.CODIES) NRDEDOC
      FROM IESIRI I
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
        INNER JOIN NARTOBJ NAO ON NAO.CODOBIECT = I1.CODOBIECT
        INNER JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
        INNER JOIN NUM1 ON NUM1.CODUM1 = I1.UMSEC
      WHERE I.DATADOC  BETWEEN &apos;||vPerioada||&apos;
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;) &apos;||
        PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||
        vWhereIG||&apos;
        AND EXISTS ( SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos; AND VALOARE = I.TIPDOC)
      GROUP BY NA.CLASA, NVL(I.PARTENER,0) )
    SELECT NCA.SIMBOL, NCA.DEN_CLASEA, NP.DEN_PART, NP.CODEXTERN, L.DEN_LOCALIT, J.DEN_JUDET, Z.DEN_ZONA, IG.VALLEI, IG.TVALEI, IG.ADAOS, IG.NRDEDOC
    FROM IESGRUP IG
      INNER JOIN NCLASEA NCA ON NCA.CODCLASEA = NVL(IG.CLASA,0)
      LEFT JOIN NPART NP ON NP.CODPART = IG.PARTENER
      LEFT JOIN NAGENDA A ON A.CODPART = IG.PARTENER AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(A.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
      LEFT JOIN NZONE Z ON Z.CODZONA = L.CODZONA&apos;;
  
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  COMMIT;
END;
PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(&apos;&apos;);
    pkg_list_struct.AdunaColoanele;
END;
end PKG_LIST_BASE_VANZCLASEART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99EF2FD15BC4299E6D424C5236B192E6BEE5E310</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZPER IS

  vTipPer      INTEGER; -- 1 - zilnic; 2 -saptamanal; 3 - lunar; 4 - trimestrial; 5 - anual;
  vTipData     BOOLEAN;
  vInceput     VARCHAR2(10);
  vSfarsit     VARCHAR2(10);
  vDataIni     DATE;
  vDataFin     DATE;
  vCantitativ  BOOLEAN;
  vCantCutii   BOOLEAN;
  vCantPaleti  BOOLEAN;
  vVariatie    BOOLEAN;
  vValoric     BOOLEAN;
  vInclTVA     BOOLEAN;
  vInclUnit    BOOLEAN;
  vValuta      BOOLEAN;
  vLunaIni     INTEGER;
  vLunaFin     INTEGER;
  vTipUM       INTEGER; -- 0 -- indiferent ; 1 -- umprincipla ; 2 -- umambalare ; 3 -- masa ; 4 -- volum
  vUM          INTEGER;
  vInclServ    BOOLEAN;
  vFaraVanz    BOOLEAN;
  vValAchiz    BOOLEAN;
  vExclCust    BOOLEAN;
  vCodAtribut  NUMBER(20);
  vNrCol       INTEGER;

  gUserFields  VARCHAR2(2500);
  gUserAlias   VARCHAR2(2500);
  gNullAlias   VARCHAR2(2500);
  gSuplCols    VARCHAR2(2500);
  gSuplJoins   VARCHAR2(5000);

PROCEDURE BAGA_DINAMIC_COLS IS
  K       INTEGER := 0;
  sAux    VARCHAR2(10);
  sOld    VARCHAR2(10);
  dAux    DATE;
  sCant   VARCHAR2(10);
BEGIN
  DELETE tmp_dinamic_cols;

  CASE vTipUM
    WHEN 3 THEN sCant := &apos;KG&apos;;
    WHEN 4 THEN sCant := &apos;CC&apos;;
    ELSE        sCant := &apos;Cant.&apos;;
  END CASE;

  CASE vTipPer
    WHEN 1 THEN
      dAux := vDataIni;
      WHILE dAux &lt;= vDataFin LOOP
        k := k + 1;
        sAux := To_Char(dAux,&apos;dd.mm.yyyy&apos;);
        IF vCantitativ THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), sCant||&apos;/&apos;||sAux,k);
        END IF;
        IF vCantCutii THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CC&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Cutii/&apos;||sAux,k);
        END IF;
        IF vCantPaleti THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CP&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Paleti/&apos;||sAux,k);
        END IF;
        IF vValoric THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Val./&apos; ||sAux,k);
        END IF;
        IF vInclTVA THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VT&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Val.(+TVA)/&apos; ||sAux,k);
        END IF;
        IF vInclUnit THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VU&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;VU/&apos; ||sAux,k);
        END IF;
        IF k &gt; 1 AND vVariatie THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k-1,&apos;fm999&apos;), &apos;Var./&apos; ||sOld||&apos;-&apos;||sAux,k);
        END IF;
        INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;D&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Disc.mon./&apos; ||sAux,k);
        sOld := sAux;
        dAux := dAux + 1;
      END LOOP;
    WHEN 2 THEN BEGIN
      dAux := Trunc(vDataIni,&apos;iw&apos;);
      WHILE dAux &lt;= vDataFin LOOP
        k := k + 1;
        sAux := To_Char(dAux, &apos;IW.IYYY&apos;);
        IF vCantitativ THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), sCant||&apos;/Sapt.&apos;||sAux,k);
        END IF;
        IF vCantCutii THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CC&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Cutii/Sapt.&apos;||sAux,k);
        END IF;
        IF vCantPaleti THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CP&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Paleti/Sapt&apos;||sAux,k);
        END IF;
        IF vValoric THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Val./Sapt.&apos;||sAux,k);
        END IF;
        IF vInclTVA THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VT&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Val.(+TVA)/Sapt.&apos; ||sAux,k);
        END IF;
        IF vInclUnit THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VU&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;VU/Sapt.&apos; ||sAux,k);
        END IF;
        IF k &gt; 1 AND vVariatie THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k-1,&apos;fm999&apos;), &apos;Var./Sapt.&apos; ||sOld||&apos;-&apos;||sAux,k);
        END IF;
        sOld := sAux;
        dAux := dAux + 7;
      END LOOP;
    END;
    WHEN 3 THEN BEGIN
      dAux := vDataIni;
      WHILE dAux &lt;= vDataFin LOOP
        k := k + 1;
        sAux := To_Char(dAux,&apos;mm.yyyy&apos;);
        IF vCantitativ THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), sCant||&apos;/Luna &apos;||sAux,k);
        END IF;
        IF vCantCutii THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CC&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Cutii/Luna &apos;||sAux,k);
        END IF;
        IF vCantPaleti THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CP&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Paleti/Luna &apos;||sAux,k);
        END IF;
        IF vValoric THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Val./Luna &apos;||sAux,k);
        END IF;
        IF vInclTVA THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VT&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Val.(+TVA)/Luna &apos; ||sAux,k);
        END IF;
        IF vInclUnit THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VU&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;VU/Luna &apos; ||sAux,k);
        END IF;
        IF k &gt; 1 AND vVariatie THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k-1,&apos;fm999&apos;), &apos;Var./Luna &apos; ||sOld||&apos;-&apos;||sAux,k);
        END IF;
        sOld := sAux;
        dAux := Trunc(ADD_MONTHS(dAux,1),&apos;mm&apos;);
      END LOOP;
    END;
    WHEN 4 THEN BEGIN
      dAux := Trunc(vDataIni,&apos;Q&apos;);
      WHILE dAux &lt;= vDataFin LOOP
        k := k + 1;
        sAux := To_Char(dAux,&apos;Q.YYYY&apos;);
        IF vCantitativ THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), sCant||&apos;/Trim.&apos;||sAux,k);
        END IF;
        IF vCantCutii THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CC&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Cutii/Trim.&apos;||sAux,k);
        END IF;
        IF vCantPaleti THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CP&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Paleti/Trim.&apos;||sAux,k);
        END IF;
        IF vValoric THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Val./Trim.&apos;||sAux,k);
        END IF;
        IF vInclTVA THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VT&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Val.(+TVA)/Trim.&apos; ||sAux,k);
        END IF;
        IF vInclUnit THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VU&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;VU/Trim.&apos; ||sAux,k);
        END IF;
        IF k &gt; 1 AND vVariatie THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k-1,&apos;fm999&apos;), &apos;Var./Trim.&apos; ||sOld||&apos;-&apos;||sAux,k);
        END IF;
        sOld := sAux;
        dAux := ADD_MONTHS(dAux,3);
      END LOOP;
    END;
    WHEN 5 THEN BEGIN
      FOR i IN vInceput..vSfarsit LOOP
        k := k + 1;
        sAux := To_Char(i,&apos;fm9999&apos;);
        IF vCantitativ THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;C&apos; ||To_Char(k  ,&apos;fm999&apos;), sCant||&apos;/An &apos;||To_Char(i,&apos;fm9999&apos;),k);
        END IF;
        IF vCantCutii THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CC&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Cutii/An &apos;||sAux,k);
        END IF;
        IF vCantPaleti THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;CP&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Paleti/An &apos;||sAux,k);
        END IF;
        IF vValoric THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;V&apos; ||To_Char(k  ,&apos;fm999&apos;), &apos;Val./An &apos;||To_Char(i,&apos;fm9999&apos;),k);
        END IF;
        IF vInclTVA THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VT&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;Val.(+TVA)/An &apos; ||sAux,k);
        END IF;
        IF vInclUnit THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VU&apos;||To_Char(k  ,&apos;fm999&apos;), &apos;VU/An &apos; ||sAux,k);
        END IF;
        IF k &gt; 1 AND vVariatie THEN
          INSERT INTO tmp_dinamic_cols(FieldName, Display, IndexLocal) VALUES (&apos;VV&apos;||To_Char(k-1,&apos;fm999&apos;), &apos;Var./An.&apos; ||sOld||&apos;-&apos;||sAux,k);
        END IF;
        sOld := sAux;
      END LOOP;
    END;
  END CASE;

  COMMIT;

  vNrCol := k;

END;

PROCEDURE BAGA_JOB_DINAMIC_COLS(sTableName in varchar2) IS
PRAGMA AUTONOMOUS_TRANSACTION;
  sTableKind varchar2(10);
BEGIN
  begin
  SELECT TEMPORARY INTO sTableKinD from user_tables where upper(table_name) = upper(sTableName);
  exception
    when others then return;
  end;
  IF sTableKind = &apos;N&apos; THEN
    INSERT INTO JOB_DINAMIC_COLS(tableName,FIELDNAME,DISPLAY,INDEXLOCAL)
    SELECT sTableName,FIELDNAME,DISPLAY,INDEXLOCAL  FROM TMP_DINAMIC_COLS;
  END IF;
  COMMIT;
END;

PROCEDURE SETPARAMS(
  pTipPer     IN INTEGER  DEFAULT NULL,
  pTipData    IN INTEGER  DEFAULT 0,
  pInceput    IN VARCHAR2 DEFAULT NULL,
  pSfarsit    IN VARCHAR2 DEFAULT NULL,
  pTipDate    IN INTEGER  DEFAULT NULL,
  pInclTVA    IN INTEGER  DEFAULT 0,
  pInclUnit   IN INTEGER  DEFAULT 0,
  pValuta     IN INTEGER  DEFAULT 0,
  pLunaIni    IN INTEGER  DEFAULT NULL,
  pLunaFin    IN INTEGER  DEFAULT NULL,
  pTipUM      IN INTEGER  DEFAULT NULL,
  pUM         IN INTEGER  DEFAULT NULL,
  pInclServ   IN INTEGER  DEFAULT 0,
  pFaraVanz   IN INTEGER  DEFAULT 0,
  pCodJob1    IN NUMBER   DEFAULT 0,
  pCodAtribut IN NUMBER   DEFAULT 0,
  pValAchiz   IN NUMBER   DEFAULT 0,
  pExclCust   IN INTEGER  DEFAULT 0
) IS
  aTipInterval NUMBER(1) := 0;
  An           NUMBER(4);
  Luna         NUMBER(2);
  DataRef      DATE;
  vListUMA     BOOLEAN   := (pkg_categconst.GetValConstanta(&apos;ListareUMAmbRapVanz&apos;,pkg_globals.anlucru,pkg_globals.lunalucru) = &apos;1&apos;);
  vDif         NUMBER;
  dInceput     DATE;
  dSfarsit     DATE;
BEGIN
  IF pCodJob1 &gt; 0 THEN
    --SELECT TIPINTERVAL INTO aTipInterval FROM JOBLISTE1 WHERE CODJOB1 = pCodJob1;
    -- Tip interval fix e o prostie, fortez TipInterval = 1, adica dinamic
    aTipInterval  := 1;
  END IF;

  IF aTipInterval = 0 THEN
    vInceput     := pInceput;
    vSfarsit     := pSfarsit;
  ELSE
    SELECT ANMAXIM, LUNAMAXIMA INTO An, Luna FROM FIRMALUNI;
    IF pTIPPER = 5 THEN
      vDif       := To_Number(pSfarsit) - To_Number(pInceput);
      vInceput   := An-vDif;
      vSfarsit   := An;
    ELSIF pTipData = 1 THEN
      dInceput   := To_Date(pInceput,&apos;DD.MM.YYYY&apos;);
      dSfarsit   := To_Date(pSfarsit,&apos;DD.MM.YYYY&apos;);
      IF Trunc(dInceput,&apos;mm&apos;) = dInceput AND  Last_Day(dSfarsit) = dSfarsit THEN
        vDif       := Months_Between(dInceput, Trunc(dSfarsit, &apos;MM&apos;));
        DataRef    := Last_day(To_Date(An||&apos;.&apos;||Luna,&apos;YYYY.MM&apos;));
        vSfarsit   := To_Char(DataRef,&apos;DD.MM.YYYY&apos;);
        DataRef    := Trunc(Add_Months(DataRef,vDif),&apos;MM&apos;);
        vInceput   := To_Char(DataRef,&apos;DD.MM.YYYY&apos;);
      ELSE
        vDif       := dSfarsit - dInceput;
        DataRef    := To_Date(An||&apos;.&apos;||Luna,&apos;YYYY.MM&apos;);
        vSfarsit   := To_Char(DataRef,&apos;DD.MM.YYYY&apos;);
        DataRef    := DataRef - vDif;
        vInceput   := To_Char(DataRef,&apos;DD.MM.YYYY&apos;);
      END IF;
    ELSE
      vDif       := To_Number(pSfarsit) - To_Number(pInceput);
      vInceput   := An*12+Luna-vDif;
      vSfarsit   := An*12+Luna;
    END IF;
  END IF;

  vTipPer      := pTipPer;
  vTipData     := (pTipData = 1);
  vCantitativ  := pTipDate IN (0,2,3);
  vCantCutii   := (vTipPer &gt;= 3 AND vCantitativ AND vListUMA);
  vCantPaleti  := (vTipPer &gt;= 3 AND vCantitativ AND vListUMA);
  vValoric     := pTipDate IN (1,2,4);
  vInclTVA     := vValoric AND (pInclTVA  = 1);
  vInclUnit    := vValoric AND (pInclUnit = 1);
  vVariatie    := pTipDate IN (3,4);
  vValuta      := (pValuta = 1);
  vLunaIni     := pLunaIni;
  vLunaFin     := pLunaFin;
  vTipUM       := pTipUM;
  vUM          := pUM;
  vInclServ    := (pInclServ = 1);
  vFaraVanz    := (pFaraVanz = 1);
  vValAchiz    := (pValAchiz = 1);
  vExclCust    := (pExclCust = 1);

  IF pTIPPER = 5 THEN
    vDataIni  := to_date(&apos;01.01.&apos;||vInceput,&apos;DD.MM.YYYY&apos;);
    vDataFin  := to_date(&apos;31.12.&apos;||vSfarsit,&apos;DD.MM.YYYY&apos;);
  ELSIF vTipData THEN
    vDataIni  := to_date(vInceput,&apos;DD.MM.YYYY&apos;);
    vDataFin  := to_date(vSfarsit,&apos;DD.MM.YYYY&apos;);
  ELSE
    PKG_LIST_BASE_UTILS.ExtractAnLuna(vInceput, An, Luna);
    vDataIni  := To_Date(An||&apos;.&apos;||Luna,&apos;YYYY.MM&apos;);
    PKG_LIST_BASE_UTILS.ExtractAnLuna(vSfarsit, An, Luna);
    vDataFin  := Last_Day(To_Date(An||&apos;.&apos;||Luna,&apos;YYYY.MM&apos;));
  END IF;
  vCodAtribut := pCodAtribut;

  BAGA_DINAMIC_COLS;
END;

PROCEDURE ADAUGACAMP(S IN OUT VARCHAR2, K IN OUT INTEGER, vCAMP IN VARCHAR2)
IS
  vLabel    VARCHAR2(10);
BEGIN
  k := k + 1;
  IF vCantitativ THEN
    vLabel := &apos;C&apos;||To_Char(k,&apos;fm999&apos;);
    S := S ||&apos;, &apos;||REPLACE(vCamp,&apos;XAux&apos;,&apos;CAux&apos;)||vLabel;
  END IF;
  IF vValoric THEN
    vLabel := &apos;V&apos;||To_Char(k,&apos;fm999&apos;);
    S := S ||&apos;, &apos;||REPLACE(vCamp,&apos;XAux&apos;,&apos;VAux&apos;)||vLabel;
  END IF;
  IF vInclTVA THEN
    vLabel := &apos;VT&apos;||To_Char(k,&apos;fm999&apos;);
    S := S ||&apos;, &apos;||REPLACE(vCamp,&apos;XAux&apos;,&apos;VTAux&apos;)||vLabel;
  END IF;
  IF vInclUnit THEN
    vLabel := &apos;VU&apos;||To_Char(k,&apos;fm999&apos;);
    S := S ||&apos;, &apos;||REPLACE(vCamp,&apos;XAux&apos;,&apos;VUAux&apos;)||vLabel;
  END IF;
  if vTipPer = 1 then
    vLabel := &apos;D&apos;||To_Char(k,&apos;fm999&apos;);
    S := S ||&apos;, &apos;||REPLACE(vCamp,&apos;XAux&apos;,&apos;DAux&apos;)||vLabel;
  end if;
END;

FUNCTION CAMPURI(pTIP VARCHAR2, pAlias VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
  S         VARCHAR2(25000);
  I         INTEGER;
  J         INTEGER;
  K         INTEGER;
  vCamp     VARCHAR2(800);
  dAux      DATE;
BEGIN
  IF (pTIP = &apos;INSERT&apos;) AND (TRIM(pAlias) IS NOT NULL)
  THEN vCamp := TRIM(pAlias)||&apos;.&apos;;
  END IF;

  IF pTIP = &apos;SELECT&apos;
  THEN
    IF vCantitativ THEN
      S := S||&apos;, SUM(CAux) C0&apos;;
    END IF;
    IF vValoric THEN
      S := S||&apos;, SUM(VAux) V0&apos;;
    END IF;
    IF vInclTVA THEN
      S := S||&apos;, SUM(VTAux) VT0&apos;;
    END IF;
    IF vInclUnit THEN
      S := S||&apos;, SUM(VUAux) VU0&apos;;
    END IF;
    if vTipPer = 1 then
      S := S||&apos;, SUM(DAux) D0&apos;;
    end if;
  ELSE
    IF vCantitativ THEN
      S := S||&apos;, &apos;||vCamp||&apos;C0&apos;;
    END IF;
    IF vValoric THEN
      S := S||&apos;, &apos;||vCamp||&apos;V0&apos;;
    END IF;
    IF vInclTVA THEN
      S := S||&apos;, &apos;||vCamp||&apos;VT0&apos;;
    END IF;
    IF vInclUnit THEN
      S := S||&apos;, &apos;||vCamp||&apos;VU0&apos;;
    END IF;
    if vTipPer = 1 then
      S := S||&apos;, &apos;||vCamp||&apos;D0&apos;;
    end if;
  END IF;

  k := 0;
  CASE vTipPer
    WHEN 1 THEN
      dAux := vDataIni;
      WHILE dAux &lt;= vDataFin LOOP
        IF pTIP = &apos;SELECT&apos; THEN
          vCamp := &apos;SUM(DECODE(DATADOC,&apos;&apos;&apos;||dAux||&apos;&apos;&apos;,XAux,0)) &apos;;
        END IF;
        ADAUGACAMP(S,K,vCAMP);
        dAux := dAux + 1;
      END LOOP;
    WHEN 2 THEN BEGIN
      j := To_Char(Trunc(vDataIni,&apos;yyyy&apos;),&apos;D&apos;) - 1;
      dAux := Trunc(vDataIni,&apos;yyyy&apos;) - j;
      WHILE dAux + 7 &lt;= vDataIni LOOP dAux := dAux + 7; END LOOP;
      WHILE dAux &lt;= vDataFin LOOP
        IF pTIP = &apos;SELECT&apos; THEN
          vCamp := &apos;SUM(CASE WHEN DATADOC BETWEEN &apos;&apos;&apos;||dAux||&apos;&apos;&apos; AND &apos;&apos;&apos;||To_Char(dAux+6)||&apos;&apos;&apos; THEN XAux ELSE 0 END) &apos;;
        END IF;
        ADAUGACAMP(S,K,vCAMP);
        dAux := dAux + 7;
      END LOOP;
    END;
    WHEN 3 THEN BEGIN
      dAux := Trunc(vDataIni,&apos;MM&apos;);
      WHILE dAux &lt;= vDataFin LOOP
        IF pTIP = &apos;SELECT&apos; THEN
          vCamp := &apos;SUM(CASE WHEN LUNA = &apos;||To_Char(dAux,&apos;mm&apos;)||&apos; AND AN = &apos;||To_Char(dAux,&apos;yyyy&apos;)||&apos; THEN XAux ELSE 0 END) &apos;;
        END IF;
        ADAUGACAMP(S,K,vCAMP);
        dAux := ADD_MONTHS(dAux,1);
      END LOOP;
    END;
    WHEN 4 THEN BEGIN
      dAux := Trunc(vDataIni,&apos;Q&apos;);
      WHILE dAux &lt;= vDataFin LOOP
        i := EXTRACT(MONTH FROM dAux);
        IF pTIP = &apos;SELECT&apos; THEN
          vCamp := &apos;SUM(CASE WHEN LUNA BETWEEN &apos;||i||&apos; AND &apos;||(i+2)||&apos; AND AN = &apos;||To_Char(dAux,&apos;yyyy&apos;)||&apos; THEN XAux ELSE 0 END) &apos;;
        END IF;
        ADAUGACAMP(S,K,vCAMP);
        dAux := ADD_MONTHS(dAux,3);
      END LOOP;
    END;
    WHEN 5 THEN BEGIN
      FOR i IN vInceput..vSfarsit LOOP
        IF pTIP = &apos;SELECT&apos; THEN
          vCamp := &apos;SUM(CASE WHEN AN = &apos;||i||&apos; THEN XAux ELSE 0 END) &apos;;
        END IF;
        ADAUGACAMP(S,K,vCAMP);
      END LOOP;
    END;
  END CASE;

  RETURN S;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert    VARCHAR2(10000);
  sSelect    VARCHAR2(30000);
  sUpdate    VARCHAR2(30000);
  sWhere     VARCHAR2( 1000);
  sJoinUM    VARCHAR2( 1000);
  sJoinU1    VARCHAR2( 1000);
  sCurs      VARCHAR2( 1000);
  sCampUM    VARCHAR2( 1000) := &apos;NUM.DEN_UM&apos;;
  vVal       VARCHAR2( 5000);
  sInsAUX    VARCHAR2( 1000);
  sSelAUX    VARCHAR2( 1000);
  sJoinUMA   VARCHAR2( 1000);
  sJoinCL    VARCHAR2( 5000);
  sValAchiz  VARCHAR2( 5000);
  sJoinAchiz VARCHAR2( 5000);
  sInsAchiz  VARCHAR2(10000);
  aSitV      NUMBER(1);
  aBancaV    NUMBER(20);
  aMonedaV   NUMBER(20);
  K          INTEGER;
  sCU1       VARCHAR2( 1000) := &apos;&apos;;
  vMaxCl     INTEGER;
  sAnP       NUMBER(4);
  sLunaP     NUMBER(2);
  sAnM       NUMBER(4);
  sLunaM     NUMBER(2);
  vDataRef   DATE;
  sTipLin    VARCHAR2(100)   := &apos;&apos;&apos;=&apos;&apos;&apos;;
  sArtAtrib1 VARCHAR2(5000)  := &apos;, NULL ARTATRIB1&apos;;
  sFiltruObj VARCHAR2(5000)  := &apos;&apos;;
  sCondB     VARCHAR2(5000)  := &apos;&apos;;
  sCond      VARCHAR2(5000)  := &apos;&apos;;
BEGIN
  IF vCodAtribut &gt; 0 THEN
    sArtAtrib1 := &apos;,
    ( SELECT Min(aa1.valoare)
      FROM nartatr aa
        LEFT JOIN natrobj ao ON ao.codartatr = aa.codartatr
        LEFT JOIN natrib1 aa1 ON aa1.codvalatr = ao.codvalatr
      WHERE aa.codarticol = nao.codarticol AND ao.codobiect = nao.codobiect AND aa.codatribut = &apos;||vCodAtribut||&apos;
    ) ARTATRIB1&apos;;
    sFiltruObj := &apos; and exists (select aa.codatribut from nartatr aa where aa.codarticol = nao.codarticol AND aa.codatribut = &apos;||vCodAtribut||&apos;) &apos;;
  END IF;
  gSuplCols :=
    &apos;NARTOBJ NAO, NART NA, NUM NUM, NGEST NG, NPART NP, NPART PROD, IOART IOA, NCLASEA NCA, NCLASEP NCP, NPERS AG, &apos;||
    &apos;NAGENDA SSOC, NLOCALIT LSOC, NJUDET JSOC, NAGENDA SLIV, NLOCALIT LLIV, NJUDET JLIV, TRASEULIVR TLIV, NTIPSEDII TIPSLIV,PRETM PRETIMP&apos;;

  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = NAO.CODOBIECT&apos;);
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJATR&apos;, &apos;OATR&apos;, &apos;OATR.CODOBIECT = NAO.CODOBIECT&apos;);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  BAGA_JOB_DINAMIC_COLS(tmpName);

  IF vInclserv THEN
    sTipLin := sTipLin ||&apos;,&apos;&apos;S&apos;&apos;&apos;;
  END IF;

  IF vTipData THEN
    sCondB := to_char(EXTRACT(YEAR FROM To_Date(vInceput,&apos;dd.mm.yyyy&apos;)) * 12 + EXTRACT(MONTH FROM To_Date(vInceput,&apos;dd.mm.yyyy&apos;))) || &apos;
            AND &apos; || to_char(EXTRACT(YEAR FROM To_Date(vSfarsit,&apos;dd.mm.yyyy&apos;)) * 12 + EXTRACT(MONTH FROM To_Date(vSfarsit,&apos;dd.mm.yyyy&apos;)));
    sCond  := EXTRACT(YEAR FROM To_Date(vInceput,&apos;dd.mm.yyyy&apos;)) * 12 + EXTRACT(MONTH FROM To_Date(vInceput,&apos;dd.mm.yyyy&apos;)) - 1;
  ELSE
    sCondB := vInceput||&apos; and &apos;||vSfarsit;
    sCond  := vInceput - 1;
  END IF;

  IF vTipPer = 5 THEN
    IF vLunaIni = vLunaFin
    THEN sWhere := &apos;I.LUNA = &apos;||vLunaIni||&apos; AND I.An&apos;;
    ELSE sWhere := &apos;I.LUNA BETWEEN &apos;||vLunaIni||&apos; AND &apos;||vLunaFin||&apos; AND I.An&apos;;
    END IF;
  ELSIF vTipData THEN
    sWhere := &apos;I.DataDoc&apos;;
  ELSE
    sWhere := &apos;I.An*12+I.LUNA&apos;;
  END IF;

  IF vInceput = vSfarsit AND vTipData THEN
    sWhere := sWhere||&apos; = To_Date(&apos;&apos;&apos;||vInceput||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF vInceput = vSfarsit THEN
    sWhere := sWhere||&apos; = &apos;||vInceput;
  ELSIF vTipData THEN
    sWhere := sWhere||&apos; BETWEEN To_Date(&apos;&apos;&apos;||vInceput||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND To_Date(&apos;&apos;&apos;||vSfarsit||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE
    sWhere := sWhere||&apos; BETWEEN &apos;||vInceput||&apos; AND &apos;||vSfarsit;
  END IF;

  IF vExclCust THEN
    sWhere := sWhere||&apos; AND NOT I.CUSTODIE IN (1, 2)&apos;;
  END IF;

  sValAchiz   := &apos;,CAST(NULL AS NUMBER(20,7)) VALACHIZ&apos;;
  sJoinAchiz  := &apos;&apos;;
  IF vValAchiz THEN
    sValAchiz :=&apos;,
        CASE
          WHEN iesval.codlivr1 &gt; 0 AND ae.initializari = 1 and ae.custodie = 1 THEN iesval.val * i1.cant
          WHEN iesval.codlivr1 &gt; 0 THEN iesval.val * Coalesce(l1.cant,0)*i1.cant/Coalesce(ae1.cant,i1.cant)
          ELSE
            CASE
              WHEN NS.CODNIRSTOC &gt; 0 THEN NS.PRET - COALESCE(NS.ADAOS,0)
              ELSE LV.PRETACHIZ
            END * CASE WHEN I.TIPDOC = 26 AND AE1.CANT &lt;&gt; 0 THEN I1.CANT/AE1.CANT ELSE 1 END * NVL(L1.CANT,I1.CANT)
        END ValAchiz&apos;;
    sJoinAchiz := &apos;LEFT JOIN TMP_LST_VALACHIZ IESVAL ON IESVAL.CODLIVR1  = L1.CODLIVR1&apos;;
    sInsAchiz  := &apos;INSERT INTO TMP_LST_VALACHIZ(VAL, CODLIVR1)
    SELECT SUM(LL1.CANT * (NS.PRET - Coalesce(NS.ADAOS,0)))/SUM(LL1.CANT) VAL, L1.CODLIVR1
    FROM IESIRI I
      INNER JOIN IESIRI1    I1  ON I1.CODIES     = I.CODIES
      INNER JOIN LIVR1      L1  ON L1.CODIES1    = I1.CODIES1
      INNER JOIN IESVALLINK IVL ON IVL.CODLIVR1  = L1.CODLIVR1
      INNER JOIN LIVR1      LL1 ON LL1.CODIES1   = IVL.CODIES1
      INNER JOIN NIRSTOC    NS  ON NS.CODNIRSTOC = LL1.CODNIRSTOC
    WHERE &apos;||sWhere||&apos; AND Nvl(I.InfoCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND LL1.CANT &lt;&gt; 0
      AND I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
      AND I1.TIPLINIE IN (&apos;||sTipLin||&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
    GROUP BY L1.CODLIVR1
    UNION ALL
    SELECT SUM(L1.CANT * (NS.PRET - Coalesce(NS.ADAOS,0)))/SUM(L1.CANT) VAL, L1.CODLIVR1
    FROM IESIRI I
      INNER JOIN IESIRI1    I1  ON I1.CODIES     = I.CODIES
      INNER JOIN LIVR1      L1  ON L1.CODIES1    = I1.CODIES1
      INNER JOIN NIRSTOC    NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN IESVALLINK IVL ON IVL.CODLIVR1  = L1.CODLIVR1
    WHERE &apos;||sWhere||&apos; AND Nvl(I.InfoCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND L1.CANT &lt;&gt; 0
      AND I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
      AND I1.TIPLINIE IN (&apos;||sTipLin||&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      AND IVL.CODLIVR1 IS NULL
    GROUP BY L1.CODLIVR1&apos;;
    LIST_EXECUTE_IMMEDIATE(sInsAchiz, aListID, aListVer);
  END IF;

  IF vTipUM = 3 THEN
    sWhere  := sWhere||&apos;
        AND (NVL(O.MASA,0) &lt;&gt; 0 OR U.TIPUM = 1)&apos;;
  END IF;

  IF vTipUM = 4 THEN
    sWhere  := sWhere||&apos;
        AND (NVL(O.VOLUM,0) &lt;&gt; 0 OR U.TIPUM = 2)&apos;;
  END IF;


  IF vValuta AND pkg_list_base_utils.GetInfoSitValuta(aSitV,aBancaV,aMonedaV) THEN
    sCurs := &apos;/ PKG_LIST_BASE_UTILS.GETCURSREFERINTA(&apos;||aMonedaV||&apos;,&apos;||aBancaV||&apos;, i.datadoc )&apos;;
  END IF;

  IF vCantitativ THEN
    vVal := vVal ||&apos;,
        CASE WHEN I.TIPDOC = 26 AND AE1.CANT &lt;&gt; 0 THEN I1.CANT/AE1.CANT ELSE 1 END * NVL(L1.CANT,I1.CANT) CAux&apos;;
  END IF;
  IF vValoric THEN
    vVal := vVal ||&apos;,
        CASE WHEN I.TIPDOC = 26 AND AE1.CANT &lt;&gt; 0 THEN I1.CANT/AE1.CANT ELSE 1 END * NVL(L1.CANT,I1.CANT) * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (16,21) AND (i1.cant * i1.pu) &lt;&gt; 0 THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i.curs&apos;||sCurs||&apos; VAux&apos;;
  END IF;
  IF vInclTVA THEN
    vVal := vVal ||&apos;,
        CASE WHEN I.TIPDOC = 26 AND AE1.CANT &lt;&gt; 0 THEN I1.CANT/AE1.CANT ELSE 1 END * NVL(L1.CANT,I1.CANT) * i1.pretorig * nvl(i1.coefdiscmaj,1) * CASE WHEN i.tipdoc IN (16,21) OR (i1.cant * i1.pu) = 0 THEN 1 ELSE (1 + NVL(i1.tva,0) / (i1.cant * i1.pu)) END * i.curs&apos;||sCurs||&apos; VTAux&apos;;
  END IF;
  IF vInclUnit THEN
    vVal := vVal ||&apos;,
        CASE WHEN I.TIPDOC = 26 AND AE1.CANT &lt;&gt; 0 THEN I1.CANT/AE1.CANT ELSE 1 END * NVL(L1.CANT,I1.CANT) * i1.pu * CASE WHEN i.tipdoc IN (16,21) AND (i1.cant * i1.pu) &lt;&gt; 0 THEN (1 - NVL(i1.tva,0) / (i1.cant * i1.pu)) ELSE 1 END * i.curs&apos;||sCurs||&apos; VUAux&apos;;
  END IF;
  if vTipPer = 1 then
    vVal := vVal ||&apos;,
      CASE WHEN I.TIPDOC = 16 THEN coalesce(i1.valdiscpret-i1.valdiscpret*i1.tva/(i1.pu*i1.cant),0) ELSE 0 END DAux&apos;;
  end if;

  sJoinU1 := &apos;
    LEFT JOIN NUM1 U1 ON U1.CODUM = NA.UM AND SECUNDARA = 0&apos;;
  IF    vTipUM = 1 THEN
    sJoinUM := &apos;
        INNER JOIN NARTOBJ O   ON O.CODOBIECT    = I1.CODOBIECT
        INNER JOIN NART    ART ON ART.CODARTICOL = O.CODARTICOL AND ART.UM = &apos;||vUM;
  ELSIF vTipUM = 2 THEN
    sJoinUM := &apos;
        INNER JOIN NARTOBJ O  ON O.CODOBIECT  = I1.CODOBIECT
        INNER JOIN NARTAMB AA ON AA.CODOBIECT = O.CODOBIECT AND AA.UMSEC = &apos;||vUM||&apos;
        INNER JOIN NUM1    U1 ON U1.CODUM1    = AA.UMSEC&apos;;
    sCU1    := &apos;, &apos;||vUM||&apos; CU1&apos;;
    sJoinU1 := &apos;
    LEFT JOIN NUM1 U1 ON U1.CODUM1 = IG.CU1&apos;;
    sCampUM  := &apos;U1.DEN_UM1&apos;;
    sInsAux  := sInsAux||&apos;, ParCant&apos;;
    sSelAux  := sSelAux||&apos;, U1.PARITATE&apos;;
  ELSIF vTipUM IN (3,4) THEN
    sJoinUM := &apos;
        INNER JOIN NARTOBJ O   ON O.CODOBIECT    = I1.CODOBIECT
        INNER JOIN NART    ART ON ART.CODARTICOL = O.CODARTICOL
        INNER JOIN NUM     U   ON U.CODUM        = ART.UM&apos;;
    sCampUM  := CASE WHEN vTipUM = 3 THEN &apos;&apos;&apos;KG&apos;&apos;&apos; ELSE &apos;&apos;&apos;CC&apos;&apos;&apos; END;
    sInsAux  := sInsAux||&apos;, ParCant&apos;;
    sSelAux  := sSelAux||&apos;, NUM.COEF&apos;;
  END IF;

  vDataRef := vDataFin;
  sAnP     := To_Char(vDataRef,&apos;yyyy&apos;);
  sLunaP   := To_Char(vDataRef,&apos;mm&apos;);
  SELECT anmaxim, lunamaxima INTO sAnM, sLunaM FROM FIRMALUNI;
  IF sAnP*12+sLunaP &gt; sAnM*12+sLunaM
  THEN sAnP   := sAnM; sLunaP := sLunaM;
  ELSE sAnM   := sAnP; sLunaM := sLunaP;
  END IF;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(sAnP, sLunaP, sAnP, sLunaP);

  sSelect := &apos;
  WITH STOC AS (
    SELECT CODOBIECT, GEST, CODIOART, SUM(REST) STOCINI, SUM(VALACHIZ) VALACHIZ
    FROM (
      SELECT NS.CODOBIECT, N.GEST, NS.CODIOART, NL.REST, NVL(NS.PRET,0) * NL.REST VALACHIZ
      FROM NIRLUNA NL
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
      WHERE NL.AN * 12 + NL.LUNA = &apos;|| sCond ||&apos;
      UNION ALL -- NIRURI LUNA
      SELECT NS.CODOBIECT, N.GEST, NS.CODIOART, NS.CANTNIR AS REST, NVL(NS.PRET,0) * NS.CANTNIR VALACHIZ
      FROM NIRSTOC NS
        INNER JOIN NIR     N ON N.CODNIR    = NS.CODNIR
        LEFT  JOIN INTRARI I ON I.CODINTR   = N.CODINTR
        LEFT  JOIN TRANSF  T ON T.CODTRANSF = N.CODTRANSF
      WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
        AND N.DATANIR &lt; To_Date(&apos;&apos;&apos;||To_Char(vDataRef,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        AND COALESCE(I.AN,T.AN,0) * 12 + COALESCE(I.LUNA,T.LUNA,0) between &apos;|| sCondB ||&apos;
      UNION ALL
      SELECT NS.CODOBIECT, N.GEST, NS.CODIOART, CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END REST, NVL(NS.PRET,0) * CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END VALACHIZ
      FROM LIVR L
        INNER JOIN LIVR1   L1  ON L1.CODLIVR    = L.CODLIVR
        INNER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        INNER JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        LEFT  JOIN INTRARI I   ON I.CODINTR     = L.CODINTR
        LEFT  JOIN IESIRI  IES ON IES.CODIES    = L.CODIES
        LEFT  JOIN TRANSF  T   ON T.CODTRANSF   = L.CODTRANSF
      WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
        AND L.DATALIVR &lt; To_Date(&apos;&apos;&apos;||To_Char(vDataRef,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)
        AND COALESCE(I.AN,IES.AN,T.AN,0) * 12 + COALESCE(I.LUNA,IES.LUNA,T.LUNA,0) between &apos;|| sCondB ||&apos;
    )
    GROUP BY CODOBIECT, GEST, CODIOART)&apos;;

  IF vCantCutii OR vCantPaleti THEN
    sSelect := sSelect||&apos;,
  UMA AS (
    SELECT
      AMB.CODOBIECT,
      Max(DECODE(Upper(U1.Codextern),&apos;&apos;CUTIE&apos;&apos;,paritate)) PUMAC,
      Max(DECODE(Upper(U1.Codextern),&apos;&apos;PALET&apos;&apos;,paritate)) PUMAP
    FROM NARTAMB AMB
      INNER JOIN NUM1 U1 ON U1.CODUM1 = AMB.UMSEC
    GROUP BY CODOBIECT)&apos;;
    sInsAux  := sInsAux||&apos;, ParCutie, ParPalet&apos;;
    sSelAux  := sSelAux||&apos;, UMA.PUMAC, UMA.PUMAP&apos;;
    sJoinUMA := &apos;
    LEFT JOIN UMA ON UMA.CODOBIECT = NAO.CODOBIECT&apos;;
  END IF;

  vMaxCl := PKG_LIST_BASE_UTILS.NIVELE_NCLASEA;
  IF vMaxCL &gt; 0 THEN
    sJoinCL := sJoinCL||&apos;
    LEFT JOIN (
      SELECT
        CODCLASEA &apos;;
    FOR i in 1..vMaxCL loop
      sInsAUX := sInsAUX||&apos;, CL&apos;||to_char(i)  ||&apos;, CS&apos;||to_char(i);
      sSelAUX := sSelAUX||&apos;, CL.D&apos;||to_char(i)||&apos;, CL.S&apos;||to_char(i);
      sJoinCL := sJoinCL ||&apos;,
        coalesce(Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN den_clasea ELSE NULL end),&apos;&apos;FARA CLASA &apos;||to_char(i)||&apos;&apos;&apos;) D&apos;||to_char(i)||&apos;,
        Max(CASE WHEN nivel = &apos;||to_char(i)||&apos; THEN simbol ELSE &apos;&apos;&apos;&apos; end) S&apos;||to_char(i);
    END LOOP;
    sJoinCL := sJoinCL||&apos;
      FROM TMP_PROFIT_NCLASEA
      GROUP BY CODCLASEA
    ) CL ON CL.CodClasea = NA.Clasa &apos;;
  END IF;

  sInsert :=
  &apos;INSERT INTO &apos;|| tmpName ||
   &apos;(CodObiect, Art, UM, Client, Gest, IOArt, DenClasaA, CodInt, CodExt, Prod, DenClasaC, SediuCli, SediuLiv, Agent, AgentI, StocFin, ValAchizStocFin, Masa, Volum,ValAchiz,ArtAtrib1&apos;||
   sInsAUX||CAMPURI(&apos;INSERT&apos;)|| &apos;, x_judet, x_codclasap, x_codgest, x_codsubunit &apos;||gUserFields||&apos;)&apos;;

  sSelect := sSelect||&apos;,
  IG AS (
    SELECT CODOBIECT, PARTENER, CODLOCATIE, GEST, CODIOART, AGENT, SUM(COALESCE(VALACHIZ,0)) VALACHIZ &apos;||CAMPURI(&apos;SELECT&apos;)||sCU1||&apos;
    FROM 
    (
      SELECT
        I1.CODOBIECT, I.PARTENER, I.CODLOCATIE, NVL(N.GEST,LV.GEST) GEST, NVL(NS.CODIOART,LV.CODIOART) CODIOART, NVL(I.AGENT,0) AGENT,
        I.DATADOC, I.LUNA, I.AN&apos;||sValAchiz||vVal||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES&apos;||
        sJoinUM||&apos;
        INNER JOIN IESLINK IL  ON IL.CODIES1    = I1.CODIES1
        INNER JOIN IESIRI1 AE1 ON AE1.CODIES1   = IL.CODLINIEAVIZ
        INNER JOIN IESIRI  AE  ON AE1.CODIES    = AE.CODIES
        INNER JOIN LIVR    L   ON L.CODIES      = AE1.CODIES
        INNER JOIN LIVR1   L1  ON L1.CODLIVR    = L.CODLIVR AND L1.CODIES1 = AE1.CODIES1
        LEFT JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        LEFT JOIN LIVRVAL LV  ON LV.CODLIVR1   = L1.CODLIVR1
        &apos;||sJoinAchiz||&apos;
      WHERE &apos;||sWhere||&apos; AND Nvl(I.InfoCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND COALESCE(I1.CANT,0) &lt;&gt; 0
        AND I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
        AND I1.TIPLINIE IN (&apos;||sTipLin||&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;
      UNION ALL
      SELECT
        I1.CODOBIECT, I.PARTENER, I.CODLOCATIE, NVL(N.GEST,LV.GEST) GEST, NVL(NS.CODIOART,LV.CODIOART) CODIOART, NVL(I.AGENT,0) AGENT,
        I.DATADOC, I.LUNA, I.AN&apos;||sValAchiz||vVal||&apos;
      FROM IESIRI I
        INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES&apos;||
        sJoinUM||&apos;
        INNER JOIN LIVR    L   ON L.CODIES     = I.CODIES 
        INNER JOIN LIVR1   L1  ON L1.CODLIVR   = L.CODLIVR AND L1.CODIES1 = I1.CODIES1
        LEFT JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN NIR     N   ON N.CODNIR      = NS.CODNIR
        LEFT JOIN LIVRVAL LV  ON LV.CODLIVR1   = L1.CODLIVR1
        LEFT JOIN IESIRI1 AE1 ON AE1.CODIES1   = I1.CODIES1 - I1.CODIES1
        LEFT JOIN IESIRI1 AE  ON AE1.CODIES    = AE.CODIES
        &apos;||sJoinAchiz||&apos;
      WHERE &apos;||sWhere||&apos; AND Nvl(I.InfoCM,0) = 0 AND I.ANULAT = 0 AND I.OPERAT = 1 AND COALESCE(I1.CANT,0) &lt;&gt; 0
        AND I.TIPDOC IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;TIPDOC&apos;&apos;)
        AND I1.TIPLINIE IN (&apos;||sTipLin||&apos;) &apos;||PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;I&apos;)||&apos;  
    )
    GROUP BY CODOBIECT, PARTENER, CODLOCATIE, GEST, CODIOART, AGENT )
  SELECT
    NVL(IG.CODOBIECT, STOC.CODOBIECT) CodObiect,NAO.DENUMIRE, &apos;||sCampUM||&apos;, NP.DEN_PART, NG.DEN_GEST, IOA.DEN_IOART, NCA.DEN_CLASEA, NAO.CODINTERN, NAO.CODEXTERN,
    PROD.DEN_PART, NCP.DEN_CLASEP,
    LSOC.DEN_LOCALIT||&apos;&apos; &apos;&apos;||GETADRESA(SSOC.SECTOR, SSOC.STRADA, SSOC.NR1, SSOC.NR2, SSOC.BLOC, SSOC.SCARA, SSOC.ETAJ, SSOC.APART, SSOC.CODPOSTAL),
    LLIV.DEN_LOCALIT||&apos;&apos; &apos;&apos;||GETADRESA(SLIV.SECTOR, SLIV.STRADA, SLIV.NR1, SLIV.NR2, SLIV.BLOC, SLIV.SCARA, SLIV.ETAJ, SLIV.APART, SLIV.CODPOSTAL),
    DECODE(AG.CODPERS,0,AG.NUME,AG.NUME||&apos;&apos; &apos;&apos;||AG.PRENUME), DECODE(AGI.CODPERS,0,AGI.NUME,AGI.NUME||&apos;&apos; &apos;&apos;||AGI.PRENUME),
    NVL(STOC.STOCINI,0), NVL(STOC.VALACHIZ,0), NVL(NAO.MASA,0), NVL(NAO.VOLUM,0),COALESCE(IG.VALACHIZ,0)&apos;||
    sArtAtrib1||sSelAUX||CAMPURI(&apos;INSERT&apos;,&apos;IG&apos;)|| &apos;, coalesce(JLIV.Simbauto, JSOC.Simbauto), NCP.CODCLASEP, NG.CODGEST, NG.CODSUBUNIT&apos;||gUserAlias||&apos;
  FROM IG
    &apos;||CASE WHEN vFaraVanz THEN &apos;FULL&apos; ELSE &apos;LEFT&apos; END||&apos; JOIN STOC ON STOC.CODOBIECT = IG.CODOBIECT AND STOC.GEST = IG.GEST AND STOC.CODIOART = IG.CODIOART
    LEFT JOIN NARTOBJ NAO ON NAO.CODOBIECT = NVL(IG.CODOBIECT, STOC.CODOBIECT)
    LEFT JOIN NART NA ON NA.CODARTICOL = NAO.CODARTICOL
    LEFT JOIN NUM ON NUM.CODUM = NA.UM &apos;||
    sJoinU1||
    sJoinUMA||
    sJoinCL||&apos;
    LEFT JOIN NGEST      NG      ON NG.CODGEST          = NVL(IG.GEST,STOC.GEST)
    LEFT JOIN NPART      NP      ON NP.CODPART          = IG.PARTENER
    LEFT JOIN NPART      PROD    ON PROD.CODPART        = NAO.CODPRODUCATOR
    LEFT JOIN IOART      IOA     ON IOA.CODIOART        = NVL(IG.CODIOART,STOC.CODIOART)
    LEFT JOIN NCLASEA    NCA     ON NCA.CODCLASEA       = NA.CLASA
    LEFT JOIN NCLASEP    NCP     ON NCP.CODCLASEP       = NP.CODCLASA
    LEFT JOIN NPERS      AG      ON AG.CODPERS          = IG.AGENT
    LEFT JOIN NAGENDA    SSOC    ON SSOC.CODPART        = IG.PARTENER AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND NVL(SSOC.INACTIV, 0) = 0
    LEFT JOIN NPERS      AGI     ON AGI.CODPERS         = NVL(SSOC.CODAGENT,0)
    LEFT JOIN NLOCALIT   LSOC    ON LSOC.CODLOCALIT     = SSOC.CODLOCALIT
    LEFT JOIN NJUDET     JSOC    ON JSOC.CODJUDET       = LSOC.CODJUDET
    LEFT JOIN NAGENDA    SLIV    ON SLIV.CODAGENDA      = IG.CODLOCATIE
    LEFT JOIN NLOCALIT   LLIV    ON LLIV.CODLOCALIT     = SLIV.CODLOCALIT
    LEFT JOIN NJUDET     JLIV    ON JLIV.CODJUDET       = LLIV.CODJUDET
    LEFT JOIN TRASEULIVR TLIV    ON TLIV.CODTRASEULIVR  = SLIV.CODTRASEU
    LEFT JOIN NTIPSEDII  TIPSLIV ON TIPSLIV.CODTIPSEDIU = SLIV.CODTIPSEDIU
    LEFT JOIN PRETM      PRETIMP ON PRETIMP.CODOBIECT   = NAO.CODOBIECT AND PRETIMP.SUBUNITATEA = NG.CODSUBUNIT AND PRETIMP.IMPLICIT = 1&apos;||
    gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

  IF vNrCol &gt; 1 AND vVariatie THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET &apos;;

    FOR k IN 1..vNrCol - 1 LOOP
      IF vCantitativ THEN
        sUpdate := sUpdate || &apos;
        VV&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = DECODE(C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0,0,(C&apos;||To_Char(k+1,&apos;fm999&apos;)||&apos;-C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;)/C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;*100),&apos;;
      END IF;
      IF vValoric THEN
        sUpdate := sUpdate || &apos;
        VV&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = DECODE(V&apos;||To_Char(k,&apos;fm999&apos;)||&apos;,0,0,(V&apos;||To_Char(k+1,&apos;fm999&apos;)||&apos;-V&apos;||To_Char(k,&apos;fm999&apos;)||&apos;)/V&apos;||To_Char(k,&apos;fm999&apos;)||&apos;*100),&apos;;
      END IF;
    END LOOP;
    sUpdate := SubStr(sUpdate,1,Length(sUpdate)-1);
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  IF vCantCutii THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET CC0 = C0/ParCutie&apos;;
    FOR k IN 1..vNrCol LOOP
     sUpdate := sUpdate ||&apos;, CC&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;/ParCutie&apos;;
    END LOOP;
    sUpdate := sUpdate ||&apos;
    WHERE Nvl(ParCutie,0) &lt;&gt; 0&apos;;
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  IF vCantPaleti THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET CP0 = C0/ParPalet&apos;;
    FOR k IN 1..vNrCol LOOP
     sUpdate := sUpdate ||&apos;, CP&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;/ParPalet&apos;;
    END LOOP;
    sUpdate := sUpdate ||&apos;
    WHERE Nvl(ParPalet,0) &lt;&gt; 0&apos;;
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  IF vCantitativ AND vTipUM = 2 THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET C0 = C0/ParCant&apos;;
    FOR k IN 1..vNrCol LOOP
     sUpdate := sUpdate ||&apos;, C&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;/ParCant&apos;;
    END LOOP;
    sUpdate := sUpdate ||&apos;
    WHERE Nvl(ParCant,0) &lt;&gt; 0&apos;;
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  IF vCantitativ AND vTipUM = 3 THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET C0 = DECODE(MASA,0,C0/ParCant,C0*MASA)&apos;;
    FOR k IN 1..vNrCol LOOP
     sUpdate := sUpdate ||&apos;, C&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = DECODE(MASA,0,C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;/ParCant,C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;*MASA)&apos;;
    END LOOP;
    sUpdate := sUpdate ||&apos;
    WHERE Nvl(ParCant,0) &lt;&gt; 0 OR MASA &lt;&gt;0&apos;;
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  IF vCantitativ AND vTipUM = 4 THEN
    sUpdate :=
    &apos;UPDATE &apos;|| tmpName || &apos;
    SET C0 = DECODE(VOLUM,0,C0/ParCant,C0*VOLUM)&apos;;
    FOR k IN 1..vNrCol LOOP
     sUpdate := sUpdate ||&apos;, C&apos;||To_Char(k,&apos;fm999&apos;)||&apos; = DECODE(VOLUM,0,C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;/ParCant,C&apos;||To_Char(k,&apos;fm999&apos;)||&apos;*VOLUM)&apos;;
    END LOOP;
    sUpdate := sUpdate ||&apos;
    WHERE Nvl(ParCant,0) &lt;&gt; 0 OR VOLUM &lt;&gt;0&apos;;
    EXECUTE IMMEDIATE sUpdate;
  END IF;

  COMMIT;

END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

END PKG_LIST_BASE_VANZPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VANZ_SPEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D615816F92F757A8B5BE52854B21A5D231D709F2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VANZ_SPEC IS

  gData       VARCHAR2(200);
  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2, aLISTID IN NUMBER DEFAULT 0, aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  DEN_COL VARCHAR2(30);
BEGIN
   gSuplCols := &apos;NARTOBJ O&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;NARTOBJEXT&apos;, &apos;OEXT&apos;, &apos;OEXT.CODOBIECT = O.CODOBIECT&apos;);
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  if pkg_list_struct.TmpExists(&apos;NPARTDET&apos;) = 1 then
    begin
      SELECT NVL(T.COLUMN_NAME, &apos;&apos;) INTO DEN_COL
      FROM
      USER_TAB_COLUMNS T
      WHERE
      T.COLUMN_ID = 3 AND TABLE_NAME = &apos;NPARTDET&apos;;
    EXCEPTION WHEN OTHERS THEN DEN_COL := &apos;&apos;;
    END;
  end if;

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME ||&apos; (
     Luna,
     ClasifPart,
     CodExtern,
     CodIntern,
     CodCNAS,
     Denumire,
     ClsArt,
     TipArticol,
     Cant,
     Val,
     DiscGen,
     DiscArt,
     DiscCum,
     ValNet &apos;||gUserFields||&apos;)
  select
    x.Luna,
    x.ClasifPart,
    x.CodExtern,
    x.CodIntern,
    x.CodCNAS,
    x.Denumire,
    x.ClsArt,
    x.TipArticol,
    x.cant,
    x.Val,
    nvl(DiscGen.val,0) DiscGen,
    nvl(DiscArt.val,0) + nvl(DiscArtSec.val,0) DiscArt,
    nvl(DiscCum.val,0) DiscCum,
    x.Val - nvl(DiscGen.val,0) - nvl(DiscArt.val,0) - nvl(DiscArtSec.val,0) - nvl(DiscCum.val,0) ValNet&apos;||gUserAlias||&apos;
  from (
  select
    Luna,
    ClasifPart,
    CodExtern,
    CodIntern,
    CodCNAS,
    Denumire,
    ClsArt,
    TipArticol,
    sum(Cant) cant,
    round(sum(Val),2) Val,
    codobiect
  from
  (
    select
      pkg_globals.GetLUNALUCRU Luna,&apos;;
  if pkg_list_struct.TmpExists(&apos;NPARTDET&apos;) = 1 and Length(trim(DEN_COL)) &gt; 0 then
   sInsert := sInsert||&apos;
      pext.&apos;||DEN_COL||&apos; ClasifPart,&apos;;
  else
   sInsert := sInsert||&apos;
      null ClasifPart,&apos;;
  end if;
   sInsert := sInsert||&apos;
      obj.codextern,
      obj.codintern,
      obj.codcnas,
      obj.denumire,
      cls.den_clasea ClsArt,
      case
        when i1.pu = 0 then 0
        else 1
      end TipArticol,
      i1.cant,
      round(i1.Cant * i1.Pretorig,2) Val,
      i1.codobiect
    from iesiri1 i1
         inner join iesiri i on i1.codies = i.codies
         inner join npart p on p.codpart = i.partener
         inner join nartobj obj on i1.codobiect = obj.codobiect
         inner join nart art on art.codarticol = obj.codarticol
         left join nclasea cls on cls.codclasea = art.clasa &apos;;
 if pkg_list_struct.TmpExists(&apos;NPARTDET&apos;) = 1 then
   sInsert := sInsert||&apos;
         left join npartdet pext on pext.codpart = p.codpart&apos;;
 end if;
 sInsert := sInsert||&apos;
    where i.an * 12 + i.luna = pkg_globals.anlunalucru and i.anulat = 0
          and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
          and i.tipdoc &lt;&gt; 26
  union all
  select
      pkg_globals.GetLUNALUCRU Luna,&apos;;
  if pkg_list_struct.TmpExists(&apos;NPARTDET&apos;) = 1 and Length(trim(DEN_COL)) &gt; 0 then
   sInsert := sInsert||&apos;
      pext.&apos;||DEN_COL||&apos; ClasifPart,&apos;;
  else
   sInsert := sInsert||&apos;
      null ClasifPart,&apos;;
  end if;
   sInsert := sInsert||&apos;
      obj.codextern,
      obj.codintern,
      obj.codcnas,
      obj.denumire,
      cls.den_clasea ClsArt,
      case
        when i1.pu = 0 then 0
        else 1
      end TipArticol,
      0 cant,
      0 Val,
      i1.codobiectorig codobiect
    from iesiri1 i1
         inner join iesiri i on i1.codies = i.codies
         inner join npart p on p.codpart = i.partener
         inner join nartobj obj on i1.codobiectorig = obj.codobiect
         inner join nart art on art.codarticol = obj.codarticol
         left join nclasea cls on cls.codclasea = art.clasa &apos;;
 if pkg_list_struct.TmpExists(&apos;NPARTDET&apos;) = 1 then
   sInsert := sInsert||&apos;
         left join npartdet pext on pext.codpart = p.codpart&apos;;
 end if;
 sInsert := sInsert||&apos;
    where i.an * 12 + i.luna = pkg_globals.anlunalucru and i.anulat = 0
          and i.tipdoc &lt;&gt; 26
          and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
          and (i1.codobiect in (
                               nvl(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcCant&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0),
                               nvl(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcVol&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0)
                               )
               or
               instr(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcTer&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU),to_char(i1.codobiect)) &gt; 0
               )                
  ) group by
      Luna,
      ClasifPart,
      CodExtern,
      CodIntern,
      CodCNAS,
      Denumire,
      ClsArt,
      TipArticol,
      codobiect
    ) x
     left join nartobj o ON o.codobiect = x.codobiect
     left join (select - sum(i1.cant * i1.pu) val, i1.codobiectorig codobiect
                from iesiri1 i1
                     inner join iesiri i on i1.codies = i.codies
                where i1.codobiect = nvl(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcCant&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0)
                      and i.an * 12 + i.luna = pkg_globals.anlunalucru and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
                      and i.anulat = 0
                group by i1.codobiectorig
               ) DiscGen on DiscGen.codobiect = x.codobiect
     left join (select - sum(i1.cant * i1.pu) val, i1.codobiectorig codobiect
                from iesiri1 i1
                     inner join iesiri i on i1.codies = i.codies
                where instr(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcTer&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU),to_char(i1.codobiect)) &gt; 0
                      and i.an * 12 + i.luna = pkg_globals.anlunalucru and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
                      and i.anulat = 0
                group by i1.codobiectorig
               ) DiscArt on DiscArt.codobiect = x.codobiect
     left join (select sum(i1.cant * i1.pretorig * (1 - nvl(i1.coefdiscmaj,1))) val, i1.codobiect
                from iesiri1 i1
                     inner join iesiri i on i1.codies = i.codies
                where i.an * 12 + i.luna = pkg_globals.anlunalucru
                      and i1.tiplinie = &apos;&apos;=&apos;&apos; and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
                      and i.anulat = 0
                group by i1.codobiect
               ) DiscArtSec on DiscArtSec.codobiect = x.codobiect
     left join (select - sum(i1.cant * i1.pu) val, i1.codobiectorig codobiect
                from iesiri1 i1
                     inner join iesiri i on i1.codies = i.codies
                where i1.codobiect = nvl(PKG_CATEGCONST.GetValConstanta(&apos;&apos;ArtDiscAcVol&apos;&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0)
                      and i.an * 12 + i.luna = pkg_globals.anlunalucru and (pkg_globals.getsubunitate = 1 or i.subunitatea = pkg_globals.getsubunitate)
                      and i.anulat = 0
                group by i1.codobiectorig
               ) DiscCum on DiscCum.codobiect = x.codobiect
     &apos;||gSuplJoins;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  commit;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_VANZ_SPEC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VENITURIRAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1512A8CBD6E3828A833489BA821A681AF43F2B00</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VENITURIRAC IS

  sZi1        VARCHAR2(50);
  sZi2        VARCHAR2(50);
  gUserFields VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);

PROCEDURE SETPARAMS (Zi1 in DATE, Zi2 in DATE) IS
BEGIN
  sZi1 := PKG_LIST_ALEGPERIOADA.getDataS;
  sZi2 := PKG_LIST_ALEGPERIOADA.getDataF;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert   CLOB;
  sInsTmp   CLOB;
  GrupaAuto NUMBER;
BEGIN
  GrupaAuto := PKG_RAC_REZ.IndexGrupaAuto;
  gSuplCols := &apos;TMP_LST_VENITURIRAC TMP, COMANDA CMD, RAC_REZ RAC&apos;;
  pkg_list_struct.StartSuplCols;

  pkg_list_struct.AddSuplTabs(gSuplCols, &apos;COMANDA1&apos;, &apos;CMD1&apos;, &apos;CMD1.CODCOMANDA1 = TMP.CODCOMANDA1&apos;, 1);

  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);
  gUserAlias := Upper(gUserAlias);

  Delete TMP_LST_VENITURIRAC;
  sInsTmp := 
  &apos;INSERT INTO TMP_LST_VENITURIRAC(
    NAV_CodDoc, NAV_TipDoc,
    REZERVARE, DATAREZ, NRREF, SERIAREZ,
    TIPREZ,
    GESTIUNE, CLIENT, NRAUTO, ARTICOLE, CLASAAUTO, PRETOFERTA, PUREZ, CODCOMANDA1, CODCOMANDA, TIPDOC, Z, DURATA,
    DEPASIRE,
    K,
    VALTOTALA,
    CODGEST, CATE, CODOBIECT, CANT, PU, PROCENT
  )
  SELECT
    R.CodComanda, R.TipDoc,
    R.Rezervare, R.DATAREZ, R.NRREF, R.SeriaRez,
    Decode(R.tiprezervare,0,&apos;&apos;Customer&apos;&apos;,1,&apos;&apos;Shuttle&apos;&apos;,3,&apos;&apos;Courtesy&apos;&apos;,4,&apos;&apos;Uz intern&apos;&apos;,5,&apos;&apos;Reparatii&apos;&apos;,6,&apos;&apos;Abonament&apos;&apos;,7,&apos;&apos;Transfer&apos;&apos;) TipRez,
    R.GESTIUNE, R.CLIENT, R.NRAUTO, R.ARTICOLE, R.CLASAAUTO, R.PretOferta, R.PUREZ, R.CodComanda1, R.CodComanda, R.TipDoc, Nvl(Rz.Zile, 0) z, Round(Durata, 3) Durata,
    Case when Depasire &lt; 0 then 0 else Round(Depasire, 3) end Depasire,
    Case when Depasire &lt; 0 then 1 when Nvl(Durata,0) = 0 then 0 else Round((Durata - Depasire) / Durata, 3) end K,
    Valoare * (1 + NVL(PROCTVA, 0) / 100) ValTotala,
    R.CodGest, Cate , R.CodObiect, R.Cant, R.PU, R.Procent
  FROM (
    SELECT
      C.Nrdoc Rezervare, C.Datadoc DATAREZ, R.NR_REF NRREF, C.SeriaDoc SeriaRez, R.TipRezervare, NG.DEN_GEST GESTIUNE, NP.DEN_PART CLIENT, NA.NRINREG NRAUTO, O.DENUMIRE ARTICOLE, GRE.DENUMIRE CLASAAUTO,
      c1.PUCORELAT PretOferta, c1.PU * Nvl(C.Curs, 1) PUREZ, C1.CodComanda1, C.CODCOMANDA, C.TipDoc, 1 Cate, 0 Tip,
      CASE
        WHEN Nvl(R.Predat,0) = 1 then R.DataPred - R.DataStart
        WHEN R.DataStop &gt;= (PKG_LIST_ALEGPERIOADA.getDataF + 1) THEN R.DataStop - R.DataStart
        ELSE (PKG_LIST_ALEGPERIOADA.getDataF + 1) - R.DataStart
      END Durata,
      CASE
        WHEN (Nvl(R.Predat,0) = 1 and R.DataPred &gt;= PKG_LIST_ALEGPERIOADA.getDataS and R.DataPred &lt; (PKG_LIST_ALEGPERIOADA.getDataF+1))
        THEN Case when R.DataStart &gt;= PKG_LIST_ALEGPERIOADA.getDataS then 0 else PKG_LIST_ALEGPERIOADA.getDataS - R.DataStart END
        ELSE CASE WHEN R.DataStart &gt;= PKG_LIST_ALEGPERIOADA.getDataS then 0 else PKG_LIST_ALEGPERIOADA.getDataS - R.DataStart END +
              CASE WHEN Nvl(R.Predat,0) = 0 and R.DataStop &lt; (PKG_LIST_ALEGPERIOADA.getDataF + 1) then 0 else Nvl(R.DataPred,R.DataStop) - (PKG_LIST_ALEGPERIOADA.getDataF + 1) END
      END Depasire,
      R.CodGestSursa CodGest,
      CASE WHEN R.FaraTVA = 1 then 0 ELSE PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU) END PROCTVA,
      C1.PU * C1.Cantacceptat * Nvl(C.Curs, 1) ValLinie,
      CASE WHEN (Nvl(C1.TIPLINIESA,0) = 1) or Nvl(E.Ind,0) in (1,2000) THEN 100 - Nvl(R.Proccedat, 0) ELSE 100 END Procent,
      Case when (Nvl(C1.TIPLINIESA,0) = 1) or Nvl(E.Ind,0) in (1,2000) then (C1.PU * C1.Cantacceptat * (1 - Nvl(R.Proccedat, 0) / 100))
                            else C1.PU * C1.Cantacceptat end * Nvl(C.Curs, 1) Valoare,
      O.CodObiect,
      Case when Nvl(a.UM1,0) = 0 then CantAcceptat else AcceptUM1 end Cant,
      Case when Nvl(a.UM1,0) = 0 then PU * Nvl(C.Curs, 1) else PretUM1* Nvl(C.Curs, 1) end PU
    FROM comanda c
      inner join RAC_REZ R on R.CodComanda = C.CodComanda
      inner join comanda1 c1 on C1.CodComanda = C.CodComanda and Nvl(C1.TIPLINIESA,0) &lt;&gt; 2
      Inner join NGest ng on ng.CodGest = R. CodGestSursa
      Inner join Npart np on NP.CODPART = C.Partener
      LEFT join Nparcaut na on NA.CODNPARCAUT = NVL(C.MIJLTRANSP,0)
      LEFT JOIN NartObj o on o.CodObiect = c1.CodObiect
      LEFT JOIN Nart a on a.CodArticol = o.CodArticol
      LEFT JOIN nechiv e ON e.codobiect = c1.codobiect
      LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    WHERE c.codcomanda &gt; 0 and C.TipDoc = 94 and C.Operat = 1 and R.TipRezervare not in (3, 4, 5, 7)
      AND ( (R.DataStart &lt;= (PKG_LIST_ALEGPERIOADA.getDataF+1) and (( Nvl(R.Predat,0) = 1 and R.DataPred &gt; (PKG_LIST_ALEGPERIOADA.getDataF+1))or(Nvl(R.Predat,0) = 0))) -- acumulate deskise
            or
            (Nvl(R.Predat,0) = 1 and R.DataPred &gt;= PKG_LIST_ALEGPERIOADA.getDataS and R.DataPred &lt; (PKG_LIST_ALEGPERIOADA.getDataF+1)) -- acumulate inkise
          )
    UNION ALL
    SELECT
      C.Nrdoc Rezervare, C.Datadoc DATAREZ, R.NR_REF NRREF, C.SeriaDoc SeriaRez, R.TipRezervare, NG.DEN_GEST GESTIUNE, NP.DEN_PART CLIENT, NA.NRINREG NRAUTO, O.DENUMIRE ARTICOLE, GRE.DENUMIRE CLASAAUTO,
      c1.PUCORELAT PretOferta, c1.PU * Nvl(C.Curs, 1) PUREZ, C1.CodComanda1, C.CodComanda CodComanda, C.TipDoc, 1 Cate, 0 Tip,
      CASE
        WHEN Nvl(R.Predat,0) = 1 then R.DataPred - R.DataStart
        WHEN R.DataStop &gt;= (PKG_LIST_ALEGPERIOADA.getDataF + 1) then R.DataStop - R.DataStart
        ELSE (PKG_LIST_ALEGPERIOADA.getDataF + 1) - R.DataStart
      END Durata,
      CASE
        WHEN (Nvl(R.Predat,0) = 1 and R.DataPred &gt;= PKG_LIST_ALEGPERIOADA.getDataS and R.DataPred &lt; (PKG_LIST_ALEGPERIOADA.getDataF+1))
        THEN Case when R.DataStart &gt;= PKG_LIST_ALEGPERIOADA.getDataS then 0 ELSE PKG_LIST_ALEGPERIOADA.getDataS - R.DataStart end
        ELSE Case when R.DataStart &gt;= PKG_LIST_ALEGPERIOADA.getDataS then 0 else PKG_LIST_ALEGPERIOADA.getDataS - R.DataStart end +
              CASE when Nvl(R.Predat,0) = 0 and R.DataStop &lt; (PKG_LIST_ALEGPERIOADA.getDataF + 1) then 0 else Nvl(R.DataPred,R.DataStop) - (PKG_LIST_ALEGPERIOADA.getDataF + 1) end
      END Depasire,
      C.CodGest,
      CASE when R.FaraTVA = 1 then 0 else PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU) end PROCTVA,
      C1.PU * C1.Cantacceptat * Nvl(C.Curs, 1) ValLinie,
      Case when Nvl(C1.TIPLINIESA,0) = 2 then 100
            else Nvl(R.Proccedat, 0) end Procent,
      Case when Nvl(C1.TIPLINIESA,0) = 2 then C1.PU * C1.Cantacceptat
            else (C1.PU * C1.Cantacceptat * (Nvl(R.Proccedat, 0) / 100)) end *Nvl(C.Curs, 1) Valoare,
      O.CodObiect,
      CASE WHEN Nvl(a.UM1,0) = 0 then CantAcceptat else AcceptUM1 end Cant,
      --Case when Nvl(a.UM1,0) = 0 then PU           else PretUM1   end PU
     Case when Nvl(a.UM1,0) = 0 then PU * Nvl(C.Curs, 1) else PretUM1* Nvl(C.Curs, 1) end PU
    FROM comanda c
      inner join  RAC_REZ R on R.CodComanda = C.CodComanda
      inner join  comanda1 c1 on C1.CodComanda = C.CodComanda
      left  join NGest ng on ng.CodGest = Nvl(C.CodGest,0)
      Inner join Npart np on NP.CODPART = C.Partener
      LEFT join Nparcaut na on NA.CODNPARCAUT = NVL(C.MIJLTRANSP,0)
      LEFT JOIN NartObj o on o.CodObiect = c1.CodObiect
      LEFT JOIN Nart a on a.CodArticol = o.CodArticol
      LEFT JOIN nechiv e ON e.codobiect = c1.codobiect and NVL(E.Ind,0) in (1,2000)
      LEFT JOIN grechiv gre ON gre.codgrechiv = e.codgrupa
    WHERE c.codcomanda &gt; 0 and nvl(C.CodGest, 0) &gt; 0 and C.TipDoc = 94 and C.Operat = 1 and R.TipRezervare not in (3, 4, 5, 7) 
          and (( nvl(c1.tipliniesa,0)&lt;&gt;0) or (nvl(c1.tipliniesa,0)=0 and E.ind in (1,2000)))
      AND ( (R.DataStart &lt;= (PKG_LIST_ALEGPERIOADA.getDataF+1) and (( Nvl(R.Predat,0) = 1 and R.DataPred &gt; (PKG_LIST_ALEGPERIOADA.getDataF+1))or(Nvl(R.Predat,0) = 0))) -- acumulate deskise
            or
            (Nvl(R.Predat,0) = 1 and R.DataPred &gt;= PKG_LIST_ALEGPERIOADA.getDataS and R.DataPred &lt; (PKG_LIST_ALEGPERIOADA.getDataF+1)) -- acumulate inkise
          )
  ) R
    LEFT JOIN (
      SELECT C.CODCOMANDA, Nvl(C1.ACCEPTUM1, 0) Zile
      FROM comanda c
        inner join RAC_REZ R  on R.CodComanda = C.CodComanda
        inner join comanda1 c1 on C1.CodComanda = C.CodComanda
        inner join NEchiv E  on E.Codobiect = c1.CodObiect and E.Ind= &apos;||GrupaAuto||&apos;
      where c.codcomanda &gt; 0 and C1.CantAcceptat = 1
    ) Rz on Rz.CodComanda = R.Codcomanda
    where nvl(R.durata,0) &lt;&gt; 0&apos;;
    

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName||&apos;(
    NAV_CodDoc, NAV_TipDoc, CODGEST, CODSUBUNIT, JUDET, 
    REZERVARE, DATAREZ, NRREF, SeriaRez, TipRez,
    GESTIUNE, CLIENT, NRAUTO, ARTICOLE, CLASAAUTO,
    ZILER, TOTALZILER, PretOferta, PUREZ,  PUREZTVA, 
    CODCOMANDA, Cate,depasire,  Valoare, Cant,PU,ProcCedat,PUReal&apos;||
    gUserFields||&apos;)
  SELECT
    TMP.NAV_CodDoc, TMP.NAV_TipDoc,TMP.CodGest, CMD.SUBUNITATEA CODSUBUNIT, J.SIMBAUTO JUDET,
    TMP.Rezervare, TMP.DataRez, TMP.NrRef, TMP.SeriaRez, TMP.TipRez,
    TMP.Gestiune, TMP.Client, TMP.NrAuto, TMP.Articole, TMP.ClasaAuto,
    Round(TMP.Durata * TMP.K, 3) ZileR, TMP.Durata TotalZileR, TMP.PretOferta, TMP.PUREZ, TMP.ValTotala PUREZTVA,
    TMP.CodComanda, TMP.Cate, TMP.Depasire depasire, Round(TMP.ValTotala * TMP.K, 3) Valoare, TMP.Cant, TMP.PU, 
    NVL(TMP.Procent,0), Case when Nvl(Durata,0) = 0 then 0 else Round(TMP.ValTotala /DURATA, 7) end&apos;||
    gUserAlias||&apos;
  FROM TMP_LST_VENITURIRAC TMP
    LEFT JOIN NAGENDA A on A.CODGEST = TMP.CODGEST
    LEFT JOIN NLOCALIT L on A.CODLOCALIT = L.CODLOCALIT
    LEFT JOIN NJUDET J on J.CODJUDET = L.CodJUDET
    LEFT JOIN RAC_REZ RAC on RAC.CODComanda = TMP.CODComanda
    LEFT JOIN COMANDA CMD on CMD.CODComanda = TMP.CODComanda &apos;||
    gSuplJoins
    ;


  --PKG_GLOBALS.SetDebugMode(TRUE);
  LIST_EXECUTE_IMMEDIATE(sInsTmp, aListID, aListVer);
  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_VENITURIRAC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VERIF_IMP_IES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91A3ACAC65FC69AD4B04FDD02D76926D12603434</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VERIF_IMP_IES IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0) IS
    sInsert VARCHAR2(2000);
    sSelect VARCHAR2(10000);
    anLucru Number(4);
    alStart Number;
    alStop  Number;
    condHolding VARCHAR2(1000);
    joinHolding VARCHAR2(1000);
    subunitHolding VARCHAR2(1000); 
    vSubunit NUMBER(20);
  BEGIN
    gSuplCols := &apos;iesiri i, npart np, spvarhiva a&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,
                                alistver,
                                gUserFields,
                                gUserAlias,
                                gNullAlias,
                                gSuplJoins,
                                gSuplCols);
                                
    anLucru := PKG_GLOBALS.ANLUCRU;
    alStart := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNASTART;
    alStop  := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNAFIN;
    
    condHolding := &apos;&apos;;
    joinHolding := &apos;&apos;;
    subunitHolding := &apos;i.subunitatea&apos;;
    if (pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1) then
      vSubunit := PKG_GLOBALS.GETSUBUNITATE;  
      subunitHolding := &apos; coalesce(i.subunitatea, ns.codsubunit) &apos;;
      joinHolding    := &apos; left join nsubunit ns on REGEXP_REPLACE (ns.cif, &apos;&apos;[^[:digit:]-]&apos;&apos;) = a.cif &apos;;
      if (vSubunit &lt;&gt; 0) then
        if (vSubunit &lt;&gt; 1) then
          condHolding := &apos; and &apos;||subunitHolding||&apos; = &apos; || vSubunit;
        ELSIF Coalesce(pkg_categconst.GetValConstanta(&apos;CumulatFirmaToateSub&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
           condHolding := &apos;and &apos;||subunitHolding||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate)&apos;;
        end if; 
      end if;
    end if;  
      
    sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(
                       NAV_CodDoc, NAV_TipDoc, NrDoc, DATADOC, VALDOC, TVADOC, VALDOCEFACT, ANWME, LUNAWME,
                       ANSPV, LUNASPV, ID_DESC_WME, ID_DESC_SPV, DEN_PART, DATAINCARCARE, ANDOC,
                       LUNADOC, DATADOCSPV, CIF, STARE_CUI, TIPTRANZ, TIPTVA, LOCALITATE, TARA, DEN_SUBUNIT &apos;||gUserFields||&apos; )&apos;;
    sSelect := &apos;
            select i.codies, i.tipdoc, i.nrdoc, i.datadoc, i.valdoc,i.tvadoc,i.valdocefact, 
                   i.an as anwme, i.luna as lunawme, a.an as anspv, a.luna as lunaspv,
                   i.iddescarcare as idwme, a.iddescarcare as idspv, np.den_part, a.dataincarcare ,
                   coalesce(i.an, a.an),
                   coalesce(i.luna, a.luna),
                   a.DATADOCSPV,
                   coalesce(a.cif_partener, npcfintr.codfiscal),
                   case when NPA.CONTRIBUABIL = 0 then &apos;&apos;CUI neplatitor TVA&apos;&apos;
                        when NPA.CONTRIBUABIL = 1 then &apos;&apos;CUI platitor TVA&apos;&apos;
                        when NPA.CONTRIBUABIL = -1 then &apos;&apos;CUI incorect&apos;&apos;
                        when NPA.CONTRIBUABIL = -2 then &apos;&apos;CUI radiat/inactiv&apos;&apos;
                        else null
                        end,
                   case i.tiptranzactie     
                        when 1 then  &apos;&apos;tranzactie interna&apos;&apos;
                        when 2 then &apos;&apos;livrare intracomunitara&apos;&apos;
                        when 3 then &apos;&apos;export&apos;&apos;
                        when 4 then &apos;&apos;interna - autofacturare&apos;&apos;
                        when 5 then &apos;&apos;factura de decontare&apos;&apos;
                        when 6 then &apos;&apos;monetare&apos;&apos;
                        else null
                   end,
                   case i.tiptva     
                        when  1 then  &apos;&apos;taxare normala&apos;&apos;
                        when  2 then &apos;&apos;taxare inversa&apos;&apos;
                        when  3 then &apos;&apos;tranzactie triunghiulara&apos;&apos;
                        when  4 then &apos;&apos;locul livrarii/prestarii in afara Romaniei&apos;&apos;
                        when  7 then &apos;&apos;regim special de scutire art 311 CF&apos;&apos;
                        when  8 then &apos;&apos;regim special de scutire art 312 CF&apos;&apos;
                        when  5 then &apos;&apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;&apos;
                        when  6 then &apos;&apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;&apos;
                        when  9 then &apos;&apos;bunuri si servicii art.2781&apos;&apos;
                        when 10 then &apos;&apos;Regim special OSS&apos;&apos;
                        when 11 then &apos;&apos;Livrari de bunuri si prestari de servicii scutite cu drept de deducere, prevazute la art. 294 alin. (5) lit. a) si b) din Codul fiscal&apos;&apos;
                        when 12 then &apos;&apos;Livrari de bunuri scutite cu drept de deducere, prevazute la art. 294 alin. (5) lit. c) si d) din Codul fiscal&apos;&apos;
                        when 13 then &apos;&apos;scutite, fara drept drept de ded. art.292&apos;&apos;
                        else null
                   end, loc.den_localit, t.den_tara, nsu.den_subunit   &apos;||gUserAlias||  
            &apos; from iesiri i
              full join spvarhiva a on a.iddescarcare = i.iddescarcare
              left join (  SELECT 
                                  distinct FIRST_VALUE(ncfi.codpart) 
                                           OVER(PARTITION BY ncfi.CODFISCAL 
                                                          order by  np.blocat nulls first, np.inactiv nulls first, ncfi.principal desc  nulls last 
                                                          ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
                                           ) as codpart,
                                           ncfi.CODFISCAL
                            FROM NPARTCODFISC ncfi
                            join npart np on np.codpart = ncfi.codpart ) ncf on upper(trim(ncf.codfiscal)) = upper(trim(a.cif_partener))
              left join npart np on np.codpart = coalesce(i.partener, ncf.codpart) 
              left join NPARTCODFISC npcfintr on npcfintr.cod_codfiscal = i.codfiscal
              left join nagenda nag
                on nag.codagenda = i.codlocatie
              left join nlocalit loc on loc.codlocalit = nag.codlocalit
              left join ntari t on t.codtara = loc.codtara &apos;
              ||joinHolding||
              &apos; left join nsubunit nsu on nsu.codsubunit = &apos; || subunitHolding ||
              &apos; LEFT JOIN (select distinct npi.cui, first_value(npi.contribuabil) over (partition by npi.cui order by npi.contribuabil ) as contribuabil from  NPART_ANAF npi) NPA ON NPA.CUI = REGEXP_REPLACE (coalesce(a.cif_partener, npcfintr.codfiscal), &apos;&apos;[^[:digit:]-]&apos;&apos;)&apos;
              ||gSuplJoins||
              &apos; where (a.tipdoc = 19 or a.tipdoc is null) 
               and (i.tipdoc in (19,26) or i.tipdoc is null) &apos;
              || condHolding ||   
              &apos; and ((i.an *12 + i.luna  BETWEEN &apos;||alStart||&apos; AND &apos;||alStop||&apos;) 
               or (a.an *12 + a.luna  BETWEEN &apos;||alStart||&apos; AND &apos;||alStop||&apos;)) &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    COMMIT;
  END;

  PROCEDURE setJoinuri IS
  BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
  END;

end PKG_LIST_BASE_VERIF_IMP_IES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VERIF_IMP_INTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1BB25BE5061EBD69176C53CB1C6AB1DF221B184</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VERIF_IMP_INTR IS

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  PROCEDURE PROCESSLIST(tmpName  IN VARCHAR2,
                        aLISTID  IN NUMBER DEFAULT 0,
                        aLISTVER IN NUMBER DEFAULT 0) IS
    sInsert VARCHAR2(2000);
    sSelect VARCHAR2(10000);
    anLucru Number(4);
    alStart Number;
    alStop  Number;
    condHolding VARCHAR2(1000);
    joinHolding VARCHAR2(1000);
    subunitHolding VARCHAR2(1000); 
    vSubunit NUMBER(20);
    
  BEGIN
    gSuplCols := &apos;intrari i, npart np, spvarhiva a&apos;;
    pkg_list_struct.StartSuplCols;
    pkg_list_struct.GetSuplCols(aLISTID,
                                alistver,
                                gUserFields,
                                gUserAlias,
                                gNullAlias,
                                gSuplJoins,
                                gSuplCols);
                                
    condHolding := &apos;&apos;;
    joinHolding := &apos;&apos;;
    subunitHolding := &apos;i.subunitatea&apos;;
    if (pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1) then
      vSubunit := PKG_GLOBALS.GETSUBUNITATE;  
      subunitHolding := &apos; coalesce(i.subunitatea, ns.codsubunit) &apos;;
      joinHolding    := &apos; left join nsubunit ns on REGEXP_REPLACE (ns.cif, &apos;&apos;[^[:digit:]-]&apos;&apos;) = a.cif &apos;;
      if (vSubunit &lt;&gt; 0) then
        if (vSubunit &lt;&gt; 1) then
          condHolding := &apos; and &apos;||subunitHolding||&apos; = &apos; || vSubunit;
        ELSIF Coalesce(pkg_categconst.GetValConstanta(&apos;CumulatFirmaToateSub&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),2) = 2 THEN
           condHolding := &apos;and &apos;||subunitHolding||&apos; IN (SELECT codsubunit FROM tmp_subunitdedicate)&apos;;
        end if; 
      end if;
    end if; 
                                
    anLucru := PKG_GLOBALS.ANLUCRU;
    alStart := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNASTART;
    alStop  := anLucru * 12 + PKG_LIST_SELECTLUNA.LUNAFIN;
    sInsert := &apos;INSERT INTO &apos;|| tmpName ||&apos;(
                       NAV_CodDoc, NAV_TipDoc, NrDoc, DATADOC, VALDOC, TVADOC, VALDOCEFACT, ANWME, LUNAWME,
                       ANSPV, LUNASPV, ID_DESC_WME, ID_DESC_SPV, DEN_PART, DATAINCARCARE, ANDOC,
                        LUNADOC, DATADOCSPV, CIF, STARE_CUI, TIPTRANZ, TIPTVA, LOCALITATE, TARA, DEN_SUBUNIT &apos;||gUserFields||&apos; )&apos;;
    sSelect := &apos;
            select i.codintr, i.tipdoc, i.nrdoc, i.datadoc, i.valdoc,i.tvadoc,i.valdocefact, 
                   i.an as anwme, i.luna as lunawme, a.an as anspv, a.luna as lunaspv,
                   i.iddescarcare as idwme, a.iddescarcare as idspv, np.den_part, a.dataincarcare ,
                   coalesce(i.an, a.an),
                   coalesce(i.luna, a.luna),
                   a.DATADOCSPV,
                   coalesce(a.cif_partener, npcfintr.codfiscal),
                   case when NPA.CONTRIBUABIL = 0 then &apos;&apos;CUI neplatitor TVA&apos;&apos;
                        when NPA.CONTRIBUABIL = 1 then &apos;&apos;CUI platitor TVA&apos;&apos;
                        when NPA.CONTRIBUABIL = -1 then &apos;&apos;CUI incorect&apos;&apos;
                        when NPA.CONTRIBUABIL = -2 then &apos;&apos;CUI radiat/inactiv&apos;&apos;
                        else null
                        end,
                   case i.tiptranzactie     
                        when  1 then &apos;&apos;tranzactie interna&apos;&apos;
                        when  2 then &apos;&apos;achizitie intracomunitara&apos;&apos;
                        when  3 then &apos;&apos;import servicii&apos;&apos;
                        when  4 then &apos;&apos;factura de transport taxabila pe DVI&apos;&apos;
                        when  5 then &apos;&apos;factura de decontare&apos;&apos;
                        when  6 then &apos;&apos;monetar&apos;&apos;
                        when  7 then &apos;&apos;Borderou de achizitii&apos;&apos;
                        when  8 then &apos;&apos;Fila carnet producator&apos;&apos;
                        when  9 then &apos;&apos;Contract achizitii&apos;&apos;
                        when 10 then &apos;&apos;Alte documente&apos;&apos;
                        when 11 then &apos;&apos;Arenda&apos;&apos;
                        else null
                   end,
                   case i.tiptva     
                        when 1 then &apos;&apos;taxare normala&apos;&apos;
                        when 2 then &apos;&apos;taxare inversa&apos;&apos;
                        when 3 then &apos;&apos;tranzactie triunghiulara&apos;&apos;
                        when 4 then &apos;&apos;taxare normala Prorata&apos;&apos;
                        when 6 then &apos;&apos;regim special de scutire art 311 CF&apos;&apos;
                        when 7 then &apos;&apos;regim special de scutire art 312 CF&apos;&apos;
                        when 8 then &apos;&apos;achizitii UE de bunuri cu instalare/montaj&apos;&apos;
                        when 9 then &apos;&apos;regim special pt. agricultori (art.315)&apos;&apos;
                        else null
                   end, loc.den_localit, t.den_tara, nsu.den_subunit &apos;||gUserAlias||  
            &apos; from intrari i
              full join spvarhiva a on a.iddescarcare = i.iddescarcare 
              left join (  SELECT 
                                  distinct FIRST_VALUE(ncfi.codpart) 
                                           OVER(PARTITION BY ncfi.CODFISCAL 
                                                          order by  np.blocat nulls first, np.inactiv nulls first, ncfi.principal desc  nulls last 
                                                          ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
                                           ) as codpart,
                                           ncfi.CODFISCAL
                            FROM NPARTCODFISC ncfi
                            join npart np on np.codpart = ncfi.codpart ) ncf on upper(trim(ncf.codfiscal)) = upper(trim(a.cif_partener))
              left join npart np on np.codpart = coalesce(i.partener, ncf.codpart) 
              left join NPARTCODFISC npcfintr on npcfintr.cod_codfiscal = i.codfiscal
              left join nagenda nag
                on nag.codagenda = i.codlocatie
              left join nlocalit loc on loc.codlocalit = nag.codlocalit
              left join ntari t on t.codtara = loc.codtara &apos;
              ||joinHolding||
              &apos; left join nsubunit nsu on nsu.codsubunit = &apos; || subunitHolding ||
              &apos; LEFT JOIN (select distinct npi.cui, first_value(npi.contribuabil) over (partition by npi.cui order by npi.contribuabil ) as contribuabil from  NPART_ANAF npi) NPA ON to_char(NPA.CUI) = REGEXP_REPLACE (coalesce(a.cif_partener, npcfintr.codfiscal), &apos;&apos;[^[:digit:]-]&apos;&apos;)&apos;
              ||gSuplJoins||
              &apos; where (a.tipdoc = 1 or a.tipdoc is null) 
                 and (i.tipdoc in (1,9) or i.tipdoc is null) &apos;
              || condHolding ||  
              &apos;  and ((i.an *12 + i.luna  BETWEEN &apos;||alStart||&apos; AND &apos;||alStop||&apos;) 
               or (a.an *12 + a.luna  BETWEEN &apos;||alStart||&apos; AND &apos;||alStop||&apos;)) &apos;;
    LIST_EXECUTE_IMMEDIATE(sInsert||sSelect, aListID, aListVer);

    COMMIT;
  END;

  PROCEDURE setJoinuri IS
  BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
  END;

end PKG_LIST_BASE_VERIF_IMP_INTR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B73559D87D0DDEDF2B76D9A79FB22C21FF537984</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VOUCHER IS

gUserFields VARCHAR2(3000);
gUserAlias  VARCHAR2(3000);
gNullAlias  VARCHAR2(3000);
gSuplJoins  VARCHAR2(5000);
gSuplCols VARCHAR2(5000);

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(10000);
  sSelect VARCHAR2(10000);
BEGIN
  gSuplCols := &apos;VOUCHER V,VOUCHERLINK VL&apos;;  
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
       OBS,     
       PART,    
       DATASTART,
       DATASTOP,
       MONEDA,  
       VALOARE,
       REST,
       GestFol,
       GestEmit,
       NrDataRez,
       ValoareUt,
       NAV_CodDoc, 
       NAV_TipDoc&apos;||gUserFields||&apos;
   )&apos;;

  sSelect := &apos;
  SELECT
      V.OBS,
      P.DEN_PART,
      V.DATASTART,
      V.DATASTOP,
      M.SIMBOL,
      V.VALOARE,
      V.VALOARE - Nvl(X.FOLOSIT,0) REST,
      NF.Den_gest GestFol,
      NE.Den_gest GestEmit,
      CMDVL.NRDOc||&apos;&apos; / &apos;&apos;||CMDVL.DataDoc NrDataRez,
      VL.Valoare ValoareUt,
      V.CodVoucher, 99&apos;||gUserAlias||&apos;
  FROM VOUCHER V
         INNER JOIN NPART P on P.CodPART = Nvl(V.CODPARTENER,0)
         INNER JOIN NMONEDE M on M.CodMoneda = Nvl(V.Moneda,0)
         LEFT JOIN (Select CodVoucher, Sum(Valoare) FOLOSIT from VOUCHERLINK group by CodVoucher) X on X.CodVoucher = V.Codvoucher
         LEFT JOIN VOUCHERLINK VL on VL.CodVoucher = V.CODVOUCHER
         LEFT JOIN COMANDA1 CMDVL1 on CMDVL1.CodComanda1 = VL.CodCmD
         LEFT JOIN COMANDA CMDVL on CMDVL.CodComanda = CMDVL1.CodComanda
         LEFT JOIN RAC_REZ RRVL on RRVL.codcomanda=CMDVL.codcomanda
         LEFT JOIN NGEST NF on NF.CodGest = RRVL.CodGestSursa
         LEFT JOIN NGEST NE on NE.CodGest = V.CodGest&apos;||gSuplJoins;
  EXECUTE IMMEDIATE sInsert||sSelect;
  COMMIT;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

end PKG_LIST_BASE_VOUCHER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHERDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC0F77C8E4246248D56EB40CF8A4F805BEDBEF0B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VOUCHERDOC IS

  vCodDoc     NUMBER(20);

  gUserFields VARCHAR2(2500);
  gUserAlias  VARCHAR2(2500);
  gNullAlias  VARCHAR2(2500);
  gSuplCols   VARCHAR2(2500);
  gSuplJoins  VARCHAR2(5000);

  vDataS       DATE;
  vDataF       DATE;

PROCEDURE SETPARAMS( pCodDoc IN NUMBER) IS
BEGIN
  vCodDoc := pCodDoc;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
  sInsert VARCHAR2(30000);
BEGIN
  gSuplCols := &apos;COMANDA CMD, RAC_REZ RAC, VOUCHER V&apos;;

  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert:=
  &apos;INSERT INTO &apos;||tmpName|| &apos;(
    OBS, PART, DATASTART, DATASTOP, MONEDA, Valoare, Rest,GestFol,GestEmit,NrDataRez,ValoareUt&apos;||
    gUserFields||&apos;)
  SELECT
    V.OBS, P.DEN_PART, V.DATASTART, V.DATASTOP, M.SIMBOL, V.VALOARE, V.VALOARE - Nvl(X.FOLOSIT,0) REST,
    NF.Den_gest GestFol,
    NE.Den_gest GestEmit,
    CMDVL.NRDOc||&apos;&apos; / &apos;&apos;||CMDVL.DataDoc NrDataRez,
    VL.Valoare ValoareUt
    &apos;||gUserAlias||&apos;
  FROM VOUCHER V
    INNER JOIN NPART P on P.CodPART = Nvl(V.CODPARTENER,0)
    INNER JOIN NMONEDE M on M.CodMoneda = Nvl(V.Moneda,0)
    LEFT JOIN (Select CodVoucher, Sum(Valoare) FOLOSIT from VOUCHERLINK group by CodVoucher) X on X.CodVoucher = V.Codvoucher
    LEFT JOIN RAC_REZ RAC on RAC.CodVoucher = V.CodVoucher
    LEFT JOIN COMANDA CMD on CMD.CodComanda = RAC.CodComanda
    LEFT JOIN VOUCHERLINK VL on VL.CodVoucher = V.CODVOUCHER
    LEFT JOIN COMANDA1 CMDVL1 on CMDVL1.CodComanda1 = VL.CodCmD
    LEFT JOIN COMANDA CMDVL on CMDVL.CodComanda = CMDVL1.CodComanda
    LEFT JOIN RAC_REZ RRVL on RRVL.codcomanda=CMDVL.codcomanda
    LEFT JOIN NGEST NF on NF.CodGest = RRVL.CodGestSursa
    LEFT JOIN NGEST NE on NE.CodGest = V.CodGest
    &apos;||gSuplJoins||&apos;
  WHERE V.CODVOUCHER = &apos;||vCodDoc ;

  Delete from X;
  Insert into X values (&apos;voucherdoc&apos;, sInsert);
  Commit;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);
  pkg_list_base_VoucherDoc.add_list_params;

  COMMIT;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

 For v_rec IN (
    SELECT P.Den_part, V.Valoare, v.DataStart, V.DataStop, M.Den_moneda Moneda,G.Den_Gest AgentiaEmitenta,V.Obs
    FROM VOUCHER V
        LEFT JOIN NPART P on P.CodPart = V.CodPartener
        LEFT JOIN NMONEDE M ON M.CODMONEDA = V.Moneda
        LEFT JOIN RAC_REZ RAC on RAC.CodVoucher = V.CodVoucher
        LEFT JOIN NGEST G on G.CodGEST = V.CodGEST
     where V.CODVOUCHER = vCodDoc
  ) LOOP
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_PARTENER&apos;,             v_rec.DEN_PART);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_VALOARE&apos;,              v_rec.Valoare);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_Moneda&apos;,               v_rec.Moneda);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_DataStart&apos;,            v_rec.DataStart);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_DataStop&apos;,             v_rec.DataStop);
      pkg_list_Struct.ADAUGA_PARAM(&apos;Vouch_AgentiaEmitenta&apos;,      v_rec.AgentiaEmitenta);
     pkg_list_Struct.ADAUGA_PARAM(&apos;Obs&apos;,                         v_rec.Obs);
      EXIT;
    END LOOP;
END;

PROCEDURE setJoinuri IS
BEGIN
    Pkg_List_Struct.SetTableSpec(gSuplCols);
    pkg_list_struct.AdunaColoanele;
END;

end pkg_list_base_VOUCHERdoc;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_BASE_VOUCHERINC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5F5F6CB0C6DE719952AB53BB675C8AA4118254F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_BASE_VOUCHERINC is

  gUserFields      VARCHAR2(2500);
  gUserAlias       VARCHAR2(2500);
  gNullAlias       VARCHAR2(2500);
  gSuplCols        VARCHAR2(2500);
  gSuplJoins       VARCHAR2(5000);
  vLISTID          NUMBER(10);
  vLISTVER         NUMBER(10);
  vCod             NUMBER(20);

PROCEDURE SETPARAMS(pCodVoucher IN NUMBER) IS
BEGIN
  vCod := pCodVoucher;
END;

PROCEDURE setJoinuri IS
BEGIN
  pkg_list_struct.SetTableSpec(gSuplCols);
  pkg_list_struct.AdunaColoanele;
END;

PROCEDURE ADD_LIST_PARAMS IS
BEGIN
  pkg_list_Struct.GOLESTE_PARAM;

  FOR v_rec IN (
    SELECT
      COD_CASTOTUTILITY,
      FURNIZOR,
      SERVICIU,
      DEPLATA,
      PLATIT,
      PLATIT_TEXT,
      COD_SCALA,
      DATATRANZACTIE,     
      CODCLIENT,
      TELEFON,
      NRFACTURA,
      DATAFACTURA,
      SUCURSALA,
      ATMCOD,
      CUSTOMCODE1,
      CUSTOMPAYMENTFIELD3,
      JSONRESPONSE,
      LISTAT
    FROM CASTOT_UTILITY CU
    WHERE CU.COD_CASTOTUTILITY = vCod
  ) LOOP
    pkg_list_Struct.ADAUGA_PARAM(&apos;Partener&apos;,           v_rec.FURNIZOR);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Serviciu&apos;,           v_rec.SERVICIU);
    pkg_list_Struct.ADAUGA_PARAM(&apos;De plata&apos;,           TO_CHAR(v_rec.DEPLATA,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Platit&apos;,             TO_CHAR(v_rec.PLATIT,&apos;fm9G999G999G990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;,.&apos;&apos;&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Platit litere&apos;,      v_rec.PLATIT_TEXT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Chitanta&apos;,           v_rec.COD_SCALA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data tranzactie&apos;,    v_rec.DATATRANZACTIE);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Cod client&apos;,         v_rec.CODCLIENT);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Nr. factura&apos;,        v_rec.NRFACTURA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Data factura&apos;,       to_char(v_rec.DATAFACTURA,&apos;dd.mm.yyyy hh24:mi&apos;));
    pkg_list_Struct.ADAUGA_PARAM(&apos;Sucursala&apos;,          v_rec.SUCURSALA);
    pkg_list_Struct.ADAUGA_PARAM(&apos;ATM cod&apos;,            v_rec.ATMCOD);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Telefon&apos;,            v_rec.telefon);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Custom cod&apos;,         v_rec.CUSTOMCODE1);
    pkg_list_Struct.ADAUGA_PARAM(&apos;Custom payment field&apos;, v_rec.CUSTOMPAYMENTFIELD3);
  END LOOP;
END;

PROCEDURE PROCESSLIST(tmpName IN VARCHAR2,aLISTID IN NUMBER DEFAULT 0,aLISTVER IN NUMBER DEFAULT 0) IS
sInsert varchar2(5000);  
BEGIN
  PKG_LIST_STRUCT.GOLESTE_PARAM;
  pkg_list_struct.StartSuplCols;
  pkg_list_struct.GetSuplCols(aLISTID,alistver,gUserFields,gUserAlias,gNullAlias,gSuplJoins,gSuplCols);

  sInsert :=
  &apos;INSERT INTO &apos;||TMPNAME||&apos;(
    COD_CASTOTUTILITY,
    FURNIZOR,
    SERVICIU,
    DEPLATA,
    PLATIT,
    PLATIT_TEXT,
    COD_SCALA,
    DATATRANZACTIE,     
    CODCLIENT,
    TELEFON,
    NRFACTURA,
    DATAFACTURA,
    SUCURSALA,
    ATMCOD,
    CUSTOMCODE1,
    CUSTOMPAYMENTFIELD3,
    JSONRESPONSE,
    LISTAT
    &apos;||gUserFields||&apos;)
  SELECT
    COD_CASTOTUTILITY,
    FURNIZOR,
    SERVICIU,
    DEPLATA,
    PLATIT,
    PLATIT_TEXT,
    COD_SCALA,
    DATATRANZACTIE,     
    CODCLIENT,
    TELEFON,
    NRFACTURA,
    DATAFACTURA,
    SUCURSALA,
    ATMCOD,
    CUSTOMCODE1,
    CUSTOMPAYMENTFIELD3,
    JSONRESPONSE,
    LISTAT&apos;||gUserAlias||&apos;
  FROM CASTOT_UTILITY&apos;||gSuplJoins||&apos;
  WHERE COD_CASTOTUTILITY = &apos;||vCod;

  LIST_EXECUTE_IMMEDIATE(sInsert, aListID, aListVer);

  PKG_LIST_BASE_VOUCHERINC.add_list_params;
  COMMIT;
END;

end PKG_LIST_BASE_VOUCHERINC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_CASABANKA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>650934556AE3AB3FEAE730DDEA7056EB31C04C2A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_casabanka IS

  p_DataIni DATE;
  p_DataFin DATE;
  p_tipDoc  NUMBER(2);

PROCEDURE setParams(v_DataIni IN VARCHAR2,
                    v_DataFin IN VARCHAR2,
                    v_tipDoc  IN NUMBER,
	                  pCodJob1 IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  p_DataIni := to_date(v_DataIni,&apos;DD.MM.YYYY&apos;);
  p_DataFin := to_date(v_DataFin,&apos;DD.MM.YYYY&apos;);
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,p_DataIni,p_DataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  p_tipDoc  := v_tipDoc;
END;

FUNCTION getDataIni RETURN DATE IS
BEGIN
  RETURN p_DataIni;
END;

FUNCTION getDataFin RETURN DATE IS
BEGIN
  RETURN p_DataFin;
END;

FUNCTION getTipDoc RETURN NUMBER IS
BEGIN
  RETURN p_tipDoc;
END;

FUNCTION getAllCasa(pLei IN Boolean DEFAULT NULL) RETURN crs IS
  crs_casa crs;
  vSelect  VARCHAR2(9000);
  vCondLei VARCHAR2(500);
  vCondSub VARCHAR2(500);
BEGIN
  IF pLei IS NOT NULL THEN
    IF pLei
    THEN vCondLei := &apos;AND nbc.codmoneda = 0 &apos;;
    ELSE vCondLei := &apos;AND nbc.codmoneda &lt;&gt; 0 &apos;;
    END IF;
  END IF;

  IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 THEN
    vCondSub := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;nbc&apos;);
  END IF;

  vSelect :=
  &apos;WITH nbc1 AS (
    SELECT codbankcont, MAX(codiobanca) KEEP (DENSE_RANK LAST ORDER BY  ANSTART, LUNASTART) codiobanca
    FROM nbankcont1
    WHERE ANSTART*12+LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
    GROUP BY codbankcont   
   ),
   IOB1 AS (
    SELECT codiobank, MAX(cont) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) cont
    FROM iobank1
    WHERE ANSTART*12+LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
    GROUP BY codiobank   
   ) 
  SELECT nbc.codbankcont, nb.simbol, nbc.den_cont denumire, mon.codmoneda, mon.simbol moneda, mon.den_moneda, c.simbol contrepr,
         s.den_subunit
  FROM nbankcont nbc
		INNER JOIN nbank nb ON nb.codbank = nbc.codbank
    INNER JOIN tmp_conturidedicate cd ON cd.codbankcont = nbc.codbankcont
    LEFT JOIN nmonede mon ON mon.codmoneda = nbc.codmoneda
    LEFT JOIN nbc1 ON nbc1.codbankcont = nbc.codbankcont
    LEFT JOIN iob1 ON iob1.codiobank = nbc1.codiobanca
    LEFT JOIN ncont c ON c.codcont = NVL(iob1.cont,0)
    LEFT JOIN nsubunit s on s.codsubunit = nbc.subunitatea
  WHERE nb.codbank = 1 &apos;||vCondLei||vCondSub||&apos;
  ORDER BY nbc.den_cont &apos;;

	OPEN crs_casa FOR vSelect;
  RETURN crs_casa;
END;

FUNCTION getAllBanca(pLei IN Boolean DEFAULT NULL) RETURN crs IS
  crs_bank crs;
  vSelect  VARCHAR2(9000);
  vCondLei VARCHAR2(500);
  vCondSub VARCHAR2(500);
BEGIN
  IF pLei IS NOT NULL THEN
    IF pLei
    THEN vCondLei := &apos;AND nbc.codmoneda = 0 &apos;;
    ELSE vCondLei := &apos;AND nbc.codmoneda &lt;&gt; 0 &apos;;
    END IF;
  END IF;

  IF pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) = 1 THEN
    vCondSub := PKG_LIST_BASE_UTILS.COND_SUBUNIT(&apos;nbc&apos;);
  END IF;

  vSelect :=
  &apos;WITH nbc1 AS (
    SELECT codbankcont, MAX(codiobanca) KEEP (DENSE_RANK LAST ORDER BY  ANSTART, LUNASTART) codiobanca
    FROM nbankcont1
    WHERE ANSTART*12+LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
    GROUP BY codbankcont   
   ),
   IOB1 AS (
    SELECT codiobank, MAX(cont) KEEP (DENSE_RANK LAST ORDER BY ANSTART, LUNASTART) cont
    FROM iobank1
    WHERE ANSTART*12+LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
    GROUP BY codiobank   
   ) 
  SELECT nbc.codbankcont, nb.simbol, nbc.den_cont denumire, nbc.nrcont, nbc.credit, mon.codmoneda, mon.simbol moneda, mon.den_moneda, c.simbol contrepr,
         s.den_subunit
  FROM nbankcont nbc
    INNER JOIN nbank nb ON nb.codbank = nbc.codbank
    INNER JOIN tmp_conturidedicate cd ON cd.codbankcont = nbc.codbankcont
    LEFT JOIN nmonede mon ON nbc.codmoneda = mon.codmoneda
    LEFT JOIN nbc1 ON nbc1.codbankcont = nbc.codbankcont
    LEFT JOIN iob1 On iob1.codiobank = nbc1.codiobanca
    LEFT JOIN ncont c ON c.codcont = NVL(iob1.cont,0)
    LEFT JOIN nsubunit s on s.codsubunit = nbc.subunitatea
  WHERE nbc.codbank &lt;&gt; 1 &apos;||vCondLei||vCondSub||&apos;
  ORDER BY nb.simbol, nbc.den_cont &apos;;

  OPEN crs_bank FOR vSelect;
  RETURN crs_bank;
END;

end PKG_LIST_CASABANKA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_CONFIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37F07A3F2068E8A89DA42CDE649730DEAF43092B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_CONFIG IS

FUNCTION get_id_header RETURN NUMBER IS
BEGIN
  RETURN -1 * pkg_list_Config.gr_id_header;
END;

FUNCTION get_id_footer RETURN NUMBER IS
BEGIN
  RETURN pkg_list_Config.gr_id_footer;
END;

FUNCTION CautaColoana (sCol IN VARCHAR2, sSirColoane IN CLOB, desc_ OUT BOOLEAN ) RETURN BOOLEAN IS
  sResult       BOOLEAN := FALSE;
  sirTemp       CLOB;
  coloanaDinSir CLOB;
BEGIN
  sirTemp := sSirColoane||&apos;,&apos;;
  WHILE length(sirTemp) &gt; 0 LOOP
    coloanaDinSir := SUBSTR(SirTemp,1,instr(sirTemp,&apos;,&apos;)-1);
    IF coloanaDinSir  = sCol || &apos; DESC&apos; THEN
      Desc_   := TRUE;
      sResult := TRUE;
    ELSIF coloanaDinSir = sCol THEN
      Desc_   := FALSE;
      sResult := TRUE;
    END IF;
    sirTemp := substr(sirTemp,length(ColoanaDinSir)+2,length(SirTemp));
  END LOOP;

  RETURN sResult ;
END;

FUNCTION ScoateColoanaDinSir (sCol IN VARCHAR2, sSirColoane IN CLOB) RETURN CLOB IS
  sResult CLOB;
  ColTemp CLOB;
  sirTemp CLOB;
  virgula VARCHAR2(1);
  desc_   BOOLEAN;
BEGIN
  IF instr(sSirColoane,sCol||&apos;,&apos;)=1 THEN --coloana de eliminat e prima din sir
   sResult := substr(sSirColoane,length(sCol)+2,length(sSirColoane));
  ELSE
    IF CautaColoana(sCol,sSirColoane,desc_) THEN
      ColTemp := &apos;,&apos;||sCol||&apos;,&apos;;
      sirTemp := &apos;,&apos;||sSirColoane||&apos;,&apos;;
      sirTemp := substr(sirTemp,1,instr(sirTemp,ColTemp)-1)||&apos;,&apos;||substr(sirTemp,instr(sirTemp,colTemp)+length(colTemp),length(sirTemp));
      sirTemp := substr(sirTemp,2,length(sirTemp));
      virgula := substr(sirtemp,length(sirtemp),1);
      IF  virgula = &apos;,&apos; THEN
        sirTemp := substr(sirTemp,1,length(sirTemp)-1);
      END IF;
      sResult := sirTemp;
    ELSE
     sResult := sSirColoane;
    END IF;
  END IF;
  RETURN sResult;
END;

--returneaza numaru grupului.....utila pentru generarea nrskip
FUNCTION Get_Group_id(nrcrt IN NUMBER) return NUMBER is
  GR_ID NUMBER;
  str CLOB;
BEGIN
  IF nrcrt &lt;= -1*pkg_list_Config.gr_id_header THEN
    gr_id := round(log(2,abs( pkg_list_Config.gr_id_header+nrcrt)+1))+1;
  ELSIF nrcrt &gt;= pkg_list_Config.gr_id_footer THEN
    gr_id := round(log(2,abs( nrcrt-pkg_list_Config.gr_id_footer)+1))+1;
  END IF;
  RETURN gr_id;
END;

FUNCTION GET_COL_TYPE (sCol VARCHAR2 , sTab VARCHAR2) RETURN VARCHAR2 IS
  sType VARCHAR2(50);
BEGIN
  SELECT DATA_TYPE INTO sType FROM USER_TAB_COLUMNS WHERE TABLE_NAME=Upper(sTab) AND COLUMN_NAME=upper(sCol);
  RETURN sType;
END;

FUNCTION getColoanefromExpresii (calc_cols VARCHAR2,nrCols OUT NUMBER) RETURN VARCHAR2 IS
  sResult CLOB;
  idx NUMBER(20);
  tmp VARCHAR2 (10000);
  aCol VARCHAR2(50);
  aExp CLOB;
begin
  tmp := calc_cols;
  nrCols := 0;

  WHILE length(TRIM(tmp)) &gt; 0 LOOP
    idx := instr(tmp,&apos;;&apos; );

    IF idx = 0 THEN
      idx := length(tmp)+1;
    END IF;

    aExp := substr(tmp,1,idx-1);
    acol := substr(aExp,instr(aExp,&apos;)&apos;,-1,1)+1);
    sRESULT := sResult ||&apos;,&apos;||acol;

    nrcols := nrcols + 1;
    tmp := substr(tmp,idx+1,length(tmp));
  END LOOP;

  sResult := substr(sResult,2,length(sResult));
  RETURN sRESULT;
END;

/* pentru coloanele - expresii pentru care am si sume la nivel de grup*/
FUNCTION get_sum_calc (sum_calc VARCHAR2, fara_total VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
  idx NUMBER(2);
  str CLOB;
  sResult CLOB:=&apos;&apos;;
  coloana CLOB;
  nr NUMBER(2);
  vFaraTotal CLOB := TRIM(fara_total);
BEGIN
  str := sum_calc;
  idx:=instr(str,&apos;;&apos;);
  IF idx = 0 AND length(str)&gt;0 THEN
    -- STEF din motive de formatare liste a trebuit sa introduc conditia de filtarare fara total IN SUM cu ajutorul CASE
    -- aceasta se intampla IN cazul listelos cu Grupare si Total
    IF vFaraTotal IS NULL THEN
      sResult:=&apos;SUM&apos;||substr(str,1,instr(str,&apos;)&apos;))||substr(str,instr(str,&apos;)&apos;)+1,length(str)) ;
    ELSE
      sResult:=&apos;SUM(CASE WHEN &apos;||vFaraTotal||&apos; THEN &apos;||substr(str,1,instr(str,&apos;)&apos;))||&apos; ELSE 0 END) &apos;||substr(str,instr(str,&apos;)&apos;)+1,length(str)) ;
    END IF;

  ELSE
    WHILE idx &gt; 0 LOOP
      IF vFaraTotal IS NULL THEN
        sResult:=sResult||&apos;SUM&apos;||substr(str,1,instr(str,&apos;)&apos;))||getColoanefromExpresii(substr(str,1,idx-1),nr)||&apos;,&apos; ;
      ELSE
        sResult:=sResult||&apos;SUM(CASE WHEN &apos;||vFaraTotal||&apos; THEN &apos;||substr(str,1,instr(str,&apos;)&apos;))||&apos; ELSE 0 END) &apos;||getColoanefromExpresii(substr(str,1,idx-1),nr)||&apos;,&apos; ;
      END IF;
      str := substr (str,idx+1);
      idx:= instr (str,&apos;;&apos;);
      IF idx = 0 AND length(str) &gt; 0 THEN
        IF vFaraTotal IS NULL THEN
          sResult:=sResult||&apos;SUM&apos;||substr(str,1,instr(str,&apos;)&apos;))||substr(str,instr(str,&apos;)&apos;)+1,length(str)) ;
        ELSE
          sResult:=sResult||&apos;SUM(CASE WHEN &apos;||vFaraTotal||&apos; THEN &apos;||substr(str,1,instr(str,&apos;)&apos;))||&apos; ELSE 0 END) &apos;||substr(str,instr(str,&apos;)&apos;)+1,length(str)) ;
        END IF;
      END IF;
    END LOOP;
  END IF;

  RETURN sResult;
END;

/*extrag coloanele care nu sunt IN sum_calc dar sunt IN calc_cols*/
FUNCTION getColoanefromCalcCols (sum_calc IN VARCHAR2,calc_cols IN VARCHAR2) RETURN VARCHAR2 IS
  idxs NUMBER(2);
  sCols CLOB;
  cCols CLOB;
  sResult VARCHAR2 (100):=&apos;&apos;;
  nrColsSuma NUMBER(2);
  nrColsCalc NUMBER(2);
  col CLOB;
  idxc NUMBER (2);
BEGIN
  sCols := getColoanefromExpresii(sum_calc,nrColsSuma);
  cCols := getColoanefromExpresii(calc_cols,nrColsCalc);

  idxs := instr(sCols,&apos;;&apos;);
  IF idxs = 0 AND length(sCols)&gt;0 THEN --am o singura coloana IN sCols
    idxc := instr(cCols,sCols);
    IF idxc = 1 THEN
      sRESULT := substr(cCols,idxc+length(sCols)+1,length(cCols));
    ELSE
       sResult := substr(cCols,1,idxc-2);
       sResult:=sResult||substr(cCols,idxc+1,length(cCols));
    END IF;
  ELSE
    WHILE idxs &gt; 0 LOOP
      col:=substr(sCols,1,idxs-1);
      idxc := instr(cCols,col);
      sResult := substr(cCols,1,idxc-1);
      sResult := sResult||substr(cCols,length(col)+idxc+1,length(cCols));
      sCols:=Substr(sCols,idxs+1,length(sCols));
      idxs := instr(sCols,&apos;;&apos;);
      cCols:=sResult;
      IF idxs = 0 AND length(sCols)&gt;0 THEN
        idxc := instr(cCols,sCols);
        IF idxc = 1 THEN
           sRESULT := substr(cCols,idxc+length(sCols)+1,length(cCols));
        ELSE
           sResult := substr(cCols,1,idxc-2);
           sResult:=sResult||substr(cCols,idxc+1,length(cCols));
        END IF;
      END IF;
    END LOOP;
  END IF;
  RETURN sResult;
END;

/*Preia o lista de coloane(a,b) si returneaza null a, null b, ... */
FUNCTION FormatNULLString (sCols IN VARCHAR2) RETURN VARCHAR2 IS
  idx NUMBER(2);
  cols CLOB;
  sResult CLOB;
BEGIN
  cols:=sCols;
  idx := instr(cols,&apos;;&apos;);
  IF idx = 0 AND length (cols) &gt; 0 THEN
    sResult := &apos;NULL &apos;||cols;
  ELSE
    WHILE idx &gt; 0 LOOP
      sResult :=sResult||&apos;NULL &apos;||substr(cols,1,idx-1)||&apos;, &apos;;
      cols := substr(cols,idx+1,length(cols));
      idx := instr(cols,&apos;;&apos;);
      IF idx = 0 AND length (cols) &gt; 0 THEN
         sResult :=sResult|| &apos;NULL &apos;||cols;
      END IF;
    END LOOP;
  END IF;
  RETURN sResult;
END;

FUNCTION GET_EXPRESII(calc_cols VARCHAR2 , expr_lst VARCHAR2) RETURN VARCHAR2 IS ---NU o mai folosesc
  idx NUMBER(2);
  j NUMBER(2);
  col_name VARCHAR2(50);
  expr CLOB;
  sResult VARCHAR2(1000):=&apos;&apos;;
  cols CLOB;
  expresii CLOB;
BEGIN
  cols := calc_cols;
  expresii := expr_lst;
  idx := instr(cols,&apos;,&apos;);
  j := instr(expresii,&apos;,&apos;);
  IF idx = 0 AND length(cols) &gt; 0 THEN
    sResult := expresii||&apos; &apos;||cols;
  ELSE
    WHILE idx &gt; 0 LOOP
      col_name :=  substr(cols,1,idx-1);
      expr :=  substr(expresii,1,j-1);
      sResult:=sResult||expr||&apos; &apos;||col_name||&apos;,&apos;;
      cols:=substr(cols,idx+1,length(cols));
      expresii:=substr(expresii,j+1,length(expresii));
      idx := instr(cols,&apos;,&apos;);
      j   := instr(expresii,&apos;,&apos;);
      IF idx = 0 AND length(cols) &gt; 0 THEN
        sResult := sResult||expresii||&apos; &apos;||cols;
      END IF;
    END LOOP;
  END IF;
  RETURN sResult;
END;

--RETURNEAZA CLAUZELE ROW_NUMBER
function getRowNumClause (sCols IN VARCHAR2,nrCols out NUMBER) return VARCHAR2 is
  sResult VARCHAR2(25000);
  i number(2);
  idx number (2) :=1 ;
  col_name CLOB:=&apos;&apos;;
  cols CLOB :=&apos;&apos;;
  str CLOB;
begin
  str := UPPER(sCols);
  i   := instr(str,&apos;,&apos;);
  IF (i = 0) and length(str) &gt; 0 THEN
          sResult:= &apos;ROW_NUMBER() OVER (PARTITION BY &apos;||replace(STR,&apos; DESC&apos;,&apos; &apos;)||&apos; ORDER BY &apos;||STR||&apos;,ROWNUM ) NRCRT_&apos;||IDX||&apos;,&apos;;
  ELSE
    WHILE i &gt; 0 LOOP
      col_name :=substr(str,1,i-1);
      cols := cols||&apos;,&apos;||col_name;
      str := substr(str,i+1,length(str));
      i := instr(str,&apos;,&apos;);
      sResult:= sResult||&apos; ROW_NUMBER() OVER (PARTITION BY &apos;||replace(substr(cols,2,length(cols)),&apos; DESC&apos;,&apos; &apos;)||
                   &apos; ORDER BY &apos;||substr(cols,2,length(cols))||&apos;,ROWNUM ) NRCRT_&apos;||IDX||&apos;,&apos;;
      idx:=idx+1;
      IF (i=0) and (length(str)&gt;0) THEN
        col_name:=STR;
        cols := cols||&apos;,&apos;||col_name;
        sResult:= sResult||&apos; ROW_NUMBER() OVER (PARTITION BY &apos;||replace(substr(cols,2,length(cols)),&apos; DESC&apos;,&apos; &apos;)||
                   &apos; ORDER BY &apos;||substr(cols,2,length(cols))||&apos;,ROWNUM ) NRCRT_&apos;||IDX||&apos;,&apos;;
        idx:=idx;
      END IF;
    END LOOP;
  END IF;
  nrCols:=idx;
  sResult:=substr(sResult,1,length(sResult)-1);
  RETURN sResult;
END;

procedure PrelucreazaColCalc(pColoaneCalc IN out VARCHAR2,
                             pSumCalc IN out VARCHAR2,
                             pSumHeaderFooter IN out VARCHAR2,
                             fara_total VARCHAR2 DEFAULT NULL )  is

sCalc CLOB;
sSumCalc CLOB;

aColCalc CLOB;
aColSumCalc CLOB;
i number(20);
idx number(20);

begin

 sCalc    := pColoaneCalc||&apos;;&apos;;
 sSumCalc := pSumCalc||&apos;;&apos;;

 pColoaneCalc :=&apos;&apos;;
 pSumCalc     :=&apos;&apos;;
 pSumHeaderFooter := &apos;&apos;;
 idx:=instr(sCalc,&apos;;&apos;);

WHILE idx &gt; 0  LOOP

 aColCalc    := substr(sCalc,1,instr(sCalc,&apos;;&apos;)-1);
 aColSumCalc := substr(sSumCalc,1,instr(sSumCalc,&apos;;&apos;)-1);

 IF getColoanefromExpresii(aColCalc,i) = getColoanefromExpresii(aColSumCalc,i) THEN
   pColoaneCalc     := pColoaneCalc||aColCalc||&apos;,&apos;;
   pSumCalc         := pSumCalc ||get_sum_calc(aColSumCalc,fara_total )||&apos;,&apos;;
   pSumHeaderFooter := pSumHeaderFooter ||getColoanefromExpresii(aColSumCalc,i)||&apos;,&apos;;

  sCalc            := substr(sCalc,instr(sCalc,&apos;;&apos;)+1,length(sCalc));
  sSumCalc         := substr(sSumCalc,instr(sSumCalc,&apos;;&apos;)+1,length(sSumCalc));


 ELSE
  pColoaneCalc     := pColoaneCalc||aColCalc||&apos;,&apos;;
  pSumCalc         := pSumCalc||&apos;NULL,&apos;;
  pSumHeaderFooter :=  pSumHeaderFooter ||&apos;NULL,&apos;;

  sCalc := substr(sCalc,instr(sCalc,&apos;;&apos;)+1,length(sCalc));

 END IF;


 idx := instr(sCalc,&apos;;&apos;);
END LOOP;

END;
-- Returneaza clauzele dense_rank()....nr coloane grup=nr clauze dense_rank()
function getDenseRankClause (sCols IN VARCHAR2, nrCols out number) return VARCHAR2 is
  SRESULT VARCHAR2(9000);
  I NUMBER(2);
  IDX NUMBER (2) :=1 ;
  COL_NAME VARCHAR2(50):=&apos;&apos;;
  STR CLOB;
  ORD  CLOB;
  PART CLOB ;
BEGIN
  STR := UPPER(SCOLS);
  I := INSTR (STR,&apos;,&apos;);
  IF (I = 0) AND LENGTH(STR) &gt; 0 THEN -- AND O COLOANA IN GRUP
    SRESULT:= &apos; DENSE_RANK() OVER ( ORDER BY &apos;||STR||&apos; ) NRG_&apos;||IDX||&apos;,&apos;;
  ELSE
    WHILE I &gt; 0 LOOP
      COL_NAME :=SUBSTR(STR,1,I-1);
      ORD      := COL_NAME;

      IF PART IS NULL THEN
           SRESULT := SRESULT ||&apos; DENSE_RANK() OVER ( ORDER BY &apos;||ORD||&apos; ) NRG_&apos;||IDX||&apos;,&apos;;
      ELSE
           SRESULT := SRESULT ||&apos; DENSE_RANK() OVER ( PARTITION BY &apos;||Replace(SUBSTR(PART,1,LENGTH(PART)-1),&apos; DESC&apos;,&apos;&apos;)||&apos; ORDER BY &apos;||ORD||&apos; ) NRG_&apos;||IDX||&apos;,&apos;;
      END IF;
      PART := PART ||ORD||&apos;,&apos;;
      STR :=  substr(str,i+1,length(str));
      I := INSTR (STR,&apos;,&apos;);
      IDX := IDX + 1;

      IF (I=0) AND ( LENGTH(STR) &gt; 0 ) THEN
       ORD := STR;
       SRESULT := SRESULT ||&apos; DENSE_RANK() OVER ( PARTITION BY &apos;||replace(SUBSTR(PART,1,LENGTH(PART)-1),&apos; DESC&apos;,&apos;&apos;)||&apos; ORDER BY &apos;||ORD||&apos; ) NRG_&apos;||IDX||&apos;,&apos;;
      END IF;
    END LOOP;
  END IF ;

  NRCOLS := IDX;
  sResult:=substr(sResult,1,length(sResult)-1);
  RETURN sResult;
END;

--returneaza clauza NVL IN functie de tipul unei coloane (VARCHAR2,NUMBER,DATE,CHAR)
procedure GetNVLClause(tab IN VARCHAR2, sCol IN VARCHAR2, sNVL_header out VARCHAR2, sNVL_footer out VARCHAR2, sWhere out VARCHAR2, DESC_ IN BOOLEAN DEFAULT FALSE) is
  sType VARCHAR2(50);
begin
  sType:=GET_COL_TYPE(sCol,tab);
  IF (UPPER(sType)=&apos;VARCHAR2&apos;) OR (UPPER(sType)=&apos;CHAR&apos;) THEN
    sNVL_header :=&apos;Coalesce(&apos;||sCol||&apos;,CHR(0))&apos;;
    sNVL_footer :=&apos;Coalesce(&apos;||sCol||&apos;,CHR(255))&apos;;
    IF desc_
    THEN sWhere := &apos;= CHR(255) AND&apos;;
    ELSE sWhere := &apos;= CHR(0) AND&apos;;
    END IF;
  ELSIF UPPER(sType)=&apos;NUMBER&apos; THEN
    sNVL_header :=&apos;Coalesce(&apos;||sCol||&apos;,-9999999999999999999)&apos;;
    sNVL_footer :=&apos;Coalesce(&apos;||sCol||&apos;, 9999999999999999999)&apos;;
    IF desc_
    THEN sWhere := &apos;= 9999999999999999999 AND&apos;;
    ELSE sWhere := &apos;=-9999999999999999999 AND&apos;;
    END IF;
  ELSIF UPPER(sType)=&apos;DATE&apos; THEN
    sNVL_header :=&apos;Coalesce(&apos;||sCol||&apos;,TO_DATE(&apos;&apos;1/1/1000&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;))&apos;;
    sNVL_footer :=&apos;Coalesce(&apos;||sCol||&apos;,TO_DATE(&apos;&apos;1/1/9999&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;))&apos;;
    IF desc_
    THEN sWhere := &apos;=TO_DATE(&apos;&apos;1/1/9999&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;) AND&apos;;
    ELSE sWhere := &apos;=TO_DATE(&apos;&apos;1/1/1000&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;) AND&apos;;
    END IF;
  ELSE
    sWhere := &apos; IS NULL AND&apos;;
  END IF;
END;

--!!!! Grupurile de reset=grupurile de sume_sold
function GetSoldSumClause (
  sSoldCols  IN  VARCHAR2,
  sResetCols IN  VARCHAR2,
  sOrderCols IN  VARCHAR2,
  pexp       OUT NUMBER,
  pGroup     IN  BOOLEAN
) RETURN VARCHAR2 is
  sResult CLOB:=&apos;&apos;;
  sCols   CLOB;
  sReset  CLOB;
  idx_grup_sold number (2) :=0;
  idx_cols_sold number (2) :=0;
  idx_grup_reset number (2):=0;
  idx_cols_reset number (2):=0;
  grup_sold CLOB;
  grup_reset CLOB;
  i number(2);
  j number(2);
  nrEXP number (2):=1;
begin
  sCols := Upper(sSoldCols);
  sReset:= Upper(sResetCols);
  idx_grup_reset := instr(sReset,&apos;;&apos;);

  IF NOT pGroup THEN --Fara grup...doar order By..
    grup_sold :=sCols;
    idx_cols_sold := instr (grup_sold,&apos;,&apos;);
    IF (idx_cols_sold = 0) and (length (grup_sold)&gt;0) THEN
      IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
        sResult:=sResult||&apos; SUM (&apos;||grup_sold||&apos;)OVER(ORDER BY &apos;|| sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
      else
        sResult:=sResult||&apos; SUM (&apos;||grup_sold||&apos;)OVER(ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
      end if;
      nrExp:=nrExp+1;
    ELSE
      WHILE idx_cols_sold &gt; 0 LOOP
        IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
          sResult:=sResult||&apos; SUM (&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;)OVER (ORDER BY &apos; ||sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        else
          sResult:=sResult||&apos; SUM (&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;)OVER (ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        end if;
        nrExp:=nrExp+1;
        grup_sold:=substr(grup_sold,idx_cols_sold+1,length(grup_sold));
        idx_cols_sold:= instr(grup_sold,&apos;,&apos;);
        IF (idx_cols_sold = 0) and (length(grup_sold) &gt; 0) THEN
          IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
            sResult:=sResult||&apos; SUM (&apos;||grup_sold||&apos;)OVER (ORDER BY &apos;|| sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          else
            sResult:=sResult||&apos; SUM (&apos;||grup_sold||&apos;)OVER (ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          end if;
        nrExp:=nrExp+1;
        END IF;
      END LOOP;
    END IF;
  ELSIF trim(sResetCols) IS NULL THEN --Fara grup_reset...doar order By..
    grup_sold :=sCols;
    idx_cols_sold := instr (grup_sold,&apos;,&apos;);
    IF (idx_cols_sold = 0) and (length (grup_sold)&gt;0) THEN
      IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
        sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER(ORDER BY &apos;|| sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
      else 
        sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER(ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
      end if;
      nrExp:=nrExp+1;      
    ELSE
      WHILE idx_cols_sold &gt; 0 LOOP
        IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
          sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (ORDER BY &apos; ||sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        else 
          sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        end if;
        nrExp:=nrExp+1;
        grup_sold:=substr(grup_sold,idx_cols_sold+1,length(grup_sold));
        idx_cols_sold:= instr(grup_sold,&apos;,&apos;);
        IF (idx_cols_sold = 0) and (length(grup_sold) &gt; 0) THEN
          IF LENGTH(TRIM(sOrderCols))&gt;0 THEN
            sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (ORDER BY &apos;|| sOrderCols ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          else
            sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (ORDER BY nrcrt ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          end if;
          nrExp:=nrExp+1;
        END IF;
      END LOOP;
    END IF;
  ELSIF idx_grup_reset &gt; 0 THEN
    WHILE idx_grup_reset &gt; 0 LOOP
      -- pentru fiecare grup_reset cauta grup_sold
      -- pentru fiecare coloana din grup_sold cate o suma cu resetare la grup_reset
      grup_reset:= substr(sReset,1,idx_grup_reset-1);
      sReset := substr(sReset,idx_grup_reset+1,length(sReset));
      idx_grup_sold:=instr(sCols,&apos;;&apos;);
      grup_sold := substr(sCols,1,idx_grup_sold-1);
      sCols := substr(sCols,idx_grup_sold+1,length(sCols));
      idx_cols_sold := instr (grup_sold,&apos;,&apos;);
      IF (idx_cols_sold = 0) and (length (grup_sold)&gt;0) THEN
        sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        nrExp:=nrExp+1;
      ELSE
        WHILE idx_cols_sold &gt; 0 LOOP
          sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY &apos; ||grup_reset ||&apos; ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          nrExp:=nrExp+1;
          grup_sold:=substr(grup_sold,idx_cols_sold+1,length(grup_sold));
          idx_cols_sold:= instr(grup_sold,&apos;,&apos;);
          IF (idx_cols_sold = 0) and (length(grup_sold) &gt; 0) THEN
            sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
            nrExp:=nrExp+1;
          END IF;
        END LOOP;
      END IF;
      idx_grup_reset:=instr(sReset,&apos;;&apos;);
      IF (idx_grup_reset = 0) and (length(sReset) &gt; 0) THEN
        --idx_grup_sold:=instr(sCols,&apos;;&apos;);
        --grup_sold := substr(sCols,1,idx_grup_sold-1);
        grup_reset := sReset;
        grup_sold :=sCols;
        idx_cols_sold := instr (grup_sold,&apos;,&apos;);
        IF (idx_cols_sold = 0) and (length (grup_sold)&gt;0) THEN
          sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          nrExp:=nrExp+1;
        ELSE
          WHILE idx_cols_sold &gt; 0 LOOP
            sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
            nrExp:=nrExp+1;
            grup_sold:=substr(grup_sold,idx_cols_sold+1,length(grup_sold));
            idx_cols_sold:= instr(grup_sold,&apos;,&apos;);
            IF (idx_cols_sold = 0) and (length(grup_sold) &gt; 0) THEN
              sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
              nrExp:=nrExp+1;
            END IF;
          END LOOP;
        END IF;
      END IF;
    END LOOP;
  ELSE
    -- am un singur grup_reset ==&gt; si un singur grup_sold
    -- pentru fiecare coloana din grup_sold cate o suma cu resetare la grup_reset
    grup_reset := sReset;
    grup_sold :=sCols;
    idx_cols_sold := instr (grup_sold,&apos;,&apos;);
    IF (idx_cols_sold = 0) and (length (grup_sold)&gt;0) THEN
      sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
      nrExp:=nrExp+1;
    ELSE
      WHILE idx_cols_sold &gt; 0 LOOP
        sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||substr(grup_sold,1,idx_cols_sold-1)||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
        nrExp:=nrExp+1;
        grup_sold:=substr(grup_sold,idx_cols_sold+1,length(grup_sold));
        idx_cols_sold:= instr(grup_sold,&apos;,&apos;);
        IF (idx_cols_sold = 0) and (length(grup_sold) &gt; 0) THEN
          sResult:=sResult||&apos; SUM (DECODE(NRG_1,NULL,&apos;||grup_sold||&apos;,0))OVER (PARTITION BY &apos;||grup_reset||&apos; ORDER BY NRCRT ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) EXP_&apos;||nrExp||&apos;,&apos;;
          nrExp:=nrExp+1;
        END IF;
      END LOOP;
    END IF;
  END IF;
  pexp:=nrExp-1;
  Return sResult;
END;

--RETURNEAZA SELECTUL PENTRU GRUPURI SI SUME LA NIVEL DE GRUP
FUNCTION GrupSumeSelect(
  tmptable     IN VARCHAR2,
  visible_cols IN VARCHAR2,
  sum_cols     IN VARCHAR2,
  group_cols   IN VARCHAR2,
  where_clause IN VARCHAR2,
  order_cols   IN VARCHAR2,
  calc_cols    IN VARCHAR2,
  sum_calc     IN VARCHAR2,
  fara_total   IN VARCHAR2,
  bCentralizat IN BOOLEAN,
  fInterval    IN VARCHAR2,
  groupsort    IN VARCHAR2
) return CLOB is
  strSelect        CLOB :=&apos;SELECT null FROM DUAL&apos;;
  strSelectAll     CLOB :=&apos;SELECT &apos;;
  strSelectHeader  CLOB :=&apos;SELECT &apos;;
  strSelectFooter  CLOB :=&apos;SELECT &apos;;
  strSelectDetalii CLOB :=&apos;SELECT &apos;;
  strSelectSum     CLOB :=&apos;SELECT &apos;;
  strWhereClause   CLOB :=&apos;WHERE NOT (&apos;;
  nrCols           NUMBER(2); --nr de coloane cu RowNum = nr coloane de grupare
  i                NUMBER(2);
  sNVL_header      CLOB;
  sNVL_footer      CLOB;
  visibleCols      CLOB;
  sWhere           CLOB;
  sCase            CLOB;
  V_COLS           CLOB;
  sColoaneCalc     CLOB;
  sCalcCols        CLOB;
  sSumCalcCols     CLOB;
  sSumHeaderFooter CLOB;
  nrCalcCols       NUMBER(2);
  allCols          CLOB;
  desc_            BOOLEAN;
BEGIN
  visibleCols:=Visible_Cols;
  v_cols:=visible_cols;
  FOR V_COLS IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)  ) LOOP
    strSelectAll     := strSelectAll    ||v_cols.column_name||&apos;,&apos;;
    strSelectDetalii := strSelectDetalii||v_cols.column_name||&apos;,&apos;;
    allCols          := allcols         ||v_cols.column_name||&apos;,&apos;;
    --caut coloana curenta IN coloanele de grupare
    IF CautaColoana(UPPER(v_cols.column_name) ,UPPER(group_cols),desc_) THEN
      GetNVLClause(tmptable,v_cols.column_name,sNVL_header,sNVL_footer,sWhere,desc_);
      IF desc_ THEN
        strSelectHeader := strSelectHeader||sNVL_Footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
        strSelectFooter := strSelectFooter||sNVL_Header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      ELSE
        strSelectHeader := strSelectHeader||sNVL_header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
        strSelectFooter := strSelectFooter||sNVL_footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      END IF;

      strSelectSum   := strSelectSum        ||v_cols.column_name||&apos;,&apos;;

      strWhereClause := strWhereClause||&apos; &apos;||v_cols.column_name||sWhere;
    ELSIF CautaColoana(UPPER(v_cols.column_name) ,UPPER(sum_cols),desc_) THEN-- caut coloana curenta IN coloanele de sume
      strSelectHeader := strSelectHeader||UPPER(v_cols.column_name)||&apos;,&apos;;
      strSelectFooter := strSelectFooter||UPPER(v_cols.column_name)||&apos;,&apos;;
      -- STEF mut conditia de fara calcul total IN sum fiindca am nevoie de linii la formatare
      IF length(trim(fara_total)) &gt; 0
      THEN strSelectSum := strSelectSum||&apos;SUM(CASE WHEN &apos;||fara_total||&apos; THEN &apos;||v_cols.column_name||&apos; ELSE 0 END) &apos;||v_cols.column_name||&apos;,&apos;;
      ELSE strSelectSum := strSelectSum||&apos;SUM(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name||&apos;,&apos;;
      END IF;
    ELSE
      strSelectHeader := strSelectHeader||&apos;NULL,&apos;;
      strSelectFooter := strSelectFooter||&apos;NULL,&apos;;
      strSelectSum    := strSelectSum   ||&apos;NULL,&apos;;
    END IF;
  END LOOP;

  allcols := substr(allCols,1,length(allCols)-1);
  strSelectAll := substr(strSelectAll,1,length(strSelectAll)-1)||&apos; FROM &apos;||UPPER(tmptable);
  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectAll := strSelectAll || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;
  strSelectAll := strSelectAll||&apos; ORDER BY &apos;||order_cols;
  sColoaneCalc := getColoanefromExpresii (calc_cols,nrCalcCols );

  sCalcCols    := calc_cols;
  sSumCalcCols := sum_calc;
  IF Length(calc_cols) &gt; 0 THEN
    PrelucreazaColCalc(sCalcCols,sSumCalcCols,sSumHeaderFooter,fara_total );
    strSelectDetalii := strSelectDetalii||sCalcCols;
    strSelectHeader  := strSelectHeader ||sSumHeaderFooter;
    strSelectFooter  := strSelectFooter ||sSumHeaderFooter;
    strSelectSum     := strSelectSum    ||sSumCalcCols;
  END IF;

  strSelectDetalii := strSelectDetalii ||&apos;ROW_number() over(order by &apos;||order_cols||&apos;)  AS NRCRT,&apos;;
  strSelectHeader  := strSelectHeader  ||&apos;NRCRT &apos;;
  strSelectFooter  := strSelectFooter  ||&apos;NRCRT &apos;;
  IF length(calc_cols)&gt;0 THEN
    allCols := allCols ||&apos;,&apos;||sColoaneCalc;
  END IF;
  allCols := allCols ||&apos;,NRCRT&apos;;

  strSelectDetalii := strSelectDetalii||pkg_list_Config.GetRowNumClause(group_cols,nrCols);
  for i IN 1..nrCols LOOP
    strSelectDetalii := strSelectDetalii||&apos;,NULL NRG_&apos;  ||i;
    strSelectHeader  := strSelectHeader ||&apos;,NULL NRCRT_&apos;||i;
    strSelectFooter  := strSelectFooter ||&apos;,NULL NRCRT_&apos;||i;
    allCols          := allCols         ||&apos;,&apos;||&apos;NRG_&apos;||i||&apos;,&apos;||&apos;NRCRT_&apos;||i;
  END LOOP;

  strSelectHeader  := strSelectHeader||&apos;,&apos;||pkg_list_Config.GetDenseRankClause(group_cols,nrcols);
  strSelectHeader  := strSelectHeader||&apos; FROM (&apos;||strSelectSum||&apos;-(&apos;||pkg_list_Config.gr_id_header;
  strSelectHeader  := strSelectHeader||&apos; + GROUPING_ID(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;)) NRCRT FROM &apos;||tmptable;

  strSelectFooter  := strSelectFooter||&apos;,&apos;||pkg_list_Config.GetDenseRankClause(group_cols,nrcols);
  strSelectFooter  := strSelectFooter||&apos; FROM (&apos;||strSelectSum||&apos;(&apos;||pkg_list_Config.gr_id_footer;
  strSelectFooter  := strSelectFooter||&apos; + GROUPING_ID(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;)) NRCRT FROM &apos;||tmptable;

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectHeader := strSelectHeader || &apos; WHERE &apos;||where_clause; --FILTRU
    strSelectFooter := strSelectFooter || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  -- STEF mut conditia de fara calcul total IN sum fiindca am nevoie de linii la formatare
  strSelectHeader  := strSelectHeader||&apos; GROUP BY ROLLUP(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;))&apos;;
  strSelectFooter  := strSelectFooter||&apos; GROUP BY ROLLUP(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;))&apos;;

  strSelectDetalii := strSelectDetalii||&apos; FROM(&apos;||strSelectAll||&apos;)&apos;;

  strWhereClause := substr(strWhereClause,1,length(strWhereClause)-length(&apos;AND&apos;));
  strWhereClause := strWhereClause||&apos;)&apos;;
  v_cols := visibleCols;

  allCols := allCols ||&apos;,pkg_list_Config.GET_GROUP_ID(NRCRT) AS NRSKIP &apos;;
  v_cols := v_cols||&apos;,NRSKIP&apos;;

  strSelect :=&apos;SELECT &apos;||allCols||&apos;  FROM ( &apos;;

  strSelect :=strSelect||strSelectDetalii||&apos; UNION ALL &apos;;
  strSelect :=strSelect||strSelectHeader||&apos; UNION ALL &apos;;
  strSelect :=strSelect||strSelectFooter||&apos; ) &apos;||strWhereClause||&apos; ORDER BY &apos;||groupsort;

  strSelect := &apos;SELECT SQL.*, ROWNUM AS GLOBALID FROM (&apos;||STRSELECT||&apos;) sql &apos; ;

   IF bCentralizat THEN -- las IN lista numai headere si footere
    strSelect := &apos;SELECT * FROM  (&apos;||strSelect ||&apos;) WHERE  (NRCRT &gt;= &apos;||gr_id_footer||&apos; OR NRCRT &lt;= &apos;||-gr_id_header||&apos;)  &apos;; --OR (GLOBALID BETWEEN 2 AND 7)
     IF length(trim(fInterval)) &gt; 0 THEN
       strSelect := strSelect ||fInterval;
     END IF;
   END IF;
  RETURN strSelect;
END;

-- RETURNEAZA SELECTU CU SUME TOTALE (FARA GRUPURI)
function SumeSelect(
  tmptable     IN VARCHAR2,
  visible_cols IN VARCHAR2,
  sum_cols     IN VARCHAR2,
  where_clause IN VARCHAR2,
  order_cols   IN VARCHAR2,
  calc_cols    IN VARCHAR2,
  sum_calc     IN VARCHAR2,
  fara_total   IN VARCHAR2,
  bCentralizat IN BOOLEAN,
  fInterval    IN VARCHAR2
) return CLOB is
  strSelect        CLOB :=&apos;SELECT null FROM DUAL&apos;;
  strSelectAll     CLOB :=&apos;SELECT &apos;;
  strSelectHeader  CLOB :=&apos;SELECT &apos;;
  strSelectFooter  CLOB :=&apos;SELECT &apos;;
  strSelectDetalii CLOB :=&apos;SELECT &apos;;
  strSelectSum     CLOB :=&apos;SELECT &apos;;
  strWhereClause   CLOB :=&apos;WHERE NOT (&apos;;
  sNVL_header      CLOB;
  sNVL_footer      CLOB;
  visibleCols      CLOB;
  sWhere           CLOB;
  sColoaneCalc     CLOB;
  nrCalcCols       NUMBER(2);
  allCols          CLOB;

  sCalcCols        CLOB;
  sSumCalcCols     CLOB;
  sSumHeaderFooter CLOB;
  
  sAuxCondHF       CLOB := &apos; WHERE &apos;;

  desc_ boolean;
begin
  visibleCols:=visible_cols;
  FOR V_COLS IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)) LOOP
    strSelectAll    := strSelectAll||v_cols.column_name||&apos;,&apos;;
    strSelectDetalii:= strSelectDetalii||v_cols.column_name||&apos;,&apos;;
    allCols := allCols ||v_cols.column_name||&apos;,&apos;;
   IF CautaColoana(Upper(v_cols.column_name) ,upper(sum_cols),desc_) THEN
     strSelectHeader := strSelectHeader||UPPER(v_cols.column_name)||&apos;,&apos;;
     strSelectFooter := strSelectFooter||UPPER(v_cols.column_name)||&apos;,&apos;;
     strSelectSum    := strSelectSum||&apos;SUM(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name||&apos;,&apos;;
    ELSE
      GetNVLClause(tmptable,v_cols.column_name,sNVL_header,sNVL_footer,sWhere);
      strSelectHeader := strSelectHeader||sNVL_header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      strSelectFooter := strSelectFooter||sNVL_footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      strSelectSum    := strSelectSum||&apos;NULL &apos;||v_cols.column_name||&apos;,&apos;;
      strWhereClause  := strWhereClause||&apos; &apos;||v_cols.column_name||sWhere;
    END IF;
  END LOOP;

  allCols := substr(allCols,1,length(allCols)-1);

  strSelectAll := substr(strSelectAll,1,length(strSelectAll)-1)||&apos; FROM &apos;||UPPER(tmptable);
  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectAll := strSelectAll || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    strSelectAll:=strSelectAll||&apos; ORDER BY &apos;||order_cols;
  END IF;

  sColoaneCalc := getColoanefromExpresii (calc_cols,nrCalcCols );
  sCalcCols    := calc_cols;
  sSumCalcCols := sum_calc;
  IF Length(calc_cols) &gt; 0 THEN
   PrelucreazaColCalc(sCalcCols,sSumCalcCols,sSumHeaderFooter,fara_total );
   strSelectDetalii := strSelectDetalii ||sCalcCols;
   strSelectHeader  := strSelectHeader  ||sSumHeaderFooter;
   strSelectFooter  := strSelectFooter  ||sSumHeaderFooter;
   strSelectSum     := strSelectSum   ||sSumCalcCols;
 END IF;

  strSelectDetalii := strSelectDetalii ||&apos;ROWNUM AS NRCRT&apos;;
  strSelectHeader  := strSelectHeader  ||&apos;NRCRT &apos;;
  strSelectFooter  := strSelectFooter  ||pkg_list_Config.gr_id_footer||&apos;NRCRT &apos;;

  IF length(calc_cols)&gt;0 THEN
      allCols := allCols||&apos;,&apos;||sColoaneCalc;
  END IF;

  allCols := allCols ||&apos;,NRCRT&apos;;

  strSelectHeader  := strSelectHeader||&apos; FROM (&apos;||strSelectSum||&apos; NULL NRCRT FROM &apos;||tmptable;
  strSelectFooter  := strSelectFooter||&apos; FROM (&apos;||strSelectSum||&apos; NULL NRCRT FROM &apos;||tmptable;

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectHeader := strSelectHeader ||sAuxCondHF||where_clause; --FILTRU
    strSelectFooter := strSelectFooter ||sAuxCondHF||where_clause; --FILTRU
    sAuxCondHF := &apos; AND &apos;;
  END IF;

  IF length(TRIM(fara_total)) &gt; 0 THEN
    strSelectHeader:=strSelectHeader ||sAuxCondHF||fara_total;
    strSelectFooter:=strSelectFooter ||sAuxCondHF||fara_total;
    sAuxCondHF := &apos; AND &apos;;
  END IF;

  strSelectHeader := strSelectHeader||&apos;)&apos;;
  strSelectFooter:=StrSelectFooter||&apos;)&apos;;

  strSelectDetalii := strSelectDetalii||&apos; FROM(&apos;||strSelectAll||&apos;)&apos;;

  strWhereClause := substr(strWhereClause,1,length(strWhereClause)-length(&apos;AND&apos;));
  strWhereClause := strWhereClause||&apos;)&apos;;

  strSelect := &apos;SELECT &apos;||allCols||&apos;,&apos;;

  strSelect := substr(strSelect,1,length(strSelect)-1);
  strSelect := strSelect||&apos;  FROM ( &apos;;
  strSelect := strSelect||strSelectDetalii||&apos; UNION ALL &apos;;
  strSelect := strSelect||strSelectHeader||&apos; UNION ALL &apos;;
  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    strSelect :=strSelect||strSelectFooter||&apos; ) &apos;||strWhereClause||&apos; ORDER BY  NRCRT, &apos;||order_cols||&apos;&apos;;
  ELSE
    strSelect :=strSelect||strSelectFooter||&apos; ) &apos;||strWhereClause||&apos; ORDER BY NRCRT&apos;;
  END IF;

  strSelect := &apos;SELECT SQL.*, ROWNUM AS GLOBALID FROM (&apos;||STRSELECT||&apos;) sql &apos; ;

   IF bCentralizat THEN -- las IN lista numai headere si footere
    strSelect := &apos;SELECT * FROM  (&apos;||strSelect ||&apos;) WHERE  (NRCRT &gt;= &apos;||gr_id_footer||&apos; OR NRCRT &lt;= &apos;||-gr_id_header||&apos;)  &apos;; --OR (GLOBALID BETWEEN 2 AND 7)
     IF length(trim(fInterval)) &gt; 0 THEN
       strSelect := strSelect ||fInterval;
     END IF;
   END IF;
  RETURN strSelect;

END;

--RETURNEAZA SELECTUL CU COLOANE TIP SOLD SI, DACA E CAZUL, SUMA TOTALA
function SumeSoldSelect (
  tmptable       IN VARCHAR2,
  visible_cols   IN VARCHAR2,
  sum_cols       IN VARCHAR2,
  where_clause   IN VARCHAR2,
  order_cols     IN VARCHAR2,
  sold_cols      IN VARCHAR2,
  resetsold_cols IN VARCHAR2,
  calc_cols      IN VARCHAR2 ,
  sum_calc       IN VARCHAR2,
  sold_calc      IN VARCHAR2,
  bCentralizat   IN BOOLEAN,
  fInterval      IN VARCHAR2
) return CLOB is
  strSelect        CLOB :=&apos;SELECT null FROM DUAL&apos;;
  strSelectAll     CLOB :=&apos;SELECT &apos;;
  strSelectFooter  CLOB :=&apos;SELECT &apos;;
  strSelectDetalii CLOB :=&apos;SELECT &apos;;
  strSelectSum     CLOB :=&apos;SELECT &apos;;
  strWhereClause   CLOB :=&apos;WHERE &apos;;
  nrCols           NUMBER(2) := 0;
  sNVL_header      CLOB;
  sNVL_footer      CLOB;
  visibleCols      CLOB;
  sWhere           CLOB;
  i                NUMBER(2);
  sColoaneCalc     CLOB;
  nrCalcCols       NUMBER(2);
  allCols          CLOB;
  sCalcCols        CLOB;
  sSumCalcCols     CLOB;
  sSumHeaderFooter CLOB;
  fara_total       VARCHAR2(1);
begin
  visibleCols:=visible_cols;
  FOR V_COLS IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)) LOOP
    strSelectAll    := strSelectAll||v_cols.column_name||&apos;,&apos;;
    strSelectDetalii:= strSelectDetalii||v_cols.column_name||&apos;,&apos;;
    allCols := allCols ||v_cols.column_name||&apos;,&apos;;
    IF  -- caut coloana curenta IN coloanele de sume
      (instr(UPPER(sum_cols),v_cols.column_name||&apos;,&apos;) &gt; 0)      or
      (instr(UPPER(sum_cols),&apos;,&apos;||v_cols.column_name) &gt; 0)      or
      (UPPER(sum_cols) = v_cols.column_name)
    THEN
      strSelectFooter := strSelectFooter||UPPER(v_cols.column_name)||&apos;,&apos;;
      strSelectSum    := strSelectSum||&apos;SUM(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name||&apos;,&apos;;
    ELSE
      GetNVLClause(tmptable,v_cols.column_name,sNVL_header,sNVL_footer,sWhere);
      strSelectFooter := strSelectFooter||sNVL_footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      strSelectSum    := strSelectSum||&apos;NULL &apos;||v_cols.column_name||&apos;,&apos;;
    END IF;
  END LOOP;

  allCols := substr(allCols,1,length(allCols)-1);

  sColoaneCalc := getColoanefromExpresii (calc_cols,nrCalcCols );

  sCalcCols    := calc_cols;
  sSumCalcCols := sum_calc;
  fara_total :=&apos;&apos;;
  IF Length(calc_cols) &gt; 0 THEN
    PrelucreazaColCalc(sCalcCols,sSumCalcCols,sSumHeaderFooter,fara_total );
    strSelectDetalii := strSelectDetalii||sCalcCols;
    --strSelectHeader  := strSelectHeader ||sSumHeaderFooter;
    strSelectFooter  := strSelectFooter ||sSumHeaderFooter;
    strSelectSum     := strSelectSum    ||sSumCalcCols;
  END IF;

  strSelectAll:=strSelectAll||&apos; ROWNUM AS NRCRT FROM &apos;||UPPER(tmptable);
  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectAll := strSelectAll || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;
  IF LENGTH(TRIM(order_cols))&gt;0 THEN
     strSelectAll:= strSelectAll||&apos; ORDER BY &apos;||order_cols||&apos;, NRCRT&apos;;
  else
     strSelectAll:= strSelectAll||&apos; ORDER BY NRCRT&apos;;
  end if;
  strSelectDetalii := strSelectDetalii ||&apos; &apos;||GetSoldSumClause (sold_cols,resetsold_cols,order_cols,nrCols, False);
  strSelectDetalii := strSelectDetalii ||&apos; NRCRT&apos;;

  for i IN 1.. nrCols LOOP
    strSelectFooter:= strSelectFooter||&apos;EXP_&apos;||i||&apos;,&apos;;
    strSelectSum := strSelectSum||&apos;NULL EXP_&apos;||i||&apos;,&apos;;
    allCols := allCols ||&apos;,EXP_&apos;||i;
  END LOOP;


  strSelectFooter  := strSelectFooter  ||&apos;NRCRT &apos;;

  IF length(calc_cols)&gt;0 THEN
    allCols := allCols ||&apos;,&apos;||sColoaneCalc;
  END IF;

  allCols := allCols ||&apos;,NRCRT&apos;;
  strSelectFooter  := strSelectFooter||&apos; FROM (&apos;||strSelectSum||&apos; NULL NRCRT FROM &apos;||tmptable||&apos;)&apos;;

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectFooter := strSelectFooter || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  strSelectDetalii := strSelectDetalii||&apos; FROM(&apos;||strSelectAll||&apos;)&apos;;

 -- strSelect :=&apos;SELECT &apos;|| visibleCols||&apos;,&apos;;
  strSelect := &apos;SELECT &apos;||allCols||&apos;,&apos;;
  strSelect := substr(strSelect,1,length(strSelect)-1);
  strSelect := strSelect||&apos;  FROM ( &apos;;
  IF NVL(LENGTH(TRIM(sum_cols)),0)&gt;0 THEN
    strSelect :=strSelect||strSelectDetalii||&apos; UNION ALL &apos;;
  ELSE
    strSelect :=strSelect||strSelectDetalii;
  END IF;


  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    IF NVL(LENGTH(TRIM(sum_cols)),0)&gt;0 THEN
      strSelect :=strSelect||strSelectFooter||&apos; )  ORDER BY &apos;||order_cols||&apos;, NRCRT&apos;;
    ELSE
      strSelect :=strSelect||&apos; )  ORDER BY &apos;||order_cols||&apos;, NRCRT&apos;;
    END IF;
  ELSE
    strSelect :=strSelect||strSelectFooter||&apos; )  ORDER BY NRCRT&apos;;
  END IF;


  strSelect := &apos;SELECT SQL.*, ROWNUM AS GLOBALID FROM (&apos;||STRSELECT||&apos;) sql &apos; ;

   IF bCentralizat THEN -- las IN lista numai headere si footere
    strSelect := &apos;SELECT * FROM  (&apos;||strSelect ||&apos;) WHERE  (NRCRT &gt;= &apos;||gr_id_footer||&apos; OR NRCRT &lt;= &apos;||-gr_id_header||&apos;)  &apos;; --OR (GLOBALID BETWEEN 2 AND 7)
     IF length(trim(fInterval)) &gt; 0 THEN
       strSelect := strSelect ||fInterval;
     END IF;
   END IF;


  return strSelect;
END;

--RETURNEAZA SELECTUL CO COLOANE TIP SOLD SI SUBTOTAL LA NIVEL DE GRUP
function GrupSumeSoldSelect (
  tmptable IN VARCHAR2,
  visible_cols IN VARCHAR2,
  sum_cols IN VARCHAR2,
  group_cols IN VARCHAR2,
  where_clause IN VARCHAR2,
  order_cols IN VARCHAR2,
  sold_cols IN VARCHAR2,
  resetsold_cols IN VARCHAR2,
  calc_cols IN VARCHAR2 ,
  sum_calc IN VARCHAR2,
  sold_calc IN VARCHAR2,
  bCentralizat IN BOOLEAN,
  fInterval IN VARCHAR2,
  groupsort IN VARCHAR2
) return CLOB IS
  strSelect        CLOB :=&apos;SELECT null FROM DUAL&apos;;
  strSelectAll     CLOB :=&apos;SELECT &apos;;
  strSelectHeader  CLOB :=&apos;SELECT &apos;;
  strSelectFooter  CLOB :=&apos;SELECT &apos;;
  strSelectDetalii CLOB :=&apos;SELECT &apos;;
  strSelectSum     CLOB :=&apos;SELECT &apos;;
  strWhereClause   CLOB :=&apos;WHERE NOT (&apos;;
  nrCols           NUMBER(2); --nr de coloane cu RowNum = nr coloane de grupare
  i                NUMBER(2);
  sNVL_header      CLOB;
  sNVL_footer      CLOB;
  visibleCols      CLOB;
  sWhere           CLOB;
  strSoldClause    CLOB;
  sColoaneCalc     CLOB;
  nrCalcCols       NUMBER(2);
  allCols          CLOB;
  desc_            BOOLEAN;

  sSumCols         CLOB;

  sCalcCols        CLOB;
  sSumCalcCols     CLOB;
  sSumHeaderFooter CLOB;
  fara_total       VARCHAR2(1);
  sOrdSold         CLOB;
BEGIN
  sSumCols := REPLACE(sum_cols,&apos; &apos;);
  sSumCols := REPLACE(sSumCols,&apos;,,&apos;,&apos;,&apos;);
  sSumCols := &apos;,&apos;||Upper(sSumCols)||&apos;,&apos;;

  visibleCols:=Visible_Cols;
  FOR V_COLS IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)) LOOP
    strSelectAll    := strSelectAll||v_cols.column_name||&apos;,&apos;;
    strSelectDetalii:= strSelectDetalii||v_cols.column_name||&apos;,&apos;;
    allCols := allCols ||v_cols.column_name||&apos;,&apos;;
    IF CautaColoana (Upper(v_cols.column_name) ,upper(group_cols),desc_) THEN
      GetNVLClause(tmptable,v_cols.column_name,sNVL_header,sNVL_footer,sWhere,desc_);
      IF desc_ THEN
        strSelectHeader := strSelectHeader||sNVL_Footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
        strSelectFooter := strSelectFooter||sNVL_Header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      ELSE
        strSelectHeader := strSelectHeader||sNVL_header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
        strSelectFooter := strSelectFooter||sNVL_footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
      END IF;
      strSelectSum    := strSelectSum||v_cols.column_name||&apos;,&apos;;
      strWhereClause  := strWhereClause||&apos; &apos;||v_cols.column_name||sWhere;
    ELSIF      -- caut coloana curenta IN coloanele de sume
      (INSTR(sSumCols,&apos;,&apos;||v_cols.column_name||&apos;,&apos;) &gt; 0)
    THEN
      strSelectHeader := strSelectHeader||UPPER(v_cols.column_name)||&apos;,&apos;;
      strSelectFooter := strSelectFooter||UPPER(v_cols.column_name)||&apos;,&apos;;
      strSelectSum    := strSelectSum||&apos;SUM(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name||&apos;,&apos;;
    ELSE
      strSelectHeader := strSelectHeader||&apos;NULL,&apos;;
      strSelectFooter := strSelectFooter||&apos;NULL,&apos;;
      strSelectSum    := strSelectSum||&apos;NULL,&apos;;
    END IF;
  END LOOP;

  allCols := SUBSTR(allCols,1,LENGTH(allCols)-1);
  strSelectAll := SUBSTR(strSelectAll,1,LENGTH(strSelectAll)-1)||&apos; FROM &apos;||UPPER(tmptable);

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectAll := strSelectAll || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  --strSelectAll := strSelectAll||&apos; ORDER BY &apos;||group_cols;
  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    strSelectAll:=strSelectAll||&apos; ORDER BY &apos;||order_cols;
  END IF;

  sColoaneCalc := getColoanefromExpresii (calc_cols,nrCalcCols );

  sCalcCols    := calc_cols;
  sSumCalcCols := sum_calc;
  fara_total :=&apos;&apos;;

  IF Length(calc_cols) &gt; 0 THEN
    PrelucreazaColCalc(sCalcCols,sSumCalcCols,sSumHeaderFooter,fara_total );
    strSelectDetalii := strSelectDetalii||sCalcCols;
    strSelectHeader  := strSelectHeader ||sSumHeaderFooter;
    strSelectFooter  := strSelectFooter ||sSumHeaderFooter;
    strSelectSum     := strSelectSum    ||sSumCalcCols;
  END IF;
  
  IF LENGTH(TRIM(order_cols))&gt;0 THEN
     strSelectDetalii := strSelectDetalii ||&apos;ROW_number() over(order by &apos;||order_cols||&apos;) AS NRCRT,&apos;;
  end if;     
  strSelectHeader  := strSelectHeader  ||&apos;NRCRT &apos;;
  strSelectFooter  := strSelectFooter  ||&apos;NRCRT &apos;;

  IF length(calc_cols)&gt;0 THEN

   allCols := allCols ||&apos;,&apos;||sColoaneCalc;
  END IF;

  allCols := allCols ||&apos;,NRCRT&apos;;

  strSelectDetalii := strSelectDetalii||pkg_list_Config.GetRowNumClause(group_cols,nrCols);
  for i IN 1..nrCols LOOP
    strSelectDetalii := strSelectDetalii||&apos;,NULL NRG_&apos;||i;
    strSelectHeader  := strSelectHeader||&apos;,NULL NRCRT_&apos;||i;
    strSelectFooter  := strSelectFooter||&apos;,NULL NRCRT_&apos;||i;

  allCols := allCols||&apos;,&apos;||&apos;NRG_&apos;||i||&apos;,&apos;||&apos;NRCRT_&apos;||i;
  END LOOP;
  strSelectHeader  := strSelectHeader||&apos;,&apos;||pkg_list_Config.GetDenseRankClause(group_cols,nrcols);
  strSelectHeader  := strSelectHeader||&apos; FROM (&apos;||strSelectSum||&apos;-(&apos;||pkg_list_Config.gr_id_header;
  strSelectHeader  := strSelectHeader||&apos; + GROUPING_ID(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;)) NRCRT FROM &apos;||tmptable;

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectHeader := strSelectHeader || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  strSelectHeader  := strSelectHeader||&apos; GROUP BY ROLLUP(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;))&apos;;

  strSelectFooter  := strSelectFooter||&apos;,&apos;||pkg_list_Config.GetDenseRankClause(group_cols,nrcols);
  strSelectFooter  := strSelectFooter||&apos; FROM (&apos;||strSelectSum||&apos;(&apos;||pkg_list_Config.gr_id_footer;
  strSelectFooter  := strSelectFooter||&apos; + GROUPING_ID(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;)) NRCRT FROM &apos;||tmptable;

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectFooter := strSelectFooter || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  strSelectFooter  := strSelectFooter||&apos; GROUP BY ROLLUP(&apos;||replace(group_cols,&apos; DESC&apos;,&apos;&apos;)||&apos;))&apos;;

  strSelectDetalii := strSelectDetalii||&apos; FROM(&apos;||strSelectAll||&apos;)&apos;;

  strWhereClause := substr(strWhereClause,1,length(strWhereClause)-length(&apos;AND&apos;));
  strWhereClause := strWhereClause||&apos;)&apos;;

  sOrdSold := group_cols ||&apos;,NRCRT&apos;;
  for i IN 1..nrCols LOOP
    sOrdSold := sOrdSold||&apos;,&apos;||&apos;NVL(NRCRT_&apos;||i||&apos;,0)&apos;;
  END LOOP;
  strSoldClause := GetSoldSumClause (sold_cols, resetsold_cols ,sOrdSold, nrCols, True);

  strSoldClause := substr(strSoldClause,1,length(strSoldClause)-1);

  strSelect :=&apos;SELECT &apos;||allCols||&apos;,&apos;|| strSoldClause||&apos;   FROM (
    &apos;;
  strSelect :=strSelect||strSelectDetalii||&apos;
    UNION ALL &apos;;
  strSelect :=strSelect||strSelectHeader||&apos;
    UNION ALL &apos;;
  strSelect :=strSelect||strSelectFooter||&apos;
  )
  &apos;||strWhereClause||&apos;
  ORDER BY &apos;||groupsort;

  strSelect := &apos;SELECT SQL.*, ROWNUM AS GLOBALID FROM (&apos;||STRSELECT||&apos;) sql &apos; ;
  IF bCentralizat THEN -- las IN lista numai headere si footere
    strSelect := &apos;SELECT * FROM  (&apos;||strSelect ||&apos;) WHERE  (NRCRT &gt;= &apos;||gr_id_footer||&apos; OR NRCRT &lt;= &apos;||-gr_id_header||&apos;)  &apos;; --OR (GLOBALID BETWEEN 2 AND 7)
     IF length(trim(fInterval)) &gt; 0 THEN
       strSelect := strSelect ||fInterval;
     END IF;
   END IF;
  return strSelect;
END;

FUNCTION GetSelectSimplu (
  tmptable     IN VARCHAR2,
  visible_cols IN VARCHAR2,
  where_clause IN VARCHAR2,
  order_cols   IN VARCHAR2,
  calc_cols    IN VARCHAR2,
  sum_calc     IN VARCHAR2 ,
  bCentralizat IN BOOLEAN,
  fInterval    IN VARCHAR2
) return CLOB IS
  strSelect        CLOB :=&apos;SELECT null FROM DUAL&apos;;
  strSelectAll     CLOB :=&apos;SELECT &apos;;
  strSelectHeader  CLOB :=&apos;SELECT &apos;;
  strSelectFooter  CLOB :=&apos;SELECT &apos;;
  strSelectDetalii CLOB :=&apos;SELECT &apos;;
  strSelectNull    CLOB :=&apos;SELECT &apos;;
  strWhereClause   CLOB :=&apos;WHERE NOT (&apos;;
  sNVL_header      CLOB;
  sNVL_footer      CLOB;
  visibleCols      CLOB;
  sWhere           CLOB;
  allCols          CLOB;
  sColoaneCalc     CLOB;
  nrCalcCols       NUMBER(2);
BEGIN
  visibleCols:=visible_cols;
  FOR V_COLS IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)) LOOP
    strSelectAll    := strSelectAll||v_cols.column_name||&apos;,&apos;;
    strSelectDetalii:= strSelectDetalii||v_cols.column_name||&apos;,&apos;;
    GetNVLClause(tmptable,v_cols.column_name,sNVL_header,sNVL_footer,sWhere);
    strSelectHeader := strSelectHeader||sNVL_header||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
    strSelectFooter := strSelectFooter||sNVL_footer||&apos; &apos;||v_cols.column_name||&apos;,&apos;;
    strSelectNull    := strSelectNull||&apos;NULL &apos;||v_cols.column_name||&apos;,&apos;;
    strWhereClause  := strWhereClause||&apos; &apos;||v_cols.column_name||sWhere;
    allCols := allCols ||v_cols.column_name||&apos;,&apos;;
  END LOOP;
  allCols := substr(allcols,1,length(allCols)-1);

  strSelectAll := substr(strSelectAll,1,length(strSelectAll)-1)||&apos; FROM &apos;||UPPER(tmptable);

  IF length(TRIM(where_clause)) &gt; 0 THEN
    strSelectAll := strSelectAll || &apos; WHERE &apos;||where_clause; --FILTRU
  END IF;

  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    strSelectAll:=strSelectAll||&apos; ORDER BY &apos;||order_cols;
  END IF;

  sColoaneCalc := getColoanefromExpresii (calc_cols,nrCalcCols );

  IF length(calc_cols) &gt; 0 THEN
    strSelectDetalii:=strSelectDetalii || replace(calc_cols,&apos;;&apos;,&apos;,&apos;) || &apos;,&apos;;
      FOR i IN 1..nrCalcCols LOOP
        strSelectHeader:=strSelectHeader ||&apos;NULL,&apos;;
        strSelectFooter:=strSelectFooter ||&apos;NULL,&apos;;
      END LOOP;
  END IF;
  strSelectDetalii := strSelectDetalii ||&apos;ROWNUM AS NRCRT&apos;;
  strSelectHeader  := strSelectHeader  ||&apos;NRCRT &apos;;
  strSelectFooter  := strSelectFooter  ||&apos;NRCRT &apos;;

   IF length(calc_cols)&gt;0 THEN
    allCols := allCols||&apos;,&apos;||sColoaneCalc;
  END IF;
  allCols  :=  allCols||&apos;,NRCRT&apos;;

  strSelectHeader  := strSelectHeader||&apos; FROM (&apos;||strSelectNull||&apos; NULL NRCRT FROM DUAL)&apos;;
  strSelectFooter  := strSelectFooter||&apos; FROM (&apos;||strSelectNull||&apos; NULL NRCRT FROM DUAL)&apos;;

  strSelectDetalii := strSelectDetalii||&apos; FROM(&apos;||strSelectAll||&apos;)&apos;;

  strWhereClause := substr(strWhereClause,1,length(strWhereClause)-length(&apos;AND&apos;));
  strWhereClause := strWhereClause||&apos;)&apos;;

  strSelect :=&apos;SELECT &apos;|| allCols||&apos;,&apos;;

  strSelect := substr(strSelect,1,length(strSelect)-1);
  strSelect := strSelect||&apos;  FROM ( &apos;;
  strSelect :=strSelect||strSelectDetalii||&apos; UNION ALL &apos;;
  strSelect :=strSelect||strSelectHeader||&apos; UNION ALL &apos;;
  IF LENGTH(TRIM(order_cols))&gt;0 THEN
    strSelect :=strSelect||strSelectFooter||&apos; ) &apos;||strWhereClause||&apos; ORDER BY &apos;||order_cols||&apos;, NRCRT&apos;;
  ELSE
    strSelect :=strSelect||strSelectFooter||&apos; ) &apos;||strWhereClause||&apos; ORDER BY NRCRT&apos;;
  END IF;

  strSelect := &apos;SELECT SQL.*, ROWNUM AS GLOBALID FROM (&apos;||STRSELECT||&apos;) sql &apos; ;

  IF bCentralizat THEN -- las IN lista numai headere si footere
    strSelect := &apos;SELECT * FROM  (&apos;||strSelect ||&apos;) WHERE  (NRCRT &gt;= &apos;||gr_id_footer||&apos; OR NRCRT &lt;= &apos;||-gr_id_header||&apos;)  &apos;; --OR (GLOBALID BETWEEN 2 AND 7)
     IF length(trim(fInterval)) &gt; 0 THEN
       strSelect := strSelect ||fInterval;
     END IF;
  END IF;


  RETURN strSelect;
END;

FUNCTION FormatNullSelect(
  stab IN VARCHAR2,
  visibleCols IN VARCHAR2
) RETURN CLOB IS
  idx      NUMBER(2);
  sColName VARCHAR2(50);
  sCols    CLOB;
  sResult  CLOB:=&apos;SELECT &apos;;
  sType    VARCHAR2(50);
BEGIN
  sCols:=visibleCols;
  idx := instr (sCols,&apos;,&apos;);
  IF (idx = 0) and (length (sCols)&gt;0) THEN
    sColName := sCols;
    sType:=GET_COL_TYPE(sColName,sTab);
    CASE
      WHEN (UPPER(sType)=&apos;VARCHAR2&apos;) OR (UPPER(sType)=&apos;CHAR&apos;) THEN sResult:=sResult||&apos;CHR(0) &apos;||sColName||&apos; FROM DUAL &apos;;
      WHEN UPPER(sType)=&apos;NUMBER&apos;                              THEN sResult:=sResult||&apos;-1 &apos;||sColName||&apos; FROM DUAL &apos;;
      WHEN UPPER(sType)=&apos;DATE&apos;                                THEN sResult:=sResult||&apos;TO_DATE(&apos;&apos;1/1/1000&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;) &apos;||sColName||&apos; FROM DUAL &apos;;
      ELSE NULL;
    END CASE;
  ELSE
    WHILE idx &gt; 0 LOOP
      sColName := substr(sCols,1,idx-1);
      sType:=GET_COL_TYPE(sColName,sTab);
      CASE
        WHEN (UPPER(sType)=&apos;VARCHAR2&apos;) OR (UPPER(sType)=&apos;CHAR&apos;) THEN sResult:=sResult||&apos;CHR(0) &apos;||sColName||&apos;, &apos;;
        WHEN UPPER(sType)=&apos;NUMBER&apos;                              THEN sResult:=sResult||&apos;-1 &apos;||sColName||&apos;, &apos;;
        WHEN UPPER(sType)=&apos;DATE&apos;                                THEN sResult:=sResult||&apos;TO_DATE(&apos;&apos;1/1/1000&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;) &apos;||sColName||&apos;, &apos;;
        ELSE NULL;
      END CASE;
      sCols:=substr(sCols,idx+1,length(sCols));
      idx:= instr(sCols,&apos;,&apos;);
      IF (idx = 0) and (length(sCols) &gt; 0) THEN
        sColName:=sCols;
        sType:=GET_COL_TYPE(sColName,sTab);
        CASE
          WHEN (UPPER(sType)=&apos;VARCHAR2&apos;) OR (UPPER(sType)=&apos;CHAR&apos;) THEN sResult:=sResult||&apos;CHR(0) &apos;||sColName||&apos;,1 NRCRT FROM DUAL &apos;;
          WHEN UPPER(sType)=&apos;NUMBER&apos;                              THEN sResult:=sResult||&apos;-1 &apos;||sColName||&apos;,1 NRCRT FROM DUAL &apos;;
          WHEN UPPER(sType)=&apos;DATE&apos;                                THEN sResult:=sResult||&apos;TO_DATE(&apos;&apos;1/1/1000&apos;&apos;,&apos;&apos;dd/mm/yyyy&apos;&apos;) &apos;||sColName||&apos;,1 NRCRT FROM DUAL &apos;;
          ELSE NULL;
        END CASE;
      END IF;
    END LOOP;
  END IF;
  RETURN sResult;
END;

--returneaza un cursor pentru fiecare filtrare, grupare, ordonare de pe client !!
--coloanele din Group_cols nu sunt si IN parametrul Order_cols dar se pun automat la inceputul clauzei ORDER BY !!
--TODO: de construit SQL conform cu cele 2 selecturi IN fct daca este grupare sau nu
--parametru fara_total este filtru where care imi exclude anumite linii din sume dar liniile sunt afisate

PROCEDURE TryToDropTMP (tmpName IN VARCHAR2, isTemp VARCHAR2 ) IS
nr NUMBER(1) := 0;
BEGIN
   SELECT COUNT(*) INTO nr FROM USER_tables WHERE table_name =UPPER(TMPNAME) AND TEMPORARY = isTemp;
   IF NR &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||TMPNAME;
    EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||TMPNAME;
   END IF;
END;

PROCEDURE ProceseazaTotal(tmptable IN OUT VARCHAR2, sum_cols IN VARCHAR2, group_cols IN VARCHAR2, sUserName IN VARCHAR2) IS
  vTable     VARCHAR2(  100);
  strSelect  CLOB;
  strGroupBy CLOB;
  DESC_      BOOLEAN;
BEGIN
  FOR V_COLS IN (
    SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME=UPPER(tmptable)
  ) LOOP
    IF CautaColoana (Upper(v_cols.column_name), upper(group_cols), desc_) THEN -- grupare dupa coloana
      strSelect  := strSelect ||&apos;,&apos;||v_cols.column_name;
      strGroupBy := strGroupBy||&apos;,&apos;||v_cols.column_name;
    ELSIF CautaColoana (upper(v_cols.column_name) ,upper(sum_cols),desc_) THEN --totaluri
      strSelect  := strSelect||&apos;, SUM(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name;
    ELSE
      strSelect  := strSelect||&apos;, MAX(&apos;||v_cols.column_name||&apos;) &apos;||v_cols.column_name;
    END IF;
  END LOOP;

  IF strGroupBy IS NOT NULL THEN
    vTable     := &apos;T&apos;||tmptable;
    strSelect  := &apos;SELECT &apos;||SubStr(strSelect,2)||&apos; FROM &apos;||tmptable||&apos; Group BY &apos;||SubStr(strGroupBy,2);
    TryToDropTMP(vTable,&apos;Y&apos;);

    EXECUTE IMMEDIATE &apos; CREATE GLOBAL TEMPORARY TABLE &apos;||vTable||&apos; ON COMMIT PRESERVE ROWS AS &apos;||strSelect;
    EXECUTE IMMEDIATE &apos; GRANT SELECT ON &apos;||vTable||&apos; TO &apos;||sUserName;
    tmptable := vTable;
  END IF;
END;

FUNCTION ClientSelect (
  tmptable       IN VARCHAR2,      --&gt; numele tabelului temporar
  visible_cols   IN VARCHAR2,      --&gt; setu de coloane pe care le afiseaza IN lista, tot aici returnez si coloanele system (nrcrt,nrg..) dar care nu se afiseaza IN lista
  sum_cols       IN VARCHAR2,      --&gt; setu coloanele pe care fac sume la nivel de grup; toate coloane de aici trebuie sa fie si IN tmpTable
  group_cols     IN VARCHAR2,      --&gt; setu de coloane pe care fac grupare; toate coloane de aici trebuie sa fie si IN tmpTable
  where_cols     IN VARCHAR2,      --&gt; filtrul where !!! inca nu este implementat
  order_cols     IN VARCHAR2,      --&gt; coloanele de ordonare altele decat cele din group_cols
  sold_cols      IN VARCHAR2,      --&gt; coloanele de tip sold. Pentru fiecare coloana din sold_cols se va genera cate o coloana suplimentara cu suma respectiva. Denumirea coloanelor generate este de forma EXP_n
  resetsold_cols IN VARCHAR2,      --&gt; coloanele la nivelul carora resetez valoarea coloanei de sold. Soldul poate fi calculat la nivelul intregii liste sau se poate reseta la nivelul unui grup care va si specificat pe acest parametru
  calc_cols      IN VARCHAR2,      --&gt; coloane calculate. Vor fi date dupa forma: (a+b)col1,(x*y)col2 unde a,b,x si y sunt coloane din tmpTable iar col1 si col2 sunt numele acestor coloane calculate
  sum_calc       IN VARCHAR2,      --&gt; setu de coloane calculate pentru care fac sume la nivel de grup. Vor fi date dupa forma: (a+b)col1 (subset al calc_cols)
  sold_calc      IN VARCHAR2,      --&gt; Va Urma.....
  fara_total     IN VARCHAR2,      --&gt; un filtru where care poate exclude din calculul totalelor anumite linii; liniile respective sunt afisate IN lista
  viewName       IN VARCHAR2,
  sUserName      IN VARCHAR2,
  bCentralizat   IN BOOLEAN,       --&gt; flag daca lista este sau nu centralizata
  fInterval      IN VARCHAR2,
  sTable         IN VARCHAR2 DEFAULT &apos;?&apos;,
  groupsort      IN VARCHAR2
) return NUMBER IS
PRAGMA AUTONOMOUS_TRANSACTION;
  crsLIST     CRS;
  xTable      VARCHAR2(100) := tmptable;
  wTable      VARCHAR2(100) := &apos;W&apos;||tmptable;
  strSelect   CLOB          := &apos;SELECT null FROM DUAL&apos;;
  visibleCols CLOB;
  pTipSQL     VARCHAR2(100); -- doar pentru debug;
BEGIN
  IF sTable = &apos;GROUPBEFORE&apos; THEN
    ProceseazaTotal(xTable, sum_cols, group_cols, sUserName);
  END IF;

  IF (sTable &lt;&gt; &apos;?&apos;)and(sTable &lt;&gt; &apos;GROUPBEFORE&apos;) THEN
    TryToDropTMP(sTable,&apos;N&apos;);
    EXECUTE IMMEDIATE &apos; CREATE TABLE  &apos;||sTABLE||&apos; AS SELECT * FROM &apos;||TMPTABLE;
    EXECUTE IMMEDIATE &apos; GRANT SELECT ON &apos;||sTable||&apos; TO &apos;||sUserName;
  END IF;

  visibleCols:=visible_cols;

  IF    (NVL(LENGTH(TRIM(group_cols)),0)&gt;0) AND (NVL(LENGTH(TRIM(sum_cols)),0)&gt;=0) AND (NVL(LENGTH(TRIM(sold_cols)),0)=0) THEN
    pTipSql   := &apos;CU GRUPARE SI SUBTOTALURI&apos;;
    strSelect := GrupSumeSelect(xtable,visible_cols,sum_cols,group_cols,where_cols,order_cols, calc_cols , sum_calc , fara_total, bCentralizat,fInterval,groupsort );
  ELSIF (NVL(LENGTH(TRIM(group_cols)),0)=0) AND (NVL(LENGTH(TRIM(sum_cols)),0)&gt;0)  AND (NVL(LENGTH(TRIM(sold_cols)),0)=0) THEN
    pTipSql   := &apos;CU TOTAL GENERAL SI FARA GRUPARE&apos;;
    strSelect := SumeSelect(xTable,visible_cols,sum_cols,where_cols,order_cols,calc_cols , sum_calc, fara_total, bCentralizat,fInterval);
  ELSIF (NVL(LENGTH(TRIM(group_cols)),0)=0) AND (NVL(LENGTH(TRIM(sum_cols)),0)&gt;=0) AND (NVL(LENGTH(TRIM(sold_cols)),0)&gt;0) THEN
    pTipSql   := &apos;CU COLOANE TIP SOLD SI TOTAL GENERAL&apos;;
    strSelect := SumeSoldSelect (xTable ,visible_cols ,sum_cols ,where_cols,order_cols ,sold_cols,resetsold_cols,calc_cols , sum_calc, sold_calc, bCentralizat,fInterval);
  ELSIF (NVL(LENGTH(TRIM(group_cols)),0)&gt;0) AND (NVL(LENGTH(TRIM(sum_cols)),0)&gt;=0) AND (NVL(LENGTH(TRIM(sold_cols)),0)&gt;0) THEN
    pTipSql   := &apos;CU COLOANE TIP SOLD SI CU SUBTOTALURI DE GRUP&apos;;
    strSelect := GrupSumeSoldSelect (xTable,visible_cols, sum_cols, group_cols, where_cols, order_cols, sold_cols, resetsold_cols, calc_cols , sum_calc, sold_calc, bCentralizat,fInterval,groupsort);
  ELSIF (NVL(LENGTH(TRIM(group_cols)),0)=0) AND (NVL(LENGTH(TRIM(sum_cols)),0)=0) AND (NVL(LENGTH(TRIM(sold_cols)),0)=0) THEN
    pTipSql   := &apos;SELECT SIMPLU (VEZI NOMENCLATOARE)&apos;;
    strSelect := GetSelectSimplu(xTable,visible_cols,where_cols,order_cols,calc_cols,sum_calc,bCentralizat,fInterval);
  ELSE
    pTipSql   := &apos;--DACA KIAR NU INTRU PE NICI O RAMURA DE MAI SUS....&apos;;
    strSelect := FormatNullSelect(xTable,visible_cols);
  END IF;
  
  IF (sTable = &apos;?&apos;)or(sTable = &apos;GROUPBEFORE&apos;) THEN
    TryToDropTMP(WTable,&apos;Y&apos;);
    EXECUTE IMMEDIATE &apos; CREATE GLOBAL TEMPORARY TABLE &apos;||WTable||&apos; ON COMMIT PRESERVE ROWS AS &apos;||strSelect;
    EXECUTE IMMEDIATE &apos; GRANT SELECT ON &apos;||WTable||&apos; TO &apos;||sUserName;
  END IF;
  
  RETURN 0;
END;

PROCEDURE GET_DATE_FROM_VIEW(tmptable IN VARCHAR2, UserViewName IN VARCHAR2, sUserName IN VARCHAR2) is

  FUNCTION CautaColoana(aCol IN VARCHAR2) return number is
    ires number(1);
  BEGIN
    SELECT count(*) into ires FROM user_tab_columns WHERE table_name = upper(UserViewName) and column_name = upper(aCol);
    RETURN iRes;
  END;

BEGIN
  TryToDropTMP(tmptable,&apos;Y&apos;);
  IF CautaColoana(&apos;ROWHEIGHT&apos;) = 0
  THEN EXECUTE IMMEDIATE &apos; CREATE GLOBAL TEMPORARY TABLE  &apos;||TMPTABLE||&apos; ON COMMIT PRESERVE ROWS AS SELECT V.*,1 ROWHEIGHT FROM &apos;||UserViewName||&apos; V &apos;;
  ELSE EXECUTE IMMEDIATE &apos; CREATE GLOBAL TEMPORARY TABLE  &apos;||TMPTABLE||&apos; ON COMMIT PRESERVE ROWS AS SELECT V.* FROM &apos;||UserViewName||&apos; V &apos;;
  END IF;
  EXECUTE IMMEDIATE &apos; GRANT SELECT ON &apos;||TMPTABLE||&apos; TO &apos;||sUserName;
END;

END pkg_list_Config;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_FISAANALITIKPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79F065ABAFAD2A932F352D1E3EEB3E8F62DFA1EA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_FISAANALITIKPART IS

FUNCTION getInfoPart(
  aCodPart   IN NUMBER DEFAULT 0,
  aLunaStart IN NUMBER,
  aLunaFin   IN NUMBER,
  AreConturi IN BOOLEAN DEFAULT FALSE,
  AreMonezi  IN BOOLEAN DEFAULT FALSE,
  info_kind  IN NUMBER
) RETURN crs
IS
  CT_INFO_MONEDA CONSTANT NUMBER := 0;
  CT_INFO_CONT   CONSTANT NUMBER := 1;

  cResult      CRS;
  sSelect      VARCHAR2(5000);
  aSubunitate  NUMBER(20);
  sDistinctCol VARCHAR2(300);
  sCondPart    VARCHAR2(300);
  sFiltru      VARCHAR2(300) := &apos; 1=1 &apos;;
BEGIN
  sDistinctCol := CASE info_kind
                    WHEN CT_INFO_MONEDA THEN &apos; DISTINCT CODMONEDA, DEN_MONEDA &apos;
                    WHEN CT_INFO_CONT   THEN &apos; DISTINCT CODCONT, CONT &apos;
                  END;

  IF Coalesce(aCodPart,0) = 0
  THEN sCondPart := &apos; &lt;&gt; 0&apos;;
  ELSE sCondPart := &apos; = &apos;||Coalesce(aCodPart,0);
  END IF;

  IF pkg_globals.GETSUBUNITATE &gt; 1
  THEN aSubunitate := pkg_globals.GETSUBUNITATE;
  ELSE aSubunitate := 0;
  END IF;

  sSelect :=&apos;
  WITH
  crs_doc AS (
    SELECT g.codgeneral,g.moneda,intr.an,intr.luna
		FROM general g
      INNER JOIN intrari intr ON g.coddoc = intr.codintr AND g.tipdoc = intr.tipdoc
		WHERE intr.an * 12 + intr.luna BETWEEN &apos;||aLunaStart||&apos; AND  &apos;||aLunaFin||&apos;
		  AND G.SEMNIFICATIE NOT IN (800,801,900,901,950,951,1100,1000,1101)
      AND Coalesce(intr.partener,0)&apos;||sCondPart||
      pkg_list_base_utils.COND_SUBUNIT(pTABLA =&gt; &apos;intr&apos;, pSUBUNIT =&gt; aSubunitate)||&apos;
	  UNION ALL
    SELECT g.codgeneral,g.moneda,ies.an,ies.luna
    FROM general g
      INNER JOIN iesiri ies ON g.coddoc = ies.codies AND g.tipdoc = ies.tipdoc
    WHERE ies.an * 12 + ies.luna BETWEEN &apos;||aLunaStart||&apos; AND &apos;||aLunaFin||&apos;
      AND G.SEMNIFICATIE  NOT IN (800,801,900,901,950,951,1100,1000,1101)
      AND Coalesce(ies.partener,0)&apos;||sCondPart||
      pkg_list_base_utils.COND_SUBUNIT(pTABLA =&gt; &apos;ies&apos;, pSUBUNIT =&gt; aSubunitate)||&apos;
		UNION ALL
		SELECT g.codgeneral,g.moneda,nc.an,nc.luna
    FROM general g
      INNER JOIN nc1  ON g.coddoc = nc1.codnc1 AND g.tipdoc = 35
      INNER JOIN NC ON NC.CODNC = NC1.CODNC
    WHERE nc.an * 12 + nc.luna BETWEEN &apos;||aLunaStart||&apos; AND &apos;||aLunaFin||&apos;
      AND G.SEMNIFICATIE  NOT IN (800,801,900,901,950,951,1100,1000,1101)
      AND Coalesce(nc.part,0)&apos;||sCondPart||
      pkg_list_base_utils.COND_SUBUNIT(pTABLA =&gt; &apos;nc&apos;, pSUBUNIT =&gt; aSubunitate)||&apos;
		UNION ALL
    SELECT g.codgeneral,g.moneda,c.an,c.luna
    FROM general g
      INNER JOIN compens c ON g.coddoc = c.codcompens AND g.tipdoc = 28
    WHERE c.an * 12 + c.luna BETWEEN &apos;||aLunaStart||&apos; AND &apos;||aLunaFin||&apos;
      AND G.SEMNIFICATIE  NOT IN (800,801,900,901,950,951,1100,1000,1101)
			AND(Coalesce(c.partd,0)&apos;||sCondPart||&apos; OR Coalesce(c.partc,0)&apos;||sCondPart||&apos;)&apos;||
      pkg_list_base_utils.COND_SUBUNIT(pTABLA =&gt; &apos;c&apos;, pSUBUNIT =&gt; aSubunitate)||&apos;
		UNION ALL
    SELECT g.codgeneral,g.moneda,t1.an,t1.luna
    FROM general g
      INNER JOIN trezor1 t1 ON g.coddoc = t1.codtrezor1 AND g.tipdoc IN (29,30,31)
      INNER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
    WHERE t1.an * 12 + t1.luna BETWEEN &apos;||aLunaStart||&apos; AND &apos;||aLunaFin||&apos;
      AND G.SEMNIFICATIE  NOT IN (800,801,900,901,950,951,1100,1000,1101)
      AND Coalesce(t1.CodPart,0)&apos;||sCondPart||
      pkg_list_base_utils.COND_SUBUNIT(pTABLA =&gt; &apos;t&apos;, pSUBUNIT =&gt; aSubunitate)||&apos;
  ),
  res As (&apos;;
  IF info_kind = CT_INFO_MONEDA AND areConturi THEN
    sSelect := sSelect||&apos;
    SELECT MON.CODMONEDA, MON.DEN_MONEDA
    FROM crs_doc
      INNER JOIN nmonede mon ON mon.codmoneda = crs_doc.moneda
      INNER JOIN obligpif o ON crs_doc.codgeneral = o.codgeneral
      INNER JOIN ncont n on n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont, o.codpart, crs_doc.an*12+crs_doc.luna, o.semnificatie)
    WHERE n.codcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;)
    UNION ALL
    SELECT MON.CODMONEDA, MON.DEN_MONEDA
    FROM NPARTSOLDLUNA nps
      INNER JOIN nmonede mon ON mon.codmoneda = nps.codmoneda
      INNER JOIN ncont n ON n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(nps.icont,nps.codpart,nps.an*12+nps.luna,0)
    WHERE nps.an*12+nps.luna = &apos;||to_char(aLunaStart - 1)||&apos;
      AND nps.codpart&apos;||sCondPart||&apos;
      AND n.codcont IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODCONT&apos;&apos;)&apos;;
  ELSIF info_kind = CT_INFO_MONEDA THEN
    sSelect := sSelect||&apos;
    SELECT MON.CODMONEDA, MON.DEN_MONEDA
    FROM crs_doc
      INNER JOIN nmonede mon ON mon.codmoneda = crs_doc.moneda
    UNION ALL
    SELECT MON.CODMONEDA, MON.DEN_MONEDA
    FROM NPARTSOLDLUNA nps
      INNER JOIN nmonede mon ON mon.codmoneda = nps.codmoneda
    WHERE nps.an*12+nps.luna = &apos;||to_char(aLunaStart - 1)||&apos;
      AND nps.codpart&apos;||sCondPart;
  ELSIF info_kind = CT_INFO_CONT AND areMonezi THEN
    sSelect := sSelect||&apos;
    SELECT N.CODCONT, N.SIMBOL||&apos;&apos; - &apos;&apos;||N.DEN_CONT CONT
    FROM crs_doc
      INNER JOIN obligpif o ON crs_doc.codgeneral = o.codgeneral
      INNER JOIN ncont n on n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont, o.codpart, crs_doc.an*12+crs_doc.luna, o.semnificatie)
    WHERE crs_doc.moneda IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)
    UNION ALL
    SELECT N.CODCONT, N.SIMBOL||&apos;&apos; - &apos;&apos;||N.DEN_CONT CONT
    FROM NPARTSOLDLUNA nps
      INNER JOIN ncont n ON n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(nps.icont,nps.codpart,nps.an*12+nps.luna,0)
    WHERE nps.an*12+nps.luna = &apos;||to_char(aLunaStart - 1)||&apos;
      AND nps.codpart&apos;||sCondPart||&apos;
      AND nps.codmoneda IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;&apos;CODMONEDA&apos;&apos;)&apos;;
  ELSIF info_kind = CT_INFO_CONT THEN
    sSelect := sSelect||&apos;
    SELECT N.CODCONT, N.SIMBOL||&apos;&apos; - &apos;&apos;||N.DEN_CONT CONT
    FROM crs_doc
      INNER JOIN obligpif o ON crs_doc.codgeneral = o.codgeneral
      INNER JOIN ncont n on n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont, o.codpart, crs_doc.an*12+crs_doc.luna, o.semnificatie)
    WHERE&apos;||sFiltru||&apos;
    UNION ALL
    SELECT N.CODCONT, N.SIMBOL||&apos;&apos; - &apos;&apos;||N.DEN_CONT CONT
    FROM NPARTSOLDLUNA nps
      INNER JOIN ncont n ON n.codcont = PKG_LIST_BASE_UTILS.iCont_CodCont(nps.icont,nps.codpart,nps.an*12+nps.luna,0)
    WHERE nps.an*12+nps.luna = &apos;||to_char(aLunaStart - 1)||&apos;
      AND nps.codpart&apos;||sCondPart||&apos;
      AND&apos;||sFiltru;
  END IF;
  sSelect := sSelect||&apos;
  )
  SELECT &apos;||sDistinctCol||&apos;
  FROM res&apos;;

  BEGIN
    OPEN cResult FOR sSelect;
  EXCEPTION WHEN OTHERS THEN
    OPEN cResult FOR SELECT 0, &apos;x&apos; FROM dual;
  END;
  RETURN cResult;
END;

END pkg_list_fisaanalitikPart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>246AB4DFDD6340D52368CC35E4933484BB9F7B39</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selart IS

gAllArt BOOLEAN;

PROCEDURE setParam (pAllArt BOOLEAN) IS
BEGIN
  gAllArt := pAllArt;
END;

FUNCTION IsAllArt RETURN BOOLEAN IS
BEGIN
  RETURN gAllArt;
END;

END pkg_list_selart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELCLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA923665DCE3D0B83560944CF90B8C75F8302874</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELCLASEART IS

  vPerioada    VARCHAR2(100);
  vToateClaseA BOOLEAN ;
  vTotiPart    BOOLEAN ;

PROCEDURE SETPARAMS(    pPerioada    IN VARCHAR2 DEFAULT NULL,
                        pToateClaseA IN NUMBER DEFAULT 1,
                        pTotiPart    IN NUMBER DEFAULT 1,
	                      v_DataIni IN VARCHAR2,
                        v_DataFin IN VARCHAR2,
                        pCodJob1 IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
	p_DataIni VARCHAR2(10);
  p_DataFin VARCHAR2(10);
BEGIN
  vPerioada    := pPerioada;
  p_DataIni := v_DataIni;
  p_DataFin := v_DataFin;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,p_DataIni,p_DataFin,xLunaAnIni,xLunaAnFin);
    vPerioada    := &apos;TO_DATE(&apos;&apos;&apos;||p_DataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos; +&apos; AND TO_DATE(&apos;&apos;&apos;||p_DataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
	END IF;
  vToateClaseA := pToateClaseA = 1;
  vTotiPart    := pTotiPart = 1;
END;

  FUNCTION Perioada    RETURN VARCHAR2 IS 
  BEGIN
    return vPerioada;
  END;
  
  FUNCTION ToateClaseA RETURN BOOLEAN IS 
  BEGIN
    return vToateClaseA;
  END;
  
  FUNCTION TotiPart    RETURN BOOLEAN IS 
  BEGIN
    return vTotiPart;
  END;
  
end PKG_LIST_SELCLASEART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELCOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A0A1B31E2E9C19B33543FD32262B0B82FD78BC0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELCOMENZI IS
  vDupaData    BOOLEAN;
  vPerioada    VARCHAR2(200);
  vAllGest     BOOLEAN;
  vComInchise  NUMBER(5);

PROCEDURE setParams (
  pDupaData IN NUMBER   DEFAULT 0,
  pPerS     IN VARCHAR2 DEFAULT NULL,
  pPerF     IN VARCHAR2 DEFAULT NULL,
  pAllGest  IN NUMBER   DEFAULT 0,
  pComInchise IN NUMBER DEFAULT 0,
  V_CODJOB1 IN NUMBER   DEFAULT 0)
IS
  sDataS VARCHAR2(10);
  sDataF VARCHAR2(10);
  vAL_S  INTEGER;
  vAL_F  INTEGER;
BEGIN
  vDupaData := Coalesce(pDupaData, 0) = 1;
  vAllGest  := Coalesce(pAllGest,  0) = 1;
  vCOmInchise := pComInchise;
  IF vDupaData THEN
    sDataS := pPerS;
    sDataF := pPerF;
  ELSE
    vAL_S  := To_Number(pPerS);
    vAL_F  := To_Number(pPerF);
  END IF;

  IF V_CODJOB1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,vAL_S,vAL_F);
  END IF;

  IF    vDupaData AND sDataS = sDataF THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  ELSIF vDupaData                     THEN vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  ELSIF               vAL_S  = vAL_F  THEN vPerioada := &apos;= &apos;||vAL_S;
  ELSE                                     vPerioada := &apos;BETWEEN &apos;||vAL_S||&apos; AND &apos;||vAL_F;
  END IF;
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION AllGest RETURN BOOLEAN IS
BEGIN
  return vAllGest;
END;

FUNCTION ComInchise RETURN NUMBER IS
BEGIN
  return vComInchise;
END;

FUNCTION Perioada RETURN VARCHAR2 IS
BEGIN
  return vPerioada;
END;

END PKG_LIST_SELCOMENZI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5102BB007E1FD5BB4860C92775408879B044646</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELCONT IS

  gLunaS    NUMBER(20);
  gLunaF    NUMBER(20);
  gPlan     INTEGER;
  gLuna     VARCHAR2(100);
  gCuObs    BOOLEAN;
  gSoldSub  BOOLEAN;
  gSubunit  NUMBER(20);

FUNCTION GetPerioadaAni return crsGlobal is
  crsResult crsGlobal;
BEGIN
  OPEN crsResult FOR
  SELECT
    CASE WHEN (luna+nr) &lt;= 12 then (luna+nr) ELSE (luna+nr) - 12 END + CASE WHEN (luna + nr) &lt;= 12 THEN an ELSE an + 1 END *12 idxluna,
    pkg_list_base_utils.decode_luna(case when mod((luna+nr),12) = 0 then (12) else mod((luna+nr),12) end) || &apos; &apos; ||
    extract (year from add_months(to_date(luna||&apos;.&apos;||an,&apos;mm.yyyy&apos;),nr)) luna
  FROM  (
    SELECT aninitial an ,lunainitiala luna ,(level-1) nr
    FROM firmaluni f
    CONNECT BY LEVEL &lt;= (f.anmaxim*12+f.lunamaxima) - (f.aninitial * 12 + f.lunainitiala) + 1
  );

 Return crsResult;
end;

FUNCTION GetPerioada RETURN crsGlobal IS
  crsResult crsGlobal;
BEGIN
  OPEN crsResult FOR

	WITH crs AS (
    SELECT
      CASE
        WHEN pkg_globals.ANLUCRU &gt; pkg_globals.ANINITIAL THEN 1
        WHEN pkg_globals.ANLUCRU = pkg_globals.ANINITIAL  THEN pkg_globals.LUNAINITIALA
        ELSE NULL
      END lunaini
    FROM dual )
  SELECT crs.lunaini + ROWNUM - 1 AS idxluna, pkg_list_base_utils.decode_luna(crs.lunaini + ROWNUM - 1) AS luna
  FROM  dual, crs
  CONNECT BY LEVEL  &lt;= (SELECT CASE
                                  WHEN pkg_globals.ANLUCRU &gt; pkg_globals.ANINITIAL THEN pkg_globals.LUNALUCRU - 1
                                  WHEN pkg_globals.ANLUCRU = pkg_globals.ANINITIAL THEN pkg_globals.LUNALUCRU - pkg_globals.LUNAINITIALA
																	ELSE NULL
																END
	                  FROM dual) + 1;
  RETURN crsResult;
END;

FUNCTION GetConturiCuMiscare (pLunaStart IN NUMBER , pLunaFin IN NUMBER) RETURN crsGlobal IS
  crsResult crsGlobal;
BEGIN
  OPEN crsResult FOR
  SELECT nc.codcont,nc.simbol,nc.den_cont denumire, decode(nc.tipcont,0,&apos;Activ&apos;,1,&apos;Pasiv&apos;,2,&apos;Bifunc.&apos;) tip,nc.codparinte
  FROM ncont nc
    INNER JOIN (
      SELECT jc.contc cont
      FROM jurnal jc
      WHERE jc.an*12+jc.luna BETWEEN pLunaStart AND pLunaFin
      UNION
      SELECT jd.contd cont
      FROM jurnal jd
      WHERE jd.an*12+jd.luna BETWEEN pLunaStart AND pLunaFin
    ) conturi ON nc.codcont = conturi.cont;

 RETURN crsResult;
END;

PROCEDURE SetParams (
  pLunaStart IN NUMBER,
  pLunaFin   IN NUMBER,
  pPlan      IN NUMBER,
  pCuObs     IN NUMBER,
  pSubunit   IN NUMBER DEFAULT 1,
  pSoldSub   IN NUMBER DEFAULT 0,
  pCodJob1   IN NUMBER DEFAULT 0)
IS
  vDataS     DATE;
  vDataF     DATE;
  sSelContS  VARCHAR2(3200);
  sSelContD  VARCHAR2(3200);
BEGIN
  gLunaS   := pLunaStart;
  gLunaF   := pLunaFin;
  gPlan    := pPlan;
  gCuObs   := Coalesce(pCuObs,   0) = 1;
  gSoldSub := Coalesce(pSoldSub, 0) = 1;

  gSubunit := Coalesce(pSubunit, 1);
  IF Coalesce(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataS,vDataF,gLunaS,gLunaF);
    IF gSubunit = 1 THEN
      gSubunit := 0;
    END IF;
  END IF;

  IF gSubunit &gt; 1 AND pkg_categconst.GetValConstanta(&apos;Holding&apos;, 0, gLunaF) = 1 THEN
    gSoldSub := TRUE;
  END IF;
  --parametrii oracle
  pkg_list_Struct.GOLESTE_PARAM;
  pkg_globals.SetSeparator(&apos;,&apos;);

  IF gPlan = 2 THEN -- plan secundar
    SELECT vc2_nt_to_vc3200(CAST(COLLECT(Simbol   ORDER BY clasa, simbol) AS vc2_nt)), vc2_nt_to_vc3200(CAST(COLLECT(Den_Cont ORDER BY clasa, simbol) AS vc2_nt)) INTO sSelContS, sSelContD
    FROM nconts
    WHERE codconts IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODCONT&apos;);
  ELSIF gPlan = 3 THEN -- plan tertiar
    SELECT vc2_nt_to_vc3200(CAST(COLLECT(Simbol   ORDER BY clasa, simbol) AS vc2_nt)), vc2_nt_to_vc3200(CAST(COLLECT(Den_Cont ORDER BY clasa, simbol) AS vc2_nt)) INTO sSelContS, sSelContD
    FROM ncontt c
    WHERE c.codcontt IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODCONT&apos;);
  ELSE -- plan principal
    SELECT vc2_nt_to_vc3200(CAST(COLLECT(Simbol   ORDER BY clasa, simbol) AS vc2_nt)), vc2_nt_to_vc3200(CAST(COLLECT(Den_Cont ORDER BY clasa, simbol) AS vc2_nt)) INTO sSelContS, sSelContD
    FROM ncont c
    WHERE c.codcont IN (SELECT VALOARE FROM tmp_manevra_liste WHERE filtru = &apos;CODCONT&apos;);
  END IF;

  pkg_list_Struct.ADAUGA_PARAM(&apos;Conturi selectate&apos;,             sSelContS);
  pkg_list_Struct.ADAUGA_PARAM(&apos;Conturi selectate - denumiri&apos;,  sSelContD);

END;

FUNCTION GetLunaStart RETURN NUMBER IS
BEGIN
  RETURN gLunaS;
END;

FUNCTION GetLunaStop RETURN NUMBER IS
BEGIN
RETURN gLunaF;
END;

FUNCTION getTipPlan RETURN INTEGER IS
BEGIN
 RETURN gPlan;
END;

FUNCTION getCuObs RETURN BOOLEAN IS
BEGIN
 RETURN gCuObs;
END;

FUNCTION getSubunit RETURN NUMBER IS
BEGIN
 RETURN gSubunit;
END;

FUNCTION getSoldSub RETURN BOOLEAN IS
BEGIN
 RETURN gSoldSub;
END;

FUNCTION getLuna RETURN VARCHAR2 IS
BEGIN
  RETURN &apos; BETWEEN &apos;||gLunaS||&apos; AND &apos;||gLunaF;
END;


end pkg_list_selCont;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELDATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E78B53C803C01D77A0DBA35360E35BDC0B0F058</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELDATA IS

  vDataRef    DATE;
  vCodExtra1  NUMBER;
  vChkExtra1  BOOLEAN;

PROCEDURE setAllParams(pDataRef   IN VARCHAR2 DEFAULT NULL,
                       pCodExtra1 IN NUMBER   DEFAULT NULL,
                       pChkExtra1 IN NUMBER   DEFAULT 0) IS
BEGIN
  vDataRef   := To_Date(pDataRef,&apos;dd.mm.yyyy&apos;);
  vCodExtra1 := pCodExtra1;
  vChkExtra1 := pChkExtra1 = 1;
END;

FUNCTION GetDataRef RETURN DATE IS
BEGIN
 RETURN vDataRef;
END;

FUNCTION CodExtra1 RETURN NUMBER IS
BEGIN
  return vCodExtra1;
END;

FUNCTION ChkExtra1 RETURN BOOLEAN IS
BEGIN
  return vChkExtra1;
END;

END PKG_LIST_SELDATA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELDELEGAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0825188A6CE37B72F9CB16CDDBA0426B6B7813C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELDELEGAT IS

  vAllDeleg    BOOLEAN;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;

  PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                        pDataIni    IN VARCHAR2 DEFAULT NULL,
                        pDataFin    IN VARCHAR2 DEFAULT NULL,
                        pLunaAnIni  IN INTEGER  DEFAULT 0,
                        pLunaAnFin  IN INTEGER  DEFAULT 0,
                        pAllDeleg   IN NUMBER   DEFAULT 1,
                        v_CODJOB1   IN NUMBER   DEFAULT 0 )
  IS
  BEGIN
    vAllDeleg    := pAllDeleg = 1;
    vDupaData    := pDupaData  = 1;

    vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
    vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
    vLunaAnIni := NVL(pLunaAnIni,0);
    vLunaAnFin := NVL(pLunaAnFin,0);
    if v_CodJob1 &gt; 0 then 
      PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin); 
    end if;

    PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataIni,vDataFin);
  END;

  FUNCTION DupaData RETURN BOOLEAN IS
  BEGIN
    return vDupaData;
  END;

  FUNCTION DataIni RETURN DATE IS
  BEGIN
    return vDataIni;
  END;

  FUNCTION DataFin RETURN DATE IS
  BEGIN
    return vDataFin;
  END;

  FUNCTION LunaAnIni RETURN INTEGER IS
  BEGIN
    return vLunaAnIni;
  END;

  FUNCTION LunaAnFin RETURN INTEGER IS
  BEGIN
    return vLunaAnFin;
  END;

  FUNCTION TotiDelegatii  RETURN BOOLEAN IS
  BEGIN
    return vAllDeleg;
  END;

END PKG_LIST_SELDELEGAT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELDOCEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D856A33A10F80354681FC8D8FFB86791F7132885</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELDOCEXT IS
  vDupaData    BOOLEAN ;
  vPerioada    VARCHAR2(200);
  vDataS       DATE;
  vDataF       DATE;
  vAtrib1      INTEGER;

PROCEDURE setParams (
  pDupaData IN NUMBER  DEFAULT 0,
  pDataS    IN VARCHAR2,
  pDataF    IN VARCHAR2,
  V_CODJOB1 IN NUMBER  DEFAULT 0
) IS
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10);
  sDataF     VARCHAR2(10);
BEGIN
  vDupaData  := Coalesce(pDupaData, 0) = 1;
  vDataS     := To_Date(pDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(pDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);
  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataS,vDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  sDataS     := To_Char(vDataS,&apos;dd.mm.yyyy&apos;);
  sDataF     := To_Char(vDataF,&apos;dd.mm.yyyy&apos;);

  IF    DupaData AND vDataS = vDataF THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF DupaData                     THEN vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF xLunaAnIni = xLunaAnFin      THEN vPerioada := &apos;= &apos;||To_Char(xLunaAnIni);
  ELSE                                    vPerioada := &apos;BETWEEN &apos;||To_Char(xLunaAnIni)||&apos; AND &apos;||To_Char(xLunaAnFin);
  END IF;

  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataS, vDataF);
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION Perioada RETURN VARCHAR2 IS
BEGIN
  return vPerioada;
END;

FUNCTION DataS RETURN DATE IS
BEGIN
  return vDataS;
END;

FUNCTION DataF RETURN DATE IS
BEGIN
  return vDataF;
END;

END PKG_LIST_SELDOCEXT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2E3A0CB68C8677AD55B02697DE25C286C53FC81</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selectemulare IS

  p_DataIni DATE;
  p_DataFin DATE;
  p_TipPrel NUMBER;
  p_TipFiltrare NUMBER;
  p_SiRetur BOOLEAN;

PROCEDURE setParams( v_DataIni IN VARCHAR2, 
	                   v_DataFin IN VARCHAR2, 
										 v_TipPrel IN NUMBER, 
										 v_TipFiltrare IN NUMBER, 
										 v_SiRetur IN NUMBER DEFAULT 0,
                     v_CODJOB1   IN NUMBER   DEFAULT 0 
										 ) 
										 IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  p_DataIni := to_date(v_DataIni,&apos;DD.MM.YYYY HH24:MI&apos;);
  p_DataFin := to_date(v_DataFin,&apos;DD.MM.YYYY HH24:MI&apos;);
	if v_CodJob1 &gt; 0 then 
		PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(v_CODJOB1,p_DataIni,p_DataFin,xLunaAnIni,xLunaAnFin); 
	end if;

  p_TipPrel := v_TipPrel;
  p_TipFiltrare := v_TipFiltrare;
  p_SiRetur := v_SiRetur = 1;
END;

FUNCTION getDataIni RETURN DATE IS
BEGIN
  RETURN p_DataIni;
END;

FUNCTION getDataFin RETURN DATE IS
BEGIN
  RETURN p_DataFin;
END;

FUNCTION  getTipPrel RETURN NUMBER IS
BEGIN
  RETURN p_TipPrel;
END;

FUNCTION  getTipFiltrare RETURN NUMBER IS
BEGIN
  RETURN p_TipFiltrare;
END;

function getSiRetur return boolean is 
begin
  RETURN p_SiRetur;
end;  

END PKG_LIST_SELECTEMULARE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9075B7F4D9AB3DF8CC88318AF9E1A69F68FF54DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTGEST IS

  vAllGest     BOOLEAN;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  vAduSerii    INTEGER;
  bCalcPMP     BOOLEAN;
  bDataDoc     BOOLEAN;
  bExtra1      BOOLEAN;
  bExtra2      BOOLEAN;
  bExtra3      BOOLEAN;
  bAllTipDoc   BOOLEAN;
  bDocs        VARCHAR2(50);

  PROCEDURE SETPARAMS(
    pDataIni    IN VARCHAR2 DEFAULT NULL,
    pDataFin    IN VARCHAR2 DEFAULT NULL,
    pAllGest    IN NUMBER   DEFAULT 1,
    pDupaData   IN NUMBER   DEFAULT 1,
    pLunaAnIni  IN INTEGER  DEFAULT 0,
    pLunaAnFin  IN INTEGER  DEFAULT 0,
    pAduSerii   IN NUMBER   DEFAULT 1,
    pCalcPMP    IN NUMBER   DEFAULT 0,
    pDataDoc    IN NUMBER   DEFAULT 1,
    pExtra1     IN NUMBER   DEFAULT 0,
    v_CODJOB1   IN NUMBER   DEFAULT 0,
    pExtra2     IN NUMBER   DEFAULT 0,
    pExtra3     IN NUMBER   DEFAULT 0,
    pAllTipDoc  IN NUMBER   DEFAULT 1,
    sDocs       IN VARCHAR2 DEFAULT NULL
  ) IS
  BEGIN
    vAllGest     := pAllGest = 1;
    vDupaData    := pDupaData = 1;

    vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
    vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
    vLunaAnIni := NVL(pLunaAnIni,0);
    vLunaAnFin := NVL(pLunaAnFin,0);
    if NVL(v_CodJob1,0) &gt; 0 then
      PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
    end if;

    PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataIni,vDataFin);

    vAduSerii    := pAduSerii;
    bCalcPMP     := pCalcPMP = 1;
    bDataDoc     := pDataDoc = 1;
    bExtra1      := pExtra1  = 1;
    bExtra2      := pExtra2  = 1;
    bExtra3      := pExtra3  = 1;
    bAllTipDoc   := pAllTipDoc = 1;
    bDocs        := sDocs;
  END;

  FUNCTION DataDoc  RETURN BOOLEAN IS
  BEGIN
   return bDataDoc;
  END;

  FUNCTION ToateGest RETURN BOOLEAN IS
  BEGIN
    return vAllGest;
  END;

  FUNCTION ToateTipDoc RETURN BOOLEAN IS
  BEGIN
    return bAllTipDoc;
  END;

  FUNCTION Docs RETURN VARCHAR2 IS
  BEGIN
    return bDocs;
  END;

  FUNCTION DupaData RETURN BOOLEAN IS
  BEGIN
    return vDupaData;
  END;

  FUNCTION DataIni RETURN DATE IS
  BEGIN
    return vDataIni;
  END;

  FUNCTION DataFin RETURN DATE IS
  BEGIN
    return vDataFin;
  END;

  FUNCTION LunaAnIni RETURN INTEGER IS
  BEGIN
    return vLunaAnIni;
  END;

  FUNCTION LunaAnFin RETURN INTEGER IS
  BEGIN
    return vLunaAnFin;
  END;

  FUNCTION AduSerii RETURN INTEGER IS
  BEGIN
    RETURN vAduSerii;
  END;

  FUNCTION CalculeazaPMP RETURN BOOLEAN IS
  BEGIN
    RETURN bCalcPMP;
  END;

  FUNCTION Extra1 RETURN BOOLEAN IS
  BEGIN
    RETURN bExtra1;
  END;

  FUNCTION Extra2 RETURN BOOLEAN IS
  BEGIN
    RETURN bExtra2;
  END;

  FUNCTION Extra3 RETURN BOOLEAN IS
  BEGIN
    RETURN bExtra3;
  END;

end PKG_LIST_SELECTGEST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTGEST2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE2AF53E77CA86BD04C077C24C9A3B8E812DC695</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTGEST2 IS

  vAllGest     BOOLEAN;
  vAllIoart    BOOLEAN;
  vZiIni       INTEGER;
  vZiFin       INTEGER;
  vTipDataIntr INTEGER;
  vData        INTEGER;

PROCEDURE SETPARAMS(
  pAllGest  IN NUMBER  DEFAULT 1,
  pZiuaIni  IN INTEGER DEFAULT NULL,
  pZiuaFin  IN INTEGER DEFAULT NULL,
  pAllIOArt IN NUMBER  DEFAULT 1,
  pData     IN NUMBER  DEFAULT 1
) IS
  vZiMax INTEGER := Extract (DAY FROM Last_Day(To_Date(to_char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||&apos;.&apos;||to_char(pkg_globals.ANLUCRU,&apos;fm0000&apos;),&apos;mm.yyyy&apos;))) ;
BEGIN
  vAllGest  := pAllGest  = 1;
  vAllIOArt := pAllIOArt = 1;
  vZiIni    := Least(pZiuaIni, vZiMax);
  vZiFin    := Least(pZiuaFin, vZiMax);
  vData     := pData;
END;

FUNCTION ToateGest RETURN BOOLEAN IS
BEGIN
  return vAllGest;
END;

FUNCTION ZiuaIni     RETURN INTEGER IS
BEGIN
  return vZiIni;
END;

FUNCTION ZiuaFin     RETURN INTEGER IS
BEGIN
  return vZiFin;
END;

FUNCTION TipData RETURN INTEGER IS
BEGIN
  return vData;
END;

FUNCTION ToateIoart RETURN BOOLEAN IS
BEGIN
  return vAllIoart;
END;

END PKG_LIST_SELECTGEST2;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTGESTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8777A6B992117223F0C3C475B6566FEDEB9915E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTGESTART IS

  vAllGest    BOOLEAN;
  vAllArt     BOOLEAN;
  vDataStart  DATE;
  vDataFin    DATE;
  vCodComanda NUMBER;
  vSerii      NUMBER;
  vAnaliza    NUMBER;
  vSaptamana  NUMBER;

PROCEDURE SetParams(
  pAllGest    IN NUMBER DEFAULT 1,
  pAllArt     IN NUMBER DEFAULT 1,
  pDataStart  IN VARCHAR2,
  pDataFin    IN VARCHAR2,
  pCodComanda IN NUMBER DEFAULT 0,
  pSerii      IN NUMBER DEFAULT 0,
  pCodJob1 IN NUMBER  DEFAULT 0,
  pAnaliza IN NUMBER  DEFAULT 0,
  pSaptamana IN NUMBER DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vAllGest    := pAllGest = 1;
  vAllArt     := pAllArt = 1;
  vDataStart  := To_Date(pDataStart,&apos;DD.MM.YYYY&apos;);
  vDataFin    := To_Date(pDataFin,&apos;DD.MM.YYYY&apos;);
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataStart,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
  vCodComanda := NVL(pCodComanda,0);
  vSerii      := NVL(pSerii,0);
  vAnaliza    := pAnaliza;
  vSaptamana  := pSaptamana;
END;

FUNCTION DataStart RETURN DATE IS
BEGIN
  RETURN vDataStart;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  RETURN vDataFin;
END;

FUNCTION AllGest RETURN BOOLEAN IS
BEGIN
  RETURN vAllGest;
END;

FUNCTION AllArt RETURN BOOLEAN IS
BEGIN
  RETURN vAllArt;
END;

FUNCTION CodComanda RETURN NUMBER IS
BEGIN
  RETURN vCodComanda;
END;

FUNCTION Saptamana RETURN NUMBER IS
BEGIN
  RETURN vSaptamana;
END;

FUNCTION Analiza RETURN NUMBER IS
BEGIN
  RETURN vAnaliza;
END;

FUNCTION Serii RETURN NUMBER IS
BEGIN
  RETURN vSerii;
END;

END pkg_list_selectgestart; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTGESTPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C79126416FA45EA09E353D6C7BFE25467BEE0BD2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selectgestper is

  vAllGest     BOOLEAN;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  bAduSerii    BOOLEAN;
  bCalcPMP     BOOLEAN;
  bDataDoc     BOOLEAN;
  bExtra1      BOOLEAN;
  bExtra2      BOOLEAN;
  bExtra3      BOOLEAN;
  bIndiferent  BOOLEAN;
  vDataDocIni  DATE;
  vDataDocFin  DATE;
  vCod         NUMBER(20);

PROCEDURE SETPARAMS(  pDataIni    IN VARCHAR2 DEFAULT NULL,
                      pDataFin    IN VARCHAR2 DEFAULT NULL,
                      pAllGest    IN NUMBER   DEFAULT 1,
                      pDupaData   IN NUMBER   DEFAULT 1,
                      pLunaAnIni  IN INTEGER  DEFAULT 0,
                      pLunaAnFin  IN INTEGER  DEFAULT 0,
                      pAduSerii   IN NUMBER   DEFAULT 1,
                      pCalcPMP    IN NUMBER   DEFAULT 0,
                      pDataDoc    IN NUMBER   DEFAULT 1,
                      pExtra1     IN NUMBER   DEFAULT 0,
                      v_CODJOB1   IN NUMBER   DEFAULT 0,
                      pExtra2     IN NUMBER   DEFAULT 0,
                      pExtra3     IN NUMBER   DEFAULT 0,
                      pIndiferent IN NUMBER   DEFAULT 1,
                      pDataDocIni IN VARCHAR2 DEFAULT NULL,
                      pDataDocFin IN VARCHAR2 DEFAULT NULL,
                      pCod        IN NUMBER   DEFAULT 0
                      )
IS
BEGIN
  vAllGest     := pAllGest = 1;
  vDupaData    := pDupaData = 1;

  vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vLunaAnIni := NVL(pLunaAnIni,0);
  vLunaAnFin := NVL(pLunaAnFin,0);
  if NVL(v_CodJob1,0) &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
  end if;

  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataIni,vDataFin);

  bAduSerii    := pAduSerii = 1;
  bCalcPMP     := pCalcPMP = 1;
  bDataDoc     := pDataDoc = 1;
  bExtra1      := pExtra1 = 1;
  bExtra2      := pExtra2 = 1;
  bExtra3      := pExtra3 = 1;
  bIndiferent  := pIndiferent = 1;
  if pDataDocIni = &apos;  .  .    &apos; then
    vDataDocIni := vDataIni;
  else   
    vDataDocIni  := to_date(pDataDocIni,&apos;dd.mm.yyyy&apos;);
  end if;
  if pDataDocFin = &apos;  .  .    &apos; then  
    vDataDocFin  := vDataFin;
  else
    vDataDocFin  := to_date(pDataDocFin,&apos;dd.mm.yyyy&apos;);
  end if;
  vCod := pCod;  
END;

FUNCTION DataDoc  RETURN BOOLEAN IS
BEGIN
 return bDataDoc;
END;

FUNCTION ToateGest RETURN BOOLEAN IS
BEGIN
  return vAllGest;
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION LunaAnIni RETURN INTEGER IS
BEGIN
  return vLunaAnIni;
END;

FUNCTION LunaAnFin RETURN INTEGER IS
BEGIN
  return vLunaAnFin;
END;

FUNCTION AduSerii RETURN BOOLEAN IS
BEGIN
  RETURN bAduSerii;
END;

FUNCTION CalculeazaPMP RETURN BOOLEAN IS
BEGIN
  RETURN bCalcPMP;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  RETURN bExtra1;
END;

FUNCTION Extra2 RETURN BOOLEAN IS
BEGIN
  RETURN bExtra2;
END;
  
FUNCTION Extra3 RETURN BOOLEAN IS
BEGIN
  RETURN bExtra3;
END;

FUNCTION Indiferent RETURN BOOLEAN IS
BEGIN
  RETURN bIndiferent;
END;

FUNCTION DataDocIni RETURN DATE IS
BEGIN
  return vDataDocIni;
END;

FUNCTION DataDocFin RETURN DATE IS
BEGIN
  return vDataDocFin;
END;

FUNCTION Cod RETURN NUMBER IS
BEGIN
  return vCod;
END;
  
end pkg_list_selectgestper; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTGESTREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2598BDC771959894F90B334F1C881529A9EADEF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTGESTREST IS

  p_DataIni DATE;
  p_DataFin DATE;

PROCEDURE setParams(  v_DataIni IN VARCHAR2, 
	                    v_DataFin IN VARCHAR2, 
											v_CodGest IN NUMBER,
                      pCodJob1 IN NUMBER  DEFAULT 0 )
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  p_DataIni := to_date(v_DataIni,&apos;DD.MM.YYYY HH24:MI&apos;);
  p_DataFin := to_date(v_DataFin,&apos;DD.MM.YYYY HH24:MI&apos;);
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,p_DataIni,p_DataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

FUNCTION getDataIni RETURN DATE IS
BEGIN
  RETURN p_DataIni;
END;

FUNCTION getDataFin RETURN DATE IS
BEGIN
  RETURN p_DataFin;
END;

END PKG_LIST_SELECTGESTREST;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTIEPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>314156610B3950E05A764EDD4C11B3A747926FD4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTIEPROFIT IS

  vAllGest     BOOLEAN;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  vIntern      BOOLEAN;
  vExtern      BOOLEAN;
  vTransf      BOOLEAN;
  vSubunit     BOOLEAN;
  vFactAviz    BOOLEAN;
  vExtra1      BOOLEAN;
  vExtra2      BOOLEAN;
  vMon         BOOLEAN;
  vExtra3      BOOLEAN;

PROCEDURE SETPARAMS(pDataIni     IN VARCHAR2 DEFAULT NULL,
                    pDataFin     IN VARCHAR2 DEFAULT NULL,
                    pAllGest     IN NUMBER   DEFAULT 1,
                    pDupaData    IN NUMBER   DEFAULT 1,
                    pLunaAnIni   IN INTEGER  DEFAULT 0,
                    pLunaAnFin   IN INTEGER  DEFAULT 0,
                    pIntern      IN NUMBER   DEFAULT 1,
                    pExtern      IN NUMBER   DEFAULT 1,
                    pTransf      IN NUMBER   DEFAULT 1,
                    pSubunit     IN NUMBER   DEFAULT 1,
                    pFactAviz    IN NUMBER   DEFAULT 1,
                    pExtra1      IN NUMBER   DEFAULT 0,
                    pExtra2      IN NUMBER   DEFAULT 0,
                    pMon         IN NUMBER   DEFAULT 1,
                    pExtra3      IN NUMBER   DEFAULT 0,
                    pCodJob1 IN NUMBER  DEFAULT 0 )
IS
BEGIN
  vAllGest     := pAllGest = 1;
  vDupaData    := pDupaData = 1;
  vDataIni     := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin     := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vLunaAnIni   := NVL(pLunaAnIni,0);
  vLunaAnFin   := NVL(pLunaAnFin,0);
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
  END IF;
  vIntern      := pIntern = 1;
  vExtern      := pExtern = 1;
  vTransf      := pTransf = 1;
  vSubunit     := pSubunit = 1;
  vFactAviz    := pFactAviz = 1;
  vExtra1      := pExtra1 = 1;
  vExtra2      := pExtra2 = 1;
  vExtra3      := pExtra3 = 1;
  vMon         := pMon = 1;
END;

FUNCTION ToateGest RETURN BOOLEAN IS
BEGIN
  return vAllGest;
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION LunaAnIni RETURN INTEGER IS
BEGIN
  return vLunaAnIni;
END;

FUNCTION LunaAnFin RETURN INTEGER IS
BEGIN
  return vLunaAnFin;
END;

FUNCTION DocInterne RETURN BOOLEAN IS
BEGIN
  return vIntern;
END;

FUNCTION DocExterne RETURN BOOLEAN IS
BEGIN
  return vExtern;
END;

FUNCTION DocTransf RETURN BOOLEAN IS
BEGIN
  return vTransf;
END;

FUNCTION DocMon RETURN BOOLEAN IS
BEGIN
  return vMon;
END;

FUNCTION DocSubunit RETURN BOOLEAN IS
BEGIN
  return vSubunit;
END;

FUNCTION DocFactAviz RETURN BOOLEAN IS
BEGIN
  return vFactAviz;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  return vExtra1;
END;

FUNCTION Extra2 RETURN BOOLEAN IS
BEGIN
  return vExtra2;
END;

FUNCTION Extra3 RETURN BOOLEAN IS
BEGIN
  return vExtra3;
END;

END pkg_list_selectieprofit; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96436EC9A9D2A373F3156349751EBE2D256BFAE8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTIOART IS

vToateIOArt BOOLEAN;
vExtra BOOLEAN;
vExtra2 BOOLEAN;
  
PROCEDURE SETPARAMS(pToateIOArt IN NUMBER DEFAULT 1, pExtra in number default 0, pExtra2 in number default 1)
IS
BEGIN
  vToateIOArt := pToateIOArt = 1;
  vExtra      := pExtra = 1;
  vExtra2     := pExtra2 = 1;
END;
  
FUNCTION ToateIOArt RETURN BOOLEAN IS 
BEGIN
  RETURN vToateIOArt;       
END;

FUNCTION Extra RETURN BOOLEAN IS 
BEGIN
  RETURN vExtra;       
END;

FUNCTION Extra2 RETURN BOOLEAN IS 
BEGIN
  RETURN vExtra2;       
END;

end PKG_LIST_SELECTIOART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37BC614EEA253ADD57C92F96663C5A0619D6B403</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTLUNA IS

  vLunaStart  NUMBER;
  vLunaFin    NUMBER;
  vLista      NUMBER;
  vCurs       NUMBER;
  vExtra1     NUMBER;
  vFixed      NUMBER;
  vValuta     NUMBER;
  vExtra2     NUMBER;
  vExtra3     NUMBER;

PROCEDURE SETPARAMS(
  p_LunaStart IN NUMBER,
	p_LunaFin   IN NUMBER,
	p_Curs      IN NUMBER DEFAULT 1,
  p_Extra1    IN NUMBER DEFAULT 0,
  pCodJob1    IN NUMBER DEFAULT 0,
  p_Fixed     IN NUMBER DEFAULT 0,
  p_Valuta    IN NUMBER DEFAULT 0,
  p_Extra2    IN NUMBER DEFAULT 0,
  p_Extra3    IN NUMBER DEFAULT 0
) IS
  vALIni    INTEGER;
  vALFin    INTEGER;
  vAn       INTEGER;
  vDif      INTEGER;
  vDataIni  DATE;
  vDataFin  DATE;
BEGIN
  vDif   := p_LunaFin - p_LunaStart;
  vALIni := pkg_globals.GetANLUCRU*12+p_LunaStart;
  vALFin := pkg_globals.GetANLUCRU*12+p_LunaFin;
  IF pCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vALIni,vALFin);
  END IF;

  PKG_LIST_BASE_UTILS.ExtractAnLuna(vALFin, vAn, vLunaFin);
  vLunaStart := Greatest(vLunaFin - vDif, 1);
  vCurs      := CASE
                  WHEN p_Valuta = -1 THEN -1
                  WHEN p_Valuta =  0 THEN  1
                  ELSE Coalesce(NULLIF(p_Curs, 0),1)
                END;
  vExtra1    := p_Extra1;
  vFixed     := p_Fixed;
  vValuta    := p_Valuta;
  vExtra2    := p_Extra2;
  vExtra3    := p_Extra3;
END;

FUNCTION LunaStart RETURN NUMBER IS
BEGIN
  return vLunaStart;
END;

FUNCTION LunaFin   RETURN NUMBER IS
BEGIN
  RETURN vLunaFin;
END;

FUNCTION Curs RETURN NUMBER IS
BEGIN
  RETURN vCurs;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  RETURN (vExtra1 = 1);
END;

FUNCTION Extra2 RETURN BOOLEAN IS
BEGIN
  RETURN (vExtra2 = 1);
END;

FUNCTION Extra3 RETURN BOOLEAN IS
BEGIN
  RETURN (vExtra3 = 1);
END;

FUNCTION Extra2Numeric RETURN NUMBER IS
BEGIN
  RETURN vExtra2;
END;

FUNCTION Extra3Numeric RETURN NUMBER IS
BEGIN
  RETURN vExtra3;
END;

FUNCTION ColFix RETURN BOOLEAN IS
BEGIN
  RETURN (vFixed = 1);
END;

FUNCTION isValuta RETURN BOOLEAN IS
BEGIN
  RETURN (vValuta = 1);
END;

end PKG_LIST_SELECTLUNA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTLUNAAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93B51D05C6CECF6D6ACDEC61BFF2CFBBC3CF43B2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTLUNAAN IS

  vLunaStart  NUMBER;
  vLunaStop   NUMBER;
  vOpt1       BOOLEAN;
  vOpt2       BOOLEAN;
  vAllX       BOOLEAN;
  vCurs       NUMBER;
  vAllY       BOOLEAN;
  vDataIni    VARCHAR2(10);
  vDataFin    VARCHAR2(10);

PROCEDURE SETPARAMS(
  p_LunaStart IN NUMBER   DEFAULT NULL,
  p_LunaStop  IN NUMBER   DEFAULT NULL,
  pOpt1       IN NUMBER   DEFAULT 0,
  pOpt2       IN NUMBER   DEFAULT 0,
  pAllX       IN NUMBER   DEFAULT 1,
  pCodJob1    IN NUMBER   DEFAULT 0,
  pCurs       IN NUMBER   DEFAULT 1,
  pAllY       IN NUMBER   DEFAULT 1,
  pDataIni    IN VARCHAR2 DEFAULT NULL,
  pDataFin    IN VARCHAR2 DEFAULT NULL )
IS
  vDataS     DATE;
  vDataF     DATE;
BEGIN
  vLunaStart := p_LunaStart;
	vLunaStop  := p_LunaStop;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataS,vDataF,vLunaStart,vLunaStop);
  END IF;
  vOpt1  := pOpt1 = 1;
  vOpt2  := pOpt2 = 1;
  vAllX  := pAllX = 1;
  vAllY  := pAllY = 1;
  vCurs  := pCurs;
  vDataIni := pDataIni;
  vDataFin := pDataFin;
END;

 PROCEDURE SETPARAMS_ListeProprii(
  pUSERID  IN NUMBER,
  pListID  IN NUMBER,
  pListVer IN NUMBER,
  pLuna1   IN NUMBER   DEFAULT NULL,
  pLuna2   IN NUMBER   DEFAULT NULL,
  pAn1     IN NUMBER   DEFAULT NULL,
  pAn2     IN NUMBER   DEFAULT NULL,
  pData1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pData2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt1Luna1   IN NUMBER   DEFAULT NULL,
  pInt1Luna2   IN NUMBER   DEFAULT NULL,
  pInt1An1     IN NUMBER   DEFAULT NULL,
  pInt1An2     IN NUMBER   DEFAULT NULL,
  pInt1Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt1Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt2Luna1   IN NUMBER   DEFAULT NULL,
  pInt2Luna2   IN NUMBER   DEFAULT NULL,
  pInt2An1     IN NUMBER   DEFAULT NULL,
  pInt2An2     IN NUMBER   DEFAULT NULL,
  pInt2Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt2Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt3Luna1   IN NUMBER   DEFAULT NULL,
  pInt3Luna2   IN NUMBER   DEFAULT NULL,
  pInt3An1     IN NUMBER   DEFAULT NULL,
  pInt3An2     IN NUMBER   DEFAULT NULL,
  pInt3Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt3Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt4Luna1   IN NUMBER   DEFAULT NULL,
  pInt4Luna2   IN NUMBER   DEFAULT NULL,
  pInt4An1     IN NUMBER   DEFAULT NULL,
  pInt4An2     IN NUMBER   DEFAULT NULL,
  pInt4Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt4Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt5Luna1   IN NUMBER   DEFAULT NULL,
  pInt5Luna2   IN NUMBER   DEFAULT NULL,
  pInt5An1     IN NUMBER   DEFAULT NULL,
  pInt5An2     IN NUMBER   DEFAULT NULL,
  pInt5Data1   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pInt5Data2   IN VARCHAR2 DEFAULT &apos;?&apos;,
  pVal1        IN VARCHAR2 DEFAULT NULL,
  pVal2        IN VARCHAR2 DEFAULT NULL,
  pVal3        IN VARCHAR2 DEFAULT NULL,
  pVal4        IN VARCHAR2 DEFAULT NULL,
  pVal5        IN VARCHAR2 DEFAULT NULL
	)
IS
  xLuna1 NUMBER   ;
  xLuna2 NUMBER   ;
  xAn1   NUMBER   ;
  xAn2   NUMBER   ;
  xData1  Date;
  xData2  Date;
  xInt1Luna1 NUMBER   ;
  xInt1Luna2 NUMBER   ;
  xInt1An1   NUMBER   ;
  xInt1An2   NUMBER   ;
  xInt1Data1  Date;
  xInt1Data2  Date;
  xInt2Luna1 NUMBER   ;
  xInt2Luna2 NUMBER   ;
  xInt2An1   NUMBER   ;
  xInt2An2   NUMBER   ;
  xInt2Data1  Date;
  xInt2Data2  Date;
  xInt3Luna1 NUMBER   ;
  xInt3Luna2 NUMBER   ;
  xInt3An1   NUMBER   ;
  xInt3An2   NUMBER   ;
  xInt3Data1  Date;
  xInt3Data2  Date;
  xInt4Luna1 NUMBER   ;
  xInt4Luna2 NUMBER   ;
  xInt4An1   NUMBER   ;
  xInt4An2   NUMBER   ;
  xInt4Data1  Date;
  xInt4Data2  Date;
  xInt5Luna1 NUMBER   ;
  xInt5Luna2 NUMBER   ;
  xInt5An1   NUMBER   ;
  xInt5An2   NUMBER   ;
  xInt5Data1  Date;
  xInt5Data2  Date;
  Cod number(20);
BEGIN
  xLuna1 := pLuna1;
  xLuna2 := pLuna2;
  xAn1   := pAn1;
  xAn2   := pAn2;

  xInt1Luna1 := pInt1Luna1;
  xInt1Luna2 := pInt1Luna2;
  xInt1An1   := pInt1An1;
  xInt1An2   := pInt1An2;

  xInt2Luna1 := pInt2Luna1;
  xInt2Luna2 := pInt2Luna2;
  xInt2An1   := pInt2An1;
  xInt2An2   := pInt2An2;

  xInt3Luna1 := pInt3Luna1;
  xInt3Luna2 := pInt3Luna2;
  xInt3An1   := pInt3An1;
  xInt3An2   := pInt3An2;


  xInt4Luna1 := pInt4Luna1;
  xInt4Luna2 := pInt4Luna2;
  xInt4An1   := pInt4An1;
  xInt4An2   := pInt4An2;

  xInt5Luna1 := pInt5Luna1;
  xInt5Luna2 := pInt5Luna2;
  xInt5An1   := pInt5An1;
  xInt5An2   := pInt5An2;
  IF (xLUNA1 IS NOT NULL) AND (xAN1 IS NOT NULL) AND (xLUNA2 IS NOT NULL) AND (xAN2 IS NOT NULL) THEN
    IF pData1 &lt;&gt; &apos;?&apos; THEN
      xData1 := To_Date(pData1,&apos;dd.mm.yyyy&apos;);
      if xLuna1 = 0 then xLuna1 := Extract(Month from xData1); end if;
      if xAn1   = 0 then xAn1   := Extract(Year from xData1); end if;
    ELSE
      xData1 := To_Date(&apos;01.&apos;||xLUNA1||&apos;.&apos;||xAN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pData2 &lt;&gt; &apos;?&apos; THEN
      xData2 := To_Date(pData2,&apos;dd.mm.yyyy&apos;);
      if xLuna2 = 0 then xLuna2 := Extract(Month from  xData2); end if;
      if xAn2   = 0 then xAn2   := Extract(Year from xData2); end if;
    ELSE
      xData2 := Last_Day(To_Date(xLUNA2||&apos;.&apos;||xAN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;
  --interval1
  IF (xInt1LUNA1 IS NOT NULL) AND (xInt1AN1 IS NOT NULL) AND (xInt1LUNA2 IS NOT NULL) AND (xInt1AN2 IS NOT NULL) THEN
    IF pInt1Data1 &lt;&gt; &apos;?&apos; THEN
      xInt1Data1 := To_Date(pInt1Data1,&apos;dd.mm.yyyy&apos;);
      if xInt1Luna1 = 0 then xInt1Luna1 := Extract(Month from xInt1Data1); end if;
      if xInt1An1   = 0 then xInt1An1   := Extract(Year from xInt1Data1); end if;
    ELSE
      xInt1Data1 := To_Date(&apos;01.&apos;||xInt1LUNA1||&apos;.&apos;||xInt1AN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pInt1Data2 &lt;&gt; &apos;?&apos; THEN
      xInt1Data2 := To_Date(pInt1Data2,&apos;dd.mm.yyyy&apos;);
      if xInt1Luna2 = 0 then xInt1Luna2 := Extract(Month from  xInt1Data2); end if;
      if xInt1An2   = 0 then xInt1An2   := Extract(Year from xInt1Data2); end if;
    ELSE
      xInt1Data2 := Last_Day(To_Date(xInt1LUNA2||&apos;.&apos;||xInt1AN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;
  --interval2
  IF (xInt2LUNA1 IS NOT NULL) AND (xInt2AN1 IS NOT NULL) AND (xInt2LUNA2 IS NOT NULL) AND (xInt2AN2 IS NOT NULL) THEN
    IF pInt2Data1 &lt;&gt; &apos;?&apos; THEN
      xInt2Data1 := To_Date(pInt2Data1,&apos;dd.mm.yyyy&apos;);
      if xInt2Luna1 = 0 then xInt2Luna1 := Extract(Month from xInt2Data1); end if;
      if xInt2An1   = 0 then xInt2An1   := Extract(Year from xInt2Data1); end if;
    ELSE
      xInt2Data1 := To_Date(&apos;01.&apos;||xInt2LUNA1||&apos;.&apos;||xInt2AN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pInt2Data2 &lt;&gt; &apos;?&apos; THEN
      xInt2Data2 := To_Date(pInt2Data2,&apos;dd.mm.yyyy&apos;);
      if xInt2Luna2 = 0 then xInt2Luna2 := Extract(Month from  xInt2Data2); end if;
      if xInt2An2   = 0 then xInt2An2   := Extract(Year from xInt2Data2); end if;
    ELSE
      xInt2Data2 := Last_Day(To_Date(xInt2LUNA2||&apos;.&apos;||xInt2AN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;
    --interval3
  IF (xInt3LUNA1 IS NOT NULL) AND (xInt3AN1 IS NOT NULL) AND (xInt3LUNA2 IS NOT NULL) AND (xInt3AN2 IS NOT NULL) THEN
    IF pInt3Data1 &lt;&gt; &apos;?&apos; THEN
      xInt3Data1 := To_Date(pInt3Data1,&apos;dd.mm.yyyy&apos;);
      if xInt3Luna1 = 0 then xInt3Luna1 := Extract(Month from xInt3Data1); end if;
      if xInt3An1   = 0 then xInt3An1   := Extract(Year from xInt3Data1); end if;
    ELSE
      xInt3Data1 := To_Date(&apos;01.&apos;||xInt3LUNA1||&apos;.&apos;||xInt3AN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pInt3Data2 &lt;&gt; &apos;?&apos; THEN
      xInt3Data2 := To_Date(pInt3Data2,&apos;dd.mm.yyyy&apos;);
      if xInt3Luna2 = 0 then xInt3Luna2 := Extract(Month from  xInt3Data2); end if;
      if xInt3An2   = 0 then xInt3An2   := Extract(Year from xInt3Data2); end if;
    ELSE
      xInt3Data2 := Last_Day(To_Date(xInt3LUNA2||&apos;.&apos;||xInt3AN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;
    --interval4
  IF (xInt4LUNA1 IS NOT NULL) AND (xInt4AN1 IS NOT NULL) AND (xInt4LUNA2 IS NOT NULL) AND (xInt4AN2 IS NOT NULL) THEN
    IF pInt4Data1 &lt;&gt; &apos;?&apos; THEN
      xInt4Data1 := To_Date(pInt4Data1,&apos;dd.mm.yyyy&apos;);
      if xInt4Luna1 = 0 then xInt4Luna1 := Extract(Month from xInt4Data1); end if;
      if xInt4An1   = 0 then xInt4An1   := Extract(Year from xInt4Data1); end if;
    ELSE
      xInt4Data1 := To_Date(&apos;01.&apos;||xInt4LUNA1||&apos;.&apos;||xInt4AN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pInt4Data2 &lt;&gt; &apos;?&apos; THEN
      xInt4Data2 := To_Date(pInt4Data2,&apos;dd.mm.yyyy&apos;);
      if xInt4Luna2 = 0 then xInt4Luna2 := Extract(Month from  xInt4Data2); end if;
      if xInt4An2   = 0 then xInt4An2   := Extract(Year from xInt4Data2); end if;
    ELSE
      xInt4Data2 := Last_Day(To_Date(xInt4LUNA2||&apos;.&apos;||xInt4AN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;
    --interval5
  IF (xInt5LUNA1 IS NOT NULL) AND (xInt5AN1 IS NOT NULL) AND (xInt5LUNA2 IS NOT NULL) AND (xInt5AN2 IS NOT NULL) THEN
    IF pInt5Data1 &lt;&gt; &apos;?&apos; THEN
      xInt5Data1 := To_Date(pInt5Data1,&apos;dd.mm.yyyy&apos;);
      if xInt5Luna1 = 0 then xInt5Luna1 := Extract(Month from xInt5Data1); end if;
      if xInt5An1   = 0 then xInt5An1   := Extract(Year from xInt5Data1); end if;
    ELSE
      xInt5Data1 := To_Date(&apos;01.&apos;||xInt5LUNA1||&apos;.&apos;||xInt5AN1,&apos;dd.mm.yyyy&apos;);
    END IF;
    IF pInt5Data2 &lt;&gt; &apos;?&apos; THEN
      xInt5Data2 := To_Date(pInt5Data2,&apos;dd.mm.yyyy&apos;);
      if xInt5Luna2 = 0 then xInt5Luna2 := Extract(Month from  xInt5Data2); end if;
      if xInt5An2   = 0 then xInt5An2   := Extract(Year from xInt5Data2); end if;
    ELSE
      xInt5Data2 := Last_Day(To_Date(xInt5LUNA2||&apos;.&apos;||xInt5AN2,&apos;mm.yyyy&apos;));
    END IF;
  END IF;

  BEGIN
  	Select Nvl(codparamliste,0) into Cod from paramliste where userid = puserid and listid = plistid and listver = plistver;
    EXCEPTIOn WHEN OTHERS THEN COD := 0;
  END;


  if Cod = 0 then
		Cod := SEQ_paramliste.NextVal;
		Insert into paramliste (
			codparamliste,
			userid,
			listid,
			listver,
			data1,
			data2,
			an1,
			luna1,
			an2,
			luna2,
      int1data1,
      int1data2,
      int1an1,
      int1luna1,
      int1an2,
      int1luna2,
      int2data1,
      int2data2,
      int2an1,
      int2luna1,
      int2an2,
      int2luna2,
      int3data1,
      int3data2,
      int3an1,
      int3luna1,
      int3an2,
      int3luna2,
      int4data1,
      int4data2,
      int4an1,
      int4luna1,
      int4an2,
      int4luna2,
      int5data1,
      int5data2,
      int5an1,
      int5luna1,
      int5an2,
      int5luna2,
      val1,
      val2,
      val3,
      val4,
      val5 )
		values (
			cod,
			puserid,
			plistid,
			plistver,
			xdata1,
			xdata2,
			xan1,
			xluna1,
			xan2,
			xluna2,
      xInt1data1,
      xInt1data2,
      xInt1an1,
      xInt1luna1,
      xInt1an2,
      xInt1luna2,
      xInt2data1,
      xInt2data2,
      xInt2an1,
      xInt2luna1,
      xInt2an2,
      xInt2luna2,
      xInt3data1,
      xInt3data2,
      xInt3an1,
      xInt3luna1,
      xInt3an2,
      xInt3luna2,
      xInt4data1,
      xInt4data2,
      xInt4an1,
      xInt4luna1,
      xInt4an2,
      xInt4luna2,
      xInt5data1,
      xInt5data2,
      xInt5an1,
      xInt5luna1,
      xInt5an2,
      xInt5luna2,
      pVal1,
      pVal2,
      pVal3,
      pVal4,
      pVal5
 );
	else
	  update paramliste set
			data1  = xdata1 ,
      data2  = xdata2 ,
      an1    = xan1   ,
      luna1  = xluna1 ,
      an2    = xan2   ,
      luna2  = xluna2,
      int1data1  = xInt1data1 ,
      int1data2  = xInt1data2 ,
      int1an1    = xInt1an1   ,
      int1luna1  = xInt1luna1 ,
      int1an2    = xInt1an2   ,
      int1luna2  = xInt1luna2,
      int2data1  = xInt2data1 ,
      int2data2  = xInt2data2 ,
      int2an1    = xInt2an1   ,
      int2luna1  = xInt2luna1 ,
      int2an2    = xInt2an2   ,
      int2luna2  = xInt2luna2,
      int3data1  = xInt3data1 ,
      int3data2  = xInt3data2 ,
      int3an1    = xInt3an1   ,
      int3luna1  = xInt3luna1 ,
      int3an2    = xInt3an2   ,
      int3luna2  = xInt3luna2,
      int4data1  = xInt4data1 ,
      int4data2  = xInt4data2 ,
      int4an1    = xInt4an1   ,
      int4luna1  = xInt4luna1 ,
      int4an2    = xInt4an2   ,
      int4luna2  = xInt4luna2,
      int5data1  = xInt5data1 ,
      int5data2  = xInt5data2 ,
      int5an1    = xInt5an1   ,
      int5luna1  = xInt5luna1 ,
      int5an2    = xInt5an2   ,
      int5luna2  = xInt5luna2,
      val1         = pVal1,
      val2         = pVal2,
      val3         = pVal3,
      val4         = pVal4,
      val5         = pVal5
		where codparamliste = cod;
	end if;
	COMMIT;
END;

FUNCTION DataIni RETURN VARCHAR2 IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN VARCHAR2 IS
BEGIN
  return vDataFin;
END;

FUNCTION LunaStart RETURN NUMBER IS
BEGIN
  return vLunaStart;
END;

FUNCTION LunaStop RETURN NUMBER IS
BEGIN
  return vLunaStop;
END;

FUNCTION optiunea1 RETURN BOOLEAN IS
BEGIN
  RETURN vOpt1;
END;

FUNCTION optiunea2 RETURN BOOLEAN IS
BEGIN
  RETURN vOpt2;
END;

FUNCTION AllX RETURN BOOLEAN IS
BEGIN
  RETURN vAllX;
END;

FUNCTION AllY RETURN BOOLEAN IS
BEGIN
  RETURN vAllY;
END;

FUNCTION Curs RETURN NUMBER IS
BEGIN
  RETURN Coalesce(vCurs,1);
END;

END PKG_LIST_SELECTLUNAAN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6FE818E6E7C7025D8863A0079366AE5488442B3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selectper IS

  vDataIni     DATE;
  vDataFin     DATE;
  vToateArt    BOOLEAN;
  vToateGest   BOOLEAN;
  vDupaData    BOOLEAN;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  bAduSerii    BOOLEAN;
  vTipPer      INTEGER;
  bInfoNP      BOOLEAN;
  
  PROCEDURE SETPARAMS (
    pDataIni     IN VARCHAR2 DEFAULT NULL,
    pDataFin     IN VARCHAR2 DEFAULT NULL,
    pToateArt    IN NUMBER   DEFAULT 1,
    pToateGest   IN NUMBER   DEFAULT 1,
    pDupaData    IN NUMBER   DEFAULT 1,
    pLunaAnIni   IN INTEGER  DEFAULT 0,
    pLunaAnFin   IN INTEGER  DEFAULT 0,
    pAduSerii    IN NUMBER   DEFAULT 1,
    pCodJob1     IN NUMBER   DEFAULT 0,
    pTipPer      IN NUMBER   DEFAULT 0,
    pInfoNP      IN NUMBER   DEFAULT 0
  ) IS
  aAn number(4);
  aLuna number(2);
  BEGIN
    vDataIni    := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
    vDataFin    := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
    vToateArt   := pToateArt = 1;
    vToateGest  := pToateGest = 1;
    vDupaData   := pDupaData = 1;
    vLunaAnIni  := NVL(pLunaAnIni,0);
    vLunaAnFin  := NVL(pLunaAnFin,0);
    bAduSerii   := pAduSerii = 1;
    bInfoNP     := pInfoNP = 1;
    IF NVL(pCodJob1,0) &gt; 0 THEN
      PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
    END IF;
    vTipPer     := pTipPer;
    if not vDupaData then
      if trunc(vLunaAnIni/12) = vLunaAnIni/12 then
        aAn := trunc(vLunaAnIni/12) - 1;
        aLuna := 12;
      else
        aAn := trunc(vLunaAnIni/12);
        aLuna := vLunaAnIni - trunc(vLunaAnIni/12)*12;
      end if;
      vDataIni := to_date(&apos;01.&apos;||LPAD(to_char(aLuna),2,&apos;0&apos;)||&apos;.&apos;||to_char(aAn));
      if trunc(vLunaAnFin/12) = vLunaAnFin/12 then
        aAn := trunc(vLunaAnFin/12) - 1;
        aLuna := 12;
      else
        aAn := trunc(vLunaAnFin/12);
        aLuna := vLunaAnFin - trunc(vLunaAnFin/12)*12;
      end if;
      vDataFin := last_day(to_date(&apos;01.&apos;||LPAD(to_char(aLuna),2,&apos;0&apos;)||&apos;.&apos;||to_char(aAn)));
    end if;
  END;

  FUNCTION AduSerii RETURN BOOLEAN IS
  BEGIN
   RETURN bAduSerii;
  END;

  FUNCTION InfoNP RETURN BOOLEAN IS
  BEGIN
   RETURN bInfoNP;
  END;

  FUNCTION DataIni RETURN DATE IS
  BEGIN
    return vDataIni;
  END;

  FUNCTION DataFin RETURN DATE IS
  BEGIN
    return vDataFin;
  END;

  FUNCTION ToateArt  RETURN BOOLEAN IS
  BEGIN
    return vToateArt;
  END;

  FUNCTION ToateGest RETURN BOOLEAN IS
  BEGIN
    return vToateGest;
  END;

  FUNCTION DupaData RETURN BOOLEAN IS
  BEGIN
    return vDupaData;
  END;

  FUNCTION LunaAnIni RETURN INTEGER IS
  BEGIN
    return vLunaAnIni;
  END;

  FUNCTION LunaAnFin RETURN INTEGER IS
  BEGIN
    return vLunaAnFin;
  END;

  FUNCTION TipPer RETURN INTEGER IS
  BEGIN
    return vTipPer;
  END;

end PKG_LIST_SELECTPER;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTPERIOADA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A73D858A35ADBCCEC8EEA488ED3C57474ABAFB57</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selectperioada IS

  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vAnLunaIni   INTEGER;
  vAnLunaFin   INTEGER;
  vOpt1       BOOLEAN;
  vOpt2       BOOLEAN;
  vAllX       BOOLEAN;
  vDataOraIni DATE;
  vDataOraFin DATE;

PROCEDURE SETPARAMS(
    pDupaData   IN NUMBER   DEFAULT 1,
    pDataIni    IN VARCHAR2 DEFAULT NULL,
    pDataFin    IN VARCHAR2 DEFAULT NULL,
    pAnLunaIni  IN NUMBER   DEFAULT NULL,
    pAnLunaFin  IN NUMBER   DEFAULT NULL,
    pOpt1       IN NUMBER   DEFAULT 0,
    pOpt2       IN NUMBER   DEFAULT 0,
    pAllX       IN NUMBER   DEFAULT 1,
    pCodJob1    IN NUMBER   DEFAULT 0,
    pDataOraIni IN VARCHAR2 DEFAULT NULL,
    pDataOraFin IN VARCHAR2 DEFAULT NULL)
IS
  vDataS     DATE;
  vDataF     DATE;
BEGIN
  vDupaData   := pDupaData = 1;
  vDataIni    := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin    := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vAnLunaIni  := pAnLunaIni;
	vAnLunaFin  := pAnLunaFin;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni,vDataFin,vAnLunaIni,vAnLunaFin);
  END IF;
  vOpt1  := pOpt1 = 1;
  vOpt2  := pOpt2 = 1;
  vAllX  := pAllX = 1;
  vDataOraIni := to_date(pDataOraIni,&apos;dd.mm.yyyy hh24:mi:ss&apos;);
  vDataOraFin := to_date(pDataOraFin,&apos;dd.mm.yyyy hh24:mi:ss&apos;);
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataOraIni RETURN DATE IS
BEGIN
  return vDataOraIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION DataOraFin RETURN DATE IS
BEGIN
  return vDataOraFin;
END;

FUNCTION AnLunaIni RETURN NUMBER IS
BEGIN
  return vAnLunaIni;
END;

FUNCTION AnLunaFin RETURN NUMBER IS
BEGIN
  return vAnLunaFin;
END;

FUNCTION optiunea1 RETURN BOOLEAN IS
BEGIN
  RETURN vOpt1;
END;

FUNCTION optiunea2 RETURN BOOLEAN IS
BEGIN
  RETURN vOpt2;
END;

FUNCTION AllX RETURN BOOLEAN IS
BEGIN
  RETURN vAllX;
END;

END pkg_list_selectperioada; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTSCAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94930830A706B861BE8D6AAD6319BB89D2D59FF9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTSCAD IS

  vToateGest    BOOLEAN ;
  vToateIoart   BOOLEAN ;
  vFaraPret     BOOLEAN ;
  vDataIni      VARCHAR2(10);
  vDataScad     VARCHAR2(10);
  vLunaIni      INTEGER;
  vLunaFin      INTEGER;
  vCentralizat  INTEGER;
  vExtra1       BOOLEAN;
  vExtra2       BOOLEAN;
  vExtra3       BOOLEAN;
  vTipNecesar   INTEGER;
  vPerVanz      BOOLEAN;
  vDataVIni     VARCHAR2(10);
  vDataVScad    VARCHAR2(10);
  vFaraRezInv   BOOLEAN;
  vSetimana     INTEGER;
  vMod          INTEGER;

  PROCEDURE SETPARAMS(
    pToateGest    IN INTEGER  DEFAULT 1,                             
    pToateIoart   IN INTEGER  DEFAULT 1,                             
    pFaraPret     IN INTEGER  DEFAULT 0,                             
    pDataIni      IN VARCHAR2 DEFAULT NULL,                          
    pDataScad     IN VARCHAR2 DEFAULT NULL,                          
    pLunaIni      IN NUMBER   DEFAULT NULL,                          
    pLunaFin      IN NUMBER   DEFAULT NULL,                          
    pCentralizat  IN NUMBER   DEFAULT NULL,                          
    pExtra1       IN INTEGER  DEFAULT 0,                             
    pExtra2       IN INTEGER  DEFAULT 0,                             
    pTipNecesar   IN NUMBER   DEFAULT 0,                             
    pPerVanz      IN INTEGER  DEFAULT 0,                             
    pDataVIni     IN VARCHAR2 DEFAULT NULL,                          
    pDataVScad    IN VARCHAR2 DEFAULT NULL,                          
    pFaraRezInv   IN INTEGER  DEFAULT 0,                             
    pCodJob1      IN NUMBER   DEFAULT 0,                             
    pSetimana     IN NUMBER   DEFAULT 0,                             
    pMod          IN NUMBER   DEFAULT 0,                             
    pExtra3       IN INTEGER  DEFAULT 0                              
  ) IS
    xALS INTEGER;
    xALF INTEGER;
  BEGIN
    -- integer to boolean
    vToateGest    := Coalesce(pToateGest,  1) = 1;
    vToateIoart   := Coalesce(pToateIoart, 1) = 1;
    vFaraPret     := Coalesce(pFaraPret,   0) = 1;
    vExtra1       := Coalesce(pExtra1,     0) = 1;
    vExtra2       := Coalesce(pExtra2,     0) = 1;
    vExtra3       := Coalesce(pExtra3,     0) = 1;
    vPerVanz      := Coalesce(pFaraRezInv, 0) = 1;
    vFaraRezInv   := Coalesce(pFaraRezInv, 0) = 1;

    vDataIni      := pDataIni;
    vDataScad     := pDataScad;
    vLunaIni      := pLunaIni;
    vLunaFin      := pLunaFin;
    vCentralizat  := pCentralizat;
    vTipNecesar   := Coalesce(pTipNecesar,0);
    vDataVIni     := pDataVIni;
    vDataVScad    := pDataVScad;
    IF NVL(pCodJob1,0) &gt; 0 THEN
      PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataIni, vDataScad, xALS,xALF);
      PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,vDataVIni,vDataVScad,xALS,xALF);
    END IF;
    vSetimana     := NVL(pSetimana,0);
    vMod          := pMod;
  END;

  FUNCTION ToateGest RETURN BOOLEAN IS
  BEGIN
    RETURN vToateGest;
  END;

  FUNCTION ToateGestN RETURN NUMBER IS
  BEGIN
    IF vToateGest then
      RETURN 1;
    else
      RETURN 0;
    end if;  
  END;

  FUNCTION ToateIoart RETURN BOOLEAN IS
  BEGIN
    RETURN vToateIoart;
  END;

  FUNCTION FaraPret RETURN BOOLEAN IS
  BEGIN
    RETURN vFaraPret;
  END;

  FUNCTION DataIni RETURN DATE IS
  BEGIN
    RETURN to_date(vDataIni,&apos;DD.MM.YYYY&apos;);
  END;

  FUNCTION DataScad RETURN DATE IS
  BEGIN
    RETURN to_date(vDataScad,&apos;DD.MM.YYYY&apos;);
  END;

  FUNCTION LunaINI RETURN INTEGER IS
  BEGIN
    RETURN vLunaINI;
  END;

  FUNCTION DataVIni RETURN VARCHAR2 IS
  BEGIN
    RETURN vDataVINI;
  END;

  FUNCTION DataVFIN RETURN VARCHAR2 IS
  BEGIN
    RETURN vdataVScad;
  END;

  FUNCTION PerVanz RETURN BOOLEAN IS
  BEGIN
    RETURN vPerVanz;
  END;

  FUNCTION TipNecesar RETURN INTEGER IS
  BEGIN
    RETURN vTipNecesar;
  END;

  FUNCTION LunaFIN RETURN INTEGER IS
  BEGIN
    RETURN vLunaFIN;
  END;

  FUNCTION Centralizat RETURN INTEGER IS
  BEGIN
    RETURN vCentralizat;
  END;

  FUNCTION Extra1 RETURN BOOLEAN IS
  BEGIN
    RETURN vExtra1;
  END;

  FUNCTION Extra2 RETURN BOOLEAN IS
  BEGIN
    RETURN vExtra2;
  END;

  FUNCTION Extra3 RETURN BOOLEAN IS
  BEGIN
    RETURN vExtra3;
  END;

  FUNCTION FaraRezInventar RETURN BOOLEAN IS
  BEGIN
    RETURN vFaraRezInv;
  END;

  FUNCTION Setimana RETURN INTEGER IS
  BEGIN
    RETURN vSetimana;
  END;

  FUNCTION ModSelectie RETURN INTEGER IS
  BEGIN
    RETURN vMod;
  END;

END PKG_LIST_SELECTSCAD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELECTSCADENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B928A40C64776CDDA1AAAB644CD2FA4C1AD1B1AC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELECTSCADENTAR IS

  g_data_ref       DATE ;
  g_CumulatFirma   BOOLEAN;
  g_TranzInCurs    BOOLEAN;
  g_TCursFirma     BOOLEAN;
  g_DetTranzInCurs BOOLEAN;
  g_Lei            BOOLEAN;
  g_AdaosDoc       BOOLEAN;
  g_DiscTermen     BOOLEAN;
  g_ToateClasele   BOOLEAN;
  g_TotiPart       BOOLEAN;
  g_tipIntarziere  NUMBER;   -- 0 =&gt;&gt; intarziere fata de termennul de plata 1 =&gt;&gt; intarziere fata de dataDoc
  g_TipCalculRest  NUMBER;   -- 0 =&gt;&gt; la sfarsitul lunii 1 =&gt;&gt; la o data specificata din luna curenta
  g_TipPerioada    NUMBER;   -- 0 =&gt;&gt; doar luna curenta 1  =&gt;&gt; incepand cu ultima luna inchisa anterioara lunii curente
  g_data_rest      DATE ;
  g_ValSapt        BOOLEAN;
  g_TMPOk          BOOLEAN;
  g_CodJob1        NUMBER;

PROCEDURE setParams(
  p_DataRef        IN VARCHAR2,
  p_TranzInCurs    IN NUMBER   DEFAULT 0,
  p_TCursFirma     IN NUMBER   DEFAULT 0,
  p_Lei            IN NUMBER   DEFAULT 0,
  p_AdaosDoc       IN NUMBER   DEFAULT 0,
  p_DiscTermen     IN NUMBER   DEFAULT 0,
  p_ToateClasele   IN NUMBER   DEFAULT 1,
  p_TotiPart       IN NUMBER   DEFAULT 1,
  p_TipIntarziere  IN INTEGER  DEFAULT 0,
  p_TipCalculRest  IN INTEGER  DEFAULT 0,
  p_DataRest       IN VARCHAR2 DEFAULT NULL,
  p_TipPerioada    IN INTEGER  DEFAULT 0,
  p_ValSapt        IN NUMBER   DEFAULT 0,
  v_ListId         IN NUMBER   DEFAULT 0,
  v_CodJob1        IN NUMBER   DEFAULT 0,
  p_CumulatFirma   IN NUMBER   DEFAULT 0,
  p_DetTranzInCurs IN NUMBER   DEFAULT 0)
IS
BEGIN
  g_CodJob1 := v_CodJob1;
  if UPPER(p_DataRef) = &apos;SYSDATE&apos;
	then g_data_ref    := SysDate;
	else g_data_ref    := To_Date(p_DataRef ,&apos;dd.mm.yyyy&apos;);
	end if;

  if UPPER(p_DataRest) = &apos;SYSDATE&apos;
	then g_data_rest   := SysDate;
	else g_data_rest   := To_Date(p_DataRest,&apos;dd.mm.yyyy&apos;);
	end if;


  IF (V_CODJOB1 &gt; 0) and (pkg_categconst.GetValConstanta(&apos;EDITVARJOB&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) &lt;&gt; 1) THEN
    PKG_ORA_LISTS.SET_DATA_DINAMIC(v_CodJob1, g_data_ref);
    g_data_rest    := g_data_ref;
  END IF;
  g_CumulatFirma   := Coalesce(p_CumulatFirma,   0) = 1;
  g_TranzInCurs    := Coalesce(p_TranzInCurs,    0) = 1;
  g_TCursFirma     := Coalesce(p_TCursFirma,     0) = 1;
  g_DetTranzInCurs := Coalesce(p_DetTranzInCurs, 0) = 1;
  g_Lei            := Coalesce(p_Lei,            0) = 1;
  g_AdaosDoc       := Coalesce(p_AdaosDoc,       0) = 1;
  g_DiscTermen     := Coalesce(p_DiscTermen,     0) = 1;
  g_ToateClasele   := Coalesce(p_ToateClasele,   1) = 1;
  g_TotiPart       := Coalesce(p_TotiPart,       0) = 1;
  g_ValSapt        := Coalesce(p_ValSapt,        0) = 1;

  g_TipIntarziere  := Coalesce(p_TipIntarziere,0);
  g_TipCalculRest  := Coalesce(p_TipCalculRest,0);
  g_TipPerioada    := Coalesce(p_TipPerioada,0);
  g_TMPOk          := TRUE;

  CASE
    WHEN Coalesce(v_ListId,0) IN (5,250) THEN PKG_LIST_BASE_SCADENTARCL.UmpleTmp(v_ListId);
    WHEN Coalesce(v_ListId,0) IN (6,251) THEN PKG_LIST_BASE_SCADENTARF.UmpleTmp(v_ListId);
    ELSE g_TMPOk := FALSE;
  END CASE;

  -- stef -- versiunile anterioare nu aveau v_ListId deci am probleme la popularea tmpurilor de aici, deci nu am coloane dinamice in acest ca (sa nu crape joburile)
  IF NOT g_TMPOk
  THEN g_ValSapt := False;
  END IF;
END;

FUNCTION DataRef        RETURN DATE IS
BEGIN
  RETURN g_data_ref;
END;

FUNCTION CuTranzInCurs  RETURN BOOLEAN IS
BEGIN
  RETURN g_TranzInCurs;
END;

FUNCTION TranzCursFirma RETURN BOOLEAN IS
BEGIN
  RETURN g_TCursFirma;
END;

FUNCTION DetTranzInCurs RETURN BOOLEAN IS
BEGIN
  RETURN g_DetTranzInCurs;
END;

FUNCTION InLei          RETURN BOOLEAN IS
BEGIN
  RETURN g_Lei;
END;

FUNCTION CalcAdaosDoc   RETURN BOOLEAN IS
BEGIN
  RETURN g_AdaosDoc;
END;

FUNCTION CalcDiscTermen RETURN BOOLEAN IS
BEGIN
  RETURN g_DiscTermen;
END;

FUNCTION ToateClasele   RETURN BOOLEAN IS
BEGIN
  RETURN g_ToateClasele;
END;

FUNCTION ToateClaseleNumber RETURN NUMBER IS
BEGIN
  if g_ToateClasele then
    return 1;
  else
    return 0;
  end if;
END;

FUNCTION TotiPart       RETURN BOOLEAN IS
BEGIN
  RETURN g_TotiPart;
END;

FUNCTION TotiPartNumber RETURN NUMBER IS
BEGIN
  if g_TotiPart then
    return 1;
  else
    return 0;
  end if;
END;

FUNCTION TipIntarziere  RETURN INTEGER IS
BEGIN
  RETURN g_TipIntarziere;
END;

FUNCTION CodJob1 RETURN NUMBER IS
BEGIN
  RETURN g_CodJob1;
END;

FUNCTION TipCalculRest  RETURN INTEGER IS
BEGIN
  RETURN g_TipCalculRest;
END;

FUNCTION DataRest       RETURN DATE IS
BEGIN
  RETURN g_data_rest;
END;

FUNCTION TipPerioada  RETURN INTEGER IS
BEGIN
  RETURN g_TipPerioada;
END;

FUNCTION ValSapt RETURN BOOLEAN IS
BEGIN
  RETURN g_ValSapt;
END;

FUNCTION TMPOk RETURN BOOLEAN IS
BEGIN
  RETURN g_TMPOk;
END;

FUNCTION COND_SUBUNIT(
  pTabla   IN VARCHAR2 DEFAULT NULL,
  pColoana IN VARCHAR2 DEFAULT &apos;SUBUNITATEA&apos;
) RETURN VARCHAR2 IS
  vSubunit NUMBER(20);
BEGIN
  IF g_CumulatFirma THEN
    vSubunit := 0;
  END IF;
  RETURN PKG_LIST_BASE_UTILS.COND_SUBUNIT(pTABLA =&gt; pTabla, pCOLOANA =&gt; pColoana, pSUBUNIT =&gt; vSubunit );
END;

FUNCTION  FiltruData (sListaCamp IN VARCHAR2) RETURN VARCHAR2 IS
  sDataRest VARCHAR2(10) := To_Char(g_data_rest,&apos;dd.mm.yyyy&apos;);
BEGIN
  IF PKG_LIST_SELECTSCADENTAR.TipCalculRest = 0
  THEN RETURN &apos;&apos;;
  ELSE RETURN &apos; AND COALESCE(&apos;||sListaCamp||&apos;,To_Date(&apos;&apos;&apos;||sDataRest||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)) &lt;= To_Date(&apos;&apos;&apos;||sDataRest||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
  END IF;
END;

END PKG_LIST_SELECTSCADENTAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELFISAMAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E523147FACD265AAB8F2AD71A4008BD577212583</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELFISAMAG IS

  p_dataIni    VARCHAR2(15);
  p_dataFin    VARCHAR2(15);
	p_dataStoc   VARCHAR2(15);
  p_flgGest    BOOLEAN;
  p_flgTipCont BOOLEAN;
	p_flgArt     BOOLEAN;
  p_StoclaZi   boolean;
  P_areSerii   boolean;
  p_CalcPMP    BOOLEAN;
  p_Stoc0      BOOLEAN;
  p_TipStocIni NUMBER(1);
  p_DataRef    VARCHAR2(15);
  p_RezUM1     BOOLEAN;
  p_ListID     NUMBER(10);
  p_ExclNeconform BOOLEAN;
  p_Nedes      BOOLEAN;

PROCEDURE setAllParams(
  v_dataini    IN VARCHAR2,
  v_dataFin    IN VARCHAR2,
  v_DataStoc   IN VARCHAR2,
  v_flgGest    IN NUMBER,
  v_flgTipCont IN NUMBER,
  v_flgArt     IN NUMBER,
  v_StocLaZi   IN NUMBER   DEFAULT 0,
  v_areSerii   IN NUMBER   DEFAULT 0,
  v_CalcPMP    IN NUMBER   DEFAULT 0,
  v_DataRef    IN VARCHAR2 DEFAULT NULL,
  v_Stoc0      IN NUMBER   DEFAULT 0,
  v_CodJob1    IN NUMBER   DEFAULT 0,
  v_RezUM1     IN NUMBER   DEFAULT 0,
  v_ListID     IN NUMBER   DEFAULT 0,
  v_ExclNeconform IN NUMBER DEFAULT 0,
  v_Nedes      IN NUMBER   DEFAULT 0
) IS
  xLunaAnIni integer;
  xLunaAnFin integer;
BEGIN
  p_dataIni   := v_dataini;
  p_dataFin   := v_dataFin;
  p_dataStoc  := v_DataStoc;
  p_DataRef   := v_DataRef;

  if Coalesce(v_CodJob1,0) &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,p_dataIni,p_dataFin, xLunaAnIni,xLunaAnFin);
    p_DataStoc  := p_DataFin;
    p_DataRef   := p_DataFin;
  end if;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(TO_DATE(p_dataIni,&apos;DD.MM.YYYY&apos;),TO_DATE(p_dataFin,&apos;DD.MM.YYYY&apos;));

  p_flgGest    := Coalesce(v_flgGest,    0) = 1;
  p_flgTipCont := Coalesce(v_flgTipCont, 0) = 1;
	p_flgArt     := Coalesce(v_flgArt,     0) = 1;
  p_stocLaZi   := Coalesce(v_StocLaZi,   0) = 0;
  p_areSerii   := Coalesce(v_areSerii,   0) = 1;
  p_CalcPMP    := Coalesce(v_CalcPMP,    0) = 1;
  p_Stoc0      := Coalesce(v_Stoc0,      0) = 1;
  p_TipStocIni := Coalesce(v_Stoc0,      0);
  p_RezUM1     := Coalesce(v_RezUM1,     0) = 1;
  p_ListID     := Coalesce(v_ListID,     0);
  p_ExclNeconform := Coalesce(v_ExclNeconform, 0) = 1;
  p_Nedes      := Coalesce(v_Nedes,      0) = 1;
END;

FUNCTION getDataRef return DATE is
begin
 RETURN to_date(p_DataRef,&apos;DD.MM.YYYY&apos;);
end;

FUNCTION calculeaza_pmp return boolean is
begin
  return p_calcPMP;
end;

FUNCTION getDataStoc RETURN DATE IS
BEGIN
   RETURN to_date(p_dataStoc,&apos;DD.MM.YYYY&apos;);
END;

FUNCTION getDataIni RETURN DATE IS
BEGIN
  RETURN to_date(p_dataIni,&apos;DD.MM.YYYY&apos;);
END;

FUNCTION isToateArt RETURN NUMBER IS
iResult NUMBER(1) := 0;
BEGIN
 IF p_flgArt THEN
  iResult := 1 ;
 END IF;
 RETURN iResult;
END;

FUNCTION getNumToateGest RETURN NUMBER IS
iResult NUMBER(1) := 0;
BEGIN
  IF p_flgGest THEN
   iResult := 1;
  END IF;
  RETURN iResult;
END;

FUNCTION getNumToateCont RETURN NUMBER IS
iResult NUMBER(1) := 0;
BEGIN
  IF p_flgTipCont THEN
   iResult := 1;
	END IF;
	RETURN iResult;
END;

FUNCTION StocLaZi  return boolean is
BEGIN
  RETURN p_StoclaZi;
END;

FUNCTION ListID return number is
BEGIN
  RETURN p_ListID;
END;

FUNCTION areSerii  return boolean is
BEGIN
  RETURN p_areSerii;
END;

FUNCTION getDataFin RETURN DATE IS
BEGIN
	RETURN to_date(p_dataFin,&apos;DD.MM.YYYY&apos;);
END;

FUNCTION isAllGest RETURN BOOLEAN IS
BEGIN
	RETURN p_flgGest;
END;

FUNCTION isAllTipCont RETURN BOOLEAN IS
BEGIN
	RETURN p_flgTipCont;
END;

FUNCTION exclNeconform RETURN BOOLEAN IS
BEGIN
	RETURN p_ExclNeconform;
END;

FUNCTION GetInterval RETURN VARCHAR2 IS
BEGIN
  RETURN &apos; to_date(&apos;&apos;&apos;||p_dataIni||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND to_date(&apos;&apos;&apos;||p_dataFin||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) &apos;;
END;

FUNCTION inclArtStoc0 RETURN BOOLEAN IS
BEGIN
  RETURN p_Stoc0;
END;

FUNCTION TipStocIni      RETURN NUMBER IS
BEGIN
  RETURN p_TipStocIni;
END;

FUNCTION inclNedes RETURN BOOLEAN IS
BEGIN
  RETURN p_Nedes;
END;

FUNCTION RezUM1 RETURN BOOLEAN IS
BEGIN
  RETURN p_RezUM1;
END;

end PKG_LIST_SELFISAMAG;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELFISAPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB4CFEE21B4278E24C3088A7627B8F0AC16EBAC7</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELFISAPERS IS

  vAllMon     BOOLEAN;
  vAllTipC    BOOLEAN;
  vAnLunaIni  NUMBER;
  vAnLunaFin  NUMBER;
  vCodPers    NPERS.CODPERS%TYPE;
  vLei        NUMBER;
  vSubunit    BOOLEAN;

PROCEDURE SETPARAMS(
  p_AllMon    IN NUMBER DEFAULT 1,
  p_AllTipC   IN NUMBER DEFAULT 1,
  p_AnLunaIni IN NUMBER DEFAULT NULL,
  p_AnLunaFin IN NUMBER DEFAULT NULL,
  p_CodPers   IN NUMBER DEFAULT 0,
  p_Lei       IN NUMBER DEFAULT 0,
  p_Subunit   IN NUMBER DEFAULT 1 ,
  V_CODJOB1   IN NUMBER DEFAULT 0
) IS
  dDataS DATE;
  dDataF DATE;
BEGIN
  vAllMon    := Coalesce(p_AllMon, 1)  = 1;
  vAllTipC   := Coalesce(p_AllTipC, 1) = 1;
	vAnLunaIni := p_AnLunaIni;
	vAnLunaFin := p_AnLunaFin;
	vCodPers   := Coalesce(p_CodPers,0);
  vLei       := Coalesce(p_Lei,0);
  vSubunit   := Coalesce(p_Subunit, 0) = 1;

  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,dDataS,dDataF,vAnLunaIni,vAnLunaFin);
  END IF;
END;

FUNCTION isAllMon RETURN BOOLEAN IS
BEGIN
  RETURN vAllMon;
END;

FUNCTION isSubunit RETURN BOOLEAN IS
BEGIN
  RETURN vSubunit;
END;

FUNCTION isAllTipC RETURN BOOLEAN IS
BEGIN
  RETURN vAllTipC;
END;

FUNCTION AnLunaIni RETURN NUMBER IS
BEGIN
  return vAnLunaIni;
END;

FUNCTION AnLunaFin   RETURN NUMBER IS
BEGIN
  return vAnLunaFin;
END;

FUNCTION isAllTipCN RETURN NUMBER IS
BEGIN
  if vAllTipC then
    return 1;
  else
    return 0;
  end if;
END;

FUNCTION Lei RETURN NUMBER IS
BEGIN
  return vLei;
END;

FUNCTION CodPers   RETURN NPERS.CODPERS%TYPE IS
BEGIN
  return vCodPers;
END;

FUNCTION gettipCont RETURN crs IS
  cResult crs;
BEGIN
  OPEN cResult FOR
    WITH crs_io AS (
      SELECT DISTINCT CODIOPERS,
              CASE x.icont
                WHEN  2 THEN CONTAVANSDECONT
                WHEN  3 THEN CONTIMPUTATII
                WHEN  4 THEN CONTGARANTII
                WHEN  5 THEN CONTALTERETINERI
                WHEN  6 THEN CONTAVANS
                WHEN  7 THEN CONTLIKI
                WHEN  8 THEN CONTNERIDICATE
                WHEN  9 THEN CONTBOALA
                WHEN 10 THEN CONTPARTSAL
                WHEN 11 THEN CONTNATURA
                WHEN 12 THEN CONTECHIPAMENT
                WHEN 13 THEN CONTIMPOZIT
              END codcont,
              CASE x.icont WHEN  2 THEN 1 ELSE 0 END AVANSDECONT
      FROM   iopers1 io1
              CROSS JOIN (SELECT level+1 icont FROM DUAL connect by level &lt;= 12) x
    )
    SELECT distinct nc.codcont, nc.simbol||&apos; - &apos;||nc.den_cont denumire, crs_io.AVANSDECONT
    FROM crs_io INNER JOIN ncont nc ON nc.codcont = crs_io.codcont
    WHERE crs_io.codCont &lt;&gt; 0;
  RETURN cResult;
END;

end PKG_LIST_SELFISAPERS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELINTIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0625E1995FA4D1E0230897A6FBC2F1C9F088A566</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELINTIES IS
  vToateArt    BOOLEAN ;
  vDupaData    BOOLEAN ;
  vPerioada    VARCHAR2(200);
  vLista       INTEGER;
  vUM          INTEGER;
  vDataS       DATE;
  vDataF       DATE;
  vExtra1      BOOLEAN;
  vExtra2      BOOLEAN;
  vExtra3      BOOLEAN;
  vExtra4      BOOLEAN;
  vAtrib1      INTEGER;
  vSeriiFaraCant BOOLEAN;

PROCEDURE setParams (
  bObj      IN INTEGER,
  pDupaData IN NUMBER  DEFAULT 0,
  pLista    IN INTEGER,
  pUM       IN INTEGER DEFAULT 0,
  pDataS    IN VARCHAR2,
  pDataF    IN VARCHAR2,
  pExtra1   IN NUMBER  DEFAULT 0,
  pExtra2   IN NUMBER  DEFAULT 0,
  pExtra3   IN NUMBER  DEFAULT 0,
  pExtra4   IN NUMBER  DEFAULT 0,
  pAtrib1   IN INTEGER DEFAULT 0,
  V_CODJOB1 IN NUMBER  DEFAULT 0,
  pSeriiFaraCant IN NUMBER DEFAULT 0
) IS
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10);
  sDataF     VARCHAR2(10);
BEGIN
  vToateArt  := Coalesce(bOBJ,      1) = 1;
  vDupaData  := Coalesce(pDupaData, 0) = 1;
  vExtra1    := Coalesce(pExtra1,   0) = 1;
  vExtra2    := Coalesce(pExtra2,   0) = 1;
  vExtra3    := Coalesce(pExtra3,   0) = 1;
  vExtra4    := Coalesce(pExtra4,   0) = 1;
  vUM        := Coalesce(pUM,       0);
  vAtrib1    := Coalesce(pAtrib1,   0);
  vSeriiFaraCant := Coalesce(pSeriiFaraCant,0) = 1;

  vDataS     := To_Date(pDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(pDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);
  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataS,vDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  sDataS     := To_Char(vDataS,&apos;dd.mm.yyyy&apos;);
  sDataF     := To_Char(vDataF,&apos;dd.mm.yyyy&apos;);

  IF    DupaData AND vDataS = vDataF THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF DupaData                     THEN vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSIF xLunaAnIni = xLunaAnFin      THEN vPerioada := &apos;= &apos;||To_Char(xLunaAnIni);
  ELSE                                    vPerioada := &apos;BETWEEN &apos;||To_Char(xLunaAnIni)||&apos; AND &apos;||To_Char(xLunaAnFin);
  END IF;

  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataS, vDataF);

  -- STEF WTF unde PLM se atribuie valoare lui ALISTID la ce foolosesete cine l-a bagat ???????
  IF    ALISTID =  0 THEN  vLista := pLista;
  ELSIF ALISTID =  3 THEN  vLista := 1;
  ELSIF ALISTID =  4 THEN  vLista := 2;
  ELSIF ALISTID = 42 THEN  vLista := 3;
  ELSIF ALISTID = 43 THEN  vLista := 4;
  ELSIF ALISTID = 97 THEN  vLista := 5;
  END IF;

  IF vLista = 3
  THEN PKG_LIST_BASE_IESIRI.BAGA_DINAMIC_COLS;
  END IF;
END;

FUNCTION ToateArt  RETURN BOOLEAN IS
BEGIN
  return vToateArt;
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION Perioada RETURN VARCHAR2 IS
BEGIN
  return vPerioada;
END;

FUNCTION Lista RETURN INTEGER IS
BEGIN
  return vLista;
END;

FUNCTION Um RETURN INTEGER IS
BEGIN
  return vUM;
END;

FUNCTION DataS RETURN DATE IS
BEGIN
  return vDataS;
END;

FUNCTION DataF RETURN DATE IS
BEGIN
  return vDataF;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  return vExtra1;
END;

FUNCTION Extra2 RETURN BOOLEAN IS
BEGIN
  return vExtra2;
END;

FUNCTION Extra3 RETURN BOOLEAN IS
BEGIN
  return vExtra3;
END;

FUNCTION Extra4 RETURN BOOLEAN IS
BEGIN
  return vExtra4;
END;

FUNCTION SeriiFaraCant RETURN BOOLEAN IS
BEGIN
  return vSeriiFaraCant;
END;

FUNCTION Atrib1 RETURN INTEGER IS
BEGIN
  return vAtrib1;
END;

END PKG_LIST_SELINTIES;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELLIVRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82389DEC356FC2C646ECFBB4567FE2ED6FE5B1D1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELLIVRARI IS
  vToateGest   BOOLEAN ;
  vToateArt    BOOLEAN ;
  vToateDoc    BOOLEAN ;
  vTipData     NUMBER(1) ;
  vPerioada    VARCHAR2(200);
  vUM          INTEGER;
  vDataS       DATE;
  vDataF       DATE;
  vExtra1      BOOLEAN;
  vExtra2      BOOLEAN;
  vExtra3      BOOLEAN;
  vExtra4      BOOLEAN;

PROCEDURE setParams ( pTipData  IN INTEGER,
                      pDataS    IN VARCHAR2,
                      pDataF    IN VARCHAR2,
                      pAllGest  IN INTEGER DEFAULT 1,
                      pAllArt   IN INTEGER DEFAULT 1,
                      pAllDoc   IN INTEGER DEFAULT 1,
                      pUM       IN INTEGER DEFAULT 0,
                      pExtra1   IN INTEGER DEFAULT 0,
                      pExtra2   IN INTEGER DEFAULT 0,
                      pExtra3   IN INTEGER DEFAULT 0,
                      pExtra4   IN INTEGER DEFAULT 0,
                      v_CodJob1 IN NUMBER  DEFAULT 0)
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
BEGIN
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  vToateGest := (pAllGest = 1);
  vToateArt  := (pAllArt  = 1);
  vToateDoc  := (pAllDoc  = 1);

  vTipData   := pTipData;
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);
  vUM        := Coalesce(pUM,0);
  vExtra1    := (pExtra1 =1 );
  vExtra2    := (pExtra2 =1 );
  vExtra3    := (pExtra3 =1 );
  vExtra4    := (pExtra4 =1 );

  IF    vTipData = 2 AND xLunaAnIni = xLunaAnFin THEN vPerioada := &apos;= &apos;||To_Char(xLunaAnIni);
  ELSIF vTipData = 2                             THEN vPerioada := &apos;BETWEEN &apos;||To_Char(xLunaAnIni)||&apos; AND &apos;||To_Char(xLunaAnFin);
  ELSIF vDataS = vDataF                          THEN vPerioada := &apos;= TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  ELSE                                                vPerioada := &apos;BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;)&apos;;
  END IF;

  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataS,vDataF);
END;

FUNCTION ToateGest  RETURN BOOLEAN IS
BEGIN
  return vToateGest;
END;

FUNCTION ToateArt  RETURN BOOLEAN IS
BEGIN
  return vToateArt;
END;

FUNCTION ToateDoc  RETURN BOOLEAN IS
BEGIN
  return vToateDoc;
END;

FUNCTION TipData RETURN INTEGER IS
BEGIN
  return vTipData;
END;

FUNCTION Perioada RETURN VARCHAR2 IS
BEGIN
  return vPerioada;
END;

FUNCTION Um RETURN INTEGER IS
BEGIN
  return vUM;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  return vExtra1;
END;

FUNCTION Extra2 RETURN BOOLEAN IS
BEGIN
  return vExtra2;
END;

FUNCTION Extra3 RETURN BOOLEAN IS
BEGIN
  return vExtra3;
END;

FUNCTION Extra4 RETURN BOOLEAN IS
BEGIN
  return vExtra4;
END;

END PKG_LIST_SELLIVRARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELMOMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D6CD6AC8CCDECCBAF9D6FE425E77852E18D8097</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selmoment IS

  vTip     NUMBER;
  vDataRef DATE;
  vExtra1  BOOLEAN;

PROCEDURE setAllParams(pTip     IN NUMBER   DEFAULT 0,
											 pDataRef IN VARCHAR2 DEFAULT NULL,
                       pExtra1  IN BOOLEAN  DEFAULT FALSE) IS
BEGIN
  vTip     := NVL(pTip,0);
  vDataRef := to_date(pDataRef,&apos;dd.mm.yyyy&apos;);
  vExtra1  := pExtra1;
END;

FUNCTION GetTip     RETURN NUMBER IS
BEGIN
 RETURN vTip;
END;

FUNCTION GetDataRef RETURN DATE IS
BEGIN
 RETURN vDataRef;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  return vExtra1;
END;

END PKG_LIST_SELMOMENT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64574304A2462160D31D78A72344CBD0DED7B869</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELPART IS

  gAllPart BOOLEAN;

PROCEDURE setParam (pAllPart NUMBER) IS
BEGIN
  gAllPart := Coalesce(pAllPart, 1) = 1;
END;

FUNCTION IsAllPart RETURN BOOLEAN IS
BEGIN
  RETURN gAllPart;
END;

END pkg_list_selpart;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELPARTART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBD7D37DB3E00BBEB5FFC8FA1D5D4AC791C5297B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELPARTART IS

  gAnLunaIni NUMBER;
  gAnLunaFin NUMBER;
  gAllPart   BOOLEAN;
  gAllArt    BOOLEAN;
  gExtra1    BOOLEAN;
  gExtra2    BOOLEAN;

PROCEDURE setParam (pAnLunaIni NUMBER, pAnLunaFin NUMBER, pAllPart NUMBER, pAllArt NUMBER, pExtra1 NUMBER DEFAULT 0, pExtra2 NUMBER DEFAULT 0) IS
BEGIN
  gAnLunaIni := pAnLunaIni;
  gAnLunaFin := pAnLunaFin;
  gAllPart   := Coalesce(pAllPart, 1) = 1;
  gAllArt    := Coalesce(pAllArt,  1) = 1;
  gExtra1    := Coalesce(pExtra1,  0) = 1;
  gExtra2    := Coalesce(pExtra2,  0) = 1;
END;

FUNCTION AnLunaIni RETURN NUMBER IS
BEGIN
  RETURN gAnLunaIni;
END;

FUNCTION AnLunaFin RETURN NUMBER IS
BEGIN
  RETURN gAnLunaFin;
END;

FUNCTION IsAllPart RETURN BOOLEAN IS
BEGIN
  RETURN gAllPart;
END;

FUNCTION IsAllArt RETURN BOOLEAN IS
BEGIN
  RETURN gAllArt;
END;

FUNCTION IsExtra1 RETURN BOOLEAN IS
BEGIN
  RETURN gExtra1;
END;

FUNCTION IsExtra2 RETURN BOOLEAN IS
BEGIN
  RETURN gExtra2;
END;

END PKG_LIST_SELPARTART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELPERAGENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50F967D9E05B38E4B7E8D5225D2C7110FA81C14E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selperagent IS

  vAllAgent    BOOLEAN;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;

PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                      pDataIni    IN VARCHAR2 DEFAULT NULL,
                      pDataFin    IN VARCHAR2 DEFAULT NULL,
                      pLunaAnIni  IN INTEGER  DEFAULT 0,
                      pLunaAnFin  IN INTEGER  DEFAULT 0,
                      pAllAgent   IN NUMBER   DEFAULT 1,
                      v_CODJOB1   IN NUMBER   DEFAULT 0 )
IS
BEGIN

  vAllAgent    := pAllAgent = 1;
  vDupaData    := pDupaData = 1;
  vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vLunaAnIni := NVL(pLunaAnIni,0);
  vLunaAnFin := NVL(pLunaAnFin,0);

  if NVL(v_CodJob1,0) &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
  end if;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataIni,vDataFin);
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION LunaAnIni RETURN INTEGER IS
BEGIN
  return vLunaAnIni;
END;

FUNCTION LunaAnFin RETURN INTEGER IS
BEGIN
  return vLunaAnFin;
END;

FUNCTION TotiAgentii  RETURN BOOLEAN IS
BEGIN
  return vAllAgent;
END;

END pkg_list_selperagent;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELPERART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C14B87B8219B5B2CF9FB518852BE4113409ABFC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_selperart IS

  vFiltruArt   INTEGER;
  vDupaData    BOOLEAN;
  vDataIni     DATE;
  vDataFin     DATE;
  vLunaAnIni   INTEGER;
  vLunaAnFin   INTEGER;
  vExtra1      BOOLEAN;

PROCEDURE SETPARAMS(  pDupaData   IN NUMBER   DEFAULT 1,
                      pDataIni    IN VARCHAR2 DEFAULT NULL,
                      pDataFin    IN VARCHAR2 DEFAULT NULL,
                      pLunaAnIni  IN INTEGER  DEFAULT 0,
                      pLunaAnFin  IN INTEGER  DEFAULT 0,
                      pFiltruArt  IN INTEGER  DEFAULT 0,
                      pExtra1     IN NUMBER   DEFAULT 0,
                      v_CODJOB1   IN NUMBER   DEFAULT 0 )
IS
BEGIN
  vFiltruArt := NVL(pFiltruArt,0);
  vDupaData  := pDupaData = 1;
  vDataIni   := to_date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin   := to_date(pDataFin,&apos;dd.mm.yyyy&apos;);
  vLunaAnIni := NVL(pLunaAnIni,0);
  vLunaAnFin := NVL(pLunaAnFin,0);
  vExtra1    := pExtra1 = 0;

  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,vLunaAnIni,vLunaAnFin);
  END IF;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(vDataIni,vDataFin);
END;

FUNCTION DupaData RETURN BOOLEAN IS
BEGIN
  return vDupaData;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION LunaAnIni RETURN INTEGER IS
BEGIN
  return vLunaAnIni;
END;

FUNCTION LunaAnFin RETURN INTEGER IS
BEGIN
  return vLunaAnFin;
END;

FUNCTION FiltruArt RETURN INTEGER IS
BEGIN
  return vFiltruArt;
END;

FUNCTION Extra1 RETURN BOOLEAN IS
BEGIN
  return vExtra1;
END;

END PKG_LIST_SELPERART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELSITART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECD812BDEF117A0BE8449A6514BDB999C2939471</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELSITART IS

  vPerioada    VARCHAR2(100);
  vToateArt    BOOLEAN ;
  vTotiPart    BOOLEAN ;
  vToateDoc    BOOLEAN ;

PROCEDURE SETPARAMS(
    pFaraData IN NUMBER   DEFAULT 1,
    pDataS    IN VARCHAR2 DEFAULT NULL,
    pDataF    IN VARCHAR2 DEFAULT NULL,
    pToateArt IN NUMBER   DEFAULT 1,
    pTotiPart IN NUMBER   DEFAULT 1,
    pToateDoc IN NUMBER   DEFAULT 1 ,
    V_CODJOB1 IN NUMBER   DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
BEGIN
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;

  IF    pFaraData = 0 AND sDataS = sDataF THEN vPerioada := &apos; = TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  ELSIF pFaraData = 0                     THEN vPerioada := &apos; BETWEEN TO_DATE(&apos;&apos;&apos;||sDataS||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;) AND TO_DATE(&apos;&apos;&apos;||sDataF||&apos;&apos;&apos;,&apos;&apos;DD.MM.YYYY&apos;&apos;)&apos;;
  ELSE                                         vPerioada := &apos;&apos;;
  END IF;

  vToateArt   := Coalesce(pToateArt, 1) = 1;
  vTotiPart   := Coalesce(pTotiPart, 1) = 1;
  vToateDoc   := Coalesce(pToateDoc, 1) = 1;
END;

FUNCTION Perioada    RETURN VARCHAR2 IS
BEGIN
  return vPerioada;
END;

FUNCTION ToateArt    RETURN BOOLEAN IS
BEGIN
  return vToateArt;
END;

FUNCTION TotiPart    RETURN BOOLEAN IS
BEGIN
  return vTotiPart;
END;

FUNCTION ToateDoc    RETURN BOOLEAN IS
BEGIN
  return vToateDoc;
END;

end PKG_LIST_SELSITART;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELTRAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5249E26B34C4F4456344F5E24B55BF4D5EAC4CCD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELTRAS IS

  p_dataIni    DATE;
  p_dataFin    DATE;
  p_flgGest    BOOLEAN;
  p_flgTipCont BOOLEAN;
  p_flgSICentr BOOLEAN;

PROCEDURE setAllParams(v_dataini    IN VARCHAR2,
                       v_dataFin    IN VARCHAR2,
											 v_flgGest    IN NUMBER   DEFAULT 1,
											 v_flgTipCont IN NUMBER   DEFAULT 1,
											 v_flgSICentr IN NUMBER   DEFAULT 1,
                       v_CodJob1    IN NUMBER   DEFAULT 0) IS
  xLunaAnIni integer;
  xLunaAnFin integer;
BEGIN
  p_dataIni    := To_Date(v_dataini,&apos;dd.mm.yyyy&apos;);
  p_dataFin    := To_Date(v_dataFin,&apos;dd.mm.yyyy&apos;);
  p_flgGest    := v_flgGest    = 1;
  p_flgTipCont := v_flgTipCont = 1;
  p_flgSICentr := v_flgSICentr = 1;
  if NVL(v_CodJob1,0) &gt; 0 then
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,p_dataIni,p_dataFin,xLunaAnIni,xLunaAnFin);
  end if;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(p_dataIni,p_dataFin);
END;


FUNCTION getDataIni RETURN DATE IS
BEGIN
  RETURN p_dataIni;
END;

FUNCTION getDataFin RETURN DATE IS
BEGIN
	RETURN p_dataFin;
END;

FUNCTION isAllGest RETURN BOOLEAN IS
BEGIN
	RETURN p_flgGest;
END;

FUNCTION isAllTipCont RETURN BOOLEAN IS
BEGIN
	RETURN p_flgTipCont;
END;

FUNCTION isSICentralizat RETURN BOOLEAN IS
BEGIN
	RETURN p_flgSICentr;
END;

FUNCTION GetInterval RETURN VARCHAR2 IS
BEGIN
  RETURN &apos; to_date(&apos;&apos;&apos;||To_Char(p_dataIni,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) AND to_date(&apos;&apos;&apos;||To_Char(p_dataFin,&apos;dd.mm.yyyy&apos;)||&apos;&apos;&apos;,&apos;&apos;dd.mm.yyyy&apos;&apos;) &apos;;
END;


end PKG_LIST_SELTRAS;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELURMDOCPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BAED9C8B70FB4F44C650CB6BAE610D209CE79CDC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELURMDOCPART IS

  vNrDoc    IESIRI.NRDOC%TYPE;
  vDataDoc  IESIRI.DATADOC%TYPE; 
  vCodPart  NPART.CODPART%TYPE;
  
  vDataS       DATE;
  vDataF       DATE;
 
  PROCEDURE SETPARAMS( p_CodPArt    IN NUMBER,
                       p_NrDoc      IN NUMBER,
                       p_DataDoc    IN VARCHAR2,
                       pCodJob1     IN NUMBER   DEFAULT 0, 
                       pDataS    IN VARCHAR2,
                       pDataF    IN VARCHAR2)
IS
  aTipInterval NUMBER(1) := 0;
  ALISTID    NUMBER(2) := 0;
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
  sDataS     VARCHAR2(10) := pDataS;
  sDataF     VARCHAR2(10) := pDataF;
  
BEGIN
  vDataS     := To_Date(sDataS,&apos;dd.mm.yyyy&apos;);
  vDataF     := To_Date(sDataF,&apos;dd.mm.yyyy&apos;);
  xLunaAnIni := Extract(Year from vDataS)*12 + Extract(Month from vDataS);
  xLunaAnFin := Extract(Year from vDataF)*12 + Extract(Month from vDataF);

  IF NVL(pCodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(pCodJob1,sDataS,sDataF,xLunaAnIni,xLunaAnFin);
  END IF;
  IF NVL(pCodJob1,0) &gt; 0 THEN
    --SELECT TIPINTERVAL INTO ATIPINTERVAL FROM JOBLISTE1 WHERE CODJOB1 = pCodJob1;
    -- Tip interval fix e o prostie, fortez TipInterval = 1, adica dinamic
    aTipInterval  := 1;
  END IF;

  IF ATIPINTERVAL = 0 THEN 
	  vDataDoc := to_date(p_DataDoc,&apos;dd.mm.yyyy&apos;);
  ELSE
    SELECT TO_CHAR(SYSDATE,&apos;DD.MM.YYYY&apos;) INTO vDataDoc FROM JOBLISTE1 WHERE CODJOB1 = NVL(pCodJob1,0);
  END IF ;
  vCodPart := p_CodPArt;
  vNrDoc   := p_NrDoc;
END;
  
  FUNCTION CodPart   RETURN NPART.CODPART%TYPE IS
  BEGIN
    return vCodPart;
  END;
  
  FUNCTION NrDoc     RETURN IESIRI.NRDOC%TYPE IS
  BEGIN
    return vNrDoc;
  END;

  FUNCTION DataDoc   RETURN IESIRI.DATADOC%TYPE IS
  BEGIN
    return vDataDoc;
  END;
  
end PKG_LIST_SELUrmDocPart;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELURMOFE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFA8DDE38F57E21B5017D0CCB83E657AB5CAD9CF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELURMOFE IS

  vDataIni     DATE;
  vDataFin     DATE;
  vTotiPart    BOOLEAN ;

PROCEDURE SETPARAMS(  pDataIni     IN VARCHAR2 DEFAULT NULL,
                      pDataFin     IN VARCHAR2 DEFAULT NULL,
                      pTotiPart    IN NUMBER   DEFAULT 1 ,
                      V_CODJOB1 IN NUMBER  DEFAULT 0
) IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  vTotiPart   := pTotiPart = 1;
  vDataIni     := To_Date(pDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin     := To_Date(pDataFin,&apos;dd.mm.yyyy&apos;);
  IF NVL(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,vDataIni,vDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

FUNCTION DataIni RETURN DATE IS
BEGIN
  return vDataIni;
END;

FUNCTION DataFin RETURN DATE IS
BEGIN
  return vDataFin;
END;

FUNCTION TotiPart  RETURN BOOLEAN IS
BEGIN
  return vTotiPart;
END;

END PKG_LIST_SELURMOFE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_SELUTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A71FD02B3DC8D9AF7DBD78172D0C2F6FBE8BFE2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_SELUTILAJE IS

  gAllUtilaje BOOLEAN;
  gAllTipUtilaje BOOLEAN;
  gAllInterventii BOOLEAN;
  gExtra1 BOOLEAN;
  gPerDataInterv NUMBER;
  gDataIni VARCHAR2(10);
  gDataFin VARCHAR2(10);
PROCEDURE setParams(
                      pAllUtilaje     IN NUMBER   DEFAULT 1,
                      pAllInterventii IN NUMBER   DEFAULT 1,
                      pExtra1         IN NUMBER   DEFAULT 0,
                      pPerDataInterv  IN NUMBER   DEFAULT 0,
                      pAllTipUtilaje  IN NUMBER   DEFAULT 1,
                      pDataIni        IN VARCHAR2,
                      pDataFin        IN VARCHAR2,
                      V_CODJOB1 IN NUMBER  DEFAULT 0)
IS
  xLunaAnIni INTEGER;
  xLunaAnFin INTEGER;
BEGIN
  gAllUtilaje := pAllUtilaje = 1;
  gAllTipUtilaje := pAllTipUtilaje = 1;
  gAllInterventii := pAllInterventii = 1;
  gExtra1 := pExtra1 = 1;
  gPerDataInterv := pPerDataInterv;
  gDataIni := pDataIni;
  gDataFin := pDataFin;
  IF Coalesce(v_CodJob1,0) &gt; 0 THEN
    PKG_ORA_LISTS.SET_INTERVAL_DINAMIC(V_CODJOB1,gDataIni,gDataFin,xLunaAnIni,xLunaAnFin);
  END IF;
END;

FUNCTION IsAllUtilaje RETURN BOOLEAN IS
BEGIN
  RETURN gAllUtilaje;
END;

FUNCTION IsAllTipUtilaje RETURN NUMBER IS
BEGIN
  if gAllTipUtilaje then return 1; else return 0; end if;
END;

FUNCTION IsAllInterventii RETURN BOOLEAN IS
BEGIN
  RETURN gAllInterventii;
END;

FUNCTION IsExtra1 RETURN BOOLEAN IS
BEGIN
  RETURN gExtra1;
END;

FUNCTION PerDataInterv RETURN NUMBER IS
BEGIN
  RETURN gPerDataInterv;
END;

FUNCTION DataIni RETURN VARCHAR2 IS
BEGIN
  RETURN gDataIni;
END;

FUNCTION DataFin RETURN VARCHAR2 IS
BEGIN
  RETURN gDataFin;
END;

END pkg_list_selutilaje; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_STRUCT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEF654ABC81B70CBF7F425EB6A78883987882F98</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LIST_STRUCT IS

  g_TableSpec        VARCHAR2(10000);
  g_TableSpecRezerva VARCHAR2(10000);
  g_tmpName          VARCHAR2(100);
  v_IdxParamLista    NUMBER(5);
  v_IdxSuplTab       NUMBER(5);

PROCEDURE SPLIT_COLUMN(tbl_name in varchar2,col_name in varchar2,sep in varchar2,tmp_name in varchar2) is
PRAGMA AUTONOMOUS_TRANSACTION;
  s varchar2(300);
  val varchar2(50);
  idx number(2) := 1;
begin
  EXECUTE IMMEDIATE &apos;DELETE FROM &apos;||tmp_name;
  EXECUTE IMMEDIATE &apos;INSERT INTO &apos;||tmp_name||&apos;(SIMBOL) SELECT DISTINCT &apos;||col_name||&apos; FROM &apos;||tbl_name;
  for v_rec in(select simbol from tmp_level1) loop
    s:= v_rec.simbol ||sep;
    idx := 1;
    while length(s) &gt; 0 loop
      val := substr(s,1,instr(s,sep)-1);
      execute IMMEDIATE &apos;update &apos;||tmp_name||&apos; set nivel_&apos;||idx||&apos; = &apos;&apos;&apos;||val||&apos;&apos;&apos; where simbol = &apos;&apos;&apos;||v_rec.simbol||&apos;&apos;&apos;&apos;;
      s := substr(s,instr(s,sep)+1,length(s));
      IDX := IDX + 1;
    end loop;
    commit;
  end loop;
end ;

FUNCTION  GET_VIEW_COLS(aViewName varchar2) return crs is
cResult crs;
BEGIN
  OPEN cResult FOR
    SELECT COLUMN_NAME, DATA_TYPE,DATA_LENGTH FROM user_tab_columns WHERE table_name = upper(aViewName);
  RETURN cResult;
END;

FUNCTION getTimeStamp(aObject IN VARCHAR2) RETURN VARCHAR2 IS
tResult VARCHAR2(50);
BEGIN
/*to_date(to_char(created),&apos;dd.mm.yyyy hh.mi.ss&apos; ) INTO tResult*/
  BEGIN
    SELECT to_char(created,&apos;dd.mm.yyyy hh24.mi.ss&apos;) INTO tResult  FROM user_objects WHERE object_name = upper(aObject);
  EXCEPTION WHEN NO_DATA_FOUND THEN
    RETURN &apos;x&apos;;
  END;
  RETURN tResult;
END;

PROCEDURE ValideazaSuplCols(aListID IN NUMBER, aListVer IN NUMBER,aSuplCols IN VARCHAR2) IS
PRAGMA AUTONOMOUS_TRANSACTION;
  sTab VARCHAR2(50);
  sAlias VARCHAR2(75);
  tmp VARCHAR2(10000);

  TYPE t_record IS RECORD(id NUMBER(20) ,alias VARCHAR2(200));
  TYPE t_table IS TABLE OF t_record;
  t_aliasSalvat  t_table;
  t_aliasNou     t_TABLE;

  i NUMBER(20) :=0;
  k NUMBER(20) :=0;
  j NUMBER(20) :=0;
  bGasit  BOOLEAN := FALSE;

BEGIN

	SELECT lc.codlistcols, substr(lc.alias,1,instr(lc.alias,&apos;.&apos;)-1) BULK COLLECT INTO t_aliasSalvat
    FROM winmadmin.listcols lc WHERE listid = aListid AND listver = aListver AND lc.usercolumn = 1;

  t_AliasNou := t_table();

  IF length(TRIM(aSuplCols)) &gt; 0 THEN
      tmp := upper(aSuplCols)||&apos;,&apos;;
          WHILE instr(tmp,&apos;,&apos;) &gt; 1 LOOP
               sTab := trim(substr(tmp,1,instr(tmp,&apos; &apos;)));
               tmp:= trim(substr(tmp,instr(tmp,&apos; &apos;)+1,length(tmp)));
               sAlias := trim(substr(tmp,1,instr(tmp,&apos;,&apos;)-1));
               tmp := TRIM(substr(tmp,instr(tmp,&apos;,&apos;)+1,length(tmp)));

							 t_aliasNou.EXTEND;
							 k:=k+1;
							 t_AliasNou(k).id :=0;
							 t_AliasNou(k).Alias := sAlias;
 	      END LOOP;
	    END IF;
  IF t_aliasSalvat.COUNT &gt; 0 THEN

		FOR i IN  t_aliasSalvat.FIRST..t_aliasSalvat.LAST LOOP

    bGasit := FALSE;
		IF t_aliasNou.COUNT &gt; 0 THEN
			 FOR j IN t_aliasNou .FIRST..t_aliasNou.LAST LOOP
            IF t_AliasSalvat(i).Alias = t_AliasNou(j).Alias  THEN
                 bGasit := TRUE;
						END IF;
			 END LOOP;
    END IF;

			 IF NOT bGasit THEN
		    DELETE FROM winmadmin.listcols lc WHERE lc.codlistcols = t_aliasSalvat(i).id;
			 END IF;

    END LOOP;

    COMMIT;
  END IF;
END;

PROCEDURE StartSuplCols IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  v_IdxSuplTab := 0;
  DELETE FROM TMP_LST_TABS;
  COMMIT;
END;

PROCEDURE IncIdxSuplTab IS
BEGIN
  -- STEF - pentru PG
  v_IdxSuplTab := v_IdxSuplTab + 1;
END;

PROCEDURE AddSuplTabs (aSuplCols IN OUT VARCHAR2, aTable IN VARCHAR2, aAlias IN VARCHAR2, aJoinCond IN VARCHAR2, aFORCEVALID IN NUMBER DEFAULT 0, aCUSTOMLST IN NUMBER DEFAULT 0) IS
  vSuplCols CLOB          := aSuplCols;
  vTable    CLOB          := TRIM(aTable);
  vAlias    VARCHAR2(100) := TRIM(aAlias);
  vJoinCond CLOB          := TRIM(aJoinCond);
  vTestCond CLOB;
  bCondOk   BOOLEAN;
  sSQL      CLOB;
BEGIN
  --aFORCEVALID = 1 SKIP VALIDARE PENTRU JOINURI CU TABLELE CARE NU SUNT IN COLOANE SUPLIMENTARE
  IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1
  THEN bCondOk := TRUE;
  ELSE bCondOk := Coalesce(Length(vJoinCond),0) &lt;&gt; 0;
  END IF;

  IF  Coalesce(Length(vTable), 0) &lt;&gt; 0
  AND Coalesce(Length(vAlias), 0) &lt;&gt; 0
  AND bCondOk
  AND TmpExists(vTable) = 1
  THEN
    IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1 THEN
      vTestCond := &apos;&apos;;
      vSuplCols := vTable||&apos; &apos;||vAlias;
    ELSIF Coalesce(Length(vSuplCols),0) = 0 AND Coalesce(aFORCEVALID,0) = 1 THEN
      vTestCond := &apos;&apos;;
      vSuplCols := vTable||&apos; &apos;||vAlias;
    ELSE
      vTestCond := &apos; AND &apos;||vJoinCond;
      vSuplCols := vSuplCols||&apos;, &apos;||vTable||&apos; &apos;||vAlias;
    END IF;
    sSQL := &apos;SELECT 1 FROM &apos;||vSuplCols||&apos; WHERE 1=0&apos;||vTestCond;
    BEGIN
      IF Coalesce(aFORCEVALID,0) = 0 THEN
        insert into x(test) values(ssql);
        commit;
        EXECUTE IMMEDIATE sSQL;
      END IF;
      IncIdxSuplTab;
      aSuplCols    := vSuplCols;
      INSERT INTO TMP_LST_TABS(ORDINE, TABLENAME, ALIASNAME, JOINCOND, FORCEVALID, ISVIEW) VALUES (v_IdxSuplTab, vTable, vAlias, vJoinCond, Coalesce(aFORCEVALID,0), 0);
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;
END;

PROCEDURE AddSuplView (aSuplCols IN OUT CLOB, aView IN CLOB, aAlias IN VARCHAR2, aJoinCond IN VARCHAR2, aFORCEVALID IN NUMBER DEFAULT 0, aCUSTOMLST IN NUMBER DEFAULT 0) IS
  vView     CLOB          := TRIM(aView);
  vAlias    VARCHAR2(100) := TRIM(aAlias);
  vJoinCond CLOB          := TRIM(aJoinCond);
  vTestCond CLOB;
  bCondOk   BOOLEAN;
  sSQL      CLOB;
BEGIN
  --aFORCEVALID = 1 SKIP VALIDARE PENTRU JOINURI CU TABLELE CARE NU SUNT IN COLOANE SUPLIMENTARE
  IF    NOT vView LIKE (&apos;(%)&apos;)
  THEN vView := &apos;(&apos;||vView||&apos;)&apos;;
  END IF;

  IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1
  THEN bCondOk := TRUE;
  ELSE bCondOk := Coalesce(Length(vJoinCond),0) &lt;&gt; 0;
  END IF;

  IF  Coalesce(Length(vView),  0) &lt;&gt; 0
  AND Coalesce(Length(vAlias), 0) &lt;&gt; 0
  AND bCondOk
  THEN
    IF v_IdxSuplTab = 0 AND Coalesce(aCUSTOMLST,0) = 1 THEN
      vTestCond := &apos;&apos;;
      aSuplCols := vView||&apos; &apos;||vAlias;
    ELSE
      vTestCond := &apos; AND &apos;||vJoinCond;
      aSuplCols := aSuplCols||&apos;, &apos;||vView||&apos; &apos;||vAlias;
    END IF;
    sSQL := &apos;SELECT 1 FROM &apos;||aSuplCols||&apos; WHERE 1=0&apos;||vTestCond;
    BEGIN
      IF Coalesce(aFORCEVALID,0) = 0 THEN
        insert into x(test) values(ssql);
        commit;
        EXECUTE IMMEDIATE sSQL;
      END IF;
      IncIdxSuplTab;
      INSERT INTO TMP_LST_TABS(ORDINE, TABLENAME, ALIASNAME, JOINCOND, FORCEVALID, ISVIEW) VALUES (v_IdxSuplTab, vView, vAlias, vJoinCond, Coalesce(aFORCEVALID,0), 1);
    EXCEPTION
      WHEN OTHERS THEN raise;
    END;
  END IF;
END;

PROCEDURE GetSuplCols (alistid IN NUMBER, alistver IN NUMBER, sFields OUT CLOB, sAlias OUT CLOB, sNullAlias OUT CLOB, sJoin OUT CLOB, gSuplCols IN CLOB) IS
  sSuplCols CLOB;
  vOK       BOOLEAN;
  sSQL      CLOB;
  sAux      CLOB;
BEGIN
  sSuplCols  := Trim(gSuplCols);
	sFields    := &apos;&apos;;
	sAlias     := &apos;&apos;;
	sNullAlias := &apos;&apos;;

  FOR v_rec IN (
    SELECT l.tablename, l.fieldname aliasname, l.joincond, Trim(l.sql) sql_sview
    FROM winmadmin.listsql l
    WHERE l.tip = 0
      AND l.listid  = aLISTID
      AND l.listver = aLISTVER
    ORDER BY codlistsql
  ) LOOP
    IF Coalesce(Length(v_rec.sql_sview), 0) = 0 --aici problema, v_rec.sql_sview intra trunchiat in parametru de tip clob
    THEN AddSuplTabs(sSuplCols, v_rec.tablename, v_rec.aliasname, v_rec.joincond, 0, CASE WHEN aLISTID &lt; 0 OR aLISTID BETWEEN 40000 AND 44999 THEN 1 ELSE 0 END);
    ELSE AddSuplView(sSuplCols, v_rec.sql_sview, v_rec.aliasname, v_rec.joincond, 0, CASE WHEN aLISTID &lt; 0 OR aLISTID BETWEEN 40000 AND 44999 THEN 1 ELSE 0 END);
    END IF;
  END LOOP;

	FOR v_rec IN (
    SELECT lc.alias, lc.fieldname
    FROM winmadmin.listcols lc
		WHERE lc.usercolumn = 1
      AND lc.listid = aLISTID
      AND lc.listver = aLISTVER
	) LOOP
    vOK := True;
    IF Coalesce(Length(sSuplCols), 0) &lt;&gt; 0 THEN
      -- stef am nevoie sa validez coloanele suplimentare fiindca in cazul extensiilor aceste pot diferi de la o firma la alta
      sSQL := &apos;SELECT &apos;||v_rec.alias||&apos; FROM &apos;||sSuplCols||&apos; WHERE 1=0&apos;;
      BEGIN
        EXECUTE IMMEDIATE sSQL;
      EXCEPTION
        WHEN OTHERS THEN vOK := FALSE;
      END;
    END IF;
    IF vOK THEN
      sFields    := sFields   ||&apos;,&apos;||v_rec.fieldname;
   	  sAlias     := sAlias    ||&apos;,&apos;||v_rec.alias;
      sNullAlias := sNullAlias||&apos;,NULL&apos;;
    END IF;
	END LOOP;

  sAux  := Upper(sAlias);
  sJoin := &apos;&apos;;
  FOR v_rec IN (
    SELECT Upper(TABLENAME) TABLENAME, Upper(ALIASNAME) ALIASNAME, Upper(JOINCOND) JOINCOND, ORDINE
    FROM TMP_LST_TABS
    ORDER BY ORDINE DESC
    -- creez joinul de la coada la cap pentru a vede daca exista dependinte
  ) LOOP
    IF (aLISTID &lt; 0 or aLISTID BETWEEN 40000 AND 44999) AND v_rec.ORDINE = 1 THEN
      sJoin := v_rec.TABLENAME||&apos; &apos;||v_rec.ALIASNAME||sJoin;
    ELSIF InStr(sAux, v_rec.ALIASNAME||&apos;.&apos;) &gt; 0 THEN
      sJoin := &apos; LEFT JOIN &apos;||v_rec.TABLENAME||&apos; &apos;||v_rec.ALIASNAME||&apos; ON &apos;||v_rec.JOINCOND||sJoin;
      sAux  := sAux||&apos;,&apos;||v_rec.JOINCOND;
    END IF;
  END LOOP;
END;

PROCEDURE UpdateTmp(pTab in VARCHAR2 , pAlias IN varchar2, pOwner IN varchar2 DEFAULT NULL) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF pOwner IS NULL THEN
    INSERT INTO tmp_list_cols(tabla,coloana,tipcol,lungime)
    SELECT  ptab, pAlias||&apos;.&apos;||a.COLUMN_NAME,a.DATA_TYPE,a.DATA_LENGTH
    FROM user_tab_columns a
    WHERE a.TABLE_NAME = pTab
  --    AND a.DATA_TYPE &lt;&gt; &apos;BLOB&apos;
    ORDER BY a.COLUMN_ID;
  ELSE
    INSERT INTO tmp_list_cols(tabla,coloana,tipcol,lungime)
    SELECT  ptab, pAlias||&apos;.&apos;||a.COLUMN_NAME,a.DATA_TYPE,a.DATA_LENGTH
    FROM ALL_TAB_COLUMNS a
    WHERE a.TABLE_NAME = pTab
      AND a.owner = pOwner
    ORDER BY a.COLUMN_ID;
  END IF;
  COMMIT;
END;

procedure adunaColoaneleXView (pViewName in VARCHAR2) IS
  sJoinsTbl view_joins.joinuri%type;
  sViewName view_joins.viewname%type;
  sIdCustomTable varchar2(20);
  idCustomTable NUMBER(10);
	b number;
  sJoinTblFromCustomTbl WINMADMIN.MAKETEPROPRII.TBLMASTER%type;
BEGIN
  sViewName := upper(pViewName);
  DELETE FROM tmp_list_cols;
  begin
    select vj.joinuri into sJoinsTbl from view_joins vj where vj.viewname = &apos;&apos; || sViewName || &apos;&apos;;
  exception
     WHEN OTHERS THEN sJoinsTbl := null;
   end;

   if coalesce(instr(sViewName, &apos;CUSTOMFORMDB_&apos;),0) &gt; 0 then
      sViewName := trim(replace(sViewName,  &apos;CUSTOMFORMDB_&apos;, &apos;&apos;));
      b := coalesce(instr(sViewName, &apos;_VIEW&apos;),0);
      sIdCustomTable := Substr(sViewName, 1, b-1);
			if length(sIdCustomTable) &gt; 0 then
        begin
           idCustomTable := to_number( sIdCustomTable );
           select mp.tblmaster into sJoinTblFromCustomTbl
                  from winmadmin.maketeproprii mp
                  where mp.codmaketeproprii = (select distinct min(mpi.codmaketeproprii) keep (DENSE_RANK FIRST ORDER BY mpi.PROG)
                                       from winmadmin.maketeproprii mpi where mpi.iddocument =idCustomTable);
         exception
            when others then sJoinTblFromCustomTbl := null;
         end;
        end if;
         if sJoinTblFromCustomTbl is not null then
           sJoinTblFromCustomTbl := sJoinTblFromCustomTbl || &apos; CustM &apos;;
           if sJoinsTbl is null then sJoinsTbl := sJoinTblFromCustomTbl;
                                     else sJoinsTbl := sJoinsTbl || &apos;, &apos; || sJoinTblFromCustomTbl;
           end if;
      end if;

   end if;

   if sJoinsTbl is not null then
     SetTableSpec(sJoinsTbl);
      AdunaColoanele;
   end if;
END;


PROCEDURE AdunaColoanele IS
 sTab   VARCHAR2(200);
 sOwner   VARCHAR2(100);
 sAlias VARCHAR2(70);
 tmp    VARCHAR2(10000);
 cnt    NUMBER(10) := 0;
BEGIN
  -- g_tmpName := &apos;TMP_LIST_NOMPART_125_30&apos;;
  DELETE FROM tmp_list_cols;

  IF length(TRIM(g_tableSpec)) &gt; 0 THEN
		SELECT COUNT(*) INTO cnt FROM tmp_list_cols ;
	  IF cnt = 0 THEN --citesc coloane doar daca nu au mai fost citite
      tmp := upper(g_TableSpec)||&apos;,&apos;;
      WHILE instr(tmp,&apos;,&apos;) &gt; 1 LOOP
        sOwner := null;
        sTab   := trim(substr(tmp,1,instr(tmp,&apos; &apos;)));
        if(instr(sTab,&apos;.&apos;) &gt; 0) then
          sOwner := trim(substr(sTab,1,instr(sTab,&apos;.&apos;)-1));
          sTab      := trim(substr(sTab,instr(sTab,&apos;.&apos;)+1,length(sTab)));
        end if;
        tmp    := trim(substr(tmp,instr(tmp,&apos; &apos;)+1,length(tmp)));
			  sAlias := trim(substr(tmp,1,instr(tmp,&apos;,&apos;)-1));
			  tmp    := TRIM(substr(tmp,instr(tmp,&apos;,&apos;)+1,length(tmp)));
				updateTmp(sTab,sAlias, sOwner);
 	    END LOOP;
	  END IF;
	END IF;
END;

PROCEDURE SetTableSpec (p_TableSpec IN VARCHAR2) IS
BEGIN
  g_TableSpec := p_tableSpec;
END;

PROCEDURE SetTableSpecRezerva (p_TableSpec IN VARCHAR2) IS
BEGIN
  g_TableSpecRezerva := g_TableSpec;
  g_TableSpec := p_tableSpec;
END;

PROCEDURE SetTableSpecFROMRezerva IS
BEGIN
  g_TableSpec := g_TableSpecRezerva;
END;

FUNCTION getCreateTemp (tmpName IN VARCHAR2) RETURN VARCHAR2 IS
 sResult  VARCHAR2(200);
BEGIN
  sResult := &apos;CREATE GLOBAL TEMPORARY TABLE &apos;||TMPNAME||&apos; ON COMMIT PRESERVE ROWS UNRECOVERABLE AS &apos;;
	RETURN sResult;
END;

FUNCTION getDMLGrant (tmpName IN VARCHAR2, UserName IN VARCHAR2) RETURN VARCHAR2 IS
	sResult VARCHAR2(100) :=&apos;GRANT DELETE, INSERT, UPDATE, SELECT ON &apos;;
BEGIN
	sResult := sResult || tmpName ||&apos; TO &apos;||UserName;
	RETURN sResult;
END;

FUNCTION TmpExists (tmpName IN Varchar2) RETURN NUMBER IS
	sResult NUMBER (1);
BEGIN
  SELECT COUNT(table_name) INTO sResult FROM user_tables WHERE table_name = UPPER(tmpName);
	RETURN sResult;
END;

FUNCTION ColExists (TabName IN VARCHAR2, ColName IN Varchar2) RETURN NUMBER IS
	sResult NUMBER (1);
BEGIN
  SELECT COUNT(1) INTO sResult FROM user_tab_columns WHERE table_name = UPPER(TabName) AND column_name = UPPER(ColName);
	RETURN sResult;
END;

PROCEDURE GenerateTMP (
  tmpName  IN VARCHAR2,
  listCols IN VARCHAR2,
  UserName IN VARCHAR2,
  plusCol1 IN VARCHAR2 DEFAULT NULL,
  plusCol2 IN VARCHAR2 DEFAULT NULL,
  plusCol3 IN VARCHAR2 DEFAULT NULL,
  plusCol4 IN VARCHAR2 DEFAULT NULL)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
  XlistCols VARCHAR2(30000);
  sDDL      VARCHAR2(30000) := &apos;CREATE GLOBAL TEMPORARY TABLE &apos;;
	sDML      VARCHAR2(  100);
BEGIN
  IF TmpExists(tmpName) = 1 THEN
		EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName;
		EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName;
	END IF;

  -- STEF la apelare din delphi se pare ca avem o limita ~4000 caractere cand se transmite parametrul asa ca spargem sirul in bucati in acest caz
  XlistCols := listCols||plusCol1||plusCol2||plusCol3||plusCol4;
  XlistCols := replace( XlistCols, &apos;V2(&apos;, &apos;VARCHAR2(&apos; );
  XlistCols := replace( XlistCols, &apos;N(&apos;, &apos;NUMBER(&apos; );

	sDDL := sDDL || tmpName ||&apos;(&apos;;
	sDDL := sDDL || XlistCols||&apos; ,UNITAR NUMBER(20) DEFAULT 1 &apos; ||&apos;) ON COMMIT PRESERVE ROWS&apos;;

	g_TableSpec := &apos;&apos;;
	EXECUTE IMMEDIATE sDDL;
  g_tmpname :=  tmpName;
	sDML := getDMLGrant(tmpName,UserName);
	EXECUTE IMMEDIATE sDML;
/*
  IF TmpExists(tmpName||&apos;PIV&apos;) = 1 THEN
		EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName||&apos;PIV&apos;;
		EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName||&apos;PIV&apos;;
	END IF;

	sDDL := &apos;CREATE GLOBAL TEMPORARY TABLE &apos; || tmpName ||&apos;PIV(&apos;;
	sDDL := sDDL || XlistCols||&apos; ,UNITAR NUMBER(20) DEFAULT 1 &apos; ||&apos;) ON COMMIT PRESERVE ROWS&apos;;

	EXECUTE IMMEDIATE sDDL;
	sDML := getDMLGrant(tmpName||&apos;PIV&apos;,UserName);
	EXECUTE IMMEDIATE sDML;
*/
END;

PROCEDURE AlterTMP (tmpName IN VARCHAR2,listCols IN VARCHAR2, SuplCols IN VARCHAR2) IS
PRAGMA AUTONOMOUS_TRANSACTION;
  sDDL VARCHAR2(10000);
BEGIN
  IF TmpExists(tmpName) = 1 THEN
  	sDDL := &apos;Rename &apos; || tmpName ||&apos; to &apos;||tmpName||&apos;XX&apos;;
  	EXECUTE IMMEDIATE sDDL;
    sDDL := &apos;CREATE GLOBAL TEMPORARY TABLE &apos;|| tmpName ||&apos; ON COMMIT PRESERVE ROWS AS (SELECT * FROM &apos; || tmpName||&apos;XX WHERE 1=0)&apos;;
  	EXECUTE IMMEDIATE sDDL;
  	sDDL := &apos;ALTER TABLE &apos; || tmpName ||&apos; ADD (&apos;||ListCols||&apos;)&apos;;
  	EXECUTE IMMEDIATE sDDL;
  	sDDL := &apos;INSERT INTO &apos; || tmpName ||&apos; SELECT x.*,&apos;||SuplCols||&apos; FROM &apos; || tmpName||&apos;XX x&apos;;
  	EXECUTE IMMEDIATE sDDL;
    pkg_list_Struct.DropTbl (tmpName||&apos;XX&apos;);
  end if;
END;

FUNCTION list_counter RETURN NUMBER IS
  sResult NUMBER(27);
BEGIN
	SELECT seq_list_counter.NEXTVAL INTO sResult FROM dual;
	RETURN sResult;
END;

PROCEDURE DropTbl (tmpName IN VARCHAR2, Do1 integer default 1, Do2 integer default 1, Do3 integer default 1, Do4 integer default 1) IS
BEGIN

  IF Do1 = 1 and TmpExists 	(tmpName) &gt; 0 THEN
   BEGIN
  	 EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName;
  	 EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName;
   EXCEPTION
     WHEN OTHERS THEN NULL;
   END;
  END IF;

  IF Do2 = 1 and TmpExists 	(&apos;W&apos;||tmpName) &gt; 0 THEN
   BEGIN
     EXECUTE IMMEDIATE &apos;TRUNCATE TABLE W&apos;||tmpName;
  	 EXECUTE IMMEDIATE &apos;DROP TABLE W&apos;||tmpName;
    EXCEPTION
     WHEN OTHERS THEN NULL;
   END;
  END IF;

  IF Do3 = 1 and TmpExists 	(tmpName||&apos;PIV&apos;) &gt; 0 THEN
   BEGIN
     EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmpName||&apos;PIV&apos;;
  	 EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmpName||&apos;PIV&apos;;
    EXCEPTION
     WHEN OTHERS THEN NULL;
   END;
  END IF;

  IF Do4 = 1 and TmpExists 	(&apos;W&apos;||tmpName||&apos;PIV&apos;) &gt; 0 THEN
   BEGIN
     EXECUTE IMMEDIATE &apos;TRUNCATE TABLE W&apos;||tmpName||&apos;PIV&apos;;
  	 EXECUTE IMMEDIATE &apos;DROP TABLE W&apos;||tmpName||&apos;PIV&apos;;
    EXCEPTION
     WHEN OTHERS THEN NULL;
   END;
  END IF;

END;

FUNCTION SaveLista( aSaveTable in varchar2, aListTable in varchar2 ,sUserName in varchar2, iCodFirma in number ) RETURN NUMBER is
iResult number(1);
sSkemaPivot varchar2(1000);
sSkemaGrant varchar2(1000);
begin

 iResult := tmpExists(upper(aSaveTable)) ;

 if iResult &lt;&gt; 0 then
   return iResult;
 end if;

 sSkemaGrant :=sUserName;
 sSkemaPivot := winmadmin.pkg_userfirme.GetSkemaPivot(iCodFirma);

 if sSkemaPivot &lt;&gt; &apos;?&apos; then
  sSkemaGrant := sSkemaGrant ||&apos;,&apos;||sSkemaPivot;
 end if;

 execute immediate &apos;CREATE TABLE &apos;||aSaveTable||&apos; AS SELECT * FROM &apos;||aListTable;
 execute immediate &apos;GRANT SELECT ON  &apos;||aSaveTable||&apos; TO &apos;||  sSkemaGrant;

 winmadmin.pkg_userfirme.ActualizareTabConsolidare(pkg_globals.FIRMANAME,aSaveTable);

 return iResult;

end;

PROCEDURE ADD_CONFIG_DINAMIC_COLS(ALISTID IN NUMBER, ALISTVER IN NUMBER, PREFIX IN VARCHAR2, MAXIM IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
  IDX NUMBER(20);
  COD NUMBER(20);
  OLDCOD NUMBER(20);
  ACOL VARCHAR2(200);
  CNT NUMBER (20);
BEGIN
  FOR IDX IN 2..MAXIM LOOP
    ACOL := PREFIX||IDX;
    SELECT COUNT(*) INTO CNT FROM WINMADMIN.LISTCOLS WHERE UPPER(FIELDNAME) = UPPER(ACOL) AND
                                                           LISTID = ALISTID AND
                                                           LISTVER = ALISTVER;
    IF CNT = 0 THEN
      COD := WINMADMIN.PKG_LIST_UTILS.GET_SEQ_NEXTVAL(&apos;WINMADMIN&apos;,&apos;SEQ_LISTCOLS_CODLISTCOLS&apos;);
      begin
        SELECT CODLISTCOLS into OLDCOD FROM WINMADMIN.LISTCOLS WHERE LISTID = ALISTID AND LISTVER = ALISTVER AND UPPER(FIELDNAME) = UPPER(PREFIX)||1;
      exception
        when others then null;
      end;

      INSERT INTO WINMADMIN.LISTCOLS(
        CODLISTCOLS,LISTID,LISTVER,FIELDNR,FIELDNAME,VISIBLE,TOTAL,SEPARATOR,ALIGNMENT,
        COLOR,DECIMALPLACES,WIDTH,CHARWIDTH,STYLES,RIGHTLINE,BOTTOMLINE,FONTNAME,FONTSTYLE,FONTSIZE,FONTCOLOR,
        NUMERICFIELD,CALCULATA,CALCFIELDNAME,CALCEXPRESIE,USERCOLUMN,ALIAS,FIELDTYPE,FIELDSIZE,DISPLAY,OBS,SOLDCOL)
      SELECT
        COD,LISTID,LISTVER,-1,ACOL,&apos;F&apos;,TOTAL,SEPARATOR,ALIGNMENT,
        COLOR,DECIMALPLACES,WIDTH,CHARWIDTH,STYLES,RIGHTLINE,BOTTOMLINE,FONTNAME,FONTSTYLE,FONTSIZE,FONTCOLOR,
        NUMERICFIELD,CALCULATA,CALCFIELDNAME,CALCEXPRESIE,USERCOLUMN,ALIAS,FIELDTYPE,FIELDSIZE,DISPLAY,OBS,SOLDCOL
      FROM WINMADMIN.LISTCOLS
      WHERE LISTID = ALISTID AND LISTVER = ALISTVER AND UPPER(FIELDNAME) = UPPER(PREFIX)||1;

      INSERT INTO WINMADMIN.LISTTITS(
        CODLISTTITS, LISTID, LISTVER,
        TITLENR, ALIGNMENT,CAPTION,COLOR,FONTNAME,FONTSTYLE, FONTSIZE,FONTCOLOR,RIGHTLINE,BOTTOMLINE,PARENT)
      SELECT
        WINMADMIN.PKG_LIST_UTILS.GET_SEQ_NEXTVAL(&apos;WINMADMIN&apos;,&apos;SEQ_LISTTITS_CODLISTTITS&apos;), LISTID, LISTVER,
        TITLENR, ALIGNMENT,CAPTION,COLOR,FONTNAME,FONTSTYLE, FONTSIZE,FONTCOLOR,RIGHTLINE,BOTTOMLINE,COD
      FROM WinMAdmin.ListTits lt
      WHERE lt.Parent = OLDCOD and lt.ListID = aListID and lt.ListVer = aListver;
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE GOLESTE_PARAM IS
BEGIN
  DELETE TMP_LIST_PARAMS;
  v_IdxParamLista := 0;
END;

PROCEDURE ADAUGA_PARAM (pDenumire VARCHAR2, pValoare VARCHAR2) IS
BEGIN
  v_IdxParamLista := v_IdxParamLista + 1;
  INSERT INTO TMP_LIST_PARAMS (IDX, DENUMIRE, VALOARE)
  VALUES (v_IdxParamLista, pDenumire, pValoare);
END;

PROCEDURE ADAUGA_PARAM_EXT (pTable VARCHAR2, pField VARCHAR2, pValField NUMBER, pPrefix VARCHAR2 default &apos;&apos;) IS
  sSql     CLOB;
  sSqlP    CLOB;
  vNr      NUMBER := 0;
  vNrX     NUMBER := 0;
  vTry     NUMBER;
  sDen     VARCHAR2(200);
  sDisplay VARCHAR2(1000);
  vCount   NUMBER;
  sZec     VARCHAR2(20);
BEGIN
  FOR vRec IN (
    SELECT utc.column_name, c1.numecamp, Coalesce(c1.CAPTION, c1.NUMECAMP) den, Coalesce(c1.nomlink, 0) nomlink,
           &apos;T.&apos;||REPLACE(c1.lookupdisplay, &apos;;&apos;, &apos;||&apos;&apos;;&apos;&apos;||T.&apos;) lookupdisplay, c1.tip, coalesce(c1.zecimale,0) zecimale
    FROM cfgtables c
      INNER JOIN cfgtables1 c1 ON c1.CodCfgTable = c.CodCfgTable
      LEFT  JOIN user_tab_columns utc ON utc.table_name = Upper(c.numetabela) AND utc.column_name = Upper(c1.numecamp)
    WHERE Upper(c.numetabela) = Upper(pTable)
      AND utc.column_name is not null
  ) LOOP
    sDisplay := Upper(vRec.lookupdisplay);
    if vRec.nomlink = 5 then
      sDisplay := replace(sDisplay, &apos;T.ADRESA&apos;,&apos;GETADRESA(T.SECTOR,T.STRADA,T.NR1,T.NR2,T.BLOC,T.SCARA,T.ETAJ,T.APART,T.CODPOSTAL)&apos;);
      sDisplay := replace(sDisplay, &apos;T.DENSEDIU&apos;,&apos;T.OBS&apos;);
      sDisplay := replace(sDisplay, &apos;T.LOCALITATE&apos;,&apos;T.IDSEDIU&apos;);
    end if;
     if vRec.nomlink = 1 then
      sDisplay := replace(sDisplay, &apos;T.DENOBIECT&apos;,&apos;T.DENUMIRE&apos;);
    end if;
    sSql := sSql ||&apos;,

      &apos;;
    IF vRec.column_name IS NULL THEN
      sSql := sSql ||&apos;NULL AS &apos;||vRec.numecamp;
    ELSE
      vNrX := vNrX + 1;
      CASE vRec.nomlink
        --cfgtables1 -&gt; nomlink/lookupdisplay
        WHEN 1 /*Articole*/     THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM nartobj t WHERE t.codobiect = x.&apos;||vRec.numecamp||&apos;)&apos;;
      --WHEN 2 /*Parteneri*/    THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM npart t WHERE t.codpart = x.&apos;||vRec.numecamp||&apos;)&apos;;
        WHEN 2 /*Parteneri*/    THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM (SELECT p.*, f.codfiscal FROM npart p LEFT JOIN npartcodfisc f ON f.codpart = p.codpart AND f.principal = 1) t WHERE t.codpart = x.&apos;||vRec.numecamp||&apos;)&apos;;
        WHEN 3 /*Personal*/     THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM npers t WHERE t.codpers = x.&apos;||vRec.numecamp||&apos;)&apos;;
        WHEN 4 /*Contract cli*/ THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM contract t WHERE t.codcontract = x.&apos;||vRec.numecamp||&apos;)&apos;;
        WHEN 5 /*Sedii part*/   THEN sSql := sSql||&apos;(SELECT &apos;||sdisplay ||&apos; FROM nagenda t WHERE t.codagenda = x.&apos;||vRec.numecamp||&apos;)&apos;;
        ELSE sSql := sSql||&apos;x.&apos;||vRec.numecamp;
      END CASE;
      sSql := sSql ||&apos; AS &apos;||vRec.numecamp;
    END IF;

    vNr  := vNr + 1;
    vTry := 0;
    LOOP -- Stef - sa nu fie doi parametrii cu aceeasi denumire
      sDen := pPrefix||vRec.numecamp||CASE WHEN vTry &gt; 0 THEN &apos; EXT_&apos;||vTry END;
      SELECT Count(1) INTO vCount FROM TMP_LIST_PARAMS WHERE DENUMIRE = sDen;
      EXIT WHEN vCount = 0;
      vTry := vTry + 1;
    END LOOP;

    IF VREC.TIP = &apos;N&apos; AND VREC.NOMLINK = 0 THEN
      IF VREC.ZECIMALE &gt; 0 THEN
        sZec := &apos;&apos;;
        for idx in 1..VREC.ZECIMALE loop
          sZec := sZec||&apos;9&apos;;
        end loop;
        sSqlP := sSqlP ||&apos;
        pkg_list_Struct.ADAUGA_PARAM(&apos;&apos;&apos;||sDen||&apos;&apos;&apos;,TO_CHAR(TO_NUMBER(COALESCE(vRec.&apos;||vRec.COLUMN_NAME||&apos;,0)),&apos;&apos;fm9G999G999G990D&apos;||sZec||&apos;&apos;&apos;, &apos;&apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;&apos;&apos;,.&apos;&apos;&apos;&apos;&apos;&apos;));&apos;;
      ELSE
        sSqlP := sSqlP ||&apos;
        pkg_list_Struct.ADAUGA_PARAM(&apos;&apos;&apos;||sDen||&apos;&apos;&apos;,TO_CHAR(TO_NUMBER(COALESCE(vRec.&apos;||vRec.COLUMN_NAME||&apos;,0)),&apos;&apos;fm9G999G999G990&apos;&apos;, &apos;&apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;&apos;&apos;,.&apos;&apos;&apos;&apos;&apos;&apos;));&apos;;
      END IF;
    ELSE
      sSqlP := sSqlP ||&apos;
      pkg_list_Struct.ADAUGA_PARAM(&apos;&apos;&apos;||sDen||&apos;&apos;&apos;,vRec.&apos;||vRec.COLUMN_NAME||&apos;);&apos;;
    END IF;
  END LOOP;

  sSQL := &apos;BEGIN
  FOR vRec IN (
    SELECT &apos;||SUBSTR(sSQL, 2)||&apos;
    FROM &apos;||CASE WHEN vNrX = 0 THEN &apos;dual&apos; ELSE &apos;(SELECT &apos;||pValField||&apos; cod FROM dual) d LEFT JOIN &apos;||pTable||&apos; x ON x.&apos;||pField||&apos; = d.cod&apos; END||&apos;
  ) LOOP&apos;||
    sSqlP ||&apos;
  END LOOP;
  END;&apos;;

  IF (vNr &gt; 0) THEN
    LIST_EXECUTE_IMMEDIATE(sSQL, 0, 0);
  END IF;
END;

FUNCTION  GET_PARAM RETURN crs IS
  cResult crs;
begin
  OPEN cResult for SELECT DENUMIRE, VALOARE FROM TMP_LIST_PARAMS ORDER BY IDX;
  RETURN cResult;
END;

function GetCursorForCols(aSQL in varchar2) return crs is
cResult crs;
begin
  open cResult for &apos;select * from (&apos;||aSQL||&apos;) where 1 = 0&apos;;
  return cResult;
end;

PROCEDURE GeneratePIV (tmpName IN VARCHAR2, CMD IN VARCHAR2, UserName IN VARCHAR2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
  S VARCHAR2(1000);
  Tmp VARCHAR2(100);
  sDML VARCHAR2(1000);
BEGIN
  Tmp := TmpName || &apos;PIV&apos;;
	IF TmpExists(tmp) = 1 THEN
		EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||tmp;
		EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||tmp;
	END IF;

  sDML := &apos;CREATE GLOBAL TEMPORARY TABLE &apos;|| tmp ||&apos; ON COMMIT PRESERVE ROWS AS (SELECT * FROM &apos; || tmpName||&apos; WHERE 1=0)&apos;;
	EXECUTE IMMEDIATE sDML;

	sDML := getDMLGrant(tmp,UserName);
	EXECUTE IMMEDIATE sDML;

	EXECUTE IMMEDIATE CMD;
  Commit;
  --delete x;
  --insert into x(test) values(cmd);
END;


END pkg_list_Struct;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LIST_UTILFISACONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BAD73946B57B2403E7D9605226E1DFC5387A8D0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_list_utilfisacont IS

  TBJCONST       number :=  100;
  TBJART         number :=  200;
  TBJPART        number :=  300;
  TBJPERS        number :=  400;
  TBJBANK        number :=  500;
  TBJFILIAL      number :=  600;
  TBJCONT        number :=  700;
  TBJAVANS       number :=  800;
  TBJRETURAVANS  number :=  900;
  TBJVAMA        number := 1000;
  TBJINKIDERI    number := 1100;
  TBJCMD1        number := 1200;

  TCJCONST       NUMBER :=  100;
  TCJTVA         NUMBER :=  200;
  TCJIOART       NUMBER :=  300;
  TCJIOPART      NUMBER :=  400;
  TCJIOPERS      NUMBER :=  500;
  TCJIOBANK      NUMBER :=  600;
  TCJFILIAL      NUMBER :=  700;
  TCJCONT        NUMBER :=  800;
  TCJTAXE        NUMBER :=  900;
  TCJNGEST1      NUMBER := 1000;

FUNCTION GET_BAZA (pTipBaza IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  RETURN CASE
           WHEN pTipBaza = TBJCONST    THEN &apos;CONST1&apos;
           WHEN pTipBaza = TBJART      THEN &apos;NARTOBJ&apos;
           WHEN pTipBaza IN (TBJPART, TBJAVANS, TBJRETURAVANS, TBJVAMA)
                                       THEN &apos;NPART&apos;
           WHEN pTipBaza = TBJPERS     THEN &apos;NPERS&apos;
           WHEN pTipBaza = TBJBANK     THEN &apos;NBANK&apos;
           WHEN pTipBaza = TBJFILIAL   THEN &apos;NSUBUNIT&apos;
           WHEN pTipBaza = TBJCONT     THEN &apos;NCONT&apos;
           WHEN pTipBaza = TBJINKIDERI THEN &apos;INCHIDERI&apos;
           WHEN pTipBaza = TBJCMD1     THEN &apos;COMANDA1&apos;
         END;
END;

FUNCTION GET_INFOBAZA (pTipBaza IN NUMBER, pCodBaza IN NUMBER, pIndexLocal IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2 IS
  vResult VARCHAR2(250);
BEGIN
  IF    pTipBaza = TBJCONST    THEN vResult := PKG_CATEGCONST.GETVALCONSTBYCODE(pCodBaza, pAn, pLuna);
  ELSIF pTipBaza = TBJART      THEN SELECT denumire INTO vResult FROM nartobj WHERE codobiect = pCodBaza;
  ELSIF pTipBaza IN (TBJPART, TBJAVANS, TBJRETURAVANS, TBJVAMA)
                               THEN SELECT den_part INTO vResult FROM npart WHERE codpart = pCodBaza;
  ELSIF pTipBaza = TBJPERS     THEN SELECT numeprenume(nume,prenume) INTO vResult FROM npers WHERE codpers = pCodBaza;
  ELSIF pTipBaza = TBJBANK     THEN SELECT denumire INTO vResult FROM nbank WHERE codbank = pCodBaza;
  ELSIF pTipBaza = TBJFILIAL   THEN SELECT den_subunit INTO vResult FROM nsubunit WHERE codsubunit = pCodBaza;
  ELSIF pTipBaza = TBJCONT     THEN SELECT simbol INTO vResult FROM ncont WHERE codcont = pCodBaza;
  ELSIF pTipBaza = TBJINKIDERI THEN vResult := &apos;&apos;;
  ELSIF pTipBaza = TBJCMD1     THEN SELECT codcomanda1 INTO vResult FROM comanda1 WHERE codcomanda1 = pIndexLocal;
  END IF;
  RETURN vResult;
END;

FUNCTION GET_DESCR (pTipCont IN NUMBER) RETURN VARCHAR2 IS
BEGIN
  RETURN CASE
           WHEN pTipCont = TCJCONST  THEN &apos;CONST1&apos;
           WHEN pTipCont = TCJTVA    THEN &apos;NTVA1&apos;
           WHEN pTipCont = TCJIOART  THEN &apos;IOART1&apos;
           WHEN pTipCont = TCJIOPART THEN &apos;IOPART1&apos;
           WHEN pTipCont = TCJIOPERS THEN &apos;IOPERS1&apos;
           WHEN pTipCont = TCJIOBANK THEN &apos;IOBANK1&apos;
           WHEN pTipCont = TCJFILIAL THEN &apos;IOFILIAL1&apos;
           WHEN pTipCont = TCJCONT   THEN &apos;NCONT&apos;
           WHEN pTipCont = TCJTAXE   THEN &apos;NTAXE1&apos;
           WHEN pTipCont = TCJNGEST1 THEN &apos;NGEST1&apos;
         END;
END;

FUNCTION GET_INFODESCR (pTipCont IN NUMBER, pCodDescr IN NUMBER, pAn IN NUMBER, pLuna IN NUMBER) RETURN VARCHAR2 IS
  vResult VARCHAR2(250);
BEGIN
  IF    pTipCont = TCJCONST  THEN vResult := PKG_CATEGCONST.GETVALCONSTBYCODE(pCodDescr, pAn, pLuna);
  ELSIF pTipCont = TCJTVA    THEN vResult := &apos;NTVA1&apos;;
  ELSIF pTipCont = TCJIOART  THEN vResult := &apos;IOART1&apos;;
  ELSIF pTipCont = TCJIOPART THEN vResult := &apos;IOPART1&apos;;
  ELSIF pTipCont = TCJIOPERS THEN vResult := &apos;IOPERS1&apos;;
  ELSIF pTipCont = TCJIOBANK THEN vResult := &apos;IOBANK1&apos;;
  ELSIF pTipCont = TCJFILIAL THEN vResult := &apos;IOFILIAL1&apos;;
  ELSIF pTipCont = TCJCONT   THEN SELECT simbol INTO vResult FROM ncont WHERE codcont = pCodDescr;
  ELSIF pTipCont = TCJTAXE   THEN vResult := &apos;NTAXE1&apos;;
  ELSIF pTipCont = TCJNGEST1 THEN vResult := &apos;NGEST1&apos;;
  END IF;
  RETURN vResult;
END;

PROCEDURE UMPLE_TMP_LST_JURNAL1 (p_Plan IN NUMBER, p_LunaIni IN NUMBER, p_LunaFin IN NUMBER, p_SubCurenta IN NUMBER, p_ListId IN NUMBER) IS
BEGIN
  UPDATE distribchelt SET datacreare = last_day(to_date(to_char(an,&apos;fm0000&apos;)||to_char(luna,&apos;fm00&apos;), &apos;yyyymm&apos;)) WHERE datacreare IS NULL;
  DELETE tmp_lst_jurnal1;

  INSERT INTO tmp_lst_jurnal1 (
    codjurnal1, coddoc, tipdoc, indexlocal,
    codbazad, tipbazad, icontbazad, coddescrd, icontd, tipcontd, analiticcontd,
    codbazac, tipbazac, icontbazac, coddescrc, icontc, tipcontc, analiticcontc,
    gest, valoare, valoarev, obs, an, luna, dirty, subunitatea, datadoc, document, codcentru, valoaregrup, codanalizanod, valoare_ifrs, valoarev_ifrs, codintr1, codobligpif, codnc1
  )
  SELECT
    j1.codjurnal1, j1.coddoc, j1.tipdoc, j1.indexlocal,
    j1.codbazad, j1.tipbazad, j1.icontbazad, j1.coddescrd, j1.icontd, j1.tipcontd, j1.analiticcontd,
    j1.codbazac, j1.tipbazac, j1.icontbazac, j1.coddescrc, j1.icontc, j1.tipcontc, j1.analiticcontc,
    j1.gest, j1.valoare, j1.valoarev, j1.obs, j1.an, j1.luna, j1.dirty, j1.subunitatea, j1.datadoc, j1.document, j1.codcentru, j1.valoaregrup, j1.codanalizanod, j1.valoare_ifrs, j1.valoarev_ifrs,
    cv.codintr1, cv.codobligpif, cv.codnc1
  FROM jurnal1 j1
    LEFT JOIN cheltavans cv ON cv.codcheltavans = j1.coddoc AND j1.tipdoc = 52
  WHERE j1.an*12+j1.luna BETWEEN p_LunaIni AND p_LunaFin
    AND Decode(p_SubCurenta,1,j1.subunitatea,p_SubCurenta) = j1.subunitatea;

  UPDATE tmp_lst_jurnal1 j1
  SET BazaD      = pkg_list_utilfisacont.GET_BAZA (TipBazaD),
      InfoBazaD  = pkg_list_utilfisacont.GET_INFOBAZA (TipBazaC, CodBazaC, IndexLocal, An, Luna),
      BazaC      = pkg_list_utilfisacont.GET_BAZA (TipBazaC),
      InfoBazaC  = pkg_list_utilfisacont.GET_INFOBAZA (TipBazaC, CodBazaC, IndexLocal, An, Luna),
      DescrD     = pkg_list_utilfisacont.GET_DESCR (TipContD),
      InfoDescrD = pkg_list_utilfisacont.GET_INFODESCR (TipContD, CodDescrD, An, Luna),
      DescrC     = pkg_list_utilfisacont.GET_DESCR (TipContC),
      InfoDescrC = pkg_list_utilfisacont.GET_INFODESCR (TipContC, CodDescrC, An, Luna),
      CodContd   = pkg_jurnal.GETCONTFORJURNAL(CodDescrD, IcontD, TipContD, AnaliticContD, An, Luna),
      CodContc   = pkg_jurnal.GETCONTFORJURNAL(CodDescrC, IcontC, TipContC, AnaliticContC, An, Luna);

  IF p_ListId IN (332) THEN
    --VAD CA ASTA ERA DOAR IN pkg_list_base_realgest3 - 332  /Realizari pe gestiuni - analitic
    --:1:2:3 TREBUIE SI PT pkg_list_base_fisacont3 -327 /Registru jurnal analitic
    DELETE tmp_lst_jurnal1 j1
    WHERE NOT EXISTS (select codcont from ncont where codcont = j1.codcontd and clasa in (6,7))
      AND NOT EXISTS (select codcont from ncont where codcont = j1.codcontc and clasa in (6,7));
  END IF;

  UPDATE tmp_lst_jurnal1 j1
  SET (articol, codobiect, cant, obslinie, coddoc1, userid) =
      (SELECT obj.denumire, i1.codobiect, i1.cant, i1.obs, i1.codintr1, i.userid 
       FROM intrari1 i1
         INNER JOIN intrari i ON i.codintr = i1.codintr
         LEFT JOIN nartobj obj ON i1.codobiect = obj.codobiect
       WHERE i1.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc in (1,2,3,4,6,7,9);

  UPDATE tmp_lst_jurnal1 j1
  SET (articol, codobiect, cant, obslinie, coddoc1, userid) =
       (SELECT obj.denumire, i1.codobiect, i1.cant, i1.obs, i1.codintr1, i.userid
        FROM dvi1
          INNER JOIN intrari1 i1 on i1.codintr1 = dvi1.codintr1
          INNER JOIN intrari i ON i.codintr = i1.codintr
          LEFT JOIN nartobj obj on i1.codobiect = obj.codobiect
        WHERE dvi1.coddvi1 = j1.indexlocal)
  WHERE j1.tipdoc in (5);

  UPDATE tmp_lst_jurnal1 j1
  SET (articol, codobiect, cant, userid)  = 
      (SELECT obj.denumire, t1.codobiect, t1.cant, t.userid 
       FROM transf1 t1
         INNER JOIN transf t ON t.codtransf = t1.codtransf
         left join nartobj obj on t1.codobiect = obj.codobiect
       WHERE t1.codtransf1 = j1.indexlocal )
  where j1.tipdoc IN (12,13);

  UPDATE tmp_lst_jurnal1 j1
  SET (articol, codobiect, cant, obslinie, coddoc1, userid) =
      (SELECT obj.denumire, i1.codobiect, i1.cant, i1.obs, i1.codies1, i.userid
       FROM iesiri1 i1
         INNER JOIN iesiri i ON i.codies = i1.codies
         LEFT JOIN nartobj obj on i1.codobiect = obj.codobiect
       WHERE i1.codies1 = j1.indexlocal)
  WHERE j1.tipdoc in (14,15,16,19,20,21,22,23,24,26);

  UPDATE tmp_lst_jurnal1 j1
  SET (coddoc1, userid) = (SELECT t1.codtrezor1, t1.userid FROM trezor1 t1 WHERE t1.codtrezor1 = j1.indexlocal)
  WHERE j1.tipdoc in (29,30,31,33);

  UPDATE tmp_lst_jurnal1 j1
  SET (coddoc1, userid)  = (SELECT nc1.codnc1, nc.userid FROM nc1 inner join nc ON nc.codnc = nc1.codnc where nc1.codnc1 = j1.indexlocal )
  WHERE j1.tipdoc = 35;

  UPDATE tmp_lst_jurnal1 j1 
  SET userid = PKG_LIST_BASE_UTILS.GetUserDoc(j1.coddoc, j1.tipdoc)
  WHERE userid IS NULL;

  UPDATE tmp_lst_jurnal1 j1 SET pret = valoare/cant WHERE j1.cant &lt;&gt; 0;
  -----------------------------
  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM intrlink l
         INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE l.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc in (1,2,4)
    AND EXISTS (SELECT l.codliniecomanda FROM intrlink l WHERE l.codintr1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT i.prefixdoc||i.nrdoc||&apos;/&apos;||i.datadoc, i.moneda, i.partener
       FROM intrasteptlink l
         INNER JOIN intrari1 i1 on i1.codintr1 = l.codliniefactura
         INNER JOIN intrari i on i1.codintr = i.codintr
       WHERE l.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc IN (2)
    AND EXISTS (SELECT l.codliniefactura FROM intrasteptlink l WHERE l.codintr1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT i.prefixdoc||i.nrdoc||&apos;/&apos;||i.datadoc, i.moneda, i.partener
       FROM intrlink l
         INNER JOIN intrari1 i1 on i1.codintr1 = l.codlinieaviz
         INNER JOIN intrari i on i1.codintr = i.codintr
       WHERE l.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc IN (9)
    AND EXISTS (SELECT l.codlinieaviz FROM intrlink l WHERE l.codintr1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM intrlink l
         INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE l.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc IN (9)
    AND EXISTS (SELECT l.codliniecomanda FROM intrlink l WHERE l.codintr1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT i.prefixdoc||i.nrdoc||&apos;/&apos;||i.datadoc, i.moneda, i.partener
       FROM dvi1
         INNER JOIN intrari1 ii1 ON dvi1.codintr1 = ii1.codintr1
         INNER JOIN intrlink l ON ii1.codintr1 = l.codintr1
         INNER JOIN intrari1 i1 ON i1.codintr1 = l.codlinieaviz
         INNER JOIN intrari i ON i1.codintr = i.codintr
       WHERE dvi1.coddvi1 = j1.indexlocal)
  WHERE j1.tipdoc IN (5)
    AND EXISTS (SELECT l.codlinieaviz FROM dvi1 INNER JOIN intrari1 ii1 on dvi1.codintr1 = ii1.codintr1 INNER JOIN intrlink l on ii1.codintr1 = l.codintr1 WHERE dvi1.coddvi1 = j1.indexlocal and l.codlinieaviz &gt; 0);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM dvi1
         INNER JOIN intrari1 ii1 on dvi1.codintr1 = ii1.codintr1
         INNER JOIN intrlink l on ii1.codintr1 = l.codintr1
         INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE dvi1.coddvi1 = j1.indexlocal)
  WHERE j1.tipdoc IN (5)
    AND EXISTS (SELECT l.codliniecomanda FROM dvi1 INNER JOIN intrari1 ii1 on dvi1.codintr1 = ii1.codintr1 INNER JOIN intrlink l on ii1.codintr1 = l.codintr1 WHERE dvi1.coddvi1 = j1.indexlocal and l.codliniecomanda &gt; 0);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM intrari1 i1
         INNER JOIN comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE i1.codintr1 = j1.indexlocal)
  WHERE j1.tipdoc = 7
    AND EXISTS (SELECT c1.codcomanda1 FROM comanda1 c1 INNER JOIN intrari1 i1 on c1.codcomanda1 = i1.codcmdint1 WHERE i1.codintr1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM ieslink l
         INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE l.codies1 = j1.indexlocal)
  WHERE j1.tipdoc in (19,20,21)
    AND EXISTS (SELECT l.codliniecomanda from ieslink l where l.codies1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT i.prefixdoc||i.nrdoc||&apos;/&apos;||i.datadoc, i.moneda, i.partener
       FROM ieslink l
         INNER JOIN iesiri1 i1 on i1.codies1 = l.codlinieaviz
         INNER JOIN iesiri i on i1.codies = i.codies
       WHERE l.codies1 = j1.indexlocal)
  WHERE j1.tipdoc in (26,22)
    AND EXISTS (SELECT l.codlinieaviz from ieslink l where l.codies1 = j1.indexlocal);

  UPDATE tmp_lst_jurnal1 j1
  SET (DocLegatura, CodMoneda, CodPart) =
      (SELECT c.prefixdoc||c.nrdoc||&apos;/&apos;||c.datadoc, c.moneda, c.partener
       FROM iesiri1 i1
         INNER JOIN comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       WHERE i1.codies1 = j1.indexlocal)
  WHERE j1.tipdoc = 24
    AND EXISTS (SELECT c1.codcomanda1 FROM comanda1 c1 INNER JOIN iesiri1 i1 on c1.codcomanda1 = i1.codcmdint1 WHERE i1.codies1 = j1.indexlocal);

  ---------------------------------
  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, codpart, codmonedadoc, codagenda, cod_codfiscal, valdoc, tvadoc, curs, codauto) =
      (SELECT i.datacreare, i.partener, i.moneda, i.codlocatie, i.codfiscal, i.valdoc, i.tvadoc, i.curs, i.codauto FROM intrari i WHERE i.codintr = j1.coddoc)
  WHERE j1.tipdoc IN (1,2,3,4,5,6,7,9);

  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, valdoc, tvadoc) = (SELECT t.datacreare, t.valdoc, t.tvadoc FROM transf t WHERE t.codtransf = j1.coddoc)
  WHERE j1.tipdoc in (12,13);

  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, codpart, codmonedadoc, codagenda, cod_codfiscal, valdoc, tvadoc, curs, codauto) =
      (SELECT i.datacreare, i.partener, i.moneda, i.codlocatie, i.codfiscal, i.valdoc, i.tvadoc, i.curs, i.codauto FROM iesiri i WHERE i.codies = j1.coddoc)
  WHERE j1.tipdoc in (14,15,16,19,20,23,24,26);

  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, codpart, codmonedadoc) = (SELECT c.datacreare, c.partener, c.moneda FROM contract c WHERE c.codcontract = j1.coddoc)
  WHERE j1.tipdoc in (25);

  UPDATE tmp_lst_jurnal1 j1
  SET datacreare = (SELECT c.datacreare FROM compens c WHERE c.codcompens = j1.coddoc)
  WHERE j1.tipdoc IN (28);

  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, codmonedadoc, obslinie, valdoc, tvadoc, curs, codauto) =
      (SELECT t.datacreare, t.monedapers, t1.obs, t1.valdoc, sum(g.tva), t1.curs, min(o.codnparcaut)
       FROM trezor1 t1
         INNER JOIN trezor t on t.codtrezor = t1.codtrezor
         inner JOIN general g on g.coddoc = t1.codtrezor1 AND g.tipdoc = t.tipdoc
         inner join obligpif o on o.codgeneral = g.codgeneral
       WHERE t1.codtrezor = j1.coddoc and t1.codtrezor1 = j1.indexlocal
       group by t.datacreare, t.monedapers, t1.obs, t1.valdoc, t1.curs
       )
  WHERE j1.tipdoc IN (29,30,31,33);

  UPDATE tmp_lst_jurnal1 j1
  SET (datacreare, obslinie, codmonedadoc, valdoc, curs) =
      (SELECT nc.datacreare, nc1.obs, nc.moneda, nc.valoare, nc.curs
       FROM nc1 INNER JOIN nc on nc.codnc = nc1.codnc
       WHERE nc.codnc = j1.coddoc AND j1.indexlocal = nc1.codnc1)
  WHERE j1.tipdoc IN (35);

  UPDATE tmp_lst_jurnal1 j1
  SET datacreare = (select dc.datacreare from distribchelt dc where dc.coddistribchelt = j1.coddoc)
  WHERE j1.tipdoc in (76);

  --cheltuieli in avans
  --intrari
  UPDATE tmp_lst_jurnal1 j1
  SET articol = (SELECT obj.denumire
                 FROM intrari1 i1
                   INNER JOIN nartobj obj on i1.codobiect = obj.codobiect
                   INNER JOIN cheltavans cv on cv.codintr1 = i1.codintr1
                 WHERE j1.coddoc = cv.codcheltavans and nvl(cv.codintr1,0) &gt; 0)
  WHERE j1.tipdoc = 52 and j1.codintr1 &gt; 0;
  --obligpif
  UPDATE tmp_lst_jurnal1 j1
  SET articol = (SELECT CASE WHEN O.SEMNIFICATIE = 900 THEN &apos;Direct pe cheltuieli(TVA)&apos; ELSE &apos;Datorii, taxe, impozite&apos; END
                 FROM obligpif o INNER JOIN cheltavans cv on cv.codobligpif = o.codobligpif
                 WHERE j1.coddoc = cv.codcheltavans and o.semnificatie in (900,950) and nvl(cv.codobligpif,0) &gt; 0 )
  WHERE j1.tipdoc = 52 AND j1.codobligpif &gt; 0;
  --nc
  UPDATE tmp_lst_jurnal1 j1
  SET articol = (SELECT &apos;Chelt Avans din NC &apos; FROM nc1 INNER JOIN cheltavans cv on cv.codnc1 = nc1.codnc1 WHERE j1.coddoc = cv.codcheltavans and nvl(cv.codnc1,0) &gt; 0)
  WHERE j1.tipdoc = 52 and j1.codnc1 &gt; 0;
END;

function GetCodAutoStinse(aCodGeneral in number) return number is
aCodAuto number(20);
begin
  begin
    select
      max(case
        when ies.codies &gt; 0 then ies.codauto
        when i.codintr &gt; 0 then i.codauto
        else 0
      end)
    into aCodAuto
    from obligpif o
         inner join stingere s on s.codstingatorpif = o.codobligpif
         inner join obligpif os on s.codstinspif = os.codobligpif
         inner join general g on g.codgeneral = os.codgeneral
         left join iesiri ies on g.coddoc = ies.codies and g.tipdoc = ies.tipdoc
         left join intrari i on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
    where o.codgeneral = aCodGeneral;
  exception when others then aCodAuto := 0;
  end;
  return aCodAuto;
end;

function GetDCJurnal(aCodJurnal in number) return timestamp is
Rez timestamp;
begin
  begin
    select
      case
        when j.tipdoc in (1,2,3,4,5,6,7,9) then (SELECT i.datacreare FROM intrari i WHERE i.codintr = j.coddoc)
        when j.tipdoc in (12,13) then (SELECT t.datacreare FROM transf t WHERE t.codtransf = j.coddoc)
        when j.tipdoc in (14,15,16,19,20,23,24,26) then (SELECT i.datacreare FROM iesiri i WHERE i.codies = j.coddoc)
        when j.tipdoc in (25) then (SELECT c.datacreare FROM contract c WHERE c.codcontract = j.coddoc)
        when j.tipdoc in (28) then (SELECT c.datacreare FROM compens c WHERE c.codcompens = j.coddoc)
        when j.tipdoc in (29,30,31,33) then (SELECT t.datacreare
                                             FROM trezor1 t1
                                               INNER JOIN trezor t on t.codtrezor = t1.codtrezor
                                               LEFT JOIN general g on g.coddoc = t1.codtrezor1 AND g.tipdoc = t.codtrezor
                                             WHERE t1.codtrezor = j.coddoc and t1.codtrezor1 = j.indexlocal)
        when j.tipdoc in (35) then (SELECT nc.datacreare
                                    FROM nc1
                                         INNER JOIN nc on nc.codnc = nc1.codnc
                                    WHERE nc.codnc = j.coddoc AND j.indexlocal = nc1.codnc1)
        when j.tipdoc in (76) then (select dc.datacreare from distribchelt dc where dc.coddistribchelt = j.coddoc)
      end
    into Rez
    from jurnal j
    where j.codjurnal = aCodJurnal;
  exception when others then Rez := null;
  end;
  return Rez;
end;

function GetPartJurnal(aCodJurnal in number) return number is
Rez number(20);
begin
  begin
    select
      case
        when j.tipdoc in (1,2,3,4,5,6,7,9) then (SELECT i.partener FROM intrari i WHERE i.codintr = j.coddoc)
        when j.tipdoc in (14,15,16,19,20,23,24,26) then (SELECT i.partener FROM iesiri i WHERE i.codies = j.coddoc)
        when j.tipdoc in (25) then (SELECT c.partener FROM contract c WHERE c.codcontract = j.coddoc)
        when j.tipdoc in (29,30,31,33) then (SELECT t1.codpart
                                             FROM trezor1 t1
                                               INNER JOIN trezor t on t.codtrezor = t1.codtrezor
                                               LEFT JOIN general g on g.coddoc = t1.codtrezor1 AND g.tipdoc = t.codtrezor
                                             WHERE t1.codtrezor = j.coddoc and t1.codtrezor1 = j.indexlocal and t1.obiecttranz in (0,1))
        when j.tipdoc in (35) then (SELECT nc1.codpart
                                    FROM nc1
                                         INNER JOIN nc on nc.codnc = nc1.codnc
                                    WHERE nc.codnc = j.coddoc AND j.indexlocal = nc1.codnc1)
        when j.tipdoc in (28) then (SELECT distinct(case when coalesce(c.partd,0) = 0 then c.partc else coalesce(c.partd,0) end)
                                    FROM compens c
                                    WHERE c.codcompens = j.coddoc)                            
        when j.tipdoc in (46) then (select o.codpart
                                    FROM reg r
                                         inner join reg1 r1 on r.codreg = r1.codreg
                                         inner join obligpif o on o.codobligpif = r1.codobligpif
                                    WHERE r.codreg = j.coddoc and r1.codreg1 = j.indexlocal)
      end
    into Rez
    from jurnal j
    where j.codjurnal = aCodJurnal;
  exception when others then Rez := null;
  end;
  return Rez;
end;

function GetObsDocJurnal(aCodJurnal in number) return varchar2 is
Rez varchar2(500);
begin
  begin
    select
      case
        when j.tipdoc in (1,2,3,4,5,6,7,9) then (SELECT i.obs FROM intrari i WHERE i.codintr = j.coddoc)
        when j.tipdoc in (14,15,16,19,20,23,24,26) then (SELECT i.obs FROM iesiri i WHERE i.codies = j.coddoc)
        when j.tipdoc in (25) then (SELECT c.obs FROM contract c WHERE c.codcontract = j.coddoc)
        when j.tipdoc in (29,30,31,33) then (SELECT t1.obs
                                             FROM trezor1 t1
                                               INNER JOIN trezor t on t.codtrezor = t1.codtrezor
                                               LEFT JOIN general g on g.coddoc = t1.codtrezor1 AND g.tipdoc = t.codtrezor
                                             WHERE t1.codtrezor = j.coddoc and t1.codtrezor1 = j.indexlocal)
        when j.tipdoc in (35) then (SELECT nc.obs
                                    FROM nc1
                                         INNER JOIN nc on nc.codnc = nc1.codnc
                                    WHERE nc.codnc = j.coddoc AND j.indexlocal = nc1.codnc1)
      end
    into Rez
    from jurnal j
    where j.codjurnal = aCodJurnal;
  exception when others then Rez := null;
  end;
  return Rez;
end;

end pkg_list_utilfisacont;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LOCALITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67130FA3DBC2556DB20E22457593648C8AE2303E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LOCALITATI IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codlocalit INTO Tmp FROM NLOCALIT WHERE codlocalit = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NLOCALIT WHERE codlocalit = RecId ;
  NotifyModif(2, RecId, &apos;NLOCALIT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NLOCALIT FIELDS( codlocalit ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NLOCALIT
  INSERT INTO  TMP_NLOCALIT ( codlocalit,den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,CODZONA,LATITUDINE,LONGITUDINE,CODPOSTAL )
    ( SELECT codlocalit,den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,codzona,LATITUDINE,LONGITUDINE,CODPOSTAL
      FROM NLOCALIT WHERE codlocalit = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
-- Master NLOCALIT
    SELECT  codlocalit INTO RecId FROM TMP_NLOCALIT;
    UPDATE NLOCALIT SET ( den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,Codzona, LATITUDINE, LONGITUDINE,CODPOSTAL  )
       = ( SELECT den_localit,tip,nvl(codjudet,0),obs, nvl(CODTARA,0),DENSUP,SIRUTA,nvl(codzona,0), LATITUDINE, LONGITUDINE,CODPOSTAL
          FROM TMP_NLOCALIT )
      WHERE codlocalit = RecId ;
  ELSE  -- INSERT
-- Master NLOCALIT
  SELECT seq_NLOCALIT_codlocalit.NextVal INTO RecId FROM DUAL;
--  insert into t (select recid, den_localit from TMP_NLOCALIT);
  INSERT INTO  NLOCALIT ( codlocalit,den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,Codzona, LATITUDINE, LONGITUDINE, CODPOSTAL  )
 ( SELECT  RecId ,den_localit,tip,nvl(codjudet,0),obs, nvl(CODTARA,0),DENSUP,SIRUTA,nvl(codzona,0), LATITUDINE, LONGITUDINE, CODPOSTAL
     FROM TMP_NLOCALIT  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;NLOCALIT&apos;);
  COMMIT;
END;



END pkg_Localitati; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D56B8447C3CB4C32DE2E48B3C87D1FFB61389A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_LOCMUNCA IS

function GetDisponibilPeZi(aCodLoc in number) return number is
vOre number;
begin
  begin
    select sum(lm1.ore) into vOre
    from locmunca1 lm1
    where lm1.codloc = aCodLoc;     
  exception when others then vOre := 0;
  end;
  return vOre;
end;

procedure SaveGANTT is
RecId number(20);
begin
  for V_Rec in (Select * from TMP_GANTT where CodGantt &gt; 0) loop
	   update Gantt set
       CODCMDPRODMAN = V_REC.CODCMDPRODMAN ,
       CODCOMANDA1   = V_REC.CODCOMANDA1   ,
       DSTART        = V_REC.DSTART        ,
       NSTART        = V_REC.NSTART        ,
       OStart        = V_REC.OSTART        ,
       OStop         = V_REC.OSTOP         ,
       Directie      = V_REC.Directie      ,
       Prioritate    = V_REC.Prioritate    ,
       BLOCAT        = V_REC.BLOCAT        ,
       ORDINE        = V_REC.ORDINE        ,
			 CANT          = V_REC.CANT          
		 where CodGANTT = V_REC.CodGANTT;
     Delete from Gantt1 G1 
		 where G1.CodGantt =  V_REC.Codgantt 
		 and not Exists (Select CodGantt1 from TMP_Gantt1 TG1 where TG1.CodGantt1 = G1.CodGantt1);
	end loop;
  for V_Rec in (Select * from TMP_GANTT where CodGantt &lt; 0) loop
		 RecId := Seq_GANTT.Nextval;
     update TMP_Gantt1 set CodGantt = RecId where CodGantt = v_rec.CodGantt;
		 insert into Gantt (CODGANTT, CODCMDPRODMAN, CODCOMANDA1, DSTART, NSTART, OSTART, OSTOP, Directie, ORDINE, Blocat, Prioritate, CANT)
		 Values(RecId, V_REC.CODCMDPRODMAN, V_REC.CODCOMANDA1, V_REC.DSTART, V_REC.NSTART, V_REC.OSTART, V_REC.OSTOP, V_REC.Directie, V_REC.ORDINE, V_REC.Blocat, V_REC.Prioritate, V_REC.CANT);
	end loop;

	for V_Rec in (Select * from TMP_GANTT1 where CodGantt1 &gt; 0) loop
	   update Gantt1 set
       Deplasare     = V_REC.Deplasare,
       CANT          = V_REC.CANT          
		 where CodGANTT1 = V_REC.CodGANTT1;
	end loop;
  for V_Rec in (Select * from TMP_GANTT1 where CodGantt1 &lt; 0) loop
		 RecId := Seq_GANTT1.Nextval;
		 insert into Gantt1 (CODGANTT1, CODGANTT, Deplasare, CANT)
		 Values(RecId, V_REC.CODGANTT, V_REC.Deplasare, V_REC.CANT);
	end loop;
	
  Delete TMP_GANTT;
  Delete TMP_GANTT1;
	Commit;
end;

procedure PrepareGANTT(aData1 in varchar2, aData2 in varchar2, aDataStart in varchar2, aDataStop in varchar2, aCodProiect in number default 0, aCant in number default 0)  is
aDataEnd    Date;
aDataBegin  Date;
DataStart   Date;
DataStop    Date;
aSapt       number;
aCodLM      number;
i           number;
DataMax     Date;
DataMin     Date;
sSQL        varchar2(2000);
Min1        number; 
Max1        number;
Cifre       number;
Min1c       number; 
Max1c       number;
CifreC      number;
G_SUBUNIT   number(20);
OreMatrita number(10, 3);
OreMasina  number(10, 3);

begin
	G_SUBUNIT := PKG_GLOBALS.GETSUBUNITATE;
  DataMin := TO_DATE(aData1, &apos;DD.MM.YYYY&apos;);
  DataMax := TO_DATE(aData2, &apos;DD.MM.YYYY&apos;);
  DataStart := TO_DATE(aDataStart, &apos;DD.MM.YYYY&apos;);
  DataStop  := TO_DATE(aDataStop, &apos;DD.MM.YYYY&apos;);

	select Min(CodComanda1) , Max(CodComanda1) into Min1, Max1
	from Comanda1 c1 inner join Comanda C on c.codcomanda = c1.codcomanda 
	where TipDoc = 53 and Operat = 1 and Nvl(Inchisa,0) = 0 and C1.RESTACCEPTAT &gt; 0;
  Cifre := Length(To_Char(Max1 - Min1));
	Min1  := Min1 - 1;
	select Min(CodComanda1) , Max(CodComanda1) into Min1c, Max1c
	from Comanda1 c1 inner join Comanda C on c.codcomanda = c1.codcomanda 
	where TipDoc = 18 and Operat = 1 and Nvl(Inchisa,0) = 0 and C1.RESTACCEPTAT &gt; 0;
  CifreC := Length(To_Char(Max1c - Min1c));
	Min1c := Min1c - 1;

  Delete TMP_CMDGANTT;
  if aCodProiect &gt; 0 then
    Insert into TMP_CMDGANTT
    SELECT         
         PN.CODPROIECTNOD codcomanda1,
         PN.CODPROIECT codcomanda,
         PN.codreteta, 
         0 Prioritate,
         NULL DataStart,
         NULL Termen,
         ACANT Cantlansat,
         NULL Document, 
         NULL Datadoc,
         o.Denumire DenObiect,
         u.DEN_UM UM,
         uu.DEN_UM Den_UM1,
         Coalesce(lm.codlocdef, Man.codloc) CodLM,
         0 codcmdprodman,
         op.codop CodOperatie,
         &apos;| &apos;||SubStr(PN.Indexparinte, 3, 200)||&apos;=&apos;||o.Denumire||Chr(13)||&apos;| &apos;||Man.nrop||&apos;.&apos;||op.denumire operatie,
         PC.OBS as DenReteta,
         P.codProiect,
         P.Versiune,
         PN.NODORIGINAL NODPARINTE,
         PN.CODPROIECTNOD,
         PN.NIVEL   NivelNod,                         
         PN.POZITIE PozNod,                         
         0 CODCMD1Parinte,                          
         0 codgest,
         NULL den_gest,
         lm.denumire LocMunca,
         Round(Man.tu * case when coalesce(man.fix,0) = 0 then ACANT/Nvl(Man.BPS,1)/ 60 else 1 end, 5) TotalOre,
         Round(Man.tu * case when coalesce(man.fix,0) = 0 then ACANT/Nvl(Man.BPS,1)/ 60 else 1 end, 5) OreGantt,
         case when man.fix &gt; 0 then man.tu else Man.tu/Nvl(Man.BPS,1) end TU,
         Man.NROP NrOper,
         0 CodcomandaCli,
         NULL DocumentCli,
         NULL DataDocCC,
         0 codcomanda1 ,
         NULL DataStartCC,
         NULL TermenCC,
         NULL Den_Part,
         o.Denumire DenProdus, 
         u.den_um UMProdus,
         ACANT cantProdus,
         Man.Incepere IncepereOp,
         PN.Incepere InceperejNod,
         Man.Decalaj DecalajOp,
         PN.Decalaj DecalajNod,
         PN.Indexparinte,
         507,
         man.fix,
         man.codman,
         O.CODOBIECT
    FROM ProiectNod PN
         INNER JOIN prodcomp PC ON PC.codprodcomp = PN.codreteta
         INNER JOIN nartobj o ON o.codobiect = PN.codobiect
         INNER JOIN nart A ON A.CODARTICOL = o.CODARTICOL
         INNER JOIN NUM U ON U.CodUM = A.UM
         Left JOIN NUM UU ON UU.CodUM = A.UM1
         LEFT JOIN Proiect P ON P.Codproiect = PN.CodProiect
         INNER JOIN prodman Man ON Man.CODPRODCOMP = PC.CODPRODCOMP
         LEFT JOIN noper op ON op.codop = Man.codop
         LEFT JOIN locmunca lm ON lm.codloc = Man.codloc
    where PN.CODPROIECT = ACODPROIECT and coalesce(lm.fara_gant,0) = 0;
  else
    Insert into TMP_CMDGANTT
    SELECT         
         CInt1.codcomanda1,
         CInt1.codcomanda,
         CInt1.codreteta, 
         case when coalesce(g.prioritate,0) = 0 then CInt1.Prioritate else coalesce(g.prioritate,0) end Prioritate,
         CInt1.DataStart,
         CInt1.Termen,
         PMAT.cant Cantlansat,
         CInt.PREFIXDOC || CInt.NrDoc ||&apos;,&apos;||LPAD(CInt1.IndexLocal, 3, &apos;0&apos;) Document, CInt.Datadoc,
         o.Denumire DenObiect,
         u.DEN_UM UM,
         uu.DEN_UM Den_UM1,
         CmdPMan.codloc CodLM,
         CmdPMan.codcmdprodman,
         op.codop CodOperatie,
         &apos;| &apos;||SubStr(PN.Indexparinte, 3, 200)||&apos;=&apos;||o.Denumire||Chr(13)||&apos;| &apos;||CmdPMan.nrop||&apos;.&apos;||op.denumire operatie,
         ProdCmp.OBS as DenReteta,
         CCli1.codProiect,
         Pr.Versiune,
         LANS1.NODPARINTE,
         PN.CODPROIECTNOD,
         CInt1.NIVEL   NivelNod,                         
         CInt1.POZITIE PozNod,                         
         LANS1.CODCMD1P CODCMD1Parinte,                          
         g.codgest,
         g.den_gest,
         lm.denumire LocMunca,
         Round(CmdPMan.tu * case when coalesce(CmdPMan.fix,0) = 0 then CInt1.cantacceptat/Nvl(CmdPMan.BPS,1)/60 else 1 end, 5) TotalOre,
         case when coalesce(CmdPMan.fix,0) = 0 then Round(Nvl(G.AreGant, 0) * CInt1.cantacceptat/Nvl(CmdPMan.BPS,1)/60, 5) else 1 end OreGantt,
         case when CmdPMan.fix &gt; 0 then cmdpman.tu else CmdPMan.tu/Nvl(CmdPMan.BPS,1) end TU,
         CmdPMan.NROP NrOper,
         CCli.codcomanda CodcomandaCli,
         CCli.PREFIXDOC || CCli.NrDoc||&apos;,&apos;||LPAD(CCli1.IndexLocal, 3, &apos;0&apos;) DocumentCli,
         CCli.DataDoc DataDocCC,
         CCli1.codcomanda1 ,
         Nvl(CCli1.DataStart,CCli.DataDoc)  DataStartCC,
         CCli1.Termen TermenCC,
         P.Den_Part,
         oc.Denumire DenProdus, uc.den_um UMProdus,
         CCli1.cantacceptat cantProdus,
         PMan.Incepere IncepereOp,
         LANS1.Incepere InceperejNod,
         PMan.Decalaj DecalajOp,
         LANS1.Decalaj DecalajNod,
         PN.Indexparinte,
         CCLI.TIPDOC,
         cmdpman.fix,
         pman.codman,
         O.CODOBIECT
    FROM comanda1 CInt1
    INNER JOIN CMDPRODMAT PMAT ON PMAT.CODCOMANDA1 = CINT1.CODCOMANDA1 AND PMAT.TIP = 0 
    INNER JOIN comanda CInt ON CInt.codcomanda = CInt1.codcomanda
    INNER JOIN Lansare1 LANS1 ON LANS1.CODCMD1 = CInt1.codComanda1
    LEFT  JOIN ProiectNod PN ON PN.CodproiectNod = LANS1.CodProiectNod
    INNER JOIN Lansare0 LANS0 ON LANS0.codLansare0 = LANS1.codLansare0
    INNER JOIN Lansare  LANS  ON LANS .codLansare  = LANS0.codLansare
    INNER JOIN prodcomp ProdCmp ON ProdCmp.codprodcomp = CInt1.codreteta
    INNER JOIN nartobj o ON o.codobiect = CInt1.codobiect
    INNER JOIN nart A ON A.CODARTICOL = o.CODARTICOL
    INNER JOIN NUM U ON U.CodUM = A.UM
    Left JOIN NUM UU ON UU.CodUM = A.UM1
    LEFT JOIN comanda1 CCli1 ON LANS0.CODCMD1 = CCli1.codcomanda1
    LEFT JOIN comanda CCli ON CCli.CODCOMANDA = CCli1.codcomanda
    LEFT JOIN Proiect Pr ON Pr.Codproiect = CCli1.CodProiect
    left JOIN nartobj oc ON oc.codobiect = CCli1.codobiect
    INNER JOIN nart Ac ON Ac.CODARTICOL = oc.CODARTICOL
    INNER JOIN NUM Uc ON Uc.CodUM = Ac.UM
    LEFT JOIN npart p ON p.codpart = CCli.PARTENER
    LEFT JOIN cmdprodman CmdPMan ON CmdPMan.codcomanda1 = CInt1.codcomanda1
    LEFT JOIN prodman PMan ON PMan.CODMAN = CmdPMan.CODMAN
    LEFT JOIN ngest g ON g.codgest = CInt.codgest
    LEFT JOIN noper op ON op.codop = CmdPMan.codop
    LEFT JOIN locmunca lm ON lm.codloc = CmdPMan.codloc
    LEFT JOIN (select distinct CODCMDPRODMAN, 1 AreGant, Prioritate from Gantt) G ON G.CODCMDPRODMAN = CmdPMan.CODCMDPRODMAN
    LEFT JOIN ( select distinct CodComanda1 from Gantt G
		            inner join (select CodGantt, Max(Deplasare) Zile from Gantt1 group by CodGantt) G1 on G.CodGantt = G1.CodGantt
                where DStart between DataMin and DataMax 
							        or
								  		G.DStart + Zile between DataMin and DataMax 
              ) GX ON GX.CODCOMANDA1 = CCli1.CODCOMANDA1
    where CInt.TipDoc = 53 and CInt.Operat = 1 and Nvl(CInt.Inchisa,0) = 0  and PMAT.REST &gt; 0
          and (CCli1.DataStart between DataMin and DataMax OR GX.CodComanda1 is not null)
          AND (G_SUBUNIT = 1 OR (CCLI.SUBUNITATEA = G_SUBUNIT AND CCLI.TIPDOC = 18) OR (CCLI.SUBUNITSURSA = G_SUBUNIT AND CCLI.TIPDOC = 44))
          and coalesce(lm.fara_gant,0) = 0;
  end if;        

	select TRUNC(DataMin,&apos;iw&apos;) , Trunc(TRUNC(DataMax,&apos;iw&apos;) + 6) into aDataBegin, aDataEnd
	from dual; 
	aSapt := To_Number(to_char(aDataEnd,&apos;iw&apos;)); 
  
  umple_tmp_zile(DataStart, DataStop);
	Delete TMP_OREGANTT;
	Delete TMP_OREGANTT1;
  INSERT INTO TMP_OREGANTT1
  WITH
  Recs as	
	 ( SELECT L.CodLoc CodLM, D.Ziua Data from Tmp_Zile D, LocMunca L),
	OLM1 as 
	 (SELECT L.CodLoc CodLM, L1.CodLoc1 CodLM1, Nvl(L1.ORE, G.Ore) Ore
		FROM LocMunca L 
		inner join LocMunca1 L1 on L1.CodLoc = L.CodLoc
		inner join ( Select CodGest, Nvl(NrSchimburi, 0) * Nvl(OreSchimb, 0) Ore from NGEST) G on G.CodGest = L1.CodGest)
	Select To_Number(to_char(Data,&apos;iw&apos;)) Sapt, Data, CodLM, CodLM1, Ore, LM1Activ CateLM1 
  from
	(
	select Recs.CodLM, OLM1.CodLM1, Recs.Data, Nvl(OreLM.Ore, OLM1.Ore) Ore, Case when ORELM.ORE = 0 then 0 else 1 end LM1Activ,  
				 OLM1.Ore OreDef, Case when OreLM.Ore = OLM1.Ore then null else OreLM.Ore end OreExcept 
  from Recs
	     left join OLM1 on OLM1.CodLM = Recs.CodLM
	     left join OreLM on OreLM.DataLM = Recs.Data and OreLM.Codlm1 = OLM1.CodLM1
	);
--asta e tabela care va modifica TMP_OREGANTT
  if aCodProiect = 0 then
		for V in (
				select * from LocMunca2 where DataStart between DataMin and DataMax
																or  DataStop between DataMin and DataMax
																or  (DataStart &lt; DataMin and DataStop &gt; DataMax)
		) loop
			if v.datastart = v.datastop then 
				OreMatrita := Coalesce(v.Orestart,0) + Coalesce(v.orestop,0);
				OreMasina  :=  OreMatrita + Round((Coalesce(v.minuneon,0)+Coalesce(v.minuneoff,0))/60,2);
				update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastart and CODLM1 = v.codloc1;
				update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastart and CODLM1 = v.codloc1asoc;
			else
				OreMatrita := Coalesce(v.Orestart,0);
				OreMasina  :=  OreMatrita + Round(Coalesce(v.minuneon,0)/60,2);
				update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastart and CODLM1 = v.codloc1;
				update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastart and CODLM1 = v.codloc1asoc;
				OreMatrita := Coalesce(v.orestop,0);
				OreMasina  :=  OreMatrita + Round(Coalesce(v.minuneoff,0)/60,2);
				update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastop and CODLM1 = v.codloc1;
				update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastop and CODLM1 = v.codloc1asoc;
				for w in ( select * from TMP_OREGANTT1 
									 where CodLM1 = v.codloc1asoc and Data between v.datastart + 1 and v.Datastop - 1) loop
					OreMasina  :=  Coalesce(w.ORE,0);
					update TMP_OREGANTT1 set ORE = 0          where DATA = w.data and CODLM1 = v.codloc1asoc;
					update TMP_OREGANTT1 set ORE = OreMasina  where DATA = w.data and CODLM1 = v.codloc1;
				end loop;
			end if;
		end loop;
  end if;
	INSERT INTO TMP_OREGANTT
  Select Sapt, Data, CodLM, 0, Sum(Ore) Ore, Sum(CateLM1) CateLM1 from TMP_OREGANTT1 group by CodLM, Data, Sapt;

	aSapt  := -999;
	aCodLM := -999;
	i      :=  0;
	DataStart := null;
	Delete TMP_SAPTGANTT;
	for V_Rec in (Select * from Tmp_Oregantt where Data between aDataBegin and aDataEnd order by CodLM, Data, Sapt) loop
		if v_rec.Sapt &lt;&gt; aSapt or v_rec.CodLM &lt;&gt; aCodLM then 
			aSapt  := v_rec.Sapt;
			aCodLM := v_rec.CodLM; 
			DataStart := V_REC.DATA;
			Insert into TMP_SAPTGANTT(CodLM, Data1, An, Luna, Sapt) values(V_REC.CODLM, V_REC.DATA, Extract(Year from V_REC.DATA), Extract(Month from V_REC.DATA),  v_rec.Sapt);
		end if;
		i := Trunc(V_REC.DATA - DataStart + 1);
    sSQL := &apos;Update TMP_SAPTGANTT set Z&apos;||i||&apos;=&apos;||Nvl(V_REC.ORE, 0)||&apos; WHERE CodLM = &apos;||V_REC.CodLM||&apos; and Sapt = &apos;||V_REC.SAPT;
		EXECUTE IMMEDIATE sSQL;
	end loop;

  Commit;
end;

procedure PrepareTMP_OREGANTT1(aData1 in varchar2, aData2 in varchar2)  is
DataMin   Date;
DataMax    Date;
OreMatrita number(10, 3);
OreMasina  number(10, 3);

begin
  DataMin := TO_DATE(aData1, &apos;DD.MM.YYYY&apos;);
  DataMax := TO_DATE(aData2, &apos;DD.MM.YYYY&apos;);

  umple_tmp_zile(DataMin,DataMax);
  Delete TMP_OREGANTT1;
  INSERT INTO TMP_OREGANTT1
  WITH
  Recs as 
   ( SELECT L.CodLoc CodLM, D.Ziua Data from Tmp_Zile D, LocMunca L),
  OLM1 as 
   (SELECT L.CodLoc CodLM, L1.CodLoc1 CodLM1, Nvl(L1.ORE, G.Ore) Ore
    FROM LocMunca L 
    inner join LocMunca1 L1 on L1.CodLoc = L.CodLoc
    inner join ( Select CodGest, Nvl(NrSchimburi, 0) * Nvl(OreSchimb, 0) Ore from NGEST) G on G.CodGest = L1.CodGest)
  Select To_Number(to_char(Data,&apos;iw&apos;)) Sapt, Data, CodLM, CodLM1, Ore, OreIni CateLM1 
  from
  (
  select Recs.CodLM, OLM1.CodLM1, Recs.Data, Nvl(OreLM.Ore, OLM1.Ore) Ore, Nvl(OreLM.Ore, OLM1.Ore) OreIni,  
         OLM1.Ore OreDef, Case when OreLM.Ore = OLM1.Ore then null else OreLM.Ore end OreExcept 
  from Recs
       left join OLM1 on OLM1.CodLM = Recs.CodLM
       left join OreLM on OreLM.DataLM = Recs.Data and OreLM.Codlm1 = OLM1.CodLM1
  );
--asta e tabela care va modifica TMP_OREGANTT
  for V in (
      select * from LocMunca2 where DataStart between DataMin and DataMax
                              or  DataStop between DataMin and DataMax
                              or  (DataStart &lt; DataMin and DataStop &gt; DataMax)
  ) loop
		-------------------
    if v.datastart = v.datastop then 
      OreMatrita := Coalesce(v.Orestart,0) + Coalesce(v.orestop,0);
      OreMasina  :=  OreMatrita + Round((Coalesce(v.minuneon,0)+Coalesce(v.minuneoff,0))/60,2);
      update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastart and CODLM1 = v.codloc1;
      update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastart and CODLM1 = v.codloc1asoc;
    else
      OreMatrita := Coalesce(v.Orestart,0);
      OreMasina  :=  OreMatrita + Round(Coalesce(v.minuneon,0)/60,2);
      update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastart and CODLM1 = v.codloc1;
      update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastart and CODLM1 = v.codloc1asoc;
      OreMatrita := Coalesce(v.orestop,0);
      OreMasina  :=  OreMatrita + Round(Coalesce(v.minuneoff,0)/60,2);
      update TMP_OREGANTT1 set ORE = ORE + OreMatrita where DATA = v.datastop and CODLM1 = v.codloc1;
      update TMP_OREGANTT1 set ORE = ORE - OreMasina  where DATA = v.datastop and CODLM1 = v.codloc1asoc;
      for w in ( select * from TMP_OREGANTT1 
                 where CodLM1 = v.codloc1asoc and Data between v.datastart + 1 and v.Datastop - 1) loop
        OreMasina  :=  Coalesce(w.ORE,0);
        update TMP_OREGANTT1 set ORE = 0          where DATA = w.data and CODLM1 = v.codloc1asoc;
        update TMP_OREGANTT1 set ORE = OreMasina  where DATA = w.data and CODLM1 = v.codloc1;
      end loop;
    end if;
		-------------------
  end loop;
  Commit;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodLoc INTO Tmp FROM LOCMUNCA WHERE CodLoc = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 524);
  DELETE FROM LOCMUNCA1 WHERE CodLoc = RecId ;
  DELETE FROM LOCMUNCA2 WHERE CodLoc = RecId ;
  DELETE FROM LOCMUNCA  WHERE CodLoc = RecId ;
  NotifyModif(2, RecId, &apos;LOCMUNCA&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_LOCMUNCA FIELDS( CodLoc ) VALUES(0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(524);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
vTip number(1);
StartDate Date;
StopDate Date;
sStartDate Varchar2(10);
sStopDate Varchar2(10);
aDate    Date;
aSapt number;
A  number;
L  number;
sSQL varchar2(2000);

BEGIN
  INSERT INTO TMP_LOCMUNCA (CODLOC, SIMBOL, DENUMIRE, TIP, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, FARA_GANT)
  SELECT CODLOC, SIMBOL, DENUMIRE, TIP, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, COALESCE(FARA_GANT,0)
  FROM LOCMUNCA
  WHERE CodLoc = RecId;

  begin
  select tip into vTip from tmp_locmunca;
  exception when others then
    vTip := 0;
  end;

  if vTip = 1 then
      INSERT INTO TMP_LOCMUNCA1 ( CODLOC1, CODLOC, NICKNAME, CODMIFIX, ORE, NRINV,DENUMIRE, DEN_GEST, CodGest, CODUTILAJ)
      SELECT
        LM1.CODLOC1, LM1.CODLOC, LM1.NICKNAME, LM1.CODMIFIX, LM1.ORE, MF.NRINVENTAR,
        ( SELECT Min(O.DENUMIRE)
          FROM MIFIX1 MF1
            LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
            LEFT JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
          WHERE MF1.CODMIFIX = LM1.CODMIFIX), NG.DEN_GEST, NG.CodGest, LM1.CODUTILAJ
      FROM LOCMUNCA1 LM1
        LEFT JOIN MIFIX MF ON MF.CODMIFIX = LM1.CODMIFIX
        LEFT JOIN MIFIX1 MF1 ON MF.CODMIFIX = MF1.CODMIFIX AND MF1.AnStart = pkg_globals.ANLUCRU AND MF1.LunaStart = pkg_globals.LUNALUCRU 
        LEFT JOIN NIRSTOC NS ON MF1.CODNIRSTOC = NS.CODNIRSTOC
        LEFT JOIN NIR        ON NIR.CODNIR = NS.CODNIR
        LEFT JOIN NGEST NG   ON NG.CODGEST = NIR.GEST
      WHERE NS.Rest &gt; 0 and CodLoc = RecId;
  else if vTip = 2 then  
      INSERT INTO TMP_LOCMUNCA1 (
        CODLOC1, CODLOC, NICKNAME, CODMIFIX, ORE, NRINV,
        DENUMIRE, DEN_GEST, CODUTILAJ, CodGest, CodLocatie)
      SELECT
        LM1.CODLOC1, LM1.CODLOC, LM1.NICKNAME, LM1.CODMIFIX, LM1.ORE, U.NRINVENTAR,
        O.DENUMIRE, NG.DEN_GEST, LM1.CODUTILAJ, Coalesce(NG.CODGEST, 0), LM1.CodLocatie
      FROM LOCMUNCA1 LM1
        INNER JOIN UTILAJE U ON LM1.CODUTILAJ = U.CODUTILAJ
        INNER JOIN NARTOBJ O ON U.CODOBIECT = O.CODOBIECT
        LEFT JOIN NGEST NG ON LM1.CODGEST = NG.CODGEST
      WHERE LM1.CodLoc = RecId;
  else
    INSERT INTO TMP_LOCMUNCA1 (
        CODLOC1, CODLOC, NICKNAME, DEN_GEST, CodGest, Ore, CodLocatie)
      SELECT
        LM1.CODLOC1, LM1.CODLOC, LM1.NICKNAME, NG.DEN_GEST, Coalesce(LM1.CODGEST, 0), LM1.Ore, LM1.CodLocatie
      FROM LOCMUNCA1 LM1
      LEFT JOIN NGEST NG ON LM1.CODGEST = NG.CODGEST
      WHERE LM1.CodLoc = RecId;    
  end if; end if;

	INSERT INTO TMP_LOCMUNCA2 ( codloc2 , codloc1 , codloc , codLoc1Asoc, OreStart , DataStart , OreStop , DataStop , OreActiv, MinuneOn, MinuneOff, 
	                            codLocAsoc , DenLocAsoc  , DenLoc1Asoc )
                 		SELECT  codloc2 , L2.codloc1 , L2.codloc , codLoc1Asoc, OreStart , DataStart , OreStop , DataStop , OreActiv, MinuneOn, MinuneOff, 
										        L.CODLOC codLocAsoc, L.DENUMIRE DenLocAsoc  , L1.NICKNAME DenLoc1Asoc   	
    FROM LOCMUNCA2 L2
		Left join LOCMUNCA1 L1 on L1.CODLOC1 = L2.CODLOC1Asoc
		Left join LOCMUNCA  L  on L .CODLOC  = L1.CODLOC
		WHERE L2.CodLoc = RecId;    

	L := pkg_globals.GetLUNALUCRU;
	A := pkg_globals.GetANLUCRU;
	StartDate := To_Date(&apos;01&apos;||To_Char(L,&apos;fm00&apos;)||To_Char(A,&apos;fm0000&apos;),&apos;DDMMYYYY&apos;);
  StartDate := TRUNC(StartDate,&apos;IW&apos;);
	L := L + 1;
	if L = 13 then 
	  L := 1;
		A := A + 1;
	end if;
	Select Max(DataLM) into StopDate From OreLM where CodLM = RecId;
	aDate := To_Date(&apos;01&apos;||To_Char(L,&apos;fm00&apos;)||To_Char(A,&apos;fm0000&apos;),&apos;DDMMYYYY&apos;) - 1;
	if (StopDate is null) or StopDate &lt; aDate then 
  	StopDate := aDate;
	end if;
	StopDate   := Trunc(TRUNC(StopDate,&apos;iw&apos;) + 6);
	sStopDate  := To_Char(StopDate, &apos;DDMMYYYY&apos;);
	sStartDate := To_Char(StartDate, &apos;DDMMYYYY&apos;);
  
  umple_tmp_zile(StartDate, StopDate); 
  
  INSERT INTO TMP_OreLM(CodORELM, DataLM,CodLM,CodLM1,Ore, Saptamana) 
  WITH 
  Recs as      
      ( SELECT L1.CodLoc1 CodLM1, D.Ziua Data from Tmp_Zile D, LocMunca1 L1 WHERE L1.CodLoc = RecId), 
  OLM1 as  
      (SELECT L1.CodLoc CodLM, L1.CodLoc1 CodLM1, Case when Nvl(L1.ORE,0) = 0 then G.Ore else L1.ORE end Ore 
       FROM LocMunca1 L1  
            inner join ( Select CodGest, Nvl(NrSchimburi, 0) * Nvl(OreSchimb, 0) Ore from NGEST) G on G.CodGest = L1.CodGest) 
  select Case when OreLM.CODORELM is null then -RowNum else OreLM.CODORELM end, Recs.Data, OLM1.CodLM,  OLM1.CodLM1, 
         case when z.codzineluc is null then Nvl(OreLM.Ore, OLM1.Ore) else 0 end Ore, To_Number(to_char(Recs.Data, &apos;iw&apos;)) Saptamana 
  from Recs 
     left join OLM1 on OLM1.CodLM1 = Recs.CodLM1 
     left join OreLM on OreLM.DataLM = Recs.Data and OreLM.Codlm1 = OLM1.CodLM1 
     left join zineluc1 z on trunc(z.data) = trunc(recs.data); 
  PKG_CFGTABLES.EXT_GOTORECORD(524);
	COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
MaxData   Date;
StartDate Date;
Nr number;
DayOfWeek number;
IsSpecial number;
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodLoc INTO RecId FROM TMP_LOCMUNCA;
    UPDATE LOCMUNCA
    SET ( SIMBOL, DENUMIRE, TIP, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, FARA_GANT ) = ( SELECT SIMBOL, DENUMIRE, TIP, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, FARA_GANT FROM TMP_LOCMUNCA )
    WHERE CodLoc = RecId;

    DELETE FROM LOCMUNCA1 LC1 
		WHERE LC1.CodLoc = RecId AND NOT EXISTS (SELECT CodLoc1 FROM TMP_LOCMUNCA1 TMP1 WHERE TMP1.CodLoc1 = LC1.CodLoc1);

    FOR v_rec IN (SELECT * FROM TMP_LOCMUNCA1) LOOP
      IF NVL(v_rec.CodLoc1, 0) &gt; 0 THEN
        UPDATE LOCMUNCA1 SET
          CODMIFIX  = v_rec.codmifix,
          ORE       = v_rec.ore,
          CODUTILAJ = v_Rec.Codutilaj,
          CODGEST   = v_Rec.CodGest,
					NICKNAME  = v_Rec.NICKNAME, 
					CodLocatie= v_Rec.CodLocatie
        WHERE CodLoc1 = v_rec.CodLoc1;
      ELSE
        Nr := seq_locmunca1_codloc1.nextval;
        update TMP_ORELM set CODLM1 = Nr where CODLM1 = v_rec.CODLOC1;
			  update TMP_LocMunca2 set CODLoc1 = Nr where CODLoc1 = v_rec.CODLOC1;
				INSERT INTO LOCMUNCA1 (CODLOC1, CODLOC, NICKNAME, CODMIFIX, ORE, CODUTILAJ, CODGEST,CodLocatie)
        VALUES (Nr, RecId, v_Rec.NICKNAME, v_Rec.CODMIFIX, v_Rec.ore, v_rec.codutilaj, v_rec.codgest, v_rec.CodLocatie);
      END IF;
    END LOOP;

    DELETE FROM LOCMUNCA2 LC2 
		WHERE LC2.CodLoc = RecId AND NOT EXISTS (SELECT CodLoc2 FROM TMP_LOCMUNCA2 TMP2 WHERE TMP2.CodLoc2 = LC2.CodLoc2);

    FOR v_rec IN (SELECT * FROM TMP_LOCMUNCA2) LOOP
      IF NVL(v_rec.CodLoc2, 0) &gt; 0 THEN
        UPDATE LOCMUNCA2 SET
          codLoc1Asoc =  v_rec.codLoc1Asoc , 
          OreStart    =  v_rec.OreStart    ,
          DataStart   =  v_rec.DataStart   ,
          OreStop     =  v_Rec.OreStop     ,
          DataStop    =  v_Rec.DataStop    ,
          OreActiv    =  v_rec.OreActiv    , 
          MinuneOn    =  v_Rec.MinuneOn    ,
          MinuneOff   =  v_Rec.MinuneOff   
        WHERE CodLoc2 = v_rec.CodLoc2;
      ELSE
				INSERT INTO LOCMUNCA2 
				( codloc2 , codloc1 , codloc , codLoc1Asoc, OreStart , DataStart , OreStop , DataStop , OreActiv, MinuneOn, MinuneOff)
				Values
				(seq_locmunca2_codloc2.nextval, v_rec.codloc1 , RecID, v_rec.codLoc1Asoc, v_rec.OreStart , v_rec.DataStart , v_rec.OreStop , v_rec.DataStop , v_rec.OreActiv, v_rec.MinuneOn, v_rec.MinuneOff);
      END IF;
    END LOOP;

  ELSE

		SELECT Seq_locmunca_CodLoc.NextVal INTO RecId FROM DUAL;
		INSERT INTO LOCMUNCA (CodLoc, Simbol, Denumire, Tip, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, FARA_GANT)
		SELECT RecId, Simbol, Denumire, Tip, ACTIVI, DSV, CodLocDef, MinuteOn, MinuteOff, SPECIAL, FARA_GANT
		FROM TMP_LOCMUNCA;

    FOR v_rec IN (SELECT * FROM TMP_LOCMUNCA1) LOOP
		  SELECT seq_locmunca1_codloc1.nextval INTO Nr FROM DUAL;
			update TMP_LocMunca2 set CODLOC1 = Nr where CODLOC1 = v_rec.CODLOC1;
			update TMP_ORELM set CODLM1 = Nr where CODLM1 = v_rec.CODLOC1;
			INSERT INTO LOCMUNCA1 (CODLOC1, CODLOC, NICKNAME, CODMIFIX, ORE, CODUTILAJ, CODGEST,CodLocatie)
			VALUES (Nr, RecId, v_Rec.NICKNAME, v_Rec.CODMIFIX, v_Rec.ore, v_rec.codutilaj, v_rec.codgest, v_rec.CodLocatie);
    END LOOP;

  	INSERT INTO LOCMUNCA2 ( codloc2 , codloc1 , codloc , codLoc1Asoc, OreStart , DataStart , OreStop , DataStop , OreActiv, MinuneOn, MinuneOff)
		SELECT seq_locmunca2_codloc2.nextval, codloc1 , RecID, codLoc1Asoc, OreStart , DataStart , OreStop , DataStop , OreActiv, MinuneOn, MinuneOff
		FROM TMP_LOCMUNCA2;    
  END IF;
  
	Select Coalesce(Special, 0) into IsSpecial from TMP_Locmunca;
	
	if IsSpecial = 1 then 
  	DELETE FROM ORELM OLM WHERE OLM.CodLM = RecId;
	else
		StartDate := To_Date(&apos;01&apos;||To_Char(pkg_globals.LUNALUCRU,&apos;fm00&apos;)||To_Char(pkg_globals.ANLUCRU,&apos;fm0000&apos;),&apos;ddmmyyyy&apos;);
		StartDate := TRUNC(StartDate,&apos;IW&apos;);
		Delete from TMP_OreLM where Saptamana &gt; 0; 
		DELETE FROM ORELM OLM WHERE OLM.CodLM = RecId AND NOT EXISTS (SELECT CodOreLM FROM TMP_OreLM TMP1 WHERE TMP1.CodOreLM = OLM.CodOreLM);
		FOR v_rec IN (SELECT * FROM TMP_ORELM) LOOP
			Select Count(*) into Nr from ORELM where DataLM = V_REC.DataLM and CodLM1 = v_Rec.CodLM1;
			if Nr &gt; 0 then 
				UPDATE ORELM SET ORE = v_rec.ore WHERE DataLM = V_REC.DataLM and CodLM1 = v_rec.CodLM1;
			ELSE
				Nr := v_rec.CodORELM;
				if Nr &lt; 0 then Nr := SEQ_ORELM_CodORELM.Nextval; end if;
				insert into OreLM (CodORELM, DataLM,CodLM,CodLM1,Ore)
				VALUES (Nr, V_REC.DataLM, V_REC.CodLM, V_REC.CodLM1, V_REC.Ore );
			END IF;
		END LOOP;
  end if;  
  NotifyModif(Operation, RecId, &apos;LOCMUNCA&apos;);
  PKG_CFGTABLES.EXT_POSTRECORDS(524);
  COMMIT;
END;

end pkg_locmunca; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52959A4E58BD6ECEB787B1A290B7CB496AE8F857</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MAIL IS
  -- Return the next email address in the list of email addresses, separated
  -- by either a &quot;,&quot; or a &quot;;&quot;. The format of mailbox may be in one of these:
  -- someone@some-domain
  -- &quot;Someone at some domain&quot; someone@some-domain
  -- Someone at some domain someone@some-domain

FUNCTION SENDMAIL_BY_SERVICE(ServerMail IN VARCHAR2,
                             Port IN NUMBER,
                             FromAddress IN VARCHAR2,
                             UserName IN VARCHAR2,
                             Password IN VARCHAR2,
                             SUBJECT IN VARCHAR2,
                             ToAddress IN VARCHAR2,
                             Message in VARCHAR2
                            ) RETURN NUMBER
IS
 SERVICIU_HOST_PORT  varchar2(1000) ;--:= &apos;192.168.16.200:8085&apos;;
 aREq       utl_http.req;
 data       varchar2(2000);
 URL        varchar2(2000);
 Msg_Eroare        varchar2(2000);

 RESP       utl_http.resp;
 value      VARCHAR2(32767);
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);

BEGIN

 SERVICIU_HOST_PORT   := PKG_CATEGCONST.GetValConstanta(&apos;IPWebServiceSMS&apos;,   pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) || &apos;:&apos; || 
                         PKG_CATEGCONST.GetValConstanta(&apos;PortWebServiceSMS&apos;, pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU);

 URL        := &apos;http://&apos; || SERVICIU_HOST_PORT || &apos;/root/WMEServer/SendMail&apos;;
 areq       := UTL_HTTP.BEGIN_REQUEST (lower(URL), &apos;POST&apos;);

 UTL_HTTP.SET_HEADER (areq, &apos;Content-Type&apos;, &apos;application/x-www-form-urlencoded&apos; );
   data := &apos;{&quot;ServerMail&quot;:&quot;&apos;  || ServerMail   || &apos;&quot;,
             &quot;Port&quot;:&quot;&apos;        || Port       || &apos;&quot;,
             &quot;Message&quot;:&quot;&apos;     || Message     || &apos;&quot;,
             &quot;FromAddress&quot;:&quot;&apos; || FromAddress || &apos;&quot;,
             &quot;UserName&quot;:&quot;&apos;    || UserName || &apos;&quot;,
             &quot;Password&quot;:&quot;&apos;    || Password || &apos;&quot;,
             &quot;Subject&quot;:&quot;&apos;     || Subject || &apos;&quot;,
             &quot;ToAddress&quot;:&quot;&apos;   || ToAddress || &apos;&quot; }&apos;;

   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));
   UTL_HTTP.WRITE_TEXT (areq, data);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE);
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

   RETURN RES;



END;








FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
  addr VARCHAR2(256);
  i pls_integer;

  FUNCTION lookup_unquoted_char(str IN VARCHAR2, chrs IN VARCHAR2) RETURN pls_integer AS c VARCHAR2(5);
    i pls_integer;
    len pls_integer;
    inside_quote BOOLEAN;
  BEGIN
    inside_quote := false;
    i := 1;
    len := length(str);
    WHILE (i &lt;= len) LOOP
      c := substr(str, i, 1);
      IF (inside_quote) THEN
        IF (c = &apos;&quot;&apos;) THEN
          inside_quote := false;
        ELSIF (c = &apos;\&apos;) THEN
          i := i + 1; -- Skip the quote character
        END IF;
        GOTO next_char;
      END IF;
      IF (c = &apos;&quot;&apos;) THEN
        inside_quote := true;
        GOTO next_char;
      END IF;

      IF (instr(chrs, c) &gt;= 1) THEN
        RETURN i;
      END IF;
      &lt;&lt; next_char &gt;&gt;
      i := i + 1;
    END LOOP;
    RETURN 0;
  END;

BEGIN
  addr_list := ltrim(addr_list);
  i := lookup_unquoted_char(addr_list, &apos;,;&apos;);
  IF (i &gt;= 1) THEN
    addr := substr(addr_list, 1, i - 1);
    addr_list := substr(addr_list, i + 1);
  ELSE
    addr := addr_list;
    addr_list := &apos;&apos;;
  END IF;

  i := lookup_unquoted_char(addr, &apos;&lt;&apos;);

  IF (i &gt;= 1) THEN
    addr := substr(addr, i + 1);
    i := instr(addr, &apos;&gt;&apos;);
    IF (i &gt;= 1) THEN
      addr := substr(addr, 1, i - 1);
    END IF;
  END IF;
  RETURN &apos;&lt;&apos;||addr||&apos;&gt;&apos;;
END;

-- Write a MIME header
PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection, name IN VARCHAR2, value IN VARCHAR2) IS
BEGIN
  utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(name || &apos;: &apos; || value || utl_tcp.CRLF));
END;

-- Mark a message-part boundary. Set &lt;last&gt; to TRUE for the last boundary.
PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
  last IN BOOLEAN DEFAULT FALSE) AS
BEGIN
  IF (last) THEN
    utl_smtp.write_data(conn, LAST_BOUNDARY);
  ELSE
    utl_smtp.write_data(conn, FIRST_BOUNDARY);
  END IF;
END;

PROCEDURE mail(sender IN VARCHAR2, recipients IN VARCHAR2, subject IN VARCHAR2,
  message IN VARCHAR2) IS
  conn utl_smtp.connection;
BEGIN
  conn := begin_mail(sender, recipients, subject);
  write_text(conn, message);
  end_mail(conn);
END;

FUNCTION begin_mail(sender IN VARCHAR2,
  recipients IN VARCHAR2,
  subject IN VARCHAR2,
  mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;,
  priority IN PLS_INTEGER DEFAULT NULL)
  RETURN utl_smtp.connection IS
  conn utl_smtp.connection;
BEGIN
  conn := begin_session;
  begin_mail_in_session(conn, sender, recipients, subject, mime_type, priority);
  RETURN conn;
END;

PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection, message IN VARCHAR2) IS
BEGIN
  utl_smtp.write_data(conn, message);
END;

PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection, message IN VARCHAR2) IS
BEGIN
  utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
END;

PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection, message IN RAW) IS
BEGIN
  utl_smtp.write_raw_data(conn, message);
END;

PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection, data IN VARCHAR2,
  mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, inline IN BOOLEAN DEFAULT TRUE,
  filename IN VARCHAR2 DEFAULT NULL, last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
  begin_attachment(conn, mime_type, inline, filename);
  write_text(conn, data);
  end_attachment(conn, last);
END;

PROCEDURE attach_mb_text(conn IN OUT NOCOPY utl_smtp.connection, data IN VARCHAR2,
  mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, inline IN BOOLEAN DEFAULT TRUE,
  filename IN VARCHAR2 DEFAULT NULL, last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
  begin_attachment(conn, mime_type, inline, filename);
  utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(data));
  -- write_text(conn, data);
  end_attachment(conn);
END;

PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection, data IN RAW,
  mime_type IN VARCHAR2 DEFAULT &apos;application/octet&apos;, inline IN BOOLEAN DEFAULT TRUE,
  filename IN VARCHAR2 DEFAULT NULL, last IN BOOLEAN DEFAULT FALSE) IS
  i PLS_INTEGER;
  len PLS_INTEGER;
BEGIN
  begin_attachment(conn, mime_type, inline, filename, &apos;base64&apos;);
  -- Split the Base64-encoded attachment into multiple lines
  i := 1;
  len := utl_raw.length(data);
  WHILE (i &lt; len) LOOP
		IF (i + MAX_BASE64_LINE_WIDTH &lt; len) THEN
			utl_smtp.write_raw_data(conn,  utl_encode.base64_encode(utl_raw.substr(data, i,MAX_BASE64_LINE_WIDTH)));
		ELSE
			utl_smtp.write_raw_data(conn,  utl_encode.base64_encode(utl_raw.substr(data, i)));
		END IF;
		utl_smtp.write_data(conn, utl_tcp.CRLF);
		i := i + MAX_BASE64_LINE_WIDTH;
  END LOOP;
  end_attachment(conn, last);
END;

PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
  mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;, inline IN BOOLEAN DEFAULT TRUE,
  filename IN VARCHAR2 DEFAULT NULL, transfer_enc IN VARCHAR2 DEFAULT NULL) IS
BEGIN
  write_boundary(conn);
  write_mime_header(conn, &apos;Content-Type&apos;, mime_type);
  IF (filename IS NOT NULL) THEN
    IF (inline) THEN
         write_mime_header(conn, &apos;Content-Disposition&apos;, &apos;inline; filename=&quot;&apos;||filename||&apos;&quot;&apos;);
    ELSE
         write_mime_header(conn, &apos;Content-Disposition&apos;, &apos;attachment; filename=&quot;&apos;||filename||&apos;&quot;&apos;);
    END IF;
  END IF;
  IF (transfer_enc IS NOT NULL) THEN
    write_mime_header(conn, &apos;Content-Transfer-Encoding&apos;, transfer_enc);
  END IF;
  utl_smtp.write_data(conn, utl_tcp.CRLF);
END;

PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
  utl_smtp.write_data(conn, utl_tcp.CRLF);
  IF (last) THEN
  write_boundary(conn, last);
  END IF;
END;

PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
  write_boundary(conn, TRUE);
  end_mail_in_session(conn);
  end_session(conn);
END;

FUNCTION set_auth_in_session (conn in out utl_smtp.connection) return varchar2 is
  res utl_smtp.reply;
  v_plain_text  varchar2(300);
  v_base_64_usr  varchar2(100);
  v_base_64_pass varchar2(100);
begin
  if smtp_authType = 0 then -- none
    return &apos;TRUE&apos; ;
  elsif smtp_authType = 1 then -- AUTH PLAIN
    v_plain_text := UTL_RAW.cast_to_varchar2(
                     UTL_ENCODE.base64_encode(
                      UTL_RAW.cast_to_raw(smtp_UserName||chr(0)||smtp_UserName||chr(0)||smtp_Password)
                      ));
    begin
      UTL_SMTP.command(conn, &apos;AUTH&apos;, &apos;PLAIN &apos;||v_plain_text);
    EXCEPTION
      when others then return &apos;TRUE&apos; ;
    end;
    return &apos;TRUE&apos; ;
  elsif smtp_authType = 2 then -- AUTH LOGIN
    v_base_64_usr  := UTL_RAW.cast_to_varchar2( UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(smtp_UserName)));
    v_base_64_pass := UTL_RAW.cast_to_varchar2( UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(smtp_PassWord)));
    res := UTL_SMTP.command(conn, &apos;AUTH&apos;,&apos;LOGIN&apos;);

    if res.code = WAIT_FOR_COMMAND then
      res := UTL_SMTP.command(conn, v_base_64_usr);
      if res.code = WAIT_FOR_COMMAND then
        res := UTL_SMTP.command(conn, v_base_64_pass);
        if res.code = SUCCESFULL_REPLY then
          return &apos;TRUE&apos;;
        else
          RETURN &apos;Invalid password&apos;;
        end if;
      else
        RETURN &apos;Invalid username&apos;;
      end if;
    else
      RETURN &apos;Invalid authentication type&apos;;
    end if;
  end if;

 -- Teoretic nu trebuie sa ajung niciodata pe linia de mai jos !!!
 RETURN &apos;Something went wrong with authenticating mail session on server&apos;;
end;

FUNCTION begin_session RETURN utl_smtp.connection IS
  conn utl_smtp.connection;
  aMessage varchar2(500);
BEGIN
  -- open SMTP connection
  conn := utl_smtp.open_connection(smtp_host, smtp_port);
  utl_smtp.ehlo(conn, smtp_domain);
  aMessage := set_auth_in_session(conn);
  if aMessage &lt;&gt; &apos;TRUE&apos; then
    utl_smtp.quit(conn);
    RAISE_APPLICATION_ERROR(-20001,aMessage);
  end if;
  RETURN conn;
END;

PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
  sender IN VARCHAR2, recipients IN VARCHAR2, subject IN VARCHAR2,
  mime_type IN VARCHAR2 DEFAULT &apos;text/plain&apos;,
  priority IN PLS_INTEGER DEFAULT NULL) IS
  my_recipients VARCHAR2(32767) := recipients;
  my_sender VARCHAR2(32767) := sender;
BEGIN
  -- Specify sender&apos;s address (our server allows bogus address as long as it is a full email address (xxx@yyy.com).
  utl_smtp.mail(conn, get_address(my_sender));
  -- Specify recipient(s) of the email.
  WHILE (my_recipients IS NOT NULL) LOOP
    utl_smtp.rcpt(conn, get_address(my_recipients));
  END LOOP;

  -- Start body of email
  utl_smtp.open_data(conn);
  -- Set &quot;Date&quot; MIME header

  -- write_mime_header(conn, &apos;Date&apos;, TO_CHAR(SYSDATE, &apos;DY, DD MON YYYY HH24:MI:SS&apos;,&apos;NLS_DATE_LANGUAGE = EN&apos;)||&apos; +0200&apos;);
  write_mime_header(conn, &apos;Date&apos;, TO_CHAR(SYSDATE, &apos;DY, DD MON YYYY HH24:MI:SS&apos;, &apos;NLS_DATE_LANGUAGE = ENGLISH&apos;));
  --write_mime_header(conn, &apos;Date&apos;, TO_CHAR(SYSDATE, &apos;DY, DD MON YYYY HH24:MI:SS&apos;)||&apos; +0200&apos;);
  --write_mime_header(conn, &apos;Date&apos;, TO_CHAR(CURRENT_TIMESTAMP));
  -- Set &quot;From&quot; MIME header
  write_mime_header(conn, &apos;From&apos;, sender);
  -- Set &quot;To&quot; MIME header
  write_mime_header(conn, &apos;To&apos;, recipients);
  -- Set &quot;Subject&quot; MIME header
  write_mime_header(conn, &apos;Subject&apos;, subject);
  -- Set &quot;Content-Type&quot; MIME header
  write_mime_header(conn, &apos;Content-Type&apos;, mime_type);
  -- Set &quot;X-Mailer&quot; MIME header
  write_mime_header(conn, &apos;X-Mailer&apos;, MAILER_ID);
  -- Set priority: High Normal Low
  IF (priority IS NOT NULL) THEN
    write_mime_header(conn, &apos;X-Priority&apos;, priority);
  END IF;

  -- Send an empty line to denotes end of MIME headers and beginning of message body.
  utl_smtp.write_data(conn, utl_tcp.CRLF);
  IF (mime_type LIKE &apos;multipart/mixed%&apos;) THEN
  write_text(conn, &apos;This is a multi-part message in MIME format.&apos; || utl_tcp.crlf);
  END IF;
END;

PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
  utl_smtp.close_data(conn);
END;

PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
  utl_smtp.quit(conn);
END;

procedure Send_mail(aSender in varchar2,
                    vRecipients in varchar2,
                    vSubject in varchar2,
                    vMessage in varchar2,
                    vMailID in number) is

	vSender  varchar2(100);
  MAX_LINE_WIDTH PLS_INTEGER := 54;
  buf RAW(2100);
  conn UTL_SMTP.CONNECTION;
  crlf VARCHAR2(2) := chr(13) || chr(10);
  data RAW(2100);
  aMesaj CLOB;
  v_mime_type_bin varchar2(30) := &apos;application/pdf&apos;;
	SS       varchar2(100);
	i        number;

  procedure do_attach(fileName in varchar2, fileObj in blob) is
    file_len PLS_INTEGER;
    amt      BINARY_INTEGER := 672 * 3;
    pos      PLS_INTEGER := 1; /* pointer for each piece */
    filepos  PLS_INTEGER := 1; /* pointer for the file */
    chunks   PLS_INTEGER;
    len      PLS_INTEGER := 1;
    modulo   PLS_INTEGER;
    pieces   PLS_INTEGER;
  begin
    file_len := dbms_lob.getlength(fileObj);
    if file_len &gt; 0 then
			v_mime_type_bin := &apos;application/&apos;||substr(fileName,instr(fileName,&apos;.&apos;)+1,length(fileName));
			pkg_mail.begin_attachment(  conn =&gt; conn,
																	mime_type =&gt; v_mime_type_bin,
																	inline =&gt; TRUE,
																	filename =&gt; filename,
																	transfer_enc =&gt; &apos;base64&apos;);

			modulo   := mod(file_len, amt);
			pieces   := trunc(file_len / amt);
			if (modulo &lt;&gt; 0) then
				pieces := pieces + 1;
			end if;
			dbms_lob.read(fileObj, amt, filepos, buf);
			data := NULL;
			/* For each piece of the file . . . */
			FOR i IN 1..pieces LOOP
					filepos := i * amt + 1;                                /* Position file pointer for next read */
					file_len := file_len - amt;                            /* Calculate remaining file length */
					data := utl_raw.concat(data, buf);                     /* Stick the buffer contents into data */
					chunks := trunc(utl_raw.length(data) / MAX_LINE_WIDTH);/* Calculate the number of chunks in this piece */
					IF (i &lt;&gt; pieces) THEN /* Don&apos;t want too many chunks */
						chunks := chunks - 1;
					END IF;
					pkg_mail.write_raw( conn =&gt; conn, message =&gt; utl_encode.base64_encode(data ) );
					data := NULL;
					if (file_len &lt; amt and file_len &gt; 0) then /* We&apos;re running out of file, only get the rest of it */
						amt := file_len;
					end if;

					if amt &lt;= file_len then
						dbms_lob.read(fileObj, amt, filepos, buf);
					end if;
			END LOOP;
			pkg_mail.end_attachment(conn =&gt; conn );   --FARA BOUNDARY
		end if;
  END;

BEGIN
	vSender := aSender;
	SS := substr(vSender,instr(vSender,&apos;@&apos;)+1,length(vSender));
	i := instr(SS,&apos;@&apos;);
	if i &gt; 0 then
		vSender := Replace(aSENDER,&apos;@&apos;||substr(ss,1, i), &apos;@&apos;);
  end if;

  begin
		conn := begin_mail( sender =&gt; vSender,
												recipients =&gt; Replace(Replace(vRecipients,&apos; &apos;, &apos;&apos;),&apos;Chr(#13)||Chr(#10)&apos;,&apos; ; &apos;) ,
												subject =&gt; vSubject,
												mime_type =&gt; pkg_mail.MULTIPART_MIME_TYPE);
    --utl_smtp.starttls(conn);
		aMesaj := vMessage;
		attach_mb_text( conn =&gt; conn,
										data =&gt; aMesaj,
										mime_type =&gt; &apos;text/html; charset=iso-8859-2&apos;);
		end_attachment(conn =&gt; conn);  --FARA BOUDARY

		if vMailID &gt; 0 then
			for v_rec in
				( select * from Mailuri1
				  where CODMAIL = vMailID
					and Nvl(FileName, &apos;?&apos;) &lt;&gt; &apos;?&apos;
					and AttachFile is not null
				)
			loop
				do_attach(v_rec.FileName,v_rec.AttachFile);
			end loop;
		end if;
		pkg_mail.end_mail(conn =&gt; conn);
  EXCEPTION
    when others then pkg_mail.end_attachment( conn =&gt; conn );
    raise;
  END;
END send_mail;

procedure SetCustomParams ( aSmtp_host     in varchar2,
                            iSmtp_port     in pls_integer,
                            aSmtp_domain   in varchar2,
                            auth_type      in number,
                            aSmtp_Username in varchar2,
                            aSmtp_Password in varchar2) is
begin
  smtp_host     := aSmtp_host;
  smtp_port     := iSmtp_port;
  smtp_domain   := aSmtp_domain;
  smtp_authType := auth_type;
  Smtp_Username := aSmtp_Username;
  Smtp_Password := aSmtp_Password;
end;

function test_mail_data return varchar2 is
  res  utl_smtp.reply;
  conn utl_smtp.connection;
  aMessage varchar2(500);
begin
  conn := utl_smtp.open_connection(smtp_host, smtp_port);
  utl_smtp.ehlo(conn, smtp_domain);
  aMessage := set_auth_in_session(conn);
  if aMessage &lt;&gt; &apos;TRUE&apos; then
    utl_smtp.quit(conn);
    RAISE_APPLICATION_ERROR(-20001,aMessage);
  end if;
  res := utl_smtp.helo(conn, smtp_domain);
  utl_smtp.quit(conn);
  return res.text;
end;

procedure test is
  res  utl_smtp.reply;
  conn utl_smtp.connection;
  aMessage varchar2(500);
  v_plain_text  varchar2(300);

begin
  pkg_mail.SetCustomParams(&apos;mail.winmentor.ro&apos;,25,&apos;winmentor.ro&apos;,1,&apos;wmetest@winmentor.ro&apos;, &apos;Testing4WME&apos;);
  conn := utl_smtp.open_connection(smtp_host, smtp_port);
  utl_smtp.ehlo(conn, smtp_domain);

  v_plain_text := UTL_RAW.cast_to_varchar2(
	  							UTL_ENCODE.base64_encode(
									UTL_RAW.cast_to_raw(&apos;wmetest&apos;||chr(0)||&apos;wmetest&apos;||chr(0)||&apos;Testing4WME&apos;)
											));
	 begin
		 UTL_SMTP.command(conn, &apos;AUTH&apos;, &apos;PLAIN &apos;||v_plain_text);
	  aMessage := &apos;TRUE&apos; ;
	 EXCEPTION
		 when others then aMessage := &apos;False&apos; ;
	 end;
  if aMessage &lt;&gt; &apos;TRUE&apos; then
    utl_smtp.quit(conn);
    RAISE_APPLICATION_ERROR(-20001,aMessage);
  end if;
  res := utl_smtp.helo(conn, smtp_domain);
  utl_smtp.quit(conn);
end;

END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MAIL_UTILS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88C1F998C31C813E7DCA19CF561B437710AD505B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_mail_utils IS


function SendMailFromTrigger(Subject in varchar2, Message in varchar2, ToAddress in varchar2) return number
is
  gUserName     varchar2(500);
  gPassword     varchar2(500);
  gFromAddress  varchar2(500);
  gSemnatura    varchar2(500);
  gPort         NUMBER;
  gServerMail   varchar2(500);
  gDomain       varchar2(500);
  gAuthType     NUMBER;
  gUseTLS       NUMBER;
  iret          number;

  gClientID           varchar2(200);
  gClientSecret       varchar2(200);
  gAuthEndPoint       varchar2(200);
  gAccesTokenEndPoint varchar2(200);
  gRefreshToken       varchar2(2000);
  gLogOutEndPoint     varchar2(200);
  gScopes             varchar2(300);
  gOAuth2             NUMBER;


begin
  winmadmin.pkg_userfirme.GET_USER_CREDENTIAL_FULL_ext(pkg_globals.USERID, 0, 
                                                   pkg_globals.CODFIRMA, 
                                                   gUserName, 
                                                   gPassword, 
                                                   gFromAddress, 
                                                   gSemnatura, 
                                                   gPort, 
                                                   gServerMail, 
                                                   gDomain, 
                                                   gAuthType, 
                                                   gUseTLS,
                                                   gRefreshToken,
                                                   goAuth2,
                                                   gClientID,
                                                   gClientSecret,
                                                   gAuthEndPoint,
                                                   gAccesTokenEndPoint,
                                                   gLogOutEndPoint,
                                                   gScopes 
                                                   );
  iRet := pkg_mail.SENDMAIL_BY_SERVICE(gServerMail,
                            gPort, 
                            gFromAddress,
                            gUserName,
                            gPassword,
                            Subject, 
                            ToAddress,
                            Message 
                            );
  Return(iRet);                           
end;

PROCEDURE ResendMail(aCod in number) is
iCodMail number(20);
BEGIN
  select seq_mailuri_codmail.nextval into iCodMail from dual;

  insert into mailuri(CODMAIL,SENDER,RECIPIENTS,SUBJECT,MESSAGE,MSG, USERID,DATA,status,host,port,domain,Codfirma,CodServer)
  select iCodMail,SENDER,RECIPIENTS,SUBJECT,MESSAGE,MSG,pkg_globals.GETUSERID,sysdate,0,host,port,domain,pkg_globals.GETCODFIRMA,CodServer
  from mailuri where CodMail = aCod;

  insert into mailuri1(CODMAIL1,CODMAIL,FileName, ATTACHFILE)
  select seq_mailuri1_codmail1.nextval, iCodMail, FileName, ATTACHFILE from mailuri1 where CodMail = aCod;
  commit;
  DoTheJob(iCodMail);
END;

PROCEDURE PostRecord_mail is
  iCodMail number(20);
  aUserID number(20);

BEGIN
  --select seq_mailuri_codmail.nextval into iCodMail from dual;
  iCodMail := seq_mailuri_codmail.nextval;
  aUserID  := pkg_globals.GETUSERID;

  INSERT INTO mailuri (
    CODMAIL, SENDER,RECIPIENTS,SUBJECT,MESSAGE, MSG,USERID, DATA,  EROARE,
		WEBSERVER,status,
		host,port,domain,Codfirma,CodServer,coddoc,coddoc1,tipdoc)
  SELECT
    iCodMail, SENDER,RECIPIENTS,SUBJECT,MESSAGE,MSG,aUserID,sysdate,EROARE,
		WEBSERVER,0,    
		host,port,domain,pkg_globals.GETCODFIRMA,CodServer, coddoc, coddoc1,tipdoc
  FROM tmp_mailuri;

  INSERT INTO mailuri1(CODMAIL1,CODMAIL,FileName, ATTACHFILE)
  SELECT seq_mailuri1_codmail1.nextval, iCodMail, FileName, ATTACHFILE
  FROM tmp_mailuri1;

  COMMIT;
END;

PROCEDURE prepare_mail(iCodServer in number, ZileAfter in number, Instant in number default 0) is
  aJobName varchar2(200);
  iCodMail number(20);
  aUserID number(20);
  err_cde number(20);
  err_msg varchar2(3000);
  DataMail date;
	aWEBSERVER number;
	
BEGIN
  select seq_mailuri_codmail.nextval into iCodMail from dual;

  if NVL(instant,0) = 0
    then aUserID := 0;
    else aUserID := pkg_globals.GETUSERID;
  end if;

  select COALESCE(WEBSERVER, 0) into aWEBSERVER from tmp_mailuri;
  INSERT INTO mailuri (
    CODMAIL,
    SENDER,
    RECIPIENTS,SUBJECT,MESSAGE,MSG,USERID,DATA,EROARE,WEBSERVER,status,host,port,domain,Codfirma,CodServer,coddoc,coddoc1,tipdoc)
  SELECT
    iCodMail, 
--    Replace(SENDER,&apos;@&apos;||Domain||&apos;@&apos;||Domain, &apos;@&apos;||Domain),
		Replace(Case when Instr(SENDER, &apos;@&apos;) = 0 THEN  SENDER||&apos;@&apos;||Domain else SENDER end,&apos;@&apos;||Domain||&apos;@&apos;||Domain, &apos;@&apos;||Domain),
    RECIPIENTS,SUBJECT,MESSAGE,Nvl(MSG, Message),aUserID,sysdate,EROARE,WEBSERVER,0,host,port,domain,pkg_globals.GETCODFIRMA,iCodServer, coddoc, coddoc1,tipdoc
  FROM tmp_mailuri;

  INSERT INTO mailuri1(CODMAIL1,CODMAIL,FileName, ATTACHFILE)
  SELECT seq_mailuri1_codmail1.nextval, iCodMail, FileName, ATTACHFILE
  FROM tmp_mailuri1;

  INSERT INTO mailuridocs(codmaildoc, codmail, coddoc1, coddoc, tipdoc, codagenda)
  SELECT seq_mailuridocs_codmaildoc.nextval, iCodMail, coddoc1, coddoc, tipdoc, codagenda
  FROM tmp_mailuridocs;

  COMMIT;
  if aWEBSERVER = 0 then 
		IF NVL(instant,0) = 0 then
			aJobName := &apos;Mail&apos;||pkg_globals.GETCODFIRMA||&apos;_&apos;||iCodMail;
			BEGIN
				 DataMail := SysDate + ZileAfter;
				 dbms_scheduler.create_job(job_name   =&gt; aJobName ,
																	 job_type   =&gt;&apos;STORED_PROCEDURE&apos; ,
																	 job_action =&gt; &apos;pkg_mail_utils.DoTheJob&apos;,
																	 start_date =&gt; DataMail,
																	 comments   =&gt; &apos;eMail by Oracle&apos;,
																	 auto_drop  =&gt; true,
																	 number_of_arguments =&gt; 1
																	 );
				 dbms_scheduler.set_job_argument_value(job_name =&gt; aJobName ,
																							 argument_position =&gt; 1,
																							 argument_value =&gt; iCodMail
																							 );

				 dbms_scheduler.enable(aJobName);
			EXCEPTION WHEN OTHERS THEN
				 err_cde := SQLCODE;
				 err_msg := SQLERRM;
				 update mailuri set eroare = err_cde ||&apos;-&apos;||err_msg where codmail = iCodMail;
				 commit;
			END;
		ELSIF NVL(instant,0) = 1 then
			DoTheJob(iCodMail);
		END IF;
	end if;
END;

procedure DoTheJob(aMailID in number, FaraCommit in number default 0) is
  userid_       number(20);
  err_num NUMBER;
  err_msg VARCHAR2(500);
  gUserMail    varchar2(256);
  gPassMail    varchar2(256);
  gPort        integer;
  gServerMail  varchar2(256);
  gDomain      varchar2(256);
  gAuthType    integer      ;
  gClientID           varchar2(200);
  gClientSecret       varchar2(200);
  gAuthEndPoint       varchar2(200);
  gAccesTokenEndPoint varchar2(200);
  gRefreshToken       varchar2(2000);
  gLogOutEndPoint     varchar2(200);
  gScopes             varchar2(300);
  gOAuth2             NUMBER;
  
  
  
  
  
  
begin
  FOR v_rec in ( SELECT  SENDER,  RECIPIENTS,  SUBJECT,  MESSAGE,  MSG,DOMAIN, PORT, HOST, USERID, CodFirma, CodServer FROM mailuri WHERE codmail = aMailID)
  LOOP
    BEGIN
      WINMADMIN.PKG_USERFIRME.GET_USER_CREDENTIAL_ext(v_rec.USERID, 
                                                  v_rec.CodServer, 
                                                  v_rec.CodFirma, 
                                                  gUserMail, 
                                                  gPassMail, 
                                                  gPort, 
                                                  gServerMail, 
                                                  gDomain, 
                                                  gAuthType,
                                                  gRefreshToken,
                                                  goAuth2,
                                                  gClientID,
                                                  gClientSecret,
                                                  gAuthEndPoint,
                                                  gAccesTokenEndPoint,
                                                  gLogOutEndPoint,
                                                  gScopes 
                                                  );
      pkg_mail.SetCustomParams(v_rec.Host, gPort, gDomain, gAuthType, gUserMail, gPassMail);
      pkg_mail.Send_mail(v_rec.Sender, v_rec.Recipients, v_rec.Subject, Coalesce(v_rec.msg, v_rec.Message), aMailID);
    EXCEPTION WHEN OTHERS THEN
      err_num := SQLCODE;
      err_msg := SQLERRM;

      update mailuri m set m.eroare = err_msg where  m.codmail = aMailID;

      select userid into userid_ from mailuri where codmail = aMailID ;

      INSERT into winmadmin.mesaje(codmesaj,text,from_user,skemafirma,data,tip_mesaj,dataafis)
      VALUES (WINMADMIN.SEQ_MESAJE_CODMESAJ.NEXTVAL,&apos;Eroare la trimitere eMail:&apos;||v_rec.RECIPIENTS,&apos;SendMail&apos;,user,sysdate,0,sysdate);

      INSERT into winmadmin.mesaje1(codmesaj1,codmesaj,to_user,sters,citit)
      VALUES (winmadmin.seq_mesaje1_codmesaj1.nextval,winmadmin.seq_mesaje_codmesaj.currval,WINMADMIN.PKG_USERFIRME.GETUSERNAME(USERID_),0,0);
       
      if FaraCommit &lt;&gt; 1 then COMMIT;end if;
    END;
  END LOOP;
END;


function GetCurrentUserMail return varchar2 is
  sResult varchar2(200);
  iServer number;
  aID1 varchar2(200);
  aID2 varchar2(200);
  aID3 varchar2(200);
  iPort number;
  aServMail varchar2(200);
  aDomeniuMail varchar2(200);
  iAuthType number;
  gClientID           varchar2(200);
  gClientSecret       varchar2(200);
  gAuthEndPoint       varchar2(200);
  gAccesTokenEndPoint varchar2(200);
  gRefreshToken       varchar2(2000);
  gLogOutEndPoint     varchar2(200);
  gScopes             varchar2(300);
  gOAuth2             NUMBER;
  
  
  
  
begin
   winmadmin.pkg_UserFirme.get_user_credential_ext( pkg_globals.USERID, 
                                              0 ,
                                              pkg_globals.GETCODFIRMA, 
                                              aID1 ,
                                              aID2 ,
                                              iPort ,
                                              aServMail ,
                                              aDomeniuMail,
                                              iAuthType,
                                              gRefreshToken,
                                              goAuth2,
                                              gClientID,
                                              gClientSecret,
                                              gAuthEndPoint,
                                              gAccesTokenEndPoint,
                                              gLogOutEndPoint,
                                              gScopes 
                                              );
/*
 	 IF Instr(aID1, &apos;@&apos;) = 0 THEN  
		 aID1 := aID1||&apos;@&apos;||aDomeniuMail;
	 END IF;
*/
   Return aID1;
end;

procedure PostDocumente(aCodDoc in number, aTipDoc in number,aOwner in varchar2)  is  -- parametri ca sa mearga deletu
pragma autonomous_transaction;
begin
  execute immediate &apos;delete from &apos;||aOwner||&apos;.documente d where d.coddoc = &apos;||aCodDoc||&apos; and d.tipdoc = &apos;||aTipDoc ;
  execute immediate
    &apos;insert into &apos;||aOwner||&apos;.documente(coddocument,coddoc,tipdoc,filename,doc,obs,userid,datacreare) &apos;||
    &apos;select &apos;||aOwner||&apos;.seq_documente_coddocument.nextval, coddoc,tipdoc,filename,doc,obs,pkg_globals.GETUSERID,sysdate &apos;||
    &apos;from tmp_documente &apos;;
  commit;
end;

procedure GetDocumente (aCodDoc in number, aTipDoc in number,aOwner in varchar2) is
pragma autonomous_transaction;
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
   
  IF    aTipDoc IN (1,2,3,4,5,6,7,9)               THEN pkg_intrari.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (14,15,16,19,20,21,22,23,24,26) THEN pkg_iesiri.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (12,13)                         THEN pkg_miscari_interne.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (8,18,43,44,53)                 THEN pkg_comanda.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (10, 25, 27, 34)                THEN pkg_contract.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (29,30,31,33)                   THEN pkg_trezor.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (28)                            THEN pkg_compensari.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (45,46,47)                      THEN Pkg_Regpart.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (54)                            THEN if TaskFirma = 1 then pkg_settask.SP_LOCKRECORD(aCodDoc);
	                                                                       else winmadmin.pkg_settask.SP_LOCKRECORD(aCodDoc); 
	                                                      end if;
  ELSIF aTipDoc IN (500)                           THEN pkg_nompart.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (501)                           THEN pkg_nom_articol.SP_LOCKRECORD(aCodDoc);
  ELSIF aTipDoc IN (502)                           THEN pkg_nompers.SP_LOCKRECORD(aCodDoc);
  END IF;

  execute immediate
    &apos;insert into tmp_documente(coddocument,coddoc,tipdoc,filename,doc,obs,incarcat,marime) &apos;||
    &apos;select coddocument,coddoc,tipdoc,filename,doc,obs,1,round(dbms_lob.getlength(doc)/1024,2) &apos;||
    &apos;from &apos;||aOwner||&apos;.documente where coddoc = &apos;||aCodDoc||&apos; and tipdoc = &apos;||aTipDoc;
  commit;
END;

PROCEDURE TestSendEmail is
BEGIN
  pkg_globals.sETCODFIRMA(6389);
  pkg_globals.SETUSERID(1266);
  DELETE TMP_MAILURI1;
  INSERT INTO TMP_MAILURI(SENDER, RECIPIENTS, SUBJECT, HOST, PORT, DOMAIN, MESSAGE)
  VALUES(&apos;miki@winmentor.ro&apos;,&apos;miki@winmentor.ro&apos;,&apos;WinMENTOR Enterprise&apos;,&apos;mail.winmentor.ro&apos;,25,&apos;winmentor.ro&apos;,&apos;xxxxxxxxxxxxx&apos;);
  COMMIT;
  pkg_mail_utils.prepare_mail(0, 1);
END;

function TestUserMail (aCodUser in number, aCodGrup in number, aCodFirma in number) return varchar2  is
  smtp_host varchar2(50);
  smtp_port number(5);
  smtp_domain varchar2(50);
  authType number(1);
  usern varchar2(100);
  pass varchar2(100);
  email varchar2(200);
  aResult varchar2(500);
  gClientID           varchar2(200);
  gClientSecret       varchar2(200);
  gAuthEndPoint       varchar2(200);
  gAccesTokenEndPoint varchar2(200);
  gRefreshToken       varchar2(2000);
  gLogOutEndPoint     varchar2(200);
  gScopes             varchar2(300);
  gOAuth2             NUMBER;
  
  
  
  
begin
  winmadmin.pkg_userfirme.get_user_credential_ext(
    iCodUser =&gt; aCodUser,
    iCodGrup =&gt; aCodGrup ,
    iCodFirma =&gt; aCodFirma ,
    aID1 =&gt; usern,
    aID2 =&gt; pass,
    iPort =&gt; smtp_port,
    aServMail =&gt; smtp_host,
    aDomeniuMail =&gt; smtp_domain,
    iAuthType =&gt; authType,
    aRefreshToken       =&gt; gRefreshToken,
    ioAuth2             =&gt; goAuth2,
    iClientID           =&gt; gClientID,
    iClientSecret       =&gt; gClientSecret,
    iAuthEndPoint       =&gt; gAuthEndPoint,
    iAccesTokenEndPoint =&gt; gAccesTokenEndPoint,
    iLogOutEndPoint     =&gt; gLogOutEndPoint,
    iScopes             =&gt; gScopes
    );
/*
  IF --	AuthType = 2 and 
	Instr(usern, &apos;@&apos;) = 0 
	THEN
    usern := usern||&apos;@&apos;||smtp_domain;
  END IF;
*/
  pkg_mail.SetCustomParams(smtp_host,smtp_port,smtp_domain,AuthType,usern,pass);
  aResult := pkg_mail.test_mail_data;
  return aResult;
end;


end pkg_mail_utils; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MASCASERART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43F8BA4514B47C309920CFE54228FE0770E8110C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MASCASERART is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodMasca INTO Tmp FROM MASCASERART WHERE CodMasca = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM MASCASERART1 WHERE CodMasca = RecId;
  DELETE FROM MASCASERART  WHERE CodMasca = RecId;
  NotifyModif(2, RecId, &apos;MASCASERART&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_MASCASERART FIELDS(CodMasca) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_MASCASERART(CodMasca, Masca)
  SELECT CodMasca, Masca
  FROM MASCASERART 
  WHERE CodMasca = RecId;

  INSERT INTO TMP_MASCASERART1 (
    CODMASCA1,
    CODMASCA,
    DENELEMENT,
    VALORI,
    ELEMENT,
    LUNGIME,
    FILL
    )
  SELECT
    CODMASCA1,
    CODMASCA,
    DENELEMENT,
    VALORI,
    ELEMENT,
    LUNGIME,
    FILL
  FROM MASCASERART1 
  WHERE CodMasca = RecId;
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodMasca INTO RecId FROM TMP_MASCASERART;
    UPDATE MASCASERART SET Masca = (SELECT Masca FROM TMP_MASCASERART)
    WHERE CodMasca = RecId;

    DELETE FROM MASCASERART1 where CodMasca = RecId and CodMasca1 not in (Select CodMasca1 from TMP_MASCASERART1);
    FOR v_rec IN (SELECT * FROM TMP_MASCASERART1 WHERE CodMasca1 &gt; 0) LOOP
      UPDATE MASCASERART1
      SET
        DENELEMENT = V_REC.DENELEMENT,
        VALORI     = V_REC.VALORI,
        ELEMENT    = V_REC.ELEMENT,
        LUNGIME    = V_REC.LUNGIME,
        FILL       = V_REC.FILL
      WHERE CodMasca1 = v_rec.CodMasca1;
    END LOOP;

    INSERT INTO MASCASERART1
    (
      CODMASCA1,
      CODMASCA,
      DENELEMENT,
      VALORI,
      ELEMENT,
      LUNGIME,
      FILL
    )
    SELECT
      SEQ_MASCASERART1_CODMASCA1.NEXTVAL,
      RECID,
      DENELEMENT,
      VALORI,
      ELEMENT,
      LUNGIME,
      FILL
    FROM TMP_MASCASERART1 WHERE CodMasca1 &lt; 0;
  ELSE
    SELECT Seq_MASCASERART_CodMasca.NextVal INTO RecId FROM DUAL;
    INSERT INTO MASCASERART(CODMASCA,MASCA)
    SELECT RECID, MASCA 
    FROM TMP_MASCASERART;
    INSERT INTO MASCASERART1 (
      CODMASCA1,
      CODMASCA,
      DENELEMENT,
      VALORI,
      ELEMENT,
      LUNGIME,
      FILL)
    SELECT
      SEQ_MASCASERART1_CODMASCA1.NEXTVAL,
      RecId,
      DENELEMENT,
      VALORI,
      ELEMENT,
      LUNGIME,
      FILL
    FROM Tmp_MascaSerArt1;
  END IF;
  NotifyModif(Operation, RecId, &apos;MASCASERART&apos;);
  COMMIT;
END;

end PKG_MASCASERART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MEDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3636F7927F395D67DCF17F3F5D51A42DBBD1B9B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MEDEX IS

FUNCTION GetCompensare(CIM in varchar2, DataStart in date) return VARCHAR2 is
t varchar2(100);
begin
  begin
    select string_agg(m2.tipcompens) into t from (select distinct tipcompens, validdela from medex2 where codcim = CIM) m2 where m2.validdela = datastart;
  exception when others then
    t := &apos;&apos;;
  end;
  return t;  
end;

FUNCTION GetCompensareS(CIM in varchar2, DataStart in varchar2) return VARCHAR2 is
t varchar2(100);
begin
  begin
    select string_agg(m2.tipcompens) into t from (select distinct tipcompens, validdela from medex2 where codcim = CIM) m2 where m2.validdela = to_date(datastart, &apos;DD.MM.YYYY&apos;);
  exception when others then
    t := &apos;&apos;;
  end;
  return t;  
end;

function ListaActuala(DataStart in Date) return number is
datamin date;
datamax date;
oData Date;
aResult number(1);
aCount number(20);
begin
  select count(codmedex) into aCount from medex;
  if aCount = 0 then
    aResult := 0;
  else
    begin
      oData := to_date(&apos;01.&apos;||to_char(pkg_globals.getlunalucru)||&apos;.&apos;||to_char(pkg_globals.getanlucru), &apos;dd.mm.yyyy&apos;);
      select max(m.datalista) into datamin from medex m where odata &gt;= m.datalista;
    exception when others then
      datamin := to_date(&apos;01.01.1000&apos;, &apos;dd.mm.yyyy&apos;);
    end;
    begin
      oData := to_date(to_char(Last_day(to_date(&apos;01.&apos;||to_char(pkg_globals.getlunalucru)||&apos;.&apos;||to_char(pkg_globals.getanlucru), &apos;dd.mm.yyyy&apos;)))||&apos;.&apos;||to_char(pkg_globals.getlunalucru)||&apos;.&apos;||to_char(pkg_globals.getanlucru), &apos;dd.mm.yyyy&apos;);
      select min(m.datalista) into datamax from medex m where odata &lt; m.datalista;
    exception when others then
      datamax := to_date(&apos;31.12.9999&apos;, &apos;dd.mm.yyyy&apos;);
    end;
    if datastart &lt; datamax and datastart &gt;= datamin then
      aResult := 1;
    else
      aResult := 0;
    end if;    
  end if;
  return aResult;  
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodMedex INTO Tmp FROM MEDEX WHERE CodMedex = RecId FOR UPDATE NOWAIT;
END;

FUNCTION Med1Valid(aCodMedex1 IN NUMBER) RETURN NUMBER IS
eBun NUMBER(1);
datas number(20);
dataf number(20);
BEGIN
  eBun := 0;
  select extract(YEAR FROM M1.VALIDDELA)*12 + extract(MONTH FROM M1.VALIDDELA) into datas from medex1 M1 where codmedex1 = aCodMedex1;
  select extract(YEAR FROM M1.VALIDPANALA)*12 + extract(MONTH FROM M1.VALIDPANALA) into dataf from medex1 M1 where codmedex1 = aCodMedex1;
  if PKG_GLOBALS.GetANLUCRU*12 + pkg_globals.GetLUNALUCRU &lt;= dataf and PKG_GLOBALS.GetANLUCRU*12 + pkg_globals.GetLUNALUCRU &gt;= datas then
    eBun := 1;
  else
    eBun := 0;
  end if;
  Return eBun;    
END;

FUNCTION Med2Valid(aCodMedex2 IN NUMBER) RETURN NUMBER IS
eBun NUMBER(1);
datas number(20);
dataf number(20);
BEGIN
  eBun := 0;
  select extract(YEAR FROM M2.VALIDDELA)*12 + extract(MONTH FROM M2.VALIDDELA) into datas from medex2 M2 where codmedex2 = aCodMedex2;
  select extract(YEAR FROM M2.VALIDPANALA)*12 + extract(MONTH FROM M2.VALIDPANALA) into dataf from medex2 M2 where codmedex2 = aCodMedex2;
  if PKG_GLOBALS.GetANLUCRU*12 + pkg_globals.GetLUNALUCRU &lt;= dataf and PKG_GLOBALS.GetANLUCRU*12 + pkg_globals.GetLUNALUCRU &gt;= datas then
    eBun := 1;
  else
    eBun := 0;
  end if;
  Return eBun;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM MEDEX_TARI WHERE CodMedex = RecId;
  DELETE FROM MEDEX2 WHERE CodMedex = RecId;
  DELETE FROM MEDEX1 WHERE CodMedex = RecId;
  DELETE FROM MEDEX  WHERE CodMedex = RecId;
  NotifyModif(2, RECID, &apos;MEDEX&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MEDEX FIELDS( CodMedex ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_MEDEX ( CodMedex, DataLista, Obs )
    ( SELECT CodMedex, DataLista, Obs
      FROM MEDEX WHERE CodMedex = RecId ) ;

  INSERT INTO TMP_MEDEX_TARI
  (
   CODMEDEXT,
   CODMEDEX, 
   COD,      
   TARA     
   )
   SELECT  
   CODMEDEXT,
   CODMEDEX, 
   COD,      
   TARA
   FROM MEDEX_TARI WHERE CodMedex = RecId;
   
   INSERT INTO TMP_MEDEX1
   (
    CODMEDEX1,       
    CODMEDEX,        
    CODCIM,         
    DENUMIRE,        
    PREZENTARE,      
    NARCOTIC,        
    FRACTIONAL,      
    SPECIAL,         
    AREBIOECHIVALENT,
    CANT,            
    PRETAM,
    PRETRID,        
    PRESCRIERE,      
    VALIDDELA,       
    VALIDPANALA,     
    DCI,             
    CONC,            
    FORMAFARM,       
    PRODUCATOR,      
    TARA,            
    GRUPA           
   )
   SELECT
    CODMEDEX1,       
    CODMEDEX,        
    CODCIM,         
    DENUMIRE,        
    PREZENTARE,      
    NARCOTIC,        
    FRACTIONAL,      
    SPECIAL,         
    AREBIOECHIVALENT,
    CANT,            
    PRETAM,
    PRETRID,        
    PRESCRIERE,      
    VALIDDELA,       
    VALIDPANALA,     
    DCI,             
    CONC,            
    FORMAFARM,       
    PRODUCATOR,      
    TARA,            
    GRUPA
   FROM MEDEX1 WHERE CodMedex = RecId;
   
   INSERT INTO TMP_MEDEX2
   (
    CODMEDEX2,
    CODMEDEX,    
    TIPCOMPENS,  
    CODCIM,      
    CODBOALA,    
    PRETAM,      
    PRETAMUT,    
    COPLATA,     
    COPLATA90,   
    PRETRID,     
    PRETREF,     
    LEGISPECIALE,
    APROBARE,    
    VALPESTE,    
    SPECIALITATE,
    INSULINA,    
    DCI,         
    GRUPA,       
    VALIDDELA,   
    VALIDPANALA,
    nhpCode 
   )
   SELECT
    CODMEDEX2,
    CODMEDEX,    
    TIPCOMPENS,  
    CODCIM,      
    CODBOALA,    
    PRETAM,      
    PRETAMUT,    
    COPLATA,     
    COPLATA90,   
    PRETRID,     
    PRETREF,     
    LEGISPECIALE,
    APROBARE,    
    VALPESTE,    
    SPECIALITATE,
    INSULINA,    
    DCI,         
    GRUPA,       
    VALIDDELA,   
    VALIDPANALA,
    nhpCode
   FROM MEDEX2 WHERE CodMedex = RecId; 
    
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodMedex INTO RecId FROM TMP_MEDEX;
    UPDATE MEDEX SET ( DataLista, Obs )
       = ( SELECT DataLista, Obs
          FROM TMP_MEDEX )
      WHERE CodMedex = RecId ;

    DELETE FROM MEDEX1 C1 where C1.CodMedex = RecId and not exists (Select TMP.CodMedex1 from TMP_MEDEX1 TMP WHERE TMP.CodMedex1 = C1.CodMedex1 );
    INSERT INTO MEDEX1 
    ( 
     CODMEDEX1,        
     CODMEDEX,        
     CODCIM,          
     DENUMIRE,         
     PREZENTARE,      
     NARCOTIC,        
     FRACTIONAL,      
     SPECIAL,         
     AREBIOECHIVALENT,
     CANT,            
     PRETAM,          
     PRETRID,         
     PRESCRIERE,      
     VALIDDELA,       
     VALIDPANALA,     
     DCI,             
     CONC,            
     FORMAFARM,       
     PRODUCATOR,      
     TARA,            
     GRUPA           
     )
    SELECT  
     SEQ_MEDEX1_CODMEDEX1.Nextval, 
     RecId,
     CODCIM,          
     DENUMIRE,         
     PREZENTARE,      
     NARCOTIC,        
     FRACTIONAL,      
     SPECIAL,         
     AREBIOECHIVALENT,
     CANT,            
     PRETAM,          
     PRETRID,         
     PRESCRIERE,      
     VALIDDELA,       
     VALIDPANALA,     
     DCI,             
     CONC,            
     FORMAFARM,       
     PRODUCATOR,      
     TARA,            
     GRUPA
    FROM TMP_MEDEX1 WHERE CodMedex1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_MEDEX1 WHERE NVL(CodMedex1,-1) &gt; 0 ORDER BY CodMedex1 ) LOOP
       UPDATE MEDEX1
       SET
        CODCIM           = v_Rec.Codcim,          
        DENUMIRE         = v_rec.DENUMIRE,         
        PREZENTARE       = v_Rec.Prezentare,      
        NARCOTIC         = v_Rec.Narcotic,        
        FRACTIONAL       = v_rec.FRACTIONAL,      
        SPECIAL          = v_Rec.SPECIAL,         
        AREBIOECHIVALENT = v_rec.AREBIOECHIVALENT,
        CANT             = v_Rec.CANT,            
        PRETAM           = v_Rec.Pretam,          
        PRETRID          = v_rec.PRETRID,         
        PRESCRIERE       = v_Rec.PRESCRIERE,      
        VALIDDELA        = v_rec.VALIDDELA,       
        VALIDPANALA      = v_Rec.VALIDPANALA,     
        DCI              = v_Rec.DCI,             
        CONC             = v_Rec.CONC,            
        FORMAFARM        = FORMAFARM,       
        PRODUCATOR       = v_Rec.PRODUCATOR,      
        TARA             = v_rec.TARA,            
        GRUPA            = v_Rec.GRUPA
       WHERE CodMedex1  = v_rec.CodMedex1;
    END LOOP;
  
    DELETE FROM MEDEX2 C2 where C2.CodMedex = RecId and not exists (Select TMP.CodMedex2 from TMP_MEDEX2 TMP WHERE TMP.CodMedex2 = C2.CodMedex2 );
    INSERT INTO MEDEX2 
    ( 
     CODMEDEX2,     
     CODMEDEX,    
     TIPCOMPENS,  
     CODCIM,      
     CODBOALA,    
     PRETAM,      
     PRETAMUT,    
     COPLATA,     
     COPLATA90,   
     PRETRID,     
     PRETREF,     
     LEGISPECIALE,
     APROBARE,    
     VALPESTE,    
     SPECIALITATE,
     INSULINA,    
     DCI,         
     GRUPA,       
     VALIDDELA,   
     VALIDPANALA ,
     nhpCode
    )
    SELECT  
     SEQ_MEDEX2_CODMEDEX2.Nextval, 
     RecId,
     TIPCOMPENS,  
     CODCIM,      
     CODBOALA,    
     PRETAM,      
     PRETAMUT,    
     COPLATA,     
     COPLATA90,   
     PRETRID,     
     PRETREF,     
     LEGISPECIALE,
     APROBARE,    
     VALPESTE,    
     SPECIALITATE,
     INSULINA,    
     DCI,         
     GRUPA,       
     VALIDDELA,   
     VALIDPANALA,
     nhpCode
    FROM TMP_MEDEX2 WHERE CodMedex2 &lt; 0;
    FOR v_rec IN ( SELECT * FROM TMP_MEDEX2 WHERE NVL(CodMedex2,-1) &gt; 0 ORDER BY CodMedex2 ) LOOP
       UPDATE MEDEX2
       SET
        TIPCOMPENS   = v_rec.TIPCOMPENS,  
        CODCIM       = v_rec.CODCIM,      
        CODBOALA     = v_Rec.CODBOALA,    
        PRETAM       = v_Rec.PRETAM,      
        PRETAMUT     = v_rec.PRETAMUT,    
        COPLATA      = v_rec.COPLATA,     
        COPLATA90    = v_rec.COPLATA90,   
        PRETRID      = v_Rec.PRETRID,     
        PRETREF      = v_rec.PRETREF,
        LEGISPECIALE = v_rec.LEGISPECIALE,
        APROBARE     = v_Rec.APROBARE,    
        VALPESTE     = v_Rec.VALPESTE,    
        SPECIALITATE = v_Rec.SPECIALITATE,
        INSULINA     = v_Rec.INSULINA,    
        DCI          = v_Rec.DCI,         
        GRUPA        = v_Rec.GRUPA,       
        VALIDDELA    = v_Rec.VALIDDELA,   
        VALIDPANALA  = v_Rec.VALIDPANALA,
        nhpCode      = v_rec.nhpcode
       WHERE CodMedex2  = v_rec.CodMedex2;
    END LOOP;
    
    DELETE FROM MEDEX_TARI T where T.CodMedex = RecId and not exists (Select TMP.CodMedexT from TMP_MEDEX_TARI TMP WHERE TMP.CodMedexT = T.CodMedexT );
    INSERT INTO MEDEX_TARI
    ( 
     CODMEDEXT,
     CODMEDEX, 
     COD,      
     TARA     
    )
    SELECT  
     SEQ_MEDEXT_CODMEDEXT.Nextval, 
     RecId,
     COD,
     TARA
    FROM TMP_MEDEX_TARI WHERE CodMedexT &lt; 0;
    FOR v_rec IN ( SELECT * FROM TMP_MEDEX_TARI WHERE NVL(CodMedexT,-1) &gt; 0 ORDER BY CodMedexT ) LOOP
       UPDATE MEDEX_TARI
       SET
        COD  = v_Rec.Cod,      
        TARA = v_Rec.Tara
       WHERE CodMedexT  = v_rec.CodMedexT;
    END LOOP;
  
  ELSE 

  SELECT seq_medex_codmedex.NextVal INTO RecId FROM DUAL;
  INSERT INTO MEDEX ( CodMedex, DataLista, Obs )
 ( SELECT  RecId, DataLista, Obs
     FROM TMP_MEDEX  ) ;

  INSERT INTO MEDEX1 
    ( 
     CODMEDEX1,        
     CODMEDEX,        
     CODCIM,          
     DENUMIRE,         
     PREZENTARE,      
     NARCOTIC,        
     FRACTIONAL,      
     SPECIAL,         
     AREBIOECHIVALENT,
     CANT,            
     PRETAM,          
     PRETRID,         
     PRESCRIERE,      
     VALIDDELA,       
     VALIDPANALA,     
     DCI,             
     CONC,            
     FORMAFARM,       
     PRODUCATOR,      
     TARA,            
     GRUPA           
     )
    SELECT  
     SEQ_MEDEX1_CODMEDEX1.Nextval, 
     RecId,
     CODCIM,          
     DENUMIRE,         
     PREZENTARE,      
     NARCOTIC,        
     FRACTIONAL,      
     SPECIAL,         
     AREBIOECHIVALENT,
     CANT,            
     PRETAM,          
     PRETRID,         
     PRESCRIERE,      
     VALIDDELA,       
     VALIDPANALA,     
     DCI,             
     CONC,            
     FORMAFARM,       
     PRODUCATOR,      
     TARA,            
     GRUPA
    FROM TMP_MEDEX1;
    
    INSERT INTO MEDEX2 
    ( 
     CODMEDEX2,     
     CODMEDEX,    
     TIPCOMPENS,  
     CODCIM,      
     CODBOALA,    
     PRETAM,      
     PRETAMUT,    
     COPLATA,     
     COPLATA90,   
     PRETRID,     
     PRETREF,     
     LEGISPECIALE,
     APROBARE,    
     VALPESTE,    
     SPECIALITATE,
     INSULINA,    
     DCI,         
     GRUPA,       
     VALIDDELA,   
     VALIDPANALA,
     nhpCode 
    )
    SELECT  
     SEQ_MEDEX2_CODMEDEX2.Nextval, 
     RecId,
     TIPCOMPENS,  
     CODCIM,      
     CODBOALA,    
     PRETAM,      
     PRETAMUT,    
     COPLATA,     
     COPLATA90,   
     PRETRID,     
     PRETREF,     
     LEGISPECIALE,
     APROBARE,    
     VALPESTE,    
     SPECIALITATE,
     INSULINA,    
     DCI,         
     GRUPA,       
     VALIDDELA,   
     VALIDPANALA,
     nhpCode
    FROM TMP_MEDEX2;

    INSERT INTO MEDEX_TARI
    ( 
     CODMEDEXT,
     CODMEDEX, 
     COD,      
     TARA     
    )
    SELECT  
     SEQ_MEDEXT_CODMEDEXT.Nextval, 
     RecId,
     COD,
     TARA
    FROM TMP_MEDEX_TARI;
    
END IF;
 NotifyModif(OPERATION, RECID, &apos;MEDEX&apos;);  

 COMMIT;
END;  

end pkg_medex; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MENUDASH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA499DDF7B7C3DE8774F0F5B790CEBF3E0BB2329</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MENUDASH IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodMenuDash INTO Tmp FROM MENUDash WHERE CodMenuDash = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
CP NUMBER(20);
aListID number(20);
BEGIN
  SP_LOCKRECORD(RecId);
  select listid into aListId 
  from menuDash 
  where CodMenuDash = recid;

--  DELETE LISTS WHERE LISTID = ALISTID;
--  DELETE LISTCALC WHERE LISTID = ALISTID;
--  DELETE LISTCOLS WHERE LISTID = ALISTID;
--  DELETE LISTGRAF WHERE LISTID = ALISTID;
--  DELETE LISTGROUPS WHERE LISTID = ALISTID;
--  DELETE LISTPIVOT WHERE LISTID = ALISTID;
--  DELETE LISTSQL WHERE LISTID = ALISTID;
--  DELETE LISTTITS WHERE LISTID = ALISTID;
  
  DELETE FROM MENUDash WHERE CodMenuDash = RecId;
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MENUDash FIELDS( CodMenuDash ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_MENUDash ( CodMenuDash, Caption, Modul, Menu, Prog, Uni, listid )
    ( SELECT CodMenuDash, Caption, Modul, Menu, Prog, Uni, listid
      FROM MENUDash WHERE CodMenuDash = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
CP NUMBER(20);
aListID number(20) := 0;
cnt number(20);
BEGIN
  
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodMenuDash INTO RecId FROM TMP_MENUDash;
        
    UPDATE MENUDash SET ( Caption, Modul, Menu, Prog, Uni, listid)
       = ( SELECT Caption, Modul, Menu, Prog, Uni, listid
          FROM TMP_MENUDash )
      WHERE CodMenuDash = RecId ;
   
  ELSE  

  SELECT SEQ_MENUDash_CODMENUDash.NextVal INTO RecId FROM DUAL;
  INSERT INTO  MENUDash ( CodMenuDash, Caption, Modul, Menu, Prog, Uni, listid )
 ( SELECT RecId, Caption, Modul, Menu, Prog, Uni, listid
     FROM TMP_MENUDash  ) ;
  END IF;

  COMMIT;
END;

end pkg_menuDASH; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MENUDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28DC95179D1F4ADCD4AF8C5358112DE3369C8594</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MENUDATE IS


  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
   TMP NUMBER(20);
  BEGIN
    SELECT CODMENUDATE INTO TMP FROM MENUDATE WHERE CODMENUDATE = RECID FOR UPDATE NOWAIT;
  END;
  
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  BEGIN
    DELETE FROM MENUDATE1 WHERE CODMENUDATE = RECID;
    DELETE FROM MENUDATE  WHERE CODMENUDATE = RECID;
    NotifyModif(2, RECID, &apos;MENUDATE&apos;);  
    COMMIT;
  END;
  
  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_MENUDATE(CODMENUDATE) VALUES(0);
    INSERT INTO TMP_MENUDATE1(CODMENUDATE1) VALUES(0);
    COMMIT;
  END;
  
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
  BEGIN
    INSERT INTO TMP_MENUDATE(CODMENUDATE,DEN_MENU,USERID,Nrbuton) 
     SELECT CODMENUDATE,DEN_MENU,USERID,nrbuton FROM MENUDATE WHERE CODMENUDATE = RECID;
     
    INSERT INTO TMP_MENUDATE1(CODMENUDATE1, CODMENUDATE, DEN_MENU, ACTION,Indexlocal)
       SELECT CODMENUDATE1, CODMENUDATE, DEN_MENU, ACTION ,indexlocal FROM MENUDATE1 WHERE CODMENUDATE = RECID order by indexlocal; 
    commit; 
  END;
  
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  BEGIN
    IF OPERATION = 0 THEN -- UPDATE
      SELECT CODMENUDATE INTO RECID FROM TMP_MENUDATE;
      
      UPDATE MENUDATE M SET (M.DEN_MENU,M.USERID,M.NRBUTON) = 
       (SELECT T.DEN_MENU, T.USERID,T.NRBUTON FROM TMP_MENUDATE T)
      WHERE M.CODMENUDATE = RECID;
      
      DELETE FROM MENUDATE1 M1 WHERE M1.CODMENUDATE = RECID AND 
                                  NOT EXISTS (SELECT T1.CODMENUDATE FROM TMP_MENUDATE1 T1 WHERE M1.CODMENUDATE1 = T1.CODMENUDATE1);
      
      FOR V_REC IN (SELECT * FROM TMP_MENUDATE1) LOOP
        UPDATE MENUDATE1 M1 SET
          M1.DEN_MENU   = V_REC.DEN_MENU,
          M1.ACTION     = V_REC.ACTION,
          M1.INDEXLOCAL = V_REC.INDEXLOCAL
        WHERE M1.CODMENUDATE1 = V_REC.CODMENUDATE1  ;
      END LOOP;
      
      INSERT INTO MENUDATE1(CODMENUDATE1,CODMENUDATE,DEN_MENU,ACTION,INDEXLOCAL)
       SELECT SEQ_MENUDATE1_CODMENUDATE1.NEXTVAL,RECID,DEN_MENU,ACTION,INDEXLOCAL FROM TMP_MENUDATE1 WHERE CODMENUDATE1 &lt; 0;
        
    ELSE -- INSERT
      
      SELECT SEQ_MENUDATE_CODMENUDATE.NEXTVAL INTO RECID FROM DUAL;
      
      INSERT INTO MENUDATE(CODMENUDATE,DEN_MENU,USERID,NRBUTON)
       SELECT RECID,DEN_MENU,PKG_GLOBALS.GETUSERID,NRBUTON FROM TMP_MENUDATE;
       
      INSERT INTO MENUDATE1(CODMENUDATE1,CODMENUDATE,DEN_MENU,ACTION,INDEXLOCAL)
       SELECT SEQ_MENUDATE1_CODMENUDATE1.NEXTVAL,RECID,DEN_MENU,ACTION,INDEXLOCAL FROM TMP_MENUDATE1;
      
    END IF;
    
   NotifyModif(OPERATION, RECID, &apos;MENUDATE&apos;);  
   COMMIT; 
  END;

 FUNCTION GETBUTOANE(nrBtn in number) RETURN CRS IS
 CRESULT CRS;
 BEGIN
   BEGIN
       OPEN CRESULT FOR 
         SELECT NRBUTON FROM (  
          SELECT LEVEL NRBUTON FROM DUAL CONNECT BY LEVEL &lt;= nrBtn
           MINUS
          SELECT NRBUTON FROM MENUDATE WHERE   USERID = PKG_GLOBALS.GETUSERID
         ) ORDER BY NRBUTON; 
           
--        SELECT DISTINCT NRBUTON FROM  MENUDATE WHERE USERID = PKG_GLOBALS.GETUSERID;
   EXCEPTION WHEN OTHERS THEN 
       OPEN CRESULT FOR SELECT 0 FROM DUAL;
   END;
   RETURN CRESULT;
  END;
  
     
  FUNCTION GETUSERMENU RETURN CRS IS 
  CRESULT  CRS;
  BEGIN
    BEGIN
        OPEN CRESULT FOR
          SELECT M.DEN_MENU,M.NRBUTON, M1.DEN_MENU SUBMENIU,M1.ACTION
          FROM MENUDATE M INNER JOIN MENUDATE1 M1 ON M.CODMENUDATE = M1.CODMENUDATE 
          WHERE M.USERID = PKG_GLOBALS.GETUSERID
          ORDER BY M.NRBUTON;
    EXCEPTION WHEN OTHERS THEN
      OPEN CRESULT FOR SELECT 0 FROM DUAL;
    END ;
    
    RETURN CRESULT;        
  END;
      

 
end pkg_menudate; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MESE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35123F2512C895E3F5289E894509DD7A77C34B6A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MESE is


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODMASA INTO Tmp FROM MESE WHERE CODMASA = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  -- steregere detalii masa
  DELETE FROM MESE1 WHERE CODMASA = RecId ;

  DELETE FROM MESE WHERE CODMASA = RecId ;


  NotifyModif(2, RECID, &apos;MESE&apos;);  
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MESE FIELDS( CODMASA ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_MESE(CODMASA, CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, WIDTH, HEIGHT, MODPLATAIMPLICIT, PROTOCOL) 
  SELECT CODMASA, CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, WIDTH, HEIGHT, MODPLATAIMPLICIT, PROTOCOL
  FROM 
    MESE
  WHERE 
    CODMASA = RecId  ;

  UPDATE TMP_MESE M
  SET
    DENSALA = (SELECT DENUMIRE FROM SALI S WHERE S.CODSALA = M.CODSALA);


  INSERT INTO TMP_MESE1 (CODMASA1, CODMASA, CODOSPATAR, OSPATAR)
  SELECT CODMASA1, 
         CODMASA, 
         CODOSPATAR, 
         NUME || &apos; &apos; || PRENUME 
  FROM 
    MESE1 M1, 
    OSPATARI O, 
    NPERS P 
  WHERE 
    CODMASA = RECID
    AND M1.CODOSPATAR = O.COD
    AND O.CODPERS = P.CODPERS ;
  


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  
    SELECT  CODMASA INTO RecId FROM TMP_MESE;

    UPDATE MESE
    SET
      (CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, MODPLATAIMPLICIT, PROTOCOL) = (SELECT CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, MODPLATAIMPLICIT, PROTOCOL FROM TMP_MESE)
    WHERE 
      CODMASA = RECID;
      

    DELETE FROM MESE1 WHERE CODMASA = RECID AND CODMASA1 NOT IN (SELECT CODMASA1 FROM TMP_MESE1);

    FOR V_REC IN (SELECT * FROM  TMP_MESE1) LOOP
      IF V_REC.CODMASA1 &lt; 0 THEN
        INSERT INTO MESE1 (CODMASA1, CODMASA, CODOSPATAR)
        VALUES (SEQ_MESE1_CODMASA1.NEXTVAL, RECID, V_REC.CODOSPATAR);
      ELSE
        UPDATE MESE1
        SET
          CODOSPATAR = V_REC.CODOSPATAR
        WHERE
          CODMASA1 = V_REC.CODMASA1;  
      END IF;   
    END LOOP;    

  ELSE  
    SELECT SEQ_MESE_CODMASA.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO MESE(CODMASA, CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, MODPLATAIMPLICIT, PROTOCOL)
    SELECT RECID, CODSALA, INDEXLOCAL, NUMARLOCURI, TEXTAFISARE, FORMA, MODPLATAIMPLICIT, PROTOCOL FROM TMP_MESE;


    INSERT INTO MESE1 (CODMASA1, CODMASA, CODOSPATAR)
      SELECT SEQ_MESE1_CODMASA1.NEXTVAL, RECID, CODOSPATAR FROM TMP_MESE1;



  END IF;

  NotifyModif(OPERATION, RECID, &apos;MESE&apos;);  

  COMMIT;
END;





end PKG_MESE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42D0C89D12368563AFFEA422E66282E2BC676F93</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MFCLASIF IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodClasif INTO Tmp FROM MFCLASIF WHERE CodClasif = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) 
IS
BEGIN
  SP_LOCKRECORD(RecId);

  DELETE FROM MFCLASIF WHERE CodClasif = RecId ;
  NotifyModif(2, RECID, &apos;MFCLASIF&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MFCLASIF FIELDS( CodClasif ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_MFCLASIF SELECT * FROM MFCLASIF WHERE CODCLASIF = RECID;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODCLASIF INTO RECID FROM TMP_MFCLASIF;

    UPDATE MFCLASIF
    SET
      (DENUMIRE, SIMBOL, DURATA, DURATAF, DURATAG) = (SELECT DENUMIRE, SIMBOL, DURATA, DURATAF, DURATAG FROM TMP_MFCLASIF)
    WHERE CodClasif = RecId ;
  ELSE  -- INSERT
  SELECT SEQ_MFCLASIF_CODCLASIF.NEXTVAL INTO RECID FROM DUAL;
  INSERT INTO  MFCLASIF (CODCLASIF, SIMBOL, DENUMIRE, DURATA, DURATAF, DURATAG )
  ( SELECT  RecId, SIMBOL, DENUMIRE, DURATA, DURATAF, DURATAG FROM TMP_MFCLASIF  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;MFCLASIF&apos;);  

  COMMIT;
END;

END PKG_MFCLASIF; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA05B1AADC8DB99550A9CA5AA2AB152EAE13259D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MIFIX IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_15&apos;;

function GETNRINVENTARNS_EXT(aCODNIRSTOC in number, aCODNIRSER in number) return varchar2 is
NrInv varchar2(2000);
begin
  begin
    select SUBSTR(string_agg(mf.nrinventar), 1, 2000) into NrInv
    from mifix mf inner join mifix1 mf1 on mf1.codmifix = mf.codmifix
    where mf1.codnirstoc = acodnirstoc
      and nvl(mf1.codnirser,0) = acodnirser
      and mf1.codmifix1 = (select max(mf2.codmifix1) from mifix1 mf2 where mf2.codmifix = mf.codmifix and mf2.codnirstoc = acodnirstoc and nvl(mf2.codnirser,0) = acodnirser)
    group by  mf1.codnirstoc, nvl(mf1.codnirser,0);  
  exception when others then
    NrInv := &apos;&apos;;
  end;
  return NrInv;
end;


function GETNRINVENTARNS(aCODNIRSTOC in number, aCODNIRSER in number) return number is
NrInv number(20);
begin
  begin
    select mf.nrinventar into NrInv
    from mifix mf inner join mifix1 mf1 on mf1.codmifix = mf.codmifix
    where mf1.codnirstoc = acodnirstoc
      and nvl(mf1.codnirser,0) = acodnirser
      and mf1.codmifix1 = (select max(mf2.codmifix1) from mifix1 mf2 where mf2.codmifix = mf.codmifix and mf2.codnirstoc = acodnirstoc and nvl(mf2.codnirser,0) = acodnirser);
  exception when others then
    NrInv := 0;
  end;
  return NrInv;
end;

procedure PROPAGANEXT(aCodMifix in number, Tip in number) is
vcodclasif number(20);
vstare number(5);
vduratan number(10);
vdurataf number(10);
vduratanf number(10);
vduratang number(10);
vCodCentru number(20);
vCodNirStoc number(20);
begin
  select codclasif, stare, durataf, duratan, duratanf, duratang, codcentru, codnirstoc
  into vcodclasif, vstare, vdurataf, vduratan, vduratanf, vduratang, vCodCentru, vCodNirStoc
  from mifix1
  where codmifix = aCodMifix and anstart*12+lunastart = pkg_globals.getanlucru*12+pkg_globals.getlunalucru;

  if Tip = 0 then
    update mifix1 set
      codclasif = vcodclasif,
      stare     = vstare,
      duratanf  = vduratanf,
      duratang  = vduratang,
      duratan   = vduratan
    where codmifix = aCodMifix and anstart*12+lunastart &gt; pkg_globals.getanlucru*12+pkg_globals.getlunalucru;
    update mifix1 set
      codcentru = vCodCentru
    where codmifix = aCodMifix and codnirstoc = vCodNirStoc and anstart*12+lunastart &gt; pkg_globals.getanlucru*12+pkg_globals.getlunalucru;
  else if Tip = 3 then
    update mifix1 set
      codcentru = vCodCentru
    where codmifix = aCodMifix and codnirstoc = vCodNirStoc and anstart*12+lunastart &gt; pkg_globals.getanlucru*12+pkg_globals.getlunalucru;
  end if; end if;
  commit;
end;

procedure InConservare(aCodMifix1 in number) is  pragma autonomous_transaction;
begin
  update mifix1 set stare = 2 where codmifix1 = acodmifix1;
  update jurnal1 set dirty = 1 where coddoc = (select codmifix from mifix1 where codmifix1 = aCodMifix1) and tipdoc = 36;
  commit;
end;

procedure empty_mifix_temptables is
begin
  delete tmp_mastermifix;
  delete tmp_mifix;
  delete tmp_mifixtransf;
  delete tmp_fisamf;
  delete tmp_jurnal;
  delete tmp_jurnal1;
  delete tmp_rulaj;
  commit;
end;

procedure GenMasterMifixDinReevaluare(aCodNirStoc in number) is
aCodFiu number(20);
begin
  begin
    select codnirstoc into aCodFiu from nirstoc where codnirstocparinte = aCodNirStoc;
  exception when others then aCodFiu := 0;
  end;
  if aCodFiu &gt; 0 then
    insert into mastermifix(codnirstoc, codclasif, duratan, duratanf, duratang, codanaliza)
    select aCodFiu, codclasif, duratan, duratanf, duratang, codanaliza
    from mastermifix where codnirstoc = aCodNirStoc;
    commit;
  end if;
end;

procedure Casare(aCodMifix1 in number, aCodIes in number) is  pragma autonomous_transaction;
begin
  update mifix1 set stare = 3 where codmifix1 = acodmifix1;
  for v_rec in (select l.datalivr, NIR.GEST, NS.PRET, i.NRDOC, i.PREFIXDOC, l1.CANT, i1.CODIES1, I.TIPDOC, MFIX1.CODMIFIX,
                       mfix1.anstart, mfix1.lunastart
                from nirstoc ns
                     inner join livr1 l1 on l1.codnirstoc = ns.codnirstoc
                     inner join iesiri1 i1 on i1.codies1 = l1.codies1
                     inner join iesiri i on i.codies = i1.codies
                     inner join livr l on l.codies = i.codies and l1.codlivr = l.codlivr
                     INNER JOIN mifix1 mfix1 ON mfix1.CODNIRSTOC = ns.codnirstoc
                     inner join nir on nir.codnir = ns.codnir
                where mfix1.codmifix1 = acodMifix1 and i.codies = aCodIes) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      V_rec.CODMIFIX,
      4,
      V_REC.DATALIVR,
      V_REC.GEST,
      V_REC.GEST,
      V_REC.PRET,
      V_REC.PRET,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= v_rec.anstart*12+v_rec.lunastart;
    EXIT;
  end loop;
  commit;
end;

procedure Vindere(aCodMifix1 in number, aCodIes in number) is  pragma autonomous_transaction;
begin
  update mifix1 set stare = 4 where codmifix1 = acodmifix1;
  for v_rec in (select l.datalivr, NIR.GEST, NS.PRET, i.NRDOC, i.PREFIXDOC, l1.CANT, i1.CODIES1, I.TIPDOC, MFIX1.CODMIFIX,
                       mfix1.anstart, mfix1.lunastart
                from nirstoc ns
                     inner join livr1 l1 on l1.codnirstoc = ns.codnirstoc
                     inner join iesiri1 i1 on i1.codies1 = l1.codies1
                     inner join iesiri i on i.codies = i1.codies
                     inner join livr l on l.codies = i.codies and l1.codlivr = l.codlivr
                     INNER JOIN mifix1 mfix1 ON mfix1.CODNIRSTOC = ns.codnirstoc
                     inner join nir on nir.codnir = ns.codnir
                where mfix1.codmifix1 = acodMifix1 and i.codies = aCodIes) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      V_rec.CODMIFIX,
      5,
      V_REC.DATALIVR,
      V_REC.GEST,
      V_REC.GEST,
      V_REC.PRET,
      V_REC.PRET,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= v_rec.anstart*12+v_rec.lunastart;
    EXIT;
  end loop;

  commit;
end;

procedure UPDATEMIFIXSTRUCT(aCodNirStocVechi in number, aCodNirStocNou in number, aCodMifix1 in number,
                            aCodCentru in number, aAn in number, aLuna in number, aCodClasif in number,
                            aStare in number, aTipOperatie in number) is pragma autonomous_transaction;
aCod number(20);
aCount number(10);
aCodMifix number(20);
aDurataF number;
aDurata number;
aDurataG number;
OldCodClasif number(20);
aCodClasifBlocat number(1);
begin
  aCodClasifBlocat := 0;
  if aTipOperatie = 12 then aCodClasifBlocat := 1; end if;
  BEGIN
    SELECT DURATA, DURATAF, DURATAG INTO aDurata, aDURATAF, aDurataG FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
  exception when others then
    aDurata := 0;
    aDurataF := 0;
    aDurataG := 0;
  END;
  begin
    select codmifix into aCodMifix from mifix1 where codmifix1 = aCodMifix1;
  exception when others then aCodMifix := 0;
  end;
  if aCodMifix &gt; 0 then
    select count(*) into aCount from mifix1 where anstart = aAn and lunastart = aLuna and codmifix = aCodMifix;
    if aCount = 0 then
      select seq_mifix1_codmifix1.nextval into aCod from dual;
      select codclasif into OldCodClasif from mifix1 where codmifix1 = aCodMifix1;
      if OldCodClasif &lt;&gt; aCodClasif then
        insert into mifix1(
              codmifix1, codmifix, codnirstoc, pret, cant, codclasif, tipamo, stare, duratan, gradu, durataf,
              amo, neutil, dfblocat, codpers, anstart, lunastart, codnirser, tipreeval, datareeval, includrata,
              amovechi, pretvechi, neutilvechi, codpart, codlocatie, codanalizanod, codcentru, duratanf, durataff,
              amof, duratang, duratafg, amog, dfblocat_f, dfblocat_g, pretinitial, pretinitial_f, pretinitial_fblocat, rezerva, rezervablocat, codsablon, amoblocat)
        select aCod, codmifix, aCodNirStocNou, pret, cant, codclasif, tipamo, aStare, adurata, gradu, adurata * 12,
               amo, neutil, dfblocat, codpers, aAn, aLuna, codnirser, tipreeval, datareeval, includrata,
               amovechi, pretvechi, neutilvechi, codpart, codlocatie, codanalizanod, aCodCentru, durataf, adurataf * 12,
               amof, aduratag, aduratag * 12, amog, dfblocat_f, dfblocat_g, pretinitial, pretinitial_f, pretinitial_fblocat, rezerva, rezervablocat, codsablon, amoblocat
        from mifix1
        where codmifix1 = aCodMifix1;
        if aCodClasifBlocat = 1 then
          update mifix1 set codclasifblocat = 1 where codmifix1 = aCod;
        end if;
      else
        insert into mifix1(
               codmifix1, codmifix, codnirstoc, pret, cant, codclasif, tipamo, stare, duratan, gradu, durataf,
               amo, neutil, dfblocat, codpers, anstart, lunastart, codnirser, tipreeval, datareeval, includrata,
               amovechi, pretvechi, neutilvechi, codpart, codlocatie, codanalizanod, codcentru, duratanf, durataff,
               amof, duratang, duratafg, amog, dfblocat_f, dfblocat_g, pretinitial, pretinitial_f, pretinitial_fblocat, rezerva, rezervablocat, codsablon, amoblocat)
        select aCod, codmifix, aCodNirStocNou, pret, cant, codclasif, tipamo, aStare, duratan, gradu, durataf,
               amo, neutil, dfblocat, codpers, aAn, aLuna, codnirser, tipreeval, datareeval, includrata,
               amovechi, pretvechi, neutilvechi, codpart, codlocatie, codanalizanod, aCodCentru, duratanf, durataff,
               amof, duratang, duratafg, amog, dfblocat_f, dfblocat_g, pretinitial, pretinitial_f, pretinitial_fblocat, rezerva, rezervablocat, codsablon, amoblocat
        from mifix1
        where codmifix1 = aCodMifix1;
      end if;
    else
      select codclasif into OldCodClasif from mifix1 where anstart = aAn and lunastart = aLuna and codmifix = aCodMifix;
      if OldCodClasif &lt;&gt; aCodClasif then
        update mifix1
        set
          codclasif = aCodClasif,
          codnirstoc = aCodNirStocNou,
          Stare = aStare,
          durataf = adurata * 12,
          durataff = adurataf * 12,
          duratafg = aduratag * 12,
          duratan = adurata,
          duratanf = adurataf,
          duratang = aduratag,
          CodCentru = aCodCentru
        where anstart = aAn and lunastart = aLuna and codmifix = aCodMifix;
        if aCodClasifBlocat = 1 then
          update mifix1 set codclasifblocat = 1 where anstart = aAn and lunastart = aLuna and codmifix = aCodMifix;
        end if;
      else
        update mifix1
        set
          codclasif = aCodClasif,
          codnirstoc = aCodNirStocNou,
          Stare = aStare,
          CodCentru = aCodCentru
        where anstart = aAn and lunastart = aLuna and codmifix = aCodMifix;
      end if;
    end if;

    select count(*) into acount from mastermifix where codnirstoc = acodnirstocnou;
    if acount &gt; 0 then
      update mastermifix set codclasif = aCodClasif, codnirstoc = aCodNirStocNou, duratan = adurata, duratanf = adurataf, duratang = aduratag where codnirstoc = aCodNirStocNou;
      if OldCodClasif &lt;&gt; aCodClasif and aCodClasifBlocat = 1 then
        update mastermifix set codclasifblocat = 1 where codnirstoc = aCodNirStocNou;
      end if;
    else
      insert into mastermifix(codnirstoc,
                              codclasif,
                              duratan,
                              duratanf,
                              duratang,
                              codanaliza)
      select aCodNirStocNou,
             acodclasif,
             adurata,
             adurataf,
             aduratag,
             codanaliza
      from mastermifix where codnirstoc = acodnirstocvechi;
      if OldCodClasif &lt;&gt; aCodClasif and aCodClasifBlocat = 1 then
        update mastermifix set codclasifblocat = 1 where codnirstoc = aCodNirStocNou;
      end if;
    end if;
    commit;
  end if;
end;

procedure NewFisaMFFromTransf(aCodNirStoc in number, aCodMifix in number, aCodOperatie in number) is pragma autonomous_transaction;
begin
  for v_rec in (select nir.datanir, NIR.GEST, NS.PRET, T.NRDOC, T.PREFIXDOC, NS.REST CANT, T1.CODTRANSF1, T.TIPDOC
                from nirstoc ns
                     inner join nir on nir.codnir = ns.codnir
                     INNER JOIN transf t ON NIR.CODTRANSF = T.CODTRANSF
                     INNER JOIN TRANSF1 T1 ON NS.CODTRANSF1 = T1.CODTRANSF1
                where ns.codnirstoc = acodnirstoc) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      ACODMIFIX,
      aCodOperatie,
      V_REC.DATANIR,
      V_REC.GEST,
      V_REC.GEST,
      V_REC.PRET,
      V_REC.PRET,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODTRANSF1,
      V_REC.TIPDOC
      );
    EXIT;
  end loop;
  commit;
end;


function NEWMIFIX(aCodNirStoc in number, aCodClasif in number, aCodCentru in number, aNrInventar in number, aAn in number, aLuna in number) return number is
aDurataN number;
aDurataF number;
aDurataG number;
aCodMifix number(20);
aTipAmo  NUMBER := 1;
aAnMax number(4);
aLunaMax number(2);
begin
  BEGIN
    SELECT DURATA * 12, DURATAF * 12, DURATAG * 12 INTO aDURATAN, aDurataF, aDurataG FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
  exception when others then aDurataN := 0;
  END;

  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipAmoOI&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipAmo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aTIPAMO := 1;
  END;

  select AnMaxim, LunaMaxima into aAnMax, aLunaMax
  from firmaluni;

  INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG)
  VALUES (aCODNIRSTOC, aCODCLASIF, aDURATAN, aDurataF, aDurataG);

  SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

  INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, RESTIMBMF, ANINTRAREG, LUNAINTRAREG)
  VALUES (aCODMIFIX, &apos;MF&apos;, aNrInventar, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, 0, aAn, aLuna);


  INSERT INTO MIFIX1(CODMIFIX1,
                     CODMIFIX,
                     CODNIRSTOC,
                     PRET,
                     CANT,
                     CODCLASIF,
                     TIPAMO,
                     STARE,
                     DURATAN,
                     GRADU,
                     DURATAF,
                     AMO,
                     DFBLOCAT,
                     ANSTART,
                     LUNASTART,
                     DFBLOCAT_F,
                     DFBLOCAT_G,
                     CODCENTRU)
  VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
         aCODMIFIX,
         aCODNIRSTOC,
         0,
         1,
         aCODCLASIF,
         aTIPAMO,
         5,
         aDURATAN,
         100,
         0,
         0,
         1,
         aAn,
         aLuna,
         1,
         1,
         aCodCentru);


  for v_rec in (select nir.datanir, NIR.GEST, NS.PRET, I.NRDOC, I.PREFIXDOC, NS.REST CANT, I1.CODIES1, I.TIPDOC
                from nirstoc ns
                     inner join nir on nir.codnir = ns.codnir
                     INNER JOIN IESIRI I ON NIR.CODIES = I.CODIES
                     INNER JOIN INTRARI1 IN1 ON NS.CODINTR1 = IN1.CODINTR1
                     INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
                     INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1 AND I.CODIES = I1.CODIES
                where ns.codnirstoc = acodnirstoc) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      ACODMIFIX,
      1,
      V_REC.DATANIR,
      0,
      V_REC.GEST,
      V_REC.PRET,
      0,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    EXIT;
  end loop;

  commit;
  return aCodMifix;
end;

 PROCEDURE SP_POST_REEVAL(DATADOC IN VARCHAR2, TIP IN NUMBER, aCODDOC1 IN NUMBER, aTIPDOC IN NUMBER)
IS
  NR NUMBER(10) := 0;
  aCODNIRSTOCNOU NUMBER(20, 0);
  aCODNIRSERNOU  NUMBER(20, 0);
  aPRETNOU       NUMBER(20, 7) := 0;
  aNEUTIL        NUMBER(20, 7) := 0;
  aTIPREEVAL     NUMBER(10)    := 0;
BEGIN
  DELETE FROM TMP_JURNAL  WHERE TIPDOC &lt;&gt; 36;
  DELETE FROM TMP_JURNAL1 WHERE TIPDOC &lt;&gt; 36;
  aTIPREEVAL := TIP;

  FOR V_REC IN
   (SELECT TMP.*, T.NRDOC NRDOCTRANSF
    FROM TMP_MIFIX TMP
         LEFT JOIN TRANSF T ON T.CODTRANSF = TMP.NRDOCREEVAL
    WHERE (PRETREEVAL IS NOT NULL AND PRETREEVAL &lt;&gt; PRET)OR(AMOREEVAL IS NOT NULL AND AMOREEVAL &lt;&gt; AMO)OR(aTIPREEVAL = 1))
  LOOP

    IF V_REC.CODNIRSTOCNOU &lt; 0 THEN
      BEGIN
        SELECT CODNOU INTO  aCODNIRSTOCNOU FROM TMP_NIRSTOC_RECOD WHERE CODVECHI = V_REC.CODNIRSTOCNOU;
        EXCEPTION WHEN OTHERS THEN aCODNIRSTOCNOU := V_REC.CODNIRSTOCNOU;
      END;
    ELSE
      aCODNIRSTOCNOU := V_REC.CODNIRSTOCNOU;
    END IF;

    IF V_REC.PRETREEVAL IS NULL THEN aPRETNOU := V_REC.PRET;
    ELSE
     aPRETNOU := V_REC.PRETREEVAL;
    END IF;


   IF V_REC.NEUTILREEVAL IS NULL THEN aNEUTIL := V_REC.NEUTIL;
   ELSE
     aNEUTIL := V_REC.NEUTILREEVAL;
   END IF;
   
    SELECT MIN(CODNIRSER) INTO aCODNIRSERNOU FROM NIRSER WHERE CODNIRSTOC =aCODNIRSTOCNOU;

    UPDATE MIFIX1
    SET
     CODNIRSTOC  = aCODNIRSTOCNOU,
     CODNIRSER   = aCODNIRSERNOU,
     PRETVECHI   = V_REC.PRET,
     PRETINITIAL = CASE
                     WHEN NVL(PRETINITIAL, 0) = 0 THEN V_REC.PRET
                     ELSE PRETINITIAL
                   END,
     PRETINITIAL_F = CASE
                     WHEN NVL(PRETINITIAL_F, 0) = 0 THEN V_REC.PRET
                     ELSE PRETINITIAL_F
                   END,
     PRET        = aPRETNOU,
     NEUTIL      = aNEUTIL,
     AMOVECHI    = V_REC.AMOINI,
     AMO         =  CASE
                    WHEN NVL(V_REC.TIPREEVAL, 0) = 1 AND NVL(V_REC.INCLUDRATA, 0) = 1 THEN V_REC.AMOINI
                    WHEN NVL(V_REC.TIPREEVAL, 0) = 0 AND NVL(V_REC.INCLUDRATA, 0) = 1 THEN V_REC.AMOINI + (V_REC.AMOREEVAL - V_REC.AMO )
                    ELSE V_REC.AMOREEVAL
                  END,



     INCLUDRATA = V_REC.INCLUDRATA,
     DATAREEVAL = TO_DATE(DATADOC,&apos;dd.mm.yyyy&apos;),
     TIPREEVAL  = TIP
    WHERE
    CODMIFIX1 = V_REC.CODMIFIX1 AND ANSTART = PKG_GLOBALS.ANLUCRU AND LUNASTART = PKG_GLOBALS.LUNALUCRU;


-- MODIFIC POZITIILE DIN LUNILE URMATOARE
     UPDATE MIFIX1
     SET
       CODNIRSTOC = aCODNIRSTOCNOU,
       PRET       = aPRETNOU,
       NEUTIL     = aNEUTIL
     WHERE
         CODMIFIX   = V_REC.CODMIFIX
     AND CODNIRSTOC = V_REC.CODNIRSTOC
     AND ANSTART * 12 + LUNASTART &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;



--    IF V_REC.PRETREEVAL IS NULL THEN
      INSERT INTO FISAMF
      (CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CODDOC1, TIPDOC, CANT)
      VALUES
      (SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, 6, V_REC.DATAREEVAL, V_REC.CODGEST, V_REC.CODGEST, V_REC.PRET, V_REC.PRETREEVAL, &apos;PV&apos;, V_REC.NRDOCTRANSF, aCODDOC1, aTIPDOC, V_REC.CANT);
--    END IF;

/*
    IF V_REC.AMOREEVAL IS NOT NULL THEN
      INSERT INTO FISAMF
      (CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC)
      VALUES
      (SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, 7, V_REC.DATAREEVAL, V_REC.CODGEST, V_REC.CODGEST, V_REC.AMO, V_REC.AMOREEVAL, &apos;PV&apos;, V_REC.NRDOCREEVAL);
    END IF;
*/

  END LOOP;

  -- detail JURNAlL1
  DELETE FROM JURNAl1 WHERE TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND CODDOC IN (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL) AND CODJURNAL1 NOT IN
  (SELECT CODJURNAL1 FROM TMP_JURNAl1);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET
      CODDOC       = V_REC.CODDOC,
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,

      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,

      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      VALOAREGRUP   = V_REC.VALOAREGRUP,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      DIRTY         = V_REC.DIRTY,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      DATADOC       = V_REC.DATADOC
    WHERE
      CODJURNAL1 = V_REC.CODJURNAl1;
   ELSE
     INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC )
     VALUES
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC);
   END IF;
  END LOOP;


  -- detail JURNAL

  DELETE
  FROM
  JURNAL
  WHERE TIPDOC = 36 AND
  AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
  AND CODDOC IN (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL) AND CODJURNAL NOT IN
  (SELECT CODJURNAL FROM TMP_JURNAL);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
   IF V_REC.CODJURNAL &gt; 0 THEN
    UPDATE JURNAL
    SET
      CODDOC     = V_REC.CODDOC,
      TIPDOC     = V_REC.TIPDOC,
      INDEXLOCAL = V_REC.INDEXLOCAL,
      CONTD      = V_REC.CONTD,
      CONTC      = V_REC.CONTC,
      GEST       = V_REC.GEST,
      VALOARE    = V_REC.VALOARE,
      VALOAREV   = V_REC.VALOAREV,
      VALOAREGRUP=v_rec.VALOAREGRUP,
      OBS        = V_REC.OBS,
      AN         = V_REC.AN,
      LUNA       = V_REC.LUNA,
      SUBUNITATEA= V_REC.SUBUNITATEA,
      CODAnalizaNod = v_rec.CODAnalizaNod,
      CODCENTRU  = v_rec.CODCENTRU,
      DATADOC    = V_REC.DATADOC,
      DOCUMENT   = V_REC.DOCUMENT
    WHERE
      CODJURNAL = V_REC.CODJURNAl;
   ELSE
   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODAnalizaNod, CODCENTRU, DATADOC, DOCUMENT)
   VALUES
   ( SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODAnalizaNod, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
   END IF;
  END LOOP;

-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 END LOOP;



  COMMIT;
END;


PROCEDURE LOCKNUMARINV(aTIP IN VARCHAR2, aNUMARINV IN NUMBER)
IS
BEGIN
  INSERT INTO NRINVLOCK (CODINVLOCK, TIP, USEDNO, USERID, SUBUNITATEA)
  VALUES (SEQ_NRINVLOCK_CODINVLOCK.NEXTVAL, aTIP, aNUMARINV, PKG_GLOBALS.USERID, pkg_globals.GETSUBUNITATE_DOC);
-- COMMIT-ul se face la nivel de tranzactie
END;




PROCEDURE UNLOCKNRINV
IS
BEGIN
  DELETE FROM NRINVLOCK
  WHERE
  USERID    = PKG_GLOBALS.USERID;
-- COMMIT-ul se face la nivel de tranzactie
END;



FUNCTION GETNEXTNRINV(aTIP IN VARCHAR2) RETURN NUMBER
IS
Tmp NUMBER(20) := 0;
BEGIN
  if (pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 1)
     and (pkg_categconst.GetValConstanta(&apos;HoldingNrInv&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU) = 2) then
    SELECT COALESCE(MAX(LASTNR), 0) INTO TMP FROM
    (
      SELECT MAX(USEDNO) AS LASTNR FROM NRINVLOCK nl WHERE nl.TIP = aTIP and nl.subunitatea = pkg_globals.GETSUBUNITATE_DOC
      UNION ALL
      select COALESCE(max(mf.nrinventar),0) AS LASTNR
        from mifix mf
        join mifix1 mf1
            on mf1.codmifix = mf.codmifix
        join nirstoc ns
            on ns.codnirstoc = mf1.codnirstoc
        join nir n
            on n.codnir = ns.codnir
        join ngest ng
            on ng.codgest = n.gest
        where mf.TIP = aTIP
              and ng.codsubunit = pkg_globals.GETSUBUNITATE_DOC
     );     
  else
    SELECT NVL(MAX(LASTNR), 0) INTO TMP FROM
    (
      SELECT MAX(USEDNO) AS LASTNR FROM NRINVLOCK WHERE TIP = aTIP
      UNION ALL
      SELECT MAX(NRINVENTAR) AS LASTNR FROM MIFIX WHERE TIP = aTIP
    );
  end if;  
  RETURN TMP + 1;
END;

FUNCTION  GetINFOMFIMB(aCodMifixImb IN NUMBER) RETURN VARCHAR2
IS
  vINFOMFIMB VARCHAR2(500) := &apos;&apos;;
BEGIN
  IF Nvl(aCodMifixImb,0) &lt;&gt; 0 THEN
    SELECT MF.NRINVENTAR || &apos; &apos; || O.DENUMIRE INTO vINFOMFIMB
    FROM (SELECT CODMIFIX, Max(CODNIRSTOC) KEEP(Dense_Rank LAST ORDER BY ANSTART * 12 + LUNASTART) CODNIRSTOC FROM MIFIX1 WHERE CODMIFIX = aCodMifixImb GROUP BY CODMIFIX) M1
      INNER JOIN MIFIX MF ON MF.CODMIFIX = M1.CODMIFIX
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT;
  END IF;
  RETURN vINFOMFIMB;
EXCEPTION
  WHEN OTHERS THEN RETURN NULL;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  BEGIN
    SELECT CODNIRSTOC INTO Tmp FROM MASTERMIFIX WHERE CODNIRSTOC = RecId FOR UPDATE NOWAIT;
    EXCEPTION WHEN OTHERS THEN TMP := 0;
  END;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  NR NUMBER(10) := 0;
  aDoc varchar2(200);

  ANL   NUMBER(5);
  ANM   NUMBER(5);
  LUNAL NUMBER(5);
  LUNAM NUMBER(5);
  ANI   NUMBER(5);
  LUNAI NUMBER(5);
BEGIN

  PKG_GLOBALS.MarkDirtyJurnal;

  SP_LOCKRECORD(RecId);
  DELETE TMP_MANEVRA;
  DELETE TMP_MANEVRA_LISTE;
  
  INSERT INTO TMP_MANEVRA_LISTE
    (FILTRU, VALOARE, FILTRU1, VALOARE1,FILTRU2, VALOARE2)
    (SELECT distinct &apos;CODMIFIX&apos;, mf1.CODMIFIX, &apos;CODAUTO&apos;, mf1.codauto, &apos;NRINV&apos;, mf.NRINVENTAR
       FROM MIFIX1 mf1
       JOIN MIFIX  mf ON mf.CODMIFIX = mf1.CODMIFIX
      WHERE mf1.CODNIRSTOC = RecId
        AND ANSTART * 12 + LUNASTART &gt;=
            PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU);
            
  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = RecId AND ANSTART * 12 + LUNASTART  &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU)
  LOOP
    --sterg extensii ciudate mifix hard
    IF PKG_LIST_STRUCT.TmpExists(&apos;MIFIX1EXT&apos;) = 1  THEN
       EXECUTE IMMEDIATE &apos;DELETE FROM MIFIX1EXT WHERE CODMIFIX1 =&apos; || V_REC.CODMIFIX1;
    END IF;
    DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC.CODMIFIX1 ;
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (V_REC.CODMIFIX);
  END LOOP;

 BEGIN
   SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;
   EXCEPTION WHEN OTHERS THEN ANI := 0; LUNAI := 0;
 END;

 IF PKG_GLOBALS.ANLUCRU = ANI AND PKG_GLOBALS.LUNALUCRU = LUNAI THEN
    INSERT INTO TMP_MANEVRA_LISTE
    (FILTRU, VALOARE, FILTRU1, VALOARE1, FILTRU2, VALOARE2)
    (SELECT distinct &apos;CODMIFIX&apos;,
                     mf1.CODMIFIX,
                     &apos;CODAUTO&apos;,
                     mf1.codauto,
                     &apos;NRINV&apos;,
                     mf.NRINVENTAR
       FROM MIFIX1 mf1
       JOIN MIFIX mf
         ON mf.CODMIFIX = mf1.CODMIFIX
      WHERE mf1.CODNIRSTOC = RecId
        AND mf1.ANSTART * 12 + mf1.LUNASTART &lt;
            PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU);
  FOR V_REC IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = RecId AND ANSTART * 12 + LUNASTART  &lt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU)
  LOOP
    --sterg extensii ciudate mifix hard
    IF PKG_LIST_STRUCT.TmpExists(&apos;MIFIX1EXT&apos;) = 1  THEN
       EXECUTE IMMEDIATE &apos;DELETE FROM MIFIX1EXT WHERE CODMIFIX1 =&apos; || V_REC.CODMIFIX1;
    END IF;    
    DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC.CODMIFIX1 ;
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (V_REC.CODMIFIX);
  END LOOP;

 END IF;


  FOR V_REC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) LOOP
     SELECT COUNT(*) INTO NR FROM MIFIX1 WHERE CODMIFIX = V_REC.CODUNIC;
      IF NR = 0 THEN

        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
          begin
           select distinct &apos; rezolvare mifix nr inventar &apos;|| nrinventar into aDoc from mifix where codmifix = v_rec.codunic;
          exception when others then
            aDoc := &apos;nu am gasit numarul de inventar&apos;;
          end;
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;MIFIX&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    1, LAST_DAY(TO_DATE(&apos;01.&apos;||pkg_globals.LUNALUCRU||&apos;.&apos;||pkg_globals.ANLUCRU,&apos;DD.MM.YYYY&apos;)), aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);

        END IF;


      	DELETE FROM FISAMF WHERE CODMIFIX = V_REC.CODUNIC;
        BEGIN
          
          UPDATE MIFIX
          SET
            CODMIFIXNOU = NULL,
            ANLUNAMIFIXNOU = NULL
          WHERE
            CODMIFIXNOU =  V_REC.CODUNIC;
             
          DELETE FROM MIFIX  WHERE CODMIFIX = V_REC.CODUNIC;
          UPDATE nparcaut
             SET nrinv = null
           WHERE (codnparcaut, nrinv) IN
                 ( SELECT distinct tl.valoare1, tl.valoare2 
                    FROM tmp_manevra_liste tl
                   where tl.valoare = V_REC.CODUNIC );
          EXCEPTION WHEN OTHERS THEN NULL;
        END;
        DELETE FROM MASTERMIFIX WHERE CODNIRSTOC = RECID;
        FOR V_MF IN (SELECT CODBUGETMF FROM BUGETMF WHERE CODMIFIX = V_REC.CODUNIC) LOOP
          DELETE BUGETMF1 WHERE CODBUGETMF = V_MF.CODBUGETMF;
          DELETE BUGETMF WHERE CODBUGETMF = V_MF.CODBUGETMF;
        END LOOP;
      END IF;
  END LOOP;

  DELETE
  FROM
    MASTERMIFIX
  WHERE
    CODNIRSTOC = RECID AND NVL((SELECT COUNT(*) FROM MIFIX1 WHERE CODNIRSTOC = RECID), 0) = 0;
/*
  SELECT COUNT(*) INTO NR FROM MIFIX1 WHERE (CODNIRSTOC = RECID);
  IF NR = 0 THEN
  	DELETE FROM MIFIX  WHERE CODMIFIX IN (SELECT CODUNIC FROM TMP_MANEVRA);
    DELETE FROM MASTERMIFIX WHERE CODNIRSTOC = RECID;
  END IF;  */


  ANL := PKG_GLOBALS.ANLUCRU; LUNAL := PKG_GLOBALS.LUNALUCRU;
  BEGIN
    SELECT ANMAXIM, LUNAMAXIMA INTO ANM, LUNAM FROM FIRMALUNI;
    EXCEPTION WHEN OTHERS THEN ANM := ANL; LUNAM := LUNAL;
  END;


/*
  FOR V_REC IN
 (SELECT * FROM JURNAL WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  DELETE FROM JURNAL1 WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU ;
*/
  WHILE ANL * 12 + LUNAL &lt;= ANM * 12 + LUNAM
  LOOP
      FOR V_REC IN
     (SELECT * FROM JURNAL WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = ANL AND LUNA = LUNAL)
      LOOP
        UPDATE NCONTRUL
        SET
          RULAJCD  = RULAJCD  - V_REC.VALOARE,
          RULAJVCD = RULAJVCD - V_REC.VALOAREV
        WHERE
          CODCONT = V_REC.CONTD AND AN = ANL AND LUNA = LUNAL;

        FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
        LOOP
          UPDATE NCONTRULSUB
          SET
            RULAJCD  = RULAJCD  - V_REC.VALOARE,
            RULAJVCD = RULAJVCD - V_REC.VALOAREV
          WHERE
            CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
        END LOOP;


        UPDATE NCONTRUL
        SET
          RULAJCC  = RULAJCC  - V_REC.VALOARE,
          RULAJVCC = RULAJVCC - V_REC.VALOAREV
        WHERE
          CODCONT = V_REC.CONTC AND AN = ANL AND LUNA = LUNAL;


        FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
        LOOP
          UPDATE NCONTRULSUB
          SET
            RULAJCC  = RULAJCC  - V_REC.VALOARE,
            RULAJVCC = RULAJVCC - V_REC.VALOAREV
          WHERE
            CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
        END LOOP;
      END LOOP;

      DELETE FROM JURNAL  WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = ANL AND LUNA = LUNAL;
      DELETE FROM JURNAL1 WHERE CODDOC IN (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA) AND TIPDOC = 36 AND AN = ANL AND LUNA = LUNAL ;

      IF LUNAL = 12 THEN
        ANL := ANL + 1;
        LUNAL := 1;
      ELSE
        LUNAL := LUNAL + 1;
      END IF;


   END LOOP;


  NotifyModif(2, RECID, &apos;MIFIX&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_MASTERMIFIX FIELDS(CODNIRSTOC ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(36);  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD_FOR_REEVAL(aCODNIRSTOC IN NUMBER)
IS
aCODMIFIXVECHI NUMBER;
BEGIN
  DELETE TMP_MIFIX;
  INSERT INTO
    TMP_MIFIX
    (CODMIFIX,
     TIP,
     NRINVENTAR,
     ANINTRARE,
     LUNAINTRARE,
     CODMIFIX1,
     CODNIRSTOC,
     PRET,
     CANT,
     CODCLASIF,
     TIPAMO,
     STARE,
     DURATAN,
     GRADU,
     DURATAF,
     AMO,
     NEUTIL,
     DFBLOCAT,
     CODPERS,
     CODNIRSER,
     ANSTART,
     LUNASTART,
     CODIOART,
     CODGEST,
     SERIE,
     CODSERIE,
     CODNIRSTOCNOU,
     SUBUNITATEA,
     DENUMIRE,
     AMOLUNA,
     AMOINI,
     REZERVA,
     CODCENTRU,
     AMOREZERVA,
     AMORBLOCAT,
     AMOFBLOCAT,
     AMOGBLOCAT,
     PRETINIBLOCAT,
     pretinitial_fblocat
     )

   SELECT * FROM
   (
     (SELECT
        MF. CODMIFIX,
        MF.TIP,
        NRINVENTAR,
        ANINTRARE,
        LUNAINTRARE,
        CODMIFIX1,
        MF1.CODNIRSTOC,
        MF1.PRET,
        CANT,
        CODCLASIF,
        TIPAMO,
        MF1.STARE,
        DURATAN,
        GRADU,
        DURATAF,
        AMO,
        NEUTIL,
        DFBLOCAT,
        CODPERS,
        MF1.CODNIRSER,
        ANSTART,
        LUNASTART,
        NS.CODIOART,
        N.GEST,
        SER.SERIE,
        SER.CODSERIE,
        MF1.CODNIRSTOC AS CODNIRSTOCNOU,
        G.CODSUBUNIT,
        O.DENUMIRE,
        PKG_INCHIDERI.AMORTIZARELUNARA(MF.CODMIFIX, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) AS AMOLUNARA,
        MF1.AMO AS AMOINI,
        MF1.REZERVA,
        MF1.CODCENTRU,
        MF1.AMOREZERVA,
        MF1.AMORBLOCAT,
        MF1.AMOFBLOCAT,
        MF1.AMOGBLOCAT,
        MF1.PRETINIBLOCAT,
        MF1.pretinitial_fblocat
      FROM
        MIFIX MF,
        MIFIX1 MF1
        LEFT OUTER JOIN NIRSTOC NS   ON NS.CODNIRSTOC  = MF1.CODNIRSTOC
        LEFT OUTER JOIN NIR     N    ON N.CODNIR       = NS.CODNIR
        LEFT OUTER JOIN NGEST   G    ON G.CODGEST      = N.GEST
        LEFT OUTER JOIN NIRSER  NSER ON NSER.CODNIRSER = MF1.CODNIRSER
        LEFT OUTER JOIN NSERII  SER  ON SER.CODSERIE   = NSER.CODSERIE,
        NARTOBJ O
      WHERE
        MF.CODMIFIX = MF1.CODMIFIX AND MF1.CODNIRSTOC = aCODNIRSTOC AND
        MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
        AND O.CODOBIECT = NS.CODOBIECT
      )
    ORDER BY NRINVENTAR
    );
  UPDATE TMP_MIFIX
  SET
  CODTMPMIFIX = ROWNUM,
  AMO         = AMO + AMOLUNA,
  INCLUDRATA  = 1;

  DELETE TMP_JURNAL;
  DELETE TMP_JURNAL1;

  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 36 AND CODDOC IN(SELECT DISTINCT CODMIFIX FROM TMP_MIFIX) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 36 AND CODDOC IN(SELECT DISTINCT CODMIFIX FROM TMP_MIFIX) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

  DELETE TMP_RULAJ;
  DELETE TMP_MIFIX_INITIAL;
  INSERT INTO TMP_MIFIX_INITIAL (CODMIFIX) SELECT CODMIFIX FROM TMP_MIFIX;
  
  
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 NR             NUMBER(7);
 aCODCLASIF     NUMBER(20) := 0;
 aCODMIFIXVECHI NUMBER(20);
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = RecId;
  IF RECID &gt; 0 AND NR = 0 THEN
    INSERT INTO MASTERMIFIX (CODNIRSTOC) VALUES (RECID);
  END IF;


  INSERT INTO TMP_MASTERMIFIX SELECT * FROM MASTERMIFIX WHERE CODNIRSTOC = RECID;


  INSERT INTO
    TMP_MIFIX
    (CODMIFIX,
     TIP,
     NRINVENTAR,
     ANINTRARE,
     LUNAINTRARE,
     CODMIFIX1,
     CODNIRSTOC,
     PRET,
     CANT,
     CODCLASIF,
     TIPAMO,
     STARE,
     DURATAN,
     GRADU,
     DURATAF,
     AMO,
     NEUTIL,
     DFBLOCAT,
     CODPERS,
     CODNIRSER,
     ANSTART,
     LUNASTART,
     CODIOART,
     CODGEST,
     SERIE,
     TIPREEVAL,
     DATAREEVAL,
     INCLUDRATA,
     AMOVECHI,
     PRETVECHI,
     NEUTILVECHI,
     SUBUNITATEA,
     DENUMIRE,
     CODPART,
     CODLOCATIE,
     CODAnalizaNod, CODSablon, CODCENTRU,
     OBS,
     DURATANF,
     DURATAFF,
     AMOF,
     DURATANG,
     DURATAFG,
     AMOG,
     ANINTRAREG,
     LUNAINTRAREG,
     DFBlocat_F,
     DFBlocat_G,
     REZERVA,
     REZERVABLOCAT,
     SERIEINV,
     AMOBLOCAT,
     CODMIFIXIMB,
     CENTRUBLOCAT,
     CODCLASIFBLOCAT,
     CODPERSBLOCAT,
     NODANALIZABLOCAT,
     CODAUTO,
     AMOREZERVA,
     AMORBLOCAT,
     AMOFBLOCAT,
     AMOGBLOCAT,
     PRETINIBLOCAT,
     pretinitial_fblocat,
     PRETINITIAL,
     PRETINITIAL_F,
     CODLOCATIESTOC,
     UTILAJ,
     CODUTILAJ,
     TIPSTORNO,
     AMOANPREC
     )

   SELECT * FROM
   (
     (SELECT
        MF. CODMIFIX,
        MF.TIP,
        MF.NRINVENTAR,
        ANINTRARE,
        LUNAINTRARE,
        CODMIFIX1,
        MF1.CODNIRSTOC,
        MF1.PRET,
        CANT,
        CODCLASIF,
        TIPAMO,
        MF1.STARE,
        DURATAN,
        GRADU,
        DURATAF,
        AMO,
        NEUTIL,
        DFBLOCAT,
        CODPERS,
        MF1.CODNIRSER,
        ANSTART,
        LUNASTART,
        NS.CODIOART,
        N.GEST,
        SER.SERIE,
        TIPREEVAL,
        DATAREEVAL,
        INCLUDRATA,
        AMOVECHI,
        PRETVECHI,
        NEUTILVECHI,
        G.CODSUBUNIT,
        O.DENUMIRE,
        MF1.CODPART,
        MF1.CODLOCATIE,
        MF1.CODAnalizaNod, MF1.CODSablon, MF1.CODCENTRU,
        MF.OBS,
        MF1.DURATANF,
        MF1.DURATAFF,
        MF1.AMOF,
        MF1.DURATANG,
        MF1.DURATAFG,
        MF1.AMOG,
        MF.ANINTRAREG,
        MF.LUNAINTRAREG,
        DFBLOCAT_F,
        DFBLOCAT_G,
        REZERVA,
        REZERVABLOCAT,
        MF.SERIEINV,
        MF1.AMOBLOCAT,
        MF.CODMIFIXIMB,
        MF1.CENTRUBLOCAT,
        MF1.CODCLASIFBLOCAT,
        MF1.CODPERSBLOCAT,
        MF1.NODANALIZABLOCAT,
        MF1.CODAUTO,
        MF1.AMOREZERVA,
        MF1.AMORBLOCAT,
        MF1.AMOFBLOCAT,
        MF1.AMOGBLOCAT,
        MF1.PRETINIBLOCAT,
        MF1.pretinitial_fblocat,
        MF1.PRETINITIAL,
        MF1.PRETINITIAL_F,
        NS.CODLOCATIE CODLOCATIESTOC,
        U.ETICHETA||&apos;/&apos;||OU.DENUMIRE UTILAJ,
        U.CODUTILAJ,
        MF1.TIPSTORNO,
        MF1.AMOANPREC
      FROM
        MIFIX MF
        LEFT OUTER JOIN UTILAJE U    ON U.NRINVENTAR   = MF.Nrinventar
        LEFT OUTER JOIN NARTOBJ OU   ON U.CODOBIECT    = OU.CODOBIECT,
        MIFIX1 MF1
        LEFT OUTER JOIN NIRSTOC NS   ON NS.CODNIRSTOC  = MF1.CODNIRSTOC
        LEFT OUTER JOIN NIR     N    ON N.CODNIR       = NS.CODNIR
        LEFT OUTER JOIN NGEST   G    ON G.CODGEST      = N.GEST
        LEFT OUTER JOIN NIRSER  NSER ON NSER.CODNIRSER = MF1.CODNIRSER
        LEFT OUTER JOIN NSERII  SER  ON SER.CODSERIE   = NSER.CODSERIE,
        NARTOBJ O
      WHERE
        MF.CODMIFIX = MF1.CODMIFIX AND MF1.CODNIRSTOC = RECID AND
        MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
        AND O.CODOBIECT = NS.CODOBIECT
      )
    ORDER BY NRINVENTAR
    );

   UPDATE TMP_MIFIX M
   SET
    CODTMPMIFIX = ROWNUM,
    DENLOCATIE  = (SELECT OBS FROM NAGENDA WHERE CODAGENDA = M.CODLOCATIE),
    INFOMFIMB   = PKG_MIFIX.GetINFOMFIMB(M.CODMIFIXIMB);

   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 36 AND CODDOC IN(SELECT DISTINCT CODMIFIX FROM TMP_MIFIX) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 36 AND CODDOC IN(SELECT DISTINCT CODMIFIX FROM TMP_MIFIX) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

   DELETE TMP_RULAJ;
   DELETE TMP_MIFIX_INITIAL;
   INSERT INTO TMP_MIFIX_INITIAL (CODMIFIX) SELECT CODMIFIX FROM TMP_MIFIX;

   SELECT COUNT(*) INTO NR FROM TMP_MASTERMIFIX WHERE CODCLASIF IS NOT NULL;
   IF NR = 0 THEN
     UPDATE TMP_MASTERMIFIX SET CODCLASIF = (SELECT MIN(CODCLASIF) FROM TMP_MIFIX);
   END IF;

   SELECT COUNT(*) INTO NR FROM TMP_MASTERMIFIX WHERE DURATAN IS NOT NULL;
   IF NR = 0 THEN
     UPDATE TMP_MASTERMIFIX
     SET
     (DURATAN, DURATANF, DURATANG) = (SELECT MIN(DURATAN), MIN(DURATANF), MIN(DURATANG) FROM TMP_MIFIX);
   END IF;


     UPDATE TMP_MASTERMIFIX
     SET
     CODCLASIFBLOCAT = (SELECT MIN(NVL(CODCLASIFBLOCAT, 0)) FROM TMP_MIFIX);


  INSERT INTO TMP_FISAMF (CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, OBS, INFOOPERATIE, DENGESTSURSA, DENGESTDEST,
                          CODDOC1, TIPDOC)
  SELECT
    CODFISAMF,
    CODMIFIX,
    CODOPERATIE,
    DATAOPERATIE,
    GESTSURSA,
    GESTDEST,
    PRETI,
    PRETE,
    PREFIXDOC,
    NRDOC,
    CANT,
    OBS,
    (
    CASE
      WHEN CODOPERATIE = 1 THEN &apos;Creare mijloc fix&apos;
      WHEN CODOPERATIE = 2 THEN &apos;Transfer intre gestiuni&apos;
      WHEN CODOPERATIE = 3 THEN &apos;Modificare de pret&apos;
      WHEN CODOPERATIE = 4 THEN &apos;Casare&apos;
      WHEN CODOPERATIE = 5 THEN &apos;Vanzare&apos;
      WHEN CODOPERATIE = 6 THEN &apos;Reevaluare - valoare MF&apos;
      WHEN CODOPERATIE = 7 THEN &apos;Reevaluare - amortizare prec&apos;
      WHEN CODOPERATIE = 8 THEN &apos;Marire de stoc&apos;
      WHEN CODOPERATIE = 9 THEN &apos;Modificare gestiune&apos;
      WHEN CODOPERATIE = 10 THEN &apos;Modificare centru de cost&apos;
      WHEN CODOPERATIE = 11 THEN &apos;Modificare tip contabil&apos;
      WHEN CODOPERATIE = 12 THEN &apos;Punere in functiune&apos;
    END),
    (SELECT DEN_GEST FROM NGEST WHERE CODGEST = GESTSURSA),
    (SELECT DEN_GEST FROM NGEST WHERE CODGEST = GESTDEST),
    CODDOC1,
    TIPDOC
  FROM
    FISAMF
  WHERE
    CODMIFIX IN (SELECT CODMIFIX FROM TMP_MIFIX);

  DELETE TMP_FISAMF_INI;
  INSERT INTO TMP_FISAMF_INI SELECT * FROM TMP_FISAMF;

  BEGIN
    SELECT CODCLASIF INTO aCODCLASIF FROM TMP_MIFIX WHERE ROWNUM = 1;
    EXCEPTION WHEN OTHERS THEN aCODCLASIF := 0;
  END;
  IF aCODCLASIF &lt;&gt; 0 THEN
    UPDATE TMP_MASTERMIFIX
    SET
     CODCLASIF = aCODCLASIF;
  END IF;

--  delete x;
 
  FOR v_rec in (SELECT M1.* 
                FROM 
                  TMP_MIFIX M1
                  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
                  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR AND N.TIPNIR = 6
               )
  LOOP
  --  insert into x(view_name) values(&apos;1&apos;);  
    SELECT MIN(CODMIFIX) INTO aCODMIFIXVECHI 
    FROM MIFIX     
    WHERE CODMIFIXNOU = V_REC.CODMIFIX and ANLUNAMIFIXNOU = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
  --  insert into x(view_name) values(aCODMIFIXVECHI);  

    IF aCODMIFIXVECHI &gt; 0 THEN
      UPDATE TMP_MIFIX
      SET
        CODMIFIXVECHI = aCODMIFIXVECHI,
        NRINVENTARVECHI = (SELECT NRINVENTAR FROM MIFIX WHERE CODMIFIX = aCODMIFIXVECHI)
      WHERE
        CODMIFIX = V_REC.CODMIFIX;  
    END IF;  
  END LOOP;                    



  PKG_CFGTABLES.EXT_GOTORECORD(36);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 aCODMIFIX   NUMBER(20);
 NRTRANSF    NUMBER(10);
 I           NUMBER(10);
 NRMASTERMF  NUMBER(10);
 TIPMF       VARCHAR2(2);
 CANTTRANSF  NUMBER(20, 7);
 CANTRAMASA  NUMBER(20, 7);
 NR          NUMBER(20) := 0;
 NRMF        NUMBER(20) := 0;
 TRANSFERURI NUMBER(1)  := 0;
 TIPNIRNOU   NUMBER(5) := 0;
 GESTDEST    NUMBER(20) := 0;
 CODTRANSF1  NUMBER(20);
 TIPDOC      NUMBER(10);
 DATANIRDEST DATE;
 PRETDEST    NUMBER(20, 7);
 PREFIXDOCTRANSF VARCHAR2(2);
 NRDOCTRANSF NUMBER(20);

 aDoc varchar2(200);
 sOper varchar2(1);
 vcExt NUMBER(20);
BEGIN
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (36); 
  for v_rec in (select coalesce(mf1.codauto,0) codvechi, coalesce(tmp.codauto,0) codnou, tmp.nrinventar
                from tmp_mifix tmp
                     left join mifix mf on tmp.codmifix = mf.codmifix
                     left join mifix1 mf1 on mf1.codmifix = mf.codmifix and mf1.anstart*12+mf1.lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU
                where coalesce(mf1.codauto,0) &lt;&gt; coalesce(tmp.codauto,0)
                ) loop
    if v_rec.codvechi = 0 and v_Rec.Codnou &gt; 0 then
      update nparcaut set nrinv = null where nrinv = v_rec.nrinventar;
      update nparcaut set nrinv = v_rec.nrinventar where codnparcaut = v_rec.codnou;
    else if v_rec.codvechi &gt; 0 and v_Rec.Codnou = 0 then
      update nparcaut set nrinv = null where codnparcaut = v_rec.codvechi;
    else if v_rec.codvechi &gt; 0 and v_Rec.Codnou &gt; 0 then
      update nparcaut set nrinv = null where codnparcaut = v_rec.codvechi;
      update nparcaut set nrinv = v_rec.nrinventar where codnparcaut = v_rec.codnou;
    end if; end if; end if;
  end loop;
  IF OPERATION = 0 THEN  -- UPDATE

     SELECT CODNIRSTOC INTO RecId FROM TMP_MASTERMIFIX;
     BEGIN
       SELECT DISTINCT TIP INTO TIPMF FROM TMP_MIFIX;
       EXCEPTION WHEN OTHERS THEN TIPMF := &apos;MF&apos;;
     END;

     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

        begin
          select distinct &apos;rezolvare mifix nr inventar &apos;|| mf.nrinventar,&apos;S&apos; into aDoc,sOper from
          mifix mf inner join mifix1 mf1 on mf.codmifix = mf1.codmifix and mf1.codnirstoc = recid;
        exception when others then
          begin
           select distinct &apos;rezolvare mifix nr inventar &apos;|| mf.nrinventar,&apos;A&apos; into aDoc,sOper from
           tmp_mifix mf where mf.codnirstoc = recid;
          exception when others then
           aDoc := &apos;Nu am gasit nr inventar&apos;;
          end;
        end;

          WINMADMIN.PKG_USERFIRME.PostLog(&apos;MIFIX&apos;, PKG_GLOBALS.USERNAME, sOper, RECID,PKG_GLOBALS.FIRMANAME,
                                    1, LAST_DAY(TO_DATE(&apos;01.&apos;||pkg_globals.LUNALUCRU||&apos;.&apos;||pkg_globals.ANLUCRU,&apos;DD.MM.YYYY&apos;)), aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
     END IF;


     UPDATE MASTERMIFIX
     SET
      (CODCLASIF, DURATAN, DURATANF, DURATANG, CODCLASIFBLOCAT, CODANALIZA) =
      (SELECT CODCLASIF, DURATAN, DURATANF, DURATANG, CODCLASIFBLOCAT, CODANALIZA
       FROM
       TMP_MASTERMIFIX)
     WHERE
       CODNIRSTOC = RECID;


  -- REZOLV LINII PROVENITE DIN TRANSFERURI DE LA ALTE POZITII;
     FOR V_RECMF IN (SELECT * FROM TMP_MIFIX WHERE CODMIFIX1VECHI IS NOT NULL)  LOOP
       IF V_RECMF.CANT &lt; V_RECMF.CANTMIFIX1VECHI THEN
         UPDATE MIFIX1
         SET
           AMO          = (CANT - V_RECMF.CANT) * AMO           / V_RECMF.CANTMIFIX1VECHI  ,
           AMOREZERVA   = (CANT - V_RECMF.CANT) * AMOREZERVA    / V_RECMF.CANTMIFIX1VECHI  ,
           NEUTIL = (CANT - V_RECMF.CANT) * NEUTIL / V_RECMF.CANTMIFIX1VECHI  ,
           CANT   =  CANT - V_RECMF.CANT
         WHERE
         CODMIFIX1 = V_RECMF.CODMIFIX1VECHI;
       END IF;

       IF V_RECMF.CODNIRSTOCVECHI IS NOT NULL THEN
         UPDATE MIFIX1
         SET
          CODNIRSTOC = V_RECMF.CODNIRSTOC,
          PRET       = V_RECMF.PRET
         WHERE
          CODMIFIX = V_RECMF.CODMIFIX
          AND CODNIRSTOC = V_RECMF.CODNIRSTOCVECHI
          AND ANSTART * 12 + LUNASTART &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
       END IF;

     END LOOP;

     TRANSFERURI := 0;
  -- REZOLV TRANSFERURI LA ALTE POZITII
     FOR V_RECMF IN (SELECT * FROM TMP_MIFIX WHERE PLECAT = 1)  LOOP
       TRANSFERURI := 1;

       BEGIN
         SELECT COUNT(*) INTO NRTRANSF FROM TMP_MIFIXTRANSF WHERE CODTMPMIFIX = V_RECMF.CODTMPMIFIX;
         EXCEPTION WHEN OTHERS THEN NRTRANSF := 0;
       END;

       BEGIN
         SELECT SUM(CANTTRANSF) INTO CANTTRANSF FROM TMP_MIFIXTRANSF WHERE CODTMPMIFIX = V_RECMF.CODTMPMIFIX;
         EXCEPTION WHEN OTHERS THEN CANTTRANSF := 0;
       END;

       IF NRTRANSF &gt; 0  THEN
         I:= 1; CANTRAMASA := V_RECMF.CANT;
         FOR V_RECTRANSF IN (SELECT * FROM TMP_MIFIXTRANSF WHERE CODTMPMIFIX = V_RECMF.CODTMPMIFIX)
         LOOP
           IF I &lt; NRTRANSF THEN
             SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;
             UPDATE TMP_FISAMF SET CODMIFIX = aCODMIFIX WHERE CODMIFIX = V_RECMF.CODMIFIX;
             INSERT INTO MIFIX (CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE)
                              VALUES (aCODMIFIX, TIPMF,  0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
                              
             SELECT SEQ_MIFIX1_CODMIFIX1.NEXTVAL INTO vcExt FROM DUAL;
             PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;MIFIX&apos;, vcExt, V_RECMF.CODMIFIX1);
             INSERT INTO MIFIX1
             (CODMIFIX1,
              CODMIFIX,
              CODNIRSTOC,
              PRET,
              CANT,
              CODCLASIF,
              TIPAMO,
              STARE,
              DURATAN,
              GRADU,
              DURATAF,
              AMO,
              NEUTIL,
              DFBLOCAT,
              DFBLOCAT_F,
              DFBLOCAT_G,
              CODPERS,
              ANSTART,
              LUNASTART,
              CODNIRSER,
              CODPART,
              CODLOCATIE,
              CODAnalizaNod, CODSablon, CODCENTRU,
              AMOBLOCAT,
              CENTRUBLOCAT,
              CODCLASIFBLOCAT,
              CODPERSBLOCAT,
              NODANALIZABLOCAT,
              CODAUTO,
              AMOREZERVA,
              AMORBLOCAT,
              AMOFBLOCAT,
              AMOGBLOCAT,
              PRETINIBLOCAT,
              pretinitial_fblocat,
              PRETINITIAL,
              PRETINITIAL_F,
              TIPSTORNO,
              AMOANPREC
              )
             VALUES
             (vcExt,
              aCODMIFIX,
              V_RECTRANSF.CODNOUNIRSTOC,
              (SELECT PRET FROM NIRSTOC WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC),
              V_RECTRANSF.CANTTRANSF,
              V_RECMF.CODCLASIF,
              V_RECMF.TIPAMO,
              V_RECMF.STARE,
              V_RECMF.DURATAN,
              V_RECMF.GRADU,
              V_RECMF.DURATAF,
              V_RECTRANSF.CANTTRANSF * V_RECMF.AMO / V_RECMF.CANT  ,
              V_RECTRANSF.CANTTRANSF * V_RECMF.NEUTIL / V_RECMF.CANT ,
              V_RECMF.DFBLOCAT,
              V_RECMF.DFBLOCAT_F,
              V_RECMF.DFBLOCAT_G,
              V_RECMF.CODPERS,
              V_RECMF.ANSTART,
              V_RECMF.LUNASTART,
--            V_RECMF.CODNIRSER,
              (SELECT CODNIRSER FROM NIRSER WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC AND ROWNUM = 1),
              V_RECMF.CODPART,
              V_RECMF.CODLOCATIE,
              V_RECMF.CODAnalizaNod, V_RECMF.CODSablon, V_RECMF.CODCENTRU,
              V_RECMF.AMOBLOCAT,
              V_RECMF.CENTRUBLOCAT,
              V_RECMF.CODCLASIFBLOCAT,
              V_RECMF.CODPERSBLOCAT,
              V_RECMF.NODANALIZABLOCAT,
              V_RECMF.CODAUTO,
              V_RECMF.AMOREZERVA,
              V_RECMF.AMORBLOCAT,
              V_RECMF.AMOFBLOCAT,
              V_RECMF.AMOGBLOCAT,
              V_RECMF.PRETINIBLOCAT,
              V_RECMF.pretinitial_fblocat,
              V_RECMF.PRETINITIAL,
              V_RECMF.PRETINITIAL_F,
              V_RECMF.TIPSTORNO,
              V_RECMF.AMOANPREC
              );


             SELECT COUNT(*) INTO NRMASTERMF FROM MASTERMIFIX WHERE CODNIRSTOC =  V_RECTRANSF.CODNOUNIRSTOC;
             IF NRMASTERMF = 0 THEN
               INSERT INTO MASTERMIFIX (CODNIRSTOC, CODCLASIF, DURATAN) (SELECT V_RECTRANSF.CODNOUNIRSTOC, CODCLASIF, DURATAN FROM TMP_MASTERMIFIX);
             ELSE
               UPDATE MASTERMIFIX
               SET
                (CODCLASIF, DURATAN) = (SELECT CODCLASIF, DURATAN FROM TMP_MASTERMIFIX)
               WHERE
               CODNIRSTOC =  V_RECTRANSF.CODNOUNIRSTOC;
             END IF;

             UPDATE TMP_MIFIX
             SET
               AMO        = (CANT - V_RECTRANSF.CANTTRANSF) * AMO / CANT ,
               AMOREZERVA = (CANT - V_RECTRANSF.CANTTRANSF) * AMOREZERVA / CANT ,
               NEUTIL     = (CANT - V_RECTRANSF.CANTTRANSF) * NEUTIL / CANT ,
               CANT       = CANT - V_RECTRANSF.CANTTRANSF
             WHERE
              CODTMPMIFIX = V_RECMF.CODTMPMIFIX;

           ELSE
             IF CANTRAMASA = V_RECTRANSF.CANTTRANSF THEN
               UPDATE TMP_MIFIX SET
                 CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC,
                 PRET       = (SELECT PRET FROM NIRSTOC WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC),
                 AMO        = AMO  /*  * CANTRAMASA*/,
                 AMOREZERVA = AMOREZERVA  /*  * CANTRAMASA*/,
                 NEUTIL     = NEUTIL /** CANTRAMASA*/,
                 CANT       = CANTRAMASA,
                 CODNIRSER  = (SELECT CODNIRSER FROM NIRSER WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC)
               WHERE
               CODTMPMIFIX = V_RECMF.CODTMPMIFIX;


               UPDATE MIFIX1 SET
                 CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC,
                 PRET       = (SELECT PRET FROM NIRSTOC WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC),
                 CANT       = CANTRAMASA,
                 CODPART    = V_RECMF.CODPART,
                 CODLOCATIE = V_RECMF.CODLOCATIE,
                 CODAnalizaNod = V_RECMF.CODAnalizaNod,
                 CODSablon     = V_RECMF.CODSablon,
                 CODCENTRU     = V_RECMF.CODCENTRU,
                 CODAUTO       = V_RECMF.CODAUTO
               WHERE
                   CODMIFIX   = V_RECMF.CODMIFIX
               AND CODNIRSTOC = V_RECMF.CODNIRSTOC
               AND ANSTART * 12 + LUNASTART &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


               IF TIPMF = &apos;MF&apos; THEN
                 BEGIN
                   SELECT N.TIPNIR, N.GEST, T.DATADOC, NS.PRET, T.PREFIXDOC, T.NRDOC, T1.CODTRANSF1, T.TIPDOC
                   INTO TIPNIRNOU, GESTDEST, DATANIRDEST, PRETDEST, PREFIXDOCTRANSF, NRDOCTRANSF, CODTRANSF1, TIPDOC
                   FROM
                     NIRSTOC NS, NIR N, TRANSF T, TRANSF1 T1
                   WHERE
                     NS.CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC
                     AND N.CODNIR = NS.CODNIR
                     AND T.CODTRANSF = N.CODTRANSF
                     AND NS.CODTRANSF1 = T1.CODTRANSF1
                     AND T1.CODTRANSF = T.CODTRANSF
                     AND NS.CODNIR = N.CODNIR;
                   EXCEPTION WHEN OTHERS THEN TIPNIRNOU := 0; GESTDEST := 0; DATANIRDEST := TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;); PRETDEST := 0;
                   PREFIXDOCTRANSF := &apos; &apos;;
                   NRDOCTRANSF := 0;
                 END;

                 INSERT INTO TMP_FISAMF
                   (CODFISAMF,
                    CODMIFIX,
                    CODOPERATIE,
                    DATAOPERATIE,
                    GESTSURSA,
                    GESTDEST,
                    PRETI,
                    PRETE,
                    PREFIXDOC,
                    NRDOC,
                    CODDOC1,
                    TIPDOC
                    )
                    VALUES
                    (-1,
                     V_RECMF.CODMIFIX,
                    ( CASE
                        WHEN TIPNIRNOU = 12 THEN 2
                        ELSE 3
                      END
                    ),
                    DATANIRDEST,
                    V_RECMF.CODGEST,
                    GESTDEST,
                    V_RECMF.PRET,
                    PRETDEST,
                    PREFIXDOCTRANSF,
                    NRDOCTRANSF,
                    CODTRANSF1,
                    TIPDOC
                    );
               END IF;
             ELSE
               SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;
               UPDATE TMP_FISAMF SET CODMIFIX = aCODMIFIX WHERE CODMIFIX = V_RECMF.CODMIFIX;
               INSERT INTO MIFIX (CODMIFIX, TIP, NRINVENTAR,  ANINTRARE, LUNAINTRARE)
                                VALUES (aCODMIFIX, TIPMF,  0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
                                
               SELECT SEQ_MIFIX1_CODMIFIX1.NEXTVAL INTO vcExt FROM DUAL;
               PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;MIFIX&apos;, vcExt, V_RECMF.CODMIFIX1);
                                
               INSERT INTO MIFIX1 (CODMIFIX1, CODMIFIX, CODNIRSTOC, PRET, CANT, CODCLASIF, TIPAMO, STARE, DURATAN, GRADU, DURATAF,
                                   AMO, NEUTIL, DFBLOCAT, CODPERS, ANSTART, LUNASTART, CODNIRSER, CODPART, CODLOCATIE,CODAnalizaNod, CODSablon, CODCENTRU, REZERVA,  REZERVABLOCAT, AMOBLOCAT, CENTRUBLOCAT, CODCLASIFBLOCAT, CODPERSBLOCAT, NODANALIZABLOCAT, CODAUTO,
                                   AMOREZERVA, AMORBLOCAT, AMOFBLOCAT, AMOGBLOCAT, PRETINIBLOCAT, pretinitial_fblocat, PRETINITIAL, PRETINITIAL_F, TIPSTORNO, AMOANPREC)
                      VALUES (vcExt, aCODMIFIX, V_RECTRANSF.CODNOUNIRSTOC, (SELECT PRET FROM NIRSTOC WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC), V_RECTRANSF.CANTTRANSF,
                              V_RECMF.CODCLASIF, V_RECMF.TIPAMO, V_RECMF.STARE, V_RECMF.DURATAN, V_RECMF.GRADU, V_RECMF.DURATAF,
                              V_RECTRANSF.CANTTRANSF * V_RECMF.AMO / V_RECMF.CANT , V_RECTRANSF.CANTTRANSF * V_RECMF.NEUTIL / V_RECMF.CANT , V_RECMF.DFBLOCAT, V_RECMF.CODPERS, V_RECMF.ANSTART, V_RECMF.LUNASTART, (SELECT CODNIRSER FROM NIRSER WHERE CODNIRSTOC = V_RECTRANSF.CODNOUNIRSTOC AND ROWNUM=1), --V_RECMF.CODNIRSER,
                              V_RECMF.CODPART, V_RECMF.CODLOCATIE,V_RECMF.CODAnalizaNod, V_RECMF.CODSablon, V_RECMF.CODCENTRU, V_RECMF.REZERVA, V_RECMF.REZERVABLOCAT, V_RECMF.AMOBLOCAT, V_RECMF.CENTRUBLOCAT, V_RECMF.CODCLASIFBLOCAT, V_RECMF.CODPERSBLOCAT, V_RECMF.NODANALIZABLOCAT,
                              V_RECMF.CODAUTO, V_RECMF.AMOREZERVA, V_RECMF.AMORBLOCAT, V_RECMF.AMOFBLOCAT, V_RECMF.AMOGBLOCAT, V_RECMF.PRETINIBLOCAT, V_RECMF.pretinitial_fblocat, V_RECMF.PRETINITIAL, V_RECMF.PRETINITIAL_F, V_RECMF.TIPSTORNO, V_RECMF.AMOANPREC);

               UPDATE TMP_MIFIX
               SET
                 AMO        = (CANT - V_RECTRANSF.CANTTRANSF) * AMO / CANT,
                 AMOREZERVA = (CANT - V_RECTRANSF.CANTTRANSF) * AMOREZERVA / CANT,
                 NEUTIL     = (CANT - V_RECTRANSF.CANTTRANSF) * NEUTIL / CANT,
                 CANT       = CANT - V_RECTRANSF.CANTTRANSF
               WHERE
                CODTMPMIFIX = V_RECMF.CODTMPMIFIX;

-- :1 --
               UPDATE MIFIX1 SET
                 CANT   = CANT - V_RECTRANSF.CANTTRANSF
               WHERE
                   CODMIFIX   = V_RECMF.CODMIFIX
               AND CODNIRSTOC = V_RECMF.CODNIRSTOC
               AND ANSTART * 12 + LUNASTART &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
--:2 --

               SELECT COUNT(*) INTO NRMASTERMF FROM MASTERMIFIX WHERE CODNIRSTOC =  V_RECTRANSF.CODNOUNIRSTOC;
               IF NRMASTERMF = 0 THEN
                 INSERT INTO MASTERMIFIX (CODNIRSTOC, CODCLASIF, DURATAN) (SELECT V_RECTRANSF.CODNOUNIRSTOC, CODCLASIF, DURATAN FROM TMP_MASTERMIFIX);
               ELSE
                 UPDATE MASTERMIFIX
                 SET
                  (CODCLASIF, DURATAN) = (SELECT CODCLASIF, DURATAN FROM TMP_MASTERMIFIX)
                 WHERE
                 CODNIRSTOC =  V_RECTRANSF.CODNOUNIRSTOC;
               END IF;
             END IF;
           END IF;
           I := I + 1;
           CANTRAMASA := CANTRAMASA - V_RECTRANSF.CANTTRANSF;
         END LOOP;
       END IF;

     END LOOP; -- END REZOLVARE TRANSFERURI LA ALTE POZITII


     FOR V_REC IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = RECID AND ANSTART = PKG_GLOBALS.ANLUCRU AND LUNASTART = PKG_GLOBALS.LUNALUCRU AND CODMIFIX1 NOT IN (SELECT CODMIFIX1 FROM TMP_MIFIX))
     LOOP
       DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC.CODMIFIX1;


       SELECT COUNT(*) INTO NRMF FROM MIFIX1 WHERE CODMIFIX = V_REC.CODMIFIX;
       IF NRMF = 0 THEN
         DELETE FROM MIFIX  WHERE CODMIFIX  = V_REC.CODMIFIX;
       END IF;
     END LOOP;

     FOR V_REC IN (SELECT * FROM TMP_MIFIX) LOOP
       if coalesce(v_rec.codutilaj,0) = 0 then
         update utilaje set nrinventar = null where nrinventar = v_rec.nrinventar;
       else
         update utilaje set nrinventar = v_rec.nrinventar where codutilaj = v_rec.codutilaj;
       end if;
       IF V_REC.CODMIFIX &gt; 0 THEN
         UPDATE MIFIX
         SET
           TIP          = V_REC.TIP,
           NRINVENTAR   = V_REC.NRINVENTAR,
           SERIEINV     = V_REC.SERIEINV,
           CODMIFIXIMB  = V_REC.CODMIFIXIMB,
           OBS          = V_REC.OBS,
           ANINTRARE    = V_REC.ANINTRARE,
           LUNAINTRARE  = V_REC.LUNAINTRARE,
           ANINTRAREG   = V_REC.ANINTRAREG,
           LUNAINTRAREG = V_REC.LUNAINTRAREG,
           RestIMBMF   = CASE
                            WHEN NVL(V_REC.CODMIFIXIMB, 0) &lt;&gt; 0
                            THEN v_rec.PRET -
                              (SELECT NVL(SUM(IL.CANT), 0)
                               FROM
                                 IMBMIFIXLINK IL
                                 LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                                 LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                               WHERE
                                 IL.CODMIFIX = v_Rec.CODMIFIX AND T.OPERAT = 1 AND T.ANULAT = 0
                              )
                            ELSE 0
                         END

         WHERE
          CODMIFIX = V_REC.CODMIFIX;


         IF V_REC.CODMIFIX1 &gt; 0 THEN
          UPDATE MIFIX1 SET
            CODMIFIX   = V_REC.CODMIFIX,
            CODNIRSTOC = V_REC.CODNIRSTOC,
            PRET       = V_REC.PRET,
            CANT       = V_REC.CANT,
            CODCLASIF  = V_REC.CODCLASIF,
            TIPAMO     = V_REC.TIPAMO,
            STARE      = V_REC.STARE,
            DURATAN    = V_REC.DURATAN,
            GRADU      = V_REC.GRADU,
            DURATAF    = V_REC.DURATAF,
            AMO        = V_REC.AMO,
            NEUTIL     = V_REC.NEUTIL,
            DFBLOCAT   = V_REC.DFBLOCAT,
            AMOBLOCAT  = V_REC.AMOBLOCAT,
            CENTRUBLOCAT = V_REC.CENTRUBLOCAT,
            CODCLASIFBLOCAT = v_rec.codclasifblocat,
            CODPERSBLOCAT   = V_REC.CODPERSBLOCAT,
            NODANALIZABLOCAT = V_REC.NODANALIZABLOCAT,
            DFBLOCAT_F = V_REC.DFBLOCAT_F,
            DFBLOCAT_G = V_REC.DFBLOCAT_G,
            CODPERS    = V_REC.CODPERS,
            CODNIRSER  = V_REC.CODNIRSER,
            ANSTART    = V_REC.ANSTART,
            LUNASTART  = V_REC.LUNASTART,
            CODPART    = V_REC.CODPART,
            CODLOCATIE = V_REC.CODLOCATIE,
            CODAnalizaNod=V_REC.CODAnalizaNod,
            CODSablon  = V_REC.CODSablon,
            CODCENTRU  = V_REC.CODCENTRU,
            DURATANF   = V_REC.DURATANF,
            DURATANG   = V_REC.DURATANG,
            DURATAFF   = V_REC.DURATAFF,
            DURATAFG   = V_REC.DURATAFG,
            AMOF       = V_REC.AMOF,
            AMOG       = V_REC.AMOG,
            REZERVA       = V_REC.REZERVA,
            REZERVABLOCAT = V_REC.REZERVABLOCAT,
            CODAUTO       = V_REC.CODAUTO,
            AMOREZERVA    = V_REC.AMOREZERVA,
            AMORBLOCAT    = V_REC.AMORBLOCAT,
            AMOFBLOCAT    = V_REC.AMOFBLOCAT,
            AMOGBLOCAT    = V_REC.AMOGBLOCAT,
            PRETINIBLOCAT = V_REC.PRETINIBLOCAT,
            pretinitial_fblocat = V_REC.pretinitial_fblocat,
            PRETINITIAL   = V_REC.PRETINITIAL,
            PRETINITIAL_F = V_REC.PRETINITIAL_F,
            TIPSTORNO     = V_REC.TIPSTORNO,
            AMOANPREC     = V_REC.AMOANPREC
          WHERE
            CODMIFIX1 = V_REC.CODMIFIX1;
         ELSE
            SELECT SEQ_MIFIX1_CODMIFIX1.NEXTVAL INTO vcExt FROM DUAL;
            PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;MIFIX&apos;, vcExt, V_REC.CODMIFIX1);
            
            INSERT INTO MIFIX1
            (CODMIFIX1,
             CODMIFIX,
             CODNIRSTOC,
             PRET,
             CANT,
             CODCLASIF,
             TIPAMO,
             STARE,
             DURATAN,
             GRADU,
             DURATAF,
             AMO,
             NEUTIL,
             DFBLOCAT,
             DFBLOCAT_F,
             DFBLOCAT_G,
             CODPERS,
             CODNIRSER,
             ANSTART,
             LUNASTART,
             CODPART,
             CODLOCATIE,
             CODAnalizaNod, CODSablon, CODCENTRU,
             DURATANF,
             DURATANG,
             DURATAFF,
             DURATAFG,
             AMOF,
             AMOG,
             REZERVA,
             REZERVABLOCAT,
             AMOBLOCAT,
             CENTRUBLOCAT,
             CODCLASIFBLOCAT,
             CODPERSBLOCAT,
             NODANALIZABLOCAT,
             CODAUTO,
             AMOREZERVA,
             AMORBLOCAT,
             AMOFBLOCAT,
             AMOGBLOCAT,
             PRETINIBLOCAT,
             pretinitial_fblocat,
             PRETINITIAL,
             PRETINITIAL_F,
             TIPSTORNO,
             AMOANPREC
             )
             VALUES
             (vcExt,
              V_REC.CODMIFIX,
              V_REC.CODNIRSTOC,
              V_REC.PRET,
              V_REC.CANT,
              V_REC.CODCLASIF,
              V_REC.TIPAMO,
              V_REC.STARE,
              V_REC.DURATAN,
              V_REC.GRADU,
              V_REC.DURATAF,
              V_REC.AMO,
              V_REC.NEUTIL,
              V_REC.DFBLOCAT,
              V_REC.DFBLOCAT_F,
              V_REC.DFBLOCAT_G,
              V_REC.CODPERS,
              V_REC.CODNIRSER,
              V_REC.ANSTART,
              V_REC.LUNASTART,
              V_REC.CODPART,
              V_REC.CODLOCATIE,
              v_rec.CODAnalizaNod, V_REC.CODSablon, V_REC.CODCENTRU,
              V_REC.DURATANF,
              V_REC.DURATANG,
              V_REC.DURATAFF,
              V_REC.DURATAFG,
              V_REC.AMOF,
              V_REC.AMOG,
              V_REC.REZERVA,
              V_REC.REZERVABLOCAT,
              V_REC.AMOBLOCAT,
              V_REC.CENTRUBLOCAT,
              V_REC.CODCLASIFBLOCAT,
              V_REC.CODPERSBLOCAT,
              V_REC.NODANALIZABLOCAT,
              V_REC.CODAUTO,
              V_REC.AMOREZERVA,
              V_REC.AMORBLOCAT,
              V_REC.AMOFBLOCAT,
              V_REC.AMOGBLOCAT,
              V_REC.PRETINIBLOCAT,
              V_REC.pretinitial_fblocat,
              V_REC.PRETINITIAL,
              V_REC.PRETINITIAL_F,
              V_REC.TIPSTORNO,
              V_REC.AMOANPREC
              );
         END IF;
       ELSE
        SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

        UPDATE TMP_MIFIX
        SET
          CODMIFIX = aCODMIFIX
        WHERE
          CODMIFIX = V_REC.CODMIFIX;
            
        UPDATE  TMP_JURNAL
        SET
          CODDOC     = aCODMIFIX,
          INDEXLOCAL = aCODMIFIX
        WHERE
          CODDOC   = V_REC.CODMIFIX;

        UPDATE
          TMP_JURNAL1
        SET
          CODDOC   = aCODMIFIX,
          INDEXLOCAL = aCODMIFIX
        WHERE
          CODDOC   = V_REC.CODMIFIX;



        UPDATE  TMP_FISAMF  SET CODMIFIX = aCODMIFIX WHERE CODMIFIX = V_REC.CODMIFIX;


        INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, OBS, ANINTRARE, LUNAINTRARE, ANINTRAREG, LUNAINTRAREG, SERIEINV, CODMIFIXIMB, RESTIMBMF)
        VALUES (
         aCODMIFIX,
         V_REC.TIP,
         V_REC.NRINVENTAR,
         V_REC.OBS,
         V_REC.ANINTRARE,
         V_REC.LUNAINTRARE,
         V_REC.ANINTRAREG,
         V_REC.LUNAINTRAREG,
         V_REC.SERIEINV,
         V_REC.CODMIFIXIMB,
         0);
        SELECT SEQ_MIFIX1_CODMIFIX1.NEXTVAL INTO vcExt FROM DUAL;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;MIFIX&apos;, vcExt, V_REC.CODMIFIX1);
        INSERT INTO MIFIX1
        (
         CODMIFIX1,
         CODMIFIX,
         CODNIRSTOC,
         PRET,
         CANT,
         CODCLASIF,
         TIPAMO,
         STARE,
         DURATAN,
         GRADU,
         DURATAF,
         AMO,
         NEUTIL,
         DFBLOCAT,
         DFBLOCAT_F,
         DFBLOCAT_G,
         CODPERS,
         CODNIRSER,
         ANSTART,
         LUNASTART,
         CODPART,
         CODLOCATIE,
         CODAnalizaNod, CODSablon, CODCENTRU,
         DURATANF,
         DURATANG,
         DURATAFF,
         DURATAFG,
         AMOF,
         AMOG,
         REZERVA,
         REZERVABLOCAT,
         AMOBLOCAT,
         CENTRUBLOCAT,
         CODCLASIFBLOCAT,
         CODPERSBLOCAT,
         NODANALIZABLOCAT,
         CODAUTO,
         AMOREZERVA,
         AMORBLOCAT,
         AMOFBLOCAT,
         AMOGBLOCAT,
         PRETINIBLOCAT,
         pretinitial_fblocat,
         PRETINITIAL,
         PRETINITIAL_F,
         TIPSTORNO,
         AMOANPREC
         )
        VALUES
        (
         vcExt,
         aCODMIFIX,
         V_REC.CODNIRSTOC,
         V_REC.PRET,
         V_REC.CANT,
         V_REC.CODCLASIF,
         V_REC.TIPAMO,
         V_REC.STARE,
         V_REC.DURATAN,
         V_REC.GRADU,
         V_REC.DURATAF,
         V_REC.AMO,
         V_REC.NEUTIL,
         V_REC.DFBLOCAT,
         V_REC.DFBLOCAT_F,
         V_REC.DFBLOCAT_G,
         V_REC.CODPERS,
         V_REC.CODNIRSER,
         V_REC.ANSTART,
         V_REC.LUNASTART,
         V_REC.CODPART,
         V_REC.CODLOCATIE,
         V_REC.CODAnalizaNod, V_REC.CODSablon, V_REC.CODCENTRU,
         V_REC.DURATANF,
         V_REC.DURATANG,
         V_REC.DURATAFF,
         V_REC.DURATAFG,
         V_REC.AMOF,
         V_REC.AMOG,
         V_REC.REZERVA ,
         V_REC.REZERVABLOCAT,
         V_REC.AMOBLOCAT,
         V_REC.CENTRUBLOCAT,
         V_REC.CODCLASIFBLOCAT,
         V_REC.CODPERSBLOCAT,
         V_REC.NODANALIZABLOCAT,
         V_REC.CODAUTO,
         V_REC.AMOREZERVA,
         V_REC.AMORBLOCAT,
         V_REC.AMOFBLOCAT,
         V_REC.AMOGBLOCAT,
         V_REC.PRETINIBLOCAT,
         V_REC.pretinitial_fblocat,
         V_REC.PRETINITIAL,
         V_REC.PRETINITIAL_F,
         V_REC.TIPSTORNO,
         V_REC.AMOANPREC
         );

       END IF;
     END LOOP;

     DELETE FROM FISAMF FMF
     WHERE
     EXISTS (SELECT CODFISAMF FROM TMP_FISAMF_INI WHERE CODFISAMF = FMF.CODFISAMF)
     AND NOT EXISTS (SELECT CODFISAMF FROM TMP_FISAMF WHERE CODFISAMF = FMF.CODFISAMF);

     FOR V_REC IN (SELECT * FROM TMP_FISAMF)
     LOOP
       IF V_REC.CODFISAMF &gt; 0 THEN
         UPDATE FISAMF
         SET
           CODMIFIX     = V_REC.CODMIFIX,
           CODOPERATIE  = V_REC.CODOPERATIE,
           DATAOPERATIE = V_REC.DATAOPERATIE,
           GESTSURSA    = V_REC.GESTSURSA,
           GESTDEST     = V_REC.GESTDEST,
           PRETI        = V_REC.PRETI,
           PRETE        = V_REC.PRETE,
           PREFIXDOC    = V_REC.PREFIXDOC,
           NRDOC        = V_REC.NRDOC,
           CANT         = V_REC.CANT,
           OBS          = V_REC.OBS,
           CODDOC1      = V_REC.CODDOC1,
           TIPDOC       = V_REC.TIPDOC
         WHERE
         CODFISAMF = V_REC.CODFISAMF;
       ELSE
         INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, OBS,
                            CODDOC1, TIPDOC)
         VALUES (SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, V_REC.CODOPERATIE, V_REC.DATAOPERATIE, V_REC.GESTSURSA, V_REC.GESTDEST, V_REC.PRETI, V_REC.PRETE, V_REC.PREFIXDOC, V_REC.NRDOC, V_REC.CANT, V_REC.OBS,
                 V_REC.CODDOC1, V_REC.TIPDOC);
         IF V_REC.CODOPERATIE = 1 THEN
           IF V_REC.TIPDOC &lt; 12 THEN
             UPDATE INTRARI1 SET CODMIFIX = V_REC.CODMIFIX WHERE CODINTR1 = V_REC.CODDOC1;
           END IF;
           IF V_REC.TIPDOC IN (12,13) THEN
             UPDATE TRANSF1 SET CODMIFIX = V_REC.CODMIFIX WHERE CODTRANSF1 = V_REC.CODDOC1;
           END IF;
           IF V_REC.TIPDOC = 15 THEN
             UPDATE IESIRI1 SET CODMIFIX = V_REC.CODMIFIX WHERE CODIES1 = V_REC.CODDOC1;
           END IF;
         END IF;
       END IF;
     END LOOP;


-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU AND CODDOC IN (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL) AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOAREGRUP   = v_rec.VALOAREGRUP,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = CASE
                      WHEN NVL(TRANSFERURI, 0) = 0 THEN V_REC.DIRTY
                      ELSE 1
                    END,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODAnalizaNod = V_REC.CODAnalizaNod,
    CODCENTRU     = v_rec.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODAnalizaNod, CODCENTRU, DATADOC, DOCUMENT )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODAnalizaNod, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
 END IF;
END LOOP;


-- detail JURNAL


-- la pozitiile provenite din transferuri sterg liniile vechi de jurnal pentru a nu se dubla
FOR V_REC IN (SELECT * FROM TMP_MIFIX WHERE CODMIFIX &gt; 0 AND CODMIFIX1 = CODMIFIX1VECHI)
LOOP

  FOR V_REC_J IN
  ( SELECT *
    FROM
    JURNAL WHERE TIPDOC = 36 AND  AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU  AND CODDOC = V_REC.CODMIFIX
  )
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC_J.VALOARE,
      RULAJVCD = RULAJVCD - V_REC_J.VALOAREV
    WHERE
      CODCONT = V_REC_J.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC_J.VALOARE,
      RULAJVCC = RULAJVCC - V_REC_J.VALOAREV
    WHERE
      CODCONT = V_REC_J.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    DELETE FROM JURNAL WHERE CODJURNAL = V_REC_J.CODJURNAL;
  END LOOP;

  
  DELETE FROM JURNAL1 WHERE
   TIPDOC = 36 AND
   AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
   AND CODDOC = V_REC.CODMIFIX;

END LOOP;


DELETE
FROM
JURNAL
WHERE
 TIPDOC = 36 AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU
 AND CODDOC IN (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL) AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAL);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOAREGRUP= v_rec.VALOAREGRUP,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA,
    CODAnalizaNod=v_rec.CODAnalizaNod,
    CODCENTRU  = v_rec.CODCENTRU,
    DATADOC    = V_REC.DATADOC,
    DOCUMENT   = V_REC.DOCUMENT
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODAnalizaNod, CODCENTRU, DATADOC, DOCUMENT)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODAnalizaNod,v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
 END IF;
END LOOP;




END IF;
  -- NU EXISTA RAMURA DE INSERT PENTRU CA RECID = CODNIRSTOC

  if NVL(PKG_CATEGCONST.GetValConstanta(&apos;MifixStatusAuto&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) = 1 then
    for v_rec in (select p.codnparcaut, mfix1.stare
                  from nparcaut p
                       inner join mifix mfix on mfix.nrinventar = p.nrinv
                       inner join mifix1 mfix1 on mfix1.codmifix = mfix.codmifix
                  where mfix1.anstart = pkg_globals.GetANLUCRU and mfix1.lunastart = pkg_globals.GetLUNALUCRU and
                        mfix1.codnirstoc = recid) loop
      update nparcaut
      set
        inactiv =
          case
            when v_rec.stare = 1 then 0
            else v_rec.stare
          end
      where codnparcaut = v_rec.codnparcaut;
    end loop;
  end if;

-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;


 END LOOP;

 -- fac link intre mifixul provenit din intrari de la subunitati si mifixul iesit de la subunitati
 for v_rec in (SELECT MF.* 
               FROM 
                 TMP_MIFIX MF 
                 INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF.CODNIRSTOC
                 INNER JOIN NIR N ON N.CODNIR = NS.CODNIR 
                                    AND N.TIPNIR = 6 
                                    AND EXTRACT(YEAR FROM DATANIR) = pkg_globals.getanlucru 
                                    AND EXTRACT(MONTH FROM DATANIR) = pkg_globals.getLunalucru
               WHERE 
                 COALESCE(CODMIFIXVECHI, 0) &gt; 0 AND CODMIFIX &gt; 0)
 loop
   UPDATE MIFIX
   SET
     CODMIFIXNOU = V_REC.CODMIFIX,
     ANLUNAMIFIXNOU = pkg_globals.getanlucru*12+pkg_globals.getlunalucru
  WHERE
    CODMIFIX = V_REC.CODMIFIXVECHI;   
 end loop;    


 PKG_GLOBALS.MarkDirtyJurnal;
 PKG_CFGTABLES.EXT_POSTRECORDS(36); 
 NotifyModif(OPERATION, RECID, &apos;MIFIX&apos;);

 COMMIT;

END;

procedure make_mifix is
vAn number(4);
vLuna number(2);
vZi number(2);
vGest number(20);
vCodIOArt number(20);
vData date;
vSubunitatea number(20);
vUserID number(20);
vVal number(20,7);
aRecID number(20);
aCodMifix number(20);
vNextAn number(4);
vNextLuna number(2);
vCodClasif number(20);
begin
  vAn := 2018;
  vLuna := 7;
  if vLuna = 12 then
    vNextAn := vAn + 1;
    vNextLuna := 1;
  else
    vNextAn := vAn;
    vNextLuna := vLuna + 1;
  end if;
  vZi := 24;
  vGest := 143;
  vCodIOArt := 305;
  vData := to_date(to_char(vZi)||&apos;.&apos;||LPAD(to_char(vLuna),2,&apos;0&apos;)||&apos;.&apos;||to_char(vAn), &apos;dd.mm.yyyy&apos;);
  vSubunitatea := 2;
  vUserID := 85;
  vCodClasif := 261;

  /*for v_obj in (select x.*, rownum nr
                from (
                select imp.codobiect, sum(imp.pretn) valoare, imp.duratan, imp.duratang, count(*) cant,
                       um1.codum1, imp.pretn pret
                from imp_mifix imp
                     inner join nartobj o on o.codobiect = imp.codobiect
                     inner join nart a on o.codarticol = a.codarticol
                     inner join num1 um1 on um1.codum = a.um and nvl(um1.secundara,0) = 0
                group by imp.codobiect, imp.duratan, imp.duratang, um1.codum1, imp.pretn
                ) x
                ) loop
    delete tmp_iesiri;
    delete tmp_iesiri1;
    delete tmp_livr;
    delete tmp_livr1;
    delete tmp_intrari;
    delete tmp_intrari1;
    delete tmp_nirstoc;
    delete tmp_nirser;
    INSERT INTO TMP_IESIRI (
      CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, NRDOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, ACCIZE,
      AN, LUNA, BUGETARE, TIPFACTURA, TIPTVA, SUBUNITATEA, TIPCASAMARCAT, MONEDA, CURS, USERID, DATACREARE, TIPTRANZACTIE,
      INFOCM, MONEDATRANSF, STARERESTITUIRE, DATATVA, STADIUWMS, EMISADECLIENT, SOLDPART, SCADENTAV, SCADENTESETATEMANUAL
      )
    values (
      -1, 15, 0, 0, 1, &apos;PV&apos;, vData, 999, v_obj.valoare, 0, 0, 0, 0,
      vAn, vLuna, 0, 0, 1, vSubunitatea, 0, 0, 1, vUserID, SysDate, 1,
      0, 0, 0, vData, 0, 0, 0, 0, 1);
    INSERT INTO TMP_IESIRI1(
      CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, PROCDISC, RESTFACT,
      TIPLIVRARE, COEFDISCMAJ, ZILE, CADOU, VALDISCPRET, D1, D2, D3, CANTUM1
      )
    VALUES (
      -1, -1, 1, &apos;=&apos;, v_obj.codum1, 0, 0, v_obj.codobiect, v_obj.pret, v_obj.pret, v_obj.cant, 0, 0, 0,
      1, 1, 0, 0, 0, 0, 0, 0, 0
      );
    INSERT INTO TMP_LIVR (CODLIVR, CODIES, DATALIVR, TIPLIVR, ANULAT, OPERAT)
    VALUES (-1, -1, vData, 15, 0, 1);

    for v_rec in (select rownum idx, imp.pretn, imp.serie
                  from imp_mifix imp
                  where imp.codobiect = v_obj.codobiect and imp.duratan = v_obj.duratan and imp.duratang = v_obj.duratang
                        and imp.pretn = v_obj.pret
                 ) loop
      insert into tmp_livr1 (
        codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, pmp, umsec, cantum1, cantum2, cantrezervat,
        codcertif, pmpvaluta, pmpdoc, pmpvalutadoc, contintermed, blocatum1, codlivr1parinte, paritate)
      values (-v_rec.idx, -1, -1, -v_rec.idx, 1, -v_rec.idx, 0, v_obj.codum1, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 1);
      INSERT INTO TMP_INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC)
      VALUES (-v_rec.idx, 1, 0, 0, 1, &apos;F&apos;, vData);
      insert into tmp_intrari1(codintr1, codintr, indexlocal, tiplinie, umsec, an, luna, codobiect, pretorig, pu, cant)
      values (-v_rec.idx, -v_rec.idx, v_rec.idx, &apos;=&apos;, v_obj.codum1, vAn, vLuna, v_obj.codobiect, v_obj.pret, v_obj.pret, 0);
      INSERT INTO TMP_NIR(CODNIR, CODINTR, CODIES, DATANIR, GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
      VALUES (-v_rec.idx, -v_rec.idx, -1, vData, vGest, 15, 0, 0, 1);
      insert into tmp_nirstoc(
        codnirstoc, codnir, codintr1, cantnir, umsec, codobiect, codioart, pret, adaos,
        tipserie, rest, cantum1, cantum2, dataachiz, tipdocachiz)
      values (-v_rec.idx, -v_rec.idx, -v_rec.idx, 0, v_obj.codum1, v_obj.codobiect, vCodIOArt, v_obj.pret, 0,
              1, 0, 0, 0, vData, 1);
      insert into tmp_nirser (codnirser, codnirstoc, codserie, cantnir, rest, cantum1, restum1, cantum2, restum2, codcertif, stare, serie)
      values (-v_rec.idx, -v_rec.idx, -v_rec.idx, 0, 0, 0, 0, 0, 0, 0, 1, v_rec.serie);
    end loop;
    pkg_iesiri.SP_POSTRECORDS(1, aRecID);
    for v_rec in (select distinct ns.codnirstoc, imp.nrinventar, nse.codnirser, ns.pret, nir.datanir, nir.gest, ies.prefixdoc, ies.nrdoc, ies1.codies1, ies.tipdoc
                  from nir
                       inner join nirstoc ns on ns.codnir = nir.codnir
                       inner join nirser nse on nse.codnirstoc = ns.codnirstoc
                       inner join nserii ser on ser.codserie = nse.codserie
                       inner join intrari1 i1 on ns.codintr1 = i1.codintr1
                       inner join iesiri ies on ies.codies = nir.codies
                       inner join livr l on ies.codies = l.codies
                       inner join livr1 l1 on l.codlivr = l1.codlivr and l1.codnirstoc = ns.codnirstoc
                       inner join iesiri1 ies1 on ies1.codies = ies.codies and l1.codies1 = ies1.codies1
                       inner join imp_mifix imp on imp.codobiect = v_obj.codobiect and imp.duratan = v_obj.duratan and imp.duratang = v_obj.duratang and imp.pretn = v_obj.pret
                                  and imp.serie = ser.serie
                  where nir.codies = aRecID
                 ) loop
      insert into mastermifix(codnirstoc, codclasif, duratanf)
      values(v_rec.codnirstoc, vCodClasif, v_obj.duratan);
      select seq_mifix_codmifix.nextval into aCodMifix from dual;
      insert into mifix (codmifix, tip, nrinventar, anintrare, lunaintrare, anintrareg, lunaintrareg)
      values (aCodMifix, &apos;MF&apos;, v_rec.nrinventar, vNextAn, vNextLuna, vNextAn, vNextLuna);
      insert into mifix1(codmifix1, codmifix, codnirstoc, pret, cant, codclasif, tipamo, stare, duratan, gradu, durataf, dfblocat, anstart, lunastart
                         , codnirser, duratanf, durataff, duratang, duratafg, dfblocat_f, dfblocat_g)
      values (seq_mifix1_codmifix1.nextval, aCOdMifix, v_rec.codnirstoc, v_rec.pret, 1, vCodClasif, 1, 1, v_obj.duratan, 100, v_obj.duratan*12, 1, vAn, vLuna,
              v_rec.codnirser, 0, 0, 0, v_obj.duratang*12, 1, 1);
      INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      ACODMIFIX,
      1,
      V_REC.DATANIR,
      0,
      V_REC.GEST,
      V_REC.PRET,
      0,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      1,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    end loop;
    commit;
  end loop;*/
end;

procedure CasareFaraCommit(aCodMifix1 in number, aCodIes in number) is
begin
  update mifix1 set stare = 3 where codmifix1 = acodmifix1;
  for v_rec in (select l.datalivr, NIR.GEST, NS.PRET, i.NRDOC, i.PREFIXDOC, l1.CANT, i1.CODIES1, I.TIPDOC, MFIX1.CODMIFIX,
                       mfix1.anstart, mfix1.lunastart
                from nirstoc ns
                     inner join livr1 l1 on l1.codnirstoc = ns.codnirstoc
                     inner join iesiri1 i1 on i1.codies1 = l1.codies1
                     inner join iesiri i on i.codies = i1.codies
                     inner join livr l on l.codies = i.codies and l1.codlivr = l.codlivr
                     INNER JOIN mifix1 mfix1 ON mfix1.CODNIRSTOC = ns.codnirstoc
                     inner join nir on nir.codnir = ns.codnir
                where mfix1.codmifix1 = acodMifix1 and i.codies = aCodIes) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      V_rec.CODMIFIX,
      4,
      V_REC.DATALIVR,
      V_REC.GEST,
      V_REC.GEST,
      V_REC.PRET,
      V_REC.PRET,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= v_rec.anstart*12+v_rec.lunastart;
    EXIT;
  end loop;
end;

procedure GenMFNoi
(
  aCodNirStoc in number,
  aCodObiect in number,
  aGest in number,
  aCodIOArt in number,
  aCodClasif in number,
  aValoare in number,
  aCant in number,
  aCarnetDim in number,
  aSeriaDim in varchar2,
  aNrDim in number,
  aDataDim in varchar2,
  aCarnetMar in number,
  aSeriaMar in varchar2,
  aNrMar in number,
  aDataMar in varchar2,
  aSerieStart in varchar2,
  aInc in number,
  aCarnetDimLivr in number,
  aSeriaDimLivr in varchar2,
  aNrDimLivr in number,
  aDataDimLivr in varchar2,
  aCarnetMarLivr in number,
  aSeriaMarLivr in varchar2,
  aNrMarLivr in number,
  aDataMarLivr in varchar2,
  aNrInv in number
) is
vAn number(4);
vLuna number(2);
vZi number(2);
vSubunitatea number(20);
vUserID number(20);
vPret number(20,7);
aRecID number(20);
vNextAn number(4);
vNextLuna number(2);
vTipSerie number(1);
vCodMifix1 number(20);
vSerie varchar2(75);
vInc number(20);
vMG number(1);
vDifPret number(1);
vAreTVANeex number(1);
vNrInv number(20);
begin
  vNrInv := aNrInv;
  vPret := aValoare / aCant;
  vAn := pkg_globals.GetANLUCRU;
  vLuna := pkg_globals.GetLUNALUCRU;
  if vLuna = 12 then
    vNextAn := vAn + 1;
    vNextLuna := 1;
  else
    vNextAn := vAn;
    vNextLuna := vLuna + 1;
  end if;
  vSubunitatea := pkg_globals.GETSUBUNITATE_DOC;
  vUserID := pkg_globals.GETUSERID;

  select nvl(a.tipserie,0) into vTipSerie
  from nartobj o
       inner join nart a on a.codarticol = o.codarticol
  where o.codobiect = aCodObiect;

  begin
    select io1.mg, io1.difpret, io1.AreTVANeex into vMG, vDifPret, vAreTVANeex
    from ioart1 io1
    where io1.codioart = aCodIOArt and pkg_globals.anlunalucru BETWEEN io1.alstart AND io1.alstop;
  exception when others then vMG := 4;
  end;

  pkg_iesiri.Set_Do_Commit(False);
  begin
    --dimunare
    for v_obj in (select x.*, rownum nr
                  from (
                  select o.codobiect, um1.codum1, um1.paritate
                  from nirstoc ns
                       inner join nartobj o on ns.codobiect = o.codobiect
                       inner join nart a on o.codarticol = a.codarticol
                       inner join num1 um1 on ns.umsec = um1.codum1
                  where ns.codnirstoc = aCodNirStoc
                  ) x
                  ) loop
      delete tmp_iesiri;
      delete tmp_iesiri1;
      delete tmp_livr;
      delete tmp_livr1;
      delete tmp_intrari;
      delete tmp_intrari1;
      delete tmp_nirstoc;
      delete tmp_nirser;
      INSERT INTO TMP_IESIRI (
        CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, SERIADOC, DATADOC, NRDOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, ACCIZE,
        AN, LUNA, BUGETARE, TIPFACTURA, TIPTVA, SUBUNITATEA, TIPCASAMARCAT, MONEDA, CURS, USERID, DATACREARE, TIPTRANZACTIE,
        INFOCM, MONEDATRANSF, STARERESTITUIRE, DATATVA, STADIUWMS, EMISADECLIENT, SOLDPART, SCADENTAV, SCADENTESETATEMANUAL
        )
      values (
        -1, 14, 0, 0, 1, &apos;PV&apos;, aCarnetDim, aSeriaDim, to_date(aDataDim, &apos;dd.mm.yyyy&apos;), aNrDim, 0, 0, 0, 0, 0,
        vAn, vLuna, 0, 0, 1, vSubunitatea, 0, 0, 1, vUserID, SysDate, 1,
        0, 0, 0, aDataDim, 0, 0, 0, 0, 1);
      INSERT INTO TMP_IESIRI1(
        CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, PROCDISC, RESTFACT,
        TIPLIVRARE, COEFDISCMAJ, ZILE, CADOU, VALDISCPRET, D1, D2, D3, CANTUM1
        )
      select
        -1, -1, 1, &apos;=&apos;, v_obj.codum1, 0, 0, v_obj.codobiect, 0, 0, ns.rest, 0, 0, 0,
        1, 1, 0, 0, 0, ns.d1, ns.d2, ns.d3, ns.restum1
      from nirstoc ns
      where ns.codnirstoc = aCodNirStoc;

      INSERT INTO TMP_LIVR (CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, TIPLIVR, ANULAT, OPERAT)
      VALUES (-1, -1, aCarnetDimLivr, aNrDimLivr, aDataDimLivr, 14, 0, 1);

      for v_ns in (select ns.rest, ns.restum1, ns.restum2
                   from nirstoc ns where ns.codnirstoc = aCodNirStoc) loop
        insert into tmp_livr1 (
          codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, pmp, umsec, cantum1, cantum2, cantrezervat,
          codcertif, pmpvaluta, pmpdoc, pmpvalutadoc, contintermed, blocatum1, codlivr1parinte, paritate)
        values (-1, -1, -1, aCodNirStoc, v_ns.rest, 0, 0, v_obj.codum1, v_ns.restum1, v_ns.restum2, 0,
                0, 0, 0, 0, 0, 0, 0, v_obj.paritate);
      end loop;
    end loop;
    pkg_iesiri.SP_POSTRECORDS(1, aRecID);
    begin
      select codmifix1 into vCodMifix1 from mifix1 where codnirstoc = acodnirstoc and anstart = vAn and lunastart = vLuna;
    exception when others then vCodMifix1 := 0;
    end;
    if vCodMifix1 &gt; 0 then
      PKG_MIFIX.CASAREFARACOMMIT(vCodMifix1, aRecID);
    end if;

    vSerie := aSerieStart;
    -- marire pt cele noi
    for v_obj in (select o.codobiect, um1.codum1, um1.paritate, a.d1, a.d2, a.d3, a.relatieum1, a.tipserie, o1.tippretmax, o1.pretmaximal,
                         a.um1, a.um2
                  from nartobj o
                       inner join nart a on o.codarticol = a.codarticol
                       inner join num1 um1 on um1.codum = a.um and nvl(um1.secundara,0) = 0
                       left join nartobj1 o1 on o.codobiect = o1.codobiect
                  where o.codobiect = aCodObiect and pkg_globals.anlunalucru BETWEEN o1.alstart AND o1.alstop
                 ) loop
      delete tmp_iesiri;
      delete tmp_iesiri1;
      delete tmp_intrari;
      delete tmp_intrari1;
      delete tmp_nir;
      delete tmp_livr;
      delete tmp_livr1;
      delete tmp_intrari;
      delete tmp_intrari1;
      delete tmp_nirstoc;
      delete tmp_nirser;
      INSERT INTO TMP_IESIRI (
        CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, SERIADOC, DATADOC, NRDOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, ACCIZE,
        AN, LUNA, BUGETARE, TIPFACTURA, TIPTVA, SUBUNITATEA, TIPCASAMARCAT, MONEDA, CURS, USERID, DATACREARE, TIPTRANZACTIE,
        INFOCM, MONEDATRANSF, STARERESTITUIRE, DATATVA, STADIUWMS, EMISADECLIENT, SOLDPART, SCADENTAV, SCADENTESETATEMANUAL
        )
      values (
        -1, 15, 0, 0, 1, &apos;PV&apos;, aCarnetMar, aSeriaMar, to_date(aDataMar, &apos;dd.mm.yyyy&apos;), aNrMar, 0, 0, 0, 0, 0,
        vAn, vLuna, 0, 0, 1, vSubunitatea, 0, 0, 1, vUserID, SysDate, 1,
        0, 0, 0, aDataDim, 0, 0, 0, 0, 1);
      INSERT INTO TMP_IESIRI1(
        CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, PROCDISC, RESTFACT,
        TIPLIVRARE, COEFDISCMAJ, ZILE, CADOU, VALDISCPRET, D1, D2, D3, CANTUM1
        )
      values (
        -1, -1, 1, &apos;=&apos;, v_obj.codum1, 0, 0, v_obj.codobiect, 0, vPret, aCant, 0, 0, 0,
        1, 1, 0, 0, 0, v_obj.d1, v_obj.d2, v_obj.d3,
        round(CASE
                WHEN v_obj.RELATIEUM1 IN (1, 7) AND NVL(v_obj.D1, 0) &lt;&gt; 0 THEN acant/v_obj.D1
                WHEN v_obj.RELATIEUM1 IN (2, 8) AND NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) &lt;&gt; 0 THEN acant / (NVL(v_obj.D1,0) * NVL(v_obj.D2,0))
                WHEN v_obj.RELATIEUM1 IN (3, 9) AND NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) * NVL(v_obj.D3, 0) &lt;&gt; 0 THEN acant / (NVL(v_obj.D1,0) * NVL(v_obj.D2,0) * NVL(v_obj.D3,0))
                WHEN v_obj.RELATIEUM1 IN (4, 10) THEN acant * NVL(v_obj.D1,0)
                WHEN v_obj.RELATIEUM1 IN (5, 11) THEN acant * NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0)
                WHEN v_obj.RELATIEUM1 IN (6, 12) THEN acant * NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) * NVL(v_obj.D3, 0)
              END,7)
              );

      INSERT INTO TMP_LIVR (CODLIVR, CODIES, CARNETLIVR, NRLIVR, DATALIVR, TIPLIVR, ANULAT, OPERAT)
      VALUES (-1, -1, aCarnetMarLivr, aNrMarLivr, aDataMarLivr, 15, 0, 1);

      for vInc in 1..aCant loop
        insert into tmp_intrari(codintr, tipdoc, anulat, blocat, operat, prefixdoc, datadoc)
        values (-vInc, 1, 0, 0, 1, &apos;F&apos;, aDataMarLivr);
        insert into tmp_intrari1(codintr1, codintr, indexlocal, tiplinie, umsec, an, luna, codobiect, pretorig, pu, cant, paritate)
        values (-vInc,-vInc,vInc,&apos;=&apos;,v_obj.codum1,vAn, vLuna,acodobiect, vpret,vpret,0,v_obj.paritate);
        insert into tmp_nir(codnir, codintr, datanir, gest, tipnir, anulat, blocat, operat)
        values (-vInc, -vInc, aDataMarLivr, aGest, 15, 0, 0, 1);
        insert into tmp_nirstoc (codnirstoc, codnir, codintr1, cantnir, umsec, codobiect, codioart, tipserie, pret, adaos, rest, cantum1, cantum2, pumaximal, dataachiz, tipdocachiz,
                                 paritate, mg, difpret, aretvaneex, um1, um2, relatieum1, tippretmax)
        values (-vInc, -vInc, -vInc, 0, v_obj.codum1, aCodObiect, aCodIOArt, v_obj.tipserie, vPret, 0, 0, 0, 0, v_obj.pretmaximal, aDataMarLivr, 1,
                v_obj.paritate, vMG, vDifPret, vAreTVANeex, v_obj.um1, v_obj.um2, v_obj.relatieum1, v_obj.tippretmax);
        insert into tmp_nirser(codnirser,codnirstoc,codserie,cantnir,rest,cantum1, restum1,cantum2,restum2,stare,serie)
        values(-vInc,-vInc,-vInc,0,0,0,0,0,0,1,vSerie);

        insert into tmp_livr1 (
          codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, pmp, umsec, cantum1, cantum2, cantrezervat,
          codcertif, pmpvaluta, pmpdoc, pmpvalutadoc, contintermed, blocatum1, codlivr1parinte, paritate)
        values (-vInc, -1, -1, -vInc, 1, -vInc, 0, v_obj.codum1,
                round(CASE
                  WHEN v_obj.RELATIEUM1 IN (1, 7) AND NVL(v_obj.D1, 0) &lt;&gt; 0 THEN 1/v_obj.D1
                  WHEN v_obj.RELATIEUM1 IN (2, 8) AND NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) &lt;&gt; 0 THEN 1 / (NVL(v_obj.D1,0) * NVL(v_obj.D2,0))
                  WHEN v_obj.RELATIEUM1 IN (3, 9) AND NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) * NVL(v_obj.D3, 0) &lt;&gt; 0 THEN 1 / (NVL(v_obj.D1,0) * NVL(v_obj.D2,0) * NVL(v_obj.D3,0))
                  WHEN v_obj.RELATIEUM1 IN (4, 10) THEN NVL(v_obj.D1,0)
                  WHEN v_obj.RELATIEUM1 IN (5, 11) THEN NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0)
                  WHEN v_obj.RELATIEUM1 IN (6, 12) THEN NVL(v_obj.D1, 0) * NVL(v_obj.D2, 0) * NVL(v_obj.D3, 0)
                END,7),
                0, 0,
                0, 0, 0, 0, 0, 0, 0, v_obj.paritate);
        vSerie := to_char(to_number(vSerie) + aInc);
      end loop;
    end loop;
    pkg_iesiri.SP_POSTRECORDS(1, aRecID);

    for v_rec in (select l1.codnirstoc
                  from livr1 l1
                       inner join livr l on l.codlivr = l1.codlivr
                  where l.codies = aRecID) loop
      pkg_mifix.NEWMIFIXFARACOMMIT(v_rec.codnirstoc, aCodClasif, 0, vNrInv, pkg_globals.GetANLUCRU, pkg_globals.GetLUNALUCRU);
      vNrInv := vNrInv + 1;
    end loop;
    commit;
  exception when others then
    Raise;
    RollBack;
  end;
  pkg_iesiri.Set_Do_Commit(False);
end;

procedure NEWMIFIXFARACOMMIT(aCodNirStoc in number, aCodClasif in number, aCodCentru in number, aNrInventar in number, aAn in number, aLuna in number) is
aDurataN number;
aDurataF number;
aDurataG number;
aCodMifix number(20);
aTipAmo  NUMBER := 1;
aStare number(1);
aNextAn number(4);
aNextLuna number(2);
begin
  BEGIN
    SELECT DURATA * 12, DURATAF * 12, DURATAG * 12 INTO aDURATAN, aDurataF, aDurataG FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
  exception when others then aDurataN := 0;
  END;

  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipAmoOI&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipAmo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aTIPAMO := 1;
  END;

  if aLuna = 12 then
    aNextAn := aAn + 1;
    aNextLuna := 1;
  else
    aNextLuna := aLuna + 1;
  end if;

  if NVL(PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0) &lt;&gt; 1 then
    aStare := 1;
    aDurataF := aDurataN;
  else
    aStare := 5;
    aDurataF := 0;
  end if;

  INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG)
  VALUES (aCODNIRSTOC, aCODCLASIF, aDURATAN, aDurataF, aDurataG);

  SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

  INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, RESTIMBMF, ANINTRAREG, LUNAINTRAREG)
  VALUES (aCODMIFIX, &apos;MF&apos;, aNrInventar, aNextAn, aNextLuna, 0, aNextAn, aNextLuna);


  INSERT INTO MIFIX1(CODMIFIX1,
                     CODMIFIX,
                     CODNIRSTOC,
                     PRET,
                     CANT,
                     CODCLASIF,
                     TIPAMO,
                     STARE,
                     DURATAN,
                     GRADU,
                     DURATAF,
                     AMO,
                     DFBLOCAT,
                     ANSTART,
                     LUNASTART,
                     DFBLOCAT_F,
                     DFBLOCAT_G,
                     CODCENTRU)
  VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
         aCODMIFIX,
         aCODNIRSTOC,
         0,
         1,
         aCODCLASIF,
         aTIPAMO,
         aStare,
         aDURATAN,
         100,
         aDurataF,
         0,
         1,
         aAn,
         aLuna,
         1,
         1,
         aCodCentru);

  for v_rec in (select nir.datanir, NIR.GEST, NS.PRET, I.NRDOC, I.PREFIXDOC, NS.REST CANT, I1.CODIES1, I.TIPDOC
                from nirstoc ns
                     inner join nir on nir.codnir = ns.codnir
                     INNER JOIN IESIRI I ON NIR.CODIES = I.CODIES
                     INNER JOIN INTRARI1 IN1 ON NS.CODINTR1 = IN1.CODINTR1
                     INNER JOIN LIVR1 L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
                     INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1 AND I.CODIES = I1.CODIES
                where ns.codnirstoc = acodnirstoc) loop
    INSERT INTO FISAMF (
      CODFISAMF,
      CODMIFIX,
      CODOPERATIE,
      DATAOPERATIE,
      GESTSURSA,
      GESTDEST,
      PRETI,
      PRETE,
      PREFIXDOC,
      NRDOC,
      CANT,
      OBS,
      CODDOC1,
      TIPDOC)
    VALUES(
      SEQ_FISAMF_CODFISAMF.NEXTVAL,
      ACODMIFIX,
      1,
      V_REC.DATANIR,
      0,
      V_REC.GEST,
      V_REC.PRET,
      0,
      V_REC.PREFIXDOC,
      V_REC.NRDOC,
      V_REC.CANT,
      &apos;&apos;,
      V_REC.CODIES1,
      V_REC.TIPDOC
      );
    EXIT;
  end loop;
end;

end PKG_MIFIX;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MISCARI_INTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B26CE7F817DBBE5309A42A76981C48D974A0A185</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MISCARI_INTERNE IS

  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_13&apos;;
  DoCommit boolean := true;
  vSkipMifixAut boolean := False;


PROCEDURE SET_Session_LivrDinRezTransf(aFlag in number)
is
begin
  v$Session_LivrDinRezTransf := aFlag; 
end;  


PROCEDURE SETCODMIFIX(aCodMifix in number) is
begin
  vCodMifix := aCodMifix;
end;


PROCEDURE MAKE_MIFIX_NOU(aCODMIFIX IN NUMBER, aCODMIFIX1 IN NUMBER, aANSTART IN NUMBER, aLUNASTART IN NUMBER)
IS
  aCODMIFIXNOU  NUMBER;
  NRINVNOU      NUMBER;
BEGIN
   SELECT COALESCE(CODMIFIXNOU, 0) INTO aCODMIFIXNOU 
   FROM 
     MIFIX
   WHERE
     CODMIFIX = aCODMIFIX;  

 IF aCODMIFIXNOU = 0 THEN
   aCODMIFIXNOU := SEQ_MIFIX_CODMIFIX.NEXTVAL;
   NRINVNOU := PKG_MIFIX.GETNEXTNRINV(&apos;MF&apos;);
           
   INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, OBS, ANINTRAREG, LUNAINTRAREG, SERIEINV,CODMIFIXIMB) 
   SELECT  aCODMIFIXNOU, &apos;MF&apos;, NRINVNOU, ANINTRARE, LUNAINTRARE, OBS, ANINTRAREG, LUNAINTRAREG, SERIEINV,CODMIFIXIMB
   FROM
     MIFIX 
   WHERE
      CODMIFIX = aCODMIFIX;  

            

   UPDATE MIFIX 
   SET
     CODMIFIXNOU = aCODMIFIXNOU,
     ANLUNAMIFIXNOU = aANSTART * 12 + aLUNASTART
   WHERE
     CODMIFIX = aCODMIFIX;  
 END IF;
         
 UPDATE MIFIX1
 SET
   CODMIFIX = aCODMIFIXNOU
 WHERE
   CODMIFIX1 = aCODMIFIX1;
           
  IF aANSTART * 12 + aLUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU THEN
    UPDATE MIFIX1 
    SET
      AMOBLOCAT = 1,
      DFBLOCAT = 1 
    WHERE
       CODMIFIX1 = aCODMIFIX1;   
  END IF; 
  INSERT INTO JURNAL1(CODJURNAL1,CODDOC, TIPDOC, INDEXLOCAL, DIRTY, AN, LUNA)
              VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, aCODMIFIXNOU, 36, aCODMIFIXNOU, 1, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);        
  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, AN, LUNA)
              VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, aCODMIFIXNOU, 36, aCODMIFIXNOU, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);        

END;    




procedure SOLVE_TRANSF_MIFIX_SERIE(aCODTRANSF IN NUMBER, LegaturaTRANSF1 IN NUMBER)
IS
 NR           NUMBER;
 aCODMIFIXNOU NUMBER;
 NRINVNOU     NUMBER                               ;
BEGIN
  if LegaturaTransf1 = 0 then
    FOR V_REC IN
    (
    SELECT M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, M.TIP, MF_TRANSF.*
    FROM
     MIFIX1 M1,
     MIFIX M,
    (
    SELECT
      NSP.CODNIRSTOC CODNIRSTOPARINTE,
      NSP.CANTNIR AS CANTNIRPARINTE,
      NSEP.CODNIRSER AS CODNIRSSERPARINTE,
      NSD.CODNIRSTOC CODNIRSTOCDEST,
      NSED.CODNIRSER AS CODNIRSERDEST,
      L1.CANT,
      L.DATALIVR,
      NP.GEST AS GESTSURSA,
      ND.GEST AS GESTDEST,
      NSP.PRET AS PRETE,
      NSD.PRET AS PRETI,
      NSD.CODTRANSF1,
      NSP.CODIOART AS CODIOARTP,
      NSD.CODIOART AS CODIOARTD,
      T.NRDOC
    FROM
      LIVR1 L1,
      LIVR L,
      TRANSF T,
      NIRSER NSEP,
      NIRSTOC NSD,
      NIRSER NSED,
      NIRSTOC NSP,
      NIR ND,
      NIR NP,
      TMP_IOART_LUNA IOA
    WHERE
      L.CODTRANSF = aCODTRANSF
      AND L1.CODLIVR = L.CODLIVR
      AND NSEP.CODNIRSER = L1.CODNIRSER
      AND NSD.CODLIVR1 = L1.CODLIVR1
      AND IOA.CODIOART = NSD.CODIOART
      AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
      AND NSED.CODNIRSTOC = NSD.CODNIRSTOC
      AND NSP.CODNIRSTOC = L1.CODNIRSTOC
      AND NVL(NSP.TIPSERIE, 0) = 1
      AND L1.CANT = 1
      AND ND.CODNIR = NSD.CODNIR
      AND NP.CODNIR = NSP.CODNIR
      AND L.CODTRANSF = T.CODTRANSF
    ) MF_TRANSF
    WHERE
    --  M1.ANSTART = PKG_GLOBALS.ANLUCRU
    --  AND M1.LUNASTART = PKG_GLOBALS.LUNALUCRU
       M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
      AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
      AND NVL(M1.CODNIRSER, 0) = NVL(MF_TRANSF.CODNIRSSERPARINTE, 0)
      AND M.CODMIFIX = M1.CODMIFIX
    )
    LOOP


    -- START CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --
        IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
          MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
        END IF;  
    -- END CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --


        UPDATE MIFIX1
        SET
          CODNIRSTOC = V_REC.CODNIRSTOCDEST,
          CODNIRSER = V_REC.CODNIRSERDEST
        WHERE
          CODMIFIX1 = V_REC.CODMIFIX1;


           INSERT INTO FISAMF(CODFISAMF,
                              CODMIFIX,
                              CODOPERATIE,
                              DATAOPERATIE,
                              GESTSURSA,
                              GESTDEST,
                              PRETI,
                              PRETE,
                              PREFIXDOC,
                              NRDOC,
                              CANT,
                              CODDOC1,
                              TIPDOC)
                       VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL,
                              V_REC.CODMIFIX,
                              2,
                              V_REC.DATALIVR,
                              V_REC.GESTSURSA,
                              V_REC.GESTDEST,
                              V_REC.PRETI,
                              V_REC.PRETE,
                              &apos;NT&apos;,
                              V_REC.NRDOC,
                              1,
                              V_REC.CODTRANSF1,
                              12);


          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            CODDOC = V_REC.CODMIFIX
            AND TIPDOC = 36
            AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;



    END LOOP;

  else
    FOR V_REC IN
    (
    SELECT M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, M.TIP,  MF_TRANSF.*
    FROM
     MIFIX1 M1,
     MIFIX M,
    (
    SELECT
      NSP.CODNIRSTOC CODNIRSTOPARINTE,
      NSP.CANTNIR AS CANTNIRPARINTE,
      NSEP.CODNIRSER AS CODNIRSSERPARINTE,
      NSD.CODNIRSTOC CODNIRSTOCDEST,
      NSED.CODNIRSER AS CODNIRSERDEST,
      L1.CANT,
      L.DATALIVR,
      NP.GEST AS GESTSURSA,
      ND.GEST AS GESTDEST,
      NSP.PRET AS PRETE,
      NSD.PRET AS PRETI,
      NSD.CODTRANSF1,
      T.NRDOC,
      NSP.CODIOART AS CODIOARTP,
      NSD.CODIOART AS CODIOARTD,
      T1.CODMIFIX AS CODMIFIX_TRANSF1
    FROM
      LIVR1 L1,
      LIVR L,
      TRANSF T,
      TRANSF1 T1,
      NIRSER NSEP,
      NIRSTOC NSD,
      NIRSER NSED,
      NIRSTOC NSP,
      NIR ND,
      NIR NP,
      TMP_IOART_LUNA IOA
    WHERE
      L.CODTRANSF = aCODTRANSF
      AND L1.CODLIVR = L.CODLIVR
      AND T1.CODTRANSF1 = L1.CODIES1
      AND NSEP.CODNIRSER = L1.CODNIRSER
      AND NSD.CODLIVR1 = L1.CODLIVR1
      AND IOA.CODIOART = NSD.CODIOART
      AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
      AND NSED.CODNIRSTOC = NSD.CODNIRSTOC
      AND NSP.CODNIRSTOC = L1.CODNIRSTOC
      AND NVL(NSP.TIPSERIE, 0) = 1
      AND L1.CANT = 1
      AND ND.CODNIR = NSD.CODNIR
      AND NP.CODNIR = NSP.CODNIR
      AND L.CODTRANSF = T.CODTRANSF
    ) MF_TRANSF
    WHERE
    --  M1.ANSTART = PKG_GLOBALS.ANLUCRU
    --  AND M1.LUNASTART = PKG_GLOBALS.LUNALUCRU
       M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
      AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
      AND NVL(M1.CODNIRSER, 0) = NVL(MF_TRANSF.CODNIRSSERPARINTE, 0)
      AND M1.CODMIFIX = MF_TRANSF.CODMIFIX_TRANSF1
      AND M1.CODMIFIX = M.CODMIFIX
    )
    LOOP
    -- START CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --
        IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
          MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
        END IF;  
    -- END CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --


        UPDATE MIFIX1
        SET
          CODNIRSTOC = V_REC.CODNIRSTOCDEST,
          CODNIRSER = V_REC.CODNIRSERDEST
        WHERE
          CODMIFIX1 = V_REC.CODMIFIX1;


           INSERT INTO FISAMF(CODFISAMF,
                              CODMIFIX,
                              CODOPERATIE,
                              DATAOPERATIE,
                              GESTSURSA,
                              GESTDEST,
                              PRETI,
                              PRETE,
                              PREFIXDOC,
                              NRDOC,
                              CANT,
                              CODDOC1,
                              TIPDOC)
                       VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL,
                              V_REC.CODMIFIX,
                              2,
                              V_REC.DATALIVR,
                              V_REC.GESTSURSA,
                              V_REC.GESTDEST,
                              V_REC.PRETI,
                              V_REC.PRETE,
                              &apos;NT&apos;,
                              V_REC.NRDOC,
                              1,
                              V_REC.CODTRANSF1,
                              12);


          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            CODDOC = V_REC.CODMIFIX
            AND TIPDOC = 36
            AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;



    END LOOP;

  end if;
END;


 

PROCEDURE SOLVE_TRANSF_MIFIX(aCODTRANSF IN NUMBER, LegaturaTRANSF1 IN NUMBER)
IS
  NR            NUMBER;
  aCODMIFIXNOU  NUMBER;
  NRINVNOU      NUMBER;
BEGIN
  IF LegaturaTRANSF1 = 0 THEN -- fara legatura in transf1
    FOR V_REC IN (
      SELECT M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, M.TIP,  MF_TRANSF.*
      FROM 
        MIFIX1 M1,
        MIFIX M,
      (
      SELECT
        NSP.CODNIRSTOC CODNIRSTOPARINTE,
        NSP.CANTNIR AS CANTNIRPARINTE,
        NSD.CODNIRSTOC CODNIRSTOCDEST,
        L1.CANT,
        L.DATALIVR,
        NP.GEST AS GESTSURSA,
        ND.GEST AS GESTDEST,
        NSP.PRET AS PRETE,
        NSD.PRET AS PRETI,
        NSD.CODTRANSF1,
        NSP.CODIOART AS CODIOARTP,
        NSD.CODIOART AS CODIOARTD,
        T.NRDOC
      FROM
        LIVR1 L1,
        TRANSF1 T1,
        LIVR L,
        TRANSF T,
        NIRSTOC NSD,
        NIR ND,
        NIRSTOC NSP,
        NIR NP,
        TMP_IOART_LUNA IOA
      WHERE
        L.CODTRANSF = aCODTRANSF
        AND L1.CODLIVR = L.CODLIVR
        AND T1.CODTRANSF1 = L1.CODIES1
        AND NVL(T1.CODMIFIX, 0) = 0
        AND NSD.CODLIVR1 = L1.CODLIVR1
        AND NSP.CODNIRSTOC = L1.CODNIRSTOC
        AND IOA.CODIOART = NSD.CODIOART
        AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
        AND NVL(NSP.TIPSERIE, 0) = 0
        AND L1.CANT = 1
        AND NSP.CANTNIR &lt;= 1
        AND ND.CODNIR = NSD.CODNIR
        AND NP.CODNIR = NSP.CODNIR
        AND L.CODTRANSF = T.CODTRANSF
      ) MF_TRANSF
      WHERE
        M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       -- M1.ANSTART = PKG_GLOBALS.ANLUCRU
       -- AND M1.LUNASTART = PKG_GLOBALS.LUNALUCRU
        AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
        AND M1.CODMIFIX = M.CODMIFIX
     ORDER BY M1.ANSTART * 12 + M1.LUNASTART 
    ) LOOP
       -- START CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --
        IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
          MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
        END IF;  
    -- END CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --
    
    
    
      UPDATE 
        MIFIX1
      SET 
        CODNIRSTOC = V_REC.CODNIRSTOCDEST
      WHERE 
        CODMIFIX1 = V_REC.CODMIFIX1;

      SELECT COUNT(*) INTO NR
      FROM
        FISAMF
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND CODOPERATIE = 2
        AND CODDOC1 = V_REC.CODTRANSF1
        AND TIPDOC = 12;

      IF NR = 0 THEN
        INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, CODDOC1, TIPDOC)
        VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, 2, V_REC.DATALIVR, V_REC.GESTSURSA, V_REC.GESTDEST, V_REC.PRETI, V_REC.PRETE, &apos;NT&apos;, V_REC.NRDOC, 1, V_REC.CODTRANSF1, 12);
      END IF;

      UPDATE JURNAL1
      SET
        DIRTY = 1
      WHERE
        CODDOC = V_REC.CODMIFIX
        AND TIPDOC = 36
        AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
    END LOOP;
  ELSE -- cu legatura in transf1
    FOR V_REC IN (
      SELECT M1.CODMIFIX1, M1.CODMIFIX,M1.ANSTART, M1.LUNASTART, M.TIP, MF_TRANSF.*
      FROM 
        MIFIX1 M1,
        MIFIX M,
      (
      SELECT
        NSP.CODNIRSTOC CODNIRSTOPARINTE,
        NSP.CANTNIR AS CANTNIRPARINTE,
        NSD.CODNIRSTOC CODNIRSTOCDEST,
        L1.CANT,
        L.DATALIVR,
        NP.GEST AS GESTSURSA,
        ND.GEST AS GESTDEST,
        NSP.PRET AS PRETE,
        NSD.PRET AS PRETI,
        NSD.CODTRANSF1,
        T.NRDOC,
        NSP.CODIOART AS CODIOARTP,
        NSD.CODIOART AS CODIOARTD,
        T1.CODMIFIX AS CODMIFIX_TRANSF1
      FROM
        LIVR1 L1,
        TRANSF1 T1,
        LIVR L,
        TRANSF T,
        NIRSTOC NSD,
        NIR ND,
        NIRSTOC NSP,
        NIR NP,
        TMP_IOART_LUNA IOA
      WHERE
        L.CODTRANSF = aCODTRANSF
        AND L1.CODLIVR = L.CODLIVR
        AND T1.CODTRANSF1 = L1.CODIES1
        AND NSD.CODLIVR1 = L1.CODLIVR1
        AND NSP.CODNIRSTOC = L1.CODNIRSTOC
        AND IOA.CODIOART = NSD.CODIOART
        AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
        AND NVL(NSP.TIPSERIE, 0) = 0
        AND L1.CANT = 1
--      AND NSP.CANTNIR &lt;= 1
        AND ND.CODNIR = NSD.CODNIR
        AND NP.CODNIR = NSP.CODNIR
        AND L.CODTRANSF = T.CODTRANSF
      ) MF_TRANSF
      WHERE
        M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
        AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
        AND M.CODMIFIX = M1.CODMIFIX
        AND M1.CODMIFIX = MF_TRANSF.CODMIFIX_TRANSF1
    ) LOOP
     -- START CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --
        IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
          MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
        END IF;  
    -- END CERINTA SAFT : LA SCHIMBARE TIP CONTABIL CREEZ MIFIXNOU --


      UPDATE MIFIX1
      SET CODNIRSTOC = V_REC.CODNIRSTOCDEST
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;

      SELECT COUNT(*) INTO NR
      FROM
        FISAMF
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND CODOPERATIE = 2
        AND CODDOC1 = V_REC.CODTRANSF1
        AND TIPDOC = 12;

      IF NR = 0 THEN
        INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, CODDOC1, TIPDOC)
        VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, 2, V_REC.DATALIVR, V_REC.GESTSURSA, V_REC.GESTDEST, V_REC.PRETI, V_REC.PRETE, &apos;NT&apos;, V_REC.NRDOC, 1, V_REC.CODTRANSF1, 12);
      END IF;

      UPDATE JURNAL1
      SET
        DIRTY = 1
      WHERE
        CODDOC = V_REC.CODMIFIX
        AND TIPDOC = 36
        AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
    END LOOP;
  END IF;


END;


PROCEDURE CHECK_TRANSF_MIFIX_FARASERIE(aCODTRANSF IN NUMBER) IS
NR NUMBER;
BEGIN
  if vCodMifix &gt; 0 then
    FOR V_REC IN (
      SELECT M1.CODMIFIX1, M1.CODMIFIX, MF_TRANSF.*, M.TIP, M1.ANSTART, M1.LUNASTART
      FROM MIFIX1 M1, MIFIX M,
      (
      SELECT
        NSP.CODNIRSTOC CODNIRSTOPARINTE,
        NSP.CANTNIR AS CANTNIRPARINTE,
        NSD.CODNIRSTOC CODNIRSTOCDEST,
        L1.CANT,
        L.DATALIVR,
        NP.GEST AS GESTSURSA,
        ND.GEST AS GESTDEST,
        NSP.PRET AS PRETE,
        NSD.PRET AS PRETI,
        NSD.CODTRANSF1,
        NSP.CODIOART AS CODIOARTP,
        NSD.CODIOART AS CODIOARTD,
        T.NRDOC
      FROM
        LIVR1 L1,
        LIVR L,
        TRANSF T,
        NIRSTOC NSD,
        NIR ND,
        NIRSTOC NSP,
        NIR NP,
        TMP_IOART_LUNA IOA
      WHERE
        L.CODTRANSF = aCODTRANSF
        AND L1.CODLIVR = L.CODLIVR
        AND NSD.CODLIVR1 = L1.CODLIVR1
        AND NSP.CODNIRSTOC = L1.CODNIRSTOC
        AND IOA.CODIOART = NSD.CODIOART
        AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
        AND NVL(NSP.TIPSERIE, 0) = 0
        AND L1.CANT = 1
        AND NSP.CANTNIR = 1
        AND ND.CODNIR = NSD.CODNIR
        AND NP.CODNIR = NSP.CODNIR
        AND L.CODTRANSF = T.CODTRANSF
      ) MF_TRANSF
      WHERE
        M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       -- M1.ANSTART = PKG_GLOBALS.ANLUCRU
       -- AND M1.LUNASTART = PKG_GLOBALS.LUNALUCRU
        AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
        AND M1.CODMIFIX = vCodMifix
        AND M1.CODMIFIX = M.CODMIFIX
    ) LOOP
      IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
        MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
      END IF;  
      UPDATE MIFIX1
      SET CODNIRSTOC = V_REC.CODNIRSTOCDEST
      WHERE CODMIFIX1 = V_REC.CODMIFIX1;

      SELECT COUNT(*) INTO NR
      FROM
        FISAMF
      WHERE
        CODMIFIX = V_REC.CODMIFIX
        AND CODOPERATIE = 2
        AND CODDOC1 = V_REC.CODTRANSF1
        AND TIPDOC = 12;

      IF NR = 0 THEN
        INSERT INTO FISAMF(CODFISAMF, CODMIFIX, CODOPERATIE, DATAOPERATIE, GESTSURSA, GESTDEST, PRETI, PRETE, PREFIXDOC, NRDOC, CANT, CODDOC1, TIPDOC)
        VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL, V_REC.CODMIFIX, 2, V_REC.DATALIVR, V_REC.GESTSURSA, V_REC.GESTDEST, V_REC.PRETI, V_REC.PRETE, &apos;NT&apos;, V_REC.NRDOC, 1, V_REC.CODTRANSF1, 12);
      END IF;

      UPDATE JURNAL1
      SET DIRTY = 1
      WHERE
        CODDOC = V_REC.CODMIFIX
        AND TIPDOC = 36
        AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
    END LOOP;
  else
    Solve_TRANSF_MIFIX(aCODTRANSF, 1); --1 = cu legatura in TRANSF1
    Solve_TRANSF_MIFIX(aCODTRANSF, 0); --0 = fara legatura in TRANSF1
  end if;
END;

PROCEDURE CHECK_TRANSF_MIFIX_SERIEBUCATA(aCODTRANSF IN NUMBER) IS
BEGIN
  if vCodMifix &gt; 0 then
    FOR V_REC IN
    (
    SELECT M1.CODMIFIX1, M1.CODMIFIX, MF_TRANSF.*, M.TIP, M1.ANSTART, M1.LUNASTART
    FROM
     MIFIX1 M1, MIFIX M,
    (
    SELECT
      NSP.CODNIRSTOC CODNIRSTOPARINTE,
      NSP.CANTNIR AS CANTNIRPARINTE,
      NSEP.CODNIRSER AS CODNIRSSERPARINTE,
      NSD.CODNIRSTOC CODNIRSTOCDEST,
      NSED.CODNIRSER AS CODNIRSERDEST,
      L1.CANT,
      L.DATALIVR,
      NP.GEST AS GESTSURSA,
      ND.GEST AS GESTDEST,
      NSP.PRET AS PRETE,
      NSD.PRET AS PRETI,
      NSD.CODTRANSF1,
      NSP.CODIOART AS CODIOARTP,
      NSD.CODIOART AS CODIOARTD,
      T.NRDOC
    FROM
      LIVR1 L1,
      LIVR L,
      TRANSF T,
      NIRSER NSEP,
      NIRSTOC NSD,
      NIRSER NSED,
      NIRSTOC NSP,
      NIR ND,
      NIR NP,
      TMP_IOART_LUNA IOA
    WHERE
      L.CODTRANSF = aCODTRANSF
      AND L1.CODLIVR = L.CODLIVR
      AND NSEP.CODNIRSER = L1.CODNIRSER
      AND NSD.CODLIVR1 = L1.CODLIVR1
      AND IOA.CODIOART = NSD.CODIOART
      AND COALESCE(IOA.ESTEMIFIX, 0) + COALESCE(IOA.ESTEOBINV, 0) = 1
      AND NSED.CODNIRSTOC = NSD.CODNIRSTOC
      AND NSP.CODNIRSTOC = L1.CODNIRSTOC
      AND NVL(NSP.TIPSERIE, 0) = 1
      AND L1.CANT = 1
      AND ND.CODNIR = NSD.CODNIR
      AND NP.CODNIR = NSP.CODNIR
      AND L.CODTRANSF = T.CODTRANSF
    ) MF_TRANSF
    WHERE
    --  M1.ANSTART = PKG_GLOBALS.ANLUCRU
    --  AND M1.LUNASTART = PKG_GLOBALS.LUNALUCRU
       M1.ANSTART * 12 + M1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
      AND M1.CODNIRSTOC = MF_TRANSF.CODNIRSTOPARINTE
      AND NVL(M1.CODNIRSER, 0) = NVL(MF_TRANSF.CODNIRSSERPARINTE, 0)
      AND M1.CODMIFIX = vCodMifix AND M.CODMIFIX = M1.CODMIFIX
    )
    LOOP
      IF V_REC.CODIOARTP &lt;&gt; V_REC.CODIOARTD   AND V_REC.TIP = &apos;MF&apos; THEN
        MAKE_MIFIX_NOU(V_REC.CODMIFIX, V_REC.CODMIFIX1, V_REC.ANSTART, V_REC.LUNASTART);
      END IF;  
        UPDATE MIFIX1
        SET
          CODNIRSTOC = V_REC.CODNIRSTOCDEST,
          CODNIRSER = V_REC.CODNIRSERDEST
        WHERE
          CODMIFIX1 = V_REC.CODMIFIX1;


           INSERT INTO FISAMF(CODFISAMF,
                              CODMIFIX,
                              CODOPERATIE,
                              DATAOPERATIE,
                              GESTSURSA,
                              GESTDEST,
                              PRETI,
                              PRETE,
                              PREFIXDOC,
                              NRDOC,
                              CANT,
                              CODDOC1,
                              TIPDOC)
                       VALUES(SEQ_FISAMF_CODFISAMF.NEXTVAL,
                              V_REC.CODMIFIX,
                              2,
                              V_REC.DATALIVR,
                              V_REC.GESTSURSA,
                              V_REC.GESTDEST,
                              V_REC.PRETI,
                              V_REC.PRETE,
                              &apos;NT&apos;,
                              V_REC.NRDOC,
                              1,
                              V_REC.CODTRANSF1,
                              12);


          UPDATE JURNAL1
          SET
            DIRTY = 1
          WHERE
            CODDOC = V_REC.CODMIFIX
            AND TIPDOC = 36
            AND AN * 12 + LUNA &gt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;
    END LOOP;
  else
    Solve_TRANSF_MIFIX_serie(aCODTRANSF, 1); --1 = cu legatura in TRANSF1
    Solve_TRANSF_MIFIX_serie(aCODTRANSF, 0); --0 = fara legatura in TRANSF1
  end if;
END;

procedure SetDoCommit(aDoCommit in boolean) is
begin
  DoCommit := aDoCommit;
end;

procedure SetSkipMifix(aSkip in boolean) is
begin
  vSkipMifixAut := aSkip;
end;

PROCEDURE CHECK_COERENTA_MODIPRET_MF(aCODDOC IN NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE TMP_JURNAL_MAN;
  FOR V_REC IN
  (
  SELECT
    MF1.codmifix1,
    MF1.codmifix,
    MF1.pret,
    ns.pret AS PRETNIRSTOC,
    MF1.ANSTART,
    MF1.LUNASTART,
    NS.CODTRANSF1
  FROM
    NIRSTOC NS, NIR N, MIFIX1 MF1
  WHERE
    N.CODTRANSF = aCODDOC
    AND N.TIPNIR = 13
    AND NS.CODNIR = N.CODNIR
    AND MF1.CODNIRSTOC = NS.CODNIRSTOC
    AND MF1.ANSTART * 12 + MF1.LUNASTART &gt;= PKG_GLOBALS.ANLUCRU * 12  + PKG_GLOBALS.LUNALUCRU
    AND MF1.PRET &lt;&gt; NS.PRET
   )
   LOOP
     UPDATE MIFIX1
     SET
       PRET = V_REC.PRETNIRSTOC
     WHERE
       CODMIFIX1 = V_REC.CODMIFIX1;

     UPDATE FISAMF
     SET
       PRETE = V_REC.PRETNIRSTOC
     WHERE
       CODMIFIX = V_REC.CODMIFIX
       AND TIPDOC = 13
       AND CODDOC1 = V_REC.CODTRANSF1;

     UPDATE JURNAL1
     SET
       DIRTY = 1
     WHERE
       TIPDOC = 36 AND CODDOC = V_REC.CODMIFIX AND AN = V_REC.ANSTART AND LUNA = V_REC.LUNASTART;

      INSERT INTO TMP_JURNAL_MAN(CODDOC, TIPDOC) VALUES(V_REC.CODMIFIX, 36);
   END LOOP;
   COMMIT;
END;

PROCEDURE SOLVE_MIFIX(aCODTRANSF IN NUMBER)
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
  aTIPAMO NUMBER(1);
BEGIN
  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       CODNIRSTOCPARINTE,
       PRET,
       REST,
       AN,
       LUNA
      FROM
        NIRSTOC NS,
        NIR N,
        TRANSF T
      WHERE
        N.CODTRANSF = aCODTRANSF
        AND NS.CODNIR = N.CODNIR
        AND T.CODTRANSF = N.CODTRANSF
     )
  LOOP
    SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    IF NR = 0 THEN
      INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA)
      SELECT V_REC.CODNIRSTOC, CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA
      FROM MASTERMIFIX
      WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE;
    ELSE
      UPDATE MASTERMIFIX SET
      (CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA)
      = (SELECT CODCLASIF, DURATAN, DURATANF, DURATANG, CODANALIZA FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE)
      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    END IF;
    UPDATE MIFIX1 SET CODNIRSTOC = V_REC.CODNIRSTOC
    WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE
          AND ANSTART * 12 + LUNASTART &gt;= V_REC.AN * 12 + V_REC.LUNA;
  END LOOP;
  COMMIT;
END;

PROCEDURE SOLVE_OBINV(aCODTRANSF IN NUMBER, aCODCLASIF IN NUMBER )
IS
  REZOLVAT NUMBER(20, 7) := 0;
  CODCLASIF_MASTER NUMBER(20) := 0;
  aDURATAN NUMBER(20);
  NR NUMBER(10) := 0;
  aCODMIFIX NUMBER(20);
  aTIPAMO NUMBER(1);
BEGIN
  CODCLASIF_MASTER := aCODCLASIF;
  BEGIN
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipAmoOI&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipAmo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aTIPAMO := 1;
  END;


  FOR V_REC IN (
    SELECT
       CODNIRSTOC,
       PRET,
       REST,
       CODNIRSTOCPARINTE
      FROM
        NIRSTOC NS,
        NIR N,
        TMP_IOART_LUNA IOLUNA
      WHERE
        N.CODTRANSF = aCODTRANSF
        AND NS.CODNIR = N.CODNIR
        AND IOLUNA.CODIOART = NS.CODIOART
        AND IOLUNA.ESTEOBINV &gt; 0
     )
   LOOP
     SELECT NVL(SUM(CANT), 0) INTO REZOLVAT
     FROM
       MIFIX1 MF
     WHERE
       MF.CODNIRSTOC = V_REC.CODNIRSTOC
       AND MF.ANSTART * 12 + MF.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU;


     IF REZOLVAT &lt; V_REC.REST THEN
       BEGIN
         SELECT NVL(CODCLASIF, 0) INTO CODCLASIF_MASTER FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN CODCLASIF_MASTER := 0;
       END;

       IF CODCLASIF_MASTER = 0 THEN CODCLASIF_MASTER := aCODCLASIF;
       END IF;

       BEGIN
         SELECT DURATA INTO aDURATAN FROM MFCLASIF WHERE CODCLASIF = aCODCLASIF;
       END;


       IF aDURATAN &gt; 0 THEN

         SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         IF NR = 0 THEN
           INSERT INTO MASTERMIFIX(CODNIRSTOC, CODCLASIF, DURATAN)
           VALUES (V_REC.CODNIRSTOC, CODCLASIF_MASTER, aDURATAN);
         END IF;

         SELECT SEQ_MIFIX_CODMIFIX.NEXTVAL INTO aCODMIFIX FROM DUAL;

         INSERT INTO MIFIX(CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE )
         VALUES (aCODMIFIX, &apos;OI&apos;, PKG_MIFIX.GetNextNrInv(&apos;OI&apos;), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

         INSERT INTO MIFIX1(CODMIFIX1,
                            CODMIFIX,
                            CODNIRSTOC,
                            PRET,
                            CANT,
                            CODCLASIF,
                            TIPAMO,
                            STARE,
                            DURATAN,
                            GRADU,
                            DURATAF,
                            AMO,
                            DFBLOCAT,
                            ANSTART,
                            LUNASTART,
                            DFBLOCAT_F,
                            DFBLOCAT_G)
         VALUES(SEQ_MIFIX1_CODMIFIX1.NEXTVAL,
                aCODMIFIX,
                V_REC.CODNIRSTOC,
                V_REC.PRET,
                V_REC.REST - REZOLVAT,
                CODCLASIF_MASTER,
                aTIPAMO,
                1,
                aDURATAN,
                100,
                (SELECT DURATAF
                 FROM
                   MIFIX1
                 WHERE
                    CODNIRSTOC    = V_REC.CODNIRSTOCPARINTE
                    AND ANSTART   = PKG_GLOBALS.ANLUCRU
                    AND LUNASTART = PKG_GLOBALS.LUNALUCRU
                    AND ROWNUM    = 1
                ),
                (V_REC.REST - REZOLVAT) * V_REC.PRET,
                0,
                PKG_GLOBALS.ANLUCRU,
                PKG_GLOBALS.LUNALUCRU,
                1,
                1);


        UPDATE MIFIX1
        SET
          CANT = CANT - ( V_REC.REST - REZOLVAT)
        WHERE
          CODNIRSTOC  = V_REC.CODNIRSTOCPARINTE
          AND ANSTART = PKG_GLOBALS.ANLUCRU
          AND LUNASTART = PKG_GLOBALS.LUNALUCRU  ;

        DELETE FROM MIFIX1
        WHERE
          CANT = 0
          AND CODNIRSTOC  = V_REC.CODNIRSTOCPARINTE
          AND ANSTART = PKG_GLOBALS.ANLUCRU
          AND LUNASTART = PKG_GLOBALS.LUNALUCRU  ;


       END IF;
     END IF;


   END LOOP;
   COMMIT;

END;


PROCEDURE CHECK_REZERVARI(CODNIRSTOC_SURSA IN NUMBER, CODNIRSER_SURSA  IN NUMBER, CODNIRSTOC_DEST IN NUMBER, CODNIRSER_DEST IN NUMBER, aCANT IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTLIVR     NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTLIVR := aCANT;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
         CODNIRSTOC = CODNIRSTOC_SURSA
     AND CODNIRSER  = CODNIRSER_SURSA
   )
   LOOP
     IF (V_REC.REST &gt; 0)AND(CANTLIVR &gt; 0) THEN
       IF CANTLIVR &lt;= V_REC.REST THEN
         CANTREZ := CANTLIVR;
       ELSE
         CANTREZ := V_REC.REST;
       END IF;

       CANTLIVR := CANTLIVR - CANTREZ;

       IF CANTREZ = V_REC.REST THEN
         NEEDSTERGERE := 1;
       ELSE
         NEEDSTERGERE := 0;
       END IF;

       IF NEEDSTERGERE = 0 THEN
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = CANTREZERVAT - CANTREZ,
           REST         = NVL(REST, 0)         - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;
       ELSE
         DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;

       SELECT COUNT(*) INTO NR FROM REZERVATS
       WHERE
         CODNIRSTOC      = CODNIRSTOC_DEST
         AND CODNIRSER   = CODNIRSER_DEST
         AND CODCOMANDA1 = V_REC.CODCOMANDA1;
       IF NR = 0 THEN
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC, CODINVENTAR1)
                      VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, CODNIRSTOC_DEST, CODNIRSER_DEST, CANTREZ, V_REC.UMSEC,
                              V_REC.CODINVENTAR1);
       ELSE
         UPDATE REZERVATS
         SET
--         CANTREZERVAT = CANTREZERVAT + CANTREZ,
           REST         = NVL(REST, 0)         + CANTREZ
         WHERE
           CODNIRSTOC      = CODNIRSTOC_DEST
           AND CODNIRSER   = CODNIRSER_DEST
           AND CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
     END IF;
   END LOOP;
END;


PROCEDURE CHECK_REZERVARI_TRANSF(CODNIRSTOC_SURSA IN NUMBER, CODNIRSER_SURSA  IN NUMBER, CODNIRSTOC_DEST IN NUMBER, CODNIRSER_DEST IN NUMBER, aCANT IN NUMBER, aCODCOMANDA1 IN NUMBER, aCODCOMAND1ORIG IN NUMBER)
IS
  NR           NUMBER (10)   := 0;
  CANTLIVR     NUMBER(20, 7) := 0;
  CANTREZ      NUMBER(20, 7) := 0;
  NEEDSTERGERE NUMBER (1)    := 0;
BEGIN
  CANTLIVR := aCANT;
  FOR V_REC IN
  (SELECT * FROM REZERVATS
   WHERE
         CODNIRSTOC = CODNIRSTOC_SURSA
     AND CODNIRSER  = CODNIRSER_SURSA
     AND (CODCOMANDA1 = aCODCOMANDA1 OR CODCOMANDA1 = aCODCOMAND1ORIG)
     and nvl(codobiect,0) = 0
   )
   LOOP
     IF (V_REC.REST &gt; 0)AND(CANTLIVR &gt; 0) THEN
       IF CANTLIVR &lt;= V_REC.REST THEN
         CANTREZ := CANTLIVR;
       ELSE
         CANTREZ := V_REC.REST;
       END IF;

       CANTLIVR := CANTLIVR - CANTREZ;

       IF CANTREZ = V_REC.REST THEN
         NEEDSTERGERE := 1;
       ELSE
         NEEDSTERGERE := 0;
       END IF;

       IF NEEDSTERGERE = 0 THEN
         UPDATE REZERVATS
         SET
--           CANTREZERVAT = CANTREZERVAT - CANTREZ,
           REST         = NVL(REST, 0)         - CANTREZ
         WHERE
           CODREZERVATS = V_REC.CODREZERVATS;
       ELSE
         DELETE REZERVATS WHERE CODREZERVATS = V_REC.CODREZERVATS;
       END IF;

       SELECT COUNT(*) INTO NR FROM REZERVATS
       WHERE
         CODNIRSTOC      = CODNIRSTOC_DEST
         AND CODNIRSER   = CODNIRSER_DEST
         AND CODCOMANDA1 = V_REC.CODCOMANDA1;
       IF NR = 0 THEN
          INSERT INTO REZERVATS (CODREZERVATS, CODCOMANDA1, CODNIRSTOC, CODNIRSER, REST, UMSEC)
                      VALUES (SEQ_REZERVATS_CODREZERVATS.NEXTVAL, V_REC.CODCOMANDA1, CODNIRSTOC_DEST, CODNIRSER_DEST, CANTREZ, V_REC.UMSEC);
       ELSE
         UPDATE REZERVATS
         SET
--         CANTREZERVAT = CANTREZERVAT + CANTREZ,
           REST         = NVL(REST, 0)         + CANTREZ
         WHERE
           CODNIRSTOC      = CODNIRSTOC_DEST
           AND CODNIRSER   = CODNIRSER_DEST
           AND CODCOMANDA1 = V_REC.CODCOMANDA1;
        END IF;
     END IF;
   END LOOP;
END;




PROCEDURE CHECK_REZERVARI_MODIPRET_IN
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
      L1.CODNIRSTOC AS CODNIRSTOC_DEST,
      L1.CODNIRSER  AS CODNIRSER_DEST,
      L1.CANT,
      NS.CODNIRSTOC AS CODNIRSTOC_SURSA,
      NVL(NSE.CODNIRSER, 0) AS CODNIRSER_SURSA
    FROM
      TMP_LIVR1_INITIAL L1,
      TMP_NIRSTOCINI NS
      LEFT OUTER JOIN TMP_NIRSERINI NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
    WHERE
      NS.CODLIVR1 = L1.CODLIVR1
  )
  LOOP
    CHECK_REZERVARI(V_REC.CODNIRSTOC_SURSA, V_REC.CODNIRSER_SURSA, V_REC.CODNIRSTOC_DEST, V_REC.CODNIRSER_DEST, V_REC.CANT);
  END LOOP;
END;


PROCEDURE CHECK_REZERVARI_MODIPRET_OUT
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
      L1.CODNIRSTOC AS CODNIRSTOC_SURSA,
      L1.CODNIRSER  AS CODNIRSER_SURSA,
      L1.CANT,
      NS.CODNIRSTOC AS CODNIRSTOC_DEST,
      NVL(NSE.CODNIRSER, 0) AS CODNIRSER_DEST
    FROM
      TMP_LIVR1 L1,
      TMP_NIRSTOC NS
      LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC
    WHERE
      NS.CODLIVR1 = L1.CODLIVR1
  )
  LOOP
    CHECK_REZERVARI(V_REC.CODNIRSTOC_SURSA, V_REC.CODNIRSER_SURSA, V_REC.CODNIRSTOC_DEST, V_REC.CODNIRSER_DEST, V_REC.CANT);
  END LOOP;
END;

PROCEDURE CHECK_REZERVARI_TRANSF_IN
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
      L1.CODNIRSTOC AS CODNIRSTOC_DEST,
      L1.CODNIRSER  AS CODNIRSER_DEST,
      L1.CANT,
      NS.CODNIRSTOC AS CODNIRSTOC_SURSA,
      NVL(NSE.CODNIRSER, 0) AS CODNIRSER_SURSA,
      T1.CODCOMANDA1,
      NVL(CL.CODLINIECOMANDA, 0) AS CODCOMAND1ORIG
    FROM
      TMP_LIVR1_INITIAL L1,
      TMP_NIRSTOCINI NS
      LEFT OUTER JOIN TMP_NIRSERINI NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
      TRANSF1_MAN T1
      LEFT OUTER JOIN CMDLINK CL ON CL.CODCOMANDA1 = T1.CODCOMANDA1
    WHERE
      NS.CODLIVR1 = L1.CODLIVR1
      AND T1.CODTRANSF1 = L1.CODIES1
      AND NVL(T1.CODCOMANDA1, 0) &lt;&gt; 0
  )
  LOOP
    CHECK_REZERVARI_TRANSF(V_REC.CODNIRSTOC_SURSA,
                           V_REC.CODNIRSER_SURSA,
                           V_REC.CODNIRSTOC_DEST,
                           V_REC.CODNIRSER_DEST,
                           V_REC.CANT,
                           V_REC.CODCOMANDA1,
                           V_REC.CODCOMAND1ORIG
                           );
  END LOOP;
END;




PROCEDURE CHECK_REZERVARI_TRANSF_OUT
IS
BEGIN
  FOR V_REC IN
  (
    SELECT
      L1.CODNIRSTOC AS CODNIRSTOC_SURSA,
      L1.CODNIRSER  AS CODNIRSER_SURSA,
      L1.CANT,
      NS.CODNIRSTOC AS CODNIRSTOC_DEST,
      NVL(NSE.CODNIRSER, 0) AS CODNIRSER_DEST,
      T1.CODCOMANDA1,
      NVL(CL.CODLINIECOMANDA, 0) AS CODCOMAND1ORIG
    FROM
      TMP_LIVR1 L1,
      TMP_NIRSTOC NS
      LEFT OUTER JOIN TMP_NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
      TRANSF1 T1
      LEFT OUTER JOIN CMDLINK CL ON CL.CODCOMANDA1 = T1.CODCOMANDA1
    WHERE
      NS.CODLIVR1 = L1.CODLIVR1
      AND T1.CODTRANSF1 = L1.CODIES1
      AND NVL(T1.CODCOMANDA1, 0) &lt;&gt; 0
  )
  LOOP
    CHECK_REZERVARI_TRANSF(V_REC.CODNIRSTOC_SURSA,
                           V_REC.CODNIRSER_SURSA,
                           V_REC.CODNIRSTOC_DEST,
                           V_REC.CODNIRSER_DEST,
                           V_REC.CANT,
                           V_REC.CODCOMANDA1,
                           V_REC.CODCOMAND1ORIG);
  END LOOP;
END;



PROCEDURE EMPTY_TRANSF_TEMPTABLES
IS
BEGIN
  DELETE TMP_TRANSF1;
  DELETE TMP_TRANSF1_INITIAL;

  DELETE TMP_TRANSFLINK;
  DELETE TMP_TRANSFLINK_INITIAL;

  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;
  Delete TMP_NIRSTOC1;
  DELETE TMP_NIRSER;

  Delete TMP_LIVR;
  Delete TMP_LIVR1;
  Delete TMP_LIVR1_INITIAL;
  Delete TMP_LIVRTOT;
  Delete TMP_LIVRVAL;

  DELETE TMP_JURNAL;
  DELETE TMP_JURNAL1;

  Delete TMP_RULAJ;

  Delete TMP_IMBMIFIXLINK;
  Delete TMP_IMBMIFIXLINK_INITIAL;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_TRANSFEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_TRANSFEXT&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_TRANSF1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_TRANSF1EXT&apos;;
  END IF;
  -- ini files
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_TRANSFEXT_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_TRANSFEXT_INI&apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_TRANSF1EXT_INI&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;Delete from TMP_TRANSF1EXT_INI&apos;;
  END IF;


/*
  DELETE TMP_STINGERE;
  DELETE TMP_STINGERE_INITIAL;
  DELETE TMP_STINGERE_ASOCIAT;
*/
  COMMIT;
END;

FUNCTION STOCNEG_LA_STERG_TRANSF_ROSU(aCODTRANSF IN NUMBER) RETURN NUMBER
IS
 STOCNEG NUMBER(5) := 0;
 NR      NUMBER(5) := 0;
BEGIN
    SELECT COUNT(*) INTO NR
    FROM
      LIVR1 L1,
      LIVR L
    WHERE
      L1.CANT &lt; 0 AND L1.CODLIVR = L.CODLIVR
      AND L.TIPLIVR = 12  AND L.CODTRANSF = aCODTRANSF;


   IF NR = 0 THEN RETURN 0; END IF;

   FOR V_REC IN
   (
        SELECT
        NS.CODNIRSTOC,
        NS.CANTNIR,
        ALTELIVR.CANTIES,
        LIVRCURENT.CANTDOCCURENT
      FROM
      (
        SELECT
          L1.CODNIRSTOC,
          SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTDOCCURENT
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
         L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR = 12 AND L.CODTRANSF = aCODTRANSF
        GROUP BY
         L1.CODNIRSTOC
      ) LIVRCURENT,
       (SELECT
         CODNIRSTOC,
         SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTIES
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
          L1.CODLIVR = L.CODLIVR
          AND NOT (L.TIPLIVR = 12 AND L.CODTRANSF = aCODTRANSF)
        GROUP BY CODNIRSTOC
       ) ALTELIVR,
       NIRSTOC NS
      WHERE
       NS.CODNIRSTOC = LIVRCURENT.CODNIRSTOC
       AND  LIVRCURENT.CODNIRSTOC = ALTELIVR.CODNIRSTOC
   ) LOOP
        IF V_REC.CANTNIR &lt; V_REC.CANTIES THEN RETURN 1; END IF;
     END LOOP;

  RETURN STOCNEG;
END;


FUNCTION STOC_NEG_LIVR1_TRANSF_ROSU(aCODLIVR1 IN NUMBER) RETURN NUMBER
IS
 STOCNEG NUMBER(5) := 0;
 NR      NUMBER(5) := 0;
BEGIN
  SELECT COUNT(*) INTO NR
  FROM
    LIVR1 L1,
    LIVR L
  WHERE
    L1.CANT &lt; 0 AND L1.CODLIVR = L.CODLIVR
    AND L.TIPLIVR = 12 AND L1.CODLIVR1 = aCODLIVR1;
   IF NR = 0 THEN RETURN 0; END IF;

   FOR V_REC IN
   (
        SELECT
        NS.CODNIRSTOC,
        NS.CANTNIR,
        ALTELIVR.CANTIES,
        LIVRCURENT.CANTDOCCURENT
      FROM
      (
        SELECT
          L1.CODNIRSTOC,
          SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTDOCCURENT
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
         L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR = 12 AND L1.CODLIVR1 = aCODLIVR1
        GROUP BY
         L1.CODNIRSTOC
      ) LIVRCURENT,
       (SELECT
         CODNIRSTOC,
         SUM(DECODE(L.TIPLIVR, 15, -L1.CANT, L1.CANT)) AS CANTIES
        FROM
         LIVR1 L1,
         LIVR L
        WHERE
          L1.CODLIVR = L.CODLIVR
          AND NOT (L.TIPLIVR = 12 AND L1.CODLIVR1 = aCODLIVR1)
        GROUP BY CODNIRSTOC
       ) ALTELIVR,
       NIRSTOC NS
      WHERE
       NS.CODNIRSTOC = LIVRCURENT.CODNIRSTOC
       AND  LIVRCURENT.CODNIRSTOC = ALTELIVR.CODNIRSTOC
   ) LOOP
        IF V_REC.CANTNIR &lt; V_REC.CANTIES THEN RETURN 1; END IF;
     END LOOP;

  RETURN STOCNEG;
END;

PROCEDURE SP_POSTRECORDS_FROM_IMPORT(RECID OUT NUMBER ) IS
  VCOD NUMBER(20);
  OLDCARNETNIR  NUMBER(20) := 0;
  OLDNRNIR      NUMBER(20) := 0;

  OLDCARNETLIVR NUMBER(20) := 0;
  OLDNRLIVR     NUMBER(20) := 0;

  ACARNET       NUMBER(20) := 0;
  ANUMARDOC     NUMBER(20) := 0;
  ATIPDOC       NUMBER(20) := 0;
  NR            NUMBER(10) := 0;
  aCODSERIE     NUMBER(20) := 0;
  NOMSERIE      VARCHAR2(75);

  aCodComanda1 number(20);
  aRoot        number(20);
  aDirty       number(1);
  aTipNIR      number(10);
  aPretMat     number(20,7);
BEGIN
  SELECT CARNETDOC, NRDOC, TIPDOC INTO ACARNET, ANUMARDOC, ATIPDOC FROM TMP_TRANSF;

  -- POZITII NOI IN INTRARI
  INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA)
  SELECT  CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA FROM TMP_INTRARI;

  INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG)
  SELECT CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, UMSEC, AN, LUNA, CODOBIECT, PRETORIG , PU, 0, TG FROM TMP_INTRARI1;

  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  -- REZOLVARE CIOBANEASCA BUG ; - REPUN IN NIRSTOC VALORI MOSTENITE DE PE NIRSTOCPARINTE
  UPDATE TMP_NIRSTOC NS
  SET (DATAACHIZ, TG, TIPDOCACHIZ) = (SELECT DATAACHIZ, TG, TIPDOCACHIZ FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOCPARINTE);

  -- sunt transferuri care se fac cu scopul de a modifica TG-ul pe serie; trebuie sa sincronizez tG-ul din nirstoc si nirser
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC WHERE NVL(TIPSERIE, 0) &gt; 0 AND TG IS NOT NULL)
  LOOP
    UPDATE TMP_NIRSTOC NS
    SET
      TG = (SELECT TG FROM TMP_NIRSER NSE WHERE NSE.CODNIRSTOC = V_REC.CODNIRSTOC AND ROWNUM = 1)
    WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  SELECT SEQ_TRANSF_CODTRANSF.NEXTVAL INTO RECID FROM DUAL;

  INSERT INTO TRANSF (
    CODTRANSF, TIPDOC,  ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
    NRDOC,  DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
    OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, SUBUNITATEA, userID,datacreare,
    MIJLTRANSP, NRTRANSP, CODGESTCMD, IDIMPORT, AJUSTVALSTOC, TipET )
  SELECT
    RECID, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
    NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
    OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET,SUBUNITATEA,pkg_globals.USERID,systimestamp,
    MIJLTRANSP, NRTRANSP, CODGESTCMD, IDIMPORT, AJUSTVALSTOC, TipET
  FROM TMP_TRANSF;

  FOR V_REC IN ( SELECT * FROM TMP_TRANSF1 ORDER BY INDEXLOCAL ) LOOP
    -- DETAIL TRANSF1
    SELECT SEQ_TRANSF1_CODTRANSF1.NEXTVAL INTO VCOD FROM DUAL;
    update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.codtransf1;

    INSERT INTO TRANSF1
      ( CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, CODCONT, UMSEC, CODOBIECT, PU, PUMAXIMAL,  CANT, TVA, D1, D2, D3)
    VALUES
      ( VCOD, RECID, V_REC.INDEXLOCAL,  V_REC.TIPLINIE, V_REC.CODOBIECTORIG, V_REC.PARITATEORIG,  V_REC.CODCONT, V_REC.UMSEC,
        V_REC.CODOBIECT,  V_REC.PU / V_REC.PARITATE,  V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.CANT * V_REC.PARITATE,  V_REC.TVA, V_REC.D1, V_REC.D2, V_REC.D3);

    UPDATE TMP_LIVR1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODTRANSF1;
    UPDATE TMP_NIRSTOC SET CODTRANSF1 = VCOD WHERE CODTRANSF1 = V_REC.CODTRANSF1;
  END LOOP;

 -- LIVR
  FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP
    SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

    INSERT INTO LIVR (CODLIVR, CODIES, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    VALUES (VCOD,  V_REC.CODIES, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR, V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

    UPDATE TMP_LIVR1 SET CODLIVR = VCOD WHERE CODLIVR = V_REC.CODLIVR;
  END LOOP;

 -- LIVR1
   FOR V_REC IN ( SELECT * FROM TMP_LIVR1 ORDER BY CODLIVR1 ) LOOP
      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
     UPDATE TMP_LIVRVAL LV
     SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
     WHERE
       LV.CODLIVR1 = V_REC.CODLIVR1;

     SELECT  SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

     INSERT INTO LIVR1
      (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTUM1, CANTUM2,   CODNIRSER, PMP, PMPDOC, PMPVALUTA, PMPVALUTADOC, UMSEC)
     VALUES
       (VCOD, V_REC.CODLIVR,  V_REC.CODIES1,  V_REC.CODINTR1,  V_REC.CODNIRSTOC,   V_REC.CANT *  V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2,
        V_REC.CODNIRSER,  V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC, V_REC.UMSEC);

     UPDATE TMP_NIRSTOC SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
   END LOOP;

   INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
   SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;

   UPDATE NIRSTOC NS
   SET
    REST    = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);


-- DETAIL NIR
  FOR V_REC IN ( SELECT * FROM TMP_NIR ORDER BY CODNIR ) LOOP
    SELECT SEQ_NIR_CODNIR.NEXTVAL INTO VCOD FROM DUAL;

    IF V_REC.TIPNIR IN (12, 13) THEN
      INSERT INTO NIR (CODNIR, CODINTR, CODTRANSF, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT )
      VALUES (VCOD, V_REC.CODINTR, RECID, V_REC.CARNETNIR, V_REC.NRNIR, V_REC.DATANIR, V_REC.GEST, V_REC.OBS, V_REC.TIPNIR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);
   ELSE
     INSERT INTO NIR (CODNIR, CODINTR, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT )
     VALUES (VCOD, V_REC.CODINTR, V_REC.CARNETNIR, V_REC.NRNIR, V_REC.DATANIR, V_REC.GEST, V_REC.OBS, V_REC.TIPNIR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

   END IF;
    UPDATE TMP_NIRSTOC SET CODNIR = VCOD WHERE CODNIR = V_REC.CODNIR;
  END LOOP;


-- DETAIL NIRSTOC
  DELETE TMP_NIRSTOC_RECOD; -- folosit la reevaluari
  FOR V_REC IN ( SELECT * FROM TMP_NIRSTOC ORDER BY CODNIRSTOC ) LOOP
    IF V_REC.CODNIRSTOC &lt; 0
      THEN SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO VCOD FROM DUAL;
      ELSE VCOD := V_REC.CODNIRSTOC;
    END IF;


    INSERT INTO TMP_NIRSTOC_RECOD(CODVECHI, CODNOU) VALUES(V_REC.CODNIRSTOC, VCOD); -- folosit la reevaluari

    INSERT INTO NIRSTOC (CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, CANTNIR, CANTFURN, UMSEC,  CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, RESTUM1, RESTUM2, PROCENTADAOS, Supliment, TG, PUMAXIMAL, FURN, DATAACHIZ, TIPDOCACHIZ, CODGESTPROD, SUBUNITATEA, CANTUM1, CANTUM2)
           VALUES (VCOD, V_REC.CODNIR, V_REC.CODINTR1, V_REC.CODTRANSF1, V_REC.CODNIRSTOCPARINTE, V_REC.CANTNIR * V_REC.PARITATE,  V_REC.CANTFURN * V_REC.PARITATE,  V_REC.UMSEC, V_REC.CODOBIECT, NVL(V_REC.CODIOART, 0), V_REC.PRET / V_REC.PARITATE, V_REC.ROTLEI, V_REC.ROTVALUTA, V_REC.CODLOCATIE, V_REC.ADAOS, V_REC.TVA, V_REC.TIPSERIE, V_REC.CODLIVR1,
      PKG_INTRARI.GET_REST_STOC    (V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * V_REC.PARITATE),
      PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
      PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
      V_REC.PROCENTADAOS, V_REC.Supliment, V_REC.TG, V_REC.PUMAXIMAL, V_REC.FURN, V_REC.DATAACHIZ, V_REC.TIPDOCACHIZ, V_REC.CODGESTPROD, V_REC.SUBUNITATEA,
      V_REC.CANTUM1, V_REC.CANTUM2 );

    /*aRoot := PKG_LIST_BASE_UTILS.GETCODNIRSTOC_ORIG(VCOD);
    begin
      select tipdoc, codcomanda1, pretmat, dirty into aTipNIR, aCodComanda1, aPretMat, aDirty
      from nirstoc1 where codnirstoc = aRoot;
    exception when others then
      insert into nirstoc1(codnirstoc, codnirstocorig, tipdoc, pretmat, dirty, dinstoc, codcomanda1)
      select ns.codnirstoc, ns.codnirstoc, nir.tipnir, nvl(ns.pret,0) - nvl(ns.adaos,0), case when nir.tipnir = 7 then 1 else 0 end,
             case when nir.tipnir = 7 then 0 else 1 end, nvl(i1.codcmdint1,0)
      from nirstoc ns
           inner join nir on nir.codnir = ns.codnir
           left join intrari1 i1 on ns.codintr1 = i1.codintr1
      where codnirstoc = aRoot;
      select tipdoc, codcomanda1, pretmat, dirty into aTipNIR, aCodComanda1, aPretMat, aDirty
      from nirstoc1 where codnirstoc = aRoot;
    end;

    INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
    values (VCOD, aRoot, aTIPNIR, aPretMat, aDirty, 1, aCodComanda1);*/

    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  -- DETAIL NIRSER
--  INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST)
--  (SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL, CODNIRSTOC, CODSERIE, CANTNIR, CANTNIR FROM TMP_NIRSER);


-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      BEGIN
        SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
        EXCEPTION WHEN OTHERS THEN NOMSERIE := &apos;&apos;;
      END;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;

    IF V_REC.CODNIRSER &lt; 0
      THEN SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCod from DUAL;
      ELSE VCOD := V_REC.CODNIRSER;
    END IF;

    INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST, CANTUM1, CANTUM2) VALUES
    (vCod, V_REC.CODNIRSTOC, aCODSERIE, V_REC.CANTNIR, V_REC.CANTNIR, V_REC.CANTUM1, V_REC.CANTUM2);
  END LOOP;



  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, CODANALIZANOD FROM TMP_JURNAL1);



  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODANALIZANOD)
  ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODANALIZANOD FROM TMP_JURNAL);


  -- ACTUALIZARE CARNETE DOCUMENTE
  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNET &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(ACARNET, ANUMARDOC);

  FOR V_REC IN (SELECT * FROM LIVR WHERE CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
  END LOOP;


  FOR V_REC IN (SELECT * FROM NIR WHERE CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
  END LOOP;


  COMMIT;
 END;



PROCEDURE SETNRDOC_I(ANRDOC IN NUMBER, ACARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

FUNCTION NR_LIVRARI_DIN_NIRTRANSF(ACODTRANSF IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(COUNT(*), 0) INTO NR FROM LIVR1
    WHERE
      CODNIRSTOC IN
       ( SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN
       ( SELECT CODNIR FROM NIR WHERE CODTRANSF = ACODTRANSF AND TIPNIR IN (12, 13) )
       );
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;


PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
  TMP NUMBER(20);
BEGIN
  SELECT CODTRANSF INTO TMP FROM TRANSF WHERE CODTRANSF = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(PKG_GLOBALS.GetTipMiscareInterna);
  INSERT INTO  TMP_TRANSF FIELDS( CODTRANSF ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(PKG_GLOBALS.GetTipMiscareInterna);
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
 ACARNETDOC NUMBER(20);
 ANRDOC NUMBER(20);
 ATIPDOC NUMBER(20);

 aCodSubunit NUMBER(20);
 aDataDoc DATE;
 aDoc varchar2(200);
 aCURS NUMBER(20, 7);
 aPRETPARINTE NUMBER(20, 7);
 PRET_IMB_MF   NUMBER(20, 7);
 VAL_ACHIZ_MF NUMBER(20, 7);
 CANT_IMB_MF  NUMBER(20, 7);

 ANPREC   NUMBER(20) := 0;
 LUNAPREC NUMBER(20) := 0;
 NR       NUMBER(20) := 0;
 aTipNS1  number;
 aCodRezervats number(20);
 aCodNirStocOrig number(20);
 LivrDinRezTransf number(1);
 aCodClasif number(20);
 aDurataN number;
 aDurataF number;
 aDurataNG number;
 aDurataNF number;
 aCodCentru number;
 aCONTIO    NUMBER;
 aCodMifix number(20);
BEGIN
-- MEMOREZ LIVRARILE CARE VOR FI STERSE
  SELECT PKG_CATEGCONST.GetValConstanta(&apos;LivrDinRezTransf&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO LivrDinRezTransf FROM DUAL;
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  SELECT CARNETDOC,  NRDOC,  TIPDOC,  SUBUNITATEA, DATADOC,  PREFIXDOC||NRDOC||&apos;/&apos;DATADOC INTO
         ACARNETDOC, ANRDOC, aTIPDOC, aCodsubunit, ADATADOC, ADOC
  FROM TRANSF WHERE CODTRANSF = RECID;

  PKG_CFGTABLES.EXT_DELETERECORD (recId, aTIPDOC);
  DELETE FROM DetaliiET1 et1
              where et1.coddetaliuet in (select et.coddetaliu
                                           from detaliiet et
                                           WHERE et.TipDoc = aTipDoc and et.CODDOC = RECID);
  DELETE FROM DetaliiET  WHERE TipDoc = aTipDoc and CODDOC = RECID;
  DELETE FROM STATUSDECL WHERE TipDoc = 100+aTipDoc and CODDOC = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;TRANSF&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE TRANSF1_MAN;
  INSERT INTO TRANSF1_MAN
  SELECT * FROM TRANSF1 WHERE CODTRANSF = RECID;

  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CODUNIC)
  SELECT CODNIRSTOC FROM LIVR1 WHERE CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODTRANSF = RECID);

  DELETE TMP_COMANDA1;
  INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
  SELECT CODLINIECOMANDA FROM TRANSFLINK IL
  WHERE IL.CODTRANSF1 IN (SELECT I1.CODTRANSF1 FROM TRANSF1 I1 WHERE CODTRANSF = RecID );


-- EMULARE1
FOR V_REC IN
(
SELECT
  E1.CODEMULARE1,
  NP.GEST,
  NSP.CODIOART,
  NSP.PRET
FROM
  TRANSF1 T1,
  NIRSTOC NS,
  NIRSTOC NSP,
  NIR NP,
  EMULARE1 E1
WHERE
  T1.CODTRANSF = RECID
  AND T1.CODEMULARE1 = E1.CODEMULARE1
  AND NS.CODTRANSF1 = T1.CODTRANSF1
  AND NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
  AND NP.CODNIR = NSP.CODNIR
 )
LOOP
  UPDATE EMULARE1
  SET
    CODGEST = V_REC.GEST,
    CODIOART = V_REC.CODIOART,
    PRETNIRSTOC = V_REC.PRET
  WHERE
    CODEMULARE1 = V_REC.CODEMULARE1;

END LOOP;



-- LIVRARI

  DELETE TMP_LIVR1;

  INSERT INTO TMP_LIVR1(CODLIVR1, CODNIRSTOC, CODNIRSER, CANT, CODIES1, CANTREZERVAT)
  SELECT CODLIVR1, CODNIRSTOC, CODNIRSER, CANT, CODIES1, CANTREZERVAT FROM LIVR1 L1
  WHERE
  CODLIVR IN
  (SELECT CODLIVR FROM LIVR WHERE CODTRANSF = RECID);

  DELETE TMP_LIVR1_INITIAL;
  INSERT INTO TMP_LIVR1_INITIAL SELECT * FROM TMP_LIVR1;

  DELETE FROM LIVRVAL  WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);
  DELETE FROM LIVR1 L1 WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

  -- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
  FOR V_REC IN (SELECT * FROM LIVR WHERE  CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
  END LOOP;

  DELETE FROM LIVR  WHERE CODTRANSF = RECID ;

  DELETE TMP_NIRSERINI;
  INSERT INTO TMP_NIRSERINI(CODNIRSER, CODNIRSTOC, CANTNIR)
  SELECT CODNIRSER, CODNIRSTOC, CANTNIR FROM NIRSER
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID));


  DELETE FROM NIRSER
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID));


  DELETE FROM NIRSERLUNA
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID)) ;


  DELETE FROM NIRLUNA
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID)) ;

  DELETE TMP_NIRSTOCINI;

  DELETE TMP_TRANSFLINK_INITIAL;
  INSERT INTO TMP_TRANSFLINK_INITIAL(CODTRANSF1, CODLINIECOMANDA, CANT)
  SELECT CODTRANSF1, CODLINIECOMANDA, CANT FROM TRANSFLINK WHERE CODTRANSF1 IN (SELECT CODTRANSF1 FROM TRANSF1 WHERE CODTRANSF = RecId);



  -- STERG MIJLOACE FIXE
  FOR V_REC IN (SELECT NS.*, N.GEST, T1.CODCOMANDA1 FROM NIRSTOC NS, NIR N, TRANSF1 T1 WHERE N.CODNIR = NS.CODNIR AND N.CODTRANSF = RECID AND NS.CODTRANSF1 = T1.CODTRANSF1)
  LOOP
  /* asta nu se poate pentru ca este validata din delphi
    FOR V_REC_MF IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC)
    LOOP
      DELETE FROM MIFIX1 WHERE CODMIFIX1 = V_REC_MF.CODMIFIX1;
      DELETE FROM MIFIX  WHERE CODMIFIX  = V_REC_MF.CODMIFIX;
    END LOOP;
*/

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, ANPREC, LUNAPREC);
    PKG_GLOBALS.SetLunaPRECEDENTA(ANPREC, LUNAPREC);
    PKG_GLOBALS.SetLunaTEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);




     FOR V_REC_MIFIX1 IN (SELECT * FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC)
     LOOP
      BEGIN
        SELECT NVL(PRET, 0) INTO aPRETPARINTE FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE;
        SELECT NVL(CONT, 0) INTO aCONTIO FROM NIRSTOC NS, TMP_IOART_LUNA IO1 WHERE NS.CODNIRSTOC = V_REC.CODNIRSTOCPARINTE AND NS.CODIOART = IO1.CODIOART;
        EXCEPTION WHEN OTHERS THEN aPRETPARINTE := 0;
      END;
      IF aCONTIO &lt;&gt; 0 AND (PKG_CATEGCONST.ESTEMIFIX(aCONTIO) = 1 OR PKG_CATEGCONST.ESTEOBINV(aCONTIO) = 1  OR PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(aCONTIO) = 1) THEN
            BEGIN
              SELECT codclasif, durataf, duratan, duratang, duratanf, codcentru INTO acodclasif, aDurataF, aDurataN, aDurataNG, aDurataNF, aCodCentru
              FROM MIFIX1
              WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE
                    and rownum = 1;
            EXCEPTION WHEN OTHERS THEN
              begin
                select codclasif, durata, durataf, duratag, durataf into acodclasif, aDurataN, aDurataF, aDurataNG, aDurataNF
                from mfclasif
                where codclasif = PKG_CATEGCONST.GetValConstanta(&apos;CodClasifImob&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
              exception when others then
                acodclasif := 0;
                aDurataF   := 0;
                aDurataN   := 0;
                aDurataNG  := 0;
                aDurataNF  := 0;
              end;
              aCodCentru := v_rec_mifix1.CodCentru;
            END;
            
            begin
              select coalesce(codmifix,0) into aCodMifix from mifix where codmifixnou = v_rec_mifix1.codmifix;
            exception when others then aCodMifix := v_rec_mifix1.codmifix;
            end;
            
            if aCodMifix = 0 then aCodMifix := v_rec_mifix1.codmifix; end if;
            if aCodMifix &lt;&gt; v_rec_mifix1.codmifix then
              update mifix set codmifixnou = null, anlunamifixnou = null where codmifix = acodmifix;
            end if;
            
            UPDATE MIFIX1
            SET
              codmifix   = aCodMifix,
              CODNIRSTOC =  V_REC.CODNIRSTOCPARINTE,
              PRET       =  aPRETPARINTE,
              DATAREEVAL = NULL,
              AMOVECHI   = 0,
              PRETVECHI  = 0,
              CodCentru  = aCodCentru,
              TIPREEVAL  = NULL,
              INCLUDRATA = NULL
            WHERE
              CODMIFIX1   = V_REC_MIFIX1.CODMIFIX1;

            update mifix1 set codmifix = aCodMifix, codnirstoc = v_rec.codnirstocparinte where codnirstoc = v_rec.codnirstoc and anstart*12+lunastart &gt; v_rec_mifix1.anstart*12+v_rec_mifix1.lunastart;

            if aCodClasif &gt; 0 then
              if aTipDoc = 12 then
                for v_ns in (select ns.codnirstoc
                             from nirstoc ns
                                  inner join nirstoc nsp on nsp.codnirstoc = ns.codnirstocparinte
                                  inner join ioart1 ioa1 on ioa1.codioart = ns.codioart    and pkg_globals.anlunalucru BETWEEN ioa1.alstart  AND ioa1.alstop
                                  inner join ioart1 ioa1p on ioa1p.codioart = nsp.codioart and pkg_globals.anlunalucru BETWEEN ioa1p.alstart AND ioa1p.alstop
                             where ns.codnirstoc = v_Rec.Codnirstoc and nsp.codnirstoc = v_rec.codnirstocparinte
                               and PKG_CATEGCONST.ESTEMIFIX(IOA1.CONT) &gt; 0 and PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(IOA1P.CONT) &gt; 0
                            ) loop
                  update mifix1
                  set
                    stare = 5,
                    codclasif = acodclasif,
                    durataf = adurataf,
                    duratan = aduratan,
                    duratanf = aduratanf,
                    duratang = aduratang,
                    durataff = adurataf * 12,
                    duratafg = aduratang * 12
                  where codmifix1 = V_REC_MIFIX1.CODMIFIX1;
                end loop;
              end if;
            end if;

            IF V_REC_MIFIX1.ANSTART = PKG_GLOBALS.ANLUCRU AND V_REC_MIFIX1.LUNASTART = PKG_GLOBALS.LUNALUCRU THEN
              PKG_INCHIDERI.REFA_MIFIX(V_REC_MIFIX1.CODMIFIX);
            END IF;

            UPDATE JURNAL1
            SET
              DIRTY = 1
            WHERE
              TIPDOC = 36
              AND CODDOC = V_REC_MIFIX1.CODMIFIX
              AND AN * 12 + LUNA &gt;= V_REC_MIFIX1.ANSTART*12+V_REC_MIFIX1.LUNASTART;
       END IF;
       
     END LOOP;
--    DELETE FROM MASTERMIFIX  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

      SELECT COUNT(*) INTO NR FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOCPARINTE;
      IF NR = 0 THEN
        UPDATE MASTERMIFIX  SET CODNIRSTOC = V_REC.CODNIRSTOCPARINTE WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      ELSE
         DELETE FROM MASTERMIFIX  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;

    INSERT INTO TMP_NIRSTOCINI (CODNIRSTOC, CODLIVR1) VALUES(V_REC.CODNIRSTOC, V_REC.CODLIVR1);

    IF aTIPDOC = 13 THEN

      DELETE FROM FISAMF
      WHERE
        CODOPERATIE IN (6, 7)
        AND NRDOC = RECID; -- la reevaluari tin codtranf in nrdoc


      DELETE FROM FISAMF
      WHERE
        CODOPERATIE = 3
        AND NRDOC        = aNRDOC
        AND DATAOPERATIE = aDATADOC
        AND PRETE        = V_REC.PRET
        AND GESTDEST     = V_REC.GEST;
    ELSE
      DELETE FROM FISAMF
      WHERE
        CODOPERATIE = 2
        AND NRDOC        = aNRDOC
        AND DATAOPERATIE = aDATADOC
        AND PRETE        = V_REC.PRET
        AND GESTDEST     = V_REC.GEST;
    END IF;

    if LivrDinRezTransf = 1 or v$Session_LivrDinRezTransf = 1 then
      for v_tmp in (select r.*
                    from rezervats r
                    where r.codnirstoc = v_rec.codnirstoc and (v_Rec.codcomanda1 = r.codcomanda1 or v_rec.codcomanda1 is null)
                   ) loop
        delete rezervats where codrezervats = v_tmp.codrezervats;
        if v_tmp.codcomanda1 &gt; 0 then
          begin
            select CodRezervatS into aCodRezervats
            from rezervats
            where codcomanda1 = v_tmp.codcomanda1 and codnirstoc = v_rec.codnirstocparinte;
          exception when others then aCodrezervats := 0;
          end;
          if aCodrezervatS &gt; 0 then
            update rezervats set
              rezervatini = rezervatini + v_tmp.rezervatini,
              rest        = rest + v_tmp.rest
            where codrezervats = acodrezervats;
          else
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, v_rec.codnirstocparinte, v_tmp.codnirser, v_tmp.rest,
                    v_tmp.umsec, v_tmp.codcmdprodmat, v_tmp.rezervatini, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          end if;
        end if;
      end loop;
    end if;

    DELETE FROM MIFIX1      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM MASTERMIFIX WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC     WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM NIRSTOC1    WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    DELETE FROM REZERVATS   WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;



-- INAINTE DE STEREGERE DIN NIR REACTIVEZ NUMERELE
  FOR V_REC IN (SELECT * FROM NIR WHERE  CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
  END LOOP;

  DELETE FROM NIR WHERE CODTRANSF = RECID ;

  DELETE FROM TRANSFLINK WHERE CODTRANSF1 IN (SELECT CODTRANSF1 FROM TRANSF1 WHERE CODTRANSF = RecId);

  DELETE TMP_IMBMIFIXLINK;
  INSERT INTO TMP_IMBMIFIXLINK (CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX)
  SELECT L.CODTRANSF1, CODINTR1, CODIES1, CODNC1, L.CODMIFIX
  FROM IMBMIFIXLINK L, TRANSF1 T1
  WHERE T1.CODTRANSF = RECID
    AND L.CODTRANSF1 = T1.CODTRANSF1;

  DELETE IMBMIFIXLINK IL
  WHERE EXISTS (SELECT CODTRANSF1 FROM TMP_IMBMIFIXLINK WHERE CODTRANSF1 = IL.CODTRANSF1);

  UPDATE CANTAR
  SET TIPDOC = NULL, CODDOC1 = NULL
  WHERE TIPDOC = aTIPDOC
    AND CODDOC1 IN (SELECT CODTRANSF1 FROM TRANSF1 WHERE CODTRANSF = RECID);

  DELETE FISAMF WHERE CODDOC1 IN (SELECT CODTRANSF1 FROM TRANSF1 WHERE CODTRANSF = RECID) AND TIPDOC = ATIPDOC;

  DELETE FROM TRANSF1  WHERE CODTRANSF = RECID ;

  DELETE FROM TRANSF   WHERE CODTRANSF = RECID ;
  -- REALOC IN DOCFREE NUMARUL DE DOCUMENT STERS
  PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = ATIPDOC) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = ATIPDOC;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = ATIPDOC;

  DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = ATIPDOC);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = ATIPDOC;


-- REACTUALIZEZ STOCURILE IMPLICATE IN STERGERE
  UPDATE NIRSTOC NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
  WHERE
    NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);

  UPDATE NIRSER NS
  SET
    REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM2)
  WHERE
  NS.CODNIRSTOC IN (SELECT CODUNIC FROM TMP_MANEVRA);


   --  am sters TRANSFR care stinge comenzi; reactualizez restul pe Comenzi
    UPDATE COMANDA1 c1
    SET
     c1.RESTACCEPTAT = c1.CANTACCEPTAT -
                 ( SELECT NVL(SUM(IL.CANT), 0)
                   FROM
                    TRANSFLINK IL
                    LEFT OUTER JOIN TRANSF1 II1 ON II1.CODTRANSF1 = IL.CODTRANSF1
                    LEFT OUTER JOIN TRANSF  II  ON II.CODTRANSF   = II1.CODTRANSF
                   WHERE
                   IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
                   )
    WHERE
    c1.CODCOMANDA1 IN (SELECT CODCOMANDA1 FROM TMP_COMANDA1);




    FOR V_REC IN (SELECT I.TIPDOC, I1.TVA, I1.CODINTR1, NVL(I.CURS, 0) AS CURS,  I1.CANT, I1.PU FROM INTRARI1 I1, INTRARI I WHERE EXISTS (SELECT CODINTR1 FROM TMP_IMBMIFIXLINK WHERE CODINTR1 = I1.CODINTR1) AND I.CODINTR = I1.CODINTR)
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

      UPDATE INTRARI1 I1
      SET
        RESTIMBMF = (
                     CASE
                       WHEN V_REC.TIPDOC = 3 THEN V_REC.CANT * V_REC.PU * aCURS - NVL(V_REC.TVA, 0)
                       ELSE V_REC.CANT * V_REC.PU * aCURS
                     END
                    )
                 -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODINTR1 = I1.CodINTR1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODINTR1 = V_REC.CODINTR1;
    END LOOP;

    FOR V_REC IN (SELECT I1.CODIES1, NVL(I.CURS, 0) AS CURS,  I1.CANT, I1.PU
                  FROM
                    IESIRI1 I1,
                    IESIRI I
                  WHERE
                    EXISTS (SELECT CODIES1 FROM TMP_IMBMIFIXLINK WHERE CODIES1 = I1.CODIES1)
                    AND I.CODIES = I1.CODIES)
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

       PRET_IMB_MF := 0; VAL_ACHIZ_MF := 0; CANT_IMB_MF := 0;
       BEGIN
        SELECT SUM(L1.CANT) AS CANTDIMIN,
               SUM(L1.CANT * (NS.PRET - COALESCE(NS.ADAOS, 0))) AS VALDIMIN
        INTO
          CANT_IMB_MF,
          VAL_ACHIZ_MF
        FROM
          LIVR1 L1,
          LIVR L,
          NIRSTOC NS
        WHERE
          L1.CODIES1 = V_REC.CODIES1
          AND L1.CODLIVR = L.CODLIVR
          AND L.TIPLIVR = 14
          AND NS.CODNIRSTOC = L1.CODNIRSTOC
        GROUP BY L1.CODIES1;

         EXCEPTION WHEN OTHERS THEN NULL;

       END;

       IF NVL(CANT_IMB_MF, 0) &lt;&gt; 0 THEN
         PRET_IMB_MF := VAL_ACHIZ_MF / CANT_IMB_MF;
       END IF;


      UPDATE IESIRI1 I1
      SET
        RESTIMBMF = /*V_REC.CANT * V_REC.PU*/PRET_IMB_MF * V_REC.CANT * aCURS -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODIES1 = I1.CodIES1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODIES1 = V_REC.CODIES1;
    END LOOP;



    FOR V_REC IN (SELECT N1.CODNC1, NVL(N.CURS, 0) AS CURS,  N1.VALOARE
                  FROM
                    NC1 N1, NC N
                  WHERE
                    EXISTS (SELECT CODNC1 FROM TMP_IMBMIFIXLINK WHERE CODNC1 = N1.CODNC1)
                    AND N.CODNC = N1.CODNC)
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

      UPDATE NC1 N1
      SET
        RESTIMBMF = V_REC.VALOARE * aCURS -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODNC1 = N1.CodNC1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODNC1 = V_REC.CODNC1;
    END LOOP;

    FOR V_REC IN (
      SELECT M.CODMIFIX, M1.PRET AS VALOARE
      FROM MIFIX M, MIFIX1 M1
      WHERE EXISTS (SELECT CODMIFIX FROM TMP_IMBMIFIXLINK WHERE CODMIFIX = M.CODMIFIX)
        AND M1.CODMIFIX = M.CODMIFIX
        AND M1.ANSTART * 12 + M1.LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
        AND M1.ANSTART * 12 + M1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 M2 WHERE M2.CODMIFIX = M.CODMIFIX AND M2.ANSTART * 12 + M2.LUNASTART &lt;=  PKG_GLOBALS.AnLunaLucru )
    ) LOOP
      UPDATE MIFIX N1
      SET
        RESTIMBMF = V_REC.VALOARE  -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODMIFIX = N1.CODMIFIX AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
        CODMIFIX = V_REC.CODMIFIX;
    END LOOP;

  IF ATIPDOC = 13 THEN
    CHECK_REZERVARI_MODIPRET_IN;
  END IF  ;


  IF ATIPDOC = 12 THEN
    CHECK_REZERVARI_TRANSF_IN;
  END IF  ;

  FOR V_REC IN
  (SELECT
     IL.CODLINIECOMANDA,
     NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
     NVL(L1.CODNIRSER,0)  AS CODNIRSER,
     L1.CANTREZERVAT
   FROM
     TMP_LIVR1_INITIAL L1,
     TMP_TRANSFLINK_INITIAL IL
   WHERE
    L1.CODIES1 = IL.CODTRANSF1
   )
  LOOP
     UPDATE REZERVATS
     SET
  --   CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT,
       REST         = REST         + V_REC.CANTREZERVAT
     WHERE
      CODCOMANDA1           = V_REC.CODLINIECOMANDA
      AND CODNIRSTOC        = V_REC.CODNIRSTOC
      AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
  END LOOP;

  DELETE FROM DocAsoc WHERE (CODDOC = RECID AND TIPDOC = aTipDoc)or(CODDOCASOC = RECID AND TIPDOCASOC = aTipDoc);

  NotifyModif(2, RECID, &apos;TRANSF&apos;);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
	ATIPDOC NUMBER(20) := 0;
	TIPPREFIX NUMBER(10) := 0;
	acount number;
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

-- MASTER TRANSF
  INSERT INTO TMP_TRANSF
  ( CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, SUBUNITATEA,
    NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, MIJLTRANSP, NRTRANSP, CODGESTCMD, LISTAT, REEVALUARE, SERIADOC, UserID,
    CodAnaliza, SubunitDest, AJUSTVALSTOC, STADIUWMS, CODAUTO,
     TipET,  UIT, ET_IDINCARCARE, ET_IDDESCARCARE, ET_TIPMEDIU, ET_STATUS, is_ETransp, Corectie
   )
   (SELECT
       CODTRANSF, tr.TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, SUBUNITATEA,
       NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
       OBS, tr.AN, tr.LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, MIJLTRANSP, NRTRANSP, CODGESTCMD, LISTAT, REEVALUARE, SERIADOC, UserID,
       CodAnaliza, SubunitDest, AJUSTVALSTOC, STADIUWMS, CODAUTO,
       TipET, ET.UIT, ET.IDINCARCARE, ET.IDDESCARCARE, ET.TIPMEDIU, Coalesce(ET.STARE,&apos;?&apos;), is_ETransp, Corectie
     FROM
       TRANSF tr
       LEFT OUTER JOIN StatusDecl ET ON ET.CodDoc = tr.CODTRANSF and ET.TipDoc = 100+tr.TipDoc
     WHERE
       CODTRANSF = RECID
   );

  INSERT INTO  TMP_TRANSF1
    (CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, CODCONT, UMSEC, CODOBIECT, PU, CANT,
     TVA, DENUM, VALOARE, PARITATE, PROCTVA,
     CODTVA,   CODACCIZE, CODTAXA1, CODTAXA2, PUMAXIMAL,
     DENOBIECT,
     CODMIFIX,
     PUVAl,
     CodReteta,
     CODCENTRU,
     CODCOMANDA1,
     CodAnalizaNod,
     CODEXTERN,
     CODINTERN,
     UM1,
     RELATIEUM1,
     D1,
     D2,
     D3,
     CantUM1,
     CantUM2,
     CmdInt,
     PRELUAT,
     COEFUM_CANTAR,
     COSTTRANSPORT,
     CODAUTO,
     CODEMULARE1,
     OBS,
     TIPDOCIMP,
     CODLINIEDOCIMP
    )
    SELECT * FROM
     (SELECT
        T1.CODTRANSF1, T1.CODTRANSF, T1.INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, T1.CODCONT, T1.UMSEC,
        T1.CODOBIECT, T1.PU * U1.PARITATE, T1.CANT/ U1.PARITATE, T1.TVA,
        U1.DEN_UM1, T1.CANT * T1.PU, U1.PARITATE,
        PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
        NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE,
        NART1LUNA.CODTAXA1,
        NART1LUNA.CODTAXA2, T1.PUMAXIMAL * U1.PARITATE,
        O.DENUMIRE,
        T1.CODMIFIX,
        T1.PUVAl,
        t1.CodReteta, T1.CODCENTRU, T1.CODCOMANDA1, T1.Codanalizanod,
        O.CODEXTERN,
        O.CODINTERN,
        A.UM1,
        A.RELATIEUM1,
        T1.D1,
        T1.D2,
        T1.D3,
        T1.CantUM1,
        T1.CantUM2,
        C.NrDoc,
        T1.PRELUAT,
        CASE
          WHEN Nvl(u.tipum,0) = 1 THEN u.coef
          ELSE 0
        END,
        T1.COSTTRANSPORT,
        T1.CODAUTO,
        T1.CODEMULARE1,
        T1.OBS,
        T1.TIPDOCIMP,
        T1.CODLINIEDOCIMP
      FROM
        TRANSF1 T1
        LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = T1.CODCOMANDA1
        LEFT JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = T1.CODOBIECT
        LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
        LEFT JOIN NUM U ON A.UM = U.CODUM
        LEFT JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL and pkg_globals.anlunalucru BETWEEN NART1LUNA.alstart AND NART1LUNA.alstop
        LEFT JOIN NUM1 U1   ON U1.CODUM1 = T1.UMSEC
      WHERE
        T1.CODTRANSF = RECID
     ) ORDER BY INDEXLOCAL;

  DELETE TMP_TRANSF1_INITIAL;
  INSERT INTO TMP_TRANSF1_INITIAL (CODTRANSF1,CODCOMANDA1) SELECT CODTRANSF1,CODCOMANDA1 FROM TMP_TRANSF1;

 -- Detail TRANSFLINK
  INSERT INTO TMP_TRANSFLINK
  (CODTRANSF1, CODLINIECOMANDA, CANT)
  (SELECT CODTRANSF1, CODLINIECOMANDA, CANT
  FROM
  TRANSFLINK L
  WHERE
  L.CODTRANSF1 IN (SELECT CODTRANSF1 FROM TMP_TRANSF1)
 );


 -- Detail IMBMIFIXLINK
  INSERT INTO TMP_IMBMIFIXLINK
  (CODIMBMIFIXLINK, CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX, CANT)
  (SELECT CODIMBMIFIXLINK, CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX, CANT
  FROM
  IMBMIFIXLINK L
  WHERE
   EXISTS (SELECT CODTRANSF1 FROM TMP_TRANSF1 WHERE CODTRANSF1 = L.CODTRANSF1)
 );

  INSERT INTO TMP_IMBMIFIXLINK_INITIAL
  SELECT * FROM TMP_IMBMIFIXLINK;


 UPDATE TMP_TRANSF1 I1
 SET
   NRDOCLINK =
   CASE
     WHEN I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) THEN ( SELECT CC.PREFIXDOC || TO_CHAR(CC.NRDOC)
                                           FROM
                                            TRANSFLINK IL
                                            LEFT OUTER JOIN COMANDA1 CC1 ON CC1.CodComanda1 = IL.CODLINIECOMANDA
                                            LEFT OUTER JOIN COMANDA  CC  ON CC.CodComanda   = CC1.CODCOMANDA
                                            WHERE IL.CODTRANSF1 = I1.CODTRANSF1
                                          )
   END
   WHERE I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;);



 INSERT INTO TMP_TRANSFLINK_INITIAL SELECT * FROM TMP_TRANSFLINK;
 UPDATE TMP_TRANSFLINK L
 SET
   DATACOMANDA =
   (SELECT  C.DATADOC
    FROM
    COMANDA1 C1, COMANDA C WHERE C1.CODCOMANDA1 = L.CODLINIECOMANDA AND C.CODCOMANDA= C1.CODCOMANDA)
   ;



-- DETAIL LIVR
  INSERT INTO TMP_LIVR
    ( CODLIVR,  CODIES, CODINTR, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    ( SELECT
      CODLIVR,  CODIES, CODINTR, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
      FROM LIVR WHERE CODTRANSF = RECID) ;


-- DETAIL LIVR1
  INSERT INTO TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODIES1,
       CODNIRSTOC,
       CANT,
       CANTUM1,
       CANTUM2,
       CODNIRSER,
       PMP, PMPDOC, PMPVALUTA, PMPVALUTADOC,
       UMSEC,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE,
       TG,
       PUMAXIMAL,
       FURN,
       DATAACHIZ,
       TIPDOCACHIZ,
       CODGESTPROD,
       SUBUNITATEA,
       CANTREZERVAT,
       D1,
       D2,
       D3,
       CODCERTIF,
       CODLOCATIE,
       PUAVAL,
       PROVIZION,
       CONTINTERMED,
       CODPROIECT,
       SERIELOT,
       CODLIVR1PARINTE,
       CODPRODCOMP,
       EUDR_RN,
       EUDR_VN
        )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODIES1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CANTUM1,
         L1.CANTUM2,
         L1.CODNIRSER,
         L1.PMP, L1.PMPDOC, L1.PMPVALUTA, L1.PMPVALUTADOC,
         L1.UMSEC,
         U1.DEN_UM1,
         U1.PARITATE,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,
        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
         NS.TG,
         NS.PUMAXIMAL,
         NS.FURN,
         NS.DATAACHIZ,
         NS.TIPDOCACHIZ,
         NS.CODGESTPROD,
         NS.SUBUNITATEA,
         L1.CANTREZERVAT / U1.PARITATE,
         NS.D1,
         NS.D2,
         NS.D3,
         L1.CODCERTIF,
         NS.CODLOCATIE,
         NS.PUVAL,
         NS.PROVIZION,
         L1.CONTINTERMED,
         L1.CODPROIECT,
         NS.SERIELOT,
         L1.CODLIVR1PARINTE,
         L1.CODPRODCOMP,
         NS.EUDR_RN,
         NS.EUDR_VN
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         L.CODTRANSF  = RECID AND U1.CODUM1 = L1.UMSEC
     );


-- DETAIL LIVRTOT
  DELETE TMP_LIVRTOT;

  INSERT INTO TMP_LIVRTOT
   (CODLIVRTOT,
    CODLIVR,
    CODIESINT1,
    UMSEC,
    GEST,
    CODIOART,
    CONTINTERMED,CODPROIECT,
    CODOBIECT,
    DENUM,
    PARITATE,
    DENGESTIOART,
    DIFPRET,
    ACCIZELATRANSFER,
    ARETVANEEX,
    MG,
    CONT,
    SUFIXTVANEEX,
    STOCREZOLVAT,
    CANT,
    PRETINREG,
    PRETACHIZ,
    PMP,
    PMPDOC,
    PMPVALUTA,
    PMPVALUTADOC,
    CODPRODCOMP
    )
  SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODIES1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),NVL(L1.CODPROIECT,0),
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ACCIZELATRANSFER,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         1,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG    * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PRETACHIZ    * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMP          * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPDOC       * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTA    * L1.CANT) / SUM(L1.CANT),
         SUM(L1.PMPVALUTADOC * L1.CANT) / SUM(L1.CANT),
         L1.CODPRODCOMP
       FROM
         TMP_LIVR1 L1
         LEFT JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART and pkg_globals.anlunalucru BETWEEN IOALUNA.alstart AND IOALUNA.alstop
         LEFT JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
         LEFT JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT JOIN IOART IO ON IO.CODIOART = L1.CODIOART
       WHERE
         L.CODTRANSF = RECID
         AND L1.CANT &lt;&gt; 0
       GROUP BY
         0,
         L1.CODLIVR,
         L1.CODIES1,
         L1.CODOBIECT,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),
         NVL(L1.CODPROIECT,0),
         L1.DENUM,
         L1.PARITATE ,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ACCIZELATRANSFER,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         L1.CODPRODCOMP
     )
  ORDER BY CODLIVR, CODIES1;


   UPDATE TMP_LIVRTOT T SET
   CODLIVRTOT             = ROWNUM,
   (DENOBIECT,
    CODEXTERN,
    CODINTERN
   )               = (SELECT DENUMIRE, CODEXTERN, CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = T.CODOBIECT), --PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
   (UM1, UM2, RELATIEUM1, TIPSERIE) = (SELECT UM1, UM2, RELATIEUM1, TIPSERIE FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   INDEXMASTER            = (SELECT INDEXLOCAL FROM TMP_TRANSF1 WHERE CODTRANSF1 = T.CODIESINT1),
-- CODLINIECOMANDA        = (SELECT CODCOMANDA1 FROM TMP_TRANSF1 WHERE CODTRANSF1 = T.CODIESINT1),
   GESTIMPLICITA          = (SELECT GESTIMPLICITA FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   PROCTVA                = PKG_SELECTARTICOLE.GETPROCENTTVA
                          (PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT), PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);


-- DETAIL TMP_LIVRVAL;
   INSERT INTO TMP_LIVRVAL SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);

-- PARITATEA PRETURILOR DIN LIVRVAL ESTE CEA DIN TMP_LIVR1
   UPDATE TMP_LIVRVAL LV
   SET
     PRETINREG = PRETINREG * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1),
     PRETACHIZ = PRETACHIZ * NVL((SELECT L1.PARITATE FROM TMP_LIVR1 L1 WHERE L1.CODLIVR1 = LV.CODLIVR1), 1);


-- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
    UPDATE TMP_LIVR1 L1
    SET
    (CODLIVRTOT, GESTIMPLICITA, DIFPRET, ARETVANEEX) =
    ( SELECT CODLIVRTOT, GESTIMPLICITA, DIFPRET, ARETVANEEX
     FROM TMP_LIVRTOT
      WHERE
        CODLIVR          = L1.CODLIVR  AND
        CODIESINT1       = L1.CODIES1  AND
        UMSEC            = L1.UMSEC    AND
        PARITATE         = L1.PARITATE AND
        NVL(GEST, 0)     = NVL(L1.GEST, 0)  AND
        NVL(CODIOART, 0) = NVL(L1.CODIOART, 0)
     );


-- DETAIL NIR
  INSERT INTO  TMP_NIR
    ( CODNIR,
      CODINTR,
      CODTRANSF,
      CARNETNIR,
      NRNIR,
      DATANIR,
      GEST,
      OBS,
      TIPNIR,
      ANULAT,
      BLOCAT,
      OPERAT,
      USERID,
      VALOARE,
      CODIOARTIMPLICIT )
    ( SELECT
        N.CODNIR,
        N.CODINTR,
        N.CODTRANSF,
        N.CARNETNIR,
        N.NRNIR,
        N.DATANIR,
        N.GEST,
        N.OBS,
        N.TIPNIR,
        N.ANULAT,
        N.BLOCAT,
        N.OPERAT,
        N.USERID,
       (SELECT SUM(NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR),
        G.CODCONT
      FROM
       NIR N
       LEFT OUTER JOIN NGEST G ON G.CODGEST = N.GEST
     WHERE N.CODTRANSF = RECID
    )
   ORDER BY NRNIR;


-- DETAIL NIRSTOC
  INSERT INTO  TMP_NIRSTOC
    ( CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, FURN, CANTNIR, UMSEC,
      CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE,  PUMAXIMAL, ADAOS, TVA, TIPSERIE,
      CODLIVR1, REST, PROCENTADAOS, Supliment, TG, DATAACHIZ, DENUM, PARITATE, VALOARE, CANTFURN,
      MG, DIFPRET, ACCIZELATRANSFER, ARETVANEEX, PUSTANDARD, PRETACHIZ, PROCTVA,
      DISCLIKISTOC, DENOBIECT, CANTUM1, CANTUM2, UM1, UM2, RelatieUM1, D1,D2,D3, CODGESTPROD, TIPDOCACHIZ,PUVAL, PROVIZION, SERIELOT,
      CODEXTERN, CODINTERN, EUDR_RN, EUDR_VN)
    SELECT * FROM
    ( SELECT
        NS.CODNIRSTOC, NS.CODNIR,  NS.CODINTR1, NS.CODTRANSF1, NS.CODNIRSTOCPARINTE, NS.FURN, NS.CANTNIR / U1.PARITATE, NS.UMSEC,
        NS.CODOBIECT, NS.CODIOART, NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA, NS.CODLOCATIE, NS.PUMAXIMAL, NS.ADAOS * U1.PARITATE, NS.TVA, NS.TIPSERIE,
        NS.CODLIVR1, NS.REST, NS.PROCENTADAOS, NS.Supliment, NS.TG, NS.DATAACHIZ, U1.DEN_UM1, U1.PARITATE, NS.CANTNIR * NS.PRET, NS.CANTFURN / U1.PARITATE,
--      (NS.CANTNIR + NVL((SELECT SUM(DIFERENTA) FROM NIR1 WHERE CODNIRSTOC = NS.CODNIRSTOC), 0)) / U1.PARITATE,
        IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.PUSTANDARD,
        (NS.PRET - NS.ADAOS -
        CASE
          WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
          ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR / U1.PARITATE)
        END) * u1.Paritate,

        PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),
        DISCLIKISTOC,
        O.DENUMIRE,
        NS.CANTUM1,
        NS.CANTUM2,
        A.UM1,
        A.UM2,
        A.RelatieUM1,
        NS.D1,
        NS.D2,
        NS.D3,
        NS.CODGESTPROD,
        NS.TIPDOCACHIZ,
        NS.PUVAL,
        NS.PROVIZION,
        NS.SERIELOT,
        O.CODEXTERN,
        O.CODINTERN,
        NS.EUDR_RN, 
        NS.EUDR_VN
      FROM NIRSTOC NS
        LEFT JOIN ioart1 IOALUNA ON IOALUNA.CODIOART = NS.CODIOART and pkg_globals.anlunalucru BETWEEN IOALUNA.alstart AND IOALUNA.alstop
        LEFT JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
        LEFT JOIN NART A    ON A.CODARTICOL = O.CODARTICOL,
        NUM1 U1
      WHERE  NS.CODNIR IN (SELECT CODNIR FROM TMP_NIR) AND U1.CODUM1 = NS.UMSEC
      )
     ORDER BY CODNIR, CODINTR1;

   INSERT INTO TMP_NIRSTOC1
   SELECT NS1.*
   FROM NIRSTOC1 NS1 WHERE EXISTS (SELECT TMP.CODNIRSTOC FROM TMP_NIRSTOC TMP WHERE TMP.CODNIRSTOC = NS1.CODNIRSTOC);

-- PENTRU DISTRIBUIRE VALORI SUPLIMENTARE PREIAU MASA SI VOLUM
   UPDATE TMP_NIRSTOC NS
   SET
    (MASA, VOLUM) =  (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = NS.CODOBIECT),
    PRETINITIAL     = PRET,
    ADAOSINITIAL    = ADAOS,
    CONT            = (SELECT CONT FROM TMP_IOART_LUNA IO WHERE IO.CODIOART = NS.CODIOART),
    MGPARINTE       = (SELECT NVL(MG, 0) FROM NIRSTOC NSP WHERE NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE),
    CODIOARTINITIAL = CODIOART,
    TIPPRETMAX      =(SELECT NVL(TIPPRETMAX, 0) FROM TMP_NARTOBJ_LUNA O1 WHERE O1.CODOBIECT = NS.CODOBIECT),
    DENFURN     = (CASE
                     WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
                     ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
                   END
                   );




-- DETAIL NIRSER
   INSERT INTO TMP_NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, SERIE, CANTUM1, CANTUM2, OBS, CODCERTIF, DATAPROD, TG, STARE, DATAPROD1, TG1, CODPRODUCATOR)
   (SELECT CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, (SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), CANTUM1, CANTUM2, OBS, CODCERTIF, DATAPROD, TG, STARE, DATAPROD1, TG1, CODPRODUCATOR
   FROM NIRSER NS WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC));

   IF RECID &gt; 0 THEN
    SELECT TIPDOC INTO ATIPDOC FROM TMP_TRANSF;
   END IF;

   PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(ATIPDOC);

   DELETE TMP_JURNAL;
   DELETE TMP_JURNAL1;

   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = ATIPDOC AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = ATIPDOC AND CODDOC = RECID);

   DELETE TMP_RULAJ;

   UPDATE TMP_LIVR1 L1
   SET
    PROCTVA = (SELECT PROCTVA FROM TMP_LIVRTOT WHERE CODLIVRTOT = L1.CODLIVRTOT),
    PROCENTADAOS = (SELECT PROCENTADAOS FROM NIRSTOC NS WHERE NS.CODNIRSTOC = L1.CODNIRSTOC),
    (DATAPROD, STARE, OBS) = (SELECT DATAPROD, STARE, OBS FROM NIRSER NSE WHERE NSE.CODNIRSER = L1.CODNIRSER);



   UPDATE TMP_NIRSTOC NS
   SET
    INDEXMASTER = (SELECT INDEXLOCAL FROM TMP_TRANSF1 WHERE CODTRANSF1 = NS.CODTRANSF1);


   UPDATE TMP_NIRSER NSE
   SET
     PARITATE = NVL((SELECT PARITATE FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC),1),
     CANTNIR  = CANTNIR / NVL((SELECT PARITATE FROM TMP_NIRSTOC WHERE CODNIRSTOC = NSE.CODNIRSTOC),1);



  DELETE TMP_NIRSTOCINI;
  DELETE TMP_NIRSERINI;
  INSERT INTO TMP_NIRSTOCINI (CODNIRSTOC, CODLIVR1) SELECT CODNIRSTOC, CODLIVR1 FROM TMP_NIRSTOC;
  INSERT INTO TMP_NIRSERINI  SELECT * FROM TMP_NIRSER;


   UPDATE TMP_TRANSF1 I1
   SET
     INFOMF         = CASE WHEN aTIPDOC = 13 THEN
                        SUBSTR(
                        (SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE FROM
                          MIFIX MF,
                          MIFIX1 MF1,
                          NIRSTOC NS,
                          NARTOBJ O
                         WHERE
                           MF.CODMIFIX = I1.CODMIFIX
                           AND MF.CODMIFIX = MF1.CODMIFIX
                           AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                           AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                           AND O.CODOBIECT = NS.CODOBIECT),
                           1,
                           50)
                       ELSE
                          TO_CHAR(
                          (SELECT MF.NRINVENTAR  FROM
                            MIFIX MF
                           WHERE
                             MF.CODMIFIX = I1.CODMIFIX)
                         )
                        END
   WHERE
     NVL(CODMIFIX, 0) &lt;&gt; 0;

/*
   UPDATE TMP_LIVRTOT T
   SET
     CODLINIECOMANDA = (SELECT NVL(IL.CODLINIECOMANDA, I1.CODCOMANDA1) FROM TMP_TRANSFLINK IL, TMP_TRANSF1 I1 WHERE I1.CODTRANSF1 = T.CODIESINT1 AND IL.CODTRANSF1 = I1.CODTRANSF1);
*/

  FOR V_REC IN -- legatura cu comenzi de la gestiuni
  (SELECT
    T.CODLIVRTOT,
    IL.CODLINIECOMANDA
   FROM
     TMP_LIVRTOT T,
     TMP_TRANSFLINK IL
   WHERE
     T.CODIESINT1 = IL.CODTRANSF1
  )
  LOOP
    UPDATE TMP_LIVRTOT
    SET
     CODLINIECOMANDA = V_REC.CODLINIECOMANDA
    WHERE
     CODLIVRTOT = V_REC.CODLIVRTOT;
  END LOOP;

  FOR V_REC IN -- legatura cu comenzi clienti de pe care am generat transferuri
  (SELECT
    T.CODLIVRTOT,
    T1.CODCOMANDA1
   FROM
     TMP_LIVRTOT T,
     TMP_TRANSF1 T1
   WHERE
     T.CODIESINT1 = T1.CODTRANSF1 and NVL(T1.CODCOMANDA1,0) &gt; 0
  )
  LOOP
    UPDATE TMP_LIVRTOT
    SET
     CODLINIECOMANDA = V_REC.CODCOMANDA1
    WHERE
     CODLIVRTOT = V_REC.CODLIVRTOT;
  END LOOP;



   UPDATE TMP_LIVR1 L1
   SET
     CODLINIECOMANDA = (SELECT CODLINIECOMANDA FROM TMP_LIVRTOT WHERE CODLIVRTOT = L1.CODLIVRTOT AND ROWNUM &lt;=1);

-- MEMOREZ STAREA LA INTRARE A LIVRARILOR
   DELETE TMP_LIVR1_INITIAL;
   INSERT INTO TMP_LIVR1_INITIAL (SELECT * FROM TMP_LIVR1);


  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
  END;

   IF TIPPREFIX = &apos;2&apos; THEN
     UPDATE TMP_TRANSF1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
   ELSE
   IF TIPPREFIX = &apos;3&apos; THEN
     UPDATE TMP_TRANSF1 I1
     SET
       DENOBIECT = SUBSTR(NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = I1.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DENOBIECT, 1, 200)
     WHERE
       I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;);
   END IF;
   END IF;


   IF TIPPREFIX &lt;&gt; &apos;1&apos; THEN
     UPDATE TMP_LIVRTOT L1
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_TRANSF1 I1 WHERE I1.CODTRANSF1 = L1.CODIESINT1);


     UPDATE TMP_NIRSTOC NS
     SET
     DENOBIECT = (SELECT DENOBIECT FROM TMP_TRANSF1 I1 WHERE I1.CODTRANSF1 = NS.CODTRANSF1);


   END IF;

   select count(*) into acount from tmp_livr1;
   if acount = 0 then
     for v_rec in (select t1.codtransf1, art.d1, art.d2, art.d3, art.relatieum1
                   from tmp_transf1 t1
                        inner join nartobj obj on t1.codobiect = obj.codobiect
                        inner join nart art on art.codarticol = obj.codarticol
                   where art.relatieum1 &gt; 0) loop
       update tmp_transf1
       set
         d1 = v_rec.d1,
         d2 = v_rec.d2,
         d3 = v_rec.d3,
         relatieum1 = v_rec.relatieum1
       where codtransf1 = v_rec.codtransf1;
     end loop;
     update tmp_transf1
     set
       cantum1 = CASE
                   WHEN RELATIEUM1 IN (1, 7) AND NVL(D1, 0) &lt;&gt; 0 THEN CANT / D1
                   WHEN RELATIEUM1 IN (2, 8) AND NVL(D1, 0) * NVL(D2, 0) &lt;&gt; 0 THEN CANT / (NVL(D1, 0) * NVL(D2, 0))
                   WHEN RELATIEUM1 IN (3, 9) AND NVL(D1, 0) * NVL(D2, 0) * NVL(D3, 0) &lt;&gt; 0 THEN CANT / (NVL(D1, 0) * NVL(D2, 0) * NVL(D3, 0))
                   WHEN RELATIEUM1 IN (4, 10) THEN CANT * NVL(D1, 0)
                   WHEN RELATIEUM1 IN (5, 11) THEN CANT * NVL(D1, 0) * NVL(D2, 0)
                   WHEN RELATIEUM1 IN (6, 12) THEN CANT * NVL(D1, 0) * NVL(D2, 0) * NVL(D3, 0)
                 END;
   /*else
     UPDATE TMP_TRANSF1 T1
     SET
       CANTUM1 = (SELECT SUM(NVL(CANTUM1, 0)) FROM TMP_LIVR1 L1 WHERE L1.CODIES1 = T1.CODTRANSF1);*/
   end if;
  PKG_CFGTABLES.EXT_GOTORECORD(aTipDoc);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
  VCOD NUMBER(20);
  OLDCARNETNIR NUMBER(20) := 0;
  OLDNRNIR     NUMBER(20) := 0;

  OLDCARNETLIVR NUMBER(20) := 0;
  OLDNRLIVR     NUMBER(20) := 0;

  ACARNET       NUMBER(20) := 0;
  ANUMARDOC     NUMBER(20) := 0;
  ATIPDOC       NUMBER(20) := 0;
  AANULAT       NUMBER(20) := 0;
  AOPERAT       NUMBER(20) := 0;
  NR            NUMBER(10) := 0;
  aCODSERIE     NUMBER(20) := 0;
  NOMSERIE      VARCHAR2(75);
  aCURS         NUMBER(20, 7) := 1;
  PRET_IMB_MF    NUMBER(20, 7);
  VAL_ACHIZ_MF  NUMBER(20, 7);
  CANT_IMB_MF   NUMBER(20, 7);

  aCodSubunit NUMBER(20);
  aDataDoc DATE;
  aDoc varchar2(200);

  aCodComanda1 number(20);
  aRoot        number(20);
  aDirty       number(1);
  aTipNIR      number(10);
  aPretMat     number(20,7);
  LivrDinRezTransf number(1);

  aTipNS1  number;
  aCodRezervats number(20);
  aDifCant number(20,7);
  aCantRez number(20,7);
  aCodNirStocOrig number(20);
  aCantNir number(20,7);
  aProd number(1);
  aCount number;
  aCont number(20);
  aContIni number(20);
  aCodMifix number(20);
  aprefixdoc varchar2(100);
  aGestIni number(20);
  aGest number(20);
  aCountBCAR number(20);
  aDelegat number(20);
  aGestBCAR number(20);
BEGIN
--BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  SELECT PKG_CATEGCONST.GetValConstanta(&apos;LivrDinRezTransf&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO LivrDinRezTransf FROM DUAL;
  SELECT CARNETDOC, NRDOC,     TIPDOC , ANULAT,  OPERAT, SUBUNITATEA, DATADOC, PREFIXDOC||NRDOC||&apos;/&apos;DATADOC, prefixdoc, Delegat, CodGestCmd
  INTO   ACARNET,   ANUMARDOC, ATIPDOC, aANULAT, AOPERAT, aCodSubunit, aDataDoc,ADOC, aprefixdoc, aDelegat, aGestBCAR
  FROM TMP_TRANSF;

  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (ATIPDOC);

  -- pentru Raportare Stoc Medicamente - sa vad data sistemului a intrarii in stoc pentru cazuri cu NIR initial neoperat
  UPDATE TMP_NIR TN
  SET DATACREARE = SYSTIMESTAMP
  WHERE OPERAT = 1 AND DATACREARE IS NULL
    AND NOT EXISTS(SELECT 1 FROM NIR N WHERE N.CODNIR = TN.CODNIR AND N.OPERAT = 1);

  -- REZOLVARE CIOBANEASCA BUG ; - REPUN IN NIRSTOC VALORI MOSTENITE DE PE NIRSTOCPARINTE
  UPDATE TMP_NIRSTOC NS
  SET (DATAACHIZ, TG, TIPDOCACHIZ, EUDR_RN, EUDR_VN) = (SELECT DATAACHIZ, TG, TIPDOCACHIZ, EUDR_RN, EUDR_VN FROM NIRSTOC NSP WHERE NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE)
  WHERE CODNIRSTOCPARINTE IS NOT NULL;

-- sunt transferuri care se fac cu scopul de a modifica TG-ul pe serie; trebuie sa sincronizez tG-ul din nirstoc si nirser
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC WHERE NVL(TIPSERIE, 0) &gt; 0 AND TG IS NOT NULL)
  LOOP
    UPDATE TMP_NIRSTOC NS
    SET TG = (SELECT TG FROM TMP_NIRSER NSE WHERE NSE.CODNIRSTOC = V_REC.CODNIRSTOC AND ROWNUM = 1)
    WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  aCountBCAR := 0;
  IF OPERATION = 0 THEN  -- UPDATE
    SELECT CODTRANSF INTO RECID FROM TMP_TRANSF;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

      WINMADMIN.PKG_USERFIRME.PostLog(&apos;TRANSF&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;,
                                       RECID,PKG_GLOBALS.FIRMANAME,
                                       aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    if aTipDoc = 12 then
      select count(1) into aCountBCAR
      from tmp_transf1 t1
           inner join bcar b on t1.codtransf1 = b.coddoc1 and b.tipdoc = atipdoc
      where (aDelegat &lt;&gt; b.coddelegat or aGestBCAR &lt;&gt; b.codpartener) and t1.codtransf1 &gt; 0;
    end if;

    -- MASTER TRANSF
    UPDATE TRANSF
    SET
      (CODTRANSF, TIPDOC,  ANULAT,  BLOCAT,   OPERAT, PREFIXDOC, CARNETDOC,
       NRDOC,  DATADOC, CARNETAE, NRAE,  VALDOC,    TVADOC,
       OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO,
       TIPMODIFPRET, MIJLTRANSP, NRTRANSP, CODGESTCMD, SUBUNITDEST, LISTAT, REEVALUARE, SERIADOC,
       IDIMPORT, AJUSTVALSTOC,STADIUWMS, CodAnaliza, CODAUTO, TipET, is_ETransp, Corectie ) =
      (SELECT RECID, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
              NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS, AN, LUNA,
              VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, MIJLTRANSP, NRTRANSP, CODGESTCMD, SUBUNITDEST, LISTAT, REEVALUARE, SERIADOC, IDIMPORT, AJUSTVALSTOC,STADIUWMS,
              CodAnaliza, CODAUTO, TipET, is_ETransp, Corectie
       FROM TMP_TRANSF
      )
    WHERE CODTRANSF = RECID;


    -- Detail IMBTRANSFLINK
    DELETE FROM IMBMIFIXLINK IL
    WHERE EXISTS (SELECT CODIMBMIFIXLINK FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODIMBMIFIXLINK = IL.CODIMBMIFIXLINK)
      AND NOT EXISTS (SELECT CODIMBMIFIXLINK FROM TMP_IMBMIFIXLINK WHERE CODIMBMIFIXLINK = IL.CODIMBMIFIXLINK);

    -- Detail TRANSFLINK
    DELETE FROM TRANSFLINK
    WHERE CODTRANSF1 IN ( SELECT CODTRANSF1 FROM TRANSF1 WHERE CodTRANSF = RecID AND CODTRANSF1 NOT IN (SELECT CODTRANSF1 FROM TMP_TRANSFLINK));

    -- DETAIL TRANSF1
    FOR V_REC IN (SELECT CODTRANSF1
                  FROM TRANSF1
                  WHERE CODTRANSF = RECID AND CODTRANSF1 NOT IN (SELECT CODTRANSF1 FROM TMP_TRANSF1)
                 ) LOOP
      DELETE TRANSF1 WHERE CODTRANSF1 = V_REC.CODTRANSF1;
      UPDATE BCAR SET TIPDOC = NULL, CODDOC1 = NULL, USERIDBLOCAJ = NULL  WHERE CODDOC1 = V_REC.CODTRANSF1 AND TIPDOC = ATIPDOC;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TRANSF1  ORDER BY INDEXLOCAL) LOOP
      IF NVL(V_REC.CODTRANSF1, 0) &gt; 0  THEN
        UPDATE TRANSF1 SET
          INDEXLOCAL   = V_REC.INDEXLOCAL,
          TIPLINIE     = V_REC.TIPLINIE,
          CODOBIECTORIG= V_REC.CODOBIECTORIG,
          PARITATEORIG = V_REC.PARITATEORIG,
          CODCONT      = V_REC.CODCONT,
          UMSEC        = V_REC.UMSEC,
          CODOBIECT    = V_REC.CODOBIECT,
          PU           = V_REC.PU   / V_REC.PARITATE,
          PUMAXIMAL    = V_REC.PUMAXIMAL   / V_REC.PARITATE,
          CANT         = V_REC.CANT * V_REC.PARITATE,
          TVA          = V_REC.TVA,
          CODMIFIX     = V_REC.CODMIFIX,
          PUVAL        = V_REC.PUVAL,
          CodCentru    = V_REC.CodCentru,
          CODCOMANDA1  = V_REC.CODCOMANDA1,
          CodReteta    = V_REC.CodReteta,
          CODTRANSF1   = V_REC.CODTRANSF1,
          CODANALIZANOD  = V_REC.CODANALIZANOD,
          D1             = V_REC.D1,
          D2             = V_REC.D2,
          D3             = V_REC.D3,
          CantUM1        = v_rec.CantUM1,
          CantUM2        = v_rec.CantUM2,
          PRELUAT        = V_REC.PRELUAT,
          CODAUTO        = V_REC.CODAUTO,
          OBS            = V_REC.OBS,
          TIPDOCIMP      = V_REC.TIPDOCIMP,
          CODLINIEDOCIMP = V_REC.CODLINIEDOCIMP
        WHERE CODTRANSF1 = V_REC.CODTRANSF1;
        PKG_CANTAR.UNLOCK_RECORDS(aTipDoc, v_rec.CODTRANSF1);
        PKG_BCAR.UNLOCK_RECORDS(ATIPDOC, v_rec.CODTRANSF1);
     ELSE
       SELECT SEQ_TRANSF1_CODTRANSF1.NEXTVAL INTO VCOD FROM DUAL;
       PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TRANSF1&apos;, VCOD, V_REC.CODTRANSF1);

       update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.codtransf1;
       INSERT INTO TRANSF1
       (
         CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, CODCONT, UMSEC,
         CODOBIECT,  PU, PUMAXIMAL, CANT, TVA, CODMIFIX, PUVAL, CodReteta, CODCENTRU, CODCOMANDA1,
         CODANALIZANOD, D1, D2, D3, CantUM1, CantUM2, PRELUAT, CODAUTO, CODEMULARE1, OBS, TIPDOCIMP, CODLINIEDOCIMP
        )
       VALUES
       ( VCOD,   RECID, V_REC.INDEXLOCAL , V_REC.TIPLINIE, V_REC.CODOBIECTORIG, V_REC.PARITATEORIG,  V_REC.CODCONT, V_REC.UMSEC,
         V_REC.CODOBIECT, V_REC.PU / V_REC.PARITATE,  V_REC.PUMAXIMAL / V_REC.PARITATE,
         V_REC.CANT * V_REC.PARITATE, V_REC.TVA, V_REC.CODMIFIX, V_REC.PUVAL, v_rec.CodReteta, V_REC.CODCENTRU, V_REC.CODCOMANDA1,
         v_rec.codanalizanod, V_REC.D1,  V_REC.D2,  V_REC.D3, v_rec.CantUM1, v_rec.CantUM2, V_REC.PRELUAT, V_REC.CODAUTO, V_REC.CODEMULARE1,
         V_REC.OBS, V_REC.TIPDOCIMP, V_REC.CODLINIEDOCIMP
        );

        UPDATE TMP_LIVR1      SET CODIES1    = VCOD WHERE CODIES1    = V_REC.CODTRANSF1;
        UPDATE TMP_NIRSTOC    SET CODTRANSF1 = VCOD WHERE CODTRANSF1 = V_REC.CODTRANSF1;
        UPDATE TMP_TRANSFLINK SET CODTRANSF1 = vCod WHERE CODTRANSF1 = v_rec.CODTRANSF1;

        UPDATE TMP_IMBMIFIXLINK SET CODTRANSF1 = vCod WHERE CODTRANSF1 = v_rec.CODTRANSF1;
        PKG_CANTAR.UPDATE_RECORDS(aTipDoc, v_rec.CODTRANSF1, vCOD);
        PKG_BCAR.UPDATE_RECORDS(ATIPDOC, v_rec.CodTRANSF1, vCOD);
      END IF;
      IF aANULAT = 1 THEN
        UPDATE CANTAR SET TIPDOC = NULL, CODDOC1 = NULL WHERE TIPDOC = aTipDoc AND CODDOC1 = v_rec.CODTRANSF1;
        UPDATE BCAR SET TIPDOC = NULL, CODDOC1 = NULL WHERE TIPDOC = aTipDoc AND CODDOC1 = v_rec.CODTRANSF1;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_TRANSFLINK) LOOP
      SELECT NVL(COUNT(*), 0) INTO NR  FROM TRANSFLINK WHERE CODTRANSF1 = v_rec.CODTRANSF1;
      IF NR = 0  THEN
        INSERT INTO TRANSFLINK (CODTRANSF1, CODLINIECOMANDA, CANT)
        VALUES  (v_rec.CODTRANSF1, v_rec.CODLINIECOMANDA, v_rec.CANT);
      ELSE
        UPDATE TRANSFLINK
        SET
          CODTRANSF1      = v_Rec.CODTRANSF1,
          CODLINIECOMANDA = v_rec.CODLINIECOMANDA,
          CANT            = v_Rec.Cant
        WHERE
         CODTRANSF1 = v_rec.CODTRANSF1;
      END IF;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_IMBMIFIXLINK) LOOP
      IF V_REC.CODIMBMIFIXLINK &lt; 0  THEN
        INSERT INTO IMBMIFIXLINK (CODIMBMIFIXLINK, CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX, CANT)
        VALUES  (SEQ_IMBMIFIXLINK_CODIMBMF.NEXTVAL,  v_rec.CODTRANSF1, v_rec.CODINTR1, V_REC.CODIES1, V_REC.CODNC1,  V_REC.CODMIFIX, v_rec.CANT);
      ELSE
        UPDATE IMBMIFIXLINK
        SET
          CODTRANSF1 = v_Rec.CODTRANSF1,
          CODINTR1   = v_rec.CODINTR1,
          CODIES1    = V_REC.CODIES1,
          CODNC1     = V_REC.CODNC1,
          CODMIFIX   = V_REC.CODMIFIX,
          CANT       = v_Rec.Cant
        WHERE
         CODIMBMIFIXLINK = V_REC.CODIMBMIFIXLINK;
      END IF;
    END LOOP;


-- DETAIL NIR
-- ATENTIE LA ORDINEA STERGERILOR DIN DETALII

    DELETE FROM NIRSER WHERE
    CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID)) AND
    CODNIRSER NOT IN ( SELECT CODNIRSER FROM TMP_NIRSER);

    delete tmp_rezervats;
    for v_rec in (select ns.codnirstoc, ns.codnirstocparinte, t1.codcomanda1, ns.rest
                  from nirstoc ns
                       left join tmp_transf1_initial t1 on t1.codtransf1 = ns.codtransf1
                  where
                  ns.CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID) AND
                  ns.CODNIRSTOC NOT IN ( SELECT CODNIRSTOC FROM TMP_NIRSTOC)) loop

      insert into tmp_rezervats(codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini, codobiect,
                                codcomanda1f, codinventar1)
      select codrezervats, codcomanda1, v_rec.codnirstocparinte, codnirser, rest, umsec, codcmdprodmat, rezervatini, codobiect,
             codcomanda1f, codinventar1
      from rezervats where codnirstoc = v_rec.codnirstoc and (v_rec.codcomanda1 = codcomanda1 or v_rec.codcomanda1 is null);

      if (LivrDinRezTransf = 1 or v$Session_LivrDinRezTransf = 1) and v_rec.CodNirStocParinte &gt; 0 then
        for v_tmp in (select r.*
                      from rezervats r
                      where r.codnirstoc = v_rec.codnirstoc
                            and (v_Rec.codcomanda1 = r.codcomanda1 or v_rec.codcomanda1 is null)
                     ) loop
          delete rezervats where codrezervats = v_tmp.codrezervats;
          begin
            select CodRezervatS into aCodRezervats
            from rezervats
            where codcomanda1 = v_tmp.codcomanda1 and codnirstoc = v_rec.codnirstocparinte
                  and (v_Rec.codcomanda1 = codcomanda1 or v_rec.codcomanda1 is null);
          exception when others then aCodrezervats := 0;
          end;

          if aCodrezervatS &gt; 0 then
            update rezervats set
              rest        = rest + v_tmp.rest
            where codrezervats = acodrezervats;
          else
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, v_rec.codnirstocparinte, v_tmp.codnirser, v_rec.rest,
                    v_tmp.umsec, v_tmp.codcmdprodmat, v_tmp.rezervatini, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          end if;
        end loop;
      end if;
      delete mastermifix where codnirstoc = v_rec.codnirstoc;
      /*if LivrDinRezTransf = 1 and aCodNirStocOrig &gt; 0 and aTipNS1 = 7 and v_rec.codnirstoc &lt;&gt; aCodNirStocOrig then
        for v_tmp in (select r.*
                      from rezervats r
                      where r.codnirstoc = v_rec.codnirstoc
                     ) loop
          delete rezervats where codrezervats = v_tmp.codrezervats;
          begin
            select CodRezervatS into aCodRezervats
            from rezervats
            where codcomanda1 = v_tmp.codcomanda1 and codnirstoc = acodnirstocorig;
          exception when others then aCodrezervats := 0;
          end;

          if aCodrezervatS &gt; 0 then
            update rezervats set
              rezervatini = rezervatini + v_tmp.rezervatini,
              rest        = rest + v_tmp.rest
            where codrezervats = acodrezervats;
          else
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, acodnirstocorig, v_tmp.codnirser, v_tmp.rest,
                    v_tmp.umsec, v_tmp.codcmdprodmat, v_tmp.rezervatini, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          end if;
        end loop;
      end if;*/

      DELETE FROM NIRSTOC WHERE codnirstoc = v_rec.codnirstoc;
      DELETE FROM NIRSTOC1 WHERE codnirstoc = v_rec.codnirstoc;
    end loop;

-- INAINTE DE STEREGERE DIN NIR REACTIVEZ NUMERELE
    FOR V_REC IN (SELECT * FROM NIR  WHERE ( CODTRANSF = RECID AND CODNIR NOT IN ( SELECT  CODNIR FROM TMP_NIR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
    END LOOP;

    DELETE FROM NIR WHERE ( CODTRANSF = RECID AND CODNIR NOT IN ( SELECT  CODNIR FROM TMP_NIR ));



-- DETAIL LIVR
    /* ATENTIE LA ORDINEA STERGERILOR DIN DETALII */

    DELETE LIVRVAL WHERE CODLIVR1 IN
    ( SELECT CODLIVR1 FROM LIVR1 WHERE
      CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODTRANSF = RECID) AND
      CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1)
    );


    DELETE FROM LIVR1 WHERE
    CODLIVR IN (SELECT CODLIVR FROM LIVR WHERE CODTRANSF = RECID) AND
    CODLIVR1 NOT IN ( SELECT CODLIVR1 FROM TMP_LIVR1);



-- INAINTE DE STEREGERE DIN LIVR REACTIVEZ NUMERELE
    FOR V_REC IN (SELECT * FROM LIVR  WHERE ( CODTRANSF = RECID AND CODLIVR NOT IN ( SELECT  CODLIVR FROM TMP_LIVR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETLIVR);
    END LOOP;

    DELETE FROM LIVR WHERE ( CODTRANSF = RECID AND CODLIVR NOT IN ( SELECT  CODLIVR FROM TMP_LIVR ));

    FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP

      IF NVL(V_REC.CODLIVR, 0) &lt; 0 THEN
        BEGIN
          SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

          INSERT INTO LIVR ( CODLIVR, CODIES, CODTRANSF,  CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
          VALUES ( VCOD, V_REC.CODIES, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR,
                   V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT, V_REC.BLOCAT,  V_REC.OPERAT );


          UPDATE TMP_LIVR1 SET CODLIVR = VCOD  WHERE CODLIVR = V_REC.CODLIVR;

        END;
      ELSE
        BEGIN
          -- VERIFIC DACA S-AU SCHIMBAT CARNETELE DE DOCUMENTE
          SELECT NVL(CARNETLIVR, 0), NVL(NRLIVR, 0) INTO OLDCARNETLIVR, OLDNRLIVR FROM LIVR
          WHERE
          NVL(CODLIVR,0) = NVL(V_REC.CODLIVR,0);

          IF (OLDCARNETLIVR &lt;&gt; 0)AND(OLDNRLIVR &lt;&gt; 0)AND(V_REC.CARNETLIVR &lt;&gt; OLDCARNETLIVR OR V_REC.NRLIVR &lt;&gt; OLDNRLIVR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETLIVR, OLDNRLIVR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETLIVR);
          END IF;


          UPDATE LIVR
          SET
            CARNETLIVR   = V_REC.CARNETLIVR,
            NRLIVR       = V_REC.NRLIVR,
            DATALIVR     = V_REC.DATALIVR,
            OBS          = V_REC.OBS,
            TIPLIVR      = V_REC.TIPLIVR,
            ANULAT       = V_REC.ANULAT,
            BLOCAT       = V_REC.BLOCAT,
            OPERAT       = V_REC.OPERAT
          WHERE
            NVL(CODLIVR,0) = NVL(V_REC.CODLIVR,0);
        END;
      END IF;
    END LOOP;

-- DETAIL LIVR1

-- STERGEREA CELOR CE AU DISPARUT E REZOLVATA MAI SUS

   FOR V_REC IN (SELECT * FROM TMP_LIVR1  ORDER BY CODLIVR, CODIES1) LOOP

      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
       PRETINREG = PRETINREG / V_REC.PARITATE,
       PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;


      IF NVL(V_REC.CODLIVR1, 0) &gt; 0 THEN
        UPDATE LIVR1 SET
          CODLIVR      =  V_REC.CODLIVR,
          CODIES1      =  V_REC.CODIES1,
          CODNIRSTOC   =  V_REC.CODNIRSTOC,
          CANT         =  V_REC.CANT * V_REC.PARITATE,
          CANTREZERVAT =  V_REC.CANTREZERVAT * V_REC.PARITATE,
          CANTUM1      =  V_REC.CANTUM1,
          CANTUM2      =  V_REC.CANTUM2,
          UMSEC        =  V_REC.UMSEC,
          CODCERTIF    =  V_REC.CODCERTIF,
          CONTINTERMED =  V_REC.CONTINTERMED ,
          CODPROIECT   =  V_REC.CODPROIECT,
          CODPRODCOMP   =  V_REC.CODPRODCOMP,
          CODLIVR1PARINTE = V_REC.CODLIVR1PARINTE
        WHERE
          CODLIVR1 = V_REC.CODLIVR1;
      ELSE
        SELECT SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
        UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

        UPDATE TMP_LIVR1 SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

        INSERT INTO LIVR1
        (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTREZERVAT, CANTUM1, CANTUM2, CODNIRSER, PMP, PMPDOC, PMPVALUTA, PMPVALUTADOC, UMSEC, CODCERTIF, CONTINTERMED,CODPROIECT, CODLIVR1PARINTE,
         CODPRODCOMP )
        VALUES
        ( VCOD, V_REC.CODLIVR, V_REC.CODIES1, V_REC.CODINTR1, V_REC.CODNIRSTOC,
          V_REC.CANT * V_REC.PARITATE,
          V_REC.CANTREZERVAT * V_REC.PARITATE,
          V_REC.CANTUM1,
          V_REC.CANTUM2,
          V_REC.CODNIRSER, V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC, V_REC.UMSEC,
          V_REC.CODCERTIF,
          V_REC.CONTINTERMED,
          V_REC.CODPROIECT,
          V_REC.CODLIVR1PARINTE,
          V_REC.CODPRODCOMP );

        UPDATE TMP_NIRSTOC SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
      END IF;
   END LOOP;


     FOR V_REC IN (SELECT * FROM TMP_LIVRVAL) LOOP
        IF V_REC.CODLIVRVAL &lt; 0 THEN
          INSERT INTO LIVRVAL(CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
          VALUES (SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL,  V_REC.CODLIVR1, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.GEST, V_REC.PRETINREG, V_REC.PRETACHIZ, V_REC.TVANEEX);
        ELSE
          UPDATE LIVRVAL
          SET
            CODLIVR1   = V_REC.CODLIVR1,
            CODOBIECT  = V_REC.CODOBIECT,
            CODIOART   = V_REC.CODIOART,
            GEST       = V_REC.GEST,
            PRETINREG  = V_REC.PRETINREG ,
            PRETACHIZ  = V_REC.PRETACHIZ ,
            TVANEEX    = V_REC.TVANEEX
          WHERE
            CODLIVRVAL = V_REC.CODLIVRVAL;
        END IF;
     END LOOP;




 -- ACTUALIZEZ STOCURILE DE PE NIR-URILE DIN CARE LIVREZ;
   UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
   NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);

   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC= NS.CODNIRSTOC ), NS.CODNIRSER, NS.CANTUM2)
   WHERE
   NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);


-- DETAIL NIR
-- ATENTIE LA ORDINEA STERGERILOR DIN DETALII
/*
    DELETE FROM NIRSER WHERE
    CODNIRSTOC IN (SELECT CODNIRSTOC FROM NIRSTOC WHERE CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID)) AND
    CODNIRSER NOT IN ( SELECT CODNIRSER FROM TMP_NIRSER);
*/
/*
    DELETE FROM NIRSTOC WHERE
    CODNIR IN (SELECT CODNIR FROM NIR WHERE CODTRANSF = RECID) AND
    CODNIRSTOC NOT IN ( SELECT CODNIRSTOC FROM TMP_NIRSTOC);
*/
/*
-- INAINTE DE STEREGERE DIN NIR REACTIVEZ NUMERELE
    FOR V_REC IN (SELECT * FROM NIR  WHERE ( CODTRANSF = RECID AND CODNIR NOT IN ( SELECT  CODNIR FROM TMP_NIR )))
    LOOP
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETNIR);
    END LOOP;

    DELETE FROM NIR WHERE ( CODTRANSF = RECID AND CODNIR NOT IN ( SELECT  CODNIR FROM TMP_NIR ));
*/


    FOR V_REC IN ( SELECT * FROM TMP_NIR ORDER BY CODNIR ) LOOP

      IF (NVL(V_REC.CODNIR,0) &lt; 0) THEN
        BEGIN
          SELECT SEQ_NIR_CODNIR.NEXTVAL INTO VCOD FROM DUAL;
          INSERT INTO NIR ( CODNIR, CODINTR, CODTRANSF, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT,OPERAT,
                            USERID )
          VALUES (VCOD, V_REC.CODINTR, RECID, V_REC.CARNETNIR, V_REC.NRNIR,
                   V_REC.DATANIR, V_REC.GEST, V_REC.OBS, V_REC.TIPNIR, V_REC.ANULAT, V_REC.BLOCAT,  V_REC.OPERAT,
                   CASE
                      WHEN NVL(V_REC.OPERAT,0) = 1 THEN pkg_globals.USERID
                      ELSE NVL(V_REC.USERID, 0)
                    END
                    );


          UPDATE TMP_NIRSTOC
          SET CODNIR = VCOD
          WHERE CODNIR = V_REC.CODNIR;

        END;
      ELSE
        BEGIN
          -- VERIFIC DACA S-AU SCHIMBAT CARNETELE DE DOCUMENTE

          SELECT NVL(CARNETNIR, 0), NVL(NRNIR, 0) INTO OLDCARNETNIR, OLDNRNIR FROM NIR
          WHERE
          NVL(CODNIR,0) = NVL(V_REC.CODNIR,0);

          IF (OLDCARNETNIR &lt;&gt; 0)AND(OLDNRNIR &lt;&gt; 0)AND(V_REC.CARNETNIR &lt;&gt; OLDCARNETNIR OR V_REC.NRNIR &lt;&gt; OLDNRNIR)
          THEN
            PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETNIR, OLDNRNIR);
            PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETNIR);
          END IF;


          UPDATE NIR
          SET
            CARNETNIR = V_REC.CARNETNIR,
            NRNIR     = V_REC.NRNIR,
            DATANIR   = V_REC.DATANIR,
            GEST      = V_REC.GEST,
            OBS       = V_REC.OBS,
            TIPNIR    = V_REC.TIPNIR,
            ANULAT    = V_REC.ANULAT,
            BLOCAT    = V_REC.BLOCAT,
            OPERAT    = V_REC.OPERAT,
            USERID    = CASE
                          WHEN NVL(V_REC.OPERAT,0) = 1 AND NVL(OPERAT,0) = 0 THEN pkg_globals.USERID
                          ELSE NVL(V_REC.USERID, 0)
                        END
          WHERE NVL(CODNIR,0) = NVL(V_REC.CODNIR,0);
        END;
      END IF;
    END LOOP;

-- DETAIL NIRSTOC

  FOR V_REC IN ( SELECT NS.*, T1.CODCOMANDA1
                 FROM TMP_NIRSTOC NS
                      LEFT JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1
                 ORDER BY CODNIRSTOC ) LOOP
   IF V_REC.CODNIRSTOC &gt; 0  THEN
     if LivrDinRezTransf = 1  or v$Session_LivrDinRezTransf = 1 then
       begin
         select ns.cantnir - v_rec.cantnir into aDifCant
         from nirstoc ns
         where ns.codnirstoc = v_rec.codnirstoc;
       exception when others then
         aDifCant := 0;
       end;

       if aDifCant &lt;&gt; 0 then
         begin
           select nvl(ns1.tipdoc,0), ns1.codnirstocorig into aTipNS1, aCodNirStocOrig
           from nirstoc1 ns1
           where ns1.codnirstoc = v_rec.codnirstoc;
         exception when others then aTipNS1 := 0; aCodNirStocOrig := 0;
         end;
         if aDifCant &lt; 0 then
           for v_tmp in (select r.*
                         from rezervats r
                         where r.codnirstoc = v_rec.codnirstoc and (v_Rec.codcomanda1 = r.codcomanda1 or v_rec.codcomanda1 is null)
                        ) loop
             update rezervats set
               rezervatini = rezervatini - Abs(aDifCant),
               rest = rest - Abs(aDifCant)
             where codrezervats = v_tmp.codrezervats;
             if v_tmp.codcomanda1 &gt; 0 then
               begin
                 select CodRezervatS into aCodRezervats
                 from rezervats
                 where codcomanda1 = v_tmp.codcomanda1 and codnirstoc = v_rec.codnirstocparinte;
               exception when others then aCodrezervats := 0;
               end;

               if aCodrezervatS &gt; 0 then
                 update rezervats set
                   rezervatini = rezervatini + Abs(aDifCant),
                   rest        = rest + Abs(aDifCant)
                 where codrezervats = acodrezervats;
               else
                 insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                        codobiect, codcomanda1f, codinventar1)
                 values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, v_rec.codnirstocparinte, v_tmp.codnirser, Abs(aDifCant),
                         v_tmp.umsec, v_tmp.codcmdprodmat, Abs(aDifCant), v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
               end if;
             end if;
           end loop;
         else
           for v_tmp in (select r.*
                         from rezervats r
                         where r.codnirstoc = v_rec.codnirstoc and (v_Rec.codcomanda1 = r.codcomanda1 or v_rec.codcomanda1 is null)
                        ) loop
             update rezervats set
               rezervatini = rezervatini + Abs(aDifCant),
               rest = rest + Abs(aDifCant)
             where codrezervats = v_tmp.codrezervats;
             if v_tmp.codcomanda1 &gt; 0 then
               begin
                 select CodRezervatS into aCodRezervats
                 from rezervats
                 where codcomanda1 = v_tmp.codcomanda1 and codnirstoc = v_rec.codnirstocparinte;
               exception when others then aCodrezervats := 0;
               end;
               if aCodrezervatS &gt; 0 then
                 update rezervats set
                   rezervatini = rezervatini - Abs(aDifCant),
                   rest        = rest - Abs(aDifCant)
                 where codrezervats = acodrezervats;
               end if;
             end if;
           end loop;
         end if;
       end if;
     end if;
     UPDATE NIRSTOC SET
        CODNIR            = V_REC.CODNIR,
        CODINTR1          = V_REC.CODINTR1,
        CODTRANSF1        = V_REC.CODTRANSF1,
        CODNIRSTOCPARINTE = V_REC.CODNIRSTOCPARINTE,
        CANTNIR           = V_REC.CANTNIR  * V_REC.PARITATE,
        CANTUM1           = V_REC.CANTUM1,
        CANTUM2           = V_REC.CANTUM2,
        CANTFURN          = V_REC.CANTFURN * V_REC.PARITATE,
        UMSEC             = V_REC.UMSEC,
        CODOBIECT         = V_REC.CODOBIECT,
        CODIOART          = NVL(V_REC.CODIOART, 0),
--      PRET              = V_REC.PRET / V_REC.PARITATE,
        Pret              = ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
        ROTLEI            = V_REC.ROTLEI,
        ROTVALUTA         = V_REC.ROTVALUTA,
        CODLOCATIE        = V_REC.CODLOCATIE,
        Adaos             = nvl(v_rec.Adaos, 0) / v_rec.Paritate,
        TVA               = V_REC.TVA,
        TIPSERIE          = V_REC.TIPSERIE,
        CODLIVR1          = V_REC.CODLIVR1,
        REST              = PKG_INTRARI.GET_REST_STOC    (V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * V_REC.PARITATE),
        RESTUM1           = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
        RESTUM2           = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
        PROCENTADAOS      = V_REC.PROCENTADAOS,
        Supliment         = V_REC.Supliment,
        TG                = V_REC.TG,
        PUMAXIMAL         = V_REC.PUMAXIMAL,
        FURN              = V_REC.FURN,
        CODGESTPROD       = V_REC.CODGESTPROD,
        SUBUNITATEA       = V_REC.SUBUNITATEA,
        DATAACHIZ         = V_REC.DATAACHIZ,
        TIPDOCACHIZ       = V_REC.TIPDOCACHIZ,
        DISCLIKISTOC      = V_REC.DISCLIKISTOC,
        D1                = V_REC.D1,
        D2                = V_REC.D2,
        D3                = V_REC.D3,
        PUVAL             = V_REC.PUVAL,
        PROVIZION         = V_REC.PROVIZION,
        SERIELOT          = V_REC.SERIELOT,
        EUDR_RN           = V_REC.EUDR_RN,
        EUDR_VN           = V_REC.EUDR_VN
     WHERE
       CODNIRSTOC = V_REC.CODNIRSTOC ;

    /*aRoot := PKG_LIST_BASE_UTILS.GETCODNIRSTOC_ORIG(V_rec.Codnirstoc);
    begin
      select nir.tipnir, nvl(ns.pret,0) - nvl(ns.adaos,0), case when nir.tipnir = 7 then 1 else 0 end, nvl(i1.codcmdint1,0)
      into aTipNir, aPretMat, aDirty, aCodComanda1
      from nirstoc ns
           inner join nir on nir.codnir = ns.codnir
           left join intrari1 i1 on ns.codintr1 = i1.codintr1
      where ns.codnirstoc = aRoot;
      UPDATE NIRSTOC1
      SET PRETMAT = ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))) - nvl(v_rec.Adaos, 0) / v_rec.Paritate
      WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    exception when others then
      aRoot := 0;
    end;*/
   ELSE
    SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO VCOD FROM DUAL;

    UPDATE TMP_NIRSTOC SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    UPDATE TMP_NIRSER SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    INSERT INTO NIRSTOC( CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, CANTNIR, CANTUM1, CANTUM2, CANTFURN, UMSEC,  CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, RESTUM1, RESTUM2, PROCENTADAOS, Supliment, TG, PUMAXIMAL, FURN, DATAACHIZ, TIPDOCACHIZ, CODGESTPROD, SUBUNITATEA, DISCLIKISTOC, D1, D2, D3, PUVAL, PROVIZION, SERIELOT, EUDR_RN, EUDR_VN )
    VALUES
    (VCOD, V_REC.CODNIR, V_REC.CODINTR1,  V_REC.CODTRANSF1,  V_REC.CODNIRSTOCPARINTE, V_REC.CANTNIR * V_REC.PARITATE,
     V_REC.CANTUM1, V_REC.CANTUM2,
     V_REC.CANTFURN * V_REC.PARITATE, V_REC.UMSEC,  V_REC.CODOBIECT,  NVL(V_REC.CODIOART, 0),
--   V_REC.PRET / V_REC.PARITATE,
     ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
     V_REC.ROTLEI, V_REC.ROTVALUTA, V_REC.CODLOCATIE,
     NVL(V_REC.ADAOS, 0) / V_REC.PARITATE,  V_REC.TVA,  V_REC.TIPSERIE,  V_REC.CODLIVR1,
     PKG_INTRARI.GET_REST_STOC   (V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * V_REC.PARITATE),
     PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
     PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
     V_REC.PROCENTADAOS,
     V_REC.Supliment,
     V_REC.TG,
     V_REC.PUMAXIMAL,
     V_REC.FURN,
     V_REC.DATAACHIZ,
     V_REC.TIPDOCACHIZ,
     V_REC.CODGESTPROD,
     V_REC.SUBUNITATEA,
     V_REC.DISCLIKISTOC,
     V_REC.D1,
     V_REC.D2,
     V_REC.D3,
     V_REC.PUVAL,
     V_REC.PROVIZION,
     V_REC.SERIELOT,
     V_REC.EUDR_RN,
     V_REC.EUDR_VN
 );

  if atipdoc = 13 and not vSkipMifixAut then
    -- modificarile de pret pt imobilizari in curs -- automatizare
    select count(*) into aCount from mastermifix where codnirstoc = v_rec.codnirstocparinte;
    if aCount &gt; 0 then
      select ioal.cont into acont
      from tmp_ioart_luna ioal
      where ioal.codioart = v_rec.codioart;

      select ioal.cont into acontini
      from tmp_ioart_luna ioal
           inner join nirstoc ns on ns.codioart = ioal.codioart
      where ns.codnirstoc = v_rec.codnirstocparinte;

      if acont = acontini and pkg_categconst.ESTEIMBUNATATIREMIFIX(acont) &gt; 0 then
        begin
          select codmifix into acodmifix from mifix1 where codnirstoc = v_rec.codnirstocparinte and anstart *12 + lunastart =  pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
        exception when others then acodmifix := 0;
        end;
        if acodmifix &gt; 0 then
          select count(*) into aCount from mifix1 where codmifix = acodmifix and anstart * 12 + lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
          if aCount &gt; 0 then
            update mifix1 set
              codnirstoc = v_rec.codnirstoc,
              pret = V_REC.PRET
            where codnirstoc = v_rec.codnirstoc
                  and anstart * 12 + lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;

            insert into mastermifix(codnirstoc,
                                    codclasif,
                                    duratan,
                                    duratanf,
                                    duratang,
                                    codanaliza)
            select v_rec.codnirstoc, m.codclasif, m.duratan, m.duratanf, m.duratang, m.codanaliza
            from mastermifix m
            where m.codnirstoc = v_rec.codnirstocparinte;

            select nir.gest into agestini
            from nirstoc ns
                 inner join nir on nir.codnir = ns.codnir
            where ns.codnirstoc = v_rec.codnirstocparinte;

            select nir.gest into agest
            from nirstoc ns
                 inner join nir on nir.codnir = ns.codnir
            where ns.codnirstoc = v_rec.codnirstoc;

            insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
            values(seq_fisamf_codfisamf.nextval, acodmifix, 3, adatadoc, agestini, agest,
               v_rec.pretinitial, v_rec.pret, aprefixdoc, anumardoc, V_REC.CANTNIR * V_REC.PARITATE, v_rec.codtransf1, atipdoc);
          end if;
        end if;
      end if;
    end if;
  end if;

    aRoot := PKG_LIST_BASE_UTILS.GETCODNIRSTOC_ORIG(VCOD);
    begin
      select nir.tipnir, nvl(ns.pret,0) - nvl(ns.adaos,0), case when nir.tipnir = 7 then 1 else 0 end, nvl(i1.codcmdint1,0),
             case when nir.tipnir = 7 and c1.codobiect = i1.codobiect then 1 else 0 end
      into aTipNir, aPretMat, aDirty, aCodComanda1, aProd
      from nirstoc ns
           inner join nir on nir.codnir = ns.codnir
           left join intrari1 i1 on ns.codintr1 = i1.codintr1
           left join comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
      where ns.codnirstoc = aRoot;

      INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      values (VCOD, aRoot, aTIPNIR, aPretMat, aDirty, case when aTIPNIR = 7 and aProd = 1 then 0 else 1 end, case when aTIPNIR = 7 and aProd = 1 then aCodComanda1 else null end);
    exception when others then
      aRoot := 0;
    end;

    /*if atipdoc = 12 and LivrDinRezTransf = 1 then
      begin
        select V_REC.CANTNIR * V_REC.PARITATE - nvl(sum(nvl(tmp.rest,0)),0) into aDifCant
        from tmp_rezervats tmp
        where tmp.codnirstoc = v_rec.codnirstocparinte;
      exception when others then aDifCant := V_REC.CANTNIR * V_REC.PARITATE;
      end;

       begin
         select nvl(ns1.tipdoc,0), nvl(l.codliniecomanda,0), ns1.codnirstocorig, ns.cantnir into aTipNS1, aCodComanda1, aCodNirStocOrig, aCantNir
         from nirstoc1 ns1
              inner join nirstoc ns on ns.codnirstoc = ns1.codnirstocorig
              left join cmdlink l on l.codcomanda1 = ns1.codcomanda1
         where ns1.codnirstoc = vcod and l.codcomanda1 is null;
       exception when others then aTipNS1 := 0; aCodNirStocOrig := 0;
       end;

       select count(*) into acount from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0;

       if acount &gt; 0 then
         for v_tmp in (select * from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0) loop
           acantrez := v_tmp.rest;
           acodrezervats := v_tmp.codrezervats;
           if aDifCant &lt; aCantRez then
             insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                    codobiect, codcomanda1f, codinventar1)
             values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, V_REC.CANTNIR * V_REC.PARITATE,
                     v_tmp.umsec, v_tmp.codcmdprodmat, V_REC.CANTNIR * V_REC.PARITATE, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
           else
             insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                    codobiect, codcomanda1f, codinventar1)
             values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, aCantRez,
                     v_tmp.umsec, v_tmp.codcmdprodmat, aCantRez, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
           end if;

           if aDifCant &lt; aCantRez then
             update rezervats set
               rezervatini = rezervatini - aDifCant,
               rest        = rest - aDifCant
             where codrezervats = acodrezervats;
           else
             delete rezervats where codrezervats = acodrezervats;
           end if;
         end loop;
       else
         for v_rez in (select * from tmp_rezervats where codnirstoc = v_rec.codnirstocparinte and rownum = 1) loop
           insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                  codobiect, codcomanda1f, codinventar1)
           values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, v_rec.codnirstocparinte, v_rez.codnirser, abs(aDifCant),
                   v_rez.umsec, v_rez.codcmdprodmat, abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);

           insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                  codobiect, codcomanda1f, codinventar1)
           values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, vcod, v_rez.codnirser, aCantNir - abs(aDifCant),
                   v_rez.umsec, v_rez.codcmdprodmat, aCantNir - abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);
         end loop;
       end if;
     end if;*/
     if atipdoc = 12 and (LivrDinRezTransf = 1  or v$Session_LivrDinRezTransf = 1) then
      aDifCant := V_REC.CANTNIR * COALESCE(V_REC.PARITATE,1);
      select count(*) into acount from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0;
      if acount &gt; 0 then
        for v_tmp in (select * from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0 and (v_Rec.codcomanda1 = codcomanda1 or v_rec.codcomanda1 is null)) loop
          aCantRez := v_tmp.rest;
          acodrezervats := v_tmp.codrezervats;
          if aDifCant &lt; aCantRez then
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, aDifCant,
                    v_tmp.umsec, v_tmp.codcmdprodmat, V_REC.CANTNIR * V_REC.PARITATE, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          else
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, aCantRez,
                    v_tmp.umsec, v_tmp.codcmdprodmat, aCantRez, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          end if;

          if aDifCant &lt; aCantRez then
            update rezervats set
              rezervatini = rezervatini - aDifCant,
              rest        = rest - aDifCant
            where codrezervats = acodrezervats;
          else
            delete rezervats where codrezervats = acodrezervats;
          end if;
        end loop;
      else
        for v_rez in (select * from tmp_rezervats where codnirstoc = v_rec.codnirstocparinte and rownum = 1) loop
          insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                 codobiect, codcomanda1f, codinventar1)
          values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, v_rec.codnirstocparinte, v_rez.codnirser, abs(aDifCant),
                  v_rez.umsec, v_rez.codcmdprodmat, abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);
          insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                codobiect, codcomanda1f, codinventar1)
          values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, vcod, v_rez.codnirser, aCantNir - abs(aDifCant),
                  v_rez.umsec, v_rez.codcmdprodmat, aCantNir - abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);
        end loop;
      end if;
    end if;
   END IF;
  END LOOP;


  -- DETAIL NIRSER
--  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

--    IF V_REC.CODNIRSER &lt; 0 THEN
--      INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST) VALUES
--      (SEQ_NIRSER_CODNIRSER.NEXTVAL, V_REC.CODNIRSTOC, V_REC.CODSERIE, V_REC.CANTNIR, V_REC.CANTNIR);
--    ELSE
--      UPDATE NIRSER
--      SET
--        CODNIRSER  = V_REC.CODNIRSER,
--        CODNIRSTOC = V_REC.CODNIRSTOC,
--        CODSERIE   = V_REC.CODSERIE,
--        CANTNIR    = V_REC.CANTNIR,
--        REST       = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC), V_REC.CODNIRSER, V_REC.CANTNIR /*V_REC.PARITATE*/)
--      WHERE
--        CODNIRSER = V_REC.CODNIRSER;
--    END IF;
--  END LOOP;
-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP
    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;

    IF V_REC.CODNIRSER &lt; 0 THEN
      SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;

      UPDATE TMP_NIRSER SET CODNIRSER = VCOD WHERE CODNIRSER = V_REC.CODNIRSER;

      INSERT INTO NIRSER (
      CODNIRSER,
      CODNIRSTOC,
      CODSERIE,
      CANTNIR,
      REST,
      CANTUM1,
      CANTUM2,
      RESTUM1,
      RESTUM2,
      OBS, CodCertif, DataProd, TG, Stare, DataProd1, TG1, CODPRODUCATOR) VALUES
      (VCOD,
      V_REC.CODNIRSTOC,
      aCODSERIE,
      V_REC.CANTNIR * V_REC.PARITATE,
      PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantNir * V_REC.PARITATE ),
      --V_REC.CANTNIR * V_REC.PARITATE,
      V_REC.CANTUM1,
      V_REC.CANTUM2,
       PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM1),
--      V_REC.RESTUM1,
--      V_REC.RESTUM2,
      PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM2),
      V_REC.OBS, V_REC.CodCertif, V_REC.DataProd, V_REC.TG, V_REC.Stare, V_REC.DataProd1, V_REC.TG1, V_REC.CODPRODUCATOR);
      update rezervats set codnirser = vcod where codnirstoc = v_rec.codnirstoc;
    ELSE
      UPDATE NIRSER
      SET
        CODNIRSER  = V_REC.CODNIRSER,
        CODNIRSTOC = V_REC.CODNIRSTOC,
        CODSERIE   = aCODSERIE,
        CANTNIR    = V_REC.CANTNIR * V_REC.PARITATE,
        CANTUM1    = V_REC.CANTUM1,
        CANTUM2    = V_REC.CANTUM2,
        OBS        = V_REC.Obs,
        Codcertif  = V_REC.Codcertif,
        DataProd   = V_REC.DataProd,
        TG         = V_REC.TG,
        DataProd1   = V_REC.DataProd1,
        TG1         = V_REC.TG1,
        CODPRODUCATOR = V_REC.CODPRODUCATOR,
        Stare      = V_REC.Stare   ,
        REST       = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantNir * V_REC.PARITATE ),
        RESTUM1    = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM1),
        RESTUM2    = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM2)
      WHERE
        CODNIRSER = V_REC.CODNIRSER;
    END IF;
  END LOOP;

-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = ATIPDOC AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOAREGRUP   = v_rec.VALOAREGRUP,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,
   V_REC.CODANALIZANOD);
 END IF;
END LOOP;


-- detail JURNAL

DELETE FROM JURNAL WHERE TIPDOC = ATIPDOC AND CODDOC = RECID AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOAREGRUP= v_rec.VALOAREGRUP,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA,
    CODCENTRU  = v_rec.CODCENTRU,
    DATADOC    = V_REC.DATADOC,
    DOCUMENT   = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
      CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, RECID, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, v_rec.VALOAREGRUP,V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODANALIZANOD);
 END IF;
END LOOP;



  ELSE -- INSERT

    SELECT SEQ_TRANSF_CODTRANSF.NEXTVAL INTO RECID FROM DUAL;

    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TRANSF&apos;, RecId);

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

      WINMADMIN.PKG_USERFIRME.PostLog(&apos;TRANSF&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                     RECID,PKG_GLOBALS.FIRMANAME,
                                     aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO TRANSF (
      CODTRANSF, TIPDOC,  ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
      NRDOC,  DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
      OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, SUBUNITATEA, userID,datacreare,
      MIJLTRANSP, NRTRANSP, CODGESTCMD, SUBUNITDEST, LISTAT, REEVALUARE, SERIADOC, IDIMPORT, AJUSTVALSTOC, STADIUWMS,
      CODANALIZA, CODAUTO, TipET, is_ETransp, Corectie )
    SELECT
      RECID, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
      NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
      OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET,SUBUNITATEA,pkg_globals.USERID,systimestamp,
      MIJLTRANSP, NRTRANSP, CODGESTCMD, SUBUNITDEST, LISTAT, REEVALUARE, SERIADOC, IDIMPORT, AJUSTVALSTOC, STADIUWMS, CODANALIZA, CODAUTO, TipET, is_ETransp, Corectie
    FROM TMP_TRANSF;

    FOR V_REC IN ( SELECT * FROM TMP_TRANSF1 ORDER BY INDEXLOCAL ) LOOP
      -- DETAIL TRANSF1
      SELECT SEQ_TRANSF1_CODTRANSF1.NEXTVAL INTO VCOD FROM DUAL;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TRANSF1&apos;, VCOD, v_rec.codtransf1);
      update tmp_jurnal1 set indexlocal = vCod where indexlocal = v_rec.codtransf1;

      INSERT INTO TRANSF1
        ( CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE, CODOBIECTORIG, PARITATEORIG, CODCONT, UMSEC, CODOBIECT, PU, PUMAXIMAL,  CANT, TVA, CODMIFIX, PUVAL, CodReteta, CODCENTRU, CODCOMANDA1,
        CODANALIZANOD, D1, D2, D3, CANTUM1, CANTUM2, PRELUAT,CODAUTO, CODEMULARE1, OBS, TIPDOCIMP, CODLINIEDOCIMP)
      VALUES
        ( VCOD, RECID, V_REC.INDEXLOCAL,  V_REC.TIPLINIE, V_REC.CODOBIECTORIG, V_REC.PARITATEORIG,  V_REC.CODCONT, V_REC.UMSEC,
          V_REC.CODOBIECT, V_REC.PU / V_REC.PARITATE,  V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.CANT * V_REC.PARITATE,  V_REC.TVA, V_REC.CODMIFIX, V_REC.PUVAL,v_rec.CodReteta, V_REC.CODCENTRU, V_REC.CODCOMANDA1,
          v_rec.codanalizanod, V_REC.D1, V_REC.D2, V_REC.D3, v_rec.CANTUM1, v_rec.CANTUM2, V_REC.PRELUAT,V_REC.CODAUTO, V_REC.CODEMULARE1, V_REC.OBS, V_REC.TIPDOCIMP, V_REC.CODLINIEDOCIMP);

      UPDATE TMP_LIVR1 SET CODIES1 = VCOD WHERE CODIES1 = V_REC.CODTRANSF1;
      UPDATE TMP_NIRSTOC SET CODTRANSF1 = VCOD WHERE CODTRANSF1 = V_REC.CODTRANSF1;
      UPDATE TMP_TRANSFLINK SET CODTRANSF1 = vCod WHERE CODTRANSF1 = v_rec.CODTRANSF1;
      UPDATE TMP_IMBMIFIXLINK SET CODTRANSF1 = vCod WHERE CODTRANSF1 = v_rec.CODTRANSF1;
      PKG_CANTAR.UPDATE_RECORDS(aTipDoc, v_rec.CODTRANSF1, vCOD);
      PKG_BCAR.UPDATE_RECORDS(ATIPDOC, v_rec.CodTRANSF1, vCOD);
    END LOOP;

    INSERT INTO TRANSFLINK (CODTRANSF1, CODLINIECOMANDA, CANT) (SELECT CODTRANSF1, CODLINIECOMANDA, CANT FROM TMP_TRANSFLINK);

    INSERT INTO IMBMIFIXLINK (CODIMBMIFIXLINK, CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX, CANT)
    SELECT SEQ_IMBMIFIXLINK_CODIMBMF.NEXTVAL,  CODTRANSF1, CODINTR1, CODIES1, CODNC1, CODMIFIX, CANT FROM TMP_IMBMIFIXLINK;



    -- LIVR
    FOR V_REC IN ( SELECT * FROM TMP_LIVR ORDER BY CODLIVR ) LOOP
      SELECT SEQ_LIVR_CODLIVR.NEXTVAL INTO VCOD FROM DUAL;

      INSERT INTO LIVR (CODLIVR, CODIES, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
      VALUES (VCOD,  V_REC.CODIES, RECID, V_REC.CARNETLIVR, V_REC.NRLIVR, V_REC.DATALIVR, V_REC.OBS, V_REC.TIPLIVR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

      UPDATE TMP_LIVR1 SET CODLIVR = VCOD WHERE CODLIVR = V_REC.CODLIVR;
    END LOOP;

    -- LIVR1
    FOR V_REC IN ( SELECT * FROM TMP_LIVR1 ORDER BY CODLIVR1 ) LOOP
      -- IESIRI VALORICE : IN RELATIA LIVRVAL - LIVR1, PARITATEA SE AFLA IN LIVR1 IAR PRETURILE IN LIVRVAL ;
      -- TREBUIE SA TREC PRETURILE DIN LIVRVAL PRIN PARITATEA DIN LIVR1
      UPDATE TMP_LIVRVAL LV
      SET
        PRETINREG = PRETINREG / V_REC.PARITATE,
        PRETACHIZ = PRETACHIZ / V_REC.PARITATE
      WHERE
        LV.CODLIVR1 = V_REC.CODLIVR1;

      SELECT  SEQ_LIVR1_CODLIVR1.NEXTVAL INTO VCOD FROM DUAL;
      UPDATE TMP_LIVRVAL SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
      UPDATE TMP_LIVR1 SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;

      INSERT INTO LIVR1
      (CODLIVR1, CODLIVR, CODIES1, CODINTR1, CODNIRSTOC, CANT, CANTREZERVAT, CODNIRSER, PMP, PMPDOC, PMPVALUTA, PMPVALUTADOC, UMSEC, CANTUM1, CANTUM2, CODCERTIF, CONTINTERMED,CODPROIECT, CODLIVR1PARINTE,
       CODPRODCOMP)
      VALUES
        (VCOD, V_REC.CODLIVR,  V_REC.CODIES1,  V_REC.CODINTR1,  V_REC.CODNIRSTOC,
        V_REC.CANT *  V_REC.PARITATE,
        V_REC.CANTREZERVAT * V_REC.PARITATE,
        V_REC.CODNIRSER,  V_REC.PMP, V_REC.PMPDOC, V_REC.PMPVALUTA, V_REC.PMPVALUTADOC,  V_REC.UMSEC, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CODCERTIF, V_REC.CONTINTERMED,V_REC.CODPROIECT,
        V_REC.CODLIVR1PARINTE,V_REC.CODPRODCOMP);

      UPDATE TMP_NIRSTOC SET CODLIVR1 = VCOD WHERE CODLIVR1 = V_REC.CODLIVR1;
    END LOOP;

    INSERT INTO LIVRVAL (CODLIVRVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX)
    SELECT SEQ_LIVRVAL_CODLIVRVAL.NEXTVAL, CODLIVR1, CODOBIECT, CODIOART, GEST, PRETINREG, PRETACHIZ, TVANEEX FROM TMP_LIVRVAL;

    UPDATE NIRSTOC NS
    SET
    REST    = PKG_INTRARI.GET_REST_STOC(NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
    RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
    RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
    WHERE
      NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);

    UPDATE NIRSER NS
    SET
      REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
      RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
      RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
    WHERE
      NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1);


-- DETAIL NIR
  FOR V_REC IN ( SELECT * FROM TMP_NIR ORDER BY CODNIR ) LOOP
    SELECT SEQ_NIR_CODNIR.NEXTVAL INTO VCOD FROM DUAL;

    INSERT INTO NIR (CODNIR, CODINTR, CODTRANSF, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT )
    VALUES (VCOD, V_REC.CODINTR, RECID, V_REC.CARNETNIR, V_REC.NRNIR, V_REC.DATANIR, V_REC.GEST, V_REC.OBS, V_REC.TIPNIR, V_REC.ANULAT,  V_REC.BLOCAT, V_REC.OPERAT);

    UPDATE TMP_NIRSTOC SET CODNIR = VCOD WHERE CODNIR = V_REC.CODNIR;
  END LOOP;


-- DETAIL NIRSTOC
  DELETE TMP_NIRSTOC_RECOD; -- folosit la reevaluari
  FOR V_REC IN ( SELECT TMP.*, TL.CODLINIECOMANDA, T1.CODCOMANDA1
                 FROM TMP_NIRSTOC TMP
                      INNER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = TMP.CODTRANSF1
                      LEFT JOIN TRANSFLINK TL ON TMP.CODTRANSF1 = TL.CODTRANSF1
                 ORDER BY TMP.CODNIRSTOC ) LOOP
    SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO VCOD FROM DUAL;

    INSERT INTO TMP_NIRSTOC_RECOD(CODVECHI, CODNOU) VALUES(V_REC.CODNIRSTOC, VCOD); -- folosit la reevaluari

/*
    INSERT INTO NIRSTOC (CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, CANTNIR, CANTFURN, UMSEC,  CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, RESTUM1, RESTUM2, PROCENTADAOS, Supliment, TG, PUMAXIMAL, FURN, DATAACHIZ, TIPDOCACHIZ, CODGESTPROD, SUBUNITATEA, DISCLIKISTOC, CANTUM1, CANTUM2, D1, D2, D3,PUVAL, PROVIZION)
           VALUES (VCOD, V_REC.CODNIR, V_REC.CODINTR1, V_REC.CODTRANSF1, V_REC.CODNIRSTOCPARINTE, V_REC.CANTNIR * V_REC.PARITATE,  V_REC.CANTFURN * V_REC.PARITATE,  V_REC.UMSEC, V_REC.CODOBIECT, NVL(V_REC.CODIOART, 0),
         --V_REC.PRET / V_REC.PARITATE,
           ROUND(v_rec.Pret / v_rec.Paritate, 7 - NVL(V_REC.ROTLEI, 0)),
           V_REC.ROTLEI, V_REC.ROTVALUTA, V_REC.CODLOCATIE, NVL(V_REC.ADAOS, 0) / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE, V_REC.CODLIVR1,
      V_REC.CANTNIR * V_REC.PARITATE,
      V_REC.CANTUM1,
      V_REC.CANTUM2,
      V_REC.PROCENTADAOS,
      V_REC.Supliment,
      V_REC.TG,
      V_REC.PUMAXIMAL,
      V_REC.FURN,
      V_REC.DATAACHIZ,
      V_REC.TIPDOCACHIZ,
      V_REC.CODGESTPROD,
      V_REC.SUBUNITATEA,
      V_REC.DISCLIKISTOC,
      V_REC.CANTUM1,
      V_REC.CANTUM2,
      V_REC.D1,
      V_REC.D2,
      V_REC.D3,
      V_REC.PUVAL,
      V_REC.PROVIZION
      );
*/
    INSERT INTO NIRSTOC( CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, CANTNIR, CANTUM1, CANTUM2, CANTFURN, UMSEC,  CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, RESTUM1, RESTUM2, PROCENTADAOS, Supliment, TG, PUMAXIMAL, FURN, DATAACHIZ, TIPDOCACHIZ, CODGESTPROD, SUBUNITATEA, DISCLIKISTOC, D1, D2, D3, PUVAL, PROVIZION, SERIELOT, EUDR_RN, EUDR_VN )
    VALUES
    (VCOD, V_REC.CODNIR, V_REC.CODINTR1,  V_REC.CODTRANSF1,  V_REC.CODNIRSTOCPARINTE, V_REC.CANTNIR * V_REC.PARITATE,
     V_REC.CANTUM1, V_REC.CANTUM2,
     V_REC.CANTFURN * V_REC.PARITATE, V_REC.UMSEC,  V_REC.CODOBIECT,  NVL(V_REC.CODIOART, 0),
--   V_REC.PRET / V_REC.PARITATE,
     ROUND(v_rec.Pret / v_rec.Paritate, PKG_INTRARI.ZECIMALEPRET(7 - NVL(V_REC.ROTLEI, 0))),
     V_REC.ROTLEI, V_REC.ROTVALUTA, V_REC.CODLOCATIE,
     NVL(V_REC.ADAOS, 0) / V_REC.PARITATE,  V_REC.TVA,  V_REC.TIPSERIE,  V_REC.CODLIVR1,
     PKG_INTRARI.GET_REST_STOC   (V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * V_REC.PARITATE),
     PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
     PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
     V_REC.PROCENTADAOS,
     V_REC.Supliment,
     V_REC.TG,
     V_REC.PUMAXIMAL,
     V_REC.FURN,
     V_REC.DATAACHIZ,
     V_REC.TIPDOCACHIZ,
     V_REC.CODGESTPROD,
     V_REC.SUBUNITATEA,
     V_REC.DISCLIKISTOC,
     V_REC.D1,
     V_REC.D2,
     V_REC.D3,
     V_REC.PUVAL,
     V_REC.PROVIZION,
     V_REC.SERIELOT,
     V_REC.EUDR_RN,
     V_REC.EUDR_VN
 );

    UPDATE TMP_NIRSTOC SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    UPDATE TMP_NIRSER  SET CODNIRSTOC = VCOD WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

    aRoot := PKG_LIST_BASE_UTILS.GETCODNIRSTOC_ORIG(VCOD);
    begin
      select nir.tipnir, nvl(ns.pret,0) - nvl(ns.adaos,0), case when nir.tipnir = 7 then 1 else 0 end, nvl(i1.codcmdint1,0),
             case when nir.tipnir = 7 and c1.codobiect = i1.codobiect then 1 else 0 end
      into aTipNir, aPretMat, aDirty, aCodComanda1, aProd
      from nirstoc ns
           inner join nir on nir.codnir = ns.codnir
           left join intrari1 i1 on ns.codintr1 = i1.codintr1
           left join comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
      where ns.codnirstoc = aRoot;

      INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
      values (VCOD, aRoot, aTIPNIR, aPretMat, aDirty, case when aTIPNIR = 7 and aProd = 1 then 0 else 1 end, case when aTIPNIR = 7 and aProd = 1 then aCodComanda1 else null end);
    exception when others then
      aRoot := 0;
    end;

    if atipdoc = 12 and (LivrDinRezTransf = 1 or v$Session_LivrDinRezTransf = 1) AND V_REC.CODLINIECOMANDA IS NULL then
      aDifCant := V_REC.cantnir * coalesce(V_REC.PARITATE,1);
      insert into x(test) values (&apos;adifcant:&apos;||adifcant);
      select count(*) into acount from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0 and (v_rec.codcomanda1 = codcomanda1 or v_rec.codcomanda1 is null) ;
      if acount &gt; 0 then
        for v_tmp in (select * from rezervats where codnirstoc = v_rec.codnirstocparinte and rest &gt; 0 and (v_rec.codcomanda1 = codcomanda1 or v_rec.codcomanda1 is null)) loop
          aCantRez := v_tmp.rest;
          insert into x(test) values (&apos;acantrez:&apos;||acantrez);
          acodrezervats := v_tmp.codrezervats;
          if aDifCant &lt; aCantRez then
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, aDifCant,
                    v_tmp.umsec, v_tmp.codcmdprodmat, aDifCant, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          else
            insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                   codobiect, codcomanda1f, codinventar1)
            values (seq_rezervats_codrezervats.nextval, v_tmp.codcomanda1, vcod, v_tmp.codnirser, aCantRez,
                    v_tmp.umsec, v_tmp.codcmdprodmat, aCantRez, v_tmp.codobiect, v_tmp.codcomanda1f, v_tmp.codinventar1);
          end if;

          if aDifCant &lt; aCantRez then
            update rezervats set
              rezervatini = rezervatini - aDifCant,
              rest        = rest - aDifCant
            where codrezervats = acodrezervats;
          else
            delete rezervats where codrezervats = acodrezervats;
          end if;
        end loop;
      else
        for v_rez in (select * from tmp_rezervats where codnirstoc = v_rec.codnirstocparinte and rownum = 1) loop
          insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                 codobiect, codcomanda1f, codinventar1)
          values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, v_rec.codnirstocparinte, v_rez.codnirser, abs(aDifCant),
                  v_rez.umsec, v_rez.codcmdprodmat, abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);
          insert into rezervats (codrezervats, codcomanda1, codnirstoc, codnirser, rest, umsec, codcmdprodmat, rezervatini,
                                codobiect, codcomanda1f, codinventar1)
          values (seq_rezervats_codrezervats.nextval, v_rez.codcomanda1, vcod, v_rez.codnirser, aCantNir - abs(aDifCant),
                  v_rez.umsec, v_rez.codcmdprodmat, aCantNir - abs(aDifCant), v_rez.codobiect, v_rez.codcomanda1f, v_rez.codinventar1);
        end loop;
      end if;
    end if;

     if atipdoc = 13 and not vSkipMifixAut then
        -- modificarile de pret pt imobilizari in curs -- automatizare
        select count(*) into aCount from mastermifix where codnirstoc = v_rec.codnirstocparinte;
        if aCount &gt; 0 then
          select ioal.cont into acont
          from tmp_ioart_luna ioal
          where ioal.codioart = v_rec.codioart;

          select ioal.cont into acontini
          from tmp_ioart_luna ioal
               inner join nirstoc ns on ns.codioart = ioal.codioart
          where ns.codnirstoc = v_rec.codnirstocparinte;

          if acont = acontini and pkg_categconst.ESTEIMBUNATATIREMIFIX(acont) &gt; 0 then
            begin
              select codmifix into acodmifix from mifix1 where codnirstoc = v_rec.codnirstocparinte and anstart *12 + lunastart =  pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
            exception when others then acodmifix := 0;
            end;
            if acodmifix &gt; 0 then
              select count(*) into aCount from mifix1 where codmifix = acodmifix and anstart * 12 + lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
              if aCount &gt; 0 then
                update mifix1 set
                  codnirstoc = vcod,
                  pret = V_REC.PRET
                where codmifix = acodmifix
                      and anstart * 12 + lunastart = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;

                insert into mastermifix(codnirstoc,
                                        codclasif,
                                        duratan,
                                        duratanf,
                                        duratang,
                                        codanaliza)
                select vcod, m.codclasif, m.duratan, m.duratanf, m.duratang, m.codanaliza
                from mastermifix m
                where m.codnirstoc = v_rec.codnirstocparinte;

                select nir.gest into agestini
                from nirstoc ns
                     inner join nir on nir.codnir = ns.codnir
                where ns.codnirstoc = v_rec.codnirstocparinte;

                select nir.gest into agest
                from nirstoc ns
                     inner join nir on nir.codnir = ns.codnir
                where ns.codnirstoc = vcod;

                insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
                values(seq_fisamf_codfisamf.nextval, acodmifix, 3, adatadoc, agestini, agest,
                   v_rec.pretinitial, v_rec.pret, aprefixdoc, anumardoc, V_REC.CANTNIR * V_REC.PARITATE, v_rec.codtransf1, atipdoc);
              end if;
            end if;
          end if;
        end if;
      end if;
  END LOOP;

  -- DETAIL NIRSER
--  INSERT INTO NIRSER (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, REST)
--  (SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL, CODNIRSTOC, CODSERIE, CANTNIR, CANTNIR FROM TMP_NIRSER);


-- Detail NirSer
  FOR V_REC IN (SELECT * FROM TMP_NIRSER) LOOP

    IF V_REC.CODSERIE &lt; 0 THEN -- serie noua; actualizez si NSERII
      BEGIN
        SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_REC.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
        EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
      END;

      IF NVL(aCODSERIE, 0) = 0 THEN
        SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
        INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_REC.SERIE, (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC));
      END IF;
    ELSE
      aCODSERIE := V_REC.CODSERIE;
      -- verific daca la editare nu a schimbat seria
      BEGIN
        SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
        EXCEPTION WHEN OTHERS THEN NOMSERIE := &apos;&apos;;
      END;

      IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_REC.SERIE THEN
        UPDATE NSERII SET SERIE = V_REC.SERIE  WHERE CODSERIE = aCODSERIE;
      END IF;
    END IF;

    SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCOD FROM DUAL;
    UPDATE TMP_NIRSER SET CODNIRSER = VCOD WHERE CODNIRSER = V_REC.CODNIRSER;

    INSERT INTO NIRSER (
    CODNIRSER,
    CODNIRSTOC,
    CODSERIE,
    CANTNIR,
    REST,
    CANTUM1,
    CANTUM2,
    RESTUM1,
    RESTUM2,
    OBS,
    CodCertif,
    DataProd, TG, Stare,
    DataProd1, TG1, CODPRODUCATOR) VALUES
    (VCOD,
    V_REC.CODNIRSTOC,
    aCODSERIE,
    V_REC.CANTNIR * V_REC.PARITATE,
--    V_REC.CANTNIR * V_REC.PARITATE,
      PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantNir * V_REC.PARITATE ),
     V_REC.CANTUM1,
     V_REC.CANTUM2,
     PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM1),
     PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = v_rec.CODNIRSTOC), v_Rec.CodNirSer, v_rec.CantUM2),
     --V_REC.CANTUM1,
     --V_REC.CANTUM2,
     V_REC.OBS, V_REC.CodCertif, V_REC.DataProd, V_REC.TG, V_REC.Stare, V_REC.DataProd1, V_REC.TG1, V_REC.CODPRODUCATOR);
     update rezervats set codnirser = vcod where codnirstoc = v_rec.codnirstoc;
  END LOOP;



  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL1);



 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, RECID, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOAREGRUP,OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);



  END IF; -- end INSERT

  pkg_pretprod.CheckNirStoc1ByCodTransf(RecId);

  -- ACTUALIZARE CARNETE DOCUMENTE
  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNET &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(ACARNET, ANUMARDOC);

  FOR V_REC IN (SELECT * FROM LIVR WHERE CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETLIVR, V_REC.NRLIVR);
  END LOOP;


  FOR V_REC IN (SELECT * FROM NIR WHERE CODTRANSF = RECID)
  LOOP
    PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETNIR, V_REC.NRNIR);
  END LOOP;


-- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
    CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;

       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF;

 END LOOP;

 UPDATE COMANDA1 c1
 SET
  c1.RestAcceptat = c1.CantAcceptat -
              ( SELECT NVL(SUM(IL.CANT), 0)
                FROM
                 TRANSFLINK IL
                 LEFT OUTER JOIN TRANSF1 II1 ON II1.CODTRANSF1 = IL.CODTRANSF1
                 LEFT OUTER JOIN TRANSF  II ON II.CODTRANSF     = II1.CODTRANSF
                WHERE
                IL.CODLINIECOMANDA = c1.CodComanda1  AND II.OPERAT = 1 AND II.ANULAT = 0
                )
  WHERE
    c1.CodComanda1 IN (SELECT CODLINIECOMANDA FROM TMP_TRANSFLINK UNION SELECT CODLINIECOMANDA  FROM TMP_TRANSFLINK_INITIAL);


/*
    UPDATE INTRARI1 I1
    SET
     RESTIMBMF =
              I1.CANT * I1.PU -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                 IL.CODINTR1 = I1.CodINTR1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
        EXISTS
        (
         SELECT CODINTR1 FROM TMP_IMBMIFIXLINK WHERE CODINTR1 = I1.CODINTR1
         UNION
         SELECT CODINTR1 FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODINTR1 = I1.CODINTR1
        );

*/


    FOR V_REC IN
    (SELECT I.TIPDOC, I1.TVA, I1.CODINTR1, NVL(I.CURS, 0) AS CURS,  I1.CANT, I1.PU FROM INTRARI1 I1, INTRARI I
     WHERE
     EXISTS (
       SELECT CODINTR1 FROM TMP_IMBMIFIXLINK WHERE CODINTR1 = I1.CODINTR1
       UNION
       SELECT CODINTR1 FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODINTR1 = I1.CODINTR1
     )
      AND I.CODINTR = I1.CODINTR
     )
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

      UPDATE INTRARI1 I1
      SET
        RESTIMBMF = (CASE
                       WHEN V_REC.TIPDOC = 3 THEN  V_REC.CANT * V_REC.PU * aCURS - NVL(V_REC.TVA, 0)
                       ELSE V_REC.CANT * V_REC.PU * aCURS
                     END
                    )
                -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                 IL.CODINTR1 = I1.CodINTR1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODINTR1 = V_REC.CODINTR1;
    END LOOP;


    FOR V_REC IN
      (SELECT I1.CODIES1, NVL(I.CURS, 0) AS CURS,  I1.CANT, I1.PU FROM IESIRI1 I1, IESIRI I
       WHERE
       EXISTS
         (
           SELECT CODIES1 FROM TMP_IMBMIFIXLINK WHERE CODIES1 = I1.CODIES1
           UNION
           SELECT CODIES1 FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODIES1 = I1.CODIES1
         )
        AND I.CODIES = I1.CODIES
       )
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

       PRET_IMB_MF := 0; VAL_ACHIZ_MF := 0; CANT_IMB_MF := 0;
       BEGIN
        SELECT SUM(L1.CANT) AS CANTDIMIN,
               SUM(L1.CANT * (NS.PRET - COALESCE(NS.ADAOS, 0))) AS VALDIMIN
        INTO
          CANT_IMB_MF,
          VAL_ACHIZ_MF
        FROM
          LIVR1 L1,
          LIVR L,
          NIRSTOC NS
        WHERE
          L1.CODIES1 = V_REC.CODIES1
          AND L1.CODLIVR = L.CODLIVR
          AND L.TIPLIVR = 14
          AND NS.CODNIRSTOC = L1.CODNIRSTOC
        GROUP BY L1.CODIES1;

         EXCEPTION WHEN OTHERS THEN NULL;

       END;

       IF NVL(CANT_IMB_MF, 0) &lt;&gt; 0 THEN
         PRET_IMB_MF := VAL_ACHIZ_MF / CANT_IMB_MF;
       END IF;



      UPDATE IESIRI1 I1
      SET
        RESTIMBMF =  /*V_REC.CANT * V_REC.PU*/ PRET_IMB_MF * V_REC.CANT * aCURS -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                 IL.CODIES1 = I1.CodIES1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODIES1 = V_REC.CODIES1;
    END LOOP;


    FOR V_REC IN
      (SELECT N1.CODNC1, NVL(N.CURS, 0) AS CURS,  N1.VALOARE FROM NC1 N1, NC N
       WHERE
       EXISTS
         (
           SELECT CODNC1 FROM TMP_IMBMIFIXLINK WHERE CODNC1 = N1.CODNC1
           UNION
           SELECT CODNC1 FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODNC1 = N1.CODNC1
         )
        AND N.CODNC = N1.CODNC
       )
    LOOP
      aCurs := V_REC.CURS;
      IF aCURS = 0 THEN  aCURS := 1;
      END IF;

      UPDATE NC1 N1
      SET
        RESTIMBMF = V_REC.VALOARE * aCURS -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                 IL.CODNC1 = N1.CodNC1 AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
       CODNC1 = V_REC.CODNC1;
    END LOOP;

    FOR V_REC IN (SELECT M.CODMIFIX, M1.PRET AS VALOARE
                  FROM
                    MIFIX M,
                    MIFIX1 M1
                  WHERE
                    EXISTS
                    (
                      SELECT CODMIFIX FROM TMP_IMBMIFIXLINK        WHERE CODMIFIX = M.CODMIFIX
                      UNION  ALL
                      SELECT CODMIFIX FROM TMP_IMBMIFIXLINK_INITIAL WHERE CODMIFIX = M.CODMIFIX
                    )
                    AND M1.CODMIFIX = M.CODMIFIX
                    AND M1.ANSTART * 12 + M1.LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
                    AND M1.ANSTART * 12 + M1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 M2 WHERE M2.CODMIFIX = M.CODMIFIX AND M2.ANSTART * 12 + M2.LUNASTART &lt;=  PKG_GLOBALS.AnLunaLucru)
    ) LOOP
      UPDATE MIFIX N1
      SET
        RESTIMBMF = V_REC.VALOARE  -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODMIFIX = N1.CODMIFIX AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
        CODMIFIX = V_REC.CODMIFIX;
    END LOOP;


 IF ATIPDOC = 13 AND aOPERAT = 1 THEN
   CHECK_REZERVARI_MODIPRET_IN;
   CHECK_REZERVARI_MODIPRET_OUT;
 END IF;


 IF ATIPDOC = 12 and aOPERAT = 1 and not (LivrDinRezTransf = 1) and not ( v$Session_LivrDinRezTransf = 1) then
   CHECK_REZERVARI_TRANSF_IN;
   CHECK_REZERVARI_TRANSF_OUT;
 END IF;


-- ACTUALIZARE REZERVARESTOC
FOR V_REC IN
(SELECT
   IL.CODLINIECOMANDA,
   NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
   NVL(L1.CODNIRSER,0)  AS CODNIRSER,
   L1.CANTREZERVAT,
   L1.PARITATE
 FROM
   TMP_LIVR1_INITIAL L1,
   TMP_TRANSFLINK_INITIAL IL
 WHERE
  L1.CODIES1 = IL.CODTRANSF1
 )
 LOOP
   UPDATE REZERVATS
   SET
--     CANTREZERVAT = CANTREZERVAT + V_REC.CANTREZERVAT * V_REC.PARITATE,
     REST         = REST         + V_REC.CANTREZERVAT * V_REC.PARITATE
   WHERE
    CODCOMANDA1           = V_REC.CODLINIECOMANDA
    AND CODNIRSTOC        = V_REC.CODNIRSTOC
    AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
 END LOOP;


-- ACTUALIZARE REZERVARESTOC
FOR V_REC IN
(SELECT
   IL.CODLINIECOMANDA,
   NVL(L1.CODNIRSTOC,0) AS CODNIRSTOC,
   NVL(L1.CODNIRSER,0)  AS CODNIRSER,
   L1.CANTREZERVAT,
   L1.PARITATE
 FROM
   TMP_LIVR1 L1,
   TMP_TRANSFLINK IL
 WHERE
  L1.CODIES1 = IL.CODTRANSF1
 )
 LOOP
   UPDATE REZERVATS
   SET
--   CANTREZERVAT = CANTREZERVAT - V_REC.CANTREZERVAT * V_REC.PARITATE,
     REST         = REST         - V_REC.CANTREZERVAT * V_REC.PARITATE
   WHERE
    CODCOMANDA1           = V_REC.CODLINIECOMANDA
    AND CODNIRSTOC        = V_REC.CODNIRSTOC
    AND NVL(CODNIRSER, 0) = V_REC.CODNIRSER;
 END LOOP;

-- actualizez modif pret nirstoc
    FOR V_REC IN ( SELECT CodNirStoc, Pret FROM Tmp_NIRSTOC WHERE NVL(ActualizPret, 0) &gt; 0 )
     LOOP
       PKG_Jurnal.setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.Pret, &apos;0&apos;, 0);
     END LOOP;

  PKG_CANTAR.ELIBEREAZA_ON_SP_POSTRECORDS;

  PKG_GLOBALS.MarkDirtyJurnal;
  NotifyModif(OPERATION, RECID, &apos;TRANSF&apos;);



-- VALORICE FARA DESCARCARE GENERATE DE DOCUMENTUL CURENT
 FOR V_REC IN
   (SELECT L1.CODLIVR1
    FROM
      LIVRVAL LV,
      LIVR1 L1,
      LIVR L,
      TMP_IOART_LUNA IOALUNA
    WHERE
      LV.CODLIVR1 = L1.CODLIVR1 AND L.CODLIVR = L1.CODLIVR AND
      L.CODTRANSF = RECID AND  LV.CODIOART = IOALUNA.CODIOART AND NVL(IOALUNA.DESCARCAREG, 0) = 0
    )
 LOOP
   UPDATE LIVR1 L1
     SET
      L1.RESTIESVAL = L1.CANT -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IESVALLINK IL
                  LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                  LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                WHERE
                  IL.CODLIVR1 = L1.CODLIVR1 AND
                  IL.CODIES1 = I1.CODIES1   AND
                  I.CODIES = I1.CODIES      AND
                  I.OPERAT = 1 AND I.ANULAT = 0
                )
   WHERE
   CODLIVR1 = V_REC.CODLIVR1;
 END LOOP;

  IF aTIPDOC = 12 and PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) &lt;&gt; 1 THEN
    CHECK_TRANSF_MIFIX_SERIEBUCATA (RECID);
    CHECK_TRANSF_MIFIX_FARASERIE   (RECID);
  END IF;

  begin
    if NVL(PKG_CATEGCONST.GetValConstanta(&apos;InchidCmdTransf&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 2) = 1 then
      for v_rec in (select distinct c.codcomanda
                    from transflink l
                         inner join transf1 t1 on l.codtransf1 = t1.codtransf1
                         inner join comanda1 c1 on c1.codcomanda1 = l.codliniecomanda
                         inner join comanda c on c.codcomanda = c1.codcomanda
                    where nvl(c.inchisa,0) = 0 and t1.codtransf = recid
                   ) loop
        update comanda set inchisa = 1 where codcomanda = v_rec.codcomanda;
        delete rezervats r where exists (select c1.codcomanda1 from comanda1 c1 where c1.codcomanda = v_rec.codcomanda and c1.codcomanda1 = r.codcomanda1);
      end loop;
    end if;
  exception when others then null;
  end;

  if aCountBCAR &gt; 0 then
    for v_rec in (select b.codbcar, t.delegat, t.codgestcmd codpartener
                  from transf1 t1
                       inner join transf t on t.codtransf = t1.codtransf
                       inner join bcar b on b.coddoc1 = t1.codtransf1 and b.tipdoc = atipdoc
                  where t.codtransf = recid
                  ) loop
      update bcar set coddelegat = v_rec.delegat, codpartener = v_rec.codpartener where codbcar = v_rec.codbcar;
    end loop;
  end if;

  if DoCommit then
    COMMIT;
  END IF;

  UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);
   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
    NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_LIVR1 UNION SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL);

  UPDATE NIRSTOC NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC    (NS.CODNIR, NS.CODNIRSTOC, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_UM1(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_UM2(NS.CODNIR, NS.CODNIRSTOC, NS.CANTUM2)
   WHERE
     NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOC);
   UPDATE NIRSER NS
   SET
     REST    = PKG_INTRARI.GET_REST_STOC_SERIE    ((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTNIR),
     RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM1),
     RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = NS.CODNIRSTOC), NS.CODNIRSER, NS.CANTUM2)
   WHERE
    NS.CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSER);

  IF aOPERAT = 0 THEN
    DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = aTIPDOC);
    DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = aTIPDOC;
  END IF;
  PKG_CFGTABLES.EXT_POSTRECORDS(ATIPDOC, OPERATION);
  if DoCommit then
		COMMIT;
  end if;


  /*EXCEPTION WHEN OTHERS THEN BEGIN
    ROLLBACK;
    RAISE;
  END;
END;*/

END;


FUNCTION GETCURSORIGINAL(ANIRSTOCPARINTE IN NUMBER) RETURN NUMBER IS
IRES NUMBER(20,7);
BEGIN
   BEGIN
     SELECT (PRET - NVL(ADAOS,0)) / PUVAL INTO IRES FROM NIRSTOC WHERE CODNIRSTOC = ANIRSTOCPARINTE;
   EXCEPTION WHEN OTHERS THEN
    IRES := 1;
   END;
 RETURN IRES;
END;

END PKG_MISCARI_INTERNE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MODIF_CENTRE_COST_X_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>455564B4DED47E25DE220686E1ADB4D0BA32AEC0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MODIF_CENTRE_COST_X_DOC IS

  PROCEDURE actualizareCentreCost(pDataStart     IN VARCHAR2,
                                  pDataEnd       IN VARCHAR2,
                                  centruCostIni  IN Number,
                                  centruCostNew  IN Number,
                                  pCodGest       IN Number default null,
                                  pCodAnalizaNod IN Number default null) is
  
    centruCostIni_not_found EXCEPTION;
    centruCostNew_not_found EXCEPTION;
    noRowsToUpdate          EXCEPTION;
    codCentruCostIni        Number(20);
    codCentruCostNew        Number(20);
    dataStartVar               Date;
    dataEndVar                 Date;
    listaTipDocDeModificat          NUMBER_LIST := NUMBER_LIST(1,2,3,4,5,6,7,8,9,14,15,16,18,19,20,21,24,26,28,29,30,31,35);
    listaTipDocDeModificatObligpif  NUMBER_LIST := NUMBER_LIST(6,7,14,15,16,18,28,29,30,31);
    
    vCodGest                Number(20);
    vCodAnalizaNod          Number(20);
  BEGIN
    dataStartVar   := to_date(pDataStart, &apos;dd.mm.yyyy&apos;);
    dataEndVar     := to_date(pDataEnd, &apos;dd.mm.yyyy&apos;);
    vCodGest       := case when coalesce(pCodGest,0) = 0 then null else pCodGest end;
    vCodAnalizaNod := case when coalesce(pCodAnalizaNod,0) = 0 then null else pCodAnalizaNod end;
    BEGIN
      IF centruCostIni is not null AND centruCostIni &gt; 0 THEN
        SELECT cc.codcentru
          INTO codCentruCostIni
          FROM centrecost cc
         WHERE cc.codcentru = centruCostIni;
      ELSE
        RAISE centruCostIni_not_found;
      END IF;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RAISE centruCostIni_not_found;
    END;
    BEGIN
      IF centruCostNew is not null AND centruCostNew &gt; 0 THEN
        SELECT cc.codcentru
          INTO codCentruCostNew
          FROM centrecost cc
         WHERE cc.codcentru = centruCostNew;
      ELSE
        RAISE centruCostNew_not_found;
      END IF;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RAISE centruCostNew_not_found;
    END;
    -- pt tipdoc = 5 trebuie in loc de codintr1 coddvi1, indexlocal din juranal1 este completat cu coddvi1  
    -- completez in temporar pe coloana codjurnal
    -- COD GESTIUNE =&gt; CONTD,  COD ANALIZA NOD =&gt; CONTC
    DELETE FROM TMP_JURNAL;
    insert into TMP_JURNAL
      (OBS, TIPDOC, CODDOC, INDEXLOCAL, CODJURNAL, CONTD, CONTC)
      select &apos;intrari1&apos;,
             intr.tipdoc,
             intr.codintr,
             intr1.codintr1,
             dv1.coddvi1,
             case when intr1.tiplinie = &apos;S&apos; then intr1.gestact else coalesce(nri.gest,nrd.gest) end as gest,
             intr1.codanalizanod
        from intrari intr
        join intrari1 intr1
          on intr1.codintr = intr.codintr
        left join dvi1 dv1
          on dv1.codintr1 = intr1.codintr1
        left join nirstoc nsti on nsti.codintr1 = intr1.codintr1
        left join nir nri on nri.codnir = nsti.codnir
        left join nirstoc nstd on nstd.coddvi1 = dv1.coddvi1
        left join nir nrd on nrd.codnir = nsti.codnir
       where trunc(intr.datadoc) between dataStartVar and dataEndVar
         and intr.tipdoc in
             (select column_value from table(listaTipDocDeModificat))
         and coalesce(intr1.codcentru, 0) = codCentruCostIni
      union all --iesiri
      select &apos;iesiri1&apos;,
       ies.TIPDOC,
       ies.CODIES,
       ies1.CODIES1,
       null,
       CASE
         WHEN ies1.TIPLINIE = &apos;S&apos; THEN
          ies1.GESTACT
         ELSE
          (CASE
            WHEN lv.CODLIVR1 IS NULL THEN
             n.GEST
            ELSE
             lv.GEST
          END)
       end as gest,
       ies1.codanalizanod
        FROM IESIRI ies
        JOIN IESIRI1 ies1
          ON IES1.codies = IES.codies
        LEFT JOIN LIVR1 lvr1
          ON lvr1.CODIES1 = ies1.CODIES1
        LEFT JOIN NIRSTOC ns
          ON ns.CODNIRSTOC = lvr1.CODNIRSTOC
        LEFT JOIN LIVRVAL lv
          ON lv.CODLIVR1 = lvr1.CODLIVR1
        LEFT JOIN NIR n
          ON n.CODNIR = ns.CODNIR
       where trunc(ies.datadoc) between dataStartVar and dataEndVar
         and ies.tipdoc in
             (select column_value from table(listaTipDocDeModificat))
         and coalesce(ies1.codcentru, 0) = codCentruCostIni
      union all --comanda
       select &apos;comanda1&apos;,
         cmd.tipdoc,
         cmd.codcomanda,
         cmd1.codcomanda1,
         null,
         cmd1.gestact,
         cmd1.codanalizanod
       from comanda cmd
       join comanda1 cmd1
          on cmd1.codcomanda = cmd.codcomanda  
       where trunc(cmd.datadoc) between dataStartVar and dataEndVar
         and cmd.tipdoc in
             (select column_value from table(listaTipDocDeModificat))
         and coalesce(cmd1.codcentru, 0) = codCentruCostIni
      union all -- trezor codcentru este in obligpif si coddoc din general este codtrezor1
      select &apos;trezor1&apos;, trz.tipdoc, trz.codtrezor, trz1.codtrezor1, null, opf.codgest, opf.codanalizanod
        from trezor trz
        join trezor1 trz1
          on trz1.codtrezor = trz.codtrezor
        join general gn
          on gn.coddoc = trz1.codtrezor1
         and gn.tipdoc = trz.tipdoc
        join obligpif opf
          on opf.codgeneral = gn.codgeneral
       where trunc(trz.datadoc) between dataStartVar and dataEndVar
         and trz.tipdoc in
             (select column_value from table(listaTipDocDeModificat))
         and coalesce(opf.codcentru, 0) = codCentruCostIni
      union all -- compens
      select &apos;compens&apos;, 28, cmps.codcompens, cmps.codcompens, null, cmps.codgest, opf.codanalizanod
        from compens cmps
        join general gn
          on gn.coddoc = cmps.codcompens
         and gn.tipdoc = 28
        join obligpif opf
          on opf.codgeneral = gn.codgeneral
       where trunc(cmps.datadoc) between dataStartVar and dataEndVar
         and coalesce(cmps.codcentru, 0) = codCentruCostIni
      union all -- nc
      select &apos;nc1&apos;, 35, nca.codnc, nca1.codnc1, null,nca1.codgest,nca1.codanalizanod
        from nc nca
        join nc1 nca1
          on nca1.codnc = nca.codnc
       where trunc(nca.datadoc) between dataStartVar and dataEndVar
         and coalesce(nca1.codcentru, 0) = codCentruCostIni;
  
    if SQL%ROWCOUNT = 0 THEN
      RAISE noRowsToUpdate;
    end if;
    --- update detalii       
    ---UPDATE INTRARI
    update intrari1 i1
       set codcentru = codCentruCostNew
     where i1.codintr1 IN (select tmc.INDEXLOCAL
                             from TMP_JURNAL tmc
                            where tmc.OBS = &apos;intrari1&apos; 
                             and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmc.contd end
                             and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmc.contc end);
    ---UPDATE IESIRI
    update iesiri1 i1
       set codcentru = codCentruCostNew
     where i1.codies1 IN (select tmc.INDEXLOCAL
                            from TMP_JURNAL tmc
                           where tmc.OBS = &apos;iesiri1&apos;
                           and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmc.contd end
                           and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmc.contc end);
    ---UPDATE COMANDA
    update comanda1 i1
       set codcentru = codCentruCostNew
     where i1.codcomanda1 IN
           (select tmc.INDEXLOCAL
              from TMP_JURNAL tmc
             where tmc.OBS = &apos;comanda1&apos;
             and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmc.contd end
             and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmc.contc end);
    ---UPDATE COMPENS
    update compens i1
       set codcentru = codCentruCostNew
     where i1.codcompens IN (select tmc.INDEXLOCAL
                               from TMP_JURNAL tmc
                              where tmc.OBS = &apos;compens&apos;
                              and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmc.contd end 
                              and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmc.contc end);
    ---UPDATE NC
    update nc1 i1
       set codcentru = codCentruCostNew
     where i1.codnc1 IN
           (select tmc.INDEXLOCAL from TMP_JURNAL tmc where tmc.OBS = &apos;nc1&apos;
           and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmc.contd end
           and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmc.contc end);
    ----update detalii term
    --- UPDATE OBLIGPIF
    update obligpif opf
       set codcentru = codCentruCostNew
     where opf.codgeneral in
           (SELECT g.codgeneral
              FROM GENERAL g
             WHERE (g.TIPDOC, g.CODDOC) IN
                   (SELECT tmcc.TIPDOC,
                           case
                             when tmcc.TIPDOC in (29, 30, 31) then
                              tmcc.INDEXLOCAL
                             else
                              tmcc.CODDOC
                           end
                      FROM TMP_JURNAL tmcc
                      where tmcc.TIPDOC in (select column_value from table(listaTipDocDeModificatObligpif))
                          and coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmcc.contd end
                          and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmcc.contc end))
       and coalesce(opf.codcentru, 0) = codCentruCostIni
       and coalesce(vCodGest,1) = case when vCodGest is null then 1 else opf.codgest end
       and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else opf.codanalizanod end;
    ---UPDATE JURNAL
    update JURNAL JRN
       set codcentru = codCentruCostNew
     WHERE (JRN.CODDOC, JRN.TIPDOC, case when JRN.TIPDOC IN (29,30,31,35) then JRN.INDEXLOCAL ELSE -1 END ) IN
           (SELECT tmcc.CODDOC, tmcc.TIPDOC, case when tmcc.TIPDOC IN (29,30,31,35) then tmcc.INDEXLOCAL ELSE -1 END
              FROM TMP_JURNAL tmcc 
              WHERE coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmcc.contd end
                  and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmcc.contc end)
       AND coalesce(JRN.codcentru, 0) = codCentruCostIni
       and coalesce(vCodGest,1) = case when vCodGest is null then 1 else JRN.gest end
       and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else JRN.codanalizanod end;
    ---UPDATE JURNAL1
    update JURNAL1 JRN1
       set codcentru = codCentruCostNew
     WHERE (JRN1.CODDOC, JRN1.TIPDOC, JRN1.INDEXLOCAL) IN
           (SELECT tmcc.CODDOC,
                   tmcc.TIPDOC,
                   case
                     when tmcc.tipdoc = 5 then
                      tmcc.codjurnal
                     else
                      tmcc.INDEXLOCAL
                   end
              FROM TMP_JURNAL tmcc
              where coalesce(vCodGest,1) = case when vCodGest is null then 1 else tmcc.contd end
                and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else tmcc.contc end)
       AND coalesce(JRN1.codcentru, 0) = codCentruCostIni
       and coalesce(vCodGest,1) = case when vCodGest is null then 1 else JRN1.gest end
       and coalesce(vCodAnalizaNod,1) = case when vCodAnalizaNod is null then 1 else JRN1.codanalizanod end;
    COMMIT;
  EXCEPTION
    WHEN centruCostIni_not_found OR centruCostNew_not_found THEN
      RETURN;
    WHEN noRowsToUpdate THEN
      RETURN;
    WHEN OTHERS THEN
      ROLLBACK;
  END;

END PKG_MODIF_CENTRE_COST_X_DOC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MONEDE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB9575E7D004B9F0CD8590E9BF395F0C079E033E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY &quot;PKG_MONEDE&quot; IS


FUNCTION GETCURSMONEDA(aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATA VARCHAR2) RETURN NUMBER
IS
 aCURS NUMBER(20,7) := 0;
BEGIN
  BEGIN
    SELECT NVL(VALOARE, 1) INTO aCURS
    FROM
      NMONEDE  N,
      NMONEDE1 N1
    WHERE
      N.CODMONEDA = N1.CODMONEDA AND
      N1.CODBANCA = aCODBANCA  AND
      N.CODMONEDA = aCODMONEDA AND
      DATA = (SELECT MAX(DATA) FROM NMONEDE1 WHERE CODBANCA = aCODBANCA AND CODMONEDA = aCODMONEDA AND DATA &lt;= TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;) and NVL(VALOARE, 1) &gt; 0);
    EXCEPTION WHEN OTHERS THEN aCURS := 1;
  END;
  if coalesce(aCURS,0) = 0 then aCURS := 1; end if;  
  RETURN aCURS;
END;

FUNCTION GETDATACURS(aCODMONEDA IN NUMBER, aCODBANCA IN NUMBER, aDATADOC IN DATE, aCURS IN NUMBER) RETURN VARCHAR2
IS
 aData VARCHAR2(10);
BEGIN
  aData := &apos;&apos;;
  
  --PKG_GLOBALS.clear_x;
  --PKG_GLOBALS.baga_in_x(ACODMONEDA||&apos; &apos;||ACODBANCA||&apos; &apos;||ADATADOC||&apos; &apos;||ACURS);
  --INSERT INTO X(TEST) VALUES(ACODMONEDA||&apos; &apos;||ACODBANCA||&apos; &apos;||ADATADOC||&apos; &apos;||ACURS);
  FOR V_REC IN (
    SELECT TO_CHAR(N1.DATA,&apos;DD.MM.YYYY&apos;) DATACURS
    FROM
      NMONEDE  N,
      NMONEDE1 N1
    WHERE
      N.CODMONEDA = N1.CODMONEDA AND
      N1.CODBANCA = aCODBANCA  AND
      N.CODMONEDA = aCODMONEDA AND
      DATA = (SELECT MAX(M1.DATA) FROM NMONEDE1 M1 WHERE M1.CODBANCA = aCODBANCA AND M1.CODMONEDA = aCODMONEDA AND M1.DATA &lt;= aDATADOC and ROUND(M1.VALOARE,4) = ROUND(aCURS,4))
    )
  LOOP
    aData := V_REC.DATACURS;
  END LOOP;  
  RETURN aDATA;
END;

PROCEDURE SET_MONEDA_CURENTA(aCodMoneda IN NUMBER)
IS
BEGIN
  MONEDACURENTA := aCodMoneda;
END;

FUNCTION GET_MONEDA_CURENTA RETURN NUMBER
IS 
BEGIN
  RETURN MONEDACURENTA;
END;

FUNCTION MONEDA_VALIDA(aCODMONEDA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF MONEDACURENTA &lt; 0 THEN RETURN 1; -- indiferent de moneda
  ELSE
    IF aCODMONEDA = MONEDACURENTA THEN RETURN 1;
                                  ELSE RETURN 0;
    END IF;                              
  END IF; 
END;

FUNCTION TESTUNICITATESIMBOL(aSimbol IN VARCHAR2, aCODMONEDA IN NUMBER) RETURN NUMBER
IS PRAGMA AUTONOMOUS_TRANSACTION;
aCount NUMBER(20);
BEGIN
  SELECT COUNT(CodMoneda) into aCount FROM NMONEDE WHERE UPPER(aSimbol) = UPPER(Simbol) AND CodMoneda &lt;&gt; aCODMONEDA;
  return aCount;
END;

FUNCTION GET_SIMBOL_MONEDA(aCodMoneda IN NUMBER) RETURN VARCHAR2
IS
aSimbol VARCHAR2(30) := &apos;???&apos;;
BEGIN
  BEGIN
    SELECT SIMBOL INTO aSimbol  FROM NMONEDE WHERE CODMONEDA = aCodMoneda;
    EXCEPTION WHEN OTHERS THEN RETURN &apos;???&apos;;
  END;
  RETURN aSimbol;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
  Tmp NUMBER(20); 
BEGIN 
  SELECT codmoneda INTO Tmp FROM NMONEDE WHERE codmoneda = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN 
  SP_LOCKRECORD(RecId);
	DELETE FROM NMONEDE1 WHERE codmoneda = RecId ;
  DELETE FROM NMONEDE  WHERE codmoneda = RecId ;
  NotifyModif(2, RECID, &apos;NMONEDE&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN 
  INSERT INTO  TMP_NMONEDE FIELDS( codmoneda ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN 
-- Master NMONEDE
  INSERT INTO  TMP_NMONEDE ( codmoneda,den_moneda,simbol,Sdenumire,ssimbol,zecimale ) 
    ( SELECT codmoneda,den_moneda,simbol,Sdenumire,ssimbol,zecimale
      FROM NMONEDE WHERE codmoneda = RecId ) ; 

-- Detail NMONEDE1
  INSERT INTO  TMP_NMONEDE1 ( codmoneda1,codmoneda,codbanca,data,valoare ) 
    ( SELECT codmoneda1,codmoneda,codbanca,data,valoare
      FROM NMONEDE1 WHERE codmoneda = RecId  ) ; 


--  SELECT MAX(NVL(codmoneda1,0)) INTO g_codmoneda1 FROM TMP_NMONEDE1; 
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0; 
  vAn INTEGER := 0; 
  vLuna INTEGER := 0; 
  vCod NUMBER(20); 
BEGIN
  IF Operation = 0 THEN  -- UPDATE 

-- Master NMONEDE
    SELECT  codmoneda INTO RecId FROM TMP_NMONEDE;
    UPDATE NMONEDE SET ( den_moneda,simbol,Sdenumire,ssimbol,zecimale ) 
       = ( SELECT den_moneda,simbol,Sdenumire,ssimbol,zecimale
          FROM TMP_NMONEDE ) 
      WHERE codmoneda = RecId ; 


-- Detail NMONEDE1
    
    DELETE FROM NMONEDE1 WHERE ( codmoneda = RecId AND codmoneda1 NOT IN ( SELECT codmoneda1 FROM TMP_NMONEDE1 WHERE NVL(codmoneda1,0) &lt;&gt; 0));

    INSERT INTO NMONEDE1 ( codmoneda1,codmoneda,codbanca,data,valoare ) 
      SELECT  seq_NMONEDE1_codmoneda1.Nextval, RecId , codbanca, data, valoare  FROM TMP_NMONEDE1 WHERE codmoneda1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NMONEDE1 WHERE NVL(codmoneda1,-1) &gt; 0  ORDER BY codmoneda1 ) LOOP 
      UPDATE NMONEDE1 SET codmoneda = RecId ,codbanca = v_rec.codbanca,data = v_rec.data,valoare = v_rec.valoare
      WHERE codmoneda1 = v_rec.codmoneda1;
    END LOOP;
  ELSE  -- INSERT 
-- Master NMONEDE
  SELECT seq_NMONEDE_codmoneda.NextVal INTO RecId FROM DUAL; 
  INSERT INTO  NMONEDE ( codmoneda,den_moneda,simbol,Sdenumire,ssimbol,zecimale ) 
 ( SELECT  RecId ,den_moneda,simbol,Sdenumire,ssimbol,zecimale
     FROM TMP_NMONEDE  ) ; 
-- Detail NMONEDE1
  INSERT INTO  NMONEDE1 ( codmoneda1,codmoneda,codbanca,data,valoare ) 
     ( SELECT  seq_NMONEDE1_codmoneda1.Nextval ,RecId,codbanca,data,valoare FROM TMP_NMONEDE1 );

END IF;
 NotifyModif(OPERATION, RECID, &apos;NMONEDE&apos;);  

  COMMIT;
END;

PROCEDURE UPDATE_PRETM_CURS ( p_simbol_banca nbank.simbol%TYPE ) IS
  v_curs_curent  NMONEDE1.VALOARE%TYPE;
  v_today     DATE := TRUNC(SYSDATE);
  v_err       VARCHAR2(4000);
  v_cod_moneda NMONEDE1.CODMONEDA%TYPE;
  v_codbanca   NBANK.CODBANK%TYPE;
BEGIN
  BEGIN
      SELECT codbank
        INTO v_codbanca
        FROM nbank
       WHERE simbol = p_simbol_banca;
  EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RAISE_APPLICATION_ERROR(-20040,
          &apos;Simbol de banca inexistent: &apos;||p_simbol_banca);
      WHEN TOO_MANY_ROWS THEN
        RAISE_APPLICATION_ERROR(-20041,
          &apos;Simbol de banca duplicat in NBANK: &apos;||p_simbol_banca);
  END;
  FOR r IN (
  SELECT DISTINCT codmoneda
    FROM nmonede1
   WHERE codbanca = v_codbanca
     AND NVL(codmoneda,0) &lt;&gt; 0 ) LOOP
     
   BEGIN
      -- log start pentru moneda curenta
      INSERT INTO pretm_autoupd_log
             (cod_moneda, cod_banca, run_date, started_by, start_ts, status)
      VALUES (r.codmoneda, v_codbanca, v_today, PKG_GLOBALS.USERNAME, SYSTIMESTAMP, &apos;RUNNING&apos;);
      COMMIT;

      v_curs_curent := GETCURSMONEDA(
                   r.codmoneda,
                   v_codbanca,
                   TO_CHAR(v_today, &apos;dd.mm.yyyy&apos;)
                 );
      IF v_curs_curent = 1 THEN
          UPDATE pretm_autoupd_log
             SET end_ts = SYSTIMESTAMP,
                 status = &apos;ERROR: nu exista curs&apos;
           WHERE cod_moneda = r.codmoneda
             AND cod_banca  = v_codbanca
             AND run_date   = v_today;
           COMMIT;
           CONTINUE;           
      END IF;
   -- 1) Actualizeaza PRETM
        UPDATE pretm p
           SET p.lei = PKG_PRETURI.WMROTOPRET(
                         (SELECT o.rotvaluta
                            FROM nartobj o
                           WHERE o.codobiect = p.codobiect),
                         NVL(p.valuta, 0) * v_curs_curent
                       )
         WHERE p.moneda = r.codmoneda
           AND EXISTS (
                 SELECT 1
                   FROM ncatpret c
                  WHERE c.codcatpret = p.codcatpret
                    AND c.tip         &lt; 3
               );
    -- 2) Actualizeaza PRETMAMB
        MERGE INTO pretmamb pa
        USING (
          SELECT
            pa2.codpretm            AS codpretm,
            o.rotvaluta             AS rot_val,
            COALESCE(pa2.valuta,0)  AS val_fc
          FROM pretmamb pa2
          JOIN pretm      p  ON pa2.codpretm   = p.codpretm
          JOIN ncatpret   c  ON c.codcatpret   = p.codcatpret
                             AND c.tip          &lt; 3
          JOIN nartobj    o  ON o.codobiect     = p.codobiect
          WHERE p.moneda = r.codmoneda
        ) src
          ON (pa.codpretm = src.codpretm)
        WHEN MATCHED THEN
          UPDATE SET
            pa.lei = PKG_PRETURI.WMROTOPRET(
                       src.rot_val,
                       src.val_fc * v_curs_curent
                     );   
        
        UPDATE pretm_autoupd_log
           SET end_ts = SYSTIMESTAMP,
               status = &apos;SUCCESS&apos;
         WHERE cod_moneda = r.codmoneda
           AND cod_banca  = v_codbanca
           AND run_date   = v_today;

        COMMIT;
        EXCEPTION
           WHEN DUP_VAL_ON_INDEX THEN
               CONTINUE;
           WHEN OTHERS THEN
                 v_err := NVL(SQLCODE || &apos;: &apos;, &apos;&apos;) || SUBSTR(SQLERRM, 1, 3900);
                 ROLLBACK;
                 UPDATE pretm_autoupd_log
                   SET end_ts = SYSTIMESTAMP,
                       status = &apos;ERROR&apos;,
                       error_msg = v_err
                 WHERE cod_moneda = r.codmoneda
                   AND cod_banca  = v_codbanca
                   AND run_date   = v_today;
                   COMMIT;  
       END;
    END LOOP;         
END UPDATE_PRETM_CURS;



END pkg_Monede; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MOTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4051059616138A352819594C96C15E45DA621FA5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_MOTIVE IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodMOTIV INTO Tmp FROM MOTIVE WHERE CodMOTIV = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM MOTIVE WHERE CodMOTIV = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_MOTIVE FIELDS( CodMOTIV, Tip ) VALUES (0,0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_MOTIVE ( CodMOTIV, Continut, Tip, Cod, Motiv )
    ( SELECT CodMOTIV, Continut, Tip, Cod, Motiv
      FROM MOTIVE WHERE CodMOTIV = RecId );
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodMOTIV INTO RecId FROM TMP_MOTIVE;
    UPDATE MOTIVE SET ( Continut, Tip, Cod, Motiv )
       = ( SELECT Continut, Tip, Cod, Motiv
          FROM TMP_MOTIVE )
      WHERE CodMOTIV = RecId ;

  ELSE  -- INSERT
-- Master Nautom
  SELECT SEQ_MOTIVE_CODMOTIV.NextVal INTO RecId FROM DUAL;
  INSERT INTO  MOTIVE ( CodMOTIV, Continut, Tip, Cod, Motiv )
 ( SELECT  RecId , Continut, Tip, Cod, Motiv
     FROM TMP_MOTIVE  ) ;
  END IF;
  COMMIT;
END;

end PKG_MOTIVE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_MOTIVEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04BCF9A283A5ABE3D05E5344686FC7BFFAE68A9C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_motivep is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_57&apos;;

procedure SP_LockRecord(RecId in NUMBER) is
  Tmp NUMBER(20);
begin
  SELECT CodMotiv INTO Tmp FROM MotiveP WHERE CodMotiv = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
  aDoc varchar2(250);
begin
  SP_LockRecord(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Motiv &quot;&apos;||denmotiv||&apos;&quot;&apos; INTO aDoc FROM MotiveP WHERE codmotiv = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;MotiveP&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM MotiveP WHERE CodMotiv = RecId;
  NotifyModif(2, RECID, &apos;MOTIVEP&apos;);
  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_MotiveP FIELDS(CodMotiv) VALUES (0);
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
begin
  INSERT INTO Tmp_MotiveP (
    CodMotiv,
    DenMotiv,
    Motiv
  )(
    SELECT
      CodMotiv,
      DenMotiv,
      Motiv
    FROM MotiveP
    WHERE CodMotiv = RecId
  );
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
  aDoc varchar2(250);
begin
  if Operation = 0 then -- UPDATE
    SELECT CodMotiv INTO RecId FROM Tmp_MotiveP;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Motiv &quot;&apos;||denmotiv||&apos;&quot;&apos; INTO aDoc FROM MotiveP WHERE codmotiv = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;MotiveP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    UPDATE MotiveP SET (
      CodMotiv,
      DenMotiv,
      Motiv
    ) = (
      SELECT
        CodMotiv,
        DenMotiv,
        Motiv
      FROM Tmp_MotiveP
    )
    WHERE CodMotiv = RecId;
  else  -- INSERT
    SELECT Seq_MotiveP_CodMotiv.NextVal INTO RecId FROM DUAL;
    INSERT INTO MotiveP (
      CodMotiv,
      DenMotiv,
      Motiv
    )(
      SELECT
        RecId,
        DenMotiv,
        Motiv
      FROM Tmp_MotiveP
    );
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Motiv &quot;&apos;||denmotiv||&apos;&quot;&apos; INTO aDoc FROM MotiveP WHERE codmotiv = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;MotiveP&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end if;

  NotifyModif(OPERATION, RECID, &apos;MOTIVEP&apos;);

  COMMIT;
end;

end PKG_MOTIVEP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>73773EC5D4E1AB99B73CA3B98126157F15019C33</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NC IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_40&apos;;

FUNCTION VALOARE_GRUP_VALUTA(aVALGRUP IN NUMBER, aVALOARE IN NUMBER, aVALOARE_VALUTA IN NUMBER) RETURN NUMBER
IS
 aCURS NUMBER(20, 7) ;
BEGIN
  IF NVL(aVALOARE_VALUTA, 0) = 0 THEN RETURN 0;
  ELSE
    aCURS := NVL(aVALOARE, 0) / aVALOARE_VALUTA;

    IF aCURS = 0 THEN aCURS := 1; END IF;

    RETURN NVL(aVALGRUP, 0) / aCURS;
  END IF;
END;


PROCEDURE SP_POSTRECORDS_FROM_IMPORT(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod NUMBER(20);
  NR   NUMBER(20) := 0;
BEGIN
  -- Master NC
  SELECT SEQ_NC_CODNC.NEXTVAL INTO RECId FROM DUAL;

  INSERT INTO NC (
    CodNC, NrDoc, DataDoc, Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, An, Luna, Subunitatea, 
    UserId, DataCreare, Sablon, CarnetDoc, CodAnaliza)
  SELECT
    RecId ,NrDoc, DataDoc, Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, An, Luna, Subunitatea, 
    pkg_globals.UserId, systimestamp, Sablon, CarnetDoc, CodAnaliza
  FROM TMP_NC;

  -- Detail NC1 corectie An, Luna
  UPDATE TMP_NC1 SET (An, Luna) = (SELECT N.An, N.Luna FROM TMP_NC N) WHERE An IS NULL OR Luna IS NULL;     

  -- Detail NC1
  FOR v_rec IN ( SELECT * FROM TMP_NC1 ORDER BY INDEXLOCAL ) LOOP
    SELECT SEQ_NC1_CODNC1.NEXTVAL INTO vCod FROM DUAL;
    UPDATE TMP_GENERAL SET CODDOC = vCod WHERE CODDOC = v_rec.CODNC1;

    INSERT INTO NC1 (
      INDEXLOCAL, PartD, PersD, PartC, PersC, CODPART, CODMIFIX, MFSaft, CODCMDINT1, CODNC1, CODNC, CONTD, CONTC, ICONTD, ICONTC, TIPLINIETVA,
      VALOARE, OBS, CODGEST, CODFORMATIE, AN, LUNA )
    VALUES (
      v_rec.INDEXLOCAL, v_rec.PartD, v_rec.PersD, v_rec.PartC, v_rec.PersC,V_REC.CODPART, V_REC.CODMIFIX, V_REC.MFSaft, V_REC.CODCMDINT1, vCod, RecID, v_rec.CONTD, v_rec.CONTC, V_REC.ICONTD, V_REC.ICONTC, V_REC.TIPLINIETVA,
      v_rec.VALOARE, v_rec.OBS, v_rec.CODGEST, V_REC.CODFORMATIE, v_rec.AN, v_rec.LUNA);
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO VCOD FROM DUAL;
    UPDATE TMP_OBLIGPIF SET CODGENERAL = vCod WHERE CODGENERAL = v_rec.CODGENERAL;
    INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
    VALUES (vCOD, V_REC.TIPDOC, V_REC.CODDOC, V_REC.MONEDA, V_REC.CURS, V_REC.SEMNIFICATIE);
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF ) LOOP
    IF V_REC.CODOBLIGPIF &lt; 0 THEN
      SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;
    ELSE
      VCOD := V_REC.CODOBLIGPIF;
    END IF;

    INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT)
    VALUES (VCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT);
  END LOOP;

  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodNC INTO Tmp FROM NC WHERE CodNC = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
 ACARNETDOC NUMBER (20);
 ANRDOC     NUMBER (20);

 aCodSubunit     NUMBER(20);
 aDataDoc        DATE;
 aDoc            VARCHAR2(200);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  -- mNC --&gt; 35
	PKG_CFGTABLES.EXT_DELETERECORD (recId, 35);
  SELECT SUBUNITATEA,  datadoc, &apos;NC&apos;||nrdoc||&apos;/&apos;||datadoc
  INTO aCodSubunit,aDataDoc,aDoc FROM nc WHERE CODNC = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NC&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
end if;

	DELETE FROM OBLIGPIF WHERE SEMNIFICATIE IN (1200, 1201) AND
  CODGENERAL IN
  (
   SELECT CODGENERAL FROM GENERAL WHERE CODDOC IN (SELECT CODNC1 FROM NC1 WHERE CODNC = RecID)
  );
  DELETE FROM GENERAL WHERE TIPDOC = 35 AND
  CODDOC IN (SELECT CODNC1 FROM NC1 WHERE CODNC = RecID);



  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 35) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD      = RULAJCD  - V_REC.VALOARE,
      RULAJVCD     = RULAJVCD - V_REC.VALOAREV,
      RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC.VALOARE_IFRS,0),
      RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC.VALOAREV_IFRS,0),
      RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC.VALOAREGRUP,0),
      RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - VALOARE_GRUP_VALUTA(NVL(V_REC.VALOAREGRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD      = RULAJCD  - V_REC.VALOARE,
        RULAJVCD     = RULAJVCD - V_REC.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC.VALOARE_IFRS,0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC.VALOAREV_IFRS,0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC.VALOAREGRUP,0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - VALOARE_GRUP_VALUTA(NVL(V_REC.VALOAREGRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC      = RULAJCC  - V_REC.VALOARE,
      RULAJVCC     = RULAJVCC - V_REC.VALOAREV,
      RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC.VALOARE_IFRS,0),
      RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC.VALOAREV_IFRS,0),
      RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC.VALOAREGRUP, 0),
      RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - VALOARE_GRUP_VALUTA(NVL(V_REC.VALOAREGRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))

    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC      = RULAJCC  - V_REC.VALOARE,
        RULAJVCC     = RULAJVCC - V_REC.VALOAREV,
        RULAJC_IFRS  = NVL(RULAJC_IFRS, 0)  - NVL(V_REC.VALOARE_IFRS,0),
        RULAJVC_IFRS = NVL(RULAJVC_IFRS, 0) - NVL(V_REC.VALOAREV_IFRS,0),
        RULAJC_GRUP  = NVL(RULAJC_GRUP, 0)  - NVL(V_REC.VALOAREGRUP,0),
        RULAJVC_GRUP = NVL(RULAJVC_GRUP, 0) - VALOARE_GRUP_VALUTA(NVL(V_REC.VALOAREGRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))

      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 35;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 35;

--  DELETE FROM NC1 WHERE CODNC = RecID;

  FOR V_REC IN
  (SELECT * FROM NC1 N1  WHERE CODNC = RECID)
  LOOP
     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODNC1 = V_REC.CODNC1)
     LOOP

       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

         FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
         LOOP
           UPDATE NCONTRULSUB
           SET
             RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
             RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV
           WHERE
             CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
         END LOOP;


         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

         FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
         LOOP
           UPDATE NCONTRULSUB
           SET
             RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
             RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV
           WHERE
             CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
         END LOOP;

       END LOOP;



       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;


     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODNC1 = V_REC.CODNC1;
     DELETE FROM NC1 WHERE CODNC1 = V_REC.CODNC1;
  END LOOP ;



  BEGIN
    SELECT NRDOC, CARNETDOC INTO aNRDOC, aCARNETDOC FROM NC WHERE CODNC = RECID;
    EXCEPTION WHEN OTHERS THEN
    BEGIN
      aNRDOC := 0; aCARNETDOC := 0;
    END;
  END;

  DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 35);
  DELETE EXPERT  WHERE CODDOC = RecID and TIPDOC = 35;
	DELETE TAXDECL WHERE CODDOC = RECID AND TIPDOC = 35;


  DELETE FROM NC WHERE CodNC = RecId ;

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
  END IF;

  NotifyModif(2, RECID, &apos;NC&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  DELETE NC1_MAN;
  
  -- mNC --&gt; 35
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(35);
  PKG_CFGTABLES.EXT_INSERTRECORD(35);

  INSERT INTO  TMP_NC FIELDS(CodNC, sablon) VALUES (0, 0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCODPART NUMBER(20) := 0;
BEGIN
   -- mNC --&gt; 35
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(35);
  
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
-- Master NC
  INSERT INTO  TMP_NC ( Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, CodNC, NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, sablon, CARNETDOC, Valoarelei, CodAnaliza, Aprobat )
    ( SELECT Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, CodNC, NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, sablon, CARNETDOC, case when Moneda = 0 then nvl(Valoare, 0) else nvl(curs, 1) * nvl(Valoare, 0) end, CodAnaliza,
             coalesce(Aprobat,0)
      FROM NC WHERE CodNC = RecId ) ;

  IF RECID &gt; 0 THEN
    BEGIN
    SELECT NVL(PART, 0) INTO aCODPART FROM TMP_NC;
    EXCEPTION WHEN OTHERS THEN aCODPART := 0;
    END;
  END IF;

-- Detail NC1
  INSERT INTO  TMP_NC1 (
    IndexLocal,
    PartD, PersD,
    PartC,
    PersC,
    CODPART,
    CODMIFIX,
    MFSaft, 
    CODCMDINT1,
    CodNC1,
    CodNC,
    ContD,
    ContC,
    ICONTD,
    ICONTC,
    TIPLINIETVA,
    Valoare,
    Obs,
    CodGest,
    CODFORMATIE,
    SimbolContD,
    SimbolContC,
    CODCENTRU,
    CODAUTO,
    AGENT,
    Codanalizanod,
    Den_gest,
    SimbolCC,
    DenNod,
    DenAgent,
    Den_Part,
    NrInreg,
    Den_formatie
    )
  SELECT
    NC1.IndexLocal,
    NC1.PartD, NC1.PersD,
    NC1.PartC, NC1.PersC,
    NC1.CODPART,
    NC1.CODMIFIX,
    NC1.MFSaft, 
    NC1.CODCMDINT1,
    NC1.CodNC1,
    NC1.CodNC,
    NC1.ContD,
    NC1.ContC,
    NC1.ICONTD,
    NC1.ICONTC,
    NC1.TIPLINIETVA,
    NC1.Valoare,
    NC1.Obs,
    NC1.CodGest,
    NC1.CODFORMATIE,
    CASE
      WHEN NC1.PartD = 1
      THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1200, NC1.ICONTD, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(
              (
              CASE
               WHEN NVL(NC1.CODPART,0) &lt;&gt; 0 THEN NC1.CODPART
               ELSE aCODPART
              END
              ),
              PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
      ELSE CASE
             WHEN PersD = 1
             THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, NC1.ICONTD, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NC1.AGENT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
             ELSE PKG_PLANCONTURI.GETSIMBOLCONT(NC1.CONTD)
           END
    END, -- SimbolContD
    CASE
      WHEN NC1.PartC = 1 THEN
        PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1201, NC1.ICONTC, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(
              (
              CASE
               WHEN NVL(NC1.CODPART,0) &lt;&gt; 0 THEN NC1.CODPART
               ELSE aCODPART
              END
              ),
             PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
      ELSE CASE
             WHEN NC1.PersC = 1
             THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1101, NC1.ICONTC, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(NC1.AGENT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
             ELSE PKG_PLANCONTURI.GETSIMBOLCONT(NC1.CONTC)
           END
    END, -- SimbolContC
    NC1.CODCENTRU,NC1.CODAUTO, NC1.AGENT, NC1.CODANALIZANOD,
    G.DEN_GEST,
    CC.SIMBOL,
    V.DENUMIRE,
    AG.NUME||&apos; &apos;||AG.PRENUME,
    P.DEN_PART,
    AUT.NRINREG,
    F.DEN_FORMATIE
  FROM NC1 NC1
       LEFT JOIN NGEST G ON G.CODGEST = NC1.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NC1.CODCENTRU
       LEFT JOIN V_NoduriAnaliza V ON V.CODANALIZANOD = NC1.CODANALIZANOD
       LEFT JOIN NPERS AG ON AG.CODPERS = NC1.AGENT
       LEFT JOIN NPART P ON P.CODPART = NC1.CODPART
       LEFT JOIN NPARCAUT AUT ON AUT.CODNPARCAUT = NC1.CODAUTO
       LEFT JOIN FORMATII F ON F.CODFORMATIE = NC1.CODFORMATIE
  WHERE NC1.CodNC = RecId
  ORDER BY NC1.INDEXLOCAL ;

  update tmp_nc1 set
    IdentifLinie = SimbolContD||&apos; = &apos;||SimbolContC||&apos; - Valoare : &apos;||Valoare;

  INSERT INTO TMP_CMDAPROBARI
  SELECT * FROM CMDAPROBARI WHERE CODDOC = RECID AND TIPDOC = 35;

 -- GENERAL
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
  (SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG FROM GENERAL WHERE TIPDOC = 35 AND CODDOC IN (SELECT CODNC1 FROM TMP_NC1));

-- OBLIGPIF
  INSERT INTO TMP_OBLIGPIF
  (CODOBLIGPIF,CODGENERAL,TERMEN, VALOARE,REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODCENTRU, CODANALIZANOD)
  (SELECT CODOBLIGPIF,CODGENERAL,TERMEN, VALOARE,REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODCENTRU, CODANALIZANOD FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));

  UPDATE TMP_OBLIGPIF OB
  SET
  CODTREZOR1 = (SELECT CODDOC FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL);

   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 35 AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 35 AND CODDOC = RECID);

   DELETE TMP_RULAJ;

   UPDATE TMP_NC1 N1
   SET
     FARAREG = (SELECT FARAREG FROM TMP_GENERAL WHERE CODDOC = N1.CODNC1 AND ROWNUM = 1);

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF)
  LOOP
    UPDATE TMP_NC1
    SET
      TERMEN = V_REC.TERMEN
    WHERE
      CODNC1 = V_REC.CODTREZOR1;
  END LOOP;


  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL SELECT * FROM TMP_OBLIGPIF;

  UPDATE TMP_NC1 I1
  SET
     INFOMF      = CASE
                   WHEN NVL(I1.CODMIFIX, 0) &lt;&gt; 0 THEN
                    (SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE
                     FROM MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NARTOBJ O
                      WHERE MF.CODMIFIX = I1.CODMIFIX
                        AND MF.CODMIFIX = MF1.CODMIFIX
                        AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                        AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                        AND O.CODOBIECT = NS.CODOBIECT)
                   ELSE NULL
                 END
   WHERE
     NVL(CODMIFIX, 0) &lt;&gt; 0;

  UPDATE TMP_NC1 I1
  SET
     INFOMFSAFT  = CASE
                   WHEN NVL(I1.MFSaft, 0) &lt;&gt; 0 THEN
                    (SELECT MF.NRINVENTAR || &apos;/&apos; || O.DENUMIRE
                     FROM MIFIX MF, MIFIX1 MF1, NIRSTOC NS, NARTOBJ O
                      WHERE MF.CODMIFIX = I1.MFSaft
                        AND MF.CODMIFIX = MF1.CODMIFIX
                        AND MF1.ANSTART * 12 + MF1.LUNASTART = PKG_GLOBALS.ANLUCRU * 12 +  PKG_GLOBALS.LUNALUCRU
                        AND NS.CODNIRSTOC = MF1.CODNIRSTOC
                        AND O.CODOBIECT = NS.CODOBIECT)
                   ELSE NULL
                 END
   WHERE
     NVL(MFSaft, 0) &lt;&gt; 0;

  UPDATE TMP_NC1 N1
  SET
    CMDINT = (SELECT
                NRDOC
              FROM
                 COMANDA C, COMANDA1 C1
              WHERE
                 C1.CODCOMANDA1 = N1.CODCMDINT1 AND C.CODCOMANDA = C1.CODCOMANDA
             );


  DELETE NC1_MAN;
  INSERT INTO NC1_MAN(CODNC1) SELECT CODNC1 FROM TMP_NC1;
  -- mNC --&gt; 35
  PKG_CFGTABLES.EXT_GOTORECORD(35);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod       NUMBER(20);
NR         NUMBER(20) := 0;
aCARNETDOC NUMBER(20) := 0;
aNRDOC     NUMBER(20) := 0;
aMONEDA    NUMBER(20) := 0;
aSubunitatea NUMBER(20);
aDataDoc     DATE;
aDoc         VARCHAR2(200);
aCURS        NUMBER(20, 7);
NRCHELT      NUMBER(20) := 0;
aAn          NUMBER(4);
aLuna        NUMBER(2);
aCount       NUMBER(5);
BEGIN
BEGIN
  -- mNC --&gt; 35
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (35);
  
  SELECT CARNETDOC,NRDOC,CURS,NVL(MONEDA,0),CodNC,subunitatea,datadoc,&apos;NC&apos;||nrdoc||&apos;/&apos;||datadoc,An,Luna
  INTO aCARNETDOC,aNRDOC,aCURS,aMONEDA,RecId,aSubunitatea,aDataDoc,aDoc,aAn,aLuna
  FROM TMP_NC;
  IF NVL(aCURS, 0) = 0 THEN aCURS := 1; END IF;

  IF aMONEDA = 0 THEN
    aCURS := 1;
  END IF;

  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    delete tmp_manevra_intr1;
  end if;

  -- Detail NC1 corectie An, Luna
  UPDATE TMP_NC1 SET (An, Luna) = (SELECT N.An, N.Luna FROM TMP_NC N) WHERE An IS NULL OR Luna IS NULL;     

  IF Operation = 0 THEN  -- UPDATE
    -- Master NC
   IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
     WINMADMIN.PKG_USERFIRME.PostLog(&apos;NC&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;,
                                     RECID,PKG_GLOBALS.FIRMANAME,
                                     aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
   END IF;

      UPDATE NC SET ( Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, NrDoc, DataDoc, An, Luna, SUBUNITATEA, sablon, CARNETDOC, CodAnaliza, Aprobat )
         = ( SELECT Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, NrDoc, DataDoc, AN, Luna, SUBUNITATEA, sablon, CARNETDOC, CodAnaliza, aprobat
            FROM TMP_NC )
      WHERE CodNC = RecId ;


      DELETE FROM OBLIGPIF WHERE CODGENERAL IN
      ( SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 35 AND CODDOC IN
       (SELECT CODNC1 FROM NC1 WHERE CODNC = RecID)
      ) AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

      DELETE FROM GENERAL
      WHERE
        TIPDOC = 35 AND CODDOC IN (SELECT CODNC1 FROM NC1 WHERE CODNC = RecID) AND
        CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);

  -- Detail NC1
  -- DELETE FROM NC1 WHERE  CodNC = RecId AND CodNC1 NOT IN ( SELECT CodNC1 FROM TMP_NC1);

      FOR V_REC IN (SELECT * FROM NC1 WHERE  CodNC = RecId AND CodNC1 NOT IN ( SELECT CodNC1 FROM TMP_NC1))
      LOOP
        FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODNC1 = V_REC.CODNC1)
        LOOP
          FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
            UPDATE NCONTRUL
            SET
              RULAJCD      = RULAJCD      - V_RECJURN.VALOARE,
              RULAJVCD     = RULAJVCD     - V_RECJURN.VALOAREV,
              RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
              RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS,
              RULAJC_GRUP  = RULAJC_IFRS  - V_RECJURN.VALOAREGRUP,
              RULAJVC_GRUP = RULAJVC_GRUP - VALOARE_GRUP_VALUTA(NVL(V_RECJURN.VALOAREGRUP,0), NVL(V_RECJURN.VALOARE,0), NVL(V_RECJURN.VALOAREV,0))
            WHERE
              CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

            UPDATE NCONTRUL
            SET
              RULAJCC      = RULAJCC      - V_RECJURN.VALOARE,
              RULAJVCC     = RULAJVCC     - V_RECJURN.VALOAREV,
              RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
              RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS,
              RULAJC_GRUP  = RULAJC_GRUP  - V_RECJURN.VALOAREGRUP,
              RULAJVC_GRUP = RULAJVC_GRUP - VALOARE_GRUP_VALUTA(NVL(V_RECJURN.VALOAREGRUP,0), NVL(V_RECJURN.VALOARE,0), NVL(V_RECJURN.VALOAREV,0))
            WHERE
              CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
          END LOOP;


          DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
          DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
          DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
          DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
        END LOOP;

        DELETE FROM MASTERCHELTAVANS WHERE CODNC1 = V_REC.CODNC1;
        DELETE FROM NC1 WHERE CODNC1 = V_REC.CODNC1;
      END LOOP;


      FOR v_rec IN ( SELECT * FROM TMP_NC1 ORDER BY INDEXLOCAL) LOOP
        IF v_rec.CODNC1 &lt; 0 THEN
          SELECT SEQ_NC1_CODNC1.NEXTVAL INTO vCod FROM DUAL;
          UPDATE TMP_GENERAL SET CODDOC = vCod WHERE CODDOC = v_rec.CODNC1;

          UPDATE TMP_JURNAL  SET INDEXLOCAL = vCod WHERE INDEXLOCAL = v_rec.CODNC1;
          UPDATE TMP_JURNAL1 SET INDEXLOCAL = vCod WHERE INDEXLOCAL = v_rec.CODNC1;
          PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NC1&apos;, vCod, V_REC.CODNC1);

          INSERT INTO NC1 (
            PartD, PersD, PartC, PersC,CODPART, CODMIFIX, MFSaft, CODCMDINT1, CODNC1, CODNC, CONTD, CONTC, 
            ICONTD, ICONTC, TIPLINIETVA, VALOARE, 
            RESTIMBMF,
            OBS, CODGEST, CODFORMATIE, AN, LUNA, INDEXLOCAL, CODCENTRU, CODAUTO, AGENT, CODANALIZANOD )
          VALUES (
            v_rec.PartD, v_rec.PersD, v_rec.PartC, v_rec.PersC, V_REC.CODPART, V_REC.CODMIFIX, V_REC.MFSaft, V_REC.CODCMDINT1, vCod, RecID, v_rec.CONTD, v_rec.CONTC, 
            v_rec.ICONTD, v_rec.ICONTC, V_REC.TIPLINIETVA, v_rec.VALOARE,
            CASE
              WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 THEN V_REC.VALOARE * aCURS
              ELSE 0
            END,
            v_rec.OBS, v_rec.CODGEST, V_REC.CODFORMATIE, v_rec.AN, v_rec.LUNA, v_rec.INDEXLOCAL, V_REC.CODCENTRU, V_REC.CODAUTO, V_REC.AGENT,
            v_rec.codanalizanod);
          if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 
          and v_rec.codmifix &gt; 0 then
            for v_xxx in (select mfix1.codnirstoc
                          from mifix1 mfix1
                          where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
              insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
              values(vCod, v_xxx.codnirstoc, v_rec.valoare * aCurs);
              exit;
            end loop;
          end if;
        ELSE
         -- VERIFIC DACA NU S-AU RUPT LEGATURUILE CU CHELTAVANS;
          IF PKG_CATEGCONST.ESTECHELTAVANS(V_REC.CONTD) + PKG_CATEGCONST.ESTEVENITAVANS(V_REC.CONTD) + PKG_CATEGCONST.ESTECHELTAVANS(V_REC.CONTC) + PKG_CATEGCONST.ESTEVENITAVANS(V_REC.CONTC) = 0 THEN
            SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODNC1 = V_REC.CODNC1;
            IF NR &gt; 0 THEN
              FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODNC1 = V_REC.CODNC1)
              LOOP
                FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
                  UPDATE NCONTRUL
                  SET
                    RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
                    RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV,
                    RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
                    RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS,
                    RULAJC_GRUP  = RULAJC_GRUP  - V_RECJURN.VALOAREGRUP,
                    RULAJVC_GRUP = RULAJVC_GRUP - VALOARE_GRUP_VALUTA(NVL(V_RECJURN.VALOAREGRUP,0), NVL(V_RECJURN.VALOARE,0), NVL(V_RECJURN.VALOAREV,0))
                  WHERE
                    CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

                  UPDATE NCONTRUL
                  SET
                    RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
                    RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV,
                    RULAJC_IFRS  = RULAJC_IFRS  - V_RECJURN.VALOARE_IFRS,
                    RULAJVC_IFRS = RULAJVC_IFRS - V_RECJURN.VALOAREV_IFRS,
                    RULAJC_GRUP  = RULAJC_GRUP  - V_RECJURN.VALOAREGRUP,
                    RULAJVC_GRUP = RULAJVC_GRUP - VALOARE_GRUP_VALUTA(NVL(V_RECJURN.VALOAREGRUP,0), NVL(V_RECJURN.VALOARE,0), NVL(V_RECJURN.VALOAREV,0))
                  WHERE
                    CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
                END LOOP;

                DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN(52, 106);
                DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN(52, 106);
                DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
                DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
              END LOOP;
              DELETE FROM MASTERCHELTAVANS WHERE CODNC1 = V_REC.CODNC1;
            END IF;
          END IF;



          UPDATE NC1 SET
            PartD       = v_rec.PartD,
            PartC       = v_rec.PartC,
            PersD       = v_rec.PersD,
            PersC       = v_rec.PersC,
            CODPART     = V_REC.CODPART,
            CODMIFIX    = V_REC.CODMIFIX,
            MFSaft      = V_REC.MFSaft,  
            CODCMDINT1  = V_REC.CODCMDINT1,
            RestIMBMF   = CASE
                            WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0
                            THEN v_rec.VALOARE * aCURS -
                              (SELECT NVL(SUM(IL.CANT), 0)
                               FROM
                                 IMBMIFIXLINK IL
                                 LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                                 LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                               WHERE
                                 IL.CODNC1 = v_Rec.CodNC1 AND T.OPERAT = 1 AND T.ANULAT = 0
                              )
                            ELSE 0
                         END,
            CODNC1      = v_rec.CODNC1,
            CODNC       = v_rec.CODNC,
            CONTD       = v_rec.CONTD,
            CONTC       = v_rec.CONTC,
            ICONTD      = v_rec.ICONTD,
            ICONTC      = v_rec.ICONTC,
            TIPLINIETVA = v_rec.TIPLINIETVA,
            VALOARE     = v_rec.VALOARE,
            OBS         = v_rec.OBS,
            CODGEST     = v_rec.CODGEST,
            CODFORMATIE = V_REC.CODFORMATIE,
            INDEXLOCAL  = v_rec.INDEXLOCAL,
            CODCENTRU   = V_REC.CODCENTRU,
            CODAUTO     = V_REC.CODAUTO,
            AGENT       = V_REC.AGENT,
            CODANALIZANOD = v_rec.codanalizanod
          WHERE CODNC1  = v_rec.CODNC1;
        END IF;
      END LOOP;

      DELETE FROM CMDAPROBARI A WHERE CODDOC = RECID AND TIPDOC = 35
      AND NOT EXISTS(SELECT COD FROM TMP_CMDAPROBARI WHERE COD = A.COD);

      FOR V_REC IN (SELECT * FROM TMP_CMDAPROBARI)
      LOOP
       IF V_REC.COD &lt; 0 THEN
          INSERT INTO CMDAPROBARI(COD,  CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
          VALUES (SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, 35, V_REC.NIVEL, V_REC.STARE, V_REC.OBS, V_REC.USERID);
        ELSE
          UPDATE CMDAPROBARI
          SET
            NIVEL  = V_REC.NIVEL,
            STARE  = V_REC.STARE,
            USERID = V_REC.USERID,
            OBS    = V_REC.OBS
          WHERE
            COD = V_REC.COD;
        END IF;
      END LOOP;
    
  -- detail GENERAL
      FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
       IF v_rec.CODGENERAL &lt; 0 THEN
         SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO VCOD FROM DUAL;
         UPDATE TMP_OBLIGPIF SET CODGENERAL = vCod WHERE CODGENERAL = v_rec.CODGENERAL;
         INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, FARAREG)
         VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.SEMNIFICATIE, V_REC.FARAREG);
       ELSE
        UPDATE GENERAL
        SET
          TIPDOC       = v_rec.TIPDOC,
          CODDOC       = v_rec.CODDOC,
          MONEDA       = v_rec.MONEDA,
          CURS         = v_rec.CURS,
          SEMNIFICATIE = v_rec.SEMNIFICATIE,
          FARAREG      = V_REC.FARAREG
        WHERE
          CODGENERAL = v_rec.CODGENERAL;
       END IF;
      END LOOP;


  -- detail OBLIGPIF
       FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ) LOOP
         IF v_rec.CODOBLIGPIF &gt; 0  THEN
           UPDATE OBLIGPIF
           SET
             CODGENERAL         = v_rec.CODGENERAL,
             TERMEN             = v_rec.TERMEN,
             VALOARE            = v_rec.VALOARE,
             REST               =
             (
              CASE
                WHEN v_rec.VALOARE &gt; 0 THEN v_rec.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
                WHEN v_rec.VALOARE &lt; 0 THEN v_rec.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = v_rec.CODOBLIGPIF), 0)
              END),

             CODPART            = v_rec.CODPART,
             ICONT              = v_rec.ICONT,
             TIPPLATA           = v_rec.TIPPLATA,
             MAJORARI           = v_rec.MAJORARI,
             SEMNIFICATIE       = v_rec.SEMNIFICATIE,
             TIP                = v_rec.TIP,
             CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
             CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
             CODCENTRU          = v_rec.CODCENTRU,
             CODANALIZANOD      = v_rec.codanalizanod
           WHERE
             CODOBLIGPIF = v_rec.CODOBLIGPIF;
         ELSE
           SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

           INSERT INTO OBLIGPIF
           (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP,
                                                            CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODCENTRU, CODANALIZANOD)
           VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP,
                                                             v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
         END IF;
       END LOOP;




-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = 35 AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    CODANALIZANOD = v_rec.CODANALIZANOD,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    VALOAREGRUP   = V_REC.VALOAREGRUP
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (
     CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD,
     CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC,
     CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV,
     OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT,
     VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP )
   VALUES (
     SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD,
     V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC,
     V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV,
     V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, v_rec.CODCENTRU, v_rec.CODANALIZANOD, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.VALOAREGRUP);
 END IF;
END LOOP;


-- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 35 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
        CODDOC       = V_REC.CODDOC,
        TIPDOC       = V_REC.TIPDOC,
        INDEXLOCAL   = V_REC.INDEXLOCAL,
        CONTD        = V_REC.CONTD,
        CONTC        = V_REC.CONTC,
        GEST         = V_REC.GEST,
        VALOARE      = V_REC.VALOARE,
        VALOAREV     = V_REC.VALOAREV,
        OBS          = V_REC.OBS,
        AN           = V_REC.AN,
        LUNA         = V_REC.LUNA,
        SUBUNITATEA  = V_REC.SUBUNITATEA,
        CODCENTRU    = v_rec.CODCENTRU,
        CODANALIZANOD= v_rec.CODANALIZANOD,
        DATADOC      = V_REC.DATADOC,
        DOCUMENT     = V_REC.DOCUMENT,
        VALOARE_IFRS  = V_REC.VALOARE_IFRS,
        VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
        VALOAREGRUP   = V_REC.VALOAREGRUP
      WHERE
        CODJURNAL = V_REC.CODJURNAl;
     ELSE
     INSERT INTO JURNAL(
       CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV,
       OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT,
       VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP)
     VALUES (
       SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV,
       V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, v_rec.CODANALIZANOD, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS,
       V_REC.VALOAREGRUP);
     END IF;
    END LOOP;



  ELSE  -- INSERT
  -- Master NC
    SELECT SEQ_NC_CODNC.NEXTVAL INTO RECId FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NC&apos;, RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

     WINMADMIN.PKG_USERFIRME.PostLog(&apos;NC&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                     RECID,PKG_GLOBALS.FIRMANAME,
                                     aSubunitatea, aDataDoc, aDoc,&apos;-&apos;,PKG_GLOBALS.GET_EXE_VERSION);
   END IF;


    INSERT INTO  NC (
      Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, CodNC, NrDoc, DataDoc, An, Luna, SUBUNITATEA,
      userid,datacreare, sablon, CARNETDOC, CodAnaliza, Aprobat )
    SELECT
      Part, JurnalTVA, TIPTRANZ, TIPTVA, Valoare, Moneda, Curs, Obs, RecId ,NrDoc, DataDoc, An, Luna, SUBUNITATEA,
      pkg_globals.USERID,systimestamp, sablon, CARNETDOC, CodAnaliza, Aprobat
    FROM TMP_NC;


  -- Detail
    FOR v_rec IN ( SELECT * FROM TMP_NC1 ORDER BY INDEXLOCAL ) LOOP
      SELECT SEQ_NC1_CODNC1.NEXTVAL INTO vCod FROM DUAL;
      UPDATE TMP_GENERAL SET CODDOC = vCod WHERE CODDOC = v_rec.CODNC1;
      UPDATE TMP_JURNAL1 SET INDEXLOCAL = vCod WHERE INDEXLOCAL = v_rec.CODNC1;
      UPDATE TMP_JURNAL  SET INDEXLOCAL = vCod WHERE INDEXLOCAL = v_rec.CODNC1;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NC1&apos;, vCod, V_REC.CODNC1);

      INSERT INTO NC1 (
        INDEXLOCAL, PartD, PersD, PartC, PersC, CODPART, CODMIFIX, MFSaft, CODCMDINT1, CODNC1, CODNC, CONTD, CONTC, ICONTD, ICONTC, TIPLINIETVA,
        VALOARE, RESTIMBMF, OBS, CODGEST, CODFORMATIE, AN, LUNA, CODCENTRU, CODAUTO, AGENT, CODANALIZANOD )
      VALUES (
        v_rec.INDEXLOCAL, v_rec.PartD, v_rec.PersD, v_rec.PartC, v_rec.PersC,V_REC.CODPART, V_REC.CODMIFIX, V_REC.MFSaft, V_REC.CODCMDINT1, vCod, RecID, v_rec.CONTD, v_rec.CONTC, V_REC.ICONTD, V_REC.ICONTC, V_REC.TIPLINIETVA,
        v_rec.VALOARE,
        CASE
          WHEN NVL(V_REC.CODMIFIX, 0) &lt;&gt; 0 THEN V_REC.VALOARE * aCURS
          ELSE 0
        END,
        v_rec.OBS, v_rec.CODGEST, V_REC.CODFORMATIE, v_rec.AN, v_rec.LUNA,V_REC.CODCENTRU,V_REC.CODAUTO, V_REC.AGENT,
        v_Rec.Codanalizanod);
      if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 and v_rec.codmifix &gt; 0 then
        for v_xxx in (select mfix1.codnirstoc
                      from mifix1 mfix1
                      where mfix1.codmifix = v_rec.codmifix and mfix1.anstart * 12 + mfix1.lunastart = aAn*12+aLuna) loop
          insert into tmp_manevra_intr1(codintr1, codobiect, pretpredare)
          values(vCod, v_xxx.codnirstoc, v_rec.valoare * aCurs);
          exit;
        end loop;
      end if;
    END LOOP;

    INSERT INTO CMDAPROBARI(COD, CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
    SELECT SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, 35, NIVEL, STARE, OBS, USERID FROM TMP_CMDAPROBARI;

    FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
      SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO VCOD FROM DUAL;
      UPDATE TMP_OBLIGPIF SET CODGENERAL = vCod WHERE CODGENERAL = v_rec.CODGENERAL;
      INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE, FARAREG)
      VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.SEMNIFICATIE, V_REC.FARAREG);
    END LOOP;

      FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ) LOOP
        INSERT INTO OBLIGPIF
        (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP,
                                                                         CONTBANKTRANZACTIE, CODOBLIGASOCIAT, CODCENTRU, CODANALIZANOD)
        VALUES (SEQ_OBLIGPIF_CODOBLIGPIF.NextVal, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.VALOARE, v_rec.CODPART,  v_rec.ICONT,
                                                  v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP,
                                                  v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
      END LOOP;


    INSERT INTO JURNAL1 (
      CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,
      CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA,
      CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT, VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP )
    SELECT
      SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
      CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA,
      CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT, VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP
    FROM TMP_JURNAL1;



    INSERT INTO JURNAL(
      CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT,
      VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP)
    SELECT
      SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT,
      VALOARE_IFRS, VALOAREV_IFRS, VALOAREGRUP
    FROM TMP_JURNAL;
  END IF;

  -- ACTUALIZARE RULAJE CONTURI
   FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
       RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
       RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
       AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;

     UPDATE NCONTRUL
     SET
       RULAJCD       = NVL(RULAJCD,  0)      + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC       = NVL(RULAJCC,  0)      + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD      = NVL(RULAJVCD, 0)      + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC      = NVL(RULAJVCC, 0)      + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
       RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),

       RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),
       RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -VALOARE_GRUP_VALUTA(NVL(V_REC.VALOARE_GRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
                                                                          ELSE  VALOARE_GRUP_VALUTA(NVL(V_REC.VALOARE_GRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
                                                END
                                               )

     WHERE
       CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;

         UPDATE NCONTRULSUB
         SET
           RULAJCD       = NVL(RULAJCD, 0)  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC       = NVL(RULAJCC, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD      = NVL(RULAJVCD, 0) + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC      = NVL(RULAJVCC, 0) + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJC_IFRS   = NVL(RULAJC_IFRS, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_IFRS, 0) ELSE NVL(V_REC.VALOARE_IFRS, 0) END),
           RULAJVC_IFRS  = NVL(RULAJVC_IFRS, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOAREV_IFRS, 0) ELSE NVL(V_REC.VALOAREV_IFRS, 0) END),

           RULAJC_GRUP   = NVL(RULAJC_GRUP, 0)   + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -NVL(V_REC.VALOARE_GRUP, 0) ELSE NVL(V_REC.VALOARE_GRUP, 0) END),
           RULAJVC_GRUP  = NVL(RULAJVC_GRUP, 0)  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN -VALOARE_GRUP_VALUTA(NVL(V_REC.VALOARE_GRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
                                                                              ELSE  VALOARE_GRUP_VALUTA(NVL(V_REC.VALOARE_GRUP,0), NVL(V_REC.VALOARE,0), NVL(V_REC.VALOAREV,0))
                                                    END
                                                   )

         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;

   END LOOP;

   IF NVL(aCARNETDOC,0) &lt;&gt; 0 THEN
     PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
   END IF;

----
   SELECT COUNT(*) INTO NR FROM TMP_OREPONTAJ;
   IF NR &gt; 0 THEN
     DELETE FROM OREPONTAJ
     WHERE AN*12+Luna = PKG_GLOBALS.ANLUNALUCRU;

     INSERT INTO OREPONTAJ (CODFORMATIE, CODPERS, ORE, SALAR, AN, LUNA)
     SELECT CODFORMATIE, CodPers, Ore, Salar, pkg_globals.AnLucru, pkg_globals.LunaLucru
     FROM Tmp_Orepontaj;
   END IF;
---
   PKG_GLOBALS.MarkDirtyJurnal;

-- LEGATURI CU CHELTAVANS
   FOR V_REC IN (SELECT * FROM TMP_NC1 WHERE CODNC1 &gt; 0)
   LOOP
     BEGIN
       SELECT COUNT(*) INTO NRCHELT  FROM CHELTAVANS WHERE CODNC1 = V_REC.CODNC1;
       EXCEPTION WHEN OTHERS THEN NRCHELT :=0;
     END;
     IF NRCHELT &gt; 0 THEN
       FOR V_CHELT1 IN (
         SELECT CA1.CODCHELTAVANS1, CA1.CODCHELTAVANS
         FROM CHELTAVANS CA, CHELTAVANS1 CA1
         WHERE CA.CODNC1 = V_REC.CODNC1 AND CA1.CODCHELTAVANS = CA.CODCHELTAVANS AND VALOARE &lt;&gt; V_REC.VALOARE * aCURS
       )
       LOOP
         UPDATE CHELTAVANS1
         SET   VALOARE = V_REC.VALOARE * aCURS
         WHERE CODCHELTAVANS1 = V_CHELT1.CODCHELTAVANS1;

         UPDATE JURNAL1
         SET  DIRTY = 1
         WHERE CODDOC = V_CHELT1.CODCHELTAVANS AND TIPDOC IN (52, 106);
      END LOOP;
     END IF;
   END LOOP;
  -- mNC --&gt; 35
  PKG_CFGTABLES.EXT_POSTRECORDS(35, Operation); 
  NotifyModif(OPERATION, RECID, &apos;NC&apos;);

  COMMIT;
  if PKG_CATEGCONST.GetValConstanta(&apos;MifixExtins&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)  = 1 then
    begin
      select count(*) into aCount from tmp_manevra_intr1;
    exception when others then
      aCount := 0;
    end;
    if aCount &gt; 0 then GenereazaModificareDePretMifix(aDataDoc, aAn, aLuna, aSubunitatea); end if;
  end if;
 EXCEPTION WHEN OTHERS THEN BEGIN
   ROLLBACK;
   RAISE;
 END;
END;
END;

procedure GenereazaModificareDePretMifix(aDataDoc in date, aAn in number, aLuna in number, aSubunitatea in number) is
aCount number(10);
aCodNIR number(20);
aCarnetTransf number(20);
aCarnetLivr number(20);
aSerieTransf VARCHAR2(10);
aSimbolTransf VARCHAR2(10);
aSerieLivr VARCHAR2(10);
aSimbolLivr VARCHAR2(10);
aNrTransf number(20);
aNrLivr number(20);
aCodTransf1 number(20);
aCodLivr1 number(20);
aCodTransf number(20);
begin
  aCarnetTransf := pkg_carnetedoc.GETCARNETTRANSF;
  aCarnetLivr   := pkg_carnetedoc.GETCARNETLIVR;

  if aCarnetTransf = 0 or aCarnetLivr = 0 then return; end if;

  for v_m in (select tmp.codintr1, tmp.pretpredare
              from tmp_manevra_intr1 tmp
              ) loop

  for v_rec in (
    SELECT
      NS.CODOBIECT,
      NS.PRET,
      1 REST,
      NS.RESTUM1,
      NS.RESTUM2,
      NS.TIPDOCACHIZ,
      NS.TIPSERIE,
      NS.UMSEC,
      NS.DATAACHIZ,
      NS.FURN,
      NS.TVA AS TVANEEX,
      NS.PUMAXIMAL,
      NS.CODNIRSTOC,
      NS.PROVIZION,
      NS.PUVAL,
      NS.D1, NS.D2, NS.D3,
      NS.CODGESTPROD,
      NS.CODLOCATIE,
      NS.ROTLEI,
      NS.ROTVALUTA,
      NS.CANTFURN,
      NS.CANTNIR,
      O.DENUMIRE,
      N.GEST,
      IO.CODIOART,
      IO.DIFERENTE,
      IO.PUSTANDARD,
      IO.DIFPRET,
      IO.MG,
      IO.ARETVANEEX,
      NC1.CONTD CONTSERV,
      NC1.CODMIFIX,
      1 Cant,
      NS.PRET - NS.ADAOS AS PRETACHIZ,
      TL.CODTVA,
      TL.PROCENT AS PROCTVA,
      NSE.CODNIRSER,
      NSE.CODSERIE,
      NSE.CODCERTIF,
      NSE.STARE,
      NSE.DATAPROD,
      NSE.OBS,
      NVL(NSE.TG, NS.TG) TG,
      O.ROTUNJIRE,
      v_m.CODINTR1,
      v_m.PRETPREDARE,
      NUM1.PARITATE,
      MFIX.NRINVENTAR
    FROM
      MIFIX1 MFIX1,
      MIFIX MFIX,
      NIRSTOC NS
      LEFT OUTER JOIN NIRSER NSE ON NSE.CODNIRSTOC = NS.CODNIRSTOC,
      NARTOBJ O,
      TMP_NART_LUNA AL,
      TMP_NTVA_LUNA TL,
      TMP_IOART_LUNA IO,
      NIR N,
      NGEST G,
      NC1,
      NUM1
    WHERE
      NC1.CODNC1 = v_m.CODINTR1
      AND MFIX1.CODNIRSTOC = NS.CODNIRSTOC
      AND MFIX.CODMIFIX = NC1.CODMIFIX
      AND NC1.CODMIFIX = MFIX1.CODMIFIX
      AND NS.CODOBIECT = O.CODOBIECT
      AND O.CODARTICOL = AL.CODARTICOL
      AND AL.CODTVA    = TL.CODTVA
      AND NS.CODNIR    = N.CODNIr
      AND NS.CODIOART  = IO.CODIOART
      AND N.GEST = G.CODGEST
      AND NUM1.CODUM1 = NS.UMSEC
      AND MFIX1.ANSTART = aAN AND MFIX1.LUNASTART = aLUNA
    ORDER BY CODOBIECT
    ) loop

    aCodTransf := 0;
    aCodNir := 0;
    aCodTransf1 := 0;
    aCodLivr1 := 0;
    delete tmp_transf;
    delete tmp_transf1;
    delete tmp_nir;
    delete tmp_livr;
    delete tmp_nirstoc;
    delete tmp_livr1;
    delete TMP_NIRSTOC_RECOD;
    DELETE TMP_IMBMIFIXLINK;
    delete tmp_jurnal;
    delete tmp_jurnal1;

    aNrTransf     := pkg_carnetedoc.GETNEXTNRDOC(aCarnetTransf, aSerieTransf, aSimbolTransf);
    aNrLivr       := pkg_carnetedoc.GETNEXTNRDOC(aCarnetLivr, aSerieLivr, aSimbolLivr);

    insert into tmp_transf(codtransf, tipdoc, anulat, blocat, operat, prefixdoc, carnetdoc, nrdoc, datadoc, valdoc, tvadoc, an, luna,
                           tiprepsuplim, subunitatea, tipmodifpret, obs)
    values (0, 13, 0, 0, 1, &apos;PV&apos;, aCarnetTransf, aNrTransf, aDataDoc, (V_REC.PRET + V_REC.PRETPREDARE) * v_rec.rest, 0, aAn, aLuna,
            0, aSubunitatea, 4, &apos;Nr. inventar: &apos;||V_REC.NRINVENTAR||&apos; - &apos;||V_REC.DENUMIRE);
    insert into tmp_livr(codlivr, codtransf, carnetlivr, nrlivr, datalivr, tiplivr, anulat, blocat, operat)
    values (-1, 0, aCarnetLivr, aNrLivr, aDataDoc, 13, 0, 0, 1);

    begin
      select count(*) into aCount from tmp_nir where gest = v_rec.gest;
    exception when others then aCount := 0;
    end;

    if aCount = 0 then
      aCodNIR := aCodNIR - 1;
      insert into tmp_nir(codnir, codtransf, datanir, gest, tipnir, anulat, blocat, operat)
      values (aCodNIR, 0, aDataDoc, v_rec.Gest, 13, 0, 0, 1);
    else
      begin
        select codnir into aCodNIR from tmp_nir where gest = v_rec.gest;
      exception when others then
        aCodNIR := aCodNIR - 1;
        insert into tmp_nir(codnir, codtransf, datanir, gest, tipnir, anulat, blocat, operat)
        values (aCodNIR, 0, aDataDoc, v_rec.Gest, 13, 0, 0, 1);
      end;
    end if;

    aCodTransf1 := aCodTransf1 - 1;
    insert into tmp_transf1(codtransf1, codtransf, indexlocal, tiplinie, umsec, codobiect, pu, cant, tva,
                            codcont, pumaximal, codmifix, paritate)
    values(aCodTransf1, 0, aCodTransf1, &apos;=&apos;, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.PRET + V_REC.PRETPREDARE, v_rec.rest, 0,
           V_REC.CONTSERV, V_REC.PUMAXIMAL, V_REC.CODMIFIX, V_REC.PARITATE);

    insert into tmp_imbmifixlink (codtransf1, codnc1, codmifix, cant)
    values(aCodTransf1, v_rec.codintr1, v_rec.codmifix,V_REC.PRETPREDARE);

    aCodLivr1 := aCodLivr1 - 1;
    insert into tmp_livr1(codlivr1, codlivr, codies1, codnirstoc, cant, codnirser, pmp, umsec, cantrezervat, codcertif, pmpvaluta, pmpdoc, pmpvalutadoc, contintermed,
                          PARITATE)
    values (aCodLivr1, -1, aCodTransf1, v_rec.codnirstoc, 1, v_rec.codnirser, 0, v_rec.umsec, 0, 0, 0, 0, 0, 0,
            V_REC.PARITATE);

    insert into tmp_nirstoc (codnir, codtransf1, codnirstocparinte, cantnir, umsec, codobiect, codioart, pret, adaos, tva, tipserie,
                             codlivr1, rest, procentadaos, supliment, cantfurn, rotlei, rotvaluta, codlocatie, tg, pumaximal,
                             furn, dataachiz, tipdocachiz, codgestprod, subunitatea, d1, d2, d3, puval, provizion, PARITATE)
    values(aCodNIR, aCodTransf1, v_rec.codnirstoc, v_rec.rest, v_rec.umsec, v_rec.codobiect, v_rec.codioart, V_REC.PRET + V_REC.PRETPREDARE,
           V_REC.PRET + V_REC.PRETPREDARE, 0, v_rec.tipserie, aCodLivr1, v_rec.rest, 0, 0, v_rec.rest, v_rec.rotlei, v_rec.rotvaluta,
           v_rec.codlocatie, v_rec.tg, v_rec.pumaximal,
           v_rec.furn, v_rec.dataachiz, v_rec.tipdocachiz, v_rec.codgestprod, aSubunitatea, v_rec.d1, v_rec.d2, v_rec.d3, v_rec.puval, v_rec.provizion,
           V_REC.PARITATE
          );

    INSERT INTO tmp_JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, DIRTY, SUBUNITATEA)
    values (-1, 0, 13, 1, aan, aluna, 1, aSubunitatea);
    INSERT INTO tmp_JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, AN, LUNA, SUBUNITATEA)
    values (-1, 0, 13, aCodTransf1, aAN, aLUNA, aSUBUNITATEa);

    begin
      pkg_miscari_interne.SetSkipMifix(True);
      pkg_miscari_interne.SP_POSTRECORDS(-1, aCodTransf);
      update intrari1 set RestIMBMF =
           CASE
             WHEN TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL(CODMIFIX, 0) &lt;&gt; 0
             THEN Cant * PU -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODINTR1 = v_m.CodINTR1 AND T.OPERAT = 1 AND T.ANULAT = 0
               )
             ELSE 0
           END
       where codintr1 = v_m.codintr1;
      pkg_miscari_interne.SetSkipMifix(False);
    exception when others then
      pkg_miscari_interne.SetSkipMifix(False);
    end;
    update jurnal1 set dirty = 1 where coddoc = aCodTransf and TipDoc = 13;
    update jurnal1 set dirty = 1 where coddoc = v_rec.codmifix and tipdoc = 36 and an*12+luna &gt;= aAn*12+aLuna;
    for v_xxx in (select * from TMP_NIRSTOC_RECOD) loop
      update mifix1 set
        codnirstoc = v_xxx.codnou,
        pret = pret + V_REC.PRETPREDARE
      where codnirstoc = v_rec.codnirstoc and anstart*12+lunastart &gt;= aAn*12+aLuna and codmifix = v_rec.codmifix;
      insert into mastermifix(codnirstoc,
                              codclasif,
                              duratan,
                              duratanf,
                              duratang,
                              codanaliza)
      select v_xxx.codnou, m.codclasif, m.duratan, m.duratanf, m.duratang, m.codanaliza
      from mastermifix m
      where m.codnirstoc = v_rec.codnirstoc;
    end loop;
    update intrari1 set restimbmf = 0 where codintr1 = v_m.codintr1;

    FOR V_xxx IN (SELECT M.CODMIFIX, M1.PRET AS VALOARE
                  FROM
                    MIFIX M,
                    MIFIX1 M1
                  WHERE
                    EXISTS (SELECT CODMIFIX FROM TMP_IMBMIFIXLINK WHERE CODMIFIX = M.CODMIFIX)
                    AND M1.CODMIFIX = M.CODMIFIX
                    AND M1.ANSTART * 12 + M1.LUNASTART &lt;= PKG_GLOBALS.AnLunaLucru
                    AND M1.ANSTART * 12 + M1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 M2 WHERE M2.CODMIFIX = M.CODMIFIX AND M2.ANSTART * 12 + M2.LUNASTART &lt;=  PKG_GLOBALS.AnLunaLucru )
    ) LOOP
      UPDATE MIFIX N1
      SET
        RESTIMBMF = V_xxx.VALOARE  -
               (SELECT NVL(SUM(IL.CANT), 0)
                FROM
                  IMBMIFIXLINK IL
                  LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = IL.CODTRANSF1
                  LEFT OUTER JOIN TRANSF   T ON  T.CODTRANSF  = T1.CODTRANSF
                WHERE
                  IL.CODMIFIX = N1.CODMIFIX AND T.T.OPERAT = 1 AND T.ANULAT = 0)
      WHERE
        CODMIFIX = V_xxx.CODMIFIX;
    END LOOP;

    for v_xxx in (select t.codtransf, t.prefixdoc, t.datadoc, t.nrdoc, t.tipdoc,
                         ns.pret pret_vechi, ns_nou.pret pret_nou, nir.gest gest_vechi, nir_nou.gest gest_nou,
                         t1.cant, t1.codtransf1, t.obs
                  from transf t
                       inner join transf1 t1 on t.codtransf = t1.codtransf
                       inner join imbmifixlink l on t1.codtransf1 = l.codtransf1
                       inner join livr1 l1 on t1.codtransf1 = l1.codies1
                       inner join livr lv on lv.codlivr = l1.codlivr and lv.codtransf = t.codtransf
                       inner join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                       inner join nir on nir.codnir = ns.codnir
                       inner join nirstoc ns_nou on ns_nou.codtransf1 = t1.codtransf1
                       inner join nir nir_nou on ns_nou.codnir = nir_nou.codnir
                  where t.codtransf = aCodTransf and l.codnc1 = v_rec.codintr1
                 ) loop
      begin
        select count(*) into aCount from fisamf where codmifix = v_rec.codmifix;
      exception when others then
        aCount := 0;
      end;
      if aCount &gt; 0 then
        insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
        values(seq_fisamf_codfisamf.nextval, v_rec.codmifix, 3, v_xxx.datadoc, v_xxx.gest_vechi, v_xxx.gest_nou,
               v_xxx.pret_vechi, v_xxx.pret_nou, v_xxx.prefixdoc, v_xxx.nrdoc, v_xxx.cant, v_xxx.codtransf1, v_xxx.tipdoc);
      else
        insert into fisamf(codfisamf, codmifix, codoperatie, dataoperatie, gestsursa, gestdest, preti, prete, prefixdoc, nrdoc, cant, coddoc1, tipdoc)
        values(seq_fisamf_codfisamf.nextval, v_rec.codmifix, 1, v_xxx.datadoc, v_xxx.gest_vechi, v_xxx.gest_nou,
               v_xxx.pret_vechi, v_xxx.pret_nou, v_xxx.prefixdoc, v_xxx.nrdoc, v_xxx.cant, v_xxx.codtransf1, v_xxx.tipdoc);
      end if;
    end loop;
    commit;
  end loop;
  end loop;
end;

END pkg_NC;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B125979EE30ECE1DDC678D051CC1ACE34E2ADFB0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NECESAR IS

procedure UpdateLinieObj(aCodNecesar in number,
                         aCodObiect in number,
                         aAcceptat in number,
                         aAcceptatum1 in number,
                         aPLANIFPER in number,
                         aPLANIFPREC in number,
                         aStoc in number,
                         aStocmin in number,
                         aStocoptim in number,
                         aStocmax in number,
                         aREZERVAT in number,
                         aCC in number,
                         aCF in number,
                         aCIIES in number,
                         aCCPANALA in number,
                         aCIIESPANALA in number,
                         aPMP in number,
                         aValPMP in number,
                         aCFPER in number,
                         aNecesar in number,
                         aCFNext in number,
                         aPlanif in number,
                         aConsum in number,
                         aConsumPrec in number) is
aCount number;                         
begin
  select count(*) into acount from necesarobj where codobiect = acodobiect and codnecesar = acodnecesar; 
  if acount &gt; 0 then 
    update necesarobj 
    set
      Acceptat    = aAcceptat,
      Acceptatum1 = aAcceptatum1,
      PLANIFPER   = aPLANIFPER,
      PLANIFPREC  = aPLANIFPREC,
      Stoc        = aStoc,
      Stocmin     = aStocmin,
      Stocoptim   = aStocoptim,
      Stocmax     = aStocmax,
      REZERVAT    = aREZERVAT,
      CC          = aCC,
      CF          = aCF,
      CFPER       = aCFPER,
      CIIES       = aCIIES,
      CCPANALA    = aCCPANALA,
      CIIESPANALA = aCIIESPANALA,
      PMP         = aPMP,
      ValPMP      = aValPMP,
      Necesar     = aNecesar,
      CFNEXT      = aCFNext,
      PLANIF      = aPlanif,
      CONSUM      = aConsum,
      CONSUMPREC  = aConsumPrec
    where codnecesar = aCodNecesar and codobiect = aCodObiect;
  else
    insert into necesarobj(codnecesar,codobiect,acceptat,acceptatum1,planifper,planifprec,stoc,stocmin,stocoptim,stocmax,rezervat,cc,cf,ciies,ccpanala,ciiespanala,PMP,ValPMP,cfper,necesar,CFNext,planif,
                           consum,consumprec)
    values (aCodNecesar,aCodobiect,aacceptat,aacceptatum1,aplanifper,aplanifprec,astoc,astocmin,astocoptim,astocmax,arezervat,acc,acf,aciies,accpanala,aciiespanala,aPMP,aValPMP,acfper,anecesar,aCFNext,aPlanif,
            aConsum,aConsumPrec); 
  end if;
  
  update necesar n set
  valPMP = (select sum(nvl(nobj.valpmp,0)) from necesarobj nobj where nobj.codnecesar = aCodNecesar)
  where n.codnecesar = aCodnecesar;
  
  commit;
end;                         

procedure POSTNECESAR(RecIdOld in number,aCarnetDoc in number, aNrDoc in number, aSeriaDoc in varchar2, aDataDoc in varchar2, 
                      aObs in varchar2, aSaptamana in number, RecId out number, aTipNecesar in number, aSupliment in number) is
begin
  insert into x(test) values(asupliment);
  
  if RecIdOld = 0 then 
    select seq_necesar_codnecesar.nextval into RecId from dual;
    insert into necesar(codnecesar, carnetdoc, nrdoc, seriadoc, datadoc, obs, Subunitatea, Saptamana, TipNecesar, Supliment,An)
    values (RecId, aCarnetDoc, aNrDoc, aSeriaDoc, to_date(aDataDoc,&apos;dd.mm.yyyy&apos;), aObs, pkg_globals.GETSUBUNITATE_DOC, aSaptamana, aTipNecesar, aSupliment,
            pkg_globals.GetANLUCRU);
  else
    RecId := RecIdOld;
    update necesar set 
    carnetdoc = aCarnetDoc, 
    nrdoc     = aNrDoc, 
    seriadoc  = aSeriaDoc, 
    datadoc   = to_date(aDataDoc,&apos;dd.mm.yyyy&apos;), 
    obs       = aObs,
    Saptamana = aSaptamana,
    TipNecesar = aTipNecesar,
    Supliment = aSupliment
    where codnecesar = RecId;
  end if;
  
  delete from necesardoc ndoc where ndoc.codnecesar = RecId and not exists(select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPLANIFPROD&apos; and tmp.valoare = ndoc.codplanifprod);
  
  insert into necesardoc(codnecesar, codplanifprod)
  select RecId, tmp.valoare
  from tmp_manevra_liste tmp 
  where tmp.filtru = &apos;CODPLANIFPROD&apos; and
        not exists (select ndoc.codplanifprod
                    from necesardoc ndoc
                    where ndoc.Codnecesar = RecId and tmp.valoare = ndoc.codplanifprod);
  if RecIdOld = 0 then
    IF ACARNETDOC &lt;&gt; 0 THEN PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC); END IF;
  end if;
  commit;
end;  

procedure DELETE(RecId in number) is 
ACARNETDOC NUMBER(20);
ANRDOC NUMBER(20);  
begin
  begin
    SELECT
      Nvl(CARNETDOC,0),
      NRDOC
    INTO
      ACARNETDOC,
      ANRDOC
    FROM
      NECESAR
    WHERE
      CODNECESAR = RECID;
  exception when others then 
    acarnetdoc := 0;
    anrdoc := 0;
  end;  
    
  DELETE NECESAROBJ WHERE CODNECESAR = RECID;
  DELETE NECESARDOC WHERE CODNECESAR = RECID;  
  DELETE NECESARCMD WHERE CODNECESAR = RECID;
  DELETE NECESAR WHERE CODNECESAR = RECID;
  
  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;
  COMMIT;
end;  

procedure UPDATECMDEXT(aCodNecesar in number, aField in varchar2, aCodComanda in number) is
Val varchar2(250);
Aux varchar2(250);
aCount number;
begin
  IF pkg_list_struct.TmpExists(&apos;COMANDF&apos;) = 1 THEN
    Val := &apos;Necesar : &apos;;
    begin
      select nrdoc||&apos;/&apos;||to_char(datadoc, &apos;dd.mm.yyyy&apos;) into Aux from necesar where codnecesar = aCodNecesar;
    exception when others then Aux := &apos;&apos;;
    end;
    Val := Val||Aux;
    Val := Val||&apos; Detalieri : &apos;;
    begin
      select string_agg(p.nrdoc||&apos;/&apos;||to_char(p.datadoc,&apos;dd.mm.yyyy&apos;)) into Aux
      from necesardoc n
           inner join planifprod p on p.codplanifprod = n.codplanifprod
      where n.codnecesar = aCodnecesar;
    exception when others then Aux := &apos;&apos;;
    end;
    Val := Val||Aux;
    
    begin
      execute immediate &apos;select count(*) from comandf where codcomanda = &apos;||acodcomanda into aCount;
    exception when others then aCount := 0;
    end;
    if aCount &gt; 0 then 
      begin
        Aux := &apos;update comandf set &apos;||aField||&apos; = &apos;&apos;&apos;||Val||&apos;&apos;&apos; where codcomanda = &apos;||aCodComanda;
        execute immediate Aux;
      exception when others then Aux := &apos;&apos;;
      end;  
    else
      begin
        Aux := &apos;insert into comandf(CodComanda,&apos;||aField||&apos;) values(&apos;||aCodComanda||&apos;,&apos;&apos;&apos;||Val||&apos;&apos;&apos;)&apos;;
        execute immediate Aux;
      exception when others then Aux := &apos;&apos;;
      end;
    end if;  
      
    commit;
  END IF;
end;  

end pkg_necesar; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>611F55774BD8F3AD5E24B0013F2A0F8C2CF0AD1D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NIMOB IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODNIMOB INTO Tmp FROM NIMOB WHERE CODNIMOB = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NIMOB WHERE CODNIMOB = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NIMOB FIELDS(CODNIMOB) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master NIMOB
  INSERT INTO TMP_NIMOB (codnimob, denumire, datastart, datastop)
  SELECT codnimob, denumire, datastart, datastop
  FROM NIMOB
  WHERE codnimob = RecId ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    -- Master NIMOB
    UPDATE NIMOB
    SET (codnimob, denumire, datastart, datastop ) = (SELECT codnimob, denumire, datastart, datastop FROM TMP_NIMOB )
    WHERE codnimob = RecId ;
  ELSE  -- INSERT
-- Master NIMOB
    SELECT SEQ_NIMOB_CODNIMOB.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NIMOB (codnimob, denumire, datastart, datastop)
    SELECT RecId, denumire, datastart, datastop
    FROM TMP_NIMOB ;
  END IF;

  NotifyModif(Operation, RecId, &apos;NIMOB&apos;);
  COMMIT;

END;

END PKG_NIMOB;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NMESERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72221299CCA001CEED9295CF0A9B6D9D6F65F885</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NMESERII IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodMeserie INTO Tmp FROM NMESERII WHERE CodMeserie = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NMESERII WHERE CodMeserie = RecId ;
  NotifyModif(2, RECID, &apos;NMESERII&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NMESERII FIELDS( CodMeserie ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_NMESERII ( CodMeserie, Den_Meserie )
    ( SELECT CodMeserie, Den_Meserie
      FROM NMESERII WHERE CodMeserie = RecId ) ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

  SELECT CodMeserie INTO RecId FROM TMP_NMESERII;

  UPDATE NMESERII SET ( Den_Meserie )
       = ( SELECT Den_Meserie
          FROM TMP_NMESERII )
      WHERE CodMeserie = RecId ;

  ELSE  -- INSERT
  
  SELECT SEQ_NMESERII_CODMESERIE.NextVal INTO RecId FROM DUAL;

  INSERT INTO  NMESERII ( CodMeserie, Den_Meserie )
 ( SELECT  RecId, Den_Meserie
     FROM TMP_NMESERII  ) ;
  END IF;
  
  NotifyModif(OPERATION, RECID, &apos;NMESERII&apos;);  
  COMMIT;
END;  

end pkg_nmeserii; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NMVS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CA78D97D0AD2930937B2CB80B02728AA2FEF2BB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_nmvs is

procedure InsertNMVS(aGTIN in varchar2, aLot in varchar2, aExp in varchar2, aSN in varchar2, aSkemeType in varchar2, aNewCodNMVS out number) is
begin
  select seq_nmvs_codnmvs.nextval into aNewCodNMVS from dual;
  insert into nmvs(codnmvs,gtin,dataexp,lot,sn,skemetype)
  values( aNewCodNMVS,agtin,aexp,alot,asn,aSkemeType);
  commit;
end;

procedure UpdateNMVS(aCodNMVS in number, aRaspuns in varchar2, aCodRaspuns in varchar2, aStatus in varchar2, aMotiv in varchar2, 
                     aFunctie in varchar2, aSkemeType in varchar2, aGLN in varchar2, aNewCodNMVS out number) is
aDataVerif date;
begin
  aNewCodNMVS := aCodNMVS;
  begin
    select coalesce(dataverif, to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;)) into aDataVerif from nmvs where codnmvs = aCodNMVS;
  exception when others then aDataVerif := sysdate;
  end;
  
  if aDataVerif = to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;) then
    update nmvs set dataverif = sysdate, mesaj = araspuns, codmesaj = acodraspuns, status = astatus, motiv = amotiv, userid = pkg_globals.GETUSERID, 
                    codfunctie = aFunctie, GLN = aGLN, subunitatea = pkg_globals.GETSUBUNITATE where codnmvs = acodnmvs;
  else
    select seq_nmvs_codnmvs.nextval into aNewCodNMVS from dual;
    insert into nmvs(codnmvs,userid,subunitatea,dataverif,gtin,dataexp,lot,sn,skemetype,mesaj,codmesaj,status,motiv,codfunctie,gln)
    select aNewCodNMVS,pkg_globals.GETUSERID,pkg_globals.GETSUBUNITATE,sysdate,gtin,dataexp,lot,sn,aSkemeType,aRaspuns,aCodRaspuns,aStatus,aMotiv,aFunctie,agln
    from nmvs where codnmvs = aCodNMVS;
  end if;
  commit;
end;  

PROCEDURE GETRECORDS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER)IS 
NMVSKEY VARCHAR2(10);  
BEGIN
  NMVSKEY := PKG_CATEGCONST.GetValConstanta(&apos;NMVSKey&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  DELETE TMP_NMVS_LOT;
  DELETE TMP_NMVS_SERII;
  
  IF aTIPDOC IN (1, 2, 3, 5) THEN
    INSERT INTO TMP_NMVS_LOT(CODSERIE, CODOBIECT, GTIN, SERIE, DATAEXP, DENUMIRE, CANT)
    SELECT 
      LOT.CODSERIE,
      O.CODOBIECT,
      CASE
        WHEN NVL(NMVSKEY, &apos;1&apos;) = &apos;2&apos; THEN LPAD(O.CODINTERN,14,&apos;0&apos;)
        ELSE  LPAD(O.CODEXTERN,14,&apos;0&apos;)
      END AS GTIN,
      SER.SERIE,
      LOT.DATAEXP,
      O.DENUMIRE,      
      LOT.CANT 
    FROM
      NARTOBJ O,
      NART A,
      NSERII SER, 
      (
      SELECT 
        NS.CODOBIECT,
        NSE.CODSERIE,
        TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;) AS DATAEXP,
        SUM(NSE.CANTNIR) AS CANT 
      FROM
        NIRSER NSE,
        NIRSTOC NS,
        NIR N
      WHERE
        N.TIPNIR = aTIPDOC
        AND N.CODINTR = aCODDOC
        AND N.CODNIR = NS.CODNIR
        AND NSE.CODNIRSTOC = NS.CODNIRSTOC
      GROUP BY NS.CODOBIECT, NSE.CODSERIE,  TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;)
      ) LOT
    WHERE
      LOT.CODOBIECT = O.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(A.CHECKISAUTENTIC, 0) = 1
      AND LOT.CODSERIE = SER.CODSERIE    ;

    
    INSERT INTO TMP_NMVS_SERII(COD, CODSERIE, CODPARINTE, SERIE, RASPUNS, CODRASPUNS, STATUS, DATAVERIF, VERIFICARE, SKEMETYPE, USERID, GLN, MOTIV)
    SELECT 
      S.CODSERIEINTR, 
      S.CODSERIE,
      SER.CODPARINTE,
      SER.SERIE,
      S.RASPUNS,
      S.CODRASPUNS,
      S.STATUS,
      S.DATAVERIF,
      0,
      NVL(S.SCHEMETYPE, &apos;GTIN&apos;),
      S.USERID,
      S.GLN,
      S.MOTIV
    FROM 
      SERIIINTR S,
      NSERII SER
    WHERE
      CODINTR = aCODDOC
      AND S.CODSERIE = SER.CODSERIE;
  END IF;  
  
  IF aTIPDOC = 18 THEN
    INSERT INTO TMP_NMVS_LOT(CODSERIE, CODOBIECT, GTIN, SERIE, DATAEXP, DENUMIRE, CANT)
    SELECT 
      LOT.CODSERIE,
      O.CODOBIECT,
      CASE
        WHEN NVL(NMVSKEY, &apos;1&apos;) = &apos;2&apos; THEN LPAD(O.CODINTERN,14,&apos;0&apos;)
        ELSE LPAD(O.CODEXTERN,14,&apos;0&apos;)
      END AS GTIN,
      SER.SERIE,
      LOT.DATAEXP,
      O.DENUMIRE,      
      LOT.CANT 
    FROM
      NARTOBJ O,
      NART A,
      NSERII SER, 
      (
      SELECT 
        NS.CODOBIECT,
        NSE.CODSERIE,
        TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;) AS DATAEXP,
        SUM(R.REST) AS CANT 
      FROM
        NIRSER NSE,
        NIRSTOC NS,
        REZERVATS R,
        COMANDA1 C1,
        COMANDA C
      WHERE
        C.TIPDOC = aTIPDOC
        AND C.CODCOMANDA = aCODDOC
        AND C1.CODCOMANDA = C.CODCOMANDA
        AND R.CODCOMANDA1 = C1.CODCOMANDA1
        AND R.CODNIRSTOC = NS.CODNIRSTOC
        AND R.CODNIRSER = NSE.CODNIRSER
        AND NSE.CODNIRSTOC = NS.CODNIRSTOC
      GROUP BY NS.CODOBIECT, NSE.CODSERIE,  TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;)
      ) LOT
    WHERE
      LOT.CODOBIECT = O.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(A.CHECKISAUTENTIC, 0) = 1
      AND LOT.CODSERIE = SER.CODSERIE    ;
    
    INSERT INTO TMP_NMVS_SERII(COD, CODSERIE, CODPARINTE, SERIE, RASPUNS, CODRASPUNS, STATUS, DATAVERIF, VERIFICARE, SKEMETYPE, USERID, GLN, MOTIV)
    SELECT 
      S.CODSERIECMD, 
      S.CODSERIE,
      SER.CODPARINTE,
      SER.SERIE,
      S.RASPUNS,
      S.CODRASPUNS,
      S.STATUS,
      S.DATAVERIF,
      0,
      NVL(S.SCHEMETYPE, &apos;GTIN&apos;),
      S.USERID,
      S.GLN,
      S.MOTIV
    FROM 
      SERIICMD S,
      NSERII SER
    WHERE
      CODCOMANDA = aCODDOC
      AND S.CODSERIE = SER.CODSERIE;
  END IF;
  
  IF aTIPDOC IN (14,19,20) THEN
    INSERT INTO TMP_NMVS_LOT(CODSERIE, CODOBIECT, GTIN, SERIE, DATAEXP, DENUMIRE, CANT)
    SELECT 
      LOT.CODSERIE,
      O.CODOBIECT,
      CASE
        WHEN NVL(NMVSKEY, &apos;1&apos;) = &apos;2&apos; THEN LPAD(O.CODINTERN,14,&apos;0&apos;)
        ELSE  LPAD(O.CODEXTERN,14,&apos;0&apos;)
      END AS GTIN,
      SER.SERIE,
      LOT.DATAEXP,
      O.DENUMIRE,      
      LOT.CANT 
    FROM
      NARTOBJ O,
      NART A,
      NSERII SER, 
      (
      SELECT 
        NS.CODOBIECT,
        NSE.CODSERIE,
        TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;) AS DATAEXP,
        SUM(NSE.CANTNIR) AS CANT 
      FROM
        NIRSER NSE,
        NIRSTOC NS,
        LIVR1 L1,
        LIVR L,
        IESIRI1 I1,
        IESIRI I
      WHERE
        I.TIPDOC = aTIPDOC
        AND I.CODIES = aCODDOC
        AND I1.CODIES = I.CODIES
        AND L.CODIES = I.CODIES
        AND L1.CODLIVR = L.CODLIVR
        AND I1.CODIES1 = L1.CODIES1
        AND L1.CODNIRSTOC = NS.CODNIRSTOC
        AND L1.CODNIRSER = NSE.CODNIRSER 
        AND NSE.CODNIRSTOC = NS.CODNIRSTOC
      GROUP BY NS.CODOBIECT, NSE.CODSERIE,  TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;)
      ) LOT
    WHERE
      LOT.CODOBIECT = O.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(A.CHECKISAUTENTIC, 0) = 1
      AND LOT.CODSERIE = SER.CODSERIE    ;

    
    INSERT INTO TMP_NMVS_SERII(COD, CODSERIE, CODPARINTE, SERIE, RASPUNS, CODRASPUNS, STATUS, DATAVERIF, VERIFICARE, SKEMETYPE, USERID, GLN, MOTIV)
    SELECT 
      S.CODSERIEIES, 
      S.CODSERIE,
      SER.CODPARINTE,
      SER.SERIE,
      S.RASPUNS,
      S.CODRASPUNS,
      S.STATUS,
      S.DATAVERIF,
      0,
      NVL(S.SCHEMETYPE, &apos;GTIN&apos;),
      S.USERID,
      S.GLN,
      S.MOTIV
    FROM 
      SERIIIES S,
      NSERII SER
    WHERE
      CODIES = aCODDOC
      AND S.CODSERIE = SER.CODSERIE;
  END IF;
  IF aTIPDOC = 12 THEN
    INSERT INTO TMP_NMVS_LOT(CODSERIE, CODOBIECT, GTIN, SERIE, DATAEXP, DENUMIRE, CANT)
    SELECT 
      LOT.CODSERIE,
      O.CODOBIECT,
      CASE
        WHEN NVL(NMVSKEY, &apos;1&apos;) = &apos;2&apos; THEN LPAD(O.CODINTERN,14,&apos;0&apos;)
        ELSE  LPAD(O.CODEXTERN,14,&apos;0&apos;)
      END AS GTIN,
      SER.SERIE,
      LOT.DATAEXP,
      O.DENUMIRE,      
      LOT.CANT 
    FROM
      NARTOBJ O,
      NART A,
      NSERII SER, 
      (
      SELECT 
        NS.CODOBIECT,
        NSE.CODSERIE,
        TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;) AS DATAEXP,
        SUM(NSE.CANTNIR) AS CANT 
      FROM
        NIRSER NSE,
        NIRSTOC NS,
        LIVR1 L1,
        LIVR L,
        TRANSF1 T1,
        TRANSF T
      WHERE
        T.TIPDOC = aTIPDOC
        AND T.CODTRANSF = aCODDOC
        AND T1.CODTRANSF = T.CODTRANSF
        AND L.CODTRANSF = T.CODTRANSF
        AND L1.CODLIVR = L.CODLIVR
        AND T1.CODTRANSF1 = L1.CODIES1
        AND L1.CODNIRSTOC = NS.CODNIRSTOC
        AND L1.CODNIRSER = NSE.CODNIRSER 
        AND NSE.CODNIRSTOC = NS.CODNIRSTOC
      GROUP BY NS.CODOBIECT, NSE.CODSERIE,  TO_CHAR(NVL(NSE.TG, NS.TG), &apos;YYMMDD&apos;)
      ) LOT
    WHERE
      LOT.CODOBIECT = O.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(A.CHECKISAUTENTIC, 0) = 1
      AND LOT.CODSERIE = SER.CODSERIE;

    
    INSERT INTO TMP_NMVS_SERII(COD, CODSERIE, CODPARINTE, SERIE, RASPUNS, CODRASPUNS, STATUS, DATAVERIF, VERIFICARE, SKEMETYPE, USERID, GLN, MOTIV)
    SELECT 
      S.CODSERIETRANSF, 
      S.CODSERIE,
      SER.CODPARINTE,
      SER.SERIE,
      S.RASPUNS,
      S.CODRASPUNS,
      S.STATUS,
      S.DATAVERIF,
      0,
      NVL(S.SCHEMETYPE, &apos;GTIN&apos;),
      S.USERID,
      S.GLN,
      S.MOTIV
    FROM 
      SERIITRANSF S,
      NSERII SER
    WHERE
      CODTRANSF = aCODDOC
      AND S.CODSERIE = SER.CODSERIE;
  END IF;
  COMMIT;
END;

PROCEDURE POSTRECORDS(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) IS
aCODSERIE NUMBER(20);  
BEGIN
  IF aTIPDOC IN (1,2,3,5) THEN
    DELETE FROM SERIIINTR 
    WHERE
      CODINTR = aCODDOC
      AND CODSERIEINTR NOT IN (SELECT COD FROM TMP_NMVS_SERII);
      
    FOR V_REC_LOT IN (SELECT CODSERIE, CODOBIECT, GTIN, DATAEXP FROM TMP_NMVS_LOT)
    LOOP
      FOR V_REC_SERII IN (SELECT * FROM TMP_NMVS_SERII WHERE CODPARINTE = V_REC_LOT.CODSERIE)
      LOOP
          IF V_REC_SERII.COD &lt; 0 THEN
            
             IF V_REC_SERII.CODSERIE &lt; 0 THEN
               aCODSERIE := PKG_IMPORTALTEAPLICATII.GETSERIEDINLOT(V_REC_SERII.CODPARINTE, V_REC_LOT.CODOBIECT, V_REC_SERII.SERIE); 
             ELSE
               aCODSERIE := V_REC_SERII.CODSERIE;
             END IF;     
                
             INSERT INTO SERIIINTR(CODSERIEINTR, CODINTR, CODOBIECT, CODSERIE, DATAEXP, RASPUNS, STATUS, DATAVERIF, GTIN, CODRASPUNS, SCHEMETYPE, USERID, GLN, MOTIV)
             VALUES (SEQ_SERIIINTR_CODSERIEINTR.NEXTVAL, aCODDOC, V_REC_LOT.CODOBIECT, aCODSERIE, V_REC_LOT.DATAEXP, V_REC_SERII.RASPUNS, V_REC_SERII.STATUS, 
                     V_REC_SERII.DATAVERIF, V_REC_LOT.GTIN, V_REC_SERII.CODRASPUNS, V_REC_SERII.SKEMETYPE, V_REC_SERII.USERID, V_REC_SERII.GLN, V_REC_SERII.MOTIV); 
          
          ELSE
            UPDATE SERIIINTR
            SET
              RASPUNS     = V_REC_SERII.RASPUNS, 
              STATUS      = V_REC_SERII.STATUS, 
              DATAVERIF   = V_REC_SERII.DATAVERIF, 
              GTIN        = V_REC_LOT.GTIN,
              CODRASPUNS  = V_REC_SERII.CODRASPUNS,
              SCHEMETYPE  = V_REC_SERII.SKEMETYPE,
              USERID      = V_REC_SERII.USERID,
              GLN         = V_REC_SERII.GLN,
              MOTIV       = V_REC_SERII.MOTIV
            WHERE
              CODSERIEINTR = V_REC_SERII.COD;
          END IF;    
      END LOOP;  
    END LOOP;  
  END IF; 

  IF aTIPDOC IN (14,19,20) THEN
    DELETE FROM SERIIIES
    WHERE
      CODIES = aCODDOC
      AND CODSERIEIES NOT IN (SELECT COD FROM TMP_NMVS_SERII);
      
    FOR V_REC_LOT IN (SELECT CODSERIE, CODOBIECT, GTIN, DATAEXP FROM TMP_NMVS_LOT)
    LOOP
      FOR V_REC_SERII IN (SELECT * FROM TMP_NMVS_SERII WHERE CODPARINTE = V_REC_LOT.CODSERIE)
      LOOP
          IF V_REC_SERII.COD &lt; 0 THEN
            
             IF V_REC_SERII.CODSERIE &lt; 0 THEN
               aCODSERIE := PKG_IMPORTALTEAPLICATII.GETSERIEDINLOT(V_REC_SERII.CODPARINTE, V_REC_LOT.CODOBIECT, V_REC_SERII.SERIE); 
             ELSE
               aCODSERIE := V_REC_SERII.CODSERIE;
             END IF;     
                
             INSERT INTO SERIIIES(CODSERIEIES, CODIES, CODOBIECT, CODSERIE, DATAEXP, RASPUNS, STATUS, DATAVERIF, GTIN, CODRASPUNS, SCHEMETYPE, USERID, GLN, MOTIV)
             VALUES (SEQ_SERIIIES_CODSERIEIES.NEXTVAL, aCODDOC, V_REC_LOT.CODOBIECT, aCODSERIE, V_REC_LOT.DATAEXP, V_REC_SERII.RASPUNS, 
                     V_REC_SERII.STATUS, V_REC_SERII.DATAVERIF, V_REC_LOT.GTIN, V_REC_SERII.CODRASPUNS, V_REC_SERII.SKEMETYPE, V_REC_SERII.USERID, V_REC_SERII.GLN,
                     V_REC_SERII.MOTIV); 
          
          ELSE
            UPDATE SERIIIES
            SET
              RASPUNS     = V_REC_SERII.RASPUNS, 
              STATUS      = V_REC_SERII.STATUS, 
              DATAVERIF   = V_REC_SERII.DATAVERIF, 
              GTIN        = V_REC_LOT.GTIN,
              CODRASPUNS  = V_REC_SERII.CODRASPUNS,
              SCHEMETYPE  = V_REC_SERII.SKEMETYPE,
              USERID      = V_REC_SERII.USERID,
              GLN         = V_REC_SERII.GLN,
              MOTIV       = V_REC_SERII.MOTIV
            WHERE
              CODSERIEIES = V_REC_SERII.COD;
          END IF;    
      END LOOP;  
    END LOOP;  
  END IF;

  IF aTIPDOC = 18 THEN
    DELETE FROM SERIICMD
    WHERE
      CODCOMANDA = aCODDOC
      AND CODSERIECMD NOT IN (SELECT COD FROM TMP_NMVS_SERII);
    
    FOR V_REC_LOT IN (SELECT CODSERIE, CODOBIECT, GTIN, DATAEXP FROM TMP_NMVS_LOT)
    LOOP
      FOR V_REC_SERII IN (SELECT * FROM TMP_NMVS_SERII WHERE CODPARINTE = V_REC_LOT.CODSERIE)
      LOOP
          IF V_REC_SERII.COD &lt; 0 THEN
             IF V_REC_SERII.CODSERIE &lt; 0 THEN
               aCODSERIE := PKG_IMPORTALTEAPLICATII.GETSERIEDINLOT(V_REC_SERII.CODPARINTE, V_REC_LOT.CODOBIECT, V_REC_SERII.SERIE); 
             ELSE
               aCODSERIE := V_REC_SERII.CODSERIE;
             END IF;     
             INSERT INTO SERIICMD(CODSERIECMD, CODCOMANDA, CODOBIECT, CODSERIE, DATAEXP, RASPUNS, STATUS, DATAVERIF, GTIN, CODRASPUNS, SCHEMETYPE, USERID, GLN, MOTIV)
             VALUES (SEQ_SERIICMD_CODSERIECMD.NEXTVAL, aCODDOC, V_REC_LOT.CODOBIECT, aCODSERIE, V_REC_LOT.DATAEXP, V_REC_SERII.RASPUNS, V_REC_SERII.STATUS, 
                     V_REC_SERII.DATAVERIF, V_REC_LOT.GTIN, V_REC_SERII.CODRASPUNS, V_REC_SERII.SKEMETYPE, V_REC_SERII.USERID, V_REC_SERII.GLN, V_REC_SERII.MOTIV); 
          ELSE
            UPDATE SERIICMD
            SET
              RASPUNS     = V_REC_SERII.RASPUNS, 
              STATUS      = V_REC_SERII.STATUS, 
              DATAVERIF   = V_REC_SERII.DATAVERIF, 
              GTIN        = V_REC_LOT.GTIN,
              CODRASPUNS  = V_REC_SERII.CODRASPUNS,
              SCHEMETYPE  = V_REC_SERII.SKEMETYPE,
              USERID      = V_REC_SERII.USERID,
              GLN         = V_REC_SERII.GLN,
              MOTIV       = V_REC_SERII.MOTIV
            WHERE
              CODSERIECMD = V_REC_SERII.COD;
          END IF;    
      END LOOP;  
    END LOOP;  
  END IF;
  
  IF aTIPDOC = 12 THEN
    DELETE FROM SERIITRANSF
    WHERE
      CODTRANSF = aCODDOC
      AND CODSERIETRANSF NOT IN (SELECT COD FROM TMP_NMVS_SERII);
      
    FOR V_REC_LOT IN (SELECT CODSERIE, CODOBIECT, GTIN, DATAEXP FROM TMP_NMVS_LOT)
    LOOP
      FOR V_REC_SERII IN (SELECT * FROM TMP_NMVS_SERII WHERE CODPARINTE = V_REC_LOT.CODSERIE)
      LOOP
          IF V_REC_SERII.COD &lt; 0 THEN
            
             IF V_REC_SERII.CODSERIE &lt; 0 THEN
               aCODSERIE := PKG_IMPORTALTEAPLICATII.GETSERIEDINLOT(V_REC_SERII.CODPARINTE, V_REC_LOT.CODOBIECT, V_REC_SERII.SERIE); 
             ELSE
               aCODSERIE := V_REC_SERII.CODSERIE;
             END IF;     
                
             INSERT INTO SERIITRANSF(CODSERIETRANSF, CODTRANSF, CODOBIECT, CODSERIE, DATAEXP, RASPUNS, STATUS, DATAVERIF, GTIN, CODRASPUNS, SCHEMETYPE, USERID, GLN, MOTIV)
             VALUES (SEQ_SERIITRANSF_CODSERIETRANSF.NEXTVAL, aCODDOC, V_REC_LOT.CODOBIECT, aCODSERIE, V_REC_LOT.DATAEXP, V_REC_SERII.RASPUNS, 
                     V_REC_SERII.STATUS, V_REC_SERII.DATAVERIF, V_REC_LOT.GTIN, V_REC_SERII.CODRASPUNS, V_REC_SERII.SKEMETYPE, V_REC_SERII.USERID, V_REC_SERII.GLN,
                     V_REC_SERII.MOTIV); 
          
          ELSE
            UPDATE SERIITRANSF
            SET
              RASPUNS     = V_REC_SERII.RASPUNS, 
              STATUS      = V_REC_SERII.STATUS, 
              DATAVERIF   = V_REC_SERII.DATAVERIF, 
              GTIN        = V_REC_LOT.GTIN,
              CODRASPUNS  = V_REC_SERII.CODRASPUNS,
              SCHEMETYPE  = V_REC_SERII.SKEMETYPE,
              USERID      = V_REC_SERII.USERID,
              GLN         = V_REC_SERII.GLN,
              MOTIV       = V_REC_SERII.MOTIV
            WHERE
              CODSERIETRANSF = V_REC_SERII.COD;
          END IF;    
      END LOOP;  
    END LOOP;  
  END IF;
                              
  COMMIT;
END;    


end pkg_nmvs; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B856A1C944FD6DBDD9CF33ABAC39C0A4936480F8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMACTIVIT IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codactivit INTO Tmp FROM NACTIVIT WHERE codactivit = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
AdoC VARCHAR2(100);
BEGIN
  
IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;activitate &quot;&apos;||n.den_activit||&apos;&quot;&apos; INTO aDoc
   FROM NACTIVIT n where N.CODACTIVIT = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NACTIVIT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);  
END IF; 
  
  
  SP_LOCKRECORD(RecId);
	DELETE FROM NACTIVIT WHERE codactivit = RecId ;

  NotifyModif(2, RECID, &apos;NACTIVIT&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NACTIVIT FIELDS( codactivit ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NACTIVIT
  INSERT INTO  TMP_NACTIVIT ( codactivit,den_activit )
    ( SELECT codactivit,den_activit
      FROM NACTIVIT WHERE codactivit = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  
  aDoc VARCHAR2(100);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NACTIVIT
    SELECT  codactivit INTO RecId FROM TMP_NACTIVIT;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;activitate &quot;&apos;||n.den_activit||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NACTIVIT n where N.CODACTIVIT = RECID;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NACTIVIT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;   
   
    UPDATE NACTIVIT SET ( den_activit )
       = ( SELECT den_activit
          FROM TMP_NACTIVIT )
      WHERE codactivit = RecId ;

  ELSE  -- INSERT
-- Master NACTIVIT
  SELECT seq_NACTIVIT_codactivit.NextVal INTO RecId FROM DUAL;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;activitate &quot;&apos;||n.den_activit||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NACTIVIT n ;
   
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NACTIVIT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);  
END IF;


  INSERT INTO  NACTIVIT ( codactivit,den_activit )
 ( SELECT  RecId ,den_activit
     FROM TMP_NACTIVIT  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NACTIVIT&apos;);  

  COMMIT;
END;



END pkg_NomActivit; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMATRIBUTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADD34B82F68D15DF89C73D68D56FC92C2F2908BA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMATRIBUTE IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodAtribut INTO Tmp FROM NATRIB WHERE CodAtribut = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  oldColSuplim VARCHAR2(30);
BEGIN
  SP_LOCKRECORD(RecId);

  FOR V_REC IN (SELECT * FROM NATRIB1 WHERE CODATRIBUT = RECID)
  LOOP
    DELETE FROM VALATREXCEPTII WHERE CODVALATR = V_REC.CODVALATR;
    DELETE FROM NATRIB1 WHERE CodAtribut = V_REC.CODATRIBUT ;
    DELETE FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR;
    DELETE FROM NATRIB1TRAD WHERE CODVALATR = V_REC.CODVALATR;
  END LOOP;

  SELECT Upper(ColSuplim) INTO oldColSuplim FROM NATRIB WHERE CodAtribut = RecId;
  IF oldColSuplim IS NOT NULL THEN
    FOR v_rec IN ( SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;NARTOBJATR&apos; AND COLUMN_NAME = Upper(oldColSuplim)) LOOP
      EXECUTE IMMEDIATE &apos;ALTER TABLE NARTOBJATR DROP COLUMN &apos;||v_rec.COLUMN_NAME;--oldColSuplim;
    END LOOP;
  END IF;
	DELETE FROM NATRIB WHERE CodAtribut = RecId ;

  NotifyModif(2, RECID, &apos;NATRIB&apos;);

 COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NATRIB FIELDS( CodAtribut ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NATRIB
  INSERT INTO  TMP_NATRIB ( CodAtribut,Denumire,TipValoare,Prefix,ColSuplim)
  SELECT CodAtribut,Denumire,TipValoare,Prefix,ColSuplim
  FROM NATRIB
  WHERE CodAtribut = RecId ;

-- Detail NATRIB1
  INSERT INTO  TMP_NATRIB1 ( CodValAtr,CodAtribut,Valoare,Codobiectasoc, Codextern, GRUPA, PROCMAJPU, INACTIV,INACTIVCMDONLINE, MESAJINACTIV,  DenObiectAsoc )
  SELECT a.CodValAtr,a.CodAtribut,a.Valoare,a.Codobiectasoc, a.Codextern, A.GRUPA, A.PROCMAJPU, A.INACTIV, A.INACTIVCMDONLINE, A.MESAJINACTIV, O.DENUMIRE
  FROM NATRIB1 A LEFT JOIN NartObj o ON o.CodObiect  = A.CodObiectAsoc
  WHERE CodAtribut = RecId;

  INSERT INTO TMP_VALATREXCEPTII(CODEXCEPTIE, CODVALATR, CODARTICOL, DENARTICOL,CODEXTERNART )
  SELECT VE.CODEXCEPTIE, VE.CODVALATR, VE.CODARTICOL, DEN_ARTICOL, A.CODEXTERNART
  FROM VALATREXCEPTII VE INNER JOIN NART A ON A.CODARTICOL = VE.CODARTICOL
  WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 WHERE CODVALATR = VE.CODVALATR);

  INSERT INTO TMP_NATRIB2( CODATRIB2,CODVALATR,CODARTICOL,PROCMAJ,DENARTICOL,CODEXTERNART )
  SELECT NA.CODATRIB2,NA.CODVALATR,NA.CODARTICOL,NA.PROCMAJ, DEN_ARTICOL, A.CODEXTERNART
  FROM NATRIB2 NA INNER JOIN NART A ON A.CODARTICOL = NA.CODARTICOL
  WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 WHERE CODVALATR = NA.CODVALATR);

  INSERT INTO TMP_NATRIB1TRAD(CODATRIB1TRAD, CODVALATR, CODLIMBA, MESAJINACTIV,DENUMIRE,DENLIMBA)
  SELECT CODATRIB1TRAD, CODVALATR, CODLIMBA, MESAJINACTIV,DENUMIRE, (SELECT DENLIMBA FROM NLIMBA NL WHERE NL.CODLIMBA = A1T.CODLIMBA)
  FROM NATRIB1TRAD A1T
  WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 A1 WHERE A1.CODVALATR = A1T.CODVALATR);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo       INTEGER := 0;
  vAn          INTEGER := 0;
  vLuna        INTEGER := 0;
  vCod         NUMBER(20);
  aCod         NUMBER(20);
  oldColSuplim VARCHAR2(30);
  newColSuplim VARCHAR2(30);
  vExistTab    INTEGER := 0;
  vExistCol    INTEGER := 0;
  sSQL         VARCHAR2(30000);
  sCond        VARCHAR2(30000);
  sAux         VARCHAR2(30);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    -- Master NATRIB
    SELECT CodAtribut, Upper(ColSuplim) INTO RecId, newColSuplim FROM TMP_NATRIB;
    SELECT             Upper(ColSuplim) INTO        oldColSuplim FROM NATRIB WHERE CodAtribut = RecId;

    UPDATE NATRIB
    SET ( Denumire,TipValoare,Prefix,ColSuplim ) = ( SELECT Denumire,TipValoare,Prefix,ColSuplim FROM TMP_NATRIB )
    WHERE CodAtribut = RecId ;

    -- Detail NATRIB1
    FOR V_REC IN (SELECT *  FROM NATRIB1 WHERE ( CodAtribut = RecId AND CodValAtr NOT IN ( SELECT CodValAtr FROM TMP_NATRIB1 WHERE Coalesce(CodValAtr,0) &lt;&gt; 0))) LOOP
      DELETE FROM VALATREXCEPTII WHERE CODVALATR = V_REC.CODVALATR;
      DELETE FROM NATRIB2        WHERE CODVALATR = V_REC.CODVALATR;
      DELETE FROM NATRIB1        WHERE CodValAtr = V_REC.CODVALATR;
      DELETE FROM NATRIB1TRAD    WHERE CodValAtr = V_REC.CODVALATR;
    END LOOP;

    FOR V_REC IN (SELECT  * FROM TMP_NATRIB1 WHERE CodValAtr &lt; 0) LOOP
      aCOD := seq_NATRIB1_CodValAtr.Nextval;

      UPDATE TMP_VALATREXCEPTII SET CODVALATR = aCOD WHERE CODVALATR = V_REC.CODVALATR;
      UPDATE TMP_NATRIB2        SET CODVALATR = aCOD WHERE CODVALATR = V_REC.CODVALATR;
      UPDATE TMP_NATRIB1TRAD    SET CODVALATR = aCOD WHERE CODVALATR = V_REC.CODVALATR;

      INSERT INTO NATRIB1 ( CodValAtr,CodAtribut,Valoare,Codobiectasoc, Codextern, GRUPA, PROCMAJPU, INACTIV, INACTIVCMDONLINE, MESAJINACTIV )
      VALUES  (aCOD , RecId , V_REC.Valoare, V_REC. Codobiectasoc, V_REC.Codextern, V_REC.GRUPA, V_REC.PROCMAJPU, V_REC.INACTIV, V_REC.INACTIVCMDONLINE, V_REC.MESAJINACTIV);
    END LOOP;

    FOR v_rec IN (
      SELECT * FROM TMP_NATRIB1 WHERE Coalesce(CodValAtr,-1) &gt; 0 ORDER BY CodValAtr
    ) LOOP
      SELECT Count(1) INTO vRecNo FROM NATRIB1 WHERE CodValAtr = Coalesce(v_rec.CodValAtr,0);

      IF(vRecNo=1) THEN
        UPDATE NATRIB1
        SET CodAtribut       = RecId ,
            Valoare          = v_rec.Valoare,
            Codobiectasoc    = V_REC.Codobiectasoc,
            Codextern        = V_REC.Codextern,
            GRUPA            = V_REC.GRUPA,
            PROCMAJPU        = V_REC.PROCMAJPU,
            INACTIV          = V_REC.INACTIV,
            INACTIVCMDONLINE = V_REC.INACTIVCMDONLINE,
            MESAJINACTIV     = V_REC. MESAJINACTIV
        WHERE CodValAtr = v_rec.CodValAtr;
      END IF;
    END LOOP;

    DELETE FROM VALATREXCEPTII VE
    WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 WHERE CODVALATR = VE.CODVALATR)
      AND NOT EXISTS (SELECT CODEXCEPTIE FROM TMP_VALATREXCEPTII WHERE CODEXCEPTIE = VE.CODEXCEPTIE);

    DELETE FROM NATRIB2 NA
    WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 WHERE CODVALATR = NA.CODVALATR)
      AND NOT EXISTS (SELECT CODATRIB2 FROM TMP_NATRIB2 WHERE CODATRIB2 = NA.CODATRIB2);

    DELETE FROM NATRIB1TRAD NA
    WHERE EXISTS (SELECT CODVALATR FROM TMP_NATRIB1 WHERE CODVALATR = NA.CODVALATR)
      AND NOT EXISTS (SELECT CODATRIB1TRAD FROM TMP_NATRIB1TRAD WHERE CODATRIB1TRAD = NA.CODATRIB1TRAD);

    FOR V_REC IN (SELECT * FROM TMP_NATRIB2) LOOP
      IF V_REC.CODATRIB2 &gt; 0 THEN
        UPDATE NATRIB2
        SET CODARTICOL = V_REC.CODARTICOL,
            PROCMAJ    = V_REC.PROCMAJ,
            CODVALATR  = V_REC.CODVALATR
        WHERE CODATRIB2 = V_REC.CODATRIB2;
      ELSE
        INSERT INTO NATRIB2 (CODATRIB2,CODVALATR,CODARTICOL,PROCMAJ)
        VALUES (SEQ_NATRIB2_COD.NEXTVAL, V_REC.CODVALATR, V_REC.CODARTICOL, v_rec.PROCMAJ);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_VALATREXCEPTII) LOOP
      IF V_REC.CODEXCEPTIE &gt; 0 THEN
        UPDATE VALATREXCEPTII
        SET CODARTICOL = V_REC.CODARTICOL,
            CODVALATR  = V_REC.CODVALATR
        WHERE CODEXCEPTIE = V_REC.CODEXCEPTIE;
      ELSE
        INSERT INTO VALATREXCEPTII (CODEXCEPTIE, CODVALATR, CODARTICOL)
        VALUES (SEQ_VALATREXCEPTII_COD.NEXTVAL, V_REC.CODVALATR, V_REC.CODARTICOL);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_NATRIB1TRAD) LOOP
      IF V_REC.CODATRIB1TRAD &gt; 0 THEN
        UPDATE NATRIB1TRAD
        SET CODLIMBA     = V_REC.CODLIMBA,
            MESAJINACTIV = V_REC.MESAJINACTIV,
            DENUMIRE     = V_REC.DENUMIRE
        WHERE CODATRIB1TRAD  = V_REC.CODATRIB1TRAD;
      ELSE
        INSERT INTO NATRIB1TRAD (CODATRIB1TRAD, CODVALATR, CODLIMBA, MESAJINACTIV,DENUMIRE)
        VALUES (SEQ_NATRIB1TRAD_CODATRIB1TRAD.NEXTVAL, V_REC.CODVALATR, V_REC.CODLIMBA, V_REC.MESAJINACTIV,V_REC.DENUMIRE);
      END IF;
    END LOOP;
  ELSE  -- INSERT
    --Master NATRIB
    RecId := SEQ_NATRIB_CodAtribut.NextVal;
    INSERT INTO  NATRIB ( CodAtribut,Denumire,TipValoare,Prefix,ColSuplim)
    SELECT  RecId,Denumire,TipValoare,Prefix,ColSuplim
    FROM TMP_NATRIB ;

    -- Detail NATRIB1
    FOR V_REC IN (SELECT  * FROM TMP_NATRIB1  ) LOOP
      aCOD := seq_NATRIB1_CodValAtr.Nextval;

      UPDATE TMP_VALATREXCEPTII SET CODVALATR = aCOD WHERE CODVALATR = V_REC.CODVALATR;
      UPDATE TMP_NATRIB1TRAD    SET CODVALATR = aCOD WHERE CODVALATR = V_REC.CODVALATR;

      INSERT INTO NATRIB1 ( CodValAtr,CodAtribut,Valoare,Codobiectasoc, Codextern, GRUPA, PROCMAJPU, INACTIV, INACTIVCMDONLINE, MESAJINACTIV )
      VALUES  (aCOD , RecId , V_REC.Valoare, V_REC. Codobiectasoc, V_REC.Codextern, V_REC.GRUPA, V_REC.PROCMAJPU, V_REC.INACTIV, V_REC.INACTIVCMDONLINE, V_REC.MESAJINACTIV);
    END LOOP;

    INSERT INTO NATRIB2 (CODATRIB2,CODVALATR,CODARTICOL,PROCMAJ)
    SELECT SEQ_NATRIB2_COD.NEXTVAL, CODVALATR, CODARTICOL, PROCMAJ FROM TMP_NATRIB2;

    INSERT INTO VALATREXCEPTII (CODEXCEPTIE, CODVALATR, CODARTICOL)
    SELECT SEQ_VALATREXCEPTII_COD.NEXTVAL, CODVALATR, CODARTICOL FROM TMP_VALATREXCEPTII;

    FOR V_REC IN (SELECT * FROM TMP_NATRIB1TRAD)
    LOOP
      INSERT INTO NATRIB1TRAD (CODATRIB1TRAD, CODVALATR, CODLIMBA, MESAJINACTIV,DENUMIRE)
      VALUES (SEQ_NATRIB1TRAD_CODATRIB1TRAD.NEXTVAL, V_REC.CODVALATR, V_REC.CODLIMBA, V_REC.MESAJINACTIV,V_REC.DENUMIRE);
    END LOOP;
  END IF;

  SELECT Count(1) INTO vExistTab FROM USER_TABLES WHERE TABLE_NAME = &apos;NARTOBJATR&apos;;

  IF Coalesce(oldColSuplim,&apos;$&apos;) &lt;&gt; &apos;$&apos; THEN
    SELECT Count(1) INTO vExistCol FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;NARTOBJATR&apos; AND COLUMN_NAME = Upper(oldColSuplim);
    IF vExistCol = 0
    THEN oldColSuplim := &apos;&apos;;
    END IF;
  END IF;

  IF Coalesce(oldColSuplim,&apos;$&apos;) &lt;&gt; Coalesce(newColSuplim,&apos;$&apos;) THEN
    IF    newColSuplim IS NULL THEN -- stergem coloana existenta
      FOR v_rec IN (
        SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;NARTOBJATR&apos; AND COLUMN_NAME = Upper(oldColSuplim)
      ) LOOP
        EXECUTE IMMEDIATE &apos;ALTER TABLE NARTOBJATR DROP COLUMN &apos;||v_rec.COLUMN_NAME;--oldColSuplim;
      END LOOP;

      IF vExistTab &gt; 0 THEN
        SELECT Count(1) INTO vExistCol FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;NARTOBJATR&apos; AND COLUMN_NAME &lt;&gt; &apos;CODOBIECT&apos;;
        IF vExistCol &gt; 0 THEN
          sCond := &apos;&apos;;
          sAux  := &apos; WHERE &apos;;

          FOR vRec IN (SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = &apos;NARTOBJATR&apos; AND COLUMN_NAME &lt;&gt; &apos;CODOBIECT&apos;) LOOP
            sCond := sCond ||sAux||vRec.COLUMN_NAME||&apos; IS NULL&apos;;
            sAux  := &apos; AND &apos;;
          END LOOP;
          EXECUTE IMMEDIATE &apos;DELETE FROM NARTOBJATR &apos;||sCond;
        END IF;
      END IF;
    ELSIF oldColSuplim IS NULL THEN -- coloana noua
      PKG_NOMATRIBUTE.REPARA_NARTOBJATR(2, RecId);
    ELSE -- redenumim coloana
      EXECUTE IMMEDIATE &apos;ALTER TABLE NARTOBJATR RENAME COLUMN &apos;||oldColSuplim||&apos; TO &apos;||newColSuplim;
    END IF;
  END IF;
  NotifyModif(OPERATION, RECID, &apos;NATRIB&apos;);
  COMMIT;
END;

FUNCTION AM_DATE_NARTOBJATR (
  vTip IN NUMBER DEFAULT 0, -- 0 FULL, 1 ARTICOL, 2 ATRIBUT
  vCod IN NUMBER DEFAULT 0
) RETURN NUMBER IS
  cSql    CLOB;
  vResult INTEGER;
BEGIN
  cSql :=
  &apos;SELECT
     CASE
       WHEN EXISTS (
          SELECT 1
          FROM natrobj ao
            INNER JOIN nartobj o  ON o.codobiect  = ao.codobiect
            INNER JOIN natrib1 av ON av.codvalatr = ao.codvalatr
            INNER JOIN natrib a   ON a.codatribut = av.codatribut
            INNER JOIN nartatr aa ON aa.codartatr = ao.codartatr
          WHERE Trim(a.colsuplim) IS NOT NULL &apos;||CASE
                                                   WHEN vTip = 1 THEN &apos; AND o.codarticol = &apos;||To_Char(vCod)
                                                   WHEN vTip = 2 THEN &apos; AND a.codatribut = &apos;||To_Char(vCod)
                                                   ELSE &apos;&apos;
                                                 END||&apos;
       )
       THEN 1
       ELSE 0
      END AmDate
  FROM DUAL&apos;;
  EXECUTE IMMEDIATE cSql INTO vResult;
  RETURN vResult;
END;

PROCEDURE REPARA_NARTOBJATR (
  vTip IN NUMBER DEFAULT 0, -- 0 FULL, 1 ARTICOL, 2 ATRIBUT
  vCod IN NUMBER DEFAULT 0
) IS
  vExistTab NUMBER(1) := 0;
  vExistCol NUMBER(1);
  cSql      CLOB;

  TYPE t_rec_x IS RECORD (codatribut NUMBER(20), colname VARCHAR2(50), existcol NUMBER(1));
  TYPE t_tab_x IS TABLE OF t_rec_x;
  bulk_x t_tab_x;
BEGIN
  SELECT Count(1) INTO vExistTab FROM USER_TABLES WHERE TABLE_NAME = &apos;NARTOBJATR&apos;;
  IF vExistTab = 1 AND vTip = 0 THEN
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP TABLE NARTOBJATR PURGE&apos;;
      vExistTab := 0;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;

  cSql :=
  &apos;SELECT
    a.codatribut, a.COLNAME,
    CASE WHEN b.COLNAME IS NULL THEN 0 ELSE 1 END existcol
  FROM (
    SELECT codatribut, Upper(Trim(colsuplim)) colname FROM natrib WHERE Trim(colsuplim) IS NOT NULL
  ) a LEFT JOIN (
      SELECT column_name colname FROM user_tab_columns WHERE table_name = &apos;&apos;NARTOBJATR&apos;&apos; AND column_name &lt;&gt; &apos;&apos;CODOBIECT&apos;&apos;
    ) b ON b.colname = a.colname
  WHERE EXISTS (
    SELECT 1
    FROM natrobj ao
      INNER JOIN nartobj o  ON o.codobiect  = ao.codobiect
      INNER JOIN natrib1 av ON av.codvalatr = ao.codvalatr
      INNER JOIN nartatr aa ON aa.codartatr = ao.codartatr
    WHERE aa.codatribut = a.CODATRIBUT&apos;||CASE WHEN vTip = 1 THEN &apos; AND o.codarticol = &apos;||To_Char(vCod) ELSE &apos;&apos; END||&apos;
  )&apos;||CASE WHEN vTip = 2 THEN &apos;AND a.codatribut = &apos;||To_Char(vCod) ELSE &apos;&apos; END||&apos;
  ORDER BY 1&apos;;
  EXECUTE IMMEDIATE cSql BULK COLLECT INTO bulk_x;

  IF bulk_x.Count &gt; 0 AND vExistTab = 0 THEN
    EXECUTE IMMEDIATE &apos;CREATE TABLE NARTOBJATR (CODOBIECT NUMBER(20) NOT NULL)&apos;;
    EXECUTE IMMEDIATE &apos;ALTER  TABLE NARTOBJATR ADD CONSTRAINT FK_NARTOBJATR_CODOBIECT FOREIGN KEY (CodObiect) REFERENCES NARTOBJ(CodObiect)&apos;;
    vExistTab := 1;
  END IF;

  FOR i IN 1..bulk_x.Count LOOP
    vExistCol := bulk_x(i).ExistCol;
    IF vExistCol = 0 THEN
      BEGIN
        EXECUTE IMMEDIATE &apos;ALTER TABLE NARTOBJATR ADD (&apos;||bulk_x(i).colname||&apos; VARCHAR2(50))&apos;;
        vExistCOL := 1;
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
    END IF;

    IF vExistCol = 1 THEN
      cSQL := &apos;
      MERGE INTO NARTOBJATR b
      USING (
        SELECT ao.codobiect, av.Valoare
        FROM natrobj ao
          INNER JOIN nartobj o  ON o.codobiect  = ao.codobiect
          INNER JOIN natrib1 av ON av.codvalatr = ao.codvalatr
          INNER JOIN nartatr aa ON aa.codartatr = ao.codartatr
        WHERE aa.codatribut = &apos;||To_Char(bulk_x(i).codatribut)||CASE WHEN vTip = 1 THEN &apos; AND o.codarticol = &apos;||To_Char(vCod) ELSE &apos;&apos; END||&apos;
      ) a ON (a.codobiect = b.codobiect)
      WHEN     MATCHED THEN UPDATE SET b.&apos;||bulk_x(i).colname||&apos; = a.valoare
      WHEN NOT MATCHED THEN INSERT (b.codobiect, b.&apos;||bulk_x(i).colname||&apos;) VALUES (a.codobiect, a.valoare)&apos;;

      EXECUTE IMMEDIATE cSQL;
    END IF;
  END LOOP;

  bulk_x := t_tab_x();
END;

PROCEDURE AddNewValAtrib(NewVal IN VarChar2, RecId in NUMBER, aCod OUT NUMBER ) IS
PRAGMA AUTONOMOUS_TRANSACTION;
aCount NUMBER(20);
BEGIN
  SELECT COUNT(CodValAtr) into aCount FROM NATRIB1 WHERE UPPER(NewVal) = UPPER(Valoare) and recID=codatribut;

  IF aCount = 0 THEN
    SELECT seq_NATRIB1_CodValAtr.Nextval INTO aCOD FROM DUAL;
    INSERT INTO NATRIB1 ( CodValAtr,CodAtribut,Valoare)
    VALUES (aCOD , RecId , NewVal);
    COMMIT;
  END IF;

  IF aCount = 1 THEN
    SELECT CODVALATR into aCod FROM NATRIB1 WHERE UPPER(NewVal) = UPPER(Valoare) and recID=codatribut;
  END IF;
END;

END pkg_NomAtribute;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMAUTORIZATIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4B2165EA03B8587747826F47F35EBABD141CEAA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMAUTORIZATIIAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codautorizatii INTO Tmp FROM nautorizatiiauto WHERE codautorizatii = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM nautorizatiiauto WHERE codautorizatii = RecId ;
  NotifyModif(2, RECID, &apos;NAUTORIZATIIAUTO&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_nautorizatiiauto FIELDS( codautorizatii ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master autorizatii
  INSERT INTO  TMP_nautorizatiiauto ( codautorizatii,denumire, Atentionare, codserviciu )
    ( SELECT codautorizatii,denumire, atentionare, codserviciu
      FROM nautorizatiiauto WHERE codautorizatii = RecId ) ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
-- Master autorizatii
    SELECT  codautorizatii INTO RecId FROM TMP_nautorizatiiauto;
    UPDATE nautorizatiiauto SET ( denumire, Atentionare, codserviciu )
       = ( SELECT denumire, atentionare, codserviciu
          FROM TMP_nautorizatiiauto )
      WHERE codautorizatii = RecId ;
  ELSE  -- INSERT
-- Master autorizatii
  SELECT seq_autorizatii_codautorizatii.NextVal INTO RecId FROM DUAL;
  INSERT INTO  nautorizatiiauto ( codautorizatii,denumire, atentionare, codserviciu )
 ( SELECT  RecId ,denumire, atentionare, codserviciu
     FROM TMP_nautorizatiiauto  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NAUTORIZATIIAUTO&apos;);  
  COMMIT;
END;

END pkg_NomAUTORIZATIIauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMCARSUPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AAB43828787587CB3B9E2B2971A094F8F12B064</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMCARSUPART IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codcarsupart INTO Tmp FROM NCARSUPART WHERE codcarsupart = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NCARSUPART WHERE codcarsupart = RecId ;

  NotifyModif(2, RECID, &apos;NCARSUPART&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCARSUPART FIELDS( codcarsupart ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master
  INSERT INTO  TMP_NCARSUPART ( codcarsupart,den_carsupart, Culoare )
    ( SELECT codcarsupart,den_carsupart, Culoare
      FROM NCARSUPART WHERE codcarsupart = RecId ) ;


  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  codcarsupart INTO RecId FROM TMP_NCARSUPART;
    UPDATE NCARSUPART SET ( den_carsupart, Culoare )
       = ( SELECT den_carsupart, Culoare
          FROM TMP_NCARSUPART )
      WHERE codcarsupart = RecId ;

  ELSE  -- INSERT

  SELECT seq_NCARSUPART_codcarsupart.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NCARSUPART ( codcarsupart,den_carsupart, Culoare )
 ( SELECT  RecId ,den_carsupart, Culoare
     FROM TMP_NCARSUPART  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NCARSUPART&apos;);  



  COMMIT;
END;

procedure BAGA_DCI(aDCI in varchar2, aCod out number) is
begin
  SELECT seq_NCARSUPART_codcarsupart.NextVal INTO aCod FROM DUAL;
  insert into NCARSUPART (CODCARSUPART, den_carsupart)
  values (acod, aDCI);
  commit;
end;  

function get_code(den in varchar2) return number is
PRAGMA AUTONOMOUS_TRANSACTION;
  cod number(20);
begin
  cod := -1;
  select count(*) into cod from NCARSUPART where upper(den_carsupart)=upper(den);
  if cod = 0 then 
    SELECT seq_NCARSUPART_codcarsupart.NextVal INTO cod FROM DUAL;
    insert into NCARSUPART (CODCARSUPART, den_carsupart)
    values (cod, den);
    commit;
  else
    select codcarsupart into cod from NCARSUPART where upper(den_carsupart) = upper(den);
  end if;
  return cod;
end;

function IsUnicat(den in varchar2) return number is 
PRAGMA AUTONOMOUS_TRANSACTION;
  RecCount number(20);
begin
  select count(*) into RecCount from ncarsupart where upper(den_carsupart) = upper(den);
  return RecCount;
end;
end PKG_NOMCARSUPART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMCASEMARCAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2EC6F47E0E7CFEF7C191CA656EB5B014F1B3D81</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMCASEMARCAT IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodCaseMarcat INTO Tmp FROM NCASEMARCAT WHERE CodCaseMarcat = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NCASEMARCAT1 WHERE CodCaseMarcat = RecId;
  DELETE FROM NCASEMARCAT2 WHERE CodCaseMarcat = RecId;
  DELETE FROM NCASEMARCAT  WHERE CodCaseMarcat = RecId;

  NotifyModif(2, RECID, &apos;NCASEMARCAT&apos;);  



  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCASEMARCAT FIELDS( CodCaseMarcat ) VALUES (0) ;
  FOR v_rec IN ( SELECT DISTINCT Procent FROM NTVA1 ORDER BY Procent) LOOP
      INSERT INTO TMP_NCASEMARCAT2 ( CodCaseMarcat2,   Procent_Tva ) VALUES
                                   (             -1, v_rec.Procent );
  END LOOP;
                                     
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aTIP NUMBER(5) := 0;
BEGIN
  -- Master NCASEMARCAT
  INSERT INTO  TMP_NCASEMARCAT ( CodCaseMarcat, Denumire, Numar, Port, Tip, Model, CodFiscal, CodBareCantar, PLUMaxCantar, NrMaxPLU, LUNGIMETEXT, TIPDRIVER, RATA, SUBUNITATEA, GESTDESTTRANSF, CODIOARTDESTTRANSF, TIPINFOART, CODCARNETTRANSF, TEXTPROMO, CODCARNETNIR, INACTIV )
                   ( SELECT      CodCaseMarcat, Denumire, Numar, Port, Tip, Model, CodFiscal , CodBareCantar, PLUMaxCantar, NrMaxPLU, LUNGIMETEXT, TIPDRIVER, RATA, SUBUNITATEA, GESTDESTTRANSF, CODIOARTDESTTRANSF, NVL(TIPINFOART, 0), CODCARNETTRANSF, TEXTPROMO, CODCARNETNIR, INACTIV
                     FROM NCASEMARCAT WHERE CodCaseMarcat = RecId );      
  -- Detail NCASEMARCAT1
  INSERT INTO  TMP_NCASEMARCAT1 ( CodCaseMarcat1, CodCaseMarcat, CodGestiune, DenGestiune )
                     ( SELECT     c.CodCaseMarcat1, c.CodCaseMarcat, c.CodGestiune, g.den_gest
                       FROM NCASEMARCAT1 c inner join ngest g on c.codgestiune = g.codgest
                       WHERE CodCaseMarcat = RecId );
  -- Detail NCASEMARCAT2
  INSERT INTO  TMP_NCASEMARCAT2 ( CodCaseMarcat2, CodCaseMarcat, Procent_Tva, ParamCasa )
                     ( SELECT     CodCaseMarcat2, CodCaseMarcat, Procent_Tva, ParamCasa FROM NCASEMARCAT2 WHERE CodCaseMarcat = RecId );
  --pentru tva-urile noi se introduc linii cu cod -1 pentru a se face post-ul ca inregistrari noi
  FOR v_rec IN ( SELECT DISTINCT Procent FROM NTVA1 WHERE Procent NOT IN (SELECT Procent_Tva FROM TMP_NCASEMARCAT2) ) LOOP
      INSERT INTO TMP_NCASEMARCAT2 ( CodCaseMarcat2,   Procent_Tva ) VALUES
                                   (             -1, v_rec.Procent );
  END LOOP;

  BEGIN
    SELECT TIP INTO aTIP FROM TMP_NCASEMARCAT;
    EXCEPTION WHEN OTHERS THEN aTIP := 0;
  END;   
  
 /* 
 IF aTIP = 20 THEN -- DUDE  
    MERGE INTO TIPURIPLATI TP
    USING
    (
    SELECT * FROM
    (
     SELECT 20 AS TIPCASA, 1 AS TIPPLATA, &apos;Card&apos; as DENUMIRE FROM DUAL
     UNION 
     SELECT 20 AS TIPCASA, 2 AS TIPPLATA, &apos;Credit&apos; as DENUMIRE FROM DUAL
     UNION 
     SELECT 20 AS TIPCASA, 3 AS TIPPLATA, &apos;TicheteMasa&apos; as DENUMIRE FROM DUAL
     UNION 
     SELECT 20 AS TIPCASA, 4 AS TIPPLATA, &apos;TicheteValorice&apos; as DENUMIRE FROM DUAL
     UNION 
     SELECT 20 AS TIPCASA, 5 AS TIPPLATA, &apos;Voucher&apos; as DENUMIRE FROM DUAL
    )
    ) STD
    ON (TP.TIPCASA = STD.TIPCASA AND TP.TIPPLATA = STD.TIPPLATA)
    WHEN MATCHED THEN
      UPDATE SET
        DENPLATA = STD.DENUMIRE
    WHEN NOT MATCHED THEN
      INSERT(CODTIPPLATA, TIPCASA, TIPPLATA, DENPLATA)
      VALUES(SEQ_TIPURIPLATI_CODTIPPLATA.NEXTVAL, 20, STD.TIPPLATA, STD.DENUMIRE);       
   
 END IF;
*/ 
 

 INSERT INTO TMP_TIPURIPLATI SELECT * FROM TIPURIPLATI WHERE TIPCASA = aTIP;
  
                 
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aTIP NUMBER(5) := 0;
  aCOD NUMBER(20); 
BEGIN

  BEGIN
    SELECT  TIP INTO aTIP FROM TMP_NCASEMARCAT;
    EXCEPTION WHEN OTHERS THEN aTIP := 0;
  END;  

  IF OPERATION = 0 THEN  -- UPDATE
    -- Master NCASEMARCAT
    
    SELECT  CodCaseMarcat INTO RecId FROM TMP_NCASEMARCAT;
       
    UPDATE NCASEMARCAT SET ( Denumire, 
                            Numar, 
                            Port, 
                            Tip, 
                            Model, 
                            CodFiscal, 
                            CodBareCantar, 
                            PLUMaxCantar, 
                            NrMaxPLU, 
                            LUNGIMETEXT, 
                            TIPDRIVER, 
                            RATA, 
                            SUBUNITATEA, 
                            GESTDESTTRANSF, 
                            CODIOARTDESTTRANSF, 
                            TIPINFOART, 
                            CODCARNETTRANSF, 
                            TEXTPROMO, 
                            CODCARNETNIR,
                            INACTIV )
                          = 
                      (SELECT Denumire, 
                              Numar, 
                              Port, 
                              Tip, 
                              Model, 
                              CodFiscal, 
                              CodBareCantar, 
                              PLUMaxCantar, 
                              NrMaxPLU, 
                              LUNGIMETEXT, 
                              TIPDRIVER, 
                              RATA, 
                              SUBUNITATEA, 
                              GESTDESTTRANSF, 
                              CODIOARTDESTTRANSF, 
                              TIPINFOART, 
                              CODCARNETTRANSF, 
                              TEXTPROMO, 
                              CODCARNETNIR,
                              INACTIV 
                      FROM 
                        TMP_NCASEMARCAT )
    WHERE 
    CodCaseMarcat = RecId ;




    -- Detail NCASEMARCAT1
    DELETE FROM NCASEMARCAT1 WHERE CodCaseMarcat = RecId and CodCaseMarcat1 not in (Select CodCaseMarcat1 from TMP_NCASEMARCAT1); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NCASEMARCAT1 ( CodCaseMarcat1, CodCaseMarcat, CodGestiune ) -- inseram inreg. noi din TMP 
                (SELECT seq_Ncasemarcat1_Codcase1.Nextval, RecId, CodGestiune
                 FROM TMP_NCASEMARCAT1 WHERE CodCaseMarcat1 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NCASEMARCAT1 WHERE NVL(CodCaseMarcat1,-1) &gt; 0 ORDER BY CodCaseMarcat1 ) LOOP -- update pentru cele ramase
      UPDATE NCASEMARCAT1
      SET
        CodGestiune    = v_rec.CodGestiune
      WHERE CodCaseMarcat1 = v_rec.CodCaseMarcat1;
    END LOOP;
       
    -- Detail NCASEMARCAT2
    DELETE FROM NCASEMARCAT2 WHERE CodCaseMarcat = RecId and CodCaseMarcat2 not in (Select CodCaseMarcat2 from TMP_NCASEMARCAT2); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NCASEMARCAT2 ( CodCaseMarcat2, CodCaseMarcat, Procent_Tva, ParamCasa ) -- inseram inreg. noi din TMP 
               (SELECT  seq_NCASEmarcat2_CodCase2.Nextval, RecId, Procent_Tva, ParamCasa
                FROM TMP_NCASEMARCAT2 WHERE CodCaseMarcat2 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NCASEMARCAT2 WHERE NVL(CodCaseMarcat2,-1) &gt; 0 ORDER BY CodCaseMarcat2 ) LOOP -- update pentru cele ramase
      UPDATE NCASEMARCAT2
      SET
        Procent_Tva = v_rec.Procent_Tva,
        ParamCasa   = v_rec.Paramcasa
      WHERE CodCaseMarcat2 = v_rec.CodCaseMarcat2;
    END LOOP;
    
    
    -- Detail TIPURIPLATI
    
--    DELETE FROM TIPURIPLATI TP WHERE TIPCASA = aTIP AND NOT EXISTS (SELECT CODTIPPLATA FROM TMP_TIPURIPLATI WHERE CODTIPPLATA = TP.CODTIPPLATA);
/*
    FOR V_REC IN (SELECT * FROM TMP_TIPURIPLATI)
    LOOP
      IF V_REC.CODTIPPLATA &lt; 0 THEN
        INSERT INTO TIPURIPLATI (CODTIPPLATA, TIPCASA, TIPPLATA, DENPLATA, INVIZIBIL)
        VALUES (SEQ_TIPURIPLATI_CODTIPPLATA.NEXTVAL, aTIP, V_REC.TIPPLATA, V_REC.DENPLATA, V_REC.INVIZIBIL);
      ELSE
        UPDATE TIPURIPLATI
        SET
          TIPCASA   = aTIP,
          TIPPLATA  = V_REC.TIPPLATA,
          DENPLATA  = V_REC.DENPLATA,
          INVIZIBIL = V_REC.INVIZIBIL 
        WHERE
          CODTIPPLATA = V_REC.CODTIPPLATA; 
      END IF;
    END LOOP;
*/    
    
  ELSE  -- INSERT
  -- Master NCASEMARCAT
    SELECT seq_NCASEMARCAT_CodCase.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NCASEMARCAT ( CodCaseMarcat, Denumire, Numar, Port, Tip, Model, CodFiscal, CodBareCantar, PLUMaxCantar, NrMaxPLU, LUNGIMETEXT, TIPDRIVER, RATA, SUBUNITATEA, GESTDESTTRANSF, CODIOARTDESTTRANSF, TIPINFOART, CODCARNETTRANSF, TEXTPROMO, CODCARNETNIR, INACTIV )
                     ( SELECT     RecId, Denumire, Numar, Port, Tip, Model, CodFiscal, CodBareCantar, PLUMaxCantar, NrMaxPLU, LUNGIMETEXT, TIPDRIVER, RATA, SUBUNITATEA, GESTDESTTRANSF, CODIOARTDESTTRANSF, TIPINFOART, CODCARNETTRANSF, TEXTPROMO, CODCARNETNIR, INACTIV
                     FROM TMP_NCASEMARCAT ) ;

    -- Detail NCASEMARCAT1
    INSERT INTO NCASEMARCAT1 ( CodCaseMarcat1, CodCaseMarcat, CodGestiune )  
    (SELECT seq_NCASEmarcat1_CodCase1.Nextval, RecId, CodGestiune
    FROM TMP_NCASEMARCAT1);
      
    -- Detail NCASEMARCAT2
    INSERT INTO NCASEMARCAT2 ( CodCaseMarcat2, CodCaseMarcat, Procent_Tva, ParamCasa ) -- inseram inreg. noi din TMP 
    (SELECT  seq_NCASEmarcat2_CodCase2.Nextval, RecId, Procent_Tva, ParamCasa
    FROM TMP_NCASEMARCAT2 );
    
    -- Detail TIPURIPLATI
--     INSERT INTO TIPURIPLATI (CODTIPPLATA, TIPCASA, TIPPLATA, DENPLATA, INVIZIBIL)
--     SELECT SEQ_TIPURIPLATI_CODTIPPLATA.NEXTVAL, TIPCASA, TIPPLATA, DENPLATA, INVIZIBIL FROM TMP_TIPURIPLATI;

  END IF;

  DELETE TIPURIPLATI WHERE TIPCASA = aTIP;
  FOR V_REC IN (SELECT * FROM TMP_TIPURIPLATI)
  LOOP
    IF V_REC.CODTIPPLATA &lt; 0 THEN aCOD := SEQ_TIPURIPLATI_CODTIPPLATA.NEXTVAL; ELSE aCOD := V_REC.CODTIPPLATA; END IF;
    INSERT INTO TIPURIPLATI(CODTIPPLATA, TIPCASA, TIPPLATA, DENPLATA, INVIZIBIL)
                VALUES (aCOD, V_REC.TIPCASA, V_REC.TIPPLATA, V_REC.DENPLATA, V_REC.INVIZIBIL);
  END LOOP;    
  NotifyModif(OPERATION, RECID, &apos;NCASEMARCAT&apos;);  


COMMIT;
END;

FUNCTION TEST_UNICITATE_NUMAR(NrLogic IN NUMBER, Cod IN NUMBER) RETURN NUMBER
is PRAGMA AUTONOMOUS_TRANSACTION;
Nr number(20);
BEGIN
  SELECT COUNT(*) INTO Nr FROM NCASEMARCAT WHERE Numar = NrLogic AND CodCaseMarcat &lt;&gt; Cod;
  RETURN Nr;  
END;

end pkg_nomcasemarcat; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMELEMAEROAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B49A9CE6E15959B8A33810B5687B29CD5F4B52D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMELEMAEROAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodElemAeroAuto INTO Tmp FROM NELEMAEROAUTO WHERE CodElemAeroAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NELEMAEROAUTO WHERE CodElemAeroAuto = RecId ;
  NotifyModif(2, RECID, &apos;NELEMAEROAUTO&apos;);  


  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NELEMAEROAUTO FIELDS( CodElemAeroAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NELEMAEROAUTO ( CodElemAeroAuto, Element, Spor )
    ( SELECT CodElemAeroAuto, Element, Spor 
      FROM NELEMAEROAUTO WHERE CodElemAeroAuto = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodElemAeroAuto INTO RecId FROM TMP_NELEMAEROAUTO;
    UPDATE NELEMAEROAUTO SET ( Element, Spor )
       = ( SELECT Element, Spor
          FROM TMP_NELEMAEROAUTO )
      WHERE CodElemAeroAuto = RecId ;

  ELSE  -- INSERT
-- Master Nautom
  SELECT SEQ_NELEMAERO_CODELEMAERO.Nextval INTO RecId FROM DUAL;
  INSERT INTO  NELEMAEROAUTO ( CodElemAeroAuto, Element, Spor )
 ( SELECT  RecId , Element, Spor
     FROM TMP_NELEMAEROAUTO  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NELEMAEROAUTO&apos;);  

  COMMIT;
END;

end pkg_nomelemaeroauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C68540CF0A19E02470079B4A73007BF3AF65A04</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMGEST IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_2&apos;;

FUNCTION GETCODCARACTLUNA(aCODGEST IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN NUMBER
IS
aCODGEST1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODGEST1 INTO aCODGEST1 
    FROM NGEST1 i1
    WHERE i1.CODGEST = aCODGEST AND An * 12 + Luna BETWEEN i1.alstart AND i1.alstop;
  EXCEPTION WHEN OTHERS THEN aCodGEST1 := 0;
  END;
  RETURN aCodGEST1;
END;

FUNCTION GET_SUBUNIT_GEST(aCODGEST IN NUMBER) RETURN NUMBER
IS
  aCODSUBUNIT NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODSUBUNIT INTO ACODSUBUNIT FROM NGEST WHERE CODGEST = aCODGEST;
    EXCEPTION WHEN OTHERS THEN aCODSUBUNIT := 0;
  END;
  RETURN aCODSUBUNIT;
END;


PROCEDURE SET_GEST_FILTRU_GENERATOR(aGEST IN NUMBER)
IS
BEGIN
  GEST_FILTRU_GENERATOR := aGEST;
END;

FUNCTION GESTIUNE_FILTRU_VALIDA(aCODGEST IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF (ACODGEST = 0)OR(GEST_FILTRU_GENERATOR = 0) THEN RETURN 1;
	ELSIF GEST_FILTRU_GENERATOR = aCODGEST         THEN RETURN 1;
  ELSE                                                RETURN 0;
  END IF;
END;


FUNCTION GET_DEN_LOCATIE(aCODLOCATIE IN NUMBER) RETURN VARCHAR2
IS
DEN VARCHAR2(30);
BEGIN
  BEGIN
    SELECT DENUMIRE INTO DEN FROM NLOCATII WHERE CODLOCATIE = aCODLOCATIE;
    EXCEPTION WHEN OTHERS THEN DEN := &apos;&apos;;
  END;
  RETURN DEN;
END;

FUNCTION GESTIUNE_DEDICATA(aCODGEST IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
BEGIN
  IF acodgest = 0 THEN
   RETURN 1;
	ELSE
  SELECT COUNT(CODGEST) INTO NR FROM TMP_GESTDEDICATE;
  IF NR = 0 THEN RETURN 1;
  ELSE
    SELECT COUNT(CODGEST) INTO NR FROM TMP_GESTDEDICATE WHERE CODGEST = aCODGEST;
    RETURN NR;
  END IF;
	END IF;
END;

PROCEDURE SET_GEST_CURENTA_LOCATII(aGEST IN NUMBER, aLoc IN NUMBER)
IS
BEGIN
  GEST_CURENTA_LOCATII := aGEST;
  Locatia_CURENTA      := aLoc;
END;

FUNCTION GET_GEST_CURENTA_LOCATII RETURN NUMBER
IS
BEGIN
  RETURN GEST_CURENTA_LOCATII;
END;

FUNCTION  GET_Locatia_CURENTA RETURN NUMBER
IS
BEGIN
  RETURN Locatia_CURENTA;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codgest INTO Tmp FROM NGEST WHERE codgest = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc VARCHAR2(200);
BEGIN
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT  &apos;Gestiune &quot;&apos;||DEN_GEST||&apos;&quot;&apos; INTO aDoc FROM ngest WHERE CODGEST = RECID;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NGEST&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  SP_LOCKRECORD(RecId);
  -- nomGest --&gt; 506
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 506);
	UPDATE NLOCATII SET CODGEST = 0 WHERE CODGEST = RECID ;
  DELETE FROM NGEST1   WHERE CODGEST = RecId ;
  DELETE FROM NAGENDA  WHERE CODGEST = RECID ;
  DELETE FROM NGEST    WHERE CODGEST = RECID ;

  NotifyModif(2, RECID, &apos;NGEST&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NGEST FIELDS( codgest ) VALUES (0) ;
  -- nomGest --&gt; 506;
  PKG_CFGTABLES.EXT_INSERTRECORD(506); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 aANSFARSIT   NUMBER (4);
 aLUNASFARSIT NUMBER (2);
BEGIN
-- Master NGEST
  INSERT INTO  TMP_NGEST (
    codgest,den_gest,GMaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,custodie,codsubunit,
    VERDISPLIVR, VERDISPLIVRTRANSF,verdispLIVRsubunit, VERNIR, VERNIRTRANSF,verNIRsubunit, verEmulare, verFactIes,
    CODPOSTRETAIL,  ANALITICCONT, CANTITATE, tip, nrschimburi,
    oreschimb, orastart, Coefcheltmat, Coefcheltman, INACTIV, verChitanta, codcaensec,codgesttr,
    ziletermen, zilelucr,CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp, Obs)
  SELECT
    codgest,den_gest,GMaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,NVL(custodie, 0),codsubunit,
    VERDISPLIVR, VERDISPLIVRTRANSF,verdispLIVRsubunit, VERNIR, VERNIRTRANSF,verNIRsubunit, verEmulare, verFactIes,
    CODPOSTRETAIL, ANALITICCONT, CANTITATE, NVL(tip, 0), nrschimburi,
    oreschimb, nvl(orastart, to_date(&apos;01.01.1900&apos;,&apos;dd.mm.yyyy&apos;)), Coefcheltmat, Coefcheltman, INACTIV, verChitanta, codcaensec,codgesttr,
    ziletermen, zilelucr,CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp, Obs
  FROM NGEST WHERE codgest = RecId;

-- Detail NAGENDA
  INSERT INTO  TMP_NAGENDA (
    obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,
    codpart,codgest,codsubunit, adresa, longitudine, latitudine, obs2 )
  SELECT
    obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,
    codpart,codgest,codsubunit, GetAdresa(sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal), longitudine, latitudine, obs2
  FROM NAGENDA WHERE codgest = RecId;

-- Detail NLOCATII
  INSERT INTO TMP_LOCATIIGEST (CODLOCATIE, CODGEST, DENUMIRE, INDEXLOCAL)
  SELECT CODLOCATIE, CODGEST, DENUMIRE, INDEXLOCAL
  FROM NLOCATII
  WHERE CODGEST = RECID;
-- Detail NGEST1
  INSERT INTO TMP_NGEST1 (CODGEST1, CODGEST, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf, Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART )
    ( SELECT CODGEST1, CODGEST, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf,Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART
      FROM NGEST1 WHERE CODGEST = RecId );


  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODGEST1, ANSTART, LUNASTART FROM TMP_NGEST1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NGEST1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODGEST1 = V_REC.CODGEST1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
  -- nomGest --&gt; 506;
  PKG_CFGTABLES.EXT_GOTORECORD(506);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn    INTEGER := 0;
  vLuna  INTEGER := 0;
  vCod   NUMBER(20);
  NR     NUMBER(10):= 0;
  aDoc   VARCHAR2(200);
BEGIN
  SELECT  &apos;Gestiune &quot;&apos;||DEN_GEST||&apos;&quot;&apos; INTO aDoc FROM TMP_NGEST;
  -- nomGest --&gt; 506
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (506); 
  IF Operation = 0 THEN  -- UPDATE
    -- Master NGEST
    SELECT codgest INTO RecId FROM TMP_NGEST;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NGEST&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NGEST
    SET  (  den_gest,gmaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,custodie,codsubunit,
            verdisplivr, verdisplivrtransf,verdisplivrsubunit, vernir, vernirtransf, vernirsubunit, verEmulare, verFactIes,
            CODPOSTRETAIL, ANALITICCONT, CANTITATE, tip, nrschimburi,
            oreschimb, orastart, Coefcheltmat, Coefcheltman, INACTIV, verChitanta, codcaensec,codgesttr,
            Ziletermen, zilelucr, CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp, Obs)
       = (SELECT
            den_gest,gmaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,custodie,codsubunit,
            verdisplivr, verdisplivrtransf,verdisplivrsubunit, vernir, vernirtransf, vernirsubunit, verEmulare, verFactIes,
            CODPOSTRETAIL, ANALITICCONT, CANTITATE, tip, nrschimburi,
            oreschimb, orastart, Coefcheltmat, Coefcheltman, INACTIV, verChitanta, codcaensec,codgesttr,
            ziletermen, zilelucr, CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp, Obs
          FROM TMP_NGEST )
    WHERE codgest = RecId ;

-- Detail NAGENDA

    DELETE FROM NAGENDA WHERE ( codgest = RecId AND codagenda NOT IN ( SELECT codagenda FROM TMP_NAGENDA WHERE NVL(codagenda,0) &lt;&gt; 0));

    INSERT INTO NAGENDA ( obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, longitudine, latitudine, obs2 )
    SELECT obs, seq_NAGENDA_codagenda.Nextval ,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart, RecId ,codsubunit, longitudine, latitudine, obs2
    FROM TMP_NAGENDA WHERE codagenda &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NAGENDA WHERE NVL(codagenda,-1) &gt; 0 ORDER BY codagenda ) LOOP
      SELECT count(*) INTO vRecNo FROM NAGENDA WHERE codagenda = NVL(v_rec.codagenda,0);
      IF(vRecNo=1) THEN
        UPDATE NAGENDA
        SET obs = v_rec.obs,
            tip = v_rec.tip,
            codlocalit = v_rec.codlocalit,
            sediusocial = v_rec.sediusocial,
            telefon = v_rec.telefon,
            fax = v_rec.fax,
            email = v_rec.email,
            sector = v_rec.sector,
            strada = v_rec.strada,
            nr1 = v_rec.nr1,
            nr2 = v_rec.nr2,
            bloc = v_rec.bloc,
            scara = v_rec.scara,
            etaj = v_rec.etaj,
            apart = v_rec.apart,
            codpostal = v_rec.codpostal,
            km = v_rec.km,
            codbankcont = v_rec.codbankcont,
            codpart = v_rec.codpart,
            codgest = RecId ,
            codsubunit = v_rec.codsubunit,
            longitudine = v_rec.longitudine,
            latitudine = v_rec.latitudine,
            obs2 = v_rec.obs2
        WHERE codagenda = v_rec.codagenda;
      END IF;
    END LOOP;
-- Detail NGEST1

    DELETE FROM NGEST1 WHERE CODGEST = RECID AND CODGEST1 NOT IN (SELECT CODGEST1 FROM TMP_NGEST1);

    INSERT INTO NGEST1 (CODGEST1, CODGEST, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf,Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART )
      SELECT SEQ_NGEST1_CODGEST1.NEXTVAL, RecId, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf,Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART
      FROM TMP_NGEST1 WHERE CODGEST1 &lt; 0;

    FOR V_REC IN ( SELECT * FROM TMP_NGEST1 WHERE NVL(CODGEST1, -1) &gt; 0 ORDER BY codGEST1 ) LOOP
      UPDATE NGEST1
      SET
        TipGest         = v_rec.TipGest,
        Cheltuieli      = v_rec.Cheltuieli,
        CheltuieliAux   = v_rec.CheltuieliAux,
        CheltuieliInd   = v_rec.CheltuieliInd,
        CheltuieliAdmin = v_rec.CheltuieliAdmin,
        CheltuieliDesf  = v_rec.CheltuieliDesf,
        Venituri        = v_rec.Venituri,
        VENITURIK       = v_rec.VENITURIK,
        Suprafata       = v_rec.Suprafata
      WHERE
      CODGEST1 = v_rec.CODGEST1;
    END LOOP;

  ELSE  -- INSERT
-- MASTER NGEST
    SELECT SEQ_NGEST_CODGEST.NEXTVAL INTO RECID FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NGEST&apos;, RecId);
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NGEST&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO  NGEST (
      codgest,den_gest,GMaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,custodie,codsubunit,
      verdisplivr, verdisplivrtransf,verdisplivrsubunit, vernir, vernirtransf,vernirsubunit, verEmulare, verFactIes,
      CODPOSTRETAIL, ANALITICCONT, CANTITATE, tip, nrschimburi, oreschimb, INACTIV, verChitanta, codcaensec,codgesttr,
      ziletermen, zilelucr, CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp, Orastart,Coefcheltmat,Coefcheltman,Obs )
    SELECT
      RecId ,den_gest,GMaster, simbol,codclasa,codactivit,codcont,codcatpret,codgestionar,custodie,codsubunit,
      verdisplivr, verdisplivrtransf,verdisplivrsubunit, vernir, vernirtransf,vernirsubunit, verEmulare, verFactIes,
      CODPOSTRETAIL, ANALITICCONT, CANTITATE, tip, nrschimburi, oreschimb, INACTIV, verChitanta, codcaensec,codgesttr,
      ziletermen, zilelucr, CODANTREPOZIT,capprod,carnetcmdint,carnetbc,carnetnp,carnetrp,orastart,Coefcheltmat,Coefcheltman,Obs
    FROM TMP_NGEST;

  -- Detail NAGENDA
    INSERT INTO NAGENDA (
      obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,
      codbankcont,codpart,codgest,codsubunit, longitudine, latitudine, obs2 )
    SELECT
      obs, seq_NAGENDA_codagenda.Nextval ,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,
      codbankcont,codpart,RecId,codsubunit, longitudine, latitudine, obs2
    FROM TMP_NAGENDA;
-- Detail IOFILIAL1
    INSERT INTO NGEST1 (CODGEST1, CODGEST, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf,Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART )
      SELECT SEQ_NGEST1_CODGEST1.NEXTVAL, RecId, TipGest, Cheltuieli, CheltuieliAux, CheltuieliInd, CheltuieliAdmin, CheltuieliDesf,Venituri, VENITURIK, Suprafata, ANSTART, LUNASTART
      FROM TMP_NGEST1;

  END IF;

-- DETAIL NLOCATII
--  UPDATE NLOCATII SET CODGEST = 0 WHERE ( CODGEST = RECID AND CODLOCATIE NOT IN ( SELECT CODLOCATIE FROM TMP_LOCATIIGEST));

  UPDATE NLOCATII SET CODGEST = 0 WHERE CODGEST = RECID;

  FOR V_REC IN (SELECT * FROM TMP_LOCATIIGEST) LOOP
    IF V_REC.CODLOCATIE &gt; 0 THEN
      UPDATE NLOCATII
      SET CODGEST = RecId
      WHERE CODLOCATIE = V_REC.CODLOCATIE;
    END IF;

  END LOOP;

 BEGIN
   SELECT COUNT(*) INTO NR FROM TMP_GESTDEDICATE WHERE CODGEST = RECID;
   EXCEPTION WHEN OTHERS THEN NR := 0;
 END;
 IF NR = 0 THEN
   INSERT INTO TMP_GESTDEDICATE (CODGEST) VALUES (RECID);
 END IF;

 PRC_AL_REFRESH(&apos;NGEST1&apos;, RECID);
 -- nomGest --&gt; 506
 PKG_CFGTABLES.EXT_POSTRECORDS(506);
 NotifyModif(OPERATION, RECID, &apos;NGEST&apos;);

 COMMIT;
END;

function GetCoefSectie(aCodGest in number) return number is
aCapProd number(20,7);
aMasa number(20,7);
begin
  select nvl(capprod,0) into aCapProd from ngest where codgest = aCodGest;
  if aCapProd = 0 then
    return 0;
  end if;
  begin
    select sum(i1.cant*o.masa) into aMasa
    from intrari i
         inner join intrari1 i1 on i1.codintr = i.codintr
         inner join nartobj o on o.codobiect = i1.codobiect
    where i.anulat = 0 and i.codgestprod = aCodGest and i.operat = 1 and i.tipdoc = 7
          and i.an*12+i.luna = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  exception when others then aMasa := 0;
  end;
  return aMasa/aCapProd;
end;

END pkg_NomGest;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE1B61E92605503894AD540B6EDB3D4C733C5A86</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMGRUPEAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodGrupeAuto INTO Tmp FROM NGRUPEAUTO WHERE CodGrupeAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NGRUPEAUTO WHERE CodGrupeAuto = RecId ;
  NotifyModif(2, RECID, &apos;NGRUPEAUTO&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NGRUPEAUTO FIELDS( CodGrupeAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NGRUPEAUTO ( CodGrupeAuto, Grupa, SporB, SporRes, SporAlte )
    ( SELECT CodGrupeAuto, Grupa, SporB, SporRes, SporAlte 
      FROM NGRUPEAUTO WHERE CodGrupeAuto = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodGrupeAuto INTO RecId FROM TMP_NGRUPEAUTO;
    UPDATE NGRUPEAUTO SET ( Grupa, SporB, SporRes, SporAlte )
       = ( SELECT Grupa, SporB, SporRes, SporAlte
          FROM TMP_NGRUPEAUTO )
      WHERE CodGrupeAuto = RecId ;

  ELSE  -- INSERT
-- Master
  SELECT seq_ngrupeauto_codgrupeauto.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NGRUPEAUTO ( CodGrupeAuto, Grupa, SporB, SporRes, SporAlte )
 ( SELECT  RecId , Grupa, SporB, SporRes, SporAlte
     FROM TMP_NGRUPEAUTO  ) ;
  END IF;
  NotifyModif(OPERATION, RECID, &apos;NGRUPEAUTO&apos;);  


  COMMIT;
END;

end pkg_nomgrupeauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3FA47E95522426A6A86E1CBD3EBF703FBC556B04</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMINSTAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodInstAuto INTO Tmp FROM NINSTAUTO WHERE CodInstAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NINSTAUTO WHERE CodInstAuto = RecId ;
  NotifyModif(2, RECID, &apos;NINSTAUTO&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NINSTAUTO FIELDS( CodInstAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NINSTAUTO ( CodInstAuto, Instalatie, Prestatie, Spor )
    ( SELECT CodInstAuto, Instalatie, Prestatie, Spor 
      FROM NINSTAUTO WHERE CodInstAuto = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodInstAuto INTO RecId FROM TMP_NINSTAUTO;
    UPDATE NINSTAUTO SET ( Instalatie, Prestatie, Spor )
       = ( SELECT Instalatie, Prestatie, Spor
          FROM TMP_NINSTAUTO )
      WHERE CodInstAuto = RecId ;

  ELSE  -- INSERT
-- Master Nautom
  SELECT seq_ninstauto_CodInstAuto.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NINSTAUTO ( CodInstAuto, Instalatie, Prestatie, Spor )
 ( SELECT  RecId , Instalatie, Prestatie, Spor
     FROM TMP_NINSTAUTO  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NINSTAUTO&apos;);  

  COMMIT;
END;

end pkg_nominstauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>479CED3C9D71FFF93B5CB3C641E3444F1171A815</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_nominterventiiauto IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_56&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodInterventiiAuto INTO Tmp FROM NINTERVENTIIAUTO WHERE CodInterventiiAuto = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Interventi &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM NINTERVENTIIAUTO WHERE codinterventiiauto = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NINTERVENTIIAUTO&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

	DELETE FROM NINTERVENTIIAUTO WHERE CodInterventiiAuto = RecId ;

  NotifyModif(2, RECID, &apos;NINTERVENTIIAUTO&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NINTERVENTIIAUTO FIELDS( CodInterventiiAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NINTERVENTIIAUTO ( CodInterventiiAuto, Denumire, PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, Tip, Serviciu, CodReteta,
                                      Accidentala, Clasa)
    ( SELECT CodInterventiiAuto, Denumire, PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, NVL(Tip,0), Serviciu, CodReteta,
             Accidentala, Clasa
      FROM NINTERVENTIIAUTO WHERE CodInterventiiAuto = RecId ) ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodInterventiiAuto INTO RecId FROM TMP_NINTERVENTIIAUTO;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Interventi &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM NINTERVENTIIAUTO WHERE codinterventiiauto = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NINTERVENTIIAUTO&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    UPDATE NINTERVENTIIAUTO SET ( Denumire, PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, Tip, Serviciu, CodReteta,Accidentala, Clasa )
       = ( SELECT Denumire, PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, Tip, Serviciu, CodReteta, Accidentala, Clasa
          FROM TMP_NINTERVENTIIAUTO )
      WHERE CodInterventiiAuto = RecId ;
    --update NINTERVENTIIAUTO set accidentala = case when nvl(perdurata,0) = 0 then 1 else 0 end where CodInterventiiAuto = recid;
  ELSE  -- INSERT
-- Master Nautom
    SELECT seq_ninterv_codinterv.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NINTERVENTIIAUTO ( Denumire, CodInterventiiAuto, PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, Tip, Serviciu, CodReteta,Accidentala,Clasa )
    SELECT  Denumire, RecId , PerTip, PerDurata, PerKm, AtentionareZile, AtentionareKm, Tip, Serviciu, CodReteta,Accidentala,Clasa
    FROM TMP_NINTERVENTIIAUTO ;
    
    --update NINTERVENTIIAUTO set accidentala = case when nvl(perdurata,0) = 0 then 1 else 0 end where CodInterventiiAuto = recid;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Interventi &quot;&apos;||denumire||&apos;&quot;&apos; INTO aDoc FROM NINTERVENTIIAUTO WHERE codinterventiiauto = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NINTERVENTIIAUTO&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NINTERVENTIIAUTO&apos;);
  COMMIT;
END;

end pkg_nominterventiiauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMLOCATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4DBC309530DA8D62186355F5AEC67C46EC3DF4C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMLOCATII IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodLocatie INTO Tmp FROM NLOCATII WHERE CodLocatie = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
AdoC VARCHAR2(100);
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NLOCATII WHERE CodLocatie = RecId ;

  NotifyModif(2, RECID, &apos;NLOCATII&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NLOCATII FIELDS( CodLocatie ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NLOCATII
  INSERT INTO  TMP_NLOCATII 
           ( CodLocatie, denumire,  NrCelule, DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, Codgest, INACTIV)
    ( SELECT CodLocatie, denumire,  NrCelule, DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, NVL(Codgest, 0), INACTIV
      FROM NLOCATII WHERE CodLocatie = RecId ) ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
  
  aDoc VARCHAR2(100);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodLocatie INTO RecId FROM TMP_NLOCATII;
    UPDATE NLOCATII SET ( denumire,  NrCelule,  DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, Codgest, INACTIV ) = 
                 ( SELECT denumire,  NrCelule,  DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, Codgest, INACTIV 
    FROM TMP_NLOCATII )
    WHERE CodLocatie = RecId ;

  ELSE  -- INSERT
    SELECT seq_NLOCATII_CodLocatie.NextVal INTO RecId FROM DUAL;


    INSERT INTO  NLOCATII ( CodLocatie, denumire,  NrCelule,  DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, Codgest, INACTIV )
                  ( SELECT  RecId ,     denumire,  NrCelule,  DESCRIERE, COORDX,  TIPLOCATIE, CODLOCFIXA, CODVECINLEFT, CODVECINRIGHT, CODEXTERN, INDEXLOCAL, Codgest, INACTIV
       FROM TMP_NLOCATII  ) ;
  END IF;
  
  NotifyModif(OPERATION, RECID, &apos;NLOCATII&apos;);

  COMMIT;
END;



END PKG_NOMLOCATII ; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAF7A77AFDCBAD38D42E317C959E909B1C83695C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMMARCIAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodMarciAuto INTO Tmp FROM NMARCIAUTO WHERE CodMarciAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NMARCIAUTO WHERE CodMarciAuto = RecId ;
  NotifyModif(2, RECID, &apos;NMARCIAUTO&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NMARCIAUTO FIELDS( CodMarciAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NMARCIAUTO ( CodMarciAuto, Marca )
    ( SELECT CodMarciAuto, Marca
      FROM NMARCIAUTO WHERE CodMarciAuto = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodMarciAuto INTO RecId FROM TMP_NMARCIAUTO;
    UPDATE NMARCIAUTO SET ( Marca )
       = ( SELECT Marca
          FROM TMP_NMARCIAUTO )
      WHERE CodMarciAuto = RecId ;

  ELSE  -- INSERT
-- Master Nautom
  SELECT seq_nmarciauto_codmarciauto.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NMARCIAUTO ( CodMarciAuto, Marca )
 ( SELECT  RecId , Marca
     FROM TMP_NMARCIAUTO  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NMARCIAUTO&apos;);  

  COMMIT;
END;

end pkg_nommarciauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>692E143D167B330CF28019EB4A57007B664209B2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_nommodeleauto IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodModeleAuto INTO Tmp FROM NMODELEAUTO WHERE CodModeleAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NMODELEAUTO WHERE CodModeleAuto = RecId ;
  NotifyModif(2, RECID, &apos;NMODELEAUTO&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NMODELEAUTO FIELDS( CodModeleAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NMODELEAUTO ( CodModeleAuto, Model, CodMarciAuto)
  SELECT CodModeleAuto, Model, CodMarciAuto
  FROM NMODELEAUTO
  WHERE CodModeleAuto = RecId ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodModeleAuto INTO RecId 
    FROM TMP_NMODELEAUTO;
    UPDATE NMODELEAUTO SET ( Model, CodMarciAuto ) = ( SELECT Model, CodMarciAuto FROM TMP_NMODELEAUTO ) WHERE CodModeleAuto = RecId ;
  ELSE  -- INSERT
    SELECT seq_nmodeleauto_codmodeleauto.NextVal INTO RecId FROM DUAL;

    INSERT INTO  NMODELEAUTO ( CodModeleAuto, Model, CodMarciAuto ) 
    SELECT  RecId , Model, CodMarciAuto
    FROM TMP_NMODELEAUTO;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NMODELEAUTO&apos;);
  COMMIT;
END;

end pkg_nommodeleauto;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C37725F9769A3EA292CB9622B4BDDA844B162D41</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMPART IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_4&apos;;

PROCEDURE Set_stopaj_Salarii
IS
  cArtCASS     NUMBER(20)   := 0;
  cArtImpozit  NUMBER(20)   := 0;
  cTaxaCASS    NUMBER(20)   := 0;
  cTaxaImpozit NUMBER(20)   := 0;
  aBazaCass    NUMBER(20,7) := 0;
  aBazaImp     NUMBER(20,7) := 0;
  aBNetCass    NUMBER(20,7) := 0;
  aBNetImp     NUMBER(20,7) := 0;
  aValCass     NUMBER(20,7) := 0;
  aValImp      NUMBER(20,7) := 0;
  Nr           NUMBER;
  aCODFISCAL   VARCHAR2(50);
  vNullDate    DATE         := To_Date(&apos;1900&apos;,&apos;yyyy&apos;);

  pjArtCass    NTAXE1.VALOARE%TYPE;
  lcArtCass    NTAXE1.LACEAPLIC%TYPE;
  pjDimCass    NTAXE1.PROCDIMINUAREB%TYPE;
  coefDimCass  NUMBER;

  pjArtImp     NTAXE1.VALOARE%TYPE;
  lcArtImp     NTAXE1.LACEAPLIC%TYPE;
  pjDimImp     NTAXE1.PROCDIMINUAREB%TYPE;
  coefDimImp   NUMBER;

  aPos         NUMBER;
  aNume        VARCHAR2(50);
  aPrenume     VARCHAR2(50);
  vDataSf      DATE;

  vSubunit     NUMBER(20) := 1;
BEGIN
  cTaxaCASS  := Coalesce(pkg_categconst.GetValConstanta(&apos;CTaxaCASS&apos;,    pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU), 0);
  IF PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 AND pkg_categconst.GetValConstanta(&apos;Holding&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru) &lt;&gt; 2 THEN
    vSubunit := PKG_GLOBALS.GETSUBUNITATE;
  END IF;
  IF cTaxaCASS &gt; 0 THEN
    SELECT
      Max(CODSERVFACT)    KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(VALOARE)        KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(LACEAPLIC)      KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(PROCDIMINUAREB) KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART)
    INTO cArtCASS, pjArtCass, lcArtCass, pjDimCass
    FROM NTAXE1
    WHERE CodTaxa = cTaxaCASS AND ANSTART*12+LUNASTART &lt;= pkg_globals.AnLunaLucru;
  ELSE
    cArtCASS    := Coalesce(pkg_categconst.GetValConstanta(&apos;CArtCASS&apos;,     pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU), 0);
    SELECT
      Max(VALOARE)        KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(LACEAPLIC)      KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(PROCDIMINUAREB) KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART)
    INTO pjArtCass, lcArtCass, pjDimCass
    FROM NTAXE1
    WHERE CODSERVFACT = cArtCASS AND ANSTART*12+LUNASTART &lt;= pkg_globals.AnLunaLucru;
  END IF;
  coefDimCass := 1 - Coalesce(pjDimCass,0)/100;

  cTaxaImpozit  := Coalesce(pkg_categconst.GetValConstanta(&apos;CTaxaImpozit&apos;, pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU), 0);
  IF cTaxaImpozit &gt; 0 THEN
    SELECT
      Max(CODSERVFACT)    KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(VALOARE)        KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(LACEAPLIC)      KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(PROCDIMINUAREB) KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART)
    INTO cArtImpozit, pjArtImp, lcArtImp, pjDimImp
    FROM NTAXE1
    WHERE CodTaxa = cTaxaImpozit AND ANSTART*12+LUNASTART &lt;= pkg_globals.AnLunaLucru;
  ELSE
    cArtImpozit := Coalesce(pkg_categconst.GetValConstanta(&apos;CArtImpozit&apos;,  pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU), 0);
    SELECT
      Max(VALOARE)        KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(LACEAPLIC)      KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART),
      Max(PROCDIMINUAREB) KEEP (Dense_Rank LAST ORDER BY ANSTART*12+LUNASTART)
    INTO pjArtImp, lcArtImp, pjDimImp
    FROM NTAXE1
    WHERE CODSERVFACT = cArtImpozit AND ANSTART*12+LUNASTART &lt;= pkg_globals.AnLunaLucru;
  END IF;
  coefDimImp := 1 - Coalesce(pjDimImp,0)/100;

  DELETE FROM Tmp_stopaj;
  INSERT INTO Tmp_stopaj (Nume, Prenume, BazaCass, ContrCass) VALUES (&apos;.?.&apos;, &apos;Sursa&apos;, pkg_globals.ANLUCRU , pkg_globals.LUNALUCRU );

  FOR v_rec IN (
    SELECT DISTINCT
      i1.CodIntr, i.Partener, p.Den_Part, pcf.CodFiscal CNP, p1.SimbolCASS, CASE WHEN c.codcontract IS NULL THEN 0 ELSE 26 END TipAsig,
      Min(C.DataStart) OVER (PARTITION BY i.Partener) DataAng, Max(C.DataStop) OVER (PARTITION BY i.Partener) DataSf
    FROM intrari1 i1
      INNER JOIN Intrari i on i.codIntr = i1.CodIntr
      INNER JOIN NPart p on p.codPart = i.Partener
      INNER JOIN (
        SELECT codpart, Max(SimbolCass) KEEP (Dense_Rank Last Order BY ANSTART*12+LUNASTART) SimbolCass FROM NPART1 WHERE ANSTART*12+LUNASTART &lt;= pkg_globals.AnLunaLucru GROUP BY CodPart
      ) p1 on p1.codpart = i.Partener
      INNER JOIN npartcodfisc pcf ON pcf.CODPART = i.Partener
      LEFT JOIN contract c ON c.codcontract = i.codcontract
    WHERE Coalesce(i1.Taxa, 0) &gt; 0
      AND i.TipDoc = 4
      AND i.An * 12 + i.luna = pkg_globals.AnLunaLucru
      AND Coalesce(p.Persoanafizica, 0) = 1
      AND pcf.PRINCIPAL = 1
      AND 1 = CASE WHEN c.codcontract IS NULL AND i.an &gt;= 2104 THEN 0 ELSE 1 END
      AND (vSubunit = 1 OR vSubunit = i.SUBUNITATEA)
  ) LOOP
    SELECT Sum(BazaCASS), Sum(ValCass) INTO aBazaCASS, aValCass
    FROM (
      SELECT
        (SELECT Max(t.Cant*t.PU) KEEP (Dense_Rank LAST ORDER BY t.indexlocal) FROM intrari1 t WHERE t.codintr = i1.codintr AND t.indexlocal &lt; i1.indexlocal AND NOT t.CodObiect IN (cArtCASS, cArtImpozit)) BazaCASS,
        i1.Cant*i1.PU ValCass
      FROM intrari1 i1
      WHERE CodIntr = v_rec.CodIntr AND Coalesce(i1.Taxa,0) &gt; 0 AND i1.CodObiect = cArtCASS
    );

    SELECT Sum(BazaImp), Sum(ValImp) INTO aBazaImp, aValImp
    FROM (
      SELECT
        (SELECT Max(t.Cant*t.PU) KEEP (Dense_Rank LAST ORDER BY t.indexlocal) FROM intrari1 t WHERE t.codintr = i1.codintr AND t.indexlocal &lt; i1.indexlocal AND NOT t.CodObiect IN (cArtCASS, CArtImpozit)) BazaImp,
        i1.Cant*i1.PU ValImp
      FROM intrari1 i1
      WHERE CodIntr = v_rec.CodIntr AND Coalesce(i1.Taxa,0) &gt; 0 AND i1.CodObiect = cArtImpozit
    );

    IF    Coalesce(lcArtCass,0)  &lt;&gt; 6 THEN aBazaCass := Coalesce( aBazaCass ,0); aBNetCass := aBazaCass;
    ELSIF Coalesce(pjArtCass,0)   = 0 THEN aBazaCass := 0;                       aBNetCass := 0;
    ELSIF Coalesce(coefDimCass,0) = 0 THEN aBazaCass := 0;                       aBNetCass := 0;
    ELSE                                   aBazaCass := Round(Coalesce(aValCass, 0) * 100 / (coefDimCass*pjArtCass), 2);
                                           aBNetCass := Round(Coalesce(aValCass, 0) * 100 / pjArtCass, 2);
    END IF;

    IF    Coalesce(lcArtImp,0)  &lt;&gt; 6  THEN aBazaImp  := Coalesce( aBazaImp ,0);  aBNetImp := aBazaImp;
    ELSIF Coalesce(pjArtImp,0)   = 0  THEN aBazaImp  := 0;                       aBNetImp := 0;
    ELSIF Coalesce(coefDimImp,0) = 0  THEN aBazaImp  := 0;                       aBNetImp := 0;
    ELSE                                   aBazaImp  := Round(Coalesce(aValImp, 0) * 100 / (coefDimImp*pjArtImp), 2);
                                           aBNetImp  := Round(Coalesce(aValImp, 0) * 100 / pjArtImp, 2);
    END IF;

    aBazaCASS := Coalesce(Abs(aBazaCASS),0);
    aBNetCASS := Coalesce(Abs(aBNetCASS),0);
    aValCass  := Coalesce(Abs(aValCass) ,0);
    aBazaImp  := Coalesce(Abs(aBazaImp) ,0);
    aBNetImp  := Coalesce(Abs(aBNetImp) ,0);
    aValImp   := Coalesce(Abs(aValImp)  ,0);

    aBazaCASS := CASE WHEN aBazaCASS &gt; 0 AND aBazaCASS &lt; 1 THEN 1 ELSE Round(aBazaCASS,0) END;
    aBNetCASS := CASE WHEN aBNetCASS &gt; 0 AND aBNetCASS &lt; 1 THEN 1 ELSE Round(aBNetCASS,0) END;
    aValCass  := CASE WHEN aValCass  &gt; 0 AND aValCass  &lt; 1 THEN 1 ELSE Round(aValCass ,0) END;
    aBazaImp  := CASE WHEN aBazaImp  &gt; 0 AND aBazaImp  &lt; 1 THEN 1 ELSE Round(aBazaImp ,0) END;
    aBNetImp  := CASE WHEN aBNetImp  &gt; 0 AND aBNetImp  &lt; 1 THEN 1 ELSE Round(aBNetImp ,0) END;
    aValImp   := CASE WHEN aValImp   &gt; 0 AND aValImp   &lt; 1 THEN 1 ELSE Round(aValImp  ,0) END;

    aPos      := InStr(v_rec.Den_Part, &apos; &apos;);
    IF aPos = 0 OR aPos &gt; 51 THEN
      aNume    := SubStr(v_rec.Den_Part,  1, 50);
      aPrenume := SubStr(v_rec.Den_Part, 51, 50);
    ELSE
      aNume    := SubStr(v_rec.Den_Part, 1, aPos - 1);
      aPrenume := SubStr(v_rec.Den_Part, aPos + 1, 50);
    END IF;

    IF pkg_globals.ANLUCRU = Coalesce(Extract(YEAR FROM v_rec.DataSf),0) AND pkg_globals.LUNALUCRU = Coalesce(Extract(MONTH FROM v_rec.DataSf),0)
    THEN vDataSf := v_rec.DataSf;
    ELSE vDataSf := NULL;
    END IF;

    IF Coalesce(aValImp,0) &lt;&gt; 0 OR Coalesce(aValCass,0) &lt;&gt; 0 THEN
      SELECT Count(*) INTO Nr FROM Tmp_stopaj
      WHERE CNP = v_rec.CNP
        AND Coalesce(Nume, &apos;?&apos;) = Coalesce(aNume, &apos;?&apos;) AND Coalesce(Prenume, &apos;?&apos;) = Coalesce(aPrenume, &apos;?&apos;)
        AND Coalesce(DataAng, vNullDate) = Coalesce(v_rec.DataAng, vNullDate) AND Coalesce(DataSf, vNullDate) = Coalesce(vDataSf, vNullDate);
      IF Nr = 0 THEN
        INSERT INTO Tmp_stopaj (
          Nume, Prenume, CNP,
          DataAng, DataSf,
          casaSN, TipAsig,
          BazaCass,    BNetCass,    ContrCass,
          BazaImpozit, BNetImpozit, Impozit)
        VALUES (
          aNume, aPrenume, v_rec.CNP,
          v_rec.DataAng, vDataSf,
          v_rec.SimbolCaSS, v_rec.TipAsig,
          aBazaCass, aBNetCass, aValCass,
          aBazaImp,  aBNetImp,  aValImp);
      ELSE
        UPDATE Tmp_stopaj
        SET BazaCass    = BazaCass    + aBazaCass,
            BNetCass    = BNetCass    + aBNetCass,
            ContrCass   = ContrCass   + aValCass,
            BazaImpozit = BazaImpozit + aBazaImp,
            BNetImpozit = BNetImpozit + aBNetImp,
            Impozit     = Impozit     + aValImp
        WHERE CNP = v_rec.CNP
          AND Coalesce(Nume, &apos;?&apos;) = Coalesce(aNume, &apos;?&apos;) AND Coalesce(Prenume, &apos;?&apos;) = Coalesce(aPrenume, &apos;?&apos;)
          AND Coalesce(DataAng, vNullDate) = Coalesce(v_rec.DataAng, vNullDate) AND Coalesce(DataSf, vNullDate) = Coalesce(vDataSf, vNullDate);
      END IF;
    END IF;
  END LOOP;
END;

FUNCTION STR_CODFISCAL(aCODFISCAL IN VARCHAR2) RETURN VARCHAR2
IS
 ACODFISC VARCHAR2(50) := &apos;&apos;;
BEGIN
  aCODFISC := REPLACE(REPLACE(UPPER(aCODFISCAL),&apos; &apos;, &apos;&apos;), &apos;-&apos;, &apos;&apos;);
  aCODFISC := REPLACE(UPPER(aCODFISCAL),&apos;.&apos;, &apos;&apos;);
	RETURN REPLACE(aCODFISC, &apos;RO&apos;, &apos;&apos;);
END;

PROCEDURE SETCLASAPART(aCLASA IN NUMBER)
IS
BEGIN
  CLASA_PART := aCLASA;
END;

FUNCTION CONDITIECLASA(aCLASA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF CLASA_PART = 0 THEN RETURN 1;
  ELSE
    IF aCLASA = CLASA_PART THEN RETURN 1; ELSE RETURN 0; END IF;
  END IF;
END;

FUNCTION GET_SUBUNIT_GEST(aCODGEST IN NUMBER) RETURN NUMBER
IS
 aCODSUBUNIT NUMBER(20) := 2;
BEGIN
  BEGIN
    SELECT CODSUBUNIT INTO aCODSUBUNIT FROM NGEST WHERE CODGEST = aCODGEST;
    EXCEPTION WHEN OTHERS THEN aCODSUBUNIT := 2;
  END;
  RETURN aCODSUBUNIT;
END;

PROCEDURE SET_PART_DOCROSU(aCODPART IN NUMBER)
IS
BEGIN
  PART_DOC_ROSU := aCODPART;
END;

FUNCTION  GET_PART_DOCROSU RETURN NUMBER
IS
BEGIN
  RETURN PART_DOC_ROSU;
END;

FUNCTION  PART_DOCROSU_VALID(aCODPART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF PART_DOC_ROSU = 0 THEN RETURN 1;
  ELSE
    IF aCODPART = PART_DOC_ROSU THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  END IF;
END;

FUNCTION COD_EXTERN_UNIC(aCODPART IN NUMBER, aCODEXTERN IN VARCHAR2) RETURN NUMBER
IS
 NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NPART WHERE CODEXTERN = aCODEXTERN AND CODPART &lt;&gt; aCODPART;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;

FUNCTION COD_INTERN_UNIC(aCODPART IN NUMBER, aCODINTERN IN VARCHAR2) RETURN NUMBER
IS
 NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NPART WHERE CODINTERN = aCODINTERN AND CODPART &lt;&gt; aCODPART;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;

FUNCTION COD_FISCAL_UNIC(aCODPART IN NUMBER, aCODFISCAL IN VARCHAR2, aPartener OUT VARCHAR2) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
BEGIN
--  SELECT COUNT(*) INTO NR FROM NPARTCODFISC WHERE STR_CODFISCAL(CODFISCAL) = STR_CODFISCAL(aCODFISCAL) AND CODPART &lt;&gt; aCODPART;
  aPartener := &apos;&apos;;
  SELECT COUNT(*) INTO NR FROM NPARTCODFISC
  WHERE
    regexp_replace(CODFISCAL, &apos;[^0-9]&apos;, &apos;&apos;)= regexp_replace(aCODFISCAL, &apos;[^0-9]&apos;, &apos;&apos;)
    AND CODPART &lt;&gt; aCODPART;

  IF NR = 0 THEN
    RETURN 1;
  ELSE
    for v_rec in (select p.den_part
                  from npart p
                       inner join npartcodfisc f on f.codpart = p.codpart
                  WHERE regexp_replace(f.CODFISCAL, &apos;[^0-9]&apos;, &apos;&apos;)= regexp_replace(aCODFISCAL, &apos;[^0-9]&apos;, &apos;&apos;)
                        AND p.CODPART &lt;&gt; aCODPART
                 ) loop
      aPartener := v_rec.den_part;
      Exit;
    end loop;
    RETURN 0;
  END IF;
END;

PROCEDURE SET_CODPART_SOLD_ANALIZAT(aCODPART IN NUMBER)
IS
BEGIN
  PARTENER_SOLD_ANALIZAT := aCODPART;
END;

FUNCTION  CODPART_SOLD_ANALIZAT_VALID(aCODPART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF PARTENER_SOLD_ANALIZAT = 0 THEN RETURN 1;
  ELSE
    IF aCODPART = PARTENER_SOLD_ANALIZAT THEN RETURN 1;
                                         ELSE RETURN 0;
    END IF;
  END IF;
END;

FUNCTION GET_DENPART(aCodPart IN NUMBER) RETURN VARCHAR2
IS
DEN VARCHAR2(100) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT DEN_PART INTO DEN FROM NPART WHERE CODPART = aCODPART;
    EXCEPTION WHEN OTHERS THEN DEN := &apos;&apos;;
  END;
  RETURN DEN;
END;

PROCEDURE SET_PART_CURENT(aCODPART IN NUMBER)
IS
BEGIN
  PARTENER_CURENT := aCODPART;
END;

FUNCTION GET_PART_CURENT RETURN NUMBER
IS
BEGIN
  RETURN PARTENER_CURENT;
END;

PROCEDURE SET_PART_EDITAT(aCODPART IN NUMBER)
IS
BEGIN
  PARTENER_EDITAT := aCODPART;
END;

FUNCTION  CODPART_PART_EDITAT_VALID(aCODPART IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF PARTENER_EDITAT &lt;= 0 THEN RETURN 1;
  ELSE
    IF aCODPART = PARTENER_EDITAT THEN RETURN 1;
                                  ELSE RETURN 0;
    END IF;
  END IF;
END;

PROCEDURE SET_PART_ICONT_ANALIZAT(aICONT IN NUMBER)
IS
BEGIN
  PARTENER_ICONT_ANALIZAT := aICONT;
END;

FUNCTION GET_PART_ICONT_ANALIZAT RETURN NUMBER
IS
BEGIN
  RETURN PARTENER_ICONT_ANALIZAT;
END;

PROCEDURE SET_PART_CURENT_CF(aCODPART IN NUMBER)
IS
BEGIN
  PARTENER_CURENT_CF := aCODPART;
END;

FUNCTION GET_PART_CURENT_CF RETURN NUMBER
IS
BEGIN
  RETURN PARTENER_CURENT_CF;
END;

PROCEDURE SET_PART_CURENT_LOCATII(aCODPART IN NUMBER)
IS
BEGIN
  PARTENER_CURENT_LOCATII := aCODPART;
END;

FUNCTION GET_PART_CURENT_LOCATII RETURN NUMBER
IS
BEGIN
  RETURN PARTENER_CURENT_LOCATII;
END;

FUNCTION GET_COD_NPART1(aCodPart in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER
IS
  CPART1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT Coalesce(CodPart1, 0) INTO CPart1
    FROM NPart1 n1
    WHERE n1.CodPart = aCodPart AND aAn * 12 + aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS then CPart1 := -1;
  END;
  RETURN CPart1;
END;

FUNCTION GET_PART_COD_CARACT_LUNA(aCodPart in NUMBER, aAn IN NUMBER, aLuna IN NUMBER) RETURN NUMBER
IS
aCODIoPart  Number(20)  := -1;
aCODIoPart1 Number(20)  := -1;

BEGIN
  BEGIN
    SELECT Coalesce(CodIoPart, 0) INTO aCodIoPart FROM NPart1 n1
    WHERE n1.CodPart = aCodPart AND aAn * 12 + aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN aCodIoPart1 := -1;
  END;

  IF aCODIOPART &gt; 0 THEN
    BEGIN
      SELECT Coalesce(CodIoPart1, 0) INTO aCodIoPart1 FROM IoPart1 i1
      WHERE i1.CodIoPart = aCodIoPart AND aAn * 12 + aLuna BETWEEN i1.alstart AND i1.alstop;
    EXCEPTION WHEN OTHERS then aCodIoPart1 := -1;
    END;
  END IF;
  RETURN aCodIoPart1;
END;

FUNCTION GET_RECORD_PART_CARACT_LUNA(aCodPart IN NUMBER, An IN NUMBER, Luna IN NUMBER) RETURN DESCR_CONT_LUNA_CURSOR
IS
TMPCURSOR DESCR_CONT_LUNA_CURSOR;
IoPartCod NUMBER(20);
BEGIN
  BEGIN
    SELECT Coalesce(CodIoPart, -1) INTO IoPartCod FROM NPart1 n1
    WHERE n1.CodPart = aCodPart AND An * 12 + Luna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN IoPartCod := -1;
  END;

  IF IoPartCod &gt; 0 THEN
  BEGIN
     OPEN tmpCursor FOR
     SELECT * FROM IoPart1 i1
     WHERE i1.CodIoPart = IoPartCod AND An * 12 + Luna BETWEEN i1.alstart AND i1.alstop;
     EXCEPTION WHEN OTHERS THEN OPEN tmpCursor FOR SELECT * FROM IOPART1 WHERE 1=2;
   END;
   ELSE OPEN tmpCursor FOR SELECT * FROM IOPART1 WHERE 1=2;
  END IF;

  RETURN tmpcursor;
END;

PROCEDURE MAKE_CURS_GENERAL_LUNA(aDATA IN VARCHAR2)
IS
BEGIN
  DELETE FROM TMP_CURS_REGULARIZAT_LUNA;
  INSERT INTO TMP_CURS_REGULARIZAT_LUNA (CODGENERAL, CURS)
-- stef o obligatie se stinge in luna generarii acestui temporar nu aduce nici un curs de regularizare
-- chiar daca am avut regularizari anterioare, si in v_soldpartprec_ext calculeaza soldul respectivei obligatii la cursul initial
-- asa ca modific modificarea
  SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
  FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
  WHERE R.TIPREG = 46
    AND R.DATADOC &lt;= TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;)
  GROUP BY R1.CODGENERAL;
END;

PROCEDURE MAKE_CURS_MONEDA_LUNA(aDATA IN VARCHAR2)
IS
BEGIN
  DELETE FROM TMP_CURS_MONEDA_REG;
  INSERT INTO TMP_CURS_MONEDA_REG (CODMONEDA, CURS)
  SELECT M1.CODMONEDA, M1.CURS
  FROM REG M1
  WHERE M1.TIPREG = 46
    AND M1.DATADOC = (SELECT MAX(DATADOC) FROM REG M2 WHERE M1.TIPREG = 46 AND M1.CODMONEDA = M2.CODMONEDA AND M2.DATADOC &lt;= TO_DATE(aDATA, &apos;dd.mm.yyyy&apos;));
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER )
IS
Tmp NUMBER(20);
BEGIN
  SELECT CODPART INTO Tmp FROM NPART WHERE CodPart = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);
  --  nomPart --&gt;  500
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 500);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT &apos;Partener &quot;&apos;||den_part||&apos;&quot;&apos; INTO aDoc FROM npart WHERE codpart = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPART&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  UPDATE NARTOBJ SET CODPRODUCATOR = NULL WHERE CODPRODUCATOR = RECID;
  DELETE FROM NPARTCONCURENTI WHERE CodPart = RecId;
  DELETE FROM NPARTACTIVIT    WHERE CodPart = RecId;
  DELETE FROM NPARTDOMACT     WHERE CodPart = RecId;

	DELETE FROM NPART1          WHERE CODPART = RECID;
  DELETE FROM NPART1CRM       WHERE CODPART = RECID;
  DELETE FROM NPARTB          WHERE CODPART = RECID;
  DELETE FROM NPARTTR         WHERE CODPART = RECID;
  DELETE FROM NPARTDISC       WHERE CODPART = RECID;
  DELETE FROM NPARTCODFISC    WHERE CODPART = RECID;
  DELETE FROM NPARTLSTCLASE   WHERE CODPART = RECID;
  DELETE FROM SYNCPARTRETAIL  WHERE CODPART = RECID;

  FOR V_REC IN (SELECT * FROM NAGENDA WHERE CODPART = RECID)
  LOOP
    DELETE FROM NAGENDA1  WHERE CODAGENDA = V_REC.CODAGENDA;
    DELETE FROM NAGENDA   WHERE CODAGENDA = V_REC.CODAGENDA;
  END LOOP;
  DELETE FROM NPERSCONTACT    WHERE CODPART = RecId;
  DELETE FROM NARTCLI         WHERE CodPart = RecId;
  DELETE FROM NPART           WHERE CodPart = RecId;

  NotifyModif(2, RECID, &apos;NPART&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NPART FIELDS( CodPart ) VALUES (0) ;
  --  nomPart --&gt;  500
  PKG_CFGTABLES.EXT_INSERTRECORD(500);
 /* mutat in delphi pe NewRecord
  if pkg_categconst.GetValConstanta(&apos;DiscPartImplicit&apos;, pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) &gt; 0 then
    INSERT INTO  TMP_NPARTDISC (CodPartDisc,CodPart, CodCategDisc, Indexlocal, Cumulat, Offinvoice )
    SELECT -1, 0, D.CODCRITERIU, 1, D.Cumulat, D.Offinvoice
    FROM CRITERIIDISC D
    WHERE D.CODCRITERIU = pkg_categconst.GetValConstanta(&apos;DiscPartImplicit&apos;, pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU);
  end if;
*/
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aANSFARSIT   NUMBER(4);
  aLUNASFARSIT NUMBER(2);
  aCODFISCAL   VARCHAR(20) := &apos;&apos;;
  vIND         NUMBER(10) := 0;
  vDATA        DATE;
BEGIN
-- Master NPART
  INSERT INTO TMP_NPART (
    CodPart, Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart,
    ScadentaC, ScadentaV, Discount, CodCategDisc, Blocat, TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT,
    INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati, SursaLead, Lead, TVALAINCASARE, MODAPLICPROCDISC,
    PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj,SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct,
    DocDefOnorCom, ModPromoFactCom, VAlidarePretOferta, IESCUCOMANDA, VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ,
    CODCONTRACTCadru, EF_Item, EF_Party, DATANASTERE, GDPR, ZILELIVRARE, SAFT_EXPORT, Farapenalizari, INACTIV, preOfeFurnVar, Tipanalizapret, VerAvizIes,
    EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, EF_TAXE, CategTarif, ZileAchiz, Culoare 
  )
  SELECT
    CodPart, Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart,
    ScadentaC, ScadentaV, Discount, CodCategDisc, Blocat, TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT,
    INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati, SursaLead, Lead, TVALAINCASARE, Coalesce(MODAPLICPROCDISC, 0),
    PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj, SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct,
    Coalesce(DocDefOnorCom, 0), Coalesce(ModPromoFactCom,0), Coalesce(ValidarePretOferta, 0), Coalesce(IESCUCOMANDA, 0), VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ,
    CODCONTRACTCadru, Coalesce(EF_Item,0), Coalesce(EF_Party,0), DATANASTERE, GDPR, ZILELIVRARE, COALESCE(SAFT_EXPORT,0), coalesce(FaraPenalizari,0), coalesce(INACTIV, 0), coalesce( preOfeFurnVar, 0),
    coalesce(Tipanalizapret, 0), VerAvizIes, EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, Coalesce(EF_TAXE,0), Coalesce(CategTarif,0), ZileAchiz, Culoare
  FROM NPART
  WHERE CodPart = RecId;

-- Detail NPART1
  INSERT INTO  TMP_NPART1 (CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, CreditClient,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT, VolumTranzF, anstart, lunastart, alstart, alstop)
  SELECT                   CodPart, CodIOPART, CodPart1, CreditFurn, VolumTranzC, CreditClient,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT, VolumTranzF, anstart, lunastart, alstart, alstop
  FROM NPART1
  WHERE CodPart = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODPART1, ANSTART, LUNASTART FROM TMP_NPART1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NPART1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODPART1 = V_REC.CODPART1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

-- Detail NPARTB
  INSERT INTO  TMP_NPARTB ( CodPartB,CodPart,CodBank,Implicit,CodLocalit,ContBanca,Sucursala, CODSWIFT, TIPCOMISION, CONTTVA, OBS, CODMONEDA, SIMBOL )
  SELECT PB.CodPartB, PB.CodPart, PB.CodBank, PB.Implicit, PB.CodLocalit, PB.ContBanca, PB.Sucursala, PB.CODSWIFT, PB.TIPCOMISION, PB.CONTTVA, PB.OBS, PB.CODMONEDA, M.SIMBOL
  FROM NPARTB PB LEFT JOIN NMONEDE M ON M.CODMONEDA = Coalesce(PB.CODMONEDA, 0)
  WHERE CodPart = RecId;

-- Detail NPARTCODFISC
  INSERT INTO  TMP_NPARTCODFISC
  SELECT * FROM NPARTCODFISC  WHERE CODPART = RecId;
-- Detail NPARTLSTCLASE
  INSERT INTO  TMP_NPARTLSTCLASE
  SELECT * FROM NPARTLSTCLASE  WHERE CODPART = RecId;

-- Detail NAGENDA
  INSERT INTO  TMP_NAGENDA (
    obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,
    strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,Inactiv,CodCoresp,TranspClient,
    codbankcont,codpart,codgest,codsubunit, CODTIPSEDIU, CODFISCAL, CODAGENT,
    adresa,
    COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, Codclient, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1,
    EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2,
    Facturare, CODANTREPOZIT, ZileTransport, judet, VERFACT, VERDISPLIVR, VERPROFORMA, VERFACTAVIZ, VERAVIZIES)
  SELECT
    A.obs,A.codagenda,A.tip,A.codlocalit,A.sediusocial,A.telefon,A.fax,Replace(Replace(A.email,&apos; &apos;, &apos;&apos;),&apos;;&apos;, Chr(13)||Chr(10)) email,A.sector,
    A.strada,A.nr1,A.nr2,A.bloc,A.scara,A.etaj,A.apart,A.codpostal,A.km,A.Inactiv,A.CodCoresp,Coalesce(A.TranspClient, 3),
    A.codbankcont,A.codpart,A.codgest,A.codsubunit, A.CODTIPSEDIU, A.CODFISCAL, A.CODAGENT,
    L.DEN_LOCALIT || CHR(13) || GetAdresa(A.sector,A.strada,A.nr1,A.nr2,A.bloc,A.scara,A.etaj,A.apart,A.codpostal),
    A.COEFUTILAJE, A.SUPRAFATA, A.MODSERVIRE, A.IDSEDIU, A.COD_CODFISCAL, A.codclient,  A.codtraseu, A.poztraseu,A.codtraseu1, A.poztraseu1,
    Coalesce(A.EDI_EXPTIP,0), Coalesce(A.EDI_PARTTIP,0), A.EDI_PARTID, Coalesce(A.EDI_OBJTIP,0), A.GLN, A.GESTLIVRARE, A.LONGITUDINE, A.LATITUDINE, A.OBS2,
    C.Obs, A.CODANTREPOZIT, A.ZileTransport, j.den_judet, A.VERFACT, A.VERDISPLIVR, A.VERPROFORMA, A.VERFACTAVIZ, A.VERAVIZIES
  FROM  NAGENDA A
    LEFT JOIN NLOCALIT L ON A.CodLocalit = L.CodLocalit
    LEFT JOIN NJUDET J ON L.CODJUDET = J.CODJUDET
    LEFT JOIN TRASEULIVR T ON A.Codtraseu = T.CODTRASEULIVR
    LEFT JOIN NAGENDA C ON Coalesce(A.CodCoresp, 0) = C.CODAGENDA
  WHERE A.codpart = RecId;

  UPDATE TMP_NAGENDA A SET
  SVERFACT     = (SELECT L.NAME FROM WINMADMIN.LISTS L WHERE L.LISTID = 101 AND L.LISTVER = A.VERFACT),
  SVERDISPLIVR = (SELECT L.NAME FROM WINMADMIN.LISTS L WHERE L.LISTID = 102 AND L.LISTVER = A.VERDISPLIVR),
  SVERPROFORMA = (SELECT L.NAME FROM WINMADMIN.LISTS L WHERE L.LISTID = 189 AND L.LISTVER = A.VERPROFORMA),
  SVERFACTAVIZ = (SELECT L.NAME FROM WINMADMIN.LISTS L WHERE L.LISTID = 141 AND L.LISTVER = A.VERFACTAVIZ),
  SVERAVIZIES  = (SELECT L.NAME FROM WINMADMIN.LISTS L WHERE L.LISTID = 140 AND L.LISTVER = A.VERAVIZIES);

-- detaliu NAGENDA1
  INSERT INTO TMP_NAGENDA1(CODAGENDA1, CODAGENDA, ANSTART, LUNASTART, CREDITCLIENT, ZILEDEPASIRE, NRFACTSOLD, SCADENTAV)
  SELECT CODAGENDA1, CODAGENDA, ANSTART, LUNASTART, CREDITCLIENT, ZILEDEPASIRE, NRFACTSOLD, SCADENTAV
  FROM NAGENDA1 A1
  WHERE EXISTS (SELECT CODAGENDA FROM TMP_NAGENDA WHERE CODAGENDA = A1.CODAGENDA);

  FOR V_REC_AG IN (SELECT CODAGENDA FROM TMP_NAGENDA) LOOP
    aANSFARSIT := 0; aLUNASFARSIT := 0;
    FOR V_REC IN (SELECT CODAGENDA1, ANSTART, LUNASTART FROM TMP_NAGENDA1 WHERE CODAGENDA = V_REC_AG.CODAGENDA ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_NAGENDA1
        SET
          ANSFARSIT   = aANSFARSIT,
          LUNASFARSIT = aLUNASFARSIT
        WHERE
          CODAGENDA1 = V_REC.CODAGENDA1;
      END IF;

      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
    END LOOP;
  END LOOP;

-- Detail NPARTTR
  INSERT INTO  TMP_NPARTTR ( CodPartTr,CodPart,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat, MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL )
  SELECT CodPartTr,CodPart,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat,MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL
  FROM NPARTTR
  WHERE CodPart = RecId;

-- Detail NPERSCONTACT
  INSERT INTO  TMP_NPERSCONTACT ( codpersc,nume,prenume,telefon,email,functie,datanastere,SERIEBI, NRBI, ELIBERATBI, DATABI, CNP, rzona,id,tip,codbankcont,codpart,implicit, Obs, CODLOCATIE, NUMELOCATIE )
  SELECT codpersc,
         PC.nume,
         PC.prenume,
         PC.telefon,
         PC.email,
         PC.functie,
         PC.datanastere,
         PC.SERIEBI,
         PC.NRBI,
         PC.ELIBERATBI,
         PC.DATABI,
         PC.CNP,
         PC.rzona,
         PC.id,
         PC.tip,
         PC.codbankcont,
         PC.codpart,
         Coalesce(PC.implicit,0),
         PC.Obs,
         PC.CODLOCATIE,
         A.OBS
  FROM
    NPERSCONTACT PC
    LEFT JOIN NAGENDA A ON A.CODAGENDA = PC.CODLOCATIE
  WHERE PC.codpart = RecId;


-- Detail PARTTOT
  INSERT INTO  TMP_PARTTOT ( CodPartTot,CodPart,SoldReal,Neoperat,anstart,lunastart )
  SELECT CodPartTot,CodPart,SoldReal,Neoperat,anstart,lunastart
  FROM PARTTOT
  WHERE CodPart = RecId
    AND getdata(anstart,lunastart) = ( SELECT MAX(getdata(anstart,lunastart)) FROM logusertab, PARTTOT WHERE user = trim(upper(numeuser)) AND getdata(anstart,lunastart) &lt;= getdata(ancurent,lunacurenta) AND CodPart = RecId);


-- Detail SOLDPART
  INSERT INTO  TMP_SOLDPART ( CodSoldPart,CodPart,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart )
  SELECT CodSoldPart,CodPart,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart
  FROM SOLDPART
  WHERE CodPart = RecId
    AND getdata(anstart,lunastart) = ( SELECT MAX(getdata(anstart,lunastart)) FROM logusertab, SOLDPART WHERE user = trim(upper(numeuser)) AND getdata(anstart,lunastart) &lt;= getdata(ancurent,lunacurenta) AND CodPart = RecId);

-- Detail NPARTDISC
  INSERT INTO  TMP_NPARTDISC ( CodPartDisc,CodPart,CodCategDisc, Indexlocal, Cumulat, Offinvoice )
  SELECT P.CodPartDisc,P.CodPart,P.CodCategDisc, P.Indexlocal,
  CASE
    WHEN  NVL(D.PUNCTE, 0) = 0 THEN D.Cumulat
  END,
  CASE
    WHEN NVL(D.PUNCTE, 0) = 1 THEN 5
    WHEN NVL(D.PUNCTE, 0) = 0 AND NVL(D.Offinvoice, 0) = 0 THEN 4
    ELSE D.Offinvoice
  END
  FROM NPARTDISC P, CRITERIIDISC D
  WHERE P.CodPart = RecId and D.CODCRITERIU = P.CodCategDisc;

  INSERT INTO TMP_NPARTTR_LNK(CODPARTTRLNK, CODPARTTR, CODPART, SEDII, DELEGAT, MIJLTRANSP, NRTRANSP)
  SELECT  LNK.CODPARTTRLNK, LNK.CODPARTTR, LNK.CODPART, LNK.SEDII, TR.DELEGAT, TR.MIJLTRANSP, TR.NRTRANSP
  FROM NPARTTR_LNK LNK, NPARTTR TR
  WHERE LNK.CODPART       = RECID
    AND LNK.CODPARTTR = TR.CODPARTTR;

  INSERT INTO TMP_NPARTTR_LNK1 (CODPARTTRLNK1, CODPARTTRLNK, CODAGENDA, SEDIU)
  SELECT CODPARTTRLNK1, CODPARTTRLNK, AG.CODAGENDA, AG.OBS
  FROM NPARTTR_LNK1 LNK1, NAGENDA AG
  WHERE AG.CODAGENDA = LNK1.CODAGENDA
    AND EXISTS (SELECT CODPARTTRLNK FROM TMP_NPARTTR_LNK WHERE CODPARTTRLNK = LNK1.CODPARTTRLNK);

  FOR V_REC IN (SELECT * FROM TMP_NAGENDA)
  LOOP
    IF Coalesce(V_REC.COD_CODFISCAL, 0) &lt;&gt; 0 THEN
      BEGIN
        SELECT Coalesce(CODFISCAL, &apos;&apos;) INTO ACODFISCAL FROM NPARTCODFISC WHERE COD_CODFISCAL = V_REC.COD_CODFISCAL;
        EXCEPTION WHEN OTHERS THEN ACODFISCAL := &apos;?&apos;;
      END;
      IF aCODFISCAL &lt;&gt; &apos;?&apos; THEN
        UPDATE TMP_NAGENDA
        SET CODFISCAL = aCODFISCAL
        WHERE CODAGENDA = V_REC.CODAGENDA;
      END IF;
    END IF;
  END LOOP;

  -- Detail NPARTCONCURENTI
  DELETE TMP_NPARTCONCURENTI;
  INSERT INTO TMP_NPARTCONCURENTI (CodPartConcurent, CodPart, CodConcurent, DenConcurent, Codpart1crm)
  SELECT PC.CodPartConcurent, PC.CodPart, PC.CodConcurent, C.DenConcurent, PC.Codpart1crm
  FROM NPARTCONCURENTI PC
       INNER JOIN CONCURENTI C ON C.CodConcurent = PC.CodConcurent
       INNER JOIN NPART1CRM P1 ON P1.CODPART = PC.CODPART AND P1.CODPART1CRM = PC.CODPART1CRM
  WHERE PC.CodPart = RecId;

  -- Detail NPARTACTIVIT
  DELETE TMP_NPARTACTIVIT;
  INSERT INTO TMP_NPARTACTIVIT (CodPartActivit, CodPart, Dim, CodActivit, DenActivit, Codpart1crm)
  SELECT PA.CodPartActivit, PA.CodPart, PA.Dim, PA.CodActivit, A.Den_Activit, PA.Codpart1crm
  FROM NPARTACTIVIT PA
    INNER JOIN NACTIVIT A ON A.CodActivit = PA.CodActivit
  WHERE PA.CodPart = RecId;

  -- TMP_NPORTOPORTUNITATI
  DELETE TMP_NPARTOPORTUNITATI;
  INSERT INTO TMP_NPARTOPORTUNITATI (CodOportunitate, PrefixDoc, NrDoc, DataDoc, CodCarnetDoc, CodPartener, CodMoneda, Tip, CodAgent, VenitEst, VenitProb)
  SELECT O.CodOportunitate, O.PrefixDoc, O.NrDoc, O.DataDoc, O.CodCarnetDoc, O.CodPartener, O.CodMoneda, O.Tip, O.CodAgent,
         O.VenitEst, O.VenitProb
  FROM OPORTUNITATI O
  WHERE O.CodPartener = RecId;

  INSERT INTO TMP_NPARTSUBUNIT(CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ)
  SELECT CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ
  FROM NPARTSUBUNIT
  WHERE CODPART = RECID
  AND Coalesce(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, Coalesce(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE);

  INSERT INTO TMP_NPARTDOMACT (CODPARTDOMACT, CODPART, CODDOMENIUACT, DENDOMENIUACT, CODCAEN, CODPART1CRM)
  SELECT D.CODPARTDOMACT, D.CODPART, D.CODDOMENIUACT, DA.DENDOMENIUACT, DA.CODCAEN, D.CODPART1CRM
  FROM NPARTDOMACT D
       LEFT JOIN DOMENIIACT DA ON DA.CODDOMENIUACT = D.CODDOMENIUACT
  WHERE D.CODPART = RECID;

  INSERT INTO TMP_NPART1CRM (codpart1crm,codpart,anstart,lunastart,cifraafaceri,nrangajati,lead,sursalead,Stare, codresponsabil, MODPLATA, CIP, DATASTART, DATAEND,profit)
  select codpart1crm,codpart,anstart,lunastart,cifraafaceri,nrangajati,lead,sursalead,Coalesce(Stare,0), codresponsabil, MODPLATA, CIP, DATASTART, DATAEND,profit
  from
    npart1crm
  where
    codpart = recid;

  UPDATE TMP_NPART1CRM
  SET
   DATASTART = TO_DATE(&apos;01.&apos; || LUNASTART || &apos;.&apos; || ANSTART, &apos;dd.mm.yyyy&apos;)
  WHERE
    DATASTART IS NULL
    AND ANSTART IS NOT NULL
    AND LUNASTART IS NOT NULL;

  vInd     := 0;
  FOR v_rec IN
   (
     SELECT * FROM TMP_NPART1CRM
     ORDER BY DataStart  desc
   ) LOOP
     if vInd &gt; 0 AND V_REC.DATAEND IS NULL then
       UPDATE Tmp_NPART1CRM SET DataEnd = TO_DATE(vDATA, &apos;dd.mm.yyyy&apos;) WHERE CODPART1CRM = v_rec.CODPART1CRM;
     end if;
     vDATA  := TO_DATE(v_rec.DATASTART - 1, &apos;dd.mm.yyyy&apos;);
     vInd := vInd + 1;
  END LOOP;
  --  nomPart --&gt;  500
  PKG_CFGTABLES.EXT_GOTORECORD(500);


/*
  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODPART1CRM, ANSTART, LUNASTART FROM TMP_NPART1CRM ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NPART1CRM
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODPART1CRM = V_REC.CODPART1CRM;
    END IF;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
*/
  COMMIT;
END;


PROCEDURE DOSYNCPARTRETAIL(aCODPART IN NUMBER)
IS
BEGIN
  FOR V_REC  IN
    ( SELECT TO_NUMBER(Coalesce(CV.VALOARE, &apos;0&apos;)) AS CODPOSTRETAIL
      FROM (
        SELECT CL.CODCONSTLUNA
        FROM CONST1 C1
          INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
          INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        WHERE UPPER(C1.simbol) = &apos;SYNCPARTRETAIL&apos;
          AND CL.USERID =  PKG_GLOBALS.GETUSERID
          AND PKG_GLOBALS.ANLUNALUCRU BETWEEN CL.ALStart AND CL.ALStop
       ) C
       LEFT JOIN CONSTVAL CV ON cv.codconstluna = c.codconstluna
    )
  LOOP
    UPDATE SYNCPARTRETAIL
    SET
      SINCRONIZAT = 0,
      DATA = SYSDATE
    WHERE
      CODPART = aCODPART
      AND CODPOSTRETAIL = V_REC.CODPOSTRETAIL;

    IF  sql%rowcount = 0 then
      INSERT INTO SYNCPARTRETAIL (CODSYNCPART, CODPART, CODPOSTRETAIL, SINCRONIZAT, DATA)
      VALUES (SEQ_SYNCPARTRETAIL_CODSYNCPART.NEXTVAL, aCODPART, V_REC.CODPOSTRETAIL, 0,SYSDATE);
    END IF;
  END LOOP;

END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo     INTEGER := 0;
  vAn        INTEGER := 0;
  vLuna      INTEGER := 0;
  vCod       NUMBER(20);
  aDoc       varchar2(200);
  aOldBlocat number(1);
  aNewBlocat number(1);
  sObs       varchar2(50);
  vTVAI      number(1);
  sCUI       varchar2(50);
BEGIN
  --  nomPart --&gt;  500
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (500);
--  insert into x sql (select Count(*) from tmp_nagenda);
  IF Operation = 0 THEN  -- UPDATE

-- Master NPART
    SELECT  CodPart INTO RecId FROM TMP_NPART;

    sObs := &apos;&apos;;
    begin
      select Coalesce(blocat,0) into aOldBlocat from npart where codpart = RecID;
      select Coalesce(blocat,0) into aNewBlocat from tmp_npart;
      if aOldBlocat = 0 and aNewBlocat = 1 then
        sObs := &apos;(blocare partener)&apos;;
      else if aOldBlocat = 1 and aNewBlocat = 0 then
        sObs := &apos;(deblocare partener)&apos;;
      end if; end if;
    exception when others then sObs := &apos;&apos;;
    end;

    UPDATE NPART SET
      (
        Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart, ScadentaC, ScadentaV, Discount, CodCategDisc,
        Blocat, TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT, INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati,
        SursaLead, Lead, TVALAINCASARE,
				MODAPLICPROCDISC,
				PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj, SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct, DocDefOnorCom,
        ModPromoFactCom, ValidarePretOferta, IESCUCOMANDA,VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ, CODCONTRACTCadru, EF_Item, EF_Party, DATANASTERE, GDPR, ZILELIVRARE, SAFT_EXPORT,
        FaraPenalizari,
        INACTIV, preOfeFurnVar, Tipanalizapret, VerAvizIes, EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, EF_TAXE, CategTarif, ZileAchiz, Culoare
      ) = (
        SELECT
          Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart, ScadentaC, ScadentaV, Discount, CodCategDisc,
          Blocat, TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT, INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati,
          SursaLead, Lead, TVALAINCASARE,
					0, --MODAPLICPROCDISC,
					PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj, SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct, DocDefOnorCom,
          ModPromoFactCom, ValidarePretOferta, IESCUCOMANDA,VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ, CODCONTRACTCadru, EF_Item, EF_Party, DATANASTERE, GDPR, ZILELIVRARE, SAFT_EXPORT,
          FaraPenalizari,
          INACTIV, preOfeFurnVar, Tipanalizapret, VerAvizIes, EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, EF_TAXE, CategTarif, ZileAchiz, Culoare
        FROM TMP_NPART
      )
    WHERE npart.CodPart = RecId;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Partener &quot;&apos;||den_part||&apos;&quot;&apos; INTO aDoc FROM npart WHERE codpart = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPART&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, sObs, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

-- Detail NPART1
   DELETE FROM NPART1 WHERE CODPART = RECID AND CODPART1 NOT IN (SELECT CODPART1 FROM TMP_NPART1);

   INSERT INTO  NPART1 ( CodPart,CodIOPART,CodPart1,CreditFurn,VolumTranzC,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT,CreditClient,VolumTranzF,anstart,lunastart )
    ( SELECT RecId,CodIOPART, seq_NPART1_CodPart1.Nextval ,CreditFurn,VolumTranzC,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT,CreditClient,VolumTranzF,anstart,lunastart FROM TMP_NPART1 WHERE CODPART1 &lt; 0);


  FOR v_rec IN ( SELECT * FROM TMP_NPART1 WHERE Coalesce(CodPart1,0) &gt; 0  ORDER BY CodPart1 ) LOOP
    SELECT Decode(CodIOPART,v_rec.CodIOPART,0,1) + Decode(CreditFurn,v_rec.CreditFurn,0,1) +
           Decode(VolumTranzC, v_rec.VolumTranzC,0,1) + Decode(CreditClient,v_rec.CreditClient,0,1) +
           Decode(SCADENTAV,   v_rec.SCADENTAV  ,0,1) + Decode(SCADENTAC,v_rec.SCADENTAC,0,1) +
           Decode(CASSBAZAMIN, v_rec.CASSBAZAMIN,0,1) + Decode(DISCOUNT,v_rec.DISCOUNT,0,1) +
           Decode(SimbolCASS,  v_rec.SimbolCASS, 0,1) + Decode(GDPR,  v_rec.GDPR, 0,1) +
           Decode(VolumTranzF,v_rec.VolumTranzF,0,1) ,anstart, lunastart
    INTO vRecNo,vAn,vLuna
    FROM NPART1 WHERE CodPart1 = Coalesce(v_rec.CodPart1,0);
    IF (vRecNo &gt; 0) THEN
      IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
        UPDATE NPART1
        SET CodIOPART    = v_rec.CodIOPART,
            CreditFurn   = v_rec.CreditFurn,
            VolumTranzC  = v_rec.VolumTranzC,
            CreditClient = v_rec.CreditClient,
            VolumTranzF  = v_rec.VolumTranzF,
            SCADENTAV    = v_rec.SCADENTAV,
            SCADENTAC    = v_rec.SCADENTAC,
            CASSBAZAMIN  = v_rec.CASSBAZAMIN,
            SimbolCASS   = v_rec.SimbolCASS,
            GDPR         = v_rec.GDPR,
            DISCOUNT     = v_rec.DISCOUNT
        WHERE CodPart1 = v_rec.CodPart1;
      ELSE
        INSERT INTO NPART1 ( CodPart,CodIOPART,CodPart1,CreditFurn,VolumTranzC,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,
                             DISCOUNT,CreditClient,VolumTranzF,anstart,lunastart )
        VALUES ( RecId,v_rec.CodIOPART,Seq_NPART1_CodPart1.NextVal,v_rec.CreditFurn,v_rec.VolumTranzC,v_rec.SCADENTAV,v_rec.SCADENTAC,v_rec.CASSBAZAMIN, v_rec.SimbolCASS, v_rec.GDPR ,
                 v_rec.DISCOUNT,v_rec.CreditClient,v_rec.VolumTranzF,v_rec.anstart,v_rec.lunastart );
      END IF;
    END IF;
  END LOOP;



-- Detail NPARTB
    DELETE FROM NPARTB WHERE ( CodPart = RecId AND CodPartB NOT IN ( SELECT CodPartB FROM TMP_NPARTB WHERE Coalesce(CodPartB,0) &lt;&gt; 0));

    INSERT INTO NPARTB ( CodPartB,CodPart,CodBank,Implicit,CodLocalit,ContBanca,Sucursala, CODSWIFT, TIPCOMISION, CONTTVA, OBS, CODMONEDA )
      SELECT  seq_NPARTB_CodPartB.Nextval , RecId ,CodBank,Implicit,CodLocalit,ContBanca,Sucursala, CODSWIFT, TIPCOMISION, CONTTVA, OBS, CODMONEDA
      FROM TMP_NPARTB WHERE CodPartB &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_NPARTB WHERE Coalesce(CodPartB,0) &gt; 0  ORDER BY CodPartB ) LOOP
      SELECT count(*) INTO vRecNo FROM NPARTB WHERE CodPartB = Coalesce(v_rec.CodPartB,0);
      IF(vRecNo=1) THEN
        UPDATE NPARTB SET CodPart = RecId ,CodBank = v_rec.CodBank,Implicit = v_rec.Implicit,CodLocalit = v_rec.CodLocalit,ContBanca = v_rec.ContBanca,
        Sucursala   = v_rec.Sucursala,
        CODSWIFT    = v_rec.CODSWIFT,
        TIPCOMISION = V_REC.TIPCOMISION,
        CONTTVA     = V_REC.CONTTVA,
        OBS         = V_REC.OBS,
        CODMONEDA   = V_REC.CODMONEDA
      WHERE CodPartB = v_rec.CodPartB;
      END IF;
    END LOOP;



-- Detail NPARTCODFISC
    DELETE FROM NPARTCODFISC WHERE CodPart = RecId AND COD_CODFISCAL NOT IN ( SELECT COD_CODFISCAL FROM TMP_NPARTCODFISC );

/*

    INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
    SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, RecId , CODFISCAL, PRINCIPAL
     FROM TMP_NPARTCODFISC WHERE COD_CODFISCAL &lt; 0 ;
*/
    FOR V_REC IN (SELECT * FROM TMP_NPARTCODFISC WHERE COD_CODFISCAL &lt; 0)
    LOOP
       SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_NAGENDA
       SET    COD_CODFISCAL = VCOD
       WHERE  COD_CODFISCAL = V_REC.COD_CODFISCAL;

      INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
      VALUES (VCOD, RecId , trim(V_REC.CODFISCAL), V_REC.PRINCIPAL);


    END LOOP;

    FOR V_REC IN ( SELECT * FROM TMP_NPARTCODFISC WHERE Coalesce(COD_CODFISCAL, 0) &gt; 0 ORDER BY COD_CODFISCAL ) LOOP
       UPDATE NPARTCODFISC
       SET
        CodPart   = RecId,
        CODFISCAL = trim(V_REC.CODFISCAL),
        PRINCIPAL =  V_REC.PRINCIPAL
       WHERE
        COD_CODFISCAL = V_REC.COD_CODFISCAL;
    END LOOP;

-- Detail NPARTCODFISC
    DELETE FROM NPARTLSTCLASE WHERE CodPart = RecId AND CODNPARTLSTCLASE NOT IN ( SELECT CODNPARTLSTCLASE FROM TMP_NPARTLSTCLASE );

    INSERT INTO NPARTLSTCLASE (CODNPARTLSTCLASE, CODPART, CODCLASA)
    SELECT SEQ_NPARTLC_CODNPARTLC.NEXTVAL, RecId , CODCLASA
     FROM TMP_NPARTLSTCLASE WHERE CODNPARTLSTCLASE &lt; 0 ;

    FOR V_REC IN ( SELECT * FROM TMP_NPARTLSTCLASE WHERE Coalesce(CODNPARTLSTCLASE, 0) &gt; 0 ORDER BY CODNPARTLSTCLASE ) LOOP
       UPDATE NPARTLSTCLASE
       SET
        CodPart   = RecId,
        CODCLASA  = V_REC.CODCLASA
       WHERE
        CODNPARTLSTCLASE = V_REC.CODNPARTLSTCLASE;
    END LOOP;



-- Detail NAGENDA


    FOR V_REC IN (SELECT * FROM NAGENDA WHERE ( codpart = RecId AND codagenda NOT IN ( SELECT codagenda FROM TMP_NAGENDA WHERE Coalesce(codagenda,0) &lt;&gt; 0)))
    LOOP
      DELETE FROM NPARTTR_LNK1 WHERE CODAGENDA = V_REC.CODAGENDA;
      DELETE FROM NAGENDA1 WHERE CODAGENDA = V_REC.CODAGENDA;
      DELETE FROM NAGENDA  WHERE CODAGENDA = V_REC.CODAGENDA;
    END LOOP;


    FOR V_REC IN
    (SELECT A1.CODAGENDA1, A1.CODAGENDA
     FROM
       NAGENDA1 A1,
       NAGENDA A
      WHERE
       A.codpart = RecId
       AND A.CODAGENDA = A1.CODAGENDA
       AND A1.codagenda1 NOT IN ( SELECT codagenda1 FROM TMP_NAGENDA1)
    )
    LOOP
      DELETE FROM NAGENDA1 WHERE CODAGENDA1 = V_REC.CODAGENDA1;
      PRC_AL_REFRESH(&apos;NAGENDA1&apos;, V_REC.CODAGENDA);
    END LOOP;




    FOR V_REC IN (SELECT * FROM TMP_NAGENDA WHERE codagenda &lt; 0)
    LOOP
      SELECT seq_NAGENDA_codagenda.Nextval INTO VCOD FROM DUAL;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NAGENDA&apos;, VCOD, V_REC.CODAGENDA);

      UPDATE TMP_NPERSCONTACT
      SET
        CODLOCATIE = VCOD
      WHERE
        CODLOCATIE = V_REC.CODAGENDA;


      UPDATE TMP_NPARTTR_LNK1
      SET
        CODAGENDA = VCOD
      WHERE
        CODAGENDA = V_REC.CODAGENDA;


      UPDATE TMP_NAGENDA1
      SET
        CODAGENDA = VCOD
      WHERE
        CODAGENDA = V_REC.CODAGENDA;

      UPDATE TMP_NAGENDA
      SET
        CODAGENDA = VCOD,
        CODPART   = RECID,
        ADRESA    = &apos;(NEW)(RECORD)(FROM)(INSERT)&apos;
      WHERE
        CODAGENDA = V_REC.CODAGENDA;

      UPDATE TMP_NAGENDA
      SET
        CODCORESP = VCOD
      WHERE
        CODCORESP = V_REC.CODAGENDA;

    END LOOP;

    INSERT INTO NAGENDA(
      obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,
      CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL,  CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, Inactiv, Codcoresp, TranspClient,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport,
      VERFACT, VERDISPLIVR, VERPROFORMA, VERFACTAVIZ, VERAVIZIES
     )
    SELECT
      obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,
      CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, Inactiv, Codcoresp, TranspClient,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport,
      VERFACT, VERDISPLIVR, VERPROFORMA, VERFACTAVIZ, VERAVIZIES
    FROM TMP_NAGENDA
    WHERE ADRESA = &apos;(NEW)(RECORD)(FROM)(INSERT)&apos;;

    FOR v_rec IN ( SELECT * FROM TMP_NAGENDA WHERE Coalesce(codagenda,0) &gt; 0  ORDER BY codagenda ) LOOP
      SELECT count(*) INTO vRecNo FROM NAGENDA WHERE codagenda = Coalesce(v_rec.codagenda,0);
      IF(vRecNo=1) THEN
        UPDATE NAGENDA
        SET
          obs         = v_rec.obs,
          tip         = v_rec.tip,
          codlocalit  = v_rec.codlocalit,
          sediusocial = v_rec.sediusocial,
          telefon     = v_rec.telefon,
          fax         = v_rec.fax,
          email       = v_rec.email,
          sector      = v_rec.sector,
          strada      = v_rec.strada,
          nr1         = v_rec.nr1,
          nr2         = v_rec.nr2,
          bloc        = v_rec.bloc,
          scara       = v_rec.scara,
          etaj        = v_rec.etaj,
          apart       = v_rec.apart,
          codpostal   = v_rec.codpostal,
          km          = v_rec.km,
          codbankcont = v_rec.codbankcont,
          codpart     = RecId ,
          codgest     = v_rec.codgest,
          codsubunit  = v_rec.codsubunit,
          CODTIPSEDIU = V_REC.CODTIPSEDIU,
          CODFISCAL   = V_REC.CODFISCAL,
          CODAGENT    = V_REC.CODAGENT,
          CODCLIENT   = V_REC.CODCLIENT,
          COEFUTILAJE = V_REC.COEFUTILAJE,
          SUPRAFATA   = V_REC.SUPRAFATA,
          MODSERVIRE  = V_REC.MODSERVIRE,
          IDSEDIU     = V_REC.IDSEDIU,
          COD_CODFISCAL = V_REC.COD_CODFISCAL,
          codtraseu		= v_rec.codtraseu,
					poztraseu		= v_rec.poztraseu,
          codtraseu1	= v_rec.codtraseu1,
					poztraseu1	= v_rec.poztraseu1,
					Inactiv	    = v_rec.Inactiv,
					codCoresp		= v_rec.codCoresp,
          TranspClient= v_rec.TranspClient,
          EDI_EXPTIP  = v_rec.EDI_EXPTIP,
          EDI_PARTTIP = v_rec.EDI_PARTTIP,
          EDI_PARTID  = v_rec.EDI_PARTID,
          EDI_OBJTIP  = v_rec.EDI_OBJTIP,
          GLN         = v_rec.GLN,
          GESTLIVRARE = V_REC.GESTLIVRARE,
          LONGITUDINE = V_REC.LONGITUDINE,
          LATITUDINE   = V_REC.LATITUDINE,
          OBS2          = V_REC.OBS2,
          CODANTREPOZIT = V_REC.CODANTREPOZIT,
          ZileTransport = V_REC.ZileTransport,
          VERFACT       = v_rec.VERFACT,
          VERDISPLIVR   = v_rec.VERDISPLIVR,
          VERPROFORMA   = v_rec.VERPROFORMA,
          VERFACTAVIZ   = v_rec.VERFACTAVIZ,
          VERAVIZIES    = v_rec.VERAVIZIES
        WHERE
         codagenda = v_rec.codagenda;
      END IF;
    END LOOP;


   FOR V_REC IN (SELECT * FROM TMP_NAGENDA1)
   LOOP
     IF V_REC.CODAGENDA1 &lt; 0 THEN
       INSERT INTO NAGENDA1 (CODAGENDA1, CODAGENDA, ANSTART, LUNASTART, CREDITCLIENT, ZILEDEPASIRE, NRFACTSOLD, SCADENTAV)
       VALUES(SEQ_NAGENDA1_CODAGENDA1.NEXTVAL, V_REC.CODAGENDA, V_REC.ANSTART, V_REC.LUNASTART, V_REC.CREDITCLIENT, V_REC.ZILEDEPASIRE, V_REC.NRFACTSOLD, V_REC.SCADENTAV);
     ELSE
       UPDATE NAGENDA1
       SET
         ANSTART      = V_REC.ANSTART,
         LUNASTART    = V_REC.LUNASTART,
         CREDITCLIENT = V_REC.CREDITCLIENT,
         ZILEDEPASIRE = V_REC.ZILEDEPASIRE,
         NRFACTSOLD   = V_REC.NRFACTSOLD,
         SCADENTAV    = V_REC.SCADENTAV
       WHERE
        CODAGENDA1 = V_REC.CODAGENDA1;
     END IF;
     PRC_AL_REFRESH(&apos;NAGENDA1&apos;, V_REC.CODAGENDA);
   END LOOP;

-- Detail NPARTTR

   DELETE FROM NPARTTR WHERE ( CodPart = RecId AND CodPartTr NOT IN ( SELECT CodPartTr FROM TMP_NPARTTR WHERE Coalesce(CodPartTr,0) &lt;&gt; 0));

    INSERT INTO NPARTTR ( CodPartTr,CodPart,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat,MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL )
      SELECT  seq_NPARTTR_CodPartTr.Nextval , RecId ,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat,MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL
      FROM TMP_NPARTTR WHERE CodPartTr &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NPARTTR WHERE Coalesce(CodPartTr,0) &gt; 0 ORDER BY CodPartTr ) LOOP
      SELECT count(*) INTO vRecNo FROM NPARTTR WHERE CodPartTr = Coalesce(v_rec.CodPartTr,0);
      IF(vRecNo=1) THEN
        UPDATE NPARTTR
        SET
          CodPart    = RecId ,
          Delegat    = v_rec.Delegat,
          cnp        = v_rec.cnp,
          doc        = v_rec.doc,
          SerieDoc   = v_rec.SerieDoc,
          NrDoc      = v_rec.NrDoc,
          Eliberat   = v_rec.Eliberat,
          MijlTransp = v_rec.MijlTransp,
          NrTransp   = v_rec.NrTransp,
          ACTIV      = V_REC.ACTIV,
          IMPLICIT   = V_REC.IMPLICIT,
          DATADOC    = V_REC.DATADOC,
          OBS        = V_REC.OBS,
          PERMIS     = V_REC.PERMIS,
          NRPASS     = V_REC.NRPASS,
          CODTARA    = V_REC.CodTara,
          ADRESA     = V_REC.Adresa,
          CODLOCALIT = V_REC.CodLocalit,
          TELEFON    = V_REC.Telefon
        WHERE
          CodPartTr = v_rec.CodPartTr;
      END IF;
    END LOOP;

-- Detail NPARTTR_Lnk

-- DELETE FROM NPARTTR_LNK LNK WHERE CODPART = RECID AND NOT EXISTS(SELECT CODPARTTRLNK FROM TMP_NPARTTR_LNK WHERE CODPARTTRLNK = LNK.CODPARTTRLNK);
  FOR V_REC IN (SELECT * FROM NPARTTR_LNK LNK WHERE CODPART = RECID AND NOT EXISTS(SELECT CODPARTTRLNK FROM TMP_NPARTTR_LNK WHERE CODPARTTRLNK = LNK.CODPARTTRLNK))
  LOOP
    DELETE FROM NPARTTR_LNK  WHERE CODPARTTRLNK = V_REC.CODPARTTRLNK;
    DELETE FROM NPARTTR_LNK1 WHERE CODPARTTRLNK = V_REC.CODPARTTRLNK;
  END LOOP;


 FOR V_REC IN
 (
   SELECT LNK.CODPARTTRLNK, LNK1.CODPARTTRLNK1
   FROM
     NPARTTR_LNK  LNK,
     NPARTTR_LNK1 LNK1
   WHERE
    LNK.CODPART = RECID
    AND LNK1.CODPARTTRLNK = LNK.CODPARTTRLNK
    AND NOT EXISTS (SELECT CODPARTTRLNK1 FROM TMP_NPARTTR_LNK1 WHERE CODPARTTRLNK1 = LNK1.CODPARTTRLNK1)
)
 LOOP
   DELETE FROM NPARTTR_LNK1 WHERE CODPARTTRLNK1 = V_REC.CODPARTTRLNK1;
 END LOOP;

 FOR V_REC IN (SELECT * FROM TMP_NPARTTR_LNK) LOOP
   IF V_REC.CODPARTTRLNK &gt; 0 THEN
     UPDATE NPARTTR_LNK
     SET
       CODPARTTR = V_REC.CODPARTTR,
       SEDII     = V_REC.SEDII,
       CODPART   = RECID
     WHERE
      CODPARTTRLNK = V_REC.CODPARTTRLNK;
   ELSE
     SELECT SEQ_NPARTTR_LNK_CODPARTTRLNK.NEXTVAL INTO VCOD FROM DUAL;
     UPDATE TMP_NPARTTR_LNK1
     SET
      CODPARTTRLNK = VCOD
     WHERE
       CODPARTTRLNK = V_REC.CODPARTTRLNK;

     INSERT INTO NPARTTR_LNK(CODPARTTRLNK, CODPARTTR, CODPART, SEDII)
     VALUES (VCOD, V_REC.CODPARTTR, RECID, V_REC.SEDII);
   END IF;

 END LOOP;


 FOR V_REC IN (SELECT * FROM TMP_NPARTTR_LNK1) LOOP
   IF V_REC.CODPARTTRLNK1 &gt; 0 THEN
     UPDATE NPARTTR_LNK1
     SET
       CODPARTTRLNK = V_REC.CODPARTTRLNK,
       CODAGENDA    = V_REC.CODAGENDA
     WHERE
      CODPARTTRLNK1 = V_REC.CODPARTTRLNK1;
   ELSE
     INSERT INTO NPARTTR_LNK1(CODPARTTRLNK1, CODPARTTRLNK, CODAGENDA)
     VALUES (SEQ_NPARTTR_LNK1_CODPARTTRLNK1.NEXTVAL, V_REC.CODPARTTRLNK, V_REC.CODAGENDA);
   END IF;

 END LOOP;

-- Detail NPERSCONTACT

    DELETE FROM NPERSCONTACT WHERE ( codpart = RecId AND codpersc NOT IN ( SELECT codpersc FROM TMP_NPERSCONTACT WHERE Coalesce(codpersc,0) &lt;&gt; 0));

    INSERT INTO NPERSCONTACT ( codpersc,nume,prenume,telefon,email,functie,datanastere, SERIEBI, NRBI, ELIBERATBI, DATABI, CNP, rzona,id,tip,codbankcont,codpart,implicit, Obs, CODLOCATIE )
      SELECT seq_NPERSCONTACT_codpersc.Nextval,nume,prenume,telefon,email,functie,datanastere, SERIEBI, NRBI, ELIBERATBI, DATABI, CNP, rzona,id,tip,codbankcont,RecId,implicit, Obs, CODLOCATIE
      FROM TMP_NPERSCONTACT WHERE codpersc &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_NPERSCONTACT WHERE Coalesce(codpersc,0) &gt; 0  ORDER BY codpersc ) LOOP
      SELECT count(*) INTO vRecNo FROM NPERSCONTACT WHERE codpersc = Coalesce(v_rec.codpersc,0);
      IF(vRecNo=1) THEN
        UPDATE NPERSCONTACT
        SET
          nume        = v_rec.nume,
          prenume     = v_rec.prenume,
          telefon     = v_rec.telefon,
          email       = v_rec.email,
          functie     = v_rec.functie,
          datanastere = v_rec.datanastere,
          SERIEBI     = V_REC.SERIEBI,
          NRBI        = V_REC.NRBI,
          ELIBERATBI  = V_REC.ELIBERATBI,
          DATABI      = V_REC.DATABI,
          CNP         = V_REC.CNP,
          rzona       = v_rec.rzona,
          id          = v_rec.id,
          tip         = v_rec.tip,
          codbankcont = v_rec.codbankcont,
          codpart     = RecId,
          implicit    = v_rec.implicit,
          Obs         = v_rec.Obs,
          CODLOCATIE  = V_REC.CODLOCATIE
        WHERE
          codpersc = v_rec.codpersc;
      END IF;
    END LOOP;

-- Detail PARTTOT


    INSERT INTO PARTTOT ( CodPartTot,CodPart,SoldReal,Neoperat,anstart,lunastart )
      SELECT  seq_PARTTOT_CodPartTot.Nextval , RecId ,SoldReal,Neoperat,anstart,lunastart
      FROM TMP_PARTTOT WHERE CodPartTot &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_PARTTOT WHERE Coalesce(CodPartTot,0) &gt; 0  ORDER BY CodPartTot ) LOOP
      SELECT  Decode(SoldReal,v_rec.SoldReal,0,1) + Decode(Neoperat,v_rec.Neoperat,0,1) ,anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM PARTTOT WHERE CodPartTot = Coalesce(v_rec.CodPartTot,0);
       IF (vRecNo &gt; 0) THEN
         IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE PARTTOT SET SoldReal = v_rec.SoldReal,Neoperat = v_rec.Neoperat WHERE CodPartTot = v_rec.CodPartTot;
        ELSE
          INSERT INTO PARTTOT ( CodPartTot,CodPart,SoldReal,Neoperat,anstart,lunastart ) VALUES ( Seq_PARTTOT_CodPartTot.NextVal,RecId,v_rec.SoldReal,v_rec.Neoperat,v_rec.anstart,v_rec.lunastart );
        END IF;
      END IF;
    END LOOP;

-- Detail SOLDPART


    INSERT INTO SOLDPART ( CodSoldPart,CodPart,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart )
      SELECT  seq_SOLDPART_CodSoldPart.Nextval , RecId ,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart
      FROM TMP_SOLDPART WHERE CodSoldPart &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_SOLDPART WHERE Coalesce(CodSoldPart,0) &gt; 0  ORDER BY CodSoldPart ) LOOP
      SELECT  Decode(CodCont,v_rec.CodCont,0,1) + Decode(CodMoneda,v_rec.CodMoneda,0,1) + Decode(SoldLei,v_rec.SoldLei,0,1) + Decode(SoldValuta,v_rec.SoldValuta,0,1) ,anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM SOLDPART WHERE CodSoldPart = Coalesce(v_rec.CodSoldPart,0);
       IF (vRecNo &gt; 0) THEN
         IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE SOLDPART SET CodCont = v_rec.CodCont,CodMoneda = v_rec.CodMoneda,SoldLei = v_rec.SoldLei,SoldValuta = v_rec.SoldValuta WHERE CodSoldPart = v_rec.CodSoldPart;
        ELSE
          INSERT INTO SOLDPART ( CodSoldPart,CodPart,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart ) VALUES ( Seq_SOLDPART_CodSoldPart.NextVal,RecId,v_rec.CodCont,v_rec.CodMoneda,v_rec.SoldLei,v_rec.SoldValuta,v_rec.anstart,v_rec.lunastart );
        END IF;
      END IF;
    END LOOP;

-- Detail NPARTDISC

    DELETE FROM NPARTDISC WHERE ( CodPart = RecId AND CodPartDisc NOT IN ( SELECT CodPartDisc FROM TMP_NPARTDISC WHERE Coalesce(CodPartDisc,0) &lt;&gt; 0));

    INSERT INTO NPARTDISC ( CodPartDisc,CodPart,CodCategDisc, Indexlocal )
      SELECT  seq_NPARTDISC_CodPartDisc.Nextval , RecId ,CodCategDisc, Indexlocal
      FROM TMP_NPARTDISC WHERE CodPartDisc &lt; 0 ;

    FOR v_rec IN ( SELECT * FROM TMP_NPARTDISC WHERE Coalesce(CodPartDisc,0) &gt; 0  ORDER BY CodPartDisc ) LOOP
      SELECT count(*) INTO vRecNo FROM NPARTDISC WHERE CodPartDisc = Coalesce(v_rec.CodPartDisc,0);
      IF(vRecNo=1) THEN
        UPDATE NPARTDISC SET CodPart = RecId ,CodCategDisc = v_rec.CodCategDisc, Indexlocal = v_Rec.Indexlocal
        WHERE CodPartDisc = v_rec.CodPartDisc;
      END IF;
    END LOOP;

    -- TMP_NPARTOPORTUNITATI &lt;-&gt; OPORTUNITATI
    --DELETE FROM OPORTUNITATI WHERE CodPartener = RecId AND CodOportunitate NOT IN (SELECT CodOportunitate FROM TMP_NPARTOPORTUNITATI WHERE Coalesce(CodOportunitate, 0) &lt;&gt; 0);

    if pkg_globals.GETSUBUNITATE &gt; 1 then
      DELETE NPARTSUBUNIT NS
      WHERE NS.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND NS.CODPART = RECID
            AND NOT EXISTS (SELECT TMP.CODPARTSUBUNIT FROM TMP_NPARTSUBUNIT TMP WHERE TMP.CODPARTSUBUNIT = NS.CODPARTSUBUNIT);
      FOR V_REC IN (SELECT * FROM TMP_NPARTSUBUNIT) LOOP
        IF V_REC.CODPARTSUBUNIT &gt; 0 THEN
          UPDATE NPARTSUBUNIT
          SET
            CODPART    = V_REC.CODPART,
            SUBUNITATEA = V_REC.SUBUNITATEA,
            ZIAPROVIZ  = V_REC.ZIAPROVIZ,
            PERAPROVIZ = V_REC.PERAPROVIZ
          WHERE CODPARTSUBUNIT = V_REC.CODPARTSUBUNIT;
        ELSE
          INSERT INTO NPARTSUBUNIT (CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ)
          VALUES (SEQ_NPARTSUBUNIT_CODPARTS.NEXTVAL, V_REC.CODPART, V_REC.SUBUNITATEA, V_REC.ZIAPROVIZ, V_REC.PERAPROVIZ);
        END IF;
      END LOOP;
    end IF;

    INSERT INTO TMP_NPARTSUBUNIT(CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ)
    SELECT CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ
    FROM NPARTSUBUNIT
    WHERE CODPART = RECID
    AND Coalesce(SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, Coalesce(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE);

    DELETE FROM NPART1CRM WHERE CODPART = RECID AND CODPART1CRM NOT IN (SELECT CODPART1CRM FROM TMP_NPART1CRM);
    for v_rec in (select * from TMP_NPART1CRM WHERE CODPART1CRM &lt; 0) loop
      select seq_NPART1CRM_CodPart1Crm.Nextval into vcod from dual;
      update tmp_npartconcurenti set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
      update tmp_npartdomact set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
      update tmp_npartactivit set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
      INSERT INTO NPART1CRM (codpart1crm,codpart,anstart,lunastart,cifraafaceri,nrangajati,lead,sursalead,Stare, codresponsabil, MODPLATA, CIP, DATASTART, DATAEND, PROFIT)
      values (vcod ,RecId, v_rec.anstart,v_rec.lunastart,v_rec.cifraafaceri,v_rec.nrangajati,v_rec.lead,v_rec.sursalead,v_rec.Stare, v_rec.codresponsabil, V_REC.MODPLATA,
              V_REC.CIP, V_REC.DATASTART, V_REC.DATAEND, V_REC.PROFIT);
    end loop;

    FOR v_rec IN ( SELECT * FROM TMP_NPART1CRM WHERE Coalesce(CodPart1CRM,0) &gt; 0  ORDER BY CodPart1CRM ) LOOP
      UPDATE NPART1CRM
      SET
        anstart        = v_rec.anstart,
        lunastart      = v_rec.lunastart,
        cifraafaceri   = v_rec.cifraafaceri,
        nrangajati     = v_rec.nrangajati,
        lead           = v_rec.lead,
        sursalead      = v_rec.sursalead,
        Stare          = v_rec.Stare,
        codresponsabil = v_rec.codresponsabil,
        MODPLATA       = v_rec.MODPLATA,
        CIP            = V_REC.CIP,
        DATASTART      = V_REC.DATASTART,
        DATAEND        = V_REC.DATAEND,
        PROFIT         = V_REC.PROFIT
      WHERE CodPart1CRM = v_rec.CodPart1CRM;
    END LOOP;

    -- Detail NPARTCONCURENTI
    DELETE FROM NPARTCONCURENTI WHERE CodPart = RecId AND CodPartConcurent NOT IN (SELECT CodPartConcurent FROM TMP_NPARTCONCURENTI);

    INSERT INTO NPARTCONCURENTI (CodPartConcurent, CodPart, CodConcurent, CODPART1CRM)
    SELECT SEQ_NPARTCONCURENTI_CPC.NextVal, RecId, CodConcurent, CODPART1CRM
    FROM TMP_NPARTCONCURENTI WHERE CodPartConcurent &lt; 0;

    FOR v_Rec IN
      (SELECT * FROM TMP_NPARTCONCURENTI WHERE Coalesce(CodPartConcurent, 0) &gt; 0 ORDER BY CodPartConcurent)
    LOOP
      UPDATE NPARTCONCURENTI SET CodPart = RecId, CodConcurent = v_Rec.CodConcurent
      WHERE CodPartConcurent = v_Rec.CodPartConcurent;
    END LOOP;

    -- Detail NPARTACTIVIT
    DELETE FROM NPARTACTIVIT WHERE CodPart = RecId AND CodPartActivit NOT IN (SELECT CodPartActivit FROM TMP_NPARTACTIVIT);

    INSERT INTO NPARTACTIVIT (CodPartActivit, CodPart, Dim, CodActivit,CODPART1CRM)
    SELECT SEQ_NPARTACTIVIT_CPA.NextVal, RecId, Dim, CodActivit, CODPART1CRM
    FROM TMP_NPARTACTIVIT WHERE CodPartActivit &lt; 0;

    FOR v_Rec IN
      (SELECT * FROM TMP_NPARTACTIVIT WHERE Coalesce(CodPartActivit, 0) &gt; 0 ORDER BY CodPartActivit)
    LOOP
      UPDATE NPARTACTIVIT SET CodPart = RecId, CodActivit = v_Rec.CodActivit, Dim = v_rec.Dim
      WHERE CodPartActivit = v_Rec.CodPartActivit;
    END LOOP;

    DELETE FROM NPARTDOMACT WHERE CODPART = RECID AND CODPARTDOMACT NOT IN (SELECT CODPARTDOMACT FROM TMP_NPARTDOMACT);
    FOR V_REC IN (SELECT * FROM TMP_NPARTDOMACT) LOOP
      IF V_REC.CODPARTDOMACT &gt; 0 THEN
        UPDATE NPARTDOMACT
        SET
          CODDOMENIUACT = V_REC.CODDOMENIUACT
        WHERE CODPARTDOMACT = V_REC.CODPARTDOMACT;
      ELSE
        INSERT INTO NPARTDOMACT(CODPARTDOMACT, CODPART, CODDOMENIUACT,CODPART1CRM)
        VALUES (SEQ_NPARTDOMACT_CODPARTDOMACT.NEXTVAL, RECID, V_REC.CODDOMENIUACT, V_REC.CODPART1CRM);
      END IF;
    END LOOP;

  ELSE  -- INSERT
    SELECT TvaLaIncasare
    INTO vTVAI
    FROM TMP_NPART;

    IF vTVAI IS NULL THEN
      BEGIN
        SELECT CodFisCal INTO sCui
        FROM TMP_NPARTCODFISC
        WHERE PRINCIPAL = 1;
      EXCEPTION
        WHEN OTHERS THEN sCui := NULL;
      END;

      IF sCui IS NOT NULL THEN
        vTVAI := pkg_NomPart.TvaLaIncasare(sCui);
      END IF;

      IF vTVAI IS NOT NULL THEN
        UPDATE TMP_NPART SET TvaLaIncasare = vTVAI;
      END IF;
    END IF;

    -- Master NPART
    SELECT seq_NPART_CodPart.NextVal INTO RecId FROM DUAL;

    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NPART&apos;, RecId);

    INSERT INTO  NPART (
      CodPart, Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart, ScadentaC, ScadentaV, Discount, CodCategDisc, Blocat,
      TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT, INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati, SursaLead, Lead, TVALAINCASARE,
      MODAPLICPROCDISC, PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj, SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct, DocDefOnorCom, ModPromoFactCom, ValidarePretOferta, IESCUCOMANDA,
      VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ, CODCONTRACTCadru, EF_Item, EF_Party, DATANASTERE, GDPR, ZILELIVRARE, SAFT_EXPORT, FaraPenalizari, INACTIV, preOfeFurnVar, Tipanalizapret, VerAvizIes,
      EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, EF_TAXE, CategTarif, ZileAchiz, Culoare)
    SELECT
      RecId, Den_part, CodExtern, CodMoneda, RegCom, EXPIRAREAUTORIZ, CODSTATISTICBNR, Autorizatie, CodIntern, CodClasa, CodCategPret, TipPart, ScadentaC, ScadentaV, Discount, CodCategDisc, Blocat,
      TIPPARTENER, DATAADAUGARII, OBS, POZA, PERSOANAFIZICA, VERFACT, VERDISPLIVR, COLDISCOUNT, INFOBLOCAT, MusaiColet, STRATEGIC, CifraAfaceri, DomeniuActiv, NrAngajati, SursaLead, Lead, TVALAINCASARE,
      MODAPLICPROCDISC, PROCCURSTRANSF, VERPROFORMA, FIDELIZARE, Majorari, TipBlocaj, SPLITTVA, POPRIRE_ANAF, codresponsabil, CodDomeniuAct, DocDefOnorCom, ModPromoFactCom, ValidarePretOferta, IESCUCOMANDA,
      VERFACTAVIZ, ZIAPROVIZ, PERAPROVIZ, CODCONTRACTCadru, Coalesce(EF_Item,0), Coalesce(EF_Party,0), DATANASTERE, GDPR, ZILELIVRARE, SAFT_EXPORT, FaraPenalizari,  INACTIV, preOfeFurnVar, Tipanalizapret, VerAvizIes,
      EF_IMPARTGEN, EF_CUSTOM, EF_PROIECT, Coalesce(EF_TAXE,0), Coalesce(CategTarif,0), ZileAchiz, Culoare
    FROM TMP_NPART;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Partener &quot;&apos;||den_part||&apos;&quot;&apos; INTO aDoc FROM npart WHERE codpart = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPART&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
-- Detail NPART1
   INSERT INTO  NPART1 ( CodPart,CodIOPART,CodPart1,CreditFurn,VolumTranzC,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT,CreditClient,VolumTranzF,anstart,lunastart )
   SELECT RecId,CodIOPART, seq_NPART1_CodPart1.Nextval ,CreditFurn,VolumTranzC,SCADENTAV,SCADENTAC,CASSBAZAMIN, SimbolCASS, GDPR ,DISCOUNT,CreditClient,VolumTranzF,anstart,lunastart
   FROM TMP_NPART1;

   for v_rec in (select * from TMP_NPART1CRM) loop
     select seq_NPART1CRM_CodPart1CRM.Nextval into vcod from dual;
     update tmp_npartconcurenti set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
     update tmp_npartdomact set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
     update tmp_npartactivit set codpart1crm = vcod where codpart1crm = v_rec.codpart1crm;
     INSERT INTO NPART1CRM (codpart1crm,codpart,anstart,lunastart,cifraafaceri,nrangajati,lead,sursalead,Stare, codresponsabil, MODPLATA, CIP, DATASTART, DATAEND,PROFIT)
     values (vcod ,RecId, v_rec.anstart,v_rec.lunastart,v_rec.cifraafaceri,v_rec.nrangajati,v_rec.lead,v_rec.sursalead,v_rec.Stare, v_rec.codresponsabil, v_rec.MODPLATA,
             V_REC.CIP, V_REC.DATASTART, V_REC.DATAEND,V_REC.PROFIT);
   end loop;

-- Detail NPARTB
    INSERT INTO  NPARTB ( CodPartB,CodPart,CodBank,Implicit,CodLocalit,ContBanca,Sucursala, CODSWIFT, TIPCOMISION, CONTTVA,OBS, CODMONEDA )
    SELECT seq_NPARTB_CodPartB.Nextval ,RecId,CodBank,Implicit,CodLocalit,ContBanca,Sucursala, CODSWIFT, TIPCOMISION, CONTTVA, OBS, CODMONEDA
    FROM TMP_NPARTB;


    FOR V_REC IN (SELECT * FROM TMP_NPARTCODFISC WHERE COD_CODFISCAL &lt; 0)
    LOOP
       SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL INTO VCOD FROM DUAL;
       UPDATE TMP_NAGENDA
       SET
         COD_CODFISCAL = VCOD
       WHERE
         COD_CODFISCAL = V_REC.COD_CODFISCAL;

      INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
      VALUES (VCOD, RecId , TRIM(V_REC.CODFISCAL), V_REC.PRINCIPAL);


    END LOOP;

-- Detail NPARTCODFISC
    INSERT INTO NPARTLSTCLASE (CODNPARTLSTCLASE, CODPART, CODCLASA)
    SELECT SEQ_NPARTLC_CODNPARTLC.NEXTVAL , RecId , CODCLASA  FROM TMP_NPARTLSTCLASE;

-- Detail NAGENDA
    FOR V_REC IN (SELECT * FROM TMP_NAGENDA)
    LOOP
      SELECT seq_NAGENDA_codagenda.Nextval INTO VCOD FROM DUAL;

      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NAGENDA&apos;, VCOD, V_REC.CODAGENDA);
      UPDATE TMP_NPARTTR_LNK1 SET CODAGENDA  = VCOD WHERE CODAGENDA  = V_REC.CODAGENDA;
      UPDATE TMP_NAGENDA      SET CODAGENDA  = VCOD WHERE CODAGENDA  = V_REC.CODAGENDA;
      UPDATE TMP_NAGENDA1     SET CODAGENDA  = VCOD WHERE CODAGENDA  = V_REC.CODAGENDA;
      UPDATE TMP_NAGENDA      SET CODCORESP  = VCOD WHERE CODCORESP  = V_REC.CODAGENDA;
      UPDATE TMP_NPERSCONTACT SET CODLOCATIE = VCOD WHERE CODLOCATIE = V_REC.CODAGENDA;

    END LOOP;

    INSERT INTO NAGENDA (
      codagenda,obs,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,
      CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, Inactiv, Codcoresp, TranspClient,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport,
      VERFACT, VERDISPLIVR, VERPROFORMA, VERFACTAVIZ, VERAVIZIES )
    Select
      codagenda,obs,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,RecID,codgest,codsubunit,
      CODTIPSEDIU, CODFISCAL, CODAGENT, Codclient, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, Inactiv, Codcoresp, TranspClient,
      EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, CODANTREPOZIT, ZileTransport,
      VERFACT, VERDISPLIVR, VERPROFORMA, VERFACTAVIZ, VERAVIZIES
    FROM TMP_NAGENDA;



    INSERT INTO NAGENDA1 (CODAGENDA1, CODAGENDA, ANSTART, LUNASTART, CREDITCLIENT, ZILEDEPASIRE, NRFACTSOLD, SCADENTAV)
    SELECT SEQ_NAGENDA1_CODAGENDA1.NEXTVAL, CODAGENDA, ANSTART, LUNASTART, CREDITCLIENT, ZILEDEPASIRE, NRFACTSOLD, SCADENTAV FROM TMP_NAGENDA1;

    FOR V_REC IN (SELECT * FROM TMP_NAGENDA1) LOOP
      PRC_AL_REFRESH(&apos;NAGENDA1&apos;, V_REC.CODAGENDA);
    END LOOP;

    -- Detail NPARTTR
    INSERT INTO  NPARTTR ( CodPartTr, CodPart, Delegat, cnp, doc, SerieDoc, NrDoc, Eliberat, MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON, EMAIL )
    SELECT  seq_NPARTTR_CodPartTr.Nextval ,RecId,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat,MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL
    FROM TMP_NPARTTR;


    -- Detail NPARTTRLNK
    FOR V_REC IN (SELECT * FROM TMP_NPARTTR_LNK)
    LOOP
      SELECT SEQ_NPARTTR_LNK_CODPARTTRLNK.NEXTVAL INTO VCOD FROM DUAL;
      UPDATE
        TMP_NPARTTR_LNK1
      SET
        CODPARTTRLNK = VCOD
      WHERE
        CODPARTTRLNK = V_REC.CODPARTTRLNK;

      INSERT INTO NPARTTR_LNK(CODPARTTRLNK, CODPARTTR, CODPART, SEDII)
      VALUES (VCOD, V_REC.CODPARTTR, RECID,  V_REC.SEDII);
    END LOOP;

    INSERT INTO NPARTTR_LNK1(CODPARTTRLNK1, CODPARTTRLNK, CODAGENDA)
    SELECT SEQ_NPARTTR_LNK1_CODPARTTRLNK1.NEXTVAL, CODPARTTRLNK, CODAGENDA FROM TMP_NPARTTR_LNK1;

    -- Detail NPERSCONTACT
    INSERT INTO  NPERSCONTACT ( codpersc,nume,prenume,telefon,email,functie,datanastere,SERIEBI, NRBI, ELIBERATBI, DATABI, CNP, rzona,id,tip,codbankcont,codpart,implicit, Obs, CODLOCATIE )
    SELECT  seq_NPERSCONTACT_codpersc.Nextval ,nume,prenume,telefon,email,functie,datanastere, SERIEBI, NRBI, ELIBERATBI, DATABI, CNP, rzona,id,tip,codbankcont,RecId,implicit, Obs, CODLOCATIE
    FROM TMP_NPERSCONTACT;

    -- Detail PARTTOT
    INSERT INTO  PARTTOT ( CodPartTot,CodPart,SoldReal,Neoperat,anstart,lunastart )
    SELECT  seq_PARTTOT_CodPartTot.Nextval ,RecId,SoldReal,Neoperat,anstart,lunastart
    FROM TMP_PARTTOT;

    -- Detail SOLDPART
    INSERT INTO  SOLDPART ( CodSoldPart,CodPart,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart )
    SELECT  seq_SOLDPART_CodSoldPart.Nextval ,RecId,CodCont,CodMoneda,SoldLei,SoldValuta,anstart,lunastart
    FROM TMP_SOLDPART;

    -- Detail NPARTDISC
    INSERT INTO  NPARTDISC ( CodPartDisc,CodPart,CodCategDisc, Indexlocal )
    SELECT  seq_NPARTDISC_CodPartDisc.Nextval ,RecId,CodCategDisc, Indexlocal
    FROM TMP_NPARTDISC;

    -- Detail NPARTCONCURENTI
    INSERT INTO NPARTCONCURENTI (CodPartConcurent, CodPart, CodConcurent,CODPART1CRM)
    SELECT SEQ_NPARTCONCURENTI_CPC.NextVal, RecId, CodConcurent,CODPART1CRM
    FROM TMP_NPARTCONCURENTI;

    -- Detail NPARTACTIVIT
    INSERT INTO NPARTACTIVIT (CodPartActivit, CodPart, Dim, CodActivit,CODPART1CRM)
    SELECT SEQ_NPARTACTIVIT_CPA.NextVal, RecId, Dim, CodActivit,CODPART1CRM
    FROM TMP_NPARTACTIVIT;

    INSERT INTO NPARTDOMACT(CODPARTDOMACT, CODPART, CODDOMENIUACT,CODPART1CRM)
    SELECT SEQ_NPARTDOMACT_CODPARTDOMACT.NEXTVAL, RECID, CODDOMENIUACT,CODPART1CRM
    FROM TMP_NPARTDOMACT;

    -- TMP_NPARTOPORTUNITATI &lt;-&gt; OPORTUNITATI
    --DELETE FROM OPORTUNITATI WHERE CodPartener = RecId AND CodOportunitate NOT IN (SELECT CodOportunitate FROM TMP_NPARTOPORTUNITATI WHERE Coalesce(CodOportunitate, 0) &lt;&gt; 0);

    INSERT INTO NPARTSUBUNIT (CODPARTSUBUNIT, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ)
    select SEQ_NPARTSUBUNIT_CODPARTS.NEXTVAL, CODPART, SUBUNITATEA, ZIAPROVIZ, PERAPROVIZ
    from tmp_npartsubunit;
  END IF;

  CHECKPART1CRM(RECID);

  PRC_AL_REFRESH(&apos;NPART1&apos;   , RECID);
  PRC_AL_REFRESH(&apos;NPART1CRM&apos;, RECID);

  NotifyModif(OPERATION, RECID, &apos;NPART&apos;);
  DOSYNCPARTRETAIL(RECID);
  if pkg_categconst.GetValConstanta(&apos;IDSEDIUAUTOMAT&apos;,    pkg_globals.ANLUCRU, pkg_globals.LUNALUCRU) = &apos;1&apos; then
    UPDATE NAGENDA
    SET
      IDSEDIU = CODAGENDA
    WHERE
      CODPART = RECID
      AND IDSEDIU IS NULL;
  end IF;
  --  nomPart --&gt;  500
  PKG_CFGTABLES.EXT_POSTRECORDS(500);
  COMMIT;
END;

PROCEDURE SET_TIPSERVIRE_LOCATII(aTipServire IN NUMBER) IS
BEGIN
  TIPSERV_CURENT := aTipServire;
END;

FUNCTION  TIPSERVIRE_LOCATII_OK (aModServire IN NUMBER) RETURN NUMBER IS
  vModServire NUMBER := Coalesce(aModServire,0);
BEGIN
  IF (Coalesce(TIPSERV_CURENT,0) = 0)
  OR (Coalesce(TIPSERV_CURENT,0) = 1 AND vModServire = 1)
  OR (Coalesce(TIPSERV_CURENT,0) = 2 AND vModServire &gt; 1)
  THEN RETURN 1;
  ELSE RETURN 0;
  END IF;
END;




FUNCTION GET_Fact_Part(aCodPart IN NUMBER) RETURN Fact_CURSOR
IS
TMPCURSOR Fact_CURSOR;
BEGIN
 BEGIN
   OPEN tmpCursor FOR
    select
      O.CodObligPIF, O.CodPart Partener, O.Termen, P.ScadentaV, E.PREFIXDOC, E.NRDOC, E.DATADOC,
      m.simbol Moneda, O.VALOARE, O.REST, 0 as ExclusPlata, E.CodIes CodDoc, E.TipDoc, nvl(O.TipPlata,0) TipPlata,
      (
       SELECT
         MAX(MODPLATA) KEEP (Dense_Rank LAST ORDER BY DATASTART) MODPLATA
       FROM
         NPART1CRM
       WHERE
         CODPART = P.CODPART
         AND DATASTART &lt;= E.DATADOC
      ) MODPLATA, o.codcentru, p.den_part
    from ObligPIF O
    inner join General G on G.CodGeneral = O.CodGeneral
    inner join NPART P on P.CodPart = O.CodPart
    inner join Iesiri E on E.CodIes = G.CodDoc
    left join nmonede m on m.codmoneda = Coalesce(e.moneda,0)
    where
      (O.Codpart = aCodPart or aCodPart = 0)
      and ((O.Valoare &gt; 0 and O.Rest &gt; 0)or(O.Valoare &lt; 0 and O.Rest &lt; 0))
      and (G.TipDoc = 19 or G.TipDoc = 26) and not o.semnificatie in (210,240);
   EXCEPTION WHEN OTHERS THEN
     OPEN tmpCursor FOR
       SELECT
        O.CodObligPIF, O.CodPart Partener, O.Termen, 0 ScadentaV, &apos;?&apos; PREFIXDOC, 0 NRDOC, O.Termen  DATADOC,
      &apos;...nedefinit...&apos; Moneda, O.VALOARE, o.REST, 0 as ExclusPlata, 0 as TipPlata, 0 as codcentru, &apos;...nedefinit...&apos; den_part FROM obligpif O  WHERE 1=2;
 END;

 RETURN tmpcursor;
END;



FUNCTION GET_Fact_Furn(aCodPart IN NUMBER) RETURN Fact_CURSOR
IS
TMPCURSOR Fact_CURSOR;
BEGIN
  BEGIN
    OPEN tmpCursor FOR
    select
      O.CodObligPIF,
      O.CodPart Partener,
      O.Termen,
      P.ScadentaC,
      E.PREFIXDOC,
      E.NRDOC,
      E.DATADOC,
      m.simbol Moneda,
      O.VALOARE,
      O.REST, 0 as ExclusPlata, E.CodIntr CodDoc, E.TipDoc,
      nvl(O.TipPlata,0) TipPlata,
      (
       SELECT
         MAX(MODPLATA) KEEP (Dense_Rank LAST ORDER BY DATASTART) MODPLATA
       FROM
         NPART1CRM
       WHERE
         CODPART = P.CODPART
         AND DATASTART &lt;= E.DATADOC
      ) MODPLATA,
      o.codcentru, p.den_part
    from ObligPIF O
    inner join General G on G.CodGeneral = O.CodGeneral
    inner join NPART P on P.CodPart = O.CodPart
    inner join INTRARI E on E.CodINTR = G.CodDoc
    left join nmonede m on m.codmoneda = Coalesce(e.moneda,0)
    where
      (O.Codpart = aCodPart or aCodPart = 0)
      and ((O.Valoare &gt; 0 and O.Rest &gt; 0)or(O.Valoare &lt; 0 and O.Rest &lt; 0))
      and G.TipDoc IN (1, 5, 9) and not o.semnificatie in (310,140);
   EXCEPTION WHEN OTHERS THEN
     OPEN tmpCursor FOR
       SELECT
        O.CodObligPIF, O.CodPart Partener, O.Termen, 0 ScadentaC, &apos;?&apos; PREFIXDOC, 0 NRDOC, O.Termen  DATADOC,
      &apos;...nedefinit...&apos; Moneda, O.VALOARE, o.REST, 0 as ExclusPlata, 0 as TipPlata, 0 as codcentru, &apos;...nedefinit...&apos; den_part
      FROM obligpif O  WHERE 1=2;
  END;

  RETURN tmpcursor;
END;



PROCEDURE REFRESH_OPORTUNITATI(aCodPart IN NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  -- TMP_NPORTOPORTUNITATI
  DELETE FROM TMP_NPARTOPORTUNITATI;

  INSERT INTO TMP_NPARTOPORTUNITATI (CodOportunitate, PrefixDoc, NrDoc, DataDoc, CodCarnetDoc, CodPartener, CodMoneda, Tip, CodAgent, CodCampanie, VenitEst, VenitProb)
  SELECT O.CodOportunitate, O.PrefixDoc, O.NrDoc, O.DataDoc, O.CodCarnetDoc, O.CodPartener, O.CodMoneda, O.Tip, O.CodAgent,
         CP.CodCampaniePart, O.VenitEst, O.VenitProb
  FROM OPORTUNITATI O
       INNER JOIN CAMPANII C ON O.CODCAMPANIE = C.CODCAMPANIE
       INNER JOIN CAMPANIIPART CP ON C.CODCAMPANIE = CP.CODCAMPANIE
  WHERE CP.CodPart = aCodPart;

  COMMIT;
END;

FUNCTION GET_PARTACTIVIT(aCodPart IN NUMBER) RETURN VARCHAR2 IS
  vLimita NUMBER := 3200;
  vLMax   NUMBER;
  vRes    VARCHAR2(3200);

BEGIN
  SELECT String_agg(den), Max(LMAX) INTO vRes, vLMax
  FROM (
    SELECT den_activit den, Sum(Length(den_activit)) OVER () LMAX, Sum(Length(den_activit)) OVER (ORDER BY den_activit ROWS UNBOUNDED PRECEDING) LCUR
    FROM NPARTACTIVIT PA INNER JOIN NACTIVIT A ON a.codactivit = pa.codactivit
    WHERE pa.codpart = aCodPart
  )
  WHERE LCUR &lt;= vLimita;

  IF vLMax &gt; vLimita THEN
    vRes := SubStr(vRes, 1, vLimita - 3) ||&apos;...&apos;;
  END IF;

  RETURN vRes;
END;



FUNCTION Clone_PART_As_Delegat(aCodPart in Number, aCodPartTR in Number) RETURN NUMBER
IS
RecId number(20);
aDelegat  varchar2(100);
acnp      varchar2(100);
vCodFiscal number(20);
vCodlocalit number(20);
vAdresa     varchar2(100);
BEGIN
  	RECID := 1;
		BEGIN
  		SELECT  Delegat, Codlocalit, Adresa, cnp into  aDelegat, vCodlocalit, vAdresa, acnp FROM NPARTTR where CodPArtTr = aCodPArtTr;
		EXCEPTION WHEN OTHERS THEN
			RECID := 0;
		END;
		if (aCodPArtTr = 0)or(RECID = 0) then
				RETURN 0;
		end if;

		RECID := 0;
		BEGIN
			Select CodPart into RECID from NPARTCODFISC where CODFISCAL = aCNP;
		EXCEPTION WHEN OTHERS THEN
			RECID := 0;
		END;
		if RECID &gt; 0 then
				RETURN RECID;
		end if;

    SELECT seq_NPART_CodPart.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NPART (
      CodPart, Den_part, CodExtern, CodMoneda, PERSOANAFIZICA,
      TVALAINCASARE )
    SELECT
      RecId, aDelegat, CodExtern, CodMoneda, 1,
      TVALAINCASARE
    FROM NPART where CodPart = aCodPart;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPART&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, &apos;Part.automat&quot;&apos;||aDelegat||&apos;&quot;&apos;,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

-- Detail NPART1
   INSERT INTO  NPART1 ( CodPart,CodIOPART,CodPart1,anstart,lunastart )
   SELECT RecId,CodIOPART, seq_NPART1_CodPart1.Nextval ,anstart,lunastart
   FROM NPART1 where CodPart = aCodPart;

   PRC_AL_REFRESH(&apos;NPART1&apos;, RECID);

   SELECT SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL INTO vCodFiscal FROM DUAL;
	 INSERT INTO NPARTCODFISC (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
   VALUES (vCodFiscal, RecId , TRIM(aCNP), 1);

   INSERT INTO NAGENDA (
      codagenda, obs,tip,codlocalit,STRADA, sediusocial,codpart,COD_CODFISCAL  )
    Select
      seq_NAGENDA_codagenda.Nextval,
			obs,tip,vCodlocalit, vAdresa, sediusocial,RecID, vCodFiscal
    FROM NAGENDA where CodPart = aCodPart and RowNum = 1;

    -- Detail NPARTTR
    INSERT INTO  NPARTTR ( CodPartTr, CodPart, Delegat, cnp, doc, SerieDoc, NrDoc, Eliberat, MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL )
    SELECT  seq_NPARTTR_CodPartTr.Nextval ,RecId,Delegat,cnp,doc,SerieDoc,NrDoc,Eliberat,MijlTransp, NrTransp, ACTIV, DATADOC, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT,TELEFON,EMAIL
    FROM NPARTTR where CodPArtTr = aCodPArtTr;
    COMMIT;
		Return RECID;
END;

procedure CHECKPART1CRM(aCodPart in number := 0) is
aCount number(20);
vcod number(20);
aAnIni number(4);
aLunaIni number(2);
begin
  begin
    select aninitial, lunainitiala into aAnIni, aLunaIni from firmaluni;
  exception when others then aAnIni := 0;
  end;

  if aAnIni = 0 then return; end if;
  if aCodPart = 0 then
    for v_rec in (select p.* from npart p where (select count(*) from npart1crm crm where crm.codpart = p.codpart) = 0
                 ) loop
      select seq_npart1crm_codpart1crm.nextval into vcod from dual;
      insert into npart1crm(codpart1crm, codpart, anstart, lunastart, cifraafaceri, nrangajati, lead, sursalead, codresponsabil)
      select vcod, v_rec.codpart, aAnIni, aLunaIni, cifraafaceri, nrangajati, lead, sursalead, codresponsabil
      from npart where codpart = v_rec.codpart;
      update npartactivit set codpart1crm = vcod where codpart = v_rec.codpart;
      update npartdomact set codpart1crm = vcod where codpart = v_rec.codpart;
      update npartconcurenti set codpart1crm = vcod where codpart = v_rec.codpart;
    end loop;
    commit;
  else
    select count(*) into aCount from npart1crm crm where crm.codpart = aCodPart;
    if aCount = 0 then
      select seq_npart1crm_codpart1crm.nextval into vcod from dual;
      insert into npart1crm(codpart1crm, codpart, anstart, lunastart, cifraafaceri, nrangajati, lead, sursalead, codresponsabil)
      select vcod, acodpart, aAnIni, aLunaIni, cifraafaceri, nrangajati, lead, sursalead, codresponsabil
      from npart where codpart = aCodPart;
      update npartactivit set codpart1crm = vcod where codpart = aCodPart;
      update npartdomact set codpart1crm = vcod where codpart = aCodPart;
      update npartconcurenti set codpart1crm = vcod where codpart = aCodPart;
    end if;
  end if;
end;

PROCEDURE MAKE_OBLIGPART_LA_ZI(aCodPart in number)
IS
  aPREFIXDOC VARCHAR2(3) := NULL;
  aDATADOC DATE := NULL;
  aNRDOC NUMBER(20) := NULL;
  aSUBUNITATEA NUMBER(20) := NULL;
  aAGENT NUMBER(20) := NULL;
BEGIN
  PKG_NOMPART.SET_PART_CURENT(ACODPART);
  PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(TO_CHAR(SYSDATE, &apos;DD.MM.YYYY&apos;));
  PKG_GLOBALS.DATASOLDPART := SYSDATE;
  PKG_REGPART.MAKE_STINGERI_LA_DATA_PART;
  DELETE TMP_OBLIGPART_LA_DATA;

  INSERT INTO TMP_OBLIGPART_LA_DATA
   (
    CODOBLIGPIF,
    CODGENERAL,
    CODDOC,
    VALOARE,
    REST,
    ICONT,
    SEMNIFICATIE,
    CODPART,
    CODGEST,
    CURS,
    TVA,
    MONEDA,
    TIPDOC,
    TERMEN
    )
  SELECT
    RG.CODOBLIGPIF,
    RG.CODGENERAL,
    RG.CODDOC,
   (VALOARE - ROUND(Coalesce(STINS, 0), 7)) VALOARE,
    VALOARE - ROUND(Coalesce(STINS, 0), 7)  REST,
    RG.ICONT,
    RG.SEMNIFICATIE,
    RG.CODPART,
    RG.CODGEST,
    RG.CURS,
    RG.TVA,
    RG.MONEDA,
    RG.TIPDOC,
    RG.TERMEN
  FROM
   (
    SELECT
      CODOBLIGPIF,
      CODGENERAL,
      CODDOC,
      ICONT,
      SEMNIFICATIE,
      CODPART,
      CODGEST,
      CURS,
      TVA,
      STINS,
      VALOARE,
      MONEDA,
      TIPDOC,
      TERMEN
    FROM
      V_OBLIGPART_LA_DATA_PE_PART
   ) RG
  WHERE
     ROUND(Coalesce(VALOARE, 0), 4) - ROUND(Coalesce(STINS, 0), 4) &lt;&gt; 0;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPART_LA_DATA)
  LOOP
    aPREFIXDOC   := NULL;
    aDATADOC     := NULL;
    aNRDOC       := NULL;
    aSUBUNITATEA := NULL;

    IF V_REC.SEMNIFICATIE IN (100, 110, 140) THEN
      BEGIN
        SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA, AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM INTRARI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODINTR = G.CODDOC;
        EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL; aAGENT := NULL;
      END ;
    ELSE
      IF V_REC.SEMNIFICATIE IN (130) THEN
        BEGIN
          SELECT &apos;DVI&apos;, I.DATADOC, I.NRDOC, INTR.SUBUNITATEA, INTR.AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM DVI I, GENERAL G, INTRARI INTR WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODDVI = G.CODDOC AND INTR.CODINTR = I.CODINTR;
          EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL; aAGENT := NULL;
        END ;
      ELSE
        IF V_REC.SEMNIFICATIE IN (200, 210, 240) THEN
          BEGIN
            SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA, AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM IESIRI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODIES = G.CODDOC;
            EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aAGENT := NULL;
          END ;
        ELSE
          IF V_REC.SEMNIFICATIE IN (310, 410, 330, 430) THEN
            BEGIN
              SELECT SUBSTR(T1.DOC, 1, 2),  T1.DATADOC, T1.NRDOC, T.SUBUNITATEA, T1.AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM TREZOR1 T1, GENERAL G, TREZOR T WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
              EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL; aAGENT := NULL;
            END ;
          ELSE
            IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
              BEGIN
                SELECT &apos;NC&apos;, DATADOC, NRDOC, SUBUNITATEA, N1.AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM NC1 N1, GENERAL G, NC N WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODNC1 = G.CODDOC AND N1.CODNC = N.CODNC;
                EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL; aAGENT := NULL;
              END ;
            ELSE
     					IF V_REC.SEMNIFICATIE = 1303 THEN
     					  BEGIN
     						  SELECT
     					  	  I.PREFIXDOC, I.DATADOC, I.NRDOC, I.SUBUNITATEA, I.AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT
     					  	FROM
     							  OBLIGPIF O
                    LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                    LEFT OUTER JOIN OBLIGPIF OA ON OA.CODOBLIGPIF = O.CODOBLIGASOCIAT
                    LEFT OUTER JOIN GENERAL GA ON GA.CODGENERAL = OA.CODGENERAL
                    LEFT OUTER JOIN IESIRI I ON I.CODIES = GA.CODDOC
                  WHERE
                    G.CODGENERAL = V_REC.CODGENERAL;
                EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aAGENT := NULL;
     						END;
      				ELSE
                BEGIN -- compensari
                  SELECT &apos;PV&apos;, DATADOC, NRDOC, SUBUNITATEA, COMPENS.AGENT INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA, aAGENT FROM COMPENS, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODCOMPENS = G.CODDOC;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL; aAGENT := NULL;
                END ;
     					END IF;
            END IF;
          END IF;
        END IF;
      END IF;
    END IF;

    UPDATE TMP_OBLIGPART_LA_DATA OB
    SET
      PREFIXDOC    = aPREFIXDOC,
      DATADOC      = aDATADOC,
      NRDOC        = aNRDOC,
      SUBUNITATEA  = aSUBUNITATEA,
      CONT         = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)),
      CODAGENT     = aAGENT
    WHERE CODGENERAL   = V_REC.CODGENERAL;
  END LOOP;
END;

FUNCTION TVALAINCASARE (aCodFiscal IN VARCHAR2, aDate IN varchar2 DEFAULT NULL) RETURN NUMBER IS
  sCUI  VARCHAR2(50) := Upper (REGEXP_REPLACE(aCodFiscal,&apos;\W+&apos;, &apos;&apos;));
  nCUI  VARCHAR2(50) := NULLIF(REGEXP_REPLACE(aCodFiscal,&apos;\D+&apos;, &apos;&apos;),&apos;&apos;);
  dDate DATE         := Coalesce(TO_DATE(aDate, &apos;dd.mm.yyyy&apos;),  To_Date(&apos;9999&apos;,&apos;yyyy&apos;));
  vRes  NUMBER;
BEGIN
  IF SubStr(sCUI,1,2) = &apos;RO&apos;
  THEN sCui := SubStr(sCui, 3);
  END IF;

  IF    nCUI IS NULL THEN -- CUI invalid
    vRes := NULL;
  ELSIF nCui &lt;&gt; sCui THEN -- CUI non RO
    vRes := NULL;
  ELSE
    BEGIN
      SELECT tvalaincasare
      INTO vRes
      FROM (
        SELECT r.tvalaincasare, Row_Number() OVER (ORDER BY r.id DESC) IDX
        FROM WINMADMIN.RTVAI_ISTORIC R
        WHERE r.cod_fiscal = To_Number(nCUI) AND Coalesce(r.data_sfarsit, r.data_inceput) &lt;= dDate
      ) ssub
      WHERE idx = 1;
    EXCEPTION WHEN OTHERS THEN
      vRes := 0;
    END;
  END IF;
  RETURN vRes;
END;

PROCEDURE PROPAGAGDPR IS
BEGIN
  FOR V_REC IN (
    SELECT P1.CODPART
    FROM NPART1 P1
    WHERE P1.GDPR = 1 AND P1.ALSTOP = 99999
  ) LOOP
    UPDATE NPART SET GDPR = 1 WHERE CODPART = V_REC.CODPART;
  END LOOP;
  COMMIT;
END;

function GETVOLTRANZCLI(aCodPart in number) return number is
aVol number(20,7);
begin
  begin
    SELECT SUM(VOLUM) into aVol
    FROM
     (
       SELECT COALESCE(VOLUMTRANZC, 0) AS VOLUM
       FROM
         NPART1
       WHERE
         CODPART = aCodPart
         AND ANSTART = pkg_globals.GetAnInitial
         AND LUNASTART = pkg_globals.GetLunaInitiala
       UNION ALL
       SELECT
         SUM(VALTRANZC) AS VOLUM
       FROM
         STINGERE S,
         OBLIGPIF O
       WHERE
         S.CODSTINSPIF = O.CODOBLIGPIF
         AND CODPART = aCodPart
       UNION ALL
       SELECT SUM(REST) AS VOLUM
       FROM
         OBLIGPIF
       WHERE
         SEMNIFICATIE = 410
         AND CODPART = aCodPart
       UNION ALL
       SELECT SUM(VALOARE) AS VOLUM
       FROM
         EMULARE
       WHERE
         CODPART = aCodPart
    ) A;
  exception when others then aVol := 0;
  end;
  return aVol;
end;

PROCEDURE StructuraANAF_CuiInit (pCUI NUMERIC, pData DATE DEFAULT NULL) IS
  dData DATE := Trunc(Coalesce(pData, SYSDATE));
BEGIN
  TRUNCATE_TABLE(&apos;TMP_STRUCTURAANAF&apos;);
  DELETE FROM WINMADMIN.NPART_ANAF WHERE CUI = pCUI AND DATA  &lt;&gt; dData;
  DELETE FROM WINMADMIN.NPART_ANAF WHERE CUI = pCUI AND STARE &lt;&gt; 1 ;

  INSERT INTO TMP_STRUCTURAANAF (
    CUI, DATA, STARE, CONTRIBUABIL, DENUMIRE,
    ADRESA, LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART,
    NRREGCOM, SPLITTVA, RTVAI, STAREINREG, STAREINACTIV, MESAJ
  )
  SELECT
    TMP.Cui, TMP.Data, Coalesce(PA.Stare, 0) Stare, PA.CONTRIBUABIL, PA.DENUMIRE,
    PA.ADRESA, PA.LOCALITATE, PA.JUDET, PA.STRADA, PA.BLOC, PA.SCARA, PA.NUMAR1, PA.NUMAR2, PA.ETAJ, PA.APART,
    PA.NRREGCOM, PA.SPLITTVA, PA.RTVAI, PA.STAREINREG, PA.STAREINACTIV, PA.MESAJ
  FROM (SELECT pCUI AS CUI , dData AS DATA FROM DUAL) tmp LEFT JOIN WINMADMIN.NPART_ANAF PA ON PA.CUI = TMP.CUI AND PA.DATA = TMP.Data;

  DELETE FROM TMP_STRUCTURAANAF WHERE Cif_Valid(Cui) = 0;
  COMMIT;
END;

PROCEDURE StructuraANAF_Sinc IS
BEGIN
  INSERT INTO WINMADMIN.NPART_ANAF (
    CUI, DATA, STARE, CONTRIBUABIL, DENUMIRE,
    ADRESA, LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART,
    NRREGCOM, SPLITTVA, RTVAI, STAREINREG, STAREINACTIV, MESAJ)
  SELECT DISTINCT
    T.CUI, T.DATA, T.STARE, T.CONTRIBUABIL, T.DENUMIRE,
    T.ADRESA, T.LOCALITATE, T.JUDET, T.STRADA, T.BLOC, T.SCARA, T.NUMAR1, T.NUMAR2, T.ETAJ, T.APART,
    T.NRREGCOM, T.SPLITTVA, T.RTVAI, T.STAREINREG, T.STAREINACTIV, T.MESAJ
  FROM TMP_STRUCTURAANAF T
  WHERE STARE = 1 AND NOT EXISTS (SELECT 1 FROM WINMADMIN.NPART_ANAF A WHERE A.CUI = T.CUI AND A.DATA = T.DATA);
  COMMIT;
END;

PROCEDURE PartANAF_Init IS
  dData DATE := Trunc(SYSDATE);
BEGIN
  DELETE FROM WINMADMIN.NPART_ANAF WHERE DATA  &lt;&gt; dData;
  DELETE FROM WINMADMIN.NPART_ANAF WHERE STARE &lt;&gt; 1;
  DELETE FROM TMP_NPART_ANAF;
  INSERT INTO TMP_NPART_ANAF (
    CODPART, DEN_PART, CUI, DATA, STARE, OLD_CONTRIB, CONTRIBUABIL, OLD_SPLITTVA, SPLITTVA,
    ADRESA,
    LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART, OLD_ADRESA, CHANGE_ADRESA,
    OLD_RTVAI, RTVAI, OLD_NRREGCOM, NRREGCOM, DENUMIRE, CHANGE_DEN, OLD_INACTIV, INACTIV
  )
  SELECT DISTINCT
    TMP.CodPart, TMP.Den_Part, To_Number(TMP.Cui), dData AS Data, Coalesce(PA.Stare, 0) Stare, TMP.AreRO OLD_CONTRIB, PA.CONTRIBUABIL, TMP.OLD_SPLITTVA, Coalesce(PA.SPLITTVA, TMP.OLD_SPLITTVA) SPLITTVA,
    PA.ADRESA,
    PA.LOCALITATE, PA.JUDET, PA.STRADA, PA.BLOC, PA.SCARA, PA.NUMAR1, PA.NUMAR2, PA.ETAJ, PA.APART, TMP.OldAdresa, TMP.CHANGE_ADRESA,
    TMP.OLD_RTVAI, PA.RTVAI, TMP.OLD_NRREGCOM, PA.NRREGCOM, PA.DENUMIRE, 0 CHANGE_DEN, TMP.OLD_INACTIV,
    CASE WHEN PA.CONTRIBUABIL IN (-3, -2) THEN 1 ELSE 0 END AS INACTIV
  FROM (
    SELECT
      CodPart, Den_Part, OLD_NRREGCOM, OLD_SPLITTVA, OLD_RTVAI, OLD_INACTIV,
      CASE WHEN SubStr(CodFiscal, 1, 2) = &apos;RO&apos; THEN 1 ELSE 0 END AreRO,
      REGEXP_REPLACE(CodFiscal, &apos;\D&apos;, &apos;&apos;) Cui,
      REGEXP_REPLACE(CodFiscal, &apos;\d&apos;, &apos;&apos;) CUI_NonDigit,
      OldAdresa,
      CASE WHEN den_tara = &apos;1&apos; THEN 1 ELSE 0 END AS CHANGE_ADRESA
    FROM (
      SELECT
        NP.CodPart, NP.Den_Part,
        Upper(REGEXP_REPLACE(CF.CodFiscal, &apos;\.|\s&apos;)) CodFiscal, NP.REGCOM OLD_NRREGCOM,
        LSOC.DEN_LOCALIT||&apos;,&apos;||GetAdresa(SSOC.sector,SSOC.strada,SSOC.nr1,SSOC.nr2,SSOC.bloc,SSOC.scara,SSOC.etaj,SSOC.apart,SSOC.codpostal) AS OldAdresa, TSOC.DEN_TARA,
        Coalesce(NP.SPLITTVA, 0)      OLD_SPLITTVA,
        Coalesce(NP.TVALaIncasare, 0) OLD_RTVAI,
        Coalesce(NP.INACTIV, 0)       OLD_INACTIV
      FROM NPARTCODFISC CF
        INNER JOIN NPART    NP   ON NP.CODPART = CF.CODPART
        INNER JOIN NAGENDA  SSOC ON SSOC.CodPart = NP.CodPart AND SSOC.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(SSOC.INACTIV, 0) = 0
        INNER JOIN NLOCALIT LSOC ON LSOC.CODLOCALIT = Coalesce(SSOC.CODLOCALIT, 0)
        INNER JOIN NJUDET   JSOC ON JSOC.CODJUDET   = Coalesce(LSOC.CODJUDET, 0)
        INNER JOIN NTARI    TSOC ON TSOC.CODTARA    = Coalesce(LSOC.CODTARA, 0)
      WHERE NP.CodPart &lt;&gt; 0
        AND Coalesce(NP.PersoanaFizica, 0)  IN (0,2,3)
        AND (TSOC.SIMBAUTO = &apos;RO&apos; OR TSOC.DEN_TARA = &apos;1&apos;)
        AND Coalesce(CF.PRINCIPAL, 0) = 1
    ) A_PG
  ) TMP LEFT JOIN WINMADMIN.NPART_ANAF PA ON PA.CUI = TMP.CUI 
  WHERE CASE
          WHEN TMP.AreRO = 1 AND TMP.CUI_NonDigit = &apos;RO&apos;  THEN 1
          WHEN TMP.AreRO = 0 AND TMP.CUI_NonDigit IS NULL THEN 1
          ELSE 0
        END = 1
    AND Coalesce(Length(TMP.CUI), 0) BETWEEN 1 AND 20;

  DELETE FROM TMP_NPART_ANAF WHERE Cif_Valid(Cui)  = 0;
  UPDATE TMP_NPART_ANAF SET CONTRIBUABIL = OLD_CONTRIB WHERE CONTRIBUABIL IS NULL;
  COMMIT;
END;

PROCEDURE PartANAF_Sinc IS
BEGIN
  BEGIN
    EXECUTE IMMEDIATE &apos;DROP TABLE SAV_TMP_NPART_ANAF PURGE&apos;;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;
  EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_TMP_NPART_ANAF AS SELECT * FROM TMP_NPART_ANAF&apos;;
  INSERT INTO WINMADMIN.NPART_ANAF (
    CUI, DATA, STARE, CONTRIBUABIL, DENUMIRE,
    ADRESA, LOCALITATE, JUDET, STRADA, BLOC, SCARA, NUMAR1, NUMAR2, ETAJ, APART,
    NRREGCOM, SPLITTVA, RTVAI, STAREINREG, STAREINACTIV, MESAJ)
  SELECT DISTINCT
    T.CUI, T.DATA, T.STARE, T.CONTRIBUABIL, T.DENUMIRE,
    T.ADRESA, T.LOCALITATE, T.JUDET, T.STRADA, T.BLOC, T.SCARA, T.NUMAR1, T.NUMAR2, T.ETAJ, T.APART,
    T.NRREGCOM, T.SPLITTVA, T.RTVAI, T.STAREINREG, T.STAREINACTIV, T.MESAJ
  FROM TMP_NPART_ANAF T
  WHERE STARE = 1 AND NOT EXISTS (SELECT 1 FROM WINMADMIN.NPART_ANAF A WHERE A.CUI = T.CUI AND A.DATA = T.DATA);
  COMMIT;
END;

PROCEDURE PartANAF_ActDen IS
BEGIN
  FOR v_rec IN (
    SELECT CODPART, DENUMIRE
    FROM TMP_NPART_ANAF
    WHERE Coalesce(CHANGE_DEN,0) = 1 AND DENUMIRE IS NOT NULL AND CODPART IS NOT NULL
  ) LOOP
    UPDATE NPART
    SET DEN_PART = v_rec.DENUMIRE
    WHERE CODPART = v_rec.CODPART;
  END LOOP;
  PartANAF_Init;
  COMMIT;
END;

PROCEDURE PartANAF_ActSedSoc IS
  aCodLocalit NUMBER(20);
BEGIN
  FOR v_rec IN (
    SELECT CODPART, LOCALITATE, JUDET, STRADA, CASE WHEN Coalesce(NUMAR1, 0) &gt; 99999 THEN 99999 ELSE NUMAR1 END NUMAR1, NUMAR2, ETAJ, APART, BLOC, SCARA
    FROM TMP_NPART_ANAF tmp
    WHERE Coalesce(tmp.CHANGE_ADRESA,0) = 1 AND tmp.localitate IS NOT NULL
  ) LOOP
    aCodLocalit := PKG_IMPORTALTEAPLICATII.GETCODLOCALIT(v_rec.LOCALITATE, v_rec.JUDET,&apos;&apos;,&apos;RO&apos;,1);
    IF coalesce(aCodLocalit, 0) &lt;&gt; 0  THEN
      UPDATE NAGENDA nag
      SET STRADA     = v_rec.STRADA,
          NR1        = v_rec.NUMAR1,
          NR2        = v_rec.NUMAR2,
          ETAJ       = v_rec.ETAJ,
          APART      = v_rec.APART,
          BLOC       = v_rec.BLOC,
          SCARA      = v_rec.SCARA,
          CODLOCALIT = aCodLocalit
      WHERE nag.CODPART IS NOT NULL
        AND nag.CODPART = v_rec.CODPART
        AND nag.SEDIUSOCIAL BETWEEN 4 AND 7
        AND Coalesce(nag.INACTIV, 0) = 0;
    END IF;
  END LOOP;
  PartANAF_Init;
  COMMIT;
END;

PROCEDURE PartANAF_ActNrRegCom IS
BEGIN
  FOR v_rec IN (
    SELECT CODPART, NRREGCOM
    FROM TMP_NPART_ANAF
    WHERE CODPART IS NOT NULL AND NRREGCOM IS NOT NULL
      AND COALESCE(OLD_NRREGCOM, &apos;#&apos;) &lt;&gt; COALESCE(NRREGCOM, &apos;#&apos;)
  ) LOOP
    UPDATE NPART
    SET REGCOM = v_rec.NRREGCOM
    WHERE CODPART = v_rec.CODPART;
  END LOOP;
  PartANAF_Init;
  COMMIT;
END;

PROCEDURE PartANAF_ActRO IS
  vCOD_CODFISCAL NUMBER(20);
  sCODFISCAL     VARCHAR2(75);
BEGIN
  FOR vRec IN (
    SELECT CodPart, CUI, CONTRIBUABIL FROM  TMP_NPART_ANAF WHERE OLD_CONTRIB &lt;&gt; CONTRIBUABIL
  ) LOOP
    sCODFISCAL := vRec.CUI;
    IF vRec.CONTRIBUABIL = 1 THEN
      sCODFISCAL := &apos;RO&apos;||sCODFISCAL;
    END IF;

    UPDATE NPARTCODFISC SET PRINCIPAL = 0 WHERE CodPArt = vRec.CodPart;

    SELECT Coalesce(Max(COD_CODFISCAL), 0) INTO vCOD_CODFISCAL
    FROM NPARTCODFISC
    WHERE CODPART = vRec.CodPart AND Upper(REGEXP_REPLACE(CODFISCAL,&apos;\W+&apos;, &apos;&apos;)) = sCODFISCAL;

    IF vCOD_CODFISCAL = 0 THEN -- insert
      INSERT INTO NPARTCODFISC(COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL) VALUES (SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL, vRec.CodPart, trim(sCODFISCAL), 1);
    ELSE --update
      UPDATE NPARTCODFISC SET PRINCIPAL = 1 WHERE COD_CODFISCAL = vCOD_CODFISCAL;
    END IF;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_CONTRIB = CONTRIBUABIL WHERE OLD_SPLITTVA &lt;&gt; SPLITTVA;
  COMMIT;
END;

PROCEDURE PartANAF_ActSplitTVA IS
BEGIN
  FOR vRec IN (
    SELECT CodPart, SPLITTVA FROM TMP_NPART_ANAF WHERE OLD_SPLITTVA &lt;&gt; SPLITTVA
  ) LOOP
    UPDATE NPART SET SPLITTVA = vRec.SPLITTVA WHERE CodPArt = vRec.CodPart;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_SPLITTVA = SPLITTVA WHERE OLD_SPLITTVA &lt;&gt; SPLITTVA;
  COMMIT;
END;

PROCEDURE PartANAF_ActRTVAI IS
BEGIN
  FOR vRec IN (
    SELECT CodPart, RTVAI FROM TMP_NPART_ANAF WHERE OLD_RTVAI &lt;&gt; RTVAI
  ) LOOP
    UPDATE NPART SET TVALAINCASARE = vRec.RTVAI WHERE CodPArt = vRec.CodPart;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_RTVAI = RTVAI WHERE OLD_RTVAI &lt;&gt; RTVAI;
  COMMIT;
END;

PROCEDURE PartANAF_ActStareInactiv IS
BEGIN
  FOR vRec IN (
    SELECT CodPart, INACTIV FROM TMP_NPART_ANAF WHERE OLD_INACTIV &lt;&gt; INACTIV
  ) LOOP
    UPDATE NPART SET INACTIV = vRec.INACTIV WHERE CodPArt = vRec.CodPart;
  END LOOP;
  UPDATE TMP_NPART_ANAF SET OLD_INACTIV = INACTIV WHERE OLD_INACTIV &lt;&gt; INACTIV;
  COMMIT;
END;

procedure UpdateNPART1Double(Camp in varchar, valoare in number) is
begin
  UpdateNPART1String(Camp, replace(to_char(valoare), &apos;,&apos;, &apos;.&apos;));
end;

procedure UpdateNPART1Integer(Camp in varchar, valoare in number) is
begin
  UpdateNPART1String(Camp, to_char(valoare));
end;

procedure UpdateNPART1CRMInteger(Camp in varchar, valoare in number, aDataStart in date) is
begin
  UpdateNPART1CRMString(Camp, to_char(valoare), aDataStart);
end;


procedure UpdateNPART1String(Camp in varchar, valoare in varchar2) is
sString varchar2(1000);
begin
  for v_rec in (
    select part1.*
    from npart1 part1 inner join TMP_MANEVRA_LISTE tmp ON VALOARE = part1.CODPART AND FILTRU = &apos;CODPART&apos;
    WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN part1.alstart AND part1.alstop
      AND pkg_globals.getanlucru*12+pkg_globals.getlunalucru   &lt;&gt; part1.anstart*12+part1.lunastart
    order by part1.CODPART
  ) loop
    insert into npart1 (
      CODPART1, CODPART, CODIOPART,
      CREDITCLIENT, VOLUMTRANZC,
      CREDITFURN, VOLUMTRANZF,
      ANSTART, LUNASTART,
      SCADENTAV, SCADENTAC,
      DISCOUNT, CASSBAZAMIN,
      SIMBOLCASS, GDPR)
    values (
      seq_npart1_codpart1.nextval, v_Rec.CODPART, v_Rec.CODIOPART,
      v_Rec.CREDITCLIENT, v_Rec.VOLUMTRANZC,
      v_Rec.CREDITFURN, v_Rec.VOLUMTRANZF,
      pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU,
      v_Rec.SCADENTAV, v_Rec.SCADENTAC,
      v_Rec.DISCOUNT, v_Rec.CASSBAZAMIN,
      v_Rec.SIMBOLCASS, v_Rec.GDPR
    );
    prc_al_refresh(&apos;npart1&apos;, v_Rec.CODPART);
    commit;
  end loop;

  for v_rec in (
    select part1.CODPART1
    from npart1 part1 inner join TMP_MANEVRA_LISTE ON VALOARE = part1.CODPART AND FILTRU = &apos;CODPART&apos;
    WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN part1.alstart AND part1.alstop
    order by part1.CODPART
  ) loop
    sString := &apos;update npart1 set &apos;||Camp||&apos; = &apos;||valoare||&apos; where CODPART1 = &apos;||v_Rec.CODPART1;
    execute immediate sString;
  end loop;
  commit;
end;
procedure UpdateNPART1CRMString(Camp in varchar, valoare in Varchar2, aDataStart in date) is
  vCod NUMBER;
  sString VARCHAR2(1000);
begin
  for v_rec in (
    select TMP.VALOARE as CODPART,
           NC.CODPART1CRM, NC.CIFRAAFACERI, NC.NRANGAJATI, NC.LEAD, NC.SURSALEAD,
           NC.CODRESPONSABIL, NC.STARE, NC.MODPLATA, NC.CIP, NC.PROFIT
    from TMP_MANEVRA_LISTE TMP
    inner join (
      select NC1.*
      from NPART1CRM NC1
      where NC1.DATASTART = (
        select MAX(NC2.DATASTART)
        from NPART1CRM NC2
        where NC2.CODPART = NC1.CODPART
      )
      and NC1.DATAEND is null
    ) NC on NC.CODPART = TMP.VALOARE
    where TMP.FILTRU = &apos;CODPART&apos;
  ) loop
    update NPART1CRM
    set DATAEND = aDataStart - 1
    where CODPART1CRM = v_rec.CODPART1CRM;

    select seq_NPART1CRM_CodPart1Crm.Nextval into vCod from dual;

    insert into NPART1CRM (
      CODPART1CRM, CODPART, DATASTART,
      CIFRAAFACERI, NRANGAJATI, LEAD, SURSALEAD,
      CODRESPONSABIL, STARE, MODPLATA, CIP, PROFIT
    ) values (
      vCod, v_rec.CODPART, aDataStart,
      v_rec.CIFRAAFACERI, v_rec.NRANGAJATI, v_rec.LEAD, v_rec.SURSALEAD,
      v_rec.CODRESPONSABIL, v_rec.STARE, v_rec.MODPLATA, v_rec.CIP, v_rec.PROFIT
    );

    -- Modifica valoarea coloanei
    sString := &apos;update NPART1CRM set &apos;||Camp||&apos; = &apos;||valoare||&apos; where CODPART1CRM = &apos;||vCod;
    execute immediate sString;
  end loop;
  commit;
end;
 

END PKG_NOMPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BCFABC60C6B804B5BD996016ED31F042BBE0FE8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMPERS IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

FUNCTION GETDATAN(aCNP IN VARCHAR2) RETURN DATE IS
sy varchar2(4);
sm varchar2(2);  
sd varchar2(2);
oData date;
y number(4);
m number(2);
d number(2);
FirstChar char;
BEGIN
  begin
    oData := Null;
    if Length(acnp) &lt; 6 then return oData; end if;

    sy := Substr(acnp, 2, 2);
    sm := Substr(acnp, 4, 2);
    sd := Substr(acnp, 6, 2);

    FirstChar := Substr(acnp, 1, 1);
    begin
      y := to_number(sy);
    exception when others then y := 0;
    end;
    if y = 0 then return oData; end if;

    if (FirstChar = &apos;1&apos;) or (FirstChar = &apos;2&apos;)
    then y := y + 1900;
    else 
      if (FirstChar = &apos;5&apos;) or (FirstChar = &apos;6&apos;)
         then y := y + 2000;
         else if (FirstChar = &apos;3&apos;) or (FirstChar = &apos;4&apos;)
              then y := y + 2100;
              end if;
      end if;
    end if;          

    begin
      m := To_number(sm);
    exception when others then m := 0;
    end;
    if m = 0 then return odata; end if;
    begin
      d := To_number(sd);
    exception when others then d := 0;
    end;
    if d = 0 then return odata; end if;
    return to_date(lpad(to_char(d),2,&apos;0&apos;)||&apos;.&apos;||lpad(to_char(m),2,&apos;0&apos;)||&apos;.&apos;||to_char(y), &apos;dd.mm.yyyy&apos;);
  exception when others then return &apos;&apos;;
  end;  
END;  

FUNCTION GET_NUMEPRENUME(ACODPERS IN NUMBER) RETURN VARCHAR2 IS
sNM varchar2(400);
BEGIN
  BEGIN
    select nume||&apos; &apos;||prenume into sNM from npers where codpers = acodpers;
  EXCEPTION WHEN OTHERS THEN sNM := &apos;&apos;;
  END;
  return sNM;
END;

PROCEDURE Set_PASSWORD(aCodPers IN NUMBER, aPass IN VARCHAR2) IS
pragma autonomous_transaction;
BEGIN
  UPDATE NPERS SET ACCMAS = aPASS WHERE CODPERS = aCodPers;
  COMMIT;
END;

PROCEDURE SET_PERSOANA_CURENTA(ACODPERS IN NUMBER)
IS
BEGIN
  PERSOANA_CURENTA := ACODPERS;
END;

FUNCTION GET_PERSOANA_CURENTA RETURN NUMBER
IS
BEGIN
  RETURN PERSOANA_CURENTA;
END;

PROCEDURE SET_ICONTPERS_CURENT(AICONT IN NUMBER)
IS
BEGIN
  ICONT_PERS_CURENT  := AICONT;
END;

FUNCTION GET_ICONTPERS_CURENT RETURN NUMBER
IS
BEGIN
  RETURN ICONT_PERS_CURENT;
END;

PROCEDURE SET_MONEDAPERS_CURENT(AMONEDA IN NUMBER)
IS
BEGIN
  MONEDA_PERS_CURENT  := AMONEDA;
END;

FUNCTION GET_MONEDAPERS_CURENT RETURN NUMBER
IS
BEGIN
  RETURN MONEDA_PERS_CURENT;
END;

FUNCTION GET_COD_NPERS1(ACODPERS IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER) RETURN NUMBER
IS
  CPERS1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT NVL(CODPERS1, 0) INTO CPERS1 FROM NPERS1 N1
    WHERE N1.CODPERS = ACODPERS AND aAn*12+aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN CPERS1 := -1;
  END;
  RETURN CPERS1;
END;

FUNCTION GET_PERS_COD_CARACT_LUNA(ACODPERS IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER) RETURN NUMBER
IS
ACODIOPERS  NUMBER(20)  := -1;
ACODIOPERS1 NUMBER(20)  := -1;
BEGIN
  BEGIN
    SELECT NVL(CODIOPERS, 0) INTO ACODIOPERS FROM NPERS1 N1
    WHERE N1.CODPERS = ACODPERS AND aAn*12+aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN ACODIOPERS1 := -1;
  END;

  IF ACODIOPERS &gt; 0 THEN
    BEGIN
      SELECT NVL(CODIOPERS1, 0) INTO ACODIOPERS1 FROM IOPERS1 I1
      WHERE I1.CODIOPERS = ACODIOPERS AND aAn*12+aLuna BETWEEN i1.alstart AND i1.alstop;
    EXCEPTION WHEN OTHERS THEN ACODIOPERS1 := -1;
    END;
  END IF;
  RETURN ACODIOPERS1;
END;

FUNCTION GET_RECORD_PERS_CARACT_LUNA(ACODPERS IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN LUNA_REF_CURSOR
IS
TMPCURSOR LUNA_REF_CURSOR;
IOPERSCOD NUMBER(20);
BEGIN
  BEGIN
    SELECT NVL(CODIOPERS, -1) INTO IOPERSCOD FROM NPERS1 N1
    WHERE N1.CODPERS = ACODPERS AND An*12+Luna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN IOPERSCOD := -1;
  END;

  IF IOPERSCOD &gt; 0 THEN
    BEGIN
      OPEN TMPCURSOR FOR
      SELECT * FROM IOPERS1 I1
      WHERE I1.CODIOPERS = IOPERSCOD AND An*12+Luna BETWEEN i1.alstart AND i1.alstop;
    EXCEPTION WHEN OTHERS THEN OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
    END;
  ELSE
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END IF;

 RETURN TMPCURSOR;
END;

PROCEDURE SP_LOCKRECORD( RECID IN NUMBER )
IS
TMP NUMBER(20);
BEGIN
  SELECT CODPERS INTO TMP FROM NPERS WHERE CODPERS = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
aDoc        VARCHAR2(500);
ACODAGENDA  NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomPers --&gt; 502
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 502);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Persoana &quot;&apos;||Nume||&apos; &apos;||Prenume||&apos;&quot;&apos; INTO aDoc FROM npers WHERE codpers = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERS&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  SELECT AGENDA INTO ACODAGENDA FROM NPERS WHERE CODPERS = RECID;
  DELETE FROM NAGENTIPROC WHERE CODPERS = RECID;
  DELETE FROM NAGENTIVAL WHERE CODPERS = RECID;
  DELETE FROM NAGENTI1 WHERE CODPERS = RECID;
  DELETE FROM NPERS1 WHERE CODPERS = RECID;
  DELETE FROM NPERSCVSCOL WHERE CODPERS = RECID;
  DELETE FROM NPERSCVLOCM WHERE CODPERS = RECID;
  DELETE FROM NPERSCVSKIL WHERE CODPERS = RECID;
  DELETE FROM NPERSCVPAS WHERE CODPERS = RECID;
  DELETE FROM NAGENDA WHERE CODAGENDA = ACODAGENDA;

	DELETE FROM NPERS WHERE CODPERS = RECID ;

  NotifyModif(2, RECID, &apos;NPERS&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NPERS FIELDS( CODPERS) VALUES (0) ;
  -- nomPers --&gt; 502
  PKG_CFGTABLES.EXT_INSERTRECORD(502);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
AANSFARSIT   NUMBER(4);
ALUNASFARSIT NUMBER(2);
ACODAGENDA   NUMBER(20);
aCodFunctie  NUMBER(20) := 0;
vInd NUMBER(10);
vData DATE;
--ACODLOCALIT  NUMBER(20);
BEGIN
  -- MASTER NPERS
  INSERT INTO  TMP_NPERS (CODPERS,
                          MARCA,
                          NUME,
                          PRENUME,
                          CNP,
                          BISERIA,
                          BINR,
                          LOCNASTERE,
                          ADRESA,
                          PRENUMET,
                          PRENUMEM,
                          LOCALITN,
                          DATAN,
                          SCIVILA,
                          SMILITAR,
                          ACTIV,
                          STRAINATATE,
                          AGENT,
                          DELEGAT,
                          LOGONNAME,
                          ACCMAS,
                          COMISION,
                          CODGEST,
                          AGENDA,
                          BIELIBERATDE,
                          LADATADE,
                          TARAN,
                          CETATENIE,
                          codanalizanod,codanaliza,
                          POZA,
                          codsubunit,
                          DataPlecarii, DataAngajarii,codloc,
                          Obs,
                          OrePeZi,
                          CodCentru,
                          codcatpret,
                          IBAN,
                          CodBank )
    ( SELECT              p.CODPERS,
                          p.MARCA,
                          p.NUME,
                          p.PRENUME,
                          p.CNP,
                          p.BISERIA,
                          p.BINR,
                          p.LOCNASTERE,
                          p.ADRESA,
                          p.PRENUMET,
                          p.PRENUMEM,
                          p.LOCALITN,
                          p.DATAN,
                          p.SCIVILA,
                          p.SMILITAR,
                          nvl(p.ACTIV,1),
                          p.STRAINATATE,
                          p.AGENT,
                          p.DELEGAT,
                          p.LOGONNAME,
                          p.ACCMAS,
                          p.COMISION,
                          p.CODGEST,
                          p.AGENDA,
                          p.BIELIBERATDE,
                          p.LADATADE,
                          p.TARAN,
                          p.CETATENIE,p.codanalizanod, n.codanaliza,
                          p.POZA,
                          p.codsubunit,
                          p.DataPlecarii, DataAngajarii,
													p.codloc,
                          p.Obs,
                          p.OrePeZi,
                          P.CodCentru,
                          p.codcatpret,
                          P.IBAN,
                          P.CodBank
          FROM NPERS p left join analizanod n on n.codanalizanod = nvl(p.codanalizanod, 0) WHERE p.CODPERS = RECID) ;

  SELECT AGENDA  INTO ACODAGENDA FROM TMP_NPERS;

  -- DETAIL NPERS1
  INSERT INTO  TMP_NPERS1 ( CODPERS1, CODPERS, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART,LUNASTART, SCHIMB )
    ( SELECT CODPERS1, CODPERS, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART,LUNASTART,SCHIMB
      FROM NPERS1 WHERE CODPERS = RECID );

  -- TMP_AGENDA
  INSERT INTO  TMP_NAGENDA_PERS ( obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu,adresa, telefonp )
    ( SELECT obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu,GetAdresa(sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal),
             telefonp
      FROM NAGENDA WHERE CODAGENDA = ACODAGENDA  ) ;

  -- TMP_NPERSCURSX
		INSERT INTO TMP_NPERSCURSX
		( CODNPERSCURS,
			CODPERS     ,
			CODFUNCTIE  ,
			CODCURS     ,
			CODTEMA     ,
			STARE       ,
			DATA        ,
			NOTA        ,
			DATAPLAN    ,
			ORE_REALIZ  ,
			SUPLIM      ,
			DEN_CURS    ,
			DEN_TEMA    ,
			SSTARE      ,
			ORE_AFER    ,
      TipFormare, NivelFormare, CodObiectiv, Den_Obiectiv
			)
    with CF as
          (
            Select distinct P1.CodPers, F1.CodCurs, F1.CodTema, 0 Suplim
            from TMP_NPERS1 P1
                inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie),
         PC as
          (Select NP.CodPers, NP.CODNPERSCURS, Nvl(NP.codfunctie,0) codfunctie,  NP.CodCurs, NP.CodTema,
                  Nvl(NP.STARE,0) Stare, Case when Nvl(NP.codfunctie,0) = 0 then 1 else 0 end Suplim ,
                  NP.Nota,
                  NP.Data,
                  NP.DataPlan, NP.TipFormare, NP.NivelFormare, NP.CodObiectiv,
									NP.ORE_REALIZ
           from NPERSCURS NP
								where NP.CodPers = RecID)
    Select TMP.CODNPERSCURS, TMP.CODPERS, TMP.CodFunctie, TMP.CODCURS, TMP.CODTEMA, TMP.STARE, TMP.DATA, TMP.NOTA, TMP.DATAPLAN, TMP.ORE_REALIZ, TMP.Suplim,
           CC.DEN_CURS, TT.DEN_TEMA,
           &apos;xxxxxxxxxx&apos;, TT.ORE, TMP.TipFormare, TMP.NivelFormare, TMP.CodObiectiv, O.Den_Obiectiv
    from
    (
    Select PC.CODNPERSCURS,
		       PC.CodPers,
    			 Nvl(PC.CodFunctie, 0) CodFunctie,
					 PC.CodCurs,
					 PC.CodTema,
					 PC.DATA,
					 PC.DATAPLAN,
					 PC.ORE_REALIZ,
					 nvl(PC.STARE,0) STARE,
					 PC.Nota,
					 PC.Suplim, Nvl(PC.TipFormare,0) TipFormare, Nvl(PC.NivelFormare,0) NivelFormare, Nvl(PC.CodObiectiv,0) CodObiectiv
    from PC
    union all
		Select  -RowNum CODNPERSCURS,
		        CF.CODPERS,
						-1 CodFunctie,
						Nvl(CF.CodCurs, 0) CodCurs,
						Nvl(CF.CodTema, 0) CodTema,
						null Data,
						null DATAPLAN,
						0 ORE_REALIZ,
						0 STARE,
						null Nota,
						0 Suplim, 0 TipFormare, 0 NivelFormare, 0 CodObiectiv
    from CF
    where not Exists ( select CodNPERSCURS
		                   from NPERSCURS
											 where Nvl(CodFunctie,0) &lt;&gt; 0 and
											       CodCurs = CF.CodCurs and
														 CodTema = CF.CodTema and
														 Codpers = CF.CodPers)
		) TMP
    left join CURSURI CC on CC.CodCurs = TMP.CodCurs
    left join TEME    TT on TT.CodTema = TMP.CodTEMA
    left join OBIECTIVE O on O.CodObiectiv = TMP.CodObiectiv;
/*
  INSERT INTO TMP_NPERSCURSX (CODNPERSCURS, CODPERS, CODCURS, CODTEMA, DATA, DATAPLAN, ORE_REALIZ, STARE, NOTA, Suplim, CODOBIECTIV,TIPFORMARE,NIVELFORMARE,DEN_OBIECTIV)
    with CF as
          ( Select distinct P1.CodPers, P1.codfunctie, F1.CodCurs, F1.CodTema, 0 Suplim
            from tmp_NPERS1 P1
                 inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie),
         PC as
          (Select NP.CodPers, NP.CODNPERSCURS, Nvl(NP.codfunctie,0) codfunctie,  NP.CodCurs, NP.CodTema,
                  Nvl(NP.STARE,0) Stare, 1 Suplim,
                  NP.Nota,
                  NP.Data,
                  NP.DataPlan, NP.TipFormare, NP.NivelFormare, NP.CodObiectiv,
                  NP.ORE_REALIZ
           from NPERSCURS NP where NP.CodPers = RECID)
    Select TMP.CODNPERSCURS, TMP.CODPERS, TMP.CODCURS, TMP.CODTEMA, TMP.DATA, TMP.DATAPLAN, TMP.ORE_REALIZ, TMP.STARE, TMP.NOTA, TMP.Suplim,
           TMP.CodObiectiv, TMP.TipFormare, TMP.NivelFormare,
					 O.Den_Obiectiv
    from
    (Select Nvl(PC.CODNPERSCURS, -RowNum) CODNPERSCURS,
            CF.CODPERS,
            Nvl(CF.CodFunctie, 0) CodFunctie,
            Nvl(CF.CodCurs, PC.CodCurs) CodCurs,
            Nvl(CF.CodTema, PC.CodTema) CodTema,
            PC.DATA,
            PC.DATAPLAN,
            PC.ORE_REALIZ,
            Nvl(PC.STARE,0) STARE,
            PC.Nota,
            Nvl(CF.Suplim, PC.Suplim) Suplim, Nvl(PC.TipFormare,0) TipFormare, Nvl(PC.NivelFormare,0) NivelFormare, Nvl(PC.CodObiectiv,0) CodObiectiv
    from CF
         left join PC on PC.CodCurs = CF.CodCurs and PC.CodTema = CF.CodTema and Nvl(PC.CodFunctie,0) = CF.CodFunctie and CF.Codpers = PC.CodPers
    union all
    Select PC.CODNPERSCURS,
           PC.CodPers,
           Nvl(PC.CodFunctie, 0) CodFunctie,
           PC.CodCurs,
           PC.CodTema,
           PC.DATA,
           PC.DATAPLAN,
           PC.ORE_REALIZ,
           nvl(PC.STARE,0) STARE,
           PC.Nota,
           1 Suplim, Nvl(PC.TipFormare,0) TipFormare, Nvl(PC.NivelFormare,0) NivelFormare, Nvl(PC.CodObiectiv,0) CodObiectiv
    from PC
    where not Exists (select CF.CodTema from CF where Nvl(PC.CodFunctie,0) = CF.CodFunctie and PC.CodCurs = CF.CodCurs and CF.CodTema = PC.CodTema and CF.Codpers = PC.CodPers)
    ) TMP
    left join OBIECTIVE O on O.CodObiectiv = TMP.CodObiectiv;
*/  -- TMP_NPERSCVSCOL
  INSERT INTO TMP_NPERSCVSCOL (CODPERSCVSCOL, CODPERS, INDEXLOCAL, DELA, PANALA, SCOALA)
         (SELECT CODPERSCVSCOL, CODPERS, INDEXLOCAL, DELA, PANALA, SCOALA FROM NPERSCVSCOL WHERE CODPERS = RECID);
  -- TMP_NPERSCVLOCM
  INSERT INTO TMP_NPERSCVLOCM (CODPERSCVLOCM, CODPERS, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL)
         (SELECT CODPERSCVLOCM, CODPERS, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL FROM NPERSCVLOCM WHERE CODPERS = RECID);
  -- TMP_NPERSCVSKIL
  INSERT INTO TMP_NPERSCVSKIL (CODPERSCVSKIL, CODPERS, INDEXLOCAL, SKILL)
         (SELECT CODPERSCVSKIL, CODPERS, INDEXLOCAL, SKILL FROM NPERSCVSKIL WHERE CODPERS = RECID);
  -- TMP_NPERSCVPAS
  INSERT INTO TMP_NPERSCVPAS (CODPERSCVPAS, CODPERS, INDEXLOCAL, PASIUNE)
         (SELECT CODPERSCVPAS, CODPERS, INDEXLOCAL, PASIUNE FROM NPERSCVPAS WHERE CODPERS = RECID);

  INSERT INTO TMP_NAGENTI1 (CODAGENT1, CODPERS, DATASTART)
  SELECT CODAGENT1, CODPERS, DATASTART FROM NAGENTI1 WHERE CODPERS = RECID;
  vInd     := 0;
  FOR v_rec IN
   (
     SELECT * FROM NAGENTI1
     WHERE CODPERS = RECID
     order by DataStart  desc
   ) LOOP
     if vInd &gt; 0 then
       UPDATE Tmp_NAGENTI1 SET DataEnd = TO_DATE(vDATA, &apos;dd.mm.yyyy&apos;) WHERE CODAGENT1 = v_rec.CODAGENT1;
     end if;
     vDATA  := TO_DATE(v_rec.DATASTART - 1, &apos;dd.mm.yyyy&apos;);
     vInd := vInd + 1;
  END LOOP;

  INSERT INTO TMP_NAGENTIPROC (CODAGENTPROC, CODAGENT1, CODPERS, CODOBIECT, PECLASEA, CODPART, PECLASEP, PROC)
  SELECT CODAGENTPROC, CODAGENT1, CODPERS, CODOBIECT, PECLASEA, CODPART, PECLASEP, PROC
  FROM NAGENTIPROC WHERE CODPERS = RECID;

  FOR V_REC IN (SELECT
                  TMP.CODAGENTPROC, O.DENUMIRE DENART
                FROM TMP_NAGENTIPROC TMP
                     LEFT JOIN NARTOBJ O ON TMP.CODOBIECT = O.CODOBIECT
                WHERE NVL(TMP.PECLASEA,0) = 0
                UNION ALL
                SELECT
                  TMP.CODAGENTPROC, CLS.DEN_CLASEA DENART
                FROM TMP_NAGENTIPROC TMP
                     LEFT JOIN NCLASEA CLS ON TMP.CODOBIECT = CLS.CODCLASEA
                WHERE TMP.PECLASEA = 1
                ) LOOP
    UPDATE TMP_NAGENTIPROC SET
    DENART = V_REC.DENART
    WHERE CODAGENTPROC = V_REC.CODAGENTPROC;
  END LOOP;

  FOR V_REC IN (SELECT
                  TMP.CODAGENTPROC, P.DEN_PART DENPART
                FROM TMP_NAGENTIPROC TMP
                     LEFT JOIN NPART P ON TMP.CODPART = P.CODPART
                WHERE NVL(TMP.PECLASEP,0) = 0
                UNION ALL
                SELECT
                  TMP.CODAGENTPROC, CLS.DEN_CLASEP DENPART
                FROM TMP_NAGENTIPROC TMP
                     LEFT JOIN NCLASEP CLS ON TMP.CODPART = CLS.CODCLASEP
                WHERE TMP.PECLASEP = 1
                ) LOOP
    UPDATE TMP_NAGENTIPROC SET
    DENPART = V_REC.DENPART
    WHERE CODAGENTPROC = V_REC.CODAGENTPROC;
  END LOOP;

  INSERT INTO TMP_NAGENTIVAL(CODAGENTVAL, CODAGENT1, CODPERS, CODMONEDA, VALMAX, SIMBOL)
  SELECT V.CODAGENTVAL, V.CODAGENT1, V.CODPERS, V.CODMONEDA, V.VALMAX, M.SIMBOL
  FROM NAGENTIVAL V
       INNER JOIN NMONEDE M ON V.CODMONEDA = M.CODMONEDA
  WHERE V.CODPERS = RECID;

  AANSFARSIT := 0; ALUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODPERS1, ANSTART, LUNASTART FROM TMP_NPERS1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (AANSFARSIT &lt;&gt; 0)AND(ALUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NPERS1
      SET
        ANSFARSIT   = AANSFARSIT,
        LUNASFARSIT = ALUNASFARSIT
       WHERE
       CODPERS1 = V_REC.CODPERS1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
  -- nomPers --&gt; 502
  PKG_CFGTABLES.EXT_GOTORECORD(502);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
ACODAGENDA  NUMBER(20);
Acount NUMBER(20);
aDoc   VARCHAR2(500);
ACOD NUMBER(20);
BEGIN

  SELECT &apos;Persoana &quot;&apos;||Nume||&apos; &apos;||Prenume||&apos;&quot;&apos; INTO aDoc FROM TMP_NPERS;
  -- nomPers --&gt; 502
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (502); 
  IF OPERATION = 0 THEN  -- UPDATE

-- MASTER NPERS
    SELECT  CODPERS INTO RECID FROM TMP_NPERS;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NPERS SET ( CODPERS,
                          MARCA,
                          NUME,
                          PRENUME,
                          CNP,
                          BISERIA,
                          BINR,
                          LOCNASTERE,
                          ADRESA,
                          PRENUMET,
                          PRENUMEM,
                          LOCALITN,
                          DATAN,
                          SCIVILA,
                          SMILITAR,
                          ACTIV,
                          STRAINATATE,
                          AGENT,
                          DELEGAT,
                          LOGONNAME,
                          ACCMAS,
                          COMISION,
                          CODGEST,
                          AGENDA,
                          BIELIBERATDE,
                          LADATADE,
                          TARAN,
                          CETATENIE,codanalizanod,
                          POZA,
                          CODSUBUNIT,
                          DataPlecarii, DataAngajarii,CODLOC,OBS,
                          OrePeZi,
                          CodCentru,
                          CodCatPret,
                          IBAN,
                          CodBank  )
          = ( SELECT CODPERS,
                          MARCA,
                          NUME,
                          PRENUME,
                          CNP,
                          BISERIA,
                          BINR,
                          LOCNASTERE,
                          ADRESA,
                          PRENUMET,
                          PRENUMEM,
                          LOCALITN,
                          DATAN,
                          SCIVILA,
                          SMILITAR,
                          ACTIV,
                          STRAINATATE,
                          AGENT,
                          DELEGAT,
                          LOGONNAME,
                          ACCMAS,
                          COMISION,
                          CODGEST,
                          AGENDA,
                          BIELIBERATDE,
                          LADATADE,
                          TARAN,
                          CETATENIE,codanalizanod,
                          POZA,
                          CODSUBUNIT,
                          DataPlecarii, DataAngajarii,CODLOC,OBS,
                          OrePeZi,
                          CodCentru,
                          CodCatPret,
                          IBAN,
                          CodBank
                 FROM TMP_NPERS )
      WHERE CODPERS = RECID ;


    -- DETAIL NPERS1

    DELETE FROM NPERS1 WHERE CODPERS = RECID AND CODPERS1 NOT IN (SELECT CODPERS1 FROM TMP_NPERS1);


    INSERT INTO NPERS1 (CODPERS1, CODPERS, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART, LUNASTART,SCHIMB)
    SELECT  SEQ_NPERS1_CODPERS1.NEXTVAL, RECID, CODIOPERS,   CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART, LUNASTART,SCHIMB
    FROM TMP_NPERS1 WHERE CODPERS1 &lt; 0;


    -- DETAIL NPERSCV-URI
/*
    -- CURS
    DELETE FROM NPERSCURS WHERE CODPERS = RECID AND CODNPERSCURS NOT IN (SELECT CODNPERSCURS FROM TMP_NPERSCURSX);
    INSERT INTO NPERSCURS (CODNPERSCURS, CODPERS, CODCURS, DATA, STARE, NOTA)
           (SELECT SEQ_NPERSCURS_CODNPERSCURS.NEXTVAL, RECID, CODCURS, DATA, STARE, NOTA FROM TMP_NPERSCURSX WHERE CODNPERSCURS &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPERSCURSX WHERE NVL(CODNPERSCURS, -1) &gt; 0 ORDER BY CODNPERSCURS ) LOOP
       UPDATE NPERSCURS
       SET
        CODNPERSCURS  = v_rec.CODNPERSCURS,
        CODPERS        = v_rec.CODPERS,
        CODCURS        = v_rec.CODCURS,
        DATA           = v_rec.DATA,
        STARE          = v_rec.STARE,
        Nota           = v_rec.Nota
       WHERE CODNPERSCURS  = v_rec.CODNPERSCURS;
    END LOOP;
*/
    -- SCOL
    DELETE FROM NPERSCVSCOL WHERE CODPERS = RECID AND CODPERSCVSCOL NOT IN (SELECT CODPERSCVSCOL FROM TMP_NPERSCVSCOL);
    INSERT INTO NPERSCVSCOL (CODPERSCVSCOL, CODPERS, INDEXLOCAL, DELA, PANALA, SCOALA)
           (SELECT SEQ_NPERSCVSCOL_CODPERSCVSCOL.NEXTVAL, RECID, INDEXLOCAL, DELA, PANALA, SCOALA FROM TMP_NPERSCVSCOL WHERE CODPERSCVSCOL &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPERSCVSCOL WHERE NVL(codPERSCVSCOL, -1) &gt; 0 ORDER BY codPERSCVSCOL ) LOOP
       UPDATE NPERSCVSCOL
       SET
        CODPERSCVSCOL  = v_rec.CODPERSCVSCOL,
        CODPERS        = v_rec.CODPERS,
        INDEXLOCAL     = v_rec.INDEXLOCAL,
        DELA           = v_rec.DELA,
        PANALA         = v_rec.PANALA,
        SCOALA         = v_rec.scoala
       WHERE CODPERSCVSCOL  = v_rec.CODPERSCVSCOL;
    END LOOP;
    -- LOCM
    DELETE FROM NPERSCVLOCM WHERE CODPERS = RECID AND CODPERSCVLOCM NOT IN (SELECT CODPERSCVLOCM FROM TMP_NPERSCVLOCM);
    INSERT INTO NPERSCVLOCM (CODPERSCVLOCM, CODPERS, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL)
           (SELECT SEQ_NPERSCVLOCM_CODPERSCVLOCM.NEXTVAL, RECID, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL FROM TMP_NPERSCVLOCM WHERE CODPERSCVLOCM &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPERSCVLOCM WHERE NVL(codPERSCVLOCM, -1) &gt; 0 ORDER BY codPERSCVLOCM ) LOOP
       UPDATE NPERSCVLOCM
       SET
        CODPERSCVLOCM  = v_rec.CODPERSCVLOCM,
        CODPERS        = v_rec.CODPERS,
        INDEXLOCAL     = v_rec.INDEXLOCAL,
        DELA           = v_rec.DELA,
        PANALA         = v_rec.PANALA,
        LOCMUNCA       = v_rec.LOCMUNCA,
        CODFISCAL      = v_rec.Codfiscal
       WHERE CODPERSCVLOCM  = v_rec.CODPERSCVLOCM;
    END LOOP;
    -- SKIL
    DELETE FROM NPERSCVSKIL WHERE CODPERS = RECID AND CODPERSCVSKIL NOT IN (SELECT CODPERSCVSKIL FROM TMP_NPERSCVSKIL);
    INSERT INTO NPERSCVSKIL (CODPERSCVSKIL, CODPERS, INDEXLOCAL, SKILL)
           (SELECT SEQ_NPERSCVSKIL_CODPERSCVSKIL.NEXTVAL, RECID, INDEXLOCAL, SKILL FROM TMP_NPERSCVSKIL WHERE CODPERSCVSKIL &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPERSCVSKIL WHERE NVL(codPERSCVSKIL, -1) &gt; 0 ORDER BY codPERSCVSKIL ) LOOP
       UPDATE NPERSCVSKIL
       SET
        CODPERSCVSKIL  = v_rec.CODPERSCVSKIL,
        CODPERS        = v_rec.CODPERS,
        INDEXLOCAL     = v_rec.INDEXLOCAL,
        SKILL           = v_rec.SKILL
       WHERE CODPERSCVSKIL  = v_rec.CODPERSCVSKIL;
    END LOOP;
    -- PAS
    DELETE FROM NPERSCVPAS WHERE CODPERS = RECID AND CODPERSCVPAS NOT IN (SELECT CODPERSCVPAS FROM TMP_NPERSCVPAS);
    INSERT INTO NPERSCVPAS (CODPERSCVPAS, CODPERS, INDEXLOCAL, PASIUNE)
           (SELECT SEQ_NPERSCVPAS_CODPERSCVPAS.NEXTVAL, RECID, INDEXLOCAL, PASIUNE FROM TMP_NPERSCVPAS WHERE CODPERSCVPAS &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPERSCVPAS WHERE NVL(codPERSCVPAS, -1) &gt; 0 ORDER BY codPERSCVPAS ) LOOP
       UPDATE NPERSCVPAS
       SET
        CODPERSCVPAS  = v_rec.CODPERSCVPAS,
        CODPERS       = v_rec.CODPERS,
        INDEXLOCAL    = v_rec.INDEXLOCAL,
        PASIUNE       = v_rec.PASIUNE
       WHERE CODPERSCVPAS  = v_rec.CODPERSCVPAS;
    END LOOP;


    -- exista posibilitatea ca sa nu existe agenda existenta in npers si atunci ...
    SELECT NVL(AGENDA, -1) INTO ACODAGENDA  FROM NPERS   WHERE CODPERS   = RECID ;
    if ACODAGENDA = -1 then
      --daca nu exista atunci se face insert
      SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL INTO ACODAGENDA FROM DUAL;
      INSERT INTO  NAGENDA ( obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu, telefonp)
      ( SELECT obs,ACODAGENDA, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu, telefonp
      FROM TMP_NAGENDA_PERS );
      -- facem update-ul si pentru npers cu noua valoare a agendei
      update npers
      set
        agenda = acodagenda
      where codpers = recid;
    else
      --am gasit incoerente in baza ... exista agenda in npers dar nu exista inreg in nagenda corespunzatoare, deci ...
      select count(*) into acount from nagenda where codagenda = acodagenda;
      if acount = 0 then
        -- insert
        INSERT INTO  NAGENDA ( obs,codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu, telefonp)
        ( SELECT obs,ACODAGENDA, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit,codtraseu,poztraseu, telefonp
        FROM TMP_NAGENDA_PERS );
      else
        --update
        -- AGENDA
        UPDATE NAGENDA SET (obs,
                           tip,
                           codlocalit,
                           sediusocial,
                           telefon,
                           fax,
                           email,
                           sector,
                           strada,
                           nr1,
                           nr2,
                           bloc,
                           scara,
                           etaj,
                           apart,
                           codpostal,
                           km,
                           codbankcont,
                           codpart,
                           codgest,
                           codsubunit,
                           codtraseu,
                           poztraseu,
                           telefonp)
                           =
            (SELECT        obs,
                           tip,
                           codlocalit,
                           sediusocial,
                           telefon,
                           fax,
                           email,
                           sector,
                           strada,
                           nr1,
                           nr2,
                           bloc,
                           scara,
                           etaj,
                           apart,
                           codpostal,
                           km,
                           codbankcont,
                           codpart,
                           codgest,
                           codsubunit,
                           codtraseu,
                           poztraseu,
                           telefonp FROM TMP_NAGENDA_PERS)
            WHERE codagenda = Acodagenda;
       end if;
   end if;
    -- LOCALIT
    --UPDATE NLOCALIT ( codlocalit,den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,CODZONA )
    --( SELECT codlocalit,den_localit,tip,codjudet,obs, CODTARA,DENSUP,SIRUTA,codzona
      --FROM TMP_NLOCALIT WHERE codlocalit = ACODLOCALIT ) ;

    FOR V_REC IN ( SELECT * FROM TMP_NPERS1 WHERE NVL(CODPERS1,0) &gt; 0 ORDER BY CODPERS1 )
    LOOP
      UPDATE NPERS1 SET
       CODIOPERS   = V_REC.CODIOPERS,
       CODFORMATIE = V_REC.CODFORMATIE,
       CODFUNCTIE  = V_REC.CODFUNCTIE ,
       CODMESERIE  = V_REC.CODMESERIE ,
       ANSTART     = V_REC.ANSTART,
       LUNASTART   = V_REC.LUNASTART,
       SCHIMB      = V_REC.SCHIMB
      WHERE CODPERS1 = V_REC.CODPERS1;
    END LOOP;

    DELETE NAGENTI1 AG1 WHERE AG1.CODPERS = RECID AND NOT EXISTS (SELECT TMP.CODAGENT1 FROM TMP_NAGENTI1 TMP WHERE TMP.CODAGENT1 = AG1.CODAGENT1);
    FOR V_REC IN (SELECT * FROM TMP_NAGENTI1) LOOP
      IF V_REC.CODAGENT1 &gt; 0 THEN
        UPDATE NAGENTI1 SET
          DATASTART = V_REC.DATASTART
        WHERE CODAGENT1 = V_REC.CODAGENT1;
      ELSE
        SELECT SEQ_NAGENTI1_CODAGENT1.NEXTVAL INTO ACOD FROM DUAL;
        UPDATE TMP_NAGENTIVAL SET CODAGENT1 = ACOD WHERE CODAGENT1 = V_REC.CODAGENT1;
        UPDATE TMP_NAGENTIPROC SET CODAGENT1 = ACOD WHERE CODAGENT1 = V_REC.CODAGENT1;
        INSERT INTO NAGENTI1 (CODAGENT1, CODPERS, DATASTART)
        VALUES (ACOD, RECID, V_REC.DATASTART);
      END IF;
    END LOOP;

    DELETE NAGENTIVAL AGV WHERE AGV.CODPERS = RECID AND NOT EXISTS (SELECT TMP.CODAGENTVAL FROM TMP_NAGENTIVAL TMP WHERE TMP.CODAGENTVAL = AGV.CODAGENTVAL);
    FOR V_REC IN (SELECT * FROM TMP_NAGENTIVAL) LOOP
      IF V_REC.CODAGENTVAL &gt; 0 THEN
        UPDATE NAGENTIVAL SET
          CODMONEDA = V_REC.CODMONEDA,
          VALMAX    = V_REC.VALMAX
        WHERE CODAGENTVAL = V_REC.CODAGENTVAL;
      ELSE
        INSERT INTO NAGENTIVAL(CODAGENTVAL, CODAGENT1, CODPERS, CODMONEDA, VALMAX)
        VALUES (SEQ_NAGENTIVAL_CODAGENTVAL.NEXTVAL, V_REC.CODAGENT1, RECID, V_REC.CODMONEDA, V_REC.VALMAX);
      END IF;
    END LOOP;

    DELETE NAGENTIPROC AGP WHERE AGP.CODPERS = RECID AND NOT EXISTS (SELECT TMP.CODAGENTPROC FROM TMP_NAGENTIPROC TMP WHERE TMP.CODAGENTPROC = AGP.CODAGENTPROC);
    FOR V_REC IN (SELECT * FROM TMP_NAGENTIPROC) LOOP
      IF V_REC.CODAGENTPROC &gt; 0 THEN
        UPDATE NAGENTIPROC SET
          CODOBIECT = V_REC.CODOBIECT,
          PECLASEA  = V_REC.PECLASEA,
          CODPART   = V_REC.CODPART,
          PECLASEP  = V_REC.PECLASEP,
          PROC      = V_REC.PROC
        WHERE CODAGENTPROC = V_REC.CODAGENTPROC;
      ELSE
        INSERT INTO NAGENTIPROC(CODAGENTPROC, CODAGENT1, CODPERS, CODOBIECT, PECLASEA, CODPART, PECLASEP, PROC)
        VALUES (SEQ_NAGENTIPROC_CODAGENTPROC.NEXTVAL, V_REC.CODAGENT1, RECID, V_REC.CODOBIECT, V_REC.PECLASEA, V_REC.CODPART, V_REC.PECLASEP, V_REC.PROC);
      END IF;
    END LOOP;

  ELSE  -- INSERT
  -- MASTER NPERS

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERS&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  SELECT SEQ_NPERS_CODPERS.NEXTVAL INTO RECID FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NPERS&apos;, RecId); 
  SELECT SEQ_NAGENDA_CODAGENDA.NEXTVAL INTO ACODAGENDA FROM DUAL;

  INSERT INTO  NPERS ( CODPERS,
                          MARCA,
                          NUME,
                          PRENUME,
                          CNP,
                          BISERIA,
                          BINR,
                          LOCNASTERE,
                          ADRESA,
                          PRENUMET,
                          PRENUMEM,
                          LOCALITN,
                          DATAN,
                          SCIVILA,
                          SMILITAR,
                          ACTIV,
                          STRAINATATE,
                          AGENT,
                          DELEGAT,
                          LOGONNAME,
                          ACCMAS,
                          COMISION,
                          CODGEST,
                          AGENDA,
                          BIELIBERATDE,
                          LADATADE,
                          TARAN,
                          CETATENIE,codanalizanod,
                          POZA,
                          CODSUBUNIT,
                          DataPlecarii, DataAngajarii,CODLOC,OBS,
                          OrePeZi,
                          CodCentru,
                          CodCatPret,
                          IBAN,
                          CodBank )
 ( SELECT  RecId,
                          MARCA,
                          NUME,
                          PRENUME,
                          CNP,
                          BISERIA,
                          BINR,
                          LOCNASTERE,
                          ADRESA,
                          PRENUMET,
                          PRENUMEM,
                          LOCALITN,
                          DATAN,
                          SCIVILA,
                          SMILITAR,
                          ACTIV,
                          STRAINATATE,
                          AGENT,
                          DELEGAT,
                          LOGONNAME,
                          ACCMAS,
                          COMISION,
                          CODGEST,
                          ACODAGENDA,
                          BIELIBERATDE,
                          LADATADE,
                          TARAN,
                          CETATENIE,codanalizanod,
                          POZA,
                          CODSUBUNIT,
                          DataPlecarii, DataAngajarii,CODLOC,OBS,
                          OrePeZi,
                          CodCentru,
                          CodCatPret,
                          IBAN,
                          CodBank
            FROM TMP_NPERS);

  -- DETAIL NPERS1
  INSERT INTO  NPERS1
     ( CODPERS1, CODPERS, CODIOPERS, CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART, LUNASTART,SCHIMB )
     ( SELECT SEQ_NPERS1_CODPERS1.NEXTVAL, RECID, CODIOPERS, CODFORMATIE, CODFUNCTIE, CODMESERIE, ANSTART, LUNASTART,SCHIMB FROM TMP_NPERS1 );
  --DETAIL NPERSCVSCOL
  INSERT INTO NPERSCVSCOL (CODPERSCVSCOL, CODPERS, INDEXLOCAL, DELA, PANALA, SCOALA)
         (SELECT SEQ_NPERSCVSCOL_CODPERSCVSCOL.NEXTVAL, RecId, INDEXLOCAL, DELA, PANALA, SCOALA FROM TMP_NPERSCVSCOL);


/*
  --DETAIL NPERSCURS
    INSERT INTO NPERSCURS (CODNPERSCURS, CODPERS, CODCURS, DATA, STARE, NOTA)
         (SELECT SEQ_NPERSCURS_CODNPERSCURS.NEXTVAL, RECID, CODCURS, DATA, STARE, NOTA FROM TMP_NPERSCURSX);
*/
  -- DETAIL NPERSCVLOCM
  INSERT INTO NPERSCVLOCM (CODPERSCVLOCM, CODPERS, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL)
         (SELECT SEQ_NPERSCVLOCM_CODPERSCVLOCM.NEXTVAL, RECID, INDEXLOCAL, DELA, PANALA, LOCMUNCA, CODFISCAL FROM TMP_NPERSCVLOCM);
  -- DETAIL NPERSCVSKIL
  INSERT INTO NPERSCVSKIL (CODPERSCVSKIL, CODPERS, INDEXLOCAL, SKILL)
         (SELECT SEQ_NPERSCVSKIL_CODPERSCVSKIL.NEXTVAL, RECID, INDEXLOCAL, SKILL FROM TMP_NPERSCVSKIL);
  -- DETAIL NPERSCVPAS
  INSERT INTO NPERSCVPAS (CODPERSCVPAS, CODPERS, INDEXLOCAL, PASIUNE)
         (SELECT SEQ_NPERSCVPAS_CODPERSCVPAS.NEXTVAL, RECID, INDEXLOCAL, PASIUNE FROM TMP_NPERSCVPAS);
  -- NAGENDA
  INSERT INTO  NAGENDA ( codagenda,tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, obs, codtraseu, poztraseu, telefonp)
    ( SELECT ACODAGENDA, tip,codlocalit,sediusocial,telefon,fax,email,sector,strada,nr1,nr2,bloc,scara,etaj,apart,codpostal,km,codbankcont,codpart,codgest,codsubunit, obs, codtraseu, poztraseu, telefonp
    FROM TMP_NAGENDA_PERS );

  FOR V_REC IN (SELECT * FROM TMP_NAGENTI1) LOOP
    SELECT SEQ_NAGENTI1_CODAGENT1.NEXTVAL INTO ACOD FROM DUAL;
    UPDATE TMP_NAGENTIVAL SET CODAGENT1 = ACOD WHERE CODAGENT1 = V_REC.CODAGENT1;
    UPDATE TMP_NAGENTIPROC SET CODAGENT1 = ACOD WHERE CODAGENT1 = V_REC.CODAGENT1;
    INSERT INTO NAGENTI1 (CODAGENT1, CODPERS, DATASTART)
    VALUES (ACOD, RECID, V_REC.DATASTART);
  END LOOP;

  INSERT INTO NAGENTIVAL(CODAGENTVAL, CODAGENT1, CODPERS, CODMONEDA, VALMAX)
  SELECT SEQ_NAGENTIVAL_CODAGENTVAL.NEXTVAL, CODAGENT1, RECID, CODMONEDA, VALMAX
  FROM TMP_NAGENTIVAL;

  INSERT INTO NAGENTIPROC(CODAGENTPROC, CODAGENT1, CODPERS, CODOBIECT, PECLASEA, CODPART, PECLASEP, PROC)
  SELECT SEQ_NAGENTIPROC_CODAGENTPROC.NEXTVAL, CODAGENT1, RECID, CODOBIECT, PECLASEA, CODPART, PECLASEP, PROC
  FROM TMP_NAGENTIPROC;
END IF;

 PRC_AL_REFRESH(&apos;NPERS1&apos;, RECID);
   -- nomPers --&gt; 502
 PKG_CFGTABLES.EXT_POSTRECORDS(502); 

 NotifyModif(OPERATION, RECID, &apos;NPERS&apos;);

 COMMIT;
END;

procedure PROPAGADISCVALAG(aCodPers in number) is
aCod number(20);
begin
  for v_rec in (select ag1.codagent1
                from tmp_npers_manevra tmp
                     inner join nagenti1 ag1 on tmp.codpers = ag1.codpers
                where tmp.codpers &lt;&gt; aCodPers) loop
    delete nagentiproc where codagent1 = v_rec.codagent1;
    delete nagentival where codagent1 = v_rec.codagent1;
    delete nagenti1 where codagent1 = v_rec.codagent1;
  end loop;
  commit;
  for v_rec in (select codpers
                from tmp_npers_manevra
                where codpers &lt;&gt; aCodPers) loop
    for v_ag1 in (select *
                  from nagenti1
                  where codpers = aCodPers) loop
      select seq_nagenti1_codagent1.nextval into aCod from dual;
      insert into nagenti1 (codagent1, codpers, datastart)
      values (aCod, v_rec.codpers, v_ag1.datastart);
      insert into nagentiproc(codagentproc,codagent1,codpers,codobiect,peclasea,codpart,peclasep,proc)
      select seq_nagentiproc_codagentproc.nextval,aCod,v_rec.codpers,codobiect,peclasea,codpart,peclasep,proc
      from nagentiproc
      where codagent1 = v_ag1.codagent1;
      insert into nagentival(codagentval, codagent1, codpers, codmoneda, valmax)
      select seq_nagentival_codagentval.nextval, aCod, v_rec.codpers, codmoneda, valmax
      from nagentival
      where codagent1 = v_ag1.codagent1;
    end loop;
  end loop;
  commit;
end;

END PKG_NOMPERS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMREMAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B087573C0545CE2616DAF6081744BC58E7BD054</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMREMAUTO IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodRemAuto INTO Tmp FROM NREMAUTO WHERE CodRemAuto = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NREMAUTO WHERE CodRemAuto = RecId ;
  NotifyModif(2, RECID, &apos;NREMAUTO&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NREMAUTO FIELDS( CodRemAuto ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NREMAUTO ( CodRemAuto, TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2 )
    ( SELECT CodRemAuto, TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2 
      FROM NREMAUTO WHERE CodRemAuto = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodRemAuto INTO RecId FROM TMP_NREMAUTO;
    UPDATE NREMAUTO SET ( TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2 )
       = ( SELECT TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2
          FROM TMP_NREMAUTO )
      WHERE CodRemAuto = RecId ;

  ELSE  -- INSERT
-- Master Nautom
  SELECT seq_nRemauto_codRemauto.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NREMAUTO ( CodRemAuto, TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2 )
 ( SELECT  RecId , TipuriRemorci, Spor_150_1, Spor_150_2, Spor150_215_1, Spor150_215_2, Spor215_1, Spor215_2
     FROM TMP_NREMAUTO  ) ;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;NREMAUTO&apos;);  

  COMMIT;
END;

end pkg_nomremauto; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMRESTAURANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6B10C4B898280DF4B4FC55DCAE469BD30C33D9B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMRESTAURANTE is


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODRESTAURANT INTO Tmp FROM RESTAURANTE WHERE CODRESTAURANT = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	 FOR V_REC IN (SELECT * FROM RESTAURANTE WHERE CODRESTAURANT = RECID)
  LOOP
   -- aici de bagat stergere detalii restaurant
    DELETE FROM RESTAURANTE WHERE CODRESTAURANT = V_REC.CODRESTAURANT;
  END LOOP;
  NotifyModif(2, RECID, &apos;RESTAURANTE&apos;);  
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RESTAURANTE FIELDS( CODRESTAURANT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_RESTAURANTE(CODRESTAURANT, DENUMIRE, SUBUNITATEA, TIPORAR, ORASTART, ORAEND, TIPUNICITATE, TIPGESTIMPLICITA, POSTWMRETAIL, CODPOSTRETAIL)
  SELECT 
    CODRESTAURANT, 
    DENUMIRE, 
    SUBUNITATEA, 
    NVL(TIPORAR,0),  
    ORASTART, 
    ORAEND, 
    NVL(TIPUNICITATE,0),  
    NVL(TIPGESTIMPLICITA, 0),  
    NVL(POSTWMRETAIL, 0), 
    NVL(CODPOSTRETAIL, 0)
  FROM 
    RESTAURANTE 
  WHERE 
   CODRESTAURANT = RecId  ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  
    SELECT  CODRESTAURANT INTO RecId FROM TMP_RESTAURANTE;

    UPDATE RESTAURANTE
    SET
      (DENUMIRE, SUBUNITATEA, TIPORAR, ORASTART, ORAEND, TIPUNICITATE, TIPGESTIMPLICITA, POSTWMRETAIL, CODPOSTRETAIL) = (SELECT DENUMIRE, SUBUNITATEA, TIPORAR, ORASTART, ORAEND, TIPUNICITATE, TIPGESTIMPLICITA, POSTWMRETAIL, CODPOSTRETAIL FROM TMP_RESTAURANTE)
    WHERE 
      CODRESTAURANT = RECID;

  ELSE  
    SELECT SEQ_RESTAURANTE_CODRESTAURANT.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO RESTAURANTE(CODRESTAURANT, DENUMIRE, SUBUNITATEA, TIPORAR, ORASTART, ORAEND, TIPUNICITATE, TIPGESTIMPLICITA, POSTWMRETAIL, CODPOSTRETAIL)
    SELECT RECID, DENUMIRE, SUBUNITATEA, TIPORAR, ORASTART, ORAEND, TIPUNICITATE, TIPGESTIMPLICITA, POSTWMRETAIL, CODPOSTRETAIL FROM TMP_RESTAURANTE;
  END IF;

  NotifyModif(OPERATION, RECID, &apos;RESTAURANTE&apos;);  

  COMMIT;
END;

end PKG_NOMRESTAURANTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D868BD6D9BC9C92F16DB7C349E10A836F0A3633</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMSUBUNIT IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

FUNCTION CATECARNETE (aCODSUBUNIT IN NUMBER) RETURN NUMBER IS
iResult number(20);
BEGIN
 select count(*) into iResult from doccarnete where subunitatea = aCodSubunit;
 Return iResult;
END;

FUNCTION GENEREAZACARNETE (ACODSUBUNIT IN NUMBER) RETURN NUMBER IS
  IRESULT    NUMBER(20) := 0;
  ACODCARNET NUMBER(20) ;
BEGIN
  --CREATE TABLE SRC_DOCCARNETE AS SELECT * FROM DOCCARNETE;
  --CREATE TABLE SRC_DOCLINK    AS SELECT * FROM DOCLINK;
  --CREATE TABLE SRC_DOCFREE    AS SELECT * FROM DOCFREE;
  FOR V_REC IN (SELECT CODCARNET, SIMBOL, DENUMIRE, SERIE, STARTNR, ENDNR, FREENR, INACTIV, SUBUNITATEA, LIMITA FROM SRC_DOCCARNETE) LOOP
    SELECT SEQ_DOCCARNETE_CODCARNET.NEXTVAL INTO ACODCARNET FROM DUAL;
    INSERT INTO DOCCARNETE(CODCARNET, SIMBOL,      DENUMIRE,      SERIE,      STARTNR,      ENDNR,      FREENR,      INACTIV,      SUBUNITATEA,LIMITA)
    VALUES                (ACODCARNET,V_REC.SIMBOL,V_REC.DENUMIRE,V_REC.SERIE,V_REC.STARTNR,V_REC.ENDNR,V_REC.FREENR,V_REC.INACTIV,ACODSUBUNIT,V_REC.LIMITA);
    IRESULT := IRESULT + 1;

    FOR V_REC_DOCLINK IN (SELECT CODDOCLINK,CODMACHETA FROM SRC_DOCLINK WHERE CODCARNET = V_REC.CODCARNET) LOOP
      INSERT INTO DOCLINK(CODDOCLINK,CODCARNET,CODMACHETA) VALUES (SEQ_DOCLINK_CODDOCLINK.NEXTVAL,ACODCARNET,V_REC_DOCLINK.CODMACHETA);
    END LOOP;

    FOR V_REC_DOCFREE IN (SELECT CODDOCFREE,STARTNR,ENDNR FROM SRC_DOCFREE WHERE CODCARNET = V_REC.CODCARNET) LOOP
      INSERT INTO DOCFREE(CODDOCFREE,CODCARNET,STARTNR,ENDNR) VALUES (SEQ_DOCFREE_CODDOCFREE.NEXTVAL,ACODCARNET,V_REC_DOCFREE.STARTNR,V_REC_DOCFREE.ENDNR);
    END LOOP;
  END LOOP;
  --COMMIT; INCAPSULAT IN TRANZACTIE INDEPENDENTA IN DELPHI CA ALTFEL CRAPA CAND SE DECLANSEAZA FUNCTIA ASTA DE PE DOCUMENTE
  RETURN IRESULT;
END;

FUNCTION getDenSubunit (aCod IN NUMBER) RETURN VARCHAR2 IS
sResult VARCHAR2(100);
BEGIN
  SELECT den_subunit INTO sResult FROM nsubunit WHERE codsubunit = aCod;
  RETURN sResult;
END;

FUNCTION GET_COD_NSUBUNIT1(ACODSUBUNIT IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER) RETURN NUMBER
IS
  CSUBUNIT1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT NVL(CODSUBUNIT1, 0) INTO CSUBUNIT1 FROM NSUBUNIT1 N1
    WHERE N1.CODSUBUNIT = ACODSUBUNIT AND aAn*12+aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN CSUBUNIT1 := -1;
  END;
  RETURN CSUBUNIT1;
END;

FUNCTION GET_SUBUNIT_COD_CARACT_LUNA(ACODSUBUNIT IN NUMBER, AAN IN NUMBER, ALUNA IN NUMBER, ACODIOFILIAL OUT NUMBER) RETURN NUMBER
IS
  ACODIOFILIAL1 NUMBER(20)  := -1;
BEGIN
  ACODIOFILIAL  := -1;

  BEGIN
    SELECT NVL(CODIOFILIAL, 0) INTO ACODIOFILIAL FROM NSUBUNIT1 N1
    WHERE N1.CODSUBUNIT = ACODSUBUNIT AND aAn*12+aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN ACODIOFILIAL1 := -1;
  END;

  IF ACODIOFILIAL &gt; 0 THEN
    BEGIN
      SELECT NVL(CODIOFILIAL1, 0) INTO ACODIOFILIAL1 FROM IOFILIAL1 I1
      WHERE I1.CODIOFILIAL = ACODIOFILIAL AND aAn*12+aLuna BETWEEN i1.alstart AND i1.alstop;
    EXCEPTION WHEN OTHERS THEN ACODIOFILIAL1 := -1;
    END;
  END IF;
  RETURN ACODIOFILIAL1;
END;

PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
  TMP NUMBER(20);
BEGIN
  SELECT CODSUBUNIT INTO TMP FROM NSUBUNIT WHERE CODSUBUNIT = RECID FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
AdoC VARCHAR2(150);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;subunitate &quot;&apos;||n.DEN_SUBUNIT||&apos;&quot;&apos; INTO aDoc
   FROM NSUBUNIT n where N.CODSUBUNIT = RECID;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSUBUNIT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
  DELETE FROM NSUBUNIT1 WHERE CODSUBUNIT = RECID;
  DELETE FROM NSUBUNIT WHERE CODSUBUNIT = RECID ;

  NotifyModif(2, RECID, &apos;NSUBUNIT&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NSUBUNIT FIELDS( CODSUBUNIT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
BEGIN
  -- MASTER NSUBUNIT
  INSERT INTO  TMP_NSUBUNIT (
    CODSUBUNIT,DEN_SUBUNIT,CIF, SATELITWM, ANPORNIRE, LUNAPORNIRE, NUMEPRESC, REGCOM,
    CODBANKCONT, CODBANKCONTTREZ, CODCATPRET,  CODBANCA, NRCONT, CODBANCATREZ, NRCONTTREZ, NoEconomicActiv, CODSIUI, codcasa, CodPers , CAPITAL_SOCIAL, 
    EFACT, TIPUNITJURIDICA )
  SELECT
    S.CODSUBUNIT, S.DEN_SUBUNIT, S.cif, S.SATELITWM, S.ANPORNIRE, S.LUNAPORNIRE, S.NUMEPRESC, S.REGCOM,
    S.CODBANKCONT, S.CODBANKCONTTREZ, S.CODCATPRET, NBK.CODBANK, NBK.NRCONT, NBKTREZ.CODBANK, NBKTREZ.NRCONT, Coalesce(S.NoEconomicActiv,0), S.CODSIUI, codcasa, CodPers , S.CAPITAL_SOCIAL,
    COALESCE(S.EFACT,0), COALESCE(S.TIPUNITJURIDICA,0)
  FROM NSUBUNIT S
    LEFT JOIN NBANKCONT NBK     ON S.CODBANKCONT     = NBK.CODBANKCONT
    LEFT JOIN NBANKCONT NBKTREZ ON S.CODBANKCONTTREZ = NBKTREZ.CODBANKCONT
  WHERE CODSUBUNIT = RECID;

  -- DETAIL NAGENDA
  INSERT INTO  TMP_NAGENDA (
    OBS,CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT, CODPART,CODGEST,CODSUBUNIT, GLN,
    ADRESA, LONGITUDINE, LATITUDINE, OBS2 )
  SELECT
    OBS,CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT,CODPART,CODGEST,CODSUBUNIT, GLN,
    GETADRESA(SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL), LONGITUDINE, LATITUDINE, OBS2
  FROM NAGENDA WHERE CODSUBUNIT = RECID;

  -- DETAIL NSUBUNIT1
  INSERT INTO  TMP_NSUBUNIT1 (CODSUBUNIT1,CODSUBUNIT,CODIOFILIAL, CODCATPRET, TVALAINCASARE, CAEN, IsFirma, Grdeclaratie, ModEditareJurnal, CodTVA, ANSTART,LUNASTART, 
                              PRELCANTBCAR)
  SELECT CODSUBUNIT1,CODSUBUNIT, CODIOFILIAL, CODCATPRET, NVL(TVALAINCASARE,0), CAEN, IsFirma, Grdeclaratie, Coalesce(ModEditareJurnal, 0), CodTVA, ANSTART,LUNASTART,
         COALESCE(PRELCANTBCAR,0)
  FROM NSUBUNIT1 WHERE CODSUBUNIT = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
  VRECNO INTEGER := 0;
  VAN    INTEGER := 0;
  VLUNA  INTEGER := 0;
  VCOD   NUMBER(20);

  AdOC VARCHAR2(150);
BEGIN
  IF OPERATION = 0 THEN  -- UPDATE

    -- MASTER NSUBUNIT
    SELECT  CODSUBUNIT INTO RECID FROM TMP_NSUBUNIT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT  &apos;subunitate &quot;&apos;||n.DEN_SUBUNIT||&apos;&quot;&apos; INTO aDoc
      FROM TMP_NSUBUNIT n where N.CODSUBUNIT = RECID;

      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSUBUNIT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NSUBUNIT
    SET (        DEN_SUBUNIT, CIF, SATELITWM, ANPORNIRE, LUNAPORNIRE, NUMEPRESC, REGCOM, CODBANKCONT, CODBANKCONTTREZ, CODCATPRET, NoEconomicActiv, CODSIUI, codcasa, CodPers , CAPITAL_SOCIAL, EFACT, TIPUNITJURIDICA ) =
        ( SELECT DEN_SUBUNIT, CIF, SATELITWM, ANPORNIRE, LUNAPORNIRE, NUMEPRESC, REGCOM, CODBANKCONT, CODBANKCONTTREZ, CODCATPRET, NoEconomicActiv, CODSIUI, codcasa, CodPers , CAPITAL_SOCIAL, EFACT, TIPUNITJURIDICA FROM TMP_NSUBUNIT )
    WHERE CODSUBUNIT = RECID;

    -- DETAIL NAGENDA
    DELETE FROM NAGENDA WHERE ( CODSUBUNIT = RECID AND CODAGENDA NOT IN ( SELECT CODAGENDA FROM TMP_NAGENDA WHERE NVL(CODAGENDA,0) &lt;&gt; 0));

    INSERT INTO NAGENDA ( OBS,CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT, CODPART,CODGEST,CODSUBUNIT, GLN, LONGITUDINE, LATITUDINE, OBS2 )
    SELECT OBS, SEQ_NAGENDA_CODAGENDA.NEXTVAL ,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT, CODPART,CODGEST,RECID, GLN, LONGITUDINE, LATITUDINE, OBS2
    FROM TMP_NAGENDA WHERE CODAGENDA &lt; 0;

    FOR V_REC IN ( SELECT * FROM TMP_NAGENDA WHERE NVL(CODAGENDA,-1) &gt; 0 ORDER BY CODAGENDA ) LOOP
      SELECT COUNT(*) INTO VRECNO FROM NAGENDA WHERE CODAGENDA = NVL(V_REC.CODAGENDA,0);
      IF(VRECNO=1) THEN
        UPDATE NAGENDA
        SET OBS = V_REC.OBS,
            TIP = V_REC.TIP,
            CODLOCALIT = V_REC.CODLOCALIT,
            SEDIUSOCIAL = V_REC.SEDIUSOCIAL,
            TELEFON = V_REC.TELEFON,
            FAX = V_REC.FAX,
            EMAIL = V_REC.EMAIL,
            SECTOR = V_REC.SECTOR,
            STRADA = V_REC.STRADA,
            NR1 = V_REC.NR1,
            NR2 = V_REC.NR2,
            BLOC = V_REC.BLOC,
            SCARA = V_REC.
            SCARA,ETAJ = V_REC.ETAJ,
            APART = V_REC.APART,
            CODPOSTAL = V_REC.CODPOSTAL,
            KM = V_REC.KM,
            CODBANKCONT = V_REC.CODBANKCONT,
            CODPART = V_REC.CODPART,
            CODGEST = V_REC.CODGEST,
            CODSUBUNIT = RECID,
            GLN = V_REC.GLN,
            LONGITUDINE = V_REC.LONGITUDINE,
            LATITUDINE = V_REC.LATITUDINE,
            OBS2 = V_REC.OBS2
        WHERE CODAGENDA = V_REC.CODAGENDA;
      END IF;
    END LOOP;

    -- DETAIL NSUBUNIT1
    DELETE FROM NSUBUNIT1 WHERE CODSUBUNIT = RECID AND CODSUBUNIT1 NOT IN (SELECT CODSUBUNIT1 FROM TMP_NSUBUNIT1);

    FOR V_REC IN ( SELECT * FROM TMP_NSUBUNIT1 ORDER BY CODSUBUNIT1 ) LOOP
      IF (V_REC.CODSUBUNIT1 &gt; 0) THEN
        UPDATE NSUBUNIT1
        SET CODIOFILIAL      = V_REC.CODIOFILIAL,
            CODCATPRET       = V_REC.CODCATPRET,
            TVALAINCASARE    = V_REC.TVALAINCASARE,
            CAEN             = V_REC.CAEN,
            CodTVA           = V_REC.CodTVA,
            IsFirma          = V_REC.IsFirma,
            GrDeclaratie     = V_REC.Grdeclaratie,
            ModEditareJurnal = V_REC.ModEditareJurnal,
            PrelCantBCAR     = V_REC.PrelCantBCAR
        WHERE CODSUBUNIT1 = V_REC.CODSUBUNIT1;
      ELSE
        INSERT INTO NSUBUNIT1 (
          CODSUBUNIT1, CODSUBUNIT, CODIOFILIAL, CODCATPRET, ANSTART, LUNASTART,
          TVALAINCASARE, CAEN, CODTVA, ISFIRMA, GRDECLARATIE, MODEDITAREJURNAL,
          PRELCANTBCAR)
        VALUES (
          SEQ_NSUBUNIT1_CODSUBUNIT1.NEXTVAL, RECID, V_REC.CODIOFILIAL, V_REC.CODCATPRET, V_REC.ANSTART, V_REC.LUNASTART,
          V_REC.TVALAINCASARE, V_REC.CAEN, V_REC.CODTVA, V_REC.ISFIRMA, V_REC.GRDECLARATIE, V_REC.MODEDITAREJURNAL,
          V_REC.PRELCANTBCAR);
      END IF;
    END LOOP;
  ELSE  -- INSERT
    -- MASTER NSUBUNIT
    SELECT SEQ_NSUBUNIT_CODSUBUNIT.NEXTVAL INTO RECID FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT  &apos;subunitate &quot;&apos;||n.DEN_SUBUNIT||&apos;&quot;&apos; INTO aDoc FROM TMP_NSUBUNIT n ;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSUBUNIT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO  NSUBUNIT ( 
      CODSUBUNIT,DEN_SUBUNIT, CIF, SATELITWM, ANPORNIRE, LUNAPORNIRE, NUMEPRESC, REGCOM, CODBANKCONT, CODBANKCONTTREZ, CODCATPRET, NoEconomicActiv, CODSIUI, codcasa, CodPers ,CAPITAL_SOCIAL, EFACT, TIPUNITJURIDICA )
    SELECT
      RECID,     DEN_SUBUNIT, CIF, SATELITWM, ANPORNIRE, LUNAPORNIRE, NUMEPRESC, REGCOM, CODBANKCONT, CODBANKCONTTREZ, CODCATPRET, NoEconomicActiv, CODSIUI, codcasa, CodPers , CAPITAL_SOCIAL, EFACT, TIPUNITJURIDICA
    FROM TMP_NSUBUNIT;
    -- DETAIL NAGENDA
    INSERT INTO  NAGENDA ( OBS,CODAGENDA,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT, CODPART,CODGEST,CODSUBUNIT, GLN, LONGITUDINE, LATITUDINE, OBS2)
    SELECT OBS, SEQ_NAGENDA_CODAGENDA.NEXTVAL ,TIP,CODLOCALIT,SEDIUSOCIAL,TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,KM,CODBANKCONT, CODPART,CODGEST,RECID, GLN, LONGITUDINE, LATITUDINE, OBS2
    FROM TMP_NAGENDA;
    -- DETAIL NSUBUNIT1
    INSERT INTO NSUBUNIT1 ( CODSUBUNIT1, CODSUBUNIT, CODIOFILIAL, CODCATPRET, CAEN, IsFirma, GrDeclaratie, CodTVA, ANSTART, LUNASTART, PRELCANTBCAR )
    SELECT  SEQ_NSUBUNIT1_CODSUBUNIT1.NEXTVAL, RECID, CODIOFILIAL, CODCATPRET, CAEN, IsFirma, GrDeclaratie, CodTVA, ANSTART, LUNASTART, PRELCANTBCAR
    FROM TMP_NSUBUNIT1;
  END IF;

  PRC_AL_REFRESH(&apos;NSUBUNIT1&apos;, RECID);
  NotifyModif(OPERATION, RECID, &apos;NSUBUNIT&apos;);

  FOR V_REC IN (
    SELECT A.CODARTICOL
    FROM NART A
    WHERE NOT EXISTS (SELECT CODARTICOL FROM NARTIMPLICITE WHERE CODARTICOL = A.CODARTICOL AND codsubunit = RECID)
  ) LOOP
    INSERT INTO NARTIMPLICITE(CODIMPLICIT, CODARTICOL, CODSUBUNIT) VALUES(SEQ_NARTIMPLICITE_CODIMPLICIT.NEXTVAL, V_REC.CODARTICOL, RECID);
  END LOOP;

  FOR V_REC IN (
    SELECT O.CODOBIECT
    FROM NARTOBJ O
    WHERE NOT EXISTS (SELECT CODOBIECT FROM NARTOBJIMP WHERE CODOBIECT = O.CODOBIECT AND codsubunit = RECID)
  ) LOOP
    INSERT INTO NARTOBJIMP(CODOBJIMP,CODOBIECT,CODSUBUNIT)
    VALUES (SEQ_NARTOBJIMP_CODOBJIMP.NEXTVAL,V_REC.CODOBIECT, RECID);
  END LOOP;

  COMMIT;
END;

END PKG_NOMSUBUNIT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMTAXE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30D83BAA83EA99573198AE27499478FE5AF76555</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMTAXE IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

FUNCTION GETCODCARACTLUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
aCODNTAXA1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODTAXA1 INTO aCODNTAXA1 FROM NTAXE1 T1
    WHERE CODTAXA = COD AND An*12+Luna BETWEEN T1.alstart AND T1.alstop;
  EXCEPTION WHEN OTHERS THEN aCODNTAXA1 := 0;
  END;
  RETURN aCODNTAXA1;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodTaxa INTO Tmp FROM NTAXE WHERE CodTaxa = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(100);
BEGIN

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;taxa &quot;&apos;||N.Den_Taxa||&apos;&quot;&apos; INTO aDoc
   FROM NTAXE n where N.CODTAXA = RECID;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTAXE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  SP_LOCKRECORD(RecId);
	DELETE FROM NTAXE1 WHERE CodTaxa = RecId ;
  DELETE FROM NTAXE  WHERE CodTaxa = RecId ;
  NotifyModif(2, RECID, &apos;NTAXE&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NTAXE FIELDS( CodTaxa ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT NUMBER(4);
aLUNASFARSIT NUMBER(2);

BEGIN
-- Master NTAXE
  INSERT INTO  TMP_NTAXE ( CodTaxa,Den_Taxa, Centralizat, TipPart )
    ( SELECT CodTaxa,Den_Taxa, Centralizat, coalesce(TipPart,0)
      FROM NTAXE WHERE CodTaxa = RecId ) ;

-- Detail NTAXE1
  INSERT INTO  TMP_NTAXE1 ( CodTaxa1,CodTaxa,Valoare,LaCeAplic,CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE, anstart,lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed )
    ( SELECT CodTaxa1,CodTaxa,Valoare, LaCeAplic,CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,Nvl(JVanz,1),CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ,ROTVALOARE,  anstart, lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed
      FROM NTAXE1 WHERE CodTaxa = RecId);



  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CodTaxa1,CodTaxa,Valoare,LaCeAplic,CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE, anstart,lunastart, SERVICIUMONETAR FROM TMP_NTAXE1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NTAXE1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODTAXA1 = V_REC.CODTAXA1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

  UPDATE TMP_NTAXE1 SET LUNASFARSIT = 0 WHERE  LUNASFARSIT IS NULL;


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);

  aDoc varchar2(100);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NTAXE
    SELECT  CodTaxa INTO RecId FROM TMP_NTAXE;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
       SELECT  &apos;taxa &quot;&apos;||N.Den_Taxa||&apos;&quot;&apos; INTO aDoc
       FROM tmp_NTAXE n where N.CODTAXA = RECID;

       WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTAXE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NTAXE SET ( Den_Taxa, Centralizat, TipPart )
       = ( SELECT Den_Taxa, Centralizat, TipPart
          FROM TMP_NTAXE )
      WHERE CodTaxa = RecId ;


-- Detail NTAXE1
    DELETE FROM NTAXE1 WHERE (CODTAXA = RECID )AND(CODTAXA1 NOT IN (SELECT CODTAXA1 FROM TMP_NTAXE1));

    INSERT INTO NTAXE1 ( CodTaxa1,CodTaxa,Valoare,LaCeAplic,CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE, anstart,lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed )
      SELECT  seq_NTAXE1_CodTaxa1.Nextval , RecId ,Valoare, NVL(LaCeAplic,0), CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE,  anstart,lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed
      FROM TMP_NTAXE1 WHERE CodTaxa1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NTAXE1 WHERE NVL(CodTaxa1,-1) &gt; 0 ORDER BY CodTaxa1 ) LOOP
       UPDATE NTAXE1 SET
          ProcDiminuareB = v_rec.ProcDiminuareB,
          Valoare = v_rec.Valoare,
          LaCeAplic = NVL(v_rec.LaCeAplic, 0) ,
          CodCont = v_rec.CodCont,
          CodContChelt = v_rec.CodContChelt,
          OricareTip = v_rec.OricareTip,
          CodIOArtExcl = v_rec.CodIOArtExcl,
          ExclusAccize = v_rec.ExclusAccize,
          ExclusExport = v_rec.ExclusExport,
          JAchiz = v_rec.JAchiz,
          JVanz = v_rec.JVanz,
          CumJAchiz = v_rec.CumJAchiz,
          CumJVanz = v_rec.CumJVanz,
          BazaMax = v_rec.BazaMax,
          BazaMin = v_rec.BazaMin,
          CodServFact = v_rec.CodServFact,
          Facturabil = v_rec.Facturabil,
          STOPAJ     = V_REC.STOPAJ,
          ROTVALOARE = V_REC.ROTVALOARE,
          ANSTART    = V_REC.ANSTART,
          LUNASTART  = V_REC.LUNASTART,
          SERVICIUMONETAR  = V_REC.SERVICIUMONETAR,
          BazaMed = V_REC.BazaMed
          WHERE
          CodTaxa1 = v_rec.CodTaxa1;
    END LOOP;
  ELSE  -- INSERT
-- Master NTAXE
    SELECT seq_NTAXE_CodTaxa.NextVal INTO RecId FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT  &apos;taxa &quot;&apos;||N.Den_Taxa||&apos;&quot;&apos; INTO aDoc
      FROM tmp_NTAXE n;

      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTAXE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO  NTAXE ( CodTaxa,Den_Taxa, Centralizat, TipPart )
    ( SELECT  RecId ,Den_Taxa, Centralizat, TipPart FROM TMP_NTAXE  ) ;

-- Detail NTAXE1
    INSERT INTO  NTAXE1 ( CodTaxa1,CodTaxa,Valoare,LaCeAplic,CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE, anstart,lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed )
     ( SELECT  seq_NTAXE1_CodTaxa1.Nextval ,RecId,Valoare, NVL(LaCeAplic, 0), CodCont,CodContChelt,OricareTip,CodIOArtExcl,ExclusAccize,ExclusExport,JAchiz,JVanz,CumJAchiz,CumJVanz,BazaMax,BazaMin,CodServFact,Facturabil, STOPAJ, ROTVALOARE, anstart,lunastart, ProcDiminuareB, SERVICIUMONETAR, BazaMed FROM TMP_NTAXE1 );

  END IF;

  UPDATE LUNA_RECORDS_FLAGS SET NTAXE_FLG = 0, NTAXE_FLG_CONTA = 0;

  PRC_AL_REFRESH(&apos;NTAXE1&apos;, RecId);

  NotifyModif(OPERATION, RECID, &apos;NTAXE&apos;);

  COMMIT;
END;



END pkg_NomTaxe;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOMTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6ABF7982A36858653C6CD26BADAC2A4E33E26AF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOMTVA IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_7&apos;;

FUNCTION GETCURSORTVAURILUNA(AN IN NUMBER, LUNA IN NUMBER) RETURN TVAURILUNA_CURSOR
IS
  TMPCURSOR TVAURILUNA_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT N.DEN_TVA, N1.*
    FROM NTVA N LEFT JOIN NTVA1 N1 ON N1.CODTVA = N.CODTVA
    WHERE Coalesce(N.CODTVA, 0) &lt;&gt; 0 AND An*12+Luna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT &apos;-1&apos; FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GETPROCTVALUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
PROC NUMBER(10, 2) := -1;
BEGIN
  BEGIN
    SELECT PROCENT INTO PROC FROM NTVA1 T1
    WHERE T1.CODTVA = COD AND An*12+Luna BETWEEN t1.alstart AND t1.alstop;
  EXCEPTION WHEN OTHERS THEN PROC := -1;
  END;
  RETURN PROC;
END;


FUNCTION GETCODCARACTLUNA(COD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER
IS
aCODTVA1 NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODTVA1 INTO aCODTVA1 FROM NTVA1 T1
    WHERE T1.CODTVA = COD AND An*12+Luna BETWEEN t1.alstart AND t1.alstop;
  EXCEPTION WHEN OTHERS THEN aCODTVA1 := 0;
  END;
  RETURN aCODTVA1;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodTva INTO Tmp FROM NTVA WHERE CodTva = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar(100);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT  &apos;tva &quot;&apos;||n.den_tva||&apos;&quot;&apos; INTO aDoc
    FROM NTVA n where N.CODTVA = RECID;

    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTVA&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM NTVA1 WHERE CodTva = RecId ;
  DELETE FROM NTVA WHERE CodTva = RecId ;

  NotifyModif(2, RECID, &apos;NTVA&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NTVA FIELDS( CodTva ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT   NUMBER(4);
aLUNASFARSIT NUMBER(2);
BEGIN
-- Master NTVA
  INSERT INTO  TMP_NTVA ( CodTva,Den_Tva )
    ( SELECT CodTva,Den_Tva
      FROM NTVA WHERE CodTva = RecId ) ;

-- Detail NTVA1
  INSERT INTO  TMP_NTVA1 ( CodTva1,CodTva,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart )
    ( SELECT CodTva1,CodTva,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart
      FROM NTVA1 WHERE CodTva = RecId);




  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODTVA1, ANSTART, LUNASTART FROM TMP_NTVA1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NTVA1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODTVA1 = V_REC.CODTVA1;
    END IF;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;


  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);

  aDoc varchar2(100);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NTVA
    SELECT  CodTva INTO RecId FROM TMP_NTVA;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;tva &quot;&apos;||n.den_tva||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NTVA n where N.CODTVA = RECID;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTVA&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

    UPDATE NTVA SET ( Den_Tva )
       = ( SELECT Den_Tva
          FROM TMP_NTVA )
      WHERE CodTva = RecId ;


-- Detail NTVA1


    DELETE FROM NTVA1 where CodTVA = RecId and CodTVA1 not in (Select CodTVA1 from TMP_NTVA1);


    INSERT INTO NTVA1 ( CodTva1,CodTva,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart )
      SELECT  seq_NTVA1_CodTva1.Nextval , RecId ,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart
      FROM TMP_NTVA1 WHERE CodTva1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NTVA1 WHERE NVL(CodTva1,-1) &gt; 0 ORDER BY CodTva1 ) LOOP
      SELECT  Decode(Procent,v_rec.Procent,0,1) + Decode(CodContDed,v_rec.CodContDed,0,1) + Decode(CodContCole,v_rec.CodContCole,0,1) + Decode(CodContNeex,v_rec.CodContNeex,0,1) ,anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM NTVA1 WHERE CodTva1 = NVL(v_rec.CodTva1,0);
       IF (vRecNo &gt; 0) THEN
         IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE NTVA1 SET Procent = v_rec.Procent,CodContDed = v_rec.CodContDed,CodContCole = v_rec.CodContCole,CodContNeex = v_rec.CodContNeex WHERE CodTva1 = v_rec.CodTva1;
        ELSE
          INSERT INTO NTVA1 ( CodTva1,CodTva,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart ) VALUES ( Seq_NTVA1_CodTva1.NextVal,RecId,v_rec.Procent,v_rec.CodContDed,v_rec.CodContCole,v_rec.CodContNeex,v_rec.anstart,v_rec.lunastart );
        END IF;
      END IF;
    END LOOP;
  ELSE  -- INSERT
-- Master NTVA
  SELECT seq_NTVA_CodTva.NextVal INTO RecId FROM DUAL;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT  &apos;tva &quot;&apos;||n.den_tva||&apos;&quot;&apos; INTO aDoc
   FROM TMP_NTVA n ;

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NTVA&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                     pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
END IF;

  INSERT INTO  NTVA ( CodTva,Den_Tva )
 ( SELECT  RecId ,Den_Tva
     FROM TMP_NTVA  ) ;
-- Detail NTVA1
  INSERT INTO NTVA1 ( CodTva1,CodTva,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart )
     ( SELECT  seq_NTVA1_CodTva1.Nextval ,RecId,Procent,CodContDed,CodContCole,CodContNeex,anstart,lunastart FROM TMP_NTVA1 );

END IF;

  UPDATE LUNA_RECORDS_FLAGS SET NTVA_FLG = 0, NTVA_FLG_CONTA=0;
  PRC_AL_REFRESH(&apos;NTVA1&apos;, RecId);
  NotifyModif(OPERATION, RECID, &apos;NTVA&apos;);

  COMMIT;
END;



END pkg_NomTva;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOM_ARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F71D95E548093B1BD767918B634AD1CD6C25285A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOM_ARTICOL IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_6&apos;;
gCodObiect number(20) := 0;

procedure UmpleTmpStoc is
begin
  delete tmp_nartobjsubunit;
  delete tmp_nartobjsubunit_sec;
  insert into tmp_nartobjsubunit_sec(subunitate, densubunit)
  select codsubunit, den_subunit from nsubunit where codsubunit &gt; 1;
  insert into tmp_nartobjsubunit(subunitate, densubunit, codgest, den_gest)
  select s.codsubunit, s.den_subunit, g.codgest, g.den_gest
  from nsubunit s
       inner join ngest g on g.codsubunit = s.codsubunit
  where s.codsubunit &gt; 1;
  commit;
end;

procedure UpdateStocuri is
begin
  for v_obj in (select to_number(valoare) codobiect from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos;) LOOP
    for v_gest in (select * from tmp_nartobjsubunit where codgest &gt; 0) loop
      if v_gest.stocmin is not null then
        MERGE INTO nartobjsubunit s
        USING (
               SELECT v_obj.codobiect codobiect, v_gest.codgest codgest, v_gest.subunitate subunitate, v_gest.stocmin stocmin
               FROM dual
              ) t
        ON (t.CODOBIECT = s.CODOBIECT and s.CODGEST = t.CODGEST AND s.subunitate = t.subunitate)
        WHEN NOT MATCHED THEN INSERT (cods,codobiect, subunitate, codgest, stocmin)
                                      VALUES
                                     (seq_nartobjsubunit_cods.nextval, t.codobiect, t.subunitate, t.codgest, t.stocmin)
        WHEN MATCHED THEN UPDATE SET s.stocmin = t.stocmin;
        update nartobjsubunit set stocmin = (select sum(coalesce(stocmin,0)) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) &gt; 0 and subunitate = v_gest.subunitate)
        where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0 and subunitate = v_gest.subunitate;
        update nartobj set stocmin = (select sum(stocmin) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0)
        where codobiect = v_obj.codobiect;
      end if;
      if v_gest.stocmax is not null then
        MERGE INTO nartobjsubunit s
        USING (
               SELECT v_obj.codobiect codobiect, v_gest.codgest codgest, v_gest.subunitate subunitate, v_gest.stocmax stocmax
               FROM dual
              ) t
        ON (t.CODOBIECT = s.CODOBIECT and s.CODGEST = t.CODGEST AND s.subunitate = t.subunitate)
        WHEN NOT MATCHED THEN INSERT (cods, codobiect, subunitate, codgest, stocmax)
                                      VALUES
                                     (seq_nartobjsubunit_cods.nextval, t.codobiect, t.subunitate, t.codgest, t.stocmax)
        WHEN MATCHED THEN UPDATE SET s.stocmax = t.stocmax;
        update nartobjsubunit set stocmax = (select sum(coalesce(stocmax,0)) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) &gt; 0 and subunitate = v_gest.subunitate)
        where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0 and subunitate = v_gest.subunitate;
        update nartobj set stocmax = (select sum(stocmax) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0)
        where codobiect = v_obj.codobiect;
      end if;
      if v_gest.stocmed is not null then
        MERGE INTO nartobjsubunit s
        USING (
               SELECT v_obj.codobiect codobiect, v_gest.codgest codgest, v_gest.subunitate subunitate, v_gest.stocmed stocmed
               FROM dual
              ) t
        ON (t.CODOBIECT = s.CODOBIECT and s.CODGEST = t.CODGEST AND s.subunitate = t.subunitate)
        WHEN NOT MATCHED THEN INSERT (cods, codobiect, subunitate, codgest, stocmed)
                                      VALUES
                                     (seq_nartobjsubunit_cods.nextval, t.codobiect, t.subunitate, t.codgest, t.stocmed)
        WHEN MATCHED THEN UPDATE SET s.stocmed = t.stocmed;
        update nartobjsubunit set stocmed = (select sum(coalesce(stocmed,0)) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) &gt; 0 and subunitate = v_gest.subunitate)
        where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0 and subunitate = v_gest.subunitate;
        update nartobj set stocmed = (select sum(stocmed) from nartobjsubunit where codobiect = v_obj.codobiect and coalesce(codgest,0) = 0)
        where codobiect = v_obj.codobiect;
      end if;
    end loop;
  end loop;
  commit;
end;

procedure test2
is
begin
  pkg_globals.SETUSERID(1); commit;
  pkg_globals.SETSUBUNITATE(2); commit;
  pkg_globals.setlunalucru(2020, 8);
  pkg_stoc_generare_facturi.make_config_luna;

  sp_gotorecord(1715);
end;

procedure UPDATE_CONTSERV IS
begin
  for v_rec in (
    select i1.codintr1, tmp.codplu, i.codintr coddoc, i.tipdoc
    from tmp_nartobj tmp
         inner join nartobj o on o.codarticol = tmp.codarticol
         inner join intrari1 i1 on i1.codobiect = o.codobiect
         inner join intrari i on i.codintr = i1.codintr
    where i.operat = 1 and i.anulat = 0 and i.an*12+i.luna = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU
    ) loop
    update intrari1 set contserv = v_rec.codplu where codintr1 = v_rec.codintr1;
    update jurnal1 set dirty = 1 where coddoc = v_rec.coddoc and tipdoc = v_rec.tipdoc;
    commit;
  end loop;
  for v_rec in (
    select i1.codies1, tmp.codplu, i.codies coddoc, i.tipdoc
    from tmp_nartobj tmp
         inner join nartobj o on o.codarticol = tmp.codarticol
         inner join iesiri1 i1 on i1.codobiect = o.codobiect
         inner join iesiri i on i.codies = i1.codies
    where i.operat = 1 and i.anulat = 0 and i.an*12+i.luna = pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU
    ) loop
    update iesiri1 set contserv = v_rec.codplu where codies1 = v_rec.codies1;
    update jurnal1 set dirty = 1 where coddoc = v_rec.coddoc and tipdoc = v_rec.tipdoc;
    commit;
  end loop;
end;

PROCEDURE UPDATE_NARTOBJGEST(aZi in number, aCodGest in number, aCodObiect in number, aStoc in number) is
aCount number(5);
sSQL varchar2(1000);
begin
  select count(*) into aCount from nartobjgest where codgest = acodgest and codobiect = acodobiect;
  if aCount = 0 then
    insert into nartobjgest (codobiect, codgest)
    values (acodobiect, acodgest);
  end if;

  sSQL := &apos;update nartobjgest set D&apos;||aZi||&apos; = &apos;||aStoc||&apos; where codgest = &apos;||aCodGest||&apos; and codobiect = &apos;||acodobiect;
  execute immediate sSQL;
  commit;
end;

procedure UpdateImpSubunit is
begin
  FOR v_rec in (select codsubunit from nsubunit where codsubunit &gt; 1) loop
    for v_xxx in (select nvl(imp.codsubunit,0) codsubunit, obj.codarticol
                  from nartobj obj
                       left join nartimplicite imp on obj.codarticol = imp.codarticol and imp.codsubunit = v_rec.codsubunit
                  WHERE obj.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos;)
                  ) loop
      if v_xxx.codsubunit = 0 then
        insert into nartimplicite (codimplicit, codarticol, codsubunit)
        values (seq_nartimplicite_codimplicit.nextval, v_xxx.codarticol, v_rec.codsubunit);
      end if;
    end loop;
  END LOOP;

  COMMIT;
end;

procedure UpdateObjImpSubunit is
begin
  FOR v_rec in (select codsubunit from nsubunit where codsubunit &gt; 1) loop
    for v_xxx in (select nvl(imp.codsubunit,0) codsubunit, obj.codobiect
                  from nartobj obj
                       left join nartobjimp imp on obj.codobiect = imp.codobiect and imp.codsubunit = v_rec.codsubunit
                  WHERE obj.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos;)
                  ) loop
      if v_xxx.codsubunit = 0 then
        insert into nartobjimp (codobjimp, codobiect, codsubunit)
        values (seq_nartobjimp_codobjimp.nextval, v_xxx.codobiect, v_rec.codsubunit);
      end if;
    end loop;
  END LOOP;

  COMMIT;
end;

procedure UpdateNArt1Integer(Camp in varchar, valoare in number) is
  sString VARCHAR2(1000);
  vRecId  NUMBER;
BEGIN
  sString := &apos;UPDATE Nart1 SET &apos;||Camp||&apos; = &apos;||valoare||&apos; WHERE codarticol1 = :vRecId&apos;;
  FOR v_rec in (
    SELECT distinct a1.codarticol1, a1.codarticol, a1.codtva, a1.codaccize, a1.TaxCode, a1.codtaxa1, a1.codtaxa2, a1.CodAccizeDVI, a1.anstart, a1.lunastart
    FROM NARTOBJ O INNER JOIN NART1 A1 ON A1.CODARTICOL = O.CODARTICOL
    WHERE O.CODOBIECT IN (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODOBIECT&apos;)
      AND pkg_globals.getanlucru*12+pkg_globals.anlunalucru BETWEEN a1.alstart AND a1.alstop
  ) LOOP
    if v_rec.CodArticol1 &gt; 0 then
      IF v_rec.anstart*12+v_rec.lunastart &lt;&gt; pkg_globals.GetANLUCRU*12+pkg_globals.GetlunaLUCRU THEN
        vRecId := seq_nart1_codarticol1.NEXTVAL;
        INSERT INTO nart1 (codarticol1, codarticol, codtva, codaccize, TaxCode, codtaxa1, codtaxa2, anstart, lunastart, CodAccizeDVI)
        VALUES (vRecID, v_Rec.codarticol, v_Rec.codtva, v_Rec.codaccize, v_Rec.TaxCode, v_Rec.codtaxa1, v_Rec.codtaxa2, pkg_globals.getanlucru, pkg_globals.getlunalucru, v_Rec.CodAccizeDVI);
      ELSE
        vRecId := v_rec.CodArticol1;
      END IF;
    end if;
    EXECUTE IMMEDIATE sString USING vRecID;
    
    PRC_AL_REFRESH(&apos;NART1&apos;, v_Rec.codarticol);
  END LOOP;
  COMMIT;
end;

FUNCTION GetStrNARTOBJEXT(DeLa IN NUMBER) RETURN VARCHAR2
IS
  STRUCT VARCHAR2(2000) := &apos;&apos;;
  NR     NUMBER(10)     := 0;
  I      NUMBER(10)     := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM USER_TAB_COLS WHERE TABLE_NAME = &apos;NARTOBJEXT&apos; AND COLUMN_ID IS NOT NULL;

  IF NR &gt; 0 THEN
    FOR V_REC IN (SELECT COLUMN_NAME FROM USER_TAB_COLS WHERE TABLE_NAME = &apos;NARTOBJEXT&apos; AND COLUMN_ID IS NOT NULL ORDER BY COLUMN_ID)
    LOOP
      I := I + 1;
      IF I &gt;= DeLa THEN
        STRUCT := STRUCT || V_REC.COLUMN_NAME;
        IF I &lt; NR THEN STRUCT := STRUCT || &apos;,&apos;; END IF;
      END IF;
    END LOOP;
  END IF;
  RETURN STRUCT;
END;

PROCEDURE  CloneazaNArtObjEXT(CODOBIECTGENERIC IN NUMBER, CODART IN NUMBER)
IS
 S VARCHAR2(2000);
BEGIN
  S := &apos;BEGIN &apos; ||
       &apos;FOR V_REC IN &apos; ||
       &apos;   (SELECT CODOBIECT &apos; ||
       &apos;    FROM &apos; ||
       &apos;      NARTOBJ O &apos; ||
       &apos;  WHERE &apos; ||
       &apos;    CODOBIECT &lt;&gt; &apos; || TO_CHAR(CODOBIECTGENERIC) ||
       &apos;    AND CODARTICOL = &apos; || TO_CHAR(CODART) ||
       &apos;    AND (SELECT COUNT(*) FROM NARTOBJEXT OE WHERE OE.CODOBIECT = O.CODOBIECT) = 0 &apos; ||
       &apos;  )  &apos; ||
       &apos;  LOOP &apos; ||
       &apos;    INSERT INTO NARTOBJEXT (&apos; || GetStrNARTOBJEXT(1) || &apos;) &apos; ||
       &apos;    SELECT SEQ_NARTOBJEXT_CODNARTOBJEXT.NEXTVAL, V_REC.CODOBIECT, &apos; || GetStrNARTOBJEXT(3) ||
                 &apos; FROM NARTOBJEXT WHERE CODOBIECT = &apos; || TO_CHAR(CODOBIECTGENERIC) || &apos;; &apos; ||
       &apos;  END LOOP;&apos; ||
       &apos;END;&apos;;
  BEGIN
    EXECUTE IMMEDIATE S;
    EXCEPTION WHEN OTHERS THEN NULL;
  END;
END ;

function getcodobiectgeneric(aCodArticol in number) return number is
aCodgeneric number(20);
begin
  aCodGeneric := 0;
  begin
    SELECT  O.CODOBIECT INTO aCodGeneric
    FROM NARTOBJ O
    WHERE O.CODARTICOL = aCodArticol AND
    NOT EXISTS (SELECT A.CODOBIECT FROM NATROBJ A WHERE A.CODOBIECT = O.CODOBIECT);
  exception when others then
    aCodGeneric := 0;
  end;
  return aCodGeneric;
end;

PROCEDURE TEST(Operation IN NUMBER)
IS
 aRECID NUMBER(20);
BEGIN
  aRECID := 667;
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(2012, 8);
  PKG_STOC_GENERARE_FACTURI.make_config_luna;

  PKG_NOM_ARTICOL.SP_GOTORECORD(aRecID);
  PKG_NOM_ARTICOL.SP_POSTRECORDS(Operation, aRecId);

END;

procedure UpdateNArtObj1Double(Camp in varchar, valoare in number) is
begin
  UpdateNArtObj1String(Camp, replace(to_char(valoare), &apos;,&apos;, &apos;.&apos;));
end;

procedure UpdateNArtObj1Integer(Camp in varchar, valoare in number) is
begin
  UpdateNArtObj1String(Camp, to_char(valoare));
end;

procedure UpdateNArtObj1String(Camp in varchar, valoare in varchar2) is
sString varchar2(1000);
begin
  for v_rec in (
    select obj1.*
    from nartobj1 obj1 inner join TMP_MANEVRA_LISTE tmp ON VALOARE = obj1.CODOBIECT AND FILTRU = &apos;CODOBIECT&apos;
    WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
      AND pkg_globals.getanlucru   &lt;&gt; anstart
      AND pkg_globals.GetlunaLUCRU &lt;&gt; lunastart
  ) loop
    insert into nartobj1 (
      codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla,
      anstart, lunastart, tippretmax, compensat, tipcompensare,
      grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit,
      hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi,
      punctesectie, proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate,
      sistave, refractie, indice_w, toxina_don, boabe_toxice, pretprod )
    values (
      seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla,
      pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare,
      v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit,
      v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi,
      v_Rec.punctesectie, v_Rec.proteina, v_Rec.aflatoxina, v_Rec.atac_plosnita, v_Rec.continut_ulei, v_Rec.aciditate,
      v_Rec.sistave, v_Rec.refractie, v_Rec.indice_w, v_Rec.toxina_don, v_Rec.boabe_toxice, v_rec.pretprod
    );
    prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
    commit;
  end loop;

  for v_rec in (
    select obj1.codobiect1
    from nartobj1 obj1 inner join TMP_MANEVRA_LISTE ON VALOARE = obj1.CODOBIECT AND FILTRU = &apos;CODOBIECT&apos;
    WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
    order by obj1.codobiect
  ) loop
    sString := &apos;update nartobj1 set &apos;||Camp||&apos; = &apos;||valoare||&apos; where codobiect1 = &apos;||v_Rec.codobiect1;
    execute immediate sString;
  end loop;
  commit;
end;

FUNCTION SET_CODOBIECT_ANALIZAT(aCodObiect in number) RETURN VARCHAR2 is
sResult VARCHAR2 (200);
BEGIN
  gCodObiect := aCodObiect;
  begin
   select denumire into sResult from nartobj where codobiect = aCodObiect;
  exception when others then sResult := &apos;???&apos;;
  end;
 RETURN sResult;
END;

FUNCTION  GET_CODOBIECT_ANALIZAT RETURN NUMBER is
BEGIN
 RETURN gCodObiect;
END;

FUNCTION  ANALIZA_IMPLICIT(IMPLICITSURSA       IN NUMBER,
                           DoarCategSursa      IN NUMBER,
                           CODCATSURSA         IN NUMBER,
                           CODCATDESTIMPLICITA IN NUMBER
                           ) RETURN NUMBER
IS
BEGIN
  IF DoarCategSursa = 0 THEN RETURN IMPLICITSURSA;
  ELSE
    IF CODCATDESTIMPLICITA = 0 THEN RETURN IMPLICITSURSA;
    ELSE
      IF CODCATSURSA = CODCATDESTIMPLICITA THEN RETURN 1; ELSE RETURN 0; END IF;
    END IF;
  END IF;
END;

PROCEDURE MULTIPLICA_PRETURI(aCODOBIECT IN NUMBER,ACODSUBUNIT IN NUMBER, SUPRASCRIU_PRET_ZERO IN NUMBER, DoarCategSursa IN NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  PRET_PROPUS NUMBER(20, 7) := 0;
  CATIMPLICITDEST NUMBER(20);
  aSyncPretRetail VARCHAR2(10);
  aMemoModiPret   VARCHAR2(10);
BEGIN
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPretRetail FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aSyncPretRetail := &apos;0&apos;;
  END;

  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aMemoModiPret FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aMemoModiPret := &apos;0&apos;;
  END;


  IF SUPRASCRIU_PRET_ZERO = 1 THEN
    FOR V_REC IN (SELECT CODSUBUNIT FROM NSUBUNIT WHERE (CODSUBUNIT &lt;&gt; ACODSUBUNIT) AND CODSUBUNIT NOT IN (0,1) AND CODSUBUNIT IN (SELECT CODUNIC FROM TMP_MANEVRA)) LOOP

      BEGIN
        SELECT NVL(CODCATPRET, 0) INTO CATIMPLICITDEST FROM PRETM WHERE SUBUNITATEA = V_REC.CODSUBUNIT AND CODOBIECT = aCODOBIECT AND NVL(IMPLICIT, 0) = 1;
        EXCEPTION WHEN OTHERS THEN CATIMPLICITDEST := 0;
      END;


      IF NVL(DoarCategSursa, 0) = 0 THEN

        DELETE FROM PRETMAMB PAMB WHERE EXISTS
          (SELECT P.CODPRETM FROM PRETM P WHERE P.CODPRETM = PAMB.CODPRETM AND P.SUBUNITATEA = V_REC.CODSUBUNIT AND P.CODOBIECT = ACODOBIECT);


        DELETE FROM PRETM WHERE SUBUNITATEA = V_REC.CODSUBUNIT AND CODOBIECT = ACODOBIECT;
      END IF;

      FOR V_REC1 IN ( SELECT * FROM PRETM WHERE CODOBIECT = ACODOBIECT AND SUBUNITATEA = ACODSUBUNIT) LOOP

      IF NVL(DoarCategSursa, 0) = 1 THEN

          FOR V_REC_PRETM IN  (SELECT * FROM PRETM WHERE SUBUNITATEA = V_REC.CODSUBUNIT AND CODOBIECT = ACODOBIECT AND CODCATPRET = V_REC1.CODCATPRET)
          LOOP
            DELETE FROM PRETMAMB  WHERE CODPRETM = V_REC_PRETM.CODPRETM;


            DELETE FROM PRETM WHERE CODPRETM = V_REC_PRETM.CODPRETM;
          END LOOP;
      END IF;


        INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA) VALUES
            (SEQ_PRETM_CODPRETM.NEXTVAL,ACODOBIECT,V_REC1.CODCATPRET,V_REC1.LEI,V_REC1.VALUTA,V_REC1.MONEDA,
            ANALIZA_IMPLICIT(NVL(V_REC1.IMPLICIT, 0),
                              NVL(DoarCategSursa, 0),
                              NVL(V_REC1.CODCATPRET, 0),
                              NVL(CATIMPLICITDEST, 0)
                              ),
                              V_REC1.PROC,V_REC1.INDEXLOCAL,
            V_REC.CODSUBUNIT);

        INSERT INTO PRETMAMB(CODPRETMAMB,CODPRETM,CODAMB,LEI,VALUTA)
        SELECT SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL,SEQ_PRETM_CODPRETM.CURRVAL,CODAMB,LEI,VALUTA FROM
        PRETMAMB PAMB WHERE PAMB.CODPRETM = V_REC1.CODPRETM;


      END LOOP;

      IF aSyncPretRetail = &apos;1&apos; THEN
        PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(aCODOBIECT, V_REC.CODSUBUNIT);
      END IF;

      IF aMemoModiPret = &apos;1&apos; THEN
        PKG_GLOBALS.MEMO_MODIFICARE_PRET(aCODOBIECT, V_REC.CODSUBUNIT);
      END IF;



    END LOOP;
  ELSE -- preturile ZERO NU SE SUPRASCRIU
    FOR V_REC IN (SELECT CODSUBUNIT FROM NSUBUNIT WHERE (CODSUBUNIT &lt;&gt; ACODSUBUNIT) AND CODSUBUNIT NOT IN (0,1) AND CODSUBUNIT IN (SELECT CODUNIC FROM TMP_MANEVRA)) LOOP
      FOR V_REC1 IN (SELECT * FROM PRETM WHERE SUBUNITATEA = V_REC.CODSUBUNIT AND CODOBIECT = aCODOBIECT)
      LOOP

          BEGIN
            SELECT NVL(CODCATPRET, 0) INTO CATIMPLICITDEST FROM PRETM WHERE SUBUNITATEA = V_REC.CODSUBUNIT AND CODOBIECT = aCODOBIECT AND NVL(IMPLICIT, 0) = 1;
            EXCEPTION WHEN OTHERS THEN CATIMPLICITDEST := 0;
          END;


        PRET_PROPUS := -1;
        IF NVL(V_REC1.MONEDA, 0) = 0 THEN
          BEGIN
            SELECT LEI INTO PRET_PROPUS FROM PRETM WHERE SUBUNITATEA = aCODSUBUNIT AND CODOBIECT = ACODOBIECT AND CODCATPRET = V_REC1.CODCATPRET;
            EXCEPTION WHEN OTHERS THEN PRET_PROPUS := -1;
          END;
        ELSE
          BEGIN
            SELECT VALUTA INTO PRET_PROPUS FROM PRETM WHERE SUBUNITATEA = aCODSUBUNIT AND CODOBIECT = ACODOBIECT AND CODCATPRET = V_REC1.CODCATPRET;
            EXCEPTION WHEN OTHERS THEN PRET_PROPUS := -1;
          END;
        END IF;
        IF PRET_PROPUS &lt;&gt; 0 THEN
          DELETE FROM PRETM    WHERE CODPRETM = V_REC1.CODPRETM;
          DELETE FROM PRETMAMB WHERE CODPRETM = V_REC1.CODPRETM;
        END IF;
      END LOOP;

      FOR V_REC1 IN ( SELECT * FROM PRETM WHERE CODOBIECT = ACODOBIECT AND SUBUNITATEA = ACODSUBUNIT ) LOOP

        IF NVL(V_REC1.MONEDA, 0) = 0 THEN PRET_PROPUS := NVL(V_REC1.LEI, 0);
                                    ELSE PRET_PROPUS := NVL(V_REC1.VALUTA, 0);
        END IF;

        IF PRET_PROPUS &lt;&gt; 0 THEN
          INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA) VALUES
              (SEQ_PRETM_CODPRETM.NEXTVAL,ACODOBIECT,V_REC1.CODCATPRET,V_REC1.LEI,V_REC1.VALUTA,V_REC1.MONEDA,
            ANALIZA_IMPLICIT(NVL(V_REC1.IMPLICIT, 0),
                              NVL(DoarCategSursa, 0),
                              NVL(V_REC1.CODCATPRET, 0),
                              NVL(CATIMPLICITDEST, 0)
                              ),

              V_REC1.PROC,V_REC1.INDEXLOCAL,
              V_REC.CODSUBUNIT);

          INSERT INTO PRETMAMB(CODPRETMAMB,CODPRETM,CODAMB,LEI,VALUTA)
          SELECT SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL,SEQ_PRETM_CODPRETM.CURRVAL,CODAMB,LEI,VALUTA FROM
          PRETMAMB PAMB WHERE PAMB.CODPRETM = V_REC1.CODPRETM;
        END IF;
      END LOOP;

      IF aSyncPretRetail = &apos;1&apos; THEN
        PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(aCODOBIECT, V_REC.CODSUBUNIT);
      END IF;

      IF aMemoModiPret = &apos;1&apos; THEN
        PKG_GLOBALS.MEMO_MODIFICARE_PRET(aCODOBIECT, V_REC.CODSUBUNIT);
      END IF;


    END LOOP;
  END IF;
  COMMIT;
END;

FUNCTION COD_EXTERN_UNIC(aCODOBIECT IN NUMBER, aCODEXTERN IN VARCHAR2, aCODUMP IN NUMBER) RETURN NUMBER
IS
  NR NUMBER(10 ) := 0;
BEGIN
  --SELECT COUNT(*) INTO NR FROM NARTOBJ WHERE CODEXTERN = aCODEXTERN AND CODOBIECT &lt;&gt; aCODOBIECT;
  SELECT SUM(NR) INTO NR FROM
  (
    SELECT COUNT(*) AS NR FROM NARTOBJ
    WHERE CODEXTERN = aCODEXTERN AND CODOBIECT &lt;&gt; aCODOBIECT
    UNION ALL
    SELECT COUNT(*) AS NR FROM CODEXTALT
    WHERE CODEXTERN = aCODEXTERN AND CODOBIECT &lt;&gt; aCODOBIECT
  );


 IF nvl(PKG_CATEGCONST.GetValConstanta(&apos;CodExternUnicAmb&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), &apos;0&apos;) &lt;&gt; &apos;3&apos; THEN

  IF NR = 0 THEN
    SELECT COUNT(*) INTO NR
    FROM
      NARTAMB AMB
    WHERE
     (
      (CODOBIECT = aCODOBIECT AND UMSEC &lt;&gt; aCODUMP)OR
      (CODOBIECT &lt;&gt; aCODOBIECT)
     )
     AND AMB.CODEXTERN IS NOT NULL
     AND AMB.CODEXTERN = aCODEXTERN;

    IF NR = 0 THEN RETURN 1; ELSE RETURN 0; END IF;
  ELSE RETURN 0;
  END IF;

 ELSE
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0; END IF;
 END IF;


END;

FUNCTION COD_EXTERN_UNIC_AMB(aCODAMB IN NUMBER, aCODOBIECT IN NUMBER, aCODUMSEC IN NUMBER, aCODEXTERN IN VARCHAR2) RETURN NUMBER
IS
  NR NUMBER(10 ) := 0;
BEGIN
   SELECT COUNT(*) INTO NR
   FROM
     NARTAMB
   WHERE
     CODEXTERN IS NOT NULL
     AND CODAMB &lt;&gt; aCODAMB
     AND UPPER(CODEXTERN) = UPPER(aCODEXTERN);


   IF nvl(PKG_CATEGCONST.GetValConstanta(&apos;CodExternUnicAmb&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), &apos;0&apos;) = &apos;3&apos; THEN
     IF NR = 0 THEN RETURN 1; ELSE RETURN 0; END IF;
   END IF;


   IF NR = 0 THEN
     SELECT SUM(NR) INTO NR FROM
     (
       SELECT COUNT(*) AS NR
       FROM
         NARTOBJ O
         INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
       WHERE
         O.CODEXTERN = aCODEXTERN
       AND
       (
         (CODOBIECT &lt;&gt; aCODOBIECT) OR
         (CODOBIECT = aCODOBIECT AND A.UM &lt;&gt; aCODUMSEC)
       )
      UNION ALL
      SELECT COUNT(*) AS NR FROM CODEXTALT
      WHERE CODEXTERN = aCODEXTERN AND CODOBIECT &lt;&gt; aCODOBIECT
    );

     IF NR = 0 THEN RETURN 1; ELSE RETURN 0; END IF;
   ELSE
     RETURN 0;
   END IF;



END;


FUNCTION COD_PLU_UNIC(aCODOBIECT IN NUMBER, aCODPLU IN NUMBER) RETURN NUMBER
IS
NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NARTOBJ WHERE CODPLU = aCODPLU AND CODOBIECT &lt;&gt; aCODOBIECT;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;


FUNCTION COD_INTERN_UNIC(aCODOBIECT IN NUMBER, aCODINTERN IN VARCHAR2) RETURN NUMBER
IS
NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NARTOBJ WHERE CODINTERN = aCODINTERN AND CODOBIECT &lt;&gt; aCODOBIECT;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;

FUNCTION DENUMIRE_UNICA_OBIECT(aCODOBIECT IN NUMBER, aDENUMIRE IN VARCHAR2) RETURN NUMBER
IS
NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NARTOBJ WHERE DENUMIRE = aDENUMIRE AND CODOBIECT &lt;&gt; aCODOBIECT;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;

FUNCTION DENUMIRE_UNICA_ARTICOL(aCODARTICOL IN NUMBER, aDENUMIRE IN VARCHAR2) RETURN NUMBER
IS
NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NART WHERE DEN_ARTICOL = aDENUMIRE AND CODARTICOL &lt;&gt; aCODARTICOL;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;

PROCEDURE ACTUALIZEAZA_NARTCLI( aCodObiect    IN NUMBER,
                                aCodPart      IN NUMBER,
                                aCodClaseP    IN NUMBER,
                                aDenumire     IN VARCHAR2,
                                aCodExtern    IN VARCHAR2,
                                aCodLaClient  IN VARCHAR2,
                                aUMSec        IN NUMBER,
                                aTipCodAfisat IN NUMBER DEFAULT 1,
                                aForceUpd     IN NUMBER DEFAULT NULL)
IS
  vCodArtCli  NUMBER;
  vCodPart    NUMBER;
  vForceUpd   NUMBER;
BEGIN
  vCodPart := CASE WHEN aCodClaseP = 0 THEN aCodPart ELSE 0 END;
  IF aForceUpd IS NULL THEN
    vForceUpd := Coalesce(To_Number(PKG_CATEGCONST.GetValConstanta(&apos;DetArtPartFromDoc&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU)), 1);
  ELSE
    vForceUpd := aForceUpd;
  END IF;

  IF  aCodObiect IS NOT NULL
  AND (Coalesce(vCodPart,0) &gt; 0 OR Coalesce(aCodClaseP, 0) &gt; 0)
  AND (aDenumire IS NOT NULL OR aCodExtern IS NOT NULL OR aCodLaClient IS NOT NULL )
  THEN
    SELECT Coalesce(Max(CODARTCLI), 0) INTO vCodArtCli
    FROM NArtCli
    WHERE CodObiect = aCodObiect
      AND CASE WHEN aCodClaseP = 0 THEN CodPart ELSE 0 END   = vCodPart
      AND CASE WHEN aCodClaseP = 0 THEN 0 ELSE CodClasep END = aCodClasep;

    IF vCodArtCli = 0 THEN
      vCodArtCli := SEQ_NARTCLI_CODARTCLI.NextVal;
      INSERT INTO NARTCLI ( CodArtCli,  CodObiect,  CodPart,  CodClaseP,  Denumire,  CodExtern,  CodLaClient,  UMSec,  TipCodAfisat)
      VALUES              ( vCodArtCli, aCodObiect, vCodPart, aCodClaseP, aDenumire, aCodExtern, aCodLaClient, aUMSec, Coalesce(aTipCodAfisat,1)) ;
    ELSE
      UPDATE NARTCLI
      SET Denumire    = CASE WHEN vForceUpd = 1 THEN Coalesce(aDenumire, Denumire)      ELSE Coalesce(Denumire, aDenumire)      END,
          CodExtern   = CASE WHEN vForceUpd = 1 THEN Coalesce(aCodExtern,CodExtern)     ELSE Coalesce(CodExtern,aCodExtern)     END,
          CodLaClient = CASE WHEN vForceUpd = 1 THEN Coalesce(aCodLaClient,CodLaClient) ELSE Coalesce(CodLaClient,aCodLaClient) END
      WHERE CodArtCli = vCodArtCli;
    END IF;
  END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodArticol INTO Tmp FROM NART WHERE CodArticol = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc VARCHAR2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Articol &quot;&apos;||DEN_ARTICOL||&apos;&quot;&apos; INTO aDoc FROM nart WHERE codarticol = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NART&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  FOR V_REC IN ( SELECT * FROM NARTOBJ WHERE NVL(CodArticol, 0) = RecID) LOOP
    FOR V_RECPRETM IN (SELECT * FROM PRETM WHERE CODOBIECT = V_REC.CODOBIECT)
    LOOP
      DELETE FROM PRETMAMB      WHERE CODPRETM = V_RECPRETM.CODPRETM;
      DELETE FROM PRETM         WHERE CODPRETM = V_RECPRETM.CODPRETM;
    END LOOP;
    DELETE FROM NARTAMB         WHERE CODOBIECT = V_REC.CODOBIECT OR CODOBIECTRETURN = V_REC.CODOBIECT;
    DELETE FROM NARTOPT         WHERE CODOBIECT = V_REC.CODOBIECT OR codobiectopt = V_REC.CODOBIECT;
 	  DELETE FROM NECHIV          WHERE CODOBIECT = V_REC.CODOBIECT ;
    DELETE FROM NATROBJ         WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NARTOBJ1        WHERE CODOBIECT = V_REC.CODOBIECT;

  IF PKG_LIST_STRUCT.TmpExists(&apos;NARTOBJEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM NARTOBJEXT WHERE CODOBIECT =  &apos; || TO_CHAR(V_REC.CODOBIECT);
  END IF;


    -- traduceri denumiri obiecte
    DELETE FROM NARTOBJTRAD     WHERE CODOBIECT = V_REC.CODOBIECT;

    DELETE FROM DISCPROMORETAIL WHERE CODOBIECT = V_REC.CODOBIECT;


    DELETE FROM NARTCLI         WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NARTOBJSUBUNIT  WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NARTOBJCOLET    WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM CODEXTALT       WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM CODINTALT       WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NSERII          WHERE CODOBIECT = V_REC.CODOBIECT;

    DELETE FROM DISCART         WHERE CODOBIECT = V_REC.CODOBIECT;

    BEGIN --TABELA DINAMICA PT. LISTE CU VALORILE ANUMITOR ATRIBUTE
      EXECUTE IMMEDIATE &apos;DELETE FROM NARTOBJATR WHERE CODOBIECT = &apos;||V_REC.CODOBIECT;
    EXCEPTION
      WHEN OTHERS THEN NULL; -- PROBABIL NU EXISTA TABELA
    END;

    DELETE FROM NARTOBJ       WHERE CODOBIECT = V_REC.CODOBIECT; -- musai la urma
    DELETE FROM NARTOBJIMP    WHERE CODOBIECT = V_REC.CODOBIECT;
  END LOOP;

  DELETE FROM NART1           WHERE CodArticol = RecId ;
  DELETE FROM NARTIMPLICITE   WHERE CodArticol = RecId ;
  DELETE FROM NARTATR         WHERE CodArticol = RecId ;
  DELETE FROM NARTDIM         WHERE CodArticol = RecId ;
  DELETE FROM NART            WHERE CodArticol = RecId ;

  INSERT INTO NARTDELETED(CODARTICOL) VALUES(RECID);


   NotifyModif(2, RECID, &apos;NART&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  -- nomArt       --&gt; 501
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(501);

  INSERT INTO  TMP_NART FIELDS( CodArticol, ParitateD1, ParitateD2, ParitateD3  ) VALUES (0,1,1,1) ;

  -- Detail DISCOUNT
  INSERT INTO TMP_DISCOUNT ( CodDiscount, CodCriteriu)
  SELECT CodDiscount, CodCriteriu
  FROM DISCOUNT;

  --Detail DISCINTERVAL
  INSERT INTO TMP_DISCINTERVAL ( CodDiscInterval, CodDiscount, LimInf, LimSup, Procent )
  SELECT CodDiscInterval, CodDiscount, LimInf, LimSup, Procent
  FROM DISCINTERVAL
  WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT);

  --actualizez campul DISCOUNTINFO in TMP_DISCOUNT - musai dupa ce am DISCINTERVAL COMPLETAT
  UPDATE TMP_DISCOUNT D SET DISCOUNTINFO = PKG_CRITERIIDISCOUNT.GETDISCINTERVALE(D.CODDISCOUNT);
  -- nomArt       --&gt; 501
  PKG_CFGTABLES.EXT_INSERTRECORD(501);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aANSFARSIT   NUMBER(4);
  aLUNASFARSIT NUMBER(2);
  CLASAART NUMBER(20);
  LENDENART NUMBER;
BEGIN
-- Master NART
 /* insert into timp (select to_char(sysdate, &apos;HH24:MI:SS&apos;) as &quot;Current Time&quot; from dual);  */

    -- nomArt       --&gt; 501
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(501);


  INSERT INTO  TMP_NART ( CodArticol,Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret,UM1,UM2, ContServiciu, INCREMENTSERIE, RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, ParitateD1, ParitateD2, ParitateD3, CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN,RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
                          ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  TIPSTOC )
  SELECT CodArticol,Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret,UM1,UM2, ContServiciu, INCREMENTSERIE, RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, Nvl(ParitateD1,1), Nvl(ParitateD2, 1),Nvl(ParitateD3, 1),CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN, RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
         ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  Coalesce(TIPSTOC,0)
  FROM NART WHERE CodArticol = RecId;

  BEGIN
    SELECT CLASA INTO CLASAART FROM TMP_NART;
    EXCEPTION WHEN OTHERS THEN CLASAART := 0;
  END;

  -- Detail NART1
  INSERT INTO  TMP_NART1 ( CodArticol1,CodArticol,CodTVA,CodAccize,TaxCode, codtaxa1,CodTaxa2,anstart,lunastart, CodAccizeDVI )
  SELECT CodArticol1,CodArticol,CodTVA,CodAccize,TaxCode, codtaxa1,CodTaxa2,anstart,lunastart, CodAccizeDVI
  FROM NART1 WHERE CodArticol = RecId;

  --Detail NARTIMPLICITE
  INSERT INTO  TMP_NARTIMPLICITE  SELECT * FROM NARTIMPLICITE WHERE CodArticol = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODARTICOL1, ANSTART, LUNASTART FROM TMP_NART1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NART1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODARTICOL1 = V_REC.CODARTICOL1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

-- Detail
  INSERT INTO  TMP_NARTOBJ (
    CodObiect, CodArticol, CodExtern, CodIntern, StocMin, StocMed, StocMax, INACTIVCMDONLINE, AUTORIZATIE,EXPIRAREAUTORIZ, TRADUCARTGENERIC, MESAJINACTIV,
    Masa, Volum, CodProducator, CodVamal, Returnabil, LuniGarantie,
    Obs, TARAORIGINE, ZILEVALABIL, ZILEDISTRIB, CODPERISABIL, ProcAdaosNir, Rotunjire, UMAmbalare,
    PRETMINIM, TERMENPLATA, DATAADAUGARII, CODPLU, USESTOCMED, NEFACTURABIL, GREUTSPECIFICA, BLOCAT, DURMAXAPROV, CODCNAS,  CODCARACT, CODD394, INACTIV,
    FARACMDFURN, FARANIVELAPROB, DESCARCAREINTEGRALA, FARASTOC, CODCATEGARTTI,
    AdaosExceptie, Promotie, ROTVALUTA, DiscPromo, PRODUSPROPRIU,
    STOCMINSUB, STOCMAXSUB, STOCMEDSUB, DENUMIRE, COEFCNAS, EXPORTEMCS, CODNC, CODCPV, EXCLUSLISTARECM, CODACCIZABIL,
    RAPCNAS, ANTIBIOTIC, LANSIMP, EXPORTKLG, CODANALIZANOD, SAFT_EXPORT, CANTVANZ, CERTIF_DDS)
  SELECT
    A.CodObiect, A.CodArticol, A.CodExtern, A.CodIntern, A.StocMin, A.StocMed, A.StocMax, A.INACTIVCMDONLINE, A.AUTORIZATIE, A.EXPIRAREAUTORIZ, A.TRADUCARTGENERIC, A.MESAJINACTIV,
    A.Masa, A.Volum, A.CodProducator, A.CodVamal, A.Returnabil, A.LuniGarantie,
    A.Obs, A.TARAORIGINE, A.ZILEVALABIL, A.ZILEDISTRIB, A.CODPERISABIL, A.ProcAdaosNir, A.Rotunjire, A.UMAmbalare,
    A.PRETMINIM, A.TERMENPLATA, A.DATAADAUGARII, A.CODPLU, A.USESTOCMED, A.NEFACTURABIL, A.GREUTSPECIFICA, A.BLOCAT, A.DURMAXAPROV, A.CODCNAS, A.CODCARACT, A.CODD394, A.INACTIV,
    A.FARACMDFURN, A.FARANIVELAPROB, A.DESCARCAREINTEGRALA, A.FARASTOC, A.CODCATEGARTTI,
    A.AdaosExceptie, A.Promotie, A.ROTVALUTA, A.DiscPromo, A.PRODUSPROPRIU,
    STOCMIN, STOCMAX, STOCMED, A.DENUMIRE, A.COEFCNAS, A.EXPORTEMCS, A.CODNC, A.CODCPV, A.EXCLUSLISTARECM, A.CODACCIZABIL,
    Coalesce(A.RAPCNAS, CASE WHEN A.CODCNAS IS NULL THEN 0 ELSE 1 END) RAPCNAS, A.ANTIBIOTIC, A.LANSIMP, A.EXPORTKLG, A.CODANALIZANOD,COALESCE(A.SAFT_EXPORT,0), A.CANTVANZ, A.CERTIF_DDS
  FROM NARTOBJ a, NART b
  WHERE a.CodArticol = RecId
    AND a.codarticol = b.codarticol
  ORDER BY codObiect;

  INSERT INTO TMP_NARTOBJSUBUNIT(CODS, CODOBIECT, SUBUNITATE, STOCMIN, STOCMED, STOCMAX, PROCSTOCMIN, PROCSTOCMAX, PROCSTOCMED, CODGEST)
  SELECT S.CODS, S.CODOBIECT, S.SUBUNITATE, S.STOCMIN, S.STOCMED, S.STOCMAX, S.PROCSTOCMIN, S.PROCSTOCMAX, S.PROCSTOCMED, S.CODGEST
  FROM
    NARTOBJSUBUNIT S,
    TMP_NARTOBJ OBJ
  WHERE OBJ.CodObiect = S.CodObiect
--  WHERE EXISTS (SELECT OBJ.CodObiect FROM TMP_NARTOBJ OBJ WHERE OBJ.CodObiect = S.CodObiect)
  AND NVL(S.SUBUNITATE, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(S.SUBUNITATE, 1), PKG_GLOBALS.GETSUBUNITATE);
  --ORDER BY S.CodObiect;

  INSERT INTO TMP_NARTOBJIMP(CODOBJIMP, CODOBIECT, CODSUBUNIT, GESTIMPLICITA, LOCATIEIMPLICITA,DURMAXAPROV,CONTIMPLICIT)
  SELECT CODOBJIMP, CODOBIECT, CODSUBUNIT, GESTIMPLICITA, LOCATIEIMPLICITA,DURMAXAPROV,CONTIMPLICIT
  FROM NARTOBJIMP IMP
  WHERE EXISTS (SELECT OBJ.CodObiect FROM TMP_NARTOBJ OBJ WHERE OBJ.CodObiect = IMP.CodObiect);

  IF PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 THEN
    UPDATE TMP_NARTOBJ O
    SET (O.STOCMINSUB, O.STOCMAXSUB, O.STOCMEDSUB)
      = (SELECT OS.STOCMIN, OS.STOCMAX, OS.STOCMED
            FROM TMP_NARTOBJSUBUNIT OS
            WHERE OS.CodObiect = O.CodObiect
                AND OS.SUBUNITATE = /*1*/ PKG_GLOBALS.GETSUBUNITATE
                AND (OS.CODGEST IS NULL OR OS.CODGEST = 0));
  END IF;

  -- Detail PRETM

  INSERT INTO TMP_PRETM (CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, GRUPA, PROC, INDEXLOCAL, SUBUNITATEA, ROTUNJIRE, SUMAFIXAIMPLICIT)
  SELECT PM.CODPRETM, PM.CODOBIECT, PM.CODCATPRET, PM.LEI, PM.VALUTA, PM.MONEDA, PM.IMPLICIT, PM.GRUPA, PM.PROC, PM.INDEXLOCAL, PM.SUBUNITATEA, PM.ROTUNJIRE, PM.SUMAFIXAIMPLICIT
  FROM
    PRETM PM,
    TMP_NARTOBJ O
  WHERE
    PM.CODOBIECT = O.CODOBIECT--CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ)
    AND NVL(PM.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(PM.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
  ORDER BY CODOBIECT, INDEXLOCAL;

  UPDATE TMP_PRETM P
  SET
    (DENCATPRET, TIPCATPRET, DENTIPCATPRET, CODCATMASTER) =
    (SELECT DEN_CATPRET, TIP,
       CASE
        WHEN TIP =  1 THEN &apos;nominal cu TVA&apos;
        WHEN TIP =  2 THEN &apos;nominal fara TVA&apos;
        WHEN TIP =  3 THEN &apos;% adaos aplicat la PU inregistrare&apos;
        WHEN TIP =  4 THEN &apos;% adaos aplicat la PU achizitie&apos;
        WHEN TIP =  5 THEN &apos;% diminuare PU maximal&apos;
        WHEN TIP =  6 THEN &apos;% din stoc aplicat la PU inregistrare&apos;
        WHEN TIP =  7 THEN &apos;% din stoc aplicat la PU achizitie&apos;
        WHEN TIP =  8 THEN &apos;% distributie aplicat la PU inregistrare&apos;
        WHEN TIP =  9 THEN &apos;% distributie aplicat la PU achizitie&apos;
        WHEN TIP = 10 THEN &apos;% adaos aplicat la ultimul PU achizitie&apos;
        WHEN TIP = 11 THEN &apos;% adaos aplicat la ultimul PU achizitie in valuta&apos;
       END,
       CODCATMASTER
    FROM NCATPRET WHERE CODCATPRET = P.CODCATPRET
    );
  -- Detail NARTOBJ1
  INSERT INTO  TMP_NARTOBJ1 (
    CodObiect1, CodObiect, PretMaximal, ProcAdaosMaximal, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA, uplift, codmoneda, AdaosLa,
    PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    anstart, lunastart, tippret, ValMat, ValMan, ValRegie, D390Exclus, Cost, Cantservauto, proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate,
    sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PRETPROD)
  SELECT
    CodObiect1,CodObiect,PretMaximal, ProcAdaosMaximal, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE,  GRUPA, uplift, codmoneda, AdaosLa,
    PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    anstart, lunastart, nvl(tippret,1), ValMat, ValMan, ValRegie, Nvl(D390Exclus,0), Cost, CantServAuto, proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate,
    sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PRETPROD
  FROM NARTObj1 o1 WHERE exists (Select tmp.codobiect from TMP_NartOBJ tmp where tmp.codobiect = o1.codobiect);

  -- traduceri denumiri
  INSERT INTO TMP_NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, Descriere)
  (
    SELECT CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, descriere
    FROM NARTOBJTRAD n WHERE exists (SELECT tmp.codobiect FROM TMP_NARTOBJ tmp where n.codobiect = tmp.codobiect)
  );

  INSERT INTO TMP_DISCPROMORETAIL(COD, CODPOSTRETAIL, CODOBIECT, DISCPROMO, DENUMIRE)
  (
    SELECT
      D.COD,
      D.CODPOSTRETAIL,
      D.CODOBIECT,
      D.DISCPROMO,
      P.DENUMIRE
    FROM
      DISCPROMORETAIL D,
      POSTRETAIL P
    WHERE
      exists (SELECT tmp.codobiect FROM TMP_NARTOBJ tmp where d.codobiect = tmp.codobiect)
      AND P.COD = D.CODPOSTRETAIL
  );

  FOR V_REC_OBJ IN (SELECT CODOBIECT FROM TMP_NARTOBJ) LOOP
    aANSFARSIT := 0; aLUNASFARSIT := 0;
    FOR V_REC IN (SELECT CODOBIECT1, ANSTART, LUNASTART FROM TMP_NARTOBJ1 WHERE CODOBIECT = V_REC_OBJ.CODOBIECT ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_NARTOBJ1
        SET
          ANSFARSIT   = aANSFARSIT,
          LUNASFARSIT = aLUNASFARSIT
        WHERE
          CODOBIECT1 = V_REC.CODOBIECT1;
      END IF;

      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
    END LOOP;
  END LOOP;

-- Detail NARTCLI
  INSERT INTO  TMP_NARTCLI (
    CodArtCli, CodObiect, CodPart, Denumire, CodExtern, UMSec, UMCorelat, DenUMCorel, CODMONEDA,
    PRET, tipcodafisat, CodLaClient, CODINTERN, IMPLICIT, DEN_PART, CODCLASEP, SIMBOLCLASAP,
    CODGAMA, OBS, DENGAMA,OBS2, UMSECIMPDOC, Duratatr, Zilestoc, GLN, IDspecific)
  SELECT
    ac.CodArtCli, ac.CodObiect, ac.CodPart, ac.Denumire, ac.CodExtern, ac.UMSec, ac.UMCorelat,u.Den_UM1, ac.CODMONEDA,
    ac.PRET, ac.tipcodafisat, CodLaClient, ac.CODINTERN, ac.IMPLICIT, P.DEN_PART, AC.CODCLASEP, CP.SIMBOL,
    AC.CODGAMA, AC.OBS, G.DENUMIRE, AC.OBS2,  AC.UMSECIMPDOC, ac.duratatr, ac.zilestoc, ac.GLN, ac.IDspecific
  FROM NARTCLI ac
    left join NUM1 u ON u.CodUM1 = ac.UmCorelat
    left join NPART P ON P.CodPART = ac.CODPART
    LEFT JOIN NCLASEP CP ON CP.CODCLASEP = AC.CODCLASEP
    LEFT JOIN NGAMEART G ON G.CODGAMA = AC.CODGAMA
  WHERE CodObiect in (SELECT CodObiect from TMP_NARTOBJ);

-- Detail NATROBJ
  INSERT INTO  TMP_NATROBJ ( CodObiect,CodAtrOBJ,CodArtAtr,CodValAtr, INDEXLOCAL )
    SELECT * FROM
    (
    ( SELECT C2.CodObiect,C2.CodAtrOBJ,C2.CodArtAtr,C2.CodValAtr, C2.INDEXLOCAL
      FROM NARTOBJ C1, NATROBJ C2
      WHERE C2.CodObiect = C1.CodObiect AND C1.CodArticol = RecId )
    ) ORDER BY INDEXLOCAL;

-- Detail NARTATR
  INSERT INTO  TMP_NARTATR ( CodArtAtr,CodArticol,CodAtribut,Activ,CodValPredef,Obligatoriu, OBS, Selectie,Facturabil, INDEXLOCAL )
  SELECT * FROM
  (
    (SELECT * FROM (SELECT CodArtAtr,CodArticol,CodAtribut,Activ,CodValPredef,Obligatoriu, OBS, Selectie,Facturabil, INDEXLOCAL
                           FROM NARTATR WHERE CodArticol = RecID ORDER BY INDEXLOCAL
                   )
    )
    ) ORDER BY INDEXLOCAL;

-- Detail NARTATR
  INSERT INTO  TMP_NARTDIM ( CodArtDim,CodObiect,CodArticol, Tip, D1, D2, D3 )
  SELECT * FROM
  (
    (SELECT * FROM (SELECT CodArtDim,Nvl(CodObiect,0),CodArticol, Tip, D1, D2, D3 FROM NARTDIM WHERE CodArticol = RecID ORDER BY Tip, D1,D2,D3
                   )
    )
    ) ORDER BY Tip, D1,D2,D3;

-- completare campuri adaugate
 BEGIN
   SELECT LENGTH(DEN_ARTICOL) INTO LENDENART FROM NART A WHERE CODARTICOL = RECID;
   EXCEPTION WHEN OTHERS THEN
     LENDENART := 0;
 END;

 FOR V_REC IN (SELECT O.*, AO.CODATROBJ FROM
              TMP_NARTOBJ O
              LEFT JOIN TMP_NATROBJ AO ON AO.CODOBIECT = O.CODOBIECT AND ROWNUM = 1
             )
 LOOP
  UPDATE TMP_NARTOBJ O
  SET
    DENOBIECT   = CASE
                    WHEN V_REC.CODATROBJ &lt;&gt; 0 THEN TRIM(SUBSTR(V_REC.DENUMIRE, LENDENART + 1, LENGTH(V_REC.DENUMIRE)))
                    ELSE &apos; .... Fara atribute ...&apos;
                  END,
    AREATRIBUTE = CASE
                    WHEN V_REC.CODATROBJ &lt;&gt; 0  THEN 1
                    ELSE 0
                  END
  WHERE
    CODOBIECT = V_REC.CODOBIECT;

 END LOOP;

/*
  UPDATE TMP_NARTOBJ O
  SET
    DENOBIECT   = CASE
                    WHEN (SELECT COUNT(*) FROM TMP_NATROBJ A WHERE A.CODOBIECT = O.CODOBIECT) &gt; 0 THEN PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(CODOBIECT)
                    ELSE &apos; .... Fara atribute ...&apos;
                  END,
    AREATRIBUTE = CASE
                    WHEN (SELECT COUNT(*) FROM TMP_NATROBJ A WHERE A.CODOBIECT = O.CODOBIECT) &gt; 0 THEN 1
                    ELSE 0
                  END;

*/


-- legaturi cu criterii discounturile
-- Detail CRITERIIDISC -- pentru fiecare obiect INSEREZ IN CRITERII CATE UN SET DE CRITERIU

-- Detail DISCART -- aduc numai inregistrarile coresounzatoare discount-urilor pe OBIECT
  INSERT INTO TMP_DISCART ( CodDiscArt, CodDiscount, CodObiect )
  (
   SELECT DA.CodDiscArt, DA.CodDiscount, DA.CodObiect
   FROM
     DISCART DA
     LEFT OUTER JOIN DISCOUNT D ON D.CODDISCOUNT = DA.CODDISCOUNT
     LEFT OUTER JOIN CRITERIIDISC CR ON CR.CODCRITERIU = D.CODCRITERIU
   WHERE
    ((CR.PECLASE = 0)AND(DA.CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ)))OR
    ((CR.PECLASE = 1)AND(DA.CODOBIECT = CLASAART))
  );

-- Detail DISCOUNT
  INSERT INTO TMP_DISCOUNT ( CodDiscount, CodCriteriu)
  ( SELECT CodDiscount, CodCriteriu FROM DISCOUNT WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCART));

-- Detail DISCINTERVAL
  INSERT INTO TMP_DISCINTERVAL ( CodDiscInterval, CodDiscount, LimInf, LimSup, Procent )
  (
   SELECT CodDiscInterval, CodDiscount, LimInf, LimSup, Procent
    FROM DISCINTERVAL  WHERE CODDISCOUNT IN (SELECT CODDISCOUNT FROM TMP_DISCOUNT)
  );
 -- actualizez campul DISCOUNTINFO in TMP_DISCOUNT - musai dupa ce am DISCINTERVAL COMPLETAT
  UPDATE TMP_DISCOUNT D SET DISCOUNTINFO = PKG_CRITERIIDISCOUNT.GETDISCINTERVALE(D.CODDISCOUNT);

  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ) LOOP
      INSERT INTO TMP_CRITERIIDISC ( CodCriteriu, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, CODOBIECT )
        ( SELECT CodCriteriu, DenCriteriu, ExcludVolTr, ExcludCantFact, ExcludTermen, ExcludValDoc, ExcludDistanta, PeClase, V_REC.CODOBIECT
          FROM CRITERIIDISC WHERE CODCRITERIU &gt; 0 AND CODCRITERIU IN (SELECT CODCRITERIU FROM TMP_DISCOUNT));
  END LOOP;

  -- fac legatura intre CRITERII si discount-urile asignate articolelor
  -- PENTRU CELE PE ARTICOL :
  FOR V_REC IN
  (SELECT
     DA.CODDISCART, DI.CODDISCOUNT, DA.CODOBIECT, DI.CODCRITERIU
   FROM
     TMP_DISCART DA,
     TMP_DISCOUNT DI,
     TMP_CRITERIIDISC CR
   WHERE
     DA.CODDISCOUNT = DI.CODDISCOUNT AND
     DI.CODCRITERIU = CR.CODCRITERIU
    )
  LOOP
    UPDATE TMP_CRITERIIDISC CRIT
    SET
      DISCOUNTCURENT = V_REC.CODDISCOUNT
    WHERE
      CRIT.PECLASE = 0 AND
      CRIT.CODCRITERIU = V_REC.CODCRITERIU AND
      CRIT.CODOBIECT   = V_REC.CODOBIECT;
  END LOOP;

  -- PENTRU CELE PE CLASE :
  UPDATE TMP_CRITERIIDISC CRIT
  SET
   DISCOUNTCURENT =
   (SELECT DI.CODDISCOUNT
    FROM
      TMP_DISCOUNT DI,
      TMP_DISCART  DA
    WHERE
     DI.CODCRITERIU = CRIT.CODCRITERIU AND
     DA.CODDISCOUNT = DI.CODDISCOUNT AND
     DA.CODCLASA    = CLASAART
   )
   WHERE
   CRIT.PECLASE = 1;

  UPDATE TMP_CRITERIIDISC CRIT
  SET
    INFODISCOUNTCURENT = NVL((SELECT DISCOUNTINFO FROM TMP_DISCOUNT WHERE CODDISCOUNT = CRIT.DISCOUNTCURENT), &apos;?&apos;)
  WHERE DISCOUNTCURENT IS NOT NULL;

  INSERT INTO TMP_NECHIV (
    CODECHIV, CODOBIECT, CODOBIECTECHIV, PARITATE, CODGRUPA, GENERIC, INDEXLOCAL , Ind)
  SELECT
    E.CODECHIV, E.CODOBIECT, E.CodObiect, E.PARITATE, E.CODGRUPA, E.GENERIC, E.INDEXLOCAL, E.Ind
  FROM
    NECHIV E
  WHERE
    EXISTS (SELECT CODOBIECT FROM  TMP_NARTOBJ O WHERE O.CODOBIECT = E.CODOBIECT);

  INSERT INTO TMP_NARTOPT
   (CODOPT, CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, OBS, DENOBIECTOPT, CODEXTERN, CODINTERN, SELECTAT, LEI )
   (SELECT CODOPT, A.CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, A.OBS, O.DENUMIRE, O.CODEXTERN, O.CODINTERN, 0, PM.LEI
  FROM NARTOPT A
       LEFT JOIN NARTOBJ O on O.CODOBIECT = A.codobiectopt
       LEFT JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND PM.IMPLICIT = 1
	WHERE A.CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ));

  INSERT INTO TMP_NARTAMB
   (CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN, UMSEC, CODEXTERN, CODPLU, CODINTERN,
   MASA, LUNGIME, LATIME, INALTIME, LXLAT, LXH, LATXH, GREUTSPECIFICA, IMPLICITTIPDOC,TIP,  DENOBIECTRETURN,
   DENUMSEC, PARITATE, IMPLICIT, NR_RANDURI, AdMax, returnabil)
   (SELECT CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN, UMSEC, CODEXTERN, CODPLU, CODINTERN,
    MASA, LUNGIME, LATIME, INALTIME, LXLAT, LXH, LATXH,GREUTSPECIFICA, IMPLICITTIPDOC, TIP,
   (SELECT DENUMIRE FROM NARTOBJ WHERE CODOBIECT = A.CODOBIECTRETURN),
   (SELECT Den_UM1  FROM NUM1 WHERE CodUM1 = A.UMSEC),
   (SELECT Paritate FROM NUM1 WHERE CodUM1 = A.UMSEC),
    CASE
      WHEN NVL(UMSEC, -1) IN (select NVL(UMAMBALARE, 0) from tmp_nartobj) THEN 1
      ELSE 0
    end,
    NR_RANDURI, AdMax, coalesce(returnabil,1)
  FROM NARTAMB A WHERE CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ));

  INSERT INTO TMP_PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA, DENUMSEC)
  SELECT PAMB.CODPRETMAMB, PAMB.CODPRETM, PAMB.CODAMB, PAMB.LEI, PAMB.VALUTA, U1.DEN_UM1
  FROM
   PRETMAMB PAMB,
   TMP_NARTAMB AMB,
   NUM1 U1
  WHERE
   AMB.UMSEC &gt; 0 AND
   AMB.CODAMB = PAMB.CODAMB
   AND U1.CODUM1 = AMB.UMSEC
   AND EXISTS (SELECT 1 FROM TMP_PRETM WHERE CODPRETM = PAMB.CODPRETM);

   INSERT INTO TMP_NARTOBJCOLET SELECT * FROM NARTOBJCOLET C WHERE EXISTS (SELECT CODOBIECT FROM TMP_NARTOBJ WHERE CODOBIECT = C.CODOBIECT);

   INSERT INTO TMP_CODEXTALT (COD, CODOBIECT, CODEXTERN, CODPART, DEN_PART)
   SELECT C.COD, C.CODOBIECT, C.CODEXTERN, C.CODPART, P.DEN_PART
    FROM CODEXTALT C
    LEFT JOIN NPART P ON P.CODPART = C.CODPART
    WHERE EXISTS (SELECT CODOBIECT FROM TMP_NARTOBJ WHERE CODOBIECT = C.CODOBIECT);

   INSERT INTO TMP_CODINTALT (COD, CODOBIECT, CODINTERN, CODPART, DEN_PART)
   SELECT C.COD, C.CODOBIECT, C.CODINTERN, C.CODPART, P.DEN_PART
    FROM CODINTALT C
    LEFT JOIN NPART P ON P.CODPART = C.CODPART
    WHERE EXISTS (SELECT CODOBIECT FROM TMP_NARTOBJ WHERE CODOBIECT = C.CODOBIECT);

   --for v_rec in (Select CodObiect from TMP_NARTOBJ) loop
		 UPDATE TMP_NARTOBJ o
		 SET
		  	OPTIONALE = (SELECT COUNT(*) FROM TMP_NARTOPT tmp WHERE tmp.CODOBIECT = o.CODOBIECT);
   --end loop;

   UPDATE TMP_NARTOBJSUBUNIT NS
   SET
    DENSUBUNIT = (SELECT DEN_SUBUNIT FROM NSUBUNIT WHERE CODSUBUNIT = NS.SUBUNITATE),
    DEN_GEST = (SELECT DEN_GEST FROM ngest GST WHERE GST.CODGEST = NS.CODGEST);

  DELETE TMP_NARTOBJSUBUNIT_INI;
  INSERT INTO TMP_NARTOBJSUBUNIT_INI SELECT CODS FROM TMP_NARTOBJSUBUNIT;

  FOR V_REC IN (SELECT PAMB.CODPRETMAMB, PAMB.LEI, U1.PARITATE FROM TMP_PRETMAMB PAMB, NARTAMB AMB, NUM1 U1
               WHERE
                 PAMB.CODAMB = AMB.CODAMB
                 AND AMB.UMSEC = U1.CODUM1
               )
  LOOP
    UPDATE TMP_PRETMAMB
    SET
      PARITATE = V_REC.PARITATE,
      LEIUMP   = CASE
                   WHEN NVL(V_REC.PARITATE, 0) &lt;&gt; 0 THEN  V_REC.LEI / V_REC.PARITATE
                   ELSE NULL
                 END
    WHERE
      CODPRETMAMB = V_REC.CODPRETMAMB;
  END LOOP;
  -- nomArt       --&gt; 501
  PKG_CFGTABLES.EXT_GOTORECORD(501);
  COMMIT;
END;

PROCEDURE MEMOMODIPRET(aCODOBIECT IN NUMBER)
IS
aVAlue varchar2(10);
BEGIN
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aValue FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aValue := &apos;0&apos;;
  END;
  IF aVALUE = &apos;1&apos; THEN
      FOR V_REC IN
      (
        SELECT
         O.CODOBIECT,
         PM.LEI AS PRETNOU,
         PM.CODCATPRET,
         PM.SUBUNITATEA
        FROM
          TMP_PRETM PM
          LEFT OUTER JOIN PRETM PM_OLD ON PM_OLD.CODOBIECT = PM.CODOBIECT AND PM_OLD.CODCATPRET = PM.CODCATPRET AND PM_OLD.SUBUNITATEA = PM.SUBUNITATEA,
          NARTOBJ O,
          NART A,
          NCATPRET CP
        WHERE
          PM.SUBUNITATEA             = PKG_GLOBALS.GETSUBUNITATE
          AND PM.CODOBIECT           = O.CODOBIECT
          AND A.CODARTICOL           = O.CODARTICOL
          AND O.CODOBIECT            = aCODOBIECT
    --    AND PM.IMPLICIT            = 1
          AND PM.CODCATPRET          = CP.CODCATPRET
          AND CP.TIP IN (1, 2)
          AND NVL(PM_OLD.LEI, 0)     &lt;&gt; NVL(PM.LEI, 0)
       )
       LOOP
         INSERT INTO MODIFICARIPRET(CODMODIF, CODOBIECT, CODCATPRET, PRETNOU, DATA, SUBUNITATEA)
                       VALUES(Seq_Modificaripret_Codmodif.Nextval, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.PRETNOU, SYSDATE, V_REC.SUBUNITATEA);
       END LOOP;

  END IF;
END;


PROCEDURE CHECKMODIFPRETRETAIL(aCODOBIECT IN NUMBER)
IS
 aCODSYNC NUMBER;
 aVALUE   VARCHAR2(20);
 aVALUE2  VARCHAR2(20);
BEGIN
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aValue FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aValue := &apos;0&apos;;
  END;

  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;ArtSyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aValue2 FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aValue2 := &apos;0&apos;;
  END;
  IF aVALUE = &apos;1&apos; THEN
  FOR V_REC IN
  (
    SELECT
     P.COD AS CODPOSTRETAIL,
     O.CODOBIECT,
     PM.LEI AS PRETNOU,
     PM.CODCATPRET
    FROM
      POSTRETAIL P,
      TMP_PRETM PM
      LEFT OUTER JOIN PRETM PM_OLD ON PM_OLD.CODOBIECT = PM.CODOBIECT AND PM_OLD.CODCATPRET = PM.CODCATPRET AND PM_OLD.SUBUNITATEA = PM.SUBUNITATEA,
      NARTOBJ O,
      NART A,
      NCATPRET CP
    WHERE
     -- PM.SUBUNITATEA             = PKG_GLOBALS.GETSUBUNITATE
     -- AND P.SUBUNITATEA          = PKG_GLOBALS.GETSUBUNITATE
      PM.SUBUNITATEA             = P.SUBUNITATEA
      AND PM.CODOBIECT           = O.CODOBIECT
      AND O.CODOBIECT            = aCODOBIECT
      AND A.CODARTICOL           = O.CODARTICOL
      AND NVL(A.CASADEMARCAT, 0) = 1
--    AND PM.IMPLICIT            = 1
      AND PM.CODCATPRET          = CP.CODCATPRET
      AND CP.TIP IN (1, 2)
      AND (NVL(PM_OLD.LEI, 0)     &lt;&gt; NVL(PM.LEI, 0) OR aVALUE2 = 1)
  )
  LOOP
    BEGIN
      SELECT CODSYNC INTO aCODSYNC
      FROM
        SYNCPRETRETAIL
      WHERE
        CODPOSTRETAIL  = V_REC.CODPOSTRETAIL
        AND CODOBIECT  = V_REC.CODOBIECT
        AND CODCATPRET = V_REC.CODCATPRET;
       EXCEPTION WHEN OTHERS THEN aCODSYNC := 0;
    END;

    IF aCODSYNC = 0 THEN
      INSERT INTO SYNCPRETRETAIL(CODSYNC, CODPOSTRETAIL, CODOBIECT, CODCATPRET, PRETNOU, DATA, SINCRONIZAT)
             VALUES(SEQ_SYSNPRETRETAIL_CODSYNC.NEXTVAL, V_REC.CODPOSTRETAIL, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.PRETNOU, SYSDATE, 0)   ;
    ELSE
      UPDATE SYNCPRETRETAIL
      SET
        PRETNOU     = V_REC.PRETNOU,
        DATA        = SysDate,
        SINCRONIZAT = 0
      WHERE
        CODSYNC = aCODSYNC
        AND PRETNOU  &lt;&gt; V_REC.PRETNOU;
    END IF;
  END LOOP;
  END IF;




  IF aVALUE = &apos;1&apos; THEN
  FOR V_REC IN
  ( SELECT * FROM
   (
    SELECT
      P.COD AS CODPOSTRETAIL,
      O.CODOBIECT,
      PMAMB.LEI AS PRETNOU,
      PM.CODCATPRET,
     (SELECT PMAMB_OLD.LEI
      FROM
        PRETM PM_OLD,
        PRETMAMB PMAMB_OLD
      WHERE
        PM_OLD.CODOBIECT = PM.CODOBIECT
        AND PM_OLD.CODCATPRET = PM.CODCATPRET
        AND PM_OLD.SUBUNITATEA = PM.SUBUNITATEA
        AND PMAMB_OLD.CODPRETM = PM_OLD.CODPRETM
        AND PMAMB_OLD.CODAMB = PMAMB.CODAMB
      ) AS PRETOLD
    FROM
      TMP_PRETMAMB PMAMB,
      TMP_PRETM PM,
      POSTRETAIL P,
      NARTOBJ O,
      NART A,
      NCATPRET CP
    WHERE
      PMAMB.CODPRETM             = PM.CODPRETM
      AND PM.SUBUNITATEA         = PKG_GLOBALS.GETSUBUNITATE
      AND P.SUBUNITATEA          = PKG_GLOBALS.GETSUBUNITATE
      AND PM.CODOBIECT           = O.CODOBIECT
      AND O.CODOBIECT            = aCODOBIECT
      AND A.CODARTICOL           = O.CODARTICOL
      AND NVL(A.CASADEMARCAT, 0) = 1
--    AND PM.IMPLICIT            = 1
      AND PM.CODCATPRET          = CP.CODCATPRET
      AND CP.TIP IN (1, 2)
     )
     WHERE
       PRETOLD &lt;&gt; PRETNOU
    )
  LOOP
    BEGIN
      SELECT CODSYNC INTO aCODSYNC
      FROM
        SYNCPRETRETAIL
      WHERE
        CODPOSTRETAIL  = V_REC.CODPOSTRETAIL
        AND CODOBIECT  = V_REC.CODOBIECT
        AND CODCATPRET = V_REC.CODCATPRET;
       EXCEPTION WHEN OTHERS THEN aCODSYNC := 0;
    END;

    IF aCODSYNC = 0 THEN
      INSERT INTO SYNCPRETRETAIL(CODSYNC, CODPOSTRETAIL, CODOBIECT, CODCATPRET, PRETNOU, DATA, SINCRONIZAT)
             VALUES(SEQ_SYSNPRETRETAIL_CODSYNC.NEXTVAL, V_REC.CODPOSTRETAIL, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.PRETNOU, SYSDATE, 0)   ;
    ELSE
      UPDATE SYNCPRETRETAIL
      SET
        PRETNOU     = V_REC.PRETNOU,
        DATA        = SysDate,
        SINCRONIZAT = 0
      WHERE
        CODSYNC = aCODSYNC;
    END IF;
  END LOOP;
  END IF;


  -- fara commit ca se face in sp_post
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  --vRecNo            INTEGER := 0;
  --vAn               INTEGER := 0;
  --vLuna             INTEGER := 0;
  vCod              NUMBER(20);
  aCODOBIECT        NUMBER(20);
  aINDEXLOCAL       NUMBER(20);
  aDENARTICOL       VARCHAR(100) := &apos;&apos;;
  aPARITATE         NUMBER(20,7) := 1;
  aNr               NUMBER(20);
  aCODPRETM         NUMBER(20);
  aCODAMB           NUMBER(20);
  aCODOPT           NUMBER(20);
  --aCount            NUMBER(20);
  aDenTrad          VARCHAR(200);
  aDoc                VARCHAR(200);
  CaractObiectGENERIC VARCHAR(10);
  ATRIBUTE          NUMBER(10) := 0;
  CODOBIECTGENERIC  NUMBER(20) := 0;
  aRelatieUM1 number(10);
  aD1 number(20,7);
  aD2 number(20,7);
  aD3 number(20,7);
  aParD1 number(20,7);
  aParD2 number(20,7);
  aParD3 number(20,7);
  Tmp number(20);
  --aBifaTrad         NUMBER(1);
  --aCodObiectGeneric NUMBER(20);
  aMemo varchar2(10);
  aCheck varchar2(10);
  aCount number(10);
  aCodCatPret number(20);
BEGIN
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aMemo FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aMemo := &apos;0&apos;;
  END;
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aCheck FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aCheck := &apos;0&apos;;
  END;
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;CatPretArt&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aCodCatPret FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aMemo := &apos;0&apos;;
  END;
  BEGIN
    SELECT DEN_ARTICOL, Coalesce(RelatieUM1,0), D1, D2, D3, ParitateD1, ParitateD2, ParitateD3 INTO aDENARTICOL, aRelatieUM1, aD1, aD2, aD3 , aParD1, aParD2, aParD3 FROM TMP_NART;
    EXCEPTION WHEN OTHERS THEN aDENARTICOL := &apos;&apos;;
  END;
  aDoc := &apos;Articol &quot;&apos;||aDENARTICOL||&apos;&quot;&apos;;

  -- nomArt       --&gt; 501
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (501);

  IF OPERATION = 0 THEN -- UPDATE

  --***************************** U P D A T E *****************************

-- Master NART
    SELECT  CodArticol INTO RecId FROM TMP_NART;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NART&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NART SET ( Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret,UM1,UM2, ContServiciu, INCREMENTSERIE, RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, ParitateD1, ParitateD2, ParitateD3, CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN,RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
                      ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  TIPSTOC  )
       = ( SELECT Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret,UM1,UM2, ContServiciu, INCREMENTSERIE,  RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, ParitateD1, ParitateD2, ParitateD3, CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN,RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
                  ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  TIPSTOC
           FROM TMP_NART )
    WHERE CodArticol = RecId ;

-- Detail NART1
    DELETE FROM NART1  A1
    WHERE
      CodArticol = RecId and
      NOT EXISTS (Select CodArticol1 from TMP_NART1 WHERE CODARTICOL1 = A1.CODARTICOL1);

    INSERT INTO NART1 ( CodArticol1,CodArticol,CodTVA,CodAccize,TaxCode, codtaxa1,CodTaxa2,anstart,lunastart,CodAccizeDVI )
    SELECT  seq_NART1_CodArticol1.Nextval , RecId ,CodTVA,CodAccize,TaxCode, codtaxa1,CodTaxa2,anstart,lunastart,CodAccizeDVI
    FROM TMP_NART1 WHERE CodArticol1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NART1 WHERE Coalesce(CodArticol1,-1) &gt; 0 ORDER BY CodArticol1 ) LOOP
    UPDATE NART1
    SET
      CodTVA       = v_rec.CodTVA,
      CodAccize    = v_rec.CodAccize,
      CodAccizeDVI = v_rec.CodAccizeDVI,
      TaxCode      = v_rec.TaxCode,
      codtaxa1     = v_rec.codtaxa1,
      CodTaxa2     = v_rec.CodTaxa2
    WHERE CodArticol1  = v_rec.CodArticol1;
    END LOOP;

    -- Detail NARTIMPLICITR
    DELETE FROM NARTIMPLICITE AI WHERE CodArticol = RecId
    AND NOT EXISTS (Select CODIMPLICIT from TMP_NARTIMPLICITE WHERE CODIMPLICIT = AI.CODIMPLICIT);

    INSERT INTO NARTIMPLICITE (CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA, NEVANDABIL)
    SELECT  SEQ_NARTIMPLICITE_CODIMPLICIT.Nextval , RecId, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA, NEVANDABIL
    FROM TMP_NARTIMPLICITE WHERE CODIMPLICIT &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_NARTIMPLICITE WHERE Coalesce(CODIMPLICIT,-1) &gt; 0 ) LOOP
    UPDATE NARTIMPLICITE
    SET
      CODSUBUNIT        = v_rec.CODSUBUNIT,
      GESTIMPLICITA     = v_rec.GESTIMPLICITA,
      CONTIMPLICIT      = v_rec.CONTIMPLICIT,
      LOCATIEIMPLICITA  = v_rec.LOCATIEIMPLICITA,
      NEVANDABIL        = v_rec.NEVANDABIL
    WHERE
     CODIMPLICIT  = v_rec.CODIMPLICIT;
    END LOOP;

-- Detail NARTOBJ
-- pentru stergerea din NArtObj trebuie mai intai sa sterg din detalii

    FOR V_REC IN (
      SELECT *
      FROM NARTOBJ O
      WHERE CODARTICOL = RECID AND NOT EXISTS (SELECT CODOBIECT FROM TMP_NARTOBJ WHERE CODOBIECT = O.CODOBIECT)
    ) LOOP
      DELETE FROM NATROBJ  WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM NARTOBJSUBUNIT WHERE CODOBIECT = V_REC.CODOBIECT;

      FOR V_REC_PRETM IN (SELECT * FROM PRETM    WHERE CODOBIECT = V_REC.CODOBIECT)
      LOOP
        DELETE FROM PRETMAMB WHERE CODPRETM = V_REC_PRETM.CODPRETM;
        DELETE FROM PRETM   WHERE CODPRETM = V_REC_PRETM.CODPRETM;
      END LOOP;

      DELETE FROM NARTCLI         WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM NARTOBJ1        WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM NARTOBJTRAD     WHERE CodObiect = V_REC.CodObiect;
      DELETE FROM DISCPROMORETAIL WHERE CodObiect = V_REC.CodObiect;
      DELETE FROM NARTOBJIMP      WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM NECHIV          WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM NARTAMB         WHERE CODOBIECT = V_REC.CODOBIECT OR CODOBIECTRETURN = V_REC.CODOBIECT;
      DELETE FROM NARTOPT         WHERE CODOBIECT = V_REC.CODOBIECT OR CODOBIECTOPT    = V_REC.CODOBIECT;
      DELETE FROM NARTOBJCOLET    WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM CODEXTALT       WHERE CODOBIECT = V_REC.CODOBIECT;
      DELETE FROM CODINTALT       WHERE CODOBIECT = V_REC.CODOBIECT;

      DELETE FROM DISCART DA
      WHERE (SELECT CR.PECLASE FROM CRITERIIDISC CR,  DISCOUNT DI WHERE DI.CODDISCOUNT = DA.CODDISCOUNT AND CR.CODCRITERIU = DI.CODCRITERIU) = 1
        AND CODOBIECT = V_REC.CODOBIECT;

      BEGIN --TABELA DINAMICA PT. LISTE CU VALORILE ANUMITOR ATRIBUTE
        EXECUTE IMMEDIATE &apos;DELETE FROM NARTOBJATR WHERE CODOBIECT = &apos;||V_REC.CODOBIECT;
      EXCEPTION
        WHEN OTHERS THEN NULL; -- PROBABIL NU EXISTA TABELA
      END;

      DELETE FROM NARTOBJ  WHERE CODOBIECT = V_REC.CODOBIECT;
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_NARTOBJ WHERE Coalesce(CodObiect,-1) &lt; 0 ORDER BY CodObiect ) LOOP
      SELECT  seq_NARTOBJ_CodObiect.Nextval into vCod from DUAL;

      UPDATE TMP_NARTOBJ1 SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NARTDIM  SET CodObiect = vCod WHERE Coalesce(CodObiect,0) = Coalesce(v_rec.CodObiect,0);

      -- traduceri denumiri
      UPDATE TMP_NARTOBJTRAD SET CodObiect = vCod WHERE CodObiect = v_Rec.CodObiect;


      UPDATE TMP_DISCPROMORETAIL SET CodObiect = vCod WHERE CodObiect = v_Rec.CodObiect;

      UPDATE TMP_NARTOBJIMP SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NATROBJ  SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_PRETM    SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_DISCART  SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NARTCLI  SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NARTAMB  SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NARTOPT  SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NECHIV   SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_NARTOBJSUBUNIT SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;

      UPDATE TMP_NARTOBJCOLET SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;

      UPDATE TMP_CODEXTALT SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
      UPDATE TMP_CODINTALT SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;

      INSERT INTO NARTOBJ (
        CodObiect, CodArticol,CodExtern,CodIntern, StocMin,StocMed, INACTIVCMDONLINE, AUTORIZATIE,EXPIRAREAUTORIZ, TRADUCARTGENERIC, MESAJINACTIV, StocMax,
        Masa,Volum,CodProducator,CodVamal,Returnabil,LuniGarantie,Obs,TARAORIGINE,
        ZILEVALABIL, ZILEDISTRIB, CODPERISABIL,ProcAdaosNir,Rotunjire, UMAmbalare, PRETMINIM,
        TERMENPLATA, DATAADAUGARII, CODPLU, USESTOCMED, NEFACTURABIL, GREUTSPECIFICA, BLOCAT,
        DURMAXAPROV, CODCNAS, CODCARACT, CODD394, INACTIV, FARACMDFURN, FARANIVELAPROB, DESCARCAREINTEGRALA, FARASTOC, CODCATEGARTTI,
        AdaosExceptie, Promotie, DiscPromo, ROTVALUTA, PRODUSPROPRIU,
        DENUMIRE,
        COEFCNAS, RAPCNAS, ANTIBIOTIC, EXPORTEMCS, CODNC, CODCPV, EXCLUSLISTARECM, CODACCIZABIL,
        LANSIMP,
        EXPORTKLG, CODANALIZANOD, SAFT_EXPORT, CANTVANZ, CERTIF_DDS )
      VALUES (
        vCod, v_Rec.CodArticol, v_Rec.CodExtern, v_Rec.CodIntern, v_Rec.StocMin, v_Rec.StocMed, V_REC.INACTIVCMDONLINE, v_rec.AUTORIZATIE,v_rec.EXPIRAREAUTORIZ,V_REC.TRADUCARTGENERIC, V_REC.MESAJINACTIV, v_Rec.StocMax,
        v_Rec.Masa, v_Rec.Volum, v_Rec.CodProducator, v_Rec.CodVamal, v_Rec.Returnabil, v_Rec.LuniGarantie, v_Rec.Obs, v_Rec.TARAORIGINE,
        v_rec.ZILEVALABIL, v_rec.ZILEDISTRIB,  V_REC.CODPERISABIL, v_Rec.ProcAdaosNir, v_Rec.Rotunjire, V_REC.UMAmbalare, V_REC.PRETMINIM,
        V_REC.TERMENPLATA, V_REC.DATAADAUGARII, V_REC.CODPLU, V_REC.USESTOCMED, v_rec.NEFACTURABIL, v_rec.GREUTSPECIFICA, V_REC.BLOCAT,
        V_REC.DURMAXAPROV, V_REC.CODCNAS, V_REC.CODCARACT, v_rec.CODD394, V_REC.INACTIV, V_REC.FARACMDFURN, V_REC.FARANIVELAPROB,  V_REC.DESCARCAREINTEGRALA, V_REC.FARASTOC, V_REC.CODCATEGARTTI,
        v_Rec.AdaosExceptie, v_Rec.Promotie, v_rec.discpromo, V_REC.ROTVALUTA, v_rec.PRODUSPROPRIU,
        CASE
          WHEN (SELECT COUNT(*) FROM TMP_NATROBJ WHERE CODOBIECT = VCOD) &gt; 0 THEN aDENARTICOL || &apos; &apos; || V_REC.DENOBIECT
          ELSE aDENARTICOL
        END,
        V_REC.COEFCNAS, V_REC.RAPCNAS, V_REC.ANTIBIOTIC, V_REC.EXPORTEMCS, V_REC.CODNC, V_REC.CODCPV, V_REC.EXCLUSLISTARECM, V_REC.CODACCIZABIL,
        CASE
           WHEN
             COALESCE(V_REC.PRODUSPROPRIU,0) = 0 THEN 0
            ELSE
              V_REC.LANSIMP
        END,
        V_REC.EXPORTKLG, V_REC.CODANALIZANOD, V_REC.SAFT_EXPORT, V_REC.CANTVANZ, V_REC.CERTIF_DDS
       );

        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NARTOBJ&apos;, VCOD, V_REC.CODOBIECT);


      if aCheck = &apos;1&apos; then CHECKMODIFPRETRETAIL(vCod); end if;
      if aMemo = &apos;1&apos; then MEMOMODIPRET(vCod); end if;
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_NARTOBJ where CodObiect &gt; 0 ORDER BY CodObiect ) LOOP
      UPDATE NARTOBJ
      SET
        CodArticol       = RecId ,
        CodExtern        = v_rec.CodExtern,
        CodIntern        = v_rec.CodIntern,
        StocMin          = v_rec.StocMin,
        StocMed          = v_rec.StocMed,
        INACTIVCMDONLINE = V_REC.INACTIVCMDONLINE,
        AUTORIZATIE      = v_rec.AUTORIZATIE,
        EXPIRAREAUTORIZ  = v_rec.EXPIRAREAUTORIZ,
        TRADUCARTGENERIC = V_REC.TRADUCARTGENERIC,
        MESAJINACTIV     = V_REC.MESAJINACTIV,
        StocMax          = v_rec.StocMax,
        Masa             = v_rec.Masa,
        Volum            = v_rec.Volum,
        CodProducator    = v_rec.CodProducator,
        CodVamal         = v_rec.CodVamal,
        Returnabil       = v_rec.Returnabil,
        LuniGarantie     = v_rec.LuniGarantie,
        Obs              = v_rec.Obs,
        TARAORIGINE      = v_rec.TARAORIGINE,
        ZILEVALABIL      = v_rec.ZILEVALABIL,
        ZILEDISTRIB      = v_rec.ZILEDISTRIB,
        CODPERISABIL     = V_REC.CODPERISABIL,
        ProcAdaosNir     = v_rec.ProcAdaosNir,
        Rotunjire        = v_rec.Rotunjire,
        UMAmbalare       = v_rec.UMAmbalare,
        PRETMINIM        = V_REC.PRETMINIM,
        TERMENPLATA      = V_REC.TERMENPLATA,
        DATAADAUGARII    = V_REC.DATAADAUGARII,
        CODPLU           = V_REC.CODPLU,
        USESTOCMED       = V_REC.USESTOCMED,
        NEFACTURABIL     = v_rec.NEFACTURABIL,
        GREUTSPECIFICA   = v_rec.GREUTSPECIFICA,
        BLOCAT           = V_REC.BLOCAT,
        DURMAXAPROV      = V_REC.DURMAXAPROV,
        CODCNAS          = V_REC.CODCNAS,
        CODCARACT        = V_REC.CODCARACT,
        CODD394          = v_rec.CODD394,
        INACTIV          = V_REC.INACTIV,
        FARACMDFURN      = V_REC.FARACMDFURN,
        FARANIVELAPROB   = V_REC.FARANIVELAPROB,
        DESCARCAREINTEGRALA = V_REC.DESCARCAREINTEGRALA,
        FARASTOC         = V_REC.FARASTOC,
        CODCATEGARTTI    = V_REC.CODCATEGARTTI,
        ROTVALUTA        = v_rec.ROTVALUTA,
        PRODUSPROPRIU    = v_rec.PRODUSPROPRIU,
        DENUMIRE         =
        CASE
          WHEN (SELECT COUNT(*) FROM TMP_NATROBJ WHERE CODOBIECT = V_REC.CODOBIECT) &gt; 0 THEN aDENARTICOL || &apos; &apos; || V_REC.DENOBIECT
          ELSE aDENARTICOL
        END,
        AdaosExceptie    = v_rec.AdaosExceptie,
        Promotie         = v_rec.Promotie,
        DiscPromo        = v_rec.discpromo,
        COEFCNAS         = v_rec.COEFCNAS,
        RAPCNAS          = v_rec.RAPCNAS,
        ANTIBIOTIC       = v_rec.ANTIBIOTIC,
        CERTIF_DDS       = v_rec.CERTIF_DDS,
        EXPORTEMCS       = V_REC.EXPORTEMCS,
        CODNC            = V_REC.CODNC,
        CODCPV           = V_REC.CODCPV,
        EXCLUSLISTARECM  = v_rec.EXCLUSLISTARECM,
        CODACCIZABIL     = V_REC.CODACCIZABIL,
        LANSIMP          = CASE WHEN COALESCE(V_REC.PRODUSPROPRIU,0) = 0 THEN 0 ELSE V_REC.LANSIMP END,
        EXPORTKLG        = V_REC.EXPORTKLG,
        CODANALIZANOD    = V_REC.CODANALIZANOD,
        SAFT_EXPORT      = V_REC.SAFT_EXPORT,
        CANTVANZ         = V_REC.CANTVANZ
      WHERE CodObiect = v_rec.CodObiect;

      if aCheck = &apos;1&apos; then CHECKMODIFPRETRETAIL(v_rec.CodObiect); end if;
      if aMemo = &apos;1&apos; then MEMOMODIPRET(v_rec.CodObiect); end if;
    END LOOP;

  DELETE FROM NARTOBJSUBUNIT S WHERE CODS IN (SELECT CODS FROM TMP_NARTOBJSUBUNIT_INI) AND CODS NOT IN (SELECT CODS FROM TMP_NARTOBJSUBUNIT);

  FOR V_REC IN (SELECT * FROM TMP_NARTOBJSUBUNIT) LOOP
    IF V_REC.CODS &lt; 0 THEN
      INSERT INTO NARTOBJSUBUNIT (CODS, CODOBIECT, SUBUNITATE, STOCMIN, STOCMAX, STOCMED, PROCSTOCMIN, PROCSTOCMAX, PROCSTOCMED, CODGEST )
      VALUES (SEQ_NARTOBJSUBUNIT_CODS.NEXTVAL, V_REC.CODOBIECT, V_REC.SUBUNITATE, V_REC.STOCMIN, V_REC.STOCMAX, V_REC.STOCMED
              , V_REC.PROCSTOCMIN, V_REC.PROCSTOCMAX, V_REC.PROCSTOCMED, V_REC.CODGEST );
    ELSE
      UPDATE NARTOBJSUBUNIT
      SET
        STOCMIN = V_REC.STOCMIN,
        STOCMAX = V_REC.STOCMAX,
        STOCMED = V_REC.STOCMED,
        PROCSTOCMIN = V_REC.PROCSTOCMIN,
        PROCSTOCMAX = V_REC.PROCSTOCMAX,
        PROCSTOCMED = V_REC.PROCSTOCMED,
        CODGEST = V_REC.CODGEST
      WHERE
        CODS = V_REC.CODS;
    END IF;
  END LOOP;

  DELETE FROM NARTOBJ1 O1
  WHERE     EXISTS (SELECT CODOBIECT  FROM NARTOBJ      WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
    AND NOT EXISTS (SELECT CODOBIECT1 FROM TMP_NARTOBJ1 WHERE CODOBIECT1 = O1.CODOBIECT1);

  -- traduceri denumiri
  DELETE FROM NARTOBJTRAD O1
  WHERE     EXISTS (SELECT CodObiect     FROM NArtObj WHERE CodArticol = RecId AND CodObiect = O1.CodObiect)
    AND NOT EXISTS (Select CodObiectTrad FROM TMP_NARTOBJTRAD WHERE CodObiectTrad = O1.CodObiectTrad);


  DELETE FROM NARTOBJIMP O1
  WHERE     EXISTS (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
    AND NOT EXISTS (SELECT CODOBJIMP FROM TMP_NARTOBJIMP WHERE CODOBJIMP = O1.CODOBJIMP);

  DELETE FROM DISCPROMORETAIL O1
  WHERE     EXISTS (SELECT CodObiect FROM NArtObj WHERE CodArticol = RecId AND CodObiect = O1.CodObiect)
    AND NOT EXISTS (Select COD       FROM TMP_DISCPROMORETAIL WHERE Cod = O1.Cod);

  DELETE FROM NARTOBJCOLET O1
  WHERE
    EXISTS (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
    AND NOT EXISTS (SELECT CODOBJCOLET FROM TMP_NARTOBJCOLET WHERE CODOBJCOLET = O1.CODOBJCOLET);
--  CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID)AND
--  CODOBJCOLET NOT IN (SELECT CODOBJCOLET FROM TMP_NARTOBJCOLET);

  DELETE FROM CODEXTALT O1
  WHERE
    EXISTS (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
    AND NOT EXISTS (SELECT COD FROM TMP_CODEXTALT WHERE COD = O1.COD);
--  CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID)AND
--  COD NOT IN (SELECT COD FROM TMP_CODEXTALT);

  DELETE FROM CODINTALT O1
  WHERE
    EXISTS (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
    AND NOT EXISTS (SELECT COD FROM TMP_CODINTALT WHERE COD = O1.COD);
--  CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID)AND
--  COD NOT IN (SELECT COD FROM TMP_CODINTALT);

-- Detail NARTOBJ1
    FOR v_rec IN ( SELECT * FROM TMP_NARTOBJ1 ORDER BY CodObiect1 ) LOOP
      IF v_Rec.CodObiect1 &lt; 0 THEN
        BEGIN
          INSERT INTO NARTOBJ1 (
            CodObiect1, CodObiect,PretMaximal, ProcAdaosMaximal, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA, uplift, codmoneda, AdaosLa,
            PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
            anstart, lunastart, tippret, ValMat, ValMan, ValRegie, D390Exclus, Cost, Cantservauto, proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate,
            sistave, refractie, indice_w, toxina_don, boabe_toxice,
            MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
            MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
            MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
            MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
            MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
            PRETPROD)
          VALUES (
            seq_NARTOBJ1_CodObiect1.Nextval ,v_rec.CodObiect, v_Rec.PretMaximal, v_Rec.ProcAdaosMaximal, V_REC.PRETREFERINTA, V_REC.TIPPRETMAX, V_REC.COMPENSAT, V_REC.TIPCOMPENSARE, V_REC.GRUPA, v_rec.uplift, v_rec.codmoneda, v_Rec.AdaosLa,
            v_Rec.PUNCTE, v_Rec.Umiditate, v_Rec.CORPURI_STRAINE, v_Rec.PUNCTESECTIE, v_Rec.Incoltit, v_Rec.Hectolitrica, v_Rec.Gluten, v_Rec.Fuzaritate, v_Rec.Cadere, v_Rec.Deformare, v_Rec.Sticlozitate, v_Rec.Sparturi,
            v_Rec.anstart, v_Rec.lunastart, v_rec.tippret, v_rec.ValMat, v_rec.ValMan, v_rec.ValRegie, v_rec.D390Exclus, v_rec.cost, v_rec.Cantservauto, v_Rec.proteina, v_Rec.aflatoxina, v_Rec.atac_plosnita, v_Rec.continut_ulei, v_Rec.aciditate,
            v_Rec.sistave, v_Rec.refractie, v_Rec.indice_w, v_Rec.toxina_don, v_Rec.boabe_toxice,
            v_Rec.MAX_UMIDITATE,v_Rec.MAX_CORPURI_STRAINE,v_Rec.MAX_INCOLTIT,v_Rec.MAX_HECTOLITRICA,v_Rec.MAX_GLUTEN,v_Rec.MAX_FUZARITATE,v_Rec.MAX_CADERE,v_Rec.MAX_DEFORMARE,
            v_Rec.MAX_STICLOZITATE,v_Rec.MAX_SPARTURI,v_Rec.MAX_PROTEINA,v_Rec.MAX_AFLATOXINA,v_Rec.MAX_ATAC_PLOSNITA,v_Rec.MAX_CONTINUT_ULEI,v_Rec.MAX_ACIDITATE,v_Rec.MAX_SISTAVE,
            v_Rec.MAX_REFRACTIE,v_Rec.MAX_INDICE_W,v_Rec.MAX_TOXINA_DON,v_Rec.MAX_BOABE_TOXICE,
            v_Rec.MIN_UMIDITATE,v_Rec.MIN_CORPURI_STRAINE,v_Rec.MIN_INCOLTIT,v_Rec.MIN_HECTOLITRICA,v_Rec.MIN_GLUTEN,v_Rec.MIN_FUZARITATE,v_Rec.MIN_CADERE,v_Rec.MIN_DEFORMARE,v_Rec.MIN_STICLOZITATE,v_Rec.MIN_SPARTURI,
            v_Rec.MIN_PROTEINA,v_Rec.MIN_AFLATOXINA,v_Rec.MIN_ATAC_PLOSNITA,v_Rec.MIN_CONTINUT_ULEI,v_Rec.MIN_ACIDITATE,v_Rec.MIN_SISTAVE,v_Rec.MIN_REFRACTIE,v_Rec.MIN_INDICE_W,v_Rec.MIN_TOXINA_DON,v_Rec.MIN_BOABE_TOXICE,
            V_REC.PRETPROD);
        END;
      ELSE
       BEGIN
         UPDATE NARTOBJ1
         SET
           CodObiect        = v_Rec.CodObiect,
           PretMaximal      = v_Rec.PretMaximal,
           ProcAdaosMaximal = v_Rec.ProcAdaosMaximal,
           PRETREFERINTA    = V_REC.PRETREFERINTA,
           TIPPRETMAX       = V_REC.TIPPRETMAX,
           COMPENSAT        = V_REC.COMPENSAT,
           TIPCOMPENSARE    = V_REC.TIPCOMPENSARE,
           GRUPA            = V_REC.GRUPA,
           uplift           = v_rec.uplift,
           PUNCTE           = v_Rec.PUNCTE         ,
           Umiditate        = v_Rec.Umiditate      ,
           CORPURI_STRAINE  = v_Rec.CORPURI_STRAINE,
           PUNCTESECTIE     = v_Rec.PUNCTESECTIE   ,
           Incoltit         = V_REC.Incoltit       ,
           Hectolitrica     = V_REC.Hectolitrica   ,
           Gluten           = V_REC.Gluten         ,
           Fuzaritate       = V_REC.Fuzaritate     ,
           Cadere           = V_REC.Cadere         ,
           Deformare        = v_rec.Deformare      ,
           Sticlozitate     = V_REC.Sticlozitate   ,
           Sparturi         = V_REC.Sparturi       ,
           codmoneda        = v_rec.codmoneda,
           AdaosLa          = v_Rec.AdaosLA,
           Anstart          = v_Rec.AnStart,
           lunastart        = v_Rec.LunaStart,
           tippret          = v_rec.tippret,
           ValMat           = v_rec.ValMat,
           ValMan           = v_rec.ValMan,
           ValRegie         = v_rec.ValRegie,
           D390Exclus       = v_rec.D390Exclus,
           Cost             = v_rec.Cost,
           CantServAuto     = v_rec.CantServAuto,
           proteina         = v_rec.proteina     ,
           aflatoxina       = v_rec.aflatoxina   ,
           atac_plosnita    = v_rec.atac_plosnita,
           continut_ulei    = v_rec.continut_ulei,
           aciditate        = v_rec.aciditate,
           sistave          = v_rec.sistave,
           refractie        = v_rec.refractie,
           indice_w         = v_rec.indice_w,
           toxina_don       = v_rec.toxina_don,
           boabe_toxice     = v_rec.boabe_toxice,
           MAX_UMIDITATE       = v_rec.MAX_UMIDITATE       ,
           MAX_CORPURI_STRAINE = v_rec.MAX_CORPURI_STRAINE ,
           MAX_INCOLTIT        = v_rec.MAX_INCOLTIT        ,
           MAX_HECTOLITRICA    = v_rec.MAX_HECTOLITRICA    ,
           MAX_GLUTEN          = v_rec.MAX_GLUTEN          ,
           MAX_FUZARITATE      = v_rec.MAX_FUZARITATE      ,
           MAX_CADERE          = v_rec.MAX_CADERE          ,
           MAX_DEFORMARE       = v_rec.MAX_DEFORMARE       ,
           MAX_STICLOZITATE    = v_rec.MAX_STICLOZITATE    ,
           MAX_SPARTURI        = v_rec.MAX_SPARTURI        ,
           MAX_PROTEINA        = v_rec.MAX_PROTEINA        ,
           MAX_AFLATOXINA      = v_rec.MAX_AFLATOXINA      ,
           MAX_ATAC_PLOSNITA   = v_rec.MAX_ATAC_PLOSNITA   ,
           MAX_CONTINUT_ULEI   = v_rec.MAX_CONTINUT_ULEI   ,
           MAX_ACIDITATE       = v_rec.MAX_ACIDITATE       ,
           MAX_SISTAVE         = v_rec.MAX_SISTAVE         ,
           MAX_REFRACTIE       = v_rec.MAX_REFRACTIE       ,
           MAX_INDICE_W        = v_rec.MAX_INDICE_W        ,
           MAX_TOXINA_DON      = v_rec.MAX_TOXINA_DON      ,
           MAX_BOABE_TOXICE    = v_rec.MAX_BOABE_TOXICE    ,
           MIN_UMIDITATE       = v_rec.MIN_UMIDITATE       ,
           MIN_CORPURI_STRAINE = v_rec.MIN_CORPURI_STRAINE ,
           MIN_INCOLTIT        = v_rec.MIN_INCOLTIT        ,
           MIN_HECTOLITRICA    = v_rec.MIN_HECTOLITRICA    ,
           MIN_GLUTEN          = v_rec.MIN_GLUTEN          ,
           MIN_FUZARITATE      = v_rec.MIN_FUZARITATE      ,
           MIN_CADERE          = v_rec.MIN_CADERE          ,
           MIN_DEFORMARE       = v_rec.MIN_DEFORMARE       ,
           MIN_STICLOZITATE    = v_rec.MIN_STICLOZITATE    ,
           MIN_SPARTURI        = v_rec.MIN_SPARTURI        ,
           MIN_PROTEINA        = v_rec.MIN_PROTEINA        ,
           MIN_AFLATOXINA      = v_rec.MIN_AFLATOXINA      ,
           MIN_ATAC_PLOSNITA   = v_rec.MIN_ATAC_PLOSNITA   ,
           MIN_CONTINUT_ULEI   = v_rec.MIN_CONTINUT_ULEI   ,
           MIN_ACIDITATE       = v_rec.MIN_ACIDITATE       ,
           MIN_SISTAVE         = v_rec.MIN_SISTAVE         ,
           MIN_REFRACTIE       = v_rec.MIN_REFRACTIE       ,
           MIN_INDICE_W        = v_rec.MIN_INDICE_W        ,
           MIN_TOXINA_DON      = v_rec.MIN_TOXINA_DON      ,
           MIN_BOABE_TOXICE    = v_rec.MIN_BOABE_TOXICE    ,
           PretProd            = v_Rec.PretProd
         WHERE CodObiect1 = v_rec.CodObiect1;
       END;
      END IF;
    END LOOP;

    -- traduceri denumiri
    FOR v_rec IN (SELECT * FROM TMP_NARTOBJTRAD ORDER BY CodObiectTrad)
    LOOP
      IF v_Rec.CodObiectTrad &lt; 0 THEN
        INSERT INTO NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, descriere)
        VALUES (SEQ_NARTOBJTRAD_CodObiectTrad.NextVal ,v_rec.CodObiect, v_rec.CodLimba, v_rec.DenumireTrad, v_rec.Avertizare, v_rec.descriere);
      ELSE
        UPDATE NARTOBJTRAD
        SET
          CodObiect    = v_rec.CodObiect,
          CodLimba     = v_rec.CodLimba,
          DenumireTrad = v_rec.DenumireTrad,
          descriere    = v_rec.descriere,
					Avertizare   = v_rec.Avertizare
        WHERE
          CodObiectTrad = v_rec.CodObiectTrad;
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_DISCPROMORETAIL )
    LOOP
      IF (Coalesce(v_Rec.Cod, 0) &lt; 0) THEN
        INSERT INTO DISCPROMORETAIL(COD, CODPOSTRETAIL, CODOBIECT, DISCPROMO)
        VALUES (SEQ_DISCPROMORETAIL_COD.NEXTVAL, V_REC.CODPOSTRETAIL, V_REC.CODOBIECT, V_REC.DISCPROMO);
      ELSE
        UPDATE DISCPROMORETAIL
        SET
          CodObiect      = v_rec.CodObiect,
          CodPOSTRETAIL  = v_rec.CODPOSTRETAIL,
          DISCPROMO      = v_rec.DISCPROMO
        WHERE
          Coalesce(Cod, 0) = Coalesce(v_rec.Cod, 0);
      END IF;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_CODEXTALT)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO CODEXTALT(COD, CODOBIECT, CODEXTERN, CODPART)
        VALUES (SEQ_CODEXTALT_COD.NEXTVAL, V_REC.CODOBIECT, V_REC.CODEXTERN, V_REC.CODPART);
      ELSE
        UPDATE CODEXTALT
        SET CODEXTERN = V_REC.CODEXTERN,
            CODPART = V_REC.CODPART
        WHERE COD = V_REC.COD;
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_CODINTALT)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO CODINTALT(COD, CODOBIECT, CODINTERN, CODPART)
        VALUES (SEQ_CODINTALT_COD.NEXTVAL, V_REC.CODOBIECT, V_REC.CODINTERN, V_REC.CODPART);
      ELSE
        UPDATE CODINTALT
        SET CODINTERN = V_REC.CODINTERN,
            CODPART = V_REC.CODPART
        WHERE COD = V_REC.COD;
      END IF;
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_NARTOBJCOLET ORDER BY CodObiect, INDEXLOCAL ) LOOP
      IF (Coalesce(v_Rec.CODOBJCOLET, 0) &lt; 0 ) THEN
        BEGIN
          INSERT INTO NARTOBJCOLET (CODOBJCOLET, CODOBIECT, INDEXLOCAL, CONTINUT, IDCOLET, D1, D2, D3 )
          VALUES (seq_NARTOBJCOLET_Cod.Nextval,
                  v_rec.CodObiect,
                  v_Rec.IndexLocal,
                  V_REC.CONTINUT,
                  DECODE(Coalesce(V_REC.IDCOLET, &apos;0&apos;), &apos;0&apos;, TRIM(TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;0000000009&apos;)), V_REC.IDCOLET),
--                  DECODE(Coalesce(V_REC.IDCOLET, 0), 0, TRIM(TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;0000000009&apos;)), V_REC.IDCOLET),
                  V_REC.D1,
                  V_REC.D2,
                  V_REC.D3
                  );
        END;
      ELSE
        BEGIN
          UPDATE NARTOBJCOLET
          SET INDEXLOCAL = V_REC.INDEXLOCAL,
              CONTINUT   = V_REC.CONTINUT,
              IDCOLET    = V_REC.IDCOLET,
              D1         = V_REC.D1,
              D2         = V_REC.D2,
              D3         = V_REC.D3
          WHERE Coalesce(CodOBJCOLET, 0) = Coalesce(v_rec.CODOBJCOLET, 0);
        END;
      END IF;
    END LOOP;

-- detail DISCART

   FOR V_REC IN
   (SELECT DA.CodDiscArt
     FROM
       DISCART DA,
       DISCOUNT D,
       CRITERIIDISC CR
     WHERE
      (D.CODDISCOUNT = DA.CODDISCOUNT)AND
      (CR.CODCRITERIU = D.CODCRITERIU)AND
      (CR.PECLASE = 0)AND(DA.CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ))
    )
    LOOP
      DELETE FROM DISCART WHERE CODDISCART = V_REC.CODDISCART AND CODDISCART NOT IN (SELECT CODDISCART FROM TMP_DISCART);
    END LOOP;

    INSERT INTO DISCART(CODDISCART, CODDISCOUNT, CODOBIECT, GRUPA)
    SELECT SEQ_DISCART_CODDISCART.NEXTVAL, CODDISCOUNT, CODOBIECT, GRUPA FROM TMP_DISCART WHERE CODDISCART &lt; 0;


-- Detail NARTCLI
    DELETE FROM NARTCLI O1
    WHERE
      EXISTS (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID AND CODOBIECT = O1.CODOBIECT)
      AND NOT EXISTS (SELECT CODARTCLI FROM TMP_NARTCLI WHERE CODARTCLI = O1.CODARTCLI);

--    CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID)AND
--    CODARTCLI NOT IN (SELECT CODARTCLI FROM TMP_NARTCLI);


    FOR v_rec IN ( SELECT * FROM TMP_NARTCLI ORDER BY CodArtCli ) LOOP
      IF (Coalesce(v_Rec.CodArtCli,0) &lt; 0 ) THEN
        BEGIN
          INSERT INTO NARTCLI (
            CodArtCli, CodObiect, CodPart, Denumire, CodExtern, UMSec, UMCorelat, CODMONEDA, PRET, tipcodafisat, CodLaClient,
            CODINTERN, IMPLICIT, CODCLASEP, CODGAMA, OBS,
            OBS2, UMSECIMPDOC, Duratatr, Zilestoc, GLN, IDspecific)
          VALUES (
            seq_NARTCLI_CodArtCli.Nextval ,v_rec.CodObiect, v_Rec.CodPart ,v_Rec.Denumire ,v_Rec.CodExtern, v_Rec.UMSec , v_rec.UMCorelat, v_Rec.CODMONEDA,  v_Rec.PRET, v_Rec.tipcodafisat, v_rec.CodLaClient,
            v_rec.codintern, v_rec.IMPLICIT, V_REC.CODCLASEP, V_REC.CODGAMA, V_REC.OBS,
            V_REC.OBS2, V_REC.UMSECIMPDOC, v_rec.duratatr, v_rec.zilestoc, v_rec.GLN, v_rec.IDspecific);
        END;
      ELSE
       BEGIN
         UPDATE NARTCLI
         SET
           CodObiect        = v_Rec.CodObiect,
           CodPart          = v_Rec.CodPart,
           Denumire         = v_Rec.Denumire,
           CodExtern        = v_Rec.CodExtern,
           UMSec            = v_Rec.UMSec,
           UMCorelat        = v_Rec.UMCorelat,
           CODMONEDA        = v_Rec.CODMONEDA,
           PRET             = v_Rec.PRET,
           tipcodafisat     = v_Rec.tipcodafisat,
           CodLaClient      = v_Rec.CodLaClient,
           CodIntern        = v_rec.Codintern,
           CODCLASEP        = V_REC.CODCLASEP,
           CODGAMA          = V_REC.CODGAMA,
           OBS              = V_REC.OBS,
           OBS2             = V_REC.OBS2,
           UMSECIMPDOC      = V_REC.UMSECIMPDOC,
           IMPLICIT         = v_Rec.IMPLICIT,
           DURATATR         = V_REC.DURATATR,
           ZILESTOC         = V_REC.ZILESTOC,
           GLN              = V_REC.GLN,
           IDspecific       = V_REC.IDspecific
         WHERE Coalesce(CodArtCli, 0) = Coalesce(v_rec.CodArtCli, 0);
       END;
      END IF;
    END LOOP;

-- Detail PRETM, PRETMAMB
    FOR V_REC IN
    (
      SELECT * FROM PRETM PM
      WHERE
        CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ)
        AND Coalesce(PM.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, Coalesce(PM.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
        AND CODPRETM NOT IN (SELECT CODPRETM FROM TMP_PRETM)
    )
    LOOP
      DELETE FROM PRETMAMB WHERE CODPRETM = V_REC.CODPRETM;
      DELETE FROM PRETM    WHERE CODPRETM = V_REC.CODPRETM;
    END LOOP;


    DELETE FROM PRETMAMB PMAMB
    WHERE
        EXISTS (SELECT * FROM TMP_PRETM WHERE CODPRETM = PMAMB.CODPRETM)
    AND NOT EXISTS (SELECT * FROM TMP_PRETMAMB WHERE CODPRETMAMB = PMAMB.CODPRETMAMB);

    aCODOBIECT := 0; aINDEXLOCAL := 0;
    FOR V_REC IN ( SELECT * FROM TMP_PRETM ORDER BY CODOBIECT, INDEXLOCAL ) LOOP
      IF aCODOBIECT &lt;&gt; V_REC.CODOBIECT THEN
        aCODOBIECT  := V_REC.CODOBIECT;
        aINDEXLOCAL := 0;
      END IF;

     aINDEXLOCAL := aINDEXLOCAL + 1;
      IF Coalesce(V_REC.CODPRETM, 0) &lt; 0  THEN
        BEGIN

          SELECT SEQ_PRETM_CODPRETM.NEXTVAL INTO aCODPRETM FROM DUAL;
          UPDATE TMP_PRETMAMB
          SET
            CODPRETM = aCODPRETM
          WHERE
            CODPRETM = V_REC.CODPRETM;


          INSERT INTO PRETM (CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, IMPLICIT, GRUPA, MONEDA, PROC, INDEXLOCAL, SUBUNITATEA,ROTUNJIRE, SUMAFIXAIMPLICIT)
          VALUES (aCODPRETM , V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.LEI, V_REC.VALUTA, V_REC.IMPLICIT, V_REC.GRUPA, V_REC.MONEDA, V_REC.PROC,
          CASE
            WHEN PKG_GLOBALS.SUBUNITATE &lt;&gt; 1 THEN aINDEXLOCAL
            ELSE V_REC.INDEXLOCAL
          END,
          V_REC.SUBUNITATEA, V_REC.ROTUNJIRE, V_REC.SUMAFIXAIMPLICIT
          );
        END;
      ELSE
        BEGIN
          UPDATE PRETM
          SET
            CODOBIECT   = V_REC.CODOBIECT,
            CODCATPRET  = V_REC.CODCATPRET,
            LEI         = V_REC.LEI,
            VALUTA      = V_REC.VALUTA,
            IMPLICIT    = V_REC.IMPLICIT,
            GRUPA       = V_REC.GRUPA,
            MONEDA      = V_REC.MONEDA,
            PROC        = V_REC.PROC,
            INDEXLOCAL  =  CASE
                             WHEN PKG_GLOBALS.SUBUNITATE &lt;&gt; 1 THEN aINDEXLOCAL
                             ELSE V_REC.INDEXLOCAL
                           END,

            SUBUNITATEA     = V_REC.SUBUNITATEA,
            ROTUNJIRE        = V_REC.ROTUNJIRE,
            SUMAFIXAIMPLICIT =V_REC.SUMAFIXAIMPLICIT
          WHERE CODPRETM = V_REC.CODPRETM;
        END;
      END IF;
    END LOOP;


    DELETE FROM NArtDim WHERE ( CodArticol = RecId AND CodArtDim NOT IN ( SELECT CodArtDim FROM TMP_NArtDim WHERE Coalesce(CodArtDim,0) &gt; 0));

    FOR v_rec IN ( SELECT * FROM TMP_NArtDim WHERE CodArtDim &lt; 0 and Coalesce(D1, 0) + Coalesce(D2, 0) + Coalesce(D3, 0) &gt;0 ORDER BY CodArtDim ) LOOP
      SELECT seq_NArtDim_CodArtDim.Nextval INTO vCod FROM DUAL;
      INSERT INTO NArtDim ( CodArtDim,CodObiect,CodArticol, Tip, D1, D2, D3 )
      values (vCod , v_rec.CodObiect,RecId , v_Rec.Tip, v_Rec.D1, v_Rec.D2, v_Rec.D3);
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_NArtDim WHERE Coalesce(CodArtDim,-1) &gt; 0  and Coalesce(D1, 0) + Coalesce(D2, 0) + Coalesce(D3, 0) &gt; 0 ORDER BY CodArtDim ) LOOP
      UPDATE NArtDim SET
        CodArticol  = RecId ,
        Tip = v_rec.Tip,
        D1  = v_rec.D1 ,
        D2  = v_rec.D2 ,
        D3  = v_rec.D3
      WHERE CodArtDim = v_rec.CodArtDim;
    END LOOP;

    -- Detail NArtDim musai inainte de NATROBJ
    DELETE FROM NARTATR WHERE ( CodArticol = RecId AND CodArtAtr NOT IN ( SELECT CodArtAtr FROM TMP_NARTATR WHERE Coalesce(CodArtAtr,0) &lt;&gt; 0));

    FOR v_rec IN ( SELECT * FROM TMP_NARTATR WHERE CodArtAtr &lt; 0 ORDER BY CodArtAtr ) LOOP
      SELECT seq_NARTATR_CodArtAtr.Nextval INTO vCod FROM DUAL;
      INSERT INTO NARTATR ( CodArtAtr,CodArticol, CodAtribut,Activ,CodValPredef,Obligatoriu, OBS, Selectie,Facturabil, INDEXLOCAL )
      values (vCod , RecId , v_Rec.CodAtribut, v_Rec.Activ, v_Rec.CodValPredef, v_Rec.Obligatoriu, V_REC.OBS, v_Rec.Selectie, v_Rec.Facturabil, V_REC.INDEXLOCAL);
      UPDATE TMP_NATROBJ SET CODARTATR = vCod where CODARTATR = v_Rec.CODARTATR;
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_NARTATR WHERE Coalesce(CodArtAtr,-1) &gt; 0 ORDER BY CodArtAtr ) LOOP
      UPDATE NARTATR SET
        CodArticol   = RecId ,
        CodAtribut   = v_rec.CodAtribut,
        Activ        = v_rec.Activ,
        CodValPredef = v_rec.CodValPredef,
        Obligatoriu  = v_rec.Obligatoriu,
        OBS          = V_REC.OBS,
        Selectie     = v_rec.Selectie,
        Facturabil   = v_rec.Facturabil,
        INDEXLOCAL   = v_rec.Indexlocal
      WHERE CodArtAtr = v_rec.CodArtAtr;
    END LOOP;

  --Detail NATROBJ
  --STERGEREA rezolvata mai sus la stergere din master
  FOR V_REC IN (SELECT AO.* FROM NATROBJ AO, NARTOBJ O WHERE  AO.CODOBIECT = O.CODOBIECT AND O.CODARTICOL = RECID AND AO.CODATROBJ NOT IN (SELECT CODATROBJ FROM TMP_NATROBJ))
  LOOP
    DELETE FROM NATROBJ
    WHERE
      CODATROBJ = V_REC.CODATROBJ;
  END LOOP;


  FOR v_rec IN ( SELECT * FROM TMP_NARTOBJIMP) LOOP
    if v_rec.codobjimp &gt; 0 then
      UPDATE NARTOBJIMP SET
        CodObiect        = v_rec.CodObiect,
        CodSubunit       = v_rec.CodSubunit,
        GestImplicita    = v_rec.GestImplicita,
        LocatieImplicita = v_rec.LocatieImplicita,
        DurMaxAprov      = v_rec.DurMaxAprov,
        ContImplicit     = v_rec.ContImplicit
      WHERE CodObjImp = v_rec.CodObjImp;
    else
      insert into nartobjimp(codobjimp,codobiect,codsubunit,gestimplicita,locatieimplicita,durmaxaprov,contimplicit)
      values (seq_nartobjimp_codobjimp.nextval,v_rec.codobiect,v_rec.codsubunit,v_rec.gestimplicita,v_rec.locatieimplicita,v_rec.durmaxaprov,v_rec.contimplicit);
    end if;
  END LOOP;

  INSERT INTO NATROBJ( CodObiect,CodAtrOBJ,CodArtAtr,CodValAtr, INDEXLOCAL )
  SELECT CodObiect, seq_NATROBJ_CodAtrOBJ.Nextval,CodArtAtr,CodValAtr, INDEXLOCAL FROM TMP_NATROBJ WHERE CodAtrOBJ &lt; 0;

  FOR v_rec IN ( SELECT * FROM TMP_NATROBJ WHERE Coalesce(CodAtrOBJ,0) &gt; 0 ORDER BY CodAtrOBJ ) LOOP
     UPDATE NATROBJ SET CodObiect = v_rec.CodObiect,CodArtAtr = v_rec.CodArtAtr,CodValAtr = v_rec.CodValAtr, INDEXLOCAL = v_rec.INDEXLOCAL
     WHERE CodAtrOBJ = v_rec.CodAtrOBJ ;
  END LOOP;

-- NARTOPT
  DELETE FROM NARTOPT A
  WHERE
  CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID) AND
  NOT EXISTS (SELECT CODOPT FROM TMP_NARTOPT WHERE CODOPT = A.CODOPT);

  FOR V_REC IN (SELECT * FROM TMP_NARTOPT) LOOP
    IF V_REC.CODOPT &lt; 0 THEN
      SELECT SEQ_NARTOPT_CODOPT.NEXTVAL INTO ACODOPT FROM DUAL;
      INSERT INTO NARTOPT(CODOPT, CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, OBS)
      VALUES (ACODOPT, V_REC.CODOBIECT, V_REC.codobiectopt, V_REC.CodTipLocatie, V_REC.ForceLei, V_REC.CANT, V_REC.STANDARD, V_REC.OBS);
    ELSE
      UPDATE
        NARTOPT
      SET
        CODOBIECT       = V_REC.CODOBIECT,
        codobiectopt    = V_REC.codobiectopt,
        CodTipLocatie   = V_REC.CodTipLocatie,
        ForceLei        = V_REC.ForceLei,
        CANT            = V_REC.CANT,
        STANDARD        = V_REC.STANDARD,
        OBS             = V_REC.OBS
      WHERE
        CODOPT = V_REC.CODOPT;
    END IF;
  END LOOP;

-- NARTAMB
  DELETE FROM NARTAMB A
  WHERE
  CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID) AND
  NOT EXISTS (SELECT CODAMB FROM TMP_NARTAMB WHERE CODAMB = A.CODAMB);

  FOR V_REC IN (SELECT * FROM TMP_NARTAMB) LOOP
    IF V_REC.CODAMB &lt; 0 THEN

      SELECT SEQ_NARTAMB_CODAMB.NEXTVAL INTO ACODAMB FROM DUAL;

      UPDATE TMP_PRETMAMB
      SET
       CODAMB = aCODAMB
      WHERE
        CODAMB = V_REC.CODAMB;


      INSERT INTO NARTAMB(CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN, UMSEC, CODEXTERN,CODPLU, CODINTERN,
                                             MASA, LUNGIME, LATIME, INALTIME, LXLAT, LXH, LATXH, GREUTSPECIFICA, IMPLICITTIPDOC, TIP, NR_RANDURI, AdMax, returnabil)
      VALUES (ACODAMB, V_REC.CODOBIECT, V_REC.CODOBIECTRETURN, V_REC.CANT, V_REC.CANTMIN, V_REC.UMSEC, V_REC.CODEXTERN,
                       V_REC.CODPLU, V_REC.CODINTERN, V_REC.MASA, V_REC.LUNGIME, V_REC.LATIME, V_REC.INALTIME, V_REC.LXLAT,
                       V_REC.LXH, V_REC.LATXH, V_REC.GREUTSPECIFICA, V_REC.IMPLICITTIPDOC, V_REC.TIP, V_REC.NR_RANDURI, V_REC.AdMax, V_REC.returnabil);
    ELSE
      UPDATE
        NARTAMB
      SET
        CODOBIECT       = V_REC.CODOBIECT,
        CODOBIECTRETURN = V_REC.CODOBIECTRETURN,
        CANT            = V_REC.CANT,
        CANTMIN         = V_REC.CANTMIN,
        UMSEC           = V_REC.UMSEC,
        CODEXTERN       = V_REC.CODEXTERN,
        CODPLU          = V_REC.CODPLU,
        CODINTERN       = V_REC.CODINTERN,
        MASA            = V_REC.MASA,
        LUNGIME         = V_REC.LUNGIME,
        LATIME          = V_REC.LATIME,
        INALTIME        = V_REC.INALTIME,
        LXLAT           = V_REC.LXLAT,
        LXH             = V_REC.LXH,
        LATXH           = V_REC.LATXH,
        GREUTSPECIFICA  = V_REC.GREUTSPECIFICA,
        IMPLICITTIPDOC  = V_REC.IMPLICITTIPDOC,
        TIP             = V_REC.TIP,
        NR_RANDURI      = V_REC.NR_RANDURI,
        AdMax           = V_REC.AdMax,
        returnabil   = V_REC.returnabil
      WHERE
        CODAMB = V_REC.CODAMB;
    END IF;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_PRETMAMB)
  LOOP
    IF V_REC.CODPRETMAMB &lt; 0 THEN
      INSERT INTO PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
      VALUES (SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL, V_REC.CODPRETM, V_REC.CODAMB, V_REC.LEI, V_REC.VALUTA);
    ELSE
      UPDATE PRETMAMB
      SET
        LEI    = V_REC.LEI,
        VALUTA = V_REC.VALUTA
      WHERE
       CODPRETMAMB = V_REC.CODPRETMAMB;
    END IF;
  END LOOP;

--
  ELSE -- INSERT
  --***************************** I N S E R T *****************************
  SELECT seq_NART_CodArticol.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NART ( CodArticol,Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret, UM1, UM2, ContServiciu, INCREMENTSERIE, RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, ParitateD1, ParitateD2, ParitateD3, CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN,RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
                      ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  TIPSTOC )
  SELECT  RecId ,Den_Articol,UM,Clasa,TipSerie,TipArticol,AreTG,ContImplicit,GestImplicita,Certificat,EvolutiePret,UM1,UM2, ContServiciu, INCREMENTSERIE, RELATIEUM1, RELATIEUM2, CASADEMARCAT, CODCENTRU, D1, D2, D3, ParitateD1, ParitateD2, ParitateD3, CLASASTATIST, COMENZIONLINE, CODEXTERNART, SUFIXCODEXTERN,RESTNEGLIJCMD,NRZILESTOCMEDIU,MUSAICALITATE, Culoare, DCI,
          ClasaW, CHECKISAUTENTIC, PROCPerisab, codmasca, constructienoua, riscfiscal,  TIPSTOC
  FROM TMP_NART;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NART&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

-- Detail NART1


  FOR V_REC IN (SELECT * FROM TMP_NART1) LOOP
    VCOD := seq_NART1_CodArticol1.Nextval;
    INSERT INTO NART1 ( CodArticol1,CodArticol,CodTVA,CodAccize,TaxCode, codtaxa1,CodTaxa2,anstart,lunastart, CodAccizeDVI )
    VALUES ( VCOD, RecId, V_REC.CodTVA,V_REC.CodAccize, V_REC.TaxCode, V_REC.codtaxa1, V_REC.CodTaxa2, V_REC.anstart, V_REC.lunastart, v_rec.CodAccizeDVI);

--    INSERT INTO TMP_NART_LUNA (CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, TaxCode, codtaxa1, CODTAXA2, ANSTART, LUNASTART)
--      VALUES ( VCOD, RecId, V_REC.CodTVA, V_REC.CodAccize, V_REC.TaxCode, codtaxa1, V_REC.CodTaxa2, V_REC.anstart, V_REC.lunastart );

  END LOOP;

  INSERT INTO TMP_NART_LUNA (CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, TaxCode, codtaxa1, CODTAXA2, ANSTART, LUNASTART, CODACCIZEDVI)
  SELECT
    CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, TaxCode, codtaxa1, CODTAXA2, ANSTART, LUNASTART, CODACCIZEDVI
  FROM
    NART1 A1
  WHERE
    A1.CODARTICOL = RECID
    AND A1.ANSTART * 12  + A1.LUNASTART =
    (SELECT
       MAX(A2.ANSTART * 12  + A2.LUNASTART)
     FROM
      NART1 A2
     WHERE
       A2.ANSTART * 12  + A2.LUNASTART &lt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       AND A2.CODARTICOL = RECID
    );


  FOR v_rec IN ( SELECT * FROM TMP_NARTOBJ ORDER BY CodObiect ) LOOP
    SELECT seq_NARTOBJ_CodObiect.Nextval INTO vCod FROM dual ;
    UPDATE TMP_NATROBJ  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTAMB  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTOPT  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTOBJ1 SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTDIM  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);

    -- traduceri denumiri
    UPDATE TMP_NARTOBJTRAD SET CodObiect = vCod WHERE Coalesce(CodObiect, 0) = Coalesce(v_rec.CodObiect, 0);


    UPDATE TMP_DISCPROMORETAIL SET CodObiect = vCod WHERE Coalesce(CodObiect, 0) = Coalesce(v_rec.CodObiect, 0);

    UPDATE TMP_PRETM    SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTOBJIMP SET CODOBIECT = vCod WHERE CodOBIECT = v_Rec.CodObiect;
    UPDATE TMP_DISCART  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NARTCLI  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NECHIV   SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_NECHIV   SET CODOBIECTECHIV = vCod  WHERE Coalesce(CodOBIECTECHIV,0) = Coalesce(v_Rec.CodObiect,0);
    UPDATE TMP_NARTOBJSUBUNIT  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);

    UPDATE TMP_NARTOBJCOLET  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_CODEXTALT  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);
    UPDATE TMP_CODINTALT  SET CodObiect      = vCod  WHERE Coalesce(CodObiect,0)      = Coalesce(v_rec.CodObiect,0);

    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NARTOBJ&apos;, vCod, v_rec.CodObiect);
/*    IF  PKG_LIST_STRUCT.TmpExists(&apos;TMP_NARTOBJEXT&apos;) = 1 THEN
      EXECUTE IMMEDIATE &apos; UPDATE TMP_NARTOBJEXT SET CODOBIECT = &apos; || VCOD || &apos; WHERE CODOBIECT = &apos; || V_REC.CODOBIECT;
    END IF;*/

    INSERT INTO NARTOBJ (
      CodObiect,CodArticol,CodExtern,CodIntern, StocMin,StocMed, INACTIVCMDONLINE, AUTORIZATIE,EXPIRAREAUTORIZ, TRADUCARTGENERIC, MESAJINACTIV, StocMax,Masa,Volum,
      CodProducator,CodVamal,Returnabil,LuniGarantie,Obs,TARAORIGINE, ZILEVALABIL, ZILEDISTRIB,
      CODPERISABIL,ProcAdaosNir,Rotunjire, UMAmbalare, PRETMINIM, TERMENPLATA, DATAADAUGARII,
      CODPLU, USESTOCMED, NEFACTURABIL, GREUTSPECIFICA, BLOCAT, DURMAXAPROV, CODCNAS, CODCARACT, CODD394, INACTIV, FARACMDFURN, FARANIVELAPROB, DESCARCAREINTEGRALA, FARASTOC, CODCATEGARTTI,
      AdaosExceptie, Promotie, ROTVALUTA, discpromo,
      DENUMIRE, produspropriu, COEFCNAS, RAPCNAS, ANTIBIOTIC, EXPORTEMCS, CODNC, CODCPV, EXCLUSLISTARECM, CODACCIZABIL, LANSIMP, EXPORTKLG, CODANALIZANOD, SAFT_EXPORT, CANTVANZ, CERTIF_DDS )
    VALUES (
      vCod, RecId, v_rec.CodExtern, v_rec.CodIntern,  v_rec.StocMin, v_rec.StocMed, V_REC.INACTIVCMDONLINE, v_rec.AUTORIZATIE,v_rec.EXPIRAREAUTORIZ, V_REC.TRADUCARTGENERIC, V_REC.MESAJINACTIV, v_rec.StocMax, v_rec.Masa, v_rec.Volum,
      v_rec.CodProducator, v_rec.CodVamal, v_rec.Returnabil, v_rec.LuniGarantie, v_rec.Obs, v_rec.TARAORIGINE, v_rec.ZILEVALABIL, v_rec.ZILEDISTRIB,
      V_REC.CODPERISABIL, v_rec.ProcAdaosNir, v_rec.Rotunjire, v_rec.UMAmbalare, V_REC.PRETMINIM, V_REC.TERMENPLATA, V_REC.DATAADAUGARII,
      V_REC.CODPLU, V_REC.USESTOCMED, v_rec.NEFACTURABIL, v_rec.GREUTSPECIFICA, V_REC.BLOCAT, V_REC.DURMAXAPROV, V_REC.CODCNAS, V_REC.CODCARACT, v_rec.CODD394, V_REC.INACTIV, V_REC.FARACMDFURN,
      V_REC.FARANIVELAPROB, V_REC.DESCARCAREINTEGRALA, V_REC.FARASTOC, V_REC.CODCATEGARTTI,
      v_rec.AdaosExceptie,  v_rec.Promotie, V_REC.ROTVALUTA, v_rec.discpromo,
      CASE
        WHEN (SELECT COUNT(*) FROM TMP_NATROBJ WHERE CODOBIECT = VCOD) &gt; 0 THEN aDENARTICOL || &apos; &apos; || V_REC.DENOBIECT
        ELSE aDENARTICOL
      END, v_Rec.produspropriu, V_REC.COEFCNAS, V_REC.RAPCNAS, V_REC.ANTIBIOTIC, V_REC.EXPORTEMCS, V_REC.CODNC, V_REC.CODCPV, V_REC.EXCLUSLISTARECM, V_REC.CODACCIZABIL,
      CASE WHEN COALESCE(V_REC.PRODUSPROPRIU,0) = 0 THEN 0 ELSE V_REC.LANSIMP END,
      V_REC.EXPORTKLG, V_REC.CODANALIZANOD, V_REC.SAFT_EXPORT, V_REC.CANTVANZ, V_REC.CERTIF_DDS
    );


     if aCheck = &apos;1&apos; then CHECKMODIFPRETRETAIL(vCod); end if;
     if aMemo = &apos;1&apos; then MEMOMODIPRET(vCod); end if;

   /*
    if PKG_GLOBALS.GETSUBUNITATE &lt;&gt; 1 then
       INSERT INTO NARTOBJSUBUNIT (CODS,CODOBIECT,SUBUNITATE,STOCMIN,STOCMED,STOCMAX)
       SELECT SEQ_NARTOBJSUBUNIT_CODS.NextVal,vCod,SUBUNITATE,STOCMIN,STOCMED,STOCMAX FROM TMP_NARTOBJSUBUNIT WHERE CodObiect = vCod;
    end if;
   */
     if (aCodCatPret &gt; 0) and (pkg_globals.GETSUBUNITATE &gt; 1) then
       for v_sub in (select codsubunit from nsubunit where codsubunit &lt;&gt; pkg_globals.GETSUBUNITATE and codsubunit &gt; 1) loop
         insert into pretm(codpretm,codobiect,codcatpret,implicit,subunitatea,indexlocal,moneda)
         values(seq_pretm_codpretm.nextval,vCod,aCodCatPret,1,v_sub.codsubunit,1,0);
       end loop;
     end if;
  END LOOP;

  INSERT INTO NARTOBJSUBUNIT (CODS,CODOBIECT,SUBUNITATE,STOCMIN,STOCMED,STOCMAX,PROCSTOCMIN,PROCSTOCMED,PROCSTOCMAX, CODGEST)
  SELECT SEQ_NARTOBJSUBUNIT_CODS.NextVal,CODOBIECT,SUBUNITATE,STOCMIN,STOCMED,STOCMAX,PROCSTOCMIN,PROCSTOCMED,PROCSTOCMAX, CODGEST FROM TMP_NARTOBJSUBUNIT;

--Detail NARTOPT
 FOR V_REC IN (SELECT * FROM TMP_NARTOPT) LOOP
	 SELECT SEQ_NARTOPT_CODOPT.NEXTVAL INTO ACODOPT FROM DUAL;
	 INSERT INTO NARTOPT(CODOPT, CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, OBS)
	 VALUES (ACODOPT, V_REC.CODOBIECT, V_REC.codobiectopt, V_REC.CodTipLocatie, V_REC.ForceLei, V_REC.CANT, V_REC.STANDARD, V_REC.OBS);
 END LOOP;

--Detail NARTAMB
 FOR V_REC IN (SELECT * FROM TMP_NARTAMB) LOOP
   SELECT SEQ_NARTAMB_CODAMB.NEXTVAL INTO ACODAMB FROM DUAL;
   UPDATE TMP_PRETMAMB
   SET
     CODAMB = aCODAMB
   WHERE
     CODAMB = V_REC.CODAMB;
   INSERT INTO NARTAMB(CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN, UMSEC, CODEXTERN, CODPLU,
                                          CODINTERN, MASA, LUNGIME, LATIME, INALTIME, LXLAT, LXH, LATXH, GREUTSPECIFICA, IMPLICITTIPDOC, TIP, NR_RANDURI, AdMax, returnabil)
  VALUES (aCODAMB, vCOD, V_REC.CODOBIECTRETURN, V_REC.CANT, V_REC.CANTMIN, V_REC.UMSEC, V_REC.CODEXTERN,
                   V_REC.CODPLU, V_REC.CODINTERN, V_REC.MASA, V_REC.LUNGIME, V_REC.LATIME,
                   V_REC.INALTIME, V_REC.LXLAT, V_REC.LXH, V_REC.LATXH, V_REC.GREUTSPECIFICA, V_REC.IMPLICITTIPDOC, V_REC.TIP, V_REC.NR_RANDURI, V_REC.AdMax, V_REC.returnabil);
 END LOOP;

  FOR v_rec IN ( SELECT * FROM TMP_NArtDim WHERE Coalesce(D1, 0) + Coalesce(D2, 0) + Coalesce(D3, 0) &gt; 0 ORDER BY CodArtDim ) LOOP
    SELECT seq_NArtDim_CodArtDim.Nextval INTO vCod FROM DUAL;
    INSERT INTO NArtDim ( CodArtDim, CodObiect, CodArticol, Tip, D1, D2, D3 )
    values (vCod , v_rec.CodObiect, RecId , v_Rec.Tip, v_Rec.D1, v_Rec.D2, v_Rec.D3);
  END LOOP;

-- Detail NARTATR - musai inainte de NATROBJ
  FOR v_rec IN ( SELECT * FROM TMP_NARTATR ORDER BY CodArtAtr ) LOOP
    SELECT seq_NARTATR_CodArtAtr.Nextval INTO vCod FROM dual ;
    INSERT INTO  NARTATR ( CodArtAtr, CodArticol,CodAtribut,Activ,CodValPredef,Obligatoriu, OBS, Selectie,Facturabil, INDEXLOCAL )
    VALUES (vCod ,RecId, v_Rec.CodAtribut, v_Rec.Activ, v_Rec.CodValPredef, v_Rec.Obligatoriu, V_REC.OBS, v_Rec.Selectie, v_Rec.Facturabil, V_REC.INDEXLOCAL);
    UPDATE TMP_NATROBJ SET CodArtAtr = vCod where CodArtAtr = v_rec.CodArtAtr;
  END LOOP;

-- Detail NATROBJ
  INSERT INTO  NATROBJ ( CodObiect,CodAtrOBJ,CodArtAtr,CodValAtr, INDEXLOCAL )
     ( SELECT CodObiect, seq_NATROBJ_CodAtrOBJ.Nextval ,CodArtAtr,CodValAtr, INDEXLOCAL  FROM TMP_NATROBJ);


    FOR V_REC IN (SELECT * FROM TMP_CODEXTALT)
    LOOP
      INSERT INTO CODEXTALT(COD,CODOBIECT, CODEXTERN, CODPART)
      VALUES (SEQ_CODEXTALT_COD.NEXTVAL, V_REC.CODOBIECT, V_REC.CODEXTERN, V_REC.CODPART);
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_CODINTALT)
    LOOP
      INSERT INTO CODINTALT(COD,CODOBIECT, CODINTERN, CODPART)
      VALUES (SEQ_CODINTALT_COD.NEXTVAL, V_REC.CODOBIECT, V_REC.CODINTERN, V_REC.CODPART);
    END LOOP;



    FOR V_REC IN ( SELECT * FROM TMP_NARTOBJCOLET ORDER BY CODOBIECT, INDEXLOCAL)
    LOOP
      INSERT INTO NARTOBJCOLET (
        CODOBJCOLET, CODOBIECT, INDEXLOCAL, CONTINUT,
        IDCOLET,
        D1, D2, D3 )
      VALUES (
        seq_NARTOBJCOLET_Cod.Nextval , V_REC.CodObiect, V_REC.IndexLocal, V_REC.CONTINUT,
        CASE Coalesce(V_REC.IDCOLET, &apos;0&apos;) WHEN &apos;0&apos; THEN TRIM(TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;00009&apos;)) ELSE V_REC.IDCOLET END,
        V_REC.D1, V_REC.D2, V_REC.D3
      );
    END LOOP;

-- Detail PretM
  aCODOBIECT := 0; aINDEXLOCAL := 0;
  FOR V_REC IN (SELECT * FROM TMP_PRETM ORDER BY CODOBIECT, INDEXLOCAL) LOOP
    SELECT SEQ_PRETM_CODPRETM.NEXTVAL INTO aCODPRETM FROM DUAL;
    UPDATE TMP_PRETMAMB
    SET
      CODPRETM = aCODPRETM
    WHERE
      CODPRETM = V_REC.CODPRETM;

    IF aCODOBIECT &lt;&gt; V_REC.CODOBIECT THEN
      aCODOBIECT  := V_REC.CODOBIECT;
      aINDEXLOCAL := 0;
    END IF;

    aINDEXLOCAL := aINDEXLOCAL + 1;
    INSERT INTO PRETM (CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, GRUPA, PROC, INDEXLOCAL, SUBUNITATEA, ROTUNJIRE, SUMAFIXAIMPLICIT)
    VALUES (aCODPRETM , V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.LEI, V_REC.VALUTA, V_REC.MONEDA, V_REC.IMPLICIT, V_REC.GRUPA, V_REC.PROC,
           CASE
            WHEN PKG_GLOBALS.SUBUNITATE &lt;&gt; 1 THEN aINDEXLOCAL
            ELSE V_REC.INDEXLOCAL
           END,
    V_REC.SUBUNITATEA, V_REC.ROTUNJIRE, V_REC.SUMAFIXAIMPLICIT);

  END LOOP;

  INSERT INTO PRETMAMB (CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
 (SELECT SEQ_PRETMAMB_CODPRETMAMB.NEXTVAL, CODPRETM, CODAMB, LEI, VALUTA FROM TMP_PRETMAMB);

-- Detail NARTOBJ1
  INSERT INTO NARTOBJ1 (
    CodObiect1, CodObiect, PretMaximal, ProcAdaosMaximal, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA, uplift, AdaosLa,
    PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    Anstart, Lunastart, codmoneda, tippret, ValMat, ValMan, ValRegie, D390Exclus, Cost, Cantservauto,
    proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PretProd)
  SELECT
    seq_NARTOBJ1_CodOBIECT1.Nextval, CodObiect, PretMaximal, ProcAdaosMaximal, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA, uplift, AdaosLa,
    PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    Anstart, Lunastart, codmoneda, tippret, ValMat, ValMan, ValRegie, D390Exclus, Cost, CantServAuto,
    proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PretProd
  FROM TMP_NARTOBJ1;

  -- traduceri denumiri
  INSERT INTO NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad, Avertizare, descriere)
  (
    SELECT SEQ_NARTOBJTRAD_CodObiectTrad.NextVal, CodObiect, CodLimba, DenumireTrad, Avertizare, descriere
    FROM TMP_NARTOBJTRAD
  );


  INSERT INTO DISCPROMORETAIL(COD, CODPOSTRETAIL, CODOBIECT, DISCPROMO)
  (
    SELECT SEQ_DISCPROMORETAIL_Cod.NextVal, CODPOSTRETAIL, CODOBIECT, DISCPROMO
    FROM TMP_DISCPROMORETAIL
  );


-- Detail NARTCLI
  INSERT INTO NARTCLI (
    CodArtCli, CodObiect, CodPart, Denumire, CodExtern, UMSec, UMCorelat,CODMONEDA, PRET, tipcodafisat, CodLaClient, CodIntern, IMPLICIT, CODCLASEP, CODGAMA, OBS,OBS2, UMSECIMPDOC,
    DurataTr, ZileStoc, GLN, IDspecific)
  SELECT
    SEQ_NARTCLI_CodArtCli.NEXTVAL, CodObiect, CodPart, Denumire,  CodExtern, UMSec, UMCorelat,CODMONEDA, PRET, tipcodafisat, CodLaClient, CODINTERN, IMPLICIT, CODCLASEP, CODGAMA, OBS,OBS2, UMSECIMPDOC,
    DurataTr, ZileStoc, GLN, IDspecific
  FROM TMP_NARTCLI;


-- Detail DiscArt
  INSERT INTO DISCART(CODDISCART, CODDISCOUNT, CODOBIECT)
  SELECT SEQ_DISCART_CODDISCART.NEXTVAL, CODDISCOUNT, CODOBIECT
  FROM TMP_DISCART;

  INSERT INTO NARTOBJIMP (CODOBJIMP,CODOBIECT,CODSUBUNIT,GESTIMPLICITA,LOCATIEIMPLICITA,DURMAXAPROV,CONTIMPLICIT)
  SELECT SEQ_NARTOBJIMP_CODOBJIMP.NEXTVAL,CODOBIECT,CODSUBUNIT,GESTIMPLICITA,LOCATIEIMPLICITA,DURMAXAPROV,CONTIMPLICIT
  FROM TMP_NARTOBJIMP;

-- Detail NARTAMB
 --MUTAT MAI DUPA INSERT IN NARTOBJ CA SA POT PUNE SI CODOBIECT AFERENT
 /*INSERT INTO NARTAMB(CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN)
 (SELECT SEQ_NARTAMB_CODAMB.NEXTVAL, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN FROM TMP_NARTAMB);
*/

   INSERT INTO NARTIMPLICITE (CODIMPLICIT, CODARTICOL, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA, NEVANDABIL)
   SELECT  SEQ_NARTIMPLICITE_CODIMPLICIT.Nextval , RecId, CODSUBUNIT, CONTIMPLICIT, GESTIMPLICITA, LOCATIEIMPLICITA, NEVANDABIL FROM TMP_NARTIMPLICITE;

--***************************** END U P D A T E / I N S E R T *****************************

END IF;

--  UPDATE LUNA_RECORDS_FLAGS SET NART_FLG = 0;
--  UPDATE LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;

-- Detail NECHIV
  FOR V_REC IN (SELECT * FROM TMP_NECHIV where Coalesce(CodGrupa,0) = 0) LOOP
			DELETE FROM NECHIV WHERE CODOBIECT = V_REC.CodObiect;
	end loop;

  FOR V_REC IN (SELECT * FROM TMP_NECHIV where Coalesce(CodGrupa,0) &gt; 0) LOOP

    IF Coalesce(V_REC.PARITATE, 0) = 0 THEN aPARITATE := 1; ELSE aPARITATE := V_REC.PARITATE; END IF;

    SELECT COUNT(*) INTO aNr FROM NECHIV WHERE Coalesce(CODOBIECT, 0) = V_REC.CODOBIECT;

		IF aNr = 0 THEN
      INSERT INTO NECHIV(CODECHIV, CODOBIECT, PARITATE, CODGRUPA,Generic,indexlocal,Ind)
      (SELECT SEQ_NECHIV_CODECHIV.NEXTVAL, V_REC.CODOBIECT, V_REC.PARITATE, V_REC.CODGRUPA,v_rec.generic,
        (select max(indexlocal) + 1 from nechiv a where a.codgrupa = v_rec.codgrupa), V_REC.Ind FROM DUAL);
    ELSE
        UPDATE NECHIV
         SET
           PARITATE = aPARITATE,
           CODGRUPA = V_REC.CODGRUPA,
           IND      = V_REC.IND
         WHERE
          CODOBIECT = V_REC.CODOBIECT;
    END IF;
  END LOOP;

 -- completare automata traduceri denumiri
  FOR v_obj IN
    (SELECT CodObiect FROM NARTOBJ WHERE CodArticol = RecId AND Coalesce(TraducArtGeneric, 0) = 1)
  LOOP
    FOR v_lang IN
      (SELECT CodLimba FROM NLIMBA WHERE CodLimba &gt; 0 AND ExtLink &lt;&gt; &apos;RO&apos;)
    LOOP
      BEGIN
        SELECT
          DenumireTrad INTO aDenTrad
        FROM
          NARTOBJ O
          LEFT OUTER JOIN NARTOBJTRAD T ON T.CodObiect = O.CodObiect
        WHERE
          (SELECT COUNT(*) FROM NATROBJ A WHERE A.CodObiect = O.CodObiect) = 0 AND
          O.CodArticol = RecId AND
          T.CodLimba = v_lang.CodLimba;
        EXCEPTION WHEN NO_DATA_FOUND THEN aDenTrad := NULL;
      END;
      IF aDenTrad IS NOT NULL THEN
        SELECT
          COUNT(*) INTO aNr
        FROM
          NARTOBJTRAD
        WHERE
          CodObiect = v_obj.CodObiect AND
          CodLimba = v_lang.CodLimba;
        IF aNr = 0 THEN
          INSERT INTO NARTOBJTRAD
            (CodObiectTrad, CodObiect, CodLimba, DenumireTrad)
          VALUES
            (SEQ_NARTOBJTRAD_CodObiectTrad.NextVal, v_obj.CodObiect, v_lang.CodLimba, aDenTrad || &apos; &apos; || PKG_SELECTARTICOLE.GET_JUST_DENOBIECT(v_obj.CodObiect));
        END IF;
      END IF;
    END LOOP; -- v_lang
  END LOOP; -- v_obj

  IF PKG_NOMATRIBUTE.AM_DATE_NARTOBJATR(1, RecId) = 1 THEN -- refacere coloane suplimentare nartobjart pt. articolul curent
    BEGIN
      EXECUTE IMMEDIATE &apos;DELETE FROM NARTOBJATR WHERE CODOBIECT IN (SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = &apos;||RecId||&apos;)&apos;;
      PKG_NOMATRIBUTE.REPARA_NARTOBJATR(1, RecId);
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
  END IF;

  select count(*) into aCount
  from cfgtables cfg
       inner join cfgtables1 cfg1 on cfg.codcfgtable = cfg1.codcfgtable
  where cfg.numetabela = &apos;NARTOBJEXT&apos;;

  -- nomArt       --&gt; 501
  PKG_CFGTABLES.EXT_POSTRECORDS(501);

   IF PKG_LIST_STRUCT.TmpExists(&apos;NARTOBJEXT&apos;) &gt; 0 and acount &gt; 0 THEN
      BEGIN
        select Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;CaractObiectGeneric&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;?&apos;) INTO CaractObiectGeneric from dual;
        EXCEPTION WHEN OTHERS THEN CaractObiectGENERIC := &apos;0&apos;;
      END;

      BEGIN
        SELECT COUNT(*) INTO ATRIBUTE FROM NARTOBJ WHERE CODARTICOL = RECID;
        EXCEPTION WHEN OTHERS THEN ATRIBUTE := 0;
      END;

      IF CaractObiectGENERIC = &apos;1&apos; AND ATRIBUTE &gt; 1
      THEN
        BEGIN
          CODOBIECTGENERIC := GetCodObiectGeneric(RecID);
           EXCEPTION WHEN OTHERS THEN CODOBIECTGENERIC := 0;

         END;

        IF CODOBIECTGENERIC &gt; 0 THEN
          CloneazaNArtObjEXT(CODOBIECTGENERIC, RECID);
        END IF;


      END IF;
    END IF;

  --actualizare automata in retete pentru constanta activata
  if PKG_CATEGCONST.GetValConstanta(&apos;UpdateDuriPeRetete&apos;, PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU) = 1 then
    for v_rec in (select pc.codprodcomp from prodcomp pc
                  where exists (select obj.codobiect from nartobj obj where pc.codobiect = obj.codobiect and obj.codarticol = recid)) loop
      begin
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        update prodcomp pc
        set
          D1 = aD1,
          D2 = aD2,
          D3 = aD3
        where pc.codprodcomp = v_Rec.Codprodcomp;

        update prodcomp pc set
        cantum1 = round(CASE
                          WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cant/D1
                          WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0))
                          WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                          WHEN aRELATIEUM1 IN (4, 10) THEN cant * Coalesce(aD1,0)
                          WHEN aRELATIEUM1 IN (5, 11) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                          WHEN aRELATIEUM1 IN (6, 12) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                        END,7)
        where exists (select obj.codobiect from nartobj obj where pc.codobiect = obj.codobiect and obj.codarticol = recid);
      exception when others then null;
      end;
    end loop;

    for v_rec in (select pm.codprodcomp, pm.codmat from prodmat pm
                 where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = recid)) loop
      begin
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        update prodmat pc
        set
          D1 = aD1,
          D2 = aD2,
          D3 = aD3
        where codmat = v_rec.codmat;

        update prodmat pc set
        cantum1 = round(CASE
                          WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cant/D1
                          WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0))
                          WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                          WHEN aRELATIEUM1 IN (4, 10) THEN cant * Coalesce(aD1,0)
                          WHEN aRELATIEUM1 IN (5, 11) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                          WHEN aRELATIEUM1 IN (6, 12) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                        END,7)
        where codmat = v_rec.codmat;
      exception when others then null;
      end;
    end loop;

    for v_rec in (select pm.codprodcomp, pm.codrez from prodrez pm
                  where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = recid)) loop
    begin
      SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
      update prodrez pc
      set
        D1 = aD1,
        D2 = aD2,
        D3 = aD3
      where codrez = v_rec.codrez;

      update prodrez pc set
      cantum1 = round(CASE
                        WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cant/D1
                        WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0))
                        WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                        WHEN aRELATIEUM1 IN (4, 10) THEN cant * Coalesce(aD1,0)
                        WHEN aRELATIEUM1 IN (5, 11) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                        WHEN aRELATIEUM1 IN (6, 12) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                      END,7)
      where codrez = v_rec.codrez;
      exception when others then null;
      end;
   end loop;

   for v_rec in (select pm.codprodcomp, pm.codnormemat from normemat pm
                 where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = recid)) loop
     begin
       SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
       update normemat pc
       set
         D1 = aD1,
         D2 = aD2,
         D3 = aD3
       where codnormemat = v_rec.codnormemat;

       update normemat pc set
       cantum1 = round(CASE
                         WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cant/D1
                         WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0))
                         WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                         WHEN aRELATIEUM1 IN (4, 10) THEN cant * Coalesce(aD1,0)
                         WHEN aRELATIEUM1 IN (5, 11) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                         WHEN aRELATIEUM1 IN (6, 12) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                       END,7)
       where codnormemat = v_rec.codnormemat;
     exception when others then null;
     end;
   end loop;
   for v_com in (select distinct codcomanda
                 from
                 (
                  select c1.codcomanda
                  from comanda1 c1
                       inner join cmdprodmat cmd on c1.codcomanda1 = cmd.codcomanda1
                  where exists (select obj.codobiect from nartobj obj where obj.codobiect = cmd.codobiect and obj.codarticol = recid)
                        and cmd.rest &gt; 0
                 )
                 ) loop
     begin
       SELECT CodComanda INTO Tmp FROM comanda WHERE codcomanda = v_com.codcomanda FOR UPDATE NOWAIT;
       for v_cmd in (select cmd.codcmdprodmat, cmd.codcomanda1, cmd.tip
                     from comanda1 c1
                          inner join cmdprodmat cmd on cmd.codcomanda1 = c1.codcomanda1
                     where c1.codcomanda = v_com.codcomanda and cmd.rest &gt; 0
                           and exists (select obj.codobiect from nartobj obj where obj.codobiect = cmd.codobiect and obj.codarticol = recid)
                    ) loop
         update cmdprodmat
         set
           D1 = aD1,
           D2 = aD2,
           D3 = aD3
         where codcmdprodmat = v_cmd.codcmdprodmat;
         update cmdprodmat set
         cantum1 = round(CASE
                           WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cant/D1
                           WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0))
                           WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cant / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                           WHEN aRELATIEUM1 IN (4, 10) THEN cant * Coalesce(aD1,0)
                           WHEN aRELATIEUM1 IN (5, 11) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                           WHEN aRELATIEUM1 IN (6, 12) THEN cant * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                         END,7)
         where codcmdprodmat = v_cmd.codcmdprodmat;
         if v_cmd.tip in (0,2) then
           update comanda1 set
             D1 = aD1,
             D2 = aD2,
             D3 = aD3
           where codcomanda1 = v_cmd.codcomanda1;
           update comanda1 set
           acceptum1 = round(CASE
                             WHEN aRELATIEUM1 IN (1, 7) AND Coalesce(aD1, 0) &lt;&gt; 0 THEN cantacceptat/D1
                             WHEN aRELATIEUM1 IN (2, 8) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) &lt;&gt; 0 THEN cantacceptat / (Coalesce(aD1,0) * Coalesce(aD2,0))
                             WHEN aRELATIEUM1 IN (3, 9) AND Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0) &lt;&gt; 0 THEN cantacceptat / (Coalesce(aD1,0) * Coalesce(aD2,0) * Coalesce(aD3,0))
                             WHEN aRELATIEUM1 IN (4, 10) THEN cantacceptat * Coalesce(aD1,0)
                             WHEN aRELATIEUM1 IN (5, 11) THEN cantacceptat * Coalesce(aD1, 0) * Coalesce(aD2, 0)
                             WHEN aRELATIEUM1 IN (6, 12) THEN cantacceptat * Coalesce(aD1, 0) * Coalesce(aD2, 0) * Coalesce(aD3, 0)
                           END,7)
           where codcomanda1 = v_cmd.codcomanda1;
         end if;
       end loop;
     exception when others then null;
     end;
    end loop;
  end if;

  select count(*) into aCount from nartobj where codarticol = recid;

  PRC_AL_REFRESH(&apos;NART1&apos;, RECID);
  if acount &lt;= 10 then
    FOR vRec IN (
      SELECT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = RECID
    ) LOOP
      PRC_AL_REFRESH(&apos;NARTOBJ1&apos;, VRec.CODOBIECT);
    END LOOP;
  else
    PRC_AL_REFRESH(&apos;NARTOBJ1&apos;);
  end if;

  COMMIT; 
  NotifyModif(OPERATION, RECID, &apos;NART&apos;);

  COMMIT;
END;

FUNCTION Get_Next_CodObiect1 RETURN NUMBER IS
NextValue Number(20);
begin
  select seq_nartobj1_codobiect1.nextval into NextValue from dual;
  return NextValue;
end;

FUNCTION VERIFICA_OBIECT_EXISTENT(aCODARTICOL IN NUMBER, aCodAtribut IN NUMBER, aCodProdus IN NUMBER, vCodAtribut OUT NUMBER) RETURN NUMBER IS
NR1 NUMBER(20);
NR2 NUMBER(20);
BEGIN
  vCodAtribut := aCodAtribut;
  FOR V_REC IN (SELECT DISTINCT CODOBIECT FROM NARTOBJ WHERE CODARTICOL = aCOdARTICOL) LOOP
    SELECT COUNT(*) INTO NR1 FROM
     (SELECT CODUNIC FROM TMP_MANEVRA
       MINUS
      SELECT ATROBJ.CODVALATR FROM NARTATR ATR INNER JOIN NATROBJ ATROBJ ON ATR.CODARTATR = ATROBJ.CODARTATR
      WHERE  ATROBJ.CODOBIECT = V_REC.CODOBIECT
     );

    SELECT COUNT(*) INTO NR2 FROM
     (SELECT ATROBJ.CODVALATR FROM NARTATR ATR INNER JOIN NATROBJ ATROBJ ON ATR.CODARTATR = ATROBJ.CODARTATR
      WHERE  ATROBJ.CODOBIECT = V_REC.CODOBIECT
       MINUS
      SELECT CODUNIC FROM TMP_MANEVRA
     );
   IF NR1 + NR2 = 0 THEN
     FOR V_TMP IN (
       SELECT PN.CODATRIBUT
       FROM NATROBJ N
            INNER JOIN NARTATR PN ON PN.CODARTATR = N.CODARTATR
            INNER JOIN TMP_MANEVRA T ON T.CODUNIC = N.CODVALATR
            INNER JOIN NATRIB1 NB1 ON NB1.CODVALATR = N.CODVALATR
            INNER JOIN NATRIB1 NP1 ON NP1.VALOARE = NB1.VALOARE
            INNER JOIN NATROBJ P ON NP1.CODVALATR = P.CODVALATR
            INNER JOIN NARTATR PA ON PA.CODARTATR = P.CODARTATR
       WHERE PA.CODATRIBUT = aCodAtribut AND P.CODOBIECT = aCodProdus AND N.CODOBIECT = V_REC.CODOBIECT
     ) LOOP
       vCodAtribut := v_tmp.codatribut;
       Exit;
     END LOOP;
     RETURN V_REC.CODOBIECT;
   END IF;
  END LOOP;
  RETURN -1;
END;

procedure CLONARE_PRETM_ATRIB(aCodObiect IN NUMBER, aCodSubunit IN NUMBER ) is
aCodArticol     NUMBER(20);
--Nr              NUMBER(20);
aImplicit        NUMBER(5);
CodObjSursa     number(20);
aOrdine          VARCHAR2(5) := &apos;!&apos;;
MaxOrdine       VARCHAR2(5) := &apos;!&apos;;
PROC            NUMBER(8,5);
MAJORARE        number(20,7) := 1;
MaxGRUPA        VARCHAR2(5) := &apos;!&apos;;
BEGIN
 TMPORDINEGRUPEPRET;
 -- caut obiectul generic fara atribute
 select codArticol into aCodArticol from Nartobj where CodObiect = aCodObiect;
 select nobj.codobiect into CodObjSursa from nartobj nobj
   WHERE (SELECT COUNT(*) FROM NAtrObj AO WHERE AO.CodObiect = NOBJ.CodObiect)= 0
   /*where exists (select n.den_articol from nart n
                  where upper(n.den_articol) = upper(nobj.denumire))*/ and nobj.codarticol = aCodArticol;

 if (Nvl(CodObjSursa, 0) &gt; 0)and(CodObjSursa &lt;&gt; aCodObiect) then
   FOR V_REC IN (SELECT A.CodValAtr, A1.Grupa
                 FROM NAtrObj A INNER JOIN NATRIB1 A1 ON A.CODVALATR  = A1.CODVALATR
                 WHERE A.CODOBIECT = aCodObiect)
   LOOP
     aOrdine := &apos;&apos;;
     BEGIN
       select VALOARE into aOrdine from TMP_MANEVRA_LISTE where Upper(Nvl(filtru,&apos;?&apos;)) = UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;));
     EXCEPTION
       WHEN no_data_found THEN NULL;
     END;


     if Nvl(aOrdine, &apos;!&apos;) &lt;&gt; &apos;!&apos;  then
       if aOrdine &gt; MaxOrdine then
          MaxOrdine := aOrdine;
          MaxGrupa := UPPER(V_Rec.Grupa);
        end if;
     else
       if UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;)) &gt; MaxGRUPA then MaxGrupa := UPPER(V_Rec.Grupa); end if;
     end if;

     BEGIN
       SELECT Nvl(PROCMAJ,0) INTO PROC FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR AND CODARTICOL = ACODARTICOL;
       EXCEPTION when others then PROC := 0;
     END;
     MAJORARE := MAJORARE * (1 + PROC/100);
   END LOOP;

  --PRETM
     if aCodSubunit &gt; 1 then
       select Count(*) into aImplicit from PretM where Subunitatea = aCodSubunit and CodObiect = aCodObiect and Nvl(Grupa, &apos;!&apos;) &lt;&gt; &apos;!&apos;;
       if aImplicit &gt; 1 then aImplicit := 1; end if;
       delete from PretM where Subunitatea = aCodSubunit and CodObiect = aCodObiect and Nvl(Grupa, &apos;!&apos;) &lt;&gt; &apos;!&apos;;
       INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET, LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA, ROTUNJIRE)
       SELECT SEQ_PRETM_CODPRETM.NEXTVAL, aCodObiect ,CODCATPRET, Round(LEI * MAJORARE, 2),Round(VALUTA * MAJORARE, 2),MONEDA, aImplicit ,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA, ROTUNJIRE
       FROM PRETM WHERE CODOBIECT = CodObjSursa and Subunitatea = aCodSubunit and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;
     else
       for v_rec in (select * from PretM where CODOBIECT = CodObjSursa and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA)
       loop
         select Count(*) into aImplicit from PretM where Subunitatea = v_rec.Subunitatea and CodObiect = aCodObiect and Nvl(Grupa, &apos;!&apos;) &lt;&gt; &apos;!&apos;;
         if aImplicit &gt; 1 then aImplicit := 1; end if;
         delete from PretM where Subunitatea = v_rec.Subunitatea and CodObiect = aCodObiect and Nvl(Grupa, &apos;!&apos;) &lt;&gt; &apos;!&apos;;
         INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET, LEI,VALUTA,MONEDA,IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA,ROTUNJIRE)
         SELECT SEQ_PRETM_CODPRETM.NEXTVAL, aCodObiect ,CODCATPRET, Round(LEI * MAJORARE, 2),Round(VALUTA * MAJORARE, 2),MONEDA, aImplicit ,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA,ROTUNJIRE
         FROM PRETM WHERE CODOBIECT = CodObjSursa and Subunitatea = v_rec.Subunitatea and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;
       end loop;
     end if;
  end if; -- exista CodObjSursa
END;

/*
function CLONARE_Get_PretM_Sursa(aCodObiect IN NUMBER, aCodSubunit IN NUMBER ) RETURN aPretM_Cursor is
TMPCURSOR aPretM_Cursor;
aCodArticol     NUMBER(20);
Nr              NUMBER(20);
aImplicit        NUMBER(5);
CodObjSursa     number(20);
PROC            NUMBER(8,5);
MAJORARE        number(20,7) := 1;
MaxGRUPA        VARCHAR2(5) := &apos;!&apos;;
BEGIN
 -- caut obiectul generic fara atribute
 select codArticol into aCodArticol from Nartobj where CodObiect = aCodObiect;
 select nobj.codobiect into CodObjSursa from nartobj nobj
   where exists ( select n.den_articol from nart n
                  where upper(n.den_articol) = upper(nobj.denumire))and nobj.codarticol = aCodArticol;
 if (Nvl(CodObjSursa, 0) = 0)or (CodObjSursa = aCodObiect) then
   OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
 else
   FOR V_REC IN (SELECT A.CodValAtr, A1.Grupa
                 FROM NAtrObj A INNER JOIN NATRIB1 A1 ON A.CODVALATR  = A1.CODVALATR
                 WHERE A.CODOBIECT = aCodObiect)
   LOOP
     if UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;)) &gt; MaxGRUPA then MaxGrupa := UPPER(V_Rec.Grupa); end if;
     BEGIN
       SELECT Nvl(PROCMAJ,0) INTO PROC FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR AND CODARTICOL = ACODARTICOL;
       EXCEPTION when others then PROC := 0;
     END;
     MAJORARE := MAJORARE * (1 + PROC/100);
   END LOOP;

  --PRETM
     if aCodSubunit &gt; 1 then
       BEGIN
         OPEN TMPCURSOR FOR
           SELECT SEQ_PRETM_CODPRETM.NEXTVAL as CODPRETM, aCodObiect as CODOBIECT,CODCATPRET, Round(LEI * MAJORARE, 2) as LEI ,Round(VALUTA * MAJORARE, 2) as VALUTA , MONEDA, 1 as IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA
           FROM PRETM WHERE CODOBIECT = CodObjSursa and Subunitatea = aCodSubunit and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;
         EXCEPTION WHEN OTHERS THEN OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
       END;
     else
       BEGIN
         OPEN TMPCURSOR FOR
           SELECT SEQ_PRETM_CODPRETM.NEXTVAL as CODPRETM, aCodObiect as CODOBIECT,CODCATPRET, Round(LEI * MAJORARE, 2) as LEI ,Round(VALUTA * MAJORARE, 2) as VALUTA , MONEDA, 1 as IMPLICIT,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA
           FROM PRETM WHERE CODOBIECT = CodObjSursa and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;
         EXCEPTION WHEN OTHERS THEN OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
       END;
     end if;
  end if; -- exista CodObjSursa

 RETURN TMPCURSOR;

END;

function CLONARE_GRUPA(aCodObiect IN NUMBER) RETURN VARCHAR2 is
MaxGRUPA        VARCHAR2(5) := &apos;!&apos;;
BEGIN
   FOR V_REC IN (SELECT A.CodValAtr, A1.Grupa
                 FROM NAtrObj A INNER JOIN NATRIB1 A1 ON A.CODVALATR  = A1.CODVALATR
                 WHERE A.CODOBIECT = aCodObiect)
   LOOP
     if UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;)) &gt; MaxGRUPA then MaxGrupa := UPPER(V_Rec.Grupa); end if;
   END LOOP;
   RETURN MAXGRUPA;
END;

function CLONARE_Majorare(aCodObiect IN NUMBER) RETURN NUMBER is
PROC            NUMBER(8,5);
MAJORARE        number(20,7) := 1;
aCodArticol     NUMBER(20);
BEGIN
 -- caut obiectul generic fara atribute
   select codArticol into aCodArticol from Nartobj where CodObiect = aCodObiect;
   FOR V_REC IN (SELECT A.CodValAtr, A1.Grupa
                 FROM NAtrObj A INNER JOIN NATRIB1 A1 ON A.CODVALATR  = A1.CODVALATR
                 WHERE A.CODOBIECT = aCodObiect)
   LOOP
     BEGIN
       SELECT Nvl(PROCMAJ,0) INTO PROC FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR AND CODARTICOL = ACODARTICOL;
       EXCEPTION when others then PROC := 0;
     END;
     MAJORARE := MAJORARE * (1 + PROC/100);
   END LOOP;
   RETURN MAJORARE;
END;
*/

FUNCTION CLONEAZA_OBIECT(aCodArticol IN NUMBER, aCodAtribut IN NUMBER, vCodProdus IN NUMBER, vCodAtribut OUT NUMBER) RETURN NUMBER IS
pragma autonomous_transaction;

CodObjSursa     number(20);
codObjNou       number(20);
denObjNou       varchar2(200);
CodExtObjSursa  varchar2(200) := null;
CodExtObjNou    varchar2(200);
CodIntObjNou    varchar2(200);
KConst          number(20);
KConst1         number(20);
KConst2         number(20);
ModDepozitareGeneric Number(5);
CodVamalGeneric Number(5);

PROC            NUMBER(8,5);
MAJORARE        number(20,7) := 1;
MaxGRUPA        VARCHAR2(5) := &apos;!&apos;;
aOrdine         VARCHAR2(5) := &apos;!&apos;;
MaxOrdine       VARCHAR2(5) := &apos;!&apos;;
CaractObiectGeneric VARCHAR2(10);
aDenTrad        VARCHAR2(200);
aAreTrad        NUMBER(20);
aBifaTrad       NUMBER(1);
kArtBlocat      NUMBER(20);
kRotIntrImplicita NUMBER(20);
kRotIesImplicita NUMBER(20);
BEGIN
  vCodAtribut := aCodAtribut;
  TMPORDINEGRUPEPRET;
  -- caut obiectul generic fara atribute
  select nobj.codobiect, nobj.denumire, nobj.codextern
  into CodObjSursa, denObjNou, CodExtObjSursa
  from nartobj nobj
  where
  (SELECT COUNT(*) FROM NAtrObj AO WHERE AO.CodObiect = NOBJ.CodObiect)= 0
  and nobj.codarticol = aCodArticol;

  -- compun denumirea obiectului si codul extern ;
  KConst  := pkg_categConst.GetValConstanta(&apos;CodExternAtrib&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);
  KConst1 := pkg_categConst.GetValConstanta(&apos;GenCodExtArt&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);
  KConst2 := pkg_categConst.GetValConstanta(&apos;GenCodIntArt&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);
  kArtBlocat := pkg_categConst.GetValConstanta(&apos;ArtBlocat&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);
  kRotIntrImplicita := pkg_categConst.GetValConstanta(&apos;RotIntrImplicita&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);
  kRotIesImplicita := pkg_categConst.GetValConstanta(&apos;RotIesImplicita&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU);


  ModDepozitareGeneric := NVL(pkg_categConst.GetValConstanta(&apos;ModDepozitareGeneric&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU), &apos;&apos;);
  CodVamalGeneric := NVL(pkg_categConst.GetValConstanta(&apos;CodVamalGeneric&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU), &apos;&apos;);

  CodExtObjNou := CodExtObjSursa;

  CaractObiectGeneric := NVL(pkg_categConst.GetValConstanta(&apos;CaractObiectGeneric&apos;,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU), &apos;&apos;) ;


  FOR V_REC IN (SELECT ATR1.CODVALATR,ATR1.VALOARE,ATR.INDEXLOCAL,atr1.codextern, Atr1.Grupa
               FROM TMP_MANEVRA TMP INNER JOIN NATRIB1 ATR1 ON TMP.CODUNIC   = ATR1.CODVALATR
                                    INNER JOIN NARTATR ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
               WHERE ATR.CODARTICOL = aCodArticol
               ORDER BY  ATR.INDEXLOCAL)
  LOOP
     aOrdine := &apos;&apos;;
     BEGIN
       select VALOARE into aOrdine from TMP_MANEVRA_LISTE where Upper(Nvl(filtru,&apos;?&apos;)) = UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;));
     EXCEPTION
       WHEN no_data_found THEN NULL;
     END;


     if Nvl(aOrdine, &apos;!&apos;) &lt;&gt; &apos;!&apos;  then
       if aOrdine &gt; MaxOrdine then
          MaxOrdine := aOrdine;
          MaxGrupa := UPPER(V_Rec.Grupa);
        end if;
     else
       if UPPER(Nvl(V_Rec.Grupa, &apos;!&apos;)) &gt; MaxGRUPA then MaxGrupa := UPPER(V_Rec.Grupa); end if;
     end if;

   BEGIN
     SELECT Nvl(PROCMAJ,0) INTO PROC FROM NATRIB2 WHERE CODVALATR = V_REC.CODVALATR AND CODARTICOL = ACODARTICOL;
     EXCEPTION when others then PROC := 0;
   END;

   MAJORARE := MAJORARE * (1 + PROC/100);

   denObjNou := denObjNou||&apos; &apos;||v_rec.valoare;
     if KConst = 3 then
       CodExtObjNou := NULL;
     else
     if KConst = 1 then
       CodExtObjNou  := CodExtObjNou||&apos; &apos;|| v_rec.valoare;
     else
     if KConst = 2 then
       CodExtObjNou  := CodExtObjNou|| v_rec.codextern;
     end if;
     end if;
     end if;

  END LOOP;

   IF KCONST1 = 1
   THEN
     CodExtObjNou  := PKG_GENERARE_CODURI.GET_NEXT_CODEXTERN_ART(PKG_GLOBALS.GETUSERID);
   END IF;

   CodIntObjNou := &apos;&apos;;
   IF KCONST2 = 1
   THEN
     CodIntObjNou  := PKG_GENERARE_CODURI.GET_NEXT_CODINTERN_ART(PKG_GLOBALS.GETUSERID);
   END IF;


  codObjNou := SEQ_NARTOBJ_CODOBIECT.NEXTVAL;
  -- NARTOBJ
  INSERT INTO NARTOBJ(
    CODOBIECT,
    CODARTICOL,
    CODPRODUCATOR,
    CODEXTERN,
    CODINTERN,
    MASA,
    VOLUM,
    STOCMIN,
    STOCMED,
    INACTIVCMDONLINE,
    AUTORIZATIE,
    EXPIRAREAUTORIZ,
    TRADUCARTGENERIC,
    MESAJINACTIV,
    STOCMAX,
    RETURNABIL,
    LUNIGARANTIE,
    OBS,
    PROCADAOSNIR,
    ROTUNJIRE,
    ADAOSEXCEPTIE,
    PROMOTIE,
    ROTVALUTA,
    DENUMIRE,
    UMAMBALARE,
    PRETMINIM,
    TERMENPLATA,
    DATAADAUGARII,
    CODPLU,
    USESTOCMED,
    DURMAXAPROV,
    CODCNAS,
    PRODUSPROPRIU,
    CODCARACT,
    CODD394,
    INACTIV,
    BLOCAT,
    DISCPROMO,
    TARAORIGINE,
    ZILEVALABIL,
    ZILEDISTRIB,
    CODPERISABIL,
    NEFACTURABIL,
    GREUTSPECIFICA,
    COEFCNAS,
    RAPCNAS,
    ANTIBIOTIC,
    CODVAMAL,
    SAFT_EXPORT
  )
  SELECT
    codObjNou,
    CODARTICOL,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPRODUCATOR ELSE NULL END,
    CodExtObjNou,
    CodIntObjNou,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN MASA    ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN VOLUM   ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMIN ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMED ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN INACTIVCMDONLINE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN AUTORIZATIE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN EXPIRAREAUTORIZ ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN TRADUCARTGENERIC ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN MESAJINACTIV ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN STOCMAX ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN RETURNABIL ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN LUNIGARANTIE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN OBS ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN PROCADAOSNIR ELSE NULL END,
    kRotIntrImplicita,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN ADAOSEXCEPTIE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN PROMOTIE ELSE NULL END,
    kRotIesImplicita,
    denObjNou,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN UMAMBALARE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN PRETMINIM ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN TERMENPLATA ELSE NULL END,
    SYSDATE,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPLU ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN USESTOCMED ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN DURMAXAPROV ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODCNAS ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN PRODUSPROPRIU ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODCARACT ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODD394 ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN INACTIV ELSE NULL END,
    CASE WHEN kArtBlocat = 1 then 1 ELSE 0 END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN DISCPROMO ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN TARAORIGINE ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN ZILEVALABIL ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN ZILEDISTRIB ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN CODPERISABIL ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN NEFACTURABIL ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN GREUTSPECIFICA ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN COEFCNAS ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN RAPCNAS ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN ANTIBIOTIC ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; AND CodVamalGeneric = &apos;1&apos; THEN CODVAMAL ELSE NULL END,
    CASE WHEN CaractObiectGeneric = &apos;1&apos; THEN SAFT_EXPORT ELSE 1 END
  FROM NARTOBJ
  WHERE CODOBIECT = CodObjSursa;

  -- NARTOBJ1
  INSERT INTO NARTOBJ1(
    CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,PRETREFERINTA,TIPPRETMAX,
    COMPENSAT,TIPCOMPENSARE,GRUPA,UPLIFT,
    CODMONEDA,COST,
    PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PretProd
  )
  SELECT
    SEQ_NARTOBJ1_CODOBIECT1.NEXTVAL,codObjNou,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,PRETREFERINTA,TIPPRETMAX,
    COMPENSAT,TIPCOMPENSARE,GRUPA,UPLIFT,
    CODMONEDA, COST, PUNCTE, Umiditate, CORPURI_STRAINE, PUNCTESECTIE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi,
    proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, sistave, refractie, indice_w, toxina_don, boabe_toxice,
    MAX_UMIDITATE,MAX_CORPURI_STRAINE,MAX_INCOLTIT,MAX_HECTOLITRICA,MAX_GLUTEN,MAX_FUZARITATE,MAX_CADERE,MAX_DEFORMARE,
    MAX_STICLOZITATE,MAX_SPARTURI,MAX_PROTEINA,MAX_AFLATOXINA,MAX_ATAC_PLOSNITA,MAX_CONTINUT_ULEI,MAX_ACIDITATE,MAX_SISTAVE,
    MAX_REFRACTIE,MAX_INDICE_W,MAX_TOXINA_DON,MAX_BOABE_TOXICE,
    MIN_UMIDITATE,MIN_CORPURI_STRAINE,MIN_INCOLTIT,MIN_HECTOLITRICA,MIN_GLUTEN,MIN_FUZARITATE,MIN_CADERE,MIN_DEFORMARE,MIN_STICLOZITATE,MIN_SPARTURI,
    MIN_PROTEINA,MIN_AFLATOXINA,MIN_ATAC_PLOSNITA,MIN_CONTINUT_ULEI,MIN_ACIDITATE,MIN_SISTAVE,MIN_REFRACTIE,MIN_INDICE_W,MIN_TOXINA_DON,MIN_BOABE_TOXICE,
    PretProd
  FROM NARTOBJ1
  WHERE CODOBIECT = CodObjSursa;

--NARTOBJSUBUNIT
 INSERT INTO NARTOBJSUBUNIT(CODS,CODOBIECT,SUBUNITATE,STOCMIN,STOCMED,STOCMAX,PROCSTOCMIN,PROCSTOCMED,PROCSTOCMAX, CODGEST)
 SELECT SEQ_NARTOBJSUBUNIT_CODS.NextVal ,codObjNou, SUBUNITATE,STOCMIN,STOCMED,STOCMAX,PROCSTOCMIN,PROCSTOCMED,PROCSTOCMAX, CODGEST FROM NARTOBJSUBUNIT
 WHERE CODOBIECT = CodObjSursa;

-- NATROBJ

FOR V_REC IN( SELECT ATR1.CODVALATR,ATR.CODARTATR,ATR1.VALOARE,ATR.INDEXLOCAL
               FROM TMP_MANEVRA TMP INNER JOIN NATRIB1 ATR1 ON TMP.CODUNIC   = ATR1.CODVALATR
                                    INNER JOIN NARTATR ATR ON ATR.CODATRIBUT = ATR1.CODATRIBUT
               WHERE ATR.CODARTICOL = aCodArticol
               ORDER BY  ATR.INDEXLOCAL ) LOOP
  INSERT INTO NATROBJ(CODATROBJ,CODOBIECT,CODARTATR,CODVALATR,INDEXLOCAL) VALUES
 (SEQ_NATROBJ_CODATROBJ.NEXTVAL,codObjNou,V_REC.CODARTATR,V_REC.CODVALATR,NVL(V_REC.INDEXLOCAL,0)) ;
END LOOP;

--PRETM

 INSERT INTO PRETM(CODPRETM,CODOBIECT,CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, PROC, INDEXLOCAL, SUBUNITATEA,GRUPA,ROTUNJIRE)
 SELECT SEQ_PRETM_CODPRETM.NEXTVAL, codObjNou,CODCATPRET, Round(LEI * MAJORARE, 2),Round(VALUTA * MAJORARE, 2),MONEDA, IMPLICIT ,PROC,INDEXLOCAL,SUBUNITATEA,GRUPA,ROTUNJIRE
 FROM PRETM WHERE CODOBIECT = CodObjSursa and UPPER(Nvl(Grupa, &apos;!&apos;)) = MaxGRUPA;

--NARTCLI
 INSERT INTO NARTCLI(CODARTCLI, CODOBIECT,CODPART,DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, tipcodafisat, CodLaClient, CODINTERN, UMCORELAT, DURATATR, ZILESTOC, GLN, IDspecific)
 SELECT SEQ_NARTCLI_CODARTCLI.NEXTVAL, codObjNou,CODPART,DENUMIRE, CODEXTERN, UMSEC, CODMONEDA, PRET, tipcodafisat, CodLaClient, CODINTERN,  UMCORELAT, DURATATR, ZILESTOC, GLN, IDspecific
 FROM NARTCLI WHERE CODOBIECT = CodObjSursa;

-- NARTOPT
 INSERT INTO NARTOPT(CODOPT,CODOBIECT,codobiectopt, CodTipLocatie, ForceLei,CANT,STANDARD, OBS)
 SELECT SEQ_NARTOPT_CODOPT.NEXTVAL,codObjNou,codobiectopt, CodTipLocatie, ForceLei,CANT,STANDARD, OBS
 FROM NARTOPT WHERE CODOBIECT = CodObjSursa;

-- NARTAMB
/*
 INSERT INTO NARTAMB(CODAMB,CODOBIECT,CODOBIECTRETURN,CANT,CANTMIN,UMSEC,CODEXTERN,CODPLU,CODINTERN,MASA,LUNGIME,LATIME,INALTIME,
                    LXLAT,LXH,LATXH, GREUTSPECIFICA, IMPLICITTIPDOC, TIP )
 SELECT SEQ_NARTAMB_CODAMB.NEXTVAL,codObjNou,CODOBIECTRETURN,CANT,CANTMIN,UMSEC,CODEXTERN,CODPLU,CODINTERN,MASA,LUNGIME,LATIME,INALTIME,
        LXLAT, LXH, LATXH, GREUTSPECIFICA, IMPLICITTIPDOC, TIP
 FROM NARTAMB WHERE CODOBIECT = CodObjSursa;
*/

 IF ModDepozitareGeneric = &apos;1&apos; THEN
   INSERT INTO NARTAMB(CODAMB, CODOBIECT, CODOBIECTRETURN, CANT, CANTMIN, UMSEC,/*CODEXTERN,*/ CODPLU,
                               CODINTERN, MASA, LUNGIME, LATIME, INALTIME, LXLAT, LXH, LATXH, GREUTSPECIFICA, IMPLICITTIPDOC, TIP, NR_RANDURI, AdMax, returnabil)
   SELECT SEQ_NARTAMB_CODAMB.NEXTVAL,
          CodObjNou,
          CODOBIECTRETURN,
          CANT,
          CANTMIN,
          UMSEC,
          /*CODEXTERN, */
          CODPLU,
          CODINTERN,
          MASA,
          LUNGIME,
          LATIME,
          INALTIME,
          LXLAT,
          LXH,
          LATXH,
          GREUTSPECIFICA,
          IMPLICITTIPDOC,
          TIP,
          NR_RANDURI, AdMax,
          returnabil
     FROM
         NARTAMB
     WHERE
        CODOBIECT = CodObjSursa;

 END IF;

 INSERT INTO NARTOBJCOLET(CODOBJCOLET, CODOBIECT, INDEXLOCAL, CONTINUT, IDCOLET)
 SELECT
    SEQ_NARTOBJCOLET_COD.NEXTVAL,
    CodObjNou,
    INDEXLOCAL,
    CONTINUT,
    --TRIM(TO_CHAR(SEQ_ETICHCOLET_COD.NEXTVAL, &apos;00009&apos;))
    IDCOLET
 FROM
   NARTOBJCOLET
 WHERE
   CODOBIECT = CodObjSursa;

  -- completare automata traduceri denumiri
  SELECT NVL(AO.TraducArtGeneric, 0) INTO aBifaTrad FROM NARTOBJ AO WHERE AO.CodObiect = CodObjSursa;
  IF aBifaTrad = 1 THEN
    FOR v_lang IN
      (SELECT * FROM NLIMBA WHERE CodLimba &gt; 0 AND ExtLink &lt;&gt; &apos;RO&apos;)
    LOOP
      SELECT COUNT(*) INTO aAreTrad FROM NARTOBJTRAD WHERE CodObiect = CodObjNou AND CodLimba = v_lang.CodLimba;
      IF aAreTrad = 0 THEN
        BEGIN
          SELECT
            AOT.DenumireTrad INTO aDenTrad
          FROM
            NARTOBJ AO
            LEFT OUTER JOIN NARTOBJTRAD AOT ON AOT.CodObiect = AO.CodObiect
          WHERE
            (SELECT COUNT(*) FROM NAtrObj ATRO WHERE ATRO.CodObiect = AO.CodObiect)= 0 AND
            AO.CodArticol = aCodArticol AND
            AOT.CodLimba = v_lang.CodLimba;
          EXCEPTION WHEN NO_DATA_FOUND THEN aDenTrad := NULL;
        END;
        IF aDenTrad IS NOT NULL THEN
          FOR v_atrib IN
            (SELECT ATR1.Valoare
             FROM
               TMP_MANEVRA TMP
               INNER JOIN NATRIB1 ATR1 ON TMP.CodUnic = ATR1.CodValAtr
               INNER JOIN NARTATR ATR ON ATR.CodAtribut = ATR1.CodAtribut
             WHERE ATR.CodArticol = aCodArticol
             ORDER BY ATR.IndexLocal
            )
          LOOP
            aDenTrad := aDenTrad || &apos; &apos; || v_atrib.Valoare;
          END LOOP; -- v_atrib
          INSERT INTO NARTOBJTRAD (CodObiectTrad, CodObiect, CodLimba, DenumireTrad)
          VALUES (SEQ_NARTOBJTRAD_CodObiectTrad.NextVal, CodObjNou, v_lang.CodLimba, aDenTrad);
        END IF;
      END IF;
    END LOOP; -- v_lang
  END IF;

  prc_al_refresh(&apos;NARTOBJ1&apos;,codObjNou);
  COMMIT;
  FOR V_TMP IN (
    SELECT PN.CODATRIBUT
    FROM NATROBJ N
         INNER JOIN NARTATR PN ON PN.CODARTATR = N.CODARTATR
         INNER JOIN TMP_MANEVRA T ON T.CODUNIC = N.CODVALATR
         INNER JOIN NATRIB1 NB1 ON NB1.CODVALATR = N.CODVALATR
         INNER JOIN NATRIB1 NP1 ON NP1.VALOARE = NB1.VALOARE
         INNER JOIN NATROBJ P ON NP1.CODVALATR = P.CODVALATR
         INNER JOIN NARTATR PA ON PA.CODARTATR = P.CODARTATR
    WHERE PA.CODATRIBUT = aCodAtribut AND P.CODOBIECT = vCodProdus AND N.CODOBIECT = codObjNou
  ) LOOP
    vCodAtribut := v_tmp.codatribut;
    Exit;
  END LOOP;

  RETURN codObjNou;
END;

FUNCTION EXPORT_PRETURI_PE_SUBUNIT RETURN NUMBER IS
 SUBUNIT_REF NUMBER(20) ;
 IRES NUMBER(1);
BEGIN
 SUBUNIT_REF := PKG_GLOBALS.GETSUBUNITATE;
 IRES := 1;
        BEGIN
             DELETE FROM TMP_PRETM;
             INSERT INTO TMP_PRETM(CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT, GRUPA, PROC,INDEXLOCAL,SUBUNITATEA,ROTUNJIRE)
             SELECT CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,GRUPA, PROC,INDEXLOCAL,SUBUNITATEA,ROTUNJIRE FROM PRETM WHERE SUBUNITATEA = SUBUNIT_REF ;
             DELETE FROM PRETM;

            FOR V_REC IN (SELECT SUB.CODSUBUNIT FROM NSUBUNIT SUB WHERE  SUB.CODSUBUNIT &gt; 0 ) LOOP
              INSERT INTO PRETM (CODPRETM,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,GRUPA, PROC,INDEXLOCAL,SUBUNITATEA,ROTUNJIRE)
              SELECT SEQ_PRETM_CODPRETM.NEXTVAL,CODOBIECT,CODCATPRET,LEI,VALUTA,MONEDA,IMPLICIT,GRUPA, PROC,INDEXLOCAL,V_REC.CODSUBUNIT,ROTUNJIRE FROM TMP_PRETM ;
            END LOOP;

           COMMIT;
        EXCEPTION WHEN OTHERS THEN
           IRES := 0;
           ROLLBACK;
        END;
  RETURN IRES;
END;

PROCEDURE TMPORDINEGRUPEPRET IS
  vAn   NUMBER        ;
  vLuna NUMBER        ;
  pOrd  VARCHAR2(1000);
  xDen  VARCHAR2(200);
  xVal  VARCHAR2(200);
  vPos  INTEGER;
BEGIN
  vAn    := pkg_globals.ANLUCRU;
  vLuna  := pkg_globals.LUNALUCRU;
  pOrd   := Trim(pkg_categconst.GetValConstanta(&apos;OrdineGrupePret&apos;,vAN,vLUNA));
  DELETE TMP_MANEVRA_LISTE;
  WHILE pOrd IS NOT NULL
  LOOP
    vPos := InStr(pOrd,&apos;=&apos;);
    xDen := Trim(SubStr(pOrd,1,vPos-1));
    pOrd := Trim(SubStr(pOrd,vPos+1));

    vPos := InStr(pOrd,&apos;;&apos;);
    IF vPos &gt; 0 THEN
      xVal := Trim(SubStr(pOrd,1,vPos-1));
      pOrd := Trim(SubStr(pOrd,vPos+1));
    ELSE
      xVal := Trim(pOrd);
      pOrd := &apos;&apos;;
    END IF;
    IF xVal IS NOT NULL THEN
      INSERT INTO TMP_MANEVRA_LISTE (FILTRU, VALOARE) VALUES (xDen, xVal);
    END IF;
  END LOOP;
  COMMIT;
END;

procedure debug is
begin
  delete tmp_manevra_liste;
  insert into tmp_manevra_liste (filtru, valoare)
  values (&apos;CODOBIECT&apos;, 105);
  commit;
  PKG_GLOBALS.SetLunaLucru(2012,6);
  --PKG_GLOBALS.SETSUBUNITATE(2);
  --PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  --CLONARE_PRETM_ATRIB(192, 2);
  UpdateNArtObj1Double(&apos;PretReferinta&apos;, 123);
end;

PROCEDURE PROPAGA_PRETURI_LA_SUBUNITATI
IS
  aCODPRETM   NUMBER(20);
  NRIMPLICITE NUMBER(5);
  aIMPLICIT   NUMBER(1);
BEGIN
  FOR V_REC IN (SELECT * FROM PRETM PM WHERE PM.CODOBIECT IN (SELECT CODUNIC FROM TMP_MANEVRA) AND SUBUNITATEA = PKG_GLOBALS.SUBUNITATE_DOC )
  LOOP
     FOR V_REC_S IN (SELECT CODSUBUNIT FROM NSUBUNIT WHERE CODSUBUNIT &gt; 1 AND CODSUBUNIT &lt;&gt; PKG_GLOBALS.SUBUNITATE_DOC)
     LOOP
       BEGIN
         SELECT CODPRETM INTO aCODPRETM FROM PRETM WHERE CODOBIECT = V_REC.CODOBIECT AND SUBUNITATEA = V_REC_S.CODSUBUNIT AND CODCATPRET = V_REC.CODCATPRET;
         EXCEPTION WHEN OTHERS THEN aCODPRETM := 0;
       END;
       IF aCODPRETM &lt;&gt; 0 THEN
         UPDATE PRETM
         SET
           CODCATPRET  = V_REC.CODCATPRET,
           LEI         = V_REC.LEI,
           VALUTA      = V_REC.VALUTA,
           MONEDA      = V_REC.MONEDA,
           PROC        = V_REC.PROC,
           SUBUNITATEA = V_REC_S.CODSUBUNIT
         WHERE
           CODPRETM = aCODPRETM;
       ELSE
         aIMPLICIT := 0;
         IF V_REC.IMPLICIT = 1 THEN
           SELECT COUNT(*) INTO NRIMPLICITE FROM PRETM WHERE CODOBIECT = V_REC.CODOBIECT AND SUBUNITATEA = V_REC_S.CODSUBUNIT AND IMPLICIT = 1;
           IF NRIMPLICITE &gt; 0 THEN aIMPLICIT := 0;
           ELSE aIMPLICIT := 1;
           END IF;
         END IF;
         INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, PROC, IMPLICIT, INDEXLOCAL, SUBUNITATEA,ROTUNJIRE)
         VALUES(SEQ_PRETM_CODPRETM.NEXTVAL, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.LEI, V_REC.VALUTA, V_REC.MONEDA, V_REC.PROC, aIMPLICIT,  V_REC.INDEXLOCAL, V_REC_S.CODSUBUNIT,
                V_REC.ROTUNJIRE);
       END IF;

     END LOOP;
  END LOOP;
  COMMIT;
END;

PROCEDURE UPDATECodAlt(aCODOBIECT IN NUMBER, aCODALT IN VARCHAR2)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
 NR NUMBER(5);
BEGIN
  SELECT COUNT(*) INTO NR FROM CODEXTALT WHERE CODOBIECT = aCODOBIECT AND CODEXTERN = aCODALT;
  IF NR = 0 THEN
    INSERT INTO CODEXTALT(COD, CODOBIECT, CODEXTERN) VALUES (SEQ_CODEXTALT_COD.NEXTVAL, aCODOBIECT, aCODALT);
  END IF;
  COMMIT;
END;

/*
PROCEDURE EXPORTA_PRETURI(aCODCATIMPLICITA IN NUMBER)
IS
  aCODPRETM        NUMBER(20);
  aIMPLICIT        NUMBER(1)  := 0;
  NR               NUMBER(20) := 0;
  aSyncPretRetail  VARCHAR2(10);
BEGIN
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPretRetail FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aSyncPretRetail := &apos;0&apos;;
  END;


   FOR V_REC_C IN (SELECT * FROM PRETM WHERE SUBUNITATEA = PKG_GLOBALS.SUBUNITATE AND CODCATPRET IN (SELECT CODCATPRET FROM TMP_NCATPRET))
   LOOP

     FOR V_REC_S IN (SELECT * FROM TMP_NSUBUNIT) LOOP
       BEGIN
         SELECT
           CODPRETM INTO aCODPRETM FROM PRETM
         WHERE
           CODOBIECT = V_REC_C.CODOBIECT AND CODCATPRET = V_REC_C.CODCATPRET AND SUBUNITATEA = V_REC_S.CODSUBUNIT;
         EXCEPTION WHEN OTHERS THEN aCODPRETM := 0;
       END;

       IF aCODPRETM = 0 THEN
         aIMPLICIT := 0;
         IF V_REC_C.IMPLICIT = 1 THEN
           SELECT COUNT(*) INTO NR
           FROM
             PRETM
           WHERE
             CODOBIECT = V_REC_C.CODOBIECT AND SUBUNITATEA = V_REC_S.CODSUBUNIT AND IMPLICIT = 1;

           IF NR = 0 THEN
              aIMPLICIT := 1;
           END IF;

         END IF;

         INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, PROC, IMPLICIT, SUBUNITATEA,ROTUNJIRE)
                     VALUES(SEQ_PRETM_CODPRETM.NEXTVAL, V_REC_C.CODOBIECT, V_REC_C.CODCATPRET,  V_REC_C.LEI, V_REC_C.VALUTA, V_REC_C.MONEDA, V_REC_C.PROC, aIMPLICIT, V_REC_S.CODSUBUNIT,
                            V_REC_C.ROTUNJIRE);

       ELSE
         UPDATE PRETM
         SET
           LEI    = V_REC_C.LEI,
           VALUTA = V_REC_C.VALUTA,
           MONEDA = V_REC_C.MONEDA
         WHERE
           CODPRETM = aCODPRETM;
       END IF;

       IF (aCODCATIMPLICITA &lt;&gt; 0) THEN
         SELECT COUNT(*) INTO NR
         FROM
           PRETM
         WHERE
           SUBUNITATEA = V_REC_S.CODSUBUNIT

           AND CODOBIECT = V_REC_C.CODOBIECT
           AND CODCATPRET = aCODCATIMPLICITA;

          IF NR &lt;&gt; 0 THEN
            UPDATE PRETM SET IMPLICIT = 0 WHERE SUBUNITATEA = V_REC_S.CODSUBUNIT AND CODOBIECT = V_REC_C.CODOBIECT;
            UPDATE PRETM SET IMPLICIT = 1 WHERE SUBUNITATEA = V_REC_S.CODSUBUNIT AND CODOBIECT = V_REC_C.CODOBIECT AND CODCATPRET = aCODCATIMPLICITA;
          END IF;
       END IF;


       IF aSyncPretRetail = &apos;1&apos; THEN
         PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_C.CODOBIECT, V_REC_S.CODSUBUNIT);
       END IF;
     END LOOP;
   END LOOP;
END;
*/
PROCEDURE COPIE_CATEG_PRETURI
IS
  aIMPLICIT        NUMBER(1)  := 0;
  aSyncPretRetail  VARCHAR2(10);
  aMemoModiPret    VARCHAR2(10);
  CodSubCurent     NUMBER(20);
BEGIN
   CodSubCurent :=  PKG_GLOBALS.SUBUNITATE;
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPretRetail FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aSyncPretRetail := &apos;0&apos;;
  END;

  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aMemoModiPret FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aMemoModiPret := &apos;0&apos;;
  END;
  FOR V_REC_I IN (SELECT * FROM TMP_CPPRETINFO)
  LOOP

    FOR V_REC_C IN ( SELECT
                       PMB.*,
                       NVL(PMS.CODPRETM, 0) AS CODPRETMS,
                       NVL(PMS.LEI, 0) AS PMSLEI,
                       NVL(PMS.VALUTA, 0) AS PMSVALUTA,
                       NVL(PMS.MONEDA, 0) AS PMSMONEDA,
                       NVL(PMS.IMPLICIT, 0) AS PMSIMPLICIT,
                       NVL(PMSI.CODPRETM, 0) AS CODPRETMSI
                     FROM
                       PRETM PMB
                       LEFT JOIN PRETM PMS  ON PMS.CODOBIECT = PMB.CODOBIECT 
                                                             AND PMS.CODCATPRET = V_REC_I.CODCATPRET_DEST 
                                                             AND PMS.SUBUNITATEA = V_REC_I.CODSUBUNIT_DEST
                       LEFT JOIN PRETM PMSI ON PMSI.CODOBIECT = PMB.CODOBIECT 
                                               AND PMSI.SUBUNITATEA = V_REC_I.CODSUBUNIT_DEST
                                               AND PMSI.IMPLICIT = 1
                     WHERE
                       PMB.SUBUNITATEA = CODSUBCURENT
                       AND PMB.CODCATPRET = V_REC_I.CODCATPRET_SURSA
     )
     LOOP
         aIMPLICIT := 0;
         IF (coalesce(V_REC_I.suprascrie_implicit, 0) = 1) THEN
             aIMPLICIT := 1; 
             IF (V_REC_C.CODPRETMSI &gt; 0) AND (V_REC_C.CODPRETMSI &lt;&gt; V_REC_C.CODPRETMS) THEN
               UPDATE PRETM PM SET IMPLICIT = 0 WHERE PM.CODPRETM = V_REC_C.CODPRETMSI;
             END IF;
         ELSE
           IF V_REC_C.IMPLICIT = 1 AND V_REC_C.CODPRETMSI = 0 THEN
              aIMPLICIT := 1;
           END IF;
         end if;   
       
         IF V_REC_C.CODPRETMS = 0 THEN

           INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, PROC, IMPLICIT, SUBUNITATEA, ROTUNJIRE, GRUPA, SUMAFIXAIMPLICIT)
                       VALUES(SEQ_PRETM_CODPRETM.NEXTVAL, V_REC_C.CODOBIECT, V_REC_I.CODCATPRET_DEST,  V_REC_C.LEI, 
                                    V_REC_C.VALUTA, V_REC_C.MONEDA, V_REC_C.PROC, aIMPLICIT, V_REC_I.CODSUBUNIT_DEST, V_REC_C.ROTUNJIRE,
                                    V_REC_C.GRUPA, V_REC_C.SUMAFIXAIMPLICIT);

           IF aSyncPretRetail = &apos;1&apos; THEN
             PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_C.CODOBIECT, V_REC_I.CODSUBUNIT_DEST);
           END IF;

           IF aMemoModiPret = &apos;1&apos; THEN
             PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_C.CODOBIECT, V_REC_I.CODSUBUNIT_DEST);
           END IF;

         ELSE
           IF V_REC_C.LEI    &lt;&gt; V_REC_C.PMSLEI OR
              V_REC_C.VALUTA &lt;&gt; V_REC_C.PMSVALUTA OR
              V_REC_C.MONEDA &lt;&gt; V_REC_C.PMSMONEDA OR
              aIMPLICIT      &lt;&gt; V_REC_C.PMSIMPLICIT
           THEN
             UPDATE PRETM
             SET
               LEI    = V_REC_C.LEI,
               VALUTA = V_REC_C.VALUTA,
               MONEDA = V_REC_C.MONEDA,
               IMPLICIT = aIMPLICIT
             WHERE
               CODPRETM = V_REC_C.CODPRETMS;

             IF aSyncPretRetail = &apos;1&apos; THEN
               PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_C.CODOBIECT, V_REC_I.CODSUBUNIT_DEST);
             END IF;

             IF aMemoModiPret = &apos;1&apos; THEN
               PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_C.CODOBIECT, V_REC_I.CODSUBUNIT_DEST);
             END IF;

           END IF;

         END IF;
     END LOOP;
   END LOOP;
END;


PROCEDURE EXPORTA_PRETURI(aCODCATIMPLICITA IN NUMBER)
IS
  aIMPLICIT        NUMBER(1)  := 0;
  aSyncPretRetail  VARCHAR2(10);
  aMemoModiPret    VARCHAR2(10);
  CodSubCurent     NUMBER(20);

BEGIN
   CodSubCurent :=  PKG_GLOBALS.SUBUNITATE;
  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPretRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPretRetail FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aSyncPretRetail := &apos;0&apos;;
  END;

  BEGIN
     SELECT PKG_CATEGCONST.GetValConstanta(&apos;MemoModiPret&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aMemoModiPret FROM DUAL;
     EXCEPTION WHEN OTHERS THEN aMemoModiPret := &apos;0&apos;;
  END;


  FOR V_REC_S IN (SELECT * FROM TMP_NSUBUNIT)
  LOOP
    FOR V_REC_C IN ( SELECT
                       PMB.*,
                       NVL(PMS.CODPRETM, 0) AS CODPRETMS,
                       NVL(PMS.LEI, 0) AS PMSLEI,
                       NVL(PMS.VALUTA, 0) AS PMSVALUTA,
                       NVL(PMS.MONEDA, 0) AS PMSMONEDA,
                       NVL(PMSI.CODPRETM, 0) AS CODPRETMSI
                     FROM
                       PRETM PMB
                       LEFT JOIN PRETM PMS  ON PMS.CODOBIECT = PMB.CODOBIECT AND PMS.CODCATPRET = PMB.CODCATPRET AND PMS.SUBUNITATEA = V_REC_S.CODSUBUNIT
                       LEFT JOIN PRETM PMSI ON PMSI.CODOBIECT = PMB.CODOBIECT AND PMSI.SUBUNITATEA = V_REC_S.CODSUBUNIT AND PMSI.IMPLICIT = 1
                     WHERE
                       PMB.SUBUNITATEA = CODSUBCURENT
                       AND EXISTS (SELECT CODCATPRET FROM TMP_NCATPRET TC WHERE TC.CODCATPRET = PMB.CODCATPRET)
     )
     LOOP
         IF V_REC_C.CODPRETMS = 0 THEN
           aIMPLICIT := 0;

           IF V_REC_C.IMPLICIT = 1 AND V_REC_C.CODPRETMSI = 0 THEN
             aIMPLICIT := 1;
           END IF;

           INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, PROC, IMPLICIT, SUBUNITATEA,ROTUNJIRE)
                       VALUES(SEQ_PRETM_CODPRETM.NEXTVAL, V_REC_C.CODOBIECT, V_REC_C.CODCATPRET,  V_REC_C.LEI, V_REC_C.VALUTA, V_REC_C.MONEDA, V_REC_C.PROC, aIMPLICIT, V_REC_S.CODSUBUNIT,
                              V_REC_C.ROTUNJIRE);

           IF aSyncPretRetail = &apos;1&apos; THEN
             PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_C.CODOBIECT, V_REC_S.CODSUBUNIT);
           END IF;

           IF aMemoModiPret = &apos;1&apos; THEN
             PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_C.CODOBIECT, V_REC_S.CODSUBUNIT);
           END IF;

         ELSE
           IF V_REC_C.LEI    &lt;&gt; V_REC_C.PMSLEI OR
              V_REC_C.VALUTA &lt;&gt; V_REC_C.PMSVALUTA OR
              V_REC_C.MONEDA &lt;&gt; V_REC_C.PMSMONEDA
           THEN
             UPDATE PRETM
             SET
               LEI    = V_REC_C.LEI,
               VALUTA = V_REC_C.VALUTA,
               MONEDA = V_REC_C.MONEDA
             WHERE
               CODPRETM = V_REC_C.CODPRETMS;

             IF aSyncPretRetail = &apos;1&apos; THEN
               PKG_POSTRETAIL.MEMO_MODIF_PRET_RETAIL(V_REC_C.CODOBIECT, V_REC_S.CODSUBUNIT);
             END IF;

             IF aMemoModiPret = &apos;1&apos; THEN
               PKG_GLOBALS.MEMO_MODIFICARE_PRET(V_REC_C.CODOBIECT, V_REC_S.CODSUBUNIT);
             END IF;

           END IF;

         END IF;
     END LOOP;
   END LOOP;

   IF aCODCATIMPLICITA &lt;&gt; 0 THEN
      UPDATE PRETM
      SET
        IMPLICIT = 0
      WHERE
        CODCATPRET &lt;&gt; aCODCATIMPLICITA
        AND SUBUNITATEA &lt;&gt; CodSubCurent;

      UPDATE PRETM
      SET
        IMPLICIT = 1
      WHERE
        CODCATPRET = aCODCATIMPLICITA
        AND SUBUNITATEA &lt;&gt; CodSubCurent;
   END IF;

END;

PROCEDURE PROPAGAOPTIONALE(aCodSursa in number) is
begin
  for v_rec in (select to_number(valoare) codobiect from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos; and valoare &lt;&gt; aCodSursa) loop
    delete nartopt where codobiect = v_rec.codobiect;
    insert into nartopt (codopt, codobiect, codobiectopt, CodTipLocatie, ForceLei, standard, cant, obs)
    select seq_nartopt_codopt.nextval, v_rec.codobiect, codobiectopt, CodTipLocatie, ForceLei, standard, cant, obs
    from nartopt
    where codobiect = aCodSursa;

    delete tmp_nartopt where codobiect = v_rec.codobiect;
    INSERT INTO TMP_NARTOPT
    (CODOPT, CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, OBS, DENOBIECTOPT, CODEXTERN, CODINTERN, SELECTAT )
    (SELECT CODOPT, A.CODOBIECT, codobiectopt, CodTipLocatie, ForceLei, CANT, STANDARD, A.OBS, O.DENUMIRE, O.CODEXTERN, O.CODINTERN, 0
     FROM NARTOPT A
          LEFT JOIN NARTOBJ O on O.CODOBIECT = A.codobiectopt
	   WHERE A.CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ) AND A.CODOBIECT = V_REC.CODOBIECT);
  end loop;
  COMMIT;
end;

procedure UpdateDuriRet is
  tmp number(20);
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_37&apos;;
begin
  for v_art in (select codarticol, D1, D2, D3, RelatieUM1 from nart where codarticol &gt; 0) loop
    for v_rec in (select pc.codprodcomp, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc
                  from prodcomp pc
                       inner join nartobj o on o.codobiect = pc.codobiect
                  where exists (select obj.codobiect from nartobj obj where pc.codobiect = obj.codobiect and obj.codarticol = v_art.codarticol)) loop
      begin
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
        END IF;
        update prodcomp pc
        set
          D1 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D1 END,
          D2 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D2 END,
          D3 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D3 END
        where pc.codprodcomp = v_Rec.Codprodcomp;
        update prodcomp pc set
        cantum1 = round(CASE
                          WHEN v_art.RELATIEUM1 IN (1, 7) AND NVL(v_art.D1, 0) &lt;&gt; 0 THEN cant/v_art.D1
                          WHEN v_art.RELATIEUM1 IN (2, 8) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0))
                          WHEN v_art.RELATIEUM1 IN (3, 9) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0) * NVL(v_art.D3,0))
                          WHEN v_art.RELATIEUM1 IN (4, 10) THEN cant * NVL(v_art.D1,0)
                          WHEN v_art.RELATIEUM1 IN (5, 11) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0)
                          WHEN v_art.RELATIEUM1 IN (6, 12) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0)
                          ELSE NULL
                        END,7)
        where exists (select obj.codobiect from nartobj obj where pc.codobiect = obj.codobiect and obj.codarticol = v_art.codarticol);
        NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
        commit;
      exception when others then rollback;
      end;
    end loop;
    for v_rec in (select pm.codprodcomp, pm.codmat, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc
                  from prodmat pm
                       inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                       inner join nartobj o on o.codobiect = pc.codobiect
                  where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = v_art.codarticol)) loop
      begin
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
        END IF;
        update prodmat pc
        set
          D1 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D1 END,
          D2 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D2 END,
          D3 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D3 END
        where codmat = v_rec.codmat;
        update prodmat pc set
        cantum1 = round(CASE
                          WHEN v_art.RELATIEUM1 IN (1, 7) AND NVL(v_art.D1, 0) &lt;&gt; 0 THEN cant/v_art.D1
                          WHEN v_art.RELATIEUM1 IN (2, 8) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0))
                          WHEN v_art.RELATIEUM1 IN (3, 9) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0) * NVL(v_art.D3,0))
                          WHEN v_art.RELATIEUM1 IN (4, 10) THEN cant * NVL(v_art.D1,0)
                          WHEN v_art.RELATIEUM1 IN (5, 11) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0)
                          WHEN v_art.RELATIEUM1 IN (6, 12) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0)
                          ELSE NULL
                        END,7)
        where codmat = v_rec.codmat;
        NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
        commit;
      exception when others then rollback;
      end;
    end loop;
    for v_rec in (select pm.codprodcomp, pm.codrez, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc
                  from prodrez pm
                       inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                       inner join nartobj o on o.codobiect = pc.codobiect
                  where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = v_art.codarticol)) loop
      begin
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
        END IF;
        update prodrez pc
        set
          D1 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D1 END,
          D2 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D2 END,
          D3 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D3 END
        where codrez = v_rec.codrez;
        update prodrez pc set
        cantum1 = round(CASE
                          WHEN v_art.RELATIEUM1 IN (1, 7) AND NVL(v_art.D1, 0) &lt;&gt; 0 THEN cant/v_art.D1
                          WHEN v_art.RELATIEUM1 IN (2, 8) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0))
                          WHEN v_art.RELATIEUM1 IN (3, 9) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0) * NVL(v_art.D3,0))
                          WHEN v_art.RELATIEUM1 IN (4, 10) THEN cant * NVL(v_art.D1,0)
                          WHEN v_art.RELATIEUM1 IN (5, 11) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0)
                          WHEN v_art.RELATIEUM1 IN (6, 12) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0)
                          ELSE NULL
                        END,7)
        where codrez = v_rec.codrez;
        NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
        commit;
      exception when others then rollback;
      end;
    end loop;
    for v_rec in (select pm.codprodcomp, pm.codnormemat, pc.DATA DataDoc, &apos;OBJ:&apos;||o.denumire||&apos; VER:&apos;||pc.OBS||&apos; (&apos;||pc.CODPRODCOMP||&apos;)&apos; Doc
                  from normemat pm
                       inner join prodcomp pc on pc.codprodcomp = pm.codprodcomp
                       inner join nartobj o on o.codobiect = pc.codobiect
                  where exists (select obj.codobiect from nartobj obj where pm.codobiect = obj.codobiect and obj.codarticol = v_art.codarticol)) loop
      begin
        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.DataDoc, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
        END IF;
        SELECT CodProdComp INTO Tmp FROM prodcomp WHERE CodProdComp = v_rec.codprodcomp FOR UPDATE NOWAIT;
        update normemat pc
        set
          D1 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D1 END,
          D2 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D2 END,
          D3 = CASE WHEN v_art.RELATIEUM1 = 0 THEN NULL ELSE v_art.D3 END
        where codnormemat = v_rec.codnormemat;
        update normemat pc set
        cantum1 = round(CASE
                          WHEN v_art.RELATIEUM1 IN (1, 7) AND NVL(v_art.D1, 0) &lt;&gt; 0 THEN cant/v_art.D1
                          WHEN v_art.RELATIEUM1 IN (2, 8) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0))
                          WHEN v_art.RELATIEUM1 IN (3, 9) AND NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0) &lt;&gt; 0 THEN cant / (NVL(v_art.D1,0) * NVL(v_art.D2,0) * NVL(v_art.D3,0))
                          WHEN v_art.RELATIEUM1 IN (4, 10) THEN cant * NVL(v_art.D1,0)
                          WHEN v_art.RELATIEUM1 IN (5, 11) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0)
                          WHEN v_art.RELATIEUM1 IN (6, 12) THEN cant * NVL(v_art.D1, 0) * NVL(v_art.D2, 0) * NVL(v_art.D3, 0)
                          ELSE NULL
                        END,7)
        where codnormemat = v_rec.codnormemat;
        NotifyModif(0, v_rec.codprodcomp, &apos;PRODCOMP&apos;);
        commit;
      exception when others then rollback;
      end;
    end loop;
  end loop;
end;

END pkg_Nom_Articol;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOM_PARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4242B6496059CA427F424AB1D1CAB53965D7C17</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_nom_parcaut IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_72&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodNParcAut INTO Tmp FROM NPARCAUT WHERE CodNParcAut = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDoc varchar2(100);
BEGIN
  --nomAuto = 505;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 505);
  
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Nr.auto: &apos;||NrInreg INTO aDoc FROM nparcAut WHERE CodnparcAut = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARCAUT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  UPDATE MIFIX1 SET CODAUTO = NULL WHERE CODAUTO = RECID;
   -- sterg intai din NPARC1 si NPARC2 si nparc3
  DELETE FROM NPARC0 WHERE CodNPArcAUT = RecId;
  DELETE FROM NPARCG WHERE CodNPArcAUT = RecId;
  DELETE FROM NPARC1 WHERE Cod = RecId;
  DELETE FROM NPARC2 WHERE Cod = RecId;
  DELETE FROM NPARC3 WHERE Cod = RecId;

  DELETE COMANDA3 C3 WHERE C3.CodComanda2 in (Select C2.CodComanda2 from Comanda2 C2 where C2.CodNParcAut = recid);
  DELETE COMANDA2 WHERE CodNParcAut = recid;
  
  DELETE FROM NPARCAUT WHERE CodNParcAut = RecId;
  NotifyModif(2, RECID, &apos;NPARCAUT&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NPARCAUT FIELDS( CodNParcAut ) VALUES (0) ;
  --nomAuto                        = 505;
  PKG_CFGTABLES.EXT_INSERTRECORD(505); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aNr number;
aGest number;
BEGIN
  -- Master NPARCAUT
  INSERT INTO  TMP_NPARCAUT (
    CodNParcAut, CodArt, NrInv, NrInreg, Sofer, KmPornire, Tip, DataInreg, Marca, Model, AnF,
    SerieC, Culoare, Lung, Lat, Inalt, TipMotor, SerieM, Motor, Cilindree, Putere, CmM,
    CmU, CmE, TipIncarc, Greutate, MasaM, MasaU, MasaURDF, MasaURFDF, LocT, LocF, LocS,
    LocP, AnvRecomF, AnvRecomS, AnvOpt1F, AnvOpt1S, AnvOpt2F, AnvOpt2S, Kg, Kgr, Sarcina,
    CodPutere, GrupAuto, TipRem, InstSp, Aer, Rezervor, VolumU, CuloareC, Den_Obiect, SursaE, TipUlei ,
    TipVehicul, CodDealer, LimitaKM, Dotari, CodRadio, Transmisie, Tractiune, GPS, CodPartGPS, Frigo, GPL,NumeDealer,
    Extern, Partener, codgest,nrcontr, PartLeas,moneda,rataleas,ratarca,ratacasco,dataachiz,dataendleas,partutiliz,
    persutiliz,obs, Inactiv, Gr_obiect, CodExtern, CodArtComb, ConsStatH)
  SELECT
    P.CodNParcAut, P.CodArt, P.NrInv, P.NrInreg, P.Sofer, P.KmPornire, P.Tip, P.DataInreg, P.Marca, P.Model, P.AnF,
    P.SerieC, P.Culoare, P.Lung, P.Lat, P.Inalt, P.TipMotor, P.SerieM, P.Motor, P.Cilindree, P.Putere, P.CmM,
    P.CmU, P.CmE, nvl(P.TipIncarc,1), P.Greutate, P.MasaM, P.MasaU, P.MasaURDF, P.MasaURFDF, P.LocT, P.LocF, P.LocS,
    P.LocP, P.AnvRecomF, P.AnvRecomS, P.AnvOpt1F, P.AnvOpt1S, P.AnvOpt2F, P.AnvOpt2S, P.Kg, P.Kgr, P.Sarcina,
    P.CodPutere, P.GrupAuto, P.TipRem, P.InstSp, P.Aer, P.Rezervor, P.VolumU, P.CuloareC, OBJ.Denumire, P.SursaE, P.TipUlei,
    P.TipVehicul, P.CodDealer, P.LimitaKM, P.Dotari, P.CodRadio, P.Transmisie, P.Tractiune, P.GPS, CodPartGPS, Frigo, P.GPL, Np.Den_Part NumeDealer,
    Nvl(P.Extern,0), P.Partener, P.codgest,P.nrcontr, PartLeas,P.moneda,P.rataleas,P.ratarca,P.ratacasco,P.dataachiz,
    P.dataendleas,P.partutiliz,P.persutiliz,P.obs, nvl(P.Inactiv,0), Gr.Denumire, P.CodExtern, P.CodArtComb, P.ConsStatH
  FROM NPARCAUT P
    LEFT JOIN NARTOBJ OBJ ON P.CODART = OBJ.CODOBIECT
    LEFT JOIN NECHIV E ON E.CODOBIECT = OBJ.CODOBIECT
    LEFT JOIN GRECHIV Gr ON Gr.Codgrechiv = E.CODGRUPA
    LEFT JOIN NPART NP on NP.Codpart = P.CodDealer
  WHERE CodNParcAut = RecId;

  begin
    select Nvl(NrInv,0), Nvl(codgest,0) into aNR, aGest from TMP_NPARCAUT;
		if aGest = 0 then 
			SELECT N.GEST into aGest FROM MIFIX MX, MIFIX1 MX1, NIRSTOC NS, NIR N
			WHERE MX.TIP = &apos;MF&apos;
					AND MX1.CODMIFIX = MX.CODMIFIX
					AND MX1.ANSTART * 12 + MX1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM MIFIX1 MX2 WHERE MX2.CODMIFIX = MX.CODMIFIX)
					AND MX1.CODNIRSTOC = NS.CODNIRSTOC AND N.CODNIR = NS.CODNIR
					AND MX.NRINVENTAR = aNR;
			UPDATE TMP_NPARCAUT SET codgest = aGEST;
		end if;
  exception when others then
    aGest := 0;
	end;


  -- Detail NParcG
  INSERT INTO  TMP_NParcG ( CODNParcG, CODNPARCAUT, CodGestIni, CodGest, CodCmd, Status, Data, CMD)
               ( SELECT     CODNParcG, CODNPARCAUT, CodGestIni, PG.CodGest, CodCmd, Status, Data,
														C.PREFIXDOC||&apos; &apos;||C.SERIADOC||C.NRDOC
               FROM NParcG PG
                    LEFT JOIN COMANDA C ON C.CodComanda = PG.CodCmd
               WHERE PG.CodNPARCAUT = RecId );
  -- Detail NPARC0
  INSERT INTO  TMP_NPARC0 ( CODNPARC0, CODNPARCAUT, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd, SOFER, FAZ, CMD)
               ( SELECT     P0.CODNPARC0, P0.CODNPARCAUT, P0.DATABord, P0.KMBord, P0.AN, P0.LUNA, P0.OBS, P0.CODPERS, P0.CodFAZ, Comb, P0.CodCmd,
                            S.NUME||&apos; &apos;||S.PRENUME, 
														FAZ.PREFIXDOC||&apos; &apos;||FAZ.NRDOC||&apos;/&apos;||TO_CHAR(FAZ.DATADOC, &apos;DD.MM.YYYY&apos;),
														CMD.PREFIXDOC||&apos; &apos;||CMD.NRDOC||&apos;/&apos;||TO_CHAR(CMD.DATADOC, &apos;DD.MM.YYYY&apos;)
               FROM NPARC0 P0
                    LEFT JOIN NPERS S ON S.CODPERS = P0.CODPERS
                    LEFT JOIN FAZ ON FAZ.CodFAZ = P0.CodFAZ
                    LEFT JOIN COMANDA CMD ON CMD.CodComanda = P0.CodCmd
               WHERE P0.CodNPARCAUT = RecId );
  -- Detail NPARC1
  INSERT INTO  TMP_NPARC1 ( CodNParc1, Cod, IndexLocal, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, 
                            ADANCIME, LATIME, INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, Ms, Obs, Seria, DOT, DenObiect, DenUm, BordDem,
                            CodNirStoc, CodNirSer, Serie )
               ( SELECT     p1.CodNParc1, p1.Cod, p1.IndexLocal, p1.Art, p1.Cant, p1.Pozitie, p1.BordInstal, p1.atentie,codpart,Montat, Anotimp,
                            P1.ADANCIME, P1.LATIME, P1.INALTIME, P1.DIAMETRU, P1.GAMA, P1.RUNFLAT, P1.SUV, P1.OFFROAD, P1.XL, NVL(P1.Ms,0), P1.OBS, P1.Seria, P1.DOT, obj.denumire, um.den_um,
                            P1.Borddem, P1.CodNirStoc, P1.CodNirSer, SER.Serie
               FROM NPARC1 p1 left join NARTOBJ obj on p1.Art = obj.codobiect
                              left join NART nart on nart.codarticol = obj.codarticol
                              left join NIRSER NSE ON NSE.CODNIRSER = P1.CODNIRSER
                              left join NSERII SER ON SER.CODSERIE = NSE.CODSERIE
                              inner join num um on um.codum = nart.um
               WHERE p1.Cod = RecId );
  -- Detail NPARC2
  INSERT INTO TMP_NPARC2 (CodNParc2,Cod,IndexLocal,Doc,SN,Eliberat,Expira,atentie,Obs,Valoare,CodIntr1,Denumire,Document)
              (
               SELECT P2.CodNParc2,P2.Cod,P2.IndexLocal,P2.Doc,P2.SN,P2.Eliberat,P2.Expira,P2.atentie,P2.Obs,P2.Valoare,P2.CodIntr1,P2.Denumire,
                      CASE
                        WHEN A.CODAUTORIZATII &gt; 0 THEN A.DENUMIRE
                        ELSE I.PREFIXDOC||&apos; &apos;||I.NRDOC
                      END
               FROM NPARC2 P2
                    LEFT JOIN NAUTORIZATIIAUTO A ON P2.DOC = A.CODAUTORIZATII
                    LEFT JOIN INTRARI1 I1 ON I1.CODINTR1 = P2.CODINTR1
                    LEFT JOIN INTRARI I ON I1.CODINTR = I.CODINTR
               WHERE Cod = RecId
              );
  --Detail NPARC3
  INSERT INTO  TMP_NPARC3 ( CodNParc3, Cod, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare, Denumire )
               ( SELECT     p3.CodNParc3, p3.Cod, p3.Interventie, p3.DataU, p3.KmU, p3.DataV, p3.KmV, p3.DataA, p3.KMA, CodCMD, Valoare, i.denumire
               FROM NPARC3 P3
                    inner join ninterventiiauto i on p3.interventie = i.codinterventiiauto
               WHERE Cod = RecId );

  --Detail NPARCCOM
  INSERT INTO  TMP_NPARCCOM ( codnparccom, codcomanda, codnparcaut, kmbord,TipComSa, 
                              partcom, DataInchiderii, InmatrRom, Inspectie, PieseClient, ProbaDrum, Spalare, DZ, NivRezervor, NrDosarDaune, NrAutRep, DataAutRep, 
                              datacom, obs,obscom,
                              ParcPropriu, Inmatriculare, SerieAuto, Marca, Model, Culoare, Energie, TipRAC, 
															Document, DataFabr )
  SELECT PC.codnparccom, PC.codcomanda, PC.codnparcaut, PC.kmbord,PC.TipComSa, 
         P.Den_Part, Nvl(R.DataStop, PC.DataInchiderii), PC.InmatrRom, PC.Inspectie, PC.PieseClient, PC.ProbaDrum, PC.Spalare, PC.DZ, PC.NivRezervor, PC.NrDosarDaune, PC.NrAutRep, PC.DataAutRep, 
--         C.SERIADOC, C.NRDOC, C.Valoare, M.Simbol, 
         Nvl(R.DataStart, C.DATADOC), C.Obs,PC.Obs,
         A.Extern, A.DATAINREG, A.Seriec , A.Marca, A.Model, A.Culoare, A.Sursae, 
				 R.TipRezervare, C.PREFIXDOC||C.SERIADOC||C.NRDOC, 
				 A.Anf 
  FROM NPARCCOM PC
    INNER JOIN COMANDA C ON C.CodComanda = PC.CODCOMANDA
    LEFT JOIN RAC_REZ R ON R.CodComanda = PC.CODCOMANDA
    LEFT JOIN NPART P ON P.CodPart = C.Partener
    LEFT JOIN NPARCAUT A on A.CODNPARCAUT = PC.CODNPARCAUT
    LEFT JOIN NMonede M ON M.CodMoNeda = C.Moneda
  WHERE PC.CodNParcAut = RecId;

	INSERT INTO  TMP_NPARCCOM1
	     ( CODCOMANDA3,CODCOMANDA2,
			   Comanda,DataStart, Data,
				 CANT,PRET,TIP,EXECUTAT,
			   operatie,lucrare,garantie, CODLUCRARE,CODOPERATIE,CODREZERVARE, CodIntr1_1, CodIntr1_2, CodIntr1_3,DocIntr_1, DocIntr_2, DocIntr_3)
	SELECT CODCOMANDA3,c2.CODCOMANDA2,
	       Document, C3.DataStart, C3.Data,
	       CANT,PRET,C3.TIP,EXECUTAT,
	       O.Denumire,Tl.Denumire,garantie , CODLUCRARE,CODOPERATIE,c3.CODREZERVARE, 
                             C3.CodIntr1_1, C3.CodIntr1_2, C3.CodIntr1_3, 
                             (select i1_1.prefixdoc||&apos; &apos;||i1_1.SeriaDoc||i1_1.NrDoc||&apos;/&apos;||i1_1.datadoc 
                                   from intrari1 i1 
                                   inner join intrari i1_1 on i1_1.codintr=i1.codintr 
                                   where i1.codintr1 = CodIntr1_1)  DocIntr_1,
                             (select i1_2.prefixdoc||&apos; &apos;||i1_2.SeriaDoc||i1_2.NrDoc||&apos;/&apos;||i1_2.datadoc 
                                   from intrari1 i1 
                                   inner join intrari i1_2 on i1_2.codintr=i1.codintr 
                                   where i1.codintr1 = CodIntr1_2)  DocIntr_2, 
                             (select i1_3.prefixdoc||&apos; &apos;||i1_3.SeriaDoc||i1_3.NrDoc||&apos;/&apos;||i1_3.datadoc 
                                   from intrari1 i1 
                                   inner join intrari i1_3 on i1_3.codintr=i1.codintr 
                                   where i1.codintr1 = CodIntr1_3) DocIntr_3
	FROM COMANDA2 c2 
	     inner join COMANDA3 C3 on C2.CodComanda2 = C3.CodComanda2
       inner join Tiplucrarisa TL on TL.CODTIPLUCRARE = C2.CODLUCRARE
			 inner join NOper O on O.CodOp = C3.CODOPERATIE
       left join TMP_NPARCCOM x on x.CodComanda = c2.codcomanda
			 left join NPart P on P.CodPart = coalesce(C2.CodPart,0)
	where c2.codNParcAut = RecID
	order by Datacom;
  --nomAuto = 505;
	PKG_CFGTABLES.EXT_GOTORECORD(505);	 
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  IndexCount Number(20);
	vCod number(20);
	aInactivOld number(2); 
	aCodGestOld number(20);
	aInactivNew number(2); 
	aStatus     number(2); 
	aCodGestNew number(20);
	aData date;
	aDoc        varchar2(100);
  aOldCodMifix   number(20);
  aNewCodMifix   number(20);
  aCount number;
  aCount1 number;
  e_stergere_eronata EXCEPTION;
  PRAGMA exception_init( e_stergere_eronata, -20001 ); 
BEGIN
  --nomAuto = 505;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (505); 
  UPDATE TMP_NPARCAUT SET codgest = null where Nvl(codgest,0) = 0;
  IF OPERATION = 0 THEN  -- UPDATE
    -- Master NPARCAUT
    SELECT  CodNParcAut INTO RecId FROM TMP_NPARCAUT;
    begin
      select mf.codmifix into aOldCodMifix 
      from nparcaut a
           inner join mifix mf on mf.nrinventar = a.nrinv
      where codnparcaut = recid and mf.tip = &apos;MF&apos;;
    exception when others then aOldCodMifix := 0;
    end;
    begin
      select mf.codmifix into aNewCodMifix 
      from tmp_nparcaut a
           inner join mifix mf on mf.nrinventar = a.nrinv AND MF.TIP = &apos;MF&apos;;
    exception when others then aNewCodMifix := 0;
    end;
    if aOldCodMifix &gt; 0 then
      update mifix1 set codauto = null where codauto = recid and codmifix = aOldCodMifix;
    end if;
    if aNewCodMifix &gt; 0 then
      update mifix1 set codauto = recid where anstart = pkg_globals.GetANLUCRU and lunastart = pkg_globals.GetLUNALUCRU and codmifix = aNewCodMifix;
    end if;

		IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
		 SELECT &apos;Nr.auto: &apos;||NrInreg INTO aDoc FROM TMP_NParcAut WHERE CodnparcAut = recid;
		 WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARCAUT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
		END IF;

    aStatus := 5;
		Select Nvl(inactiv,0), Nvl(CodGest,0) into aInactivOld, aCodGestOld FROM NParcAut WHERE CodNPARCAUT = RecId;
    Select Nvl(inactiv,0), CodGest into aInactivNew, aCodGestNew FROM TMP_NParcAut;

    UPDATE NPARCAUT SET ( CodArt, NrInv, NrInreg, Sofer, KmPornire, Tip, DataInreg, Marca, Model, AnF,
                          SerieC, Culoare, Lung, Lat, Inalt, TipMotor, SerieM, Motor, Cilindree, Putere, CmM,
                          CmU, CmE, TipIncarc, Greutate, MasaM, MasaU, MasaURDF, MasaURFDF, LocT, LocF, LocS,
                          LocP, AnvRecomF, AnvRecomS, AnvOpt1F, AnvOpt1S, AnvOpt2F, AnvOpt2S, Kg, Kgr, Sarcina,
                          CodPutere, GrupAuto, TipRem, InstSp, Aer, Rezervor, VolumU, CuloareC, SursaE, TipUlei,
                          TipVehicul, CodDealer, LimitaKM, Dotari, CodRadio, Transmisie, Tractiune, GPS, CodPartGPS, Frigo, GPL,
                          Extern, Partener, codgest,nrcontr, PartLeas,moneda,rataleas,ratarca,ratacasco,dataachiz,dataendleas,
                          partutiliz,persutiliz,obs, Inactiv, CodExtern, CodArtComb, ConsStatH )
                          =
                 ( SELECT Nvl(CodArt,0), NrInv, NrInreg, Sofer, KmPornire, Tip, DataInreg, Marca, Model, AnF,
                          SerieC, Culoare, Lung, Lat, Inalt, TipMotor, SerieM, Motor, Cilindree, Putere, CmM,
                          CmU, CmE, TipIncarc, Greutate, MasaM, MasaU, MasaURDF, MasaURFDF, LocT, LocF, LocS,
                          LocP, AnvRecomF, AnvRecomS, AnvOpt1F, AnvOpt1S, AnvOpt2F, AnvOpt2S, Kg, Kgr, Sarcina,
                          CodPutere, GrupAuto, TipRem, InstSp, Aer, Rezervor, VolumU, CuloareC, SursaE, TipUlei,
                          TipVehicul, CodDealer, LimitaKM, Dotari, CodRadio, Transmisie, Tractiune, GPS, CodPartGPS, Frigo, GPL,
                          Extern, Partener, codgest,nrcontr, PartLeas,moneda,rataleas,ratarca,ratacasco,dataachiz,dataendleas,
                          partutiliz,persutiliz,obs, Inactiv, CodExtern, CodArtComb, ConsStatH
                   FROM TMP_NPARCAUT )
                   WHERE CodNParcAut = RecId ;
  -- Detail NPARC0

    DELETE FROM NPARC0 WHERE CodNPARCAUT = RecId and CodNParc0 not in (Select CodNParc0 from TMP_NPARC0); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NPARC0 ( CODNPARC0, CODNPARCAUT, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd ) -- inseram inreg. noi din TMP
               (SELECT  seq_NPARC0_CodNParc0.Nextval, RecId, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd
               FROM TMP_NPARC0 WHERE CodNParc0 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPARC0 WHERE NVL(CodNParc0,-1) &gt; 0 ORDER BY CodNParc0 ) LOOP -- update pentru cele ramase
      UPDATE NPARC0
      SET
        DATABord  = v_rec.DATABord,
        KMBord    = v_rec.KMBord,
        AN        = v_rec.AN,
        LUNA      = v_rec.LUNA,
        OBS       = v_rec.OBS,
        CODPERS   = V_REC.CODPERS,
        Comb      = V_REC.Comb, 
        CodFAZ    = V_REC.CodFAZ, 
        CodCmd    = V_REC.CodCmd
      WHERE CodNParc0 = v_rec.CodNParc0;
    END LOOP;

    -- Detail NPARC1
    DELETE FROM NPARC1 WHERE Cod = RecId and CodNParc1 not in (Select CodNParc1 from TMP_NPARC1); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NPARC1 ( CodNParc1,   Cod, IndexLocal, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, ADANCIME, LATIME, INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, MS, OBS, Seria, DOT,
                         BordDem, CodNirStoc, CodNirSer ) -- inseram inreg. noi din TMP
                (SELECT seq_NPARC1_CodNParc1.Nextval, RecId, IndexLocal, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, ADANCIME, LATIME, INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, MS, OBS, Seria, DOT,
                        BordDem, CodNirStoc, CodNirSer
                FROM TMP_NPARC1 WHERE CodNParc1 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPARC1 WHERE NVL(CodNParc1,-1) &gt; 0 ORDER BY CodNParc1 ) LOOP -- update pentru cele ramase
      UPDATE NPARC1
      SET
        IndexLocal = v_rec.IndexLocal,
        Art        = v_rec.Art,
        Cant       = v_rec.Cant,
        Pozitie    = v_rec.Pozitie,
        BordInstal = v_rec.BordInstal,
        atentie    = v_rec.atentie,
        codpart    = v_rec.codpart,
        Montat     = v_rec.Montat, 
        Anotimp    = v_rec.Anotimp,
        ADANCIME   = v_rec.ADANCIME,
        LATIME     = v_rec.LATIME  ,
        INALTIME   = v_rec.INALTIME,
        DIAMETRU   = v_rec.DIAMETRU,
        GAMA       = v_rec.GAMA,    
        RUNFLAT    = v_rec.RUNFLAT, 
        SUV        = v_rec.SUV,     
        OFFROAD    = v_rec.OFFROAD, 
        XL         = v_rec.XL,      
        MS         = v_rec.MS,   
        OBS        = v_rec.OBS,   
        Seria      = v_rec.Seria,
        DOT        = v_rec.DOT,
        BordDem    = v_rec.BordDem,
        CodNirStoc = v_rec.Codnirstoc,
        CodNirSer = v_rec.Codnirser
      WHERE CodNParc1 = v_rec.CodNPArc1;
    END LOOP;
    --refacem index local
    IndexCount := 1;
    FOR v_rec IN (SELECT * FROM NPARC1 WHERE Cod = RecId) LOOP
      UPDATE NPARC1
      SET
        IndexLocal = IndexCount
      WHERE CodNParc1 = v_rec.CodNParc1;
      IndexCount := IndexCount + 1;
    END LOOP;

    -- Detail NPARC2
    DELETE FROM NPARC2 WHERE Cod = RecId and CodNParc2 not in (Select CodNParc2 from TMP_NPARC2); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NPARC2 (                   CodNParc2,   Cod, IndexLocal, Doc, SN, Eliberat, Expira, atentie,Obs, Valoare,CodIntr1,Denumire ) -- inseram inreg. noi din TMP
               (SELECT  seq_NPARC2_CodNParc2.Nextval, RecId, IndexLocal, Doc, SN, Eliberat, Expira, atentie,Obs, Valoare,CodIntr1,Denumire
               FROM TMP_NPARC2 WHERE CodNParc2 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPARC2 WHERE NVL(CodNParc2,-1) &gt; 0 ORDER BY CodNParc2 ) LOOP -- update pentru cele ramase
      UPDATE NPARC2
      SET
        IndexLocal = v_rec.IndexLocal,
        Doc        = v_rec.Doc,
        SN         = v_rec.SN,
        Eliberat   = v_rec.Eliberat,
        Expira     = v_rec.Expira,
        atentie    = v_rec.atentie,
        Obs        = v_rec.Obs,
        Valoare    = v_rec.Valoare,
        CodIntr1   = v_rec.CodIntr1,
        Denumire   = v_rec.Denumire
      WHERE CodNParc2 = v_rec.CodNPArc2;
    END LOOP;
    --refacem index local
    IndexCount := 1;
    FOR v_rec IN (SELECT * FROM NPARC2 WHERE Cod = RecId) LOOP
      UPDATE NPARC2
      SET
        IndexLocal = IndexCount
      WHERE CodNParc2 = v_rec.CodNParc2;
      IndexCount := IndexCount + 1;
    END LOOP;

    -- Detail NPARC3
    DELETE FROM NPARC3 WHERE Cod = RecId and CodNParc3 not in (Select CodNParc3 from TMP_NPARC3); -- stergem cele care nu se mai regasesc in TMP
    INSERT INTO NPARC3 (                   CodNParc3,   Cod, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare ) -- inseram inreg. noi din TMP
               (SELECT  seq_NPARC3_CodNParc3.Nextval, RecId, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare
               FROM TMP_NPARC3 WHERE CodNParc3 &lt; 0);
    FOR v_rec IN ( SELECT * FROM TMP_NPARC3 WHERE NVL(CodNParc3,-1) &gt; 0 ORDER BY CodNParc3 ) LOOP -- update pentru cele ramase
      UPDATE NPARC3
      SET
        Interventie = v_rec.Interventie,
        DataU       = v_rec.DataU,
        KmU         = v_rec.KmU,
        DataV       = v_rec.DataV,
        KmV         = v_rec.KmV,
        DataA       = v_rec.DataA,
        KMA         = v_rec.KMA,
        CodCMD      = v_rec.CodCMD, 
        Valoare     = v_rec.Valoare
      WHERE CodNParc3 = v_rec.CodNPArc3;
    END LOOP;

    select count(*) into acount from comanda3;

		for v_rec in (
      select c3.codcomanda3
      from comanda2 c2
           inner join comanda3 c3 on c3.codcomanda2 = c2.codcomanda2
           left join TMP_NPARCCOM1 TMP on tmp.codcomanda3 = c3.codcomanda3
      where c2.codnparcaut = RecID and tmp.codcomanda3 is null     
    ) loop
      delete comanda3 where codcomanda3 = v_rec.codcomanda3;
    end loop;
    
    --DELETE FROM COMANDA3 WHERE 
		--CODCOMANDA3 IN (
		--SELECT CODCOMANDA3	FROM COMANDA2 c2 inner join COMANDA3 C3 on C2.CodComanda2 = C3.CodComanda2
		--where  c2.codNParcAut = RecID AND CODCOMANDA3 NOT IN (SELECT CODCOMANDA3 FROM TMP_NPARCCOM1) 
		--);

    select count(*) into acount1 from comanda3;

    if aCount - aCount1 &gt; 20 then
      pkg_trigar.BAGA_IN_TRIGAR_MODIF(pkg_globals.GETUSERID, RecID, aCount, &apos;COMANDA3&apos;, &apos;CODCOMANDA3&apos;, &apos;stergere mare(nom.auto)&apos;, to_char(aCount));
      raise_application_error(-20001,&apos;Stergere de inregistrari in COMANDA3 nejustificat de mare ! :&apos;||acount||&apos;-CodNParcAut: &apos;||RecId);
    end if;

		for vx in (Select CodComanda2, CodLucrare, Garantie,CODREZERVARE from TMP_NPARCCOM1 where Nvl(CodComanda2,0) &gt; 0) loop
			update COMANDA2 
			Set 
				CODLUCRARE	= vx.CODLUCRARE,	
				GARANTIE    = vx.GARANTIE,   
				CODREZERVARE= vx.CODREZERVARE
			where CODCOMANDA2 = vx.CODCOMANDA2;
		end loop;
		
		for vx in (Select distinct CodLucrare, Nvl(Garantie,0) Garantie, CODREZERVARE from TMP_NPARCCOM1 where Nvl(CodComanda2,0) = 0) loop
				SELECT SEQ_COMANDA1_CODCOMANDA2.Nextval INTO VCOD from Dual;
				update TMP_NPARCCOM1 set CODCOMANDA2 = vCod 
				where Nvl(CodComanda2,0) = 0 and CodLucrare = vx.codlucrare and Nvl(Garantie,0) = vx.garantie;
				INSERT INTO  COMANDA2 ( CODCOMANDA2,CODCOMANDA,CODLUCRARE,GARANTIE,CODNPARCAUT,CODREZERVARE)
				VALUES (vCod,0,vx.CODLUCRARE,Nvl(vx.GARANTIE,0),RecID,vx.CODREZERVARE);
		end loop;

--    Delete from NPARCCOM1; insert into NPARCCOM1 (Select * from TMP_NPARCCOM1);

  	for vx in (Select * from TMP_NPARCCOM1) loop
			if vx.codcomanda3 &lt; 0 then 
				INSERT INTO  COMANDA3 
				( CODCOMANDA3,CODCOMANDA2,CODOPERATIE,TIP,EXECUTAT,DataStart, DATA, CODCOMANDA,CODREZERVARE,CodIntr1_1, CodIntr1_2, CodIntr1_3)
				VALUES 
				(SEQ_COMANDA2_CODCOMANDA3.Nextval ,vx.CODCOMANDA2,vx.CODOPERATIE,vx.TIP,vx.EXECUTAT, vx.DataStart, vx.DATA, 0,vx.CODREZERVARE,vx.CodIntr1_1, vx.CodIntr1_2, vx.CodIntr1_3);
			else
				update COMANDA3 
				Set 
					CODOPERATIE= vx.CODOPERATIE,
					TIP     = vx.TIP,
					DATA    = vx.Data, 
					DATAStart= vx.DataStart, 
					CODREZERVARE = vx.CODREZERVARE,
					EXECUTAT= vx.EXECUTAT,
          CodIntr1_1 = vx.CodIntr1_1,
          CodIntr1_2 = vx.CodIntr1_2,
          CodIntr1_3 = vx.CodIntr1_3
				where CODCOMANDA3 = vx.CODCOMANDA3;
			end if;
		end loop;
  ELSE  -- INSERT
  -- Master NPARCAUT
    SELECT seq_NPARCAUT_CodNPARCAUT.NextVal INTO RecId FROM DUAL;

		IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
		 SELECT &apos;Nr.auto: &apos;||NrInreg INTO aDoc FROM TMP_NParcAut;
		 WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPARCAUT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
		END IF;

    INSERT INTO  NPARCAUT (
      CodNParcAut, CodArt, NrInv, NrInreg, Sofer, KmPornire, Tip, DataInreg, Marca, Model, AnF,
      SerieC, Culoare, Lung, Lat, Inalt, TipMotor, SerieM, Motor, Cilindree, Putere, CmM,
      CmU, CmE, TipIncarc, Greutate, MasaM, MasaU, MasaURDF, MasaURFDF, LocT, LocF, LocS,
      LocP, AnvRecomF, AnvRecomS, AnvOpt1F, AnvOpt1S, AnvOpt2F, AnvOpt2S, Kg, Kgr, Sarcina,
      CodPutere, GrupAuto, TipRem, InstSp, Aer, Rezervor, VolumU, CuloareC, SursaE, TipUlei,
      TipVehicul, CodDealer, LimitaKM, Dotari, CodRadio, Transmisie, Tractiune, GPS, CodPartGPS, Frigo, GPL,
      Extern, Partener, codgest,nrcontr, PartLeas,moneda,rataleas,ratarca,ratacasco,dataachiz,dataendleas,
      partutiliz,persutiliz,obs, Inactiv, CodExtern, CodArtComb, ConsStatH )
    SELECT
      RecId, Nvl(CodArt,0), NrInv, NrInreg, Sofer, KmPornire, Tip, DataInreg, Marca, Model, AnF,
      SerieC, Culoare, Lung, Lat, Inalt, TipMotor, SerieM, Motor, Cilindree, Putere, CmM,
      CmU, CmE, TipIncarc, Greutate, MasaM, MasaU, MasaURDF, MasaURFDF, LocT, LocF, LocS,
      LocP, AnvRecomF, AnvRecomS, AnvOpt1F, AnvOpt1S, AnvOpt2F, AnvOpt2S, Kg, Kgr, Sarcina,
      CodPutere, GrupAuto, TipRem, InstSp, Aer, Rezervor, VolumU, CuloareC, SursaE, TipUlei,
      TipVehicul, CodDealer, LimitaKM, Dotari, CodRadio, Transmisie, Tractiune, GPS, CodPartGPS, Frigo, GPL,
      Extern, Partener, codgest,nrcontr, PartLeas,moneda,rataleas,ratarca,ratacasco,dataachiz,dataendleas,
      partutiliz,persutiliz,obs, Inactiv, CodExtern, CodArtComb, ConsStatH
    FROM TMP_NPARCAUT;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NPARCAUT&apos;, RecId);
    -- Detail NPARC0
    INSERT INTO NPARC0 ( CODNPARC0, CODNPARCAUT, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd )
               (SELECT  seq_NPARC0_CodNParc0.Nextval, RecId, DATABord, KMBord, AN, LUNA, OBS, CODPERS, CodFAZ, Comb, CodCmd
                FROM TMP_NPARC0);

    -- Detail NPARC1
    INSERT INTO NPARC1 (       CodNParc1,   Cod, IndexLocal, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, ADANCIME, LATIME, INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, MS, OBS, Seria, DOT,
                        BordDem, Codnirstoc, Codnirser)
    (SELECT seq_NPARC1_CodNParc1.Nextval, RecId, IndexLocal, Art, Cant, Pozitie, BordInstal, atentie,codpart,Montat, Anotimp, ADANCIME, LATIME, INALTIME, DIAMETRU, GAMA, RUNFLAT, SUV, OFFROAD, XL, MS, OBS, Seria, DOT,
            BordDem, Codnirstoc, Codnirser
    FROM TMP_NPARC1);
    --refacem IndexLocal
    IndexCount := 1;
    FOR v_rec IN (SELECT * FROM NPARC1 WHERE Cod = RecId) LOOP
      UPDATE NPARC1
      SET
        IndexLocal = IndexCount
      WHERE CodNParc1 = v_rec.CodNParc1;
      IndexCount := IndexCount + 1;
    END LOOP;

    -- Detail NPARC2
    INSERT INTO NPARC2 (        CodNParc2,   Cod, IndexLocal, Doc, SN, Eliberat, Expira, atentie,Obs,Valoare,CodIntr1,Denumire ) -- inseram inreg. noi din TMP
    (SELECT  seq_NPARC2_CodNParc2.Nextval, RecId, IndexLocal, Doc, SN, Eliberat, Expira, atentie,Obs,Valoare,CodIntr1,Denumire
    FROM TMP_NPARC2 );
    --refacem index local
    IndexCount := 1;
    FOR v_rec IN (SELECT * FROM NPARC2 WHERE Cod = RecId) LOOP
      UPDATE NPARC2
      SET
        IndexLocal = IndexCount
      WHERE CodNParc2 = v_rec.CodNParc2;
      IndexCount := IndexCount + 1;
    END LOOP;

    -- Detail NPARC3
    INSERT INTO NPARC3 (        CodNParc3,   Cod, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare ) -- inseram inreg. noi din TMP
    (SELECT  seq_NPARC3_CodNParc3.Nextval, RecId, Interventie, DataU, KmU, DataV, KmV, DataA, KMA, CodCMD, Valoare
    FROM TMP_NPARC3 );

		for vx in (Select distinct CodLucrare, Garantie from TMP_NPARCCOM1) loop
				SELECT SEQ_COMANDA1_CODCOMANDA2.Nextval INTO VCOD from Dual;
				update TMP_NPARCCOM1 set CODCOMANDA2 = vCod 
				where Nvl(CodComanda2,0) = 0 and CodLucrare = vx.codlucrare and Garantie = vx.garantie;
				INSERT INTO  COMANDA2 ( CODCOMANDA2,CODCOMANDA,CODLUCRARE,GARANTIE,CODNPARCAUT)
				VALUES (vCod,0,vx.CODLUCRARE,vx.GARANTIE,RecID);
		end loop;

  	for vx in (Select * from TMP_NPARCCOM1) loop
			INSERT INTO  COMANDA3 
			( CODCOMANDA3,CODCOMANDA2,CODOPERATIE,TIP,EXECUTAT,DataStart, DATA,CODCOMANDA,CODREZERVARE, CodIntr1_1, CodIntr1_2, CodIntr1_3)
			VALUES 
			(SEQ_COMANDA2_CODCOMANDA3.Nextval ,vx.CODCOMANDA2,vx.CODOPERATIE,vx.TIP,vx.EXECUTAT,vx.DataStart, vx.DATA,0,vx.CODREZERVARE, vx.CodIntr1_1, vx.CodIntr1_2, vx.CodIntr1_3);
		end loop;
  	aInactivOld := -1; aCodGestOld := -1;
    aStatus := 6;
    Select Nvl(inactiv,0), CodGest into aInactivNew, aCodGestNew FROM TMP_NParcAut;
    
    begin
      select mf.codmifix into aNewCodMifix 
      from tmp_nparcaut a
           inner join mifix mf on mf.nrinventar = a.nrinv and mf.tip = &apos;MF&apos;;
    exception when others then aNewCodMifix := 0;
    end;
    if aNewCodMifix &gt; 0 then
      update mifix1 set codauto = recid where anstart = pkg_globals.GetANLUCRU and lunastart = pkg_globals.GetLUNALUCRU and codmifix = aNewCodMifix;
    end if;
    
  END IF;

	if aCodGestOld &lt;&gt; aCodGestNew or aInactivOld &lt;&gt; aInactivNew then 
		select Count(*) into IndexCount from nparcg where codnparcaut = recid;
		if IndexCount = 1 and aCodGestOld = 0 and aInactivOld = aInactivNew
		then 
			update NParcG set CodGest = aCodGestNew where codnparcaut = recid;
		else 
			if (IndexCount = 0)and(OPERATION = 0) -- UPDATE
			THEN aData := TO_DATE(&apos;01.&apos;||to_char(PKG_GLOBALS.LUNAINITIALA,&apos;00&apos;)||&apos;.&apos;||To_Char(PKG_GLOBALS.ANINITIAL)||&apos; 00:01&apos;, &apos;DD.MM.YYYY hh24:mi&apos;);
 	  	else aData := SysDate;
		  end if;
			INSERT INTO  NParcG 
							 ( CODNParcG, CODNPARCAUT, CodGestIni, CodGest, Status, Data)
					values(SEQ_NPARCG_CODNPARCG.NextVal, RecID, aCodGestOld, aCodGestNew, aInactivNew, aData);
		end if;
	end if;
  --nomAuto = 505;
 PKG_CFGTABLES.EXT_POSTRECORDS(505); 
 NotifyModif(OPERATION, RECID, &apos;NPARCAUT&apos;);

 COMMIT;
END;

FUNCTION CHECK_TABLE_FOR_AUTO(aTABLENAME IN VARCHAR2, aCODAUTO IN NUMBER, aFLDNAME IN VARCHAR2 DEFAULT &apos;CODAUTO&apos;) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM &apos; || aTABLENAME || &apos; WHERE &apos; || aFLDNAME || &apos; = &apos; || TO_CHAR(aCODAUTO) INTO NR;
  RETURN NR;
END;

FUNCTION AUTO_IMPLICAT_IN_TRANZACTII(aCODAUTO IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
BEGIN
  NR := CHECK_TABLE_FOR_AUTO(&apos;INTRARI&apos;, aCODAUTO);  
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;IESIRI&apos;, aCODAUTO);  
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;INTRARI1&apos;, aCODAUTO);  
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;IESIRI1&apos;, aCODAUTO);  
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;COMANDA&apos;, aCODAUTO, &apos;MIJLTRANSP&apos;);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;CONTRACT1&apos;, aCODAUTO);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_AUTO(&apos;COMANDA2&apos;, aCODAUTO, &apos;CODNPARCAUT&apos;);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  RETURN 0;
END;

function getultimacitire(aCodNParcAut in number) return number is
aRez number(20);  
begin
  aRez := 0;
  for v_rec in (select databord from nparc0 where codnparcaut = acodnparcaut order by databord desc) loop
    for v_rec0 in (select codnparc0 from nparc0 where databord = v_rec.databord and codnparcaut = acodnparcaut order by codnparc0 desc) loop
      aRez := v_rec0.codnparc0;
			return aRez;
    end loop; 
  end loop;
  return aRez;
end;  

procedure UPDATE_AUT is
begin
  insert into nparc2(codnparc2,doc,sn,eliberat,expira,atentie,cod,obs,valoare)
  select seq_nparc2_codnparc2.nextval,doc,sn,eliberat,expira,atentie,cod,obs,valoare
  from tmp_nparc2;
  commit; 
end;  

procedure UPDATE_AUTO is
aCod number(20);
vcodmodel number(20);
vcodmarca number(20);
begin
  for v_rec in (select * from tmp_nparcaut_man) loop
    vCodmodel := 0;
    if Length(v_rec.den_model) &gt; 0 then
      begin
        select CODMODELEAUTO into vcodmodel from nmodeleauto where model = v_rec.den_model;
      exception when others then 
        select seq_nmodeleauto_codmodeleauto.Nextval into vcodmodel from dual;
        insert into nmodeleauto(codmodeleauto,model)
        values(vcodmodel, v_rec.den_model);
      end;
    end if;
    vcodmarca := 0;
    if Length(v_rec.den_model) &gt; 0 then
      begin
        select CODMARCIAUTO into vcodmarca from nmarciauto where marca = v_rec.den_marca;
      exception when others then 
        select seq_nmarciauto_CODMARCIAUTO.Nextval into vcodmarca from dual;
        insert into nmarciauto(CODMARCIAUTO,marca)
        values(vcodmarca, v_rec.den_marca);
      end;
    end if;  
    delete tmp_nparcaut;
    Delete TMP_NPARcG;
  	Delete TMP_NPARc0;
  	Delete TMP_NPARc1;
  	Delete TMP_NPARc2;
  	Delete TMP_NPARc3;
  	Delete TMP_NPARCCOM;
  	Delete TMP_NPARCCOM1;
    insert into tmp_nparcaut(
    NrInreg,Marca,Model,CodArt,SerieC,SerieM,Cilindree,MasaM,
    LocT,PartLeas,AnF,RataRCA,RataCASCO,RataLEAS,
    NrContr,Transmisie,Tractiune,LimitaKm,CodDealer,CuloareC,CodGest)
    values (v_rec.NrInreg,vCodMarca,vCodModel,v_rec.CodArt,v_rec.SerieC,v_rec.SerieM,v_rec.Cilindree,v_rec.MasaM,
    v_rec.LocT,v_rec.PartLeas,v_rec.AnF,v_rec.RataRCA,v_rec.RataCASCO,v_rec.RataLEAS,
    v_rec.NrContr,v_rec.Transmisie,v_rec.Tractiune,v_rec.LimitaKm,v_rec.CodDealer,v_rec.CuloareC,v_rec.CodGest);
    pkg_nom_parcaut.SP_POSTRECORDS(1,aCod);
  end loop;
end;  

procedure EMPTY_NPARCAUT_TEMPTABLES IS
BEGIN
  Delete TMP_NPARCAUT;
	Delete TMP_NPARcG;
	Delete TMP_NPARc0;
	Delete TMP_NPARc1;
	Delete TMP_NPARc2;
	Delete TMP_NPARc3;
	Delete TMP_NPARCCOM;
	Delete TMP_NPARCCOM1;
  COMMIT;
END;  

procedure UPDATE_BORDAUTO is
begin
  insert into nparc0(codnparc0,codnparcaut,databord,kmbord,an,luna,obs,codpers)
  select seq_nparc0_codnparc0.nextval, codnparcaut,databord,kmbord,extract(year from databord),extract(month from databord),obs,codpers
  from tmp_nparc0_man;
  delete tmp_nparc0_man;
  commit;
end;

procedure Test is
cod number;
begin
	Delete TMP_NPARCAUT;
	Delete TMP_NPARcG;
	Delete TMP_NPARc0;
	Delete TMP_NPARc1;
	Delete TMP_NPARc2;
	Delete TMP_NPARc3;
	Delete TMP_NPARCCOM;
	Delete TMP_NPARCCOM1;
	Select count(*) into cod from nparcaut where codnparcaut = 149;
	if Cod = 1 then 
  	SP_GOTORECORD(149);
	  SP_POSTRECORDS(0, cod);
	end if;
end;

end PKG_NOM_PARCAUT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD73F2FA6FC7641894BB099848C43FEB17BE6088</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NOTECREDIT IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_47&apos;;
KArtDiscAcTer    varchar2(1000) := &apos;&apos;;
KArtDiscAcVol    number(20) := 0;
KArtDiscAcCant   number(20) := 0;
KArtPenAcTer     number(20) := 0;
KArtDiscPrimTer  varchar2(1000) := &apos;&apos;;
KArtDiscPrimVol  number(20) := 0;
KArtDiscPrimCant number(20) := 0;
KArtPenPrimTer   number(20) := 0;
KArtDiscOffInvoiceF  number(20) := 0;
KArtDiscOffInvoiceC  number(20) := 0;
--DECODIFICARILE LA TIPURI
tncTermen number(1) := 1;
tncVolum number(1) := 2;
tncCantitate number(1) := 3;
tncCadouri number(1) := 4;
tncProvizioane number(1) := 5;
tncPenalizari number(1) := 6;

PROCEDURE RUPE(aCodNCFact in number) is
begin
  for v_rec in (select f.codncredit, coalesce(f.coddoc, i1.codies) coddoc, f.coddoc1
                from notecreditfact f
                     inner join notecredit nc on nc.codncredit = f.codncredit
                     left join iesiri1 i1 on f.coddoc1 = i1.codies1
                where codncfact = aCodNCFact and nc.tipdoc = 58) loop
    
    if v_rec.coddoc1 &gt; 0 then
      UpdateCentralizare(-v_rec.coddoc, v_rec.codncredit, v_rec.coddoc1);
      delete notecreditfact where coddoc1  = v_rec.coddoc1;
    else
      UpdateCentralizare(-v_rec.coddoc, v_rec.codncredit);
      delete notecreditfact where coddoc = v_rec.coddoc;
    end if;
  end loop;
  for v_rec in (select f.codncredit, coalesce(f.coddoc, i1.codintr) coddoc, f.coddoc1
                from notecreditfact f
                     inner join notecredit nc on nc.codncredit = f.codncredit
                     left join intrari1 i1 on f.coddoc1 = i1.codintr1
                where codncfact = aCodNCFact and nc.tipdoc = 59) loop
    if v_rec.coddoc1 &gt; 0 then
      UpdateCentralizare(-v_rec.coddoc, v_rec.codncredit, v_rec.coddoc1);
      delete notecreditfact where coddoc1  = v_rec.coddoc1;
    else
      UpdateCentralizare(-v_rec.coddoc, v_rec.codncredit);
      delete notecreditfact where coddoc = v_rec.coddoc;
    end if;
  end loop;
  commit;
end;

procedure UPDATE_RECORDS(aTipDoc in number, aCodDoc1 in number, aCodCentralizare in number, aNrDoc in number, aDataDoc in date, aValT in number, aOldPU in number) is
aPu number(20,7);
aValDoc number(20,7);
aVT number(20,7);
aCodNCredit number(20);
begin
  if aTipDoc = 19 then
    select pu, pu*cant, pu*cant +tva into aPu, aValDoc, aVT from iesiri1 where codies1 = aCodDoc1;
    update centralizarenc set facturat = facturat - aOldPU + aPu, diferente = diferente + aOldPU - aPu where codcentralizare = aCodCentralizare;
  end if;
  if aTipDoc = 1 then
    select pu, pu*cant, pu*cant +tva into aPu, aValDoc, aVT from intrari1 where codintr1 = aCodDoc1;
    update centralizarenc set facturat = facturat - aOldPU + aPu, diferente = diferente + aOldPU - aPu where codcentralizare = aCodCentralizare;
  end if;
  select CodNCredit into aCodNCredit from CENTRALIZARENC where CODCENTRALIZARE = aCodCentralizare;
  MERGE INTO NOTECREDITFACT F
  USING (
         SELECT aTIPDOC as TipDoc, aCodDoc1 as CodDoc1, aCodNCredit as CodNCredit
         from dual
        ) N
  ON (F.CODDOC1 = N.CODDOC1 and F.TIPDOC = N.TIPDOC AND F.CODNCREDIT = N.CODNCREDIT)
  WHEN MATCHED THEN UPDATE SET VALDOC = aValDoc, VALT = aVT
  WHEN NOT MATCHED THEN INSERT (CODNCFACT,
                                CODNCREDIT,
                                TIPDOC,
                                PREFIXDOC,
                                NRDOC,
                                DATADOC,
                                VALDOC,
                                VALT,
                                CODDOC1
                                )
                                VALUES
                               (SEQ_NOTECREDITFACT_CODNCFACT.NEXTVAL,
                                aCODNCREDIT,
                                aTIPDOC,
                                &apos;F&apos;,
                                aNRDOC,
                                aDATADOC,
                                aPu,
                                aVALT,
                                aCODDOC1
                               );
end;

procedure ADAUGASTRUCT(aCodNCredit1 in number, aCodIes1 in number, aVal in number) is
aCodPart number(20);
aCodLocatie number(20);
aDataDoc date;
aSubunitate number(20);
aCodObiect number(20);
aCant number(20,7);
aCodDiscount number(20);
aCodClasa number(20);
aCount number(10);
aProc number(20,7);
begin
  select i.partener, i.codlocatie, i.datadoc, i.subunitatea, i1.codobiect, i1.cant, nvl(a.clasa,0)
  into aCodPart, aCodLocatie, aDataDoc, aSubunitate, aCodObiect, aCant, aCodClasa
  from iesiri1 i1
       inner join iesiri i on i1.codies = i.codies
       inner join nartobj o on o.codobiect = i1.codobiect
       inner join nart a on a.codarticol = o.codarticol
  where i1.codies1 = aCodIes1;

  select count(*) into aCount from TMP_NCVDISC_VOL where codobiect = aCodObiect;
  if aCount = 0 then
    insert into tmp_ncvdisc_vol(codobiect, valoare)
    values (aCodObiect, aVal);
  else
    update tmp_ncvdisc_vol set Valoare = nvl(Valoare,0) + aVal;
  end if;

  for v_rec in (
                select distinct d.coddiscount, di.procent
                from NPARTDISC PD
                  INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
                  INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
                  INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
                  INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = D.CODDISCOUNT
                  INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODOBIECT = aCODOBIECT
                  LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
                where CD.peclase = 0 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
                  and CD1.Subunitatea = aSubunitate
                  and PD.CodPart = aCodPart and cd.tipinterval = 0
               ) loop
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = v_rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,v_rec.coddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = v_rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,proc)
      values (v_rec.CodDiscount,v_rec.procent);
    end if;
  end loop;

  begin
    select distinct d.coddiscount into aCodDiscount
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODOBIECT = aCODOBIECT
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 0 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 2;
  exception when others then aCodDiscount := 0;
  end;

  if aCodDiscount &gt; 0 then
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,acoddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,cant)
      values (aCodDiscount,aCant);
    else
      update tmp_ncvdisc_man
      set
        cant = nvl(cant,0) + acant
      where coddiscount = acoddiscount;
    end if;
  end if;

  /*begin
    select distinct d.coddiscount into aCodDiscount
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODOBIECT = aCODOBIECT
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 0 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 6;
  exception when others then aCodDiscount := 0;
  end;*/

  for v_rec in  (select distinct d.coddiscount
                 from NPARTDISC PD
                   INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
                   INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
                   INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
                   INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODOBIECT = aCODOBIECT
                   LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
                 where CD.peclase = 0 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
                   and CD1.Subunitatea = aSubunitate
                   and PD.CodPart = aCodPart and cd.tipinterval = 6
                 ) loop
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = v_Rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,v_Rec.coddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = v_rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,valoare)
      values (v_rec.CodDiscount,aVal);
    else
      update tmp_ncvdisc_man
      set
        valoare = nvl(valoare,0) + aVal
      where coddiscount = v_rec.coddiscount;
    end if;
  end loop;
  -- toate articolele
  begin
    select distinct d.coddiscount, di.procent into aCodDiscount, aProc
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = D.CODDISCOUNT
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 3 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 0;
  exception when others then aCodDiscount := 0;
  end;

  if aCodDiscount &gt; 0 then
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,acoddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,proc)
      values (aCodDiscount,aproc);
    end if;
  end if;

  --pe clase
  begin
    select distinct d.coddiscount, di.procent into aCodDiscount, aProc
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = D.CODDISCOUNT
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODCLASA = aCODCLASA
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 1 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 0;
  exception when others then aCodDiscount := 0;
  end;

  if aCodDiscount &gt; 0 then
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,acoddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,proc)
      values (aCodDiscount,aproc);
    end if;
  end if;

  begin
    select distinct d.coddiscount into aCodDiscount
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODCLASA = aCODCLASA
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 1 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 2;
  exception when others then aCodDiscount := 0;
  end;

  if aCodDiscount &gt; 0 then
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,acoddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = aCodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,cant)
      values (aCodDiscount,aCant);
    else
      update tmp_ncvdisc_man
      set
        cant = nvl(cant,0) + acant
      where coddiscount = acoddiscount;
    end if;
  end if;

  /*begin
    select distinct d.coddiscount into aCodDiscount
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODCLASA = aCODCLASA
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 1 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 6;
  exception when others then aCodDiscount := 0;
  end;*/

  for v_rec in (
    select distinct d.coddiscount
    from NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCART DA ON DA.CODDISCOUNT = D.CODDISCOUNT AND DA.CODCLASA = aCODCLASA
      LEFT JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 1 and CD.offinvoice = 1 and (AG.CODAGENDA = aCodLocatie or NVL(D.Codtipsediu, 0) = 0)
      and CD1.Subunitatea = aSubunitate
      and PD.CodPart = aCodPart and cd.tipinterval = 6
      ) loop
    select count(*) into aCount from TMP_NCVDISC where codncredit1 = aCodNCredit1 and coddiscount = v_rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc(codncredit1, coddiscount)
      values (acodncredit1,v_rec.coddiscount);
    end if;
    select count(*) into aCount from TMP_NCVDISC_MAN where coddiscount = v_rec.CodDiscount;
    if aCount = 0 then
      insert into tmp_ncvdisc_man(coddiscount,valoare)
      values (v_rec.CodDiscount,aVal);
    else
      update tmp_ncvdisc_man
      set
        valoare = nvl(valoare,0) + aVal
      where coddiscount = v_rec.coddiscount;
    end if;
  end loop;
  commit;
end;

procedure PreiaProcente is
begin
  for v_rec in (select TMP.coddiscount, DI.PROCENT
                from TMP_NCVDISC_MAN tmp
                     INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = tmp.CODDISCOUNT
                WHERE NVL(TMP.CANT,0) &lt;&gt; 0 AND TMP.CANT BETWEEN DI.LIMINF AND DI.LIMSUP
                ) LOOP
    UPDATE TMP_NCVDISC_MAN SET PROC = V_REC.PROCENT WHERE CODDISCOUNT = V_REC.CODDISCOUNT;
  END LOOP;
  for v_rec in (select TMP.coddiscount, DI.PROCENT
                from TMP_NCVDISC_MAN tmp
                     INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = tmp.CODDISCOUNT
                WHERE NVL(TMP.VALOARE,0) &lt;&gt; 0 AND TMP.VALOARE BETWEEN DI.LIMINF AND DI.LIMSUP
                ) LOOP
    UPDATE TMP_NCVDISC_MAN SET PROC = V_REC.PROCENT WHERE CODDISCOUNT = V_REC.CODDISCOUNT;
  END LOOP;
  commit;
end;

procedure bagainx(text in varchar2) is
pragma autonomous_transaction;
begin
  insert into x(test) values(text);
  commit;
end;

procedure GenereazaVolum(aCodNCredit in number,
                         aCodContract in number,
                         aTipArticol in number,
                         aDataStart in varchar2,
                         aDataStop in varchar2,
                         aCodMoneda in number,
                         aCodPart in number,
                         aSubunitatea in number,
                         aTrimestru in number,
                         aPretBrutV in number,
                         aTipDoc in number,
                         aTipDiscV in number,
                         aTotal out number,
                         aTotalLei out number
                        ) is
begin
  null;
end;

function GetDiscVolLinie(aCodDoc1 in number, aTipNC in number) return number is
aValDisc number(20,7);
aValDisc1 number(20,7);
aCodDoc number(20);
begin
  if aTipNC = 59 then
    begin
      select codintr into aCodDoc
      from intrari1
      where codintr1 = aCodDoc1;
    exception when others then
      aCodDoc := 0;
    end;
  else
    begin
      select codies into aCodDoc
      from iesiri1
      where codies1 = aCodDoc1;
    exception when others then
      aCodDoc := 0;
    end;
  end if;

  aValDisc := 0.0;
  if aTipNC = 59 then
    begin
      SELECT sum(NC1.valoare) into aValDisc
      FROM NOTECREDIT1 NC1
           INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
           INNER JOIN INTRARI1 I1 ON I1.CODINTR1 = NC1.CODDOC
           INNER JOIN INTRARI I ON I1.CODINTR = I.CODINTR AND NC1.TIPDOC = I.TIPDOC
           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
      WHERE (NC1.CODDOC = aCodDoc1 AND (NVL(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))
            AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIP = tncVolum;
    exception when others then
      aValDisc := 0.0;
    end;
    begin
      SELECT SUM(NC1.VALOARE * I1.CANT * I1.PRETORIG / CENTR.VAL) INTO aValDisc1
      FROM NOTECREDIT1 NC1
           INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
           INNER JOIN INTRARI I ON NC1.CODDOC = I.CODINTR AND I.TIPDOC = NC1.TIPDOC
           INNER JOIN (SELECT SUM(II1.CANT * II1.PRETORIG) VAL, II1.CODINTR
                       FROM INTRARI1 II1
                       WHERE II1.CODINTR = aCodDoc
                       GROUP BY II1.CODINTR) CENTR ON CENTR.CODINTR = I.CODINTR
           INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR AND I1.CODINTR1 = aCodDoc1
           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
      WHERE (NC1.CODDOC = aCodDoc AND NVL(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1)
            AND NC1.Valoare &lt;&gt; 0 AND NC1.TIP = tncVolum;
    exception when others then
      aValDisc1 := 0;
    end;
  else
    begin
      SELECT sum(NC1.valoare) into aValDisc
      FROM NOTECREDIT1 NC1
           INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
           INNER JOIN IESIRI1 I1 ON I1.CODIES1 = NC1.CODDOC
           INNER JOIN IESIRI I ON I1.CODIES = I.CODIES AND NC1.TIPDOC = I.TIPDOC
           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
      WHERE (NC1.CODDOC = aCodDoc1 AND (NVL(C.TipTargetV,-1) = 2 OR NC.VOLUMPEARTICOLE = 1))
            AND NC1.Valoare &lt;&gt; 0 AND I.TIPDOC = NC1.TIPDOC AND NC1.TIP = tncVolum;
    exception when others then
      aValDisc := 0.0;
    end;
    begin
      SELECT SUM(NC1.VALOARE * I1.CANT * I1.PRETORIG / CENTR.VAL) INTO aValDisc1
      FROM NOTECREDIT1 NC1
           INNER JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
           INNER JOIN IESIRI I ON NC1.CODDOC = I.CODIES AND I.TIPDOC = NC1.TIPDOC
           INNER JOIN (SELECT SUM(II1.CANT * II1.PRETORIG) VAL, II1.CODIES
                       FROM IESIRI1 II1
                       WHERE II1.CODIES = aCodDoc
                       GROUP BY II1.CODIES) CENTR ON CENTR.CODIES = I.CODIES
           INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES AND I1.CODIES1 = aCodDoc1
           LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
      WHERE (NC1.CODDOC = aCodDoc AND NVL(C.TipTargetV,-1) &lt;&gt; 2 AND NC.VOLUMPEARTICOLE &lt;&gt; 1)
            AND NC1.Valoare &lt;&gt; 0 AND NC1.TIP = tncVolum;
    exception when others then
      aValDisc1 := 0;
    end;
  end if;

  aValDisc := nvl(aValDisc,0) + nvl(aValDisc1,0);
  return aValDisc;
end;

function GetValDiscNCVol(aCodIes1 in number, aCantLivr in number, aCodIes in number, aTipDoc in number, aCant in number, aPU in number, aTVA in number, aAdDim in number, aCoefdiscmaj in number, aValdiscpret in number, aValdoc in number, aTvaDoc in number) return number is
aValPeArt number(20,7);
aValPeDoc number(20,7);
begin
  aValPeArt := 0;
  aValPeDoc := 0;

  for v_rec in (select nc1.valoare
                FROM NOTECREDIT NC
                     INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                     LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
                WHERE ((NC.CODCONTRACT &gt; 0 AND NVL(C.TIPTARGETV,0) = 2 AND NC.TIPDOC = 58 AND NC1.TIP = tncVolum AND NC1.CODDOC = aCodIes1 AND NC1.TIPDOC = aTipDoc)
                    OR (NVL(NC.CODCONTRACT,0) = 0 AND NC.VOLUMPEARTICOLE = 1 AND NC.TIPDOC = 58 AND NC1.TIP = tncVolum AND NC1.CODDOC = aCodIes1 AND NC1.TIPDOC = aTipDoc)
                      )
                ) loop
    aValPeArt := aValPeArt + v_rec.Valoare;
  end loop;

  for v_rec in (select nc1.valoare
                FROM NOTECREDIT NC
                     INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
                     LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
                WHERE ((NC.CODCONTRACT &gt; 0 AND NVL(C.TIPTARGETV,0) &lt; 2 AND NC.TIPDOC = 58 AND NC1.TIP = tncVolum AND NC1.CODDOC = aCodIes AND NC1.TIPDOC = aTipDoc)
                    OR (NVL(NC.CODCONTRACT,0) = 0 AND NVL(NC.VOLUMPEARTICOLE,0) = 0 AND NC.TIPDOC = 58 AND NC1.TIP = tncVolum AND NC1.CODDOC = aCodIes AND NC1.TIPDOC = aTipDoc)
                      )
                ) loop
    aValPeDoc := aValPeDoc + v_rec.Valoare;
  end loop;

  if aValPeDoc &lt;&gt; 0 then
    aValPeDoc := aCantLivr * PKG_LIST_BASE_IESIRI.CALCPIES(aCodIes, aTipDoc, aCant, aPU, aTVA, aAdDim, aCoefdiscmaj, aValdiscpret) / (aValdoc-aTvadoc) * aValPeDoc;
  end if;

  return aValPeArt + aValPeDoc;

end;

function GetCodContract1(aCodObiect in number, aDataDoc in date, aCodContract in number, aCodDoc1 in number default 0) return number is
vCodContract1 number(20);
vTipArticol number(20);
vConst number(1);
aTipDoc number(20);
begin
  vConst := coalesce(PKG_CATEGCONST.GetValConstanta(&apos;NCCContract&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU),2);
  if aCodDoc1 = 0 or vConst &lt;&gt; 1 then
    begin
      select nvl(TipArticol,0) into vTipArticol
      from contract
      where codcontract = aCodContract;
    exception when others then vTipArticol := 0;
    end;

    if vTipArticol = 0 then
      begin
        select nvl(c1.CodContract1,0) into vCodContract1
        from contract1 c1
             inner join contract c on c1.codcontract = c.codcontract
        where C1.codobiect = aCodObiect and C1.CodContract = aCodContract
              and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc;
      exception when others then
        vCodContract1 := 0;
      end;
    else
      begin
        select nvl(c1.CodContract1,0) into vCodContract1
        from contract1 c1
             inner join nart a on a.clasa = c1.codclasa
             inner join nartobj obj on obj.codarticol = a.codarticol
             inner join contract c on c1.codcontract = c.codcontract
        where obj.codobiect = aCodObiect and C1.CodContract = aCodContract
              and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc;
      exception when others then
        vCodContract1 := 0;
      end;
    end if;
  else
    begin
      select nvl(TipArticol,0), tipdoc into vTipArticol, aTipDoc
      from contract
      where codcontract = aCodContract;
    exception when others then vTipArticol := 0;
    end;

    if aTipDoc = 27 then
      if vTipArticol = 0 then
        begin
          select nvl(c1.CodContract1,0) into vCodContract1
          from contract1 c1
               inner join contract c on c1.codcontract = c.codcontract
               inner join iesiri1 i1 on c1.codcontract1 = i1.codcontract1
          where C1.codobiect = aCodObiect and C1.CodContract = aCodContract
                and i1.codies1 = aCodDoc1;
        exception when others then
          vCodContract1 := 0;
        end;
        if vCodContract1 = 0 then
          begin
            select nvl(c1.CodContract1,0) into vCodContract1
            from contract1 c1
                 inner join contract c on c1.codcontract = c.codcontract
                 inner join iesiri i on i.codcontract = c.codcontract
                 inner join iesiri1 i1 on i1.codies = i.codies and i1.codobiect = c1.codobiect
            where i1.codobiect = aCodObiect and C1.CodContract = aCodContract
                  and i1.codies1 = aCodDoc1;
          exception when others then
            vCodContract1 := 0;
          end;
        end if;
      else
        begin
          select nvl(c1.CodContract1,0) into vCodContract1
          from contract1 c1
               inner join nart a on a.clasa = c1.codclasa
               inner join nartobj obj on obj.codarticol = a.codarticol
               inner join contract c on c1.codcontract = c.codcontract
               inner join iesiri1 i1 on c1.codcontract1 = i1.codcontract1
          where obj.codobiect = aCodObiect and C1.CodContract = aCodContract
                and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc
                and i1.codies1 = aCodDoc1;
        exception when others then
          vCodContract1 := 0;
        end;
        if vCodContract1 = 0 then
          begin
            select nvl(c1.CodContract1,0) into vCodContract1
            from contract1 c1
                 inner join nart a on a.clasa = c1.codclasa
                 inner join nartobj obj on obj.codarticol = a.codarticol
                 inner join contract c on c1.codcontract = c.codcontract
                 inner join iesiri i on i.codcontract = c.codcontract
                 inner join iesiri1 i1 on i1.codies = i.codies and i1.codobiect = c1.codobiect
            where i1.codobiect = aCodObiect and C1.CodContract = aCodContract
                  and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc
                  and i1.codies1 = aCodDoc1;
          exception when others then
            vCodContract1 := 0;
          end;
        end if;
      end if;
    else
      if vTipArticol = 0 then
        begin
          select nvl(c1.CodContract1,0) into vCodContract1
          from contract1 c1
               inner join contract c on c1.codcontract = c.codcontract
               inner join intrari1 i1 on c1.codcontract1 = i1.codcontract1
          where C1.codobiect = aCodObiect and C1.CodContract = aCodContract
                and i1.codintr1 = aCodDoc1;
        exception when others then
          vCodContract1 := 0;
        end;
        if vCodContract1 = 0 then
          begin
            select nvl(c1.CodContract1,0) into vCodContract1
            from contract1 c1
                 inner join contract c on c1.codcontract = c.codcontract
                 inner join intrari i on i.codcontract = c.codcontract
                 inner join intrari1 i1 on i1.codintr = i.codintr and i1.codobiect = c1.codobiect
            where i1.codobiect = aCodObiect and C1.CodContract = aCodContract
                  and i1.codintr1 = aCodDoc1;
          exception when others then
            vCodContract1 := 0;
          end;
        end if;
      else
        begin
          select nvl(c1.CodContract1,0) into vCodContract1
          from contract1 c1
               inner join nart a on a.clasa = c1.codclasa
               inner join nartobj obj on obj.codarticol = a.codarticol
               inner join contract c on c1.codcontract = c.codcontract
               inner join intrari1 i1 on c1.codcontract1 = i1.codcontract1
          where obj.codobiect = aCodObiect and C1.CodContract = aCodContract
                and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc
                and i1.codintr1 = aCodDoc1;
        exception when others then
          vCodContract1 := 0;
        end;
        if vCodContract1 = 0 then
          begin
            select nvl(c1.CodContract1,0) into vCodContract1
            from contract1 c1
                 inner join nart a on a.clasa = c1.codclasa
                 inner join nartobj obj on obj.codarticol = a.codarticol
                 inner join contract c on c1.codcontract = c.codcontract
                 inner join intrari i on i.codcontract = c.codcontract
                 inner join intrari1 i1 on i1.codintr = i.codintr and i1.codobiect = c1.codobiect
            where i1.codobiect = aCodObiect and C1.CodContract = aCodContract
                  and Nvl(C1.DataStart,C.DataStart) &lt;= aDataDoc AND Nvl(C1.DataStop,C.DataStop)  &gt;= aDataDoc
                  and i1.codintr1 = aCodDoc1;
          exception when others then
            vCodContract1 := 0;
          end;
        end if;
      end if;
    end if;
  end if;

  return vCodContract1;
end;

procedure MAKE_MANEVRA_NC(aCodNCredit in number, CuCommit in boolean default True) is
begin
  delete manevra_notecredit;
  KArtDiscAcTer       := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  KArtDiscPrimTer     := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscPrimVol     := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscPrimCant    := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;,    PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenPrimTer      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,         PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceF := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceF&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  for v_rec in (select nc.tipdoc, nvl(nc.codcontract,0) codcontract, nc.codpart, nc.datastart, nc.datastop, nc.subunitatea, nc.codmoneda,
                       nvl(c.TipTargetV,0) TipTargetV
                from notecredit nc
                     inner join contract c on nc.codcontract = c.codcontract
                where nc.codncredit = aCodNCredit) loop
    if v_Rec.TipDoc = 58 then
      if v_rec.TipTargetV = 0 then
        insert into manevra_notecredit(codobiect, valoare, UserID, Codncredit)
        select 0, SUM(ValM), pkg_globals.GETUSERID, aCodNCredit from (
          select SUM(case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else i1.cant * i1.pu end) ValM
          FROM IESIRI I
               INNER JOIN iesiri1 I1 on i.codies = i1.codies
          where I.TipDoc IN (19, 21, 26) AND I.Partener = v_rec.codpart
            AND NVL(I.Anulat,0) = 0 and i.operat = 1
            AND I1.CodObiect &gt; 0
            AND I.DataDoc BETWEEN v_rec.datastart and v_rec.DataStop
            AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
            AND I.Subunitatea = v_rec.subunitatea
            and I.Moneda = v_Rec.codmoneda
          union all
          select SUM(i1.restfact) ValM
          FROM IESIRI I
               INNER JOIN iesiri1 I1 on i.codies = i1.codies
          where I.TipDoc IN (19, 21, 26) AND I.Partener = v_Rec.codpart
            AND NVL(I.Anulat,0) = 0 and i.operat = 1
            AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
            AND I.DataDoc BETWEEN v_rec.DataStart and v_Rec.DataStop
            AND I.Subunitatea = v_Rec.Subunitatea
            and I.Moneda = v_Rec.CodMoneda
          );
      else if v_rec.TipTargetV = 1 then
        insert into manevra_notecredit(codobiect, valoare, UserID, CodNCredit)
        select 0, SUM(ValM), pkg_globals.GETUSERID, aCodNCredit from (
          select SUM(case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else i1.cant * i1.pu end else I1.Cant * C1.pret end) ValM
          FROM IESIRI I
               INNER JOIN iesiri1 I1 on i.codies = i1.codies
               INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.codcontract)
          where I.TipDoc IN (19, 21, 26) AND I.Partener = v_rec.CodPart
            AND NVL(I.Anulat,0) = 0 and i.operat = 1
            AND I1.CodObiect &gt; 0
            AND I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
            AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
            AND I.Subunitatea = v_rec.Subunitatea
            and I.Moneda = v_Rec.CodMoneda
            and c1.codcontract = v_Rec.CodContract
          union all
          select SUM(i1.restfact) ValM
          FROM IESIRI I
               INNER JOIN iesiri1 I1 on i.codies = i1.codies
               INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.codcontract)
          where I.TipDoc IN (19, 21, 26) AND I.Partener = v_Rec.CodPart
            AND NVL(I.Anulat,0) = 0 and i.operat = 1
            AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
            AND I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
            AND I.Subunitatea = v_Rec.subunitatea
            and I.Moneda = v_rec.codmoneda
            and c1.codcontract = v_Rec.codcontract
          );
      else
        insert into manevra_notecredit(codobiect, codcontract1, valoare, UserID, Codncredit, valoare_b)
        select codobiect, codcontract1, sum(valm), pkg_globals.GETUSERID, aCodNCredit, sum(valm_b) from (
        select i1.codobiect, c1.codcontract1,
               SUM(case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end else I1.Cant * C1.pret end) valm,
               SUM(case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end else I1.Cant * C1.pret end) valm_b
        FROM IESIRI I
             inner join iesiri1 I1 on i.codies = i1.codies
             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_Rec.CodContract)
        where I.DataDoc BETWEEN v_Rec.DataStart and v_rec.DataStop
              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
              AND I1.CodObiect &gt; 0
              and c1.codcontract = v_Rec.CodContract
              and i.subunitatea = v_Rec.Subunitatea
              and ((i.partener = v_Rec.CodPart) or (i.partcustodie = v_rec.codpart))
        group by i1.codobiect, c1.codcontract1
         union all
        select i1.CodObiect, c1.codcontract1, SUM(i1.restfact) ValM, SUM(i1.restfact) ValM_b
        FROM IESIRI I
             INNER JOIN iesiri1 I1 on i.codies = i1.codies
             INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.CodContract)
        where I.TipDoc IN (19, 21, 26)
          AND NVL(I.Anulat,0) = 0 and i.operat = 1
          AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
          AND I.DataDoc BETWEEN v_Rec.DataStart and v_rec.DataStop
          AND I.Subunitatea = v_rec.Subunitatea
          and I.Moneda = v_Rec.CodMoneda
          and c1.codcontract = v_Rec.CodContract
          and ((i.partener = v_Rec.CodPart) or (i.partcustodie = v_rec.codpart))
         group by i1.codobiect, c1.codcontract1
          ) group by codobiect, codcontract1;
      end if;
      end if;
    else
      if v_rec.TipTargetV = 0 then
        insert into manevra_notecredit(codobiect, valoare, UserID, Codncredit)
        select 0, SUM(ValM), pkg_globals.GETUSERID, aCodNCredit from (
        select SUM(I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)) ValM
        FROM Intrari I
             inner join intrari1 I1 on i.codintr = i1.codintr
        where I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              AND I1.CodObiect &gt; 0
              and i.subunitatea = v_rec.Subunitatea
              and i.partener = v_rec.CodPart
        union all
        select SUM(I1.restfact) ValM
        FROM INTRARI I
             INNER JOIN intrari1 I1 on i.codintr = i1.codintr
        where I.TipDoc IN (1, 3, 4, 5, 9) AND I.Partener = v_rec.CodPart
          AND I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
          and i.operat = 1 and NVL(I.Anulat,0) = 0
          and I.Moneda = v_rec.CodMoneda
          AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
          AND I.Subunitatea = v_rec.Subunitatea
         );
      else if v_rec.TipTargetV = 1 then
        insert into manevra_notecredit(codobiect, valoare, UserID, Codncredit)
        select 0, SUM(ValM), pkg_globals.GETUSERID, aCodNCredit from (
        select SUM(case when nvl(c1.tipdiscount,0) = 0 then I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1) else I1.Cant * C1.pret end) ValM
        FROM Intrari I
             inner join intrari1 I1 on i.codintr = i1.codintr
             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.CodContract)
        where I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              AND I1.CodObiect &gt; 0
              and i.subunitatea = v_rec.Subunitatea
              and i.partener = v_rec.CodPart
              and c1.codcontract = v_rec.CodContract
        union all
        select SUM(I1.restfact) ValM
        FROM INTRARI I
             INNER JOIN intrari1 I1 on i.codintr = i1.codintr
             INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.CodContract)
        where I.TipDoc IN (1, 3, 4, 5, 9) AND I.Partener = v_rec.CodPart
          AND I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
          and i.operat = 1 and NVL(I.Anulat,0) = 0
          and I.Moneda = v_rec.CodMoneda
          AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
          AND I.Subunitatea = v_rec.Subunitatea
          and c1.codcontract = v_rec.CodContract
         );
      else
        insert into manevra_notecredit(codobiect, codcontract1, valoare, UserID, CodNCredit, valoare_b)
        select codobiect, codcontract1, SUM(ValM), pkg_globals.GETUSERID, aCodNCredit, sum(valm_b) from (
        select i1.codobiect, c1.codcontract1,
        SUM(case when nvl(c1.tipdiscount,0) = 0 then I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1) else I1.Cant * C1.pret end) ValM,
        SUM(case when nvl(c1.tipdiscount,0) = 0 then I1.Cant*I1.PretOrig else I1.Cant * C1.pret end) ValM_b
        FROM Intrari I
             inner join intrari1 I1 on i.codintr = i1.codintr
             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.CodContract)
        where I.DataDoc BETWEEN v_Rec.DataStart and v_rec.DataStop
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              AND I1.CodObiect &gt; 0
              and i.subunitatea = v_rec.Subunitatea
              and i.partener = v_Rec.CodPart
              and c1.codcontract = v_rec.CodContract
        group by i1.codobiect, c1.codcontract1
        union all
        select i1.CodObiect, c1.codcontract1, SUM(I1.restfact) ValM, SUM(I1.restfact) ValM_b
        FROM INTRARI I
             INNER JOIN intrari1 I1 on i.codintr = i1.codintr
             INNER JOIN contract1 c1 on c1.codcontract1 = pkg_notecredit.getcodcontract1(i1.codobiect, i.datadoc, v_rec.CodContract)
        where I.TipDoc IN (1, 3, 4, 5, 9) and i.partener = v_Rec.CodPart
          AND I.DataDoc BETWEEN v_rec.DataStart and v_rec.DataStop
          and i.operat = 1 and NVL(I.Anulat,0) = 0
          and I.Moneda = v_rec.CodMoneda
          AND (i1.tiplinie = &apos;T&apos; or i1.tiplinie = &apos;G&apos;)
          AND I.Subunitatea = v_Rec.Subunitatea
          and c1.codcontract = v_rec.CodContract
         group by i1.CodObiect, c1.codcontract1 )
         group by CodObiect, codcontract1;
      end if;
      end if;
    end if;
  end loop;
  if CuCommit then commit; end if;
end;

procedure MAKE_MANEVRA_T(aCodContract in number) is
DeLa number(10);
sDeLa varchar2(40);
DeLaData Date;
begin
  delete contractt_manevra;
  delete tmp_manevra_liste where filtru = &apos;CODOBIECT&apos; AND FILTRU1 = &apos;TERMENFIX&apos;;
  sDeLa := &apos;30.12.1899&apos;;
  for v_rec in (
    select &apos;CODOBIECT&apos; FILTRU, c1.codobiect VALOARE, &apos;TERMENFIX&apos; FILTRU1, to_char(ct.termenfix, &apos;dd.mm.yyyy&apos;) stermenfix, ct.termenfix
    from contractt ct
         inner join contract1 c1 on c1.codcontract1 = ct.codcontract1
    where c1.codcontract = aCodContract
    order by codobiect, termenfix
  ) loop
    insert into tmp_manevra_liste(filtru, filtru1, valoare, valoare1, valoare2)
    values (v_rec.filtru, v_rec.filtru1, v_rec.valoare, sDeLa, v_rec.stermenfix);
    sDeLa := to_char(v_rec.termenfix + 1, &apos;dd.mm.yyyy&apos;);
  end loop;

  for v_tmp in (select nvl(TipDiscountT,0) TipDiscountT, CodContract1
       from contract1
       where codcontract = aCodContract and nvl(DiscTCumulat,0) = 1
      ) loop
    if v_tmp.TipDiscountT = 0 then
      -- tip discount la zile plata
      DeLa := 0;
      FOR v_rec IN ( SELECT * FROM contractt WHERE codcontract1 = v_tmp.CodContract1 ORDER BY zile ) LOOP
        insert into contractt_manevra (CODCONTRACTT, CODCONTRACT1, ZILE, DISCOUNT, VALDISCOUNT, TERMENFIX,
                                       PROCVALDOC, ZILEDELA)
        values (v_rec.CODCONTRACTT, v_rec.CODCONTRACT1, v_rec.ZILE, v_rec.DISCOUNT, v_rec.VALDISCOUNT, v_rec.TERMENFIX,
                v_rec.PROCVALDOC, DELA);
        DeLa := v_rec.ZILE + 1;
      END LOOP;
    else
      DeLaData := to_date(&apos;01.01.1899&apos;,&apos;dd.mm.yyyy&apos;);
      FOR v_rec IN ( SELECT * FROM contractt WHERE codcontract1 = v_tmp.CodContract1 ORDER BY termenfix ) LOOP
        insert into contractt_manevra (CODCONTRACTT, CODCONTRACT1, ZILE, DISCOUNT, VALDISCOUNT, TERMENFIX,
                                       PROCVALDOC, TERMENFIXDELA)
        values (v_rec.CODCONTRACTT, v_rec.CODCONTRACT1, v_rec.ZILE, v_rec.DISCOUNT, v_rec.VALDISCOUNT, v_rec.TERMENFIX,
                v_rec.PROCVALDOC, DeLaData);
        DeLaData := v_rec.TERMENFIX + 1;
      END LOOP;
    end if;
  end loop;
  commit;
end;

function IsCumulat(vCodDoc1 in number, vCodContract in number, vTip in number) return number is
vCumulat number(1);
begin
  vCumulat := 0;
  if vTip = 1 then
    if vCodContract &gt; 0 then
      begin
        select nvl(C1.DISCTCUMULAT, 0) into vCumulat
          from iesiri1 i1
               inner join iesiri i on i.codies = i1.codies
               inner join contract1 c1 on i1.codobiect = c1.codobiect
               inner join contract c on c1.codcontract = c.codcontract
          where i1.codies1 = vCodDoc1 and C1.CodContract = vCodContract
                and i.datadoc between nvl(c1.datastart, c.datastart) and nvl(c1.datastop, c.datastop);
      exception when others then
        vCumulat := 0;
      end;
    end if;
  else
    if vCodContract &gt; 0 then
      begin
        select nvl(C1.DISCTCUMULAT, 0) into vCumulat
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
             inner join contract1 c1 on i1.codobiect = c1.codobiect
             inner join contract c on c1.codcontract = c.codcontract
        where i1.codintr1 = vCodDoc1 and C1.CodContract = vCodContract
              and i.datadoc between nvl(c1.datastart, c.datastart) and nvl(c1.datastop, c.datastop);
      exception when others then
        vCumulat := 0;
      end;
    end if;
  end if;
  return vCumulat;
end;

FUNCTION GETDISCVOLUM(aCODDOC IN NUMBER, aCodContract in number, aTip in number, aCodNCredit in number, PretBrut in number default 0, aCurs in number default 1) RETURN NUMBER IS
vDisc number(20,7);
vProcDisc number(20,7);
vValDisc number(20,7);
vTipDisc number(1);
vValDoc number(20,7);
vTotal number(20,7);
vCurs number(10,7);
BEGIN
  if aCurs = 0 then vCurs := 1; else vCurs := aCurs; end if;
  KArtDiscAcTer       := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  KArtDiscPrimTer     := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscPrimVol     := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscPrimCant    := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;,    PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenPrimTer      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,         PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceF := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceF&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  if aCodContract = 0 then Return 0; end if;
  vDisc := 0;
  begin
    select nvl(TipTargetV,0) into vTipDisc from contract where codcontract = aCodContract;
  exception when others then vTipDisc := 0;
  end;

  if aTip = 1 then
  -- clienti
    if vTipDisc = 0 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when NVL(PretBrut,0) &lt;&gt; 1 then
                case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                else case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
              end
            ) ValM
            FROM IESIRI I
                 inner join iesiri1 I1 on i.codies = i1.codies
            where i1.codobiect &gt; 0
              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
              and i.codies = aCodDoc
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else if vTipDisc = 1 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNcredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when NVL(PretBrut,0)&lt;&gt; 1 then
                case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                else case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
              end
            ) ValM
            FROM IESIRI I
                 inner join iesiri1 I1 on i.codies = i1.codies
                 inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
            where i1.codobiect &gt; 0
              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
              and i.codies = aCodDoc
              and c1.codcontract = aCodContract
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else
      for v_rec in ( select a.codobiect, a.codcontract1, sum(a.valm) valm, tmp.valoare valtot from (
                        select
                          I1.CodObiect,
                          c1.codcontract1,
                          SUM(
                            case when  NVL(PretBrut,0) &lt;&gt; 1 then
                              case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                              else case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
                            end
                          ) ValM
                        FROM IESIRI I
                             inner join iesiri1 I1 on i.codies = i1.codies
                             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
                        where i1.codobiect &gt; 0
                          AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                          and i1.codies1 = aCodDoc
                          and c1.codcontract = aCodContract
                       group by I1.CodObiect, c1.codcontract1
                       ) a
                       inner join manevra_notecredit tmp on a.codobiect = tmp.codobiect and a.codcontract1 = tmp.codcontract1 and tmp.UserID = pkg_globals.GETUSERID
                                                         and tmp.codncredit = aCodNCredit
                       where tmp.valoare &lt;&gt; 0
                       group by a.codobiect, a.codcontract1, tmp.valoare
                   ) loop
        begin
          select nvl(cv.Discount, 0) into vProcDisc
          from contractv cv
               inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
          where cv.codcontract = aCodContract
          and c1.codcontract1 = v_rec.codcontract1
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
        exception when others then vProcDisc := 0;
        end;
        if vProcDisc = 0 then
          begin
            select nvl(cv.ValDiscount, 0) into vValDisc
            from contractv cv
                 inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
            where cv.codcontract = aCodContract
            and c1.codcontract1 = v_rec.codcontract1
            and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
          exception when others then vValDisc := 0;
          end;
        end if;

        if vProcDisc &lt;&gt; 0 then
          vDisc := vDisc + v_Rec.ValM * vProcDisc/100;
        else
          vDisc := vDisc + v_Rec.ValM / v_Rec.valtot * vValDisc * vCurs;
        end if;
      end loop;
    end if;
    end if;
  else
    -- furnizori
    if vTipDisc = 0 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and codncredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when  NVL(PretBrut,0) &lt;&gt; 1 then
                I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
              else
                I1.Cant*I1.PretOrig
              end
            ) ValM
            FROM Intrari I
                 inner join intrari1 I1 on i.codintr = i1.codintr
            where i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              and i.codintr = aCodDoc
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else if vTipDisc = 1 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(case when  NVL(PretBrut,0) &lt;&gt; 1 then
                         I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
                       else
                         I1.Cant*I1.PretOrig
                       end) ValM
            FROM Intrari I
                 inner join intrari1 I1 on i.codintr = i1.codintr
                 inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
            where i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              and i.codintr = aCodDoc
              and c1.codcontract = aCodContract
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else
      for v_rec in ( select a.codobiect, a.codcontract1, sum(a.valm) valm, tmp.valoare valtot from (
                        select I1.CodObiect, c1.codcontract1, SUM(case when  NVL(PretBrut,0) &lt;&gt; 1 then
                                                                    I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
                                                                  else
                                                                    I1.Cant*I1.PretOrig
                                                                  end) ValM
                        FROM Intrari I
                             inner join intrari1 I1 on i.codintr = i1.codintr
                             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
                        where i1.codobiect &gt; 0
                          AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                          and i1.codintr1 = aCodDoc
                          and c1.codcontract = aCodContract
                       group by I1.CodObiect, c1.codcontract1 ) a
                       left join manevra_notecredit tmp on a.codobiect = tmp.codobiect and a.codcontract1 = tmp.codcontract1 and UserID = pkg_globals.GETUSERID
                                                        and tmp.codncredit = aCodNCredit
                       group by a.codobiect, a.codcontract1, tmp.valoare
                   ) loop
        begin
          select nvl(cv.Discount, 0) into vProcDisc
          from contractv cv
               inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
          where cv.codcontract = aCodContract
          and c1.codcontract1 = v_rec.codcontract1
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
        exception when others then vProcDisc := 0;
        end;
        if vProcDisc = 0 then
          begin
            select nvl(cv.ValDiscount, 0) into vValDisc
            from contractv cv
                 inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
            where cv.codcontract = aCodContract
            and c1.codcontract1 = v_rec.codcontract1
            and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
          exception when others then vValDisc := 0;
          end;
        end if;

        if vProcDisc &lt;&gt; 0 then
          vDisc := vDisc + v_Rec.ValM * vProcDisc/100;
        else
          vDisc := vDisc + v_Rec.ValM / v_Rec.valtot * vValDisc * vCurs;
        end if;
      end loop;
    end if;
    end if;
  end if;
  return vDisc;
END;

FUNCTION GETDISCVOLUMTRIM(aCODDOC IN NUMBER, aCodContract in number, aTip in number, aCodNCredit in number, Trimestru in number, PretBrut in number default 0, aCurs in number default 1) RETURN NUMBER IS
vDisc number(20,7);
vProcDisc number(20,7);
vValDisc number(20,7);
vTipDisc number(1);
vValDoc number(20,7);
vTotal number(20,7);
vCurs number(10,7);
BEGIN
  if aCurs = 0 then vCurs := 1; else vCurs := aCurs; end if;
  KArtDiscAcTer       := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  KArtDiscPrimTer     := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscPrimVol     := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscPrimCant    := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;,    PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenPrimTer      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,         PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceF := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceF&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  if aCodContract = 0 then Return 0; end if;
  vDisc := 0;
  begin
    select nvl(TipTargetV,0) into vTipDisc from contract where codcontract = aCodContract;
  exception when others then vTipDisc := 0;
  end;

  if aTip = 1 then
  -- clienti
    if vTipDisc = 0 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when NVL(PretBrut,0) &lt;&gt; 1 then
                case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                else case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
              end
            ) ValM
            FROM IESIRI I
                 inner join iesiri1 I1 on i.codies = i1.codies
            where i1.codobiect &gt; 0
              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
              and i.codies = aCodDoc
           ) a;

      if Trimestru = 1 then
        begin
          select nvl(c.discount1, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma1 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 2 then
        begin
          select nvl(c.discount2, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma2 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 3 then
        begin
          select nvl(c.discount3, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma3 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 4 then
        begin
          select nvl(c.discount4, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma4 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      end if;
      end if;
      end if;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      end if;
    else if vTipDisc = 1 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNcredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when  NVL(PretBrut,0) &lt;&gt; 1 then
                case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                else case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
              end
            ) ValM
            FROM IESIRI I
                 inner join iesiri1 I1 on i.codies = i1.codies
                 inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
            where i1.codobiect &gt; 0
              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
              and i.codies = aCodDoc
              and c1.codcontract = aCodContract
           ) a;

      if Trimestru = 1 then
        begin
          select nvl(c.discount1, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma1 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 2 then
        begin
          select nvl(c.discount2, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma2 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 3 then
        begin
          select nvl(c.discount3, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma3 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      else if Trimestru = 4 then
        begin
          select nvl(c.discount4, 0) into vProcDisc
          from contract c
          where c.codcontract = aCodContract
                and c.suma4 &lt;= vTotal;
        exception when others then vProcDisc := 0;
        end;
      end if;
      end if;
      end if;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      end if;
    end if;
    end if;
  else
    -- furnizori
    if vTipDisc = 0 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and codncredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(
              case when NVL(PretBrut,0) &lt;&gt; 1 then
                I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
              else
                I1.Cant*I1.PretOrig
              end
            ) ValM
            FROM Intrari I
                 inner join intrari1 I1 on i.codintr = i1.codintr
            where i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              and i.codintr = aCodDoc
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else if vTipDisc = 1 then
      begin
      select valoare into vTotal from manevra_notecredit where codobiect = 0 and rownum = 1 and UserID = pkg_globals.GETUSERID and CodNCredit = aCodNCredit;
      exception when others then vTotal := 0;
      end;

      if vTotal = 0 then return 0; end if;

      select sum(nvl(a.valm,0)) into vValDoc
      from (
            select SUM(case when NVL(PretBrut,0) &lt;&gt; 1 then
                         I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
                       else
                         I1.Cant*I1.PretOrig
                       end) ValM
            FROM Intrari I
                 inner join intrari1 I1 on i.codintr = i1.codintr
                 inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
            where i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              and i.codintr = aCodDoc
              and c1.codcontract = aCodContract
           ) a;

      begin
        select nvl(cv.Discount, 0) into vProcDisc
        from contractv cv
        where cv.codcontract = aCodContract
              and nvl(cv.codcontract1,0) = 0
              and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
      exception when others then vProcDisc := 0;
      end;
      if vProcDisc = 0 then
        begin
          select nvl(cv.ValDiscount, 0) into vValDisc
          from contractv cv
          where cv.codcontract = aCodContract
          and nvl(cv.codcontract1,0) = 0
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= vTotal and nvl(ccv.codcontract1,0) = 0);
        exception when others then vValDisc := 0;
        end;
      end if;

      if vProcDisc &lt;&gt; 0 then
        vDisc := vValDoc * vProcDisc/100;
      else
        vDisc := vValDoc / vTotal * vValDisc * vCurs;
      end if;
    else
      for v_rec in ( select a.codobiect, a.codcontract1, sum(a.valm) valm, tmp.valoare valtot from (
                        select I1.CodObiect, c1.codcontract1, SUM(case when NVL(PretBrut,0) &lt;&gt; 1 then
                                                                    I1.Cant*I1.PretOrig*nvl(I1.CoefDiscMaj,1)
                                                                  else
                                                                    I1.Cant*I1.PretOrig
                                                                  end) ValM
                        FROM Intrari I
                             inner join intrari1 I1 on i.codintr = i1.codintr
                             inner join contract1 c1 on c1.codcontract1 = pkg_notecredit.GetCodContract1(i1.codobiect, i.datadoc, aCodContract)
                        where i1.codobiect &gt; 0
                          AND I1.CodObiect not in (KArtDiscPrimVol,KArtDiscPrimCant,KArtPenPrimTer) AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                          and i1.codintr1 = aCodDoc
                          and c1.codcontract = aCodContract
                       group by I1.CodObiect, c1.codcontract1 ) a
                       left join manevra_notecredit tmp on a.codobiect = tmp.codobiect and a.codcontract1 = tmp.codcontract1 and UserID = pkg_globals.GETUSERID
                                                        and tmp.codncredit = aCodNCredit
                       group by a.codobiect, a.codcontract1, tmp.valoare
                   ) loop
        begin
          select nvl(cv.Discount, 0) into vProcDisc
          from contractv cv
               inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
          where cv.codcontract = aCodContract
          and c1.codcontract1 = v_rec.codcontract1
          and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
        exception when others then vProcDisc := 0;
        end;
        if vProcDisc = 0 then
          begin
            select nvl(cv.ValDiscount, 0) into vValDisc
            from contractv cv
                 inner join contract1 c1 on cv.codcontract1 = c1.codcontract1
            where cv.codcontract = aCodContract
            and c1.codcontract1 = v_rec.codcontract1
            and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = aCodContract and suma &lt;= v_rec.valtot and ccv.codcontract1 = c1.codcontract1);
          exception when others then vValDisc := 0;
          end;
        end if;

        if vProcDisc &lt;&gt; 0 then
          vDisc := vDisc + v_Rec.ValM * vProcDisc/100;
        else
          vDisc := vDisc + v_Rec.ValM / v_Rec.valtot * vValDisc * vCurs;
        end if;
      end loop;
    end if;
    end if;
  end if;
  return vDisc;
END;

procedure UpdateCentralizare(aCodDoc in number, aCodNC in number, aCodDoc1 in number default 0) is
vtipdoc number(10);
vVal number(20);
begin
  select TipDoc into vTipDoc from notecredit where codncredit = acodnc;
  if aCodDoc1 &gt; 0 then
    if vTipDoc = 58 then
      for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                           case
                             when art.tiparticol = 0 then i1.cant
                           else
                             case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else I1.Cant*I1.PU end
                           end  valoare
                    from iesiri1 i1
                         inner join iesiri i on i.codies = i1.codies
                         inner join nartobj obj on i1.codobiect = obj.codobiect
                         inner join nart art on obj.codarticol = art.codarticol
                    where i1.codies = Abs(aCodDoc)) loop

        update centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_Rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;

        update tmp_centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;

      end loop;
    else
      for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                           case when art.tiparticol = 0 then I1.Cant*I1.PU else i1.cant end valoare
                    from intrari1 i1
                         inner join nartobj obj on i1.codobiect = obj.codobiect
                         inner join nart art on obj.codarticol = art.codarticol
                    where i1.codintr = Abs(aCodDoc)) loop
        vVal := v_rec.valoare;
        for v_tmp in (
          select coalesce(facturat,0) facturat, coalesce(diferente,0) diferente, codcentralizare
          from centralizarenc
          where nvl(codobiect,0) = v_rec.codobiect and codncredit = aCodNC and facturat &lt;&gt; 0
        ) loop
          if vVal &gt; v_tmp.facturat then
            vVal := vVal - v_tmp.facturat;
            update centralizarenc
            set
              diferente = nvl(diferente,0) + coalesce(facturat,0),
              facturat  = 0
            where codcentralizare = v_tmp.codcentralizare;

            update tmp_centralizarenc
            set
              diferente = nvl(diferente,0) + coalesce(facturat,0),
              facturat  = 0
            where codcentralizare = v_tmp.codcentralizare;
          else
            update centralizarenc
            set
              diferente = nvl(diferente,0) + vVal,
              facturat  = coalesce(facturat,0) - vVal
            where codcentralizare = v_tmp.codcentralizare;

            update tmp_centralizarenc
            set
              diferente = nvl(diferente,0) + vVal,
              facturat  = coalesce(facturat,0) - vVal
            where codcentralizare = v_tmp.codcentralizare;
            vVal := 0;
          end if;
          if vVal &lt;= 0 then Exit; end if;
        end loop;
      end loop;
    end if;
  else
    if vTipDoc = 58 then
      for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                           case
                             when art.tiparticol = 0 then i1.cant
                           else
                             case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else I1.Cant*I1.PU end
                           end  valoare
                    from iesiri1 i1
                         inner join iesiri i on i.codies = i1.codies
                         inner join nartobj obj on i1.codobiect = obj.codobiect
                         inner join nart art on obj.codarticol = art.codarticol
                    where i1.codies = Abs(aCodDoc)) loop

        update centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_Rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;

        update tmp_centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;

      end loop;
    else
      for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                           case when art.tiparticol = 0 then I1.Cant*I1.PU else i1.cant end valoare
                    from intrari1 i1
                         inner join nartobj obj on i1.codobiect = obj.codobiect
                         inner join nart art on obj.codarticol = art.codarticol
                    where i1.codintr = Abs(aCodDoc)) loop

        update centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;

        update tmp_centralizarenc
        set
          diferente = nvl(diferente,0) - Sign(aCodDoc) * v_Rec.valoare,
          facturat  = nvl(facturat,0) + Sign(aCodDoc) * v_rec.valoare
        where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = aCodNC;
      end loop;
    end if;
  end if;  
  update tmp_notecredit set
    TOTALZ     = TOTALZ + (select nvl(Round(sum(valdoc),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0),
    TOTALLEIZ  = TOTALLEIZ + (select nvl(Round(sum(vallei),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0);
end;

PROCEDURE EMPTY_NOTE_TEMPTABLES
IS
begin
  delete tmp_notecredit;
  delete tmp_notecredit1;
  delete tmp_notecreditt;
  delete tmp_notecreditc;
  delete tmp_notecreditv;
  delete tmp_notecreditp;
  delete tmp_notecreditct;
  delete tmp_notecreditz;
  commit;
end;

function GetProcOffInvoice(vCodPart IN NUMBER, vData IN VARCHAR2, vCodSubunit IN NUMBER, vCodSediu IN NUMBER) return number IS
aProcNed NUMBER(10);
aProc NUMBER(10);
begin
  begin
    select NVL(SUM(NVL(DI.Procent, 0)), 0) into aProc
    from  NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = D.CODDISCOUNT
      INNER JOIN NAGENDA AG ON D.CODTIPSEDIU = AG.CODTIPSEDIU
    where CD.peclase = 3 and CD.offinvoice = 1 and AG.CODAGENDA = vCodSediu
      and CD1.Subunitatea = vCodSubunit
      and PD.CodPart = vCodPart
      and CD1.Datastart = (select max(CD11.datastart) from criteriidisc1 CD11 where to_date(vData, &apos;DD.MM.YYYY&apos;) &gt;= CD11.DATASTART and CD11.CODCRITERIU1 = cd1.codcriteriu1);
  exception when others then aProc := 0;
  end;
  begin
    select NVL(SUM(NVL(DI.Procent, 0)), 0) into aProcNed
    from  NPARTDISC PD
      INNER JOIN criteriidisc CD ON PD.CODCATEGDISC = CD.CODCRITERIU
      INNER JOIN criteriidisc1 CD1 ON CD.CODCRITERIU = CD1.CODCRITERIU
      INNER JOIN DISCOUNT D ON CD.CODCRITERIU = D.CODCRITERIU and CD1.CODCRITERIU1 = D.CODCRITERIU1
      INNER JOIN DISCINTERVAL DI ON DI.CODDISCOUNT = D.CODDISCOUNT
    where CD.peclase = 3 and CD.offinvoice = 1
      and CD1.Subunitatea = vCodSubunit and NVL(D.Codtipsediu, 0) = 0
      and PD.CodPart = vCodPart
      and CD1.Datastart = (select max(CD11.datastart) from criteriidisc1 CD11 where to_date(vData, &apos;DD.MM.YYYY&apos;) &gt;= CD11.DATASTART and CD11.CODCRITERIU1 = cd1.codcriteriu1);
  exception when others then aProcNed := 0;
  end;
  return aProc + aProcNed;
end;

function IntrareCuDiscount(CodIntr IN NUMBER) return number IS
aCount NUMBER(10);
begin
  begin
    select count(i1.codobiect) into aCount
    from intrari1 i1
    where i1.codintr = CodIntr and
         (i1.CodObiect in
         (nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0),
          nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0),
          nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0)) or
          INSTR(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), TO_CHAR(I1.CODOBIECT)) &gt; 0);
  exception when others then aCount := 0;
  end;
  return aCount;
end;

FUNCTION GETPROCCONTRACTVOLUM(vSuma IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
vTip number(1);
begin
  select c.tiptargetv into vTip from contract c where codcontract = vCodContract;
  if vTip &lt;= 1 then
    begin
      select nvl(cv.Discount, 0) into vProc
      from contractv cv
      where cv.codcontract = vCodContract
      and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = vCodContract and suma &lt;= vSuma);
    exception when others then vProc := 0;
    end;
  end if;
  Return vProc;
end;

FUNCTION GETVALDISCCONTRACTVOLUM(vSuma IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
begin
  begin
    select nvl(cv.ValDiscount, 0) into vProc
    from contractv cv
    where cv.codcontract = vCodContract
    and cv.suma = (select max(suma) from contractv CCv where CCv.Codcontract = vCodContract and suma &lt;= vSuma);
  exception when others then vProc := 0;
  end;
  Return vProc;
end;

FUNCTION GETPROCCONTRACTCANT(vCodObiect IN NUMBER, vValoare IN NUMBER, vCodContract IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
begin
  begin
    select nvl(cc.Discount, 0) into vProc
    from contractc cc
         inner join contract1 c1 on c1.codcontract1 = cc.codcontract1
         inner join num1 on c1.umsec = num1.codum1
    where c1.codcontract = vCodContract and c1.codobiect = vCodObiect
    and cc.cantmin = (select max(cantmin * num1.paritate) from contractc ccv where ccv.codcontract1 = c1.codcontract1 and cantmin*num1.paritate &lt;= vValoare);
  exception when others then vProc := 0;
  end;
  Return vProc;
end;

FUNCTION GETDISCCANT(vCant IN NUMBER, vValDoc IN NUMBER, vTotal IN NUMBER, vCodContract1 IN NUMBER, vPretMediu in number, vGlobal in number default 0, vCurs in number default 1) RETURN NUMBER IS
vProc NUMBER(20,7);
vVal  NUMBER(20,7);
vRez  NUMBER(20,7);
vValT NUMBER(20,7);
vTipDiscount NUMBER(1);
vTipDiscountC number(1);
vPret NUMBER(20,7);
vParitate number(20,7);
vRest number(20,7);
vLastP number(20,7);
vCount number(20);
vCodContract number(20);
begin
  select nvl(c1.TipDiscount, 0), nvl(c1.TipDiscountC, 0), c1.pret, decode(nvl(num1.paritate,1),0,1,nvl(num1.paritate,1)),c1.codcontract into vTipDiscount, vTipDiscountC, vPret, vParitate, vCodContract
  from contract1 c1
       inner join contract c on c.codcontract = c1.codcontract
       inner join num1 on num1.codum1 = c1.umsec
  where c1.codcontract1 = vCodContract1;
  vRez := 0;
  if vTipDiscountC = 0 then
    begin
      select nvl(cc.Discount, 0) into vProc
      from contractc cc
           inner join contract1 c1 on c1.codcontract1 = cc.codcontract1
           inner join num1 on c1.umsec = num1.codum1
      where c1.codcontract1 = vCodContract1
      and cc.cantmin*num1.paritate = (select max(cantmin * num1.paritate) from contractc where codcontract1 = c1.codcontract1 and cantmin*num1.paritate &lt;= vTotal);
    exception when others then vProc := 0;
    end;
    if vTipDiscount = 0 then
      vRez := vProc * vValDoc/100;
    else
      vRez := vProc / 100 * vCant * vPret / vParitate;
    end if;
  else if vTipDiscountC = 1 then
    begin
      select nvl(cc.ValDiscount, 0) into vVal
      from contractc cc
           inner join contract1 c1 on c1.codcontract1 = cc.codcontract1
           inner join num1 on c1.umsec = num1.codum1
      where c1.codcontract1 = vCodContract1
      and cc.cantmin*num1.paritate = (select max(cantmin * num1.paritate) from contractc where codcontract1 = c1.codcontract1 and cantmin*num1.paritate &lt;= vTotal);
    exception when others then vVal := 0;
    end;
    vRez := vVal * vCant / vParitate;
  else
    vRest := vTotal;
    vVal := 0;
    FOR vrec IN (
        SELECT cc.CantMin, cc.Discount
        FROM contract1 c1
             INNER JOIN contractc cc ON cc.codcontract1 = c1.codcontract1
        WHERE c1.codcontract1 = vCodContract1 AND cc.cantmin &lt;= vTotal
        ORDER BY cantmin DESC
      ) LOOP
          vLastP := vrec.discount;
          if vTipDiscount = 0 then
            vVal   := vVal + vLastP/100 * vrec.CantMin * vPretMediu;
          else
            vVal   := vVal + vLastP/100 * vrec.CantMin * vPret;
          end if;
          vRest  := vRest - vrec.CantMin;
    END LOOP;
    if vTipDiscount = 0 then
      vVal := vVal + vLastP/100 * vRest * vPretMediu;
    else
      vVal := vVal + vLastP/100 * vRest * vPret;
    end if;

    vRez := vCant/vTotal * vVal;
  end if;
  end if;
  vValT := 0;
  if vGlobal &gt; 0 then
    begin
      select nvl(cc.Discount, 0), nvl(cc.ValDiscount, 0) into vProc, vVal
      from contractc0 cc
      where cc.cantmin = (select max(c0.cantmin) from contractc0 c0 where c0.codcontract = cc.codcontract and c0.cantmin &lt;= vGlobal)
            and cc.codcontract = vCodContract;
    exception when others then vProc := 0; vVal := 0;
    end;
    if vProc &lt;&gt; 0 then
      if vTipDiscount = 0 then
        vValT := vProc/100 * vValDoc * vCant / vGlobal;
--        pkg_globals.baga_in_x(&apos;vtipdiscount - 0&apos;||vValT);
      else
        vValT := vProc/100 * vCant * vPret * vCant / vGlobal;
--        pkg_globals.baga_in_x(&apos;vtipdiscount - 1&apos;||vValT);
      end if;
    else if vVal &lt;&gt; 0 then
      vValT := vVal;
    end if;
    end if;
  end if;
  vRez := coalesce(vRez,0) + vValT;
  return vRez * vCurs;
end;

function getvalobiecties(aCodIes1 IN NUMBER, aTipDiscount in number, aPretC in number) RETURN NUMBER IS
aCodObiect NUMBER(20);
aVal NUMBER(20,7);
begin
  if aTipDiscount = 0 then
    select i1.codobiect into aCodObiect
    from iesiri1 i1 where i1.codies1 = aCodIes1;

    select sum(case when i.tipdoc = 21 then I1.Cant * I1.PU * I1.Coefdiscmaj - I1.Tva else i1.cant * i1.PU * i1.coefdiscmaj end) into aVal
    from iesiri1 i1
         inner join iesiri i on i1.codies = i.codies
    where i.codies = (select codies from iesiri1 where codies1 = aCodIes1) and i1.codobiect = aCodObiect;
  else
    select i1.codobiect into aCodObiect
    from iesiri1 i1 where i1.codies1 = aCodIes1;

    select sum(case when i.tipdoc = 21 then I1.Cant * aPretC * I1.Coefdiscmaj - I1.Tva else i1.cant * aPretC * i1.coefdiscmaj end) into aVal
    from iesiri1 i1
         inner join iesiri i on i1.codies = i.codies
    where i.codies = (select codies from iesiri1 where codies1 = aCodIes1) and i1.codobiect = aCodObiect;
  end if;
  return aVal;
end;

function getvalobiectintr(aCodIntr1 IN NUMBER, aTipDiscount in number, aPretC in number) RETURN NUMBER IS
aCodObiect NUMBER(20);
aVal NUMBER(20,7);
begin
  if aTipDiscount = 0 then
    select i1.codobiect into aCodObiect
    from intrari1 i1 where i1.codintr1 = aCodIntr1;

    select sum(I1.Cant * I1.PU * i1.Coefdiscmaj) into aVal
    from intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    where i.codintr = (select codintr from intrari1 where codintr1 = aCodIntr1) and i1.codobiect = aCodObiect;
  else
    select i1.codobiect into aCodObiect
    from intrari1 i1 where i1.codintr1 = aCodIntr1;

    select sum(I1.Cant * aPretC * i1.Coefdiscmaj) into aVal
    from intrari1 i1
         inner join intrari i on i1.codintr = i.codintr
    where i.codintr = (select codintr from intrari1 where codintr1 = aCodIntr1) and i1.codobiect = aCodObiect;
  end if;

  return aVal;
end;

FUNCTION GETDISCTERMENCLI(vDataPlata IN varchar2, vNrZile IN NUMBER, vCodContract IN NUMBER, vCodDoc1 IN NUMBER, vPlata IN NUMBER, vValOrig IN NUMBER DEFAULT 0) RETURN NUMBER IS
vDisc         NUMBER(20,7);
vProc         NUMBER(20,7);
vTipDiscount  NUMBER(1);
vPretC        NUMBER(20, 7);
vCodContract1 NUMBER(20);
vDiscTCumulat NUMBER(1);
vTipArticol   NUMBER(20);
BEGIN
  --insert into x(test) values (vDataPlata||&apos; &apos;||vNrZile||&apos; &apos;||vCodContract||&apos; &apos;||vCodDoc1||&apos; &apos;||vPlata||&apos; &apos;||vValOrig);
  IF Nvl(vCodContract,0) &gt; 0 AND Nvl(vCodDoc1,0) &gt; 0 THEN
    SELECT nvl(TipArticol,0) INTO vTipArticol
    FROM contract
    WHERE codcontract = vCodContract;

    IF vTipArticol = 0 THEN
      SELECT TipDiscount, PretC, CodContract1, DiscTCumulat INTO vTipDiscount, vPretC, vCodContract1, vDiscTCumulat
      FROM (
        SELECT Nvl(C1.TipDiscount, 0) TipDiscount, Nvl(c1.pret, 0) PretC, nvl(c1.CodContract1,0) CodContract1, NVL(C1.DiscTCumulat,0) DiscTCumulat
        FROM iesiri1 i1
          INNER JOIN iesiri i ON i.codies = i1.codies
          INNER JOIN contract1 c1 ON i1.codobiect = c1.codobiect
          INNER JOIN contract c ON c.codcontract = c1.codcontract
        WHERE i1.codies1 = vCodDoc1 AND C1.CodContract = vCodContract
          AND i.datadoc BETWEEN Nvl(c1.datastart,c.datastart) AND Nvl(c1.datastop,c.datastop)
          AND Nvl(c1.sediulivrare,0) IN (0, i.codlocatie)
        ORDER BY Nvl(c1.sediulivrare,0) DESC
      )
      WHERE ROWNUM = 1;
    ELSE
      SELECT TipDiscount, PretC, CodContract1, DiscTCumulat INTO vTipDiscount, vPretC, vCodContract1, vDiscTCumulat
      FROM (
        SELECT Nvl(C1.TipDiscount, 0) TipDiscount, Nvl(c1.pret, 0) PretC, nvl(c1.CodContract1,0) CodContract1, NVL(C1.DiscTCumulat,0) DiscTCumulat
        FROM iesiri1 i1
          INNER JOIN iesiri i ON i.codies = i1.codies
          INNER JOIN nartobj obj ON obj.codobiect = i1.codobiect
          INNER JOIN nart a ON a.codarticol = obj.codarticol
          INNER JOIN contract1 c1 ON a.clasa = c1.codclasa
          INNER JOIN contract c ON c.codcontract = c1.codcontract
        WHERE i1.codies1 = vCodDoc1 AND C1.CodContract = vCodContract
          AND i.datadoc BETWEEN nvl(c1.datastart,c.datastart) AND nvl(c1.datastop,c.datastop)
          AND Nvl(c1.sediulivrare,0) IN (0, i.codlocatie)
        ORDER BY Nvl(c1.sediulivrare,0) DESC
      )
      WHERE ROWNUM = 1;
    END IF;

    if vValOrig &gt; 0 then
      if vDiscTCumulat = 0 then
        if vTipDiscount = 0 then
          select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) into vProc
          from iesiri1 i1
          where i1.codies1 = vCodDoc1;
          if vProc &lt;&gt; 0 then
            begin
              select
                case
                  when coalesce(i.valdoc,0) = 0 then 0
                  else nvl(vProc/100 * vPlata/i.valdoc * (case when i.tipdoc = 21 then I1.Cant * I1.PU - I1.Tva else i1.cant * i1.PU end), 0)
                end into vDisc
              from iesiri1 i1
                   inner join iesiri i on i1.codies = i.codies
              where i1.codies1 = vCodDoc1;
            exception when others then vDisc := 0;
            end;
          else
            select case when coalesce(i.valdoc,0) = 0 then 0
                   else
                   nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                   I1.Cant * vPlata/i.valdoc
                   end
                   into vDisc
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
            where i1.codies1 = vCodDoc1;
          end if;
        else
          select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) into vProc
          from iesiri1 i1
          where i1.codies1 = vCodDoc1;
          if vProc &lt;&gt; 0 then
            begin
              select
                   case
                     when coalesce(i.valdoc,0) = 0 then 0
                     else nvl(vProc/100 * vPlata/i.valdoc * (case when i.tipdoc = 21 then I1.Cant * vPretC - I1.Tva else i1.cant * vPretC end), 0)
                   end into vDisc
              from iesiri1 i1
                   inner join iesiri i on i1.codies = i.codies
              where i1.codies1 = vCodDoc1;
            exception when others then vDisc := 0;
            end;
          else
            select case
                     when coalesce(i.valdoc,0) = 0 then 0
                     else nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                          I1.Cant * vPlata/i.valdoc
                   end
                   into vDisc
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
            where i1.codies1 = vCodDoc1;
          end if;
        end if;
      else
        vDisc := pkg_notecredit.GETDISCCUMULAT(vCodDoc1, vCodContract1, 1);
      end if;
    else
      if vDiscTCumulat = 0 then
        if vTipDiscount = 0 then
          select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) into vProc
          from iesiri1 i1
          where i1.codies1 = vCodDoc1;
          if vProc &lt;&gt; 0 then
            begin
              select
                case
                  when coalesce(i.valdoc,0) = 0 then 0
                  else nvl(vProc/100 * vPlata/i.valdoc * (case when i.tipdoc = 21 then (I1.Cant * I1.PU - I1.Tva) * I1.Coefdiscmaj else i1.cant * i1.PU * i1.coefdiscmaj end), 0)
                end into vDisc
              from iesiri1 i1
                   inner join iesiri i on i1.codies = i.codies
              where i1.codies1 = vCodDoc1;
            exception when others then vDisc := 0;
            end;
          else
            select case when coalesce(i.valdoc,0) = 0 then 0
                   else
                   nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                   I1.Cant * vPlata/i.valdoc
                   end
                   into vDisc
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
            where i1.codies1 = vCodDoc1;
          end if;
        else
          select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) into vProc
          from iesiri1 i1
          where i1.codies1 = vCodDoc1;
          if vProc &lt;&gt; 0 then
            begin
              select
                   case
                     when coalesce(i.valdoc,0) = 0 then 0
                     else nvl(vProc/100 * vPlata/i.valdoc * (case when i.tipdoc = 21 then I1.Cant * vPretC - I1.Tva else i1.cant * vPretC end), 0)
                   end into vDisc
              from iesiri1 i1
                   inner join iesiri i on i1.codies = i.codies
              where i1.codies1 = vCodDoc1;
            exception when others then vDisc := 0;
            end;
          else
            select case
                     when coalesce(i.valdoc,0) = 0 then 0
                     else nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                          I1.Cant * vPlata/i.valdoc
                   end
                   into vDisc
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
            where i1.codies1 = vCodDoc1;
          end if;
        end if;
      else
        vDisc := pkg_notecredit.GETDISCCUMULAT(vCodDoc1, vCodContract1, 1);
      end if;
    end if;
  else
    vDisc := 0;
  end if;

  Return vDisc;
end;

function GETDISCCUMULAT(vCodDoc1 in number, vCodContract1 in number, vTip in number, vValOrig IN NUMBER DEFAULT 0) return number is
vTotalPlata number(20,7);
vTotalDoc number(20,7);
vTotalLinie number(20,7);
vPartial number(20,7);
vCodObiect number(20);
vDisc number(20,7);
vTipDiscountT number(1);
vTipDiscountT1 number(1);
vDiscT number(20,7);
vCant number(20,7);
vDataDoc date;
begin
  vDisc := 0;
  if vValOrig &gt; 9 then
    if vTip = 1 then
      -- aduc codul de obiect valoarea liniei si valoare documentului
      select i1.codobiect, i.valdoc, i.datadoc, case when i.tipdoc = 21 then i1.PretOrig*i1.cant else i1.PretOrig*i1.cant+i1.tva end, i1.cant
      into vCodObiect, vTotalDoc, vDataDoc, vTotalLinie, vCant
      from iesiri1 i1
           inner join iesiri i on i.codies = i1.codies
      where codies1 = vCodDoc1;
      -- calculez valoarea totala a stingerilor
      begin
        select sum(s.valoare) into vTotalPlata
        from iesiri1 i1
             inner join iesiri i on i.codies = i1.codies
             inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
             inner join obligpif ostins on ostins.codgeneral = g.codgeneral
             inner join stingere s on s.codstinspif = ostins.codobligpif
        where i1.codies1 = vCodDoc1;
      exception when others then vTotalPlata := 0;
      end;
      -- daca nu este stins in totalitate se iese cu 0
      if vTotalDoc &lt;&gt; vTotalPlata then return 0; end if;

      begin
        select nvl(c1.TipDiscountT, 0) into vTipDiscountT
        from contract1 c1
        where c1.codcontract1 = vCodContract1;
      exception when others then vTipDiscountT := -1;
      end;

      if vTipDiscountT = 0 then
        -- tip discount la zile plata
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by zile) loop
          begin
            select sum(stingere.valoare) into vPartial
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
                 inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) - vDataDoc between v_rec.ziledela and v_rec.zile
                  and i1.codies1 = vCodDoc1
                  AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 1) OR (t1.TipTranz = 1 AND t1.ObiectTranz = 1) or (t1.tiptranz = 1 and t1.obiecttranz = 0 and gs.tipdoc = 33))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if
            vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      else if vTipDiscountT = 1 then
        -- tip discount la termen fix
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by termenfix) loop
          begin
            select sum(stingere.valoare) into vPartial
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
                 inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) between v_rec.termenfixdela and v_rec.termenfix
                  and i1.codies1 = vCodDoc1
                  AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 1) OR (t1.TipTranz = 1 AND t1.ObiectTranz = 1) or (t1.tiptranz = 1 and t1.obiecttranz = 0 and gs.tipdoc = 33))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      end if;
      end if;
    else
      select i1.codobiect, i.valdoc, i.datadoc, i1.pu*i1.cant+i1.tva, i1.cant
      into vCodObiect, vTotalDoc, vDataDoc, vTotalLinie, vCant
      from intrari1 i1
           inner join intrari i on i.codintr = i1.codintr
      where codintr1 = vCodDoc1;

      begin
        select sum(s.valoare) into vTotalPlata
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
             inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
             inner join obligpif ostins on ostins.codgeneral = g.codgeneral
             inner join stingere s on s.codstinspif = ostins.codobligpif
        where i1.codintr1 = vCodDoc1;
      exception when others then vTotalPlata := 0;
      end;

      if vTotalDoc &lt;&gt; vTotalPlata then return 0; end if;

      begin
        select nvl(c1.TipDiscountT, 0) into vTipDiscountT
        from contract1 c1
        where c1.codcontract1 = vCodContract1;
      exception when others then vTipDiscountT := -1;
      end;

      if vTipDiscountT = 0 then
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by zile) loop
          begin
            select sum(stingere.valoare) into vPartial
            from intrari1 i1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) - vDataDoc between v_rec.ziledela and v_rec.zile
                  and i1.codintr1 = vCodDoc1
                  AND ((G.TipDoc IN (29, 30, 31) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 1))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      else if vTipDiscountT = 1 then
        -- tip discount la termen fix
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by termenfix) loop
          begin
            select sum(stingere.valoare) into vPartial
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
                 inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) between v_rec.termenfixdela and v_rec.termenfix
                  and i1.codies1 = vCodDoc1
                  AND ((G.TipDoc IN (29, 30, 31) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 1))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      end if;
      end if;
    end if;
  else
    if vTip = 1 then
      -- aduc codul de obiect valoarea liniei si valoare documentului
      select i1.codobiect, i.valdoc, i.datadoc, case when i.tipdoc = 21 then i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) else (i1.PretOrig*i1.cant+i1.tva)*nvl(i1.coefdiscmaj,1) end, i1.cant
      into vCodObiect, vTotalDoc, vDataDoc, vTotalLinie, vCant
      from iesiri1 i1
           inner join iesiri i on i.codies = i1.codies
      where codies1 = vCodDoc1;
      -- calculez valoarea totala a stingerilor
      begin
        select sum(s.valoare) into vTotalPlata
        from iesiri1 i1
             inner join iesiri i on i.codies = i1.codies
             inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
             inner join obligpif ostins on ostins.codgeneral = g.codgeneral
             inner join stingere s on s.codstinspif = ostins.codobligpif
        where i1.codies1 = vCodDoc1;
      exception when others then vTotalPlata := 0;
      end;
      -- daca nu este stins in totalitate se iese cu 0
      if vTotalDoc &lt;&gt; vTotalPlata then return 0; end if;

      begin
        select nvl(c1.TipDiscountT, 0) into vTipDiscountT
        from contract1 c1
        where c1.codcontract1 = vCodContract1;
      exception when others then vTipDiscountT := -1;
      end;

      if vTipDiscountT = 0 then
        -- tip discount la zile plata
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by zile) loop
          begin
            select sum(stingere.valoare) into vPartial
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
                 inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) - vDataDoc between v_rec.ziledela and v_rec.zile
                  and i1.codies1 = vCodDoc1
                  AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 1) OR (t1.TipTranz = 1 AND t1.ObiectTranz = 1) or (t1.tiptranz = 1 and t1.obiecttranz = 0 and gs.tipdoc = 33))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      else if vTipDiscountT = 1 then
        -- tip discount la termen fix
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by termenfix) loop
          begin
            select sum(stingere.valoare) into vPartial
            from iesiri1 i1
                 inner join iesiri i on i1.codies = i.codies
                 inner join general g on g.coddoc = i.codies and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) between v_rec.termenfixdela and v_rec.termenfix
                  and i1.codies1 = vCodDoc1
                  AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 1) OR (t1.TipTranz = 1 AND t1.ObiectTranz = 1) or (t1.tiptranz = 1 and t1.obiecttranz = 0 and gs.tipdoc = 33))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      end if;
      end if;
    else
      select i1.codobiect, i.valdoc, i.datadoc, i1.pu*i1.cant+i1.tva, i1.cant
      into vCodObiect, vTotalDoc, vDataDoc, vTotalLinie, vCant
      from intrari1 i1
           inner join intrari i on i.codintr = i1.codintr
      where codintr1 = vCodDoc1;

      begin
        select sum(s.valoare) into vTotalPlata
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
             inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
             inner join obligpif ostins on ostins.codgeneral = g.codgeneral
             inner join stingere s on s.codstinspif = ostins.codobligpif
        where i1.codintr1 = vCodDoc1;
      exception when others then vTotalPlata := 0;
      end;

      if vTotalDoc &lt;&gt; vTotalPlata then return 0; end if;

      begin
        select nvl(c1.TipDiscountT, 0) into vTipDiscountT
        from contract1 c1
        where c1.codcontract1 = vCodContract1;
      exception when others then vTipDiscountT := -1;
      end;

      if vTipDiscountT = 0 then
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by zile) loop
          begin
            select sum(stingere.valoare) into vPartial
            from intrari1 i1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) - vDataDoc between v_rec.ziledela and v_rec.zile
                  and i1.codintr1 = vCodDoc1
                  AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 0))
                  AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      else if vTipDiscountT = 1 then
        -- tip discount la termen fix
        for v_rec in (select * from contractt_manevra where codcontract1 = vCodContract1 order by termenfix) loop
          begin
            select sum(stingere.valoare) into vPartial
            from intrari1 i1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join general g on g.coddoc = i.codintr and g.tipdoc = i.tipdoc
                 inner join obligpif ostins on ostins.codgeneral = g.codgeneral
                 inner join stingere on stingere.codstinspif = ostins.codobligpif
                 inner join obligpif ostingator on stingere.codstingatorpif = ostingator.codobligpif
                 inner join general gs on gs.codgeneral = ostingator.codgeneral
                 left join trezor1 t1 on gs.coddoc = t1.codtrezor1
                 left join trezor t on t1.codtrezor = t.codtrezor and gs.tipdoc = t.tipdoc
                 left join (select c.datadoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gs.coddoc and comp.tipdoc = gs.tipdoc
            where nvl(t1.datadoc, comp.datadoc) between v_rec.termenfixdela and v_rec.termenfix
                 and i1.codintr1 = vCodDoc1
                 AND ((gs.TipDoc IN (29, 30, 31) AND t1.TipTranz = 0) OR (t1.TipTranz = 0 AND t1.ObiectTranz = 0))
                 AND T1.Anulat &lt;&gt; 1 AND T.operat = 1;
          exception when others then vPartial := 0;
          end;

          if vPartial/vTotalDoc *100 &lt; v_rec.procvaldoc then
            if vTotalPlata - vPartial &lt;= 0 then vTotalPlata := vTotalPlata - vPartial; Exit; end if;
            vDisc := -1;
            Exit;
          else
            vTotalPlata := vTotalPlata - vPartial;
            if vTotalPlata &lt;= 0 then Exit; end if;
          end if;
        end loop;
        if vDisc = -1 then Return 0; end if;
        if vTotalPlata &lt;= 0 then
          begin
            select nvl(c1.TipDiscountT1, 0), nvl(c1.disct,0) into vTipDiscountT1, vDiscT
            from contract1 c1
            where c1.codcontract1 = vCodContract1;
          exception when others then vTipDiscountT1 := -1;
          end;
          if vTipDiscountT1 = 0 then
            vDisc :=  vTotalLinie * vDiscT / 100;
          else if vTipDiscountT1 = 1 then
            vDisc := vDiscT * vCant;
          end if;
          end if;
        end if;
      end if;
      end if;
    end if;
  end if;

  return vDisc;
end;

FUNCTION GETDISCTERMENFURN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract IN NUMBER, vCodDoc1 IN NUMBER, vPlata IN NUMBER) RETURN NUMBER IS
vDisc NUMBER(20,7);
vProc number(20,7);
vTipDiscount number(1);
vPretC number(20, 7);
vCodContract1 number(20);
vDiscTCumulat number(1);
vTipArticol number(1);
begin
  if vCodContract &gt; 0 then
    select nvl(TipArticol,0) into vTipArticol
    from contract
    where codcontract = vCodContract;

    if vTipArticol = 0 then
    select nvl(C1.TipDiscount, 0), nvl(c1.pret, 0), nvl(c1.CodContract1,0), NVL(C1.DiscTCumulat,0) into vTipDiscount, vPretC, vCodContract1, vDiscTCumulat
    from intrari1 i1
         inner join intrari i on i.codintr = i1.codintr
         inner join contract1 c1 on i1.codobiect = c1.codobiect
         inner join contract c on c.codcontract = c1.codcontract
    where i1.codintr1 = vCodDoc1 and C1.CodContract = vCodContract
          and i.datadoc between nvl(c1.datastart,c.datastart) and nvl(c1.datastop,c.datastop);
    else
    select nvl(C1.TipDiscount, 0), nvl(c1.pret, 0), nvl(c1.CodContract1,0), NVL(C1.DiscTCumulat,0) into vTipDiscount, vPretC, vCodContract1, vDiscTCumulat
    from intrari1 i1
         inner join intrari i on i.codintr = i1.codintr
         inner join nartobj obj on obj.codobiect = i1.codobiect
         inner join nart a on a.codarticol = obj.codarticol
         inner join contract1 c1 on a.clasa = c1.codclasa
         inner join contract c on c.codcontract = c1.codcontract
    where i1.codintr1 = vCodDoc1 and C1.CodContract = vCodContract
          and i.datadoc between nvl(c1.datastart,c.datastart) and nvl(c1.datastop,c.datastop);
    end if;

    if vDiscTCumulat = 0 then
      if vTipDiscount = 0 then
        select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataplata, vNrZile, vCodContract1), 0) into vProc
        from intrari1 i1
        where i1.codintr1 = vCodDoc1;
        if vProc &lt;&gt; 0 then
          begin
            select
            case when coalesce(i.valdoc,0)=0 then 0 else ---razvan
            nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1) * vPlata/i.valdoc *
            case when i.tipdoc = 9 then I1.Cant * I1.PU + i1.tva else i1.cant * i1.pu end/100, 0) end into vDisc
            from intrari1 i1
                 inner join intrari i on i1.codintr = i.codintr
            where i1.codintr1 = vCodDoc1;
          exception when others then vDisc := 0;
          end;
        else
          select case
                   when coalesce(i.valdoc,0) = 0 then 0
                   when I1.Cant * I1.PU + i1.tva = 0 then 0
                   when I1.Cant * I1.PU = 0 then 0
                   else nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                            I1.Cant * vPlata/case when i.tipdoc = 9 then I1.Cant * I1.PU + i1.tva else i1.cant * i1.pu end
                 end into vDisc
          from intrari1 i1
               inner join intrari i on i.codintr = i1.codintr
          where i1.codintr1 = vCodDoc1;
        end if;
      else
        select nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataplata, vNrZile, vCodContract1), 0) into vProc
        from intrari1 i1
        where i1.codintr1 = vCodDoc1;
        if vProc &lt;&gt; 0 then
          begin
            select
            case when coalesce(i.valdoc,0)=0 then 0 else ---razvan
            nvl(pkg_notecredit.GETPROCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1) * vPlata/i.valdoc * (I1.Cant * vPretC)/100, 0)
            end into vDisc
            from intrari1 i1
                 inner join intrari i on i1.codintr = i.codintr
            where i1.codintr1 = vCodDoc1;
          exception when others then vDisc := 0;
          end;
        else
          select case
                   when coalesce(i.valdoc,0) = 0 then 0
                   else nvl(pkg_notecredit.GETVALDISCCONTRACTTERMEN(vDataPlata, vNrZile, vCodContract1), 0) *
                        I1.Cant * vPlata/i.valdoc
                  end into vDisc
          from intrari1 i1
               inner join intrari i on i.codintr = i1.codintr
          where i1.codintr1 = vCodDoc1;
        end if;
      end if;
    else
      vDisc := pkg_notecredit.GETDISCCUMULAT(vCodDoc1, vCodContract1, 2);
    end if;
  else
    vDisc := 0;
  end if;

  Return vDisc;
end;

FUNCTION GETPROCCONTRACTTERMEN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract1 IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
vTip NUMBER(20);
begin
  begin
    select nvl(c1.TipDiscountT, 0) into vTip
    from contract1 c1
    where c1.codcontract1 = vCodContract1;
  exception when others then vTip := -1;
  end;

  if vTip = -1 then return 0; end if;

  if vTip = 0 then
    begin
      select nvl(ct.Discount, 0) into vProc
      from contractt ct
           inner join contract1 c1 on ct.codcontract1 = c1.codcontract1
      where c1.codcontract1 = vCodContract1
      and ct.zile = (select min(zile) from contractt ctt where codcontract1 = c1.codcontract1 and zile &gt;= vNrZile);
    exception when others then vProc := 0;
    end;
  else
    begin
      select nvl(ct.Discount, 0) into vProc
      from contractt ct
           inner join contract1 c1 on ct.codcontract1 = c1.codcontract1
      where c1.codcontract1 = vCodContract1
      and ct.TermenFix = (select min(termenfix)
                          from contractt
                          where codcontract1 = c1.codcontract1 and
                                to_date(vDataPlata, &apos;DD.MM.YYYY&apos;) &lt;= termenfix);
    exception when others then vProc := 0;
    end;
  end if;

  Return vProc;
end;

FUNCTION GETVALDISCCONTRACTTERMEN(vDataPlata IN VARCHAR2, vNrZile IN NUMBER, vCodContract1 IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
vTip NUMBER(20);
begin
  begin
    select nvl(c1.tipdiscountt, 0) into vTip
    from contract1 c1
    where c1.codcontract1 = vCodContract1;
  exception when others then vTip := -1;
  end;

  if vTip = -1 then return 0; end if;

  if vTip = 0 then
    begin
      select nvl(ct.ValDiscount, 0) into vProc
      from contractt ct
           inner join contract1 c1 on ct.codcontract1 = c1.codcontract1
      where c1.codcontract1 = vCodContract1
      and ct.zile = (select min(zile) from contractt ctt where ctt.codcontract1 = c1.codcontract1 and zile &gt;= vNrZile);
    exception when others then vProc := 0;
    end;
  else
    begin
      select nvl(ct.ValDiscount, 0) into vProc
      from contractt ct
           inner join contract1 c1 on ct.codcontract1 = c1.codcontract1
      where c1.codcontract1 = vCodContract1
      and ct.TermenFix = (select min(termenfix)
                          from contractt
                          where codcontract1 = c1.codcontract1 and
                                to_date(vDataPlata, &apos;DD.MM.YYYY&apos;) &lt;= termenfix);
    exception when others then vProc := 0;
    end;
  end if;

  Return vProc;
end;

FUNCTION GETPROCCONTRACTPEN(vCodContract IN NUMBER) RETURN NUMBER IS
vProc NUMBER(20,7);
begin
  begin
    select nvl(ct.PROCMAJ, 0) into vProc
    from contract ct
    where ct.codcontract = vCodContract;
  exception when others then vProc := 0;
  end;
  Return vProc;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodNCredit INTO Tmp FROM NOTECREDIT WHERE CodNCredit = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
vTipDoc number(20);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodSubunit number(20);
aDataDoc Date;
aDoc varchar2(200);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);

  select TipDoc, CarnetDoc, NrDoc, Subunitatea, to_date(to_char(DataCreare,&apos;dd.mm.yyyy&apos;),&apos;dd.mm.yyyy&apos;), PREFIXDOC||NRDOC||&apos;/&apos;||to_char(DATACREARE, &apos;dd.mm.yyyy&apos;)
  into vTipDoc, ACARNETDOC, ANRDOC, aCodSubunit, aDataDoc, aDoc
  from notecredit where CodNCredit = RecId;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NOTECREDIT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM NOTECREDIT1 WHERE CodNCredit = RecId;
  DELETE FROM NOTECREDIT  WHERE CodNCredit = RecId;
  DELETE FROM NOTECREDITFACT  WHERE CodNCredit = RecId;

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = vTipDoc) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  UPDATE CONTRACT2
  SET CODDOC  = NULL,
      TIPDOC  = NULL,
      NRDOC   = NULL,
      DATADOC = NULL
  WHERE CODDOC = RecID AND TIPDOC = vTipDoc;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = vTipDoc;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = vTipDoc;

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;

  NotifyModif(2, RECID, &apos;CONTRACT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NOTECREDIT FIELDS( CodNCredit, VolumPeArticole, Trimestriala ) VALUES (0, 0, 0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
vDataStart Date;
vDataStop Date;
vTipDoc number(20);
vCodContract number(20) := 0;
vCount NUMBER(10);
vCount1 number(10);
vCodPart number(20);
vTipDiscV number(1);
vVolumPeArticole number(1);
vPretBrutC number(1);
vPretBrutV number(1);
vTrimestriala number(1);
vLuna number(2);
vTrimestru number(1);
vAreCorectii number(10);
vPrevizionare number(1);
vIesiriPeVolum number(1);
vValOrig number(20,7);
vTotCant number(20,7);
vCurs number(20,7);
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  KArtDiscAcTer       := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  KArtDiscPrimTer     := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscPrimVol     := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscPrimCant    := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;,    PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenPrimTer      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,         PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceF := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceF&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  if RecId &gt; 0 then
  INSERT INTO TMP_NOTECREDIT (CodNCredit,
                              CodContract2,
                              CodPart,
                              TipDoc,
                              Subunitatea,
                              DataStart,
                              DataStop,
                              CODCONTV, CODCONTT, CODCONTC, CODCONTP,
                              DataStartD,
                              DataStopD,
                              DataFact,
                              Contract, An, Luna,
                              TipARticol,
                              Obs,
                              CodContract,
                              CodMoneda,
                              VolumPeArticole,
                              CODCONTZ,
                              PretBrutC,
                              PretBrutV,
                              CodCarnet,
                              TipDiscV,
                              Trimestriala,
                              Corectie,
                              COdNCCorectie,
                              PrefixDoc,
                              CarnetDoc,
                              NrDoc,
                              SeriaDoc,
                              AreCarnetDoc,
                              AreCorectii,
                              Previzionare,
                              IesiriPeVolum,
                              Curs,
                              Inchisa,
                              ValOrigTer, CODANALIZA)
                       SELECT NC.CodNCredit,
                              NC.CodContract2,
                              NC.CodPart,
                              NC.TipDoc,
                              NC.Subunitatea,
                              NC.Datastart,
                              NC.DataStop,
                              nc.CODCONTV, nc.CODCONTT, nc.CODCONTC, nc.CODCONTP,
                              NC.DataStart,
                              NC.DataStop,
                              SysDate,
                              case
                                when NVL(NC.CodContract2, nvl(NC.CodContract,0)) = 0 then &apos;...fara...&apos;
                                else case when nvl(NC.CodContract,0) = 0 then C.Nrdoc||&apos;/&apos;||to_char(C.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(C.DataStop, &apos;DD.MM.YYYY&apos;)
                                          else CNC.Nrdoc||&apos;/&apos;||to_char(CNC.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(CNC.DataStop, &apos;DD.MM.YYYY&apos;)
                                     end
                              end, NC.An, NC.Luna, NC.TipArticol,
                              NC.Obs,
                              case when nvl(nc.codcontract2, 0) = 0 then NC.CodContract else C.Codcontract end,
                              nvl(NC.CodMoneda, C.Moneda),
                              nvl(NC.VOLUMPEARTICOLE,0),
                              nc.CODCONTZ,
                              nvl(nc.pretbrutc,0),
                              nvl(nc.pretbrutv,0),
                              nc.codcarnet,
                              case
                                when decode(NVL(NC.CodContract2,0),0,nvl(NC.CodContract,0),NC.CodContract2) = 0 then
                                  case
                                    when nvl(NC.Volumpearticole,0) = 0 then 3
                                    else 4
                                  end
                                else
                                  case when nvl(NC.CodContract,0) = 0 then
                                    NVL(C.TIPTARGETV,0)
                                  else NVL(CNC.TIPTARGETV,0)
                                  end
                              end,
                              nvl(NC.Trimestriala,0),
                              NC.Corectie,
                              NC.CodNCCorectie,
                              NC.PrefixDoc,
                              NC.CarnetDoc,
                              NC.NrDoc,
                              NC.SeriaDoc,
                              Decode(Nvl(NC.CARNETDOC,0),0,0,1),
                              (select count(*) from notecredit where codnccorectie = recid),
                              NC.Previzionare,
                              NC.IesiriPeVolum,
                              NC.Curs,
                              NC.Inchisa,
                              coalesce(NC.ValOrigTer, 0),NC.CODANALIZA
                       FROM NOTECREDIT NC
                            LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
                            LEFT JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
                            LEFT JOIN CONTRACT CNC ON CNC.Codcontract = nc.codcontract
                       WHERE CodNCredit = RecId;
  --insert into x(sql) values(recid);
  --commit;
  select coalesce(VolumPeArticole,0) into vVolumPeArticole from tmp_notecredit;
  select coalesce(AreCorectii,0) into vAreCorectii from tmp_notecredit;
  select coalesce(Trimestriala,0) into vTrimestriala from tmp_notecredit;
  select coalesce(IesiriPeVolum,0) into vIesiriPeVolum from tmp_notecredit;
  select coalesce(ValOrigTer, CODANALIZA,0) into vValOrig from tmp_notecredit;
  select coalesce(curs,1) into vCurs from tmp_notecredit;
  if vCurs = 0 then vCurs := 1; end if;
  if vTrimestriala = 1 then
    select extract(month from datastop) into vLuna from tmp_notecredit;
    vTrimestru := 0;
    if vLuna in (1,2,3) then vTrimestru := 1; end if;
    if vLuna in (4,5,6) then vTrimestru := 2; end if;
    if vLuna in (7,8,9) then vTrimestru := 3; end if;
    if vLuna in (10,11,12) then vTrimestru := 4; end if;
  end if;

  select datastart into vDataStart from tmp_notecredit;
  select datastop into vDataStop from tmp_notecredit;

  select TipDoc into vTipDoc from tmp_notecredit;

  select nvl(c.codcontract, 0), nvl(nc.codpart, 0), nvl(c.tiptargetv,0) into vCodContract, vCodPart, vTipDiscV
  from notecredit nc
       left join contract c on nc.codcontract = c.codcontract
  where nc.codncredit = RecId;

  INSERT INTO TMP_NOTECREDIT1 (CodNCredit1,
                               CodNCredit,
                               TipOper,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               CODCLASEDISC,
                               CODNCREDIT1ORIG,
                               PREVIZIONAT,
                               CODDISCOUNT,
                               VALDOC,
                               VALLEI,
                               TIP,
                               PROCTVA,
                               OBSNAV,
                               CODANALIZANOD,
                               CODCENTRU)
                        SELECT CodNCredit1,
                               CodNCredit,
                               TipOper,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               CODCLASEDISC,
                               CODNCREDIT1ORIG,
                               PREVIZIONAT,
                               CODDISCOUNT,
                               VALDOC,
                               VALLEI,
                               TIP,
                               NVL(PROCTVA,24),
                               OBSNAV,
                               CODANALIZANOD,
                               CODCENTRU
                        FROM NOTECREDIT1
                        WHERE CodNCredit = RecId;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncProvizioane;

  if vCount &gt; 0 then
    INSERT INTO TMP_NOTECREDITZ (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 CODNCREDIT1ORIG,
                                 CODDISCOUNT,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC,
                                 VALLEI,
                                 DISCOUNT,
                                 DENCRITERIU,
                                 CREDITAT,
                                 DEN_CLASEDISC,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 I.CodIes,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 NC1.CODNCREDIT1ORIG,
                                 NC1.CODDISCOUNT,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(G.MONEDA,NC.CODMONEDA)) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 case
                                   when i.codies is null then nc1.valdoc
                                   else I.ValDoc - I.TVADOC
                                 end,
                                 case
                                   when i.codies is null then nc1.valdoc
                                   else ROUND((I.ValDoc - I.TVADOC) * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4)
                                 end *
                                 case
                                   when NC.Corectie = 2 and nvl(nc1.coddoc,0) = 0 then NC.Curs
                                   else 1
                                 end ValLei,
                                 0,
                                 CD.DENCRITERIU,
                                 nvl(ALTE.CREDITAT,0) + nvl(ALTELIBERE.CREDITAT,0),
                                 CLSDISC.DEN_CLASEDISC,
                                 CLSDISC.CODCLASEDISC,
                                 nvl(nc1.proctva,24),
                                 CODANALIZANOD,
                                 CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NC1.CODNCREDIT
                               LEFT JOIN IESDISC ID ON NC1.CODDOC = ID.CODIESDISC
                               LEFT JOIN DISCOUNT D ON NVL(ID.CODDISCOUNT,NC1.CODDISCOUNT) = D.CODDISCOUNT
                               LEFT JOIN CRITERIIDISC CD ON CD.CODCRITERIU = D.CODCRITERIU
                               LEFT JOIN IESIRI I ON I.CODIES = ID.CodIes AND NC1.TipDoc = I.TipDoc
                               LEFT  JOIN NCLASEDISC CLSDISC ON CLSDISC.CODCLASEDISC = CD.CLASA
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               left join (SELECT sum(N1.VALOARE) creditat, N1.CODDOC, nvl(n1.proctva,24) proctva
                                          FROM NOTECREDIT1 N1
                                               INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = N1.CODNCREDIT
                                          WHERE N1.Valoare &lt;&gt; 0 AND NC.TIPDOC = vTipDoc
                                                AND n1.TIP = tncProvizioane AND N1.CODNCREDIT &lt;&gt; RecId
                                                AND NVL(NC.CORECTIE,0) = 0
                                                and n1.coddoc &gt; 0
                                          group by n1.coddoc, nvl(n1.proctva,24)
                               ) ALTE on alte.coddoc = nc1.coddoc and alte.proctva = nvl(nc1.proctva,24)
                               left join (SELECT sum(NCC1.VALOARE) creditat, nc1.codncredit1, nvl(nc1.proctva,24) proctva
                                                 FROM NOTECREDIT1 NC1
                                                      INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NC1.CODNCREDIT
                                                      INNER JOIN NOTECREDIT1 NCC1 ON NCC1.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                                                      INNER JOIN NOTECREDIT NCC ON NCC.CODNCREDIT = NCC1.CODNCREDIT
                                          WHERE nvl(nc1.coddoc,0) = 0 and NC1.Valoare &lt;&gt; 0 AND NC.TIPDOC = vTipDoc
                                                AND NC1.TIP = 5 AND NCC1.CODNCREDIT &lt;&gt; RecId
                                                AND nvl(NCC.corectie,0) = 0
                                                AND NC.corectie = 2
                                          group by nc1.codncredit1, nvl(nc1.proctva,24)
                               ) AlteLibere on altelibere.codncredit1 = nc1.CodNCredit1Orig AND Coalesce(nc1.proctva,24) = altelibere.proctva
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncProvizioane
                                AND not coalesce(g.semnificatie,0) in (240, 500, 211, 210);

    if vTipDoc = 58 then
      for v_rec in (with IProc as (
                    SELECT DISTINCT I1.CodIes,i1.codobiect, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz ncz
                      inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                      inner join iesiri i on id.codies = i.codies
                      inner join iesiri1 I1 on i.codies = i1.codies
                      INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                      INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                      INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                    ),
                    IProcVal as ( select ProcTva, CodIes, CodObiect, sum(BazaTVA) BazaTVA, cumulat from
                                 (
                                  select distinct IProc.ProcTVA, I.CodIes, ii.codobiect,i1.indexlocal,
                                         i1.PretOrig*i1.cant*
                                         case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                         -
                                         case
                                           when not i.tipdoc in (16,21) then 0
                                           else i1.PretOrig*i1.cant*
                                                case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                                *pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                         end BazaTVA, 0 cumulat
                                  FROM (select distinct id.codies, 0 codobiect, coalesce(cd.cumulat,0) cumulat
                                        from tmp_notecreditz ncz
                                             inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                             inner join discount d on d.coddiscount = id.coddiscount
                                             inner join criteriidisc cd on cd.codcriteriu = d.codcriteriu
                                        where nvl(id.codobiect,0) = 0
                                       ) ii
                                        inner join iesiri i on ii.codies = i.codies
                                        inner join iesiri1 I1 on i.codies = i1.codies
                                        INNER JOIN IProc ON i1.codies = IProc.codies and IProc.codobiect = i1.codobiect
                                 )
                                 group by ProcTVA, CodIes, CodObiect
                                 union all
                                 select distinct IProc.ProcTVA, I.CodIes, ii.codobiect,
                                        sum(i1.PretOrig*i1.cant*
                                            case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                            -
                                            case
                                              when not i.tipdoc in (16,21) then 0
                                              else i1.PretOrig*i1.cant*
                                                   case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                                   *pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                            end) BazaTVA, ii.cumulat
                                  FROM (select distinct id.codies, id.codobiect, coalesce(cd.cumulat,0) cumulat
                                        from tmp_notecreditz ncz
                                             inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                             inner join discount d on d.coddiscount = id.coddiscount
                                             inner join criteriidisc cd on cd.codcriteriu = d.codcriteriu
                                        where nvl(id.codobiect,0) &gt; 0
                                       ) ii
                                        inner join iesiri i on ii.codies = i.codies
                                        inner join iesiri1 I1 on i.codies = i1.codies and i1.codobiect = ii.codobiect
                                        INNER JOIN IProc ON i1.codies = IProc.codies and IProc.codobiect = i1.codobiect
                                  group by IProc.ProcTVA, I.CodIes, ii.codobiect, ii.cumulat
                                )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner JOIN DISCOUNT D ON NVL(ID.CODDISCOUNT,NCz.CODDISCOUNT) = D.CODDISCOUNT
                         inner JOIN CRITERIIDISC CD ON CD.CODCRITERIU = D.CODCRITERIU
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA and nvl(id.codobiect,0) = IProcVal.CodObiect and iprocval.cumulat = coalesce(cd.cumulat,0)
                    where id.offinvoice = 2 and ncz.coddoc &gt; 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;
    else
      for v_rec in (with IProc as (
                    SELECT DISTINCT I1.CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz ncz
                      inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                      inner join iesiri i on id.codies = i.codies
                      inner join iesiri1 I1 on i.codies = i1.codies
                      INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                      INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                      INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                    ),
                    IProcVal as (
                                  select IProc.ProcTVA, I.CodIes,
                                         sum(i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) -
                                             case
                                               when not i.tipdoc in (16,21) then 0
                                               else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                             end) BazaTVA
                                  FROM tmp_notecreditz ncz
                                       inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                       inner join iesiri i on id.codies = i.codies
                                       inner join iesiri1 I1 on i.codies = i1.codies
                                       INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                  group by IProc.ProcTVA, I.CodIes
                                 )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA
                    where id.offinvoice = 3) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;
    end if;
    update tmp_notecreditz set discount = valoare where nvl(coddoc,0) = 0 and nvl(codncredit1orig,0) = 0;
    if vAreCorectii &gt; 0 then
      update tmp_notecreditz tmpz
      set
        valoare = valoare + nvl((select sum(nvl(valoare,0) - nvl(valoareold,0)) from notecredit1 where codncredit1orig = tmpz.codncredit1),0);
    end if;
  end if;

  insert into tmp_notecreditzc (codncredit, valoare, discount, dencriteriu, creditat, den_clasedisc, valoareold, proctva)
  select RecId, sum(valoare), sum(discount), dencriteriu, sum(creditat), den_clasedisc, sum(valoareold), proctva
  from tmp_notecreditz
  group by dencriteriu, den_clasedisc, proctva;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncVolum;

  if vCount &gt; 0 then
    MAKE_MANEVRA_NC(RecId);

  if vTipDoc = 58 then

  if vCodContract &gt; 0 then
    if vTipDiscV = 0 then
    INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 CODNCREDIT1ORIG,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU
                                 )
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b, ProcTVA from (
                            select I.CodIes,
                            case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end ValM,
                            case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end ValM_b,
                            PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                              inner join iesiri1 I1 on i.codies = i1.codies
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            WHERE I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              AND i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              AND nc1.codncredit = RecId
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                           ) GROUP BY CodIes, ProcTVA
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecID, vTrimestru, 0, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecID, 0, vCurs) end,
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecID, vTrimestru, 1, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecID, 1, vCurs) end,
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,v.proctva),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODIES = V.CODIES AND Coalesce(nc1.proctva,24) = v.proctva
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
       else if vTipDiscV = 1 then
         INSERT INTO TMP_NOTECREDITV
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          DENUMIRE,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          CODNCREDIT1ORIG,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b, proctva from (
                            select I.CodIes,
                                   case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end ValM,
                                   case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end ValM_b,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                              inner join iesiri1 I1 on i.codies = i1.codies
                              inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                              and nc1.codncredit = RecId
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                           ) group by codies, proctva
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecId, vTrimestru, 0, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 0, vCurs) end,
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecId, vTrimestru, 1, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 1, vCurs) end,
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODIES = V.CODIES AND Coalesce(nc1.proctva,24) = v.proctva
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
       else
         INSERT INTO TMP_NOTECREDITV
                           (CodNCredit1,
                            CodNCredit,
                            Valoare,
                            CodObligStins,
                            CodDoc,
                            TipDoc,
                            CodObligStingator,
                            Obs,
                            ValDif,
                            Valoareold,
                            DOC,
                            NRDOC,
                            DATADOC,
                            MONEDA,
                            SEDIU,
                            CURS,
                            VALDOC_N,
                            VALLEI_N,
                            DISCOUNT_N,
                            VALDOC_B,
                            VALLEI_B,
                            DISCOUNT_B,
                            CODOBIECT,
                            DENUMIRE,
                            CODDOCMASTER,
                            CODCLASEDISC,
                            CODINTERN,
                            CODNCREDIT1ORIG,
                            PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU)
                            with ValAfis as (
                              select codies1, valm, valm_b from (
                              select I1.CodIes1,
                                     case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end else I1.Cant * C1.pret end ValM,
                                     case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end else I1.Cant * C1.pret end ValM_b
                              FROM notecredit1 nc1
                                inner join IESIRI I on nc1.tipdoc = i.tipdoc
                                inner join iesiri1 I1 on i.codies = i1.codies and nc1.coddoc = i1.codies1
                                inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                                INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                                INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                                INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                              where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                and i1.codobiect &gt; 0
                                AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                                AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                                and nc1.codncredit = RecId
                                AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                             )
                             )
                            SELECT NC1.CodNCredit1,
                                   NC1.CodNCredit,
                                   NC1.Valoare,
                                   NC1.CodObligStins,
                                   NC1.CodDoc,
                                   NC1.TipDoc,
                                   NC1.CodObligStingator,
                                   NC1.Obs,
                                   NC1.ValDif,
                                   NC1.Valoareold,
                                   I.PREFIXDOC Doc,
                                   I.NRDOC NrDoc,
                                   I.DATADOC DataDoc,
                                   PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                   A.OBS Sediu,
                                   DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                   ROUND(V.ValM, 4) ValDoc,
                                   ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                   pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 0, vCurs),
                                   ROUND(V.ValM_b, 4) ValDoc_b,
                                   ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                   pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 1, vCurs),
                                   I1.CodObiect,
                                   OBJ.Denumire,
                                   I.CODIES,
                                   NC1.CODCLASEDISC,
                                   OBJ.CODINTERN,
                                   NC1.CODNCREDIT1ORIG,
                                   nvl(NC1.PROCTVA,24),
                                   NC1.CODANALIZANOD,
                                   NC1.CODCENTRU
                            FROM NOTECREDIT1 NC1
                                 INNER JOIN IESIRI I ON NC1.TipDoc = I.TipDoc
                                 INNER JOIN IESIRI1 I1 ON NC1.Coddoc = I1.CodIes1 AND I.CodIes = I1.CodIes
                                 INNER JOIN VALAFIS V ON V.CODIES1 = I1.CODIES1
                                 INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
                                 LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                                 LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                                 LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                            WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
       end if;
     end if;
     else
       if vVolumPeArticole = 0 then
           INSERT INTO TMP_NOTECREDITV
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          Denumire,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          CODNCREDIT1ORIG,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b, proctva from (
                            select I.CodIes,
                                   case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end ValM,
                                   case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end ValM_b,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                              inner join iesiri1 I1 on i.codies = i1.codies
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                           ) group by codies, proctva
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 NVL(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODIES = I.CODIES and v.proctva = nvl(nc1.proctva,24)
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
         else
           INSERT INTO TMP_NOTECREDITV
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          Denumire,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          CODINTERN,
                          CODNCREDIT1ORIG,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies1, sum(valm) valm, sum(valm_b) valm_b from (
                            select I1.CodIes1,
                            SUM(
                              case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                            ) ValM,
                            SUM(
                              case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
                            ) ValM_b
                            FROM notecredit1 nc1
                              inner join IESIRI I on nc1.tipdoc = i.tipdoc
                              inner join iesiri1 I1 on i.codies = i1.codies and nc1.coddoc = i1.codies1
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                           group by I1.CodIes1
                           ) group by codies1
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 1, vCurs),
                                 i1.codobiect,
                                 obj.denumire,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 OBJ.CODINTERN,
                                 NC1.CODNCREDIT1ORIG,
                                 NVL(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI1 I1 ON NC1.Coddoc = I1.CodIes1
                               INNER JOIN IESIRI I ON I1.CODIES = I.CODIES AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODIES1 = I1.CODIES1
                               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = I1.CODOBIECT
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
         end if;
       end if;
  else
    IF vCodContract &gt; 0 then
    if vTipDiscV = 0 then
    INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 CODNCREDIT1ORIG,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as ( select codintr, sum(valm) valm, sum(valm_b) valm_b, ProcTVA from (
                            select I.CodIntr, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM,
                                   I1.Cant*I1.PretOrig ValM_b,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                              inner join intrari1 I1 on i.codintr = i1.codintr
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                              and nc1.codncredit = RecId
                           ) group by codintr, proctva )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecId, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA, v.proctva),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODINTR = V.CODINTR AND Coalesce(nc1.proctva,24) = v.proctva
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                                and g.semnificatie &lt;&gt; 110;
    else if vTipDiscV = 1 then
      INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 CODNCREDIT1ORIG,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as ( select codintr, sum(valm) valm, sum(valm_b) valm_b, ProcTVA from (
                            select I.CodIntr, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM,
                                   I1.Cant*I1.PretOrig ValM_b,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                              inner join intrari1 I1 on i.codintr = i1.codintr
                              inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                              and nc1.codncredit = RecId
                           ) group by codintr, ProcTVA )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,V.PROCTVA),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODINTR = V.CODINTR AND Coalesce(nc1.proctva,24) = V.ProcTVA
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                          and g.semnificatie &lt;&gt; 110;
    else
      INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                   CodNCredit,
                                   Valoare,
                                   CodObligStins,
                                   CodDoc,
                                   TipDoc,
                                   CodObligStingator,
                                   Obs,
                                   ValDif,
                                   Valoareold,
                                   DOC,
                                   NRDOC,
                                   DATADOC,
                                   MONEDA,
                                   SEDIU,
                                   CURS,
                                   VALDOC_N,
                                   VALLEI_N,
                                   DISCOUNT_N,
                                   VALDOC_B,
                                   VALLEI_B,
                                   DISCOUNT_B,
                                   CODOBIECT,
                                   DENUMIRE,
                                   CODDOCMASTER,
                                   CODCLASEDISC,
                                   CODINTERN,
                                   CODNCREDIT1ORIG,
                                   PROCTVA,
                                   CODANALIZANOD,
                                   CODCENTRU)
          with ValAfis as ( select codintr1, valm, valm_b from (
            select I1.CodIntr1, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM, I1.Cant*I1.PretOrig ValM_b
            FROM notecredit1 nc1
              inner join INTRARI I on nc1.tipdoc = i.tipdoc
              inner join intrari1 I1 on i.codintr = i1.codintr and nc1.coddoc = i1.codintr1
              inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
            and i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
              and nc1.codncredit = RecId
           ) )
          SELECT NC1.CodNCredit1,
                 NC1.CodNCredit,
                 NC1.Valoare,
                 NC1.CodObligStins,
                 NC1.CodDoc,
                 NC1.TipDoc,
                 NC1.CodObligStingator,
                 NC1.Obs,
                 NC1.ValDif,
                 NC1.Valoareold,
                 I.PREFIXDOC Doc,
                 I.NRDOC NrDoc,
                 I.DATADOC DataDoc,
                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                 A.OBS Sediu,
                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                 ROUND(V.ValM, 4) ValDoc,
                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                 pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 0, vCurs),
                 ROUND(V.ValM_b, 4) ValDoc_b,
                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                 pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 1, vCurs),
                 I1.CODOBIECT,
                 OBJ.DENUMIRE,
                 I.CODINTR,
                 NC1.CODCLASEDISC,
                 OBJ.CODINTERN,
                 NC1.CODNCREDIT1ORIG,
                 NC1.PROCTVA,
                 NC1.CODANALIZANOD,
                 NC1.CODCENTRU
          FROM NOTECREDIT1 NC1
               INNER JOIN INTRARI I ON NC1.TipDoc = I.TipDoc
               INNER JOIN INTRARI1 I1 ON NC1.Coddoc = I1.CodIntr1 AND I1.CodIntr = I.CodIntr
               INNER JOIN VALAFIS V ON I1.CODINTR1 = V.CODINTR1
               INNER JOIN NARTOBJ OBJ ON OBJ.CodObiect = I1.CodObiect
               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
          and g.semnificatie &lt;&gt; 110 ;
    end if;
  end if;
  else
      if vVolumPeArticole = 0  then
        if vIesiriPeVolum = 1 then
          INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                     CodNCredit,
                                     Valoare,
                                     CodObligStins,
                                     CodDoc,
                                     TipDoc,
                                     CodObligStingator,
                                     Obs,
                                     ValDif,
                                     Valoareold,
                                     DOC,
                                     NRDOC,
                                     DATADOC,
                                     MONEDA,
                                     SEDIU,
                                     CURS,
                                     VALDOC_N,
                                     VALLEI_N,
                                     DISCOUNT_N,
                                     VALDOC_B,
                                     VALLEI_B,
                                     DISCOUNT_B,
                                     CODOBIECT,
                                     DENUMIRE,
                                     CODDOCMASTER,
                                     CODCLASEDISC,
                                     CODNCREDIT1ORIG,
                                     PROCTVA,
                                     CODANALIZANOD,
                                     CODCENTRU)
                          with ValAfis as ( select coddoc, sum(valm) valm, sum(valm_b) valm_b, tipdoc, ProcTVA from (
                            select I.CodIntr CodDoc, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM,
                                   I1.Cant*I1.PretOrig ValM_b, 2 tipdoc,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                              inner join intrari1 I1 on i.codintr = i1.codintr
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                              and nc1.codncredit = RecId
                            union all
                            select I.CodIes coddoc, case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end ValM,
                                   case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end ValM_b, 1 tipdoc,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                              inner join iesiri1 I1 on i.codies = i1.codies
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                           ) group by coddoc, tipdoc, proctva )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,v.proctva),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN VALAFIS V ON NC1.CODDOC = V.CODDOC and v.tipdoc = 2 AND Coalesce(nc1.proctva,24) = v.proctva
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                          and g.semnificatie &lt;&gt; 110
                          union all
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 NC1.PROCTVA,
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODDOC = I.CODIES AND V.TIPDOC = 1 AND Coalesce(nc1.proctva,24) = v.proctva
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
        else
        INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                     CodNCredit,
                                     Valoare,
                                     CodObligStins,
                                     CodDoc,
                                     TipDoc,
                                     CodObligStingator,
                                     Obs,
                                     ValDif,
                                     Valoareold,
                                     DOC,
                                     NRDOC,
                                     DATADOC,
                                     MONEDA,
                                     SEDIU,
                                     CURS,
                                     VALDOC_N,
                                     VALLEI_N,
                                     DISCOUNT_N,
                                     VALDOC_B,
                                     VALLEI_B,
                                     DISCOUNT_B,
                                     CODOBIECT,
                                     DENUMIRE,
                                     CODDOCMASTER,
                                     CODCLASEDISC,
                                     CODNCREDIT1ORIG,
                                     PROCTVA,
                                     CODANALIZANOD,
                                     CODCENTRU)
                          with ValAfis as ( select coddoc, sum(valm) valm, sum(valm_b) valm_b, tipdoc, proctva from (
                            select I.CodIntr CodDoc, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM,
                                   I1.Cant*I1.PretOrig ValM_b, 2 tipdoc,
                                   PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                            FROM notecredit1 nc1
                              inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                              inner join intrari1 I1 on i.codintr = i1.codintr
                              INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                              INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                              INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum
                              AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                              and nc1.codncredit = RecId
                           ) group by coddoc, tipdoc, proctva )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,v.proctva),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN VALAFIS V ON NC1.CODDOC = V.CODDOC and v.tipdoc = 2 AND Coalesce(nc1.proctva,24) = v.proctva
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                          and g.semnificatie &lt;&gt; 110 ;
        end if;
      else
        if vIesiriPeVolum = 1 then
          INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                       CodNCredit,
                                       Valoare,
                                       CodObligStins,
                                       CodDoc,
                                       TipDoc,
                                       CodObligStingator,
                                       Obs,
                                       ValDif,
                                       Valoareold,
                                       DOC,
                                       NRDOC,
                                       DATADOC,
                                       MONEDA,
                                       SEDIU,
                                       CURS,
                                       VALDOC_N,
                                       VALLEI_N,
                                       DISCOUNT_N,
                                       VALDOC_B,
                                       VALLEI_B,
                                       DISCOUNT_B,
                                       CODOBIECT,
                                       DENUMIRE,
                                       CODDOCMASTER,
                                       CODCLASEDISC,
                                       CODINTERN,
                                       CODNCREDIT1ORIG,
                                       PROCTVA,
                                       CODANALIZANOD,
                                       CODCENTRU)
                              with ValAfis as ( select coddoc1, valm, valm_b, TipDoc from (
                                select I1.CodIntr1 CodDoc1, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM, I1.Cant*I1.PretOrig ValM_b, 2 TipDoc
                                FROM notecredit1 nc1
                                  inner join INTRARI I on nc1.tipdoc = i.tipdoc
                                  inner join intrari1 I1 on i.codintr = i1.codintr and nc1.coddoc = i1.codintr1
                                  INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                                  INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                                  INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                                where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                and i1.codobiect &gt; 0
                                  AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                                  AND nc1.tip = tncVolum
                                  AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                                  and nc1.codncredit = RecId
                                union all
                                select I1.CodIes1 CodDoc1,
                                case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end ValM,
                                case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end ValM_b, 1 TipDoc
                                FROM notecredit1 nc1
                                  inner join IESIRI I on nc1.tipdoc = i.tipdoc
                                  inner join iesiri1 I1 on i.codies = i1.codies and nc1.coddoc = i1.codies1
                                  INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                                  INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                                  INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                                where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                  and i1.codobiect &gt; 0
                                  AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                                  AND nc1.tip = tncVolum
                                  and nc1.codncredit = RecId
                                  AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                                  and nc1.codncredit = RecId
                               ) )
                              SELECT NC1.CodNCredit1,
                                     NC1.CodNCredit,
                                     NC1.Valoare,
                                     NC1.CodObligStins,
                                     NC1.CodDoc,
                                     NC1.TipDoc,
                                     NC1.CodObligStingator,
                                     NC1.Obs,
                                     NC1.ValDif,
                                     NC1.Valoareold,
                                     I.PREFIXDOC Doc,
                                     I.NRDOC NrDoc,
                                     I.DATADOC DataDoc,
                                     PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                     A.OBS Sediu,
                                     DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                     ROUND(V.ValM, 4) ValDoc,
                                     ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                     pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 0, vCurs),
                                     ROUND(V.ValM_b, 4) ValDoc_b,
                                     ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                     pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 1, vCurs),
                                     I1.CODOBIECT,
                                     OBJ.DENUMIRE,
                                     I.CODINTR,
                                     NC1.CODCLASEDISC,
                                     OBJ.CODINTERN,
                                     NC1.CODNCREDIT1ORIG,
                                     nvl(NC1.PROCTVA,24),
                                     NC1.CODANALIZANOD,
                                     NC1.CODCENTRU
                              FROM NOTECREDIT1 NC1
                                   INNER JOIN INTRARI I ON NC1.TipDoc = I.TipDoc
                                   INNER JOIN INTRARI1 I1 ON NC1.Coddoc = I1.CodIntr1 AND I1.CodIntr = I.CodIntr
                                   INNER JOIN VALAFIS V ON I1.CODINTR1 = V.CODDOC1 and V.TIPDOC = 2
                                   INNER JOIN NARTOBJ OBJ ON OBJ.CodObiect = I1.CodObiect
                                   LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                                   LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                              WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                              and g.semnificatie &lt;&gt; 110
                              union all
                              SELECT
                                 NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 1, vCurs),
                                 i1.codobiect,
                                 obj.denumire,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 OBJ.CODINTERN,
                                 NC1.CODNCREDIT1ORIG,
                                 nvl(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI1 I1 ON NC1.Coddoc = I1.CodIes1
                               INNER JOIN IESIRI I ON I1.CODIES = I.CODIES AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODDOC1 = I1.CODIES1 AND V.TIPDOC = 1
                               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = I1.CODOBIECT
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum AND G.Semnificatie = 200;
        else
          INSERT INTO TMP_NOTECREDITV (CodNCredit1,
                                       CodNCredit,
                                       Valoare,
                                       CodObligStins,
                                       CodDoc,
                                       TipDoc,
                                       CodObligStingator,
                                       Obs,
                                       ValDif,
                                       Valoareold,
                                       DOC,
                                       NRDOC,
                                       DATADOC,
                                       MONEDA,
                                       SEDIU,
                                       CURS,
                                       VALDOC_N,
                                       VALLEI_N,
                                       DISCOUNT_N,
                                       VALDOC_B,
                                       VALLEI_B,
                                       DISCOUNT_B,
                                       CODOBIECT,
                                       DENUMIRE,
                                       CODDOCMASTER,
                                       CODCLASEDISC,
                                       CODINTERN,
                                       CODNCREDIT1ORIG,
                                       PROCTVA,
                                       CODANALIZANOD,
                                       CODCENTRU)
                              with ValAfis as ( select codintr1, valm, valm_b from (
                                select I1.CodIntr1, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM, I1.Cant*I1.PretOrig ValM_b
                                FROM notecredit1 nc1
                                  inner join INTRARI I on nc1.tipdoc = i.tipdoc
                                  inner join intrari1 I1 on i.codintr = i1.codintr and nc1.coddoc = i1.codintr1
                                  INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                                  INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                                  INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                                where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                and i1.codobiect &gt; 0
                                  AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                                  AND nc1.tip = tncVolum
                                  AND Coalesce(nc1.proctva,24) = PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1)
                                  and nc1.codncredit = RecId
                               ) )
                              SELECT NC1.CodNCredit1,
                                     NC1.CodNCredit,
                                     NC1.Valoare,
                                     NC1.CodObligStins,
                                     NC1.CodDoc,
                                     NC1.TipDoc,
                                     NC1.CodObligStingator,
                                     NC1.Obs,
                                     NC1.ValDif,
                                     NC1.Valoareold,
                                     I.PREFIXDOC Doc,
                                     I.NRDOC NrDoc,
                                     I.DATADOC DataDoc,
                                     PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                     A.OBS Sediu,
                                     DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                     ROUND(V.ValM, 4) ValDoc,
                                     ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                     pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 0, vCurs),
                                     ROUND(V.ValM_b, 4) ValDoc_b,
                                     ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                     pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 1, vCurs),
                                     I1.CODOBIECT,
                                     OBJ.DENUMIRE,
                                     I.CODINTR,
                                     NC1.CODCLASEDISC,
                                     OBJ.CODINTERN,
                                     NC1.CODNCREDIT1ORIG,
                                     nvl(NC1.PROCTVA,24),
                                     NC1.CODANALIZANOD,
                                     NC1.CODCENTRU
                              FROM NOTECREDIT1 NC1
                                   INNER JOIN INTRARI I ON NC1.TipDoc = I.TipDoc
                                   INNER JOIN INTRARI1 I1 ON NC1.Coddoc = I1.CodIntr1 AND I1.CodIntr = I.CodIntr
                                   INNER JOIN VALAFIS V ON I1.CODINTR1 = V.CODINTR1
                                   INNER JOIN NARTOBJ OBJ ON OBJ.CodObiect = I1.CodObiect
                                   LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                                   LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                                   LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                              WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum and g.semnificatie &lt;&gt; 500 and g.semnificatie &lt;&gt; 111 and g.semnificatie &lt;&gt; 200 and g.semnificatie &lt;&gt; 140
                              and g.semnificatie &lt;&gt; 110 ;
        end if;
      end if;
    end if;
    end if;
    if vAreCorectii &gt; 0 then
      update tmp_notecreditv tmpv
      set
        valoare = valoare + nvl((select sum(nvl(valoare,0) - nvl(valoareold,0)) from notecredit1 where codncredit1orig = tmpv.codncredit1),0);
    end if;
  end if;

  begin
    select nvl(PretBrutV,0) into vPretBrutV from tmp_notecredit;
  exception when others then vPretBrutV := 0;
  end;

  if vPretBrutV = 1 then
    update tmp_notecreditv set
    ValDoc   = ValDoc_b,
    ValLei   = ValLei_b,
    Discount = Discount_b;
  else
    update tmp_notecreditv set
    ValDoc   = ValDoc_N,
    ValLei   = ValLei_N,
    Discount = Discount_N;
  end if;
  update tmp_notecreditv set procdisc = valoare / vallei * 100;

  update tmp_notecredit set
  TotalDiscV = (select sum(valoare) from tmp_notecreditv);

  begin
    select nvl(Previzionare,0) into vPrevizionare from tmp_notecredit;
  exception when others then vPrevizionare := 0;
  end;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncTermen;

  if vCodContract &gt; 0 then
    MAKE_MANEVRA_T(vCodContract);
  end if;
  if vCount &gt; 0 then
  if vTipDoc = 58 then
    if vValOrig &gt; 0 then
      INSERT INTO TMP_NOTECREDITT
      (CODNCREDIT1,
       CODNCREDIT,
       VALOARE,
       CODOBLIGSTINS,
       CODDOC,
       TIPDOC,
       CODOBLIGSTINGATOR,
       Obs,
       ValDif,
       Valoareold,
       doc,
       Cont,
       Moneda,
       Termen,
       Subunitatea,
       Sediu,
       Curs,
       ValDoc,
       ValLei,
       ValPlata,
       DocPlata,
       ZilePlata,
       Discount,
       Articol,
       CodObiect,
       Cant,
       ValFaraTVA,
       CODCLASEDISC,
       ProcTVA,
       ValOrig,
       CODANALIZANOD,
       CODCENTRU,
       TERMENFIX )
       SELECT NC1.CodNCredit1,
              NC1.CodNCredit,
              NC1.Valoare,
              NC1.CodObligStins,
              NC1.CodDoc,
              NC1.TipDoc,
              NC1.CodObligStingator,
              NC1.Obs,
              NC1.ValDif,
              NC1.Valoareold,
              I.prefixdoc||&apos; &apos;|| I.nrdoc||&apos;/&apos;||to_char(I.datadoc, &apos;dd.mm.yyyy&apos;),
              PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie),
              PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)),
              obstins.termen,
              i.subunitatea,
              A.Obs,
              DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)),
              case when i.tipdoc = 21 then i1.pretorig*i1.cant else i1.pretorig*i1.cant+i1.tva end,
              ROUND(case when i.tipdoc = 21 then i1.pretorig*i1.cant else i1.pretorig*i1.cant+i1.tva end * DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)), 4),
              case
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then case when i.tipdoc = 21 then i1.pretorig*i1.cant else i1.pretorig*i1.cant+i1.tva end
                else sign(obstins.valoare) * stingere.valoare *
                case when coalesce(i.valdoc,0)=0 then 0 else ---razvan
                (case when i.tipdoc = 21 then i1.pretorig*i1.cant else i1.pretorig*i1.cant+i1.tva end) / i.valdoc end
              end,
              case
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then &apos;TOTAL CUMULAT&apos;
                else case
                       when gstingator.tipdoc = 28 then &apos;PV&apos;||&apos; &apos;||comp.nrdoc||&apos;/&apos;||to_char(comp.datadoc, &apos;dd.mm.yyyy&apos;)
                       else t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;)
                     end
              end,
              nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc,
              pkg_notecredit.GETDISCTERMENCLI(to_char(nvl(T1.Datadoc, COMP.datadoc), &apos;DD.MM.YYYY&apos;), nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc, C.CODCONTRACT, I1.CodIes1,
                                              case when gstingator.tipdoc = 28 and obstins.valoare &lt; 0 then - stingere.valoare else stingere.valoare end),
              OBJ.Denumire,
              I1.CodObiect,
              I1.Cant,
              case when i.tipdoc = 21 then i1.pretorig*i1.cant-i1.TVA else i1.pretorig*i1.cant end,
              NC1.CODCLASEDISC,
              nvl(NC1.PROCTVA,24),
              case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end,
              NC1.CODANALIZANOD,
              NC1.CODCENTRU,
              TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       FROM NOTECREDIT1 NC1
            INNER JOIN IESIRI1 I1 ON NC1.CodDoc = I1.CodIes1
            INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
            INNER JOIN IESIRI I ON I1.CodIes = I.CodIes AND I.TIPDOC = NC1.TIPDOC
            INNER JOIN GENERAL GSTINS ON I.CodIes = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
            INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif and gstins.codgeneral = obstins.codgeneral
            left JOIN OBLIGPIF obstingator on NC1.CODOBLIGSTINGATOR = obstingator.codobligpif
            left JOIN stingere ON stingere.codstinspif = obstins.codobligpif AND stingere.codstingatorpif = obstingator.codobligpif
            left JOIN GENERAL GSTINGATOR ON obstingator.codgeneral = GSTINGATOR.CODGENERAL
            LEFT JOIN (SELECT TT1.DOC, TT1.NRDOC, TT1.DATADOC, TT1.CODTREZOR1, TT.TIPDOC
                       FROM TREZOR1 TT1
                            INNER JOIN TREZOR TT ON  TT.CODTREZOR = TT1.CODTREZOR) T1 ON T1.CODTREZOR1 = GSTINGATOR.CODDOC AND T1.TIPDOC = GSTINGATOR.TIPDOC
            left join (select c.datadoc, c.nrdoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gstingator.coddoc and comp.tipdoc = gstingator.tipdoc
            LEFT  JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
            LEFT  JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
            LEFT  JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
            LEFT  JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
            LEFT  JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODOBIECT&apos; AND TMP.FILTRU1 = &apos;TERMENFIX&apos; AND TO_NUMBER(TMP.VALOARE) = OBJ.CODOBIECT AND case when vPrevizionare = 1 then I.DATADOC ELSE nvl(T1.Datadoc, COMP.datadoc) END BETWEEN TO_DATE(TMP.VALOARE1,&apos;DD.MM.YYYY&apos;) AND TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       WHERE gstins.semnificatie &lt;&gt; 240 and gstins.semnificatie &lt;&gt; 500
             and gstins.semnificatie &lt;&gt; 211 and gstins.semnificatie &lt;&gt; 210 and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen;
    else
      INSERT INTO TMP_NOTECREDITT
      (CODNCREDIT1,
       CODNCREDIT,
       VALOARE,
       CODOBLIGSTINS,
       CODDOC,
       TIPDOC,
       CODOBLIGSTINGATOR,
       Obs,
       ValDif,
       Valoareold,
       doc,
       Cont,
       Moneda,
       Termen,
       Subunitatea,
       Sediu,
       Curs,
       ValDoc,
       ValLei,
       ValPlata,
       DocPlata,
       ZilePlata,
       Discount,
       Articol,
       CodObiect,
       Cant,
       ValFaraTVA,
       CODCLASEDISC,
       ProcTVA,
       ValOrig,
       CODANALIZANOD,
       CODCENTRU,
       TERMENFIX )
       SELECT NC1.CodNCredit1,
              NC1.CodNCredit,
              NC1.Valoare,
              NC1.CodObligStins,
              NC1.CodDoc,
              NC1.TipDoc,
              NC1.CodObligStingator,
              NC1.Obs,
              NC1.ValDif,
              NC1.Valoareold,
              I.prefixdoc||&apos; &apos;|| I.nrdoc||&apos;/&apos;||to_char(I.datadoc, &apos;dd.mm.yyyy&apos;),
              PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie),
              PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)),
              obstins.termen,
              i.subunitatea,
              A.Obs,
              DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)),
              case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end,
              ROUND(case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end * DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)), 4),
              case
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end
                else sign(obstins.valoare) * stingere.valoare *
                (case when coalesce(i.valdoc,0)=0 then 0 else ---razvan,
                (case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end) / i.valdoc end)
              end,
              case
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then &apos;TOTAL CUMULAT&apos;
                else case
                       when gstingator.tipdoc = 28 then &apos;PV&apos;||&apos; &apos;||comp.nrdoc||&apos;/&apos;||to_char(comp.datadoc, &apos;dd.mm.yyyy&apos;)
                       else t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;)
                     end
              end,
              nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc,
              pkg_notecredit.GETDISCTERMENCLI(to_char(nvl(T1.Datadoc, COMP.datadoc), &apos;DD.MM.YYYY&apos;), nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc, C.CODCONTRACT, I1.CodIes1,
                                              case when gstingator.tipdoc = 28 and obstins.valoare &lt; 0 then - stingere.valoare else stingere.valoare end),
              OBJ.Denumire,
              I1.CodObiect,
              I1.Cant,
              case when i.tipdoc = 21 then (i1.pretorig*i1.cant)*i1.coefdiscmaj-i1.TVA else (i1.pretorig*i1.cant)*i1.coefdiscmaj end,
              NC1.CODCLASEDISC,
              nvl(NC1.PROCTVA,24),
              case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end,
              NC1.CODANALIZANOD,
              NC1.CODCENTRU,
              TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       FROM NOTECREDIT1 NC1
            INNER JOIN IESIRI1 I1 ON NC1.CodDoc = I1.CodIes1
            INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
            INNER JOIN IESIRI I ON I1.CodIes = I.CodIes AND I.TIPDOC = NC1.TIPDOC
            INNER JOIN GENERAL GSTINS ON I.CodIes = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
            INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif and gstins.codgeneral = obstins.codgeneral
            left JOIN OBLIGPIF obstingator on NC1.CODOBLIGSTINGATOR = obstingator.codobligpif
            left JOIN stingere ON stingere.codstinspif = obstins.codobligpif AND stingere.codstingatorpif = obstingator.codobligpif
            left JOIN GENERAL GSTINGATOR ON obstingator.codgeneral = GSTINGATOR.CODGENERAL
            LEFT JOIN (SELECT TT1.DOC, TT1.NRDOC, TT1.DATADOC, TT1.CODTREZOR1, TT.TIPDOC
                       FROM TREZOR1 TT1
                            INNER JOIN TREZOR TT ON  TT.CODTREZOR = TT1.CODTREZOR) T1 ON T1.CODTREZOR1 = GSTINGATOR.CODDOC AND T1.TIPDOC = GSTINGATOR.TIPDOC
            left join (select c.datadoc, c.nrdoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gstingator.coddoc and comp.tipdoc = gstingator.tipdoc
            LEFT  JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
            LEFT  JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
            LEFT  JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
            LEFT  JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
            LEFT  JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODOBIECT&apos; AND TMP.FILTRU1 = &apos;TERMENFIX&apos; AND TO_NUMBER(TMP.VALOARE) = OBJ.CODOBIECT AND case when vPrevizionare = 1 then I.DATADOC ELSE nvl(T1.Datadoc, COMP.datadoc) END BETWEEN TO_DATE(TMP.VALOARE1,&apos;DD.MM.YYYY&apos;) AND TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       WHERE gstins.semnificatie &lt;&gt; 240 and gstins.semnificatie &lt;&gt; 500
             and gstins.semnificatie &lt;&gt; 211 and gstins.semnificatie &lt;&gt; 210 and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen;
     end if;
   else
     INSERT INTO TMP_NOTECREDITT
      (CODNCREDIT1,
       CODNCREDIT,
       VALOARE,
       CODOBLIGSTINS,
       CODDOC,
       TIPDOC,
       CODOBLIGSTINGATOR,
       Obs,
       ValDif,
       Valoareold,
       doc,
       Cont,
       Moneda,
       Termen,
       Subunitatea,
       Sediu,
       Curs,
       ValDoc,
       ValLei,
       ValPlata,
       DocPlata,
       ZilePlata,
       Discount,
       Articol,
       CodObiect,
       Cant,
       ValFaraTVA,
       CODCLASEDISC,
       ProcTVA,
       CODANALIZANOD,
       CODCENTRU,
       TERMENFIX)
       SELECT NC1.CodNCredit1,
              NC1.CodNCredit,
              NC1.Valoare,
              NC1.CodObligStins,
              NC1.CodDoc,
              NC1.TipDoc,
              NC1.CodObligStingator,
              NC1.Obs,
              NC1.ValDif,
              NC1.Valoareold,
              I.prefixdoc||&apos; &apos;|| I.nrdoc||&apos;/&apos;||to_char(I.datadoc, &apos;dd.mm.yyyy&apos;),
              PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie),
              PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)),
              obstins.termen,
              i.subunitatea,
              A.Obs,
              DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)),
              i1.pu*i1.cant+i1.tva,
              ROUND((i1.pu*i1.cant+i1.tva)* DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)), 4),
              case
                when pkg_notecredit.IsCumulat(i1.codintr1, C.CODCONTRACT, 2) = 1 then i1.pu*i1.cant+i1.tva
                when coalesce(i.valdoc,0)=0 then 0 ---razvan
                else sign(obstins.valoare) * stingere.valoare * (i1.pu*i1.cant+i1.tva) / i.valdoc
              end,
              case
                when pkg_notecredit.IsCumulat(i1.codintr1, C.CODCONTRACT, 2) = 1 then &apos;TOTAL CUMULAT&apos;
                else case
                       when gstingator.tipdoc = 28 then &apos;PV&apos;||&apos; &apos;||comp.nrdoc||&apos;/&apos;||to_char(comp.datadoc, &apos;dd.mm.yyyy&apos;)
                       else t1.doc||&apos; &apos; ||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;)
                     end
              end,
              nvl(T1.Datadoc,comp.datadoc) - I.Datadoc,
              pkg_notecredit.GETDISCTERMENFURN(to_char(nvl(T1.Datadoc,comp.datadoc), &apos;DD.MM.YYYY&apos;), nvl(T1.Datadoc,comp.datadoc) - I.Datadoc, C.CODCONTRACT, I1.CodIntr1,
                                               case when gstingator.tipdoc = 28 and obstins.valoare &lt; 0 then - stingere.valoare else stingere.valoare end),
              OBJ.Denumire,
              I1.CodObiect,
              I1.Cant,
              i1.pretorig*i1.cant*i1.coefdiscmaj,
              NC1.CODCLASEDISC,
              nvl(NC1.PROCTVA,24),
              NC1.CODANALIZANOD,
              NC1.CODCENTRU,
              TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       FROM NOTECREDIT1 NC1
            INNER JOIN INTRARI1 I1 ON NC1.CodDoc = I1.CodIntr1
            INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
            INNER JOIN INTRARI I ON I1.CodIntr = I.CodIntr AND NC1.TIPDOC = I.TIPDOC
            INNER JOIN GENERAL GSTINS ON I.CodIntr = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
            INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif and gstins.codgeneral = obstins.codgeneral
            left JOIN OBLIGPIF obstingator on NC1.CODOBLIGSTINGATOR = obstingator.codobligpif
            left JOIN stingere ON stingere.codstinspif = obstins.codobligpif AND stingere.codstingatorpif = obstingator.codobligpif
            left JOIN GENERAL GSTINGATOR ON obstingator.codgeneral = GSTINGATOR.CODGENERAL
            LEFT JOIN (SELECT TT1.DOC, TT1.NRDOC, TT1.DATADOC, TT1.CODTREZOR1, TT.TIPDOC
                       FROM TREZOR1 TT1
                            INNER JOIN TREZOR TT ON  TT.CODTREZOR = TT1.CODTREZOR) T1 ON T1.CODTREZOR1 = GSTINGATOR.CODDOC AND T1.TIPDOC = GSTINGATOR.TIPDOC
            left join (select c.datadoc, c.nrdoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gstingator.coddoc and comp.tipdoc = gstingator.tipdoc
            LEFT  JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
            LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
            LEFT  JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
            LEFT  JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
            LEFT  JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODOBIECT&apos; AND TMP.FILTRU1 = &apos;TERMENFIX&apos; AND TO_NUMBER(TMP.VALOARE) = OBJ.CODOBIECT AND case when vPrevizionare = 1 then I.DATADOC ELSE nvl(T1.Datadoc, COMP.datadoc) END BETWEEN TO_DATE(TMP.VALOARE1,&apos;DD.MM.YYYY&apos;) AND TO_DATE(TMP.VALOARE2,&apos;DD.MM.YYYY&apos;)
       WHERE gstins.semnificatie &lt;&gt; 140 and gstins.semnificatie &lt;&gt; 600 and gstins.semnificatie &lt;&gt; 130
       and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen;

   end if;
   end if;

   if vCodContract &gt; 0 then
     delete from tmp_notecreditt where discount = 0;
     UPDATE TMP_NOTECREDITT T SET PREVIZIONAT = (SELECT NVL(PREVIZIONAT,0) FROM TMP_NOTECREDIT1 WHERE CODNCREDIT1 = T.CODNCREDIT1);
   end if;

  /*if vPrevizionare = 1 then
    update tmp_notecreditt set discount = previzionat, valoare = previzionat;
  end if;*/

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncCantitate;

  if vCount &gt; 0 then
   if vTipDoc = 58 then
     if vCodContract &gt; 0 then
     vTotCant := 0;
     begin
     select
       sum(i1.cant) totalcant into vTotCant
     from notecredit1 nc1
           inner join notecredit nc on nc.codncredit = nc1.codncredit
           inner join iesiri1 i1 on nc1.coddoc = i1.codies1
           inner join iesiri   i on i1.codies    = i.codies
           left join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
           left join contract c on c1.codcontract = c.codcontract
     where (NVL(i.anulat, 0) = 0)
            and nc.codcontract = vCodContract
            and nc1.tip = tncCantitate and nc1.codncredit = RecId
            and (nc.corectie = 1 or I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;))
            AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0);
     exception when others then vTotCant := 0;
     end;
     INSERT INTO TMP_NOTECREDITC (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  PROCTVA,
                                  OBSNAV,
                                  CODANALIZANOD,
                                  CODCENTRU
                                  )
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant,
                                c1.codcontract1,
                                  sum(
                                    case when i.tipdoc = 21 then (i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) - i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*
                                    pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100) else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) end
                                     )/sum(i1.cant) pretmediu,
                                  sum(
                                    case when i.tipdoc = 21 then (i1.PretOrig*i1.cant - i1.PretOrig*i1.cant*
                                    pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100) else i1.PretOrig*i1.cant end
                                     )/sum(i1.cant) pretmediu_b
                              from notecredit1 nc1
                                   inner join notecredit nc on nc.codncredit = nc1.codncredit
                                   inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                   inner join iesiri   i on i1.codies    = i.codies
                                   left join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                                   left join contract c on c1.codcontract = c.codcontract
                              where (NVL(i.anulat, 0) = 0)
                                    and nc.codcontract = vCodContract
                                    and nc1.tip = tncCantitate and nc1.codncredit = RecId
                                    and (nc.corectie = 1 or I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;))
                                    AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              group by i1.codobiect, c1.codcontract1
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  case when nvl(NC1.CodObligStins,0) = 0 then g.codgeneral else NC1.CodObligStins end,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoareold,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  0,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva)/i1.cant, 2) else i1.pretorig * i1.coefdiscmaj end pret,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant - i1.tva)/i1.cant, 2) else i1.pretorig end pret_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end Val,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end Val_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                   case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  round (pkg_notecredit.GetDiscCant(I1.cant, case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end,CumulCant.totalcant,CumulCant.codcontract1,CUmulCant.pretmediu, vTotCant, vCurs), 2),
                                  round (pkg_notecredit.GetDiscCant(I1.cant, case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end,CumulCant.totalcant,CumulCant.codcontract1,CUmulCant.pretmediu_b, vTotCant, vCurs), 2),
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva) else i1.Pretorig*i1.Cant * i1.coefdiscmaj end,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant - i1.tva) else i1.Pretorig*i1.Cant end,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NVL(NC1.PROCTVA,24),
                                  NC1.OBSNAV,
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join notecredit nc on nc.codncredit = nc1.codncredit
                                inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                inner join iesiri i on i1.codies = i.codies AND I.TIPDOC = NC1.TIPDOC
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect and (nc.corectie = 1 or CumulCant.CodContract1 = PKG_NOTECREDIT.GETCODCONTRACT1(i1.codobiect, i.datadoc, vCodContract))
                                INNER JOIN general g ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie not in (500, 240, 211, 100, 140, 400)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    else
      INSERT INTO TMP_NOTECREDITC (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  PROCTVA,
                                  OBSNAV,
                                  CODANALIZANOD,
                                  CODCENTRU)
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant
                              from notecredit1 nc1
                                   inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                   inner join iesiri   i on i1.codies  = i.codies
                                   inner join notecredit nc on nc.codncredit = nc1.codncredit
                              where (NVL(i.anulat, 0) = 0)
                                    and nc1.tip = tncCantitate and nc1.codncredit = RecId
                                    and (nc.corectie = 1 or I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;))
                                    AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              group by i1.codobiect
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  case when nvl(NC1.CodObligStins,0) = 0 then g.codgeneral else NC1.CodObligStins end,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoareold,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  NC1.Valoare/DECODE(I1.cant * I1.PU * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.PU * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) * 100,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva)/i1.cant, 2) else i1.pretorig * i1.coefdiscmaj end pret,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant - i1.tva)/i1.cant, 2) else i1.pretorig end pret_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end Val,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end Val_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                   case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  0, 0,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva) else i1.Pretorig*i1.Cant * i1.coefdiscmaj end,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant - i1.tva) else i1.Pretorig*i1.Cant end,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NVL(NC1.PROCTVA,24),
                                  NC1.OBSNAV,
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect
                                inner join iesiri i on i1.codies = i.codies AND I.TIPDOC = NC1.TIPDOC
                                INNER JOIN general g ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie not in (500, 240, 211, 100, 140, 400)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    end if;
  else
  if vCodContract &gt; 0 then
    vTotCant := 0;
    begin
    select
      sum(i1.cant) into vtotcant
    from notecredit1 nc1
         inner join intrari1 i1 on nc1.coddoc = i1.codintr1
         inner join intrari   i on i1.codintr    = i.codintr
         inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
         inner join contract c on c.codcontract = c1.codcontract
    where (NVL(i.anulat, 0) = 0)
          and c.codcontract = vCodContract
          and nc1.codncredit = RecId and nc1.tip = tncCantitate
          and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
          AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0);
    exception when others then vTotCant := 0;
    end;
    INSERT INTO TMP_NOTECREDITC (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  PROCTVA,
                                  OBSNAV,
                                  CODANALIZANOD,
                                  CODCENTRU)
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant,
                                c1.codcontract1,
                                sum(I1.cant * I1.Pretorig * I1.COEFDISCMAJ)/sum(i1.cant) pretmediu,
                                sum(I1.cant * I1.Pretorig)/sum(i1.cant) pretmediu_b
                              from notecredit1 nc1
                                   inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                   inner join intrari   i on i1.codintr    = i.codintr
                                   inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                                   inner join contract c on c.codcontract = c1.codcontract
                              where (NVL(i.anulat, 0) = 0)
                                    and c.codcontract = vCodContract
                                    and nc1.codncredit = RecId and nc1.tip = tncCantitate
                                    and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                    AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              group by i1.codobiect, c1.codcontract1
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  case when nvl(NC1.CodObligStins,0) = 0 then g.codgeneral else NC1.CodObligStins end,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoareold,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  case when vCodContract = 0 then NC1.Valoare/DECODE(I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) * 100 else 0 end,
                                  I1.PU pret,
                                  I1.PretOrig pret,
                                  I1.cant * I1.Pretorig * I1.COEFDISCMAJ Val,
                                  I1.cant * I1.Pretorig Val_b,
                                  I1.cant * I1.Pretorig * I1.COEFDISCMAJ * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                  I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  round (pkg_notecredit.GetDiscCant(I1.cant, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), CumulCant.totalcant, CumulCant.CodContract1, cumulcant.pretmediu,vTotCant,vCurs), 2),
                                  round (pkg_notecredit.GetDiscCant(I1.cant, I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), CumulCant.totalcant, CumulCant.CodContract1, cumulcant.pretmediu_b,vTotCant,vCurs), 2),
                                  I1.cant * I1.PretOrig * I1.COEFDISCMAJ,
                                  I1.cant * I1.PretOrig,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NC1.PROCTVA,
                                  NC1.OBSNAV,
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                inner join intrari i on i1.codintr = i.codintr AND I.TIPDOC = NC1.TIPDOC
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect  and CumulCant.CodContract1 = PKG_NOTECREDIT.GETCODCONTRACT1(i1.codobiect, i.datadoc, vCodContract)
                                INNER JOIN general g ON g.coddoc = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie not in (500,111,200,140,300,240)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    else
      INSERT INTO TMP_NOTECREDITC (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  PROCTVA,
                                  OBSNAV,
                                  CODANALIZANOD,
                                  CODCENTRU)
                         with CumulCant as
                          (
                            select
                              i1.codobiect,
                              sum(i1.cant) totalcant
                            from notecredit1 nc1
                                 inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                 inner join intrari   i on i1.codintr    = i.codintr
                            where (NVL(i.anulat, 0) = 0)
                                  and nc1.codncredit = RecId and nc1.tip = tncCantitate
                                  and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                  AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                            group by i1.codobiect
                          )
                         SELECT NC1.CodNCredit1,
                                NC1.CodNCredit,
                                NC1.Valoare,
                                case when nvl(NC1.CodObligStins,0) = 0 then g.codgeneral else NC1.CodObligStins end,
                                NC1.CodDoc,
                                NC1.TipDoc,
                                NC1.CodObligStingator,
                                NC1.Obs,
                                NC1.ValDif,
                                NC1.Valoareold,
                                OBJ.Denumire Articol,
                                I1.cant,
                                i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                A.obs sediu,
                                DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                i1.codobiect,
                                case when vCodContract = 0 then NC1.Valoare/DECODE(I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) * 100 else 0 end,
                                I1.PU pret,
                                I1.PretOrig pret_b,
                                I1.cant * I1.Pretorig * I1.COEFDISCMAJ Val,
                                I1.cant * I1.Pretorig Val_b,
                                I1.cant * I1.Pretorig * I1.COEFDISCMAJ * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                0, 0,
                                I1.cant * I1.PretOrig * I1.COEFDISCMAJ,
                                I1.cant * I1.PretOrig,
                                NC1.CODCLASEDISC,
                                OBJ.CODINTERN,
                                NVL(NC1.PROCTVA,24),
                                NC1.OBSNAV,
                                NC1.CODANALIZANOD,
                                NC1.CODCENTRU
                         FROM NOTECREDIT1 NC1
                              inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                              inner join CumulCant on i1.codobiect = CumulCant.codobiect
                              inner join intrari i on i1.codintr = i.codintr AND I.TIPDOC = NC1.TIPDOC
                              INNER JOIN general g ON g.coddoc = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie not in (500,111,200,140,300,240)
                              INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                              LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                              LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                         WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    end if;
  end if;
  end if;

  begin
    select nvl(PretBrutC,0) into vPretBrutC from tmp_notecredit;
  exception when others then vPretBrutC := 0;
  end;

  if vPretBrutC = 1 then
    update tmp_notecreditc set
    Pret = PRET_B,
    Val  = VAL_B,
    VALLEI = VALLEI_B,
    DISCOUNT = DISCOUNT_B,
    VALFARATVA = VALFARATVA_B;
  else
    update tmp_notecreditc set
    Pret = PRET_N,
    Val  = VAL_N,
    VALLEI = VALLEI_N,
    DISCOUNT = DISCOUNT_N,
    VALFARATVA = VALFARATVA_N;
  end if;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncPenalizari;

  if vCount &gt; 0 then
  if vTipDoc = 58 then
  INSERT INTO TMP_NOTECREDITP (CodNCredit1,
                               CodNCredit,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               DOC,
                               CONT,
                               MONEDA,
                               TERMEN,
                               SUBUNITATEA,
                               SEDIU,
                               CURS,
                               VALDOC,
                               VALLEI,
                               VALPLATA,
                               DOCPLATA,
                               ZILEPLATA,
                               DISCOUNT,
                               CODANALIZANOD,
                               CODCENTRU)
                        SELECT NC1.CodNCredit1,
                               NC1.CodNCredit,
                               NC1.Valoare,
                               NC1.CodObligStins,
                               NC1.CodDoc,
                               NC1.TipDoc,
                               NC1.CodObligStingator,
                               NC1.Obs,
                               NC1.ValDif,
                               NC1.Valoareold,
                               i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                               PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
                               PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)) MONEDA,
                               obstins.termen termen,
                               i.subunitatea subunitatea,
                               A.obs sediu,
                               DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)) CURS,
                               obstins.valoare valdoc,
                               obstins.valoare * DECODE(NVL(GREG.CURS, Gstins.CURS), 0, 1, NVL(GREG.CURS, Gstins.CURS)) vallei,
                               stingere.valoare,
                               t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;) docplata,
                               t1.datadoc - i.datadoc,
                               case when t1.datadoc &gt; obstins.termen then stingere.Valoare * pkg_notecredit.GETPROCCONTRACTPEN(vCodContract)/100 else 0 end,
                               NC1.CODANALIZANOD,
                               NC1.CODCENTRU
                        FROM NOTECREDIT1 NC1
                             left join obligpif obstins on nc1.codobligstins = obstins.codobligpif
                             left join obligpif obstingator on nc1.codobligstingator = obstingator.codobligpif
                             left join stingere on stingere.codstinspif = obstins.codobligpif
                                                    and stingere.codstingatorpif = obstingator.codobligpif
                             left join general gstins on gstins.codgeneral = obstins.codgeneral
                             left join general gstingator on gstingator.codgeneral = obstingator.codgeneral
                             left join iesiri i on gstins.coddoc = i.codies and gstins.tipdoc = i.tipdoc
                             left join trezor1 t1 on gstingator.coddoc = t1.codtrezor1
                             left join trezor t on t1.codtrezor = t.codtrezor and gstingator.tipdoc = t.tipdoc
                             left join nagenda a on i.codlocatie = a.codagenda
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
                        WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncPenalizari;
  else

  INSERT INTO TMP_NOTECREDITP (CodNCredit1,
                               CodNCredit,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               DOC,
                               CONT,
                               MONEDA,
                               TERMEN,
                               SUBUNITATEA,
                               SEDIU,
                               CURS,
                               VALDOC,
                               VALLEI,
                               VALPLATA,
                               DOCPLATA,
                               ZILEPLATA,
                               DISCOUNT,
                               CODANALIZANOD,
                               CODCENTRU)
                        SELECT NC1.CodNCredit1,
                               NC1.CodNCredit,
                               NC1.Valoare,
                               NC1.CodObligStins,
                               NC1.CodDoc,
                               NC1.TipDoc,
                               NC1.CodObligStingator,
                               NC1.Obs,
                               NC1.ValDif,
                               NC1.Valoareold,
                               i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                               PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
                               PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)) MONEDA,
                               obstins.termen termen,
                               i.subunitatea subunitatea,
                               A.obs sediu,
                               DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)) CURS,
                               obstins.valoare valdoc,
                               obstins.valoare * DECODE(NVL(GREG.CURS, Gstins.CURS), 0, 1, NVL(GREG.CURS, Gstins.CURS)) vallei,
                               stingere.valoare,
                               t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;) docplata,
                               t1.datadoc - i.datadoc,
                               case when t1.datadoc &gt; obstins.termen then stingere.Valoare * pkg_notecredit.GETPROCCONTRACTPEN(vCodContract)/100 else 0 end,
                               NC1.CODANALIZANOD,
                               NC1.CODCENTRU
                        FROM NOTECREDIT1 NC1
                             left join obligpif obstins on nc1.codobligstins = obstins.codobligpif
                             left join obligpif obstingator on nc1.codobligstingator = obstingator.codobligpif
                             left join stingere on stingere.codstinspif = obstins.codobligpif
                                                    and stingere.codstingatorpif = obstingator.codobligpif
                             left join general gstins on gstins.codgeneral = obstins.codgeneral
                             left join general gstingator on gstingator.codgeneral = obstingator.codgeneral
                             left join intrari i on gstins.coddoc = i.codintr and gstins.tipdoc = i.tipdoc
                             left join trezor1 t1 on gstingator.coddoc = t1.codtrezor1
                             left join trezor t on t1.codtrezor = t.codtrezor and gstingator.tipdoc = t.tipdoc
                             left join nagenda a on i.codlocatie = a.codagenda
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
                       WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncPenalizari;

  end if;
  end if;

  if vTipDoc = 58 then
    insert into tmp_notecreditfact (codncfact, CodNCredit, coddoc, tipdoc, prefixdoc, nrdoc, datadoc, valdoc, valt, restval, valalte,coddoc1)
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, nvl(NCF.valt, ncf.valdoc), nvl(NCF.valt, ncf.valdoc) - nvl(alte.val, 0),
           nvl(alte.val,0), ncf.coddoc1
    from Notecreditfact NCF
         inner join iesiri i on NCF.Coddoc = i.codies and ncf.tipdoc = i.tipdoc
         left join (select sum(a.valdoc) val, a.coddoc, a.tipdoc
                    from notecreditfact a
                    where a.codncredit &lt;&gt; RecId
                    group by a.coddoc, a.tipdoc) alte on alte.coddoc = ncf.coddoc and alte.tipdoc = ncf.tipdoc
    where codncredit = RecId
    union all
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, nvl(NCF.valt, ncf.valdoc), nvl(NCF.valt, ncf.valdoc) - nvl(alte.val, 0),
           nvl(alte.val,0), ncf.coddoc1
    from Notecreditfact NCF
         inner join iesiri1 i1 on ncf.coddoc1 = i1.codies1
         inner join iesiri i on i1.codies = i.codies and ncf.tipdoc = i.tipdoc
         left join (select sum(a.valdoc) val, a.coddoc, a.tipdoc
                    from notecreditfact a
                    where a.codncredit &lt;&gt; RecId
                    group by a.coddoc, a.tipdoc) alte on alte.coddoc = ncf.coddoc and alte.tipdoc = ncf.tipdoc
    where codncredit = RecId;
  else
    insert into tmp_notecreditfact (codncfact, CodNCredit, coddoc, tipdoc, prefixdoc, nrdoc, datadoc, valdoc, valt, restval, valalte,coddoc1)
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, nvl(NCF.valt, ncf.valdoc), nvl(NCF.valt, ncf.valdoc) - nvl(alte.val, 0),
           nvl(alte.val,0),ncf.coddoc1
    from Notecreditfact NCF
         left join intrari i on NCF.Coddoc = i.codintr and ncf.tipdoc = i.tipdoc
         left join iesiri ies on ncf.coddoc = ies.codies and ncf.tipdoc = ies.tipdoc
         left join (select sum(a.valdoc) val, a.coddoc, a.tipdoc
                    from notecreditfact a
                    where a.codncredit &lt;&gt; RecId
                    group by a.coddoc, a.tipdoc) alte on alte.coddoc = ncf.coddoc and alte.tipdoc = ncf.tipdoc
    where codncredit = RecId and (ies.codies &gt; 0 or i.codintr &gt; 0)
    union all
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, nvl(NCF.valt, ncf.valdoc), nvl(NCF.valt, ncf.valdoc) - nvl(alte.val, 0),
           nvl(alte.val,0),ncf.coddoc1
    from Notecreditfact NCF
         inner join iesiri1 i1 on i1.codies1 = ncf.coddoc1
         inner join iesiri ies on i1.codies = ies.codies and ncf.tipdoc = ies.tipdoc
         left join (select sum(a.valdoc) val, a.coddoc, a.tipdoc
                    from notecreditfact a
                    where a.codncredit &lt;&gt; RecId
                    group by a.coddoc, a.tipdoc) alte on alte.coddoc = ncf.coddoc and alte.tipdoc = ncf.tipdoc
    where codncredit = RecId
    union all
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, nvl(NCF.valt, ncf.valdoc), nvl(NCF.valt, ncf.valdoc) - nvl(alte.val, 0),
           nvl(alte.val,0),ncf.coddoc1
    from Notecreditfact NCF
         inner join intrari1 i1 on i1.codintr1 = ncf.coddoc1
         inner join intrari i on i1.codintr = i.codintr and ncf.tipdoc = i.tipdoc
         left join (select sum(a.valdoc) val, a.coddoc, a.tipdoc
                    from notecreditfact a
                    where a.codncredit &lt;&gt; RecId
                    group by a.coddoc, a.tipdoc) alte on alte.coddoc = ncf.coddoc and alte.tipdoc = ncf.tipdoc
    where codncredit = RecId;
  end if;

  insert into tmp_nccadouri(codnccadouri,
                            codncredit,
                            codobiect,
                            codobiectasoc,
                            codobiectasocsec,
                            cant,
                            cantfact,
                            codarticol,
                            umsec,
                            diferente,
                            denumire,
                            denumireasoc,
                            denumireasocsec,
                            den_um1,
                            tiparticol,
                            Pret,
                            Paritate,
                            CODANALIZANOD,
                            CODCENTRU)
                     select c.codnccadouri,
                            c.codncredit,
                            c.codobiect,
                            c.codobiectasoc,
                            c.codobiectasocsec,
                            c.cant,
                            c.cantfact,
                            c.codarticol,
                            c.umsec,
                            c.diferente,
                            obj.denumire,
                            objasoc.denumire,
                            objasocsec.denumire,
                            num1.den_um1,
                            art.tiparticol,
                            0,
                            num1.paritate,
                            C.CODANALIZANOD,
                            C.CODCENTRU
                     from nccadouri c
                          left join nartobj obj on c.codobiect = obj.codobiect
                          left join nart art on obj.codarticol = art.codarticol
                          left join nartobj objasoc on c.codobiectasoc = objasoc.codobiect
                          left join nartobj objasocsec on c.codobiectasocsec = objasocsec.codobiect
                          left join num1 on num1.codum1 = c.umsec where c.codncredit = RecId;

  INSERT INTO TMP_CENTRALIZARENC (
    CODCENTRALIZARE,
    CODNCREDIT,
    CODARTICOL,
    CODOBIECT,
    CODOBIECTASOC,
    CODOBIECTASOCSEC,
    UMSEC,
    DIFERENTE,
    TIPARTICOL,DENUMIRE, DENUMIREASOC, DENUMIREASOCSEC, DEN_UM1, PARITATE, FACTURAT,PROCTVA,
    CODCENTRU, CODANALIZANOD,
    OBS,CANT)
  SELECT
    C.CODCENTRALIZARE,
    C.CODNCREDIT,
    C.CODARTICOL,
    C.CODOBIECT,
    C.CODOBIECTASOC,
    C.CODOBIECTASOCSEC,
    C.UMSEC,
    C.DIFERENTE,
    NART.TIPARTICOL,O.DENUMIRE,
    case when o.codobiect &lt;&gt; nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0) then
      OS.DENUMIRE
      else case when vTipDoc = 58 then iI.prefixdoc||&apos; &apos;||iI.nrdoc||&apos;/&apos;||to_char(ii.datadoc, &apos;dd.mm.yyyy&apos;)
                                  else it.prefixdoc||&apos; &apos;||it.nrdoc||&apos;/&apos;||to_char(it.datadoc, &apos;dd.mm.yyyy&apos;)
           end
    end,
    OSS.DENUMIRE, NUM1.DEN_UM1, 0, C.FACTURAT, NVL(C.PROCTVA,TVA1.PROCENT),
    C.CODCENTRU, C.CODANALIZANOD,
    C.OBS,C.CANT
  FROM CENTRALIZARENC C
    INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = C.CODNCREDIT
    INNER JOIN NARTOBJ O ON O.CODOBIECT = C.CODOBIECT
    INNER JOIN NART ON NART.CODARTICOL = O.CODARTICOL
    INNER JOIN NART1 ART1 ON art1.codarticol = o.codarticol AND NC.AN*12+NC.LUNA BETWEEN art1.ALStart AND art1.ALStop
    INNER JOIN NTVA1 TVA1 ON tva1.codtva = art1.codtva      AND NC.AN*12+NC.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
    LEFT JOIN NARTOBJ OS ON OS.CODOBIECT = C.CODOBIECTASOC
    LEFT JOIN NARTOBJ OSS ON OSS.CODOBIECT = C.CODOBIECTASOCSEC
    LEFT JOIN NUM1 ON NUM1.CODUM1 = C.UMSEC
    LEFT JOIN IESIRI II ON II.CODIES = C.CODOBIECTASOC
    LEFT JOIN INTRARI IT ON IT.CODINTR = C.CODOBIECTASOC
  WHERE C.CODNCREDIT = RECID;

  if vTipDoc = 58 then
    for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         case
                           when art.tiparticol = 0 then i1.cant
                         else
                           case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else I1.Cant*I1.PU end
                         end  valoare
                  from tmp_notecreditfact tmp
                       inner join iesiri1 i1 on i1.codies = tmp.coddoc
                       inner join iesiri i on i.codies = i1.codies
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid) loop
      update tmp_centralizarenc
      set
        paritate = paritate + v_Rec.valoare
      where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = recid;
    end loop;
  else
    for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         case when art.tiparticol &lt;&gt; 0 then I1.Cant*I1.PU else i1.cant end valoare
                  from tmp_notecreditfact tmp
                       inner join intrari i on tmp.coddoc = i.codintr and i.tipdoc = tmp.tipdoc
                       inner join intrari1 i1 on tmp.coddoc = i1.codintr
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid
                        AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                  union all
                  select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         - case when art.tiparticol &lt;&gt; 0 then I1.Cant*I1.PU else i1.cant end valoare
                  from tmp_notecreditfact tmp
                       inner join iesiri i on tmp.coddoc = i.codies and i.tipdoc = tmp.tipdoc
                       inner join iesiri1 i1 on tmp.coddoc = i1.codies
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid
                        AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                 ) loop
      update tmp_centralizarenc
      set
        paritate = paritate + case when codobiect = KArtDiscOffInvoiceF then -v_Rec.valoare else v_rec.valoare end
      where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = recid;
    end loop;
  end if;

  update tmp_centralizarenc tmp set
  --facturat = paritate,
  den_um1  = (select den_um1 from num1 where codum1 = tmp.umsec);

  if vAreCorectii &gt; 0 then
    update tmp_centralizarenc set
    paritate = (select sum(valoare) from tmp_notecreditz)
    where codobiect in (KArtDiscOffInvoiceC, KArtDiscOffInvoiceF);

    update tmp_centralizarenc set
    paritate = (select sum(valoare) from tmp_notecreditv)
    where codobiect in (KArtDiscAcVol, KArtDiscPrimVol);

    update tmp_centralizarenc set
    diferente = paritate - facturat
    where codobiect in (KArtDiscOffInvoiceC, KArtDiscOffInvoiceF, KArtDiscAcVol, KArtDiscPrimVol);

    update tmp_centralizarenc tmp set
    corectii = (SELECT SUM(CC.DIFERENTE)
                FROM CENTRALIZARENC CC
                     INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = CC.CODNCREDIT
                WHERE NC.CORECTIE = 1
                      AND NC.CODNCCORECTIE = tmp.codncredit and
                      coalesce(CC.proctva,24) = coalesce(tmp.proctva,24) AND
                      COALESCE(CC.CODOBIECT,0) = COALESCE(TMP.CODOBIECT,0) AND
                      COALESCE(CC.CODOBIECTASOC,0) = COALESCE(TMP.CODOBIECTASOC,0) AND
                      COALESCE(CC.CODOBIECTASOCSEC,0) = COALESCE(TMP.CODOBIECTASOCSEC,0));
  end if;

  select count(*) into vCount1 from tmp_centralizarenc;
  if vCount1 = 0 then
    select count(*) into vCount from tmp_notecreditfact;
    if vCount &gt; 0 then
      -- trebuie incarcata centralizarea
      if vTipDoc = 58 then
        insert into tmp_centralizarenc (CodArticol, CodObiect, DenumireAsoc, CodObiectAsoc, Denumire,
          Facturat, UMSec, Den_UM1, TIPARTICOL, paritate, DenumireAsocSec, CodObiectAsocSec,corectii)
        select ART.CodArticol, OBJ.CodObiect, objasoc.denumire as DenumireAsoc, nvl(objasoc.codobiect, 0) as CodObiectAsoc, OBJ.Denumire,
          SUM(case when art.tiparticol = 1 then case when i.tipdoc = 21 then I1.Cant * I1.PU - i1.tva else I1.Cant * I1.PU end else I1.Cant end) Facturat,
          Num1.CODUM1 UMSec, NUM1.Den_UM1, ART.TIPARTICOL, num1.paritate, objasocsec.denumire as DenumireAsocSec, nvl(objasocsec.codobiect, 0) as CodObiectAsocSec,
          (SELECT SUM(NCC1.VALOARE - NCC1.VALOAREOLD)
           FROM NOTECREDIT NCC
                INNER JOIN NOTECREDIT1 NCC1 ON NCC.CODNCREDIT = NCC1.CODNCREDIT
           WHERE NCC.CORECTIE = 1
                 AND NCC.CODNCCORECTIE = NC.codncredit)
        FROM IESIRI I
             inner join iesiri1 I1 on i.codies = i1.codies
             inner join nartobj OBJ on i1.codobiect = obj.codobiect
             inner join nart ART on OBJ.codarticol = ART.codarticol
             inner join num1 on art.um = num1.codum and nvl(num1.secundara, 0) = 0
             inner join tmp_notecreditfact tmp on i.codies = tmp.coddoc and tmp.tipdoc = i.tipdoc
             inner join tmp_notecredit nc on tmp.codncredit = nc.codncredit
             left  join nartobj OBJASOC on i1.codobiectorig = objasoc.codobiect
             left  join contract1 c1 on i1.codobiectorig = c1.codcadou
             left  join contract c on c1.codcontract = c.codcontract and c.codcontract = vCodContract
             left  join nartobj OBJASOCSEC on c1.codobiectsec = objasocsec.codobiect
        where I.TipDoc IN (19, 21, 26) AND I.Partener = vCodPart
          AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
          AND I1.TipLinie &lt;&gt; &apos;T&apos; AND I1.TipLinie &lt;&gt; &apos;G&apos;
          AND I.Subunitatea = nc.subunitatea
        GROUP BY OBJ.CodObiect, Obj.Denumire, ART.CodArticol, NUM1.CodUM1, NUM1.Den_UM1, objasoc.denumire, objasoc.codobiect, Art.TipArticol, num1.paritate
                 ,objasocsec.denumire, objasocsec.codobiect;

      else
        insert into tmp_centralizarenc (
          CodArticol,
          CodObiect,
          DenumireAsoc,
          CodObiectAsoc,
          Denumire,
          Facturat,
          UMSec,
          Den_UM1,
          TIPARTICOL,
          paritate,
          DenumireAsocSec,
          CodObiectAsocSec,
          corectii)
        select
          ART.CodArticol,
          OBJ.CodObiect,
          objasoc.denumire,
          nvl(objasoc.codobiect, 0),
          OBJ.Denumire,
          SUM(case when coalesce(tmp.valdoc,0) = 0 then 0 else case when art.tiparticol = 1 then I1.Cant * I1.PU  else i1.Cant end * nvl(tmp.valt,tmp.valdoc)/tmp.valdoc end),
          Num1.CODUM1,
          NUM1.Den_UM1,
          Art.TipArticol,
          num1.paritate,
          objasocsec.denumire,
          nvl(objasocsec.codobiect, 0),
          (SELECT SUM(NCC1.VALOARE - NCC1.VALOAREOLD)
           FROM NOTECREDIT NCC
                INNER JOIN NOTECREDIT1 NCC1 ON NCC.CODNCREDIT = NCC1.CODNCREDIT
           WHERE NCC.CORECTIE = 1
                 AND NCC.CODNCCORECTIE = TMP.codncredit)
         FROM INTRARI I
             inner join INTRARI1 I1 on i.codintr = i1.codintr
             inner join nartobj OBJ on i1.codobiect = obj.codobiect
             inner join nart ART on OBJ.codarticol = ART.codarticol
             inner join num1 on art.um = num1.codum and nvl(num1.secundara, 0) = 0
             inner join tmp_notecreditfact tmp on i.codintr = tmp.coddoc and tmp.tipdoc = i.tipdoc
             left  join nartobj OBJASOC on i1.codobiectorig = objasoc.codobiect
             left  join contract1 c1 on i1.codobiectorig = c1.codcadou
             left  join contract c on c1.codcontract = c.codcontract and c.codcontract = vCodContract
             left  join nartobj OBJASOCSEC on c1.codobiectsec = objasocsec.codobiect
         where I.TipDoc IN (1, 3, 4, 5, 9) AND I.Partener = vCodPart
         AND (I1.CodObiect IN (
                               KArtDiscPrimVol,
                               KArtDiscPrimCant,
                               KArtPenPrimTer,
                               KArtDiscOffInvoiceF) or INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) &gt; 0)
         AND I1.TipLinie &lt;&gt; &apos;T&apos; AND I1.TipLinie &lt;&gt; &apos;G&apos;
         AND I.Subunitatea = PKG_GLOBALS.GETSUBUNITATE
         GROUP BY OBJ.CodObiect, Obj.Denumire, ART.CodArticol, NUM1.CodUM1, NUM1.Den_UM1, objasoc.denumire, objasoc.codobiect, Art.TipArticol, num1.paritate,
                 objasocsec.denumire, objasocsec.codobiect;

      end if;
    end if;
  end if;

  update tmp_centralizarenc set
  PROCTVA = 24
  WHERE PROCTVA IS NULL;

  update tmp_notecredit set
    TOTALT     = (select Round(sum(valdoc),2) from tmp_notecreditt),
    TOTALLEIT  = (select Round(sum(vallei),2) from tmp_notecreditt),
    TOTALV     = (select Round(sum(valdoc),2) from tmp_notecreditv),
    TOTALLEIV  = (select Round(sum(vallei),2) from tmp_notecreditv),
    TOTALC     = (select Round(sum(val),2) from tmp_notecreditc),
    TOTALLEIC  = (select Round(sum(vallei),2) from tmp_notecreditc),
    TOTALP     = (select Round(sum(valdoc),2) from tmp_notecreditp),
    TOTALLEIP  = (select Round(sum(vallei),2) from tmp_notecreditp),
    TOTALZ     = (select Round(sum(valdoc),2) from (select distinct codobligstins, valdoc from tmp_notecreditz where codobligstins &gt; 0)),
    TOTALLEIZ  = (select Round(sum(vallei),2) from (select distinct codobligstins, vallei from tmp_notecreditz where codobligstins &gt; 0)),
    TOTALDISCZ = (select Round(sum(valoare - nvl(valoareold,0)),2) from tmp_notecreditz),
    TOTALFACT  = (select sum(FACTURAT) from Tmp_Centralizarenc),
    TOTALDIF   = (select sum(DIFERENTE) from Tmp_Centralizarenc);

  update tmp_notecredit set
    TOTALZ     = TOTALZ + (select nvl(Round(sum(valdoc),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0),
    TOTALLEIZ  = TOTALLEIZ + (select nvl(Round(sum(vallei),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0);

  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = vTipDoc AND CODDOC = RECID);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = vTipDoc AND CODDOC = RECID);
  DELETE TMP_RULAJ;

  COMMIT;
  end if;
END;

PROCEDURE SP_GOTORECORD_SEC(RecId IN NUMBER) IS
vDataStart Date;
vDataStop Date;
vTipDoc number(20);
vCodContract number(20) := 0;
vCount NUMBER(10);
vCount1 number(10);
vCodPart number(20);
vTipDiscV number(1);
vVolumPeArticole number(1);
vPretBrutC number(1);
vPretBrutV number(1);
vTrimestriala number(1);
vLuna number(2);
vTrimestru number(1);
vCurs number(20,7);
BEGIN
  delete tmp_notecredit_man;
  delete tmp_notecreditc_man;
  delete tmp_notecreditv_man;
  delete tmp_notecreditt_man;
  delete tmp_notecreditz_man;
  delete tmp_notecreditzc_man;
  delete tmp_notecreditp_man;
  delete tmp_notecreditfact_man;
  delete tmp_centralizarenc_man;

  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  KArtDiscAcTer       := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscAcVol       := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,       PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscAcCant      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenAcTer        := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,           PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceC := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceC&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  KArtDiscPrimTer     := PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimTer&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU);
  KArtDiscPrimVol     := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimVol&apos;,     PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscPrimCant    := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscPrimCant&apos;,    PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtPenPrimTer      := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenPrim&apos;,         PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  KArtDiscOffInvoiceF := nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscOffInvoiceF&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);

  if RecId &gt; 0 then
  INSERT INTO TMP_NOTECREDIT_MAN (CodNCredit,
                              CodContract2,
                              CodPart,
                              TipDoc,
                              Subunitatea,
                              DataStart,
                              DataStop,
                              CODCONTV, CODCONTT, CODCONTC, CODCONTP,
                              DataStartD,
                              DataStopD,
                              DataFact,
                              Contract, An, Luna,
                              TipARticol,
                              Obs,
                              CodContract,
                              CodMoneda,
                              VolumPeArticole,
                              CODCONTZ,
                              PretBrutC,
                              PretBrutV,
                              CodCarnet,
                              TipDiscV,
                              Trimestriala,
                              Corectie,
                              COdNCCorectie,
                              PrefixDoc,
                              CarnetDoc,
                              NrDoc,
                              SeriaDoc,
                              AreCarnetDoc
                              )
                       SELECT NC.CodNCredit,
                              NC.CodContract2,
                              NC.CodPart,
                              NC.TipDoc,
                              NC.Subunitatea,
                              NC.Datastart,
                              NC.DataStop,
                              nc.CODCONTV, nc.CODCONTT, nc.CODCONTC, nc.CODCONTP,
                              NC.DataStart,
                              NC.DataStop,
                              SysDate,
                              case
                                when NVL(NC.CodContract2, nvl(NC.CodContract,0)) = 0 then &apos;...fara...&apos;
                                else case when nvl(NC.CodContract,0) = 0 then C.Nrdoc||&apos;/&apos;||to_char(C.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(C.DataStop, &apos;DD.MM.YYYY&apos;)
                                          else CNC.Nrdoc||&apos;/&apos;||to_char(CNC.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(CNC.DataStop, &apos;DD.MM.YYYY&apos;)
                                     end
                              end, NC.An, NC.Luna, NC.TipArticol,
                              NC.Obs,
                              case when nvl(nc.codcontract2, 0) = 0 then NC.CodContract else C.Codcontract end,
                              nvl(NC.CodMoneda, C.Moneda),
                              nvl(NC.VOLUMPEARTICOLE,0),
                              nc.CODCONTZ,
                              nvl(nc.pretbrutc,0),
                              nvl(nc.pretbrutv,0),
                              nc.codcarnet,
                              case
                                when decode(NVL(NC.CodContract2,0),0,nvl(NC.CodContract,0),NC.CodContract2) = 0 then
                                  case
                                    when nvl(NC.Volumpearticole,0) = 0 then 3
                                    else 4
                                  end
                                else
                                  case when nvl(NC.CodContract,0) = 0 then
                                    NVL(C.TIPTARGETV,0)
                                  else NVL(CNC.TIPTARGETV,0)
                                  end
                              end,
                              nvl(NC.Trimestriala,0),
                              NC.Corectie,
                              NC.CodNCCorectie,
                              NC.PrefixDoc,
                              NC.CarnetDoc,
                              NC.NrDoc,
                              NC.SeriaDoc,
                              Decode(Nvl(NC.CARNETDOC,0),0,0,1)
                       FROM NOTECREDIT NC
                            LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
                            LEFT JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
                            LEFT JOIN CONTRACT CNC ON CNC.Codcontract = nc.codcontract
                       WHERE CodNCredit = RecId;
  --insert into x(sql) values(recid);
  --commit;
  select nvl(VolumPeArticole,0) into vVolumPeArticole from tmp_notecredit_man;
  select nvl(Trimestriala,0) into vTrimestriala from tmp_notecredit_man;
  select coalesce(curs,0) into vCurs from notecredit where codncredit = recid;
  if vCurs = 0 then vCurs := 1; end if;
  if vTrimestriala = 1 then
    select extract(month from datastop) into vLuna from tmp_notecredit_man;
    vTrimestru := 0;
    if vLuna in (1,2,3) then vTrimestru := 1; end if;
    if vLuna in (4,5,6) then vTrimestru := 2; end if;
    if vLuna in (7,8,9) then vTrimestru := 3; end if;
    if vLuna in (10,11,12) then vTrimestru := 4; end if;
  end if;

  select datastart into vDataStart from tmp_notecredit_man;
  select datastop into vDataStop from tmp_notecredit_man;

  select TipDoc into vTipDoc from tmp_notecredit_man;

  select nvl(c.codcontract, 0), nvl(nc.codpart, 0), nvl(c.tiptargetv,0) into vCodContract, vCodPart, vTipDiscV
  from notecredit nc
       left join contract c on nc.codcontract = c.codcontract
  where nc.codncredit = RecId;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncProvizioane;

  if vCount &gt; 0 then
    INSERT INTO TMP_NOTECREDITZ_MAN (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 CODNCREDIT1ORIG,
                                 CODDISCOUNT,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC,
                                 VALLEI,
                                 DISCOUNT,
                                 DENCRITERIU,
                                 CREDITAT,
                                 DEN_CLASEDISC,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 I.CodIes,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 NC1.CODNCREDIT1ORIG,
                                 NC1.CODDISCOUNT,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(G.MONEDA,NC.CODMONEDA)) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 case
                                   when i.codies is null then nc1.valdoc
                                   else I.ValDoc - I.TVADOC
                                 end,
                                 case
                                   when i.codies is null then nc1.valdoc
                                   else ROUND((I.ValDoc - I.TVADOC) * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4)
                                 end *
                                 case
                                   when NC.Corectie = 2 and nvl(nc1.coddoc,0) = 0 then NC.Curs
                                   else 1
                                 end ValLei,
                                 0,
                                 CD.DENCRITERIU,
                                 nvl(ALTE.CREDITAT,0) + nvl(ALTELIBERE.CREDITAT,0),
                                 CLSDISC.DEN_CLASEDISC,
                                 CLSDISC.CODCLASEDISC,
                                 nvl(nc1.proctva,24),
                                 CODANALIZANOD,
                                 CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NC1.CODNCREDIT
                               LEFT JOIN IESDISC ID ON NC1.CODDOC = ID.CODIESDISC
                               LEFT JOIN DISCOUNT D ON NVL(ID.CODDISCOUNT,NC1.CODDISCOUNT) = D.CODDISCOUNT
                               LEFT JOIN CRITERIIDISC CD ON CD.CODCRITERIU = D.CODCRITERIU
                               LEFT JOIN IESIRI I ON I.CODIES = ID.CodIes AND NC1.TipDoc = I.TipDoc
                               LEFT  JOIN NCLASEDISC CLSDISC ON CLSDISC.CODCLASEDISC = CD.CLASA
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               left join (SELECT sum(N1.VALOARE) creditat, N1.CODDOC, nvl(n1.proctva,24) proctva
                                          FROM NOTECREDIT1 N1
                                               INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = N1.CODNCREDIT
                                          WHERE N1.Valoare &lt;&gt; 0 AND NC.TIPDOC = vTipDoc
                                                AND n1.TIP = tncProvizioane AND N1.CODNCREDIT &lt;&gt; RecId
                                                AND NVL(NC.CORECTIE,0) = 0
                                                and n1.coddoc &gt; 0
                                          group by n1.coddoc, nvl(n1.proctva,24)
                               ) ALTE on alte.coddoc = nc1.coddoc and alte.proctva = nvl(nc1.proctva,24)
                               left join (SELECT sum(NCC1.VALOARE) creditat, nc1.codncredit1, nvl(nc1.proctva,24) proctva
                                                 FROM NOTECREDIT1 NC1
                                                      INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NC1.CODNCREDIT
                                                      INNER JOIN NOTECREDIT1 NCC1 ON NCC1.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                                                      INNER JOIN NOTECREDIT NCC ON NCC.CODNCREDIT = NCC1.CODNCREDIT
                                          WHERE nvl(nc1.coddoc,0) = 0 and NC1.Valoare &lt;&gt; 0 AND NC.TIPDOC = vTipDoc
                                                AND NC1.TIP = 5 AND NCC1.CODNCREDIT &lt;&gt; RecId
                                                AND nvl(NCC.corectie,0) = 0
                                                AND NC.corectie = 2
                                          group by nc1.codncredit1, nvl(nc1.proctva,24)
                               ) AlteLibere on altelibere.codncredit1 = nc1.CodNCredit1Orig AND Coalesce(nc1.proctva,24) = altelibere.proctva
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncProvizioane
                                AND not nvl(g.semnificatie,0) in (240, 500, 211, 210);

    if vTipDoc = 58 then
      for v_rec in (with IProc as (
                    select distinct I1.CodIes,i1.codobiect, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz_man ncz
                      inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                      inner join iesiri i on id.codies = i.codies
                      inner join iesiri1 I1 on i.codies = i1.codies
                      INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                      INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                      INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                    ),
                    IProcVal as ( select ProcTva, CodIes, CodObiect, sum(BazaTVA) BazaTVA, cumulat from
                                 (
                                  select distinct IProc.ProcTVA, I.CodIes, ii.codobiect,i1.indexlocal,
                                         i1.PretOrig*i1.cant*
                                         case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                         -
                                         case
                                           when not i.tipdoc in (16,21) then 0
                                           else i1.PretOrig*i1.cant*
                                                case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                                *pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                         end BazaTVA, 0 cumulat
                                  FROM (select distinct id.codies, 0 codobiect, coalesce(cd.cumulat,0) cumulat
                                        from tmp_notecreditz ncz
                                             inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                             inner join discount d on d.coddiscount = id.coddiscount
                                             inner join criteriidisc cd on cd.codcriteriu = d.codcriteriu
                                        where nvl(id.codobiect,0) = 0
                                       ) ii
                                        inner join iesiri i on ii.codies = i.codies
                                        inner join iesiri1 I1 on i.codies = i1.codies
                                        INNER JOIN IProc ON i1.codies = IProc.codies and IProc.codobiect = i1.codobiect
                                 )
                                 group by ProcTVA, CodIes, CodObiect
                                 union all
                                 select distinct IProc.ProcTVA, I.CodIes, ii.codobiect,
                                        sum(i1.PretOrig*i1.cant*
                                            case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                            -
                                            case
                                              when not i.tipdoc in (16,21) then 0
                                              else i1.PretOrig*i1.cant*
                                                   case when ii.cumulat = 1 then 1 else nvl(i1.coefdiscmaj,1) end
                                                   *pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                            end) BazaTVA, ii.cumulat
                                  FROM (select distinct id.codies, id.codobiect, coalesce(cd.cumulat,0) cumulat
                                        from tmp_notecreditz ncz
                                             inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                             inner join discount d on d.coddiscount = id.coddiscount
                                             inner join criteriidisc cd on cd.codcriteriu = d.codcriteriu
                                        where nvl(id.codobiect,0) &gt; 0
                                       ) ii
                                        inner join iesiri i on ii.codies = i.codies
                                        inner join iesiri1 I1 on i.codies = i1.codies and i1.codobiect = ii.codobiect
                                        INNER JOIN IProc ON i1.codies = IProc.codies and IProc.codobiect = i1.codobiect
                                  group by IProc.ProcTVA, I.CodIes, ii.codobiect, ii.cumulat
                                )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz_man ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner JOIN DISCOUNT D ON NVL(ID.CODDISCOUNT,NCz.CODDISCOUNT) = D.CODDISCOUNT
                         inner JOIN CRITERIIDISC CD ON CD.CODCRITERIU = D.CODCRITERIU
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA and nvl(id.codobiect,0) = IProcVal.CodObiect and iprocval.cumulat = coalesce(cd.cumulat,0)
                    where id.offinvoice = 2 and ncz.coddoc &gt; 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz_man ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;
    else
      for v_rec in (with IProc as (
                    select distinct I1.CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz_man ncz
                      inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                      inner join iesiri i on id.codies = i.codies
                      inner join iesiri1 I1 on i.codies = i1.codies
                      INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                      INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol AND I.AN*12+I.LUNA BETWEEN art1.ALStart AND art1.ALStop
                      INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva        AND I.AN*12+I.LUNA BETWEEN tva1.ALStart AND tva1.ALStop
                    ),
                    IProcVal as (
                                  select IProc.ProcTVA, I.CodIes,
                                         sum(i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) -
                                             case
                                               when not i.tipdoc in (16,21) then 0
                                               else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                             end) BazaTVA
                                  FROM tmp_notecreditz ncz
                                       inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                       inner join iesiri i on id.codies = i.codies
                                       inner join iesiri1 I1 on i.codies = i1.codies
                                       INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                  group by IProc.ProcTVA, I.CodIes
                                 )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz_man ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA
                    where id.offinvoice = 3) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz_man ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz_man set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;
    end if;
    update tmp_notecreditz_man set discount = valoare where nvl(coddoc,0) = 0 and nvl(codncredit1orig,0) = 0;
    update tmp_notecreditz_man tmpz
    set
      valoare = valoare + nvl((select sum(nvl(valoare,0) - nvl(valoareold,0)) from notecredit1 where codncredit1orig = tmpz.codncredit1),0);
  end if;

  insert into tmp_notecreditzc_man (codncredit, valoare, discount, dencriteriu, creditat,den_clasedisc)
  select RecId, sum(valoare), sum(discount), dencriteriu, sum(creditat), den_clasedisc
  from tmp_notecreditz_man
  group by dencriteriu,den_clasedisc;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncVolum;

  if vCount &gt; 0 then
    MAKE_MANEVRA_NC(RecId, False);

  if vTipDoc = 58 then

  if vCodContract &gt; 0 then
    if vTipDiscV = 0 then
    INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIes,
                            SUM(case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end) ValM,
                            SUM(case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end) ValM_b
                            FROM notecredit1 nc1
                                 inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                                 inner join iesiri1 I1 on i.codies = i1.codies
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                           group by I.CodIes
                           ) group by codies
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecID, vTrimestru, 0, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecID, 0, vCurs) end,
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecID, vTrimestru, 1, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecID, 1, vCurs) end,
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODIES = V.CODIES
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
       else if vTipDiscV = 1 then
         INSERT INTO TMP_NOTECREDITV_MAN
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          DENUMIRE,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIes, SUM(case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end) ValM,
                                   SUM(case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end) ValM_b
                            FROM notecredit1 nc1
                                 inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                                 inner join iesiri1 I1 on i.codies = i1.codies
                                 inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                              and nc1.codncredit = RecId
                           group by I.CodIes
                           ) group by codies
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecId, vTrimestru, 0, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 0, vCurs) end,
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 case when vTrimestriala = 1 then pkg_notecredit.GetDiscVolumTrim(I.CodIes, vCodContract, 1, RecId, vTrimestru, 1, vCurs) else pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 1, vCurs) end,
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODIES = V.CODIES
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
       else
         INSERT INTO TMP_NOTECREDITV_MAN
                           (CodNCredit1,
                            CodNCredit,
                            Valoare,
                            CodObligStins,
                            CodDoc,
                            TipDoc,
                            CodObligStingator,
                            Obs,
                            ValDif,
                            Valoareold,
                            DOC,
                            NRDOC,
                            DATADOC,
                            MONEDA,
                            SEDIU,
                            CURS,
                            VALDOC_N,
                            VALLEI_N,
                            DISCOUNT_N,
                            VALDOC_B,
                            VALLEI_B,
                            DISCOUNT_B,
                            CODOBIECT,
                            DENUMIRE,
                            CODDOCMASTER,
                            CODCLASEDISC,
                            CODINTERN,
                            PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU)
                            with ValAfis as (
                              select codies1, valm, valm_b from (
                              select I1.CodIes1, case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end else I1.Cant * C1.pret end ValM,
                                     case when nvl(c1.tipdiscount,0) = 0 then case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end else I1.Cant * C1.pret end ValM_b
                              FROM notecredit1 nc1
                                   inner join IESIRI I on nc1.tipdoc = i.tipdoc
                                   inner join iesiri1 I1 on i.codies = i1.codies and nc1.coddoc = i1.codies1
                                   inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                              where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                                and i1.codobiect &gt; 0
                                AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                                AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                                and nc1.codncredit = RecId
                             )
                             )
                            SELECT NC1.CodNCredit1,
                                   NC1.CodNCredit,
                                   NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                   NC1.CodObligStins,
                                   NC1.CodDoc,
                                   NC1.TipDoc,
                                   NC1.CodObligStingator,
                                   NC1.Obs,
                                   NC1.ValDif,
                                   NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                   I.PREFIXDOC Doc,
                                   I.NRDOC NrDoc,
                                   I.DATADOC DataDoc,
                                   PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                   A.OBS Sediu,
                                   DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                   ROUND(V.ValM, 4) ValDoc,
                                   ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                   pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 0, vCurs),
                                   ROUND(V.ValM_b, 4) ValDoc_b,
                                   ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                   pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 1, vCurs),
                                   I1.CodObiect,
                                   OBJ.Denumire,
                                   I.CODIES,
                                   NC1.CODCLASEDISC,
                                   OBJ.CODINTERN,
                                   COALESCE(NC1.PROCTVA,24),
                                   NC1.CODANALIZANOD,
                                   NC1.CODCENTRU
                            FROM NOTECREDIT1 NC1
                                 INNER JOIN IESIRI I ON NC1.TipDoc = I.TipDoc
                                 INNER JOIN IESIRI1 I1 ON NC1.Coddoc = I1.CodIes1 AND I.CodIes = I1.CodIes
                                 INNER JOIN VALAFIS V ON V.CODIES1 = I1.CODIES1
                                 INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
                                 LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                                 LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                                 LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                                 LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                            WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
       end if;
     end if;
     else
       if vVolumPeArticole = 0 then
           INSERT INTO TMP_NOTECREDITV_MAN
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          Denumire,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIes, SUM(case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end) ValM,
                                   SUM(case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end) ValM_b
                            FROM notecredit1 nc1
                                 inner join IESIRI I on nc1.coddoc = i.codies and nc1.tipdoc = i.tipdoc
                                 inner join iesiri1 I1 on i.codies = i1.codies
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                           group by I.CodIes
                           ) group by codies
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIes, vCodContract, 1, RecId, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI I ON NC1.Coddoc = I.CodIes AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODIES = I.CODIES
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
         else
           INSERT INTO TMP_NOTECREDITV_MAN
                         (CodNCredit1,
                          CodNCredit,
                          Valoare,
                          CodObligStins,
                          CodDoc,
                          TipDoc,
                          CodObligStingator,
                          Obs,
                          ValDif,
                          Valoareold,
                          DOC,
                          NRDOC,
                          DATADOC,
                          MONEDA,
                          SEDIU,
                          CURS,
                          VALDOC_N,
                          VALLEI_N,
                          DISCOUNT_N,
                          VALDOC_B,
                          VALLEI_B,
                          DISCOUNT_B,
                          CODOBIECT,
                          Denumire,
                          CODDOCMASTER,
                          CODCLASEDISC,
                          CODINTERN,
                          PROCTVA,
                          CODANALIZANOD,
                          CODCENTRU)
                          with ValAfis as (
                            select codies1, sum(valm) valm, sum(valm_b) valm_b from (
                            select I1.CodIes1,
                            SUM(
                              case when i.tipdoc = 21 then (I1.Cant*i1.pretorig - I1.TVA) * nvl(I1.CoefDiscMaj,1) else i1.cant * i1.pretorig * nvl(I1.CoefDiscMaj,1) end
                            ) ValM,
                            SUM(
                              case when i.tipdoc = 21 then I1.Cant*i1.pretorig - I1.TVA else i1.cant * i1.pretorig end
                            ) ValM_b
                            FROM notecredit1 nc1
                                 inner join IESIRI I on nc1.tipdoc = i.tipdoc
                                 inner join iesiri1 I1 on i.codies = i1.codies and nc1.coddoc = i1.codies1
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                              AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                           group by I1.CodIes1
                           ) group by codies1
                           )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I1.CodIes1, vCodContract, 1, RecId, 1, vCurs),
                                 i1.codobiect,
                                 obj.denumire,
                                 I.CODIES,
                                 NC1.CODCLASEDISC,
                                 OBJ.CODINTERN,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN IESIRI1 I1 ON NC1.Coddoc = I1.CodIes1
                               INNER JOIN IESIRI I ON I1.CODIES = I.CODIES AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON V.CODIES1 = I1.CODIES1
                               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = I1.CODOBIECT
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
         end if;
       end if;
  else
    IF vCodContract &gt; 0 then
    if vTipDiscV = 0 then
    INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as ( select codintr, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIntr, SUM(I1.Cant*I1.PretOrig*I1.Coefdiscmaj) ValM,
                                   SUM(I1.Cant*I1.PretOrig) ValM_b
                            FROM notecredit1 nc1
                                 inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                                 inner join intrari1 I1 on i.codintr = i1.codintr
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                           group by I.CodIntr
                           ) group by codintr )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecId, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecId, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODINTR = V.CODINTR
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
    else if vTipDiscV = 1 then
      INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as ( select codintr, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIntr, SUM(I1.Cant*I1.PretOrig*I1.Coefdiscmaj) ValM,
                                   SUM(I1.Cant*I1.PretOrig) ValM_b
                            FROM notecredit1 nc1
                                 inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                                 inner join intrari1 I1 on i.codintr = i1.codintr
                                 inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
                              and nc1.codncredit = RecId
                           group by I.CodIntr
                           ) group by codintr )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODINTR = V.CODINTR
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
    else
      INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                   CodNCredit,
                                   Valoare,
                                   CodObligStins,
                                   CodDoc,
                                   TipDoc,
                                   CodObligStingator,
                                   Obs,
                                   ValDif,
                                   Valoareold,
                                   DOC,
                                   NRDOC,
                                   DATADOC,
                                   MONEDA,
                                   SEDIU,
                                   CURS,
                                   VALDOC_N,
                                   VALLEI_N,
                                   DISCOUNT_N,
                                   VALDOC_B,
                                   VALLEI_B,
                                   DISCOUNT_B,
                                   CODOBIECT,
                                   DENUMIRE,
                                   CODDOCMASTER,
                                   CODCLASEDISC,
                                   CODINTERN,
                                   PROCTVA,
                                   CODANALIZANOD,
                                   CODCENTRU)
          with ValAfis as ( select codintr1, valm, valm_b from (
            select I1.CodIntr1, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM, I1.Cant*I1.PretOrig ValM_b
            FROM notecredit1 nc1
                 inner join INTRARI I on nc1.tipdoc = i.tipdoc
                 inner join intrari1 I1 on i.codintr = i1.codintr and nc1.coddoc = i1.codintr1
                 inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
            and i1.codobiect &gt; 0
              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
              AND nc1.tip = tncVolum and c1.codcontract = vCodContract
              and nc1.codncredit = RecId
           ) )
          SELECT NC1.CodNCredit1,
                 NC1.CodNCredit,
                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                 NC1.CodObligStins,
                 NC1.CodDoc,
                 NC1.TipDoc,
                 NC1.CodObligStingator,
                 NC1.Obs,
                 NC1.ValDif,
                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                 I.PREFIXDOC Doc,
                 I.NRDOC NrDoc,
                 I.DATADOC DataDoc,
                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                 A.OBS Sediu,
                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                 ROUND(V.ValM, 4) ValDoc,
                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                 pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 0, vCurs),
                 ROUND(V.ValM_b, 4) ValDoc_b,
                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                 pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 1, vCurs),
                 I1.CODOBIECT,
                 OBJ.DENUMIRE,
                 I.CODINTR,
                 NC1.CODCLASEDISC,
                 OBJ.CODINTERN,
                 COALESCE(NC1.PROCTVA,24),
                 NC1.CODANALIZANOD,
                 NC1.CODCENTRU
          FROM NOTECREDIT1 NC1
               INNER JOIN INTRARI I ON NC1.TipDoc = I.TipDoc
               INNER JOIN INTRARI1 I1 ON NC1.Coddoc = I1.CodIntr1 AND I1.CodIntr = I.CodIntr
               INNER JOIN VALAFIS V ON I1.CODINTR1 = V.CODINTR1
               INNER JOIN NARTOBJ OBJ ON OBJ.CodObiect = I1.CodObiect
               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
    end if;
  end if;
  else
      if vVolumPeArticole = 0  then
        INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                 CodNCredit,
                                 Valoare,
                                 CodObligStins,
                                 CodDoc,
                                 TipDoc,
                                 CodObligStingator,
                                 Obs,
                                 ValDif,
                                 Valoareold,
                                 DOC,
                                 NRDOC,
                                 DATADOC,
                                 MONEDA,
                                 SEDIU,
                                 CURS,
                                 VALDOC_N,
                                 VALLEI_N,
                                 DISCOUNT_N,
                                 VALDOC_B,
                                 VALLEI_B,
                                 DISCOUNT_B,
                                 CODOBIECT,
                                 DENUMIRE,
                                 CODDOCMASTER,
                                 CODCLASEDISC,
                                 PROCTVA,
                                 CODANALIZANOD,
                                 CODCENTRU)
                          with ValAfis as ( select codintr, sum(valm) valm, sum(valm_b) valm_b from (
                            select I.CodIntr, SUM(I1.Cant*I1.PretOrig*I1.Coefdiscmaj) ValM,
                                   SUM(I1.Cant*I1.PretOrig) ValM_b
                            FROM notecredit1 nc1
                                 inner join INTRARI I on nc1.coddoc = i.codintr and nc1.tipdoc = i.tipdoc
                                 inner join intrari1 I1 on i.codintr = i1.codintr
                            where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            and i1.codobiect &gt; 0
                              AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                              AND nc1.tip = tncVolum
                              and nc1.codncredit = RecId
                           group by I.CodIntr
                           ) group by codintr )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 NC1.CodObligStins,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 ROUND(V.ValM, 4) ValDoc,
                                 ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 0, vCurs),
                                 ROUND(V.ValM_b, 4) ValDoc_b,
                                 ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                 pkg_notecredit.GetDiscVolum(I.CodIntr, vCodContract, 2, RecID, 1, vCurs),
                                 0,
                                 &apos;&apos;,
                                 I.CODINTR,
                                 NC1.CODCLASEDISC,
                                 COALESCE(NC1.PROCTVA,24),
                                 NC1.CODANALIZANOD,
                                 NC1.CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN INTRARI I ON NC1.Coddoc = I.CodIntr AND NC1.TipDoc = I.TipDoc
                               INNER JOIN VALAFIS V ON I.CODINTR = V.CODINTR
                               LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                               LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                          WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;

      else
        INSERT INTO TMP_NOTECREDITV_MAN (CodNCredit1,
                                   CodNCredit,
                                   Valoare,
                                   CodObligStins,
                                   CodDoc,
                                   TipDoc,
                                   CodObligStingator,
                                   Obs,
                                   ValDif,
                                   Valoareold,
                                   DOC,
                                   NRDOC,
                                   DATADOC,
                                   MONEDA,
                                   SEDIU,
                                   CURS,
                                   VALDOC_N,
                                   VALLEI_N,
                                   DISCOUNT_N,
                                   VALDOC_B,
                                   VALLEI_B,
                                   DISCOUNT_B,
                                   CODOBIECT,
                                   DENUMIRE,
                                   CODDOCMASTER,
                                   CODCLASEDISC,
                                   CODINTERN,
                                   PROCTVA,
                                   CODANALIZANOD,
                                   CODCENTRU)
                            with ValAfis as ( select codintr1, valm, valm_b from (
                              select I1.CodIntr1, I1.Cant*I1.PretOrig*I1.Coefdiscmaj ValM, I1.Cant*I1.PretOrig ValM_b
                              FROM notecredit1 nc1
                                   inner join INTRARI I on nc1.tipdoc = i.tipdoc
                                   inner join intrari1 I1 on i.codintr = i1.codintr and nc1.coddoc = i1.codintr1
                              where I.DataDoc BETWEEN to_date(vDataStart, &apos;DD.MM.YYYY&apos;) and to_date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              and i1.codobiect &gt; 0
                                AND I1.CodObiect not in (KArtDiscPrimVol,
                                                       KArtDiscPrimCant,
                                                       KArtPenPrimTer,
                                                       KArtDiscOffInvoiceF)  AND INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) = 0
                                AND nc1.tip = tncVolum
                                and nc1.codncredit = RecId
                             ) )
                            SELECT NC1.CodNCredit1,
                                   NC1.CodNCredit,
                                   NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                   NC1.CodObligStins,
                                   NC1.CodDoc,
                                   NC1.TipDoc,
                                   NC1.CodObligStingator,
                                   NC1.Obs,
                                   NC1.ValDif,
                                   NC1.Valoare + NVL(CORECTII.VALOARE,0),
                                   I.PREFIXDOC Doc,
                                   I.NRDOC NrDoc,
                                   I.DATADOC DataDoc,
                                   PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                   A.OBS Sediu,
                                   DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                   ROUND(V.ValM, 4) ValDoc,
                                   ROUND(V.ValM * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                   pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 0, vCurs),
                                   ROUND(V.ValM_b, 4) ValDoc_b,
                                   ROUND(V.ValM_b * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei_b,
                                   pkg_notecredit.GetDiscVolum(NC1.CodDoc, vCodContract, 2, RecID, 1, vCurs),
                                   I1.CODOBIECT,
                                   OBJ.DENUMIRE,
                                   I.CODINTR,
                                   NC1.CODCLASEDISC,
                                   OBJ.CODINTERN,
                                   COALESCE(NC1.PROCTVA,24),
                                   NC1.CODANALIZANOD,
                                   NC1.CODCENTRU
                            FROM NOTECREDIT1 NC1
                                 INNER JOIN INTRARI I ON NC1.TipDoc = I.TipDoc
                                 INNER JOIN INTRARI1 I1 ON NC1.Coddoc = I1.CodIntr1 AND I1.CodIntr = I.CodIntr
                                 INNER JOIN VALAFIS V ON I1.CODINTR1 = V.CODINTR1
                                 INNER JOIN NARTOBJ OBJ ON OBJ.CodObiect = I1.CodObiect
                                 LEFT OUTER JOIN GENERAL G ON I.CODINTR = G.CODDOC AND I.TipDoc = G.TipDoc
                                 LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                                 LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                                 LEFT OUTER JOIN (SELECT SUM(NVL(N1.VALOARE,0) - NVL(N1.VALOAREOLD,0)) VALOARE, N1.CODNCREDIT1ORIG
                                                FROM NOTECREDIT1 N1
                                                     INNER JOIN NOTECREDIT N ON N1.CODNCREDIT = N.CODNCREDIT
                                                WHERE N.CODNCREDIT &lt;&gt; RECID
                                                GROUP BY N1.CODNCREDIT1ORIG
                                                ) CORECTII ON CORECTII.CODNCREDIT1ORIG = NC1.CODNCREDIT1
                            WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncVolum;
      end if;
    end if;
    end if;
  end if;

  begin
    select nvl(PretBrutV,0) into vPretBrutV from tmp_notecredit_man;
  exception when others then vPretBrutV := 0;
  end;

  if vPretBrutV = 1 then
    update tmp_notecreditv_man set
    ValDoc   = ValDoc_b,
    ValLei   = ValLei_b,
    Discount = Discount_b;
  else
    update tmp_notecreditv_man set
    ValDoc   = ValDoc_N,
    ValLei   = ValLei_N,
    Discount = Discount_N;
  end if;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncTermen;

  if vCount &gt; 0 then
  MAKE_MANEVRA_T(vCodContract);
  if vTipDoc = 58 then

      INSERT INTO TMP_NOTECREDITT_MAN
      (CODNCREDIT1,
       CODNCREDIT,
       VALOARE,
       CODOBLIGSTINS,
       CODDOC,
       TIPDOC,
       CODOBLIGSTINGATOR,
       Obs,
       ValDif,
       Valoareold,
       doc,
       Cont,
       Moneda,
       Termen,
       Subunitatea,
       Sediu,
       Curs,
       ValDoc,
       ValLei,
       ValPlata,
       DocPlata,
       ZilePlata,
       Discount,
       Articol,
       CodObiect,
       Cant,
       ValFaraTVA,
       CODCLASEDISC,
       PROCTVA,
       CODANALIZANOD,
       CODCENTRU )
       SELECT NC1.CodNCredit1,
              NC1.CodNCredit,
              CASE WHEN TOT.VALTOT &lt;&gt; 0 THEN NC1.Valoare - NC1.VALOARE * COALESCE(CNC.FACTURAT,0)/TOT.VALTOT ELSE 0 END,
              NC1.CodObligStins,
              NC1.CodDoc,
              NC1.TipDoc,
              NC1.CodObligStingator,
              NC1.Obs,
              NC1.ValDif,
              CASE WHEN TOT.VALTOT &lt;&gt; 0 THEN NC1.Valoare - NC1.VALOARE * COALESCE(CNC.FACTURAT,0)/TOT.VALTOT ELSE 0 END,
              I.prefixdoc||&apos; &apos;|| I.nrdoc||&apos;/&apos;||to_char(I.datadoc, &apos;dd.mm.yyyy&apos;),
              PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie),
              PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)),
              obstins.termen,
              i.subunitatea,
              A.Obs,
              DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)),
              case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end,
              ROUND(case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end * DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)), 4),
              case
                when coalesce(i.valdoc,0)=0 then 0---razvan
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj
                else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end
                else sign(obstins.valoare) * stingere.valoare * (case when i.tipdoc = 21 then i1.pretorig*i1.cant*i1.coefdiscmaj
                else i1.pretorig*i1.cant*i1.coefdiscmaj+i1.tva end) / i.valdoc
              end,
              case
                when pkg_notecredit.IsCumulat(i1.codies1, C.CODCONTRACT, 1) = 1 then &apos;TOTAL CUMULAT&apos;
                else case
                       when gstingator.tipdoc = 28 then &apos;PV&apos;||&apos; &apos;||comp.nrdoc||&apos;/&apos;||to_char(comp.datadoc, &apos;dd.mm.yyyy&apos;)
                       else t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;)
                     end
              end,
              nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc,
              pkg_notecredit.GETDISCTERMENCLI(to_char(nvl(T1.Datadoc, COMP.datadoc), &apos;DD.MM.YYYY&apos;), nvl(T1.Datadoc, COMP.datadoc) - I.Datadoc, C.CODCONTRACT, I1.CodIes1,
                                              case when gstingator.tipdoc = 28 and obstins.valoare &lt; 0 then - stingere.valoare else stingere.valoare end),
              OBJ.Denumire,
              I1.CodObiect,
              I1.Cant,
              case when i.tipdoc = 21 then (i1.pretorig*i1.cant)*i1.coefdiscmaj-i1.TVA else (i1.pretorig*i1.cant)*i1.coefdiscmaj end,
              NC1.CODCLASEDISC,
              COALESCE(NC1.PROCTVA,24),
              NC1.CODANALIZANOD,
              NC1.CODCENTRU
       FROM NOTECREDIT1 NC1
            INNER JOIN IESIRI1 I1 ON NC1.CodDoc = I1.CodIes1
            INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
            INNER JOIN IESIRI I ON I1.CodIes = I.CodIes
            INNER JOIN GENERAL GSTINS ON I.CodIes = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
            INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif  and gstins.codgeneral = obstins.codgeneral
            left JOIN OBLIGPIF obstingator on NC1.CODOBLIGSTINGATOR = obstingator.codobligpif
            left JOIN stingere ON stingere.codstinspif = obstins.codobligpif AND stingere.codstingatorpif = obstingator.codobligpif
            left JOIN GENERAL GSTINGATOR ON obstingator.codgeneral = GSTINGATOR.CODGENERAL
            LEFT JOIN (SELECT TT1.DOC, TT1.NRDOC, TT1.DATADOC, TT1.CODTREZOR1, TT.TIPDOC
                       FROM TREZOR1 TT1
                            INNER JOIN TREZOR TT ON  TT.CODTREZOR = TT1.CODTREZOR) T1 ON T1.CODTREZOR1 = GSTINGATOR.CODDOC AND T1.TIPDOC = GSTINGATOR.TIPDOC
            left join (select c.datadoc, c.nrdoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gstingator.coddoc and comp.tipdoc = gstingator.tipdoc
            LEFT JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
            LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
            LEFT JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
            LEFT JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
            LEFT JOIN CENTRALIZARENC CNC ON CNC.CODNCREDIT = RECID AND CNC.PROCTVA = NC1.PROCTVA AND CNC.CODOBIECTASOC = I1.CODOBIECT
            LEFT JOIN (
              SELECT SUM(nc1.valoare) VALTOT,
                     I1.CODOBIECT, NC1.PROCTVA
              FROM NOTECREDIT1 NC1
                   INNER JOIN IESIRI1 I1 ON NC1.CodDoc = I1.CodIes1
                   INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
                   INNER JOIN IESIRI I ON I1.CodIes = I.CodIes
                   INNER JOIN GENERAL GSTINS ON I.CodIes = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
                   INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif  and gstins.codgeneral = obstins.codgeneral
              WHERE gstins.semnificatie &lt;&gt; 240 and gstins.semnificatie &lt;&gt; 500
                    and gstins.semnificatie &lt;&gt; 211 and gstins.semnificatie &lt;&gt; 210 and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen
              GROUP BY I1.CODOBIECT, NC1.PROCTVA      
            ) TOT ON TOT.CODOBIECT = I1.CODOBIECT AND TOT.PROCTVA = NC1.PROCTVA
       WHERE gstins.semnificatie &lt;&gt; 240 and gstins.semnificatie &lt;&gt; 500
             and gstins.semnificatie &lt;&gt; 211 and gstins.semnificatie &lt;&gt; 210 and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen;

   else

     INSERT INTO TMP_NOTECREDITT_MAN
      (CODNCREDIT1,
       CODNCREDIT,
       VALOARE,
       CODOBLIGSTINS,
       CODDOC,
       TIPDOC,
       CODOBLIGSTINGATOR,
       Obs,
       ValDif,
       Valoareold,
       doc,
       Cont,
       Moneda,
       Termen,
       Subunitatea,
       Sediu,
       Curs,
       ValDoc,
       ValLei,
       ValPlata,
       DocPlata,
       ZilePlata,
       Discount,
       Articol,
       CodObiect,
       Cant,
       ValFaraTVA,
       CODCLASEDISC,
       PROCTVA,
       CODANALIZANOD,
       CODCENTRU)
       SELECT NC1.CodNCredit1,
              NC1.CodNCredit,
              CASE WHEN TOT.VALTOT &lt;&gt; 0 THEN NC1.Valoare - NC1.VALOARE * COALESCE(CNC.FACTURAT,0)/TOT.VALTOT ELSE 0 END,
              NC1.CodObligStins,
              NC1.CodDoc,
              NC1.TipDoc,
              NC1.CodObligStingator,
              NC1.Obs,
              NC1.ValDif,
              CASE WHEN TOT.VALTOT &lt;&gt; 0 THEN NC1.Valoare - NC1.VALOARE * COALESCE(CNC.FACTURAT,0)/TOT.VALTOT ELSE 0 END,
              I.prefixdoc||&apos; &apos;|| I.nrdoc||&apos;/&apos;||to_char(I.datadoc, &apos;dd.mm.yyyy&apos;),
              PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie),
              PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)),
              obstins.termen,
              i.subunitatea,
              A.Obs,
              DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)),
              i1.pu*i1.cant+i1.tva,
              ROUND((i1.pu*i1.cant+i1.tva)* DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)), 4),
              case
                when coalesce (i.valdoc,0)=0 then 0 ---razvan
                when pkg_notecredit.IsCumulat(i1.codintr1, C.CODCONTRACT, 2) = 1 then i1.pu*i1.cant+i1.tva
                else sign(obstins.valoare) * stingere.valoare * (i1.pu*i1.cant+i1.tva) / i.valdoc
              end,
              case
                when pkg_notecredit.IsCumulat(i1.codintr1, C.CODCONTRACT, 2) = 1 then &apos;TOTAL CUMULAT&apos;
                else case
                       when gstingator.tipdoc = 28 then &apos;PV&apos;||&apos; &apos;||comp.nrdoc||&apos;/&apos;||to_char(comp.datadoc, &apos;dd.mm.yyyy&apos;)
                       else t1.doc||&apos; &apos; ||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;)
                     end
              end,
              nvl(T1.Datadoc,comp.datadoc) - I.Datadoc,
              pkg_notecredit.GETDISCTERMENFURN(to_char(nvl(T1.Datadoc,comp.datadoc), &apos;DD.MM.YYYY&apos;), nvl(T1.Datadoc,comp.datadoc) - I.Datadoc, C.CODCONTRACT, I1.CodIntr1,
                                               case when gstingator.tipdoc = 28 and obstins.valoare &lt; 0 then - stingere.valoare else stingere.valoare end),
              OBJ.Denumire,
              I1.CodObiect,
              I1.Cant,
              i1.pretorig*i1.cant*i1.coefdiscmaj,
              NC1.CODCLASEDISC,
              COALESCE(NC1.PROCTVA,24),
              NC1.CODANALIZANOD,
              NC1.CODCENTRU
       FROM NOTECREDIT1 NC1
            INNER JOIN INTRARI1 I1 ON NC1.CodDoc = I1.CodIntr1
            INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
            INNER JOIN INTRARI I ON I1.CodIntr = I.CodIntr
            INNER JOIN GENERAL GSTINS ON I.CodIntr = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
            INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif and gstins.codgeneral = obstins.codgeneral
            left JOIN OBLIGPIF obstingator on NC1.CODOBLIGSTINGATOR = obstingator.codobligpif
            left JOIN stingere ON stingere.codstinspif = obstins.codobligpif AND stingere.codstingatorpif = obstingator.codobligpif
            left JOIN GENERAL GSTINGATOR ON obstingator.codgeneral = GSTINGATOR.CODGENERAL
            LEFT JOIN (SELECT TT1.DOC, TT1.NRDOC, TT1.DATADOC, TT1.CODTREZOR1, TT.TIPDOC
                       FROM TREZOR1 TT1
                            INNER JOIN TREZOR TT ON  TT.CODTREZOR = TT1.CODTREZOR) T1 ON T1.CODTREZOR1 = GSTINGATOR.CODDOC AND T1.TIPDOC = GSTINGATOR.TIPDOC
            left join (select c.datadoc, c.nrdoc, c.codcompens, 28 tipdoc from compens c) comp on comp.codcompens = gstingator.coddoc and comp.tipdoc = gstingator.tipdoc
            LEFT JOIN CENTRALIZARENC CNC ON CNC.CODNCREDIT = RECID AND CNC.PROCTVA = NC1.PROCTVA AND CNC.CODOBIECTASOC = I1.CODOBIECT
            LEFT JOIN (
              SELECT SUM(nc1.valoare) VALTOT,
                     I1.CODOBIECT, NC1.PROCTVA
              FROM NOTECREDIT1 NC1
                   INNER JOIN INTRARI1 I1 ON NC1.CodDoc = I1.CodIntr1
                   INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.CodObiect
                   INNER JOIN INTRARI I ON I1.CodINTR = I.CodINTR
                   INNER JOIN GENERAL GSTINS ON I.CodINTR = GSTINS.CodDoc AND I.TipDoc = GSTINS.TipDoc
                   INNER JOIN OBLIGPIF obstins on NC1.CODOBLIGSTINS = obstins.codobligpif  and gstins.codgeneral = obstins.codgeneral
              WHERE gstins.semnificatie &lt;&gt; 140 and gstins.semnificatie &lt;&gt; 600 and gstins.semnificatie &lt;&gt; 130
                    and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen
              GROUP BY I1.CODOBIECT, NC1.PROCTVA
            ) TOT ON TOT.CODOBIECT = I1.CODOBIECT AND TOT.PROCTVA = NC1.PROCTVA
            LEFT  JOIN NAGENDA A ON I.CODLOCATIE = A.CODAGENDA
            LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
            LEFT  JOIN NOTECREDIT NC ON NC1.CODNCREDIT = NC.CODNCREDIT
            LEFT  JOIN CONTRACT C ON NC.CODCONTRACT = C.CODCONTRACT
       WHERE gstins.semnificatie &lt;&gt; 140 and gstins.semnificatie &lt;&gt; 600 and gstins.semnificatie &lt;&gt; 130
       and NC1.CodNCredit = RecId AND NC1.Tip = tncTermen;

   end if;
   end if;
   if vCodContract &gt; 0 then
     delete from tmp_notecreditt_man where discount = 0;
   end if;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncCantitate;

  if vCount &gt; 0 then
   if vTipDoc = 58 then
     if vCodContract &gt; 0 then
     INSERT INTO TMP_NOTECREDITC_MAN (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  OBSNAV,
                                  PROCTVA,
                                  CODANALIZANOD,
                                  CODCENTRU
                                  )
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant,
                                c1.codcontract1,
                                  sum(
                                    case when i.tipdoc = 21 then (i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) - i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*
                                    pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100) else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) end
                                     )/sum(i1.cant) pretmediu,
                                  sum(
                                    case when i.tipdoc = 21 then (i1.PretOrig*i1.cant - i1.PretOrig*i1.cant*
                                    pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100) else i1.PretOrig*i1.cant end
                                     )/sum(i1.cant) pretmediu_b
                              from notecredit1 nc1
                                   inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                   inner join iesiri   i on i1.codies    = i.codies
                                   inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                                   inner join contract c on c1.codcontract = c.codcontract
                              where (NVL(i.anulat, 0) = 0)
                                    and c.codcontract = vCodContract
                                    and nc1.tip = tncCantitate and nc1.codncredit = RecId
                                    and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              group by i1.codobiect, c1.codcontract1
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  NC1.CodObligStins,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoare,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  0,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva)/i1.cant, 2) else i1.pretorig * i1.coefdiscmaj end pret,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant - i1.tva)/i1.cant, 2) else i1.pretorig end pret_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end Val,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end Val_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                   case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  round (pkg_notecredit.GetDiscCant(I1.cant, case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end,CumulCant.totalcant,CumulCant.codcontract1,CUmulCant.pretmediu,0,vCurs), 2),
                                  round (pkg_notecredit.GetDiscCant(I1.cant, case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end,CumulCant.totalcant,CumulCant.codcontract1,CUmulCant.pretmediu_b,0,vCurs), 2),
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva) else i1.Pretorig*i1.Cant * i1.coefdiscmaj end,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant - i1.tva) else i1.Pretorig*i1.Cant end,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NC1.OBSNAV,
                                  COALESCE(NC1.PROCTVA,24),
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                inner join iesiri i on i1.codies = i.codies
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect and CumulCant.CodContract1 = PKG_NOTECREDIT.GETCODCONTRACT1(i1.codobiect, i.datadoc, vCodContract)
                                INNER JOIN general g ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie not in (500, 240, 211, 100, 140, 400)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    else
      INSERT INTO TMP_NOTECREDITC_MAN (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  OBSNAV,
                                  PROCTVA,
                                  CODANALIZANOD,
                                  CODCENTRU)
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant
                              from notecredit1 nc1
                                   inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                   inner join iesiri   i on i1.codies  = i.codies
                              where (NVL(i.anulat, 0) = 0)
                                    and nc1.tip = tncCantitate and nc1.codncredit = RecId
                                    and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              group by i1.codobiect
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  NC1.CodObligStins,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoare,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  NC1.Valoare/DECODE(I1.cant * I1.PU * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.PU * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) * 100,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva)/i1.cant, 2) else i1.pretorig * i1.coefdiscmaj end pret,
                                  case when i.tipdoc = 21 then round((I1.Pretorig*i1.cant - i1.tva)/i1.cant, 2) else i1.pretorig end pret_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end Val,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end Val_b,
                                  case when i.tipdoc = 21 then (I1.cant * I1.Pretorig)*i1.coefdiscmaj - i1.tva else I1.cant * I1.Pretorig * i1.coefdiscmaj end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                   case when i.tipdoc = 21 then (I1.cant * I1.Pretorig - i1.tva) else I1.cant * I1.Pretorig end
                                   * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  0, 0,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant * i1.coefdiscmaj - i1.tva) else i1.Pretorig*i1.Cant * i1.coefdiscmaj end,
                                  case when i.tipdoc = 21 then (I1.Pretorig*i1.cant - i1.tva) else i1.Pretorig*i1.Cant end,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NC1.OBSNAV,
                                  COALESCE(NC1.PROCTVA,24),
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join iesiri1 i1 on nc1.coddoc = i1.codies1
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect
                                inner join iesiri i on i1.codies = i.codies
                                INNER JOIN general g ON g.coddoc = i.codies and g.tipdoc = i.tipdoc and g.semnificatie not in (500, 240, 211, 100, 140, 400)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    end if;
  else
  if vCodContract &gt; 0 then
    INSERT INTO TMP_NOTECREDITC_MAN (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  OBSNAV,
                                  PROCTVA,
                                  CODANALIZANOD,
                                  CODCENTRU)
                           with CumulCant as
                            (
                              select
                                i1.codobiect,
                                sum(i1.cant) totalcant,
                                c1.codcontract1,
                                sum(I1.cant * I1.Pretorig * I1.COEFDISCMAJ)/sum(i1.cant) pretmediu,
                                sum(I1.cant * I1.Pretorig)/sum(i1.cant) pretmediu_b
                              from notecredit1 nc1
                                   inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                   inner join intrari   i on i1.codintr    = i.codintr
                                   inner join contract1 c1 on c1.codcontract1 = GetCodContract1(i1.codobiect, i.datadoc, vCodContract)
                                   inner join contract c on c.codcontract = c1.codcontract
                              where (NVL(i.anulat, 0) = 0)
                                    and c.codcontract = vCodContract
                                    and nc1.codncredit = RecId and nc1.tip = tncCantitate
                                    and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                              group by i1.codobiect, c1.codcontract1
                            )
                           SELECT NC1.CodNCredit1,
                                  NC1.CodNCredit,
                                  NC1.Valoare,
                                  NC1.CodObligStins,
                                  NC1.CodDoc,
                                  NC1.TipDoc,
                                  NC1.CodObligStingator,
                                  NC1.Obs,
                                  NC1.ValDif,
                                  NC1.Valoare,
                                  OBJ.Denumire Articol,
                                  I1.cant,
                                  i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                  PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                  A.obs sediu,
                                  DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                  i1.codobiect,
                                  case when vCodContract = 0 then NC1.Valoare/DECODE(I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) else 0 end,
                                  I1.PU pret,
                                  I1.PretOrig pret,
                                  I1.cant * I1.Pretorig * I1.COEFDISCMAJ Val,
                                  I1.cant * I1.Pretorig Val_b,
                                  I1.cant * I1.Pretorig * I1.COEFDISCMAJ * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                  I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                  round (pkg_notecredit.GetDiscCant(I1.cant, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), CumulCant.totalcant, CumulCant.CodContract1, cumulcant.pretmediu,0,vCurs), 2),
                                  round (pkg_notecredit.GetDiscCant(I1.cant, I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), CumulCant.totalcant, CumulCant.CodContract1, cumulcant.pretmediu_b,0,vCurs), 2),
                                  I1.cant * I1.PretOrig * I1.COEFDISCMAJ,
                                  I1.cant * I1.PretOrig,
                                  NC1.CODCLASEDISC,
                                  OBJ.CODINTERN,
                                  NC1.OBSNAV,
                                  COALESCE(NC1.PROCTVA,24),
                                  NC1.CODANALIZANOD,
                                  NC1.CODCENTRU
                           FROM NOTECREDIT1 NC1
                                inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                inner join CumulCant on i1.codobiect = CumulCant.codobiect
                                inner join intrari i on i1.codintr = i.codintr
                                INNER JOIN general g ON g.coddoc = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie not in (500,111,200,140,300,240)
                                INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                                LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                                LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                           WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    else
      INSERT INTO TMP_NOTECREDITC_MAN (CodNCredit1,
                                  CodNCredit,
                                  Valoare,
                                  CodObligStins,
                                  CodDoc,
                                  TipDoc,
                                  CodObligStingator,
                                  Obs,
                                  ValDif,
                                  Valoareold,
                                  ARTICOL,
                                  CANT,
                                  DOC,
                                  MONEDA,
                                  SEDIU,
                                  CURS,
                                  CODOBIECT,
                                  PROCDISC,
                                  PRET_N,
                                  PRET_B,
                                  VAL_N,
                                  VAL_B,
                                  VALLEI_N,
                                  VALLEI_B,
                                  DISCOUNT_N,
                                  DISCOUNT_B,
                                  ValFaraTVA_N,
                                  ValFaraTVA_B,
                                  CODCLASEDISC,
                                  CODINTERN,
                                  OBSNAV,
                                  PROCTVA,
                                  CODANALIZANOD,
                                  CODCENTRU)
                         with CumulCant as
                          (
                            select
                              i1.codobiect,
                              sum(i1.cant) totalcant
                            from notecredit1 nc1
                                 inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                                 inner join intrari   i on i1.codintr    = i.codintr
                            where (NVL(i.anulat, 0) = 0)
                                  and nc1.codncredit = RecId and nc1.tip = tncCantitate
                                  and I.Datadoc between To_Date(vDataStart, &apos;DD.MM.YYYY&apos;) and To_Date(vDataStop, &apos;DD.MM.YYYY&apos;)
                            group by i1.codobiect
                          )
                         SELECT NC1.CodNCredit1,
                                NC1.CodNCredit,
                                NC1.Valoare,
                                NC1.CodObligStins,
                                NC1.CodDoc,
                                NC1.TipDoc,
                                NC1.CodObligStingator,
                                NC1.Obs,
                                NC1.ValDif,
                                NC1.Valoare,
                                OBJ.Denumire Articol,
                                I1.cant,
                                i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                                PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(g.MONEDA, 0)) MONEDA,
                                A.obs sediu,
                                DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                i1.codobiect,
                                case when vCodContract = 0 then NC1.Valoare/DECODE(I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 0, 1, I1.cant * I1.Pretorig * I1.CoefDiscMaj * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS))) else 0 end,
                                I1.PU pret,
                                I1.PretOrig pret_b,
                                I1.cant * I1.Pretorig * I1.COEFDISCMAJ Val,
                                I1.cant * I1.Pretorig Val_b,
                                I1.cant * I1.Pretorig * I1.COEFDISCMAJ * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei,
                                I1.cant * I1.Pretorig * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) vallei_b,
                                0, 0,
                                I1.cant * I1.PretOrig * I1.COEFDISCMAJ,
                                I1.cant * I1.PretOrig,
                                NC1.CODCLASEDISC,
                                OBJ.CODINTERN,
                                NC1.OBSNAV,
                                COALESCE(NC1.PROCTVA,24),
                                NC1.CODANALIZANOD,
                                NC1.CODCENTRU
                         FROM NOTECREDIT1 NC1
                              inner join intrari1 i1 on nc1.coddoc = i1.codintr1
                              inner join CumulCant on i1.codobiect = CumulCant.codobiect
                              inner join intrari i on i1.codintr = i.codintr
                              INNER JOIN general g ON g.coddoc = i.codintr and g.tipdoc = i.tipdoc and g.semnificatie not in (500,111,200,140,300,240)
                              INNER JOIN NARTOBJ OBJ ON I1.CodObiect = OBJ.Codobiect
                              LEFT  JOIN NAGENDA A ON A.codagenda = i.codlocatie
                              LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                         WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncCantitate;
    end if;
  end if;
  end if;

  begin
    select nvl(PretBrutC,0) into vPretBrutC from tmp_notecredit_man;
  exception when others then vPretBrutC := 0;
  end;

  if vPretBrutC = 1 then
    update tmp_notecreditc_man set
    Pret = PRET_B,
    Val  = VAL_B,
    VALLEI = VALLEI_B,
    DISCOUNT = DISCOUNT_B,
    VALFARATVA = VALFARATVA_B;
  else
    update tmp_notecreditc_man set
    Pret = PRET_N,
    Val  = VAL_N,
    VALLEI = VALLEI_N,
    DISCOUNT = DISCOUNT_N,
    VALFARATVA = VALFARATVA_N;
  end if;

  select count(*) into vCount
  from notecredit1
  where codncredit = recid and tip = tncPenalizari;

  if vCount &gt; 0 then
  if vTipDoc = 58 then
  INSERT INTO TMP_NOTECREDITP_MAN (CodNCredit1,
                               CodNCredit,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               DOC,
                               CONT,
                               MONEDA,
                               TERMEN,
                               SUBUNITATEA,
                               SEDIU,
                               CURS,
                               VALDOC,
                               VALLEI,
                               VALPLATA,
                               DOCPLATA,
                               ZILEPLATA,
                               DISCOUNT,
                               CODANALIZANOD,
                               CODCENTRU)
                        SELECT NC1.CodNCredit1,
                               NC1.CodNCredit,
                               NC1.Valoare,
                               NC1.CodObligStins,
                               NC1.CodDoc,
                               NC1.TipDoc,
                               NC1.CodObligStingator,
                               NC1.Obs,
                               NC1.ValDif,
                               NC1.Valoare,
                               i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                               PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
                               PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)) MONEDA,
                               obstins.termen termen,
                               i.subunitatea subunitatea,
                               A.obs sediu,
                               DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)) CURS,
                               obstins.valoare valdoc,
                               obstins.valoare * DECODE(NVL(GREG.CURS, Gstins.CURS), 0, 1, NVL(GREG.CURS, Gstins.CURS)) vallei,
                               stingere.valoare,
                               t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;) docplata,
                               t1.datadoc - i.datadoc,
                               case when t1.datadoc &gt; obstins.termen then stingere.Valoare * pkg_notecredit.GETPROCCONTRACTPEN(vCodContract)/100 else 0 end,
                               NC1.CODANALIZANOD,
                               NC1.CODCENTRU
                        FROM NOTECREDIT1 NC1
                             left join obligpif obstins on nc1.codobligstins = obstins.codobligpif
                             left join obligpif obstingator on nc1.codobligstingator = obstingator.codobligpif
                             left join stingere on stingere.codstinspif = obstins.codobligpif
                                                    and stingere.codstingatorpif = obstingator.codobligpif
                             left join general gstins on gstins.codgeneral = obstins.codgeneral
                             left join general gstingator on gstingator.codgeneral = obstingator.codgeneral
                             left join iesiri i on gstins.coddoc = i.codies and gstins.tipdoc = i.tipdoc
                             left join trezor1 t1 on gstingator.coddoc = t1.codtrezor1
                             left join trezor t on t1.codtrezor = t.codtrezor and gstingator.tipdoc = t.tipdoc
                             left join nagenda a on i.codlocatie = a.codagenda
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
                        WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncPenalizari;
  else

  INSERT INTO TMP_NOTECREDITP_MAN (CodNCredit1,
                               CodNCredit,
                               Valoare,
                               CodObligStins,
                               CodDoc,
                               TipDoc,
                               CodObligStingator,
                               Obs,
                               ValDif,
                               Valoareold,
                               DOC,
                               CONT,
                               MONEDA,
                               TERMEN,
                               SUBUNITATEA,
                               SEDIU,
                               CURS,
                               VALDOC,
                               VALLEI,
                               VALPLATA,
                               DOCPLATA,
                               ZILEPLATA,
                               DISCOUNT,
                               CODANALIZANOD,
                               CODCENTRU)
                        SELECT NC1.CodNCredit1,
                               NC1.CodNCredit,
                               NC1.Valoare,
                               NC1.CodObligStins,
                               NC1.CodDoc,
                               NC1.TipDoc,
                               NC1.CodObligStingator,
                               NC1.Obs,
                               NC1.ValDif,
                               NC1.Valoare,
                               i.prefixdoc||&apos; &apos;|| i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) doc,
                               PKG_LIST_BASE_UTILS.decode_iCont(obstins.icont,obstins.codpart,i.an*12+i.luna,obstins.semnificatie) cont,
                               PKG_MONEDE.GET_SIMBOL_MONEDA(NVL(gstins.MONEDA, 0)) MONEDA,
                               obstins.termen termen,
                               i.subunitatea subunitatea,
                               A.obs sediu,
                               DECODE(NVL(GREG.CURS, GSTINS.CURS), 0, 1, NVL(GREG.CURS, GSTINS.CURS)) CURS,
                               obstins.valoare valdoc,
                               obstins.valoare * DECODE(NVL(GREG.CURS, Gstins.CURS), 0, 1, NVL(GREG.CURS, Gstins.CURS)) vallei,
                               stingere.valoare,
                               t1.doc||&apos; &apos;||t1.nrdoc||&apos;/&apos;||to_char(t1.datadoc, &apos;dd.mm.yyyy&apos;) docplata,
                               t1.datadoc - i.datadoc,
                               case when t1.datadoc &gt; obstins.termen then stingere.Valoare * pkg_notecredit.GETPROCCONTRACTPEN(vCodContract)/100 else 0 end,
                               NC1.CODANALIZANOD,
                               NC1.CODCENTRU
                        FROM NOTECREDIT1 NC1
                             left join obligpif obstins on nc1.codobligstins = obstins.codobligpif
                             left join obligpif obstingator on nc1.codobligstingator = obstingator.codobligpif
                             left join stingere on stingere.codstinspif = obstins.codobligpif
                                                    and stingere.codstingatorpif = obstingator.codobligpif
                             left join general gstins on gstins.codgeneral = obstins.codgeneral
                             left join general gstingator on gstingator.codgeneral = obstingator.codgeneral
                             left join intrari i on gstins.coddoc = i.codintr and gstins.tipdoc = i.tipdoc
                             left join trezor1 t1 on gstingator.coddoc = t1.codtrezor1
                             left join trezor t on t1.codtrezor = t.codtrezor and gstingator.tipdoc = t.tipdoc
                             left join nagenda a on i.codlocatie = a.codagenda
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
                       WHERE NC1.CodNCredit = RecId AND NC1.Tip = tncPenalizari;

  end if;
  end if;

  if vTipDoc = 58 then
    insert into tmp_notecreditfact_man (codncfact, CodNCredit, coddoc, tipdoc, prefixdoc, nrdoc, datadoc, valdoc,coddoc1)
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc,ncf.coddoc1
    from Notecreditfact NCF
         inner join iesiri i on NCF.Coddoc = i.codies and ncf.tipdoc = i.tipdoc
    where codncredit = RecId;
  else
    insert into tmp_notecreditfact_man (codncfact, CodNCredit, coddoc, tipdoc, prefixdoc, nrdoc, datadoc, valdoc, valt,coddoc1)
    select NCF.codncfact, NCF.CodNCredit, NCF.coddoc, NCF.tipdoc, NCF.prefixdoc, NCF.nrdoc, NCF.datadoc, NCF.valdoc, NCF.ValT,ncf.coddoc1
    from Notecreditfact NCF
         left join intrari i on NCF.Coddoc = i.codintr and ncf.tipdoc = i.tipdoc
         left join iesiri ies on ncf.coddoc = ies.codies and ncf.tipdoc = ies.tipdoc
    where codncredit = RecId and (ies.codies &gt; 0 or i.codintr &gt; 0);
  end if;

  insert into tmp_nccadouri(codnccadouri,
                            codncredit,
                            codobiect,
                            codobiectasoc,
                            codobiectasocsec,
                            cant,
                            cantfact,
                            codarticol,
                            umsec,
                            diferente,
                            denumire,
                            denumireasoc,
                            denumireasocsec,
                            den_um1,
                            tiparticol,
                            Pret,
                            Paritate,
                            CODANALIZANOD,
                            CODCENTRU)
                     select c.codnccadouri,
                            c.codncredit,
                            c.codobiect,
                            c.codobiectasoc,
                            c.codobiectasocsec,
                            c.cant,
                            c.cantfact,
                            c.codarticol,
                            c.umsec,
                            c.diferente,
                            obj.denumire,
                            objasoc.denumire,
                            objasocsec.denumire,
                            num1.den_um1,
                            art.tiparticol,
                            0,
                            num1.paritate,
                            C.CODANALIZANOD,
                            C.CODCENTRU
                     from nccadouri c
                          left join nartobj obj on c.codobiect = obj.codobiect
                          left join nart art on obj.codarticol = art.codarticol
                          left join nartobj objasoc on c.codobiectasoc = objasoc.codobiect
                          left join nartobj objasocsec on c.codobiectasocsec = objasocsec.codobiect
                          left join num1 on num1.codum1 = c.umsec where c.codncredit = RecId;

  INSERT INTO TMP_CENTRALIZARENC_MAN (
    CODCENTRALIZARE,
    CODNCREDIT,
    CODARTICOL,
    CODOBIECT,
    CODOBIECTASOC,
    CODOBIECTASOCSEC,
    UMSEC,
    DIFERENTE,
    TIPARTICOL,DENUMIRE, DENUMIREASOC, DENUMIREASOCSEC, DEN_UM1, PARITATE, FACTURAT,PROCTVA,
    CODCENTRU, CODANALIZANOD,
    OBS,CANT)
  SELECT
    C.CODCENTRALIZARE,
    C.CODNCREDIT,
    C.CODARTICOL,
    C.CODOBIECT,
    C.CODOBIECTASOC,
    C.CODOBIECTASOCSEC,
    C.UMSEC,
    C.DIFERENTE,
    NART.TIPARTICOL,O.DENUMIRE,
    case when o.codobiect &lt;&gt; nvl(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0) then
      OS.DENUMIRE
      else case when vTipDoc = 58 then iI.prefixdoc||&apos; &apos;||iI.nrdoc||&apos;/&apos;||to_char(ii.datadoc, &apos;dd.mm.yyyy&apos;)
                                  else it.prefixdoc||&apos; &apos;||it.nrdoc||&apos;/&apos;||to_char(it.datadoc, &apos;dd.mm.yyyy&apos;)
           end
    end,
    OSS.DENUMIRE, NUM1.DEN_UM1, 0, C.FACTURAT,NVL(C.PROCTVA,24),
    C.CODCENTRU, C.CODANALIZANOD,
    C.OBS,C.CANT
  FROM CENTRALIZARENC C
       LEFT JOIN NART ON NART.CODARTICOL = C.CODARTICOL
       LEFT JOIN NARTOBJ O ON C.CODOBIECT = O.CODOBIECT
       LEFT JOIN NARTOBJ OS ON OS.CODOBIECT = C.CODOBIECTASOC
       LEFT JOIN NARTOBJ OSS ON OSS.CODOBIECT = C.CODOBIECTASOCSEC
       LEFT JOIN NUM1 ON NUM1.CODUM1 = C.UMSEC
       LEFT JOIN IESIRI II ON II.CODIES = C.CODOBIECTASOC
       LEFT JOIN INTRARI IT ON IT.CODINTR = C.CODOBIECTASOC
  WHERE C.CODNCREDIT = RECID;

  if vTipDoc = 58 then
    for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         case
                           when art.tiparticol = 0 then i1.cant
                         else
                           case when i.tipdoc = 21 then I1.Cant*I1.PU - I1.TVA else I1.Cant*I1.PU end
                         end  valoare
                  from tmp_notecreditfact_man tmp
                       inner join iesiri1 i1 on i1.codies = tmp.coddoc
                       inner join iesiri i on i.codies = i1.codies
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid) loop
      update tmp_centralizarenc_man
      set
        paritate = paritate + v_Rec.valoare
      where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = recid;
    end loop;
  else
    for v_rec in (select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         case when art.tiparticol &lt;&gt; 0 then I1.Cant*I1.PU else i1.cant end valoare
                  from tmp_notecreditfact tmp
                       inner join intrari i on tmp.coddoc = i.codintr and i.tipdoc = tmp.tipdoc
                       inner join intrari1 i1 on tmp.coddoc = i1.codintr
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid
                        AND (I1.CodObiect IN (
                               KArtDiscPrimVol,
                               KArtDiscPrimCant,
                               KArtPenPrimTer,
                               KArtDiscOffInvoiceF) or INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) &gt; 0)
                  union all
                  select nvl(i1.codobiect,0) codobiect, nvl(i1.codobiectorig,0) codobiectorig,
                         - case when art.tiparticol &lt;&gt; 0 then I1.Cant*I1.PU else i1.cant end valoare
                  from tmp_notecreditfact tmp
                       inner join iesiri i on tmp.coddoc = i.codies and i.tipdoc = tmp.tipdoc
                       inner join iesiri1 i1 on tmp.coddoc = i1.codies
                       inner join nartobj obj on i1.codobiect = obj.codobiect
                       inner join nart art on obj.codarticol = art.codarticol
                  where tmp.codncredit = recid
                        AND (I1.CodObiect IN (
                               KArtDiscPrimVol,
                               KArtDiscPrimCant,
                               KArtPenPrimTer,
                               KArtDiscOffInvoiceF) or INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) &gt; 0)
                 ) loop
      update tmp_centralizarenc_man
      set
        paritate = paritate + v_Rec.valoare
      where nvl(codobiect,0) = v_rec.codobiect and nvl(codobiectasoc,0) = v_Rec.codobiectorig and codncredit = recid;
    end loop;
  end if;

  update tmp_centralizarenc_man set
  diferente = diferente + nvl(facturat,0) - nvl(paritate,0);

  update tmp_centralizarenc_man set
  facturat = paritate,
  den_um1 = (select den_um1 from num1 where codum1 = umsec);

  select count(*) into vCount1 from tmp_centralizarenc_man;
  if vCount1 = 0 then
    select count(*) into vCount from tmp_notecreditfact_man;
    if vCount &gt; 0 then
      -- trebuie incarcata centralizarea
      if vTipDoc = 58 then
        insert into tmp_centralizarenc_man (CodArticol, CodObiect, DenumireAsoc, CodObiectAsoc, Denumire,
          Facturat, UMSec, Den_UM1, TIPARTICOL, paritate, DenumireAsocSec, CodObiectAsocSec)
        select ART.CodArticol, OBJ.CodObiect, objasoc.denumire as DenumireAsoc, nvl(objasoc.codobiect, 0) as CodObiectAsoc, OBJ.Denumire,
          SUM(case when art.tiparticol = 1 then case when i.tipdoc = 21 then I1.Cant * I1.PU - i1.tva else I1.Cant * I1.PU end else I1.Cant end) Facturat,
          Num1.CODUM1 UMSec, NUM1.Den_UM1, ART.TIPARTICOL, num1.paritate, objasocsec.denumire as DenumireAsocSec, nvl(objasocsec.codobiect, 0) as CodObiectAsocSec
        FROM IESIRI I
             inner join iesiri1 I1 on i.codies = i1.codies
             inner join nartobj OBJ on i1.codobiect = obj.codobiect
             inner join nart ART on OBJ.codarticol = ART.codarticol
             inner join num1 on art.um = num1.codum and nvl(num1.secundara, 0) = 0
             inner join tmp_notecreditfact_man tmp on i.codies = tmp.coddoc and tmp.tipdoc = i.tipdoc
             inner join tmp_notecredit_man nc on tmp.codncredit = nc.codncredit
             left  join nartobj OBJASOC on i1.codobiectorig = objasoc.codobiect
             left  join contract1 c1 on i1.codobiectorig = c1.codcadou
             left  join contract c on c1.codcontract = c.codcontract and c.codcontract = vCodContract
             left  join nartobj OBJASOCSEC on c1.codobiectsec = objasocsec.codobiect
        where I.TipDoc IN (19, 21, 26) AND I.Partener = vCodPart
          AND (I1.CodObiect not in (KArtDiscAcVol,KArtDiscAcCant,KArtPenAcTer,KArtDiscOffInvoiceC) AND INSTR(KArtDiscAcTer, TO_CHAR(I1.CODOBIECT)) = 0)
          AND I1.TipLinie &lt;&gt; &apos;T&apos; AND I1.TipLinie &lt;&gt; &apos;G&apos;
          AND I.Subunitatea = nc.subunitatea
        GROUP BY OBJ.CodObiect, Obj.Denumire, ART.CodArticol, NUM1.CodUM1, NUM1.Den_UM1, objasoc.denumire, objasoc.codobiect, Art.TipArticol, num1.paritate
                 ,objasocsec.denumire, objasocsec.codobiect;

      else
        insert into tmp_centralizarenc_man (
          CodArticol,
          CodObiect,
          DenumireAsoc,
          CodObiectAsoc,
          Denumire,
          Facturat,
          UMSec,
          Den_UM1,
          TIPARTICOL,
          paritate,
          DenumireAsocSec,
          CodObiectAsocSec)
        select
          ART.CodArticol,
          OBJ.CodObiect,
          objasoc.denumire,
          nvl(objasoc.codobiect, 0),
          OBJ.Denumire,
          SUM(case when art.tiparticol = 1 then I1.Cant * I1.PU  else i1.Cant end ),
          Num1.CODUM1,
          NUM1.Den_UM1,
          Art.TipArticol,
          num1.paritate,
          objasocsec.denumire,
          nvl(objasocsec.codobiect, 0)
         FROM INTRARI I
             inner join INTRARI1 I1 on i.codintr = i1.codintr
             inner join nartobj OBJ on i1.codobiect = obj.codobiect
             inner join nart ART on OBJ.codarticol = ART.codarticol
             inner join num1 on art.um = num1.codum and nvl(num1.secundara, 0) = 0
             inner join tmp_notecreditfact_man tmp on i.codintr = tmp.coddoc and tmp.tipdoc = i.tipdoc
             left  join nartobj OBJASOC on i1.codobiectorig = objasoc.codobiect
             left  join contract1 c1 on i1.codobiectorig = c1.codcadou
             left  join contract c on c1.codcontract = c.codcontract and c.codcontract = vCodContract
             left  join nartobj OBJASOCSEC on c1.codobiectsec = objasocsec.codobiect
         where I.TipDoc IN (1, 3, 4, 5, 9) AND I.Partener = vCodPart
         AND (I1.CodObiect IN (
                               KArtDiscPrimVol,
                               KArtDiscPrimCant,
                               KArtPenPrimTer,
                               KArtDiscOffInvoiceF) or INSTR(KArtDiscPrimTer, TO_CHAR(I1.CODOBIECT)) &gt; 0) AND I1.TipLinie &lt;&gt; &apos;T&apos; AND I1.TipLinie &lt;&gt; &apos;G&apos;
         AND I.Subunitatea = PKG_GLOBALS.GETSUBUNITATE
         GROUP BY OBJ.CodObiect, Obj.Denumire, ART.CodArticol, NUM1.CodUM1, NUM1.Den_UM1, objasoc.denumire, objasoc.codobiect, Art.TipArticol, num1.paritate,
                 objasocsec.denumire, objasocsec.codobiect;

      end if;
    end if;
  end if;

  UPDATE TMP_CENTRALIZARENC_MAN SET
  PROCTVA = 24
  WHERE PROCTVA IS NULL;

  update tmp_notecredit_man set
    TOTALT     = (select sum(valdoc) from tmp_notecreditt_man),
    TOTALLEIT  = (select sum(vallei) from tmp_notecreditt_man),
    TOTALV     = (select sum(valdoc) from tmp_notecreditv_man),
    TOTALLEIV  = (select sum(vallei) from tmp_notecreditv_man),
    TOTALC     = (select sum(val) from tmp_notecreditc_man),
    TOTALLEIC  = (select sum(vallei) from tmp_notecreditc_man),
    TOTALP     = (select sum(valdoc) from tmp_notecreditp_man),
    TOTALLEIP  = (select sum(vallei) from tmp_notecreditp_man),
    TOTALZ     = (select sum(valdoc) from tmp_notecreditz_man),
    TOTALLEIZ  = (select sum(vallei) from tmp_notecreditz_man),
    TOTALDISCZ = (select sum(discount) from tmp_notecreditz_man);

  end if;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vTrim number(1);
NR NUMBER(20) := 0;
vTipDoc number(20);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodSubunit number(20);
aDataDoc Date;
aDoc varchar2(200);
vAreCorectii number(10);
BEGIN
  select nvl(AreCorectii,0) into vAreCorectii from tmp_notecredit;

  select Trimestriala, TipDoc, CarnetDoc, NrDoc, Subunitatea, to_date(to_char(DataCreare,&apos;dd.mm.yyyy&apos;),&apos;dd.mm.yyyy&apos;), PREFIXDOC||NRDOC||&apos;/&apos;||to_char(DATACREARE, &apos;dd.mm.yyyy&apos;)
  into vTrim, vTipDoc, ACARNETDOC, ANRDOC, aCodSubunit, aDataDoc, aDoc
  from tmp_notecredit;

  if vTrim = 1 then
    delete tmp_notecreditc;
    delete tmp_notecreditp;
    delete tmp_notecreditt;
    delete tmp_notecreditz;
  end if;

  IF Operation = 0 THEN  -- UPDATE
    SELECT  CodNCredit INTO RecId FROM TMP_NOTECREDIT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NOTECREDIT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NOTECREDIT SET ( CodContract2,
                            CodPart,
                            TipDoc,
                            Subunitatea,
                            DataStart,
                            CODCONTV, CODCONTT, CODCONTC, CODCONTP, DataStop, Datafact, TipArticol, Obs, CodContract,
                            Codmoneda, VOLUMPEARTICOLE, CODCONTZ, PRETBRUTC, PRETBRUTV, CODCARNET,
                            Trimestriala, Corectie, CodNCCorectie,
                            PrefixDoc,
                            CarnetDoc,
                            NrDoc,
                            SeriaDoc,
                            Previzionare,
                            IesiriPeVolum,
                            Curs,
                            Inchisa,
                            ValOrigTer, CODANALIZA )
               = ( SELECT CodContract2,
                          CodPart,
                          TipDoc,
                          Subunitatea,
                          DataStart,
                          CODCONTV, CODCONTT, CODCONTC, CODCONTP,DataStop, DataFact, TipArticol, Obs, CodContract,
                          CodMoneda, VOLUMPEARTICOLE, codcontz, PRETBRUTC, PRETBRUTV, CODCARNET,
                          Trimestriala, Corectie, CodNCCorectie,
                          PrefixDoc,
                          CarnetDoc,
                          NrDoc,
                          SeriaDoc,
                          Previzionare,
                          IesiriPeVolum,
                          Curs,
                          Inchisa,
                          ValOrigTer, CODANALIZA
                   FROM TMP_NOTECREDIT )
    WHERE CodNCredit = RecId;

    DELETE TMP_NOTECREDIT1;
    INSERT INTO TMP_NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,PREVIZIONAT,
                                 PROCTVA, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, &apos;T&apos;, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC, PREVIZIONAT,
           PROCTVA, CODANALIZANOD, CODCENTRU
    FROM TMP_NOTECREDITT;

    INSERT INTO TMP_NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC
                                 ,CODNCREDIT1ORIG, PROCTVA, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, &apos;V&apos;, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,
           CODNCREDIT1ORIG, PROCTVA, CODANALIZANOD, CODCENTRU FROM TMP_NOTECREDITV;

    if vAreCorectii &gt; 0 then
      update tmp_notecreditz tmpz
      set
        valoare = valoare - nvl((select sum(nvl(valoare,0) - nvl(valoareold,0)) from notecredit1 where codncredit1orig = tmpz.codncredit1),0);
    end if;

    INSERT INTO TMP_NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS,CODNCREDIT1ORIG,
                                 CODDISCOUNT, VALDOC, VALLEI, PROCTVA, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, &apos;Z&apos;, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODNCREDIT1ORIG,
           CODDISCOUNT, VALDOC, VALLEI, PROCTVA, CODANALIZANOD, CODCENTRU
    FROM TMP_NOTECREDITZ;

    INSERT INTO TMP_NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,
                                                          PROCTVA, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, &apos;C&apos;, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,
           PROCTVA, CODANALIZANOD, CODCENTRU
    FROM TMP_NOTECREDITC;

    INSERT INTO TMP_NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODANALIZANOD, CODCENTRU)
    SELECT CODNCREDIT1, CODNCREDIT, &apos;P&apos;, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODANALIZANOD, CODCENTRU FROM TMP_NOTECREDITP;

    DELETE FROM NOTECREDIT1 NC1 WHERE NC1.CodNCredit = RecId AND NC1.CODNCREDIT1 NOT IN (SELECT CodNCredit1 FROM TMP_NOTECREDIT1);

    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITT) LOOP
      IF NVL(v_rec.CodNCredit1, 0) &gt; 0 THEN
        UPDATE NOTECREDIT1 SET
          TipOper       = &apos;T&apos;,
          Valoare       = v_Rec.Valoare,
          ValoareOld    = v_Rec.ValoareOld,
          ValDif        = v_rec.valdif,
          CodNCredit1Orig = v_Rec.CodNCredit1Orig,
          CodObligStins = v_rec.CodObligStins,
          CodDoc        = v_Rec.CodDoc,
          TipDoc        = v_Rec.TipDoc,
          CodObligStingator = v_rec.CodObligStingator,
          Obs           = v_rec.obs,
          CODCLASEDISC  = V_REC.CODCLASEDISC,
          PREVIZIONAT   = V_REC.PREVIZIONAT,
          Tip           = tncTermen,
          ProcTVA       = v_rec.ProcTVA,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCredit1 = v_rec.CodNCredit1;
      ELSE
        INSERT INTO NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,PREVIZIONAT,
                                 TIP,PROCTVA, CODANALIZANOD, CODCENTRU)
        VALUES (seq_notecredit1_codncredit1.nextval, RecId, &apos;T&apos;, v_rec.VALOARE, v_rec.VALOAREOLD, V_REC.VALDIF, v_rec.CODOBLIGSTINS, v_rec.CODDOC, v_rec.TIPDOC, v_rec.CODOBLIGSTINGATOR, v_rec.Obs,
                V_REC.CODCLASEDISC,V_REC.PREVIZIONAT,tncTermen,v_rec.PROCTVA, v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITV) LOOP
      IF NVL(v_rec.CodNCredit1, 0) &gt; 0 THEN
        UPDATE NOTECREDIT1 SET
          TipOper       = &apos;V&apos;,
          Valoare       = v_Rec.Valoare,
          ValoareOld    = v_Rec.ValoareOld,
          ValDif        = v_rec.valdif,
          CodObligStins = v_rec.CodObligStins,
          CodDoc        = v_Rec.CodDoc,
          TipDoc        = v_Rec.TipDoc,
          CodObligStingator = v_rec.CodObligStingator,
          Obs           = v_rec.obs,
          CODCLASEDISC  = V_REC.CODCLASEDISC,
          Tip           = tncVolum,
          CODNCREDIT1ORIG = V_REC.CODNCREDIT1ORIG,
          ProcTVA       = v_rec.ProcTVA,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCredit1 = v_rec.CodNCredit1;
      ELSE
        INSERT INTO NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,
                                 TIP, CODNCREDIT1ORIG,PROCTVA, CODANALIZANOD, CODCENTRU)
        VALUES (seq_notecredit1_codncredit1.nextval, RecId, &apos;V&apos;, v_rec.VALOARE, v_rec.VALOAREOLD, V_REC.VALDIF, v_rec.CODOBLIGSTINS, v_rec.CODDOC, v_rec.TIPDOC, v_rec.CODOBLIGSTINGATOR, v_rec.Obs,
                V_REC.CODCLASEDISC, tncVolum,V_REC.CODNCREDIT1ORIG,v_rec.proctva, v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITZ) LOOP
      IF NVL(v_rec.CodNCredit1, 0) &gt; 0 THEN
        UPDATE NOTECREDIT1 SET
          TipOper       = &apos;Z&apos;,
          Valoare       = v_Rec.Valoare,
          ValoareOld    = v_Rec.ValoareOld,
          ValDif        = v_rec.valdif,
          CodObligStins = v_rec.CodObligStins,
          CodNCredit1Orig = v_rec.CodNCredit1Orig,
          CodDoc        = v_Rec.CodDoc,
          TipDoc        = v_Rec.TipDoc,
          CodObligStingator = v_rec.CodObligStingator,
          Obs           = v_rec.obs,
          CODCLASEDISC  = V_REC.CODCLASEDISC,
          CODDISCOUNT   = V_REC.CODDISCOUNT,
          VALDOC        = V_REC.VALDOC,
          VALLEI        = V_REC.VALLEI,
          TIP           = tncProvizioane,
          PROCTVA       = V_REC.PROCTVA,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCredit1 = v_rec.CodNCredit1;
      ELSE
        INSERT INTO NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALDIF, VALOAREOLD, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, CODCLASEDISC,CODNCREDIT1ORIG,
                                 CODDISCOUNT, VALDOC, VALLEI,TIP, PROCTVA, CODANALIZANOD, CODCENTRU)
        VALUES (seq_notecredit1_codncredit1.nextval, RecId, &apos;Z&apos;, v_rec.VALOARE, v_rec.VALOAREOLD, V_REC.VALDIF, v_rec.CODOBLIGSTINS, v_rec.CODDOC, v_rec.TIPDOC, v_rec.CODOBLIGSTINGATOR, v_Rec.Obs,
                V_REC.CODCLASEDISC,V_REC.CODNCREDIT1ORIG, V_REC.CODDISCOUNT, V_REC.VALDOC, V_REC.VALLEI, tncProvizioane, V_REC.PROCTVA, v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITC) LOOP
      IF NVL(v_rec.CodNCredit1, 0) &gt; 0 THEN
        UPDATE NOTECREDIT1 SET
          TipOper       = &apos;C&apos;,
          Valoare       = v_Rec.Valoare,
          ValoareOld    = v_Rec.ValoareOld,
          ValDif        = v_rec.valdif,
          CodObligStins = v_rec.CodObligStins,
          CodDoc        = v_Rec.CodDoc,
          TipDoc        = v_Rec.TipDoc,
          CodObligStingator = v_rec.CodObligStingator,
          Obs           = v_rec.obs,
          CODCLASEDISC  = V_REC.CODCLASEDISC,
          TIP           = tncCantitate,
          ProcTVA       = v_rec.ProcTVA,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCredit1 = v_rec.CodNCredit1;
      ELSE
        INSERT INTO NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, CODOBLIGSTINS, CODDOC, TIPDOC, CODOBLIGSTINGATOR, OBS, VALDIF, CODCLASEDISC,
                                 TIP,PROCTVA, CODANALIZANOD, CODCENTRU)
        VALUES (seq_notecredit1_codncredit1.nextval, RecId, &apos;C&apos;, v_rec.VALOARE, v_rec.VALOAREOLD, v_rec.CODOBLIGSTINS, v_rec.CODDOC, v_rec.TIPDOC, v_rec.CODOBLIGSTINGATOR, v_rec.OBS,V_REC.VALDIF,
                V_REC.CODCLASEDISC,tncCantitate,v_rec.proctva, v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITP) LOOP
      IF NVL(v_rec.CodNCredit1, 0) &gt; 0 THEN
        UPDATE NOTECREDIT1 SET
          TipOper       = &apos;P&apos;,
          Valoare       = v_Rec.Valoare,
          ValoareOld    = v_Rec.ValoareOld,
          ValDif        = v_rec.valdif,
          CodObligStins = v_rec.CodObligStins,
          CodDoc        = v_Rec.CodDoc,
          TipDoc        = v_Rec.TipDoc,
          CodObligStingator = v_rec.CodObligStingator,
          Obs           = v_rec.obs,
          Tip           = tncPenalizari,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCredit1 = v_rec.CodNCredit1;
      ELSE
        INSERT INTO NOTECREDIT1 (CODNCREDIT1, CODNCREDIT, TIPOPER, VALOARE, VALOAREOLD, VALDIF, CODOBLIGSTINS, CODDOC,
                                              TIPDOC, CODOBLIGSTINGATOR, OBS, TIP, CODANALIZANOD, CODCENTRU)
        VALUES (seq_notecredit1_codncredit1.nextval, RecId, &apos;P&apos;, v_rec.VALOARE, v_rec.VALOAREOLD, V_REC.VALDIF, v_rec.CODOBLIGSTINS,
                                                            v_rec.CODDOC, v_rec.TIPDOC, v_rec.CODOBLIGSTINGATOR, v_Rec.Obs, tncPenalizari,
                                                            v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    delete from notecreditfact where (codncredit = recid) and (codncfact not in (select codncfact from tmp_notecreditfact));
    FOR v_rec IN (SELECT * FROM TMP_NOTECREDITFACT) LOOP
      IF NVL(v_rec.CodNCFact, 0) &gt; 0 THEN
        UPDATE NOTECREDITFACT SET
          CODDOC     = v_rec.coddoc,
          TIPDOC     = v_Rec.TIPDOC,
          PREFIXDOC  = v_rec.PREFIXDOC,
          NRDOC      = v_Rec.NRDOC,
          DATADOC    = v_Rec.DATADOC,
          VALDOC     = v_Rec.ValDoc,
          VALT       = v_rec.VALT,
          CODDOC1    = V_REC.CODDOC1
        WHERE CodNCFact = v_rec.CodNCFact;
      ELSE
        INSERT INTO NOTECREDITFACT (CODNCFACT, CODNCREDIT, CODDOC, TIPDOC, PREFIXDOC, NRDOC, DATADOC, VALDOC, VALT, CODDOC1)
        VALUES (seq_notecreditfact_CODNCFACT.Nextval, RecId, v_rec.CODDOC, v_rec.TIPDOC, v_rec.PREFIXDOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC,
                v_rec.VALT, V_REC.CODDOC1);
      END IF;
    END LOOP;

    delete from nccadouri where (codncredit = recid) and (codnccadouri not in (select codnccadouri from tmp_nccadouri));
    FOR v_rec IN (SELECT * FROM TMP_NCCadouri) LOOP
      IF NVL(v_rec.CodNCCadouri, 0) &gt; 0 THEN
        UPDATE Nccadouri SET
          Codobiect      = v_rec.Codobiect ,
          Codobiectasoc  = v_rec.Codobiectasoc ,
          Codarticol     = v_rec.Codarticol ,
          Umsec          = v_rec.Umsec ,
          Diferente      = v_rec.Diferente,
          Codobiectasocsec  = v_rec.Codobiectasocsec,
          Cant           = v_Rec.Cant,
          CantFact       = v_Rec.CantFact,
          CODANALIZANOD = v_rec.CODANALIZANOD,
          CODCENTRU  = v_rec.CODCENTRU
        WHERE CodNCCadouri = v_rec.CodNCCadouri;
      ELSE
        INSERT INTO NCCadouri (Codnccadouri, Codncredit, Codobiect, Codobiectasoc, Codarticol, Umsec, Diferente, Codobiectasocsec, Cant, CantFact, CODANALIZANOD, CODCENTRU)
        VALUES (seq_nccadouri_CODNCcadouri.Nextval, RecId, v_rec.Codobiect, v_rec.Codobiectasoc, v_rec.Codarticol, v_rec.Umsec, v_rec.Diferente, v_rec.codobiectasocsec,
        v_Rec.cant, v_rec.cantfact, v_rec.CODANALIZANOD, v_rec.CODCENTRU);
      END IF;
    END LOOP;

    delete from CENTRALIZARENC where (codncredit = recid) and (CODCENTRALIZARE not in (select CODCENTRALIZARE from TMP_CENTRALIZARENC));
    FOR v_rec IN (SELECT * FROM TMP_CENTRALIZARENC) LOOP
      IF NVL(v_rec.CodCentralizare, 0) &gt; 0 THEN
        UPDATE CENTRALIZARENC SET
          CODARTICOL       = V_REC.CODARTICOL,
          CODOBIECT        = V_REC.CODOBIECT,
          CODOBIECTASOC    = V_REC.CODOBIECTASOC,
          CODOBIECTASOCSEC = V_REC.CODOBIECTASOCSEC,
          UMSEC            = V_REC.UMSEC,
          DIFERENTE        = V_REC.DIFERENTE,
          TIPARTICOL       = V_REC.TIPARTICOL,
          FACTURAT         = V_REC.FACTURAT,
          PROCTVA          = V_REC.PROCTVA,
          CODCENTRU        = V_REC.CODCENTRU,
          CODANALIZANOD    = V_REC.CODANALIZANOD,
          OBS              = V_REC.OBS,
          CANT             = V_REC.CANT
        WHERE CodCentralizare = v_rec.CodCentralizare;
      ELSE
        INSERT INTO CENTRALIZARENC (CODCENTRALIZARE, CODNCREDIT, CODARTICOL, CODOBIECT, CODOBIECTASOC, CODOBIECTASOCSEC, UMSEC, DIFERENTE, TIPARTICOL, FACTURAT, PROCTVA,
                                    CODCENTRU, CODANALIZANOD,OBS,CANT)
        values (seq_centralizarenc_CODC.Nextval, recid, v_rec.CODARTICOL, v_rec.CODOBIECT, v_rec.CODOBIECTASOC, v_rec.CODOBIECTASOCSEC, v_rec.UMSEC, v_rec.DIFERENTE, v_rec.TIPARTICOL, V_REC.FACTURAT,
                V_REC.PROCTVA,V_REC.CODCENTRU, V_REC.CODANALIZANOD,V_REC.OBS,V_REC.CANT);
      END IF;
    END LOOP;

-- detail JURNAlL1

  DELETE FROM JURNAl1 WHERE TIPDOC = vTipDoc AND CODDOC = RECID AND CODJURNAL1 NOT IN
  (SELECT CODJURNAL1 FROM TMP_JURNAl1);

  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET
      CODDOC       = V_REC.CODDOC,
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,

      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,

      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      DIRTY         = V_REC.DIRTY,
      SUBUNITATEA   = V_REC.SUBUNITATEA,
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT,
      CODCENTRU = V_REC.CODCENTRU,
      CODANALIZANOD = V_REC.CODANALIZANOD
    WHERE
      CODJURNAL1 = V_REC.CODJURNAl1;
   ELSE
     INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD,
     TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,
      ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
      GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY,
      SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
     VALUES
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,
     V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,
     V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
     V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY,
     V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
   END IF;
  END LOOP;


-- detail JURNAL


    DELETE FROM JURNAL WHERE TIPDOC = vTipDoc AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC,
        INDEXLOCAL = V_REC.INDEXLOCAL,
        CONTD      = V_REC.CONTD,
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE,
        VALOAREV   = V_REC.VALOAREV,
        OBS        = V_REC.OBS,
        AN         = V_REC.AN,
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT,
        CODCENTRU = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD
      WHERE
        CODJURNAL = V_REC.CODJURNAl;
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST,
     VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA,
     DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST,
     V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA,
     V_REC.DATADOC, V_REC.DOCUMENT, V_REC.CODCENTRU, V_REC.CODANALIZANOD);
     END IF;
    END LOOP;

  ELSE

  SELECT Seq_NoteCredit_CodNCredit.NextVal INTO RecId FROM DUAL;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NOTECREDIT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  INSERT INTO NOTECREDIT (CodNCredit,
                          CodContract2,
                          CodPart,
                          TipDoc,
                          Subunitatea,
                          DataStart,
                          CODCONTV, CODCONTT, CODCONTC, CODCONTP,DataStop, An, Luna, DataFact, TipArticol, Obs, CodContract,
                          CodMoneda, VOLUMPEARTICOLE, CODCONTZ, PRETBRUTC, PRETBRUTV, CODCARNET,
                          Trimestriala, Corectie, CodNCCorectie,
                          PrefixDoc,
                          CarnetDoc,
                          NrDoc,
                          SeriaDoc, userid,datacreare,
                          Previzionare,
                          IesiriPeVolum,
                          Curs,
                          Inchisa,
                          ValOrigTer, CODANALIZA)
                   SELECT RecId,
                          tmp.CodContract2,
                          tmp.CodPart,
                          tmp.TipDoc,
                          tmp.Subunitatea,
                          tmp.DataStart,
                          tmp.CODCONTV, tmp.CODCONTT, tmp.CODCONTC, tmp.CODCONTP, tmp.DataStop, tmp.An, tmp.Luna, tmp.DataFact, Tmp.TipArticol, Tmp.obs, TMP.codcontract,
                          TMP.CODMONEDA, tmp.volumpearticole, TMP.CODCONTZ, TMP.PRETBRUTC, TMP.PRETBRUTV, TMP.CODCARNET,
                          TMP.Trimestriala, TMP.Corectie, TMP.CodNCCorectie,
                          TMP.PrefixDoc,
                          TMP.CarnetDoc,
                          TMP.NrDoc,
                          TMP.SeriaDoc, PKG_GLOBALS.USERID,SYSTIMESTAMP,
                          tmp.Previzionare,
                          tmp.Iesiripevolum,
                          TMP.Curs,
                          tmp.Inchisa,
                          tmp.ValOrigTer,
                          tmp.CODANALIZA
                   FROM TMP_NOTECREDIT tmp;

  INSERT INTO NOTECREDIT1 (CodNCredit1,
                           CodNCredit,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           TipOper,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           PREVIZIONAT,
                           TIP,
                           PROCTVA,
                           CODANALIZANOD,
                           CODCENTRU)
                    SELECT SEQ_NOTECREDIT1_CodNCredit1.Nextval,
                           RecId,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           &apos;T&apos;,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           PREVIZIONAT,
                           tncTermen,
                           PROCTVA,
                           CODANALIZANOD,
                           CODCENTRU
                    FROM TMP_NOTECREDITT;
  INSERT INTO NOTECREDIT1 (CodNCredit1,
                           CodNCredit,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           TipOper,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           TIP,
                           CODNCREDIT1ORIG,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU)
                    SELECT SEQ_NOTECREDIT1_CodNCredit1.Nextval,
                           RecId,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           &apos;V&apos;,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           tncVolum,
                           CODNCREDIT1ORIG,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU
                    FROM TMP_NOTECREDITV;
  INSERT INTO NOTECREDIT1 (CodNCredit1,
                           CodNCredit,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           TipOper,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           CODNCREDIT1ORIG,
                           CODDISCOUNT,
                           VALDOC,
                           VALLEI,
                           TIP,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU)
                    SELECT SEQ_NOTECREDIT1_CodNCredit1.Nextval,
                           RecId,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           &apos;Z&apos;,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           CODNCREDIT1ORIG,
                           CODDISCOUNT,
                           VALDOC,
                           VALLEI,
                           tncProvizioane,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU
                    FROM TMP_NOTECREDITZ;
  INSERT INTO NOTECREDIT1 (CodNCredit1,
                           CodNCredit,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           TipOper,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           TIP,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU)
                    SELECT SEQ_NOTECREDIT1_CodNCredit1.Nextval,
                           RecId,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           &apos;C&apos;,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           CODCLASEDISC,
                           tncCantitate,
                           PROCTVA,
                            CODANALIZANOD,
                            CODCENTRU
                    FROM TMP_NOTECREDITC;
  INSERT INTO NOTECREDIT1 (CodNCredit1,
                           CodNCredit,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           TipOper,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           TIP,
                            CODANALIZANOD,
                            CODCENTRU)
                    SELECT SEQ_NOTECREDIT1_CodNCredit1.Nextval,
                           RecId,
                           Valoare,
                           ValoareOld,
                           ValDif,
                           CodObligStins,
                           &apos;P&apos;,
                           CodDoc,
                           TipDoc,
                           CodObligStingator,
                           Obs,
                           tncPenalizari,
                            CODANALIZANOD,
                            CODCENTRU
                    FROM TMP_NOTECREDITP;

  INSERT INTO NOTECREDITFACT (CODNCFACT, CODNCREDIT, CODDOC, TIPDOC, PREFIXDOC, NRDOC, DATADOC, VALDOC, VALT, CODDOC1)
  select seq_notecreditfact_CODNCFACT.Nextval, RecId, CODDOC, TIPDOC, PREFIXDOC, NRDOC, DATADOC, VALDOC, VALT, CODDOC1
  from tmp_notecreditfact;

  INSERT INTO NCCadouri (Codnccadouri, Codncredit, Codobiect, Codobiectasoc, Codarticol, Umsec, Diferente, Codobiectasocsec,
                         Cant, CantFact,
                            CODANALIZANOD,
                            CODCENTRU)
  select seq_nccadouri_CODNCcadouri.Nextval, RecId, Codobiect, Codobiectasoc, Codarticol, Umsec, Diferente, Codobiectasocsec,
  Cant, CantFact,
                            CODANALIZANOD,
                            CODCENTRU from tmp_nccadouri;

  INSERT INTO CENTRALIZARENC (CODCENTRALIZARE, CODNCREDIT, CODARTICOL, CODOBIECT, CODOBIECTASOC, CODOBIECTASOCSEC, UMSEC, DIFERENTE, TIPARTICOL, FACTURAT, PROCTVA,
                              CODCENTRU, CODANALIZANOD,OBS,CANT)
  SELECT seq_centralizarenc_CODC.Nextval, recid, CODARTICOL, CODOBIECT, CODOBIECTASOC, CODOBIECTASOCSEC, UMSEC, DIFERENTE, TIPARTICOL, FACTURAT, PROCTVA,
         CODCENTRU, CODANALIZANOD,OBS,CANT
  FROM TMP_CENTRALIZARENC;

  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD,
  TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE,
   VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD,
  TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE,
  VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD FROM TMP_JURNAL1);



 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
 SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD)
 ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA,
 SUBUNITATEA, DATADOC, DOCUMENT, CODCENTRU, CODANALIZANOD FROM TMP_JURNAL);

  END IF;

  -- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

   SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
   IF NR = 0 THEN
     INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
     VALUES
     (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
   END IF;

   UPDATE NCONTRUL
   SET
     RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
     RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
     RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
   WHERE
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


  IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
    FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
    LOOP
      SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      IF NR = 0 THEN
        INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
        VALUES
        (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
      END IF;

      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
        RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
        RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
        RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
      WHERE
        CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;
  END IF;

  END LOOP;

  PKG_GLOBALS.MarkDirtyJurnal;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;

 NotifyModif(OPERATION, RECID, &apos;CONTRACT&apos;);


  COMMIT;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

procedure GEN_TMP_PEN(
vZileGratie in number,
vDataRef in varchar2,
vIni in number default 0,
vAllPart in number default 1,
vAllMon in number default 1,
sDataRef in varchar2,
vRestZero in number default 0,
vLitigii in number default 0,
AnLunaIni in number) is
dataref date;
aVal number(20,7);
aRest number(20,7);
aIdx number(10);
vAnLunaIni number(20);
begin
  select aninitial*12+lunainitiala into vAnLunaIni from firmaluni;
  if vAnLunaIni = AnLunaIni then
    vAnLunaIni := vAnLunaIni - 1;
  else
    vAnLunaIni := AnLunaIni;
  end if;
  
  delete tmp_gen_penalitati;
  delete tmp_cmd_tmp;

  insert into tmp_cmd_tmp(codobiect,datadoc,tip)
  SELECT CODSTINSPIF, MAX(DATADOC), &apos;DATA_LAST_PLATA&apos;
  FROM
  (
  SELECT T1.DATADOC, S.CODSTINSPIF
  FROM STINGERE S
       INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
       INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
       INNER JOIN TREZOR T ON GS.TIPDOC = T.TIPDOC AND GS.TIPDOC IN (29,30,31)
       INNER JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR AND T1.CODTREZOR1 = GS.CODDOC
  UNION ALL
  SELECT CO.DATADOC, S.CODSTINSPIF
  FROM STINGERE S
       INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
       INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
       INNER JOIN COMPENS CO ON CO.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
  ) GROUP BY CODSTINSPIF;

  insert into tmp_cmd_tmp(codobiect,resta,tip)
  SELECT
    GV.CODDOC,SUM(OV.VALOARE),&apos;VAL210&apos;
  FROM
    OBLIGPIF OV
    INNER JOIN GENERAL GV ON OV.CODGENERAL = GV.CODGENERAL
  WHERE
    OV.SEMNIFICATIE = 210 AND GV.TIPDOC IN (19,21,22,26)
  GROUP BY GV.CODDOC;

  insert into tmp_cmd_tmp(codobiect,resta,tip)
  SELECT CODSTINSPIF, SUM(VALOARE), &apos;STINS&apos;
  FROM STINGERE
  GROUP BY CODSTINSPIF;

  insert into tmp_cmd_tmp(codobiect,resta,tip)
  SELECT S.CODSTINSPIF, SUM(S.VALOARE), &apos;STINS1&apos;
  FROM STINGERE S
  WHERE S.CODSTINGERE &lt; (SELECT MAX(SS.CODSTINGERE) FROM STINGERE SS WHERE SS.CODSTINSPIF = S.CODSTINSPIF)
  GROUP BY S.CODSTINSPIF;

  insert into tmp_cmd_tmp(codobiect,resta,datadoc,tip)
  select I1.CODOBLIGMAJORAT, SUM(I1.PU * I1.CANT),MAX(I.DATADOC),&apos;MAJ&apos;
  FROM IESIRI1 I1, IESIRI I
  WHERE I.ANULAT = 0 AND I.CODIES = I1.CODIES AND I.DATADOC &lt;= to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
  GROUP BY I1.CODOBLIGMAJORAT;

  if PKG_CATEGCONST.GetValConstanta(&apos;MajTermLivr&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) = 2 then
    if vIni &lt;&gt; 1 then
      insert into tmp_gen_penalitati
      SELECT
          O.CODOBLIGPIF,
          I.PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          I.VALDOC,
          NVL((SELECT MIN(DATALIVR) FROM LIVR L WHERE L.CODIES = I.CODIES), I.DATADOC) + TRUNC(O.TERMEN - I.DATADOC) AS TERMEN,
          O.VALOARE - COALESCE(TMP210.RESTA,0) - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          I.CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          NVL(I.GRATIE,0),
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codies,
          i.tipdoc,
          i.seriadoc
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          IESIRI I
          LEFT JOIN TMP_CMD_TMP TMP210 ON TMP210.CODOBIECT = I.CODIES AND TMP210.TIP = &apos;VAL210&apos;
          LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 200
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = I.TIPDOC
          AND NVL(I.ANULAT, 0) = 0
          AND NVL(I.TIPFACTURA,0) &lt;&gt; 15
          AND G.CODDOC     = I.CODIES
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND NVL((SELECT MIN(DATALIVR) FROM LIVR L WHERE L.CODIES = I.CODIES), I.DATADOC) + TRUNC(O.TERMEN - I.DATADOC) + case when nvl(i.gratie,0) = 0 then vZileGratie else i.gratie end &lt; to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(I.CODMONETAR,0) = 0 AND P.CODPART = I.PARTENER
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
          /*AND NOT EXISTS (SELECT SS.CODSTINGERE
                          FROM STINGERE SS
                               INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                               INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                          WHERE SS.CODSTINSPIF = O.CODOBLIGPIF AND GST.TIPDOC = 16)*/

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1301
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1303
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND vLitigii = 1
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          I.PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          I.VALDOC,
          NVL((SELECT MIN(DATALIVR) FROM LIVR L WHERE L.CODIES = I.CODIES), I.DATADOC) + TRUNC(O.TERMEN - I.DATADOC) AS TERMEN,
          O.VALOARE - COALESCE(TMP210.RESTA,0) - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          I.CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          NVL(I.GRATIE,0),
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codies,
          i.tipdoc,
          i.seriadoc
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          IESIRI I
          LEFT JOIN TMP_CMD_TMP TMP210 ON TMP210.CODOBIECT = I.CODIES AND TMP210.TIP = &apos;VAL210&apos;
          LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 200 AND P.CODPART = I.PARTENER
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = I.TIPDOC
          AND NVL(I.ANULAT, 0) = 0
          AND NVL(I.TIPFACTURA,0) &lt;&gt; 15
          AND NVL(I.ANULAT, 0) = 0
          AND G.CODDOC     = I.CODIES
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND NVL((SELECT MIN(DATALIVR) FROM LIVR L WHERE L.CODIES = I.CODIES), I.DATADOC) + TRUNC(O.TERMEN - I.DATADOC) + case when nvl(i.gratie,0) = 0 then vZileGratie else i.gratie end &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(I.CODMONETAR,0) = 0
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
          /*AND NOT EXISTS (SELECT SS.CODSTINGERE
                          FROM STINGERE SS
                               INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                               INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                          WHERE SS.CODSTINSPIF = O.CODOBLIGPIF AND GST.TIPDOC = 16)*/

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1301
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1303
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND vLitigii = 1
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
    end if;
  else
    if vIni &lt;&gt; 1 then
      insert into tmp_gen_penalitati
      SELECT
          O.CODOBLIGPIF,
          I.PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          I.VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMP210.RESTA,0) - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          I.CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          NVL(I.GRATIE,0),
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codies,
          i.tipdoc,
          i.seriadoc
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          IESIRI I
          LEFT JOIN TMP_CMD_TMP TMP210 ON TMP210.CODOBIECT = I.CODIES AND TMP210.TIP = &apos;VAL210&apos;
          LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 200 AND P.CODPART = I.PARTENER
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = I.TIPDOC
          AND NVL(I.TIPFACTURA,0) &lt;&gt; 15
          AND G.CODDOC     = I.CODIES
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + case when nvl(i.gratie,0) = 0 then vZileGratie else i.gratie end &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(I.CODMONETAR,0) = 0
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
          /*AND NOT EXISTS (SELECT SS.CODSTINGERE
                          FROM STINGERE SS
                               INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                               INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                          WHERE SS.CODSTINSPIF = O.CODOBLIGPIF AND GST.TIPDOC = 16)*/
        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1301
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS ON TMPS.CODOBIECT = O.CODOBLIGPIF AND TMPS.TIP = &apos;STINS&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1303
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND vLitigii = 1
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          I.PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          I.VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMP210.RESTA,0) - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          I.CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          NVL(I.GRATIE,0),
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codies,
          i.tipdoc,
          i.seriadoc
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          IESIRI I
          LEFT JOIN TMP_CMD_TMP TMP210 ON TMP210.CODOBIECT = I.CODIES AND TMP210.TIP = &apos;VAL210&apos;
          LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 200 AND P.CODPART = I.PARTENER
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = I.TIPDOC
          AND NVL(I.TIPFACTURA,0) &lt;&gt; 15
          AND G.CODDOC     = I.CODIES
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + case when nvl(i.gratie,0) = 0 then vZileGratie else i.gratie end &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(I.CODMONETAR,0) = 0
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
          /*AND NOT EXISTS (SELECT SS.CODSTINGERE
                          FROM STINGERE SS
                               INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                               INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                          WHERE SS.CODSTINSPIF = O.CODOBLIGPIF AND GST.TIPDOC = 16)*/
        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1301
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND COALESCE(P.FARAPENALIZARI,0) = 0;

        insert into tmp_gen_penalitati
        SELECT
          O.CODOBLIGPIF,
          &apos;COMP&apos; PREFIXDOC,
          I.NRDOC,
          I.DATADOC,
          O.REST VALDOC,
          O.TERMEN,
          O.VALOARE - COALESCE(TMPS1.RESTA,0) AS REST,
          O.MAJORARI AS MAJORARI,
          0 AS PRELUAT,
          A.OBS AS LOCATIE,
          P.DEN_PART,
          P.CODPART,
          A.CODAGENDA CODLOCATIE,
          S.DEN_SUBUNIT,
          G.MONEDA,
          COALESCE(CFA.COD_CODFISCAL,CFP.COD_CODFISCAL) CODFISCAL,
          COALESCE(TMPJ.RESTA,0) AS MAJANTERIOARE,
          TMPJ.DATADOC AS DATA_LAST_FACTMAJ,
          TMP.DATADOC DATA_LAST_PLATA,
          O.REST,
          O.VALOARE,
          0,
          0,
          P.SCADENTAV,
          0,
          0,
          0,
          O.VALOARE,
          i.codcompens,
          28,
          &apos;&apos;
        FROM
          OBLIGPIF O
          LEFT JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT = O.CODOBLIGPIF AND TMP.TIP = &apos;DATA_LAST_PLATA&apos;
          LEFT JOIN TMP_CMD_TMP TMPS1 ON TMPS1.CODOBIECT = O.CODOBLIGPIF AND TMPS1.TIP = &apos;STINS1&apos;
          LEFT JOIN TMP_CMD_TMP TMPJ ON TMPJ.CODOBIECT = O.CODOBLIGPIF AND TMPJ.TIP = &apos;MAJ&apos;,
          GENERAL G,
          COMPENS I,
          NPART P
          LEFT JOIN NPARTCODFISC CFP ON P.CODPART = CFP.CODPART AND CFP.PRINCIPAL = 1,
          NAGENDA A
          LEFT JOIN NPARTCODFISC CFA ON A.COD_CODFISCAL = CFA.COD_CODFISCAL,
          NSUBUNIT S
        WHERE
          O.SEMNIFICATIE   = 1303
          AND I.CODCOMPENS = G.CODDOC
          AND P.CODPART = O.CODPART
          AND P.CODPART = A.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7
          AND G.CODGENERAL = O.CODGENERAL
          AND G.TIPDOC     = 28
          AND NVL(O.MAJORARI, 0) &lt;&gt; 0
          AND O.REST = 0 and O.VALOARE &gt; 0 AND I.AN*12+I.LUNA &gt;= vANLUNAINI
          AND O.TERMEN + vZileGratie &lt;  to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
          AND S.CODSUBUNIT = I.SUBUNITATEA
          AND (vAllPart = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODPART&apos; and tmp.valoare = p.codpart))
          AND (vAllMon = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;CODMONEDA&apos; and tmp.valoare = g.moneda))
          AND vLitigii = 1
          AND COALESCE(P.FARAPENALIZARI,0) = 0;
    end if;
  end if;

  update tmp_gen_penalitati tmp
  set
    storno =
    (
      select sum(case when o.semnificatie = 200 then o.rest else - o.rest end)
      from obligpif o
      where o.codpart = tmp.codpart and o.rest &lt;&gt; 0
            and o.termen &lt; to_date(vDataRef,&apos;dd.mm.yyyy&apos;) and ((o.valoare &lt; 0 and o.semnificatie = 200) or o.semnificatie in (210,410))
    );

  UPDATE tmp_gen_penalitati tmp
  SET SCADENTAV = (SELECT P1.SCADENTAV FROM NPART1 P1 WHERE P1.CODPART = TMP.CODPART AND PKG_GLOBALS.AnLunaLucru BETWEEN P1.ALStart AND p1.ALStop)
  WHERE NVL(TMP.SCADENTAV,0) = 0;

  delete tmp_gen_penalitati_man;
  insert into tmp_gen_penalitati_man select * from tmp_gen_penalitati;

  aIdx := 0;
  FOR V_REC IN (SELECT tmp.coddoc, tmp.tipdoc, tmp.CODOBLIGPIF,tmp.PREFIXDOC,tmp.NRDOC,tmp.DATADOC,tmp.VALDOC,tmp.TERMEN,tmp.REST,tmp.MAJORARI,tmp.PRELUAT,tmp.LOCATIE,
                tmp.DEN_PART,tmp.CODPART,tmp.CODLOCATIE,tmp.DEN_SUBUNIT,tmp.MONEDA,tmp.CODFISCAL,tmp.MAJANTERIOARE,tmp.DATA_LAST_FACTMAJ,
                tmp.DATA_LAST_PLATA,tmp.RESTOBLIG,tmp.VALOBLIG,tmp.GRATIEDOC,tmp.STORNO,tmp.SCADENTAV,tmp.VALMAJ, tmp.seriadoc
                FROM tmp_gen_penalitati_man tmp
                where tmp.restoblig &gt; 0) LOOP
    delete tmp_gen_penalitati where codobligpif = v_rec.codobligpif;
    aVal := 0;
    aRest := v_rec.valoblig;

    dataref := v_rec.termen;
    FOR V_TMP IN (SELECT CODOBLIGPIF, DATADOC, VALOARE, DATAPEN, DATAGEN
                  FROM (
                  SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, T1.DATADOC, s.valoare, null datapen, T1.DATADOC DATAGEN
                  FROM STINGERE S
                       INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                       INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                       INNER JOIN TREZOR T ON GS.TIPDOC = T.TIPDOC AND GS.TIPDOC IN (29,30,31)
                       INNER JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR AND T1.CODTREZOR1 = GS.CODDOC
                  WHERE s.codstinspif = v_rec.codobligpif AND T1.DATADOC &lt;= to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
                  UNION ALL
                  SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, CO.DATADOC, s.valoare, null datapen, CO.DATADOC DATAGEN
                  FROM STINGERE S
                       INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                       INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                       INNER JOIN COMPENS CO ON CO.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
                  WHERE s.codstinspif = v_rec.codobligpif AND CO.DATADOC &lt;= to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
                  UNION ALL
                  SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, NULL DATADOC, i.valdoc-i.tvadoc valoare, coalesce(i1.termencontract,I.DATADOC) DATAPEN, coalesce(i1.termencontract,I.DATADOC) DATAGEN
                  FROM IESIRI1 I1
                       INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND NVL(I.ANULAT, 0) = 0
                  WHERE I1.CODOBLIGMAJORAT = v_rec.CODOBLIGPIF AND COALESCE(I.CODMONETAR,0) = 0
                  UNION ALL
                  SELECT V_REC.CODOBLIGPIF CODOBLIGPIF, I.DATADOC, SS.valoare, null datapen, I.DATADOC DATAGEN
                  FROM STINGERE SS
                       INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                       INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                       INNER JOIN IESIRI I ON I.CODIES = GST.CODDOC AND I.TIPDOC = GST.TIPDOC
                  WHERE SS.CODSTINSPIF = V_REC.CODOBLIGPIF AND GST.TIPDOC = 16 AND I.DATADOC &lt;= to_date(vDataRef,&apos;dd.mm.yyyy&apos;)
                  )
                  ORDER BY DATAGEN
                 ) LOOP
      if not v_tmp.datapen is null then dataref := v_tmp.datapen; end if;
      if v_tmp.datapen is null then
        if v_tmp.datadoc &gt; v_rec.termen then
          aIdx := aIdx + 1;
          insert into tmp_gen_penalitati (
          CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
          DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
          DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE, CODUNIC, CODDOC, TIPDOC,Seriadoc
          )
          values (
          v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
          v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
          v_tmp.DATAGEN,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST, 2),v_tmp.datadoc - dataref,
          AIDX, v_rec.coddoc, v_rec.tipdoc, V_REC.SERIADOC
          );
          --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST, 2);
          dataref := v_tmp.datadoc;
        end if;
        aRest := aRest - v_tmp.valoare;
      else
        --corectez precedentele
        aVal := v_tmp.valoare;
        for v_xxx in (select * from tmp_gen_penalitati where codobligpif = v_rec.codobligpif AND DATADOC &lt;= V_TMP.DATAPEN order by datadoc) loop
          if aVal &gt; v_xxx.valmaj then
            update tmp_gen_penalitati SET VALMAJ = 0 WHERE CODUNIC = V_XXX.CODUNIC;
            AVAL := AVAL - V_XXX.VALMAJ;
          else
            update tmp_gen_penalitati SET VALMAJ = VALMAJ - AVAL WHERE CODUNIC = V_XXX.CODUNIC;
            AVAL := 0;
          end if;
          IF AVAL &lt;= 0 THEN EXIT; END IF;
        end loop;
      end if;

      --ROUND((MAJORARI / 100) * (&apos; + SDATAREF + &apos; - NVL(DATA_LAST_FACTMAJ, TERMEN)) * REST, 2)
    END LOOP;
    --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2);
    --update TMP_GEN_PENALITATI set valmaj = aVal where codobligpif = v_rec.codobligpif;
    if aRest &lt; 0.01 then aRest := 0; end if;
    if to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref &gt; 0 then
      aIdx := aIdx + 1;
      insert into tmp_gen_penalitati (
      CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
      DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
      DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODUNIC,CODDOC,TIPDOC,SERIADOC
      )
      values (
      v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
      v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
      to_date(sDataRef,&apos;dd.mm.yyyy&apos;),v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST,2),to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref,
      AIDX,v_rec.CODDOC,v_rec.TIPDOC,V_REC.SERIADOC
      );
    end if;
  END LOOP;

  delete tmp_gen_penalitati_man where trunc(data_last_plata) &lt;= trunc(termen) and restoblig = 0;
  commit;

  if vRestZero = 1 then
    FOR V_REC IN (SELECT rownum nr, tmp.coddoc,tmp.tipdoc,tmp.CODOBLIGPIF,tmp.PREFIXDOC,tmp.NRDOC,tmp.DATADOC,tmp.VALDOC,tmp.TERMEN,tmp.REST,tmp.MAJORARI,tmp.PRELUAT,tmp.LOCATIE,
                  tmp.DEN_PART,tmp.CODPART,tmp.CODLOCATIE,tmp.DEN_SUBUNIT,tmp.MONEDA,tmp.CODFISCAL,tmp.MAJANTERIOARE,tmp.DATA_LAST_FACTMAJ,
                  tmp.DATA_LAST_PLATA,tmp.RESTOBLIG,tmp.VALOBLIG,tmp.GRATIEDOC,tmp.STORNO,tmp.SCADENTAV,tmp.VALMAJ,TMP.SERIADOC
                  FROM tmp_gen_penalitati_man tmp where tmp.restoblig = 0) LOOP
      delete tmp_gen_penalitati where codobligpif = v_rec.codobligpif;
      aVal := 0;
      aRest := v_rec.valoblig;

      dataref := v_rec.termen;
      FOR V_TMP IN (SELECT CODOBLIGPIF, DATADOC, VALOARE, DATAPEN, DATAGEN
                    FROM (
                    SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, T1.DATADOC, s.valoare, NULL DATAPEN, T1.DATADOC DATAGEN
                    FROM STINGERE S
                         INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                         INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                         INNER JOIN TREZOR T ON GS.TIPDOC = T.TIPDOC AND GS.TIPDOC IN (29,30,31)
                         INNER JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR AND T1.CODTREZOR1 = GS.CODDOC
                    WHERE S.CODSTINSPIF = v_rec.CODOBLIGPIF
                    UNION ALL
                    SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, CO.DATADOC, s.valoare, NULL DATAPEN, CO.DATADOC DATAGEN
                    FROM STINGERE S
                         INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                         INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                         INNER JOIN COMPENS CO ON CO.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
                    WHERE S.CODSTINSPIF = v_rec.CODOBLIGPIF
                    UNION ALL
                    SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, NULL DATADOC, i.valdoc-i.tvadoc valoare, coalesce(i1.termencontract,I.DATADOC) DATAPEN, coalesce(i1.termencontract,I.DATADOC) DATAGEN
                    FROM IESIRI1 I1
                         INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND NVL(I.ANULAT, 0) = 0
                    WHERE I1.CODOBLIGMAJORAT = v_rec.CODOBLIGPIF AND COALESCE(I.CODMONETAR,0) = 0
                    UNION ALL
                    SELECT V_REC.CODOBLIGPIF CODOBLIGPIF, I.DATADOC, SS.valoare, null datapen, I.DATADOC DATAGEN
                    FROM STINGERE SS
                         INNER JOIN OBLIGPIF OST ON OST.CODOBLIGPIF = SS.CODSTINGATORPIF
                         INNER JOIN GENERAL GST ON OST.CODGENERAL = GST.CODGENERAL
                         INNER JOIN IESIRI I ON I.CODIES = GST.CODDOC AND I.TIPDOC = GST.TIPDOC
                    WHERE SS.CODSTINSPIF = V_REC.CODOBLIGPIF AND GST.TIPDOC = 16
                         )
                     ORDER BY DATAGEN
                   ) LOOP
        if not v_tmp.datapen is null then dataref := v_tmp.datapen; end if;
        if v_tmp.datapen is null then
          if v_tmp.datadoc &gt; v_rec.termen then
            if v_tmp.datadoc &gt; to_date(vDataRef,&apos;dd.mm.yyyy&apos;) then
              aIdx := aIdx + 1;
              insert into tmp_gen_penalitati (
              CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
              DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
              DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODUNIC,CODDOC,TIPDOC,SERIADOC
              )
              values (
              v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
              v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
              v_tmp.DATAGEN,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2),to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref,AIDX,
              v_rec.coddoc,v_rec.tipdoc,V_REC.SERIADOC
              );
              aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2);
              dataref := to_date(vDataRef,&apos;dd.mm.yyyy&apos;);
            else
              aIdx := aIdx + 1;
              insert into tmp_gen_penalitati (
              CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
              DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
              DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODUNIC,CODDOC,TIPDOC,SERIADOC
              )
              values (
              v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
              v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
              v_tmp.DATAGEN,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST,2),v_tmp.datadoc - dataref,AIDX,
              V_REC.CODDOC,V_REC.TIPDOC,V_REC.SERIADOC
              );
              --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST, 2);
              dataref := v_tmp.datadoc;
            end if;
            aRest := aRest - v_tmp.valoare;
          else
            aRest := aRest - v_tmp.valoare;
          end if;
        else
          --corectez precedentele
          aVal := v_tmp.valoare;
          for v_xxx in (select * from tmp_gen_penalitati where codobligpif = v_rec.codobligpif AND DATADOC &lt;= V_TMP.DATAPEN order by datadoc) loop
            if aVal &gt; v_xxx.valmaj then
              update tmp_gen_penalitati SET VALMAJ = 0 WHERE CODUNIC = V_XXX.CODUNIC;
              AVAL := AVAL - V_XXX.VALMAJ;
            else
              update tmp_gen_penalitati SET VALMAJ = VALMAJ - AVAL WHERE CODUNIC = V_XXX.CODUNIC;
              AVAL := 0;
            end if;
            IF AVAL &lt;= 0 THEN EXIT; END IF;
          end loop;
        end if;
        --ROUND((MAJORARI / 100) * (&apos; + SDATAREF + &apos; - NVL(DATA_LAST_FACTMAJ, TERMEN)) * REST, 2)
      END LOOP;
      --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2);
      --update TMP_GEN_PENALITATI set valmaj = aVal where codobligpif = v_rec.codobligpif;
      if aRest &lt; 0.01 then aRest := 0; end if;
      if to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref &gt; 0 then
        aIdx := aIdx + 1;
        insert into tmp_gen_penalitati (
        CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
        DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
        DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODDOC,TIPDOC,SERIADOC
        )
        values (
        v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
        v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
        to_date(sDataRef,&apos;dd.mm.yyyy&apos;),v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST,2),to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref,
        V_REC.CODDOC,V_REC.TIPDOC,V_REC.SERIADOC
        );
      end if;
    END LOOP;
  end if;

  DELETE tmp_gen_penalitati WHERE VALMAJ = 0;
  UPDATE TMP_GEN_PENALITATI TMP
  SET
    RESTLADATA =
    (SELECT O.VALOARE -
            NVL
            (
              (SELECT
                 NVL(SUM(S.VALOARE), 0)
               FROM STINGERE S
                    INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                    INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                    INNER JOIN TREZOR T ON GS.TIPDOC = T.TIPDOC AND GS.TIPDOC IN (29,30,31)
                    INNER JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR AND T1.CODTREZOR1 = GS.CODDOC
               WHERE S.CODSTINSPIF = TMP.CODOBLIGPIF AND T1.DATADOC &lt;= DATAREF
            ), 0)-
            NVL
            (
              (SELECT
                 NVL(SUM(S.VALOARE), 0)
               FROM STINGERE S
                    INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                    INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                    INNER JOIN COMPENS CO ON CO.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
               WHERE S.CODSTINSPIF = TMP.CODOBLIGPIF AND CO.DATADOC &lt;= DATAREF
            ), 0)
     FROM OBLIGPIF O
     WHERE O.CODOBLIGPIF = TMP.CODOBLIGPIF
    );
  commit;
  /*
  alter table tmp_gen_penalitati add
(
  storno number(20,7)
);*/
end;

PROCEDURE TEST1 AS
BEGIN
  delete tmp_manevra_liste;
  --insert into tmp_manevra_liste(filtru,valoare)
  --values(&apos;CODPART&apos;,240);
  commit;

  pkg_globals.SetLunaLucru_SIMPLA(2022,5);

  GEN_TMP_PEN(
  5,
  &apos;26.05.2022&apos;,
  0,
  1,
  1,
  &apos;26.05.2022&apos;,
  1,
  1,
  2022*12+5);
END;


procedure test is
aVal number(20,7);
aRest number(20,7);
dataref date;
sDataRef varchar2(10);
vdataref date;
aIdx number(5);
begin
  MAKE_MANEVRA_T(109);
  commit;
  aVal := pkg_notecredit.GETDISCTERMENFURN(&apos;30.06.2020&apos;, 0, 109, 7194, 545);
  /*delete tmp_gen_penalitati_man;
  insert into tmp_gen_penalitati_man select * from tmp_gen_penalitati;
  commit;
  sDataRef := &apos;25.06.2019&apos;;
  vdataref := to_date(&apos;25.06.2019&apos;,&apos;dd.mm.yyyy&apos;);
  aIdx := 0;
  FOR V_REC IN (SELECT tmp.CODOBLIGPIF,tmp.PREFIXDOC,tmp.NRDOC,tmp.DATADOC,tmp.VALDOC,tmp.TERMEN,tmp.REST,tmp.MAJORARI,tmp.PRELUAT,tmp.LOCATIE,
                  tmp.DEN_PART,tmp.CODPART,tmp.CODLOCATIE,tmp.DEN_SUBUNIT,tmp.MONEDA,tmp.CODFISCAL,tmp.MAJANTERIOARE,tmp.DATA_LAST_FACTMAJ,
                  tmp.DATA_LAST_PLATA,tmp.RESTOBLIG,tmp.VALOBLIG,tmp.GRATIEDOC,tmp.STORNO,tmp.SCADENTAV,tmp.VALMAJ
                  FROM tmp_gen_penalitati_man tmp where tmp.restoblig = 0) LOOP
      delete tmp_gen_penalitati where codobligpif = v_rec.codobligpif;
      aVal := 0;
      aRest := v_rec.valoblig;

      dataref := v_rec.termen;
      FOR V_TMP IN (SELECT CODOBLIGPIF, DATADOC, VALOARE, DATAPEN, DATAGEN
                    FROM (
                    SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, COALESCE(T1.DATADOC,CO.DATADOC) DATADOC, s.valoare, NULL DATAPEN, COALESCE(T1.DATADOC,CO.DATADOC) DATAGEN
                    FROM STINGERE S
                         INNER JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
                         INNER JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
                         LEFT JOIN TREZOR T ON GS.TIPDOC = T.TIPDOC AND GS.TIPDOC IN (29,30,31)
                         LEFT JOIN TREZOR1 T1 ON T.CODTREZOR = T1.CODTREZOR AND T1.CODTREZOR1 = GS.CODDOC
                         LEFT JOIN COMPENS CO ON CO.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
                    WHERE S.CODSTINSPIF = v_rec.CODOBLIGPIF
                    UNION ALL
                    SELECT v_rec.CODOBLIGPIF CODOBLIGPIF, NULL DATADOC, i.valdoc-i.tvadoc valoare, coalesce(i1.termencontract,I.DATADOC) DATAPEN, I.DATADOC DATAGEN
                    FROM IESIRI1 I1
                         INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
                    WHERE I1.CODOBLIGMAJORAT = v_rec.CODOBLIGPIF
                         )
                     ORDER BY DATAGEN
                   ) LOOP
        if not v_tmp.datapen is null then dataref := v_tmp.datapen; end if;
        if v_tmp.datapen is null then
          if v_tmp.datadoc &gt; v_rec.termen then
            if v_tmp.datadoc &gt; to_date(vDataRef,&apos;dd.mm.yyyy&apos;) then
              aIdx := aIdx + 1;
              insert into tmp_gen_penalitati (
              CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
              DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
              DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODUNIC
              )
              values (
              v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
              v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
              v_rec.DATA_LAST_PLATA,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2),to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref,AIDX
              );
              aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (to_date(vDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2);
              dataref := to_date(vDataRef,&apos;dd.mm.yyyy&apos;);
            else
              aIdx := aIdx + 1;
              insert into tmp_gen_penalitati (
              CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
              DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
              DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE,CODUNIC
              )
              values (
              v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
              v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
              v_rec.DATA_LAST_PLATA,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST,2),v_tmp.datadoc - dataref,AIDX
              );
              --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (v_tmp.datadoc - dataref) * aREST, 2);
              dataref := v_tmp.datadoc;
            end if;
            aRest := aRest - v_tmp.valoare;
          else
            aRest := aRest - v_tmp.valoare;
          end if;
        else
          --corectez precedentele
          aVal := v_tmp.valoare;
          for v_xxx in (select * from tmp_gen_penalitati where codobligpif = v_rec.codobligpif AND DATADOC &lt;= V_TMP.DATAPEN order by datadoc) loop
            if aVal &gt; v_xxx.valmaj then
              update tmp_gen_penalitati SET VALMAJ = 0 WHERE CODUNIC = V_XXX.CODUNIC;
              AVAL := AVAL - V_XXX.VALMAJ;
            else
              update tmp_gen_penalitati SET VALMAJ = VALMAJ - AVAL WHERE CODUNIC = V_XXX.CODUNIC;
              AVAL := 0;
            end if;
            IF AVAL &lt;= 0 THEN EXIT; END IF;
          end loop;
        end if;
        --ROUND((MAJORARI / 100) * (&apos; + SDATAREF + &apos; - NVL(DATA_LAST_FACTMAJ, TERMEN)) * REST, 2)
      END LOOP;
      --aVal := aVal + ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST, 2);
      --update TMP_GEN_PENALITATI set valmaj = aVal where codobligpif = v_rec.codobligpif;
      if to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref &gt; 0 then
        aIdx := aIdx + 1;
        insert into tmp_gen_penalitati (
        CODOBLIGPIF,PREFIXDOC,NRDOC,DATADOC,VALDOC,TERMEN,REST,MAJORARI,PRELUAT,LOCATIE,
        DEN_PART,CODPART,CODLOCATIE,DEN_SUBUNIT,MONEDA,CODFISCAL,MAJANTERIOARE,DATA_LAST_FACTMAJ,
        DATA_LAST_PLATA,RESTOBLIG,VALOBLIG,GRATIEDOC,STORNO,SCADENTAV,VALMAJ,ZILE
        )
        values (
        v_rec.CODOBLIGPIF,v_rec.PREFIXDOC,v_rec.NRDOC,v_rec.DATADOC,v_rec.VALDOC,v_rec.TERMEN,aRest,v_rec.MAJORARI,v_rec.PRELUAT,v_rec.LOCATIE,
        v_rec.DEN_PART,v_rec.CODPART,v_rec.CODLOCATIE,v_rec.DEN_SUBUNIT,v_rec.MONEDA,v_rec.CODFISCAL,v_rec.MAJANTERIOARE,v_rec.DATA_LAST_FACTMAJ,
        v_rec.DATA_LAST_PLATA,v_rec.RESTOBLIG,v_rec.VALOBLIG,v_rec.GRATIEDOC,v_rec.STORNO,v_rec.SCADENTAV,ROUND((v_rec.MAJORARI / 100) * (to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref) * aREST,2),to_date(sDataRef,&apos;dd.mm.yyyy&apos;) - dataref
        );
      end if;
    END LOOP;
  commit;
  */
end;

function CHECK_NC_FACT(aCodDoc in number, aCodDoc1 in number, aTipDoc in number, aCodNC in number) return number is
vCodDoc number(20);
aCount  number(20);
begin
  if aCodDoc1 &gt; 0 then
    if aTipDoc = 1 then
      begin
        select codintr into vCodDoc from intrari1 where codintr1 = aCodDoc1;
      exception when others then vCodDoc := -1;
      end;
      if vCodDoc &lt;= 0 then 
        -- document neindentificat dar totusi caut pe linii
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc1 = acoddoc1 and tipdoc = atipdoc;
        if aCount &gt;= 1 then
          return aCount;
        end if;
      else
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc = vCodDoc and tipdoc = atipdoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
        select count(*) into aCount 
        from notecreditfact ncf
             inner join intrari1 i1 on i1.codintr1 = ncf.coddoc1
        where ncf.tipdoc = aTipDoc and i1.codintr = vCodDoc and ncf.codncredit &lt;&gt; aCodNC;
        if aCount &gt; 0 then
          return aCount;
        end if;
      end if;
    else
      begin
        select codies into vCodDoc from iesiri1 where codies1 = aCodDoc1;
      exception when others then vCodDoc := -1;
      end;
      if vCodDoc &lt;= 0 then 
        -- document neindentificat dar totusi caut pe linii
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc1 = acoddoc1 and tipdoc = atipdoc;
        if aCount &gt;= 1 then
          return aCount;
        end if;
      else
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc = vCodDoc and tipdoc = atipdoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
        select count(*) into aCount 
        from notecreditfact ncf
             inner join iesiri1 i1 on i1.codies1 = ncf.coddoc1
        where ncf.tipdoc = aTipDoc and i1.codies = vCodDoc and ncf.codncredit &lt;&gt; aCodNC;
        if aCount &gt; 0 then
          return aCount;
        end if;
      end if;
    end if;
  else
    if aTipDoc = 1 then
      vCodDoc := aCodDoc;
      if vCodDoc &lt;= 0 then 
        -- document neindentificat dar totusi caut pe linii
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc1 = acoddoc1 and tipdoc = atipdoc;
        if aCount &gt;= 1 then
          return aCount;
        end if;
      else
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc = vCodDoc and tipdoc = atipdoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
        select count(*) into aCount 
        from notecreditfact ncf
             inner join intrari1 i1 on i1.codintr1 = ncf.coddoc1
        where ncf.tipdoc = aTipDoc and i1.codintr = vCodDoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
      end if;
    else
      vCodDoc := aCodDoc;
      if vCodDoc &lt;= 0 then 
        -- document neindentificat dar totusi caut pe linii
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc1 = acoddoc1 and tipdoc = atipdoc;
        if aCount &gt;= 1 then
          return aCount;
        end if;
      else
        select count(*) into aCount from notecreditfact where codncredit &lt;&gt; aCodNC and coddoc = vCodDoc and tipdoc = atipdoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
        select count(*) into aCount 
        from notecreditfact ncf
             inner join iesiri1 i1 on i1.codies1 = ncf.coddoc1
        where ncf.tipdoc = aTipDoc and i1.codies = vCodDoc;
        if aCount &gt; 0 then
          return aCount;
        end if;
      end if;
    end if;
  end if;
  return 0;
end;

end pkg_notecredit;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43CE2A2AD9FF7C79D6DC63BC73405BE189502807</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NPARTRETAIL is

 PROCEDURE CLEAR_PART_TABLES
 IS
 BEGIN
    DELETE TMP_MANEVRA;
    DELETE TMP_NPART;
    DELETE TMP_NPART1;
    DELETE TMP_NPARTCODFISC;
    DELETE TMP_NPARTTR;
    DELETE TMP_NPARTDISC;
    DELETE TMP_NPARTB;
    DELETE TMP_NAGENDA;
    DELETE TMP_NLOCALIT;
 END;

 PROCEDURE PREPARE_PART_BAZA_FOR_SYNC(aCODPOSTRETAIL IN NUMBER) -- SE EXECUTE PA BAZA. PREGATESTE PARTENERII NESINCRONIZATI AUTOMAT BAZA-&gt;RETAIL PENTRU PRELUARE
 IS
 BEGIN

    DELETE TMP_MANEVRA;
    DELETE TMP_NPART;
    DELETE TMP_NPART1;
    DELETE TMP_NPARTCODFISC;
    DELETE TMP_NPARTTR;
    DELETE TMP_NPARTDISC;
    DELETE TMP_NPARTB;
    DELETE TMP_NAGENDA;
    DELETE TMP_NLOCALIT;


    INSERT INTO TMP_MANEVRA(CODUNIC)
    SELECT CODSYNCPART FROM SYNCPARTRETAIL WHERE SINCRONIZAT = 0 AND CODPOSTRETAIL = aCODPOSTRETAIL;

    INSERT INTO TMP_NPART(CODPART,
                          DEN_PART,
                          REGCOM,
                          CODEXTERN,
                          CODMONEDA,
                          AUTORIZATIE,
                          CODINTERN,
                          CODCLASA,
                          CODCATEGPRET,
                          TIPPART,
                          SCADENTAC,
                          SCADENTAV,
                          DISCOUNT,
                          CODCATEGDISC,
                          BLOCAT,
                          TIPPARTENER,
                          DATAADAUGARII,
                          OBS,
                          POZA,
                          PERSOANAFIZICA,
                          COLDISCOUNT,
                          INFOBLOCAT,
                          EXPIRAREAUTORIZ,
                          CODSTATISTICBNR,
                          MUSAICOLET,
                          STRATEGIC,
                          CIFRAAFACERI,
                          DOMENIUACTIV,
                          NRANGAJATI,
                          SURSALEAD,
                          LEAD,
                          TVALAINCASARE,
                          MODAPLICPROCDISC,
                          PROCCURSTRANSF,
                          FIDELIZARE,
                          DATANASTERE,
                          MAJORARI,
                          TIPBLOCAJ,
                          POPRIRE_ANAF,
                          CODRESPONSABIL,
                          CODDOMENIUACT,
                          DOCDEFONORCOM,
                          MODPROMOFACTCOM,
                          VALIDAREPRETOFERTA,
                          IESCUCOMANDA,
                          CANTMINCMD,
                          ZIAPROVIZ,
                          PERAPROVIZ)

         SELECT           P.CODPART,
                          P.DEN_PART,
                          P.REGCOM,
                          P.CODEXTERN,
                          P.CODMONEDA,
                          P.AUTORIZATIE,
                          P.CODINTERN,
                          P.CODCLASA,
                          P.CODCATEGPRET,
                          P.TIPPART,
                          P.SCADENTAC,
                          P.SCADENTAV,
                          P.DISCOUNT,
                          P.CODCATEGDISC,
                          P.BLOCAT,
                          P.TIPPARTENER,
                          P.DATAADAUGARII,
                          P.OBS,
                          P.POZA,
                          P.PERSOANAFIZICA,
                          P.COLDISCOUNT,
                          P.INFOBLOCAT,
                          P.EXPIRAREAUTORIZ,
                          P.CODSTATISTICBNR,
                          P.MUSAICOLET,
                          P.STRATEGIC,
                          P.CIFRAAFACERI,
                          P.DOMENIUACTIV,
                          P.NRANGAJATI,
                          P.SURSALEAD,
                          P.LEAD,
                          P.TVALAINCASARE,
                          P.MODAPLICPROCDISC,
                          P.PROCCURSTRANSF,
                          P.FIDELIZARE,
                          P.DATANASTERE,
                          P.MAJORARI,
                          P.TIPBLOCAJ,
                          P.POPRIRE_ANAF,
                          P.CODRESPONSABIL,
                          P.CODDOMENIUACT,
                          P.DOCDEFONORCOM,
                          P.MODPROMOFACTCOM,
                          P.VALIDAREPRETOFERTA,
                          P.IESCUCOMANDA,
                          P.CANTMINCMD,
                          P.ZIAPROVIZ,
                          P.PERAPROVIZ
     FROM
       NPART P,
       TMP_MANEVRA M,
       SYNCPARTRETAIL SY
     WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;


    INSERT INTO TMP_NPART1(CODPART1, CODPART, CODIOPART, CREDITCLIENT, VOLUMTRANZC, CREDITFURN, VOLUMTRANZF, ANSTART, LUNASTART, SCADENTAV, SCADENTAC, DISCOUNT, CASSBAZAMIN, SIMBOLCASS)
    SELECT P1.CODPART1,
           P1.CODPART,
           P1.CODIOPART,
           P1.CREDITCLIENT,
           P1.VOLUMTRANZC,
           P1.CREDITFURN,
           P1.VOLUMTRANZF,
           P1.ANSTART,
           P1.LUNASTART,
           P1.SCADENTAV,
           P1.SCADENTAC,
           P1.DISCOUNT,
           P1.CASSBAZAMIN,
           P1.SIMBOLCASS
     FROM
       NPART1 P1,
       TMP_MANEVRA M,
       SYNCPARTRETAIL SY
     WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P1.CODPART;



    INSERT INTO TMP_NPARTCODFISC(COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
    SELECT P.COD_CODFISCAL, P.CODPART, P.CODFISCAL, PRINCIPAL
     FROM
       NPARTCODFISC P,
       TMP_MANEVRA M,
       SYNCPARTRETAIL SY
     WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;

    INSERT INTO TMP_NPARTTR(CODPARTTR, CODPART, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, CODPERS, CODAUTO, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT, TELEFON, EMAIL)
    SELECT P.CODPARTTR, P.CODPART, P.DELEGAT, P.CNP, P.DOC, P.SERIEDOC, P.NRDOC, P.ELIBERAT, P.MIJLTRANSP, P.NRTRANSP, P.ACTIV, P.DATADOC, P.CODPERS, P.CODAUTO, P.IMPLICIT, P.OBS, P.PERMIS, P.NRPASS, P.CODTARA, P.ADRESA, P.CODLOCALIT, P.TELEFON, P.EMAIL
    FROM
      NPARTTR P,
      TMP_MANEVRA M,
      SYNCPARTRETAIL SY
    WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;


    INSERT INTO TMP_NPARTDISC(CODPARTDISC, CODPART, CODCATEGDISC, INDEXLOCAL)
    SELECT P.CODPARTDISC, P.CODPART, P.CODCATEGDISC, P.INDEXLOCAL
    FROM
      NPARTDISC P,
      TMP_MANEVRA M,
      SYNCPARTRETAIL SY
    WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;



    INSERT INTO TMP_NPARTB(CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODSWIFT, CODMONEDA, TIPCOMISION, OBS)
    SELECT P.CODPARTB, P.CODPART, P.CODBANK, P.IMPLICIT, P.CODLOCALIT, P.CONTBANCA, P.SUCURSALA, P.CODSWIFT, P.CODMONEDA, P.TIPCOMISION, P.OBS
    FROM
      NPARTB P,
      TMP_MANEVRA M,
      SYNCPARTRETAIL SY
    WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;



    INSERT INTO TMP_NAGENDA(
		       CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART,
					 CODPOSTAL, KM, OBS, CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT,
					 CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, INACTIV, CODCORESP, TRANSPCLIENT, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, TELEFONP, EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP, EDI_EXPCUMUL, EDI_EXPEAN)
    SELECT P.CODAGENDA,
           P.TIP,
           P.CODLOCALIT,
           P.SEDIUSOCIAL,
           P.TELEFON,
           P.FAX,
           P.EMAIL,
           P.SECTOR,
           P.STRADA,
           P.NR1,
           P.NR2,
           P.BLOC,
           P.SCARA,
           P.ETAJ,
           P.APART,
           P.CODPOSTAL,
           P.KM,
           P.OBS,
           P.CODBANKCONT,
           P.CODPART,
           P.CODGEST,
           P.CODSUBUNIT,
           P.CODTIPSEDIU,
           P.CODFISCAL,
           P.CODAGENT,
           P.CODCLIENT,
           P.CODTRASEU,
           P.POZTRASEU,
           P.CODTRASEU1,
           P.POZTRASEU1,
           P.INACTIV,
           P.CODCORESP,
           P.TRANSPCLIENT,
           P.COEFUTILAJE,
           P.SUPRAFATA,
           P.MODSERVIRE,
           P.IDSEDIU,
           P.COD_CODFISCAL,
           P.TELEFONP,
           P.EDI_EXPTIP,
           P.EDI_PARTTIP,
           P.EDI_PARTID,
           P.EDI_OBJTIP,
           P.GLN,
           P.GESTLIVRARE,
           P.LONGITUDINE,
           P.LATITUDINE,
           P.OBS2,
           P.EDI_IMPTIP,
           P.EDI_FURNTIP,
           P.EDI_FURNID,
           P.EDI_OBJTIPIMP,
           P.EDI_EXPCUMUL,
           P.EDI_EXPEAN
    FROM
      NAGENDA P,
      TMP_MANEVRA M,
      SYNCPARTRETAIL SY
    WHERE
       M.CODUNIC = SY.CODSYNCPART
       AND SY.CODPART = P.CODPART;



    INSERT INTO TMP_NLOCALIT(CODLOCALIT, DEN_LOCALIT, TIP, CODJUDET, OBS, CODTARA, DENSUP, SIRUTA, CODZONA, LATITUDINE, LONGITUDINE)
    SELECT L.CODLOCALIT,
           L.DEN_LOCALIT,
           L.TIP,
           L.CODJUDET,
           L.OBS,
           L.CODTARA,
           L.DENSUP,
           L.SIRUTA,
           L.CODZONA,
           L.LATITUDINE,
           L.LONGITUDINE
    FROM
      TMP_NAGENDA A,
      NLOCALIT L
    WHERE
      NVL(A.CODLOCALIT, 0) &lt;&gt; 0
      AND L.CODLOCALIT = A.CODLOCALIT

    UNION

    SELECT L.CODLOCALIT,
           L.DEN_LOCALIT,
           L.TIP,
           L.CODJUDET,
           L.OBS,
           L.CODTARA,
           L.DENSUP,
           L.SIRUTA,
           L.CODZONA,
           L.LATITUDINE,
           L.LONGITUDINE
    FROM
      TMP_NPARTB A,
      NLOCALIT L
    WHERE
      NVL(A.CODLOCALIT, 0) &lt;&gt; 0
      AND L.CODLOCALIT = A.CODLOCALIT

    UNION

    SELECT L.CODLOCALIT,
           L.DEN_LOCALIT,
           L.TIP,
           L.CODJUDET,
           L.OBS,
           L.CODTARA,
           L.DENSUP,
           L.SIRUTA,
           L.CODZONA,
           L.LATITUDINE,
           L.LONGITUDINE
    FROM
      TMP_NPARTTR A,
      NLOCALIT L
    WHERE
      NVL(A.CODLOCALIT, 0) &lt;&gt; 0
      AND L.CODLOCALIT = A.CODLOCALIT;



 END;


PROCEDURE SYNCRON_PARTBAZA_ON_RETAIL -- SE EXECUTA PE RETAIL DUPA CE AM PREGATIT TEMPORARELE CU TABELELE DE PARTENERI LUATE DE PE BAZA
IS
BEGIN
    PRC_AL_REFRESH(&apos;TMP_NPART1&apos;, 0);

    MERGE INTO NLOCALIT L
    USING TMP_NLOCALIT  TL
    ON (TL.CODLOCALIT = L.CODLOCALIT)
    WHEN NOT MATCHED THEN
    INSERT (CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
    VALUES (TL.CODLOCALIT, TL.DEN_LOCALIT, TL.CODJUDET, TL.CODTARA)
    WHEN MATCHED THEN
    UPDATE
    SET
     DEN_LOCALIT = TL.DEN_LOCALIT,
     CODJUDET    = TL.CODJUDET,
     CODTARA     = TL.CODTARA  ;


   MERGE INTO NPART P
   USING TMP_NPART TP
   ON (TP.CODPART = P.CODPART)
   WHEN NOT MATCHED THEN
   INSERT               ( CODPART,
                          DEN_PART,
                          REGCOM,
                          CODEXTERN,
                          CODMONEDA,
                          AUTORIZATIE,
                          CODINTERN,
                          CODCLASA,
                          CODCATEGPRET,
                          TIPPART,
                          SCADENTAC,
                          SCADENTAV,
                          DISCOUNT,
                          CODCATEGDISC,
                          BLOCAT,
                          TIPPARTENER,
                          DATAADAUGARII,
                          OBS,
                          POZA,
                          PERSOANAFIZICA,
                          COLDISCOUNT,
                          INFOBLOCAT,
                          EXPIRAREAUTORIZ,
                          CODSTATISTICBNR,
                          MUSAICOLET,
                          STRATEGIC,
                          CIFRAAFACERI,
                          DOMENIUACTIV,
                          NRANGAJATI,
                          SURSALEAD,
                          LEAD,
                          TVALAINCASARE,
                          MODAPLICPROCDISC,
                          PROCCURSTRANSF,
                          FIDELIZARE,
                          DATANASTERE,
                          MAJORARI,
                          TIPBLOCAJ,
                          POPRIRE_ANAF,
                          CODRESPONSABIL,
                          CODDOMENIUACT,
                          DOCDEFONORCOM,
                          MODPROMOFACTCOM,
                          VALIDAREPRETOFERTA,
                          IESCUCOMANDA,
                          CANTMINCMD,
                          ZIAPROVIZ,
                          PERAPROVIZ)
         VALUES          ( TP.CODPART,
                          TP.DEN_PART,
                          TP.REGCOM,
                          TP.CODEXTERN,
                          TP.CODMONEDA,
                          TP.AUTORIZATIE,
                          TP.CODINTERN,
                          TP.CODCLASA,
                          TP.CODCATEGPRET,
                          TP.TIPPART,
                          TP.SCADENTAC,
                          TP.SCADENTAV,
                          TP.DISCOUNT,
                          TP.CODCATEGDISC,
                          TP.BLOCAT,
                          TP.TIPPARTENER,
                          TP.DATAADAUGARII,
                          TP.OBS,
                          TP.POZA,
                          TP.PERSOANAFIZICA,
                          TP.COLDISCOUNT,
                          TP.INFOBLOCAT,
                          TP.EXPIRAREAUTORIZ,
                          TP.CODSTATISTICBNR,
                          TP.MUSAICOLET,
                          TP.STRATEGIC,
                          TP.CIFRAAFACERI,
                          TP.DOMENIUACTIV,
                          TP.NRANGAJATI,
                          TP.SURSALEAD,
                          TP.LEAD,
                          TP.TVALAINCASARE,
                          TP.MODAPLICPROCDISC,
                          TP.PROCCURSTRANSF,
                          TP.FIDELIZARE,
                          TP.DATANASTERE,
                          TP.MAJORARI,
                          TP.TIPBLOCAJ,
                          TP.POPRIRE_ANAF,
                          TP.CODRESPONSABIL,
                          TP.CODDOMENIUACT,
                          TP.DOCDEFONORCOM,
                          TP.MODPROMOFACTCOM,
                          TP.VALIDAREPRETOFERTA,
                          TP.IESCUCOMANDA,
                          TP.CANTMINCMD,
                          TP.ZIAPROVIZ,
                          TP.PERAPROVIZ)
   WHEN MATCHED THEN
   UPDATE
   SET
    DEN_PART    = TP.DEN_PART,
    REGCOM      = TP.REGCOM,
    CODEXTERN   = TP.CODEXTERN,
    CODMONEDA   = TP.CODMONEDA,
    AUTORIZATIE = TP.AUTORIZATIE,
    CODINTERN   = TP.CODINTERN,
    CODCLASA    = TP.CODCLASA,
    CODCATEGPRET = TP.CODCATEGPRET,
    TIPPART      = TP.TIPPART,
    SCADENTAC    = TP.SCADENTAC,
    SCADENTAV    = TP.SCADENTAV,
    DISCOUNT     = TP.DISCOUNT,
    CODCATEGDISC = TP.CODCATEGDISC,
    BLOCAT       = TP.BLOCAT,
    TIPPARTENER  = TP.TIPPARTENER,
    DATAADAUGARII = TP.DATAADAUGARII,
    OBS           = TP.OBS,
    POZA          = TP.POZA,
    PERSOANAFIZICA = TP.PERSOANAFIZICA,
    COLDISCOUNT    = TP.COLDISCOUNT,
    INFOBLOCAT     = TP.INFOBLOCAT,
    EXPIRAREAUTORIZ = TP.EXPIRAREAUTORIZ,
    CODSTATISTICBNR = TP.CODSTATISTICBNR,
    MUSAICOLET      = TP.MUSAICOLET,
    STRATEGIC       = TP.STRATEGIC,
    CIFRAAFACERI    = TP.CIFRAAFACERI,
    DOMENIUACTIV    = TP.DOMENIUACTIV,
    NRANGAJATI      = TP.NRANGAJATI,
    SURSALEAD       = TP.SURSALEAD,
    LEAD            = TP.LEAD,
    TVALAINCASARE   = TP.TVALAINCASARE,
    MODAPLICPROCDISC  = TP.MODAPLICPROCDISC,
    PROCCURSTRANSF    = TP.PROCCURSTRANSF,
    FIDELIZARE        = TP.FIDELIZARE,
    DATANASTERE       = TP.DATANASTERE,
    MAJORARI          = TP.MAJORARI,
    TIPBLOCAJ         = TP.TIPBLOCAJ,
    POPRIRE_ANAF      = TP.POPRIRE_ANAF,
    CODRESPONSABIL    = TP.CODRESPONSABIL,
    CODDOMENIUACT     = TP.CODDOMENIUACT,
    DOCDEFONORCOM     = TP.DOCDEFONORCOM,
    MODPROMOFACTCOM   = TP.MODPROMOFACTCOM,
    VALIDAREPRETOFERTA  = TP.VALIDAREPRETOFERTA ,
    IESCUCOMANDA        = TP.IESCUCOMANDA,
    CANTMINCMD          = TP.CANTMINCMD,
    ZIAPROVIZ           = TP.CANTMINCMD,
    PERAPROVIZ          = TP.PERAPROVIZ ;


   MERGE INTO NPART1 P1
   USING TMP_NPART1 TP1
   ON (P1.CODPART = TP1.CODPART AND P1.ANSTART = TP1.ANSTART AND P1.LUNASTART = TP1.LUNASTART)
   WHEN NOT MATCHED THEN
   INSERT( CODPART1, CODPART, CODIOPART, CREDITCLIENT, VOLUMTRANZC, CREDITFURN, VOLUMTRANZF, ANSTART, LUNASTART, SCADENTAV, SCADENTAC, DISCOUNT, CASSBAZAMIN, SIMBOLCASS, ALSTART, ALSTOP)
   VALUES (TP1.CODPART1, TP1.CODPART, TP1.CODIOPART, TP1.CREDITCLIENT, TP1.VOLUMTRANZC, TP1.CREDITFURN, TP1.VOLUMTRANZF, TP1.ANSTART, TP1.LUNASTART, TP1.SCADENTAV, TP1.SCADENTAC, TP1.DISCOUNT, TP1.CASSBAZAMIN, TP1.SIMBOLCASS, TP1.ALSTART, TP1.ALSTOP)
   ;

   MERGE INTO NPARTCODFISC P
   USING TMP_NPARTCODFISC TP
   ON (P.COD_CODFISCAL = TP.COD_CODFISCAL)
   WHEN NOT MATCHED THEN
   INSERT (COD_CODFISCAL, CODPART, CODFISCAL, PRINCIPAL)
   VALUES (TP.COD_CODFISCAL, TP.CODPART, TP.CODFISCAL, TP.PRINCIPAL)
   WHEN MATCHED THEN
   UPDATE
   SET
    CODFISCAL = TP.CODFISCAL,
    PRINCIPAL = TP.PRINCIPAL ;


   MERGE INTO NPARTTR P
   USING TMP_NPARTTR TP
   ON (P.CODPARTTR = TP.CODPARTTR)
   WHEN NOT MATCHED THEN
   INSERT (CODPARTTR, CODPART, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, CODPERS, CODAUTO, IMPLICIT, OBS, PERMIS, NRPASS, CODTARA, ADRESA, CODLOCALIT, TELEFON, EMAIL)
   VALUES (TP.CODPARTTR, TP.CODPART, TP.DELEGAT, TP.CNP, TP.DOC, TP.SERIEDOC, TP.NRDOC, TP.ELIBERAT, TP.MIJLTRANSP, TP.NRTRANSP, TP.ACTIV, TP.DATADOC, TP.CODPERS, TP.CODAUTO, TP.IMPLICIT, TP.OBS, TP.PERMIS, TP.NRPASS, TP.CODTARA, TP.ADRESA, TP.CODLOCALIT, TP.TELEFON, TP.EMAIL)
   WHEN MATCHED THEN
   UPDATE
   SET
    DELEGAT    = TP.DELEGAT,
    CNP        = TP.CNP,
    DOC        = TP.DOC,
    SERIEDOC   = TP. SERIEDOC,
    NRDOC      = TP.NRDOC,
    ELIBERAT   = TP.ELIBERAT,
    MIJLTRANSP = TP.MIJLTRANSP,
    NRTRANSP   = TP.NRTRANSP,
    ACTIV      = TP.ACTIV,
    DATADOC    = TP.DATADOC,
    CODPERS    = TP.CODPERS,
    CODAUTO    = TP.CODAUTO,
    IMPLICIT   = TP.IMPLICIT,
    OBS        = TP.OBS,
    PERMIS     = TP.PERMIS,
    NRPASS     = TP.NRPASS,
    CODTARA    = TP.CODTARA,
    ADRESA     = TP.ADRESA,
    CODLOCALIT = TP.CODLOCALIT,
    TELEFON    = TP.TELEFON,
    EMAIL      = TP.EMAIL ;

   FOR V_REC IN (SELECT CODPART FROM TMP_NPART)
   LOOP
     DELETE FROM NPARTDISC 
     WHERE
       CODPART = V_REC.CODPART;
   END LOOP;    

   MERGE INTO NPARTDISC P
   USING TMP_NPARTDISC TP
   ON (P.CODPARTDISC = TP.CODPARTDISC)
   WHEN NOT MATCHED THEN
   INSERT (CODPARTDISC, CODPART, CODCATEGDISC, INDEXLOCAL)
   VALUES (TP.CODPARTDISC, TP.CODPART, TP.CODCATEGDISC, TP.INDEXLOCAL)
   WHEN MATCHED THEN
   UPDATE
   SET
     CODCATEGDISC = TP.CODCATEGDISC,
     INDEXLOCAL   = TP.INDEXLOCAL;

   DELETE FROM NPARTDISCRETAIL
   WHERE
     CODPARTDISC NOT IN (SELECT CODPARTDISC FROM NPARTDISC);


  MERGE INTO NPARTB P
  USING TMP_NPARTB TP
  ON (TP.CODPARTB = P.CODPARTB)
  WHEN NOT MATCHED THEN
  INSERT (CODPARTB, CODPART, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODSWIFT, CODMONEDA, TIPCOMISION, OBS)
  VALUES (TP.CODPARTB, TP.CODPART, TP.CODBANK, TP.IMPLICIT, TP.CODLOCALIT, TP.CONTBANCA, TP.SUCURSALA, TP.CODSWIFT, TP.CODMONEDA, TP.TIPCOMISION, TP.OBS)
  WHEN MATCHED THEN
  UPDATE
  SET
    CODBANK     = TP.CODBANK,
    IMPLICIT    = TP.IMPLICIT,
    CODLOCALIT  = TP.CODLOCALIT,
    CONTBANCA   = TP.CONTBANCA,
    SUCURSALA   = TP.SUCURSALA,
    CODSWIFT    = TP.CODSWIFT ,
    CODMONEDA   = TP.CODMONEDA,
    TIPCOMISION = TP.TIPCOMISION,
    OBS         = TP.OBS;


  MERGE INTO NAGENDA A
  USING TMP_NAGENDA TA
  ON (A.CODAGENDA = TA.CODAGENDA)
  WHEN NOT MATCHED THEN
    INSERT (CODAGENDA, TIP, CODLOCALIT, SEDIUSOCIAL, TELEFON, FAX, EMAIL, SECTOR, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, CODPOSTAL, KM, OBS, CODBANKCONT, CODPART, CODGEST, CODSUBUNIT, CODTIPSEDIU, CODFISCAL, CODAGENT, CODCLIENT, CODTRASEU, POZTRASEU,CODTRASEU1, POZTRASEU1, INACTIV, CODCORESP, TRANSPCLIENT, COEFUTILAJE, SUPRAFATA, MODSERVIRE, IDSEDIU, COD_CODFISCAL, TELEFONP, EDI_EXPTIP, EDI_PARTTIP, EDI_PARTID, EDI_OBJTIP, GLN, GESTLIVRARE, LONGITUDINE, LATITUDINE, OBS2, EDI_IMPTIP, EDI_FURNTIP, EDI_FURNID, EDI_OBJTIPIMP, EDI_EXPCUMUL, EDI_EXPEAN)
    VALUES (TA.CODAGENDA,
            TA.TIP,
            TA.CODLOCALIT,
            TA.SEDIUSOCIAL,
            TA.TELEFON,
            TA.FAX,
            TA.EMAIL,
            TA.SECTOR,
            TA.STRADA,
            TA.NR1,
            TA.NR2,
            TA.BLOC,
            TA.SCARA,
            TA.ETAJ,
            TA.APART,
            TA.CODPOSTAL,
            TA.KM,
            TA.OBS,
            TA.CODBANKCONT,
            TA.CODPART,
            TA.CODGEST,
            TA.CODSUBUNIT,
            TA.CODTIPSEDIU,
            TA.CODFISCAL,
            TA.CODAGENT,
            TA.CODCLIENT,
            TA.CODTRASEU,
            TA.POZTRASEU,
            TA.CODTRASEU1,
            TA.POZTRASEU1,
            TA.INACTIV,
            TA.CODCORESP,
            TA.TRANSPCLIENT,
            TA.COEFUTILAJE,
            TA.SUPRAFATA,
            TA.MODSERVIRE,
            TA.IDSEDIU,
            TA.COD_CODFISCAL,
            TA.TELEFONP,
            TA.EDI_EXPTIP,
            TA.EDI_PARTTIP,
            TA.EDI_PARTID,
            TA.EDI_OBJTIP,
            TA.GLN,
            TA.GESTLIVRARE,
            TA.LONGITUDINE,
            TA.LATITUDINE,
            TA.OBS2,
            TA.EDI_IMPTIP,
            TA.EDI_FURNTIP,
            TA.EDI_FURNID,
            TA.EDI_OBJTIPIMP,
            TA.EDI_EXPCUMUL,
            TA.EDI_EXPEAN)
       WHEN MATCHED THEN
       UPDATE
       SET
       TIP           =      TA.TIP,
       CODLOCALIT    =      TA.CODLOCALIT,
       SEDIUSOCIAL   =      TA.SEDIUSOCIAL,
       TELEFON       =      TA.TELEFON,
       FAX           =      TA.FAX,
       EMAIL         =      TA.EMAIL,
       SECTOR        =      TA.SECTOR,
       STRADA        =      TA.STRADA,
       NR1           =      TA.NR1,
       NR2           =      TA.NR2,
       BLOC          =      TA.BLOC,
       SCARA         =      TA.SCARA,
       ETAJ          =      TA.ETAJ,
       APART         =      TA.APART,
       CODPOSTAL     =      TA.CODPOSTAL,
       KM            =      TA.KM,
       OBS           =      TA.OBS,
       CODBANKCONT   =      TA.CODBANKCONT,
       CODPART       =      TA.CODPART,
       CODGEST       =      TA.CODGEST,
       CODSUBUNIT    =      TA.CODSUBUNIT,
       CODTIPSEDIU   =      TA.CODTIPSEDIU,
       CODFISCAL     =      TA.CODFISCAL,
       CODAGENT      =      TA.CODAGENT,
       CODCLIENT     =      TA.CODCLIENT,
       CODTRASEU     =      TA.CODTRASEU,
       POZTRASEU     =      TA.POZTRASEU,
       INACTIV       =      TA.INACTIV,
       CODCORESP     =      TA.CODCORESP,
       TRANSPCLIENT  =      TA.TRANSPCLIENT,
       COEFUTILAJE   =      TA.COEFUTILAJE,
       SUPRAFATA     =      TA.SUPRAFATA,
       MODSERVIRE    =      TA.MODSERVIRE,
       IDSEDIU       =      TA.IDSEDIU,
       COD_CODFISCAL =      TA.COD_CODFISCAL,
       TELEFONP      =      TA.TELEFONP,
       EDI_EXPTIP    =      TA.EDI_EXPTIP,
       EDI_PARTTIP   =      TA.EDI_PARTTIP,
       EDI_PARTID    =      TA.EDI_PARTID,
       EDI_OBJTIP    =      TA.EDI_OBJTIP,
       GLN           =      TA.GLN,
       GESTLIVRARE   =      TA.GESTLIVRARE,
       LONGITUDINE   =      TA.LONGITUDINE,
       LATITUDINE    =      TA.LATITUDINE,
       OBS2          =      TA.OBS2,
       EDI_IMPTIP    =      TA.EDI_IMPTIP,
       EDI_FURNTIP   =      TA.EDI_FURNTIP,
       EDI_FURNID    =      TA.EDI_FURNID,
       EDI_OBJTIPIMP =      TA.EDI_OBJTIPIMP,
       EDI_EXPCUMUL  =      TA.EDI_EXPCUMUL,
       EDI_EXPEAN    =      TA.EDI_EXPEAN;

   MAKE_PARTRETAIL_FROM_TMPNPART;

END;


PROCEDURE MAKE_PARTRETAIL_FROM_TMPNPART
IS
  NR NUMBER(10);
  aCODIOPART NUMBER(20);
  aCOD       NUMBER(20);
BEGIN
   MERGE INTO NPARTRETAIL PR
   USING (SELECT P.* FROM NPART P, TMP_NPART TP  WHERE P.CODPART =TP.CODPART) P
   ON ( PR.CODPART = P.CODPART)
   WHEN NOT MATCHED THEN
   INSERT (CODPARTRETAIL, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET)
   VALUES (SEQ_NPARTRETAIL_CODPARTRETAIL.NEXTVAL,
           P.CODPART,
           P.DEN_PART,
           P.REGCOM,
           P.OBS,
           P.CODEXTERN,
           P.CODINTERN,
           NVL(P.PERSOANAFIZICA, 0),
           P.COLDISCOUNT,
           P.CODCLASA,
           P.FIDELIZARE,
           P.DATANASTERE,
           P.BLOCAT,
           P.INFOBLOCAT,
           P.CODCATEGPRET )
  WHEN MATCHED THEN
  UPDATE SET
    PR.DENUMIRE    = P.DEN_PART,
    PR.REGCOM      = P.REGCOM,
    PR.OBS         = P.OBS,
    PR.CODEXTERN   = P.CODEXTERN,
    PR.CODINTERN   = P.CODINTERN,
    PR.TIPPART     = NVL(P.PERSOANAFIZICA, 0),
    PR.COLDISCOUNT = P.COLDISCOUNT,
    PR.CODCLASA    = P.CODCLASA,
    PR.BLOCAT      = P.BLOCAT,
    PR.INFOBLOCAT  = P.INFOBLOCAT,
    PR.CODCATEGPRET  = P.CODCATEGPRET
  WHERE
    NVL(PR.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;



  MERGE INTO NSEDIIPARTRETAIL SR
  USING
  (SELECT A.*, PR.CODPARTRETAIL, L.DEN_LOCALIT, L.CODJUDET, L.CODTARA, PR.TIPMODIF
   FROM
     NAGENDA A
     LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT,
     NPARTRETAIL PR,
     TMP_NPART TP
   WHERE
    TP.CODPART = PR.CODPART
    AND PR.CODPART = A.CODPART
   ) SP
  ON (SP.CODAGENDA = SR.CODAGENDA)
  WHEN NOT MATCHED THEN
  INSERT (CODSEDIU,
          CODPARTRETAIL,
          DENUMIRE,
          CODLOCALIT,
          DENLOCALIT,
          CODJUDET,
          CODTARA,
          TELEFON,
          FAX,
          EMAIL,
          STRADA,
          NR1,
          NR2,
          BLOC,
          SCARA,
          ETAJ,
          APART,
          SECTOR,
          CODPOSTAL,
          SEDIUSOCIAL,
          CODAGENDA
         )
  VALUES (SEQ_NSEDIIPARTRETAIL_CODSEDIU.NEXTVAL,
          SP.CODPARTRETAIL,
          SP.OBS,
          SP.CODLOCALIT,
          SP.DEN_LOCALIT,
          SP.CODJUDET,
          SP.CODTARA,
          SP.TELEFON,
          SP.FAX,
          SP.EMAIL,
          SP.STRADA,
          SP.NR1,
          SP.NR2,
          SP.BLOC,
          SP.SCARA,
          SP.ETAJ,
          SP.APART,
          SP.SECTOR,
          SP.CODPOSTAL,
          SP.SEDIUSOCIAL,
          SP.CODAGENDA
         )
   WHEN MATCHED THEN
   UPDATE
   SET
     DENUMIRE    = SP.OBS,
     CODLOCALIT  = SP.CODLOCALIT,
     DENLOCALIT  = SP.DEN_LOCALIT,
     CODJUDET    = SP.CODJUDET,
     CODTARA     = SP.CODTARA,
     TELEFON     = SP.TELEFON,
     FAX         = SP.FAX,
     EMAIL       = SP.EMAIL,
     STRADA      = SP.STRADA,
     NR1         = SP.NR1,
     NR2         = SP.NR2,
     BLOC        = SP.BLOC,
     SCARA       = SP.SCARA,
     ETAJ        = SP.ETAJ,
     APART       = SP.APART,
     SECTOR      = SP.SECTOR,
     CODPOSTAL   = SP.CODPOSTAL,
     SEDIUSOCIAL = SP.SEDIUSOCIAL
   WHERE
       NVL(SP.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;

  MERGE INTO NCODFISCRETAIL CFR
  USING
    (SELECT CF.*, PR.CODPARTRETAIL, PR.TIPMODIF FROM
      NPARTCODFISC CF,
      NPARTRETAIL PR,
      TMP_NPART TP
    WHERE
      TP.CODPART = PR.CODPART
      AND CF.CODPART = PR.CODPART
    ) CFP
  ON (CFR.COD_CODFISCAL = CFP.COD_CODFISCAL)
  WHEN NOT MATCHED THEN
  INSERT (COD,
          CODPARTRETAIL,
          CODFISCAL,
          PRINCIPAL,
          COD_CODFISCAL
         )
 VALUES  (SEQ_NCODFISCRETAIL_COD.NEXTVAL,
          CFP.CODPARTRETAIL,
          CFP.CODFISCAL,
          CFP.PRINCIPAL,
          CFP.COD_CODFISCAL
         )
 WHEN MATCHED THEN
 UPDATE
 SET
   CODFISCAL =  CFP.CODFISCAL,
   PRINCIPAL =  CFP.PRINCIPAL
 WHERE
   NVL(CFP.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;



  MERGE INTO NPARTDISCRETAIL PDR
  USING
    (SELECT PD.*, PR.CODPARTRETAIL, PR.TIPMODIF
    FROM
      NPARTDISC PD,
      NPARTRETAIL PR,
      TMP_NPART TP
    WHERE
      PR.CODPART = TP.CODPART
      AND PD.CODPART = PR.CODPART
    ) PDB
  ON (PDR.CODPARTDISC = PDB.CODPARTDISC)
  WHEN NOT MATCHED THEN
  INSERT (
         COD,
         CODPARTRETAIL,
         CODCATEGDISC,
         INDEXLOCAL,
         CODPARTDISC
         )
    VALUES
         (SEQ_NPARTDISCRETAIL_COD.NEXTVAL,
          PDB.CODPARTRETAIL,
          PDB.CODCATEGDISC,
          PDB.INDEXLOCAL,
          PDB.CODPARTDISC
         )
  WHEN MATCHED THEN
  UPDATE
  SET
    CODCATEGDISC = PDB.CODCATEGDISC
  WHERE
     NVL(PDB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;

  DELETE FROM NPARTDISCRETAIL
  WHERE
    CODPARTDISC NOT IN (SELECT CODPARTDISC FROM NPARTDISC);

  MERGE INTO NDELEGATRETAIL DR
  USING
    (SELECT
       PT.*, PR.CODPARTRETAIL, PR.TIPMODIF
     FROM
      NPARTTR PT,
      NPARTRETAIL PR,
      TMP_NPART TP
    WHERE
      TP.CODPART = PR.CODPART
      AND PT.CODPART = PR.CODPART
    ) DB
  ON (DR.CODPARTTR = DB.CODPARTTR)
  WHEN NOT MATCHED THEN
  INSERT (
          COD,
          CODPARTRETAIL,
          DELEGAT,
          CNP,
          DOC,
          SERIEDOC,
          NRDOC,
          ELIBERAT,
          MIJLTRANSP,
          NRTRANSP,
          ACTIV,
          DATADOC,
          IMPLICIT,
          OBS,
          CODPARTTR
    )
    VALUES
         (SEQ_NDELEGATRETAIL_COD.NEXTVAL,
          DB.CODPARTRETAIL,
          DB.DELEGAT,
          DB.CNP,
          DB.DOC,
          DB.SERIEDOC,
          DB.NRDOC,
          DB.ELIBERAT,
          DB.MIJLTRANSP,
          DB.NRTRANSP,
          DB.ACTIV,
          DB.DATADOC,
          DB.IMPLICIT,
          DB.OBS,
          DB.CODPARTTR
         )
   WHEN MATCHED THEN
   UPDATE
   SET
    DELEGAT    =      DB.DELEGAT,
    CNP        =      DB.CNP,
    DOC        =      DB.DOC,
    SERIEDOC   =      DB.SERIEDOC,
    NRDOC      =      DB.NRDOC,
    ELIBERAT   =      DB.ELIBERAT,
    MIJLTRANSP =      DB.MIJLTRANSP,
    NRTRANSP   =      DB.NRTRANSP,
    ACTIV      =      DB.ACTIV,
    DATADOC    =      DB.DATADOC,
    IMPLICIT   =      DB.IMPLICIT,
    OBS        =      DB.OBS
   WHERE
     NVL(DB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;





  MERGE INTO NBANCIRETAIL BR
  USING
    (SELECT
     PB.*,
     PR.CODPARTRETAIL,
     L.DEN_LOCALIT AS DENLOCALIT,
     L.CODJUDET,
     L.CODTARA,
     K.DENUMIRE AS DENBANCA,
     PR.TIPMODIF
    FROM
      NPARTB PB
      LEFT JOIN NLOCALIT L ON L.CODLOCALIT = PB.CODLOCALIT
      LEFT JOIN NBANK K ON K.CODBANK = PB.CODBANK,
      NPARTRETAIL PR,
      TMP_NPART TP
    WHERE
      TP.CODPART = PR.CODPART
      AND PB.CODPART = PR.CODPART
    ) BB
  ON (BR.CODPARTB = BB.CODPARTB)
  WHEN NOT MATCHED THEN
  INSERT (
          COD,
          CODPARTRETAIL,
          CODBANK,
          IMPLICIT,
          CODLOCALIT,
          CONTBANCA,
          SUCURSALA,
          CODMONEDA,
          DENBANCA,
          DENLOCALIT,
          CODPARTB,
          CODJUDET,
          CODTARA
        )
    VALUES
         (SEQ_NBANCIRETAIL_COD.NEXTVAL,
          BB.CODPARTRETAIL,
          BB.CODBANK,
          BB.IMPLICIT,
          BB.CODLOCALIT,
          BB.CONTBANCA,
          BB.SUCURSALA,
          BB.CODMONEDA,
          BB.DENBANCA,
          BB.DENLOCALIT,
          BB.CODPARTB,
          BB.CODJUDET,
          BB.CODTARA
         )
   WHEN MATCHED THEN
   UPDATE
   SET
     CODBANK    =  BB.CODBANK,
     IMPLICIT   =  BB.IMPLICIT,
     CODLOCALIT =  BB.CODLOCALIT,
     CONTBANCA  =  BB.CONTBANCA,
     SUCURSALA  =  BB.SUCURSALA,
     CODMONEDA  =  BB.CODMONEDA,
     DENBANCA   =  BB.DENBANCA,
     DENLOCALIT =  BB.DENLOCALIT,
     CODJUDET   =  BB.CODJUDET,
     CODTARA    =  BB.CODTARA
   WHERE
     NVL(BB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;

END;


PROCEDURE SET_FLAG_SINCRONIZAT
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_MANEVRA)
  LOOP
    UPDATE SYNCPARTRETAIL
    SET
      SINCRONIZAT = 1
    WHERE
      CODSYNCPART = V_REC.CODUNIC;
  END LOOP;
END;

FUNCTION COD_FISCAL_UNIC(aCODPART IN NUMBER, aCODFISCAL IN VARCHAR2) RETURN NUMBER
IS
 NR NUMBER(10 ):= 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NCODFISCRETAIL WHERE PKG_NOMPART.STR_CODFISCAL(CODFISCAL) = PKG_NOMPART.STR_CODFISCAL(aCODFISCAL) AND CODPARTRETAIL &lt;&gt; aCODPART;
  IF NR = 0 THEN RETURN 1; ELSE RETURN 0;
  END IF;
END;


PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodPARTRETAIL INTO Tmp FROM NPARTRETAIL WHERE CodPARTRETAIL = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  DELETE FROM NSEDIIPARTRETAIL WHERE CODPARTRETAIL = RECID;
  DELETE FROM NCODFISCRETAIL   WHERE CODPARTRETAIL = RECID;
  DELETE FROM NPARTDISCRETAIL  WHERE CODPARTRETAIL = RECID;
  DELETE FROM NDELEGATRETAIL   WHERE CODPARTRETAIL = RECID;
  DELETE FROM NBANCIRETAIL     WHERE CODPARTRETAIL = RECID;

  DELETE FROM NPARTRETAIL      WHERE CODPARTRETAIL = RECID;


  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NPARTRETAIL(CODPARTRETAIL) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_NPARTRETAIL(CODPARTRETAIL, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET)

  SELECT  CODPARTRETAIL, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET
  FROM
    NPARTRETAIL
  WHERE
    CODPARTRETAIL = RECID;


  INSERT INTO TMP_NSEDIIPARTRETAIL(CODSEDIU, CODPARTRETAIL, DENUMIRE, CODLOCALIT, DENLOCALIT, CODJUDET, CODTARA, TELEFON, FAX, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, SECTOR, CODPOSTAL, SEDIUSOCIAL)

  SELECT
    CODSEDIU, CODPARTRETAIL, DENUMIRE, CODLOCALIT, DENLOCALIT, CODJUDET, CODTARA, TELEFON, FAX, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, SECTOR, CODPOSTAL, SEDIUSOCIAL
  FROM
    NSEDIIPARTRETAIL
  WHERE
    CODPARTRETAIL = RECID;


  INSERT INTO TMP_NCODFISCRETAIL(COD, CODPARTRETAIL, CODFISCAL, PRINCIPAL)
  SELECT COD, CODPARTRETAIL, CODFISCAL, PRINCIPAL
  FROM
    NCODFISCRETAIL
  WHERE
    CODPARTRETAIL = RECID;

  INSERT INTO TMP_NPARTDISCRETAIL(COD, CODPARTRETAIL, CODCATEGDISC, INDEXLOCAL)
  SELECT COD, CODPARTRETAIL, CODCATEGDISC, INDEXLOCAL
  FROM
    NPARTDISCRETAIL
  WHERE
    CODPARTRETAIL = RECID;


  INSERT INTO TMP_NDELEGATRETAIL(COD, CODPARTRETAIL, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS)
  SELECT
    COD, CODPARTRETAIL, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS
  FROM
     NDELEGATRETAIL
  WHERE
    CODPARTRETAIL = RECID;

  INSERT INTO TMP_NBANCIRETAIL(COD, CODPARTRETAIL, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA)
  SELECT COD, CODPARTRETAIL, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA
  FROM
    NBANCIRETAIL
  WHERE
    CODPARTRETAIL = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CODPARTRETAIL INTO RecID FROM TMP_NPARTRETAIL;

    UPDATE NPARTRETAIL
    SET
      (CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET) =
      (SELECT CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET FROM TMP_NPARTRETAIL)
    WHERE
      CODPARTRETAIL = RECID;


    DELETE FROM NSEDIIPARTRETAIL WHERE CODPARTRETAIL = RECID AND CODSEDIU NOT IN (SELECT CODSEDIU FROM TMP_NSEDIIPARTRETAIL);

    FOR V_REC IN (SELECT * FROM TMP_NSEDIIPARTRETAIL)
    LOOP
        IF V_REC.CODSEDIU &lt; 0 THEN
          INSERT INTO NSEDIIPARTRETAIL(CODSEDIU, CODPARTRETAIL, DENUMIRE, CODLOCALIT, DENLOCALIT, CODJUDET, CODTARA, TELEFON, FAX, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, SECTOR, CODPOSTAL, SEDIUSOCIAL)
                      VALUES          (SEQ_NSEDIIPARTRETAIL_CODSEDIU.NEXTVAL, RECID,  V_REC.DENUMIRE, V_REC.CODLOCALIT, V_REC.DENLOCALIT, V_REC.CODJUDET, V_REC.CODTARA, V_REC.TELEFON, V_REC.FAX, V_REC.EMAIL, V_REC.STRADA, V_REC.NR1, V_REC.NR2, V_REC.BLOC, V_REC.SCARA, V_REC.ETAJ, V_REC.APART, V_REC.SECTOR, V_REC.CODPOSTAL, V_REC.SEDIUSOCIAL);
        ELSE
          UPDATE NSEDIIPARTRETAIL
          SET
          (DENUMIRE,
          CODLOCALIT,
          DENLOCALIT,
          CODJUDET,
          CODTARA,
          TELEFON,
          FAX,
          EMAIL,
          STRADA,
          NR1,
          NR2,
          BLOC,
          SCARA,
          ETAJ,
          APART,
          SECTOR,
          CODPOSTAL,
          SEDIUSOCIAL) = (SELECT
          V_REC.DENUMIRE,
          V_REC.CODLOCALIT,
          V_REC.DENLOCALIT,
          V_REC.CODJUDET,
          V_REC.CODTARA,
          V_REC.TELEFON,
          V_REC.FAX,
          V_REC.EMAIL,
          V_REC.STRADA,
          V_REC.NR1,
          V_REC.NR2,
          V_REC.BLOC,
          V_REC.SCARA,
          V_REC.ETAJ,
          V_REC.APART,
          V_REC.SECTOR,
          V_REC.
          CODPOSTAL,
          V_REC.SEDIUSOCIAL FROM DUAL)
          WHERE
            CODSEDIU = V_REC.CODSEDIU;
        END IF;
    END LOOP;


    DELETE FROM NCODFISCRETAIL WHERE CODPARTRETAIL = RECID AND COD NOT IN (SELECT COD FROM TMP_NCODFISCRETAIL);

    FOR V_REC IN (SELECT * FROM TMP_NCODFISCRETAIL)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO NCODFISCRETAIL(COD, CODPARTRETAIL, CODFISCAL, PRINCIPAL)
        VALUES (SEQ_NCODFISCRETAIL_COD.NEXTVAL, RECID, V_REC.CODFISCAL, V_REC.PRINCIPAL);
      ELSE
        UPDATE NCODFISCRETAIL
        SET
          (CODFISCAL, PRINCIPAL) = (SELECT V_REC.CODFISCAL, V_REC.PRINCIPAL FROM DUAL)
        WHERE
          COD = V_REC.COD;
      END IF;

    END LOOP;


    DELETE FROM NPARTDISCRETAIL WHERE CODPARTRETAIL = RECID AND COD NOT IN (SELECT COD FROM  TMP_NPARTDISCRETAIL);


    FOR V_REC IN (SELECT * FROM TMP_NPARTDISCRETAIL)
    LOOP
       IF V_REC.COD &lt; 0 THEN
         INSERT INTO NPARTDISCRETAIL(COD, CODPARTRETAIL, CODCATEGDISC, INDEXLOCAL)
         VALUES(SEQ_NPARTDISC_CODPARTDISC.NEXTVAL, RECID, V_REC.CODCATEGDISC, V_REC.INDEXLOCAL);
       ELSE
         UPDATE NPARTDISCRETAIL
         SET
           (CODCATEGDISC, INDEXLOCAL) = (SELECT V_REC.CODCATEGDISC, V_REC.INDEXLOCAL FROM DUAL)
         WHERE
           COD = V_REC.COD;
       END IF;
    END LOOP;



    DELETE FROM NDELEGATRETAIL WHERE CODPARTRETAIL = RECID AND COD NOT IN (SELECT COD FROM  TMP_NDELEGATRETAIL);

    FOR V_REC IN (SELECT * FROM TMP_NDELEGATRETAIL)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO NDELEGATRETAIL(COD, CODPARTRETAIL, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS)
        VALUES(SEQ_NDELEGATRETAIL_COD.NEXTVAL, RECID, V_REC.DELEGAT, V_REC.CNP, V_REC.DOC, V_REC.SERIEDOC, V_REC.NRDOC, V_REC.ELIBERAT, V_REC.MIJLTRANSP, V_REC.NRTRANSP, V_REC.ACTIV, V_REC.DATADOC, V_REC.IMPLICIT, V_REC.OBS);
      ELSE
          UPDATE NDELEGATRETAIL
          SET
           (DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS) =
           (SELECT V_REC.DELEGAT, V_REC.CNP, V_REC.DOC, V_REC.SERIEDOC, V_REC.NRDOC, V_REC.ELIBERAT, V_REC.MIJLTRANSP, V_REC.NRTRANSP, V_REC.ACTIV, V_REC.DATADOC, V_REC.IMPLICIT, V_REC.OBS FROM DUAL)
          WHERE
            COD = V_REC.COD;
      END IF;
    END LOOP;


    DELETE FROM NBANCIRETAIL WHERE CODPARTRETAIL = RECID AND COD NOT IN (SELECT COD FROM  TMP_NBANCIRETAIL);


   FOR V_REC IN (SELECT * FROM TMP_NBANCIRETAIL)
   LOOP
     IF V_REC.COD &lt; 0 THEN
       INSERT INTO NBANCIRETAIL(COD, CODPARTRETAIL, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA)
              VALUES (SEQ_NBANCIRETAIL_COD.NEXTVAL, RECID, V_REC.CODBANK, V_REC.IMPLICIT, V_REC.CODLOCALIT, V_REC.CONTBANCA, V_REC.SUCURSALA, V_REC.CODMONEDA, V_REC.DENBANCA,
                      V_REC.DENLOCALIT,
                      V_REC.CODJUDET,
                      V_REC.CODTARA
                      );
     ELSE
       UPDATE NBANCIRETAIL
       SET
        (CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA) =
        (SELECT V_REC.CODBANK, V_REC.IMPLICIT, V_REC.CODLOCALIT, V_REC.CONTBANCA, V_REC.SUCURSALA, V_REC.CODMONEDA, V_REC.DENBANCA, V_REC.DENLOCALIT, V_REC.CODJUDET, V_REC.CODTARA FROM DUAL)
       WHERE
         COD = V_REC.COD;
     END IF;
   END LOOP;


  ELSE
    SELECT SEQ_NPARTRETAIL_CODPARTRETAIL.NEXTVAL INTO RECID FROM DUAL;

    INSERT INTO NPARTRETAIL (CODPARTRETAIL, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE,BLOCAT, INFOBLOCAT, CODCATEGPRET, DATACREARE, USERID)
    SELECT RECID, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET, SYSTIMESTAMP, PKG_GLOBALS.GETUSERID
    FROM
      TMP_NPARTRETAIL;

    INSERT INTO NSEDIIPARTRETAIL(CODSEDIU, CODPARTRETAIL, DENUMIRE, CODLOCALIT, DENLOCALIT, CODJUDET, CODTARA, TELEFON, FAX, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, SECTOR, CODPOSTAL, SEDIUSOCIAL)
    SELECT SEQ_NSEDIIPARTRETAIL_CODSEDIU.NEXTVAL, RECID,  DENUMIRE, CODLOCALIT, DENLOCALIT, CODJUDET, CODTARA, TELEFON, FAX, EMAIL, STRADA, NR1, NR2, BLOC, SCARA, ETAJ, APART, SECTOR, CODPOSTAL, SEDIUSOCIAL
    FROM
       TMP_NSEDIIPARTRETAIL;


    INSERT INTO NCODFISCRETAIL(COD, CODPARTRETAIL, CODFISCAL, PRINCIPAL)
    SELECT  SEQ_NCODFISCRETAIL_COD.NEXTVAL, RECID, CODFISCAL, PRINCIPAL FROM TMP_NCODFISCRETAIL;



    INSERT INTO NPARTDISCRETAIL(COD, CODPARTRETAIL, CODCATEGDISC, INDEXLOCAL)
    SELECT SEQ_NPARTDISC_CODPARTDISC.NEXTVAL, RECID, CODCATEGDISC, INDEXLOCAL FROM TMP_NPARTDISCRETAIL;


     INSERT INTO NDELEGATRETAIL(COD, CODPARTRETAIL, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS)
     SELECT SEQ_NDELEGATRETAIL_COD.NEXTVAL, RECID, DELEGAT, CNP, DOC, SERIEDOC, NRDOC, ELIBERAT, MIJLTRANSP, NRTRANSP, ACTIV, DATADOC, IMPLICIT, OBS
     FROM
       TMP_NDELEGATRETAIL;

     INSERT INTO NBANCIRETAIL(COD, CODPARTRETAIL, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA)
           SELECT SEQ_NBANCIRETAIL_COD.NEXTVAL, RECID, CODBANK, IMPLICIT, CODLOCALIT, CONTBANCA, SUCURSALA, CODMONEDA, DENBANCA, DENLOCALIT, CODJUDET, CODTARA
           FROM
             TMP_NBANCIRETAIL;



  END IF;
  COMMIT;
END;

FUNCTION GET_CODIOPART_LUNA_LUCRU(aCodPart in NUMBER) RETURN NUMBER
IS
  aCODIoPart  Number(20) := - 1;
  aAN         NUMBER(5);
  aLUna       NUMBER(2) ;

BEGIN
  aAN   := PKG_GLOBALS.GETANLUCRU;
  aLUNA := PKG_GLOBALS.GETLUNALUCRU;
  BEGIN
    SELECT NVL(CodIoPart, 0) INTO aCodIoPart FROM NPart1 n1
    WHERE n1.CodPart = aCodPart AND aAn*12+aLuna BETWEEN n1.alstart AND n1.alstop;
  EXCEPTION WHEN OTHERS THEN aCodIoPart := 0;
  END;
  RETURN aCODIOPART;
END;

PROCEDURE MAKE_PARTRETAIL_FROM_NPART
IS
  NR NUMBER(10);
  aCODIOPART     NUMBER(20);
  aCOD           NUMBER(20);
  aCODPARTRETAIL NUMBER(20);
BEGIN
-- curatare dublari
    FOR V_REC IN
    (
    SELECT
      CODPART,
      COUNT(*) AS NR
    FROM
      NPARTRETAIL
    GROUP BY CODPART
    HAVING COUNT(*) &gt; 1
    )
    LOOP
      SELECT MIN(CODPARTRETAIL) INTO aCODPARTRETAIL FROM  NPARTRETAIL WHERE CODPART = V_REC.CODPART;
      FOR V_REC_R IN (SELECT * FROM NPARTRETAIL WHERE CODPART = V_REC.CODPART AND CODPARTRETAIL &lt;&gt; aCODPARTRETAIL)
      LOOP
        UPDATE IESIRIRETAIL
        SET
          CODPARTRETAIL = aCODPARTRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;

        UPDATE EMULARE
        SET
          CODPARTRETAIL = aCODPARTRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;

        UPDATE RESTNP
        SET
          CODPARTRETAIL = aCODPARTRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


        UPDATE EMULARE
        SET
          CODPARTRETAILCOMIS = aCODPARTRETAIL
        WHERE
          CODPARTRETAILCOMIS = V_REC_R.CODPARTRETAIL;


        DELETE FROM NCODFISCRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;

        DELETE FROM NSEDIIPARTRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


        DELETE FROM NBANCIRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


        DELETE FROM NDELEGATRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


        DELETE FROM NPARTDISCRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


        DELETE FROM NPARTRETAIL
        WHERE
          CODPARTRETAIL = V_REC_R.CODPARTRETAIL;


      END LOOP;

    END LOOP  ;



   -- start
   MERGE INTO NPARTRETAIL PR
   USING (SELECT * FROM NPART  WHERE CODPART &gt; 0) P
   ON ( PR.CODPART = P.CODPART)
   WHEN NOT MATCHED THEN
   INSERT (CODPARTRETAIL, CODPART, DENUMIRE, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT, CODCATEGPRET)
   VALUES (SEQ_NPARTRETAIL_CODPARTRETAIL.NEXTVAL,
           P.CODPART,
           P.DEN_PART,
           P.REGCOM,
           P.OBS,
           P.CODEXTERN,
           P.CODINTERN,
           NVL(P.PERSOANAFIZICA, 0),
           P.COLDISCOUNT,
           P.CODCLASA,
           P.FIDELIZARE,
           P.DATANASTERE,
           P.BLOCAT,
           P.INFOBLOCAT,
           P.CODCATEGPRET)
  WHEN MATCHED THEN
  UPDATE SET
    PR.DENUMIRE    = P.DEN_PART,
    PR.REGCOM      = P.REGCOM,
    PR.OBS         =  P.OBS,
    PR.CODEXTERN   = P.CODEXTERN,
    PR.CODINTERN   = P.CODINTERN,
    PR.TIPPART     =  NVL(P.PERSOANAFIZICA, 0),
    PR.COLDISCOUNT =  P.COLDISCOUNT,
    PR.CODCLASA     = P.CODCLASA,
    PR.BLOCAT      = P.BLOCAT,
    PR.INFOBLOCAT  = P.INFOBLOCAT,
    PR.CODCATEGPRET = P.CODCATEGPRET
  WHERE
    NVL(PR.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;


  SELECT COUNT(*) INTO NR FROM NPARTRETAIL WHERE CODPARTRETAIL = 0;
  IF NR = 0 THEN
    INSERT INTO NPARTRETAIL(CODPARTRETAIL, CODPART, DENUMIRE)
    VALUES (0, 0, &apos;... nedefinit ...&apos;);
  END IF;

  MERGE INTO NSEDIIPARTRETAIL SR
  USING
  (SELECT A.*, PR.CODPARTRETAIL, L.DEN_LOCALIT, L.CODJUDET, L.CODTARA, PR.TIPMODIF
   FROM
     NAGENDA A
     LEFT JOIN NLOCALIT L ON A.CODLOCALIT = L.CODLOCALIT,
     NPARTRETAIL PR WHERE PR.CODPART = A.CODPART) SP
  ON (SP.CODAGENDA = SR.CODAGENDA)
  WHEN NOT MATCHED THEN
  INSERT (CODSEDIU,
          CODPARTRETAIL,
          DENUMIRE,
          CODLOCALIT,
          DENLOCALIT,
          CODJUDET,
          CODTARA,
          TELEFON,
          FAX,
          EMAIL,
          STRADA,
          NR1,
          NR2,
          BLOC,
          SCARA,
          ETAJ,
          APART,
          SECTOR,
          CODPOSTAL,
          SEDIUSOCIAL,
          CODAGENDA
         )
  VALUES (SEQ_NSEDIIPARTRETAIL_CODSEDIU.NEXTVAL,
          SP.CODPARTRETAIL,
          SP.OBS,
          SP.CODLOCALIT,
          SP.DEN_LOCALIT,
          SP.CODJUDET,
          SP.CODTARA,
          SP.TELEFON,
          SP.FAX,
          SP.EMAIL,
          SP.STRADA,
          SP.NR1,
          SP.NR2,
          SP.BLOC,
          SP.SCARA,
          SP.ETAJ,
          SP.APART,
          SP.SECTOR,
          SP.CODPOSTAL,
          SP.SEDIUSOCIAL,
          SP.CODAGENDA
         )
   WHEN MATCHED THEN
   UPDATE
   SET
     DENUMIRE    = SP.OBS,
     CODLOCALIT  = SP.CODLOCALIT,
     DENLOCALIT  = SP.DEN_LOCALIT,
     CODJUDET    = SP.CODJUDET,
     CODTARA     = SP.CODTARA,
     TELEFON     = SP.TELEFON,
     FAX         = SP.FAX,
     EMAIL       = SP.EMAIL,
     STRADA      = SP.STRADA,
     NR1         = SP.NR1,
     NR2         = SP.NR2,
     BLOC        = SP.BLOC,
     SCARA       = SP.SCARA,
     ETAJ        = SP.ETAJ,
     APART       = SP.APART,
     SECTOR      = SP.SECTOR,
     CODPOSTAL   = SP.CODPOSTAL,
     SEDIUSOCIAL = SP.SEDIUSOCIAL
   WHERE
       NVL(SP.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;

  MERGE INTO NCODFISCRETAIL CFR
  USING
    (SELECT CF.*, PR.CODPARTRETAIL, PR.TIPMODIF FROM
      NPARTCODFISC CF,
      NPARTRETAIL PR
    WHERE
      CF.CODPART = PR.CODPART
--      AND ROWNUM = 1
    ) CFP
  ON (CFR.COD_CODFISCAL = CFP.COD_CODFISCAL)
  WHEN NOT MATCHED THEN
  INSERT (COD,
          CODPARTRETAIL,
          CODFISCAL,
          PRINCIPAL,
          COD_CODFISCAL
         )
 VALUES  (SEQ_NCODFISCRETAIL_COD.NEXTVAL,
          CFP.CODPARTRETAIL,
          CFP.CODFISCAL,
          CFP.PRINCIPAL,
          CFP.COD_CODFISCAL
         )
 WHEN MATCHED THEN
 UPDATE
 SET
   CODFISCAL =  CFP.CODFISCAL,
   PRINCIPAL =  CFP.PRINCIPAL
 WHERE
   NVL(CFP.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;



  MERGE INTO NPARTDISCRETAIL PDR
  USING
    (SELECT PD.*, PR.CODPARTRETAIL, PR.TIPMODIF
    FROM
      NPARTDISC PD,
      NPARTRETAIL PR
    WHERE
      PD.CODPART = PR.CODPART
    ) PDB
  ON (PDR.CODPARTDISC = PDB.CODPARTDISC)
  WHEN NOT MATCHED THEN
  INSERT (
         COD,
         CODPARTRETAIL,
         CODCATEGDISC,
         INDEXLOCAL,
         CODPARTDISC
         )
    VALUES
         (SEQ_NPARTDISCRETAIL_COD.NEXTVAL,
          PDB.CODPARTRETAIL,
          PDB.CODCATEGDISC,
          PDB.INDEXLOCAL,
          PDB.CODPARTDISC
         )
  WHEN MATCHED THEN
  UPDATE
  SET
    CODCATEGDISC = PDB.CODCATEGDISC
  WHERE
     NVL(PDB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;

  FOR V_REC IN
   (SELECT PDR.COD, PR.CODPART, PDR.CODCATEGDISC
    FROM
      NPARTDISCRETAIL PDR,
      NPARTRETAIL PR
    WHERE
      PDR.CODPARTRETAIL = PR.CODPARTRETAIL
   )
 LOOP
   SELECT COUNT(*) INTO NR FROM NPARTDISC
   WHERE
     CODPART = V_REC.CODPART
     AND CODCATEGDISC = V_REC.CODCATEGDISC;

   IF NR = 0 THEN
     DELETE FROM NPARTDISCRETAIL WHERE COD = V_REC.COD;
   END IF;

 END LOOP;


  MERGE INTO NDELEGATRETAIL DR
  USING
    (SELECT
       PT.*, PR.CODPARTRETAIL, PR.TIPMODIF
     FROM
      NPARTTR PT,
      NPARTRETAIL PR
    WHERE
      PT.CODPART = PR.CODPART
    ) DB
  ON (DR.CODPARTTR = DB.CODPARTTR)
  WHEN NOT MATCHED THEN
  INSERT (
          COD,
          CODPARTRETAIL,
          DELEGAT,
          CNP,
          DOC,
          SERIEDOC,
          NRDOC,
          ELIBERAT,
          MIJLTRANSP,
          NRTRANSP,
          ACTIV,
          DATADOC,
          IMPLICIT,
          OBS,
          CODPARTTR
    )
    VALUES
         (SEQ_NDELEGATRETAIL_COD.NEXTVAL,
          DB.CODPARTRETAIL,
          DB.DELEGAT,
          DB.CNP,
          DB.DOC,
          DB.SERIEDOC,
          DB.NRDOC,
          DB.ELIBERAT,
          DB.MIJLTRANSP,
          DB.NRTRANSP,
          DB.ACTIV,
          DB.DATADOC,
          DB.IMPLICIT,
          DB.OBS,
          DB.CODPARTTR
         )
   WHEN MATCHED THEN
   UPDATE
   SET
    DELEGAT    =      DB.DELEGAT,
    CNP        =      DB.CNP,
    DOC        =      DB.DOC,
    SERIEDOC   =      DB.SERIEDOC,
    NRDOC      =      DB.NRDOC,
    ELIBERAT   =      DB.ELIBERAT,
    MIJLTRANSP =      DB.MIJLTRANSP,
    NRTRANSP   =      DB.NRTRANSP,
    ACTIV      =      DB.ACTIV,
    DATADOC    =      DB.DATADOC,
    IMPLICIT   =      DB.IMPLICIT,
    OBS        =      DB.OBS
   WHERE
     NVL(DB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;





  MERGE INTO NBANCIRETAIL BR
  USING
    (SELECT
     PB.*,
     PR.CODPARTRETAIL,
     L.DEN_LOCALIT AS DENLOCALIT,
     L.CODJUDET,
     L.CODTARA,
     K.DENUMIRE AS DENBANCA,
     PR.TIPMODIF
    FROM
      NPARTB PB
      LEFT JOIN NLOCALIT L ON L.CODLOCALIT = PB.CODLOCALIT
      LEFT JOIN NBANK K ON K.CODBANK = PB.CODBANK,
      NPARTRETAIL PR
    WHERE
      PB.CODPART = PR.CODPART
    ) BB
  ON (BR.CODPARTB = BB.CODPARTB)
  WHEN NOT MATCHED THEN
  INSERT (
          COD,
          CODPARTRETAIL,
          CODBANK,
          IMPLICIT,
          CODLOCALIT,
          CONTBANCA,
          SUCURSALA,
          CODMONEDA,
          DENBANCA,
          DENLOCALIT,
          CODPARTB,
          CODJUDET,
          CODTARA
        )
    VALUES
         (SEQ_NBANCIRETAIL_COD.NEXTVAL,
          BB.CODPARTRETAIL,
          BB.CODBANK,
          BB.IMPLICIT,
          BB.CODLOCALIT,
          BB.CONTBANCA,
          BB.SUCURSALA,
          BB.CODMONEDA,
          BB.DENBANCA,
          BB.DENLOCALIT,
          BB.CODPARTB,
          BB.CODJUDET,
          BB.CODTARA
         )
   WHEN MATCHED THEN
   UPDATE
   SET
     CODBANK    =  BB.CODBANK,
     IMPLICIT   =  BB.IMPLICIT,
     CODLOCALIT =  BB.CODLOCALIT,
     CONTBANCA  =  BB.CONTBANCA,
     SUCURSALA  =  BB.SUCURSALA,
     CODMONEDA  =  BB.CODMONEDA,
     DENBANCA   =  BB.DENBANCA,
     DENLOCALIT =  BB.DENLOCALIT,
     CODJUDET   =  BB.CODJUDET,
     CODTARA    =  BB.CODTARA
   WHERE
     NVL(BB.TIPMODIF, &apos;?&apos;) &lt;&gt; &apos;M&apos;;



  UPDATE EMULARE E
  SET
    CODPARTRETAIL = (SELECT CODPARTRETAIL FROM NPARTRETAIL WHERE CODPART = E.CODPART AND ROWNUM = 1)
  WHERE
    NVL(CODPART, 0) &lt;&gt; 0;

  UPDATE RESTNP NP
  SET
    CODPARTRETAIL = (SELECT CODPARTRETAIL FROM NPARTRETAIL WHERE CODPART = NP.CODPART AND ROWNUM = 1)
  WHERE
    NVL(CODPART, 0) &lt;&gt; 0;



  UPDATE EMULARERETAIL E
  SET
    CODSEDIURETAIL = (SELECT CODSEDIU FROM NSEDIIPARTRETAIL SR WHERE SR.CODAGENDA = E.CODLOCATIE)
  WHERE
    NVL(E.CODLOCATIE, 0) &lt;&gt; 0;



  UPDATE IESIRIRETAIL I
  SET
    CODPARTRETAIL = (SELECT CODPARTRETAIL FROM NPARTRETAIL WHERE CODPART = I.PARTENER AND ROWNUM = 1)
  WHERE
    NVL(PARTENER, 0) &lt;&gt; 0;


  UPDATE IESIRIRETAIL I
  SET
    CODSEDIURETAIL = (SELECT CODSEDIU FROM NSEDIIPARTRETAIL SR WHERE SR.CODAGENDA = I.CODLOCATIE)
  WHERE
    NVL(CODLOCATIE, 0) &lt;&gt; 0;


  UPDATE IESIRIRETAIL I
  SET
    DELEGATRETAIL = (SELECT COD FROM NDELEGATRETAIL DR WHERE DR.CODPARTTR = I.DELEGAT)
  WHERE
    NVL(DELEGAT, 0) &lt;&gt; 0;


  UPDATE IESIRIRETAIL I
  SET
    CODFISCALRETAIL = (SELECT COD FROM NCODFISCRETAIL FR WHERE FR.COD_CODFISCAL = I.CODFISCAL)
  WHERE
    NVL(I.CODFISCAL, 0) &lt;&gt; 0;


  FOR V_REC IN (
/*
    SELECT
      PR.CODPARTRETAIL,
      PR.CODPART
    FROM
      NPARTRETAIL PR
      LEFT JOIN NPART P ON PR.CODPART IS NOT NULL AND PR.CODPART = P.CODPART
    WHERE
      P.CODPART IS NULL
*/
    SELECT
      PR.CODPARTRETAIL,
      P.CODPART,
      PR.CODPART AS CODPARTSTERS
    FROM
      NPARTRETAIL PR
      LEFT JOIN NPART P ON PR.CODPART IS NOT NULL AND PR.CODPART = P.CODPART
    WHERE
      PR.CODPART IS NOT NULL
      AND P.CODPART IS NULL

   )
  LOOP
    SELECT COUNT(*) INTO NR FROM EMULARE WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
    IF NR = 0 THEN
      SELECT COUNT(*) INTO NR FROM IESIRIRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
    END IF;

    IF NR = 0 THEN
      DELETE FROM NBANCIRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
      DELETE FROM NDELEGATRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
      DELETE FROM NPARTDISCRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
      DELETE FROM NCODFISCRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
      DELETE FROM NSEDIIPARTRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
      DELETE FROM NPARTRETAIL WHERE CODPARTRETAIL = V_REC.CODPARTRETAIL;
    ELSE
      UPDATE NPARTRETAIL
      SET
        BLOCAT = 1,
        INFOBLOCAT = &apos;STERS DE PE BAZA&apos;
      WHERE
        CODPARTRETAIL = V_REC.CODPARTRETAIL;
    END IF;

  END LOOP;

  COMMIT;
END;


PROCEDURE SET_FLAG_MODIF(aCODPARTRETAIL IN NUMBER)
IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   UPDATE NPARTRETAIL
   SET
     TIPMODIF = &apos;M&apos;
   WHERE
     CODPARTRETAIL = aCODPARTRETAIL;
   COMMIT;
END;


PROCEDURE CLEAR_PARTRETAIL_TEMPS
IS
BEGIN
   DELETE TMP_NPARTRETAIL;
   DELETE TMP_NSEDIIPARTRETAIL;
   DELETE TMP_NCODFISCRETAIL;
   DELETE TMP_NPARTDISCRETAIL;
   DELETE TMP_NDELEGATRETAIL;
   DELETE TMP_NBANCIRETAIL;
   DELETE TMP_NLOCALIT;
   DELETE TMP_NBANK;
   COMMIT;
END;


PROCEDURE PREPARE_NEW_PARTRETAIL
IS
BEGIN
   DELETE TMP_NPARTRETAIL;
   DELETE TMP_NSEDIIPARTRETAIL;
   DELETE TMP_NCODFISCRETAIL;
   DELETE TMP_NPARTDISCRETAIL;
   DELETE TMP_NDELEGATRETAIL;
   DELETE TMP_NBANCIRETAIL;
   DELETE TMP_NLOCALIT;
   DELETE TMP_NBANK   ;


   INSERT INTO TMP_NPARTRETAIL
   SELECT * FROM NPARTRETAIL WHERE CODPARTRETAIL &gt; 0 AND NVL(CODPART, 0) = 0;

   INSERT INTO TMP_NSEDIIPARTRETAIL
   SELECT * FROM NSEDIIPARTRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NCODFISCRETAIL
   SELECT * FROM NCODFISCRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);


   INSERT INTO TMP_NPARTDISCRETAIL
   SELECT * FROM NPARTDISCRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NDELEGATRETAIL
   SELECT * FROM NDELEGATRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NBANCIRETAIL
   SELECT * FROM NBANCIRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);
   COMMIT;
END;

PROCEDURE PREPARE_MODIF_PARTRETAIL
IS
BEGIN
   DELETE TMP_NPARTRETAIL;
   DELETE TMP_NSEDIIPARTRETAIL;
   DELETE TMP_NCODFISCRETAIL;
   DELETE TMP_NPARTDISCRETAIL;
   DELETE TMP_NDELEGATRETAIL;
   DELETE TMP_NBANCIRETAIL;
   DELETE TMP_NLOCALIT;
   DELETE TMP_NBANK   ;


   INSERT INTO TMP_NPARTRETAIL
   SELECT * FROM NPARTRETAIL WHERE CODPARTRETAIL &gt; 0 AND NVL(CODPART, 0) &gt; 0 AND TIPMODIF = &apos;M&apos;;

   INSERT INTO TMP_NSEDIIPARTRETAIL
   SELECT * FROM NSEDIIPARTRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NCODFISCRETAIL
   SELECT * FROM NCODFISCRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);


   INSERT INTO TMP_NPARTDISCRETAIL
   SELECT * FROM NPARTDISCRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NDELEGATRETAIL
   SELECT * FROM NDELEGATRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);

   INSERT INTO TMP_NBANCIRETAIL
   SELECT * FROM NBANCIRETAIL WHERE CODPARTRETAIL IN (SELECt CODPARTRETAIL FROM TMP_NPARTRETAIL);
   COMMIT;
END;

FUNCTION GET_COD_LOCALIT(aCODLOCALIT IN NUMBER, aDENLOCALIT IN VARCHAR2, aCODJUDET IN VARCHAR2, aCODTARA IN VARCHAR2) RETURN NUMBER
IS
 NEWCODLOCALIT NUMBER(20);
 NR NUMBER;
BEGIN
   IF NVL(aCODLOCALIT, 0) &lt;&gt; 0  THEN 
     SELECT COUNT(*) INTO NR FROM NLOCALIT WHERE CODLOCALIT = aCODLOCALIT;
     IF NR &gt; 0 THEN
       RETURN aCODLOCALIT;
     END IF;
   END IF;
   
   IF NVL(aDENLOCALIT, &apos;?&apos;) = &apos;?&apos; THEN RETURN 0; END IF;


   BEGIN
     SELECT CODLOCALIT INTO NEWCODLOCALIT FROM NLOCALIT
     WHERE
       UPPER(DEN_LOCALIT) = UPPER(aDENLOCALIT)
       AND NVL(CODJUDET, 0) = NVL(aCODJUDET, 0)
       AND NVL(CODTARA, 0) = NVL(aCODTARA, 0);
       EXCEPTION WHEN OTHERS THEN NEWCODLOCALIT := 0;
   END;

   IF NEWCODLOCALIT = 0 THEN
      NEWCODLOCALIT := SEQ_NLOCALIT_CODLOCALIT.NEXTVAL;
      INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
                  VALUES (NEWCODLOCALIT, aDENLOCALIT, aCODJUDET, aCODTARA);

      INSERT INTO TMP_NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
                  VALUES (NEWCODLOCALIT, aDENLOCALIT, aCODJUDET, aCODTARA);



   END IF;
   RETURN NEWCODLOCALIT;
   

/*
  IF NVL(aCODLOCALIT, 0) &lt;&gt; 0  THEN 
    RETURN aCODLOCALIT;
  ELSE

     IF NVL(aDENLOCALIT, &apos;?&apos;) = &apos;?&apos; THEN RETURN 0; END IF;


    BEGIN
      SELECT CODLOCALIT INTO NEWCODLOCALIT FROM NLOCALIT
      WHERE
        UPPER(DEN_LOCALIT) = UPPER(aDENLOCALIT)
        AND NVL(CODJUDET, 0) = NVL(aCODJUDET, 0)
        AND NVL(CODTARA, 0) = NVL(aCODTARA, 0);
       EXCEPTION WHEN OTHERS THEN NEWCODLOCALIT := 0;
    END;

    IF NEWCODLOCALIT = 0 THEN
      NEWCODLOCALIT := SEQ_NLOCALIT_CODLOCALIT.NEXTVAL;
      INSERT INTO NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
                  VALUES (NEWCODLOCALIT, aDENLOCALIT, aCODJUDET, aCODTARA);

      INSERT INTO TMP_NLOCALIT(CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
                  VALUES (NEWCODLOCALIT, aDENLOCALIT, aCODJUDET, aCODTARA);



    END IF;
    RETURN NEWCODLOCALIT;

  END IF;
*/  
END;

FUNCTION GET_COD_BANCA(aCODBANCA IN NUMBER, aDENBANCA IN VARCHAR2) RETURN NUMBER
IS
  aCODBANK NUMBER(20);
BEGIN
  IF NVL(aCODBANCA, 0) &lt;&gt; 0 THEN RETURN aCODBANCA;
  ELSE
    IF NVL(aDENBANCA, &apos;?&apos;) = &apos;?&apos; THEN  RETURN 0; END IF;
    BEGIN
      SELECT CODBANK INTO aCODBANK FROM NBANK WHERE UPPER(DENUMIRE) = UPPER(aDENBANCA);
      EXCEPTION WHEN OTHERS THEN aCODBANK := 0;
    END;

    IF aCODBANK = 0 THEN
      aCODBANK := SEQ_NBANK_CODBANK.NEXTVAL;
      INSERT INTO NBANK    (CODBANK, DENUMIRE, SIMBOL) VALUES (aCODBANK, aDENBANCA,  SUBSTR(aDENBANCA, 1, 30));
      INSERT INTO TMP_NBANK(CODBANK, DENUMIRE,SIMBOL) VALUES (aCODBANK, aDENBANCA,  SUBSTR(aDENBANCA, 1, 30));

    END IF;

    RETURN aCODBANK;

  END IF;
END;


PROCEDURE DO_POST_NEWPART_ONBAZA -- se executa pe BAZA si preia inregistrarile noi
IS
 aANINI           NUMBER(5);
 aLUNAINI         NUMBER(5);
 CODNOUPART       NUMBER (20);
 CODNOUAGENDA     NUMBER (20);
 COD_CODFISCALNOU NUMBER (20);
 CODPARTDISCNOU   NUMBER (20);
 CODPARTTRNOU     NUMBER (20);
 CODPARTBNOU      NUMBER(20);
 aCODLOCALIT      NUMBER(20);
 aCODBANCA        NUMBER(20);

 aCODIO           NUMBER (20);

 BEGIN
  BEGIN
    SELECT ANINITIAL, LUNAINITIALA INTO aANINI, aLUNAINI FROM  FIRMALUNI;
    EXCEPTION WHEN OTHERS THEN aANINI := 0; aLUNAINI := 0;
  END;
  FOR V_REC IN (SELECT * FROM TMP_NPARTRETAIL) LOOP
    CODNOUPART := SEQ_NPART_CODPART.NEXTVAL;
    INSERT INTO NPART(CODPART,
                      DEN_PART,
                      REGCOM,
                      CODEXTERN,
                      CODINTERN,
                      COLDISCOUNT,
                      CODCLASA,
                      FIDELIZARE,
                      DATANASTERE,
                      BLOCAT,
                      INFOBLOCAT,
                      CODCATEGPRET,
                      PERSOANAFIZICA,
                      OBS,
                      DATAADAUGARII                     )
                VALUES(CODNOUPART,
                       V_REC.DENUMIRE,
                       V_REC.REGCOM,
                       V_REC.CODEXTERN,
                       V_REC.CODINTERN,
                       V_REC.COLDISCOUNT,
                       V_REC.CODCLASA,
                       V_REC.FIDELIZARE,
                       V_REC.DATANASTERE,
                       V_REC.BLOCAT,
                       V_REC.INFOBLOCAT,
                       V_REC.CODCATEGPRET,
                       V_REC.TIPPART,
                       V_REC.OBS,
                       V_REC.DATACREARE);


    NotifyModif(-11, CODNOUPART, &apos;NPART&apos;);


     aCODIO := PKG_CATEGCONST.GetValConstanta(&apos;IOPARTPJ&apos;, PKG_GLOBALS.ANLUCRU,  PKG_GLOBALS.LUNALUCRU);
     IF V_REC.TIPPART = 1 THEN
       aCODIO := NVL(PKG_CATEGCONST.GetValConstanta(&apos;IOPARTPF&apos;, PKG_GLOBALS.ANLUCRU,  PKG_GLOBALS.LUNALUCRU), PKG_CATEGCONST.GetValConstanta(&apos;IOPARTPJ&apos;, PKG_GLOBALS.ANLUCRU,  PKG_GLOBALS.LUNALUCRU));
     END IF;

     INSERT INTO NPART1(CODPART1, CODPART, CODIOPART, ANSTART, LUNASTART, ALSTART, ALSTOP)
     VALUES     (SEQ_NPART1_CODPART1.NEXTVAL, CODNOUPART,aCODIO,  aANINI, aLUNAINI, 0, 99999);

     INSERT INTO NPART1CRM(CODPART1CRM, CODPART, ANSTART, LUNASTART, ALSTART, ALSTOP)
     VALUES     (SEQ_NPART1CRM_CODPART1CRM.NEXTVAL, CODNOUPART, aANINI, aLUNAINI, 0, 99999);


     UPDATE TMP_NPARTRETAIL
     SET
       CODPART = CODNOUPART
     WHERE
       CODPARTRETAIL = V_REC.CODPARTRETAIL;


     FOR V_REC_D IN (SELECT * FROM TMP_NSEDIIPARTRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL )
     LOOP
       CODNOUAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;
       aCODLOCALIT  := GET_COD_LOCALIT(V_REC_D.CODLOCALIT,V_REC_D.DENLOCALIT, V_REC_D.CODJUDET, V_REC_D.CODTARA);
       INSERT INTO NAGENDA(CODAGENDA,
                           TIP,
                           CODLOCALIT,
                           SEDIUSOCIAL,
                           TELEFON,
                           FAX,
                           EMAIL,
                           SECTOR,
                           STRADA,
                           NR1,
                           NR2,
                           BLOC,
                           SCARA,
                           ETAJ,
                           APART,
                           CODPOSTAL,
                           OBS,
                           CODPART
                            )
                    VALUES(CODNOUAGENDA,
                           0,
                           aCODLOCALIT,
--                           V_REC_D.CODLOCALIT,
                           V_REC_D.SEDIUSOCIAL,
                           V_REC_D.TELEFON,
                           V_REC_D.FAX,
                           V_REC_D.EMAIL,
                           V_REC_D.SECTOR,
                           V_REC_D.STRADA,
                           V_REC_D.NR1,
                           V_REC_D.NR2,
                           V_REC_D.BLOC,
                           V_REC_D.SCARA,
                           V_REC_D.ETAJ,
                           V_REC_D.APART,
                           V_REC_D.CODPOSTAL,
                           V_REC_D.DENUMIRE,
                           CODNOUPART
                          );


      UPDATE TMP_NSEDIIPARTRETAIL
      SET
        CODAGENDA  = CODNOUAGENDA,
        CODLOCALIT = aCODLOCALIT
      WHERE
        CODSEDIU = V_REC_D.CODSEDIU;


     END LOOP;

     FOR V_REC_D IN (SELECT * FROM TMP_NCODFISCRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
     LOOP
       COD_CODFISCALNOU := SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL;
       INSERT INTO NPARTCODFISC(COD_CODFISCAL,
                                CODPART,
                                CODFISCAL,
                                PRINCIPAL)

                  VALUES       (COD_CODFISCALNOU,
                                CODNOUPART,
                                V_REC_D.CODFISCAL,
                                V_REC_D.PRINCIPAL
                               );

        UPDATE TMP_NCODFISCRETAIL
        SET
          COD_CODFISCAL = COD_CODFISCALNOU
        WHERE
          COD = V_REC_D.COD;

     END LOOP;

      FOR V_REC_D IN (SELECt * FROM TMP_NPARTDISCRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
      LOOP
         CODPARTDISCNOU := SEQ_NPARTDISC_CODPARTDISC.NEXTVAL;
         INSERT INTO NPARTDISC(CODPARTDISC,
                              CODPART,
                              CODCATEGDISC,
                              INDEXLOCAL)
                    VALUES   (CODPARTDISCNOU,
                              CODNOUPART,
                              V_REC_D.CODCATEGDISC,
                              V_REC_D.INDEXLOCAL);
        UPDATE TMP_NPARTDISCRETAIL
        SET
          CODPARTDISC = CODPARTDISCNOU
        WHERE
          COD = V_REC_D.COD;
      END LOOP;


    FOR V_REC_D IN (SELECT * FROM TMP_NDELEGATRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
    LOOP
        CODPARTTRNOU := SEQ_NPARTTR_CODPARTTR.NEXTVAL;
        INSERT INTO NPARTTR(CODPARTTR,
                            CODPART,
                            DELEGAT,
                            CNP,
                            DOC,
                            SERIEDOC,
                            NRDOC,
                            ELIBERAT,
                            MIJLTRANSP,
                            NRTRANSP,
                            ACTIV,
                            DATADOC,
                            IMPLICIT,
                            OBS
                            )
                     VALUES(CODPARTTRNOU,
                            CODNOUPART,
                            V_REC_D.DELEGAT,
                            V_REC_D.CNP,
                            V_REC_D.DOC,
                            V_REC_D.SERIEDOC,
                            V_REC_D.NRDOC,
                            V_REC_D.ELIBERAT,
                            V_REC_D.MIJLTRANSP,
                            V_REC_D.NRTRANSP,
                            V_REC_D.ACTIV,
                            V_REC_D.DATADOC,
                            V_REC_D.IMPLICIT,
                            V_REC_D.OBS
                            );



      UPDATE TMP_NDELEGATRETAIL
      SET
        CODPARTTR = CODPARTTRNOU
      WHERE
        COD = V_REC_D.COD;
    END LOOP;


    FOR V_REC_D IN (SELECT * FROM TMP_NBANCIRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
    LOOP
       CODPARTBNOU := SEQ_NPARTB_CODPARTB.NEXTVAL;
       aCODLOCALIT := GET_COD_LOCALIT(V_REC_D.CODLOCALIT,V_REC_D.DENLOCALIT, V_REC_D.CODJUDET, V_REC_D.CODTARA);
       aCODBANCA   := GET_COD_BANCA(V_REC_D.CODBANK,V_REC_D.DENBANCA);

       INSERT INTO NPARTB(CODPARTB,
                          CODPART,
                          CODBANK,
                          IMPLICIT,
                          CODLOCALIT,
                          CONTBANCA,
                          SUCURSALA,
                          CODMONEDA)
       VALUES            (CODPARTBNOU,
                          CODNOUPART,
                          aCODBANCA,
                          V_REC_D.IMPLICIT,
                          aCODLOCALIT,
                          --V_REC_D.CODLOCALIT,
                          V_REC_D.CONTBANCA,
                          V_REC_D.SUCURSALA,
                          V_REC_D.CODMONEDA
                          );



      UPDATE TMP_NBANCIRETAIL
      SET
        CODPARTB   = CODPARTBNOU,
        CODLOCALIT = aCODLOCALIT,
        CODBANK    = aCODBANCA
      WHERE
        COD = V_REC_D.COD;


    END LOOP;


  END LOOP;
 -- COMMIT;
END;



PROCEDURE DO_POST_MODIFPART_ONBAZA -- se executa pe BAZA si preia inregistrarile noi
IS
 CODNOUAGENDA     NUMBER (20);
 COD_CODFISCALNOU NUMBER (20);
 CODPARTDISCNOU   NUMBER (20);
 CODPARTTRNOU     NUMBER (20);
 CODPARTBNOU      NUMBER (20);
 aCODLOCALIT      NUMBER (20);
 aCODBANCA        NUMBER (20);


 BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NPARTRETAIL) LOOP
    UPDATE NPART
    SET
     ( DEN_PART,
       REGCOM,
       CODEXTERN,
       CODINTERN,
       COLDISCOUNT,
       CODCLASA,
       FIDELIZARE,
       DATANASTERE,
       BLOCAT,
       INFOBLOCAT,
       PERSOANAFIZICA,
       OBS
      ) =
      (SELECT
         V_REC.DENUMIRE,
         V_REC.REGCOM,
         V_REC.CODEXTERN,
         V_REC.CODINTERN,
         V_REC.COLDISCOUNT,
         V_REC.CODCLASA,
         V_REC.FIDELIZARE,
         V_REC.DATANASTERE,
         V_REC.BLOCAT,
         V_REC.INFOBLOCAT,
         V_REC.TIPPART,
         V_REC.OBS
       FROM
         DUAL
      )
    WHERE
      CODPART = V_REC.CODPART;

    NotifyModif(-12,  V_REC.CODPART, &apos;NPART&apos;);




     FOR V_REC_D IN (SELECT * FROM TMP_NSEDIIPARTRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
     LOOP
       aCODLOCALIT  := GET_COD_LOCALIT(V_REC_D.CODLOCALIT,V_REC_D.DENLOCALIT, V_REC_D.CODJUDET, V_REC_D.CODTARA);
       IF V_REC_D.CODAGENDA IS NULL THEN
           CODNOUAGENDA := SEQ_NAGENDA_CODAGENDA.NEXTVAL;
           INSERT INTO NAGENDA(CODAGENDA,
                               TIP,
                               CODLOCALIT,
                               SEDIUSOCIAL,
                               TELEFON,
                               FAX,
                               EMAIL,
                               SECTOR,
                               STRADA,
                               NR1,
                               NR2,
                               BLOC,
                               SCARA,
                               ETAJ,
                               APART,
                               CODPOSTAL,
                               OBS,
                               CODPART
                              )
                        VALUES(CODNOUAGENDA,
                               0,
                               aCODLOCALIT,
                               --V_REC_D.CODLOCALIT,
                               V_REC_D.SEDIUSOCIAL,
                               V_REC_D.TELEFON,
                               V_REC_D.FAX,
                               V_REC_D.EMAIL,
                               V_REC_D.SECTOR,
                               V_REC_D.STRADA,
                               V_REC_D.NR1,
                               V_REC_D.NR2,
                               V_REC_D.BLOC,
                               V_REC_D.SCARA,
                               V_REC_D.ETAJ,
                               V_REC_D.APART,
                               V_REC_D.CODPOSTAL,
                               V_REC_D.DENUMIRE,
                               V_REC.CODPART
                              );


          UPDATE TMP_NSEDIIPARTRETAIL
          SET
            CODAGENDA  = CODNOUAGENDA,
            CODLOCALIT = aCODLOCALIT
          WHERE
            CODSEDIU = V_REC_D.CODSEDIU;
       ELSE
         UPDATE NAGENDA
         SET
          (
           CODLOCALIT,
           SEDIUSOCIAL,
           TELEFON,
           FAX,
           EMAIL,
           SECTOR,
           STRADA,
           NR1,
           NR2,
           BLOC,
           SCARA,
           ETAJ,
           APART,
           CODPOSTAL,
           OBS
         ) =
         ( SELECT
             aCODLOCALIT,
             --V_REC_D.CODLOCALIT,
             V_REC_D.SEDIUSOCIAL,
             V_REC_D.TELEFON,
             V_REC_D.FAX,
             V_REC_D.EMAIL,
             V_REC_D.SECTOR,
             V_REC_D.STRADA,
             V_REC_D.NR1,
             V_REC_D.NR2,
             V_REC_D.BLOC,
             V_REC_D.SCARA,
             V_REC_D.ETAJ,
             V_REC_D.APART,
             V_REC_D.CODPOSTAL,
             V_REC_D.DENUMIRE
           FROM
             DUAL
         )
         WHERE
           CODAGENDA = V_REC_D.CODAGENDA;

          UPDATE TMP_NSEDIIPARTRETAIL
          SET
            CODLOCALIT = aCODLOCALIT
          WHERE
            CODSEDIU = V_REC_D.CODSEDIU;


       END IF;
     END LOOP;

     FOR V_REC_D IN (SELECT * FROM TMP_NCODFISCRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
     LOOP
      IF V_REC_D.COD_CODFISCAL IS NULL THEN
       COD_CODFISCALNOU := SEQ_NPARTCODFISC_COD_CODFISCAL.NEXTVAL;
       INSERT INTO NPARTCODFISC(COD_CODFISCAL,
                                CODPART,
                                CODFISCAL,
                                PRINCIPAL)
                  VALUES       (COD_CODFISCALNOU,
                                V_REC.CODPART,
                                V_REC_D.CODFISCAL,
                                V_REC_D.PRINCIPAL
                               );

        UPDATE TMP_NCODFISCRETAIL
        SET
          COD_CODFISCAL = COD_CODFISCALNOU
        WHERE
          COD = V_REC_D.COD;

       ELSE
         UPDATE NPARTCODFISC
         SET
           (CODFISCAL, PRINCIPAL) = (SELECT V_REC_D.CODFISCAL, V_REC_D.PRINCIPAL FROM DUAL )
         WHERE
           COD_CODFISCAL = V_REC_D.COD_CODFISCAL;
       END IF;

     END LOOP;

      FOR V_REC_D IN (SELECT * FROM TMP_NPARTDISCRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
      LOOP
         IF V_REC_D.CODPARTDISC IS NULL THEN
           CODPARTDISCNOU := SEQ_NPARTDISC_CODPARTDISC.NEXTVAL;

           INSERT INTO NPARTDISC(CODPARTDISC,
                                 CODPART,
                                 CODCATEGDISC,
                                 INDEXLOCAL)
                    VALUES     (CODPARTDISCNOU,
                                V_REC.CODPART,
                                V_REC_D.CODCATEGDISC,
                                V_REC_D.INDEXLOCAL);
            UPDATE TMP_NPARTDISCRETAIL
            SET
              CODPARTDISC = CODPARTDISCNOU
            WHERE
              COD = V_REC_D.COD;
         ELSE
           UPDATE NPARTDISC
           SET
             CODCATEGDISC = V_REC_D.CODCATEGDISC,
             INDEXLOCAL   = V_REC_D.INDEXLOCAL
           WHERE
             CODPARTDISC = V_REC_D.CODPARTDISC;
         END IF;
      END LOOP;


    FOR V_REC_D IN (SELECT * FROM TMP_NDELEGATRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
    LOOP
        IF V_REC_D.CODPARTTR IS NULL THEN
            CODPARTTRNOU := SEQ_NPARTTR_CODPARTTR.NEXTVAL;
            INSERT INTO NPARTTR(CODPARTTR,
                                CODPART,
                                DELEGAT,
                                CNP,
                                DOC,
                                SERIEDOC,
                                NRDOC,
                                ELIBERAT,
                                MIJLTRANSP,
                                NRTRANSP,
                                ACTIV,
                                DATADOC,
                                IMPLICIT,
                                OBS
                                )
                         VALUES(CODPARTTRNOU,
                                V_REC.CODPART,
                                V_REC_D.DELEGAT,
                                V_REC_D.CNP,
                                V_REC_D.DOC,
                                V_REC_D.SERIEDOC,
                                V_REC_D.NRDOC,
                                V_REC_D.ELIBERAT,
                                V_REC_D.MIJLTRANSP,
                                V_REC_D.NRTRANSP,
                                V_REC_D.ACTIV,
                                V_REC_D.DATADOC,
                                V_REC_D.IMPLICIT,
                                V_REC_D.OBS
                                );



          UPDATE TMP_NDELEGATRETAIL
          SET
            CODPARTTR = CODPARTTRNOU
          WHERE
            COD = V_REC_D.COD;
       ELSE
         UPDATE NPARTTR SET
         (
          DELEGAT,
          CNP,
          DOC,
          SERIEDOC,
          NRDOC,
          ELIBERAT,
          MIJLTRANSP,
          NRTRANSP,
          ACTIV,
          DATADOC,
          IMPLICIT,
          OBS
         )=
         ( SELECT
              V_REC_D.DELEGAT,
              V_REC_D.CNP,
              V_REC_D.DOC,
              V_REC_D.SERIEDOC,
              V_REC_D.NRDOC,
              V_REC_D.ELIBERAT,
              V_REC_D.MIJLTRANSP,
              V_REC_D.NRTRANSP,
              V_REC_D.ACTIV,
              V_REC_D.DATADOC,
              V_REC_D.IMPLICIT,
              V_REC_D.OBS
           FROM
             DUAL
          )
         WHERE
           CODPARTTR = V_REC_D.CODPARTTR;
       END IF;
    END LOOP;


    FOR V_REC_D IN (SELECT * FROM TMP_NBANCIRETAIL D WHERE D.CODPARTRETAIL = V_REC.CODPARTRETAIL)
    LOOP
       aCODLOCALIT  := GET_COD_LOCALIT(V_REC_D.CODLOCALIT,V_REC_D.DENLOCALIT, V_REC_D.CODJUDET, V_REC_D.CODTARA);
       aCODBANCA    := GET_COD_BANCA(V_REC_D.CODBANK,V_REC_D.DENBANCA);

       IF V_REC_D.CODPARTB IS NULL THEN
           CODPARTBNOU := SEQ_NPARTB_CODPARTB.NEXTVAL;
           INSERT INTO NPARTB(CODPARTB,
                              CODPART,
                              CODBANK,
                              IMPLICIT,
                              CODLOCALIT,
                              CONTBANCA,
                              SUCURSALA,
                              CODMONEDA
                             )
           VALUES            (CODPARTBNOU,
                              V_REC.CODPART,
                              aCODBANCA,
                              V_REC_D.IMPLICIT,
                              aCODLOCALIT,
--                            V_REC_D.CODLOCALIT,
                              V_REC_D.CONTBANCA,
                              V_REC_D.SUCURSALA,
                              V_REC_D.CODMONEDA
                             );



          UPDATE TMP_NBANCIRETAIL
          SET
            CODPARTB   = CODPARTBNOU,
            CODLOCALIT = aCODLOCALIT,
            CODBANK    = aCODBANCA
          WHERE
            COD = V_REC_D.COD;

       ELSE
         UPDATE NPARTB SET
         ( CODBANK,
           IMPLICIT,
           CODLOCALIT,
           CONTBANCA,
           SUCURSALA,
           CODMONEDA
         )=
         (SELECT
            V_REC_D.CODBANK,
            V_REC_D.IMPLICIT,
            V_REC_D.CODLOCALIT,
            V_REC_D.CONTBANCA,
            V_REC_D.SUCURSALA,
            V_REC_D.CODMONEDA
          FROM
            DUAL
         )
         WHERE
           CODPARTB = V_REC_D.CODPARTB;

          UPDATE TMP_NBANCIRETAIL
          SET
            CODLOCALIT = aCODLOCALIT,
            CODBANK    = aCODBANCA
          WHERE
            COD = V_REC_D.COD;



       END IF;
    END LOOP;


  END LOOP;
 -- COMMIT;
END;


PROCEDURE MUTA_CODIFICARI_PE_RETAIL -- se executa pe RETAIL dupa ce a fost actualizata BAZA; are ca scop actualizarea cu codurile de pe baza
IS
BEGIN
    MERGE INTO NLOCALIT L
    USING TMP_NLOCALIT  TL
    ON (TL.CODLOCALIT = L.CODLOCALIT)
    WHEN NOT MATCHED THEN
    INSERT (CODLOCALIT, DEN_LOCALIT, CODJUDET, CODTARA)
    VALUES (TL.CODLOCALIT, TL.DEN_LOCALIT, TL.CODJUDET, TL.CODTARA);

    MERGE INTO NBANK B
    USING TMP_NBANK  TB
    ON (TB.CODBANK = B.CODBANK)
    WHEN NOT MATCHED THEN
    INSERT (CODBANK, DENUMIRE, SIMBOL)
    VALUES (TB.CODBANK, TB.DENUMIRE, SUBSTR(TB.DENUMIRE, 1, 30));


   MERGE INTO NPART P
   USING TMP_NPARTRETAIL PR
   ON  (P.CODPART = PR.CODPART)
   WHEN NOT MATCHED THEN
   INSERT (CODPART, DEN_PART, REGCOM, OBS, CODEXTERN, CODINTERN, TIPPART, COLDISCOUNT, CODCLASA, FIDELIZARE, DATANASTERE, BLOCAT, INFOBLOCAT)
          VALUES (PR.CODPART, PR.DENUMIRE, PR.REGCOM, PR.OBS, PR.CODEXTERN, PR.CODINTERN, PR.TIPPART, PR.COLDISCOUNT, PR.CODCLASA, PR.FIDELIZARE, PR.DATANASTERE, PR.BLOCAT, PR.INFOBLOCAT)
   WHEN MATCHED THEN
   UPDATE SET
     DEN_PART       = PR.DENUMIRE,
     REGCOM         = PR.REGCOM,
     OBS            = PR.OBS,
     CODEXTERN      = PR.CODEXTERN,
     CODINTERN      = PR.CODINTERN,
     PERSOANAFIZICA = PR.TIPPART,
     COLDISCOUNT    = PR.COLDISCOUNT,
     FIDELIZARE     = PR.FIDELIZARE,
     DATANASTERE    = PR.DATANASTERE,
     BLOCAT         = PR.BLOCAT,
     INFOBLOCAT     = PR.INFOBLOCAT,
     CODCLASA       = PR.CODCLASA;


  FOR V_REC IN (SELECT * FROM TMP_NPARTRETAIL) LOOP
    UPDATE NPARTRETAIL
    SET
      CODPART   = V_REC.CODPART,
      TIPMODIF  = NULL
    WHERE
      CODPARTRETAIL = V_REC.CODPARTRETAIL;

    UPDATE EMULARE
    SET
      CODPART   = V_REC.CODPART
    WHERE
      CODPARTRETAIL = V_REC.CODPARTRETAIL;

    UPDATE RESTNP
    SET
      CODPART   = V_REC.CODPART
    WHERE
      CODPARTRETAIL = V_REC.CODPARTRETAIL;


    UPDATE EMULARE
    SET
      CODPARTCOMIS   = V_REC.CODPART
    WHERE
      CODPARTRETAILCOMIS = V_REC.CODPARTRETAIL;


    UPDATE IESIRIRETAIL
    SET
      PARTENER = V_REC.CODPART
    WHERE
      CODPARTRETAIL = V_REC.CODPARTRETAIL;

    UPDATE IESIRIRETAIL
    SET
      CODPARTCOMIS   = V_REC.CODPART
    WHERE
      CODPARTRETAILCOMIS = V_REC.CODPARTRETAIL;


    UPDATE DETALIIET
    SET
      CODPARTTR   = V_REC.CODPART
    WHERE
      CODPARTRETAILTR = V_REC.CODPARTRETAIL;



  END LOOP;


  MERGE INTO NAGENDA A
  USING (SELECT SR.*, PR.CODPART FROM  TMP_NSEDIIPARTRETAIL SR, NPARTRETAIL PR WHERE SR.CODPARTRETAIL = PR.CODPARTRETAIL) S
  ON (A.CODAGENDA = S.CODAGENDA)
  WHEN NOT MATCHED THEN
  INSERT            (CODAGENDA,
                      TIP,
                      CODLOCALIT,
                      SEDIUSOCIAL,
                      TELEFON,
                      FAX,
                      EMAIL,
                      SECTOR,
                      STRADA,
                      NR1,
                      NR2,
                      BLOC,
                      SCARA,
                      ETAJ,
                      APART,
                      CODPOSTAL,
                      OBS,
                      CODPART)
              VALUES (S.CODAGENDA,
                      0,
                      S.CODLOCALIT,
                      S.SEDIUSOCIAL,
                      S.TELEFON,
                      S.FAX,
                      S.EMAIL,
                      S.SECTOR,
                      S.STRADA,
                      S.NR1,
                      S.NR2,
                      S.BLOC,
                      S.SCARA,
                      S.ETAJ,
                      S.APART,
                      S.CODPOSTAL,
                      S.DENUMIRE,
                      S.CODPART)
    WHEN MATCHED THEN
    UPDATE SET
      CODLOCALIT  =   S.CODLOCALIT,
      SEDIUSOCIAL =   S.SEDIUSOCIAL,
      TELEFON     =   S.TELEFON,
      FAX         =   S.FAX,
      EMAIL       =   S.EMAIL,
      SECTOR      =   S.SECTOR,
      STRADA      =   S.STRADA,
      NR1         =   S.NR1,
      NR2         =   S.NR2,
      BLOC        =   S.BLOC,
      SCARA       =   S.SCARA,
      ETAJ        =   S.ETAJ,
      APART       =   S.APART,
      CODPOSTAL   =   S.CODPOSTAL,
      OBS         =   S.DENUMIRE;



   FOR V_REC IN (SELECT * FROM TMP_NSEDIIPARTRETAIL)
   LOOP
     UPDATE NSEDIIPARTRETAIL
     SET
       CODAGENDA  = V_REC.CODAGENDA,
       CODLOCALIT = V_REC.CODLOCALIT
     WHERE
       CODSEDIU = V_REC.CODSEDIU;

     UPDATE EMULARE
     SET
       CODLOCATIE = V_REC.CODAGENDA
     WHERE
       CODSEDIURETAIL = V_REC.CODSEDIU;


     UPDATE IESIRIRETAIL
     SET
       CODLOCATIE = V_REC.CODAGENDA
     WHERE
       CODSEDIURETAIL = V_REC.CODSEDIU;


   END LOOP;



   MERGE INTO NPARTCODFISC CF
   USING (SELECT CFR.*, PR.CODPART FROM TMP_NCODFISCRETAIL CFR, NPARTRETAIL PR WHERE PR.CODPARTRETAIL = CFR.CODPARTRETAIL) CFR
   ON (CF.COD_CODFISCAL = CFR.COD_CODFISCAL)
   WHEN NOT MATCHED THEN
   INSERT (COD_CODFISCAL,
           CODPART,
           CODFISCAL,
           PRINCIPAL
          )
   VALUES (CFR.COD_CODFISCAL,
           CFR.CODPART,
           CFR.CODFISCAL,
           CFR.PRINCIPAL
          )
   WHEN MATCHED THEN
   UPDATE SET
     CODFISCAL = CFR.CODFISCAL,
     PRINCIPAL = CFR.PRINCIPAL;

  FOR V_REC IN (SELECT * FROM TMP_NCODFISCRETAIL)
  LOOP
    UPDATE NCODFISCRETAIL
    SET
      COD_CODFISCAL = V_REC.COD_CODFISCAL
    WHERE
      COD = V_REC.COD;

    UPDATE IESIRIRETAIL
    SET
      CODFISCAL = V_REC.COD_CODFISCAL
    WHERE
      CODFISCALRETAIL = V_REC.COD;

  END LOOP;


  MERGE INTO NPARTDISC PD
  USING (SELECT PDR.*, PR.CODPART FROM TMP_NPARTDISCRETAIL PDR, NPARTRETAIL PR WHERE PR.CODPARTRETAIL = PDR.CODPARTRETAIL) PDR
  ON (PD.CODPARTDISC = PDR.CODPARTDISC)
  WHEN NOT MATCHED THEN
  INSERT (CODPARTDISC, CODPART, CODCATEGDISC, INDEXLOCAL)
  VALUES (PDR.CODPARTDISC, PDR.CODPART, PDR.CODCATEGDISC, PDR.INDEXLOCAL)
  WHEN MATCHED THEN
  UPDATE SET
    CODCATEGDISC = PDR.CODCATEGDISC,
    INDEXLOCAL   = PDR.INDEXLOCAL;

  FOR V_REC IN (SeLECT * FROM TMP_NPARTDISCRETAIL)
  LOOP
    UPDATE NPARTDISCRETAIL
    SET
      CODPARTDISC = V_REC.CODPARTDISC
    WHERE
      COD = V_REC.COD;
  END LOOP;



  MERGE INTO NPARTTR TR
  USING (SELECT D.*, PR.CODPART FROM TMP_NDELEGATRETAIL D, NPARTRETAIL PR WHERE PR.CODPARTRETAIL = D.CODPARTRETAIL) DR
  ON (TR.CODPARTTR = DR.CODPARTTR)
  WHEN NOT MATCHED THEN
  INSERT             (CODPARTTR,
                      CODPART,
                      DELEGAT,
                      CNP,
                      DOC,
                      SERIEDOC,
                      NRDOC,
                      ELIBERAT,
                      MIJLTRANSP,
                      NRTRANSP,
                      ACTIV,
                      DATADOC,
                      IMPLICIT,
                      OBS)
            VALUES (DR.CODPARTTR,
                    DR.CODPART,
                    DR.DELEGAT,
                    DR.CNP,
                    DR.DOC,
                    DR.SERIEDOC,
                    DR.NRDOC,
                    DR.ELIBERAT,
                    DR.MIJLTRANSP,
                    DR.NRTRANSP,
                    DR.ACTIV,
                    DR.DATADOC,
                    DR.IMPLICIT,
                    DR.OBS)
   WHEN MATCHED THEN
   UPDATE SET
    DELEGAT    = DR.DELEGAT,
    CNP        = DR.CNP,
    DOC        = DR.DOC,
    SERIEDOC   = DR.SERIEDOC,
    NRDOC      = DR.NRDOC,
    ELIBERAT   = DR.ELIBERAT,
    MIJLTRANSP = DR.MIJLTRANSP,
    NRTRANSP   = DR.NRTRANSP,
    ACTIV      = DR.ACTIV,
    DATADOC    = DR.DATADOC,
    IMPLICIT   = DR.IMPLICIT,
    OBS        = DR.OBS;

    FOR V_REC IN (SELECT * FROM TMP_NDELEGATRETAIL)
    LOOP
      UPDATE NDELEGATRETAIL
      SET
        CODPARTTR = V_REC.CODPARTTR
      WHERE
        COD = V_REC.COD;


      UPDATE IESIRIRETAIL
      SET
        DELEGAT = V_REC.CODPARTTR
      WHERE
        DELEGATRETAIL = V_REC.COD;

    END LOOP;


   MERGE INTO NPARTB PB
   USING (SELECT BR.*, PR.CODPART FROM TMP_NBANCIRETAIL BR, NPARTRETAIL PR WHERE PR.CODPARTRETAIL = BR.CODPARTRETAIL) PBR
   ON (PB.CODPARTB = PBR.CODPARTB)
   WHEN NOT MATCHED THEN
   INSERT (CODPARTB,
           CODPART,
           CODBANK,
           IMPLICIT,
           CODLOCALIT,
           CONTBANCA,
           SUCURSALA,
           CODMONEDA
           )
   VALUES (PBR.CODPARTB,
           PBR.CODPART,
           PBR.CODBANK,
           PBR.IMPLICIT,
           PBR.CODLOCALIT,
           PBR.CONTBANCA,
           PBR.SUCURSALA,
           PBR.CODMONEDA
           )
  WHEN MATCHED THEN
  UPDATE SET
    CODBANK    = PBR.CODBANK,
    IMPLICIT   = PBR.IMPLICIT,
    CODLOCALIT = PBR.CODLOCALIT,
    CONTBANCA  = PBR.CONTBANCA,
    SUCURSALA  = PBR.SUCURSALA,
    CODMONEDA  = PBR.CODMONEDA;




  FOR V_REC IN (SELECT * FROM TMP_NBANCIRETAIL)
  LOOP
    UPDATE NBANCIRETAIL
    SET
      CODPARTB   = V_REC.CODPARTB,
      CODLOCALIT = V_REC.CODLOCALIT,
      CODBANK    = V_REC.CODBANK
    WHERE
      COD = V_REC.COD;
  END LOOP;




  --COMMIT;
END;



end PKG_NPARTRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_NZONE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32B91DB80A4A08BEAF0A79B930193C2F88C2A695</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_NZONE IS

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
	BEGIN
	  
		INSERT INTO tmp_nzone(codzona,den_zona,simbol,obs)
		 SELECT codzona,den_zona,simbol,obs FROM nzone WHERE codzona = recid;
		COMMIT; 
	END;
	
	PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
   tmp NUMBER(20);
	BEGIN
	  SELECT codzona INTO tmp FROM nzone WHERE codzona = RecId FOR UPDATE NOWAIT;
	END;
	
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ) IS
	BEGIN
	  IF operation = 0 THEN
		  SELECT codzona INTO RecId FROM tmp_nzone;
			
			UPDATE nzone SET (den_zona,SIMBOL,OBS)= (SELECT den_zona,SIMBOL,OBS FROM tmp_nzone) WHERE codzona = recid;
		ELSE
		 SELECT seq_nzone_codzona.nextval INTO RECID FROM DUAL;
		 INSERT INTO nzone(codzona,den_zona,simbol,obs)
		  SELECT RECID,den_zona,simbol,obs FROM tmp_nzone;
			
		
		END IF;
   NotifyModif(OPERATION, RECID, &apos;NZONE&apos;);  

	COMMIT;	
	END;
	
	PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
	BEGIN
	  SP_LOCKRECORD(recid);
		DELETE FROM nzone WHERE codzona = recid;
    NotifyModif(2, RECID, &apos;NZONE&apos;);  

		COMMIT;
		
	END;
	
	PROCEDURE SP_INSERTRECORD IS
	BEGIN
	  INSERT INTO  TMP_Nzone FIELDS( codzona ) VALUES (0) ;
    COMMIT;
	END;
	
end pkg_nzone; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OBIECTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8162ED5783CCC2BB836545FF684F0B491998439C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_OBIECTIVE is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodOBIECTIV INTO Tmp FROM OBIECTIVE WHERE CodOBIECTIV = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM OBIECTIVE WHERE CodOBIECTIV = RecId ;
  NotifyModif(2, RECID, &apos;OBIECTIVE&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_OBIECTIVE FIELDS( CodOBIECTIV ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_OBIECTIVE SELECT * FROM OBIECTIVE WHERE CodOBIECTIV = RECID;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodOBIECTIV INTO RECID FROM TMP_OBIECTIVE;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE OBIECTIVE
    SET
     (DEN_OBIECTIV, TIP) = (SELECT DEN_OBIECTIV, TIP FROM TMP_OBIECTIVE)
    WHERE
      CodOBIECTIV = RECID;
  ELSE  -- INSERT
    SELECT SEQ_OBIECTIVE_CODOBIECTIV.NextVal INTO RecId FROM DUAL;
    INSERT INTO OBIECTIVE(CodOBIECTIV, DEN_OBIECTIV, TIP)
    SELECT RECID, DEN_OBIECTIV, TIP FROM TMP_OBIECTIVE;
  END IF; 

  NotifyModif(OPERATION, RECID, &apos;OBIECTIVE&apos;);  

  COMMIT;
  
END;


end PKG_OBIECTIVE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06D11E8147E66B5041F2221E77D9C2871FBDE11D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_OFERTA IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_28&apos;;

function ExistaOfertaValabila(aCodObiect in number) return number is
aCount number(10);
begin
  select count(*) into aCount
  from oferta1 o1
       inner join oferta o on o.codoferta = o1.codoferta
       inner join num1 um on o1.umsec = um.codum1
  where o1.codobiect = aCodObiect and nvl(o.operat,0) = 1 and nvl(o.anulat,0) &lt;&gt; 1
        and sysdate between o.datastart and o.dataend and o.tipdoc = 51;

  return aCount;
end;

function GetCodOferta1(aCodObiect in number, aData in date, aCodPart in number, aCodLocatie in number, aSubunitatea in number, aTipDoc in number, aCant in number) return number is
vCodOferta1 number(20);
begin
  --insert into x(test) values(&apos;codobiect : &apos;||aCodObiect||&apos; - data : &apos;||aData||&apos; - codpart : &apos;||aCodPart||&apos; - codlocatie : &apos;||aCodLocatie||&apos; - subunitatea : &apos;||aSubunitatea||
  --                           &apos; - Tipdoc : &apos;||atipdoc||&apos; - Cant : &apos;||aCant);
  begin
    select o1.codoferta1 into vCodOferta1
    from oferta1 o1
         inner join oferta o on o.codoferta = o1.codoferta and (o.subunitatea = aSubunitatea or nvl(o.toatesubunit,0) = 1)
    where o1.codobiect = aCodObiect and (o.codlocatie = aCodLocatie or nvl(o.codlocatie,0) = 0) and nvl(aData, pkg_globals.data0) between o.datastart and o.dataend and o.partener = aCodpart and o.tipdoc = aTipDoc
    and o1.cantmin = (select max(oo1.cantmin)
                      from oferta1 oo1
                           inner join oferta oo on oo.codoferta = oo1.codoferta and (oo.subunitatea = aSubunitatea or nvl(oo.toatesubunit,0) = 1)
                      where oo1.codobiect = aCodObiect and (oo.codlocatie = aCodLocatie or nvl(oo.codlocatie,0) = 0) and aData between oo.datastart and oo.dataend and oo.partener = aCodPart and oo.tipdoc = 51
                            and aCant &gt;= oo1.cantmin);
  exception when others then vCodOferta1 := 0;
  end;

  return vCodOferta1;
end;

function GetCodOferta1PretMin(aCodObiect in number, aData in date) return number is
vCodOferta1 number(20);
vPret number(20,7);
begin
  vPret := 0.0;
  vCodOferta1 := 0;
  for v_rec in (
    select o1.codoferta1, o1.pret
    from nartobj obj
         inner join nartcli acli on acli.codobiect = obj.codobiect and acli.implicit = 1
         inner join oferta1 o1 on o1.codobiect = obj.codobiect
         inner join oferta o on o.codoferta = o1.codoferta and o.partener = acli.codpart
    where o1.codobiect = aCodObiect and nvl(aData, pkg_globals.data0) between o.datastart and o.dataend and o.tipdoc = 51
          and (pkg_globals.GETSUBUNITATE = 1 or o.subunitatea = pkg_globals.GETSUBUNITATE)
  ) loop
    if v_rec.pret &gt; vPret then
      vPret := v_rec.Pret;
      vCodOferta1 := v_rec.codoferta1;
    end if;
  end loop;

  return vCodOferta1;
end;

function GetCodOferta1PretMinPart(aCodObiect in number, aData in date, aCodOferta in number) return number is
vPret number(20,7);
begin
  vPret := 0;
  for v_rec in (
    select o1.codoferta1, o1.pret
    from nartobj obj
         inner join oferta1 o1 on o1.codobiect = obj.codobiect
         inner join oferta o on o.codoferta = o1.codoferta
    where o1.codobiect = aCodObiect
          and o.CodOferta = aCodOferta
  ) loop
    vPret := v_rec.Pret;
    Exit;
  end loop;

  return vPret;
end;

function GetPretMediuOferte(aCodobiect in number, aCodArticol in number default 0, aRetGenerica in boolean default False, aCodAtribut in number default -1, aModGenerice in number default 0) return number is
aPret number(20,7);
begin
  if NVL(aModGenerice,0) = 1 then
    begin
      select nvl(avg(Round(O1.PRET * UM.Paritate * Coalesce(1+O1.PROCADAOS/100,1),7)*
             PKG_LIST_BASE_UTILS.GETCURSREFERINTA(o.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
             last_day(to_date(&apos;01.&apos;||case when pkg_globals.GetLUNALUCRU &lt; 10 then &apos;0&apos;||to_char(pkg_globals.GetLUNALUCRU) else to_char(pkg_globals.GetLUNALUCRU) end||&apos;.&apos;||to_char(pkg_globals.GetanLUCRU), &apos;dd.mm.yyyy&apos;)))),0)
             into aPret
      from oferta1 o1
           inner join nartobj obj on o1.codobiect = obj.codobiect
           inner join oferta o on o.codoferta = o1.codoferta
           inner join num1 um on o1.umsec = um.codum1
      where obj.codarticol = NVL(aCodArticol,0) and nvl(o.operat,0) = 1 and nvl(o.anulat,0) &lt;&gt; 1
            and sysdate between o.datastart and o.dataend and o.tipdoc = 51;
    exception when others then
      aPret := 0;
    end;
  else
    if aRetGenerica and NVL(aCodAtribut,-1) = 0 then
      begin
        select nvl(avg(Round(O1.PRET * UM.Paritate * Coalesce(1+O1.PROCADAOS/100,1),7)*
               PKG_LIST_BASE_UTILS.GETCURSREFERINTA(o.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
               last_day(to_date(&apos;01.&apos;||case when pkg_globals.GetLUNALUCRU &lt; 10 then &apos;0&apos;||to_char(pkg_globals.GetLUNALUCRU) else to_char(pkg_globals.GetLUNALUCRU) end||&apos;.&apos;||to_char(pkg_globals.GetanLUCRU), &apos;dd.mm.yyyy&apos;)))),0)
               into aPret
        from oferta1 o1
             inner join nartobj obj on o1.codobiect = obj.codobiect
             inner join oferta o on o.codoferta = o1.codoferta
             inner join num1 um on o1.umsec = um.codum1
        where obj.codarticol = NVL(aCodArticol,0) and nvl(o.operat,0) = 1 and nvl(o.anulat,0) &lt;&gt; 1
              and sysdate between o.datastart and o.dataend and o.tipdoc = 51;
      exception when others then
        aPret := 0;
      end;
    else
      begin
        select nvl(avg(Round(O1.PRET * UM.Paritate * Coalesce(1+O1.PROCADAOS/100,1),7)*
               PKG_LIST_BASE_UTILS.GETCURSREFERINTA(o.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
               last_day(to_date(&apos;01.&apos;||case when pkg_globals.GetLUNALUCRU &lt; 10 then &apos;0&apos;||to_char(pkg_globals.GetLUNALUCRU) else to_char(pkg_globals.GetLUNALUCRU) end||&apos;.&apos;||to_char(pkg_globals.GetanLUCRU), &apos;dd.mm.yyyy&apos;)))),0)
               into aPret
        from oferta1 o1
             inner join oferta o on o.codoferta = o1.codoferta
             inner join num1 um on o1.umsec = um.codum1
        where o1.codobiect = aCodObiect and nvl(o.operat,0) = 1 and nvl(o.anulat,0) &lt;&gt; 1
              and sysdate between o.datastart and o.dataend and o.tipdoc = 51;
      exception when others then
        aPret := 0;
      end;
    end if;
  end if;
  return aPret;
end;

function GetPMPOferte(aCodobiect in number, aDate in varchar2) return number is
aPret number(20,7);
begin
  begin
    select nvl(
           Round(
           avg(
           O1.PRET * UM.Paritate * Coalesce(1+O1.PROCADAOS/100,1)*
           PKG_LIST_BASE_UTILS.GETCURSREFERINTA(o.moneda, pkg_categconst.GetValConstanta(&apos;BancaCursPUV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),to_date(aDate, &apos;dd.mm.yyyy&apos;))
           )
           ,7)
           ,0)
           into aPret
    from oferta1 o1
         inner join oferta o on o.codoferta = o1.codoferta
         inner join num1 um on o1.umsec = um.codum1
    where o1.codobiect = aCodObiect and nvl(o.operat,0) = 1 and nvl(o.anulat,0) &lt;&gt; 1
          and to_date(aDate, &apos;dd.mm.yyyy&apos;) between o.datastart and o.dataend and o.tipdoc = 51;
  exception when others then
    aPret := 0;
  end;
  return aPret;
end;

FUNCTION GetPretOfertaPartLocObj(aCodPart IN NUMBER, aCodLocatie IN NUMBER, aCodObiect IN NUMBER, aDataRef IN VARCHAR2, aTipDoc IN NUMBER) return number is
  aPret number(20,7);
BEGIN
  BEGIN
    SELECT o1.pret into aPret
    FROM oferta1 o1 inner join oferta o on o1.codoferta = o.codoferta
    WHERE o1.codobiect = aCodObiect
      AND (o.codlocatie = aCodLocatie or Coalesce(o.codlocatie,0) = 0)
      AND to_date(aDataRef, &apos;dd.mm.yyyy&apos;) BETWEEN o.datastart AND o.dataend
      AND o.partener = aCodpart
      AND o.tipdoc = aTipDoc;
  EXCEPTION WHEN OTHERS THEN
    aPret := 0;
  END;
  RETURN aPret;
END;

FUNCTION GetPretOferta(aCodObiect IN NUMBER, aCant IN NUMBER, aDataRef IN VARCHAR2, aCodPart IN NUMBER, aCodLocatie IN NUMBER, aSubunitatea IN NUMBER, aTipOfe IN NUMBER) RETURN NUMBER IS
  aPretOfe number(20,7) := 0;
  dDataRef DATE         := To_Date(aDataRef, &apos;dd.mm.yyyy&apos;);
BEGIN
  BEGIN
    SELECT Min(o1.pret) KEEP (Dense_Rank last order by o1.cantmin) INTO aPretOfe
    FROM oferta1 o1
      INNER JOIN oferta o on o.codoferta = o1.codoferta
    WHERE o1.codobiect = aCodObiect
      AND dDataRef between o.datastart and o.dataend
      AND NVL(o.partener, 0) = aCodpart
      AND (o.subunitatea = aSubunitatea OR Coalesce(o.toatesubunit,0) = 1)
      AND (o.codlocatie = aCodLocatie OR Coalesce(o.codlocatie,0) = 0)
      AND o.tipdoc = aTipOfe
      AND aCant &gt;= o1.cantmin;
  EXCEPTION
    WHEN others THEN aPretOfe := 0;
  END;

  RETURN aPretOfe;
end;


PROCEDURE Umple_TMP_SelArtOfe(
            pTipOfe     IN NUMBER,
            pDataRef    IN VARCHAR2,
            pCodPart    IN NUMBER,
            pCodLocatie IN NUMBER,
            pSubunit    IN NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  vDataRef DATE  := To_Date(pDataRef,&apos;dd.mm.yyyy&apos;);
  --aCLASAP NUMBER(20) := 0;
  aCodIdentPart VARCHAR2(250);

BEGIN
  DELETE TMP_SelArtOfe;
  BEGIN
    SELECT CODIDENT INTO aCodIdentPart FROM NPART P, NCLASEP CLP
    WHERE
      CODPART = pCodPart
      AND NVL(P.CODCLASA, 0) = CLP.CODCLASEP;
    EXCEPTION WHEN OTHERS THEN aCodIdentPart := &apos;0&apos;;
  END;

  IF pCodPart &lt;&gt; 0 AND pCodLocatie &lt;&gt; 0 THEN
    INSERT INTO TMP_SelArtOfe(CodOferta1, CodObiect)
    SELECT O1.CodOferta1, O1.CodObiect
    FROM OFERTA O INNER JOIN OFERTA1 O1 ON O1.CodOferta = O.CodOferta
    WHERE O.Operat = 1 AND O.Anulat &lt;&gt; 1 AND O.Blocat &lt;&gt; 1 AND O.TipDoc = pTipOfe
      AND ((O.DataCerere is null) OR (OFERTAT = 1))
      AND O.DataStart &lt;= vDataRef AND O.DataEnd &gt;= vDataRef
      AND Nvl(O.Partener,0) = pCodPart AND Nvl(O.CodLocatie,0) = pCodLocatie
      AND (O.ToateSubunit = 1 OR O.Subunitatea = pSubunit);
  END IF;

  IF pCodPart &lt;&gt; 0 THEN
    INSERT INTO TMP_SelArtOfe(CodOferta1, CodObiect)
    SELECT O1.CodOferta1, O1.CodObiect
    FROM OFERTA O INNER JOIN OFERTA1 O1 ON O1.CodOferta = O.CodOferta
    WHERE O.Operat = 1 AND O.Anulat &lt;&gt; 1 AND O.Blocat &lt;&gt; 1 AND O.TipDoc = pTipOfe
      AND ((O.DataCerere is null) OR (OFERTAT = 1))
      AND O.DataStart &lt;= vDataRef AND O.DataEnd &gt;= vDataRef
      AND Nvl(O.Partener,0) = pCodPart AND Nvl(O.CodLocatie,0) = 0
      AND (O.ToateSubunit = 1 OR O.Subunitatea = pSubunit)
      AND NOT EXISTS (SELECT TMP.CODOFERTA1 FROM TMP_SelArtOfe TMP WHERE TMP.CODOFERTA1 = O1.CODOFERTA1);
  END IF;

  IF pCodPart = 0 THEN
    INSERT INTO TMP_SelArtOfe(CodOferta1, CodObiect)
    SELECT O1.CodOferta1, O1.CodObiect
    FROM OFERTA O INNER JOIN OFERTA1 O1 ON O1.CodOferta = O.CodOferta
    WHERE O.Operat = 1 AND O.Anulat &lt;&gt; 1 AND O.Blocat &lt;&gt; 1 AND O.TipDoc = pTipOfe
      AND ((O.DataCerere is null) OR (OFERTAT = 1))
      AND O.DataStart &lt;= vDataRef AND O.DataEnd &gt;= vDataRef
      AND Nvl(O.Partener,0) &gt; 0
      AND (O.ToateSubunit = 1 OR O.Subunitatea = pSubunit);
  END IF;

  INSERT INTO TMP_SelArtOfe(CodOferta1, CodObiect)
  SELECT O1.CodOferta1, O1.CodObiect
  FROM
    OFERTA O
    INNER JOIN OFERTA1 O1 ON O1.CodOferta = O.CodOferta
    LEFT JOIN NCLASEP CLAP ON CLAP.CODCLASEP = O.CODCLASEP
  WHERE O.Operat = 1 AND O.Anulat &lt;&gt; 1 AND O.Blocat &lt;&gt; 1 AND O.TipDoc = pTipOfe
    AND ((O.DataCerere is null) OR (OFERTAT = 1))
    AND O.DataStart &lt;= vDataRef AND O.DataEnd &gt;= vDataRef
    AND (Nvl(O.Partener,0) = 0 AND (Nvl(O.CODCLASEP, 0) = 0)
         OR INSTRB(aCodIdentPart,CLAP.CODIDENT) = 1--Nvl(O.CODCLASEP, 0) = aCLASAP )
         )
    AND (O.ToateSubunit = 1 OR O.Subunitatea = pSubunit)
    AND NOT EXISTS (SELECT TMP.CODOFERTA1 FROM TMP_SelArtOfe TMP WHERE TMP.CODOFERTA1 = O1.CODOFERTA1);

  COMMIT;
END;

FUNCTION OfertaVal(aCodOferta IN NUMBER) RETURN NUMBER IS
M1 NUMBER(20);
M2 NUMBER(20);
BEGIN
  begin
  select Extract(MONTH FROM O.DataStart)+12*Extract(Year FROM O.DataStart) INTO M1
  from oferta O
  where O.Codoferta = aCodOferta;
  exception when others then
    M1 := 99999999999999;
  end;

  begin
  select Extract(MONTH FROM O.Dataend)+12*Extract(Year FROM O.DataEnd) INTO M2
  from oferta O
  where O.Codoferta = aCodOferta;
  exception when others then
    M2 := 0;
  end;
  if (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &lt;= M2) AND (PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU &gt;= M1) then
    Return 1;
  else
    Return 0;
  end if;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodOferta INTO Tmp FROM OFERTA WHERE CodOferta = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_OFERTA FIELDS( CodOferta ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(PKG_GLOBALS.GetTipOferta);
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aCarnetDoc  NUMBER (20);
  aNrDoc      NUMBER (20);
  aCodSubunit NUMBER(20);
  aDataDoc    DATE;
  aDoc        VARCHAR2(200);
  aTIPOFERTA  NUMBER(5);
BEGIN
  SP_LOCKRECORD(RecId);

  SELECT  CarnetDoc, NrDoc, Subunitatea, DataStart, Decode(TipDoc,50,&apos;OC&apos;,51,&apos;OF&apos;)||NrDoc||&apos;/&apos;||DataStart||&apos;-&apos;||DataEnd, TIPDOC
  INTO    aCarnetDoc, aNrDoc, aCodSubunit, aDataDoc, aDoc, aTIPOFERTA
  FROM    OFERTA
  WHERE   CodOferta = recId;
  
 PKG_CFGTABLES.EXT_DELETERECORD (recId, aTIPOFERTA);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;OFERTA&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;


  DELETE FROM OFERTA1 WHERE CodOferta = RecId ;
  DELETE FROM OFERTA  WHERE CodOferta = RecId ;

  DELETE FROM CMDAPROBARI WHERE  CODDOC = RECID AND TIPDOC = aTIPOFERTA;

  PKG_CARNETEDOC.RELEASENUMARDOC(aCarnetDoc, aNrDoc);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCarnetDoc);

  NotifyModif(2, RECID, &apos;OFERTA&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aTIPOFERTA    NUMBER(5);
  aModulCereale NUMBER := Nvl(pkg_categconst.GetValConstanta(&apos;ModulCereale&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru),2);
  aPartRO       NUMBER := 0;
  aPart         NUMBER := 0;
  aClaseP       NUMBER := 0;
  aTipB         NUMBER := 0;
BEGIN

  INSERT INTO TMP_OFERTA (
    CodOferta, TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd,DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT,
    TipBeneficiar, CodClaseP, NRI, Partener, An, Luna,
    Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, UserId, DataCreare, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE,
    Agent, NRMAXAPROBARI, CodNParcAut, CodPartComis, SendMail, ProcDisc, CodAnaliza)
  SELECT
    CodOferta, TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd, DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT,
    Coalesce(TipBeneficiar,0), CodClaseP, NRI, Partener, PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GetLunaLucru,
    Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, UserId, DataCreare, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE,
    Agent, NRMAXAPROBARI, CodNParcAut, CodPartComis, 0, ProcDisc, CodAnaliza
  FROM OFERTA
  WHERE CodOferta = RecId;

  select coalesce(o.partener,0), coalesce(o.codclasep,p.codclasa,0), coalesce(o.tipbeneficiar,0)
  into aPart, aClaseP, aTipB
  from tmp_oferta o
       left join npart p on p.codpart = o.partener;
 
  delete from tmp_nartcli;
  insert into tmp_nartcli(
  codartcli,
  codobiect,
  codpart,
  denumire,
  codextern,
  umsec,
  codmoneda,
  pret,
  tipcodafisat,
  umcorelat,
  implicit,
  codlaclient,
  codclasep,
  codgama,
  codintern,
  obs,
  obs2,
  umsecimpdoc,
  duratatr,
  zilestoc,
  gln,
  idspecific
  )
  select 
  codartcli,
  codobiect,
  codpart,
  denumire,
  codextern,
  umsec,
  codmoneda,
  pret,
  tipcodafisat,
  umcorelat,
  implicit,
  codlaclient,
  codclasep,
  codgama,
  codintern,
  obs,
  obs2,
  umsecimpdoc,
  duratatr,
  zilestoc,
  gln,
  idspecific
  from nartcli
  where codpart = aPart;
  if aClaseP &gt; 0 then
    insert into tmp_nartcli(
    codartcli,
    codobiect,
    codpart,
    denumire,
    codextern,
    umsec,
    codmoneda,
    pret,
    tipcodafisat,
    umcorelat,
    implicit,
    codlaclient,
    codclasep,
    codgama,
    codintern,
    obs,
    obs2,
    umsecimpdoc,
    duratatr,
    zilestoc,
    gln,
    idspecific
    )
    select 
    cli.codartcli,
    cli.codobiect,
    cli.codpart,
    cli.denumire,
    cli.codextern,
    cli.umsec,
    cli.codmoneda,
    cli.pret,
    cli.tipcodafisat,
    cli.umcorelat,
    cli.implicit,
    cli.codlaclient,
    cli.codclasep,
    cli.codgama,
    cli.codintern,
    cli.obs,
    cli.obs2,
    cli.umsecimpdoc,
    cli.duratatr,
    cli.zilestoc,
    cli.gln,
    cli.idspecific
    from nartcli cli
         left join tmp_nartcli tmp on tmp.codobiect = cli.codobiect
    where cli.codclasep = aClaseP and tmp.codobiect is null; 
  end if;

  BEGIN
    SELECT TIPDOC, CASE WHEN Upper(Trim(F.CodFiscal)) LIKE &apos;RO%&apos; THEN 1 ELSE 0 END PartRO
    INTO aTIPOFERTA, aPartRO
    FROM TMP_OFERTA O LEFT JOIN NPARTCODFISC F ON F.COD_CODFISCAL = O.CODFISCAL;
  EXCEPTION
    WHEN OTHERS THEN aTIPOFERTA := 0;
  END;
  
  PKG_CFGTABLES.CHECK_STRUCT_EXTENSIE_X_TIPDOC(aTIPOFERTA);
  
  INSERT INTO TMP_OFERTA1 (
    CodOferta1, CodOferta, CodObiect, CodArticol, UMSec, CantMin, CantMax, Pret, PretRef,
    Obs, ZileL, ZileC, ProcAdaos, ProcDiscount, CodExtOfe, CantMinUM1, CANTOPTIM, CANTOPTIMUM1, D1, D2, D3,
    IndexLocal,
    DenObiect, DenUM, Paritate,
    PROCTVA,
    DenArtCli, CodExtCli, CodLaClient, CodClaseP,
    PU,
    RelatieUM1, UM1, DenUM1, CODCATPRET, PRETUM1, TIPCATPRET, CODEXTERN, CODINTERN, CODEXTERNART,
    PeArticol, TipLinie, CodProiect, Proiect, DataCertifI, Datacertiff, Codreteta, Consum, codcentru,
    PretAchiz, CodAnalizaNod, GestAct,
    Marja,
    ValMarja,
    ValAchiz,
    ROTUNJIRE,
    DEN_GRECHIV, 
    CODVAMAL, 
    PRODUCATOR, 
    CLASAARTICOL,
    PUREAL,
    DENARTCLI_INI,
    CODEXTCLI_INI,
    CODLACLIENT_INI,
    CODLINIEDOCIMP
  )
  SELECT
    O1.CodOferta1, O1.CodOferta, O1.CodObiect, O1.CodArticol, O1.UMSec, O1.CantMin/ U.Paritate, O1.CantMax/ U.Paritate, O1.Pret * U.Paritate, O1.PretRef * U.Paritate,
    O1.Obs, O1.ZileL, O1.ZileC, O1.ProcAdaos, O1.ProcDiscount, O1.CodExtOfe, O1.CantMinUM1, O1.CANTOPTIM, O1.CANTOPTIMUM1, O1.D1, O1.D2, O1.D3,
    ROW_NUMBER() OVER (PARTITION BY O1.CodOferta ORDER BY O1.IndexLocal, O1.CodOferta1 ASC),
    OBJ.Denumire, U.Den_UM1, U.Paritate,
    CASE
      WHEN aModulCereale = 1 AND Trim(obj.codd394) IS NOT NULL AND aPartRO = 1 THEN 0
      ELSE TL.PROCENT --PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU)
    END PROCTVA,
    AC.Denumire, AC.CodExtern, AC.CodLaClient, Nvl(AC.CodClaseP,0),
    O1.Pret * U.Paritate * Coalesce(1+O1.ProcAdaos/100,1),
    A.RelatieUM1, A.UM1, UMSpec.Den_UM, O1.CODCATPRET, O1.PRETUM1, CAT.TIP, OBJ.CODEXTERN, OBJ.CODINTERN, A.CODEXTERNART,
    CASE WHEN Nvl(O1.CodArticol,0) &gt; 0 THEN 1 ELSE 0 END PeArticol, DECODE(NVL(A.TIPARTICOL, 0), 0, &apos;=&apos;, 2, &apos;=&apos;, &apos;S&apos;) TipLinie,
    O1.Codproiect, PR.Versiune, O1.Datacertifi, O1.Datacertiff, PN.Codreteta, case when PN.CODRETETA &gt; 0 THEN 1 ELSE 0 END, O1.CODCENTRU,
    O1.PretAchiz * U.Paritate, O1.CodAnalizaNod, O1.GestAct,
    CASE WHEN Coalesce(O1.PretAchiz,0) &gt; 0 THEN (O1.Pret*(100+nvl(O1.ProcDiscount,0))/100 - O1.PretAchiz)/(O1.Pret*(100+nvl(O1.ProcDiscount,0))/100)*100 ELSE 0 END,
    CASE WHEN Coalesce(O1.PretAchiz,0) &gt; 0 THEN (O1.Pret*(100+nvl(O1.ProcDiscount,0))/100 - O1.PretAchiz)*O1.CantMin ELSE 0 END,
    O1.PretAchiz*O1.CantMin,
    CASE
     WHEN aTIPOFERTA = 51 THEN OBJ.ROTUNJIRE 
     ELSE OBJ.ROTVALUTA
    END,
    grech.denumire AS DEN_GRECHIV, 
    OBJ.CODVAMAL, 
    PROD.DEN_PART AS PRODUCATOR, 
    NC.DEN_CLASEA AS CLASAARTICOL,
    O1.Pret * U.Paritate * Coalesce(1+O1.ProcAdaos/100,1) * Coalesce(1+O1.ProcDiscount/100,1),
    AC.Denumire, AC.CodExtern, AC.CodLaClient, O1.CODLINIEDOCIMP     
  FROM OFERTA O
    INNER JOIN OFERTA1 O1   ON O1.CodOferta = O.CodOferta
    INNER JOIN NARTOBJ OBJ  ON Obj.CodObiect = O1.CodObiect
    INNER JOIN NART A       ON A.CodArticol = Obj.CodArticol
    INNER JOIN NART1 AL     ON AL.CODARTICOL = A.CODARTICOL AND PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU BETWEEN AL.ALSTART AND AL.ALSTOP
    INNER JOIN NTVA1 TL     ON TL.CODTVA = AL.CODTVA AND PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU BETWEEN TL.ALSTART AND TL.ALSTOP
    INNER JOIN NUM1 U       ON U.CodUM1 = O1.UMSec
    LEFT JOIN NPART P       ON P.CodPart = CASE WHEN Coalesce(TipBeneficiar,0) = 1 THEN 0 ELSE O.Partener END
    LEFT JOIN tmp_nartcli AC ON AC.CODOBIECT = O1.CODOBIECT
    LEFT JOIN NUM UMSpec    ON UMSpec.CODUM = A.UM1
    LEFT JOIN NCATPRET CAT  ON CAT.CODCATPRET = O1.CODCATPRET
    LEFT JOIN PROIECT PR    ON PR.CODPROIECT = O1.CODPROIECT
    LEFT JOIN PROIECTNOD PN ON PN.CODPROIECT = PR.CODPROIECT AND PN.NODORIGINAL = 0
    LEFT JOIN NECHIV NECH   ON nech.codobiect = OBJ.codobiect
    LEFT JOIN GRECHIV GRECH ON grech.codgrechiv = nech.codgrupa
    LEFT JOIN NPART PROD    ON OBJ.CODPRODUCATOR = PROD.CODPART
    LEFT JOIN NCLASEA NC    ON NC.CODCLASEA = A.CLASA
  WHERE O.CodOferta = RecId;

  UPDATE TMP_OFERTA1 SET 
    VALOARE = Cantmin * pkg_preturi.WMROTOPRET(rotunjire, pu),
    PU      = pkg_preturi.WMROTOPRET(rotunjire, pu);

  UPDATE tmp_oferta SET valoare = (SELECT SUM(Valoare*Coalesce(1+ProcDiscount/100,1)) FROM tmp_oferta1);

  update tmp_oferta o set
  DISCOUNTPART =
  CASE
    WHEN TIPDOC = 50 THEN NVL((SELECT DISCOUNT  FROM NPART WHERE CODPART = O.PARTENER), 0)
    ELSE 0
  END,

  valachiz = (SELECT SUM(ValAchiz) FROM tmp_oferta1),
  valmarja = (SELECT SUM(ValMarja) FROM tmp_oferta1);

  INSERT INTO TMP_CMDAPROBARI
  SELECT * FROM CMDAPROBARI WHERE CODDOC = RECID AND TIPDOC = aTIPOFERTA;

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;OFERTA1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTA1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_OFERTA1EXT SELECT * FROM OFERTA1EXT WHERE CODOFERTA1 IN (SELECT CODOFERTA1 FROM TMP_OFERTA1) &apos;;
  END IF;


  IF PKG_LIST_STRUCT.TmpExists(&apos;OFERTAEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTAEXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_OFERTAEXT SELECT * FROM OFERTAEXT WHERE CODOFERTA = &apos; ||  RECID;
  END IF;*/


  DELETE TMP_OFERTA1_INITIAL;
  INSERT INTO TMP_OFERTA1_INITIAL (CODOFERTA1)
  SELECT CODOFERTA1 FROM TMP_OFERTA1;
  
  PKG_CFGTABLES.EXT_GOTORECORD(aTIPOFERTA);
  delete from tmp_nartcli;
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo        INTEGER := 0;
  vCod          NUMBER(20);
  vCodPart      NPart.CodPart%TYPE;
  vCodClaseP    NClaseP.CodClaseP%TYPE;
  aCarnetDoc    NUMBER (20);
  aNrDoc        NUMBER (20);
  aCodSubunit   NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
  aTIPOFERTA    NUMBER(5) ;
  vUpdArtCli    NUMBER;
BEGIN
  SELECT CodOferta, Coalesce(Partener,0), Coalesce(CodClaseP,0), CarnetDoc, NrDoc, Subunitatea, DataStart, Decode(TipDoc,50,&apos;OC&apos;,51,&apos;OF&apos;)||NrDoc||&apos;/&apos;||DataStart||&apos;-&apos;||DataEnd, TIPDOC
  INTO RecId, vCodPart, vCodClaseP, aCarnetDoc, aNrDoc, aCodSubunit, aDataDoc, aDoc, aTIPOFERTA
  FROM TMP_Oferta;
  
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (aTIPOFERTA);
  
  IF Operation = 0 THEN  -- UPDATE

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;OFERTA&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    -- Master OFERTA

    UPDATE OFERTA
    SET ( TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd, DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT, TipBeneficiar, CodClaseP, Partener,
          Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, UserId, DataCreare, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE,  Agent, NRMAXAPROBARI, NRI,
          CodNParcAut, CodPartComis, ProcDisc, CodAnaliza)
          =
        ( SELECT
            TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd, DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT, TipBeneficiar, CodClaseP, Partener,
            Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, UserId, DataCreare, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE, Agent, NRMAXAPROBARI, NRI,
            CodNParcAut, CodPartComis, ProcDisc, CodAnaliza
          FROM TMP_OFERTA )
    WHERE CodOferta = RecId ;

    -- Detail OFERTA1
    DELETE FROM OFERTA1
    WHERE CodOferta = RecID AND CodOferta1 NOT IN (SELECT CodOferta1 FROM TMP_OFERTA1);

    FOR v_rec IN (
      SELECT
        CodOferta1, CodOferta, CodObiect, CodArticol, UmSec, CantMin * Paritate CantMin, Pret / Paritate Pret, PretRef / Paritate PretRef, Obs, ZileL, ZileC, ProcAdaos, ProcDiscount, CodExtOfe,
        CantMinUM1, D1, D2, D3, CantOptim, CANTOPTIMUM1, CantMax * Paritate CantMax, CodCatPret,PRETUM1, CodProiect, IndexLocal, DataCertifI, DataCertifF, CODCENTRU,
        PretAchiz / Paritate PretAchiz, CodAnalizaNod, GestAct, CodLinieDocImp
      FROM TMP_OFERTA1
      ORDER BY IndexLocal)
    LOOP
      IF NVL(v_rec.CodOferta1, 0) &gt; 0 THEN
        UPDATE OFERTA1 SET
          CodObiect     = v_rec.CodObiect,
          CodArticol    = v_rec.CodArticol,
          UMSec         = v_rec.UMSec,
          CantMin       = v_rec.CantMin,
          Pret          = v_rec.Pret,
          PretRef       = v_rec.PretRef,
          Obs           = v_rec.Obs,
          ZileL         = v_rec.ZileL,
          ZileC         = v_rec.ZileC,
          ProcAdaos     = v_rec.ProcAdaos,
          ProcDiscount  = v_rec.ProcDiscount,
          CodExtOfe     = v_rec.CodExtOfe,
          CantMinUM1    = v_rec.CantMinUM1,
          D1            = v_rec.D1,
          D2            = v_rec.D2,
          D3            = v_rec.D3,
          CantOptim     = v_rec.CantOptim,
          CANTOPTIMUM1  = V_REC.CANTOPTIMUM1,
          CantMax       = v_rec.CantMax,
          CodCatPret    = v_rec.CodCatPret,
          PRETUM1       = v_rec.PRETUM1,
          CodProiect    = v_rec.CodProiect,
          IndexLocal    = v_rec.IndexLocal,
          DataCertifI   = v_rec.DataCertifI,
          DataCertifF   = v_rec.DataCertifF,
          codcentru     = v_rec.codcentru,
          PretAchiz     = v_rec.Pretachiz,
          CodAnalizaNod = v_Rec.CodAnalizaNod, 
          GestAct       = v_Rec.GestAct,
          CodLinieDocImp = v_rec.codliniedocimp
        WHERE CodOferta1 = v_rec.CodOferta1;
      ELSE
        SELECT Seq_Oferta1_CodOferta1.Nextval INTO vCod from Dual;
        
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;OFERTA1&apos;, vCod, V_REC.CODOFERTA1);
        
/*        IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTA1EXT&apos;) = 1 THEN
          EXECUTE IMMEDIATE &apos; UPDATE TMP_OFERTA1EXT SET CODOFERTA1 = &apos; || VCOD || &apos; WHERE CODOFERTA1 = &apos; || V_REC.CODOFERTA1;
        END IF;
*/
        INSERT INTO OFERTA1 (
          CodOferta1, CodOferta, CodObiect, CodArticol, UMSec, CantMin, Pret, PretRef, Obs, ZileL, ZileC, ProcAdaos, ProcDiscount, CodExtOfe,
          CantMinUM1, D1, D2, D3, CantOptim, CANTOPTIMUM1, CantMax, CodCatPret, PRETUM1, CodProiect, IndexLocal, DataCertifI, DataCertifF,
          CodCentru, PretAchiz, CodAnalizaNod, GestAct, Codliniedocimp)
        VALUES  (
          vCod, RecId, v_rec.CodObiect, v_rec.CodArticol, v_rec.UMSec, v_rec.CantMin, v_rec.Pret, v_rec.PretRef, v_rec.Obs, v_rec.ZileL, v_rec.ZileC, v_rec.ProcAdaos, v_rec.ProcDiscount, v_rec.CodExtOfe,
          v_rec.CantMinUM1, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CantOptim, V_REC.CANTOPTIMUM1, v_rec.CantMax, v_rec.CodCatPret, V_REC.PRETUM1, v_rec.CodProiect, v_rec.IndexLocal,
          v_rec.DataCertifI, v_rec.DataCertifF, v_rec.codcentru, v_rec.PretAchiz, v_rec.CodAnalizaNod, v_rec.GestAct, v_rec.codliniedocimp);
     END IF;
    END LOOP;

    DELETE FROM CMDAPROBARI A WHERE CODDOC = RECID AND TIPDOC = aTIPOFERTA
    AND NOT EXISTS(SELECT COD FROM TMP_CMDAPROBARI WHERE COD = A.COD);

    FOR V_REC IN (SELECT * FROM TMP_CMDAPROBARI)
    LOOP
     IF V_REC.COD &lt; 0 THEN
        INSERT INTO CMDAPROBARI(COD,  CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
        VALUES (SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, aTIPOFERTA, V_REC.NIVEL, V_REC.STARE, V_REC.OBS, V_REC.USERID);

      ELSE
        UPDATE CMDAPROBARI
        SET
          NIVEL  = V_REC.NIVEL,
          STARE  = V_REC.STARE,
          USERID = V_REC.USERID,
          OBS    = V_REC.OBS
        WHERE
          COD = V_REC.COD;
      END IF;
    END LOOP;

  ELSE -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;OFERTA&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT Seq_Oferta_CodOferta.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;OFERTA&apos;, RecId);
    INSERT INTO OFERTA (
      CodOferta, TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd, DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT, TipBeneficiar, CodClaseP, Partener, An, Luna,
      Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, UserId, DataCreare, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE, Agent, NRMAXAPROBARI, NRI, CodNParcAut, CodPartComis,
      ProcDisc, CodAnaliza)
    SELECT
      RecId,     TipDoc, Anulat, Blocat, Operat, NrDoc, DataStart, DataEnd, DATACERERE, DATAOFERTA, ToateSubunit, OFERTAT, TipBeneficiar, CodClaseP, Partener, An, Luna,
      Obs, Moneda, CodLocatie, Subunitatea, CodFiscal, pkg_globals.USERID, SysDate, CarnetDoc, SeriaDoc, CodPersC, TIPLIVRARE, Agent, NRMAXAPROBARI, NRI, CodNParcAut, CodPartComis,
      ProcDisc, CodAnaliza
    FROM TMP_OFERTA;

    -- Detail Oferta1
    SELECT COUNT(1) INTO vRecNo FROM TMP_Oferta1;

    FOR v_rec IN (
      SELECT
        CodOferta1, CodObiect, CodArticol, UmSec, CantMin * Paritate CantMin, Pret / Paritate Pret, PretRef / Paritate PretRef, Obs, ZileL, ZileC, ProcAdaos, ProcDiscount, CodExtOfe,
        CantMinUM1, D1, D2, D3, CantOptim, CantOptimUM1, CantMax * Paritate CantMax, CodCatPret, PretUM1, CodProiect, IndexLocal, DataCertifI, DataCertifF, CodCentru,
        PretAchiz/ Paritate PretAchiz, CodAnalizaNod, GestAct, CodLinieDocimp
      FROM tmp_oferta1
    ) LOOP
      SELECT Seq_Oferta1_CodOferta1.Nextval INTO vCod from Dual;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;OFERTA1&apos;, vCod, v_rec.CodOferta1);
      
/*      IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTA1EXT&apos;) = 1 THEN
        EXECUTE IMMEDIATE &apos; UPDATE TMP_OFERTA1EXT SET CODOFERTA1 = &apos; || vCod || &apos; WHERE CODOFERTA1 = &apos; ||v_rec.CodOferta1;
      END IF;
*/
      INSERT INTO OFERTA1 (
        CodOferta1, CodOferta, CodObiect, CodArticol, UMSec, CantMin, Pret, PretRef, Obs, ZileL, ZileC, ProcAdaos, ProcDiscount, CodExtOfe,
        CantMinUM1, D1, D2, D3, CantOptim, CantOptimUM1, CantMax, CodCatPret, PretUM1, CodProiect, IndexLocal, Datacertifi, Datacertiff, CodCentru,
        PretAchiz, CodAnalizaNod, GestAct, Codliniedocimp)
      VALUES  (
        vCod, RecId, v_rec.CodObiect, v_rec.CodArticol, v_rec.UMSec, v_rec.CantMin, v_rec.Pret, v_rec.PretRef, v_rec.Obs, v_rec.ZileL, v_rec.ZileC, v_rec.ProcAdaos, v_rec.ProcDiscount, v_rec.CodExtOfe,
        v_rec.CantMinUM1, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CantOptim, v_rec.CantOptimUM1, v_rec.CantMax, v_rec.CodCatPret, v_rec.PretUM1, v_rec.CodProiect, v_rec.IndexLocal,
        v_rec.datacertifI, v_rec.datacertiff, v_rec.CodCentru, v_rec.PretAchiz, v_rec.CodAnalizaNod, v_rec.GestAct, v_rec.codliniedocimp);
    END LOOP;

    INSERT INTO CMDAPROBARI(COD, CODDOC, TIPDOC, NIVEL, STARE, OBS, USERID)
    SELECT SEQ_CMDAPROBARI_COD.NEXTVAL, RECID, aTIPOFERTA, NIVEL, STARE, OBS, USERID FROM TMP_CMDAPROBARI;
  END IF;

  -- Actualizare nartcli
  IF vCodPart &lt;&gt; 0 OR vCodClaseP &lt;&gt; 0 THEN
    vUpdArtCli := NVL(PKG_CATEGCONST.GetValConstanta(&apos;DetArtPartFromDoc&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 1);
    if vUpdArtCli = 1 then
      FOR v_rec IN (
        SELECT CodObiect, Coalesce(Max(CodClaseP), vCodClaseP, 0) CodClaseP, Max(DenArtCli) DenArtCli, Max(CodExtCli) CodExtCli, Max(CodLaClient) CodLaClient, Max(UMSec) UMSec
        FROM TMP_Oferta1
        WHERE coalesce(DENARTCLI,&apos;@&apos;) &lt;&gt; coalesce(DENARTCLI_INI,&apos;@&apos;) OR coalesce(CodExtCli,&apos;@&apos;) &lt;&gt; coalesce(CodExtCli_INI,&apos;@&apos;) OR coalesce(CodLaClient,&apos;@&apos;) &lt;&gt; coalesce(CodLaClient_INI,&apos;@&apos;)
        GROUP BY CodObiect)
      LOOP
        PKG_NOM_ARTICOL.ACTUALIZEAZA_NARTCLI(v_rec.CodObiect, vCodPart, v_rec.CodClaseP, v_rec.DenArtCli, v_rec.CodExtCli, v_rec.CodLaClient, v_rec.UMSec, 7, vUpdArtCli);
      END LOOP;
    end if;  
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(aCarnetDoc, aNrDoc);

  NotifyModif(OPERATION, RECID, &apos;OFERTA&apos;);

/*  IF PKG_LIST_STRUCT.TmpExists(&apos;OFERTA1EXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTA1EXT&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;DELETE FROM OFERTA1EXT WHERE CODOFERTA1 IN (SELECT CODOFERTA1 FROM TMP_OFERTA1_INITIAL)  &apos;;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_OFERTA1EXT SET CODOFERTA1EXT = SEQ_OFERTA1EXT_CODOFERTA1EXT.NEXTVAL WHERE CODOFERTA1EXT &lt; 0&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO OFERTA1EXT SELECT * FROM TMP_OFERTA1EXT &apos;;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;OFERTAEXT&apos;) = 1 AND PKG_LIST_STRUCT.TmpExists(&apos;TMP_OFERTAEXT&apos;) = 1 THEN
     EXECUTE IMMEDIATE &apos;DELETE FROM OFERTAEXT WHERE CODOFERTA =  &apos; || RECID;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_OFERTAEXT SET CODOFERTAEXT = SEQ_OFERTAEXT_CODOFERTAEXT.NEXTVAL  WHERE CODOFERTAEXT &lt; 0&apos;;
     EXECUTE IMMEDIATE &apos;UPDATE TMP_OFERTAEXT SET CODOFERTA = &apos; || RECID;
     EXECUTE IMMEDIATE &apos;INSERT INTO OFERTAEXT SELECT * FROM TMP_OFERTAEXT &apos;;
  END IF;*/

  PKG_CFGTABLES.EXT_POSTRECORDS (aTIPOFERTA);

  COMMIT;
END;

procedure debug is
begin
  pkg_globals.SETFIRMANAME(&apos;AAAAA&apos;);
  SP_GOTORECORD(105);
end;

function RoundPret(Pret in number,  Rot in number) return number is
  pretRotunjit Number(20,7);
  intPrec Number(1);
begin
  case Rot 
    when 1 then  intPrec := 6;
    when 2 then  intPrec := 5;
    when 3 then  intPrec := 4;
    when 4 then  intPrec := 3;
    when 5 then  intPrec := 2;
    when 6 then  intPrec := 1;
    when 7 then  intPrec := 0;
    when 8 then  intPrec := 7;
  else
     intPrec := 2;
  end case;
  pretRotunjit := ROUND (Pret, intPrec);
  return pretRotunjit;
end;

function updateComandaXOferta( pCodOferta IN NUMBER ) return varchar IS
  codComandaModificata Number(20);
  valDoc Number(20,7);
  vPretLinie Number(20,7);
  listaComenziModificate Varchar2(3000);
  listaComenziBlocate Varchar2(3000);
  existaComenziBLocate boolean;
  tmpCod Number(20);
  CURSOR lista_comenzi
  IS  select cmd1.codcomanda1 as codComanda1, 
              cmd.codcomanda as codComanda,
              cmd.nrdoc as nrDoc,
              cmd.datadoc as dataDoc,
              ofr1.codoferta1 as codOferta1,
              cmd1.addim as adDim,
              cmd1.PU as cmdPU, 
              cmd1.pretorig as cmdPretOrig,
              ofr1.pret as ofrPret,
              obj.rotunjire as rotunjire
         from comanda cmd
         join comanda1 cmd1
           on cmd1.codcomanda = cmd.codcomanda
         join oferta1 ofr1
           on ofr1.codoferta1 = cmd1.codoferta1
         join oferta ofr
           on ofr.codoferta = ofr1.codoferta
         join npart part
           on part.codpart = cmd.partener
        join nartobj obj on obj.codobiect = cmd1.codobiect   
        where ofr.codoferta = pCodOferta
          and trunc(cmd1.termen) between trunc(ofr.datastart) and
              trunc(ofr.dataend)
          and cmd1.restacceptat &gt; 0
          and coalesce(cmd.anulat, 0) = 0
          and coalesce(cmd.inchisa, 0) = 0
          and coalesce(part.preofefurnvar, 0) = 1
          and ofr.partener = cmd.partener
          and ofr1.pret &lt;&gt; cmd1.pretorig
          and cmd.tipdoc = 8
         order by cmd1.codcomanda;
begin
  codComandaModificata := -1;
  valDoc := 0.0;
  listaComenziModificate := &apos;&apos;;
  listaComenziBlocate :=&apos;&apos;;
  existaComenziBLocate := false;
  for v_rec in lista_comenzi
  loop
    if codComandaModificata = -1 or codComandaModificata != v_rec.codComanda then  
      codComandaModificata := v_rec.codComanda;
      begin
        SELECT CodComanda into tmpCod  FROM COMANDA WHERE CodComanda = v_rec.codComanda FOR UPDATE NOWAIT;
      exception 
         when others  then
           listaComenziBlocate := listaComenziBlocate || v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;; &apos;;
           existaComenziBLocate := true;
      end;
    end if;  
  end loop;
  if existaComenziBLocate then 
    rollback;
    return &apos;ERR#$&apos;||listaComenziBlocate;
  end if;
  codComandaModificata := -1;
  for v_rec in lista_comenzi
  loop
    if codComandaModificata = -1 then
      codComandaModificata := v_rec.codComanda;
      listaComenziModificate := v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;);
    else
      if codComandaModificata != v_rec.codComanda then
        select sum(RoundPret(((100 + coalesce(cmd1.procdisc,0)) / 100) * cmd1.cantacceptat * cmd1.pu, obj.rotunjire)) into valDoc
        from comanda1 cmd1
        join nartobj obj on obj.codobiect = cmd1.codobiect 
        where cmd1.codcomanda = codComandaModificata 
              and coalesce(cmd1.anulat,0) = 0;
         update comanda cmd set cmd.valoare = valDoc where cmd.codcomanda = codComandaModificata;
        codComandaModificata := v_rec.codComanda;
        listaComenziModificate := listaComenziModificate || &apos;; &apos;|| v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;);
      end if;
    end if ;  

    vPretLinie := RoundPret(((100 + coalesce(v_rec.addim,0)) / 100) * v_rec.ofrpret, v_rec.rotunjire);
   
    update comanda1 cmd1
       set pretorig = v_rec.ofrpret,
             cmd1.pu = vPretLinie
       where cmd1.codcomanda1 = v_rec.codcomanda1;
  end loop;  
  if codComandaModificata != -1 then
        select sum(RoundPret(((100 + coalesce(cmd1.procdisc,0)) / 100) * cmd1.cantacceptat * cmd1.pu, obj.rotunjire)) into valDoc
        from comanda1 cmd1 
          join nartobj obj on obj.codobiect = cmd1.codobiect 
        where cmd1.codcomanda = codComandaModificata 
              and coalesce(cmd1.anulat,0) = 0;
         update comanda cmd set cmd.valoare = valDoc where cmd.codcomanda = codComandaModificata;
   end if;
   commit;
   return listaComenziModificate ;
end;
function updateComandaXOfertaNoua( pCodOferta IN NUMBER ) return varchar IS
  codComandaModificata Number(20);
  valDoc Number(20,7);
  vPretLinie Number(20,7);
  listaComenziModificate Varchar2(3000);
  listaComenziBlocate Varchar2(3000);
  existaComenziBLocate boolean;
  tmpCod Number(20);
  CURSOR lista_comenzi
  IS  select l_tot.codComanda1,l_tot.codComanda, l_tot.nrDoc, l_tot.dataDoc, l_tot.adDim, l_tot.cmdPU, l_tot.cmdPretOrig, l_tot.rotunjire,l_tot.codOferta1, l_tot.ofrPret
      from 
         (select  t_lst.codComanda1, t_lst.codComanda, t_lst.nrDoc, t_lst.dataDoc, t_lst.adDim, t_lst.cmdPU, t_lst.cmdPretOrig, t_lst.rotunjire,
                   max(t_lst.codOferta1)  KEEP (DENSE_RANK LAST ORDER BY t_lst.cantmin ) codOferta1,
                   max(t_lst.ofrPret)  KEEP (DENSE_RANK LAST ORDER BY t_lst.cantmin ) ofrPret
         from (          
         select cmd1.codcomanda1 as codComanda1, 
                      cmd.codcomanda as codComanda,
                      cmd.nrdoc as nrDoc,
                      cmd.datadoc as dataDoc,
                      ofr1.codoferta1 as codOferta1,
                      cmd1.addim as adDim,
                      cmd1.PU as cmdPU, 
                      cmd1.pretorig as cmdPretOrig,
                      ofr1.pret as ofrPret,
                      obj.rotunjire as rotunjire,
                      ofr1.cantmin as cantmin,
                      cmd1.termen
                 from oferta ofr  
                 join oferta1 ofr1
                   on ofr1.codoferta = ofr.codoferta 
                 join comanda cmd
                   on cmd.partener = ofr.partener
                 join comanda1 cmd1
                   on cmd1.codcomanda = cmd.codcomanda and cmd1.codobiect = ofr1.codobiect and cmd1.cantacceptat &gt;= coalesce(ofr1.cantmin,0) 
                 join npart part
                   on part.codpart = cmd.partener
                join nartobj obj on obj.codobiect = cmd1.codobiect   
                where ofr.codoferta = pCodOferta
                  and trunc(cmd1.termen) between trunc(ofr.datastart) and
                      trunc(ofr.dataend)
                  and cmd1.restacceptat &gt; 0
                  and coalesce(cmd.anulat, 0) = 0
                  and coalesce(cmd.inchisa, 0) = 0
                  and coalesce(part.preofefurnvar, 0) = 1
                  and cmd.tipdoc = 8
                 order by cmd1.codcomanda) t_lst
          group by t_lst.codComanda1, t_lst.codComanda, t_lst.nrDoc, t_lst.dataDoc, t_lst.adDim, t_lst.cmdPU, t_lst.cmdPretOrig, t_lst.rotunjire) l_tot
  where l_tot.cmdpretorig &lt;&gt; l_tot.ofrpret
  order by l_tot.codcomanda;
begin
  codComandaModificata := -1;
  valDoc := 0.0;
  listaComenziModificate := &apos;&apos;;
  listaComenziBlocate :=&apos;&apos;;
  existaComenziBLocate := false;
  for v_rec in lista_comenzi
  loop
    if codComandaModificata = -1 or codComandaModificata != v_rec.codComanda then  
      codComandaModificata := v_rec.codComanda;
      begin
        SELECT CodComanda into tmpCod  FROM COMANDA WHERE CodComanda = v_rec.codComanda FOR UPDATE NOWAIT;
      exception 
         when others  then
           listaComenziBlocate := listaComenziBlocate || v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;)||&apos;; &apos;;
           existaComenziBLocate := true;
      end;
    end if;  
  end loop;
  if existaComenziBLocate then 
    rollback;
    return &apos;ERR#$&apos;||listaComenziBlocate;
  end if;
  codComandaModificata := -1;
  for v_rec in lista_comenzi
  loop
    if codComandaModificata = -1 then
      codComandaModificata := v_rec.codComanda;
      listaComenziModificate := v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;);
    else
      if codComandaModificata != v_rec.codComanda then
        select sum(RoundPret(((100 + coalesce(cmd1.procdisc,0)) / 100) * cmd1.cantacceptat * cmd1.pu, obj.rotunjire)) into valDoc
        from comanda1 cmd1
        join nartobj obj on obj.codobiect = cmd1.codobiect 
        where cmd1.codcomanda = codComandaModificata 
              and coalesce(cmd1.anulat,0) = 0;
         update comanda cmd set cmd.valoare = valDoc where cmd.codcomanda = codComandaModificata;
        codComandaModificata := v_rec.codComanda;
        listaComenziModificate := listaComenziModificate || &apos;; &apos;|| v_rec.nrdoc ||&apos;/&apos;|| to_char(v_rec.datadoc,&apos;dd.mm.yyyy&apos;);
      end if;
    end if ;  

    vPretLinie := RoundPret(((100 + coalesce(v_rec.addim,0)) / 100) * v_rec.ofrpret, v_rec.rotunjire);
    update comanda1 cmd1
       set pretorig = v_rec.ofrpret,
             cmd1.pu = vPretLinie
       where cmd1.codcomanda1 = v_rec.codcomanda1;
  end loop;  
  if codComandaModificata != -1 then
        select sum(RoundPret(((100 + coalesce(cmd1.procdisc,0)) / 100) * cmd1.cantacceptat * cmd1.pu, obj.rotunjire)) into valDoc
        from comanda1 cmd1 
          join nartobj obj on obj.codobiect = cmd1.codobiect 
        where cmd1.codcomanda = codComandaModificata 
              and coalesce(cmd1.anulat,0) = 0;
         update comanda cmd set cmd.valoare = valDoc where cmd.codcomanda = codComandaModificata;
   end if;
   commit;
   return listaComenziModificate ;
end;

end PKG_OFERTA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ONORARECOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3A7149FF538CEDF9587694FC1EB90A3CCE9EE79</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ONORARECOMENZI IS

PROCEDURE settermen(aTermenDeLa IN VARCHAR2, aTermenPanaLa IN VARCHAR2 DEFAULT NULL ) is
BEGIN
  pDataSys      := Trunc(SYSDATE);
  pDataTermLivrDeLa   := To_Date(Nvl(aTermenDeLa,&apos;X&apos;), &apos;DD.MM.YYYY&apos;);
  pDataTermLivrPanaLa := To_Date(Nvl(aTermenPanaLa,&apos;X&apos;), &apos;DD.MM.YYYY&apos;);
  pFlagTermLivr := 1;
EXCEPTION WHEN OTHERS THEN
  pDataTermLivrDeLa := pDataSys;
  pDataTermLivrPanaLa := pDataSys;
  pFlagTermLivr := 0;
END;

PROCEDURE CLR_LCK_COMENZI is
BEGIN
  UPDATE Comanda SET UserIDBlocaj = null WHERE UserIDBlocaj = PKG_GLOBALS.UserID;
  COMMIT;
END;

FUNCTION  LCK_COMENZI(
            aCodSubunit         IN NUMBER,
            aDataTermLivrDeLa   IN VARCHAR2,
            aDataTermLivrPanaLa IN VARCHAR2,
            aNrComenzi          IN VARCHAR2,
            aCodDelegat         IN NUMBER,
            aCodMijlTransp      IN NUMBER,
            aCodTraseu          IN NUMBER,
            aCodAgent           IN NUMBER,
            aCodClient          IN NUMBER,
            aCodSubunitSursa    IN NUMBER,
            aCodGestSursa       IN NUMBER,
            aFlagClaseArt       IN NUMBER,
            aStadiuWMS          IN NUMBER,
            aTipPlata           IN NUMBER DEFAULT 0,
            aRez                IN NUMBER DEFAULT 0,
            aCmdC               IN NUMBER DEFAULT 0,
            aDL                 IN NUMBER DEFAULT 0,
            aCmdG               IN NUMBER DEFAULT 0,
            aCmdS               IN NUMBER DEFAULT 0,
            aAllSerii           IN NUMBER DEFAULT 1
          )
RETURN VARCHAR2 IS
  lRecID            NUMBER(20);
  lOraError         VARCHAR2(2048);
  lCodClient        NUMBER(20);
  lCodSubunitSursa  NUMBER(20);
  lCodGestSursa     NUMBER(20);
  COMANDA_BLOCATA   EXCEPTION;
  pragma exception_init(COMANDA_BLOCATA, -20999);
  aFacturabilCC     NUMBER(1);
  aAprobariCmdCl    number(1);
BEGIN
  if Length(aNrComenzi) &gt; 0 then
    delete tmp_manevra_liste where filtru = &apos;NRDOC&apos;;
    execute immediate &apos;insert into tmp_manevra_liste(filtru,valoare) select &apos;&apos;NRDOC&apos;&apos;,NRDOC FROM COMANDA WHERE NRDOC IN (&apos;||aNrComenzi||&apos;)&apos;;
  end if;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;FacturabilCC&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO aFacturabilCC FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aFacturabilCC  := 2;
  END;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;AprobariCmdCl&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO aAprobariCmdCl FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aAprobariCmdCl  := 2;
  END;
  pDataSys         := Trunc(SYSDATE);
  BEGIN
    pDataTermLivrDeLa    := To_Date(Nvl(aDataTermLivrDeLa,&apos;X&apos;), &apos;DD.MM.YYYY&apos;);
    pDataTermLivrPanaLa  := To_Date(Nvl(aDataTermLivrPanaLa,&apos;X&apos;), &apos;DD.MM.YYYY&apos;);
    pFlagTermLivr  := 1;
  EXCEPTION WHEN OTHERS THEN
    pDataTermLivrDeLa  := pDataSys;
    pDataTermLivrPanaLa  := pDataSys;
    pFlagTermLivr  := 0;
  END;
  lCodClient       := Nvl(aCodClient,0);
  lCodSubunitSursa := Nvl(aCodSubunitSursa,0);
  lCodGestSursa    := Nvl(aCodGestSursa,0);
  -- stef -- se vrea daca am ales un client de exemplu sa aduca doar clientul si sa nu mai aduca comenzile de la gestiuni sau subunitati
  IF lCodClient + lCodSubunitSursa + lCodGestSursa  &gt; 0 THEN
    IF lCodClient       = 0 THEN lCodClient       := -1; END IF;
    IF lCodSubunitSursa = 0 THEN lCodSubunitSursa := -1; END IF;
    IF lCodGestSursa    = 0 THEN lCodGestSursa    := -1; END IF;
  END IF;
  pFlagClaseArt   := Nvl(aFlagClaseArt,0);

  lOraError := &apos;&apos;;
  FOR vRec IN
    (
      SELECT DISTINCT C.CodComanda, C.NrDoc, Nvl(C.UserIDBlocaj, 0) UserIDBlocaj
      FROM Comanda C
        INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
        INNER JOIN NArtObj NAO on NAO.CodObiect = C1.CodObiect
        INNER JOIN NArt NA on NA.CodArticol = NAO.CodArticol
        LEFT JOIN RezervatS RS on RS.CodComanda1 = C1.CodComanda1
        LEFT JOIN NIRStoc NS on NS.CodNIRStoc = RS.CodNIRStoc
        LEFT JOIN NAgenda Loc ON Loc.codagenda = c.codlocatie
      WHERE C.OPERAT = 1 AND C.ANULAT = 0 AND Nvl(C.INCHISA,0) = 0
        AND C.AN*12+C.LUNA &lt;= PKG_GLOBALS.AnLunaLucru
        AND Decode(C.TipDoc,44,C.SubunitSursa,C.Subunitatea) = aCodSubunit
        AND (
             (C.TipDoc = 18 AND aCmdC &gt; 0 AND COALESCE(C.DISPLIVRARE,0) = 0 AND C.Partener    = Decode(lCodClient,0,C.Partener,lCodClient)) OR              -- comenzi de la clienti
             (C.TipDoc = 18 AND aDL &gt; 0 AND C.DISPLIVRARE = 1 AND C.Partener    = Decode(lCodClient,0,C.Partener,lCodClient)) OR              -- comenzi de la clienti
             (C.TipDoc = 43 AND aCmdG &gt; 0 AND C.CodGest     = Decode(lCodGestSursa,0,C.CodGest,lCodGestSursa)) OR         -- comenzi de la gestiuni
             (C.TipDoc = 44 AND aCmdS &gt; 0 AND C.Subunitatea = Decode(lCodSubunitSursa,0,C.Subunitatea,lCodSubunitSursa))  -- comenzi de la subunitati
            )
        AND C1.RESTACCEPTAT &gt; 0
        AND (pFlagTermLivr = 0  or (Nvl(C1.Termen, pDataSys) BETWEEN pDataTermLivrDeLa and pDataTermLivrPanaLa))
        AND (aCodDelegat = 0    or Nvl(C.Delegat, 0) = aCodDelegat)
        AND (aCodMijlTransp = 0 or Nvl(C.MijlTransp, 0) = aCodMijlTransp)
        AND (aCodTraseu = 0     or Coalesce(C.CODTRASEULIVR, Loc.CodTraseu, 0) = aCodTraseu)
        AND (aCodAgent = 0      or Nvl(C.Agent, 0) = aCodAgent)
        AND (aNrComenzi is null or Length(aNrComenzi) = 0 or C.NRDOC IN (select TO_NUMBER(valoare) from tmp_manevra_liste where UPPER(FILTRU) = &apos;NRDOC&apos;))
        AND (pFlagClaseArt = 1  or Nvl(NA.Clasa, 0) IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODCLASEA&apos;))
        AND (aStadiuWMS = -1    or Nvl(StadiuWMS, -1) = aStadiuWMS)
        AND (aTipPlata = 0      or exists (select tc.codtermen from termenecmd tc where tc.tipplata = aTipPlata and tc.codcomanda = c.codcomanda))
        AND (aRez = 0           or RS.Rest &gt; 0)
        AND (((aFacturabilCC = 1 OR aAprobariCmdCl = 1) AND C.FACTURABIL = 1)
             OR
             (aFacturabilCC = 2 AND aAprobariCmdCl = 2 AND ((COALESCE(C.DISPLIVRARE, 0) = 0)OR(COALESCE(C.DISPLIVRARE, 0) = 1 AND C.VERIFICAT = 1 AND C.FACTURABIL = 1))
             )
             )
        AND (aAllSerii = 1 or exists (select tmp.valoare from tmp_manevra_liste tmp where tmp.filtru = &apos;SERIE&apos; AND tmp.valoare = c.seriadoc))
    )
  LOOP
    BEGIN
      SELECT CodComanda into lRecID from Comanda where CodComanda = vRec.CodComanda for update nowait;
      if vRec.UserIDBlocaj &lt;&gt; 0 and vRec.UserIDBlocaj &lt;&gt; PKG_GLOBALS.UserID THEN raise COMANDA_BLOCATA; END if;
      UPDATE Comanda set UserIDBlocaj = PKG_GLOBALS.UserID where CodComanda = vRec.CodComanda;
    EXCEPTION WHEN COMANDA_BLOCATA THEN
      lOraError := lOraError || to_char(vRec.NrDoc) || &apos;, &apos;;
    END;
  END LOOP;
  COMMIT;
  RETURN lOraError;
END;

PROCEDURE ULCK_COMANDA(aCodComanda IN NUMBER) is
BEGIN
  UPDATE Comanda SET UserIDBlocaj = NULL WHERE CodComanda = aCodComanda;
  COMMIT;
END;

PROCEDURE GET_TMP_Comenzi(SursaPU in number, CarePU in number, DataRef in varchar2, aRez IN NUMBER DEFAULT 0) IS
BEGIN
  GET_TMP_OperLivr_Articole(aRez);
  GET_TMP_OperLivr_Comenzi;
  if SursaPU = 1 then
    if CarePU = 0 then
      for v_rec in (select c1.codcomanda1, c1.codobiect, c.codclient, c.codsediu
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                    ) loop
        update TMP_OnorCom_Articole set pret = pkg_oferta.GetPretOfertaPartLocObj(v_rec.codclient, v_rec.codsediu, v_rec.CodObiect, DataRef, 50)
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    else
      for v_rec in (select c1.codcomanda1, c1.codobiect, c.codclient, c.codsediu
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                    where nvl(c1.pret,0) = 0
                    ) loop
        update TMP_OnorCom_Articole set pret = pkg_oferta.GetPretOfertaPartLocObj(v_rec.codclient, v_rec.codsediu, v_rec.CodObiect, DataRef, 50)
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    end if;
  else if SursaPU = 2 then
    if CarePU = 0 then
      for v_rec in (select c1.codcomanda1, pm.lei
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                         inner join npart p on c.codclient = p.codpart
                         left join pretm pm on pm.codcatpret = p.codcategpret and pm.subunitatea = c.subunitatea and pm.codobiect = c1.codobiect
                    ) loop
        update TMP_OnorCom_Articole set pret = v_rec.lei
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    else
      for v_rec in (select c1.codcomanda1, pm.lei
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                         inner join npart p on c.codclient = p.codpart
                         left join pretm pm on pm.codcatpret = p.codcategpret and pm.subunitatea = c.subunitatea and pm.codobiect = c1.codobiect
                    where nvl(c1.pret,0) = 0
                    ) loop
        update TMP_OnorCom_Articole set pret = v_rec.lei
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    end if;
  else if SursaPU = 3 then
    if CarePU = 0 then
      for v_rec in (select c1.codcomanda1, pm.lei
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                         left join pretm pm on pm.implicit = 1 and pm.subunitatea = c.subunitatea and pm.codobiect = c1.codobiect
                    ) loop
        update TMP_OnorCom_Articole set pret = v_rec.lei
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    else
      for v_rec in (select c1.codcomanda1, pm.lei
                    from TMP_OnorCom_Comenzi c
                         inner join TMP_OnorCom_Articole c1 on c1.codcomanda = c.codcomanda
                         left join pretm pm on pm.implicit = 1 and pm.subunitatea = c.subunitatea and pm.codobiect = c1.codobiect
                    ) loop
        update TMP_OnorCom_Articole set pret = v_rec.lei
        where codcomanda1 = v_rec.codcomanda1;
      end loop;
    end if;
  end if; end if; end if;
END;

PROCEDURE GET_TMP_OperLivr_Comenzi IS
BEGIN
  DELETE FROM TMP_OnorCom_Comenzi;
  INSERT INTO TMP_OnorCom_Comenzi (
    Poz,
    CodClient,
    DenClient,
    CodSediu, DenSediu, SediuSocial, CodFiscal, TipComanda, NrComanda, DataComanda, Obs,
    CodAgent, DenAgent, CodDelegat, CodPers, FaraTransport, CodMijlTransp, CodTraseuLivr,
    CodComanda, CodMoneda, Subunitatea, ScadentaV, Rest,
    Curs, GDI, GAA, A1, A2, A3, A4, A5, A6, KGA1, KGA2, KGA3, KGA4, KGA5, KGA6, MASAU, VOLUMU, MASA, VOLUM,
    ModDoc,
    TipDoc,
    TipDocAmb,
    FlagLucru, FlagInchidere,
    DenTraseu, DenDelegat, DenMijlTransp, Valoare, Discount,
    ExclPromoAut,
    CountNeinchise,
    Custodie,
    MijlTransp, NrTransp,
    TIPCMD, Seriadoc, ValRest)
  SELECT
    C.ORDINELIVRARE,
    CASE
      WHEN C.TipDoc = 18 THEN C.Partener     -- comanda client
      WHEN C.TipDoc = 43 THEN C.Codgest      -- comanda de la gestiuni
      WHEN C.TipDoc = 44 THEN C.Subunitatea  -- comanda de la subunitati
    END,
    CASE
      WHEN C.TipDoc = 18 THEN P.Den_Part     -- comanda client
      WHEN C.TipDoc = 43 THEN NGE.Den_Gest   -- comanda de la gestiuni
      WHEN C.TipDoc = 44 THEN NS.Den_Subunit -- comanda de la subunitati
    END,
    C.CodLocatie, S.Obs, S.SediuSocial, C.CodFiscal, C.TipDoc, C.NrDoc, C.DataDoc, C.Obs,
    C.Agent, AG.Nume||&apos; &apos;||AG.Prenume, C.Delegat, PT.CodPers, C.FaraTransport, C.MijlTransp, C.CodTraseuLivr,
    C.CodComanda, C.Moneda, Decode(C.TipDoc,44,C.SubunitSursa,C.Subunitatea), C.ScadentaV, a.Rest,
    1 Curs, 0 GDI, 0 GAA, 0 A1, 0 A2, 0 A3, 0 A4, 0 A5, 0 A6, 0 KGA1, 0 KGA2, 0 KGA3, 0 KGA4, 0 KGA5, 0 KGA6, 0 MASAU, 0 VOLUMU, 0 MASA, 0 VOLUM,
    0 ModDoc,
    CASE
      WHEN C.TipDoc = 43 THEN 12  -- Nota de transfer
      WHEN C.TipDoc = 44 THEN 23  -- Iesiri catre subunitati
      ELSE
        CASE  
          WHEN C.DISPLIVRARE = 1 THEN
            CASE
              WHEN Nvl(P.DocDefOnorCom,0) = 1 THEN 19
              WHEN Nvl(P.DocDefOnorCom,0) = 2 THEN 20
              WHEN S.SediuSocial IN (2,3,6,7) THEN 19 -- Facturi care clienti -- orice sediu care include facturare
              ELSE 20 -- Avize de Expeditie catre clienti -- practic restul tipurilor de sedii S.SediuSocial IN (1,4,5)
            END
          ELSE
            CASE 
              WHEN pkg_categconst.GetValConstanta(&apos;OnorComNoRez&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 THEN 18
              ELSE
                CASE 
                  WHEN Nvl(P.DocDefOnorCom,0) = 1 THEN 19
                  WHEN Nvl(P.DocDefOnorCom,0) = 2 THEN 20
                  WHEN S.SediuSocial IN (2,3,6,7) THEN 19 -- Facturi care clienti -- orice sediu care include facturare
                  ELSE 20 -- Avize de Expeditie catre clienti -- practic restul tipurilor de sedii S.SediuSocial IN (1,4,5) 
                END    
            END    
        END    
    END TipDoc,
    CASE
      WHEN C.TipDoc = 43 THEN 57
      WHEN Nvl(PT.Codpers,0) &lt;&gt; 0 THEN 57
      ELSE 20
    END TipDocAmb,
    1 FlagLucru, 0 FlagInchidere,
    TL.DenTraseu, PT.Delegat, PA.NrInreg, C.Valoare, 0 Discount,
    CASE
      WHEN C.TipDoc = 18  AND Nvl(ModPromoFactCom, 1) = 1 THEN 1
      ELSE 0
    END,
    A.CountNeinchise,
    0 Custodie, c.mijltransp, c.nrtransp,
    CASE WHEN COALESCE(C.DISPLIVRARE, 0) = 1 THEN &apos;DL&apos; ELSE C.PREFIXDOC END, C.Seriadoc,
    round(A.restval,2)  
  FROM COMANDA C
    LEFT JOIN NPART P ON P.CodPart = C.PARTENER
    LEFT JOIN NPERS AG ON AG.CodPers = C.AGENT
    LEFT JOIN NAGENDA S ON S.CodAgenda = C.CodLocatie -- Nu are sens decat pt CLIENTI
    LEFT JOIN (SELECT CodComanda, Sum(RESTLIVR) Rest, Sum(RESTLIVR*pretorig*coefdiscmaj) RestVal, Count(1) CountNeinchise FROM TMP_Onorcom_Articole GROUP BY CodComanda) A ON A.CodComanda = C.CodComanda
    LEFT JOIN NSubunit NS ON NS.CodSubunit = C.Subunitatea
    LEFT JOIN NGest NGE ON NGE.CodGest = C.CodGest
    LEFT JOIN TraseuLivr TL ON TL.CodTraseuLivr = C.CodTraseuLivr
    LEFT JOIN NPartTr PT ON PT.CodPartTr = C.Delegat
    LEFT JOIN NParcAut PA ON PA.CodNParcAut = C.MijlTransp
  WHERE C.TipDoc in (18, 43, 44) -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
    AND C.UserIDBlocaj = PKG_GLOBALS.UserID AND EXISTS (SELECT TMP.CODCOMANDA FROM TMP_Onorcom_Articole TMP WHERE C.CODCOMANDA = TMP.CODCOMANDA);

  COMMIT;
END;

PROCEDURE GET_TMP_OperLivr_Articole(aRez in number default 0) IS
BEGIN
  DELETE FROM TMP_OnorCom_PrelStoc;
  DELETE FROM TMP_OnorCom_Articole;
  INSERT INTO TMP_Onorcom_Articole(
    CODCOMANDA1, CODCOMANDA, INDEXLOCAL, CODOBIECT, DENOBIECT, CODEXTERN, CODARTICOL, TERMENLIVR, CODUM, UMSEC,
    CANTCOMANDAT, CANTACCEPTAT, RESTLIVR, LIVRSTOC, LIVRECHIV, CODEKIV, DENEKIV, PARITATEEKIV, CODUMEKIV,
    CODUMSPEC, CANTSPEC, D1, D2, D3, RELATIEUMSPEC, RELATIEUMALT,
    Cantaribil,
    CANT, PRET, PRETORIG, VALOARE, ADDIM, PROCDISC, OBS, SCADENTA, TERMENPLATA,
    NET, BRUT, A1, A2, A3, A4, A5, A6, KGA1, KGA2, KGA3, KGA4, KGA5, KGA6, FlagInchidere,
    PROCTVA, RestNeglijCmd,
    CoefDiscMaj, Codgest, Codioart,
    TipLinie, ContServ, GestAct, den_um1)
  SELECT
    C1.CodComanda1, C.CodComanda, c1.IndexLocal, C1.CodObiect, NAO.Denumire, NAO.CodExtern, NA.CODARTICOL, C1.Termen, NA.UM, C1.UMSec,
    C1.CantComandat, C1.CantAcceptat, C1.RestAcceptat, 0, 0, 0, &apos; &apos;, 1, 0,
    NA.UM1, C1.CantUM1, C1.D1, C1.D2, C1.D3, NA.RelatieUM1, NA.RelatieUM2,
    CASE WHEN U.TipUM = 1 AND Nvl(U.Coef,0) &lt;&gt; 0 THEN 1 ELSE 0 END,
    0, 
    case when c.pretcuamanunt = 1 then C1.PU / (1 + PKG_SELECTARTICOLE.GETPROCENTTVA(NAO.CodArticol, PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU) / 100) else c1.pu end,
    case when c.pretcuamanunt = 1 then C1.PRETORIG / (1 + PKG_SELECTARTICOLE.GETPROCENTTVA(NAO.CodArticol, PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU) / 100) else C1.PRETORIG end,
    0, C1.AdDim, C1.ProcDisc, C1.Obs, C1.Scadenta, NAO.TermenPlata,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    PKG_SELECTARTICOLE.GETPROCENTTVA(NAO.CodArticol, PKG_GLOBALS.GETANLUCRU,PKG_GLOBALS.GETLUNALUCRU), Nvl(NA.RestNeglijCmd, 0.01),
    CoefDiscMaj, IMP.GESTIMPLICITA, IMP.CONTIMPLICIT,
    CASE WHEN NA.TIPARTICOL = 0 THEN &apos;=&apos; ELSE &apos;S&apos; END TipLinie,
    CASE WHEN NA.TIPARTICOL = 1 THEN NA.ContServiciu ELSE NULL END ContServ,
    CASE WHEN NA.TIPARTICOL = 1 THEN Coalesce( NullIF(C1.GestAct, 0), IMP.GESTIMPLICITA) ELSE NULL END GestAct, num1.den_um1
  FROM Comanda C
    INNER JOIN Comanda1 C1 on C1.CodComanda = C.CodComanda
    INNER JOIN NArtObj NAO on NAO.CodObiect = C1.CodObiect
    INNER JOIN NArt NA on NA.CodArticol = NAO.CodArticol
    INNER JOIN NUM U on U.CodUM = NA.UM
    LEFT  JOIN NARTIMPLICITE IMP ON IMP.CODARTICOL = NA.CODARTICOL AND IMP.CODSUBUNIT = C.SUBUNITATEA
    LEFT JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
  WHERE C.TipDoc in (18, 43, 44) -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
    AND C.UserIDBlocaj = PKG_GLOBALS.UserID
    AND C1.RESTACCEPTAT &lt;&gt; 0 and C1.RESTACCEPTAT * c1.cantacceptat &gt; 0
    AND (pFlagTermLivr = 0 OR (Nvl(C1.Termen, pDataSys) between pDataTermLivrDeLa and pDataTermLivrPanaLa ))
    AND (pFlagClaseArt = 1 OR Nvl(NA.Clasa,0) IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODCLASEA&apos;))
    AND COALESCE(C1.MODINCHIDERE,0) = 0
    AND (aRez = 0 or exists (select r.codrezervats from rezervats r where r.codcomanda1 = c1.codcomanda1 and r.rest &gt; 0));
  COMMIT;
END;

PROCEDURE GET_TMP_GrupCom IS
BEGIN
  UPDATE TMP_OnorCom_Comenzi  SET idxgrup = 0;
  UPDATE TMP_OnorCom_Articole SET idxgrup = 0;

  MERGE INTO TMP_OnorCom_Comenzi T1
  USING (
    SELECT
      ROWID xROWID,
      Dense_Rank() OVER (ORDER BY CODCLIENT, CODSEDIU, CODFISCAL, CODAGENT, CODDELEGAT, CODPERS, FARATRANSPORT, CODMIJLTRANSP, CODTRASEULIVR, CODMONEDA, SUBUNITATEA, SCADENTAV, CURS, TIPDOC, TIPDOCAMB) idxgrup
    FROM TMP_OnorCom_Comenzi C
    WHERE C.MODDOC = 3
      AND C.CODDOC = 0
      AND Coalesce(C.GDI, 0) = 0
      AND EXISTS (SELECT 1 FROM TMP_OnorCom_Articole A WHERE A.LivrStoc &gt; 0 AND A.CodComanda = C.CodComanda)
  ) T2 ON (T1.ROWID = T2.xROWID)
  WHEN MATCHED THEN UPDATE SET T1.idxgrup = T2.idxgrup;

  MERGE INTO TMP_OnorCom_Articole A USING TMP_OnorCom_Comenzi C
  ON (A.CodComanda = C.CodComanda)
  WHEN MATCHED THEN UPDATE SET A.idxgrup = C.idxgrup;

  INSERT INTO TMP_OnorCom_GrupCom (IdxGrup, TipDoc, TipDocAmb, A1, A2, A3, A4, A5, A6 )
  SELECT IdxGrup, Min(TipDoc), Min(TipDocAmb), Sum(A1), Sum(A2), Sum(A3), Sum(A4), Sum(A5), Sum(A6)
  FROM TMP_OnorCom_Comenzi
  WHERE idxgrup &gt; 0
  GROUP BY idxgrup;

  COMMIT;
END;

PROCEDURE GET_TMP_GrupComByCod IS
BEGIN
  UPDATE TMP_OnorCom_Comenzi  SET idxgrup = 0;
  UPDATE TMP_OnorCom_Articole SET idxgrup = 0;

  MERGE INTO TMP_OnorCom_Comenzi T1
  USING (
    SELECT
      C.ROWID xROWID,
      Dense_Rank() OVER (ORDER BY CODCLIENT, CODSEDIU, CODFISCAL, CODAGENT, CODDELEGAT, CODPERS, FARATRANSPORT, CODMIJLTRANSP, CODTRASEULIVR, CODMONEDA, SUBUNITATEA, SCADENTAV, CURS, TIPDOC, TIPDOCAMB) idxgrup
    FROM TMP_OnorCom_Comenzi C
         INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C.CODCOMANDA AND TMP.FILTRU = &apos;CODCOMANDA&apos;
    WHERE C.MODDOC = 3
      AND C.CODDOC = 0
      AND Coalesce(C.GDI, 0) = 0
      AND EXISTS (SELECT 1 FROM TMP_OnorCom_Articole A WHERE A.LivrStoc &gt; 0 AND A.CodComanda = C.CodComanda)
  ) T2 ON (T1.ROWID = T2.xROWID)
  WHEN MATCHED THEN UPDATE SET T1.idxgrup = T2.idxgrup;

  MERGE INTO TMP_OnorCom_Articole A USING TMP_OnorCom_Comenzi C
  ON (A.CodComanda = C.CodComanda)
  WHEN MATCHED THEN UPDATE SET A.idxgrup = C.idxgrup;

  INSERT INTO TMP_OnorCom_GrupCom (IdxGrup, TipDoc, TipDocAmb, A1, A2, A3, A4, A5, A6 )
  SELECT C.IdxGrup, Min(C.TipDoc), Min(C.TipDocAmb), Sum(C.A1), Sum(C.A2), Sum(C.A3), Sum(C.A4), Sum(C.A5), Sum(C.A6)
  FROM TMP_OnorCom_Comenzi C
       INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.VALOARE = C.CODCOMANDA AND TMP.FILTRU = &apos;CODCOMANDA&apos;
  WHERE C.idxgrup &gt; 0
  GROUP BY C.idxgrup;

  COMMIT;
END;

PROCEDURE GET_TMP_LivrStoc(
            aCodObiect IN NUMBER,
            aTipArticol IN NUMBER,
            aCodComanda IN NUMBER,
            aDateStart IN VARCHAR2,
            aCodObiectEchiv IN NUMBER,
            aCodComanda1 IN NUMBER
          ) IS
  lTipArtRel    NUMBER(1);
  lCodObj       NUMBER(20);
  filtruGest    NUMBER(20);
  filtruIOArt   NUMBER(20);
  aNeconf       NUMBER(1);
BEGIN
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;IesLivrNeconf&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO aNeconf FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aNeconf  := 1;
  END;
  lTipArtRel := 0;
  if Nvl(aTipArticol,0) in (2,3) THEN lTipArtRel := 1; END if;

  lCodObj := aCodObiect; -- caut in stoc obiectul de pe comanda
  if aCodObiectEchiv &gt; 0 THEN
    lCodObj := aCodObiectEchiv; -- caut in stoc obiectul echivalent selectat
  END if;

  SELECT Count(1) INTO filtruGest  FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODGEST&apos;;
  SELECT Count(1) INTO filtruIOArt FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODIOART&apos;;

  DELETE FROM TMP_OnorCom_LivrStoc;
  INSERT INTO TMP_OnorCom_LivrStoc (
    CodArticol, CodGest, CodLocatie,
    Producator,
    CodTipCont, DataIntrStoc, Expira, CodSerie,
    SerieObiect,
    CodUM,
    D1,
    D2,
    D3,
    Stoc,
    STOCINITIAL,
    Preluat,
    Cantar,
    RezervatCom1Curenta,
    RezervatCom1Altele,
    RezervatComCurenta,
    RezervatComAltele,
    CodObiect, DenObiect, CodNIRSTOC, CodNIRSER,
    PrefixDoc, SeriaDoc, NrDoc )
  SELECT
    NA.CodArticol, N.Gest, NSTOC.CodLocatie,
    Decode(NSTOC.TipDocAchiz, 7, (SELECT Den_Gest FROM NGest where CodGest = NSTOC.CodGestProd), (SELECT Den_Part FROM NPart WHERE CodPart = NSToc.Furn) ) Producator,
    NSTOC.CodIOArt, N.DataNIR, NSTOC.TG, NSER.CodSerie,
    CASE WHEN NSTOC.TipSerie = 0 THEN null ELSE (SELECT Serie FROM NSerii WHERE CodSerie = NSER.CodSerie) END SerieObiect,
    NA.UM,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D1, 0) ELSE 0 END D1,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D2, 0) ELSE 0 END D2,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D3, 0) ELSE 0 END D3,
    CASE
      WHEN NSTOC.TIPSERIE &gt; 0
      THEN NSER.REST  - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSER.CODNIRSER  ), 0)
      ELSE NSTOC.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NSTOC.CODNIRSTOC), 0)
    END Stoc,
    CASE
      WHEN NSTOC.TIPSERIE &gt; 0
      THEN NSER.REST  - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSER.CODNIRSER  ), 0)
      ELSE NSTOC.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NSTOC.CODNIRSTOC), 0)
    END StocInitial,
    0 Preluat,
    ( SELECT Nvl(Sum(Net_KG), 0) FROM Cantar WHERE TipDoc IN (18, 43, 44) AND CodDoc1 = aCodComanda1 AND Nvl(Net_KG,0) &lt;&gt; 0) CANTAR, -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND RS.CodComanda1 =  aCodComanda1 AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatCom1Curenta,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND RS.CodComanda1 &lt;&gt; aCodComanda1 AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatCom1Altele,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS LEFT JOIN Comanda1 C1 on C1.CodComanda1 = RS.CodComanda1
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND C1.CodComanda  =  aCodComanda  AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatComCurenta,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS left join Comanda1 C1 on C1.CodComanda1 = RS.CodComanda1
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND C1.CodComanda  &lt;&gt; aCodComanda  AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatComAltele,
    NSTOC.CodObiect, NAO.Denumire, NSTOC.CodNIRSTOC, Nvl(NSER.CodNIRSER,0) CodNIRSER,
    COALESCE(intr.PrefixDoc, tr.PrefixDoc, ies.PrefixDoc) PrefixDoc, COALESCE(intr.SeriaDoc, tr.SeriaDoc, ies.SeriaDoc) SeriaDoc, COALESCE(intr.NrDoc, tr.NrDoc, ies.NrDoc) NrDoc
  FROM NIRStoc NSTOC
    INNER JOIN NIR N on N.CodNIR = NSTOC.CodNIR
    INNER JOIN NGEST G ON G.CodGest = N.Gest
    LEFT JOIN TMP_IOArt_Luna TIOAL on TIOAL.CodIOArt = NSTOC.CodIOArt
    LEFT JOIN NArtObj NAO on NAO.CodObiect = NSTOC.CodObiect
    LEFT JOIN NArt NA on NA.CodArticol = NAO.CodArticol
    LEFT JOIN NIRSer NSER on NSER.CodNIRStoc = NSTOC.CodNIRStoc
    LEFT JOIN intrari intr ON intr.codintr = n.codintr
    LEFT JOIN transf tr    ON tr.codtransf = n.codtransf
    LEFT JOIN iesiri ies   ON ies.codies = n.codies
  WHERE NSTOC.CodObiect = lCodObj
		AND TIOAL.MG &lt;&gt; 5 -- Metoda de Gestiune: 5 = &apos;articole/stocuri valorice&apos;
		AND Coalesce(NSER.Rest, NSTOC.Rest) &lt;&gt; 0
    AND (filtruGest  = 0 OR Nvl(N.Gest, 0)         IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODGEST&apos; ) )
    AND (filtruIOArt = 0 OR Nvl(NSTOC.CodIOArt, 0) IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODIOART&apos;) )
    AND G.CodSubunit = Pkg_Globals.GETSUBUNITATE_DOC
    and (aNeconf = 1 or (aNeconf = 2 and g.tip &lt;&gt; 4));

  delete TMP_OnorCom_LivrStoc where stoc &lt;= 0;

  COMMIT;
END;

PROCEDURE GET_TMP_LivrStocAll IS
  lTipArtRel    NUMBER(1);
  lCodObj       NUMBER(20);
  filtruGest    NUMBER(20);
  filtruIOArt   NUMBER(20);
  aNeconf       NUMBER(1);
  aSub          NUMBER(20);
BEGIN
  aSub := Pkg_Globals.GETSUBUNITATE_DOC;
  BEGIN
    SELECT TO_NUMBER(PKG_CATEGCONST.GetValConstanta(&apos;IesLivrNeconf&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) INTO aNeconf FROM DUAL;
    EXCEPTION WHEN OTHERS THEN aNeconf  := 1;
  END;
  lTipArtRel := 0;

  SELECT Count(1) INTO filtruGest  FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODGEST&apos;;
  SELECT Count(1) INTO filtruIOArt FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODIOART&apos;;

  DELETE FROM TMP_OnorCom_LivrStoc;
  INSERT INTO TMP_OnorCom_LivrStoc (
    CodArticol, CodGest, CodLocatie,
    Producator,
    CodTipCont, DataIntrStoc, Expira, CodSerie,
    SerieObiect,
    CodUM,
    D1,
    D2,
    D3,
    Stoc,
    STOCINITIAL,
    Preluat,
    Cantar,
    RezervatCom1Curenta,
    RezervatCom1Altele,
    RezervatComCurenta,
    RezervatComAltele,
    CodObiect, DenObiect, CodNIRSTOC, CodNIRSER,
    PrefixDoc, SeriaDoc, NrDoc )
  SELECT
    NA.CodArticol, N.Gest, NSTOC.CodLocatie,
    Decode(NSTOC.TipDocAchiz, 7, (SELECT Den_Gest FROM NGest where CodGest = NSTOC.CodGestProd), (SELECT Den_Part FROM NPart WHERE CodPart = NSToc.Furn) ) Producator,
    NSTOC.CodIOArt, N.DataNIR, NSTOC.TG, NSER.CodSerie,
    CASE WHEN NSTOC.TipSerie = 0 THEN null ELSE (SELECT Serie FROM NSerii WHERE CodSerie = NSER.CodSerie) END SerieObiect,
    NA.UM,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D1, 0) ELSE 0 END D1,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D2, 0) ELSE 0 END D2,
    CASE WHEN lTipArtRel = 1 THEN Nvl(NSTOC.D3, 0) ELSE 0 END D3,
    CASE
      WHEN NSTOC.TIPSERIE &gt; 0
      THEN NSER.REST  - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSER.CODNIRSER  ), 0)
      ELSE NSTOC.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NSTOC.CODNIRSTOC), 0)
    END Stoc,
    CASE
      WHEN NSTOC.TIPSERIE &gt; 0
      THEN NSER.REST  - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSER.CODNIRSER  ), 0)
      ELSE NSTOC.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NSTOC.CODNIRSTOC), 0)
    END StocInitial,
    0 Preluat,
    ( SELECT Nvl(Sum(Net_KG), 0) FROM Cantar WHERE TipDoc IN (18, 43, 44) AND Nvl(Net_KG,0) &lt;&gt; 0) CANTAR, -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatCom1Curenta,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatCom1Altele,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS LEFT JOIN Comanda1 C1 on C1.CodComanda1 = RS.CodComanda1
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatComCurenta,
    ( SELECT Nvl(Sum(RS.Rest),0)
      FROM RezervatS RS left join Comanda1 C1 on C1.CodComanda1 = RS.CodComanda1
      WHERE Nvl(RS.CodNIRStoc, 0) = Nvl(NSTOC.CodNIRStoc, 0) AND Nvl(RS.CodNIRSer, 0) = Nvl(NSER.CodNIRSer, 0) AND Nvl(RS.Rest, 0) &lt;&gt; 0
    ) RezervatComAltele,
    NSTOC.CodObiect, NAO.Denumire, NSTOC.CodNIRSTOC, Nvl(NSER.CodNIRSER,0) CodNIRSER,
    COALESCE(intr.PrefixDoc, tr.PrefixDoc, ies.PrefixDoc) PrefixDoc, COALESCE(intr.SeriaDoc, tr.SeriaDoc, ies.SeriaDoc) SeriaDoc, COALESCE(intr.NrDoc, tr.NrDoc, ies.NrDoc) NrDoc
  FROM NIRStoc NSTOC
    INNER JOIN NIR N on N.CodNIR = NSTOC.CodNIR
    INNER JOIN NGEST G ON G.CodGest = N.Gest
    LEFT JOIN TMP_IOArt_Luna TIOAL on TIOAL.CodIOArt = NSTOC.CodIOArt
    LEFT JOIN NArtObj NAO on NAO.CodObiect = NSTOC.CodObiect
    LEFT JOIN NArt NA on NA.CodArticol = NAO.CodArticol
    LEFT JOIN NIRSer NSER on NSER.CodNIRStoc = NSTOC.CodNIRStoc
    LEFT JOIN intrari intr ON intr.codintr = n.codintr
    LEFT JOIN transf tr    ON tr.codtransf = n.codtransf
    LEFT JOIN iesiri ies   ON ies.codies = n.codies
  WHERE nstoc.codobiect in (select tmp.codobiect 
                from tmp_onorcom_articole tmp
                     inner join tmp_onorcom_comenzi tmpc on tmpc.codcomanda = tmp.codcomanda
                where tmpc.flaglucru = 1
                )
		AND TIOAL.MG &lt;&gt; 5 -- Metoda de Gestiune: 5 = &apos;articole/stocuri valorice&apos;
		AND Coalesce(NSER.Rest, NSTOC.Rest) &lt;&gt; 0
    AND (filtruGest  = 0 OR Nvl(N.Gest, 0)         IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODGEST&apos; ) )
    AND (filtruIOArt = 0 OR Nvl(NSTOC.CodIOArt, 0) IN (SELECT Valoare FROM TMP_MANEVRA_LISTE WHERE UPPER(Filtru) = &apos;CODIOART&apos;) )
    AND G.CodSubunit = aSub
    and (aNeconf = 1 or (aNeconf = 2 and g.tip &lt;&gt; 4));

  delete TMP_OnorCom_LivrStoc where stoc &lt;= 0;
  delete tmp_manevra_liste where filtru = &apos;ONORCOM&apos; AND FILTRU1 = &apos;CODOBIECT&apos;;
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU,FILTRU1,VALOARE1)
  SELECT DISTINCT &apos;ONORCOM&apos;, &apos;CODOBIECT&apos;, CODOBIECT
  FROM tmp_onorcom_articole a
       inner join tmp_onorcom_comenzi c on c.codcomanda = a.codcomanda
  where c.flaglucru = 1;
  COMMIT;
END;

PROCEDURE Rezervare_Stoc(pCodObiect IN NUMBER, pCodIOArt IN NUMBER, pCodGest IN NUMBER, pMG IN NUMBER, pDataLivr IN DATE, pCant IN OUT NUMBER) IS
  vCursor     SYS_REFCURSOR;
  vCantRest   NUMBER;
  vCantRez    NUMBER;
  vCantPrel   NUMBER;
  vCodnirstoc NUMBER;
  vCodnirser  NUMBER;
  vDataMax    DATE := pDataLivr;
BEGIN

--  function ConditieData : boolean;
--  var An, Luna, Zi : word;
--  begin
--    with Stoc do begin
--     if LivrDinStocUlterior = 1 then Result := True
--     else
--     if LivrDinStocUlterior = 3 then begin
--       DecodeDate(Fields[fSTOCMOMENT_IntratLa].AsDateTime, An, Luna, Zi);
--       Result := An * 12 + Luna &lt;= g_AnLuna.Lucru.An * 12 + g_AnLuna.Lucru.Luna;
--     end
--     else
--      Result := Fields[fSTOCMOMENT_IntratLa].AsDateTime &lt;= DataFacturarii//2
--   end;

  vCantRest := pCant;
  vCantRez  := 0;
  OPEN vCursor FOR
   &apos;SELECT ns.codnirstoc, Nvl(nse.codnirser,0) codnirser
    FROM nirstoc ns
      INNER JOIN nir n ON n.codnir = ns.codnir
      LEFT JOIN nirser nse ON nse.codnirstoc = ns.codnirstoc
      LEFT JOIN nserii s ON s.codserie = nse.codserie
    WHERE ns.rest &gt; 0 AND ns.codobiect = :codobiect AND ns.codioart = :codioart AND n.gest = :Codgest
      AND n.datanir &lt;= :DataMax
    ORDER BY ns.dataachiz &apos;||CASE WHEN pMG = 2 THEN &apos;DESC&apos; ELSE &apos;ASC&apos; END ||&apos;, CASE WHEN ns.tipserie &gt; 0 THEN s.serie ELSE NULL END ASC&apos;
  USING pCodObiect, pCodIOArt, pCodGest, vDataMax;

  LOOP
    FETCH vCursor INTO vCodnirstoc, vCodnirser;
    vCantPrel := pkg_globals.GET_STOC_REAL_EXT(vCodnirstoc, vCodnirser);

    IF vCantRest &gt; 0 AND vCantPrel &gt; 0 THEN

      IF vCantPrel &gt; vCantRest
      THEN vCantPrel := vCantRest;
      END IF;

      pkg_globals.LOCK_STOC_CANT(vCodnirstoc, vCodnirser, vCantPrel);

      INSERT INTO TMP_OnorCom_StocBuf( codnirstoc, codnirser, preluat) VALUES (vCodnirstoc, vCodnirser, vCantPrel);

      vCantRez  := vCantRez  + vCantPrel;
      vCantRest := vCantRest - vCantPrel;

    END IF;
    EXIT WHEN vCursor%NOTFOUND OR vCantRest = 0;
  END LOOP;

  pCant := vCantRez;
END;

PROCEDURE PreluareAutomataDinStoc (pDataLivr IN VARCHAR2, pCodIOArt IN NUMBER, pCodGest IN NUMBER, pOrdineGR IN NUMBER DEFAULT 0, pImp IN NUMBER DEFAULT 0, pRezOnly IN NUMBER DEFAULT 0) IS
  dDataLivr   DATE;
  vMG         NUMBER;
  vCodGest    NUMBER;
  vCodIoart   NUMBER;

  vCodObiect  NUMBER;
  vRestObj    NUMBER;
  vRestCom1   NUMBER;

  vRowId      ROWID;
  vCodnirstoc NUMBER;
  vCodnirser  NUMBER;
  vPreluat    NUMBER;
BEGIN
  BEGIN
    dDataLivr := To_Date(Nvl(pDataLivr,&apos;X&apos;), &apos;DD.MM.YYYY&apos;);
  EXCEPTION WHEN OTHERS THEN
    dDataLivr := Trunc(SYSDATE);
  END;

  --LivrDinStocUlterior := KConst.GetConstObj(&apos;LivrAutUlterioare&apos;, True).AsInteger;

  -- pasul 1 preluare din rezervare comenzi
  MERGE INTO TMP_OnorCom_PrelStoc P
  USING (
    SELECT R.CodComanda1, R.Rest, R.CodNirstoc, Nvl(R.CodNirser,0) CodNirser
    FROM TMP_OnorCom_Articole  A INNER JOIN RezervatS R ON R.CodComanda1 = A.CodComanda1
  ) R ON (R.CodComanda1 = P.CodComanda1 AND R.CodNirstoc = P.CodNirstoc AND R.CodNirser = P.CodNirser)
  WHEN     MATCHED THEN UPDATE SET P.Preluat = R.Rest, P.Rezervat = R.Rest WHERE P.Preluat &lt; R.Rest
  WHEN NOT MATCHED THEN INSERT (P.CodComanda1, P.CodNirstoc, P.CodNirser, P.Preluat, P.Rezervat) VALUES (R.CodComanda1, R.CodNirstoc, R.CodNirser, R.Rest, R.Rest);

  MERGE INTO TMP_OnorCom_Articole A
  USING(
    SELECT CodComanda1, Sum(Preluat) LivrStoc
    FROM TMP_OnorCom_PrelStoc
    GROUP BY CodComanda1
  ) P ON (P.CodComanda1 = A.CodComanda1)
  WHEN MATCHED THEN UPDATE SET A.LivrStoc = P.LivrStoc WHERE A.LivrStoc &lt;&gt; P.LivrStoc;
  
  if pRezOnly = 0 then
  if pImp &gt; 0 then
    vCodObiect := 0;
    if pOrdineGR = 1 then
      FOR vREC IN (
        SELECT TMPA.CodComanda1, TMPA.CodObiect, 
               TMPA.RestLivr - TMPA.LivrStoc RestCom1, 
               Sum(TMPA.RestLivr - TMPA.LivrStoc) OVER (PARTITION BY TMPA.CodObiect) RestObj, 
               tmpa.codgest, 
               tmpa.codioart
        FROM TMP_OnorCom_Articole TMPA 
             INNER JOIN TMP_ONORCOM_COMENZI TMPC ON TMPA.CODCOMANDA = TMPC.CODCOMANDA
        WHERE TMPA.RestLivr &gt; 0 AND TipLinie = &apos;=&apos;
        ORDER BY TMPC.GRLIVR
      ) LOOP
        vCodIOArt := Nvl(vrec.CodIOArt, 0);
        vCodGest  := Nvl(vrec.CodGest,  0);

        IF vCodIOArt &lt;&gt; 0 AND vCodGest &lt;&gt; 0 THEN
          SELECT MG INTO vMG
          FROM IOART1
          WHERE CODIOART = vCodIOArt AND PKG_GLOBALS.AnLunaLucru BETWEEN ALStart AND ALStop;

          vRestCom1 := vRec.RestCom1;
          IF vCodObiect &lt;&gt; vRec.CodObiect THEN
            vCodObiect := vRec.CodObiect;
            vRestObj   := vRec.RestObj;
            Rezervare_Stoc(vCodObiect, vCodIOArt, vCodGest, vMG, dDataLivr, vRestObj);
          END IF;

          IF vRestCom1 &gt; vRestObj
          THEN vRestCom1 := vRestObj;
          END IF;

          WHILE vRestCom1 &gt; 0
          LOOP
            SELECT ROWID, codnirstoc, codnirser, preluat INTO vRowId, vcodnirstoc, vcodnirser, vpreluat FROM TMP_OnorCom_StocBuf WHERE ROWNUM = 1;
            IF vpreluat &gt; vRestCom1 THEN
              vpreluat := vRestCom1;
              UPDATE TMP_OnorCom_StocBuf SET preluat = preluat - vpreluat WHERE ROWID = vRowId;
            ELSE
              DELETE TMP_OnorCom_StocBuf WHERE ROWID = vRowId;
            END IF;

            vRestCom1 := vRestCom1 - vpreluat;
            vRestObj  := vRestObj  - vpreluat;

            MERGE INTO TMP_OnorCom_PrelStoc P
            USING (
              SELECT vREC.CodComanda1 CodComanda1, vcodnirstoc CodNirStoc, vcodnirser CodNirSer, vpreluat Preluat,
                     (select sum(r.rest) from rezervats r where r.codcomanda1 = vrec.codcomanda1 and codnirstoc = vcodnirstoc and codnirser = vcodnirser) rezervat
              FROM DUAL
            ) B ON (B.CodComanda1 = P.CodComanda1 AND B.CodNirstoc = P.CodNirstoc AND B.CodNirser = P.CodNirser)
            WHEN     MATCHED THEN UPDATE SET P.Preluat = P.Preluat + B.Preluat, P.REZERVAT = P.REZERVAT + CASE WHEN B.REZERVAT &gt; B.PRELUAT THEN B.PRELUAT ELSE B.REZERVAT END
            WHEN NOT MATCHED THEN INSERT (P.CodComanda1, P.CodNirstoc, P.CodNirser, P.Preluat, P.Rezervat) VALUES (B.CodComanda1, B.CodNirstoc, B.CodNirser, B.Preluat, CASE WHEN B.REZERVAT &gt; B.PRELUAT THEN B.PRELUAT ELSE B.REZERVAT END);
          END LOOP;
        end if;
      END LOOP;
    ELSE
      FOR vREC IN (
        SELECT CodComanda1, CodObiect, RestLivr - LivrStoc RestCom1,
          Sum(RestLivr - LivrStoc) OVER (PARTITION BY CodObiect) RestObj, codgest, codioart
        FROM TMP_OnorCom_Articole
        WHERE RestLivr &gt; 0 AND TipLinie = &apos;=&apos;
        ORDER BY CodObiect
      ) LOOP
        vCodIOArt := Nvl(vrec.CodIOArt, 0);
        vCodGest  := Nvl(vrec.CodGest,  0);

        IF vCodIOArt &lt;&gt; 0 AND vCodGest &lt;&gt; 0 THEN
          SELECT MG INTO vMG
          FROM IOART1
          WHERE CODIOART = vCodIOArt AND PKG_GLOBALS.AnLunaLucru BETWEEN ALStart AND ALStop;

          vRestCom1 := vRec.RestCom1;
          IF vCodObiect &lt;&gt; vRec.CodObiect THEN
            vCodObiect := vRec.CodObiect;
            vRestObj   := vRec.RestObj;
            Rezervare_Stoc(vCodObiect, vCodIOArt, vCodGest, vMG, dDataLivr, vRestObj);
          END IF;

          IF vRestCom1 &gt; vRestObj
          THEN vRestCom1 := vRestObj;
          END IF;

          WHILE vRestCom1 &gt; 0
          LOOP
            SELECT ROWID, codnirstoc, codnirser, preluat INTO vRowId, vcodnirstoc, vcodnirser, vpreluat FROM TMP_OnorCom_StocBuf WHERE ROWNUM = 1;
            IF vpreluat &gt; vRestCom1 THEN
              vpreluat := vRestCom1;
              UPDATE TMP_OnorCom_StocBuf SET preluat = preluat - vpreluat WHERE ROWID = vRowId;
            ELSE
              DELETE TMP_OnorCom_StocBuf WHERE ROWID = vRowId;
            END IF;

            vRestCom1 := vRestCom1 - vpreluat;
            vRestObj  := vRestObj  - vpreluat;

            MERGE INTO TMP_OnorCom_PrelStoc P
            USING (
              SELECT vREC.CodComanda1 CodComanda1, vcodnirstoc CodNirStoc, vcodnirser CodNirSer, vpreluat Preluat,
                     (select sum(r.rest) from rezervats r where r.codcomanda1 = vrec.codcomanda1 and codnirstoc = vcodnirstoc and codnirser = vcodnirser) rezervat
              FROM DUAL
            ) B ON (B.CodComanda1 = P.CodComanda1 AND B.CodNirstoc = P.CodNirstoc AND B.CodNirser = P.CodNirser)
            WHEN     MATCHED THEN UPDATE SET P.Preluat = P.Preluat + B.Preluat, P.REZERVAT = P.REZERVAT + CASE WHEN B.REZERVAT &gt; B.PRELUAT THEN B.PRELUAT ELSE B.REZERVAT END
            WHEN NOT MATCHED THEN INSERT (P.CodComanda1, P.CodNirstoc, P.CodNirser, P.Preluat, P.Rezervat) VALUES (B.CodComanda1, B.CodNirstoc, B.CodNirser, B.Preluat, CASE WHEN B.REZERVAT &gt; B.PRELUAT THEN B.PRELUAT ELSE B.REZERVAT END);
          END LOOP;
        end if;
      END LOOP;
    END IF;

    MERGE INTO TMP_OnorCom_Articole A
    USING(
      SELECT CodComanda1, Sum(Preluat) LivrStoc
      FROM TMP_OnorCom_PrelStoc
      GROUP BY CodComanda1
    ) P ON (P.CodComanda1 = A.CodComanda1)
    WHEN MATCHED THEN UPDATE SET A.LivrStoc = P.LivrStoc WHERE A.LivrStoc &lt;&gt; P.LivrStoc;
  ELSE
    -- pasul 2 preluare din Gestiunea si Tipul contabil predefinite
    vCodIOArt := Nvl(pCodIOArt, 0);
    vCodGest  := Nvl(pCodGest,  0);

    IF vCodIOArt &lt;&gt; 0 AND vCodGest &lt;&gt; 0 THEN
      SELECT MG INTO vMG
      FROM IOART1
      WHERE CODIOART = vCodIOArt AND PKG_GLOBALS.AnLunaLucru BETWEEN ALStart AND ALStop;

      vCodObiect := 0;

      if pOrdineGR = 1 then
        FOR vREC IN (
          SELECT TMPA.CodComanda1, TMPA.CodObiect, TMPA.RestLivr - TMPA.LivrStoc RestCom1,
            Sum(TMPA.RestLivr - TMPA.LivrStoc) OVER (PARTITION BY TMPA.CodObiect) RestObj
          FROM TMP_OnorCom_Articole TMPA INNER JOIN TMP_ONORCOM_COMENZI TMPC ON TMPA.CODCOMANDA = TMPC.CODCOMANDA
          WHERE TMPA.RestLivr &gt; 0 AND TipLinie = &apos;=&apos;
          ORDER BY TMPC.GRLIVR
        ) LOOP
          vRestCom1 := vRec.RestCom1;
          IF vCodObiect &lt;&gt; vRec.CodObiect THEN
            vCodObiect := vRec.CodObiect;
            vRestObj   := vRec.RestObj;
            Rezervare_Stoc(vCodObiect, vCodIOArt, vCodGest, vMG, dDataLivr, vRestObj);
          END IF;

          IF vRestCom1 &gt; vRestObj
          THEN vRestCom1 := vRestObj;
          END IF;

          WHILE vRestCom1 &gt; 0
          LOOP
            SELECT ROWID, codnirstoc, codnirser, preluat INTO vRowId, vcodnirstoc, vcodnirser, vpreluat FROM TMP_OnorCom_StocBuf WHERE ROWNUM = 1;
            IF vpreluat &gt; vRestCom1 THEN
              vpreluat := vRestCom1;
              UPDATE TMP_OnorCom_StocBuf SET preluat = preluat - vpreluat WHERE ROWID = vRowId;
            ELSE
              DELETE TMP_OnorCom_StocBuf WHERE ROWID = vRowId;
            END IF;

            vRestCom1 := vRestCom1 - vpreluat;
            vRestObj  := vRestObj  - vpreluat;

            MERGE INTO TMP_OnorCom_PrelStoc P
            USING (
              SELECT vREC.CodComanda1 CodComanda1, vcodnirstoc CodNirStoc, vcodnirser CodNirSer, vpreluat Preluat
              FROM DUAL
            ) B ON (B.CodComanda1 = P.CodComanda1 AND B.CodNirstoc = P.CodNirstoc AND B.CodNirser = P.CodNirser)
            WHEN     MATCHED THEN UPDATE SET P.Preluat = P.Preluat + B.Preluat
            WHEN NOT MATCHED THEN INSERT (P.CodComanda1, P.CodNirstoc, P.CodNirser, P.Preluat) VALUES (B.CodComanda1, B.CodNirstoc, B.CodNirser, B.Preluat);
          END LOOP;
        END LOOP;
      ELSE
        FOR vREC IN (
          SELECT CodComanda1, CodObiect, RestLivr - LivrStoc RestCom1, Sum(RestLivr - LivrStoc) OVER (PARTITION BY CodObiect) RestObj
          FROM TMP_OnorCom_Articole
          WHERE RestLivr &gt; 0
          ORDER BY CodObiect
        ) LOOP
          vRestCom1 := vRec.RestCom1;
          IF vCodObiect &lt;&gt; vRec.CodObiect THEN
            vCodObiect := vRec.CodObiect;
            vRestObj   := vRec.RestObj;
            Rezervare_Stoc(vCodObiect, vCodIOArt, vCodGest, vMG, dDataLivr, vRestObj);
          END IF;

          IF vRestCom1 &gt; vRestObj
          THEN vRestCom1 := vRestObj;
          END IF;

          WHILE vRestCom1 &gt; 0
          LOOP
            SELECT ROWID, codnirstoc, codnirser, preluat INTO vRowId, vcodnirstoc, vcodnirser, vpreluat FROM TMP_OnorCom_StocBuf WHERE ROWNUM = 1;
            IF vpreluat &gt; vRestCom1 THEN
              vpreluat := vRestCom1;
              UPDATE TMP_OnorCom_StocBuf SET preluat = preluat - vpreluat WHERE ROWID = vRowId;
            ELSE
              DELETE TMP_OnorCom_StocBuf WHERE ROWID = vRowId;
            END IF;

            vRestCom1 := vRestCom1 - vpreluat;
            vRestObj  := vRestObj  - vpreluat;

            MERGE INTO TMP_OnorCom_PrelStoc P
            USING (
              SELECT vREC.CodComanda1 CodComanda1, vcodnirstoc CodNirStoc, vcodnirser CodNirSer, vpreluat Preluat FROM DUAL
            ) B ON (B.CodComanda1 = P.CodComanda1 AND B.CodNirstoc = P.CodNirstoc AND B.CodNirser = P.CodNirser)
            WHEN     MATCHED THEN UPDATE SET P.Preluat = P.Preluat + B.Preluat
            WHEN NOT MATCHED THEN INSERT (P.CodComanda1, P.CodNirstoc, P.CodNirser, P.Preluat) VALUES (B.CodComanda1, B.CodNirstoc, B.CodNirser, B.Preluat);
          END LOOP;
        END LOOP;
      END IF;

      MERGE INTO TMP_OnorCom_Articole A
      USING(
        SELECT CodComanda1, Sum(Preluat) LivrStoc
        FROM TMP_OnorCom_PrelStoc
        GROUP BY CodComanda1
      ) P ON (P.CodComanda1 = A.CodComanda1)
      WHEN MATCHED THEN
        UPDATE SET A.LivrStoc = P.LivrStoc
        WHERE A.LivrStoc &lt;&gt; P.LivrStoc;
    END IF;
  end if;
  end if;

  UPDATE TMP_OnorCom_Articole
  SET flaginchidere = 1
  WHERE Abs(Round( RestLivr - LivrStoc - LivrEchiv, 2)) &lt; RESTNEGLIJCMD AND TipLinie = &apos;=&apos;;

  -- stef Linii de comenszi de tip serviciu
  UPDATE TMP_OnorCom_Articole
  SET flaginchidere = 1, LivrStoc = RestLivr
  WHERE TipLinie = &apos;S&apos;;

  UPDATE TMP_OnorCom_Comenzi C
  SET COUNTNEINCHISE = (SELECT Count(1) FROM TMP_OnorCom_Articole A WHERE A.CodComanda = C.CodComanda AND A.FLAGINCHIDERE = 0);

  FOR V_REC IN (SELECT TMP.CODCOMANDA1, TMP.CODNIRSTOC
                FROM TMP_ONORCOM_PRELSTOC TMP
                     INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = TMP.CODNIRSTOC
                     INNER JOIN COMANDA1 C1 ON TMP.CODCOMANDA1 = C1.CODCOMANDA1
                WHERE C1.CODOBIECT &lt;&gt; NS.CODOBIECT
               ) LOOP
    DELETE TMP_ONORCOM_PRELSTOC WHERE CODCOMANDA1 = V_REC.CODCOMANDA1 AND CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;

  COMMIT;
END;

procedure PreluareAutomataCantariri is
aCantPrel number(20,7);
aCantStoc number(20,7);
begin
  for v_rec in (select c.codobiect, sum(c.net_kg) preluat, coalesce(c.serie,0) codserie
                from tmp_manevra_liste tmp
                     inner join cantar c on c.codcantar = to_number(tmp.valoare1)
                where tmp.filtru = &apos;ONORCOM&apos; and tmp.filtru1 = &apos;CODCANTAR&apos;
                group by c.codobiect
               ) loop
    aCantPrel := v_rec.preluat;           
    for v_cmd in (
      select o.codobiect, o.restlivr, coalesce(ioa1.mg,1) mg, o.codcomanda1
      from tmp_onorcom_comenzi c
           inner join tmp_onorcom_articole o on o.codcomanda = c.codcomanda
           inner join nartobj obj on obj.codobiect = o.codobiect
           inner join nartimplicite imp on imp.codarticol = obj.codarticol and imp.codsubunit = pkg_globals.GETSUBUNITATE
           inner join ioart1 ioa1 on ioa1.codioart = imp.contimplicit and pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU between ioa1.alstart and ioa1.alstop
      where c.flaglucru = 1 and o.restlivr &gt; 0 and o.codobiect = v_rec.codobiect
      order by o.termenlivr
    ) loop
      if aCantPrel &gt; 0 then
        if v_cmd.restlivr &gt; aCantPrel then
          -- restul pe linia de comanda este mai mare decat s-a preluat la cantar
          -- incerc sa preiau din stoc
          if v_cmd.mg = 1 then
            for v_stoc in (
              select st.codnirstoc, st.codnirser, st.stocinitial, st.stoc
              from TMP_OnorCom_LivrStoc st
                   inner join nirstoc ns on st.codnirstoc = ns.codnirstoc
              where st.codobiect = v_rec.codobiect and coalesce(st.codserie,0) = v_rec.codserie
              order by ns.dataachiz
            ) loop
              if aCantPrel &gt; 0 then
                if v_stoc.stoc &gt; aCantPrel then
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, aCantPrel);
                  update TMP_OnorCom_LivrStoc set stocinitial = stocinitial - aCantPrel, stoc = stoc - aCantPrel where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := 0;
                else
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, v_stoc.stoc);
                  update TMP_OnorCom_LivrStoc set stocinitial = 0, stoc = 0 where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := aCantPrel - v_stoc.stoc;
                end if;
              end if;  
            end loop;
          else
            for v_stoc in (
              select st.codnirstoc, st.codnirser, st.stocinitial, st.stoc
              from TMP_OnorCom_LivrStoc st
                   inner join nirstoc ns on ns.codnirstoc = st.codnirstoc
              where st.codobiect = v_rec.codobiect and coalesce(st.codserie,0) = v_rec.codserie     
              order by ns.dataachiz desc
            ) loop
              if aCantPrel &gt; 0 then
                if v_stoc.stoc &gt; aCantPrel then
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, aCantPrel);
                  update TMP_OnorCom_LivrStoc set stocinitial = stocinitial - aCantPrel, stoc = stoc - aCantPrel where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := 0;
                else
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, v_stoc.stoc);
                  update TMP_OnorCom_LivrStoc set stocinitial = 0, stoc = 0 where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := aCantPrel - v_stoc.stoc;
                end if;
              end if;  
            end loop;
          end if;  
        else
          -- restul pe linia de comanda este mai mic decat s-a preluat la cantar
          -- incerc sa preiau din stoc
          if v_cmd.mg = 1 then
            for v_stoc in (
              select st.codnirstoc, st.codnirser, st.stocinitial, st.stoc
              from TMP_OnorCom_LivrStoc st
                   inner join nirstoc ns on ns.codnirstoc = st.codnirstoc
              where st.codobiect = v_rec.codobiect and coalesce(st.codserie,0) = v_rec.codserie
              order by ns.dataachiz
            ) loop
              if aCantPrel &gt; 0 then
                if v_stoc.stoc &gt; v_cmd.restlivr then
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, v_cmd.restlivr);
                  update TMP_OnorCom_LivrStoc set stocinitial = stocinitial - v_cmd.restlivr, stoc = stoc - v_cmd.restlivr where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := 0;
                else
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, v_stoc.stoc);
                  update TMP_OnorCom_LivrStoc set stocinitial = 0, stoc = 0 where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := aCantPrel - v_stoc.stoc;
                end if;
              end if;  
            end loop;
          else
            for v_stoc in (
              select st.codnirstoc, st.codnirser, st.stocinitial, st.stoc
              from TMP_OnorCom_LivrStoc st
                   inner join nirstoc ns on ns.codnirstoc = st.codnirstoc
              where st.codobiect = v_rec.codobiect and coalesce(st.codserie,0) = v_rec.codserie     
              order by ns.dataachiz desc
            ) loop
              if aCantPrel &gt; 0 then
                if v_stoc.stoc &gt; aCantPrel then
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, aCantPrel);
                  update TMP_OnorCom_LivrStoc set stocinitial = stocinitial - aCantPrel, stoc = stoc - aCantPrel where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := 0;
                else
                  insert into tmp_onorcom_prelstoc(codcomanda1,codnirstoc,codnirser,preluat)
                  values (v_cmd.codcomanda1, v_stoc.codnirstoc, v_stoc.codnirser, v_stoc.stoc);
                  update TMP_OnorCom_LivrStoc set stocinitial = 0, stoc = 0 where codnirstoc = v_stoc.codnirstoc and codnirser = v_stoc.codnirser;
                  aCantPrel := aCantPrel - v_stoc.stoc;
                end if;
              end if;  
            end loop;
          end if;
        end if;
      end if;  
      update tmp_onorcom_articole a
        set 
          livrstoc = livrstoc + coalesce((select sum(preluat) from tmp_onorcom_prelstoc s where s.codcomanda1 = a.codcomanda1),0),
          restlivr = restlivr - coalesce((select sum(preluat) from tmp_onorcom_prelstoc s where s.codcomanda1 = a.codcomanda1),0)
        where a.codcomanda1 = v_cmd.codcomanda1;
    end loop;           
  end loop;
  commit;             
end;  

END PKG_OnorareComenzi;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OPERATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31F09F2B466F776695987709AFEDD3ADCAEE3103</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_OPERATII IS

PROCEDURE SETCLASAOP(aCLASA IN NUMBER)
IS
BEGIN
  CLASA_OP := aCLASA;
END;

FUNCTION CONDITIECLASA(aCLASA IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF CLASA_OP = 0 THEN RETURN 1;
  ELSE
    IF aCLASA = CLASA_OP THEN RETURN 1; ELSE RETURN 0; END IF;
  END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodOp INTO Tmp FROM NOPER WHERE CodOp = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NOPER  WHERE CodOp = RecId ;
  DELETE FROM NOPER1  WHERE CodOp = RecId ;
  NotifyModif(2, RECID, &apos;NOPER&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NOPER FIELDS( CodOp ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NOPER ( CodOp, CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,
                           LocMunca,Marcaauto,Modelauto,Facturabil,Durata, Ore, CodTipLucrare, Subunitatea, Codprestatie )
    ( SELECT CodOp, CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,
             LocMunca,Marcaauto,Modelauto,Facturabil,Durata, Round(Durata/60, 4), CodTipLucrare, Subunitatea, CodPrestatie
      FROM NOPER WHERE CodOp = RecId ) ;
      
  INSERT INTO TMP_NOPER1 (Codop1,CODOP,CODOBIECT,CANT,UMSEC,PRET,DENUM,DENOBIECT) 
  (Select O.Codop1,O.CODOP,O.CODOBIECT,O.CANT,O.UMSEC,O.PRET,U.DEN_UM DENUM, J.Denumire DENOBIECT 
    from NOper1 O 
    left join NUM U on U.Codum=O.UMSEC 
    left join NARTOBJ J on J.Codobiect=O.CodObiect
    WHERE O.CODoP = RecId);
  COMMIT;    
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodOp INTO RecId FROM TMP_NOPER;
    UPDATE NOPER SET ( CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,LocMunca,Marcaauto,Modelauto,Facturabil,Durata, CodTipLucrare, Subunitatea, CodPrestatie )
       = ( SELECT CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,LocMunca,Marcaauto,Modelauto,Facturabil,Durata, CodTipLucrare, Subunitatea, CodPrestatie
          FROM TMP_NOPER )
      WHERE CodOp = RecId ;

    DELETE FROM NOper1 
    where CODOp = RecID 
    and CodOp1 not in (Select CODOp1 from TMP_NOper1);


    for v_rec in (select * from TMP_NOper1 where CODOp1 &lt; 0) loop
        INSERT INTO NOPER1 
             ( 
               Codop1,
               CODOP,
               CODOBIECT,
               CANT,
               UMSEC,
               PRET 
              )
           values
             (
               Seq_Noper1_CodOp1.Nextval,
               RecId,
               V_REC.CODOBIECT,
               V_REC.CANT,
               V_REC.UMSEC,
               V_REC.PRET
              );
    end loop;

    for v_rec in (select * from TMP_NOper1 where CODOp1 &gt; 0) loop
        Update NOPER1 SET 
               CODOBIECT = V_REC.CODOBIECT,
               CANT      = V_REC.CANT,
               UMSEC     = V_REC.UMSEC,
               PRET      = V_REC.PRET
         where CodOp1 = V_Rec.Codop1;
    end loop;

  ELSE  -- INSERT
    SELECT SEQ_NOPER_CODOP.NextVal INTO RecId FROM DUAL;

    INSERT INTO NOPER ( CodOp, CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,LocMunca,Marcaauto,Modelauto,Facturabil,Durata, CodTipLucrare, Subunitatea, CodPrestatie )
    ( SELECT  RecId, CodExtern, Denumire, ClasaOp, Tip, Activ, CodServiciu, CodTarif,LocMunca,Marcaauto,Modelauto,Facturabil,Durata, CodTipLucrare, Subunitatea, CodPrestatie
      FROM TMP_NOPER ) ;
      
    for v_rec in (select * from TMP_NOper1 where CODOp1 &lt; 0) loop
        INSERT INTO NOPER1 
             ( 
               Codop1,
               CODOP,
               CODOBIECT,
               CANT,
               UMSEC,
               PRET 
              )
           values
             (
               Seq_Noper1_CodOp1.Nextval,
               RecId,
               V_REC.CODOBIECT,
               V_REC.CANT,
               V_REC.UMSEC,
               V_REC.PRET
              );
    end loop;



  END IF;
  NotifyModif(OPERATION, RECID, &apos;NOPER&apos;);  

  COMMIT;
END;
  
end pkg_operatii; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C63EE1C7B149CA4ED7696EE3FD6E91564894073A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_OPORTUNITATI IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_55&apos;;
DoCommit boolean := true;

procedure SP_LockRecord(RecId in NUMBER) is
  Tmp NUMBER(20);
begin
  SELECT CodOportunitate INTO Tmp FROM Oportunitati WHERE CodOportunitate = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
aDoc varchar2(200);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
BEGIN
  SP_LOCKRECORD(RecId);
  SELECT
    Nvl(CODCARNETDOC,0),
    NRDOC
  INTO
    ACARNETDOC,
    ANRDOC
  FROM
    Oportunitati
  WHERE
    CodOportunitate = RECID;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 82);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Oportunitate &quot;&apos;||prefixdoc||nrdoc||&apos;/&apos;||datadoc||&apos;&quot;&apos; INTO aDoc FROM Oportunitati WHERE codoportunitate = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;Oportunitati&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE FROM Oportunitati1 WHERE CodOportunitate = RecId;
  DELETE FROM Oportunitati WHERE CodOportunitate = RecId;
  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = 82)or(CODDOCASOC = RECID AND TIPDOCASOC = 82);
  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;

  NotifyModif(2, RECID, &apos;OPORTUNITATI&apos;);

  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_Oportunitati FIELDS(CodOportunitate) VALUES (0);
  PKG_CFGTABLES.EXT_INSERTRECORD(82); 
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.GETANLUCRU,pkg_globals.GETlunalucru), &apos;1&apos;)
	INTO TaskFirma from dual;
  INSERT INTO Tmp_Oportunitati (
    CodOportunitate,
    PrefixDoc, NrDoc, DataDoc,
    CodCarnetDoc,
    CodPartener, CodMoneda, Tip, CodAgent,
    CodCampanie, VenitEst, VenitProb,
    CodSubunitate, CodOferta, CodComanda, CodContract,
    An, Luna,
    ProbVanz, DataSemnare,
    PartCodFiscal, PartLocalit, PartCifraAfaceri, PartNrAngajati, PartDomeniuAct,
    SeriaDoc, CodLead, CodTask, UserID, CodProiectCRM, Codclaseopt, Codlocatie, Obs,
    Curs, CodFiscal
  )
  SELECT
    O.CodOportunitate,
    O.PrefixDoc, O.NrDoc, O.DataDoc,
    O.CodCarnetDoc,
    O.CodPartener, O.CodMoneda, O.Tip, O.CodAgent,
    O.CodCampanie, O.VenitEst, O.VenitProb,
    O.CodSubunitate, OFE.CodOferta, COM.CodComanda, CONTR.CodContract,
    O.An, O.Luna,
    O.ProbVanz, O.DataSemnare,
    coalesce(CF.CodFiscal, P.CodFiscal), P.Den_Localit, P.CifraAfaceri, P.NrAngajati, P.DenDomeniuAct,
    O.SeriaDoc, O.CodLead, 
		Case when TaskFirma = 2 then TSK_F.CodTask else TSK.CodTask end CodTask, O.UserID,
    O.CodProiectCRM, O.Codclaseopt, O.CodLocatie, O.Obs, O.Curs, coalesce(O.CodFiscal, p.COD_CODFISCAL)  
  FROM Oportunitati O
    INNER JOIN V_NPART P ON P.CodPart = O.CodPartener
    LEFT JOIN OFERTA OFE ON OFE.CodOferta = O.CodOferta AND Nvl(OFE.Anulat,0) = 0
    LEFT JOIN CONTRACT CONTR ON CONTR.CodContract = O.CodContract AND Nvl(CONTR.Anulat,0) = 0
    LEFT JOIN COMANDA COM ON COM.CodComanda = O.CodComanda AND Nvl(COM.Anulat,0) = 0
    LEFT JOIN WINMADMIN.SETTASK TSK ON TSK.CodTask = O.CodTask AND NVL(TSK.Sters,0) = 0
    LEFT JOIN SETTASK TSK_F ON TSK_F.CodTask = O.CodTask AND NVL(TSK_F.Sters,0) = 0
    LEFT JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = O.CODFISCAL
  WHERE O.CodOportunitate = RecId;

  if TaskFirma = 2 then 
		INSERT INTO Tmp_Oportunitati1 (CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp, CodTask, Task,CodPers)
		SELECT CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp,
					 o1.CodTask, T.Executant||&apos;-&apos;||T.DataTask, o1.CodPers
		FROM Oportunitati1 o1 left join SetTask T on T.CodTask = O1.Codtask
		WHERE CodOportunitate = RecId;
	else
		INSERT INTO Tmp_Oportunitati1 (CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp, CodTask, Task,CodPers)
		SELECT CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp,
					 o1.CodTask, T.Executant||&apos;-&apos;||T.DataTask, o1.CodPers
		FROM Oportunitati1 o1 left join WinMAdmin.SetTask T on T.CodTask = O1.Codtask
		WHERE CodOportunitate = RecId;
  end if;
  PKG_CFGTABLES.EXT_GOTORECORD(82);
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
aDoc varchar2(200);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
begin
  SELECT
    Nvl(CODCARNETDOC,0),
    NRDOC
  INTO
    ACARNETDOC,
    ANRDOC
  FROM
    tmp_Oportunitati;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (82); 
  if Operation = 0 then -- UPDATE
    SELECT CodOportunitate INTO RecId FROM Tmp_Oportunitati;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Oportunitate &quot;&apos;||prefixdoc||nrdoc||&apos;/&apos;||datadoc||&apos;&quot;&apos; INTO aDoc FROM Oportunitati WHERE codoportunitate = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Oportunitati&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE Oportunitati SET (
      CodOportunitate,
      PrefixDoc, NrDoc, DataDoc,
      CodCarnetDoc,
      CodPartener, CodMoneda, Tip, CodAgent,
      CodCampanie, VenitEst, VenitProb,
      CodSubunitate, CodOferta, CodComanda, CodContract,
      An, Luna,
      ProbVanz, DataSemnare,
      SeriaDoc, CodLead, CodTask, UserID, CodProiectCRM, Codclaseopt,
      CodLocatie, Obs, Curs, CodFiscal
    ) = (
      SELECT
        CodOportunitate,
        PrefixDoc, NrDoc, DataDoc,
        CodCarnetDoc,
        CodPartener, CodMoneda, Tip, CodAgent,
        CodCampanie, VenitEst, VenitProb,
        CodSubunitate, CodOferta, CodComanda, CodContract,
        EXTRACT(YEAR FROM DataDoc), EXTRACT(MONTH FROM DataDoc),
        ProbVanz, DataSemnare,
        SeriaDoc, CodLead, CodTask, UserID, CodProiectCRM, Codclaseopt,
        CodLocatie, Obs, Curs, CodFiscal
      FROM Tmp_Oportunitati
    )
    WHERE CodOportunitate = RecId;

    DELETE FROM Oportunitati1
    WHERE
      CodOportunitate = RecId AND
      CodOportunitate1 NOT IN (SELECT CodOportunitate1 FROM Tmp_Oportunitati1);
    for V_Rec in
      (SELECT * FROM Tmp_Oportunitati1 ORDER BY IndexLocal)
    loop
      if nvl(V_Rec.CodOportunitate1, 0) &gt; 0 then
        UPDATE Oportunitati1
        SET
          IndexLocal = V_Rec.IndexLocal,
          Stadiu = V_Rec.Stadiu,
          CodAgent = V_Rec.CodAgent,
          Info = V_Rec.Info,
          DataC = V_Rec.DataC,
          CodMotiv = v_rec.CodMotiv,
          FollowUp = v_rec.FollowUp,
          CodTask  = v_rec.Codtask,
          CodPers  = v_rec.CodPers
        WHERE CodOportunitate1 = V_Rec.CodOportunitate1;
      else
        INSERT INTO Oportunitati1 (
          CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp, Codtask, CodPers
        )
        VALUES (
          Seq_Oportunitati1_CO1.NextVal, RecId, V_Rec.IndexLocal, V_Rec.Stadiu, V_Rec.CodAgent, V_Rec.Info, V_Rec.DataC, v_rec.CodMotiv, v_rec.FollowUp, v_rec.Codtask,
          v_rec.Codpers
        );
      end if;
    end loop;
  else  -- INSERT
    SELECT Seq_Oportunitati_CO.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;OPORTUNITATI&apos;, RecId);
    INSERT INTO Oportunitati (
      CodOportunitate,
      PrefixDoc, NrDoc, DataDoc,
      CodCarnetDoc,
      CodPartener, CodMoneda, Tip, CodAgent,
      CodCampanie, VenitEst, VenitProb,
      CodSubunitate, CodOferta, CodComanda, CodContract,
      An, Luna,
      ProbVanz, DataSemnare,
      SeriaDoc, CodLead, CodTask, UserID, Datacreare, CodProiectCRM, Codclaseopt, CodLocatie, Obs,
      Curs, CodFiscal
    )
    SELECT
      RecId,
      PrefixDoc, NrDoc, DataDoc,
      CodCarnetDoc,
      CodPartener, CodMoneda, Tip, CodAgent,
      CodCampanie, VenitEst, VenitProb,
      CodSubunitate, CodOferta, CodComanda, CodContract,
      EXTRACT(YEAR FROM DataDoc), EXTRACT(MONTH FROM DataDoc),
      ProbVanz, DataSemnare,
      SeriaDoc, CodLead, CodTask, pkg_globals.GETUSERID, SysDate, CodProiectCRM, Codclaseopt, CodLocatie, Obs,
      Curs, CodFiscal
    FROM Tmp_Oportunitati;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Oportunitate &quot;&apos;||prefixdoc||nrdoc||&apos;/&apos;||datadoc||&apos;&quot;&apos; INTO aDoc FROM Oportunitati WHERE codoportunitate = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;Oportunitati&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO Oportunitati1 (
      CodOportunitate1, CodOportunitate, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp,Codtask, CodPers)
    SELECT
      Seq_Oportunitati1_CO1.NextVal, RecId, IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp,Codtask, CodPers
    FROM (
      SELECT IndexLocal, Stadiu, CodAgent, Info, DataC, CodMotiv, FollowUp,Codtask,CodPers
      FROM Tmp_Oportunitati1
      ORDER BY IndexLocal
    );
    -- actualizare CARNETE DOCUMENTE
    --IF (CARNETDOC_I &lt;&gt; 0) AND (NRDOC_I &lt;&gt; 0) AND (aCARNET &lt;&gt; CARNETDOC_I OR aNUMARDOC &lt;&gt; NRDOC_I) THEN
    --  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    --  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
    --END IF;
    --PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNUMARDOC);
  end if;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, TO_CHAR(ANRDOC));
  END IF;
  
  PKG_CFGTABLES.EXT_POSTRECORDS(82);
  NotifyModif(OPERATION, RECID, &apos;OPORTUNITATI&apos;);

  if DoCommit then
    COMMIT;
  end if;  
end;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

function GetDocInfo(aCodDoc in NUMBER, aTipDoc in NUMBER) return VARCHAR2 is
  lResult VARCHAR2(40) := &apos;-Nedefinit-&apos;;
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
  case aTipDoc
    when 18 then SELECT PREFIXDOC||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,   &apos;dd.mm.yyyy&apos;) INTO lResult FROM Comanda  WHERE CodComanda  = aCodDoc;
    when 34 then SELECT &apos;C.&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataDoc,   &apos;dd.mm.yyyy&apos;) INTO lResult FROM Contract WHERE CodContract = aCodDoc;
    when 50 then SELECT &apos;O.&apos;||SeriaDoc||NrDoc||&apos;/&apos;||To_Char(DataOferta,&apos;dd.mm.yyyy&apos;) INTO lResult FROM Oferta   WHERE CodOferta   = aCodDoc;
    when 54 then 
			if TaskFirma = 2 
			then SELECT Username||&apos;/&apos;||To_Char(DataTask,&apos;dd.mm.yyyy&apos;) INTO lResult FROM SetTask WHERE  CodTask  = aCodDoc;
			else SELECT Username||&apos;/&apos;||To_Char(DataTask,&apos;dd.mm.yyyy&apos;) INTO lResult FROM WinMAdmin.SetTask WHERE  CodTask  = aCodDoc;
			end if;
    else lResult := &apos;-Nedefinit-&apos;;
  end case;
  return lResult;
end;

procedure StergeCodDoc (aCodOportunitate in NUMBER, aCodDoc in NUMBER, aTipDoc in NUMBER) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  vVenitEstimat NUMBER;

BEGIN
  vVenitEstimat := 0;

  SELECT Nvl(Sum(D1.CANTACCEPTAT*D1.PU),0) INTO vVenitEstimat
  FROM Oportunitati O
    INNER JOIN Comanda D ON D.CodComanda = O.CodComanda
    INNER JOIN Comanda1 D1 ON D1.CodComanda = D.CodComanda
  WHERE O.CodOportunitate = aCodOportunitate AND D.TipDoc &lt;&gt; aTipDoc;

  IF vVenitEstimat = 0 THEN
    SELECT Nvl(Sum(D1.CANT*D1.PRET),0) INTO vVenitEstimat
    FROM Oportunitati O
      INNER JOIN CONTRACT D ON D.CodContract = O.CodContract
      INNER JOIN CONTRACT1 D1 ON D1.CodContract = D.CodContract
    WHERE O.CodOportunitate = aCodOportunitate AND D.TipDoc &lt;&gt; aTipDoc;
  END IF;

  IF vVenitEstimat = 0 THEN
    SELECT Nvl(Sum(D1.CANTMIN*D1.PRET),0) INTO vVenitEstimat
    FROM Oportunitati O
      INNER JOIN OFERTA D ON D.CodOferta = O.CodOferta
      INNER JOIN OFERTA1 D1 ON D1.CodOferta = D.CodOferta
    WHERE O.CodOportunitate = aCodOportunitate AND D.TipDoc &lt;&gt; aTipDoc;
  END IF;

  CASE aTipDoc
    WHEN 18 THEN
      UPDATE Oportunitati SET CodComanda = 0, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
    WHEN 34 THEN
      UPDATE Oportunitati SET CodContract = 0, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
    WHEN 50 THEN
      UPDATE Oportunitati SET CodOferta = 0, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
    WHEN 55 THEN
      UPDATE Oportunitati SET CodTask = 0 WHERE CodOportunitate = aCodOportunitate;
  END CASE;
  COMMIT;
END;

procedure AdaugaCodDoc (aCodOportunitate in NUMBER, aCodDoc in NUMBER, aTipDoc in NUMBER, aOldCodDoc in number) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
  vVenitEstimat NUMBER;                                           
  aTask varchar2(100);
TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
  CASE aTipDoc
    WHEN 18 THEN
      SELECT Nvl(Sum(CANTACCEPTAT*PU),0) INTO vVenitEstimat FROM Comanda1 WHERE CodComanda = aCodDoc;
      UPDATE Oportunitati SET CodComanda = aCodDoc, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
    WHEN 34 THEN
      SELECT Nvl(Sum(CANT*PRET),0) INTO vVenitEstimat FROM Contract1 WHERE CodContract = aCodDoc;
      UPDATE Oportunitati SET CodContract = aCodDoc, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
      if aOldCodDoc &gt; 0 then
        update contract set anulat = 1 where codcontract = aOldCodDoc; 
      end if;
    WHEN 27 THEN
      SELECT Nvl(Sum(CANT*PRET),0) INTO vVenitEstimat FROM Contract1 WHERE CodContract = aCodDoc;
      UPDATE Oportunitati SET CodContract = aCodDoc, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;  
      if aOldCodDoc &gt; 0 then
        update contract set anulat = 1 where codcontract = aOldCodDoc; 
      end if;
    WHEN 50 THEN
      SELECT Nvl(Sum(CANTMIN*PRET),0) INTO vVenitEstimat FROM Oferta1 WHERE CodOferta = aCodDoc;
      UPDATE Oportunitati SET CodOferta = aCodDoc, VenitEst = vVenitEstimat WHERE CodOportunitate = aCodOportunitate;
      if aOldCodDoc &gt; 0 then
        update oferta set anulat = 1 where codoferta = aOldCodDoc; 
      end if;
    WHEN 54 THEN
      UPDATE Oportunitati SET CodTask = aCodDoc WHERE CodOportunitate = aCodOportunitate;
    WHEN -54 THEN
      if TaskFirma = 1 then
				Select Executant||&apos;-&apos;||DataTask into aTask from SetTask where CodTask = aCodDoc;
			else
				Select Executant||&apos;-&apos;||DataTask into aTask from WinMAdmin.SetTask where CodTask = aCodDoc;
      end if;
			UPDATE Oportunitati1 SET CodTask = aCodDoc WHERE CodOportunitate1 = aCodOportunitate;
			UPDATE TMP_Oportunitati1 SET CodTask = aCodDoc, Task = aTask WHERE CodOportunitate1 = aCodOportunitate;
  END CASE;
  COMMIT;
END;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

end PKG_OPORTUNITATI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OPPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61DA90E5FA75DB7DFEDC7B9BB72407D27236D565</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_OPPER is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodOpper INTO Tmp FROM OPPER WHERE CodOpper = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  
  DELETE OPPER1 WHERE CodOpper = RecId;
  DELETE OPPER  WHERE CodOpper = RecId;
  NotifyModif(2, RECID, &apos;OPPER&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_OPPER FIELDS( CodOpper) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_OPPER 
  SELECT * FROM OPPER WHERE CODOPPER = RECID;

  INSERT INTO TMP_OPPER1(CODOPPER1, CODOPPER, SAPTAMANA, TIPOPER, VALOARE, TERMEN, OBS, CODELEMBUGET, ELEMENT)
  SELECT O1.CODOPPER1, O1.CODOPPER, O1.SAPTAMANA, O1.TIPOPER, O1.VALOARE, O1.TERMEN, O1.OBS, O1.CODELEMBUGET, E.ELEMENT 
  FROM OPPER1 O1
       LEFT JOIN ELEMBUGET E ON O1.CODELEMBUGET = E.CODELEMBUGET
  WHERE O1.CODOPPER = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod          NUMBER(20);
BEGIN
  IF Operation = 0 THEN
    SELECT CodOpper INTO RecId FROM TMP_OPPER;
    
    UPDATE OPPER
    SET 
    (
      CODOPPER,
      OBS     ,
      VALOARE ,
     AN ,
     SUBUNITATEA
    )

    = 
    (SELECT 
       CODOPPER     ,
       OBS       ,
       VALOARE   ,
       AN  ,
       SUBUNITATEA
    FROM 
       TMP_OPPER 
     )
    WHERE 
      CodOpper = RecId;   


    DELETE FROM OPPER1
    WHERE CodOpper = RecID AND CodOpper1 NOT IN (SELECT CodOpper1 FROM TMP_Opper1);

    FOR v_rec IN ( SELECT * FROM TMP_OPPER1 ORDER BY SAPTAMANA)
    LOOP
      IF NVL(v_rec.CODOPPER1, 0) &gt; 0 THEN
        UPDATE OPPER1 
        SET
          SAPTAMANA  = v_rec.SAPTAMANA,
          TERMEN     = v_rec.TERMEN,
          TIPOPER    = v_rec.TIPOPER,
          VALOARE    = V_REC.VALOARE,
          OBS        = V_REC.OBS,
          CODELEMBUGET = V_REC.CODELEMBUGET
        WHERE 
          CodOpper1  = v_rec.CodOpper1;
      ELSE
        INSERT INTO OPPER1 (
          CodOpper1,
          CODOPPER,
          SAPTAMANA,
          TIPOPER,
          TERMEN,
          VALOARE,
          OBS,
          CODELEMBUGET
         ) 
        VALUES  (
          SEQ_OPPER1_CODOPPER1.Nextval,
          RecId,       
          V_REC.SAPTAMANA,
          V_REC.TIPOPER,
          V_REC.TERMEN,
          V_REC.VALOARE,
          V_REC.OBS,
          V_REC.CODELEMBUGET
          );
     END IF;
    END LOOP;

  ELSE  
    SELECT SEQ_OPPER_CODOPPER.Nextval INTO RecID From DUAL;
    INSERT INTO OPPER
    (
      CODOPPER     ,
      OBS       ,
      VALOARE   ,
      AN,
      SUBUNITATEA
    )
    ( 
    SELECT 
      RecId     ,       
      OBS       ,
      VALOARE   ,
      AN,
      SUBUNITATEA
    FROM 
      TMP_OPPER
    );
    
    INSERT INTO OPPER1(CODOPPER1, CODOPPER, SAPTAMANA, TIPOPER, VALOARE, TERMEN, OBS, CODELEMBUGET)
    SELECT SEQ_OPPER1_CODOPPER1.Nextval, RECID, SAPTAMANA, TIPOPER, VALOARE, TERMEN, OBS, CODELEMBUGET
    FROM
      TMP_OPPER1;
  END IF;
  
  NotifyModif(OPERATION, RECID, &apos;OPPER&apos;);  
  
  COMMIT;
END;
  
end PKG_OPPER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_OPREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>171D262E9C01056AEEEFF5D32EE7D06347BD486C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_opreg is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodOp INTO Tmp FROM OPREG WHERE CodOp = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  
  DELETE OPREG1 WHERE CodOp = RecId;
  DELETE OPREG  WHERE CodOp = RecId;
  NotifyModif(2, RECID, &apos;OPREG&apos;);  

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_OPREG FIELDS( CodOp) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_OPREG 
    (
      CODOP     ,
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA
     )
  ( SELECT 
      CODOP     ,
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA
    FROM OPREG WHERE CodOp = RecId );

  INSERT INTO TMP_OPREG1 
    (
      CODOP1    ,
      CODOP     ,
      TERMEN    ,
      Stins     ,
      Obs       
     )
  ( SELECT 
      CODOP1    ,
      CODOP     ,
      TERMEN    ,
      Stins     ,
      Obs       
    FROM OPREG1 WHERE CodOp = RecId );
       
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod          NUMBER(20);
BEGIN
  IF Operation = 0 THEN
    SELECT CodOp INTO RecId FROM TMP_OPREG;
    UPDATE OPREG
    SET (
      CODOP     ,
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA)

     = (SELECT 
      CODOP     ,
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA
        FROM TMP_OPREG )
    WHERE CodOp = RecId;   
    -- Detail OFERTA1

    DELETE FROM OpReg1
    WHERE CodOp = RecID AND CodOp1 NOT IN (SELECT CodOp1 FROM TMP_OpReg1);

    FOR v_rec IN (
      SELECT 
      CodOp1    ,
      CODOP     ,
      TERMEN    ,
      Stins     ,
      Obs       
      FROM TMP_OpReg1
      ORDER BY TERMEN)
    LOOP
      IF NVL(v_rec.CodOp1, 0) &gt; 0 THEN
        UPDATE OpReg1 SET
          CodOp1     = v_rec.CodOp1 ,
          CODOP      = v_rec.CODOP  ,
          TERMEN     = v_rec.TERMEN ,
          Stins      = v_rec.Stins  ,
          Obs        = v_rec.Obs    
        WHERE CodOp1  = v_rec.CodOp1;
      ELSE
        SELECT Seq_OpReg1_CodOpReg1.Nextval INTO vCod from Dual;
        INSERT INTO OpReg1 (
          CodOp1    ,
          CODOP     ,
          TERMEN    ,
          Stins     ,
          Obs       )
        VALUES  (
          vCod,             
          RecId,       
          v_rec.TERMEN    , 
          v_rec.Stins     , 
          v_rec.Obs           
          );
     END IF;
    END LOOP;

  ELSE  
    SELECT SEQ_OPREG_CODOP.Nextval INTO RecID From DUAL;
    INSERT INTO OPREG 
    (
      CODOP     ,
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA
    )
    ( 
    SELECT 
      RecId     ,       
      CODPART   ,
      CODBanca  ,
      OBS       ,
      TIPTRANZ  ,
      TIPDECONT ,
      ZIDECONT  ,
      CODMONEDA ,
      VALOARE   ,
      AN_Start  ,
      LUNA_Start,
      AN_MAX    ,
      LUNA_MAX  ,
      SUBUNITATEA
    FROM TMP_OPREG
    );
    
    FOR v_rec IN (
      SELECT 
      CodOp1    ,
      CODOP     ,
      TERMEN    ,
      Stins     ,
      Obs       
      FROM TMP_OpReg1
      ORDER BY TERMEN)
    LOOP
      SELECT Seq_OpReg1_CodOpReg1.Nextval INTO vCod from Dual;
      INSERT INTO OpReg1 (
        CodOp1    ,
        CODOP     ,
        TERMEN    ,
        Stins     ,
        Obs       )
      VALUES  (
        vCod,             
        RecId,       
        v_rec.TERMEN    , 
        v_rec.Stins     , 
        v_rec.Obs           
        );
    END LOOP;
  END IF;
  
  NotifyModif(OPERATION, RECID, &apos;OPREG&apos;);  
  
  COMMIT;
END;
  
end pkg_opreg;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ORAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C40D48915181EC3EC38F3A1771C0E32603D0B46</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ORAR IS

  g_CodJob number(20);

PROCEDURE Avarie_orar IS
  TYPE r_x_orar IS RECORD( CodOrar NUMBER(20), Operatie NUMBER(1));
  TYPE t_x_orar IS TABLE OF r_x_orar INDEX BY PLS_INTEGER;
  x_orar t_x_orar;
BEGIN
  SELECT CodOrar, Operatie
  BULK COLLECT INTO x_orar
  FROM (
    SELECT O.CodOrar, CASE WHEN S.SCHEDULE_NAME IS NULL THEN 1 ELSE 0 END OPERATIE
    FROM ORAR O LEFT JOIN USER_SCHEDULER_SCHEDULES S ON S.SCHEDULE_NAME = Upper(O.DENUMIRE)
  );

  FOR indx IN 1 .. x_orar.COUNT
  LOOP
    pkg_orar.creaza_orar(x_orar(indx).CodOrar, x_orar(indx).Operatie);
  END LOOP;
END;

PROCEDURE creaza_orar(recid in number, operation in number ) is
  Denumire  varchar2(50);
  newObs    varchar2(100);
  oldObs    varchar2(100);
  newStartD date;
  oldStartD date;
  newEndD   date;
  oldEndD   date;
  newRep    varchar2(300);
  oldRep    varchar2(300);
BEGIN
  SELECT
    Upper(denumire),
    Obs,
    to_date (to_char(data_start,&apos;dd.mm.yyyy&apos;)||&apos; &apos;||ora||&apos;:&apos;||min||&apos;:00&apos;,&apos;dd.mm.yyyy hh24:mi:ss&apos;),
    CASE repetare WHEN 0 THEN NULL ELSE to_date (to_char(data_fin,&apos;dd.mm.yyyy&apos;)||&apos; 23:59:59&apos;,&apos;dd.mm.yyyy hh24:mi:ss&apos;) END data_fin,
    CASE repetare WHEN 1 THEN &apos;FREQ=DAILY&apos; WHEN 2 THEN &apos;FREQ=WEEKLY&apos; WHEN 3 THEN &apos;FREQ=MONTHLY&apos; WHEN 4 THEN &apos;FREQ=HOURLY&apos; ELSE NULL END||
    CASE WHEN interval &gt; 1 THEN &apos;;INTERVAL=&apos;||interval ELSE NULL END||
    nvl2(zile_sapt,&apos;;BYDAY=&apos;||zile_sapt,null)||
    nvl2(zile_luna,&apos;;BYMONTHDAY=&apos;||zile_luna,null)
  INTO
    Denumire,
    newObs,
    newStartD,
    newEndD,
    newRep
  FROM orar
  WHERE codorar = recid;

  IF operation &lt;&gt; 0 THEN
    dbms_scheduler.create_schedule(
      schedule_name   =&gt; Denumire ,
      start_date      =&gt; newStartD,
      repeat_interval =&gt; newRep ,
      end_date        =&gt; newEndD,
      comments        =&gt; newObs);
  END IF;

  IF operation = 0 THEN -- update
    dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;start_date&apos;, value =&gt; oldStartD);
    IF Nvl(oldStartD, pkg_globals.data0) &lt;&gt; Nvl(newStartD, pkg_globals.data0) THEN
      dbms_scheduler.set_attribute(name =&gt; Denumire, attribute =&gt; &apos;start_date&apos;, value =&gt; newStartD);
    END IF;

    dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;repeat_interval&apos;, value =&gt; oldRep);
    IF Nvl(oldRep, newRep||&apos;_&apos;) &lt;&gt; Nvl(newRep, oldRep||&apos;_&apos;) THEN
      dbms_scheduler.set_attribute(name =&gt; Denumire, attribute =&gt; &apos;repeat_interval&apos;, value =&gt; newRep);
    END IF;

    dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;end_date&apos;, value =&gt; oldEndD);
    IF Nvl(oldEndD, pkg_globals.data0) &lt;&gt; Nvl(newEndD, pkg_globals.data0) THEN
      dbms_scheduler.set_attribute(name =&gt; Denumire, attribute =&gt; &apos;end_date&apos;, value =&gt; newEndD);
    END IF;

    dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;comments&apos;, value =&gt; oldObs);
    IF Nvl(oldObs, newObs||&apos;_&apos;) &lt;&gt; Nvl(newObs, oldObs||&apos;_&apos;) THEN
      dbms_scheduler.set_attribute(name =&gt; Denumire, attribute =&gt; &apos;comments&apos;, value =&gt; newObs);
    END IF;
  END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODORAR INTO Tmp FROM ORAR WHERE CodORAR = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_ORAR FIELDS( CodORAR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  sDen varchar2(200);
BEGIN
  SP_LOCKRECORD(RECID);
  select upper(denumire) into sDen from orar where codorar = recid;
  BEGIN
    DELETE FROM ORAR WHERE CODORAR = RECID;
    dbms_scheduler.drop_schedule(schedule_name =&gt; sDen);
  EXCEPTION
    WHEN others THEN
      rollback;
      raise;
  END;

  NotifyModif(2, RECID, &apos;ORAR&apos;);
  COMMIT;
END;

FUNCTION EXPIRAT(Denumire VARCHAR2) RETURN NUMBER IS
  vEXPIRAT NUMBER := 0;
  startD   TIMESTAMP;
  endD     TIMESTAMP;
  nextD    TIMESTAMP;
  rep      VARCHAR2(500);
BEGIN
  BEGIN
		dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;start_date&apos;,      value =&gt; StartD);
		dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;end_date&apos;,        value =&gt; EndD);
		dbms_scheduler.get_attribute(  name =&gt; Denumire, attribute =&gt; &apos;repeat_interval&apos;, value =&gt; Rep);
  EXCEPTION
    WHEN others THEN
		  vEXPIRAT := 1;
  END;

  IF vEXPIRAT = 0 THEN
		IF Rep IS NULL -- daca se executa o singura data
		THEN
		  if StartD &lt; SysDate then NextD := null; else nextD := StartD; end if;
		ELSE
      BEGIN
        DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING(Rep, StartD, SysDate, nextD);
      EXCEPTION
        WHEN OTHERS THEN nextD := NULL;
      END;
		END IF;

		CASE
			WHEN nextD IS NULL THEN vEXPIRAT := 1;
			WHEN EndD &lt; nextD  THEN vEXPIRAT := 1;
			ELSE vEXPIRAT := 0;
		END CASE;
  END IF;
  RETURN vEXPIRAT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  S VARCHAR2(100);
BEGIN
  BEGIN
    SELECT ZILE_SAPT INTO S FROM ORAR WHERE CODORAR = RECID;
    S:= REPLACE(S,&apos;MON&apos;,&apos;L&apos;);
    S:= REPLACE(S,&apos;TUE&apos;,&apos;Ma&apos;);
    S:= REPLACE(S,&apos;WED&apos;,&apos;Mi&apos;);
    S:= REPLACE(S,&apos;THU&apos;,&apos;J&apos;);
    S:= REPLACE(S,&apos;FRI&apos;,&apos;V&apos;);
    S:= REPLACE(S,&apos;SAT&apos;,&apos;S&apos;);
    S:= REPLACE(S,&apos;SUN&apos;,&apos;D&apos;);
  EXCEPTION WHEN OTHERS THEN
    S := NULL;
  END;

  INSERT INTO TMP_ORAR(CODORAR,DENUMIRE,OBS,REPETARE,INTERVAL,ORA,MIN,ZILE_SAPT,ZILE_LUNA,DATA_START,DATA_FIN,EXPLICATII,EXPIRAT)
  SELECT
    O.CODORAR, O.DENUMIRE, O.OBS, O.REPETARE, O.INTERVAL, O.ORA, O.MIN, O.ZILE_SAPT, O.ZILE_LUNA, O.DATA_START, O.DATA_FIN,
    CASE O.REPETARE
      WHEN 0 THEN &apos;Fara repetare; &apos; 
      WHEN 1 THEN &apos;Repetare zilnica; &apos; 
      WHEN 2 THEN &apos;Repetare saptamanala; &apos; 
      WHEN 3 THEN &apos;Repetare lunara; &apos; 
      WHEN 4 THEN &apos;Repetare orara; &apos;
      ELSE &apos;&apos; 
    END||
    CASE
      WHEN  O.REPETARE &gt; 0 THEN 
        &apos;Odata la &apos;||
        CASE O.REPETARE
          WHEN 1 THEN &apos;zile&apos; 
          WHEN 2 THEN &apos;saptamani&apos; 
          WHEN 3 THEN &apos;luni, &apos; 
          WHEN 4 THEN &apos;ore&apos;
          ELSE &apos;&apos; 
        END ||&apos; = &apos;|| To_Char(Coalesce(NULLIF(O.INTERVAL,0), 1)) 
      ELSE &apos; &apos; 
    END||
    CASE
      WHEN length(trim(O.ZILE_SAPT)) &gt; 0 THEN &apos;In zilele &apos;||S||&apos;(ora &apos;||O.ORA||&apos;:&apos;||O.MIN||&apos;) ; &apos;
      WHEN length(trim(O.ZILE_LUNA)) &gt; 0 THEN 
        CASE 
          WHEN O.ZILE_LUNA = &apos;-1&apos; THEN &apos; &apos; 
          ELSE
            &apos;In zilele de &apos;||Replace(O.ZILE_LUNA,&apos;-1,&apos;,&apos; &apos;)||
            CASE
              WHEN instr(zile_luna,&apos;-1&apos;)&gt; 0 THEN &apos; si &apos; 
              ELSE&apos;; &apos; 
            END
        END||
        CASE
          WHEN instr(zile_luna,&apos;-1&apos;)&gt;0 then &apos;in ultima zi a lunii (ora &apos;||O.ORA||&apos;:&apos;||O.MIN||&apos;); &apos;
          ELSE&apos;; &apos;
        END
      ELSE &apos;&apos;
    END||Chr(13)||Chr(10)||
    CASE
      WHEN repetare &gt; 0 THEN &apos;Activ in perioada &apos;||O.DATA_START||&apos; - &apos;||O.DATA_FIN
      ELSE &apos;Ruleaza la &apos;||O.DATA_START||&apos; ora &apos;||ORA||&apos;:&apos;||O.MIN
    END EXPLICATII,
    PKG_ORAR.Expirat(O.DENUMIRE) EXPIRAT 
  FROM ORAR O
  WHERE O.CODORAR = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF OPERATION = 0 THEN -- UPDATE
    SELECT CODORAR INTO RECID FROM TMP_ORAR;
    UPDATE ORAR O
    SET (O.DENUMIRE,O.OBS,O.REPETARE,O.INTERVAL,O.ORA,O.MIN,O.ZILE_SAPT,O.ZILE_LUNA,O.DATA_START,O.DATA_FIN) =
        (SELECT DENUMIRE,OBS,REPETARE,INTERVAL,ORA,MIN,ZILE_SAPT,ZILE_LUNA,Trunc(DATA_START),Trunc(DATA_FIN) FROM TMP_ORAR)
    WHERE O.CODORAR = RECID;
  ELSE -- INSERT
    SELECT SEQ_ORAR_CODORAR.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO ORAR(CODORAR,DENUMIRE,OBS,REPETARE,INTERVAL,ORA,MIN,ZILE_SAPT,ZILE_LUNA,DATA_START,DATA_FIN,USERID,DATACREARE)
    SELECT RECID,DENUMIRE,OBS,REPETARE,INTERVAL,ORA,MIN,ZILE_SAPT,ZILE_LUNA,Trunc(DATA_START),Trunc(DATA_FIN),PKG_GLOBALS.USERID,SYSDATE
    FROM TMP_ORAR ;
  END IF;
  CREAZA_ORAR(RecId,Operation);

  NotifyModif(OPERATION, RECID, &apos;ORAR&apos;);

  COMMIT;
END;

procedure SaveGlobalEnviroment is
BEGIN
  NULL;
  /*insert into variabile_sesiune(codjob,sql_exec) values
  (g_Codjob,&apos;PKG_GLOBALS.SETLUNALUCRU(&apos;||pkg_globals.GetANLUCRU||&apos;,&apos;||pkg_globals.GetLUNALUCRU||&apos;)&apos;);
  insert into variabile_sesiune(codjob,sql_exec) values
  (g_Codjob,&apos;PKG_GLOBALS.SETSUBUNITATE(&apos;||pkg_globals.GETSUBUNITATE||&apos;)&apos;);
  commit;*/
END;

procedure SaveListaEnviroment(aSql in varchar2) is
  x number(20);
BEGIN
  /*select count(*) into x from user_scheduler_schedules;
  insert into variabile_sesiune(codjob,sql_exec) values(g_CodJob,aSQL);
  commit;*/
  NULL;
END;

procedure SetCodJob(aCodJob in number) is
BEGIN
  g_CodJob := aCodJob;
END;

PROCEDURE initEnviroment (aCodJob in number) is
BEGIN
  /*for v_rec in (select s.* from variabile_sesiune s where s.codjob = aCodJob) loop
    execute immediate v_rec.sql_exec;
  end loop;
  commit; */
  NULL;
END;

PROCEDURE unJob is
BEGIN
  dbms_scheduler.create_job(
    job_name   =&gt; &apos;TEST_VARIABILE&apos; ,
    job_type   =&gt; &apos;plsql_block&apos; ,
    job_action =&gt; &apos; begin
                      pkg_orar.setParams;
                      insert into t_orar(variabila,valoare) values(&apos;&apos;ANLUCRU&apos;&apos;,&apos;||pkg_globals.GetANLUCRU||&apos;);
                      insert into t_orar(variabila,valoare) values(&apos;&apos;SUBUNITATEA&apos;&apos;,&apos;||pkg_globals.GETSUBUNITATE||&apos;);
                      insert into t_orar(variabila,valoare)
                      select filtru,valoare from tmp_manevra_liste;
                      insert into t_orar(variabila,valoare) select &apos;&apos;NR&apos;&apos;, count(*) from tmp_manevra_liste;
                      commit;
                    end;&apos;,
    start_date =&gt; (sysdate + (1/(24*60))),
    comments   =&gt; &apos;job test&apos;,
    auto_drop  =&gt; true
  );
  dbms_scheduler.enable(&apos;TEST_VARIABILE&apos;);
END;

procedure setParams is
begin
 pkg_globals.SetLunaLucru(An =&gt; 2008,Luna =&gt; 1);
 pkg_globals.SETSUBUNITATE(100);
 insert into tmp_manevra_liste(filtru,valoare) values (&apos;test orar&apos;,&apos;999&apos;);
 commit;
end;

end pkg_orar;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ORA_LISTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55C30B99184924AA025125958D0E7459B74E6369</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ORA_LISTS IS


FUNCTION DO_JOBLISTA_WEBSERVICE(askemafirma varchar, aCodJob1 number) RETURN NUMBER
is
  aUserID number(20) := 0;
  aLunaLucru number(2);
  aAnLucru   number(5);
  IPWebServiceSMS   varchar2(100);
  PortWebServiceSMS varchar2(10);
  aDBName   varchar2(20);
  JobInfo   varchar2(3000);
  MSG_EROARE varchar2(1000);
  URL varchar2(1000);
  aREq utl_http.req;
  RESP utl_http.resp;
  value VARCHAR2(32767);
  Res        NUMBER(1) := 0;
  aPos       Number(10);
  StartPos   Number(10);
  EndPos     Number(10);

begin
  begin
   select coalesce(j.userid, 0)
   into
      aUserid
   from
     JobLISTE J,
     JobLISTE1 j1
   where
      CodJob1 = acodJob1
      and J.codJob = J1.CodJob;
    exception when others then
     aUserID := 0;
  end;


  if Coalesce(aUserID, 0) &lt;&gt; 0 then

    select anmaxim, lunamaxima into aAnlucru, aLunalucru from  firmaluni;
    pkg_globals.SETUSERID(aUserID);COMMIT;
    pkg_globals.SETFIRMANAME(askemafirma); COMMIT;
    pkg_globals.SETLUNALUCRU_SIMPLa(aAnlucru, aLunalucru);


    IPWebServiceSMS   := PKG_CATEGCONST.GetValConstanta(&apos;IPWebServiceSMS&apos;, aAnLucru, aLunaLucru);

    PortWebServiceSMS := PKG_CATEGCONST.GetValConstanta(&apos;PortWebServiceSMS&apos;, aAnLucru, aLunaLucru);

    select global_name into aDBName from global_name ;

    JobInfo := &apos;{&quot;JobInfo&quot;:{
                                       &quot;DataBaseType&quot;:&quot;ORA&quot;,
                                       &quot;DBName&quot;:&quot;&apos;         || aDBName        ||&apos;&quot;,
                                       &quot;CodJob1&quot;:&quot;&apos;        || aCodJob1       ||&apos;&quot;,
                                       &quot;Skema&quot;:&quot;&apos;          || askemafirma    ||&apos;&quot;
                                     }}&apos;;

    MSG_EROARE := &apos;&apos;;
    URL        := &apos;http://&apos; || IPWebServiceSMS  || &apos;:&apos; || PortWebServiceSMS || &apos;/root/wmeserver/solveJobLista&apos;;


    UTL_HTTP.set_transfer_timeout(3600);
    areq       := UTL_HTTP.BEGIN_REQUEST ( LOWER(URL),&apos;POST&apos; );

    utl_http.set_header(areq, &apos;Content-Length&apos;, length(JobInfo));

    UTL_HTTP.WRITE_TEXT (areq, JobInfo);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE);
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

  RETURN RES;


  end if;

end;

PROCEDURE DropJobListeFin(aCod IN NUMBER)
IS
 aSkema varchar2(100);
 aTabla varchar2(100);
 aCodJob1 number(20);
BEGIN
  BEGIN
    SELECT CodJob1, SKEMAFIRMA, Tabla into aCodJob1, aSkema, aTabla FROM JOBLISTEFIN WHERE codjoblistefin = aCod;
  EXCEPTION WHEN OTHERS THEN
    aSkema := &apos;?&apos;;
    aTabla := &apos;?&apos;;
		aCodJob1 := 0;
  END;
  IF aTabla &lt;&gt; &apos;?&apos; AND aSkema &lt;&gt; &apos;?&apos; THEN
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||aSkema||&apos;.&apos;||atabla||&apos; PURGE&apos;;
    EXCEPTION WHEN OTHERS THEN
      aSkema := &apos;?&apos;;
    END;
  END IF;
  DELETE FROM JOBLISTEFIN WHERE CODJOBLISTEFIN = aCod;
END;

PROCEDURE DropCompleteJobListeFin(aCod in number)
IS
 aCodJob1 number(20);
BEGIN
	BEGIN
		SELECT CodJob1 INTO aCodJob1 FROM JOBLISTEFIN WHERE codjoblistefin = aCod;
	EXCEPTION WHEN OTHERS THEN
		aCodJob1 := 0;
	END;
	IF aCodJob1 &gt; 0 THEN
    PKG_ORA_LISTS.DropJobListeFin(aCod);
--ce dracu mai trebuie si asta!!!!!!		PKG_ORA_LISTS.CREATE_VIEW_4_LAST_JOB(aCodJob1);
		COMMIT;
	END IF;
END;

PROCEDURE KeepLastResult
IS
  aMaxCod number(20);
BEGIN
  UPDATE joblistefin SET TABLE_TYPE = 1;
  FOR v_rec IN (SELECT DISTINCT codjob1 FROM JOBLISTEFIN) LOOP
    SELECT max(codjoblistefin) INTO aMaxCod FROM joblistefin WHERE codjob1 = v_rec.codjob1;
    UPDATE joblistefin SET TABLE_TYPE = 0 WHERE codjoblistefin = aMaxCod;
  END LOOP;
  FOR v_del IN (SELECT codjoblistefin FROM joblistefin WHERE TABLE_TYPE = 1) LOOP
    DropJobListeFin(v_del.codjoblistefin);
  END LOOP;
	COMMIT;
END;

PROCEDURE DelJobListeFin_TablaInexist
IS
BEGIN
  FOR v_rec IN (SELECT codjoblistefin, Tabla FROM JOBLISTEFIN) LOOP
    BEGIN
      EXECUTE IMMEDIATE &apos;SELECT Count(*) FROM &apos;||v_rec.tabla;
    EXCEPTION WHEN OTHERS THEN
      DELETE JOBLISTEFIN WHERE codjoblistefin = v_rec.codjoblistefin;
		END;
	END LOOP;
	COMMIT;
END;

PROCEDURE testjob IS
  TMP_NAME VARCHAR2(50);
  USERN NUMBER(20);
BEGIN
/*
  SELECT &apos;J_&apos;||&apos;5_0&apos;||&apos;_&apos;||seq_JobUnic.Nextval INTO TMP_NAME FROM DUAL;
  PKG_ORA_LISTS.SET_VARIABILE_SESIUNE(780);
  PKG_ORA_LISTS.CREAZA_TABLA(TMP_NAME,5,0);
  PKG_LIST_BASE_SCADENTARCL.PROCESSLIST(TMP_NAME,5,0);
  INSERT INTO JOBLISTEFIN (CODJOBLISTEFIN,CODJOB1,TABLA,SUBUNITATEA,SKEMAFIRMA,LISTANAME,DATAGEN,TABLE_TYPE,TIPDEPO,LISTID,LISTVER, DATAINI, DATAFIN)
  VALUES (SEQ_JOBLISTEFIN_CODJOBLISTEFIN.NEXTVAL,780,TMP_NAME,PKG_GLOBALS.GETSUBUNITATE,&apos;Cornel&apos;,&apos;Scadentar clienti&apos;,SYSDATE,0,0,5,0,PKG_ORA_LISTS.GET_JOB_DATAINI,PKG_ORA_LISTS.GET_JOB_DATAFIN);
  INSERT INTO WINMADMIN.MESAJE(CODMESAJ,TEXT,FROM_USER,SKEMAFIRMA,DATA,TIP_MESAJ)
  VALUES (WINMADMIN.SEQ_MESAJE_CODMESAJ.NEXTVAL,&apos;Job complet Scadentar clienti la data &apos;||SYSDATE, &apos;JOB LISTE&apos;,&apos;Cornel&apos;,SYSDATE,0);
  SELECT USERID INTO USERN FROM JOBLISTE WHERE CODJOB = (SELECT DISTINCT CODJOB FROM JOBLISTE1 WHERE CODJOB1 =780);
  INSERT INTO WINMADMIN.MESAJE1(CODMESAJ1,CODMESAJ,TO_USER,STERS)
  VALUES (WINMADMIN.SEQ_MESAJE1_CODMESAJ1.NEXTVAL,WINMADMIN.SEQ_MESAJE_CODMESAJ.CURRVAL, WINMADMIN.PKG_USERFIRME.GETUSERNAME(USERN),0);
  PKG_ORA_LISTS.CREATE_VIEW_4_LAST_JOB (780);
*/
  COMMIT;
END;

FUNCTION GetNumeView(ViewName VARCHAR2, DataIni DATE, DataFin DATE, Subunit INTEGER) RETURN VARCHAR2 IS
  RESULT   VARCHAR2(1000);
  SS       VARCHAR2(1000);
  S        VARCHAR2(1000);
  vValori  VARCHAR2(255);
  vElement VARCHAR2( 10);
  vLungime NUMBER(2);
  vFill    VARCHAR2(  1);
  b        INTEGER;
  bb       INTEGER;
  Pos      INTEGER;

  PROCEDURE EXTRACT_ELEMENT(pSS IN VARCHAR2, pValori OUT VARCHAR2, pElement OUT VARCHAR2, pLungime OUT NUMBER, pFill OUT VARCHAR2) IS
    x    INTEGER;
    vSS  VARCHAR2(500) := pSS;
    Buf  VARCHAR2(300);
    Buf1 VARCHAR2(300);
  BEGIN
    pValori  := &apos;&apos;;
    pElement := &apos;&apos;;
    pLungime := 0;
    pFill    := &apos;0&apos;;
    X := Instr(vSS,&apos;[&apos;);
    IF X &gt; 0 then
      Buf := SubStr(vSS, X + 1, 255);
      vSS  := SubStr(vSS, 1, X -1) || SubStr(vSS, X+255);
      bb  := INSTR(Buf, &apos;]&apos;);
      IF bb &gt; 0 THEN
        IF bb &gt; 101 THEN bb := 101; END IF;
        Buf := SUBSTR(Buf, 1, bb-1);
        bb  := Instr(Buf, &apos;=&apos;);
        IF bb &gt; 0
        THEN pValori := Substr(Buf, bb+1, 255);
        END IF;
      END IF;
    END IF;

    X := Instr(vSS,&apos;(&apos;);
    IF X &gt; 0 THEN
      Buf := SubStr(vSS, X + 1, 255);
      vSS  := SubStr(vSS, 1, X-1) || SubStr(vSS, X+255);
      bb  := Instr(Buf, &apos;)&apos;);
      IF bb &gt; 0 THEN
        bb  := Least(bb,101);
        Buf := SubStr(Buf, 1, bb-1);
        bb  := Instr(Buf, &apos;,&apos;);
        IF bb &gt; 0 THEN
          pFill := SubStr(Buf, bb+1, 1);
          Buf   := SubStr(Buf, 1, bb-1) || SubStr(Buf, bb+255);
        END IF;
        BEGIN
          pLungime := To_Number(Buf);
        EXCEPTION
          WHEN OTHERS THEN pLungime := 0;
        END;
      END IF;
    END IF;
    pElement := vSS;
  END;

  FUNCTION TRANSLATE_ELEMENT(pValori VARCHAR2, pElement VARCHAR2, pLungime NUMBER, pFill VARCHAR2) RETURN VARCHAR2 IS
    Res VARCHAR2(500);
  BEGIN
    IF pElement IS NOT NULL THEN
      IF    pElement =  &apos;P&apos; THEN Res := pValori;
      ELSIF pElement =  &apos;S&apos; THEN Res := To_Char(Subunit);
      ELSIF pElement = &apos;AA&apos; THEN Res := To_Char(DataIni,&apos;yyyy&apos;);
      ELSIF pElement = &apos;L1&apos; THEN Res := To_Char(DataIni,&apos;mm&apos;);
      ELSIF pElement = &apos;Z1&apos; THEN Res := To_Char(DataIni,&apos;dd&apos;);
      ELSIF pElement = &apos;L2&apos; THEN Res := To_Char(DataFin,&apos;mm&apos;);
      ELSIF pElement = &apos;Z2&apos; THEN Res := To_Char(DataFin,&apos;dd&apos;);
      END IF;
      Res := LPad(Res,pLungime,pFill);
    END IF;
    RETURN Res;
  END;

BEGIN
  s    := ViewName;
  IF Instr( S,&apos;P(&apos;) = 0
  THEN RETURN s;
  END IF;
  LOOP
    Pos := Instr(S,&apos;+&apos;);
    IF Pos &gt; 0
    THEN ss := Substr(s, 1, Pos-1); s := SubStr(s, Pos+1);
    ELSE ss := s;
    END IF;
    EXTRACT_ELEMENT (SS, vValori, vElement, vLungime, vFill);
    Result := Result||TRANSLATE_ELEMENT(vValori, vElement, vLungime, vFill);
    EXIT WHEN pos = 0;
  END LOOP;
  RETURN RESULT;
END;


PROCEDURE CREATE_VIEW_4_LAST_JOB (aCodJob1 in number) is
  MascaviewName varchar2(300);
  viewName varchar2(50);
  tblName varchar2(50);
  nr number;
  aDataINI Date;
  aDataFIN Date;
  aDataGen Date;
  aSubunitate number(20);
	isExp number(1);
	NumeExp varchar2(100);
	SkemaF varchar2(100);
BEGIN
-- select codjob1 into aCodJob1 from joblistefin  where codjoblistefin = aCodJobListefin;
  BEGIN
    select tabla, Nvl(Export,0), Nvl(FISIER_EXPORT, &apos;?&apos;) into MascaViewName, isExp, NumeExp from jobliste1 where codjob1 = aCodjob1;
  EXCEPTION
    WHEN OTHERS THEN MascaViewName := &apos;?&apos;;
  END;
  SELECT Count(*) into nr from joblistefin where codjob1 = acodjob1;
  if Nr &gt; 0 then
	  select tabla, DataIni, DataFin, DataGen, SUBUNITATEA, SKEMAFIRMA
		into   tblName, aDataINI, aDataFIN, aDataGen, aSubunitate, SkemaF
	  from joblistefin
	  where codjoblistefin=(select max(codjoblistefin) from joblistefin jf where jf.codjob1 = acodjob1);
	  if Nvl(TblName,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
      if IsExp = 1 and NumeExp &lt;&gt; &apos;?&apos; then
		 	  BEGIN
          --CREATE DIRECTORY WMETOXLS AS &apos;OCale&apos;;
          --GRANT READ, WRITE ON DIRECTORY WMETOXLS TO XXXX;
				  ORA_EXCEL.new_document;
          ORA_EXCEL.set_1900_date_system;
				  ORA_EXCEL.add_sheet(&apos;WME&apos;);
				  ORA_EXCEL.query_to_sheet(&apos;Select * from &apos; ||TblName);
				  ORA_EXCEL.save_to_file(&apos;WMETOXLS_&apos;||Upper(SkemaF), NumeExp);
			  EXCEPTION
          WHEN OTHERS THEN IsExp := 0;
			  END;
		  END IF;
		  IF Nvl(MascaViewName,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
			  if aDataIni is null then aDataIni := aDataGen; end if;
			  if aDataFin is null then aDataFin := aDataGen; end if;
			  if aDataIni &gt; aDataFin then aDataIni := aDataFin; end if;
			  ViewName := PKG_ORA_LISTS.GetNumeView(MascaViewName, aDataIni, aDataFin, aSubunitate);
			  execute immediate &apos;create or replace view &apos;||viewName||&apos; as select * from &apos;||tblName;
		  end if;
	  end if;
  else
	  if Nvl(ViewName,&apos;?&apos;) &lt;&gt; &apos;?&apos;  then
	    BEGIN
			  execute immediate &apos;drop view &apos;||viewName;
		  EXCEPTION
        WHEN OTHERS THEN ViewName := &apos;?&apos;;
      END;
    end if;
  end if;
end;

PROCEDURE ExportOraToXLSX(aSQL in varchar2, NumeExp in varchar2) is
begin
  ORA_EXCEL.new_document;
  ORA_EXCEL.add_sheet(&apos;WME&apos;);
  ORA_EXCEL.query_to_sheet(aSQL);
  ORA_EXCEL.save_to_file(&apos;WMETOXLS_&apos;||WINMADMIN.PKG_USERFIRME.GetSkemaFirma(pkg_globals.GetCodFirma), NumeExp);
end;

function TestStoredProcName(aCodJob1 IN NUMBER, aID IN NUMBER, aStoredProc in varchar2) return number is
  nume varchar2(100);
  aCodOrar number;
  aActiv number;
begin
  begin
    select StoredProcName into nume from winmadmin.lists where listid = aID and listver = 0;
  EXCEPTION
    when others then Nume := &apos;?&apos;;
  end;

  if nvl(nume, &apos;?&apos;) = &apos;?&apos;
  then nume := aStoredProc;
  else Return 1;
  end if;

  if nvl(nume, &apos;?&apos;) = &apos;?&apos;
  then Return 0;
  end if;

  update winmadmin.lists set StoredProcName = nume where listid = aID and listver = 0;
  SELECT O.CODORAR ,j1.activ into aCodOrar, aActiv
  FROM JOBLISTE1 J1
    INNER JOIN JOBLISTE J ON J1.CODJOB = J.CODJOB
    INNER JOIN ORAR O  ON O.CODORAR = J.CODORAR
  WHERE j1.CODJOB1 = ACODJOB1;

  if Nvl(aCODORAR,0) &gt; 0 then
    SET_JOB(aCODORAR, aCODJOB1,(aActiv = 1) );
  end if;
  Return 1;
end;

PROCEDURE SET_INTERVAL_DINAMIC(aCodJob1 IN NUMBER, aDataIni IN OUT VARCHAR2, aDataFin OUT VARCHAR2, aLunaAnIni IN OUT integer, aLunaAnFin OUT integer) IS
  dDataIni DATE;
  dDataFin DATE;
BEGIN
  dDataIni := To_Date(aDataIni,&apos;dd.mm.yyyy&apos;);
  dDataFin := To_Date(aDataFin,&apos;dd.mm.yyyy&apos;);

  SET_INTERVAL_DINAMIC (aCodJob1, dDataIni, dDataFin, aLunaAnIni, aLunaAnFin);

  aDataIni := To_Char(dDataIni,&apos;dd.mm.yyyy&apos;);
  aDataFin := To_Char(dDataFin,&apos;dd.mm.yyyy&apos;);
END;

PROCEDURE SET_INTERVAL_DINAMIC(aCodJob1 IN NUMBER, aDataIni IN OUT DATE, aDataFin OUT DATE, aLunaAnIni IN OUT integer, aLunaAnFin OUT integer) IS
  aANSTART    NUMBER;
  aLUNASTART  NUMBER;
  aZISTART    NUMBER;
  aANEND      NUMBER;
  aLUNAEND    NUMBER;
  aZIEND      NUMBER;

  AMAx        NUMBER;
  LMax        NUMBER;
  DMax        DATE;
  AFin        NUMBER;
  LFin        NUMBER;
  DFin        DATE;
  TipI        integer := -1;
BEGIN
  --  TIPINTERVAL --&gt; 0==(Zi max...zi max)
  --              --&gt; 1==(an max, luna max...an max, luna max)
                  --&gt; 2==(an ini, luna ini...an max, luna max)
                  --&gt; 3==(an max, ianuarie...an max, luna max)
                  --&gt; 4==(an, luna, zi din tabela TMP_INTERVAL_LISTARE) -- pentru liste WEB
                  --&gt; 5==(Zi max - 1...zi max - 1)
  --              --&gt; 6==(an max, luna max  - 1...an max, luna max - 1)
	BEGIN
    SELECT Coalesce(ANSTART,0), Coalesce(LUNASTART,0), Coalesce(ZISTART,0), Coalesce(ANEND,0), Coalesce(LUNAEND,0), Coalesce(ZIEND,0)
    INTO   aANSTART, aLUNASTART, aZISTART, aANEND, aLUNAEND, aZIEND
		FROM   TMP_INTERVAL_LISTARE
    WHERE CODJOB1 = aCODJOB1;
	EXCEPTION WHEN OTHERS THEN
		aANSTART := 0; aLUNASTART := 0; aZISTART := 0; aANEND := 0; aLUNAEND := 0; aZIEND := 0;
	END;

  IF aANSTART &lt;&gt; 0 THEN
		TipI := 4;
  ELSE
    SELECT Coalesce(TIPINTERVAL,1) INTO TipI FROM JOBLISTE1 WHERE CODJOB1 = aCodJob1;
  END IF;
  IF TipI &gt; -1 THEN
		SELECT LUNAMAXIMA, ANMAXIM, Last_Day(To_Date(LUNAMAXIMA||&apos;.&apos;||ANMAXIM,&apos;mm.yyyy&apos;)) INTO LMax, AMax, DMax FROM FIRMALUNI;
		--intotdeauna se listeaza pana la ultima luna cu date
		if DMAx &gt; SysDate then DMAx := SysDate; END IF;
		aDataFin   := DMax;
		aLunaAnFin := AMax * 12 + LMax;
		--la tip interval 2 data de pornire e fixa, inceput de an sau luna initiala firma, dupa cum e setata in param listei
		IF TipI = 0 THEN
			aDataIni   := Trunc(SysDate-1);
			aDataFin   := aDataIni;
		ELSIF TipI = 1 THEN
			aDataIni   := Trunc(DMax,&apos;mm&apos;);
			aLunaAnIni := AMax * 12 + LMax;
		ELSIF TipI = 3 THEN
			aDataIni   := Trunc(DMax,&apos;yyyy&apos;);
			aLunaAnIni := AMax * 12 + 1;
		ELSIF TipI = 4 THEN -- caz special pentru liste web
			IF aANEND=0 AND aLUNAEND=0 THEN --are numai start
				aANEND   := aAnStart;
				IF aLUNASTART = 0 THEN -- listeaza AnStart intreg
					aLunaStart := 1;
					aLunaEnd   := 12;
				ELSE
					aLunaEnd := aLunaStart;
				END IF;
			END IF;
			IF aANEND*12 + aLUNAEND &gt; AMAx*12+LMAX THEN
				aANEND := AMax;
				aLUNAEND := LMAX;
			END IF;
			IF aZIEND = 0 THEN
				aDataFin   := Last_Day(To_Date(aLUNAEND||&apos;.&apos;||aANEND,&apos;mm.yyyy&apos;));
			ELSE
				aDataFin   := To_Date(aZIEND||&apos;.&apos;||aLUNAEND||&apos;.&apos;||aANEND,&apos;dd.mm.yyyy&apos;);
			END IF;
			aLunaAnFin := aANEND*12 + aLUNAEND;

			IF aZISTART = 0 then aZISTART := 1;END IF;
			aDataIni   := To_Date(aZISTART||&apos;.&apos;||aLUNASTART||&apos;.&apos;||aANSTART,&apos;dd.mm.yyyy&apos;);
			aLunaAnIni := aANSTART*12 + aLUNASTART;
		ELSIF TipI = 5 THEN
			aDataIni   := Trunc(SysDate);
			aDataFin   := aDataIni;
		ELSIF TipI = 6 THEN
			SELECT LUNAMAXIMA, ANMAXIM, Last_Day(To_Date(LUNAMAXIMA||&apos;.&apos;||ANMAXIM,&apos;mm.yyyy&apos;)) INTO LMax, AMax, DMax FROM FIRMALUNI;
      LFin := LMax;
      AFin := AMax;
      DFin := DMax;
			LMax := LMax - 1;
			If LMax = 0 then
			  LMax := 12;
				AMax := AMax - 1;
			end if;
			DMax := Last_Day(To_Date(LMAX||&apos;.&apos;||AMAX,&apos;mm.yyyy&apos;));
			if DMAx &gt; SysDate then DMAx := SysDate; END IF;
			aDataIni   := Trunc(DMax,&apos;mm&apos;);
			aDataFin   := DFin;
			aLunaAnIni := (AMax * 12 + LMax);
			aLunaAnFin := (AFin * 12 + LFin);
		END IF;
	END IF;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(aDataIni, aDataFin);
END;

PROCEDURE SET_DATA_DINAMIC(aCodJob1 IN NUMBER, aData IN OUT DATE) IS
  DMax        DATE;
BEGIN
	BEGIN -- verificare tabela TMP_INTERVAL_LISTARE -- pentru liste WEB
    SELECT To_Date(To_Char(Coalesce(ANSTART,0),&apos;fm0000&apos;)||To_Char(Coalesce(LUNASTART,0),&apos;fm00&apos;)||To_Char(Coalesce(ZISTART,0),&apos;fm00&apos;),&apos;yyyymmdd&apos;) INTO aData
		FROM   TMP_INTERVAL_LISTARE
    WHERE  CODJOB1 = aCODJOB1 AND Coalesce(ANSTART,0) &lt;&gt; 0;
	EXCEPTION WHEN OTHERS THEN
    aData := SYSDATE;
	END;

  SELECT Last_Day(To_Date(To_Char(ANMAXIM,&apos;fm0000&apos;)||To_Char(LUNAMAXIMA,&apos;fm00&apos;),&apos;yyyymm&apos;)) INTO DMax FROM FIRMALUNI;
  IF (DMax &gt; aData) THEN
    IF (12*EXTRACT(YEAR FROM DMax) + EXTRACT(MONTH FROM DMax)) &lt; (12*EXTRACT(YEAR FROM aData) + EXTRACT(MONTH FROM aData)) 
		THEN aData := DMAx; 
    END IF;
  END IF;
  PKG_ORA_LISTS.SET_INTERVAL_LISTARE(aData, aData);
END;

PROCEDURE SET_INTERVAL_LISTARE(aDataIni IN DATE, aDataFin IN DATE) IS
BEGIN
  JOB_DATAIni := aDATAIni;
  JOB_DATAFin := aDATAFin;
END;

FUNCTION GET_JOB_DATAINI RETURN DATE IS
begin
  RETURN JOB_DATAIni;
end;

FUNCTION GET_JOB_DATAFIN RETURN DATE IS
begin
  RETURN JOB_DATAFIN;
end;

FUNCTION SET_LAST_MONTH RETURN NUMBER IS
    iRes number(2);
BEGIN
   select (case
           when (anmaxim *12 +lunamaxima) &lt; (extract(year from sysdate) * 12 + extract(month from sysdate)) then
                   lunamaxima
           else  extract(month from sysdate)
          end ) into ires
   from firmaluni ;
   return iRes;
END;

FUNCTION SET_LAST_YEAR RETURN NUMBER IS
  iRes number(4);
BEGIN
 select (case
           when (anmaxim *12 +lunamaxima) &lt; (extract(year from sysdate) * 12 + extract(month from sysdate)) then
                   anmaxim
           else  extract(year from sysdate)
          end ) into ires
   from firmaluni ;
   return iRes;
END;

FUNCTION GET_VALUES_FROM_TMP(aSubunit  number, aCodJob1  number, DATAFIXATA IN NUMBER DEFAULT 0) RETURN NUMBER IS
  S       VARCHAR2(4000);
  IRES    NUMBER(1);
  ANINI   NUMBER(4);
  LUNAINI NUMBER(2);
  ANMAX   NUMBER (4);
  LUNAMAX NUMBER(2);
	IsWeb   NUMBER(1);
	aCodJob Number(20);
BEGIN
  BEGIN
		SELECT CodJob INTO aCodJob FROM JOBLISTE1 WHERE CODJOB1 = ACODJOB1;
		SELECT WebServer into IsWeb from JobListe where CodJob = aCodJob;

		INSERT INTO VARIABILE_SESIUNE(CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
		SELECT aCodJob1,&apos;INSERT INTO TMP_MANEVRA_LISTE(FILTRU,VALOARE,FILTRU1,VALOARE1,FILTRU2,VALOARE2) VALUES (&apos;&apos;&apos;||FILTRU||&apos;&apos;&apos;,&apos;&apos;&apos;||VALOARE||&apos;&apos;&apos;,&apos;&apos;&apos;||FILTRU1||&apos;&apos;&apos;,&apos;&apos;&apos;||VALOARE1||&apos;&apos;&apos;,&apos;&apos;&apos;||FILTRU2||&apos;&apos;&apos;,&apos;&apos;&apos;||VALOARE2||&apos;&apos;&apos;)&apos;,1,0 FROM TMP_MANEVRA_LISTE;

		INSERT INTO VARIABILE_SESIUNE(CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
		SELECT aCodJob1,&apos;INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (&apos;||CODUNIC||&apos;)&apos;,1,0 FROM TMP_MANEVRA;

		if IsWeb = 0 then
      SELECT ANINITIAL,LUNAINITIALA,ANMAXIM,LUNAMAXIMA INTO ANINI, LUNAINI,ANMAX,LUNAMAX FROM FIRMALUNI;

			INSERT INTO VARIABILE_SESIUNE(CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
			SELECT ACODJOB1,&apos;PKG_GLOBALS.SETLUNALUCRU(pkg_ora_lists.set_last_year,pkg_ora_lists.set_last_month)&apos;,0,-1 from dual;

			INSERT INTO VARIABILE_SESIUNE(CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
			SELECT ACODJOB1,&apos;PKG_GLOBALS.SETSUBUNITATE(&apos;||aSubunit||&apos;)&apos;,0,-2 from dual;

			INSERT INTO VARIABILE_SESIUNE(CODJOB1,SQL_EXEC,TIP_SQL,ORDINE)
			SELECT ACODJOB1,&apos;PKG_SETLUNI.SetLunaInitiala(&apos;||ANINI||&apos;,&apos;||LUNAINI||&apos;)&apos;,0,-3 from dual;
    end if;
    IRES := 1;
  EXCEPTION  WHEN OTHERS THEN
    IRES := 0;
    ROLLBACK;
    RAISE;
  END;
  COMMIT;
  RETURN IRES;
END;

PROCEDURE SET_VARIABILE_SESIUNE (ACODJOB1 IN NUMBER) IS
  s  varchar2(500);
BEGIN
  PKG_Globals.SetUserId(0); Commit;
	JOB_CodJob1 := aCodJob1;
  DELETE FROM TMP_DINAMIC_COLS;
  DELETE FROM TMP_MACHETE;
  INSERT INTO TMP_MACHETE SELECT * FROM MACHETE;
  FOR V_REC IN (SELECT * FROM VARIABILE_SESIUNE WHERE CODJOB1 = ACODJOB1 ORDER BY ORDINE) LOOP
    IF V_REC.TIP_SQL = 1 then
      LIST_EXECUTE_IMMEDIATE (V_REC.SQL_EXEC, 0, ACODJOB1);
    END IF;
    IF V_REC.TIP_SQL = 0 THEN
      s := &apos;BEGIN &apos;||V_REC.SQL_EXEC||&apos;;  END;&apos;;
      LIST_EXECUTE_IMMEDIATE (s, 0, ACODJOB1);
			COMMIT;
    END IF;
  END LOOP;
  FOR V_REC IN (SELECT DISTINCT LISTAID FROM JOBLISTE1 WHERE CODJOB1 = ACODJOB1) LOOP
    LIST_BAGA_DINAMIC_COLS(v_rec.LISTAID);
  END LOOP;
  COMMIT;
END;

PROCEDURE CREAZA_TABLA(NUMETMP IN OUT VARCHAR2, ALISTID IN NUMBER, ALISTVER IN NUMBER, aCodJob1 IN NUMBER DEFAULT NULL) IS
  TYPE t_rec IS RECORD(CodJobListeFin NUMBER(20), sqlDrop VARCHAR2(500));
  TYPE t_tab IS TABLE OF t_rec;

  t_drop      t_tab;

  sCOL         VARCHAR2(10000);
  IS_COLOR     NUMBER(1);
  aDINAMICName VARCHAR2(10000);
  sInsert      VARCHAR2(4000);
  vNewDepo     NUMBER(1);
  vNumeTmp     VARCHAR2(200);
BEGIN
  --PENTRU POSTERITATE : PREIAU COLOANELE CU NVL(USERCOLUMN,0) = 0 DE PE V=0 SI SUPLIMENTARE DE PE VERSIUNEA CORECTA

  IF aCodJob1 IS NOT NULL THEN
    vNumeTmp := NULL;

    SELECT Nvl(J.NewDepo,0) INTO vNewDepo FROM JobListe1 J1 INNER JOIN JobListe J ON J.CodJob = J1.CodJob WHERE J1.CodJob1 = aCodJob1;

    IF vNewDepo = 0 THEN -- Se pastreaza aceeasi tabela pentru joburi
      SELECT Max(Tabla) KEEP (Dense_Rank Last ORDER BY CodJobListeFin) INTO vNumeTmp FROM JobListeFin WHERE CodJob1 = aCodJob1;

      SELECT CodJobListeFin, &apos;DROP TABLE &apos;||SkemaFirma||&apos;.&apos;||Tabla||&apos; PURGE&apos; BULK COLLECT INTO t_drop FROM JobListeFin WHERE CodJob1 = aCodJob1;
      FOR i IN 1..t_drop.COUNT
      LOOP
        BEGIN
          EXECUTE IMMEDIATE t_drop(i).sqlDrop;
          DELETE  JobListeFin WHERE CodJobListeFin = t_drop(i).CodJobListeFin;
        EXCEPTION
          WHEN OTHERS THEN NULL;-- PRESUPUN CA TABLA NU EXISTA (AR MAI FI CAZUL CAND E IN UZ)
        END;
      END LOOP;
    END IF;

    NumeTmp := Nvl(vNumeTmp, NumeTmp);

    IF NumeTmp IS NULL THEN -- Depozit nou sau prima lansare de Job
      NumeTmp := &apos;J_&apos;||Trim(TO_CHAR(aListID))||&apos;_&apos;||Trim(TO_CHAR(aListVer))||&apos;_&apos;||seq_JobUnic.NEXTVAL;
    END IF;
  END IF;


  aDINAMICName := &apos;JCL&apos;||JOB_CodJob1;

  IF Coalesce(JOB_CodJob1 ,0) &gt; 0 THEN
    INSERT INTO job_dinamic_cols (TABLENAME, FIELDNAME, DISPLAY, INDEXLOCAL)
    SELECT aDINAMICName, FIELDNAME, DISPLAY, INDEXLOCAL
    FROM tmp_dinamic_cols;
  END IF;

  IS_COLOR := 0;
  FOR V_REC IN (
    SELECT
      FIELDNAME,
      Min(FIELDTYPE) FIELDTYPE,
      CASE Min(FIELDTYPE)
        WHEN 0 THEN Max(FIELDSIZE)
        ELSE 0
      END FIELDSIZE
    --SELECT DISTINCT FIELDNAME, FIELDTYPE, FIELDSIZE
    FROM (
      SELECT DISTINCT UPPER(FIELDNAME) FIELDNAME,   FIELDTYPE,      FIELDSIZE FROM           LISTCOLS WHERE LISTID = ALISTID AND LISTVER = 0 AND UPPER(FIELDNAME) NOT LIKE &apos;NRCRT%&apos; AND UPPER(FIELDNAME) NOT LIKE &apos;NRG%&apos; AND NOT REGEXP_LIKE (UPPER(FIELDNAME), &apos;EXP_\d&apos;)
      UNION ALL
      SELECT DISTINCT UPPER(FIELDNAME) FIELDNAME,   FIELDTYPE,      FIELDSIZE FROM WINMADMIN.LISTCOLS WHERE LISTID = ALISTID AND LISTVER = ALISTVER AND USERCOLUMN = 1
      UNION ALL
      SELECT DISTINCT UPPER(FIELDNAME) FIELDNAME, 1 FIELDTYPE,    0 FIELDSIZE FROM WINMADMIN.LISTCALC WHERE LISTID = ALISTID AND LISTVER = ALISTVER AND TIP = 0
      UNION ALL
      SELECT DISTINCT UPPER(FIELDNAME) FIELDNAME, 0 FIELDTYPE, 1000 FIELDSIZE FROM WINMADMIN.LISTCALC WHERE LISTID = ALISTID AND LISTVER = ALISTVER AND Tip = 1
      UNION ALL
      SELECT DISTINCT UPPER(FIELDNAME) FIELDNAME, 1 FIELDTYPE,    0 FIELDSIZE FROM tmp_dinamic_cols
    )
    GROUP BY FIELDNAME
  ) LOOP
    IF UPPER(V_REC.FIELDNAME) = &apos;COLOR&apos;
    THEN IS_COLOR := 1;
    END IF;
    sCOL := sCOL||V_REC.FIELDNAME ||&apos; &apos;||
            CASE V_REC.FIELDTYPE
              WHEN 0 THEN &apos;VARCHAR2(&apos;||V_REC.FIELDSIZE||&apos;)&apos;
              WHEN 1 THEN &apos;NUMBER(30,7)&apos;
              WHEN 2 THEN &apos;DATE&apos;
              WHEN 4 THEN &apos;BLOB&apos;
              ELSE NULL
            END ||&apos;,&apos;;
  END LOOP;


  sCOL := sCOL ||&apos;UNITAR NUMBER(20)&apos;;
  IF IS_COLOR = 0 THEN
    SCOL := SCOL ||&apos;,COLOR NUMBER(20)&apos;;
  END IF;

--  INSERT INTO X(TEST) VALUES(&apos; CREATE TABLE &apos;||NUMETMP||&apos;( &apos;||SCOL||&apos;)&apos;);  COMMIT;
  BEGIN
    EXECUTE IMMEDIATE &apos; DROP TABLE &apos;||NUMETMP;
  EXCEPTION WHEN OTHERS THEN -- TABLA NU EXISTA
    NULL;
  END;

  EXECUTE IMMEDIATE &apos; CREATE TABLE &apos;||NUMETMP||&apos;( &apos;||SCOL||&apos;)&apos;;
END;

PROCEDURE MESAJ_JOB_EXECUTAT(aCODJOB1 IN NUMBER) IS
  vCodMesaj  NUMBER;
  vCodMesaj1 NUMBER;
  vUserId    NUMBER;
  sUserName  VARCHAR2(200);
  sListaName VARCHAR2(200);
  sFirmaName VARCHAR2(200);
BEGIN
  SELECT J.USERID, L.NAME INTO vUserId, sListaName
  FROM JOBLISTE1 J1
    INNER JOIN JOBLISTE J ON J.CODJOB = J1.CODJOB
    INNER JOIN WINMADMIN.LISTS L ON J1.LISTAID = L.LISTID AND J1.LISTAVER = L.LISTVER
  WHERE J1.CODJOB1 = aCODJOB1;

  IF Nvl(PKG_GLOBALS.GETUSERID,0) = 0
  THEN PKG_GLOBALS.SETUSERID(vUserId);
  ELSE vUserId := PKG_GLOBALS.GETUSERID;
  END IF;

  sFirmaName := PKG_GLOBALS.FIRMANAME;
  IF Nvl(pkg_categconst.GetValConstanta(&apos;AutoMesajJob&apos;,pkg_globals.AnLucru,pkg_globals.LunaLucru),1) = 1  THEN
    sUserName := WINMADMIN.PKG_USERFIRME.GETUSERNAME(vUserId);
    IF sFirmaName IS NULL THEN
      SELECT Max(SkemaFirma) KEEP (Dense_Rank Last ORDER BY codjoblistefin)
      INTO sFirmaName
      FROM JobListeFin
      WHERE CodJob1 = aCODJOB1;
    END IF;
    IF sFirmaName IS NULL THEN
      sFirmaName := USER;
    END IF;

    SELECT WINMADMIN.SEQ_MESAJE_CODMESAJ.NEXTVAL, WINMADMIN.SEQ_MESAJE1_CODMESAJ1.NEXTVAL INTO vCodMesaj, vCodMesaj1 FROM DUAL;
    INSERT INTO WINMADMIN.MESAJE(CODMESAJ,TEXT,FROM_USER,SKEMAFIRMA,DATA,TIP_MESAJ) VALUES (vCodMesaj,&apos;Job complet &apos;||sListaName||&apos; la data &apos;||SYSDATE, &apos;JOB LISTE&apos;,sFirmaName,SYSDATE,0);
    INSERT INTO WINMADMIN.MESAJE1(CODMESAJ1,CODMESAJ,TO_USER,STERS) VALUES (vCodMesaj1,vCodMesaj,sUserName,0);
  END IF;
END;

PROCEDURE SET_JOB(aCODORAR IN NUMBER, aCODJOB1 IN NUMBER,activ IN BOOLEAN DEFAULT TRUE) IS
  S VARCHAR2(5000);
  aListID  number(20);
  aListVER number(20);
  ANUMETMP VARCHAR2(200);
  SORAR VARCHAR2(100);
  aJobName varchar2(100);
  STOREDPROC varchar2(300);
  ALISTANAME VARCHAR2(100);
  aTableName varchar2(50);
	IsWebServer number(1);
	aCodJob     number(20);
BEGIN
  aJobName := &apos;JLIST&apos;||aCODJOB1;
  SELECT O.DENUMIRE INTO SORAR FROM ORAR O where o.codorar = aCODORAR;

  ANUMETMP := &apos;JLST&apos;||ACODJOB1;

	SELECT J1.CodJob, J1.LISTAID,J1.LISTAVER,L.NAME,tabla INTO aCodJob, ALISTID,ALISTVER,ALISTANAME,aTableName
  FROM JOBLISTE1 J1 INNER JOIN WINMADMIN.LISTS  L ON J1.LISTAID = L.LISTID AND J1.LISTAVER = L.LISTVER
  WHERE J1.CODJOB1 = ACODJOB1;

  SELECT WebServer into IsWebServer from JobListe where CodJob = aCodJob;
  SELECT l.storedprocname
  INTO STOREDPROC
  FROM JOBLISTE1 J1 INNER JOIN WINMADMIN.LISTS  L ON J1.LISTAID = L.LISTID  AND COALESCE(STOREDPROCNAME, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND RowNum = 1
  WHERE J1.CODJOB1 = ACODJOB1;

  IF Nvl(STOREDPROC, &apos;?&apos;) &lt;&gt; &apos;?&apos; then
    if COALESCE(IsWebServer, 0) = 1 then

   S :=   &apos;declare &apos; ||
           &apos; res number; &apos; ||
           &apos; begin &apos; ||
           &apos;   Res := &apos; || PKG_GLOBALS.FirmaName || &apos;.PKG_ORA_LISTS.DO_JOBLISTA_WEBSERVICE(&apos;&apos;&apos; ||  PKG_GLOBALS.FirmaName  || &apos;&apos;&apos;, &apos; || aCODJOB1 || &apos;); &apos; ||
           &apos; end;&apos;;
	  else
			S :=  &apos;DECLARE TMP_NAME VARCHAR2(50); USERN NUMBER(20);&apos;||Chr(13)||Chr(10)||
						&apos;BEGIN &apos;||Chr(13)||Chr(10)||
						&apos;  PKG_ORA_LISTS.SET_VARIABILE_SESIUNE(&apos;||aCODJOB1||&apos;); &apos;||Chr(13)||Chr(10)||
						&apos;  PKG_ORA_LISTS.CREAZA_TABLA(TMP_NAME,&apos;||TO_CHAR(ALISTID)||&apos;,&apos;||TO_CHAR(ALISTVER)||&apos;,&apos;||aCODJOB1||&apos;); &apos;||Chr(13)||Chr(10)||
						&apos;  &apos;||STOREDPROC||&apos;(TMP_NAME,&apos;||TO_CHAR(aListID)||&apos;,&apos;||TO_CHAR(AlISTvER)||&apos;); &apos;||Chr(13)||Chr(10)||
						&apos;  INSERT INTO JOBLISTEFIN (CODJOBLISTEFIN,CODJOB1,TABLA,SUBUNITATEA,SKEMAFIRMA,LISTANAME,DATAGEN,TABLE_TYPE,TIPDEPO,LISTID,LISTVER, DATAINI, DATAFIN)&apos;||Chr(13)||Chr(10)||
						&apos;  VALUES (SEQ_JOBLISTEFIN_CODJOBLISTEFIN.NEXTVAL,&apos;||aCODJOB1||&apos;,TMP_NAME,PKG_GLOBALS.GETSUBUNITATE,&apos;&apos;&apos;||PKG_GLOBALS.FIRMANAME||&apos;&apos;&apos;,&apos;&apos;&apos;||ALISTANAME||&apos;&apos;&apos;,SYSDATE,0,0,&apos;||TO_CHAR(ALISTID)||&apos;,&apos;||TO_CHAR(ALISTVER)||&apos;,PKG_ORA_LISTS.GET_JOB_DATAINI,PKG_ORA_LISTS.GET_JOB_DATAFIN);&apos;||Chr(13)||Chr(10)||
						&apos;  PKG_ORA_LISTS.MESAJ_JOB_EXECUTAT(&apos;||aCODJOB1||&apos;);&apos;||Chr(13)||Chr(10)||
						&apos;  PKG_ORA_LISTS.CREATE_VIEW_4_LAST_JOB (&apos;||aCODJOB1||&apos;);&apos;||Chr(13)||Chr(10)||
						&apos;  COMMIT;&apos;||Chr(13)||Chr(10)||
						&apos;END;&apos; ;
    end if;
    BEGIN
      DBMS_SCHEDULER.drop_job(aJobName,TRUE);
    EXCEPTION
      WHEN OTHERS THEN NULL;-- NU EXISTA JOBU....SAU FACE FIGURI !
    END;
    dbms_scheduler.create_job(
      job_name      =&gt; aJobName,
      job_type      =&gt; &apos;PLSQL_BLOCK&apos;,
      job_action    =&gt; s ,
      schedule_name =&gt; SORAR,
      comments      =&gt; To_char(aCODJOB1),
      auto_drop     =&gt; false
    );

    IF activ
    THEN DBMS_SCHEDULER.enable(AJOBNAME);
    ELSE DBMS_SCHEDULER.disable(AJOBNAME);
    END IF;
  ELSE
    BEGIN
      DBMS_SCHEDULER.drop_job(aJobName,TRUE);
    EXCEPTION
      WHEN OTHERS THEN NULL;-- NU EXISTA JOBU....SAU FACE FIGURI !
    END;
  END IF;
END;

procedure create_view_cumulat (aMask in varchar2, aViewName in varchar2) is
    union_token constant varchar2(20) := &apos; UNION ALL &apos;;
    all_col_list varchar_list;
    tab_list varchar_list;

    sSQL    varchar2(30000) := &apos; &apos;;
    idx     number(3) := 0;

     function get_select(aTableName in varchar2, cols varchar_list) return varchar2 is
       sResult varchar2(30000);
       i number;
       begin
          sResult := &apos; SELECT &apos;;
          for v_rec in (
          select  c.column_value,
                  case when uc.TABLE_NAME is null then 0 else 1 end col_exists
             from the(select cast(cols as varchar_list)  from dual) c left join  user_tab_columns uc on uc.COLUMN_NAME = c.column_value and uc.TABLE_NAME = aTableName
             order by c.column_value
            ) loop
            if v_rec.col_exists  = 1 then
               sResult := sResult ||v_rec.column_value||&apos;,&apos;;
            else
               sResult := sResult ||&apos; NULL &apos;||v_rec.column_value||&apos;,&apos;;
            end if;
          end loop;

         sResult := substr(sResult, 1, length(sResult) - 1) || &apos; FROM &apos;||aTableName;

         RETURN sResult;
       end;

begin

  select view_name bulk collect into tab_list  from user_views where instr(view_name,aMask) = 1;
  select distinct column_name bulk collect into all_col_list  from user_tab_columns where instr(table_name,aMask) = 1 order by column_name;

  for idx in tab_list.first..tab_list.last loop
    sSQL := sSQL ||  get_select (tab_list(idx), all_col_list) ||union_token;
  end loop;
  sSQL := substr(sSQL,1,length(sSQL) - length(union_token));

 execute immediate &apos;create or replace view &apos;||aViewName||&apos; AS &apos;||ssql;

end;

procedure testjobx is
TMP_NAME VARCHAR2(50);
USERN NUMBER(20);
g_data_ref dATE;
BEGIN
	g_data_ref := sYSDATE;
  PKG_ORA_LISTS.SET_DATA_DINAMIC(1, g_data_ref);
--  USERN := PKG_ORA_LISTS.DO_JOBLISTA_WEBSERVICE(&apos;CLIMA&apos;, 184);
/*
  PKG_ORA_LISTS.SET_VARIABILE_SESIUNE(130);
  PKG_ORA_LISTS.CREAZA_TABLA(TMP_NAME,114,0,130);
  PKG_LIST_BASE_NART.PROCESSLIST(TMP_NAME,114,0);
  INSERT INTO JOBLISTEFIN (CODJOBLISTEFIN,CODJOB1,TABLA,SUBUNITATEA,SKEMAFIRMA,LISTANAME,DATAGEN,TABLE_TYPE,TIPDEPO,LISTID,LISTVER, DATAINI, DATAFIN)
  VALUES (SEQ_JOBLISTEFIN_CODJOBLISTEFIN.NEXTVAL,130,TMP_NAME,PKG_GLOBALS.GETSUBUNITATE,&apos;Stest&apos;,&apos;Nomenclator articole&apos;,SYSDATE,0,0,114,0,PKG_ORA_LISTS.GET_JOB_DATAINI,PKG_ORA_LISTS.GET_JOB_DATAFIN);
  PKG_ORA_LISTS.MESAJ_JOB_EXECUTAT(130);
  PKG_ORA_LISTS.CREATE_VIEW_4_LAST_JOB (130);
  COMMIT;
*/
END;

end PKG_ORA_LISTS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A04C47B1A78280CF6A6D5D2AA866DD68D040AE41</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_pachete IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_61&apos;;

procedure DeleteLinie(aCodPachete in number, aCodLinie in number, aDenLinie in varchar2) is
aCount number(10);  
begin
  if aDenLinie = &apos;CODLIVR1&apos; then
    select count(*) into aCount from pacheteobjl where codpachete = aCodPachete;
    if aCount = 1 then
      select count(*) into aCount from pacheteobjl where codpachete = aCodPachete and CodLivr1 = aCodLinie;
      if aCount = 1 then
        pkg_pachete.SP_DELETERECORD(aCodPachete);
      end if;
    else
      delete pacheteobjl where codpachete = aCodPachete and CodLivr1 = aCodLinie;
      commit;
    end if;
  else
    select count(*) into aCount from pacheteobj where codpachete = aCodPachete;
    if aCount = 1 then
      select count(*) into aCount from pacheteobj where codpachete = aCodPachete and CodNirStoc = aCodLinie;
      if aCount = 1 then
        pkg_pachete.SP_DELETERECORD(aCodPachete);
      end if;
    else
      delete pacheteobj where codpachete = aCodPachete and CodNirStoc = aCodLinie;
      commit;
    end if;
  end if;
end;  

procedure UpdatePacheteObjL is
begin  
  for v_rec in (select pk.codpachete, l1.codlivr1, l1.cant, l1.cantum1
                from pachete1 pk1
                     inner join pachete pk on pk.codpachete = pk1.codpachete
                     inner join iesiri i on i.codies = pk1.coddoc and i.tipdoc = pk1.tipdoc
                     inner join iesiri1 i1 on i1.codies = i.codies
                     inner join livr1 l1 on i1.codies1 = l1.codies1
                     left join pacheteobjl pkl on pkl.codpachete = pk.codpachete and pkl.codlivr1 = l1.codlivr1
                where pk.tiplivrare = i1.tiplivrare and coalesce(pkl.codpacheteobjl,0) = 0
                ) loop
    insert into pacheteobjl (codpacheteobjl, codpachete, codlivr1, cant, rest, cantum1)
    values (seq_pacheteobjl_codpacheteobjl.nextval, v_rec.codpachete, v_rec.codlivr1, v_rec.cant, v_rec.cant, v_rec.cantum1);            
  end loop;
  commit;
end;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

function InsertDoc(RecId in number, CodDoc in number, TipDoc in number) return NUMBER is
aCod NUMBER(1) := 1;
tmp number(20);
begin
  BEGIN
    SELECT codpachete INTO Tmp FROM PACHETE WHERE codpachete = RecId FOR UPDATE NOWAIT;
    INSERT INTO PACHETE1( CodPachete1, CodPachete, CodDoc, TipDoc) VALUES (SEQ_Pachete1_CodPachete1.Nextval, RecId, CodDoc, TipDoc);
    COMMIT;
  EXCEPTION WHEN OTHERS THEN aCod := 0;
  END;
  Return aCod;
end;

procedure InsertObj(RecId in number, aCodNirStoc in number, aCant in number, aCantUM1 in number) is
aCount NUMBER(10);
vCant number(20,7);
begin
  if RecId &gt; 0 then
    select count(*) into aCount from pacheteobj where codnirstoc = aCodNirStoc and CodPachete = RecId;
    if aCount = 1 then
      update pacheteobj set
        Cant = Cant + aCant,
        Rest = rest + aCant,
        CantUM1 = CantUM1 + aCantUM1
      where codpachete = RecId and CodNirStoc = aCodNirStoc;
    else
      if aCant &gt; 0 then
        insert into pacheteobj (codpacheteobj, codpachete, codnirstoc, cant, rest, cantum1)
        values (seq_pacheteobj_codpacheteobj.nextval, RecId, aCodNirStoc, aCant, aCant, aCantUM1);
      end if;
    end if;
  else
    if aCant &lt; 0 then
      vCant := - aCant;
      for v_rec in (select pobj.codpacheteobj, pobj.rest cant
                    from pacheteobj pobj
                         inner join pachete p on pobj.codpachete = p.codpachete
                    where pobj.codnirstoc = aCodNirStoc
                    order by p.datacreare desc
                   ) loop
        if vCant &lt;= 0 then Exit; end if;
        if vCant &gt; v_rec.cant then
          vCant := vCant - v_rec.cant;
          update pacheteobj set cant = cant - vCant, rest = rest - vCant where codpacheteobj = v_rec.codpacheteobj;
          delete pacheteobj where cant = 0 and codpacheteobj = v_rec.codpacheteobj;
        else
          update pacheteobj set cant = cant - vCant, rest = rest - vCant where codpacheteobj = v_rec.codpacheteobj;
          vCant := 0;
        end if;
      end loop;
    end if;
  end if;
  COMMIT;
end;

procedure InsertObjL(RecId in number, aCodLivr1 in number, aCant in number, aCantUM1 in number, aPachet in number default 0) is
aCount NUMBER(10);
vCant number(20,7);
begin
  if aPachet &gt; 0 then
    if RecId &gt; 0 then
      select count(*) into aCount from pacheteobjl where codlivr1 = aCodLivr1 and CodPachete = RecId and Pachet = aPachet;
      if aCount = 1 then
        update pacheteobjl set
          Cant = Cant + aCant,
          Rest = rest + aCant,
          CantUM1 = CantUM1 + aCantUM1
        where codpachete = RecId and CodLivr1 = aCodLivr1 and Pachet = aPachet;
      else
        if aCant &gt; 0 then
          insert into pacheteobjl (codpacheteobjl, codpachete, codlivr1, cant, rest, cantum1, Pachet)
          values (seq_pacheteobjl_codpacheteobjl.nextval, RecId, aCodLivr1, aCant, aCant, aCantUM1, aPachet);
        end if;
      end if;
    else
      if aCant &lt; 0 then
        vCant := - aCant;
        for v_rec in (select pobj.codpacheteobjl, pobj.rest cant
                      from pacheteobjl pobj
                           inner join pachete p on pobj.codpachete = p.codpachete
                      where pobj.codlivr1 = aCodLivr1
                      order by p.datacreare desc
                     ) loop
          if vCant &lt;= 0 then Exit; end if;
          if vCant &gt; v_rec.cant then
            vCant := vCant - v_rec.cant;
            update pacheteobjl set cant = cant - vCant, rest = rest - vCant where codpacheteobjl = v_rec.codpacheteobjl;
            delete pacheteobjl where cant = 0 and codpacheteobjl = v_rec.codpacheteobjl;
          else
            update pacheteobjl set cant = cant - vCant, rest = rest - vCant where codpacheteobjl = v_rec.codpacheteobjl;
            vCant := 0;
          end if;
        end loop;
      end if;
    end if;
  else
    if RecId &gt; 0 then
      select count(*) into aCount from pacheteobjl where codlivr1 = aCodLivr1 and CodPachete = RecId;
      if aCount = 1 then
        update pacheteobjl set
          Cant = Cant + aCant,
          Rest = rest + aCant,
          CantUM1 = CantUM1 + aCantUM1
        where codpachete = RecId and CodLivr1 = aCodLivr1;
      else
        if aCant &gt; 0 then
          insert into pacheteobjl (codpacheteobjl, codpachete, codlivr1, cant, rest, cantum1)
          values (seq_pacheteobjl_codpacheteobjl.nextval, RecId, aCodLivr1, aCant, aCant, aCantUM1);
        end if;
      end if;
    else
      if aCant &lt; 0 then
        vCant := - aCant;
        for v_rec in (select pobj.codpacheteobjl, pobj.rest cant
                      from pacheteobjl pobj
                           inner join pachete p on pobj.codpachete = p.codpachete
                      where pobj.codlivr1 = aCodLivr1
                      order by p.datacreare desc
                     ) loop
          if vCant &lt;= 0 then Exit; end if;
          if vCant &gt; v_rec.cant then
            vCant := vCant - v_rec.cant;
            update pacheteobjl set cant = cant - vCant, rest = rest - vCant where codpacheteobjl = v_rec.codpacheteobjl;
            delete pacheteobjl where cant = 0 and codpacheteobjl = v_rec.codpacheteobjl;
          else
            update pacheteobjl set cant = cant - vCant, rest = rest - vCant where codpacheteobjl = v_rec.codpacheteobjl;
            vCant := 0;
          end if;
        end loop;
      end if;
    end if;
  end if;  
  COMMIT;
end;

function getpartener(RecId in NUMBER) return varchar2 is
aDenPart varchar2(200);
begin
  select case
           when P.TipPart = &apos;PARTENER&apos; or P.TIPPART IS NULL then PA.Den_Part
           when P.TipPart = &apos;SUBUNITATE&apos; then S.Den_Subunit
           when P.TipPart = &apos;GESTIUNE&apos; then G.Den_Gest
         end into aDenPart
  from pachete p
       LEFT JOIN NPART PA ON P.CodPart = PA.CodPart
       LEFT JOIN NGEST G ON P.CodPart = G.Codgest
       LEFT JOIN NSUBUNIT S ON P.CodPart = S.CodSubunit
  where p.codpachete = recid;
  return adenpart;
end;

function getcodpartener(RecId in NUMBER) return number is
aCodPart number(20);
begin
  select case
           when p1.tipdoc in (12, 13) then
             coalesce(ng.codgest, 0)
           when p1.tipdoc = 23 then
             coalesce(ns.codsubunit, 0)
           else
             coalesce(np.codpart, 0)
         end into aCodPart
  from pachete p
       inner join pachete1 p1 on p.codpachete = p1.codpachete
       left join transf t on p1.coddoc = t.codtransf
       left join ngest ng on t.codgestcmd = ng.codgest
       left join iesiri i on p1.coddoc = i.codies
       left join npart np on i.partener = np.codpart
       left join nsubunit ns on i.codsubunit = ns.codsubunit
  where p.codpachete = recid and rownum &lt;= 1;
  return aCodPart;
end;

function GetMasa(RecId in number) return number is
aMasa number(20, 7);
aTip number(1);
begin
  begin
    select coalesce(tippachet,0) into aTip from pachete where codpachete = RecId;
  exception when others then aTip := 0;
  end;

  if aTip = 0 then
    select sum
    (
      PKOBJL.Cant * coalesce(OBJ.Masa, 0)
    )
    into aMasa
    FROM PACHETEOBJL PKOBJL
         INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = PKOBJL.CODLIVR1
         INNER JOIN NIRSTOC NS ON L1.CodNIRStoc = NS.CodNIRStoc
         INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
    WHERE PKOBJL.Codpachete = RecId;
  else
    select sum
    (
      PKOBJ.Cant * coalesce(OBJ.Masa, 0)
    )
    into aMasa
    FROM PACHETEOBJ PKOBJ
         INNER JOIN NIRSTOC NS ON PKOBJ.CodNIRStoc = NS.CodNIRStoc
         INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
    WHERE PKOBJ.Codpachete = RecId;
  end if;

  Return aMasa;
end;

function GetVolum(RecId in number) return number is
aVolum number(20, 7);
aTip number(1);
begin
  begin
    select coalesce(tippachet,0) into aTip from pachete where codpachete = RecId;
  exception when others then aTip := 0;
  end;

  if aTip = 0 then
    select sum
    (
      PKOBJL.Cant * coalesce(OBJ.Volum, 0)
    )
    into aVolum
    FROM PACHETEOBJL PKOBJL
         INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = PKOBJL.CODLIVR1
         INNER JOIN NIRSTOC NS ON L1.CodNIRStoc = NS.CodNIRStoc
         INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
    WHERE PKOBJL.Codpachete = RecId;
  else
    select sum
    (
      PKOBJ.Cant * coalesce(OBJ.Volum, 0)
    )
    into aVolum
    FROM PACHETEOBJ PKOBJ
         INNER JOIN NIRSTOC NS ON PKOBJ.CodNIRStoc = NS.CodNIRStoc
         INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
    WHERE PKOBJ.Codpachete = RecId;
  end if;

  Return aVolum;
end;

function GetMasa1(RecId in number) return number is
aMasa number(20, 7);
aTip number(1);
begin
  aMasa := 0;
  begin
    select coalesce(tippachet,0) into aTip from pachete where codpachete = RecId;
  exception when others then aTip := 0;
  end;

  if aTip = 0 then
    FOR V_REC IN (
      select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Masa, 0)
      )  masa
      FROM TMP_PACHETE1 P1
           INNER JOIN TMP_PACHETEOBJL PKOBJL ON PKOBJL.CODDOC = P1.CODDOC AND PKOBJL.TIPDOC = P1.TIPDOC
           INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = PKOBJL.CODLIVR1
           INNER JOIN NIRSTOC NS ON L1.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE P1.Codpachete1 = RecId
      UNION ALL
      select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Masa, 0)
      ) masa
      FROM TMP_PACHETE1 P1
           INNER JOIN TMP_PACHETEOBJL PKOBJL ON PKOBJL.CODDOC = P1.CODDOC AND PKOBJL.TIPDOC = P1.TIPDOC
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE P1.Codpachete1 = RecId
    ) LOOP
      aMasa := aMasa + v_rec.masa;
    END LOOP;  
  end if;

  Return aMasa;
end;

function GetVolum1(RecId in number) return number is
aVolum number(20, 7);
aTip number(1);
begin
  aVolum := 0;
  begin
    select coalesce(tippachet,0) into aTip from pachete where codpachete = RecId;
  exception when others then aTip := 0;
  end;

  if aTip = 0 then
    FOR V_REC IN (
      select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Volum, 0)
      ) volum
      FROM TMP_PACHETE1 P1
           INNER JOIN TMP_PACHETEOBJL PKOBJL ON PKOBJL.CODDOC = P1.CODDOC AND PKOBJL.TIPDOC = P1.TIPDOC
           INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = PKOBJL.CODLIVR1
           INNER JOIN NIRSTOC NS ON L1.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE P1.Codpachete1 = RecId
      UNION ALL
      select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Volum, 0)
      ) volum
      FROM TMP_PACHETE1 P1
           INNER JOIN TMP_PACHETEOBJL PKOBJL ON PKOBJL.CODDOC = P1.CODDOC AND PKOBJL.TIPDOC = P1.TIPDOC
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE P1.Codpachete1 = RecId
    ) LOOP
      aVolum := aVolum + v_rec.volum;
    END LOOP;  
  end if;

  Return aVolum;
end;

function GetValoare1(RecId in number) return number is
aVALOARE number(20, 7);
aTip number(1);
begin
  aVALOARE := 0;
  begin
    select coalesce(tippachet,0) into aTip from pachete where codpachete = RecId;
  exception when others then aTip := 0;
  end;

  if aTip = 0 then
    FOR V_REC IN (
      select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(PKOBJL.PRET, 0)
      ) valoare
      FROM TMP_PACHETE1 P1
           INNER JOIN TMP_PACHETEOBJL PKOBJL ON PKOBJL.CODDOC = P1.CODDOC AND PKOBJL.TIPDOC = P1.TIPDOC
      WHERE P1.Codpachete1 = RecId
    ) LOOP
      aValoare := aValoare + v_rec.valoare;
    END LOOP;  
  end if;

  Return aValoare;
end;

PROCEDURE SETLISTARE(RecId IN NUMBER, aListat IN NUMBER) IS
BEGIN
  UPDATE PACHETE
  SET
    Listat = aListat
  WHERE CodPachete = RecId;

  UPDATE TMP_PACHETE
  SET
    Listat = aListat
  WHERE CodPachete = RecId;

  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codpachete INTO Tmp FROM PACHETE WHERE codpachete = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aCarnetDoc NUMBER (20);
  aNrDoc     NUMBER (20);
  aDataDoc   DATE;
  aDoc       VARCHAR2(200);
  aSubunit   NUMBER(20);
BEGIN
  SP_LOCKRECORD(RecId);
  -- mColet     --&gt;  77
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 77);
  SELECT P.CARNETDOC, P.NRDOC, P.DATAP, DC.SERIE||P.NRDOC||&apos;/&apos;||P.DATAP, P.SUBUNITATE
  INTO aCarnetDoc, aNrDoc, aDataDoc, aDoc, aSubunit
  FROM PACHETE P LEFT JOIN DOCCARNETE DC ON P.CARNETDOC = DC.CODCARNET
  WHERE P.CODPACHETE = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PACHETE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM PACHETELINK WHERE CODPACHETEOBJ IN (SELECT CODPACHETEOBJ FROM PACHETEOBJ WHERE CODPACHETE = RecId);
  DELETE FROM PACHETEDLLINK WHERE CODPACHETEOBJ IN (SELECT CODPACHETEOBJ FROM PACHETEOBJ WHERE CODPACHETE = RecId);
  DELETE FROM PACHETEOBJ WHERE codpachete = RecId;
  DELETE FROM PACHETEOBJL WHERE codpachete = RecId;
  DELETE FROM PACHETE1 WHERE codpachete = RecId;
  DELETE FROM PACHETE  WHERE codpachete = RecId;


  PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);

  NotifyModif(2, RecId, &apos;PACHETE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_PACHETE FIELDS( codpachete, listat ) VALUES (0, 0) ;
  -- mColet     --&gt;  77
  PKG_CFGTABLES.EXT_INSERTRECORD(77);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_PACHETE (CodPachete,
                           DataP,
                           UserID,
                           DataCreare,
                           Subunitate,
                           Gestiune,
                           CarnetDoc,
                           NrDoc,
                           Colector,
                           DataColectare,
                           Verificator,
                           DataVerificare,
                           Transportator,
                           DataTransport,
                           NrPachete,
                           Operat,
                           Blocat,
                           Anulat,
                           IdentificatorP,
                           Listat,
                           An,
                           Luna,
                           CodPart,
                           TipPart,
                           Sediu,
                           Delegat,
                           SerieDoc,
                           Den_Part,
                           Masa,
                           Volum,
                           Den_Sediu,
                           NumeDelegat,
                           TipLivrare,
                           TipPachet,
                           Sponsorizare )
                  ( SELECT P.codpachete,
                           P.DataP,
                           P.UserID,
                           P.DataCreare,
                           P.Subunitate,
                           P.Gestiune,
                           P.CarnetDoc,
                           P.NrDoc,
                           P.Colector,
                           P.DataColectare,
                           P.Verificator,
                           P.DataVerificare,
                           P.Transportator,
                           P.DataTransport,
                           P.NrPachete,
                           P.Operat,
                           P.Blocat,
                           P.Anulat,
                           P.IdentificatorP,
                           P.Listat,
                           P.An,
                           P.Luna,
                           P.CodPart,
                           P.TipPart,
                           P.Sediu,
                           P.Delegat,
                           DC.Serie,
                           case
                             when P.TipPart = &apos;PARTENER&apos; then PA.Den_Part
                             when P.TipPart = &apos;SUBUNITATE&apos; then S.Den_Subunit
                             when P.TipPart = &apos;GESTIUNE&apos; then G.Den_Gest
                           end Den_Part,
                           coalesce(GetMasa(RecId), 0),
                           coalesce(GetVolum(RecId), 0),
                           A.obs,
                           TR.Delegat,
                           coalesce(P.TipLivrare,3),
                           coalesce(P.TipPachet,0),
                           coalesce(P.Sponsorizare,0)
                    FROM PACHETE P
                         LEFT JOIN DOCCARNETE DC ON P.CARNETDOC = DC.CODCARNET
                         LEFT JOIN NPART PA ON P.CodPart = PA.CodPart
                         LEFT JOIN NGEST G ON P.CodPart = G.Codgest
                         LEFT JOIN NSUBUNIT S ON P.CodPart = S.CodSubunit
                         LEFT JOIN NAGENDA A ON P.Sediu = A.CODAGENDA
                         LEFT JOIN NPARTTR TR ON P.Delegat = TR.CodPartTr
                    WHERE codpachete = RecId ) ;

  INSERT INTO TMP_PACHETE1 ( CodPachete,
                             CodDoc,
                             TipDoc,
                             DenTipDoc,
                             SerieDoc,
                             NrDoc,
                             DataDoc,
                             CodPart,
                             Partener
                           )
                     /*SELECT * from (SELECT P1.CodPachete1 CodPachete1,
                             P1.CodPachete CodPachete,
                             P1.CodDoc CodDoc,
                             P1.TipDoc TipDoc,
                             T.PrefixDoc PrefixDoc,
                             DCT.Serie Serie,
                             T.NrDoc NrDoc,
                             T.DataDoc DataDoc,
                             CASE
                               WHEN P1.TipDoc = 12 THEN T.CodGestCmd
                               ELSE 0
                             END CodPart,
                             CASE
                               WHEN P1.TipDoc = 12 THEN G.Den_Gest
                               ELSE &apos;...nedefinit...&apos;
                             END Partener
                      FROM PACHETE1 P1 INNER JOIN TRANSF T ON P1.Coddoc = T.CodTransf AND coalesce(T.Anulat, 0) &lt;&gt; 1
                                       LEFT JOIN DOCCARNETE DCT ON T.CarnetDoc = DCT.CodCarnet
                                       LEFT JOIN NGEST G ON T.CodGestCmd = G.CodGest
                      WHERE P1.CodPachete = RecId AND P1.TipDoc IN (12, 13)
                      UNION ALL*/
                      SELECT distinct
                             POBJL.CodPachete CodPachete,
                             I.CODIES CodDoc,
                             I.TipDoc TipDoc,
                             I.PrefixDoc PrefixDoc,
                             I.SERIADOC,
                             I.NrDoc NrDoc,
                             I.DataDoc DataDoc,
                             I.Partener,
                             P.Den_Part
                      FROM PACHETEOBJL POBJL
                           INNER JOIN LIVR1 L1 ON L1.CODLIVR1 = POBJL.CODLIVR1
                           INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
                           INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
                           INNER JOIN IESIRI I ON I1.CODIES = I.CodIes AND coalesce(I.Anulat, 0) &lt;&gt; 1 AND L.CODIES = I.CODIES
                           LEFT JOIN DOCCARNETE DCI ON I.CarnetDoc = DCI.CodCarnet
                           LEFT JOIN NPART P ON I.Partener = P.CodPart
                           LEFT JOIN NSUBUNIT S ON I.Codsubunit = S.CodSubunit
                      WHERE POBJL.CodPachete = RecId
                      UNION ALL
                      SELECT distinct
                             POBJL.CodPachete CodPachete,
                             C.CODCOMANDA CodDoc,
                             C.TipDoc TipDoc,
                             C.PrefixDoc PrefixDoc,
                             C.SERIADOC,
                             C.NrDoc NrDoc,
                             C.DataDoc DataDoc,
                             C.Partener,
                             P.Den_Part
                      FROM PACHETEOBJL POBJL
                           INNER JOIN REZERVATS R ON POBJL.CODREZERVATS = R.CODREZERVATS
                           INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = R.CODCOMANDA1
                           INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
                           INNER JOIN NPART P ON C.Partener = P.CodPart
                      WHERE POBJL.CodPachete = RecId
                      ;
  
  for v_rec in (select p1.*
                from pachete1 p1 
                     inner join tmp_pachete1 tmp on tmp.coddoc = p1.coddoc and tmp.tipdoc = p1.tipdoc
                where p1.codpachete = recid) loop
    update tmp_pachete1 set codpachete1 = v_rec.codpachete1
    where coddoc = v_rec.coddoc and tipdoc = v_rec.tipdoc;
  end loop;              
  
  INSERT INTO TMP_PACHETEOBJ(CODPACHETEOBJ, CODPACHETE, CODNIRSTOC, CANT, REST, LIVRAT, DEN_UM1, DENUMIRE)
  SELECT POBJ.CODPACHETEOBJ, POBJ.CODPACHETE, POBJ.CODNIRSTOC, POBJ.CANT, POBJ.REST, POBJ.CANT - POBJ.REST, NUM1.DEN_UM1, OBJ.DENUMIRE
  FROM PACHETEOBJ POBJ
       INNER JOIN NIRSTOC NS ON POBJ.CODNIRSTOC = NS.CODNIRSTOC
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
       INNER JOIN NUM1 ON NUM1.CODUM1 = NS.UMSEC
  WHERE POBJ.CODPACHETE = RECID;

  INSERT INTO TMP_PACHETEOBJL
  (
    codpacheteobjl,
    codpachete,
    codlivr1,
    cant,
    rest,
    cantum1,
    codrezervats,
    CODDOC,
    TIPDOC,
    DenObiect,
    UM,
    Den_UM1,
    CodObiect,
    CantAmb,
    Colete,
    CantMin,
    CodAmb,
    OK,
    DenAmb,
    CodGest,
    DenUM1,
    D1,
    D2,
    D3,
    Pachet,
    MasaU,
    VolumU,
    Masa,
    Volum,
    Pret,
    Valoare,
    CodComanda1
  )
  SELECT 
    PL.codpacheteobjl,
    PL.codpachete,
    PL.codlivr1,
    PL.cant,
    PL.rest,
    PL.cantum1,
    PL.codrezervats,
    I.CODIES CODDOC,
    I.TIPDOC,
    case
      when coalesce(L1.CodNirStoc, 0) = 0 then OBJVAL.Denumire
      else OBJ.Denumire
    end Denumire,
    ART.UM,
    UM1.Den_UM1,
    I1.CodObiect,
    AMB.CANT CantAmb,
    0 Colete,
    AMB.CantMin,
    AMB.CODOBIECTRETURN CodAmb,
    0 OK,
    AMB.DENUMIRE DenAmb,
    coalesce(NIR.GEST, LVAL.GEST) CodGest,
    UMS.Den_UM DenUM1,
    NS.D1,
    NS.D2,
    NS.D3,
    COALESCE(PL.Pachet,0),
    OBJ.MASA,
    OBJ.VOLUM,
    OBJ.MASA * PL.CANT,
    OBJ.VOLUM * PL.CANT,
    COALESCE(I1.PU,0),
    COALESCE(I1.PU,0) * PL.CANT,
    0
  FROM PACHETEOBJL PL
       INNER JOIN LIVR1 L1 ON PL.CodLivr1 = L1.CodLivr1
       INNER JOIN IESIRI1 I1 ON I1.CODIES1 = L1.CODIES1
       INNER JOIN IESIRI I ON I1.CodIes = I.CodIes AND coalesce(I.Anulat, 0) &lt;&gt; 1
       INNER JOIN LIVR L ON I.CodIes = L.CodIes AND L1.CODLIVR = L.CODLIVR
       LEFT JOIN NIRSTOC NS ON L1.CodNIRStoc = NS.CodNIRStoc
       LEFT JOIN NIR NIR ON NS.CODNIR = NIR.CODNIR
       LEFT JOIN LIVRVAL LVAL ON LVAL.CodLivr1 = L1.CODLIVR1
       LEFT JOIN NIRSER NSR ON L1.CodNIRSer = NSR.CodNIRSer
       LEFT JOIN NSERII SR ON NSR.CodSerie = SR.CodSerie
       LEFT JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
       LEFT JOIN NART ART ON OBJ.CodArticol = ART.CodArticol
       LEFT JOIN NARTOBJ OBJVAL ON LVAL.CodObiect = OBJVAL.CodObiect
       LEFT JOIN NUM1 UM1 ON L1.UMSec = UM1.CodUM1
       LEFT JOIN NUM UMS ON ART.UM1 = UMS.CodUM
       LEFT JOIN (SELECT A.*, O.DENUMIRE
                  FROM NARTAMB A
                       INNER JOIN (
                                   select CODOBIECT, COUNT(*) CATE
                                   from NARTAMB
                                   GROUP BY CODOBIECT
                                   HAVING COUNT(*) = 1
                                   ) AMBUNIC ON AMBUNIC.CODOBIECT = A.CODOBIECT
                       INNER JOIN NARTOBJ O ON O.CODOBIECT = A.CODOBIECTRETURN            
                 ) AMB ON AMB.CODOBIECT = I1.CODOBIECT
  WHERE PL.CODPACHETE = RECID
  UNION ALL
  SELECT 
    PL.codpacheteobjl,
    PL.codpachete,
    PL.codlivr1,
    PL.cant,
    PL.rest,
    PL.cantum1,
    PL.codrezervats,
    C.CODCOMANDA CODDOC,
    C.TIPDOC,
    OBJ.Denumire,
    ART.UM,
    UM1.Den_UM1,
    C1.CodObiect,
    AMB.CANT CantAmb,
    0 Colete,
    AMB.CantMin,
    AMB.CODOBIECTRETURN CodAmb,
    0 OK,
    AMB.DENUMIRE DenAmb,
    NIR.GEST CodGest,
    UMS.Den_UM DenUM1,
    NS.D1,
    NS.D2,
    NS.D3,
    COALESCE(PL.Pachet,0),
    OBJ.MASA,
    OBJ.VOLUM,
    OBJ.MASA * PL.CANT,
    OBJ.VOLUM * PL.CANT,
    PKG_PRETURI.WMROTOPRET(OBJ.ROTUNJIRE, CASE WHEN C.PRETCUAMANUNT = 1 THEN (C1.PU *100) / (100 + PKG_SELECTARTICOLE.GETPROCENTTVA(OBJ.CodArticol,C.AN,C.LUNA)) ELSE C1.PU END),
    PKG_PRETURI.WMROTOPRET(OBJ.ROTUNJIRE, CASE WHEN C.PRETCUAMANUNT = 1 THEN (C1.PU *100) / (100 + PKG_SELECTARTICOLE.GETPROCENTTVA(OBJ.CodArticol,C.AN,C.LUNA)) ELSE C1.PU END) * PL.CANT,
    C1.CODCOMANDA1
  FROM PACHETEOBJL PL
       INNER JOIN REZERVATS R ON PL.CODREZERVATS = R.CODREZERVATS
       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = R.CODCOMANDA1
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       LEFT JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
       LEFT JOIN NIR NIR ON NS.CODNIR = NIR.CODNIR
       LEFT JOIN NIRSER NSR ON R.CodNIRSer = NSR.CodNIRSer
       LEFT JOIN NSERII SR ON NSR.CodSerie = SR.CodSerie
       LEFT JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
       LEFT JOIN NART ART ON OBJ.CodArticol = ART.CodArticol
       LEFT JOIN NUM1 UM1 ON R.UMSec = UM1.CodUM1
       LEFT JOIN NUM UMS ON ART.UM1 = UMS.CodUM
       LEFT JOIN (SELECT A.*, O.DENUMIRE
                  FROM NARTAMB A
                       INNER JOIN (
                                   select CODOBIECT, COUNT(*) CATE
                                   from NARTAMB
                                   GROUP BY CODOBIECT
                                   HAVING COUNT(*) = 1
                                   ) AMBUNIC ON AMBUNIC.CODOBIECT = A.CODOBIECT
                       INNER JOIN NARTOBJ O ON O.CODOBIECT = A.CODOBIECTRETURN            
                 ) AMB ON AMB.CODOBIECT = R.CODOBIECT
  WHERE PL.CODPACHETE = RECID;
  
  INSERT INTO TMP_PACHETEGEST (CODGEST)
  SELECT DISTINCT CODGEST FROM TMP_PACHETEOBJL;
  UPDATE TMP_PACHETEGEST TMP SET
  DEN_GEST = (SELECT DEN_GEST FROM NGEST WHERE CODGEST = TMP.CODGEST);
  
  INSERT INTO TMP_PACHETECOL(PACHET,
                             MASA,
                             VOLUM,
                             VALOARE)
  SELECT COALESCE(PACHET,0), SUM(COALESCE(MASA,0)), SUM(COALESCE(VOLUM,0)), SUM(COALESCE(VALOARE,0))
  FROM TMP_PACHETEOBJL
  GROUP BY COALESCE(PACHET,0);
  
  update tmp_pachete set nrpachete = (select count(1)
                                      from (select distinct pachet from tmp_pacheteobjl where pachet &gt; 0)
                                     ),
                         valoare = (select sum(coalesce(valoare,0)) from tmp_pacheteobjl); 
  
  for v_rec in (select coddoc, tipdoc from tmp_pachete1) loop
    update tmp_pachete1 set 
    masa = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Masa, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE PKOBJL.CODDOC = V_REC.CODDOC AND PKOBJL.TIPDOC = V_REC.TIPDOC
    ), 
    volum = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.VOLUM, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE PKOBJL.CODDOC = V_REC.CODDOC AND PKOBJL.TIPDOC = V_REC.TIPDOC
    ), 
    valoare = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(PKOBJL.PRET, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
      WHERE PKOBJL.CODDOC = V_REC.CODDOC AND PKOBJL.TIPDOC = V_REC.TIPDOC
    )  
    where coddoc = v_rec.coddoc and tipdoc = v_rec.tipdoc;
  end loop;
  
  for v_rec in (select codgest from tmp_pachetegest) loop
    update tmp_pachetegest set 
    masa = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.Masa, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE PKOBJL.CODGEST = V_REC.CODGEST
    ), 
    volum = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(OBJ.VOLUM, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
           INNER JOIN REZERVATS R ON R.CODREZERVATS = PKOBJL.CODREZERVATS
           INNER JOIN NIRSTOC NS ON R.CodNIRStoc = NS.CodNIRStoc
           INNER JOIN NARTOBJ OBJ ON NS.CodObiect = OBJ.CodObiect
      WHERE PKOBJL.CODGEST = V_REC.CODGEST
    ), 
    valoare = (
    select sum
      (
        COALESCE(PKOBJL.Cant,0) * coalesce(PKOBJL.PRET, 0)
      )
      FROM TMP_PACHETEOBJL PKOBJL
      WHERE PKOBJL.CODGEST = V_REC.CODGEST
    )
    where CODGEST = V_REC.CODGEST;
  end loop; 
  -- mColet     --&gt;  77 
  PKG_CFGTABLES.EXT_GOTORECORD(77);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aCarnetDoc NUMBER(20);
  aNumarDoc  NUMBER(20);
  aDataDoc   DATE;
  aDoc       VARCHAR2(200);
  aSubunit   NUMBER(20);
BEGIN
  SELECT CarnetDoc, NrDoc, DataP, SerieDoc||NrDoc||&apos;/&apos;||DataP, Subunitate
  INTO aCarnetDoc, aNumarDoc, aDataDoc, aDoc, aSubunit
  FROM TMP_PACHETE;
  -- mColet     --&gt;  77
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (77); 
  IF Operation = 0 THEN
    SELECT  codpachete INTO RecId FROM TMP_PACHETE;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PACHETE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE PACHETE
      SET ( DataP,
            UserId,
            DataCreare,
            Subunitate,
            Gestiune,
            CarnetDoc,
            NrDoc,
            Colector,
            DataColectare,
            Verificator,
            DataVerificare,
            Transportator,
            DataTransport,
            NrPachete,
            Operat,
            Blocat,
            Anulat,
            IdentificatorP,
            Listat,
            An,
            Luna,
            CodPart,
            TipPart,
            Sediu,
            Delegat,
            TipLivrare,
            TipPachet,
            Sponsorizare )
 = ( SELECT DataP,
            UserId,
            DataCreare,
            Subunitate,
            Gestiune,
            CarnetDoc,
            NrDoc,
            Colector,
            DataColectare,
            Verificator,
            DataVerificare,
            Transportator,
            DataTransport,
            NrPachete,
            Operat,
            Blocat,
            Anulat,
            Identificatorp,
            Listat,
            An,
            Luna,
            CodPart,
            TipPart,
            Sediu,
            Delegat,
            coalesce(TipLivrare,3),
            coalesce(tippachet,0),
            Sponsorizare
    FROM TMP_PACHETE )
    WHERE codpachete = RecId ;

    DELETE FROM PACHETE1 where CodPachete = RecId and CodPachete1 not in (Select CodPachete1 from TMP_PACHETE1);
    FOR V_REC IN (SELECT * FROM TMP_PACHETE1) LOOP
      IF V_REC.CODPACHETE1 &gt; 0 THEN
        UPDATE PACHETE1 SET
          CODDOC = V_REC.CODDOC,
          TIPDOC = V_REC.TIPDOC
        WHERE CODPACHETE1 = V_REC.CODPACHETE1;  
      ELSE
        INSERT INTO PACHETE1(CODPACHETE1, CODPACHETE, CODDOC, TIPDOC)
        VALUES (SEQ_PACHETE1_CODPACHETE1.NEXTVAL, RECID, V_REC.CODDOC, V_REC.TIPDOC);
      END IF;
    END LOOP;
      
    DELETE FROM PACHETEOBJ WHERE CODPACHETE = RECID AND CODPACHETEOBJ NOT IN (SELECT CODPACHETEOBJ FROM TMP_PACHETEOBJ);
    FOR V_REC IN (SELECT * FROM TMP_PACHETEOBJ) LOOP
      IF V_REC.CODPACHETEOBJ &gt; 0 THEN
        UPDATE PACHETEOBJ SET
          CODNIRSTOC = V_REC.CODNIRSTOC,              
          CANT       = V_REC.CANT,
          REST       = V_REC.REST,
          CANTUM1    = V_REC.CANTUM1
        WHERE CODPACHETEOBJ = V_REC.CODPACHETEOBJ;
      ELSE
        INSERT INTO PACHETEOBJ (CODPACHETEOBJ, CODPACHETE, CODNIRSTOC, CANT, REST, CANTUM1)
        VALUES (SEQ_PACHETEOBJ_CODPACHETEOBJ.NEXTVAL, RECID, V_REC.CODNIRSTOC, V_REC.CANT, V_REC.REST, V_REC.CANTUM1);
      END IF;  
    END LOOP;
    
    DELETE FROM PACHETEOBJL WHERE CODPACHETE = RECID AND CODPACHETEOBJL NOT IN (SELECT CODPACHETEOBJL FROM TMP_PACHETEOBJL);
    FOR V_REC IN (SELECT * FROM TMP_PACHETEOBJL) LOOP
      IF V_REC.CODPACHETEOBJL &gt; 0 THEN
        UPDATE PACHETEOBJL SET
          CODLIVR1     = V_REC.CODLIVR1,
          CANT         = V_REC.CANT,
          REST         = V_REC.REST,
          CANTUM1      = V_REC.CANTUM1,
          PACHET       = V_REC.PACHET,
          CODREZERVATS = V_REC.CODREZERVATS
        WHERE CODPACHETEOBJL = V_REC.CODPACHETEOBJL;
      ELSE
        INSERT INTO PACHETEOBJL (CODPACHETEOBJL, CODPACHETE, CODLIVR1, CANT, REST, CANTUM1, PACHET, CODREZERVATS)
        VALUES (SEQ_PACHETEOBJL_CODPACHETEOBJL.NEXTVAL, RECID, V_REC.CODLIVR1, V_REC.CANT, V_REC.REST, V_REC.CANTUM1, V_REC.PACHET, V_REC.CODREZERVATS);
      END IF;
    END LOOP;
  ELSE
    SELECT Seq_Pachete_CodPachete.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;PACHETE&apos;, RecId);
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PACHETE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO PACHETE ( CodPachete,
                          DataP,
                          Subunitate,
                          Gestiune,
                          CarnetDoc,
                          NrDoc,
                          Colector,
                          DataColectare,
                          Verificator,
                          DataVerificare,
                          Transportator,
                          DataTransport,
                          NrPachete,
                          Operat,
                          Blocat,
                          Anulat,
                          IdentificatorP,
                          Listat,
                          An,
                          Luna,
                          CodPart,
                          TipPart,
                          Sediu,
                          Delegat,
                          TipLivrare,
                          TipPachet,
                          UserID,
                          DataCreare,
                          Sponsorizare )
                ( SELECT  RecId,
                          DataP,
                          Subunitate,
                          Gestiune,
                          CarnetDoc,
                          NrDoc,
                          Colector,
                          DataColectare,
                          Verificator,
                          DataVerificare,
                          Transportator,
                          DataTransport,
                          NrPachete,
                          Operat,
                          Blocat,
                          Anulat,
                          IdentificatorP,
                          Listat,
                          An,
                          Luna,
                          CodPart,
                          TipPart,
                          Sediu,
                          Delegat,
                          coalesce(TipLivrare,3),
                          coalesce(tippachet,0),
                          pkg_globals.GETUSERID,
                          sysdate,
                          Sponsorizare
                     FROM TMP_PACHETE ) ;

    INSERT INTO PACHETE1 (CodPachete1,
                          CodPachete,
                          CodDoc,
                          TipDoc)
                  (SELECT Seq_Pachete1_CodPachete1.NextVal,
                          RecId,
                          CodDoc,
                          TipDoc
                   FROM TMP_PACHETE1);

    INSERT INTO PACHETEOBJ (CODPACHETEOBJ, CODPACHETE, CODNIRSTOC, CANT, REST)
    SELECT SEQ_PACHETEOBJ_CODPACHETEOBJ.NEXTVAL, RECID, CODNIRSTOC, CANT, REST
    FROM TMP_PACHETEOBJ;
    
    INSERT INTO PACHETEOBJL(CODPACHETEOBJL, CODPACHETE, CODLIVR1, CANT, REST, CANTUM1, PACHET, CODREZERVATS)
    SELECT SEQ_PACHETEOBJL_CODPACHETEOBJL.NEXTVAL, RECID, CODLIVR1, CANT, REST, CANTUM1, PACHET, CODREZERVATS
    FROM TMP_PACHETEOBJL;
  END IF;

  UPDATE PACHETEOBJ POBJ
  SET
   REST = CANT -
          (SELECT coalesce(SUM(PL.CANT), 0)
           FROM
            PACHETELINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          ) -
          (SELECT coalesce(SUM(PL.CANT), 0)
           FROM
            PACHETEDLLINK PL
           WHERE
           PL.CODPACHETEOBJ = POBJ.CODPACHETEOBJ
          )
  WHERE
    POBJ.CODPACHETE = RECID;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANUMARDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(aCarnetDoc, aNumarDoc);

  NotifyModif(Operation, RecId, &apos;PACHETE&apos;);
  -- mColet     --&gt;  77
  PKG_CFGTABLES.EXT_POSTRECORDS(77);
  COMMIT;
END;

procedure UpdateVerifFactDL(RecID in number) is
begin
  for v_rec in (select distinct dl1.codcomanda
                from pacheteobjl po
                     inner join rezervats r on po.codrezervats = r.codrezervats
                     inner join comanda1 dl1 on dl1.codcomanda1 = r.codcomanda1
                where po.codpachete = recid
               ) loop
    update comanda set verificat = 1, facturabil = 1 where codcomanda = v_rec.codcomanda;             
  end loop;
  commit;                   
end;  

end pkg_pachete; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PACKING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF8D9DEEFA2DC81829C707C0F5D230E9A2A28E7D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PACKING IS

gCodDoc number(20);
gTipDoc number(20);

PROCEDURE SET_VARIABILE(aCodDoc in number , aTipDoc in number,  aCodDetaliu  out number) is
begin
  gCodDoc := aCodDoc;
  gTipDoc := aTipDoc;

  
  BEGIN
    SELECT CODPACKING into aCODDETALIU FROM PACKING
    WHERE
      CODDOC = aCODDOC
      AND TIPDOC = aTIPDOC;
    EXCEPTION WHEN OTHERS THEN
      aCODDETALIU := 0;    
  END;  

  IF aCodDetaliu = 0 THEN
    aCODDETALIU := SEQ_PACKING_CODPACKING.NEXTVAL;
    INSERT INTO PACKING (CODPACKING, CODDOC, TIPDOC )
    VALUES(aCODDETALIU, aCodDoc, aTipDoc);
    commit;
  END IF; 
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
begin
 --todo
 NotifyModif(2, RecId, &apos;PACKING&apos;);
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  DELETE FROM PACKING3 P3 WHERE P3.CODPACKING2 IN 
         (SELECT P2.CODPACKING2  FROM PACKING2 P2 WHERE P2.CODPACKING1 IN (SELECT P1.CODPACKING1 
                                                                                             FROM PACKING P JOIN PACKING1 P1 ON P1.CODPACKING = P.CODPACKING  
                                                                                             WHERE P.CODPACKING = RECID));

  DELETE FROM PACKING2 P2 WHERE P2.CODPACKING1 IN (SELECT P1.CODPACKING1 
                                                                                             FROM PACKING P JOIN PACKING1 P1 ON P1.CODPACKING = P.CODPACKING  
                                                                                             WHERE  P.CODPACKING = RECID);
  DELETE FROM PACKING1 P1 WHERE P1.CODPACKING IN (SELECT P.CODPACKING FROM PACKING P WHERE  P.CODPACKING = RECID);
  DELETE FROM PACKING P WHERE P.CODPACKING = RECID;

    
  NotifyModif(2, RecId, &apos;PACKING&apos;);
  COMMIT;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO tmp_packing(codpacking) VALUES (0);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
  nrRows NUMBER;
BEGIN
  delete from TMP_PACKING;
  delete from TMP_PACKING1; 
  delete from TMP_PACKING2;
  delete from TMP_PACKING3;  
  
  INSERT INTO  TMP_PACKING (CODPACKING, CODDOC, TIPDOC, OBS, dirty)
      SELECT CODPACKING, CODDOC, TIPDOC, OBS, dirty from PACKING 
      WHERE CODPACKING = RecId;

  INSERT INTO TMP_PACKING1
    (CODPACKING1,
     CODPACKING,
     CODDOC1,
     CODOBIECT,
     CODAMB_PRIMAR,
     CODAMB_SECUNDAR,
     CODAMB_TERTIAR,
     CANTAMB,
     CANTAMBXPRIMAR,
     CANTAMBXSECUNDAR,
     CANTAMBXTERTIAR,
     CANTOBJ,
     DENAMB_PRIMAR,
     DENAMB_SECUNDAR,
     DENAMB_TERTIAR,
     DENOBIECT,
     CANTXPRIMAR,
     NR_RANDXPRIMAR,
     CANTRANDXPRIMAR,
     CANTXSECUNDAR,
     NR_RANDXSECUNDAR,
     CANTRANDXSECUNDAR,
     CANTXTERTIAR,
     NR_RANDXTERTIAR,
     CANTRANDXTERTIAR)
    SELECT pk1.CODPACKING1,
           pk1.CODPACKING,
           pk1.CODDOC1,
           pk1.CODOBIECT,
           pk1.CODAMB_PRIMAR,
           pk1.CODAMB_SECUNDAR,
           pk1.CODAMB_TERTIAR,
           pk1.CANTAMB,
           pk1.CANTAMBXPRIMAR,
           pk1.CANTAMBXSECUNDAR,
           pk1.CANTAMBXTERTIAR,
           pk1.CANTOBJ,
           nobj_amb_primar.DENUMIRE,
           nobj_amb_secundar.DENUMIRE,
           nobj_amb_tertiar.DENUMIRE,
           nobj.DENUMIRE,
           namb_primar.CANT,
           namb_primar.NR_RANDURI ,
           case when coalesce(namb_primar.CANT,0) &lt;&gt; 0 then ceil(namb_primar.CANT/coalesce(namb_primar.NR_RANDURI,1)) else null end,
           namb_secundar.CANT,
           namb_secundar.NR_RANDURI,
           case when coalesce(namb_secundar.CANT,0) &lt;&gt; 0 then ceil(namb_secundar.CANT/coalesce(namb_secundar.NR_RANDURI,1)) else null end,
           namb_tertiar.CANT,
           namb_tertiar.NR_RANDURI,
           case when coalesce(namb_tertiar.CANT,0) &lt;&gt; 0 then ceil(namb_tertiar.CANT/coalesce(namb_tertiar.NR_RANDURI,1)) else null end
      from PACKING1 pk1
      join PACKING pk on pk.CODPACKING = pk1.CODPACKING
      left join NARTAMB namb_primar on namb_primar.CODAMB = pk1.CODAMB_PRIMAR
      left join NARTAMB namb_secundar on namb_secundar.CODAMB = pk1.CODAMB_SECUNDAR
      left join NARTAMB namb_tertiar on namb_tertiar.CODAMB = pk1.CODAMB_TERTIAR
      left join NARTOBJ  nobj on nobj.CODOBIECT = pk1.CODOBIECT
      left join NARTOBJ nobj_amb_primar on nobj_amb_primar.CODOBIECT = namb_primar.CODOBIECTRETURN
      left join NARTOBJ nobj_amb_secundar on nobj_amb_secundar.CODOBIECT = namb_secundar.CODOBIECTRETURN
      left join NARTOBJ nobj_amb_tertiar on nobj_amb_tertiar.CODOBIECT = namb_tertiar.CODOBIECTRETURN
      WHERE PK.CODPACKING = RecId;
      --din contracte
      IF gTipDoc IN (27,34) THEN
        UPDATE TMP_PACKING1 tpk1 
               set CANTCOMANDA = ( SELECT ctr1.CANT * coalesce(u1.paritate,1)
                                                        FROM CONTRACT1 ctr1 
                                                            JOIN NUM1 u1 ON u1.CodUM1 = ctr1.UmSec
                                                        WHERE ctr1.CODCONTRACT1 = tpk1.CODDOC1 and ctr1.codobiect = tpk1.codobiect );
        -- adauga inregistrarile noi
         nrRows := -1;
        FOR v_rec IN (SELECT ctr1.CODCONTRACT1, ctr1.CODOBIECT, nobj.DENUMIRE ,ctr1.CANT * coalesce(u1.PARITATE,1) AS cantcmd
                             FROM CONTRACT ctr 
                               JOIN CONTRACT1 ctr1 on ctr1.CODCONTRACT = ctr.CODCONTRACT 
                               JOIN NUM1 u1 ON u1.CODUM1 = ctr1.UMSEC
                               JOIN NARTOBJ  nobj on nobj.CODOBIECT = ctr1.CODOBIECT
                             where ctr.CODCONTRACT = gCodDoc and ctr.tipdoc = gTipDoc) LOOP
        update tmp_packing1 tpk1 set deleted = 0 where tpk1.coddoc1 = v_rec.CODCONTRACT1 and tpk1.codobiect = v_rec.codobiect ;
        IF sql%rowcount = 0 THEN 
           INSERT INTO tmp_packing1(CODPACKING1,
                                                     CODPACKING,
                                                     CODDOC1,
                                                     CODOBIECT,
                                                     CANTOBJ,
                                                     DENOBIECT,
                                                     CANTCOMANDA,
                                                     DELETED)
           VALUES(nrRows, RecId, v_rec.CODCONTRACT1, v_rec.CODOBIECT, v_rec.CANTCMD, v_rec.DENUMIRE, v_rec.CANTCMD, 0);
            nrRows := nrRows - 1;
         END IF;
        END LOOP;  
        
        UPDATE TMP_PACKING1 SET DELETED = 1 WHERE DELETED IS NULL;          
      END IF;
      
      -- daca sunt comenzi
      IF gTipDoc IN (18) THEN
        UPDATE TMP_PACKING1 tpk1 
               set CANTCOMANDA = ( SELECT c1.CANTACCEPTAT * coalesce(u1.paritate,1) 
                                                        FROM COMANDA1 c1 
                                                            JOIN NUM1 u1 ON u1.CodUM1 = c1.UmSec
                                                        WHERE c1.CODCOMANDA1 = tpk1.CODDOC1 and c1.codobiect = tpk1.codobiect );
        -- adauga inregistrarile noi
         nrRows := -1;
        FOR v_rec IN (SELECT cmd1.codcomanda1, cmd1.CODOBIECT, nobj.DENUMIRE ,cmd1.CANTACCEPTAT * coalesce(u1.PARITATE,1) AS cantcmd
                             FROM COMANDA cmd 
                               JOIN COMANDA1 cmd1 on cmd1.CODCOMANDA = cmd.CODCOMANDA 
                               JOIN NUM1 u1 ON u1.CODUM1 = cmd1.UMSEC
                               JOIN NARTOBJ  nobj on nobj.CODOBIECT = cmd1.CODOBIECT
                             where cmd.codcomanda = gCodDoc and cmd.tipdoc = gTipDoc) LOOP
        update tmp_packing1 tpk1 set deleted = 0 where tpk1.coddoc1 = v_rec.codcomanda1 and tpk1.codobiect = v_rec.codobiect ;
        IF sql%rowcount = 0 THEN 
           INSERT INTO tmp_packing1(CODPACKING1,
                                                     CODPACKING,
                                                     CODDOC1,
                                                     CODOBIECT,
                                                     CANTOBJ,
                                                     DENOBIECT,
                                                     CANTCOMANDA,
                                                     DELETED)
           VALUES(nrRows, RecId, v_rec.CODCOMANDA1, v_rec.CODOBIECT, v_rec.CANTCMD, v_rec.DENUMIRE, v_rec.CANTCMD, 0);
            nrRows := nrRows - 1;
         END IF;
        END LOOP;  
        
        UPDATE TMP_PACKING1 SET DELETED = 1 WHERE DELETED IS NULL;          
        
        INSERT INTO TMP_REZERVATS
                                              (CODREZERVATS,
                                               CODCOMANDA1,
                                               CODNIRSTOC,
                                               CODNIRSER,
                                               REST,
                                               UMSEC,
                                               CODCMDPRODMAT,
                                               REZERVATINI,
                                               CODOBIECT)
          SELECT CODREZERVATS,
                 CODCOMANDA1,
                 CODNIRSTOC,
                 CODNIRSER,
                 REST,
                 UMSEC,
                 CODCMDPRODMAT,
                 REZERVATINI,
                 CODOBIECT
            FROM REZERVATS rz
           WHERE rz.CODCOMANDA1 IN
                 (SELECT tpk1.CODDOC1 FROM TMP_PACKING1 tpk1);
                 
      END IF;
      INSERT INTO tmp_packing2 (
               CODPACKING2,                           
               CODPACKING1,                        
               SSCC,                       
               OBS,                        
               CODAMB_FINAL,
               DEN_AMB,
               CANTOBJ)
        SELECT pk2.codpacking2, 
                    pk2.codpacking1, 
                    pk2.sscc,
                    pk2.obs,
                    pk2.codamb_final,
                    nobj_amb_final.denumire,
                    pk2.CANTOBJ  
        FROM PACKING2 pk2                                    
        LEFT JOIN NARTAMB namb_final on namb_final.CODAMB = pk2.codamb_final
        LEFT JOIN NARTOBJ nobj_amb_final on nobj_amb_final.CODOBIECT = namb_final.CODOBIECTRETURN
        where pk2.codpacking1 in (select pk1.codpacking1 from tmp_packing1 pk1);
        
        INSERT INTO tmp_packing3 (
               CODPACKING3 ,                           
               CODPACKING2,                        
               CODREZERVATS, 
               CANT,
               UMSEC, 
               SERIE,
               CODSERIE)
        SELECT pk3.CODPACKING3, 
                    pk3.CODPACKING2, 
                    pk3.CODREZERVATS,
                    pk3.CANT,
                    pk3.UMSEC,
                    ns.SERIE,
                    ns.CODSERIE
        FROM PACKING3 pk3                   
        left join rezervats rez on rez.codrezervats = pk3.codrezervats
        left join nirser nrsr
               on nrsr.codnirser = rez.codnirser
        left join nserii ns
               on ns.codserie = nrsr.codserie
        where pk3.codpacking2 in (select pk2.codpacking2 from tmp_packing2 pk2);
        
        update tmp_packing2 pk2 set pk2.rest = pk2.cantobj 
                                               - coalesce((SELECT sum(pk3.CANT) as consum 
                                                         FROM tmp_packing3 pk3 where pk3.CODPACKING2 = pk2.codpacking2 group by pk3.CODPACKING2), 0) ;
        

--   updateDetalii(gCodDoc,  gTipDoc);   
   commit;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  
vCodPack1 number(20);
vCodPack2 number(20);
BEGIN	
  SELECT CODPACKING INTO RecId FROM TMP_PACKING;
  -- golesc randurile fara date
  DELETE FROM TMP_PACKING3 pkg3 WHERE pkg3.CODPACKING2 in 
         (SELECT pkg2.CODPACKING2 FROM TMP_PACKING2 pkg2 WHERE (pkg2.SSCC IS NULL or LENGTH(pkg2.SSCC) &lt; 1) 
                                                                                                                                                AND  (pkg2.OBS IS NULL OR LENGTH(pkg2.OBS) &lt; 1))
         OR COALESCE(pkg3.CODREZERVATS,0) = 0 ; 
         
  DELETE FROM TMP_PACKING2 pkg2 WHERE (pkg2.SSCC is null or LENGTH(pkg2.SSCC) &lt; 1) AND  (pkg2.OBS IS NULL OR LENGTH(pkg2.OBS) &lt; 1);
 	
   --clean
   DELETE FROM PACKING3 PK3 WHERE PK3.CODPACKING2 IN
                (SELECT PK2.CODPACKING2 FROM PACKING2 PK2 
                       JOIN PACKING1 PK1 ON PK1.CODPACKING1 = PK2.CODPACKING1 
                WHERE PK1.CODPACKING = RecId); 

    DELETE FROM PACKING2 PK2 WHERE pk2.codpacking1 in 
                                        (SELECT pk1.codpacking1 
                                         FROM PACKING1 pk1 
                                         where pk1.CODPACKING = RecId);
                                               
       DELETE FROM PACKING1 pk1 
              WHERE pk1.CODPACKING1 NOT IN (SELECT tpk1.CODPACKING1 FROM TMP_PACKING1 tpk1)
                          AND pk1.CODPACKING = RecId; 
       --PACKING                   
       UPDATE PACKING pk
            set (CODPACKING, CODDOC, TIPDOC, OBS, DIRTY) =
                (select CODPACKING, CODDOC, TIPDOC, OBS, 0 from TMP_PACKING)
         WHERE pk.CODPACKING = RecId ;
       --PACKING1  - UPDATE
       UPDATE PACKING1 PK1
                SET  (CODOBIECT, CODAMB_PRIMAR, CODAMB_SECUNDAR, CODAMB_TERTIAR, 
                                                CANTAMB, CANTAMBXPRIMAR, CANTAMBXSECUNDAR, CANTAMBXTERTIAR, CANTOBJ ) = 
                                 (SELECT CODOBIECT, 
                                                CASE WHEN CODAMB_PRIMAR &lt;&gt; 0 THEN CODAMB_PRIMAR ELSE NULL END,
                                                CASE WHEN CODAMB_SECUNDAR &lt;&gt; 0 THEN CODAMB_SECUNDAR ELSE NULL END, 
                                                CASE WHEN CODAMB_TERTIAR &lt;&gt; 0 THEN CODAMB_TERTIAR ELSE NULL END, 
                                                 CANTAMB, CANTAMBXPRIMAR, CANTAMBXSECUNDAR, CANTAMBXTERTIAR, CANTOBJ 
                                 FROM TMP_PACKING1 tpk1
                                 WHERE tpk1.CODPACKING1 &gt; 0 and tpk1.CODPACKING1 = pk1.CODPACKING1) 
         WHERE pk1.codpacking = RecId;

         FOR V_RECP IN (SELECT * FROM TMP_PACKING1 tpk1 WHERE tpk1.CODPACKING1 &lt; 0) LOOP
             vCodPack1 := SEQ_PACKING1_CODPACKING1.NEXTVAL;
             UPDATE TMP_PACKING2 tpk2 SET CODPACKING1 = vCodPack1 WHERE tpk2.CODPACKING1 = V_RECP.CODPACKING1;
             INSERT INTO PACKING1 (CODPACKING1, CODPACKING, CODDOC1, CODOBIECT, CODAMB_PRIMAR, 
                                                   CODAMB_SECUNDAR, CODAMB_TERTIAR, CANTAMB,
                                                   CANTAMBXPRIMAR, CANTAMBXSECUNDAR, CANTAMBXTERTIAR, CANTOBJ) 
             VALUES (vCodPack1, 
                          RecId,
                          V_RECP.CODDOC1, 
                          V_RECP.CODOBIECT, 
                          CASE WHEN V_RECP.CODAMB_PRIMAR &lt;&gt; 0 THEN V_RECP.CODAMB_PRIMAR ELSE NULL END,
                          CASE WHEN V_RECP.CODAMB_SECUNDAR &lt;&gt; 0 THEN V_RECP.CODAMB_SECUNDAR ELSE NULL END, 
                          CASE WHEN V_RECP.CODAMB_TERTIAR &lt;&gt; 0 THEN V_RECP.CODAMB_TERTIAR ELSE NULL END, 
                          V_RECP.CANTAMB,
                          V_RECP.CANTAMBXPRIMAR, V_RECP.CANTAMBXSECUNDAR, V_RECP.CANTAMBXTERTIAR, V_RECP.CANTOBJ) ;
         END LOOP;
         
         FOR V_RECP2 IN (SELECT * FROM TMP_PACKING2 tpk2 WHERE tpk2.CODPACKING2 &lt; 0) LOOP 
            vCodPack2 := SEQ_PACKING2_CODPACKING2.NEXTVAL;
            UPDATE TMP_PACKING3 tpk3 SET CODPACKING2 = vCodPack2 WHERE tpk3.CODPACKING2 = V_RECP2.CODPACKING2; 
            UPDATE TMP_PACKING2 tpk2 SET CODPACKING2 = vCodPack2 WHERE tpk2.CODPACKING2 =  V_RECP2.CODPACKING2;     
         END LOOP;
         --PACKING2  - INSERT (initial au fost toate sterse)
         INSERT INTO PACKING2 (CODPACKING2, CODPACKING1, SSCC, OBS, CODAMB_FINAL, CANTOBJ) 
                SELECT  tpk2.codpacking2, 
                        tpk2.codpacking1 ,
                        tpk2.sscc, 
                        tpk2.obs, 
                        tpk2.codamb_final,
                        tpk2.CANTOBJ
               FROM TMP_PACKING2 tpk2;
           
          --PACKING3  - INSERT (initial au fost toate sterse)    
          UPDATE TMP_PACKING3 TPK3 SET CODPACKING3 = SEQ_PACKING3_CODPACKING3.NEXTVAL WHERE TPK3.CODPACKING3 &lt; 0;     
          INSERT INTO PACKING3 (
               CODPACKING3 ,                           
               CODPACKING2,                        
               CODREZERVATS, 
               CANT,
               UMSEC)
           SELECT tpk3.CODPACKING3, 
                    tpk3.CODPACKING2, 
                    tpk3.CODREZERVATS,
                    tpk3.CANT,
                    tpk3.UMSEC
            FROM TMP_PACKING3 tpk3; 
    COMMIT;       
 END; 
 
 PROCEDURE SET_DIRTY(aCodDoc in number , aTipDoc in number,  aFlag  in number) is
   vCodPacking number(20,0);
 BEGIN
   BEGIN
     SELECT CODPACKING into vCodPacking 
     FROM PACKING
     WHERE
        CODDOC = aCODDOC
        AND TIPDOC = aTIPDOC;
     EXCEPTION WHEN OTHERS THEN
        vCodPacking := 0; 
   END;      
   IF vCodPacking &lt;&gt; 0 THEN
    UPDATE PACKING SET DIRTY = aFlag WHERE CODPACKING = vCodPacking;
    COMMIT;
  END IF; 
end; 

end PKG_PACKING; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4ADCB5CA4F7FFF544ED611E9C024C8122B968CCA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PARTICIP is
PROCEDURE SP_GOTORECORD
IS
BEGIN
  DELETE TMP_PARTICIP;
  INSERT INTO TMP_PARTICIP SELECT * FROM PARTICIP;
  COMMIT;
END;  

PROCEDURE SP_POSTRECORDS
IS
BEGIN
  DELETE FROM PARTICIP WHERE COD NOT IN (SELECT COD FROM TMP_PARTICIP WHERE COD &gt; 0); 
  FOR V_REC IN (SELECT * FROM TMP_PARTICIP)
  LOOP
     IF V_REC.COD &gt; 0 THEN
       UPDATE PARTICIP
       SET
         DENUMIRE = V_REC.DENUMIRE,
         PROCENT  = V_REC.PROCENT 
       WHERE
         COD = V_REC.COD;  
     ELSE
       INSERT INTO PARTICIP(COD, DENUMIRE, PROCENT)
       VALUES (SEQ_PARTICIP_COD.NEXTVAL, V_REC.DENUMIRE, V_REC.PROCENT);
     END IF;    
  END LOOP;
  COMMIT;    
END;  
end PKG_PARTICIP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PERISABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2B4C10894048F401D2DE10954DD44B8AAECA061</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PERISABIL IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
   TMP NUMBER(20);
  BEGIN
    SELECT CODPERISABIL INTO TMP FROM PERISABIL WHERE CODPERISABIL = RECID FOR UPDATE NOWAIT;
  END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  BEGIN
    DELETE FROM PERISABIL1  WHERE CODPERISABIL = RECID;
    DELETE FROM PERISABIL2  WHERE CODPERISABIL = RECID;
    DELETE FROM PERISABIL  WHERE CODPERISABIL = RECID;
    
    NotifyModif(2, RecId, &apos;PERISABIL&apos;);
    
    COMMIT;
  END;

PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_PERISABIL (CODPERISABIL) VALUES(0);
    INSERT INTO TMP_PERISABIL1 (CODPERISABIL1,Luna_Ini) VALUES(0,1);
    COMMIT;
  END;
  
PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
  BEGIN
    INSERT INTO TMP_PERISABIL(CODPERISABIL,DENUMIRE,OBS) 
     SELECT CODPERISABIL,DENUMIRE,OBS FROM PERISABIL WHERE CODPERISABIL = RECID;
    
    INSERT INTO TMP_PERISABIL1(CODPERISABIL1,CODPERISABIL,LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1)
      SELECT CODPERISABIL1,CODPERISABIL,LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1 FROM PERISABIL1 WHERE CODPERISABIL = RECID;
    INSERT INTO TMP_PERISABIL2(CODPERISABIL2,CODPERISABIL,LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1)
      SELECT CODPERISABIL2,CODPERISABIL,LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1 FROM PERISABIL2 WHERE CODPERISABIL = RECID;
   COMMIT;
  END;
  
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  BEGIN
    IF OPERATION = 0 THEN -- UPDATE
      SELECT CODPERISABIL INTO RECID FROM TMP_PERISABIL;
      
      UPDATE PERISABIL SET(DENUMIRE,OBS) = 
        (SELECT DENUMIRE,OBS FROM TMP_PERISABIL)
      WHERE CODPERISABIL = RECID;
      
      DELETE FROM PERISABIL1 P1 WHERE P1.CODPERISABIL = RECID AND NOT EXISTS
       (SELECT TMP.CODPERISABIL1 FROM TMP_PERISABIL1 TMP WHERE TMP.CODPERISABIL1 = P1.CODPERISABIL1);
      DELETE FROM PERISABIL2 P2 WHERE P2.CODPERISABIL = RECID AND NOT EXISTS
       (SELECT TMP.CODPERISABIL2 FROM TMP_PERISABIL2 TMP WHERE TMP.CODPERISABIL2 = P2.CODPERISABIL2);
      
      FOR V_REC IN (SELECT * FROM TMP_PERISABIL1) LOOP
        UPDATE PERISABIL1 P1 SET
          P1.LUNA_INI = V_REC.LUNA_INI,
          P1.LUNA_FIN = V_REC.LUNA_FIN,
          P1.NrZile   = V_REC.NrZile,
          P1.NrZileDir= V_REC.NrZileDir,
          P1.OBS1     = V_REC.OBS1
       WHERE P1.CODPERISABIL1 = V_REC.CODPERISABIL1   ;
      END LOOP; 
      
      INSERT INTO PERISABIL1(CODPERISABIL1,CODPERISABIL,LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1)
       SELECT SEQ_PERISABIL1_CODPERISABIL1.NEXTVAL,RECID,LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1 FROM TMP_PERISABIL1 WHERE CODPERISABIL1 &lt; 0  ;
        
      FOR V_REC IN (SELECT * FROM TMP_PERISABIL2) LOOP
        UPDATE PERISABIL2 P2 SET
          P2.LUNA_INI  = V_REC.LUNA_INI,
          P2.LUNA_FIN  = V_REC.LUNA_FIN,
          P2.ZI_INI    = V_REC.ZI_INI,
          P2.ZI_FIN    = V_REC.ZI_FIN,
          P2.StocMediu = V_REC.StocMediu,  
          P2.TIPSEZON  = V_REC.TIPSEZON,
          P2.OBS1      = V_REC.OBS1
       WHERE P2.CODPERISABIL2 = V_REC.CODPERISABIL2   ;
      END LOOP; 

      INSERT INTO PERISABIL2(CODPERISABIL2,CODPERISABIL,LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1)
       SELECT SEQ_PERISABIL2_CODPERISABIL2.NEXTVAL,RECID,LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1 FROM TMP_PERISABIL2 WHERE CODPERISABIL2 &lt; 0  ;
      
        
    ELSE -- INSERT
     SELECT SEQ_PERISABIL_CODPERISABIL.NEXTVAL INTO RECID FROM DUAL;
     
     INSERT INTO PERISABIL(CODPERISABIL,DENUMIRE,OBS)
      SELECT RECID,DENUMIRE,OBS  FROM TMP_PERISABIL;
      
     INSERT INTO PERISABIL1(CODPERISABIL1,CODPERISABIL,LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1)
      SELECT SEQ_PERISABIL1_CODPERISABIL1.NEXTVAL, RECID,  LUNA_INI,LUNA_FIN,NrZile, NrZileDir,OBS1 FROM TMP_PERISABIL1;
     INSERT INTO PERISABIL2(CODPERISABIL2,CODPERISABIL,LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1)
      SELECT SEQ_PERISABIL2_CODPERISABIL2.NEXTVAL, RECID,  LUNA_INI, ZI_INI,LUNA_FIN, ZI_FIN,StocMediu,  TIPSEZON,OBS1 FROM TMP_PERISABIL2;
    END IF;
    
    NotifyModif(Operation, RecId, &apos;PERISABIL&apos;);
    
    COMMIT;
  END;  
end PKG_PERISABIL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4C141F9BB3F45A357E789CDB30ADAA9B02B944A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_perscontact IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_52&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODPERSC INTO Tmp FROM NPERSCONTACT WHERE CODPERSC = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
   SELECT &apos;Pers.contact. &quot;&apos;||nume||&apos; &apos;||prenume||&apos;&quot;&apos; INTO aDoc FROM NPERSCONTACT WHERE codpersc = recid;
   WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERSCONTACT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

	DELETE FROM NPERSCONTACT WHERE CODPERSC = RecId ;

  NotifyModif(2, RecId, &apos;NPERSCONTACT&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NPERSCONTACT FIELDS(CODPERSC) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NPERSCONTACT
  INSERT INTO TMP_NPERSCONTACT ( CODPERSC, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, IMPLICIT, Obs )
  SELECT CODPERSC, NUME, PRENUME, NVL(TELEFON,&apos;&apos;), NVL(EMAIL,&apos;&apos;), FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, Nvl(IMPLICIT,0), Obs
  FROM NPERSCONTACT WHERE CODPERSC = RecId ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
-- Master NPERSCONTACT
    SELECT CODPERSC INTO RecId FROM TMP_NPERSCONTACT;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Pers.contact. &quot;&apos;||nume||&apos; &apos;||prenume||&apos;&quot;&apos; INTO aDoc FROM NPERSCONTACT WHERE codpersc = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERSCONTACT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE NPERSCONTACT
    SET (CODPERSC, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, IMPLICIT, Obs)
       = (SELECT
            CODPERSC, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, IMPLICIT, Obs
          FROM TMP_NPERSCONTACT )
    WHERE CODPERSC = RecId ;

  ELSE  -- INSERT
-- Master NPERSCONTACT
    SELECT SEQ_NPERSCONTACT_CODPERSC.NextVal INTO RecId FROM DUAL;

    INSERT INTO  NPERSCONTACT (
      CODPERSC, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, IMPLICIT, Obs)
    SELECT
      RecId,    NUME, PRENUME, TELEFON, EMAIL, FUNCTIE, DATANASTERE, RZONA, ID, TIP, CODBANKCONT, CODPART, IMPLICIT, Obs
    FROM TMP_NPERSCONTACT ;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Pers.contact. &quot;&apos;||nume||&apos; &apos;||prenume||&apos;&quot;&apos; INTO aDoc FROM NPERSCONTACT WHERE codpersc = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NPERSCONTACT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

  END IF;

  NotifyModif(Operation, RecId, &apos;NPERSCONTACT&apos;);

  COMMIT;

END;

END PKG_PERSCONTACT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FC19CF1991E35971E9741D6BCE9EE81AA819296</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PGS IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT codPGS INTO Tmp FROM PGS WHERE codPGS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM PGS1 WHERE codPGS = RecId ;
  DELETE FROM PGS  WHERE codPGS = RecId ;
  NotifyModif(2, RecId, &apos;PGS&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_PGS FIELDS( codPGS ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master CURSURI
  INSERT INTO  TMP_PGS ( codPGS, Denumire )
    ( SELECT codPGS, Denumire
    FROM PGS WHERE codPGS = RecId ) ;

  INSERT INTO  TMP_PGS1 ( codPGS1, codPGS,IndexLocal,CodCurs, CodTema )
    ( SELECT codPGS1, codPGS,IndexLocal,CodCurs, CodTema
      FROM PGS1 WHERE codPGS = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT codPGS INTO RecId FROM TMP_PGS;

    UPDATE PGS SET ( Denumire )
                       = ( SELECT Denumire FROM TMP_PGS )
    WHERE codPGS = RecId ;

    DELETE FROM PGS1 where codPGS = RecId and codPGS1 not in (Select codPGS1 from TMP_PGS1);
    FOR v_rec IN ( SELECT * FROM TMP_PGS1 WHERE codPGS1 &gt; 0 ) LOOP
       UPDATE PGS1
       SET
            INDEXLOCAL  = V_REC.INDEXLOCAL,
            CODCURS     = V_REC.CODCURS
       WHERE codPGS1  = v_rec.codPGS1;
    END LOOP;

    INSERT INTO PGS1
    ( codPGS1, codPGS, IndexLocal,CodCurs, CodTema)
    SELECT SEQ_PGS1_codPGS1.Nextval , RecId , IndexLocal, CodCurs, CodTema
    FROM TMP_PGS1 WHERE codPGS1 &lt; 0;


  ELSE  -- INSERT

    SELECT Seq_PGS_codPGS.NextVal INTO RecId FROM DUAL;

    INSERT INTO  PGS ( codPGS, Denumire )
              ( SELECT  RecId , Denumire
                FROM Tmp_PGS ) ;

    INSERT INTO PGS1
    ( codPGS1, codPGS, IndexLocal,CodCurs, CodTema)
    SELECT SEQ_PGS1_codPGS1.Nextval , RecId , IndexLocal, CodCurs, CodTema
    FROM TMP_PGS1;

  END IF;
  NotifyModif(Operation, RecId, &apos;PGS&apos;);
  COMMIT;

END;



END PKG_PGS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PIPE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48EC8D77DC024F9532A454E0F1152DC321475CF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PIPE is

procedure SEND_PIPE_MESSAGE(NUME_PIPE IN VARCHAR2, MESAJ IN VARCHAR2)
IS
RES NUMBER;
BEGIN
  EXECUTE IMMEDIATE &apos;BEGIN SYS.DBMS_PIPE.PACK_MESSAGE(&apos;&apos;&apos; || MESAJ ||&apos;&apos;&apos;); END;&apos;; 
  EXECUTE IMMEDIATE &apos; DECLARE RES NUMBER; BEGIN RES := SYS.DBMS_PIPE.SEND_MESSAGE(&apos;&apos;&apos; || NUME_PIPE ||&apos;&apos;&apos;); END; &apos;;
END;    


end PKG_PIPE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANCONTSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCAF2ED1B33F1E847AFC911F195329F54C964C5B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANCONTSEC IS

FUNCTION GET_CONT_COD_CARACT_LUNA(aCODCONTS IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
 aCODCONTS1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT NVL( Max(CODCONTS1) KEEP (Dense_Rank LAST ORDER BY AnStart, LunaStart), 0) INTO aCODCONTS1
    FROM NCONTS1
    WHERE CODCONTS = aCODCONTS AND ANSTART * 12 + LUNASTART &lt;= aAN * 12 + aLUNA;
  EXCEPTION
    WHEN OTHERS THEN RETURN -1;
  END;
  RETURN aCODCONTS1;
END;

PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER)
IS
BEGIN
  INITIALIZARI := FLAG;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodContS INTO Tmp FROM NCONTS WHERE CodContS = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomPlanConturiS --&gt; 525
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 525);
  delete from ncontS1 where codcontS = recid;
	DELETE FROM NCONTS WHERE CodContS = RecId ;
  COMMIT;
  
  NotifyModif(2, RecId, &apos;NCONTS&apos;);
  
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCONTS FIELDS( CodContS ) VALUES (0) ;
  -- nomPlanConturiS --&gt; 525
  PKG_CFGTABLES.EXT_INSERTRECORD(525); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT NUMBER(4);
aLUNASFARSIT NUMBER(2);
BEGIN
  -- Master NCONTS
  INSERT INTO TMP_NCONTS ( CodContS,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
  SELECT CodContS,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte
  FROM NCONTS WHERE CodContS = RecId;

  INSERT INTO TMP_NCONTS1 ( CodContS1,CodContS,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart )
  SELECT CodContS1,CodContS,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart
  FROM NCONTS1 WHERE CodContS = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODCONTS1, ANSTART, LUNASTART FROM TMP_NCONTS1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NCONTS1
      SET ANSFARSIT   = aANSFARSIT,
          LUNASFARSIT = aLUNASFARSIT
      WHERE CODCONTS1 = V_REC.CODCONTS1;
    END IF;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

  g_CodContS1 := NVL(g_CodContS1,0);

  -- Detail NCONTSOLDS
  INSERT INTO TMP_NCONTSOLDS ( CodContSoldS,CodContS,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna )
  SELECT CodContSoldS,CodContS,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna
  FROM NCONTSOLDS WHERE CodContS = RecId AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;

  SELECT MAX(NVL(CodContSoldS,0)) INTO g_CodContSoldS FROM NCONTSOLDS WHERE CodContS = RecId ;

  g_CodContSoldS := NVL(g_CodContSoldS,0);

  -- Detail NCONTRULS
  INSERT INTO TMP_NCONTRULS ( CodcontrulS, CodContS,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna )
  SELECT CodcontrulS,CodContS,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna
  FROM NCONTRULS WHERE CodContS = RecId AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;

  SELECT MAX(NVL(CodcontrulS,0)) INTO g_CodcontrulS FROM NCONTRULS WHERE CodContS = RecId ;

  g_CodcontrulS := NVL(g_CodcontrulS,0);
  -- nomPlanConturiS --&gt; 525
  PKG_CFGTABLES.EXT_GOTORECORD(525); 
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  -- nomPlanConturiS --&gt; 525
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (525); 
  IF Operation = 0 THEN  -- UPDATE

    -- Master NCONTS
    SELECT  CodContS INTO RecId FROM TMP_NCONTS;
    UPDATE NCONTS
    SET ( Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
      = ( SELECT Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte FROM TMP_NCONTS )
    WHERE CodContS = RecId ;

    -- Detail NCONTS1
    DELETE FROM NCONTS1 where CodContS = RecId and CodContS1 not in (Select CodContS1 from TMP_NCONTS1);

    INSERT INTO NCONTS1 ( CodContS1,CodContS,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart )
    SELECT  seq_NCONTS1_CodContS1.Nextval , RecId ,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart
    FROM TMP_NCONTS1 WHERE CodContS1 &lt; 0;

    FOR V_REC IN ( SELECT * FROM TMP_NCONTS1 WHERE NVL(CodContS1,-1) &gt; 0 ORDER BY CodContS1 ) LOOP
      UPDATE NCONTS1
      SET
        NRANALITICE    = v_rec.NrAnalitice,
        ContTransfD    = v_rec.ContTransfD,
        ContTransfC    = v_rec.ContTransfC,
        ContInkidSold  = v_rec.ContInkidSold,
        Participatiune = v_rec.Participatiune,
        Sincronizare   = v_rec.Sincronizare,
				CodCont        = v_rec.CodCont
      WHERE CodContS1 = v_rec.CodContS1;
    END LOOP;

    IF INITIALIZARI = 1 THEN
      -- Detail NCONTSOLD
      FOR V_REC IN ( SELECT * FROM TMP_NCONTSOLDS ) LOOP
        IF V_REC.CODCONTSOLDS &lt; 0 THEN
          INSERT INTO NCONTSOLDS (CodContSoldS, SoldID, SoldIC, SoldVID, SoldVIC, CodContS, An, Luna )
          VALUES (SEQ_NCONTSOLDS_CodContSoldS.Nextval, V_REC.SoldID, V_REC.SoldIC, V_REC.SoldVID, V_REC.SoldVIC, RecId , V_REC.An, V_REC.Luna);
        ELSE
          UPDATE NCONTSOLDS
          SET
            SoldID  = V_REC.SOLDID,
            SoldIC  = V_REC.SOLDIC,
            SoldVID = V_REC.SOLDVID,
            SoldVIC = V_REC.SOLDVIC
          WHERE CODCONTSOLDS = V_REC.CODCONTSOLDS;
        END IF;
      END LOOP;

      -- Detail NCONTRUL
      FOR V_REC IN (SELECT * FROM TMP_NCONTRULS) LOOP
        IF V_REC.CODCONTRULS &lt; 0 THEN
          INSERT INTO NCONTRULS ( CodContRulS, RulajPD, RulajPC, CodContS, RulajCD, RulajCC, RulajVPD, RulajVPC, RulajVCD, RulajVCC, An, Luna )
          VALUES  (seq_NCONTRULS_CodContRulS.Nextval, V_REC.RulajPD, V_REC.RulajPC, RecId, V_REC.RulajCD, V_REC.RulajCC, V_REC.RulajVPD,  V_REC.RulajVPC, V_REC.RulajVCD, V_REC.RulajVCC, V_REC.An, V_REC.Luna);
        ELSE
          UPDATE NCONTRULS
          SET
            RulajPD   = V_REC.RULAJPD,
            RulajPC   = V_REC.RULAJPC,
            RulajVPD  = V_REC.RULAJVPD,
            RulajVPC  = V_REC.RULAJVPC
          -- NU MA ATING DE RULAJELE CURENTE
          WHERE CODCONTRULS = V_REC.CODCONTRULS;
        END IF;
      END LOOP;
    END IF; -- initializari

  ELSE  -- INSERT
    -- Master NCONTS
    SELECT seq_NCONTS_CodContS.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NCONTS&apos;, RecId);
    INSERT INTO  NCONTS ( CodContS,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
    SELECT  RecId ,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte
    FROM TMP_NCONTS;

    -- Detail NCONTS1
    INSERT INTO  NCONTS1 ( CodContS1,CodContS,CodCont,NrAnalitice,Participatiune,Sincronizare,Conttransfd,Conttransfc,Continkidsold,anstart,lunastart )
    SELECT seq_NCONTS1_CodContS1.Nextval ,RecId,CodCont,NrAnalitice,Participatiune,Sincronizare,Conttransfd,Conttransfc,Continkidsold,anstart,lunastart
    FROM TMP_NCONTS1;

    -- Detail NCONTSOLDS
    INSERT INTO  NCONTSOLDS ( CodContSoldS,CodContS,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna )
    SELECT  seq_NCONTSOLDS_CodContSoldS.Nextval ,RecId,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna
    FROM TMP_NCONTSOLDS;

    -- Detail NCONTRULS
    INSERT INTO  NCONTRULS ( CodContrulS,CodContS,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna )
    SELECT  seq_NCONTRULS_CodContrulS.Nextval ,RecId,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna
    FROM TMP_NCONTRULS;

  END IF;
  
  PRC_AL_REFRESH(&apos;NCONTS1&apos;,  RecId);
   -- nomPlanConturiS --&gt; 525
  PKG_CFGTABLES.EXT_POSTRECORDS(525);
  NotifyModif(Operation, RecId, &apos;NCONTS&apos;);
  
  COMMIT;
END;



END PKG_PLANCONTSEC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANCONTTERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B556BD4ACA76194A939154D011EF13067EE3768</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANCONTTERT IS

FUNCTION GET_CONT_COD_CARACT_LUNA(aCodContT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
 aCodContT1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT NVL( Max(CodContT1) KEEP (Dense_Rank LAST ORDER BY AnStart, LunaStart), 0) INTO aCodContT1
    FROM NCONTT1
    WHERE CodContT = aCodContT AND ANSTART * 12 + LUNASTART &lt;= aAN * 12 + aLUNA;
  EXCEPTION
    WHEN OTHERS THEN RETURN -1;
  END;
  RETURN aCodContT1;
END;

PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER)
IS
BEGIN
  INITIALIZARI := FLAG;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodContT INTO Tmp FROM NCONTT WHERE CodContT = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  delete from ncontt1 where codcontt = recid;
	DELETE FROM NCONTT WHERE CodContT = RecId ;
  
  NotifyModif(2, RecId, &apos;NCONTT&apos;);
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NCONTT FIELDS( CodContT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aANSFARSIT NUMBER(4);
aLUNASFARSIT NUMBER(2);
BEGIN
  -- Master NCONTT
  INSERT INTO TMP_NCONTT ( CodContT,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
  SELECT CodContT,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte
  FROM NCONTT WHERE CodContT = RecId;

  INSERT INTO TMP_NCONTT1 ( CodContT1,CodContT,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart )
  SELECT CodContT1,CodContT,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart
  FROM NCONTT1 WHERE CodContT = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CodContT1, ANSTART, LUNASTART FROM TMP_NCONTT1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NCONTT1
      SET ANSFARSIT   = aANSFARSIT,
          LUNASFARSIT = aLUNASFARSIT
      WHERE CodContT1 = V_REC.CodContT1;
    END IF;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;

  g_CodContT1 := NVL(g_CodContT1,0);

  -- Detail NCONTSOLDT
  INSERT INTO TMP_NCONTSOLDT ( CodContSoldT,CodContT,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna )
  SELECT CodContSoldT,CodContT,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna
  FROM NCONTSOLDT WHERE CodContT = RecId AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;

  SELECT MAX(NVL(CodContSoldT,0)) INTO g_CodContSoldT FROM NCONTSOLDT WHERE CodContT = RecId ;

  g_CodContSoldT := NVL(g_CodContSoldT,0);

  -- Detail NCONTRULT
  INSERT INTO TMP_NCONTRULT ( CodContRulT, CodContT,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna )
  SELECT CodContRulT,CodContT,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna
  FROM NCONTRULT WHERE CodContT = RecId AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;

  SELECT MAX(NVL(CodContRulT,0)) INTO g_CodContRulT FROM NCONTRULT WHERE CodContT = RecId ;

  g_CodContRulT := NVL(g_CodContRulT,0);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    -- Master NCONTT
    SELECT  CodContT INTO RecId FROM TMP_NCONTT;
    UPDATE NCONTT
    SET ( Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
      = ( SELECT Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte FROM TMP_NCONTT )
    WHERE CodContT = RecId ;

    -- Detail NCONTT1
    DELETE FROM NCONTT1 where CodContT = RecId and CodContT1 not in (Select CodContT1 from TMP_NCONTT1);

    INSERT INTO NCONTT1 ( CodContT1,CodContT,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart )
    SELECT  seq_NCONTT1_CodContT1.Nextval , RecId ,NrAnalitice,ContTransfD,ContTransfC,ContInkidSold,Participatiune,Sincronizare, anstart, lunastart
    FROM TMP_NCONTT1 WHERE CodContT1 &lt; 0;

    FOR V_REC IN ( SELECT * FROM TMP_NCONTT1 WHERE NVL(CodContT1,-1) &gt; 0 ORDER BY CodContT1 ) LOOP
      UPDATE NCONTT1
      SET
        NRANALITICE    = v_rec.NrAnalitice,
        ContTransfD    = v_rec.ContTransfD,
        ContTransfC    = v_rec.ContTransfC,
        ContInkidSold  = v_rec.ContInkidSold,
        Participatiune = v_rec.Participatiune,
        Sincronizare   = v_rec.Sincronizare
      WHERE CodContT1 = v_rec.CodContT1;
    END LOOP;

    IF INITIALIZARI = 1 THEN
      -- Detail NCONTSOLD
      FOR V_REC IN ( SELECT * FROM TMP_NCONTSOLDT ) LOOP
        IF V_REC.CodContSoldT &lt; 0 THEN
          INSERT INTO NCONTSOLDT (CodContSoldT, SoldID, SoldIC, SoldVID, SoldVIC, CodContT, An, Luna )
          VALUES (SEQ_NCONTSOLDT_CodContSoldT.Nextval, V_REC.SoldID, V_REC.SoldIC, V_REC.SoldVID, V_REC.SoldVIC, RecId , V_REC.An, V_REC.Luna);
        ELSE
          UPDATE NCONTSOLDT
          SET
            SoldID  = V_REC.SOLDID,
            SoldIC  = V_REC.SOLDIC,
            SoldVID = V_REC.SOLDVID,
            SoldVIC = V_REC.SOLDVIC
          WHERE CodContSoldT = V_REC.CodContSoldT;
        END IF;
      END LOOP;

      -- Detail NCONTRUL
      FOR V_REC IN (SELECT * FROM TMP_NCONTRULT) LOOP
        IF V_REC.CodContRulT &lt; 0 THEN
          INSERT INTO NCONTRULT ( CodContRulT, RulajPD, RulajPC, CodContT, RulajCD, RulajCC, RulajVPD, RulajVPC, RulajVCD, RulajVCC, An, Luna )
          VALUES  (seq_NCONTRULT_CodContRulT.Nextval, V_REC.RulajPD, V_REC.RulajPC, RecId, V_REC.RulajCD, V_REC.RulajCC, V_REC.RulajVPD,  V_REC.RulajVPC, V_REC.RulajVCD, V_REC.RulajVCC, V_REC.An, V_REC.Luna);
        ELSE
          UPDATE NCONTRULT
          SET
            RulajPD   = V_REC.RULAJPD,
            RulajPC   = V_REC.RULAJPC,
            RulajVPD  = V_REC.RULAJVPD,
            RulajVPC  = V_REC.RULAJVPC
          -- NU MA ATING DE RULAJELE CURENTE
          WHERE CodContRulT = V_REC.CodContRulT;
        END IF;
      END LOOP;
    END IF; -- initializari

  ELSE  -- INSERT
    -- Master NCONTT
    SELECT seq_NCONTT_CodContT.NextVal INTO RecId FROM DUAL;
    INSERT INTO  NCONTT ( CodContT,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte )
    SELECT  RecId ,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte
    FROM TMP_NCONTT;

    -- Detail NCONTT1
    INSERT INTO  NCONTT1 ( CodContT1,CodContT,NrAnalitice,Participatiune,Sincronizare,Conttransfd,Conttransfc,Continkidsold,anstart,lunastart )
    SELECT seq_NCONTT1_CodContT1.Nextval ,RecId,NrAnalitice,Participatiune,Sincronizare,Conttransfd,Conttransfc,Continkidsold,anstart,lunastart
    FROM TMP_NCONTT1;

    -- Detail NCONTSOLDT
    INSERT INTO  NCONTSOLDT ( CodContSoldT,CodContT,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna )
    SELECT  seq_NCONTSOLDT_CodContSoldT.Nextval ,RecId,SoldID,SoldIC,SoldVID,SoldVIC, An, Luna
    FROM TMP_NCONTSOLDT;

    -- Detail NCONTRULT
    INSERT INTO  NCONTRULT ( CodContRulT,CodContT,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna )
    SELECT  seq_NCONTRULT_CodContRulT.Nextval ,RecId,RulajPD,RulajPC,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC, An, Luna
    FROM TMP_NCONTRULT;

  END IF;
  
  PRC_AL_REFRESH(&apos;NCONTT1&apos;,  RecId);
  NotifyModif(Operation, RecId, &apos;NCONTT&apos;);
  
  COMMIT;
END;



END PKG_PLANCONTTERT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANCONTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CC1FFE0997AAE6F11514BCE44150645904A5E58</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANCONTURI IS


PROCEDURE UPDATE_SOLD_PARINTE(aCODPARINTE IN NUMBER)
IS
 NR NUMBER := 0;
 OLDPA NUMBER := 0;
BEGIN
    SELECT COUNT(*) INTO NR
    FROM
      NCONTSOLD
    WHERE
      CODCONT = ACODPARINTE
      AND AN = GET_AN_SOLDINI
      AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;

    IF NR = 0 THEN
      INSERT INTO NCONTSOLD (CODCONTSOLD, CODCONT, AN, LUNA)
      VALUES
      (SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, ACODPARINTE, GET_AN_SOLDINI, /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1);
    END IF;

    UPDATE NCONTSOLD
    SET
      (SOLDID, SOLDIC, SOLDVID, SOLDVIC,
      SOLDI_IFRS, SOLDVI_IFRS,
      SOLDI_GRUP, SOLDVI_GRUP
      ) = (SELECT SUM(NVL(SOLDID, 0)), SUM(NVL(SOLDIC, 0)), SUM(NVL(SOLDVID, 0)), SUM(NVL(SOLDVIC, 0)),
        SUM(NVL(SOLDI_IFRS, 0)),  SUM(NVL(SOLDVI_IFRS, 0)),
        SUM(NVL(SOLDI_GRUP, 0)),  SUM(NVL(SOLDVI_GRUP, 0))
      FROM NCONTSOLD S, NCONT C
      WHERE
        C.CODCONT        = S.CODCONT
        AND C.CODPARINTE = ACODPARINTE
        AND S.AN         = GET_AN_SOLDINI
        AND S.LUNA       = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/ 1
      )
    WHERE
      CODCONT  = ACODPARINTE
      AND  AN  = GET_AN_SOLDINI
      AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 ;

     BEGIN
       SELECT NVL(CODPARINTE, 0) INTO OLDPA FROM NCONT WHERE CODCONT = aCODPARINTE;
       EXCEPTION WHEN OTHERS THEN OLDPA := 0;
     END;
     IF OLDPA &lt;&gt; 0 THEN UPDATE_SOLD_PARINTE(OLDPA);
     END IF;
END;


PROCEDURE UPDATE_SOLD_SUB_PARINTE(aCODPARINTE IN NUMBER)
IS
  NR NUMBER := 0;
  ACODCONTSOLD    NUMBER := 0;
  ACODCONTSOLDSUB NUMBER := 0;
  OLDPA           NUMBER := 0;
BEGIN
    BEGIN
      SELECT  CODCONTSOLD INTO aCODCONTSOLD
      FROM
        NCONTSOLD
      WHERE
        CODCONT = ACODPARINTE
        AND AN = GET_AN_SOLDINI
        AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
      EXCEPTION WHEN OTHERS THEN ACODCONTSOLD := 0;
    END;

    IF aCODCONTSOLD &lt;&gt; 0 THEN
      UPDATE NCONTSOLDSUB
      SET
        SOLDID = 0,
        SOLDIC = 0,
        SOLDVID = 0,
        SOLDVIC = 0,
        SOLDI_IFRS = 0,
        SOLDVI_IFRS = 0,
        SOLDI_GRUP = 0,
        SOLDVI_GRUP = 0
      WHERE
        CODCONTSOLD = aCODCONTSOLD;

      FOR V_REC IN
        (SELECT
            SS.SUBUNITATEA,
            SUM(NVL(SS.SOLDID, 0)) AS SOLDID,
            SUM(NVL(SS.SOLDIC, 0)) AS SOLDIC,
            SUM(NVL(SS.SOLDVID, 0)) AS SOLDVID,
            SUM(NVL(SS.SOLDVIC, 0)) AS SOLDVIC,
            SUM(NVL(SS.SOLDI_IFRS, 0)) AS SOLDI_IFRS,
            SUM(NVL(SS.SOLDVI_IFRS, 0)) AS SOLDVI_IFRS,
            SUM(NVL(SS.SOLDI_GRUP, 0)) AS SOLDI_GRUP,
            SUM(NVL(SS.SOLDVI_GRUP, 0)) AS SOLDVI_GRUP
          FROM
            NCONT C,
            NCONTSOLD S,
            NCONTSOLDSUB SS
          WHERE
            C.CODPARINTE =  ACODPARINTE
            AND S.CODCONT = C.CODCONT
            AND S.AN = GET_AN_SOLDINI
            AND S.LUNA = 1
            AND SS.CODCONTSOLD = S.CODCONTSOLD
          GROUP BY SUBUNITATEA
         )
       LOOP
         BEGIN
           SELECT
             CODCONTSOLDSUB INTO aCODCONTSOLDSUB FROM NCONTSOLDSUB
           WHERE
             CODCONTSOLD =  aCODCONTSOLD
             AND SUBUNITATEA = V_REC.SUBUNITATEA;
           EXCEPTION WHEN OTHERS THEN aCODCONTSOLDSUB := 0;
         END;

         IF aCODCONTSOLDSUB = 0 THEN
           aCODCONTSOLDSUB := SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL;
           INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP)
                       VALUES      (aCODCONTSOLDSUB, aCODCONTSOLD, V_REC.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0);
         END IF;
         UPDATE NCONTSOLDSUB
         SET
          SOLDID       = V_REC.SOLDID,
          SOLDIC       = V_REC.SOLDIC,
          SOLDVID      = V_REC.SOLDVID,
          SOLDVIC      = V_REC.SOLDVIC,
          SOLDI_IFRS   = V_REC.SOLDI_IFRS,
          SOLDVI_IFRS  = V_REC.SOLDVI_IFRS,
          SOLDI_GRUP   = V_REC.SOLDI_GRUP,
          SOLDVI_GRUP  = V_REC.SOLDVI_GRUP
         WHERE
           CODCONTSOLDSUB = aCODCONTSOLDSUB;

       END LOOP;

    END IF;

     BEGIN
       SELECT NVL(CODPARINTE, 0) INTO OLDPA FROM NCONT WHERE CODCONT = aCODPARINTE;
       EXCEPTION WHEN OTHERS THEN OLDPA := 0;
     END;
     IF OLDPA &lt;&gt; 0 THEN UPDATE_SOLD_SUB_PARINTE(OLDPA);
     END IF;

END;




PROCEDURE UPDATE_RULAJP_PARINTE(aCODPARINTE IN NUMBER)
IS
 NR NUMBER := 0;
 OLDPA NUMBER := 0;
BEGIN
    SELECT COUNT(*) INTO NR
    FROM
      NCONTRUL
    WHERE
      CODCONT  = ACODPARINTE
      AND AN   = PKG_GLOBALS.ANLUCRU
      AND LUNA = PKG_GLOBALS.LUNALUCRU;

    IF NR = 0 THEN
      INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, ACODPARINTE, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;


    UPDATE NCONTRUL
    SET
    (RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,
     RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
     RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP

    ) =
    (
      SELECT
        SUM(NVL(RULAJPD, 0)),
        SUM(NVL(RULAJPC, 0)),
        SUM(NVL(RULAJVPD, 0)),
        SUM(NVL(RULAJVPC, 0)),
        SUM(NVL(RULAJP_IFRS, 0)),
        SUM(NVL(RULAJC_IFRS, 0)),
        SUM(NVL(RULAJVP_IFRS, 0)),
        SUM(NVL(RULAJVC_IFRS, 0)),
        SUM(NVL(RULAJP_GRUP, 0)),
        SUM(NVL(RULAJC_GRUP, 0)),
        SUM(NVL(RULAJVP_GRUP, 0)),
        SUM(NVL(RULAJVC_GRUP, 0))
      FROM
        NCONTRUL R, NCONT C
      WHERE
       C.CODCONT = R.CODCONT AND C.CODPARINTE = ACODPARINTE AND R.AN = PKG_GLOBALS.ANLUCRU AND R.LUNA = PKG_GLOBALS.LUNALUCRU
    )
  WHERE
   CODCONT = ACODPARINTE AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;



   BEGIN
     SELECT NVL(CODPARINTE, 0) INTO OLDPA FROM NCONT WHERE CODCONT = aCODPARINTE;
     EXCEPTION WHEN OTHERS THEN OLDPA := 0;
   END;
   IF OLDPA &lt;&gt; 0 THEN UPDATE_RULAJP_PARINTE(OLDPA);
   END IF;
END;





PROCEDURE UPDATE_RULAJP_SUB_PARINTE(aCODPARINTE IN NUMBER)
IS
  NR NUMBER := 0;
  ACODCONTRUL    NUMBER := 0;
  ACODCONTRULSUB NUMBER := 0;
  OLDPA           NUMBER := 0;
BEGIN
    BEGIN
      SELECT  CODCONTRUL INTO aCODCONTRUL
      FROM
        NCONTRUL
      WHERE
        CODCONT = ACODPARINTE
        AND AN = PKG_GLOBALS.ANLUCRU
        AND LUNA = PKG_GLOBALS.LUNALUCRU;
      EXCEPTION WHEN OTHERS THEN ACODCONTRUL := 0;
    END;

    IF aCODCONTRUL &lt;&gt; 0 THEN
      UPDATE NCONTRULSUB
      SET
        RULAJPD      = 0,
        RULAJPC      = 0,
        RULAJVPD     = 0,
        RULAJVPC     = 0,
        RULAJP_IFRS  = 0,
        RULAJVP_IFRS = 0,
        RULAJP_GRUP  = 0,
        RULAJVP_GRUP = 0
      WHERE
        CODCONTRUL = aCODCONTRUL;


      FOR V_REC IN
        (
          SELECT
            RS.SUBUNITATEA,
            SUM(NVL(RS.RULAJPD, 0)) AS RULAJPD,
            SUM(NVL(RS.RULAJPC, 0)) AS RULAJPC,
            SUM(NVL(RS.RULAJVPD, 0)) AS RULAJVPD,
            SUM(NVL(RS.RULAJVPC, 0)) AS RULAJVPC,
            SUM(NVL(RS.RULAJP_IFRS, 0)) AS RULAJP_IFRS,
            SUM(NVL(RS.RULAJVP_IFRS, 0)) AS RULAJVP_IFRS,
            SUM(NVL(RS.RULAJP_GRUP, 0)) AS RULAJP_GRUP,
            SUM(NVL(RS.RULAJVP_GRUP, 0)) AS RULAJVP_GRUP
          FROM
            NCONT C,
            NCONTRUL R,
            NCONTRULSUB RS
          WHERE
            C.CODPARINTE = aCODPARINTE
            AND R.CODCONT = C.CODCONT
            AND R.AN = PKG_GLOBALS.ANLUCRU
            AND R.LUNA = PKG_GLOBALS.LUNALUCRU
            AND RS.CODCONTRUL = R.CODCONTRUL
          GROUP BY SUBUNITATEA
        )
       LOOP
         BEGIN
           SELECT
             CODCONTRULSUB INTO aCODCONTRULSUB FROM NCONTRULSUB
           WHERE
             CODCONTRUL =  aCODCONTRUL
             AND SUBUNITATEA = V_REC.SUBUNITATEA;
           EXCEPTION WHEN OTHERS THEN aCODCONTRULSUB := 0;
         END;

         IF aCODCONTRULSUB = 0 THEN
           aCODCONTRULSUB := SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL;
           INSERT INTO NCONTRULSUB(CODCONTRULSUB,
                                   CODCONTRUL,
                                   SUBUNITATEA,
                                   RULAJPD,
                                   RULAJPC,
                                   RULAJVPD,
                                   RULAJVPC,
                                   RULAJP_IFRS,
                                   RULAJVP_IFRS,
                                   RULAJP_GRUP,
                                   RULAJVP_GRUP
                                  )


                       VALUES      (aCODCONTRULSUB, aCODCONTRUL, V_REC.SUBUNITATEA, 0, 0, 0, 0, 0, 0, 0, 0);
         END IF;
         UPDATE NCONTRULSUB
         SET
           RULAJPD     = V_REC.RULAJPD,
           RULAJPC     = V_REC.RULAJPC,
           RULAJVPD    = V_REC.RULAJVPD,
           RULAJVPC    = V_REC.RULAJVPC,
           RULAJP_IFRS = V_REC.RULAJP_IFRS,
           RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
           RULAJP_GRUP  = V_REC.RULAJP_GRUP,
           RULAJVP_GRUP = V_REC. RULAJVP_GRUP
         WHERE
           CODCONTRULSUB = aCODCONTRULSUB;

       END LOOP;

    END IF;

     BEGIN
       SELECT NVL(CODPARINTE, 0) INTO OLDPA FROM NCONT WHERE CODCONT = aCODPARINTE;
       EXCEPTION WHEN OTHERS THEN OLDPA := 0;
     END;
     IF OLDPA &lt;&gt; 0 THEN UPDATE_RULAJP_SUB_PARINTE(OLDPA);
     END IF;

END;


FUNCTION GET_AN_SOLDINI RETURN NUMBER
IS
BEGIN
  IF PKG_GLOBALS.LUNALUCRU &gt;= /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 THEN
    RETURN   PKG_GLOBALS.ANLUCRU;
  ELSE
    RETURN   PKG_GLOBALS.ANLUCRU - 1;
  END IF;
END;

procedure SETSIMBOLSITFIN
IS
begin
  update ncont
  set simbolsitfin = simbol
  where nvl(simbolsitfin, &apos;@&apos;) = &apos;@&apos;;
end;

PROCEDURE SETCODCONTREP(aCODCONT IN NUMBER)
IS
BEGIN
  CODCONTREP := aCODCONT;
END;


FUNCTION GETCODCONTREP RETURN NUMBER
IS
BEGIN
  RETURN CODCONTREP;
END;

FUNCTION GET_CONT_COD_CARACT_ANLUNA(aCODCONT IN NUMBER, aANLUNA IN NUMBER) RETURN NUMBER
IS
 aCODCONT1 NUMBER(20) := -1;
BEGIN
  BEGIN
    SELECT Coalesce(CODCONT1, 0) INTO aCODCONT1
    FROM NCONT1
    WHERE CODCONT = aCODCONT AND aANLUNA BETWEEN ALSTART AND ALSTOP;
  EXCEPTION
    WHEN OTHERS THEN RETURN -1;
  END;
  RETURN aCODCONT1;
END;

FUNCTION GET_CONT_COD_CARACT_LUNA(aCODCONT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
 aCODCONT1 NUMBER(20) := -1;
BEGIN
  RETURN GET_CONT_COD_CARACT_ANLUNA(aCODCONT, aAN*12+aLUNA);
END;


FUNCTION REPARTIZARE_SOLD_IN_LUNA(aCODCONT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NCONTREP WHERE CODCONT = aCODCONT AND AN = aAN AND LUNA = aLUNA;
  RETURN NR;
END;

PROCEDURE SET_FLAG_INITIALIZARI(FLAG IN NUMBER)
IS
BEGIN
  INITIALIZARI := FLAG;
END;

FUNCTION GETSIMBOLCONT(CONT IN NUMBER) RETURN VARCHAR2
IS
aSimbol VARCHAR(100) := &apos;???&apos;;
BEGIN
  BEGIN
    SELECT SIMBOL INTO aSimbol FROM NCONT WHERE CODCONT = CONT;
    EXCEPTION WHEN OTHERS THEN RETURN aSimbol;
  END;
  RETURN aSimbol;
END;


FUNCTION GETCODCONT_BY_SIMBOL(ASIMBOL IN VARCHAR2, Principal in number default 0) RETURN NUMBER
IS
aCOD NUMBER(20) := 0;
BEGIN
  BEGIN
    if NVL(Principal,0) = 0 then
      SELECT CODCONT INTO ACOD FROM NCONT WHERE upper(SIMBOL) = upper(aSIMBOL);
    else
      SELECT CODCONTS INTO ACOD FROM NCONTS WHERE upper(SIMBOL) = upper(aSIMBOL);
    end if;
    EXCEPTION WHEN OTHERS THEN RETURN aCOD;
  END;
  RETURN aCOD;
END;



FUNCTION GETDENCONT(CONT IN NUMBER) RETURN VARCHAR2
IS
aDEN VARCHAR(100) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT DEN_CONT INTO aDEN FROM NCONT WHERE CODCONT = CONT;
    EXCEPTION WHEN OTHERS THEN RETURN aDEN;
  END;
  RETURN aDEN;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodCont INTO Tmp FROM NCONT WHERE CodCont = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCODPARINTE NUMBER(20) := 0;
NR          NUMBER(20) := 0;
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomPlanConturi  --&gt; 521
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 521);
  SELECT NVL(CODPARINTE, 0) INTO aCODPARINTE FROM NCONT WHERE CODCONT = RECID;

  FOR V_REC IN (SELECT * FROM NCONT1 WHERE CODCONT = RECID)
  LOOP
    DELETE NCONT1SUB    WHERE CODCONT1 = V_REC.CODCONT1;
    DELETE NCONT1       WHERE CODCONT1 = V_REC.CODCONT1;
  END LOOP;



  FOR V_REC IN (SELECT * FROM NCONTSOLD WHERE CODCONT = RECID)
  LOOP
    DELETE NCONTSOLD WHERE CODCONTSOLD = V_REC.CODCONTSOLD;
    DELETE FROM NCONTSOLDSUB WHERE CODCONTSOLD = V_REC.CODCONTSOLD;
  END LOOP;

  FOR V_REC IN (SELECT * FROM  NCONTRUL WHERE CODCONT = RECID)
  LOOP
    DELETE NCONTRUL WHERE CODCONTRUL = V_REC.CODCONTRUL;
    DELETE FROM NCONTRULSUB WHERE CODCONTRUL = V_REC.CODCONTRUL;
  END LOOP;


  DELETE NCONTREP WHERE CODCONT = RECID;

  FOR V_REC IN (SELECt * FROM NCONTREPSOLD WHERE CODCONT = RECID)
  LOOP
    DELETE NCONTREPSOLDSUB WHERE CODCONTREPSOLD = V_REC.CODCONTREPSOLD;
    DELETE NCONTREPSOLD WHERE CODCONTREPSOLD = V_REC.CODCONTREPSOLD;
  END LOOP;

--  DELETE NCONTREPRUL  WHERE CODCONT = RECID;

  FOR V_REC IN (SELECT * FROM NCONTREPRUL  WHERE CODCONT = RECID)
  LOOP
    DELETE NCONTREPRULSUB WHERE CODCONTREPRUL = V_REC.CODCONTREPRUL;
    DELETE NCONTREPRUL WHERE CODCONTREPRUL = V_REC.CODCONTREPRUL;
  END LOOP;

  DELETE NCONT        WHERE CODCONT = RecId ;

-- DACA AM STERS UN ANALITIC STERG DIN NCONTREP CODUL PARINTE DACA EL NU MAI ARE REPARTIZARI PE COPII
  DELETE NCONTREP     WHERE CODCONT NOT IN (SELECT CODPARINTE FROM NCONTREPSOLD UNION SELECT CODPARINTE FROM NCONTREPRUL);


  -- AM STERS UN ANALITIC. RECALCULEZ SOLDURILE SI RULAJELE PRECEDNTE LA INCEPUT DE AN ALE PARINTERLUI

  IF ACODPARINTE &gt; 0  THEN
    null;
 /*  17.11.2021 am renuntat la update-urile de mai jos deoarece strica solurile initiale
   SELECT COUNT(*) INTO NR FROM NCONT WHERE CODPARINTE = aCODPARINTE;
   IF NR &gt; 0 THEN
     UPDATE_SOLD_PARINTE(aCODPARINTE);
     UPDATE_SOLD_SUB_PARINTE(aCODPARINTE);
     UPDATE_RULAJP_PARINTE(aCODPARINTE);
     UPDATE_RULAJP_SUB_PARINTE(aCODPARINTE);
   END IF;
*/
 /*
    SELECT COUNT(*) INTO NR FROM NCONT WHERE CODPARINTE = aCODPARINTE;

    IF NR &gt; 0 THEN
      UPDATE NCONTSOLD
      SET
        (SOLDID,
         SOLDIC,
         SOLDVID,
         SOLDVIC,
         SOLDI_IFRS, SOLDVI_IFRS,
         SOLDI_GRUP, SOLDVI_GRUP
         ) = (SELECT
                 SUM(NVL(SOLDID, 0)),
                 SUM(NVL(SOLDIC, 0)),
                 SUM(NVL(SOLDVID, 0)),
                 SUM(NVL(SOLDVIC, 0)),
                 SUM(NVL(SOLDI_IFRS, 0)),
                 SUM(NVL(SOLDVI_IFRS, 0)),
                 SUM(NVL(SOLDI_GRUP, 0)),
                 SUM(NVL(SOLDVI_GRUP, 0))
                 FROM NCONTSOLD S, NCONT C
                 WHERE
                   C.CODCONT = S.CODCONT AND C.CODPARINTE = ACODPARINTE
                   AND S.AN = GET_AN_SOLDINI
                   AND S.LUNA =1)
      WHERE
       CODCONT  = ACODPARINTE
       AND AN   = GET_AN_SOLDINI
       AND LUNA = 1;


      UPDATE NCONTRUL
      SET
        (RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,
         RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
         RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
         ) =
                                                                         (SELECT
                                                                              SUM(NVL(RULAJPD,  0)),
                                                                              SUM(NVL(RULAJPC,  0)),
                                                                              SUM(NVL(RULAJVPD, 0)),
                                                                              SUM(NVL(RULAJVPD, 0)),
                                                                              SUM(NVL(RULAJP_IFRS, 0)),
                                                                              SUM(NVL(RULAJC_IFRS, 0)),
                                                                              SUM(NVL(RULAJVP_IFRS, 0)),
                                                                              SUM(NVL(RULAJVC_IFRS, 0)),
                                                                              SUM(NVL(RULAJP_GRUP, 0)),
                                                                              SUM(NVL(RULAJC_GRUP, 0)),
                                                                              SUM(NVL(RULAJVP_GRUP, 0)),
                                                                              SUM(NVL(RULAJVC_GRUP, 0))
                                                                            FROM
                                                                              NCONTRUL R, NCONT C
                                                                            WHERE
                                                                              C.CODCONT = R.CODCONT AND C.CODPARINTE = ACODPARINTE
                                                                              AND R.AN = PKG_GLOBALS.ANLUCRU
                                                                              AND R.LUNA = PKG_GLOBALS.LUNALUCRU
                                                                          )
      WHERE
       CODCONT = ACODPARINTE
       AND AN = GET_AN_SOLDINI
       AND LUNA =  1;
    END IF;
  */
  END IF;

  PRC_AL_REFRESH(&apos;NCONT1&apos;,  RecId);
  NotifyModif(2, RecId, &apos;NCONT&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NCONT FIELDS( CodCont ) VALUES (0) ;
  -- nomPlanConturi  --&gt; 521
  PKG_CFGTABLES.EXT_INSERTRECORD(521); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 aANSFARSIT NUMBER(4);
 aLUNASFARSIT NUMBER(2);
 aINDEX NUMBER(10) := 0;
 NR     NUMBER(10) := 0;

BEGIN
-- Master NCONT
  INSERT INTO  TMP_NCONT ( CodCont, Simbol, Clasa, Den_cont,Name, TipCont, VizibilBalanta, BalantaSintetica, Nivel, CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV, CODSAFT, TAXCODE, IMPOZIT, taxtype )
    ( SELECT CodCont, Simbol, Clasa, Den_cont, Name, TipCont, VizibilBalanta, BalantaSintetica, Nivel, CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV, CODSAFT, TAXCODE, IMPOZIT, taxtype
      FROM
        NCONT
      WHERE CodCont = RecId ) ;

-- Detail NCONT1
  INSERT INTO  TMP_NCONT1 ( CodCont1,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart, codanalizanod )
    ( SELECT CodCont1,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart, codanalizanod
      FROM NCONT1 WHERE CodCont = RecId );

  INSERT INTO TMP_NCONT1SUB (COD, CODCONT1, SUBUNITATEA, TIPINCHIDERE, DENSUBUNIT)
  SELECT NC1S.COD, NC1S.CODCONT1, NC1S.SUBUNITATEA, NC1S.TIPINCHIDERE, NS.DEN_SUBUNIT
  FROM
    NCONT1SUB NC1S,
    NSUBUNIT NS
  WHERE
    EXISTS (SELECT CODCONT1 FROM TMP_NCONT1 WHERE CODCONT1 = NC1S.CODCONT1)
    AND NS.CODSUBUNIT = NC1S.SUBUNITATEA;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODCONT1, ANSTART, LUNASTART FROM TMP_NCONT1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_NCONT1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODCONT1 = V_REC.CODCONT1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;


-- Detail NCONTSOLD



  INSERT INTO TMP_NCONTSOLD (CodContSold, SoldID, SoldIC, SoldVID, SoldVIC,
    SOLDI_IFRS, SOLDVI_IFRS,
    SOLDI_GRUP, SOLDVI_GRUP,
  CodCont, An, Luna )
    ( SELECT CodContSold, SoldID, SoldIC, SoldVID, SoldVIC,
             SOLDI_IFRS, SOLDVI_IFRS,
             SOLDI_GRUP, SOLDVI_GRUP,
             CodCont, An, Luna
      FROM
        NCONTSOLD WHERE CodCont = RecId
        AND AN   = GET_AN_SOLDINI
        AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1
        );

-- Detail NCONTSOLDSUB
 INSERT INTO TMP_NCONTSOLDSUB (CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
                               SOLDI_IFRS, SOLDVI_IFRS,
                               SOLDI_GRUP, SOLDVI_GRUP,
                              DENSUBUNIT)
 SELECT
 CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
 SOLDI_IFRS, SOLDVI_IFRS,
 SOLDI_GRUP, SOLDVI_GRUP,
 SUB.DEN_SUBUNIT
 FROM
  NCONTSOLDSUB S,
  NSUBUNIT SUB
 WHERE
   SUB.CODSUBUNIT = S.SUBUNITATEA
   AND EXISTS (SELECT CODCONTSOLD FROM TMP_NCONTSOLD WHERE CODCONTSOLD = S.CODCONTSOLD);

-- Detail NCONTRUL
  INSERT INTO TMP_NCONTRUL ( CodContRul,RulajPD,RulajPC,CodCont,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC,
           RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
           RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
           An, Luna )
    ( SELECT CodContRul,RulajPD,RulajPC,CodCont,RulajCD,RulajCC,RulajVPD,RulajVPC,RulajVCD,RulajVCC,
      RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
      An, Luna
      FROM NCONTRUL WHERE CodCont = RecId
      AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU );


-- Detail NCONTRULSUB
  INSERT INTO TMP_NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJCD, RULAJCC, RULAJVCD, RULAJVCC,
  RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
  RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
  DENSUBUNIT)
  SELECT CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC, RULAJCD, RULAJCC, RULAJVCD, RULAJVCC,
  RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
  RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
  S.DEN_SUBUNIT
  FROM
   NCONTRULSUB R,
   NSUBUNIT S
  WHERE
  EXISTS (SELECT CODCONTRUL FROM TMP_NCONTRUL WHERE CODCONTRUL = R.CODCONTRUL)
  AND S.CODSUBUNIT = R.SUBUNITATEA;

  aINDEX := 0;
  FOR V_REC_SOLD IN (SELECT * FROM TMP_NCONTSOLD)
  LOOP
    FOR V_REC_SUB IN (SELECT * FROM NSUBUNIT WHERE CODSUBUNIT &gt; 1)
    LOOP
      SELECT COUNT(*) INTO NR FROM TMP_NCONTSOLDSUB
      WHERE
        SUBUNITATEA     = V_REC_SUB.CODSUBUNIT
        AND CODCONTSOLD = V_REC_SOLD.CODCONTSOLD;
      IF NR = 0 THEN
        aINDEX := aINDEX - 1;
        INSERT INTO TMP_NCONTSOLDSUB (CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, DENSUBUNIT)
                    VALUES (aINDEX, V_REC_SOLD.CODCONTSOLD, V_REC_SUB.CODSUBUNIT, V_REC_SUB.DEN_SUBUNIT);
      END IF;
    END LOOP;
  END LOOP;



  aINDEX := 0;
  FOR V_REC_RUL IN (SELECT * FROM TMP_NCONTRUL)
  LOOP
    FOR V_REC_SUB IN (SELECT * FROM NSUBUNIT WHERE CODSUBUNIT &gt; 1)
    LOOP
      SELECT COUNT(*) INTO NR FROM TMP_NCONTRULSUB
      WHERE
        SUBUNITATEA     = V_REC_SUB.CODSUBUNIT
        AND CODCONTRUL  = V_REC_RUL.CODCONTRUL;
      IF NR = 0 THEN
        aINDEX := aINDEX - 1;
        INSERT INTO TMP_NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, DENSUBUNIT)
                    VALUES (aINDEX, V_REC_RUL.CODCONTRUL, V_REC_SUB.CODSUBUNIT, V_REC_SUB.DEN_SUBUNIT);
      END IF;
    END LOOP;
  END LOOP;

  UPDATE TMP_NCONT
  SET
    INACTIV = CASE
                WHEN NVL(ANINACTIV, 0) + NVL(LUNAINACTIV, 0) &lt;&gt; 0 THEN 1
                ELSE 0
              END;
  -- nomPlanConturi  --&gt; 521
  PKG_CFGTABLES.EXT_GOTORECORD(521);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 aCODPARINTE            NUMBER(20) := 0;
 NrCopii                NUMBER(20) := 0;
 NR                     NUMBER(10) := 0;
 aAnLuna                NUMBER(20) := 0;
 ANINCEPUTREPARTIZARI   NUMBER(4)  := 0;
 LUNAINCEPUTREPARTIZARI NUMBER(2)  := 0;
 CONTUL_EXISTA_IN_LUNA  NUMBER(10) := 0;
 aCOD                   NUMBER(20) := 0;
 VCOD                   NUMBER(20) := 0;
 ANI                    NUMBER(5);
 LUNAI                  NUMBER(2);
 aCODCONTREPSOLD        NUMBER(20);
 aCODCONTREPSOLDSUB     NUMBER(20);

 aCODCONTREPRUL         NUMBER(20);
 aCODCONTREPRULSUB      NUMBER(20);
 aCODCONTSOLD           NUMBER(20);

BEGIN
  -- nomPlanConturi  --&gt; 521
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (521);
  SELECT NVL(CODPARINTE, 0) INTO aCODPARINTE FROM TMP_NCONT;
  if aCodParinte &gt; 0 then
    begin
      select Count(CodCont) into NrCopii from NCONT where CodParinte = aCodParinte;
    exception when others then
      NrCopii := 0;
    end;
    begin
      select AnStart * 12 + LunaStart into aAnLuna from TMP_NCONT1 where RowNum = 1;
    exception when others then
      aAnLuna := 0;
    end;
  end if;

  IF Operation = 0 THEN  -- UPDATE

-- Master NCONT
    SELECT  CodCont INTO RecId FROM TMP_NCONT;


    UPDATE NCONT SET ( Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV, CODSAFT, TAXCODE, IMPOZIT, taxtype )
       = ( SELECT Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV, CODSAFT, TAXCODE, IMPOZIT, taxtype
          FROM TMP_NCONT )
      WHERE CodCont = RecId ;


-- Detail NCONT1

    FOR V_REC IN
    (
      SELECT * FROM NCONT1 where CodCont = RecId and CodCont1 not in (Select CodCont1 from  TMP_NCONT1)
    )
    LOOP
      DELETE FROM NCONT1SUB WHERE CODCONT1 = V_REC.CODCONT1;
      DELETE FROM NCONT1    WHERE CODCONT1 = V_REC.CODCONT1;
    END LOOP;


--    DELETE FROM NCONT1 where CodCont = RecId and CodCont1 not in (Select CodCont1 from
 --   TMP_NCONT1);

    FOR V_REC IN
    ( SELECT
        CODCONT1,
        NrAnalitice,
        ContTransfD,
        ContTransfC,
        ContTransfCDim,
        CONTSECUNDARG,
        CONTSECUNDARGO,
        CODCENTRU,
        CODCENTRUS,
        CODCENTRUSG,
        CODCENTRUSGO,
        TipInchidere,
        ContInkidSold,
        Participatiune,
        Sincronizare,
        ContSecundar,
        ContTertiar,
        anstart,
        lunastart,
        codanalizanod
      FROM TMP_NCONT1 WHERE CodCont1 &lt; 0
    )
    LOOP
      SELECT seq_NCONT1_CodCont1.Nextval INTO VCOD FROM DUAL;
      UPDATE TMP_NCONT1SUB
      SET
        CODCONT1 = VCOD
      WHERE
        CODCONT1 = V_REC.CODCONT1;

    INSERT INTO NCONT1 ( CodCont1, CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart, codanalizanod )
     VALUES
       (
        VCOD ,
        RecId ,
        V_REC.NrAnalitice,
        V_REC.ContTransfD,
        V_REC.ContTransfC,
        V_REC.ContTransfCDim,
        V_REC.CONTSECUNDARG,
        V_REC.CONTSECUNDARGO,
        V_REC.CODCENTRU,
        V_REC.CODCENTRUS,
        V_REC.CODCENTRUSG,
        V_REC.CODCENTRUSGO,
        V_REC.TipInchidere,
        V_REC.ContInkidSold,
        V_REC.Participatiune,
        V_REC.Sincronizare,
        V_REC.ContSecundar,
        V_REC.ContTertiar,
        V_REC.anstart,
        V_REC.lunastart,
        V_REC.codanalizanod
       );
    END LOOP;


/*
    INSERT INTO NCONT1 ( CodCont1,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart )
      SELECT  seq_NCONT1_CodCont1.Nextval , RecId ,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart
      FROM TMP_NCONT1 WHERE CodCont1 &lt; 0;
*/
    FOR V_REC IN ( SELECT * FROM TMP_NCONT1 WHERE NVL(CodCont1,-1) &gt; 0 ORDER BY CodCont1 ) LOOP
      UPDATE NCONT1
      SET
        NRANALITICE    = v_rec.NrAnalitice,
        ContTransfD    = v_rec.ContTransfD,
        ContTransfC    = v_rec.ContTransfC,
        ContTransfCDim = v_rec.ContTransfCDim ,
        TipInchidere     = v_rec.TipInchidere     ,
        CONTSECUNDARG  = v_rec.CONTSECUNDARG  ,
        CONTSECUNDARGO = v_rec.CONTSECUNDARGO ,
        CODCENTRU      = v_rec.CODCENTRU      ,
        CODCENTRUS     = v_rec.CODCENTRUS     ,
        CODCENTRUSG    = v_rec.CODCENTRUSG    ,
        CODCENTRUSGO   = v_rec.CODCENTRUSGO  ,
        ContInkidSold  = v_rec.ContInkidSold,
        Participatiune = v_rec.Participatiune,
        Sincronizare   = v_rec.Sincronizare,
        ContSecundar   = v_rec.ContSecundar,
        ContTertiar    = v_rec.ContTertiar,
        codanalizanod  = V_REC.codanalizanod
      WHERE
        CodCont1 = v_rec.CodCont1;
    END LOOP;


    FOR V_REC IN (SELECT * FROM TMP_NCONT1SUB)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO NCONT1SUB(COD, CODCONT1, SUBUNITATEA, TIPINCHIDERE)
        VALUES (SEQ_NCONT1SUB_COD.NEXTVAL, V_REC.CODCONT1, V_REC.SUBUNITATEA, V_REC.TIPINCHIDERE);
      ELSE
        UPDATE NCONT1SUB
        SET
          SUBUNITATEA  = V_REC.SUBUNITATEA,
          TIPINCHIDERE = V_REC.TIPINCHIDERE
        WHERE
          COD = V_REC.COD;
      END IF;
    END LOOP;

  SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;


   IF (INITIALIZARI = 1) OR ( ANI * 12 + LUNAI = PKG_GLOBALS.AnLucru * 12 + PKG_GLOBALS.LunaLucru)
   THEN

  -- Detail NCONTSOLD
      FOR V_REC IN ( SELECT * FROM TMP_NCONTSOLD ) LOOP
        IF V_REC.CODCONTSOLD &lt; 0 THEN
          SELECT SEQ_NCONTSOLD_CodContSold.Nextval INTO aCOD FROM DUAL;
          INSERT INTO NCONTSOLD (CodContSold, SoldID, SoldIC, SoldVID, SoldVIC,
          SOLDI_IFRS, SOLDVI_IFRS,
          SOLDI_GRUP, SOLDVI_GRUP,
          CodCont, An, Luna )
          VALUES (aCOD, V_REC.SoldID, V_REC.SoldIC, V_REC.SoldVID, V_REC.SoldVIC,
          V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS,
          V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP,
          RecId , V_REC.An, V_REC.Luna);
          UPDATE TMP_NCONTSOLDSUB
          SET
            CODCONTSOLD = aCOD
          WHERE
            CODCONTSOLD = V_REC.CODCONTSOLD;
        ELSE
          UPDATE NCONTSOLD
          SET
            SoldID      = V_REC.SOLDID,
            SoldIC      = V_REC.SOLDIC,
            SoldVID     = V_REC.SOLDVID,
            SoldVIC     = V_REC.SOLDVIC,
            SOLDI_IFRS  = V_REC.SOLDI_IFRS,
            SOLDVI_IFRS = V_REC.SOLDVI_IFRS,
            SOLDI_GRUP  = V_REC.SOLDI_GRUP,
            SOLDVI_GRUP = V_REC.SOLDVI_GRUP
          WHERE
            CODCONTSOLD = V_REC.CODCONTSOLD;
/* :1:2:3
          UPDATE NCONTREPSOLD
          SET
            SoldID      = V_REC.SOLDID,
            SoldIC      = V_REC.SOLDIC,
            SoldVID     = V_REC.SOLDVID,
            SoldVIC     = V_REC.SOLDVIC,
            SOLDI_IFRS  = V_REC.SOLDI_IFRS,
            SOLDVI_IFRS = V_REC.SOLDVI_IFRS,
            SOLDI_GRUP  = V_REC.SOLDI_GRUP,
            SOLDVI_GRUP = V_REC.SOLDVI_GRUP
          WHERE
            CODCONT= V_REC.CODCONT;
*/

        END IF;
      END LOOP;


  -- Detail NCONTRUL
      FOR V_REC IN (SELECT * FROM TMP_NCONTRUL) LOOP
        IF V_REC.CODCONTRUL &lt; 0 THEN
            SELECT seq_NCONTRUL_CodContRul.Nextval INTO aCOD FROM DUAL;

            INSERT INTO NCONTRUL ( CodContRul, RulajPD, RulajPC, CodCont, RulajCD, RulajCC, RulajVPD, RulajVPC, RulajVCD, RulajVCC,
            RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
            RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP,
            An, Luna )
               VALUES  (aCOD, V_REC.RulajPD, V_REC.RulajPC, RecId, V_REC.RulajCD, V_REC.RulajCC, V_REC.RulajVPD,  V_REC.RulajVPC, V_REC.RulajVCD, V_REC.RulajVCC,
               V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS, V_REC.RULAJC_IFRS, V_REC.RULAJVC_IFRS,
               V_REC.RULAJP_GRUP, V_REC.RULAJVP_GRUP, V_REC.RULAJC_GRUP, V_REC.RULAJVC_GRUP,
               V_REC.An, V_REC.Luna);

          UPDATE TMP_NCONTRULSUB
          SET
            CODCONTRUL = aCOD
          WHERE
            CODCONTRUL = V_REC.CODCONTRUL;

        ELSE
          UPDATE NCONTRUL
          SET
            RulajPD      = V_REC.RULAJPD,
            RulajPC      = V_REC.RULAJPC,
            RulajVPD     = V_REC.RULAJVPD,
            RulajVPC     = V_REC.RULAJVPC,
            RULAJP_IFRS  = V_REC.RULAJP_IFRS,
            RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
            RULAJC_IFRS  = V_REC.RULAJC_IFRS,
            RULAJVC_IFRS = V_REC.RULAJVC_IFRS,

            RULAJP_GRUP  = V_REC.RULAJP_GRUP,
            RULAJVP_GRUP = V_REC.RULAJVP_GRUP,
            RULAJC_GRUP  = V_REC.RULAJC_GRUP,
            RULAJVC_GRUP = V_REC.RULAJVC_GRUP
         -- NU MA ATING DE RULAJELE CURENTE
          WHERE
            CODCONTRUL = V_REC.CODCONTRUL;
/*
          UPDATE NCONTREPRUL
          SET
            RulajPD      = V_REC.RULAJPD,
            RulajPC      = V_REC.RULAJPC,
            RulajVPD     = V_REC.RULAJVPD,
            RulajVPC     = V_REC.RULAJVPC,
            RULAJP_IFRS  = V_REC.RULAJP_IFRS,
            RULAJC_IFRS  = V_REC.RULAJC_IFRS,
            RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
            RULAJVC_IFRS = V_REC.RULAJVC_IFRS,

            RULAJP_GRUP  = V_REC.RULAJP_GRUP,
            RULAJC_GRUP  = V_REC.RULAJC_GRUP,
            RULAJVP_GRUP = V_REC.RULAJVP_GRUP,
            RULAJVC_GRUP = V_REC.RULAJVC_GRUP

         -- NU MA ATING DE RULAJELE CURENTE
          WHERE
            CODCONT = V_REC.CODCONT;
*/
        END IF;
      END LOOP;


      FOR V_REC IN (SELECT * FROM TMP_NCONTSOLDSUB)
      LOOP
        IF V_REC.CODCONTSOLDSUB &lt; 0 THEN
          INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
          SOLDI_IFRS, SOLDVI_IFRS,
          SOLDI_GRUP, SOLDVI_GRUP
          )
          VALUES( SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC.CODCONTSOLD, V_REC.SUBUNITATEA, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC,
          V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS,
          V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP
          );
        ELSE
          UPDATE NCONTSOLDSUB
          SET
            SOLDID      = V_REC.SOLDID,
            SOLDIC      = V_REC.SOLDIC,
            SOLDVID     = V_REC.SOLDVID,
            SOLDVIC     = V_REC.SOLDVIC,
            SOLDI_IFRS  = V_REC.SOLDI_IFRS,
            SOLDVI_IFRS = V_REC.SOLDVI_IFRS,
            SOLDI_GRUP  = V_REC.SOLDI_GRUP,
            SOLDVI_GRUP = V_REC.SOLDVI_GRUP
          WHERE
           CODCONTSOLDSUB = V_REC.CODCONTSOLDSUB;
        END IF;
      END LOOP;


      FOR V_REC IN (SELECT RS.*, R.CODCONT FROM TMP_NCONTRULSUB RS, NCONTRUL R WHERE RS.CODCONTRUL = R.CODCONTRUL )
      LOOP
        IF V_REC.CODCONTRULSUB &lt; 0 THEN
         INSERT INTO NCONTRULSUB (CODCONTRULSUB,
                                  CODCONTRUL,
                                  SUBUNITATEA,
                                  RULAJPD,
                                  RULAJPC,
                                  RULAJVPD,
                                  RULAJVPC,
                                  RULAJP_IFRS,
                                  RULAJC_IFRS,
                                  RULAJVP_IFRS,
                                  RULAJVC_IFRS,
                                  RULAJP_GRUP,
                                  RULAJC_GRUP,
                                  RULAJVP_GRUP,
                                  RULAJVC_GRUP

                                   )
                           VALUES( SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL,
                                   V_REC.CODCONTRUL,
                                   V_REC.SUBUNITATEA,
                                   V_REC.RULAJPD,
                                   V_REC.RULAJPC,
                                   V_REC.RULAJVPD,
                                   V_REC.RULAJVPC,
                                   V_REC.RULAJP_IFRS,
                                   V_REC.RULAJC_IFRS,
                                   V_REC.RULAJVP_IFRS,
                                   V_REC.RULAJVC_IFRS,
                                   V_REC.RULAJP_GRUP,
                                   V_REC.RULAJC_GRUP,
                                   V_REC.RULAJVP_GRUP,
                                   V_REC.RULAJVC_GRUP
                                  );
        ELSE
          UPDATE NCONTRULSUB
          SET
             RULAJPD      = V_REC.RULAJPD,
             RULAJPC      = V_REC.RULAJPC,
             RULAJVPD     = V_REC.RULAJVPD,
             RULAJVPC     = V_REC.RULAJVPC,
             RULAJP_IFRS  = V_REC.RULAJP_IFRS,
             RULAJC_IFRS  = V_REC.RULAJC_IFRS,
             RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
             RULAJVC_IFRS = V_REC.RULAJVC_IFRS,

             RULAJP_GRUP  = V_REC.RULAJP_GRUP,
             RULAJC_GRUP  = V_REC.RULAJC_GRUP,
             RULAJVP_GRUP = V_REC.RULAJVP_GRUP,
             RULAJVC_GRUP = V_REC.RULAJVC_GRUP
          WHERE
           CODCONTRULSUB = V_REC.CODCONTRULSUB;
-- :1

/*
           FOR V_REC_REP IN (select R.CODCONT, RS.* FROM NCONTREPRUL R, NCONTREPRULSUB RS WHERE  RS.CODCONTREPRUL = R.CODCONTREPRUL AND R.CODCONT = V_REC.CODCONT AND RS.SUBUNITATEA = V_REC.SUBUNITATEA)
           LOOP
             UPDATE NCONTREPRULSUB
             SET
               RulajPD      = V_REC.RULAJPD,
               RulajPC      = V_REC.RULAJPC,
               RulajVPD     = V_REC.RULAJVPD,
               RulajVPC     = V_REC.RULAJVPC,
               RULAJP_IFRS  = V_REC.RULAJP_IFRS,
               RULAJC_IFRS  = V_REC.RULAJC_IFRS,
               RULAJVP_IFRS = V_REC.RULAJVP_IFRS,
               RULAJVC_IFRS = V_REC.RULAJVC_IFRS,

               RULAJP_GRUP  = V_REC.RULAJP_GRUP,
               RULAJC_GRUP  = V_REC.RULAJC_GRUP,
               RULAJVP_GRUP = V_REC.RULAJVP_GRUP,
               RULAJVC_GRUP = V_REC.RULAJVC_GRUP

             WHERE
               CODREPRULSUB = V_REC_REP.CODREPRULSUB;
           END LOOP;
*/
        END IF;


      END LOOP;


    END IF; -- initializari
  ELSE  -- INSERT
--Master NCONT
  SELECT seq_NCONT_CodCont.NextVal INTO RecId FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NCONT&apos;, RecId);
  INSERT INTO  NCONT ( CodCont,Simbol,Clasa,Den_cont,Name,TipCont,VizibilBalanta,BalantaSintetica,Nivel,CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV,CODSAFT, TAXCODE, IMPOZIT,taxtype )
 ( SELECT RecId, Simbol, Clasa, Den_cont, Name, TipCont, VizibilBalanta, BalantaSintetica, Nivel, CodParinte, SimbolSitFin, ANINACTIV, LUNAINACTIV,CODSAFT, TAXCODE, IMPOZIT,taxtype
     FROM TMP_NCONT  ) ;

-- Detail NCONT1
/*
  INSERT INTO NCONT1 ( CodCont1,CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere, ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart )
     ( SELECT seq_NCONT1_CodCont1.Nextval ,RecId, NrAnalitice, ContTransfD, ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,  ContInkidSold, Participatiune, Sincronizare, ContSecundar, ContTertiar, ANSTART, LUNASTART FROM TMP_NCONT1);
*/


    FOR V_REC IN
    ( SELECT
        CODCONT1,
        NrAnalitice,
        ContTransfD,
        ContTransfC,
        ContTransfCDim,
        CONTSECUNDARG,
        CONTSECUNDARGO,
        CODCENTRU,
        CODCENTRUS,
        CODCENTRUSG,
        CODCENTRUSGO,
        TipInchidere,
        ContInkidSold,
        Participatiune,
        Sincronizare,
        ContSecundar,
        ContTertiar,
        anstart,
        lunastart,
        codanalizanod
      FROM TMP_NCONT1 WHERE CodCont1 &lt; 0
    )
    LOOP
      SELECT seq_NCONT1_CodCont1.Nextval INTO VCOD FROM DUAL;
      UPDATE TMP_NCONT1SUB
      SET
        CODCONT1 = VCOD
      WHERE
        CODCONT1 = V_REC.CODCONT1;

    INSERT INTO NCONT1 ( CodCont1, CodCont,NrAnalitice,ContTransfD,ContTransfC,ContTransfCDim,CONTSECUNDARG,  CONTSECUNDARGO, CODCENTRU, CODCENTRUS, CODCENTRUSG, CODCENTRUSGO,TipInchidere,ContInkidSold,Participatiune,Sincronizare,ContSecundar,ContTertiar, anstart, lunastart, codanalizanod )
      VALUES
       (
        VCOD ,
        RecId ,
        V_REC.NrAnalitice,
        V_REC.ContTransfD,
        V_REC.ContTransfC,
        V_REC.ContTransfCDim,
        V_REC.CONTSECUNDARG,
        V_REC.CONTSECUNDARGO,
        V_REC.CODCENTRU,
        V_REC.CODCENTRUS,
        V_REC.CODCENTRUSG,
        V_REC.CODCENTRUSGO,
        V_REC.TipInchidere,
        V_REC.ContInkidSold,
        V_REC.Participatiune,
        V_REC.Sincronizare,
        V_REC.ContSecundar,
        V_REC.ContTertiar,
        V_REC.anstart,
        V_REC.lunastart,
        V_REC.codanalizanod
        );
    END LOOP;

   INSERT INTO NCONT1SUB(COD, CODCONT1, SUBUNITATEA, TIPINCHIDERE)
   SELECT SEQ_NCONT1SUB_COD.NEXTVAL, CODCONT1, SUBUNITATEA, TIPINCHIDERE FROM TMP_NCONT1SUB;


  if (aCodParinte &gt; 0) and (NrCopii = 0) then
    begin
      update NCONT1 NC1 set ContSecundar = null 
      where NC1.codcont = aCodparinte and aAnLuna BETWEEN nc1.alstart AND nc1.alstop;
    exception when others then
      null;
    end;
  end if;

   SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;


   IF (INITIALIZARI = 1) OR ( ANI * 12 + LUNAI = PKG_GLOBALS.AnLucru * 12 + PKG_GLOBALS.LunaLucru)
   THEN
    -- Detail NCONTSOLD
      FOR V_REC IN (SELECT * FROM TMP_NCONTSOLD)
      LOOP

          SELECT SEQ_NCONTSOLD_CodContSold.Nextval INTO aCOD FROM DUAL;
          INSERT INTO NCONTSOLD (CodContSold, SoldID, SoldIC, SoldVID, SoldVIC,
            SOLDI_IFRS, SOLDVI_IFRS,
            SOLDI_GRUP, SOLDVI_GRUP,
            CodCont, An, Luna )
                          VALUES (aCOD, V_REC.SoldID, V_REC.SoldIC, V_REC.SoldVID, V_REC.SoldVIC,
                          V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS,
                          V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP,
                          RecId , V_REC.An, V_REC.Luna);
          UPDATE TMP_NCONTSOLDSUB
          SET
            CODCONTSOLD = aCOD
          WHERE
            CODCONTSOLD = V_REC.CODCONTSOLD;
      END LOOP;




    -- Detail NCONTRUL
     FOR V_REC IN (SELECT * FROM TMP_NCONTRUL)
     LOOP
       SELECT seq_NCONTRUL_CodContRul.Nextval INTO aCOD FROM DUAL;
       INSERT INTO NCONTRUL ( CodContRul, RulajPD, RulajPC, CodCont, RulajCD, RulajCC, RulajVPD, RulajVPC, RulajVCD, RulajVCC,
       RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
       RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP,
       An, Luna )
            VALUES  (aCOD, V_REC.RulajPD, V_REC.RulajPC, RecId, V_REC.RulajCD, V_REC.RulajCC, V_REC.RulajVPD,  V_REC.RulajVPC, V_REC.RulajVCD, V_REC.RulajVCC,
            V_REC.RULAJP_IFRS, V_REC.RULAJC_IFRS,  V_REC.RULAJVP_IFRS, V_REC.RULAJVC_IFRS,
            V_REC.RULAJP_GRUP, V_REC.RULAJC_GRUP,  V_REC.RULAJVP_GRUP, V_REC.RULAJVC_GRUP,
            V_REC.An, V_REC.Luna);

       UPDATE TMP_NCONTRULSUB
       SET
         CODCONTRUL = aCOD
       WHERE
         CODCONTRUL = V_REC.CODCONTRUL;

     END LOOP;

    INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
    SOLDI_IFRS, SOLDVI_IFRS,
    SOLDI_GRUP, SOLDVI_GRUP
    )
    SELECT SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
    SOLDI_IFRS, SOLDVI_IFRS,
    SOLDI_GRUP, SOLDVI_GRUP
    FROM TMP_NCONTSOLDSUB;

    INSERT INTO NCONTRULSUB (CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,
    RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
    RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP
    )
    SELECT SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,
    RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
    RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP
    FROM TMP_NCONTRULSUB;
  END IF;

END IF;


-- SUNT PE INITIALIZARI; AM SALVAT UN ANALITIC; RECALCULEZ SOLDURILE SI RULAJELE INTIALE ALE PARINTELUI
IF INITIALIZARI = 1 AND ACODPARINTE &gt; 0  THEN
   UPDATE_SOLD_PARINTE(aCODPARINTE);
   UPDATE_SOLD_SUB_PARINTE(aCODPARINTE);
   UPDATE_RULAJP_PARINTE(aCODPARINTE);
   UPDATE_RULAJP_SUB_PARINTE(aCODPARINTE);

--  SELECT COUNT(*) INTO NR FROM NCONT WHERE CODPARINTE = aCODPARINTE;
--  IF NR &gt; 0 THEN

--    SELECT COUNT(*) INTO NR
--    FROM
--      NCONTSOLD
--    WHERE
 --     CODCONT = ACODPARINTE
 --     AND AN = GET_AN_SOLDINI
 --     AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;

 --   IF NR = 0 THEN
 --     INSERT INTO NCONTSOLD (CODCONTSOLD, CODCONT, AN, LUNA)
--      VALUES
--      (SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, ACODPARINTE, GET_AN_SOLDINI, /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1);
--    END IF;

--    UPDATE NCONTSOLD
--    SET
--      (SOLDID, SOLDIC, SOLDVID, SOLDVIC,
--      SOLDI_IFRS, SOLDVI_IFRS,
--      SOLDI_GRUP, SOLDVI_GRUP
--      ) = (SELECT SUM(NVL(SOLDID, 0)), SUM(NVL(SOLDIC, 0)), SUM(NVL(SOLDVID, 0)), SUM(NVL(SOLDVIC, 0)),
--        SUM(NVL(SOLDI_IFRS, 0)),  SUM(NVL(SOLDVI_IFRS, 0)),
--        SUM(NVL(SOLDI_GRUP, 0)),  SUM(NVL(SOLDVI_GRUP, 0))
--      FROM NCONTSOLD S, NCONT C
--     WHERE
--        C.CODCONT        = S.CODCONT
--        AND C.CODPARINTE = ACODPARINTE
 --       AND S.AN         = GET_AN_SOLDINI
--        AND S.LUNA       = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/ 1
--      )
--    WHERE
--      CODCONT  = ACODPARINTE
--      AND  AN  = GET_AN_SOLDINI
--      AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1 ;


--    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = ACODPARINTE AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
--    IF NR = 0 THEN
--      INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, AN, LUNA) VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, ACODPARINTE, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
--    END IF;


--    UPDATE NCONTRUL
--    SET
--      (RULAJPD, RULAJPC, RULAJVPD, RULAJVPC,
--      RULAJP_IFRS, RULAJC_IFRS,  RULAJVP_IFRS, RULAJVC_IFRS,
--      RULAJP_GRUP, RULAJC_GRUP,  RULAJVP_GRUP, RULAJVC_GRUP

--      ) =
--      (
--        SELECT
--          SUM(NVL(RULAJPD, 0)),
--          SUM(NVL(RULAJPC, 0)),
--          SUM(NVL(RULAJVPD, 0)),
--          SUM(NVL(RULAJVPC, 0)),
--          SUM(NVL(RULAJP_IFRS, 0)),
--          SUM(NVL(RULAJC_IFRS, 0)),
--          SUM(NVL(RULAJVP_IFRS, 0)),
--          SUM(NVL(RULAJVC_IFRS, 0)),
 --         SUM(NVL(RULAJP_GRUP, 0)),
--          SUM(NVL(RULAJC_GRUP, 0)),
--          SUM(NVL(RULAJVP_GRUP, 0)),
--          SUM(NVL(RULAJVC_GRUP, 0))
--        FROM
--          NCONTRUL R, NCONT C
--        WHERE
--         C.CODCONT = R.CODCONT AND C.CODPARINTE = ACODPARINTE AND R.AN = PKG_GLOBALS.ANLUCRU AND R.LUNA = PKG_GLOBALS.LUNALUCRU
--      )
--    WHERE
--     CODCONT = ACODPARINTE AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
--  END IF;
END IF;

PRC_AL_REFRESH(&apos;NCONT1&apos;,  RecId);

-- nomPlanConturi  --&gt; 521
PKG_CFGTABLES.EXT_POSTRECORDS(521); 

NotifyModif(Operation, RecId, &apos;NCONT&apos;);


COMMIT; -- commit-ul asta trebuie sa ramana; procedurilde de mai jos contin si ele commit-uri


-- VERIFICARE REPARTIZARII SOLDURILOR / RULAJELOR PE ANALITICE

SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;

IF aCODPARINTE &gt; 0 AND PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU &gt; ANI * 12 + LUNAI
THEN
  DELETE TMP_NCONT_LUNA_1;
  PKG_INCHIDERI.MAKE_NCONT_LUNA(&apos;TMP_NCONT_LUNA_1&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);

   SELECT DISTINCT ANSTART, LUNASTART INTO ANINCEPUTREPARTIZARI, LUNAINCEPUTREPARTIZARI FROM NCONT1 WHERE CODCONT IN (SELECT CODCONT FROM NCONT WHERE CODPARINTE = aCODPARINTE) AND
         ANSTART * 12 + LUNASTART = (SELECT MIN(ANSTART * 12 + LUNASTART) FROM NCONT1 WHERE CODCONT IN(SELECT CODCONT FROM NCONT WHERE CODPARINTE = aCODPARINTE));

  IF ANINCEPUTREPARTIZARI = PKG_GLOBALS.ANLUCRU AND LUNAINCEPUTREPARTIZARI = PKG_GLOBALS.LUNALUCRU THEN
  FOR V_RECPARINTE IN (SELECT * FROM TMP_NCONT_LUNA_1 WHERE CODCONT = aCODPARINTE ) LOOP
    IF V_RECPARINTE.NRANALITICE = 0 THEN -- PARINTELE ARE ANALITICE DAR TOCMAI LE-AM FACUT ACTIVE DIN LUNI MAI MARI DECAT CEA CURENTA
       -- ACTUALIZEZ IN NCONTREP ANUL SI LUNA DE INCEPUT A REPARTIZARII
       UPDATE NCONTREP
       SET
        AN   = NVL(ANINCEPUTREPARTIZARI, 0),
        LUNA = NVL(LUNAINCEPUTREPARTIZARI, 0)
       WHERE
         CODCONT = aCODPARINTE;

       FOR V_RECANALITICE IN (SELECT * FROM NCONT WHERE CODPARINTE = aCODPARINTE) LOOP
         DELETE NCONTSOLD
         WHERE
           CODCONT = V_RECANALITICE.CODCONT
           AND AN   = GET_AN_SOLDINI
           AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
         DELETE NCONTRUL  WHERE CODCONT = V_RECANALITICE.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
       END LOOP;

    ELSE -- CONTUL PARINTE ARE ANALITICE IN LUNA DE LUCRU
      FOR V_RECANALITICE IN (SELECT * FROM NCONT WHERE CODPARINTE = aCODPARINTE) LOOP
        SELECT COUNT(*) INTO CONTUL_EXISTA_IN_LUNA FROM TMP_NCONT_LUNA_1 WHERE CODCONT = V_RECANALITICE.CODCONT;
        -- DACA PARINTELE ARE SOLDURI SI UN SINGUR ANALITIC IN LUNA CURENTA :
        -- 1. DISTRIBUI TOT SOLDUL/RULAJELE PE ANALITICUL ACTIV
        -- 2. RAD REPARTIZARILE DE PE ANALITICILE CARE NU SUNT ACTIVE IN LUNA CURENTA

        -- DACA SUNT MAI MULTE ANALITICE VERIFIC DACA CELE ACTIVE AU POZITII IN FISIERELE DE REPARTIZARI

         IF (V_RECPARINTE.NRANALITICE &gt;= 1) AND
         ((NVL(V_RECPARINTE.SOLDID,  0) &lt;&gt;  0 OR NVL(V_RECPARINTE.SOLDIC,  0) &lt;&gt; 0 OR NVL(V_RECPARINTE.SOLDVID,  0) &lt;&gt; 0 OR NVL(V_RECPARINTE.SOLDVIC, 0)  &lt;&gt; 0 OR
           NVL(V_RECPARINTE.RULAJPD, 0) &lt;&gt;  0 OR NVL(V_RECPARINTE.RULAJPC, 0) &lt;&gt; 0 OR NVL(V_RECPARINTE.RULAJVPD, 0) &lt;&gt; 0 OR NVL(V_RECPARINTE.RULAJVPC, 0) &lt;&gt; 0))
         THEN
           IF CONTUL_EXISTA_IN_LUNA = 1 THEN
             -- NCONTREP
              SELECT COUNT(*) INTO NR FROM NCONTREP WHERE CODCONT = aCODPARINTE;
              IF NR = 0 THEN
                INSERT INTO NCONTREP (CODCONTREP, CODCONT, AN, LUNA)
                VALUES (SEQ_NCONTREP_CODCONTREP.NEXTVAL, aCODPARINTE, ANINCEPUTREPARTIZARI, LUNAINCEPUTREPARTIZARI);
              ELSE
                UPDATE NCONTREP
                SET
                  AN   = ANINCEPUTREPARTIZARI,
                  LUNA = LUNAINCEPUTREPARTIZARI
                WHERE
                  CODCONT = aCODPARINTE;
              END IF;

          --  NCONTSOLD :4:5:6:7
              SELECT COUNT(*) INTO NR FROM NCONTSOLD
              WHERE
                CODCONT = V_RECANALITICE.CODCONT
                AND AN = GET_AN_SOLDINI
                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
              IF NR = 0 THEN
                 INSERT INTO NCONTSOLD(CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
                 SOLDI_IFRS, SOLDVI_IFRS,
                 SOLDI_GRUP, SOLDVI_GRUP,
                 AN, LUNA)
                 VALUES (SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL, V_RECANALITICE.CODCONT,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDID
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDIC
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVID
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVIC
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDI_IFRS
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVI_IFRS
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDI_GRUP
                    ELSE 0
                  END,
                  CASE
                    WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVI_GRUP
                    ELSE 0
                  END,
                  GET_AN_SOLDINI,
                  /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1);
              ELSE
                UPDATE NCONTSOLD
                SET
                  SOLDID      = V_RECPARINTE.SOLDID,
                  SOLDIC      = V_RECPARINTE.SOLDIC,
                  SOLDVID     = V_RECPARINTE.SOLDVID,
                  SOLDVIC     = V_RECPARINTE.SOLDVIC,
                  SOLDI_IFRS  = V_RECPARINTE.SOLDI_IFRS,
                  SOLDVI_IFRS = V_RECPARINTE.SOLDVI_IFRS,
                  SOLDI_GRUP  = V_RECPARINTE.SOLDI_GRUP,
                  SOLDVI_GRUP = V_RECPARINTE.SOLDVI_GRUP
                WHERE
                  V_RECPARINTE.NRANALITICE = 1 AND CODCONT = V_RECANALITICE.CODCONT
                  AND AN = GET_AN_SOLDINI
                  AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
              END IF;

              IF V_RECPARINTE.NRANALITICE = 1 THEN --preiau solduri pe subunitati de ;a parinte
                 FOR V_REC_SOLD IN (SELECT SS.* FROM
                                    NCONTSOLD S,
                                    NCONTSOLDSUB SS
                                   WHERE
                                     CODCONT = V_RECPARINTE.CODCONT
                                     AND AN = GET_AN_SOLDINI
                                     AND LUNA = 1
                                     AND SS.CODCONTSOLD = S.CODCONTSOLD
                                   )
                LOOP
                  BEGIN
                    SELECT CODCONTSOLD INTO aCODCONTSOLD FROM NCONTSOLD WHERE CODCONT = V_RECANALITICE.CODCONT AND  AN = GET_AN_SOLDINI AND LUNA = 1;
                    EXCEPTION WHEN OTHERS THEN aCODCONTSOLD := 0;
                  END;

                  IF COALESCE(aCODCONTSOLD, 0) &lt;&gt; 0 THEN
                    UPDATE NCONTSOLDSUB
                    SET
                      SOLDID      = V_REC_SOLD.SOLDID,
                      SOLDIC      = V_REC_SOLD.SOLDIC,
                      SOLDVID     = V_REC_SOLD.SOLDVID,
                      SOLDVIC     = V_REC_SOLD.SOLDVIC,
                      SOLDI_IFRS  = V_REC_SOLD.SOLDI_IFRS,
                      SOLDVI_IFRS = V_REC_SOLD.SOLDVI_IFRS,
                      SOLDI_GRUP  = V_REC_SOLD.SOLDI_GRUP,
                      SOLDVI_GRUP = V_REC_SOLD.SOLDVI_GRUP
                    WHERE
                      CODCONTSOLD = aCODCONTSOLD
                      AND SUBUNITATEA =  V_REC_SOLD.SUBUNITATEA;

                    if  SQL%notfound then
                       INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB,
                                                CODCONTSOLD,
                                                SUBUNITATEA,
                                                SOLDID,
                                                SOLDIC,
                                                SOLDVID,
                                                SOLDVIC,
                                                SOLDI_IFRS,
                                                SOLDVI_IFRS,
                                                SOLDI_GRUP,
                                                SOLDVI_GRUP)
                       VALUES(SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL,
                             aCODCONTSOLD,
                             V_REC_SOLD.SUBUNITATEA,
                             V_REC_SOLD.SOLDID,
                             V_REC_SOLD.SOLDIC,
                             V_REC_SOLD.SOLDVID,
                             V_REC_SOLD.SOLDVIC,
                             V_REC_SOLD.SOLDI_IFRS,
                             V_REC_SOLD.SOLDVI_IFRS,
                             V_REC_SOLD.SOLDI_GRUP,
                             V_REC_SOLD.SOLDVI_GRUP);

                    end if;


                  END IF;

                END LOOP;
              END IF;



          --  NCONTREPSOLD
              SELECT COUNT(*) INTO NR FROM NCONTREPSOLD WHERE CODCONT =  V_RECANALITICE.CODCONT;

              IF NR = 0 THEN
                INSERT INTO NCONTREPSOLD(CODCONTREPSOLD, CODCONT, CODPARINTE, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
                SOLDI_IFRS, SOLDVI_IFRS,
                SOLDI_GRUP, SOLDVI_GRUP
                )
                VALUES (SEQ_NCONTREPSOLD_CODCONTREPS.NEXTVAL, V_RECANALITICE.CODCONT, aCODPARINTE,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDID FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDID
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDIC FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDIC
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDVID FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVID
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDVIC FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/ 1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVIC
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDI_IFRS FROM NCONTSOLD
                                              WHERE CODCONT = V_RECANALITICE.CODCONT
                                              AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL */ 1
                                              AND AN   = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDI_IFRS
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDVI_IFRS FROM NCONTSOLD
                                              WHERE
                                                CODCONT  = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL */ 1
                                                AND AN   = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVI_IFRS
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDI_GRUP FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL */1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDI_GRUP
                  ELSE 0
                END,
                CASE
                  WHEN INITIALIZARI = 1 THEN (SELECT SOLDVI_GRUP FROM NCONTSOLD
                                              WHERE
                                                CODCONT = V_RECANALITICE.CODCONT
                                                AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL */ 1
                                                AND AN = GET_AN_SOLDINI)
                  WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.SOLDVI_GRUP
                  ELSE 0
                END
               );
              ELSE
                UPDATE NCONTREPSOLD
                SET
                  SOLDID      = V_RECPARINTE.SOLDID,
                  SOLDIC      = V_RECPARINTE.SOLDIC,
                  SOLDVID     = V_RECPARINTE.SOLDVID,
                  SOLDVIC     = V_RECPARINTE.SOLDVIC,
                  SOLDI_IFRS  = V_RECPARINTE.SOLDI_IFRS,
                  SOLDVI_IFRS = V_RECPARINTE.SOLDVI_IFRS,
                  SOLDI_GRUP  = V_RECPARINTE.SOLDI_GRUP,
                  SOLDVI_GRUP = V_RECPARINTE.SOLDVI_GRUP
                WHERE
                  V_RECPARINTE.NRANALITICE = 1 AND CODCONT = V_RECANALITICE.CODCONT;
              END IF;

              IF V_RECPARINTE.NRANALITICE = 1 THEN -- AICI SUBUNITATI
                BEGIN
                  SELECT CODCONTREPSOLD INTO ACODCONTREPSOLD
                  FROM
                    NCONTREPSOLD
                  WHERE
                    CODCONT = V_RECANALITICE.CODCONT;
                  EXCEPTION WHEN OTHERS THEN aCODCONTREPSOLD := 0;
                END;

                IF aCODCONTREPSOLD &lt;&gt; 0 THEN

                  FOR V_REC_SOLDSUB IN
                  (SELECT SS.* FROM NCONTSOLD S, NCONTSOLDSUB SS
                   WHERE
                     AN = PKG_GLOBALS.ANLUCRU
                     AND LUNA = 1
                     AND S.CODCONT = V_RECPARINTE.CODCONT
                     AND SS.CODCONTSOLD = S.CODCONTSOLD
                   )
                  LOOP
                    BEGIN
                      SELECT CODREPSOLDSUB INTO aCODCONTREPSOLDSUB
                      FROM
                        NCONTREPSOLDSUB SS
                      WHERE
                        SS.CODCONTREPSOLD = aCODCONTREPSOLD
                        AND SUBUNITATEA = V_REC_SOLDSUB.SUBUNITATEA;
                      EXCEPTION WHEN OTHERS THEN aCODCONTREPSOLDSUB := 0;
                    END ;
                    IF aCODCONTREPSOLDSUB = 0 THEN
                    INSERT INTO NCONTREPSOLDSUB
                    (CODREPSOLDSUB,
                    CODCONTREPSOLD,
                    SUBUNITATEA,
                    SOLDID,
                    SOLDIC,
                    SOLDVID,
                    SOLDVIC,
                    SOLDI_IFRS,
                    SOLDVI_IFRS,
                    SOLDI_GRUP,
                    SOLDVI_GRUP)
                   VALUES
                   (SEQ_NCONTREPSOLDSUB_COD.NEXTVAL,
                    aCODCONTREPSOLD,
                    V_REC_SOLDSUB.SUBUNITATEA,
                    V_REC_SOLDSUB.SOLDID,
                    V_REC_SOLDSUB.SOLDIC,
                    V_REC_SOLDSUB.SOLDVID,
                    V_REC_SOLDSUB.SOLDVIC,
                    V_REC_SOLDSUB.SOLDI_IFRS,
                    V_REC_SOLDSUB.SOLDVI_IFRS,
                    V_REC_SOLDSUB.SOLDI_GRUP,
                    V_REC_SOLDSUB.SOLDVI_GRUP);
                    ELSE
                      UPDATE NCONTREPSOLDSUB
                      SET
                        SOLDID      = V_REC_SOLDSUB.SOLDID,
                        SOLDIC      = V_REC_SOLDSUB.SOLDIC,
                        SOLDVID     = V_REC_SOLDSUB.SOLDVID,
                        SOLDVIC     = V_REC_SOLDSUB.SOLDVIC,
                        SOLDI_IFRS  = V_REC_SOLDSUB.SOLDI_IFRS,
                        SOLDVI_IFRS = V_REC_SOLDSUB.SOLDVI_IFRS,
                        SOLDI_GRUP  = V_REC_SOLDSUB.SOLDI_GRUP,
                        SOLDVI_GRUP = V_REC_SOLDSUB.SOLDVI_GRUP
                      WHERE
                        CODREPSOLDSUB = aCODCONTREPSOLDSUB  ;
                    END IF;


                  END LOOP;
                END IF;
              END IF;

          --  NCONTRUL :8:9:10
              SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

              IF NR = 0 THEN
                INSERT INTO NCONTRUL ( CodContRul, CodCont, RulajPD, RulajPC, RulajVPD, RulajVPC,
                RULAJP_IFRS, RULAJC_IFRS, RULAJVP_IFRS, RULAJVC_IFRS,
                RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP,
                An, Luna )
                   VALUES (seq_NCONTRUL_CodContRul.Nextval, V_RECANALITICE.CODCONT,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RulajPD
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RulajPC
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RulajVPD
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RulajVPC
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJP_IFRS
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJC_IFRS
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVP_IFRS
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVC_IFRS
                     ELSE 0
                   END,


                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJP_GRUP
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJC_GRUP
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVP_GRUP
                     ELSE 0
                   END,
                   CASE
                     WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVC_GRUP
                     ELSE 0
                   END,
                   PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
              ELSE
                  UPDATE NCONTRUL
                  SET
                    RULAJPD     = V_RECPARINTE.RULAJPD,
                    RULAJPC     = V_RECPARINTE.RULAJPC,
                    RULAJVPD    = V_RECPARINTE.RULAJVPD,
                    RULAJVPC    = V_RECPARINTE.RULAJVPC,
                    RULAJP_IFRS = V_RECPARINTE.RULAJP_IFRS,
                    RULAJC_IFRS = V_RECPARINTE.RULAJC_IFRS,
                    RULAJVP_IFRS = V_RECPARINTE.RULAJVP_IFRS,
                    RULAJVC_IFRS = V_RECPARINTE.RULAJVC_IFRS,
                    RULAJP_GRUP  = V_RECPARINTE.RULAJP_GRUP,
                    RULAJC_GRUP = V_RECPARINTE.RULAJC_GRUP,
                    RULAJVP_GRUP = V_RECPARINTE.RULAJVP_GRUP,
                    RULAJVC_GRUP = V_RECPARINTE.RULAJVC_GRUP
                  WHERE
                    V_RECPARINTE.NRANALITICE = 1 AND CODCONT = V_RECANALITICE.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
              END IF;

          --  NCONTREPRUL
              SELECT COUNT(*) INTO NR FROM NCONTREPRUL WHERE CODCONT =  V_RECANALITICE.CODCONT;

              IF NR = 0 THEN
                INSERT INTO NCONTREPRUL (CODCONTREPRUL, CODCONT, CODPARINTE,
                RULAJPD,
                RULAJPC,
                RULAJVPD,
                RULAJVPC,
                RULAJP_IFRS,
                RULAJC_IFRS,
                RULAJVP_IFRS, RULAJVC_IFRS,
                RULAJP_GRUP, RULAJC_GRUP, RULAJVP_GRUP, RULAJVC_GRUP
                )
                VALUES (SEQ_NCONTREPRUL_CODCONTREPRUL.NEXTVAL, V_RECANALITICE.CODCONT, aCODPARINTE,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJPD FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJPD
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJPC FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJPC
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVPD FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVPD
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVPC FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVPC
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJP_IFRS FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJP_IFRS
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJC_IFRS FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJC_IFRS
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVP_IFRS FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVP_IFRS
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVC_IFRS FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVC_IFRS
                   ELSE 0
                 END,

                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJP_GRUP FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJP_GRUP
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJC_GRUP FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJC_GRUP
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVP_GRUP FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVP_GRUP
                   ELSE 0
                 END,
                 CASE
                   WHEN INITIALIZARI = 1 THEN (SELECT RULAJVC_GRUP FROM NCONTRUL WHERE CODCONT = V_RECANALITICE.CODCONT AND LUNA = PKG_GLOBALS.LUNALUCRU AND AN = PKG_GLOBALS.ANLUCRU)
                   WHEN V_RECPARINTE.NRANALITICE = 1 THEN V_RECPARINTE.RULAJVC_GRUP
                   ELSE 0
                 END
                 );
              ELSE
                UPDATE NCONTREPRUL
                SET
                  RULAJPD  = V_RECPARINTE.RULAJPD,
                  RULAJPC  = V_RECPARINTE.RULAJPC,
                  RULAJVPD = V_RECPARINTE.RULAJVPD,
                  RULAJVPC = V_RECPARINTE.RULAJVPC,
                  RULAJP_IFRS = V_RECPARINTE.RULAJP_IFRS,
                  RULAJC_IFRS = V_RECPARINTE.RULAJC_IFRS,
                  RULAJVP_IFRS = V_RECPARINTE.RULAJVP_IFRS,
                  RULAJVC_IFRS = V_RECPARINTE.RULAJVC_IFRS,
                  RULAJP_GRUP = V_RECPARINTE.RULAJP_GRUP,
                  RULAJC_GRUP = V_RECPARINTE.RULAJC_GRUP,
                  RULAJVP_GRUP = V_RECPARINTE.RULAJVP_GRUP,
                  RULAJVC_GRUP = V_RECPARINTE.RULAJVC_GRUP
                WHERE
                  V_RECPARINTE.NRANALITICE = 1 AND CODCONT =  V_RECANALITICE.CODCONT;
              END IF;

              IF V_RECPARINTE.NRANALITICE = 1 THEN -- AICI SUBUNITATI RULAJE
                BEGIN
                  SELECT CODCONTREPRUL INTO ACODCONTREPRUL
                  FROM
                    NCONTREPRUL
                  WHERE
                    CODCONT = V_RECANALITICE.CODCONT;
                  EXCEPTION WHEN OTHERS THEN aCODCONTREPRUL := 0;
                END;

                IF aCODCONTREPRUL &lt;&gt; 0 THEN

                  FOR V_REC_SOLDSUB IN
                  (SELECT RS.* FROM NCONTRUL R, NCONTRULSUB RS
                   WHERE
                     AN = PKG_GLOBALS.ANLUCRU
                     AND LUNA = PKG_GLOBALS.LUNALUCRU
                     AND R.CODCONT = V_RECPARINTE.CODCONT
                     AND RS.CODCONTRUL = R.CODCONTRUL
                   )
                  LOOP
                    BEGIN
                      SELECT CODREPRULSUB INTO aCODCONTREPRULSUB
                      FROM
                        NCONTREPRULSUB RS
                      WHERE
                        RS.CODCONTREPRUL = aCODCONTREPRUL
                        AND SUBUNITATEA = V_REC_SOLDSUB.SUBUNITATEA;
                      EXCEPTION WHEN OTHERS THEN aCODCONTREPRULSUB := 0;
                    END ;
                    IF aCODCONTREPRULSUB = 0 THEN
                    INSERT INTO NCONTREPRULSUB
                    (CODREPRULSUB,
                     CODCONTREPRUL,
                     SUBUNITATEA,
                     RULAJPD,
                     RULAJPC,
                     RULAJVPD,
                     RULAJVPC,
                     RULAJP_IFRS,
                     RULAJC_IFRS,
                     RULAJVP_IFRS,
                     RULAJVC_IFRS,
                     RULAJP_GRUP,
                     RULAJC_GRUP,
                     RULAJVP_GRUP,
                     RULAJVC_GRUP
                     )
                   VALUES
                   (SEQ_NCONTREPRULSUB_COD.NEXTVAL,
                    aCODCONTREPRUL,
                    V_REC_SOLDSUB.SUBUNITATEA,
                    V_REC_SOLDSUB.RULAJPD,
                    V_REC_SOLDSUB.RULAJPC,
                    V_REC_SOLDSUB.RULAJVPD,
                    V_REC_SOLDSUB.RULAJVPC,
                    V_REC_SOLDSUB.RULAJP_IFRS,
                    V_REC_SOLDSUB.RULAJC_IFRS,
                    V_REC_SOLDSUB.RULAJVP_IFRS,
                    V_REC_SOLDSUB.RULAJVC_IFRS,
                    V_REC_SOLDSUB.RULAJP_GRUP,
                    V_REC_SOLDSUB.RULAJC_GRUP,
                    V_REC_SOLDSUB.RULAJVP_GRUP,
                    V_REC_SOLDSUB.RULAJVC_GRUP
                    );
                    ELSE
                      UPDATE NCONTREPRULSUB
                      SET
                        RULAJPD      = V_REC_SOLDSUB.RULAJPD,
                        RULAJPC      = V_REC_SOLDSUB.RULAJPC,
                        RULAJVPD     = V_REC_SOLDSUB.RULAJVPD,
                        RULAJVPC     = V_REC_SOLDSUB.RULAJVPC,
                        RULAJP_IFRS  = V_REC_SOLDSUB.RULAJP_IFRS,
                        RULAJC_IFRS  = V_REC_SOLDSUB.RULAJC_IFRS,
                        RULAJVP_IFRS = V_REC_SOLDSUB.RULAJVP_IFRS,
                        RULAJVC_IFRS = V_REC_SOLDSUB.RULAJVC_IFRS,
                        RULAJP_GRUP  = V_REC_SOLDSUB.RULAJP_GRUP,
                        RULAJC_GRUP  = V_REC_SOLDSUB.RULAJC_GRUP,
                        RULAJVP_GRUP =  V_REC_SOLDSUB.RULAJVP_GRUP,
                        RULAJVC_GRUP = V_REC_SOLDSUB.RULAJVC_GRUP
                      WHERE
                        CODREPRULSUB = aCODCONTREPRULSUB  ;
                    END IF;


                  END LOOP;
                END IF;

              END IF;

           ELSE -- ANALITICUL ANALIZAT NU MAI EXISTA IN LUNA CURENTA. TREBUIE SA-I RAD REPARTIZARILE
             DELETE NCONTSOLD
            WHERE
              CODCONT = V_RECANALITICE.CODCONT
              AND AN = GET_AN_SOLDINI
              AND LUNA = /*PKG_GLOBALS.LUNA_START_AN_CONTABIL*/1;
             DELETE NCONTRUL  WHERE CODCONT = V_RECANALITICE.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

             UPDATE NCONTREPRUL
             SET
               RULAJPD  = 0,
               RULAJPC  = 0,
               RULAJVPD = 0,
               RULAJVPC = 0,
               RULAJP_IFRS = 0,
               RULAJC_IFRS = 0,
               RULAJVP_IFRS = 0,
               RULAJVC_IFRS = 0,
               RULAJP_GRUP = 0,
               RULAJC_GRUP = 0,
               RULAJVP_GRUP = 0,
               RULAJVC_GRUP = 0
             WHERE
             CODCONT =  V_RECANALITICE.CODCONT;

             UPDATE NCONTREPSOLD
             SET
               SOLDID      = 0,
               SOLDIC      = 0,
               SOLDVID     = 0,
               SOLDVIC     = 0,
               SOLDI_IFRS  = 0,
               SOLDVI_IFRS = 0,
               SOLDI_GRUP  = 0,
               SOLDVI_GRUP = 0
             WHERE
             CODCONT =  V_RECANALITICE.CODCONT;
           END IF;
         END IF; -- AM ANALITICE ACTIVE SI SOLD DE DITRIBUIT
      END LOOP;
    END IF;
    COMMIT;
  END LOOP;
  END IF;


END IF;
END;



FUNCTION GETNUMARANALITICE(CONT IN NUMBER, UNANSTART IN NUMBER, OLUNASTART IN NUMBER) RETURN NUMBER
IS
RECNO INTEGER := 0;
BEGIN
  SELECT COUNT(*) INTO RECNO FROM NCONT N
  WHERE
   CODPARINTE = CONT AND
  ( SELECT COUNT(*) FROM NCONT1 N1 WHERE N.CODCONT = N1.CODCONT AND
    GETDATA(UNANSTART, OLUNASTART) &gt;= GETDATA(ANSTART, LUNASTART)) &gt; 0;
  RETURN RECNO;
END;



PROCEDURE ECHIV_CONTSERV_INTRARI1
IS
BEGIN
 -- CONTSERV INTRARI
  FOR V_REC IN
  ( SELECT
      E.CONTVECHI,
      I1.CODINTR1,
      I.CODINTR,
      I.TIPDOC,
      MIN(E.CONTNOU) AS CONTNOU
    FROM
      NCONTECHIV E,
      INTRARI1 I1,
      INTRARI I
    WHERE
      E.AN = PKG_GLOBALS.ANLUCRU
      AND I1.CODINTR = I.CODINTR
      AND I.AN = E.AN
      AND I1.CONTSERV = E.CONTVECHI
    GROUP BY
        E.CONTVECHI,
        I1.CODINTR1,
        I.CODINTR,
        I.TIPDOC
  )
  LOOP
     UPDATE INTRARI1
     SET
       CONTSERV = V_REC.CONTNOU
     WHERE
       CODINTR1 = V_REC.CODINTR1;

     UPDATE JURNAL1
     SET
       DIRTY = 1
     WHERE
       TIPDOC = V_REC.TIPDOC
       AND CODDOC = V_REC.CODINTR
       AND AN = PKG_GLOBALS.ANLUCRU;
  END LOOP;
END;


PROCEDURE ECHIV_CONTSERV_IESIRI1
IS
BEGIN
 -- CONTSERV IESIRI1
  FOR V_REC IN
  ( SELECT
      E.CONTVECHI,
      I1.CODIES1,
      I.CODIES,
      I.TIPDOC,
      MIN(E.CONTNOU) AS CONTNOU
    FROM
      NCONTECHIV E,
      IESIRI1 I1,
      IESIRI I
    WHERE
      E.AN = PKG_GLOBALS.ANLUCRU
      AND I1.CODIES= I.CODIES
      AND I.AN = E.AN
      AND I1.CONTSERV = E.CONTVECHI
    GROUP BY
        E.CONTVECHI,
        I1.CODIES1,
        I.CODIES,
        I.TIPDOC
  )
  LOOP
     UPDATE IESIRI1
     SET
       CONTSERV = V_REC.CONTNOU
     WHERE
       CODIES1 = V_REC.CODIES1;

     UPDATE JURNAL1
     SET
       DIRTY = 1
     WHERE
       TIPDOC = V_REC.TIPDOC
       AND CODDOC = V_REC.CODIES
       AND AN = PKG_GLOBALS.ANLUCRU;
  END LOOP;
END;

PROCEDURE ECHIV_CONTSERV_NART
IS
BEGIN
  FOR V_REC IN
  (
  SELECT
    E.CONTVECHI,
    A.CODARTICOL,
    MIN(E.CONTNOU) AS CONTNOU
  FROM
    NCONTECHIV E,
    NART A
  WHERE
    E.AN = PKG_GLOBALS.ANLUCRU
    AND A.CONTSERVICIU = E.CONTVECHI
  GROUP BY
      E.CONTVECHI,
      A.CODARTICOL
  )
  LOOP
     UPDATE NART
     SET
       CONTSERVICIU = V_REC.CONTNOU
     WHERE
       CODARTICOL = V_REC.CODARTICOL;
  END LOOP;

END;

FUNCTION CONTECHIVALAT(aCODCONT IN NUMBER) RETURN NUMBER
IS
 Res NUMBER(20) := 0;
BEGIN
  SELECT NVL(MIN(CONTNOU), 0) INTO RES FROM NCONTECHIV WHERE CONTVECHI = aCODCONT AND AN = PKG_GLOBALS.GetANLUCRU;
  RETURN RES;
END;

FUNCTION CONTECHIVALENT(aCODCONT IN NUMBER) RETURN NUMBER
IS
 Res NUMBER(20) := 0;
BEGIN
  SELECT NVL(MIN(CONTNOU), aCODCONT) INTO RES FROM NCONTECHIV WHERE CONTVECHI = aCODCONT AND AN = PKG_GLOBALS.GetANLUCRU;
  RETURN RES;
END;


PROCEDURE ECHIV_IOART
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  ( SELECT *
    FROM
      IOART1 I1
    WHERE
      I1.ANSTART * 12 + I1.LUNASTART =
      (SELECT
         MAX(I2.ANSTART * 12 + I2.LUNASTART)
       FROM
         IOART1 I2
       WHERE
         CODIOART = I1.CODIOART
         AND I2.ANSTART * 12 + I2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
  )
  LOOP
    NeedEchiv := ContEchivalat(V_REC.CONT) +
                 ContEchivalat(V_REC.DIFERENTE) +
                 ContEchivalat(V_REC.CHELTUIELI) +
                 ContEchivalat(V_REC.VENITURI) +
                 ContEchivalat(V_REC.PLUSINVENTAR) +
                 ContEchivalat(V_REC.CHELTTVACOLECTAT) +
                 ContEchivalat(V_REC.CONTROTUNJIRI) +
                 ContEchivalat(V_REC.DIVERSE) +
                 ContEchivalat(V_REC.CUSTODIE) +
                 ContEchivalat(V_REC.PROVIZION) +
                 ContEchivalat(V_REC.CHELTPROVIZION) +
                 ContEchivalat(V_REC.VENITPROVIZION);

    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        INSERT INTO IOART1(CODIOART1, CODIOART, CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT, CONTROTUNJIRI, DIVERSE, CUSTODIE, ACCIZELATRANSFER, DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG, ANSTART, LUNASTART, PUSTANDARD, PROVIZION, CHELTPROVIZION, VENITPROVIZION)
        VALUES (SEQ_IOART1_CODIOART1.NEXTVAL, V_REC.CODIOART, ContEchivalent(V_REC.CONT), ContEchivalent(V_REC.DIFERENTE), ContEchivalent(V_REC.CHELTUIELI), ContEchivalent(V_REC.VENITURI), ContEchivalent(V_REC.PLUSINVENTAR), ContEchivalent(V_REC.MINUSINVENTAR), ContEchivalent(V_REC.CHELTTVACOLECTAT), ContEchivalent(V_REC.CONTROTUNJIRI), ContEchivalent(V_REC.DIVERSE), ContEchivalent(V_REC.CUSTODIE), V_REC.ACCIZELATRANSFER, V_REC.DESCARCAREG, V_REC.CONTABGEST, V_REC.BAZA, V_REC.DIFPRET, V_REC.ARETVANEEX, V_REC.TVANEEX, V_REC.MG, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, V_REC.PUSTANDARD, ContEchivalent(V_REC.PROVIZION), ContEchivalent(V_REC.CHELTPROVIZION), ContEchivalent(V_REC.VENITPROVIZION));

        prc_al_refresh(&apos;ioart1&apos;, V_REC.CODIOART);
      ELSE
        UPDATE IOART1
        SET
          CONT               = ContEchivalent(V_REC.CONT),
          DIFERENTE          = ContEchivalent(V_REC.DIFERENTE),
          CHELTUIELI         = ContEchivalent(V_REC.CHELTUIELI),
          VENITURI           = ContEchivalent(V_REC.VENITURI),
          PLUSINVENTAR       = ContEchivalent(V_REC.PLUSINVENTAR),
          MINUSINVENTAR      = ContEchivalent(V_REC.MINUSINVENTAR),
          CHELTTVACOLECTAT   = ContEchivalent(V_REC.CHELTTVACOLECTAT),
          CONTROTUNJIRI      = ContEchivalent(V_REC.CONTROTUNJIRI),
          DIVERSE            = ContEchivalent(V_REC.DIVERSE),
          CUSTODIE           = ContEchivalent(V_REC.CUSTODIE),
          PROVIZION          = ContEchivalent(V_REC.PROVIZION),
          CHELTPROVIZION     = ContEchivalent(V_REC.CHELTPROVIZION),
          VENITPROVIZION     = ContEchivalent(V_REC.VENITPROVIZION)
        WHERE
          CODIOART1 = V_REC.CODIOART1;
      END IF;

    END IF;

  END LOOP;

END;



PROCEDURE ECHIV_IOPART
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  ( SELECT *
    FROM
      IOPART1 I1
    WHERE
      I1.ANSTART * 12 + I1.LUNASTART =
      (SELECT
         MAX(I2.ANSTART * 12 + I2.LUNASTART)
       FROM
         IOPART1 I2
       WHERE
         CODIOPART = I1.CODIOPART
         AND I2.ANSTART * 12 + I2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
  )
  LOOP
    NeedEchiv := ContEchivalat(V_REC.CONTFURNIZOR) +
                 ContEchivalat(V_REC.CONTCLIENT) +
                 ContEchivalat(V_REC.CONTFURNAVANS) +
                 ContEchivalat(V_REC.CONTCLIENTAVANS) +
                 ContEchivalat(V_REC.CONTFURNAVIZ) +
                 ContEchivalat(V_REC.CONTCLIENTAVIZ) +
                 ContEchivalat(V_REC.CONTFURNMF) +
                 ContEchivalat(V_REC.CONTCREDITD) +
                 ContEchivalat(V_REC.CONTDEBITD) +
                 ContEchivalat(V_REC.CONTLITIGII) +
                 ContEchivalat(V_REC.CONTFURNAVS) +
                 ContEchivalat(V_REC.CONTFURNAVIC) +
                 ContEchivalat(V_REC.CONTFURNAVIN) +
                 ContEchivalat(V_REC.CONTTERTI) +
                 ContEchivalat(V_REC.CONTFURNLEAS) +
                 ContEchivalat(V_REC.CONTNCRF) +
                 ContEchivalat(V_REC.CONTNCRC) +
                 ContEchivalat(V_REC.CONTCHELTAVANS) +
                 ContEchivalat(V_REC.CONTVENITAVANS) +
                 ContEchivalat(V_REC.CONTGARANTIEEF) +
                 ContEchivalat(V_REC.CONTGARANTIETF) +
                 ContEchivalat(V_REC.CONTGARANTIEEC) +
                 ContEchivalat(V_REC.CONTGARANTIETC) +
                 ContEchivalat(V_REC.CONTSUPLIMF1) +
                 ContEchivalat(V_REC.CONTSUPLIMF2) +
                 ContEchivalat(V_REC.CONTSUPLIMF3) +
                 ContEchivalat(V_REC.CONTSUPLIMF4) +
                 ContEchivalat(V_REC.CONTSUPLIMF5) +
                 ContEchivalat(V_REC.CONTSUPLIMC1) +
                 ContEchivalat(V_REC.CONTSUPLIMC2) +
                 ContEchivalat(V_REC.CONTSUPLIMC3) +
                 ContEchivalat(V_REC.CONTSUPLIMC4) +
                 ContEchivalat(V_REC.CONTSUPLIMC5) +
                 ContEchivalat(V_REC.CONTSUPLIMF6) +
                 ContEchivalat(V_REC.CONTSUPLIMF7) +
                 ContEchivalat(V_REC.CONTSUPLIMF8) +
                 ContEchivalat(V_REC.CONTSUPLIMF9) +
                 ContEchivalat(V_REC.CONTSUPLIMF10) +
                 ContEchivalat(V_REC.CONTSUPLIMF11) +
                 ContEchivalat(V_REC.CONTSUPLIMF12) +
                 ContEchivalat(V_REC.CONTSUPLIMF13) +
                 ContEchivalat(V_REC.CONTSUPLIMF14) +
                 ContEchivalat(V_REC.CONTSUPLIMF15) +
                 ContEchivalat(V_REC.CONTSUPLIMF16) +
                 ContEchivalat(V_REC.CONTSUPLIMF17) +
                 ContEchivalat(V_REC.CONTSUPLIMF18) +
                 ContEchivalat(V_REC.CONTSUPLIMF19) +
                 ContEchivalat(V_REC.CONTSUPLIMF20) +
                 ContEchivalat(V_REC.CONTSUPLIMF21) +
                 ContEchivalat(V_REC.CONTSUPLIMF22) +
                 ContEchivalat(V_REC.CONTSUPLIMF23) +
                 ContEchivalat(V_REC.CONTSUPLIMF24) +
                 ContEchivalat(V_REC.CONTSUPLIMF25) +
                 ContEchivalat(V_REC.CONTSUPLIMF26) +
                 ContEchivalat(V_REC.CONTSUPLIMF27) +
                 ContEchivalat(V_REC.CONTSUPLIMF28) +
                 ContEchivalat(V_REC.CONTSUPLIMF29) +
                 ContEchivalat(V_REC.CONTSUPLIMF30);



    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        INSERT INTO IOPART1(CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, CONTGARANTIEEF, CONTGARANTIETF, CONTGARANTIEEC, CONTGARANTIETC, CONTSUPLIMF1, CONTSUPLIMF2, CONTSUPLIMF3, CONTSUPLIMF4, CONTSUPLIMF5, CONTSUPLIMC1, CONTSUPLIMC2, CONTSUPLIMC3, CONTSUPLIMC4, CONTSUPLIMC5, CONTSUPLIMF6, CONTSUPLIMF7, CONTSUPLIMF8, CONTSUPLIMF9, CONTSUPLIMF10, CONTSUPLIMF11, CONTSUPLIMF12, CONTSUPLIMF13, CONTSUPLIMF14, CONTSUPLIMF15, CONTSUPLIMF16, CONTSUPLIMF17, CONTSUPLIMF18, CONTSUPLIMF19, CONTSUPLIMF20, CONTSUPLIMF21, CONTSUPLIMF22, CONTSUPLIMF23, CONTSUPLIMF24, CONTSUPLIMF25, CONTSUPLIMF26, CONTSUPLIMF27, CONTSUPLIMF28, CONTSUPLIMF29, CONTSUPLIMF30, TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP, ANSTART, LUNASTART)
        VALUES
        (
          SEQ_IOPART1_CODIOPART1.NEXTVAL,
          V_REC.CODIOPART,
          ContEchivalent(V_REC.CONTFURNIZOR),
          ContEchivalent(V_REC.CONTCLIENT),
          ContEchivalent(V_REC.CONTFURNAVANS),
          ContEchivalent(V_REC.CONTCLIENTAVANS),
          ContEchivalent(V_REC.CONTFURNAVIZ),
          ContEchivalent(V_REC.CONTCLIENTAVIZ),
          ContEchivalent(V_REC.CONTFURNMF),
          ContEchivalent(V_REC.CONTCREDITD),
          ContEchivalent(V_REC.CONTDEBITD),
          ContEchivalent(V_REC.CONTLITIGII),
          ContEchivalent(V_REC.CONTFURNAVS),
          ContEchivalent(V_REC.CONTFURNAVIC),
          ContEchivalent(V_REC.CONTFURNAVIN),
          ContEchivalent(V_REC.CONTTERTI),
          ContEchivalent(V_REC.CONTFURNLEAS),
          ContEchivalent(V_REC.CONTNCRF),
          ContEchivalent(V_REC.CONTNCRC),
          ContEchivalent(V_REC.CONTCHELTAVANS),
          ContEchivalent(V_REC.CONTVENITAVANS),
          ContEchivalent(V_REC.CONTGARANTIEEF),
          ContEchivalent(V_REC.CONTGARANTIETF),
          ContEchivalent(V_REC.CONTGARANTIEEC),
          ContEchivalent(V_REC.CONTGARANTIETC),
          ContEchivalent(V_REC.CONTSUPLIMF1),
          ContEchivalent(V_REC.CONTSUPLIMF2),
          ContEchivalent(V_REC.CONTSUPLIMF3),
          ContEchivalent(V_REC.CONTSUPLIMF4),
          ContEchivalent(V_REC.CONTSUPLIMF5),
          ContEchivalent(V_REC.CONTSUPLIMC1),
          ContEchivalent(V_REC.CONTSUPLIMC2),
          ContEchivalent(V_REC.CONTSUPLIMC3),
          ContEchivalent(V_REC.CONTSUPLIMC4),
          ContEchivalent(V_REC.CONTSUPLIMC5),
          ContEchivalent(V_REC.CONTSUPLIMF6),
          ContEchivalent(V_REC.CONTSUPLIMF7),
          ContEchivalent(V_REC.CONTSUPLIMF8),
          ContEchivalent(V_REC.CONTSUPLIMF9),
          ContEchivalent(V_REC.CONTSUPLIMF10),
          ContEchivalent(V_REC.CONTSUPLIMF11),
          ContEchivalent(V_REC.CONTSUPLIMF12),
          ContEchivalent(V_REC.CONTSUPLIMF13),
          ContEchivalent(V_REC.CONTSUPLIMF14),
          ContEchivalent(V_REC.CONTSUPLIMF15),
          ContEchivalent(V_REC.CONTSUPLIMF16),
          ContEchivalent(V_REC.CONTSUPLIMF17),
          ContEchivalent(V_REC.CONTSUPLIMF18),
          ContEchivalent(V_REC.CONTSUPLIMF19),
          ContEchivalent(V_REC.CONTSUPLIMF20),
          ContEchivalent(V_REC.CONTSUPLIMF21),
          ContEchivalent(V_REC.CONTSUPLIMF22),
          ContEchivalent(V_REC.CONTSUPLIMF23),
          ContEchivalent(V_REC.CONTSUPLIMF24),
          ContEchivalent(V_REC.CONTSUPLIMF25),
          ContEchivalent(V_REC.CONTSUPLIMF26),
          ContEchivalent(V_REC.CONTSUPLIMF27),
          ContEchivalent(V_REC.CONTSUPLIMF28),
          ContEchivalent(V_REC.CONTSUPLIMF29),
          ContEchivalent(V_REC.CONTSUPLIMF30),
          V_REC.TVANEEXF,
          V_REC.TVANEEXC,
          V_REC.TVANEEXP,
          V_REC.TVANEEXI,
          V_REC.TIP,
          PKG_GLOBALS.GETANLUCRU,
          PKG_GLOBALS.GETLUNALUCRU
        );
        PRC_AL_REFRESH(&apos;IOPART1&apos;, V_REC.CODIOPART);
      ELSE
        UPDATE IOPART1
        SET
          CONTFURNIZOR    = ContEchivalent(V_REC.CONTFURNIZOR),
          CONTCLIENT      = ContEchivalent(V_REC.CONTCLIENT),
          CONTFURNAVANS   = ContEchivalent(V_REC.CONTFURNAVANS),
          CONTCLIENTAVANS = ContEchivalent(V_REC.CONTCLIENTAVANS),
          CONTFURNAVIZ    = ContEchivalent(V_REC.CONTFURNAVIZ),
          CONTCLIENTAVIZ  = ContEchivalent(V_REC.CONTCLIENTAVIZ),
          CONTFURNMF      = ContEchivalent(V_REC.CONTFURNMF),
          CONTCREDITD     = ContEchivalent(V_REC.CONTCREDITD),
          CONTDEBITD      = ContEchivalent(V_REC.CONTDEBITD),
          CONTLITIGII     = ContEchivalent(V_REC.CONTLITIGII),
          CONTFURNAVS     = ContEchivalent(V_REC.CONTFURNAVS),
          CONTFURNAVIC    = ContEchivalent(V_REC.CONTFURNAVIC),
          CONTFURNAVIN    = ContEchivalent(V_REC.CONTFURNAVIN),
          CONTTERTI       = ContEchivalent(V_REC.CONTTERTI),
          CONTFURNLEAS    = ContEchivalent(V_REC.CONTFURNLEAS),
          CONTNCRF        = ContEchivalent(V_REC.CONTNCRF),
          CONTNCRC        = ContEchivalent(V_REC.CONTNCRC),
          CONTCHELTAVANS  = ContEchivalent(V_REC.CONTCHELTAVANS),
          CONTVENITAVANS  = ContEchivalent(V_REC.CONTVENITAVANS),
          CONTGARANTIEEF  = ContEchivalent(V_REC.CONTGARANTIEEF),
          CONTGARANTIETF  = ContEchivalent(V_REC.CONTGARANTIETF),
          CONTGARANTIEEC  = ContEchivalent(V_REC.CONTGARANTIEEC),
          CONTGARANTIETC  = ContEchivalent(V_REC.CONTGARANTIETC),
          CONTSUPLIMF1    = ContEchivalent(V_REC.CONTSUPLIMF1),
          CONTSUPLIMF2    = ContEchivalent(V_REC.CONTSUPLIMF2),
          CONTSUPLIMF3    = ContEchivalent(V_REC.CONTSUPLIMF3),
          CONTSUPLIMF4    = ContEchivalent(V_REC.CONTSUPLIMF4),
          CONTSUPLIMF5    = ContEchivalent(V_REC.CONTSUPLIMF5),
          CONTSUPLIMC1    = ContEchivalent(V_REC.CONTSUPLIMC1),
          CONTSUPLIMC2    = ContEchivalent(V_REC.CONTSUPLIMC2),
          CONTSUPLIMC3    = ContEchivalent(V_REC.CONTSUPLIMC3),
          CONTSUPLIMC4    = ContEchivalent(V_REC.CONTSUPLIMC4),
          CONTSUPLIMC5    = ContEchivalent(V_REC.CONTSUPLIMC5),
          CONTSUPLIMF6    = ContEchivalent(V_REC.CONTSUPLIMF6),
          CONTSUPLIMF7    = ContEchivalent(V_REC.CONTSUPLIMF7),
          CONTSUPLIMF8    = ContEchivalent(V_REC.CONTSUPLIMF8),
          CONTSUPLIMF9    = ContEchivalent(V_REC.CONTSUPLIMF9),
          CONTSUPLIMF10   = ContEchivalent(V_REC.CONTSUPLIMF10),
          CONTSUPLIMF11   = ContEchivalent(V_REC.CONTSUPLIMF11),
          CONTSUPLIMF12   = ContEchivalent(V_REC.CONTSUPLIMF12),
          CONTSUPLIMF13   = ContEchivalent(V_REC.CONTSUPLIMF13),
          CONTSUPLIMF14   = ContEchivalent(V_REC.CONTSUPLIMF14),
          CONTSUPLIMF15   = ContEchivalent(V_REC.CONTSUPLIMF15),
          CONTSUPLIMF16   = ContEchivalent(V_REC.CONTSUPLIMF16),
          CONTSUPLIMF17   = ContEchivalent(V_REC.CONTSUPLIMF17),
          CONTSUPLIMF18   = ContEchivalent(V_REC.CONTSUPLIMF18),
          CONTSUPLIMF19   = ContEchivalent(V_REC.CONTSUPLIMF19),
          CONTSUPLIMF20   = ContEchivalent(V_REC.CONTSUPLIMF20),
          CONTSUPLIMF21   = ContEchivalent(V_REC.CONTSUPLIMF21),
          CONTSUPLIMF22   = ContEchivalent(V_REC.CONTSUPLIMF22),
          CONTSUPLIMF23   = ContEchivalent(V_REC.CONTSUPLIMF23),
          CONTSUPLIMF24   = ContEchivalent(V_REC.CONTSUPLIMF24),
          CONTSUPLIMF25   = ContEchivalent(V_REC.CONTSUPLIMF25),
          CONTSUPLIMF26   = ContEchivalent(V_REC.CONTSUPLIMF26),
          CONTSUPLIMF27   = ContEchivalent(V_REC.CONTSUPLIMF27),
          CONTSUPLIMF28   = ContEchivalent(V_REC.CONTSUPLIMF28),
          CONTSUPLIMF29   = ContEchivalent(V_REC.CONTSUPLIMF29),
          CONTSUPLIMF30   = ContEchivalent(V_REC.CONTSUPLIMF30)
        WHERE
          CODIOPART1 = V_REC.CODIOPART1;
      END IF;

    END IF;

  END LOOP;

END;


PROCEDURE ECHIV_IOPERS
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  ( SELECT *
    FROM
      IOPERS1 I1
    WHERE
      I1.ANSTART * 12 + I1.LUNASTART =
      (SELECT
         MAX(I2.ANSTART * 12 + I2.LUNASTART)
       FROM
         IOPERS1 I2
       WHERE
         CODIOPERS = I1.CODIOPERS
         AND I2.ANSTART * 12 + I2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
  )
  LOOP

    NeedEchiv := ContEchivalat(V_REC.CONTAVANSDECONT)+
                 ContEchivalat(V_REC.CONTIMPUTATII)+
                 ContEchivalat(V_REC.CONTGARANTII)+
                 ContEchivalat(V_REC.CONTALTERETINERI)+
                 ContEchivalat(V_REC.CONTAVANS)+
                 ContEchivalat(V_REC.CONTLIKI)+
                 ContEchivalat(V_REC.CONTNERIDICATE)+
                 ContEchivalat(V_REC.CONTBOALA)+
                 ContEchivalat(V_REC.CONTPARTSAL)+
                 ContEchivalat(V_REC.CONTNATURA)+
                 ContEchivalat(V_REC.CONTECHIPAMENT)+
                 ContEchivalat(V_REC.CONTIMPOZIT);

    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        INSERT INTO IOPERS1(CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT, ANSTART, LUNASTART)
        VALUES (SEQ_IOPERS1_CODIOPERS1.NEXTVAL,
                V_REC.CODIOPERS,
                ContEchivalent(V_REC.CONTAVANSDECONT),
                ContEchivalent(V_REC.CONTIMPUTATII),
                ContEchivalent(V_REC.CONTGARANTII),
                ContEchivalent(V_REC.CONTALTERETINERI),
                ContEchivalent(V_REC.CONTAVANS),
                ContEchivalent(V_REC.CONTLIKI),
                ContEchivalent(V_REC.CONTNERIDICATE),
                ContEchivalent(V_REC.CONTBOALA),
                ContEchivalent(V_REC.CONTPARTSAL),
                ContEchivalent(V_REC.CONTNATURA),
                ContEchivalent(V_REC.CONTECHIPAMENT),
                ContEchivalent(V_REC.CONTIMPOZIT),
                PKG_GLOBALS.GETANLUCRU,
                PKG_GLOBALS.GETLUNALUCRU
               );
        PRC_AL_REFRESH(&apos;IOPERS1&apos;, V_REC.CODIOPERS);
      ELSE
        UPDATE IOPERS1
        SET
           CONTAVANSDECONT  = ContEchivalent(CONTAVANSDECONT),
           CONTIMPUTATII    = ContEchivalent(CONTIMPUTATII),
           CONTGARANTII     = ContEchivalent(CONTGARANTII),
           CONTALTERETINERI = ContEchivalent(CONTALTERETINERI),
           CONTAVANS        = ContEchivalent(CONTAVANS),
           CONTLIKI         = ContEchivalent(CONTLIKI),
           CONTNERIDICATE   = ContEchivalent(CONTNERIDICATE),
           CONTBOALA        = ContEchivalent(CONTBOALA),
           CONTPARTSAL      = ContEchivalent(CONTPARTSAL),
           CONTNATURA       = ContEchivalent(CONTNATURA),
           CONTECHIPAMENT   = ContEchivalent(CONTECHIPAMENT),
           CONTIMPOZIT      = ContEchivalent(CONTIMPOZIT)
        WHERE
          CODIOPERS1 = V_REC.CODIOPERS1;
      END IF;

    END IF;

  END LOOP;

END;



PROCEDURE ECHIV_CONSTANTE
IS
  NEEDECHIV     NUMBER(20) := 0;
  aCODCONSTLUNA NUMBER(20);
BEGIN
  FOR V_REC IN
  ( SELECT
      CL.*
    FROM
      CONSTLUNA CL,
      CONST1 C1
    WHERE
      CL.CODCONST1 = C1.CODCONST1
      AND C1.TIP IN (1, 2, 20)
      AND CL.ANSTART * 12 + CL.LUNASTART =
      (SELECT
         MAX(CL2.ANSTART * 12 + CL2.LUNASTART)
       FROM
         CONSTLUNA CL2
       WHERE
         CODCONST1 = CL.CODCONST1
         AND CL2.ANSTART * 12 + CL2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
    ORDER BY CL.CODCONSTLUNA
  )
  LOOP
    NeedEchiv := 0;
    FOR V_REC_V IN (SELECT * FROM CONSTVAL CV WHERE CV.CODCONSTLUNA = V_REC.CODCONSTLUNA)
    LOOP
      NeedEchiv := NeedEchiv + ContEchivalat(V_REC_V.VALOARE);
    END LOOP;

    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        aCODCONSTLUNA := SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL;
        INSERT INTO CONSTLUNA(CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
        VALUES (aCODCONSTLUNA,
                V_REC.CODCONST1,
                PKG_GLOBALS.GETANLUCRU,
                PKG_GLOBALS.GETLUNALUCRU,
                V_REC.USERID
               );

        FOR V_REC_V IN (SELECT * FROM CONSTVAL CV WHERE CV.CODCONSTLUNA = V_REC.CODCONSTLUNA)
        LOOP
          INSERT INTO CONSTVAL(VALOARE, CODCONSTLUNA)
          VALUES (CONTECHIVALENT(V_REC_V.VALOARE), aCODCONSTLUNA);
        END LOOP;


      ELSE
        FOR V_REC_V IN (SELECT * FROM CONSTVAL CV WHERE CV.CODCONSTLUNA = V_REC.CODCONSTLUNA)
        LOOP
         UPDATE CONSTVAL
         SET
           VALOARE = CONTECHIVALENT(V_REC_V.VALOARE)
         WHERE
           VALOARE = V_REC_V.VALOARE
           AND CODCONSTLUNA = V_REC_V.CODCONSTLUNA;
        END LOOP;
      END IF;

    END IF;

  END LOOP;

END;


PROCEDURE ECHIV_IOBANK
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  (
   SELECT *
    FROM
      IOBANK1 I1
    WHERE
      I1.ANSTART * 12 + I1.LUNASTART =
      (SELECT
         MAX(I2.ANSTART * 12 + I2.LUNASTART)
       FROM
         IOBANK1 I2
       WHERE
         CODIOBANK = I1.CODIOBANK
         AND I2.ANSTART * 12 + I2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
  )
  LOOP

    NeedEchiv :=  ContEchivalat(V_REC.CONT) +
                  ContEchivalat(V_REC.DOBANDA) +
                  ContEchivalat(V_REC.COMISION) +
                  ContEchivalat(V_REC.CHELTUIELICV) +
                  ContEchivalat(V_REC.VENITURICV) +
                  ContEchivalat(V_REC.PCEC) +
                  ContEchivalat(V_REC.PEFECTE) +
                  ContEchivalat(V_REC.PEFECTEREM) +
                  ContEchivalat(V_REC.ICEC) +
                  ContEchivalat(V_REC.IEFECTE) +
                  ContEchivalat(V_REC.IEFECTEREM);

    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        INSERT INTO IOBANK1(CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM, ANSTART, LUNASTART)
        VALUES(SEQ_IOBANK1_CODIOBANK1.NEXTVAL,
               V_REC.CODIOBANK,
               ContEchivalent(V_REC.CONT),
               ContEchivalent(V_REC.DOBANDA),
               ContEchivalent(V_REC.COMISION),
               ContEchivalent(V_REC.CHELTUIELICV),
               ContEchivalent(V_REC.VENITURICV),
               ContEchivalent(V_REC.PCEC),
               ContEchivalent(V_REC.PEFECTE),
               ContEchivalent(V_REC.PEFECTEREM),
               ContEchivalent(V_REC.ICEC),
               ContEchivalent(V_REC.IEFECTE),
               ContEchivalent(V_REC.IEFECTEREM),
               PKG_GLOBALS.GETANLUCRU,
               PKG_GLOBALS.GETLUNALUCRU
              );
        PRC_AL_REFRESH(&apos;IOBANK1&apos;, V_REC.CODIOBANK);
      ELSE
        UPDATE IOBANK1
        SET
          CONT         = ContEchivalent(V_REC.CONT),
          DOBANDA      = ContEchivalent(V_REC.DOBANDA),
          COMISION     = ContEchivalent(V_REC.COMISION),
          CHELTUIELICV = ContEchivalent(V_REC.CHELTUIELICV),
          VENITURICV   = ContEchivalent(V_REC.VENITURICV),
          PCEC         = ContEchivalent(V_REC.PCEC),
          PEFECTE      = ContEchivalent(V_REC.PEFECTE),
          PEFECTEREM   = ContEchivalent(V_REC.PEFECTEREM),
          ICEC         = ContEchivalent(V_REC.ICEC),
          IEFECTE      = ContEchivalent(V_REC.IEFECTE),
          IEFECTEREM   = ContEchivalent(V_REC.IEFECTEREM)
        WHERE
          CODIOBANK1 = V_REC.CODIOBANK1;
      END IF;

    END IF;

  END LOOP;

END;


PROCEDURE ECHIV_IOFILIAL
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  (
   SELECT *
    FROM
      IOFILIAL1 I1
    WHERE
      I1.ANSTART * 12 + I1.LUNASTART =
      (SELECT
         MAX(I2.ANSTART * 12 + I2.LUNASTART)
       FROM
         IOFILIAL1 I2
       WHERE
         CODIOFILIAL = I1.CODIOFILIAL
         AND I2.ANSTART * 12 + I2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
  )
  LOOP

    NeedEchiv :=  ContEchivalat(V_REC.CONTDECONTARE) +
                  ContEchivalat(V_REC.CONTDECONTSERV) +
                  ContEchivalat(V_REC.CONTDECONTCB) +
                  ContEchivalat(V_REC.CONTDECONTCMP) +
                  ContEchivalat(V_REC.CONTDECONTAREF);


    IF NeedEchiv &gt; 0 THEN
      IF V_REC.ANSTART * 12 + V_REC.LUNASTART &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU THEN
        INSERT INTO IOFILIAL1(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP, CONTDECONTAREF, ISFIRMA, ANSTART, LUNASTART)
        VALUES(SEQ_IOFILIAL1_CODIOFILIAL1.NEXTVAL,
               V_REC.CODIOFILIAL,
               ContEchivalent(V_REC.CONTDECONTARE),
               ContEchivalent(V_REC.CONTDECONTSERV),
               ContEchivalent(V_REC.CONTDECONTCB),
               ContEchivalent(V_REC.CONTDECONTCMP),
               ContEchivalent(V_REC.CONTDECONTAREF),
               V_REC.ISFIRMA,
               PKG_GLOBALS.GETANLUCRU,
               PKG_GLOBALS.GETLUNALUCRU
              );
        PRC_AL_REFRESH(&apos;IOFILIAL1&apos;, V_REC.CODIOFILIAL);
      ELSE
        UPDATE IOFILIAL1
        SET
          CONTDECONTARE  = ContEchivalent(CONTDECONTARE),
          CONTDECONTSERV = ContEchivalent(CONTDECONTSERV),
          CONTDECONTCB   = ContEchivalent(CONTDECONTCB),
          CONTDECONTCMP  = ContEchivalent(CONTDECONTCMP),
          CONTDECONTAREF = ContEchivalent(CONTDECONTAREF)
        WHERE
          CODIOFILIAL1 = V_REC.CODIOFILIAL1;
      END IF;

    END IF;

  END LOOP;

END;

PROCEDURE ECHIV_CORELATII
IS
BEGIN
    FOR V_REC IN
    (
    select
      CV.SIMBOL AS SIMBOLVECHI,
      CN.SIMBOL AS SIMBOLNOU
    from
      ncontechiv E,
      NCONT CV,
      NCONT CN
    where
      an = PKG_GLOBALS.GetANLUCRU
      AND CV.CODCONT = E.CONTVECHI
      AND CN.CODCONT = E.CONTNOU
    )
    LOOP
       UPDATE SITFINLIN
       SET
         CORELATIE = REPLACE(CORELATIE, &apos;&lt;&apos; || V_REC.SIMBOLVECHI || &apos;&gt;&apos;, &apos;&lt;&apos; || V_REC.SIMBOLNOU || &apos;&gt;&apos;)
       WHERE
         CORELATIE LIKE &apos;%&lt;&apos; || V_REC.SIMBOLVECHI || &apos;&gt;%&apos;;

       UPDATE SITFINLIN
       SET
         OBS = REPLACE(OBS, &apos;&lt;&apos; || V_REC.SIMBOLVECHI || &apos;&gt;&apos;, &apos;&lt;&apos; || V_REC.SIMBOLNOU || &apos;&gt;&apos;)
       WHERE
         OBS LIKE &apos;%&lt;&apos; || V_REC.SIMBOLVECHI || &apos;&gt;%&apos;;
END LOOP ;
END;


PROCEDURE ECHIV_NOTECREDIT
IS
  NEEDECHIV NUMBER(20) := 0;
BEGIN
  FOR V_REC IN
  (
   SELECT *
    FROM
      NOTECREDIT
    WHERE
      AN * 12 + LUNA &gt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GetLUNALUCRU
  )
  LOOP
    NeedEchiv :=  ContEchivalat(V_REC.CODCONTV) +
                  ContEchivalat(V_REC.CODCONTT) +
                  ContEchivalat(V_REC.CODCONTC) +
                  ContEchivalat(V_REC.CODCONTP) +
                  ContEchivalat(V_REC.CODCONTZ);

    IF NeedEchiv &gt; 0 THEN
      UPDATE NOTECREDIT
      SET
        CODCONTV    = ContEchivalent(V_REC.CODCONTV),
        CODCONTT    = ContEchivalent(V_REC.CODCONTT),
        CODCONTC    = ContEchivalent(V_REC.CODCONTC),
        CODCONTP    = ContEchivalent(V_REC.CODCONTP),
        CODCONTZ    = ContEchivalent(V_REC.CODCONTZ)
      WHERE
        CODNCREDIT = V_REC.CODNCREDIT;
    END IF;
  END LOOP;

END;

PROCEDURE SET_ECHIVALARI_AUTOMATE
IS
BEGIN
  ECHIV_CONTSERV_INTRARI1;
  ECHIV_CONTSERV_IESIRI1;
  ECHIV_CONTSERV_NART;
  ECHIV_IOART;
  ECHIV_IOPART;
  ECHIV_IOPERS;
  ECHIV_CONSTANTE;
  ECHIV_IOBANK;
  ECHIV_IOFILIAL;
  ECHIV_CORELATII;
  ECHIV_NOTECREDIT;
END;


PROCEDURE POST_NCONT_ECHIV
IS
 aCOD           NUMBER(20);
 aCODCONTSOLD   NUMBER(20);
 NR             NUMBER(10);

BEGIN
  FOR V_REC IN (SELECT * FROM NCONTECHIV WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1)
  LOOP
    DELETE FROM NCONTECHIVSUB WHERE CODCONTECHIV = V_REC.CODCONTECHIV;
    DELETE FROM NCONTECHIV    WHERE CODCONTECHIV = V_REC.CODCONTECHIV;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NCONTECHIV)
  LOOP
    aCOD := SEQ_NCONTECHIV_CODCONTECHIV.NEXTVAL;
    UPDATE TMP_NCONTECHIV
    SET
      CODCONTECHIV = aCOD
    WHERE
      CODCONTECHIV = V_REC.CODCONTECHIV;

    UPDATE TMP_NCONTECHIVSUB
    SET
      CODCONTECHIV = aCOD
    WHERE
      CODCONTECHIV = V_REC.CODCONTECHIV;

  END LOOP;

  INSERT INTO NCONTECHIV(CODCONTECHIV, CONTVECHI, CONTNOU, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, AN, LUNA)
  SELECT CODCONTECHIV, CONTVECHI, CONTNOU, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, PKG_GLOBALS.ANLUCRU, 1 FROM TMP_NCONTECHIV;

  INSERT INTO NCONTECHIVSUB(CODCONTECHIVSUB, CODCONTECHIV, CODSUBUNIT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP)
  SELECT SEQ_NCONTECHIVSUB_COD.NEXTVAL, CODCONTECHIV, CODSUBUNIT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP FROM TMP_NCONTECHIVSUB;

  FOR V_REC IN ( SELECT DISTINCT CONTNOU FROM
                (
                SELECT CONTNOU FROM NCONTECHIV WHERE AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1
                UNION
                SELECT CODUNIC AS CONTNOU FROM TMP_MANEVRA
                )
               )
  LOOP
     BEGIN
       SELECT CODCONTSOLD INTO aCODCONTSOLD FROM NCONTSOLD WHERE CODCONT = V_REC.CONTNOU AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = 1;
       EXCEPTION WHEN OTHERS THEN aCODCONTSOLD := 0;
     END;
     IF aCODCONTSOLD = 0 THEN
       aCODCONTSOLD := SEQ_NCONTSOLD_CODCONTSOLD.NEXTVAL;
       INSERT INTO NCONTSOLD(CODCONTSOLD, CODCONT, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP, AN, LUNA)
                   VALUES(aCODCONTSOLD, V_REC.CONTNOU, 0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, 1);

     ELSE
       UPDATE NCONTSOLD
       SET
         SOLDID       = 0,
         SOLDIC       = 0,
         SOLDVID      = 0,
         SOLDVIC      = 0,
         SOLDI_IFRS   = 0,
         SOLDVI_IFRS  = 0,
         SOLDI_GRUP   = 0,
         SOLDVI_GRUP  = 0
       WHERE
        CODCONTSOLD = aCODCONTSOLD;
     END IF;

       FOR V_REC_S IN (SELECT CODSUBUNIT FROM NSUBUNIT WHERE CODSUBUNIT &gt; 1)
       LOOP
         BEGIN
           SELECT COUNT(*) INTO NR FROM NCONTSOLDSUB WHERE CODCONTSOLD = aCODCONTSOLD AND SUBUNITATEA = V_REC_S.CODSUBUNIT;
           EXCEPTION WHEN OTHERS THEN NR := 0;
         END;
         IF NR = 0 THEN
           INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, SUBUNITATEA, CODCONTSOLD, SOLDID, SOLDIC, SOLDVID, SOLDVIC, SOLDI_IFRS, SOLDVI_IFRS, SOLDI_GRUP, SOLDVI_GRUP)
                       VALUES(SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC_S.CODSUBUNIT,   aCODCONTSOLD,  0, 0, 0, 0, 0, 0, 0, 0);
         ELSE
           UPDATE NCONTSOLDSUB
           SET
             SOLDID       = 0,
             SOLDIC       = 0,
             SOLDVID      = 0,
             SOLDVIC      = 0,
             SOLDI_IFRS   = 0,
             SOLDVI_IFRS  = 0,
             SOLDI_GRUP   = 0,
             SOLDVI_GRUP  = 0
           WHERE
            CODCONTSOLD = aCODCONTSOLD AND SUBUNITATEA = V_REC_S.CODSUBUNIT;
         END IF;
       END LOOP;


  END LOOP;

  FOR V_REC IN (SELECT * FROM NCONTECHIV WHERE  AN = PKG_GLOBALS.ANLUCRU  AND LUNA = 1)
  LOOP
      UPDATE NCONTSOLD
      SET
        SOLDID       = NVL(SOLDID, 0)      + NVL(V_REC.SOLDID,  0),
        SOLDIC       = NVL(SOLDIC, 0)      + NVL(V_REC.SOLDIC,  0),
        SOLDVID      = NVL(SOLDVID, 0)     + NVL(V_REC.SOLDVID, 0),
        SOLDVIC      = NVL(SOLDVIC, 0)     + NVL(V_REC.SOLDVIC, 0),
        SOLDI_IFRS   = NVL(SOLDI_IFRS, 0)  + NVL(V_REC.SOLDI_IFRS, 0),
        SOLDVI_IFRS  = NVL(SOLDVI_IFRS, 0) + NVL(V_REC.SOLDVI_IFRS, 0),
        SOLDI_GRUP   = NVL(SOLDI_GRUP, 0)  + NVL(V_REC.SOLDI_GRUP, 0),
        SOLDVI_GRUP  = NVL(SOLDVI_GRUP, 0) + NVL(V_REC.SOLDVI_GRUP, 0)
      WHERE
        CODCONT = V_REC.CONTNOU
        AND AN = PKG_GLOBALS.ANLUCRU
        AND LUNA = 1;

  END LOOP;

  FOR V_REC IN (SELECT
                  S.CODCONTSOLD,
                  ES.*
                FROM
                  NCONTECHIVSUB ES,
                  NCONTECHIV E,
                  NCONTSOLD S
                WHERE
                  ES.CODCONTECHIV = E.CODCONTECHIV
                  AND E.AN = PKG_GLOBALS.ANLUCRU
                  AND E.LUNA = 1
                  AND S.CODCONT = E.CONTNOU
                  AND S.AN = E.AN
                  AND S.LUNA = 1
               )
   LOOP
      UPDATE NCONTSOLDSUB
      SET
        SOLDID       = NVL(SOLDID, 0)      + NVL(V_REC.SOLDID,  0),
        SOLDIC       = NVL(SOLDIC, 0)      + NVL(V_REC.SOLDIC,  0),
        SOLDVID      = NVL(SOLDVID, 0)     + NVL(V_REC.SOLDVID, 0),
        SOLDVIC      = NVL(SOLDVIC, 0)     + NVL(V_REC.SOLDVIC, 0),
        SOLDI_IFRS   = NVL(SOLDI_IFRS, 0)  + NVL(V_REC.SOLDI_IFRS, 0),
        SOLDVI_IFRS  = NVL(SOLDVI_IFRS, 0) + NVL(V_REC.SOLDVI_IFRS, 0),
        SOLDI_GRUP   = NVL(SOLDI_GRUP, 0)  + NVL(V_REC.SOLDI_GRUP, 0),
        SOLDVI_GRUP  = NVL(SOLDVI_GRUP, 0) + NVL(V_REC.SOLDVI_GRUP, 0)
      WHERE
        CODCONTSOLD = V_REC.CODCONTSOLD
        AND SUBUNITATEA = V_REC.CODSUBUNIT;
   END LOOP;

  SET_ECHIVALARI_AUTOMATE;
  PKG_GLOBALS.ResetAllRecordsLunaFlags;
  COMMIT;
END;

PROCEDURE UPDATE_NUME_CONT(ANUME IN VARCHAR2, ASIMBOL IN VARCHAR2) IS
BEGIN
  UPDATE NCONT SET NAME = ANUME WHERE SIMBOL = ASIMBOL;
  COMMIT;
END;

PROCEDURE NCONT_NewEntry(ASIMBOL IN VARCHAR2, ANUME IN VARCHAR2, ANAME IN VARCHAR2, AAN IN number, ALUNA IN NUMBER, RECID OUT NUMBER) is
	NR number;
  ANINI    NUMBER(20) := 0;
  LUNAINI  NUMBER(20) := 0;
  AN    NUMBER(5) := 0;
  LUNA  NUMBER(3) := 0;
  aClasa NUMBER(10) := 0;
BEGIN
  RECID := 0;
	Select Count(*) into NR FROM NCONT WHERE SubSTR(SIMBOL,1,LENGTH(aSIMBOL)) = aSIMBOL;
	if NR = 0 then
		BEGIN
			SELECT ANINITIAL, LUNAINITIALA    INTO ANINI, LUNAINI  FROM FIRMALUNI;
			EXCEPTION WHEN OTHERS THEN ANINI := 0;
		END;
		IF ANINI &gt; 0 AND LUNAINI &gt; 0 THEN
			AN   := aAN;
			LUNA := aLUNA;
			if aAn   &lt; ANINI   then AN   := ANINI;  END IF;
			if aLUNA &lt; LUNAINI then LUNA := LUNAINI;END IF;
			aClasa := To_Number(Substr(aSimbol,1,1));
			Insert into TMP_NCONT (CodCont, Simbol, Den_Cont, Name, TipCont, VizibilBalanta, BalantaSintetica, Nivel, Clasa, Inactiv)
			Values (0, aSIMBOL, aNUME, aNAME, 0, 1, 0, 1, aClasa, 1);
			Insert into TMP_NCONT1 (CodCont1, AnStart, LunaStart)
			Values (-1, AN, LUNA);
			PKG_PLANCONTURI.SP_POSTRECORDS(1, RecID);
		END IF;
	END IF;
END;

PROCEDURE NCONT_AddNewEntries is
RECID NUMBER(20);
BEGIN
  For v_rec in (Select * from NCONT_NEWENTRY where Done &lt;&gt; 1)
		loop
    	PKG_PLANCONTURI.NCONT_NewEntry(V_REC.SIMBOL, V_REC.DEN_CONT, V_REC.NAME, V_REC.ANSTART, V_REC.LUNASTART, RECID);
			if RECID &gt; 0 then
				Update NCONT_NEWENTRY SET DONE = 1 where CodCont = V_REC.CodCont;
				Commit;
			END IF;
		end loop;
END;

END pkg_PlanConturi;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56B7F9607426F2C23D6C8FE45404212BEF9ED81C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PlanCurs IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
  BEGIN
  SELECT CodPlanCurs INTO Tmp FROM PlanCurs WHERE CodPlanCurs = RecId FOR UPDATE NOWAIT;
END;
  
  
PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM PlanCurs1 WHERE CodPlanCurs = RecId ;
  DELETE FROM PlanCurs  WHERE CodPlanCurs = RecId ;
  
  NotifyModif(2, RecId, &apos;PlanCurs&apos;);
  
  COMMIT;
END;
  
PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_PlanCurs FIELDS( CodPlanCurs ) VALUES (0) ;
  COMMIT;
END;
  
PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master PlanCurs
  INSERT INTO  TMP_PlanCurs ( CodPlanCurs, CODPERS, NR, DataCurs, TIP, AN, LUNA)
    ( SELECT CodPlanCurs, CODPERS, NR, DataCurs, TIP, AN, LUNA
    FROM PlanCurs WHERE CodPlanCurs = RecId ) ;

  INSERT INTO  TMP_PlanCurs1 ( CodPlanCurs1, CodPlanCurs, CodTema, DataPlan, Stare)
    ( SELECT CodPlanCurs1, CodPlanCurs, CodTema, DataPlan, Stare
    FROM PlanCurs1 WHERE CodPlanCurs = RecId ) ;
  
  COMMIT;
END;
  
  
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
  -- Master PlanCurs
    SELECT CodPlanCurs INTO RecId FROM TMP_PlanCurs;
    
    UPDATE PlanCurs 
    SET ( CODPERS, NR, DataCurs, TIP, AN, LUNA )
    = ( SELECT CODPERS, NR, DataCurs, TIP, AN, LUNA FROM TMP_PlanCurs )
    WHERE CodPlanCurs = RecId ;

    DELETE FROM PLANCURS1 where CODPLANCURS = RecId and CODPLANCURS1 not in (Select CODPLANCURS1 from TMP_PLANCURS1);

    INSERT INTO PLANCURS1 
    ( CodPlanCurs1, CodPlanCurs, CodTema, DataPlan, Stare)
    SELECT SEQ_PLANCURS1_CODPLANCURS1.Nextval , RecId , CodTema, DataPlan, Stare
    FROM TMP_PLANCURS1 WHERE CODPLANCURS1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_PLANCURS1 WHERE CODPLANCURS1 &gt; 0 ) LOOP
       UPDATE PLANCURS1
       SET
        CodTema  = V_REC.Codtema, 
        DataPlan = V_REC.dataPlan, 
        Stare    = V_REC.Stare
       WHERE CODPLANCURS1  = v_rec.CODPLANCURS1;
    END LOOP;
  
  ELSE  -- INSERT
  -- Master PlanCurs
    SELECT SEQ_PlanCurs_CodPlanCurs.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO  PlanCurs ( CodPlanCurs, CODPERS, NR, DataCurs, TIP, AN, LUNA)
              ( SELECT  RecId ,CODPERS, NR, DataCurs, TIP, AN, LUNA
                FROM TMP_PlanCurs ) ;

    INSERT INTO PLANCURS1 
    ( CodPlanCurs1, CodPlanCurs, CodTema, DataPlan, Stare)
    SELECT SEQ_PLANCURS1_CODPLANCURS1.Nextval , RecId , CodTema, DataPlan, Stare
    FROM TMP_PLANCURS1;

  END IF;
  
  NotifyModif(Operation, RecId, &apos;PlanCurs&apos;);
  
  COMMIT;
  
END;



END PKG_PlanCurs; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANIFCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A9DB4BCC986D624A88BDF275FFAC3571823476E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANIFCMD IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_69&apos;;
vAllCls number(1);
vAllClsS number(1);
vAllProd number(1);

FUNCTION GetAllCls RETURN number IS
BEGIN
  RETURN vAllCls;
END;

FUNCTION GetAllClsS RETURN number IS
BEGIN
  RETURN vAllClsS;
END;

FUNCTION GetAllProd RETURN number IS
BEGIN
  RETURN vAllProd;
END;

FUNCTION Multip(aAn in number) RETURN number IS
vWeeks number(2);
BEGIN
  SELECT to_number(to_char(to_date(&apos;01.01.&apos;||to_char(aAn + 1),&apos;dd.mm.yyyy&apos;), &apos;iw&apos;)) INTO vWeeks FROM dual;
  IF vWeeks = 1 THEN
    RETURN 52;
  ELSE
    RETURN vWeeks;
  END IF;
END;

FUNCTION LOCKSTARE(aCodStare in number) RETURN number IS
Rez number(1);
Tmp NUMBER(20);
BEGIN
  BEGIN
    SELECT SEC.CodStare INTO Tmp
    FROM STAREESTIMARI SE
         INNER JOIN stareestimari sec on sec.an = se.an AND sec.saptamana = se.saptamana AND sec.an = sec.ang AND sec.saptamana = sec.saptamanag
    WHERE se.CodStare = aCodStare AND sec.subunitatea = se.subunitatea
    FOR UPDATE NOWAIT;
    Rez := 0;
  EXCEPTION WHEN OTHERS THEN
    Rez := 1;
  END;
  RollBack;
  IF Rez = 1 THEN RETURN Rez; END IF;
  BEGIN
    SELECT SEC.CodStare INTO Tmp
    FROM STAREESTIMARI SE
         INNER JOIN stareestimari sec on sec.an = se.an AND sec.saptamana = se.saptamana AND sec.ang * Multip(sec.An) + sec.saptamanag = sec.an * Multip(sec.An) + sec.saptamana + 1
    WHERE se.CodStare = aCodStare AND sec.subunitatea = se.subunitatea
    FOR UPDATE NOWAIT;
    Rez := 0;
  EXCEPTION WHEN OTHERS THEN
    Rez := 1;
  END;
  RollBack;
  RETURN Rez;
END;

FUNCTION GETANDREFRESHREST(aCodStare2 in number) RETURN number IS
Rez number(20,7);
BEGIN
  BEGIN
    UPDATE stareestimari2 se2
    SET
      restacceptat = (SELECT c1.restacceptat FROM comanda1 c1 WHERE c1.codcomanda1 = se2.codcomanda1)
    WHERE se2.codstare2 = aCodStare2;
    COMMIT;
    SELECT restacceptat
    INTO rez
    FROM stareestimari2
    WHERE codstare2 = aCodStare2;
  EXCEPTION WHEN OTHERS THEN Rez := 0;
  END;
  RETURN Rez;
END;

FUNCTION BLOCARECUREFRESH(aCodStare in number) RETURN number IS
Tmp NUMBER(20);
Rez number(1);
aCodStareC number(20);
aCodStareN number(20);
BEGIN
  Rez := 1;
  BEGIN
    SELECT SEC.CodStare INTO aCodStareC
    FROM STAREESTIMARI SE
         INNER JOIN STAREESTIMARI SEC ON SEC.AN = SE.AN AND SEC.SAPTAMANA = SE.SAPTAMANA AND SEC.AN = SEC.ANG AND SEC.SAPTAMANA = SEC.SAPTAMANAG
    WHERE SE.CodStare = aCodStare AND se.subunitatea = sec.subunitatea;
  EXCEPTION WHEN OTHERS THEN aCodStareC := 0;
  END;
  IF aCodStareC = 0 THEN Rez := 0; END IF;
  IF Rez = 0 THEN RETURN Rez; END IF;

  BEGIN
    SELECT SEC.CodStare INTO aCodStareN
    FROM STAREESTIMARI SE
         INNER JOIN STAREESTIMARI SEC ON SEC.AN = SE.AN AND SEC.SAPTAMANA = SE.SAPTAMANA AND SEC.ANG * Multip(sec.An) + SEC.SAPTAMANAG = SEC.AN * Multip(sec.An) + SEC.SAPTAMANA + 1
    WHERE SE.CodStare = aCodStare AND se.subunitatea = sec.subunitatea;
  EXCEPTION WHEN OTHERS THEN aCodStareC := 0;
  END;
  IF aCodStareN = 0 THEN Rez := 0; END IF;
  IF Rez = 0 THEN RETURN Rez; END IF;

  BEGIN
    SELECT CodStare INTO Tmp FROM STAREESTIMARI WHERE CodStare = aCodStareC FOR UPDATE NOWAIT;
  EXCEPTION WHEN OTHERS THEN
    RollBack;
    Rez := 0;
  END;
  IF Rez = 0 THEN RETURN Rez; END IF;

  BEGIN
    SELECT CodStare INTO Tmp FROM STAREESTIMARI WHERE CodStare = aCodStareN FOR UPDATE NOWAIT;
  EXCEPTION WHEN OTHERS THEN
    RollBack;
    Rez := 0;
  END;
  IF Rez = 0 THEN RETURN Rez; END IF;

  REFRESHDATETS(aCodStareC, aCodStareN);

  COMMIT;
  RETURN Rez;
END;

PROCEDURE PROPAGAMAT(aCodObiect in number, aCodStare in number, aStoc in number, aStocMin in number, aPret in number) IS
aSetG number(2);
aSet number(2);
aAn number(4);
aAnG number(4);
aCodOferta number(20);
BEGIN
  BEGIN
    SELECT se.an, se.saptamana, se.ang, se.saptamanag, se.codoferta INTO aAn, aSet, aAnG, aSetG, aCodOferta
    FROM stareestimari se
    WHERE se.codstare = aCodStare;
  EXCEPTION WHEN OTHERS THEN aSet := 0;
  END;

  IF aSet = 0 THEN RETURN; END IF;

  for v_rec in (SELECT nvl(se1.codstare1,0) codstare1, se.codstare
                FROM stareestimari se
                     LEFT JOIN stareestimari1 se1 on se1.codstare = se.codstare AND se1.codobiect = aCodObiect
                WHERE an = aAn AND saptamana = aSet AND ang * Multip(aAn) + saptamanag &lt;&gt; aAnG * Multip(aAn) + aSetG
                ) loop
    IF v_rec.codstare1 &gt; 0 THEN
      UPDATE stareestimari1 SET dirty = nvl(dirty,0) + 1 WHERE codstare1 = v_rec.codstare1;
    ELSE
      IF v_rec.codstare &gt; 0 THEN
        INSERT INTO stareestimari1(codstare, codobiect, dirty, codstare1, stocmin, stocini, pret)
        VALUES (v_rec.codstare, aCodObiect, 1, seq_stareestimari1_codstare1.nextval, aStocMin, aStoc, aPret);
      END IF;
    END IF;
  END loop;
  COMMIT;
END;

FUNCTION UpdateCmdF(aCodStare1 in number) RETURN number IS
Cant number(20,7);
aSetG number(2);
aSet number(2);
aAn number(4);
aAnG number(4);
aCodOferta number(20);
BEGIN
  BEGIN
    SELECT se.an, se.saptamana, se.ang, se.saptamanag, se.codoferta INTO aAn, aSet, aAnG, aSetG, aCodOferta
    FROM stareestimari1 se1
         INNER JOIN stareestimari se on se.codstare = se1.codstare
    WHERE se1.codstare1 = aCodStare1;
  EXCEPTION WHEN OTHERS THEN
    aSet := 0;
  END;

  IF aSet = 0 THEN RETURN 0; END IF;

  IF aSetG = aSet THEN
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se1.codstare1 = aCodStare1 AND se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen &lt;= iso_week_to_date(aAnG, aSetG) + 6
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND c.subunitatea = se.subunitatea
          AND nvl(c.inchisa,0) = 0
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);
  ELSE
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen between iso_week_to_date(aAnG, aSetG) AND iso_week_to_date(aAnG, aSetG) + 6
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND c.subunitatea = se.subunitatea
          AND nvl(c.inchisa,0) = 0
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);
  END IF;

  UPDATE stareestimari1 se1
  SET
    CmdF = (SELECT sum(se2.restacceptat) FROM stareestimari2 se2 WHERE se2.codstare = se1.codstare AND se2.codstare1 = se1.codstare1),
    pret = (SELECT o1.pret FROM oferta1 o1 WHERE o1.codoferta = aCodOferta AND se1.codobiect = o1.codobiect)
  WHERE se1.codstare1 = acodstare1;

  BEGIN
    SELECT nvl(cmdf,0) INTO cant FROM stareestimari1 WHERE codstare1 = acodstare1;
  EXCEPTION WHEN OTHERS THEN cant := 0;
  END;

  COMMIT;
  RETURN cant;
END;

FUNCTION GENNEWSTARE1(aCodStare in number, aCodObiect in number) RETURN number IS
aSet number(2);
aSetG number(2);
aAn number(4);
aAnG number(4);
aCodStare1 number(20);
aCodOferta number(20);
sColEstimat varchar2(50);
sSQL varchar2(5000);
BEGIN
  BEGIN
    SELECT an, saptamana, ang, saptamanag, codoferta INTO aAn, aSet, aAnG, aSetG, aCodOferta FROM stareestimari WHERE codstare = aCodStare;
  EXCEPTION WHEN OTHERS THEN
    aAn := 0;
  END;

  IF aAn = 0 THEN RETURN 0; END IF;
  SELECT seq_stareestimari1_codstare1.nextval INTO aCodStare1 FROM dual;

  INSERT INTO stareestimari1 (codstare, codobiect, stocmin, codstare1, pret, stocini)
  SELECT aCodStare, aCodObiect, osub.stocmin, aCodStare1, o1.pret, stoc.cant
  FROM nartobj obj
       LEFT JOIN nartobjsubunit osub on osub.codobiect = obj.codobiect
                                     AND ( osub.codgest IS null OR osub.codgest = 0)
                                     AND osub.subunitate = pkg_globals.GETSUBUNITATE
       LEFT JOIN oferta1 o1 on o1.codobiect = obj.codobiect AND o1.codoferta = aCodOferta
       LEFT JOIN (SELECT sum(ns.rest) cant, ns.codobiect
                  FROM nirstoc ns
                       INNER JOIN nir on nir.codnir = ns.codnir
                       INNER JOIN ngest g on g.codgest = nir.gest
                  WHERE g.codsubunit = pkg_globals.GETSUBUNITATE AND ns.codobiect = aCodObiect AND ns.rest &lt;&gt; 0
                       AND g.tip &lt;&gt; 4
                  GROUP by ns.codobiect
                  ) stoc on stoc.codobiect = obj.codobiect
  WHERE obj.codobiect = aCodObiect;

  UmpleTemporarGenerator(aAn * Multip(aAn) + aSet, PKG_GLOBALS.GETUSERID, PKG_GLOBALS.GETSUBUNITATE, aCodObiect);

  IF aAnG = aAn THEN
    sColEstimat := &apos;e1m.c&apos;||aSetG;
  ELSE
    sColEstimat := &apos;e1m.n&apos;||aSetG;
  END IF;

  IF aAnG * Multip(aAn) + aSetG &gt; aAn * Multip(aAn) + aSet + 1 THEN
    sSQL :=
    &apos;UPDATE stareestimari1 S
     SET estimat =
            (SELECT sum(&apos;||sColEstimat||&apos;) estimat
             FROM estimariprod1m e1m
                  INNER JOIN estimariprod e on e.codestimareprod = e1m.codestimareprod
                  LEFT JOIN nartobjsubunit osub on osub.codobiect = e1m.codobiect
                                                   AND ( osub.codgest IS null OR osub.codgest = 0)
                                                   AND osub.subunitate = &apos;||pkg_globals.getSubunitate||&apos;
             WHERE e.an = &apos;||aAn||&apos; AND e.saptamana = &apos;||aSet||&apos; AND nvl(&apos;||sColEstimat||&apos;,0) &gt; 0
                   AND e.operat = 1 AND nvl(e.anulat,0) = 0 AND e.subunitatea = &apos;||pkg_globals.getSubunitate||&apos;
                   AND e1m.codobiect = s.codobiect
              )
     WHERE s.codstare1 = &apos;||aCodStare1;
    EXECUTE IMMEDIATE sSQL;
  ELSE IF aAnG * Multip(aAn) + aSetG = aAn * Multip(aAn) + aSet + 1 THEN -- + 1
    UPDATE stareestimari1
    SET
      estimat = (SELECT sum(tmp.resta)
                 FROM TMP_CMDTL tmp
                  WHERE tmp.tip = 2 AND tmp.userid = pkg_globals.GETUSERID
                 ),
      consum = (SELECT sum(tmp.cantc)
                FROM TMP_CMDTL tmp
                WHERE tmp.tip = 2 AND tmp.userid = pkg_globals.GETUSERID
                )
    WHERE codstare1 = aCodStare1;
  ELSE
    UPDATE stareestimari1
    SET
      estimat = (SELECT sum(tmp.resta)
                 FROM TMP_CMDTL tmp
                  WHERE tmp.tip = 1 AND tmp.userid = pkg_globals.GETUSERID
                 ),
      consum = (SELECT sum(tmp.cantc)
                 FROM TMP_CMDTL tmp
                  WHERE tmp.tip = 1 AND tmp.userid = pkg_globals.GETUSERID
                 )
    WHERE codstare1 = aCodStare1;
  END IF; END IF;

  INSERT INTO tmp_stareestimari1 (codstare, codobiect, stocmin, codstare1, pret, stocini, den_umsec, den_um1,
                                  denumire, d1, d2, d3, relatieum1, estimari, consum)
  SELECT se1.codstare, se1.codobiect, se1.stocmin, se1.codstare1, se1.pret, se1.stocini, umsec.den_um1, um1.den_um,
         obj.denumire, art.d1, art.d2, art.d3, art.relatieum1, se1.estimat, se1.consum
  FROM stareestimari1 se1
       INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
       INNER JOIN nart art on art.codarticol = obj.codarticol
       INNER JOIN num1 umsec on umsec.codum = art.um AND nvl(umsec.secundara,0) = 0
       LEFT JOIN num um1 on um1.codum = art.um1
  WHERE codstare1 = aCodStare1;

  IF aSetG = aSet THEN
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se1.codstare1 = aCodStare1 AND se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen &lt;= iso_week_to_date(aAnG, aSetG) + 6
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND c.subunitatea = se.subunitatea
          AND nvl(c.inchisa,0) = 0
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);
  ELSE
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen between iso_week_to_date(aAnG, aSetG) AND iso_week_to_date(aAnG, aSetG) + 6
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND c.subunitatea = se.subunitatea
          AND nvl(c.inchisa,0) = 0
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);
  END IF;

  UPDATE stareestimari1 se1
  SET
    CmdF = (SELECT sum(se2.restacceptat) FROM stareestimari2 se2 WHERE se2.codstare = se1.codstare AND se2.codstare1 = se1.codstare1)
  WHERE se1.codstare1 = acodstare1;

  UPDATE tmp_stareestimari1 tmp
  SET
    CmdF = (SELECT se1.cmdf FROM stareestimari1 se1 WHERE se1.codstare1 = tmp.codstare1)
  WHERE tmp.codstare1 = acodstare1;

  COMMIT;
  RETURN aCodStare1;
END;

PROCEDURE UmpleTemporarGenerator(vAnSet in number, vUserID in number, vSubunitatea in number, vCodObiect in number default 0) IS
vNextAnSet number(10);
BEGIN
  vNextAnSet := vAnSet + 1;

  DELETE TMP_CMDTL WHERE USERID = vUserId;

  IF vCodObiect &gt; 0 THEN
    MERGE INTO TMP_CMDTL TMP
    USING (
      SELECT PNOD.CODOBIECT CODOBIECT, sum(PNOD.NECESAR) NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An * Multip(PP.An) + PP.SAPTAMANA = vAnSet AND PNOD.CodObiect = vCodObiect AND
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 AND
            PNOD.TIP = 3 AND PP.SUBUNITATEA = vSubunitatea
      GROUP BY PNOD.CODOBIECT
          ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) + V.NECESAR, TMP.CANTA = NVL(TMP.CANTA,0) + V.NECESAR
    WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.RESTA, TMP.CANTA, TMP.USERID,TMP.CODCMDTL,TMP.TIP)
                          VALUES (V.CODOBIECT,V.NECESAR, V.NECESAR, VUSERID, SEQ_CMDTL_CODCMDTL.NEXTVAL,1);

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, sum(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    --NEXT

    MERGE INTO TMP_CMDTL TMP
    USING (
      SELECT PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An * Multip(PP.An) + PP.SAPTAMANA = vNextAnSet AND
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 AND
            PNOD.TIP = 3 AND PP.SUBUNITATEA = vSubunitatea AND PNOD.codobiect = vCodObiect
      GROUP BY PNOD.CODOBIECT
          ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) + V.NECESAR, TMP.CANTA = NVL(TMP.CANTA,0) + V.NECESAR
    WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.RESTA,TMP.CANTA,TMP.USERID,TMP.CODCMDTL,TMP.TIP)
                          VALUES (V.CODOBIECT,V.NECESAR,V.NECESAR,VUSERID,SEQ_CMDTL_CODCMDTL.NEXTVAL,2);

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, sum(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea AND cmd.codobiect = vCodObiect
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;
  ELSE
    MERGE INTO TMP_CMDTL TMP
    USING (
      SELECT PNOD.CODOBIECT CODOBIECT, sum(PNOD.NECESAR) NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An * Multip(PP.An) + PP.SAPTAMANA = vAnSet AND
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 AND
            PNOD.TIP = 3 AND PP.SUBUNITATEA = vSubunitatea
      GROUP BY PNOD.CODOBIECT
          ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) + V.NECESAR
    WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.RESTA,TMP.CANTA,TMP.USERID,TMP.CODCMDTL,TMP.TIP)
                          VALUES (V.CODOBIECT,V.NECESAR,V.NECESAR,VUSERID,SEQ_CMDTL_CODCMDTL.NEXTVAL,1);

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, sum(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 1)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    --NEXT

    MERGE INTO TMP_CMDTL TMP
    USING (
      SELECT PNOD.CODOBIECT CODOBIECT, SUM(PNOD.NECESAR) NECESAR
      FROM PLANIFNOD PNOD
           INNER JOIN PLANIFPROD1 PP1 ON PP1.CODPLANIFPROD1 = PNOD.CODPLANIFPROD1
           INNER JOIN PLANIFPROD PP ON PP.CODPLANIFPROD = PP1.CODPLANIFPROD
      WHERE PP.An * Multip(PP.An) + PP.SAPTAMANA = vNextAnSet AND
            PP.OPERAT = 1 AND PP.ANULAT = 0 AND PP.BLOCAT = 0 AND
            PNOD.TIP = 3 AND PP.SUBUNITATEA = vSubunitatea
      GROUP BY PNOD.CODOBIECT
          ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) + V.NECESAR
    WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.RESTA,TMP.CANTA,TMP.USERID,TMP.CODCMDTL,TMP.TIP)
                          VALUES (V.CODOBIECT,V.NECESAR,V.NECESAR,VUSERID,SEQ_CMDTL_CODCMDTL.NEXTVAL,2);

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, sum(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_LUNI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MARTI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_MIERCURI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_JOI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_VINERI
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_SAMBATA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;

    MERGE INTO TMP_CMDTL TMP
    USING (
           SELECT CMD.CODOBIECT CODOBIECT, SUM(IL.CANT) STINS
           FROM IESPRODLINK IL
                INNER JOIN CMDPRODMAT CMD ON IL.CODCMDPRODMAT = CMD.CODCMDPRODMAT
                INNER JOIN LANSZ1 L1 ON CMD.CODCOMANDA1 = L1.CODCMD1_DUMINICA
                INNER JOIN LANSZ L ON L1.CODLANSZ = L.CODLANSZ
           WHERE NVL(L.ANULAT,0) = 0 AND L.AN * Multip(L.An) + l.saptamana = vNextAnSet AND CMD.TIP = 1
                 AND L.SUBUNITATEA = vSubunitatea
           GROUP BY CMD.CODOBIECT
           ) V
    ON (TMP.CODOBIECT = V.CODOBIECT AND TMP.USERID = VUSERID AND TMP.TIP = 2)
    WHEN MATCHED THEN UPDATE SET TMP.RESTA = NVL(TMP.RESTA,0) - V.STINS, TMP.CANTC = NVL(TMP.CANTC,0) + V.STINS;
  END IF;
END;

PROCEDURE SetDirtyDinTS IS
BEGIN
  for v_rec in (SELECT se1.codstare1
                FROM necesar n
                     INNER JOIN necesarobj nobj on n.codnecesar = nobj.codnecesar
                     INNER JOIN stareestimari se on se.saptamana = n.saptamana AND se.subunitatea = n.subunitatea
                     INNER JOIN stareestimari1 se1 on se.codstare = se1.codstare AND se1.codobiect = nobj.codobiect
                WHERE exists (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODNECESAR&apos; AND n.codnecesar = valoare)
                      AND exists (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODOBIECT&apos; AND nobj.codobiect = valoare)
                ) loop
    UPDATE stareestimari1
    SET
      dirty = nvl(dirty,0) + 1
    WHERE codstare1 = v_rec.codstare1;
  END loop;
  COMMIT;
END;

PROCEDURE REFRESHDATETS(aCodStareC in number, aCodStareN in number) IS
aSubunitatea number(20);
aAn number(4);
aSet number(2);
aCodOferta number(20);
BEGIN
  BEGIN
    SELECT se.subunitatea, se.an, se.saptamana, se.codoferta INTO aSubunitatea, aAn, aSet, aCodOferta
    FROM stareestimari se
    WHERE se.codstare = aCodStareC;
  EXCEPTION WHEN OTHERS THEN RETURN;
  END;

  UmpleTemporarGenerator(aAn * Multip(aAn) + aSet, PKG_GLOBALS.GETUSERID, aSubunitatea);

  for v_rec in (SELECT
                  distinct
                  tmp.codobiect codobiect,
                  osub.stocmin stocmin,
                  stoc.cant cant,
                  o1.pret pret,
                  tmp.cantc consum
                FROM TMP_CMDTL tmp
                     LEFT JOIN nartobjsubunit osub on osub.codobiect = tmp.codobiect
                                                   AND ( osub.codgest IS null OR osub.codgest = 0)
                                                   AND osub.subunitate = aSubunitatea
                     LEFT JOIN (SELECT sum(ns.rest) cant, ns.codobiect
                                FROM nirstoc ns
                                     INNER JOIN nir on nir.codnir = ns.codnir
                                     INNER JOIN ngest g on g.codgest = nir.gest
                                WHERE g.codsubunit = aSubunitatea AND ns.rest &lt;&gt; 0 AND g.tip &lt;&gt; 4
                                GROUP by ns.codobiect
                                ) stoc on stoc.codobiect = tmp.codobiect
                     LEFT JOIN OFERTA1 O1 ON O1.CODOFERTA = aCodOferta AND O1.Codobiect = tmp.Codobiect
                WHERE tmp.tip in (1,2) AND tmp.userid = pkg_globals.GETUSERID
                      AND NOT exists
                      (SELECT se1.codobiect
                       FROM stareestimari1 se1
                            INNER JOIN stareestimari se on se.codstare = se1.codstare
                       WHERE se.an = aAn AND se.saptamana = aSet AND se.subunitatea = aSubunitatea
                             AND se1.codobiect = tmp.codobiect
                       )
                ) loop
    INSERT INTO stareestimari1 (codstare, codobiect, stocmin, codstare1, pret, stocini, consum)
    SELECT se.codstare, v_rec.codobiect, v_rec.stocmin, seq_stareestimari1_codstare1.nextval, v_rec.pret, v_rec.cant, v_rec.consum
    FROM stareestimari se
    WHERE se.an = aAn AND se.saptamana = aSet AND se.subunitatea = aSubunitatea;
  END loop;

  MERGE INTO stareestimari1 S
  USING (
         SELECT
           tmp.codobiect,
           tmp.resta ESTIMAT,
           tmp.cantc consum,
           TMP.CANTA DETALIERI
         FROM TMP_CMDTL tmp
         WHERE tmp.tip = 2 AND tmp.userid = pkg_globals.GETUSERID
         ) V
  ON (S.CODOBIECT = V.CODOBIECT AND S.CODSTARE = ACODSTAREN)
  WHEN MATCHED THEN UPDATE SET S.ESTIMAT = nvl(V.DETALIERI,0) - nvl(S.CONSUM,0);

  MERGE INTO stareestimari1 S
  USING (
         SELECT
           tmp.codobiect,
           tmp.resta ESTIMAT,
           tmp.cantc consum,
           TMP.CANTA DETALIERI
         FROM TMP_CMDTL tmp
         WHERE tmp.tip = 1 AND tmp.userid = pkg_globals.GETUSERID
         ) V
  ON (S.CODOBIECT = V.CODOBIECT AND S.CODSTARE = ACODSTAREC)
  WHEN MATCHED THEN UPDATE SET S.ESTIMAT = nvl(V.DETALIERI,0) - nvl(S.CONSUM,0);

  UPDATE stareestimari SET
    dirty = 0
  WHERE codstare = aCodStareC;
  UPDATE stareestimari SET
    dirty = 0
  WHERE codstare = aCodStareN;
END;

FUNCTION UpdateTermenPePreCmd(aCodPreComanda1 in number, aTermen in varchar2) RETURN number IS
aCodPreComanda number(20);
BEGIN
  BEGIN
    SELECT codprecomanda
    INTO aCodPreComanda
    FROM precomanda1
    WHERE codprecomanda1 = aCodPreComanda1;
  EXCEPTION WHEN OTHERS THEN aCodPreComanda := 0;
  END;
  IF aCodPreComanda = 0 THEN RETURN 0; END IF;
  UPDATE precomanda1 SET termen = aTermen WHERE CodPreComanda1 = aCodPreComanda1;
  RETURN 1;
END;

PROCEDURE SetNecesarAccPeStare1(aCodStare1 in number) IS
aSaptamana number(2);
aSaptamanaG number(2);
aAn number(4);
aAnG number(4);
aDataStopG date;
aNecesarAcc number(20,7);
BEGIN
  BEGIN
    SELECT se.an, se.ang, se.saptamana, se.saptamanag, iso_week_to_date(se.AnG, se.SaptamanaG) + 6, nvl(se1.necesaracc, -9999999999)
    INTO aAn, aAnG, aSaptamana, aSaptamanaG, aDataStopG, aNecesarAcc
    FROM stareestimari1 se1
         INNER JOIN stareestimari se on se.codstare = se1.codstare
    WHERE se1.codstare1 = aCodStare1;
  EXCEPTION WHEN OTHERS THEN RETURN;
  END;

  IF aNecesarAcc = -9999999999 THEN

  for v_rec in (
    SELECT
      case WHEN x.necesar + x.stocmin &gt; 0 THEN x.necesar + x.stocmin ELSE 0 END necesaracc
    FROM (
    SELECT
      nvl(se1.stocmin,0) stocmin,
      nvl(se1.necesar,0) - nvl(cmdf.cant,0) + nvl(estint.cant,0) - nvl(cmdff.cant,0) + nvl(se1.estimat,0) - nvl(se1.stocmin,0) Necesar
    FROM stareestimari se
         INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
         INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
         LEFT JOIN (SELECT sum(se2.restacceptat) cant, se1.codobiect
                    FROM stareestimari2 se2
                         INNER JOIN stareestimari1 se1 on se2.codstare1 = se1.codstare1
                         INNER JOIN stareestimari1 se11 on se1.codstare = se11.codstare AND se1.codobiect = se11.codobiect
                         INNER JOIN stareestimari se on se11.codstare = se.codstare AND se2.codstare = se.codstare
                    WHERE se11.codstare1 = aCodStare1
                          AND se.an = aAn AND se.saptamana = aSaptamana
                          AND se.AnG * Multip(aAn) + se.saptamanag between aAn * Multip(aAn) + aSaptamana + 1 AND aAnG * 53 + aSaptamanaG - 1
                    GROUP by se1.codobiect
                    ) cmdf on cmdf.codobiect = se1.codobiect
         LEFT JOIN (SELECT sum(nvl(se11.estimat,0)) cant, se11.codobiect
                    FROM stareestimari1 se1
                         INNER JOIN stareestimari1 se11 on se1.codstare = se11.codstare AND se11.codobiect = se1.codobiect
                         INNER JOIN stareestimari se on se11.codstare = se.codstare
                    WHERE se1.codstare1 = aCodStare1
                          AND se.an = aAn AND se.saptamana = aSaptamana
                          AND se.AnG * Multip(aAn) + se.saptamanag between aAn * Multip(aAn) + aSaptamana + 1 AND aAnG * 53 + aSaptamanaG - 1
                    GROUP by se11.codobiect
                    ) estint on estint.codobiect = se1.codobiect
         LEFT JOIN (SELECT sum(se2.restacceptat) cant, se1.codobiect
                    FROM stareestimari2 se2
                         INNER JOIN stareestimari1 se1 on se2.codstare1 = se1.codstare1
                         INNER JOIN stareestimari se on se1.codstare = se.codstare AND se2.codstare = se.codstare
                    WHERE se1.codstare1 = aCodStare1
                    GROUP by se1.codobiect
                    ) cmdff on cmdff.codobiect = se1.codobiect
         LEFT JOIN (SELECT SUM(C1.CANTACCEPTAT) CANT, SE1.CODSTARE1
                    FROM STAREESTIMARI1 SE1
                         INNER JOIN stareestimari se on se1.codstare = se.codstare
                         INNER JOIN stareestimari ses on se.An = ses.An AND se.saptamana = ses.saptamana AND se.subunitatea = ses.subunitatea
                         INNER JOIN stareestimari1 se11 on ses.codstare = se11.codstare AND se1.codobiect = se11.codobiect
                         INNER JOIN PLANIFLINK L ON SE11.CODSTARE1 = L.CODSTARE1
                         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
                         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                    WHERE se1.codstare1 = aCodStare1
                          AND c1.termen &lt;= aDataStopG
                    GROUP BY SE1.CODSTARE1
                    ) CMDFP ON CMDFP.CODSTARE1 = SE1.CODSTARE1
         LEFT JOIN (SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1
                    FROM STAREESTIMARI1 SE1
                         INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
                         INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
                         INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
                    WHERE se1.codstare1 = aCodStare1
                          AND PC.USERID = PKG_GLOBALS.GETUSERID
                    GROUP BY SE1.CODSTARE1
                    ) RESTC ON RESTC.CODSTARE1 = SE1.CODSTARE1
         LEFT JOIN (SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1
                    FROM STAREESTIMARI1 SE1
                         INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
                         INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
                         INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
                    WHERE se1.codstare1 = aCodStare1
                          AND PC.USERID &lt;&gt; PKG_GLOBALS.GETUSERID
                    GROUP BY SE1.CODSTARE1
                    ) RESTCA ON RESTCA.CODSTARE1 = SE1.CODSTARE1
    WHERE se1.codstare1 = aCodStare1 ) x
    ) loop
    UPDATE stareestimari1 SET necesaracc = v_rec.necesaracc WHERE codstare1 = aCodStare1;
  END loop;
  END IF;
END;

PROCEDURE ModificaStareFaraCommit(aTermen in DATE, aCodComanda1 in number) IS
aNewCodStare1 number(20);
aNewCodStare number(20);
aAn number(4);
aSet number(2);
aAnMin number(4);
aSetMin number(2);
aAnSetMax number(10);
BEGIN
  aAn := to_number(to_char(aTermen, &apos;iyyy&apos;));
  aSet := to_number(to_char(aTermen, &apos;iw&apos;));

  INSERT INTO x(test) VALUES (to_char(aTermen, &apos;dd.mm.yyyy&apos;));

  for v_rec in (SELECT codstare2, codstare, codobiect FROM stareestimari2 WHERE codcomanda1 = acodcomanda1 order by codstare2 desc) loop
    BEGIN
      SELECT an, saptamana
      INTO aAnMin, aSetMin
      FROM stareestimari
      WHERE codstare = v_rec.codstare;
    EXCEPTION WHEN OTHERS THEN aAnMin := 0;
    END;

    IF aAnMin &gt; 0 THEN
      BEGIN
        SELECT max(sen.ang * Multip(sen.An) + sen.saptamanag)
        INTO aAnSetMax
        FROM stareestimari se
             INNER JOIN stareestimari sen on sen.an = se.an AND sen.saptamana = se.saptamana AND sen.subunitatea = se.subunitatea
        WHERE se.codstare = v_rec.codstare;
      EXCEPTION WHEN OTHERS THEN aAnSetMax := 0;
      END;

      INSERT INTO x(test) VALUES (v_rec.codstare2);

      IF aAn * Multip(aAn) + aSet &lt;= aAnSetmax THEN
        INSERT INTO x(test) VALUES (&apos;UPDATE la termen&apos;);

        UPDATE stareestimari2
        SET
          termen = aTermen
        WHERE codstare2 = v_rec.CodStare2;
      END IF;

      IF aAn * Multip(aAn) + aSet &lt; aAnMin * Multip(aAnMin) + aSetMin THEN
        BEGIN
          SELECT se1.codstare1, se1.codstare
          INTO aNewCodStare1, aNewCodStare
          FROM stareestimari se
               INNER JOIN stareestimari sen on se.an = sen.an AND se.saptamana = sen.saptamana AND se.subunitatea = sen.subunitatea
                                               AND sen.ang = sen.an AND sen.saptamanag = sen.saptamana
               INNER JOIN stareestimari1 se1 on sen.codstare = se1.codstare AND se1.codobiect = v_rec.codobiect
          WHERE se.codstare = v_rec.CodStare;
        EXCEPTION WHEN OTHERS THEN
          aNewCodStare1 := 0;
        END;
        IF aNewCodStare1 &gt; 0 THEN
          UPDATE stareestimari2 SET codstare1 = aNewCodStare1, codstare = aNewCodStare WHERE codcomanda1 = aCodComanda1;
        END IF;
      ELSE IF aAn * Multip(aAn) + aSet &lt;= aAnSetmax THEN
        BEGIN
          SELECT se1.codstare1, se1.codstare
          INTO aNewCodStare1, aNewCodStare
          FROM stareestimari se
               INNER JOIN stareestimari sen on se.an = sen.an AND se.saptamana = sen.saptamana AND se.subunitatea = sen.subunitatea
                                               AND sen.ang = aAn AND sen.saptamanag = aSet
               INNER JOIN stareestimari1 se1 on sen.codstare = se1.codstare AND se1.codobiect = v_rec.codobiect
          WHERE se.codstare = v_rec.CodStare;
        EXCEPTION WHEN OTHERS THEN
          aNewCodStare1 := 0;
        END;
        IF aNewCodStare1 &gt; 0 THEN
          UPDATE stareestimari2 SET codstare1 = aNewCodStare1, codstare = aNewCodStare WHERE codcomanda1 = aCodComanda1;
        END IF;
      ELSE
        DELETE stareestimari2 WHERE codstare2 = v_rec.codstare2;
      END IF; END IF;
    END IF;
    exit;
  END loop;

  BEGIN
    SELECT se1n.codstare1, se1n.codstare
    INTO aNewCodStare1, aNewCodStare
    FROM planiflink l
         INNER JOIN stareestimari1 se1 on se1.codstare1 = l.codstare1
         INNER JOIN stareestimari se on se.codstare = se1.codstare
         INNER JOIN stareestimari sen on se.an = sen.an AND se.saptamana = sen.saptamana AND se.subunitatea = sen.subunitatea
                                         AND sen.ang = aAn AND sen.saptamanag = aSet
         INNER JOIN stareestimari1 se1n on se1n.codstare = sen.codstare AND se1n.codobiect = se1.codobiect
    WHERE l.codcomanda1 = aCodComanda1 AND sen.an * Multip(sen.An) + sen.saptamana = (SELECT max(an*Multip(An)+saptamana) FROM stareestimari WHERE subunitatea = pkg_globals.getsubunitate);
  EXCEPTION WHEN OTHERS THEN
    aNewCodStare1 := 0;
  END;
  IF aNewCodStare1 &gt; 0 THEN
    UPDATE planiflink SET codstare1 = aNewCodStare1 WHERE codcomanda1 = aCodComanda1;
  END IF;
END;

FUNCTION ModificaStare(aCodStare2 in number, aTermen in varchar, aCodComanda1 in number, aCodStare in number) RETURN number IS
aNewTermen date;
aCodComanda number(20);
aNewCodStare1 number(20);
aNewCodStare number(20);
aAn number(4);
aSet number(2);
vAn number(4);
vSet number(2);
vData date;
aObs varchar2(500);
aCodSubunit number(20);
aDataDoc date;
aOldTermen varchar2(100);
BEGIN
  aNewTermen := to_date(aTermen, &apos;DD.MM.YYYY&apos;);
  aAn := to_number(to_char(aNewTermen, &apos;iyyy&apos;));
  aSet := to_number(to_char(aNewTermen, &apos;iw&apos;));
  BEGIN
    DELETE tmp_comanda;
    SELECT c1.codcomanda, c.subunitatea, c.datadoc, c.nrdoc||&apos;/&apos;||to_char(c.datadoc)||&apos; : modificare termen : &apos;||c1.indexlocal||&apos;.&apos;||obj.denumire||&apos; &apos;||to_char(c1.termen,&apos;dd.mm.yyyy&apos;)||&apos; -&gt; &apos;||aNewTermen,
           to_char(c1.termen,&apos;dd.mm.yyyy&apos;)
    INTO aCodComanda, aCodSubunit, aDataDoc, aObs, aOldTermen
    FROM comanda1 c1
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
         INNER JOIN nartobj obj on c1.codobiect = obj.codobiect
    WHERE c1.CodComanda1 = aCodComanda1;
    pkg_comanda.SP_LOCKRECORD(aCodComanda);
    UPDATE comanda1 SET termen = aNewTermen WHERE CodComanda1 = aCodComanda1;
    /*IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_14&apos;) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, aCodComanda, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aObs, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;*/
    INSERT INTO trigar_modif (CodModif, DatAmodif, UserModif, Cod, CodMaster, TableName, FieldName, OldValue, NewValue)
    VALUES(SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, aCodComanda1,aCodComanda, &apos;COMANDA&apos;, &apos;TERMEN&apos;, SubstrB(aOldTERMEN,1,100), SubstrB(aTermen,1,100));

    BEGIN
      SELECT se.an, se.saptamana, se.datacreare INTO vAn, vSet, vData
      FROM stareestimari se
      WHERE se.codstare = aCodStare;
    EXCEPTION WHEN OTHERS THEN
      vAn := 0;
      vSet := 0;
    END;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLogCuCommit(&apos;STAREESTIMARI&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, vAn*Multip(vAn)+vSet, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, vData, vSet||&apos;/&apos;||vAn, aObs, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

  EXCEPTION WHEN OTHERS THEN
    rollback;
    RETURN -1;
  END;

  --nu se merge pe trigger datorita tmp_comanda

  IF aCodStare2 &gt; 0 THEN
    UPDATE stareestimari2
    SET
      termen = aNewTermen
    WHERE codstare2 = aCodStare2;

    BEGIN
      SELECT se1n.codstare1, se1n.codstare
      INTO aNewCodStare1, aNewCodStare
      FROM stareestimari2 se2
           INNER JOIN stareestimari1 se1 on se1.codstare1 = se2.codstare1
           INNER JOIN stareestimari se on se.codstare = se1.codstare
           INNER JOIN stareestimari sen on se.an = sen.an AND se.saptamana = sen.saptamana AND se.subunitatea = sen.subunitatea
                                           AND sen.ang = aAn AND sen.saptamanag = aSet
           INNER JOIN stareestimari1 se1n on se1n.codstare = sen.codstare AND se1n.codobiect = se1.codobiect
      WHERE se2.codstare2 = aCodStare2;
    EXCEPTION WHEN OTHERS THEN
      aNewCodStare1 := 0;
    END;

    IF aNewCodStare1 &gt; 0 THEN
      UPDATE stareestimari2 SET termen = aTermen, codstare1 = aNewCodStare1, codstare = aNewCodStare WHERE codcomanda1 = aCodComanda1;
    END IF;
  END IF;

  BEGIN
    SELECT se1n.codstare1, se1n.codstare
    INTO aNewCodStare1, aNewCodStare
    FROM planiflink l
         INNER JOIN stareestimari1 se1 on se1.codstare1 = l.codstare1
         INNER JOIN stareestimari se on se.codstare = se1.codstare
         INNER JOIN stareestimari sen on se.an = sen.an AND se.saptamana = sen.saptamana AND se.subunitatea = sen.subunitatea
                                         AND sen.ang = aAn AND sen.saptamanag = aSet
         INNER JOIN stareestimari1 se1n on se1n.codstare = sen.codstare AND se1n.codobiect = se1.codobiect
    WHERE l.codcomanda1 = aCodComanda1;
  EXCEPTION WHEN OTHERS THEN
    aNewCodStare1 := 0;
  END;
  IF aNewCodStare1 &gt; 0 THEN
    UPDATE planiflink SET codstare1 = aNewCodStare1 WHERE codcomanda1 = aCodComanda1;
  END IF;

  COMMIT;
  RETURN 1;
END;

PROCEDURE setstare(aSetG in number, aAnG in number, aSet in number, aAn in number, aCodStare in number, aSubunitatea in number) IS
sColEstimat varchar(50);
sSQL varchar2(10000);
aDataS date;
aDataF date;
BEGIN
  IF aAnG = aAn THEN
    sColEstimat := &apos;e1m.c&apos;||aSetG;
  ELSE
    sColEstimat := &apos;e1m.n&apos;||aSetG;
  END IF;

  IF aAnG * Multip(aAn) + aSetG &gt; aAn * Multip(aAn) + aSet + 1 THEN
    sSQL :=
    &apos;MERGE INTO stareestimari1 S
     USING (
            SELECT e1m.codobiect, sum(&apos;||sColEstimat||&apos;) estimat, osub.stocmin
            FROM estimariprod1m e1m
                 INNER JOIN estimariprod e on e.codestimareprod = e1m.codestimareprod
                 LEFT JOIN nartobjsubunit osub on osub.codobiect = e1m.codobiect
                                               AND ( osub.codgest IS null OR osub.codgest = 0)
                                               AND osub.subunitate = &apos;||aSubunitatea||&apos;
            WHERE e.an = &apos;||aAn||&apos; AND e.saptamana = &apos;||aSet||&apos; AND nvl(&apos;||sColEstimat||&apos;,0) &gt; 0
                  AND e.operat = 1 AND nvl(e.anulat,0) = 0 AND e.subunitatea = &apos;||aSubunitatea||&apos;
            GROUP by e1m.codobiect, osub.stocmin
            ) V
     ON (S.CODOBIECT = V.CODOBIECT AND S.codstare = &apos;||aCodStare||&apos; )
     WHEN MATCHED THEN UPDATE SET S.ESTIMAT = nvl(S.ESTIMAT,0) + V.ESTIMAT&apos;;
    EXECUTE IMMEDIATE sSQL;
  ELSE IF aAnG * Multip(aAn) + aSetG = aAn * Multip(aAn) + aSet + 1 THEN -- + 1
    MERGE INTO stareestimari1 S
    USING (
           SELECT
             tmp.codobiect,
             tmp.resta ESTIMAT,
             osub.stocmin,
             tmp.cantc consum
           FROM TMP_CMDTL tmp
                LEFT JOIN nartobjsubunit osub on osub.codobiect = tmp.codobiect
                                              AND (osub.codgest IS null OR osub.codgest = 0)
                                              AND osub.subunitate = aSubunitatea
           WHERE tmp.tip = 2 AND tmp.userid = pkg_globals.GETUSERID
           ) V
    ON (S.CODOBIECT = V.CODOBIECT AND S.CODSTARE = ACODSTARE)
    WHEN MATCHED THEN UPDATE SET S.ESTIMAT = V.ESTIMAT, S.CONSUM = V.CONSUM;
  ELSE
    MERGE INTO stareestimari1 S
    USING (
           SELECT
             tmp.codobiect,
             tmp.resta ESTIMAT,
             osub.stocmin,
             tmp.cantc consum
           FROM TMP_CMDTL tmp
                LEFT JOIN nartobjsubunit osub on osub.codobiect = tmp.codobiect
                                              AND (osub.codgest IS null OR osub.codgest = 0)
                                              AND osub.subunitate = aSubunitatea
           WHERE tmp.tip = 1 AND tmp.userid = pkg_globals.GETUSERID
           ) V
    ON (S.CODOBIECT = V.CODOBIECT AND S.CODSTARE = ACODSTARE)
    WHEN MATCHED THEN UPDATE SET S.ESTIMAT = V.ESTIMAT, S.CONSUM = V.CONSUM;
  END IF; END IF;

  aDataS := iso_week_to_date(aAnG, aSetG);
  aDataF := aDataS + 6;

  IF aAnG * Multip(aAn) + aSetG = aAn * Multip(aAn) + aSet THEN
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen &lt;= aDataF
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND se.subunitatea = aSubunitatea AND c.subunitatea = aSubunitatea
          AND nvl(c.inchisa,0) = 0;
  ELSE
    INSERT INTO stareestimari2 (codstare2,codstare1,codstare,codcomanda1,datadoc,nrdoc,codpart,codobiect,umsec,restacceptat,pu,codmoneda,termen,saptamana)
    SELECT seq_stareestimari2_codstare2.nextval, se1.codstare1, se.codstare, c1.codcomanda1, c.datadoc, c.nrdoc, c.partener, c1.codobiect, c1.umsec, c1.restacceptat, c1.pu, c.moneda, c1.termen, aSet
    FROM stareestimari1 se1,
         stareestimari se,
         comanda1 c1,
         comanda c
    WHERE se.codstare = se1.codstare AND se1.codobiect = c1.codobiect AND c1.codcomanda = c.codcomanda
          AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND nvl(c.anulat,0) = 0 AND c.operat = 1 AND c1.termen between aDataS AND aDataF
          AND c.tipdoc = 8 AND c1.restacceptat &lt;&gt; 0 AND se.subunitatea = aSubunitatea AND c.subunitatea = aSubunitatea
          AND nvl(c.inchisa,0) = 0;
  END IF;

  UPDATE stareestimari1 se1
  SET
    CmdF = (SELECT sum(se2.restacceptat) FROM stareestimari2 se2 WHERE se2.codstare = se1.codstare AND se2.codstare1 = se1.codstare1)
  WHERE se1.codstare = acodstare;

  COMMIT;
END;

PROCEDURE StergeSalvare(aCodStare in number) IS
vAn number(4);
vSet number(2);
vData date;
BEGIN
  BEGIN
    SELECT se.an, se.saptamana, se.datacreare INTO vAn, vSet, vData
    FROM stareestimari se
    WHERE se.codstare = aCodStare;
  EXCEPTION WHEN OTHERS THEN
    vAn := 0;
    vSet := 0;
  END;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;STAREESTIMARI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, vAn*Multip(vAn)+vSet, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, vData, vSet||&apos;/&apos;||vAn, vSet||&apos;/&apos;||vAn, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE stareestimari WHERE an = vAn AND saptamana = vSet;

  DELETE precmdlink l WHERE exists
  (SELECT p1.codprecomanda1
   FROM (SELECT codstare FROM stareestimari WHERE an = van AND saptamana = vset) s
        INNER JOIN stareestimari1 s1 on s1.codstare = s.codstare
        INNER JOIN precomanda1 p1 on p1.codstare1 = s1.codstare1
   WHERE l.codprecomanda1 = p1.codprecomanda1);

  DELETE planiflink l WHERE exists
  (SELECT s1.codstare1
   FROM (SELECT codstare FROM stareestimari WHERE an = van AND saptamana = vset) s
        INNER JOIN stareestimari1 s1 on s1.codstare = s.codstare
   WHERE l.codstare1 = s1.codstare1);

  DELETE stareestimari1 s1 WHERE exists
  (SELECT s.codstare
   FROM stareestimari s
   WHERE s.an = van AND s.saptamana = vset AND s1.codstare = s.codstare);

  DELETE stareestimari2 s2 WHERE exists
  (SELECT s.codstare
   FROM stareestimari s
   WHERE s.an = van AND s.saptamana = vset AND s2.codstare = s.codstare);

  /*for v_rec in (SELECT codstare
                FROM stareestimari
                WHERE an = vAn AND Saptamana = vSet
               ) loop
    DELETE stareestimari WHERE codstare = v_rec.codstare;
    for v_rec1 in (SELECT codstare1 FROM stareestimari1 WHERE codstare = v_rec.codstare) loop
      for v_xxx in (SELECT codprecomanda1
                    FROM precomanda1
                    WHERE codstare1 = v_rec1.codstare1
                    ) loop
        DELETE precmdlink WHERE codprecomanda1 = v_xxx.codprecomanda1;
      END loop;
      DELETE planiflink WHERE codstare1 = v_rec1.codstare1;
    END loop;
    DELETE stareestimari1 WHERE codstare = v_rec.codstare;
    DELETE stareestimari2 WHERE codstare = v_rec.codstare;
    COMMIT;
  END loop;*/
  COMMIT;
END;

FUNCTION GetCursorStare1(aSetG in number, aAnG in number, aSet in number, aAn in number, aCodStare1 in number, CuRefreshRestSE2 in boolean) RETURN Stare1_Ref_Cursor IS
TmpCursor Stare1_Ref_Cursor;
adatacreare timestamp;
aCodStare2 number(20);
aUserID number(20);
asubunitatea number(20);
aCodObiect number(20);
BEGIN
  aUserID := pkg_globals.GETUSERID;
  for v_rec in (SELECT count(*), codstare1, codcomanda1
                FROM planiflink
                GROUP by codstare1, codcomanda1
                having count(*) &gt; 1
               ) loop
    DELETE planiflink WHERE codstare1 = v_rec.codstare1 AND codcomanda1 = v_rec.codcomanda1;
    INSERT INTO planiflink (codcomanda1, codstare1)
    VALUES (v_rec.codcomanda1, v_rec.codstare1);
  END loop;

  for v_rec in (
                SELECT count(*), se2.codcomanda1, se2.codstare
                FROM stareestimari2 se2
                     INNER JOIN stareestimari se on se.codstare = se2.codstare
                WHERE se.an = aAn AND se.saptamana = aSet
                GROUP by se2.codcomanda1, se2.codstare
                having count(*) &gt; 1
                ) loop
    BEGIN
      SELECT max(codstare2) INTO aCodStare2 FROM stareestimari2 WHERE codcomanda1 = v_rec.codcomanda1 AND codstare = v_rec.codstare;
    EXCEPTION WHEN OTHERS THEN aCodStare2 := 0;
    END;
    IF aCodStare2 &gt; 0 THEN
      DELETE stareestimari2 WHERE codcomanda1 = v_rec.codcomanda1 AND codstare = v_rec.codstare AND codstare2 &lt;&gt; aCodStare2;
    END IF;
  END loop;

  COMMIT;

  IF CuRefreshRestSE2 THEN
    UPDATE stareestimari2 se2
    SET
      restacceptat = (SELECT c1.restacceptat FROM comanda1 c1 WHERE c1.codcomanda1 = se2.codcomanda1)
    WHERE se2.codstare1 = aCodStare1;
    COMMIT;
  END IF;

  BEGIN
    SELECT se.datacreare, se.subunitatea, se1.codobiect INTO adatacreare, asubunitatea, aCodObiect
    FROM stareestimari se
         INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
    WHERE se1.codstare1 = acodstare1;
  EXCEPTION WHEN OTHERS THEN
    aDataCreare := sysdate;
  END;

  DELETE tmp_cmd_tmp;
  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT CODLINIECOMANDA, SUM(L.CANT) CANT, &apos;STORNO&apos;
  FROM CMDLIVRLINK L
       INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
       INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
  WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66 AND s1.codobiect = acodobiect
  GROUP BY CODLINIECOMANDA;

  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT se1.codobiect, sum(nvl(se1.estimat,0)) cant, &apos;ESTINTP&apos;
  FROM stareestimari1 se1
       INNER JOIN stareestimari se on se1.codstare = se.codstare
  WHERE se.an = aAn AND se.saptamana = aSet AND se.AnG * 100 + se.saptamanag &lt; aAnG * 100 + aSetG
        AND se.subunitatea = aSubunitatea AND se1.codobiect = acodobiect
  GROUP by se1.codobiect;

  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP&apos;
  FROM STAREESTIMARI1 SE1
       INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
       INNER JOIN planiflink l on l.codstare1 = se1.codstare1
       INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codcomanda1
       INNER JOIN comanda c on c1.codcomanda = c.codcomanda
       LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
  WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
        AND se.subunitatea = aSubunitatea AND c1.codobiect = acodobiect
        AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
        AND c1.termen between iso_week_to_date(aAnG, aSetG) AND iso_week_to_date(aAnG, aSetG) + 6
  GROUP by c1.codobiect;

  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX&apos;
  FROM STAREESTIMARI1 SE1
       INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
       INNER JOIN stareestimari2 se2 on se2.codstare = se.codstare AND se2.codstare1 = se1.codstare1
  WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
        AND se.subunitatea = aSubunitatea AND se1.codobiect = acodobiect
  GROUP by se1.codobiect;

  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTC&apos;
  FROM STAREESTIMARI1 SE1
       INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
       INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
       INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
  WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
        AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
        AND PC.USERID = PKG_GLOBALS.GETUSERID AND se1.codstare1 = acodstare1
  GROUP BY SE1.CODSTARE1;

  INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
  SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTCA&apos;
  FROM STAREESTIMARI1 SE1
       INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
       INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
       INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
  WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
        AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
        AND PC.USERID &lt;&gt; PKG_GLOBALS.GETUSERID AND se1.codstare1 = acodstare1
  GROUP BY SE1.CODSTARE1;

  BEGIN
  IF aAnG * 100 + aSetG = aAn * 100 + aSet THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
    FROM comanda1 c1
         INNER JOIN comanda c on c.codcomanda = c1.codcomanda
         LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
          AND c.subunitatea = aSubunitatea
          AND c1.termen &lt;= iso_week_to_date(aAnG, aSetG) + 6
          AND c.datacreare &gt; adatacreare AND c1.codobiect = acodobiect
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
    GROUP by c1.codobiect;

    OPEN TmpCursor FOR
    SELECT
      x.codstare,
      x.codstare1,
      x.codobiect,
      x.stocmin,
      x.stocini,
      x.StocPrec,
      x.Estimari,
      x.CmdF,
      - x.Necesar Necesar,
      - x.Necesar * X.Pret ValNecesar,
      x.StocFinal,
      x.Pret,
      x.StocVal,
      rownum,
      x.denumire,
      x.cmdfp,
      x.restprecmd,
      x.restprecmda,
      x.dirty,
      x.dirtycmdf,
      x.part1nec,
      x.UMSec,
      x.UM1,
      x.D1,
      x.D2,
      x.D3,
      - round(
        CASE
          WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
          WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
          WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
          WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
          WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
          WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
        END,7) NecesarUM1,
      x.RelatieUM1,
      x.Den_UMSec,
      x.Den_UM1,
      case
        WHEN - x.Necesar - x.restprecmd - x.restprecmda &lt; 0 THEN 0
        ELSE - x.Necesar - x.restprecmd - x.restprecmda
      END restnecesar,
      x.consum
    FROM
    (
     SELECT
      se.codstare,
      se1.codstare1,
      se1.codobiect,
      nvl(se1.stocmin,0) stocmin,
      nvl(se1.stocini,0) StocIni,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
        ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0)
      END StocPrec,
      nvl(se1.estimat,0) Estimari,
      nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
        ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
      END - nvl(se1.stocmin,0) Necesar,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
        ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
      END StocFinal,
      nvl(se1.pret,0) pret,
      nvl(se1.pret,0) * (
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END
      ) stocval,
      obj.denumire,
      cmdfp.resta CMDFP,
      nvl(RESTC.RESTA,0) RESTPRECMD,
      nvl(RESTCA.RESTA,0) RESTPRECMDA,
      se1.dirty,
      se1.dirtycmdf,
      se1.part1nec,
      um.codum1 UMSec,
      um1.codum UM1,
      art.d1,
      art.d2,
      art.d3,
      art.relatieum1,
      um.Den_UM1 Den_UMSec,
      um1.Den_Um Den_UM1,
      se1.consum
    FROM stareestimari se
         INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
         INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
         INNER JOIN nart art on art.codarticol = obj.codarticol
         LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
         LEFT JOIN num um1 on um1.codum = art.um1
         LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
         LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
         LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
         LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
         LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
         LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND se.subunitatea = aSubunitatea AND se1.codstare1 = acodstare1
    order by obj.denumire) x;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
    FROM comanda1 c1
         INNER JOIN comanda c on c.codcomanda = c1.codcomanda
         LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
          AND c.subunitatea = aSubunitatea
          AND c1.termen between iso_week_to_date(aAnG, aSetG) AND iso_week_to_date(aAnG, aSetG) + 6
          AND c.datacreare &gt; adatacreare
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
          AND c1.codobiect = acodobiect
    GROUP by c1.codobiect;
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP_PREC&apos;
    FROM STAREESTIMARI1 SE1
         INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
         INNER JOIN STAREESTIMARI SES ON SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
         INNER JOIN STAREESTIMARI1 SES1 ON SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
         INNER JOIN planiflink l on l.codstare1 = SES1.codstare1
         INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codcomanda1
         INNER JOIN comanda c on c1.codcomanda = c.codcomanda
         LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND se.subunitatea = aSubunitatea AND c1.codobiect = acodobiect
          AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
    GROUP by c1.codobiect;
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX_PREC&apos;
    FROM STAREESTIMARI1 SE1
         INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
         INNER JOIN STAREESTIMARI SES ON SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
         INNER JOIN STAREESTIMARI1 SES1 ON SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
         INNER JOIN stareestimari2 se2 on se2.codstare = ses.codstare AND se2.codstare1 = ses1.codstare1
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND se.subunitatea = aSubunitatea AND se1.codobiect = acodobiect
    GROUP by se1.codobiect;
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL_PREC&apos;
    FROM comanda1 c1
         INNER JOIN comanda c on c.codcomanda = c1.codcomanda
         LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
          AND c.subunitatea = aSubunitatea
          AND c1.termen &lt; iso_week_to_date(aAnG, aSetG)
          AND c.datacreare &gt; adatacreare AND c1.codobiect = acodobiect
          AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
          AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
    GROUP by c1.codobiect;

    OPEN TmpCursor FOR
    SELECT
      x.codstare,
      x.codstare1,
      x.codobiect,
      x.stocmin,
      x.stocini,
      x.StocPrec,
      x.Estimari,
      x.CmdF,
      - x.Necesar necesar,
      - x.Necesar * X.Pret ValNecesar,
      x.StocFinal,
      x.Pret,
      x.StocVal,
      rownum,
      x.denumire,
      x.cmdfp,
      x.restprecmd,
      x.restprecmda,
      x.dirty,
      x.dirtycmdf,
      x.part1nec,
      x.UMSec,
      x.UM1,
      x.D1,
      x.D2,
      x.D3,
      - round(
        CASE
          WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
          WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
          WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
          WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
          WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
          WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
        END,7) NecesarUM1,
      x.RelatieUM1,
      x.Den_UMSec,
      x.Den_UM1,
      case
        WHEN - x.Necesar - x.restprecmd - x.restprecmda &lt; 0 THEN 0
        ELSE - x.Necesar - x.restprecmd - x.restprecmda
      END restnecesar,
      x.consum
    FROM
    (
     SELECT
      se.codstare,
      se1.codstare1,
      se1.codobiect,
      nvl(se1.stocmin,0) stocmin,
      nvl(se1.stocini,0) StocIni,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
        ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) - nvl(EstIntP.resta,0)
      END StocPrec,
      nvl(se1.estimat,0) Estimari,
      nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
        ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
      END - nvl(se1.stocmin,0) Necesar,
      case
        WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
        ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
      END StocFinal,
      nvl(se1.pret,0) pret,
      nvl(se1.pret,0) * (
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END
      ) stocval,
      obj.denumire,
      cmdfp.resta CMDFP,
      nvl(RESTC.RESTA,0) RESTPRECMD,
      nvl(RESTCA.RESTA,0) RESTPRECMDA,
      se1.dirty,
      se1.dirtycmdf,
      se1.part1nec,
      um.codum1 UMSec,
      um1.codum UM1,
      art.d1,
      art.d2,
      art.d3,
      art.relatieum1,
      um.Den_UM1 Den_UMSec,
      um1.Den_Um Den_UM1,
      se1.consum
    FROM stareestimari se
         INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
         INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
         INNER JOIN nart art on art.codarticol = obj.codarticol
         LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
         LEFT JOIN num um1 on um1.codum = art.um1
         LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
         LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
         LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
         LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
         LEFT JOIN tmp_cmd_tmp cmdfp_prec on cmdfp_prec.codobiect = se1.codobiect AND cmdfp_prec.tip = &apos;CMDFP_PREC&apos;
         LEFT JOIN tmp_cmd_tmp cmdffix_prec on cmdffix_prec.codobiect = se1.codobiect AND cmdffix_prec.tip = &apos;CMDFFIX_PREC&apos;
         LEFT JOIN tmp_cmd_tmp cmdfl_prec on cmdfl_prec.codobiect = se1.codobiect AND cmdfl_prec.tip = &apos;CMDFL_PREC&apos;
         LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
         LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND se.subunitatea = aSubunitatea AND se1.codobiect &gt; 0 AND se1.codstare1 = acodstare1
    order by obj.denumire) x;
  END IF;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;

  DELETE tmp_cmd_tmp;
  RETURN TmpCursor;
END;

PROCEDURE MakeTemporar(aSetG in number, aAnG in number, aSet in number, aAn in number, aAllCls in number, aAllClsS in number, aAllProd in number, aPrel in boolean, RemoveDirtyCmdF in boolean) IS
  aDataCreare timestamp;
  aSubunitatea number(20);
  aUserID number(20);
  dataG date;
BEGIN
  dataG := iso_week_to_date(aAnG, aSetG);
  aSubunitatea := pkg_globals.GETSUBUNITATE;
  aUserID := pkg_globals.GETUSERID;
  BEGIN
    SELECT min(datacreare) INTO adatacreare
    FROM stareestimari WHERE an = aan AND saptamana = aset AND ang = aang AND saptamanag = asetg;
  EXCEPTION WHEN OTHERS THEN
    aDataCreare := sysdate;
  END;
  IF aPrel THEN
    vAllCls  := aAllCls;
    vAllClsS := aAllClsS;
    vAllProd := aAllProd;
    DELETE FROM TMP_NCLASEA;
    DELETE FROM TMP_NCLASEAS;
    DELETE FROM TMP_NPART;
    IF NOT aAllCls = 1 THEN
      INSERT INTO tmp_nclasea(codclasea)   SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos;;
    END IF;
    IF NOT aAllClsS = 1 THEN
      INSERT INTO tmp_nclaseas(codclaseas) SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos;;
    END IF;
    IF NOT aAllProd = 1 THEN
      INSERT INTO tmp_npart(codpart)       SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos;;
    END IF;
  END IF;

  DELETE FROM tmp_stareestimari1;
  DELETE FROM tmp_cmd_tmp;
  COMMIT;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,tip)
    SELECT o.codobiect, &apos;CODOBIECT&apos;
    FROM nartobj o INNER JOIN nart a ON a.codarticol = o.codarticol
    WHERE (aAllCls  = 1 OR EXISTS (SELECT cls.codclasea   FROM tmp_nclasea cls   WHERE cls.codclasea = a.clasa))
      AND (aAllClsS = 1 OR EXISTS (SELECT clsS.codclaseas FROM tmp_nclaseas clsS WHERE clsS.codclaseas = a.clasastatist))
      AND (aAllProd = 1 OR EXISTS (SELECT p.codpart       FROM tmp_npart p       WHERE p.codpart = o.codproducator));
  END IF;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT L.CODLINIECOMANDA, SUM(L.CANT) CANT, &apos;STORNO&apos;
    FROM CMDLIVRLINK L
      INNER JOIN COMANDA1    S1  ON S1.CODCOMANDA1 = L.CODCOMANDA1
      INNER JOIN COMANDA     S   ON S.CODCOMANDA   = S1.CODCOMANDA
      INNER JOIN TMP_CMD_TMP TMP ON TMP.CODOBIECT  = S1.CODOBIECT  AND TMP.TIP = &apos;CODOBIECT&apos;
    WHERE S.OPERAT = 1 AND Coalesce(S.ANULAT,0) = 0 AND S.TIPDOC = 66
    GROUP BY L.CODLINIECOMANDA;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT L.CODLINIECOMANDA, SUM(L.CANT) CANT, &apos;STORNO&apos;
    FROM CMDLIVRLINK L
      INNER JOIN COMANDA1    S1  ON S1.CODCOMANDA1 = L.CODCOMANDA1
      INNER JOIN COMANDA     S   ON S.CODCOMANDA   = S1.CODCOMANDA
    WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
    GROUP BY CODLINIECOMANDA;
  END IF;
  COMMIT;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT se1.codobiect, sum(nvl(se1.estimat,0)) cant, &apos;ESTINTP&apos;
    FROM stareestimari1 se1
      INNER JOIN stareestimari se  ON se.codstare   = se1.codstare
      INNER JOIN tmp_cmd_tmp   tmp ON tmp.codobiect = se1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.AnG * 100 + se.saptamanag &lt; aAnG * 100 + aSetG
      AND se.subunitatea = aSubunitatea
    GROUP BY se1.codobiect;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT se1.codobiect, sum(nvl(se1.estimat,0)) cant, &apos;ESTINTP&apos;
    FROM stareestimari1 se1 INNER JOIN stareestimari se  ON se.codstare   = se1.codstare
    WHERE se.an = aAn AND se.saptamana = aSet
      AND se.AnG * 100 + se.saptamanag &lt; aAnG * 100 + aSetG
      AND se.subunitatea = aSubunitatea
    GROUP BY se1.codobiect;
  END IF;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP&apos;
    FROM STAREESTIMARI1 SE1
      INNER JOIN STAREESTIMARI SE     ON SE.CODSTARE    = SE1.CODSTARE
      INNER JOIN PLANIFLINK    L      ON l.codstare1    = se1.codstare1
      INNER JOIN COMANDA1      C1     ON c1.codcomanda1 = l.codcomanda1
      INNER JOIN COMANDA       C      ON c.codcomanda   = c1.codcomanda
      INNER JOIN TMP_CMD_TMP   TMP    ON tmp.codobiect  = c1.codobiect     AND TMP.TIP    = &apos;CODOBIECT&apos;
      LEFT  JOIN TMP_CMD_TMP   STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
      AND se.subunitatea = aSubunitatea
      AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
      AND c1.termen between dataG AND dataG + 6
      --and c1.restacceptat &gt; 0
      AND C.datadoc &gt;= sysdate - 365
    GROUP BY c1.codobiect;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP&apos;
    FROM STAREESTIMARI1 SE1
      INNER JOIN STAREESTIMARI SE     ON SE.CODSTARE    = SE1.CODSTARE
      INNER JOIN PLANIFLINK    L      ON l.codstare1    = se1.codstare1
      INNER JOIN COMANDA1      C1     ON c1.codcomanda1 = l.codcomanda1
      INNER JOIN COMANDA       C      ON c.codcomanda   = c1.codcomanda
      LEFT  JOIN TMP_CMD_TMP   STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
      AND se.subunitatea = aSubunitatea
      AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
      AND c1.termen between dataG AND dataG + 6
      AND C.datadoc &gt;= sysdate - 365
      --AND C1.RESTACCEPTAT &gt; 0
    GROUP BY c1.codobiect;
  END IF;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX&apos;
    FROM STAREESTIMARI SE
      INNER JOIN STAREESTIMARI1 SE1 ON SE1.CODSTARE  = SE.CODSTARE
      INNER JOIN STAREESTIMARI2 SE2 ON SE2.CODSTARE  = SE.CODSTARE   AND SE2.CODSTARE1 = SE1.CODSTARE1
      INNER JOIN TMP_CMD_TMP    TMP ON TMP.CODOBIECT = SE1.CODOBIECT AND tmp.tip = &apos;CODOBIECT&apos;
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
      AND se.subunitatea = aSubunitatea
    GROUP BY se1.codobiect;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX&apos;
    FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, stareestimari2 se2
    WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
          AND se.subunitatea = aSubunitatea AND SE1.CODSTARE = SE.CODSTARE
          AND se2.codstare = se.codstare AND se2.codstare1 = se1.codstare1
    GROUP by se1.codobiect;
  END IF;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTC&apos;
    FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, PRECOMANDA1 PC1, PRECOMANDA PC, tmp_cmd_tmp tmp
    WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
          AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
          AND PC.USERID = PKG_GLOBALS.GETUSERID AND SE1.CODSTARE = SE.CODSTARE
          AND PC1.CODSTARE1 = SE1.CODSTARE1 AND PC.CODPRECOMANDA = PC1.CODPRECOMANDA
          AND tmp.codobiect = se1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
          AND PC1.REST &gt; 0
    GROUP BY SE1.CODSTARE1;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTC&apos;
    FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, PRECOMANDA1 PC1, PRECOMANDA PC
    WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
          AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
          AND PC.USERID = PKG_GLOBALS.GETUSERID AND SE1.CODSTARE = SE.CODSTARE
          AND PC1.CODSTARE1 = SE1.CODSTARE1 AND PC.CODPRECOMANDA = PC1.CODPRECOMANDA
          AND PC1.REST &gt; 0
    GROUP BY SE1.CODSTARE1;
  END IF;

  IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTCA&apos;
    FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, PRECOMANDA1 PC1, PRECOMANDA PC, tmp_cmd_tmp tmp
    WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
          AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
          AND PC.USERID &lt;&gt; PKG_GLOBALS.GETUSERID AND SE1.CODSTARE = SE.CODSTARE
          AND PC1.CODSTARE1 = SE1.CODSTARE1 AND PC.CODPRECOMANDA = PC1.CODPRECOMANDA
          AND tmp.codobiect = se1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
          AND PC1.REST &gt; 0
    GROUP BY SE1.CODSTARE1;
  ELSE
    INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
    SELECT SE1.CODSTARE1, SUM(PC1.REST) CANT, &apos;RESTCA&apos;
    FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, PRECOMANDA1 PC1, PRECOMANDA PC
    WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
          AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
          AND PC.USERID &lt;&gt; PKG_GLOBALS.GETUSERID AND SE1.CODSTARE = SE.CODSTARE
          AND PC1.CODSTARE1 = SE1.CODSTARE1 AND PC.CODPRECOMANDA = PC1.CODPRECOMANDA
          AND PC1.REST &gt; 0
    GROUP BY SE1.CODSTARE1;
  END IF;

  IF aAnG * 100 + aSetG = aAn * 100 + aSet THEN
    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
      FROM tmp_cmd_tmp tmp, comanda c, comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0 AND c.codcomanda = c1.codcomanda
            AND c.subunitatea = aSubunitatea
            AND c1.termen &lt;= dataG + 6
            AND c.an &gt;= aAnG - 1
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            AND tmp.codobiect = c1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    ELSE
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
      FROM comanda c, comanda1 c1
           LEFT JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSubunitatea
            AND c1.termen &lt;= dataG + 6
            AND c.an &gt;= aAnG - 1 AND c.codcomanda = c1.codcomanda
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    END IF;

    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_stareestimari1 (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        DIRTY,
        DIRTYCMDF,
        PART1NEC,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.dirty,
        x.dirtycmdf,
        x.part1nec,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.resta CMDFP,
        nvl(RESTC.RESTA,0) RESTPRECMD,
        nvl(RESTCA.RESTA,0) RESTPRECMDA,
        se1.dirty,
        se1.dirtycmdf,
        se1.part1nec,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           INNER JOIN tmp_cmd_tmp tmp on tmp.codobiect = se1.codobiect
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
           LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND se1.codobiect &gt; 0
            AND tmp.tip = &apos;CODOBIECT&apos;
      order by obj.denumire) x;
    ELSE
      INSERT INTO tmp_stareestimari1 (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        DIRTY,
        DIRTYCMDF,
        PART1NEC,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.dirty,
        x.dirtycmdf,
        x.part1nec,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.resta CMDFP,
        nvl(RESTC.RESTA,0) RESTPRECMD,
        nvl(RESTCA.RESTA,0) RESTPRECMDA,
        se1.dirty,
        se1.dirtycmdf,
        se1.part1nec,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
           LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND se1.codobiect &gt; 0
      order by obj.denumire) x;
    END IF;
  ELSE
    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
      FROM tmp_cmd_tmp tmp, comanda c, comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSubunitatea AND c.codcomanda = c1.codcomanda
            AND c1.termen between dataG AND dataG + 6
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            AND tmp.codobiect = c1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    ELSE
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL&apos;
      FROM comanda c, comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSubunitatea
            AND c1.termen between dataG AND dataG + 6
            AND c.datacreare &gt; adatacreare AND c.codcomanda = c1.codcomanda
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            --AND C1.RESTACCEPTAT &gt; 0
            AND C.datadoc &gt;= sysdate - 365
      GROUP by c1.codobiect;
    END IF;

    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP_PREC&apos;
      FROM tmp_cmd_tmp tmp, STAREESTIMARI1 SE1, STAREESTIMARI SE, STAREESTIMARI SES, STAREESTIMARI1 SES1, planiflink l, comanda c,
           comanda1 c1
           LEFT JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE tmp.codobiect = se1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
            AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND SE1.CODSTARE = SE.CODSTARE
            AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0 AND c1.codcomanda = c.codcomanda
            AND SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
            AND SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT AND l.codstare1 = SES1.codstare1
            AND c1.codcomanda1 = l.codcomanda1
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    ELSE
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFP_PREC&apos;
      FROM STAREESTIMARI1 SE1, STAREESTIMARI SE, STAREESTIMARI SES, STAREESTIMARI1 SES1,
           planiflink l, comanda c, comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND SE1.CODSTARE = SE.CODSTARE
            AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
            AND SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
            AND l.codstare1 = SES1.codstare1 AND c1.codcomanda1 = l.codcomanda1
            AND c1.codcomanda = c.codcomanda
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    END IF;

    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX_PREC&apos;
      FROM tmp_cmd_tmp tmp
        INNER JOIN STAREESTIMARI1 SE1  ON SE1.CODOBIECT = TMP.CODOBIECT
        INNER JOIN STAREESTIMARI  SE   ON SE1.CODSTARE  = SE.CODSTARE
        INNER JOIN STAREESTIMARI  SES  ON SES.SAPTAMANA = SE.SAPTAMANA AND SES.AN = SE.AN AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
        INNER JOIN STAREESTIMARI1 SES1 ON SES1.CODSTARE = SES.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
        INNER JOIN STAREESTIMARI2 SE2  ON SE2.CODSTARE  = SES.CODSTARE AND SE2.CODSTARE1  = SES1.CODSTARE1
      WHERE tmp.tip = &apos;CODOBIECT&apos;
        AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
        AND se.subunitatea = aSubunitatea
      GROUP BY se1.codobiect;
    ELSE
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT se1.codobiect, sum(se2.restacceptat) cant, &apos;CMDFFIX_PREC&apos;
      FROM STAREESTIMARI1 SE1
        INNER JOIN STAREESTIMARI  SE   ON SE1.CODSTARE  = SE.CODSTARE
        INNER JOIN STAREESTIMARI  SES  ON SES.SAPTAMANA = SE.SAPTAMANA AND SES.AN = SE.AN AND SES.ANG * 100 + SES.SAPTAMANAG &lt; SE.ANG * 100 + SE.SAPTAMANAG
        INNER JOIN STAREESTIMARI1 SES1 ON SES1.CODSTARE = SES.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
        INNER JOIN STAREESTIMARI2 SE2  ON SE2.CODSTARE  = SES.CODSTARE AND SE2.CODSTARE1  = SES1.CODSTARE1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
        AND se.subunitatea = aSubunitatea
      GROUP BY se1.codobiect;
    END IF;

    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL_PREC&apos;
      FROM tmp_cmd_tmp tmp,comanda c,comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSubunitatea AND tmp.codobiect = c1.codobiect AND tmp.tip = &apos;CODOBIECT&apos;
            AND c1.termen &lt; dataG AND c.codcomanda = c1.codcomanda
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    ELSE
      INSERT INTO tmp_cmd_tmp(codobiect,resta,tip)
      SELECT c1.codobiect, sum(c1.cantacceptat - NVL(Storno.RESTA,0)) cant, &apos;CMDFL_PREC&apos;
      FROM comanda c,comanda1 c1
           LEFT  JOIN tmp_cmd_tmp STORNO ON STORNO.CODOBIECT = C1.CodComanda1 AND STORNO.TIP = &apos;STORNO&apos;
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSubunitatea
            AND c1.termen &lt; dataG AND c.codcomanda = c1.codcomanda
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1)
            AND C.datadoc &gt;= sysdate - 365
            --AND C1.RESTACCEPTAT &gt; 0
      GROUP by c1.codobiect;
    END IF;

    IF aAllCls + aAllClsS + aAllProd &gt; 0 THEN
      INSERT INTO tmp_stareestimari1 (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        DIRTY,
        DIRTYCMDF,
        PART1NEC,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.dirty,
        x.dirtycmdf,
        x.part1nec,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) - nvl(EstIntP.resta,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.resta CMDFP,
        nvl(RESTC.RESTA,0) RESTPRECMD,
        nvl(RESTCA.RESTA,0) RESTPRECMDA,
        se1.dirty,
        se1.dirtycmdf,
        se1.part1nec,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           INNER JOIN tmp_cmd_tmp tmp on tmp.codobiect = se1.codobiect
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp_prec on cmdfp_prec.codobiect = se1.codobiect AND cmdfp_prec.tip = &apos;CMDFP_PREC&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix_prec on cmdffix_prec.codobiect = se1.codobiect AND cmdffix_prec.tip = &apos;CMDFFIX_PREC&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl_prec on cmdfl_prec.codobiect = se1.codobiect AND cmdfl_prec.tip = &apos;CMDFL_PREC&apos;
           LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND se1.codobiect &gt; 0
            AND tmp.tip = &apos;CODOBIECT&apos;
      order by obj.denumire) x;
    ELSE
      INSERT INTO tmp_stareestimari1 (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        DIRTY,
        DIRTYCMDF,
        PART1NEC,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.dirty,
        x.dirtycmdf,
        x.part1nec,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) - nvl(EstIntP.resta,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.resta,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.resta,0) + nvl(CmdFFix_prec.resta,0) + nvl(CmdFL_prec.resta,0) + nvl(CmdFP.resta,0) + nvl(CmdFFix.resta,0) + nvl(CmdFL.resta,0) - nvl(EstIntP.resta,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.resta CMDFP,
        nvl(RESTC.RESTA,0) RESTPRECMD,
        nvl(RESTCA.RESTA,0) RESTPRECMDA,
        se1.dirty,
        se1.dirtycmdf,
        se1.part1nec,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd_tmp EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp on cmdfp.codobiect = se1.codobiect AND cmdfp.tip = &apos;CMDFP&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl on cmdfl.codobiect = se1.codobiect AND cmdfl.tip = &apos;CMDFL&apos;
           LEFT JOIN tmp_cmd_tmp cmdfp_prec on cmdfp_prec.codobiect = se1.codobiect AND cmdfp_prec.tip = &apos;CMDFP_PREC&apos;
           LEFT JOIN tmp_cmd_tmp cmdffix_prec on cmdffix_prec.codobiect = se1.codobiect AND cmdffix_prec.tip = &apos;CMDFFIX_PREC&apos;
           LEFT JOIN tmp_cmd_tmp cmdfl_prec on cmdfl_prec.codobiect = se1.codobiect AND cmdfl_prec.tip = &apos;CMDFL_PREC&apos;
           LEFT JOIN tmp_cmd_tmp RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND RESTC.TIP = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd_tmp RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1 AND RESTCA.TIP = &apos;RESTCA&apos;
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSubunitatea AND se1.codobiect &gt; 0
      order by obj.denumire) x;
    END IF;
  END IF;

  UPDATE tmp_stareestimari1 SET
  restnecesar =
    case
      WHEN necesar - restprecmd - restprecmda &lt; 0 THEN 0
      ELSE necesar - restprecmd - restprecmda
    END,
  StocDC = StocFinal + cmdfp,
  valnecesar = nvl(necesar,0) * nvl(pret,0);

  IF RemoveDirtyCmdF THEN
    UPDATE stareestimari1 se1
    SET
      dirtycmdf = 0
    WHERE exists (SELECT se.codstare FROM stareestimari se
                  WHERE se.an = aAn AND se.saptamana = aSet
                        AND se.ang = aang AND se.saptamanag = aSetG
                        AND se.codstare = se1.codstare AND se.subunitatea = aSubunitatea
                  );
    UPDATE tmp_stareestimari1 SET dirtycmdf = 0;
  END IF;

  DELETE tmp_cmd_tmp;
  COMMIT;
END;

PROCEDURE MakeTemporarCentralizat(aSet in number, aAn in number) IS
aDataCreare timestamp;
aSetG number;
aAnG number;
aUserID number(20);
aSubunitatea number(20);
si date;
sf date;
MultipA number(10);
BEGIN
  aUserID      := pkg_globals.getuserid;
  aSubunitatea := pkg_globals.GETSUBUNITATE;
  BEGIN
    SELECT min(datacreare) INTO adatacreare
    FROM stareestimari WHERE an = aan AND saptamana = aset;
  EXCEPTION WHEN OTHERS THEN
    aDataCreare := sysdate;
  END;

  aAnG := aAn;
  aSetG := aSet;

  DELETE tmp_stareestimari1_centr WHERE userid = aUserID;
  multipa := Multip(aAn);

  for i in 1..multipa loop
    si := iso_week_to_date(aAnG, aSetG);
    sf := iso_week_to_date(aAnG, aSetG) + 6;
    IF aAnG * multipa + aSetG = aAn * multipa + aSet THEN
      DELETE tmp_cmd2 WHERE userid = auserid;
      DELETE tmp_cmd_pluna2 WHERE userid = auserid;
      COMMIT;
      --  1 CMDFP
      -- 11 STORNO CMDFP
      --  2 CMDFL
      -- 22 STORNO CMDFL

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT sum(nvl(se1.estimat,0)), se1.codobiect, aUserID, &apos;ESTINTP&apos;
      FROM stareestimari1 se1
           INNER JOIN stareestimari se on se1.codstare = se.codstare
      WHERE se.an = aAn AND se.saptamana = aSet AND se.AnG * multipa + se.saptamanag &lt; aAnG * multipa + aSetG
            AND se.subunitatea = aSUBUNITATEA
      GROUP by se1.codobiect;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 1 --CMDFP
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN planiflink l on l.codstare1 = se1.codstare1
           INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codcomanda1
           INNER JOIN comanda c on c1.codcomanda = c.codcomanda
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
            AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c1.termen between si AND sf;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 11, aUserID --STORNO CMDFP
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 1
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT sum(se2.restacceptat) cant, se1.codobiect, aUserID, &apos;CMDFFIX&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN stareestimari2 se2 on se2.codstare = se.codstare AND se2.codstare1 = se1.codstare1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
      GROUP by se1.codobiect;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 2 --CMDFL
      FROM comanda1 c1
           INNER JOIN comanda c on c.codcomanda = c1.codcomanda
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSUBUNITATEA
            AND c1.termen &lt;= sf
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 22, aUserID --STORNO CMDFL
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 2
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1, aUserID, &apos;RESTC&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
           INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
      WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
            AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
            AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND PC.USERID = aUSERID
            AND PC1.REST &gt; 0
      GROUP BY SE1.CODSTARE1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1, aUserID, &apos;RESTCA&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
           INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
      WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
            AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
            AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND PC.USERID &lt;&gt; aUSERID
            AND PC1.REST &gt; 0
      GROUP BY SE1.CODSTARE1;

      INSERT INTO tmp_stareestimari1_centr (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum,
        an,
        saptamana,
        userid
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum,
        aAnG,
        aSetG,
        aUserID
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.cant CMDFP,
        nvl(RESTC.CANTC,0) RESTPRECMD,
        nvl(RESTCA.CANTC,0) RESTPRECMDA,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd2 EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Userid = aUserID AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 11
                      WHERE tmp.userid = aUserID AND tmp.tip = 1
                      GROUP by c1.codobiect
                     ) cmdfp on cmdfp.codobiect = se1.codobiect
           LEFT JOIN tmp_cmd2 cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.userid = aUserID AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 22
                      WHERE tmp.userid = aUserID AND tmp.tip = 2
                      GROUP by c1.codobiect
                     ) cmdfl on cmdfl.codobiect = se1.codobiect
           LEFT JOIN tmp_cmd2 RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND restc.userid = aUserID AND restc.Tip = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd2 RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
      order by obj.denumire) x;
    ELSE
      DELETE tmp_cmd2 WHERE userid = auserid;
      DELETE tmp_cmd_pluna2 WHERE userid = auserid;
      COMMIT;
      --  1 CMDFP
      -- 11 STORNO CMDFP
      --  2 CMDFL
      -- 22 STORNO CMDFL

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT sum(nvl(se1.estimat,0)) cant, se1.codobiect, aUserID, &apos;ESTINTP&apos;
      FROM stareestimari1 se1
           INNER JOIN stareestimari se on se1.codstare = se.codstare
      WHERE se.an = aAn AND se.saptamana = aSet AND se.AnG * multipa + se.saptamanag &lt; aAnG * multipa + aSetG
            AND se.subunitatea = aSUBUNITATEA
      GROUP by se1.codobiect;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 1 --CMDFP
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN planiflink l on l.codstare1 = se1.codstare1
           INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codcomanda1
           INNER JOIN comanda c on c1.codcomanda = c.codcomanda
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
            AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c1.termen between si AND sf;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 11, aUserID --STORNO CMDFP
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 1
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT sum(se2.restacceptat) cant, se1.codobiect, aUserID, &apos;CMDFFIX&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN stareestimari2 se2 on se2.codstare = se.codstare AND se2.codstare1 = se1.codstare1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
      GROUP by se1.codobiect;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 2 --CMDFL
      FROM comanda1 c1
           INNER JOIN comanda c on c.codcomanda = c1.codcomanda
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSUBUNITATEA
            AND c1.termen between si AND sf
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 22, aUserID --STORNO CMDFL
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 2
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 3 --CMDFP_PREC
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN STAREESTIMARI SES ON SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * multipa + SES.SAPTAMANAG &lt; SE.ANG * multipa + SE.SAPTAMANAG
           INNER JOIN STAREESTIMARI1 SES1 ON SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
           INNER JOIN planiflink l on l.codstare1 = SES1.codstare1
           INNER JOIN comanda1 c1 on c1.codcomanda1 = l.codcomanda1
           INNER JOIN comanda c on c1.codcomanda = c.codcomanda
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
            AND c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 33, aUserID --STORNO CMDFP_PREC
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 3
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT sum(se2.restacceptat) cant, se1.codobiect, aUserID, &apos;CMDFFIX_PREC&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN STAREESTIMARI SES ON SES.AN = SE.AN AND SES.SAPTAMANA = SE.SAPTAMANA AND SES.ANG * multipa + SES.SAPTAMANAG &lt; SE.ANG * multipa + SE.SAPTAMANAG
           INNER JOIN STAREESTIMARI1 SES1 ON SES.CODSTARE = SES1.CODSTARE AND SES1.CODOBIECT = SE1.CODOBIECT
           INNER JOIN stareestimari2 se2 on se2.codstare = ses.codstare AND se2.codstare1 = ses1.codstare1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
      GROUP by se1.codobiect;

      INSERT INTO tmp_cmd_pluna2(codcomanda1, userid, tip)
      SELECT c1.codcomanda1, aUserID, 4 --CMDFL_PREC
      FROM comanda1 c1
           INNER JOIN comanda c on c.codcomanda = c1.codcomanda
      WHERE c.tipdoc = 8 AND c.operat = 1 AND c.anulat = 0
            AND c.subunitatea = aSUBUNITATEA
            AND c1.termen &lt; si
            AND c.datacreare &gt; adatacreare
            AND NOT exists (SELECT se2.codcomanda1 FROM stareestimari2 se2 WHERE se2.codcomanda1 = c1.codcomanda1)
            AND NOT exists (SELECT l.codcomanda1 FROM planiflink l WHERE l.codcomanda1 = c1.codcomanda1);

      INSERT INTO tmp_cmd_pluna2(codcomanda1, cant1, tip, userid)
      SELECT TMP.CODCOMANDA1, SUM(L.CANT), 44, aUserID --STORNO CMDFL_PREC
      FROM TMP_CMD_PLUNA2 TMP
           INNER JOIN CMDLIVRLINK L ON TMP.CODCOMANDA1 = L.CODLINIECOMANDA
           INNER JOIN COMANDA1 S1 ON L.CODCOMANDA1 = S1.CODCOMANDA1
           INNER JOIN COMANDA S ON S1.CODCOMANDA = S.CODCOMANDA
      WHERE S.OPERAT = 1 AND NVL(S.ANULAT,0) = 0 AND S.TIPDOC = 66
            AND TMP.USERID = aUserID AND tmp.tip = 4
      GROUP BY TMP.CODCOMANDA1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1, aUserID, &apos;RESTC&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
           INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
      WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
            AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
            AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND PC.USERID = aUSERID
            AND PC1.REST &gt; 0
      GROUP BY SE1.CODSTARE1;

      INSERT INTO tmp_cmd2(cantc, codobiect, userid, tip)
      SELECT SUM(PC1.REST) CANT, SE1.CODSTARE1, aUserID, &apos;RESTCA&apos;
      FROM STAREESTIMARI1 SE1
           INNER JOIN STAREESTIMARI SE ON SE1.CODSTARE = SE.CODSTARE
           INNER JOIN PRECOMANDA1 PC1 ON PC1.CODSTARE1 = SE1.CODSTARE1
           INNER JOIN PRECOMANDA PC ON PC.CODPRECOMANDA = PC1.CODPRECOMANDA
      WHERE se.an = PC.ANC AND se.saptamana = PC.SAPTAMANAC
            AND SE.ANG = PC.ANG AND SE.SAPTAMANAG = PC.SAPTAMANAG
            AND se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND PC.USERID &lt;&gt; aUSERID
            AND PC1.REST &gt; 0
      GROUP BY SE1.CODSTARE1;

      INSERT INTO tmp_stareestimari1_centr (
        codstare,
        codstare1,
        codobiect,
        stocmin,
        stocini,
        StocPrec,
        Estimari,
        CmdF,
        Necesar,
        StocFinal,
        Pret,
        StocVal,
        indexlocal,
        denumire,
        CMDFP,
        RESTPRECMD,
        RESTPRECMDA,
        UMSec,
        UM1,
        D1,
        D2,
        D3,
        NecesarUM1,
        RelatieUM1,
        Den_UMSec,
        Den_UM1,
        consum,
        an,
        saptamana,
        UserID
      )
      SELECT
        x.codstare,
        x.codstare1,
        x.codobiect,
        x.stocmin,
        x.stocini,
        x.StocPrec,
        x.Estimari,
        x.CmdF,
        - x.Necesar,
        x.StocFinal,
        x.Pret,
        x.StocVal,
        rownum,
        x.denumire,
        x.cmdfp,
        x.restprecmd,
        x.restprecmda,
        x.UMSec,
        x.UM1,
        x.D1,
        x.D2,
        x.D3,
        - round(
          CASE
            WHEN x.RELATIEUM1 IN (1, 7) AND NVL(x.D1,0) &lt;&gt; 0 THEN x.NECESAR/x.D1
            WHEN x.RELATIEUM1 IN (2, 8) AND NVL(x.D1,0) * NVL(x.D2,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0))
            WHEN x.RELATIEUM1 IN (3, 9) AND NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0) &lt;&gt; 0 THEN x.NECESAR / (NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0))
            WHEN x.RELATIEUM1 IN (4, 10) THEN x.NECESAR * NVL(x.D1,0)
            WHEN x.RELATIEUM1 IN (5, 11) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0)
            WHEN x.RELATIEUM1 IN (6, 12) THEN x.NECESAR * NVL(x.D1,0) * NVL(x.D2,0) * NVL(x.D3,0)
          END,7) NecesarUM1,
        x.RelatieUM1,
        x.Den_UMSec,
        x.Den_UM1,
        x.consum,
        aAnG,
        aSetG,
        aUserID
      FROM
      (
       SELECT
        se.codstare,
        se1.codstare1,
        se1.codobiect,
        nvl(se1.stocmin,0) stocmin,
        nvl(se1.stocini,0) StocIni,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN se1.StocIni
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) - nvl(EstIntP.cantc,0)
        END StocPrec,
        nvl(se1.estimat,0) Estimari,
        nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) CmdF,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
        END - nvl(se1.stocmin,0) Necesar,
        case
          WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
          ELSE nvl(se1.stocini,0) + nvl(CmdFP.cant,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
        END StocFinal,
        nvl(se1.pret,0) pret,
        nvl(se1.pret,0) * (
          case
            WHEN aSetG = aSet AND aAnG = aAn THEN nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(se1.estimat,0)
            ELSE nvl(se1.stocini,0) + nvl(CmdFP_prec.cant,0) + nvl(CmdFFix_prec.cantc,0) + nvl(CmdFL_prec.cant,0) + nvl(CmdFP.cant,0) + nvl(CmdFFix.cantc,0) + nvl(CmdFL.cant,0) - nvl(EstIntP.cantc,0) - nvl(se1.estimat,0)
          END
        ) stocval,
        obj.denumire,
        cmdfp.cant CMDFP,
        nvl(RESTC.CANTC,0) RESTPRECMD,
        nvl(RESTCA.CANTC,0) RESTPRECMDA,
        um.codum1 UMSec,
        um1.codum UM1,
        art.d1,
        art.d2,
        art.d3,
        art.relatieum1,
        um.Den_UM1 Den_UMSec,
        um1.Den_Um Den_UM1,
        se1.consum
      FROM stareestimari se
           INNER JOIN stareestimari1 se1 on se1.codstare = se.codstare
           INNER JOIN nartobj obj on se1.codobiect = obj.codobiect
           INNER JOIN nart art on art.codarticol = obj.codarticol
           LEFT JOIN num1 um on um.codum = art.um AND nvl(um.secundara,0) = 0
           LEFT JOIN num um1 on um1.codum = art.um1
           LEFT JOIN tmp_cmd2 EstIntP on EstIntP.codobiect = se1.codobiect AND EstIntP.Userid = aUserID AND EstIntP.Tip = &apos;ESTINTP&apos;
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 11
                      WHERE tmp.userid = aUserID AND tmp.tip = 1
                      GROUP by c1.codobiect
                     ) cmdfp on cmdfp.codobiect = se1.codobiect
           LEFT JOIN tmp_cmd2 cmdffix on cmdffix.codobiect = se1.codobiect AND cmdffix.userid = aUserID AND cmdffix.tip = &apos;CMDFFIX&apos;
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 22
                      WHERE tmp.userid = aUserID AND tmp.tip = 2
                      GROUP by c1.codobiect
                     ) cmdfl on cmdfl.codobiect = se1.codobiect
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 33
                      WHERE tmp.userid = aUserID AND tmp.tip = 3
                      GROUP by c1.codobiect
                     ) cmdfp_prec on cmdfp_prec.codobiect = se1.codobiect
           LEFT JOIN tmp_cmd2 cmdffix_prec on cmdffix_prec.codobiect = se1.codobiect AND cmdffix_prec.userid = aUserID AND cmdffix_prec.tip = &apos;CMDFFIX_PREC&apos;
           LEFT JOIN (SELECT sum(c1.cantacceptat - NVL(Storno.Cant1,0)) cant, c1.codobiect
                      FROM tmp_cmd_pluna2 tmp
                           INNER JOIN comanda1 c1 on tmp.codcomanda1 = c1.codcomanda1
                           LEFT  JOIN tmp_cmd_pluna2 STORNO ON STORNO.CodComanda1 = tmp.CodComanda1 AND storno.userid = aUserID AND storno.tip = 44
                      WHERE tmp.userid = aUserID AND tmp.tip = 4
                      GROUP by c1.codobiect
                     ) cmdfl_prec on cmdfl_prec.codobiect = se1.codobiect
           LEFT JOIN tmp_cmd2 RESTC ON RESTC.CODOBIECT = SE1.CODSTARE1 AND restc.userid = aUserID AND restc.Tip = &apos;RESTC&apos;
           LEFT JOIN tmp_cmd2 RESTCA ON RESTCA.CODOBIECT = SE1.CODSTARE1
      WHERE se.an = aAn AND se.saptamana = aSet AND se.ang = aAnG AND se.saptamanag = aSetG
            AND se.subunitatea = aSUBUNITATEA
      order by obj.denumire) x;
    END IF;

    UPDATE tmp_stareestimari1_centr SET
    restnecesar =
      case
        WHEN necesar - restprecmd - restprecmda &lt; 0 THEN 0
        ELSE necesar - restprecmd - restprecmda
      END,
    StocDC = StocFinal + cmdfp,
    valnecesar = nvl(necesar,0) * nvl(pret,0)
    WHERE an = aAnG AND saptamana = aSetG AND userid = aUserId;

    IF aSetg = multipa THEN
      aSetG := 1;
      aAnG := aAnG + 1;
    ELSE
      aSetG := aSetG + 1;
    END IF;
  END loop;

  DELETE tmp_cmd2 WHERE userid = auserid;
  DELETE tmp_cmd_pluna2 WHERE userid = auserid;

  COMMIT;
END;

PROCEDURE GenereazaStare(aAn in number, aSet in number, aCodOferta in number) IS
aAnG number(4);
aSetG number(2);
aDataCreare timestamp;
aSubunitatea number(20);
aUserId number(20);
aCodStare number(20);
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  aAnG := aAn;
  aSetG := aSet;
  aDataCreare := sysdate;
  aSubunitatea := pkg_globals.GETSUBUNITATE;
  aUserID := pkg_globals.GETUSERID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;STAREESTIMARI&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, aAn*Multip(aAn)+aSet, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataCreare, aSet||&apos;/&apos;||aAn, aSet||&apos;/&apos;||aAn, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  UmpleTemporarGenerator(aAn * Multip(aAn) + aSet, aUserID, aSubunitatea);

  DELETE TMP_PLANIFCMDMAT WHERE userid = aUserID;
  INSERT INTO TMP_PLANIFCMDMAT (CODOBIECT, STOC, STOCMIN, PRET, USERID)
  SELECT distinct obj.codobiect codobiect, stoc.cant stoc, osub.stocmin stocmin, o1.pret, aUserID
  FROM nartobj obj
       LEFT JOIN nartobjsubunit osub on osub.codobiect = OBJ.codobiect
                                     AND ( osub.codgest IS null OR osub.codgest = 0)
                                     AND osub.subunitate = aSubunitatea
       LEFT JOIN (SELECT sum(case WHEN nir.operat = 0 THEN ns.cantnir ELSE ns.rest END) cant, ns.codobiect
                  FROM nirstoc ns
                       INNER JOIN nir on nir.codnir = ns.codnir
                       INNER JOIN ngest g on g.codgest = nir.gest
                  WHERE g.codsubunit = pkg_globals.GETSUBUNITATE AND ((ns.rest &lt;&gt; 0 AND nir.operat = 1) OR (ns.rest = 0 AND nir.operat = 0 AND nir.tipnir = 12)) AND g.tip &lt;&gt; 4
                  GROUP by ns.codobiect
                  ) stoc on stoc.codobiect = obj.codobiect
       LEFT JOIN OFERTA1 O1 ON O1.CODOFERTA = aCodOferta AND O1.Codobiect = obj.Codobiect,
       nart art
       INNER JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = aSubunitatea
       INNER JOIN TMP_IOART_LUNA IOLUNA ON IOLUNA.CODIOART = IMP.CONTIMPLICIT
       INNER JOIN CONSTVAL CV ON TRIM(CV.VALOARE) = TRIM(TO_CHAR(IOLUNA.CONT))
       INNER JOIN CONSTLUNA CL ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
       INNER JOIN CONST1 CS1 ON CS1.CODCONST1 = CL.CODCONST1
  WHERE nvl(obj.produspropriu,0) = 0 AND obj.codarticol = art.codarticol AND nvl(art.tiparticol,&apos;0&apos;) = &apos;0&apos;
        AND UPPER(CS1.SIMBOL) = &apos;GENCMDFCONTURI&apos;;

  MERGE INTO TMP_PLANIFCMDMAT TMP
  USING (
         SELECT
           tmp.codobiect CODOBIECT,
           osub.stocmin STOCMIN,
           O1.PRET PRET,
           STOC.CANT CANT
         FROM TMP_CMDTL tmp
              LEFT JOIN nartobjsubunit osub on osub.codobiect = tmp.codobiect
                                            AND (osub.codgest IS null OR osub.codgest = 0)
                                            AND osub.subunitate = aSubunitatea
              LEFT JOIN OFERTA1 O1 ON O1.CODOFERTA = aCodOferta AND O1.Codobiect = TMP.Codobiect
              LEFT JOIN (SELECT sum(ns.rest) cant, ns.codobiect
                         FROM nirstoc ns
                              INNER JOIN nir on nir.codnir = ns.codnir
                              INNER JOIN ngest g on g.codgest = nir.gest
                         WHERE g.codsubunit = pkg_globals.GETSUBUNITATE AND ((ns.rest &lt;&gt; 0 AND nir.operat = 1) OR (ns.rest = 0 AND nir.operat = 0 AND nir.tipnir = 12)) AND g.tip &lt;&gt; 4
                         GROUP by ns.codobiect
                        ) stoc on stoc.codobiect = TMP.codobiect
         WHERE tmp.tip in (1,2) AND tmp.userid = pkg_globals.GETUSERID
         ) V
  ON (TMP.CODOBIECT = V.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.STOC, TMP.STOCMIN, TMP.PRET, TMP.USERID)
                        VALUES (V.CODOBIECT,V.CANT,V.STOCMIN,V.PRET,aUserID);

  for i in 1..Multip(aAn) loop
    SELECT seq_stareestimari_codstare.nextval INTO aCodStare FROM dual;
    INSERT INTO stareestimari (codstare, saptamana, an, saptamanag, ang, datacreare, userid, subunitatea, codoferta)
    VALUES (aCodStare, aSet, aAn, aSetG, aAnG, aDataCreare, aUSERID, aSubunitatea, aCodOferta);

    INSERT INTO stareestimari1 (codstare, codobiect, stocini, stocmin, codstare1, pret)
    SELECT aCodStare, codobiect, stoc, stocmin, seq_stareestimari1_codstare1.nextval, pret
    FROM tmp_planifcmdmat WHERE userid = aUserID;
    PKG_PLANIFCMD.setstare(aSetG, aAnG, aSet, aAn, aCodStare, aSubunitatea);

    IF aSetG = Multip(aAn) THEN
      aSetG := 1;
      aAnG := aAnG + 1;
    ELSE
      aSetG := aSetG + 1;
    END IF;
  END loop;

  for v_rec in (SELECT sum(nvl(se1.estimat,0)) estimat, sum(nvl(se1.stocmin,0)) stocmin,
                       sum(nvl(se1.stocini,0)) stocini, sum(nvl(se1.cmdf,0)) cmdf,
                       se1.codobiect
                FROM stareestimari se
                     INNER JOIN stareestimari1 se1 on se.codstare = se1.codstare
                WHERE se.an = aAn AND se.saptamana = aSet AND se.subunitatea = aSubunitatea
                GROUP by se1.codobiect
               ) loop
    IF v_rec.estimat = 0 AND v_rec.stocmin = 0 AND v_rec.stocini = 0 AND v_rec.cmdf = 0 THEN
      DELETE stareestimari1 se1
      WHERE se1.codobiect = v_rec.codobiect
            AND exists (SELECT se.codstare FROM stareestimari se WHERE se.codstare = se1.codstare AND se.an = aan AND se.saptamana = aset AND se.subunitatea = aSubunitatea);
    END IF;
  END loop;
  COMMIT;
END;

PROCEDURE UpdateNecesarInStare(aCodStare1 in number, aNecesar in number) IS
BEGIN
  UPDATE stareestimari1 SET necesaracc = aNecesar WHERE codstare1 = aCodStare1;
  UPDATE tmp_stareestimari1 SET necesaracc = aNecesar WHERE codstare1 = aCodStare1;
  COMMIT;
END;

PROCEDURE UPDATECMDEXTTL(aAn in number, aSet in number, aAnG in number, aSetG in number, aField in varchar2, aCodComanda in number) IS
Val varchar2(250);
Aux varchar2(1000);
aCount number;
aNextAn number(4);
aNextSet number(2);
oData date;
CuDetalieri boolean;
BEGIN
  IF pkg_list_struct.TmpExists(&apos;COMANDF&apos;) = 1 THEN
    Val := &apos;Necesar : &apos;||aSet||&apos;/&apos;||aAn;

    oData := iso_week_to_date(aan, aset);
    oData := oData + 7;
    aNextSet := to_number(to_char(odata,&apos;IW&apos;));
    aNextAn  := to_number(to_char(odata,&apos;IYYY&apos;));

    CuDetalieri := (aAnG = aNextAn AND aSetG = aNextSet) OR (aAn = aAnG AND aSet = aSetG);
    IF CuDetalieri THEN
      BEGIN
        aux := &apos;&apos;;
        SELECT string_agg(doc) INTO Aux
        FROM (
        SELECT p.nrdoc||&apos;/&apos;||to_char(p.datadoc,&apos;dd.mm.yyyy&apos;) doc
        FROM planifprod p
        WHERE p.an = aAn AND p.saptamana = aSet AND p.insaptamana = 1
        union all
        SELECT p.nrdoc||&apos;/&apos;||to_char(p.datadoc,&apos;dd.mm.yyyy&apos;) doc
        FROM planifprod p
        WHERE p.an = aNextAn AND p.saptamana = aNextSet AND p.insaptamana = 0
        );
      EXCEPTION WHEN OTHERS THEN Aux := &apos;&apos;;
      END;
      IF Length(Aux) &gt; 0 THEN
        Val := Val||&apos; Detalieri : &apos;||aux;
      END IF;
    END IF;

    BEGIN
      EXECUTE IMMEDIATE &apos;SELECT count(*) FROM comandf WHERE codcomanda = &apos;||acodcomanda INTO aCount;
    EXCEPTION WHEN OTHERS THEN aCount := 0;
    END;
    IF aCount &gt; 0 THEN
      BEGIN
        Aux := &apos;UPDATE comandf SET &apos;||aField||&apos; = &apos;&apos;&apos;||Val||&apos;&apos;&apos; WHERE codcomanda = &apos;||aCodComanda;
        EXECUTE IMMEDIATE Aux;
      EXCEPTION WHEN OTHERS THEN Aux := &apos;&apos;;
      END;
    ELSE
      BEGIN
        Aux := &apos;INSERT INTO comandf(CodComandf,CodComanda,&apos;||aField||&apos;) VALUES(seq_comandf_codcomandf.nextval,&apos;||aCodComanda||&apos;,&apos;&apos;&apos;||Val||&apos;&apos;&apos;)&apos;;
        EXECUTE IMMEDIATE Aux;
      EXCEPTION WHEN OTHERS THEN Aux := &apos;&apos;;
      END;
    END IF;

    COMMIT;
  END IF;
END;

/*PROCEDURE test IS
BEGIN
  DELETE stareestimari2 WHERE codstare in (SELECT codstare FROM stareestimari WHERE ang = 2015 AND saptamanag = 40);
  DELETE stareestimari1 WHERE codstare in (SELECT codstare FROM stareestimari WHERE ang = 2015 AND saptamanag = 40);
  DELETE stareestimari WHERE ang = 2015 AND saptamanag = 40;
  for i in 1..53 loop
    IF i &gt; 40 THEN
      setstare(40, 2015, i, 2015, 0, sysdate);
    ELSE
      setstare(40, 2015, i, 2016, 0, sysdate);
    END IF;
  END loop;
END;*/

END PKG_PLANIFCMD;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C2A0321763E1DD82D3B4999773AF91A0E9FE952</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANIFPROD IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_45&apos;;

procedure BagaMateriale(aNodOriginal in number, aCodObiect in number, aNecesar in number, aCodProdComp in number, aNivel in number, 
                        aCodPlanifProd1 in number, aCodPlanifProd in number, aObservatii in varchar2) is
vcodplanifnod number(20);  
vcodplanifnodorig number(20);
aCount number(10);
vCodProdComp number(20);
begin
  for v_tmp in (select mat.codobiect, 
                       case when nvl(mat.tip,3) &lt;= 2 then nvl(pc.codprodcomp,0) else 0 end codprodcomp,
                       aNecesar/decode(nvl(prod.cant,0),0,1,prod.cant)*mat.cant cant, mat.codmat, mat.indexlocal,
                       case when nvl(mat.tip,3) &lt;= 2 then 1 else 3 end Tip,
                       aObservatii||&apos;.&apos;||LPAD(to_char(mat.IndexLocal), 2, &apos;0&apos;) Observatii,
                       prod.cant lotoptim, mat.cant cantmat
                from prodmat mat
                     inner join prodcomp prod on prod.codprodcomp = mat.codprodcomp
                     left join prodcomp pc on pc.codobiect = mat.codobiect and pc.implicit = 1 and mat.tip &lt;= 2
                where mat.codprodcomp = aCodProdComp
                order by mat.indexlocal
               ) loop
    select seq_planifnod_codplanifnod.nextval into vcodplanifnod from dual;
     
    insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, cant, nodoriginal, pozitie, tip, codobiect, indexparinte, codprodmat,
                          nivel, ordine, versiune, cantprodreteta, cantmatreteta, necesar)
    values (vcodplanifnod, aCodPlanifProd1, aCodPlanifProd, v_tmp.cant, aNodOriginal, v_tmp.indexlocal, case when v_tmp.codprodcomp &gt; 0 then 1 else 3 end,
            v_tmp.codobiect, v_tmp.Observatii, v_tmp.codmat, aNivel, v_tmp.indexlocal, 0, v_tmp.lotoptim, v_tmp.cantmat, v_tmp.cant);
    if v_tmp.CodProdComp &gt; 0 then
      select seq_planifnod_codplanifnod.nextval into vcodplanifnodorig from dual; 
      
      insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, cant, nodoriginal, pozitie, tip, codobiect, indexparinte, codprodmat,
                            nivel, ordine, versiune, cantprodreteta, cantmatreteta, necesar, codreteta)
      values (vcodplanifnodorig, aCodPlanifProd1, aCodPlanifProd, v_tmp.cant, aNodOriginal, v_tmp.indexlocal, case when v_tmp.codprodcomp &gt; 0 then 1 else 3 end,
              v_tmp.codobiect, v_tmp.Observatii, v_tmp.codmat, aNivel, v_tmp.indexlocal, 1, v_tmp.lotoptim, v_tmp.cantmat, v_tmp.cant, v_tmp.codprodcomp);
      pkg_planifprod.BagaMateriale(vcodplanifnodorig, v_tmp.CodObiect, v_tmp.Cant, v_tmp.CodProdComp, aNivel + 1, aCodPlanifProd1, aCodPlanifProd, v_tmp.observatii);
    else
      if v_tmp.tip = 1 then -- nu exista reteta implicita, vad daca este unica
        select count(*) into aCount
        from prodcomp
        where codobiect = v_tmp.codobiect and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0;
        
        if aCount = 1 then
          begin
            select codprodcomp into vCodProdComp
            from prodcomp
            where codobiect = v_tmp.codobiect and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0;
          exception when others then vCodProdComp := 0;
          end;  
          
          select seq_planifnod_codplanifnod.nextval into vcodplanifnodorig from dual; 
      
          insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, cant, nodoriginal, pozitie, tip, codobiect, indexparinte, codprodmat,
                                nivel, ordine, versiune, cantprodreteta, cantmatreteta, necesar, codreteta)
          values (vcodplanifnodorig, aCodPlanifProd1, aCodPlanifProd, v_tmp.cant, aNodOriginal, v_tmp.indexlocal, case when vcodprodcomp &gt; 0 then 1 else 3 end,
                  v_tmp.codobiect, v_tmp.Observatii, v_tmp.codmat, aNivel, v_tmp.indexlocal, 1, v_tmp.lotoptim, v_tmp.cantmat, v_tmp.cant, vcodprodcomp);
          if vCodProdComp &gt; 0 then        
            pkg_planifprod.BagaMateriale(vcodplanifnodorig, v_tmp.CodObiect, v_tmp.Cant, vCodProdComp, aNivel + 1, aCodPlanifProd1, aCodPlanifProd, v_tmp.observatii);
          end if;  
        end if;
      end if;  
    end if;
  end loop;
end;

function GENSTRUCT(vCodPlanifProd in number) return number is
Rez number;  
vcodplanifnod number(20);
vcodplanifnodorig number(20);
vCodProdComp number(20);
aCount number(10);
begin
  Rez := 0;
  for v_rec in (select p1.codobiect, p1.codplanifprod1, p1.necesar
                from planifprod1 p1
                where p1.codplanifprod = vCodPlanifProd) loop
    select count(*) into aCount
    from prodcomp
    where codobiect = v_rec.codobiect and implicit = 1 and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0;
    
    if aCount = 1 then
      for v_xxx in (select codprodcomp
                    from prodcomp
                    where codobiect = v_rec.codobiect and implicit = 1 and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0
                   ) loop 
        delete planifnod where codplanifprod = vcodplanifprod;
        select seq_planifnod_codplanifnod.nextval into vcodplanifnod from dual;
        insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte, 
                              necesar, cant, cantmatreteta, cantprodreteta)
        values (vcodplanifnod, v_rec.codplanifprod1, vcodplanifprod, 0, v_rec.codobiect, 0, 0, 1, 0, &apos;.00&apos;, 
                v_rec.necesar, v_rec.necesar, 0, 0);
      
        select seq_planifnod_codplanifnod.nextval into vcodplanifnodorig from dual;                      
        insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte, 
                              necesar, cant, cantmatreteta, cantprodreteta, codreteta)
        values (vcodplanifnodorig, v_rec.codplanifprod1, vcodplanifprod, vcodplanifnod, v_rec.codobiect, 0, 0, 1, 1, &apos;.00&apos;, 
                v_rec.necesar, v_rec.necesar, 0, 0, v_xxx.codprodcomp);
        pkg_planifprod.BagaMateriale(vcodplanifnodorig, v_rec.codobiect, v_rec.necesar, v_xxx.codprodcomp, 1, 
                      v_rec.codplanifprod1, vCodPlanifProd, &apos;.00&apos;);
      end loop;              
    else
      select count(*) into aCount
      from prodcomp
      where codobiect = v_rec.codobiect and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0;
      
      if aCount = 1 then
        for v_xxx in (select codprodcomp
                      from prodcomp
                      where codobiect = v_rec.codobiect and nvl(anulat,0) = 0 and nvl(inactiv,0) = 0
                     ) loop 
          delete planifnod where codplanifprod = vcodplanifprod;
          select seq_planifnod_codplanifnod.nextval into vcodplanifnod from dual;
          insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte, 
                                necesar, cant, cantmatreteta, cantprodreteta)
          values (vcodplanifnod, v_rec.codplanifprod1, vcodplanifprod, 0, v_rec.codobiect, 0, 0, 1, 0, &apos;.00&apos;, 
                  v_rec.necesar, v_rec.necesar, 0, 0);
          
          select seq_planifnod_codplanifnod.nextval into vcodplanifnodorig from dual;                      
          insert into planifnod(codplanifnod, codplanifprod1, codplanifprod, nodoriginal, codobiect, pozitie, nivel, tip, versiune, indexparinte, 
                                necesar, cant, cantmatreteta, cantprodreteta, codreteta)
          values (vcodplanifnodorig, v_rec.codplanifprod1, vcodplanifprod, vcodplanifnod, v_rec.codobiect, 0, 0, 1, 1, &apos;.00&apos;, 
                  v_rec.necesar, v_rec.necesar, 0, 0, v_xxx.codprodcomp);
          pkg_planifprod.BagaMateriale(vcodplanifnodorig, v_rec.codobiect, v_rec.necesar, v_xxx.codprodcomp, 1, 
                        v_rec.codplanifprod1, vCodPlanifProd, &apos;.00&apos;);
        end loop;              
      end if;
    end if;                
  end loop;
  commit;
  
  select count(*) into Rez
  from planifnod 
  where codplanifprod = vcodplanifprod and tip = 3 and versiune = 1 and nvl(codreteta,0) = 0; 
  
  if Rez = 0 then 
    update planifprod set operat = 1 where codplanifprod = vcodplanifprod;
    commit;
  end if;  
  return Rez;
end;  

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodPlanifProd INTO Tmp FROM PLANIFPROD WHERE CodPlanifProd = RecId FOR UPDATE NOWAIT;
END;
  
PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
BEGIN
  SELECT
    trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7,
    SAPTAMANA,
    carnetdoc,
    nrdoc
  INTO
    aDATADOC,
    ADOC,
    acarnetdoc,
    anrdoc
  FROM PLANIFPROD WHERE CODPLANIFPROD = RECID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PLANIFPROD&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
   
  SP_LOCKRECORD(RecId);
  DELETE FROM PLANIFNOD   WHERE CodPLANIFPROD = RecId ;
  DELETE FROM PLANIFPROD1 WHERE CodPLANIFPROD = RecId ;
  DELETE FROM PLANIFPROD  WHERE CodPLANIFPROD = RecId ;
  
  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;
  
  NotifyModif(2, RecId, &apos;PLANIFPROD&apos;);
  
  COMMIT;
END;
  
PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PLANIFPROD FIELDS( CodPLANIFPROD, SAPTAMANA, INSAPTAMANA ) VALUES (0, to_number(TO_CHAR(sysdate,&apos;IW&apos;)), 1);
  COMMIT;
END;
  
PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCount number(10);
BEGIN
  -- Master PLANIFPROD
  
  select count(*) into aCount from user_triggers where status = &apos;DISABLED&apos;;
  if aCount &gt; 0 then
    execute immediate &apos;alter table planifnod enable all triggers&apos;;
    execute immediate &apos;alter table planifprod enable all triggers&apos;;
    execute immediate &apos;alter table lansz1 enable all triggers&apos;; 
  end if;
  
  INSERT INTO TMP_PLANIFPROD (CODPLANIFPROD,CODLANSPROD,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,OBS,ANULAT,BLOCAT,OPERAT,SAPTAMANA,DATASTART,DATASTOP,DEN_SUBUNIT, nrdoc, Datadoc,
                              carnetdoc,seriadoc,INSAPTAMANA)
  SELECT P.CODPLANIFPROD,P.CODLANSPROD,P.AN,P.LUNA,P.SUBUNITATEA,P.USERID,P.DATACREARE,P.OBS,P.ANULAT,P.BLOCAT,P.OPERAT,P.SAPTAMANA,
         iso_week_to_date(p.an, p.saptamana),
         iso_week_to_date(p.an, p.saptamana) + 6,
         S.DEN_SUBUNIT, p.nrdoc, p.datadoc,p.carnetdoc,p.seriadoc,nvl(P.INSAPTAMANA,1)
  FROM PLANIFPROD P
       INNER JOIN NSUBUNIT S ON P.SUBUNITATEA = S.CODSUBUNIT
  WHERE P.CodPLANIFPROD = RecId;
  
  INSERT INTO  TMP_PLANIFPROD1 ( CODPLANIFPROD1, CODPLANIFPROD,CODLANSPROD1,CODOBIECT,CODRETETA,OBS,NECESAR,CANT,DENUMIRE,CODEXTERN,DENUM,
                                 CUPROIECT, CODPROIECT, PROIECT, DEN_CLASEAS, DEN_IOART, CODINTERN)
    ( SELECT P1.CODPLANIFPROD1,P1.CODPLANIFPROD,P1.CODLANSPROD1,P1.CODOBIECT,P1.CODRETETA,P1.OBS,P1.NECESAR,NVL(P1.CANT,L1.NECESAR),OBJ.DENUMIRE,OBJ.CODEXTERN,NUM.DEN_UM,
             NVL(P1.CUPROIECT,0), NVL(P1.CODPROIECT,0), P.VERSIUNE, CLS_AS.DEN_CLASEAS, IOA.DEN_IOART, OBJ.CODINTERN
      FROM PLANIFPROD1 P1
           INNER JOIN NARTOBJ OBJ ON P1.CODOBIECT = OBJ.CODOBIECT
           INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
           INNER JOIN NUM ON ART.UM = NUM.CODUM
           LEFT  JOIN NCLASEAS CLS_AS ON CLS_AS.CODCLASEAS = ART.CLASASTATIST
           LEFT  JOIN LANSPROD1 L1 ON L1.CODLANSPROD1 = P1.CODLANSPROD1
           LEFT  JOIN PROIECT P ON P.CODPROIECT = P1.CODPROIECT AND P1.CUPROIECT = 1
           LEFT  JOIN NARTIMPLICITE IMP ON ART.CODARTICOL = IMP.CODARTICOL AND IMP.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
           LEFT  JOIN IOART IOA ON IOA.CODIOART = NVL(IMP.CONTIMPLICIT,0)
      WHERE CodPLANIFPROD = RecId );
      
  INSERT INTO TMP_PLANIFNOD(
    CODPLANIFNOD,
    CODPLANIFPROD,
    CODPLANIFPROD1,    
    CANT,
    NECESAR,         
    NODORIGINAL,
    POZITIE, 
    CODRETETA, 
    TIP,
    CODOBIECT,
    DenUM, 
    INDEXPARINTE,
    CodProdMat, 
    DENUMIRE,
    OBS,
    IDENTIFICATOR   ,
    DATADOCUMENTATIE,
    ARHIVA          ,
    PROIECTANT,
    ordine,
    nivel,
    codproiectnod,
    versiune,
    reteta,
    CantProdReteta,
    CantMatReteta,
    retetaparinte)
  SELECT PN.CODPLANIFNOD,
         PN.CODPLANIFPROD,
         PN.CODPLANIFPROD1,    
         PN.CANT,
         PN.NECESAR,         
         PN.NODORIGINAL,
         PN.POZITIE, 
         PN.CODRETETA, 
         PN.TIP,
         PN.CODOBIECT,
         U.DEN_UM,
         PN.INDEXPARINTE,
         NVL(MAT.CODMAT,0) CODPRODMAT,
         OBJ.DENUMIRE,
         PC.OBS,
         PC.IDENTIFICATOR,
         PC.DATADOCUMENTATIE,
         PC.ARHIVA,
         PC.PROIECTANT,
         nvl(pn.ordine,0),
         PN.NIVEL,
         PN.COdProiectNod,
         pn.versiune,
         case when nvl(p1.cuproiect,0) = 1 and nvl(pnp.nodoriginal,0) = 0 then p.versiune else pc.obs end,
         PN.CANTPRODRETETA,
         PN.CANTMATRETETA,
         case when p1.cuproiect = 1 then &apos;&apos; else &apos; - &apos;||PCP.Obs||&apos;(&apos;||PCP.Codprodcomp||&apos;)&apos; end
  FROM PLANIFNOD PN 
       INNER JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
       INNER JOIN NART    A   ON A.CODARTICOL = OBJ.CODARTICOL
       INNER JOIN NUM     U   ON U.CodUM      = A.UM
       INNER JOIN PLANIFPROD1 P1 ON P1.CODPLANIFPROD1 = PN.CODPLANIFPROD1
       LEFT  JOIN PLANIFNOD PNP ON PNP.CODPLANIFNOD = PN.NODORIGINAL
       LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
       LEFT  JOIN PRODCOMP PCP ON PNP.CodReteta = PCP.CodProdComp
       LEFT  JOIN PRODMAT MAT ON MAT.CODMAT = PN.CODPRODMAT
       LEFT  JOIN PROIECT P ON P.CODPROIECT = PN.CODRETETA
  WHERE PN.CODPLANIFPROD = RecId;  
  
  COMMIT;
END;
  
  
PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod number(20);  
vOldCod number(20);
Nr number(10);
aDataDoc DATE;
aDoc     VARCHAR2(200);
aCARNETDOC    NUMBER(20);
aNRDOC        NUMBER(20);
aSetimana number(2);
aCurentWeek number(1);
aOldWeek number(1);
aAn number(4);
aOldAn number(4);
aOldSetimana number(2);
aSubunit number(20);
BEGIN
  aOldWeek := 0;
  SELECT
    trunc(trunc(to_date(AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (Saptamana - 1) * 7,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
    carnetdoc, nrdoc, saptamana, InSaptamana, An, subunitatea
  INTO
    aDATADOC,
    ADOC, acarnetdoc,anrdoc, asetimana, aCurentWeek, aAn, asubunit
  FROM TMP_PLANIFPROD;

  FOR V_REC IN (SELECT * FROM tmp_planifnod where CodPlanifNod &lt; 0) LOOP
    SELECT seq_planifnod_codplanifnod.nextval INTO vCOD FROM DUAL;
    vOldCod := V_REC.codplanifnod;
    UPDATE tmp_planifnod SET nodoriginal = vCOD WHERE nodoriginal = vOldCod;
    UPDATE tmp_planifnod SET codplanifnod = vCOD WHERE codplanifnod = vOldCod;
  END LOOP;
   
  IF Operation = 0 THEN  -- UPDATE
  -- Master PLANIFPROD
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PLANIFPROD&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  
    SELECT CodPLANIFPROD INTO RecId FROM TMP_PLANIFPROD;
    select InSaptamana, An, Saptamana into aOldWeek, aOldAn, aOldSetimana from planifprod where codplanifprod = recid; 
    
    UPDATE PLANIFPROD 
    SET ( CODPLANIFPROD,CODLANSPROD,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,OBS,ANULAT,OPERAT,BLOCAT,SAPTAMANA,NRDOC, DATADOC,CARNETDOC,SERIADOC,INSAPTAMANA)
    = ( SELECT CODPLANIFPROD,CODLANSPROD,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,OBS,ANULAT,OPERAT,BLOCAT,SAPTAMANA,NRDOC,DATADOC,CARNETDOC,SERIADOC,INSAPTAMANA FROM TMP_PLANIFPROD )
    WHERE CodPLANIFPROD = RecId ;
  
    DELETE PLANIFNOD PN1 WHERE PN1.CODPLANIFPROD = RECID AND NOT EXISTS
    (SELECT T1.CODPLANIFPROD FROM TMP_PLANIFNOD T1 WHERE PN1.CODPLANIFNOD = T1.CODPLANIFNOD);
    DELETE PLANIFPROD1 P1 WHERE P1.CODPLANIFPROD = RECID AND NOT EXISTS (SELECT T1.CODPLANIFPROD1 FROM TMP_PLANIFPROD1 T1 WHERE T1.CODPLANIFPROD1 = P1.CODPLANIFPROD1);
    FOR V_REC IN (SELECT * FROM TMP_PLANIFPROD1) LOOP
      IF V_REC.CODPLANIFPROD1 &gt; 0 THEN 
        UPDATE PLANIFPROD1 SET
          CODLANSPROD1 = V_REC.CODLANSPROD1,
          CODOBIECT    = V_REC.CODOBIECT,
          CODRETETA    = V_REC.CODRETETA,
          OBS          = V_REC.OBS,
          NECESAR      = V_REC.NECESAR,
          CANT         = V_REC.CANT,
          CUPROIECT    = V_REC.CUPROIECT,
          CODPROIECT   = V_REC.CODPROIECT
        WHERE CODPLANIFPROD1 = V_REC.CODPLANIFPROD1;
      ELSE
        select seq_planifprod1_codplanifprod1.nextval into vCod from dual;
        update tmp_planifnod set codplanifprod1 = vCod where CodPlanifProd1 = v_rec.codplanifprod1; 
        INSERT INTO PLANIFPROD1 
  			(CODPLANIFPROD1, CODPLANIFPROD,CODLANSPROD1,CODOBIECT,CODRETETA,OBS,NECESAR,CANT,CUPROIECT, CODPROIECT)
			  VALUES (vCod,RecId, V_REC.CODLANSPROD1,V_REC.CODOBIECT,V_REC.CODRETETA,V_REC.OBS,V_REC.NECESAR,V_REC.CANT,V_REC.CUPROIECT,V_REC.CODPROIECT);
      END IF;
    end loop;
      
    for v_rec in (select * from tmp_planifnod) loop
      SELECT NVL(COUNT(*), 0) INTO NR  FROM planifnod WHERE codplanifnod = V_REC.codplanifnod;
      IF NR = 0
      THEN 
        INSERT INTO PLANIFNOD(CODPLANIFNOD, CODPLANIFPROD1, CODPLANIFPROD, CANT, NECESAR, NODORIGINAL, POZITIE, CODRETETA, TIP, CODOBIECT, 
                              INDEXPARINTE, CODPRODMAT, NIVEL, ORDINE, CODPROIECTNOD,VERSIUNE,CANTPRODRETETA, CANTMATRETETA)
        VALUES (V_REC.CODPLANIFNOD, V_REC.CODPLANIFPROD1, RECID, V_REC.CANT, V_REC.NECESAR, V_REC.NODORIGINAL, V_REC.POZITIE, V_REC.CODRETETA, V_REC.TIP, V_REC.CODOBIECT, 
                V_REC.INDEXPARINTE, V_REC.CODPRODMAT, V_REC.NIVEL, V_REC.ORDINE, V_REC.CODPROIECTNOD,V_REC.VERSIUNE,V_REC.CANTPRODRETETA,V_REC.CANTMATRETETA);
      ELSE
        UPDATE PLANIFNOD SET
          CANT         = V_REC.CANT,
          NECESAR      = V_REC.NECESAR,          
          NODORIGINAL  = V_REC.NODORIGINAL,
          POZITIE      = V_REC.POZITIE,
          CODRETETA    = V_REC.CODRETETA,
          TIP          = V_REC.TIP,
          CODOBIECT    = V_REC.CODOBIECT,
          INDEXPARINTE = V_REC.INDEXPARINTE,
          CODPRODMAT   = V_REC.CODPRODMAT,
          NIVEL        = V_REC.NIVEL,
          ORDINE       = V_REC.ORDINE,
          CODPROIECTNOD = V_REC.CODPROIECTNOD,
          VERSIUNE     = V_REC.VERSIUNE,
          CANTPRODRETETA = V_REC.CANTPRODRETETA,
          CANTMATRETETA  = V_REC.CANTMATRETETA
        WHERE CODPLANIFNOD = V_REC.CODPLANIFNOD;
      END IF;
    end loop;
  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PLANIFPROD&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;  
  
  -- Master PLANIFPROD
    SELECT SEQ_PLANIFPROD_CodPLANIFPROD.NextVal INTO RecId FROM DUAL;
    
    INSERT INTO PLANIFPROD 
    (CODPLANIFPROD,CODLANSPROD,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,OBS,ANULAT,OPERAT,BLOCAT,SAPTAMANA,NRDOC,DATADOC,CARNETDOC,SERIADOC,INSAPTAMANA )
    (SELECT RecId,CODLANSPROD,AN,LUNA,SUBUNITATEA,PKG_GLOBALS.USERID,SYSTIMESTAMP,OBS,ANULAT,OPERAT,BLOCAT,SAPTAMANA,NRDOC,DATADOC,CARNETDOC,SERIADOC,INSAPTAMANA
     FROM TMP_PLANIFPROD);

    for v_rec in (select * from tmp_planifprod1) loop
      select seq_planifprod1_codplanifprod1.nextval into vCod from dual;
      update tmp_planifnod set codplanifprod1 = vCod where CodPlanifProd1 = v_rec.codplanifprod1; 
      INSERT INTO PLANIFPROD1 
        ( CODPLANIFPROD1, CODPLANIFPROD,CODLANSPROD1,CODOBIECT,CODRETETA,OBS,NECESAR,CANT,CUPROIECT,CODPROIECT)
         VALUES (vCod,RecId, V_REC.CODLANSPROD1,V_REC.CODOBIECT,V_REC.CODRETETA,V_REC.OBS,V_REC.NECESAR,V_REC.CANT,V_REC.CUPROIECT,V_REC.CODPROIECT);
    end loop;
    INSERT INTO PLANIFNOD(CODPLANIFNOD, CODPLANIFPROD1, CODPLANIFPROD, CANT, NECESAR, NODORIGINAL, POZITIE, CODRETETA, TIP, CODOBIECT, 
                          INDEXPARINTE, CODPRODMAT, NIVEL, ORDINE, CODPROIECTNOD,VERSIUNE,CANTPRODRETETA, CANTMATRETETA)
    SELECT CODPLANIFNOD, CODPLANIFPROD1, RECID, CANT, NECESAR, NODORIGINAL, POZITIE, CODRETETA, TIP, CODOBIECT, 
           INDEXPARINTE, CODPRODMAT, NIVEL, ORDINE, CODPROIECTNOD,VERSIUNE,CANTPRODRETETA, CANTMATRETETA FROM TMP_PLANIFNOD;
  END IF;
  
  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
  
  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;
  
  /*if aCurentWeek &lt;&gt; 1 then
    if aSetimana = 1 then
      aSetimana := 53;
      aAn := aAn - 1;  
    else
      aSetimana := aSetimana - 1;
    end if;  
  end if;
  update lansz set dirty = 1 where saptamana = asetimana and an = aAn and subunitatea = asubunit and nvl(finalizat,0)=0;
  if aOldWeek &lt;&gt; aCurentWeek then
    if aOldWeek &lt;&gt; 1 then
      if aOldSetimana = 1 then
        aOldSetimana := 53;
        aOldAn := aOldAn - 1;  
      else
        aOldSetimana := aOldSetimana - 1;
      end if;
    end if;  
    update lansz set dirty = 1 where saptamana = aOldSetimana and an = aOldAn and subunitatea = asubunit and nvl(finalizat,0)=0;  
  end if;*/
  
  NotifyModif(Operation, RecId, &apos;PLANIFPROD&apos;);
  
  COMMIT;
END;

END PKG_PLANIFPROD; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLANIFPRODLUN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A17E1D72B37B1021B8A127195504FD80E992B4BF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLANIFPRODLUN is

vSaptamana number(2);
vCodGest number(20);
vCodCatPret number(20);
vAnLunaIni number(20);
vAnLunaFin number(20);
vCodMoneda number(20);
vAllCls number(1);
vAllGest number(1);
vAllIOArt number(1);

function GetFirstDateOfWeek(aSaptamana in number, aAn in number) return varchar2 is
begin
  return to_char(iso_week_to_date(aAn, aSaptamana), &apos;dd.mm.yyyy&apos;);
end;  

procedure SetParams(aSaptamana in number, aCodGest in number, aCodCatPret in number, aAllCls in number, aAllGest in number, aAllIOArt in number, aCodMoneda in number) is
begin
  vSaptamana  := aSaptamana;
  vCodGest    := aCodGest;
  vCodCatPret := aCodCatPret;
  vAllCls     := aAllCls;
  vAllGest    := aAllGest;
  vAllIOArt   := aAllIOArt;
  vCodMoneda  := aCodMoneda;
end;  

procedure SetParamsVanz(aAnLunaIni in number, aAnLunaFin in number) is
begin
  vAnLunaIni := aAnLunaIni;
  vAnLunaFin := aAnLunaFin;
end;

procedure UpdateVanz(aRefresh in number default 0) is
vUserID number(20);  
begin
  vUserID := PKG_GLOBALS.GETUSERID;
  
  if aRefresh &gt;0 then
    update tmp_pluna set mediev = 0;
  end if;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
         SELECT TL.CODOBIECT CODOBIECT, SUM(L1.CANT) REST
         FROM TMP_PLUNA TL
              INNER JOIN IESIRI1 I1 ON I1.CODOBIECT = TL.CODOBIECT
              INNER JOIN LIVR1 L1 ON L1.CODIES1 = I1.CODIES1
              INNER JOIN LIVR L ON L1.CODLIVR = L.CODLIVR
              INNER JOIN IESIRI I ON I1.CODIES = I.CODIES AND L.CODIES = I.CODIES
         WHERE I.ANULAT = 0 AND I.AN * 12 + I.LUNA BETWEEN vAnLunaIni AND vAnLunaFin
               AND I.TIPDOC IN (19,20) AND TL.USERID = VUSERID
         GROUP BY TL.CODOBIECT
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
  WHEN MATCHED THEN UPDATE SET TMP.MEDIEV = V.REST;
  
  update TMP_PLUNA 
  set
    MEDIEV = MEDIEV/trunc(vAnLunaFin - vAnLunaIni + 1);
  
  COMMIT;
end;

procedure UmpleTabele is
vUserID number(20);
vCurs number(20,7);
vSubunitatea number(20);
begin
  vSubunitatea := PKG_GLOBALS.GETSUBUNITATE;
  vUserID := PKG_GLOBALS.GETUSERID;
  vCurs   := PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(vCodMoneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate);
  
  delete TMP_PLUNA where userid = VUSERID;

  if vAllCls &lt;&gt; 1 then
    if vCodCatPret &gt; 0 then
      if vCodMoneda &gt; 0 then 
        MERGE INTO TMP_PLUNA TMP
        USING (
          select distinct codobiect, codmoneda, pret
          from 
          (
          SELECT 
            OBJ.CODOBIECT CODOBIECT,
            PM.MONEDA CODMONEDA, 
            case 
              when PM.MONEDA = vCodMoneda then NVL(PM.Valuta,0) 
              else 
                case when PM.LEI IS NULL THEN
                  case 
                    when vCurs = 0 then 0
                    else PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(PM.moneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate) * 
                         NVL(PM.VALUTA,0) / 
                         vCurs
                  end
                  else 
                    case
                      when vCurs = 0 then 0
                      else PM.VALUTA / vCurs
                    end    
                end
            end PRET
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NCLASEA CLS ON CLS.CODCLASEA = ART.CLASA
               INNER JOIN NCLASEA CLSA ON INSTRB(CLSA.CODIDENT, CLS.CODIDENT) = 1
               INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODCLASEA&apos; AND CLSA.CODCLASEA = TMP.VALOARE
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2
          UNION ALL
          SELECT 
            OBJ.CODOBIECT CODOBIECT,
            PM.MONEDA CODMONEDA, 
            case 
              when PM.MONEDA = vCodMoneda then NVL(PM.Valuta,0) 
              else 
                case when PM.LEI IS NULL THEN
                  case 
                    when vCurs = 0 then 0
                    else PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(PM.moneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate) * 
                         NVL(PM.VALUTA,0) / 
                         vCurs
                  end
                  else 
                    case
                      when vCurs = 0 then 0
                      else PM.VALUTA / vCurs
                    end    
                end
            end PRET
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 AND NVL(ART.CLASA,0) = 0 AND
                EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCLASEA&apos; AND 0 = TMP.VALOARE)
        )      
        ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      else
        MERGE INTO TMP_PLUNA TMP
        USING (
          SELECT distinct OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NCLASEA CLS ON CLS.CODCLASEA = ART.CLASA
               INNER JOIN NCLASEA CLSA ON INSTRB(CLSA.CODIDENT, CLS.CODIDENT) = 1
               INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODCLASEA&apos; AND CLSA.CODCLASEA = TMP.VALOARE
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2
          UNION ALL
          SELECT OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 AND NVL(ART.CLASA,0) = 0 AND
                EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCLASEA&apos; AND 0 = TMP.VALOARE)
              ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      end if;                        
    else
      if vCodMoneda &gt; 0 then
        MERGE INTO TMP_PLUNA TMP
        USING (
          select distinct codobiect, codmoneda, pret
          from 
          (
          SELECT 
            OBJ.CODOBIECT CODOBIECT,
            PM.MONEDA CODMONEDA, 
            case 
              when PM.MONEDA = vCodMoneda then NVL(PM.Valuta,0) 
              else 
                case when PM.LEI IS NULL THEN
                  case 
                    when vCurs = 0 then 0
                    else PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(PM.moneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate) * 
                         NVL(PM.VALUTA,0) / 
                         vCurs
                  end
                  else 
                    case
                      when vCurs = 0 then 0
                      else PM.VALUTA / vCurs
                    end    
                end
            end PRET
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NCLASEA CLS ON CLS.CODCLASEA = ART.CLASA
               INNER JOIN NCLASEA CLSA ON INSTRB(CLSA.CODIDENT, CLS.CODIDENT) = 1
               INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODCLASEA&apos; AND CLSA.CODCLASEA = TMP.VALOARE
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.IMPLICIT = 1 and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2
          UNION ALL
          SELECT OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 AND NVL(ART.CLASA,0) = 0 AND
                EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCLASEA&apos; AND 0 = TMP.VALOARE)
              )) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      else
        MERGE INTO TMP_PLUNA TMP
        USING (
          select distinct codobiect, pret, codmoneda
          from (
          SELECT OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NCLASEA CLS ON CLS.CODCLASEA = ART.CLASA
               INNER JOIN NCLASEA CLSA ON INSTRB(CLSA.CODIDENT, CLS.CODIDENT) = 1
               INNER JOIN TMP_MANEVRA_LISTE TMP ON TMP.FILTRU = &apos;CODCLASEA&apos; AND CLSA.CODCLASEA = TMP.VALOARE
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.IMPLICIT = 1 and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2
          UNION ALL
          SELECT OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 AND NVL(ART.CLASA,0) = 0 AND
                EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODCLASEA&apos; AND 0 = TMP.VALOARE)
              )) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      end if;                        
    end if;                        
  else
    if vCodCatPret &gt; 0 then
      if vCodMoneda &gt; 0 then
        MERGE INTO TMP_PLUNA TMP
        USING (
          SELECT distinct 
            OBJ.CODOBIECT CODOBIECT,
            PM.MONEDA CODMONEDA, 
            case 
              when PM.MONEDA = vCodMoneda then NVL(PM.Valuta,0) 
              else 
                case when PM.LEI IS NULL THEN
                  case 
                    when vCurs = 0 then 0
                    else PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(PM.moneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate) * 
                         NVL(PM.VALUTA,0) / 
                         vCurs
                  end
                  else 
                    case
                      when vCurs = 0 then 0
                      else PM.VALUTA / vCurs
                    end    
                end
            end PRET
          FROM NARTOBJ OBJ
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 
              ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);                      
      else
        MERGE INTO TMP_PLUNA TMP
        USING (
          SELECT distinct OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.CODCATPRET = vCodCatPret and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 
              ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      end if;                        
    else
      if vCodMoneda &gt; 0 then 
        MERGE INTO TMP_PLUNA TMP
        USING (
          SELECT distinct
            OBJ.CODOBIECT CODOBIECT,
            PM.MONEDA CODMONEDA, 
            case 
              when PM.MONEDA = vCodMoneda then NVL(PM.Valuta,0) 
              else 
                case when PM.LEI IS NULL THEN
                  case 
                    when vCurs = 0 then 0
                    else PKG_LIST_BASE_UTILS.GETCURSREFERINTA(nvl(PM.moneda,0), pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU), sysdate) * 
                         NVL(PM.VALUTA,0) / 
                         vCurs
                  end
                  else 
                    case
                      when vCurs = 0 then 0
                      else PM.VALUTA / vCurs
                    end    
                end
            end PRET
          FROM NARTOBJ OBJ
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.IMPLICIT = 1 and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 
              ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);                      
      else
        MERGE INTO TMP_PLUNA TMP
        USING (
          SELECT distinct OBJ.CODOBIECT CODOBIECT, NVL(PM.Lei,0) PRET, PM.MONEDA CODMONEDA
          FROM NARTOBJ OBJ
               LEFT  JOIN PRETM PM ON PM.CODOBIECT = OBJ.CODOBIECT AND PM.IMPLICIT = 1 and PM.SUBUNITATEA = vSubunitatea
          WHERE OBJ.PRODUSPROPRIU = 2 
              ) V
        ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
        WHEN NOT MATCHED THEN INSERT (TMP.CODOBIECT,TMP.PRET,TMP.USERID,TMP.CODCMDPL,TMP.CODMONEDA)        
                              VALUES (V.CODOBIECT,V.PRET,VUSERID,SEQ_TMP_PLUNA_CODPLUNA.NEXTVAL,V.CODMONEDA);
      end if;                        
    end if;                        
  end if;
  
  --elimin duplicatele
  for v_rec in (select count(*) cate, codobiect, codmoneda, pret, min(codcmdpl) codcmdpl
                from tmp_pluna
                where userid = vuserid
                group by codobiect, codmoneda, pret
                having count(*) &gt; 1
                ) loop
    delete tmp_pluna where codobiect = v_rec.codobiect and codmoneda = v_rec.codmoneda and pret = v_rec.pret
                           and userid = vuserid and codcmdpl &lt;&gt; v_rec.codcmdpl;
  end loop;              
  commit;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
         SELECT distinct P.CODOBIECT CODOBIECT, SUM(NS.REST) REST
         FROM TMP_PLUNA P
              INNER JOIN NIRSTOC NS ON NS.CODOBIECT = P.CODOBIECT
              INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
              INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
              INNER JOIN TMP_IOART_LUNA IOLUNA ON IOLUNA.CODIOART = NS.CODIOART
         WHERE NS.REST &gt; 0 AND IOLUNA.MG &lt;&gt; 5
               AND (VALLGEST = 1 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODGEST&apos; AND TMP.VALOARE = NIR.GEST))
               AND (VALLIOART = 1 OR EXISTS (SELECT TMP.VALOARE FROM TMP_MANEVRA_LISTE TMP WHERE TMP.FILTRU = &apos;CODIOART&apos; AND TMP.VALOARE = IOLUNA.CODIOART))
               AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE AND P.USERID = VUSERID
         GROUP BY P.CODOBIECT
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
  WHEN MATCHED THEN UPDATE SET TMP.STOC = V.REST;
  
  UMPLE_TMP_CMD;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
    SELECT P.CODOBIECT CODOBIECT, SUM(NVL(P.CANT3,0)) CANTCC
    FROM TMP_CMD_PLUNA P
    WHERE P.TIP = 18 AND NVL(P.CANT3,0) &gt; 0 AND P.USERID = VUSERID
    GROUP BY P.CODOBIECT
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
  WHEN MATCHED THEN UPDATE SET TMP.CANTCC = V.CANTCC;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
    SELECT P.CODOBIECT CODOBIECT, SUM(P.CANT3) CANTCI
    FROM TMP_CMD_PLUNA P
    WHERE P.TIP = 53 AND P.CANT3 &gt; 0 AND P.USERID = VUSERID
    GROUP BY P.CODOBIECT
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
  WHEN MATCHED THEN UPDATE SET TMP.CANTCI = V.CANTCI;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
    SELECT P.CODOBIECT CODOBIECT, SUM(P.CANT3) RESTCMDINT
    FROM TMP_CMD_PLUNA P
    WHERE P.TIP = 53 AND P.CANT3 &gt; 0 AND P.USERID = VUSERID AND P.CODCOMANDA1 &gt; 0
    GROUP BY P.CODOBIECT
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = VUSERID)
  WHEN MATCHED THEN UPDATE SET TMP.RESTCMDINT = V.RESTCMDINT;
  
  MERGE INTO TMP_PLUNA TMP
  USING (
    SELECT 
      P.CODOBIECT, 
      SUM(CASE WHEN P.WEEK = VSAPTAMANA THEN P.CANT3 ELSE 0 END) WEEK1,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 1 THEN P.CANT3 ELSE 0 END) WEEK2,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 2 THEN P.CANT3 ELSE 0 END) WEEK3,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 3 THEN P.CANT3 ELSE 0 END) WEEK4,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 4 THEN P.CANT3 ELSE 0 END) WEEK5,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA THEN P.CANT1 ELSE 0 END) PRWEEK1,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 1 THEN P.CANT1 ELSE 0 END) PRWEEK2,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 2 THEN P.CANT1 ELSE 0 END) PRWEEK3,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 3 THEN P.CANT1 ELSE 0 END) PRWEEK4,
      SUM(CASE WHEN P.WEEK = VSAPTAMANA + 4 THEN P.CANT1 ELSE 0 END) PRWEEK5,
      P.USERID
    FROM TMP_CMD_PLUNA P
    WHERE P.TIP = 53 AND P.CANT3 &gt; 0 AND P.USERID = VUSERID AND P.CODPROGRAMF1 &gt; 0
    GROUP BY P.CODOBIECT, P.USERID
        ) V
  ON (TMP.CODOBIECT = V.CODOBIECT and TMP.USERID = V.USERID)
  WHEN MATCHED THEN UPDATE SET 
    TMP.WEEK1 = V.WEEK1,
    TMP.WEEK2 = V.WEEK2,
    TMP.WEEK3 = V.WEEK3,
    TMP.WEEK4 = V.WEEK4,
    TMP.WEEK5 = V.WEEK5,
    TMP.PRWEEK1 = V.PRWEEK1,
    TMP.PRWEEK2 = V.PRWEEK2,
    TMP.PRWEEK3 = V.PRWEEK3,
    TMP.PRWEEK4 = V.PRWEEK4,
    TMP.PRWEEK5 = V.PRWEEK5
  WHERE TMP.USERID = VUSERID;
  
  COMMIT;
end;  

PROCEDURE UMPLE_TMP_CMD IS
VUSERID NUMBER(20);  
BEGIN
  VUSERID := PKG_GLOBALS.GETUSERID;
  
  DELETE TMP_CMD WHERE USERID = VUSERID;
  INSERT INTO TMP_CMD(CODOBIECT, CANTC, USERID)
  SELECT C1.CODCOMANDA1, SUM(L.CANT) CANT, VUSERID
  FROM TMP_PLUNA TL
       INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       INNER JOIN CMDLINK L ON L.CODLINIECOMANDA = C1.CODCOMANDA1
  WHERE C1.RESTACCEPTAT &gt; 0 AND C.TIPDOC = 18 AND C.ANULAT = 0 AND TL.USERID = VUSERID
  GROUP BY C1.CODCOMANDA1;
  
  DELETE TMP_CMD_PLUNA WHERE USERID = VUSERID;
  INSERT INTO TMP_CMD_PLUNA(CODCOMANDA1, CANT1, CANT2, CANT3, CANT4, TIP, USERID, CODOBIECT)
  SELECT C1.CODCOMANDA1, C1.CANTACCEPTAT, NVL(LANSATE.CANTC,0), C1.RESTACCEPTAT, C1.CANTACCEPTAT - NVL(LANSATE.CANTC,0), 18, VUSERID, C1.CODOBIECT
  FROM TMP_PLUNA TL
       INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       LEFT JOIN TMP_CMD LANSATE ON LANSATE.CODOBIECT = C1.CODCOMANDA1 AND LANSATE.USERID = VUSERID
  WHERE C1.RESTACCEPTAT &gt; 0 AND C.TIPDOC = 18 AND C.ANULAT = 0 AND TL.USERID = VUSERID;
  
  if vCodGest &gt; 0 then
    DELETE TMP_CMD WHERE USERID = VUSERID; 
    INSERT INTO TMP_CMD(CODOBIECT, CANTC, USERID, TIP)
    SELECT C1.CODCOMANDA1, SUM(L.CANT) CANT, VUSERID, TO_CHAR(PF1.CODPROGRAMF1) 
    FROM TMP_PLUNA TL
         INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN CMDPRODMAT PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN INTRPRODLINK L ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
         INNER JOIN PROGRAMF1 PF1 ON PF1.CODPROGRAMF1 = L.CODPROGRAMF1
         INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1
         INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    WHERE C.TIPDOC = 53 AND C.ANULAT = 0 AND I.ANULAT = 0 AND C.CODGEST = VCODGEST AND TL.USERID = VUSERID
    GROUP BY C1.CODCOMANDA1, PF1.CODPROGRAMF1;  
  
    INSERT INTO TMP_CMD_PLUNA(CANT1, CANT2, CANT3, TERMEN, TIP, CODPROGRAMF1, USERID, WEEK, CODOBIECT)
    SELECT PF1.CANTPROGRAMAT, NVL(PREDATE.CANTC,0), PF1.CANTPROGRAMAT - NVL(PREDATE.CANTC,0), PF1.TERMEN, 53, PF1.CODPROGRAMF1, VUSERID, TO_NUMBER(TO_CHAR(PF1.TERMEN,&apos;IW&apos;)),
           C1.CODOBIECT
    FROM TMP_PLUNA TL
         INNER JOIN CMDPRODMAT PROD ON TL.CODOBIECT = PROD.CODOBIECT AND PROD.TIP = 0
         INNER JOIN COMANDA1 C1 ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
         LEFT  JOIN TMP_CMD PREDATE ON PREDATE.CODOBIECT = C1.CODCOMANDA1 AND TO_NUMBER(PREDATE.TIP) = PF1.CODPROGRAMF1 AND PREDATE.USERID = VUSERID
    WHERE PROD.REST &gt; 0 AND C.CODGEST = VCODGEST AND C.TIPDOC = 53 AND C.ANULAT = 0 AND TL.USERID = VUSERID;
    
    DELETE TMP_CMD WHERE USERID = VUSERID;
    INSERT INTO TMP_CMD(CODOBIECT, CANTC, USERID)
    SELECT C1.CODCOMANDA1, SUM(L.CANT) CANT, VUSERID
    FROM TMP_PLUNA TL
         INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN CMDPRODMAT PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN INTRPRODLINK L ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
         INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1
         INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    WHERE C.TIPDOC = 53 AND C.ANULAT = 0 AND I.ANULAT = 0 AND C.CODGEST = VCODGEST AND TL.USERID = VUSERID AND NVL(L.CODPROGRAMF1,0) = 0
    GROUP BY C1.CODCOMANDA1;
    
    INSERT INTO TMP_CMD_PLUNA
    (
      CODCOMANDA1, 
      CANT1, 
      CANT2, 
      CANT3, 
      TERMEN, 
      TIP, 
      USERID, 
      WEEK,
      CODOBIECT
    )
    SELECT 
      C1.CODCOMANDA1, 
      C1.CANTACCEPTAT - (SELECT NVL(SUM(PF1.CANTPROGRAMAT),0) FROM PROGRAMF1 PF1 WHERE PF1.CODCOMANDA1 = C1.CODCOMANDA1), 
      NVL(PREDATE.CANTC,0), 
      C1.CANTACCEPTAT - (SELECT NVL(SUM(PF1.CANTPROGRAMAT),0) FROM PROGRAMF1 PF1 WHERE PF1.CODCOMANDA1 = C1.CODCOMANDA1) - NVL(PREDATE.CANTC,0), 
      C1.TERMEN, 
      53, 
      VUSERID, 
      TO_NUMBER(TO_CHAR(C1.TERMEN,&apos;IW&apos;)),
      C1.CODOBIECT
    FROM TMP_PLUNA TL
         INNER JOIN CMDPRODMAT PROD ON TL.CODOBIECT = PROD.CODOBIECT AND PROD.TIP = 0
         INNER JOIN COMANDA1 C1 ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         LEFT  JOIN TMP_CMD PREDATE ON PREDATE.CODOBIECT = C1.CODCOMANDA1 AND PREDATE.USERID = VUSERID
    WHERE PROD.REST &gt; 0 AND C.CODGEST = VCODGEST AND C.TIPDOC = 53 AND C.ANULAT = 0 AND TL.USERID = VUSERID;
    DELETE TMP_CMD_PLUNA WHERE USERID = VUSERID AND TIP = 53 AND CODPROGRAMF1 IS NULL AND CANT1 = 0;
  else
    DELETE TMP_CMD WHERE USERID = VUSERID; 
    INSERT INTO TMP_CMD(CODOBIECT, CANTC, USERID, TIP)
    SELECT C1.CODCOMANDA1, SUM(L.CANT) CANT, VUSERID, TO_CHAR(PF1.CODPROGRAMF1) 
    FROM TMP_PLUNA TL
         INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN CMDPRODMAT PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN INTRPRODLINK L ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
         INNER JOIN PROGRAMF1 PF1 ON PF1.CODPROGRAMF1 = L.CODPROGRAMF1
         INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1
         INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    WHERE C.TIPDOC = 53 AND C.ANULAT = 0 AND I.ANULAT = 0 AND TL.USERID = VUSERID
    GROUP BY C1.CODCOMANDA1, PF1.CODPROGRAMF1;  
  
    INSERT INTO TMP_CMD_PLUNA(CANT1, CANT2, CANT3, TERMEN, TIP, CODPROGRAMF1, USERID, WEEK, CODOBIECT)
    SELECT PF1.CANTPROGRAMAT, NVL(PREDATE.CANTC,0), PF1.CANTPROGRAMAT - NVL(PREDATE.CANTC,0), PF1.TERMEN, 53, PF1.CODPROGRAMF1, VUSERID, TO_NUMBER(TO_CHAR(PF1.TERMEN,&apos;IW&apos;)),
           C1.CODOBIECT
    FROM TMP_PLUNA TL
         INNER JOIN CMDPRODMAT PROD ON TL.CODOBIECT = PROD.CODOBIECT AND PROD.TIP = 0
         INNER JOIN COMANDA1 C1 ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
         LEFT  JOIN TMP_CMD PREDATE ON PREDATE.CODOBIECT = C1.CODCOMANDA1 AND TO_NUMBER(PREDATE.TIP) = PF1.CODPROGRAMF1 AND PREDATE.USERID = VUSERID
    WHERE PROD.REST &gt; 0 AND C.TIPDOC = 53 AND C.ANULAT = 0 AND TL.USERID = VUSERID;
    
    DELETE TMP_CMD WHERE USERID = VUSERID;
    INSERT INTO TMP_CMD(CODOBIECT, CANTC, USERID)
    SELECT C1.CODCOMANDA1, SUM(L.CANT) CANT, VUSERID
    FROM TMP_PLUNA TL
         INNER JOIN COMANDA1 C1 ON C1.CODOBIECT = TL.CODOBIECT
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN CMDPRODMAT PROD ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN INTRPRODLINK L ON PROD.CODCMDPRODMAT = L.CODLINIECOMANDA
         INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1
         INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
    WHERE C.TIPDOC = 53 AND C.ANULAT = 0 AND I.ANULAT = 0 AND TL.USERID = VUSERID AND NVL(L.CODPROGRAMF1,0) = 0
    GROUP BY C1.CODCOMANDA1;
    
    INSERT INTO TMP_CMD_PLUNA
    (
      CODCOMANDA1, 
      CANT1, 
      CANT2, 
      CANT3, 
      TERMEN, 
      TIP, 
      USERID, 
      WEEK,
      CODOBIECT
    )
    SELECT 
      C1.CODCOMANDA1, 
      C1.CANTACCEPTAT - (SELECT NVL(SUM(PF1.CANTPROGRAMAT),0) FROM PROGRAMF1 PF1 WHERE PF1.CODCOMANDA1 = C1.CODCOMANDA1), 
      NVL(PREDATE.CANTC,0), 
      C1.CANTACCEPTAT - (SELECT NVL(SUM(PF1.CANTPROGRAMAT),0) FROM PROGRAMF1 PF1 WHERE PF1.CODCOMANDA1 = C1.CODCOMANDA1) - NVL(PREDATE.CANTC,0), 
      C1.TERMEN, 
      53, 
      VUSERID, 
      TO_NUMBER(TO_CHAR(C1.TERMEN,&apos;IW&apos;)),
      C1.CODOBIECT
    FROM TMP_PLUNA TL
         INNER JOIN CMDPRODMAT PROD ON TL.CODOBIECT = PROD.CODOBIECT AND PROD.TIP = 0
         INNER JOIN COMANDA1 C1 ON PROD.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         LEFT  JOIN TMP_CMD PREDATE ON PREDATE.CODOBIECT = C1.CODCOMANDA1 AND PREDATE.USERID = VUSERID
    WHERE PROD.REST &gt; 0 AND C.TIPDOC = 53 AND C.ANULAT = 0 AND TL.USERID = VUSERID;
    DELETE TMP_CMD_PLUNA WHERE USERID = VUSERID AND TIP = 53 AND CODPROGRAMF1 IS NULL AND CANT1 = 0;
  end if;
  
  DELETE TMP_CMD_PLUNA WHERE USERID = VUSERID AND CANT3 &lt;= 0;
  
  COMMIT;
END;  

PROCEDURE CLEARTABLES IS
VUSERID NUMBER(20);  
BEGIN
  VUSERID := PKG_GLOBALS.GETUSERID;
  DELETE TMP_CMD WHERE USERID = VUSERID;
  DELETE TMP_CMD_PLUNA WHERE USERID = VUSERID;
  DELETE TMP_PLUNA WHERE USERID = VUSERID;
  COMMIT;
END;  

PROCEDURE CLEARSALVARE(AANLUNA IN NUMBER, aCodGest in number) IS
BEGIN
  DELETE PLANIFPRODLUN WHERE ANLUNA = AANLUNA AND CODGEST = ACODGEST;
  COMMIT;
END;  

PROCEDURE INSERTSALVARE(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, PL1 IN NUMBER, PL2 IN NUMBER, PL3 IN NUMBER, PL4 IN NUMBER, PL5 IN NUMBER, 
                        PL IN NUMBER, LANSARE IN NUMBER, ACODGEST IN NUMBER) IS
BEGIN
  DELETE PLANIFPRODLUN WHERE ANLUNA = AANLUNA AND CODOBIECT = ACODOBIECT;
  INSERT INTO PLANIFPRODLUN (CODOBIECT, PLWEEK1, PLWEEK2, PLWEEK3, PLWEEK4, PLWEEK5, ANLUNA, PLANIFICAT, LANSARE, CODGEST)
  VALUES (ACODOBIECT, PL1, PL2, PL3, PL4, PL5, AANLUNA, PL, LANSARE, ACODGEST);
  COMMIT;
END;  

PROCEDURE UPDATE_LANSARE(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, ALANSARE IN NUMBER, ACODGEST IN NUMBER) IS
ACOUNT NUMBER(10);    
BEGIN
  select count(*) INTO ACOUNT from planifprodlun where anluna = aanluna and codobiect = acodobiect and codgest = acodgest;
  
  if acount &gt; 0 then
    UPDATE PLANIFPRODLUN SET
    LANSARE = ALANSARE
    WHERE anluna = aanluna and codobiect = acodobiect and codgest = acodgest;
  else
    INSERT INTO PLANIFPRODLUN (CODOBIECT, ANLUNA, LANSARE, CODGEST)
    VALUES (ACODOBIECT, AANLUNA, ALANSARE, ACODGEST);
  end if;
  COMMIT;
END;

PROCEDURE UPDATE_PLANIF(AANLUNA IN NUMBER, ACODOBIECT IN NUMBER, PL1 IN NUMBER, PL2 IN NUMBER, PL3 IN NUMBER, PL4 IN NUMBER, PL5 IN NUMBER,
                        PL IN NUMBER, ACODGEST IN NUMBER, CuUPD in boolean) IS
ACOUNT NUMBER(10);
BEGIN
  select count(*) INTO ACOUNT from planifprodlun where anluna = aanluna and codobiect = acodobiect and codgest = acodgest;
  
  if acount &gt; 0 then
    if CuUPD then 
      UPDATE PLANIFPRODLUN SET
      PLWEEK1 = PL1,
      PLWEEK2 = PL2,
      PLWEEK3 = PL3,
      PLWEEK4 = PL4,
      PLWEEK5 = PL5,
      PLANIFICAT = PL
      WHERE anluna = aanluna and codobiect = acodobiect and codgest = acodgest;
    end if;  
  else
    INSERT INTO PLANIFPRODLUN (CODOBIECT, ANLUNA, PLWEEK1, PLWEEK2, PLWEEK3, PLWEEK4, PLWEEK5, PLANIFICAT, CODGEST)
    VALUES (ACODOBIECT, AANLUNA, PL1, PL2, PL3, PL4, PL5, PL, ACODGEST);
  end if;
  COMMIT;
END;

PROCEDURE BLOCK_SECTIE(aUserID in number, aCodGest in number) is
begin
  delete planiflock where userid = aUserId;
  insert into planiflock(userid, codgest)
  values (aUserId, aCodGest);
  commit;
end;  

PROCEDURE UNBLOCK(aUserID in number) is
begin
  delete planiflock where userid = aUserId;
  commit;
end;

procedure UPDATENEXT
(
  aCodObiect in number, 
  aAnLuna in number,
  aCodGest in number, 
  aPlanificat in number, 
  aPLWeek1 in number, 
  aPLWeek2 in number, 
  aPLWeek3 in number, 
  aPLWeek4 in number,
  aPLWeek5 in number
) is
begin
  update planifprodlun set
    planificat = aPlanificat,
    plweek1 = aplweek1,
    plweek2 = aplweek2,
    plweek3 = aplweek3,
    plweek4 = aplweek4,
    plweek5 = aplweek5
  where codgest = acodgest and codobiect = acodobiect and anluna = aanluna;
  commit;
end;
  
end PKG_PLANIFPRODLUN; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>674E7EDD7A3CE93C5841EFA6AF789FC0D0A18422</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PLATI IS


PROCEDURE CHECKADDCONTDEST(aCODPART IN NUMBER, aCONTDEST VARCHAR2) IS
PRAGMA AUTONOMOUS_TRANSACTION;

  aCONT NUMBER;
  aCODBANK NUMBER;
  NR NUMBER;
BEGIN
  BEGIN
    SELECT
      CODPARTB INTO aCONT FROM NPARTB
    WHERE
      CONTBANCA = aCONTDEST
      AND CODPART = aCODPART;

    EXCEPTION WHEN OTHERS THEN  aCONT := 0;
  END;

  IF aCONT = 0 THEN
    BEGIN
      SELECT CODBANK INTO aCODBANK
      FROM
        NBANK
      WHERE
        UPPER(CODBNR) =  UPPER(SUBSTR(Replace(aCONTDEST, &apos; &apos;, &apos;&apos;), 5, 4));

      EXCEPTION WHEN OTHERS THEN aCODBANK := 0;

    END ;

    IF aCODBANK &lt;&gt; 0 THEN
      INSERT INTO NPARTB(CODPARTB, CODPART, CODBANK,CONTBANCA)
      VALUES(SEQ_NPARTB_CODPARTB.NEXTVAL, aCODPART, aCODBANK, aCONTDEST);

      SELECT COUNT(*) INTO NR FROM NPARTB WHERE CODPART = aCODPART;
      IF NR = 0 THEN
        UPDATE NPARTB SET IMPLICIT = 1 WHERE CODPART = aCODPART;
      END IF;


    END IF;

  END IF;

COMMIT;

END;


PROCEDURE SETNRDOC_I(ANRDOC IN NUMBER, ACARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODPLATA INTO Tmp FROM PLATI WHERE CODPLATA = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
ACARNETDOC NUMBER(20);
ANRDOC NUMBER(20);
BEGIN
  SELECT CARNETDOC,  NRDOC INTO
         ACARNETDOC, ANRDOC
  FROM PLATI WHERE CODPLATA = RECID;

  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 105);
 	DELETE FROM PLATI1 WHERE CODPLATA = RecId;
 	DELETE FROM PLATI2 WHERE CODPLATA = RecId;
 	DELETE FROM PLATI  WHERE CODPLATA = RecId;
  PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);

  NotifyModif(2, RecId, &apos;PLATI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_PLATI FIELDS(CODPLATA) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(105);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCODCONT NUMBER(20) := 0;
CodA  number(20);
aLuna number(2);
aLuna1 number(2);
aLuna2 number(2);
aAn number(4);
aTip  number(2);
aTipSold number(1);
CursOrd Number(20,7);
BEGIN
	PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);

  INSERT INTO TMP_PLATI (CODPLATA, DATA, TipDoc, CodAnaliza, userid, datacreare, CODBANKCONT, VALOARE, CARNETDOC, NRDOC, SIMBOLMONEDA, VALOAREDEREPARTIZAT, CODBANK, NRCONT, AN, LUNA, CODMONEDA, APROBAT,
                         OBS, CURS)
  (SELECT CODPLATA, DATA, TipDoc, CodAnaliza, userid, datacreare, BK.CODBANKCONT, VALOARE, CARNETDOC, NRDOC, M.SIMBOL, VALOAREDEREPARTIZAT, BK.CODBANK, BK.NRCONT, AN, LUNA, M.CODMONEDA, APROBAT,
          P.OBS, CURS
   FROM
     PLATI P
     LEFT OUTER JOIN NBANKCONT BK  ON BK.CODBANKCONT   = P.CODBANKCONT
     LEFT OUTER JOIN NMONEDE M ON BK.CODMONEDA = M.CODMONEDA
   WHERE
     P.CODPLATA = RECID
   );
   UPDATE TMP_PLATI P
   SET
    SOLDCONT = CASE
                 WHEN NVL(CODMONEDA, 0) = 0  THEN (SELECT SOLDLEI FROM V_SOLDURIBANCILUNA WHERE CODBANKCONT = P.CODBANKCONT)
                 ELSE (SELECT SOLDVALUTA FROM V_SOLDURIBANCILUNA WHERE CODBANKCONT = P.CODBANKCONT)
               END;

   Select CodAnaliza, Nvl(TipDoc,0) into CodA, aTip from TMP_Plati;
   if aTip = 0 then
     INSERT INTO TMP_PLATI1
     (CODPLATA1,
      CODOBLIGPIF,
      VALOARE,
      CODMONEDA,
      CONTDEST,
      ADRESAFURN,
      INDEXLOCAL,
      STINSA,
      CODSWIFT,
      CODBNR,
      CODSTATISTICBNR,
      TIPCOMISION,
      CODBANK,
      CODPART,
      SPLITTVA,
      REST,
      DENPART,
      DOC,
      NRDOC,
      VALDOC,
      TERMEN,
      SUBUNITATEA,
      CodAnalizaNod,
			codanalizanodx ,
			codpers        ,
			codcont,
      codfiscal,
      SIMBOLCLASA,
      Obs
     )
     (
     SELECT
       P1.CODPLATA1,
       P1.CODOBLIGPIF,
       P1.VALOARE,
       P1.CODMONEDA,
       P1.CONTDEST,
       P1.ADRESAFURN,
       P1.INDEXLOCAL,
       P1.STINSA,
       P1.CODSWIFT,
       P1.CODBNR,
       P1.CODSTATISTICBNR,
       P1.TIPCOMISION,
       P1.CODBANK,
       P.CODPART,
       NVL(P1.SPLITTVA, 0),
       P1.REST,
       P.DEN_PART,
       I.PREFIXDOC,
       I. NRDOC,
       CASE
         WHEN NVL(P1.SPLITTVA, 0) = 0 THEN O.VALOARE - NVL(O.DINCARETVA, 0)
         ELSE O.DINCARETVA
       END VALOARE,
       O.TERMEN,
       I.SUBUNITATEA,
       O.Codanalizanod,
			 P1.codanalizanodx ,
			 P1.codpers        ,
			 P1.codcont,
       CF.CODFISCAL,
       CLA.SIMBOL,
       I.Obs
     FROM
       PLATI1 P1,
       OBLIGPIF O,
       GENERAL G,
       INTRARI I,
       NPART P
       LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
       LEFT JOIN NCLASEP CLA ON CLA.CODCLASEP = P.CODCLASA
     WHERE
       CODPLATA          = RECID
       AND O.CODOBLIGPIF = P1.CODOBLIGPIF
       AND G.CODGENERAL  = O.CODGENERAL
       AND G.TIPDOC      = I.TIPDOC
       AND G.CODDOC      = I.CODINTR
       AND G.SEMNIFICATIE = 100
			 AND P.CODPART     = O.CODPART
		 UNION ALL
		 SELECT
			 P1.CODPLATA1,
			 P1.CODOBLIGPIF,
			 P1.VALOARE,
			 P1.CODMONEDA,
			 P1.CONTDEST,
			 P1.ADRESAFURN,
			 P1.INDEXLOCAL,
			 P1.STINSA,
			 P1.CODSWIFT,
			 P1.CODBNR,
			 P1.CODSTATISTICBNR,
			 P1.TIPCOMISION,
			 P1.CODBANK,
			 P.CODPART,
       NVL(P1.SPLITTVA, 0),
       P1.REST,
			 P.DEN_PART,
			 &apos;DVOT&apos;,
			 D.NRDOC,
			 O.VALOARE,
			 O.TERMEN,
			 I.SUBUNITATEA,
			 O.Codanalizanod,
			 P1.codanalizanodx ,
			 P1.codpers        ,
			 P1.codcont,
       CF.CODFISCAL,
       CLA.SIMBOL,
       D.Obs
		 FROM
			 PLATI1 P1,
			 OBLIGPIF O,
			 GENERAL G,
			 DVI D,
			 INTRARI I,
			 NPART P
       LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
       LEFT JOIN NCLASEP CLA ON CLA.CODCLASEP = P.CODCLASA
		 WHERE
			 CODPLATA          = RECID
			 AND O.CODOBLIGPIF = P1.CODOBLIGPIF
			 AND G.CODGENERAL  = O.CODGENERAL
       AND G.SEMNIFICATIE = 130
			 AND G.TIPDOC      = 5
			 AND G.CODDOC      = D.CODDVI
			 AND D.CODINTR     = I.CODINTR
			 AND P.CODPART     = O.CODPART
		 ) ;
	 else
  	 Select PKG_GLOBALS.LUNALUCRU into aLuna from dual;
  	 Select PKG_GLOBALS.AnLUCRU into aAn from dual;

     execute immediate &apos;BEGIN&apos;||Chr(10)||
     &apos;  DELETE TMP_BUGETANALIZA;&apos;||Chr(10)||
     &apos;  PKG_ANALIZA.GetBugete( &apos;||CodA||&apos;, &apos;||PKG_GLOBALS.ANLUCRU||&apos;, 1, 12, 9, 0 );&apos;||Chr(10)||
     &apos;  DELETE TMP_BUGETANALIZA WHERE CODANALIZANOD IN (SELECT DISTINCT NODPARINTE FROM ANALIZANOD WHERE CODANALIZA = &apos;||CodA||&apos;);&apos;||Chr(10)||
     &apos;  COMMIT;&apos;||Chr(10)||
     &apos;END;&apos;;

		 INSERT INTO TMP_PLATI1
		 (CODPLATA1,
			CODOBLIGPIF,
			VALOARE,
			CODMONEDA,
			CONTDEST,
			ADRESAFURN,
			INDEXLOCAL,
			STINSA,
			CODSWIFT,
			CODBNR,
			CODSTATISTICBNR,
			TIPCOMISION,
			CODBANK,
			CODPART,
			DENPART,
			DOC,
			NRDOC,
			VALDOC,
			TERMEN,
			SUBUNITATEA,
			CodAnalizaNod,
			SoldBuget,
			codanalizanodx ,
			codpers        ,
			codcont,
      codfiscal,
      SIMBOLCLASA,
      Obs
		 )
		 (
		 SELECT
			 P1.CODPLATA1,
			 P1.CODOBLIGPIF,
			 P1.VALOARE,
			 P1.CODMONEDA,
			 P1.CONTDEST,
			 P1.ADRESAFURN,
			 P1.INDEXLOCAL,
			 P1.STINSA,
			 P1.CODSWIFT,
			 P1.CODBNR,
			 P1.CODSTATISTICBNR,
			 P1.TIPCOMISION,
			 P1.CODBANK,
			 P.CODPART,
			 P.DEN_PART,
			 I.PREFIXDOC,
			 I. NRDOC,
			 O.VALOARE,
			 O.TERMEN,
			 I.SUBUNITATEA,
			 O.Codanalizanod,
			 0,
			 Nvl(P1.codanalizanodx,O.Codanalizanod) ,
			 P1.codpers,
			 P1.codcont,
       CF.CODFISCAL,
       CLA.SIMBOL,
       I.Obs
		 FROM
			 PLATI1 P1,
			 OBLIGPIF O,
			 GENERAL G,
			 INTRARI I,
			 NPART P
       LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
       LEFT JOIN NCLASEP CLA ON CLA.CODCLASEP = P.CODCLASA
		 WHERE
			 CODPLATA          = RECID
			 AND O.CODOBLIGPIF = P1.CODOBLIGPIF
			 AND G.CODGENERAL  = O.CODGENERAL
			 AND G.TIPDOC      = I.TIPDOC
			 AND G.CODDOC      = I.CODINTR
			 AND P.CODPART     = O.CODPART
		 UNION ALL
		 SELECT
			 P1.CODPLATA1,
			 P1.CODOBLIGPIF,
			 P1.VALOARE,
			 P1.CODMONEDA,
			 P1.CONTDEST,
			 P1.ADRESAFURN,
			 P1.INDEXLOCAL,
			 P1.STINSA,
			 P1.CODSWIFT,
			 P1.CODBNR,
			 P1.CODSTATISTICBNR,
			 P1.TIPCOMISION,
			 P1.CODBANK,
			 P.CODPART,
			 P.DEN_PART,
			 &apos;DVOT&apos;,
			 D.NRDOC,
			 O.VALOARE,
			 O.TERMEN,
			 I.SUBUNITATEA,
			 O.Codanalizanod,
			 0,
			 Nvl(P1.codanalizanodx,O.Codanalizanod) ,
			 P1.codpers        ,
			 P1.codcont,
       CF.CODFISCAL,
       CLA.SIMBOL,
       D.Obs
		 FROM
			 PLATI1 P1,
			 OBLIGPIF O,
			 GENERAL G,
			 DVI D,
			 INTRARI I,
			 NPART P
       LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
       LEFT JOIN NCLASEP CLA ON CLA.CODCLASEP = P.CODCLASA

		 WHERE
			 CODPLATA          = RECID
			 AND O.CODOBLIGPIF = P1.CODOBLIGPIF
			 AND G.CODGENERAL  = O.CODGENERAL
			 AND G.TIPDOC      = 5
			 AND G.CODDOC      = D.CODDVI
			 AND D.CODINTR     = I.CODINTR
			 AND P.CODPART     = O.CODPART
		 ) ;
   end if;

   INSERT INTO TMP_PLATI1 --plati in avans
   (CODPLATA1,
   	CODOBLIGPIF,
	  VALOARE,
	  CODMONEDA,
	  CONTDEST,
	  ADRESAFURN,
	  INDEXLOCAL,
    STINSA,
    CODSWIFT,
    CODBNR,
    CODSTATISTICBNR,
    TIPCOMISION,
    CODBANK,
	  CODPART,
	  DENPART,
	  VALDOC,
    SUBUNITATEA,
    AVANS,
		Codanalizanod ,
		Codanalizanodx ,
		codpers        ,
		codcont,
    CODFISCAL,
    SIMBOLCLASA
   )

   SELECT
     P1.CODPLATA1,
   	 P1.CODOBLIGPIF,
	   P1.VALOARE,
	   P1.CODMONEDA,
	   P1.CONTDEST,
	   P1.ADRESAFURN,
	   P1.INDEXLOCAL,
	   P1.STINSA,
     P1.CODSWIFT,
     P1.CODBNR,
     P1.CODSTATISTICBNR,
     P1.TIPCOMISION,
     P1.CODBANK,
	   P1.CODPART,
	   Case when P1.CODOBLIGPIF = 0 then P.DEN_PART
			    when P1.CODOBLIGPIF = 1 then A.NUME || &apos; &apos;|| A.PRENUME
					when P1.CODOBLIGPIF = 2 then C.Simbol
		 end,
	   P1.VALOARE,
	   PKG_GLOBALS.SUBUNITATE,
     P1.CODOBLIGPIF + 1,
		 P1.codanalizanodx ,
		 P1.codanalizanodx ,
		 P1.codpers        ,
		 P1.codcont,
     CF.CODFISCAL,
     CLA.SIMBOL
   FROM
     PLATI1 P1
     Left join NPART P on P.CodPart = P1.CodPart
     LEFT JOIN NCLASEP CLA ON CLA.CODCLASEP = P.CODCLASA
     LEFT JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
     Left join NPERS A on A.CodPers = P1.CodPers
     Left join NCont C on C.CodCont = P1.CodCont
   WHERE
     CODPLATA           = RECID
     AND P1.CODOBLIGPIF &lt; 10;

  INSERT INTO TMP_PLATI2(CODPLATA2, CODPLATA, CODPERS, CONTDEST, CODSWIFT, VALOARE,NRDOC, NUME, PRENUME )
  SELECT P2.CODPLATA2, P2.CODPLATA, P2.CODPERS, P2.CONTDEST, P2.CODSWIFT, P2.VALOARE, P2.NRDOC, P.NUME, P.PRENUME
  FROM 
    PLATI2 P2
    INNER JOIN NPERS P ON P.CODPERS = P2.CODPERS
  WHERE
    CODPLATA = RecID;  


   DELETE TMP_PLATI1_INITIAL;
   INSERT INTO TMP_PLATI1_INITIAL
   SELECT * FROM TMP_PLATI1;

   Select Nvl(Curs,1) into CursOrd from TMP_PLATI;
	 if CursOrd = 0 then CursOrd := 1; end if;

	 /*UPDATE TMP_PLATI1 P1
	 set P1.SOLDBUGET = PKG_PLATI.GetSoldBuget(P1.Codanalizanod, aAn, aLuna, RecID)
	                  - (Select Sum(Valoare*CursOrd) from TMP_PLATI1 x where x.Codanalizanod = P1.Codanalizanod);	*/

   UPDATE TMP_PLATI1 P1
	 set P1.SOLDBUGET = (select sum(case when codcentru = 1 then B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12 else 0 end) from TMP_BUGETANALIZA where codanalizanod = P1.Codanalizanod)
                    - (select sum(case when codcentru = 4 then B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12 else 0 end) from TMP_BUGETANALIZA where codanalizanod = P1.Codanalizanod);

	 INSERT INTO TMP_PLATIPART (CODPART, DEN_PART, SUMA, SUMADETALII, Avans, CodPers, CodCont, CodFiscal, SIMBOLCLASA)
   SELECT
		 CODPART,
     DENPART,
     ROUND(SUM(VALOARE), 2),
     ROUND(SUM(VALOARE), 2),
		 Avans,
		 CodPers,
		 CodCont,
     CodFiscal,
     SIMBOLCLASA
   FROM
     TMP_PLATI1
   GROUP BY
     CODPART, DENPART, Avans, CodPers, CodCont, CodFiscal, SIMBOLCLASA;

	 INSERT INTO TMP_PLATIPART (DEN_PART, SUMA, SUMADETALII, CodPers)
   SELECT
     NUME || &apos; &apos; || PRENUME,
     ROUND(SUM(VALOARE), 2),
     ROUND(SUM(VALOARE), 2),
		 CodPers
   FROM
     TMP_PLATI2
   GROUP BY
      NUME || &apos; &apos; || PRENUME, CodPers;


   UPDATE TMP_PLATIPART
   SET
    DOCLEGATURA = &apos;X&apos;;

   DELETE TMP_PLATIPART_INITIAL;
   INSERT INTO TMP_PLATIPART_INITIAL SELECT * FROM TMP_PLATIPART;

   IF RECID &gt; 0 THEN
     BEGIN
       SELECT NVL(CODBANKCONT, 0) INTO aCODCONT FROM TMP_PLATI;
       EXCEPTION WHEN OTHERS THEN aCODCONT := 0;
     END ;

     IF aCODCONT = 0 THEN
       UPDATE TMP_PLATI
       SET
        CODMONEDA = (SELECT DISTINCT NVL(CODMONEDA, 0) FROM TMP_PLATI1);

       UPDATE TMP_PLATI P
       SET
        SIMBOLMONEDA = (SELECT SIMBOL FROM NMONEDE M WHERE M.CODMONEDA = P.CODMONEDA);
     END IF;
   END IF;
   PKG_CFGTABLES.EXT_GOTORECORD(105);
   COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
ACARNETDOC NUMBER(20);
ANRDOC NUMBER(20);
BEGIN
  SELECT CARNETDOC, NRDOC
  INTO   ACARNETDOC,   ANRDOC
  FROM TMP_PLATI;

  UPDATE TMP_PLATI1
  SET
    DINCARETVA = VALOARE
  WHERE
    SPLITTVA = 1;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (105); 
  IF Operation = 0 THEN
    SELECT  CODPLATA INTO RECID FROM TMP_PLATI;

    UPDATE PLATI P
    SET
     (  DATA,
        CODBANKCONT,
        VALOARE,
        VALOAREDEREPARTIZAT,
        APROBAT,
        CARNETDOC,
        NRDOC,
			  TipDoc,
        CodAnaliza,
				AN,
        LUNA,
        OBS, CURS
      )
      = (SELECT
           DATA,
           CODBANKCONT,
           VALOARE,
           VALOAREDEREPARTIZAT,
           APROBAT,
           CARNETDOC,
           NRDOC,
					 TipDoc,
           CodAnaliza,
           AN,
           LUNA,
           OBS, CURS
       FROM
         TMP_PLATI TP
       )
    WHERE
      P.CODPLATA = RECID;

   DELETE PLATI1 P1
   WHERE
     CODPLATA = RECID
     AND NOT EXISTS (SELECT CODPLATA1 FROM TMP_PLATI1 WHERE CODPLATA1 = P1.CODPLATA1);


   DELETE PLATI2 P2
   WHERE
     CODPLATA = RECID
     AND NOT EXISTS (SELECT CODPLATA2 FROM TMP_PLATI2 WHERE CODPLATA2 = P2.CODPLATA2);



   FOR V_REC IN (SELECT * FROM TMP_PLATI1)
   LOOP
     IF V_REC.CODPLATA1 &lt; 0 THEN
       INSERT INTO PLATI1
			 (CODPLATA1, CODPLATA, CODOBLIGPIF, VALOARE, SPLITTVA, REST, CODMONEDA, CONTDEST, ADRESAFURN, CODSWIFT, CODBNR, CODSTATISTICBNR, TIPCOMISION, CODBANK, INDEXLOCAL, CODPART, DINCARETVA,
				Codanalizanodx ,
				codpers        ,
				codcont
			 )
       VALUES
			 (SEQ_PLATI1_CODPLATA1.NEXTVAL, RECID, V_REC.CODOBLIGPIF, V_REC.VALOARE, V_REC.SPLITTVA, V_REC.REST, V_REC.CODMONEDA, V_REC.CONTDEST, V_REC.ADRESAFURN, V_REC.CODSWIFT, V_REC.CODBNR, V_REC.CODSTATISTICBNR, V_REC.TIPCOMISION, V_REC.CODBANK, V_REC.INDEXLOCAL, V_REC.CODPART, V_REC.DINCARETVA,
				Nvl(V_REC.Codanalizanodx, V_REC.Codanalizanod),
				V_REC.codpers        ,
				V_REC.codcont
			 );
     ELSE
       UPDATE PLATI1
       SET
         VALOARE         = V_REC.VALOARE,
         SPLITTVA        = V_REC.SPLITTVA,
         REST            = V_REC.REST,
				 CODMONEDA       = V_REC.CODMONEDA,
         CONTDEST        = V_REC.CONTDEST,
         ADRESAFURN      = V_REC.ADRESAFURN,
         CODSWIFT        = V_REC.CODSWIFT,
         CODBNR          = V_REC.CODBNR,
         CODSTATISTICBNR = V_REC.CODSTATISTICBNR,
         TIPCOMISION     = V_REC.TIPCOMISION,
         CODBANK         = V_REC.CODBANK,
         INDEXLOCAL      = V_REC.INDEXLOCAL,
         CODPART         = V_REC.CODPART,
         DINCARETVA      = V_REC.DINCARETVA,
				 Codanalizanodx  = Nvl(V_REC.Codanalizanodx, V_REC.Codanalizanod) ,
				 codpers         = V_REC.codpers        ,
				 codcont         = V_REC.codcont
       WHERE
        CODPLATA1 = V_REC.CODPLATA1;
     END IF;
   END LOOP;
   
  FOR V_REC IN (SELECT * FROM TMP_PLATI2)
  LOOP
    IF V_REC.CODPLATA2 &lt; 0 THEN
      INSERT INTO PLATI2(CODPLATA2, CODPLATA, CODPERS, CONTDEST, CODSWIFT, VALOARE, NRDOC)
      VALUES(SEQ_PLATI2_CODPLATA2.NEXTVAL, RECID,  V_REC.CODPERS, V_REC.CONTDEST, V_REC.CODSWIFT, V_REC.VALOARE, V_REC.NRDOC );
    ELSE
      UPDATE PLATI2
      SET
        CODPERS  = V_REC.CODPERS, 
        CONTDEST = V_REC.CONTDEST, 
        CODSWIFT = V_REC.CODSWIFT, 
        VALOARE   = V_REC.VALOARE,
        NRDOC     = V_REC.NRDOC 
      WHERE
        CODPLATA2 = V_REC.CODPLATA2;  
    END IF    ;
  END LOOP;    
   
   
  ELSE
    SELECT SEQ_PLATI_CODPLATA.Nextval INTO RecID From DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;PLATI&apos;, RecId); 
    INSERT INTO PLATI( CODPLATA, DATA, CODBANKCONT, VALOARE, CARNETDOC, NRDOC,TipDoc, userid, datacreare,
                       CodAnaliza, AN, LUNA, SUBUNITATEA, VALOAREDEREPARTIZAT, APROBAT, OBS, CURS)
    SELECT RECID, DATA, CODBANKCONT, VALOARE, CARNETDOC, NRDOC,TipDoc,PKG_GLOBALS.USERID,SYSTIMESTAMP,
           CodAnaliza, AN, LUNA, SUBUNITATEA, VALOAREDEREPARTIZAT, APROBAT, OBS, CURS
    FROM TMP_PLATI;
    INSERT INTO PLATI1
		(CODPLATA1, CODPLATA, CODOBLIGPIF, VALOARE, SPLITTVA, REST, CODMONEDA, CONTDEST, ADRESAFURN, CODSWIFT, CODBNR,CODSTATISTICBNR, TIPCOMISION, CODBANK, INDEXLOCAL, CODPART, DINCARETVA,
		 Codanalizanodx, codpers, codcont
		)
    SELECT SEQ_PLATI1_CODPLATA1.NEXTVAL, RECID, CODOBLIGPIF, VALOARE, SPLITTVA, REST, CODMONEDA, CONTDEST, ADRESAFURN, CODSWIFT, CODBNR, CODSTATISTICBNR, TIPCOMISION, CODBANK, INDEXLOCAL, CODPART, DINCARETVA,
				   Nvl(Codanalizanodx, Codanalizanod), codpers, codcont
		 FROM TMP_PLATI1;

   INSERT INTO PLATI2(CODPLATA2, CODPLATA, CODPERS, CONTDEST, CODSWIFT, VALOARE, NRDOC)
   SELECT SEQ_PLATI2_CODPLATA2.NEXTVAL, RECID,  CODPERS, CONTDEST, CODSWIFT, VALOARE, NRDOC 
   FROM 
     TMP_PLATI2;
   



  END IF;

 

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  PKG_CFGTABLES.EXT_POSTRECORDS(105); 
  NotifyModif(Operation, RecId, &apos;PLATI&apos;);
  COMMIT;
END;

function GetSoldBuget(aCodanalizanod in Number, aAn in Number, aLuna in Number, aCodPlata in Number, aTipDoc in number default 0) return number is
  aSold number;
  x number;
	y number;
	aLuna1 Number;
	aLuna2 Number;
	aTipSold Number;
  aCodAnaliza number;
begin
  if aTipDoc = 1 then
    begin
      select codanaliza into aCodAnaliza from analizanod where codanalizanod = aCodAnalizaNod;
      execute immediate &apos;BEGIN&apos;||Chr(10)||
     &apos;  DELETE TMP_BUGETANALIZA;&apos;||Chr(10)||
     &apos;  PKG_ANALIZA.GetBugete( &apos;||aCodAnaliza||&apos;, &apos;||PKG_GLOBALS.ANLUCRU||&apos;, 1, 12, 9, 0 );&apos;||Chr(10)||
     &apos;  DELETE TMP_BUGETANALIZA WHERE CODANALIZANOD IN (SELECT DISTINCT NODPARINTE FROM ANALIZANOD WHERE CODANALIZA = &apos;||aCodAnaliza||&apos;);&apos;||Chr(10)||
     &apos;  COMMIT;&apos;||Chr(10)||
     &apos;END;&apos;;
    exception when others then aCodAnaliza := 0;
    end;
    
    begin
      select (select sum(case when codcentru = 1 then B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12 else 0 end) from TMP_BUGETANALIZA where codanalizanod = aCodanalizanod)
              - (select sum(case when codcentru = 4 then B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12 else 0 end) from TMP_BUGETANALIZA where codanalizanod = aCodanalizanod)
      into aSold from dual;
    exception when others then aSold := 0;
    end;  
  else
  BEGIN
			BEGIN
					SELECT NVL(pkg_categconst.GetValConstanta(&apos;TipValoriBuget&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipSold from dual;
					EXCEPTION WHEN OTHERS THEN aTipSold := 1;
			END;
			if aTipSold = 1 then
				 aLuna1 := aLuna;
				 aLuna2 := aLuna;
			elsif aTipSold = 2 then
		 aLuna1 := aLuna;
				 aLuna2 := Trunc((aLuna + 2)/3)*3;
				 aLuna1 := aLuna2 - 2;
			elsif aTipSold = 3 then
				 aLuna1 := 1;
				 aLuna2 := 12;
			end if;
			Select Sum(Nvl(Buget,0)) Into aSold
			from (
				SELECT BUGET from BUGETANALIZA BA
				WHERE BA.AN = aAn AND BA.Luna between aLuna1 and aLuna2 AND BA.CodAnalizaNod = aCodAnalizaNod AND BA.Tip = 9
				UNION ALL
				select R1.VCredit Buget
				from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				WHERE R.AN = aAn AND R.LunaDest between aLuna1 and aLuna2 and R1.CodNodDest = aCodAnalizaNod
					    and Nvl(R1.VCredit,0) &lt;&gt; 0
				UNION ALL
				select -R1.VCredit Buget
				from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				where R.AN = aAn AND R.LunaSursa between aLuna1 and aLuna2 AND R1.CodNodSursa = aCodAnalizaNod
					    and Nvl(R1.VCredit,0) &lt;&gt; 0
				UNION ALL
				select -p1.VALOARE Buget
				from Plati1 P1 inner join Plati P on P.CodPlata = P1.CodPlata
				WHERE P.An = aAn AND P.Luna between aLuna1 and aLuna2 and P.TipDoc = 1 AND P1.CodAnalizaNodx = aCodAnalizaNod and P1.CodObligPIF in (0,1,2) and (aCodPlata = 0 or P.CodPlata &lt;&gt; aCodPlata)
				UNION ALL
				select -P1.Valoare Buget
				from ObligPIF O
						 inner join Plati1 P1   on P1.CodObligPIF = O.CodObligPIF
						 inner join Plati P     on P.Codplata = P1.Codplata
				WHERE P.An = aAn AND P.Luna between aLuna1 and aLuna2 and P.TipDoc = 1 AND O.CodAnalizaNod = aCodAnalizaNod and (not P1.CodObligPIF in (0,1,2)) and (aCodPlata = 0 or P.CodPlata &lt;&gt; aCodPlata)
				UNION ALL
				select -R1.VPLATAAPROB Buget
				from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				WHERE R.AN = aAn AND R.LunaDest between aLuna1 and aLuna2 and R1.CodNodDest = aCodAnalizaNod
					    and Nvl(R1.VPLATAAPROB,0) &lt;&gt; 0
				UNION ALL
				select +R1.VPLATAAPROB Buget
				from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
				where R.AN = aAn AND R.LunaSursa between aLuna1 and aLuna2 AND R1.CodNodSursa = aCodAnalizaNod
  				    and Nvl(R1.VPLATAAPROB,0) &lt;&gt; 0
				);
  EXCEPTION WHEN OTHERS THEN aSold := 0;
  END ;
  end if;
  Return aSold;
end;

function GetSoldBuget1(aCodanalizanod in Number, aAn in Number, aLuna in Number) return number is
  aSold number;
	aLuna1 Number;
	aLuna2 Number;
	aTipSold Number;

begin
  BEGIN
			BEGIN
					SELECT NVL(pkg_categconst.GetValConstanta(&apos;TipValoriBuget&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 1) INTO aTipSold from dual;
					EXCEPTION WHEN OTHERS THEN aTipSold := 1;
			END;
			if aTipSold = 1 then
				 aLuna1 := aLuna;
				 aLuna2 := aLuna;
			elsif aTipSold = 2 then
		 aLuna1 := aLuna;
				 aLuna2 := Trunc((aLuna + 2)/3)*3;
				 aLuna1 := aLuna2 - 2;
			elsif aTipSold = 3 then
				 aLuna1 := 1;
				 aLuna2 := 12;
			end if;
			Select Sum(Nvl(Buget,0)) Into aSold
			from
				(
					SELECT BUGET from BUGETANALIZA BA
					WHERE BA.AN = aAn AND BA.Luna between aLuna1 and aLuna2 AND BA.CodAnalizaNod = aCodAnalizaNod AND BA.Tip = 9
					UNION ALL
					select R1.VCredit Buget
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
					WHERE R.AN = aAn AND R.LunaDest between aLuna1 and aLuna2  and R1.CodNodDest = aCodAnalizaNod
					UNION ALL
					select -R1.VCredit Buget
					from Bugetrectif1 R1 inner join Bugetrectif R on R.Codbugetrectif = R1.CODBUGETRECTIF
					where R.AN = aAn AND R.LunaSursa between aLuna1 and aLuna2 AND R1.CodNodSursa = aCodAnalizaNod
					UNION ALL
					select -C1.PU*C1.CantComandat Buget
					from COMANDA1 C1
							 inner join COMANDA C on C.CodComanda = C1.CodComanda
							 inner join AnalizaNod N on N.CodAnalizaNod = C1.CodAnalizaNod
					WHERE C.TipDoc = 8 and C.An = aAn AND C.Luna between aLuna1 and aLuna2 and C1.Codanalizanod = aCodAnalizaNod
				) ;
  EXCEPTION WHEN OTHERS THEN aSold := 0;
  END ;
  Return aSold;
end;

end PKG_PLATI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACFAE7A2D3468D45E5CE543094E6D568CC344FCC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PMP IS

  G_PMP_LEI      NUMBER(20,7);
  G_PMP_VALUTA   NUMBER(20,7);
  G_PMP_PREC     NUMBER(20,7);
  G_PMP_PREC_VAL NUMBER(20,7);
  G_PMP_LAST     NUMBER(20,7);
  G_PMP_LAST_VAL NUMBER(20,7);

FUNCTION GET_PMP_VALUTA_FROM_VAR RETURN NUMBER IS
BEGIN
 RETURN G_PMP_VALUTA  ;
 G_PMP_VALUTA  := -1;
END;

FUNCTION GET_PMP_PREC_FROM_VAR RETURN NUMBER IS
BEGIN
 RETURN G_PMP_PREC  ;
 G_PMP_PREC  := -1;
END;

FUNCTION GET_PMP_PREC_VALUTA_FROM_VAR RETURN NUMBER IS
BEGIN
 RETURN G_PMP_PREC_VAL  ;
 G_PMP_PREC_VAL  := -1;
END;

FUNCTION GET_PMP_LAST_FROM_VAR RETURN NUMBER IS
BEGIN
 RETURN G_PMP_LAST;
 G_PMP_LAST  := -1;
END;

FUNCTION GET_PMP_LAST_VALUTA_FROM_VAR RETURN NUMBER IS
BEGIN
 RETURN G_PMP_LAST_VAL  ;
 G_PMP_LAST_VAL  := -1;
END;

FUNCTION GET_PMP_LEI (aCodObiect in number, aCodSubunit in Number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  G_PMP_LEI      := -1;
  G_PMP_VALUTA   := -1;
  G_PMP_PREC     := -1;
  G_PMP_PREC_VAL := -1;
  G_PMP_LAST     := -1;
  G_PMP_LASt_VAL := -1;
  G_PMP_LEI      := GET_PMP_OBIECT (aCodObiect, aCodSubunit , G_PMP_VALUTA, NVL(XAN,0), NVL(XLUNA,0));
  RETURN G_PMP_LEI;
  G_PMP_LEI      := -1;
END;

FUNCTION GET_PMP_LAST (aCodObiect in number, aCodSubunit in Number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0) RETURN NUMBER IS
BEGIN
  G_PMP_LEI      := -1;
  G_PMP_VALUTA   := -1;
  G_PMP_PREC     := -1;
  G_PMP_PREC_VAL := -1;
  G_PMP_LAST     := -1;
  G_PMP_LAST_VAL := -1;
  G_PMP_LEI      := GET_PMP_OBIECT (aCodObiect, aCodSubunit , G_PMP_VALUTA, NVL(XAN,0), NVL(XLUNA,0));
  RETURN G_PMP_LAST;
  G_PMP_LAST     := -1;
END;

FUNCTION GET_PMP_OBIECT (aCodObiect in number, aCodSubunit in Number, pmpvaluta out number, XAN IN  NUMBER DEFAULT 0, XLUNA IN NUMBER DEFAULT 0 ) RETURN NUMBER IS
  iPMP          NUMBER(20,7) := 0;
  iPMPVal       NUMBER(20,7) := 0;
  iPMPPrec      NUMBER(20,7) := 0;
  iPMPPrecVal   NUMBER(20,7) := 0;
  iPMPLast      NUMBER(20,7) := 0;
  iPMPLastVal   NUMBER(20,7) := 0;

  aCANTINTR     NUMBER(20,7) := 0;
  aVALINTR      NUMBER(20,7) := 0;
  aVALVALUTA    NUMBER(20,7) := 0;
  CANTINTRPREC  NUMBER(20,7) := 0;
  VALINTRPREC   NUMBER(20,7) := 0;
  VALVALUTAPREC NUMBER(20,7) := 0;
  iAn           NUMBER(4);
  iLuna         NUMBER(2);
  iAnPrec       NUMBER(4);
  iLunaPrec     NUMBER(2);
BEGIN
  -- pkg_globals.SetLunaLucru(2008,8);
  iAn   := Coalesce(xAn,0);
  iLuna := Coalesce(xLuna,0);
  IF iAn = 0 THEN
    iAn   := pkg_globals.AnLucru;
    iLuna := pkg_globals.LunaLucru;
  END IF;

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(iAn, iLuna, iAnPrec, iLunaPrec);
  PKG_GLOBALS.SetLunaTemp(iAn, iLuna);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);

  BEGIN
    SELECT SUM(CANTINTR),  SUM(VALINTR), SUM(VALVALUTA) INTO CANTINTRPREC, VALINTRPREC , VALVALUTAPREC
    FROM PMPLUNA
    WHERE an = iAnPrec AND luna = iLunaPrec
      AND CodObiect  = aCodObiect
      AND CodSubunit = CASE aCodSubunit WHEN 1 THEN CodSubunit ELSE aCodSubunit END;
  EXCEPTION
    WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; VALVALUTAPREC := 0;
  END;

  CANTINTRPREC  := Coalesce(CANTINTRPREC ,0);
  VALINTRPREC   := Coalesce(VALINTRPREC  ,0);
  VALVALUTAPREC := Coalesce(VALVALUTAPREC,0);

  IF Coalesce(CANTINTRPREC,0) &lt;&gt; 0 THEN
    iPMPPrec    := Round(VALINTRPREC   / CANTINTRPREC,7);
    iPMPPrecVal := Round(VALVALUTAPREC / CANTINTRPREC,7);
  END IF;

  BEGIN
    SELECT Sum(VALINTR), Sum(CANTINTR), sum(VALVALUTA) INTO aVALINTR, aCANTINTR, aVALVALUTA
    FROM V_PMP_LUNA
    WHERE CodObiect  = aCodObiect
      AND CodSubunit = CASE aCodSubunit WHEN 1 THEN CodSubunit ELSE aCodSubunit END;
  EXCEPTION
    WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
  END;

  aVALINTR   := Coalesce(aVALINTR  ,0) + Coalesce(VALINTRPREC,  0);
  aCANTINTR  := Coalesce(aCANTINTR ,0) + Coalesce(CANTINTRPREC, 0);
  aVALVALUTA := Coalesce(aVALVALUTA,0) + Coalesce(VALVALUTAPREC,0);
  IF aCANTINTR &lt;&gt; 0 THEN
    iPMP    := Round(aVALINTR   / aCANTINTR,7);
    iPMPVal := Round(aVALVALUTA / aCANTINTR,7);
  END IF;

  iPMPLast    := iPMP;
  iPMPLastVal := iPMPVal;

  IF iPMPLast = 0    THEN iPMPLast    := iPMPPrec;    END IF;
  IF iPMPLastVal = 0 THEN iPMPLastVal := iPMPPrecVal; END IF;

  IF iPMPLast = 0 OR iPMPLastVal = 0 THEN
    FOR vRec IN (
      SELECT SUM(CANTINTR) CANT, SUM(VALINTR) VAL, SUM(VALVALUTA) VALV
      FROM PMPLUNA
      WHERE an = iAnPrec AND luna = iLunaPrec
        AND CodObiect  = aCodObiect
        AND CodSubunit = CASE aCodSubunit WHEN 1 THEN CodSubunit ELSE aCodSubunit END
      GROUP BY AN, LUNA
      ORDER BY AN DESC, LUNA DESC
    ) LOOP
      IF iPMPLast    = 0 AND vRec.Cant &lt;&gt; 0 THEN iPMPLast    := Round(vRec.Val  / vRec.Cant,7); END IF;
      IF iPMPLastVal = 0 AND vRec.Cant &lt;&gt; 0 THEN iPMPLastVal := Round(vRec.ValV / vRec.Cant,7); END IF;
      EXIT WHEN iPMPLast &lt;&gt; 0 AND iPMPLastVal &lt;&gt; 0;
    END LOOP;
  END IF;

  G_PMP_PREC     := iPMPPrec;
  G_PMP_PREC_VAL := iPMPPrecVal;
  G_PMP_LAST     := iPMPLast;
  G_PMP_LAST_VAL := iPMPLastVal;
  PMPValuta      := iPMPVal;
  RETURN iPMP;
END;

FUNCTION GET_PMP_OBIECT_DOC (aCodObiect in number, aCodSubunit in Number, aPMPCodIntr in Number, aPMPCodIes in Number, aPMPCodTransf in Number,pmpvaluta out number,XAN IN  NUMBER DEFAULT 0,XLUNA IN NUMBER DEFAULT 0 ) return number is
  iResult number(20,7) := -1;
  iResultValuta number(20,7) := -1;

 aCANTINTR     NUMBER(20, 7) := 0;
 aVALINTR      NUMBER(20, 7) := 0;
 aVALVALUTA    NUMBER(20,7)  := 0;
 CANTINTRPREC  NUMBER(20, 7) := 0;
 VALINTRPREC   NUMBER(20, 7) := 0;
 VALVALUTAPREC NUMBER(20,7)  := 0;
 NR            NUMBER(20)    := 0;
 IAN NUMBER(4);
 ILUNA NUMBER(2);
BEGIN
 -- pkg_globals.SetLunaLucru(2008,8);

  PKG_Globals.SetPMPCodDocs(aPMPCodIntr, aPMPCodIes, aPMPCodTransf);

 IAN := NVL(XAN,0);
 ILUNA := NVL(XLUNA,0);
 IF IAN = 0 THEN
   IAN := pkg_globals.AnLucru;
   ILUNA := pkg_globals.LunaLucru;
 END IF  ;
  pkg_globals.SetLunaTemp(IAN, ILUNA);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);

  SELECT COUNT(*) INTO NR FROM V_PMP_LUNA_DOC WHERE CodObiect = aCodObiect;

  IF NR = 0 THEN
    IF aCodSubunit = 1 then -- la nivel de firma
      begin
      select sum(valIntr), Sum(CantIntr),SUM(VALVALUTA) into aValIntr, aCantIntr, aVALVALUTA from pmpluna
      where
        (an*12 + luna) = (IAN * 12 + ILUNA - 1)
        and
        codobiect = aCodObiect;
       EXCEPTION WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
      end;
    else  -- pe subunitate
      begin
      select sum(valIntr), Sum(CantIntr), SUM(VALVALUTA) into aValIntr, aCantIntr, aVALVALUTA from pmpluna
      where
            (an*12 + luna) = (IAN * 12 + ILUNA - 1)and
            codobiect = aCodObiect and
            codsubunit = aCodSubunit;
      EXCEPTION WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
      end;
    end if;
  ELSE
    if aCodSubunit = 1 then -- la nivel de firma
      begin
      SELECT sum(v.VALINTR),sum(v.CANTINTR) , sum(v.VALVALUTA) into aVALINTR, aCANTINTR, aVALVALUTA
      FROM  V_PMP_LUNA_DOC v
      where V.CODOBIECT = aCodObiect;
      EXCEPTION WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
      end;
      BEGIN
        SELECT SUM(CANTINTR),  SUM(VALINTR), SUM(VALVALUTA) INTO CANTINTRPREC, VALINTRPREC, VALVALUTAPREC
        FROM
          PMPLUNA
        WHERE
          (an*12 + luna) = (IAN * 12 + ILUNA - 1)
          AND
          CODOBIECT  = aCodObiect;
        EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0; VALVALUTAPREC := 0;
      END;

    else -- pe subunitate

      begin
      SELECT Sum(v.VALINTR) ,Sum(v.CANTINTR), sum(v.VALVALUTA) into aVALINTR, aCANTINTR, aVALVALUTA
      FROM V_PMP_LUNA_DOC v
      where
        v.CODOBIECT = aCodObiect and v.CODSUBUNIT = aCodSubunit;
      EXCEPTION WHEN OTHERS THEN aCANTINTR := 0; aVALINTR := 0; aVALVALUTA := 0;
      end;
      BEGIN
        SELECT SUM(CANTINTR),  SUM(VALINTR), SUM(VALVALUTA) INTO CANTINTRPREC, VALINTRPREC , VALVALUTAPREC
        FROM
          PMPLUNA
        WHERE
          (an*12 + luna) = (IAN * 12 + ILUNA - 1)
          AND
          CODOBIECT  = aCodObiect and codsubunit = aCodSubunit;

        EXCEPTION WHEN OTHERS THEN CANTINTRPREC := 0; VALINTRPREC := 0;  VALVALUTAPREC := 0;
      END;

    end if;

    aVALINTR   := aVALINTR   + Nvl(VALINTRPREC, 0);
    aCANTINTR  := aCANTINTR  + Nvl(CANTINTRPREC, 0);
    aVALVALUTA := aVALVALUTA + NVL(VALVALUTAPREC,0);

  END IF;
  iResult := 0;
  iResultValuta := 0;
  if aCANTINTR &lt;&gt; 0 then
     iResult := aVALINTR / aCANTINTR;
     iResultValuta := aVALVALUTA / aCANTINTR;
  end if;
  pmpvaluta := round(iResultValuta,7);
  RETURN round(iResult,7);
END;

FUNCTION AM_MISCARI_CU_PMP return NUMBER is
  cntio     NUMBER(20);
  cntdoc    NUMBER(20);
  vAntemp   NUMBER(4) := PKG_GLOBALS.AnTemp;
  vLunaTemp NUMBER(2) := PKG_GLOBALS.LunaTemp;
BEGIN
  pkg_stoc_generare_facturi.make_config_luna;

  SELECT count(1) INTO cntio FROM TMP_IOART_LUNA IO WHERE io.mg = 3;
  IF cntio = 0 THEN
    RETURN 0;
  END IF;

  DELETE FROM tmp_pmp_act_luna;

  INSERT INTO tmp_pmp_act_luna(codies, tipdoc, codlivr1, codobiect, codsubunit, pmp,pmpvaluta)
  SELECT i.CodIes, i.TipDoc, l1.codlivr1, ns.codobiect, i.subunitatea, l1.pmp, l1.pmpvaluta
  FROM iesiri i
    INNER JOIN livr           l  ON l.codies      = i.codies
    INNER JOIN livr1          l1 ON l.codlivr     = l1.codlivr
    INNER JOIN nirstoc        ns ON ns.codnirstoc = l1.codnirstoc
    INNER JOIN tmp_ioart_luna io ON io.codioart   = ns.codioart AND io.mg = 3
  WHERE i.an = vAntemp AND i.luna = vLunaTemp;

  INSERT INTO tmp_pmp_act_luna(codies, tipdoc, codlivr1, codobiect, codsubunit, pmp,pmpvaluta)
  SELECT i.CodIntr, i.TipDoc, l1.codlivr1, ns.codobiect,i.subunitatea, l1.pmp, l1.pmpvaluta
  FROM intrari i
    INNER JOIN livr           l  ON l.codintr      = i.codintr
    INNER JOIN livr1          l1 on l.codlivr     = l1.codlivr
    INNER JOIN nirstoc        ns on ns.codnirstoc = l1.codnirstoc
    INNER JOIN tmp_ioart_luna io ON io.codioart   = ns.codioart AND io.mg = 3
  WHERE i.an = vAntemp AND i.luna = vLunaTemp;

  INSERT INTO tmp_pmp_act_luna(codies, tipdoc, codlivr1, codobiect, codsubunit, pmp,pmpvaluta)
  SELECT TR.CodTransf, TR.TipDoc, l1.codlivr1, ns.codobiect,TR.subunitatea, l1.pmp, l1.pmpvaluta
  FROM transf tr
    INNER JOIN livr           l  ON l.CodTransf   = tr.CodTransf
    INNER JOIN livr1          l1 on l.codlivr     = l1.codlivr
    INNER JOIN nirstoc        ns on ns.codnirstoc = l1.codnirstoc
    INNER JOIN tmp_ioart_luna io ON io.codioart   = ns.codioart AND io.mg = 3
  WHERE tr.an = vAntemp AND tr.luna = vLunaTemp;

  COMMIT;
  SELECT Count(1) INTO cntdoc FROM tmp_pmp_act_luna;
  RETURN cntdoc;
END;

procedure CALC_PMP(Tip in Number) is
  sCodSubunit VARCHAR2(100);
  tSQL        CLOB;

  iAn         NUMBER(4) := PKG_GLOBALS.ANLUCRU;
  iLuna       NUMBER(2) := PKG_GLOBALS.LUNALUCRU;
  iAnPrec     NUMBER(4);
  iLunaPrec   NUMBER(2);
BEGIN
  --PKG_GLOBALS_setdebugmode(true);
  --CALL create_wm_temps_flag(&apos;PMP_CALC&apos;);
  DELETE FROM TMP_PMP;
  DELETE FROM TMP_PMP_CALC_P;
  DELETE FROM TMP_PMP_CALC_I;
  
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(iAn, iLuna, iAnPrec, iLunaPrec);
  PKG_GLOBALS.SetLunaTemp(iAn, iLuna);
  PKG_CATEGCONST.CONST_TO_TMP_CONSTANTE(&apos;TRANSFPMP&apos;);

  IF Tip = 2
  THEN sCodSubunit := &apos;CodSubunit&apos;;
  ELSE sCodSubunit := &apos;1&apos;;
  END IF;

  tSQL := &apos;INSERT INTO TMP_PMP_CALC_P
  SELECT
    CodObiect, &apos;||sCodSubunit||&apos; AS CodSubunit,
    SUM(CANTINTR),  SUM(VALINTR), SUM(VALVALUTA)
  FROM PMPLUNA
  WHERE an = &apos;||To_Char(iAnPrec)||&apos; AND luna = &apos;||to_char(iLunaPrec)||&apos;
  GROUP BY CodObiect &apos;||CASE WHEN sCodSubunit = &apos;1&apos; THEN &apos;&apos; ELSE &apos;,&apos;||sCodSubunit END;
  LIST_EXECUTE_IMMEDIATE(tSQL, 0, 0);

  tSQL := &apos;INSERT INTO TMP_PMP_CALC_I
  SELECT
    CodObiect, &apos;||sCodSubunit||&apos; AS CodSubunit,
    Sum(CANTINTR), Sum(VALINTR), Sum(VALVALUTA)
  FROM V_PMP_LUNA aa
  GROUP BY CodObiect &apos;||CASE WHEN sCodSubunit = &apos;1&apos; THEN &apos;&apos; ELSE &apos;,&apos;||sCodSubunit END;
  LIST_EXECUTE_IMMEDIATE(tSQL, 0, 0);

  tSQL := &apos;
  INSERT INTO tmp_pmp(
    CodObiect, Codsubunit,
    PMP,
    PMPValuta
  ) 
  SELECT 
    pal.CodObiect, pal.CodSubunit,
    CASE WHEN Coalesce(P.CANTINTR,0)+Coalesce(I.CANTINTR,0) = 0 THEN 0 ELSE Round( (Coalesce(P.VALINTR,  0)+Coalesce(I.VALINTR,  0)) / (Coalesce(P.CANTINTR,0)+Coalesce(I.CANTINTR,0)) , 7) END AS PMPL, 
    CASE WHEN Coalesce(P.CANTINTR,0)+Coalesce(I.CANTINTR,0) = 0 THEN 0 ELSE Round( (Coalesce(P.VALVALUTA,0)+Coalesce(I.VALVALUTA,0)) / (Coalesce(P.CANTINTR,0)+Coalesce(I.CANTINTR,0)) , 7) END AS PMPV
  FROM ( SELECT DISTINCT CodObiect, 1 AS CodSubunit FROM tmp_pmp_act_luna ) pal 
    LEFT JOIN TMP_PMP_CALC_P P ON P.CodObiect = PAL.CodObiect AND P.CodSubunit = PAL.CodSubunit 
    LEFT JOIN TMP_PMP_CALC_I I ON I.CodObiect = PAL.CodObiect AND I.CodSubunit = PAL.CodSubunit&apos;;
  LIST_EXECUTE_IMMEDIATE(tSQL, 0, 0);
  COMMIT;
END;

procedure CALC_PMP2(Tip in Number) is
  cntio   NUMBER(20);
  cntdoc  NUMBER(20);
  pmp_    NUMBER(20,7);
  pmpval_ NUMBER(20,7);
begin
  DELETE FROM tmp_pmp;
  IF Tip = 2 THEN
    INSERT INTO tmp_pmp(codobiect, Codsubunit)
    SELECT DISTINCT CodObiect, CodSubunit from  tmp_pmp_act_luna;
  ELSE
    INSERT INTO tmp_pmp(codobiect, Codsubunit)
    SELECT DISTINCT CodObiect, 1 from  tmp_pmp_act_luna;
  END IF;

  FOR v_rec IN (select * from tmp_pmp) LOOP
    pmp_ := GET_PMP_OBIECT (v_rec.CodObiect, v_rec.CodSubunit,pmpval_);
    UPDATE tmp_pmp
    SET pmp           = pmp_,
        pmpvaluta     = pmpval_,
        pmpprec       = G_PMP_PREC,
        pmpprecvaluta = G_PMP_PREC_VAL
    WHERE codobiect = v_rec.codobiect
     AND codsubunit = v_rec.codsubunit;
  END LOOP;
  COMMIT;
END;

procedure updatePMP(Tip in Number) is
  aCant           NUMBER(20,7);
  pmpNou          NUMBER(20,7);
  pmpVechi        NUMBER(20,7);
  aValIntr        NUMBER(20,7);
  aCantIntr       NUMBER(20,7);
  ValIntrPREC     NUMBER(20,7);
  CantIntrPREC    NUMBER(20,7);
  liniLivr        NUMBER(20);
  NR              NUMBER(20);
  amIntrariInLuna BOOLEAN   := false;
  vAntemp         NUMBER(4) := PKG_GLOBALS.AnTemp;
  vLunaTemp       NUMBER(2) := PKG_GLOBALS.LunaTemp;
BEGIN
  UPDATE jurnal1 SET dirty = 0 WHERE an = vAntemp AND LUNA = vLunaTemp AND tipdoc = -9 AND coddoc = -999;

  IF AM_MISCARI_CU_PMP = 0 THEN
    RETURN;
  END IF;

  CALC_PMP(Tip);

  IF Tip = 2 THEN
    FOR v_rec IN (
      SELECT
        T.codlivr1, T.codies, T.tipDoc,
        T.pmp as OldPMP, t.pmpvaluta as OldPMPValuta,
        A.PMP as NewPMP, a.pmpvaluta as NewPMPValuta
      FROM tmp_pmp_act_luna T INNER JOIN tmp_pmp A ON A.CODobiect = T.CODobiect and A.CODSUBUNIT = T.Codsubunit
      WHERE ((Coalesce(T.PMP,0) &lt;&gt; Coalesce(A.PMP,0)) OR (Coalesce(T.PMPVALUTA,0) &lt;&gt; Coalesce(A.PMPVALUTA,0)))
    ) LOOP
      UPDATE jurnal1 SET dirty = 1 WHERE coddoc = v_rec.codies AND tipdoc = v_rec.tipdoc;
      UPDATE livr1
      SET pmp       = v_rec.NewPMP,
          pmpvaluta = v_rec.NewPMPValuta
      WHERE codlivr1 = v_rec.codlivr1;
			FOR v_X IN (
				SELECT E.codies, E.tipDoc
        FROM LIVR1 L1
          INNER JOIN IESLINK LK  ON LK.Codlinieaviz = L1.CodIes1
          INNER JOIN IESIRI1 E1  ON E1.CODIES1      = LK.Codies1
          INNER JOIN IESIRI  E   ON E. CODIES       = E1.Codies
          INNER JOIN IESIRI1 EE1 ON EE1.CODIES1     = L1.Codies1
          INNER JOIN IESIRI  EE  ON EE. CODIES      = EE1.Codies
				WHERE L1.CodLivr1 = V_REC.CodLivr1
          AND EE.TipDoc = 20 AND EE.Custodie = 1
			) LOOP
        UPDATE jurnal1 SET dirty = 1 WHERE coddoc = v_X.codies AND tipdoc = v_X.tipdoc;
			END LOOP;
    END LOOP;
  ELSE
    FOR v_rec IN (
      SELECT
        T.codlivr1, T.codies, T.tipDoc,
        T.pmp as OldPMP, t.pmpvaluta OldPMPValuta,
        A.PMP as NewPMP, a.pmpvaluta NewPMPValuta
      FROM tmp_pmp_act_luna T INNER JOIN tmp_pmp A ON A.CODobiect = T.CODobiect
      WHERE ((Coalesce(T.PMP,0) &lt;&gt; Coalesce(A.PMP,0)) OR (Coalesce(T.PMPVALUTA,0) &lt;&gt; Coalesce(A.PMPVALUTA,0)))
    ) LOOP
			UPDATE jurnal1 SET dirty = 1 WHERE coddoc = v_rec.codies AND tipdoc = v_rec.tipdoc;
      UPDATE livr1
      SET pmp       = v_rec.NewPMP,
          pmpvaluta = v_rec.NewPMPValuta
      WHERE codlivr1 = v_rec.codlivr1;
			FOR v_X IN (
        SELECT E.codies, E.tipDoc
        FROM LIVR1 L1
          INNER JOIN IESLINK LK  ON LK.Codlinieaviz = L1.CodIes1
          INNER JOIN IESIRI1 E1  ON E1.CODIES1      = LK.Codies1
          INNER JOIN IESIRI  E   ON E. CODIES       = E1.Codies
          INNER JOIN IESIRI1 EE1 ON EE1.CODIES1     = L1.Codies1
          INNER JOIN IESIRI  EE  ON EE. CODIES      = EE1.Codies
				WHERE L1.CodLivr1 = V_REC.CodLivr1
          AND EE.TipDoc = 20 AND EE.Custodie = 1
			) LOOP
        UPDATE jurnal1 SET dirty = 1 WHERE coddoc = v_X.codies AND tipdoc = v_X.tipdoc;
			END LOOP;
    END LOOP;
  END IF;
  COMMIT;
END;

end pkg_pmp;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_POSTCALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50948D07D0FBD2A7A0DCD1548CED3928405021D8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_POSTCALCUL IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodPC INTO Tmp FROM PCALCUL WHERE CODPC = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
sJob varchar2(100);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 72) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 72;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 72;
  DELETE FROM PCGEST WHERE  CODPC = RecId;
  DELETE FROM PCART WHERE  CODPC = RecId;
  DELETE FROM PCDIR WHERE  CODPC = RecId;
  DELETE FROM PCSECTII WHERE  CODPC = RecId;
  DELETE FROM PCALCUL WHERE  CODPC = RecId;

  NotifyModif(2, RecId, &apos;PCALCUL&apos;);

  COMMIT;
END;

PROCEDURE GET_PCSECTII_1( ANLuna IN NUMBER,  Subunit IN NUMBER  ) IS
BEGIN
  INSERT INTO TMP_PCSECTII2_1 (CODPCSECTII2_1, CODPC, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
--  SELECT -JJ.INDEXLOCAL, 0, PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
  SELECT ROWNUM, 0, -JJ.INDEXLOCAL, --PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
         JJ.VALOARE,
         NS.CODCONTD,
         NS.CODCONTC,
         NS.CODCENTRU,
         NS.CODGEST,
         Substr(G.DEN_GEST,1,30),
         CC.Simbol,
         Substr(DEBIT.SIMBOL,1,20),
         Substr(CREDIT.SIMBOL,1,20)
   from  JURNAL JJ
         inner join NESTJURNAL NS on NS.CODNESTJURNAL = -JJ.INDEXLOCAL
         inner join Distribchelt DS on DS.CODDISTRIBCHELT = JJ.CODDOC
         LEFT JOIN NGEST G ON G.CODGEST = JJ.GEST
         LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = JJ.CODCENTRU
         LEFT JOIN NCONT DEBIT ON JJ.CONTD = DEBIT.CODCONT
         LEFT JOIN NCONT CREDIT ON JJ.CONTC = CREDIT.CODCONT
   where JJ.IndexLocal &lt; 0
         AND JJ.Tipdoc = 76
         AND (Subunit = 1 or JJ.SUBUNITATEA = Subunit)
         AND(JJ.An*12+JJ.Luna=ANLUNA)
         AND DS.FAZA &lt; 3;

  for v_rec in (select CodNest, Sum(Val) Total from TMP_PCSECTII2_1 group by CodNest) loop
    Update TMP_PCSECTII2 set Total = v_rec.Total where CodNest = v_rec.CodNest;
  end loop;

  INSERT INTO TMP_PCSECTII3_1 (CODPCSECTII3_1, CODPC, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
--  SELECT -JJ.INDEXLOCAL, 0, PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
  SELECT ROWNUM, 0, -JJ.INDEXLOCAL, --PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
         JJ.VALOARE,
         NS.CODCONTD,
         NS.CODCONTC,
         NS.CODCENTRU,
         NS.CODGEST,
         Substr(G.DEN_GEST,1,30),
         CC.Simbol,
         Substr(DEBIT.SIMBOL,1,20),
         Substr(CREDIT.SIMBOL,1,20)
   from  JURNAL JJ
         inner join NESTJURNAL NS on NS.CODNESTJURNAL = -JJ.INDEXLOCAL
         inner join Distribchelt DS on DS.CODDISTRIBCHELT = JJ.CODDOC
         LEFT JOIN NGEST G ON G.CODGEST = JJ.GEST
         LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = JJ.CODCENTRU
         LEFT JOIN NCONT DEBIT ON JJ.CONTD = DEBIT.CODCONT
         LEFT JOIN NCONT CREDIT ON JJ.CONTC = CREDIT.CODCONT
   where JJ.IndexLocal &lt; 0
         AND JJ.Tipdoc = 76
         AND (Subunit = 1 or JJ.SUBUNITATEA = Subunit)
         AND(JJ.An*12+JJ.Luna=ANLUNA)
         AND DS.FAZA = 4;
  for v_rec in (select CodNest, Sum(Val) Total from TMP_PCSECTII3_1 group by CodNest) loop
    Update TMP_PCSECTII3 set Total = v_rec.Total where CodNest = v_rec.CodNest;
  end loop;
  INSERT INTO TMP_PCSECTII5_1 (CODPCSECTII5_1, CODPC, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
--  SELECT -JJ.INDEXLOCAL, 0, PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
  SELECT ROWNUM, 0, -JJ.INDEXLOCAL, --PKG_Jurnal.GetCodNestJurnal(JJ.CONTD, JJ.CONTC, JJ.GEST, JJ.CODCENTRU) CodNest,
         JJ.VALOARE,
         NS.CODCONTD,
         NS.CODCONTC,
         NS.CODCENTRU,
         NS.CODGEST,
         Substr(G.DEN_GEST,1,30),
         CC.Simbol,
         Substr(DEBIT.SIMBOL,1,20),
         Substr(CREDIT.SIMBOL,1,20)
   from  JURNAL JJ
         inner join NESTJURNAL NS on NS.CODNESTJURNAL = -JJ.INDEXLOCAL
         inner join Distribchelt DS on DS.CODDISTRIBCHELT = JJ.CODDOC
         LEFT JOIN NGEST G ON G.CODGEST = JJ.GEST
         LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = JJ.CODCENTRU
         LEFT JOIN NCONT DEBIT ON JJ.CONTD = DEBIT.CODCONT
         LEFT JOIN NCONT CREDIT ON JJ.CONTC = CREDIT.CODCONT
   where JJ.IndexLocal &lt; 0
         AND JJ.Tipdoc = 76
         AND (Subunit = 1 or JJ.SUBUNITATEA = Subunit)
         AND(JJ.An*12+JJ.Luna=ANLUNA)
         AND DS.FAZA = 3;
  for v_rec in (select CodNest, Sum(Val) Total from TMP_PCSECTII5_1 group by CodNest) loop
    Update TMP_PCSECTII5 set Total = v_rec.Total where CodNest = v_rec.CodNest;
  end loop;
END;

PROCEDURE SP_INSERTRECORD IS
Subunit      number;
AnLuna       number;
aAn           number;
aLuna         number;

BEGIN
  INSERT INTO TMP_PCALCUL FIELDS( CODPC ) VALUES (0) ;

  aAn   := PKG_Globals.ANLUCRU;
  aLuna := PKG_Globals.LUNALUCRU;
  AnLuna := aAn*12 + aLuna;
  Subunit := PKG_Globals.SUBUNITATE_DOC;
--insert into xxx (x2,x3,x4) values(0, anluna, subunit);
  GET_PCSECTII_1( ANLuna, Subunit);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
ANLUNA_START number(10);
NR           number(20);
Subunit      number;
AnLuna       number;
aAn          number;
aLuna        number;
TipValMatPC  number;

BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO TMP_PCALCUL (CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc,ValF)
  SELECT CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, NVL(TipAloc, 0),ValF FROM PCALCUL WHERE CODPC = RECID;

  SELECT AN*12 + LUNA, SUBUNITATEA, An, Luna into AnLuna, Subunit, aAn, aLuna FROM PCALCUL WHERE CODPC = RECID;

  TipValMatPC := pkg_categconst.GetValConstanta(&apos;TipValMatPC&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);

  INSERT INTO TMP_PCGEST (CODPCGEST, CODPC, CODGEST, MANS, PUNCTE, VALi, VALA, ValG, ValC, VALMAT, VALMAN, ValPUNCT, COEFMAN, DENGEST, ValD, ValS, TOTAL, ValMatN)
  SELECT
    PCG.CODPCGEST,
    PCG.CODPC,
    PCG.CODGEST,
    PCG.ManS,
    PCG.Puncte,
    PCG.VALi, PCG.VALa, PCG.ValG, PCG.ValC, PCG.VALMAT, PCG.VALMAN,
    case Nvl(PCG.Puncte,0) when 0 then 0 else Nvl((Nvl(PCG.VALi,0)+ Nvl(PCG.VALA,0)+ Nvl(PCG.ValG,0)+ Nvl(PCG.ValC,0)),0)/PCG.Puncte end,
    case Nvl(PCG.MANS,0) when 0 then 0 else Nvl(PCG.VALMAN,0)/Nvl(PCG.MANS, 0) end,
    Case PCG.CODGEST when 0 then &apos;.TOTAL&apos; else Substr(G.DEN_GEST,1,30) end,
    Nvl(PCG.VALMAT,0) + Nvl(PCG.VALMAN,0),
    Nvl(PCG.VALi,0)+ Nvl(PCG.VALA,0)+ Nvl(PCG.ValG,0)+ Nvl(PCG.ValC,0),
    Nvl(PCG.VALMAT,0) + Nvl(PCG.VALMAN,0) + Nvl(PCG.VALi,0)+ Nvl(PCG.VALA,0)+ Nvl(PCG.ValG,0)+ Nvl(PCG.ValC,0), PCG.Valmatn
  FROM
    PCGEST PCG
    LEFT JOIN NGEST G ON G.CODGEST = PCG.CODGEST
  WHERE PCG.CODPC = RECID;

  SELECT AN*12+LUNA into ANLUNA_START from TMP_PCALCUL;

  INSERT INTO TMP_PCART
   (
    CODPCART ,
    CODPC    ,
    CODCMD1  ,
    Comanda  ,
    DataCmd  ,
    CODIOART ,
    CANT     ,
    CANTTOT  ,
    VAL      ,
    VALS     ,
    VALi    ,
    VALa    ,
    ValG, ValC     ,
    MAT     ,
    CODGEST  ,
    CODFORMATIE,
    COEF,
    MAN,
    VALMAN,
    CODCC    ,
    REST     ,
    ANLUNA   ,
    PUCALC   ,
    PretMat  ,
    CODOBIECT,
    PUNCTE  ,
    CENTRU   ,
    DENOBIECT,
    DENIOART ,
    DENUM,
    PRETREFERINTA,
    PRETRETETA,
    TIPPRET,
    OBJ_CODEXTERN,
    OBJ_CODINTERN,
    CODCMDPRODMAT,
    VALLINIE,
    VALTOT,
    CONSUM
    )
  SELECT
    PCA.CODPCART,
    PCA.CODPC,
    PCA.CODCMD1,
    C.Seriadoc||C.Nrdoc,
    C.DataDoc,
    PCA.CODIOART,
    Nvl(PCA.CANT, 0),
    Nvl(PCA.CANTTOT, 0),
    PCA.VAL,
    PCA.VALS,
    PCA.VALi,
    PCA.VALa,
    PCA.ValG, ValC,
    PCA.MAT,
    PCA.CODGEST,
    PCA.CODFORMATIE,
    PCA.COEF,
    PCA.MAN,
    PCA.VALMAN,
    PCA.CODCC,
    MAT.REST,
    ANLUNA_START - (C.AN*12 + C.LUNA),
    Round(CASE
            WHEN NVL(PCA.CANT, 0) = 0 THEN 0
            ELSE CASE WHEN TipValMatPC = 2 THEN (NVL(PCA.MAT, 0)+NVL(PCA.MAN, 0)+NVL(PCA.VALS, 0))/NVL(PCA.CANT, 0) ELSE (NVL(PCA.VAL, 0)+NVL(PCA.MAN, 0)+NVL(PCA.VALS, 0))/NVL(PCA.CANT, 0) END
          END,5),
    Round(CASE WHEN NVL(PCA.CANT, 0) = 0 THEN 0 ELSE NVL(PCA.MAT, 0)/NVL(PCA.CANT, 0) END,5),
    C1.CODOBIECT,
    PCA.PUNCTE,
    CC.Simbol,
    OBJ.DENUMIRE,
    Substr(IOA.DEN_IOART,1,50),
    Substr(UM.DEN_UM,1,15),
    OBJ1.PRETREFERINTA,
    PC.PRET,
    OBJ1.TIPPRET,
    OBJ.CODEXTERN,
    OBJ.CODINTERN,
    PCA.CODCMDPRODMAT,
    PCA.VALLINIE,
    PCA.VALTOT,
    C1.CONSUM
  FROM PCART PCA
       LEFT JOIN CMDPRODMAT MAT ON MAT.CODCMDPRODMAT = PCA.CODCMDPRODMAT
       LEFT JOIN COMANDA1 C1 ON MAT.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN COMANDA  C  ON C.CODCOMANDA = C1.CODCOMANDA
       INNER JOIN PCALCUL PCC ON PCC.CODPC = PCA.CODPC
       LEFT JOIN NGEST G ON G.CODGEST = PCA.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = PCA.CODCC
       LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
       LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = MAT.CODOBIECT
       LEFT JOIN NARTOBJ1 OBJ1 ON OBJ1.CODOBIECT = OBJ.CODOBIECT
       LEFT JOIN NART    ART ON OBJ.CODARTICOL = ART.CODARTICOL
       LEFT JOIN NUM UM ON UM.CODUM = ART.UM
       LEFT JOIN IOART IOA ON PCA.CODIOART = IOA.CODIOART
  WHERE PCA.CODPC = RECID AND PCC.AN*12+PCC.LUNA BETWEEN obj1.alstart AND obj1.alstop
        and (MAT.TIP = 0 and c1.consum = 1 or MAT.tip = 2 and c1.consum = 2);

  INSERT INTO TMP_PCDIR(
    CODPCDIR,
    CODPC,
    CODNEST,
    CODCMD1,
    VAL,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCD.CODPCDIR,
    PCD.CODPC,
    PCD.CODNEST,
    PCD.CODCMD1,
    PCD.VAL,
    DEBIT.CODCONT,
    CREDIT.CODCONT,
    CC.CODCENTRU,
    NS.CODGEST,
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCDIR PCD
       LEFT JOIN NESTJURNAL NS ON PCD.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCD.CODPC = RECID;

  INSERT INTO TMP_PCSECTII (
    CODPCSECTII,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC = RECID and PCS.FAZA = 0;

  INSERT INTO TMP_PCSECTII2 (
    CODPCSECTII2,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC = RECID and PCS.FAZA = 2;


  INSERT INTO TMP_PCSECTII3 (
    CODPCSECTII3,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC = RECID and PCS.FAZA = 3;

  INSERT INTO TMP_PCSECTII4 (
    CODPCSECTII4,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC = RECID and PCS.FAZA = 4;

  INSERT INTO TMP_PCSECTII5 (
    CODPCSECTII5,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC = RECID and PCS.FAZA = 5;

 delete from TMP_PCFIRMA_BUF;
 insert into TMP_PCFIRMA_BUF
   (Codnest, Val)
 select CodNest, Val  FROM
 (
   Select Toate.CodNest, Sum(Toate.Val) Val
     from (select PKG_Jurnal.GetCodNestJurnal(PKG_JURNAL.GETCONTFORJURNAL(J.CODDESCRD,
                                                                          J.ICONTD,
                                                                          J.TIPCONTD,
                                                                          &apos;&apos;,
                                                                          aAn,
                                                                          aLuna),
                                              PKG_JURNAL.GETCONTFORJURNAL(J.CODDESCRC,
                                                                          J.ICONTC,
                                                                          J.TIPCONTC,
                                                                          &apos;&apos;,
                                                                          aAn,
                                                                          aLuna),
                                              J.CodGest,
                                              J.CodCC) CodNest,
                  J.VAL
             from (select x.CodCmd1,
                          x.CODGEST,
                          x.CODCC,
                          x.CODDESCRD,
                          x.ICONTD,
                          x.TIPCONTD,
                          x.CODDESCRC,
                          x.ICONTC,
                          x.TIPCONTC,
                          Sum(x.VAL) Val
                     from ((select I.CODBAZAD CodCmd1,
                                   I.GEST CODGEST,
                                   I.CODCENTRU CODCC,
                                   I.CODDESCRD,
                                   I.ICONTD,
                                   I.TIPCONTD,
                                   I.CODDESCRC,
                                   I.ICONTC,
                                   I.TIPCONTC,
                                   Sum(I.VALOARE * Nvl(I.IContBazaD, 1)) VAL
                              from JURNAL1 I
                             where I.TIPBAZAD = 1200
                               AND TipDOC &lt;&gt; 71
                               AND TipDOC &lt;&gt; 72
                               AND I.An * 12 + I.Luna = AnLuna
                               AND I.SUBUNITATEA = Subunit
                             group by I.CODBAZAD,
                                      I.GEST,
                                      I.CODCENTRU,
                                      I.CODDESCRD,
                                      I.ICONTD,
                                      I.TIPCONTD,
                                      I.CODDESCRC,
                                      I.ICONTC,
                                      I.TIPCONTC) union all
                           (select I.CODBAZAD CodCmd1,
                                   I.GEST CODGEST,
                                   I.CODCENTRU CODCC,
                                   I.CODDESCRD,
                                   I.ICONTD,
                                   I.TIPCONTD,
                                   I.CODDESCRC,
                                   I.ICONTC,
                                   I.TIPCONTC,
                                   -Sum(I.VALOARE) VAL
                              from JURNAL1 I
                             where I.TIPBAZAD = 1200
                               AND TipDOC = 71
                               and CODDOC &gt; 0
                               AND I.An * 12 + I.Luna = AnLuna
                               AND I.SUBUNITATEA = Subunit
                             group by I.CODBAZAD,
                                      I.GEST,
                                      I.CODCENTRU,
                                      I.CODDESCRD,
                                      I.ICONTD,
                                      I.TIPCONTD,
                                      I.CODDESCRC,
                                      I.ICONTC,
                                      I.TIPCONTC) union all
                           (select I.CODBAZAD CodCmd1,
                                   I.GEST CODGEST,
                                   I.CODCENTRU CODCC,
                                   I.CODDESCRD,
                                   I.ICONTD,
                                   I.TIPCONTD,
                                   I.CODDESCRC,
                                   I.ICONTC,
                                   I.TIPCONTC,
                                   Sum(I.VALOARE) VAL
                              from JURNAL1 I
                             where I.TIPBAZAD = 1200
                               AND TipDOC = 71
                               and CODDOC &gt; 0
                               AND I.An * 12 + I.Luna = AnLuna - 1
                               AND I.SUBUNITATEA = Subunit
                             group by I.CODBAZAD,
                                      I.GEST,
                                      I.CODCENTRU,
                                      I.CODDESCRD,
                                      I.ICONTD,
                                      I.TIPCONTD,
                                      I.CODDESCRC,
                                      I.ICONTC,
                                      I.TIPCONTC) union all
                           (select CodCmd1,
                                   CODGEST,
                                   CODCC,
                                   ICODDESCRD CODDESCRD,
                                   IICONTD ICONTD,
                                   ITIPCONTD TIPCONTD,
                                   ICODDESCRC CODDESCRC,
                                   IICONTC ICONTC,
                                   ITIPCONTC TIPCONTC,
                                   VAL
                              from (select I.CODBAZAC CodCmd1,
                                           I.GEST CODGEST,
                                           I.CODCENTRU CODCC,
                                           I.CODDESCRD ICODDESCRC,
                                           I.ICONTD IICONTC,
                                           I.TIPCONTD ITIPCONTC,
                                           I.CODDESCRC ICODDESCRD,
                                           I.ICONTC IICONTD,
                                           I.TIPCONTC ITIPCONTD,
                                           -Sum(I.VALOARE) VAL
                                      from JURNAL1 I
                                     where I.TIPBAZAC = 1200
                                       AND TipDOC = 76
                                       AND I.An * 12 + I.Luna = AnLuna
                                       AND I.SUBUNITATEA = Subunit
                                     group by I.CODBAZAC,
                                              I.GEST,
                                              I.CODCENTRU,
                                              I.CODDESCRD,
                                              I.ICONTD,
                                              I.TIPCONTD,
                                              I.CODDESCRC,
                                              I.ICONTC,
                                              I.TIPCONTC))) x
                    group by x.CodCmd1,
                             x.CODGEST,
                             x.CODCC,
                             x.CODDESCRD,
                             x.ICONTD,
                             x.TIPCONTD,
                             x.CODDESCRC,
                             x.ICONTC,
                             x.TIPCONTC) J
            inner join Centrecost CC on CC.CodCentru = J.CodCC
            WHERE NVL(CC.TipAloc, 0) = 0
           union all
           select Z.CodNest, -Z.Val
             from TMP_PCDir Z inner join TMP_PCGEST G on G.CodGest = Z.CodGest
           union all
           select Z.CodNest, -Z.Val
             from TMP_PCSECTII Z inner join TMP_PCGEST G on G.CodGest = Z.CodGest
           union all
           select Z.CodNest, -Z.Val
             from TMP_PCSECTII2 Z inner join TMP_PCGEST G on G.CodGest = Z.CodGest
           union all
           select Z.CodNest, -Z.Val
             from TMP_PCSECTII3 Z inner join TMP_PCGEST G on G.CodGest = Z.CodGest
           union all
           select Z.CodNest, -Z.Val
             from TMP_PCSECTII5 Z inner join TMP_PCGEST G on G.CodGest = Z.CodGest

    ) Toate
    Group by Toate.CodNest)
  where Val &lt;&gt; 0;
/*
  INSERT INTO TMP_PCFIRMA (CODPCFIRMA, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT)
  SELECT
    ROWNUM,
    PCF.CODNEST,
    PCF.VAL,
    NS.CODCONTD,
    NS.CODCONTC,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM TMP_PCFIRMA_BUF PCF
       LEFT JOIN NESTJURNAL NS ON PCF.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT;
*/

  INSERT INTO TMP_PCFIRMA (CODPCFIRMA, VAL, CODCC, CODGEST, DENGEST, CENTRU)
  select RowNum, Cen.Val, Cen.CODCENTRU, Cen.CODGEST, Substr(G.DEN_GEST,1,30), CC.Simbol
  from ( SELECT NS.CODCENTRU,
                NS.CODGEST,
                Sum(PCF.VAL) Val
              FROM TMP_PCFIRMA_BUF PCF
                   LEFT JOIN NESTJURNAL NS ON PCF.CODNEST = NS.CODNESTJURNAL
              group by NS.CODCENTRU, NS.CODGEST
        ) Cen
       LEFT JOIN NGEST G ON G.CODGEST = Cen.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = Cen.CODCENTRU
  where Cen.Val &lt;&gt; 0;

--insert into xxx (x2,x3,x4) values(1, anluna, subunit);
  GET_PCSECTII_1( ANLuna, Subunit);
  INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 72 AND CODDOC = RECID);
  INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 72 AND CODDOC = RECID);
  DELETE TMP_RULAJ;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
aNest number(20);
aCod  number(20);
Nr    number(20);
BEGIN

  IF OPERATION = 0 THEN

    SELECT CODPC INTO RECID FROM TMP_PCALCUL;

    UPDATE PCALCUL
    SET (AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc,ValF) =
    (SELECT AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc ,ValF
     FROM TMP_PCALCUL)
     WHERE CODPC = RECID;

    DELETE FROM PCGEST WHERE CODPC = RECID AND CODPCGEST NOT IN (SELECT CODPCGEST FROM TMP_PCGEST);
    FOR V_REC IN (SELECT * FROM TMP_PCGEST) LOOP
      IF v_rec.codpcgest &gt; 0 then
        UPDATE PCGEST SET
          PUNCTE  = v_Rec.PUNCTE,
          MANS     = v_Rec.MANS   ,
          VALi     = v_Rec.VALi   ,
          VALa     = v_Rec.VALa   ,
          ValG     = v_Rec.ValG   ,
          ValC     = v_Rec.ValC   ,
          ValMat   = v_Rec.ValMat ,
          ValMan   = v_Rec.ValMan ,
          CODGEST  = v_Rec.CodGest,
          ValMatN  = v_Rec.ValMatN
        WHERE CODPCGEST = V_REC.CODPCGEST;
      else
        insert into pcgest (
          CODPCGEST, CODPC,
          PUNCTE, MANS,
          VALi, VALa, ValG, ValC, ValMat, ValMan, CODGEST, ValMatN )
        values (
          seq_pcgest_codpcgest.nextval, recid,
          v_Rec.PUNCTE, v_Rec.MANS,
          v_Rec.VALi, v_Rec.VALa, v_Rec.ValG, v_Rec.ValC, v_Rec.ValMat, v_Rec.ValMan, v_Rec.codgest,
          v_rec.ValMatN);
      end if;
    END LOOP;

    DELETE FROM PCART WHERE CODPC = RECID AND CODPCART NOT IN (SELECT CODPCART FROM TMP_PCART);
    FOR V_REC IN (SELECT * FROM TMP_PCART) LOOP
      IF v_rec.codpcart &gt; 0 then
        UPDATE PCART SET
          CODCMD1    = v_rec.codcmd1,
          CODGEST    = v_rec.CODGEST,
          CODFORMATIE=v_rec.CODFORMATIE,
          COEF       =v_rec.COEF,
          MAN        =v_rec.MAN,
          VALMAN     = v_rec.VALMAN,
          CODCC      = v_rec.CodCC,
          CODIOART   = v_rec.codioart,
          CANT       = v_Rec.Cant,
          CANTTOT    = v_Rec.CantTot,
          VAL        = v_rec.val,
          VALS       = v_rec.vals,
          VALi       = v_rec.VALi,
          VALa       = v_rec.VALa,
          ValG       = v_Rec.ValG   ,
          ValC       = v_Rec.ValC   ,
          PUNCTE     = v_rec.PUNCTE,
          MAT        = v_rec.MAT,
          CODCMDPRODMAT = V_REC.CODCMDPRODMAT,
          VALLINIE   = V_REC.VALLINIE,
          VALTOT     = V_REC.VALTOT
        WHERE CODPCART = V_REC.CODPCART;
      else
        insert into pcart (
        CODPCART   ,
        CODPC      ,
        CODCMD1    ,
        CODGEST    ,
        CODFORMATIE,
        COEF,
          MAN,
          VALMAN,
        CODCC      ,
        CODIOART   ,
        CANT       ,
        CANTTOT    ,
        VAL        ,
        VALS       ,
        VALi       ,
        VALa       ,
        ValG       ,
        ValC       ,
        PUNCTE     ,
        MAT,
        CODCMDPRODMAT,
        VALLINIE,
        VALTOT      )
        values (
          seq_pcart_codpcart.nextval,
          recid,
          v_rec.CODCMD1    ,
          v_rec.CODGEST    ,
          v_rec.CODFORMATIE,
          v_rec.COEF       ,
          v_rec.MAN        ,
          v_rec.VALMAN     ,
          v_rec.CODCC      ,
          v_rec.CODIOART   ,
          v_rec.CANT       ,
          v_rec.CANTTOT    ,
          v_rec.VAL        ,
          v_rec.VALS       ,
          v_rec.VALi       ,
          v_rec.VALa       ,
          v_rec.ValG,
          v_rec.ValC       ,
          v_rec.PUNCTE     ,
          v_rec.MAT        ,
          V_REC.CODCMDPRODMAT,
          V_REC.VALLINIE,
          V_REC.VALTOT);
      end if;
    END LOOP;

    DELETE FROM PCDIR WHERE CODPC = RECID AND CODPCDIR NOT IN (SELECT CODPCDIR FROM TMP_PCDIR);
    FOR V_REC IN (SELECT * FROM TMP_PCDIR) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;
      IF v_rec.codpcdir &gt; 0 then
        UPDATE PCDIR SET
          CODNEST   = anest,
          CODCMD1   = v_Rec.CodCMD1,
          VAL       = v_rec.val
        WHERE CODPCDIR = V_REC.CODPCDIR;
      else
        insert into pcdir (
          CODPCDIR,
          CODPC,
          CODNEST,
          CodCMD1,
          VAL )
        values (
          seq_pcdir_codpcdir.nextval,
          recid,
          aNEST,
          v_rec.CodCMD1,
          v_rec.VAL);
      end if;
    END LOOP;

    DELETE FROM PCSECTII WHERE CODPC = RECID AND CODPCSECTII NOT IN ( SELECT CODPCSECTII FROM TMP_PCSECTII
                                                                      union all
                                                                      SELECT CODPCSECTII2 as CODPCSECTII FROM TMP_PCSECTII2
                                                                      union all
                                                                      SELECT CODPCSECTII3 as CODPCSECTII FROM TMP_PCSECTII3
                                                                      union all
                                                                      SELECT CODPCSECTII5 as CODPCSECTII FROM TMP_PCSECTII5
                                                                      union all
                                                                      SELECT CODPCSECTII4 as CODPCSECTII FROM TMP_PCSECTII4
                                                                    );
    FOR V_REC IN (SELECT * FROM TMP_PCSECTII) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;

      IF v_rec.codpcsectii &gt; 0 then
        UPDATE PCSECTII SET
          CODNEST = anest,
          FAZA    = 0,
          VAL     = v_rec.val
        WHERE CODPCSECTII = V_REC.CODPCSECTII;
      else
        insert into pcsectii (
          CODPCSECTII,
          CODPC,
          CODNEST,
          FAZA,
          VAL )
        values (seq_pcsectii_codpcsectii.nextval, recid, anest, 0, v_Rec.val);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PCSECTII2) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;

      IF v_rec.codpcsectii2 &gt; 0 then
        UPDATE PCSECTII SET
          CODNEST = anest,
          FAZA    = 2,
          VAL     = v_rec.val
        WHERE CODPCSECTII = V_REC.CODPCSECTII2;
      else
        insert into pcsectii (
          CODPCSECTII,
          CODPC,
          CODNEST,
          FAZA,
          VAL )
        values (seq_pcsectii_codpcsectii.nextval, recid, anest, 2, v_Rec.val);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PCSECTII3) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;

      IF v_rec.codpcsectii3 &gt; 0 then
        UPDATE PCSECTII SET
          CODNEST = anest,
          FAZA    = 3,
          VAL     = v_rec.val
        WHERE CODPCSECTII = V_REC.CODPCSECTII3;
      else
        insert into pcsectii (
          CODPCSECTII,
          CODPC,
          CODNEST,
          FAZA,
          VAL )
        values (seq_pcsectii_codpcsectii.nextval, recid, anest, 3, v_Rec.val);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PCSECTII4) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;

      IF v_rec.codpcsectii4 &gt; 0 then
        UPDATE PCSECTII SET
          CODNEST = anest,
          FAZA    = 4,
          VAL     = v_rec.val
        WHERE CODPCSECTII = V_REC.CODPCSECTII4;
      else
        insert into pcsectii (
          CODPCSECTII,
          CODPC,
          CODNEST,
          FAZA,
          VAL )
        values (seq_pcsectii_codpcsectii.nextval, recid, anest, 4, v_Rec.val);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_PCSECTII5) LOOP
      aNEst := Nvl(v_Rec.Codnest, 0);
      if aNest = 0 then aNest := PKG_Jurnal.GetCodNestJurnal(v_rec.CodD, v_rec.CodC, v_rec.CodGest, v_rec.CodCC); end if;

      IF v_rec.codpcsectii5 &gt; 0 then
        UPDATE PCSECTII SET
          CODNEST = anest,
          FAZA    = 5,
          VAL     = v_rec.val
        WHERE CODPCSECTII = V_REC.CODPCSECTII5;
      else
        insert into pcsectii (
          CODPCSECTII,
          CODPC,
          CODNEST,
          FAZA,
          VAL )
        values (seq_pcsectii_codpcsectii.nextval, recid, anest, 5, v_Rec.val);
      end if;
    END LOOP;
-- detail JURNAlL1
    DELETE FROM JURNAl1 WHERE TIPDOC = 72 AND CODDOC = RECID AND CODJURNAL1 NOT IN
    (SELECT CODJURNAL1 FROM TMP_JURNAl1);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
     IF V_REC.CODJURNAL1 &gt; 0 THEN
      UPDATE JURNAL1
      SET
        CODDOC       = V_REC.CODDOC,
        TIPDOC       = V_REC.TIPDOC,
        INDEXLOCAL   = V_REC.INDEXLOCAL,

        CODBAZAD     = V_REC.CODBAZAD,
        ICONTBAZAD   = V_REC.ICONTBAZAD,
        TIPBAZAD     = V_REC.TIPBAZAD,
        CODBAZAC     = V_REC.CODBAZAC,
        ICONTBAZAC   = V_REC.ICONTBAZAC,
        TIPBAZAC     = V_REC.TIPBAZAC,

        CODDESCRD     = V_REC.CODDESCRD,
        ICONTD        = V_REC.ICONTD,
        TIPCONTD      = V_REC.TIPCONTD,
        ANALITICCONTD = V_REC.ANALITICCONTD,
        CODDESCRC     = V_REC.CODDESCRC,
        ICONTC        = V_REC.ICONTC,
        TIPCONTC      = V_REC.TIPCONTC,
        ANALITICCONTC = V_REC.ANALITICCONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        DIRTY         = V_REC.DIRTY,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        CODCENTRU     = V_REC.CODCENTRU,
        DATADOC       = V_REC.DATADOC,
        DOCUMENT      = V_REC.DOCUMENT
      WHERE
        CODJURNAL1 = V_REC.CODJURNAl1;
     ELSE
       INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
       VALUES
       (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
     END IF;
    END LOOP;



    -- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 72 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC,
        INDEXLOCAL = V_REC.INDEXLOCAL,
        CONTD      = V_REC.CONTD,
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE,
        VALOAREV   = V_REC.VALOAREV,
        OBS        = V_REC.OBS,
        AN         = V_REC.AN,
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = V_REC.CODCENTRU,
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT
      WHERE
        CODJURNAL = V_REC.CODJURNAl;
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT);
     END IF;
    END LOOP;

  ELSE -- INSERT

  SELECT SEQ_pcalcul_CODPC.NEXTVAL INTO RECID FROM DUAL;

  INSERT INTO PCALCUL (CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc,ValF)
  SELECT RECID,AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc,ValF FROM TMP_PCALCUL;

  insert into pcgest (
    CODPCGEST, CODPC,
    PUNCTE, MANS,
    VALi, VALa, ValG, ValC, ValMat, ValMan, CODGEST, ValMatN )
  SELECT
    seq_pcgest_codpcgest.nextval,
    recid,
    PUNCTE, MANS,
    VALi, VALa, ValG, ValC, ValMat, ValMan, CODGEST, ValMatN
  FROM TMP_PCGEST;

  insert into pcart (
  CODPCART   ,
  CODPC      ,
  CODCMD1    ,
  CODGEST    ,
  CODFORMATIE,
  COEF,
  MAN,
  VALMAN,
  CODCC      ,
  CODIOART   ,
  CANT       ,
  CANTTOT    ,
  VAL        ,
  VALi, VALa,
  VALS       ,
  ValG, ValC       ,
  PUNCTE     ,
  MAT,
  CODCMDPRODMAT,
  VALLINIE,
  VALTOT)
  SELECT
    seq_pcart_codpcart.nextval,
    recid,
    CODCMD1    ,
    CODGEST    ,
    CODFORMATIE,
    COEF       ,
    MAN,
    VALMAN,
    CODCC      ,
    CODIOART   ,
    CANT       ,
    CANTTOT    ,
    VAL        ,
    VALi, VALa,
    VALS       ,
    ValG, ValC       ,
    PUNCTE     ,
    MAT,
    CODCMDPRODMAT,
    VALLINIE,
    VALTOT
  FROM TMP_PCART;

  insert into pcdir (
    CODPCDIR,
    CODPC,
    CODNEST,
    CodCMD1,
    VAL )
  SELECT
    seq_pcdir_codpcdir.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    CodCMD1,
    VAL
  FROM TMP_PCDIR;

  insert into pcsectii (
    CODPCSECTII,
    CODPC,
    CODNEST,
    FAZA, VAL )
  SELECT
    seq_pcsectii_codpcsectii.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    0, val
  FROM TMP_PCSECTII;

  insert into pcsectii (
    CODPCSECTII,
    CODPC,
    CODNEST,
    FAZA, VAL )
  SELECT
    seq_pcsectii_codpcsectii.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    2, val
  FROM TMP_PCSECTII2;

  insert into pcsectii (
    CODPCSECTII,
    CODPC,
    CODNEST,
    FAZA, VAL )
  SELECT
    seq_pcsectii_codpcsectii.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    3, val
  FROM TMP_PCSECTII3;

  insert into pcsectii (
    CODPCSECTII,
    CODPC,
    CODNEST,
    FAZA, VAL )
  SELECT
    seq_pcsectii_codpcsectii.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    4, val
  FROM TMP_PCSECTII4;

  insert into pcsectii (
    CODPCSECTII,
    CODPC,
    CODNEST,
    FAZA, VAL )
  SELECT
    seq_pcsectii_codpcsectii.nextval,
    recid,
    PKG_Jurnal.GetCodNestJurnal(CodD, CodC, CodGest, CodCC),
    5, val
  FROM TMP_PCSECTII5;

  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT )
  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC,DOCUMENT FROM TMP_JURNAL1);
  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT)
  (SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT FROM TMP_JURNAL);

 END IF;

 -- ACTUALIZARE RULAJE CONTURI
 FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;

     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
     WHERE
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;

         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;

  END LOOP;

  PKG_GLOBALS.MarkDirtyJurnal;

  NotifyModif(Operation, RecId, &apos;PCALCUL&apos;);

COMMIT;
EXCEPTION WHEN OTHERS THEN
  ROLLBACK;
  RAISE;
END;

FUNCTION UpdateFinala(aCodPC IN NUMBER, aOperat IN NUMBER) return Boolean is pragma autonomous_transaction;
Done BOOLEAN;
begin
  begin
    update PCALCUL set OPERAT = aOperat where codPC = aCodPC;
    commit;
    Done := True;
  exception when others then
    Done := False;
  end;

  Return Done;
end;

end pkg_postcalcul;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_POSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>327C98A8A01DE9E8BDBE9DD75F0E545E21D8F0D3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_POSTRETAIL IS


PROCEDURE CHECKINACTIVARI_ART(aCODPOSTRETAIL IN NUMBER)
IS  
BEGIN
  FOR V_REC IN (SELECT * FROM INACTIVRETAIL WHERE CODPOSTRETAIL = aCODPOSTRETAIL)
  LOOP
    UPDATE NARTOBJ
    SET
      INACTIV = 1
    WHERE
      CODOBIECT = V_REC.CODOBIECT;  
  END LOOP;     
END;  

PROCEDURE MEMO_MODIF_PROMO_RETAIL(aCODPROMO IN NUMBER, aTIPMODIF IN NUMBER)
IS
BEGIN
  FOR V_REC IN (SELECT COD FROM POSTRETAIL)
  LOOP
    INSERT INTO SYNCPROMORETAIL(CODSYNCPROMO, CODPROMO, CODPOSTRETAIL,SINCRONIZAT, DATA, TIPMODIF)
    VALUES (SEQ_SYNCPROMORETAIL_CODSYNC.NEXTVAL, aCODPROMO, V_REC.COD, 0, SYSDATE, aTIPMODIF);
  END LOOP;     
END;    

PROCEDURE GETSINTEZASTOC
IS
aCODNIR NUMBER;
BEGIN
  DELETE NIRSTOC;
  DELETE NIR;
  FOR V_REC_N IN (SELECT DISTINCT CODGESTPROD FROM TMP_NIRSTOC_MAN)
  LOOP
    aCODNIR := SEQ_NIR_CODNIR.NEXTVAL;
    INSERT INTO NIR(CODNIR, GEST, OPERAT)
    VALUES (aCODNIR, V_REC_N.CODGESTPROD, 1);
    FOR V_REC_NS IN (SELECT * FROM TMP_NIRSTOC_MAN WHERE CODGESTPROD = V_REC_N.CODGESTPROD)
    LOOP
      INSERT INTO NIRSTOC(CODNIRSTOC, CODNIR, CODOBIECT, CODIOART, REST)
      VALUES(SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL, aCODNIR, V_REC_NS.CODOBIECT, V_REC_NS.CODIOART, V_REC_NS.REST);
    END LOOP;    
  END LOOP;    
END;    

PROCEDURE CHECKFUZIONARIPART
IS
  CODSEDIU_R_OLD NUMBER;
  CODSEDIU_R_NEW NUMBER;
BEGIN

  FOR V_REC IN -- fuzionare parteneri
  (  
  SELECT  
    F.CODPARTINIT AS CODPART_OLD,
    F.CODPARTFIN AS CODPART_NEW
  FROM
   TMP_FUZPART F
  WHERE
    CODPARTINIT &lt;&gt; CODPARTFIN 
  )
  LOOP

    UPDATE EMULARE
    SET
     CODPART = V_REC.CODPART_NEW
    WHERE
      CODPART = V_REC.CODPART_OLD;

    UPDATE RESTNP
    SET
     CODPART = V_REC.CODPART_NEW
    WHERE
      CODPART = V_REC.CODPART_OLD;

    UPDATE IESIRI
    SET
      PARTENER = V_REC.CODPART_NEW
    WHERE
      PARTENER = V_REC.CODPART_OLD;


    DELETE FROM NPART1 WHERE CODPART = V_REC.CODPART_OLD; 
    DELETE FROM NPART  WHERE CODPART = V_REC.CODPART_OLD; 
    DELETE FROM NPARTRETAIL WHERE CODPART = V_REC.CODPART_OLD; 

  END LOOP;


  FOR V_REC IN -- fuzionare sedii
  (  
  SELECT  
    F.CODLOCINIT AS CODLOCATIE_OLD,
    F.CODLOCFIN AS CODLOCATIE_NEW
  FROM
   TMP_FUZPART F
  WHERE
    CODPARTINIT = CODPARTFIN 
    AND COALESCE(CODLOCINIT, 0) &lt;&gt; COALESCE(CODLOCFIN, 0)
    AND COALESCE(CODLOCINIT, 0) &gt; 0
  ORDER BY DATA  
  )
  LOOP

    UPDATE EMULARE
    SET
     CODLOCATIE = V_REC.CODLOCATIE_NEW
    WHERE
      CODLOCATIE = V_REC.CODLOCATIE_OLD;


    UPDATE IESIRI
    SET
      CODLOCATIE = V_REC.CODLOCATIE_NEW
    WHERE
      CODLOCATIE = V_REC.CODLOCATIE_OLD;

    BEGIN
      SELECT MIN(CODSEDIU) INTO CODSEDIU_R_OLD FROM NSEDIIPARTRETAIL  WHERE CODAGENDA = v_rec.codlocatie_old;
      EXCEPTION WHEN OTHERS THEN CODSEDIU_R_OLD := 0;
    END;
       
    BEGIN
      SELECT MIN(CODSEDIU) INTO CODSEDIU_R_NEW FROM NSEDIIPARTRETAIL  WHERE CODAGENDA = v_rec.codlocatie_new;
      EXCEPTION WHEN OTHERS THEN CODSEDIU_R_NEW := 0;
    END;
      
    IF COALESCE(CODSEDIU_R_OLD, 0) &lt;&gt; 0 AND COALESCE(CODSEDIU_R_NEW, 0) &lt;&gt; 0 THEN
      UPDATE EMULARE
      SET
       codsediuretail = CODSEDIU_R_NEW
      WHERE
        codsediuretail = CODSEDIU_R_OLD;

      UPDATE IESIRIRETAIL
      SET
       codsediuretail = CODSEDIU_R_NEW
      WHERE
        codsediuretail = CODSEDIU_R_OLD;

      
    END IF;
    


    DELETE FROM NSEDIIPARTRETAIL
    WHERE
      CODAGENDA =  V_REC.CODLOCATIE_OLD; 

    DELETE FROM NAGENDA
    WHERE
      CODAGENDA =  V_REC.CODLOCATIE_OLD; 


  END LOOP;

-- stergeri manuale pe baza, care nu provin din fuzionari
  FOR V_REC IN (SELECT * FROM NSEDIIPARTRETAIL WHERE COALESCE(CODAGENDA, 0) &gt; 0 AND COALESCE(CODAGENDA, 0) NOT IN (SELECT CODAGENDA FROM NAGENDA))
  LOOP
    UPDATE IESIRIRETAIL 
    SET 
      codsediuretail = NULL
    WHERE
      codsediuretail = V_REC.CODSEDIU;  

    UPDATE EMULARE 
    SET 
      codsediuretail = NULL
    WHERE
      codsediuretail = V_REC.CODSEDIU;  
    
    DELETE FROM NSEDIIPARTRETAIL
    WHERE
      CODSEDIU = V_REC.CODSEDIU;

  END LOOP;   
  
  -- curata incoerente;
   FOR V_REC IN (SELECT SP.* FROM NSEDIIPARTRETAIL SP INNER JOIN NPARTRETAIL P ON P.CODPARTRETAIL = SP.CODPARTRETAIL AND P.TIPMODIF IS NULL AND SP.CODAGENDA IS NULL)
   LOOP
      UPDATE IESIRIRETAIL 
      SET 
        codsediuretail = NULL
      WHERE
        codsediuretail = V_REC.CODSEDIU;  

      UPDATE EMULARE 
      SET 
        codsediuretail = NULL
      WHERE
        codsediuretail = V_REC.CODSEDIU;  

    DELETE FROM NSEDIIPARTRETAIL
    WHERE
      CODSEDIU = V_REC.CODSEDIU;
   END LOOP;    
  

   FOR V_REC IN (SELECT SP.* FROM NSEDIIPARTRETAIL SP WHERE codpartretail not in (select CODPARTRETAIL FROM NPARTRETAIL ) )
   LOOP
      UPDATE IESIRIRETAIL 
      SET 
        codsediuretail = NULL
      WHERE
        codsediuretail = V_REC.CODSEDIU;  

      UPDATE EMULARE 
      SET 
        codsediuretail = NULL
      WHERE
        codsediuretail = V_REC.CODSEDIU;  

      DELETE FROM NCODFISCRETAIL
      WHERE
        codPartRetail = V_REC.CODPARTRETAIL;  


    DELETE FROM NSEDIIPARTRETAIL
    WHERE
      CODSEDIU = V_REC.CODSEDIU;
   END LOOP;    

   for v_rec in (select * from npartretail where codpart is not null and codpart not in (select codpart from npart))
   loop  
      UPDATE IESIRIRETAIL 
      SET 
        codpartretail = NULL
      WHERE
        codPartRetail = V_REC.CODPARTRETAIL;  

      UPDATE EMULARE 
      SET 
        codpartretail = NULL
      WHERE
        codPartRetail = V_REC.CODPARTRETAIL;  
  

      DELETE FROM NCODFISCRETAIL
      WHERE
        codPartRetail = V_REC.CODPARTRETAIL;  
  

      DELETE FROM NPARTRETAIL
      WHERE
        codPartRetail = V_REC.CODPARTRETAIL;  
   end loop;

  COMMIT;  

END;


PROCEDURE PREIA_SINTEZA_EMULARE(aCODPOSTRETAIL IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
-- stergeri remote

  FOR V_REC IN 
  (SELECT CODSINTEZA 
   FROM 
     SINTEZAEMULARE S,
     TMP_EMULARE E
   WHERE
     S.CODPOSTRETAIL = aCODPOSTRETAIL
     AND S.CODEMULARE = E.CODEMULARE
  )
  LOOP
    DELETE FROM SINTEZAEMULARE2 WHERE CODSINTEZA = V_REC.CODSINTEZA;
    DELETE FROM SINTEZAEMULARE1 WHERE CODSINTEZA = V_REC.CODSINTEZA;
    DELETE FROM SINTEZAEMULARE  WHERE CODSINTEZA = V_REC.CODSINTEZA;
  END LOOP;  
       
   
  

  MERGE INTO SINTEZAEMULARE SE
  USING (
  SELECT E.* 
     FROM EMULARERETAIL E WHERE E.CODPOSTRETAIL = aCODPOSTRETAIL
   ) ER
  ON (SE.CODEMULARE = ER.CODEMULARE AND SE.CODPOSTRETAIL = ER.CODPOSTRETAIL) 
  WHEN 
    NOT MATCHED THEN
    INSERT (CODSINTEZA,     
            CODEMULARE,     
            NRBON,          
            DATABON,        
            VALOARE,        
            VALOAREDISCOUNT,
            LISTAT,         
            PRELUAT,        
            CODCASAMARCAT,  
            TVATOTAL,       
            TVADISCOUNT,    
            DATACREARE,     
            DATALISTARE,    
            CODIES,         
            CODPART,        
            CODPERS,        
            CODPOSTRETAIL,  
            CODLOCATIE,     
            CODAGENT,       
            OBS,            
            IDBON,          
            DELEGAT
          )
      VALUES (SEQ_SINTEZAEMULARE_CODSINTEZA.NEXTVAL,
              ER.CODEMULARE,     
              ER.NRBON,          
              ER.DATABON,        
              ER.VALOARE,        
              ER.VALOAREDISCOUNT,
              ER.LISTAT,         
              ER.PRELUAT,        
              ER.CODCASAMARCAT,  
              ER.TVATOTAL,       
              ER.TVADISCOUNT,    
              ER.DATACREARE,     
              ER.DATALISTARE,    
              ER.CODIES,         
              ER.CODPART,        
              ER.CODPERS,        
              ER.CODPOSTRETAIL,  
              ER.CODLOCATIE,     
              ER.CODAGENT,       
              ER.OBS,            
              ER.IDBON,          
              ER.DELEGAT
          )
  WHEN 
  MATCHED THEN
  UPDATE 
  SET
     NRBON            = ER.NRBON,          
     DATABON          = ER.DATABON,                  
     VALOARE          = ER.VALOARE,        
     VALOAREDISCOUNT  = ER.VALOAREDISCOUNT,
     LISTAT           = ER.LISTAT,         
     PRELUAT          = ER.PRELUAT,        
     CODCASAMARCAT    = ER.CODCASAMARCAT,  
     TVATOTAL         = ER.TVATOTAL,       
     TVADISCOUNT      = ER.TVADISCOUNT,    
     DATACREARE       = ER.DATACREARE,     
     DATALISTARE      = ER.DATALISTARE,    
     CODIES           = ER.CODIES,         
     CODPART          = ER.CODPART,        
     CODPERS          = ER.CODPERS,        
     CODLOCATIE       = ER.CODLOCATIE,     
     CODAGENT         = ER.CODAGENT,       
     OBS              = ER.OBS,            
     IDBON            = ER.IDBON,          
     DELEGAT          = DELEGAT;
     
   MERGE INTO SINTEZAEMULARE1 SE1
   USING (SELECT E1.*, S.CODSINTEZA , E.CODPOSTRETAIL AS CODPOST_RETAIL
          FROM
            EMULARE1RETAIL E1,
            EMULARERETAIL E,
            SINTEZAEMULARE S
          WHERE
            E.CODPOSTRETAIL  = aCODPOSTRETAIL
            AND E.CODEMULARE = E1.CODEMULARE
            AND E1.CODPOSTRETAIL = aCODPOSTRETAIL
            AND S.CODEMULARE = E.CODEMULARE
            AND S.CODPOSTRETAIL = E.CODPOSTRETAIL
          ) ER1
   ON (SE1.CODEMULARE1 = ER1.CODEMULARE1 AND SE1.CODPOSTRETAIL = ER1.CODPOST_RETAIL)
   WHEN NOT MATCHED THEN
   INSERT 
   (CODSINTEZA1,   
    CODSINTEZA,    
    CODEMULARE1,   
    CODPOSTRETAIL, 
    CODOBIECT,     
    INDEXLOCAL,    
    PRETART,       
    PRET,          
    CANT,          
    UMSEC,         
    DISCOUNT,      
    TVA,           
    TIPLINIE,      
    CONTSERV,      
    CADOU,         
    PRETPROMO     
   )
   VALUES
   (SEQ_SINTEZAEMUL1_CODSINTEZA1.NEXTVAL,   
    ER1.CODSINTEZA,    
    ER1.CODEMULARE1,   
    ER1.CODPOSTRETAIL, 
    ER1.CODOBIECT,     
    ER1.INDEXLOCAL,    
    ER1.PRETART,       
    ER1.PRET,          
    ER1.CANT,          
    ER1.UMSEC,         
    ER1.DISCOUNT,      
    ER1.TVA,           
    ER1.TIPLINIE,      
    ER1.CONTSERV,      
    ER1.CADOU,         
    ER1.PRETPROMO     
   )
 WHEN MATCHED THEN
 UPDATE
 SET
    CODOBIECT       = ER1.CODOBIECT,    
    INDEXLOCAL      = ER1.INDEXLOCAL,   
    PRETART         = ER1.PRETART,         
    PRET            = ER1.PRET,         
    CANT            = ER1.CANT,         
    UMSEC           = ER1.UMSEC,        
    DISCOUNT        = ER1.DISCOUNT,     
    TVA             = ER1.TVA,          
    TIPLINIE        = ER1.TIPLINIE,     
    CONTSERV        = ER1.CONTSERV,     
    CADOU           = ER1.CADOU,        
    PRETPROMO       = ER1.PRETPROMO;
     

FOR V_REC IN 
(  
    SELECT * FROM
    (
    SELECT 
      S.CODSINTEZA,
      ER.CODEMULARE,
      S1.CODSINTEZA1,
      ER1.CODEMULARE1
    FROM
      EMULARERETAIL ER,
      SINTEZAEMULARE S,
      SINTEZAEMULARE1 S1
      LEFT JOIN EMULARE1RETAIL ER1 ON ER1.CODEMULARE1  = S1.CODEMULARE1 AND ER1.CODPOSTRETAIL = aCODPOSTRETAIL
    WHERE
      ER.CODEMULARE = S.CODEMULARE
      AND ER.CODPOSTRETAIL = aCODPOSTRETAIL
      AND S.CODPOSTRETAIL = aCODPOSTRETAIL
      AND S1.CODSINTEZA = S.CODSINTEZA
    )  
    WHERE
      CODEMULARE1 IS NULL
)
LOOP
  DELETE FROM SINTEZAEMULARE1 WHERE CODSINTEZA1 = V_REC.CODSINTEZA1;
END LOOP  ;



   MERGE INTO SINTEZAEMULARE2 SE2
   USING (SELECT E2.*, S.CODSINTEZA , E.CODPOSTRETAIL AS CODPOST_RETAIL
          FROM
            EMULARE2RETAIL E2,
            EMULARERETAIL E,
            SINTEZAEMULARE S
          WHERE
            E.CODPOSTRETAIL = aCODPOSTRETAIL
            AND E.CODEMULARE = E2.CODEMULARE
            AND S.CODEMULARE = E.CODEMULARE
            AND S.CODPOSTRETAIL = E.CODPOSTRETAIL
          ) ER2
   ON (SE2.CODEMULARE2 = ER2.CODEMULARE2 AND SE2.CODPOSTRETAIL = ER2.CODPOST_RETAIL)
   WHEN NOT MATCHED THEN
   INSERT(CODSINTEZA2,   
          CODSINTEZA,    
          CODEMULARE2,   
          CODPOSTRETAIL, 
          TIPPLATA,      
          VALOARE,       
          DENUMIRE,      
          CODBANKCONT)
   VALUES(SEQ_SINTEZAEMUL2_CODSINTEZA2.NEXTVAL,   
          ER2.CODSINTEZA,    
          ER2.CODEMULARE2,   
          ER2.CODPOSTRETAIL, 
          ER2.TIPPLATA,      
          ER2.VALOARE,       
          ER2.DENUMIRE,      
          ER2.CODBANKCONT)
   WHEN MATCHED THEN       
   UPDATE
   SET
     TIPPLATA    =  ER2.TIPPLATA,   
     VALOARE     =  ER2.VALOARE,              
     DENUMIRE    =  ER2.DENUMIRE,          
     CODBANKCONT =  ER2.CODBANKCONT;
     
     
  COMMIT;
END;


PROCEDURE PREPARE_GENMONETARE_RETAIL(aCODSUBUNIT IN NUMBER)
IS
BEGIN
  DELETE TMP_GENMONETARERETAIL;
  INSERT INTO TMP_GENMONETARERETAIL(CODPOSTRETAIL, CARNETDOC, CARNETLIVR, CARNETCMD, CARNETNP, CARNETBC, CARNETNIR, CONTINTERMED, CONTCASH, CONTCEC, CONTCARD, CONTTICHET, DESCARCAREPROD, DENUMIRE, ID, NUMEFIRMA, SUBUNITATEA, DEN_SUBUNIT)
  SELECT 
      G.CODPOSTRETAIL, 
      G.CARNETDOC, 
      G.CARNETLIVR, 
      G.CARNETCMD, 
      G.CARNETNP, 
      G.CARNETBC, 
      G.CARNETNIR, 
      G.CONTINTERMED, 
      G.CONTCASH, 
      G.CONTCEC, 
      G.CONTCARD, 
      G.CONTTICHET, 
      G.DESCARCAREPROD,
      R.DENUMIRE, 
      R.ID, 
      R.NUMEFIRMA, 
      R.SUBUNITATEA, 
      S.DEN_SUBUNIT
  FROM    
    GENMONETARERETAIL G,
    POSTRETAIL R,
    NSUBUNIT S
  WHERE
    G.CODPOSTRETAIL = R.COD
    AND R.SUBUNITATEA = S.CODSUBUNIT;  
    

   FOR V_REC IN  (SELECT R.*, S.DEN_SUBUNIT 
                 FROM 
                   POSTRETAIL R, 
                   NSUBUNIT S 
                 WHERE 
                   R.COD NOT IN (SELECT CODPOSTRETAIL FROM TMP_GENMONETARERETAIL)
                   AND R.SUBUNITATEA = S.CODSUBUNIT
                 )  
                 
  LOOP
    INSERT INTO TMP_GENMONETARERETAIL(CODPOSTRETAIL, 
                                      DENUMIRE, 
                                      ID, 
                                      NUMEFIRMA, 
                                      SUBUNITATEA, 
                                      DEN_SUBUNIT)
    VALUES (V_REC.COD, 
            V_REC.DENUMIRE, 
            V_REC.ID, 
            V_REC.NUMEFIRMA, 
            V_REC.SUBUNITATEA, 
            V_REC.DEN_SUBUNIT
           );
  END LOOP;  
  COMMIT;
END;    


PROCEDURE POST_MONETARE_RETAIL
IS
BEGIN
  DELETE FROM GENMONETARERETAIL
  WHERE
    CODPOSTRETAIL NOT IN (SELECT CODPOSTRETAIL FROM TMP_GENMONETARERETAIL);
    
  FOR V_REC IN (SELECT * FROM TMP_GENMONETARERETAIL)
  LOOP
    UPDATE GENMONETARERETAIL
    SET
    ( CARNETDOC,       
      CARNETLIVR,      
      CARNETCMD,       
      CARNETNP,        
      CARNETBC,        
      CARNETNIR,       
      CONTINTERMED,    
      CONTCASH,        
      CONTCEC,         
      CONTCARD,        
      CONTTICHET,
      DESCARCAREPROD
    )= 
    (SELECT  
       V_REC.CARNETDOC,       
       V_REC.CARNETLIVR,      
       V_REC.CARNETCMD,       
       V_REC.CARNETNP,        
       V_REC.CARNETBC,        
       V_REC.CARNETNIR,       
       V_REC.CONTINTERMED,    
       V_REC.CONTCASH,        
       V_REC.CONTCEC,         
       V_REC.CONTCARD,        
       V_REC.CONTTICHET,
       V_REC.DESCARCAREPROD
     FROM
        DUAL
    )
   WHERE
     CODPOSTRETAIL = V_REC.CODPOSTRETAIL;
     
	IF SQL%ROWCOUNT = 0 then
		INSERT  INTO GENMONETARERETAIL 
                ( CODPOSTRETAIL,
                  CARNETDOC,       
                  CARNETLIVR,      
                  CARNETCMD,       
                  CARNETNP,        
                  CARNETBC,        
                  CARNETNIR,       
                  CONTINTERMED,    
                  CONTCASH,        
                  CONTCEC,         
                  CONTCARD,        
                  CONTTICHET,
                  DESCARCAREPROD
                )
                VALUES 
                ( V_REC.CODPOSTRETAIL,
                  V_REC.CARNETDOC,       
                  V_REC.CARNETLIVR,      
                  V_REC.CARNETCMD,       
                  V_REC.CARNETNP,        
                  V_REC.CARNETBC,        
                  V_REC.CARNETNIR,       
                  V_REC.CONTINTERMED,    
                  V_REC.CONTCASH,        
                  V_REC.CONTCEC,         
                  V_REC.CONTCARD,        
                  V_REC.CONTTICHET,
                  V_REC.DESCARCAREPROD
                );
	END IF;
    
    
    
    
            
  END LOOP;    
  
  COMMIT;
END;    


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT COD INTO Tmp FROM POSTRETAIL WHERE COD = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  
  DELETE FROM INACTIVRETAIL WHERE CODPOSTRETAIL = RECID;
  
  DELETE POSTRETAIL WHERE COD = RecId;
  
  NotifyModif(2, RecId, &apos;POSTRETAIL&apos;);
  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_POSTRETAIL FIELDS( COD ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER)
IS
BEGIN
  INSERT INTO TMP_POSTRETAIL SELECT * FROM POSTRETAIL WHERE COD = RECID;
  INSERT INTO TMP_INACTIVRETAIL(CODINACTIVRETAIL, CODOBIECT, CODPOSTRETAIL, DENUMIRE)
  SELECT  CODINACTIVRETAIL, I.CODOBIECT, CODPOSTRETAIL, DENUMIRE
  FROM 
    INACTIVRETAIL I
    INNER JOIN NARTOBJ O ON O.CODOBIECT = I.CODOBIECT
  WHERE
    CODPOSTRETAIL = RecId;  
  
  
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER)
IS
BEGIN
  IF Operation = 0 THEN
    SELECT COD INTO RecId FROM TMP_POSTRETAIL;
    UPDATE POSTRETAIL SET (DENUMIRE, ID,NUMEFIRMA, SUBUNITATEA) = (SELECT DENUMIRE, ID, NUMEFIRMA, SUBUNITATEA FROM TMP_POSTRETAIL)
    WHERE
      COD = RECID;
      
    DELETE FROM INACTIVRETAIL 
     WHERE 
       CODPOSTRETAIL = RECID
       AND CODOBIECT NOT IN (SELECT CODOBIECT FROM TMP_INACTIVRETAIL);
 

  FOR V_REC IN (SELECT * FROM TMP_INACTIVRETAIL)
   LOOP
    
     IF V_REC.CODINACTIVRETAIL &lt; 0 THEN
       INSERT INTO INACTIVRETAIL (CODINACTIVRETAIL, CODOBIECT, CODPOSTRETAIL)
       VALUES(SEQ_INACTIVRETAIL_CODINACTIV.NEXTVAL, V_REC.CODOBIECT, V_REC.CODPOSTRETAIL);
     ELSE
       UPDATE INACTIVRETAIL
       SET
         CODOBIECT = V_REC.CODOBIECT
       WHERE
         CODINACTIVRETAIL = V_REC.CODINACTIVRETAIL;  
     END IF;     
   END LOOP;       
      
      
  ELSE
    SELECT SEQ_POSTRETAIL_COD.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO POSTRETAIL(COD, DENUMIRE, ID, NUMEFIRMA, SUBUNITATEA)
    SELECT RECID, DENUMIRE, ID, NUMEFIRMA, SUBUNITATEA FROM TMP_POSTRETAIL;
    

    INSERT INTO INACTIVRETAIL (CODINACTIVRETAIL, CODOBIECT, CODPOSTRETAIL)
    SELECT SEQ_INACTIVRETAIL_CODINACTIV.NEXTVAL, CODOBIECT, RecID
    FROM
      TMP_INACTIVRETAIL;

    
  END IF;
  
  NotifyModif(Operation, RecId, &apos;POSTRETAIL&apos;);
    
  COMMIT;
END;

PROCEDURE CHECKFUZIONARI
IS
BEGIN

FOR V_REC IN 
(  
SELECT  
  O_OLD.CODOBIECT AS CODOBIECT_OLD,
  O_OLD.CODARTICOL AS CODARTICOL_OLD,
  O_NEW.CODOBIECT AS CODOBIECT_NEW,
  O_NEW.CODARTICOL AS CODARTICOL_NEW
FROM
 NARTOBJ O_OLD,
 NARTOBJ O_NEW,
 TMP_FUZART F
WHERE
      O_OLD.CODARTICOL = F.CODARTINIT
 AND  O_NEW.CODARTICOL = F.CODARTFIN
)
LOOP

  UPDATE EMULARE1
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;

  UPDATE IESIRI1RETAIL
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;



  UPDATE RESTCMD1
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;

  UPDATE RESTARTINACTIVE
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;

  UPDATE RESTGESTIMPLICITE
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;


  UPDATE RESTNP1
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;

  UPDATE IESIRI1
  SET
   CODOBIECT = V_REC.CODOBIECT_NEW
  WHERE
    CODOBIECT = V_REC.CODOBIECT_OLD;


END LOOP;


FOR V_REC IN 
(  
SELECT  
  O_OLD.CODOBIECT AS CODOBIECT_OLD,
  O_OLD.CODARTICOL AS CODARTICOL_OLD,
  O_NEW.CODOBIECT AS CODOBIECT_NEW,
  O_NEW.CODARTICOL AS CODARTICOL_NEW
FROM
  NARTOBJ O_OLD,
  NARTOBJ O_NEW,
  TMP_FUZART F
WHERE
      O_OLD.CODARTICOL = F.CODARTINIT
 AND  O_NEW.CODARTICOL = F.CODARTFIN
)
LOOP

  DELETE FROM NARTOBJ1 WHERE CODOBIECT = V_REC.CODOBIECT_OLD;
  DELETE FROM PRETM    WHERE CODOBIECT = V_REC.CODOBIECT_OLD;
  DELETE FROM NATROBJ  WHERE CODOBIECT = V_REC.CODOBIECT_OLD;
  DELETE FROM NARTOBJ  WHERE CODOBIECT = V_REC.CODOBIECT_OLD;

  DELETE FROM NART1          WHERE CODARTICOL   = V_REC.CODARTICOL_OLD;
  DELETE FROM NARTIMPLICITE  WHERE CODARTICOL   = V_REC.CODARTICOL_OLD;
  DELETE FROM NART           WHERE CODARTICOL   = V_REC.CODARTICOL_OLD;
END LOOP;


BEGIN -- curat inregistrari diblate in RESTARTINACTIVE
FOR V_REC IN 
(
SELECT 
  CODOBIECT, 
  CODRESTAURANT, 
  COUNT(*) 
FROM
   RESTARTINACTIVE
GROUP BY
  CODOBIECT,
  CODRESTAURANT
HAVING COUNT(*) &gt; 1     
)
LOOP
   DELETE FROM RESTARTINACTIVE
   WHERE
    CODOBIECT = V_REC.CODOBIECT
    AND CODRESTAURANT = V_REC.CODRESTAURANT
    AND COD &gt; (SELECT MIN(COD) FROM RESTARTINACTIVE WHERE CODOBIECT = V_REC.CODOBIECT AND CODRESTAURANT = V_REC.CODRESTAURANT);
END LOOP;
END;


COMMIT;  

END;


PROCEDURE CHECKARTDELETED
IS
  NR1 NUMBER(10) := 0;
  NR2 NUMBER(10) := 0;
  NR3 NUMBER(10) := 0;
  NR4 NUMBER(10) := 0;
BEGIN

FOR V_REC IN 
(  
SELECT  
  CODOBIECT, O.CODARTICOL
FROM
  TMP_NARTDELETED D,
  NARTOBJ O
WHERE
 O.CODARTICOL = D.CODARTICOL 
)
LOOP
   
  SELECT COUNT(*) INTO NR1 FROM EMULARE1  WHERE CODOBIECT = V_REC.CODOBIECT;
  SELECT COUNT(*) INTO NR2 FROM RESTCMD1  WHERE CODOBIECT = V_REC.CODOBIECT;
  SELECT COUNT(*) INTO NR3 FROM RESTNP1   WHERE CODOBIECT = V_REC.CODOBIECT;
  SELECT COUNT(*) INTO NR4 FROM IESIRI1   WHERE CODOBIECT = V_REC.CODOBIECT;
  
  IF NR1 + NR2 + NR3 + NR4 = 0 THEN
    DELETE FROM RESTARTINACTIVE WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NARTOBJ1        WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM PRETM           WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NATROBJ         WHERE CODOBIECT = V_REC.CODOBIECT;
    DELETE FROM NARTOBJ         WHERE CODOBIECT = V_REC.CODOBIECT;
/*
    DELETE FROM NART1          WHERE CODARTICOL   = V_REC.CODARTICOL;
    DELETE FROM NARTIMPLICITE  WHERE CODARTICOL   = V_REC.CODARTICOL;
    DELETE FROM NART           WHERE CODARTICOL   = V_REC.CODARTICOL;
*/    
  END IF;  

  
END LOOP;

  FOR V_REC IN (SELECT D.CODARTICOL 
                FROM 
                  TMP_NARTDELETED  D,
                  NART A
                WHERE
                  D.CODARTICOL = A.CODARTICOL  
)
  LOOP
    SELECT COUNT(*) INTO NR1 FROM NARTOBJ  WHERE CODARTICOL = V_REC.CODARTICOL;
    IF NR1 = 0 THEN 
      DELETE FROM NART1          WHERE CODARTICOL   = V_REC.CODARTICOL;
      DELETE FROM NARTIMPLICITE  WHERE CODARTICOL   = V_REC.CODARTICOL;
      DELETE FROM NARTATR        WHERE CODARTICOL   = V_REC.CODARTICOL;
      DELETE FROM NART           WHERE CODARTICOL   = V_REC.CODARTICOL;
    END IF;
  END LOOP;    


COMMIT;  

END;


PROCEDURE CHECKFUZGEST
IS
BEGIN

FOR V_REC IN 
(  
SELECT  
  F.CODGESTINIT AS CODGEST_OLD,
  F.CODGESTFIN AS CODGEST_NEW
FROM
 TMP_FUZGEST F
)
LOOP

  UPDATE EMULARE1
  SET
    CODGEST = V_REC.CODGEST_NEW
  WHERE
    CODGEST = V_REC.CODGEST_OLD;

  UPDATE RESTCMD1
  SET
   CODGEST = V_REC.CODGEST_NEW
  WHERE
    CODGEST = V_REC.CODGEST_OLD;
  
  UPDATE RESTGESTIMPLICITE
  SET
   GESTIMPLICITA = V_REC.CODGEST_NEW
  WHERE
   GESTIMPLICITA = V_REC.CODGEST_OLD;
     
  UPDATE NAGENDA
  SET
    CODGEST = V_REC.CODGEST_NEW
  WHERE
    CODGEST = V_REC.CODGEST_OLD;


END LOOP;


FOR V_REC IN 
(  
    SELECT  
      F.CODGESTINIT AS CODGEST_OLD,
      F.CODGESTFIN AS CODGEST_NEW
    FROM
     TMP_FUZGEST F
)
LOOP

  DELETE FROM NGEST1          WHERE CODGEST   = V_REC.CODGEST_OLD;
  DELETE FROM NGEST           WHERE CODGEST   = V_REC.CODGEST_OLD;
END LOOP;

COMMIT;  

END;

PROCEDURE CHECKFUZLOCALIT
IS
BEGIN

FOR V_REC IN 
(  
SELECT  
  F.CODLOCALITINIT AS CODLOCALIT_OLD,
  F.CODLOCALITFIN AS CODLOCALIT_NEW
FROM
 TMP_FUZLOCALIT F
)
LOOP

  UPDATE NAGENDA
  SET
    CODLOCALIT = V_REC.CODLOCALIT_NEW
  WHERE
    CODLOCALIT = V_REC.CODLOCALIT_OLD;

  UPDATE NSEDIIPARTRETAIL
  SET
    CODLOCALIT = V_REC.CODLOCALIT_NEW
  WHERE
    CODLOCALIT = V_REC.CODLOCALIT_OLD;
  

END LOOP;


FOR V_REC IN 
(  
    SELECT  
      F.CODLOCALITINIT AS CODLOCALIT_OLD,
      F.CODLOCALITFIN AS CODLOCALIT_NEW
    FROM
     TMP_FUZLOCALIT F
)
LOOP
  DELETE FROM NLOCALIT  WHERE CODLOCALIT   = V_REC.CODLOCALIT_OLD;
END LOOP;

COMMIT;  

END;

PROCEDURE MEMO_MODIF_PRET_RETAIL(aCODOBIECT IN NUMBER, aCODSUBUNIT IN NUMBER)
IS
aCODSYNC NUMBER;
BEGIN
  FOR V_REC IN 
  (
    SELECT 
     P.COD AS CODPOSTRETAIL, 
     O.CODOBIECT,
     PM.LEI AS PRETNOU,
     PM.CODCATPRET
    FROM 
      POSTRETAIL P,
      PRETM PM,
      NARTOBJ O,
      NART A,
      NCATPRET CP
    WHERE
      PM.SUBUNITATEA    = aCodSubunit
      AND P.SUBUNITATEA = aCODSUBUNIT
      AND PM.CODOBIECT  = aCODOBIECT
      AND O.CODOBIECT   = aCODOBIECT
      AND A.CODARTICOL  = O.CODARTICOL
      AND NVL(A.CASADEMARCAT, 0) = 1  
--      AND PM.IMPLICIT   = 1
      AND PM.CODCATPRET = CP.CODCATPRET
      AND CP.TIP IN (1, 2)  
  ) 
  LOOP
    BEGIN
      SELECT CODSYNC INTO aCODSYNC 
      FROM 
        SYNCPRETRETAIL 
      WHERE
        CODPOSTRETAIL = V_REC.CODPOSTRETAIL
        AND CODOBIECT = V_REC.CODOBIECT
        AND CODCATPRET = V_REC.CODCATPRET;
        EXCEPTION WHEN OTHERS THEN aCODSYNC := 0;
    END;  
    
    IF aCODSYNC = 0 THEN 
      INSERT INTO SYNCPRETRETAIL(CODSYNC, CODPOSTRETAIL, CODOBIECT, CODCATPRET, PRETNOU, DATA, SINCRONIZAT)
             VALUES(SEQ_SYSNPRETRETAIL_CODSYNC.NEXTVAL, V_REC.CODPOSTRETAIL, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.PRETNOU, SYSDATE, 0)   ;
    ELSE
      UPDATE SYNCPRETRETAIL
      SET
        PRETNOU   = V_REC.PRETNOU,
        DATA      = SysDate,
        SINCRONIZAT = 0
      WHERE
        CODSYNC = aCODSYNC
        AND PRETNOU &lt;&gt; V_REC.PRETNOU;
    END IF;    
  END LOOP;   
END;    

PROCEDURE PREPARE_TEMP_PRETURI(aCODPOSTRETAIL IN NUMBER)
IS
BEGIN
  DELETE TMP_NART;
  DELETE TMP_NTAXE;
  DELETE TMP_NART1;
  DELETE TMP_NARTOBJ;
  DELETE TMP_NARTOBJ1;
  DELETE TMP_NUM;
  DELETE TMP_NUM1;
  DELETE TMP_PRETM;
  DELETE TMP_PRETMAMB;
  DELETE TMP_NCATPRET;
  DELETE TMP_CODEXTALT;
  FOR V_REC IN (SELECT S.*, A.CODARTICOL, A.UM, P.SUBUNITATEA 
                FROM 
                  SYNCPRETRETAIL S,
                  NARTOBJ O,
                  NART A,
                  POSTRETAIL P  
                WHERE 
                  CODPOSTRETAIL             = aCODPOSTRETAIL
                  AND O.CODOBIECT           = S.CODOBIECT
                  AND A.CODARTICOL          = O.CODARTICOL
                  AND P.COD                 = aCODPOSTRETAIL
                  AND NVL(S.SINCRONIZAT, 0) = 0
                )
  LOOP
    INSERT INTO TMP_NART(CODARTICOL, 
                         DEN_ARTICOL, 
                         TIPARTICOL, 
                         UM, 
                         TIPSERIE, 
                         ARETG, 
                         CONTSERVICIU, 
                         CASADEMARCAT,  
                         CODEXTERNART, 
                         SUFIXCODEXTERN)

   SELECT CODARTICOL, DEN_ARTICOL, TIPARTICOL, UM, TIPSERIE, ARETG, CONTSERVICIU, CASADEMARCAT, CODEXTERNART, SUFIXCODEXTERN FROM NART WHERE CODARTICOL = V_REC.CODARTICOL;                          

   INSERT INTO TMP_NARTOBJ (CODOBIECT, 
                            CODARTICOL, 
                            CODEXTERN, 
                            CODINTERN,  
                            ROTUNJIRE, 
                            PROMOTIE, 
                            DENUMIRE, 
                            BLOCAT, 
                            INACTIV,
                            DISCPROMO 
                            )
   SELECT CODOBIECT, CODARTICOL, CODEXTERN, CODINTERN, ROTUNJIRE, PROMOTIE, DENUMIRE, BLOCAT, INACTIV, DISCPROMO  FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT;                          
   
   INSERT INTO TMP_CODEXTALT(COD, CODOBIECT, CODEXTERN)
   SELECT COD, CODOBIECT, CODEXTERN FROM CODEXTALT WHERE CODOBIECT = V_REC.CODOBIECT;
   
   INSERT INTO TMP_PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, PROC, INDEXLOCAL, SUBUNITATEA)
               SELECT CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, PROC, INDEXLOCAL, SUBUNITATEA
               FROM PRETM
               WHERE
                 CODOBIECT = V_REC.CODOBIECT
                 AND SUBUNITATEA = V_REC.SUBUNITATEA
                 AND CODCATPRET = V_REC.CODCATPRET; 
   


  END LOOP;    

  INSERT INTO TMP_PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
  SELECT CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA FROM PRETMAMB WHERE CODPRETM IN (SELECt CODPRETM FROM TMP_PRETM);

  
  INSERT INTO TMP_NUM (CODUM, DEN_UM, TIP, ZECIMALE, TIPUM, COEF)
  SELECT CODUM, DEN_UM, TIP, ZECIMALE, TIPUM, COEF FROM NUM WHERE CODUM IN (SELECT UM FROM TMP_NART);
  
  INSERT INTO TMP_NUM1 (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CODEXTERN)
  SELECT CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CODEXTERN FROM NUM1 WHERE CODUM IN (SELECT UM FROM TMP_NART);


  INSERT INTO TMP_NART1(CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, ANSTART, LUNASTART)
               SELECT CODARTICOL1, CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, ANSTART, LUNASTART 
               FROM 
                 NART1 
               WHERE 
                 CODARTICOL IN (SELECT CODARTICOL FROM TMP_NART);


  INSERT INTO TMP_NTAXE(CODTAXA, DEN_TAXA, CENTRALIZAT) 
  SELECT  CODTAXA, DEN_TAXA, CENTRALIZAT FROM NTAXE 
  WHERE 
    CODTAXA IN (SELECT CODACCIZE FROM TMP_NART1) or
    CODTAXA IN (SELECT CODTAXA1  FROM TMP_NART1) or
    CODTAXA IN (SELECT CODTAXA2  FROM TMP_NART1);


  INSERT INTO TMP_NARTOBJ1(CODOBIECT1, 
                           CODOBIECT, 
                           PRETMAXIMAL, 
                           PROCADAOSMAXIMAL, 
                           ADAOSLA, 
                           ANSTART, 
                           LUNASTART, 
                           PRETREFERINTA, 
                           TIPPRETMAX, 
                           COMPENSAT, 
                           TIPCOMPENSARE, 
                           GRUPA )
  SELECT CODOBIECT1, CODOBIECT, PRETMAXIMAL, PROCADAOSMAXIMAL, ADAOSLA, ANSTART, LUNASTART, PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA
  FROM NARTOBJ1
  WHERE
    CODOBIECT IN (SELECT CODOBIECT FROM TMP_NARTOBJ);                          


  INSERT INTO TMP_NCATPRET(CODCATPRET, DEN_CATPRET, TIP, SIMBOL)
  SELECT CODCATPRET, DEN_CATPRET, TIP, SIMBOL 
  FROM 
    NCATPRET 
  WHERE CODCATPRET IN (SELECT CODCATPRET FROM TMP_PRETM);
  COMMIT;
END;    

PROCEDURE PREIA_PRETURI_NOI(aCODPOSTRETAIL IN NUMBER, IDPREL OUT NUMBER)
IS
NR NUMBER(10) := 0;
BEGIN
  prc_al_refresh(&apos;TMP_NART1&apos;,     0);
  prc_al_refresh(&apos;TMP_NARTOBJ11&apos;, 0);

  IDPREL := SEQ_PRELPRET_RETAIL.NEXTVAL;  
  FOR V_REC IN (SELECT * FROM TMP_NUM)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NUM WHERE CODUM = V_REC.CODUM;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NUM(CODUM, DEN_UM, TIP, ZECIMALE, TIPUM, COEF)
      VALUES (V_REC.CODUM, V_REC.DEN_UM, V_REC.TIP, V_REC.ZECIMALE, V_REC.TIPUM, V_REC.COEF);
    ELSE
      UPDATE NUM
      SET
       DEN_UM   = V_REC.DEN_UM,
       TIP      = V_REC.TIP, 
       ZECIMALE = V_REC.ZECIMALE, 
       TIPUM    = V_REC.TIPUM, 
       COEF     = V_REC.COEF
      WHERE
        CODUM = V_REC.CODUM; 
       
    END IF;    
  END LOOP; 
  
  FOR V_REC IN (SELECT * FROM TMP_NUM1)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NUM1 WHERE CODUM1 = V_REC.CODUM1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NUM1(CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CODEXTERN)
      VALUES (V_REC.CODUM1, V_REC.CODUM, V_REC.SECUNDARA, V_REC.DEN_UM1, V_REC.PARITATE, V_REC.ZECIMALE, V_REC.OBS, V_REC.CODEXTERN);
    ELSE
      UPDATE NUM1
      SET
        CODUM     = V_REC.CODUM,
        SECUNDARA = V_REC.SECUNDARA,
        DEN_UM1   = V_REC.DEN_UM1,
        PARITATE  = V_REC.PARITATE, 
        ZECIMALE  = V_REC.ZECIMALE,
        OBS       = V_REC.OBS,
        CODEXTERN = V_REC.CODEXTERN
      WHERE
        CODUM1 = V_REC.CODUM1; 
    END IF;    
  END LOOP; 
    

  FOR V_REC IN (SELECT * FROM TMP_NART)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NART WHERE CODARTICOL = V_REC.CODARTICOL;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NART(CODARTICOL, 
                       DEN_ARTICOL, 
                       TIPARTICOL,       
                       UM,       
                       TIPSERIE,       
                       ARETG,       
                       CONTSERVICIU,       
                       CASADEMARCAT,       
                       CODEXTERNART,       
                       SUFIXCODEXTERN      
                      ) 
      VALUES 
                      (V_REC.CODARTICOL, 
                       V_REC.DEN_ARTICOL, 
                       V_REC.TIPARTICOL,       
                       V_REC.UM,       
                       V_REC.TIPSERIE,       
                       V_REC.ARETG,       
                       V_REC.CONTSERVICIU,       
                       V_REC.CASADEMARCAT,       
                       V_REC.CODEXTERNART,       
                       V_REC.SUFIXCODEXTERN      
                      );       
     ELSE
      UPDATE NART
      SET
        CODARTICOL     = V_REC.CODARTICOL,
        DEN_ARTICOL    = V_REC.DEN_ARTICOL,  
        TIPARTICOL     = V_REC.TIPARTICOL,
        UM             = V_REC.UM,
        TIPSERIE       = V_REC.TIPSERIE,
        ARETG          = V_REC.ARETG,
        CONTSERVICIU   = V_REC.CONTSERVICIU,
        CASADEMARCAT   = V_REC.CASADEMARCAT,      
        CODEXTERNART   = V_REC.CODEXTERNART,
        SUFIXCODEXTERN = V_REC.SUFIXCODEXTERN
      WHERE
        CODARTICOL = V_REC.CODARTICOL; 
    END IF;    
  END LOOP; 


  FOR V_REC IN (SELECT * FROM TMP_NTAXE)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NTAXE WHERE CODTAXA = V_REC.CODTAXA;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NTAXE(CODTAXA, DEN_TAXA, CENTRALIZAT)
      VALUES (V_REC.CODTAXA, V_REC.DEN_TAXA, V_REC.CENTRALIZAT); 
     ELSE
      UPDATE NTAXE
      SET
        DEN_TAXA    = V_REC.DEN_TAXA,
        CENTRALIZAT = V_REC.CENTRALIZAT
      WHERE
        CODTAXA = V_REC.CODTAXA; 
    END IF;    
  END LOOP;  
  
    
  FOR V_REC IN (SELECT * FROM TMP_NART1)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NART1 WHERE CODARTICOL1 = V_REC.CODARTICOL1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NART1(  CODARTICOL1,
                          CODARTICOL, 
                          CODTVA, 
                          CODACCIZE, 
                          CODTAXA1, 
                          CODTAXA2, 
                          ANSTART, 
                          LUNASTART,
                          ALSTART,
                          ALSTOP      
                       ) 
      VALUES          (
                        V_REC.CODARTICOL1,
                        V_REC.CODARTICOL,
                        V_REC.CODTVA,    
                        V_REC.CODACCIZE, 
                        V_REC.CODTAXA1,  
                        V_REC.CODTAXA2,  
                        V_REC.ANSTART,   
                        V_REC.LUNASTART ,
                        V_REC.ALSTART,
                        V_REC.ALSTOP
                      );       
     ELSE
      UPDATE NART1
      SET
        CODARTICOL  = V_REC.CODARTICOL, 
        CODTVA      = V_REC.CODTVA, 
        CODACCIZE   = V_REC.CODACCIZE, 
        CODTAXA1    = V_REC.CODTAXA1, 
        CODTAXA2    = V_REC.CODTAXA2, 
        ANSTART     = V_REC.ANSTART, 
        LUNASTART   = V_REC.LUNASTART,
        ALSTART     = V_REC.ALSTART,
        ALSTOP      = V_REC.ALSTOP      
      WHERE CODARTICOL1 = V_REC.CODARTICOL1; 
    END IF;    
  END LOOP; 


  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NARTOBJ WHERE CODOBIECT = V_REC.CODOBIECT;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NARTOBJ
                      (CODOBIECT, 
                       CODARTICOL,
                       CODEXTERN, 
                       CODINTERN, 
                       ROTUNJIRE, 
                       PROMOTIE, 
                       DENUMIRE, 
                       BLOCAT, 
                       INACTIV,
                       DISCPROMO 
                      ) 
      VALUES 
                      (
                        V_REC.CODOBIECT,                        
                        V_REC.CODARTICOL,                         
                        V_REC.CODEXTERN,                        
                        V_REC.CODINTERN,                        
                        V_REC.ROTUNJIRE,                        
                        V_REC.PROMOTIE,                            
                        V_REC.DENUMIRE,                            
                        V_REC.BLOCAT,                            
                        V_REC.INACTIV,
                        V_REC.DISCPROMO                            
                      );       
     ELSE
      UPDATE NARTOBJ
      SET
       CODARTICOL =  V_REC.CODARTICOL,
       CODEXTERN  =  V_REC.CODEXTERN, 
       CODINTERN  =  V_REC.CODINTERN, 
       ROTUNJIRE  =  V_REC.ROTUNJIRE, 
       PROMOTIE   =  V_REC.PROMOTIE,  
       DENUMIRE   =  V_REC.DENUMIRE,  
       BLOCAT     =  V_REC.BLOCAT,    
       INACTIV    =  V_REC.INACTIV,
       DISCPROMO  =  V_REC.DISCPROMO   
      WHERE
        CODOBIECT = V_REC.CODOBIECT; 
    END IF;    
  END LOOP; 
  

  FOR V_REC IN (SELECT * FROM TMP_CODEXTALT)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM CODEXTALT WHERE COD = V_REC.COD;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO CODEXTALT (COD, CODOBIECT, CODEXTERN)
      VALUES        ( V_REC.COD, V_REC.CODOBIECT, V_REC.CODEXTERN);
     ELSE
      UPDATE CODEXTALT
      SET
       CODEXTERN  =  V_REC.CODEXTERN
      WHERE
        COD = V_REC.COD; 
    END IF;    
  END LOOP; 


  
  FOR V_REC IN (SELECT * FROM TMP_NARTOBJ1)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NARTOBJ1 WHERE CODOBIECT1 = V_REC.CODOBIECT1;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NARTOBJ1 (
        CODOBIECT1,  CODOBIECT,  PRETMAXIMAL,  PROCADAOSMAXIMAL,  ADAOSLA, ANSTART, LUNASTART,
        PRETREFERINTA, TIPPRETMAX, COMPENSAT, TIPCOMPENSARE, GRUPA ,
        ALSTART, ALSTOP
      )
      VALUES ( 
        V_REC.CODOBIECT1, V_REC.CODOBIECT, V_REC.PRETMAXIMAL, V_REC.PROCADAOSMAXIMAL, V_REC.ADAOSLA, V_REC.ANSTART, V_REC.LUNASTART,
        V_REC.PRETREFERINTA,V_REC.TIPPRETMAX, V_REC.COMPENSAT, V_REC.TIPCOMPENSARE, V_REC.GRUPA,
        V_REC.ALSTART, V_REC.ALSTOP 
      );       
    ELSE
      UPDATE NARTOBJ1
      SET
        CODOBIECT        = V_REC.CODOBIECT, 
        PRETMAXIMAL      = V_REC.PRETMAXIMAL, 
        PROCADAOSMAXIMAL = V_REC.PROCADAOSMAXIMAL, 
        ADAOSLA          = V_REC.ADAOSLA,                     
        ANSTART          = V_REC.ANSTART,                     
        LUNASTART        = V_REC.LUNASTART,                   
        PRETREFERINTA    = V_REC.PRETREFERINTA,               
        TIPPRETMAX       = V_REC.TIPPRETMAX,                  
        COMPENSAT        = V_REC.COMPENSAT,                   
        TIPCOMPENSARE    = V_REC.TIPCOMPENSARE,               
        GRUPA            = V_REC.GRUPA,
        ALSTART          = V_REC.ALSTART,
        ALSTOP           = V_REC.ALSTOP       
       WHERE CODOBIECT1 = V_REC.CODOBIECT1; 
    END IF;    
  END LOOP; 

  FOR V_REC IN (SELECT * FROM TMP_NCATPRET)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO NR FROM NCATPRET WHERE CODCATPRET = V_REC.CODCATPRET;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO NCATPRET(CODCATPRET, DEN_CATPRET, TIP, SIMBOL)
             VALUES (V_REC.CODCATPRET, V_REC.DEN_CATPRET, V_REC.TIP, V_REC.SIMBOL);
     ELSE
      UPDATE NCATPRET
      SET
        DEN_CATPRET = V_REC.DEN_CATPRET,
        TIP         = V_REC.TIP,
        SIMBOL      = V_REC.SIMBOL
      WHERE
        CODCATPRET = V_REC.CODCATPRET ;
    END IF;    
  END LOOP; 

  FOR V_REC IN (SELECT * FROM TMP_PRETM)
  LOOP
    -- MA ASIGUR CA CODPRETM PE BAZA = CODPRETM PE SATELIT la ACELASI OBIECT SI CATEGORIE
    FOR V_REC_D IN
    (SELECT * FROM PRETM WHERE CODOBIECT = V_REC.CODOBIECT AND CODCATPRET = V_REC.CODCATPRET AND SUBUNITATEA = V_REC.SUBUNITATEA)   
    LOOP
      DELETE FROM PRETMAMB WHERE CODPRETM = V_REC_D.CODPRETM;  
      DELETE FROM PRETM    WHERE CODPRETM = V_REC_D.CODPRETM;  
    END LOOP;    
   

    BEGIN
      SELECT COUNT(*) INTO NR FROM PRETM WHERE CODPRETM = V_REC.CODPRETM;
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0 THEN 
      INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, VALUTA, MONEDA, IMPLICIT, PROC, INDEXLOCAL, SUBUNITATEA)
             VALUES (V_REC.CODPRETM, V_REC.CODOBIECT, V_REC.CODCATPRET, V_REC.LEI, V_REC.VALUTA, V_REC.MONEDA, V_REC.IMPLICIT, V_REC.PROC, V_REC.INDEXLOCAL, V_REC.SUBUNITATEA);
     ELSE
      UPDATE PRETM
      SET
        CODOBIECT   = V_REC.CODOBIECT,   
        CODCATPRET  = V_REC.CODCATPRET,  
        LEI         = V_REC.LEI,         
        VALUTA      = V_REC.VALUTA,      
        MONEDA      = V_REC.MONEDA,      
        IMPLICIT    = V_REC.IMPLICIT,    
        PROC        = V_REC.PROC,        
        INDEXLOCAL  = V_REC.INDEXLOCAL,  
        SUBUNITATEA = V_REC.SUBUNITATEA 
      WHERE
       CODPRETM = V_REC.CODPRETM;
    END IF;    

    FOR V_REC_PA IN (SELECT * FROM TMP_PRETMAMB PA WHERE PA.CODPRETM = V_REC.CODPRETM)
    LOOP
       UPDATE PRETMAMB 
       SET
         CODAMB = V_REC_PA.CODAMB,
         LEI    = V_REC_PA.LEI
       WHERE
         CODPRETMAMB = V_REC_PA.CODPRETMAMB;
       IF SQL%rowcount = 0 THEN     
         INSERT INTO PRETMAMB(CODPRETMAMB, CODPRETM, CODAMB, LEI, VALUTA)
         VALUES(V_REC_PA.CODPRETMAMB, V_REC_PA.CODPRETM, V_REC_PA.CODAMB, V_REC_PA.LEI, V_REC_PA.VALUTA);
       END IF;
    END LOOP;    
  END LOOP; 

  FOR V_REC IN  (
    SELECT  O.CODOBIECT, PM.LEI AS PRETNOU, PM.CODCATPRET
    FROM  TMP_PRETM PM, NARTOBJ O
    WHERE PM.CODOBIECT  = O.CODOBIECT
  ) LOOP
    INSERT INTO SYNCPRETRETAIL(CODSYNC, CODPOSTRETAIL, CODOBIECT, CODCATPRET, PRETNOU, DATA, SINCRONIZAT, IDPRELUARE)
    VALUES(SEQ_SYSNPRETRETAIL_CODSYNC.NEXTVAL,  aCODPOSTRETAIL,  V_REC.CODOBIECT, V_REC.CODCATPRET,  V_REC.PRETNOU, SYSDATE, 1, IDPREL);
  END LOOP;  

  COMMIT;
END;    

PROCEDURE UPDATEPUNCTERETAIL(aCODPART IN NUMBER, aCODPOSTRETAIL IN NUMBER)
IS
BEGIN
  DELETE FROM TOTALPUNCTE WHERE CODPOSTRETAIL = aCODPOSTRETAIL AND CODPART = aCODPART;
  INSERT INTO TOTALPUNCTE(COD, CODPART, CODPUNCTAJ, PUNCTE, VALOARE, CODPOSTRETAIL)
  SELECT SEQ_TOTALPUNCTE_COD.NEXTVAL, CODPART, CODPUNCTAJ, PUNCTE, VALOARE, CODPOSTRETAIL FROM TMP_TOTALPUNCTE;
  COMMIT;
END;    

PROCEDURE PREIA_PUNCTE_PEBAZA(aCODPOSTRETAIL IN NUMBER)
IS
BEGIN
  DELETE FROM TOTALPUNCTE WHERE CODPOSTRETAIL = aCODPOSTRETAIL;
  INSERT INTO TOTALPUNCTE(COD, CODPART, CODPUNCTAJ, PUNCTE, VALOARE, CODPOSTRETAIL)
  SELECT SEQ_TOTALPUNCTE_COD.NEXTVAL, CODPART, CODPUNCTAJ, PUNCTE, VALOARE, CODPOSTRETAIL FROM TMP_TOTALPUNCTE;
  COMMIT;
END;    


end PKG_POSTRETAIL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E7598F60981CB74099FEBDC6920ACB192C41FE9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PRECOMANDA is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_70&apos;;

procedure STERGE(aAn in number, aSet in number, aAnG in number, aSetG in number) is
begin
  for v_rec in (select codprecomanda
                from precomanda
                where anc = aan and saptamanac = aset
                      and ang = aang and saptamanag = asetg
                      and userid = pkg_globals.GETUSERID) loop
    delete precmdlink where codprecomanda1 in (select codprecomanda1 from precomanda1 where codprecomanda = v_rec.codprecomanda);                  
    delete precomanda1 where codprecomanda = v_rec.codprecomanda;
    delete precomanda where codprecomanda = v_rec.codprecomanda;                  
  end loop;                    
  commit;
end;  

procedure STERGELINIE(aCodPreComanda1 in number) is
aCodPreComanda number(20);
aRest number(20,7);
aCant number(20,7);
aCount number(10);
begin
  begin
    select codprecomanda, Cant, Rest into aCodPreComanda, aCant, aRest from PreComanda1 where CodPreComanda1 = aCodPreComanda1;
  exception when others then aCodPreComanda := 0;
  end;

  if aRest = 0 then Return; end if;
  if aRest &lt; aCant then
    update PreComanda1 set cant = cant - aRest,
                           rest = 0
    where codprecomanda1 = acodprecomanda1;
  else 
    delete precmdlink where codprecomanda1 = aCodPreComanda1; 
    delete PreComanda1 where CodPreComanda1 = aCodPreComanda1;
    select count(*) into acount from precomanda1 where codprecomanda = acodprecomanda;
    if acount = 0 then
      delete precomanda where codprecomanda = acodprecomanda;
    end if;
  end if;

  commit;
end;

procedure SALVEAZAPRECMD is
aCodPrecomanda number(20);
aAn number(4);
aSet number(2);
aAnG number(4);
aSetG number(2);
begin
  begin
    select codprecomanda 
    into aCodPrecomanda
    from precomanda 
    where userid = pkg_globals.getuserid and subunitatea = pkg_globals.GETSUBUNITATE
          and anc = aAn and saptamanac = aSet and ang = aAnG and saptamanag = aSetG;
  exception when others then
    aCodPrecomanda := 0;
  end;   
  
  if aCodPrecomanda = 0 then 
    select seq_precomanda_codprecomanda.nextval into aCodPrecomanda from dual;
    insert into precomanda(codprecomanda, userid, subunitatea, anc, saptamanac, ang, saptamanag)
    select aCodPreComanda, pkg_globals.GETUSERID, pkg_globals.GETSUBUNITATE, anc, saptamanac, ang, saptamanag
    from tmp_precomanda;
  end if;
  
  delete precomanda1 where codprecomanda = acodprecomanda and codstare1 in (select CodStare1 from tmp_precomanda1);
  
  INSERT INTO PRECOMANDA1 
  (
    codprecomanda1,
    codprecomanda,
    indexlocal,
    codobiect,
    umsec,
    pu,
    cant,
    rest,
    termen,
    addim,
    procdisc,
    obs,
    pretorig,
    coefdiscmaj,
    scadenta,
    d1,
    d2,
    d3,
    cantum1,
    codcontract1,
    codcentru,
    codoferta1,
    pretum1,
    codpart,
    codpromo1,
    moneda,
    codstare1,
    codlocatie,
    cantmin,
    datastart
  )
  SELECT
    SEQ_PRECOMANDA1_codprecomanda1.NEXTVAL,
    aCodPrecomanda,
    indexlocal,
    codobiect,
    umsec,
    pu,
    cant,
    rest,
    termen,
    addim,
    procdisc,
    obs,
    pretorig,
    coefdiscmaj,
    scadenta,
    d1,
    d2,
    d3,
    cantum1,
    codcontract1,
    codcentru,
    codoferta1,
    pretum1,
    codpart,
    codpromo1,
    moneda,
    codstare1,
    codlocatie,
    cantmin,
    datastart
  FROM TMP_PRECOMANDA1;
  
  commit;
end;  

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodPreComanda INTO Tmp FROM PRECOMANDA WHERE CodPreComanda = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_COMANDA FIELDS( CodComanda ) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
ACARNETDOC NUMBER (20);
ANRDOC NUMBER (20);
aCodSubunit NUMBER(20);
aDataDoc DATE;
aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);
  SELECT
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;DATADOC
  INTO
    ACARNETDOC,
    ANRDOC,
    aCodSubunit,
    aDataDoc,
    ADOC
  FROM
    PRECOMANDA
  WHERE
    CODPRECOMANDA = RECID;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID, CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRECOMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID, PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  DELETE PRECMDLINK WHERE CODPRECOMANDA1 IN (SELECT CODPRECOMANDA1 FROM PRECOMANDA1 WHERE CODPRECOMANDA = RECID);
  DELETE FROM PRECOMANDA1 WHERE CODPRECOMANDA = RECID;
  DELETE FROM PRECOMANDA  WHERE CODPRECOMANDA = RecId;

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;

  NotifyModif(2, RecId, &apos;PRECOMANDA&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_PRECOMANDA 
  (
    codprecomanda,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    carnetdoc,
    datadoc,
    valoare,
    an,
    luna,
    obs,
    moneda,
    subunitatea,
    inchisa,
    seriadoc,
    verificat,
    codstare1
  )   
  SELECT
    codprecomanda,
    tipdoc,
    anulat,
    blocat,
    operat,
    prefixdoc,
    nrdoc,
    carnetdoc,
    datadoc,
    valoare,
    an,
    luna,
    obs,
    moneda,
    subunitatea,
    inchisa,
    seriadoc,
    verificat,
    codstare1
  FROM PRECOMANDA
  WHERE CodPreComanda = RecId;

  INSERT INTO TMP_PRECOMANDA1 
  (
    codprecomanda1,
    codprecomanda,
    indexlocal,
    codobiect,
    umsec,
    pu,
    cant,
    rest,
    termen,
    addim,
    procdisc,
    obs,
    pretorig,
    coefdiscmaj,
    scadenta,
    d1,
    d2,
    d3,
    cantum1,
    codcontract1,
    codcentru,
    codoferta1,
    pretum1,
    codpart,
    codpromo1,
    moneda,
    valoare,
    DENOBIECT, 
    DENUM,     
    DENUM1,    
    CODEXTERN, 
    CODINTERN, 
    UM1,       
    RELATIEUM1,
    PARITATE,  
    ROTUNJIRE,
    promo,
    oferta,
    contract,
    codlocatie,
    cantmin,
    datastart 
  )
  SELECT
    P1.codprecomanda1,
    P1.codprecomanda,
    P1.indexlocal,
    P1.codobiect,
    P1.umsec,
    P1.pu,
    P1.cant,
    P1.rest,
    P1.termen,
    P1.addim,
    P1.procdisc,
    P1.obs,
    P1.pretorig,
    P1.coefdiscmaj,
    P1.scadenta,
    P1.d1,
    P1.d2,
    P1.d3,
    P1.cantum1,
    P1.codcontract1,
    P1.codcentru,
    P1.codoferta1,
    P1.pretum1,
    P1.codpart,
    P1.codpromo1,
    P1.moneda,
    P1.cant * P1.pu,
    O.DENUMIRE,
    U1.DEN_UM1,
    UMSPEC.Den_Um,
    O.CODEXTERN,
    O.CODINTERN,
    A.UM1,
    A.RELATIEUM1,
    u1.Paritate,
    O.ROTVALUTA,
    case when PO.CODPROMO &gt; 0 then PO.NRDOC||&apos;/&apos;||TO_CHAR(PO.DATASTART,&apos;DD.MM.YYYY&apos;)||&apos;-&apos;||TO_CHAR(PO.DATAEND,&apos;DD.MM.YYYY&apos;) else null end,
    case when OFF.CODOFERTA &gt; 0 THEN OFF.NRDOC||&apos;/&apos;||TO_CHAR(OFF.DATASTART,&apos;DD.MM.YYYY&apos;)||&apos;-&apos;||TO_CHAR(OFF.DATAEND,&apos;DD.MM.YYYY&apos;) ELSE NULL END,
    CASE WHEN C.CODCONTRACT &gt; 0 THEN C.NRDOC||&apos;/&apos;||TO_CHAR(C.DATADOC,&apos;DD.MM.YYYY&apos;) ELSE NULL END,
    p1.codlocatie,
    p1.cantmin,
    p1.datastart  
  FROM PRECOMANDA1 p1
       INNER JOIN NARTOBJ O ON P1.CODOBIECT = O.CODOBIECT
       INNER JOIN NART A ON O.CODARTICOL = A.CODARTICOL
       LEFT JOIN NUM1 u1 ON u1.CodUM1 = p1.UmSec
       LEFT JOIN NUM UMSPEC on a.um1 = UMSPEC.CODUM
       LEFT JOIN PROMO1 PO1 ON P1.CODPROMO1 = PO1.CODPROMO1
       LEFT JOIN PROMO PO ON PO.CODPROMO = PO1.CODPROMO
       LEFT JOIN CONTRACT1 C1 ON C1.CODCONTRACT1 = P1.CODCONTRACT1
       LEFT JOIN CONTRACT C ON C.CODCONTRACT = C1.CODCONTRACT
       LEFT JOIN OFERTA1 OF1 ON P1.CODOFERTA1 = OF1.CODOFERTA1
       LEFT JOIN OFERTA OFF ON OFF.CODOFERTA = OF1.CODOFERTA
  where CodPreComanda = RecId
  ORDER BY IndexLocal;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod          NUMBER(20);
  aOperat       INTEGER := 0;
  aInchisa      INTEGER := 0;
  aAnulat       INTEGER := 0;
  aCARNETDOC    NUMBER(20);
  aNRDOC        NUMBER(20);
  aCodSubunit   NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
BEGIN
  SELECT
    NVL(OPERAT,0),
    NVL(INCHISA,0),
    NVL(ANULAT,0),
    Nvl(CARNETDOC,0),
    NRDOC,
    SUBUNITATEA,
    DATADOC,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC
  INTO
    aOperat,
    aInchisa,
    aAnulat,
    aCARNETDOC,
    aNRDOC,
    aCodSubunit,
    aDATADOC,
    ADOC
  FROM TMP_PRECOMANDA;
  
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodPreComanda INTO RecId FROM TMP_PRECOMANDA;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRECOMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE PRECOMANDA
    SET 
    (  
      tipdoc,
      anulat,
      blocat,
      operat,
      prefixdoc,
      nrdoc,
      carnetdoc,
      datadoc,
      valoare,
      an,
      luna,
      obs,
      moneda,
      subunitatea,
      inchisa,
      seriadoc,
      verificat,
      codstare1
    )
       =( SELECT
            tipdoc,
            anulat,
            blocat,
            operat,
            prefixdoc,
            nrdoc,
            carnetdoc,
            datadoc,
            valoare,
            an,
            luna,
            obs,
            moneda,
            subunitatea,
            inchisa,
            seriadoc,
            verificat,
            codstare1
          FROM TMP_PRECOMANDA)
    WHERE CodPreComanda = RecId ;

    DELETE FROM PRECOMANDA1
    WHERE CodPreComanda = RecID
      AND CodPreComanda1 NOT IN (SELECT CodPreComanda1 FROM TMP_PRECOMANDA1);


    FOR v_rec IN (SELECT * FROM TMP_PRECOMANDA1  ORDER BY IndexLocal) LOOP
      IF NVL(v_rec.CodPreComanda1, -1) &gt; 0
      THEN
        UPDATE PRECOMANDA1 SET
          indexlocal     = v_rec.indexlocal,
          codobiect      = v_rec.codobiect,
          umsec          = v_rec.umsec,
          pu             = v_rec.pu,
          cant           = v_rec.cant,
          rest           = v_rec.rest,
          termen         = v_rec.termen,
          addim          = v_rec.addim,
          procdisc       = v_rec.procdisc,
          obs            = v_rec.obs,
          pretorig       = v_rec.pretorig,
          coefdiscmaj    = v_rec.coefdiscmaj,
          scadenta       = v_rec.scadenta,
          d1             = v_rec.d1,
          d2             = v_rec.d2,
          d3             = v_rec.d3,
          cantum1        = v_rec.cantum1,
          codcontract1   = v_rec.codcontract1,
          codcentru      = v_rec.codcentru,
          codoferta1     = v_rec.codoferta1,
          pretum1        = v_rec.pretum1,
          codpart        = v_rec.codpart,
          codpromo1      = v_rec.codpromo1,
          moneda         = v_rec.moneda,
          codlocatie     = v_rec.codlocatie,
          cantmin        = v_rec.cantmin,
          datastart      = v_rec.datastart     
        WHERE CODPRECOMANDA1  = v_rec.CODPRECOMANDA1;
      ELSE
        SELECT seq_PRECOMANDA1_CodPreComanda1.Nextval INTO VCOD from Dual;

        INSERT INTO PRECOMANDA1 (
          codprecomanda1,
          codprecomanda,
          indexlocal,
          codobiect,
          umsec,
          pu,
          cant,
          rest,
          termen,
          addim,
          procdisc,
          obs,
          pretorig,
          coefdiscmaj,
          scadenta,
          d1,
          d2,
          d3,
          cantum1,
          codcontract1,
          codcentru,
          codoferta1,
          pretum1,
          codpart,
          codpromo1,
          moneda,
          codlocatie,
          cantmin,
          datastart )
        VALUES (
          vCod,  
          RecID, 
          v_rec.indexlocal,
          v_rec.codobiect,
          v_rec.umsec,
          v_rec.pu,
          v_rec.cant,
          v_rec.rest,
          v_rec.termen,
          v_rec.addim,
          v_rec.procdisc,
          v_rec.obs,
          v_rec.pretorig,
          v_rec.coefdiscmaj,
          v_rec.scadenta,
          v_rec.d1,
          v_rec.d2,
          v_rec.d3,
          v_rec.cantum1,
          v_rec.codcontract1,
          v_rec.codcentru,
          v_rec.codoferta1,
          v_rec.pretum1,
          v_rec.codpart,
          v_rec.codpromo1,
          v_rec.moneda,
          v_rec.codlocatie,
          v_rec.cantmin,
          v_rec.datastart
        );
      END IF;
    END LOOP;

  ELSE -- INSERT

    SELECT seq_PRECOMANDA_CodPreComanda.NextVal INTO RecId FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRECOMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO PRECOMANDA 
    (
      codprecomanda,
      tipdoc,
      anulat,
      blocat,
      operat,
      prefixdoc,
      nrdoc,
      carnetdoc,
      datadoc,
      valoare,
      an,
      luna,
      obs,
      moneda,
      subunitatea,
      inchisa,
      seriadoc,
      verificat,
      codstare1
    )   
    SELECT
      RECID,
      tipdoc,
      anulat,
      blocat,
      operat,
      prefixdoc,
      nrdoc,
      carnetdoc,
      datadoc,
      valoare,
      an,
      luna,
      obs,
      moneda,
      subunitatea,
      inchisa,
      seriadoc,
      verificat,
      codstare1
    FROM TMP_PRECOMANDA;
    
    INSERT INTO PRECOMANDA1 
    (
      codprecomanda1,
      codprecomanda,
      indexlocal,
      codobiect,
      umsec,
      pu,
      cant,
      rest,
      termen,
      addim,
      procdisc,
      obs,
      pretorig,
      coefdiscmaj,
      scadenta,
      d1,
      d2,
      d3,
      cantum1,
      codcontract1,
      codcentru,
      codoferta1,
      pretum1,
      codpart,
      codpromo1,
      moneda,
      codlocatie,
      cantmin,
      datastart
    )
    SELECT
      SEQ_PRECOMANDA1_codprecomanda1.NEXTVAL,
      RECID,
      indexlocal,
      codobiect,
      umsec,
      pu,
      cant,
      rest,
      termen,
      addim,
      procdisc,
      obs,
      pretorig,
      coefdiscmaj,
      scadenta,
      d1,
      d2,
      d3,
      cantum1,
      codcontract1,
      codcentru,
      codoferta1,
      pretum1,
      codpart,
      codpromo1,
      moneda,
      codlocatie,
      cantmin,
      datastart
    FROM TMP_PRECOMANDA1;
  END IF;

  NotifyModif(Operation, RecId, &apos;COMANDA&apos;);
  COMMIT;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;  

end PKG_PRECOMANDA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PREDARIPLUS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>830F2F45433874F60E717817ACA1FFDA37E7464F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PREDARIPLUS is

PROCEDURE STERGE(AIDINREG IN NUMBER) IS
aDoc varchar2(500);
aDataDoc date;
BEGIN
  select 
    &apos;NRDOC:&apos;||NRDOC||&apos; &apos;||
    &apos;DATADOC:&apos;||TO_CHAR(DATADOC,&apos;DD.MM.YYYY HH24:MI&apos;)||&apos; &apos;||
    &apos;CODAFA:&apos;||CODAFA||&apos; &apos;||
    &apos;CODEXTERN:&apos;||CODEXTERN||&apos; &apos;||
    &apos;UA:&apos;||UA||&apos; &apos;||
    &apos;SECTIE:&apos;||SECTIE||&apos; &apos;||
    &apos;CANTITATE:&apos;||CANTITATE||&apos; &apos;||
    &apos;DATAMODIF:&apos;||TO_CHAR(DATAMODIF,&apos;DD.MM.YYYY HH24:MI&apos;)||&apos; &apos;||
    &apos;NRCMD:&apos;||NRCMD||&apos; &apos;||
    &apos;DATACMD:&apos;||TO_CHAR(DATACMD,&apos;DD.MM.YYYY HH24:MI&apos;)||&apos; &apos;||
    &apos;FSC:&apos;||FSC||&apos; &apos;||
    &apos;SCHIMB:&apos;||SCHIMB||&apos; &apos;||
    &apos;FORMATIE:&apos;||FORMATIE||&apos; &apos;||
    &apos;NRNP:&apos;||NRNP||&apos; &apos;||
    &apos;DATANP:&apos;||TO_CHAR(DATANP,&apos;DD.MM.YYYY HH24:MI&apos;)||&apos; &apos;||
    &apos;USERIDBLOCAJ:&apos;||USERIDBLOCAJ||&apos; &apos;||
    &apos;CODCOMANDA1:&apos;||CODCOMANDA1||&apos; &apos;||
    &apos;CANTITATEWME:&apos;||CANTITATEWME||&apos; &apos;||
    &apos;DATAWME:&apos;||TO_CHAR(DATAWME,&apos;DD.MM.YYYY HH24:MI&apos;)||&apos; &apos;||
    &apos;LINIA:&apos;||LINIA,
    DATADOC
    INTO aDoc, aDataDoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION); 
  DELETE PREDARIPLUS WHERE IDINREG = AIDINREG;
  COMMIT;
END;  

PROCEDURE UPDATE_CODEXTERN(AIDINREG IN NUMBER, ACODEXTERN IN VARCHAR2) IS
aDoc varchar2(500);
aDataDoc date;
BEGIN
  select 
    codextern||&apos;-&gt;&apos;||aCodExtern, datadoc into aDoc, adatadoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  UPDATE PREDARIPLUS SET CODEXTERN = ACODEXTERN WHERE IDINREG = AIDINREG;
  COMMIT;
END;  

PROCEDURE UPDATE_LINIA(AIDINREG IN NUMBER, ALINIA IN VARCHAR2) IS
aDoc varchar2(500);
aDataDoc date;
BEGIN
  select 
    &apos;Linia: &apos;||LINIA||&apos;-&gt;&apos;||aLINIA, datadoc into aDoc, adatadoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  UPDATE PREDARIPLUS SET LINIA = ALINIA WHERE IDINREG = AIDINREG;
  COMMIT;
END;  

PROCEDURE UPDATE_UA(AIDINREG IN NUMBER, AUA IN VARCHAR2) IS
aDoc varchar2(500);
aDataDoc date;  
BEGIN
  select 
    UA||&apos;-&gt;&apos;||aUA, datadoc into aDoc, adatadoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  UPDATE PREDARIPLUS SET UA = AUA WHERE IDINREG = AIDINREG;
  COMMIT;
END;

PROCEDURE UPDATE_SECTIE(AIDINREG IN NUMBER, ASECTIE IN VARCHAR2) IS
aDoc varchar2(500);
aDataDoc date;  
BEGIN
  select 
    sectie||&apos;-&gt;&apos;||aSectie, datadoc into aDoc, adatadoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  UPDATE PREDARIPLUS SET SECTIE = ASECTIE WHERE IDINREG = AIDINREG;
  COMMIT;
END;

PROCEDURE UPDATE_CANTITATE(AIDINREG IN NUMBER, ACANTITATE IN NUMBER) IS
aDoc varchar2(500);
aDataDoc date;  
BEGIN
  select 
    to_char(cantitate)||&apos;-&gt;&apos;||to_char(aCantitate), datadoc into aDoc, adatadoc
  from predariplus where idinreg = aIDInreg;
  WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, AIDINREG, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  UPDATE PREDARIPLUS SET CANTITATE = ACANTITATE WHERE IDINREG = AIDINREG;
  COMMIT;
END;

PROCEDURE PP_LOCK_ALLFREE(AUSERID IN NUMBER, ACODAFA IN VARCHAR2, ADATASTART IN VARCHAR2, ADATASTOP IN VARCHAR2) IS
BEGIN
  IF ADATASTART IS NULL AND ADATASTOP IS NULL THEN
    IF NOT ACODAFA IS NULL THEN
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND trim(CODAFA) = ACODAFA;
    ELSE
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL;
    END IF;
  END IF;
  IF NOT ADATASTART IS NULL AND ADATASTOP IS NULL THEN
    IF NOT ACODAFA IS NULL THEN
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND trim(CODAFA) = ACODAFA AND DATADOC &gt;= TO_DATE(ADATASTART,&apos;DD.MM.YYYY&apos;);
    ELSE
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND DATADOC &gt;= TO_DATE(ADATASTART,&apos;DD.MM.YYYY&apos;);
    END IF;
  END IF;
  IF ADATASTART IS NULL AND NOT ADATASTOP IS NULL THEN
    IF NOT ACODAFA IS NULL THEN
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND trim(CODAFA) = ACODAFA AND DATADOC &lt;= TO_DATE(ADATASTOP,&apos;DD.MM.YYYY&apos;);
    ELSE
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND DATADOC &lt;= TO_DATE(ADATASTOP,&apos;DD.MM.YYYY&apos;);
    END IF;
  END IF;
  IF NOT ADATASTART IS NULL AND NOT ADATASTOP IS NULL THEN
    IF NOT ACODAFA IS NULL THEN
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND trim(CODAFA) = ACODAFA AND DATADOC BETWEEN TO_DATE(ADATASTART,&apos;DD.MM.YYYY&apos;) AND TO_DATE(ADATASTOP,&apos;DD.MM.YYYY&apos;);
    ELSE
      UPDATE PREDARIPLUS
      SET
        USERIDBLOCAJ = AUSERID
      WHERE nvl(USERIDBLOCAJ,0) = 0 AND NRNP IS NULL AND DATADOC BETWEEN TO_DATE(ADATASTART,&apos;DD.MM.YYYY&apos;) AND TO_DATE(ADATASTOP,&apos;DD.MM.YYYY&apos;);
    END IF;
  END IF;
  COMMIT;
END;

PROCEDURE PP_LOCK(ACODCOMANDA1 IN NUMBER, AUSERID IN NUMBER, AID IN NUMBER, APRELUAT IN NUMBER) IS
ANRDOC NUMBER(20);
ADATADOC DATE;
ACODEXTERN VARCHAR2(80);
ASIMBOL VARCHAR2(15);
BEGIN
  BEGIN
    SELECT C.NRDOC, C.DATADOC,O.CODEXTERN,G.SIMBOL INTO ANRDOC, ADATADOC,ACODEXTERN,ASIMBOL
    FROM COMANDA1 C1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
         INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
    WHERE C1.CODCOMANDA1 = ACODCOMANDA1;
  EXCEPTION WHEN OTHERS THEN ANRDOC := 0;
  END;
  IF ANRDOC &gt; 0 THEN
    UPDATE PREDARIPLUS 
    SET
      NRCMD = TO_CHAR(ANRDOC),
      DATACMD = ADATADOC,
      USERIDBLOCAJ = AUSERID,
      CODCOMANDA1 = ACODCOMANDA1,
      CANTITATEWME = APRELUAT
    WHERE IDINREG = AID AND CODEXTERN = ACODEXTERN AND SECTIE = ASIMBOL;  
    COMMIT;
  END IF;       
END;  

PROCEDURE PP_RELEASE(AUSERID IN NUMBER) IS
BEGIN
  update predariplus set nrcmd = null, datacmd = null,cantitatewme = null,codcomanda1=null where useridblocaj is null and nrnp is null;
  DELETE PREDARIPLUS PP
  WHERE USERIDBLOCAJ = AUSERID AND NRNP IS NULL AND CANTITATE IS NULL
  AND EXISTS(SELECT IDINREG FROM PREDARIPLUS P WHERE PP.CODAFA = P.CODAFA AND P.NRNP IS NULL AND P.IDINREG &lt;&gt; PP.IDINREG);
  
  UPDATE PREDARIPLUS 
  SET
    NRCMD = null,
    DATACMD = null,
    USERIDBLOCAJ = null,
    CODCOMANDA1 = null,
    CANTITATEWME = case when cantitate is null then cantitatewme else null end
  WHERE USERIDBLOCAJ = AUSERID AND NRNP IS NULL;  
  COMMIT;
END;

PROCEDURE PP_UPDATENP(AUSERID IN NUMBER, ACODCOMANDA1 IN NUMBER, ACODINTR IN NUMBER) IS
BEGIN
  FOR V_REC IN (SELECT TO_CHAR(i.nrdoc) NRDOC, i.datadoc, i1.obs, f.den_formatie, i.schimb, I.DATACREARE, I1.CODINTR1
                FROM INTRARI I
                     INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
                     LEFT JOIN FORMATII F ON F.CODFORMATIE = I.CODFORMATIE
                WHERE I.CODINTR = ACODINTR AND I1.CODCMDINT1 = ACODCOMANDA1) LOOP
    FOR V_PP IN (SELECT PP.IDINREG 
                 FROM PREDARIPLUS PP
                      INNER JOIN COMANDA1 C1 ON PP.CODCOMANDA1 = C1.CODCOMANDA1
                      INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                      INNER JOIN NARTOBJ O ON C1.CODOBIECT = O.CODOBIECT
                      INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
                 WHERE PP.USERIDBLOCAJ = AUSERID AND PP.CODCOMANDA1 = ACODCOMANDA1
                       AND O.CODEXTERN = PP.CODEXTERN AND G.SIMBOL = PP.SECTIE
                ) LOOP
      UPDATE PREDARIPLUS
      SET
        FSC = V_REC.OBS,
        NRNP = V_REC.NRDOC,
        DATANP = V_REC.DATADOC,
        USERIDBLOCAJ = null,
        FORMATIE = V_REC.DEN_FORMATIE,
        SCHIMB = V_REC.SCHIMB,
        DATAWME = V_REC.DATACREARE
      WHERE IDINREG = V_PP.IDINREG;
      DELETE PPLINK WHERE IDINREG = V_PP.IDINREG;
      INSERT INTO PPLINK(IDINREG, CODCOMANDA1, CODINTR1)
      VALUES (V_PP.IDINREG, ACODCOMANDA1, V_REC.CODINTR1);
    END LOOP;
  END LOOP;
  COMMIT;
END;  

PROCEDURE SCADECANT(AID IN NUMBER, DESCAZUT IN NUMBER) IS
BEGIN
  UPDATE PREDARIPLUS SET
  CANTITATE = CANTITATE - DESCAZUT
  WHERE IDINREG = AID;
  COMMIT;
END;  

FUNCTION DUPLICARE(AID IN NUMBER, ACANT IN NUMBER) RETURN NUMBER IS
NEWID NUMBER(20);
aDoc varchar2(500);
aDataDoc date;
BEGIN
  select &apos;DUPLICAT PENTRU &apos;||to_char(AID), datadoc into aDoc, aDataDoc FROM PREDARIPLUS WHERE IDINREG = AID;  
  BEGIN
    SELECT MAX(IDINREG) + 1 INTO NEWID FROM PREDARIPLUS;
    INSERT INTO PREDARIPLUS(
      IDINREG, 
      NRDOC, 
      DATADOC, 
      CODAFA, 
      CODEXTERN, 
      UA, 
      SECTIE, 
      CANTITATEWME, 
      DATAMODIF, 
      NRCMD, 
      DATACMD, 
      FSC, 
      SCHIMB, 
      FORMATIE, 
      NRNP, 
      DATANP, 
      USERIDBLOCAJ, 
      CODCOMANDA1)
    SELECT 
      NEWID, 
      NRDOC, 
      DATADOC, 
      CODAFA, 
      CODEXTERN, 
      UA, 
      SECTIE, 
      ACANT, 
      SYSDATE, 
      NRCMD, 
      DATACMD, 
      FSC, 
      SCHIMB, 
      FORMATIE, 
      NRNP, 
      DATANP, 
      PKG_GLOBALS.GETUSERID, 
      CODCOMANDA1
    FROM PREDARIPLUS WHERE IDINREG = AID;
    COMMIT;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PREDARIPLUS&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, NEWID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,PKG_GLOBALS.GET_EXE_VERSION);
  EXCEPTION WHEN OTHERS THEN NEWID := 0;
  END;  
  RETURN NEWID;
END;  

PROCEDURE VERIFCANTWME IS
PrimaZi date;
PrimaZiPrec date;
BEGIN
  SELECT trunc(sysdate) - (to_number(to_char(sysdate,&apos;DD&apos;)) - 1) into PrimaZi FROM dual;
  PrimaZiPrec := PrimaZi - 31;
  FOR V_REC IN 
  (
    SELECT PP.IDINREG
    FROM PREDARIPLUS PP
         INNER JOIN (SELECT COUNT(*) CATE, CODAFA FROM PREDARIPLUS GROUP BY CODAFA) CT ON CT.CODAFA = PP.CODAFA
    WHERE CT.CATE = 1 AND PP.CANTITATEWME IS NULL AND NOT NRNP IS NULL AND USERIDBLOCAJ IS NULL
          AND PP.DATADOC BETWEEN PRIMAZIPREC AND SYSDATE
  ) LOOP
    BEGIN
      UPDATE PREDARIPLUS SET CANTITATEWME = CANTITATE WHERE IDINREG = V_REC.IDINREG;
      COMMIT;
    EXCEPTION WHEN OTHERS THEN NULL;
    END;
  END LOOP;
  
  FOR V_REC IN (SELECT * FROM (
                SELECT
                  PP.IDINREG,
                  PP.NRNP PP_NRNP, PP.DATANP PP_DATANP, PP.FSC PP_FSC, PP.NRCMD PP_NRCMD, PP.DATACMD PP_DATACMD, PP.FORMATIE PP_FORMATIE, PP.SCHIMB PP_SCHIMB, PP.CODCOMANDA1 PP_CODCOMANDA1,
                  TO_CHAR(I.NRDOC) NRNP, I.DATADOC DATANP, TO_CHAR(C.NRDOC) NRCMD, C.DATADOC DATACMD, I1.OBS FSC, I.SCHIMB, F.DEN_FORMATIE FORMATIE, L.CODCOMANDA1
                FROM PREDARIPLUS PP
                     INNER JOIN PPLINK L ON PP.IDINREG = L.IDINREG
                     INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODCOMANDA1
                     INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                     INNER JOIN INTRARI1 I1 ON L.CODINTR1 = I1.CODINTR1 AND I1.CODCMDINT1 = C1.CODCOMANDA1
                     INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
                     LEFT JOIN FORMATII F ON F.CODFORMATIE = I.CODFORMATIE
                WHERE PP.DATADOC BETWEEN PRIMAZIPREC AND SYSDATE
                             )
                WHERE CODCOMANDA1 &lt;&gt; PP_CODCOMANDA1 OR
                      NRNP &lt;&gt; PP_NRNP OR
                      DATANP &lt;&gt; PP_DATANP OR
                      FSC &lt;&gt; PP_FSC OR
                      FORMATIE &lt;&gt; PP_FORMATIE OR
                      SCHIMB &lt;&gt; PP_SCHIMB OR
                      NRCMD &lt;&gt; PP_NRCMD OR
                      DATACMD &lt;&gt; PP_DATACMD
                ) LOOP
    IF V_REC.CODCOMANDA1 &lt;&gt; V_REC.PP_CODCOMANDA1 THEN
      BEGIN 
        UPDATE PREDARIPLUS SET CODCOMANDA1 = V_REC.CODCOMANDA1 WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;  
    END IF;
    IF V_REC.NRNP &lt;&gt; V_REC.PP_NRNP THEN
      BEGIN
        UPDATE PREDARIPLUS SET NRNP = V_REC.NRNP WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;  
    END IF;
    IF V_REC.DATANP &lt;&gt; V_REC.PP_DATANP THEN
      BEGIN
        UPDATE PREDARIPLUS SET DATANP = V_REC.DATANP WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
    IF V_REC.FSC &lt;&gt; V_REC.PP_FSC THEN
      BEGIN
        UPDATE PREDARIPLUS SET FSC = V_REC.FSC WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
    IF V_REC.FORMATIE &lt;&gt; V_REC.PP_FORMATIE THEN
      BEGIN
        UPDATE PREDARIPLUS SET FORMATIE = V_REC.FORMATIE WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
    IF V_REC.SCHIMB &lt;&gt; V_REC.PP_SCHIMB THEN
      BEGIN
        UPDATE PREDARIPLUS SET SCHIMB = V_REC.SCHIMB WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
    IF V_REC.NRCMD &lt;&gt; V_REC.PP_NRCMD THEN
      BEGIN
        UPDATE PREDARIPLUS SET NRCMD = V_REC.NRCMD WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
    IF V_REC.DATACMD &lt;&gt; V_REC.PP_DATACMD THEN
      BEGIN
        UPDATE PREDARIPLUS SET DATACMD = V_REC.DATACMD WHERE IDINREG = V_REC.IDINREG;
        COMMIT;
      EXCEPTION WHEN OTHERS THEN NULL;
      END;
    END IF;
  END LOOP;
END;

end PKG_PREDARIPLUS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRESTATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98374EA2199B4CEB1A6C7B6791274E8FFF5EC2F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PRESTATII is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CODPRESTATIE INTO Tmp FROM PRESTATII WHERE CODPRESTATIE = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE PRESTATII WHERE CODPRESTATIE = RecId;
  NotifyModif(2, RecId, &apos;PRESTATII&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PRESTATII (CODPRESTATIE) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_PRESTATII
    (
     CODPRESTATIE, 
     COD, 
     DENUMIRE 
     )
  SELECT 
     CODPRESTATIE, 
     COD, 
     DENUMIRE
  FROM PRESTATII
  WHERE CODPRESTATIE = RecId;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN
    SELECT CODPRESTATIE INTO RecId FROM TMP_PRESTATII;
    UPDATE PRESTATII
    SET (COD, 
         DENUMIRE )
     = (SELECT 
          COD, 
          DENUMIRE
        FROM TMP_PRESTATII )
    WHERE CODPRESTATIE = RecId;   
  ELSE  
    SELECT SEQ_PRESTATII_CODPRESTATIE.Nextval INTO RecID From DUAL;
    INSERT INTO PRESTATII 
    (CODPRESTATIE, 
     COD, 
     DENUMIRE )
    SELECT 
      RECID, 
      COD, 
      DENUMIRE
     FROM TMP_PRESTATII;
  END IF;
  NotifyModif(Operation, RecId, &apos;PRESTATII&apos;);
  COMMIT;
END;

end PKG_PRESTATII;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29AB944A598745CA2792D599E31E1FFEB7A5D038</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PRETPROD IS

procedure CheckNS1Reziduale is
begin
  update nirstoc1 ns1 set
    codcomanda1 = null,
    pretmat = (select nvl(ns.pret,0) - nvl(ns.adaos,0) from nirstoc ns where ns.codnirstoc = ns1.codnirstoc),
    dirty = 0,
    dinstoc = 1
  where ns1.tipdoc = 7 and exists
  (select ns.codnirstoc
   from nirstoc ns
        inner join intrari1 i1 on ns.codintr1 = i1.codintr1
        inner join comanda1 c1 on i1.codcmdint1 = c1.codcomanda1
   where c1.codobiect &lt;&gt; i1.codobiect and ns.codnirstoc = ns1.codnirstocorig);
   commit;
end;

procedure UpdateNirStoc1Consumuri(aCodNirStoc in number) is
aRoot NUMBER(20);
aTipNir NUMBER(10);
aCodComanda1 number(20);
aPret number(20,7);
aProd number(1);
begin
  delete from tmp_manevra where codunic = aCodNirStoc;
  insert into tmp_manevra(codunic)
  select
    distinct nsl.codnirstoc
  from nirstoc ns
       inner join intrari1 i1 on i1.codintr1 = ns.codintr1
       inner join cmdprodmat prod on prod.codcomanda1 = i1.codcmdint1 and nvl(prod.tip,0) = 0
       inner join (select sum(i1.cant) cant, i1.codcmdint1
                   from intrari1 i1
                        inner join intrari i on i1.codintr = i.codintr
                   where i1.codcmdint1 &gt; 0
                   group by i1.codcmdint1) predat on predat.codcmdint1 = prod.codcomanda1
       inner join iesiri1 ies1 on ies1.codcmdint1 = prod.codcomanda1
       inner join iesiri ies on ies.codies = ies1.codies
       inner join livr l on l.codies = ies.codies
       inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
       inner join nirstoc nsl on nsl.codnirstoc = l1.codnirstoc
       left  join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
  where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and ns.codnirstoc = aCodNirStoc and nvl(ns1.codnirstoc,0) = 0;

  aRoot := pkg_list_base_utils.GETCODNIRSTOC_ORIG(acodnirstoc);
  begin
    select NIR.TIPNIR, nvl(i1.codcmdint1,0), case when i1.codobiect = c1.codobiect then 1 else 0 end into aTipNir, aCodComanda1, aProd
    from NIRSTOC ns
         inner join nir on nir.codnir = ns.codnir
         left join intrari1 i1 on i1.codintr1 = ns.codintr1
         left join comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
    where ns.codnirstoc = aRoot;
  exception when others then aTipNir := 0; aCodComanda1 := 0;
  end;

  aPret := 0;
  if aTipNir &lt;&gt; 7 then
    begin
      select nvl(pret,0)-nvl(adaos,0) into aPret
      from nirstoc
      where codnirstoc = aCodNirstoc;
    exception when others then aPret := 0;
    end;
  end if;

  insert into nirstoc1 (codnirstoc, codnirstocorig, tipdoc, dirty, codcomanda1, pretmat)
  values (acodnirstoc, aRoot, aTipNir, 1, case when aTipNir = 7 and aProd = 1 then aCodComanda1 else 0 end, aPret);
end;

procedure CorecteazaNirStoc_Parinte IS
  CURSOR rec_cur IS
    SELECT ns.codnirstoc
    FROM nirstoc ns INNER JOIN nirstoc nsp ON nsp.codnirstoc = Coalesce(ns.codnirstocparinte,0)
    WHERE Coalesce(ns.codnirstocparinte,0) &lt;&gt; 0 AND Coalesce(ns.codnirstocparinte,0) &lt; ns.codnirstoc AND Coalesce(nsp.codnirstocparinte,0) = ns.codnirstoc;

  TYPE num_tab_t IS TABLE OF NUMBER(20);
  pk_tab NUM_TAB_T;
BEGIN
  OPEN rec_cur;
  LOOP
    FETCH rec_cur BULK COLLECT INTO pk_tab LIMIT 10000;
    EXIT WHEN pk_tab.COUNT() = 0;
    FORALL i IN pk_tab.FIRST .. pk_tab.LAST UPDATE nirstoc SET codnirstocparinte = 0 WHERE codnirstoc = pk_tab(i);
  END LOOP;
  CLOSE rec_cur;
END;

PROCEDURE PopuleazaNirStoc1 IS
BEGIN
  CorecteazaNirStoc_Parinte;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE nirstoc1&apos;;
  INSERT INTO nirstoc1 ( codnirstoc, codnirstocorig, tipdoc, pretmat, dirty, dinstoc, codcomanda1)
  WITH tmp(codnirstoc, codnirstocorig, tipdoc, PretMat, dirty, DinStoc, CodComanda1) AS (
    SELECT
      ns.codnirstoc, ns.codnirstoc codnirstocorig, n.tipnir tipdoc,
      CASE WHEN Nvl(D.CodDvi,0) = 0 AND Nvl(i1.codcmdint1,0) = 0 THEN Nvl(ns.pret,0)-Nvl(ns.adaos,0) ELSE 0 END PretMat,
      CASE WHEN Nvl(i1.codcmdint1,0) = 0 THEN 0 ELSE 1 END dirty,
      1 DinStoc, nvl(i1.codcmdint1,0) CodComanda1
    FROM nirstoc ns
      LEFT JOIN nir n ON n.codnir = ns.codnir
      LEFT JOIN intrari1 i1 ON i1.codintr1 = ns.codintr1
      LEFT JOIN dvi d ON d.codintr = n.codintr AND d.tipimport = 1
    WHERE Coalesce(CodNirstocParinte,0) = 0
    UNION ALL
    SELECT
      ns.codnirstoc, tmp.codnirstocorig, tmp.tipdoc, tmp.PretMat, tmp.dirty, tmp.DinStoc, tmp.CodComanda1
    FROM tmp INNER JOIN nirstoc ns ON Coalesce(ns.codnirstocparinte,0) = tmp.codnirstoc
  )
  SELECT codnirstoc, codnirstocorig, tipdoc, pretmat, dirty, dinstoc, codcomanda1
  FROM tmp;

  COMMIT;
END;

PROCEDURE CompleteazaNirStoc1 IS
BEGIN
  CorecteazaNirStoc_Parinte;
  INSERT INTO nirstoc1 ns1
  SELECT
    ns.codnirstoc, ns.codnirstoc codnirstocorig, n.tipnir tipdoc,
    CASE WHEN Nvl(D.CodDvi,0) = 0 AND Nvl(i1.codcmdint1,0) = 0 THEN Nvl(ns.pret,0)-Nvl(ns.adaos,0) ELSE 0 END PretMat,
    CASE WHEN Nvl(i1.codcmdint1,0) = 0 THEN 0 ELSE 1 END dirty,
    1 DinStoc, case when c1.codobiect = i1.codobiect then nvl(i1.codcmdint1,0) else null end CodComanda1
  FROM nirstoc ns
    LEFT JOIN nirstoc1 ns1 ON ns1.codnirstoc = ns.codnirstoc
    LEFT JOIN nir n ON n.codnir = ns.codnir
    LEFT JOIN intrari1 i1 ON i1.codintr1 = ns.codintr1
    LEFT JOIN dvi d ON d.codintr = n.codintr AND d.tipimport = 1
    LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = I1.CODCMDINT1
  WHERE Nvl(CodNirstocParinte,0) = 0 AND ns1.codnirstoc IS NULL;

  COMMIT;

  /*EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_nirstoc1&apos;;

  INSERT INTO tmp_nirstoc1 (codnirstoc, codnirstocorig, tipdoc, pretmat, dirty, dinstoc, codcomanda1)
  WITH tmp(codnirstoc, codnirstocorig, tipdoc, PretMat, dirty, DinStoc, CodComanda1) AS (
    SELECT codnirstoc, codnirstocorig, tipdoc, PretMat, dirty, DinStoc, CodComanda1
    FROM nirstoc1
    WHERE codnirstoc = codnirstocorig
    UNION ALL
    SELECT ns.codnirstoc, tmp.codnirstocorig, tmp.tipdoc, tmp.PretMat, tmp.dirty, tmp.DinStoc, tmp.CodComanda1
    FROM tmp INNER JOIN nirstoc ns ON Nvl(ns.codnirstocparinte,0) = tmp.codnirstoc
  )
  SELECT codnirstoc, codnirstocorig, tipdoc, pretmat, dirty, dinstoc, codcomanda1
  FROM tmp;

  DELETE tmp_nirstoc1 WHERE codnirstoc IN (SELECT codnirstoc FROM nirstoc1);
  INSERT INTO nirstoc1 SELECT * FROM tmp_nirstoc1;
  COMMIT;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_nirstoc1&apos;;
  */
END;

PROCEDURE CheckNirStoc1 IS
  nr  number;
  nr1 number;
BEGIN
  DELETE nirstoc1 ns1 WHERE NOT EXISTS (SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = NS1.CODNIRSTOC);
  DELETE nirstoc1 ns1 WHERE NOT EXISTS (SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = NS1.CODNIRSTOCORIG);
  COMMIT;

  SELECT count(*) INTO nr  FROM nirstoc;
  SELECT count(*) INTO nr1 FROM nirstoc1;
  IF Nr &lt;&gt; Nr1 THEN
    IF Nr1 = 0
    THEN PopuleazaNirStoc1;
    ELSE CompleteazaNirStoc1;
    END IF;
  END IF;

  SELECT count(*) INTO nr  FROM nirstoc;
  SELECT count(*) INTO nr1 FROM nirstoc1;
  IF nr1 &gt; nr THEN
    DELETE nirstoc1 ns1 WHERE NOT EXISTS (SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = NS1.CODNIRSTOC);
    COMMIT;
  END IF;

  CheckNS1Reziduale;
END;

procedure CheckInfoCursor(Total out number, Realizat out number) is
  nr  number;
  nr1 number;
begin
  select count(*) into nr  from nirstoc;
  select count(*) into nr1 from nirstoc1;
  if nr1 &gt; nr then
    delete nirstoc1 ns1 where not exists (select ns.codnirstoc from nirstoc ns where ns.codnirstoc = ns1.codnirstoc);
    select count(*) into nr1 from nirstoc1;
  end if;
  if Nr = Nr1 THEN
    Get_DifPretProdAllSubunit;
    select count(*) into Realizat
    from TMP_BALANTA_STOC tmp
         inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect
    where nvl(ns1.dirty,0) = 0;

    select count(*) into Total
    from TMP_BALANTA_STOC tmp
         inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect;
  else
    Total    := 1;
    Realizat := 0;
  end if;
end;

procedure GetDateCursorLuna is
begin
  Get_DifPretProdAllSubunit;
  commit;
end;

procedure PreiaInfoCursor(Total out number, Realizat out number) is
begin
  CheckNirStoc1;
  select count(*) into Realizat
  from TMP_BALANTA_STOC tmp
       inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect
  where nvl(ns1.dirty,0) = 0;

  select count(*) into Total
  from TMP_BALANTA_STOC tmp
       inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect;
  commit;
end;

function PregatireCalcul return number is
total number;
nr number;
aCod number(20);
begin
  total := 0;

  update nirstoc1 ns1 set dirty = 1
  where Exists (select bs.codobiect from tmp_balanta_stoc bs where bs.Codobiect = ns1.codnirstoc);
  commit;

  select count(*) into Total
  from TMP_BALANTA_STOC tmp;
  return Total;
end;

function InsereazaCopii(aCodNirStoc in number, aNivel in number, creanga in varchar2, ind in  number) return number is
  NR number;
  Rez number;
  aCodComanda1 number(20);
  acount number(10);
begin
  Nr := InStr(creanga,&apos;.&apos;||aCodNirStoc||&apos;.&apos;);
  if NR = 0 then
    select count(*) into acount from TMP_MANEVRA_LINIICOMENZI
    where codcomanda1 = acodnirstoc and cant = anivel;
    if acount = 0 then
      Insert into TMP_MANEVRA_LINIICOMENZI (CodComanda1, CANT) values(aCodNirStoc, aNivel);
      Select CodComanda1 into aCodComanda1 from Nirstoc1 where CodNirStoc = aCodNirStoc;
      Rez := 0;
      if aCodComanda1 &gt; 0 then
        for v_rec in (
          select ns1.codnirstoc, Ind
          from iesiri1 ies1
               inner join iesiri ies on ies.codies = ies1.codies
               inner join livr1 l1 on l1.codies1 = ies1.codies1
               inner join livr l on ies.codies = l.codies and l1.codlivr = l.codlivr
               inner join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc and ns1.CodComanda1 &gt; 0
          where
              ies1.codcmdint1 = aCodComanda1
              and ies.anulat = 0 and ies.operat = 1 and ns1.codnirstoc &lt;&gt; aCodNirStoc
          ) loop
          Rez := Rez + InsereazaCopii(v_rec.codnirstoc, aNivel + 1, creanga||aCodNirStoc||&apos;.&apos;, ind);
        end loop;
      end if;
    end if;
  else
    Rez := 1;
    Insert into TMP_MANEVRA2 (CodUnic) values(aCodNirStoc);
    update nirstoc1 set dirty = 0, dinstoc = 1 where codnirstoc = aCodNirStoc;
  end if;
  Return Rez;
end;

function UpdatePretNS1Partial(Cate in number) return number is
  Ind number;
  Rez number;
  NrInreg number;
  LoopTot number;
  LoopInd number;
  aPret number(20,7);
begin
  Rez := 0;
  select Count(*) into LoopTot from TMP_BALANTA_STOC tmp
                               inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect where ns1.dirty = 1;
  LoopInd := 0;
  PKG_GLOBALS.StartEvolutie(1, PKG_GLOBALS.GetUserID, LoopTot, &apos;Insereaza copii&apos;);
  Ind := 1;
  while Ind &gt; 0 loop
     EXECUTE IMMEDIATE &apos;truncate table TMP_MANEVRA2&apos;;
     EXECUTE IMMEDIATE &apos;truncate table TMP_MANEVRA_LINIICOMENZI&apos;;
     Ind := 0;
     for v_rec in ( select tmp.CodObiect codnirstoc
                    from TMP_BALANTA_STOC tmp
                    inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect where ns1.dirty = 1 and RowNum &lt; 1001)
     loop
        Rez := Rez + InsereazaCopii(v_rec.codnirstoc, 0, &apos;.&apos;, Ind);
        Ind := Ind + 1;
     end loop;
     if Ind &gt; 0 then
       for v_rec in ( select X.codnirstoc, NS1.CodComanda1, X.Nivel, NS1.PretMat
                       from ( select Distinct Tmp.CodComanda1  codnirstoc, Max(tmp.Cant) Nivel
                              from TMP_MANEVRA_LINIICOMENZI tmp
                              where not exists (select t2.codunic from tmp_manevra2 t2 where tmp.codcomanda1 = t2.codunic)
                              group by tmp.CodComanda1
                             ) X
                       inner join NirStoc1 NS1 on NS1.CodNirStoc = X.codnirstoc
                       order by X.Nivel desc)
       loop
          begin
            select nvl(NS1.PretMat,0) * (1 - NS1.Dirty) into aPret
            from   NirStoc1 NS1
            where  NS1.CODNIRSTOC = v_rec.codnirstoc;
          exception when others then aPret := 0;
          end;

          if aPret = 0 then
            if v_rec.CodComanda1 = 0 then
              aPret := v_rec.PretMat;
            else
              aPret := GetPretMat(v_rec.CodComanda1);
            end if;
          end if;

          if v_rec.CodComanda1 &gt; 0 then
            update nirstoc1 set pretmat = aPret, dirty = 0 where codcomanda1 = v_rec.codcomanda1;
          else
            update nirstoc1 set pretmat = aPret, dirty = 0 where codnirstoc = v_rec.codnirstoc;
          end if;
       end loop;
       select LoopTot - Count(*) into LoopInd from TMP_BALANTA_STOC tmp
                                    inner join nirstoc1 ns1 on ns1.codnirstoc = tmp.codobiect where ns1.dirty = 1;
       PKG_GLOBALS.SetEvolutie(1, PKG_GLOBALS.GetUserID, LoopInd);
     end if;
  end loop;

  update nirstoc1 ns1 set pretmat = 0, dirty = 1
  where exists (select t2.codunic from tmp_manevra2 t2 where ns1.codnirstoc = t2.codunic);

  commit;
  Return Rez;
end;

function GetPretMat(aCodComanda1 in number) return number is
aPredat number(20,7);
aValMat number(20,7);
aPret number(20,7);
begin
  aPredat   := 0;
  aValMat   := 0;
  select sum(i1.cant) into aPredat
  from intrari1 i1
       inner join intrari i on i1.codintr = i.codintr and i.anulat=0 and i.operat=1
       inner join comanda1 c1 on c1.codcomanda1 = i1.codcmdint1
  where c1.codobiect = i1.codobiect and c1.codcomanda1 = aCodComanda1;

  select Sum(l1.cant*nvl(ns1.pretmat,0)) into aValMat
  from iesiri1 ies1
       inner join iesiri ies on ies.codies = ies1.codies and ies.anulat=0 and ies.operat=1
       inner join livr1 l1 on l1.codies1 = ies1.codies1
       inner join livr l on ies.codies = l.codies and l1.codlivr = l.codlivr
       left  join nirstoc1 ns1 on ns1.codnirstoc = l1.codnirstoc
  where ies1.codcmdint1 = aCodcomanda1;

  if aPredat = 0 then
    aPret := 0;
  else
    aPret :=  Round(aValMat/aPredat,7);
  end if;
  return aPret;
end;

function UpdateNirStoc1InLuna return number is
  Rez number;
  Nr number;
begin
  GetDateCursorLuna;
  select count(*) into nr from tmp_balanta_stoc;
  Rez := UpdatePretNS1Partial(nr);
  Return Rez;
end;

procedure Get_DifPretProdAllSubunit is
aAn number(4);
aLuna number(2);
begin
  aAn := PKG_GLOBALS.GetANLUCRU;
  aLuna := PKG_GLOBALS.GetLUNALUCRU;

  Delete TMP_BALANTA_STOC;

  PKG_DIFPRETPROD.MAKE_STOCINITIAL_LUNA(aAN, aLUNA);
  PKG_DIFPRETPROD.MAKE_MISCARI_IN_LUNA(aAN, aLUNA);

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_LA_DATA N
  ON (nvl(N.CODOBIECT,0) = nvl(SD.CODOBIECT,0))
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (nvl(N.CODOBIECT,0), N.CANTNIR, 0, 0);

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_IN_INTERVALUL N
  ON (nvl(N.CODOBIECT,0) = nvl(SD.CODOBIECT,0))
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (nvl(N.CODOBIECT,0), 0, N.CANTNIR,  0)
  WHEN     MATCHED THEN UPDATE SET SD.INTRARI = N.CANTNIR;

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_IN_INTERVALUL N
  ON (nvl(N.CODOBIECT,0) = nvl(SD.CODOBIECT,0))
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (nvl(N.CODOBIECT,0), 0, 0, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = N.CANTNIR;
--aici e pregatite codnirstoc-urile
  --PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  --PKG_DIFPRETPROD.MAKE_MISCARI_BalantaStoc(aAN, aLUNA);
  delete TMP_BALANTA_STOC bs where Nvl(bs.stocinitial,0) = 0 and Nvl(bs.Intrari,0) = 0 and Nvl(bs.iesiri,0) = 0;
end;

function GetPretNirStoc1Mat(aCodNirStoc in number, CuResetManevra in boolean default true) return number is
aPredat number(20,7);
aValMat number(20,7);
aPret number(20,7);
aCount number(10);
begin
  if CuResetManevra then
    delete tmp_manevra2;
  end if;
  aPredat   := 0;
  aValMat := 0;
  for v_rec in (
    select
      predat.cant predat,
      NVL(l1.cant,0) cantlivr,
      NVL(ns1.pretmat,0) pu,
      nvl(nsi.pret,0) - nvl(nsi.adaos,0) puns,
      nvl(ns1.tipdoc,0) tipdoc,
      nvl(ns1.dirty,1) dirty,
      nsi.codnirstoc
    from nirstoc1 nsp
         inner join nirstoc ns on ns.codnirstoc = nsp.codnirstocorig
         inner join intrari1 i1 on i1.codintr1 = ns.codintr1
         inner join cmdprodmat prod on prod.codcomanda1 = i1.codcmdint1 and nvl(prod.tip,0) = 0
         inner join (select sum(i1.cant) cant, i1.codcmdint1
                     from intrari1 i1
                          inner join intrari i on i1.codintr = i.codintr
                     where i1.codcmdint1 &gt; 0 and nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1
                     group by i1.codcmdint1) predat on predat.codcmdint1 = prod.codcomanda1
         inner join iesiri1 ies1 on ies1.codcmdint1 = prod.codcomanda1
         inner join iesiri ies on ies.codies = ies1.codies
         inner join livr l on l.codies = ies.codies
         inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
         inner join nirstoc  nsi on nsi.codnirstoc = l1.codnirstoc
         left  join nirstoc1 ns1 on ns1.codnirstoc = nsi.codnirstoc
    where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and nsp.codnirstoc = aCodNirStoc
    ) loop
    aPredat := v_Rec.Predat;
    select count(*) into acount from tmp_manevra2 where codunic = v_rec.codnirstoc;
    if acount &gt; 0 then
      aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
    else
      insert into tmp_manevra2(codunic) values (v_Rec.Codnirstoc);
      if v_rec.tipdoc = 7 and v_Rec.dirty = 1 then
        aValMat := aValMat + v_Rec.cantlivr * GetPretNirStoc1Mat(v_rec.codnirstoc, false);
      else if v_rec.tipdoc = 7 and v_Rec.dirty = 0 then
        aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
      else if v_Rec.dirty = 1 then
        aValMat := aValMat + v_Rec.cantlivr * v_rec.puns;
      else
        aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
      end if;end if;end if;
    end if;
  end loop;

  if aPredat = 0 then
    aPret := 0;
  else
    aPret :=  aValMat/aPredat;
  end if;
  return aPret;
end;

function GetValConsumPeComanda(aCodComanda1 in number, CuSupliment in number) return number is
aValMat number(20,7);
aPret number(20,7);
aCant number(20,7);
begin
  aValMat := 0;
  if Pkg_Categconst.GetValConstanta(&apos;CoefMatManInPretNP&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru) = 1 then
    if CuSupliment = 1 then
      for v_rec in (
        select
          l1.cant cantlivr,
          nvl(ns1.pretmat,0) pu,
          nvl(nsi.pret,0) - nvl(nsi.adaos,0) puns,
          nvl(ns1.tipdoc,0) tipdoc,
          nvl(ns1.dirty,1) dirty,
          nsi.codnirstoc,
          nvl(g.coefcheltmat,0) coefmat
        from iesiri1 ies1
             inner join iesiri ies on ies.codies = ies1.codies
             inner join ngest g on g.codgest = ies.codgestprod
             inner join livr l on l.codies = ies.codies
             inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
             inner join nirstoc  nsi on nsi.codnirstoc = l1.codnirstoc
             left  join nirstoc1 ns1 on ns1.codnirstoc = nsi.codnirstoc
        where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and ies1.codcmdint1 = aCodComanda1
        union all
        select
          i1.cant cantlivr,
          i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end,
          i1.pu puns,
          1 tipdoc,
          0 dirty,
          0 codnirstoc,
          0 coefmat
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
        where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
              and i1.codcmdint1 = aCodComanda1 and exists (
              select mat.codobiect
              from prodmat mat
                   inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                   inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
              where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
              )
        ) loop
        if v_rec.tipdoc = 7 and v_Rec.dirty = 1 then
          aValMat := aValMat + v_Rec.cantlivr * GetPretNirStoc1Mat(v_rec.codnirstoc) * (1 + v_rec.coefmat);
        else if v_rec.tipdoc = 7 and v_Rec.dirty = 0 then
          aValMat := aValMat + v_Rec.cantlivr * v_rec.pu * (1 + v_rec.coefmat);
        else if v_Rec.dirty = 1 then
          aValMat := aValMat + v_Rec.cantlivr * v_rec.puns * (1 + v_rec.coefmat);
        else
          aValMat := aValMat + v_Rec.cantlivr * v_rec.pu * (1 + v_rec.coefmat);
        end if;
        end if;
        end if;
      end loop;
    else
      for v_rec in (select mat.cant, mat.codcmdprodmat
                    from cmdprodmat mat
                    where mat.codcomanda1 = aCodComanda1 and tip = 1
                    ) loop
        aCant := v_rec.cant;
        for v_tmp in (select
                        l1.cant cantlivr,
                        nvl(ns1.pretmat,0) pu,
                        ies1.pu pretdoc,
                        nvl(nsi.pret,0) - nvl(nsi.adaos,0) puns,
                        nvl(ns1.tipdoc,0) tipdoc,
                        nvl(ns1.dirty,1) dirty,
                        nsi.codnirstoc,
                        nvl(g.coefcheltmat,0) coefmat
                      from iesiri1 ies1
                           inner join iesiri ies on ies.codies = ies1.codies
                           inner join ngest g on g.codgest = ies.codgestprod
                           inner join livr l on l.codies = ies.codies
                           inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
                           inner join nirstoc  nsi on nsi.codnirstoc = l1.codnirstoc
                           inner join iesprodlink l on l.codies1 = ies1.codies1
                           inner join cmdprodmat mat on mat.codcmdprodmat = l.codcmdprodmat
                           left  join nirstoc1 ns1 on ns1.codnirstoc = nsi.codnirstoc
                      where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and mat.codcmdprodmat = v_rec.codcmdprodmat
                      union all
                      select
                        i1.cant cantlivr,
                        i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end,
                        i1.pu pretdoc,
                        i1.pu puns,
                        1 tipdoc,
                        0 dirty,
                        0 codnirstoc,
                        0 coefmat
                      from intrari1 i1
                           inner join intrari i on i.codintr = i1.codintr
                      where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
                            and i1.codcmdint1 = aCodComanda1 and exists (
                            select mat.codobiect
                            from prodmat mat
                                 inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                                 inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
                            where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
                            )
                      ) loop
          if aCant = 0 then Exit; end if;
          if aCant &lt; v_tmp.cantlivr then
            if v_tmp.tipdoc = 7 and v_tmp.dirty = 1 then
              aValMat := aValMat + aCant * GetPretNirStoc1Mat(v_tmp.codnirstoc) * (1 + v_tmp.coefmat);
            else if v_tmp.tipdoc = 7 and v_tmp.dirty = 0 then
              aValMat := aValMat + aCant * v_tmp.pu * (1 + v_tmp.coefmat);
            else if v_tmp.dirty = 1 then
              aValMat := aValMat + aCant * v_tmp.puns * (1 + v_tmp.coefmat);
            else
              aValMat := aValMat + aCant * v_tmp.pu * (1 + v_tmp.coefmat);
            end if; end if; end if;
            aCant := 0;
          else
            if v_tmp.tipdoc = 7 and v_tmp.dirty = 1 then
              aValMat := aValMat + v_tmp.cantlivr * GetPretNirStoc1Mat(v_tmp.codnirstoc) * (1 + v_tmp.coefmat);
            else if v_tmp.tipdoc = 7 and v_tmp.dirty = 0 then
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.pu * (1 + v_tmp.coefmat);
            else if v_tmp.dirty = 1 then
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.puns * (1 + v_tmp.coefmat);
            else
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.pu * (1 + v_tmp.coefmat);
            end if; end if; end if;
            aCant := aCant - v_tmp.cantlivr;
          end if;
        end loop;
      end loop;
    end if;
  else
    if CuSupliment = 1 then
      for v_rec in (
        select
          l1.cant cantlivr,
          nvl(ns1.pretmat,0) pu,
          nvl(nsi.pret,0) - nvl(nsi.adaos,0) puns,
          nvl(ns1.tipdoc,0) tipdoc,
          nvl(ns1.dirty,1) dirty,
          nsi.codnirstoc
        from iesiri1 ies1
             inner join iesiri ies on ies.codies = ies1.codies
             inner join livr l on l.codies = ies.codies
             inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
             inner join nirstoc  nsi on nsi.codnirstoc = l1.codnirstoc
             left  join nirstoc1 ns1 on ns1.codnirstoc = nsi.codnirstoc
        where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and ies1.codcmdint1 = aCodComanda1
        union all
        select
          i1.cant cantlivr,
          i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end,
          i1.pu puns,
          1 tipdoc,
          0 dirty,
          0 codnirstoc
        from intrari1 i1
             inner join intrari i on i.codintr = i1.codintr
        where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
              and i1.codcmdint1 = aCodComanda1 and exists (
              select mat.codobiect
              from prodmat mat
                   inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                   inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
              where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
              )
        ) loop
        if v_rec.tipdoc = 7 and v_Rec.dirty = 1 then
          aValMat := aValMat + v_Rec.cantlivr * GetPretNirStoc1Mat(v_rec.codnirstoc);
        else if v_rec.tipdoc = 7 and v_Rec.dirty = 0 then
          aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
        else if v_Rec.dirty = 1 then
          aValMat := aValMat + v_Rec.cantlivr * v_rec.puns;
        else
          aValMat := aValMat + v_Rec.cantlivr * v_rec.pu;
        end if;
        end if;
        end if;
      end loop;
    else
      for v_rec in (select mat.cant, mat.codcmdprodmat
                    from cmdprodmat mat
                    where mat.codcomanda1 = aCodComanda1 and tip = 1
                    ) loop
        aCant := v_rec.cant;
        for v_tmp in (select
                        l1.cant cantlivr,
                        nvl(ns1.pretmat,0) pu,
                        ies1.pu pretdoc,
                        nvl(nsi.pret,0) - nvl(nsi.adaos,0) puns,
                        nvl(ns1.tipdoc,0) tipdoc,
                        nvl(ns1.dirty,1) dirty,
                        nsi.codnirstoc
                      from iesiri1 ies1
                           inner join iesiri ies on ies.codies = ies1.codies
                           inner join livr l on l.codies = ies.codies
                           inner join livr1 l1 on l1.codies1 = ies1.codies1 and l.codlivr = l1.codlivr
                           inner join nirstoc  nsi on nsi.codnirstoc = l1.codnirstoc
                           inner join iesprodlink l on l.codies1 = ies1.codies1
                           inner join cmdprodmat mat on mat.codcmdprodmat = l.codcmdprodmat
                           left  join nirstoc1 ns1 on ns1.codnirstoc = nsi.codnirstoc
                      where nvl(ies.anulat,0) = 0 and nvl(ies.operat, 0) = 1 and mat.codcmdprodmat = v_rec.codcmdprodmat
                      union all
                      select
                        i1.cant cantlivr,
                        i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end,
                        i1.pu pretdoc,
                        i1.pu puns,
                        1 tipdoc,
                        0 dirty,
                        0 codnirstoc
                      from intrari1 i1
                           inner join intrari i on i.codintr = i1.codintr
                      where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
                            and i1.codcmdint1 = aCodComanda1 and exists (
                            select mat.codobiect
                            from prodmat mat
                                 inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                                 inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
                            where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
                            )
                      ) loop
          if aCant = 0 then Exit; end if;
          if aCant &lt; v_tmp.cantlivr then
            if v_tmp.tipdoc = 7 and v_tmp.dirty = 1 then
              aValMat := aValMat + aCant * GetPretNirStoc1Mat(v_tmp.codnirstoc);
            else if v_tmp.tipdoc = 7 and v_tmp.dirty = 0 then
              aValMat := aValMat + aCant * v_tmp.pu;
            else if v_tmp.dirty = 1 then
              aValMat := aValMat + aCant * v_tmp.puns;
            else
              aValMat := aValMat + aCant * v_tmp.pu;
            end if; end if; end if;
            aCant := 0;
          else
            if v_tmp.tipdoc = 7 and v_tmp.dirty = 1 then
              aValMat := aValMat + v_tmp.cantlivr * GetPretNirStoc1Mat(v_tmp.codnirstoc);
            else if v_tmp.tipdoc = 7 and v_tmp.dirty = 0 then
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.pu;
            else if v_tmp.dirty = 1 then
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.puns;
            else
              aValMat := aValMat + v_tmp.cantlivr * v_tmp.pu;
            end if; end if; end if;
            aCant := aCant - v_tmp.cantlivr;
          end if;
        end loop;
      end loop;
    end if;
  end if;

  return aValMat;
end;

function GetValBonConsum(aCodComanda1 in number) return number is
aValMat number(20,7);
begin
  aValMat := 0;
  for v_rec in (select i1.pu*i1.cant valoare
                from iesiri1 i1
                     inner join iesiri i on i.codies = i1.codies
                where i.operat = 1 and i.anulat = 0 and i1.codcmdint1 = aCodComanda1
                union all
                select
                  i1.cant*i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end valoare
                from intrari1 i1
                     inner join intrari i on i.codintr = i1.codintr
                where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
                      and i1.codcmdint1 = aCodComanda1 and exists (
                      select mat.codobiect
                      from prodmat mat
                           inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                           inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
                      where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
                      )
                ) loop
    aValMat := aValMat + v_rec.valoare;
  end loop;
  return aValMat;
end;

function GetValBonConsumAchiz(aCodComanda1 in number) return number is
aValMat number(20,7);
begin
  aValMat := 0;
  for v_rec in (select case when ns.codnirstoc &gt; 0 then (ns.pret - coalesce(ns.adaos,0)) else coalesce(lv.pretachiz,0) end * l1.cant valoare
                from iesiri1 i1
                     inner join iesiri i on i.codies = i1.codies
                     inner join livr l on l.codies = i.codies
                     inner join livr1 l1 on l1.codlivr = l.codlivr and l1.codies1 = i1.codies1
                     left join nirstoc ns on ns.codnirstoc = l1.codnirstoc
                     left join livrval lv on lv.codlivr1 = l1.codlivr1
                where i.operat = 1 and i.anulat = 0 and i1.codcmdint1 = aCodComanda1
                union all
                select
                  i1.cant*i1.pu * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end valoare
                from intrari1 i1
                     inner join intrari i on i.codintr = i1.codintr
                where nvl(i.anulat,0) = 0 and nvl(i.operat, 0) = 1 and i1.tiplinie = &apos;S&apos;
                      and i1.codcmdint1 = aCodComanda1 and exists (
                      select mat.codobiect
                      from prodmat mat
                           inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                           inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
                      where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
                      )
                ) loop
    aValMat := aValMat + v_rec.valoare;
  end loop;
  return aValMat;
end;

function GetValManNet(aCodComanda1 in number) return number is
aValManNet number(20,7);
begin
  aValManNet := 0;
  begin
    select sum(nvl(pn1.valman,0)) into aValManNet
    from prodnet1 pn1
         inner join prodnet pn on pn1.codprodnet = pn.codprodnet
    where pn1.tip = 1 and pn.an*12+pn.luna=pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU
          and pn1.coddoc1 = aCodComanda1;
  exception when others then aValManNet := 0;
  end;
  return aValManNet;
end;

function GetValManReal(aCodComanda1 in number, aDataRef in varchar default to_char(sysdate,&apos;dd.mm.yyyy&apos;)) return number is
aValMan number(20,7);
aCodMoneda number(20);
begin
  aValMan := 0;
  begin
    select coalesce(pc.codmoneda,0) into acodmoneda
    from prodcomp pc
         inner join comanda1 c1 on c1.codreteta = pc.codprodcomp
    where c1.codcomanda1 = acodcomanda1;
  exception when others then aCodMoneda := 0;
  end;
  if acodmoneda &gt; 0 then
    begin
      SELECT
        sum(
          case
            when p2.codies1 &gt; 0 then i1.pu
            else Coalesce( (select nvl(Tarif,0) from Tarifeman1 tt1 WHERE p.an*12+p.luna BETWEEN tt1.alstart AND tt1.alstop and tt1.codtarif = p2.codtarif), 0)
          end * Coalesce(P2.TU, pm.tu) * P2.REALIZAT / 60
        ) * 
        case when pc.codmoneda &gt; 0 then PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
              nvl(PC.codmoneda,0),
              decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                     0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                     pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
              to_date(aDataRef, &apos;dd.mm.yyyy&apos;))
             else 1 end into aValMan
      FROM RaportP P
        INNER JOIN RaportP1 P1 ON P1.CodRaportP  = P.CodRaportP
        INNER JOIN RaportP2 P2 ON P2.CodRaportP1 = P1.CodRaportP1
        left JOIN ProdMan  PM ON PM.CodMan      = P2.CodMan
        left join prodcomp pc on pc.codprodcomp = pm.codprodcomp
        left join locmunca lm on p2.codloc = lm.codloc
        LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = P2.CODIES1
      WHERE P2.CodComanda1 = aCodComanda1;
    exception when others then 
      aValMan := 0;
    end;
  else
    begin
      SELECT
        sum(
          case
            when p2.codies1 &gt; 0 then i1.pu
            else Coalesce( (select nvl(Tarif,0) from Tarifeman1 tt1 WHERE p.an*12+p.luna BETWEEN tt1.alstart AND tt1.alstop and tt1.codtarif = p2.codtarif), 0)
          end * Coalesce(P2.TU, pm.tu) * P2.REALIZAT / 60
        ) into aValMan
      FROM RaportP P
        INNER JOIN RaportP1 P1 ON P1.CodRaportP  = P.CodRaportP
        INNER JOIN RaportP2 P2 ON P2.CodRaportP1 = P1.CodRaportP1
        left JOIN ProdMan  PM ON PM.CodMan      = P2.CodMan
        left join prodcomp pc on pc.codprodcomp = pm.codprodcomp
        left join locmunca lm on p2.codloc = lm.codloc
        LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = P2.CODIES1
      WHERE P2.CodComanda1 = aCodComanda1;
    exception when others then 
      aValMan := 0;
    end;
  end if;
  return aValMan;
end;

function GetPredariPeComanda(aCodComanda1 in number) return number is
aCant number(20,7);
begin
  begin
    select sum(i1.cant) into aCant
    from intrari1 i1
         inner join intrari i on i.codintr = i1.codintr
         inner join comanda1 c1 on i1.codcmdint1 = c1.codcomanda1
    where i1.codcmdint1 = aCodComanda1 and nvl(i.anulat,0) = 0 and nvl(i.operat,0) = 1 and i1.codobiect = c1.codobiect;
  exception when others then aCant := 0;
  end;
  return aCant;
end;

function GetPredariReziduu(aCodComanda1 in number) return number is
aCant number(20,7);
begin
  begin
    select sum(i1.cant) into aCant
    from intrari1 i1
         inner join intrari i on i.codintr = i1.codintr
         inner join intrprodlink l on i1.codintr1 = l.codintr1
         inner join cmdprodmat cmd on cmd.codcmdprodmat = l.codliniecomanda and cmd.tip = 0
    where cmd.codcomanda1 = aCodComanda1 and nvl(i.anulat,0) = 0 and nvl(i.operat,0) = 1;
  exception when others then aCant := 0;
  end;
  return aCant;
end;

function GetTotalPredariReziduu(aCodCmdProdMat in number) return number is
aCant number(20,7);
begin
  begin
    select sum(i1.cant) into aCant
    from intrari1 i1
         inner join intrari i on i.codintr = i1.codintr
         inner join intrprodlink l on i1.codintr1 = l.codintr1
         inner join cmdprodmat rez on l.codliniecomanda = rez.codcmdprodmat and rez.tip = 2
         inner join comanda1 c1 on rez.codcomanda1 = c1.codcomanda1
         inner join cmdprodmat r on r.codcomanda1 = c1.codcomanda1
    where r.codcmdprodmat = aCodCmdProdMat and nvl(i.anulat,0) = 0 and nvl(i.operat,0) = 1;
  exception when others then aCant := 0;
  end;
  return aCant;
end;

procedure UpdateNirStoc1 is
aRoot NUMBER(20);
aTipNir NUMBER(10);
aCodComanda1 number(20);
begin
  --stergem intai pozitiile de nirtoc care nu mai sunt
  delete nirstoc1 ns1 where not exists (select ns.codnirstoc from nirstoc ns where ns.codnirstoc = ns1.codnirstoc);
  --inseram cele noi aparute
  for v_rec in (select ns.codnirstoc
                from nirstoc ns
                where not exists (select ns1.codnirstoc from nirstoc1 ns1 where ns1.codnirstoc = ns.codnirstoc)
                ) loop
    aRoot := pkg_list_base_utils.GETCODNIRSTOC_ORIG(v_Rec.codnirstoc);

    begin
      select NIR.TIPNIR, nvl(i1.codcmdint1,0) into aTipNir, aCodComanda1
      from NIRSTOC ns
           inner join nir on nir.codnir = ns.codnir
           left join intrari1 i1 on i1.codintr1 = ns.codintr1
      where ns.codnirstoc = aRoot;
    exception when others then aTipNir := 0; aCodComanda1 := 0;
    end;

    insert into nirstoc1 (codnirstoc, codnirstocorig, tipdoc, dirty, codcomanda1)
    values (v_Rec.codnirstoc, aRoot, aTipNir, 1, case when aTipNir = 7 then aCodComanda1 else 0 end);
  end loop;
  update nirstoc1 set codnirstocorig = codnirstoc where nvl(codnirstocorig,0) = 0;
  Commit;
  UpdateCodComanda1OnNirStoc1;
end;

procedure CheckNirStoc1ByCodIntr(aCodIntr in number) is
begin
  for v_rec in (select ns.codnirstoc, nvl(ns1.codnirstoc,0) codnirstoc1, nvl(i1.codcmdint1,0) codcomanda1
                from intrari1 i1
                     inner join nirstoc ns on ns.codintr1 = i1.codintr1
                     left join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
                where i1.codintr = aCodIntr) loop
    if v_rec.codnirstoc1 = 0 then
      insert into nirstoc1(
        codnirstoc,
        codnirstocorig,
        tipdoc,
        pretmat,
        dinstoc,
        codcomanda1)
      values (
        v_rec.codnirstoc,
        pkg_list_base_utils.GETCODNIRSTOC_ORIG(v_Rec.codnirstoc),
        7,
        0,
        0,
        v_rec.codcomanda1);
    end if;
  end loop;
end;

procedure CheckNirStoc1ByCodTransf(aCodTransf in number) is
aRoot number(20);
aCodComanda1 number(20);
aTipDoc number(20);
begin
  for v_rec in (select ns.codnirstoc, nvl(ns1.codnirstoc,0) codnirstoc1
                from transf1 t1
                     inner join nirstoc ns on ns.codtransf1 = t1.codtransf1
                     left join nirstoc1 ns1 on ns.codnirstoc = ns1.codnirstoc
                where t1.codtransf = aCodTransf) loop
    if v_rec.codnirstoc1 = 0 then
      begin
        select pkg_list_base_utils.GETCODNIRSTOC_ORIG(v_Rec.codnirstoc) into aRoot from dual;
      exception when others then aRoot := 0;
      end;

      begin
        select nvl(i1.codcmdint1,0) into aCodComanda1
        from nirstoc ns
             inner join intrari1 i1 on ns.codintr1 = i1.codintr1
        where ns.codnirstoc = aRoot;
      exception when others then aCodComanda1 := 0;
      end;

      begin
        select nvl(nir.tipnir,0) into aTipDoc
        from nirstoc ns
             inner join nir on nir.codnir = ns.codnir
        where ns.codnirstoc = aRoot;
      exception when others then aTipDoc := 0;
      end;

      insert into nirstoc1(
        codnirstoc,
        codnirstocorig,
        tipdoc,
        pretmat,
        dinstoc,
        codcomanda1)
      values (
        v_rec.codnirstoc,
        aRoot,
        aTipDoc,
        0,
        0,
        aCodComanda1);

      if aCodComanda1 &gt; 0 then
        UpdatePreturiByCodComanda1(aCodComanda1);
      end if;
    end if;
  end loop;
end;

procedure UpdatePreturiByCodComanda1(aCodComanda1 in number) is
aPret number(20,7);
aFlag boolean;
begin
  delete tmp_manevra;
  aFlag := False;
  for v_rec in (select ns1.codnirstocorig, prod.rest
                from nirstoc1 ns1
                     inner join cmdprodmat prod on prod.codcomanda1 = ns1.codcomanda1 and nvl(prod.tip,0) = 0
                where ns1.codcomanda1 = aCodComanda1
               ) loop
    if not aFlag then
      aFlag := True;
      aPret := GetPretNirStoc1Mat(v_rec.codnirstocorig);
    else
      Exit;
    end if;
  end loop;

  update nirstoc1
  set
    dirty = 0,
    PretMat = aPret
  where codcomanda1 = aCodComanda1;
end;

procedure SetDirtyStructura is
aCount number(20);
begin
  select count(*) into aCount from tmp_manevra;
  DELETE TMP_MANEVRA2;

  while aCount &gt; 0 loop
    for v_rec in (select codunic codnirstoc from tmp_manevra) loop
      SetDirtyNirStoc1(v_rec.codnirstoc);
      select count(*) into aCount from tmp_manevra;
    end loop;
  end loop;
end;

procedure SetDirtyNirStoc1(aCodNirStoc in number) is
 aCodComanda1 number(20);
 NR NUMBER(10) := 0;
begin
  SELECT COUNT(*) INTO NR FROM TMP_MANEVRA2 WHERE CODUNIC = aCODNIRSTOC;
  IF NR = 0 THEN
   INSERT INTO TMP_MANEVRA2(CODUNIC) VALUES(aCODNIRSTOC);
  ELSE
    delete tmp_manevra where codunic = aCodNirStoc;
    RETURN;
  END IF;

  begin
    select nvl(codcomanda1,0) into aCodComanda1 from nirstoc1 where codnirstoc = aCodNirStoc;
  exception when others then aCodComanda1 := 0;
  end;

  if aCodComanda1 &gt; 0 then
    update nirstoc1 set dirty = 1 where codcomanda1 = aCodComanda1;
    insert into tmp_manevra(codunic) select codnirstoc from nirstoc1 where codcomanda1 = aCodComanda1 and nvl(dirty,0) = 0;
  end if;
  delete tmp_manevra where codunic = aCodNirStoc;

  insert into tmp_manevra(codunic)
  select nsi.codnirstoc
  from nirstoc ns
       inner join livr1 l1 on l1.codnirstoc = ns.codnirstoc
       inner join iesiri1 i1 on l1.codies1 = i1.codies1 and nvl(i1.codcmdint1,0) &gt; 0
       inner join iesiri i on i.codies = i1.codies
       inner join livr l on l.codies = i.codies and l1.codlivr = l.codlivr
       inner join intrari1 intr1 on intr1.codcmdint1 = i1.codcmdint1
       inner join nirstoc nsi on nsi.codintr1 = intr1.codintr1
  where
    ns.codnirstoc = aCodNirStoc
    AND NSI.CODNIRSTOC &lt;&gt; aCodNirStoc;
end;

procedure UpdateCodComanda1OnNirStoc1 is
begin
  for v_rec in (select ns1.codnirstoc, i1.codcmdint1 codcomanda1, nvl(prod.tip,0) tip
                from nirstoc1 ns1
                     inner join nirstoc root on root.codnirstoc = ns1.codnirstocorig
                     inner join intrari1 i1 on root.codintr1 = i1.codintr1
                     left  join intrprodlink l on i1.codintr1 = l.codintr1
                     left  join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
                where ns1.tipdoc = 7 and nvl(ns1.codcomanda1,0) = 0) loop
    update nirstoc1 set codcomanda1 = case when v_rec.tip = 2 then 0 else v_rec.codcomanda1 end where codnirstoc = v_rec.codnirstoc;
  end loop;
end;

procedure debug is
  rez number;
begin
  pkg_globals.SetLunaLucru(2012,2);
  Get_DifPretProdAllSubunit;
  rez := UpdatePretNS1Partial(24);
  --pkg_pretprod.UpdateNirStoc1InLuna;
end;

end PKG_PRETPROD;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRETURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>060EDF984818639B7AE0C834AA6F5A4E6FBFE58E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_preturi IS


PROCEDURE TEST
IS
aPRET NUMBER(20, 7);
BEGIN
  pkg_globals.setuserid(1270); commit;
  pkg_globals.setsubunitate(2); commit;
  pkg_globals.setlunalucru(2015, 1);
  pkg_stoc_generare_facturi.make_config_luna;
  
  aPret := pkg_preturi.getpretreceptie(2268, 256, 11, 0.09, 1, 1, 0, 1, 0, 0);
  
END;     


FUNCTION GETTIPCATPRET(aCODCATPRET IN NUMBER) RETURN NUMBER
IS
  aTIP NUMBER(5) := 0;
BEGIN
  BEGIN
    SELECT NVL(TIP, 0) INTO aTIP FROM NCATPRET WHERE CODCATPRET = aCODCATPRET;
    EXCEPTION WHEN OTHERS THEN aTIP := 0;
  END;
  RETURN aTIP;
END;

FUNCTION GET_INCADRARE_ADAOSM(DATAREF IN VARCHAR2, aPRETRIDICATA IN NUMBER) RETURN PRETURI_ART_CURSOR
IS
  TMPCURSOR PRETURI_ART_CURSOR;
  GASIT      NUMBER(1)     := 0;
  LIMINF     NUMBER(20, 7) := 0;
  COTAADAOST NUMBER(20, 7) := 0;
  CODADAOSM  NUMBER(20, 0) := 0;
BEGIN
  FOR V_REC IN (SELECT * FROM ADAOSM WHERE DATA &lt;= TO_DATE(DATAREF, &apos;dd.mm.yyyy&apos;) ORDER BY DATA)
  LOOP
    LIMINF := 0;
    FOR V_REC1 IN (SELECT * FROM ADAOSM1 WHERE CODADAOSM = V_REC.CODADAOSM ORDER BY LIMSUP)
    LOOP
      IF aPRETRIDICATA &gt; LIMINF AND aPRETRIDICATA &lt;= V_REC1.LIMSUP THEN
        GASIT := 1; CODADAOSM := V_REC1.CODADAOSM1; COTAADAOST := V_REC1.COTAADAOST;
      ELSE
        LIMINF := V_REC1.LIMSUP;
      END IF;
      EXIT WHEN GASIT = 1;
    END LOOP;
    EXIT WHEN GASIT = 1;
  END LOOP;

  IF GASIT = 1 THEN
    OPEN TMPCURSOR FOR  SELECT CODADAOSM, COTAADAOST FROM DUAL;
  ELSE
    OPEN TMPCURSOR FOR  SELECT -1, -1 FROM DUAL;
  END IF;

  RETURN TMPCURSOR;
END;


FUNCTION WMROTOPRET(ROT IN NUMBER, PRET IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN  CASE ROT
            WHEN 1 THEN ROUND(PRET, 6)
            WHEN 2 THEN ROUND(PRET, 5)
            WHEN 3 THEN ROUND(PRET, 4)
            WHEN 4 THEN ROUND(PRET, 3)
            WHEN 5 THEN ROUND(PRET, 2)
            WHEN 6 THEN ROUND(PRET, 1)
            WHEN 7 THEN ROUND(PRET, 0)
            WHEN 8 THEN ROUND(PRET, 7)
            ELSE        ROUND(PRET, 2)
          END;
END;

FUNCTION ROTUNJESTE_PRET(aCODOBIECT IN NUMBER, aPRET IN NUMBER, INLEI IN NUMBER) RETURN NUMBER IS
  ROT NUMBER(2) := 0;
BEGIN
  BEGIN
    IF INLEI = 1
    THEN SELECT NVL(ROTUNJIRE, 0) INTO ROT FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT;
    ELSE SELECT NVL(ROTVALUTA, 0) INTO ROT FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN ROT := 5;
  END;

  RETURN WMROTOPRET(ROT, aPRET);
END;

FUNCTION CALCULEAZAPRETRECEPTIE(aCODOBIECT IN NUMBER, TIPCATEG IN NUMBER, PRETLEI IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER) RETURN NUMBER IS
  PRET NUMBER(20, 7)           := 0.0;
  LASTPRETACHIZ NUMBER(20, 7)  := 0.0;
BEGIN
   IF TIPCATEG = 1 THEN
     IF TIPTVANEEX = 0 THEN PRET := PRETLEI / (1 + aPROCTVA);
                       ELSE PRET := PRETLEI;
     END IF;
   ELSE
     IF TIPCATEG = 2 THEN
       IF TIPTVANEEX = 2 THEN PRET := PRETLEI + (PRETLEI - aPRETACHIZ) * aPROCTVA;
       ELSE
       IF TIPTVANEEX = 1 THEN PRET := PRETLEI * (1 +  aPROCTVA);
       ELSE PRET := PRETLEI;
       END IF;
       END IF;
     ELSE
      IF TIPCATEG = 3 THEN
        IF TIPTVANEEX = 2 THEN PRET := aPRETINREG * (1 + PRETLEI / 100)  + (aPRETINREG * (1 + PRETLEI / 100) - aPRETINREG) * aPROCTVA;
        ELSE
        IF TIPTVANEEX = 1 THEN PRET := aPRETINREG * (1 + PRETLEI / 100) * (1 + aPROCTVA);
        ELSE PRET := aPRETINREG * (1 + PRETLEI / 100);
        END IF;
        END IF;
      ELSE
       IF TIPCATEG = 4 THEN
         IF TIPTVANEEX = 2 THEN PRET := aPRETACHIZ * (1 + PRETLEI / 100)  + (aPRETACHIZ * (1 + PRETLEI / 100) - aPRETACHIZ) * aPROCTVA;
         ELSE
         IF TIPTVANEEX = 1 THEN PRET := aPRETACHIZ * (1 + PRETLEI / 100) * (1 + aPROCTVA);
         ELSE PRET := aPRETACHIZ * (1 + PRETLEI / 100);
         END IF;
         END IF;
       ELSE
        IF TIPCATEG = 5 THEN
          PRET := aPRETMAX + aPRETMAX * PRETLEI/100;
          IF TIPTVANEEX = 0 THEN PRET := PRET / (1 + aPROCTVA);END IF;
        ELSE
         IF TIPCATEG = 10 THEN
           LASTPRETACHIZ := PKG_INTRARI.GETLASTPRETACHIZ(aCODOBIECT);
           IF LASTPRETACHIZ = 0 THEN LASTPRETACHIZ := aPRETACHIZ;
           END IF;
           IF TIPTVANEEX = 2
           THEN PRET := LASTPRETACHIZ * (1 + PRETLEI / 100)  + (LASTPRETACHIZ * (1 + PRETLEI / 100) - aPRETACHIZ) * aPROCTVA;
           ELSE PRET := LASTPRETACHIZ * (1 + PRETLEI / 100) * (1 + aPROCTVA);
           END IF;
         ELSE
           IF TIPCATEG = 6 THEN
             IF TIPTVANEEX = 2 THEN PRET := aPRETINREG * (1 + PRETLEI / 100)  + (aPRETINREG * (1 + PRETLEI / 100) - aPRETINREG) * aPROCTVA;
             ELSE
             IF TIPTVANEEX = 1 THEN PRET := aPRETINREG * (1 + PRETLEI / 100) * (1 + aPROCTVA);
             ELSE PRET := aPRETINREG * (1 + PRETLEI / 100);
             END IF;
             END IF;
           ELSE
           IF TIPCATEG = 7 THEN
             IF TIPTVANEEX = 2 THEN PRET := aPRETACHIZ * (1 + PRETLEI / 100)  + (aPRETACHIZ * (1 + PRETLEI / 100) - aPRETACHIZ) * aPROCTVA;
             ELSE
             IF TIPTVANEEX = 1 THEN PRET := aPRETACHIZ * (1 + PRETLEI / 100) * (1 + aPROCTVA);
             ELSE PRET := aPRETACHIZ * (1 + PRETLEI / 100);
             END IF;
             END IF;
           END IF;
           END IF;
         END IF;
        END IF;
       END IF;
      END IF;
     END IF;
   END IF;

   IF (aPARITATE &lt;&gt; 1)AND(APARITATE &lt;&gt; 0) THEN
     PRET := aPARITATE * PRET;
   END IF;


   IF (PRET &lt;&gt; 0)AND(ROTUNJIRE &lt;&gt; 0) THEN
     PRET := ROTUNJESTE_PRET(aCODOBIECT, PRET, INLEI );
   END IF;
   RETURN PRET;
 END;

 FUNCTION GETPRETRECEPTIE(aCODOBIECT IN NUMBER, aCODGEST IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER ) RETURN NUMBER
 IS
   CATPRETGEST      NUMBER(20)     := 0;
   SUBUNITGEST      NUMBER(20)     := 0;
   PRET             NUMBER(20, 7)  := 0.0;
   TIPCATEG         NUMBER(2)      := 0;
   PRETLEI          NUMBER(20, 7)  := 0.0;
   LASTPRETACHIZ    NUMBER(20, 7)  := 0.0;
   SKIPPRETIMPLICIT NUMBER(1, 0)   := 0;
 BEGIN
   IF aCODGEST &lt;&gt; 0 THEN
     SELECT NVL(CODCATPRET, 0), CODSUBUNIT INTO CATPRETGEST, SUBUNITGEST FROM NGEST WHERE CODGEST = aCODGEST;
   END IF;

   SKIPPRETIMPLICIT := NVL(PKG_CATEGCONST.GETVALCONSTANTA(&apos;DOARCATGEST&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0);

   IF CATPRETGEST &lt;&gt; 0 THEN
     BEGIN
       SELECT
         C.TIP,
         P.LEI
       INTO
         TIPCATEG,
         PRETLEI
       FROM
         PRETM P
         LEFT OUTER JOIN NCATPRET C ON C.CODCATPRET = P.CODCATPRET
         WHERE
           CODOBIECT = aCODOBIECT
        -- AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
           AND NVL(P.SUBUNITATEA, 1) = SUBUNITGEST
           AND P.CODCATPRET = CATPRETGEST;
       EXCEPTION WHEN OTHERS THEN BEGIN
         TIPCATEG := 0;
         PRETLEI  := 0;
       END;
     END;
   END IF;

   IF TIPCATEG = 0 THEN
     IF SKIPPRETIMPLICIT = 1 THEN RETURN 0;
     ELSE
       BEGIN
         SELECT C.TIP, P.LEI INTO TIPCATEG, PRETLEI
         FROM
           PRETM P
           LEFT OUTER JOIN NCATPRET C ON C.CODCATPRET = P.CODCATPRET
         WHERE
           CODOBIECT = aCODOBIECT
           AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
           AND IMPLICIT = 1;
         EXCEPTION WHEN OTHERS THEN BEGIN
           TIPCATEG := 0;
           PRETLEI  := 0;
         END;
       END;
     END IF;
   END IF;

  PRET := CALCULEAZAPRETRECEPTIE(aCODOBIECT, TIPCATEG, PRETLEI,  aPRETACHIZ, aPROCTVA, aPARITATE, INLEI, ROTUNJIRE, TIPTVANEEX, aPRETMAX , aPRETINREG );
  RETURN PRET;
 END;

 FUNCTION GETPRETRECEPTIEDINCATEGORIE(aCODOBIECT IN NUMBER, CATPRETGEST IN NUMBER, aPRETACHIZ IN NUMBER, aPROCTVA IN NUMBER, aPARITATE IN NUMBER, INLEI IN NUMBER, ROTUNJIRE IN NUMBER, TIPTVANEEX IN NUMBER, aPRETMAX IN NUMBER, aPRETINREG IN NUMBER ) RETURN NUMBER
 IS
   PRET          NUMBER(20, 7) := 0.0;
   TIPCATEG      NUMBER(2)     := 0;
   PRETLEI       NUMBER(20, 7) := 0.0;
   LASTPRETACHIZ NUMBER(20, 7) := 0.0;
 BEGIN
   IF CATPRETGEST &lt;&gt; 0 THEN
     BEGIN
       SELECT C.TIP, NVL(P.LEI, 0) INTO TIPCATEG, PRETLEI
       FROM
       PRETM P
       LEFT OUTER JOIN NCATPRET C ON C.CODCATPRET = P.CODCATPRET
       WHERE
         CODOBIECT = aCODOBIECT
         AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
         AND P.CODCATPRET = CATPRETGEST;
       EXCEPTION WHEN OTHERS THEN BEGIN
         TIPCATEG := 0;
         PRETLEI  := 0;
       END;
     END;
   END IF;

   IF TIPCATEG = 0 THEN
     BEGIN
       SELECT C.TIP, P.LEI INTO TIPCATEG, PRETLEI
       FROM
         PRETM P
         LEFT OUTER JOIN NCATPRET C ON C.CODCATPRET = P.CODCATPRET
         WHERE
           CODOBIECT = aCODOBIECT
           AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
           AND IMPLICIT = 1;
       EXCEPTION WHEN OTHERS THEN BEGIN
         TIPCATEG := 0;
         PRETLEI  := 0;
       END;
     END;
   END IF;

  PRET := CALCULEAZAPRETRECEPTIE(aCODOBIECT, TIPCATEG, PRETLEI,  aPRETACHIZ, aPROCTVA, aPARITATE, INLEI, ROTUNJIRE, TIPTVANEEX, aPRETMAX, aPRETINREG);
  RETURN PRET;
 END;


-- CAUTA CATEGORIE DE PRET IMPLICITA LA NIVEL DE PARTENER + ARTICOL  sau DIN CONSTANTE
 FUNCTION GETCATPRETVANZARE(aCODOBIECT IN NUMBER, aCODPART IN NUMBER, NEEDMANUALSELECTION OUT NUMBER) RETURN NUMBER
 IS
   CODCAT     NUMBER(20, 0) := 0;
   CODCATPART NUMBER(20, 0) := 0;
   NR         NUMBER (5, 0) := 0;
 BEGIN
   NEEDMANUALSELECTION := 0; -- IMI SPUNE DACA VA TREBUI SA SELECTEZE MANUAL DIN LISTA CATEGORIA : 0 = NU; &lt;&gt; 0 = DA;


  -- VERIFIC DACA PARTENERUL ARE ASIGNATA O CATEGORIE
   IF aCODPART &lt;&gt; 0 THEN
     BEGIN
       SELECT NVL(CODCATEGPRET, 0) INTO CODCAT FROM NPART WHERE CODPART = aCODPART;
       EXCEPTION WHEN OTHERS THEN CODCAT := 0;
     END;
     CODCATPART := CODCAT;

   END IF;

   IF CODCAT = 0 THEN
   -- DACA NU ARE PARTENERUL CATEGORIE, VERIFIC DACA ESTE DEFINITA CONSTANTA CU CATEGORIA IMPLICITA LA NIVELUL LUNII DE LUCRU
     CODCAT := NVL(PKG_CATEGCONST.GETVALCONSTANTA(&apos;CPRETVANZ&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0);
   END IF;


   IF CODCAT = 0 AND NVL(PKG_CATEGCONST.GETVALCONSTANTA(&apos;DOARCATPART&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0) = 1 THEN  RETURN 0;
   END IF;

   -- AM GASIT CATEGORIE; VERIFIC DACA ARTICOLUL ANALIZAT O FOLOSESTE
   IF CODCAT &lt;&gt; 0 THEN
     SELECT COUNT(*) INTO NR
     FROM
       PRETM P
     WHERE
       CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
       AND CODCATPRET = CODCAT;
     IF NR = 0 THEN CODCAT := 0;
     END IF;
   END IF;



   -- DUPA TOATE ANALIZELE ASTEA, DACA NU GASESC O CATEGORIE VAD DACA VA TREBUI SA SELECTEZE MANUAL

   IF CODCAT = 0 THEN
     SELECT COUNT(*) INTO NEEDMANUALSELECTION
     FROM
       PRETM P
     WHERE
       CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE);

     IF NEEDMANUALSELECTION = 1 THEN -- am deja una definita; nu e cazul de selectie manuala
       SELECT CODCATPRET INTO CODCAT  FROM PRETM P WHERE CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE);

       IF CODCATPART &lt;&gt; 0 THEN NEEDMANUALSELECTION := 1;
                          ELSE NEEDMANUALSELECTION := 0;
       END IF;
     END IF;
   END IF;


   RETURN CODCAT;
 END;




-- CAUTA CATEGORIE DE PRET IMPLICITA LA NIVEL DE SUBUNITATE + ARTICOL  sau DIN CONSTANTE
 FUNCTION GETCATPRETVANZARESUBUNIT(aCODOBIECT IN NUMBER, aCODSUBUNIT IN NUMBER, NEEDMANUALSELECTION OUT NUMBER) RETURN NUMBER
 IS
   CODCAT NUMBER(20, 0) := 0;
   NR     NUMBER (5, 0) := 0;
 BEGIN
   NEEDMANUALSELECTION := 0; -- IMI SPUNE DACA VA TREBUI SA SELECTEZE MANUAL DIN LISTA CATEGORIA : 0 = NU; &lt;&gt; 0 = DA;


  -- VERIFIC DACA SUBUNITATEA ARE ASIGNATA O CATEGORIE
   IF aCODSUBUNIT &lt;&gt; 0 THEN
     BEGIN
       SELECT NVL(CODCATPRET, 0) INTO CODCAT FROM NSUBUNIT WHERE CODSUBUNIT = aCODSUBUNIT;
       EXCEPTION WHEN OTHERS THEN CODCAT := 0;
     END;
   END IF;

   IF CODCAT = 0 THEN
   -- DACA NU ARE PARTENERUL CATEGORIE, VERIFIC DACA ESTE DEFINITA CONSTANTA CU CATEGORIA IMPLICITA LA NIVELUL LUNII DE LUCRU
     CODCAT := NVL(PKG_CATEGCONST.GETVALCONSTANTA(&apos;CPRETVANZSUBUNIT&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), 0);
   END IF;


   -- AM GASIT CATEGORIE; VERIFIC DACA ARTICOLUL ANALIZAT O FOLOSESTE
   IF CODCAT &lt;&gt; 0 THEN
     SELECT COUNT(*) INTO NR
     FROM
       PRETM P
     WHERE
       CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
       AND CODCATPRET = CODCAT;
     IF NR = 0 THEN CODCAT := 0;
     END IF;
   END IF;

   -- DUPA TOATE ANALIZELE ASTEA, DACA NU GASESC O CATEGORIE VAD DACA VA TREBUI SA SELECTEZE MANUAL

   IF CODCAT = 0 THEN
     SELECT COUNT(*) INTO NEEDMANUALSELECTION
     FROM
       PRETM P
     WHERE
       CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE);

     IF NEEDMANUALSELECTION = 1 THEN -- am deja una definita; nu e cazul de selectie manuala
       SELECT CODCATPRET INTO CODCAT  FROM PRETM P WHERE CODOBIECT = aCODOBIECT
       AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE);

       NEEDMANUALSELECTION := 0;
     END IF;
   END IF;
   RETURN CODCAT;
 END;







-- RETURNEAZA UN CURSOR CARE CONTINE CATEGORIILE DE PRETURI ASIGNATE UNUI ARTICOL/OBIECT
FUNCTION GET_LISTA_CAT_PRETURI(ACODOBIECT IN NUMBER) RETURN PRETURI_ART_CURSOR
IS
  TMPCURSOR PRETURI_ART_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT P.CODCATPRET, N.DEN_CATPRET, P.LEI, P.VALUTA, N.TIP, P.IMPLICIT, P.CODPRETM, M.SIMBOL, P.MONEDA
    FROM
      PRETM    P,
      NCATPRET N,
      NMONEDE M
    WHERE
      P.CODOBIECT = ACODOBIECT
      AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE_DOC, 1, 2, PKG_GLOBALS.GETSUBUNITATE_DOC)
      AND P.CODCATPRET = N.CODCATPRET
      AND M.CODMONEDA = NVL(P.MONEDA, 0)
    ORDER BY P.CODOBIECT, P.INDEXLOCAL;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_LISTA_CAT_PRETURI_RECEPTIE(ACODOBIECT IN NUMBER, aCODGEST IN NUMBER) RETURN PRETURI_ART_CURSOR
IS
  TMPCURSOR PRETURI_ART_CURSOR;
  CODCATPRETGEST NUMBER(20) := 0;
  CATEGGEST      NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT NVL(CODCATPRET, 0) INTO CODCATPRETGEST FROM NGEST WHERE CODGEST = aCODGEST;
    EXCEPTION WHEN OTHERS THEN CODCATPRETGEST := 0;
  END;
  IF CODCATPRETGEST &lt;&gt; 0 THEN
    BEGIN
      SELECT NVL(COUNT(*), 0) INTO CATEGGEST
      FROM
        PRETM P
      WHERE
        P.CODOBIECT = ACODOBIECT
        AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
        AND CODCATPRET = CODCATPRETGEST;
      EXCEPTION WHEN OTHERS THEN CATEGGEST := 0;
    END;
  END IF;

  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      P.CODCATPRET,
      N.DEN_CATPRET,
      P.LEI,
      P.VALUTA,
      N.TIP,
      (
        CASE
         WHEN CATEGGEST &lt;&gt; 0 AND P.CODCATPRET  = CODCATPRETGEST  THEN 1
         WHEN CATEGGEST &lt;&gt; 0 AND P.CODCATPRET  &lt;&gt; CODCATPRETGEST THEN 0
         ELSE P.IMPLICIT
        END
      ) AS IMPLICIT,
      U.DEN_UM
    FROM
      PRETM P,
      NCATPRET N,
      NARTOBJ O,
      NART A,
      NUM U
    WHERE
      P.CODOBIECT      = ACODOBIECT
      AND O.CODOBIECT  = ACODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND U.CODUM      = A.UM
      AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
      AND P.CODCATPRET = N.CODCATPRET AND N.TIP IN (1, 2, 3, 4, 5, 6, 7)
    ORDER BY
      P.CODOBIECT, P.INDEXLOCAL;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


-- RETURNEAZA UN CURSOR CARE CONTINE INFORMATII PRIVIND O CATEGORIE DE PRET DEFINITA PENTRU UN ARTICOL SI ROTUNJIRILE AFERENTE
FUNCTION GET_RECORD_PRET_ARTICOL(ACODOBIECT IN NUMBER, ACATPRET IN NUMBER) RETURN PRETURI_ART_CURSOR
IS
TMPCURSOR PRETURI_ART_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      P.CODCATPRET,
      P.LEI,
      P.VALUTA,
      P.MONEDA,
      N.TIP,
      (SELECT NVL(ROTUNJIRE, 0) FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT) AS ROTLEI,
      (SELECT NVL(ROTVALUTA, 0) FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT) AS ROVALUTA
    FROM
      PRETM P,
      NCATPRET N
    WHERE
      P.CODOBIECT = ACODOBIECT
      AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
      AND P.CODCATPRET = N.CODCATPRET AND P.CODCATPRET = ACATPRET
    ORDER BY P.CODOBIECT, P.INDEXLOCAL;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;




-- RETURNEAZA UN CURSOR CARE CONTINE INFORMATII PRIVIND O CATEGORIE DE PRET DEFINITA PENTRU UN ARTICOL, O UNITATE DE MASURA SI ROTUNJIRILE AFERENTE
FUNCTION GET_RECORD_PRET_ARTICOL_UMSEC(ACODOBIECT IN NUMBER, ACATPRET IN NUMBER, AUMSEC IN NUMBER) RETURN PRETURI_ART_CURSOR
IS
TMPCURSOR PRETURI_ART_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      P.CODCATPRET,
      P.LEI,
      P.VALUTA,
      P.MONEDA,
      N.TIP,
      (SELECT NVL(ROTUNJIRE, 0) FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT) AS ROTLEI,
      (SELECT NVL(ROTVALUTA, 0) FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT) AS ROVALUTA,
      PAMB.LEI AS LEIUMSEC,
      PAMB.VALUTA AS VALUTAUMSEC
    FROM
      PRETM P,
      NCATPRET N,
      NARTAMB AMB,
      PRETMAMB PAMB
    WHERE
      P.CODOBIECT = ACODOBIECT
      AND NVL(P.SUBUNITATEA, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE)
      AND P.CODCATPRET  = N.CODCATPRET
      AND P.CODCATPRET  = ACATPRET
      AND PAMB.CODPRETM = P.CODPRETM
      AND AMB.CODOBIECT = ACODOBIECT
      AND AMB.UMSEC     = AUMSEC
      AND PAMB.CODAMB   = AMB.CODAMB
    ORDER BY P.CODOBIECT, P.INDEXLOCAL;
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION GETPRET (aTip IN NUMBER, aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN DATE ) RETURN NUMBER
                  --aTip 0 - intrare , 1 - iesire
IS
  pTipPromo NUMBER := 0;
  pTipContr NUMBER := 0;
  pTipOfe   NUMBER := 0;

  pResult   NUMBER;
BEGIN

  IF aTip IS NULL OR aCodObiect IS NULL OR aPart IS NULL OR aLocatie IS NULL OR aSubunit IS NULL OR aDataRef IS NULL
  THEN
    pResult := NULL;
  ELSE
    IF    aTip = 0 THEN
      pTipPromo := 75;
      pTipContr := 10;
      pTipOfe   := 51;
    ELSIF aTip = 1 THEN
      pTipPromo := 56;
      pTipContr := 27;
      pTipOfe   := 50;
    END IF;

    IF pResult IS NULL THEN -- pret din promotii
      SELECT MIN(p1.pret)
      INTO pResult
      FROM Promo P
        INNER JOIN Promo1 P1 ON P1.CodPromo = P.CodPromo
        LEFT JOIN PromoPart PP ON PP.CodPromo = P.CodPromo
        LEFT JOIN PromoSub PS ON PS.CodPromo = P.CodPromo
      WHERE P.Anulat = 0 AND P.Operat = 1 AND P.TipPromotie = 1 AND P.TipDoc = pTipPromo
        AND ( ( P.TipClasep = 0 AND COALESCE(PP.Partener, P.Partener, 0) IN (0, aPart) AND Nvl(P.CodLocatie,0) IN (0, aLocatie) ) OR
              ( P.TipClasep = 1 AND COALESCE(PP.CodClaseP, 0) IN (SELECT CodClasa FROM Npart WHERE CodPArt = aPart))
            )
        AND Coalesce(PS.Subunitatea, P.Subunitatea, 1) IN (1, aSubunit)
        AND P1.Codobiect = aCodObiect
        AND P.DATASTART &lt;= aDataRef
        AND P.DATAEND   &gt;= aDataRef;
    END IF;

    IF pResult IS NULL THEN -- pret din contract
      SELECT MIN(c1.pret*(1+Nvl(C1.AdDim,0)/ 100)*(1+Nvl(C1.ProcDisc,0)/ 100))
      INTO pResult
      FROM Contract C INNER JOIN Contract1 C1 ON C1.CodContract  = C.CodContract
      WHERE C.Anulat = 0 AND C.Operat = 1 AND C.Activ = 1 AND C.TipDoc = pTipContr
        AND C.Partener = aPart
        AND C.CodLocatie IN (0 , aLocatie)
        AND C.Subunitatea = aSubunit
        AND C1.Codobiect = aCodObiect
        AND NVL(C1.CodObiectSec, 0) = 0
        AND Nvl(C1.DATASTART, C.DATASTART) &lt;= aDataRef
        AND Nvl(C1.DATASTOP,  C.DATASTOP)  &gt;= aDataRef;
    END IF;

    IF pResult IS NULL THEN -- pret din oferta
      SELECT MIN(O1.pret*(1+Nvl(O1.ProcAdaos,0)/ 100)*(1+Nvl(O1.ProcDiscount,0)/ 100))
      INTO pResult
      FROM Oferta O INNER JOIN Oferta1 O1 ON O1.CodOferta  = O.CodOferta
      WHERE O.Anulat = 0 AND O.Operat = 1 AND O.TipDoc = pTipOfe
        AND O.Partener = aPart
        AND O.CodLocatie IN (0 , aLocatie)
        AND O.Subunitatea = aSubunit
        AND O1.Codobiect = aCodObiect
        AND O.DATASTART &lt;= aDataRef
        AND O.DATAEND   &gt;= aDataRef;
    END IF;

  END IF;
  RETURN pResult;
END;

FUNCTION GETPRET_IES (aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN VARCHAR2 ) RETURN NUMBER
IS
BEGIN
  RETURN PKG_PRETURI.GETPRET(1,aCodObiect, aPart, aLocatie, aSubunit, To_Date(aDataRef,&apos;DD.MM.YYYY&apos;));
END;

FUNCTION GETPRET_INTR(aCodObiect IN NUMBER, aPart IN NUMBER, aLocatie IN NUMBER, aSubunit IN NUMBER, aDataRef IN VARCHAR2 ) RETURN NUMBER
IS
BEGIN
  RETURN PKG_PRETURI.GETPRET(0,aCodObiect, aPart, aLocatie, aSubunit, To_Date(aDataRef,&apos;DD.MM.YYYY&apos;));
END;


END PKG_PRETURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROCINTRETINERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F50B0D9168577B560DE4E2808272E722F295835A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROCINTRETINERE IS


PROCEDURE SETJOB(ASCHED IN VARCHAR2) IS
stareJOB NUMBER(1);
S        VARCHAR2(100);
BEGIN
   
   STAREJOB := GETSTAREJOB(S);
   
   IF stareJOB = 1 THEN 
      dbms_scheduler.disable(&apos;ACT_STARE_NIRSER&apos;);    
   END IF; 
   
   IF STAREJOB = 0 THEN
      dbms_scheduler.enable(&apos;ACT_STARE_NIRSER&apos;);       
   END IF;
   
   IF STAREJOB = -1 THEN
      DBMS_SCHEDULER.create_job(job_name =&gt; &apos;ACT_STARE_NIRSER&apos; ,
                                job_type =&gt; &apos;STORED_PROCEDURE&apos;,
                                job_action =&gt; &apos;PKG_PROCINTRETINERE.UPDATE_NIRSER_DATAPROD&apos; ,
                                schedule_name =&gt; ASCHED,
                                Auto_drop =&gt; false);
                                        
     dbms_scheduler.enable(&apos;ACT_STARE_NIRSER&apos;);       
  END IF;   
END;

PROCEDURE UPDATE_NIRSER_DATAPROD IS 
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  
  FOR V_REC IN (SELECT OBJ.CODOBIECT,NS.CODNIRSTOC,OBJ.ZILEVALABIL,OBJ.ZILEDISTRIB
                FROM NARTOBJ OBJ INNER JOIN NIRSTOC NS ON OBJ.CODOBIECT = NS.CODOBIECT
                ) LOOP
    
      UPDATE NIRSER NSER SET 
             NSER.STARE = 1 
       WHERE NSER.CODNIRSTOC = V_REC.CODNIRSTOC AND
             NSER.DATAPROD + V_REC.ZILEDISTRIB &gt;= TO_DATE(SYSDATE,&apos;DD.MM.YYYY&apos;); 
       
       UPDATE NIRSER NSER SET 
             NSER.STARE = 2 
       WHERE NSER.CODNIRSTOC = V_REC.CODNIRSTOC AND
             NSER.DATAPROD + V_REC.ZILEVALABIL &gt;= TO_DATE(SYSDATE,&apos;DD.MM.YYYY&apos;); 
      
  END LOOP;  
 COMMIT;
END;

FUNCTION GETSTAREJOB(DEN_SCHED OUT VARCHAR2) RETURN NUMBER IS
iResult number(1);
BEGIN
  begin
    select decode(enabled,&apos;TRUE&apos;,1,0),SCHEDULE_NAME into iresult,DEN_SCHED from user_scheduler_jobs where job_name = &apos;ACT_STARE_NIRSER&apos;;
  exception  when others then
    iResult := -1;
    DEN_SCHED :=&apos;?&apos;;
  end;
  
  return iresult ;
 
END;

end PKG_PROCINTRETINERE; </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROC_ACT_DATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7851B5B8BE05490AE977ECE08E93776749455AF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROC_ACT_DATE IS
gDefaultName constant varchar2(10) := &apos;WMJOB&apos;;
gCodProc1 tCod;
gCodProc1_ins tCod;

PROCEDURE ACTUAL_PROC_DATE IS
BEGIN
  null;
END;

PROCEDURE RUN_NOW(aCodProc in  number) is
aName  varchar2(50);
begin
  null;
end;



PROCEDURE SETJOB(aCodProc in number) IS
BEGIN
  null;
END;

procedure drop_job is 
begin
  null;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
BEGIN
  null;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  null;
END;
 
PROCEDURE SP_INSERTRECORD IS
BEGIN
  null;
END;  

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
BEGIN
  null;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  null;
END;

function GetVanzari(aCodObiect in number, aSubunitatea in number, aAnLuna in number) return number is
aRez number(20,7);
begin
  begin
    select sum(i1.cant) into aRez
    from iesiri1 i1
         inner join iesiri i on i.codies = i1.codies
    where i.an*12+i.luna = aAnLuna and i.tipdoc  in (19,20,21,22) and i.anulat = 0 and nvl(i.custodie,0) = 0;
  exception when others then aRez := 0;
  end;  
  return aRez;
end;  

procedure UpdateStocArt is 
aAnLunaMin number(20);
aAnLunaCurent number(20);
aLunaCurent number(20);
aAnCurent number(20);
Vanz number(20,7);
begin
  begin
    select aninitial*12+lunainitiala, 
           anmaxim*12+lunamaxima,
           anmaxim, lunamaxima
    into aAnLunaMin, aAnLunaCurent, aAnCurent, aLunaCurent 
    from firmaluni;
  exception when others then aAnLunaMin := 0;
  end;
  
  MERGE INTO nartobjsubunit s
  USING (
         SELECT OBJ.codobiect, 
                S.CODSUBUNIT subunitate
         from NARTOBJ OBJ, NSUBUNIT S
        ) N
  ON (S.CODOBIECT = N.CODOBIECT and S.SUBUNITATE = N.SUBUNITATE)
  WHEN NOT MATCHED THEN INSERT (CODS, CODOBIECT, SUBUNITATE)
                                VALUES 
                               (SEQ_NARTOBJSUBUNIT_CODS.NEXTVAL, N.CODOBIECT, N.SUBUNITATE);
  
  if aAnLunaMin = 0 then return; end if;
  if aAnLunaCurent &gt;= 2018*12+1 then
    for v_rec in (select codobiect, nvl(procstocmin,0) procstocmin, nvl(procstocmed,0) procstocmed, nvl(procstocmax,0) procstocmax, subunitate subunitatea
                  from nartobjsubunit
                  where (codgest is null or codgest = 0 )
                  order by subunitatea, codobiect
                  ) loop
      Vanz := GetVanzari(v_rec.codobiect, v_rec.subunitatea, aAnLunaCurent - 12);
      update nartobjsubunit set
      stocmin = Vanz,
      stocmed = Vanz + v_rec.procstocmed/100*Vanz,
      stocmax = Vanz + v_rec.procstocmax/100*Vanz
      where codobiect = v_rec.codobiect and subunitate = v_rec.subunitatea and (codgest is null or codgest = 0);
    end loop;
  else
    execute immediate &apos;declare Vanz number(20,7);
    begin
      for v_rec in (select codobiect, nvl(procstocmin,0) procstocmin, nvl(procstocmed,0) procstocmed, nvl(procstocmax,0) procstocmax, subunitate subunitatea
                  from nartobjsubunit
                  where (codgest is null or codgest = 0 )
                  order by subunitatea, codobiect
                  ) loop
      begin
        case &apos;||aLunaCurent||&apos;
        when 1 then select nvl(l1,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 2 then select nvl(l2,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 3 then select nvl(l3,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 4 then select nvl(l4,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 5 then select nvl(l5,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 6 then select nvl(l6,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea; 
        when 7 then select nvl(l7,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 8 then select nvl(l8,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 9 then select nvl(l9,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 10 then select nvl(l10,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 11 then select nvl(l11,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        when 12 then select nvl(l12,0) into Vanz from medie_vanz where codobiect = v_rec.codobiect and subunitatea = v_rec.subunitatea;
        end case;  
      exception when others then Vanz := 0;
      end;
      update nartobjsubunit set
      stocmin = Vanz,
      stocmed = Vanz + v_rec.procstocmed/100*Vanz,
      stocmax = Vanz + v_rec.procstocmax/100*Vanz
      where codobiect = v_rec.codobiect and subunitate = v_rec.subunitatea and (codgest is null or codgest = 0);
    end loop;
    end;&apos;;
  end if;
  commit;
end;  

end pkg_proc_act_date; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A77E8B30C9EAA91922C21844DF058A79C556A16D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PRODCOMP IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_37&apos;;
DoCommit boolean := true;
vFromImport number(1);
vCodMat number(20);
vModGenerice number(1) := 0;
vTipPretDin number(1) := 0; -- 0 = din nomenclator 1 = din reteta generica
vTipFiltru number(1); -- 0 - toate retetele, 1 - create in luna curenta, 2 - create dupa, 3 - create in intervalul
vDataStart varchar2(10);
vDataStop varchar2(10);
vAllRet number(1) := 0;
KTipCoefIndirecte number(1);
KRegieAntecalcul number(1);
KTipPret number(1);

procedure SetParams(aAllRet in number, aFromImport in number default 0) is
begin
  vAllRet := aAllRet;
  vFromImport := aFromImport;
end;

procedure UpdateProcReal(vArt in number, vProc in number) is
aCantNou number(20,7);
begin
  delete tmp_manevra_liste where filtru = &apos;CODPRODCOMP&apos; or filtru = &apos;CODPROIECT&apos;;
  for v_rec in (with nu as
                (
                select mat.codmat
                from prodmat mat
                     inner join proiectnod pn on pn.codprodmat = mat.codmat
                     inner join proiect p on p.codproiect = pn.codproiect
                     inner join comanda1 c1 on c1.codproiect = p.codproiect
                     inner join cmdlink l on c1.codcomanda1 = l.codliniecomanda
                where mat.codobiect = vart
                union all
                select mat.codmat
                from livr1 l1
                     inner join livr l on l1.codlivr = l.codlivr
                     inner join proiectnod pn on l1.codproiect = pn.codproiect
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                where nvl(l.anulat,0) = 0 and l.operat = 1 and mat.codobiect = vart
                )
                select mat.codmat, mat.codprodcomp, pc.data, mat.cant,
                       &apos;OBJ:&apos;||obj.denumire||&apos; (&apos;||mat.CODPRODCOMP||&apos;) - % utilizare.(&apos;||vProc||&apos;)&apos; doc,
                       round(mat.Cant * 100 / decode(nvl(mat.ProcReal,100),0,100,nvl(mat.ProcReal,100)) ,7) CantT
                from prodmat mat
                     inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
                     inner join nartobj obj on obj.codobiect = pc.codobiect
                where mat.codobiect = vart and
                      not mat.codmat in (select codmat from nu)
               ) loop
    aCantNou := vProc / 100 * v_rec.CantT;
    update prodmat
    set
      procreal = vProc,
      Cant = aCantNou,
      Valoare = Pret * vProc / 100 * v_rec.CantT
    where codmat = v_rec.codmat;

    insert into tmp_manevra_liste(filtru, valoare) values (&apos;CODPRODCOMP&apos;, v_rec.codprodcomp);
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    for v_xxx in (with nu as
                    (
                    select pn.codproiectnod
                    from prodmat mat
                         inner join proiectnod pn on pn.codprodmat = mat.codmat
                         inner join proiect p on p.codproiect = pn.codproiect
                         inner join comanda1 c1 on c1.codproiect = p.codproiect
                         inner join cmdlink l on c1.codcomanda1 = l.codliniecomanda
                    where mat.codmat = v_rec.codmat
                    union all
                    select pn.codproiectnod
                    from livr1 l1
                         inner join livr l on l1.codlivr = l.codlivr
                         inner join proiectnod pn on l1.codproiect = pn.codproiect
                         inner join prodmat mat on mat.codmat = pn.codprodmat
                    where nvl(l.anulat,0) = 0 and l.operat = 1 and mat.codmat = v_rec.codmat
                    )
                  select pn.codproiectnod, pn.codproiect, &apos;Inloc.mat. (&apos;||pn.codproiectnod||&apos;)&apos; doc, p.dataproiect
                  from proiect p
                       inner join proiectnod pn on pn.codproiect = p.codproiect
                  where pn.codprodmat = v_rec.codmat and
                        not pn.codproiectnod in (select codproiectnod from nu)) loop

      update proiectnod set cant = cant * aCantNou / v_rec.cant where codproiectnod = v_xxx.codproiectnod;
      insert into tmp_manevra_liste(filtru, valoare) values (&apos;CODPROIECT&apos;, v_xxx.codproiect);
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_42&apos;)
      THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_xxx.codproiect, PKG_GLOBALS.FIRMANAME,
                                        PKG_GLOBALS.GETSUBUNITATE, v_xxx.DataProiect, v_xxx.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    end loop;
  end loop;

  commit;
end;

procedure INLOCMAT(ArtNou in number, ArtVechi in number) is
begin
  delete tmp_manevra_liste where filtru = &apos;CODPRODCOMP&apos; or filtru = &apos;CODPROIECT&apos;;
  for v_rec in (with nu as
                (
                select pn.codproiectnod
                from prodmat mat
                     inner join proiectnod pn on pn.codprodmat = mat.codmat
                     inner join proiect p on p.codproiect = pn.codproiect
                     inner join comanda1 c1 on c1.codproiect = p.codproiect
                     inner join cmdlink l on c1.codcomanda1 = l.codliniecomanda
                where mat.codobiect = artvechi
                union all
                select pn.codproiectnod
                from livr1 l1
                     inner join livr l on l1.codlivr = l.codlivr
                     inner join proiectnod pn on l1.codproiect = pn.codproiect
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                where nvl(l.anulat,0) = 0 and l.operat = 1 and mat.codobiect = artvechi
                )
                select pn.codproiectnod, pn.codproiect, &apos;Inloc.mat. (&apos;||pn.codproiectnod||&apos;)&apos; doc, p.dataproiect
                from proiectnod pn
                     inner join proiect p on p.codproiect = pn.codproiect
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                where mat.codobiect = artvechi and
                      not pn.codproiectnod in (select codproiectnod from nu)
               ) loop
    insert into tmp_manevra_liste(filtru, valoare) values (&apos;CODPROIECT&apos;, v_rec.codproiect);
    update proiectnod set codobiect = artnou where codobiect = artvechi and codproiectnod = v_rec.codproiectnod;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_42&apos;)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codproiect, PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, v_rec.DataProiect, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end loop;
  update normemat set codobiect = artnou where codobiect = artvechi and nvl(codmat,0) = 0;
  for v_rec in (with nu as
                (
                select mat.codmat
                from prodmat mat
                     inner join proiectnod pn on pn.codprodmat = mat.codmat
                     inner join proiect p on p.codproiect = pn.codproiect
                     inner join comanda1 c1 on c1.codproiect = p.codproiect
                     inner join cmdlink l on c1.codcomanda1 = l.codliniecomanda
                where mat.codobiect = artvechi
                union all
                select mat.codmat
                from livr1 l1
                     inner join livr l on l1.codlivr = l.codlivr
                     inner join proiectnod pn on l1.codproiect = pn.codproiect
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                where nvl(l.anulat,0) = 0 and l.operat = 1 and mat.codobiect = artvechi
                )
                select mat.codmat, mat.codprodcomp, pc.data,
                       &apos;OBJ:&apos;||obj.denumire||&apos; (&apos;||mat.CODPRODCOMP||&apos;) - inloc.mat.(&apos;||mat.codmat||&apos;)&apos; doc
                from prodmat mat
                     inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
                     inner join nartobj obj on obj.codobiect = pc.codobiect
                where mat.codobiect = artvechi and
                      not mat.codmat in (select codmat from nu)
               ) loop
    update prodmat set codobiect = artnou where codobiect = artvechi and codmat = v_rec.codmat;
    update normemat set codobiect = artnou where codmat = v_rec.codmat and codobiect = artvechi;
    insert into tmp_manevra_liste(filtru, valoare) values (&apos;CODPRODCOMP&apos;, v_rec.codprodcomp);
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end loop;

  commit;
end;

procedure SetParamsT(aTipFiltru in number, aDataStart in varchar2, aDataStop in varchar2) is
begin
  vTipFiltru := aTipFiltru;
  vDataStart := aDataStart;
  vDataStop  := aDataStop;
end;

function AduValoareMateriale(aCodProdComp in number) return number is
aVal number(20,7);
begin
  aVal := 0;
  begin
    select sum(case
                 when nvl(mat.tip,3) in (3,5) or nvl(mat.valmat,0) = 0 then nvl(mat.cant,0) * nvl(mat.pret,0)
                 else nvl(mat.cant,0) * nvl(mat.valmat,0)
               end) into aVal
    from prodmat mat
         inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
         inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and mat.codprodgest = pg.codprodgest
    where pc.codprodcomp = aCodProdComp;
  exception when others then aVal := 0;
  end;
  return aVal;
end;

function AduValoareManopera(aCodProdComp in number) return number is
aVal number(20,7);
begin
  aVal := 0;
  for v_rec in (select nvl(mat.cant,0) cant, nvl(mat.valman,0) valman
                from prodmat mat
                     inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
                     inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and mat.codprodgest = pg.codprodgest
                where pc.codprodcomp = aCodProdComp and not mat.tip in (3,5)
                ) loop
    aVal := aVal + v_rec.cant * v_rec.valman;
  end loop;

  for v_rec in (select nvl(man.BPS,0) BPS, nvl(t1.tarif,0) tarif, nvl(man.tu,0) tu
                from prodman man
                     inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
                     inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and man.codprodgest = pg.codprodgest
                     left  join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                where pc.codprodcomp = aCodProdComp
                ) loop
    if v_rec.BPS = 0 then
      aVal := aVal + Round(v_rec.Tarif * v_rec.TU / 60, 7);
    else
      aVal := aVal + Round(v_rec.Tarif * v_rec.TU / 60 / v_rec.BPS, 7);
    end if;
  end loop;
  return aVal;
end;

function AduValoareRegie(aCodProdComp in number, aValRegieMan out number) return number is
aVal number(20,7);
KTipCoefIndirecte number(1);
KRegieAntecalcul number(1);
begin
  aVal := 0;
  for v_rec in (select nvl(mat.cant,0) cant, nvl(mat.valregie,0) valregie
                from prodmat mat
                     inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
                     inner join prodgest pg on pc.codprodcomp = pg.codprodcomp and mat.codprodgest = pg.codprodgest
                where pc.codprodcomp = aCodProdComp and not mat.tip in (3,5)
                ) loop
    aVal := aVal + v_rec.cant * v_rec.valregie;
  end loop;

  if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
    for v_rec in (select nvl(coefindirecte,0) coefindirecte
                  from prodcomp
                  where codprodcomp = acodprodcomp) loop
      aVal := aVal + v_rec.CoefIndirecte;
    end loop;
  else
    for v_rec in (select nvl(pg.coefmat,nvl(g.coefcheltmat,0)) coefmat, nvl(mat.cant,0) cant, nvl(mat.pret,0) pret, pc.cant lot
                  from prodcomp pc
                       inner join prodmat mat on mat.codprodcomp = pc.codprodcomp
                       inner join prodgest pg on pg.codprodcomp = pc.codprodcomp and mat.codprodgest = pg.codprodgest
                       left join ngest g on g.codgest = pg.codgest
                  where pc.codprodcomp = aCodProdComp and nvl(mat.tip,3) in (3,5)
                  ) loop
      aVal := aVal + v_rec.Pret * v_rec.Cant / v_rec.lot * v_rec.CoefMat;
    end loop;

    aValRegieMan := 0;
    for v_rec in (select nvl(pg.coefman,nvl(g.coefcheltman,0)) coefman, nvl(man.bps,0) bps, nvl(t1.tarif,0) tarif, nvl(man.tu,0) tu
                  from prodcomp pc
                       inner join prodman man on man.codprodcomp = pc.codprodcomp
                       inner join prodgest pg on pg.codprodcomp = pc.codprodcomp and man.codprodgest = pg.codprodgest
                       left join ngest g on g.codgest = pg.codgest
                       left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                  where pc.codprodcomp = aCodProdComp
                  ) loop
          if v_rec.BPS = 0 then
            aVal := aVal + Round(v_rec.Tarif * v_rec.TU / 60 * v_rec.CoefMan,7);
            aValRegieMan := aValRegieMan + Round(v_rec.Tarif * v_rec.TU / 60 * v_rec.CoefMan,7);
          else
            aVal := aVal + Round(v_rec.Tarif * v_rec.TU / 60 / v_rec.BPS * v_rec.CoefMan,7);
            aValRegieMan := aValRegieMan + Round(v_rec.Tarif * v_rec.TU / 60 / v_rec.BPS * v_rec.CoefMan,7);
          end if;
    end loop;
  end if;
  return aVal;
end;

function CalcAndGetPretRef(aCodProdComp in number) return number is pragma autonomous_transaction;
aValMat number(20,7);
aValMan number(20,7);
aValRegie number(20,7);
aPret number(20,7);
aValRegieMan number(20,7);
begin
  aPret := 0;
  for v_rec in (select cant, nvl(tippret,1) tippret
                from prodcomp
                where codprodcomp = acodprodcomp and cant &gt; 0) loop
    if v_rec.TipPret = 1 then
      aValMat   := AduValoareMateriale(aCodProdComp);
      aValMan   := AduValoareManopera(aCodProdComp);
      aValRegie := AduValoareRegie(aCodProdComp, aValRegieMan);
      aPret := aValMat/v_rec.Cant + aValMan + aValRegie;
      update prodcomp set
        pret = apret,
        pretvaluta = case when nvl(codmoneda,0) = 0 then apret else apret /
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
        nvl(codmoneda,0),
        decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
               0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
               pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
        sysdate) end,
        valmat = aValMat,
        valman = aValMan,
        valregie = aValRegie,
        valregieMan = aValRegieMan,
        valag = ag /100 * (avalman + avalregieman)
      where codprodcomp = aCodProdcomp;

      update prodcomp set
        totpretfix = nvl(Pret,0) + nvl(CoefIndirecte,0) + nvl(ValAG,0),
        totpretcoef = nvl(Pret,0) * (1.0 + nvl(CoefIndirecte,0))
      where codprodcomp = acodprodcomp;

      update prodcomp set
        valprofit = nvl(Profit,0) / 100 * nvl(TotPretFix,0)
      where codprodcomp = acodprodcomp;

      update prodcomp set
        pretfinal = nvl(ValProfit,0) + nvl(TotPretFix,0)
      where codprodcomp = acodprodcomp;

      update prodcomp set
        TotPretFixV = TotPretFix /
                      case
                        when nvl(codmoneda,0) = 0 then 1
                        else
                          PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                            nvl(codmoneda,0),
                            decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
                            sysdate)
                      end,
        TotPretCoefV = TotPretCoef /
                      case
                        when nvl(codmoneda,0) = 0 then 1
                        else
                          PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                            nvl(codmoneda,0),
                            decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
                            sysdate)
                      end,
        PretFinalV = PretFinal /
                      case
                        when nvl(codmoneda,0) = 0 then 1
                        else
                          PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                            nvl(codmoneda,0),
                            decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
                            sysdate)
                      end
      where codprodcomp = acodprodcomp;
    else
      aValMat   := AduValoareMateriale(aCodProdComp);
      aPret := aValMat/v_rec.Cant;
      update prodcomp set
        pret = apret,
        pretvaluta = case when nvl(codmoneda,0) = 0 then apret else apret /
        PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
          codmoneda,
          decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
          sysdate) end,
        valmat = aValMat
      where codprodcomp = aCodProdcomp;
    end if;
  end loop;
  commit;
  return aPret;
end;

procedure sterge_mat(aCodMat in number) is pragma autonomous_transaction;
begin
  for v_rec in (select mat.codmat, mat.codprodcomp, pc.data,
                       &apos;OBJ:&apos;||prod.denumire||&apos; (&apos;||mat.CODPRODCOMP||&apos;) - sterg.mat.(&apos;||obj.denumire||&apos;)&apos; doc
                from prodmat mat
                     inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
                     inner join nartobj prod on prod.codobiect = pc.codobiect
                     inner join nartobj obj on obj.codobiect = mat.codobiect
                where mat.codmat = aCodMat) loop
    delete prodmat where codmat = v_rec.CodMat;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end loop;
  commit;
end;

procedure sterge_man(aCodMan in number) is pragma autonomous_transaction;
begin
  for v_rec in (select man.codman, man.codprodcomp, pc.data,
                       &apos;OBJ:&apos;||obj.denumire||&apos; (&apos;||man.CODPRODCOMP||&apos;) - sterg.op.(&apos;||op.denumire||&apos;)&apos; doc
                from prodman man
                     inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
                     inner join nartobj obj on obj.codobiect = pc.codobiect
                     inner join noper op on man.codop = op.codop
                where man.codman = aCodMan) loop
    delete prodman where codman = v_rec.CodMan;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end loop;
  commit;
end;

function baga_man_nou(aCodprodcomp in number,
                      aNrop in number,
                      aCodop in number,
                      aCodloc in number,
                      aCodtarif in number,
                      aTu in number,
                      aValoare in number,
                      aCodprodgest in number,
                      aDsv in number,
                      aBps in number,
                      aTpi in number,
                      aDetalii in number,
                      aFix in number,
                      aNivel in number) return number is pragma autonomous_transaction;
vCod number(20);
vDenumire varchar2(100);
begin
  begin
    select denumire into vDenumire from noper where codop = aCodOp;
  exception when others then vDenumire := &apos;&apos;;
  end;

  for v_rec in (select nvl(pg.coefman, g.coefcheltman) coef, pc.tippret,
                       pc.codprodcomp, pc.data,
                       &apos;OBJ:&apos;||obj.denumire||&apos; (&apos;||pc.CODPRODCOMP||&apos;) - adaug op.(&apos;||vdenumire||&apos;)&apos; doc
                from prodgest pg
                     inner join ngest g on pg.codgest = g.codgest
                     inner join prodcomp pc on pg.codprodcomp = pc.codprodcomp
                     inner join nartobj obj on obj.codobiect = pc.codobiect
                where pc.codprodcomp = aCodProdComp and pg.codprodgest = aCodProdGest) loop
    select seq_prodman_codman.nextval into vCod from dual;
    insert into prodman (
      codman,
      codprodcomp,
      nrop,
      codop,
      codloc,
      codtarif,
      tu,
      valoare,
      codprodgest,
      dsv,
      bps,
      tpi,
      Detalii, Fix, Nivel, Coefbps)
    values (
      vCod,
      aCodprodcomp,
      aNrop,
      aCodop,
      aCodloc,
      aCodtarif,
      aTu,
      aValoare,
      aCodprodgest,
      aDsv,
      aBps,
      aTpi,
      aDetalii, aFix, aNivel, 0
      );
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    Exit;
  end loop;
  commit;
  return vCod;
end;

function baga_mat_nou(aCodprodcomp in number,
                      aCodobiect in number,
                      aCant in number,
                      aPret in number,
                      aD1 in number,
                      aD2 in number,
                      aD3 in number,
                      aIndexlocal in number,
                      aCantum1 in number,
                      aCodprodgest in number,
                      aTip in number,
                      aPretorig in number,
                      aValoare in number) return number is pragma autonomous_transaction;
vCod number(20);
aLot number(20,7);
vDenumire varchar2(200);
begin
  begin
    select denumire into vDenumire from nartobj where codobiect = aCodObiect;
  exception when others then vDenumire := &apos;&apos;;
  end;
  if aTip = 1 then
    for v_rec in (select nvl(pg.coefmat, g.coefcheltmat) coef, pc.tippret,
                         pc.codprodcomp, pc.data,
                         &apos;OBJ:&apos;||prod.denumire||&apos; (&apos;||pc.CODPRODCOMP||&apos;) - adaug mat.(&apos;||vdenumire||&apos;)&apos; doc
                from prodgest pg
                     inner join ngest g on pg.codgest = g.codgest
                     inner join prodcomp pc on pg.codprodcomp = pc.codprodcomp
                     inner join nartobj prod on prod.codobiect = pc.codobiect
                where pc.codprodcomp = aCodProdComp and pg.codprodgest = aCodProdGest) loop
      select seq_prodmat_codmat.nextval into vCod from dual;
      insert into prodmat (
        codmat,
        codprodcomp,
        codobiect,
        cant,
        pret,
        d1,
        d2,
        d3,
        indexlocal,
        cantum1,
        codprodgest,
        tip,
        pretorig,
        valoare
        )
      values (
        vCod,
        aCodprodcomp,
        aCodobiect,
        aCant,
        aPret,
        aD1,
        aD2,
        aD3,
        aIndexlocal,
        aCantum1,
        aCodprodgest,
        3,
        aPretorig,
        aValoare
        );
      begin
        select cant into aLot from prodcomp where codprodcomp = aCodProdComp;
      exception when others then aLot := 1;
      end;
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc, null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      for v_tmp in (select pn.CODPROIECTNOD,pn.CODPROIECT,pn.CANT,pn.NODORIGINAL,pn.POZITIE,pn.CODRETETA,pn.TIP,pn.CODOBIECT,pn.INDEXPARINTE,pn.CODPRODMAT,pn.NIVEL,pn.ORDINE,nvl(pnm.maxpoz,1) maxpoz,
                           &apos;Adaug mat. (&apos;||pn.codproiectnod||&apos;) - &apos;||vDenumire doc, p.dataproiect
                    from proiectnod pn
                         inner join proiect p on p.codproiect = pn.codproiect
                         left join (select max(pozitie)+1 maxpoz, nodoriginal from proiectnod group by nodoriginal) pnm on pnm.nodoriginal = pn.codproiectnod
                    where pn.codreteta = aCodProdComp
                   ) loop
        insert into proiectnod(
          codproiectnod,
          codproiect,
          cant,
          nodoriginal,
          pozitie,
          codreteta,
          tip,
          codobiect,
          indexparinte,
          codprodmat,
          nivel,
          ordine)
        values (
          seq_proiectnod_codproiectnod.nextval,
          v_tmp.codproiect,
          v_tmp.cant/aLot * acant,
          v_tmp.codproiectnod,
          v_tmp.maxpoz,
          0,
          3,
          acodobiect,
          v_tmp.indexparinte||&apos;.&apos;||to_char(v_tmp.maxpoz, &apos;00&apos;),
          vCod,
          v_tmp.nivel + 1,
          0
          );
        IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,&apos;MON_42&apos;)
        THEN
          WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_tmp.codproiect, PKG_GLOBALS.FIRMANAME,
                                          PKG_GLOBALS.GETSUBUNITATE, v_tmp.DataProiect, v_tmp.Doc,null, PKG_GLOBALS.GET_EXE_VERSION);
        END IF;
      end loop;
      Exit;
    end loop;
  else
    for v_rec in (select nvl(pg.coefmat, g.coefcheltmat) coef, pc.tippret,
                         pc.codprodcomp, pc.data,
                         &apos;OBJ:&apos;||prod.denumire||&apos; (&apos;||pc.CODPRODCOMP||&apos;) - adaug rez.(&apos;||vdenumire||&apos;)&apos; doc
                from prodgest pg
                     inner join ngest g on pg.codgest = g.codgest
                     inner join prodcomp pc on pg.codprodcomp = pc.codprodcomp
                     inner join nartobj prod on prod.codobiect = pc.codobiect
                where pc.codprodcomp = aCodProdComp and pg.codprodgest = aCodProdGest) loop
      select seq_prodrez_codrez.nextval into vCod from dual;
      insert into prodrez(
        codrez,
        codprodcomp,
        codobiect,
        cant,
        pret,
        d1,
        d2,
        d3,
        indexlocal,
        reziduu,
        cantum1,
        codprodgest)
      values (
        vCod,
        aCodprodcomp,
        aCodobiect,
        aCant,
        aPret,
        aD1,
        aD2,
        aD3,
        aIndexlocal,
        0,
        aCantum1,
        aCodprodgest
        );
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, v_rec.codprodcomp, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, v_rec.Data, v_rec.Doc, null, PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      Exit;
    end loop;
  end if;
  commit;
  return vCod;
end;

procedure STERGERETETASIPROIECT(aCodProdComp in number) is
begin
  pkg_prodcomp.SP_DELETERECORD(aCodProdComp);
  for v_rec in (select codproiect
                from proiectnod
                where codreteta = aCodProdComp and nvl(nodoriginal,0) = 0) loop
    pkg_proiect.SP_DELETERECORD(v_rec.codproiect);
  end loop;
end;

procedure UpdateValManDinTarif(aCodTarif1 in number, aTipFiltru in number, aDataStart in varchar2, aDataStop in varchar2) is
aPretRef number(20,7);
begin
  for v_rec in (select man.codman, nvl(man.tu,0) * nvl(t1.tarif,0)/60 valoare
                from tarifeman1 t1
                     inner join prodman man on man.codtarif = t1.codtarif
                     inner join prodcomp pc on man.codprodcomp = pc.codprodcomp
                where t1.codtarif1 = aCodTarif1
                      and ((aTipFiltru = 0) or (aTipFiltru in (1,3) and pc.data between to_date(aDataStart,&apos;dd.mm.yyyy&apos;) and to_date(aDataStop,&apos;dd.mm.yyyy&apos;))
                           or (aTipFiltru = 2 and pc.data &gt;= to_date(aDataStart,&apos;dd.mm.yyyy&apos;)))
                ) loop
    update prodman set valoare = v_rec.valoare where codman = v_rec.codman;
  end loop;
  if pkg_categconst.GetValConstanta(&apos;PretRefAutReteta&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 then
    for v_rec in (select distinct man.codprodcomp
                  from tarifeman1 t1
                       inner join prodman man on man.codtarif = t1.codtarif
                       inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
                  where t1.codtarif1 = aCodTarif1
                        and ((aTipFiltru = 0) or (aTipFiltru in (1,3) and pc.data between to_date(aDataStart,&apos;dd.mm.yyyy&apos;) and to_date(aDataStop,&apos;dd.mm.yyyy&apos;))
                           or (aTipFiltru = 2 and pc.data &gt;= to_date(aDataStart,&apos;dd.mm.yyyy&apos;)))
                  ) loop
      aPretRef := CalcAndGetPretRef(v_rec.codprodcomp);
    end loop;
  end if;
  commit;
end;

function GetRetetaGenerica(aCodObiect in number) return number is
aCodReteta number(20);
begin
  aCodReteta := 0;
  begin
    select codprodcomp into aCodReteta from prodcomp where generic = 1 and codobiect = acodobiect;
  exception when others then aCodReteta := 0;
  end;
  return aCodReteta;
end;

procedure SetLucruCuGenerice(aMod in number) is
begin
  vModGenerice := aMod;
end;

procedure SetTipPretDin(aTipPretDin in number) is
begin
  vTipPretDin := aTipPretDin;
end;

procedure Set_Mat_Echivalat(aCodMat IN NUMBER) is
begin
  vCodMat := aCodMat;
end;

function Get_Mat_Echivalat return number is
begin
  return vCodMat;
end;

procedure UpdateManAll(aCodProdComp IN NUMBER) is
aCount number(10);
begin
  for v_rec in (select pc.codprodcomp, pg.codprodgest
                from prodcomp pc
                     inner join prodgest pg on pc.codprodcomp = pg.codprodcomp) loop
    select count(*) into aCount from prodgest where codprodcomp = v_rec.codprodcomp;
    if aCount = 1 then
      delete prodman where codprodcomp = v_rec.codprodcomp and codprodgest = v_rec.codprodgest;
      insert into prodman (codman, codprodcomp, nrop, codop, codloc, codtarif, tu, valoare, codprodgest, indexlocal, dsv, bps, tpi, obs, Detalii, Fix, Nivel)
      select seq_prodman_codman.nextval, v_rec.codprodcomp, nrop, codop, codloc, codtarif, tu, valoare, v_rec.codprodgest, indexlocal, dsv, bps, tpi, obs, Detalii, Fix, Nivel
      from prodman where codprodcomp = aCodProdComp;
    end if;
  end loop;
  commit;
end;

procedure UpdatePretDinPostCalc(aTip IN NUMBER)  is
xMat number;
xVal number;
begin
  delete prodcomp_clona;

  if pkg_categconst.GetValConstanta(&apos;TipValMatPC&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 2 then
    xMat := 1;
    xVal := 0;
  else
    xMat := 0;
    xVal := 1;
  end if;

  insert into TMP_PCArt_Pret (codobiect, codArticol, valmat, valman, valregie)
  select Codobiect, 0, Round((Sum(xMat*nvl(Mat,0))+Sum(xVal*nvl(Val,0))) /Sum(nvl(Cant,0)), 5),
                       Round(Sum(nvl(Man,0)) /Sum(nvl(Cant,0)), 5),
                       Round(Sum(nvl(ValS,0))/Sum(nvl(Cant,0)), 5)
  from tmp_pcart group by codobiect;

  if pkg_categconst.GetValConstanta(&apos;PretRefUnicArticol&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1   then
    update TMP_PCArt_Pret pc set pc.CodArticol = (select codarticol from nartobj where codobiect = pc.codobiect);
    for v_rec in
    (select na.Codarticol, Round((Sum(xMat*nvl(pc.Mat,0))+Sum(xVal*nvl(pc.Val,0))) /Sum(nvl(pc.Cant,0)), 5) valmat,
                           Round(Sum(nvl(pc.Man,0)) /Sum(nvl(pc.Cant,0)), 5) valman,
                           Round(Sum(nvl(pc.ValS,0))/Sum(nvl(pc.Cant,0)), 5) ValRegie
    from tmp_pcart pc inner join NartObj na on na.codobiect = pc.codobiect group by na.codArticol)
    loop
      update TMP_PCArt_Pret set
      valmat = v_rec.valmat,
      valman = v_rec.valman,
      valregie = v_rec.valRegie
      where CodArticol = v_rec.CodArticol;
    end loop;
  end if;

  UpdateNArtObj1(aTip);
end;

procedure UpdateNArtObj1(aTip IN NUMBER) is
vValMat number(20,7);
vValMan number(20,7);
vValRegie number(20,7);
begin
  -- merg pe inregistrarea valabila acum
  --inserez cele care nu sunt si apoi facem update la toate
  for v_rec in (select obj1.*
                from nartobj1 obj1
                     inner join (select distinct codobiect from TMP_PCArt_Pret) pcc on pcc.codobiect = obj1.codobiect
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                order by obj1.codobiect
               )
  loop

    if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; pkg_globals.GetANLUCRU*12+pkg_globals.GetlunaLUCRU then
      insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                            , anstart, lunastart, tippretmax, compensat, tipcompensare
                            , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                            , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                            , punctesectie, tippret)
       values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                            , pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare
                            , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                            , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                            , v_Rec.punctesectie, nvl(v_rec.tippret,1));
       prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
       commit;
    end if;

  end loop;

  for v_rec in (select obj1.codobiect1, obj1.codobiect, obj1.TipPret, c.valmat, c.valman, c.valregie
                from nartobj1 obj1
                     inner join TMP_PCArt_Pret c on c.codobiect = obj1.codobiect
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
               )
  loop
    vValMat   := nvl(v_rec.ValMat,   0);
    vValMan   := nvl(v_rec.ValMan,   0);
    vValRegie := nvl(v_rec.ValRegie, 0);

    if aTip = 1 then
      update nartobj1
      set pretreferinta = vValMat +  (2-v_rec.tippret)*vValMan + (2-v_rec.tippret)*vValRegie,
          valmat = vValMat,
          valman = vValMan,
          valregie = vValRegie
      where codobiect1 = v_Rec.codobiect1;
      update tmp_pcart
      set PretReferinta = vValMat +  (2-v_rec.tippret)*vValMan + (2-v_rec.tippret)*vValRegie
      where codobiect = v_rec.codobiect;
    else
      update nartobj1
      set valmat = vValMat,
          valman = vValMan,
          valregie = vValRegie
      where codobiect1 = v_Rec.codobiect1;
    end if;
  end loop;
  commit;
end;

procedure UpdatePretFixMat(aCodObiect in number, aPret in number) is
begin
  update prodmat
  set pret = aPret
  where pret = 0 and codobiect = aCodObiect;
  commit;
end;

procedure TestRetete is
aCount number(10);
aPret number(20,7);
begin
  for v_rec in (select pc.codprodcomp, mat.codmat, mat.codobiect material, nvl(mat.tip,3) tip, pc.codobiect, nvl(mat.pret,0) pret
                from prodcomp_clona pcc
                     inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                     inner join prodmat mat on mat.codprodcomp = pc.codprodcomp
                where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0
                ) loop
    if (v_rec.tip = 1) or (v_rec.tip = 2) then
      -- complex : test de existenta a retetei
      select count(*) into aCount
      from prodcomp_clona pcc
           inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
      where pc.codobiect = v_Rec.material;
      if aCount = 0 then
        insert into tmp_atentionari (tip, camp1, camp2, camp3, camp4)
        values (1, v_Rec.codprodcomp, v_rec.codobiect, v_rec.codmat, v_rec.material);
      end if;
    else
      select count(*) into aCount
      from prodcomp_clona pcc
           inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
      where pc.codobiect = v_Rec.material;
      if aCount &gt; 0 then
        insert into tmp_atentionari (tip, camp1, camp2, camp3, camp4)
        values (2, v_Rec.codprodcomp, v_rec.codobiect, v_rec.codmat, v_rec.material);
      end if;
      aPret := GetpretFromStoc(v_rec.material);
      if aPret = 0.0 then
        if v_rec.pret = 0 and v_rec.tip &lt;&gt; 4 then
          insert into tmp_atentionari (tip, camp1, camp2, camp3, camp4)
          values (3, v_Rec.codprodcomp, v_rec.codobiect, v_rec.codmat, v_rec.material);
        end if;
      end if;
    end if;
  end loop;
end;

function GetPretFromStoc(aCodObiect in number) return number is
aCount number(10);
pret number(20,7);
begin
  pret := 0;
  select count(*) into aCount from tmp_manevra_preturi where codobiect = aCodObiect;
  if aCount &gt; 0 then
    select nvl(pret,0) into pret from tmp_manevra_preturi where codobiect = acodobiect and rownum =1 ;
  end if;
  return pret;
end;

function GetPretFromCompusi(aCodObiect in number) return number is
aCount number(10);
pret number(20,7);
begin
  pret := 0;
  select count(*) into aCount from tmp_manevra_compusi where codobiect = aCodObiect;
  if aCount &gt; 0 then
    select nvl(pret,0) into pret from tmp_manevra_compusi where codobiect = acodobiect and rownum =1 ;
  end if;
  return pret;
end;

function GetValMatFromCompusi(aCodObiect in number) return number is
aCount number(10);
valmat number(20,7);
begin
  valmat := 0;
  select count(*) into aCount from tmp_manevra_compusi where codobiect = aCodObiect;
  if aCount &gt; 0 then
    select nvl(valmat,0) into valmat from tmp_manevra_compusi where codobiect = acodobiect and rownum =1 ;
  end if;
  return valmat;
end;

function GetValManFromCompusi(aCodObiect in number) return number is
aCount number(10);
valman number(20,7);
begin
  valman := 0;
  select count(*) into aCount from tmp_manevra_compusi where codobiect = aCodObiect;
  if aCount &gt; 0 then
    select nvl(valman,0) into valman from tmp_manevra_compusi where codobiect = acodobiect and rownum =1 ;
  end if;
  return valman;
end;

function GetRegieFromCompusi(aCodObiect in number) return number is
aCount number(10);
regie number(20,7);
begin
  regie := 0;
  select count(*) into aCount from tmp_manevra_compusi where codobiect = aCodObiect;
  if aCount &gt; 0 then
    select nvl(regie,0) into regie from tmp_manevra_compusi where codobiect = acodobiect and rownum =1 ;
  end if;
  return regie;
end;

procedure GetPreturi0(AnLunaDela in number, AnLunaPanaLa in number, aCodProdComp in number, aMarja in number) is
begin
  GetPreturi(AnLunaDeLa, AnLunaPanaLa, aCodProdComp, aMarja);
  update tmp_manevra_preturi set pret = 0;
  commit;
  delete tmp_manevra_preturi_Detalii;
  commit;

  insert into tmp_manevra_preturi_Detalii(codobiect, codarticol, pret, obj_codextern, obj_codintern)
  select codobiect, codarticol, pret, obj_codextern, obj_codintern from tmp_manevra_preturi;
  commit;
end;

procedure GetPreturi(AnLunaDela in number, AnLunaPanaLa in number, aCodProdComp in number, aMarja in number, aDinManevra in boolean default false) is
TipPret number(1);
RetGenerica number(1);
begin
  RetGenerica := 0;
  if aCodProdComp &gt; 0 then
    select nvl(generic,0) into RetGenerica from prodcomp where codprodcomp = aCodProdComp;
  end if;

  ArmeazaTMPs(aCodProdComp, aDinManevra);
  TipPret := To_Number(Pkg_Categconst.GetValConstanta(&apos;TipEvaluarePret&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru));
  if TipPret &gt; 3 or TipPret &lt; 1 then TipPret := 2; end if;

  delete tmp_manevra_preturi;
  delete tmp_manevra_preturi_Detalii;

  if vModGenerice = 1 then
    if RetGenerica = 1 then
      insert into tmp_manevra_preturi_Detalii(pret, codobiect, codnirstoc, cant, dataachiz, codarticol, codatribut, codobiectgeneric, obj_codextern, obj_codintern)
      select distinct a.PU, a.CodObiect, a.codnirstoc, a.cantnir, a.dataachiz, a.codarticol, a.codatribut,
                       pkg_nom_articol.getcodobiectgeneric(a.CodArticol), a.obj_codextern, a.obj_codintern
      from
        (select distinct nvl(NS_OK.PU, 0) pu, mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, coalesce(mat.codatribut,0) codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, o.CodArticol, ns.codnirstoc, ns.cantnir, ns.dataachiz, ns.codobiect
                  from nirstoc ns
                  inner join nartobj o on o.codobiect = ns.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip in (3,5) and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         union all
         select distinct nvl(NS_OK.PU,0) pu, mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, coalesce(mat.codatribut,0) codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on ns.codobiect = o.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip &lt; 3
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         and not exists (select codprodcomp from prodcomp where codobiect = mat.codobiect)
         union all
         select distinct nvl(NS_OK.PU,0) pu, pc.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, 0 codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodcomp pc
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on pc.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on ns.codobiect = o.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and pc.tipreteta = 2
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
        ) a;
    else
      insert into tmp_manevra_preturi_Detalii(pret, codobiect, codnirstoc, cant, dataachiz, codobiectgeneric, codarticol, obj_codextern, obj_codintern)
      select distinct a.PU, a.CodObiect, a.codnirstoc, a.cantnir, a.dataachiz,
                       pkg_nom_articol.getcodobiectgeneric(a.CodArticol), a.codarticol, a.obj_codextern, a.obj_codintern
      from
        (select distinct nvl(NS_OK.PU, 0) pu,mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on o.codobiect = ns.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip in (3,5) and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         union all
         select distinct nvl(NS_OK.PU,0) pu, mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on o.codobiect = ns.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip &lt; 3
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         and not exists (select codprodcomp from prodcomp where codobiect = mat.codobiect)
         union all
         select distinct nvl(NS_OK.PU,0) pu, pc.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodcomp pc
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on pc.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on ns.codobiect = o.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and pc.tipreteta = 2
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
        ) a;
    end if;
  else
    if RetGenerica = 1 then
      insert into tmp_manevra_preturi_Detalii(pret, codobiect, codnirstoc, cant, dataachiz, codarticol, codatribut, obj_codextern, obj_codintern)
      select distinct a.PU, a.CodObiect, a.codnirstoc, a.cantnir, a.dataachiz, a.codarticol, a.codatribut, a.obj_codextern, a.obj_codintern
      from
        (select distinct nvl(NS_OK.PU, 0) pu, Mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, coalesce(mat.codatribut,0) codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz
                  from nirstoc ns
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on mat.codobiect = NS_OK.codobiect
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip in (3,5) and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         union all
         select distinct nvl(NS_OK.PU,0) pu, Mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, coalesce(mat.codatribut,0) codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz
                  from nirstoc ns
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on mat.codobiect = NS_OK.codobiect
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip &lt; 3
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         and not exists (select codprodcomp from prodcomp where codobiect = mat.codobiect)
         union all
         select distinct nvl(NS_OK.PU,0) pu, pc.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol, 0 codatribut,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodcomp pc
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on pc.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on ns.codobiect = o.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and pc.tipreteta = 2
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
        ) a;
    else
      insert into tmp_manevra_preturi_Detalii(pret, codobiect, codnirstoc, cant, dataachiz, codarticol, obj_codextern, obj_codintern)
      select distinct a.PU, a.CodObiect, a.codnirstoc, a.cantnir, a.dataachiz, a.codarticol, a.obj_codextern, a.obj_codintern
      from
        (select distinct nvl(NS_OK.PU, 0) pu, Mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz
                  from nirstoc ns
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on mat.codobiect = NS_OK.codobiect
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip in (3,5) and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         union all
         select distinct nvl(NS_OK.PU,0) pu, Mat.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodmat mat
              inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on mat.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz
                  from nirstoc ns
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on mat.codobiect = NS_OK.codobiect
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and mat.Tip &lt; 3
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
         and not exists (select codprodcomp from prodcomp where codobiect = mat.codobiect)
         union all
         select distinct nvl(NS_OK.PU,0) pu, pc.codobiect, ns_ok.codnirstoc, nvl(ns_ok.cantnir,0) cantnir, ns_ok.dataachiz, obj.codarticol,
                obj.codextern as obj_codextern, obj.codintern as obj_codintern
         from prodcomp pc
              inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
              inner join nartobj obj on pc.codobiect = obj.codobiect
              left join
                (
                  select nvl(NS.pret,0) - nvl(NS.adaos, 0) PU, NS.CodObiect, ns.codnirstoc, ns.cantnir, ns.dataachiz, o.codarticol
                  from nirstoc ns
                  inner join nartobj o on ns.codobiect = o.codobiect
                  inner join nir on nir.codnir = ns.codnir
                  inner join intrari i on nir.codintr = i.codintr
                  left join dvi on dvi.codintr = i.codintr
                  left join (select * from ngest where nvl(tip,0) &lt;&gt; 4) g on nir.gest = g.codgest
                  where (extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &gt;= AnLunaDeLa
                  AND extract(YEAR FROM NS.dataachiz)*12 + extract(MONTH FROM NS.dataachiz) &lt;= AnLunaPanaLa)
                  and nvl(ns.pret, 0) - nvl(ns.adaos,0) &lt;&gt; 0 and ns.cantnir &lt;&gt; 0 and nvl(dvi.tipimport,0) = 0
                  and i.anulat = 0 and i.operat = 1 and nir.operat = 1
                ) NS_OK on obj.codarticol = NS_OK.codarticol
         where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and pc.tipreteta = 2
         and ( aCodProdComp = 0 or pc.codprodcomp = aCodProdComp)
        ) a;
    end if;
  end if;

  if DoCommit then
    commit;
  end if;

  if vModGenerice &lt;&gt; 1 then
    if TipPret = 1 then
      insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
      select tmp.codobiect, max(nvl(tmp.pret,0)), obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut,
             obj.codextern as obj_codextern, obj.codintern as obj_codintern
      from tmp_manevra_preturi_Detalii tmp
           inner join nartobj obj on tmp.codobiect = obj.codobiect
           inner join nart on obj.codarticol = nart.codarticol
           left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
      group by tmp.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern ;
    else
      if TipPret = 3 then
        insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
        select tmp.codobiect,min(nvl(tmp.pret,0)), obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut,
             obj.codextern as obj_codextern, obj.codintern as obj_codintern
        from tmp_manevra_preturi_Detalii tmp
             inner join nartobj obj on tmp.codobiect = obj.codobiect
             inner join nart on obj.codarticol = nart.codarticol
             left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
        group by tmp.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern ;
      else
        insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
        select codobiect, case when nvl(cantitate,0) = 0 then 0 else nvl(valoare,0)/nvl(cantitate,0) end, 
               denumire, den_claseas, codarticol, codatribut, obj_codextern, obj_codintern  
        from (
            select tmp.codobiect,sum(tmp.cant * tmp.pret) valoare, sum(nvl(tmp.cant,0)) cantitate, 
                   obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut,
                   obj.codextern as obj_codextern, obj.codintern as obj_codintern
              from tmp_manevra_preturi_Detalii tmp
                   inner join nartobj obj on tmp.codobiect = obj.codobiect
                   inner join nart on obj.codarticol = nart.codarticol
                   left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
              group by tmp.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern);
      end if;
    end if;
  else
    if TipPret = 1 then
      insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
      select mat.codobiect,max(nvl(tmp.pret,0)), obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut,
                   obj.codextern as obj_codextern, obj.codintern as obj_codintern
      from prodmat mat
           inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
           inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
           inner join nartobj obj on mat.codobiect = obj.codobiect
           inner join tmp_manevra_preturi_Detalii tmp on tmp.codarticol = obj.codarticol
           inner join nart on obj.codarticol = nart.codarticol
           left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
      group by mat.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern;
    else
      if TipPret = 3 then
        insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
        select mat.codobiect,min(nvl(tmp.pret,0)), obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut,
                   obj.codextern as obj_codextern, obj.codintern as obj_codintern
        from prodmat mat
             inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
             inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
             inner join nartobj obj on mat.codobiect = obj.codobiect
             inner join tmp_manevra_preturi_Detalii tmp on tmp.codarticol = obj.codarticol
             inner join nart on obj.codarticol = nart.codarticol
             left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
        group by mat.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern;
      else
        insert into tmp_manevra_preturi (codobiect, pret, denumire, DEN_CLASEAS, codarticol, codatribut, obj_codextern, obj_codintern)
        select codobiect, case when nvl(cantitate,0) = 0 then 0 else nvl(valoare,0)/nvl(cantitate,0) end, denumire,
                den_claseas, codarticol, codatribut, obj_codextern, obj_codintern 
        from (
        select mat.codobiect,sum(tmp.cant * tmp.pret) valoare, sum(nvl(tmp.cant,0)) cantitate, obj.denumire, nclaseas.den_claseas,
               tmp.codarticol, tmp.codatribut, obj.codextern as obj_codextern, obj.codintern as obj_codintern
        from prodmat mat
             inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
             inner join prodcomp_clona pcc on pcc.codprodcomp = pc.codprodcomp
             inner join nartobj obj on mat.codobiect = obj.codobiect
             inner join tmp_manevra_preturi_Detalii tmp on tmp.codarticol = obj.codarticol
             inner join nart on obj.codarticol = nart.codarticol
             left  join nclaseas on nart.clasastatist = nclaseas.codclaseas
        group by mat.codobiect, obj.denumire, nclaseas.den_claseas, tmp.codarticol, tmp.codatribut, obj.codextern, obj.codintern);
      end if;
    end if;
  end if;
  if DoCommit then
    commit;
  end if;

  delete tmp_manevra_preturi_Detalii where pret = 0;

  for v_Rec in (select tmp.codobiect, tmp.codarticol, tmp.pret, tmp.obj_codextern, tmp.obj_codintern
                from tmp_manevra_preturi tmp
                     left join (select count(*) nr, codarticol, codobiect
                                from tmp_manevra_preturi_Detalii
                                group by codarticol, codobiect) Detalii on nvl(Detalii.codobiect,0) = nvl(tmp.codobiect,0) 
                                                                        and nvl(Detalii.codarticol,0) = nvl(tmp.codarticol,0)
                where Detalii.nr = 0) loop
    insert into tmp_manevra_preturi_Detalii(codobiect, codarticol, pret, obj_codextern, obj_codintern)
    values (v_rec.codobiect, v_rec.codarticol, v_rec.pret, v_rec.obj_codextern, v_rec.obj_codintern);
  end loop;

  for v_rec in (select distinct codobiect
                from tmp_manevra_preturi_Detalii) loop

    for v_tmp in (select a.*, RowNum from (select tmp.codobiect, tmp.pret, tmp.codnirstoc, tmp.ordine
                  from tmp_manevra_preturi_Detalii tmp
                       left join nirstoc ns on tmp.codnirstoc = ns.codnirstoc
                  where tmp.codobiect = v_Rec.Codobiect
                  order by ns.dataachiz desc) a ) loop

      update tmp_manevra_preturi_Detalii set ordine = v_tmp.RowNum
      where codnirstoc = v_tmp.codnirstoc
            and codobiect = v_rec.codobiect;
    end loop;
  end loop;

  if DoCommit then
    commit;
  end if;

  SeteazaStare(aMarja);
end;

function GetPretMaterialCompus(aCodObiect in number, aPret in number, TipPret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
vPret number(20,7);
valmat number(20,7);
valman number(20,7);
regie number(20,7);
PretDinStoc number(20,7);
PretMax number(20,7);
PretMin number(20,7);
begin
  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
  where pc.codobiect = aCodObiect;

  if aCount = 0 then
    PretDinStoc := GetPretFromStoc(aCodObiect);
    if PretDinStoc = 0 then
      return aPret;
    else
      return PretDinStoc;
    end if;
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    PretDinStoc := GetPretFromCompusi(aCodObiect);
    if PretDinStoc &gt; 0 then
      return PretDinStoc;
    end if;
  end if;


  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
  where pc.codobiect = aCodObiect
  and pc.generic = 1;

  if aCount2 &gt; 0 then
    vPret := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret,
                          nvl(pc.CoefIndirecte,0) CoefIndirecte
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                        inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                   where pc.codobiect = aCodObiect
                         and pc.generic = 1) loop
      if v_rec1.tippret = 1 then
        valmat := 0;
        valman := 0;
        regie  := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
          --manopera retetei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            valman := valman + v_tmp.valoare;
            if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
              regie  := regie  + v_tmp.valoare * v_tmp.coefcheltman;
            end if;
          end loop;
          -- manopera compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            valman := valman + v_tmp.cant/v_Rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
          end loop;
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,5) then
              valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
              if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                regie  := regie + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect)/v_rec1.cant * v_tmp.coefcheltmat;
              end if;
            else
              valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
            end if;
          end loop;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            regie := regie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
          end loop;
          ValMat := ValMat/v_Rec1.Cant;

          if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
            regie := regie + v_rec1.coefindirecte;
          end if;

          vpret := vpret + valmat + valman + regie;
        end loop;
      else
        valmat := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,5) then
              valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
            else
              valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
            end if;
          end loop;
          ValMat := ValMat/v_Rec1.Cant;

          vpret := vpret + valmat;
        end loop;
      end if;
    end loop;
    update tmp_manevra_compusi set pret = vPret/aCount2 where codobiect = aCodObiect;
    return vPret/aCount2;
  else
    vPret := 0;
    if TipPret = 1 then
      PretMax := 0;
      for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret,
                            nvl(pc.coefindirecte,0) coefindirecte
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                       where pc.codobiect = aCodObiect
                       ) loop
            if v_rec1.tippret = 1 then
              valmat := 0;
              valman := 0;
              regie  := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                --manopera retetei
                for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                              from prodman man
                                   inner join prodgest pg on man.codprodgest = pg.codprodgest
                                   left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                                   left join ngest ng on ng.codgest = pg.codgest
                              where man.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  valman := valman + v_tmp.valoare;
                  if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                    regie  := regie  + v_tmp.valoare * v_tmp.coefcheltman;
                  end if;
                end loop;
                -- manopera compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  valman := valman + v_tmp.cant/v_Rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
                end loop;
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                    if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                      regie  := regie + v_tmp.cant/v_Rec1.cant * GetPretFromStoc(v_tmp.codobiect) * v_tmp.coefcheltmat;
                    end if;
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                --regia compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  regie := regie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
                  regie := regie + v_rec1.coefindirecte;
                end if;

                vpret := vpret + valmat + valman + regie;
              end loop;
            else
              valmat := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                vpret := vpret + valmat;
              end loop;
            end if;
            if vPret &gt; PretMax then PretMax := vPret; end if;
          end loop;
        update tmp_manevra_compusi set pret = PretMax where codobiect = aCodObiect;
        return PretMax;
    else
      if TipPret = 3 then
        PretMin := 0;
        for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret,
                              nvl(pc.coefindirecte,0) coefindirecte
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                       where pc.codobiect = aCodObiect
                       ) loop
          if v_rec1.tippret = 1 then
              valmat := 0;
              valman := 0;
              regie  := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                --manopera retetei
                for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                              from prodman man
                                   inner join prodgest pg on man.codprodgest = pg.codprodgest
                                   left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                                   left join ngest ng on ng.codgest = pg.codgest
                              where man.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  valman := valman + v_tmp.valoare;
                  if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                    regie  := regie  + v_tmp.valoare * v_tmp.coefcheltman;
                  end if;
                end loop;
                -- manopera compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  valman := valman + v_tmp.cant/v_Rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
                end loop;
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                    if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                      regie  := regie + v_tmp.cant/v_Rec1.cant * GetPretFromStoc(v_tmp.codobiect) * v_tmp.coefcheltmat;
                    end if;
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                --regia compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  regie := regie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
                  regie := regie + v_rec1.coefindirecte;
                end if;

                vpret := vpret + valmat + valman + regie;
              end loop;
            else
              valmat := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                vpret := vpret + valmat;
              end loop;
            end if;
            if vPret &lt; PretMin then PretMin := vPret; end if;
          end loop;
        update tmp_manevra_compusi set pret = PretMin where codobiect = aCodObiect;
        return PretMin;
      else
        for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret,
                              nvl(pc.coefindirecte,0) coefindirecte
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                       where pc.codobiect = aCodObiect
                       ) loop
          if v_rec1.tippret = 1 then
              valmat := 0;
              valman := 0;
              regie  := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                --manopera retetei
                for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                              from prodman man
                                   inner join prodgest pg on man.codprodgest = pg.codprodgest
                                   left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                                   left join ngest ng on ng.codgest = pg.codgest
                              where man.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  valman := valman + v_tmp.valoare;
                  if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                    regie  := regie  + v_tmp.valoare * v_tmp.coefcheltman;
                  end if;
                end loop;
                -- manopera compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  valman := valman + v_tmp.cant/v_rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
                end loop;
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                    if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                      regie  := regie + v_tmp.cant/v_Rec1.cant * GetPretFromStoc(v_tmp.codobiect) * v_tmp.coefcheltmat;
                    end if;
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                --regia compusilor
                for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
                  regie := regie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
                  regie := regie + v_rec1.coefindirecte;
                end if;

                vpret := vpret + valmat + valman + regie;
              end loop;
            else
              valmat := 0;
              for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
                -- materiale
                for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret, nvl(mat.tip, 3) tip
                              from prodmat mat
                                   inner join prodgest pg on mat.codprodgest = pg.codprodgest
                                   left join ngest ng on ng.codgest = pg.codgest
                              where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
                  if v_tmp.tip in (3,5) then
                    valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
                  else
                    valmat := valmat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, TipPret);
                  end if;
                end loop;
                ValMat := ValMat/v_Rec1.Cant;

                vpret := vpret + valmat;
              end loop;
            end if;
        end loop;
        update tmp_manevra_compusi set pret = vPret/aCount where codobiect = aCodObiect;
        return vPret/aCount;
      end if;
    end if;
  end if;
end;

procedure UpdateDateRete is
aBanca number(20);
aConst number(20);
begin
  /*for v_rec in (select cl.*, man.bps
                from prodman_clona cl
                     inner join prodman man on cl.codman = man.codman) loop
    update prodman set valoare = v_rec.valoare_n*v_rec.bps where codman = v_rec.codman;
  end loop;*/
  aBanca := pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  if pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 0 then
    aBanca := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  end if;
  aConst := pkg_categconst.GetValConstanta(&apos;AntecalculCuZero&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  for v_rec in (select c.*, nvl(pc.codmoneda,0) codmoneda, coalesce(m.adddim,0) adddim, coalesce(m.adddim_transp,0) adddim_transp
                from prodmat_clona c
                     inner join prodcomp pc on pc.codprodcomp = c.codprodcomp
                     inner join prodmat m on m.codmat = c.codmat) loop
    update prodmat set pretorig = v_rec.pret_n, pret = v_rec.pret_n, valmat = v_rec.valmat, valman = v_Rec.valman, valregie = v_Rec.valregie where codmat = v_rec.codmat;
    if v_rec.adddim &lt;&gt; 0 or v_rec.adddim_transp &lt;&gt; 0 then
      update prodmat set pret = PretOrig + PretOrig * v_rec.AddDim /100 + PretOrig * v_rec.AddDim_transp /100 where codmat = v_rec.codmat;
    end if;
    update prodmat set valoare = pret * cant where codmat = v_rec.codmat;
    if v_rec.codmoneda &gt; 0 then
      update prodmat set
        pretv = pret / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
          v_rec.codmoneda,
          aBanca,
          sysdate)
      where codmat = v_rec.codmat;
    else
      update prodmat set
        pretv = pret
      where codmat = v_rec.codmat;
    end if;
  end loop;
  for v_rec in (select cl.*, pc.tipreteta, pc.cant, nvl(pc.coefindirecte,0) coefindirecte, nvl(pc.ag,0) ag, nvl(pc.profit,0) profit
                from prodcomp_clona cl
                     inner join prodcomp pc on pc.codprodcomp = cl.codprodcomp
               ) loop
    if (v_rec.pret_n is null) then
      insert into x(test) values(&apos;valoare nula la pret pentru reteta:&apos;||v_rec.codprodcomp||&apos; - constata(AntecalculCuZero) cu valoare:&apos;||aConst);
    else
      if (v_rec.pret_n = 0) then
        insert into x(test) values(&apos;valoare zero la pret pentru reteta:&apos;||v_rec.codprodcomp||&apos; - constata(AntecalculCuZero) cu valoare:&apos;||aConst);
      else
        update prodcomp
        set
          pret = v_rec.pret_n,
          pretvaluta = v_rec.pret_n / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
            nvl(codmoneda,0),
            aBanca,
            sysdate),
          valmat = v_rec.valmat,
          valman = v_rec.valman,
          valregie = v_Rec.valregie,
          valregieman = v_rec.valregieman
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          ValAG = v_rec.AG / 100 * (valman + valregieman)
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          TotPretFix = Pret + v_rec.CoefIndirecte + ValAG,
          TotPretCoef = Pret * (1.0 + v_rec.CoefIndirecte)
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          TotPretFixV = TotPretFix / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
            nvl(codmoneda,0),
            aBanca,
            sysdate),
          TotPretCoefV = TotPretCoef / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
            nvl(codmoneda,0),
            aBanca,
            sysdate)
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          ValProfit = v_rec.profit / 100 * TotPretFix
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          ValProfitV = ValProfit / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
            nvl(codmoneda,0),
            aBanca,
            sysdate)
        where codprodcomp = v_rec.codprodcomp;
        update prodcomp
        set
          PretFinal = ValProfit + TotPretFix,
          PretFinalV = (ValProfit + TotPretFix) / PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
            nvl(codmoneda,0),
            aBanca,
            sysdate)
        where codprodcomp = v_rec.codprodcomp;
      end if;  
    end if;  
  end loop;
  for v_rec in (select * from prodrez_clona) loop
    update prodrez set pret = v_rec.pret_n where codrez = v_rec.codrez;
  end loop;

  IF DoCommit then
    commit;
  end if;
end;

procedure ArmeazaTmps(aCodProdComp in number, aDinManevra in boolean default false) is
AnLunaInceput number(20);
AnLunaCurent number(20);
begin
  AnLunaInceput := 0;
  AnLunaCurent  := pkg_globals.GetANLUCRU*12+pkg_globals.getlunalucru;
  delete prodcomp_clona;
  delete prodman_clona;
  delete prodmat_clona;
  delete prodrez_clona;
  delete tmp_manevra_compusi;

  if aCodProdComp &gt; 0 then
    insert into prodcomp_clona(codprodcomp, codobiect, pret_v, pret_n)
    select codprodcomp, codobiect, nvl(pret,0), 0
    from prodcomp
    where CodProdComp = aCodProdComp;

    insert into prodman_clona(codman, valoare_v, valoare_n)
    select man.codman, nvl(man.valoare,0), 0
    from prodman man
       inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
    where pc.CodProdComp = aCodProdComp;

    insert into prodmat_clona(codmat, codobiect, pret_v, pret_n, codprodcomp)
    select distinct mat.codmat, mat.codobiect, nvl(mat.pret,0), 0, mat.codprodcomp
    from prodmat mat
      inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
    where pc.CodProdComp = aCodProdComp;

    insert into prodrez_clona(codrez, codprodcomp, pret_v, pret_n)
    select rez.codrez, rez.codprodcomp, nvl(rez.pret,0), 0
    from prodrez rez
         inner join prodcomp pc on pc.codprodcomp = rez.codprodcomp
    where pc.codprodcomp = aCodProdComp and pc.tipreteta = 2;
  else
    if aDinManevra then
      insert into prodcomp_clona(codprodcomp, codobiect, pret_v, pret_n)
      select pc.codprodcomp, pc.codobiect, nvl(pc.pret,0), 0
      from prodcomp pc
      where nvl(pc.cant,0) &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0
      and exists (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODPRODCOMP&apos; and tmp.valoare = pc.codprodcomp);

      insert into tmp_manevra_compusi(codobiect, pret)
      select distinct codobiect, 0
      from prodcomp_clona;
      commit;
      insert into prodman_clona(codman, valoare_v, valoare_n)
      select man.codman, nvl(man.valoare,0), 0
      from prodman man
         inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
      where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0
      and exists (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODPRODCOMP&apos; and tmp.valoare = pc.codprodcomp);

      insert into prodmat_clona(codmat, codobiect, pret_v, pret_n, codprodcomp)
      select distinct mat.codmat, mat.codobiect, nvl(mat.pret,0), 0, mat.codprodcomp
      from prodmat mat
        inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
      where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and
            exists (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODPRODCOMP&apos; and tmp.valoare = pc.codprodcomp);

      insert into prodrez_clona(codrez, codprodcomp, pret_v, pret_n)
      select rez.codrez, rez.codprodcomp, nvl(rez.pret,0), 0
      from prodrez rez
           inner join prodcomp pc on pc.codprodcomp = rez.codprodcomp
      where pc.tipreteta = 2
      and exists (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODPRODCOMP&apos; and tmp.valoare = pc.codprodcomp);
    else
      insert into prodcomp_clona(codprodcomp, codobiect, pret_v, pret_n)
      select pc.codprodcomp, pc.codobiect, nvl(pc.pret,0), 0
      from prodcomp pc
      where nvl(pc.cant,0) &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0
      and Extract(Year from pc.Data) * 12 + Extract(month from pc.Data) &lt;= AnLunaCurent;

      insert into tmp_manevra_compusi(codobiect, pret)
      select distinct codobiect, 0
      from prodcomp_clona;
      commit;
      insert into prodman_clona(codman, valoare_v, valoare_n)
      select man.codman, nvl(man.valoare,0), 0
      from prodman man
         inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
      where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0
      and Extract(Year from pc.Data) * 12 + Extract(month from pc.Data) &lt;= AnLunaCurent;

      insert into prodmat_clona(codmat, codobiect, pret_v, pret_n,codprodcomp)
      select mat.codmat, mat.codobiect, nvl(mat.pret,0), 0,mat.codprodcomp
      from prodmat mat
        inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
      where pc.cant &lt;&gt; 0 and nvl(pc.inactiv,0) = 0 and nvl(pc.invizibila,0) = 0 and
            Extract(Year from pc.Data) * 12 + Extract(month from pc.Data) &lt;= AnLunaCurent;

      insert into prodrez_clona(codrez, codprodcomp, pret_v, pret_n)
      select rez.codrez, rez.codprodcomp, nvl(rez.pret,0), 0
      from prodrez rez
           inner join prodcomp pc on pc.codprodcomp = rez.codprodcomp
      where pc.tipreteta = 2
      and Extract(Year from pc.Data) * 12 + Extract(month from pc.Data) &lt;= AnLunaCurent;
    end if;
  end if;
  if DoCommit then
    commit;
  end if;
end;

function GetRegie(aCodObiect in number, TipPret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
aRegie number(20,7);
valregie number(20,7);
RegieMax number(20,7);
RegieMin number(20,7);
begin
  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
  where pc.codobiect = aCodObiect;

  if aCount = 0 then
    return 0;
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    aregie := GetRegieFromCompusi(aCodObiect);
    if aRegie &gt; 0 then
      return aregie;
    end if;
  end if;


  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
  where pc.codobiect = aCodObiect
  and pc.generic = 1;

  if aCount2 &gt; 0 then
    aregie := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.coefindirecte,0) coefindirecte
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                   where pc.codobiect = aCodObiect
                         and pc.generic = 1) loop
      valregie := 0;
      --regia manoperei
      if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
        for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                      from prodman man
                           inner join prodgest pg on man.codprodgest = pg.codprodgest
                           left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                           left join ngest ng on ng.codgest = pg.codgest
                      where man.codprodcomp = v_rec1.codprodcomp) loop
          valregie  := valregie  + v_tmp.valoare * v_tmp.coefcheltman;
        end loop;
      end if;
      -- regia materialelor
      if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
        for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, nvl(tmpp.pret,0) pret, nvl(mat.tip, 3) tip
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) in (3,5)) loop
          valregie  := valregie + v_tmp.cant * v_tmp.pret/v_rec1.cant * v_tmp.coefcheltmat;
        end loop;
      end if;
      --regia compusilor
      for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                    from prodmat mat
                         inner join prodgest pg on mat.codprodgest = pg.codprodgest
                         left join ngest ng on ng.codgest = pg.codgest
                    where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) &lt; 3) loop
        valregie := valregie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
      end loop;
      if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
        valregie := valregie + v_rec1.coefindirecte;
      end if;
      aregie := aregie + valregie;
    end loop;

    update tmp_manevra_compusi set regie = aregie/aCount2 where codobiect = aCodObiect;
    return aregie/aCount2;
  else
    aregie := 0;
    if TipPret = 1 then
      RegieMax := 0;
      for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.coefindirecte,0) coefindirecte
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
        valregie := 0;
        if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
          --regia manoperei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_rec1.codprodcomp) loop
            valregie  := valregie  + v_tmp.valoare * v_tmp.coefcheltman;
          end loop;
        end if;
        if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
          -- regia materialelor
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, nvl(tmpp.pret,0) pret, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) in (3,5)) loop
            valregie  := valregie + v_tmp.cant * v_tmp.pret/v_rec1.cant * v_tmp.coefcheltmat;
          end loop;
        end if;
        --regia compusilor
        for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) &lt; 3) loop
          valregie := valregie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
        end loop;
        if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
          valregie := valregie + v_rec1.coefindirecte;
        end if;
        aregie := valregie;
        if aregie &gt; RegieMax then RegieMax := aregie; end if;
      end loop;
      update tmp_manevra_compusi set Regie = RegieMax where codobiect = aCodObiect;
      return RegieMax;
    else
      if TipPret = 3 then
        RegieMin := 0;
        for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.coefindirecte,0) coefindirecte
                         from prodcomp pc
                              inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                         where pc.codobiect = aCodObiect
                         ) loop
          valregie := 0;
          if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
            --regia manoperei
            for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                               inner join prodgest pg on man.codprodgest = pg.codprodgest
                               left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                               left join ngest ng on ng.codgest = pg.codgest
                          where man.codprodcomp = v_rec1.codprodcomp) loop
              valregie  := valregie  + v_tmp.valoare * v_tmp.coefcheltman;
            end loop;
          end if;
          if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
            -- regia materialelor
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, nvl(tmpp.pret,0) pret, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) in (3,5)) loop
              valregie  := valregie + v_tmp.cant * v_tmp.pret/v_Rec1.cant * v_tmp.coefcheltmat;
            end loop;
          end if;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) &lt; 3) loop
            valregie := valregie + v_tmp.cant/v_rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
          end loop;
          aregie := valregie;
          if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
            valregie := valregie + v_rec1.coefindirecte;
          end if;
          if aregie &lt; RegieMin then RegieMin := aregie; end if;
        end loop;
        update tmp_manevra_compusi set Regie = RegieMin where codobiect = aCodObiect;
        return RegieMin;
      else
        aregie := 0;
        for v_rec1 in (select pc.codprodcomp, pc.cant, nvl(pc.coefindirecte,0) coefindirecte
                       from prodcomp_clona pcc
                            inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                       where pc.codobiect = aCodObiect) loop
          valregie := 0;
          if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
            --regia manoperei
            for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                               inner join prodgest pg on man.codprodgest = pg.codprodgest
                               left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                               left join ngest ng on ng.codgest = pg.codgest
                          where man.codprodcomp = v_rec1.codprodcomp) loop
              valregie  := valregie  + v_tmp.valoare * v_tmp.coefcheltman;
            end loop;
          end if;
          if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
            -- regia materialelor
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, nvl(tmpp.pret,0) pret, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) in (3,5)) loop
              valregie  := valregie + v_tmp.cant * v_tmp.pret/v_Rec1.cant * v_tmp.coefcheltmat;
            end loop;
          end if;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and nvl(mat.tip, 3) &lt; 3) loop
            valregie := valregie + v_tmp.cant/v_Rec1.cant * pkg_prodcomp.GetRegie(v_tmp.codobiect, TipPret);
          end loop;
          if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
            valregie := valregie + v_rec1.coefindirecte;
          end if;
          aregie := aregie + valregie;
        end loop;
        update tmp_manevra_compusi set regie = aregie/aCount where codobiect = aCodObiect;
        return aregie/aCount;
      end if;
    end if;
  end if;
end;

function GetValoareMan(aCodObiect in number, TipPret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
man number(20,7);
valman number(20,7);
ManMax number(20,7);
ManMin number(20,7);
begin
  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
  where pc.codobiect = aCodObiect;

  if aCount = 0 then
    return pkg_prodcomp.GetValoareManDinDerivate(aCodObiect, TipPret);
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    man := GetValManFromCompusi(aCodObiect);
    if Man &gt; 0 then
      return man;
    end if;
  end if;

  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
  where pc.codobiect = aCodObiect
  and pc.generic = 1;

  if aCount2 &gt; 0 then
    man := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                   where pc.codobiect = aCodObiect
                         and pc.generic = 1) loop
      for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
        valman := 0;
        for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                      from prodman man
                        left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                      where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
          valman := valman + v_tmp.valoare;
        end loop;
        for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
          valman := valman + v_tmp.cant/v_Rec1.Cant * GetValoareMan(v_tmp.codobiect, TipPret);
        end loop;
        man := man + valman;
      end loop;
    end loop;
    update tmp_manevra_compusi set valman = man/aCount2 where codobiect = aCodObiect;
    return man/aCount2;
  else
    man := 0;
    if TipPret = 1 then
      ManMax := 0;
      for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
          valman := 0;
          for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                          left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                        where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
            valman := valman + v_tmp.valoare;
          end loop;
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            valman := valman + v_tmp.cant/v_Rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
          end loop;
          man := man + valman;
          if man &gt; ManMax then ManMax := man; end if;
        end loop;
      end loop;
      update tmp_manevra_compusi set ValMan = ManMax where codobiect = aCodObiect;
      return ManMax;
    else
      if TipPret = 3 then
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
          ManMin := 0;
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
            valman := 0;
            for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                            left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                          where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
              valman := valman + v_tmp.valoare;
            end loop;
            for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
              valman := valman + v_tmp.cant/v_rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
            end loop;
            man := man + valman;
            if man &lt; ManMin then ManMin := man; end if;
          end loop;
        end loop;
        update tmp_manevra_compusi set ValMan = ManMin where codobiect = aCodObiect;
        return ManMin;
      else
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
          
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
            valman := 0;
            for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                            left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                          where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
              valman := valman + v_tmp.valoare;
            end loop;
            for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
              valman := valman + v_tmp.cant/v_rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
            end loop;
            man := man + valman;
          end loop;
        end loop;
        update tmp_manevra_compusi set ValMan = man/aCount where codobiect = aCodObiect;
        return man/aCount;
      end if;
    end if;
  end if;
end;

function GetValoareManDinDerivate(aCodObiect in number, TipPret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
man number(20,7);
valman number(20,7);
ManMax number(20,7);
ManMin number(20,7);
aCodArticol number(20);
begin
  select codarticol into aCodArticol from nartobj where codobiect = aCodObiect;

  if pkg_nom_articol.getcodobiectgeneric(aCodArticol) &lt;&gt; aCodObiect then
    return 0;
  end if;

  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
  where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect;

  if aCount = 0 then
    return 0;
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    man := GetValManFromCompusi(aCodObiect);
    if Man &gt; 0 then
      return man;
    end if;
  end if;

  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
  where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect and pc.generic = 1;

  if aCount2 &gt; 0 then
    man := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                        inner join nartobj obj on obj.codobiect = pc.codobiect
                   where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect and pc.generic = 1
                   ) loop
      for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
        valman := 0;
        for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                      from prodman man
                        left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                      where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
          valman := valman + v_tmp.valoare;
        end loop;
        for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
          valman := valman + v_tmp.cant/v_Rec1.Cant * GetValoareMan(v_tmp.codobiect, TipPret);
        end loop;
        man := man + valman;
      end loop;
    end loop;
    update tmp_manevra_compusi set valman = man/aCount2 where codobiect = aCodObiect;
    return man/aCount2;
  else
    man := 0;
    if TipPret = 1 then
      ManMax := 0;
      for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                       where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
          valman := 0;
          for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                          left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                        where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
            valman := valman + v_tmp.valoare;
          end loop;
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            valman := valman + v_tmp.cant/v_Rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
          end loop;
          man := man + valman;
          if man &gt; ManMax then ManMax := man; end if;
        end loop;
      end loop;
      update tmp_manevra_compusi set ValMan = ManMax where codobiect = aCodObiect;
      return ManMax;
    else
      if TipPret = 3 then
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                       where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
          ManMin := 0;
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
            valman := 0;
            for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                            left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                          where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
              valman := valman + v_tmp.valoare;
            end loop;
            for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
              valman := valman + v_tmp.cant/v_rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
            end loop;
            man := man + valman;
            if man &lt; ManMin then ManMin := man; end if;
          end loop;
        end loop;
        update tmp_manevra_compusi set ValMan = ManMin where codobiect = aCodObiect;
        return ManMin;
      else
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                       where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
            valman := 0;
            for v_tmp in (select round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                          from prodman man
                            left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                          where man.codprodcomp = v_rec1.codprodcomp and man.codprodgest = v_Rec.Codprodgest) loop
              valman := valman + v_tmp.valoare;
            end loop;
            for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
              valman := valman + v_tmp.cant/v_rec1.cant * GetValoareMan(v_tmp.codobiect, TipPret);
            end loop;
            man := man + valman;
          end loop;
        end loop;
        update tmp_manevra_compusi set ValMan = man/aCount where codobiect = aCodObiect;
        return man/aCount;
      end if;
    end if;
  end if;
end;

function GetValoareMat(aCodObiect in number, tippret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
valmat number(20,7);
mat number(20,7);
MatMax number(20,7);
MatMin number(20,7);
begin
  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
  where pc.codobiect = aCodObiect;

  if aCount = 0 then
    return pkg_prodcomp.GetValoareMatDinDerivate(aCodObiect, TipPret);
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    mat := GetValMatFromCompusi(aCodObiect);
    if mat &gt; 0 then
      return mat;
    end if;
  end if;

  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
  where pc.codobiect = aCodObiect
  and pc.generic = 1;

  if aCount2 &gt; 0 then
    mat := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                   where pc.codobiect = aCodObiect
                         and pc.generic = 1) loop
      for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
        valmat := 0;
        for v_tmp in (select mat.codobiect, mat.cant, mat.pret, nvl(pg.coefmat, ng.coefcheltmat) coefcheltmat,
                             case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
          if v_tmp.Semifabricat = 1 then
            valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
          else
            valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
          end if;
        end loop;
        valmat := valmat/v_Rec1.cant;
        mat := mat + valmat;
      end loop;
    end loop;
    
    update tmp_manevra_compusi set valmat = mat/aCount2 where codobiect = aCodObiect;
    return mat/aCount2;
  else
    mat := 0;
    if TipPret = 1 then
      MatMax := 0;
      for v_rec1 in (select pc.codprodcomp, pcc.cant
                       from prodcomp_clona pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
          valmat := 0;
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                             case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
            if v_tmp.Semifabricat = 1 then
              valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
            else
              valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
            end if;
          end loop;
          valmat := valmat/v_Rec1.cant;
          mat := mat + valmat;
          if mat &gt; MatMax then MatMax := mat; end if;
        end loop;
      end loop;
      update tmp_manevra_compusi set pret = MatMax where codobiect = aCodObiect;
      return MatMax;
    else
      if TipPret = 3 then
        MatMin := 0;
        mat := 0;
        for v_rec1 in (select pc.codprodcomp, pcc.cant
                       from prodcomp_clona pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
            valmat := 0;
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                                 case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
              if v_tmp.Semifabricat = 1 then
                valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
              else
                valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
              end if;
            end loop;
            valmat := valmat/v_Rec1.cant;
            mat := mat + valmat;
            if mat &lt; MatMin then MatMin := mat; end if;
          end loop;
        end loop;
        update tmp_manevra_compusi set pret = MatMin where codobiect = aCodObiect;
        return MatMin;
      else
        mat :=0;
        for v_rec1 in (select pc.codprodcomp, pcc.cant
                       from prodcomp_clona pc
                            inner join prodcomp pcc on pc.codprodcomp = pcc.codprodcomp
                       where pc.codobiect = aCodObiect
                       ) loop
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
            valmat := 0;
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                                 case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
              if v_tmp.Semifabricat = 1 then
                valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
              else
                valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
              end if;
            end loop;
            valmat := valmat/v_Rec1.cant;
            mat := mat + valmat;
          end loop;
        end loop;
        update tmp_manevra_compusi set pret = mat/aCount where codobiect = aCodObiect;
        return mat/aCount;
      end if;
    end if;
  end if;
end;

function GetValoareMatDinDerivate(aCodObiect in number, tippret in number) return number is
aCount number(10);
aCount1 number(10);
aCount2 number(10);
valmat number(20,7);
mat number(20,7);
MatMax number(20,7);
MatMin number(20,7);
aCodArticol number(20);
begin
  select codarticol into aCodArticol from nartobj where codobiect = aCodObiect;

  if pkg_nom_articol.getcodobiectgeneric(aCodArticol) &lt;&gt; aCodObiect then
    return 0;
  end if;

  select count(pc.codprodcomp) into aCount
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
  where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect;

  if aCount = 0 then
    return 0;
  end if;

  select count(valoare) into aCount1 from tmp_manevra_liste where valoare = aCodObiect;
  if aCount1 = 0 then
    insert into tmp_manevra_liste(valoare) values (aCodObiect);
  else
    mat := GetValMatFromCompusi(aCodObiect);
    if mat &gt; 0 then
      return mat;
    end if;
  end if;

  select count(pc.codprodcomp) into aCount2
  from prodcomp_clona pcc
       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
  where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect and pc.generic = 1;

  if aCount2 &gt; 0 then
    mat := 0;
    for v_rec1 in (select pc.codprodcomp, pc.cant
                   from prodcomp_clona pcc
                        inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
                        inner join nartobj obj on obj.codobiect = pc.codobiect
                   where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                         and pc.generic = 1) loop
      for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp) loop
        valmat := 0;
        for v_tmp in (select mat.codobiect, mat.cant, mat.pret, nvl(pg.coefmat, ng.coefcheltmat) coefcheltmat,
                             case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                      from prodmat mat
                           inner join prodgest pg on mat.codprodgest = pg.codprodgest
                           left join ngest ng on ng.codgest = pg.codgest
                      where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
          if v_tmp.Semifabricat = 1 then
            valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
          else
            valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
          end if;
        end loop;
        valmat := valmat/v_Rec1.cant;
        mat := mat + valmat;
      end loop;
    end loop;
    update tmp_manevra_compusi set valmat = mat/aCount2 where codobiect = aCodObiect;
    return mat/aCount2;
  else
    mat := 0;
    if TipPret = 1 then
      MatMax := 0;
      for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                     where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
          valmat := 0;
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                             case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
            if v_tmp.Semifabricat = 1 then
              valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
            else
              valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
            end if;
          end loop;
          valmat := valmat/v_Rec1.cant;
          mat := mat + valmat;
          if mat &gt; MatMax then MatMax := mat; end if;
        end loop;
      end loop;
      update tmp_manevra_compusi set pret = MatMax where codobiect = aCodObiect;
      return MatMax;
    else
      if TipPret = 3 then
        MatMin := 0;
        mat := 0;
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                       where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
            valmat := 0;
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                                 case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
              if v_tmp.Semifabricat = 1 then
                valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
              else
                valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
              end if;
            end loop;
            valmat := valmat/v_Rec1.cant;
            mat := mat + valmat;
            if mat &lt; MatMin then MatMin := mat; end if;
          end loop;
        end loop;
        update tmp_manevra_compusi set pret = MatMin where codobiect = aCodObiect;
        return MatMin;
      else
        mat :=0;
        for v_rec1 in (select pc.codprodcomp, pc.cant
                       from prodcomp pc
                            inner join nartobj obj on obj.codobiect = pc.codobiect
                       where obj.codarticol = aCodArticol and obj.codobiect &lt;&gt; aCodObiect
                       ) loop
          for v_rec in (select codprodgest from prodgest where codprodcomp = v_Rec1.codprodcomp ) loop
            valmat := 0;
            for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, mat.pret,
                                 case when nvl(mat.tip,3) in (3,5) then 0 else 1 end Semifabricat
                          from prodmat mat
                               inner join prodgest pg on mat.codprodgest = pg.codprodgest
                               left join ngest ng on ng.codgest = pg.codgest
                          where mat.codprodcomp = v_rec1.codprodcomp and pg.codprodgest = v_rec.codprodgest and (nvl(mat.tip,3) &lt; 4 or mat.tip = 5)) loop
              if v_tmp.Semifabricat = 1 then
                valmat := valmat + v_tmp.cant * GetValoareMat(v_tmp.codobiect, TipPret);
              else
                valmat := valmat + v_tmp.cant * GetPretFromStoc(v_tmp.codobiect);
              end if;
            end loop;
            valmat := valmat/v_Rec1.cant;
            mat := mat + valmat;
          end loop;
        end loop;
        update tmp_manevra_compusi set pret = mat/aCount where codobiect = aCodObiect;
        return mat/aCount;
      end if;
    end if;
  end if;
end;

function ActualizeazaPret(aCodProdComp in number) return number is
vPret number(20,7);
aCant number(20,7);
vValMat number(20,7);
vValMan number(20,7);
vValRegie number(20,7);
vValRegieMan number(20,7);
mat number(20,7);
man number(20,7);
aCountI number(10);
PreturiZero boolean;
DinManevra boolean;
begin
  pkg_stoc_generare_facturi.make_config_luna;
  select count(*) into aCountI from tmp_manevra_liste where filtru = &apos;CODPRODCOMP&apos;;
  DinManevra := aCountI &gt; 0;
  ArmeazaTmps(aCodProdComp, DinManevra);

  KTipPret          := Pkg_Categconst.GetValConstanta(&apos;TipEvaluarePret&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru);
  KTipCoefIndirecte := Pkg_Categconst.GetValConstanta(&apos;TipCoefIndirecte&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru);
  KRegieAntecalcul  := Pkg_Categconst.GetValConstanta(&apos;RegieAntecalcul&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru);

  PreturiZero := False;
  if aCodProdComp = 0 then
    for v_xxx in (select pc.codprodcomp, pc.codobiect, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret,
                         obj.denumire, pc.cant, nvl(pc.CoefIndirecte,0) CoefIndirecte, pc.tipreteta,
                         tmpp.pret pretprodus
                  from prodcomp_clona pcc
                       inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
                       inner join nartobj obj on pc.codobiect = obj.codobiect
                       inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                       left join tmp_manevra_preturi tmpp on tmpp.codobiect = pc.codobiect
                  ) loop
      if v_xxx.tipreteta = 2 then
        -- update la valoare manopera
        for v_tmp in (select pm.tu, t1.tarif, pm.codman, decode(nvl(pm.bps,1),0,1,nvl(pm.bps,1)) BPS
                      FROM PRODMAN PM
                        left join TARIFEMAN1 T1 ON t1.codtarif = pm.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                      where PM.codprodcomp = v_xxx.CodProdComp) loop
          update prodman_clona
          set
            valoare_n = round((v_tmp.tarif * v_tmp.tu)/60, 7)/v_tmp.BPS
          where codman = v_tmp.codman;
        end loop;
        -- bag produsul in temporarul de analiza
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
        -- update la materiale
        for v_tmp in (select mat.codmat, mat.codobiect, nvl(mat.pret,0) pret, nvl(mat.tip,3) tip, obj.denumire
                      from prodmat mat
                           inner join nartobj obj on mat.codobiect = obj.codobiect
                      where mat.codprodcomp = v_xxx.codprodcomp) loop
          insert into tmp_manevra_liste(valoare)
          select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
          if v_tmp.tip in (3,4,5) then
            vValMat   := 0;
            vValMan   := 0;
            vValRegie := 0;
            vPret     := GetPretFromStoc(v_tmp.codobiect);
          else
            vValMan   := GetValoareMan(v_tmp.codobiect, KTipPret);
            vValMat   := GetValoareMat(v_tmp.codobiect, KTipPret);
            vValregie := GetRegie(v_tmp.codobiect, KTipPret);
            vPret     := GetPretMaterialCompus(v_tmp.codobiect, v_tmp.pret, KTipPret);
          end if;
          update prodmat_clona set pret_n = vPret, valmat = vValMat, valman = vValMan, valregie = vValRegie where codmat = v_tmp.codmat;
        end loop;

        select cant into aCant from prodcomp where codprodcomp = v_xxx.CodProdComp;

        vValMat   := v_xxx.cant * nvl(v_xxx.pretprodus,0);
        vValMan   := 0;
        vValRegie := 0;
        vValRegieMan := 0;
        vPret     := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_xxx.codprodcomp) loop
          --manopera retetei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)),7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop  
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            vValMan   := vValMan + v_tmp.valoare;
            if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
              vValRegie := vValRegie  + v_tmp.valoare * v_tmp.coefcheltman;
              vValRegieMan := vValRegieMan  + v_tmp.valoare * v_tmp.coefcheltman;
            end if;
          end loop;
          -- manopera compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValMan := vValMan + v_tmp.cant/aCant * GetValoareMan(v_tmp.codobiect, KTipPret);
          end loop;
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, tmpp.pret, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,4,5) then
              vValMat   := vValMat + v_tmp.cant * nvl(v_tmp.pret,0);
              if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                vValRegie := vValRegie + v_tmp.cant * nvl(v_tmp.pret,0)/acant * v_tmp.coefcheltmat;
              end if;
            else
              vValMat := vValMat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, KTipPret);
            end if;
          end loop;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValRegie := vValRegie + v_tmp.cant/aCant * pkg_prodcomp.GetRegie(v_tmp.codobiect, KTipPret);
          end loop;
          vValMat := vValMat/aCant;
        end loop;

        if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
          vValRegie := vValRegie + v_xxx.CoefIndirecte;
        end if;

        if v_xxx.tippret = 1 then
          vPret := vPret + vValMat + vValMan + vValRegie;
        else
          vPret := vPret + vValMat;
        end if;

        -- caz particular pentru iulian machidon cu pondere fata de cantitate
        for v_rez in (select rez.codrez, rez.cant, totrez.cant total
                      from prodrez rez
                           inner join (select sum(cant) cant, codprodcomp
                                       from prodrez
                                       group by codprodcomp) totrez on totrez.codprodcomp = rez.codprodcomp
                      where rez.codprodcomp = v_xxx.codprodcomp) loop
          update prodrez_clona set pret_n = vPret /v_rez.total where codrez = v_rez.CodRez;
        end loop;
        update prodcomp_clona set pret_n = v_xxx.pretprodus, valmat = vValMat, valman = vValMan, valregie = vValRegie where codprodcomp = v_xxx.Codprodcomp;

      else
        -- update la valoare manopera
        for v_tmp in (select pm.tu, t1.tarif, pm.codman, decode(nvl(pm.bps,1),0,1,nvl(pm.bps,1)) BPS
                      FROM PRODMAN PM
                        left join TARIFEMAN1 T1 ON t1.codtarif = pm.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                      where PM.codprodcomp = v_xxx.CodProdComp) loop
          update prodman_clona
          set
            valoare_n = round((v_tmp.tarif * v_tmp.tu)/60, 7)/v_tmp.BPS
          where codman = v_tmp.codman;
        end loop;
        -- bag produsul in temporarul de analiza
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
        -- update la materiale
        for v_tmp in (select mat.codmat, mat.codobiect, nvl(mat.pret,0) pret, nvl(mat.tip,3) tip, obj.denumire
                      from prodmat mat
                           inner join nartobj obj on mat.codobiect = obj.codobiect
                      where mat.codprodcomp = v_xxx.codprodcomp) loop
          insert into tmp_manevra_liste(valoare)
          select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
          if v_tmp.tip in (3,4,5) then
            vValMat   := 0;
            vValMan   := 0;
            vValRegie := 0;
            vPret     := GetPretFromStoc(v_tmp.codobiect);
          else
            vValMan   := GetValoareMan(v_tmp.codobiect, KTipPret);
            vValMat   := GetValoareMat(v_tmp.codobiect, KTipPret);
            vValregie := GetRegie(v_tmp.codobiect, KTipPret);
            vPret     := GetPretMaterialCompus(v_tmp.codobiect, v_tmp.pret, KTipPret);
          end if;
          update prodmat_clona set pret_n = vPret, valmat = vValMat, valman = vValMan, valregie = vValRegie where codmat = v_tmp.codmat;
        end loop;

        select cant into aCant from prodcomp where codprodcomp = v_xxx.CodProdComp;

        vValMat   := 0;
        vValMan   := 0;
        vValRegie := 0;
        vValRegieMan := 0;
        vPret     := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_xxx.codprodcomp) loop
          --manopera retetei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)),7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            vValMan   := vValMan + v_tmp.valoare;
            if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
              vValRegie := vValRegie  + v_tmp.valoare * v_tmp.coefcheltman;
              vValRegieMan := vValRegieMan  + v_tmp.valoare * v_tmp.coefcheltman;
            end if;
          end loop;
          -- manopera compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValMan := vValMan + v_tmp.cant/aCant * GetValoareMan(v_tmp.codobiect, KTipPret);
          end loop;
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, tmpp.pret, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,4,5) then
              vValMat   := vValMat + v_tmp.cant * coalesce(v_tmp.pret,0);
              if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                vValRegie := vValRegie + v_tmp.cant * v_tmp.pret/acant * v_tmp.coefcheltmat;
              end if;
            else
              vValMat := vValMat + v_tmp.cant * pkg_prodcomp.GetValoareMat(v_tmp.codobiect, KTipPret);
            end if;
          end loop;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip
                        from prodmat mat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValRegie := vValRegie + v_tmp.cant/aCant * pkg_prodcomp.GetRegie(v_tmp.codobiect, KTipPret);
          end loop;
          vValMat := vValMat/aCant;
        end loop;

        if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
          vValRegie := vValRegie + v_xxx.CoefIndirecte;
        end if;

        if v_xxx.tippret = 1 then
          vPret := vPret + vValMat + vValMan + vValRegie;
        else
          vPret := vPret + vValMat;
        end if;

        update prodcomp_clona set pret_n = vPret, valmat = vValMat, valman = vValMan, valregie = vValRegie, valregieman = vValRegieMan where codprodcomp = v_xxx.Codprodcomp;
      end if;
    end loop;
  else
    for v_xxx in (select pc.codprodcomp, pc.codobiect, nvl(pc.tippret, nvl(Tmp.tippret, 1)) tippret, pc.cant,
                         nvl(pc.CoefIndirecte,0) CoefIndirecte, pc.tipreteta,
                         tmpp.pret pretprodus
                  from prodcomp pc
                       inner join tmp_nartobj_luna tmp on pc.codobiect = tmp.codobiect
                       left join tmp_manevra_preturi tmpp on tmpp.codobiect = pc.codobiect
                  WHERE pc.CodProdComp = aCodProdComp) loop
      if v_xxx.tipreteta = 2 then
        -- update la valoare manopera
        for v_tmp in (select pm.tu, t1.tarif, pm.codman, decode(nvl(pm.bps,1),0,1,nvl(pm.bps,1)) BPS
                      FROM PRODMAN PM
                        left join TARIFEMAN1 T1 ON t1.codtarif = pm.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                      where PM.codprodcomp = v_xxx.CodProdComp) loop
          update prodman_clona
          set
            valoare_n = round((v_tmp.tarif * v_tmp.tu)/60, 7)/v_tmp.BPS
          where codman = v_tmp.codman;
        end loop;

        -- update la materiale

        vPret := 0;
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;

        for v_tmp in (select mat.codmat, mat.codobiect, nvl(mat.pret,0) pret, mat.tip
                      from prodmat mat
                      where mat.codprodcomp = v_xxx.codprodcomp) loop

          insert into tmp_manevra_liste(valoare)
          select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
          mat := 0;
          man := 0;
          vValRegie := 0;
          if v_tmp.tip in (3,4,5) then
            if v_tmp.tip = 4 then
              vPret := 0;
            else
              vPret := pkg_prodcomp.GetPretFromStoc(v_tmp.codobiect);
            end if;
          else
            --testul preturilor zero
            if not PreturiZero then
              select count(codprodcomp) into aCountI
              from prodcomp where codobiect = v_tmp.codobiect and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0 and nvl(pret,0) = 0;
              if aCountI &gt; 0 then
                PreturiZero := True;
              end if;
            end if;

            -- aduc ori pretul retetei implicite ori medie
            select count(codprodcomp) into aCountI from prodcomp where codobiect = v_tmp.codobiect
            and generic = 1 and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
            if aCountI &gt; 0 then
              select sum(pret)/aCountI, sum(valmat)/aCountI, sum(valman)/aCountI, sum(valregie)/aCountI into vPret, mat, man, vValRegie from prodcomp
              where codobiect = v_tmp.codobiect and generic = 1  and nvl(inactiv, 0) = 0
              and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
            else
              select count(codprodcomp) into aCountI from prodcomp
              where codobiect = v_tmp.codobiect
              and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
              if aCountI &gt; 0 then
                select sum(pret)/aCountI, sum(valmat)/aCountI, sum(valman)/aCountI, sum(valregie)/aCountI into vPret, mat, man, vValRegie from prodcomp
                where codobiect = v_tmp.codobiect  and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
              else
                vPret := pkg_prodcomp.GetPretFromStoc(v_tmp.codobiect);
                mat := 0;
                man := 0;
                vValRegie := 0;
              end if;
            end if;
          end if;

          update prodmat_clona set pret_n = vPret, valmat = mat, valman = man, valregie = vValRegie where codmat = v_tmp.codmat;
        end loop;

        -- update la pret produs compus
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;

        select cant into aCant from prodcomp where codprodcomp = v_xxx.CodProdComp;

        vValMat   := v_xxx.cant * nvl(v_xxx.pretprodus,0);
        vValMan   := 0;
        vValRegie := 0;
        vPret := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_xxx.codprodcomp) loop
          --manopera retetei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            vValMan   := vValMan + v_tmp.valoare;
            if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
              vValRegie := vValRegie  + v_tmp.valoare * v_tmp.coefcheltman;
            end if;
          end loop;
          -- manopera compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip, nvl(clona.valman,0) valman
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValMan := vValMan + v_tmp.cant/aCant * v_tmp.valman;
          end loop;
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, tmpp.pret, nvl(mat.tip, 3) tip, nvl(clona.valmat,0) valmat
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,4,5) then
              vValMat   := vValMat + v_tmp.cant * nvl(v_tmp.pret,0);
              if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                vValRegie := vValRegie + v_tmp.cant * nvl(v_tmp.pret,0)/acant * v_tmp.coefcheltmat;
              end if;
            else
              vValMat   := vValMat + v_tmp.cant * v_tmp.valmat;
            end if;
          end loop;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip, nvl(clona.valregie,0) valregie
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValRegie := vValRegie + v_tmp.cant/acant * v_tmp.valregie;
          end loop;
          --vValMat := vValMat/aCant;
        end loop;

        if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
          vValRegie := vValRegie + v_xxx.CoefIndirecte;
        end if;

        if v_xxx.tippret = 1 then
          vPret := vPret + vValMat + vValMan + vValRegie;
        else
          vPret := vPret + vValMat;
        end if;

        -- caz particular pentru iulian machidon cu pondere fata de cantitate
        for v_rez in (select rez.codrez, rez.cant, totrez.cant total
                      from prodrez rez
                           inner join (select sum(cant) cant, codprodcomp
                                       from prodrez
                                       group by codprodcomp) totrez on totrez.codprodcomp = rez.codprodcomp
                      where rez.codprodcomp = v_xxx.codprodcomp) loop
          update prodrez_clona set pret_n = vPret /v_rez.total where codrez = v_rez.CodRez;
        end loop;
        update prodcomp_clona set pret_n = v_xxx.pretprodus, valmat = vValMat, valman = vValMan, valregie = vValRegie where codprodcomp = v_xxx.Codprodcomp;
      else
        -- update la valoare manopera
        for v_tmp in (select pm.tu, t1.tarif, pm.codman, decode(nvl(pm.bps,1),0,1,nvl(pm.bps,1)) BPS
                      FROM PRODMAN PM
                        left join TARIFEMAN1 T1 ON t1.codtarif = pm.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                      where PM.codprodcomp = v_xxx.CodProdComp) loop
          update prodman_clona
          set
            valoare_n = round((v_tmp.tarif * v_tmp.tu)/60, 7)/v_tmp.BPS
          where codman = v_tmp.codman;
        end loop;

        -- update la materiale

        vPret := 0;
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;

        for v_tmp in (select mat.codmat, mat.codobiect, nvl(mat.pret,0) pret, mat.tip
                      from prodmat mat
                      where mat.codprodcomp = v_xxx.codprodcomp) loop

          insert into tmp_manevra_liste(valoare)
          select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;
          mat := 0;
          man := 0;
          vValRegie := 0;
          if v_tmp.tip in (3,4,5) then
            if v_tmp.tip = 4 then
              vPret := 0;
            else
              vPret := pkg_prodcomp.GetPretFromStoc(v_tmp.codobiect);
            end if;
          else
            --testul preturilor zero
            if not PreturiZero then
              select count(codprodcomp) into aCountI
              from prodcomp where codobiect = v_tmp.codobiect and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0 and nvl(pret,0) = 0;
              if aCountI &gt; 0 then
                PreturiZero := True;
              end if;
            end if;

            -- aduc ori pretul retetei implicite ori medie
            select count(codprodcomp) into aCountI from prodcomp where codobiect = v_tmp.codobiect
            and generic = 1 and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
            if aCountI &gt; 0 then
              select sum(pret)/aCountI, sum(valmat)/aCountI, sum(valman)/aCountI, sum(valregie)/aCountI into vPret, mat, man, vValRegie from prodcomp
              where codobiect = v_tmp.codobiect and generic = 1  and nvl(inactiv, 0) = 0
              and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
            else
              select count(codprodcomp) into aCountI from prodcomp
              where codobiect = v_tmp.codobiect
              and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
                if aCountI &gt; 0 then
                  select sum(pret)/aCountI, sum(valmat)/aCountI, sum(valman)/aCountI, sum(valregie)/aCountI into vPret, mat, man, vValRegie from prodcomp
                  where codobiect = v_tmp.codobiect  and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
                else
                  vPret := pkg_prodcomp.GetPretFromStoc(v_tmp.codobiect);
                  mat := 0;
                  man := 0;
                  vValRegie := 0;
                end if;
            end if;
          end if;

         update prodmat_clona set pret_n = vPret, valmat = mat, valman = man, valregie = vValRegie where codmat = v_tmp.codmat;
        end loop;

        -- update la pret produs compus
        delete tmp_manevra_liste;
        insert into tmp_manevra_liste(valoare)
        select codobiect from prodcomp where codprodcomp = v_xxx.codprodcomp;

        select cant into aCant from prodcomp where codprodcomp = v_xxx.CodProdComp;

        vValMat   := 0;
        vValMan   := 0;
        vValRegie := 0;
        vValRegieMan := 0;
        vPret := 0;
        for v_rec in (select codprodgest from prodgest where codprodcomp = v_xxx.codprodcomp) loop
          --manopera retetei
          for v_tmp in (select nvl(pg.coefman, nvl(ng.coefcheltman,0)) coefcheltman, round((t1.tarif * man.tu)/60/decode(nvl(man.bps,1),0,1,nvl(man.bps,1)), 7) valoare
                        from prodman man
                             inner join prodgest pg on man.codprodgest = pg.codprodgest
                             left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                             left join ngest ng on ng.codgest = pg.codgest
                        where man.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            vValMan   := vValMan + v_tmp.valoare;
            if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
              vValRegie := vValRegie  + v_tmp.valoare * v_tmp.coefcheltman;
              vValRegieMan := vValRegieMan  + v_tmp.valoare * v_tmp.coefcheltman;
            end if;
          end loop;
          -- manopera compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip, nvl(clona.valman,0) valman
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValMan := vValMan + v_tmp.cant/aCant * v_tmp.valman;
          end loop;
          -- materiale
          for v_tmp in (select mat.codobiect, nvl(pg.coefmat, nvl(ng.coefcheltmat,0)) coefcheltmat, mat.cant, tmpp.pret, nvl(mat.tip, 3) tip, nvl(clona.valmat,0) valmat
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join tmp_manevra_preturi tmpp on tmpp.codobiect = mat.codobiect
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest) loop
            if v_tmp.tip in (3,4,5) then
              vValMat   := vValMat + v_tmp.cant * v_tmp.pret;
              if not (KTipCoefIndirecte = 3 and KRegieAntecalcul = 2) then
                vValRegie := vValRegie + v_tmp.cant * v_tmp.pret/acant * v_tmp.coefcheltmat;
              end if;
            else
              vValMat   := vValMat + v_tmp.cant * v_tmp.valmat;
            end if;
          end loop;
          --regia compusilor
          for v_tmp in (select mat.codobiect, mat.cant, nvl(mat.tip, 3) tip, nvl(clona.valregie,0) valregie
                        from prodmat mat
                             inner join prodmat_clona clona on clona.codmat = mat.codmat
                             inner join prodgest pg on mat.codprodgest = pg.codprodgest
                             left join ngest ng on ng.codgest = pg.codgest
                        where mat.codprodcomp = v_xxx.codprodcomp and pg.codprodgest = v_rec.codprodgest and nvl(mat.tip, 3) &lt; 3) loop
            vValRegie := vValRegie + v_tmp.cant/acant * v_tmp.valregie;
          end loop;
          vValMat := vValMat/aCant;
        end loop;

        if KTipCoefIndirecte = 3 and KRegieAntecalcul = 2 then
          vValRegie := vValRegie + v_xxx.CoefIndirecte;
        end if;

        if v_xxx.tippret = 1 then
          vPret := vPret + vValMat + vValMan + vValRegie;
        else
          vPret := vPret + vValMat;
        end if;

        update prodcomp_clona set pret_n = vPret, valmat = vValMat, valman = vValMan, valregie = vValRegie, valregieman = vValRegieMan where codprodcomp = v_xxx.Codprodcomp;
      end if;
    end loop;
  end if;

  if DoCommit then
    commit;
  end if;
  if PreturiZero then
    Return 1;
  else
    Return 0;
  end if;
end;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

FUNCTION GET_VALORE_PRODUS(aCodcomanda1 in number, aDeazagrezare in number, aPMP in number default 0) return number is
  iResult number(20,6);
  iResultS number(20,6);
  TipCoefIndirecte number(20,6);
  aAn number(4);
  aLuna number(2);
begin
  aAn := PKG_GLOBALS.GETANLUCRU;
  aLuna := PKG_GLOBALS.GETLUNALUCRU;
  begin
    SELECT NVL(PKG_CATEGCONST.GetValConstanta(&apos;TipCoefIndirecte&apos;, aAn, aLuna), 0) INTO TipCoefIndirecte FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TipCoefIndirecte := 1;
  end;

  if aPMP &gt; 0 then
    if TipCoefIndirecte = 2 then
      if aDeazagrezare = 0 then
        SELECT NVL(SUM(
                       coalesce(L1.PMP,0) * L1.CANT + NVL(C1.COEFINDIRECTE,0 )*
                        round(CASE
                           WHEN nvl(ART.RELATIEUM1,0) = 0 then 0
                           WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN L1.cant/ART.D1
                           WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0))
                           WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
                           WHEN ART.RELATIEUM1 IN (4, 10) THEN L1.cant * NVL(ART.D1,0)
                           WHEN ART.RELATIEUM1 IN (5, 11) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0)
                           WHEN ART.RELATIEUM1 IN (6, 12) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
                         END,NVL(UM1.ZECIMALE,1)) * NVL(NUM.COEF,1)
                      )
                   ,0) INTO IRESULT
        FROM   IESIRI I,
               IESIRI1 I1
               INNER JOIN NUM1 UM1 ON UM1.CODUM1 = I1.UMSEC,
               LIVR1 L1,
               LIVR L,
               NIRSTOC NS
               INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NUM ON NUM.CODUM = ART.UM
               LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
               COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      else
        SELECT NVL(
                   SUM(
                       coalesce(L1.PMP,0) * L1.CANT +
                       NVL(C1.COEFINDIRECTE,0 ) *
                       round(CASE
                               WHEN nvl(ART.RELATIEUM1,0) = 0 then 0
                               WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN L1.cant/ART.D1
                               WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0))
                               WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
                               WHEN ART.RELATIEUM1 IN (4, 10) THEN L1.cant * NVL(ART.D1,0)
                               WHEN ART.RELATIEUM1 IN (5, 11) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0)
                               WHEN ART.RELATIEUM1 IN (6, 12) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
                             END,NVL(UM1.ZECIMALE,1)) * NVL(NUM.COEF,1)
                      )
                  ,0) INTO IRESULT
        FROM   IESIRI I,
               IESIRI1 I1
               INNER JOIN NUM1 UM1 ON UM1.CODUM1 = I1.UMSEC,
               LIVR1 L1,
               LIVR L,
               NIRSTOC NS
               INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NUM ON NUM.CODUM = ART.UM
               LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
               COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      end if;
    else
    if TipCoefIndirecte = 3 then
       if aDeazagrezare = 0 then
         begin
           SELECT SUM(coalesce(L1.PMP,0) * L1.CANT) +  NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT   INTO IRESULT
           FROM   CMDPRODMAT  CMD,
                  PRODMAT     PM,
                  IESPRODLINK IES,
                  LIVR1       L1,
                  LIVR        L,
                  NIRSTOC     NS
                  INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                  LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
                  COMANDA1    C1
           WHERE  CMD.CODCMDPRODMAT = IES.CODCMDPRODMAT
             AND  PM.CODMAT = CMD.CODPRODMAT
             AND  IES.CODIES1 = L1.CODIES1
             AND  L.CODLIVR = L1.CODLIVR
             AND  L.TIPLIVR = 24
             AND  L1.CODNIRSTOC = NS.CODNIRSTOC
             AND  C1.CODCOMANDA1 = CMD.CODCOMANDA1
             AND  CMD.CODCOMANDA1 = aCodcomanda1
             AND NVL(DVI.TIPIMPORT,0) = 0
             group by NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT;
         exception when others then IRESULT := 0;
         end;
       else
         begin
           SELECT SUM(coalesce(L1.PMP,0) * L1.CANT) +  NVL(C1.COEFINDIRECTE,0 )* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT   INTO IRESULT
           FROM   CMDPRODMAT  CMD,
                  PRODCOMP    PM,
                  IESPRODLINK IES,
                  LIVR1       L1,
                  LIVR        L,
                  NIRSTOC     NS
                  INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                  LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
                  COMANDA1    C1
           WHERE  CMD.CODCMDPRODMAT = IES.CODCMDPRODMAT
             AND  PM.CODPRODCOMP = C1.CODRETETA
             AND  IES.CODIES1 = L1.CODIES1
             AND  L.CODLIVR = L1.CODLIVR
             AND  L.TIPLIVR = 24
             AND  L1.CODNIRSTOC = NS.CODNIRSTOC
             AND  C1.CODCOMANDA1 = CMD.CODCOMANDA1
             AND  CMD.CODCOMANDA1 = aCodcomanda1
             AND NVL(DVI.TIPIMPORT,0) = 0
           group by NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT;
         exception when others then IRESULT := 0;
         end;
       end if;
    else
      begin
        SELECT NVL( SUM(coalesce(L1.PMP,0) * L1.CANT * (NVL(C1.COEFINDIRECTE,0)+1))  ,0) INTO IRESULT
        FROM IESIRI I,
             IESIRI1 I1,
             LIVR1 L1,
             LIVR L,
             NIRSTOC NS
             INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
             INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
             INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
             INNER JOIN NUM ON NUM.CODUM = ART.UM
             LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
             COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      exception when others then IRESULT := 0;
      end;
    end if;
    end if;
  else
    if TipCoefIndirecte = 2 then
      if aDeazagrezare = 0 then
        SELECT NVL(SUM(
                       (NVL(NS.PRET,0) - NVL(NS.ADAOS,0)) * L1.CANT + NVL(C1.COEFINDIRECTE,0 )*
                        round(CASE
                           WHEN nvl(ART.RELATIEUM1,0) = 0 then 0
                           WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN L1.cant/ART.D1
                           WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0))
                           WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
                           WHEN ART.RELATIEUM1 IN (4, 10) THEN L1.cant * NVL(ART.D1,0)
                           WHEN ART.RELATIEUM1 IN (5, 11) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0)
                           WHEN ART.RELATIEUM1 IN (6, 12) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
                         END,NVL(UM1.ZECIMALE,1)) * NVL(NUM.COEF,1)
                      )
                   ,0) INTO IRESULT
        FROM   IESIRI I,
               IESIRI1 I1
               INNER JOIN NUM1 UM1 ON UM1.CODUM1 = I1.UMSEC,
               LIVR1 L1,
               LIVR L,
               NIRSTOC NS
               INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NUM ON NUM.CODUM = ART.UM
               LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
               COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      else
        SELECT NVL(
                   SUM(
                       (NVL(NS.PRET,0) - NVL(NS.ADAOS,0)) * L1.CANT +
                       NVL(C1.COEFINDIRECTE,0 ) *
                       round(CASE
                               WHEN nvl(ART.RELATIEUM1,0) = 0 then 0
                               WHEN ART.RELATIEUM1 IN (1, 7) AND NVL(ART.D1, 0) &lt;&gt; 0 THEN L1.cant/ART.D1
                               WHEN ART.RELATIEUM1 IN (2, 8) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0))
                               WHEN ART.RELATIEUM1 IN (3, 9) AND NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0) &lt;&gt; 0 THEN L1.cant / (NVL(ART.D1,0) * NVL(ART.D2,0) * NVL(ART.D3,0))
                               WHEN ART.RELATIEUM1 IN (4, 10) THEN L1.cant * NVL(ART.D1,0)
                               WHEN ART.RELATIEUM1 IN (5, 11) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0)
                               WHEN ART.RELATIEUM1 IN (6, 12) THEN L1.cant * NVL(ART.D1, 0) * NVL(ART.D2, 0) * NVL(ART.D3, 0)
                             END,NVL(UM1.ZECIMALE,1)) * NVL(NUM.COEF,1)
                      )
                  ,0) INTO IRESULT
        FROM   IESIRI I,
               IESIRI1 I1
               INNER JOIN NUM1 UM1 ON UM1.CODUM1 = I1.UMSEC,
               LIVR1 L1,
               LIVR L,
               NIRSTOC NS
               INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
               INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
               INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
               INNER JOIN NUM ON NUM.CODUM = ART.UM
               LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
               COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      end if;
    else
    if TipCoefIndirecte = 3 then
       if aDeazagrezare = 0 then
         begin
           SELECT SUM((nvl(NS.PRET,0) - nvl(NS.ADAOS,0)) * L1.CANT) +  NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT   INTO IRESULT
           FROM   CMDPRODMAT  CMD,
                  PRODMAT     PM,
                  IESPRODLINK IES,
                  LIVR1       L1,
                  LIVR        L,
                  NIRSTOC     NS
                  INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                  LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
                  COMANDA1    C1
           WHERE  CMD.CODCMDPRODMAT = IES.CODCMDPRODMAT
             AND  PM.CODMAT = CMD.CODPRODMAT
             AND  IES.CODIES1 = L1.CODIES1
             AND  L.CODLIVR = L1.CODLIVR
             AND  L.TIPLIVR = 24
             AND  L1.CODNIRSTOC = NS.CODNIRSTOC
             AND  C1.CODCOMANDA1 = CMD.CODCOMANDA1
             AND  CMD.CODCOMANDA1 = aCodcomanda1
             AND NVL(DVI.TIPIMPORT,0) = 0
             group by NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT;
         exception when others then IRESULT := 0;
         end;
       else
         begin
           SELECT SUM((nvl(NS.PRET,0) - nvl(NS.ADAOS,0)) * L1.CANT) +  NVL(C1.COEFINDIRECTE,0 )* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT   INTO IRESULT
           FROM   CMDPRODMAT  CMD,
                  PRODCOMP    PM,
                  IESPRODLINK IES,
                  LIVR1       L1,
                  LIVR        L,
                  NIRSTOC     NS
                  INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                  LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
                  COMANDA1    C1
           WHERE  CMD.CODCMDPRODMAT = IES.CODCMDPRODMAT
             AND  PM.CODPRODCOMP = C1.CODRETETA
             AND  IES.CODIES1 = L1.CODIES1
             AND  L.CODLIVR = L1.CODLIVR
             AND  L.TIPLIVR = 24
             AND  L1.CODNIRSTOC = NS.CODNIRSTOC
             AND  C1.CODCOMANDA1 = CMD.CODCOMANDA1
             AND  CMD.CODCOMANDA1 = aCodcomanda1
             AND NVL(DVI.TIPIMPORT,0) = 0
           group by NVL(C1.COEFINDIRECTE,0)* nvl(PM.CANTUM1,TipCoefIndirecte-2)/PM.CANT*L1.CANT;
         exception when others then IRESULT := 0;
         end;
       end if;
    else
      begin
        SELECT NVL( SUM((nvl(NS.PRET,0) - nvl(NS.ADAOS,0)) * L1.CANT * (NVL(C1.COEFINDIRECTE,0)+1))  ,0) INTO IRESULT
        FROM IESIRI I,
             IESIRI1 I1,
             LIVR1 L1,
             LIVR L,
             NIRSTOC NS
             INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
             INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NS.CODOBIECT
             INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
             INNER JOIN NUM ON NUM.CODUM = ART.UM
             LEFT JOIN DVI ON DVI.CODINTR = NIR.CODNIR,
             COMANDA1 C1
        WHERE  I.CODIES = I1.CODIES
          AND  L.CODIES = I.CODIES
          AND  I1.CODIES1 = L1.CODIES1
          AND  L.CODLIVR = L1.CODLIVR
          AND  L.TIPLIVR = 24
          AND  L1.CODNIRSTOC = NS.CODNIRSTOC
          AND  C1.CODCOMANDA1 = I1.CODCMDINT1
          AND  C1.CODCOMANDA1 = aCodcomanda1
          AND NVL(DVI.TIPIMPORT,0) = 0;
      exception when others then IRESULT := 0;
      end;
    end if;
    end if;
  end if;
  
  begin
    SELECT NVL(SUM(I1.PU * I1.CANT),0) * case when coalesce(i.moneda,0) &gt; 0 then i.curs else 1 end INTO IRESULTS
    FROM INTRARI I,
         INTRARI1 I1
    WHERE I1.CODCMDINT1 = aCodcomanda1
          AND COALESCE(I.ANULAT,0) = 0 AND I.OPERAT = 1 AND I1.TIPLINIE = &apos;S&apos;
          AND I.CODINTR = I1.CODINTR
          and exists (
              select mat.codobiect
              from prodmat mat
                   inner join cmdprodmat cmd on cmd.codprodmat = mat.codmat
                   inner join comanda1 c1 on c1.codcomanda1 = cmd.codcomanda1
              where c1.codcomanda1 = aCodComanda1 and mat.tip = 6 and mat.codobiect = i1.codobiect
              );
  exception when others then IRESULTS := 0;
  end;
  
  return NVL(iResult,0) + NVL(iResultS,0);
end;

FUNCTION UpdateImplicit(aCodProdComp IN NUMBER, aImplicit IN NUMBER) return Boolean is pragma autonomous_transaction;
Done BOOLEAN;
begin
  begin
    update prodcomp set implicit = aImplicit where codprodcomp = aCodProdComp;
    commit;
    Done := True;
  exception when others then
    Done := False;
  end;

  Return Done;
end;

FUNCTION UpdateGeneric(aCodProdComp IN NUMBER, aGeneric IN NUMBER) return Boolean is pragma autonomous_transaction;
Done BOOLEAN;
begin
  begin
    update prodcomp set generic = aGeneric where codprodcomp = aCodProdComp;
    commit;
    Done := True;
  exception when others then
    Done := False;
  end;

  Return Done;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodProdComp INTO Tmp FROM PRODCOMP WHERE CodProdComp = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
vCodProiect number(20);
vCodObiect number(20);
aDataDoc DATE;
aDoc     VARCHAR2(600);
BEGIN
  SP_LOCKRECORD(RecId);
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 504);
  SELECT
    DATA,
    &apos;OBJ:&apos;||OBJ.DENUMIRE||&apos; VER:&apos;||P.OBS||&apos; (&apos;||RecId||&apos;)&apos;
  INTO
    aDATADOC,
    ADOC
  FROM PRODCOMP P
   LEFT JOIN NARTOBJ OBJ ON P.CODOBIECT = OBJ.CODOBIECT
  WHERE P.CODPRODCOMP = RecId;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  select CodObiect into vCodObiect from prodcomp where codprodcomp = recid;

  begin
    select P.CodProiect into vCodProiect
    from proiectnod PN
         inner join proiect P on PN.CODPROIECT = P.CODPROIECT
    where PN.NODORIGINAL = 0 and
          PN.CODRETETA = RecId and
          PN.CODOBIECT = vCodObiect and
          P.Invizibila = 1;
  exception when no_data_found then
    vCodProiect := 0;
  end;

  if vCodProiect &gt; 0 then
    DELETE PROIECTNOD  WHERE CodProiect  = vCodProiect;
    DELETE PROIECT  WHERE CodProiect  = vCodProiect;
  end if;

  DELETE PRODMATECHIV WHERE CodProdComp = RecId;
  DELETE PRODSDV  WHERE CodProdComp = RecId;
  DELETE PRODMAN  WHERE CodProdComp = RecId;
  DELETE PRODMAT  WHERE CodProdComp = RecId;
  DELETE PRODREZ  WHERE CodProdComp = RecId;
  DELETE PRODMAS  WHERE CodProdComp = RecId;
  DELETE PRODGEST WHERE CodProdComp = RecId;
  DELETE NORMEMAT WHERE CODPRODCOMP = RECID;
  DELETE PRODNORME WHERE CODPRODCOMP = RECID;
  DELETE PRODCOMP WHERE CodProdComp = RecId;

  NotifyModif(2, RecId, &apos;PRODCOMP&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PRODCOMP (Codprodcomp, tipreteta) values (0,1);
  PKG_CFGTABLES.EXT_INSERTRECORD(504);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aCount number(20);
aCodGest number(20);
TIPPREFIX VARCHAR2(1);
Blocare number(1);
aValRegieMan number(20,7);
aBanca number(20);
aDur number(20,7);
aPrecI number(20,7);
aPrecF number(20,7);
aDurPrec number(20,7);
aLotOptim number(20);
aCodMan number(20);
BEGIN
  aBanca := pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  if pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 0 then
    aBanca := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  end if;
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;BlocareModifReteta&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO Blocare FROM DUAL;
    EXCEPTION WHEN OTHERS THEN Blocare := 2;
  END;

  begin
    select sum(case
                 when nvl(man.bps,0) = 0 then nvl(t1.tarif,0) * nvl(man.tu,0) / 60 * nvl(pg.coefman,nvl(g.coefcheltman,0))
                 else nvl(t1.tarif,0) * nvl(man.tu,0) / 60 / nvl(man.bps,0) * nvl(pg.coefman,nvl(g.coefcheltman,0))
               end) into aValRegieMan
    from prodcomp pc
         inner join prodman man on man.codprodcomp = pc.codprodcomp
         inner join prodgest pg on pg.codprodcomp = pc.codprodcomp and man.codprodgest = pg.codprodgest
         left join ngest g on g.codgest = pg.codgest
         left join TARIFEMAN1 T1 ON t1.codtarif = man.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
    where pc.codprodcomp = RecId;
  exception when others then aValRegieMan := 0;
  end;

  begin
    select cant into aLotOptim from prodcomp where codprodcomp = recid;
  exception when others then aLotOptim := 1;
  end;

  INSERT INTO TMP_PRODCOMP
    ( CodProdComp,
      CODOBIECT,
      OBS,
      DATA,
      ANULAT,
      BLOCAT,
      OPERAT,
      CANT,
      D1,
      D2,
      D3,
      TIPRETETA,
      CantUM1,
      RELATIEUM1,
      DEN_OBIECT,
      DEN_UM,
      Den_UmSpec,
      UM,
      UM1,
      COEFINDIRECTE,
      PRET,
      IMPLICIT,
      descriere,
      inactiv,
      Gest,
      HFactor,
      IDENTIFICATOR,
      DATADOCUMENTATIE,
      ARHIVA,
      OBSERVATII,
      PROIECTANT,
      CodClasaProd,
      Invizibila,
      Generic,
      durata,
      totalmat,
      totalman,
      totalrez,
      totalprod,
      TipPret, codproiect, valmat, valman, valregie, genericold, inactivold, implicitold,
      Obs1, Obs2, Obs3, Obs4, Obs5, Obs6,
      CodMoneda, PretValuta,
      AG,
      ValAG,
      Profit,
      ValProfit,
      PretFinal,
      VALPROFITV,
      PRETFINALV,
      TOTPRETCOEF,
      TOTPRETFIX,
      TOTPRETCOEFV,
      TOTPRETFIXV,
      valregieman,
      NOHFACTOR
      )
  (SELECT
      P.CodProdComp,
      P.CODOBIECT,
      P.OBS,
      P.DATA,
      P.ANULAT,
      P.BLOCAT,
      P.OPERAT,
      P.Cant,
      P.D1,
      P.D2,
      P.D3,
      P.TIPRETETA,
      P.CantUM1,
      ART.RELATIEUM1,
      OBJ.Denumire,
      U.Den_Um,
      U1.Den_Um,
      Art.UM,
      U1.CodUM,
      P.COEFINDIRECTE,
      P.PRET,
      P.Implicit,
      P.Descriere,
      P.Inactiv,
      P.Gest,
      P.HFactor,
      P.IDENTIFICATOR,
      P.DATADOCUMENTATIE,
      P.ARHIVA,
      P.OBSERVATII,
      P.PROIECTANT,
      P.CodClasaProd,
      P.Invizibila,
      P.Generic,
      P.durata,
      nvl((select sum(nvl(cant, 0)*nvl(pret, 0)) from prodmat where codprodcomp = recid), 0),
      nvl((select sum(nvl(valoare, 0)) from prodman where codprodcomp = recid), 0),
      nvl((select sum(nvl(cant, 0)*nvl(pret, 0)) from prodrez where codprodcomp = recid), 0),
      nvl((select sum(nvl(cant, 0)*nvl(pret, 0)) from prodmat where codprodcomp = recid), 0) +
      nvl((select sum(nvl(valoare, 0)) from prodman where codprodcomp = recid), 0) -
      nvl((select sum(nvl(cant, 0)*nvl(pret, 0)) from prodrez where codprodcomp = recid), 0),
      P.TipPret, P.CodProiect, P.Valmat, p.valman, p.valregie, p.generic, p.inactiv, p.implicit,
      P.Obs1, P.Obs2, P.Obs3, P.Obs4, P.Obs5, P.Obs6,
      P.CodMoneda, P.PretValuta,
      P.AG,
      P.ValAG,
      P.Profit,
      P.ValProfit,
      P.PretFinal,
      P.VALPROFITV,
      P.PRETFINALV,
      nvl(P.TOTPRETCOEF,nvl(P.pret, 0) * (1 + nvl(P.COEFINDIRECTE, 0))),
      nvl(P.TOTPRETFIX,nvl(P.pret, 0) + nvl(P.COEFINDIRECTE, 0)),
      nvl(P.TOTPRETCOEFV,P.TOTPRETCOEF /
                         PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                           P.codmoneda,
                           aBanca,
                           sysdate)),
      nvl(P.TOTPRETFIXV, P.TOTPRETFIX /
                         PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                           P.codmoneda,
                           aBanca,
                           sysdate)),
      nvl(P.ValRegieMan, aValRegieMan),
      NVL(P.NOHFACTOR,0)
   FROM PRODCOMP P
         LEFT JOIN NARTOBJ OBJ ON P.CODOBIECT = OBJ.CODOBIECT
         LEFT JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
         LEFT JOIN NUM U ON ART.UM = U.CODUM
         LEFT JOIN NUM U1 ON ART.UM1 = U1.CODUM
   WHERE P.CodProdComp = RecId );

  update tmp_prodcomp set valtotal = nvl(valmat,0)+nvl(valman,0)+nvl(valregie,0);
  if Blocare = 1 then
    update tmp_prodcomp set nrcmd = (select count(*) from comanda1 where codreteta = RecId);
  end if;

  update tmp_prodcomp set durataafis = durata;
  if pkg_categconst.GetValConstanta(&apos;AfisareDurata&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 2 then
    update tmp_prodcomp set durataafis = nvl(durata,0)/60;
  end if;

  begin
    select NVL(Gest, 0) into aCodGest from TMP_ProdComp;
  exception when others then aCodGest := 0;
  end;

  --inainte de PRODMAT
  INSERT INTO TMP_PRODMAN (CODMAN,
                           CODPRODCOMP,
                           NROP,
                           CODOP,
                           CODLOC,
                           CODTARIF,
                           TU,
                           VALOARE,
                           DEN_OPERATIE,
                           DEN_LOCMUNCA,
                           DIFICULTATE,
                           TARIF,
                           CODPRODGEST,
                           DSV,
                           BPS,
                           TPI,
                           Obs,
                           Detalii, Fix, Nivel,
                           TUH,
                           TPIH,
                           CODEXTERN,
                           DECALAJ,
                           BARA,
                           INCEPERE,
                           COEFBPS,
                           VALOARELEI)
                   (SELECT PM.CODMAN,
                           PM.CODPRODCOMP,
                           PM.NROP,
                           PM.CODOP,
                           PM.CODLOC,
                           PM.CODTARIF,
                           PM.TU,
                           PM.VALOARE,
                           O.DENUMIRE,
                           LM.DENUMIRE,
                           T.Denumire,
                           COALESCE(T1.TARIF, PM.VALOARE/PM.TU*60),
                           NVL(PM.CodProdGest, 0),
                           PM.DSV,
                           PM.Bps,
                           PM.Tpi,
                           PM.obs,
                           PM.Detalii, Fix, Nivel,
                           NVL(PM.TU,0)/60,
                           NVL(PM.Tpi,0)/60,
                           O.CODEXTERN,
                           case when coalesce(PM.DECALAJ,0) = 0 then 1 else PM.DECALAJ end,
                           &apos;...&apos; BARA,
                           PM.INCEPERE,
                           COALESCE(PM.COEFBPS,0),
                           PM.VALOARE *
                           PKG_LIST_BASE_UTILS.GETCURSREFERINTA(
                            nvl(PC.codmoneda,0),
                            decode(pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   0,pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),
                                   pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)),
                            sysdate)
                    FROM PRODMAN PM
                         INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = PM.CODPRODCOMP
                         LEFT JOIN NOPER O ON PM.CODOP = O.CODOP
                         LEFT JOIN LOCMUNCA LM ON PM.CODLOC = LM.CODLOC
                         left join TARIFEMAN1 T1 ON t1.codtarif = pm.codtarif AND PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALStart AND T1.ALStop
                         left join TARIFEMAN T ON t.codtarif = pm.codtarif
                    WHERE PM.CodProdComp = RecId);

  for v_Rec in (
    SELECT
      PM.CODMAT,
      PM.CODPRODCOMP,
      PM.CODOBIECT,
      PM.CANT,
      PM.PRET,
      PM.PRETV,
      PM.D1,
      PM.D2,
      PM.D3,
      PM.CopyD1,
      PM.CopyD2,
      PM.CopyD3,
      PM.Indexlocal,
      PM.CantUM1,
      ART.RelatieUM1,
      OBJ.DENUMIRE,
      ART.UM,
      ART.UM1,
      ART.CODARTICOL,
      NVL(PM.CodProdGest, 0) CodProdGest,
      PM.Tip,
      NVL(PM.Codatribut, 0) CodAtribut,
      pm.Obs,
      1 Paritate,
      NUM.DEN_UM,
      pm.valmat,
      pm.valman,
      pm.valregie,
      obj.codintern,
      obj.codextern,
      ROW_NUMBER() OVER (ORDER BY pm.indexlocal) Ordine,
      PM.Adddim,
      PM.Adddim_Transp,
      PM.Pretorig,
      PROD.DEN_PART,
      nvl(PM.ProcReal,100) ProcReal,
      round(PM.Cant * 100 / decode(nvl(PM.ProcReal,100),0,100,nvl(PM.ProcReal,100)) ,7) CantT,
      nvl(PM.Valoare,PM.Cant*PM.Pret) Valoare,
      PM.CodReteta,
      CASE WHEN PC.CODPRODCOMP &gt; 0 THEN PC.OBS ELSE NULL END RETETA,
      PM.CodMan, MAN.NROP, MAN.DEN_OPERATIE,
      PM.ETAPA, PM.PRINCIPAL, PM.CONSUM
    FROM PRODMAT PM
      LEFT JOIN NARTOBJ OBJ ON PM.CODOBIECT = OBJ.Codobiect
      LEFT JOIN NPART PROD ON PROD.CODPART = OBJ.CODPRODUCATOR
      LEFT JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
      LEFT JOIN NUM ON ART.UM = NUM.CODUM
      LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = PM.CODRETETA
      LEFT JOIN TMP_PRODMAN MAN ON MAN.CODMAN = PM.CODMAN
    WHERE PM.CodProdComp = RecId order by pm.indexlocal
  ) loop
    INSERT INTO TMP_PRODMAT (
      CODMAT, CODPRODCOMP, CODOBIECT, CANT, PRET, PRETV, D1, D2, D3, CopyD1, CopyD2, CopyD3, IndexLocal, CantUM1, RelatieUM1, DEN_OBIECT, CODUM, CODUMSPEC, CODARTICOL, CodProdGest, Tip,
      codatribut, Obs, Paritate, denum, valmat, valman, Valregie, CodIntern, CodExtern, ADDDIM, ADDDIM_TRANSP, PRETORIG, PRODUCATOR, Procreal, Cantt,
      Valoare, Codreteta, RETETA, CodMan, NrOp, OPER, ETAPA, PRINCIPAL, CONSUM)
    values (
      v_rec.CODMAT, v_rec.CODPRODCOMP, v_rec.CODOBIECT, v_rec.CANT, v_rec.PRET, v_rec.PRETV, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CopyD1, v_rec.CopyD2, v_rec.CopyD3, v_rec.IndexLocal, v_rec.CantUM1, v_rec.RelatieUM1, v_rec.DENUMIRE, v_rec.UM, v_rec.UM1, v_rec.CODARTICOL, v_rec.CodProdGest, v_rec.Tip,
      v_rec.Codatribut, v_rec.Obs, v_rec.Paritate, v_rec.DEN_UM, v_rec.valmat, v_rec.valman, v_rec.valregie, v_rec.codintern, v_rec.codextern, V_REC.ADDDIM,
      V_REC.ADDDIM_TRANSP, NVL(V_REC.PRETORIG, V_REC.PRET), V_REC.DEN_PART, v_rec.ProcReal, v_rec.CantT, v_rec.valoare, v_rec.codreteta, V_REC.RETETA, v_rec.CodMan,
      v_rec.nrop, V_REC.DEN_OPERATIE, V_REC.ETAPA, V_REC.PRINCIPAL, V_REC.CONSUM);
  end loop;

  delete tmp_prodmat_initial;
  insert into tmp_prodmat_initial select * from tmp_prodmat;

  INSERT INTO TMP_PRODREZ (CODREZ, CODPRODCOMP, CODOBIECT, CANT, PRET, D1, D2, D3, IndexLocal, REZIDUU, CantUM1, RelatieUM1, DEN_OBIECT, CODUM, CODUMSPEC, CODARTICOL,
                           CodProdGest, Paritate, CodIntern, CodExtern, DENUM, Obs)
  (SELECT PR.CODREZ, PR.CODPRODCOMP, PR.CODOBIECT, PR.CANT, PR.PRET, PR.D1, PR.D2, PR.D3, PR.IndexLocal, PR.REZIDUU, PR.CantUM1, ART.RelatieUM1, OBJ.DENUMIRE, ART.UM, ART.UM1, ART.CODARTICOL,
          NVL(PR.CodProdGest, 0), 1, obj.codintern, obj.codextern, NUM.DEN_UM, PR.Obs
   FROM PRODREZ PR
        LEFT JOIN NARTOBJ OBJ ON PR.CODOBIECT = OBJ.Codobiect
        LEFT JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
        LEFT JOIN NUM ON ART.UM = NUM.CODUM
   WHERE PR.CodProdComp = RecId) ORDER BY Indexlocal;


  INSERT INTO TMP_PRODGEST (CODPRODGEST, CODPRODCOMP, INDEXLOCAL, CODGEST, CoefMat, CoefMan, TimpEst)
  SELECT CODPRODGEST, CODPRODCOMP, INDEXLOCAL, pg.CODGEST, nvl(pg.CoefMat, g.CoefCheltMat), nvl(pg.CoefMan, g.CoefCheltMan), pg.TimpEst FROM PRODGEST pg
         left join ngest g on g.codgest = pg.codgest WHERE CODPRODCOMP = RecId;

  INSERT INTO TMP_PRODNORME(CODNORMA, CODPRODCOMP, NORMA, INDEXLOCAL, IMPLICIT,ACTIV,DATAACTIV,DATAINACTIV)
  SELECT CODNORMA, CODPRODCOMP, NORMA, INDEXLOCAL, nvl(IMPLICIT,0),nvl(ACTIV,0),DATAACTIV,DATAINACTIV FROM PRODNORME WHERE CODPRODCOMP = RECID;

  select count(*) into aCount from tmp_prodgest;
  if aCount = 0 then
    INSERT INTO TMP_PRODGEST (CODPRODGEST, CODPRODCOMP, INDEXLOCAL, CODGEST)
    values (0, RecId, 1, aCodGest);
    begin
      select count(distinct codprodgest) into aCount from tmp_prodmat;
      if aCount = 1 then
        update tmp_prodgest set codprodgest = (select distinct codprodgest from tmp_prodmat);
      end if;
    exception when others then
      update tmp_prodgest set codprodgest = 0;
    end;
  end if;

  insert into tmp_prodmas (codprodmas, codprodcomp, descriere, frecventa, metoda, codobiect, indexlocal, denumire )
  select pm.codprodmas, pm.codprodcomp, pm.descriere, pm.frecventa, pm.metoda, pm.codobiect, pm.indexlocal, obj.denumire
  from prodmas PM
       left join nartobj obj on pm.codobiect = obj.codobiect
  where codprodcomp = RecId;

  INSERT INTO TMP_PRODSDV (CODPRODSDV, CODPRODMAN, INDEXLOCAL, CODSDV, CODGENERIC, CANT, PRET, CODPRODCOMP, DENUMIRE, CODUM, CODARTICOL, DENUM)
  SELECT SDV.CODPRODSDV, SDV.CODPRODMAN, SDV.INDEXLOCAL, SDV.CODSDV, SDV.CODGENERIC, SDV.CANT, SDV.PRET, SDV.CODPRODCOMP, OBJ.DENUMIRE, ART.UM, OBJ.CODARTICOL,
         NUM.DEN_UM
  FROM PRODSDV SDV
       LEFT JOIN NARTOBJ OBJ ON SDV.CODSDV = OBJ.CODOBIECT
       LEFT JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
       LEFT JOIN NUM ON ART.UM = NUM.CODUM
  WHERE CODPRODCOMP = RecId;

  INSERT INTO TMP_NORMEMAT(CODNORMEMAT, CODNORMA, CODPRODCOMP, CODOBIECT, CANT, PRET, CODMAT,
                           D1, D2, D3, INDEXLOCAL, CANTUM1, DEN_OBIECT, RELATIEUM1, DENUM, PARITATE, CODUM, CODUMSPEC)
  SELECT NMAT.CODNORMEMAT, NMAT.CODNORMA, NMAT.CODPRODCOMP, NMAT.CODOBIECT, NMAT.CANT, NMAT.PRET, NMAT.CODMAT,
         NMAT.D1, NMAT.D2, NMAT.D3, NMAT.INDEXLOCAL, NMAT.CANTUM1, OBJ.DENUMIRE, ART.RELATIEUM1, NUM.DEN_UM, 1, ART.UM, ART.UM1
  FROM NORMEMAT NMAT
       INNER JOIN PRODNORME N ON N.CODNORMA = NMAT.CODNORMA
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NMAT.CODOBIECT
       INNER JOIN NART ART ON ART.CODARTICOL = OBJ.CODARTICOL
       INNER JOIN NUM ON ART.UM = NUM.CODUM
  WHERE NMAT.CODPRODCOMP = RECID;

  insert into tmp_prodmatechiv (codmatechiv, codprodcomp, codmat, codobiect, paritate, ordine, denumire, UM, den_UM)
  select e.codmatechiv, e.codprodcomp, e.codmat, e.codobiect, e.paritate, e.ordine, obj.denumire, a.um, num.den_um
  from prodmatechiv e
       inner join nartobj obj on e.codobiect = obj.codobiect
       inner join nart a on obj.codarticol = a.codarticol
       inner join num on num.codum = a.um
  where codprodcomp = RecId;

  INSERT INTO TMP_PROIECTE (CODPROIECT, VERSIUNE, DURATA, DATAPROIECT, INACTIV, FINALIZAT, BLOCAT, GENERIC, IMPLICIT, OBS1, OBS2, OBS3, OBS4, OBS5, OBS6)
  SELECT P.CODPROIECT, P.VERSIUNE, P.DURATA, P.DATAPROIECT, mod(P.ACTIV + 1,2), NVL(P.FINALIZAT,0), NVL(P.BLOCAT,0), NVL(P.GENERIC,0), NVL(P.IMPLICIT,0),
         P.OBS1, P.OBS2, P.OBS3, P.OBS4, P.OBS5, P.OBS6
  FROM TMP_PRODCOMP PC
       INNER JOIN PROIECTNOD PN ON PN.CODOBIECT = PC.CODOBIECT AND NVL(PN.NODORIGINAL,0) = 0
       INNER JOIN PROIECT P ON PN.CODPROIECT = P.CODPROIECT;

  select count(*) into aCount from tmp_prodgest where nvl(indexlocal, 0) &gt; 0;
  if aCount = 0 then
    for v_rec in (select codprodgest from tmp_prodgest order by codprodgest) loop
      aCount := aCount + 1;
      update tmp_prodgest set indexlocal = aCount where codprodgest = v_rec.codprodgest;
    end loop;
  end if;

  select count(*) into aCount from tmp_prodmat where nvl(indexlocal, 0) &gt; 0;
  if aCount = 0 then
    for v_rec in (select codprodgest from tmp_prodgest) loop
      aCount := 0;
      for v_tmp in (select * from tmp_prodmat where codprodgest = v_Rec.codprodgest order by codmat) loop
        aCount := aCount + 1;
        update tmp_prodmat set indexlocal = aCount where codmat = v_tmp.codmat;
      end loop;
    end loop;
  end if;

  select count(*) into aCount from tmp_prodrez where nvl(indexlocal, 0) &gt; 0;
  if aCount = 0 then
    for v_rec in (select codprodgest from tmp_prodgest) loop
      aCount := 0;
      for v_tmp in (select * from tmp_prodrez where codprodgest = v_Rec.codprodgest order by codrez) loop
        aCount := aCount + 1;
        update tmp_prodrez set indexlocal = aCount where codrez = v_tmp.codrez;
      end loop;
    end loop;
  end if;

  select count(*) into aCount from tmp_prodman where nvl(indexlocal, 0) &gt; 0;
  if aCount = 0 then
    for v_rec in (select codprodgest from tmp_prodgest) loop
      aCount := 0;
      for v_tmp in (select * from tmp_prodman where codprodgest = v_Rec.codprodgest order by codman) loop
        aCount := aCount + 1;
        update tmp_prodman set indexlocal = aCount where codman = v_tmp.codman;
      end loop;
    end loop;
  end if;

  select count(*) into aCount from tmp_prodsdv where nvl(indexlocal, 0) &gt; 0;
  if aCount = 0 then
    for v_rec in (select codprodgest from tmp_prodgest) loop
      for v_tmp in (select * from tmp_prodman where codprodgest = v_Rec.codprodgest order by codman) loop
        aCount := 0;
        for v_tmp1 in (select * from tmp_prodsdv where codprodman = v_tmp.codman order by codsdv) loop
          aCount := aCount + 1;
          update tmp_prodsdv set indexlocal = aCount where codsdv = v_tmp1.codsdv;
        end loop;
      end loop;
    end loop;
  end if;

  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO TIPPREFIX FROM DUAL;
    EXCEPTION WHEN OTHERS THEN TIPPREFIX := &apos;1&apos;;
  END;

  IF TIPPREFIX = &apos;2&apos; THEN
    UPDATE TMP_PRODMAT MAT
    SET
      DEN_OBIECT = NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = MAT.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
    UPDATE TMP_PRODREZ REZ
    SET
      DEN_OBIECT = NVL((SELECT CODEXTERN FROM NARTOBJ O WHERE O.CODOBIECT = REZ.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
  ELSE
  IF TIPPREFIX = &apos;3&apos; THEN
    UPDATE TMP_PRODMAT MAT
    SET
      DEN_OBIECT = NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = MAT.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
    UPDATE TMP_PRODREZ REZ
    SET
      DEN_OBIECT = NVL((SELECT CODINTERN FROM NARTOBJ O WHERE O.CODOBIECT = REZ.CODOBIECT), &apos;&apos;) || &apos;;&apos; || DEN_OBIECT;
  END IF;
  END IF;

  /*for v_rec in (select tu, codman from tmp_prodman order by nrop, detalii) loop
    aDur := v_rec.tu;
    aDurPrec := aDur;
    aPrecI := 0;
    aPrecF := v_rec.tu;
    aCodMan := v_rec.codman;
    Exit;
  end loop;

  for v_rec in (select codman, tu, coalesce(decalaj,4) decalaj, nrop, detalii from tmp_prodman where codman &lt;&gt; aCodMan order by nrop, detalii) loop
    if v_rec.decalaj in (0,1,4) then
      if aDur - aPrecI - aDurPrec &lt; v_Rec.tu * aLotOptim then
        aDur := aPrecF + v_Rec.tu * aLotOptim;
      else
        aDur := aDur + v_Rec.tu * aLotOptim;
        update tmp_prodman set incepere = aPrecF where codman = v_rec.codman;
      end if;
      update tmp_prodman set incepere = aPrecF where codman = v_rec.codman;
      aPrecI := aPrecI + aDurPrec;
      aPrecF := aPrecF + v_Rec.tu * aLotOptim;
    else if v_Rec.decalaj = 2 then
      update tmp_prodman set incepere = aPrecI where codman = v_rec.codman;
      if aDurPrec &lt; v_rec.TU * aLotOptim then
        aDur := aDur - aDurPrec + v_rec.TU * aLotOptim;
      end if;
      aPrecF := aPrecI + v_rec.TU * aLotOptim;
    else if v_rec.decalaj = 3 then
      if aDur &lt; v_rec.TU * aLotOptim then
        update tmp_prodman set incepere = incepere + v_rec.TU * aLotOptim - aDur where nrop &lt; v_rec.nrop;
        update tmp_prodman set incepere = incepere + v_rec.TU * aLotOptim - aDur where nrop = v_rec.nrop and detalii &lt; v_rec.detalii;
        aDur := v_rec.TU * aLotOptim;
        aPrecI := 0;
        aPrecF := v_rec.TU * aLotOptim;
      else
        aPrecI := aDur - v_rec.TU * aLotOptim;
        update tmp_prodman set incepere = aPrecI where codman = v_rec.codman;
      end if;
    end if;end if;end if;
    aDurPrec := v_Rec.tu * aLotOptim;
  end loop;*/
  PKG_CFGTABLES.EXT_GOTORECORD(504);
  IF DoCommit THEN
    COMMIT;
  END IF;
END;

function PrjFExists(aCodProdComp in number) return number is
aCount number(10);
begin
  select count(c1.codcomanda1) into aCount
  from proiectnod pn
       inner join comanda1 c1 on pn.codproiect = c1.codproiect
  where pn.codreteta = aCodProdComp;
  if acount = 0 then
    select count(l1.codlivr1) into aCount
    from proiectnod pn
         inner join livr1 l1 on pn.codproiect = l1.codproiect
    where pn.codreteta = aCodProdComp;
  end if;
  return aCount;
end;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCodProdMan number(20);
vCodProdGest number(20);
vCodMat number(20);
vCod number(20);
aDataDoc DATE;
aDoc     VARCHAR2(500);
aCant number(20,7);
aCantIni number(20,7);
aCodObiect number(20);
aTip number(10);
OldGeneric number(1);
NewGeneric number(1);
aCodProiect number(20);
aCount number(10);
aCount1 number(10);
aClonare number(10);
aCodUtilizare number(20);
aCodObjNou number(20);
aCodObjVechi number(20);
aGenPrj number(10);

  procedure CheckRetCentr(aCod in number) is
  acount number(10);
  acount1 number(10);  
  begin
    select count(*) into aCount from tmp_prodmat;
    select count(*) into aCount1
    from prodmat m
         inner join tmp_prodmat tm on tm.codobiect = m.codobiect and tm.cant = m.cant
    where m.codprodcomp = acod;
    if aCount &lt;&gt; aCount1 then 
      update prodcomp pc
      set codproiect = null
      where pc.codproiect &gt; 0 and
            exists (select pn.codreteta from proiectnod pn where pn.codreteta = aCod and pn.codproiect = pc.codproiect);
    end if;  
  end;  

BEGIN
  aGenPrj := To_Number(Pkg_Categconst.GetValConstanta(&apos;ImpRetGenPrj&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru));
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (504); 
  if Operation &lt;&gt; 0 and vFromImport &gt; 0 then
    if aGenPrj = 1 then
      insert into tmp_manevra_liste(filtru, valoare, filtru1)
      select &apos;CODMAT&apos;, TO_CHAR(CODMAT), RETETA
      FROM TMP_PRODMAT
      WHERE LENGTH(TRIM(RETETA)) &gt; 0;
    end if;  
    select count(*) into aCount from tmp_prodmat;
    for v_rec in (
      select pc.codprodcomp 
      from prodcomp pc
           inner join tmp_prodcomp t on t.codobiect = pc.codobiect and pc.cant = t.cant
    ) loop
      select count(*) into aCount1
      from prodmat m
           inner join tmp_prodmat tm on tm.codobiect = m.codobiect and tm.cant = m.cant
      where m.codprodcomp = v_rec.codprodcomp;
      if aCount = aCount1 then 
        RecID := v_rec.codprodcomp;
        Exit;
      end if;  
    end loop;
    if RecID &gt; 0 then return; end if;
  end if;
  
  SELECT
    DATA,
    &apos;OBJ:&apos;||DEN_OBIECT||&apos; VER:&apos;||OBS||&apos; (&apos;||CODPRODCOMP||&apos;)&apos;
  INTO
    aDATADOC,
    ADOC
  FROM TMP_PRODCOMP;

  if Operation = 0 then
    SELECT CodProdComp, Cant, CodObiect INTO RecId, aCant, aCodObjNou FROM Tmp_ProdComp;
    aClonare := PrjFExists(RecID);
    if aClonare &gt; 0 and To_Number(Pkg_Categconst.GetValConstanta(&apos;RetPrjModif&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru)) &lt;&gt; 1 then
      update prodcomp set ascuns = 1, implicit = 0, generic = 0 where codprodcomp = RecID;
      aCodUtilizare := RecID;
      select CodObiect into aCodObjVechi from prodcomp where codprodcomp = RecID;
    end if;
    select cant into aCantIni from prodcomp where codprodcomp = recid;
    CheckRetCentr(RecID);
  end if;
  
  if aClonare &gt; 0 and To_Number(Pkg_Categconst.GetValConstanta(&apos;RetPrjModif&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru)) = 1 then aClonare := 0; end if;

  if Operation = 0 and (aClonare = 0) then
    select cant into aCantIni from prodcomp where codprodcomp = recid;

    if aCant &lt;&gt; aCantIni then
      update proiectnod set cant = aCant where codreteta = RecId and coalesce(nodoriginal,0) = 0;
      for v_rec in (select pn0.cant cantnod, pc.cant cantreteta, pn.codproiectnod
                    from proiectnod pn
                         inner join proiectnod pn0 on pn.nodoriginal = pn0.codproiectnod
                         inner join prodcomp pc on pn0.codreteta = pc.codprodcomp
                    where pn.codreteta = recid and pn.nodoriginal &gt; 0
                   ) loop
        update proiectnod set cant = aCant * v_rec.cantnod / v_rec.cantreteta where codproiectnod = v_rec.codproiectnod;
      end loop;
    end if;

    select generic into NewGeneric from tmp_prodcomp;
    select generic into OldGeneric from prodcomp where CodProdComp = RecId;

    if NewGeneric = 1 and OldGeneric = 0 then
      select nvl(CodProiect,0) into aCodProiect from tmp_prodcomp;
      if aCodProiect &gt; 0 then
        update proiect set generic = 1 where CodProiect = aCodProiect;
      end if;
    end if;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    update prodcomp set (CODOBIECT, HFactor, OBS, DATA, ANULAT, BLOCAT, OPERAT, CANT, D1, D2, D3, TIPRETETA, CANTUM1, COEFINDIRECTE, PRET, IMPLICIT, DESCRIERE, INACTIV, GEST, IDENTIFICATOR, DATADOCUMENTATIE, ARHIVA, OBSERVATII, PROIECTANT, CodClasaProd, INVIZIBILA, GENERIC, TipPret, durata,
                         valmat, valman, valregie, codproiect, Obs1, Obs2, Obs3, Obs4, Obs5, Obs6, CodMoneda, PretValuta,
                         AG, ValAG, Profit, ValProfit, PretFinal, VALPROFITV, PRETFINALV, TOTPRETCOEF, TOTPRETFIX, TOTPRETCOEFV, TOTPRETFIXV,
                         valregieman, nohfactor )
                      = (select CODOBIECT, HFactor, OBS, DATA, ANULAT, BLOCAT, OPERAT, CANT, D1, D2, D3, TIPRETETA, CANTUM1, COEFINDIRECTE, PRET, IMPLICIT, DESCRIERE, INACTIV, GEST, IDENTIFICATOR, DATADOCUMENTATIE, ARHIVA, OBSERVATII, PROIECTANT, CodClasaProd, Invizibila, GENERIC, TipPret, durata,
                                valmat, valman, valregie, codproiect, Obs1, Obs2, Obs3, Obs4, Obs5, Obs6, CodMoneda, PretValuta,
                                AG, ValAG, Profit, ValProfit, PretFinal, VALPROFITV, PRETFINALV, TOTPRETCOEF, TOTPRETFIX, TOTPRETCOEFV, TOTPRETFIXV,
                                valregieman, nohfactor
                         from tmp_prodcomp) where codprodcomp = RecId;

    for v_rec in (select pg.codprodgest,
                         (select min(pg.codprodgest) from prodgest p where p.codprodcomp = pg.codprodcomp
                          and exists (select pm.codmat from prodmat pm where pm.codprodgest = p.codprodgest)
                         ) codprodgestnou
                  from prodgest pg 
                  where pg.codprodcomp = RecId and not exists (select tmp_PG.codprodgest from tmp_prodgest tmp_pg where tmp_pg.codprodgest = pg.codprodgest)
                 ) loop
      update prodmat set codprodgest = v_rec.codprodgestnou where codprodgest = v_rec.codprodgest;
      delete prodgest where codprodgest = v_rec.codprodgest;
    end loop;             
    
    for v_Rec in (select * from tmp_prodgest) loop
      if v_Rec.Codprodgest &gt; 0 then
        update prodgest set
        IndexLocal = v_Rec.Indexlocal,
        CodGest = v_Rec.Codgest,
        CoefMat = v_rec.coefmat,
        CoefMan = v_rec.coefman,
        TimpEst = v_rec.Timpest
        where codprodgest = v_Rec.Codprodgest;
      else
        select seq_prodgest_codprodgest.nextval into vCodProdGest from dual;
        insert into prodgest (codprodgest, codprodcomp, IndexLocal, codgest, CoefMat, CoefMan, TimpEst)
        values (vCodProdGest, v_Rec.Codprodcomp, v_Rec.IndexLocal, v_Rec.Codgest, v_rec.coefmat, v_rec.coefman, v_rec.TimpEst);

        update tmp_prodmat set
          codprodgest = vCodProdGest
        where codprodgest = v_rec.codprodgest;

        update tmp_prodman set
          codprodgest = vCodProdGest
        where codprodgest = v_rec.codprodgest;

        update tmp_prodrez set
          codprodgest = vCodProdGest
        where codprodgest = v_rec.codprodgest;
      end if;
    end loop;

    delete prodman pm where pm.codprodcomp = RecId and not exists (select tmp_pm.codman from tmp_prodman tmp_pm where tmp_pm.codman = pm.codman);
    for v_rec in (select * from tmp_prodman order by nrop) loop
      if v_Rec.codman &gt; 0 then
        update prodman set
          nrop        = v_rec.nrop,
          codop       = v_Rec.codop,
          codloc      = v_rec.codloc,
          codtarif    = v_rec.codtarif,
          tu          = v_rec.tu,
          valoare     = nvl(v_Rec.valoare, 0),
          CodProdGest = v_Rec.codprodgest,
          DSV         = v_Rec.DSV,
          BPS         = v_Rec.BPS,
          TPI         = nvl(v_rec.TPI, 0),
          Obs         = v_rec.obs,
          Detalii     = v_rec.Detalii,
          Fix         = v_rec.Fix,
          Nivel       = v_rec.nrop,
          decalaj     = v_rec.decalaj,
          incepere    = v_rec.incepere,
          coefbps     = v_rec.coefbps
        where codman  = v_Rec.codman;
      else
        select seq_prodman_codman.nextval into vCodProdMan from dual;
        insert into prodman ( codman, codprodcomp, nrop, codop, codloc, codtarif, tu, valoare, CodProdGest, DSV, BPS, TPI, Obs, Detalii, Fix, Nivel, Decalaj, Incepere,
                              coefbps)
        values (vCodProdMan, RecId, v_rec.nrop, v_rec.codop, v_Rec.codloc, v_Rec.codtarif, v_Rec.tu, v_Rec.valoare, v_Rec.CodProdGest, v_Rec.DSV, v_Rec.BPS,
                v_Rec.TPI, v_Rec.Obs, v_rec.Detalii, v_rec.Fix, v_rec.nrop, v_rec.decalaj, v_rec.Incepere, v_rec.coefbps);
        update tmp_prodsdv set
          codprodman = vCodProdMan
        where codprodman = v_rec.codman;

        update tmp_prodmat set
          codman = vCodProdMan
        where codman = v_rec.codman;
      end if;
    end loop;

    for v_rec in (select * from prodmat pm
                  where pm.codprodcomp = RecId and
                        not exists (select tmp_PM.codmat from tmp_prodmat tmp_pm where tmp_pm.codmat = pm.codmat)) loop
      delete prodmat pm where pm.codmat = v_rec.codmat;
      for v_xxx in (select indexparinte, codproiect from proiectnod where codprodmat = v_rec.codmat) loop
        delete nodechiv ne where exists (select pn.codproiectnod from proiectnod pn where instr(pn.indexparinte,v_xxx.IndexParinte) &gt; 0 and pn.CodProiect = v_xxx.CodProiect and ne.codproiectnod = pn.codproiectnod);
        delete proiectnod pn where instr(pn.indexparinte,v_xxx.IndexParinte) &gt; 0 and CodProiect = v_xxx.CodProiect;
      end loop;
    end loop;
    for v_rec in (select * from tmp_prodmat) loop
      if v_Rec.Codmat &gt; 0 then
        begin
          select cant, codobiect, tip into aCant, aCodObiect, aTip from prodmat where codmat = v_rec.codmat;
        exception when others then
          aCant := v_rec.cant;
          aCodObiect := v_rec.CodObiect;
          aTip := v_rec.tip;
        end;
        if not (round(aCant,7) &lt;&gt; round(v_rec.Cant,7) and aCodObiect = v_rec.CodObiect and aTip = v_rec.tip) then
          if not (round(aCant,7) = round(v_rec.Cant,7) and aCodObiect = v_rec.CodObiect and aTip = v_rec.tip) then
            for v_xxx in (select indexparinte, codproiect from proiectnod where codprodmat = v_rec.codmat) loop
              if v_rec.Tip in (3,4,5) then
                delete nodechiv ne where exists (select pn.codproiectnod from proiectnod pn where instr(pn.indexparinte,v_xxx.IndexParinte) &gt; 0 and pn.CodProiect = v_xxx.CodProiect and ne.codproiectnod = pn.codproiectnod);
                delete proiectnod pn where instr(pn.indexparinte,v_xxx.IndexParinte) &gt; 0 and CodProiect = v_xxx.CodProiect and CodProdMat &lt;&gt; v_rec.codmat;
              end if;
            end loop;
          end if;
        else
          for v_xxx in (select indexparinte, codproiect from proiectnod where codprodmat = v_rec.codmat) loop
            if v_rec.Tip in (3,4,5) then
              delete proiectnod pn where instr(pn.indexparinte,v_xxx.IndexParinte) &gt; 0 and CodProiect = v_xxx.CodProiect and CodProdMat &lt;&gt; v_rec.codmat;
            end if;
          end loop;
        end if;
        update prodmat set
          CODOBIECT = v_rec.CODOBIECT,
          CANT = v_rec.cant,
          PRET = v_rec.pret,
          PRETV = v_rec.pretv,
          D1   = v_rec.d1,
          D2   = v_rec.d2,
          D3   = v_rec.d3,
          CopyD1   = v_rec.Copyd1,
          CopyD2   = v_rec.Copyd2,
          CopyD3   = v_rec.Copyd3,
          IndexLocal = v_rec.indexlocal,
          CantUM1    = v_rec.CantUM1,
          CodProdGest    = v_rec.codprodgest,
          Tip        = v_rec.tip,
          Obs        = v_rec.Obs,
          CodAtribut = v_rec.codatribut,
          AddDim     = v_rec.AddDim,
          AddDim_Transp = v_rec.AddDim_transp,
          PretOrig   = v_rec.pretorig,
          ProcReal   = v_rec.ProcReal,
          Valoare    = v_rec.Valoare,
          CodReteta  = v_rec.CodReteta,
          CodMan     = v_rec.CodMan,
          ETAPA      = V_REC.ETAPA,
          PRINCIPAL  = V_REC.PRINCIPAL,
          CONSUM     = V_REC.CONSUM
        where codmat = v_rec.codmat;
        update proiectnod set
          Cant      = v_rec.Cant/aCant*Cant,
          CodObiect = v_rec.CodObiect,
          Tip       = case when v_rec.tip in (3,4) then 3 when v_rec.tip = 5 then 5 else 1 end
        where codprodmat = v_rec.CodMat;
        PropagaParitateCantInAdancime(v_rec.CodMat, v_rec.Cant);
      else
        select seq_prodmat_codmat.nextval into vCodMat from dual;
        update tmp_prodmatechiv set codmat = vCodMat where CodMat = v_rec.codmat;
        update tmp_normemat set codmat = vCodMat where CodMat = v_rec.codmat;
        if aGenPrj = 1 then
          update tmp_manevra_liste set valoare = to_char(vCodMat) where filtru = &apos;CODMAT&apos; and valoare = to_char(v_rec.codmat);
        end if;  
        insert into prodmat (CODMAT, CODPRODCOMP, CODOBIECT, CANT, PRET, PRETV, D1, D2, D3, CopyD1, CopyD2, CopyD3, Indexlocal, CantUM1, CodProdGest, Tip, Obs, codatribut, adddim, adddim_transp, pretorig, ProcReal,
                             Valoare, CodReteta,CodMan, ETAPA, PRINCIPAL, CONSUM)
        values (vCodMat,RecId,v_rec.CODOBIECT, v_rec.CANT, v_Rec.PRET, v_Rec.PRETV, v_Rec.D1, v_Rec.D2, v_Rec.D3, v_Rec.CopyD1, v_Rec.CopyD2, v_Rec.CopyD3, v_rec.IndexLocal, v_rec.CantUM1, v_rec.CodProdGest, v_Rec.Tip, v_rec.Obs, v_rec.codatribut,
                v_rec.adddim, v_rec.adddim_transp, v_rec.pretorig, v_rec.ProcReal, v_rec.Valoare, v_rec.CodReteta,v_rec.CodMan, V_REC.ETAPA, V_REC.PRINCIPAL, V_REC.CONSUM);

        for v_tmp in (select pn.CODPROIECTNOD,pn.CODPROIECT,pn.CANT,pn.NODORIGINAL,pn.POZITIE,pn.CODRETETA,pn.TIP,pn.CODOBIECT,pn.INDEXPARINTE,pn.CODPRODMAT,pn.NIVEL,pn.ORDINE,nvl(pnm.maxpoz,1) maxpoz
                      from proiectnod pn
                           left join (select max(pozitie)+1 maxpoz, nodoriginal from proiectnod group by nodoriginal) pnm on pnm.nodoriginal = pn.codproiectnod
                      where pn.codreteta = recid
                     ) loop
          select cant into aCant from tmp_prodcomp;
          insert into proiectnod(
            codproiectnod,
            codproiect,
            cant,
            nodoriginal,
            pozitie,
            codreteta,
            tip,
            codobiect,
            indexparinte,
            codprodmat,
            nivel,
            ordine)
          values (
            seq_proiectnod_codproiectnod.nextval,
            v_tmp.codproiect,
            v_tmp.cant/aCant*v_rec.cant,
            v_tmp.codproiectnod,
            v_tmp.maxpoz,
            0,
            case when v_rec.tip in (3,4) then 3 when v_rec.tip = 5 then 5 else 1 end,
            v_rec.codobiect,
            trim(v_tmp.indexparinte)||&apos;.&apos;||lpad(to_char(v_tmp.maxpoz), 2,&apos;0&apos;),
            vCodMat,
            v_tmp.nivel + 1,
            0
            );
        end loop;
      end if;
    end loop;

    delete prodmatechiv pe where pe.codprodcomp = RecId and not exists (select tmp.CodMatEchiv from tmp_prodmatechiv tmp where tmp.codmatechiv = pe.codmatechiv);
    for v_rec in (select * from tmp_prodmatechiv) loop
      if v_Rec.codmatechiv &gt; 0 then
        update prodmatechiv set
          codobiect = v_Rec.Codobiect,
          paritate  = v_Rec.paritate,
          ordine    = v_rec.ordine
        where codmatechiv = v_Rec.codmatechiv;
      else
        insert into prodmatechiv (codmatechiv, codprodcomp, codmat, codobiect, paritate, ordine)
        values (seq_prodmatechiv_codmatechiv.nextval, RecId, v_rec.CodMat, v_rec.CodObiect, v_Rec.Paritate, v_Rec.Ordine);
      end if;
    end loop;

    delete prodrez pr where pr.codprodcomp = RecId and not exists (select tmp_Pr.codrez from tmp_prodrez tmp_pr where tmp_pr.codrez = pr.codrez);
    for v_rec in (select * from tmp_prodrez) loop
      if v_Rec.Codrez &gt; 0 then
        update prodrez set
          CODOBIECT = v_rec.CODOBIECT,
          CANT = v_rec.cant,
          PRET = v_rec.pret,
          D1   = v_rec.d1,
          D2   = v_rec.d2,
          D3   = v_rec.d3,
          IndexLocal = v_rec.indexlocal,
          Reziduu    = v_rec.reziduu,
          CantUM1    = v_rec.CantUM1,
          CodProdGest    = v_Rec.Codprodgest,
          Obs        = v_rec.Obs
        where codrez = v_rec.codrez;
      else
        insert into prodrez (CODREZ, CODPRODCOMP, CODOBIECT, CANT, PRET, D1, D2, D3, IndexLocal, Reziduu, CantUM1, CODPRODGEST, Obs)
        values (seq_prodREZ_codrez.nextval,RecId,v_rec.CODOBIECT, v_rec.CANT, v_Rec.PRET, v_Rec.D1, v_Rec.D2, v_Rec.D3, v_Rec.IndexLocal,
                v_Rec.Reziduu, v_rec.CantUM1, v_rec.CodProdGest, v_rec.Obs);
      end if;
    end loop;

    delete tmp_prodmas
    where nvl(codprodgest,0) = 0 and descriere is null
          and frecventa is null and metoda is null
          and nvl(codobiect,0) = 0;

    delete prodmas ps where ps.codprodcomp = RecId and not exists (select tmp_Ps.codprodmas from tmp_prodmas tmp_ps where tmp_ps.codprodmas = ps.codprodmas);
    for v_rec in (select * from tmp_prodmas) loop
      if v_Rec.CodProdMas &gt; 0 then
        update prodmas set
        descriere   = v_Rec.Descriere,
        frecventa   = v_rec.frecventa,
        metoda      = v_Rec.Metoda,
        codobiect   = v_Rec.Codobiect,
        indexlocal  = v_Rec.Indexlocal
        where codprodmas = v_rec.codprodmas;
      else
        insert into prodmas (codprodmas, codprodcomp, descriere, frecventa, metoda, codobiect, indexlocal)
        values (seq_prodmas_codprodmas.nextval,RecId, v_Rec.descriere, v_Rec.frecventa, v_Rec.metoda, v_Rec.codobiect, v_rec.indexlocal);
      end if;
    end loop;

    delete prodsdv sdv where sdv.codprodcomp = recid and codprodsdv not in (select codprodsdv from tmp_prodsdv);
    for v_rec in (select * from tmp_prodsdv) loop
      if v_Rec.Codprodsdv &gt; 0 then
        update prodsdv set
          CODPRODMAN  = v_Rec.Codprodman,
          INDEXLOCAL  = v_Rec.Indexlocal,
          CODSDV      = v_Rec.Codsdv,
          CODGENERIC  = v_Rec.Codgeneric,
          CANT        = v_Rec.Cant,
          PRET        = v_Rec.Pret
        where codprodsdv = v_rec.codprodsdv;
      else
        insert into prodsdv (codprodsdv, codprodman, indexlocal, codsdv, codgeneric, cant, pret, codprodcomp)
        values (seq_prodsdv_codprodsdv.nextval, v_Rec.codprodman, v_Rec.indexlocal, v_Rec.codsdv, v_Rec.codgeneric, v_Rec.cant, v_Rec.pret, RecId);
      end if;
    end loop;

    delete normemat nmat where nmat.codprodcomp = recid and codnormemat not in (select codnormemat from tmp_normemat);
    delete prodnorme nor where nor.codprodcomp = recid and codnorma not in (select codnorma from tmp_prodnorme);
    for v_rec in (select * from tmp_prodnorme) loop
      if v_Rec.CodNorma &gt; 0 then
        update prodnorme set
          norma  = v_Rec.norma,
          indexlocal = v_rec.indexlocal,
          implicit = v_rec.implicit,
          ACTIV = V_REC.ACTIV,
          DATAACTIV = V_REC.DATAACTIV,
          DATAINACTIV = V_REC.DATAINACTIV
        where codnorma = v_rec.codnorma;
      else
        select seq_prodnorme_codnorma.nextval into vCod from dual;
        update tmp_normemat set codnorma = vcod where codnorma = v_rec.codnorma;
        insert into prodnorme (codnorma, codprodcomp, norma, indexlocal, implicit,activ,dataactiv,datainactiv)
        values (vCod, RecId, v_rec.norma, v_rec.indexlocal, v_rec.implicit,v_rec.activ,v_rec.dataactiv,v_rec.datainactiv);
      end if;
    end loop;

    for v_rec in (select * from tmp_normemat) loop
      if v_Rec.Codnormemat &gt; 0 then
        update normemat set
          codnorma    = v_rec.codnorma,
          codprodcomp = v_rec.codprodcomp,
          codobiect   = v_rec.codobiect,
          cant        = v_rec.cant,
          pret        = v_rec.pret,
          d1          = v_rec.D1,
          d2          = v_rec.D2,
          d3          = v_rec.D3,
          indexlocal  = v_rec.Indexlocal,
          cantum1     = v_rec.cantum1,
          codmat      = v_rec.codmat
        where codnormemat = v_rec.codnormemat;
      else
        insert into normemat(codnormemat, codnorma, codprodcomp, codobiect, cant, pret, D1, D2, D3, indexlocal, cantum1,codmat)
        values (seq_normemat_codnormemat.nextval, v_Rec.codnorma, recid, v_rec.codobiect, v_rec.cant, v_rec.pret,
                v_rec.d1, v_rec.d2, v_rec.d3, v_rec.indexlocal, v_rec.cantum1,v_rec.codmat);
      end if;
    end loop;

  ELSE  -- INSERT
    vcod := recid;
    SELECT seq_prodcomp_codprodcomp.NextVal INTO RecId FROM DUAL;
    
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;PRODCOMP&apos;, RecId); 
    
    if vcod &gt; 0 then
    --propag arhiva
    insert into documente(coddocument,
                          coddoc,
                          tipdoc,
                          filename,
                          doc,
                          obs,
                          userid,
                          datacreare,
                          coddosar,
                          coddepozit,
                          tipdocument)
    select 
                          seq_documente_coddocument.nextval,
                          RecId,
                          tipdoc,
                          filename,
                          doc,
                          obs,
                          userid,
                          datacreare,
                          coddosar,
                          coddepozit,
                          tipdocument 
    from documente where coddoc = vcod and tipdoc = 504;
    end if;
    
    SELECT
      &apos;OBJ:&apos;||DEN_OBIECT||&apos; VER:&apos;||OBS||&apos; (&apos;||RecId||&apos;)&apos;
    INTO
      ADOC
    FROM TMP_PRODCOMP;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PRODCOMP&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID, PKG_GLOBALS.FIRMANAME, PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO PRODCOMP (CodProdComp, CODOBIECT, HFactor, OBS, DATA, ANULAT, BLOCAT, OPERAT, CANT, D1, D2, D3, TIPRETETA, CANTUM1, COEFINDIRECTE, PRET, IMPLICIT,
    DESCRIERE, INACTIV, GEST, IDENTIFICATOR, DATADOCUMENTATIE, ARHIVA, OBSERVATII, PROIECTANT, CodClasaProd, Invizibila,
    TipPret, GENERIC, durata, userid, Datacreare, valmat, valman, valregie, Obs1, Obs2, Obs3, Obs4, Obs5, Obs6, Codmoneda, Pretvaluta,
    AG, ValAG, Profit, ValProfit, PretFinal, VALPROFITV, PRETFINALV, TOTPRETCOEF, TOTPRETFIX, TOTPRETCOEFV, TOTPRETFIXV,valregieman,nohfactor)
    (SELECT RecId,CODOBIECT, HFactor, OBS, DATA, ANULAT, BLOCAT, OPERAT, CANT, D1, D2, D3, TIPRETETA, CANTUM1, COEFINDIRECTE, PRET, IMPLICIT,
    DESCRIERE, INACTIV, GEST, IDENTIFICATOR, DATADOCUMENTATIE, ARHIVA, OBSERVATII, PROIECTANT, CodClasaProd, Invizibila,
    TipPret, GENERIC, durata, PKG_GLOBALS.USERID,SYSTIMESTAMP, valmat, valman, valregie, Obs1, Obs2, Obs3, Obs4, Obs5, Obs6, CodMoneda, PretValuta,
    AG, ValAG, Profit, ValProfit, PretFinal, VALPROFITV, PRETFINALV, TOTPRETCOEF, TOTPRETFIX, TOTPRETCOEFV, TOTPRETFIXV,valregieman,nohfactor
    FROM tmp_PRODCOMP);

    for v_Rec in (select * from tmp_prodgest) loop
      select seq_prodgest_codprodgest.nextval into vCodProdGest from dual;

      INSERT INTO PRODGEST (CODPRODGEST, CODPRODCOMP, INDEXLOCAL, CODGEST, COEFMAT, COEFMAN, TIMPEST)
      values (vCodProdGest, RecId, v_Rec.INDEXLOCAL, v_Rec.CODGEST, v_rec.CoefMat, v_rec.CoefMan, V_REC.TIMPEST);

      update tmp_prodmat set
        codprodgest = vCodProdGest
      where codprodgest = v_rec.codprodgest;

      update tmp_prodman set
        codprodgest = vCodProdGest
      where codprodgest = v_rec.codprodgest;

      update tmp_prodrez set
        codprodgest = vCodProdGest
      where codprodgest = v_rec.codprodgest;
    end loop;

    for v_Rec in (select * from tmp_prodman) loop
      select seq_prodman_codman.NextVal into vCodProdMan from dual;
      update tmp_prodsdv
        set codprodman = vCodProdMan
      where codprodman = v_Rec.Codman;
      update tmp_prodmat
        set codman = vCodProdMan
      where codman = v_Rec.Codman;

      INSERT INTO PRODMAN (CODMAN, CODPRODCOMP, NROP, CODOP, CODLOC, CODTARIF, TU, VALOARE, CODPRODGEST, DSV, BPS, TPI, OBS, Detalii, Fix, Nivel, Decalaj,
                           INCEPERE, COEFBPS)
      values( vCodProdMan,
              RecId,
              v_Rec.NROP,
              v_Rec.CODOP,
              v_Rec.CODLOC,
              v_Rec.CODTARIF,
              v_Rec.TU,
              v_Rec.VALOARE,
              v_Rec.CODPRODGEST,
              v_rec.DSV,
              v_rec.BPS,
              nvl(v_rec.TPI, 0), v_rec.OBS, v_rec.Detalii, v_rec.Fix, v_rec.NROP, v_rec.decalaj, v_rec.incepere,
              v_rec.coefbps);
    end loop;

    for v_rec in (select * from tmp_prodmat) loop
      select seq_prodmat_CODMAT.Nextval into vCodMat from dual;
      update tmp_prodmatechiv set codmat = vCodMat where CodMat = v_rec.CodMat;
      update tmp_normemat set codmat = vCodMat where CodMat = v_rec.codmat;
      if aGenPrj = 1 then
        update tmp_manevra_liste set valoare = to_char(vCodMat) where filtru = &apos;CODMAT&apos; and valoare = to_char(v_rec.codmat);
      end if;  
      INSERT INTO PRODMAT (CODMAT, CODPRODCOMP, CODOBIECT, CANT, PRET, PRETV, D1, D2, D3, CopyD1, CopyD2, CopyD3, IndexLocal, CantUM1, CodProdGest, Tip, Obs, codatribut,
                           adddim, adddim_transp, pretorig, ProcReal, Valoare, CodReteta, CodMan, ETAPA, PRINCIPAL, CONSUM)
      values (vCodMat, RecId, v_rec.CODOBIECT, v_rec.CANT, v_rec.PRET, v_rec.PRETV, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.CopyD1, v_rec.CopyD2, v_rec.CopyD3, v_rec.IndexLocal, v_rec.CantUM1, v_rec.CodProdGest, v_rec.Tip, v_rec.Obs, v_rec.codatribut,
              v_rec.adddim, v_rec.adddim_transp, v_rec.pretorig, v_rec.ProcReal, v_rec.Valoare, v_rec.CodReteta,v_rec.CodMan, V_REC.ETAPA, V_REC.PRINCIPAL, V_REC.CONSUM);
    end loop;

    insert into prodmatechiv (codmatechiv, codprodcomp, codmat, codobiect, paritate, ordine)
    select seq_prodmatechiv_codmatechiv.nextval, RecId, CodMat, CodObiect, Paritate, Ordine
    from tmp_prodmatechiv;

    INSERT INTO PRODREZ (CODREZ, CODPRODCOMP, CODOBIECT, CANT, PRET, D1, D2, D3, IndexLocal, Reziduu, CantUM1, CodProdGest, Obs)
    (SELECT seq_prodrez_CODREZ.Nextval, RecId, CODOBIECT, CANT, PRET, D1, D2, D3, IndexLocal, Reziduu, CantUM1, CodProdGest, Obs
     FROM tmp_PRODREZ);

    delete tmp_prodmas
    where nvl(codprodgest,0) = 0 and descriere is null
          and frecventa is null and metoda is null
          and nvl(codobiect,0) = 0;
    insert into prodmas (codprodmas, codprodcomp, descriere, frecventa, metoda, codobiect, indexlocal )
    select seq_prodmas_codprodmas.nextval, RecId, descriere, frecventa, metoda, codobiect, indexlocal
    from tmp_prodmas;

    INSERT into prodsdv (codprodsdv, codprodman, indexlocal, codsdv, codgeneric, cant, pret, codprodcomp)
    select seq_prodsdv_codprodsdv.nextval, codprodman, indexlocal, codsdv, codgeneric, cant, pret, RecId from tmp_prodsdv;

    for v_rec in (select * from tmp_prodnorme) loop
      select seq_prodnorme_codnorma.nextval into vCod from dual;
      update tmp_normemat set codnorma = vcod where codnorma = v_rec.codnorma;
      insert into prodnorme(codnorma, codprodcomp, norma, indexlocal,implicit,activ,dataactiv,datainactiv)
      values(vCod, recid, v_rec.norma, v_rec.indexlocal,v_rec.implicit,v_rec.activ,v_rec.dataactiv,v_rec.datainactiv);
    end loop;
    insert into normemat(codnormemat, codnorma, codprodcomp, codobiect, cant, pret, D1, D2, D3, indexlocal, cantum1,codmat)
    select seq_normemat_codnormemat.nextval, codnorma, recid, codobiect, cant, pret, D1, D2, D3, indexlocal, cantum1,codmat
    from tmp_normemat;

    if To_Number(Pkg_Categconst.GetValConstanta(&apos;DoNormaImp&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru)) = 1 then
      select count(*) into aCount from prodnorme where implicit = 1 and codprodcomp = recid;
      if aCount = 0 then
        select seq_prodnorme_codnorma.nextval into vCod from dual;
        insert into prodnorme(codnorma, codprodcomp, norma, indexlocal,implicit,activ, dataactiv)
        values(vCod, recid, &apos;Optima&apos;, (select max(indexlocal) + 1 from prodnorme where codprodcomp = recid) ,1, 1, to_date(to_char(sysdate, &apos;dd.mm.yyyy&apos;), &apos;dd.mm.yyyy&apos;));

        insert into normemat(codnormemat, codnorma, codprodcomp, codobiect, cant, pret, D1, D2, D3, indexlocal, cantum1, codmat)
        select seq_normemat_codnormemat.nextval, vcod, recid, codobiect, cant, pret, D1, D2, D3, indexlocal, cantum1, codmat
        from prodmat
        where codprodcomp = recid;
      end if;
    end if;
    if pkg_categconst.GetValConstanta(&apos;InactivGenProdComp&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 then
      update prodcomp set
        inactiv = 1
      where codobiect = (select codobiect from prodcomp where codprodcomp = recid)
            and codprodcomp &lt;&gt; recid;

      select count(*) into aCount
      from prodcomp
      where codobiect = (select codobiect from prodcomp where codprodcomp = recid)
            and codprodcomp &lt;&gt; recid and implicit = 1;
      if aCount &gt; 0 then
        update prodcomp set implicit = 1 where codprodcomp = recid;
        update prodcomp set
          implicit = 0
        where codobiect = (select codobiect from prodcomp where codprodcomp = recid)
              and codprodcomp &lt;&gt; recid;
      end if;

      select count(*) into aCount
      from prodcomp
      where codobiect = (select codobiect from prodcomp where codprodcomp = recid)
            and codprodcomp &lt;&gt; recid and generic = 1;
      if aCount &gt; 0 then
        update prodcomp set generic = 1 where codprodcomp = recid;
        update prodcomp set
          generic = 0
        where codobiect = (select codobiect from prodcomp where codprodcomp = recid)
              and codprodcomp &lt;&gt; recid;
      end if;
    end if;
    if aClonare &gt; 0 then
      update prodcomp set codutilizare = aCodUtilizare where codprodcomp = RecID;
      for v_rec in (select pn.CODPROIECTNOD,pn.CODPROIECT,pn.CANT,pn.INDEXPARINTE,pn.NIVEL
                    from proiectnod pn
                         inner join proiect p on p.codproiect = pn.codproiect
                    where nvl(p.ascuns,0) = 0 and pn.codreteta = aCodUtilizare
                   ) loop
        -- ii recreez
        for v_tmp in (select mat.*, pn.codproiectnod, pn.indexparinte, pn.cant cantnod
                      from (select nvl(mv.codmat,0) codmatvechi, nvl(mn.codmat,0) codmatnou, mv.codobiect, mn.codobiect codobiectnou,
                                   mn.cant, mn.indexlocal, mv.tip, mn.tip tipnou
                            from (select * from prodmat where codprodcomp = aCodUtilizare) mv
                                 full join (select * from prodmat where codprodcomp = RecID) mn on mv.indexlocal = mn.indexlocal
                            ) mat
                           left join proiectnod pn on pn.codprodmat = mat.codmatvechi and pn.codproiect = v_rec.codproiect and pn.nodoriginal = v_rec.codproiectnod
                      order by mat.indexlocal) loop
          if v_tmp.codmatvechi &gt; 0 and v_tmp.codmatnou &gt; 0 then
            if (v_tmp.codobiect &lt;&gt; v_tmp.codobiectnou) or (v_tmp.tip &lt;&gt; v_tmp.tipnou) then
              -- s-a inlocuit obiectul, sterg copiii si actualizez obiectul si cantitatea
              delete proiectnod pn where instr(pn.indexparinte,v_tmp.IndexParinte) &gt; 0 and pn.codproiectnod &lt;&gt; v_tmp.codproiectnod and pn.codproiect = v_rec.codproiect;
              update proiectnod set codobiect = v_tmp.codobiectnou, codprodmat = v_tmp.codmatnou where codproiectnod = v_tmp.codproiectnod;
              update proiectnod set cant = case when v_tmp.tip = 5 then v_tmp.cant else v_rec.cant*v_tmp.Cant/aCant end where codproiectnod = v_tmp.codproiectnod;
            else
              -- nu s-a inlocuit materialul, actualizez cantitatea si actualizez in adancime
              update proiectnod pn set cant = case when v_tmp.tip = 5 then v_tmp.cant else v_rec.cant*v_tmp.Cant/aCant end,
                                       tip = case when v_tmp.tip in (1,2) then 1 when v_tmp.tip = 5 then 5 else 3 end,
                                       codprodmat = v_tmp.codmatnou
              where pn.codproiectnod = v_tmp.codproiectnod;
              if v_tmp.tip &lt; 3 then
                UpdateCantCuParitate(v_tmp.codproiectnod, v_rec.cant*v_tmp.Cant/aCant);
              end if;
              /*for v_xxx in (select pn.codproiectnod, pp.cant cantparinte, pc.cant cantreteta, mat.cant cantmaterial
                            from proiectnod pn
                                 inner join proiectnod pp on pp.codproiectnod = pn.nodoriginal
                                 inner join prodmat mat on mat.codmat = pn.codprodmat
                                 inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
                            where instr(pn.indexparinte,v_tmp.IndexParinte) &gt; 0 and pn.codproiectnod &lt;&gt; v_tmp.codproiectnod
                                  and pn.codproiect = v_rec.codproiect
                           ) loop
                update proiectnod set cant = v_xxx.cantparinte * v_xxx.cantmaterial / v_xxx.cantreteta where codproiectnod = v_xxx.codproiectnod;
              end loop;*/
            end if;
          end if;
          if v_tmp.codmatnou = 0 and v_tmp.codmatvechi &gt; 0 then
            -- nu mai exista un material in reteta noua, il sterg si pe copii
            delete proiectnod pn where instr(pn.indexparinte,v_tmp.IndexParinte) &gt; 0 and pn.codproiect = v_rec.codproiect;
          end if;
          if v_tmp.codmatnou &gt; 0 and v_tmp.codmatvechi = 0 then
            -- inserare material nou
            insert into proiectnod
            (
              codproiectnod,
              codproiect,
              cant,
              nodoriginal,
              pozitie,
              codreteta,
              tip,
              codobiect,
              indexparinte,
              codprodmat,
              nivel,
              ordine
            )
            values
            (
              seq_proiectnod_codproiectnod.nextval,
              v_rec.codproiect,
              case when v_tmp.tip = 5 then v_tmp.cant else v_rec.cant*v_tmp.Cant/aCant end,
              v_rec.codproiectnod,
              v_tmp.indexlocal,
              0,
              case when v_tmp.tip in (1,2) then 1 when v_tmp.tip = 5 then 5 else 3 end,
              v_tmp.codobiectnou,
              trim(v_rec.indexparinte)||&apos;.&apos;||LPAD(to_char(v_tmp.indexlocal), 2,&apos;0&apos;),
              v_tmp.codmatnou,
              v_rec.nivel + 1,
              v_tmp.indexlocal
            );
          end if;
        end loop;
        -- actualizez codreteta
        update proiectnod set codreteta = RecID where codproiectnod = v_rec.codproiectnod;
        update proiect set codutilizare = null where codproiect = v_rec.codproiect;
        /*if aCodObjVechi &lt;&gt; aCodObjNou then
          update proiectnod set codobiect = aCodObjNou where codproiectnod = v_rec.codproiectnod;
        end if;
        if aCant &lt;&gt; aCantIni then
          for v_xxx in (select pn.codproiectnod, pp.cant cantparinte, pc.cant cantreteta, mat.cant cantmaterial
                        from proiectnod pn
                             inner join proiectnod pp on pp.codproiectnod = pn.nodoriginal
                             inner join prodmat mat on mat.codmat = pn.codprodmat
                             inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp
                        where instr(pn.indexparinte,v_rec.IndexParinte) &gt; 0 and pn.codproiectnod &lt;&gt; v_rec.codproiectnod
                              and pn.codproiect = v_rec.codproiect
                       ) loop
            update proiectnod set cant = v_xxx.cantparinte * v_xxx.cantmaterial / v_xxx.cantreteta where codproiectnod = v_xxx.codproiectnod;
          end loop;
        end if;*/
      end loop;
    end if;
  END IF;

  for v_rec in (select RowNum IndexLocal, pm.codmat
                from (select codmat
                      from prodmat
                      where codprodcomp = RecId
                      order by indexlocal) pm
                ) loop
    update prodmat set indexlocal = v_rec.indexlocal where codmat = v_rec.codmat;
  end loop;

  update prodcomp set generic = 0, implicit = 0 where codprodcomp = recid and nvl(anulat,0) = 1;--scot genericul si implicitul la reteta anulata
  PropagaGant(RecID);
  PKG_CFGTABLES.EXT_POSTRECORDS(504);
  IF DoCommit THEN
    COMMIT;
  END IF;
  NotifyModif(Operation, RecId, &apos;PRODCOMP&apos;);
  IF DoCommit THEN
    COMMIT;
  END IF;
end;

procedure PropagaParitateCantInAdancime(aCodMat in number, aCant in number) is
begin
  for v_rec in (select pn.codproiectnod, pn0.cant cantparinte, pc.cant cantreteta, pn.codreteta, pn.codproiect, pn.indexparinte, pn.cant
                from proiectnod pn
                     inner join proiectnod pn0 on pn0.codproiectnod = pn.nodoriginal
                     inner join prodcomp pc on pc.codprodcomp = pn0.codreteta
                where pn.codprodmat = aCodMat
               ) loop
    update proiectnod set cant = v_Rec.cantparinte / v_rec.cantreteta * aCant where codproiectnod = v_rec.codproiectnod;
    if v_rec.codreteta &gt; 0 then
      UpdateCantCuParitate(v_rec.codproiectnod, v_Rec.cantparinte / v_rec.cantreteta * aCant);
    end if;
  end loop;
end;

procedure UpdateCantCuParitate(aCodproiectnod in number, aCant in number) is
begin
  for v_rec in (select pn.codproiectnod, pn0.cant cantparinte, pc.cant cantreteta, pn.codreteta, pn.codproiect, pn.indexparinte, pn.cant, mat.cant cantmat
                from proiectnod pn
                     inner join proiectnod pn0 on pn0.codproiectnod = pn.nodoriginal
                     inner join prodcomp pc on pc.codprodcomp = pn0.codreteta
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                where pn0.codproiectnod = aCodProiectNod) loop
    update proiectnod set cant = aCant / v_rec.cantreteta * v_rec.CantMat where codproiectnod = v_rec.CodProiectnod;
    if v_rec.codreteta &gt; 0 then
      UpdateCantCuParitate(v_rec.codproiectnod, aCant / v_rec.cantreteta * v_rec.CantMat);
    end if;
  end loop;
end;

procedure SetDurataInRetete is
begin
  update prodcomp p set
  durata = (select max(coalesce(p.cant,0)*coalesce(m.tu,0)+coalesce(m.incepere,0))
            from prodman m
            where m.codprodcomp = p.codprodcomp)
  where exists (select valoare from tmp_manevra_liste where valoare = p.codprodcomp and filtru = &apos;CODPRODCOMP&apos;);
end;

procedure GetPreturiOferta(RetGenerica in boolean default False) IS
aPret number(20,7);
begin
  for v_rec in (select * from tmp_manevra_preturi where nvl(pret,0) = 0)
  loop
    aPret := pkg_oferta.GetPretMediuOferte(v_Rec.Codobiect, v_rec.codarticol, retgenerica, v_rec.codatribut, vModGenerice);
    if aPret &lt;&gt; 0 then
      update tmp_manevra_preturi set pret = aPret, Stare = 4 where codobiect = v_rec.codobiect;
    end if;
  end loop;
  commit;
end;

procedure MakeOferta is
aCod number(20);
Inserez boolean;
begin
  Inserez := False;
  select seq_oferta_codoferta.nextval into aCod from dual;
  for v_rec in (select tmp.*, num1.codum1 from tmp_manevra_preturi tmp
                inner join nartobj obj on tmp.codobiect = obj.codobiect
                inner join nart art on art.codarticol = obj.codarticol
                inner join num1 on num1.codum = art.um and nvl(num1.secundara,0) = 0
                where tmp.stare = 3) loop
    if pkg_oferta.ExistaOfertaValabila(v_rec.codobiect) = 0 then
      if not Inserez then
        Inserez := True;
      end if;
      insert into oferta1(codoferta1, codoferta, codobiect, cantmin, UMSec)
      values (seq_oferta1_codoferta1.nextval, aCod, v_rec.codobiect, 1, v_rec.codum1);
    end if;
  end loop;
  if Inserez then
    insert into oferta(codoferta, tipdoc, operat, nrdoc, datastart, dataend, toatesubunit, anulat, blocat)
    values (aCod, 51, 1, 0, to_date(to_char(sysdate, &apos;DD.MM.YYYY&apos;), &apos;DD.MM.YYYY&apos;), to_date(&apos;31.12.2050&apos;, &apos;DD.MM.YYYY&apos;), 1, 0, 0);
  end if;
  commit;
end;

procedure SeteazaStare(aMarja in number) is
ValMarja    number;
PretRef     number;
CateRef     number;
aCate       number;
Marja       number;
begin
  Marja := aMarja/100;
  update tmp_manevra_preturi_Detalii set stare = 3 where nvl(Pret,0) = 0;
  update tmp_manevra_preturi set stare = 3 where nvl(Pret,0) = 0 and Nvl(stare,0) &lt;&gt; 4;

  update tmp_manevra_preturi set stare = 1 where Nvl(Stare,0) &lt; 3;
  for v_rec in (select * from tmp_manevra_preturi where Nvl(Stare,0) &lt; 3)
  loop
    for v_rec_D in (select * from tmp_manevra_preturi_Detalii where CodObiect = v_rec.CodObiect and Nvl(Stare,0) &lt;&gt; 3)
    loop
      PretRef := -1;
      CateRef := 99999999999;
      ValMarja := v_rec_d.Pret*Marja;
      begin
        Select Count(*) into aCate from tmp_manevra_preturi_Detalii
        where CodObiect = v_rec_d.CodObiect and Stare &lt;&gt; 3
              and Abs(v_rec_d.Pret - Pret) &gt; ValMarja;
        EXCEPTION WHEN OTHERS THEN aCate := -1;
      end;
      if aCate &lt;&gt; -1 and aCate &lt; CateRef then
        CateRef := aCate;
        PretRef  := v_rec_d.Pret;
      end if;
    end loop;

    if PretRef &lt;&gt; -1 then
      ValMarja := PretRef*Marja;
      update tmp_manevra_preturi_Detalii set Stare =
      Case when PretRef - Pret= 0 then 4
           when Abs(PretRef - Pret) &gt; ValMarja then 2
           else 1
      end
      where CodObiect = v_rec.CodObiect and Nvl(Stare,0) &lt;&gt; 3;

    end if;
  end loop;
  update tmp_manevra_preturi p set p.Stare = 2
  where nvl(p.Stare, 0) &lt;&gt; 4
        and Exists (select CodObiect from tmp_manevra_preturi_Detalii where CodObiect = p.CodObiect and Stare = 2);
  if DoCommit then
    commit;
  end if;
end;

procedure CurataExtreme(aMarja in number) is
TipPret number(1);
begin
  if aMarja &gt; 0 then PKG_ProdComp.SeteazaStare(aMarja); end if;
  delete from tmp_manevra_preturi_Detalii where Stare = 2;

  TipPret := To_Number(Pkg_Categconst.GetValConstanta(&apos;TipEvaluarePret&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru));
  if TipPret &gt; 3 or TipPret &lt; 1 then TipPret := 2; end if;

  if TipPret = 1 then
    update tmp_manevra_preturi p
    set pret = ( select max(nvl(pret,0))
                 from tmp_manevra_preturi_Detalii where codobiect = p.codobiect
                 group by codobiect)
    where nvl(p.Stare,0) &lt; 3;
  else
    if TipPret = 3 then
      update tmp_manevra_preturi p
      set pret = ( select min(nvl(pret,0))
                   from tmp_manevra_preturi_Detalii where codobiect = p.codobiect
                   group by codobiect)
      where nvl(p.Stare,0) &lt; 3;
    else
      update tmp_manevra_preturi p
      set pret = ( select avg(nvl(pret,0))
                   from tmp_manevra_preturi_Detalii where codobiect = p.codobiect
                   group by codobiect)
      where nvl(p.Stare,0) &lt; 3;
    end if;
  end if;
  commit;
  SeteazaStare(aMarja);
end;

function GetPretDinRetete(aCodObiect in number) return number is
aCountI number(10);
vPret number(20,7);
begin
  select count(codprodcomp) into aCountI from prodcomp where codobiect = acodobiect
  and generic = 1 and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
  if aCountI &gt; 0 then
    select sum(pret*cant)/sum(cant) into vPret from prodcomp
    where codobiect = acodobiect and generic = 1  and nvl(inactiv, 0) = 0
    and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
  else
    select count(codprodcomp) into aCountI from prodcomp
    where codobiect = acodobiect
    and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0 and nvl(invizibila, 0) = 0;
    if aCountI &gt; 0 then
      select sum(pret*cant)/sum(cant) into vPret from prodcomp
      where codobiect = acodobiect  and nvl(invizibila, 0) = 0 and nvl(inactiv, 0) = 0 and nvl(cant,0) &gt; 0;
    end if;
  end if;

  return vPret;
end;

procedure EXEC_DEBUG IS
--aNr number(20);
BEGIN
  --delete prodcomp_clona;
  --delete prodman_clona;
  --delete prodmat_clona;
  --delete tmp_manevra_compusi;
  --delete tmp_manevra_preturi;
  PKG_GLOBALS.SetLunaLucru(2016,1);
  PKG_GLOBALS.SETSUBUNITATE(2);
  --PKG_PRODCOMP.ActualizeazaPret(103);
  delete tmp_manevra_liste;
  insert into tmp_manevra_liste(filtru, valoare)
  select &apos;CODPRODCOMP&apos;, codprodcomp
  from prodcomp;
  ArmeazaTmps(0, true);
  --aNr := ActualizeazaPret(0);
  --UpdateDateRete;
  --PKG_PRODCOMP.SeteazaStare(50);
END;

procedure SavePreturi(modul in number) is
begin
  if modul = 1 then
    delete manevra_preturi;
    delete manevra_preturi_d;
    delete manevra_prodcomp_clona;
    delete manevra_prodman_clona;
    delete manevra_prodmat_clona;
    Insert Into manevra_Preturi ( CODOBIECT, PRET, STARE, CodArticol, CodAtribut)
    (Select codobiect, PRET, STARE, CodArticol, CodAtribut from Tmp_Manevra_Preturi);
    Insert Into Manevra_Preturi_D (Select * from tmp_manevra_preturi_Detalii);
    insert into manevra_prodcomp_clona select * from prodcomp_clona;
    insert into manevra_prodman_clona select * from prodman_clona;
    insert into manevra_prodmat_clona select * from prodmat_clona;
  else
    delete manevra_preturi_p;
    delete manevra_preturi_d_p;
    delete manevra_prodcomp_clona_p;
    delete manevra_prodman_clona_p;
    delete manevra_prodmat_clona_p;
    Insert Into manevra_Preturi_p ( CODOBIECT, PRET, STARE, CodArticol, CodAtribut)
    (Select codobiect, PRET, STARE, CodArticol, CodAtribut from Tmp_Manevra_Preturi);
    Insert Into Manevra_Preturi_D_p (Select * from tmp_manevra_preturi_Detalii);
    insert into manevra_prodcomp_clona_p select * from prodcomp_clona;
    insert into manevra_prodman_clona_p select * from prodman_clona;
    insert into manevra_prodmat_clona_p select * from prodmat_clona;
  end if;
  if DoCommit then
    commit;
  end if;
end;

procedure LoadPreturi(modul in number) is
begin
  if modul = 1 then
    delete tmp_manevra_preturi;
    delete tmp_manevra_preturi_Detalii;
    delete prodcomp_clona;
    delete prodman_clona;
    delete prodmat_clona;
    Insert Into Tmp_Manevra_Preturi ( CODOBIECT, PRET, STARE, DENUMIRE, Den_Claseas, CodArticol, CodAtribut, OBJ_CODEXTERN, OBJ_CODINTERN)
    (Select m.codobiect, m.PRET, m.STARE, o.DENUMIRE, nclaseas.den_claseas, m.codarticol, m.codatribut, O.CODEXTERN, O.CODINTERN
     from Manevra_Preturi m
          inner join NArtObj o on o.CodObiect = m.CodObiect
          inner join nart on o.codarticol = nart.codarticol
          left  join nclaseas on nart.clasastatist = nclaseas.codclaseas);
    Insert Into tmp_manevra_preturi_Detalii (Select * from Manevra_Preturi_D);
    insert into prodcomp_clona select * from manevra_prodcomp_clona;
    insert into prodman_clona select * from manevra_prodman_clona;
    insert into prodmat_clona select * from manevra_prodmat_clona;
    --ArmeazaTmps(0);
  else
    delete tmp_manevra_preturi;
    delete tmp_manevra_preturi_Detalii;
    delete prodcomp_clona;
    delete prodman_clona;
    delete prodmat_clona;
    Insert Into Tmp_Manevra_Preturi ( CODOBIECT, PRET, STARE, DENUMIRE, Den_Claseas, Codarticol, Codatribut, OBJ_CODEXTERN, OBJ_CODINTERN)
    (Select m.codobiect, m.PRET, m.STARE, o.DENUMIRE, nclaseas.den_claseas, m.CodArticol, m.CodAtribut, O.CODEXTERN, O.CODINTERN
     from Manevra_Preturi_p m
       inner join NArtObj o on o.CodObiect = m.CodObiect
       inner join nart on o.codarticol = nart.codarticol
       left  join nclaseas on nart.clasastatist = nclaseas.codclaseas);
    Insert Into tmp_manevra_preturi_Detalii (Select * from Manevra_Preturi_D_P);
    insert into prodcomp_clona select * from manevra_prodcomp_clona_p;
    insert into prodman_clona select * from manevra_prodman_clona_p;
    insert into prodmat_clona select * from manevra_prodmat_clona_p;
  end if;
  if DoCommit then
    commit;
  end if;
end;

procedure UpdateNArtObj1AnteC is
TipPret number(1);
begin
  -- merg pe inregistrarea valabila acum
  --inserez cele care nu sunt si apoi facem update la toate

  TipPret := Pkg_Categconst.GetValConstanta(&apos;TipEvaluarePret&apos;, pkg_globals.getanlucru, pkg_globals.getlunalucru);
  for v_rec in (select obj1.*
                from nartobj1 obj1
                     inner join (select distinct codobiect from prodcomp_clona) pcc on pcc.codobiect = obj1.codobiect
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                order by obj1.codobiect
               )
  loop

    if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; pkg_globals.GetANLUCRU*12+pkg_globals.GetlunaLUCRU then
      insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                            , anstart, lunastart, pretreferinta, tippretmax, compensat, tipcompensare
                            , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                            , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                            , punctesectie, tippret, cost)
       values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                            , pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU, v_Rec.pretreferinta, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare
                            , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                            , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                            , v_Rec.punctesectie, nvl(v_rec.tippret,1), v_Rec.cost);
       prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
    end if;

  end loop;
  for v_rec in (select obj1.codobiect1, pc.valmat, pcc.valman, pcc.valregie, obj1.codobiect, obj1.tippret, pc.tippret tippretreteta, pc.totpretfix
                from nartobj1 obj1
                     inner join prodcomp_clona pcc on pcc.codobiect = obj1.codobiect
                     left join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                 and pc.generic = 1
                order by obj1.codobiect) loop
    -- setez implicitele
    if vTipPretDin = 1 then
      if v_rec.tippretreteta = 1 then
        update nartobj1
        set
          pretreferinta = v_Rec.valmat + v_Rec.valman + v_Rec.valregie,
          cost = v_rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      else
        update nartobj1
        set
          pretreferinta = v_Rec.valmat,
          cost = v_rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      end if;
    else
      if v_rec.tippret = 1 then
        update nartobj1
        set
          pretreferinta = v_Rec.valmat + v_Rec.valman + v_Rec.valregie ,
          cost = v_rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      else
        update nartobj1
        set
          pretreferinta = v_Rec.valmat,
          cost = v_rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      end if;
    end if;
    delete prodcomp_clona where codobiect = v_rec.codobiect;
  end loop;

  if TipPret = 1 then
    for v_rec in (select obj1.codobiect1, cc.valmat, cc.valtot, obj1.tippret, cc.totpretfix
                  from nartobj1 obj1
                       inner join (select pcc.codobiect, max(pcc.valmat) valmat, max(pcc.valmat + pcc.valman + pcc.valregie) valtot, max(pc.totpretfix) totpretfix
                                   from prodcomp_clona pcc
                                        inner join prodcomp pc on pcc.codprodcomp = pc.codprodcomp
                                   group by pcc.codobiect) cc on cc.codobiect = obj1.codobiect
                  WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                  ) loop
      if v_rec.tippret = 1 then
        update nartobj1
        set
          pretreferinta = v_Rec.valtot,
          cost = v_Rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      else
        update nartobj1
        set
          pretreferinta = v_Rec.valmat,
          cost = v_Rec.totpretfix
        where codobiect1 = v_Rec.codobiect1;
      end if;
    end loop;
  else
    if TipPret = 3 then
        for v_rec in (select obj1.codobiect1, cc.valmat, cc.valtot, obj1.tippret, cc.totpretfix
                      from nartobj1 obj1
                           inner join (select pcc.codobiect, min(pcc.valmat) valmat, min(pcc.valmat + pcc.valman + pcc.valregie) valtot,
                                              min(pc.totpretfix) totpretfix
                                       from prodcomp_clona pcc
                                            inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
                                       group by pcc.codobiect) cc on cc.codobiect = obj1.codobiect
                      WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                      ) loop
          if v_rec.tippret = 1 then
            update nartobj1
            set
              pretreferinta = v_Rec.valtot,
              cost = v_Rec.totpretfix
            where codobiect1 = v_Rec.codobiect1;
          else
            update nartobj1
            set
              pretreferinta = v_Rec.valmat,
              cost = v_Rec.totpretfix
            where codobiect1 = v_Rec.codobiect1;
          end if;
        end loop;
     else
        for v_rec in (select obj1.codobiect1, cc.valmat, cc.valtot, obj1.tippret, cc.totpretfix
                      from nartobj1 obj1
                           inner join (select pcc.codobiect, avg(pcc.valmat) valmat, avg(pcc.valmat + pcc.valman + pcc.valregie) valtot,
                                              avg(pc.totpretfix) totpretfix
                                       from prodcomp_clona pcc
                                            inner join prodcomp pc on pc.codprodcomp = pcc.codprodcomp
                                       group by pcc.codobiect) cc on cc.codobiect = obj1.codobiect
                      WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                      ) loop
          if v_rec.tippret = 1 then
            update nartobj1
            set
              pretreferinta = v_Rec.valtot,
              cost = v_rec.totpretfix
            where codobiect1 = v_Rec.codobiect1;
          else
            update nartobj1
            set
              pretreferinta = v_Rec.valmat,
              cost = v_rec.totpretfix
            where codobiect1 = v_Rec.codobiect1;
          end if;
        end loop;
     end if;
  end if;
  -- rezultantele
  for v_rec in (select obj1.codobiect1, rez.pret_n, obj1.codobiect, rez.codrez
                from nartobj1 obj1
                     inner join prodrez r on obj1.codobiect = r.codobiect
                     inner join prodrez_clona rez on rez.codrez = r.codrez
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                order by obj1.codobiect) loop
    -- setez implicitele
    update nartobj1 set pretreferinta = v_Rec.pret_n where codobiect1 = v_Rec.codobiect1;
    delete prodrez_clona where codrez = v_rec.codrez;
  end loop;

  if DoCommit then
    commit;
  end if;
end;

procedure UpdateNArtObj1ByTipCont(aAn IN NUMBER, aLuna in number) is
begin
  for v_rec in (select obj1.*, cont.simbol
                from nartobj1 obj1
                     inner join nartobj obj on obj.codobiect = obj1.codobiect
                     left join nartimplicite imp on obj.codarticol = imp.codarticol and imp.codsubunit = 2
                     left join ioart1 ioa1 on ioa1.codioart = imp.contimplicit
                     left join ncont cont on cont.codcont = ioa1.cont
                WHERE aAn*12+aLuna BETWEEN obj1.alstart AND obj1.alstop
                  and aAn*12+aLuna BETWEEN ioa1.alstart AND ioa1.alstop
                order by obj1.codobiect
               )
  loop

    if v_rec.simbol = &apos;341&apos; then
      if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; aAn*12+aLuna then
        insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                              , anstart, lunastart, tippretmax, compensat, tipcompensare, pretreferinta
                              , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                              , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                              , punctesectie, tippret)
         values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                              , aAn, aLuna, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare, v_rec.pretreferinta
                              , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                              , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                              , v_Rec.punctesectie, 2);
         prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
      else
        update nartobj1
        set tippret = 2
        where codobiect1 = v_Rec.codobiect1;
      end if;
    end if;
    if v_rec.simbol = &apos;345&apos; then
      if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; aAn*12+aLuna then
        insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                              , anstart, lunastart, tippretmax, compensat, tipcompensare, pretreferinta
                              , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                              , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                              , punctesectie, tippret)
         values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                              , aAn, aLuna, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare, v_rec.pretreferinta
                              , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                              , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                              , v_Rec.punctesectie, 1);
         prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
      else
        update nartobj1
        set tippret = 1
        where codobiect1 = v_Rec.codobiect1;
      end if;
    end if;
  end loop;

  commit;
end;

procedure CorectieMatDuplInProj is
nrMatRet number;
nrMatProj number;
begin
  for v_rec in (select par.codproiectnod nodoriginal, mat.codprodcomp, mat.codmat, mat.codobiect,
                       mat.cant * par.cant/pc.cant cant, mat.cant cantret
                from prodmat mat
                     inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
                     inner join proiectnod par on mat.codprodcomp = par.codreteta
                     left join proiectnod nod on par.codproiectnod = nod.nodoriginal and mat.codmat = nod.codprodmat
                where nvl(nod.codproiectnod,0) = 0) loop

    select count(*) into nrMatRet
    from prodmat
    where codprodcomp = v_rec.codprodcomp
          and codobiect = v_rec.codobiect
          and cant = v_rec.cantret;

    select count(*) into nrMatProj
    from proiectnod
    where nodoriginal = v_rec.nodoriginal
          and codobiect = v_rec.codobiect
          and cant = v_rec.cant;

    if nrMatProj = nrMatRet then
      -- avem un caz de duplicitate material gresit

      for v_tmp in (select nodord.codproiectnod, matord.codmat
                    from (select codmat,
                                 ROW_NUMBER() OVER (PARTITION BY codobiect, cant ORDER BY codmat) Ordine
                          from prodmat
                          where codobiect = v_rec.codobiect and cant = v_rec.cantret and codprodcomp = v_rec.codprodcomp
                          ) matord
                          inner join (select codproiectnod,
                                             ROW_NUMBER() OVER (PARTITION BY nodoriginal, codobiect, cant ORDER BY codproiectnod) Ordine
                                      from proiectnod
                                      where codobiect = v_rec.codobiect and cant = v_rec.cant and nodoriginal = v_rec.nodoriginal
                                      ) nodord on matord.ordine = nodord.ordine
                    ) loop
         update proiectnod set codprodmat = v_tmp.codmat where codproiectnod = v_tmp.codproiectnod;
       end loop;
    end if;
  end loop;
  commit;
end;

procedure CorectieMatDuplInProjByCod(aCodProiect in number) is
nrMatRet number;
nrMatProj number;
begin
  for v_rec in (select par.codproiectnod nodoriginal, mat.codprodcomp, mat.codmat, mat.codobiect,
                       mat.cant * par.cant/pc.cant cant, mat.cant cantret
                from prodmat mat
                     inner join prodcomp pc on mat.codprodcomp = pc.codprodcomp
                     inner join proiectnod par on mat.codprodcomp = par.codreteta
                     left join proiectnod nod on par.codproiectnod = nod.nodoriginal and mat.codmat = nod.codprodmat
                where nvl(nod.codproiectnod,0) = 0 and par.codproiect = aCodProiect) loop

    select count(*) into nrMatRet
    from prodmat
    where codprodcomp = v_rec.codprodcomp
          and codobiect = v_rec.codobiect
          and cant = v_rec.cantret;

    select count(*) into nrMatProj
    from proiectnod
    where nodoriginal = v_rec.nodoriginal
          and codobiect = v_rec.codobiect
          and cant = v_rec.cant;

    if nrMatProj = nrMatRet then
      -- avem un caz de duplicitate material gresit

      for v_tmp in (select nodord.codproiectnod, matord.codmat
                    from (select codmat,
                                 ROW_NUMBER() OVER (PARTITION BY codobiect, cant ORDER BY codmat) Ordine
                          from prodmat
                          where codobiect = v_rec.codobiect and cant = v_rec.cantret and codprodcomp = v_rec.codprodcomp
                          ) matord
                          inner join (select codproiectnod,
                                             ROW_NUMBER() OVER (PARTITION BY nodoriginal, codobiect, cant ORDER BY codproiectnod) Ordine
                                      from proiectnod
                                      where codobiect = v_rec.codobiect and cant = v_rec.cant and nodoriginal = v_rec.nodoriginal
                                      ) nodord on matord.ordine = nodord.ordine
                    ) loop
         update proiectnod set codprodmat = v_tmp.codmat where codproiectnod = v_tmp.codproiectnod;
       end loop;
    end if;
  end loop;
  commit;
end;

procedure CorectieCmdProdMat is
begin
  for v_rec in (select round(c1.cantacceptat/pc.cant*mat.cantmat,5) cantnou, cmdr.cant, cmdr.codcmdprodmat
                from comanda1 c1
                     inner join prodcomp pc on pc.codprodcomp = c1.codreteta
                     inner join (select sum(cant) cantmat, codobiect, codcomanda1 from cmdprodmat group by codobiect, codcomanda1) cmdmat on cmdmat.codcomanda1 = c1.codcomanda1
                     inner join (select sum(cant) cantmat, codobiect, codprodcomp from prodmat group by codobiect, codprodcomp) mat on mat.codprodcomp = c1.codreteta
                                                                                                                                       and cmdmat.codobiect = mat.codobiect
                     inner join (select count(*) nr, codobiect, codcomanda1 from cmdprodmat group by codobiect, codcomanda1) catemat on catemat.codcomanda1 = c1.codcomanda1
                                                                                                                                        and catemat.codobiect = cmdmat.codobiect
                     inner join cmdprodmat cmdr on cmdr.codcomanda1 = c1.codcomanda1 and cmdr.codobiect = cmdmat.codobiect
                where round(cmdmat.cantmat,5) &lt;&gt; round(c1.cantacceptat/pc.cant*mat.cantmat,5) and catemat.nr = 1
               ) loop
    update cmdprodmat set
      rest = rest + v_rec.cantnou - v_rec.cant,
      cant = v_rec.cantnou
    where codcmdprodmat = v_rec.codcmdprodmat;
  end loop;
  update iesprodlink l set cant = (select i1.cant from iesiri1 i1 where l.codies1 = i1.codies1);
  update cmdprodmat cmd set rest = cant - (select sum(l.cant) from iesprodlink l where l.codcmdprodmat = cmd.codcmdprodmat)
  where cmd.tip = 1;
  update cmdprodmat prod set rest = cant - (select sum(l.cant) from intrprodlink l where l.codliniecomanda = prod.codcmdprodmat)
  where prod.tip = 0;
end;

procedure UpdateNArtObj1Double(aCodObiect in number, Camp in varchar, valoare in number) is
sString varchar2(1000);
begin
  if pkg_categconst.GetValConstanta(&apos;PretRefUnicArticol&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 then
    for v_rec in (select obj1.*
                  from nartobj1 obj1
                       inner join nartobj obj on obj1.codobiect = obj.codobiect
                       inner join nartobj objp on objp.codarticol = obj.codarticol
                  WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                    and OBJP.CODOBIECT = aCodObiect
                  order by obj1.codobiect) loop

      if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; pkg_globals.GetANLUCRU*12+pkg_globals.GetlunaLUCRU then
        insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                              , anstart, lunastart, tippretmax, compensat, tipcompensare
                              , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                              , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                              , punctesectie)
        values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                              , pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare
                              , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                              , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                              , v_Rec.punctesectie);
        prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
      end if;
    end loop;
    for v_rec in (select obj1.codobiect1
                from nartobj1 obj1
                     inner join nartobj obj on obj1.codobiect = obj.codobiect
                     inner join nartobj objp on objp.codarticol = obj.codarticol
                WHERE PKG_GLOBALS.ANLUNALUCRU BETWEEN obj1.ALStart AND obj1.ALStop
                  and OBJP.CODOBIECT = aCodObiect
                  order by obj1.codobiect) loop
      sString := &apos;update nartobj1 set &apos;||Camp||&apos; = &apos;||replace(to_char(valoare), &apos;,&apos;, &apos;.&apos;)||&apos; where codobiect1 = &apos;||v_Rec.codobiect1;
      execute immediate sString;
    end loop;
  else
    for v_rec in (select obj1.*
                  from nartobj1 obj1
                  WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                    and OBJ1.CODOBIECT = aCodObiect
                  order by obj1.codobiect) loop

      if v_Rec.anstart*12+v_Rec.lunastart &lt;&gt; pkg_globals.GetANLUCRU*12+pkg_globals.GetlunaLUCRU then
        insert into nartobj1 (codobiect1, codobiect, pretmaximal, procadaosmaximal, adaosla
                              , anstart, lunastart, tippretmax, compensat, tipcompensare
                              , grupa, uplift, codmoneda, puncte, umiditate, corpuri_straine, incoltit
                              , hectolitrica, gluten, fuzaritate, cadere, deformare, sticlozitate, sparturi
                              , punctesectie)
        values (seq_nartobj1_codobiect1.nextval, v_Rec.codobiect, v_Rec.pretmaximal, v_Rec.procadaosmaximal, v_Rec.adaosla
                              , pkg_globals.GetANLUCRU, pkg_globals.GetLunaLUCRU, v_Rec.tippretmax, v_Rec.compensat, v_Rec.tipcompensare
                              , v_Rec.grupa, v_Rec.uplift, v_Rec.codmoneda, v_Rec.puncte, v_Rec.umiditate, v_Rec.corpuri_straine, v_Rec.incoltit
                              , v_Rec.hectolitrica, v_Rec.gluten, v_Rec.fuzaritate, v_Rec.cadere, v_Rec.deformare, v_Rec.sticlozitate, v_Rec.sparturi
                              , v_Rec.punctesectie);
        prc_al_refresh(&apos;nartobj1&apos;, v_Rec.codobiect);
      end if;
    end loop;
    for v_rec in (select obj1.codobiect1
                from nartobj1 obj1
                WHERE pkg_globals.getanlucru*12+pkg_globals.getlunalucru BETWEEN obj1.alstart AND obj1.alstop
                 and obj1.codobiect = aCodObiect
                 order by obj1.codobiect) loop
      sString := &apos;update nartobj1 set &apos;||Camp||&apos; = &apos;||replace(to_char(valoare), &apos;,&apos;, &apos;.&apos;)||&apos; where codobiect1 = &apos;||v_Rec.codobiect1;
      execute immediate sString;
    end loop;
  end if;

  if DoCommit then
    commit;
  end if;
end;

procedure PROPAGAFISA(aCodProdComp in number) is
begin
  if vAllRet &gt; 0 then
    for v_rec in (select codprodcomp from prodcomp where codprodcomp &lt;&gt; aCodProdComp) loop
      begin
        pkg_prodcomp.SP_LOCKRECORD(v_rec.codprodcomp);
        delete prodmas where codprodcomp = v_rec.codprodcomp;
        for v_mas in (select * from prodmas where codprodcomp = aCodProdComp) loop
          insert into prodmas(
                              CODPRODMAS,
                              CODPRODCOMP,
                              DESCRIERE,
                              FRECVENTA,
                              METODA,
                              CODOBIECT,
                              INDEXLOCAL
                              )
          values (seq_prodmas_codprodmas.nextval,
                  v_rec.codprodcomp,
                  v_mas.descriere,
                  v_mas.FRECVENTA,
                  v_mas.METODA,
                  v_mas.CODOBIECT,
                  v_mas.INDEXLOCAL
                  );
        end loop;
      exception when others then null;
      end;
    end loop;
  else
    for v_rec in (select codprodcomp from tmp_prodcomp_man where codprodcomp &lt;&gt; aCodProdComp) loop
      begin
        pkg_prodcomp.SP_LOCKRECORD(v_rec.codprodcomp);
        delete prodmas where codprodcomp = v_rec.codprodcomp;
        for v_mas in (select * from prodmas where codprodcomp = aCodProdComp) loop
          insert into prodmas(
                              CODPRODMAS,
                              CODPRODCOMP,
                              DESCRIERE,
                              FRECVENTA,
                              METODA,
                              CODOBIECT,
                              INDEXLOCAL
                              )
          values (seq_prodmas_codprodmas.nextval,
                  v_rec.codprodcomp,
                  v_mas.descriere,
                  v_mas.FRECVENTA,
                  v_mas.METODA,
                  v_mas.CODOBIECT,
                  v_mas.INDEXLOCAL
                  );
        end loop;
      exception when others then null;
      end;
    end loop;
  end if;
  commit;
end;

procedure ActualizeazaPretDinMat(aCodProdComp in number, aData in varchar2) is
vPret number(20,7);
vPretV number(20,7);
vValMat number(20,7);
vBanca number(20);
begin
  --pkg_globals.SetLunaLucru_SIMPLA(2008,7);
  vBanca := pkg_categconst.GetValConstanta(&apos;BancaProdV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  if vBanca = 0 or vBanca is null then
    vBanca := pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  end if;
  for v_xxx in (select pc.codprodcomp, pc.codobiect, pc.cant,
                       nvl(pc.CoefIndirecte,0) CoefIndirecte, pc.tipreteta, pc.codmoneda
                from prodcomp pc
                WHERE pc.CodProdComp = aCodProdComp) loop
    vValMat   := 0;
    for v_tmp in (select mat.cant, nvl(mat.pret,0) pret, nvl(mat.pretv,0) pretv
                  from prodmat mat
                  where mat.codprodcomp = v_xxx.codprodcomp) loop
      if v_xxx.codmoneda &gt; 0 then vValMat := vValMat + v_tmp.pretv * v_tmp.cant; else vValMat := vValMat + v_tmp.pret * v_tmp.cant; end if;
    end loop;
    if v_xxx.codmoneda &gt; 0 then
      vPretV := vValMat / v_xxx.cant;
      vPret  := vPretV * PKG_LIST_BASE_UTILS.GETCURSREFERINTA(v_xxx.CODMONEDA,
                                                             vBanca,
                                                             to_date(aData,&apos;dd.mm.yyyy&apos;));
      vValMat := vValMat * PKG_LIST_BASE_UTILS.GETCURSREFERINTA(v_xxx.CODMONEDA,
                                                                vBanca,
                                                                to_date(aData,&apos;dd.mm.yyyy&apos;));
    else
      vPret  := vValMat / v_xxx.cant;
      vPretV := vPret;
    end if;
    update prodcomp set pret = vPret, pretvaluta = vPretV, valmat = vValMat where codprodcomp = v_xxx.Codprodcomp;
  end loop;
  commit;
end;

function CloneazaReteta(aCodProdComp in number) return number is
aCod number(20);
begin
  Set_Do_Commit(False);
  delete tmp_prodcomp;
  delete tmp_prodmat;
  delete tmp_prodrez;
  delete tmp_proiecte;
  delete tmp_prodgest;
  delete tmp_prodman;
  delete tmp_prodsdv;
  delete tmp_prodmas;
  delete tmp_prodmatechiv;
  delete tmp_prodnorme;
  delete tmp_normemat;
  SP_GOTORECORD(aCodProdComp);
  SP_POSTRECORDS(1, aCod);
  Set_Do_Commit(True);
  return aCod;
end;

procedure DOVERIF is
aCount number(10);
aPret number(20,7);
begin
  delete tmp_atentionari;
  update prodcomp set generic = 0, implicit = 0 where inactiv = 1;
  update prodcomp set generic = 0, implicit = 0 where ascuns = 1;
  commit;
  for v_rec in (select pc.codobiect, count(*)
                from prodcomp pc
                where nvl(pc.ascuns,0) = 0 and nvl(pc.inactiv,0) = 0 and pc.generic = 1
                      and pc.codprodcomp &gt;= 100
                group by pc.codobiect
                having count(*) &gt; 1
               ) loop
    insert into tmp_atentionari (tip, camp1, camp2)
    select 4, codprodcomp, codobiect
    from prodcomp
    where codobiect = v_rec.codobiect and nvl(ascuns,0) = 0 and nvl(inactiv,0) = 0 and generic = 1;
  end loop;
  commit;
  for v_rec in (select pc.codobiect, count(*)
                from prodcomp pc
                where nvl(pc.ascuns,0) = 0 and nvl(pc.inactiv,0) = 0 and pc.implicit = 1
                      and pc.codprodcomp &gt;= 100
                group by pc.codobiect
                having count(*) &gt; 1
               ) loop
    insert into tmp_atentionari (tip, camp1, camp2)
    select 5, codprodcomp, codobiect
    from prodcomp
    where codobiect = v_rec.codobiect and nvl(ascuns,0) = 0 and nvl(inactiv,0) = 0 and implicit = 1;
  end loop;
  commit;
  for v_rec in (select distinct pc.codobiect
                from prodcomp pc
                where not exists (select p.codprodcomp from prodcomp p where p.codobiect = pc.codobiect and nvl(p.ascuns,0) = 0 and p.generic = 1 and nvl(inactiv,0) = 0)
                      and nvl(pc.ascuns,0) = 0 and nvl(pc.inactiv,0) = 0 and pc.codprodcomp &gt;= 100
               ) loop
    insert into tmp_atentionari (tip, camp1, camp2)
    select 6, codprodcomp, codobiect
    from prodcomp
    where codobiect = v_rec.codobiect
          and nvl(ascuns,0) = 0 and nvl(inactiv,0) = 0;
  end loop;
  commit;
  for v_rec in (select distinct pc.codobiect
                from prodcomp pc
                where not exists (select p.codprodcomp from prodcomp p where p.codobiect = pc.codobiect and nvl(p.ascuns,0) = 0 and p.implicit = 1 and nvl(inactiv,0) = 0)
                      and nvl(pc.ascuns,0) = 0 and nvl(pc.inactiv,0) = 0 and pc.codprodcomp &gt;= 100
               ) loop
    insert into tmp_atentionari (tip, camp1, camp2)
    select 7, codprodcomp, codobiect
    from prodcomp
    where codobiect = v_rec.codobiect
          and nvl(ascuns,0) = 0 and nvl(inactiv,0) = 0;
  end loop;
  commit;
end;

procedure propagagant(acodprodcomp in number) is
begin
  for v_Rec in (
    select man.decalaj, man.incepere, manu.codman
    from prodman man
         inner join prodcomp pc on pc.codprodcomp = man.codprodcomp
         inner join prodman manu on manu.codprodcomp = pc.codutilizare and man.nrop = manu.nrop
         and man.nrop = manu.nrop and man.codop = manu.codop and man.codloc = manu.codloc and man.codtarif = manu.codtarif
    where pc.codprodcomp = acodprodcomp
  ) loop
    update prodman set decalaj = v_rec.decalaj, incepere = v_rec.incepere where codman = v_rec.codman;
  end loop;
end;

procedure UPDATECODRETETAMAT is
aCodProdComp number(20);  
begin
  for v_rec in (select * from tmp_manevra_liste where filtru = &apos;CODMAT&apos;) loop
    insert into x(test) values (v_rec.filtru||&apos;:&apos;||v_Rec.Valoare||&apos; - &apos;||v_rec.filtru1);
    aCodProdComp := 0;
    begin
      select codprodcomp into aCodProdComp from prodcomp where trim(obs) = trim(v_rec.filtru1) and coalesce(ascuns,0) = 0;
    exception when others then 
      aCodProdComp := 0;
      insert into x(test) values(&apos;eroare la versiunea: &apos;||v_rec.filtru1);
    end;
    if aCodProdComp &gt; 0 then
      update prodmat set codreteta = aCodProdComp where codmat = v_rec.valoare;
    end if;
  end loop;
  commit;
end;

procedure GENPRJIMPORT is
aCodProiect number(20);
aCount number(20);
aActiv number(1);
aFinalizat number(1);  
begin
  for v_rec in (
    select tmp.valoare codprodcomp
    from tmp_manevra_liste tmp 
    where tmp.filtru = &apos;CODPRODCOMP&apos;
  ) loop
    aActiv := 1;
    aFinalizat := aActiv;
    aCodProiect := pkg_proiect.GENPRJFROMRETETA(v_rec.CodProdComp, 1);
    select count(*) into aCount from proiectnod where codproiect = aCodProiect and tip &lt; 3 and codreteta = 0;
    if aCount &gt; 0 then
      aActiv := 0;
      aFinalizat := 0;
    end if;
    update proiect set Activ = aActiv, Finalizat = aFinalizat where codproiect = aCodProiect;
  end loop;  
  commit;
end;    

function GetMasaS(aCodObiect in number) return number is
iResult number(20,7);
aCount  number(10);
begin
    begin
    select coalesce(masa,0) into iResult from nartobj where codobiect = acodobiect;
    exception when others then iResult := 0;
    end;
   
    select count(*) into acount from prodcomp where codobiect = aCodObiect;
    if acount &gt; 1 then
      select count(*) into acount from prodcomp where codobiect = aCodObiect and implicit = 1;
      if acount = 1 then
        for v_rec in (select m.codobiect, o.masa, m.tip, m.cant 
                      from prodcomp pc
                           inner join prodmat m on pc.codprodcomp = m.codprodcomp
                           inner join nartobj o on o.codobiect = m.codobiect
                      where pc.codobiect = acodobiect and pc.implicit = 1) loop
          if v_rec.tip &lt; 3 then
            iResult := iResult + v_rec.cant * GETMASAS(ACODOBIECT);
          else
            iResult := iResult + v_rec.cant * v_rec.masa;
          end if;
        end loop;
      else if acount = 0 then
        select count(*) into acount from prodcomp where codobiect = aCodObiect and generic = 1;
        if acount = 1 then
          for v_rec in (select m.codobiect, o.masa, m.tip, m.cant 
                        from prodcomp pc
                             inner join prodmat m on pc.codprodcomp = m.codprodcomp
                             inner join nartobj o on o.codobiect = m.codobiect
                        where pc.codobiect = acodobiect and pc.generic = 1) loop
            if v_rec.tip &lt; 3 then
              iResult := iResult + v_rec.cant * GETMASAS(ACODOBIECT);
            else
              iResult := iResult + v_rec.cant * v_rec.masa;
            end if;
          end loop;
        end if;
      end if; end if;
    else if acount = 1 then
      iResult := 0;
      for v_rec in (select m.codobiect, o.masa, m.tip, m.cant 
                    from prodcomp pc
                         inner join prodmat m on pc.codprodcomp = m.codprodcomp
                         inner join nartobj o on o.codobiect = m.codobiect
                    where pc.codobiect = acodobiect) loop                  
        if v_rec.tip &lt; 3 then 
          iResult := iResult + v_rec.cant * GETMASAS(ACODOBIECT);
        else 
          iResult := iResult + v_rec.cant * v_rec.masa;
        end if;
      end loop;
    else
      select coalesce(masa,0) into iresult from nartobj where codobiect = acodobiect;
    end if; end if;
     
    RETURN COALESCE(iResult, 0);
end; 

procedure setmasa is
amasa number(20,7);
acount number(10);  
begin
  for V_OBJ in (select distinct CODOBIECT from PRODCOMP where CODOBIECT &gt; 0) LOOP  
    select count(*) into acount from prodcomp where codobiect = v_obj.codobiect;
    if acount = 1 then 
      for v_rec in (
          select codprodcomp, cant, codobiect
          from prodcomp
          where codobiect = v_obj.codobiect
        ) loop
          Amasa := 0;
          for v_tmp in (
            select coalesce(o.masa,0) masa, m.tip, m.cant, m.codobiect
            from prodmat m
                 inner join nartobj o on o.codobiect = m.codobiect
            where m.codprodcomp = v_rec.codprodcomp     
          ) loop
            if v_tmp.tip &lt; 3 then
              amasa := amasa + v_tmp.cant * GETMASAS(v_tmp.CODOBIECT);
            else
              amasa := amasa + v_tmp.cant * coalesce(v_tmp.masa,0);
            end if;
          end loop;
          update nartobj set masa = coalesce(amasa,0)/v_rec.cant where codobiect = v_rec.codobiect;
      end loop;
    else
      select count(*) into acount from prodcomp where codobiect = v_obj.codobiect and implicit = 1;
      if acount = 1 then 
        for v_rec in (
            select codprodcomp, cant, codobiect
            from prodcomp
            where codobiect = v_obj.codobiect and implicit = 1
          ) loop
            Amasa := 0;
            for v_tmp in (
              select coalesce(o.masa,0) masa, m.tip, m.cant, m.codobiect
              from prodmat m
                   inner join nartobj o on o.codobiect = m.codobiect
              where m.codprodcomp = v_rec.codprodcomp     
            ) loop
              if v_tmp.tip &lt; 3 then
                amasa := amasa + v_tmp.cant * GETMASAS(v_tmp.CODOBIECT);
              else
                amasa := amasa + v_tmp.cant * coalesce(v_tmp.masa,0);
              end if;
            end loop;
            update nartobj set masa = coalesce(amasa,0)/v_rec.cant where codobiect = v_rec.codobiect;
          end loop;
      else
        select count(*) into acount from prodcomp where codobiect = v_obj.codobiect and generic = 1;
        for v_rec in (
            select codprodcomp, cant, codobiect
            from prodcomp
            where codobiect = v_obj.codobiect and generic = 1
          ) loop
            Amasa := 0;
            for v_tmp in (
              select coalesce(o.masa,0) masa, m.tip, m.cant, m.codobiect
              from prodmat m
                   inner join nartobj o on o.codobiect = m.codobiect
              where m.codprodcomp = v_rec.codprodcomp     
            ) loop
              if v_tmp.tip &lt; 3 then
                amasa := amasa + v_tmp.cant * GETMASAS(v_tmp.CODOBIECT);
              else
                amasa := amasa + v_tmp.cant * coalesce(v_tmp.masa,0);
              end if;
            end loop;
            update nartobj set masa = coalesce(amasa,0)/v_rec.cant where codobiect = v_rec.codobiect;
        end loop;
      end if;  
    end if;  
  end loop;
  commit;
end;

procedure BagaMateriale(acodproiect in number, aCodObiect in number, aCant in number, aCodProdComp in number, 
                        aNivel in number, aCodOriginal in number, aIndex in varchar2, aCodProdus in number) is
begin
  for v_rec in (select mat.codobiect, mat.tip, case when nvl(mat.tip,3) &lt;= 2 then nvl(pc.codprodcomp,0) else 0 end codprodcomp,
                       aCant/decode(nvl(prod.cant,0),0,1,prod.cant)*mat.cant cant,
                       aIndex||&apos;.&apos;||LPAD(to_char(IndexLocal), 2, &apos;0&apos;) Idx,
                       mat.codmat, mat.indexlocal, o.denumire
                from prodmat mat
                     inner join prodcomp prod on prod.codprodcomp = mat.codprodcomp
                     inner join nartobj o on o.codobiect = mat.codobiect
                     left  join prodcomp pc   on pc.codobiect     = mat.codobiect and pc.implicit = 1
                where mat.codprodcomp = aCodProdComp
                order by mat.indexlocal
               ) loop
    insert into tmp_proiectnod(codproiect,cant,nodoriginal,pozitie,codreteta,codobiect,indexparinte,codprodmat,nivel,denumire,necesar,proiectant)
    values (aCodProiect, v_rec.cant, aCodProdComp, v_rec.indexlocal, v_rec.codprodcomp, v_rec.codobiect, v_rec.idx, v_rec.codmat, aNivel+1, 
            LPAD(v_rec.denumire, Length(v_rec.denumire) + (aNivel+1)*2, &apos; &apos;), v_rec.cant, aCodProdus);
    if v_rec.CodProdComp &gt; 0 then
      BagaMateriale(acodproiect, v_rec.CodObiect, v_rec.Cant, v_Rec.CodProdComp, aNivel+1, acodprodcomp, v_rec.idx, aCodProdus);
    end if;
  end loop;
end;

procedure PregatesteStructura is
cCls number(10);
cClsS number(10);
cProd number(10);
/*
completare structura TMP_PROIECTNOD
CODPROIECT   - cod reteta produs (acelasi pe toata adancimea structurii)
CANT         - cantitate material/semifabricat in structura 
NODORIGINAL  - cod reteta parinte
POZITIE      - pozitia pe acelasi nivel
CODRETETA    - se completeaza numai la semifabricate (se pot gasi copiii lui prin nodoriginal = codreteta)
CODOBIECT    - codul de obiect
INDEXPARINTE - index de ordonare a structurii (contine elemente de nivel si pozitie)
CODPRODMAT   - CODMAT  din tabela PRODMAT
NIVEL        - nivelul de adancime in structura
DENUMIRE     - articol
PROIECTANT   - codul de obiect al produsului (acelasi pe toata adancimea structurii)
*/
begin
  select count(*) into cCls from tmp_manevra_liste where filtru = &apos;CODCLASEA&apos;;
  select count(*) into cClsS from tmp_manevra_liste where filtru = &apos;CODCLASEAS&apos;;
  select count(*) into cProd from tmp_manevra_liste where filtru = &apos;CODPRODUS&apos;;
  DELETE TMP_STOCREAL;
  DELETE TMP_PROIECTNOD;
  INSERT INTO TMP_STOCREAL(CODOBIECT,CANT)
  SELECT NS.CODOBIECT, SUM(NS.REST)
  FROM NIRSTOC NS
       INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
       INNER JOIN NGEST G ON G.CODGEST = NIR.GEST
  WHERE NS.REST &gt; 0 AND G.TIP &lt;&gt; 4
  GROUP BY NS.CODOBIECT;
  for v_rec in (select PC.CODPRODCOMP,
                       PC.CODOBIECT,
                       PC.CANT,
                       PC.IMPLICIT,
                       PC.DESCRIERE,
                       o.denumire
                from prodcomp pc
                     inner join nartobj o on o.codobiect = pc.codobiect
                     inner join nart a on a.codarticol = o.codarticol
                where (cCls = 0 or a.clasa in (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODCLASEA&apos;)) and
                      (cProd = 0 or o.codobiect in (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODPRODUS&apos;)) and
                      (cClsS = 0 or a.clasastatist in (select tmp.valoare from tmp_manevra_liste tmp where filtru = &apos;CODCLASEAS&apos;)) and
                      pc.implicit = 1
               ) loop
    insert into tmp_proiectnod(codproiect,cant,nodoriginal,pozitie,codreteta,codobiect,indexparinte,codprodmat,nivel,denumire,necesar,proiectant)
    values (v_rec.codprodcomp, v_rec.cant, 0, 1, v_rec.codprodcomp, v_rec.codobiect, &apos;00&apos;, 0, 0, v_rec.denumire, v_rec.cant,v_rec.codobiect);
    BagaMateriale(v_rec.codprodcomp, v_rec.CodObiect, v_rec.Cant, v_Rec.CodProdComp, 0, 0, &apos;00&apos;, v_rec.CodObiect);
  end loop;
  commit;
end;

procedure test is
begin
  execute immediate &apos;begin pkg_prodcomp.PregatesteStructura; end;&apos;;
end;  

end pkg_prodcomp;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55BBE6A7614F6CB4E5A7740C6FF5A3973DE168A4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PRODNET IS

procedure IncarcaManCmd1(aSubunitatea in number, aCodGest in number, aCodCentru in number) is
vAnLuna number(10);
begin
  vAnLuna := PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU;
  delete comanda1_man;
  delete consumuri_man;
  delete predari_man;

  if aCodCentru &gt; 0 then
    insert into comanda1_man(codcomanda1)
    select distinct codcomanda1 from (
      select c1.codcomanda1
      from comanda1 c1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna and c1.codcentru = aCodCentru
      union all
      select c1.codcomanda1
      from iesiri i
           inner join iesiri1 i1 on i.codies = i1.codies
           inner join iesprodlink l on l.codies1 = i1.codies1
           inner join cmdprodmat mat on mat.codcmdprodmat = l.codcmdprodmat
           inner join comanda1 c1 on mat.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and i.an*12+i.luna &gt;= vAnLuna
            and nvl(i.blocat,0) = 0 and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and c1.codcentru = aCodCentru
      union all
      select c1.codcomanda1
      from intrari i
           inner join intrari1 i1 on i.codintr = i1.codintr
           inner join intrprodlink l on l.codintr1 = i1.codintr1
           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
           inner join comanda1 c1 on prod.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and i.an*12+i.luna &gt;= vAnLuna
            and nvl(i.blocat,0) = 0 and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
            and c1.codcentru = aCodCentru
      union all
      select c1.codcomanda1
      from raportp rp
           inner join raportp1 rp1 on rp.codraportp = rp1.codraportp
           inner join raportp2 rp2 on rp1.codraportp1 = rp2.codraportp1
           inner join manprodlink l on l.codraportp2 = rp2.codraportp2
           inner join cmdprodman man on man.codcmdprodman = l.codcmdprodman
           inner join comanda1 c1 on man.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and rp.an*12+rp.luna &gt;= vAnLuna
            and c1.codcentru = aCodCentru
    );
  else
    insert into comanda1_man(codcomanda1)
    select distinct codcomanda1 from (
      select c1.codcomanda1
      from comanda1 c1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
      union all
      select c1.codcomanda1
      from iesiri i
           inner join iesiri1 i1 on i.codies = i1.codies
           inner join iesprodlink l on l.codies1 = i1.codies1
           inner join cmdprodmat mat on mat.codcmdprodmat = l.codcmdprodmat
           inner join comanda1 c1 on mat.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and i.an*12+i.luna &gt;= vAnLuna
            and nvl(i.blocat,0) = 0 and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
      union all
      select c1.codcomanda1
      from intrari i
           inner join intrari1 i1 on i.codintr = i1.codintr
           inner join intrprodlink l on l.codintr1 = i1.codintr1
           inner join cmdprodmat prod on prod.codcmdprodmat = l.codliniecomanda
           inner join comanda1 c1 on prod.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and i.an*12+i.luna &gt;= vAnLuna
            and nvl(i.blocat,0) = 0 and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
      union all
      select c1.codcomanda1
      from raportp rp
           inner join raportp1 rp1 on rp.codraportp = rp1.codraportp
           inner join raportp2 rp2 on rp1.codraportp1 = rp2.codraportp1
           inner join manprodlink l on l.codraportp2 = rp2.codraportp2
           inner join cmdprodman man on man.codcmdprodman = l.codcmdprodman
           inner join comanda1 c1 on man.codcomanda1 = c1.codcomanda1
           inner join comanda c on c.codcomanda = c1.codcomanda
      where nvl(c.inchisa, 0) = 1 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
            and c.subunitatea = aSubunitatea and (aCodGest = 0 or c.codgest = aCodGest)
            and c.an*12+c.luna &lt;= vAnLuna
            and rp.an*12+rp.luna &gt;= vAnLuna
    );
  end if;

  if Nvl(pkg_categconst.GetValConstanta(&apos;ProdNetSuplim&apos; ,PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU),2) = 1 then
    insert into predari_man
    select mat.cant * sum(il.cant)/prod.cant cant, mat.codcmdprodmat, mat.codobiect, mat.codcomanda1
    from intrprodlink il
         inner join intrari1     i1   on i1.codintr1        = il.codintr1
         inner join intrari      i    on i1.codintr         = i.codintr
         inner join cmdprodmat   prod on il.codliniecomanda = prod.codcmdprodmat
         inner join cmdprodmat   mat  on prod.codcomanda1   = mat.codcomanda1 and mat.tip = 1
         inner join comanda1_man c1   on c1.codcomanda1     = mat.codcomanda1
    where COALESCE(i.blocat,0) = 0 and COALESCE(i.operat,0) = 1 and COALESCE(i.anulat,0) = 0
          and COALESCE(prod.cant,0) &gt; 0 and i.an*12+i.luna &lt;= vAnLuna
    group by mat.codcmdprodmat, mat.cant, prod.cant, mat.codobiect, mat.codcomanda1;

    insert into consumuri_man
    select COALESCE(cant,0) cant, case when COALESCE(cant,0) = 0 then 0 else val/cant end pret, codcmdprodmat, codies1, codobiect, codcomanda1 from (
    select sum(l1.cant*
               case
                 when il.codies1 is null then
                   case
                     when RestDePredat.Rest &gt;= prod.cant then 0
                     else (prod.cant - coalesce(RestDePredat.Rest,0))/prod.cant
                   end
                 else 1
               end) cant,
           sum(l1.cant*
               case
                 when il.codies1 is null then
                   case
                     when RestDePredat.Rest &gt;= prod.cant then 0
                     else (prod.cant - coalesce(RestDePredat.Rest,0))/prod.cant
                   end
                 else 1
               end
               * ns.pret) val, coalesce(il.codcmdprodmat,0) codcmdprodmat, i1.codies1, c1.codcomanda1, i1.codobiect
    from comanda1_man c1
         inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
         inner join iesiri1    i1   on i1.codcmdint1  = c1.codcomanda1
         inner join iesiri     i    on i1.codies      = i.codies
         left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                     from comanda1_man cc1
                          inner join cmdprodmat   prodc on cc1.codcomanda1     = prodc.codcomanda1 and COALESCE(prodc.tip,0) = 0
                          inner join intrprodlink ilc   on prodc.codcmdprodmat = ilc.codliniecomanda
                          inner join intrari1     i1c   on ilc.codintr1        = i1c.codintr1
                          inner join intrari      ic    on i1c.codintr         = ic.codintr
                     where COALESCE(ic.blocat,0) = 0 and COALESCE(ic.operat,0) = 1 and COALESCE(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                     group by prodc.codcmdprodmat
                    ) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
         left  join livr        l  on i.codies      = l.codies
         left  join livr1       l1 on l1.codies1    = i1.codies1 and l.codlivr = l1.codlivr
         left  join nirstoc     ns on l1.codnirstoc = ns.codnirstoc
         left  join centrecost  cc on i1.codcentru  = cc.codcentru
         left  join iesprodlink il on i1.codies1    = il.codies1
         left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                     from comanda1_man c1
                          inner join cmdprodmat   prod on c1.codcomanda1     = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
                          inner join intrprodlink il   on prod.codcmdprodmat = il.codliniecomanda
                          inner join intrari1     i1   on il.codintr1        = i1.codintr1
                          inner join intrari      i    on i1.codintr         = i.codintr
                     where prod.rest &lt;=0
                           and COALESCE(i.blocat,0) = 0 and COALESCE(i.operat,0) = 1 and COALESCE(i.anulat,0) = 0
                     group by c1.codcomanda1
                    ) Stinse on Stinse.codcomanda1 = c1.codcomanda1
    where COALESCE(cc.tipaloc,0) = 0
          and ((prod.cant - COALESCE(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - COALESCE(RestDePredat.Rest,0) &lt;= 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
          and i.an*12+i.luna &lt;= vAnLuna
    group by il.codcmdprodmat, i1.codies1, c1.codcomanda1, i1.codobiect ) A_PG;
  else
    insert into predari_man(cant,codcmdprodmat)
    select mat.cant * sum(il.cant)/prod.cant cant, mat.codcmdprodmat
    from intrprodlink il
         inner join intrari1 i1 on i1.codintr1 = il.codintr1
         inner join intrari i on i1.codintr = i.codintr
         inner join cmdprodmat prod on il.codliniecomanda = prod.codcmdprodmat
         inner join cmdprodmat mat on prod.codcomanda1 = mat.codcomanda1 and mat.tip = 1
         inner join comanda1_man c1 on c1.codcomanda1 = mat.codcomanda1
    where COALESCE(i.blocat,0) = 0 and COALESCE(i.operat,0) = 1 and COALESCE(i.anulat,0) = 0
          and COALESCE(prod.cant,0) &gt; 0 and i.an*12+i.luna &lt;= vAnLuna
    group by mat.codcmdprodmat, mat.cant, prod.cant;
    insert into consumuri_man(cant,pret,codcmdprodmat,codies1,codcomanda1)
    select COALESCE(cant,0) cant, case when COALESCE(cant,0) = 0 then 0 else val/cant end pret, codcmdprodmat, codies1, codcomanda1 from (
    select sum(l1.cant) cant, sum(l1.cant * ns.pret) val, il.codcmdprodmat, i1.codies1, c1.codcomanda1
    from comanda1_man c1
         inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
         inner join iesiri1 i1 on i1.codcmdint1 = c1.codcomanda1
         inner join iesiri i on i1.codies = i.codies
         left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                     from comanda1_man cc1
                          inner join cmdprodmat prodc on cc1.codcomanda1 = prodc.codcomanda1 and COALESCE(prodc.tip,0) = 0
                          inner join intrprodlink ilc on prodc.codcmdprodmat = ilc.codliniecomanda
                          inner join intrari1 i1c on ilc.codintr1 = i1c.codintr1
                          inner join intrari ic on i1c.codintr = ic.codintr
                     where COALESCE(ic.blocat,0) = 0 and COALESCE(ic.operat,0) = 1 and COALESCE(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                     group by prodc.codcmdprodmat) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
         left  join livr l on i.codies = l.codies
         left  join livr1 l1 on l1.codies1 = i1.codies1 and l.codlivr = l1.codlivr
         left  join nirstoc ns on l1.codnirstoc = ns.codnirstoc
         left  join centrecost cc on i1.codcentru = cc.codcentru
         left  join iesprodlink il on i1.codies1 = il.codies1
         left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                  from comanda1_man c1
                       inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and COALESCE(prod.tip,0) = 0
                       inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
                       inner join intrari1 i1 on il.codintr1 = i1.codintr1
                       inner join intrari i on i1.codintr = i.codintr
                  where prod.rest &lt;=0
                        and COALESCE(i.blocat,0) = 0 and COALESCE(i.operat,0) = 1 and COALESCE(i.anulat,0) = 0
                  group by c1.codcomanda1) Stinse on Stinse.codcomanda1 = c1.codcomanda1
    where COALESCE(cc.tipaloc,0) = 0
          and ((prod.cant - COALESCE(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - COALESCE(RestDePredat.Rest,0) &lt;= 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
          and i.an*12+i.luna &lt;= vAnLuna
    group by il.codcmdprodmat, i1.codies1, c1.codcomanda1 ) A_PG;
  end if;
end;

procedure SetDirty(aCodCmdProdMat in number, An in number, Luna in number, aTip in number) is
pragma autonomous_transaction;
vCodComanda1 number(20);
begin
  vCodComanda1 := 0;
  for v_rec in (select pn1.codprodnet1, pn1.coddoc1
                from prodnet1 pn1
                     inner join prodnet pn on pn1.codprodnet = pn.codprodnet
                     inner join cmdprodmat mat on mat.codcomanda1 = pn1.coddoc1
                where nvl(pn1.Tip,0) = aTip and mat.codcmdprodmat = aCodCmdProdMat and pn1.dirty = 1 and pn.An*12+pn.luna = An*12+Luna) loop
    vCodComanda1 := v_rec.coddoc1;
    update prodnet1 set dirty = 1 where codprodnet1 = v_rec.codprodnet1;
  end loop;

  if vCodComanda1 = 0 then
    begin
      if aTip = 0 then
        select nvl(codcomanda1,0) into vCodComanda1 from cmdprodmat where codcmdprodmat = aCodCmdProdMat;
      else
        select nvl(codcomanda1,0) into vCodComanda1 from cmdprodman where codcmdprodman = aCodCmdProdMat;
      end if;
    exception when others then vCodComanda1 := 0;
    end;

    for v_rec in (select pn1.codprodnet1, pn1.coddoc1
                from prodnet1 pn1
                     inner join prodnet pn on pn1.codprodnet = pn.codprodnet
                where pn1.coddoc1 = vCodComanda1 and pn1.dirty = 1 and pn.An*12+pn.luna = An*12+Luna) loop
      update prodnet1 set dirty = 1 where codprodnet1 = v_rec.codprodnet1;
    end loop;
  end if;

  commit;
end;

procedure RefacereDirty(aCodProdNet in number, DoCommit in number default 1) is
vCodGest number(20);
vAnLuna number(20);
vSterg boolean;
begin
  vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  select distinct pn.CodGest into vCodGest
  from prodnet pn
  where pn.codprodnet = aCodProdNet and pn.an*12+pn.luna = vAnLuna;

  for v_rec in (select pn1.codprodnet1, nvl(pn1.codies1,0) codies1, pn1.coddoc1 codcomanda1, nvl(pn1.codcmdprodmat,0) codcmdprodmat, pn1.codprodnet, nvl(pn1.tip,0) tip
                from prodnet1 pn1
                     inner join prodnet pn on pn1.codprodnet = pn.codprodnet
                where pn.codprodnet = aCodProdNet and pn1.dirty = 1 and pn.An*12+pn.luna = vAnLuna) loop
    if v_rec.tip = 0 then
      -- materiale
      if v_rec.codcmdprodmat &gt; 0 then
        -- linie detaliata
        vSterg := True;
        for v_tmp in (
          with predari as (
            select mat.cant * sum(il.cant)/prod.cant cant, mat.codcmdprodmat
            from intrprodlink il
                 inner join intrari1 i1 on i1.codintr1 = il.codintr1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join cmdprodmat prod on il.codliniecomanda = prod.codcmdprodmat
                 inner join cmdprodmat mat on prod.codcomanda1 = mat.codcomanda1 and mat.tip = 1
                 inner join comanda1 c1 on c1.codcomanda1 = mat.codcomanda1
                 inner join comanda c on c1.codcomanda = c.codcomanda
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and c.codgest = vCodGest
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and mat.codcmdprodmat = v_rec.codcmdprodmat
            group by mat.codcmdprodmat, mat.cant, prod.cant
          ),
          consumuri as ( select nvl(cant,0) cant, case when nvl(cant,0) = 0 then 0 else val/cant end pret, codcmdprodmat, codies1, codcomanda1 from (
            select sum(l1.cant) cant, sum(l1.cant * ns.pret) val, il.codcmdprodmat, i1.codies1, c1.codcomanda1
            from comanda1 c1
                 inner join comanda c on c1.codcomanda = c.codcomanda
                 inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                 inner join iesiri1 i1 on i1.codcmdint1 = c1.codcomanda1
                 inner join iesiri i on i1.codies = i.codies
                 left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                             from comanda1 cc1
                                  inner join comanda cc on cc1.codcomanda = cc.codcomanda
                                  inner join cmdprodmat prodc on cc1.codcomanda1 = prodc.codcomanda1 and nvl(prodc.tip,0) = 0
                                  inner join intrprodlink ilc on prodc.codcmdprodmat = ilc.codliniecomanda
                                  inner join intrari1 i1c on ilc.codintr1 = i1c.codintr1
                                  inner join intrari ic on i1c.codintr = ic.codintr
                             where nvl(cc.inchisa, 0) = 0 and nvl(cc.blocat,0) = 0 and nvl(cc.operat,0) = 1 and nvl(cc.anulat,0) = 0 and cc.an*12+cc.luna &lt;= vAnLuna
                                   and nvl(ic.blocat,0) = 0 and nvl(ic.operat,0) = 1 and nvl(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                             group by prodc.codcmdprodmat) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
                 left  join livr l on i.codies = l.codies
                 left  join livr1 l1 on l1.codies1 = i1.codies1 and l.codlivr = l1.codlivr
                 left  join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                 left  join centrecost cc on i1.codcentru = cc.codcentru
                 left  join iesprodlink il on i1.codies1 = il.codies1
                 left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                          from comanda1 c1
                               inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                               inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
                               inner join intrari1 i1 on il.codintr1 = i1.codintr1
                               inner join intrari i on i1.codintr = i.codintr
                          where prod.rest &lt;= 0
                          group by c1.codcomanda1) Stinse on Stinse.codcomanda1 = c1.codcomanda1
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and nvl(cc.tipaloc,0) = 0
                  and ((prod.cant - nvl(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - nvl(RestDePredat.Rest,0) = 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and c.codgest = vCodGest
                  and il.codcmdprodmat = v_Rec.codcmdprodmat
            group by il.codcmdprodmat, i1.codies1, c1.codcomanda1 )
          )
          select round(x.valoare,7) valoare, round(x.difcant,7) difcant, round(x.cant,7) cant, round(x.cantReal,7) cantreal
          from (
          select (consumuri.cant - nvl(predari.cant, 0)) * consumuri.pret valoare, consumuri.codcmdprodmat, consumuri.codies1, consumuri.cant - nvl(predari.cant, 0) difcant, consumuri.cant CantReal, nvl(predari.cant, 0) cant, consumuri.codcomanda1
          from consumuri
               left join predari on consumuri.codcmdprodmat = predari.codcmdprodmat
          where consumuri.cant - nvl(predari.cant, 0) &gt; 0 ) x
            inner join comanda1 c1 on c1.codcomanda1 = x.codcomanda1
            inner join comanda c on c1.codcomanda = c.codcomanda
            inner join nartobj obj on c1.codobiect = obj.codobiect
            inner join iesiri1 i1 on i1.codies1 = x.codies1
            inner join nartobj objmat on i1.codobiect = objmat.codobiect
            left  join cmdprodmat mat on x.codcmdprodmat = mat.codcmdprodmat) loop

          vSterg := False;
          update prodnet1 set
            VALMAT   = v_tmp.valoare,
            VALMAN   = 0,
            DIFCANT  = v_tmp.difcant,
            CANTREAL = v_tmp.cantreal,
            PRET     = case when v_tmp.difcant &lt;&gt; 0 then round(v_tmp.valoare/v_tmp.difcant,2) else 0 end,
            DIRTY    = 0
          where codprodnet1 = v_rec.codprodnet1;
          update prodnet1 set valmat = pret * difcant where codprodnet1 = v_rec.codprodnet1;

        end loop;
        if vSterg then delete prodnet1 where codprodnet1 = v_rec.codprodnet1; end if;
      else
        --linie centralizata
        vSterg := True;
        for v_tmp in (
          with predari as (
            select mat.cant * sum(il.cant)/prod.cant cant, mat.codcmdprodmat
            from intrprodlink il
                 inner join intrari1 i1 on i1.codintr1 = il.codintr1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join cmdprodmat prod on il.codliniecomanda = prod.codcmdprodmat
                 inner join cmdprodmat mat on prod.codcomanda1 = mat.codcomanda1 and mat.tip = 1
                 inner join comanda1 c1 on c1.codcomanda1 = mat.codcomanda1
                 inner join comanda c on c1.codcomanda = c.codcomanda
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and nvl(i.blocat,0) = 0 and nvl(i.operat,0) = 1 and nvl(i.anulat,0) = 0
                  and c.codgest = vCodGest
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and c1.codcomanda1 = v_rec.CodComanda1
            group by mat.codcmdprodmat, mat.cant, prod.cant
          ),
          consumuri as ( select nvl(cant,0) cant, case when nvl(cant,0) = 0 then 0 else val/cant end pret, codcmdprodmat, codies1, codcomanda1 from (
            select sum(l1.cant) cant, sum(l1.cant * ns.pret) val, il.codcmdprodmat, i1.codies1, c1.codcomanda1
            from comanda1 c1
                 inner join comanda c on c1.codcomanda = c.codcomanda
                 inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                 inner join iesiri1 i1 on i1.codcmdint1 = c1.codcomanda1
                 inner join iesiri i on i1.codies = i.codies
                 left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                             from comanda1 cc1
                                  inner join comanda cc on cc1.codcomanda = cc.codcomanda
                                  inner join cmdprodmat prodc on cc1.codcomanda1 = prodc.codcomanda1 and nvl(prodc.tip,0) = 0
                                  inner join intrprodlink ilc on prodc.codcmdprodmat = ilc.codliniecomanda
                                  inner join intrari1 i1c on ilc.codintr1 = i1c.codintr1
                                  inner join intrari ic on i1c.codintr = ic.codintr
                             where nvl(cc.inchisa, 0) = 0 and nvl(cc.blocat,0) = 0 and nvl(cc.operat,0) = 1 and nvl(cc.anulat,0) = 0 and cc.an*12+cc.luna &lt;= vAnLuna
                                   and nvl(ic.blocat,0) = 0 and nvl(ic.operat,0) = 1 and nvl(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                             group by prodc.codcmdprodmat) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
                 left  join livr l on i.codies = l.codies
                 left  join livr1 l1 on l1.codies1 = i1.codies1 and l.codlivr = l1.codlivr
                 left  join nirstoc ns on l1.codnirstoc = ns.codnirstoc
                 left  join centrecost cc on i1.codcentru = cc.codcentru
                 left  join iesprodlink il on i1.codies1 = il.codies1
                 left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                          from comanda1 c1
                               inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                               inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
                               inner join intrari1 i1 on il.codintr1 = i1.codintr1
                               inner join intrari i on i1.codintr = i.codintr
                          where prod.rest &lt;= 0
                          group by c1.codcomanda1) Stinse on Stinse.codcomanda1 = c1.codcomanda1
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and nvl(cc.tipaloc,0) = 0
                  and ((prod.cant - nvl(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - nvl(RestDePredat.Rest,0) = 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and c.codgest = vCodGest
                  and c1.codcomanda1 = v_rec.CodComanda1
            group by il.codcmdprodmat, i1.codies1, c1.codcomanda1 )
          )
          select sum(round(x.valoare,7)) valoare
          from (
          select (consumuri.cant - nvl(predari.cant, 0)) * consumuri.pret valoare, consumuri.codcomanda1, consumuri.codies1, consumuri.codcmdprodmat
          from consumuri
               left join predari on consumuri.codcmdprodmat = predari.codcmdprodmat
          where consumuri.cant - nvl(predari.cant, 0) &gt; 0 ) x
            inner join comanda1 c1 on c1.codcomanda1 = x.codcomanda1
            inner join comanda c on c1.codcomanda = c.codcomanda
            inner join nartobj obj on c1.codobiect = obj.codobiect
            inner join iesiri1 i1 on i1.codies1 = x.codies1
            inner join nartobj objmat on i1.codobiect = objmat.codobiect
            left  join cmdprodmat mat on x.codcmdprodmat = mat.codcmdprodmat
          group by c1.codcomanda1, obj.denumire, c.nrdoc, c.datadoc) loop

          vSterg := False;
          update prodnet1 set
            VALMAT   = v_tmp.valoare,
            VALMAN   = 0
          where codprodnet1 = v_rec.codprodnet1;

        end loop;
        if vSterg then delete prodnet1 where codprodnet1 = v_rec.codprodnet1; end if;
      end if;
    else
      -- manopera
      if v_rec.codcmdprodmat &gt; 0 then
        -- linie detaliata
        vSterg := True;
        for v_tmp in (
          with predari as (
            select man.cant * sum(il.cant)/prod.cant cant, man.codcmdprodman
            from intrprodlink il
                 inner join intrari1 i1 on i1.codintr1 = il.codintr1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join cmdprodmat prod on il.codliniecomanda = prod.codcmdprodmat
                 inner join cmdprodman man on prod.codcomanda1 = man.codcomanda1
                 inner join comanda1 c1 on c1.codcomanda1 = man.codcomanda1
                 inner join comanda c on c1.codcomanda = c.codcomanda
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and c.codgest = vCodGest
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and man.codcmdprodman = v_rec.codcmdprodmat
            group by man.codcmdprodman, man.cant, prod.cant
          ),
          consumuri as ( select nvl(cant,0) cant, case when nvl(cant,0) = 0 then 0 else val/cant end pret, codcmdprodman from (
            select sum(P2.realizat) cant, sum(T1.Tarif * PM.TU * P2.REALIZAT / 60) val, man.codcmdprodman
            from comanda1 c1
                 inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                 inner join comanda c on c1.codcomanda = c.codcomanda
                 inner join cmdprodman man on c1.codcomanda1 = man.codcomanda1
                 inner join manprodlink ml on man.codcmdprodman = ml.codcmdprodman
                 inner join raportp2 p2 on ml.codraportp2 = p2.codraportp2
                 inner join raportp1 p1 on p2.codraportp1 = p1.codraportp1
                 inner join raportp p on p.codraportp = p1.codraportp
                 INNER JOIN ProdMan PM ON PM.CodMan = P2.CodMan
                 INNER JOIN Tarifeman1 T1 on T1.CodTarif = PM.codTarif AND vAnLuna BETWEEN t1.alstart AND t1.alstop
                 left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                             from comanda1 cc1
                                  inner join comanda cc on cc1.codcomanda = cc.codcomanda
                                  inner join cmdprodmat prodc on cc1.codcomanda1 = prodc.codcomanda1 and nvl(prodc.tip,0) = 0
                                  inner join intrprodlink ilc on prodc.codcmdprodmat = ilc.codliniecomanda
                                  inner join intrari1 i1c on ilc.codintr1 = i1c.codintr1
                                  inner join intrari ic on i1c.codintr = ic.codintr
                             where nvl(cc.inchisa, 0) = 0 and nvl(cc.blocat,0) = 0 and nvl(cc.operat,0) = 1 and nvl(cc.anulat,0) = 0 and cc.an*12+cc.luna &lt;= vAnLuna
                                   and nvl(ic.blocat,0) = 0 and nvl(ic.operat,0) = 1 and nvl(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                             group by prodc.codcmdprodmat) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
                 left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                          from comanda1 c1
                               inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                               inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
                               inner join intrari1 i1 on il.codintr1 = i1.codintr1
                               inner join intrari i on i1.codintr = i.codintr
                          where prod.rest &lt;= 0
                          group by c1.codcomanda1) Stinse on Stinse.codcomanda1 = c1.codcomanda1
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and ((prod.cant - nvl(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - nvl(RestDePredat.Rest,0) = 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
                  and c.an*12+c.luna &lt;= vAnLuna
                  and p.an*12+p.luna &lt;= vAnLuna
                  and c.codgest = vCodGest
                  and man.codcmdprodman = v_rec.codcmdprodmat
            group by man.codcmdprodman )
          )
          select round(x.valoare,7) valoare, round(x.difcant,7) difcant, round(x.cant,7) cant, round(x.cantReal,7) cantreal
          from (
          select (consumuri.cant - nvl(predari.cant, 0)) * consumuri.pret valoare, consumuri.codcmdprodman, consumuri.cant - nvl(predari.cant, 0) difcant, consumuri.cant CantReal, nvl(predari.cant, 0) cant
          from consumuri
               left join predari on consumuri.codcmdprodman = predari.codcmdprodman
          where consumuri.cant - nvl(predari.cant, 0) &gt; 0 ) x
            inner join cmdprodman man on x.codcmdprodman = man.codcmdprodman
            inner join comanda1 c1 on c1.codcomanda1 = man.codcomanda1
            inner join comanda c on c1.codcomanda = c.codcomanda
            inner join nartobj obj on c1.codobiect = obj.codobiect
            inner join noper op on op.codop = man.codop ) loop

          vSterg := False;
          update prodnet1 set
            VALMAT   = 0,
            VALMAN   = v_tmp.valoare,
            DIFCANT  = v_tmp.difcant,
            CANTREAL = v_tmp.cantreal,
            PRET     = case when v_tmp.difcant &lt;&gt; 0 then round(v_tmp.valoare/v_tmp.difcant,2) else 0 end,
            DIRTY    = 0
          where codprodnet1 = v_rec.codprodnet1;
          update prodnet1 set valman = pret * difcant where codprodnet1 = v_rec.codprodnet1;
        end loop;
        if vSterg then delete prodnet1 where codprodnet1 = v_rec.codprodnet1; end if;
      else
        --linie centralizata
        vSterg := True;
        for v_tmp in (
          with predari as (
            select sum(cant) cant, codcomanda1 from (
            select man.cant * sum(il.cant)/prod.cant cant, c1.codcomanda1
            from intrprodlink il
                 inner join intrari1 i1 on i1.codintr1 = il.codintr1
                 inner join intrari i on i1.codintr = i.codintr
                 inner join cmdprodmat prod on il.codliniecomanda = prod.codcmdprodmat
                 inner join cmdprodman man on prod.codcomanda1 = man.codcomanda1
                 inner join comanda1 c1 on c1.codcomanda1 = man.codcomanda1
                 inner join comanda c on c1.codcomanda = c.codcomanda
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and c.codgest = vCodGest
                  and c.an*12+c.luna &lt;= vAnLuna
                  and i.an*12+i.luna &lt;= vAnLuna
                  and c1.codcomanda1 = v_Rec.CodComanda1
            group by man.cant, prod.cant, c1.codcomanda1 )
            group by codcomanda1
          ),
          consumuri as ( select nvl(cant,0) cant, case when nvl(cant,0) = 0 then 0 else val/cant end pret, codcomanda1 from (
            select sum(P2.realizat) cant, sum(T1.Tarif * PM.TU * P2.REALIZAT / 60) val, c1.codcomanda1
            from comanda1 c1
                 inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                 inner join comanda c on c1.codcomanda = c.codcomanda
                 inner join cmdprodman man on c1.codcomanda1 = man.codcomanda1
                 inner join manprodlink ml on man.codcmdprodman = ml.codcmdprodman
                 inner join raportp2 p2 on ml.codraportp2 = p2.codraportp2
                 inner join raportp1 p1 on p2.codraportp1 = p1.codraportp1
                 inner join raportp p on p.codraportp = p1.codraportp
                 INNER JOIN ProdMan PM ON PM.CodMan = P2.CodMan
                 INNER JOIN Tarifeman1 T1 on T1.CodTarif = PM.codTarif AND vAnLuna BETWEEN t1.alstart AND t1.alstop
                 left  join (select sum(ilc.cant) Rest, prodc.codcmdprodmat
                             from comanda1 cc1
                                  inner join comanda cc on cc1.codcomanda = cc.codcomanda
                                  inner join cmdprodmat prodc on cc1.codcomanda1 = prodc.codcomanda1 and nvl(prodc.tip,0) = 0
                                  inner join intrprodlink ilc on prodc.codcmdprodmat = ilc.codliniecomanda
                                  inner join intrari1 i1c on ilc.codintr1 = i1c.codintr1
                                  inner join intrari ic on i1c.codintr = ic.codintr
                             where nvl(cc.inchisa, 0) = 0 and nvl(cc.blocat,0) = 0 and nvl(cc.operat,0) = 1 and nvl(cc.anulat,0) = 0 and cc.an*12+cc.luna &lt;= vAnLuna
                                   and nvl(ic.blocat,0) = 0 and nvl(ic.operat,0) = 1 and nvl(ic.anulat,0) = 0 and ic.an*12+ic.luna &lt;= vAnLuna
                             group by prodc.codcmdprodmat) RestDePredat on RestDePredat.codcmdprodmat = prod.codcmdprodmat
                 left  JOIN (select c1.codcomanda1, max(i.an*12+i.luna) AnLunaFinal
                          from comanda1 c1
                               inner join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
                               inner join intrprodlink il on prod.codcmdprodmat = il.codliniecomanda
                               inner join intrari1 i1 on il.codintr1 = i1.codintr1
                               inner join intrari i on i1.codintr = i.codintr
                          where prod.rest &lt;=0
                          group by c1.codcomanda1) Stinse on Stinse.codcomanda1 = c1.codcomanda1
            where nvl(c.inchisa, 0) = 0 and nvl(c.blocat,0) = 0 and nvl(c.operat,0) = 1 and nvl(c.anulat,0) = 0
                  and ((prod.cant - nvl(RestDePredat.Rest,0) &gt; 0) or ((prod.cant - nvl(RestDePredat.Rest,0) = 0) and (Stinse.AnLunaFinal &gt; vAnLuna)))
                  and c.an*12+c.luna &lt;= vAnLuna
                  and p.an*12+p.luna &lt;= vAnLuna
                  and c.codgest = vCodGest
                  and c1.codcomanda1 = v_rec.CodComanda1
            group by c1.codcomanda1 )
          )
          select round(sum(x.valoare),7) valoare
          from (
          select sum((consumuri.cant - nvl(predari.cant, 0)) * consumuri.pret) valoare, consumuri.codcomanda1
          from consumuri
               left join predari on consumuri.codcomanda1 = predari.codcomanda1
          where consumuri.cant - nvl(predari.cant, 0) &gt; 0 group by consumuri.codcomanda1 ) x
            inner join comanda1 c1 on c1.codcomanda1 = x.codcomanda1
            inner join comanda c on c1.codcomanda = c.codcomanda
            inner join nartobj obj on c1.codobiect = obj.codobiect
          group by c1.codcomanda1, c.nrdoc, c.datadoc, obj.denumire) loop

          vSterg := False;
          update prodnet1 set
            VALMAT   = 0,
            VALMAN   = v_tmp.valoare
          where codprodnet1 = v_rec.codprodnet1;
          if vSterg then delete prodnet1 where codprodnet1 = v_rec.codprodnet1; end if;
        end loop;
      end if;
    end if;
  end loop;
  if NVL(DoCommit,1) = 1 then
    commit;
  end if;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT codprodnet INTO Tmp FROM prodnet WHERE codprodnet = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);

  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 71) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;



    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;

  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 71;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 71;



  DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 71);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 71;


	DELETE FROM prodnet1 WHERE codprodnet = RecId ;
 DELETE FROM prodnet  WHERE codprodnet = RecId ;

  NotifyModif(2, RecId, &apos;PRODNET&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_prodnet FIELDS( codprodnet ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO  TMP_prodnet(Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest, Codcentru)
    ( SELECT Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest, CodCentru
      FROM prodnet WHERE codprodnet = RecId );

  insert into tmp_prodnet1(codprodnet1,codprodnet,Tip,coddoc1,explicatii,valmat,valman,CODCENTRU, CODANALIZANOD,CODCMDPRODMAT,
              DIFCANT,CANTREAL, CANT, PRET, denumire, nrdoc, datadoc, material, codies1)
  (select pn1.codprodnet1,pn1.codprodnet,nvl(pn1.Tip,0),pn1.coddoc1,pn1.explicatii,pn1.valmat,pn1.valman,pn1.CODCENTRU, pn1.CODANALIZANOD,pn1.CODCMDPRODMAT,
          pn1.DIFCANT, pn1.CANTREAL, Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0), pn1.Pret,
          obj.denumire, c.nrdoc, c.datadoc, objmat.denumire, pn1.codies1
   from prodnet1 pn1
        left join comanda1 c1 on pn1.coddoc1   = c1.codcomanda1
        left join comanda   c on c1.codcomanda = c.codcomanda
        left join nartobj obj on obj.codobiect = c1.codobiect
        left join cmdprodmat mat on pn1.codcmdprodmat = mat.codcmdprodmat
        left join iesiri1 i1 on pn1.codies1 = i1.codies1
        left join nartobj objmat on i1.codobiect = objmat.codobiect
   where codprodnet = recid and nvl(pn1.tip,0) = 0
   union all
   select pn1.codprodnet1,
          pn1.codprodnet,
          nvl(pn1.Tip,0),
          pn1.coddoc1,
          pn1.explicatii,
          pn1.valmat,
          pn1.valman,
          pn1.CODCENTRU,
          pn1.CODANALIZANOD,
          pn1.CODCMDPRODMAT,
          pn1.DIFCANT,
          pn1.CANTREAL,
          Nvl(pn1.CANTREAL,0)-Nvl(pn1.DIFCANT,0),
          pn1.Pret,
          obj.denumire,
          c.nrdoc,
          c.datadoc,
          op.denumire,
          pn1.codies1
   from prodnet1 pn1
        left join comanda1 c1 on pn1.coddoc1   = c1.codcomanda1
        left join nartobj obj on obj.codobiect = c1.codobiect
        left join comanda   c on c1.codcomanda = c.codcomanda
        left join cmdprodman man on pn1.codcmdprodmat = man.codcmdprodman
        left join noper op on op.codop = man.codop
   where codprodnet = recid and nvl(pn1.tip,0) = 1
   );

   INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = 71 AND CODDOC = RECID);
   INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 71 AND CODDOC = RECID);

   DELETE TMP_RULAJ;


  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 VcOD NUMBER(20);
 NR   NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT  codprodnet INTO RecId FROM TMP_prodnet;

    UPDATE prodnet SET ( An, Luna, Obs, Tip, Subunitatea, CodGest, CodCentru )
       = ( SELECT An, Luna, Obs, Tip, Subunitatea, CodGest, CodCentru
          FROM TMP_prodnet )
      WHERE codprodnet = RecId;

    DELETE FROM PRODNET1
    WHERE CodPRODNET = RecID
      AND CodPRODNET1 NOT IN (SELECT CodPRODNET1 FROM TMP_PRODNET1);

    FOR v_rec IN (SELECT * FROM TMP_PRODNET1) LOOP
      IF NVL(v_rec.CodPRODNET1, 0) &gt; 0
      THEN
        UPDATE PRODNET1 SET
          Tip        = V_REC.Tip,
          coddoc1    = V_REC.CODDOC1,
          explicatii = V_REC.EXPLICATII,
          valmat     = V_REC.VALMAT,
          valman     = V_rEC.Valman,
          CodGest    = v_rec.CodGest,
          CODCENTRU  = v_rec.CODCENTRU,
          CODANALIZANOD  = V_REC.CODANALIZANOD,
          CODCMDPRODMAT  = V_REC.CODCMDPRODMAT ,
          PRET           = V_REC.PRET,
          DIFCANT        = V_REC.DIFCANT,
          CANTREAL       = V_REC.CANTREAL,
          codies1        = v_rec.codies1
        WHERE CODPRODNET1  = v_rec.CODPRODNET1;
      ELSE
        SELECT seq_PRODNET1_CodPRODNET1.NEXTVAL INTO vCod FROM dual;

        INSERT INTO  PRODNET1 (
          codprodnet1,codprodnet,Tip,coddoc1,explicatii,valmat,valman, CodGest, CODCENTRU, CODANALIZANOD,CODCMDPRODMAT,CANTREAL,DIFCANT, PRET, codies1
        )
        VALUES (
          vCod , RecId, V_REC.Tip,V_REC.coddoc1,V_REC.explicatii,V_REC.valmat,V_REC.valman, v_rec.CodGest, v_rec.CODCENTRU, v_rec.CODANALIZANOD,v_rec.CODCMDPRODMAT,v_rec.CANTREAL,v_rec.DIFCANT, v_rec.PRET,
          v_rec.codies1
        );
      END IF;
    END LOOP;


-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = 71 AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    CODANALIZANOD = v_rec.CODANALIZANOD,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD, DATADOC, DOCUMENT )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD, V_REC.DATADOC, V_REC.DOCUMENT);
 END IF;
END LOOP;



-- detail JURNAL

    DELETE FROM JURNAL WHERE TIPDOC = 71 AND CODDOC = RECID AND CODJURNAL NOT IN
    (SELECT CODJURNAL FROM TMP_JURNAl);

    FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
     IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC,
        INDEXLOCAL = V_REC.INDEXLOCAL,
        CONTD      = V_REC.CONTD,
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE,
        VALOAREV   = V_REC.VALOAREV,
        OBS        = V_REC.OBS,
        AN         = V_REC.AN,
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        CODCENTRU  = v_rec.CODCENTRU,
        CODANALIZANOD  = V_REC.CODANALIZANOD,
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT
      WHERE
        CODJURNAL = V_REC.CODJURNAl;
     ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT)
     VALUES
     ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.CODCENTRU, V_REC.CODANALIZANOD,V_REC.DATADOC, V_REC.DOCUMENT);
     END IF;
    END LOOP;
  ELSE  -- INSERT

    SELECT seq_PRODNET_CodPRODNET.NextVal INTO RecId FROM DUAL;

    INSERT INTO PRODNET
      (Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest, CodCentru)
    SELECT
      RECID, An, Luna, Obs, Tip, Subunitatea, CodGest, CodCentru
    FROM TMP_PRODNET;

    FOR V_REC IN (SELECT * FROM TMP_PRODNET1)
    LOOP
      SELECT seq_PRODNET1_CodPRODNET1.Nextval INTO VCOD FROM DUAL;

      INSERT INTO PRODNET1 (
        codprodnet1,codprodnet,tip,coddoc1,explicatii,valmat,valman,CodGest, CODCENTRU, CODANALIZANOD,CODCMDPRODMAT,CANTREAL,DIFCANT, PRET,CODies1 )
      VALUES(
        vCod , RecId, V_REC.tip,V_REC.coddoc1,V_REC.explicatii,V_REC.valmat,V_REC.valman,v_rec.CodGest, v_Rec.CODCENTRU, v_Rec.CODANALIZANOD,v_Rec.CODCMDPRODMAT,v_Rec.CANTREAL,v_Rec.DIFCANT, v_rec.PRET,
        V_REC.CODies1
      );

    END LOOP;


    INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT )
    (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC,DOCUMENT FROM TMP_JURNAL1);



   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT)
   ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, CODANALIZANOD,DATADOC, DOCUMENT FROM TMP_JURNAL);


  END IF;



  -- ACTUALIZARE RULAJE CONTURI
   FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;

     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
     WHERE
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;

         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;

   END LOOP;


  PKG_GLOBALS.MarkDirtyJurnal;

  NotifyModif(Operation, RecId, &apos;PRODNET&apos;);

  COMMIT;
END;

end pkg_prodnet;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72DEDEA634B648510811A3ADCE1CF334901D8824</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROGRAMF IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_39&apos;;
vCodProgramF number(20) := 0;
vDinGoTo boolean := False;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := aCARNET;
  NRDOC_I     := aNRDOC;
END;

procedure UpdatePFManevra(dDela in varchar2, dPanaLa in varchar2, oDeLa in varchar2, oPanaLa in varchar2, dCodProgramf in number, vAllGest in number, vAllTipCont in number) is
begin
  delete tmp_programf_manevra;
  insert into tmp_programf_manevra(codprogramf, vdela, vpanala, vdelaora, vpanalaora, tipdurata, AllGest, AllTipCont)
  values (dCodProgramf, to_date(dDela, &apos;DD.MM.YYYY&apos;), to_date(dPanaLa, &apos;DD.MM.YYYY&apos;), to_date(oDeLa, &apos;HH24&apos;), to_date(oPanaLa, &apos;HH24&apos;), 0, vAllGest, vAllTipCont);
end;

procedure ClearPF1Manevra is
begin
  delete tmp_programf1_manevra;
end;

procedure ClearPFManOp is
begin
  delete tmp_programfman_manevra;
end;

procedure InsertPF1Manevra(vCodProgramF in number, vCodComanda1 in number, vCodGest in number, vPrioritate in number, vTermen in varchar2, vCantProgramat in number, vCodCmdProdMan in number) is
begin
  insert into tmp_programf1_manevra(codprogramf, codcomanda1, codgest, prioritate, termenexec, cantprogramat, codcmdprodman, termen)
  values (vCodProgramF, vCodComanda1, vCodGest, vPrioritate, to_date(vTermen, &apos;DD.MM.YYYY&apos;), vCantProgramat, vCodCmdPRodMan, to_date(vTermen, &apos;DD.MM.YYYY&apos;));
end;

procedure InsertPFManOp(vCodProgramF in number, vCantProgramat in number, vCodCmdProdMan in number) is
begin
  insert into tmp_programfman_manevra(codprogramf, cant, codcmdprodman)
  values (vCodProgramF, vCantProgramat, vCodCmdProdMan);
end;

FUNCTION ESTE_SECTIA(aCodProgramF in number, aCodGest IN NUMBER) return number is
aCount NUMBER(20);
begin
  aCount := 0;
  select count(*) into aCount from programf1
  where codprogramf = aCodProgramF and codgest = aCodGest;
  if aCount &gt; 0 then
    aCount := 1;
  end if;
  return aCount;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20);
BEGIN
  SELECT CODPROGRAMF INTO TMP FROM PROGRAMF WHERE CODPROGRAMF = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCarnetDoc  number(20);
aNrDoc      NUMBER (20);
BEGIN
  SP_LOCKRECORD(RECID);

  SELECT CarnetDoc, NrDoc INTO aCarnetDoc, aNrDoc
  FROM ProgramF
  WHERE CodProgramF = recId;

  DELETE FROM PROGRAMFSDV WHERE CODPROGRAMF = RECID;
  for v_rec in (select codprogramf1 from programf1 where codprogramf = recid) loop
    update intrprodlink set codprogramf1 = null where codprogramf1 = v_rec.codprogramf1;
    update iesprodlink set codprogramf1 = null where codprogramf1 = v_rec.codprogramf1;
  end loop;
  DELETE FROM PROGRAMF1   WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMF    WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMFSDV WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMFMAN WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMFLMC WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMFCONT WHERE CODPROGRAMF = RECID;
  DELETE FROM PROGRAMFGEST WHERE CODPROGRAMF = RECID;

  if aCarnetDoc &gt; 0 then
    PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
  end if;

  NotifyModif(2, RecId, &apos;CODPROGRAMF&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PROGRAMF(CODPROGRAMF) VALUES(0);
  DELETE FROM TMP_PF_MAT_CMD;
  DELETE FROM TMP_PF_SDV_CMD;
  DELETE FROM TMP_PF_LOCM_CMD;
  DELETE FROM TMP_PF_MAN_CMD;
  DELETE FROM TMP_PF_MAT_GEST;
  DELETE FROM TMP_PF_SDV_GEST;
  DELETE FROM TMP_PF_LOCM_GEST;
  DELETE FROM TMP_PF_MAN_GEST;
  DELETE FROM TMP_PF_MAT;
  DELETE FROM TMP_PF_SDV;
  DELETE FROM TMP_PF_LOCM;
  DELETE FROM TMP_PROGRAMF1_MANEVRA;
  DELETE FROM TMP_PF_MAN;
  COMMIT;
END;

FUNCTION GETDISPONIBIL(aOIA IN number, NS IN NUMBER, DS IN NUMBER, DSTART IN DATE, aDSTOP IN DATE, aOSTART IN NUMBER, aOSTOP IN NUMBER, aZILENELUC IN NUMBER, CODGEST IN NUMBER, aCODLOC IN NUMBER) RETURN NUMBER IS
NRLM NUMBER(10);
DISPZILNIC NUMBER(10);
OSA NUMBER(10);
STOPA NUMBER(10);
DISPPROGRAM NUMBER(10);
ZNELUC NUMBER(10);
ZLP NUMBER(10);
OIA NUMBER(10);
OSTART NUMBER(10);
OSTOP NUMBER(10);
DSTOP DATE;
BEGIN
  OIA := aOIA;
  OSTART := aOSTART;
  if aOSTOP = 0 then
    OSTOP := 24;
    DSTOP := aDSTOP -1;
  else
    OSTOP := aOSTOP;
    DSTOP := aDSTOP;
  end if;

  ZNELUC := (DSTOP - DSTART) + 1 - aZILENELUC;
  SELECT COUNT(DISTINCT LM1.CODLOC1) INTO NRLM
  FROM LOCMUNCA LM
       INNER JOIN LOCMUNCA1 LM1 ON LM.CODLOC = LM1.CODLOC
       LEFT JOIN  MIFIX1 MF1 ON MF1.CODMIFIX   = LM1.CODMIFIX
       LEFT JOIN  NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
       LEFT JOIN  NIR        ON NIR.CODNIR = NS.CODNIR
  WHERE NIR.GEST = CODGEST
    AND LM.CODLOC = aCODLOC
    AND MF1.Anstart*12 + MF1.lunastart = (select max(anstart*12+lunastart) from mifix1 where codmifix = LM1.codmifix);

  DISPZILNIC := NS * DS;
  STOPA := OIA + DISPZILNIC - 24;
  IF STOPA &gt; 0 THEN
    OSA := STOPA;
    IF DSTOP &gt; DSTART THEN
      ZLP := DSTOP - DSTART + 1 - ZNELUC;
      IF ZLP &gt; 0 THEN
        IF OSTART &gt;= OIA THEN
          IF OSTOP &gt;= OSA THEN
            IF OSTOP &gt;= OIA THEN
              DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OSTOP)+(OIA-OSA))*NRLM;
            ELSE
              DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OSTOP)+(OIA-OSA)+(OIA-OSTOP))*NRLM;
            END IF;
          ELSE
            DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OSTOP)+2*(OIA-OSA))*NRLM;
          END IF;
        ELSE
          IF OSTART &gt;= OSA THEN
            IF OSTOP &gt;= OSA THEN
              IF OSTOP &gt;= OIA THEN
                DISPPROGRAM := (DISPZILNIC*ZLP-OSA-(24-OSTOP))*NRLM;
              ELSE
                DISPPROGRAM := (DISPZILNIC*ZLP-OSA-(24-OIA))*NRLM;
              END IF;
            ELSE
              DISPPROGRAM := (DISPZILNIC*ZLP-OSA-(24-OSTOP)+(OIA-OSA))*NRLM;
            END IF;
          ELSE
            IF OSTOP &gt;= OSA THEN
              IF OSTOP &gt;= OIA THEN
                DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OSTOP))*NRLM;
              ELSE
                DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OIA))*NRLM;
              END IF;
            ELSE
              DISPPROGRAM := (DISPZILNIC*ZLP-OSTART-(24-OSTOP)+(OIA-OSA))*NRLM;
            END IF;
          END IF;
        END IF;
      ELSE
        DISPPROGRAM := 0;
      END IF;
    ELSE
      IF OSTART &gt;= OIA THEN
        DISPPROGRAM := (OSTOP-OSTART)*NRLM;
      ELSE
        DISPPROGRAM := (OSTOP-OIA)*NRLM;
      END IF;
    END IF;
  ELSE
    OSA := 24 + STOPA;
    IF DSTOP &gt; DSTART THEN
      ZLP := DSTOP - DSTART + 1 - ZNELUC;
      IF ZLP &gt; 0 THEN
        IF OSTART &gt;= OIA THEN
          IF OSTART &gt;= OSA THEN
            IF OSTOP &gt;= OSA THEN
              DISPPROGRAM := (DISPZILNIC*(ZLP-1))*NRLM;
            ELSE
              IF OSTOP &gt;= OIA THEN
                DISPPROGRAM := (DISPZILNIC*(ZLP-1)-(OSA-OSTOP))*NRLM;
              ELSE
                DISPPROGRAM := (DISPZILNIC*(ZLP-2))*NRLM;
              END IF;
            END IF;
          ELSE
            IF OSTOP &gt;= OSA THEN
              DISPPROGRAM := (DISPZILNIC*ZLP-(OSTART-OIA))*NRLM;
            ELSE
              IF OSTOP &gt;= OIA THEN
                DISPPROGRAM := (DISPZILNIC*(ZLP)-(OSTART-OIA)-(OSA-OSTOP))*NRLM;
              ELSE
                DISPPROGRAM := (DISPZILNIC*(ZLP-1)-(OSTART-OIA))*NRLM;
              END IF;
            END IF;
          END IF;
        ELSE
          IF OSTART &gt;= OSA THEN
            DISPPROGRAM := (DISPZILNIC*ZLP)*NRLM;
          ELSE
            IF OSTOP &gt;= OIA THEN
              DISPPROGRAM := (DISPZILNIC*ZLP-(OSA-OSTOP))*NRLM;
            ELSE
              DISPPROGRAM := (DISPZILNIC*(ZLP-1))*NRLM;
            END IF;
          END IF;
        END IF;
      ELSE
        DISPPROGRAM := 0;
      END IF;
    ELSE
      IF OSTART &gt;= OIA THEN
        IF OSTART &gt;= OSA THEN
          DISPPROGRAM := 0;
        ELSE
          IF OSTOP &gt;= OSA THEN
            DISPPROGRAM := (OSA-OSTART)*NRLM;
          ELSE
            DISPPROGRAM := (OSTOP-OSTART)*NRLM;
          END IF;
        END IF;
      ELSE
        IF OSTOP &gt;= OSA THEN
          DISPPROGRAM := DISPZILNIC*NRLM;
        ELSE
          DISPPROGRAM := (DISPZILNIC-(OSA-OSTOP))*NRLM;
        END IF;
      END IF;
    END IF;
  END IF;

  RETURN DISPPROGRAM;
END;

PROCEDURE CALCUL_CMD(XT IN VARCHAR2, YT IN VARCHAR2) IS
--PRAGMA AUTONOMOUS_TRANSACTION;
vDATASTART DATE;
vDATASTOP  DATE;
vZILEN NUMBER;
BEGIN
  SELECT VDELA INTO vDATASTART FROM TMP_PROGRAMF_MANEVRA;
  SELECT VPANALA INTO vDATASTOP FROM TMP_PROGRAMF_MANEVRA;

  SELECT
    count(zn1.data) INTO vZILEN
  FROM
    zineluc1 zn1
  where zn1.data between (select VDELA from tmp_programf_manevra where rownum = 1)
        AND (select VpanaLA from tmp_programf_manevra where rownum = 1);

  DELETE FROM TMP_PF_MAT_CMD;
  DELETE FROM TMP_PF_SDV_CMD;
  DELETE FROM TMP_PF_LOCM_CMD;
  DELETE FROM TMP_PF_MAN_CMD;

  if PKG_CATEGCONST.GetValConstanta(&apos;RAPORDMAN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    INSERT INTO TMP_PF_MAT_CMD
     (NRDOC,DATADOC,DENOBJ,CODEXTERN,DEN_UM,CANT,CODGEST,CODOBIECT,STOCREZ, CANTPROD, PRIORITATE,
      CODCOMANDA1, D1, D2, D3)
    SELECT
      ROUND(C.NRDOC + c1.indexlocal / 1000, 3),
      C.DATADOC,
      NOBJ.DENUMIRE,
      NOBJ.CODEXTERN,
      NUM1.DEN_UM1,
      ROUND(CMD.CANT * TMP.CANT/ MAN.CANT, 2),
      C.CODGEST,
      BAZAM.CODOBIECT,
      NVL(REZ.CANTREZERVAT,0),
      PF1.Cantprogramat,
      PF1.Prioritate,
      C1.CODCOMANDA1,
      C1.D1,
      C1.D2,
      C1.D3
    FROM TMP_PROGRAMFMAN_MANEVRA TMP
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = TMP.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA AND C.TIPDOC = 53
         INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
         INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
         INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
         INNER JOIN CMDPRODMAT CMD ON CMD.CODCMDPRODMAN = TMP.CODCMDPRODMAN
         INNER JOIN TMP_PF_MAT BAZAM ON CMD.CODOBIECT = BAZAM.CODOBIECT
         INNER JOIN TMP_PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1 AND PF1.CODPROGRAMF = TMP.CODPROGRAMF
         LEFT  JOIN (SELECT REZ.CODCMDPRODMAT, SUM(REZ.REST) CANTREZERVAT
                     FROM REZERVATS REZ
                     GROUP BY REZ.CODCMDPRODMAT) REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
    WHERE (C1.CONSUM = 1 AND CMD.TIP = 1) OR (C1.CONSUM = 2 AND CMD.TIP IN (0,1));

    INSERT INTO TMP_PF_SDV_CMD (NRCMD, PRIORITATE, DEN_OBIECT, CODEXTERN, UM, CANTPROGRAMAT, SECTIE, CODOBIECT)
    SELECT ROUND(C.NRDOC + c1.indexlocal / 1000, 3), PF1.PRIORITATE, OBJ.DENUMIRE, OBJ.CODEXTERN, NUM.DEN_UM, PF1.CANTPROGRAMAT, C.CODGEST SECTIE, SDV.CODSDV
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
         INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
         INNER JOIN PRODSDV SDV ON SDV.CODPRODMAN = MAN.CODMAN
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODOBIECT
         INNER JOIN NART A ON OBJ.CODARTICOL = A.CODARTICOL
         INNER JOIN NUM ON NUM.CODUM = A.UM
         INNER JOIN TMP_PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1 AND PF1.CODPROGRAMF = PFM.CODPROGRAMF;

    INSERT INTO TMP_PF_LOCM_CMD(
      CODLMC, CODPROGRAMF, CODGEST, CODLOC, CODCOMANDA1, DATAPROGRAMARE,
      NRCMD, PRIORITATE, DEN_OBIECT, CODEXTERN,
      NECESAR, NECESARM,
      DEN_UM, CANTPROD, CODOP)
    SELECT
      - ROWNUM, PF1.CODPROGRAMF, C.CODGEST, MAN.CODLOC, PF1.CODCOMANDA1, vDataStart,
      ROUND(C.NRDOC + c1.indexlocal / 1000, 3),
      PF1.PRIORITATE,
      OBJ.DENUMIRE,
      OBJ.CODEXTERN,
      ROUND(PFM.CANT * NVL(MAN.TPI, 0) + PFM.CANT * MAN.TU / 60, 2) NECESAR,
      NVL(ROUND(PFM.CANT * NVL(MAN.TPI, 0) + PFM.CANT * MAN.TU, 2),0) NECESARM,
      NUM1.DEN_UM1,
      PF1.CANTPROGRAMAT,
      MAN.CODOP
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON PFM.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
         INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
         INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODOBIECT
         INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
         INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
         INNER JOIN NGEST PG ON PG.CODGEST = C.CODGEST
         INNER JOIN TMP_PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1 AND PF1.CODPROGRAMF = PFM.CODPROGRAMF;

    INSERT INTO TMP_PF_MAN_CMD
     (CODOP, CODGEST, CODCOMANDA1,
      DATADOC, NRDOC, DENUMIRE,
      CODEXTERN, NECESAR, NECESARM,
      DEN_UM, CANTPROD, VALOARE, PRIORITATE, OPERATII, CODCMDPRODMAN)
    SELECT
      MAN.CODOP, C.CODGEST, C1.CODCOMANDA1, C.DATADOC,ROUND(C.NRDOC + c1.indexlocal / 1000, 3),OBJ.DENUMIRE,OBJ.CODEXTERN,
      round(TMP.CANT * nvl(MAN.TPI, 0) + TMP.CANT * nvl(MAN.TU, 0) / 60, 3),
      round(TMP.CANT * nvl(MAN.TPI, 0) + TMP.CANT * nvl(MAN.TU, 0), 3),
      NUM1.DEN_UM1,
      PF1.CANTPROGRAMAT,
      round(TMP.CANT * nvl(MAN.TPI, 0) + TMP.CANT * nvl(MAN.TU, 0) / 60, 3) * TMPM.TARIF,
      PF1.Prioritate,
      MAN.CANT, PFM.CODCMDPRODMAN
    FROM TMP_PROGRAMFMAN_MANEVRA TMP
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = TMP.CODCMDPRODMAN
         INNER JOIN PROGRAMFMAN PFM ON PFM.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN NARTOBJ OBJ ON C1.CODOBIECT = OBJ.CODOBIECT
         INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
         INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
         LEFT  JOIN TMP_PF_MAN TMPM ON TMPM.CODOP = MAN.CODOP
         LEFT  JOIN TMP_PROGRAMF1 PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1 AND PF1.CODPROGRAMF = TMP.CODPROGRAMF;
  else
    INSERT INTO TMP_PF_MAT_CMD
     (NRDOC,DATADOC,DENOBJ,CODEXTERN,DEN_UM,CANT,CODGEST,CODOBIECT,STOCREZ, CANTPROD, PRIORITATE,
      CODCOMANDA1, D1, D2, D3)
    select
      ROUND(C.NRDOC + c1.indexlocal / 1000, 3),
      C.DATADOC,
      NOBJ.DENUMIRE,
      NOBJ.CODEXTERN,
      NUM1.DEN_UM1,
      ROUND(CMD.CANT * PF1.CANTPROGRAMAT/ C1.CANTACCEPTAT, 2),
      C.CODGEST,
      BAZAM.CODOBIECT,
      NVL(REZ.CANTREZERVAT,0),
      PF1.Cantprogramat,
      PF1.Prioritate,
      C1.CODCOMANDA1,
      C1.D1,
      C1.D2,
      C1.D3
    from TMP_PROGRAMF1_MANEVRA PF1
         inner join comanda1 c1 on PF1.codcomanda1 = c1.codcomanda1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA AND C.TIPDOC = 53
         inner join cmdprodmat CMD on C1.CODCOMANDA1 = cmd.codcomanda1
         INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
         INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
         INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMsec
         inner join TMP_PF_MAT BAZAM ON CMD.CODOBIECT = BAZAM.CODOBIECT
         LEFT JOIN (SELECT REZ.CODCMDPRODMAT, SUM(REZ.REST) CANTREZERVAT
                    FROM REZERVATS REZ
                    GROUP BY REZ.CODCMDPRODMAT
                   ) REZ ON REZ.CODCMDPRODMAT = CMD.CODCMDPRODMAT
    WHERE (C1.CONSUM = 1 AND CMD.TIP = 1) OR (C1.CONSUM = 2 AND CMD.TIP IN (0,1));

    INSERT INTO TMP_PF_SDV_CMD(NRCMD, PRIORITATE, DEN_OBIECT, CODEXTERN, UM, CANTPROGRAMAT, SECTIE, CODOBIECT)
        SELECT ROUND(C.NRDOC + c1.indexlocal / 1000, 3), PF1.PRIORITATE, OBJ.DENUMIRE, OBJ.CODEXTERN, NUM.DEN_UM, PF1.CANTPROGRAMAT, C.CODGEST SECTIE, SDV.CODSDV
         FROM TMP_PROGRAMF1_MANEVRA PF1
              INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
              INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
              INNER JOIN PRODSDV SDV ON SDV.CODPRODCOMP = C1.CODRETETA
              INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODOBIECT
              INNER JOIN NART A ON OBJ.CODARTICOL = A.CODARTICOL
              INNER JOIN NUM ON NUM.CODUM = A.UM;

    INSERT INTO TMP_PF_LOCM_CMD(
      CODLMC, CODPROGRAMF, CODGEST, CODLOC, CODCOMANDA1, DATAPROGRAMARE,
      NRCMD,PRIORITATE,DEN_OBIECT,CODEXTERN,
      NECESAR, NECESARM,
      den_um, cantprod,CODOP)
    SELECT
        - ROWNUM, PF1.CODPROGRAMF, C.CODGEST, PMAN.CODLOC, PF1.CODCOMANDA1, vDataStart,
        ROUND(C.NRDOC + c1.indexlocal / 1000, 3),
        PF1.PRIORITATE,
        OBJ.DENUMIRE,
        OBJ.CODEXTERN,
          NVL(CASE
             WHEN PC.CANT &lt;&gt; 1 THEN
               PF1.CANTPROGRAMAT / PC.CANT * NVL(PMAN.TPI, 0)  + PF1.CANTPROGRAMAT / PMAN.BPS * PMAN.TU
             ELSE
               NVL(PMAN.TPI, 0) + PF1.CANTPROGRAMAT / PMAN.BPS * PMAN.TU
             END,0) / 60 NECESAR,
        NVL(CASE
             WHEN PC.CANT &lt;&gt; 1 THEN
               PF1.CANTPROGRAMAT / PC.CANT * NVL(PMAN.TPI, 0)  + PF1.CANTPROGRAMAT / PMAN.BPS * PMAN.TU
             ELSE
               NVL(PMAN.TPI, 0) + PF1.CANTPROGRAMAT / PMAN.BPS * PMAN.TU
             END,0) NECESARM,
             NUM1.DEN_UM1,
             PF1.CANTPROGRAMAT,
             PMAN.CODOP
      FROM TMP_PROGRAMF1_MANEVRA PF1
           INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
           INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
           INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODOBIECT
           INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
           INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
           INNER JOIN CMDPRODMAN PMAN ON PMAN.CODCOMANDA1 = C1.CODCOMANDA1
           INNER JOIN NGEST PG ON PG.CODGEST = C.CODGEST
      ;

    INSERT INTO TMP_PF_MAN_CMD(
    CODOP, CODGEST, CODCOMANDA1,
    DATADOC, NRDOC, DENUMIRE,
    CODEXTERN, NECESAR, NECESARM,
    den_um, cantprod, valoare, Prioritate, OPERATII)
      SELECT MAN.CODOP, C.CODGEST, C1.CODCOMANDA1, C.DATADOC,ROUND(C.NRDOC + c1.indexlocal / 1000, 3),OBJ.DENUMIRE,OBJ.CODEXTERN,
               round(sum(
                 case
                   when PC.CANT &lt;&gt; 1 THEN round(TMP.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + TMP.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 6)
                   ELSE round(NVL(MAN.TPI, 0) + TMP.CANTPROGRAMAT * nvl(MAN.TU, 0), 6)
                 END
                 ) / 60, 6),
             round(sum(
               case
                 when PC.CANT &lt;&gt; 1 THEN round(TMP.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + TMP.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 6)
                 ELSE round(NVL(MAN.TPI, 0) + TMP.CANTPROGRAMAT * nvl(MAN.TU, 0), 6)
               END
               ), 6),
               TMP.UM,
               TMP.CANTPROGRAMAT,
               round(sum(
                 case
                   when PC.CANT &lt;&gt; 1 THEN round(TMP.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + TMP.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 6)
                   ELSE round(NVL(MAN.TPI, 0) + TMP.CANTPROGRAMAT * nvl(MAN.TU, 0), 6)
                 END
                 ) / 60, 6) * TMPM.TARIF,
                 TMP.Prioritate,
               SUM(MAN.CANT)
      FROM COMANDA1 C1
           INNER JOIN TMP_PROGRAMF1_MANEVRA TMP ON C1.CODCOMANDA1 = TMP.CODCOMANDA1
           INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
           INNER JOIN NARTOBJ OBJ ON C1.CODOBIECT = OBJ.CODOBIECT
           INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
           INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
           INNER JOIN TMP_PF_MAN TMPM ON TMPM.CODOP = MAN.CODOP
      GROUP BY MAN.CODOP, C.CODGEST, C1.CODCOMANDA1, C.NRDOC, C1.IndexLocal, C.DATADOC,
               OBJ.DENUMIRE, OBJ.CODEXTERN,TMP.UM,
               TMP.CANTPROGRAMAT, TMPM.TARIF, TMP.Prioritate;
  end if;
--  COMMIT;
END;

PROCEDURE CALCUL_GEST(XT IN VARCHAR2, YT IN VARCHAR2) IS
--PRAGMA AUTONOMOUS_TRANSACTION;
vDATASTART DATE;
vDATASTOP  DATE;
vZILEN NUMBER;
BEGIN
  SELECT VDELA INTO vDATASTART FROM TMP_PROGRAMF_MANEVRA;
  SELECT VPANALA INTO vDATASTOP FROM TMP_PROGRAMF_MANEVRA;

  SELECT
    count(zn1.data) INTO vZILEN
  FROM
    zineluc1 zn1
  where zn1.data between (select VDELA from tmp_programf_manevra where rownum = 1)
        AND (select VpanaLA from tmp_programf_manevra where rownum = 1);

  DELETE FROM TMP_PF_MAT_GEST;
  DELETE FROM TMP_PF_SDV_GEST;
  DELETE FROM TMP_PF_LOCM_GEST;
  DELETE FROM TMP_PF_MAN_GEST;

  if PKG_CATEGCONST.GetValConstanta(&apos;RAPORDMAN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    INSERT INTO TMP_PF_MAT_GEST(
      CODOBIECT,DENOBJ,DEN_UM,DEN_GEST,
      CANTPROGRAMAT,
      RESTASIGURAT,
      CODGEST, REZERVAT)
    SELECT
      MAT.CODOBIECT, NOBJ.DENUMIRE, NUM.DEN_UM, NG.DEN_GEST,
      ROUND(SUM(MAT.CANT * PFM.CANT / MAN.CANT),2) CANT,
      sum(CASE
            WHEN MAT.CANT * PFM.CANT / MAN.CANT - NVL(REZ.CANT,0) &lt; 0 THEN 0
            ELSE MAT.CANT * PFM.CANT / MAN.CANT - NVL(REZ.CANT,0)
          END) RESTASIGURAT,
      C.CODGEST, SUM(NVL(REZ.CANT,0))
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN CMDPRODMAT MAT ON MAT.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = MAT.CODOBIECT
         INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
         INNER JOIN NUM ON NUM.CODUM = NART.UM
         INNER JOIN NGEST NG ON C.CODGEST = NG.CODGEST
         LEFT JOIN (SELECT R.CODCMDPRODMAT, SUM(R.REST) CANT
                    FROM REZERVATS R
                         INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
                         INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                         INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
                    where exists (select codcomanda1 from tmp_programf1_manevra where codcomanda1 = R.codcomanda1)
                    AND NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
                    GROUP BY R.CODCMDPRODMAT) REZ ON REZ.CODCMDPRODMAT = MAT.CODCMDPRODMAT
    WHERE (C1.CONSUM = 1 AND MAT.TIP = 1) OR (C1.CONSUM = 2 AND MAT.TIP IN (0,1))
    GROUP BY MAT.CODOBIECT,NOBJ.DENUMIRE, NUM.DEN_UM, NG.DEN_GEST, C.CODGEST;

    INSERT INTO TMP_PF_SDV_GEST(CODPROGRAMFSDV,CODPROGRAMF,CODGEST,CODOBIECT,CANT,STOC,DEN_GEST,DEN_UM)
    SELECT NVL(PROGSDV.CODPROGRAMFSDV,-1) CODPROGRAMFSDV, PFM.CODPROGRAMF, NG.CODGEST, PSDV.CODSDV,
           NVL(PROGSDV.CANT,ROUND(PSDV.CANT * PFM.CANT / MAN.CANT,2)) CANT, ROUND(NVL(STOC.REST,0),2), NG.DEN_GEST, NUM.DEN_UM
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON PFM.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN PRODSDV PSDV ON PSDV.CODPRODMAN = MAN.CODMAN
         INNER JOIN NGEST NG ON NG.CODGEST = C.CODGEST
         INNER JOIN NARTOBJ NOBJ ON PSDV.CODSDV = NOBJ.CODOBIECT
         INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
         INNER JOIN NUM ON NUM.CODUM = NART.UM
         LEFT JOIN (SELECT NS.CODOBIECT ,SUM(NS.REST) REST
                    FROM NIRSTOC NS
                    GROUP BY NS.CODOBIECT
                    ) STOC ON PSDV.CODSDV = STOC.CODOBIECT
         LEFT JOIN PROGRAMFSDV PROGSDV ON PROGSDV.CODPROGRAMF = PFM.CODPROGRAMF AND
                                          PROGSDV.CODGEST = C.CODGEST
                                          AND PROGSDV.CODOBIECT = PSDV.CODSDV;

    INSERT INTO TMP_PF_LOCM_GEST(SECTIE,CODGEST,CODLOCMUNCA,DISPONIBIL,NECESAR,DIFERENTE,DISPONIBILM,NECESARM,DIFERENTEM)
    WITH
      CRS_ZILE AS (
        SELECT
          T.CodProgramf,
          (T.vPanaLa - T.VDeLa) + 1 - (
            SELECT
              count(zn1.data)
            FROM zineluc1 zn1
            where zn1.data between (select VDELA from tmp_programf_manevra where rownum = 1)
                  AND (select VpanaLA from tmp_programf_manevra where rownum = 1)) zile
        FROM TMP_PROGRAMF_MANEVRA T
      ),
      CRS_NECESAR AS (
        SELECT
          SUM(PFM.CANT * NVL(PMAN.TPI, 0)  + PFM.CANT * PMAN.TU) NECESAR,
          NG.ORESCHIMB * NG.NRSCHIMBURI * ZILE.ZILE DISPONIBIL,
          NVL(PMAN.CODLOC,0) CODLOC,
          NVL(CMD.CODGEST, 0) CODGEST
        FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
             TMP_PROGRAMFMAN_MANEVRA PFM
             INNER JOIN CMDPRODMAN PMAN ON PMAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
             INNER JOIN COMANDA1 CMD1 ON PMAN.CODCOMANDA1 = CMD1.CODCOMANDA1
             INNER JOIN COMANDA CMD ON CMD1.CODCOMANDA = CMD.CODCOMANDA
             INNER JOIN NGEST NG ON NG.CODGEST = CMD.CODGEST
        GROUP BY NG.ORESCHIMB,NG.NRSCHIMBURI,ZILE.ZILE,PMAN.CODLOC,CMD.CODGEST
      )
    SELECT
      NG.DEN_GEST SECTIE,NG.CODGEST,NECESAR.CODLOC,
      NVL(NECESAR.DISPONIBIL,0) DISPONIBIL,
      NVL(NECESAR.NECESAR,0)/60 NECESAR,
      NVL(NECESAR.DISPONIBIL,0) - NVL(NECESAR.NECESAR,0)/60 DIFERENTE,
      NVL(NECESAR.DISPONIBIL,0) * 60 DISPONIBILM,
      NVL(NECESAR.NECESAR,0) NECESARM,
      NVL(NECESAR.DISPONIBIL,0) * 60 - NVL(NECESAR.NECESAR,0) DIFERENTEM
    FROM CRS_NECESAR NECESAR
         INNER JOIN NGEST NG ON NG.CODGEST = NECESAR.CODGEST;

    INSERT INTO TMP_PF_MAN_GEST(CODOP, CODGEST, DEN_GEST, ORE, VALOARE, OREM,OPERATII)
    SELECT
      OP.CODOP,
      G.CodGEST,
      G.DEN_GEST,
      round(sum(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0)) / 60, 3),
      round(sum(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0) / 60 * T1.TARIF), 2),
      round(sum(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0)), 2),
      SUM(MAN.CANT)
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
         INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
         INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
         INNER JOIN TARIFEMAN1 T1 ON T1.CODTARIF = MAN.CODTARIF
    WHERE PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALSTART AND T1.ALSTOP
    GROUP BY OP.CODOP, G.CODGEST, G.DEN_GEST;
  ELSE
    INSERT INTO TMP_PF_MAT_GEST(CODOBIECT,DENOBJ,DEN_UM,DEN_GEST,CANTPROGRAMAT,STOCDISP,RESTASIGURAT,CODGEST, REZERVAT)
    SELECT PRODM.CODOBIECT, NOBJ.DENUMIRE, NUM.DEN_UM,NG.DEN_GEST,
           ROUND(SUM(PRODM.CANT * PF1.CANTPROGRAMAT /C1.CANTACCEPTAT ),2) CANT,
           ROUND(NVL(STOC.STOCDISP,0),2),
           sum(CASE
             WHEN PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT - NVL(REZ.CANT,0) &lt; 0 THEN 0
             ELSE PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT - NVL(REZ.CANT,0)
           END) RESTASIGURAT, C.CODGEST, SUM(NVL(REZ.CANT,0))
    FROM TMP_PROGRAMF1_MANEVRA PF1 INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
                                   INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                                   INNER JOIN CMDPRODMAT PRODM ON PRODM.CODCOMANDA1 = C1.CODCOMANDA1
                                   INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = PRODM.CODOBIECT
                                   INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
                                   INNER JOIN NUM ON NUM.CODUM = NART.UM
                                   INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
                                   INNER JOIN NGEST NG ON NG.CODGEST = C.CODGEST
                                   LEFT JOIN (
                                     SELECT
                                       NS.CODOBIECT,SUM(NS.REST) STOCDISP
                                     FROM NIRSTOC NS
                                          INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                                          INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
                                     WHERE NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
                                     GROUP BY CODOBIECT) STOC ON STOC.CODOBIECT = PRODM.CODOBIECT
                                   LEFT JOIN ( SELECT R.CODCMDPRODMAT, SUM(R.REST) CANT
                                               FROM REZERVATS R
                                                    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
                                                    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                                                    INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
                                               where exists (select codcomanda1 from tmp_programf1_manevra where codcomanda1 = R.codcomanda1)
                                               AND NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
                                               GROUP BY R.CODCMDPRODMAT
                                             ) REZ ON REZ.CODCMDPRODMAT = PRODM.CODCMDPRODMAT
    WHERE (C1.CONSUM = 1 AND PRODM.TIP = 1) OR (C1.CONSUM = 2 AND PRODM.TIP IN (0,1))
    GROUP BY  PRODM.CODOBIECT,NOBJ.DENUMIRE, NUM.DEN_UM, NG.DEN_GEST, C.CODGEST,NVL(STOC.STOCDISP,0);

    INSERT INTO TMP_PF_SDV_GEST(CODPROGRAMFSDV,CODPROGRAMF,CODGEST,CODOBIECT,CANT,STOC,DEN_GEST,DEN_UM)
    SELECT NVL(PROGSDV.CODPROGRAMFSDV,-1) CODPROGRAMFSDV, PF1.CODPROGRAMF, NG.CODGEST, PSDV.CODSDV,
           ROUND(NVL(PROGSDV.CANT,PSDV.CANT) * PF1.CANTPROGRAMAT,2) CANT, ROUND(NVL(STOC.REST,0),2), NG.DEN_GEST, NUM.DEN_UM
    FROM TMP_PROGRAMF1_MANEVRA PF1
         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
         INNER JOIN PRODSDV PSDV ON PSDV.CODPRODCOMP = C1.CODRETETA
         INNER JOIN NGEST NG ON NG.CODGEST = C.CODGEST
         INNER JOIN NARTOBJ NOBJ ON PSDV.CODSDV = NOBJ.CODOBIECT
         INNER JOIN NART ON NART.CODARTICOL = NOBJ.CODARTICOL
         INNER JOIN NUM ON NUM.CODUM = NART.UM
         LEFT JOIN (SELECT NS.CODOBIECT ,SUM(NS.REST) REST
                    FROM NIRSTOC NS
                    GROUP BY NS.CODOBIECT
                    ) STOC ON PSDV.CODSDV = STOC.CODOBIECT
         LEFT JOIN PROGRAMFSDV PROGSDV ON PROGSDV.CODPROGRAMF = PF1.CODPROGRAMF AND
                                          PROGSDV.CODGEST = C.CODGEST
                                          AND PROGSDV.CODOBIECT = PSDV.CODSDV;

    INSERT INTO TMP_PF_LOCM_GEST(SECTIE,CODGEST,CODLOCMUNCA,DISPONIBIL,NECESAR,DIFERENTE,DISPONIBILM,NECESARM,DIFERENTEM)
    WITH
      CRS_ZILE AS (
        SELECT
          T.CodProgramf,
          (T.vPanaLa - T.VDeLa) + 1 - (
            SELECT
              count(zn1.data)
            FROM zineluc1 zn1
            where zn1.data between (select VDELA from tmp_programf_manevra where rownum = 1)
                  AND (select VpanaLA from tmp_programf_manevra where rownum = 1)) zile
        FROM TMP_PROGRAMF_MANEVRA T
      ),
      CRS_NECESAR AS (
        SELECT
          SUM(CASE
                WHEN PC.CANT &lt;&gt; 1 THEN
                    PF1.CANTPROGRAMAT / PC.CANT * NVL(PMAN.TPI, 0)  + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
                ELSE
                    NVL(PMAN.TPI, 0) + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
              END) NECESAR,
          NG.ORESCHIMB * NG.NRSCHIMBURI * ZILE.ZILE DISPONIBIL,
          NVL(PMAN.CODLOC,0) CODLOC,
          NVL(CMD.CODGEST, 0) CODGEST
        FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
              TMP_PROGRAMF1_MANEVRA PF1 INNER JOIN COMANDA1 CMD1 ON PF1.CODCOMANDA1 = CMD1.CODCOMANDA1
                                        INNER JOIN COMANDA CMD ON CMD1.CODCOMANDA = CMD.CODCOMANDA
                                        INNER JOIN PRODCOMP PC ON CMD1.CODRETETA = PC.CODPRODCOMP
                                        INNER JOIN CMDPRODMAN PMAN ON PMAN.CODCOMANDA1 = CMD1.CODCOMANDA1
                                        INNER JOIN NGEST NG ON NG.CODGEST = CMD.CODGEST
        GROUP BY NG.ORESCHIMB,NG.NRSCHIMBURI,ZILE.ZILE,PMAN.CODLOC,CMD.CODGEST
      )
    SELECT
      NG.DEN_GEST SECTIE,NG.CODGEST,NECESAR.CODLOC,
      NVL(NECESAR.DISPONIBIL,0) DISPONIBIL,
      NVL(NECESAR.NECESAR,0)/60 NECESAR,
      NVL(NECESAR.DISPONIBIL,0) - NVL(NECESAR.NECESAR,0)/60 DIFERENTE,
      NVL(NECESAR.DISPONIBIL,0) * 60 DISPONIBILM,
      NVL(NECESAR.NECESAR,0) NECESARM,
      NVL(NECESAR.DISPONIBIL,0) * 60 - NVL(NECESAR.NECESAR,0) DIFERENTEM
    FROM CRS_NECESAR NECESAR
         INNER JOIN NGEST NG ON NG.CODGEST = NECESAR.CODGEST;

    INSERT INTO TMP_PF_MAN_GEST(CODOP, CODGEST, DEN_GEST, ORE, VALOARE, OREM,OPERATII)
    SELECT
      OP.CODOP,
      G.CodGEST,
      G.DEN_GEST,
        round(sum(
          case
            when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
            ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
          END
          ) / 60, 2),
      round(sum(
        case
          when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
          ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
        END * T1.TARIF
        ) / 60, 2),
      round(sum(
        case
          when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
          ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
        END
      ), 2),
      SUM(MAN.CANT)
    FROM TMP_PROGRAMF1_MANEVRA PF1
         INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
         INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = PF1.CODCOMANDA1
         INNER JOIN PRODGEST PG ON PG.CODPRODGEST = MAN.CODPRODGEST
         INNER JOIN NGEST G ON C.CODGEST = G.CODGEST
         INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
         INNER JOIN TARIFEMAN1 T1 ON T1.CODTARIF = MAN.CODTARIF
    WHERE PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALSTART AND T1.ALSTOP
    GROUP BY OP.CODOP, G.CODGEST, G.DEN_GEST;
  END IF;
--  COMMIT;
END;

PROCEDURE UPDATE_STOCURI(AllGest in number, AllTipCont in number) IS
BEGIN
  UPDATE TMP_PF_MAT MAT
  SET
    STOCDISP = nvl((SELECT SUM(NS.REST)
                FROM NIRSTOC NS
                     INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                     INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
                WHERE NS.REST &gt; 0 AND NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE AND NS.CODOBIECT = MAT.CODOBIECT
                      AND ((ALLGEST = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; AND VALOARE = NIR.GEST)))
                      AND ((ALLTIPCONT = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODIOART&apos; AND VALOARE = NS.CODIOART)))
                ),0),
    ALTEREZ = nvl((SELECT SUM(R.REST)
               FROM REZERVATS R
                    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
                    INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                    INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
               where  NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
                     AND NS.CODOBIECT = MAT.CODOBIECT
                     AND ((ALLGEST = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; AND VALOARE = NIR.GEST)))
                     AND ((ALLTIPCONT = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODIOART&apos; AND VALOARE = NS.CODIOART)))
               ),0);
  UPDATE TMP_PF_MAT_GEST MAT
  SET
    STOCDISP = nvl((SELECT SUM(NS.REST)
                FROM NIRSTOC NS
                     INNER JOIN NIR ON NIR.CODNIR = NS.CODNIR
                     INNER JOIN NGEST NG ON NIR.GEST = NG.CODGEST
                WHERE REST &gt; 0 AND NG.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE AND NS.CODOBIECT = MAT.CODOBIECT
                      AND ((ALLGEST = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODGEST&apos; AND VALOARE = NIR.GEST)))
                      AND ((ALLTIPCONT = 1) OR (EXISTS (SELECT VALOARE FROM TMP_MANEVRA_LISTE WHERE FILTRU = &apos;CODIOART&apos; AND VALOARE = NS.CODIOART)))
                ),0);
END;

PROCEDURE CALCUL_DETALII(XT IN VARCHAR2, YT IN VARCHAR2, vTip in number) IS
--PRAGMA AUTONOMOUS_TRANSACTION;
vDATASTART DATE;
vDATASTOP  DATE;
vZILEN NUMBER;
aCount number;
vAllGest number(1);
vAllTipCont number(1);
BEGIN
  SELECT VDELA INTO vDATASTART FROM TMP_PROGRAMF_MANEVRA;
  SELECT VPANALA INTO vDATASTOP FROM TMP_PROGRAMF_MANEVRA;
  select AllGest into vAllGest from tmp_programf_manevra;
  select AllTipCont into vAllTipCont from tmp_programf_manevra;

  SELECT
    count(zn1.data) INTO vZILEN
  FROM
    zineluc1 zn1
  where zn1.data between (select VDELA from tmp_programf_manevra where rownum = 1)
        AND (select VpanaLA from tmp_programf_manevra where rownum = 1);
  DELETE FROM TMP_PF_MAT;
  DELETE FROM TMP_PF_SDV;
  DELETE FROM TMP_PF_LOCM;
  DELETE FROM TMP_PF_MAN;

  if PKG_CATEGCONST.GetValConstanta(&apos;RAPORDMAN&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) = 1 then
    if not vDinGoTo then
      delete tmp_programf1;
      insert into tmp_programf1
       (codprogramf1,codprogramf, codcomanda1, codgest, termen, cantprogramat, codformatie,
        schimb, den_gest, nrcmd, den_obiect, codextern, um, termenexec, den_client, termenlivr, codobiect,
        codcomanda, durata, duratam, den_formatie, d1, d2, d3, lansat, cantreteta, duratareteta,
        termencmdint,nrcmdcli,obscmdint,obscmdcli,prioritate,datastart)
      select
        -1,tmp.codprogramf, c1.codcomanda1, c.codgest, c1.termen,
        sum(case
          when maxop.ultim = man.nrop then tmp.cant * nvl(man.bps,0)
          else 0
        end) cantprogramat,
        c.codformatie,
        c.schimb, g.den_gest, ROUND(C.NRDOC + c1.indexlocal / 1000, 3) nrcmd, obj.denumire den_obiect, obj.codextern, num1.den_um1 um, c1.termen termenexec,
        case when cs.codcomanda &gt; 0 then ss.den_subunit else p.den_part end den_client, cc1.termen termenlivr, obj.codobiect,
        c.codcomanda, sum(tmp.cant * (man.tu + man.tpi)) / 60 durata, sum(tmp.cant * (man.tu + man.tpi)) duratam,
        f.den_formatie, c1.d1, c1.d2, c1.d3, c1.cantacceptat lansat, pc.cant cantreteta, pc.durata duratareteta,
        c1.termen termencmdint,
        case when cs.codcomanda &gt; 0 then ROUND(CS.NRDOC + CS1.indexlocal / 1000, 3) ELSE ROUND(CC.NRDOC + CC1.indexlocal / 1000, 3) END,
        c1.obs,
        case when cs.codcomanda &gt; 0 then CS1.OBS ELSE cc1.obs END,gt.prioritate,gt.dstart
      from tmp_programfman_manevra tmp
           inner join cmdprodman man on man.codcmdprodman = tmp.codcmdprodman
           inner join comanda1 c1 on c1.codcomanda1 = man.codcomanda1
           inner join comanda c on c1.codcomanda = c.codcomanda
           inner join ngest g on g.codgest = c.codgest
           inner join nartobj obj on c1.codobiect = obj.codobiect
           inner join num1 on num1.codum1 = c1.umsec
           inner join prodcomp pc on pc.codprodcomp = c1.codreteta
           inner join (select ret.codprodcomp, max(pm.nrop) ultim
                       from cmdprodman m
                            inner join tmp_programfman_manevra mv on m.codcmdprodman = mv.codcmdprodman
                            inner join prodman pm on m.codman = pm.codman
                            inner join prodcomp ret on ret.codprodcomp = pm.codprodcomp
                       group by ret.codprodcomp) maxop on maxop.codprodcomp = pc.codprodcomp
           LEFT JOIN (Select CodComanda1, CODCMDPRODMAN from CMDPRODMAN x where NROP = 1) PM ON PM.CODCOMANDA1 = C1.CODCOMANDA1
           left JOIN GANTT GT ON GT.CODCMDPRODMAN = PM.CODCMDPRODMAN
           left join formatii f on f.codformatie = c.codformatie
           left join cmdlink ls on ls.codcomanda1 = c1.codcomanda1
           left join comanda1 cs1 on cs1.codcomanda1 = ls.codliniecomanda
           left join comanda cs on cs.codcomanda = cs1.codcomanda
           left join nsubunit ss on ss.codsubunit = cs.subunitsursa
           left join comanda1 cc1 on cc1.codcomanda1 = pkg_comanda.DinCmdCli(c1.codcomanda1)
           left join comanda cc on cc1.codcomanda = cc.codcomanda
           left join npart p on p.codpart = cc.partener
			where vTip = 0 or GT.Codgantt is not null
      group by
        tmp.codprogramf, 
        c1.codcomanda1, 
        c.codgest, 
        c1.termen,
        c.codformatie,
        c.schimb, 
        g.den_gest, 
        C.NRDOC,
        c1.indexlocal, 
        obj.denumire, 
        obj.codextern, 
        num1.den_um1, 
        cs.codcomanda,
        ss.den_subunit,
        p.den_part,
        cc1.termen, 
        obj.codobiect,
        c.codcomanda, 
        f.den_formatie, 
        c1.d1, 
        c1.d2, 
        c1.d3, 
        c1.cantacceptat, 
        pc.cant, 
        pc.durata,
        CS.NRDOC,
        CS1.indexlocal,
        CC.NRDOC,
        CC1.indexlocal,
        c1.obs,
        CS1.OBS,
        cc1.obs,
        gt.prioritate,
        gt.dstart;
    end if;

    INSERT INTO TMP_PF_MAT
     (CODOBIECT,DENUMIRE,CODEXTERN,
      DEN_UM1,
      NECESAR,
      CONSUMAT,
      DIFERENTE,
      REZERVAT,
      STOCFURN,
      RESTASIGURAT)
    SELECT
      NOBJ.CODOBIECT, NOBJ.DENUMIRE,NOBJ.CODEXTERN,
      NUM.DEN_UM,
      ROUND(SUM(MAT.CANT * TMP.CANT / MAN.CANT),2)  NECESAR,
      ROUND(SUM((MAT.CANT * TMP.CANT / MAN.CANT) - (MAT.REST * TMP.CANT / MAN.CANT)),2) CONSUMAT,
      ROUND(SUM(MAT.REST * TMP.CANT / MAN.CANT),2) DIFERENTE,
      ROUND(SUM(NVL(REZ.REST,0)),2) REZERVAT,
      ROUND(NVL(CMDFURN.STOCFURN,0),2) STOCFURN ,
      ROUND(SUM(case when MAT.CANT * TMP.CANT / MAN.CANT - NVL(REZ.REST,0) &lt; 0 then 0 else MAT.CANT * TMP.CANT / MAN.CANT - NVL(REZ.REST,0) end),2)
    FROM
      TMP_PROGRAMFMAN_MANEVRA TMP
      INNER JOIN CMDPRODMAN MAN ON TMP.CODCMDPRODMAN = MAN.CODCMDPRODMAN
      INNER JOIN CMDPRODMAT MAT ON MAT.CODCMDPRODMAN = MAN.CODCMDPRODMAN
      INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
      INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = MAT.CODOBIECT
      INNER JOIN NART N ON N.CODARTICOL = NOBJ.CODARTICOL
      INNER JOIN NUM ON NUM.CODUM = N.UM
      LEFT JOIN REZERVATS REZ ON REZ.CODCMDPRODMAT = MAT.CODCMDPRODMAT
      LEFT JOIN (SELECT CFURN1.CODOBIECT,SUM(CFURN1.RESTACCEPTAT) STOCFURN
                 FROM COMANDA CFURN
                      INNER JOIN COMANDA1 CFURN1 ON CFURN.CODCOMANDA = CFURN1.CODCOMANDA
                      INNER JOIN CMDPRODMAT MAT ON MAT.CODOBIECT = CFURN1.CODOBIECT
                      INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = MAT.CODCMDPRODMAN
                      INNER JOIN TMP_PROGRAMFMAN_MANEVRA TMP ON TMP.CODCMDPRODMAN = MAN.CODCMDPRODMAN
                 WHERE CFURN.TIPDOC = 8 GROUP BY CFURN1.CODOBIECT
                ) CMDFURN ON CMDFURN.CODOBIECT = MAT.CODOBIECT
      WHERE (C1.CONSUM = 1 AND MAT.TIP = 1) OR (C1.CONSUM = 2 AND MAT.TIP IN (0,1))
    GROUP BY NOBJ.CODOBIECT,
             NOBJ.DENUMIRE,
             NOBJ.CODEXTERN,
             NUM.DEN_UM,
             NVL(CMDFURN.STOCFURN,0);
    update TMP_PF_MAT set restasigurat = 0 where restasigurat &lt; 0;

    INSERT INTO TMP_PF_SDV
     (DENUMIRE,
      DEN_UM,
      CODEXTERN,
      REST,
      STOCFURN,
      CANTACT,
      CANTDOC,
      CODOBIECT)
    SELECT
      NOBJ.DENUMIRE,
      NUM.DEN_UM,
      NOBJ.CODEXTERN,
      ROUND(NVL(STOC.REST,0),2) REST,
      ROUND(NVL(CMDFURN.STOCFURN,0),2) STOCFURN,
      ROUND(NVL(SUM(PSDV.CANT),0),2) CANTACT,
      ROUND(SUM(SDV.CANT * TMP.CANT),2) CANTDOC,
      NOBJ.CODOBIECT
    FROM TMP_PROGRAMFMAN_MANEVRA TMP
         INNER JOIN CMDPRODMAN MAN ON TMP.CODCMDPRODMAN = MAN.CODCMDPRODMAN
         INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN PRODMAN PMAN ON PMAN.CODMAN = MAN.CODMAN
         INNER JOIN (SELECT S.CODPRODMAN, S.CODSDV, SUM(S.CANT/PC.CANT) CANT
                     FROM PRODSDV S
                          INNER JOIN PRODCOMP PC ON PC.Codprodcomp = S.CODPRODCOMP
                     GROUP BY CODPRODMAN, CODSDV
                    ) SDV ON SDV.CODPRODMAN = PMAN.CODMAN
         LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = SDV.CODSDV
         LEFT JOIN NART N ON N.CODARTICOL = NOBJ.CODARTICOL
         LEFT JOIN NUM ON NUM.CODUM = N.UM
         LEFT JOIN (SELECT NS.CODOBIECT ,SUM(NS.REST) REST
                    FROM NIRSTOC NS
                    GROUP BY NS.CODOBIECT
                   ) STOC ON SDV.CODSDV = STOC.CODOBIECT
         LEFT JOIN (SELECT CFURN1.CODOBIECT,SUM(CFURN1.RESTACCEPTAT) STOCFURN
                    FROM COMANDA CFURN
                         INNER JOIN COMANDA1 CFURN1 ON CFURN.CODCOMANDA = CFURN1.CODCOMANDA
                    WHERE CFURN.TIPDOC = 8 GROUP BY CFURN1.CODOBIECT
                   ) CMDFURN ON CMDFURN.CODOBIECT = SDV.CODSDV
         LEFT JOIN (SELECT CODPROGRAMF,SUM(CANT) CANT
                    FROM PROGRAMFSDV
                    GROUP BY CODPROGRAMF
                   ) PSDV ON PSDV.CODPROGRAMF = TMP.CODPROGRAMF
    GROUP BY NOBJ.DENUMIRE,NUM.DEN_UM,NOBJ.CODEXTERN,NOBJ.CODOBIECT,NVL(STOC.REST,0),NVL(CMDFURN.STOCFURN,0) ;

    INSERT INTO TMP_PF_LOCM(DENUMIRE,DISPONIBIL,NECESAR,DIFERENTE,CODLOCMUNCA,DISPONIBILM,NECESARM,DIFERENTEM)
     WITH CRS_ZILE AS
     (
       SELECT
          T.CodProgramf,
          (T.vPanaLa - T.VDeLa) + 1 - (
            SELECT
              count(zn1.data)
            FROM
              zineluc1 zn1
            where zn1.data between vDataStart AND vDataStop) zile
       FROM TMP_PROGRAMF_MANEVRA T
     ),
     CRS_NECESAR AS
     (
       SELECT
         SUM(CASE
               WHEN PC.CANT &lt;&gt; 1 THEN PFM.CANT / PMAN.CANT * NVL(PMAN.TPI, 0)  + PFM.CANT / PMAN.BPS * PMAN.TU
               ELSE NVL(PMAN.TPI, 0) + PFM.CANT / PMAN.BPS * PMAN.TU
             END) NECESAR,
         NVL(PMAN.CODLOC,0) CODLOC
       FROM TMP_PROGRAMFMAN_MANEVRA PFM
            INNER JOIN CMDPRODMAN PMAN ON PMAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
            INNER JOIN PRODMAN MAN ON PMAN.CODMAN = MAN.CODMAN
            INNER JOIN PRODCOMP PC ON PC.CODPRODCOMP = MAN.CODPRODCOMP
       GROUP BY PMAN.CODLOC
     ),
     CRS_LOCURI AS
     (
       select
         x.codloc,
         sum(x.disponibil) disponibil
       from (SELECT distinct LM.CODLOC,
                    LM.DENUMIRE,
                    LM1.ore * zile.zile DISPONIBIL
             FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                  LOCMUNCA LM LEFT JOIN LOCMUNCA1 LM1 ON LM.CODLOC = LM1.CODLOC
                              LEFT JOIN MIFIX1 MF1    ON MF1.CODMIFIX   = LM1.CODMIFIX
                              LEFT JOIN NIRSTOC NS    ON NS.CODNIRSTOC = MF1.CODNIRSTOC
                              LEFT JOIN NIR           ON NIR.CODNIR = NS.CODNIR
                              LEFT JOIN NGEST NG      ON NG.CODGEST = NIR.GEST
             WHERE LM.TIP = 1 AND NS.Rest &gt; 0 AND MF1.Anstart*12 + MF1.lunastart = (select max(anstart*12+lunastart) from mifix1 where codmifix = LM1.codmifix)
             UNION ALL
             SELECT distinct LM.CODLOC,
                    LM.DENUMIRE,
                    LM1.ore * zile.zile DISPONIBIL
             FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                  LOCMUNCA LM LEFT JOIN LOCMUNCA1 LM1 ON LM.CODLOC = LM1.CODLOC
             WHERE LM.TIP = 2
             UNION ALL
             SELECT distinct LM.CODLOC,
                    LM.DENUMIRE,
                    NVL(G.ORESCHIMB,0) * NVL(G.NRSCHIMBURI,0) * zile.zile DISPONIBIL
             FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                   TMP_PROGRAMFMAN_MANEVRA MM
                   INNER JOIN CMDPRODMAN MAN ON MM.CODCMDPRODMAN = MAN.CODCMDPRODMAN
                   INNER JOIN LOCMUNCA LM ON MAN.CODLOC = LM.CODLOC
                   INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
                   INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                   INNER JOIN NGEST G ON G.CODGEST = C.CODGEST
             WHERE LM.TIP = 0
            ) x group by x.codloc
     )
    SELECT
      LM.DENUMIRE,
      NVL(LOCURI.DISPONIBIL,0) DISPONIBIL,
      NVL(NECESAR.NECESAR,0)/60 NECESAR,
      NVL(LOCURI.DISPONIBIL,0) - NVL(NECESAR.NECESAR,0)/60 DIFERENTE,
      NECESAR.CODLOC,
      NVL(LOCURI.DISPONIBIL,0)*60 DISPONIBILM,
      NVL(NECESAR.NECESAR,0) NECESARM,
      NVL(LOCURI.DISPONIBIL,0)*60 - NVL(NECESAR.NECESAR,0) DIFERENTEM
    FROM CRS_NECESAR NECESAR
         INNER JOIN LOCMUNCA LM ON NECESAR.CODLOC = LM.CODLOC
         LEFT JOIN CRS_LOCURI LOCURI ON LOCURI.CODLOC = NECESAR.CODLOC;

    INSERT INTO TMP_PF_MAN(
      CODOP,
      CODTARIF,
      DEN_OP,
      DEN_TARIF,
      TARIF,
      ORE,
      VALOARE,
      OREM,
      OPERATII,
      Den_Locm)
    SELECT
      OP.CodOp,
      T1.CODTARIF,
      OP.DENUMIRE,
      T.DENUMIRE,
      round(T1.TARIF, 2),
      round(sum(round(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0), 2) / 60), 2),
      round(sum(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0) * T1.TARIF / 60), 2),
      round(sum(PFM.CANT * nvl(MAN.TPI, 0) + PFM.CANT * nvl(MAN.TU, 0) * T1.TARIF), 2),
      round(sum(PFM.CANT), 2),
      L.DENUMIRE
    FROM TMP_PROGRAMFMAN_MANEVRA PFM
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCMDPRODMAN = PFM.CODCMDPRODMAN
         INNER JOIN PRODMAN PMAN ON PMAN.CODMAN = MAN.CODMAN
         INNER JOIN COMANDA1 C1 ON MAN.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
         INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
         INNER JOIN TARIFEMAN1 T1 ON T1.CODTARIF = MAN.CODTARIF
         INNER JOIN TARIFEMAN T ON T1.CODTARIF = T.CODTARIF
         INNER JOIN LOCMUNCA L ON L.CODLOC = MAN.CODLOC
    WHERE PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALSTART AND T1.ALSTOP
    GROUP BY OP.CODOP, T1.CODTARIF, OP.DENUMIRE, T.DENUMIRE, T1.TARIF, L.DENUMIRE;
  else
    if not vDinGoTo then
      delete tmp_programf1;
      insert into tmp_programf1
       (codprogramf1,codprogramf, codcomanda1, codgest, termen, cantprogramat, codformatie,
        schimb, den_gest, nrcmd, den_obiect, codextern, um, termenexec, den_client, termenlivr, codobiect,
        codcomanda, durata, duratam, den_formatie, d1, d2, d3, lansat, cantreteta, duratareteta,
        termencmdint,nrcmdcli,obscmdint,obscmdcli,saptamana,prioritate,datastart)
      select
        -1,tmp.codprogramf, c1.codcomanda1, c.codgest, c1.termen,
        tmp.cantprogramat,
        c.codformatie,
        c.schimb, g.den_gest, ROUND(C.NRDOC + c1.indexlocal / 1000, 3) nrcmd, obj.denumire den_obiect, obj.codextern, num1.den_um1 um, c1.termen termenexec,
        case when cs.codcomanda &gt; 0 then ss.den_subunit else p.den_part end den_client, cc1.termen termenlivr, obj.codobiect,
        c.codcomanda, tmp.cantprogramat/pc.cant*nvl(pc.durata,0)/60 durata,
        tmp.cantprogramat/pc.cant*nvl(pc.durata,0) duratam,
        f.den_formatie, c1.d1, c1.d2, c1.d3, c1.cantacceptat lansat, pc.cant cantreteta, pc.durata duratareteta,
        c1.termen termencmdint,case when cs.codcomanda &gt; 0 then ROUND(CS.NRDOC + CS1.indexlocal / 1000, 3) ELSE ROUND(CC.NRDOC + CC1.indexlocal / 1000, 3) END,
        c1.obs,
        case when cs.codcomanda &gt; 0 then CS1.OBS ELSE cc1.obs END,TO_NUMBER(TO_CHAR(C1.TERMEN,&apos;IW&apos;)),gt.prioritate,gt.dstart
      from tmp_programf1_manevra tmp
           inner join comanda1 c1 on c1.codcomanda1 = tmp.codcomanda1
           inner join comanda c on c1.codcomanda = c.codcomanda
           inner join ngest g on g.codgest = c.codgest
           inner join nartobj obj on c1.codobiect = obj.codobiect
           inner join num1 on num1.codum1 = c1.umsec
           inner join prodcomp pc on pc.codprodcomp = c1.codreteta
           LEFT JOIN (Select CodComanda1, CODCMDPRODMAN from CMDPRODMAN x where NROP = 1) PM ON PM.CODCOMANDA1 = C1.CODCOMANDA1
           left JOIN GANTT GT ON GT.CODCMDPRODMAN = PM.CODCMDPRODMAN
           left join formatii f on f.codformatie = c.codformatie
           left join cmdlink ls on ls.codcomanda1 = c1.codcomanda1
           left join comanda1 cs1 on cs1.codcomanda1 = ls.codliniecomanda
           left join comanda cs on cs.codcomanda = cs1.codcomanda
           left join nsubunit ss on ss.codsubunit = cs.subunitsursa
           left join comanda1 cc1 on cc1.codcomanda1 = pkg_comanda.DinCmdCli(c1.codcomanda1)
           left join comanda cc on cc1.codcomanda = cc.codcomanda
           left join npart p on p.codpart = cc.partener
           left join tmp_programf_manevra mm on mm.codprogramf = tmp.codprogramf
			where vTip = 0 or GT.Codgantt is not null;
    end if;

    INSERT INTO TMP_PF_MAT(CODOBIECT,DENUMIRE,CODEXTERN,
                   DEN_UM1,NECESAR,CONSUMAT,DIFERENTE,REZERVAT,STOCFURN,RESTASIGURAT)
    SELECT NOBJ.CODOBIECT, NOBJ.DENUMIRE,NOBJ.CODEXTERN,NUM.DEN_UM,
           ROUND(SUM(PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT),2)  NECESAR,
           ROUND(SUM((PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT) - (PRODM.REST * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT)),2) CONSUMAT,
           ROUND(SUM(PRODM.REST * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT),2) DIFERENTE,
           ROUND(SUM(NVL(REZ.REST,0)),2) REZERVAT,
           ROUND(NVL(CMDFURN.STOCFURN,0),2) STOCFURN ,
           ROUND(SUM(case when PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT - NVL(REZ.REST,0) &lt; 0 then 0 else PRODM.CANT * PF1.CANTPROGRAMAT / C1.CANTACCEPTAT - NVL(REZ.REST,0) end),2)
    FROM COMANDA1 C1 INNER JOIN TMP_PROGRAMF1_MANEVRA PF1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
                     INNER JOIN CMDPRODMAT PRODM ON PRODM.CODCOMANDA1 = C1.CODCOMANDA1
                     INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = PRODM.CODOBIECT
                     INNER JOIN NART N ON N.CODARTICOL = NOBJ.CODARTICOL
                     INNER JOIN NUM ON NUM.CODUM = N.UM
                     LEFT JOIN REZERVATS REZ ON REZ.CODCMDPRODMAT = PRODM.CODCMDPRODMAT
                     LEFT JOIN ( SELECT CFURN1.CODOBIECT,SUM(CFURN1.RESTACCEPTAT) STOCFURN
                                 FROM COMANDA CFURN INNER JOIN COMANDA1 CFURN1 ON CFURN.CODCOMANDA = CFURN1.CODCOMANDA
                                 WHERE CFURN.TIPDOC = 8 GROUP BY CFURN1.CODOBIECT
                               ) CMDFURN ON CMDFURN.CODOBIECT = PRODM.CODOBIECT
    WHERE (C1.CONSUM = 1 AND PRODM.TIP = 1) OR (C1.CONSUM = 2 AND PRODM.TIP IN (0,1))
    GROUP BY NOBJ.CODOBIECT,
             NOBJ.DENUMIRE,
             NOBJ.CODEXTERN,
             NUM.DEN_UM,
             NVL(CMDFURN.STOCFURN,0);
    update TMP_PF_MAT set restasigurat = 0 where restasigurat &lt; 0;

    INSERT INTO TMP_PF_SDV(DENUMIRE,DEN_UM,CODEXTERN,REST,STOCFURN,CANTACT,CANTDOC,CODOBIECT)
    SELECT NOBJ.DENUMIRE,NUM.DEN_UM,NOBJ.CODEXTERN, ROUND(NVL(STOC.REST,0),2) REST, ROUND(NVL(CMDFURN.STOCFURN,0),2) STOCFURN,
           ROUND(NVL(SUM(PSDV.CANT),0),2) CANTACT ,ROUND(SUM(SDV.CANT * PF1.CANTPROGRAMAT),2) CANTDOC,NOBJ.CODOBIECT
    FROM TMP_PROGRAMF1_MANEVRA PF1
         INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN PRODMAN PMAN ON C1.CODRETETA = PMAN.CODPRODCOMP
         INNER JOIN (SELECT S.CODPRODMAN,S.CODSDV,SUM(S.CANT/PC.CANT) CANT
                     FROM PRODSDV S
                          INNER JOIN PRODCOMP PC ON PC.Codprodcomp = S.CODPRODCOMP
                     GROUP BY CODPRODMAN,CODSDV
                    ) SDV ON SDV.CODPRODMAN = PMAN.CODMAN
         LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = SDV.CODSDV
         LEFT JOIN NART N ON N.CODARTICOL = NOBJ.CODARTICOL
         LEFT JOIN NUM ON NUM.CODUM = N.UM
         LEFT JOIN (SELECT NS.CODOBIECT ,SUM(NS.REST) REST
                    FROM NIRSTOC NS
                    GROUP BY NS.CODOBIECT
                   ) STOC ON SDV.CODSDV = STOC.CODOBIECT
         LEFT JOIN (SELECT CFURN1.CODOBIECT,SUM(CFURN1.RESTACCEPTAT) STOCFURN
                    FROM COMANDA CFURN
                         INNER JOIN COMANDA1 CFURN1 ON CFURN.CODCOMANDA = CFURN1.CODCOMANDA
                    WHERE CFURN.TIPDOC = 8 GROUP BY CFURN1.CODOBIECT) CMDFURN ON CMDFURN.CODOBIECT = SDV.CODSDV
         LEFT JOIN (SELECT CODPROGRAMF,SUM(CANT) CANT
                    FROM PROGRAMFSDV
                    GROUP BY CODPROGRAMF) PSDV ON PSDV.CODPROGRAMF = PF1.CODPROGRAMF
    GROUP BY NOBJ.DENUMIRE,NUM.DEN_UM,NOBJ.CODEXTERN,NOBJ.CODOBIECT,NVL(STOC.REST,0),NVL(CMDFURN.STOCFURN,0) ;

    INSERT INTO TMP_PF_LOCM(DENUMIRE,DISPONIBIL,NECESAR,DIFERENTE,CODLOCMUNCA,DISPONIBILM,NECESARM,DIFERENTEM)
     WITH CRS_ZILE AS (
           SELECT
              T.CodProgramf,
              (T.vPanaLa - T.VDeLa) + 1 - (
                SELECT
                  count(zn1.data)
                FROM
                  zineluc1 zn1
                where zn1.data between vDataStart AND vDataStop) zile
            FROM TMP_PROGRAMF_MANEVRA T
           ),
          CRS_NECESAR AS (
           SELECT
             SUM( CASE
                   WHEN PC.CANT &lt;&gt; 1 THEN
                       PF1.CANTPROGRAMAT / PMAN.CANT * NVL(PMAN.TPI, 0)  + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
                   ELSE
                       NVL(PMAN.TPI, 0) + PF1.CANTPROGRAMAT / PMAN.BPS*PMAN.TU
                   END ) NECESAR,
             NVL(PMAN.CODLOC,0) CODLOC
           FROM TMP_PROGRAMF1_MANEVRA PF1
                INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
                INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
                INNER JOIN CMDPRODMAN PMAN ON PMAN.CODCOMANDA1 = PF1.CODCOMANDA1
           GROUP BY PMAN.CODLOC
           ),
         CRS_LOCURI AS (
           select
             x.codloc,
             sum(x.disponibil) disponibil
           from (
                 SELECT distinct LM.CODLOC,
                    LM.DENUMIRE,
                    LM1.ore * zile.zile DISPONIBIL
             FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                   LOCMUNCA LM LEFT JOIN LOCMUNCA1 LM1 ON LM.CODLOC = LM1.CODLOC
                               LEFT JOIN MIFIX1 MF1    ON MF1.CODMIFIX   = LM1.CODMIFIX
                               LEFT JOIN NIRSTOC NS    ON NS.CODNIRSTOC = MF1.CODNIRSTOC
                               LEFT JOIN NIR           ON NIR.CODNIR = NS.CODNIR
                               LEFT JOIN NGEST NG      ON NG.CODGEST = NIR.GEST
                   WHERE LM.TIP = 1 AND NS.Rest &gt; 0 AND MF1.Anstart*12 + MF1.lunastart = (select max(anstart*12+lunastart) from mifix1 where codmifix = LM1.codmifix)
                   UNION ALL
                   SELECT distinct LM.CODLOC,
                          LM.DENUMIRE,
                          LM1.ore * zile.zile DISPONIBIL
                   FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                        LOCMUNCA LM LEFT JOIN LOCMUNCA1 LM1 ON LM.CODLOC = LM1.CODLOC
                   WHERE LM.TIP = 2
                   UNION ALL
                   SELECT distinct LM.CODLOC,
                          LM.DENUMIRE,
                          NVL(G.ORESCHIMB,0) * NVL(G.NRSCHIMBURI,0) * zile.zile DISPONIBIL
                   FROM (SELECT ZILE FROM CRS_ZILE WHERE ROWNUM = 1) ZILE,
                         TMP_PROGRAMF1_MANEVRA MM
                         INNER JOIN CMDPRODMAN MAN ON MM.CODCOMANDA1 = MAN.CODCOMANDA1
                         INNER JOIN LOCMUNCA LM ON MAN.CODLOC = LM.CODLOC
                         INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = MAN.CODCOMANDA1
                         INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
                         INNER JOIN NGEST G ON G.CODGEST = C.CODGEST
                   WHERE LM.TIP = 0
                 ) x group by x.codloc
          )
    SELECT LM.DENUMIRE,
           NVL(LOCURI.DISPONIBIL,0) DISPONIBIL,
           NVL(NECESAR.NECESAR,0)/60 NECESAR,
           NVL(LOCURI.DISPONIBIL,0) - NVL(NECESAR.NECESAR,0)/60  DIFERENTE,
           NECESAR.CODLOC,
           NVL(LOCURI.DISPONIBIL,0)*60 DISPONIBILM,
           NVL(NECESAR.NECESAR,0) NECESARM,
           NVL(LOCURI.DISPONIBIL,0)*60 - NVL(NECESAR.NECESAR,0) DIFERENTEM
    FROM CRS_NECESAR NECESAR
         INNER JOIN LOCMUNCA LM ON NECESAR.CODLOC = LM.CODLOC
         LEFT JOIN CRS_LOCURI LOCURI ON LOCURI.CODLOC = NECESAR.CODLOC;

    INSERT INTO TMP_PF_MAN(CODOP, CODTARIF, DEN_OP, DEN_TARIF, TARIF, ORE, VALOARE, OREM,OPERATII, Den_Locm)
    SELECT OP.CodOp,
           T1.CODTARIF,
           OP.DENUMIRE,
           T.DENUMIRE,
           round(T1.TARIF, 2),
             round(sum(
               case
                 when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
                 ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
               END
               ) / 60, 2),
           round(sum(
             case
               when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
               ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
             END * T1.TARIF
             )  / 60 , 2),
           round(sum(
             case
               when PC.CANT &lt;&gt; 1 THEN round(PF1.CANTPROGRAMAT/nvl(PC.CANT, 1) * nvl(MAN.TPI, 0) + PF1.CANTPROGRAMAT / nvl(MAN.BPS, 1) * nvl(MAN.TU, 0), 2)
               ELSE round(NVL(MAN.TPI, 0) + PF1.CANTPROGRAMAT * nvl(MAN.TU, 0), 2)
             END
             ), 2),
            round(sum(MAN.CANT), 2),
            L.DENUMIRE
    FROM TMP_PROGRAMF1_MANEVRA PF1
         INNER JOIN COMANDA1 C1 ON PF1.CODCOMANDA1 = C1.CODCOMANDA1
         INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = PF1.CODCOMANDA1
         INNER JOIN NOPER OP ON OP.CODOP = MAN.CODOP
         INNER JOIN TARIFEMAN1 T1 ON T1.CODTARIF = MAN.CODTARIF
         INNER JOIN TARIFEMAN T ON T1.CODTARIF = T.CODTARIF
         INNER JOIN LOCMUNCA L ON L.CODLOC = MAN.CODLOC
    WHERE PKG_GLOBALS.AnLunaLucru BETWEEN T1.ALSTART AND T1.ALSTOP
    GROUP BY OP.CODOP, T1.CODTARIF, OP.DENUMIRE, T.DENUMIRE, T1.TARIF, L.DENUMIRE;
    INSERT INTO TMP_PROGRAMFMAN_MANEVRA(CODPFMAN,CODPROGRAMF,CODCMDPRODMAN,CANT)
    SELECT - ROWNUM,
           (SELECT CODPROGRAMF FROM TMP_PROGRAMF_MANEVRA) CODPROGRAMF,
           MAN.CODCMDPRODMAN,
           round(MAN.CANT, 2)
    FROM TMP_PROGRAMF1_MANEVRA PF1
         INNER JOIN CMDPRODMAN MAN ON MAN.CODCOMANDA1 = PF1.CODCOMANDA1;
  end if;
  CALCUL_GEST(XT, YT);
  CALCUL_CMD(XT, YT);
  update_stocuri(vAllGest, vAllTipCont);
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
ora1 DATE;
ora2 DATE;
BEGIN
  vDinGoTo := True;
  vCodProgramF := RecId;
  INSERT INTO TMP_PROGRAMF(CODPROGRAMF,DATAINREG,VDELA,VPANALA,VDELAORA,VPANALAORA,OPERAT,BLOCAT,ANULAT,
	                         TIP,CODFORMATIE,SUBUNITATEA,AN,LUNA, ZILEN,
													 TIPDURATA, NRDOC, CarnetDoc, PREFIXDOC, SERIADOC,
                           ALLGEST, ALLTIPCONT)
  SELECT CODPROGRAMF,DATAINREG,TO_DATE(to_CHAR(VDELA,&apos;dd.mm.yyyy&apos;),&apos;DD.MM.YYYY&apos;),TO_DATE(to_CHAR(VPANALA,&apos;dd.mm.yyyy&apos;),&apos;DD.MM.YYYY&apos;),
         TO_char(VDELA,&apos;HH24:MI:SS&apos;),TO_CHAR(VPANALA,&apos;HH24:MI:SS&apos;),OPERAT,BLOCAT,ANULAT,
				 TIP,CODFORMATIE,SUBUNITATEA,AN,LUNA,
         (SELECT count(zn1.data)
          FROM zineluc1 zn1
          where zn1.data between (select VDELA from ProgramF where CodProgramF = RecId)
                       AND (select VpanaLA from ProgramF where CodProgramF = RecId)),
				 NVL(TIPDURATA, 0), NRDOC, CarnetDoc, PREFIXDOC,SERIADOC,
				 ALLGEST, ALLTIPCONT
  FROM PROGRAMF WHERE CODPROGRAMF = RECID;

  select to_date(to_char(vdela, &apos;HH24&apos;), &apos;HH24&apos;)   into ora1 from programf where codprogramf = recid;
  select to_date(to_char(vpanala, &apos;HH24&apos;), &apos;HH24&apos;) into ora2 from programf where codprogramf = recid;

  INSERT INTO TMP_PROGRAMF1(CODPROGRAMF1,CODPROGRAMF,CODCOMANDA1,CODGEST,DATASTART, PRIORITATE,TERMEN,CANTPROGRAMAT,
                            DEN_GEST,NRCMD,DEN_OBIECT,CODEXTERN,UM, TERMENEXEC,DEN_CLIENT,TERMENLIVR,CODOBIECT,
                            CODCOMANDA, DURATA, DURATAM, SCHIMB, CODFORMATIE, DEN_FORMATIE, D1, D2, D3, LANSAT,
                            CANTRETETA, DURATARETETA, TERMENCMDINT,SAPTAMANA,NRCMDCLI,OBSCMDINT,OBSCMDCLI)
  SELECT PF1.CODPROGRAMF1,PF1.CODPROGRAMF,PF1.CODCOMANDA1,PF1.CODGEST, G.DSTART, G.PRIORITATE,
         PF1.TERMEN,PF1.CANTPROGRAMAT,
         NG.DEN_GEST,ROUND(C.NRDOC + c1.indexlocal / 1000, 3),NOBJ.DENUMIRE,NOBJ.CODEXTERN,NUM1.DEN_UM1, NVL(PF1.TERMEN,C1.TERMEN),
         CASE WHEN CCLIENT.TIPDOC = 44 THEN SS.DEN_SUBUNIT ELSE NP.DEN_PART END,
         c1client.termen,
         NOBJ.CODOBIECT, C.CODCOMANDA, Round(PF1.CANTPROGRAMAT/PC.CANT * PC.DURATA/60, 3), PF1.CANTPROGRAMAT/PC.CANT * PC.DURATA,
         PF1.schimb,pf1.codformatie,F.Den_Formatie, C1.D1, C1.D2, C1.D3, C1.Cantacceptat,
         DECODE(NVL(PC.CANT,0),0,1,NVL(PC.CANT,0)), PC.DURATA,C1.TERMEN,TO_NUMBER(TO_CHAR(NVL(PF1.TERMEN,C1.TERMEN),&apos;IW&apos;)), Round(CCLIENT.NRDOC + C1CLIENT.indexlocal / 1000, 3),
         C1.OBS, C1CLIENT.OBS
  FROM PROGRAMF1 PF1
       INNER JOIN PROGRAMF PF ON PF1.CODPROGRAMF = PF.CODPROGRAMF
       INNER JOIN NGEST NG ON NG.CODGEST = PF1.CODGEST
       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
       INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
       INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
       INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = C1.CODOBIECT
       INNER JOIN NUM1 ON NUM1.CODUM1 = C1.UMSEC
       LEFT JOIN (Select CodComanda1, CODCMDPRODMAN from CMDPRODMAN where NROP = 1) PM ON PM.CODCOMANDA1 = C1.CODCOMANDA1
       left JOIN GANTT G ON G.CODCMDPRODMAN = PM.CODCMDPRODMAN
       LEFT JOIN FORMATII F ON PF1.Codformatie = F.CodFormatie
       LEFT JOIN CMDLINK CLINK ON CLINK.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN COMANDA1 C1CLIENT ON C1CLIENT.CODCOMANDA1 = CLINK.CODLINIECOMANDA
       LEFT JOIN COMANDA CCLIENT ON CCLIENT.CODCOMANDA = C1CLIENT.CODCOMANDA
       LEFT JOIN NSUBUNIT SS ON SS.CODSUBUNIT = CCLIENT.SUBUNITSURSA
       LEFT JOIN NPART NP ON NP.CODPART = CCLIENT.PARTENER
  WHERE PF1.CODPROGRAMF = RECID;


  update tmp_programf pf
  set
    durata = (select sum(pf1.DURATA)
              from tmp_programf1 pf1 where pf.codprogramf = pf1.codprogramf);

  -- populez manevra
  DELETE FROM TMP_PROGRAMF_MANEVRA;
  INSERT INTO TMP_PROGRAMF_MANEVRA(CODPROGRAMF,DATAINREG,VDELA,VPANALA,VDELAORA,VPANALAORA,OPERAT,BLOCAT,ANULAT,TIP,CODFORMATIE,SUBUNITATEA,AN,LUNA, TIPDURATA,
              ALLGEST, ALLTIPCONT )
  SELECT CODPROGRAMF,DATAINREG,TO_DATE(to_CHAR(VDELA,&apos;dd.mm.yyyy&apos;),&apos;DD.MM.YYYY&apos;),TO_DATE(to_CHAR(VPANALA,&apos;dd.mm.yyyy&apos;),&apos;DD.MM.YYYY&apos;),
         TO_char(VDELA,&apos;HH24:MI:SS&apos;),TO_CHAR(VPANALA,&apos;HH24:MI:SS&apos;),OPERAT,
         BLOCAT,ANULAT,TIP,CODFORMATIE,SUBUNITATEA,AN,LUNA, TIPDURATA, ALLGEST, ALLTIPCONT FROM PROGRAMF WHERE CODPROGRAMF = RECID;

  DELETE FROM TMP_PROGRAMF1_MANEVRA;
  INSERT INTO TMP_PROGRAMF1_MANEVRA(CODPROGRAMF1,CODPROGRAMF,CODCOMANDA1,CODGEST,PRIORITATE,CANTPROGRAMAT,DURATARETETA,TERMENEXEC,DATASTART,
                                    DEN_GEST,NRCMD,DEN_OBIECT,CODEXTERN,UM,DEN_CLIENT,CODOBIECT,CODCOMANDA,DURATA, DURATAM, D1, D2, D3, CANTRETETA)
  SELECT PF1.CODPROGRAMF1,PF1.CODPROGRAMF,PF1.CODCOMANDA1,PF1.CODGEST,PF1.PRIORITATE,PF1.CANTPROGRAMAT,PC.DURATA,MAX(PF1.TERMENEXEC),PF1.DATASTART,
         PF1.DEN_GEST,PF1.NRCMD,PF1.DEN_OBIECT,PF1.CODEXTERN,PF1.UM,PF1.DEN_CLIENT,PF1.CODOBIECT,PF1.CODCOMANDA,PF1.DURATA, PF1.DURATAM, PF1.D1, PF1.D2, PF1.D3, PC.CANT
  FROM TMP_PROGRAMF1 PF1
       INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = PF1.CODCOMANDA1
       INNER JOIN PRODCOMP PC ON C1.CODRETETA = PC.CODPRODCOMP
  GROUP BY PF1.CODPROGRAMF1,PF1.CODPROGRAMF,PF1.CODCOMANDA1,PF1.CODGEST,PF1.PRIORITATE,PF1.CANTPROGRAMAT,PC.DURATA,PF1.DATASTART,
         PF1.DEN_GEST,PF1.NRCMD,PF1.DEN_OBIECT,PF1.CODEXTERN,PF1.UM,PF1.DEN_CLIENT,PF1.CODOBIECT,PF1.CODCOMANDA,PF1.DURATA, PF1.DURATAM, PF1.D1, PF1.D2, PF1.D3, PC.CANT;

  INSERT INTO TMP_LOCURIMUNCAOBS(IDOBS,CODPROGRAMF1,CODLOCMUNCA,OBS)
  SELECT IDOBS,CODPROGRAMF1,CODLOCMUNCA,OBS FROM LOCURIMUNCAOBS WHERE EXISTS (SELECT TMP.CODPROGRAMF1 FROM TMP_PROGRAMF1 TMP WHERE TMP.CODPROGRAMF1 = CODPROGRAMF1);

  INSERT INTO TMP_PROGRAMFMAN (CODPFMAN, CODPROGRAMF, CODCMDPRODMAN, CANT)
  SELECT CODPFMAN, CODPROGRAMF, CODCMDPRODMAN, CANT FROM PROGRAMFMAN;
  INSERT INTO TMP_PROGRAMFMAN_MANEVRA(CODPFMAN,CODPROGRAMF,CODCMDPRODMAN,CANT)
  SELECT CODPFMAN, CODPROGRAMF, CODCMDPRODMAN, CANT FROM PROGRAMFMAN;

  INSERT INTO TMP_PROGRAMFGEST(CODPROGRAMF, CODGEST)
  SELECT CODPROGRAMF, CODGEST
  FROM PROGRAMFGEST
  WHERE CODPROGRAMF = RECID;

  INSERT INTO TMP_PROGRAMFCONT (CODPROGRAMF, CODIOART)
  SELECT CODPROGRAMF, CODIOART
  FROM PROGRAMFCONT
  WHERE CODPROGRAMF = RECID;

  delete tmp_manevra_liste where filtru = &apos;CODGEST&apos; OR FILTRU = &apos;CODIOART&apos;;
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU, VALOARE)
  SELECT &apos;CODGEST&apos;, CODGEST FROM TMP_PROGRAMFGEST;
  INSERT INTO TMP_MANEVRA_LISTE(FILTRU, VALOARE)
  SELECT &apos;CODIOART&apos;, CODIOART FROM TMP_PROGRAMFCONT;

  CALCUL_DETALII(to_char(ora1, &apos;HH24&apos;), to_char(ora2, &apos;HH24&apos;), 0);
  for v_rec in (select CODLMC, codprogramf, codgest, codloc, codcomanda1, codop from TMP_PF_LOCM_CMD) loop
    for v_xxx in (select pflmc.dataprogramare
                  from programflmc pflmc
                  where pflmc.codprogramf = v_rec.codprogramf and pflmc.codgest = v_rec.codgest
                        and pflmc.codloc = v_rec.codloc and pflmc.codcomanda1 = v_rec.codcomanda1 AND pflmc.CODOP = v_rec.CODOP) loop
      update TMP_PF_LOCM_CMD set dataprogramare = v_xxx.dataprogramare where codlmc = v_rec.codlmc;
      Exit;
    end loop;
  end loop;
  vDinGoTo := False;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ) IS
aCARNETDOC    NUMBER(20);
aNRDOC        NUMBER(20);
aCodSubunit   NUMBER(20);
aDataDoc      DATE;
aDoc          VARCHAR2(200);
BEGIN
  SELECT
    Nvl(CARNETDOC,0),
    NRDOC,
    Subunitatea,
    DataInreg,
    PREFIXDOC||NRDOC||&apos;/&apos;||DATAINREG
  INTO
    aCARNETDOC,
    aNRDOC,
    aCodSubunit,
    aDataDoc,
    aDoc
  FROM TMP_PROGRAMF;

  IF OPERATION = 0 THEN --UPDATE
    SELECT CODPROGRAMF INTO RECID FROM TMP_PROGRAMF ;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROGRAMF&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE PROGRAMF  SET
      (DATAINREG,VDELA,VPANALA,OPERAT,BLOCAT,ANULAT,TIP,CODFORMATIE, TIPDURATA,NRDOC, CARNETDOC, PREFIXDOC,SERIADOC,ALLGEST, ALLTIPCONT) =
      (SELECT DATAINREG, VDELA, VPANALA,
              OPERAT,BLOCAT,ANULAT,TIP,CODFORMATIE,TIPDURATA,NRDOC, CARNETDOC, PREFIXDOC,SERIADOC, ALLGEST, ALLTIPCONT FROM TMP_PROGRAMF)
    WHERE CODPROGRAMF = RECID;

    FOR V_REC IN (SELECT P1.CODPROGRAMF1
                  FROM PROGRAMF1 P1 WHERE NOT EXISTS(SELECT CODPROGRAMF1 FROM  TMP_PROGRAMF1 WHERE CODPROGRAMF1 = P1.CODPROGRAMF1)
                                   AND CODPROGRAMF = RECID
                 ) LOOP
      DELETE FROM PROGRAMF1 P1 WHERE P1.CODPROGRAMF1 = V_REC.CODPROGRAMF1;
      update intrprodlink set codprogramf1 = null where codprogramf1 = v_rec.codprogramf1;
      update iesprodlink set codprogramf1 = null where codprogramf1 = v_rec.codprogramf1;
    END LOOP;
    INSERT INTO PROGRAMF1(CODPROGRAMF1,CODPROGRAMF,CODCOMANDA1,CODGEST,PRIORITATE,TERMEN,CANTPROGRAMAT,SCHIMB, CODFORMATIE)
    SELECT SEQ_PROGRAMF1_CODPROGRAMF1.NEXTVAL,RECID,CODCOMANDA1,CODGEST,PRIORITATE,TERMENEXEC,CANTPROGRAMAT,SCHIMB, CODFORMATIE
    FROM TMP_PROGRAMF1 WHERE CODPROGRAMF1 &lt;= 0;

    FOR V_REC IN (SELECT * FROM TMP_PROGRAMF1 where codprogramf1 &gt; 0) LOOP
      UPDATE PROGRAMF1 SET
        CODCOMANDA1   = V_REC.CODCOMANDA1  ,
        CODGEST       = V_REC.CODGEST      ,
        PRIORITATE    = V_REC.PRIORITATE   ,
        TERMEN        = V_REC.TERMENEXEC   ,
        CANTPROGRAMAT = V_REC.CANTPROGRAMAT,
        SCHIMB        = V_REC.SCHIMB,
        CODFORMATIE   = V_REC.CODFORMATIE
      WHERE CODPROGRAMF1 = V_REC.CODPROGRAMF1;
    END LOOP;

    DELETE FROM PROGRAMFSDV PSDV WHERE NOT EXISTS(SELECT CODPROGRAMFSDV FROM TMP_PF_SDV_GEST WHERE CODPROGRAMFSDV = PSDV.CODPROGRAMFSDV)
                                        AND CODPROGRAMF = RECID;

    INSERT INTO PROGRAMFSDV(CODPROGRAMFSDV ,CODPROGRAMF ,CODGEST ,CODOBIECT ,CANT)
    SELECT SEQ_PROGRAMFSDV_CODPROGRAMFSDV.NEXTVAL,RECID,CODGEST,CODOBIECT,CANT FROM TMP_PF_SDV_GEST WHERE CODPROGRAMFSDV &lt;=0;

    FOR V_REC IN (SELECT * FROM TMP_PF_SDV_GEST) LOOP
      UPDATE PROGRAMFSDV SET CANT = V_REC.CANT WHERE CODPROGRAMFSDV = V_REC.CODPROGRAMFSDV;
    END LOOP;

   --  DELETE FROM LOCURIMUNCAOBS WHERE NOT EXISTS (SELECT
    DELETE FROM LOCURIMUNCAOBS L WHERE NOT EXISTS (SELECT IDOBS FROM TMP_LOCURIMUNCAOBS WHERE IDOBS = L.IDOBS)
                                       AND EXISTS (SELECT CODPROGRAMF1 FROM TMP_PROGRAMF1 WHERE L.CODPROGRAMF1 = CODPROGRAMF1);

    INSERT INTO LOCURIMUNCAOBS(IDOBS,CODPROGRAMF1,CODLOCMUNCA,OBS)
    SELECT SEQ_LOCURIMUNCAOBS_ID.NEXTVAL,CODPROGRAMF1,CODLOCMUNCA,OBS FROM TMP_LOCURIMUNCAOBS WHERE IDOBS &lt;=0;

    FOR V_REC IN (SELECT * FROM TMP_LOCURIMUNCAOBS) LOOP
      UPDATE LOCURIMUNCAOBS SET OBS = V_REC.OBS WHERE IDOBS = V_REC.IDOBS;
    END LOOP;

    DELETE PROGRAMFLMC PLMC WHERE NOT EXISTS (SELECT TMP.CODLMC FROM TMP_PF_LOCM_CMD TMP WHERE TMP.CODLMC = PLMC.CODLMC) AND PLMC.CODPROGRAMF = RECID;
    FOR V_REC IN (SELECT * FROM TMP_PF_LOCM_CMD) LOOP
      IF V_REC.CODLMC &gt; 0 THEN
        UPDATE PROGRAMFLMC SET
          codgest = V_REC.CODGEST,
          codloc = V_REC.CODLOC,
          codcomanda1 = V_REC.CODCOMANDA1,
          dataprogramare = V_REC.DATAPROGRAMARE,
          CODOP = V_REC.CODOP
        WHERE CODLMC = V_REC.CODLMC;
      ELSE
        INSERT INTO PROGRAMFLMC(CODLMC, CODPROGRAMF, CODGEST, CODLOC, CODCOMANDA1, DATAPROGRAMARE,CODOP)
        VALUES (SEQ_PROGRAMFLMC_CODLMC.NEXTVAL, RECID, V_REC.CODGEST, V_REC.CODLOC, V_REC.CODCOMANDA1, V_REC.DATAPROGRAMARE,V_REC.CODOP);
      END IF;
    END LOOP;

    DELETE PROGRAMFMAN PFMAN WHERE NOT EXISTS
    (SELECT TMP.CODCMDPRODMAN
     FROM TMP_PROGRAMFMAN_MANEVRA TMP
     WHERE TMP.CODCMDPRODMAN = PFMAN.CODCMDPRODMAN
    ) AND PFMAN.CODPROGRAMF = RECID;
    FOR V_REC IN (SELECT * FROM TMP_PROGRAMFMAN_MANEVRA) LOOP
      IF V_REC.CODPFMAN &gt; 0 THEN
        UPDATE PROGRAMFMAN SET
          CODCMDPRODMAN = V_REC.CODCMDPRODMAN,
          CANT          = V_REC.CANT
        WHERE CODPFMAN = V_REC.CODPFMAN;
      ELSE
        INSERT INTO PROGRAMFMAN(CODPFMAN, CODPROGRAMF, CODCMDPRODMAN, CANT)
        VALUES (SEQ_PROGRAMFMAN_CODPROGRAMFMAN.NEXTVAL, RECID, V_REC.CODCMDPRODMAN, V_REC.CANT);
      END IF;
    END LOOP;

    DELETE PROGRAMFGEST WHERE CODPROGRAMF = RECID;
    INSERT INTO PROGRAMFGEST (CODPROGRAMF, CODGEST)
    SELECT RECID, CODGEST
    FROM TMP_PROGRAMFGEST;

    DELETE PROGRAMFCONT WHERE CODPROGRAMF = RECID;
    INSERT INTO PROGRAMFCONT (CODPROGRAMF, CODIOART)
    SELECT RECID, CODIOART
    FROM TMP_PROGRAMFCONT;

  ELSE --INSERT
    SELECT SEQ_PROGRAMF_CODPROGRAMF.NEXTVAL INTO RECID FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
       WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROGRAMF&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO PROGRAMF(CODPROGRAMF,DATAINREG,VDELA,VPANALA,OPERAT,BLOCAT,ANULAT,TIP,CODFORMATIE,SUBUNITATEA,TipDurata,
                         AN,LUNA,NRDOC,CARNETDOC,PREFIXDOC,SERIADOC,ALLGEST,ALLTIPCONT)
    SELECT RECID,DATAINREG,VDELA, VPANALA,
           OPERAT,BLOCAT,ANULAT,TIP,CODFORMATIE,PKG_GLOBALS.GETSUBUNITATE_DOC,TipDurata,
           PKG_GLOBALS.GetANLUCRU,PKG_GLOBALS.GetLUNALUCRU,NRDOC,CARNETDOC,PREFIXDOC,SERIADOC,
           ALLGEST, ALLTIPCONT
    FROM TMP_PROGRAMF;

    INSERT INTO PROGRAMF1(CODPROGRAMF1,CODPROGRAMF,CODCOMANDA1,CODGEST,PRIORITATE,TERMEN,CANTPROGRAMAT,SCHIMB,CODFORMATIE)
    SELECT SEQ_PROGRAMF1_CODPROGRAMF1.NEXTVAL,RECID,CODCOMANDA1,CODGEST,PRIORITATE,TERMENEXEC,CANTPROGRAMAT,SCHIMB,CODFORMATIE
    FROM TMP_PROGRAMF1;

    INSERT INTO PROGRAMFSDV(CODPROGRAMFSDV,CODPROGRAMF,CODGEST,CODOBIECT,CANT)
    SELECT SEQ_PROGRAMFSDV_CODPROGRAMFSDV.NEXTVAL,RECID,CODGEST,CODOBIECT,CANT FROM TMP_PF_SDV_GEST;

    INSERT INTO LOCURIMUNCAOBS(IDOBS,CODPROGRAMF1,CODLOCMUNCA,OBS)
    SELECT SEQ_LOCURIMUNCAOBS_ID.NEXTVAL,CODPROGRAMF1,CODLOCMUNCA,OBS FROM LOCURIMUNCAOBS;

    INSERT INTO PROGRAMFLMC(CODLMC, CODPROGRAMF, CODGEST, CODLOC, CODCOMANDA1, DATAPROGRAMARE,CODOP)
    SELECT SEQ_PROGRAMFLMC_CODLMC.NEXTVAL, RECID, CODGEST, CODLOC, CODCOMANDA1, DATAPROGRAMARE,CODOP
    FROM TMP_PF_LOCM_CMD;

    INSERT INTO PROGRAMFMAN (CODPFMAN, CODPROGRAMF, CODCMDPRODMAN, CANT)
    SELECT SEQ_PROGRAMFMAN_CODPROGRAMFMAN.NEXTVAL, RECID, CODCMDPRODMAN, CANT
    FROM TMP_PROGRAMFMAN_MANEVRA;

    INSERT INTO PROGRAMFGEST (CODPROGRAMF, CODGEST)
    SELECT RECID, CODGEST FROM TMP_PROGRAMFGEST;

    INSERT INTO PROGRAMFCONT (CODPROGRAMF, CODIOART)
    SELECT RECID, CODIOART FROM TMP_PROGRAMFCONT;
  END IF;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0) AND (aCARNETDOC &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNETDOC, aNRDOC);

  NotifyModif(Operation, RecId, &apos;CODPROGRAMF&apos;);

  COMMIT;
END;

PROCEDURE UPDATEPF(aCodProgramF IN NUMBER, aCodComanda1 IN NUMBER, aCant IN NUMBER, aTermen IN VARCHAR2) IS
aCodProgramF1 number(20);
aCodGest number(20);
BEGIN
  begin
    select codprogramf1 into aCodProgramF1
    from programf1
    where codprogramf = aCodProgramF and termen = to_date(aTermen, &apos;dd.mm.yyyy&apos;) and codcomanda1 = aCodComanda1;
  exception when others then
    aCodProgramF1 := 0;
  end;

  select c.codgest into aCodGest
  from comanda c
       inner join comanda1 c1 on c.codcomanda = c1.codcomanda
  where c1.codcomanda1 = aCodComanda1;

  if aCodProgramF1 &gt; 0 then
    update programf1 set CANTPROGRAMAT = CANTPROGRAMAT + aCant
    where codprogramf1 = aCodProgramF1;
  else
    select seq_programf1_codprogramf1.nextval into aCodProgramF1 from dual;
    insert into programf1(codprogramf1, codprogramf, codcomanda1, codgest, termen, cantprogramat)
    values (aCodProgramF1, aCodProgramF, aCodComanda1, aCodGest, to_date(aTermen,&apos;dd.mm.yyyy&apos;), aCant);
  end if;
END;

function UpdateTermenPF(aCodProgramF1 in number, aTermen in varchar2) return number is
aCodProgramF number(20);
aRez number(1);
begin
  aRez := 1;
  begin
    select codprogramf into aCodProgramF from programf1 where codprogramf1 = aCodProgramF1;
  exception when others then aRez := 0;
  end;
  if aRez = 0 then return 0; end if;

  begin
    pkg_programf.SP_LOCKRECORD(aCodProgramF);
  exception when others then aRez := 0;
  end;
  if aRez = 0 then return 0; end if;

  begin
    update programf1 set termen = to_date(aTermen, &apos;dd.mm.yyyy&apos;) where codprogramf1 = aCodProgramF1;
    commit;
  exception when others then aRez := 0;
  end;

  return aRez;
end;

procedure SetDinGoTo(aDinGoTo in boolean) is
begin
  vDinGoTo := aDinGoTo;
end;

procedure CURATA_ZERO(aCodProgramF in number) is
begin
  for v_rec in (select codprogramf1
                from programf1
                where codprogramf = aCodProgramF and CantProgramat = 0
               ) loop
    delete locurimuncaobs where codprogramf1 = v_rec.codprogramf1;
    delete programf1 where codprogramf1 = v_rec.codprogramf1;
  end loop;
  commit;
end;

end PKG_PROGRAMF;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1643D9C094D620A2CAA68C19BC16F715BAE8B8E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROIECT IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_42&apos;;
vCodProiect number(20);
DoCommit boolean := true;

procedure UpdateIndexCopii(aCodProiectNod in number) is
aIndexParinte varchar2(50);
begin
  select indexparinte into aIndexParinte from proiectnod where codproiectnod = aCodProiectNod;
  for v_rec in (
    select pozitie, codproiectnod
    from proiectnod
    where nodoriginal = aCodProiectNod
    order by pozitie
  ) loop
    update proiectnod set indexparinte = aIndexParinte||&apos;.&apos;||LPAD(to_char(v_rec.pozitie), 2, &apos;0&apos;) where codproiectnod = v_rec.codproiectnod;
  end loop;
  commit;
  for v_rec in (
    select codproiectnod
    from proiectnod
    where nodoriginal = aCodProiectNod and tip &lt; 3
  ) loop
    UpdateIndexCopii(v_Rec.Codproiectnod);
  end loop;
end;  

procedure UpdateIndexParinte(aCodProiect in number default 0) is
begin
  for v_rec in (
    select p.codproiect, pn0.codproiectnod
    from proiect p
         inner join proiectnod pn0 on pn0.codproiect = p.codproiect and pn0.nodoriginal = 0
    where aCodProiect = 0 or p.CodProiect = aCodProiect
  ) loop
    Update proiectnod set IndexParinte = &apos;.00&apos; where codproiectnod = v_rec.codproiectnod;
    UpdateIndexCopii(v_rec.codproiectnod);
  end loop;
end;

procedure SetNecesar(aNecesar in number) is
begin
  vNecesar := aNecesar;
end;

function GENRETCENTRALIZATOARE(aCodProiect in number) return number is pragma autonomous_transaction;
vCodProdComp number(20);
vCodProdGest number(20);
begin
  select seq_prodcomp_codprodcomp.nextval into vCodProdComp from dual;
  for v_rec in (select pc.*, pn0.cant cantnou
                from proiect p
                     inner join proiectnod pn0 on pn0.codproiect = p.codproiect and pn0.nodoriginal = 0
                     inner join prodcomp pc on pn0.codreteta = pc.codprodcomp
                where p.codproiect = aCodProiect) loop
    insert into prodcomp (codprodcomp, codobiect, obs, data, anulat, blocat, operat, 
                          cant, pret, coefindirecte, implicit, descriere, inactiv, gest, 
                          identificator, datadocumentatie, arhiva, observatii, proiectant, 
                          codclasaprod, invizibila, generic, durata, userid, datacreare, 
                          hfactor, valmat, valman, valregie, tippret, codproiect, 
                          obs1, obs2, obs3, obs4, obs5, obs6, codmoneda, pretvaluta, ag, 
                          valag, profit, valprofit, pretfinal, valprofitv, pretfinalv, 
                          totpretcoef, totpretfix, totpretcoefv, totpretfixv, valregieman)            
    values (vCodProdComp, v_rec.codobiect, v_rec.obs, v_rec.data, v_rec.anulat, v_rec.blocat, v_rec.operat, 
            v_rec.cantnou, v_rec.pret, v_rec.coefindirecte, 0, v_rec.descriere, v_rec.inactiv, v_rec.gest, 
            v_rec.identificator, v_rec.datadocumentatie, v_rec.arhiva, v_rec.observatii, v_rec.proiectant, 
            v_rec.codclasaprod, v_rec.invizibila, 0, v_rec.durata, v_rec.userid, v_rec.datacreare, 
            v_rec.hfactor, v_rec.valmat, v_rec.valman, v_rec.valregie, v_rec.tippret, aCodProiect, 
            v_rec.obs1, v_rec.obs2, v_rec.obs3, v_rec.obs4, v_rec.obs5, v_rec.obs6, v_rec.codmoneda, v_rec.pretvaluta, v_rec.ag, 
            v_rec.valag, v_rec.profit, v_rec.valprofit, v_rec.pretfinal, v_rec.valprofitv, v_rec.pretfinalv, 
            v_rec.totpretcoef, v_rec.totpretfix, v_rec.totpretcoefv, v_rec.totpretfixv, v_rec.valregieman);
    Exit;        
  end loop;
  
  select seq_prodgest_codprodgest.nextval into vCodProdGest from dual;
  for v_rec in (select pg.*
                from proiect p
                     inner join proiectnod pn0 on pn0.codproiect = p.codproiect and pn0.nodoriginal = 0
                     inner join prodgest pg on pn0.codreteta = pg.codprodcomp
                where p.codproiect = aCodProiect) loop
    insert into prodgest(codprodgest, codprodcomp, indexlocal, codgest, coefmat, coefman)
    values(seq_prodgest_codprodgest.nextval, vCodProdComp, v_rec.indexlocal, v_rec.codgest, v_rec.coefmat, v_rec.coefman);            
    Exit;
  end loop;              
  
  for v_rec in (select sum(pn.cant) Cant_Nou,
                       mat.codobiect, mat.pret, mat.d1, mat.d2, mat.d3,
                       mat.indexlocal, sum(pn.cant / mat.cant * mat.cantum1) cantum1, mat.tip, mat.codatribut, sum(pn.cant / pc.cant * mat.valmat) valmat,
                       sum(pn.cant / mat.cant * mat.valman) valman, sum(pn.cant / mat.cant * mat.valregie) valregie, mat.adddim, mat.adddim_transp, mat.pretorig, mat.procreal,
                       sum(pn.cant / mat.cant * mat.valoare) valoare, mat.copyd1, mat.copyd2, mat.copyd3
                from proiectnod pn
                     left join prodmat mat on mat.codmat = pn.codprodmat
                     left join prodcomp pc on mat.codprodcomp = pc.codprodcomp
                where pn.tip = 3 and pn.codproiect = aCodProiect
                group by mat.codobiect, mat.pret, mat.d1, mat.d2, mat.d3, mat.indexlocal,
                       mat.tip, mat.codatribut, mat.adddim, mat.adddim_transp, mat.pretorig, mat.procreal,
                       mat.copyd1, mat.copyd2, mat.copyd3
               ) loop
    insert into prodmat (codmat, codprodcomp, codobiect, cant, pret, d1, d2, d3,
                         indexlocal, cantum1, codprodgest, tip, codatribut, valmat,
                         valman, valregie, adddim, adddim_transp, pretorig, procreal,
                         valoare, copyd1, copyd2, copyd3)
    values(seq_prodmat_codmat.nextval, vCodProdComp, v_rec.codobiect, v_rec.cant_nou, v_rec.pret, v_rec.d1, v_rec.d2, v_rec.d3,
           v_rec.indexlocal, v_rec.cantum1, vCodProdGest, v_rec.tip, v_rec.codatribut, v_rec.valmat,
           v_rec.valman, v_rec.valregie, v_rec.adddim, v_rec.adddim_transp, v_rec.pretorig, v_rec.procreal,
           v_rec.valoare, v_rec.copyd1, v_rec.copyd2, v_rec.copyd3);
  end loop;
  commit;
  return vCodProdComp;
end;

function GetValCampProiectExtins(NrField in number, CodProiect in number) return varchar2 is
Val varchar2(250);
sSelect varchar2(500);
begin
  if pkg_list_struct.TmpExists(&apos;PROIECTEXT&apos;) = 0 then Return &apos;&apos;; end if;
  Val := &apos;&apos;;
  for v_rec in (select tab.*, RowNum NrField
                from user_tab_columns tab
                where tab.table_name = &apos;PROIECTEXT&apos;) loop
    if NrField = v_rec.NrField then
      if v_rec.data_type = &apos;NUMBER&apos; then
        sSelect := &apos;select to_char(&apos;||v_rec.column_name||&apos;) from proiectext where codproiect = &apos;||CodProiect;
        execute immediate sSelect into Val; 
      end if;
      if v_rec.data_type = &apos;VARCHAR2&apos; then
        sSelect := &apos;select &apos;||v_rec.column_name||&apos; from proiectext where codproiect = &apos;||CodProiect;
        execute immediate sSelect into Val;
      end if;
      if v_rec.data_type = &apos;DATE&apos; then
        sSelect := &apos;select to_char(&apos;||v_rec.column_name||&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;) from proiectext where codproiect = &apos;||CodProiect;
        execute immediate sSelect into Val;
      end if;
      Exit;
    end if;            
  end loop;  
  Return Val;            
end;  

function GetNecesar return number is
begin  
  return vNecesar;
end;

function LockProject(aCodProdComp in number) return number is
Rez number(1);
begin
  Rez := 1;
  for v_rec in (select distinct P.CodProiect
                from proiect p
                     inner join proiectnod pn on p.codproiect = pn.codproiect
                where pn.codreteta = aCodProdComp     
                ) loop
    begin            
      SP_LOCKRECORD(v_rec.codproiect);            
    exception when others then 
      Rez := 0;
      Exit;
    end;  
  end loop;
    
  if Rez = 0 then 
    Rollback;
  end if;
  
  return Rez;
end;

function DeleteProject(aCodProdComp in number) return number is pragma autonomous_transaction;
Rez number(1);
begin
  Rez := 1;
  for v_rec in (select distinct P.CodProiect
                from proiect p
                     inner join proiectnod pn on p.codproiect = pn.codproiect
                where pn.codreteta = aCodProdComp     
                ) loop
    begin            
      SP_LOCKRECORD(v_rec.codproiect);            
    exception when others then 
      Rez := 0;
      Rollback;
      Exit;
    end;  
  end loop;                    
  if Rez = 0 then Return Rez; end if;
  
  for v_rec in (select distinct P.CodProiect
                from proiect p
                     inner join proiectnod pn on p.codproiect = pn.codproiect
                where pn.codreteta = aCodProdComp     
                ) loop
    begin            
      SP_DELETERECORD_FARALOCKCOMMIT(v_rec.codproiect);            
    exception when others then 
      Rez := 0;
      Exit;
    end;  
  end loop;  
  if Rez = 0 then 
    Rollback;
  else
    commit;    
  end if;
  
  return Rez;
end;

function GENPRJFROMRETETA(aCodProdComp IN NUMBER, NeGeneric IN NUMBER DEFAULT 0) return number is pragma autonomous_transaction;
vCod number(20);
vCodNod number(20);
vCant number(20,7);
aDurata number(20,7);
begin
  select seq_proiect_codproiect.nextval into vCod from dual;
  select Cant into vCant from ProdComp where codprodcomp = aCodProdComp;
  insert into proiect (codproiect, codobiectprod, versiune, intocmita, dataproiect, procesare, clasa
                       , activ, finalizat, blocat, invizibila, generic, implicit, userid, datacreare)
  select vCod, codobiect, substr(Obs,1,100), proiectant, data, tipreteta, codclasaprod,
          1, 1, 0, 0, 1, 0, pkg_globals.GETUSERID, sysdate 
  from prodcomp
  where codprodcomp = aCodProdComp;
  
  select seq_proiectnod_codproiectnod.nextval into vCodNod from dual;
  insert into proiectnod(codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, 
                         tip, codobiect, indexparinte, nivel)
  select vCodNod, vCod, cant, 0, 0, aCodProdComp,
         tipreteta, codobiect, &apos;.00&apos;, 0
  from prodcomp 
  where codprodcomp = aCodProdComp;
  
  BagaProiectNodDinReteta(vCod, aCodProdComp, vCant, &apos;.00&apos;, vCodNod, 0);
  
  delete tmp_proiectman;
  insert into tmp_proiectman (
    CODPROIECTNOD,
    CODPROIECT,   
    NODORIGINAL,  
    POZITIE,      
    CODRETETA,    
    DEN_OBIECT,   
    TIP,          
    SIMBOL,       
    DURATA,       
    CANT,         
    NIVEL,        
    ORDINE,       
    INCEPERE,
    Decalaj,
    DURATANOD,    
    COPILMAXIM,   
    NODCRITIC,    
    BARA         
    )
  select PN.CODPROIECTNOD,
       PN.CODPROIECT,
       PN.NODORIGINAL,
       PN.POZITIE,
       PN.CODRETETA,
       obj.denumire den_obiect,
       0,
       pn.IndexParinte Simbol,
       Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
       pn.Cant,
       pn.nivel,
       o.Ordine,
       0,
       0,
       0,
       -1,
       &apos;...&apos; NodCritic,
       &apos;...&apos; bara
  from proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
       inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = vCod) - Nivel as Ordine
                   from proiectnod WHERE CodProiect = vCod Group by Nivel) O on O.Nivel = pn.Nivel
  WHERE PN.CodProiect = vCod and pc.codprodcomp &gt; 0;

  SetCopilMaxim(vCod);
  
  aDurata := 0;
  begin
    select DurataNod into aDurata from tmp_proiectman where nvl(nodoriginal,0) = 0;
  exception when others then aDurata := 0; 
  end;

  if aDurata &lt;&gt; 0 then 
    update proiect set Durata = aDurata
    where CodProiect = vCod;
  end if;
  commit;
  return vCod;
end;

procedure BagaProiectNodDinReteta(aCodProiect in number, aCodProdComp in number, aCant in number, aIndexParinte in varchar2, aNodOriginal in number, aNivel in number, NeGeneric IN NUMBER DEFAULT 0) is
Nivel number(10);
RetetaGenerica number(20);
vCodNod number(20);
begin
  Nivel := aNivel + 1;
  for v_rec in (select mat.*, pc.cant cantreteta, rownum lvl
                from prodmat mat
                     inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp 
                where pc.codprodcomp = aCodProdComp order by mat.codmat) loop
      
    if NeGeneric &gt; 0 then
      RetetaGenerica := v_rec.codreteta;
    else  
      RetetaGenerica := pkg_prodcomp.GetRetetaGenerica(v_rec.codobiect);
    end if;  
    if not v_rec.tip in (1,2) then RetetaGenerica := 0; end if;
    select seq_proiectnod_codproiectnod.nextval into vCodNod from dual;     
    
    if v_rec.lvl &lt; 10 then 
      insert into proiectnod(codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, tip, codobiect, indexparinte, 
                             codprodmat, nivel)
      values (vCodNod, aCodProiect, v_rec.cant/v_rec.cantreteta*aCant, aNodOriginal, v_rec.lvl, RetetaGenerica, v_Rec.tip, v_rec.codobiect, 
              aIndexParinte||&apos;.&apos;||&apos;0&apos;||to_char(v_rec.lvl), v_rec.codmat, Nivel);
    else
      insert into proiectnod(codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, tip, codobiect, indexparinte, 
                             codprodmat, nivel)
      values (vCodNod, aCodProiect, v_rec.cant/v_rec.cantreteta*aCant, aNodOriginal, v_rec.lvl, RetetaGenerica, v_Rec.tip, v_rec.codobiect, 
              aIndexParinte||&apos;.&apos;||to_char(v_rec.lvl), v_rec.codmat, Nivel);
    end if;
            
    if v_rec.tip &lt; 3 then
      if RetetaGenerica &gt; 0 then 
        if v_rec.lvl &lt; 10 then
          BagaProiectNodDinReteta(aCodProiect, RetetaGenerica, v_rec.cant/v_rec.cantreteta*aCant, aIndexParinte||&apos;.&apos;||&apos;0&apos;||to_char(v_rec.lvl), vCodNod, Nivel); 
        else
          BagaProiectNodDinReteta(aCodProiect, RetetaGenerica, v_rec.cant/v_rec.cantreteta*aCant, aIndexParinte||&apos;.&apos;||to_char(v_rec.lvl), vCodNod, Nivel);
        end if;  
      end if;  
    end if;  
  end loop;
end;

function GenProiectGeneric(aCodProdComp IN NUMBER) return number is pragma autonomous_transaction;
vCod number(20);
vCodNod number(20);
vCant number(20,7);
aDurata number(20,7);
begin
  begin 
    vCod := 0;
    select seq_proiect_codproiect.nextval into vCod from dual;
    select Cant into vCant from ProdComp where codprodcomp = aCodProdComp;
    insert into proiect (codproiect, codobiectprod, versiune, intocmita, dataproiect, procesare, clasa
                         , activ, finalizat, blocat, invizibila, generic, implicit, userid, datacreare)
    select vCod, codobiect, Obs, proiectant, data, tipreteta, codclasaprod,
            1, 1, 0, 0, 1, 0, pkg_globals.GETUSERID, sysdate 
    from prodcomp
    where codprodcomp = aCodProdComp;
    
    select seq_proiectnod_codproiectnod.nextval into vCodNod from dual;
    insert into proiectnod(codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, 
                           tip, codobiect, indexparinte, nivel)
    select vCodNod, vCod, cant, 0, 0, aCodProdComp,
           tipreteta, codobiect, &apos;.00&apos;, 0
    from prodcomp 
    where codprodcomp = aCodProdComp;
    
    BagaProiectNodDinReteta(vCod, aCodProdComp, vCant, &apos;.00&apos;, vCodNod, 0);
    
    delete tmp_proiectman;
    insert into tmp_proiectman (
      CODPROIECTNOD,
      CODPROIECT,   
      NODORIGINAL,  
      POZITIE,      
      CODRETETA,    
      DEN_OBIECT,   
      TIP,          
      SIMBOL,       
      DURATA,       
      CANT,         
      NIVEL,        
      ORDINE,       
      INCEPERE,
      Decalaj,
      DURATANOD,    
      COPILMAXIM,   
      NODCRITIC,    
      BARA         
      )
    select PN.CODPROIECTNOD,
         PN.CODPROIECT,
         PN.NODORIGINAL,
         PN.POZITIE,
         PN.CODRETETA,
         obj.denumire den_obiect,
         0,
         pn.IndexParinte Simbol,
         Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
         pn.Cant,
         pn.nivel,
         o.Ordine,
         0,
         0,
         0,
         -1,
         &apos;...&apos; NodCritic,
         &apos;...&apos; bara
    from proiectnod pn
         inner join prodcomp pc on pn.codreteta = pc.codprodcomp
         inner join nartobj obj on obj.codobiect = pc.codobiect
         inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = vCod) - Nivel as Ordine
                     from proiectnod WHERE CodProiect = vCod Group by Nivel) O on O.Nivel = pn.Nivel
    WHERE PN.CodProiect = vCod and pc.codprodcomp &gt; 0;

    SetCopilMaxim(vCod);
    
    aDurata := 0;
    begin
      select DurataNod into aDurata from tmp_proiectman where nvl(nodoriginal,0) = 0;
    exception when others then aDurata := 0; 
    end;

    if aDurata &lt;&gt; 0 then 
      update proiect set Durata = aDurata
      where CodProiect = vCod;
    end if;
    
    for v_rec in (
      select prj.nr nr_mat_proiect, mat.nr nr_mat_reteta, mat.codprodcomp
      from (select count(*) nr, pn0.codproiect, pn0.codreteta
            from proiect pn 
                 inner join proiectnod pn0 on pn0.codproiect = pn.codproiect
                 inner join proiectnod pn1 on pn1.nodoriginal = pn0.codproiectnod and pn1.codproiect = pn.codproiect
            where pn.codproiect = vCod     
            group by pn0.codproiect, pn0.codreteta
            ) prj
            inner join 
            (select count(*) nr, codprodcomp
             from prodmat
             where codprodcomp = aCodProdComp
             group by codprodcomp
            ) mat on prj.codreteta = mat.codprodcomp
      where prj.nr &lt;&gt; mat.nr
      ) loop
      vCod := 0;
    end loop;  
  exception when others then vCod := 0;
  end;
  
  if vCod &gt; 0 then Commit; end if;
    
  return vCod;
end;

FUNCTION UpdateImplicit(aCodProiect IN NUMBER, aImplicit IN NUMBER) return Boolean is pragma autonomous_transaction;
Done BOOLEAN;
begin
  begin
    update proiect set implicit = aImplicit where codproiect = aCodProiect;
    commit;
    Done := True;
  exception when others then
    Done := False;
  end;

  Return Done;
end;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

function GetCodProiect return number is
begin
  return vCodProiect;
end;

procedure SetCodProiect(aCodProiect in number) is
begin
  vCodProiect := aCodProiect;
end;

function GetMasa(aCodProiect in number) return number is 
aMasa number(20,7);
begin
  select sum(FI.Masa * PN.Cant) into aMasa
  from PROIECT P
       INNER JOIN PROIECTNOD PN ON P.CODPROIECT = PN.CODPROIECT
       INNER JOIN FISASUP FS ON PN.CODPROIECTNOD = FS.CODPROIECTNOD
       INNER JOIN FISAINF FI ON FS.CODFISASUP = FI.Codfisapro
  where FI.CodFisaSup &gt; 0 and P.CODPROIECT = aCodProiect;
  
  return aMasa;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20) := 0;
BEGIN
  SELECT CodProiect INTO Tmp FROM PROIECT WHERE CodProiect = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
aCodUtilizare number(20);
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomProiect   --&gt; 507;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 507);
  SELECT
    DATAPROIECT,
    VERSIUNE,
    CODUTILIZARE
  INTO
    aDATADOC,
    ADOC,
    ACODUTILIZARE
  FROM PROIECT WHERE CODPROIECT = RECID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE PROIECTNOD WHERE CODPROIECT = RecId;
  update proiect set codidentificare = null where codidentificare = recid;
  IF ACODUTILIZARE &gt; 0 THEN
    DELETE PROIECTNOD WHERE CODPROIECT = ACODUTILIZARE;
    DELETE PROIECT WHERE CODPROIECT = ACODUTILIZARE;
  END IF;
  DELETE PROIECT WHERE CodProiect = RecId;
  
  NotifyModif(2, RecId, &apos;PROIECT&apos;);
  
  COMMIT;
END;

PROCEDURE SP_DELETERECORD_FARALOCKCOMMIT( RecId IN NUMBER ) IS
aDataDoc DATE;
aDoc     VARCHAR2(200);
BEGIN
  SELECT
    DATAPROIECT,
    VERSIUNE
  INTO
    aDATADOC,
    ADOC
  FROM PROIECT WHERE CODPROIECT = RECID;
  
  -- nomProiect   --&gt; 507;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 507);
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  DELETE PROIECTNOD WHERE CODPROIECT = RecId;
  DELETE PROIECT WHERE CodProiect = RecId;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PROIECT(Codproiect) values (0); 
  -- nomProiect   --&gt; 507; 
  PKG_CFGTABLES.EXT_INSERTRECORD(507); 
  COMMIT;
END;

procedure SetDrumCritic(aCodNod in number) is
X number;
begin
  update tmp_proiectman set NodCritic = Simbol where CodProiectNod = aCodNod;
  begin
    select nvl(CopilMaxim, 0) into X from tmp_proiectman where CodProiectNod = aCodNod;
    exception when others then X := 0;
  end;

  for v_rec in (select CodProiectNod from tmp_proiectman where Nvl(DurataNod,0) = X and NODORIGINAL = aCodNod ) loop
    SetDrumCritic(v_rec.CodProiectNod);
  end loop;
end;

procedure SetDecalaj(aCodNod in number, Total in number) is
DurataParinte number;
DecalajParinte number;
begin
  update tmp_proiectman set Incepere = Total - Decalaj - Durata where CodProiectNod = aCodNod;
  begin
    select nvl(Durata, 0), nvl(Decalaj, 0)  into DurataParinte, DecalajParinte  from tmp_proiectman where CodProiectNod = aCodNod;
    exception when others then DurataParinte := 0;DecalajParinte := 0;
  end;
  update tmp_proiectman set --Decalaj = Decalaj + DecalajParinte + DurataParinte, 
														Incepere = Total - (Decalaj + DecalajParinte + DurataParinte) where NodOriginal = aCodNod;
  for v_rec in (select CodProiectNod from tmp_proiectman where NODORIGINAL = aCodNod ) loop
    SetDecalaj(v_rec.CodProiectNod, Total);
  end loop;
end;

PROCEDURE SETDURATANOD(aCodProiectNod in number) is
aDurPrec number(20,7);
aPrecI number(20,7);
aPrecF number(20,7);
aCod number(20);
aCount number(10);
aDif number(20,7);
aIndexParinte varchar2(50);
aDur number(20,7);
begin
  select indexparinte into aindexparinte from tmp_proiectman where codproiectnod = acodproiectnod;
  select count(*) into aCount from tmp_proiectman where nodoriginal = aCodproiectnod;
  if aCount = 0 then
    update tmp_proiectman set incepere = 0 where codproiectnod = acodproiectnod;
    return;
  end if;
  for v_rec in (select codproiectnod, durata, incepere from tmp_proiectman where nodoriginal = aCodProiectNod order by pozitie) loop
    aDurPrec := v_rec.durata;
    aPrecI := v_Rec.incepere;
    aPrecF := v_Rec.incepere + v_rec.durata;
    aCod := v_rec.codproiectnod;
    Exit;
  end loop; 
  for v_rec in (select codproiectnod, durata, coalesce(decalaj,4) decalaj, pozitie, indexparinte from tmp_proiectman where nodoriginal = aCodProiectNod and codproiectnod &lt;&gt; aCod order by pozitie) loop
    if v_rec.decalaj in (0,1,4) then
      select aPrecF - incepere into aDif from tmp_proiectman where codproiectnod = v_rec.codproiectnod;
      update tmp_proiectman set incepere = incepere + aDif where codproiectnod &lt;&gt; v_rec.codproiectnod and instr(indexparinte, v_rec.indexparinte, 1) = 1;
      update tmp_proiectman set incepere = aPrecF where codproiectnod = v_rec.codproiectnod;
      aPrecI := aPrecI + aDurPrec;
      aPrecF := aPrecF + v_rec.Durata;
    else if v_Rec.decalaj = 2 then
      select aPrecI - incepere into aDif from tmp_proiectman where codproiectnod = v_rec.codproiectnod;
      update tmp_proiectman set incepere = incepere + aDif where codproiectnod &lt;&gt; v_rec.codproiectnod and instr(indexparinte, v_rec.indexparinte, 1) = 1;
      update tmp_proiectman set incepere = aPrecI where codproiectnod = v_rec.codproiectnod;
      aPrecF := aPrecI + v_Rec.Durata;
    /*else if v_rec.decalaj = 3 then
      select max(incepere+durata) into aDur from tmp_proiectman where nodoriginal = acodproiectnod and pozitie &lt; v_rec.pozitie;
      if aDur &lt; v_rec.Durata then
        for v_tmp in (select codproiectnod, indexparinte, incepere from tmp_proiectman where nodoriginal = aCodProiectNod and pozitie &lt; v_Rec.pozitie) loop
          update tmp_proiectman set incepere = incepere + v_rec.durata - aDur where instrb(indexparinte, v_tmp.indexparinte, 1) = 1;
        end loop;
        --update tmp_proiectman set incepere = 0 where codproiectnod = v_Rec.codproiectnod;
        aPrecI := 0;
        aPrecF := v_rec.Durata;
      else
        aPrecI := aDur - v_Rec.Durata;
        select aPrecI - incepere into aDif from tmp_proiectman where codproiectnod = v_rec.codproiectnod;
        update tmp_proiectman set incepere = aPrecI where codproiectnod = v_rec.codproiectnod;
        update tmp_proiectman set incepere = incepere + aDif where codproiectnod &lt;&gt; v_rec.codproiectnod and instr(indexparinte, v_rec.indexparinte, 1) = 1;
      end if;
    end if;*/end if;end if;
    aDurPrec := v_Rec.durata;
  end loop;
  update tmp_proiectman set incepere = (select max(t.incepere+t.durata) from tmp_proiectman t where t.nodoriginal = acodproiectnod) where codproiectnod = acodproiectnod;
end;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
X number;
Total number;
Facut number(1);
NewOrdine number(5) := -1;
aMarja number;
aNivel number;
BEGIN
  INSERT INTO  TMP_PROIECT ( CodProiect, 
                             CodVersiune, 
                             CodObiectProd, 
                             Versiune, 
                             Intocmita, 
                             DataProiect, 
                             Clasa, 
                             Procesare,
                             Complex,                     
                             activ,                         
                             Finalizat,                         
                             Blocat,
                             Den_Procesare,
                             Den_Pers,
                             Masa, 
                             Den_Obiect,
                             Invizibila,
                             Durata,
                             MarjaOrdine,
                             implicit,
                             Generic,
                             Obs1,
                             Obs2,
                             Obs3,
                             Obs4,
                             Obs5,
                             Obs6,
                             CodUtilizare,
                             CodIdentificare,
                             CodExtern )
    ( SELECT P.CodProiect, 
             P.CodVersiune, 
             P.CodObiectProd, 
             P.Versiune, 
             P.Intocmita, 
             P.DataProiect, 
             P.Clasa, 
             P.Procesare,
             P.Complex,                     
             P.activ,                         
             P.Finalizat,                         
             P.Blocat,
             case
               when P.Procesare = 1 then &apos;Agregare&apos;
               else &apos;Dezagregare&apos;
             end Den_Procesare,
             NP.NUME||&apos; &apos;||NP.PRENUME Den_Pers,
             GetMasa(P.Codproiect),
             OBJ.Denumire,
             P.Invizibila,
             P.Durata,
             Nvl(P.MarjaOrdine, 0),
             P.implicit,
             P.Generic,
             P.Obs1,
             P.Obs2,
             P.Obs3,
             P.Obs4,
             P.Obs5,
             P.Obs6,
             P.CodUtilizare,
             P.CodIdentificare,
             P.CodExtern
      FROM 
        PROIECT P 
        LEFT JOIN NPERS NP ON P.Intocmita = NP.Codpers 
        LEFT JOIN NARTOBJ OBJ ON P.CODOBIECTPROD = OBJ.CODOBIECT
      WHERE P.CodProiect = RecId ) ;

  INSERT INTO  TMP_PROIECTNOD ( CODPROIECTNOD,
                                CODPROIECT,    
                                CANT,
                                NECESAR,         
                                NODORIGINAL,
                                POZITIE, 
                                CODRETETA, 
                                TIP,
                                CODOBIECT,
                                DenUM, 
                                INDEXPARINTE,
                                CodProdMat, 
                                DENUMIRE,
                                OBS,
                                IDENTIFICATOR   ,
                                DATADOCUMENTATIE,
                                ARHIVA          ,
                                PROIECTANT,
                                ordine,
                                nivel,
                                DECALAJ      
                                 )
                       ( SELECT PN.CODPROIECTNOD,
                                PN.CODPROIECT,    
                                PN.CANT,
                                PN.CANT,         
                                PN.NODORIGINAL,
                                PN.POZITIE, 
                                PN.CODRETETA, 
                                PN.TIP,
                                PN.CodObiect,
                                U.DEN_UM,
                                PN.INDEXPARINTE,
                                PN.CodProdMat,
                                OBJ.DENUMIRE,
                                PC.OBS,
                                PC.IDENTIFICATOR   ,
                                PC.DATA,
                                PC.ARHIVA          ,
                                PC.PROIECTANT,
                                nvl(pn.ordine,0),
                                PN.NIVEL,
                                coalesce(PN.DECALAJ,2) DECALAJ
                         FROM PROIECTNOD PN 
                              INNER JOIN NARTOBJ OBJ ON PN.CODOBIECT = OBJ.CODOBIECT
                              INNER JOIN NART    A   ON A.CODARTICOL = OBJ.CODARTICOL
                              INNER JOIN NUM     U   ON U.CodUM      = A.UM
                              LEFT  JOIN PRODCOMP PC ON PN.CodReteta = PC.CodProdComp
                         WHERE PN.CODPROIECT = RecId );
  
  insert into tmp_proiectman (
  CODPROIECTNOD,
  CODPROIECT,   
  NODORIGINAL,  
  POZITIE,      
  CODRETETA,    
  DEN_OBIECT,   
  TIP,          
  SIMBOL,       
  DURATA,       
  CANT,         
  NIVEL,        
  ORDINE,       
  INCEPERE,
  Decalaj,
  DURATANOD,    
  COPILMAXIM,   
  NODCRITIC,    
  BARA,
  LOTOPTIM,
  INDEXPARINTE         
  )
  select 
       PN.CODPROIECTNOD,
       PN.CODPROIECT,
       PN.NODORIGINAL,
       PN.POZITIE,
       PN.CODRETETA,
       obj.denumire den_obiect,
       0,
       pn.IndexParinte Simbol,
       Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
       pn.Cant,
       pn.nivel,
       nvl(o.Ordine*10000 + Pozitie,0),
       Nvl(Incepere, 0),
       PN.DECALAJ,
       0,
       -1,
       &apos;...&apos; NodCritic,
       &apos;...&apos; bara,
       pc.cant,
       PN.INDEXPARINTE
  from proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
       inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = RecId) - Nivel as Ordine
                   from proiectnod WHERE CodProiect = RecId Group by Nivel) O on O.Nivel = pn.Nivel
  WHERE PN.CodProiect = RecId and pc.codprodcomp &gt; 0;

/*
  for v_rec in (select Nivel, Min(Pozitie) Pozitie from TMP_ProiectNod group by Nivel) loop
  	update TMP_ProiectNod set Decalaj = 1 where Nivel = v_rec.Nivel and Pozitie = v_rec.Pozitie;
    update TMP_ProiectNod set Decalaj = 2 where Nivel = v_rec.Nivel and Pozitie &lt;&gt; v_rec.Pozitie and Nvl(Decalaj, 0) &lt;= 1;
   end loop;
*/

/*
  begin
    select CodProiectNod, Nvl(Durata, 0) into X, Total from tmp_proiectman where Nvl(NodOriginal,0) = 0;
    exception when others then X := 0;Total := 0;
  end;
  if Total &gt; 0 then 
    X := PKG_PROIECT.GetDurataCopii(X, Total); 
  end if;
  begin
    select CodProiectNod, Nvl(DurataNod, 0) into X, Total from tmp_proiectman where Nvl(NodOriginal,0) = 0;
    exception when others then X := 0;Total := 0;
  end;


  for v_rec in (select t.codproiectnod from tmp_proiectman t order by t.nivel desc, t.pozitie) loop
    SETDURATANOD(v_rec.CODPROIECTNOD);
  end loop;
*/

  update tmp_proiect set durata = (select coalesce(incepere,0) + coalesce(durata,0) from tmp_proiectman where nodoriginal = 0);
  
 -- nomProiect   --&gt; 507; 
 PKG_CFGTABLES.EXT_GOTORECORD(507);
 
  IF  DoCommit THEN
    COMMIT;
  END IF;
END;

procedure GenRetetaNoua(aCodProiectNod in number, aCodProdComp in number, aCodObiect in number, aObs in varchar2) is
vCodProdComp number(20);
vCodProdGest number(20);
vCodMat number(20);
begin
  select seq_prodcomp_codprodcomp.nextval into vCodProdComp from dual;
  for v_rec in (select pc.*
                from prodcomp pc
                where pc.codprodcomp = aCodProdComp) loop
    insert into prodcomp (codprodcomp, codobiect, obs, data, anulat, blocat, operat, 
                          cant, pret, coefindirecte, implicit, descriere, inactiv, gest, 
                          identificator, datadocumentatie, arhiva, observatii, proiectant, 
                          codclasaprod, invizibila, generic, durata, userid, datacreare, 
                          hfactor, valmat, valman, valregie, tippret, 
                          obs1, obs2, obs3, obs4, obs5, obs6, codmoneda, pretvaluta, ag, 
                          valag, profit, valprofit, pretfinal, valprofitv, pretfinalv, 
                          totpretcoef, totpretfix, totpretcoefv, totpretfixv, valregieman)            
    values (vCodProdComp, acodobiect, aobs, v_rec.data, v_rec.anulat, v_rec.blocat, v_rec.operat, 
            v_rec.cant, v_rec.pret, v_rec.coefindirecte, v_rec.implicit, v_rec.descriere, v_rec.inactiv, v_rec.gest, 
            v_rec.identificator, v_rec.datadocumentatie, v_rec.arhiva, v_rec.observatii, v_rec.proiectant, 
            v_rec.codclasaprod, v_rec.invizibila, v_rec.generic, v_rec.durata, v_rec.userid, v_rec.datacreare, 
            v_rec.hfactor, v_rec.valmat, v_rec.valman, v_rec.valregie, v_rec.tippret,
            v_rec.obs1, v_rec.obs2, v_rec.obs3, v_rec.obs4, v_rec.obs5, v_rec.obs6, v_rec.codmoneda, v_rec.pretvaluta, v_rec.ag, 
            v_rec.valag, v_rec.profit, v_rec.valprofit, v_rec.pretfinal, v_rec.valprofitv, v_rec.pretfinalv, 
            v_rec.totpretcoef, v_rec.totpretfix, v_rec.totpretcoefv, v_rec.totpretfixv, v_rec.valregieman);
    Exit;        
  end loop;
  
  select seq_prodgest_codprodgest.nextval into vCodProdGest from dual;
  for v_rec in (select pg.*
                from prodgest PG
                where pg.codprodcomp = aCodProdComp) loop
    insert into prodgest(codprodgest, codprodcomp, indexlocal, codgest, coefmat, coefman)
    values(vCodProdGest, vCodProdComp, v_rec.indexlocal, v_rec.codgest, v_rec.coefmat, v_rec.coefman);            
    Exit;
  end loop;              
  
  for v_rec in (select mat.*
                from prodmat mat
                where mat.codprodcomp = aCodProdComp
                ) loop
    select seq_prodmat_codmat.nextval into vCodMat from dual;            
    insert into prodmat (codmat, codprodcomp, codobiect, cant, pret, d1, d2, d3, 
                         indexlocal, cantum1, codprodgest, tip, codatribut, valmat, 
                         valman, valregie, adddim, adddim_transp, pretorig, procreal, 
                         valoare, copyd1, copyd2, copyd3)            
    values(vCodMat, vCodProdComp, v_rec.codobiect, v_rec.cant, v_rec.pret, v_rec.d1, v_rec.d2, v_rec.d3,
           v_rec.indexlocal, v_rec.cantum1, vCodProdGest, v_rec.tip, v_rec.codatribut, v_rec.valmat, 
           v_rec.valman, v_rec.valregie, v_rec.adddim, v_rec.adddim_transp, v_rec.pretorig, v_rec.procreal, 
           v_rec.valoare, v_rec.copyd1, v_rec.copyd2, v_rec.copyd3);
    update proiectnod set codprodmat = vCodMat where codprodmat = v_rec.codmat and nodoriginal = aCodProiectNod;       
  end loop;
  
  update proiectnod set codreteta = vCodProdComp where codproiectnod = aCodProiectNod;
  
  commit;                            
end;

function CheckModificari(aCodProiect in number) return number is
aCount number(10);
begin
  -- daca s-a schimbat produsul
  select count(*) into aCount
  from proiect p
       inner join tmp_proiect tmp on tmp.codproiect = p.codproiect
  where p.codproiect = aCodProiect and p.codobiectprod &lt;&gt; tmp.codobiectprod;
  if aCount &gt; 0 then return aCount; end if;
  -- daca sunt inregistrari noi in proiectnod
  select count(*) into aCount
  from tmp_proiectnod 
  where codproiect = aCodProiect and codproiectnod &lt;= 0;
  if aCount &gt; 0 then return aCount; end if;
  -- daca s-au schimbat retete, cantitati
  select count(*) into aCount
  from proiectnod pn
       left join tmp_proiectnod tmp on pn.codproiectnod = tmp.codproiectnod
  where pn.codproiect = aCodProiect and 
        (pn.cant &lt;&gt; tmp.cant or nvl(pn.codreteta,0) &lt;&gt; nvl(tmp.codreteta,0) or tmp.codproiectnod is null);
  return aCount;      
end;  

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCODNOD      NUMBER(20) := 0;
vOLDCOD      NUMBER(20) := 0;
NR           NUMBER(20);
aDurata      NUMBER(20, 7);
aDataDoc     DATE;
aDoc         VARCHAR2(200);
flgTestGeneric number(1);
flgModif     number(10);
ACODUTILIZARE NUMBER(20);
BEGIN
  SELECT
    DATAPROIECT,
    VERSIUNE,
    CODUTILIZARE
  INTO
    aDATADOC,
    ADOC,
    ACODUTILIZARE
  FROM TMP_PROIECT;
  
  flgTestGeneric := 0;
  -- nomProiect   --&gt; 507;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (507); 
  if operation = 0 then
    select CodProiect into RecId from tmp_proiect;
    flgModif := CheckModificari(RecID);
  end if;  
  
  FOR V_REC IN (SELECT * FROM tmp_proiectnod where CodProiectNod &lt; 0) LOOP
    SELECT seq_proiectnod_codproiectnod.nextval INTO vCODNOD FROM DUAL;
    vOldCod := V_REC.codproiectnod;
    UPDATE tmp_proiectnod SET nodoriginal = vCODNOD WHERE nodoriginal = vOldCod;
    UPDATE tmp_proiectnod SET codproiectnod = vCODNOD WHERE codproiectnod = vOldCod;
    UPDATE tmp_proiectman SET codproiectnod = vCODNOD WHERE codproiectnod = vOldCod;
  END LOOP;

  IF Operation = 0 THEN  -- UPDATE
    -- sunt pe modific
    -- vad daca s-a modificat ceva structural
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                        PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    update proiect set (codversiune, codobiectprod, versiune, intocmita, dataproiect, clasa
                          ,procesare, complex, activ, finalizat, blocat, Invizibila, implicit,Durata, MarjaOrdine, Generic,
                          Obs1,Obs2,Obs3,Obs4,Obs5,Obs6,codextern)
                     = (select p.codversiune, p.codobiectprod, p.versiune, p.intocmita, p.dataproiect, p.clasa
                          ,p.procesare, p.complex, p.activ, p.finalizat, p.blocat, p.Invizibila, p.implicit,
                          0, Nvl(p.MarjaOrdine, 0), p.Generic, p.Obs1,p.Obs2,p.Obs3,p.Obs4,p.Obs5,p.Obs6,p.codextern
                        from tmp_proiect p)
                        where codproiect = Recid;
    
    
    if flgModif &gt; 0 then 
      update proiect set codutilizare = null where codproiect = RecID;
      update proiect set codidentificare = null where codidentificare = RecID;
    else 
      update proiect set (versiune,intocmita,dataproiect,obs1,codextern,marjaordine)
                     = (select p.versiune, p.intocmita, p.dataproiect, p.Obs1, p.codextern, p.marjaordine
                        from tmp_proiect p)
                        where codidentificare = (select codutilizare from tmp_proiect);
    end if;
    
    delete proiectnod where codproiect = recid and codproiectnod not in (select codproiectnod from tmp_proiectnod);
    for v_rec in (select * from tmp_proiectnod) loop
      SELECT NVL(COUNT(*), 0) INTO NR  FROM proiectnod WHERE codproiectnod = V_REC.codproiectnod;
      IF NR = 0
      THEN 
        insert into proiectnod (codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, tip, codobiect, INDEXPARINTE, 
                                CodProdMat, ordine,NIVEL, DECALAJ)
        values (v_rec.codproiectnod, RecId, v_Rec.cant, v_Rec.nodoriginal,v_Rec.pozitie,v_Rec.codreteta,v_Rec.tip,v_rec.codobiect,v_rec.INDEXPARINTE, 
                v_Rec.CodProdMat,v_rec.ordine,v_rec.NIVEL,v_Rec.decalaj);
      ELSE
        update proiectnod set 
          cant        = v_Rec.Cant, 
          nodoriginal = v_Rec.nodoriginal, 
          pozitie     = v_Rec.pozitie, 
          codreteta   = v_Rec.Codreteta, 
          tip         = v_Rec.Tip,
          INDEXPARINTE= v_rec.INDEXPARINTE,
          codobiect   = v_rec.codobiect,
          CodProdMat  = v_rec.Codprodmat,
          ordine      = v_rec.ordine,
          nivel       = v_Rec.Nivel,
          decalaj     = v_rec.decalaj
        where codproiectnod = v_Rec.codproiectnod;
      END IF;
      if v_rec.codreteta &lt; 0 then
        flgTestGeneric := 1;
        GenRetetaNoua(v_rec.codproiectnod, - v_rec.codreteta, v_rec.codobiect, v_rec.obs); 
      end if;
    end loop;
  ELSE  -- INSERT
  
  SELECT seq_PROIECT_codproiect.NextVal INTO RecId FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;proiect&apos;, RecId);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROIECT&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      PKG_GLOBALS.GETSUBUNITATE, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  INSERT INTO proiect ( CodProiect,
                        CodVersiune, 
                        CodObiectProd, 
                        Versiune, 
                        Intocmita, 
                        DataProiect, 
                        Clasa, 
                        Procesare,
                        Complex,                     
                        activ,                         
                        Finalizat,                         
                        Blocat,
                        Invizibila,
                        implicit,Durata, MarjaOrdine, generic, Datacreare, USERID,
                        Obs1,
                        Obs2,
                        Obs3,
                        Obs4,
                        Obs5,
                        Obs6,
                        CodExtern )
               ( SELECT RecId,
                        P.CodVersiune, 
                        P.CodObiectProd, 
                        P.Versiune, 
                        P.Intocmita, 
                        P.DataProiect, 
                        P.Clasa, 
                        P.Procesare,
                        P.Complex,                     
                        P.activ,                         
                        P.Finalizat,                         
                        P.Blocat,
                        P.Invizibila,
                        P.implicit,0, Nvl(P.MarjaOrdine, 0), P.generic, SYSTIMESTAMP, PKG_GLOBALS.USERID,
                        P.Obs1,
                        P.Obs2,
                        P.Obs3,
                        P.Obs4,
                        P.Obs5,
                        P.Obs6,
                        P.CodExtern
                FROM TMP_PROIECT p);
  
  for v_rec in (select * from tmp_proiectnod) loop
    INSERT INTO PROIECTNOD ( CODPROIECTNOD,
                             CODPROIECT,    
                             CANT,         
                             NODORIGINAL, 
                             POZITIE, 
                             CODRETETA, 
                             TIP,
                             CODOBIECT, INDEXPARINTE,
                             Codprodmat,
                             ordine,
                             nivel,
                             decalaj)
                     values( v_rec.codproiectnod,
                             RecId,    
                             v_rec.CANT,         
                             v_rec.NODORIGINAL,
                             v_rec.POZITIE, 
                             v_rec.CODRETETA, 
                             v_rec.TIP,
                             v_rec.codobiect, v_rec.INDEXPARINTE,
                             v_rec.CodProdMat,
                             v_rec.ordine,
                             v_rec.nivel,
                             v_rec.decalaj );   
     if v_rec.codreteta &lt; 0 then
       GenRetetaNoua(v_rec.codproiectnod, - v_rec.codreteta, v_rec.codobiect, v_rec.obs); 
     end if;
   end loop;                   
   
   flgTestGeneric := 1;
  END IF;

  for v_Rec in (SELECT PN.CODPROIECTNOD, PM.INCEPERE, level - 1 nivel, pm.decalaj
                FROM PROIECTNOD PN left join TMP_PROIECTMAN PM on PM.Codproiectnod = PN.CODPROIECTNOD
                WHERE PN.CODPROIECT = RecId
                START WITH PN.NODORIGINAL = 0 
                CONNECT BY PRIOR PN.CODPROIECTNOD = PN.NODORIGINAL) loop
    
    update proiectnod set nivel = v_rec.nivel, Incepere = v_rec.Incepere, decalaj = v_Rec.decalaj where codproiectnod = v_Rec.codproiectnod;
  end loop;
 
 /*delete tmp_proiectman;
 insert into tmp_proiectman (
    CODPROIECTNOD,
    CODPROIECT,   
    NODORIGINAL,  
    POZITIE,      
    CODRETETA,    
    DEN_OBIECT,   
    TIP,          
    SIMBOL,       
    DURATA,       
    CANT,         
    NIVEL,        
    ORDINE,       
    INCEPERE,
    Decalaj,
    DURATANOD,    
    COPILMAXIM,   
    NODCRITIC,    
    BARA         
    )
    select PN.CODPROIECTNOD,
         PN.CODPROIECT,
         PN.NODORIGINAL,
         PN.POZITIE,
         PN.CODRETETA,
         obj.denumire den_obiect,
         0,
         pn.IndexParinte Simbol,
         Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
         pn.Cant,
         pn.nivel,
         o.Ordine,
         INCEPERE,
         0,
         0,
         -1,
         &apos;...&apos; NodCritic,
         &apos;...&apos; bara
    from proiectnod pn
         inner join prodcomp pc on pn.codreteta = pc.codprodcomp
         inner join nartobj obj on obj.codobiect = pc.codobiect
         inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = RecId) - Nivel as Ordine
                     from proiectnod WHERE CodProiect = RecId Group by Nivel) O on O.Nivel = pn.Nivel
    WHERE PN.CodProiect = RecId;

  SetCopilMaxim(RecId);*/
     
  aDurata := 0;
  begin
    select DurataNod+Incepere into aDurata from tmp_proiectman where nvl(nodoriginal,0) = 0;
  exception when others then aDurata := 0; 
  end;

  if aDurata &lt;&gt; 0 then 
    update proiect set Durata = aDurata
    where CodProiect = RecId;
  end if;

  if flgTestGeneric = 1 then
    TestAndUpdateGeneric(RecID);
  end if;

  --CheckAndUpdateRetete(RecId);
  PROPAGAGANT(RECID);
  
  -- nomProiect   --&gt; 507;
  PKG_CFGTABLES.EXT_POSTRECORDS(507); 
  
  IF  DoCommit THEN
    NotifyModif(Operation, RecId, &apos;PROIECT&apos;);
    COMMIT;
  END IF;
end;  

procedure CheckAndUpdateRetete(aCodProiect in number) is
aCount number(10);
aModif number(10);
aCodProdComp number(20);
begin
  for v_rec in (select pn.codproiectnod, pn.cant, pc.cant cantreteta, pn.codreteta 
                from proiectnod pn
                     inner join prodcomp pc on pn.codreteta = pc.codprodcomp
                where pn.codreteta &gt; 0 and pn.codproiect = aCodProiect) loop
    aCount := 0;
    aModif := 0;
    for v_mat in (select pn.cant, mat.cant cantmat
                  from proiectnod pn
                       inner join prodmat mat on pn.codprodmat = mat.codmat
                  where pn.codproiect = aCodProiect and pn.nodoriginal = v_rec.codproiectnod) loop
      if v_mat.cant &lt;&gt; round(v_rec.cant*v_mat.cantmat/v_rec.cantreteta,7) then 
        aModif := aModif + 1;
        select count(*) into aCount from proiectnod where codreteta = v_rec.codreteta and codproiect &lt;&gt; aCodProiect;
      end if;
      if aCount &gt; 0 then Exit; end if;
    end loop;
    if aCount &gt; 0 then
      --trebuie sa fac clona la reteta
      aCodProdComp := pkg_prodcomp.CloneazaReteta(v_rec.codreteta);
      update prodcomp set generic = 0, implicit = 0 where codprodcomp = aCodProdComp;
      update proiectnod set codreteta = aCodProdComp where codproiectnod = v_rec.codproiectnod;
      for v_pn in (select pn.codproiectnod, matc.codmat 
                   from proiectnod pn
                        inner join prodmat mat on pn.codprodmat = mat.codmat and mat.codprodcomp = v_rec.codreteta
                        inner join prodmat matc on matc.codobiect = mat.codobiect and matc.indexlocal = mat.indexlocal and matc.cant = mat.cant
                   where pn.nodoriginal = v_rec.codproiectnod and pn.codproiect = aCodProiect and matc.codprodcomp = aCodProdComp
                  ) loop
        update proiectnod set codprodmat = v_pn.codmat where codproiectnod = v_pn.codproiectnod;
      end loop;             
    end if;
    --fac update la cantitati
    for v_mat in (select pn.cant, mat.cant cantmat, mat.codmat
                from proiectnod pn
                     inner join prodmat mat on pn.codprodmat = mat.codmat
                where pn.codproiect = aCodProiect and pn.nodoriginal = v_rec.codproiectnod) loop
      if v_mat.cant &lt;&gt; round(v_rec.cant*v_mat.cantmat/v_rec.cantreteta,7) then 
        update prodmat set cant = round(v_mat.cant*v_rec.cantreteta/v_rec.cant,7) where codmat = v_mat.codmat;
      end if;
    end loop;
  end loop;
end;

procedure TestAndUpdateGeneric(aCodProiect in number) is
aCount integer;  
aCodObiect number(20);
begin
  begin
    select codobiectprod into aCodObiect from proiect where codproiect = aCodProiect;
  exception when others then aCodObiect := 0;
  end;
  
  insert into x(test) values(&apos;codobiect:&apos;||acodobiect);
  
  if aCodObiect = 0 then Return; end if;
  
  select count(1) into aCount 
  from proiect
  where codobiectprod = aCodObiect and generic = 1;
  
  insert into x(test) values(&apos;proiecte generice:&apos;||acount);
  
  if aCount &gt; 0 then Return; end if;
  
  select count(*) into aCount
  from proiectnod pn
       inner join prodcomp pc on pc.codprodcomp = pn.codreteta
  where pn.codproiect = aCodProiect and nvl(pc.generic,0) = 0 and pn.codreteta &gt; 0;     
  
  insert into x(test) values(&apos;retete negenerice:&apos;||acount);
  
  if aCount = 0 then
    update proiect set generic = 1 where codproiect = aCodProiect;
  end if;
end;  

function GetCopilMaxim(aNod in number) return number is
x number;
y number;
begin
   select CopilMaxim into x from Tmp_Proiectman where CodProiectNod = aNod;
   if x = -1 then 
     x := 0;
     for v_rec in (select * from  Tmp_Proiectman WHERE NodOriginal = aNod) loop
       y := GetCopilMaxim(v_rec.CodProiectNod) + v_rec.Durata;
       if y &gt; x then x := y; end if;
     end loop;
     update tmp_proiectman set copilmaxim = x, DurataNod = Durata + x where CodProiectNod = aNod;
   end if;
   Return x;
end;


procedure SetCopilMaxim(RecId in number) is
x number;
begin
/*
  Delete tmp_proiectman;
  
  insert into tmp_proiectman (
  CODPROIECTNOD,
  CODPROIECT,   
  NODORIGINAL,  
  POZITIE,      
  CODRETETA,    
  DEN_OBIECT,   
  TIP,          
  SIMBOL,       
  DURATA,       
  CANT,         
  NIVEL,        
  ORDINE,       
  INCEPERE,
  Decalaj,
  DURATANOD,    
  COPILMAXIM,   
  NODCRITIC,    
  BARA         
  )
  select PN.CODPROIECTNOD,
       PN.CODPROIECT,
       PN.NODORIGINAL,
       PN.POZITIE,
       PN.CODRETETA,
       obj.denumire den_obiect,
       0,
       pn.IndexParinte Simbol,
       Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
       pn.Cant,
       pn.nivel,
       o.Ordine,
       0,
       0,
       0,
       0,
       &apos;...&apos; NodCritic,
       &apos;...&apos; bara
  from proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
       inner join (select distinct Nivel, (Select Max(Nivel) from proiectnod WHERE CodProiect = RecId) - Nivel as Ordine
                   from proiectnod WHERE CodProiect = RecId Group by Nivel) O on O.Nivel = pn.Nivel
  WHERE PN.CodProiect = RecId;

 update tmp_proiectman set copilmaxim = -1;
*/
 for v_rec in (select * from tmp_proiectman order by simbol desc) loop
   x := GetCopilMaxim(v_rec.CodProiectNod);
   update tmp_proiectman set copilmaxim = x, DurataNod = Durata + x where CodProiectNod = v_rec.CodProiectNod;
 end loop;
end;

procedure BagaProiectNodDinRetetaX(aCodProiect in number, aCodProdComp in number, aCant in number, aIndexParinte in varchar2, aNodOriginal in number, aNivel in number) is
Poz number(10);
Nivel number(10);
vIndexParinte varchar2(300);
vIndex varchar2(300);
RetetaGenerica number(20);
vCodNod number(20);
begin
  Nivel := aNivel + 1;
  Poz := 0;
  vIndexParinte := &apos;&apos;;
  if Length(aIndexParinte) &gt; 0 then
    vIndexparinte := aIndexParinte||&apos;.&apos;; 
  end if;
  for v_rec in (select mat.*, pc.cant cantreteta
                from prodmat mat
                     inner join prodcomp pc on pc.codprodcomp = mat.codprodcomp 
                where pc.codprodcomp = aCodProdComp) loop
    Poz := Poz + 1;
    if Poz &lt; 10 then 
      vIndex := vIndexParinte||&apos;0&apos;||to_char(Poz);
    else
      vIndex := vIndexParinte||to_char(Poz);
    end if;  
    
    begin
      select to_number(Valoare1) into RetetaGenerica from tmp_manevra_liste where filtru = &apos;CODOBIECT&apos; AND FILTRU1 = &apos;CODPRODCOMP&apos; AND VALOARE = V_REC.CODOBIECT;
    exception when others then RetetaGenerica := 0;
    end;
      
    select seq_proiectnod_codproiectnod.nextval into vCodNod from dual;     
    insert into tmp_proiectnod(codproiectnod, codproiect, cant, nodoriginal, pozitie, codreteta, tip, codobiect, indexparinte, 
                           codprodmat, nivel)
    values (vCodNod, aCodProiect, v_rec.cant/v_rec.cantreteta*aCant, aNodOriginal, Poz, RetetaGenerica, v_Rec.tip, v_rec.codobiect, vIndexParinte,
            v_rec.codmat, Nivel);
            
    if v_rec.tip &lt; 3 then
      if RetetaGenerica &gt; 0 then 
        BagaProiectNodDinReteta(aCodProiect, RetetaGenerica, v_rec.cant/v_rec.cantreteta*aCant, vIndexParinte, vCodNod, Nivel); 
      end if;  
    end if;  
  end loop;
end;

procedure CloneazaPrjAscunse is
aNewCodProiect number(20);
begin
  PKG_REMAKE_SEQUENCES.REMAKE_ALL_SEQUENCES;
  for v_rec in (select codproiect from proiect where nvl(ascuns,0) = 0 and nvl(codutilizare,0) = 0 and codproiect &gt; 0) loop
    aNewCodProiect := 0;
    delete tmp_proiect;
    delete tmp_proiectnod;
    delete tmp_proiectman;
    delete tmp_proiectgrid;
    SP_GOTORECORD(v_rec.CodProiect);
    update tmp_proiectnod set codproiectnod = - codproiectnod;
    update tmp_proiectnod set nodoriginal = - nodoriginal where nodoriginal &gt; 0;
    SP_POSTRECORDS(1, aNewCodProiect);
    update proiect set ascuns = 1, generic = 0, implicit = 0, codidentificare = aNewCodProiect where codproiect = v_rec.codproiect;
    update proiect set codutilizare = v_rec.codproiect where codproiect = aNewCodProiect;
    IF PKG_LIST_STRUCT.TmpExists(&apos;PROIECTEXT&apos;) = 1 THEN
      begin
        PKG_PROIECT.CheckTmpExt;
        EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
        EXECUTE IMMEDIATE &apos;INSERT INTO TMP_PROIECTEXT SELECT * FROM PROIECTEXT WHERE CODPROIECT = &apos;||V_REC.CODPROIECT;
        EXECUTE IMMEDIATE &apos;UPDATE TMP_PROIECTEXT SET CODPROIECT = &apos;||ANEWCODPROIECT||&apos;, CODPROIECTEXT = SEQ_PROIECTEXT_CODPROIECTEXT.NEXTVAL&apos;;
        EXECUTE IMMEDIATE &apos;INSERT INTO PROIECTEXT SELECT * FROM TMP_PROIECTEXT&apos;;
      exception when others then null;
      end;  
    END IF;
  end loop;
  commit;
end;  

procedure CloneazaProiect(vCodProiect in number, vCodRetVeche in number, vCodRetNoua in number, vCodProiectNou out number) is
vCod number(20);
vCount number(20);  
begin
  select seq_proiect_codproiect.nextval into vCodProiectNou from dual;
  insert into proiect(
    CODPROIECT,
    CODVERSIUNE,
    CODOBIECTPROD,
    VERSIUNE,
    INTOCMITA,
    DATAPROIECT,
    CLASA,
    PROCESARE,
    COMPLEX,
    ACTIV,
    FINALIZAT,
    BLOCAT,
    INVIZIBILA,
    GENERIC,
    DURATA,
    MARJAORDINE,
    USERID,
    DATACREARE,
    OBS1,
    OBS2,
    OBS3,
    OBS4,
    OBS5,
    OBS6,
    CodIdentificare
  )
  select   
    vCodProiectNou,
    CODVERSIUNE,
    CODOBIECTPROD,
    VERSIUNE,
    INTOCMITA,
    trunc(sysdate),
    CLASA,
    PROCESARE,
    COMPLEX,
    ACTIV,
    FINALIZAT,
    BLOCAT,
    INVIZIBILA,
    GENERIC,
    DURATA,
    MARJAORDINE,
    pkg_globals.GETUSERID,
    sysdate,
    OBS1,
    OBS2,
    OBS3,
    OBS4,
    OBS5,
    OBS6,
    CodIdentificare
  from proiect 
  where codproiect = vCodProiect;
   
  delete tmp_proiectnod;
  insert into tmp_proiectnod(CODPROIECTNOD,
                             CODPROIECT,
                             CANT,
                             NODORIGINAL,
                             POZITIE,
                             CODRETETA,
                             TIP,
                             CODOBIECT,
                             INDEXPARINTE,
                             CODPRODMAT,
                             NIVEL,
                             ORDINE,
                             DECALAJ)
  select CODPROIECTNOD,
         vCodProiectNou,
         CANT,
         NODORIGINAL,
         POZITIE,
         CODRETETA,
         TIP,
         CODOBIECT,
         INDEXPARINTE,
         CODPRODMAT,
         NIVEL,
         ORDINE,
         DECALAJ
  from proiectnod
  where codproiect = vCodProiect;        
  
  for v_rec in (select codproiectnod
                from proiectnod 
                where codproiect = vCodProiect
                order by codproiectnod
                ) loop
    select seq_proiectnod_codproiectnod.nextval into vCod from dual;
    update tmp_proiectnod set codproiectnod = vcod where codproiectnod = v_rec.codproiectnod;
    update tmp_proiectnod set nodoriginal = vcod where nodoriginal = v_rec.codproiectnod;
  end loop;
  
  for v_rec in (select codproiectnod, codreteta, indexparinte, cant, nivel from tmp_proiectnod order by codproiectnod) loop
    if v_rec.codreteta = vCodRetVeche then
      update tmp_proiectnod set codreteta = vCodRetNoua where codproiectnod = v_rec.codproiectnod;
      delete tmp_proiectnod where indexparinte &lt;&gt; v_rec.indexparinte and instrb(indexparinte,v_rec.indexparinte) = 1;
      BagaProiectNodDinRetetaX(vCodProiectNou, vCodRetNoua, v_rec.Cant, v_rec.IndexParinte, v_rec.CodProiectNod, v_rec.Nivel);
    end if;
  end loop;
  
  insert into proiectnod (
    CODPROIECTNOD,
    CODPROIECT,
    CANT,
    NODORIGINAL,
    POZITIE,
    CODRETETA,
    TIP,
    CODOBIECT,
    INDEXPARINTE,
    CODPRODMAT,
    NIVEL,
    ORDINE,
    DECALAJ
  )
  select 
    CODPROIECTNOD,
    CODPROIECT,
    CANT,
    NODORIGINAL,
    POZITIE,
    CODRETETA,
    TIP,
    CODOBIECT,
    INDEXPARINTE,
    CODPRODMAT,
    NIVEL,
    ORDINE,
    DECALAJ   
  from tmp_proiectnod;
  
  --conditie de generic sau nu
  select count(*) into vCount
  from proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
  where pn.codproiect = vCodProiectNou and nvl(pc.generic,0) = 0 and pc.codprodcomp &gt; 0;
  
  if vCount = 0 then 
    update proiect set generic = 1 where codproiect = vCodProiectNou;
  else
    update proiect set generic = 0 where codproiect = vCodProiectNou;
  end if;   
  
end;  

procedure GENPRJ_INLOCRET(vCodRetVechi in number, vCodRetNou in number, vInactivePrj in number, vInactiveRet in number) is
vCodPrjNou number(20);  
begin
  for v_rec in (/*with nu as 
                 (
                  select count(*) nr, codproiect from (
                  select p.codproiect 
                  from proiect p 
                       inner join comanda1 c1 on c1.codproiect = p.codproiect
                       inner join proiectnod pn on p.codproiect = pn.codproiect
                       inner join cmdlink l on c1.codcomanda1 = l.codliniecomanda
                  union all
                  select l1.codproiect
                  from livr1 l1
                       inner join livr l on l1.codlivr = l.codlivr
                       inner join proiectnod pn on l1.codproiect = pn.codproiect
                       inner join iesiri i on l.codies = i.codies
                  where i.tipdoc &lt;&gt; 16 and nvl(l.anulat,0) = 0 and l.operat = 1
                  ) group by codproiect
                 )
                */ 
                select distinct pn.codproiect
                from proiectnod pn
                  --   left join nu on nu.codproiect = pn.codproiect
                where codreteta = vCodRetVechi --and nvl(nu.nr,0) = 0
                ) loop
    CloneazaProiect(v_rec.CodProiect, vCodRetVechi, vCodRetNou, vCodPrjNou);
    if vInactivePrj &gt; 0 then
      update proiect set activ = 0, generic = 0, implicit = 0 where codproiect = v_rec.codproiect;
    end if;
    if vInactiveRet &gt; 0 then
      update prodcomp set inactiv = 1, generic = 0, implicit = 0 where codprodcomp = vCodRetVechi;
    end if;
  end loop;
  commit;
end;  

procedure CheckTmpExt is
NR NUMBER(20);
NR1 NUMBER(20);
SIR VARCHAR2(5000);
DT VARCHAR2(500);
VG VARCHAR2(500);
begin
  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_PROIECTEXT&apos;) = 1 THEN
    SELECT COUNT(*) INTO NR1 FROM USER_TAB_COLS WHERE  TABLE_NAME = &apos;PROIECTEXT&apos; AND COLUMN_ID IS NOT NULL;
    SELECT COUNT(*) INTO NR  FROM USER_TAB_COLS WHERE  TABLE_NAME = &apos;TMP_PROIECTEXT&apos; AND COLUMN_ID IS NOT NULL;

    IF NR1 &lt;&gt; NR THEN
      EXECUTE IMMEDIATE &apos;DROP TABLE TMP_PROIECTEXT&apos;;
    END IF;
    SELECT COUNT(*) INTO NR FROM USER_OBJECTS WHERE OBJECT_NAME = &apos;SEQ_PROIECTEXT_CODPROIECTEXT&apos;;
    IF NR = 0 THEN
      PKG_REMAKE_SEQUENCES.REMAKE_SEQUENCE(&apos;PROIECTEXT&apos;, &apos;CODPROIECTEXT&apos;, &apos;SEQ_PROIECTEXT_CODPROIECTEXT&apos;);
    END IF;
  END IF;

  IF PKG_LIST_STRUCT.TmpExists(&apos;TMP_PROIECTEXT&apos;) = 0 THEN
    Sir := &apos;CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTEXT(&apos; ;
    SELECT COUNT(*) INTO NR FROM USER_TAB_COLS WHERE  TABLE_NAME = &apos;PROIECTEXT&apos; AND COLUMN_ID IS NOT NULL;
    FOR V_REC IN (SELECT * FROM USER_TAB_COLS WHERE  TABLE_NAME = &apos;PROIECTEXT&apos; AND COLUMN_ID IS NOT NULL ORDER BY COLUMN_ID)
    LOOP
      IF V_REC.DATA_TYPE = &apos;VARCHAR2&apos; THEN DT := &apos; VARCHAR2(&apos; || V_REC.DATA_LENGTH || &apos;) &apos;;
      ELSE
      IF V_REC.DATA_TYPE = &apos;DATE&apos; THEN DT := &apos; DATE &apos;;
      ELSE
       DT := &apos; NUMBER(&apos; || V_REC.DATA_PRECISION || &apos;,&apos; || V_REC.DATA_SCALE || &apos;) &apos;;
      END IF;
      END IF;

      IF V_REC.COLUMN_ID &lt; NR  THEN VG := &apos;, &apos;;
      ELSE
       VG := &apos;&apos;;
      END IF;
      DT := DT || VG;
      SIR := SIR || &apos; &apos; || V_REC.COLUMN_NAME || &apos; &apos; || DT;
    END LOOP;
    SIR := SIR || &apos; ) ON COMMIT PRESERVE ROWS&apos;;
    execute immediate SIR;
--    execute immediate &apos;CREATE GLOBAL TEMPORARY TABLE &apos; || PKG_GLOBALS.FIRMANAME || &apos;.TMP_COMANDC ( CODCOMANDC NUMBER(20), CODCOMANDA NUMBER(20) ) ON COMMIT PRESERVE ROWS &apos;;
    --PKG_CFGTABLES.SETGRANTMODUL(&apos;TMP_PROIECTEXT&apos;, PKG_GLOBALS.FIRMANAME);
  END IF;
end;  

procedure GENPRJASCUNS(aCodProiect in number, aCodProiectNou out number) is
aCod number(20);
aCodPN number(20);
aNod number(20);
aCodRet number(20);
aCodRetN number(20);
begin
  select seq_proiect_codproiect.nextval into aCod from dual;
  insert into proiect(
    CODPROIECT,
    CODVERSIUNE,
    CODOBIECTPROD,
    VERSIUNE,
    INTOCMITA,
    DATAPROIECT,
    CLASA,
    PROCESARE,
    COMPLEX,
    ACTIV,
    FINALIZAT,
    BLOCAT,
    INVIZIBILA,
    GENERIC,
    DURATA,
    MARJAORDINE,
    USERID,
    DATACREARE,
    OBS1,
    OBS2,
    OBS3,
    OBS4,
    OBS5,
    OBS6,
    Ascuns,
    CodIdentificare
  )
  select   
    aCod,
    CODVERSIUNE,
    CODOBIECTPROD,
    VERSIUNE,
    INTOCMITA,
    trunc(sysdate),
    CLASA,
    PROCESARE,
    COMPLEX,
    ACTIV,
    FINALIZAT,
    BLOCAT,
    INVIZIBILA,
    0,
    DURATA,
    MARJAORDINE,
    pkg_globals.GETUSERID,
    sysdate,
    OBS1,
    OBS2,
    OBS3,
    OBS4,
    OBS5,
    OBS6,
    1,
    aCod
  from proiect 
  where codproiect = aCodProiect;
   
  delete tmp_proiectnod;
  insert into tmp_proiectnod(CODPROIECTNOD,
                             CODPROIECT,
                             CANT,
                             NODORIGINAL,
                             POZITIE,
                             CODRETETA,
                             TIP,
                             CODOBIECT,
                             INDEXPARINTE,
                             CODPRODMAT,
                             NIVEL,
                             ORDINE,
                             DECALAJ,
                             INCEPERE)
  select CODPROIECTNOD,
         aCod,
         CANT,
         NODORIGINAL,
         POZITIE,
         CODRETETA,
         TIP,
         CODOBIECT,
         INDEXPARINTE,
         CODPRODMAT,
         NIVEL,
         ORDINE,
         DECALAJ,
         INCEPERE
  from proiectnod
  where codproiect = aCodProiect;        
  
  for v_rec in (select codproiectnod
                from proiectnod 
                where codproiect = aCodProiect
                order by indexparinte
                ) loop
    select seq_proiectnod_codproiectnod.nextval into aCodPN from dual;
    update tmp_proiectnod set codproiectnod = aCodPN where codproiectnod = v_rec.codproiectnod;
    update tmp_proiectnod set nodoriginal = aCodPN where nodoriginal = v_rec.codproiectnod;
  end loop;
  
  insert into proiectnod (
    CODPROIECTNOD,
    CODPROIECT,
    CANT,
    NODORIGINAL,
    POZITIE,
    CODRETETA,
    TIP,
    CODOBIECT,
    INDEXPARINTE,
    CODPRODMAT,
    NIVEL,
    ORDINE,
    DECALAJ,
    INCEPERE
  )
  select 
    CODPROIECTNOD,
    CODPROIECT,
    CANT,
    NODORIGINAL,
    POZITIE,
    CODRETETA,
    TIP,
    CODOBIECT,
    INDEXPARINTE,
    CODPRODMAT,
    NIVEL,
    ORDINE,
    DECALAJ,
    INCEPERE   
  from tmp_proiectnod;
  
  /*select codproiectnod into anod from proiectnod where codproiect = aCod and nvl(nodoriginal,0) = 0;
  select codreteta into acodret from proiectnod where codproiect = acodproiect and nvl(nodoriginal,0) = 0;
  acodretn := pkg_prodcomp.CloneazaReteta(acodret);
  update prodcomp set ascuns = 1 where codprodcomp = acodretn;
  update prodcomp set codutilizare = acodretn where codprodcomp = acodret;
  update prodcomp set generic = 0, implicit = 0 where codprodcomp = aCodRetN;
  
  for v_rec in (select pn.codproiectnod, matn.codmat
                from proiectnod pn
                     inner join prodmat mat on mat.codmat = pn.codprodmat
                     inner join prodmat matn on matn.codprodcomp = acodretn and matn.codobiect = mat.codobiect and matn.indexlocal = mat.indexlocal
                where pn.codproiect = acod and pn.nodoriginal = anod) loop
    update proiectnod set codprodmat = v_rec.codmat where codproiectnod = v_rec.codproiectnod;
  end loop;
  update proiectnod set codreteta = acodretn where codproiect = acod and nvl(nodoriginal,0) = 0;*/
  update proiect set codutilizare = aCod where codproiect = aCodProiect;
  update proiect set codidentificare = aCod where codidentificare = aCodProiect;
  
  IF PKG_LIST_STRUCT.TmpExists(&apos;PROIECTEXT&apos;) = 1 THEN
    PKG_PROIECT.CheckTmpExt;
    EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;; 
    EXECUTE IMMEDIATE &apos;INSERT INTO TMP_PROIECTEXT SELECT * FROM PROIECTEXT WHERE CODPROIECT = &apos;||ACODPROIECT;
    EXECUTE IMMEDIATE &apos;UPDATE TMP_PROIECTEXT SET CODPROIECT = &apos;||ACOD||&apos;, CODPROIECTEXT = SEQ_PROIECTEXT_CODPROIECTEXT.NEXTVAL&apos;;
    EXECUTE IMMEDIATE &apos;INSERT INTO PROIECTEXT SELECT * FROM TMP_PROIECTEXT&apos;;
    EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
  END IF;
  
  commit;
  aCodProiectNou := aCod;
end;

procedure CheckExtPrj(aCodProiect in number, aCodProiectI in number) is
aCodProiectExt number(20);
aCodProiectExtI number(20);
begin
  begin
    execute immediate &apos;select nvl(codproiectext,0) from proiectext where codproiect = &apos;||aCodProiect into aCodProiectExt;
  exception when others then aCodProiectExt := 0;
  end;
  begin
    execute immediate &apos;select nvl(codproiectext,0) from proiectext where codproiect = &apos;||aCodProiectI into aCodProiectExtI;
  exception when others then aCodProiectExtI := 0;
  end;
  CheckTmpExt;
  if aCodProiectExt &gt; 0 then
    if aCodProiectExtI = 0 then
      EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO TMP_PROIECTEXT SELECT * FROM PROIECTEXT WHERE CODPROIECTEXT = &apos;||aCODPROIECTEXT;
      EXECUTE IMMEDIATE &apos;UPDATE TMP_PROIECTEXT SET CODPROIECT = &apos;||aCODPROIECTI||&apos;, CODPROIECTEXT = SEQ_PROIECTEXT_CODPROIECTEXT.NEXTVAL&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO PROIECTEXT SELECT * FROM TMP_PROIECTEXT&apos;;
      EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
    else
      EXECUTE IMMEDIATE &apos;DELETE PROIECTEXT WHERE CODPROIECTEXT = &apos;||aCodProiectExtI;
      EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO TMP_PROIECTEXT SELECT * FROM PROIECTEXT WHERE CODPROIECTEXT = &apos;||aCODPROIECTEXT;
      EXECUTE IMMEDIATE &apos;UPDATE TMP_PROIECTEXT SET CODPROIECT = &apos;||aCODPROIECTI||&apos;, CODPROIECTEXT = SEQ_PROIECTEXT_CODPROIECTEXT.NEXTVAL&apos;;
      EXECUTE IMMEDIATE &apos;INSERT INTO PROIECTEXT SELECT * FROM TMP_PROIECTEXT&apos;;
      EXECUTE IMMEDIATE &apos;DELETE TMP_PROIECTEXT&apos;;
    end if;
    commit;
  end if;  
end;

procedure CorectExtUnic is
aCodM number(20);
aCount number(20);
vNr number(20);
ssql varchar2(10000);
begin
  IF PKG_LIST_STRUCT.TmpExists(&apos;PROIECTEXT&apos;) = 1 THEN
    begin
      execute immediate &apos;select count(*) from proiectext&apos; into aCount;
    exception when others then aCount := 0;
    end;
    if aCount &gt; 0 then
      begin
        execute immediate &apos;select min(codproiectext) - 1 from proiectext&apos; into aCodM;
      exception when others then aCodM := 100;
      end;
      sSql := &apos;begin
                 for v_rec in (select &apos;||aCodM||&apos; + rownum NewCod, codproiect from proiectext order by codproiectext) loop
                   update proiectext set codproiectext = v_rec.newcod where codproiect = v_rec.codproiect;
                 end loop;
               end;&apos;;
      execute immediate ssql;           
      EXECUTE IMMEDIATE &apos;SELECT SEQ_PROIECTEXT_CODPROIECTEXT.NEXTVAL FROM dual&apos; INTO vNr;
      execute immediate &apos;select max(codproiectext)+1 from proiectext&apos; into aCodM;
      commit;
      BEGIN
        EXECUTE IMMEDIATE &apos;DROP SEQUENCE SEQ_PROIECTEXT_CODPROIECTEXT&apos;;
      EXCEPTION
        WHEN OTHERS THEN NULL;
      END;
      EXECUTE IMMEDIATE &apos;CREATE SEQUENCE SEQ_PROIECTEXT_CODPROIECTEXT START WITH &apos;||aCodM||&apos; INCREMENT BY 1&apos;;
    end if;  
  END IF;
  commit;
end;

procedure CurataExtAcunse is
ssql varchar2(10000);
begin
  sSql := &apos;begin
             for v_rec in (select codproiect from proiect where ascuns = 1) loop
               delete proiectext where codproiect = v_rec.codproiect;
             end loop;
             commit;
           end;&apos;;
  execute immediate ssql;
end;

procedure CheckExtPrjAscunse is
begin
  IF PKG_LIST_STRUCT.TmpExists(&apos;PROIECTEXT&apos;) = 1 THEN
    CurataExtAcunse;
    CorectExtUnic;
    PKG_PROIECT.CheckTmpExt;
    for v_rec in (select p.codproiect, pi.codproiect codproiecti
                  from proiect p
                       inner join proiect pi on p.codutilizare = pi.codproiect
                  where p.codutilizare &gt; 0     
                  ) loop
      CheckExtPrj(v_rec.CodProiect, v_rec.CodProiectI);
    end loop;             
  end if;
end;  


function GetDurataCopii(aCodNod in number, aDur in number) return number is
Copii number;
Dur number(20,7);
DurNodPrecedent number(20,7);
DurataNodCurent number(20,7);

begin
  Dur := 0;
	SELECT Count(*) into Copii from  tmp_proiectman where NodOriginal = aCodNod;
	if Copii = 0 then  
	  Dur := aDur; 
	else 
		DurNodPrecedent := 0;
		FOR V_REC IN (SELECT RowNum Ind, X.* from tmp_proiectman x where NodOriginal = aCodNod order by Pozitie) loop
			 DurataNodCurent := V_Rec.Durata + GetDurataCopii(V_Rec.CODPROIECTNOD, V_Rec.Durata);
			 if V_rec.Decalaj = 3 then 
				 if DurataNodCurent &gt; DurNodPrecedent then Dur := Dur + DurataNodCurent; else Dur := Dur + DurNodPrecedent; end if;
			 elsif V_rec.Decalaj = 4 then 
				 if DurataNodCurent &gt; DurNodPrecedent then Dur := Dur + DurataNodCurent; else Dur := Dur + DurNodPrecedent; end if;
			 else
				 Dur := Dur + DurataNodCurent;
			 end if;
			 DurNodPrecedent := DurataNodCurent;
		end loop; 
	end if; 
	update tmp_proiectman x set DurataNod = Dur where x.codproiectnod = aCodNod;
	Return Dur;
end;

procedure SetIncepereCopii(aCodNod in number, aFinal in number) is
Copii number;
IncepeNodPrecedent number(20,7);
IncepeNodCurent number(20,7);
DurataNodPrecedent number(20,7);
aDecalaj   number;  
begin
	SELECT Count(*) into Copii from  tmp_proiectman where NodOriginal = aCodNod;
	if Copii = 0 then  
		 update tmp_proiectman x set 
			 Incepere = aFinal  
		 where x.codproiectnod = aCodNod;
	else
		IncepeNodPrecedent := 0;
		DurataNodPrecedent := 0;
		FOR V_REC IN (SELECT RowNum Ind, X.* from tmp_proiectman x where NodOriginal = aCodNod order by Pozitie) loop
			 aDecalaj := Nvl(V_rec.Decalaj,0);
			 if 
			 aDecalaj = 3 then 
					if V_REC.Duratanod &gt;= DurataNodPrecedent 
					then 
					  IncepeNodCurent    := IncepeNodPrecedent;
					else 
					  IncepeNodCurent    := IncepeNodPrecedent + DurataNodPrecedent - V_REC.DurataNod; 
						aDecalaj := 4;
					end if;
			 elsif 
			 aDecalaj = 4 then 
					if V_REC.Duratanod &gt;= DurataNodPrecedent 
					then 
					  IncepeNodCurent    := IncepeNodPrecedent;
						aDecalaj := 3;
					else 
					  IncepeNodCurent := IncepeNodPrecedent + DurataNodPrecedent - V_REC.DurataNod;    
					end if;
			 else
  			 if V_Rec.Ind = 1 then aDecalaj := 1; else aDecalaj := 2; end if; 
				 IncepeNodCurent    := IncepeNodPrecedent + DurataNodPrecedent;
			 end if;
			 IncepeNodCurent := aFinal + IncepeNodCurent;
			 DurataNodPrecedent := V_REC.DurataNod;    
			 IncepeNodPrecedent := IncepeNodCurent;
       update tmp_proiectman x set 
  			 Decalaj  = aDecalaj, 
	  		 Incepere = IncepeNodCurent 
			 where x.codproiectnod = V_REC.CodProiectNod;
			 SetIncepereCopii(V_REC.CodProiectNod, IncepeNodCurent + V_REC.DurataNod);
		end loop; 
	end if; 
end;

procedure TestDurata is
X number;
begin
  PKG_PROIECT.SP_GOTORECORD(118);
end;

procedure UmpleMan is
begin
  insert into tmp_proiectman (
  CODPROIECTNOD,
  CODPROIECT,   
  NODORIGINAL,  
  POZITIE,      
  CODRETETA,    
  DEN_OBIECT,   
  TIP,          
  SIMBOL,       
  DURATA,       
  CANT,         
  NIVEL,        
  ORDINE,       
  INCEPERE,
  Decalaj,
  DURATANOD,    
  COPILMAXIM,   
  NODCRITIC,    
  BARA,
  LOTOPTIM,
  INDEXPARINTE         
  )
  select 
       PN.CODPROIECTNOD,
       PN.CODPROIECT,
       PN.NODORIGINAL,
       PN.POZITIE,
       PN.CODRETETA,
       obj.denumire den_obiect,
       0,
       pn.IndexParinte Simbol,
       Round(pn.Cant * nvl(pc.Durata, 0) / pc.cant, 3) Durata,
       pn.Cant,
       pn.nivel,
       nvl(o.Ordine*10000 + Pozitie,0),
       Nvl(Incepere, 0),
       PN.DECALAJ,
       0,
       -1,
       &apos;...&apos; NodCritic,
       &apos;...&apos; bara,
       pc.cant,
       PN.INDEXPARINTE
  from tmp_proiectnod pn
       inner join prodcomp pc on pn.codreteta = pc.codprodcomp
       inner join nartobj obj on obj.codobiect = pc.codobiect
       inner join (select distinct Nivel, (Select Max(Nivel) from tmp_proiectnod) - Nivel as Ordine
                   from tmp_proiectnod Group by Nivel) O on O.Nivel = pn.Nivel
  WHERE pc.codprodcomp &gt; 0;
end;  

procedure PROPAGAGANT(aCodProiect in number) is
begin
  for v_rec in (
    select p.codproiect
    from proiect pi
         inner join proiect p on p.codidentificare = pi.codutilizare
    where pi.codproiect = aCodProiect
  ) loop
    for v_pn in (
      select pn.codproiectnod, pni.decalaj, pni.incepere
      from proiectnod pni, proiectnod pn
      where pni.codproiect = aCodProiect and pn.codproiect = v_rec.codproiect
            and pni.indexparinte = pn.indexparinte and pni.codobiect = pn.codobiect 
            and pni.pozitie = pn.pozitie
    ) loop
      update proiectnod set decalaj = v_pn.decalaj, incepere = v_pn.incepere where codproiectnod = v_pn.codproiectnod;
    end loop;
  end loop;
end;  

end pkg_proiect;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROIECTCRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCDE9F2687B47EF7A3E8952791B89FB6E3DE55F4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROIECTCRM is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodProiectCRM INTO Tmp FROM PROIECTCRM WHERE CodProiectCRM = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM PROIECTCRM WHERE CodProiectCRM = RecId;
  NotifyModif(2, RecId, &apos;PROIECTCRM&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PROIECTCRM FIELDS( CodProiectCRM) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_PROIECTCRM (CodProiectCRM, Denumire, Descriere, Valoare, Moneda, CodPers)
  SELECT CodProiectCRM, Denumire, Descriere, Valoare, Moneda, CodPers
  FROM PROIECTCRM WHERE CodProiectCRM = RecId;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodProiectCRM INTO RecId FROM TMP_PROIECTCRM;
    UPDATE PROIECTCRM SET (Denumire, Descriere, Valoare, Moneda, CodPers)
    = (SELECT Denumire, Descriere, Valoare, Moneda, CodPers
       FROM TMP_PROIECTCRM)
    WHERE CodProiectCRM = RecId;
  ELSE  -- INSERT
    SELECT SEQ_PROIECTCRM_CODPROIECTCRM.NextVal INTO RecId FROM DUAL;
    INSERT INTO PROIECTCRM(CodProiectCRM, Denumire, Descriere, Valoare, Moneda, CodPers)
    SELECT RecId, Denumire, Descriere, Valoare, Moneda, CodPers
    FROM TMP_PROIECTCRM;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;NCLASEOP&apos;);
  COMMIT;
END;

end PKG_PROIECTCRM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2557DDDB65129E0D5AF6AA65F651946E0A67997E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PROMO IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_30&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodPromo INTO Tmp FROM PROMO WHERE CodPromo = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PROMO FIELDS(CodPromo) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aCarnetDoc  NUMBER (20);
  aNrDoc      NUMBER (20);
  aCodSubunit NUMBER(20);
  aDataDoc    DATE;
  aDoc        VARCHAR2(200);
  aSyncPromoRetail varchar2(1);

BEGIN
  SP_LOCKRECORD(RecId);

  SELECT  CarnetDoc, NrDoc, Subunitatea, DataStart, &apos;PROMO&apos;||NrDoc||&apos;/&apos;||DataStart||&apos;-&apos;||DataEnd
  INTO    aCarnetDoc, aNrDoc, aCodSubunit, aDataDoc, aDoc
  FROM    PROMO
  WHERE   CodPromo = recId;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROMO&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  -- STERGERE DETALII PROMO1CADOU
  DELETE FROM PROMO1CADOUSER WHERE CODCADOU IN (SELECT PC.CodCadou FROM PROMO1 P1 INNER JOIN PROMO1CADOU PC ON PC.CodPromo1 = P1.CodPromo1 WHERE P1.CodPromo = RECID);
  DELETE FROM PROMO1CADOUSER WHERE CODCADOU IN (SELECT PC.CodCadou FROM PROMO1CADOU PC WHERE PC.CodPromo = RECID);

  -- STERGERE DETALII PROMO1
  DELETE FROM PROMO1SER   WHERE CodPromo1 IN (SELECT CodPromo1 FROM PROMO1 WHERE CodPromo = RecId);
  DELETE FROM PROMO1CADOU WHERE CodPromo1 IN (SELECT CodPromo1 FROM PROMO1 WHERE CodPromo = RecId);

  -- STERGERE DETALII PROMO
  DELETE FROM PROMO1CADOU WHERE CodPromo = RECID;
  DELETE FROM PROMOPART   WHERE CodPromo = RECID;
  DELETE FROM PROMOSUB    WHERE CodPromo = RECID;
  DELETE FROM PROMOPRAG   WHERE CodPromo = RECID;
  DELETE FROM PROMO1      WHERE CodPromo = RecId ;
  DELETE FROM PROMO       WHERE CodPromo = RecId ;

  PKG_CARNETEDOC.RELEASENUMARDOC(aCarnetDoc, aNrDoc);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCarnetDoc);

  NotifyModif(2, RecId, &apos;PROMO&apos;);

 BEGIN
   SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPromoRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPromoRetail FROM DUAL;
   EXCEPTION WHEN OTHERS THEN aSyncPromoRetail := &apos;0&apos;;
 END;

  IF aSyncPromoRetail = &apos;1&apos; then
    PKG_POSTRETAIL.MEMO_MODIF_PROMO_RETAIL(RECID, 1);
  END IF;  

  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  vCount     INTEGER;
  vTipDenArt INTEGER;
  vTipPrefix INTEGER;
BEGIN
  vTipPrefix := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;TipPrefixDenObiect&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),1);

  INSERT INTO TMP_PROMO (
    CodPromo, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd,
    Moneda, TipPromotie, TipConditie, Obs,
    Subunitatea,
    UserId, TipClasep, TipServire, DeMana, ValMin, Praguri, CantMin, ExclAltePromo,
    OraStart, OraStop,
    An, Luna, Conf_Active, PRETCUAMANUNT)
  SELECT
    CodPromo, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd,
    Moneda, TipPromotie, TipConditie, Obs,
    Coalesce(Subunitatea, PKG_GLOBALS.getSubunitate),
    UserId, Coalesce(TipClasep,0), Coalesce(TipServire,0), Coalesce(DeMana,0), Coalesce(ValMin,0), Coalesce(Praguri,0), Coalesce(CantMin,0), Coalesce(ExclAltePromo,0),
    Coalesce(OraStart,&apos;00:00&apos;), Coalesce(OraStop,&apos;23:59&apos;),
    PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GetLunaLucru, 1, PRETCUAMANUNT
  FROM PROMO WHERE CodPromo = RecId;

  SELECT CASE DEMANA WHEN 4 THEN 9 WHEN 3 THEN 8 ELSE vTipPrefix END INTO vTipDenArt FROM TMP_PROMO;

  INSERT INTO TMP_PROMOPART (
    CodPromoPart, CodPromo, CodClaseP, Partener, CodLocatie, CodFiscal, CodPersC, Prioritar,
    Denumire, Den_Sediu, Den_CodFiscal, Den_PersC )
  SELECT
    PP.CodPromoPart, PP.CodPromo, PP.CodClaseP, PP.Partener, PP.CodLocatie, PP.CodFiscal, PP.CodPersC, Coalesce(PP.Prioritar,0),
    Decode( Coalesce(P.TipClaseP,0),1,C.Den_ClaseP, NP.Den_Part), Decode(PP.CodLocatie,0,&apos;TOATE&apos;,A.Obs), CF.CodFiscal, PC.NUme||&apos; &apos;||PC.Prenume
  FROM PROMO P
    INNER JOIN PROMOPART PP   ON PP.CodPromo = P.CodPromo
    LEFT JOIN NCLASEP C       ON C.CodClaseP = PP.CodClaseP
    LEFT JOIN NPART NP        ON NP.CodPart = PP.Partener
    LEFT JOIN NAGENDA A       ON A.CodAgenda = PP.CodLocatie
    LEFT JOIN NPARTCODFISC CF ON CF.Cod_CodFiscal = PP.CodFiscal
    LEFT JOIN NPERSCONTACT PC ON PC.CodPersC = PP.CodPersC
  WHERE P.CodPromo = RecId;

  vCount := 0;
  SELECT Count(CodPromoPart) INTO vCount FROM TMP_PROMOPART;
  IF vCount = 0 THEN
    INSERT INTO TMP_PROMOPART (
      CodPromoPart, CodPromo, Partener, CodLocatie, CodFiscal, CodPersC, Prioritar,
      Denumire, Den_Sediu, Den_CodFiscal, Den_PersC )
    SELECT
      -1, P.CodPromo, P.Partener, P.CodLocatie, P.CodFiscal, P.CodPersC, 0 Prioritar,
      NP.Den_Part, Decode(P.CodLocatie,0,&apos;TOATE&apos;,A.Obs), CF.CodFiscal, PC.NUme||&apos; &apos;||PC.Prenume
    FROM PROMO P
      INNER JOIN NPART NP       ON NP.CodPart = P.Partener
      LEFT JOIN NAGENDA A       ON A.CodAgenda = P.CodLocatie
      LEFT JOIN NPARTCODFISC CF ON CF.Cod_CodFiscal = P.CodFiscal
      LEFT JOIN NPERSCONTACT PC ON PC.CodPersC = P.CodPersC
    WHERE P.CodPromo = RecId AND Coalesce(P.Partener,0) &lt;&gt; 0;
  END IF;

  INSERT INTO TMP_PROMOSUB ( CodPromoSub, CodPromo, Subunitatea, Denumire )
  SELECT PS.CodPromoSub, PS.CodPromo, PS.Subunitatea, S.Den_Subunit
  FROM PROMOSUB PS INNER JOIN NSUBUNIT S ON S.CodSubunit = PS.Subunitatea
  WHERE PS.CodPromo = RecId;

  vCount := 0;
  SELECT Count(CodPromoSub) INTO vCount FROM TMP_PROMOSUB;
  IF vCount = 0 THEN
    INSERT INTO TMP_PROMOSUB ( CodPromoSub, CodPromo, Subunitatea, Denumire )
    SELECT -1, P.CodPromo, P.Subunitatea, S.Den_Subunit
    FROM TMP_PROMO P INNER JOIN NSUBUNIT S ON S.CodSubunit = P.Subunitatea
    WHERE P.Subunitatea &gt; 1;
  END IF;

  INSERT INTO TMP_PROMOPRAG(CODPRAG, CODPROMO, VALMIN, PROCDISC, VALDISC, CANTMIN)
  SELECT CODPRAG, CODPROMO, VALMIN, PROCDISC, VALDISC, CANTMIN
  FROM PROMOPRAG
  WHERE CODPROMO = RecId;

  INSERT INTO  TMP_PROMO1 (
    CodPromo1, CodPromo, CodObiect, CodArticol, CodClaseA, CuEchivalente, UMSec, Cant, CantOptim, Pret, PretAmanunt,
    ProcDisc, ValDisc, ZileC, TipLimita, ModAplic, TG_Max, Zile_Exp, GrupaPret, ValMin,
    IndexLocal,
    DenObiect,
    DenUM, Paritate,
    AuxLimita, ObjCuAtrib,
    ProcTVA,
    CodExtern, CodIntern, CodExternArt,
    PeArticol, cant_max)
  SELECT
    P1.CodPromo1, P1.CodPromo, P1.CodObiect, P1.CodArticol, P1.CodClaseA, CuEchivalente, P1.UMSec, P1.Cant/Coalesce(U.Paritate,1), p1.CantOptim/Coalesce(U.Paritate,1), P1.Pret*Coalesce(U.Paritate,1), P1.PretAmanunt*Coalesce(U.Paritate,1),
    P1.ProcDisc, P1.ValDisc, P1.ZileC, Coalesce(P1.TipLimita,0), Coalesce(P1.ModAplic,0), P1.TG_Max, P1.Zile_Exp, P1.GrupaPret, P1.ValMin,
    DENSE_RANK() OVER (ORDER BY P1.CodPromo1 ASC),
    CASE vTipDenArt
      WHEN 9 THEN &apos;***TOATE***&apos;
      WHEN 8 THEN CA.Den_ClaseA
      WHEN 3 THEN SUBSTR(OBJ.CodIntern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      WHEN 2 THEN SUBSTR(OBJ.CodExtern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      ELSE OBJ.Denumire
    END DenObiect,
    U.Den_UM1, Coalesce(U.Paritate,1),
    CASE P1.TipLimita
      WHEN 3 THEN &apos;Serie&apos;
      WHEN 2 THEN &apos;Zile expirare &lt;= &apos;||P1.Zile_Exp
      WHEN 1 THEN &apos;Data expirare &lt;= &apos;||To_Char(P1.TG_Max,&apos;dd.mm.yyyy&apos;)
      ELSE &apos;Stoc disponibil&apos;
    END,
    CASE WHEN EXISTS (SELECT AO.CODATROBJ FROM NATROBJ AO WHERE AO.CodObiect = P1.CodObiect) THEN 1 ELSE 0 END,
    PKG_SELECTARTICOLE.GETPROCENTTVA(Obj.CODARTICOL,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU),
    OBJ.CODEXTERN, OBJ.CODINTERN, A.CODEXTERNART,
    CASE WHEN Coalesce(P1.CodArticol,0) &gt; 0 THEN 1 ELSE 0 END PeArticol, P1.CANT_MAX/Coalesce(U.Paritate,1)
  FROM PROMO1 P1
    LEFT JOIN NARTOBJ OBJ ON Obj.CodObiect = P1.CodObiect
    LEFT JOIN NUM1 U      ON U.CodUM1      = P1.UMSec
    LEFT JOIN NART A      ON A.CodArticol  = OBJ.CodArticol
    LEFT JOIN NCLASEA CA  ON CA.CodClaseA  = P1.CodClaseA
  WHERE P1.CodPromo = RecId;

  -- promo1cadou cu legatura in promo1
  INSERT INTO  TMP_PROMO1CADOU (
    CodCadou, CodPromo1, CodPromo, CodObiect, UMSec, Cant,
    TipLimita, TG_Max, Zile_Exp, ValMin, CantMin,
    IndexLocal,
    DenObiect, DenUM, Paritate,
    AuxLimita)
  SELECT
    PC.CodCadou, PC.CodPromo1, PC.CodPromo, PC.CodObiect, PC.UMSec, PC.Cant/U.Paritate,
    Coalesce(PC.TipLimita,0), PC.TG_Max, PC.Zile_Exp, PC.ValMin, PC.CantMin/U.Paritate,
    DENSE_RANK() OVER (PARTITION BY PC.CodPromo1 ORDER BY PC.CodCadou ASC),
    CASE vTipPrefix
      WHEN 2 THEN SUBSTR(OBJ.CodExtern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      WHEN 3 THEN SUBSTR(OBJ.CodIntern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      ELSE OBJ.Denumire
    END DenObiect,
    U.Den_UM1, U.Paritate,
    CASE PC.TipLimita
      WHEN 3 THEN &apos;Serie&apos;
      WHEN 2 THEN &apos;Zile expirare &lt;= &apos;||PC.Zile_Exp
      WHEN 1 THEN &apos;Data expirare &lt;= &apos;||To_Char(PC.TG_Max,&apos;dd.mm.yyyy&apos;)
      ELSE &apos;Stoc disponibil&apos;
    END
  FROM PROMO1CADOU PC
    LEFT JOIN NARTOBJ OBJ ON Obj.CodObiect = PC.CodObiect
    LEFT JOIN NUM1 U      ON U.CodUM1      = PC.UMSec
  WHERE PC.CodPromo1 IN (SELECT CODPROMO1 FROM TMP_PROMO1);

  -- promo1 cadou fara legatura in promo1
  INSERT INTO  TMP_PROMO1CADOU (
    CodCadou, CodPromo1, CodPromo, CodObiect, UMSec, Cant,
    TipLimita, TG_Max, Zile_Exp, ValMin, CantMin,
    IndexLocal,
    DenObiect, DenUM, Paritate,
    AuxLimita)
  SELECT
    PC.CodCadou, PC.CodPromo1, PC.CodPromo, PC.CodObiect, PC.UMSec, PC.Cant/U.Paritate,
    Coalesce(PC.TipLimita,0), PC.TG_Max, PC.Zile_Exp, PC.ValMin, PC.CantMin/U.Paritate,
    DENSE_RANK() OVER (PARTITION BY PC.CodPromo1 ORDER BY PC.CodCadou ASC),
    CASE vTipPrefix
      WHEN 2 THEN SUBSTR(OBJ.CodExtern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      WHEN 3 THEN SUBSTR(OBJ.CodIntern|| &apos;;&apos; ||OBJ.Denumire, 1, 200)
      ELSE OBJ.Denumire
    END DenObiect,
    U.Den_UM1, U.Paritate,
    CASE PC.TipLimita
      WHEN 3 THEN &apos;Serie&apos;
      WHEN 2 THEN &apos;Zile expirare &lt;= &apos;||PC.Zile_Exp
      WHEN 1 THEN &apos;Data expirare &lt;= &apos;||To_Char(PC.TG_Max,&apos;dd.mm.yyyy&apos;)
      ELSE &apos;Stoc disponibil&apos;
    END
  FROM PROMO1CADOU PC
    LEFT JOIN NARTOBJ OBJ ON Obj.CodObiect = PC.CodObiect
    LEFT JOIN NUM1 U      ON U.CodUM1      = PC.UMSec
  WHERE PC.CodPromo = RecId AND Coalesce(PC.CODPROMO1, 0) = 0;

  INSERT INTO TMP_PROMO1SER( CODPROMO1S, CODPROMO1, SERIE, INDEXLOCAL)
  SELECT PS.CODPROMO1S, PS.CODPROMO1, PS.SERIE, ROW_NUMBER() OVER (PARTITION BY PS.CODPROMO1 ORDER BY PS.CODPROMO1S)
  FROM TMP_PROMO1 P1 INNER JOIN PROMO1SER PS ON PS.CODPROMO1 = P1.CODPROMO1;

  INSERT INTO TMP_PROMO1CADOUSER(CODCADOUS, CODCADOU, SERIE, INDEXLOCAL)
  SELECT CS.CODCADOUS, CS.CODCADOU, CS.SERIE, ROW_NUMBER() OVER (PARTITION BY CS.CODCADOU ORDER BY CS.CODCADOUS)
  FROM TMP_PROMO1CADOU C INNER JOIN PROMO1CADOUSER CS ON CS.CODCADOU = C.CODCADOU;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo           INTEGER := 0;
  vCod             NUMBER(20);
  vCodCadou        NUMBER(20);
  aCarnetDoc       NUMBER(20);
  aNrDoc           NUMBER(20);
  aCodSubunit      NUMBER(20);
  aDataStart       DATE;
  aDataEnd         DATE;
  aDoc             VARCHAR2(200);
  aCount           INTEGER;
  aTipPromotie     NUMBER(1);
  aAmPrioritar     INTEGER;
  aSyncPromoRetail varchar2(1); 
  
  
BEGIN
  SELECT  CodPromo, CarnetDoc, NrDoc, Subunitatea, DataStart, DataEnd, &apos;PROMO&apos;||NrDoc||&apos;/&apos;||DataStart||&apos;-&apos;||DataEnd, TipPromotie
  INTO    RecId, aCarnetDoc, aNrDoc, aCodSubunit, aDataStart, aDataEnd, aDoc, aTipPromotie
  FROM    TMP_PROMO;

  DELETE FROM TMP_PROMO1CADOUSER
  WHERE CodCadou IN (SELECT CodCadou FROM TMP_PROMO1CADOU WHERE Coalesce(TipLimita,0) &lt;&gt; 3);

  DELETE FROM TMP_PROMO1SER
  WHERE CodPromo1 IN (SELECT CodPromo1 FROM TMP_PROMO1 WHERE Coalesce(TipLimita,0) &lt;&gt; 3);

  DELETE FROM TMP_PROMOSUB WHERE Coalesce(SUBUNITATEA,0) = 0;

  DELETE FROM TMP_PROMOPART WHERE Coalesce(CODCLASEP,0) = 0 AND Coalesce(PARTENER,0) = 0;

  SELECT Count(1) INTO aCount FROM TMP_PROMOSUB;
  IF aCount = 0
  THEN UPDATE TMP_PROMO SET SUBUNITATEA = 1;
  ELSE UPDATE TMP_PROMO SET SUBUNITATEA = NULL;
  END IF;

  SELECT Count(1) INTO aCount FROM TMP_PROMOPART;
  IF aCount = 0
  THEN UPDATE TMP_PROMO SET PARTENER = 0;
  END IF;

  IF aTipPromotie &lt;&gt; 2 THEN
    UPDATE TMP_PROMOPART SET PRIORITAR = 0;
  ELSE
    UPDATE TMP_PROMOPART SET PRIORITAR = 0 WHERE Coalesce(PARTENER,0) = 0;
  END IF;
  SELECT Max(Prioritar) INTO aAmPrioritar FROM TMP_PROMOPART;

  IF Operation = 0 THEN  -- UPDATE
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROMO&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataStart, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    -- Master PROMO

    UPDATE PROMO
    SET ( CodPromo, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd, Partener,
          Moneda, TipPromotie, TipConditie, Obs, Subunitatea, TipClaseP, TipServire, DeMana, ValMin, Praguri, CantMin,
          ExclAltePromo,
          OraStart, OraStop, PRETCUAMANUNT)
      = (SELECT
          CodPromo, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd, Partener,
          Moneda, TipPromotie, TipConditie, Obs, Subunitatea, TipClaseP, TipServire, DeMana, ValMin, Praguri, CantMin,
          CASE WHEN DeMana IN (3, 4) THEN ExclAltePromo ELSE 0 END ExclAltePromo,
          OraStart, OraStop, PRETCUAMANUNT
         FROM TMP_PROMO )
    WHERE CodPromo = RecId;

    -- Detail
    DELETE FROM PROMOPART
    WHERE CodPromo = RecID
      AND CodPromoPart NOT IN (SELECT CodPromoPart FROM TMP_PROMOPART);

    UPDATE PROMOPART PP
    SET (PP.CodClaseP, PP.Partener, PP.CodLocatie, PP.CodFiscal, PP.CodPersc, PP.Prioritar) =
        (SELECT T.CodClaseP, T.Partener, T.CodLocatie, T.CodFiscal, T.CodPersc, T.Prioritar FROM TMP_PROMOPART T WHERE T.CodPromoPart = PP.CodPromoPart)
    WHERE PP.CodPromo = RecID;

    INSERT INTO PROMOPART( CodPromoPart, CodPromo,  CodClaseP, Partener, CodLocatie, CodFiscal, CodPersc, Prioritar)
    SELECT Seq_PromoPart_CodPromoPart.NextVal, RecID, CodClaseP, Partener, CodLocatie, CodFiscal, CodPersc, Prioritar
    FROM TMP_PROMOPART
    WHERE Coalesce(CodPromoPart,0) &lt;= 0;

    DELETE FROM PROMOSUB
    WHERE CodPromo = RecID
      AND CodPromoSub NOT IN (SELECT CodPromoSub FROM TMP_PROMOSUB);

    UPDATE PROMOSUB PS
    SET PS.Subunitatea = (SELECT T.Subunitatea FROM TMP_PROMOSUB T WHERE T.CodPromoSub = PS.CodPromoSub)
    WHERE PS.CodPromo = RecID;

    INSERT INTO PROMOSUB( CodPromoSub, CodPromo, Subunitatea)
    SELECT Seq_PromoSub_CodPromoSub.NextVal, RecID, Subunitatea
    FROM TMP_PROMOSUB
    WHERE Coalesce(CodPromoSub,0) &lt;= 0;

    DELETE FROM PROMOPRAG
    WHERE CodPromo = RecID
      AND CodPrag NOT IN (SELECT CodPrag FROM TMP_PROMOPRAG);

    UPDATE PROMOPRAG PP
    SET (PP.ValMin, PP.ProcDisc, PP.ValDisc, PP.CantMin) = (SELECT T.ValMin, T.ProcDisc, T.ValDisc, T.CantMin FROM TMP_PROMOPRAG T WHERE T.CodPrag = PP.CodPrag)
    WHERE PP.CodPromo = RecID;

    INSERT INTO PROMOPRAG(CodPrag, CodPromo, ValMin, ProcDisc, ValDisc, CantMin)
    SELECT SEQ_PROMOPRAG_CODPRAG.NextVal, RecID, ValMin, ProcDisc, ValDisc, CantMin
    FROM TMP_PROMOPRAG
    WHERE Coalesce(CodPrag,0) &lt;= 0;

    --DELETE FROM PROMO1CADOUSER
    --WHERE CodCadou IN ( SELECT PC.CodCadou FROM Promo1 P1 INNER JOIN Promo1Cadou PC ON PC.CodPromo1 = P1.CodPromo1 WHERE P1.CodPromo = RecId)
    --  AND CodCadouS NOT IN ( SELECT CODCADOUS FROM TMP_PROMO1CADOUSER WHERE CODCADOUS &gt; 0);

    -- PROMO1CADOUSER CU LEGATURI IN PROMO1
    DELETE FROM PROMO1CADOUSER
    WHERE CodCadou IN (SELECT CODCADOU FROM PROMO1CADOU P1C, PROMO1 P1 WHERE Coalesce(P1C.CODPROMO1, 0) &lt;&gt; 0 AND P1.CODPROMO1 = P1C.CODPROMO1 AND P1.CODPROMO = RECID)
      AND CodCadouS NOT IN ( SELECT CODCADOUS FROM TMP_PROMO1CADOUSER WHERE CODCADOUS &gt; 0);

    -- PROMO1CADOUSER CU LEGATURI IN PROMO1
    DELETE FROM PROMO1CADOUSER
    WHERE CodCadouS IN (SELECT CODCADOUS FROM PROMO1CADOU P1C WHERE Coalesce(P1C.CODPROMO1, 0) = 0 AND P1C.CODPROMO = RECID)
      AND CodCadouS NOT IN ( SELECT CODCADOUS FROM TMP_PROMO1CADOUSER WHERE CODCADOUS &gt; 0);

    DELETE FROM PROMO1SER
    WHERE CodPromo1 IN (SELECT P1.CodPromo1 FROM Promo1 P1 WHERE P1.CodPromo = RecID)
      AND CodPromo1S NOT IN ( SELECT CODPROMO1S FROM TMP_PROMO1SER WHERE CODPROMO1S &gt; 0);

    -- PROMO1CADOU CU LEGATURA IN PROMO1
    DELETE FROM PROMO1CADOU
    WHERE Coalesce(CODPROMO1, 0) &lt;&gt; 0
      AND CodPromo1 IN (SELECT P1.CodPromo1 FROM Promo1 P1 WHERE P1.CodPromo = RecID)
      AND CodCadou NOT IN (SELECT CodCadou FROM TMP_PROMO1CADOU WHERE CodCadou &gt; 0);

    -- PROMO1CADOU FARA LEGATURA IN PROMO1
    DELETE FROM PROMO1CADOU
    WHERE Coalesce(CODPROMO1, 0) = 0
      AND CodPromo = RECID
      AND CodCadou NOT IN (SELECT CodCadou FROM TMP_PROMO1CADOU WHERE CodCadou &gt; 0);

    DELETE FROM PROMO1
    WHERE CodPromo = RecID
      AND CodPromo1 NOT IN (SELECT CodPromo1 FROM TMP_PROMO1);

    FOR v_rec IN (
      SELECT
        CodPromo1, CodObiect, CodArticol, CodClaseA, CuEchivalente, UMSec, Cant*Coalesce(Paritate,1) Cant,CantOptim*Coalesce(Paritate,1) CantOptim, Pret/Coalesce(Paritate,1) Pret, PretAmanunt/Coalesce(Paritate,1) PretAmanunt,
        ProcDisc, ValDisc, ZileC, TipLimita, ModAplic, TG_Max, GrupaPret, Zile_Exp, ValMin, CANT_MAX*Coalesce(PARITATE,1) as cant_max
      FROM TMP_Promo1
      ORDER BY IndexLocal)
    LOOP
      IF Coalesce(v_rec.CodPromo1,0) &gt; 0 THEN
        UPDATE Promo1
        SET    CodObiect      = v_rec.CodObiect,
               CodArticol     = v_rec.CodArticol,
               CodClaseA      = v_rec.CodClaseA,
               CuEchivalente  = v_rec.CuEchivalente,
               UMSec          = v_rec.UMSec,
               Cant           = v_rec.Cant,
               Pret           = v_rec.Pret,
               ProcDisc       = v_rec.ProcDisc,
               ValDisc        = v_rec.ValDisc,
               ZileC          = v_rec.ZileC,
               TipLimita      = v_rec.TipLimita,
               ModAplic       = v_rec.ModAplic,
               TG_Max         = Decode(v_rec.TipLimita,1,v_rec.TG_Max,NULL),
               GrupaPret      = v_rec.GrupaPret,
               Zile_Exp       = Decode(v_rec.TipLimita,2,v_rec.Zile_Exp,NULL),
               ValMin         = v_rec.ValMin,
               PretAmanunt    = v_rec.PretAmanunt,
               CantOptim      = v_rec.CantOptim,
               cant_max       = v_rec.cant_max
        WHERE  CodPromo1 = v_rec.CodPromo1;

        --DELETE FROM PROMO1CADOU C
        --WHERE C.CodPromo1 = v_rec.CodPromo1
        --  AND NOT EXISTS (SELECT 1 FROM TMP_PROMO1CADOU TC WHERE TC.CodPromo1 = C.CodPromo1 AND TC.CodCadou = C.CodCadou);
      ELSE
        SELECT Seq_PROMO1_CodPromo1.NEXTVAL INTO vCod FROM dual;
        UPDATE TMP_PROMO1CADOU SET CodPromo1 = vCOD WHERE CodPromo1 = v_rec.CodPromo1;
        UPDATE TMP_PROMO1SER   SET CodPromo1 = vCOD WHERE CodPromo1 = v_rec.CodPromo1;

        INSERT INTO  Promo1 (
          CodPromo1, CodPromo, CodObiect, CodArticol, CodClaseA, CuEchivalente, UMSec, Cant, Pret, ProcDisc, ValDisc, GrupaPret, ZileC,
          TipLimita, ModAplic, TG_Max, Zile_Exp,
          ValMin, PretAmanunt,CantOptim, cant_max)
        VALUES (
          vCod , RecId, v_rec.CodObiect, v_rec.CodArticol, v_rec.CodClaseA, v_rec.CuEchivalente, v_rec.UMSec, v_rec.Cant, v_rec.Pret, v_rec.ProcDisc, v_rec.ValDisc, v_rec.GrupaPret, v_rec.ZileC,
          v_rec.TipLimita, v_rec.ModAplic, Decode(v_rec.TipLimita,1,v_rec.TG_Max,NULL), Decode(v_rec.TipLimita,2,v_rec.Zile_Exp,NULL),
          v_rec.ValMin, v_rec.PretAmanunt, v_rec.CantOptim, v_rec.cant_max);
      END IF;
    END LOOP;

    FOR v_rec IN (
      SELECT CodCadou, CodPromo1, CodPromo, CodObiect, UMSec, Cant*Paritate Cant, TipLimita, TG_Max, Zile_Exp, ValMin, CantMin*Paritate CantMin
      FROM TMP_Promo1Cadou
      ORDER BY CodPromo1, IndexLocal)
    LOOP
      IF Coalesce(v_rec.CodCadou,0) &gt; 0 THEN
        UPDATE Promo1Cadou
        SET    CodObiect      = v_rec.CodObiect,
               UMSec          = v_rec.UMSec,
               Cant           = v_rec.Cant,
               TipLimita      = v_rec.TipLimita,
               TG_Max         = Decode(v_rec.TipLimita,1,v_rec.TG_Max,NULL),
               Zile_Exp       = Decode(v_rec.TipLimita,2,v_rec.Zile_Exp,NULL),
               ValMin         = v_Rec.ValMin,
               CantMin        = v_rec.CantMin,
               CODPROMO       = RECID
        WHERE  CodCadou = v_rec.CodCadou;

      ELSE
        SELECT Seq_Promo1Cadou_CodCadou.NextVal INTO vCod FROM dual;
        UPDATE TMP_PROMO1CADOUSER SET CodCadou = vCOD WHERE CodCadou = v_rec.CodCadou;

        INSERT INTO  Promo1Cadou (
          CodCadou, CodPromo1, CodObiect, UMSec, Cant,
          TipLimita, TG_Max, Zile_Exp, Codpromo, ValMin, CantMin)
        VALUES (
          vCod , v_rec.CodPromo1, v_rec.CodObiect, v_rec.UMSec, v_rec.Cant,
          v_rec.TipLimita, Decode(v_rec.TipLimita,1,v_rec.TG_Max,NULL), Decode(v_rec.TipLimita,2,v_rec.Zile_Exp,NULL), RECID, v_rec.ValMin, v_rec.CantMin);
      END IF;
    END LOOP;

    UPDATE PROMO1SER PS
    SET PS.Serie = (SELECT T.Serie FROM TMP_PROMO1SER T WHERE T.CodPromo1S = PS.CodPromo1S )
    WHERE PS.CodPromo1S IN ( SELECT T.CodPromo1S FROM TMP_PROMO1SER T WHERE Coalesce(T.CodPromo1S,0) &gt; 0);

    INSERT INTO PROMO1SER( CodPromo1S, CodPromo1, Serie)
    SELECT Seq_Promo1Ser_CodPromo1S.NextVal, CodPromo1, Serie
    FROM (
      SELECT CodPromo1, Serie
      FROM TMP_PROMO1SER
      WHERE Coalesce(CodPromo1S,0) &lt;= 0 AND Coalesce(CodPromo1,0) &gt; 0
      ORDER BY CodPromo1, IndexLocal
    );

    UPDATE PROMO1CADOUSER PCS
    SET PCS.Serie = (SELECT T.Serie FROM TMP_PROMO1CADOUSER T WHERE T.CodCadouS = PCS.CodCadouS )
    WHERE PCS.CodCadouS IN ( SELECT T.CodCadouS FROM TMP_PROMO1CADOUSER T WHERE Coalesce(T.CodCadouS,0) &gt; 0);

    INSERT INTO PROMO1CADOUSER( CodCadouS, CodCadou, Serie)
    SELECT Seq_Promo1CadouSer_CodCadouS.NextVal, CodCadou, Serie
    FROM (
      SELECT CodCadou, Serie
      FROM TMP_PROMO1CADOUSER
      WHERE Coalesce(CodCadouS,0) &lt;= 0 AND Coalesce(CodCadou,0) &gt; 0
      ORDER BY CodCadou, IndexLocal
    );
  ELSE -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;PROMO&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataStart, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT Seq_Promo_CodPromo.NextVal INTO RecId FROM DUAL;

    INSERT INTO PROMO (
      CodPromo, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd, Partener,
      Moneda, TipPromotie, TipConditie, Obs, Subunitatea, An, Luna, TipClaseP, TipServire, DeMana, ValMin, Praguri, CantMin,
      ExclAltePromo,
      OraStart, OraStop,
      UserId, DataCreare, PRETCUAMANUNT)
    SELECT
      RecId, TipDoc, Anulat, Blocat, Operat, CarnetDoc, SeriaDoc, NrDoc, DataStart, DataEnd, Partener,
      Moneda, TipPromotie, TipConditie, Obs, Subunitatea, An, Luna, TipClaseP, TipServire, DeMana, ValMin, Praguri, CantMin,
      CASE WHEN DeMana IN (3, 4) THEN ExclAltePromo ELSE 0 END ExclAltePromo,
      OraStart, OraStop,
      Pkg_Globals.UserId, SysTimeStamp, PRETCUAMANUNT
    FROM TMP_PROMO;

    INSERT INTO PROMOPART( CodPromoPart,    CodPromo, CodClaseP, Partener, CodLocatie, CodFiscal, CodPersc, Prioritar)
    SELECT Seq_PromoPart_CodPromoPart.NextVal, RecID, CodClaseP, Partener, CodLocatie, CodFiscal, CodPersc, Prioritar
    FROM TMP_PROMOPART;

    INSERT INTO PROMOSUB( CodPromoSub, CodPromo, Subunitatea)
    SELECT Seq_PromoSub_CodPromoSub.NextVal, RecID, Subunitatea
    FROM TMP_PROMOSUB;

    INSERT INTO PROMOPRAG(CodPrag, CodPromo, ValMin, ProcDisc, ValDisc, CantMin)
    SELECT SEQ_PROMOPRAG_CODPRAG.NextVal, RecID, ValMin, ProcDisc, ValDisc, CantMin
    FROM TMP_PROMOPRAG;

    FOR v_rec IN (
      SELECT
        CodPromo1, CodObiect, CodArticol, CodClaseA, CuEchivalente, UMSec,
        Cant*Coalesce(Paritate,1) Cant, CantOptim*Coalesce(Paritate,1) CantOptim, Pret/Coalesce(Paritate,1) Pret, PretAmanunt/Coalesce(Paritate,1) PretAmanunt,
        ProcDisc, ValDisc, GrupaPret, ZileC, TipLimita, ModAplic, TG_Max, Zile_Exp, ValMin, CANT_MAX*Coalesce(Paritate,1) as cant_max
      FROM TMP_Promo1
      ORDER BY IndexLocal)
    LOOP
      SELECT Seq_PROMO1_CodPromo1.NEXTVAL INTO vCod FROM dual;
      UPDATE TMP_PROMO1CADOU SET CodPromo1 = vCOD WHERE CodPromo1 = v_rec.CodPromo1;
      UPDATE TMP_PROMO1SER   SET CodPromo1 = vCOD WHERE CodPromo1 = v_rec.CodPromo1;

      INSERT INTO  Promo1 (
        CodPromo1, CodPromo, CodObiect, CodArticol, CodClaseA, CuEchivalente, UMSec, Cant, Pret, ProcDisc, ValDisc, GrupaPret, ZileC, TipLimita, ModAplic,
        TG_Max, Zile_Exp, ValMin, PretAmanunt, CantOptim, cant_max)
      VALUES (
        vCod , RecId, v_rec.CodObiect, v_rec.CodArticol, v_rec.CodClaseA, v_rec.CuEchivalente, v_rec.UMSec, v_rec.Cant, v_rec.Pret, v_rec.ProcDisc, v_rec.ValDisc, v_rec.GrupaPret, v_rec.ZileC, v_rec.TipLimita, v_rec.ModAplic,
        v_rec.TG_Max, v_rec.Zile_Exp, v_rec.ValMin, v_rec.PretAmanunt,v_rec.CantOptim, v_rec.cant_max
      );
    END LOOP;

    FOR v_rec IN (
      SELECT CodCadou, CodPromo1, CodObiect, UMSec, Cant*Paritate Cant, TipLimita, TG_Max, Zile_Exp, ValMin, CantMin*Paritate CantMin, CodPromo
      FROM TMP_Promo1Cadou
      ORDER BY CodPromo1, IndexLocal)
    LOOP
      SELECT Seq_Promo1Cadou_CodCadou.NextVal INTO vCod FROM dual;
      UPDATE TMP_PROMO1CADOUSER SET CodCadou = vCOD WHERE CodCadou = v_rec.CodCadou;

      INSERT INTO  Promo1Cadou (CodCadou, CodPromo1, CodObiect, UMSec, Cant, TipLimita, TG_Max, Zile_Exp, ValMin, CantMin, CODPROMO)
      VALUES (vCod, v_rec.CodPromo1, v_rec.CodObiect, v_rec.UMSec, v_rec.Cant, v_rec.TipLimita, v_rec.TG_Max, v_rec.Zile_Exp, v_rec.ValMin, v_rec.CantMin, RecId);
    END LOOP;

    INSERT INTO PROMO1SER( CodPromo1S, CodPromo1, Serie)
    SELECT Seq_Promo1Ser_CodPromo1S.NextVal, CodPromo1, Serie
    FROM (
      SELECT CodPromo1, Serie
      FROM TMP_PROMO1SER
      ORDER BY CodPromo1, IndexLocal
    );

    INSERT INTO PROMO1CADOUSER( CodCadouS, CodCadou, Serie)
    SELECT Seq_Promo1CadouSer_CodCadouS.NextVal, CodCadou, Serie
    FROM (
      SELECT CodCadou, Serie
      FROM TMP_PROMO1CADOUSER
      ORDER BY CodCadou, IndexLocal
    );
  END IF;
  PKG_CARNETEDOC.SOLVENUMARDOC(aCarnetDoc, aNrDoc);

  NotifyModif(Operation, RecId, &apos;PROMO&apos;);

  IF aAmPrioritar = 1 THEN
    FOR vRec IN (
      SELECT PARTENER, Coalesce(CODLOCATIE, 0) CODLOCATIE
      FROM tmp_promopart
      WHERE prioritar = 1
    ) LOOP
      UPDATE promopart pp
      SET pp.prioritar = 0
      WHERE pp.Partener = vRec.Partener
        AND (Coalesce(pp.CodLocatie, 0) = vREc.CodLocatie OR vRec.CodLocatie = 0)
        AND pp.codpromo &lt;&gt; RecId
        AND EXISTS (SELECT 1 FROM promo p WHERE p.codpromo = pp.codpromo AND p.TipPromotie = 2 AND p.DataStart &lt;= aDataEnd AND p.DataEnd &gt;= aDataStart);
    END LOOP;
  END IF;

 BEGIN
   SELECT PKG_CATEGCONST.GetValConstanta(&apos;SyncPromoRetail&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO aSyncPromoRetail FROM DUAL;
   EXCEPTION WHEN OTHERS THEN aSyncPromoRetail := &apos;0&apos;;
 END;

  IF aSyncPromoRetail = &apos;1&apos; then
    PKG_POSTRETAIL.MEMO_MODIF_PROMO_RETAIL(RECID, 0);
  END IF;  



  COMMIT;
END;

end PKG_PROMO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_PUNCTAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3D472808ACFE07478DA84788243D334443E6FC9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_PUNCTAJE IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  TMP NUMBER(20) := 0;
BEGIN
  SELECT CodPunctaj INTO Tmp
  FROM PUNCTAJE
  WHERE CodPunctaj = RecId
  FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aCodPunctaj number(20);
BEGIN
  SP_LOCKRECORD(RecId);

  DELETE PunctajValDoc WHERE CodPunctaj = RecId;
  DELETE PuncteUse     WHERE CodPunctaj = RecId;
  DELETE Punctaje      WHERE CodPunctaj = RecId;
  
  NotifyModif(2, RecId, &apos;PUNCTAJE&apos;);

  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_PUNCTAJE(CodPunctaj) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN

  INSERT INTO  TMP_PUNCTAJE (CodPunctaj, denumire, datastart, dataend, tip, casademarcat, facturare)
  SELECT CodPunctaj, denumire, datastart, dataend, tip, casademarcat, facturare
  FROM Punctaje
  WHERE CodPunctaj = RecId ;

  INSERT INTO  TMP_PunctajValDoc ( cod, CodPunctaj, LIMITAVAL, PUNCTE) 
  SELECT
    cod, CodPunctaj, limitaval, puncte 
  FROM PunctajValDoc
  WHERE CodPunctaj = RecId;

  INSERT INTO  TMP_PuncteUse (cod, CodPunctaj, puncte, valacordata)
  SELECT
    cod, CodPunctaj, puncte, valacordata 
  FROM PuncteUse
  WHERE CodPunctaj = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 vCOD      NUMBER(20);
 NR        NUMBER(20);
 IDX       NUMBER(20)  := 0;
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodPunctaj INTO RecId FROM TMP_Punctaje;

    UPDATE Punctaje
    SET (codpunctaj, denumire, datastart, dataend, tip, casademarcat, facturare) =
        (SELECT codpunctaj, denumire, datastart, dataend, tip, casademarcat, facturare FROM TMP_Punctaje)
    WHERE CodPunctaj = RecID;

    DELETE PunctajValDoc WHERE CodPunctaj = RecID AND Cod NOT IN (SELECT Cod FROM TMP_PunctajValDoc);
    DELETE PuncteUse     WHERE CodPunctaj = RecID AND Cod NOT IN (SELECT Cod FROM TMP_PuncteUse);

    FOR V_REC IN (SELECT cod, codpunctaj, LIMITAVAL, puncte FROM TMP_PunctajValDoc)
    LOOP
      IF v_rec.Cod &gt; 0 THEN
        UPDATE PunctajValDoc
        SET CodPunctaj = v_rec.CodPunctaj,
            LIMITAVAL  = v_rec.LIMITAVAL,
            Puncte     = v_rec.Puncte
        WHERE Cod = v_rec.Cod;
      ELSE
        SELECT SEQ_PunctajValDoc_Cod.NEXTVAL INTO vCod FROM DUAL;
        INSERT INTO PunctajValDoc (cod, codpunctaj, LIMITAVAL, puncte)
        VALUES (vCod, RecID, v_rec.LIMITAVAL, v_rec.Puncte);
      END IF;
    END LOOP;

    FOR V_REC IN (SELECT cod, codpunctaj, puncte, valacordata FROM TMP_PuncteUse)
    LOOP
      IF v_rec.Cod &gt; 0 THEN
        UPDATE PuncteUse
        SET Puncte      = v_rec.Puncte,
            ValAcordata = v_rec.ValAcordata
        WHERE Cod = v_rec.Cod;
      ELSE
        SELECT SEQ_PuncteUse_Cod.NEXTVAL INTO vCod FROM DUAL;
        INSERT INTO PuncteUse (cod, codpunctaj, puncte, valacordata)
        VALUES (vCod, RecID, v_rec.Puncte, v_rec.ValAcordata);
      END IF;
    END LOOP;

  ELSE  -- INSERT

    SELECT SEQ_Punctaje_CodPunctaj.NextVal INTO RecId FROM DUAL;
    INSERT INTO Punctaje (
      codpunctaj, denumire, datastart, dataend, tip, casademarcat, facturare)
    SELECT
      RecId, denumire, datastart, dataend, tip, casademarcat, facturare
    FROM TMP_Punctaje;

    INSERT INTO PunctajValDoc (cod, codpunctaj, LIMITAVAL, puncte)
    SELECT SEQ_PunctajValDoc_Cod.NEXTVAL, RecID, LIMITAVAL, puncte
    FROM TMP_PunctajValDoc;

    INSERT INTO PuncteUse (cod, codpunctaj, puncte, valacordata)
    SELECT SEQ_PuncteUse_Cod.NEXTVAL, RecID, puncte, valacordata
    FROM TMP_PuncteUse;
  END IF;
  
  NotifyModif(Operation, RecId, &apos;PUNCTAJE&apos;);

  COMMIT;
END;

PROCEDURE GET_PUNCTE_SI_VALOARE(aDATA IN VARCHAR2, aVALOARE IN NUMBER, aPUNCTE OUT NUMBER, aVALPUNCTE OUT NUMBER)
IS
  VALPUNCTE NUMBER(20, 7) := 0;
BEGIN
  aPUNCTE := 0; aVALPUNCTE := 0;
  
    FOR V_REC IN
   (
    SELECT P.CODPUNCTAJ, NVL(PUNCTE, 0) * TRUNC(aVALOARE / LIMITAVAL) AS PUNCTE
    FROM
      PUNCTAJVALDOC PV,
      PUNCTAJE P
    WHERE
      PV.CODPUNCTAJ = P.CODPUNCTAJ
      AND P.TIP = 1
      AND P.DATASTART &lt;= TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;)
      AND P.DATAEND   &gt;= TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;)
      AND PV.LIMITAVAL &lt;&gt; 0
   )
   LOOP
     IF V_REC.PUNCTE &lt;&gt; 0 THEN
       aPUNCTE := aPUNCTE + V_REC.PUNCTE;
       SELECT
         VALACORDATA * V_REC.PUNCTE / PUNCTE INTO VALPUNCTE
       FROM
         PUNCTEUSE
       WHERE
         CODPUNCTAJ = V_REC.CODPUNCTAJ
         AND NVL(PUNCTE, 0) &gt; 0
         AND ROWNUM = 1;
        aVALPUNCTE := aVALPUNCTE + VALPUNCTE;
     END IF;
   END LOOP;
   
END;    


END PKG_PUNCTAJE; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RAC_CATP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7562692C4AEB71E9E658D5682FA0CDAD32CD9FF0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RAC_CATP is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodRAC_CATP INTO Tmp FROM RAC_CATP WHERE CodRAC_CATP = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM RAC_CATP WHERE CodRAC_CATP = RecId ;
 	DELETE FROM RAC_CATP1 WHERE CodRAC_CATP = RecId ;
 	DELETE FROM RAC_CATP2 WHERE CodRAC_CATP = RecId ;
  NotifyModif(2, RecId, &apos;RAC_CATP&apos;);
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RAC_CATP FIELDS( CodRAC_CATP ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_RAC_CATP 
	(   CODRAC_CATP  ,   
			CODPARTENER  ,
			CODSEDIU     ,
			CODGEST      ,
			CODSUBUNITATE, OBS, CodContract,
			DATASTART    ,
			DATASTOP, Abonament
		)
	SELECT 
      CODRAC_CATP  ,   
			CODPARTENER  ,
			CODSEDIU     ,
			CODGEST      ,
			CODSUBUNITATE, OBS, CodContract,
			DATASTART    ,
			DATASTOP, Abonament
		
  FROM RAC_CATP WHERE CodRAC_CATP = RECID;

  INSERT INTO  TMP_RAC_CATP1 
	(   CODRAC_CATP1     ,   
			CODRAC_CATP      ,
			CODRAC_P         ,
      OBS              ,
      TIP       
		)
	SELECT 
      R.CODRAC_CATP1     ,   
			R.CODRAC_CATP      ,
			R.CODRAC_P         ,
      P.OBS              ,
      P.TIP       
	FROM 
	  RAC_CATP1 R
		inner join RAC_P P on R.CODRAC_P = P.CODRAC_P

-- 	WHERE CodRAC_CATP1 in (Select CodRAC_CATP1 from TMP_RAC_CATP1) 
-- selectu asta e facut pe TMP_RAC_CATP1 care e gol!
-- ca doar acuma tocmaqi il incarci!
	WHERE CodRAC_CATP = RecId;


  INSERT INTO  TMP_RAC_CATP2 
	(codrac_catp2, 
   codrac_catp,  
   codGest,      
   codSubunitate
  )
  Select
   codrac_catp2, 
   codrac_catp,  
   codGest,      
   codSubunitate
  FROM RAC_CATP2 where CodRac_CatP = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
Cod number(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodRAC_CATP INTO RECID FROM TMP_RAC_CATP;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE RAC_CATP
    SET
     (
      CODPARTENER  ,
			CODSEDIU     ,
			CODGEST      ,
			CODSUBUNITATE, OBS, CodContract,
			DATASTART    ,
			DATASTOP, Abonament      
			)
			= 
			(SELECT 
			CODPARTENER  ,
			CODSEDIU     ,
			CODGEST      ,
			CODSUBUNITATE, OBS, CodContract,
			DATASTART    ,
			DATASTOP, Abonament      
			FROM TMP_RAC_CATP)
    WHERE
      CodRAC_CATP = RECID;
	  
	 --RAC_CATP1
	 
--	  For V_Rec in (Select CODRAC_CATP From RAC_CATP where CODRAC_CATP=RecID and Codrac_CATP not in (Select CODRAC_CATP from TMP_RAC_CATP)) loop-
--	    DELETE FROM RAC_CATP1 where CODRAC_CATP = V_Rec.CODRAC_CATP;
--		end loop;

    DELETE FROM RAC_CATP2 where CODRAC_CATP = RecID and CodRAC_CATP2 not in (Select CODRAC_CATP2 from TMP_RAC_CATP2);
    DELETE FROM RAC_CATP1 where CODRAC_CATP = RecID and CodRAC_CATP1 not in (Select CODRAC_CATP1 from TMP_RAC_CATP1);
	
		for v_rec in (select * from TMP_RAC_CATP1) loop
      if V_Rec.Codrac_CATP1 &lt; 0 then 
--  			select SEQ_RAC_CATP1_COD.Nextval into COD from Dual;
				INSERT INTO RAC_CATP1
					( 
					  CODRAC_CATP1,
            CODRAC_CATP,      
            CODRAC_P         
					)
					Values 
--  				(	COD,
					( SEQ_RAC_CATP1_COD.Nextval,
						RecId ,
						V_REC.CODRAC_P );
	    else 
-- --------------------------------------- 
				UPDATE RAC_CATP1
				SET 
					CODRAC_P = V_REC.CODRAC_P
				WHERE CODRAC_CATP1  = v_rec.CODRAC_CATP1;
-- asta nu trebuie
--				Cod := V_Rec.CodRAC_CATP1;
	    end if;
	  end loop;
    
    
		for v_rec in (select * from TMP_RAC_CATP2) loop
      if V_Rec.Codrac_CATP2 &lt; 0 then 
--  			select SEQ_RAC_CATP1_COD.Nextval into COD from Dual;
				INSERT INTO RAC_CATP2
					( 
					  CODRAC_CATP2,
            CODRAC_CATP,      
            codGest,      
            codSubunitate        
					)
					Values 
--  				(	COD,
					( SEQ_RAC_CATP2_COD.Nextval,
						RecId ,
						V_REC.CODGEST,
            V_REC.Codsubunitate );
	    else 
-- --------------------------------------- 
				UPDATE RAC_CATP2
				SET 
					CODRAC_CatP = V_REC.CODRAC_CatP,
          CodGest = V_Rec.Codgest,          
          CodSubunitate = V_Rec.CodSubunitate          
				WHERE CODRAC_CATP2  = v_rec.CODRAC_CATP2;
-- asta nu trebuie
--				Cod := V_Rec.CodRAC_CATP1;
	    end if;
	  end loop;




ELSE  -- INSERT
    SELECT SEQ_RAC_CATP_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO RAC_CATP(
           CODRAC_CATP,  
           CODPARTENER,  
           CODSEDIU   ,  
           CODGEST    ,  
           CODSUBUNITATE, OBS, CodContract,
           DATASTART    ,      
           DATASTOP, Abonament         )
    SELECT 
      RECID   , 
      CODPARTENER,  
      CODSEDIU   ,  
      CODGEST    ,  
      CODSUBUNITATE, OBS, CodContract,
      DATASTART    ,      
      DATASTOP, Abonament         
    FROM TMP_RAC_CATP;   
    INSERT INTO RAC_CATP1 
    ( 
      CODRAC_CATP1      ,   
      codRAC_CATP       ,
      CODRAC_P         
    )
    SELECT 
      SEQ_RAC_CATP1_COD.Nextval , 
      RecId                     ,
      CODRAC_P
    FROM TMP_RAC_CATP1;

    INSERT INTO RAC_CATP2 
    ( 
      CODRAC_CATP2      ,   
      codRAC_CATP       ,
      CODGest,
      CODSubunitate         
    )
    SELECT 
      SEQ_RAC_CATP2_COD.Nextval , 
      RecId                     ,
      CODGest,
      CODSubunitate
     FROM TMP_RAC_CATP2;

  END IF; 

  NotifyModif(Operation, RecId, &apos;RAC_CATP&apos;);
  COMMIT;
 
END;


end PKG_RAC_CATP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RAC_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB61064ECC58556BD691C5BDBA0FAF243C899569</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RAC_P is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodRAC_P INTO Tmp FROM RAC_P WHERE CodRAC_P = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM RAC_P WHERE CodRAC_P = RecId ;
 	DELETE FROM RAC_P1 WHERE CodRAC_P0 in (select CodRac_P0 from Rac_P0 where CodRac_P = RecId) ;
 	DELETE FROM RAC_P0 WHERE CodRAC_P = RecId ;
  NotifyModif(2, RecId, &apos;RAC_P&apos;);
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RAC_P FIELDS( CodRAC_P ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_RAC_P 
	(   CODRAC_P      ,   
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar       
		)
	SELECT 
      CODRAC_P      ,   
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar      
	FROM RAC_P WHERE CodRAC_P = RECID;

  INSERT INTO  TMP_RAC_P0 
	(   CODRAC_P0      ,   
			codRAC_P      ,
			DATASTART       
		)
	SELECT 
      CODRAC_P0      ,   
			codRAC_P      ,
			DATASTART
             
	FROM RAC_P0 WHERE CodRAC_P = RECID;


  INSERT INTO  TMP_RAC_P1 
	(   CODRAC_P1      ,   
			codRAC_P0      ,
			codgrupa ,
			p1       ,
			p2       ,
			p3       ,
			p4       ,
			p5       ,
			P6       ,
			Fix      ,
      GARANTIE ,
			DEN_GRUPA
		)
	SELECT 
      CODRAC_P1      ,   
			codRAC_P0      ,
			codgrupa ,
			p1       ,
			p2       ,
			p3       ,
			p4       ,
			p5       ,
			P6       , 
			Fix      ,
      GARANTIE ,
			G.DENUMIRE
	FROM RAC_P1 R inner join GrEchiv G on G.CODGRECHIV = R.CodGrupa WHERE R.CodRAC_P0 in (Select CodRAC_P0 from TMP_RAC_P0);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
Cod number(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodRAC_P INTO RECID FROM TMP_RAC_P;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE RAC_P
    SET
     (
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar       
			)
			= 
			(SELECT 
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar       
			FROM TMP_RAC_P)
    WHERE
      CodRAC_P = RECID;
	  
	 --RAC_P0
	 
	  For V_Rec in (Select CODRAC_P0 From RAC_P0 where CODRAC_P=RecID and Codrac_P0 not in (Select CODRAC_P0 from TMP_RAC_P0)) loop
  	  DELETE FROM RAC_P0 where CODRAC_P0 = V_Rec.CODRAC_P0;
	    DELETE FROM RAC_P1 where CODRAC_P0 = V_Rec.CODRAC_P0;
		end loop;

	  For V_Rec in (Select CODRAC_P0 From TMP_RAC_P0 where CODRAC_P0 &gt; 0) loop
   	  DELETE FROM RAC_P1 where CODRAC_P0 = v_Rec.Codrac_P0 and CodRac_P1 not in (Select CODRAC_P1 from TMP_RAC_P1);
		end loop;


		for v_rec in (select * from TMP_RAC_P0) loop
      if V_Rec.Codrac_P0 &lt; 0 then 
  			select SEQ_RAC_P0_COD.Nextval into COD from Dual;
				INSERT INTO RAC_P0
					( 
						CODRAC_P0      ,   
						codRAC_P       ,
						DATASTART       
					)
					Values 
					( COD,
						RecId ,
						V_REC.DATASTART );
					INSERT INTO RAC_P1 
					( 
						CODRAC_P1      ,   
						codRAC_P0       ,
						codgrupa ,
						p1       ,
						p2       ,
						p3       ,
						p4       ,
						p5       ,
						P6       ,
            GARANTIE ,
            Fix       
					)
					SELECT 
						SEQ_RAC_P1_COD.Nextval , 
						Cod,
						codgrupa ,
						p1       ,
						p2       ,
						p3       ,
						p4       ,
						p5       ,
						P6       ,
            GARANTIE ,
            Fix       
					FROM TMP_RAC_P1 WHERE CodRAC_P0=V_Rec.Codrac_P0;
	    else 
-- --------------------------------------- 
				UPDATE RAC_P0
				SET 
					DATASTART = V_REC. DATASTART
				WHERE CODRAC_P0  = v_rec.CODRAC_P0;
				Cod := V_Rec.CodRAC_P0;
				-- update p1 pt P1 &gt; 0 in P0 veki
				FOR v_r IN ( SELECT * FROM TMP_RAC_P1 WHERE CODRAC_P0 = Cod and CODRAC_P1 &gt; 0) LOOP
					UPDATE RAC_P1
					SET 
						codgrupa = V_R.codgrupa,
						p1       = V_R. p1,
						p2       = V_R. p2,
						p3       = V_R. p3,
						p4       = V_R. p4,
						p5       = V_R. p5,
						P6       = V_R. P6,
            GARANTIE = V_R. GARANTIE,  
						Fix      = V_R.Fix       
					WHERE CODRAC_P1  = v_r.CODRAC_P1;
				END LOOP;
				-- insert pt inreg noi P1 in P0 veki
				FOR v_r IN ( SELECT * FROM TMP_RAC_P1 WHERE  CODRAC_P0 = Cod and CODRAC_P1 &lt; 0) LOOP
					INSERT INTO RAC_P1 
					( 
						CODRAC_P1      ,   
						codRAC_P0       ,
						codgrupa ,
						p1       ,
						p2       ,
						p3       ,
						p4       ,
						p5       ,
						P6       ,
            GARANTIE ,
            Fix       
					)
					Values
					(
						SEQ_RAC_P1_COD.Nextval , 
						Cod,
						v_r.codgrupa ,
						v_r.p1       ,
						v_r.p2       ,
						v_r.p3       ,
						v_r.p4       ,
						v_r.p5       ,
						v_r.P6       ,
            v_r.GARANTIE , 
						v_r.Fix       
					);
				end loop;
-- --------------------------------------- 
	  end if;
	end loop;
ELSE  -- INSERT
    SELECT SEQ_RAC_P_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO RAC_P(
      CODRAC_P,   
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar       
		)
    SELECT 
  		RECID   , 
			obs     ,
			tip     ,
			Moneda, ValFixa  ,
			i1      ,
			i2      ,
			i3      ,
			i4      ,
			i5      ,
			i6      ,
      liniar    
		FROM TMP_RAC_P;   

		
		for v_rec in (select * from TMP_RAC_P0) loop
			select SEQ_RAC_P0_COD.Nextval into COD from Dual;
			INSERT INTO RAC_P0
				( 
					CODRAC_P0      ,   
					codRAC_P       ,
					DATASTART       
				)
				Values 
				( COD,
					RecId ,
					V_REC.DATASTART );
				INSERT INTO RAC_P1 
				( 
					CODRAC_P1      ,   
					codRAC_P0       ,
					codgrupa ,
					p1       ,
					p2       ,
					p3       ,
					p4       ,
					p5       ,
					P6       , 
          GARANTIE ,
          Fix       
				)
				SELECT 
					SEQ_RAC_P1_COD.Nextval , 
					Cod,
					codgrupa ,
					p1       ,
					p2       ,
					p3       ,
					p4       ,
					p5       ,
					P6       ,
          GARANTIE , 
					Fix       
				FROM TMP_RAC_P1 WHERE CodRAC_P0=V_Rec.Codrac_P0;
		end loop;
		
  END IF; 

  NotifyModif(Operation, RecId, &apos;RAC_P&apos;);
  COMMIT;
 
END;


end PKG_RAC_P; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RAC_REZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CE1D853E448961B9C287AFEF0C7DF12E2AC5BF8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RAC_REZ is
CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_14&apos;;

function RAC_DATACuOra return Number is
begin
	Return IsDataCuOra;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodRAC_REZ INTO Tmp FROM RAC_REZ WHERE CodRAC_REZ = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM RAC_REZ WHERE CodRAC_REZ = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RAC_REZ FIELDS( CodRAC_REZ ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_RAC_REZ 
	(   CODRAC_REZ      ,   
  		CodComanda      ,
			Telefon
		)
	SELECT 
      CODRAC_REZ      ,   
  		CodComanda      ,
			Telefon

	FROM RAC_REZ WHERE CodRAC_REZ = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodRAC_REZ INTO RECID FROM TMP_RAC_REZ;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE RAC_REZ
    SET
     (
  		CodComanda      ,
			Telefon
			)
			= 
			(SELECT 
  		CodComanda      ,
			Telefon
			FROM TMP_RAC_REZ)
    WHERE
      CodRAC_REZ = RECID;
  ELSE  -- INSERT
    SELECT SEQ_RAC_REZ_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO RAC_REZ(
		CodRAC_REZ      , 
		CodComanda      ,
		CodTIPASIG      
		)
    SELECT 
		RECID           , 
		CodComanda      ,
		CodTIPASIG      
		FROM TMP_RAC_REZ;
  END IF; 

  NotifyModif(Operation, RecId, &apos;RAC_REZ&apos;);
  COMMIT;
 
END;

function RAC_Libere (aCodComanda in number, aCodComanda1 in number, aCodObiect in number, Zi1 in VarChar2, Zi2 in VarChar2) return RAC_CURSOR is
crs RAC_CURSOR;
aInd number(20);
GrupaAuto number;
begin
  GrupaAuto := PKG_RAC_REZ.IndexGrupaAuto;
  begin
    Select Nvl(G.Ind, 0) into aInd from NEchiv E  inner join GrEchiv  G  on G.CODGRECHIV = E.CodGrupa 
    where E.Codobiect = aCodObiect;
  EXCEPTION when others THEN 
    aInd := 0;
  end;
  IF aInd = GrupaAuto THEN 
		begin
    PKG_RAC_REZ.Init_Tmp_V_Auto(zi1);
    open crs for
    with
		Masini as
        (
         select X.CodGest, Nvl(E.CodGrupa, 0) CodGrupa, Sum(X.Q) Total 
         from TMP_V_AUTO X
         inner join NParcAut P on P.Codnparcaut = X.CodAuto
         left join NEchiv  E  on E.Codobiect = P.CodArt
         where x.Q &lt;&gt; 0
        group by X.CodGest, Nvl(E.CodGrupa, 0)
        ),
  ------------------------------------------------------------------------------------------------------------------
    ComenziRAC as
        (select c.codcomanda, R.CodGestSursa CodGestTransf, --Nvl(C.CodGest, 0) CodGestTransf, 
                R.CodGestSursa, R.TipRezervare, NVL(C.MijlTransp,0) CodAuto
         from Comanda c 
         left  join NGest   G2 on G2.CodGest = C.CodGest
         inner join RAC_REZ  R  on R.codcomanda = c.codcomanda
         where c.codcomanda &gt; 0 and c.tipdoc = 94 
           and C.CodComanda &lt;&gt; aCodComanda 
           and Nvl(C.Operat, 0) = 1
           and Nvl(R.Predat, 0) = 0
           and Nvl(R.CodPartExt,0) = 0
           and 
           (
           ( TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) between R.DataStart and R.DataStop)
           or 
           ( TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;) between R.DataStart and R.DataStop)
           or 
           ( R.DataStart between TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) and TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;))
           or 
           ( R.DataStop between TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) and TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;)))),
  ------------------------------------------------------------------------------------------------------------------
    Rezervari as
        (
        Select x.CodGestTransf, x.CodGestSursa, x.CodGrupa, 
               Nvl(M1.Total,0) TotalS, Nvl(M2.Total,0) TotalT, Sum(x.Ocupate) Ocupate
        from(
            select CodGestTransf, CodGestSursa, E.CodGrupa, C1.Cantacceptat Ocupate
            from comanda1 c1
            inner join comenzirac c on c.codcomanda  = c1.codcomanda
                   inner join NEchiv  E on E.Codobiect   = c1.CodObiect
            where C.CodAuto = 0 and (not(C.TipRezervare in (1,6))) and C1.CANTACCEPTAT = 1
            union all
            select 
               CodGestTransf, CodGestSursa, E.CodGrupa,  1 Ocupate
            from comenzirac c 
                 inner join NParcAut p on p.CodNparcAut   = c.CodAuto
                 inner join NEchiv  E on E.Codobiect   = p.CodArt
            where C.CodAuto &gt; 0-- and C.TipRezervare in (1,6)
            ) X
            left  join Masini  M1 on M1.CodGrupa = x.CodGrupa and M1.CodGest = Nvl(x.CodGestSursa,0) 
            left  join Masini  M2 on M2.CodGrupa = x.CodGrupa and M2.CodGest = Nvl(x.CodGestTransf,0) 
        group by x.CodGestTransf, x.CodGestSursa, x.CodGrupa, Nvl(M1.Total,0), Nvl(M2.Total,0))
  --Finally!----------------------------------------------------------------------------------------------------------------
        select aCodComanda1 as CodComanda1, 
               TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) DataStart, 
               TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;) DataStop, 
               NG.CodSubunit, X.CodGest, X.CodGrupa, 
               X.Total, Nvl(X.Ocupate,0) Ocupate, 
               X.Total - Nvl(X.Ocupate,0) Libere, 
               S.Den_Subunit, NG.Den_Gest, G.DENUMIRE DenClasa
        from
        (
         Select CodGest, CodGrupa, Total, Sum(Ocupate) Ocupate 
         from
         ( 
           select CodGest, CodGrupa, Total, 0 Ocupate from Masini 
           union all
           select CodGestSursa CodGest, CodGrupa, TotalS Total, Ocupate from REZERVARI
           union all
           select CodGestTransf CodGest, CodGrupa,TotalT Total, Ocupate from REZERVARI where CodGestTransf &lt;&gt; 0
           union all
           select CodGestSursa CodGest, CodGrupa, TotalS Total, -Ocupate from REZERVARI where CodGestTransf &lt;&gt; 0
         ) group by CodGest, CodGrupa, Total
        ) X 
        inner join GrEchiv G on G.CODGRECHIV = X.CodGrupa
        inner join NGest NG on NG.CodGest = X.CodGest
        inner join NSubunit S on s.CodSubunit = NG.CodSubunit
        where Nvl(G.Ind,0) = aInd;
    EXCEPTION when others THEN
      open crs for select -1 CodCfg from dual;
    end;
  ELSE -- cand nu e GrupaAuto
    begin
      open crs for
        with Masini as
        (select NG.CodGest, E.CodGrupa, Sum(NS.Rest) Total
           from nirstoc ns
           inner join Nir     N  on N.CodNir = NS.CodNir
           inner join NGest   NG on N.Gest = NG.CodGest
           inner join NEchiv  E  on E.Codobiect = ns.CodObiect
           inner join GrEchiv GrE  on GrE.CODGRECHIV = E.CodGrupa 
           where Nvl(GrE.Ind,0) = aInd
           group by NG.CodGest, E.CodGrupa),
        ComenziRAC as
        (select c.codcomanda, Nvl(C.CodGest, 0) CodGestTransf, 
                R.CodGestSursa, R.TipRezervare, NVL(C.MijlTransp,0) CodAuto
         from Comanda c 
         left  join NGest   G2 on G2.CodGest = C.CodGest
         inner join RAC_REZ  R  on R.codcomanda = c.codcomanda
         where c.codcomanda &gt; 0 and c.tipdoc = 94 
           and C.CodComanda &lt;&gt; aCodComanda 
           and Nvl(C.Operat, 0) = 1
           and Nvl(R.Predat, 0) = 0
					 and Nvl(R.CodPartExt,0) = 0
					 and 
					 (
					 ( TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) between R.DataStart and R.DataStop)
					 or 
					 ( TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;) between R.DataStart and R.DataStop)
					 or 
					 ( R.DataStart between TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) and TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;))
					 or 
					 ( R.DataStop between TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) and TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;)))),
				Rezervari as
				(
				Select x.CodGestTransf, x.CodGestSursa, x.CodGrupa, 
							 Nvl(M1.Total,0) TotalS, Nvl(M2.Total,0) TotalT, Sum(x.Ocupate) Ocupate
				from(
						select CodGestTransf, CodGestSursa, E.CodGrupa, C1.Cantacceptat Ocupate
						from comanda1 c1
						inner join comenzirac c on c.codcomanda  = c1.codcomanda
									 inner join NEchiv  E on E.Codobiect   = c1.CodObiect
						where not(C.TipRezervare in (1,8))
						union all
						select 
							 CodGestTransf, CodGestSursa, E.CodGrupa,  1 Ocupate
						from comenzirac c 
								 inner join NParcAut p on p.CodNparcAut   = c.CodAuto
								 inner join NEchiv  E on E.Codobiect   = p.CodArt
						where C.CodAuto &gt; 0 and C.TipRezervare in (1,8)
						) X
						left  join Masini  M1 on M1.CodGrupa = x.CodGrupa and M1.CodGest = Nvl(x.CodGestSursa,0) 
						left  join Masini  M2 on M2.CodGrupa = x.CodGrupa and M2.CodGest = Nvl(x.CodGestTransf,0) 
				group by x.CodGestTransf, x.CodGestSursa, x.CodGrupa, Nvl(M1.Total,0), Nvl(M2.Total,0))
				select aCodComanda1 as CodComanda1, 
							 TO_DATE(Zi1, &apos;DD.MM.YYYY hh24:mi&apos;) DataStart, 
							 TO_DATE(Zi2, &apos;DD.MM.YYYY hh24:mi&apos;) DataStop, 
							 NG.CodSubunit, X.CodGest, X.CodGrupa, 
							 X.Total, Nvl(X.Ocupate,0) Ocupate, 
							 X.Total - Nvl(X.Ocupate,0) Libere, 
							 S.Den_Subunit, NG.Den_Gest, G.DENUMIRE DenClasa
				from
				(
				 Select CodGest, CodGrupa, Total, Sum(Ocupate) Ocupate 
				 from
				 ( 
					 select CodGest, CodGrupa, Total, 0 Ocupate from Masini 
					 union all
					 select CodGestSursa CodGest, CodGrupa, TotalS Total, Ocupate from REZERVARI
					 union all
					 select CodGestTransf CodGest, CodGrupa,TotalT Total, Ocupate from REZERVARI where CodGestTransf &lt;&gt; 0
					 union all
					 select CodGestSursa CodGest, CodGrupa, TotalS Total, -Ocupate from REZERVARI where CodGestTransf &lt;&gt; 0
				 ) group by CodGest, CodGrupa, Total
				) X 
				inner join GrEchiv G on G.CODGRECHIV = X.CodGrupa
				inner join NGest NG on NG.CodGest = X.CodGest
				inner join NSubunit S on s.CodSubunit = NG.CodSubunit
				where Nvl(G.Ind,0) = aInd;
		EXCEPTION when others THEN
			open crs for select -1 CodCfg from dual;
		end;
	END IF;
  return crs;
end;

function RAC_Ocupate (aCodComanda in number, aCodComanda1 in number, aCodObiect in number, Zi in VarChar2, aTip in number) return RAC_CURSOR1 is
crs RAC_CURSOR1;
aInd number(20);
begin
  begin
		Select Nvl(G.Ind, 0) into aInd
		from NEchiv E  
		inner join GrEchiv  G  on G.CODGRECHIV = E.CodGrupa 
		where E.Codobiect = aCodObiect;
  EXCEPTION when others THEN
    aInd := 0;
  end;
  begin
    open crs for
			select aCodComanda1 as CodComanda1, C.Seriadoc||C.Nrdoc||&apos;/&apos;||C.Datadoc Cmd, 
			       C1.CANTACCEPTAT Ocupate, R.DataStart, R.DataStop, 
						 TO_DATE(Zi, &apos;DD.MM.YYYY hh24:mi&apos;) Ziua,
						 S1.CodSubunit CodSubunitPrel, 
						 S2.CodSubunit CodSubunitLivr, 
						 S1.Den_Subunit SubunitPrel, S2.Den_Subunit SubunitLivr,  
						 G1.Den_Gest GestPrel, G2.Den_Gest GestLivr,  
						 G1.CodGest CodGestPrel, G2.CodGest CodGestLivr,  
						 G.DENUMIRE DenClasa
  		from comanda1 c1
			 inner join Comanda  c  on c.codcomanda = c1.codcomanda
			 inner join RAC_REZ  R  on R.codcomanda = c.codcomanda
			 inner join NGest G1 on G1.codGest = Nvl(R.CodGestSursa,0)
			 inner join NGest G2 on G2.codGest = Nvl(R.CodGestDest,0)
			 inner join Nsubunit S1 on S1.codSubunit = G1.CodSubunit
			 inner join Nsubunit S2 on S2.codSubunit = G2.CodSubunit
			 inner join NEchiv   E  on E.Codobiect = c1.CodObiect-- and E.GENERIC = 1
    	 inner join GrEchiv  G  on G.CODGRECHIV = E.CodGrupa 
			 where c.codcomanda &gt; 0 and c.Operat = 1 and c.tipdoc = 94 and Nvl(G.Ind,0) = aInd
			   and C.CodComanda &lt;&gt; aCodComanda 
--				 and Nvl(C.Operat, 0) = 1
				 and Nvl(R.Predat, 0) = 0
				 and 
				 ((aTip = 0 and Trunc(TO_DATE(Zi, &apos;DD.MM.YYYY hh24:mi&apos;)) = Trunc(R.DataStart)) 
				  or 
					(aTip = 1 and Trunc(TO_DATE(Zi, &apos;DD.MM.YYYY hh24:mi&apos;)) = Trunc(R.DataStop))
				 );
  EXCEPTION when others THEN
    open crs for select -1 CodCfg from dual;
  end;
  return crs;
end;

function IndexGrupaAuto return Number is
begin
  Return 1;
end;
	

Procedure Init_Tmp_V_Auto (Zi1 in VarChar2) is
begin
	pkg_rac_rez.SET_RAC_DATASTART(Zi1);
	delete TMP_V_Auto;
	insert into TMP_V_Auto 
	select * from (select CodAuto, CodGest, CodClasa, Q, DATASTART, DATASTOP from V_AUTO);
end;

PROCEDURE SET_RAC_DATASTART(aData in varchar2, DoTMP in integer Default 0)
IS
IndGrupa number;
BEGIN
  DATAPORNIRE := TO_DATE(aData, &apos;DD.MM.YYYY hh24:mi&apos;);
	IsDataCuOra := 1;
	if DataPornire = Trunc(DataPornire) then 
		IsDataCuOra:= 0; 
	end if;
	IndGrupa := PKG_RAC_REZ.IndexGrupaAuto;
	if DoTmp = 1 then 
		delete TMP_V_RAC_CARS;
		insert into TMP_V_RAC_CARS 
		select A.CodAuto, S.Den_Subunit Subunitate, G.Den_Gest Gestiune, A.Clasa, A.NrAuto, A.Marca, 
					 A.Model, A.Inactiv, A.CodGest, G.CODCLASA, A.CodGrEchiv, A.AnF, A.Data
		FROM V_RAC_CARS A 
		 inner join NGest G on G.codGest = A.CodGest-- and G.Tip = 7
		 inner join Nsubunit S on S.codSubunit = G.CodSubunit
		where A.Extern = 0 and A.Generic = 0 and A.CodGest &gt; 0 and Ind = IndGrupa;
	end if;
END;

FUNCTION RAC_DATASTART  RETURN DATE IS 
BEGIN 
  RETURN  DATAPORNIRE; 
END;

PROCEDURE CloneREZ(aCod in number)
IS 
  RECID Number;
  vCod             NUMBER(20);
  aMIJLTRANSP      NUMBER(20);
	aCodSubunit      NUMBER(20);
  aDataDoc         DATE;
  aDataStop        DATE;
  aDataStart       DATE;
  aDoc             VARCHAR2(200);
	aValoare         Number(20,7);
	aKmIn            Number(20,7);
	aCombIn          Number(20,7);
  aDataIn          DATE;
	aAn              Number(4);
	aLuna            Number(4);
	aAn0             Number(4);
	aLuna0           Number(4);
	aZile            Number(4);
	aTipUM           number(1); 
	aTipUM1          number(1); 
	aZecimale        number(4); 
	aCoef            NUMBER(20,5);
	aPret            NUMBER(20,5);
	aVal             NUMBER(20,5);
  aUM1             NUMBER(20);
	aCodRAC          NUMBER(20);
	aDataFact        Date;
	aFactLunara      Number(1);
	avalsofercm      NUMBER(20,5);
	avalsoferf       NUMBER(20,5);
	avalclientcm     NUMBER(20,5);
	avalclientf      NUMBER(20,5);
	aCantCM          NUMBER(20,5);
	Clone            Number;
	CloneIndex       Number;
  aCodArticol      Number(20);
  Cod0             Number(20);
	aProcTVA         Number(20,5);
	 
begin
		Select Count(*) into Clone from Rac_REZ where CodREZERVARE = aCod;
    if Clone = 0 then
		  Delete comanda  where CodComanda = -aCod;
		  Delete comanda1 where CodComanda = -aCod;
		  Delete Rac_rez  where CodComanda = -aCod;
			INSERT INTO COMANDA (
				CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PARTENER, CODGEST, SUBUNITSURSA,
				CARNETDOC, PREFIXDOC, NRDOC, SERIADOC, 
				DATADOC, AN, LUNA, OBS, 
				SCADENTAV, INCHISA, VALOARE, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
				VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, userid,datacreare, DISPLIVRARE,Verificat, Facturabil, Curs, FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
				FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS)
			SELECT
				-CODCOMANDA, -TIPDOC, ANULAT, BLOCAT, OPERAT, PARTENER, CODGEST, SUBUNITSURSA,
				0, PREFIXDOC, NRDOC, SERIADOC, 
				DATADOC, AN, LUNA, OBS, 
				SCADENTAV, INCHISA, VALOARE, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
				VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, userid,datacreare, DISPLIVRARE,Verificat, Facturabil, Curs, FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
				FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS
			FROM COMANDA where CodComanda = aCod;
 
			INSERT INTO RAC_REZ(
  			CodRAC_REZ      ,
				CodComanda      ,
				TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, 
				CodGestSursa, CodGestDest    ,
				NR_REF          ,
				CodCOMISIONAR   ,
				CodSediuComis   , 
				CODREZERVARE    ,
				CodLocalit_Prel ,
				ADRESA_PREL     ,
				CodLocalit_Livr ,
				ADRESA_LIVR     ,
				NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
				CodContr_PRELIVR,
				FactLunara      ,
				SUMAGARANTIE    ,
				NUME_CARD       ,
				EXPIRA_CARD     ,
				CODCCV          ,
				OBS_Contract    ,
				CodTIPASIG      ,
				Email           ,
				codinterventie  ,
				kmin            ,
				kmout           ,
				combin          ,
				combout         ,
				kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
				CodSofer        ,
				CODSOFER1       ,
				CODSOFER2       ,
				FARATVA         , 
				Telefon         ,
        SursaClient
			)
			SELECT
  			-CodRAC_REZ     ,
				-CodComanda     ,
				TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, 
				CodGestSursa, CodGestDest    ,
				NR_REF          ,
				CodCOMISIONAR   ,
				CodSediuComis   , 
				CODREZERVARE    ,
				CodLocalit_Prel ,
				ADRESA_PREL     ,
				CodLocalit_Livr ,
				ADRESA_LIVR     ,
				NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
				CodContr_PRELIVR,
				FactLunara      ,
				SUMAGARANTIE    ,
				NUME_CARD       ,
				EXPIRA_CARD     ,
				CODCCV          ,
				OBS_Contract    ,
				CodTIPASIG      ,
				Email           ,
				codinterventie  ,
				0               ,
				kmin            ,
				0               ,
				combin          ,
				kmnextrev       ,
        valsofercm      ,
        valsoferf       ,
        valclientcm     ,
        valclientf      ,
				CodSofer        ,
				CODSOFER1       ,
				CODSOFER2       ,
				FARATVA         , 
				Telefon         ,
        SursaClient
			FROM RAC_REZ where CodComanda = aCod;

				INSERT INTO COMANDA1 (
					CODCOMANDA1,CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,PU, CANTCOMANDAT,
					CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
					CULANSARE, UMCorelat, PUCorelat, CODCADOU, RESTLANSAT, 
					DataStart, TERMEN, 
					ANULAT, ADDIM,prioritate, 
					PROCDISC, OBS, PRETORIG, COEFDISCMAJ, CODCATPRET, SCADENTA, CONSUM,
					REZERVATINI, D1, D2, D3, TipSursa, CodSursa, CantUM1, AcceptUM1,
					TIPPLATA, CADOU, CADOULINK, PRETPROMO, CoefIndirecte, codreteta, Codproiect, TipLivrare, CODANALIZANOD, nivel, pozitie, EXCEPTIONAL, TAXA, CODCONTRACT1,
					CODOFERTA1 ,PRETUM1, GESTACT, CODCENTRU, CODNORMA, MODINCHIDERE, TERMENCONTRACT, CODMIFIX, TipLinieSA )
        Select 
					-CODCOMANDA1,-CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,PU, CANTCOMANDAT,
					CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
					CULANSARE, UMCorelat, PUCorelat, CODCADOU, RESTLANSAT, 
					DataStart, TERMEN, 
					ANULAT, ADDIM,prioritate, 
					PROCDISC, OBS, PRETORIG, COEFDISCMAJ, CODCATPRET, SCADENTA, CONSUM,
					REZERVATINI, D1, D2, D3, TipSursa, CodSursa, CantUM1, AcceptUM1,
					TIPPLATA, CADOU, CADOULINK, PRETPROMO, CoefIndirecte, codreteta, Codproiect, TipLivrare, CODANALIZANOD, nivel, pozitie, EXCEPTIONAL, TAXA, CODCONTRACT1,
					CODOFERTA1 ,PRETUM1, GESTACT, CODCENTRU, CODNORMA, MODINCHIDERE, TERMENCONTRACT, CODMIFIX, TipLinieSA 
					from Comanda1 where CodComanda = aCod;
		end if;
		
--		insert into X(View_name) values(aCod);	commit;
		SELECT
			SUBUNITATEA, DATADOC, &apos;CLONA &apos;||PREFIXDOC||NRDOC||&apos;/&apos;||DATADOC,
      VALOARE, An,Luna, MIJLTRANSP
		  INTO
			aCodSubunit, aDATADOC, aDoc, 
			aValoare, aAn, aLUNA, aMIJLTRANSP 
		FROM COMANDA where CodComanda = aCod;
		aLuna0 := aLuna;
		aAn0 := aAn;
    if aLuna = 12 then aLuna := 1; aAn := aAn + 1; else aLuna := aLuna + 1; end if;

    SELECT seq_COMANDA_CodComanda.NextVal INTO RecId FROM DUAL;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;COMANDA&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, SysDate, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

		SELECT
			DATAStop,
			DATAStart,
			DataFact, 
			KmIn,
			CombIn,
			Nvl(FactLunara,0) FactLunara
		  INTO
			aDATAStop,
			aDATAStart,
			aDataFact, 
			aKmIn,
			aCombIn,
			aFactLunara
		FROM RAC_REZ where CodComanda = aCod;
    
		
--		aDataDoc := trunc(ADD_MONTHS(aDataStart,1),&apos;month&apos;) + 0.00001; 
		aDataDoc := PKG_RAC_REZ.RAC_DATASTART; 

    BEGIN
  		Select Nvl(LOT,0) into CloneIndex from Comanda where CodComanda = aCod;
      EXCEPTION WHEN OTHERS THEN CloneIndex := 0;
    END;

    INSERT INTO COMANDA (
      CODCOMANDA, TIPDOC, ANULAT, BLOCAT, OPERAT, PARTENER, CODGEST, SUBUNITSURSA,
      CARNETDOC, PREFIXDOC, NRDOC, SERIADOC, 
			DATADOC, AN, LUNA, OBS, 
			SCADENTAV, INCHISA, VALOARE, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
      VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, userid,datacreare, DISPLIVRARE,Verificat, Facturabil, Curs, FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
      FACTURA_APL_EXT, CODPERS_APL_EXT, LOT, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS)
    SELECT
      RecId, TIPDOC, ANULAT, BLOCAT, OPERAT, PARTENER, CODGEST, SUBUNITSURSA,
			0, PREFIXDOC, NRDOC, SERIADOC, 
			aDATADOC, Extract(Year from aDataDoc), Extract(Month from aDataDoc), OBS, 
			SCADENTAV, INCHISA, VALOARE, MONEDA, CODCONTRACT, CODCMDPARINTE, DELEGAT, CODTRASEULIVR, ORDINELIVRARE, INSOTITOR, MIJLTRANSP,AGENT,
      VALDISCOUNT, CODLOCATIE, SUBUNITATEA, CODFISCAL, NRI, PKG_GLOBALS.USERID,SYSTIMESTAMP, DISPLIVRARE,Verificat, Facturabil, NVL(Curs, 1), 
			FARATRANSPORT, PLATAPELOC, CODIES,SCHIMB,CODFORMATIE, IDIMPORT,
      FACTURA_APL_EXT, CODPERS_APL_EXT, CloneIndex+1, NRTRANSP, CODIESAVANS, FARAFACTURA, DINONLINE, PRETCUAMANUNT,CODANALIZA, TIPTRANZACTIE, SUBUNITDEST, NRMAXAPROBARI, STADIUWMS
    FROM COMANDA where CodComanda = aCod;

    aCodRAC := SEQ_RAC_REZ_COD.NextVal;
		aDataFact := ADD_MONTHS(aDataFact,1); 
		INSERT INTO RAC_REZ(
		CodRAC_REZ      ,
			CodComanda      ,
			TipRezervare, DataStart, DataStop, CodDelegat1, CodDelegat2, CodGestSursa, CodGestDest    ,
			NR_REF          ,
			CodCOMISIONAR   ,
			CodSediuComis, 
			CODREZERVARE   ,
			CodLocalit_Prel ,
			ADRESA_PREL     ,
			CodLocalit_Livr ,
			ADRESA_LIVR     ,
			NR_ZBOR, codmodel, codmarca, DataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
			CodContr_PRELIVR,
			FactLunara     ,
			SUMAGARANTIE    ,
			NUME_CARD       ,
			EXPIRA_CARD     ,
			CODCCV          ,
			OBS_Contract    ,
			CodTIPASIG      ,
			Email           ,
			codinterventie  ,
			kmin            ,
			kmout           ,
			combin          ,
			combout         ,
			kmnextrev       ,
			valsofercm      ,
			valsoferf       ,
			valclientcm     ,
			valclientf      ,
			CodSofer        ,
			CODSOFER1        ,
			CODSOFER2        ,
			FARATVA         , 
			Telefon         ,
      SursaClient
		)
		SELECT
		aCodRAC,
		RECID           ,
			TipRezervare, 
			aDatadoc, 
			DataStop, 
			CodDelegat1, CodDelegat2, CodGestDest, CodGestDest    ,
			NR_REF          ,
			CodCOMISIONAR   ,
			CodSediuComis, 
			aCod            ,
			CodLocalit_Livr ,
			ADRESA_LIVR     ,
			CodLocalit_Livr ,
			ADRESA_LIVR     ,
			NR_ZBOR, codmodel, codmarca, aDataFact, datapred, Predat, CodVoucher, codpartext, ProcCedat         ,
			CodContr_PRELIVR,
			FactLunara     ,
			SUMAGARANTIE    ,
			NUME_CARD       ,
			EXPIRA_CARD     ,
			CODCCV          ,
			OBS_Contract    ,
			CodTIPASIG      ,
			Email           ,
			codinterventie  ,
			0               ,
  		aKmIn           ,  --km de sosire de la inreg clonata
			0               ,
			combout         ,
			kmnextrev       ,
			valsofercm      ,
			valsoferf       ,
			valclientcm     ,
			valclientf      ,
			CodSofer        ,
			CODSOFER1        ,
			CODSOFER2        ,
			FARATVA         , 
			Telefon         ,
      SursaClient
		FROM RAC_REZ where CodComanda = aCod;

    aDataStop := PKG_RAC_REZ.RAC_DATASTART - 0.000001;
		BEGIN
  		select CodNParc0 into Cod0 from NParc0 where CODCMD = aCod;
		EXCEPTION WHEN OTHERS THEN Cod0 := 0;
		END;
		if Cod0 = 0 then 
      INSERT INTO NPARC0 (CODNPARC0, CODNPARCAUT, CodCMD, DATABORD, KMBORD, COMB, AN, LUNA, OBS) 
			Values( seq_NPARC0_CodNParc0.Nextval, aMIJLTRANSP, aCod, aDataStop, aKmIn, aCombIn, aAn0, aLuna0, aDoc );
		else
  		update NParc0 set DataBord  =  aDataStop where CodNParc0 = Cod0;
		end if;
		update RAC_REZ     set DataStop =  aDataStop, DataPred =  aDataStop, Predat = 1, CodCCV = 1 where CodComanda = aCod;
		update TMP_RAC_REZ set DataStop =  aDataStop, DataPred =  aDataStop, Predat = 1, CodCCV = 1 where CodComanda = aCod;

	  avalsofercm      := 0;
	  avalsoferf       := 0;
	  avalclientcm     := 0;
	  avalclientf      := 0;
    FOR V_REC IN (SELECT * FROM COMANDA1 where CodComanda = aCod)
    LOOP
			SELECT seq_COMANDA1_CodComanda1.Nextval INTO VCOD FROM DUAL;
			BEGIN
				Select Nvl(e1.Cant,0) into aCantCM from Emulare1 e1 inner join Emulare e on e.CodEmulare = e1.CodEmulare
												where Nvl(e.CODMONETAR,0) = 0 and e1.Codcomanda1 = v_rec.codcomanda1;
				EXCEPTION WHEN OTHERS THEN aCantCM := 0;
			END;
      INSERT INTO COMANDA1 (
        CODCOMANDA1,CODCOMANDA, INDEXLOCAL, CODOBIECT, UMSEC,PU, 
				CANTCOMANDAT,CANTACCEPTAT, RESTACCEPTAT, CANTRETURNAT,
        CULANSARE, UMCorelat, PUCorelat, CODCADOU, RESTLANSAT, 
				DataStart, TERMEN, 
				ANULAT, ADDIM,prioritate, 
        PROCDISC, OBS, PRETORIG, COEFDISCMAJ, CODCATPRET, SCADENTA, CONSUM,
        REZERVATINI, D1, D2, D3, TipSursa, CodSursa, CantUM1, AcceptUM1,
        TIPPLATA, CADOU, CADOULINK, PRETPROMO, CoefIndirecte, codreteta, Codproiect, TipLivrare, CODANALIZANOD, nivel, pozitie, EXCEPTIONAL, TAXA, CODCONTRACT1,
        CODOFERTA1 ,PRETUM1, GESTACT, CODCENTRU, CODNORMA, MODINCHIDERE, TERMENCONTRACT, CODMIFIX, TipLinieSA )
      VALUES(
        vCod,  RecID, v_rec.INDEXLOCAL, v_rec.CODOBIECT, v_rec.UMSEC, v_rec.PU,
        v_rec.CANTCOMANDAT, v_rec.CANTACCEPTAT, v_rec.RESTACCEPTAT - aCantCM, v_rec.CANTRETURNAT ,
        v_rec.CULANSARE, v_rec.UMCorelat, v_rec.PUCorelat, V_REC.CODCADOU, v_rec.CANTACCEPTAT, 
				aDataDoc, v_rec.TERMEN, 
				v_rec.ANULAT, V_REC.ADDIM,v_rec.prioritate, 
        V_REC.PROCDISC, V_REC.OBS, V_REC.PRETORIG, V_REC.COEFDISCMAJ, V_REC.CODCATPRET,   V_REC.SCADENTA, V_REC.CONSUM,
        v_rec.REZERVATINI, v_rec.D1, v_rec.D2, v_rec.D3, v_rec.tipSursa, v_rec.CodSursa, v_rec.CantUM1, V_REC.AcceptUM1,
        V_REC.TIPPLATA, V_REC.CADOU, V_REC.CADOULINK,  V_REC.PRETPROMO, v_rec.CoefIndirecte, v_rec.codreteta, v_rec.Codproiect, v_rec.TipLivrare, V_REC.CODANALIZANOD, v_rec.nivel, v_rec.pozitie,
        v_rec.EXCEPTIONAL, V_REC.TAXA, V_REC.CODCONTRACT1, V_REC.CODOFERTA1, V_REC.PRETUM1, V_REC.GESTACT, V_REC.CODCENTRU, V_REC.CODNORMA, V_REC.MODINCHIDERE, V_REC.TERMENCONTRACT,
        V_REC.CODMIFIX, V_REC.TipLinieSA
      );

			Select Nvl(TipUM,0), Nvl(u.Zecimale,0), Nvl(u.Coef,1) into aTipUM, aZecimale, aCoef 
			from NUM1 u1, num u 
			where u1.Codum1 = v_rec.umsec and u.codum = u1.codum;
      if aTipUM = 6 then 
    		aZile := Round(v_rec.TERMEN - aDataDoc,0);

  			update COMANDA1 --comanda noua
					set Cantacceptat = aZile 
				where CodComanda1 = vCod;

			  aZile := v_rec.Cantacceptat - aZile;
				update COMANDA1 --comanda veke
					set Cantacceptat = aZile 
				where CodComanda1  = v_rec.CodComanda1;
				update TMP_COMANDA1 --comanda veke
					set Cantacceptat = aZile 
				where CodComanda1  = v_rec.CodComanda1;
      else
  			aTipUM := 0;
				begin
					Select UM1 into aUM1 
					from NArt a, NArtObj O 
					where O.CodObiect = v_rec.CodObiect and a.Codarticol = o.Codarticol;
					Select Nvl(TipUM,0), Nvl(u.Zecimale,0), Nvl(Coef,1) into aTipUM, aZecimale, aCoef 
					from num u 
					where u.Codum = aUm1;
					if aTipUM = 6 and Nvl(v_rec.AcceptUM1,0) &lt;&gt; 0 and NVL(v_rec.Cantacceptat,0) &lt;&gt; 0 then 
						aZile := Round(v_rec.TERMEN - aDataDoc, 0);

						update COMANDA1 --comanda noua
						  set AcceptUM1 = aZile, 
							    PU       = PretUM1 * aZile / v_rec.Cantacceptat,
                  Pretorig = PretUM1 * aZile / v_rec.Cantacceptat 
						where CodComanda1 = vCod;

						aZile := v_rec.AcceptUM1 - aZile;
						update COMANDA1 --comanda veke
						  set AcceptUM1 = aZile, 
							    PU       = PretUM1 * aZile / v_rec.Cantacceptat,
                  Pretorig = PretUM1 * aZile / v_rec.Cantacceptat 
						where CodComanda1  = v_rec.CodComanda1;
						update TMP_COMANDA1 --comanda veke
						  set AcceptUM1 = aZile, 
							    PU       = PretUM1 * aZile / v_rec.Cantacceptat,
                  Pretorig = PretUM1 * aZile / v_rec.Cantacceptat
						where CodComanda1  = v_rec.CodComanda1;
						update TMP_COMANDA1 --comanda veke
						  set Valoare = PU*Cantacceptat
						where CodComanda1  = v_rec.CodComanda1;
					else 
					  aTipUM := 0;
					end if;
				exception when others then
					aTipUM := 0;
				end;
				if aTipUM = 0 then
					update COMANDA1 --comanda noua
						set CantAcceptat = 0, AcceptUM1 = 0
					where CodComanda1 = vCod;
				end if;
				UPDATE TMP_COMANDA1 C1
				SET
					VALDISCOUNT = NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * NVL(PROCDISC, 0)/100,
					TVA         = NVL( NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * NVL(PROCTVA, 0)/ 100,0);
			end if;
      select CodArticol into aCodArticol from NartObj where CodObiect = v_rec.CodObiect;
			aProcTVA := PKG_SELECTARTICOLE.GETPROCENTTVA(aCodArticol,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU);
      begin
				Select NVL(CANTACCEPTAT, 0) * NVL(PU, 0) *(1+Nvl(ProcDisc,0)/100)*(1 + NVL(aPROCTVA, 0)/ 100) 
							 into aVal
				from Comanda1 where CodComanda1 = vCod and Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 1;
			exception when others then
				aVal := 0;
			end;
			avalsofercm      := avalsofercm   + aVal;
      begin
			Select NVL(CANTACCEPTAT, 0) * NVL(PU, 0) *(1+Nvl(ProcDisc,0)/100)*(1 + NVL(aPROCTVA, 0)/ 100) 
			       into aVal
			from Comanda1 where CodComanda1 = vCod and Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 0;
			exception when others then
				aVal := 0;
			end;
      avalsoferf       := avalsoferf    + aVal;
      begin
			Select NVL(CANTACCEPTAT, 0) * NVL(PU, 0) *(1+Nvl(ProcDisc,0)/100)*(1 + NVL(aPROCTVA, 0)/ 100) 
			       into aVal
			from Comanda1 where CodComanda1 = vCod and Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 1;
			exception when others then
				aVal := 0;
			end;
      avalclientcm     := avalclientcm  + aVal;
      begin
			Select NVL(CANTACCEPTAT, 0) * NVL(PU, 0) *(1+Nvl(ProcDisc,0)/100)*(1 + NVL(aPROCTVA, 0)/ 100) 
			       into aVal
			from Comanda1 where CodComanda1 = vCod and Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 0;
			exception when others then
				aVal := 0;
			end;
      avalclientf      := avalclientf   + aVal;
    END LOOP;
    
		update COMANDA1 set Termen =  aDataStop where CodComanda = aCod;
--update comanda SURSA CLONARE
    update COMANDA
       set Blocat = 1, 
			     Valoare    =
           (Select Sum(NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * (1+NVL(PROCDISC, 0)/100)) from tmp_comanda1),
           VALDISCOUNT =
           (Select Sum(Nvl(ValDiscount, 0)) from tmp_Comanda1)
     where CodComanda = aCod;

    update TMP_COMANDA
       set Blocat = 1, 
			     Valoare    =
           (Select Sum(NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * (1+NVL(PROCDISC, 0)/100)) from tmp_comanda1),
           VALDISCOUNT =
           (Select Sum(Nvl(ValDiscount, 0)) from tmp_Comanda1);
					 
--update comanda CLONA rezultata		
    update COMANDA 
		  set                      
			  Valoare =  (Select Sum(Nvl(Cantacceptat,0)*Nvl(PU,0)*(1+NVL(PROCDISC, 0)/100)) from comanda1 where CodComanda = RECID),
				VALDISCOUNT = ( Select Sum(Nvl(NVL(CANTACCEPTAT, 0) * NVL(PU, 0) * NVL(PROCDISC, 0)/100,0)) 
				                from Comanda1 where CodComanda = RECID)
		where CodComanda = RECID;
  	Update RAC_REZ set 
		 valsofercm  = avalsofercm , 
     valsoferf   = avalsoferf  , 
     valclientcm = avalclientcm,       
     valclientf  = avalclientf 
		where CodComanda = RECID;
		
--sfarsit update
     update TMP_COMANDA set ValTVA = Round((Select Sum(Nvl(TVA,0)*(1+Nvl(ProcDisc,0)/100)) from tmp_Comanda1),2);
     update TMP_COMANDA set DiscTVA = ValDiscount*ValTVA/Valoare where Nvl(Valoare,0) &lt;&gt; 0;
     update TMP_COMANDA set Valoare = Valoare + ValTVA, ValDiscount = ValDiscount + DiscTVA;
  	 Update TMP_RAC_REZ set 
			 valsofercm  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 1),0), 
			 valsoferf   = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 0),0), 
			 valclientcm = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 1),0),       
			 valclientf  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 0),0);
  	 Update RAC_REZ set 
			 valsofercm  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 1),0), 
			 valsoferf   = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) = 2 and Nvl(ModInchidere,0) = 0),0), 
			 valclientcm = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 1),0),       
			 valclientf  = Nvl((Select Sum((Valoare + TVA)*(1+Nvl(ProcDisc,0)/100)) from Tmp_Comanda1 
											where Nvl(CuLansare,0) &lt;&gt; 2 and Nvl(ModInchidere,0) = 0),0)
			where CodComanda = aCod;


  NotifyModif(1, RecId, &apos;COMANDA&apos;);
  COMMIT;
end;


function RAC_Reparatii(aCodAuto in number) return RAC_CURSOR2 is
crs RAC_CURSOR2;
aInd number(20);
begin
  begin
    open crs for
	    SELECT CODCOMANDA3,c2.CODCOMANDA2,CANT,PRET, C3.TIP,EXECUTAT,garantie ,CODLUCRARE,CODOPERATIE, c2.CodRezervare, Data, Op.CodServiciu
	    FROM COMANDA2 c2 
			inner join COMANDA3 C3 on C2.CodComanda2 = C3.CodComanda2
			inner join NOper   Op  on Op.CodOp       = C3.CodOperatie
			where  c2.codNParcAut = aCodAuto and Nvl(Executat,0) &lt;&gt; 1;
  EXCEPTION when others THEN
    open crs for select -1 CodCfg from dual;
  end;
  return crs;
end;
--execute PKG_RAC_REZ.RefacereParcG;
procedure RefacereParcG is
  aData date := TO_DATE(&apos;01.07.2014 00:01&apos;, &apos;DD.MM.YYYY hh24:mi&apos;);
	N number;
begin
  delete nparcg;
  INSERT INTO  NParcG 
             ( CODNParcG, CODNPARCAUT, CodGest, Status, Data)
  Select SEQ_NPARCG_CODNPARCG.NextVal, CodNParcAut, CodGest, Inactiv, aData 
	from nparcaut;
	for v_rec in ( select P.Inactiv, C.Mijltransp, R.* 
	               from Rac_rez r 
								 inner join Comanda c on c.codcomanda  = r.codcomanda 
								 inner join NParcAut p on P.Codnparcaut = C.Mijltransp
	               where c.codcomanda &gt; 0 and r.TipRezervare = 7 and nvl(c.Tiptranzactie,0) = 1 and nvl(r.predat,0) = 1 order by r.datapred) loop
		Delete NParcG where CodNparcAut = v_rec.mijltransp; 	  
	end loop;
	for v_rec in ( select P.Inactiv, C.Mijltransp, R.* 
	               from Rac_rez r 
								 inner join Comanda c on c.codcomanda  = r.codcomanda 
								 inner join NParcAut p on P.Codnparcaut = C.Mijltransp
	               where c.codcomanda &gt; 0 and r.TipRezervare = 7 and nvl(r.predat,0) = 1 
								 order by r.datapred) loop
		select Count(*) into N from NParcG where CodNparcAut = v_rec.mijltransp; 	  
    if N = 0 then 
			INSERT INTO  NParcG 
								 ( CODNParcG, CODNPARCAUT, CodGest, Status, Data)
			values(SEQ_NPARCG_CODNPARCG.NextVal, v_rec.Mijltransp, v_rec.CodGestSursa, v_rec.Inactiv, aData);
    end if;
		INSERT INTO  NParcG 
							 ( CODNParcG, CODNPARCAUT, CodGest, Status, Data,CODCMD)
		values(SEQ_NPARCG_CODNPARCG.NextVal, v_rec.Mijltransp, v_rec.CodGestDest, v_rec.Inactiv, v_rec.DataPred, v_rec.CodComanda);
    update nparcAut set CodGest = v_rec.CodGestDest where CodNparcAut = v_rec.mijltransp; 	  
	end loop;
	Commit;
end;

procedure Init_ReparaParcG is
begin
  pkg_rac_rez.SET_RAC_DATASTART(&apos;17.08.2016 01:01&apos;);
  delete TMP_V_Auto;
  insert into TMP_V_Auto (CodAuto, CodGest, CodClasa, q)
  select * from (select CodAuto, CodGest, CodClasa, Sum(Q) q from V_AUTO group by CodAuto, codgest, CodClasa) where q = -1;
end;

procedure ReparaParcG is
  n number;
begin
  Init_ReparaParcG;
	for x_rec in (Select * from TMP_V_AUTO) loop
		Update nparcaut set codgest = x_rec.Codgest where codnparcaut = x_rec.codauto;
		Update nparcg set codgest   = x_rec.Codgest 
		where codnparcaut = x_rec.codauto and Data = (select Min(Data) from nparcg where  codnparcaut = x_rec.codauto);
	end loop;
	commit;
end;

PROCEDURE Fill_RAC_TABLES
IS
IndGrupa number;
BEGIN
  DATAPORNIRE := Sysdate;
	IsDataCuOra := 1;
	IndGrupa    := PKG_RAC_REZ.IndexGrupaAuto;
	delete RAC_CARS;  
  delete RAC_AUTO_CEN;  
  delete RAC_AUTO;  
	delete RAC_Transfer;  
	delete RAC_EMU;
insert into RAC_CARS  
     SELECT 
          P.CodNParcAut CodAuto, 
          NPG.Data, 
          Coalesce(NPG.CodGest,0) CodGest, NG.Den_Gest Gestiune, NG.Codsubunit Subunitate, NG.CodClasa,  
          Coalesce(NPG.Status,0) Inactiv, Coalesce(P.Extern,0) Extern, 
          P.CodArt CodObiect, 
          P.Nrinreg NrAuto, Ma.Marca, Mo.Model, P.AnF, 
          Coalesce(G.CodGrEchiv, 0) CodGrEchiv, Coalesce(G.IND,0) Ind, G.DENUMIRE Clasa, Coalesce(E.Generic,0) Generic 
     FROM NParcAut P 
          INNER JOIN (SELECT CodNParcAut, Max(DATA) Data FROM NParcG WHERE Data &lt;= DataPornire group by CodNParcAut) xNPG on xNPG.CodNParcAut = P.CodNParcAut 
          INNER JOIN NParcG NPG ON NPG.CodNParcAut = xNPG.CodNParcAut and NPG.Data = xNPG.Data
          LEFT JOIN NEchiv E ON E.Codobiect = P.CodArt 
          LEFT JOIN GrEchiv G ON G.CODGRECHIV = E.CodGrupa 
          LEFT JOIN Nmodeleauto Mo ON Mo.CODMODELEAUTO = p.Model 
          LEFT JOIN Nmarciauto Ma ON Ma.CODMarciAuto = p.Marca 
          LEFT JOIN NGest NG on NG.CODGEST = NPG.CodGest ;																									 

	insert into RAC_Transfer 
	select R.CodGestSursa, R.CodGestDest, NVL(C.MijlTransp,0) CodAuto, R.DataStart, R.DataStop, R.DataPred
	 from RAC_REZ  R
	 inner join Comanda c on R.codcomanda = c.codcomanda
	 where Nvl(C.Operat, 0) = 1
				 and Nvl(R.Predat, 0) = 1
				 and R.CodGestSursa &lt;&gt; R.CodGestDest
				 and DataPornire &gt; R.DataPred
	union all
	select X.CodGestDest CodGestSursa, R.CodGestSursa CodGestDest, NVL(C.MijlTransp,0) CodAuto, R.DataStart, R.DataStop, R.DataPred
	 from RAC_REZ  R
	 inner join Comanda c on R.codcomanda = c.codcomanda
	 inner join Comanda XX on XX.codcomanda = R.CodRezervare
	 inner join Rac_Rez X on X.codcomanda = XX.codcomanda
	 where Nvl(C.Operat, 0) = 1
				 and Nvl(R.Predat,0) = 1
				 and Nvl(R.CodRezervare, 0) &gt; 0
				 and Nvl(XX.Mijltransp,0) = Nvl(C.Mijltransp,0)
				 and R.CodGestSursa &lt;&gt; R.CodGestDest
				 and DataPornire &gt; R.DataPred;
		
	insert into RAC_AUTO 
	with
	PTransf as
	(Select CodCmd,CodNparcAut CodAuto,Data,CodGest,CodGestIni CodGestPrec from NParcG  
	 where Nvl(CodGest,0) &gt; 0 and Nvl(CodCmd,0) = 0),
	Cars as
	( select Nvl(CodGest,0) CodGest, CodNParcAut CodAuto, CodArt CodObiect from NPArcAut where nvl(Extern,0) = 0 and Nvl(CodGest,0) &gt; 0)
	------------------------------------------------------------------------------------------------------------------
	Select X.CodAuto, X.CodObiect, X.CodGest, X.Transferat, X.Q, X.DataStart, X.DataStop, GG.CodClasa 
	FROM (
	select T.CodAuto, C.CodObiect, T.CodGestSursa CodGest, 1 Transferat, -1 Q, T.DataStart, T.DataStop 
				 from v_rac_Transfer T 
				 inner join Cars C on C.CodAuto = T.CodAuto
	union all
	select T.CodAuto, C.CodObiect, T.CodGestDest  CodGest, 1 Transferat, +1 Q, T.DataStart, T.DataStop  
				 from v_rac_Transfer T 
				 inner join Cars C on C.CodAuto = T.CodAuto
	union all
	select T.CodAuto, C.CodObiect, T.CodGestPrec CodGest, 0 Transferat, -1 Q, T.Data DataStart, T.Data DataStop 
				 from PTransf T 
				 inner join Cars C on C.CodAuto = T.CodAuto
	where T.CodGestPrec &lt;&gt; 0
	union all
				select T.CodAuto, C.CodObiect, T.CodGest            , 0 Transferat, +1 Q, T.Data DataStart, T.Data DataStop 
				from PTransf T 
				inner join Cars C on C.CodAuto = T.CodAuto
	) X inner join NGEST GG on GG.CodGest = X.CodGest;

	insert into RAC_AUTO_CEN 
	(select CODAUTO,CODGEST,Q from (Select CodAuto, CodGest, Sum(Q) Q from  RAC_AUTO group by CodAuto, CodGest) where Q &lt;&gt; 0);

	insert into RAC_EMU
	Select CODCOMANDA, Sum(COALESCE(e1.Cant,0)) Cant
	from Emulare1 e1 inner join Emulare e on e.CodEmulare = e1.CodEmulare and COALESCE(e.CODMONETAR,0) = 0  
			 inner join Comanda1 c1 on C1.CodComanda1 = e1.CodComanda1 and COALESCE(e1.CODCOMANDA1,0) &lt;&gt; 0
	group by CodComanda
	;
  Insert into RAC_AUTO (CODAUTO,CODOBIECT,CODGEST,TRANSFERAT,Q,DATASTART,  DATASTOP,CODCLASA)
	    					 VALUES(-1,     0,        0,      0,         0,DATAPORNIRE, SysDate,   0);         
	COMMIT;
	
END;

PROCEDURE Fill_RAC_TMP IS
BEGIN
	delete TMP_RAC_CARS     ;
  delete TMP_RAC_AUTO_CEN ; 
  delete TMP_RAC_AUTO     ; 
  delete TMP_RAC_EMU      ;

  insert into TMP_RAC_CARS     select * from  RAC_CARS where Extern = 0 and Generic = 0 and CodGest &gt; 0 and Ind = 1;
  insert into TMP_RAC_AUTO_CEN select * from  RAC_AUTO_CEN;  
  insert into TMP_RAC_AUTO     select * from  RAC_AUTO;  
  insert into TMP_RAC_EMU      select * from  RAC_EMU;

  COMMIT;
END;	
--execute PKG_RAC_REZ.ReparaParcG ;
end PKG_RAC_REZ; 

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D27EAEAA9AC76A140DDAF3227500EEE9FCAA025A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RAPORTP IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_xx&apos;;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := aCARNET;
  NRDOC_I     := aNRDOC;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodRaportP INTO Tmp FROM RaportP WHERE CodRaportP = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_RaportP FIELDS(CodRaportP) VALUES (0);
  -- mRaportProductie --&gt; 63
  PKG_CFGTABLES.EXT_INSERTRECORD(63);  
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aNrDoc      NUMBER (20);
  aCodSubunit NUMBER(20);
  aDataDoc    DATE;
  aDoc        VARCHAR2(200);
  aCarnetDoc  number(20);
BEGIN
  SP_LOCKRECORD(RecId);
  -- mRaportProductie --&gt; 63
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 63);
  SELECT NrDoc, Subunitatea, DataI, &apos;RaportP &apos;||NrDoc||&apos;/&apos;||dataI||&apos;-&apos;||DataS, CarnetDoc
  INTO   aNrDoc, aCodSubunit, aDataDoc, aDoc, aCarnetDoc
  FROM    RaportP
  WHERE   CodRaportP = recId;

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;RaportP&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  for v_rec in (select coalesce(l.codcmdprodman,0) codcmdprodman, P2.codraportp2
                from RAPORTP2 P2
                     INNER JOIN RAPORTP1 P1 ON P2.CODRAPORTP1 = P1.CODRAPORTP1
                     left join manprodlink l on l.codraportp2 = P2.codraportp2
                WHERE P1.CODRAPORTP = RecID) loop
    delete raportp2 where codraportp2 = v_rec.codraportp2;
    if v_rec.codcmdprodman &gt; 0 then
      delete manprodlink where codraportp2 = v_rec.codraportp2;
      UPDATE CMDPRODMAN man
      SET
        man.REST = man.cant -
                   ( SELECT NVL(SUM(IL.CANT), 0)
                     FROM
                       MANPRODLINK IL
                       inner join raportp2 r2 on il.codraportp2 = r2.codraportp2
                       inner join raportp1 r1 on r1.codraportp1 = r2.codraportp1
                       inner join raportp r on r.codraportp = r1.codraportp
                     where man.codcmdprodman = il.codcmdprodman
                     )
      where man.codcmdprodman = v_rec.codcmdprodman;
    end if;
  end loop;

  DELETE FROM RaportP3 WHERE CodRaportP = RecId;
  DELETE FROM RaportP1 WHERE CodRaportP = RecId;
  DELETE FROM RaportP0 WHERE CodRaportP = RecId;
  DELETE FROM RaportP  WHERE CodRaportP = RecId;

  if aCarnetDoc &gt; 0 then
    PKG_CARNETEDOC.RELEASENUMARDOC(ACARNETDOC, ANRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(ACARNETDOC);
  end if;
  NotifyModif(2, RecId, &apos;RAPORTP&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  nr     number(20);
  CodI1  number(20);
  I1     number(20);
  aAng   number(20);
  aCmd   varchar2(100);
  aObj   varchar2(200);
  aCodR  number(20);
  vAnLuna number(20);
BEGIN
  begin
    select an*12+luna into vAnLuna from raportp where codraportp = recid;
  exception when others then vAnLuna := pkg_globals.GetANLUCRU*12+pkg_globals.GetLUNALUCRU;
  end;

  INSERT INTO TMP_RaportP (CODRAPORTP, NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA,
                           prefixdoc,carnetdoc,seriadoc,SCHIMB,Obs)
  SELECT CODRAPORTP, NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA,
         prefixdoc, carnetdoc, seriadoc, SCHIMB,Obs
  FROM RaportP WHERE CodRaportP = RecId;

  INSERT INTO  TMP_RaportP0 (CODRAPORTP0, CODRAPORTP, CODCOMANDA1, REALIZAT, REBUT, COMANDA, DENOBIECT, CODRETETA, UTILAJ, Codutilaj2c, Derealizat,
                             CLIENTU, FURNU, SERIEF,OBS,Codexterncliu)
  SELECT
    P0.CODRAPORTP0, P0.CODRAPORTP, P0.CODCOMANDA1, P0.REALIZAT, P0.REBUT,
    C.PREFIXDOC||C.NRDOC||&apos;/&apos;||C.DATADOC, OB.DENUMIRE, C1.Codreteta, OBJU.DENUMIRE, U2C.CodUtilaj2C, CMD.Cant,
    CLI.DEN_PART, FURN.DEN_PART, U.SERIEF,P0.OBS,CLI.CODEXTERN
  FROM RaportP0 P0
    LEFT JOIN Comanda1 C1 ON C1.CodComanda1 = P0.CodComanda1
    LEFT JOIN CMDPRODMAT CMD ON CMD.CODCOMANDA1 = C1.CODCOMANDA1 and CMD.TIP = 0
    LEFT JOIN NartObj  Ob ON Ob.CodObiect   = C1.CodObiect
    LEFT JOIN Comanda  C  ON C.CodComanda   = C1.CodComanda
    LEFT JOIN UTILAJE2C U2C ON U2C.CODCOMANDA1 = C1.CODCOMANDA1
    LEFT JOIN UTILAJE U ON U.CODUTILAJ = U2C.CODUTILAJ
    LEFT JOIN NARTOBJ OBJU ON OBJU.CODOBIECT = U.CODOBIECT
    LEFT JOIN NPART CLI ON CLI.CODPART = U.CODPART
    LEFT JOIN NPART FURN ON FURN.CODPART = U.CODFURNIZOR
  WHERE P0.CodRaportP = RecId;

  INSERT INTO  TMP_RaportP1 (
    CODRAPORTP1, CODRAPORTP0, CODRAPORTP, ANGAJAT, Realizat, Indice, Rebut, DEN_ANGAJAT, MARCA, ProdRealizat, Prodrebut)
  SELECT
    P1.CODRAPORTP1, P1.CODRAPORTP0, P1.CODRAPORTP, P1.ANGAJAT, P1.Realizat, P1.Indice, P1.Rebut, Decode(P1.Angajat,0, A.NUME,A.NUME||&apos; &apos;||A.PRENUME), A.MARCA,
    P1.Prodrealizat, P1.Prodrebut
  FROM RaportP1 P1
    LEFT JOIN NPERS A ON A.CodPers = P1.Angajat
  WHERE P1.CodRaportP = RecId;

  insert into tmp_raportp1c (codraportp1c, codraportp0, codraportp, angajat, realizat, rebut, prodrealizat, prodrebut, den_angajat, marca)
  select rownum, x.codraportp0, x.codraportp, x.angajat, x.realizat, x.rebut, x.prodrealizat, x.prodrebut, x.den_angajat, x.marca
  from (select codraportp0, codraportp, angajat, sum(realizat) realizat, sum(rebut) rebut, sum(prodrealizat) prodrealizat, sum(prodrebut) prodrebut, den_angajat, marca
  from tmp_raportp1
  group by codraportp0, codraportp, angajat, den_angajat, marca) x;

  insert into tmp_raportp3 (codraportp3, codraportp1, codraportp, codmotiv, ore)
  select codraportp3, codraportp1, codraportp, codmotiv, ore
  from raportp3 where codraportp = RecId;

  INSERT INTO TMP_RaportP2
  (
    CODRAPORTP2,
    CODRAPORTP1,
    CODCOMANDA1,
    CODMAN,
    REALIZAT,
    REBUT,
    CODOP,
    CODLOC,
    CODTARIF,
    TU,
    TUH,
    CODUTILAJ,
    VALOARE,
    INDEXOPER,
    COMANDA,
    UTILAJ,
    OPERATIE,
    DURATA,
    DURATAH,
    TARIF,
    TIPLOCMUNCA,
    DATASTART,
    DATASTOP,
    DATASTARTC,
    DATASTOPC,
    REFACUT,
    CODIES1,
    CODRAPORTP0,
    OBS
  )
  SELECT
    P2.CODRAPORTP2,
    P2.CODRAPORTP1,
    P2.CODCOMANDA1,
    P2.CODMAN,
    P2.REALIZAT,
    P2.REBUT,
    nvl(P2.CODOP, PM.codop),
    case when nvl(P2.CODMAN,0) &gt; 0 then pm.codloc else P2.CODLOC end,
    nvl(P2.CODTARIF,pm.codtarif),
    nvl(P2.TU, pm.tu),
    nvl(P2.TU, pm.tu)/60,
    P2.CODUTILAJ,
    case when p2.codies1 &gt; 0 then i1.pu else case when nvl(p2.codtarif,0) = 0 then TM1.Tarif else T1.Tarif end end * nvl(P2.TU, pm.tu) * P2.REALIZAT / 60,
    PM.NrOp,
    C.PREFIXDOC||C.NRDOC||&apos;/&apos;||C.DATADOC,
    OB.DENUMIRE,
    PM.NROP||&apos;/&apos;||case when nvl(OP.codop,0) = 0 then OPMan.DENUMIRE else OP.Denumire end,
    nvl(P2.TU, pm.tu) * P2.REALIZAT,
    nvl(P2.TU, pm.tu) * P2.REALIZAT / 60,
    case when p2.codies1 &gt; 0 then i1.pu else case when nvl(p2.codtarif,0) = 0 then TM1.Tarif else T1.Tarif end end,
    lm.tip,
    P2.DATASTART,
    P2.DATASTOP,
    to_char(P2.DATASTART, &apos;dd.mm.yyyy hh24:mi:ss&apos;),
    to_char(P2.DATASTOP, &apos;dd.mm.yyyy hh24:mi:ss&apos;),
    P2.REFACUT,
    P2.CODIES1,
    P1.CODRAPORTP0,
    P2.OBS
  FROM RaportP P
    INNER JOIN RaportP1 P1 ON P1.CodRaportP  = P.CodRaportP
    INNER JOIN RaportP2 P2 ON P2.CodRaportP1 = P1.CodRaportP1
    left JOIN ProdMan  PM ON PM.CodMan      = P2.CodMan
    left join locmunca lm on p2.codloc = lm.codloc
    left JOIN TarifeMan1 T1 on T1.CodTarif = P2.codTarif AND vAnLuna BETWEEN t1.ALSTART AND t1.ALSTOP 
    left JOIN TarifeMan1 TM1 on TM1.CodTarif = Pm.codTarif AND vAnLuna BETWEEN tm1.ALSTART AND tm1.ALSTOP
    LEFT JOIN NOper    Op ON Op.CodOp       = P2.CodOp
    LEFT JOIN NOper    OpMan ON OpMan.CodOp = PM.CodOp
    LEFT JOIN Comanda1 C1 ON C1.CodComanda1 = P2.CodComanda1
    LEFT JOIN Comanda  C  ON C.CodComanda   = C1.CodComanda
    LEFT JOIN UTILAJE U ON P2.CODUTILAJ = U.CODUTILAJ
    LEFT JOIN NartObj  Ob ON Ob.CodObiect = U.CodObiect
    LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = P2.CODIES1
  WHERE P.CodRaportP = RecId;

  insert into tmp_raportp2c(codraportp2c, codraportp0, codcomanda1, codobiect, codman, realizat, rebut, codop, valoare, operatie, nrop)
  select rownum, x.codraportp0, x.codcomanda1, x.codobiect, x.codman, x.realizat, x.rebut, x.codop, x.valoare, x.operatie, x.indexoper
  from (select codraportp0, codcomanda1, codobiect, codman, sum(realizat) realizat, sum(rebut) rebut, codop, sum(valoare) valoare, operatie, indexoper
  from tmp_raportp2
  group by codraportp0, codcomanda1, codobiect, codman, codop, operatie, indexoper) x;

  for v_rec in (select * from tmp_raportp1c) loop
    update tmp_raportp1 set
    codraportp1c = v_rec.codraportp1c
    where codraportp0 = v_rec.codraportp0 and codraportp = v_rec.codraportp and angajat = v_rec.angajat;

    update tmp_raportp2 tmp set
    codraportp1c = v_rec.codraportp1c
    where tmp.codraportp1 in (select r1.codraportp1
                              from TMP_raportp1 r1
                              where r1.codraportP1c = v_rec.codraportP1c);
  end loop;

  for v_rec in (select *
                from tmp_raportp2c tmp
                ) loop
    update tmp_raportp2 set
    codraportp2c = v_rec.codraportp2c
    where codraportp0 = v_rec.codraportp0 and nvl(codcomanda1,0) = nvl(v_rec.codcomanda1,0)
          and nvl(codobiect,0) = nvl(v_rec.codobiect,0) and nvl(codman,0) = nvl(v_rec.codman,0) and codop = v_rec.codop;
  end loop;

  for v_rec in (select tmp.*, t1.codraportp1
                from tmp_raportp2c tmp
                     inner join tmp_raportp2 t2 on t2.codraportp2c = tmp.codraportp2c
                     inner join tmp_raportp1 t1 on t1.codraportp1 = t2.codraportp1
                ) loop
    update tmp_raportp1 set
    codraportp2c = v_rec.codraportp2c
    where codraportp1 = v_rec.codraportp1;
  end loop;

  INSERT INTO TMP_MANPRODLINK (CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1)
  SELECT CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1
  FROM MANPRODLINK WHERE CODRAPORTP2 IN (SELECT CODRAPORTP2 FROM TMP_RAPORTP2);

  DELETE TMP_MANPRODLINK_INITIAL;
  INSERT INTO TMP_MANPRODLINK_INITIAL
  SELECT * FROM TMP_MANPRODLINK;

  FOR v_rec IN (SELECT CODRAPORTP1 FROM TMP_RaportP1)
  LOOP
    UPDATE TMP_RaportP1 SET VALOARE = (select sum(Valoare) from TMP_RaportP2 WHERE CodRaportP1 = v_rec.CodRaportP1),
                            Timp    = (select sum(Durata)   from TMP_RaportP2 WHERE CodRaportP1 = v_rec.CodRaportP1)
    where CodRaportP1 = v_rec.CodRaportP1;
  END LOOP;

  FOR v_rec IN (SELECT CODRAPORTP0 FROM TMP_RaportP0)
  LOOP
    UPDATE TMP_RaportP0 SET REBUT    = (select sum(ProdREBUT)   from TMP_RaportP1 WHERE CodRaportP0 = v_rec.CodRaportP0)
    where CodRaportP0 = v_rec.CodRaportP0;
  END LOOP;

  Select Count(*) into NR from TMP_RAPORTP0;
  if nvl(NR,0) = 0 then
      Delete from TMP_RaportP1;
      I1 := 0;
      for v_rec in ( select r2.CodRaportP2, r1.CodRaportP1, r2.CodComanda1
                     from Raportp2 r2 inner join RaportP1 r1 on r1.CodRaportP1 = r2.CodRaportP1
                     where r1.CodRaportP = RecId)
      loop
        Select Count(*) into NR from TMP_RAPORTP0 where CodComanda1 = v_rec.CodComanda1;
        if Nr = 0 then
          SELECT
            C.PREFIXDOC||C.NRDOC||&apos;/&apos;||C.DATADOC, OB.DENUMIRE, C1.CodReteta into aCmd, aObj, aCodR
          FROM Comanda1 C1
            LEFT  JOIN NartObj  Ob ON Ob.CodObiect   = C1.CodObiect
            LEFT  JOIN Comanda  C  ON C.CodComanda   = C1.CodComanda
          WHERE C1.CodComanda1 = v_rec.CodComanda1;

          INSERT INTO  TMP_RaportP0 (CODRAPORTP0, CODRAPORTP, CODCOMANDA1, Comanda, Denobiect, Codreteta)
          VALUES (-V_REC.CODCOMANDA1, RecID, V_REC.CODCOMANDA1, aCmd, aObj, aCodR);
        end if;

        Select Angajat into aAng from RAPORTP1 where CodRaportP1 = v_rec.CodRaportP1;
        Select Count(*) into NR from TMP_RAPORTP1 where Angajat = aAng and CodRaportP0 = -v_rec.CodComanda1;
        if Nr = 0 then
          I1 := I1 - 1;
          SELECT Decode(A.CodPers,0, A.NUME,A.NUME||&apos; &apos;||A.PRENUME), A.MARCA into aObj, aCodR
          FROM NPERS A where A.CodPers = aAng;
          INSERT INTO  TMP_RaportP1 (CODRAPORTP1, CODRAPORTP0, CODRAPORTP, Angajat, DEN_ANGAJAT, MARCA)
          VALUES (I1, -V_REC.CODCOMANDA1, RecID, aAng, aObj, aCodR);
          CodI1 := I1;
        else
          Select CodRaportP1 into CodI1 from TMP_RAPORTP1 where CodRaportP0 = -v_rec.CodComanda1;
        end if;
        update TMP_RAPORTP2 set CodRaportP1 = CodI1 where CodRaportP2 = v_rec.CodRaportP2;
      end loop;
  end if;
  -- mRaportProductie --&gt; 63
  PKG_CFGTABLES.EXT_GOTORECORD(63);
	
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod          NUMBER(20);
  aCARNET       NUMBER(20) := 0;
  aNrDoc        NUMBER(20);
  aCodSubunit   NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
  Nr            number(10);
BEGIN
  SELECT CodRaportP, NrDoc, Subunitatea, DataI, &apos;RaportP &apos;||NrDoc||&apos;/&apos;||dataI||&apos;-&apos;||DataS, CarnetDoc
  INTO    RecId, aNrDoc, aCodSubunit, aDataDoc, aDoc, aCarnet
  FROM TMP_RaportP;
  
  -- mRaportProductie --&gt; 63
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (63);
  IF Operation = 0 THEN  -- UPDATE

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;RaportP&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    -- Master RaportP

    UPDATE RaportP
    SET (NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA,prefixdoc,carnetdoc,seriadoc,SCHIMB,Obs)
      = (SELECT NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA,prefixdoc,carnetdoc,seriadoc,SCHIMB,Obs
         FROM TMP_RaportP )
    WHERE CodRaportP = RecId;

    -- Detail
    SELECT Count(*) into NR FROM RaportP0 P0 WHERE P0.CodRaportP = RecId;
    if NR = 0 then
      DELETE FROM MANPRODLINK WHERE CodRaportP2 IN (SELECT CodRaportP2 FROM TMP_MANPRODLINK_INITIAL);
      DELETE FROM RaportP2
      WHERE CodRaportP1 IN (SELECT P1.CodRaportP1 FROM RaportP1 P1 WHERE P1.CodRaportP = RecID);

      DELETE FROM RaportP1    WHERE CodRaportP = RecID;
      DELETE FROM RaportP3    WHERE CodRaportP = RecID;

      FOR v_rec IN (SELECT * FROM TMP_RaportP0 )
      LOOP
        SELECT Seq_RaportP0_CodRaportP0.NEXTVAL INTO vCod FROM dual;
        UPDATE TMP_RaportP1 SET CodRaportP0 = vCOD WHERE CodRaportP0 = v_rec.CodRaportP0;
        INSERT INTO  RaportP0 ( CODRAPORTP0, CODRAPORTP, CodComanda1, Realizat, Rebut, OBS)
        VALUES ( vCod , RecId, v_rec.CodComanda1, v_rec.Realizat, v_rec.Rebut, V_REC.OBS);
      END LOOP;

      FOR v_rec IN ( SELECT * FROM TMP_RaportP1) LOOP
        SELECT Seq_RaportP1_CodRaportP1.NEXTVAL INTO vCod FROM dual;
        UPDATE TMP_RaportP2 SET CodRaportP1 = vCOD WHERE CodRaportP1 = v_rec.CodRaportP1;
        INSERT INTO  RaportP1 ( CODRAPORTP1, CODRAPORTP0, CODRAPORTP, ANGAJAT, Realizat, Indice, Rebut, Prodrealizat, Prodrebut)
        VALUES ( vCod , v_rec.CODRAPORTP0, RecId, v_rec.ANGAJAT, v_rec.Realizat, v_rec.Indice, v_rec.Rebut, v_rec.ProdRealizat, v_rec.ProdRebut);
      END LOOP;

      FOR v_rec IN (
        SELECT
          CODRAPORTP2,
          CODRAPORTP1,
          CODCOMANDA1,
          CODOBIECT,
          CODMAN,
          REALIZAT,
          REBUT,
          CODOP,
          CODLOC,
          CODTARIF,
          TU,
          CODUTILAJ,
          DATASTART,
          DATASTOP,
          REFACUT,
          CODIES1,
          OBS
        FROM TMP_RaportP2
        ORDER BY CodRaportP1, IndexOper)
      LOOP
          SELECT Seq_RaportP2_CodRaportP2.NextVal INTO vCod FROM dual;
          update tmp_manprodlink set codraportp2 = vcod where codraportp2 = v_rec.codraportp2;
          INSERT INTO  RaportP2 (
            CODRAPORTP2,
            CODRAPORTP1,
            CODCOMANDA1,
            CODOBIECT,
            CODMAN,
            REALIZAT,
            REBUT,
            CODOP,
            CODLOC,
            CODTARIF,
            TU,
            CODUTILAJ,
            DATASTART,
            REFACUT,
            CODIES1,
            OBS)
          VALUES (vCod ,
                  v_rec.CODRAPORTP1,
                  v_rec.CODCOMANDA1,
                  v_rec.CODOBIECT,
                  v_rec.CODMAN,
                  v_rec.REALIZAT,
                  v_rec.REBUT,
                  v_rec.CODOP,
                  v_rec.CODLOC,
                  v_rec.CODTARIF,
                  v_rec.TU,
                  v_rec.CODUTILAJ,
                  v_rec.DATASTART,
                  V_REC.REFACUT,
                  V_REC.CODIES1,
                  V_REC.OBS);
      END LOOP;

      FOR V_REC IN (SELECT * FROM TMP_MANPRODLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM MANPRODLINK WHERE CODRAPORTP2 = v_rec.CODRAPORTP2;
        IF NR = 0  THEN
          INSERT INTO MANPRODLINK (CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1)
          VALUES (v_rec.CODRAPORTP2, v_rec.CODCMDPRODMAN, v_rec.CANT, v_rec.CODPROGRAMF1);
        ELSE
          UPDATE MANPRODLINK
          SET
            CODRAPORTP2 = v_Rec.Codraportp2,
            CODCMDPRODMAN = v_Rec.Codcmdprodman,
            CANT = v_Rec.Cant,
            CODPROGRAMF1 = v_rec.codprogramf1
          WHERE CODRAPORTP2 = v_rec.CODRAPORTP2;
        END IF;
      END LOOP;
    else --nr=0
      DELETE FROM MANPRODLINK WHERE CodRaportP2 IN (SELECT CodRaportP2 FROM TMP_MANPRODLINK_INITIAL);
      DELETE FROM RaportP2
      WHERE CodRaportP1 IN (SELECT P1.CodRaportP1 FROM RaportP1 P1 WHERE P1.CodRaportP = RecID)
        AND CodRaportP2 NOT IN (SELECT CodRaportP2 FROM TMP_RaportP2 WHERE CodRaportP2 &gt; 0);

      DELETE FROM RAPORTP3 R3
      WHERE R3.CODRAPORTP = RECID AND
            NOT EXISTS (SELECT TMP.CODRAPORTP3 FROM TMP_RAPORTP3 TMP WHERE TMP.CODRAPORTP3 = R3.CODRAPORTP3);

      DELETE FROM RaportP1
      WHERE CodRaportP = RecID
        AND CodRaportP1 NOT IN (SELECT CodRaportP1 FROM TMP_RaportP1);

      DELETE FROM RaportP0
      WHERE CodRaportP = RecID
        AND CodRaportP0 NOT IN (SELECT CodRaportP0 FROM TMP_RaportP0);

      FOR v_rec IN (SELECT * FROM TMP_RaportP0 )
      LOOP
        IF nvl(v_rec.CodRaportP0,0) &gt; 0 THEN
          UPDATE RaportP0
          SET    CODCoMANDA1 = v_rec.CODCoMANDA1,
                 REALIZAT    = v_rec.REALIZAT,
                 REBUT       = v_rec.REBUT,
                 OBS         = V_REC.OBS
          WHERE  CodRaportP0 = v_rec.CodRaportP0;
        ELSE
          SELECT Seq_RaportP0_CodRaportP0.NEXTVAL INTO vCod FROM dual;
          UPDATE TMP_RaportP1 SET CodRaportP0 = vCOD WHERE CodRaportP0 = v_rec.CodRaportP0;

          INSERT INTO  RaportP0 ( CODRAPORTP0, CODRAPORTP, CodComanda1, Realizat, Rebut, OBS)
          VALUES ( vCod , RecId, v_rec.CodComanda1, v_rec.Realizat, v_rec.Rebut, V_REC.OBS);
        END IF;
      END LOOP;

      FOR v_rec IN ( SELECT * FROM TMP_RaportP1 ORDER BY ANGAJAT ) LOOP
        IF nvl(v_rec.CodRaportP1,0) &gt; 0 THEN
          UPDATE RaportP1
          SET    ANGAJAT     = v_rec.ANGAJAT,
                 REALIZAT    = v_rec.REALIZAT,
                 Indice      = v_rec.Indice,
                 REBUT       = v_rec.REBUT,
                 ProdRealizat = v_rec.Prodrealizat,
                 ProdRebut = v_rec.prodrebut
          WHERE  CodRaportP1 = v_rec.CodRaportP1;
        ELSE
          SELECT Seq_RaportP1_CodRaportP1.NEXTVAL INTO vCod FROM dual;
          UPDATE TMP_RaportP2 SET CodRaportP1 = vCOD WHERE CodRaportP1 = v_rec.CodRaportP1;
          UPDATE TMP_RaportP3 SET CodRaportP1 = vCOD WHERE CodRaportP1 = v_rec.CodRaportP1;

          INSERT INTO  RaportP1 ( CODRAPORTP1, CODRAPORTP0, CODRAPORTP, ANGAJAT, Realizat, Indice, Rebut, ProdRealizat, ProdRebut)
          VALUES ( vCod , v_rec.CODRAPORTP0, RecId, v_rec.ANGAJAT, v_rec.Realizat, v_rec.Indice, v_rec.Rebut, v_rec.ProdRealizat, v_rec.ProdRebut);
        END IF;
      END LOOP;

      FOR V_REC IN (
        SELECT codraportp3, codraportp1, codraportp, codmotiv, ore FROM TMP_RAPORTP3
      ) LOOP
        IF NVL(V_REC.CODRAPORTP3,0) &gt; 0 THEN
          UPDATE RAPORTP3 SET
            codraportp1 = V_REC.CODRAPORTP1,
            codraportp  = V_REC.CODRAPORTP,
            codmotiv    = CODMOTIV,
            ore         = ORE
          WHERE CODRAPORTP3 = V_REC.CODRAPORTP3;
        ELSE
          SELECT Seq_RaportP3_CodRaportP3.NextVal INTO vCod FROM dual;
          INSERT INTO RAPORTP3 (CODRAPORTP3, CODRAPORTP1, CODRAPORTP, CODMOTIV, ORE)
          VALUES (VCOD, V_REC.CODRAPORTP1, RecId, V_REC.CODMOTIV, V_REC.ORE);
        END IF;
      END LOOP;

      FOR v_rec IN (
        SELECT
          CODRAPORTP2,
          CODRAPORTP1,
          CODCOMANDA1,
          CODOBIECT,
          CODMAN,
          REALIZAT,
          REBUT,
          CODOP,
          CODLOC,
          CODTARIF,
          TU,
          CODUTILAJ,
          DATASTART,
          DATASTOP,
          REFACUT,
          CODIES1,
          OBS
        FROM TMP_RaportP2
        ORDER BY CodRaportP1, IndexOper)
      LOOP
        IF nvl(v_rec.CODRAPORTP2,0) &gt; 0 THEN
          UPDATE RaportP2
          SET
            CODCOMANDA1 = v_Rec.Codcomanda1,
            CODOBIECT   = v_Rec.Codobiect,
            CODMAN      = v_Rec.Codman,
            REALIZAT    = v_Rec.Realizat,
            REBUT       = v_Rec.Rebut,
            CODOP       = v_Rec.Codop,
            CODLOC      = v_Rec.Codloc,
            CODTARIF    = v_Rec.Codtarif,
            TU          = v_rec.tu,
            CODUTILAJ   = v_Rec.Codutilaj,
            DATASTART   = v_Rec.DataStart,
            DATASTOP    = v_Rec.DataStop,
            REFACUT     = V_rEC.Refacut,
            CODIES1     = V_REC.CODIES1,
            OBS         = V_REC.OBS
          WHERE CODRAPORTP2 = v_rec.CODRAPORTP2;
        ELSE
          SELECT Seq_RaportP2_CodRaportP2.NextVal INTO vCod FROM dual;
          update tmp_manprodlink set codraportp2 = vcod where codraportp2 = v_rec.codraportp2;
          INSERT INTO  RaportP2
          (CODRAPORTP2,
           CODRAPORTP1,
           CODCOMANDA1,
           CODOBIECT,
           CODMAN,
           REALIZAT,
           REBUT,
           CODOP,
           CODLOC,
           CODTARIF,
           TU,
           CODUTILAJ,
           DATASTART,
           DATASTOP,
           REFACUT,
           CODIES1,
           OBS)
          VALUES
          (vCod,
           v_Rec.CODRAPORTP1,
           v_Rec.CODCOMANDA1,
           v_Rec.CODOBIECT,
           v_Rec.CODMAN,
           v_Rec.REALIZAT,
           v_Rec.REBUT,
           v_Rec.CODOP,
           v_Rec.CODLOC,
           v_Rec.CODTARIF,
           v_Rec.TU,
           v_Rec.CODUTILAJ,
           v_Rec.DATASTART,
           v_Rec.DATASTOP,
           V_REC.REFACUT,
           V_REC.CODIES1,
           V_REC.OBS);
        END IF;
      END LOOP;

      FOR V_REC IN (SELECT * FROM TMP_MANPRODLINK) LOOP
        SELECT NVL(COUNT(*), 0) INTO NR  FROM MANPRODLINK WHERE CODRAPORTP2 = v_rec.CODRAPORTP2;
        IF NR = 0  THEN
          INSERT INTO MANPRODLINK (CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1)
          VALUES (v_rec.CODRAPORTP2, v_rec.CODCMDPRODMAN, v_rec.CANT, v_rec.CODPROGRAMF1);
        ELSE
          UPDATE MANPRODLINK
          SET
            CODRAPORTP2 = v_Rec.Codraportp2,
            CODCMDPRODMAN = v_Rec.Codcmdprodman,
            CANT = v_Rec.Cant,
            CODPROGRAMF1 = v_rec.codprogramf1
          WHERE CODRAPORTP2 = v_rec.CODRAPORTP2;
        END IF;
      END LOOP;
    end if;
  ELSE -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;RaportP&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT Seq_RaportP_CodRaportP.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;RaportP&apos;, RecId); 
    INSERT INTO RaportP ( CODRAPORTP, NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA, USERID, DATACREARE,
                          prefixdoc,carnetdoc,seriadoc,SCHIMB,Obs)
    SELECT RecId, NRDOC, DATAI, DATAS, Intreruperi, PE_FORMATIE, CODCENTRU, SECTIE, FORMATIE, PROGRAMF, SUBUNITATEA, AN, LUNA, Pkg_Globals.UserId, SysTimeStamp,
           prefixdoc,carnetdoc,seriadoc,SCHIMB,Obs
    FROM TMP_RaportP;

    FOR v_rec IN ( SELECT * FROM TMP_RaportP0)
    LOOP
      SELECT Seq_RaportP0_CodRaportP0.NEXTVAL INTO vCod FROM dual;
      UPDATE TMP_RaportP1 SET CodRaportP0 = vCOD WHERE CodRaportP0 = v_rec.CodRaportP0;

      INSERT INTO  RaportP0 ( CODRAPORTP0, CODRAPORTP, CodComanda1, Realizat, Rebut, OBS)
      VALUES ( vCod , RecId, v_rec.CodComanda1, v_rec.Realizat, v_rec.Rebut, V_REC.OBS);
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_RaportP1) LOOP
      SELECT Seq_RaportP1_CodRaportP1.NEXTVAL INTO vCod FROM dual;
      UPDATE TMP_RaportP2 SET CodRaportP1 = vCOD WHERE CodRaportP1 = v_rec.CodRaportP1;
      UPDATE TMP_RaportP3 SET CodRaportP1 = vCOD WHERE CodRaportP1 = v_rec.CodRaportP1;

      INSERT INTO  RaportP1 ( CODRAPORTP1, CODRAPORTP0, CODRAPORTP, ANGAJAT, Realizat, Indice, Rebut, ProdRealizat, ProdRebut)
      VALUES ( vCod , v_rec.CODRAPORTP0, RecId, v_rec.ANGAJAT, v_rec.Realizat, v_rec.Indice, v_rec.Rebut, v_rec.ProdRealizat, v_rec.ProdRebut);
    END LOOP;

    FOR v_rec IN (SELECT * FROM TMP_RaportP2)  LOOP
      SELECT Seq_RaportP2_CodRaportP2.NEXTVAL INTO vCod FROM dual;
      UPDATE TMP_MANPRODLINK SET CodRaportP2 = vCOD WHERE CodRaportP2 = v_rec.CodRaportP2;
      INSERT INTO  RaportP2
          (CODRAPORTP2,
           CODRAPORTP1,
           CODCOMANDA1,
           CODOBIECT,
           CODMAN,
           REALIZAT,
           REBUT,
           CODOP,
           CODLOC,
           CODTARIF,
           TU,
           CODUTILAJ,
           DATASTART,
           DATASTOP,
           REFACUT,
           CODIES1,
           OBS)
          values
           (vCod,
           v_Rec.CODRAPORTP1,
           v_Rec.CODCOMANDA1,
           v_Rec.CODOBIECT,
           v_Rec.CODMAN,
           v_Rec.REALIZAT,
           v_Rec.REBUT,
           v_Rec.CODOP,
           v_Rec.CODLOC,
           v_Rec.CODTARIF,
           v_Rec.TU,
           v_Rec.CODUTILAJ,
           v_Rec.DATASTART,
           v_Rec.DATASTOP,
           V_REC.REFACUT,
           V_REC.CODIES1,
           V_REC.OBS);
    END LOOP;

    INSERT INTO MANPRODLINK (CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1)
    SELECT CODRAPORTP2, CODCMDPRODMAN, CANT, CODPROGRAMF1 FROM TMP_MANPRODLINK;

    INSERT INTO RAPORTP3 (CODRAPORTP3, CODRAPORTP1, CODRAPORTP, CODMOTIV, ORE)
    SELECT SEQ_RAPORTP3_CODRAPORTP3.NEXTVAL, CODRAPORTP1, RecId, CODMOTIV, ORE FROM TMP_RAPORTP3;

  END IF;

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(aCARNET &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNRDOC);

  DELETE TMP_COMANDA1;
  INSERT INTO TMP_COMANDA1 (CODCOMANDA1)
  SELECT CODCMDPRODMAN 
  FROM TMP_MANPRODLINK 
  UNION ALL
  SELECT CODCMDPRODMAN 
  FROM TMP_MANPRODLINK_INITIAL; 
  UPDATE CMDPRODMAN c1
      SET
       c1.REST = c1.cant -
                   ( SELECT NVL(SUM(IL.CANT), 0)
                     FROM
                      MANPRODLINK IL
                      inner join raportp2 r2 on r2.codraportp2 = il.codraportp2
                      inner join raportp1 r1 on r1.codraportp1 = r2.codraportp1
                      inner join raportp r on r.codraportp = r1.codraportp
                     where c1.codcmdprodman = il.codcmdprodman
                     )
      WHERE
      c1.CODcmdprodmaN IN
      (SELECT CODcomanda1 FROM TMP_comanda1);
  -- mRaportProductie --&gt; 63
  PKG_CFGTABLES.EXT_POSTRECORDS(63);
  NotifyModif(Operation, RecId, &apos;RAPORTP&apos;);
  COMMIT;
END;

procedure MutaCant is
begin
  delete tmp_comanda1;
  insert into tmp_comanda1 (codcomanda1, cantcomandat, cantacceptat)
  select codraportp2, realizat, rebut
  from raportp2;

  update raportp2 set realizat = null, rebut = null;
  commit;

  begin
    execute immediate &apos;alter table raportp2 modify realizat number(13,7)&apos;;
    execute immediate &apos;alter table raportp2 modify rebut number(13,7)&apos;;
  exception when others then null;
  end;


  update raportp2 r2 set realizat = (select t2.cantcomandat from tmp_comanda1 t2 where r2.codraportp2 = t2.codcomanda1);
  update raportp2 r2 set rebut = (select t2.cantacceptat from tmp_comanda1 t2 where r2.codraportp2 = t2.codcomanda1);

  delete tmp_comanda1;
  commit;

  begin
    execute immediate &apos;alter table tmp_raportp2 modify realizat number(13,7)&apos;;
    execute immediate &apos;alter table tmp_raportp2 modify rebut number(13,7)&apos;;
  exception when others then null;
  end;
end;

end PKG_RaportP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RAPSTOCMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D637D12D5D9820620AA370C7D8B7BC799EA45922</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RAPSTOCMED IS

PROCEDURE GOLESTE_TMP IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED_CUMULAT&apos; ;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED_NAO&apos; ;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED_SUB&apos; ;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED&apos; ;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED0&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED1&apos;;
END;

PROCEDURE UMPLE_TMP(pNewData IN VARCHAR2, pOldData IN VARCHAR2, pCodSIUI IN VARCHAR2) IS
  vNewData     DATE;
  vDataRef     DATE;
  cEGN         VARCHAR2(1);
  vAn          NUMBER(4);
  vLuna        NUMBER(2);
  vZi          NUMBER(2);
  vTipGestExcl NUMBER(2) := -1;
BEGIN
  --CALL create_wm_temps_flag(&apos;PKG_RAPSTOCMED&apos;); --Se activeaza pt PG
  vNewData := To_Date(pNewData,&apos;dd.mm.yyyy&apos;);
  vDataRef := CASE WHEN pOldData IS NULL THEN vNewData ELSE To_Date(pOldData,&apos;dd.mm.yyyy&apos;) + 1 END;
  pkg_rapstocmed.GOLESTE_TMP;

  vAn   := Extract(YEAR  FROM vDataRef);
  vLuna := Extract(MONTH FROM vDataRef);
  cEGN  := Coalesce(pkg_categconst.GetValConstanta(&apos;ExclGestNeconforme&apos;,vAn,vLuna),&apos;1&apos;);
  IF cEGN = &apos;2&apos; THEN
    vTipGestExcl := 4;
  END IF;
--STERR_INSERT(&apos;UMPLE_TMP2&apos;, &apos;vNewData -&gt; &apos;||To_Char(vNewData,&apos;dd.mm.yyyy&apos;)||&apos; / vDataRef -&gt; &apos;||To_Char(vDataRef,&apos;dd.mm.yyyy&apos;)||&apos; / vAn -&gt; &apos;||vAn||&apos; / vLuna -&gt; &apos;||vLuna||&apos; / vTipGestExcl -&gt; &apos;||vTipGestExcl);
  INSERT INTO TMP_RAPSTOCMED_NAO
  SELECT codobiect, Trim(codcnas) CIM, Coalesce(coefcnas,1) coefcnas
  FROM nartobj
  WHERE Coalesce(rapcnas,1) = 1 AND Coalesce(coefcnas,1) &lt;&gt; 0 AND Trim(codcnas) IS NOT NULL;

  INSERT INTO TMP_RAPSTOCMED_SUB
  SELECT codsubunit, Trim(codsiui) CodWorkplace, Trim(REPLACE(Upper(cif), &apos;RO&apos;,&apos;&apos;)) cif
  FROM nsubunit
  WHERE Trim(codsiui) IS NOT NULL AND codsiui = pCodSIUI;

  INSERT INTO TMP_RAPSTOCMED(codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop)
  SELECT sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 0 Tip, 1 Semn, Sum(nser.rest*nao.coefcnas) CANT, To_Date(&apos;2100&apos;,&apos;yyyy&apos;) DataOp
  FROM nirstoc ns
    INNER JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = g.codsubunit
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
  WHERE ns.rest &lt;&gt; 0
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl
  GROUP BY sub.CodWorkplace, nao.CIM, Trim(ser.SERIE), Coalesce(nser.TG, ns.TG);

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- intrari in stoc
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 1 Tip, 1 Semn, nser.cantnir*nao.coefcnas CANT, Trunc(i.datacreare) DataOp,
    CASE WHEN Upper(t.simbauto) = &apos;RO&apos; THEN 1 ELSE 2 END CodTipPart,
    1 CodTipDoc, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
    CASE
      WHEN i.tipdoc = 6             THEN Trim(REPLACE(Upper(subs.cif), &apos;RO&apos;,&apos;&apos;))
      WHEN Upper(t.simbauto) = &apos;RO&apos; THEN Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;))
      ELSE                               p.den_part
    END Part,
    CASE WHEN i.tipdoc &lt;&gt; 2 THEN I.Nrdoc END NrFactura,
    CASE WHEN i.tipdoc = 2  THEN I.Nrdoc END NrAviz,
    I.DataDoc,
    NULL CodTara
  FROM intrari i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nir n ON n.codintr = i.codintr AND n.tipnir = i.tipdoc
    INNER JOIN nirstoc ns ON ns.codnir = n.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subs ON subs.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,2,5,6)
    AND n.operat = 1
    AND Coalesce(n.datacreare, i.datacreare) &gt;= vDataRef
    AND ns.cantnir &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- livrari din intrari
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 1 Tip, -1 Semn, l1.cant*nao.coefcnas CANT, Trunc(i.datacreare) DataOp,
    CASE WHEN Upper(t.simbauto) = &apos;RO&apos; THEN 1 ELSE 2 END CodTipPart,
    2 CodTipDoc, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
    CASE
      WHEN i.tipdoc = 6             THEN Trim(REPLACE(Upper(subs.cif), &apos;RO&apos;,&apos;&apos;))
      WHEN Upper(t.simbauto) = &apos;RO&apos; THEN Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;))
      ELSE                               p.den_part
    END Part,
    CASE WHEN i.tipdoc &lt;&gt; 2 THEN I.Nrdoc END NrFactura,
    CASE WHEN i.tipdoc = 2  THEN I.Nrdoc END NrAviz,
    I.DataDoc,
    NULL CodTara
  FROM intrari i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN livr l ON l.codintr = i.codintr AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
    INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
    INNER JOIN nirstoc ns ON ns.codnirstoc = nser.codnirstoc
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subs ON subs.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (1,2,5,6)
    AND i.datacreare &gt;= vDataRef
    AND l1.cant &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot,
    tip,
    semn,
    cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT --iesiri din stoc
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot,
    --- ???? ---CASE WHEN i.tipdoc = 15 AND l1.cant &gt; 0 THEN 1 ELSE  2 END Tip, -- maririle de stoc tipdoc 15 cu cu Livr sunt intrare sau iesire???
    2 Tip,
    CASE WHEN i.tipdoc = 15 THEN 1 ELSE -1 END * Sign(l1.cant) Semn,
    Abs(l1.cant)*nao.coefcnas CANT, Trunc(i.datacreare) DataOp,
    CASE
      --- ??? ---WHEN i.tipdoc = 15 THEN 1 ELSE -1 END * Sign(l1.cant) Semn,
      WHEN i.tipdoc IN (14,15)              AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 2
      WHEN i.tipdoc IN (14,15)                                                     THEN 6
      WHEN i.tipdoc IN (16)                 AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 1
      WHEN i.tipdoc IN (16)                                                        THEN 6
      WHEN Coalesce(p.persoanafizica,0) = 1 AND Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 1
      WHEN Coalesce(p.persoanafizica,0) = 1                                        THEN 6
      WHEN                                      Coalesce(S.TIPUNITJURIDICA, 0) = 1 THEN 2
      ELSE                                                                              3
    END CodTipPart, --  S.TIPUNITJURIDICA = 1 --  1 persoana fizica / 2 persoana juridica,
                                              -- cumparator de antibiotic 7 - identificata cu CNP / 8 - identificata cu CID / 9 - identificat cu pasaport / 10 - identificat cu Card EU
                                              -- 11 Unitate medicala
                    --  S.TIPUNITJURIDICA = 2 --  3 unitate de distributie angro, importator sau fabricant / 4 farmacie comunitara / 5 farmacie cu circuit inchis  / 6 altele
    CASE
      WHEN i.tipdoc IN (14,15) AND Coalesce(nser.TG, ns.TG) &lt;= i.datacreare        THEN 6
      WHEN i.tipdoc IN (14,15)                                                     THEN 4
      WHEN l1.cant &lt; 0                                                             THEN 2
      ELSE                                                                              5
    END CodTipDoc, --2 (retur), 3 (retragere), 4 (reglare stoc prin inventar), 5 (vanzare), 6 (expirare)
    CASE
      WHEN i.tipdoc IN (23)         THEN          Trim(REPLACE(Upper(subd.cif)      , &apos;RO&apos;,&apos;&apos;))
      WHEN i.tipdoc IN (16)         THEN Coalesce(Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;)), p.den_part)
      WHEN i.tipdoc IN (14,15)      THEN Coalesce(Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;)), sub.cif)
      WHEN Upper(t.simbauto) = &apos;RO&apos; THEN          Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;))
      ELSE p.den_part
    END Part,
    CASE
      WHEN i.tipdoc IN (14,15,16) THEN NULL
      WHEN i.tipdoc &lt;&gt; 20         THEN I.Nrdoc
    END NrFactura,
    CASE
      WHEN i.tipdoc IN (14,15,20) THEN I.Nrdoc
    END NrAviz,
    CASE
      WHEN i.tipdoc IN (16) THEN NULL
      ELSE I.DataDoc
    END DataDoc,
    Coalesce(Upper(t.simbauto), &apos;RO&apos;) CodTara
  FROM iesiri i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nsubunit s ON s.codsubunit = i.subunitatea
    INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
    INNER JOIN livr1 l1 ON l1.codlivr = l.codlivr
    INNER JOIN nirser nser ON nser.codnirser = l1.codnirser
    INNER JOIN nirstoc ns ON ns.codnirstoc = nser.codnirstoc
    INNER JOIN nir n ON n.codnir = ns.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subd ON subd.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (14,15,16,19,20,21,22,23)
    AND i.datacreare &gt;= vDataRef
    AND l1.cant &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  INSERT INTO TMP_RAPSTOCMED(
    codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
    CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
  SELECT -- intrari in stoc pe documente de iesire
    sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns.TG) dataExpirareLot, 2 Tip, 1 Semn, nser.cantnir*nao.coefcnas CANT, Trunc(i.datacreare) DataOp,
    CASE
      WHEN i.tipdoc IN (14,15)              THEN 1
      WHEN i.tipdoc IN (16)                 THEN 1
      WHEN Upper(t.simbauto) = &apos;RO&apos;         THEN 1
      ELSE                                       2
    END CodTipPart,
    CASE
      WHEN i.tipdoc IN (14,15) AND Coalesce(nser.TG, ns.TG) &lt;= i.datacreare THEN 6
      WHEN i.tipdoc IN (14,15)                                              THEN 4
      WHEN i.tipdoc IN (16,19,20,21,22, 23)                                 THEN 2
    END CodTipDoc,--2 (retur), 3 (retragere), 4 (reglare stoc prin inventar), 5 (vanzare), 6 (expirare)
    CASE
      WHEN i.tipdoc IN (23)         THEN          Trim(REPLACE(Upper(subd.cif)      , &apos;RO&apos;,&apos;&apos;))
      WHEN i.tipdoc IN (16)         THEN Coalesce(Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;)), p.den_part)
      WHEN i.tipdoc IN (14,15)      THEN Coalesce(Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;)), sub.cif)
      WHEN Upper(t.simbauto) = &apos;RO&apos; THEN          Trim(REPLACE(Upper(fisc.codfiscal), &apos;RO&apos;,&apos;&apos;))
      ELSE p.den_part
    END Part,
    CASE
      WHEN i.tipdoc IN (14,15,16) THEN NULL
      WHEN i.tipdoc &lt;&gt; 20         THEN I.Nrdoc
    END NrFactura,
    CASE
      WHEN i.tipdoc IN (14,15,20) THEN I.Nrdoc
    END NrAviz,
    CASE
      WHEN i.tipdoc IN (16) THEN NULL
      ELSE I.DataDoc
    END DataDoc,
    Coalesce(Upper(t.simbauto), &apos;RO&apos;) CodTara
  FROM iesiri i
    INNER JOIN tmp_rapstocmed_sub sub ON sub.codsubunit = i.subunitatea
    INNER JOIN nir n ON n.codies = i.codies AND n.tipnir = i.tipdoc
    INNER JOIN nirstoc ns ON ns.codnir = n.codnir
    INNER JOIN ngest g ON g.codgest = n.gest
    INNER JOIN nirser nser ON nser.codnirstoc = ns.codnirstoc
    INNER JOIN nserii ser ON ser.codserie = nser.codserie
    LEFT  JOIN tmp_rapstocmed_nao nao ON nao.codobiect = ns.codobiect
    LEFT  JOIN npart p ON p.codpart = i.partener
    LEFT  JOIN nagenda a ON a.codagenda = i.codlocatie
    LEFT  JOIN nlocalit loc ON loc.codlocalit = a.codlocalit
    LEFT  JOIN ntari t ON t.codtara = loc.codtara
    LEFT  JOIN npartcodfisc fisc ON fisc.cod_codfiscal = i.codfiscal
    LEFT  JOIN nsubunit subd ON subd.codsubunit = i.codsubunit
  WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (14,15,16,19,20,21,22,23)
    AND n.operat = 1
    AND Coalesce(n.datacreare, i.datacreare) &gt;= vDataRef
    AND ns.cantnir &lt;&gt; 0
    AND nao.codobiect IS NOT NULL
    AND NOT ns.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
    AND Coalesce(g.tip, 0) &lt;&gt; vTipGestExcl;

  IF cEGN = &apos;2&apos; THEN
    INSERT INTO TMP_RAPSTOCMED(
      codworkplace, cim, numarLot, dataExpirareLot, tip, semn, cant, dataop,
      CodTipPart, CodTipDoc, Part, NrFactura, NrAviz, DataDoc, CodTara )
    SELECT -- intrari in stoc pe documente de transfer din gestiuni Neconforme Excluse
      sub.CodWorkplace, nao.CIM, Trim(ser.SERIE) numarLot, Coalesce(nser.TG, ns_s.TG) dataExpirareLot,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 ELSE  2 END Tip,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 ELSE -1 END Semn,
      /*nser.cantnir*/l1.cant*nao.coefcnas CANT, Trunc(t.datacreare) DataOp,
      CASE
        WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN 1 -- intrare                      --&gt; 1 intern
        WHEN Coalesce(S.TIPUNITJURIDICA, 0) = 1  THEN 2 -- iesire S.TIPUNITJURIDICA = 1 --&gt; 2 extern
        WHEN Coalesce(S.TIPUNITJURIDICA, 0) = 2  THEN 3 -- iesire S.TIPUNITJURIDICA = 2 --&gt; 3 Unitate de distributie angro/importator/fabricant autorizat
                                                 ELSE 6                                 --&gt; 6 altele
      END CodTipPart,
      CASE WHEN Coalesce(g_s.tip, 0) = 4 THEN vTipGestExcl ELSE 3 END Tip, --1 (achizitie), 2 (retur), 3 (retragere), 4 (reglare stoc prin inventar).
      Trim(REPLACE(Upper(sub.cif), &apos;RO&apos;,&apos;&apos;)) Part,
      NULL NrFactura,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN n_d.NrNir ELSE L.NRLivr END NrAviz,
      T.DataDoc,
      CASE WHEN Coalesce(g_s.tip, 0) = vTipGestExcl THEN NULL      ELSE &apos;RO&apos; END CodTara
    FROM transf t
      INNER JOIN tmp_rapstocmed_sub sub  ON sub.codsubunit  = t.subunitatea
      INNER JOIN nsubunit           s    ON s.codsubunit    = t.subunitatea
      INNER JOIN transf1            t1   ON t1.codtransf    = t.codtransf
      INNER JOIN tmp_rapstocmed_nao nao  ON nao.codobiect   = t1.codobiect
      INNER JOIN livr               l    ON l.codtransf     = t.codtransf
      INNER JOIN livr1              l1   ON l1.codlivr      = l.codlivr AND l1.codies1 = t1.codtransf1
      INNER JOIN nirser             nser ON nser.codnirser  = l1.codnirser
      INNER JOIN nserii             ser  ON ser.codserie    = nser.codserie
      INNER JOIN nirstoc            ns_d ON ns_d.codlivr1   = l1.codlivr1
      INNER JOIN nir                n_d  ON n_d.codnir      = ns_d.codnir
      LEFT  JOIN ngest              g_d  ON g_d.codgest     = n_d.gest
      INNER JOIN nirstoc            ns_s ON ns_s.codnirstoc = l1.codnirstoc
      INNER JOIN nir                n_s  ON n_s.codnir      = ns_s.codnir
      LEFT  JOIN ngest              g_s  ON g_s.codgest     = n_s.gest
    WHERE t.operat = 1 AND t.anulat = 0 AND t.tipdoc IN (12)
      AND n_d.operat = 1
      AND Coalesce(n_d.datacreare, t.datacreare) &gt;= vDataRef
      AND l1.cant &lt;&gt; 0
      AND NOT ns_s.codioart IN (SELECT DISTINCT codioart FROM ioart1 WHERE mg = 5)
      AND ( (Coalesce(g_d.tip, 0) &lt;&gt; vTipGestExcl AND Coalesce(g_s.tip, 0) =  vTipGestExcl) OR
            (Coalesce(g_d.tip, 0) =  vTipGestExcl AND Coalesce(g_s.tip, 0) &lt;&gt; vTipGestExcl) );
  END IF;

  INSERT INTO TMP_RAPSTOCMED0 (codworkplace)
  SELECT DISTINCT CodWorkplace
  FROM TMP_RAPSTOCMED_SUB;

  INSERT INTO TMP_RAPSTOCMED1 (
    CodWorkplace, CIM, numarLot, dataExpirareLot,
    stoc,
    stocant,
    aretranz )
  SELECT
    CodWorkplace, CIM, numarLot, dataExpirareLot,
    Round(Sum(CASE WHEN Tip = 0 THEN Cant WHEN DataOp &gt; vNewData THEN - Semn * Cant ELSE 0 END)) stoc,
    Round(Sum(CASE WHEN Tip = 0 THEN Cant ELSE - Semn * Cant END)) stocant,
    Max (CASE WHEN Tip = 0 OR DataOp &gt; vNewData THEN 0 ELSE 1 END) aretranz
  FROM TMP_RAPSTOCMED
  GROUP BY CodWorkplace, CIM, numarLot, dataExpirareLot;

  DELETE FROM TMP_RAPSTOCMED1 WHERE stoc = 0 AND aretranz = 0;
  DELETE FROM TMP_RAPSTOCMED  WHERE Tip = 0;
  DELETE FROM TMP_RAPSTOCMED  WHERE DataOp &gt; vNewData;

  COMMIT;
END;

PROCEDURE GetRaport IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_RAPSTOCMED_CUMULAT&apos;;

  INSERT INTO TMP_RAPSTOCMED_CUMULAT
  SELECT
    CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, 0 Ordine, &apos;STOC ANTERIOR&apos; Tip, STOCANT CANT,
    NULL TIPPART,
    NULL TIPDOC,
    NULL PART, NULL NRDOC, NULL DATADOC, NULL CODTARA
  FROM TMP_RAPSTOCMED1
  WHERE ARETRANZ &gt; 0;

  INSERT INTO TMP_RAPSTOCMED_CUMULAT
  SELECT
    CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, 1 Ordine, &apos;INTRARI&apos; Tip, Sum(CANT),
    CASE CodTipPart
      WHEN 1 THEN &apos;intern&apos;
      WHEN 2 THEN &apos;extern&apos;
    END TIPPART,
    CASE CodTipDoc
      WHEN 1 THEN &apos;achizitie&apos;
      WHEN 2 THEN &apos;retur&apos;
      WHEN 3 THEN &apos;retragere&apos;
      WHEN 4 THEN &apos;reglare stoc prin inventar&apos;
    END TIPDOC,
    PART, Coalesce(NRFACTURA, NRAVIZ) NRDOC, DATADOC, NULL CODTARA
  FROM TMP_RAPSTOCMED
  WHERE TIP = 1
  GROUP BY CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, CodTipPart, CodTipDoc, PART, NRFACTURA, NRAVIZ, DATADOC, CODTARA;

  INSERT INTO TMP_RAPSTOCMED_CUMULAT
  SELECT
    CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, 2 Ordine, &apos;IESIRI&apos; Tip, Sum(CANT),
    CASE CodTipPart
      --Pentru farmaciile cu circuit închis si pentru farmaciile private - nsubunit.TIPUNITJURIDICA = 1
      WHEN  1 THEN &apos;persoana fizica&apos;
      WHEN  2 THEN &apos;persoana juridica&apos;
      --Pentru unitatile de distributie angro a medicamentelor, importatori sau fabricanti autorizati
      WHEN  3 THEN &apos;unitate de distributie angro a medicamentelor, importator sau fabricant autorizat&apos;
      WHEN  4 THEN &apos;farmacie comunitara&apos;
      WHEN  5 THEN &apos;farmacie cu circuit inchis&apos;
      WHEN  6 THEN &apos;altele&apos;
      --Pentru farmaciile cu circuit închis si pentru farmaciile private - nsubunit.TIPUNITJURIDICA = 1 -&gt; completare SER 1.18
      WHEN  7 THEN &apos;Persoana fizica (cetatean roman sau strain)  identificata cu CNP (cumparator de antibiotic)&apos;
      WHEN  8 THEN &apos;Persoana fizica (cetatean roman sau strain) identificata cu CID (cumparator de antibiotic)&apos;
      WHEN  9 THEN &apos;Persoana fizica cetatean strain identificat cu pasaport (cumparator de antibiotic)&apos;
      WHEN 10 THEN &apos;Persoana fizica cetatean strain identificat cu Card EU (CE) (cumparator de antibiotic)&apos;
      WHEN 11 THEN &apos;Unitate medicala&apos;
    END TIPPART,
    CASE CodTipDoc
      WHEN 2 THEN &apos;retur&apos;
      WHEN 3 THEN &apos;retragere&apos;
      WHEN 4 THEN &apos;reglare stoc prin inventar&apos;
      WHEN 5 THEN &apos;vanzare&apos;
      WHEN 6 THEN &apos;expirare&apos;
      --completare SER 1.18
      WHEN 7 THEN &apos;vanzare antibiotice fara reteta&apos;
      WHEN 8 THEN &apos;vanzare antibiotice cu reteta emisa in Romania&apos;
      WHEN 9 THEN &apos;vanzare antibiotice cu reteta emisa in strainatate&apos;
    END TIPDOC,
    PART, Coalesce(NRFACTURA, NRAVIZ) NRDOC, DATADOC, CODTARA
  FROM TMP_RAPSTOCMED
  WHERE TIP = 2
  GROUP BY CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, CodTipPart, CodTipDoc, PART, NRFACTURA, NRAVIZ, DATADOC, CODTARA;

  INSERT INTO TMP_RAPSTOCMED_CUMULAT
  SELECT
    CodWorkplace, CIM, NUMARLOT, DATAEXPIRARELOT, 3 Ordine, &apos;STOC RAPORTAT&apos; Tip, STOC CANT,
    NULL TIPPART,
    NULL TIPDOC,
    NULL PART, NULL NRDOC, NULL DATADOC, NULL CODTARA
  FROM TMP_RAPSTOCMED1;

  COMMIT;
END;

END pkg_rapstocmed;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4877642ACE9A0D5A7FC0EDCCDF022452FBCA04BE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RECLAMATII is

PROCEDURE UmpleDocAsoc(aCodDOC IN NUMBER, aTipDOC IN NUMBER, aCodDOCAsoc IN NUMBER, aTipDocAsoc IN NUMBER) 
IS
  Duplicat NUMBER(2);
BEGIN
  SELECT COUNT(*) INTO Duplicat 
	FROM DocAsoc WHERE CodDoc = aCodDoc AND TipDoc = aTipDoc AND CodDocAsoc = aCodDocAsoc AND TipDocAsoc = aTipDocAsoc;
    
  IF Duplicat = 0 then 
    INSERT INTO DOCASOC(CodDoc, Tipdoc, CodDocAsoc, TipDocAsoc) values (aCodDOC, aTipDOC, aCodDOCAsoc, aTipDocAsoc);
  END IF;
	COMMIT;
End;

PROCEDURE RezolvaReclamatie(RecID in number, aCodDOC IN NUMBER, aTipDOC IN NUMBER, aDataDoc in Date) IS
BEGIN
  update Reclamatii set 
    CodDocR = aCodDoc,
		TipdocR = aTipDoc, 
		Rezolvat = 1,
		DataRez = aDataDoc
	where CodReclamatie = RecID;
End;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodRECLAMATIE INTO Tmp FROM RECLAMATII WHERE CodRECLAMATIE = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  -- mReclamatii --&gt; 97
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 97);
 	DELETE FROM RECLAMATII WHERE CodRECLAMATIE = RecId ;
 	DELETE FROM RECLAMATII1 WHERE CodRECLAMATIE = RecId ;
 	DELETE FROM RECLAMATII2 WHERE CodRECLAMATIE = RecId ;
  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = 97)or(CODDOCASOC = RECID AND TIPDOCASOC = 97);
  PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
  PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);

	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RECLAMATII FIELDS( CodRECLAMATIE ) VALUES (0) ;
  -- mReclamatii --&gt; 97
  PKG_CFGTABLES.EXT_INSERTRECORD(97); 
  COMMIT;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

PROCEDURE SOLVENRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  IF (CARNETDOC_I &lt;&gt; 0) AND (NRDOC_I &lt;&gt; 0) AND (aCARNET &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I) THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNET, aNRDOC);
END;


PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aTipDoc Number(20);
aCodDoc Number(20);
BEGIN
  if RecID &gt; 0 then 
  	Select TipDoc, CodDoc into aTipDoc, aCodDoc from Reclamatii where CodReclamatie = RecId;
		if aTipDoc in (1,2,3,4,5,9) then 
			Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodIntr1 from Intrari1 where CodIntr = aCodDoc);
		elsif aTipDoc in (8,18) then 
			Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodComanda1 from Comanda1 where CodComanda = aCodDoc);
		elsif aTipDoc in (19,20,21,26) then 
			Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodIes1 from Iesiri1 where CodIes = aCodDoc);
		elsif aTipDoc in (10,27) then 
			Delete from Reclamatii1 where CodReclamatie = RecId and CodDoc1 not in (Select CodContract1 from Contract1 where CodContract = aCodDoc);
		end if;
	end if;
	INSERT INTO  TMP_RECLAMATII 
	(   
    CODRECLAMATIE,
    ANULAT,       
    BLOCAT,       
    OPERAT,       
    CODDOC,       
    TIPDOC,       
    NRDOC,        
    SERIADOC,     
    DATADOC,      
    CARNETDOC,    
    CodSubunit, 
    codutilizator, 
    Motiv,
    CodPart,
    Reclamatie,
    CodDocR, 
    TipDocR,
    Rezolvat,
    DATARez,
    CodResp,
    IMPUTABILA,
    TIPIMPUT,  
    CODPIMPUT,
    CodPersC,
    CodLocatie,
    VALOARE
   )
	SELECT 
    R.CODRECLAMATIE,
    R.ANULAT,       
    R.BLOCAT,       
    R.OPERAT,       
    R.CODDOC,       
    R.TIPDOC,       
    R.NRDOC,        
    R.SERIADOC,     
    R.DATADOC,      
    R.CARNETDOC,    
    R.CodSubunit, 
    R.codutilizator, 
    R.Motiv,
    R.CodPart,
    R.Reclamatie,
    R.CodDocR, 
    R.TipDocR,
    R.Rezolvat,
    R.DATARez,
    R.CodResp,
    R.IMPUTABILA,
    R.TIPIMPUT,  
    R.CODPIMPUT,
    R.CodPersC,
    R.CodLocatie,
    0                       
  FROM RECLAMATII R
  WHERE R.CodRECLAMATIE = RECID;

  INSERT INTO  TMP_RECLAMATII1
	(   
    CODRECLAMATIE1,
    codReclamatie, 
    CodDoc1, 
    Cant, 
    Obs,
    CodObiect, 
    UMSec,
    D1,
    D2,
    D3,
    CantUMs,
    PU,
    Valoare,
    Imputabil,
    CodIntern,
    CodExtern
	)
	SELECT 
	    CODRECLAMATIE1,
      R1.codReclamatie, 
      CodDoc1, 
      R1.Cant, 
      R1.Obs,
			Case when  C.TipDoc is not null then  C1.CodObiect  
				   when  I.TipDoc is not null then  I1.CodObiect
				   when  E.TipDoc is not null then  E1.CodObiect
				   when CT.TipDoc is not null then CT1.CodObiect
					 else 0
			end,
			Case when  C.TipDoc is not null then  C1.UMSec  
           when  I.TipDoc is not null then  I1.UMSec
           when  E.TipDoc is not null then  E1.UMSec
           when CT.TipDoc is not null then CT1.UMSec
           else 0
      end,
      R1.D1,
      R1.D2,
      R1.D3,
      R1.CantUMs,
 			Case when  C.TipDoc is not null then  C1.PU  
           when  I.TipDoc is not null then  I1.PU
           when  E.TipDoc is not null then  E1.PU
           when CT.TipDoc is not null then CT1.PRET
           else 0
      end PU, 
 			Case when  C.TipDoc is not null then C1.PU*R1.Cant  
           when  I.TipDoc is not null then I1.PU*R1.Cant
           when  E.TipDoc is not null then E1.PU*R1.Cant
           when CT.TipDoc is not null then CT1.PRET*R1.Cant
           else 0
      end Valoare,
      R1.Imputabil,
      o.codintern,
      o.codextern
  FROM TMP_RECLAMATII R 
       left join Comanda  C   on C.CodComanda   = R.CodDoc and  C.TipDoc = R.TipDoc  
       left join Intrari  I   on I.CodIntr      = R.CodDoc and  I.TipDoc = R.TipDoc  
       left join Iesiri   E   on E.CodIes       = R.CodDoc and  E.TipDoc = R.TipDoc
       left join Contract CT  on CT.CodContract = R.CodDoc and CT.TipDoc = R.TipDoc
       inner join RECLAMATII1 R1 on R1.Codreclamatie = R.CodReclamatie
       left join Comanda1  C1   on  C1.CodComanda1  = R1.CodDoc1  
       left join Intrari1  I1   on  I1.CodIntr1     = R1.CodDoc1  
       left join Iesiri1   E1   on  E1.CodIes1      = R1.CodDoc1  
       left join Contract1 CT1  on CT1.CodContract1 = R1.CodDoc1  
       LEFT JOIN NartObj o ON o.CodObiect  = coalesce(c1.codobiect,i1.CodObiect,e1.codobiect,CT1.CodObiect)
       LEFT JOIN Nart A    ON a.CodArticol = o.CodArticol
  where R1.CodReclamatie = RecId;

  update  TMP_RECLAMATII R 
     set R.Valoare = (Select SUM(R1.valoare) from TMP_RECLAMATII1 R1 where R.CodReclamatie = R1.CodReclamatie);
  
  update  TMP_RECLAMATII1 R1 
     set R1.DenObiect = (Select O.Denumire from NArtOBJ O where O.CodObiect = R1.CodObiect),
         R1.DenUM     = (Select U.DEN_UM1 from NUM1 U where U.CodUM1 = R1.UMSec);

  INSERT INTO  TMP_RECLAMATII2
	(   
   CODRECLAMATIE2,
   codReclamatie, 
   CodPers
	)
	SELECT 
	 CODRECLAMATIE2,
   codReclamatie, 
   CodPers 
  FROM RECLAMATII2
  where CodReclamatie = RecId;
  -- mReclamatii --&gt; 97
  PKG_CFGTABLES.EXT_GOTORECORD(97);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
Cod number(20);
aCARNETDOC number(20);
aNRDOC number(20); 
BEGIN
	select CarnetDoc, NrDoc into aCarnetDoc, aNrDoc from Tmp_Reclamatii; 
  
  -- mReclamatii --&gt; 97
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (97);
  
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodRECLAMATIE INTO RECID FROM TMP_RECLAMATII;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE RECLAMATII
    SET
    ( CODRECLAMATIE,
      ANULAT,
      BLOCAT,
      OPERAT,
      CODDOC,
      TIPDOC,
      NRDOC,
      SERIADOC,
      DATADOC,
      CARNETDOC,
      CodSubunit,
      codutilizator,
      Motiv,
      CodPart,
      Reclamatie,
      CodDocR, 
      TipDocR,
      Rezolvat,
      DATARez,
      CodResp,
      IMPUTABILA,
      TIPIMPUT,  
      CODPIMPUT,
      CodPersC,
      CodLocatie              
     )
      = 
     (SELECT 
        CODRECLAMATIE, 
        ANULAT,        
        BLOCAT,        
        OPERAT,        
        CODDOC,        
        TIPDOC,        
        NRDOC,         
        SERIADOC,      
        DATADOC,       
        CARNETDOC,     
        CodSubunit,    
        codutilizator, 
        Motiv,
        CodPart,
        Reclamatie,
        CodDocR, 
        TipDocR,
        Rezolvat,
        DATARez,
        CodResp,
        IMPUTABILA,
        TIPIMPUT,  
        CODPIMPUT,
        CodPersC,
        CodLocatie              
     FROM TMP_RECLAMATII)
     WHERE CodRECLAMATIE = RECID;

--Reclamatii1  

    DELETE FROM Reclamatii1 
    where CODReclamatie = RecID 
    and CodReclamatie1 not in (Select CODReclamatie1 from TMP_Reclamatii1);

    for v_rec in (select * from TMP_Reclamatii1 where CODReclamatie1 &lt; 0) loop
      INSERT INTO Reclamatii1
        ( 
          codReclamatie1,
          codReclamatie, 
          CodDoc1, 
          Cant, 
          Obs,
          D1,
          D2,
          D3,
          CantUMs,
          PU,
          Imputabil
         )
        Values 
        ( SEQ_RECLAMATII1_CODRECLAMATIE1.Nextval,
          RecId ,
          V_REC.CodDoc1, 
          V_REC.Cant, 
          V_REC.Obs,
          V_REC.D1,
          V_REC.D2,
          V_REC.D3,
          V_REC.CantUMs,
          V_REC.PU,
          V_REC.IMPUTABIL            
          );
    end loop;
    for v_rec in (select * from TMP_Reclamatii1 where CODReclamatie1 &gt; 0) loop
      update Reclamatii1 set 
        Cant = v_rec.Cant, 
        Obs = v_rec.Obs,
        D1 = V_REC.D1,
        D2 = V_REC.D2,
        D3 = V_REC.D3,
        CantUMs = V_REC.CantUMs,
        PU = V_REC.PU,
        IMPUTABIL = V_REC.IMPUTABIL
      where CODReclamatie1 = v_rec.CODReclamatie1;
    end loop;

    --Reclamatii2  
    DELETE FROM Reclamatii2 
    where CODReclamatie = RecID 
    and CodReclamatie2 not in (Select CODReclamatie2 from TMP_Reclamatii2);

    for v_rec in (select * from TMP_Reclamatii2 where CODReclamatie2 &lt; 0) loop
      INSERT INTO Reclamatii2
        ( 
          codReclamatie2,
          codReclamatie, 
          CodPers
         )
        Values 
        ( SEQ_RECLAMATII2_CODRECLAMATIE2.Nextval,
          RecId ,
          V_REC.CodPers
          );
    end loop;
    for v_rec in (select * from TMP_Reclamatii2 where CODReclamatie2 &gt; 0) loop
      update Reclamatii2 set 
        CodPers = V_REC.CodPers
      where CODReclamatie2 = v_rec.CODReclamatie2;
    end loop;
  ELSE  -- INSERT
    SELECT SEQ_RECLAMATII_CodRECLAMATIE.NextVal INTO RecId FROM DUAL;  
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;RECLAMATII&apos;, RecId);
    INSERT INTO RECLAMATII(
      CODRECLAMATIE, 
      ANULAT,        
      BLOCAT,        
      OPERAT,        
      CODDOC,        
      TIPDOC,        
      NRDOC,         
      SERIADOC,      
      DATADOC,       
      CARNETDOC,     
      CodSubunit,    
      codutilizator, 
      Motiv,
      CodPart,
      Reclamatie,
      CodDocR, 
      TipDocR,
      Rezolvat,
      DATARez,
      CodResp,
      IMPUTABILA,
      TIPIMPUT,  
      CODPIMPUT,
      CodPersC,
      CodLocatie )             
    SELECT 
      RECID , 
      ANULAT,        
      BLOCAT,        
      OPERAT,        
      CODDOC,        
      TIPDOC,        
      NRDOC,         
      SERIADOC,      
      DATADOC,       
      CARNETDOC,     
      CodSubunit,    
      codutilizator, 
      Motiv,
       CodPart,
      Reclamatie,
      CodDocR, 
      TipDocR,
      Rezolvat,
      DATARez,
      CodResp,
      IMPUTABILA,
      TIPIMPUT,  
      CODPIMPUT,
      CodPersC,
      CodLocatie 
    FROM TMP_RECLAMATII;

    for v_rec in (select * from TMP_RECLAMATII1) loop
      INSERT INTO RECLAMATII1 
      ( 
        codReclamatie1,
        codReclamatie, 
        CodDoc1, 
        Cant, 
        Obs,
        D1,
        D2,
        D3,
        CantUMs,
        PU,
        Imputabil   
      )
      Values 
      ( SEQ_RECLAMATII1_CODRECLAMATIE1.Nextval,
        RecId ,
        V_REC.CodDoc1, 
        V_REC.Cant, 
        V_REC.Obs,
        V_REC.D1,
        V_REC.D2,
        V_REC.D3,
        V_REC.CantUMs,
        V_REC.PU,
        V_REC.IMPUTABIL
      );
    end loop;

    for v_rec in (select * from TMP_RECLAMATII2) loop
        INSERT INTO RECLAMATII2 
        ( 
          codReclamatie2,
          codReclamatie, 
          CodPers   
        )
          Values 
          ( SEQ_RECLAMATII2_CODRECLAMATIE2.Nextval,
            RecId ,
            V_REC.CodPers
            );
    end loop;
  END IF;
  IF (CARNETDOC_I &lt;&gt; 0) AND (NRDOC_I &lt;&gt; 0) AND (aCARNETDOC &lt;&gt; CARNETDOC_I OR aNRDOC &lt;&gt; NRDOC_I) THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
  PKG_CARNETEDOC.SOLVENUMARDOC(aCARNETDOC, aNRDOC);
  -- mReclamatii --&gt; 97
  PKG_CFGTABLES.EXT_POSTRECORDS(97);
  NotifyModif(Operation, RecId, &apos;RECLAMATII&apos;);
  COMMIT;
END; 

end PKG_RECLAMATII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F673190D4B410001F28DB4E4723E7BFE1C05360</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REG IS
  
	PROCEDURE SetBankReg(bank_p IN NUMBER) IS
  BEGIN
    bank_reg := bank_p;
  END;
  
  FUNCTION GetBankReg RETURN NUMBER IS
  BEGIN
    RETURN bank_reg;
  END;
    
  PROCEDURE SetMonedaReg(moneda_p IN NUMBER) IS
  BEGIN
    moneda_reg := moneda_p;
  END;
  
  FUNCTION GetMonedaReg RETURN NUMBER IS
  BEGIN
    RETURN moneda_reg;
  END;
  
  PROCEDURE SetCursReg(curs_p IN NUMBER) IS
  BEGIN
    curs_reg := curs_p;
  END;
  
  FUNCTION GetCursReg RETURN NUMBER IS
  BEGIN
    RETURN curs_reg;
  END;
  
  PROCEDURE SetDataReg(data_p IN VARCHAR2) IS
  BEGIN
    data_reg := TO_DATE(data_p, &apos;DD.MM.YYYY&apos;);
    zi_reg := EXTRACT(DAY FROM data_reg);
    luna_reg := EXTRACT(MONTH FROM data_reg);
    an_reg := EXTRACT(YEAR FROM data_reg);
  END;
  
  FUNCTION GetDataReg RETURN DATE IS
  BEGIN
    RETURN data_reg;
  END;
  
  FUNCTION GetLunaReg RETURN NUMBER IS
  BEGIN
    RETURN luna_reg;
  END;
  
  FUNCTION GetAnReg RETURN NUMBER IS
  BEGIN
    RETURN an_reg;
  END;
  
  /*PROCEDURE SetSubunitReg(subunit_p IN NUMBER) IS
  BEGIN
    subunit_reg := subunit_p;
  END;
  
  FUNCTION GetSubunitReg RETURN NUMBER IS
  BEGIN
    RETURN subunit_reg;
  END;*/
  
  PROCEDURE SetCursParamsReg(data_p IN VARCHAR2, bank_p IN NUMBER, moneda_p IN NUMBER) IS
  BEGIN
    SetDataReg(data_p);
    SetBankReg(bank_p);
    SetMonedaReg(moneda_p);
  END;
  
  PROCEDURE SetParamsReg(data_p IN VARCHAR2, moneda_p IN NUMBER, curs_p IN NUMBER/*, subunit_p IN NUMBER*/) IS
  BEGIN
    SetDataReg(data_p);
    SetMonedaReg(moneda_p);
    SetCursReg(curs_p);
    /*SetSubunitReg(subunit_p);*/
  END;
  
  FUNCTION GetLastRegDate(/*subunit_p IN NUMBER, */moneda_p IN NUMBER, tipreg_p IN NUMBER) RETURN DATE IS
    tmp DATE;
  BEGIN
    SELECT MAX(DataDoc) INTO tmp FROM REG WHERE CodMoneda = moneda_p/* AND CodSubunit = subunit_p*/ AND TipReg = tipreg_p
		AND TO_DATE(&apos;01.&apos; || TO_CHAR(EXTRACT(MONTH FROM DataDoc)) || &apos;.&apos; || TO_CHAR(EXTRACT(YEAR FROM DataDoc)), &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH;
    IF tmp IS NULL THEN
		  RETURN TO_DATE(&apos;01.01.0001&apos;, &apos;DD.MM.YYYY&apos;);
		ELSE
		  RETURN tmp;
		END IF;
    EXCEPTION WHEN OTHERS THEN RETURN TO_DATE(&apos;01.01.0001&apos;, &apos;DD.MM.YYYY&apos;); -- conventie
  END;
  
  /*
	FUNCTION GetObligCurs(codgeneral_p IN NUMBER, curs_p IN NUMBER) RETURN NUMBER IS
	  curs_reg NUMBER(20,4);
  BEGIN		
		SELECT
      Curs INTO curs_reg
	  FROM
		  GENERAL_REG
		WHERE
		  CodGeneral = codgeneral_p AND
			Data = (SELECT MAX(Data) FROM GENERAL_REG WHERE CodGeneral = codgeneral_p AND TO_DATE(&apos;01.&apos; || TO_CHAR(EXTRACT(MONTH FROM Data)) || &apos;.&apos; || TO_CHAR(EXTRACT(YEAR FROM Data)), &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH);
		RETURN curs_reg;
		EXCEPTION WHEN OTHERS THEN RETURN curs_p;
  END;
	*/
  
  FUNCTION GetTrezorCurs(codtrezor1_p IN NUMBER, subunit_p IN NUMBER, moneda_p IN NUMBER, curs_p IN NUMBER) RETURN NUMBER IS
    tmp NUMBER(20,4) := 0;
    tmp_cod_reg NUMBER(20);
    cod_last_reg NUMBER(20);
    num_reg NUMBER(20);
  BEGIN
    SELECT COUNT(*) INTO num_reg FROM REG WHERE CodMoneda = moneda_p AND CodSubunit = subunit_p AND TipReg = 45 AND EXTRACT(YEAR FROM DataDoc) = PKG_GLOBALS.GETANLUCRU AND EXTRACT(MONTH FROM DataDoc) = PKG_GLOBALS.GETLUNALUCRU;
    IF num_reg = 0 THEN
      -- nu exista nici o regularizare in luna de lucru
      -- doar ADD posibil
      SELECT CodReg INTO cod_last_reg FROM REG WHERE DataDoc = GetLastRegDate(/*subunit_p, */moneda_p, 45) AND TipReg = 45;
    ELSE
      -- exista cel putin o regularizare in luna de lucru
      SELECT CodReg INTO tmp_cod_reg FROM TMP_REG;
      IF tmp_cod_reg = 0 THEN
        -- ADD
        SELECT CodReg INTO cod_last_reg FROM REG WHERE DataDoc = GetLastRegDate(/*subunit_p, */moneda_p, 45) AND TipReg = 45;
      ELSE
        -- EDIT
        SELECT CodReg INTO cod_last_reg FROM REG WHERE CodMoneda = moneda_p/* AND CodSubunit = subunit_p*/ AND TipReg = 45 AND DataDoc = (SELECT MAX(DataDoc) FROM REG WHERE DataDoc &lt; GetLastRegDate(/*subunit_p, */moneda_p, 45));
      END IF;
    END IF;
    SELECT Curs INTO tmp FROM TREZOR1_REG WHERE CodTrezor1 = codtrezor1_p AND CodReg = cod_last_reg;
    IF tmp IS NULL THEN
		  RETURN curs_p;
		ELSE
		  RETURN tmp;
		END IF;
    EXCEPTION WHEN OTHERS THEN RETURN curs_p;
  END;
    
  FUNCTION GetCursBanca(data_p IN VARCHAR2, banca_p IN NUMBER, moneda_p IN NUMBER) RETURN NUMBER IS
    tmp NUMBER(20,4) := -1;
    data_curs DATE;
  BEGIN
    data_curs := TO_DATE(data_p, &apos;DD.MM.YYYY&apos;);
    SELECT Valoare INTO tmp
    FROM NMONEDE1
    WHERE Data = (SELECT MAX(Data) FROM NMONEDE1 WHERE CodBanca = banca_p AND CodMoneda = moneda_p AND Data &lt;= data_curs)
          and codbanca = banca_p and codmoneda = moneda_p;
		IF tmp IS NULL THEN
		  curs_reg := 0;
		ELSE
      curs_reg := tmp;
		END IF;
    RETURN curs_reg;
    EXCEPTION WHEN OTHERS THEN RETURN -1;
  END;
	
	FUNCTION GetNumRegsPerMonth(tip_p IN NUMBER, month_p IN NUMBER, year_p IN NUMBER, moneda_p IN NUMBER, codreg_p IN NUMBER) RETURN NUMBER IS
	  tmp NUMBER(20);
	BEGIN
	  SELECT
		  COUNT(*) INTO tmp
	  FROM
		  REG
		WHERE
		  CodReg &lt;&gt; codreg_p AND
		  TipReg = tip_p AND
			CodMoneda = moneda_p AND
			EXTRACT(MONTH FROM DataDoc) = month_p AND
			EXTRACT(YEAR FROM DataDoc) = year_p;
		RETURN tmp;
		EXCEPTION WHEN OTHERS THEN RETURN -1;
	END;

FUNCTION RegLeasing(sDataReg IN VarChar2)RETURN VarChar2
IS
  aCurs number;
	V number;
	DataReg date;
	Total number := 0;
	Cate  number := 0;
begin
	DataReg := TO_DATE(sDataReg,&apos;dd.mm.yyyy&apos;);
	for V_rec in 
	(
	 select c.codcontract, c.curs OldCurs, C.CodBanca, C.Moneda, Nvl(C.ProcMajCurs, 0) Maj, c0.CodContract0, C.SUBUNITATEA
	 from contract0 c0
	inner join Contract C on c.codcontract = c0.codcontract and c.moneda &gt; 0
	left join ( Select CodContract 
	 					  from Contract0 x 
							where x.TipLinie = 3 
										 or
										 (x.TipLinie = 2 and x.Data &gt;= DataReg) 
						) C0x on C0x.CodContract = C.CodContract
	where c.Tipdoc = 25 and c0.tiplinie = 1 and c0.Facturat = 1 
				and c0x.CodContract is null
	) loop
  	Total := Total + 1;
  	Select Count(*) into V from Contract2 where CodContract = v_rec.CodContract and Nvl(CodDoc,0) = 0 and Data &lt;= DataReg; 
		if V = 0 then 
			Select Sum(Suma) into V from Contract2 where CodContract = v_rec.CodContract and Data &gt; DataReg; 
			aCurs := PKG_MONEDE.GETCURSMONEDA(V_rec.Moneda, V_rec.CodBanca, TO_DATE(sDataReg,&apos;dd.mm.yyyy&apos;));
			aCurs := Round(aCurs * (100.0 + V_rec.Maj)/100.0, 4);
			V := V * (aCurs - v_rec.OldCurs);
			Cate := Cate + 1;
			Insert into Contract0 (  
				CodContract0,
				CodContract, Data, Suma, Curs, TipLinie, OldCurs)
			Values (
				seq_CONTRACT0_CodContract0.nextval,
				v_rec.CodContract, DataReg, V, aCurs, 2, v_rec.OldCurs);
			
			Update Contract Set curs = aCurs where CodContract = v_rec.CodContract;
			
			Select COUNT(*) into v from jurnal1 
			where  coddoc = v_rec.CodContract 
			and tipdoc = 25 
			and An = Extract(Year from DataReg) 
			and Luna = Extract(Month from DataReg);

			if V &gt; 0 then
				update jurnal1 set dirty = 1 where coddoc = v_rec.CodContract and tipdoc = 25;
			else 
				INSERT INTO JURNAL
										 (CODJURNAL, CODDOC,  TIPDOC, INDEXLOCAL, SUBUNITATEA,  AN,  LUNA)
							 VALUES(SEQ_JURNAL_CODJURNAL.NEXTVAL, v_rec.CodContract, 25, v_rec.CodContract, v_rec.SUBUNITATEA, Extract(Year from DataReg), Extract(Month from DataReg));
				INSERT INTO JURNAL1
										 (CODJURNAL1, CODDOC,  TIPDOC, INDEXLOCAL, SUBUNITATEA,  AN,  LUNA, Dirty)
							 VALUES(SEQ_JURNAL1_CODJURNAL1.NEXTVAL, v_rec.CodContract, 25, 1, v_rec.SUBUNITATEA, Extract(Year from DataReg), Extract(Month from DataReg), 1);
			end if;
			
	  end if;
	end loop;
	Commit;
	Return Cate||&apos;/&apos;||Total;
end;

END PKG_REG; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C371D5506F8172C1552DC27E40B6651F56D972BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REGOSS IS

  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER) IS
    tmp NUMBER(20);
  BEGIN
    SELECT CODREGOSS INTO tmp FROM REGOSS WHERE CODREGOSS = RecID FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecID IN NUMBER) IS
  BEGIN
    --     PKG_GLOBALS.MarkDirtyJurnal;
    SP_LOCKRECORD(RecID);
  
    DELETE FROM REGOSS1 WHERE CODREGOSS = RecID;
  
    DELETE FROM REGOSS WHERE CODREGOSS = RecID;
  
    FOR V_REC IN
      (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 108) -- mRegularOSS = 108
    LOOP
      UPDATE NCONTRUL
      SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

       UPDATE NCONTRUL
       SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
       WHERE CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

    END LOOP;
			
	  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 108;
 	  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 108;
    NotifyModif(2, RecId, &apos;REGOSS&apos;);
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    DELETE FROM TMP_REGOSS;
    INSERT INTO TMP_REGOSS (CodRegOSS) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecID IN NUMBER) IS
    vTrimestru Number(1);
    vCursReg Number(23,7);
    vMoneda Number;
    nrRanduriModif Number;
  BEGIN
    DELETE FROM TMP_REGOSS;
    INSERT INTO TMP_REGOSS
      (CODREGOSS,
       TIPREG,
       NRDOC,
       DATADOC,
       TRIMESTRUL,
       CODBANK,
       CODMONEDA,
       CURS,
       DIRTY,
       OBS,
       CODSUBUNIT,
       AN,
       LUNA,
       CODGEST,
       CODANALIZA,
       CODANALIZANOD,
       CODCENTRU,
       CURS_IFRS,
       SIMBOLMONEDA,
       SIMBOLBANK)
      (SELECT r.CODREGOSS,
               r.TIPREG,
              r.NRDOC,
              r.DATADOC,
              r.TRIMESTRUL,
              r.CODBANK,
              r.CODMONEDA,
              r.CURS,
              r.DIRTY,
              r.OBS,
              r.CODSUBUNIT,
              r.AN,
              r.LUNA,
              r.CODGEST,
              r.CODANALIZA,
              r.CODANALIZANOD,
              r.CODCENTRU,
              r.CURS_IFRS,
              m.SIMBOL,
              b.SIMBOL
         FROM REGOSS r
         LEFT OUTER JOIN NMONEDE m
           ON m.CODMONEDA = r.CODMONEDA
         LEFT OUTER JOIN NBANK b
           ON b.CODBANK = r.CODBANK
        WHERE r.CODREGOSS = RecID);
    select ross.trimestrul, ross.curs, ross.codmoneda into vTrimestru, vCursReg, vMoneda from tmp_regoss ross;
    -- populez TMP_REGOSS1;
    DELETE FROM TMP_REGOSS1;
    INSERT INTO TMP_REGOSS1
      (CODREGOSS1,
       CODREGOSS,
       CODDOC,                       
       TIPDOC,       
       TVADOCVAL,
       TVADOC,
       TVADOCREG,
       CODGEST,
       CONT,
       SIMBOLCONT,
       SEMN,
       CURS,
       SEMNIFICATIE,
       DIFERENTA,
       CODPART,
       DEN_PART,
       DOC,
       SUBUNITATEA,
       CODTVASERV,
       CODTVASERV1,
       modificari)
      select rs1.CODREGOSS1,
             rs1.CODREGOSS,
             rs1.CODDOC,                       
             rs1.TIPDOC,       
             rs1.TVADOCVAL,
             rs1.TVADOC,
             rs1.TVADOCREG,
             rs1.CODGEST,
             rs1.CONT,
             PKG_PLANCONTURI.GETSIMBOLCONT(rs1.CONT),
             rs1.SEMN,
             rs1.CURS,
             rs1.SEMNIFICATIE,
             rs1.TVADOCREG - rs1.TVADOCVAL,
             part.codpart,
             part.den_part,
             ies.seriadoc||&apos; &apos;||ies.nrdoc||&apos;/&apos;||to_char(ies.datadoc, &apos;dd.mm.yyyy&apos;) as doc,
             ies.subunitatea,
             ies.codtvaserv,
             tsr1.codtvaserv1,
             0
        from REGOSS1 rs1
        join iesiri ies on ies.codies = rs1.coddoc
        join npart part on part.codpart = ies.partener
        left join tvaserv tsr on tsr.codtvaserv = ies.codtvaserv
        left join tvaserv1 tsr1 on tsr1.codtvaserv = tsr.codtvaserv 
                                     and pkg_globals.AnLunaLucru BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
       where CODREGOSS = RecID;
		INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL WHERE TIPDOC = 108 AND CODDOC = RECID);
		INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 108 AND CODDOC = RECID);
		DELETE TMP_RULAJ;

    GenerateDataXTrimestru(vTrimestru, vCursReg, vMoneda);  
    select count(*) into nrRanduriModif  from tmp_regoss1 rs1 where coalesce(rs1.modificari,0) = 1;
    
    if nrRanduriModif = 0 then
         select count(*) into nrRanduriModif
         from regoss1 rs1 
         left join tmp_regoss1 trs1 on trs1.codregoss1 = rs1.codregoss1
         where rs1.codregoss = RecID
         and trs1.codregoss1 is null;
    end if;

    if (nrRanduriModif &gt; 0) then
      update jurnal1 j1 set dirty = 1 where j1.TIPDOC = 108 AND j1.CODDOC = RECID;
    end if;
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER) IS
	  NR NUMBER(20);
	  TMP_NR NUMBER(20);
  BEGIN
    IF Operation = 0 THEN
      -- UPDATE
      SELECT CodRegOSS INTO RecID FROM TMP_REGOSS;
      UPDATE REGOSS
         SET (CODREGOSS,
              TIPREG,
              NRDOC,
              DATADOC,
              TRIMESTRUL,
              CODBANK,
              CODMONEDA,
              CURS,
              DIRTY,
              OBS,
              CODSUBUNIT,
              AN,
              LUNA,
              CODGEST,
              CODANALIZA,
              CODANALIZANOD,
              CODCENTRU,
              CURS_IFRS) =
             (SELECT CODREGOSS,
                     TIPREG,
                     NRDOC,
                     DATADOC,
                     TRIMESTRUL,
                     CODBANK,
                     CODMONEDA,
                     CURS,
                     DIRTY,
                     OBS,
                     CODSUBUNIT,
                     AN,
                     LUNA,
                     CODGEST,
                     CODANALIZA,
                     CODANALIZANOD,
                     CODCENTRU,
                     CURS_IFRS
                FROM TMP_REGOSS)
       WHERE CODREGOSS = RecID;
    
      DELETE FROM REGOSS1 WHERE CODREGOSS = RecID;
    
      INSERT INTO REGOSS1
        (CODREGOSS1,
         CODREGOSS,
         CODDOC,                       
         TIPDOC,        
         TVADOCVAL,
         TVADOC,
         TVADOCREG,
         CODGEST,
         CONT,
         SEMN,
         CURS,
         SEMNIFICATIE,
         SUBUNITATEA)
        (SELECT SEQ_REG1_CODREG1.NEXTVAL,
                RecID,
                CODDOC,                       
                TIPDOC,       
                TVADOCVAL,
                TVADOC,
                TVADOCREG,
                CODGEST,
                CONT,
                SEMN,
                CURS,
                SEMNIFICATIE,
                SUBUNITATEA
           FROM TMP_REGOSS1);
   		DELETE FROM JURNAL1 WHERE TIPDOC = 108 AND CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);
   		FOR V_REC IN
   			(SELECT * FROM TMP_JURNAL1)
   		LOOP
   			IF V_REC.CODJURNAL1 &gt; 0 THEN
   			  UPDATE JURNAL1
   				SET
   				  CODDOC = V_REC.CODDOC,
   					TIPDOC = V_REC.TIPDOC,
   					INDEXLOCAL = V_REC.INDEXLOCAL,
   					CODBAZAD = V_REC.CODBAZAD,
            ICONTBAZAD = V_REC.ICONTBAZAD,
            TIPBAZAD = V_REC.TIPBAZAD,
            CODBAZAC = V_REC.CODBAZAC,
            ICONTBAZAC = V_REC.ICONTBAZAC,
            TIPBAZAC = V_REC.TIPBAZAC,
            CODDESCRD = V_REC.CODDESCRD,
            ICONTD = V_REC.ICONTD,
            TIPCONTD = V_REC.TIPCONTD,
            ANALITICCONTD = V_REC.ANALITICCONTD,
            CODDESCRC = V_REC.CODDESCRC,
            ICONTC = V_REC.ICONTC,
            TIPCONTC = V_REC.TIPCONTC,
            ANALITICCONTC = V_REC.ANALITICCONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE,
            VALOAREV = V_REC.VALOAREV,
            OBS = V_REC.OBS,
            AN = V_REC.AN,
            LUNA = V_REC.LUNA,
            DIRTY = V_REC.DIRTY,
            SUBUNITATEA = V_REC.SUBUNITATEA,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
            DATADOC = V_REC.DATADOC,
            DOCUMENT = V_REC.DOCUMENT
   				WHERE CODJURNAL1 = V_REC.CODJURNAL1;
   			ELSE
   			  INSERT INTO JURNAL1
            (
              CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
              CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
              CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
              GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
          VALUES
            (
              SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,
              V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
              V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
   			END IF;
   		END LOOP;
   		
      DELETE FROM JURNAL WHERE TIPDOC = 108 AND CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);
   		
      FOR V_REC IN
   			(SELECT * FROM TMP_JURNAL)
   		LOOP
   			IF V_REC.CODJURNAL &gt; 0 THEN
   			  UPDATE JURNAL
   				SET  
            CODDOC = V_REC.CODDOC,
            TIPDOC = V_REC.TIPDOC, 
            INDEXLOCAL = V_REC.INDEXLOCAL, 
            CONTD = V_REC.CONTD, 
            CONTC = V_REC.CONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE, 
            VALOAREV = V_REC.VALOAREV, 
            OBS = V_REC.OBS, 
            AN = V_REC.AN, 
            LUNA = V_REC.LUNA,
            SUBUNITATEA = V_REC.SUBUNITATEA,
            DATADOC = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
            DOCUMENT = V_REC.DOCUMENT
   				WHERE CODJURNAL = V_REC.CODJURNAl;
   			ELSE
   				INSERT INTO JURNAL
            (
              CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
              CONTD, CONTC, GEST, VALOARE, VALOAREV,
              OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
   				VALUES
            (
              SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV,
              V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
   			END IF;
   		END LOOP;
    
    ELSE
      -- INSERT
      SELECT SEQ_REGOSS_CODREGOSS.NEXTVAL INTO RecID FROM DUAL;
      INSERT INTO REGOSS
        (CODREGOSS,
          TIPREG,
          NRDOC,
          DATADOC,
         TRIMESTRUL,
         CODBANK,
         CODMONEDA,
         CURS,
         DIRTY,
         OBS,
         CODSUBUNIT,
         AN,
         LUNA,
         CODGEST,
         CODANALIZA,
         CODANALIZANOD,
         CODCENTRU,
         CURS_IFRS)
        (SELECT RecID,
                TIPREG,
                NRDOC,
                DATADOC,
                TRIMESTRUL,
                CODBANK,
                CODMONEDA,
                CURS,
                DIRTY,
                OBS,
                CODSUBUNIT,
                AN,
                LUNA,
                CODGEST,
                CODANALIZA,
                CODANALIZANOD,
                CODCENTRU,
                CURS_IFRS
           FROM TMP_REGOSS);
    
      INSERT INTO REGOSS1
        (CODREGOSS1,
         CODREGOSS,
         CODDOC,                       
         TIPDOC,       
         TVADOCVAL,
         TVADOC,
         TVADOCREG,
         CODGEST,
         CONT,
         SEMN,
         CURS,
         SEMNIFICATIE,
         SUBUNITATEA)
        (SELECT SEQ_REG1_CODREG1.NEXTVAL,
                RecID,
                CODDOC,                       
                TIPDOC,       
                TVADOCVAL,
                TVADOC,
                TVADOCREG,
                CODGEST,
                CONT,
                SEMN,
                CURS,
                SEMNIFICATIE,
                SUBUNITATEA
           FROM TMP_REGOSS1);
    
				INSERT INTO JURNAL1
					(
						CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
						CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
						CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
						GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
					)
					(
						SELECT
							SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,
							CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
							CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
							GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
						FROM TMP_JURNAL1
					);
				INSERT INTO JURNAL
					(
						CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
						CONTD, CONTC, GEST, VALOARE, VALOAREV,
						OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
					)
					(
						SELECT
							SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,
							CONTD, CONTC, GEST, VALOARE, VALOAREV,
							OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
						FROM
							TMP_JURNAL
					);
    END IF;
  
  		-- ACTUALIZARE RULAJE CONTURI
		FOR V_REC IN
      (SELECT * FROM TMP_RULAJ)
		LOOP
		  SELECT COUNT(*) INTO TMP_NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
			IF TMP_NR = 0 THEN
		    INSERT INTO NCONTRUL
          (
            CODCONTRUL, CODCONT,
            RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
            AN, LUNA
          )
			  VALUES
          (
            SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,
            0, 0, 0, 0, 0, 0, 0, 0,
            PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU
          );
      END IF;
 			UPDATE NCONTRUL SET
 			  RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE ELSE 0 END),
  			RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE ELSE 0 END),
 	 			RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
 		 		RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
 			WHERE 
        CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN
         (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB
             (
               CODCONTRULSUB, CODCONTRUL,
               RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
               SUBUNITATEA
             )
           VALUES
             (
               SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,
               0, 0, 0, 0, 0, 0, 0, 0,
               V_REC.SUBUNITATEA
             );
         END IF;
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;
     
   END LOOP;
  PKG_GLOBALS.MarkDirtyJurnal;
    NotifyModif(Operation, RecId, &apos;REGOSS&apos;);
    COMMIT;
  END;
  
  PROCEDURE GetDateTrimestru(pTrimestrul IN NUMBER, dataStart OUT DATE, dataStop OUT DATE, pAn IN NUMBER DEFAULT NULL) is
    aAn Number(4);
  begin
    if pAn is null then
      aAn := PKG_GLOBALS.GetANLUCRU();
    else
      aAn := pAn;
    end if;
    with q(qtr, trimestrul) as( 
      select add_months(to_date(&apos;01.01.&apos;||aAn,&apos;dd.mm.yyyy&apos;), (level - 1) * 3), level as trimestrul
        from dual
      connect by level &lt;= 4)
    select qtr as first_day,
      last_day(add_months(qtr, 2)) as last_day into dataStart, dataStop
     from q
     where trimestrul = pTrimestrul;
  end;
  
  PROCEDURE GenerateDataXTrimestru(pTrimestrul IN NUMBER, pCursReg IN NUMBER, pMoneda IN NUMBER, pForce IN NUMBER DEFAULT 0) is
    dataStartTrim date;
    dataStopTrim date;
    aCursReg number(20,7);
    recId number;
    recIdx number;
    nrRows integer;
    tvaDocRegExistent number(20,7);
    tvadocvalExistent number(20,7);
    contExistent Number(20);
    flgModif number(1);
  BEGIN
    aCursReg := pCursReg;
    GetDateTrimestru(pTrimestrul, dataStartTrim, dataStopTrim);
    begin
      select rs.codregoss into recId  from tmp_regoss rs;
    exception 
           when NO_DATA_FOUND then recId := 0;
    end;
    if dataStartTrim is null or dataStopTrim is null  then
      return;
    end if;
    if recId &lt; 1 OR pForce &gt; 0 then
       delete from tmp_regoss1;
    end if;
    update tmp_regoss1 set deleted = 1;
    recIdx := 0;
    flgModif := 1;
    if pForce &gt; 0 then 
      flgModif := 0;
    end if;
    for v_rec in 
                      (  select ies.codies as coddoc,
                             ies.tipdoc as tipdoc,
                             ies.tvadoc as tvadoc,
                             ies.tvadoc * coalesce(ies.curs,1) as tvadocval,
                             ies.tvadoc * aCursReg as tvadocreg,
                             ies.moneda,
                             ies.curs,
                             ies.partener as codpart,
                             part.den_part as den_part,
                             ies.seriadoc||&apos; &apos;||ies.nrdoc||&apos;/&apos;||to_char(ies.datadoc, &apos;dd.mm.yyyy&apos;) as doc,
                             ies.subunitatea as subunitatea,
                             ies.codtvaserv as codtvaserv,
                             tsr1.codtvaserv1 as codtvaserv1,
                             tsr1.codcont as cont,
                             PKG_PLANCONTURI.GETSIMBOLCONT(tsr1.codcont) as simbolcont        
                      from iesiri ies
                      join npart part on part.codpart = ies.partener
                      join tvaserv1 tsr1 on tsr1.codtvaserv = ies.codtvaserv 
                                                                 and pkg_globals.AnLunaLucru BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
                     where trunc(ies.datadoc) between dataStartTrim and dataStopTrim
                       and ies.tiptranzactie = 2
                       and ies.tiptva = 10
                       and ies.tipdoc = 19
                       and coalesce(ies.anulat,0) = 0
                       and coalesce(ies.operat,0) = 1
                       and coalesce(tsr1.codcont,0) &lt;&gt; 0
                       and ies.moneda = pMoneda ) loop
       select count(*) into nrRows from tmp_regoss1 trs1 where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;
       if nrRows &gt; 0 then
           select trs1.TVADOCREG, trs1.TVADOCVAL, trs1.cont  into tvaDocRegExistent, tvadocvalExistent, contExistent 
           from tmp_regoss1 trs1 
           where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC and rownum = 1;
           if (abs(tvaDocRegExistent - v_rec.TVADOCREG) &gt; 0.0000001)
                  OR (abs(tvadocvalExistent - v_rec.TVADOCVAL) &gt; 0.0000001)
                  OR (contExistent &lt;&gt; v_rec.CONT)  then --update existing row 
             update tmp_regoss1 trs1
                    set  TVADOCVAL   = v_rec.TVADOCVAL ,
                           TVADOC        = v_rec.TVADOC ,
                           TVADOCREG  = v_rec.TVADOCREG ,
                           CURS             = v_rec.CURS,
                           DIFERENTA     = v_rec.TVADOCREG - v_rec.TVADOCVAL,
                           CODPART       = v_rec.CODPART,
                           DEN_PART      = v_rec.DEN_PART,
                           DOC               = v_rec.DOC,
                           SUBUNITATEA  = v_rec.SUBUNITATEA,
                           CONT              = v_rec.cont,
                           CODTVASERV  = v_rec.CODTVASERV,
                           CODTVASERV1= v_rec.CODTVASERV1,
                           MODIFICARI   = flgModif,
                           DELETED        = 0,
                           SIMBOLCONT = v_rec.SIMBOLCONT 
              where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;                   
           ELSE
             update tmp_regoss1 trs1 SET DELETED = 0  where trs1.coddoc = v_rec.CODDOC and trs1.tipdoc = v_rec.TIPDOC;  
           end if;
       else 
           recIdx := recIdx + 1;
           insert into tmp_regoss1 (
                         CODREGOSS1,
                         CODREGOSS ,
                         CODDOC ,                       
                         TIPDOC ,
                         TVADOCVAL ,
                         TVADOC ,
                         TVADOCREG ,         
                         CURS,
                         DIFERENTA,
                         CODPART,
                         DEN_PART,
                         DOC,
                         SUBUNITATEA,
                         CONT,
                         SIMBOLCONT,
                         CODTVASERV,
                         CODTVASERV1,
                         MODIFICARI,
                         DELETED )
           values (
                         -1 * recIdx,
                         recId ,
                         v_rec.CODDOC ,                       
                         v_rec.TIPDOC ,
                         v_rec.TVADOCVAL ,
                         v_rec.TVADOC ,
                         v_rec.TVADOCREG ,
                         v_rec.CURS,
                         v_rec.TVADOCREG - v_rec.TVADOCVAL,
                         v_rec.CODPART,
                         v_rec.DEN_PART,
                         v_rec.DOC,
                         v_rec.SUBUNITATEA,
                         v_rec.CONT,
                         v_rec.SIMBOLCONT,
                         v_rec.CODTVASERV,
                         v_rec.CODTVASERV1,
                         flgModif,
                         0 );                   
        end if;
     end loop;
     delete from tmp_regoss1 where deleted = 1;
     commit;
  END;
  
  FUNCTION GetNumRegsPerQuarter( pTrimestru IN NUMBER,  pMoneda IN NUMBER, pCodreg IN NUMBER) RETURN NUMBER IS
    tmp NUMBER(20);
  BEGIN
    SELECT
      COUNT(*) INTO tmp
    FROM
      REGOSS ross
    WHERE
      ross.codregoss &lt;&gt; pCodreg AND
      ross.codmoneda = pMoneda AND
      ross.trimestrul = pTrimestru ;
    RETURN tmp;
    EXCEPTION WHEN OTHERS THEN RETURN -1;
  END;
  

END PKG_REGOSS;

 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REGPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9608C81828E9FF49695EE0C6C00BE1A7A6A6828C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REGPART IS


PROCEDURE SET_INCLUSIV_LITIGII(FLAG IN NUMBER)
IS
BEGIN
  INCLUSIV_LITIGII := FLAG;
END;


FUNCTION CONDITIE_LITIGII(aSEMNIFICATIE IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aSEMNIFICATIE IN (1303) THEN RETURN INCLUSIV_LITIGII;
                             ELSE RETURN 1;
  END IF;
END;


 PROCEDURE SET_MARJA_REGAVIZE(MARJA IN NUMBER)
 IS
 BEGIN
   MARJAREGAVIZE := MARJA;
 END;

 FUNCTION CONDITIE_MARJA_REGAVIZE(SOLD IN NUMBER) RETURN NUMBER
 IS
 BEGIN
   IF ABS(SOLD) &gt; ABS(MARJAREGAVIZE) THEN RETURN 1;
                                     ELSE RETURN 0;
   END IF;
 END;



PROCEDURE SET_INCLUSIV_AVIZE(FLAG IN NUMBER)
IS
BEGIN
  INCLUSIVAVIZE := FLAG;
END;


FUNCTION CONDITIE_AVIZE(aICONT IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF   aICONT  IN (6, 7) THEN
    RETURN INCLUSIVAVIZE;
  ELSE
   RETURN 1;
  END IF;
END;

FUNCTION  CONDITIE_AVANS_PE_NC(aSEMNIFICATIE IN NUMBER, aICONT IN NUMBER) RETURN NUMBER
IS
BEGIN
   IF  aSEMNIFICATIE IN (1200, 1201) AND  aICONT  IN (12) THEN RETURN INCLUSIV_AVANS_FACTURAT;
    ELSE RETURN 1;
  END IF;

END;


FUNCTION CONDITIE_ICONT_AVANS_FACTURAT(aICONT IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF   aICONT  IN (4, 5) THEN RETURN INCLUSIV_AVANS_FACTURAT;
                         ELSE RETURN 1;
  END IF;
END;


PROCEDURE SET_INCLUSIV_GARANTII(FLAG IN NUMBER)
IS
BEGIN
  INCLUSIV_GARANTII := FLAG;
END;


FUNCTION CONDITIE_GARANTII(aSEMNIFICATIE IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aSEMNIFICATIE IN (120, 220) THEN RETURN INCLUSIV_GARANTII;
                                 ELSE RETURN 1;
  END IF;
END;



PROCEDURE SET_INCLUSIV_AVANS_FACTURAT(FLAG IN NUMBER)
IS
BEGIN
  INCLUSIV_AVANS_FACTURAT := FLAG;
END;

FUNCTION CONDITIE_AVANS_FACTURAT(aSEMNIFICATIE IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aSEMNIFICATIE IN (110, 210, 310, 410) THEN RETURN INCLUSIV_AVANS_FACTURAT;
                                           ELSE RETURN 1;
  END IF;
END;


PROCEDURE SET_INCLUSIV_CECURI(FLAG IN NUMBER)
IS
BEGIN
  INCLUSIV_CECURI := FLAG;
END;

FUNCTION CONDITIE_CECURI(aSEMNIFICATIE IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF aSEMNIFICATIE IN (500, 600) THEN RETURN INCLUSIV_CECURI;
                                 ELSE RETURN 1;
  END IF;
END;



PROCEDURE MAKE_STINGERE_LUNA
IS
BEGIN
  DELETE TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA (CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM(VALOARE) AS VALOARE
  FROM
  (
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    TREZOR1 T1
    WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (29, 30, 31,32, 33)
           AND T1.CODTREZOR1 = G_S.CODDOC
           AND T1.AN   = PKG_GLOBALS.GETANLUCRU
           AND T1.LUNA = PKG_GLOBALS.GETLUNALUCRU
           AND NVL(T1.ANULAT, 0) = 0
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         CASE
           WHEN O.SEMNIFICATIE = 1303 THEN S.VALOARE
           ELSE NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0)
         END AS VALOARE
    FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            COMPENS C,
            OBLIGPIF O
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC = 28
           AND C.CODCOMPENS = G_S.CODDOC
           AND C.AN   = PKG_GLOBALS.GETANLUCRU
           AND C.LUNA = PKG_GLOBALS.GETLUNALUCRU
           AND S.CODSTINSPIF = O.CODOBLIGPIF
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
          FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            INTRARI I
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9)
           AND I.CODINTR = G_S.CODDOC
           AND I.AN   = PKG_GLOBALS.GETANLUCRU
           AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
           AND I.OPERAT = 1 AND I.ANULAT = 0
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
     FROM
       STINGERE S,
       OBLIGPIF O_S,
       GENERAL G_S,
       IESIRI I
     WHERE
      O_S.CODOBLIGPIF = S.CODSTINGATORPIF
      AND G_S.CODGENERAL  = O_S.CODGENERAL
      AND G_S.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26)
      AND I.CODIES = G_S.CODDOC
      AND I.AN   = PKG_GLOBALS.GETANLUCRU
      AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
-- AVIZE DE INTRARE STINSE DE FACT LA AVIZ
  SELECT
    OSTINS.CODOBLIGPIF AS CODSTINSPIF,
    (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
      ( CASE
          WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
          ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
        END
       )
    )  AS VALOARE
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I,
    INTRARI1 I1,
    INTRLINK IL,
    INTRARI1 I1STINS,
    INTRARI  ISTINS,
    GENERAL GSTINS,
    OBLIGPIF OSTINS
  WHERE
    O.  SEMNIFICATIE       = 140
    AND G.CODGENERAL       = O.CODGENERAL
    AND G.TIPDOC           = 9
    AND I.CODINTR          = G.CODDOC
    AND I1.CODINTR         = I.CODINTR
    AND IL.CODINTR1        = I1.CODINTR1
    AND IL.CODLINIEAVIZ    = I1STINS.CODINTR1
    AND ISTINS.CODINTR     = I1STINS.CODINTR
    AND ISTINS.CODINTR     = GSTINS.CODDOC
    AND ISTINS.TIPDOC      = GSTINS.TIPDOC
    AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
    AND I.OPERAT           = 1
    AND
    (
      (     ISTINS.AN * 12 + ISTINS.LUNA &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      ) OR
      (     ISTINS.AN * 12 + ISTINS.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
    )
    AND NVL(G.FaraReg, 0)  = 0

 UNION ALL

-- AVIZE DE INTRARE STINSE DE DVI LA AVIZ
  SELECT
    OSTINS.CODOBLIGPIF AS CODSTINSPIF,
    ((D1.PRETIMPORT/I.CURS) * I1.CANT + NVL(I1STINS.TVA , 0) *
      ( CASE
          WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
          ELSE (D1.PRETIMPORT/I.CURS) * I1.CANT /( I1STINS.PU * I1STINS.CANT)
        END
       )
    )  AS VALOARE
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I,
    INTRARI1 I1
    LEFT OUTER JOIN DVI1 D1 ON D1.CODINTR1 = I1.CODINTR1,
    INTRLINK IL,
    INTRARI1 I1STINS,
    INTRARI  ISTINS,
    GENERAL GSTINS,
    OBLIGPIF OSTINS
  WHERE
    O.  SEMNIFICATIE       = 140
    AND G.CODGENERAL       = O.CODGENERAL
    AND G.TIPDOC           = 5
    AND I.CODINTR          = G.CODDOC
    AND I1.CODINTR         = I.CODINTR
    AND IL.CODINTR1        = I1.CODINTR1
    AND IL.CODLINIEAVIZ    = I1STINS.CODINTR1
    AND ISTINS.CODINTR     = I1STINS.CODINTR
    AND ISTINS.CODINTR     = GSTINS.CODDOC
    AND ISTINS.TIPDOC      = GSTINS.TIPDOC
    AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
    AND I.OPERAT           = 1
    AND
    (
      (     ISTINS.AN * 12 + ISTINS.LUNA &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      ) OR
      (     ISTINS.AN * 12 + ISTINS.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
    )
/*
    AND I.AN               = PKG_GLOBALS.GETANLUCRU
    AND I.LUNA             = PKG_GLOBALS.GETLUNALUCRU
*/
    AND NVL(G.FaraReg, 0)  = 0

   UNION ALL
-- AVIZE DE IESIRE STINSE
   SELECT
     OSTINS.CODOBLIGPIF AS CODSTINSPIF,
     (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
      ( CASE
          WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
          ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
        END
       )
      )  AS VALOARE
   FROM
     OBLIGPIF O,
     GENERAL G,
     IESIRI I,
     IESIRI1 I1,
     IESLINK IL,
     IESIRI1 I1STINS,
     IESIRI  ISTINS,
     GENERAL GSTINS,
     OBLIGPIF OSTINS
   WHERE
     O.  SEMNIFICATIE       = 240
     AND G.CODGENERAL       = O.CODGENERAL
     AND G.TIPDOC           = 26
     AND I.CODIES           = G.CODDOC
     AND I1.CODIES          = I.CODIES
     AND IL.CODIES1         = I1.CODIES1
     AND IL.CODLINIEAVIZ    = I1STINS.CODIES1
     AND ISTINS.CODIES      = I1STINS.CODIES
     AND ISTINS.CODIES      = GSTINS.CODDOC
     AND ISTINS.TIPDOC      = GSTINS.TIPDOC
     AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
     AND I.OPERAT           = 1
/*
     AND I.AN               = PKG_GLOBALS.GETANLUCRU
     AND I.LUNA             = PKG_GLOBALS.GETLUNALUCRU
*/
    AND
    (
      (     ISTINS.AN * 12 + ISTINS.LUNA &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      ) OR
      (     ISTINS.AN * 12 + ISTINS.LUNA = PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
        AND I.AN * 12      + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
      )
    )

     AND NVL(G.FaraReg, 0)  = 0

  ) GROUP BY CODSTINSPIF;
END;

PROCEDURE MAKE_STINGERI_LA_DATA_PART
IS
BEGIN
  DELETE TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA (CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM(VALOARE) AS VALOARE
  FROM
  (
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    TREZOR1 T1,
    TREZOR T,
    OBLIGPIF O
    WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND O.CODOBLIGPIF = S.CODSTINSPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (29, 30, 31,32, 33)
           AND T1.CODTREZOR1 = G_S.CODDOC
           AND T.CODTREZOR = T1.CODTREZOR
           AND T.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND NVL(T1.ANULAT, 0) = 0
           AND NVL(G_S.FaraReg, 0) = 0
           AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
    FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            COMPENS C,
            OBLIGPIF O
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND O.CODOBLIGPIF = S.CODSTINSPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC = 28
           AND C.CODCOMPENS = G_S.CODDOC
           AND C.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND NVL(G_S.FaraReg, 0) = 0
           AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
          FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            INTRARI I,
            OBLIGPIF O
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND O.CODOBLIGPIF = S.CODSTINSPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9)
           AND I.CODINTR = G_S.CODDOC
           AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND I.OPERAT = 1 AND I.ANULAT = 0
           AND NVL(G_S.FaraReg, 0) = 0
           AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
     FROM
       STINGERE S,
       OBLIGPIF O_S,
       GENERAL G_S,
       IESIRI I,
       OBLIGPIF O
     WHERE
      O_S.CODOBLIGPIF = S.CODSTINGATORPIF
      AND O.CODOBLIGPIF = S.CODSTINSPIF
      AND G_S.CODGENERAL  = O_S.CODGENERAL
      AND G_S.TIPDOC IN (16, 19, 20, 21, 22, 23, 24, 25, 26)
      AND I.CODIES = G_S.CODDOC
      AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND NVL(G_S.FaraReg, 0) = 0
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
  UNION ALL
-- AVIZE DE INTRARE STINSE
  SELECT
    OSTINS.CODOBLIGPIF AS CODSTINSPIF,
   (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
    ( CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
        ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
      END
     )
     )  AS VALOARE
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I,
    INTRARI1 I1,
    INTRLINK IL,
    INTRARI1 I1STINS,
    INTRARI  ISTINS,
    GENERAL GSTINS,
    OBLIGPIF OSTINS
  WHERE
    O.  SEMNIFICATIE       = 140
    AND G.CODGENERAL       = O.CODGENERAL
    AND G.TIPDOC           = 9
    AND I.CODINTR          = G.CODDOC
    AND I1.CODINTR         = I.CODINTR
    AND IL.CODINTR1        = I1.CODINTR1
    AND IL.CODLINIEAVIZ    = I1STINS.CODINTR1
    AND ISTINS.CODINTR     = I1STINS.CODINTR
    AND ISTINS.CODINTR     = GSTINS.CODDOC
    AND ISTINS.TIPDOC      = GSTINS.TIPDOC
    AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
    AND I.OPERAT           = 1
    AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
    AND NVL(G.FaraReg, 0)  = 0
    AND OSTINS.CODPART = PKG_NOMPART.GET_PART_CURENT

   UNION ALL
-- AVIZE DE IESIRE STINSE
   SELECT
     OSTINS.CODOBLIGPIF AS CODSTINSPIF,
    (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
        ( CASE
            WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
            ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
          END
         )
     )  AS VALOARE
   FROM
     OBLIGPIF O,
     GENERAL G,
     IESIRI I,
     IESIRI1 I1,
     IESLINK IL,
     IESIRI1 I1STINS,
     IESIRI  ISTINS,
     GENERAL GSTINS,
     OBLIGPIF OSTINS
   WHERE
     O.  SEMNIFICATIE       = 240
     AND G.CODGENERAL       = O.CODGENERAL
     AND G.TIPDOC           = 26
     AND I.CODIES           = G.CODDOC
     AND I1.CODIES          = I.CODIES
     AND IL.CODIES1         = I1.CODIES1
     AND IL.CODLINIEAVIZ    = I1STINS.CODIES1
     AND ISTINS.CODIES      = I1STINS.CODIES
     AND ISTINS.CODIES      = GSTINS.CODDOC
     AND ISTINS.TIPDOC      = GSTINS.TIPDOC
     AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
     AND I.OPERAT           = 1
     AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
     AND NVL(G.FaraReg, 0)  = 0
     AND OSTINS.CODPART = PKG_NOMPART.GET_PART_CURENT

  ) GROUP BY CODSTINSPIF;
END;

PROCEDURE MAKE_STINGERI_LA_DATA
IS
BEGIN
  DELETE TMP_STINGERE_LUNA;
  INSERT INTO TMP_STINGERE_LUNA(CODSTINSPIF, VALOARE)
  SELECT CODSTINSPIF, SUM(VALOARE) AS VALOARE
  FROM
  (
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    TREZOR1 T1,
    TREZOR T
    WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (29, 30, 31,32, 33)
           AND T1.CODTREZOR1 = G_S.CODDOC
           AND T.CODTREZOR = T1.CODTREZOR
           AND T.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND NVL(T1.ANULAT, 0) = 0
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
    FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            COMPENS C
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC = 28
           AND C.CODCOMPENS = G_S.CODDOC
           AND C.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
          FROM
            STINGERE S,
            OBLIGPIF O_S,
            GENERAL G_S,
            INTRARI I
          WHERE
           O_S.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G_S.CODGENERAL  = O_S.CODGENERAL
           AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9)
           AND I.CODINTR = G_S.CODDOC
           AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
           AND I.OPERAT = 1 AND I.ANULAT = 0
           AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT S.CODSTINSPIF,
         NVL(S.VALOARE, 0) - NVL(G_S.TVA, 0) AS VALOARE
     FROM
       STINGERE S,
       OBLIGPIF O_S,
       GENERAL G_S,
       IESIRI I
     WHERE
      O_S.CODOBLIGPIF = S.CODSTINGATORPIF
      AND G_S.CODGENERAL  = O_S.CODGENERAL
      AND G_S.TIPDOC IN (16, 19, 20, 21, 22, 23, 24, 25, 26)
      AND I.CODIES = G_S.CODDOC
      AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
-- AVIZE DE INTRARE STINSE
  SELECT
    OSTINS.CODOBLIGPIF AS CODSTINSPIF,
   (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
    ( CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
        ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
      END
     )
     )  AS VALOARE
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I,
    INTRARI1 I1,
    INTRLINK IL,
    INTRARI1 I1STINS,
    INTRARI  ISTINS,
    GENERAL GSTINS,
    OBLIGPIF OSTINS
  WHERE
    O.  SEMNIFICATIE       = 140
    AND G.CODGENERAL       = O.CODGENERAL
    AND G.TIPDOC           = 9
    AND I.CODINTR          = G.CODDOC
    AND I1.CODINTR         = I.CODINTR
    AND IL.CODINTR1        = I1.CODINTR1
    AND IL.CODLINIEAVIZ    = I1STINS.CODINTR1
    AND ISTINS.CODINTR     = I1STINS.CODINTR
    AND ISTINS.CODINTR     = GSTINS.CODDOC
    AND ISTINS.TIPDOC      = GSTINS.TIPDOC
    AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
    AND I.OPERAT           = 1
    AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
    AND NVL(G.FaraReg, 0)  = 0

   UNION ALL
-- AVIZE DE IESIRE STINSE
   SELECT
     OSTINS.CODOBLIGPIF AS CODSTINSPIF,
    (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
        ( CASE
            WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
            ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
          END
         )
     )  AS VALOARE
   FROM
     OBLIGPIF O,
     GENERAL G,
     IESIRI I,
     IESIRI1 I1,
     IESLINK IL,
     IESIRI1 I1STINS,
     IESIRI  ISTINS,
     GENERAL GSTINS,
     OBLIGPIF OSTINS
   WHERE
     O.  SEMNIFICATIE       = 240
     AND G.CODGENERAL       = O.CODGENERAL
     AND G.TIPDOC           = 26
     AND I.CODIES           = G.CODDOC
     AND I1.CODIES          = I.CODIES
     AND IL.CODIES1         = I1.CODIES1
     AND IL.CODLINIEAVIZ    = I1STINS.CODIES1
     AND ISTINS.CODIES      = I1STINS.CODIES
     AND ISTINS.CODIES      = GSTINS.CODDOC
     AND ISTINS.TIPDOC      = GSTINS.TIPDOC
     AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
     AND I.OPERAT           = 1
     AND I.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
     AND NVL(G.FaraReg, 0)  = 0

  ) GROUP BY CODSTINSPIF;
END;


PROCEDURE MAKE_INFO_STINSE_LUNA
IS
BEGIN
  DELETE TMP_INFOSTINSE;
  INSERT INTO TMP_INFOSTINSE(CODGENERAL, CODDOC, TIPDOC, MONEDA)

  SELECT DISTINCT
         CODGENERAL,
         CODDOC,
         TIPDOC,
         MONEDA
  FROM
  (
  SELECT
    GSTINS.CODGENERAL,
    GSTINS.CODDOC,
    GSTINS.TIPDOC,
    GSTINS.MONEDA
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    TREZOR1 T1,
    OBLIGPIF OSTINS,
    GENERAL GSTINS
  WHERE
    O_S.CODOBLIGPIF = S.CODSTINGATORPIF
    AND G_S.CODGENERAL  = O_S.CODGENERAL
    AND G_S.TIPDOC IN (29, 30, 31,32, 33)
    AND T1.CODTREZOR1 = G_S.CODDOC
    AND T1.AN   = PKG_GLOBALS.GETANTEMP
    AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND NVL(T1.ANULAT, 0) = 0
    AND OSTINS.CODOBLIGPIF = S.CODSTINSPIF
    AND GSTINS.CODGENERAL  = OSTINS.CODGENERAL
    AND GSTINS.MONEDA &lt;&gt; 0
    AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT
    GSTINS.CODGENERAL,
    GSTINS.CODDOC,
    GSTINS.TIPDOC,
    GSTINS.MONEDA
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    COMPENS C,
    OBLIGPIF OSTINS,
    GENERAL GSTINS
  WHERE
    O_S.CODOBLIGPIF = S.CODSTINGATORPIF
    AND G_S.CODGENERAL  = O_S.CODGENERAL
    AND G_S.TIPDOC = 28
    AND C.CODCOMPENS = G_S.CODDOC
    AND C.AN   = PKG_GLOBALS.GETANTEMP
    AND C.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND OSTINS.CODOBLIGPIF = S.CODSTINSPIF
    AND GSTINS.CODGENERAL  = OSTINS.CODGENERAL
    AND GSTINS.MONEDA &lt;&gt; 0
    AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT
    GSTINS.CODGENERAL,
    GSTINS.CODDOC,
    GSTINS.TIPDOC,
    GSTINS.MONEDA
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    INTRARI I,
    OBLIGPIF OSTINS,
    GENERAL GSTINS
  WHERE
    O_S.CODOBLIGPIF = S.CODSTINGATORPIF
    AND G_S.CODGENERAL  = O_S.CODGENERAL
    AND G_S.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 8, 9)
    AND I.CODINTR = G_S.CODDOC
    AND I.AN   = PKG_GLOBALS.GETANTEMP
    AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND I.OPERAT = 1 AND I.ANULAT = 0
    AND OSTINS.CODOBLIGPIF = S.CODSTINSPIF
    AND GSTINS.CODGENERAL  = OSTINS.CODGENERAL
    AND GSTINS.MONEDA &lt;&gt; 0
    AND NVL(G_S.FaraReg, 0) = 0
  UNION ALL
  SELECT
    GSTINS.CODGENERAL,
    GSTINS.CODDOC,
    GSTINS.TIPDOC,
    GSTINS.MONEDA
  FROM
    STINGERE S,
    OBLIGPIF O_S,
    GENERAL G_S,
    IESIRI I,
    OBLIGPIF OSTINS,
    GENERAL GSTINS
  WHERE
    O_S.CODOBLIGPIF = S.CODSTINGATORPIF
    AND G_S.CODGENERAL  = O_S.CODGENERAL
    AND G_S.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26)
    AND I.CODIES = G_S.CODDOC
    AND I.AN   = PKG_GLOBALS.GETANTEMP
    AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND I.OPERAT = 1 AND I.ANULAT = 0
    AND OSTINS.CODOBLIGPIF = S.CODSTINSPIF
    AND GSTINS.CODGENERAL  = OSTINS.CODGENERAL
    AND GSTINS.MONEDA &lt;&gt; 0
    AND NVL(G_S.FaraReg, 0) = 0
  );

  UPDATE TMP_INFOSTINSE INF
  SET
   (AN, LUNA) = (SELECT AN, LUNA FROM INTRARI I WHERE CODINTR = INF.CODDOC)
  WHERE
    INF.TIPDOC &gt;=1 AND  INF.TIPDOC &lt;=10;

  UPDATE TMP_INFOSTINSE INF
  SET
   (AN, LUNA) = (SELECT AN, LUNA FROM IESIRI I WHERE CODIES = INF.CODDOC)
  WHERE
    INF.TIPDOC &gt;=19 AND  INF.TIPDOC &lt;=26;

  UPDATE TMP_INFOSTINSE INF
  SET
   (AN, LUNA) = (SELECT T.AN, T.LUNA FROM TREZOR T, TREZOR1 T1 WHERE CODTREZOR1 = INF.CODDOC AND T.CODTREZOR = T1.CODTREZOR)
  WHERE
    INF.TIPDOC &gt;=29 AND  INF.TIPDOC &lt;=33;

  UPDATE TMP_INFOSTINSE INF
  SET
   (AN, LUNA) = (SELECT AN, LUNA FROM COMPENS C WHERE CODCOMPENS = INF.CODDOC)
  WHERE
    INF.TIPDOC = 28;

  UPDATE TMP_INFOSTINSE INF
  SET
   (AN, LUNA) = (SELECT N.AN, N.LUNA FROM NC N, NC1 N1 WHERE CODNC1 = INF.CODDOC AND N.CODNC = N1.CODNC)
  WHERE
    INF.TIPDOC = 35;

  UPDATE TMP_INFOSTINSE INF
  SET
  CURS =
    (
     SELECT R.CURS
     FROM
       REG R, REG1 R1
     WHERE
       R1.CODGENERAL = INF.CODGENERAL
       AND R1.CODREG = R.CODREG
       AND R.TIPREG = 46
       AND R.CODMONEDA = INF.MONEDA
       AND R.AN * 12 + R.LUNA  =
      (SELECT MAX(AN * 12 + LUNA)
       FROM
         REG R2, REG1 R21
       WHERE
         R21.CODGENERAL = INF.CODGENERAL
         AND R21.CODREG = R2.CODREG
         AND R2.TIPREG = 46
         AND R2.CODMONEDA = INF.MONEDA
         AND R2.AN * 12 + R2.LUNA &gt;= INF.AN * 12 + INF.LUNA
         AND R2.AN * 12 + R2.LUNA &lt;= PKG_GLOBALS.ANTEMP * 12 + PKG_GLOBALS.LUNATEMP
       )
    );
END;


 PROCEDURE MAKE_REGPART_LUNA
 IS
 aPREFIXDOC VARCHAR2(3) := NULL;
 aDATADOC DATE := NULL;
 aNRDOC NUMBER(20) := NULL;
 aSUBUNITATEA NUMBER(20) := NULL;
 ContRegAvans number(5) := 0;
 BEGIN
   -- POPULEAZA TMP_REGPART_LUNA CU OBLIGATIILE CARE TREBUIESC REGULARIZATE
   -- PRESUPUNE CA S_A APELAT PKG_REG.SETPARAMSREG
   DELETE FROM TMP_REGPART_LUNA;
   PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);
   PKG_GLOBALS.MAKE_IOPART_LUNA;
   PKG_NOMPART.MAKE_CURS_GENERAL_LUNA(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.LUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.ANLUCRU));
   MAKE_STINGERE_LUNA;

   INSERT INTO TMP_REGPART_LUNA
   (CODGENERAL,
    SOLDDOCVAL,
    SOLDDOC,
    ICONT,
    SEMNIFICATIE,
    CODPART,
    CODIOPART1,
    CODGEST,
    CURS,
    TVA,
		  COEFPROVIZION,
    CODOBLIGPIF
    )
  SELECT
    RG.CODGENERAL,
   (VALOARE - ROUND(NVL(STINS, 0), 7)) * CURS ,
    VALOARE - ROUND(NVL(STINS, 0), 7)  AS SOLDDOC,
    RG.ICONT,
    RG.SEMNIFICATIE,
    RG.CODPART,
    RG.CODIOPART1,
    RG.CODGEST,
    RG.CURS,
    RG.TVA,
		  RG.COEFPROVIZION,
    RG.CODOBLIGPIF
  FROM
   (
   SELECT * FROM V_REGPART_LUNAPREC
   UNION
   ALL SELECT * FROM V_REGPART_DE_STINS
   ) RG
  WHERE
     CONDITIE_MARJA_REGAVIZE(ROUND(NVL(VALOARE, 0), 4) - ROUND(NVL(STINS, 0), 4)) = 1
     AND CONDITIE_AVIZE(RG.ICONT) = 1
     AND CONDITIE_AVANS_FACTURAT(RG.SEMNIFICATIE) = 1
     AND CONDITIE_LITIGII(RG.SEMNIFICATIE) = 1
     AND CONDITIE_GARANTII(RG.SEMNIFICATIE) = 1
     AND CONDITIE_ICONT_AVANS_FACTURAT(RG.ICONT) = 1
     AND CONDITIE_AVANS_PE_NC(RG.SEMNIFICATIE, RG.ICONT) = 1
     AND CONDITIE_CECURI(RG.SEMNIFICATIE) = 1 ;

   
    select count(*) INTO ContRegAvans -- testez daca nu este armata constanta care spune ce conturi de avans se regularizeaza
    from
      const1 C1
      INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
      INNER JOIN CONSTVAL CV ON CL.ALSTART &lt;= pkg_globals.Anlucru * 12 + pkg_globals.LunaLucru  AND CL.ALSTOP &gt;=  pkg_globals.Anlucru * 12 + pkg_globals.LunaLucru AND CV.CODCONSTLUNA = CL.CODCONSTLUNA
    where
      upper(c1.simbol) = &apos;CREGAVANSCONTURI&apos;
      AND CV.VALOARE IS NOT NULL;   

    if ContRegAvans &gt; 0 then --  daca constanta este armata sterg avansurile care nu sunt in conatanta
      FOR V_REC IN 
        (SELECT 
          CODGENERAL, 
          CODOBLIGPIF,   
          ContAvansConst.VALOARE
         FROM
           TMP_REGPART_LUNA  
           LEFT JOIN 
           (
           select CV.VALOARE 
            from
              const1 C1
              INNER JOIN CONSTLUNA CL ON CL.CODCONST1 = C1.CODCONST1
              INNER JOIN CONSTVAL CV ON CL.ALSTART &lt;= pkg_globals.Anlucru * 12 + pkg_globals.LunaLucru AND CL.ALSTOP &gt;= pkg_globals.Anlucru * 12 + pkg_globals.LunaLucru AND CV.CODCONSTLUNA = CL.CODCONSTLUNA
            where
              upper(c1.simbol) = &apos;CREGAVANSCONTURI&apos;
              AND CV.VALOARE IS NOT NULL
            ) ContAvansConst ON ContAvansConst.VALOARE = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(SEMNIFICATIE, ICONT, CodIOPart1)     
          WHERE
            SEMNIFICATIE IN (110, 210, 310, 410)  
         )
         LOOP
           IF V_REC.valoare is null then
             DELETE FROM TMP_REGPART_LUNA WHERE CODGENERAL = V_REC.CODGENERAL AND CODOBLIGPIF = V_REC.CODOBLIGPIF;
           end if;  
         END LOOP;     
    end if;  



   FOR V_REC IN (SELECT * FROM TMP_REGPART_LUNA)
   LOOP
     aPREFIXDOC   := NULL;
     aDATADOC     := NULL;
     aNRDOC       := NULL;
     aSUBUNITATEA := NULL;

     IF V_REC.SEMNIFICATIE IN (100, 110, 120, 140) THEN
       BEGIN
         SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM INTRARI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODINTR = G.CODDOC;
         EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
       END ;
     ELSE
       IF V_REC.SEMNIFICATIE IN (130) THEN
          BEGIN
            SELECT &apos;DVI&apos;, I.DATADOC, I.NRDOC, INTR.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM DVI I, GENERAL G, INTRARI INTR WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODDVI = G.CODDOC AND INTR.CODINTR = I.CODINTR;
            EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
          END ;
       ELSE
          IF V_REC.SEMNIFICATIE IN (200, 210, 220, 240) THEN
            BEGIN
              SELECT PREFIXDOC, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM IESIRI I, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODIES = G.CODDOC;
              EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL;
            END ;
          ELSE
            IF V_REC.SEMNIFICATIE IN (310, 410, 330, 430, 500, 600) THEN
              BEGIN
                SELECT SUBSTR(T1.DOC, 1, 2),  T1.DATADOC, T1.NRDOC, T.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM TREZOR1 T1, GENERAL G, TREZOR T WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
                EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
              END ;
            ELSE
              IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
                BEGIN
                  SELECT &apos;NC&apos;, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM NC1 N1, GENERAL G, NC N WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODNC1 = G.CODDOC AND N1.CODNC = N.CODNC;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
                END ;
              ELSE
     							  IF V_REC.SEMNIFICATIE = 1303 THEN
     								  BEGIN
     									  SELECT
     										   I.PREFIXDOC, I.DATADOC, I.NRDOC, I.SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA
     										 FROM
     										   OBLIGPIF O
     										 	 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
     											  LEFT OUTER JOIN OBLIGPIF OA ON OA.CODOBLIGPIF = O.CODOBLIGASOCIAT
     											  LEFT OUTER JOIN GENERAL GA ON GA.CODGENERAL = OA.CODGENERAL
     											  LEFT OUTER JOIN IESIRI I ON I.CODIES = GA.CODDOC
     										 WHERE
     										   G.CODGENERAL = V_REC.CODGENERAL;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL;
     									 END;
      								ELSE
                BEGIN -- compensari
                  SELECT &apos;PV&apos;, DATADOC, NRDOC, SUBUNITATEA INTO aPREFIXDOC, aDATADOC, aNRDOC, aSUBUNITATEA FROM COMPENS, GENERAL G WHERE G.CODGENERAL = V_REC.CODGENERAL AND CODCOMPENS = G.CODDOC;
                  EXCEPTION WHEN OTHERS THEN aPREFIXDOC := NULL; aDATADOC := NULL; aNRDOC := NULL; aSUBUNITATEA := NULL;
                END ;
      								END IF;
              END IF;
            END IF;
          END IF;
       END IF;
     END IF;

     UPDATE TMP_REGPART_LUNA
     SET
       PREFIXDOC    = aPREFIXDOC,
       DATADOC      = aDATADOC,
       NRDOC        = aNRDOC,
       SUBUNITATEA  = aSUBUNITATEA
     WHERE
       CODGENERAL   = V_REC.CODGENERAL;
   END LOOP;

 END;


 FUNCTION DATA_DOC_CORECTA(DATADOC IN DATE,  DATAREG IN DATE, DATANEXTREG IN DATE) RETURN NUMBER
 IS
  RET NUMBER(1) := 0;
 BEGIN
   IF DATANEXTREG IS NULL THEN
     IF DATADOC &gt; DATAREG THEN RET := 1;
     END IF;
   ELSE
     IF (DATADOC &gt; DATAREG)and(DATADOC &lt;= DATANEXTREG) THEN RET := 1;
     END IF;
   END IF;
   RETURN RET;
 END;

  PROCEDURE GenerareReg IS
	  REG1_IDX_LOCAL NUMBER(20);
		REG1CONT_IDX_LOCAL NUMBER(20);
	BEGIN

    DELETE FROM TMP_REG1;
	 	 REG1_IDX_LOCAL := 0;

/* FORMA NOUA*/
PKG_REGPART.MAKE_REGPART_LUNA;
FOR V_REC IN
(SELECT RP.*, P.DEN_PART
 FROM
   TMP_REGPART_LUNA RP
   LEFT OUTER JOIN NPART P ON P.CODPART = RP.CODPART
 )
LOOP
--    IF V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal &lt;&gt; 0
    IF ABS(V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal) &gt; 0.0000001
    THEN
   		  REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
   		  INSERT INTO TMP_REG1
       (
      	  CodReg1,
      			CodGeneral,
      	  Cont,
      			PrefixDoc,
         NrDoc,
         DataDoc,
       		CodPart,
         DenPart,
   					 SimbolCont,
       		SoldDocVal,
         SoldDoc,
         SoldDocReg,
       		Diferenta,
       		Document,
       		CodGest,
   					 Semn,
   					 Curs,
   					 Semnificatie,
  						 CoefProvizion,
         SUBUNITATEA,
         CODOBLIGPIF
       		)
   			VALUES
   			  ( -1 * REG1_IDX_LOCAL,
       		 	V_REC.CodGeneral,
       		  V_REC.ICONT ,
       			 V_REC.PrefixDoc,
           V_REC.NrDoc,
           V_REC.DataDoc,
       			 V_REC.CodPart,
           V_REC.Den_Part,
   					   PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)),
       			 V_REC.SoldDocVal,
           V_REC.SoldDoc,
           V_REC.SoldDoc * PKG_REG.CURS_REG,
       			 V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal,
       			 (CASE
						   WHEN V_REC.Semnificatie = 1303 THEN &apos;Litigii &apos; || V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;)
							 ELSE V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;)
							END),
       		  V_REC.CodGest,
   					1,
   					V_REC.Curs,
   					V_REC.Semnificatie,
					   V_REC.CoefProvizion,
        V_REC.SUBUNITATEA,
        V_REC.CODOBLIGPIF
   				);
     END IF;
END LOOP;

  FOR V_REC IN (
    SELECT
      R1.CODREG1,
      PKG_TREZOR.CODCONTCEC(O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.obiecttranz, PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GETLunaLUCRU) CodCont
    FROM TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
    WHERE R1.CODOBLIGPIF = O.CODOBLIGPIF
      AND O.SEMNIFICATIE IN (500, 600)
      AND G.CODGENERAL  = O.CODGENERAL
      AND T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
    SET CONT = V_REC.CODCONT, SIMBOLCONT = PKG_PLANCONTURI.GETSIMBOLCONT(V_REC.CODCONT)
    WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;


/* END FORMA NOUA*/

		-- populez TMP_REG1CONT;
		DELETE FROM TMP_REG1CONT;
		REG1CONT_IDX_LOCAL := 0;
		FOR V_REG1CONT IN
  		(
  		  SELECT
  				SUM(SoldDoc/* * Semn*/) AS SoldDoc,
  				SUM(SoldDocVal/* * Semn*/) AS SoldDocVal,
  				SUM(SoldDocReg/* * Semn*/) AS SoldDocReg,
  				SUM((SoldDocReg/* * Semn*/) - (SoldDocVal/* * Semn*/)) AS Diferenta,
  				Cont,
  				SimbolCont
  			FROM
  			  TMP_REG1
  			GROUP BY
  				Cont,
  				SimbolCont
  		)
		LOOP
		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
		  INSERT INTO TMP_REG1CONT
    		(
    		  CodReg1Cont,
    			SoldDoc,
    			SoldDocVal,
    			SoldDocReg,
    			Diferenta,
    			Cont,
    			SimbolCont
    		)
			VALUES
  			(
  			  -1 * REG1CONT_IDX_LOCAL,
  				 V_REG1CONT.SoldDoc,
  				 V_REG1CONT.SoldDocVal,
  			 	V_REG1CONT.SoldDocReg,
    			V_REG1CONT.Diferenta,
    			V_REG1CONT.Cont,
    			V_REG1CONT.SimbolCont
  			);
		END LOOP;
  END;

  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER) IS
    tmp NUMBER(20);
  BEGIN
    SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecID IN NUMBER) IS
  BEGIN
     PKG_GLOBALS.MarkDirtyJurnal;
     SP_LOCKRECORD(RecID);
    -- REPUN CURSURILE ULTERIOARE PE CURSUL
      SELECT MIN(DATADOC) INTO DATANEXTREG
      FROM
       REG
      WHERE
        TIPREG = 46
        AND DATADOC   &gt; (SELECT DATADOC FROM REG WHERE CODREG = RECID)
        AND CODMONEDA = (SELECT CODMONEDA FROM REG WHERE CODREG = RECID);

      CODNEXTREG := NULL;
      IF DATANEXTREG IS NOT NULL THEN
        SELECT CODREG INTO CODNEXTREG FROM REG
        WHERE
        DATADOC = DATANEXTREG
        AND TIPREG = 46
        AND CODMONEDA = (SELECT CODMONEDA FROM REG WHERE CODREG = RECID);
      END IF;



-- testez daca regularizarile nu afecteaza stingeri ulterioare
-- 1. TREZOR
     FOR V_REC IN
     (
     SELECT
       REG1.CURS AS OLDCURSREG,
       GSTINGATOR.CODGENERAL,
       GSTINGATOR.CURS AS CURSSTINGATOR,
       T1.CODTREZOR
     FROM
       REG REG,
       REG1 REG1,
       OBLIGPIF OSTINS,
       STINGERE S,
       OBLIGPIF OSTINGATOR,
       GENERAL GSTINGATOR,
       TREZOR1 T1
     WHERE
          REG.CODREG = RECID
      AND REG1.CODREG = REG.CODREG
      AND OSTINS.CODGENERAL = REG1.CODGENERAL
      AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
      AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
      AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
      AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
      AND T1.CODTREZOR1 = GSTINGATOR.CODDOC
      AND PKG_REGPART.DATA_DOC_CORECTA(T1.DATADOC,  REG.DATADOC, DATANEXTREG) = 1
      AND REG1.CURS &lt;&gt; GSTINGATOR.CURS
      AND NVL(GSTINGATOR.FaraReg, 0) = 0

     )
     LOOP
       UPDATE GENERAL
       SET
        CURS = V_REC.OLDCURSREG
       WHERE
        CODGENERAL = V_REC.CODGENERAL;

       UPDATE JURNAL1
       SET
        DIRTY = 1
       WHERE
        TIPDOC IN (29, 30, 31, 33) AND CODDOC = v_rec.codtrezor;
     END LOOP;

     -- 2.COMPENSARI
     FOR V_REC IN
     (
     SELECT
       REG1.CURS AS OLDCURSREG,
       GSTINGATOR.CODGENERAL,
       GSTINGATOR.CURS AS CURSSTINGATOR,
       C.CODCOMPENS
     FROM
      REG REG,
      REG1 REG1,
      OBLIGPIF OSTINS,
      STINGERE S,
      OBLIGPIF OSTINGATOR,
      GENERAL GSTINGATOR,
      COMPENS C
     WHERE
      REG.CODREG = RECID
      AND REG1.CODREG = REG.CODREG
      AND OSTINS.CODGENERAL = REG1.CODGENERAL
      AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
      AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
      AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
      AND GSTINGATOR.TIPDOC = 28
      AND C.CODCOMPENS = GSTINGATOR.CODDOC
  --  AND C.DATADOC &gt; REG.DATADOC
      AND PKG_REGPART.DATA_DOC_CORECTA(C.DATADOC,  REG.DATADOC, DATANEXTREG) = 1
      AND NVL(GSTINGATOR.FaraReg, 0) = 0
     )
     LOOP
       UPDATE JURNAL1
       SET
        DIRTY = 1
       WHERE
        TIPDOC = 28 AND CODDOC = V_REC.CODCOMPENS;
     END LOOP;

     -- DACA AM O REGULARIZARE ULTERIOARA TREBUIE PUSA PE DIRTY
     IF CODNEXTREG IS NOT NULL THEN
       UPDATE JURNAL1
       SET
         DIRTY = 1
       WHERE
         TIPDOC = 46 AND CODDOC = CODNEXTREG;

       FOR V_REC IN
       (
       SELECT R1_CURENT.CURS AS CURSCURENT,
              R1_NEXT.CODREG1
       FROM
         REG1 R1_CURENT,
         REG1 R1_NEXT
       WHERE
            R1_CURENT.CODREG = RECID
        AND R1_NEXT.CODREG = CODNEXTREG
        AND R1_CURENT.CODGENERAL = R1_NEXT.CODGENERAL
       )
       LOOP
         UPDATE REG1
         SET
          CURS = V_REC.CURSCURENT
         WHERE
           CODREG1 = V_REC.CODREG1;
       END LOOP;
     END IF;



   		DELETE FROM REG1 WHERE CodReg = RecID;
    /*
		   DELETE FROM GENERAL_REG WHERE CodReg = RecID;
		  */
    DELETE FROM REG WHERE CodReg = RecID;
  		FOR
  		  V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 46)
  		LOOP
        UPDATE
  			  NCONTRUL
        SET
          RULAJCD  = RULAJCD  - V_REC.VALOARE,
          RULAJVCD = RULAJVCD - V_REC.VALOAREV,
          RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
        WHERE
          CODCONT = V_REC.CONTD AND
  				AN = PKG_GLOBALS.ANLUCRU AND
  				LUNA = PKG_GLOBALS.LUNALUCRU;


      FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET
          RULAJCD  = RULAJCD  - V_REC.VALOARE,
          RULAJVCD = RULAJVCD - V_REC.VALOAREV,
          RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
        WHERE
          CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;


  			UPDATE
  			  NCONTRUL
  			SET
  			  RULAJCC  = RULAJCC  - V_REC.VALOARE,
  				RULAJVCC = RULAJVCC - V_REC.VALOAREV,
          RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
  			WHERE
  			  CODCONT = V_REC.CONTC AND
  				AN = PKG_GLOBALS.ANLUCRU AND
  				LUNA = PKG_GLOBALS.LUNALUCRU;

      FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET
          RULAJCC  = RULAJCC  - V_REC.VALOARE,
  				RULAJVCC = RULAJVCC - V_REC.VALOAREV,
          RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
          RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
        WHERE
          CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;


  		END LOOP;

  		DELETE FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 46;
	  	DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 46;

			DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 46);
			DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 46;

    NotifyModif(2, RecId, &apos;REG&apos;);
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    DELETE FROM TMP_REG;
    INSERT INTO TMP_REG
		  (CodReg, DataDoc)
		VALUES
		  (0, LAST_DAY(TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;)));
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecID IN NUMBER) IS
	   REG1_IDX_LOCAL     NUMBER(20);
 		 REG1CONT_IDX_LOCAL NUMBER(20);
	 	 PARAM_REG_DATA     DATE;
	 	 PARAM_REG_MONEDA   NUMBER(20);
		  PARAM_REG_CURS     NUMBER(23,7);
    COUNTIN            NUMBER(20) := 0;
    COUNTOUT           NUMBER(20) := 0;
	 	 NR                  NUMBER(20):= 0;
  BEGIN
    PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  -- POPULEZ LA INTRARE UN MARTOR
    DELETE TMP_REG1CONT_MARTOR;

    DELETE TMP_REG1_INITIAL;


    IF RecID &gt; 0 THEN
      INSERT INTO TMP_REG1_INITIAL(CODGENERAL, SOLDDOCVAL, SOLDDOCREG, CODOBLIGPIF) (SELECT CODGENERAL, SOLDDOCVAL, SOLDDOCREG, CODOBLIGPIF FROM REG1 WHERE CODREG = RECID);
    END IF;


  		REG1CONT_IDX_LOCAL := 0;
  		FOR V_REG1CONT IN
    		(
    		  SELECT
    				SUM(SoldDoc/* * Semn*/) AS SoldDoc,
    				SUM(SoldDocVal/* * Semn*/) AS SoldDocVal,
    				SUM(SoldDocReg/* * Semn*/) AS SoldDocReg,
    				SUM((SoldDocReg/* * Semn*/) - (SoldDocVal/* * Semn*/)) AS Diferenta,
    				Cont
    			FROM
    			  REG1
       WHERE
         REG1.CODREG = RECID
    			GROUP BY
    				Cont
    		)
  		LOOP
  		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
  		  INSERT INTO TMP_REG1CONT_MARTOR
      		(
      		  CodReg1Cont,
      			 SoldDoc,
      			 SoldDocVal,
      			 SoldDocReg,
      			 Diferenta,
      			 Cont
      		)
  			VALUES
    			(
    			  -1 * REG1CONT_IDX_LOCAL,
    				 V_REG1CONT.SoldDoc,
    				 V_REG1CONT.SoldDocVal,
    				 V_REG1CONT.SoldDocReg,
      			V_REG1CONT.Diferenta,
      			V_REG1CONT.Cont
    			);
  		END LOOP;



		DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST, CodAnaliza, CodCentru, CURS_IFRS, CodAnalizaNod)
      (SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.An, R.Luna, R.CODGEST, R.CodAnaliza, R.CodCentru, R.CURS_IFRS, R.CodAnalizaNod
      FROM REG R
      LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
      LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
      WHERE R.CodReg = RecID);

		    SELECT DataDoc, CodMoneda, Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM TMP_REG;

		    PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);



		-- populez TMP_REG1;
  DELETE FROM TMP_REG1;
  REG1_IDX_LOCAL := 0;

/* FORMA NOUA */
PKG_REGPART.MAKE_REGPART_LUNA;
FOR V_REC IN
(SELECT RP.*, P.DEN_PART
 FROM
   TMP_REGPART_LUNA RP
   LEFT OUTER JOIN NPART P ON P.CODPART = RP.CODPART
 )
LOOP
--    IF V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal &lt;&gt; 0 THEN
    IF ABS(V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal) &gt; 0.0000001 THEN

  		  REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
  		  INSERT INTO TMP_REG1
      (
     	  CodReg1,
     			CodGeneral,
     	  Cont,
     			PrefixDoc,
        NrDoc,
        DataDoc,
      		CodPart,
        DenPart,
  					 SimbolCont,
      		SoldDocVal,
        SoldDoc,
        SoldDocReg,
      		Diferenta,
      		Document,
      		CodGest, CodCentru, CodAnalizaNod,
  					 Semn,
  					 Curs,
  				  Semnificatie,
						  CoefProvizion,
        SUBUNITATEA,
        CODOBLIGPIF
      		)
  			VALUES
  			  ( -1 * REG1_IDX_LOCAL,
      		 	V_REC.CodGeneral,
      		  V_REC.ICONT ,
      			 V_REC.PrefixDoc,
          V_REC.NrDoc,
          V_REC.DataDoc,
      			 V_REC.CodPart,
          V_REC.Den_Part,
  					   PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)),
      			 V_REC.SoldDocVal,
          V_REC.SoldDoc,
          V_REC.SoldDoc * PARAM_REG_CURS,
      			 V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
      			 (CASE
						       WHEN V_REC.Semnificatie = 1303 THEN &apos;Litigii &apos; || V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;)
							      ELSE V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;)
							    END),
      		  V_REC.CodGest, 0, 0,
     					1,
     					V_REC.Curs,
     					V_REC.Semnificatie,
   						 V_REC.CoefProvizion,
          V_REC.SUBUNITATEA,
          V_REC.CODOBLIGPIF
  				);
   END IF;
END LOOP;

  FOR V_REC IN (
    SELECT
      R1.CODREG1,
      PKG_TREZOR.CODCONTCEC(O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.obiecttranz, PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GETLunaLUCRU) CodCont
    FROM TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
    WHERE R1.CODOBLIGPIF = O.CODOBLIGPIF
      AND O.SEMNIFICATIE IN (500, 600)
      AND G.CODGENERAL  = O.CODGENERAL
      AND T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
    SET CONT = V_REC.CODCONT, SIMBOLCONT = PKG_PLANCONTURI.GETSIMBOLCONT(V_REC.CODCONT)
    WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;

/*END FORMA NOUA */


/*
		-- repopulez si REG1;
		DELETE FROM REG1 WHERE CodReg = RecID;
    INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, Cont, Semn, Curs, Semnificatie)
      (SELECT SEQ_REG1_CODREG1.NEXTVAL, RecID, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, Cont, Semn, Curs, Semnificatie
      FROM TMP_REG1);
*/
		-- populez TMP_REG1CONT;
		DELETE FROM TMP_REG1CONT;
		REG1CONT_IDX_LOCAL := 0;
		FOR V_REG1CONT IN
  		(
  		  SELECT
  				SUM(SoldDoc/* * Semn*/) AS SoldDoc,
  				SUM(SoldDocVal/* * Semn*/) AS SoldDocVal,
  				SUM(SoldDocReg/* * Semn*/) AS SoldDocReg,
  				SUM((SoldDocReg/* * Semn*/) - (SoldDocVal/* * Semn*/)) AS Diferenta,
  				Cont
      --,
  			--	SimbolCont
  			FROM
  			  TMP_REG1
  			GROUP BY
  				Cont
    --  ,
  		--		SimbolCont
  		)
		LOOP
		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
		  INSERT INTO TMP_REG1CONT
    		(
    		  CodReg1Cont,
    			SoldDoc,
    			SoldDocVal,
    			SoldDocReg,
    			Diferenta,
    			Cont
       --,
    		--	SimbolCont
    		)
			VALUES
  			(
  			  -1 * REG1CONT_IDX_LOCAL,
  				V_REG1CONT.SoldDoc,
  				V_REG1CONT.SoldDocVal,
  				V_REG1CONT.SoldDocReg,
    			V_REG1CONT.Diferenta,
    			V_REG1CONT.Cont
       --,
    		--	V_REG1CONT.SimbolCont
  			);
		END LOOP;

		INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL WHERE TIPDOC = 46 AND CODDOC = RECID);
		INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 46 AND CODDOC = RECID);
		DELETE TMP_RULAJ;

  DIFERENTE := 0;
  SELECT COUNT(*) INTO COUNTIN FROM TMP_REG1CONT_MARTOR;
  SELECT COUNT(*) INTO COUNTOUT FROM TMP_REG1CONT;

  IF COUNTIN &lt;&gt; COUNTOUT THEN DIFERENTE := 1;
  ELSE
    FOR V_REC IN
     (
       SELECT  INTBL.CONT,
               INTBL.SOLDDOCVAL SOLDIN,
               OUTTBL.SOLDDOCVAL SOLDOUT,
               INTBL.SOLDDOCREG SOLDREGIN,
               OUTTBL.SOLDDOCREG SOLDREGOUT
       FROM
        TMP_REG1CONT_MARTOR INTBL
        LEFT OUTER JOIN TMP_REG1CONT OUTTBL ON OUTTBL.CONT = INTBL.CONT
       UNION
       SELECT  OUTTBL.CONT,
               INTBL.SOLDDOCVAL SOLDIN,
               OUTTBL.SOLDDOCVAL SOLDOUT,
               INTBL.SOLDDOCREG SOLDREGIN,
               OUTTBL.SOLDDOCREG SOLDREGOUT
       FROM
        TMP_REG1CONT OUTTBL
        LEFT OUTER JOIN TMP_REG1CONT_MARTOR INTBL ON INTBL.CONT = OUTTBL.CONT)
    LOOP
        IF (NVL(V_REC.SOLDIN,    0) &lt;&gt; NVL(V_REC.SOLDOUT, 0))OR
           (NVL(V_REC.SOLDREGIN, 0) &lt;&gt; NVL(V_REC.SOLDREGOUT, 0))
         THEN
          DIFERENTE := 1;
          EXIT;
        END IF;
    END LOOP;
   END IF;
   IF DIFERENTE = 1 THEN
     SELECT COUNT(*) INTO NR FROM TMP_JURNAL1;
     IF NR = 0 THEN
       INSERT INTO TMP_JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY)
       VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, 46, -2, 1);

       INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY, An, Luna, Subunitatea)
       VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, 46, -2, 1, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, 2);

       INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, ContD, ContC, An, Luna, Subunitatea)
       VALUES (SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, 46, -2, 0, 0, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, 2);

     ELSE
       FOR V_REC IN ( SELECT * FROM TMP_JURNAl1 )
       LOOP
         UPDATE TMP_JURNAL1
         SET DIRTY = 1
         WHERE
           CODJURNAL1 = V_REC.CODJURNAL1;


         UPDATE JURNAL1
         SET DIRTY = 1
         WHERE
           CODJURNAL1 = V_REC.CODJURNAL1;
       END LOOP;
    END IF;
   END IF;





  FOR V_REC IN
  (
   SELECT
    R1.CODREG1,
    RI.CODGENERAL AS CODGENERAL_INI,
    R1.SOLDDOCVAL,
    RI.SOLDDOCVAL AS SOLDDOCVAL_INI,
    R1.SOLDDOCREG,
    RI.SOLDDOCREG AS SOLDDOCREG_INI
   FROM
     TMP_REG1 R1
     LEFT OUTER JOIN TMP_REG1_INITIAL RI ON RI.CODGENERAL = R1.CODGENERAL AND NVL(R1.CODOBLIGPIF, 0) = NVL(RI.CODOBLIGPIF, 0)
  )
  LOOP
    IF   NVL(V_REC.CODGENERAL_INI, 0) = 0
      OR NVL(V_REC.SOLDDOCVAL, 0) &lt;&gt; NVL(V_REC.SOLDDOCVAL_INI, 0)
      OR NVL(V_REC.SOLDDOCREG, 0) &lt;&gt; NVL(V_REC.SOLDDOCREG_INI, 0)
    THEN
      UPDATE TMP_REG1
      SET
        MODIFICARI = 1
      WHERE
        CODREG1 = V_REC.CODREG1;
    END IF;
  END LOOP;

  COMMIT;
 END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER) IS
	  TMP_NR NUMBER(20);
	  NR NUMBER(20);
    cod1 number(20);
  BEGIN
    IF Operation = 0 THEN
      -- UPDATE
      SELECT CodReg INTO RecID FROM TMP_REG;
      UPDATE REG SET (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, An, Luna, CODGEST, Codanaliza, CodCentru, CURS_IFRS, CodAnalizaNod) =
        (SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, An, Luna, CODGEST, Codanaliza, CodCentru, CURS_IFRS, CodAnalizaNod
        FROM TMP_REG)
        WHERE CodReg = RecID;

   		DELETE FROM REG1 WHERE CodReg = RecID;

      for v_rec in (select * from tmp_reg1) loop
        select SEQ_REG1_CODREG1.NEXTVAL into cod1 from dual;
        insert into x(test) values (&apos;codnou:&apos;||cod1);
        --commit;
        INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, CodCentru, CodAnalizaNod, Cont, Semn, Curs, Semnificatie, SUBUNITATEA, CODOBLIGPIF)
        values (cod1, RecID, v_rec.CodGeneral, v_rec.SoldDocVal, v_rec.SoldDoc, v_rec.SoldDocReg, v_rec.CodGest, v_rec.CodCentru, v_rec.CodAnalizaNod, v_rec.Cont, v_rec.Semn, v_rec.Curs, v_rec.Semnificatie, v_rec.SUBUNITATEA, v_rec.CODOBLIGPIF);
        update tmp_jurnal set indexlocal = cod1 where indexlocal = v_rec.codreg1;
        update tmp_jurnal1 set indexlocal = cod1 where indexlocal = v_rec.codreg1;
      end loop;
			/*
			DELETE FROM GENERAL_REG WHERE CodReg = RecID;
      INSERT INTO GENERAL_REG (CodReg, CodGeneral, Curs, Data)
        (SELECT RecID, CodGeneral, PKG_REG.GetCursReg, PKG_REG.GetDataReg
        FROM TMP_REG1);
			*/

			DELETE FROM JURNAL1 WHERE TIPDOC = 46 AND CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);
			FOR V_REC IN
			  (SELECT * FROM TMP_JURNAL1)
			LOOP
			  IF V_REC.CODJURNAL1 &gt; 0 THEN
				  UPDATE  JURNAL1
 					SET
 			 	  CODDOC        = V_REC.CODDOC,
    				TIPDOC        = V_REC.TIPDOC,
 					  INDEXLOCAL    = V_REC.INDEXLOCAL,
 				  	CODBAZAD      = V_REC.CODBAZAD,
        ICONTBAZAD    = V_REC.ICONTBAZAD,
        TIPBAZAD      = V_REC.TIPBAZAD,
        CODBAZAC      = V_REC.CODBAZAC,
        ICONTBAZAC    = V_REC.ICONTBAZAC,
        TIPBAZAC      = V_REC.TIPBAZAC,
        CODDESCRD     = V_REC.CODDESCRD,
        ICONTD        = V_REC.ICONTD,
        TIPCONTD      = V_REC.TIPCONTD,
        ANALITICCONTD = V_REC.ANALITICCONTD,
        CODDESCRC     = V_REC.CODDESCRC,
        ICONTC        = V_REC.ICONTC,
        TIPCONTC      = V_REC.TIPCONTC,
        ANALITICCONTC = V_REC.ANALITICCONTC,
        GEST          = V_REC.GEST,
        VALOARE       = V_REC.VALOARE,
        VALOAREV      = V_REC.VALOAREV,
        VALOARE_IFRS  = V_REC.VALOARE_IFRS,
        VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
        OBS           = V_REC.OBS,
        AN            = V_REC.AN,
        LUNA          = V_REC.LUNA,
        DIRTY         = V_REC.DIRTY,
        SUBUNITATEA   = V_REC.SUBUNITATEA,
        CODCENTRU     = V_REC.CODCENTRU,
        DATADOC       = V_REC.DATADOC,
        DOCUMENT      = V_REC.DOCUMENT,
        CODANALIZANOD = V_REC.CODANALIZANOD
 					WHERE
 					  CODJURNAL1 = V_REC.CODJURNAl1;
				 ELSE
				   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD)
				    VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_Rec.CODCENTRU,v_rec.CODANALIZANOD);
				 END IF;
			END LOOP;
			DELETE FROM JURNAL WHERE TIPDOC = 46 AND CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);
			FOR V_REC IN (SELECT * FROM TMP_JURNAL)
			LOOP
			  IF V_REC.CODJURNAL &gt; 0 THEN
   				UPDATE
   				  JURNAL
   				SET
         CODDOC      = V_REC.CODDOC,
         TIPDOC      = V_REC.TIPDOC,
         INDEXLOCAL  = V_REC.INDEXLOCAL,
         CONTD       = V_REC.CONTD,
         CONTC       = V_REC.CONTC,
         GEST        = V_REC.GEST,
         VALOARE     = V_REC.VALOARE,
         VALOAREV    = V_REC.VALOAREV,
         VALOARE_IFRS  = V_REC.VALOARE_IFRS,
         VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
         OBS         = V_REC.OBS,
         AN          = V_REC.AN,
         LUNA        = V_REC.LUNA,
         SUBUNITATEA = V_REC.SUBUNITATEA,
         DATADOC     = V_REC.DATADOC,
         CODCENTRU   = V_REC.CODCENTRU,
         CODANALIZANOD=V_REC.CODANALIZANOD,
         DOCUMENT    = V_REC.DOCUMENT
   				WHERE
   				  CODJURNAL = V_REC.CODJURNAl;
				 ELSE
				   INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD)
				 	 VALUES (SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD);
				 END IF;
			END LOOP;
   ELSE
      -- INSERT
      SELECT SEQ_REG_CODREG.NEXTVAL INTO RecID FROM DUAL;
      INSERT INTO REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, An, Luna, CODGEST, Codanaliza,
                       CURS_IFRS, CODCENTRU,CODANALIZANOD)
        (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, An, Luna, CODGEST, Codanaliza,
                CURS_IFRS, CODCENTRU,CODANALIZANOD
        FROM TMP_REG);
   		for v_rec in (select * from tmp_reg1) loop
        select SEQ_REG1_CODREG1.NEXTVAL into cod1 from dual;
        INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, CodCentru, CodAnalizaNod, Cont, Semn, Curs, Semnificatie, SUBUNITATEA, CODOBLIGPIF)
        values(cod1, RecID, v_rec.CodGeneral, v_rec.SoldDocVal, v_rec.SoldDoc, v_rec.SoldDocReg, v_rec.CodGest, v_rec.CodCentru, v_rec.CodAnalizaNod, v_rec.Cont, v_rec.Semn, v_rec.Curs, v_rec.Semnificatie, v_rec.SUBUNITATEA, v_rec.CODOBLIGPIF);
        update tmp_jurnal set indexlocal = cod1 where indexlocal = v_rec.codreg1;
        update tmp_jurnal1 set indexlocal = cod1 where indexlocal = v_rec.codreg1;
      end loop;
			/*
      INSERT INTO GENERAL_REG (CodReg, CodGeneral, Curs, Data)
        (SELECT RecID, CodGeneral, PKG_REG.GetCursReg, PKG_REG.GetDataReg
        FROM TMP_REG1);
			*/

    			INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD)
    		 (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD FROM TMP_JURNAL1);

    		  INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD)
    		  (SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD FROM TMP_JURNAL);
   END IF;

   IF RECID &gt; 0 THEN
      -- VERIFIC DACA S-A SCHIMBAT CEVA IN SOLDURILE REGULARIZATE;
      DIFERENTE := 0;
      FOR V_REC IN
       (
         SELECT  INTBL.CONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT,
                 INTBL.SOLDDOCREG SOLDREGIN,
                 OUTTBL.SOLDDOCREG SOLDREGOUT
         FROM
            TMP_REG1CONT_MARTOR INTBL
            LEFT OUTER JOIN TMP_REG1CONT OUTTBL ON OUTTBL.CONT = INTBL.CONT
         UNION
         SELECT  OUTTBL.CONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT,
                 INTBL.SOLDDOCREG SOLDREGIN,
                 OUTTBL.SOLDDOCREG SOLDREGOUT
         FROM
          TMP_REG1CONT OUTTBL
          LEFT OUTER JOIN TMP_REG1CONT_MARTOR INTBL ON INTBL.CONT = OUTTBL.CONT
       )
        LOOP
          IF (NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0))OR(NVL(V_REC.SOLDREGIN, 0) &lt;&gt; NVL(V_REC.SOLDREGOUT, 0))
          THEN
            DIFERENTE := 1;
            EXIT;
          END IF;
        END LOOP;

        SELECT MIN(DATADOC) INTO DATANEXTREG
        FROM
          REG
        WHERE
          TIPREG = 46
          AND DATADOC   &gt; (SELECT DATADOC FROM TMP_REG)
          AND CODMONEDA = (SELECT CODMONEDA FROM TMP_REG);
        CODNEXTREG := NULL;
        IF DATANEXTREG IS NOT NULL THEN
          SELECT CODREG INTO CODNEXTREG FROM REG WHERE DATADOC = DATANEXTREG AND TIPREG = 46 AND CODMONEDA = (SELECT CODMONEDA FROM TMP_REG);
        END IF;

    -- testez daca regularizarile nu afecteaza stingeri ulterioare
    -- 1. TREZOR
         FOR V_REC IN
         (
         SELECT
           REG.CURS AS CURSREG,
           GSTINGATOR.CODGENERAL,
           GSTINGATOR.CURS AS CURSSTINGATOR,
           T1.CODTREZOR
         FROM
           REG REG,
           REG1 REG1,
           OBLIGPIF OSTINS,
           STINGERE S,
           OBLIGPIF OSTINGATOR,
           GENERAL GSTINGATOR,
           TREZOR1 T1
         WHERE
              REG.CODREG             = RECID
          AND REG1.CODREG            = REG.CODREG
          AND OSTINS.CODGENERAL      = REG1.CODGENERAL
          AND S.CODSTINSPIF          = OSTINS.CODOBLIGPIF
          AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
          AND GSTINGATOR.CODGENERAL  = OSTINGATOR.CODGENERAL
          AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
          AND T1.CODTREZOR1          = GSTINGATOR.CODDOC
          AND PKG_REGPART.DATA_DOC_CORECTA(T1.DATADOC,  REG.DATADOC, DATANEXTREG) = 1
    --       T1.DATADOC &gt; REG.DATADOC
          AND REG.CURS &lt;&gt; GSTINGATOR.CURS
          AND NVL(GSTINGATOR.FaraReg, 0) = 0
         )
         LOOP
           UPDATE GENERAL
           SET
             CURS = V_REC.CURSREG
           WHERE
             CODGENERAL = V_REC.CODGENERAL;

           UPDATE JURNAL1
           SET
             DIRTY = 1
           WHERE
             TIPDOC IN (29, 30, 31, 33) AND CODDOC = v_rec.codtrezor;
         END LOOP;

         -- 2.COMPENSARI
         FOR V_REC IN
         (
         SELECT
           REG.CURS AS CURSREG,
           GSTINGATOR.CODGENERAL,
           GSTINGATOR.CURS AS CURSSTINGATOR,
           C.CODCOMPENS
         FROM
           REG REG,
           REG1 REG1,
           OBLIGPIF OSTINS,
           STINGERE S,
           OBLIGPIF OSTINGATOR,
           GENERAL GSTINGATOR,
           COMPENS C
         WHERE
          REG.CODREG                 = RECID
          AND REG1.CODREG            = REG.CODREG
          AND OSTINS.CODGENERAL      = REG1.CODGENERAL
          AND S.CODSTINSPIF          = OSTINS.CODOBLIGPIF
          AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
          AND GSTINGATOR.CODGENERAL  = OSTINGATOR.CODGENERAL
          AND GSTINGATOR.TIPDOC      = 28
          AND C.CODCOMPENS           = GSTINGATOR.CODDOC
      --  AND C.DATADOC &gt; REG.DATADOC
          AND PKG_REGPART.DATA_DOC_CORECTA(C.DATADOC,  REG.DATADOC, DATANEXTREG) = 1
          AND NVL(GSTINGATOR.FaraReg, 0) = 0
         )
         LOOP
           UPDATE JURNAL1
           SET
            DIRTY = 1
           WHERE
            TIPDOC = 28 AND CODDOC = V_REC.CODCOMPENS;
         END LOOP;

         -- DACA AM O REGULARIZARE ULTERIOARA TREBUIE PUSA PE DIRTY
         IF DIFERENTE = 1 THEN
           IF CODNEXTREG IS NOT NULL THEN
             UPDATE JURNAL1
             SET
               DIRTY = 1
             WHERE
               TIPDOC = 46 AND CODDOC = CODNEXTREG;

             UPDATE REG1 R1
               SET CURS = (SELECT CURS FROM TMP_REG)
             WHERE
               CODREG = CODNEXTREG
               AND EXISTS (SELECT CODGENERAL FROM TMP_REG1 WHERE CODGENERAL = R1.CODGENERAL);
           END IF;
         END IF;
    END IF;

    FOR V_REC IN
    (
    SELECT I.CODIES AS CODFACTAVIZ
    FROM
      IESIRI I,
      IESIRI1 I1,
      IESLINK IL,
      IESIRI1 I1Aviz,
      GENERAL GAviz
    WHERE
      I.TIPDOC = 26
      AND I1.CODIES = I.CODIES
      AND IL.CODIES1 = I1.CODIES1
      AND IL.CODLINIEAVIZ = I1Aviz.Codies1
      AND I1Aviz.Codies = GAviz.Coddoc
      AND GAviz.Semnificatie = 240
      AND GAviz.TIPDOC = 20
      AND EXISTS (SELECT CODGENERAL FROM REG1 R1 WHERE R1.CODGENERAL = GAviz.Codgeneral AND R1.CODREG = RECID)
    )
    LOOP
      UPDATE JURNAL1
      SET
         DIRTY = 1
      WHERE
       TIPDOC = 26 AND CODDOC = V_REC.CODFACTAVIZ;

    END LOOP;

    FOR V_REC IN
    (
    SELECT I.CODIES AS CODFACTAVIZ
    FROM
      IESIRI I,
      IESIRI1 I1,
      IESLINK IL,
      IESIRI1 I1Aviz,
      GENERAL GAviz
    WHERE
      I.TIPDOC = 9
      AND I1.CODIES = I.CODIES
      AND IL.CODIES1 = I1.CODIES1
      AND IL.CODLINIEAVIZ = I1Aviz.Codies1
      AND I1Aviz.Codies = GAviz.Coddoc
      AND GAviz.Semnificatie = 140
      AND GAviz.TIPDOC = 2
      AND EXISTS (SELECT CODGENERAL FROM REG1 R1 WHERE R1.CODGENERAL = GAviz.Codgeneral AND R1.CODREG = RECID)
    )
    LOOP
      UPDATE JURNAL1
      SET
         DIRTY = 1
      WHERE
       TIPDOC = 9 AND CODDOC = V_REC.CODFACTAVIZ;

    END LOOP;


			-- ACTUALIZARE RULAJE CONTURI
			FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
			  SELECT COUNT(*) INTO TMP_NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
 				IF TMP_NR = 0 THEN
 				   INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
 			   	VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;

 				UPDATE
 				  NCONTRUL
 				SET
 				  RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE ELSE 0 END),
 					RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE ELSE 0 END),
 					RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
 					RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
          RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
          RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS

 				WHERE
 				  CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
           VALUES
           (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
         END IF;

         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
           RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS
			 WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;


 		END LOOP;


   PKG_GLOBALS.MarkDirtyJurnal;
   NotifyModif(Operation, RecId, &apos;REG&apos;);
   COMMIT;
  END;

FUNCTION GET_CURS_REG_PROVIZION(aCODOBLIGPIF IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NUMBER
IS
  aCURS    NUMBER(20, 7);
  aCURSREG NUMBER(20, 7);
  aANI     NUMBER(5);
  aLUNAI   NUMBER(2);
  aCODREG  NUMBER(20);
  xAN      NUMBER(5);
  xLUNA    NUMBER(2);

  ANOBLIG     NUMBER(5);
  LUNAOBLIG   NUMBER(2);
  CURSOBLIG  NUMBER(20, 7);

BEGIN
  BEGIN
    SELECT CURS INTO aCURS FROM GENERAL G, OBLIGPIF O WHERE O.CODOBLIGPIF = aCODOBLIGPIF AND G.CODGENERAL = O.CODGENERAL;
    EXCEPTION WHEN OTHERS THEN aCURS := 0;
  END;

  BEGIN
    SELECT C.AN, C.LUNA, G.CURS INTO ANOBLIG, LUNAOBLIG, CURSOBLIG
    FROM
      COMPENS C,
      GENERAL G,
      OBLIGPIF O
    WHERE
      O.CODOBLIGPIF = aCODOBLIGPIF
      AND G.CODGENERAL = O.CODGENERAL
      AND G.TIPDOC = 28
      AND C.CODCOMPENS = G.CODDOC;
    EXCEPTION WHEN OTHERS THEN ANOBLIG := 0; LUNAOBLIG := 0;
  END;

  IF ANOBLIG = aAN AND LUNAOBLIG = aLUNA THEN RETURN CURSOBLIG; END IF;

  SELECT ANINITIAL, LUNAINITIALA INTO aANI, aLUNAI FROM FIRMALUNI;
  xAN := aAN; xLuna := aLuna;

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(xAN, xLUNA, xAN, xLUNA);
  WHILE xAN * 12 + xLUNA &gt;= aANI * 12 + aLUNAI LOOP
    BEGIN
      SELECT
        R.CODREG,
        R.CURS
      INTO
        aCODREG,
        aCURSREG
      FROM
        REG R,
        REG1 R1
      WHERE
        R.AN = xAN
        AND R.LUNA = xLUNA
        AND R1.CODOBLIGPIF = aCODOBLIGPIF
        AND R1.CODREG = R.CODREG
        AND R.TIPREG = 46;
      EXCEPTION WHEN OTHERS THEN aCODREG := 0;
    END;

    IF aCODREG  &gt; 0  THEN
      IF PKG_CATEGCONST.GetValConstanta(&apos;RegProviz&apos;, xAN, xLUNA) = &apos;1&apos; THEN
        RETURN aCURSREG;
      END  IF;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(xAN, xLUNA, xAN, xLUNA);

  END LOOP;
  RETURN aCURS;

END;

END PKG_REGPART;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REGPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E8B696ACE947F7C71233309BBDDB3C2496C9C3D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REGPERS IS

  PROCEDURE GenerareReg IS
	  LunaPrecedentaReg NUMBER(2);
		AnPrecedentReg NUMBER(20);
    aSEMN NUMBER(5) := 1;
    aTIPCONT NUMBER(5) := 0;
  BEGIN
		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
		PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
		PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
		PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);
		
    -- populez TMP_REGTREZOR1;
    DELETE FROM TMP_REGPERS1;
    DELETE FROM TMP_REGPERS1;

    DELETE TMP_SOLDPERS_SUB;
    
   -- folosesc manevra TMP_SOLDPERS pentru ca trebuie sa interpretez semnului soldului in functie de TIPUL CONTULUI 
    INSERT INTO 
    TMP_SOLDPERS_SUB 
    (CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA)
  
    SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA 
    FROM 
      V_SOLDPERS_TRANZACTII_SUB
    WHERE
      CODMONEDA = PKG_REG.moneda_reg;
      
      
     FOR V_REC IN 
     (
      SELECT * FROM TMP_SOLDPERS_SUB S
     )
     LOOP
       BEGIN
         SELECT NVL(TIPCONT, 0) INTO ATIPCONT FROM NCONT WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)); 
         EXCEPTION WHEN OTHERS THEN aTIPCONT := 0;
       END;
     
       IF NVL(aTIPCONT, 0) = 1 THEN aSEMN := -1;
       ELSE 
       aSEMN := 1;
       END IF;
       
       UPDATE TMP_SOLDPERS_SUB 
       SET
        SEMN  = aSEMN 
       WHERE
         CODPERS = V_REC.CODPERS
         AND CODMONEDA = V_REC.CODMONEDA
         AND ICONT = V_REC.ICONT;
     END LOOP;
    
    

  

 		INSERT INTO TMP_REGPERS1
  	  (
  	    CodRegPers1, 
        SoldDoc, 
        SoldDocVal, 
        SoldDocReg, 
        CodPers, 
        CodCont,
        ICONT,
        SUBUNITATEA,
        Diferenta, 
        Den_Pers, 
        Den_Cont
  		)

        SELECT  -1 * ROWNUM, 
                SOLDVALUTA, 
                SOLDLEI, 
                SoldValuta * PKG_REG.GetCursReg, 
                CodPers, 
                CodCont,
                ICONT,
                SUBUNITATEA,
        				SoldValuta * PKG_REG.GetCursReg - SoldLei, 
                Prenume || &apos; &apos; || Nume, 
                Den_Cont 
        FROM        
       ( 
        SELECT 
          T1.CODPERS,
          SOLDVALUTA,
          SOLDLEI,
          NUME,
          PRENUME,
          PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))) AS DEN_CONT,
          PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) AS CODCONT,
          ICONT,
          SUBUNITATEA
        FROM  
        (
            SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
            FROM
            (  
              SELECT CODPERS, ICONT, CODMONEDA,SUBUNITATEA,  NVL(SOLDLEI,0) * NVL(SEMN, 1) SOLDLEI , NVL(SOLDVALUTA,0) * NVL(SEMN, 1) SOLDVALUTA
              FROM 
                TMP_SOLDPERS_SUB
              
                UNION ALL
         
               SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
               FROM
                 V_SOLDPERS_PREC_SUB
               WHERE
                 CODMONEDA = PKG_REG.moneda_reg
             )
             GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
          ) T1,
            NPERS NP
          WHERE 
            NP.CodPers = T1.CodPers  
            AND	T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
          ); 

  END;

  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER) IS
    tmp NUMBER(20);
  BEGIN
    SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
  END;
  
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER) IS
  BEGIN
    PKG_GLOBALS.MarkDirtyJurnal;  
    SP_LOCKRECORD(RecID);

    DELETE TMP_REGPERS1_MARTOR;
    INSERT INTO TMP_REGPERS1_MARTOR(CODPERS, SOLDDOCVAL, ICONT)
    SELECT CODPERS, SOLDDOCVAL, ICONT FROM REGPERS1 WHERE CODREG = RECID;
    DELETE FROM REGPERS1 WHERE CodReg = RecID;
    DELETE FROM REG WHERE CodReg = RecID;
		
		FOR V_REC IN
      (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 47) -- mRegularPers = 47
  	LOOP
      UPDATE NCONTRUL
      SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCD = RULAJCD - V_REC.VALOARE, RULAJVCD = RULAJVCD - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

   		UPDATE NCONTRUL
   		SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
   		WHERE CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

      FOR V_REC_JURN_SUB IN
        (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND AN = V_REC.AN AND LUNA = V_REC.LUNA)
      LOOP
        UPDATE NCONTRULSUB
        SET RULAJCC = RULAJCC - V_REC.VALOARE, RULAJVCC = RULAJVCC - V_REC.VALOAREV
        WHERE CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
      END LOOP;

   END LOOP;
			
	 DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 47;
 	 DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 47;
		
   DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 47); 
	 DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 47; 
-- :1:2:3 DEOARECE REGULARIZAREA FIXEAZA SOLDURILE FINALE ALE BANCILOR, DUPA STERGERE regularizare TREBUIE SA LE RECALCULEZ;
  /*PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);

  PKG_GLOBALS.ANTEMP   := PKG_GLOBALS.ANLUCRU;
  PKG_GLOBALS.LUNATEMP := PKG_GLOBALS.LUNALUCRU ;
  PKG_INCHIDERI.MAKE_SOLD_BANK;*/


-- :4:5:6 tranzactiile ulterioare din trezor la conturile implicate in stergere trebuiesc puse pe DIRTY
   /*FOR V_REC_TREZOR IN
   (SELECT T.* FROM 
     TREZOR T,
     NBANKCONT BC
    WHERE 
      TIPDOC IN (29, 30, 31) 
      AND BC.CODBANKCONT = T.CODBANCA
      AND BC.CREDIT = 1
      AND 
      EXISTS 
      (
        SELECT CODBANKCONT FROM
        (
          SELECT CODBANKCONT 
          FROM 
            TMP_REGTREZOR1_MARTOR 
        )  
        WHERE 
          CODBANKCONT = T.CODBANCA
      )
      AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
    )
   LOOP
      UPDATE JURNAL1 
      SET
        DIRTY = 1
      WHERE
        TIPDOC = V_REC_TREZOR.TIPDOC 
        AND CODDOC = V_REC_TREZOR.CODTREZOR;
   END LOOP; */
    NotifyModif(2, RecId, &apos;REG&apos;);
    COMMIT;
  END;
  
  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    DELETE FROM TMP_REGPERS1_MARTOR;
  	DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg, DataDoc)
  	VALUES (0, LAST_DAY(TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;)));
    COMMIT;
  END;
  
  PROCEDURE SP_GOTORECORD(RecID IN NUMBER) IS
  	PARAM_REG_DATA DATE;
	 	PARAM_REG_MONEDA NUMBER(20);
		PARAM_REG_CURS NUMBER(23,7);
		LunaPrecedentaReg NUMBER(2);
		AnPrecedentReg NUMBER(20);
    DIFERENTE NUMBER(1) := 0;
    aSEMN NUMBER(5) := 1;
    aTIPCONT NUMBER(5) := 0;
  BEGIN
    PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
    DELETE FROM TMP_REG;
    INSERT INTO TMP_REG
      (
        CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty,
        Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
      )
      (
        SELECT
          R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty,
          R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.Luna, R.An, CodAnaliza, CodCentru, CodAnalizaNod
        FROM
          REG R
          LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
          LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
        WHERE R.CodReg = RecID
      );
			
		-- pregatesc PARAMS din PKG_REG
    SELECT DataDoc, CodMoneda, Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM TMP_REG;
    PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);
    CURS_IN := PARAM_REG_CURS;
    -- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
    PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
    PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);
    		
    DELETE TMP_REGPERS1_MARTOR;
    INSERT INTO TMP_REGPERS1_MARTOR(CODPERS, ICONT, SOLDDOCVAL) 
    SELECT 
      CODPERS, ICONT, SUM(SOLDDOCVAL) 
    FROM 
      REGPERS1 
    WHERE 
      CODREG = RECID
    GROUP BY CODPERS, ICONT; 
      
    
		-- populez TMP_REGPERS1;
    DELETE FROM TMP_REGPERS1;
    DELETE TMP_SOLDPERS_SUB;
    
   -- folosesc manevra TMP_SOLDPERS pentru ca trebuie sa interpretez semnului soldului in functie de TIPUL CONTULUI 
    INSERT INTO TMP_SOLDPERS_SUB 
    (CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA)
    SELECT 
      CODPERS, 
      ICONT, 
      CODMONEDA, 
      SUBUNITATEA,
      SOLDLEI, 
      SOLDVALUTA 
    FROM 
      V_SOLDPERS_TRANZACTII_SUB
    WHERE
      CODMONEDA =  PKG_REG.moneda_reg;
      
     
     
     FOR V_REC IN 
     (
      SELECT * FROM TMP_SOLDPERS_SUB S
     )
     LOOP
       BEGIN
         SELECT NVL(TIPCONT, 0) INTO ATIPCONT FROM NCONT WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)); 
         EXCEPTION WHEN OTHERS THEN aTIPCONT := 0;
       END;
     
       IF NVL(aTIPCONT, 0) = 1 THEN aSEMN := -1;
       ELSE 
       aSEMN := 1;
       END IF;
       
       UPDATE TMP_SOLDPERS_SUB 
       SET
        SEMN  = aSEMN 
       WHERE
         CODPERS = V_REC.CODPERS
         AND CODMONEDA = V_REC.CODMONEDA
         AND ICONT = V_REC.ICONT;
     END LOOP;
    
    

  

 		INSERT INTO TMP_REGPERS1
  	  (
  	    CodRegPers1, 
        SoldDoc, 
        SoldDocVal, 
        SoldDocReg, 
        CodPers, 
        CodCont,
        ICONT,
        SUBUNITATEA,
        Diferenta, 
        Den_Pers, 
        Den_Cont
  		)

  SELECT  -1 * ROWNUM, 
          SOLDVALUTA, 
          SOLDLEI, 
          SoldValuta * PKG_REG.GetCursReg, 
          CodPers, 
          CodCont,
          ICONT,
          SUBUNITATEA,
  				SoldValuta * PKG_REG.GetCursReg - SoldLei, 
          Prenume || &apos; &apos; || Nume, 
          Den_Cont 
  FROM        
 ( 
  SELECT 
    T1.CODPERS,
    SOLDVALUTA,
    SOLDLEI,
    NUME,
    PRENUME,
    ICONT,
    SUBUNITATEA,
    PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))) AS DEN_CONT,
    PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)) AS CODCONT
  FROM  
  (
      SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
      FROM
      (  
        SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, NVL(SOLDLEI,0) * NVL(SEMN, 1) SOLDLEI , NVL(SOLDVALUTA,0) * NVL(SEMN, 1) SOLDVALUTA
        FROM 
          TMP_SOLDPERS_SUB
        
          UNION ALL
   
         SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
          FROM
           V_SOLDPERS_PREC_SUB
          WHERE
            CODMONEDA =  PKG_REG.moneda_reg
           
       )
       GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
    ) T1,
      NPERS NP
    WHERE 
      NP.CodPers = T1.CodPers  
      AND CODMONEDA = PKG_REG.GetMonedaReg 
      AND	T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
    ); 


    
    
/*    
 		INSERT INTO TMP_REGPERS1
  	  (
  	    CodRegPers1, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont,
        Diferenta, Den_Pers, Den_Cont
  		)
  	  (
  		  SELECT
  			  -1 * ROWNUM, T1.SoldValuta, T1.SoldLei, T1.SoldValuta * PKG_REG.GetCursReg, T1.CodPers, T1.CodCont,
  				T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei, NP.Prenume || &apos; &apos; || NP.Nume, T1.Den_Cont
  			FROM
  				(SELECT CodPers, SoldValuta, SoldLei, CodCont, Den_Cont FROM V_SOLDURIPERSLUNA) T1 -- :7:8:9
  				INNER JOIN NPERS NP ON NP.CodPers = T1.CodPers
  			WHERE
  				-- :10:11:12 NP.CodMoneda = PKG_REG.GetMonedaReg AND
  				T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
  		);
*/    
  		INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL WHERE TIPDOC = 47 AND CODDOC = RECID);
  		INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 47 AND CODDOC = RECID);
  		DELETE TMP_RULAJ;

    -- VERIFIC DIFERENTELE APARUTE FATA DE ULTIMA REGULARIZARE
    FOR V_REC IN  
      (
        SELECT
          INTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          TMP_REGPERS1_MARTOR INTBL
          LEFT OUTER JOIN 
          (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) AS SOLDDOCVAL 
          FROM 
            TMP_REGPERS1 
          GROUP BY CODPERS, ICONT  
          ) OUTTBL ON OUTTBL.CODPERS = INTBL.CODPERS AND OUTTBL.ICONT = INTBL.ICONT
        UNION 
        SELECT
          OUTTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          /*TMP_REGPERS1 OUTTBL*/
          (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) AS SOLDDOCVAL FROM TMP_REGPERS1 GROUP BY CODPERS, ICONT) OUTTBL
          LEFT OUTER JOIN TMP_REGPERS1_MARTOR INTBL ON INTBL.CODPERS = OUTTBL.CODPERS AND INTBL.ICONT = OUTTBL.ICONT
      )
    LOOP
      IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
        DIFERENTE := 1; EXIT;
      END IF;
    END LOOP;
    
    IF DIFERENTE = 1 THEN
      FOR V_REC IN (SELECT * FROM TMP_JURNAL1)
      LOOP 
        UPDATE TMP_JURNAL1 SET DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1; 
        UPDATE JURNAL1 SET DIRTY = 1 WHERE CODJURNAL1 = V_REC.CODJURNAL1;
      END LOOP;

     -- :13:14:15
      /*FOR V_REC_TREZOR IN
      (SELECT T.* FROM 
        TREZOR T,
        NBANKCONT BC
       WHERE 
         TIPDOC IN (29, 30, 31) 
         AND BC.CODBANKCONT = T.CODBANCA
         AND BC.CREDIT = 1
         AND 
         EXISTS 
         (
           SELECT CODBANKCONT FROM
           (
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1 
             UNION
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1_MARTOR 
           )  
           WHERE 
             CODBANKCONT = T.CODBANCA
         )
         AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       )
      LOOP
         UPDATE JURNAL1 
         SET
           DIRTY = 1
         WHERE
           TIPDOC = V_REC_TREZOR.TIPDOC 
           AND CODDOC = V_REC_TREZOR.CODTREZOR;
      END LOOP;*/
      
    END IF;
    COMMIT;
  END;
  
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER) IS
	  NR NUMBER(20);
	  TMP_NR NUMBER(20);
    DIFERENTE NUMBER(1) := 0;
    CURS_OUT NUMBER(20, 7);
    cod1 number(20);
  BEGIN
    SELECT CURS INTO CURS_OUT FROM TMP_REG;
    IF Operation = 0 THEN
      
			-- UPDATE
      SELECT CodReg INTO RecID FROM TMP_REG;
      UPDATE REG SET
        (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod) =
        (SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod FROM TMP_REG)
      WHERE CodReg = RecID;
      DELETE FROM REGPERS1 WHERE CodReg = RecID;
      for v_rec in (select * from TMP_REGPERS1) loop
        select SEQ_REGPERS1_CODREGPERS1.NEXTVAL into cod1 from dual;
        INSERT INTO REGPERS1
        (CodRegPers1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA)
        values (cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodPers, v_rec.CodCont, v_rec.ICONT, v_rec.SUBUNITATEA);
        update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
        update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
	    end loop;
  	
   		DELETE FROM JURNAL1 WHERE TIPDOC = 47 AND CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);
   		FOR V_REC IN
   			(SELECT * FROM TMP_JURNAL1)
   		LOOP
   			IF V_REC.CODJURNAL1 &gt; 0 THEN
   			  UPDATE JURNAL1
   				SET
   				  CODDOC = V_REC.CODDOC,
   					TIPDOC = V_REC.TIPDOC,
   					INDEXLOCAL = V_REC.INDEXLOCAL,
   					CODBAZAD = V_REC.CODBAZAD,
            ICONTBAZAD = V_REC.ICONTBAZAD,
            TIPBAZAD = V_REC.TIPBAZAD,
            CODBAZAC = V_REC.CODBAZAC,
            ICONTBAZAC = V_REC.ICONTBAZAC,
            TIPBAZAC = V_REC.TIPBAZAC,
            CODDESCRD = V_REC.CODDESCRD,
            ICONTD = V_REC.ICONTD,
            TIPCONTD = V_REC.TIPCONTD,
            ANALITICCONTD = V_REC.ANALITICCONTD,
            CODDESCRC = V_REC.CODDESCRC,
            ICONTC = V_REC.ICONTC,
            TIPCONTC = V_REC.TIPCONTC,
            ANALITICCONTC = V_REC.ANALITICCONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE,
            VALOAREV = V_REC.VALOAREV,
            OBS = V_REC.OBS,
            AN = V_REC.AN,
            LUNA = V_REC.LUNA,
            DIRTY = V_REC.DIRTY,
            SUBUNITATEA = V_REC.SUBUNITATEA,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
            DATADOC = V_REC.DATADOC,
            DOCUMENT = V_REC.DOCUMENT
   				WHERE CODJURNAL1 = V_REC.CODJURNAL1;
   			ELSE
   			  INSERT INTO JURNAL1
            (
              CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
              CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
              CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
              GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
          VALUES
            (
              SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,
              V_REC.CODBAZAC, V_REC.ICONTBAZAC, V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC,
              V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
   			END IF;
   		END LOOP;
   		
      DELETE FROM JURNAL WHERE TIPDOC = 47 AND CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);
   		
      FOR V_REC IN
   			(SELECT * FROM TMP_JURNAL)
   		LOOP
   			IF V_REC.CODJURNAL &gt; 0 THEN
   			  UPDATE JURNAL
   				SET  
            CODDOC = V_REC.CODDOC,
            TIPDOC = V_REC.TIPDOC, 
            INDEXLOCAL = V_REC.INDEXLOCAL, 
            CONTD = V_REC.CONTD, 
            CONTC = V_REC.CONTC,
            GEST = V_REC.GEST,
            VALOARE = V_REC.VALOARE, 
            VALOAREV = V_REC.VALOAREV, 
            OBS = V_REC.OBS, 
            AN = V_REC.AN, 
            LUNA = V_REC.LUNA,
            SUBUNITATEA = V_REC.SUBUNITATEA,
            DATADOC = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
            DOCUMENT = V_REC.DOCUMENT
   				WHERE CODJURNAL = V_REC.CODJURNAl;
   			ELSE
   				INSERT INTO JURNAL
            (
              CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
              CONTD, CONTC, GEST, VALOARE, VALOAREV,
              OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD
            )
   				VALUES
            (
              SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,
              V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV,
              V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD
            );
   			END IF;
   		END LOOP;
      
    ELSE
    
			-- INSERT
      SELECT SEQ_REG_CODREG.NEXTVAL INTO RecID FROM DUAL;
      INSERT INTO REG
        (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
        (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod FROM TMP_REG);
      for v_rec in (select * from TMP_REGPERS1) loop
        select SEQ_REGPERS1_CODREGPERS1.NEXTVAL into cod1 from dual;
        INSERT INTO REGPERS1
        (CodRegPers1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodPers, CodCont, ICONT, SUBUNITATEA)
        values (cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodPers, v_rec.CodCont, v_rec.ICONT, v_rec.SUBUNITATEA);
        update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
        update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregpers1;
	    end loop;
				
   			INSERT INTO JURNAL1
          (
            CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL,
            CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
            CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
            GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
          )
   		    (
            SELECT
              SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,
              CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,
              CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC,
              GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
            FROM TMP_JURNAL1
          );
   		  INSERT INTO JURNAL
          (
            CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL,
            CONTD, CONTC, GEST, VALOARE, VALOAREV,
            OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
          )
   		    (
            SELECT
              SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,
              CONTD, CONTC, GEST, VALOARE, VALOAREV,
              OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD
            FROM
              TMP_JURNAL
          );
				
    END IF;
		
		-- ACTUALIZARE RULAJE CONTURI
		FOR V_REC IN
      (SELECT * FROM TMP_RULAJ)
		LOOP
		  SELECT COUNT(*) INTO TMP_NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
			IF TMP_NR = 0 THEN
		    INSERT INTO NCONTRUL
          (
            CODCONTRUL, CODCONT,
            RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
            AN, LUNA
          )
			  VALUES
          (
            SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,
            0, 0, 0, 0, 0, 0, 0, 0,
            PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU
          );
      END IF;
 			UPDATE NCONTRUL SET
 			  RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE ELSE 0 END),
  			RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE ELSE 0 END),
 	 			RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
 		 		RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
 			WHERE 
        CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

     IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
       FOR V_REC_SUB IN
         (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
       LOOP
         SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
         IF NR = 0 THEN
           INSERT INTO NCONTRULSUB
             (
               CODCONTRULSUB, CODCONTRUL,
               RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC,
               SUBUNITATEA
             )
           VALUES
             (
               SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,
               0, 0, 0, 0, 0, 0, 0, 0,
               V_REC.SUBUNITATEA
             );
         END IF;
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
           RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
           RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
         WHERE
           CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;
     END IF;
     
   END LOOP;
   

    FOR V_REC IN  
      (
        SELECT
          INTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          TMP_REGPERS1_MARTOR INTBL
          LEFT OUTER JOIN 
          (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) AS SOLDDOCVAL 
          FROM 
            TMP_REGPERS1 
          GROUP BY CODPERS, ICONT  
          ) OUTTBL ON OUTTBL.CODPERS = INTBL.CODPERS AND OUTTBL.ICONT = INTBL.ICONT
        UNION 
        SELECT
          OUTTBL.CODPERS, INTBL.SOLDDOCVAL SOLDIN, OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          /*TMP_REGPERS1 OUTTBL*/
          (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) AS SOLDDOCVAL FROM TMP_REGPERS1 GROUP BY CODPERS, ICONT) OUTTBL
          LEFT OUTER JOIN TMP_REGPERS1_MARTOR INTBL ON INTBL.CODPERS = OUTTBL.CODPERS AND INTBL.ICONT = OUTTBL.ICONT
      )
    LOOP
      IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
        DIFERENTE := 1; EXIT;
      END IF;
    END LOOP;



    IF (DIFERENTE = 1) OR (NVL(CURS_IN, 0) &lt;&gt; NVL(CURS_OUT, 0)) THEN
      FOR V_REC IN 
        (SELECT *  FROM REG WHERE TIPREG = 47 AND CODMONEDA = (SELECT CODMONEDA FROM TMP_REG) AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU)
      LOOP
        UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = 47 AND CODDOC = V_REC.CODREG;
      END LOOP;   

     -- :16:17:18  
       /*FOR V_REC_TREZOR IN
       (SELECT T.* FROM 
         TREZOR T,
         NBANKCONT BC
        WHERE 
          TIPDOC IN (29, 30, 31) 
          AND BC.CODBANKCONT = T.CODBANCA
          AND BC.CREDIT = 1
          AND 
         EXISTS 
         (
           SELECT CODBANKCONT FROM
           (
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1 
             UNION
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1_MARTOR 
           )  
           WHERE 
             CODBANKCONT = T.CODBANCA
         )
         AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       )
       LOOP
         UPDATE JURNAL1 
         SET
           DIRTY = 1
         WHERE
           TIPDOC = V_REC_TREZOR.TIPDOC 
           AND CODDOC = V_REC_TREZOR.CODTREZOR;
       END LOOP; */
    END IF;
    PKG_GLOBALS.MarkDirtyJurnal;
    NotifyModif(Operation, RecId, &apos;REG&apos;);  
    COMMIT;
  END;
  
END PKG_REGPERS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REGTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81FF083530A6F370BC76FADE1E0B8AB2D1C59245</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REGTREZOR IS

  PROCEDURE GenerareReg IS
	  LunaPrecedentaReg NUMBER(2);
		AnPrecedentReg NUMBER(20);
  BEGIN
		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
		PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
		PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
		PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);
		
		-- populez TMP_REGTREZOR1;
  DELETE FROM TMP_REGTREZOR1;
		INSERT INTO TMP_REGTREZOR1
		  (
		    CodRegTrezor1,
				SoldDoc,
				SoldDocVal,
				SoldDocReg,
				CodBank,
				CodBankCont,
				Diferenta,
				Den_Cont,
				NrCont,
				Filiala,
				Credit,
    SUBUNITATEA
			)
		  (
			  SELECT
				  -1 * ROWNUM,
					T1.SoldValuta,
					T1.SoldLei,
					T1.SoldValuta * PKG_REG.GetCursReg,
					NBC.CodBank,
					T1.CodBankCont,
					T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei,
					NBC.Den_Cont,
					NBC.NrCont,
					NBC.Filiala,
					NBC.Credit,
					NBC.SUBUNITATEA
				FROM
				(
          SELECT
					  SoldValuta,
						SoldLei,
					  CodBankCont
          FROM
					  V_SOLDURIBANCILUNA
         ) T1
				 INNER JOIN NBANKCONT NBC ON NBC.CodBankCont = T1.CodBankCont AND NVL(NBC.FARAREG, 0) = 0
				 WHERE
				   NBC.CodMoneda = PKG_REG.GetMonedaReg AND
					 T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
			 );
  END;

  PROCEDURE SP_LOCKRECORD(RecID IN NUMBER) IS
    tmp NUMBER(20);
  BEGIN
    SELECT CodReg INTO tmp FROM REG WHERE CodReg = RecID FOR UPDATE NOWAIT;
  END;
  
  PROCEDURE SP_DELETERECORD(RecID IN NUMBER) IS
  BEGIN
    PKG_GLOBALS.MarkDirtyJurnal;  
    SP_LOCKRECORD(RecID);

    DELETE TMP_REGTREZOR1_MARTOR;
    INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
    SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = RECID;

  
    DELETE FROM REGTREZOR1 WHERE CodReg = RecID;
    DELETE FROM REG WHERE CodReg = RecID;
		
		FOR
  	  V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = 45)
  	LOOP
     UPDATE
			     NCONTRUL
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV
      WHERE
        CODCONT = V_REC.CONTD AND
				    AN      = PKG_GLOBALS.ANLUCRU AND
				   LUNA     = PKG_GLOBALS.LUNALUCRU;


       FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
       LOOP
         UPDATE NCONTRULSUB
         SET
           RULAJCD  = RULAJCD  - V_REC.VALOARE,
           RULAJVCD = RULAJVCD - V_REC.VALOAREV
         WHERE
           CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;

   			UPDATE
   			  NCONTRUL
   			SET
   			  RULAJCC  = RULAJCC  - V_REC.VALOARE,
   				 RULAJVCC = RULAJVCC - V_REC.VALOAREV
   			WHERE
   			  CODCONT = V_REC.CONTC AND
   				AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


       FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
       LOOP
         UPDATE NCONTRULSUB
         SET
           RULAJCC  = RULAJCC  - V_REC.VALOARE,
           RULAJVCC = RULAJVCC - V_REC.VALOAREV
         WHERE
           CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
       END LOOP;

   		END LOOP;
			
		DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = 45;
 	  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = 45;
    
		DELETE EXPERT1 WHERE CODEXPERT = (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = 45); 
	  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = 45; 
		
-- DEOARECE REGULARIZAREA  FIXEAZA SOLDURILE FINALE ALE BANCILOR, DUPA STERGERE regularizare TREBUIE SA LE RECALCULEZ;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU,  PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);  

  PKG_GLOBALS.ANTEMP   := PKG_GLOBALS.ANLUCRU;
  PKG_GLOBALS.LUNATEMP := PKG_GLOBALS.LUNALUCRU ;
  PKG_INCHIDERI.MAKE_SOLD_BANK;



-- tranzactiile ulterioare din trezor la conturile implicate in stergere trebuiesc puse pe DIRTY
   FOR V_REC_TREZOR IN
   (SELECT T.* FROM 
     TREZOR T,
     NBANKCONT BC
    WHERE 
      TIPDOC IN (29, 30, 31) 
      AND BC.CODBANKCONT = T.CODBANCA
      AND BC.CREDIT = 1
      AND 
      EXISTS 
      (
        SELECT CODBANKCONT FROM
        (
          SELECT CODBANKCONT 
          FROM 
            TMP_REGTREZOR1_MARTOR 
        )  
        WHERE 
          CODBANKCONT = T.CODBANCA
      )
      AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
    )
   LOOP
      UPDATE JURNAL1 
      SET
        DIRTY = 1
      WHERE
        TIPDOC = V_REC_TREZOR.TIPDOC 
        AND CODDOC = V_REC_TREZOR.CODTREZOR;
   END LOOP; 
  
  NotifyModif(2, RecId, &apos;REG&apos;);
  COMMIT;
 END;
  
  PROCEDURE SP_INSERTRECORD IS
  BEGIN

    DELETE FROM TMP_REGTREZOR1_MARTOR;

  		DELETE FROM TMP_REG;
      INSERT INTO TMP_REG
  		  (CodReg, DataDoc)
  		VALUES
  		  (0, LAST_DAY(TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;)));
    COMMIT;
  END;
  
  PROCEDURE SP_GOTORECORD(RecID IN NUMBER) IS
  		PARAM_REG_DATA DATE;
	 	 PARAM_REG_MONEDA NUMBER(20);
		  PARAM_REG_CURS NUMBER(23,7);
		  LunaPrecedentaReg NUMBER(2);
		  AnPrecedentReg NUMBER(20);
    DIFERENTE NUMBER(1) := 0;
  BEGIN
    PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
    DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
      (SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol, B.Simbol, R.Provizion, R.Luna, R.An, R.CodAnaliza, R.CodCentru, R.CodAnalizaNod
      FROM REG R
      LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
      LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
      WHERE R.CodReg = RecID);
			
		-- pregatesc PARAMS din PKG_REG
    		SELECT DataDoc, CodMoneda, Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM TMP_REG;
    		PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);
    		CURS_IN :=  PARAM_REG_CURS;
    		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
    		PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
    		PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
    		PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);
    		
      DELETE TMP_REGTREZOR1_MARTOR;
      INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
      SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = RECID;
    
		-- populez TMP_REGTREZOR1;
    DELETE FROM TMP_REGTREZOR1;
  		INSERT INTO TMP_REGTREZOR1
  		  (
  		    CodRegTrezor1,
  				SoldDoc,
  				SoldDocVal,
  				SoldDocReg,
  				CodBank,
  				CodBankCont,
  				Diferenta,
  				Den_Cont,
  				NrCont,
  				Filiala,
  				Credit,
      SUBUNITATEA
  			)
  		  (
  			  SELECT
  				  -1 * ROWNUM,
  					T1.SoldValuta,
  					T1.SoldLei,
  					T1.SoldValuta * PKG_REG.GetCursReg,
  					NBC.CodBank,
  					T1.CodBankCont,
  					T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei,
  					NBC.Den_Cont,
  					NBC.NrCont,
  					NBC.Filiala,
  					NBC.Credit,
       NBC.SUBUNITATEA
  				FROM
  				(
            SELECT
  					  SoldValuta,
  						SoldLei,
  					  CodBankCont
            FROM
  					  V_SOLDURIBANCILUNA
           ) T1
  				 INNER JOIN NBANKCONT NBC ON NBC.CodBankCont = T1.CodBankCont  AND NVL(NBC.FARAREG, 0) = 0
  				 WHERE
  				   NBC.CodMoneda = PKG_REG.GetMonedaReg AND
  					 T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
  			 );
  	
   
  		INSERT INTO TMP_JURNAL (SELECT * FROM JURNAL WHERE TIPDOC = 45 AND CODDOC = RECID);
  		INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = 45 AND CODDOC = RECID);
  		DELETE TMP_RULAJ;

-- VERIFIC DIFERENTELE APARUTE FATA DE ULTIMA REGULARIZARE

  FOR V_REC IN  
   (
     SELECT  INTBL.CODBANKCONT,
             INTBL.SOLDDOCVAL SOLDIN,
             OUTTBL.SOLDDOCVAL SOLDOUT
     FROM
      TMP_REGTREZOR1_MARTOR INTBL
      LEFT OUTER JOIN TMP_REGTREZOR1 OUTTBL ON OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
     UNION 
     SELECT  OUTTBL.CODBANKCONT,
             INTBL.SOLDDOCVAL SOLDIN,
             OUTTBL.SOLDDOCVAL SOLDOUT
     FROM
      TMP_REGTREZOR1 OUTTBL
      LEFT OUTER JOIN TMP_REGTREZOR1_MARTOR INTBL ON INTBL.CODBANKCONT = OUTTBL.CODBANKCONT)
    LOOP
      IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
        DIFERENTE := 1;
        EXIT;
      END IF;
    END LOOP;




    IF PKG_GLOBALS.ANCURENT * 12 + PKG_GLOBALS.LUNACURENTA &lt;= PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU AND  DIFERENTE = 1 THEN
      
      FOR V_REC IN (SELECT * FROM TMP_JURNAL1)
      LOOP 
        UPDATE TMP_JURNAL1 
        SET
          DIRTY = 1
        WHERE
         CODJURNAL1 = V_REC.CODJURNAL1;
  
        UPDATE JURNAL1 
        SET
          DIRTY = 1
        WHERE
         CODJURNAL1 = V_REC.CODJURNAL1;
 
      END LOOP;


      FOR V_REC_TREZOR IN
      (SELECT T.* FROM 
        TREZOR T,
        NBANKCONT BC
       WHERE 
         TIPDOC IN (29, 30, 31) 
         AND BC.CODBANKCONT = T.CODBANCA
         AND BC.CREDIT = 1
         AND 
         EXISTS 
         (
           SELECT CODBANKCONT FROM
           (
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1 
             UNION
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1_MARTOR 
           )  
           WHERE 
             CODBANKCONT = T.CODBANCA
         )
         AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       )
      LOOP
         UPDATE JURNAL1 
         SET
           DIRTY = 1
         WHERE
           TIPDOC = V_REC_TREZOR.TIPDOC 
           AND CODDOC = V_REC_TREZOR.CODTREZOR;
      END LOOP; 
    END IF;
		
    COMMIT;
  END;
  
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecID OUT NUMBER) IS
	  NR NUMBER(20);
	  TMP_NR NUMBER(20);
   DIFERENTE NUMBER(1) := 0;
   CURS_OUT NUMBER(20, 7) ;
   Cod1 number(20);
  BEGIN
    SELECT CURS INTO CURS_OUT FROM TMP_REG;
    IF Operation = 0 THEN
      
			-- UPDATE
      SELECT CodReg INTO RecID FROM TMP_REG;
      UPDATE REG SET (TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod) =
        (SELECT TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
        FROM TMP_REG)
        WHERE CodReg = RecID;
      DELETE FROM REGTREZOR1 WHERE CodReg = RecID;
      for v_rec in (select * from tmp_regtrezor1) loop
        select SEQ_REGTREZOR1_CODREGTREZOR1.NEXTVAL into Cod1 from dual;
        INSERT INTO REGTREZOR1 (CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
        values (Cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodBank, v_rec.CodBankCont);
        update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
        update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
		  end loop;
      
   			DELETE FROM JURNAL1 WHERE TIPDOC = 45 AND CODDOC = RECID AND CODJURNAL1 NOT IN (SELECT CODJURNAL1 FROM TMP_JURNAl1);
   			FOR V_REC IN
   			  (SELECT * FROM TMP_JURNAL1)
   			LOOP
   			  IF V_REC.CODJURNAL1 &gt; 0 THEN
   				  UPDATE
   					  JURNAL1
   					SET
   					  CODDOC = V_REC.CODDOC,
   						TIPDOC = V_REC.TIPDOC,
   						INDEXLOCAL = V_REC.INDEXLOCAL,
   						CODBAZAD = V_REC.CODBAZAD,
               ICONTBAZAD = V_REC.ICONTBAZAD,
               TIPBAZAD = V_REC.TIPBAZAD,
               CODBAZAC = V_REC.CODBAZAC,
               ICONTBAZAC = V_REC.ICONTBAZAC,
               TIPBAZAC = V_REC.TIPBAZAC,
               CODDESCRD = V_REC.CODDESCRD,
               ICONTD = V_REC.ICONTD,
               TIPCONTD = V_REC.TIPCONTD,
               ANALITICCONTD = V_REC.ANALITICCONTD,
               CODDESCRC = V_REC.CODDESCRC,
               ICONTC = V_REC.ICONTC,
               TIPCONTC = V_REC.TIPCONTC,
               ANALITICCONTC = V_REC.ANALITICCONTC,
               GEST = V_REC.GEST,
               VALOARE = V_REC.VALOARE,
               VALOAREV = V_REC.VALOAREV,
               OBS = V_REC.OBS,
               AN = V_REC.AN,
               LUNA = V_REC.LUNA,
               DIRTY = V_REC.DIRTY,
               SUBUNITATEA = V_REC.SUBUNITATEA,
               DATADOC = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
               DOCUMENT = V_REC.DOCUMENT
   					WHERE
   					  CODJURNAL1 = V_REC.CODJURNAL1;
   				ELSE
   				  INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD)
   				  VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CODBAZAD, V_REC.ICONTBAZAD, V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD);
   				END IF;
   			END LOOP;
   			DELETE FROM JURNAL WHERE TIPDOC = 45 AND CODDOC = RECID AND CODJURNAL NOT IN (SELECT CODJURNAL FROM TMP_JURNAl);
   			FOR V_REC IN
   			  (SELECT * FROM TMP_JURNAL)
   			LOOP
   			  IF V_REC.CODJURNAL &gt; 0 THEN
   				UPDATE
   				  JURNAL
   				SET  
             CODDOC = V_REC.CODDOC,
             TIPDOC = V_REC.TIPDOC, 
             INDEXLOCAL = V_REC.INDEXLOCAL, 
             CONTD = V_REC.CONTD, 
             CONTC = V_REC.CONTC,
             GEST = V_REC.GEST,
             VALOARE = V_REC.VALOARE, 
             VALOAREV = V_REC.VALOAREV, 
             OBS = V_REC.OBS, 
             AN = V_REC.AN, 
             LUNA = V_REC.LUNA,
             SUBUNITATEA = V_REC.SUBUNITATEA,
             DATADOC = V_REC.DATADOC,
        CODCENTRU     = V_REC.CODCENTRU,
        CODANALIZANOD = V_REC.CODANALIZANOD,
             DOCUMENT = V_REC.DOCUMENT
   				WHERE
   				  CODJURNAL = V_REC.CODJURNAl;
   				ELSE
   				  INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT,CODCENTRU,CODANALIZANOD)
   					VALUES (SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT,V_REC.CODCENTRU,V_REC.CODANALIZANOD);
   				END IF;
   			END LOOP;
    ELSE
			-- INSERT
      SELECT SEQ_REG_CODREG.NEXTVAL INTO RecID FROM DUAL;
      INSERT INTO REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod)
        (SELECT RecID, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, Provizion, Luna, An, CodAnaliza, CodCentru, CodAnalizaNod
        FROM TMP_REG);
      for v_rec in (select * from tmp_regtrezor1) loop
        select SEQ_REGTREZOR1_CODREGTREZOR1.NEXTVAL into Cod1 from dual;
        INSERT INTO REGTREZOR1 (CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
        values (Cod1, RecID, v_rec.SoldDoc, v_rec.SoldDocVal, v_rec.SoldDocReg, v_rec.CodBank, v_rec.CodBankCont);
        update tmp_jurnal1 set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
        update tmp_jurnal set indexlocal = Cod1 where indexlocal = v_rec.codregtrezor1;
		  end loop;
				
   			INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD)
   		  (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD, CODBAZAC, ICONTBAZAC, TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD FROM TMP_JURNAL1);
   		  INSERT INTO JURNAL (CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD)
   		  (SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC,CODCENTRU,CODANALIZANOD FROM TMP_JURNAL);
				
    END IF;
		
		-- ACTUALIZARE RULAJE CONTURI
		FOR V_REC IN (SELECT * FROM TMP_RULAJ)
		LOOP
		  SELECT COUNT(*) INTO TMP_NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
			 IF TMP_NR = 0 THEN
		     INSERT INTO NCONTRUL (CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
			    VALUES (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;
 			UPDATE NCONTRUL SET
 			  RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE ELSE 0 END),
  				RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE ELSE 0 END),
 	 			RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
 		 		RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
 			WHERE 
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;


   IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
     FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
     LOOP
       SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

       IF NR = 0 THEN
         INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
         VALUES
         (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
       END IF;
    
       UPDATE NCONTRULSUB
       SET
         RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
         RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
         RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
       WHERE
         CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
     END LOOP;
   END IF; 

		END LOOP;
				



  FOR V_REC IN  
   (
     SELECT  INTBL.CODBANKCONT,
             INTBL.SOLDDOCVAL SOLDIN,
             OUTTBL.SOLDDOCVAL SOLDOUT
     FROM
      TMP_REGTREZOR1_MARTOR INTBL
      LEFT OUTER JOIN TMP_REGTREZOR1 OUTTBL ON OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
     UNION 
     SELECT  OUTTBL.CODBANKCONT,
             INTBL.SOLDDOCVAL SOLDIN,
             OUTTBL.SOLDDOCVAL SOLDOUT
     FROM
      TMP_REGTREZOR1 OUTTBL
      LEFT OUTER JOIN TMP_REGTREZOR1_MARTOR INTBL ON INTBL.CODBANKCONT = OUTTBL.CODBANKCONT)
    LOOP
      IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
        DIFERENTE := 1;
        EXIT;
      END IF;
    END LOOP;



    IF (DIFERENTE = 1)OR(NVL(CURS_IN, 0) &lt;&gt; NVL(CURS_OUT, 0)) THEN
      FOR V_REC IN 
      (SELECT * 
        FROM 
          REG 
        WHERE 
          TIPREG = 45 
          AND CODMONEDA = (SELECT CODMONEDA FROM TMP_REG)
          AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
        )
        LOOP
          UPDATE JURNAL1
          SET 
            DIRTY = 1
          WHERE
           TIPDOC = 45
           AND CODDOC = V_REC.CODREG;
        END LOOP;   


       FOR V_REC_TREZOR IN
       (SELECT T.* FROM 
         TREZOR T,
         NBANKCONT BC
        WHERE 
          TIPDOC IN (29, 30, 31) 
          AND BC.CODBANKCONT = T.CODBANCA
          AND BC.CREDIT = 1
          AND 
         EXISTS 
         (
           SELECT CODBANKCONT FROM
           (
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1 
             UNION
             SELECT CODBANKCONT 
             FROM 
               TMP_REGTREZOR1_MARTOR 
           )  
           WHERE 
             CODBANKCONT = T.CODBANCA
         )
         AND AN * 12 + LUNA &gt; PKG_GLOBALS.ANLUCRU * 12 + PKG_GLOBALS.LUNALUCRU
       )
       LOOP
         UPDATE JURNAL1 
         SET
           DIRTY = 1
         WHERE
           TIPDOC = V_REC_TREZOR.TIPDOC 
           AND CODDOC = V_REC_TREZOR.CODTREZOR;
       END LOOP; 
    END IF;

  PKG_GLOBALS.MarkDirtyJurnal;
  NotifyModif(Operation, RecId, &apos;REG&apos;);  
  COMMIT;
		
END;
  
END PKG_REGTREZOR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REMAKE_SEQUENCES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>435992B2790E636A8BE9AFBD2E52751EBE92C1E4</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REMAKE_SEQUENCES IS

PROCEDURE REMAKE_SEQUENCE(NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2,NUME_SEQ IN VARCHAR2) IS
  STR     VARCHAR2(100);
  VAL_COL NUMBER(10);
  VAL_SEQ NUMBER(10);
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT MAX(&apos; || NUME_COLCOD || &apos;) + 1 FROM &apos; || NUME_TBL INTO VAL_COL;
  BEGIN
    EXECUTE IMMEDIATE &apos;SELECT &apos; || NUME_SEQ || &apos;.NEXTVAL FROM DUAL &apos; INTO VAL_SEQ;
    EXCEPTION WHEN OTHERS THEN VAL_SEQ := 101;
  END;

  VAL_COL := GREATEST(Coalesce(VAL_COL, 0), 101);
  VAL_SEQ := GREATEST(Coalesce(VAL_SEQ, 0), 101);

  BEGIN
    EXECUTE IMMEDIATE &apos;DROP SEQUENCE &apos;||NUME_SEQ;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;
  EXECUTE IMMEDIATE &apos;CREATE SEQUENCE &apos;||NUME_SEQ||&apos; START WITH &apos;||GREATEST(VAL_COL,VAL_SEQ) ||&apos; INCREMENT BY 1&apos;;
END;

PROCEDURE RESTART_SEQUENCE(NUME_SEQ IN VARCHAR, VAL_START NUMBER DEFAULT 100) IS
  vValSeq NUMBER;
BEGIN
  BEGIN -- optiune RESTART introdusa de la 12C
    EXECUTE IMMEDIATE &apos;ALTER SEQUENCE &apos;||NUME_SEQ||&apos; RESTART START WITH &apos; || VAL_START;
  EXCEPTION WHEN OTHERS THEN --11g
    EXECUTE IMMEDIATE &apos;SELECT &apos;        ||NUME_SEQ||&apos;.NEXTVAL FROM DUAL&apos;  INTO vValSeq;
    EXECUTE IMMEDIATE &apos;ALTER SEQUENCE &apos;||NUME_SEQ||&apos; INCREMENT BY &apos; || to_char(VAL_START - vValSeq - 1);
    EXECUTE IMMEDIATE &apos;SELECT &apos;        ||NUME_SEQ||&apos;.NEXTVAL FROM DUAL&apos; INTO vValSeq;
    EXECUTE IMMEDIATE &apos;ALTER SEQUENCE &apos;||NUME_SEQ||&apos; INCREMENT BY 1&apos;;
  END;
END;

PROCEDURE REVAL_SEQUENCE(NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2,NUME_SEQ IN VARCHAR2,SHRINK_SEQ BOOLEAN DEFAULT FALSE) IS
  vNewVal NUMBER;
  vValSeq NUMBER;
  vValCol NUMBER;
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT &apos;||NUME_SEQ||&apos;.NEXTVAL FROM DUAL&apos;         INTO vValSeq;
  EXECUTE IMMEDIATE &apos;SELECT MAX(&apos;||NUME_COLCOD||&apos;)+1 FROM &apos;||NUME_TBL INTO vValCol;

  IF SHRINK_SEQ 
  THEN vNewVal := GREATEST(Coalesce(vValCol, 0), 101);
  ELSE vNewVal := GREATEST(Coalesce(vValCol, 0), 101, vValSeq);
  END IF;

  IF vNewVal &lt;&gt; vValSeq+1 THEN
    PKG_REMAKE_SEQUENCES.RESTART_SEQUENCE(NUME_SEQ, vNewVal); 
  END IF;
END;

PROCEDURE REINIT_ALL_SEQUENCES IS
  TYPE  t_rec IS RECORD(sequence_name VARCHAR2(100));
  TYPE  t_tab IS TABLE OF t_rec;
  t_seq t_tab;
  i     NUMBER;
  vNr   NUMBER;
BEGIN
  SELECT sequence_name BULK COLLECT INTO t_Seq
  FROM user_sequences;

	FOR i IN t_seq.FIRST..t_seq.LAST LOOP
    PKG_REMAKE_SEQUENCES.RESTART_SEQUENCE(t_seq(i).sequence_name); 
  END LOOP;
END;

FUNCTION  REMAKE_ALL_SEQUENCES RETURN VARCHAR2 IS
  TYPE  t_rec IS RECORD(sequence_name VARCHAR2(100), table_name VARCHAR2(50), column_name VARCHAR2(50));
  TYPE  t_tab IS TABLE OF t_rec;
  t_seq t_tab;
  i     NUMBER;
  bNOK  BOOLEAN;
  Fail  NUMBER;
  vRes  VARCHAR2(32000);
BEGIN
  WITH seq AS (
    SELECT
      sequence_name,
      CASE
        WHEN sequence_name = &apos;SEQ_ALERTA_INFO_CODALERTEINFO&apos;  THEN &apos;ALERTE_INFO&apos;
        WHEN sequence_name = &apos;SEQ_ALERTA_INFO_RULARE&apos;         THEN &apos;ALERTE_INFO&apos;
        WHEN sequence_name = &apos;SEQ_AUTORIZATII_CODAUTORIZATII&apos; THEN &apos;NAUTORIZATIIAUTO&apos;
        WHEN sequence_name = &apos;SEQ_BALSTOCREST_COD&apos;            THEN &apos;BAL_STOC_REST&apos;
        WHEN sequence_name = &apos;SEQ_COMANDA1_CODCOMANDA2&apos;       THEN &apos;COMANDA2&apos; -- CRED CA SAU DENUMIT ERONAT ASA
        WHEN sequence_name = &apos;SEQ_COMANDA2_CODCOMANDA3&apos;       THEN &apos;COMANDA3&apos; -- CRED CA SAU DENUMIT ERONAT ASA
        WHEN sequence_name = &apos;SEQ_DESCRIP_CODDESCRIPTOR&apos;      THEN &apos;DESCRIPTORI&apos;
        WHEN sequence_name = &apos;SEQ_DESCRIPT1_CODDESCRIPTOR1&apos;   THEN &apos;DESCRIPTORI1&apos;
        WHEN sequence_name = &apos;SEQ_DPP_CODDIFPRETPROD&apos;         THEN &apos;DIFPRETPROD&apos;
        WHEN sequence_name = &apos;SEQ_DPP1_CODDIFPRETPROD1&apos;       THEN &apos;DIFPRETPROD1&apos;
        WHEN sequence_name = &apos;SEQ_ETICHCOLET_COD&apos;             THEN &apos;NARTOBJCOLET&apos;
        WHEN sequence_name = &apos;SEQ_ESTPROD1M_CODESTPROD1M&apos;     THEN &apos;ESTIMARIPROD1M&apos;
        WHEN sequence_name = &apos;SEQ_ESTPROD1M_CODESTPROD1M&apos;     THEN &apos;ESTIMARIPROD1M&apos;
        WHEN sequence_name = &apos;SEQ_ESTPROD1N_CODESTPROD1N&apos;     THEN &apos;ESTIMARIPROD1N&apos;
        WHEN sequence_name = &apos;SEQ_IESIRIR_CODIESR&apos;            THEN &apos;IESIRIRETAIL&apos;
        WHEN sequence_name = &apos;SEQ_IESIRI1R_CODIES1R&apos;          THEN &apos;IESIRI1RETAIL&apos;
        WHEN sequence_name = &apos;SEQ_MEDEXT_CODMEDEXT&apos;           THEN &apos;MEDEX_TARI&apos;
        WHEN sequence_name = &apos;SEQ_NELEMAERO_CODELEMAERO&apos;      THEN &apos;NELEMAEROAUTO&apos;
        WHEN sequence_name = &apos;SEQ_NINTERV_CODINTERV&apos;          THEN &apos;NINTERVENTIIAUTO&apos;
        WHEN sequence_name = &apos;SEQ_NPARTCODFISC_COD_CODFISCAL&apos; THEN &apos;NPARTCODFISC&apos;
        WHEN sequence_name = &apos;SEQ_NPARTLC_CODNPARTLC&apos;         THEN &apos;NPARTLSTCLASE&apos;
        WHEN sequence_name = &apos;SEQ_PMP_ALL_LUNA&apos;               THEN &apos;PMP_ALL_LUNA&apos;
        WHEN sequence_name = &apos;SEQ_PRELPRET_RETAIL&apos;            THEN &apos;SYNCPRETRETAIL&apos;
        WHEN sequence_name = &apos;SEQ_PRIORITATEGANTT&apos;            THEN &apos;GANTT&apos;
        WHEN sequence_name = &apos;SEQ_PROCACTDATE_CODPROCACT&apos;     THEN &apos;PROC_ACT_DATE&apos;
        WHEN sequence_name = &apos;SEQ_PROCACTDATE1_CODPROCACT1&apos;   THEN &apos;PROC_ACT_DATE1&apos;
        WHEN sequence_name = &apos;SEQ_PROCACTDEF_CODPROCDEF&apos;      THEN &apos;PROC_ACT_DEF&apos;
        WHEN sequence_name = &apos;SEQ_RESTOBIECTE_COD&apos;            THEN &apos;RESTOBIECT&apos;
        WHEN sequence_name = &apos;SEQ_SYSNPRETRETAIL_CODSYNC&apos;     THEN &apos;SYNCPRETRETAIL&apos;
        WHEN sequence_name = &apos;SEQ_TIPSEDII1_CODTIPSEDIU1&apos;     THEN &apos;NTIPSEDII1&apos;
        WHEN sequence_name = &apos;SEQ_USER_LISTS_LISTID&apos;          THEN &apos;MENULISTE&apos;
        WHEN sequence_name = &apos;SEQ_TRIGAR_MODIF&apos;               THEN &apos;TRIGAR_MODIF&apos;
        WHEN sequence_name = &apos;SEQ_SINTEZAEMUL1_CODSINTEZA1&apos;   THEN &apos;SINTEZAEMULARE1&apos;
        WHEN sequence_name = &apos;SEQ_SINTEZAEMUL2_CODSINTEZA2&apos;   THEN &apos;SINTEZAEMULARE2&apos;
        WHEN sequence_name = &apos;SEQ_STOBJASOC_CODSTOBJASOC&apos;     THEN &apos;SETTASKOBJASOC&apos;
        WHEN INSTR(seq.sequence_name,&apos;_&apos;, 5) = 0              THEN SubStr(seq.sequence_name, 5)
        ELSE                                                       SubStr(seq.sequence_name, 5, INSTR(seq.sequence_name,&apos;_&apos;,-1)-5 )
      END table_name,
      CASE -- in principiu secventa este asociata primei coloane din tabela, iar exceptiile sunt in acest case
        WHEN sequence_name = &apos;SEQ_ALERTA_INFO_RULARE&apos;         THEN &apos;CODRULARE&apos;
        WHEN sequence_name = &apos;SEQ_ETICHCOLET_COD&apos;             THEN &apos;IDCOLET&apos;
        WHEN sequence_name = &apos;SEQ_EMULARE_BONID&apos;              THEN &apos;IDBON&apos;
        WHEN sequence_name = &apos;SEQ_PRELPRET_RETAIL&apos;            THEN &apos;IDPRELUARE&apos;
        WHEN sequence_name = &apos;SEQ_TRIGAR_MODIF&apos;               THEN &apos;CODMODIF&apos;
        WHEN sequence_name = &apos;SEQ_PRIORITATEGANTT&apos;            THEN &apos;PRIORITATE&apos;
        WHEN sequence_name = &apos;SEQ_STAREESTIMARI1_CODSTARE1&apos;   THEN &apos;CODSTARE1&apos;
        WHEN sequence_name = &apos;SEQ_NMVS_CODNMVS&apos;               THEN &apos;CODNMVS&apos;
        ELSE NULL
      END column_name
    FROM user_sequences seq
    WHERE sequence_name &lt;&gt; &apos;SEQ_CONDCOR2_CODCONDCOR2&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_INVENTLOC_CODINVENTLOC&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_JOB_LISTCONFIG_CODJ&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_JOB_LISTE_TABLEID&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_JOBUNIC&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_LIST_COUNTER&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NPARC3_CODNPARC0&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NPARTOPORTUNITATI_CPO&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NRI_CMDINTERNA&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NRINV_MF&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_PCDISTRIB_CODPCDISTRIB&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_PCFIRMA_CODPCFIRMA&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_SERIE_UNICA&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_TARIFEMASTER_CODTARIFM&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_TREZOR1REG_CODTREZ1REG&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_ALERTE1_CODALERTA1&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_ALERTE1_DEF_CODALERTEDEF1&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_CMDTL_CODCMDTL&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NPERSTIPLUCR_CODTIPLUCR&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_PROCACTDATE1_CODPROCACT1&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_PROCACTDATE_CODPROCACT&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_RAC_REZP_COD&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_RAC_REZS_COD&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_USER_LISTS_LISTID&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_NATRTRAD_CODNATRTRAD&apos;
      AND sequence_name &lt;&gt; &apos;SEQ_TVADISC_CODTVADISC&apos;
  )
  SELECT seq.sequence_name, t.table_name, Coalesce(seq.column_name, c1.column_name) column_name BULK COLLECT INTO t_Seq
  FROM seq
    LEFT JOIN user_tables t ON t.table_name = seq.table_name
    --LEFT JOIN user_tab_columns cs ON cs.table_name = seq.table_name AND cs.column_name = seq.column_name
    LEFT JOIN user_tab_columns c1 ON c1.table_name = seq.table_name AND c1.column_id = 1;

  --stef pt a testa tabelele care apar in mai multe seqvente pentru corectii se inlocuieste selectul de mai sus (si se ruleaza pe martor), si dupa aia verificare manuala
  --SELECT t.table_name, Coalesce(cs.column_name, c1.column_name) col_name, Count(1) NrAparitii, min (seq.sequence_name), Max(seq.sequence_name)
  --FROM seq
  --  LEFT JOIN user_tables t ON t.table_name = seq.table_name
  --  LEFT JOIN user_tab_columns cs ON cs.table_name = seq.table_name AND cs.column_name = seq.column_name
  --  LEFT JOIN user_tab_columns c1 ON c1.table_name = seq.table_name AND c1.column_id = 1
  --GROUP BY t.table_name, Coalesce(cs.column_name, c1.column_name)
  --ORDER BY 3 desc


  FAIL := 0;
	FOR i IN t_seq.FIRST..t_seq.LAST LOOP
    bNOK := FALSE;
    IF t_seq(i).table_name IS NULL
    THEN
      bNOK := TRUE;
    ELSE
      BEGIN
        -- STEF - ca sa nu mai invalideze pachete prin drop/create sequence
        pkg_remake_sequences.REVAL_SEQUENCE(t_seq(i).table_name, t_seq(i).column_name, t_seq(i).sequence_name);
        --pkg_remake_sequences.REMAKE_SEQUENCE(t_seq(i).table_name, t_seq(i).column_name, t_seq(i).sequence_name);
      EXCEPTION
        WHEN OTHERS THEN bNOK := TRUE;
      END;
    END IF;

    IF bNOK THEN
      FAIL := FAIL + 1;
      IF FAIL &gt; 1 THEN vRes := vRes ||&apos;; &apos;; END IF;
      vRes := vRes ||t_seq(i).sequence_name;
    END IF;
  END LOOP;

  DELETE nirstoc1 ns1 WHERE NOT EXISTS (SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = NS1.CODNIRSTOC);

  IF FAIL = 0
  THEN vRes := &apos;&apos;;
  ELSE vRes := &apos;Secvente nerefacute : &apos;||vRes;
  END IF;

  RETURN vRes;
END;

PROCEDURE REMAKE_ALL_SEQUENCES IS
RESULT VARCHAR2(32000);
BEGIN
  RESULT := REMAKE_ALL_SEQUENCES;
END;

end PKG_REMAKE_SEQUENCES;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RESTAURANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15F62F550B7816460F12585FB4258F5AFC0885B0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RESTAURANT IS

PROCEDURE MAKE_ALL_STOC_LA_DATA( aDATA IN VARCHAR2)
IS
BEGIN
  DELETE TMP_NIR_LA_DATA;
  INSERT INTO TMP_NIR_LA_DATA (CODOBIECT, CANTNIR)
  SELECT
    CODOBIECT,
    SUM(CANTNIR) AS CANTNIR
  FROM
   (
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND NVL(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
--   AND NVL(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
--     AND NVL(A.CASADEMARCAT, 0) = 1
     AND NS.CODIOART = IO1.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
   UNION ALL
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
     --LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND NVL(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
--   AND NVL(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
--     AND NVL(A.CASADEMARCAT, 0) = 1
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
   )
   WHERE
     NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; TO_DATE(aDATA, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   DELETE TMP_LIVR_LA_DATA;
   INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
   SELECT
     CODOBIECT,
     SUM(CANT) AS CANT
   FROM
   (
   SELECT
     NS.CODOBIECT,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END
      CANT,
      L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A
   WHERE
     L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
     AND NS.CODNIR = N.CODNIR
     AND NVL(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
--     AND NVL(A.CASADEMARCAT, 0) = 1
   )
   WHERE
    NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; TO_DATE(aData, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   MERGE INTO TMP_NIR_LA_DATA N
   USING TMP_LIVR_LA_DATA L
   ON ( N.CODOBIECT = L.CODOBIECT)
   WHEN MATCHED THEN UPDATE SET N.CANTNIR = N.CANTNIR - L.CANTNIR;


   COMMIT;

END;

PROCEDURE MAKE_STOC_DATA_GEST(aDataStart IN VARCHAR2, aDataStop IN VARCHAR2)
IS
oData date;
vDataStart date;
vDataStop date;
BEGIN
  if to_date(aDataStart,&apos;dd.mm.yyyy&apos;) &gt; to_date(aDataStop,&apos;dd.mm.yyyy&apos;) then 
    vDataStart := to_date(aDataStop,&apos;dd.mm.yyyy&apos;);
    vDataStop := to_date(aDataStart,&apos;dd.mm.yyyy&apos;);
  else
    vDataStart := to_date(aDataStart,&apos;dd.mm.yyyy&apos;);
    vDataStop := to_date(aDataStop,&apos;dd.mm.yyyy&apos;);
  end if;
  DELETE TMP_STOC_DATA_GEST;
  oData := vDataStart;
  
  DELETE TMP_STOC_DATA_GEST;
  INSERT INTO TMP_STOC_DATA_GEST (CODGEST, CODIOART, VALOARE, DATASTOC)
  SELECT
    CODGEST,
    CODIOART,
    SUM(VALOARE),
    oData
  FROM
   (
   SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    NS.CANTNIR * NS.PRET VALOARE,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.OPERAT = 1
     AND NVL(N.GEST, 0) &lt;&gt; 0
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND NS.CODIOART = IO1.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
  UNION ALL
  SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    NS.CANTNIR * NS.PRET VALOARE,
    N.DATANIR AS DATACREARE
  FROM
    NIRSTOC NS,
    NIR N,
    NARTOBJ O,
    NART A
  WHERE
    NS.CODNIR = N.CODNIR
    AND N.OPERAT = 1
    AND NVL(N.GEST, 0) &lt;&gt; 0
    AND O.CODOBIECT = NS.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
  )
  WHERE
    NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; oDATA
  GROUP BY CODGEST, CODIOART;

  DELETE TMP_LIVR_DATA_GEST;
  INSERT INTO TMP_LIVR_DATA_GEST(CODGEST, CODIOART, VALOARE)
  SELECT
    CODGEST,
    CODIOART,
    SUM(VALOARE) AS VALOARE
  FROM
  (
  SELECT
    N.GEST CODGEST,
    NS.CODIOART,
    CASE
      WHEN L.TIPLIVR = 15 THEN  -L1.CANT
      ELSE L1.CANT
    END * NS.PRET VALOARE,
    L.DATALIVR AS DATACREARE
  FROM
    LIVR1 L1,
    LIVR L,
    NIRSTOC NS,
    NIR N,
    NARTOBJ O,
    NART A
  WHERE
    L1.CODNIRSTOC = NS.CODNIRSTOC
    AND L1.CODLIVR = L.CODLIVR
    AND NS.CODNIR = N.CODNIR
    AND NVL(N.GEST, 0) &lt;&gt; 0
    AND O.CODOBIECT = NS.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
  )
  WHERE
    NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; oData
  GROUP BY CODGEST, CODIOART; 

  MERGE INTO TMP_STOC_DATA_GEST N
  USING TMP_LIVR_DATA_GEST L
  ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
  WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE - L.VALOARE;
  COMMIT;
   
  WHILE oData &lt;= vDataStop LOOP
    DELETE TMP_NIR_DATA_GEST;
    INSERT INTO TMP_NIR_DATA_GEST (CODGEST, CODIOART, VALOARE)
    SELECT CODGEST, CODIOART, VALOARE
    FROM TMP_STOC_DATA_GEST
    WHERE DATASTOC = ODATA;
     
    oData := trunc(oData + 1);
     
    INSERT INTO TMP_STOC_DATA_GEST
    SELECT CODGEST, CODIOART, VALOARE, ODATA
    FROM TMP_NIR_DATA_GEST;
    
    DELETE TMP_NIR_DATA_GEST;
    INSERT INTO TMP_NIR_DATA_GEST (CODGEST, CODIOART, VALOARE)
    SELECT
      CODGEST,
      CODIOART,
      SUM(VALOARE)
    FROM
     (
     SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      NS.CANTNIR * NS.PRET VALOARE
     FROM
       NIRSTOC NS,
       NIR N,
       NARTOBJ O,
       NART A,
       IOART1 IO1
    WHERE
       NS.CODNIR = N.CODNIR
       AND N.OPERAT = 1
       AND NVL(N.GEST, 0) &lt;&gt; 0
       AND O.CODOBIECT = NS.CODOBIECT
       AND A.CODARTICOL = O.CODARTICOL
       AND NS.CODIOART = IO1.CODIOART
       AND IO1.MG &lt;&gt; 5
       AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
       AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
       AND NVL(N.DATANIR, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) = oDATA
    UNION ALL
    SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      NS.CANTNIR * NS.PRET VALOARE
    FROM
      NIRSTOC NS,
      NIR N,
      NARTOBJ O,
      NART A
    WHERE
      NS.CODNIR = N.CODNIR
      AND N.OPERAT = 1
      AND NVL(N.GEST, 0) &lt;&gt; 0
      AND O.CODOBIECT = NS.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
      AND NVL(N.DATANIR, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) = oDATA
    )
    GROUP BY CODGEST, CODIOART;

    DELETE TMP_LIVR_DATA_GEST;
    INSERT INTO TMP_LIVR_DATA_GEST(CODGEST, CODIOART, VALOARE)
    SELECT
      CODGEST,
      CODIOART,
      SUM(VALOARE) AS VALOARE
    FROM
    (
    SELECT
      N.GEST CODGEST,
      NS.CODIOART,
      CASE
        WHEN L.TIPLIVR = 15 THEN  -L1.CANT
        ELSE L1.CANT
      END * NS.PRET VALOARE,
      L.DATALIVR AS DATACREARE
    FROM
      LIVR1 L1,
      LIVR L,
      NIRSTOC NS,
      NIR N,
      NARTOBJ O,
      NART A
    WHERE
      L1.CODNIRSTOC = NS.CODNIRSTOC
      AND L1.CODLIVR = L.CODLIVR
      AND NS.CODNIR = N.CODNIR
      AND NVL(N.GEST, 0) &lt;&gt; 0
      AND O.CODOBIECT = NS.CODOBIECT
      AND A.CODARTICOL = O.CODARTICOL
      AND NVL(L.DATALIVR, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) = oDATA
    )
    GROUP BY CODGEST, CODIOART;
    
    MERGE INTO TMP_STOC_DATA_GEST N
    USING TMP_NIR_DATA_GEST L
    ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
    WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE + L.VALOARE
    WHEN NOT MATCHED THEN INSERT (N.CODGEST, N.CODIOART, N.VALOARE, N.DATASTOC)
    VALUES (L.CODGEST, L.CODIOART, L.VALOARE, ODATA);
    
    MERGE INTO TMP_STOC_DATA_GEST N
    USING TMP_LIVR_DATA_GEST L
    ON ( N.CODGEST = L.CODGEST AND N.CODIOART = L.CODIOART AND N.DATASTOC = oData)
    WHEN MATCHED THEN UPDATE SET N.VALOARE = N.VALOARE - L.VALOARE;
    COMMIT;
  END LOOP;
END;

PROCEDURE GET_RESTOBSART(aCODRESTAURANT IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTOBSART;

  INSERT INTO TMP_RESTOBSART(COD, CODRESTAURANT, CODOBIECT, NEWRECORD, SELECTAT, OBS)
  SELECT
    COD,
    CODRESTAURANT,
    CODOBIECT,
    0,
    0,
    OBS
  FROM
   RESTOBSART
  WHERE
    CODRESTAURANT = aCODRESTAURANT   ;

 DELETE TMP_RESTOBSART_INI;

 INSERT INTO TMP_RESTOBSART_INI (COD) SELECT COD FROM TMP_RESTOBSART;



 COMMIT;
END;

PROCEDURE POST_RESTOBSART(aCODRESTAURANT IN NUMBER)
IS
aCODOBIECT NUMBER(20) := 0;
BEGIN
  DELETE FROM RESTOBSART O
  WHERE
   EXISTS(SELECT COD FROM TMP_RESTOBSART_INI OI WHERE OI.COD = O.COD)
   AND NOT EXISTS(SELECT COD FROM TMP_RESTOBSART OT WHERE OT.COD = O.COD);


  FOR V_REC IN (SELECT * FROM TMP_RESTOBSART)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTOBSART
      SET
       OBS = V_REC.OBS
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO RESTOBSART(COD, CODRESTAURANT, CODOBIECT, OBS)
      VALUES (V_REC.COD, V_REC.CODRESTAURANT, V_REC.CODOBIECT, V_REC.OBS);
    END IF;
  END LOOP;


  COMMIT;
END;



PROCEDURE MEMO_BALSTOCREST(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    INSERT INTO BAL_STOC_REST(COD, CODGEST, DATASTART, DATAEND)
    VALUES (SEQ_BALSTOCREST_COD.NEXTVAL, aGEST, TO_DATE(aDATA_START, &apos;DD.MM.YYYY hh24:mi&apos;), TO_DATE(aDATA_END, &apos;DD.MM.YYYY hh24:mi&apos;));
    EXCEPTION WHEN OTHERS THEN NULL;
  END;
  COMMIT;
END;


PROCEDURE MEMO_RESTRAPORTZ(aCODPOSTRETAIL IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    INSERT INTO RESTRAPORTZ(COD,CODPOSTRETAIL, DATASTART, DATAEND)
    VALUES (SEQ_RESTRAPORTZ_COD.NEXTVAL, aCODPOSTRETAIL, TO_DATE(aDATA_START, &apos;DD.MM.YYYY hh24:mi&apos;), TO_DATE(aDATA_END, &apos;DD.MM.YYYY hh24:mi&apos;));
    EXCEPTION WHEN OTHERS THEN NULL;
  END;
  COMMIT;
END;


PROCEDURE SET_CMD_DIMINUATE
IS
BEGIN
  FOR V_REC IN (SELECT CODUNIC FROM TMP_MANEVRA)
  LOOP
    UPDATE RESTCMD
    SET
      DIMINUAT = 1
    WHERE
      CODRESTCMD = V_REC.CODUNIC;
  END LOOP;
  COMMIT;
END;

PROCEDURE MAKE_STOC_LA_DATA(aGEST IN NUMBER, aDATA IN VARCHAR2)
IS
BEGIN
  DELETE TMP_NIR_LA_DATA;
  INSERT INTO TMP_NIR_LA_DATA (CODOBIECT, CANTNIR)
  SELECT
    CODOBIECT,
    SUM(CANTNIR) AS CANTNIR
  FROM
   (
   SELECT
    NS.CODOBIECT,
    CANTNIR,
  /*
    CASE
      WHEN N.CODINTR IS NOT NULL THEN --I.DATACREARE
      CASE
       WHEN TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;) &lt;&gt; TO_CHAR(I.DATACREARE, &apos;DD.MM.YYYY&apos;) THEN I.DATADOC
       ELSE I.DATACREARE
      END

      WHEN N.CODTRANSF IS NOT NULL THEN --T.DATACREARE
      CASE
       WHEN TO_CHAR(T.DATADOC, &apos;DD.MM.YYYY&apos;) &lt;&gt;  TO_CHAR(T.DATACREARE, &apos;DD.MM.YYYY&apos;) THEN T.DATADOC
       ELSE T.DATACREARE
      END

      WHEN N.CODIES IS NOT NULL THEN --E.DATACREARE
      CASE
       WHEN TO_CHAR(E.DATADOC, &apos;DD.MM.YYYY&apos;) &lt;&gt; TO_CHAR(E.DATACREARE, &apos;DD.MM.YYYY&apos;) THEN E.DATADOC
       ELSE E.DATACREARE
      END
    END */
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
--   AND NVL(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
     AND NVL(A.CASADEMARCAT, 0) = 1
     AND NS.CODIOART = IO1.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &gt;= (select aninitial*12+lunainitiala from firmaluni)
   UNION ALL
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     --LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
     --LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
     --LEFT OUTER JOIN IESIRI E ON E.CODIES    = N.CODIES,
     NARTOBJ O,
     NART A
  WHERE
     NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
--   AND NVL(O.PRODUSPROPRIU, 0) = 0
     AND A.CODARTICOL = O.CODARTICOL
     AND NVL(A.CASADEMARCAT, 0) = 1
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) &lt; (select aninitial*12+lunainitiala from firmaluni)
   )
   WHERE
     NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; TO_DATE(aDATA, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   DELETE TMP_LIVR_LA_DATA;
   INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
   SELECT
     CODOBIECT,
     SUM(CANT) AS CANT
   FROM
   (
   SELECT
     NS.CODOBIECT,
     CASE
       WHEN L.TIPLIVR = 15 THEN  -L1.CANT
       ELSE L1.CANT
     END
      CANT,
      L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A
   WHERE
     L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
     AND NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND NVL(A.CASADEMARCAT, 0) = 1
   )
   WHERE
    NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; TO_DATE(aData, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   MERGE INTO TMP_NIR_LA_DATA N
   USING TMP_LIVR_LA_DATA L
   ON ( N.CODOBIECT = L.CODOBIECT)
   WHEN MATCHED THEN UPDATE SET N.CANTNIR = N.CANTNIR - L.CANTNIR;


  -- COMMIT;

END;


PROCEDURE MAKE_MISCARI_IN_INTERVALUL(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
BEGIN
  DELETE TMP_NIR_IN_INTERVALUL;
  INSERT INTO TMP_NIR_IN_INTERVALUL (CODOBIECT, CANTNIR)
  SELECT
    CODOBIECT,
    SUM(CANTNIR) AS CANTNIR
  FROM
   (
   SELECT
    NS.CODOBIECT,
    CANTNIR,
    N.DATANIR AS DATACREARE
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR        = N.CODNIR
     AND N.GEST       = aGEST
     AND O.CODOBIECT  = NS.CODOBIECT
     AND O.CODARTICOL = A.CODARTICOL
     AND NVL(A.CASADEMARCAT, 1) = 1
     AND IO1.CODIOART = NS.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND N.TIPNIR &lt;&gt; 12 AND N.TIPNIR &lt;&gt; 13
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
   UNION ALL -- maririle de stoc le consideri ntrari
   SELECT
     NS.CODOBIECT,
     L1.CANT
      CANT,
      L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
   WHERE
     L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
     AND L.TIPLIVR = 15 -- mariri de stoc
     AND NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND NVL(A.CASADEMARCAT, 0) = 1
     AND IO1.CODIOART = NS.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
   )
   WHERE
      NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aDATA_START, &apos;DD.MM.YYYY hh24:mi&apos;)
     AND  NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aDATA_END, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   DELETE TMP_LIVR_IN_INTERVALUL;
   INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
   SELECT
     CODOBIECT,
     SUM(CANT) AS CANT
   FROM
   (
   SELECT
     NS.CODOBIECT,
     L1.CANT,
     L.DATALIVR AS DATACREARE
   FROM
     LIVR1 L1,
     LIVR L,
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A
   WHERE
     L1.CODNIRSTOC = NS.CODNIRSTOC
     AND L1.CODLIVR = L.CODLIVR
     AND L.TIPLIVR &lt;&gt; 15 -- maririle le-am bagat pe intrari
     AND L.TIPLIVR &lt;&gt; 12 AND L.TIPLIVR &lt;&gt; 13
     AND NS.CODNIR = N.CODNIR
     AND N.GEST = aGEST
     AND O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND NVL(A.CASADEMARCAT, 0) = 1
   )
   WHERE
         NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aData_START, &apos;DD.MM.YYYY hh24:mi&apos;)
     AND NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END, &apos;DD.MM.YYYY hh24:mi&apos;)
   GROUP BY CODOBIECT;

   --COMMIT;
END;


PROCEDURE MAKE_BALANTA_STOC(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
BEGIN
  DELETE TMP_BALANTA_STOC;
  MAKE_STOC_LA_DATA(aGEST, aDATA_START);
  MAKE_MISCARI_IN_INTERVALUL(aGEST, aDATA_START, aDATA_END);

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_LA_DATA N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, N.CANTNIR, 0, 0);


 MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_NIR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, 0, N.CANTNIR,  0)
  WHEN     MATCHED THEN UPDATE SET SD.INTRARI = N.CANTNIR;

 MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = N.CANTNIR;

-- detaliere iesiri pe diverse coloane
  FOR V_REC IN
 (
    SELECT
      CODOBIECT,
      TIPLIVR,
      SUM(CANT) AS CANT
     FROM
    (
       SELECT
         NS.CODOBIECT,
         L.TIPLIVR,
         L1.CANT,
         L.DATALIVR AS DATACREARE
       FROM
         LIVR1 L1,
         LIVR L,
         NIRSTOC NS,
         NIR N,
         NARTOBJ O,
         NART A
       WHERE
         L1.CODNIRSTOC = NS.CODNIRSTOC
         AND L1.CODLIVR = L.CODLIVR
         AND L.TIPLIVR &lt;&gt; 15
         AND NS.CODNIR = N.CODNIR
         AND N.GEST = aGEST
         AND O.CODOBIECT = NS.CODOBIECT
         AND A.CODARTICOL = O.CODARTICOL
         AND NVL(A.CASADEMARCAT, 0) = 1
       )
       WHERE
             NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aData_START, &apos;DD.MM.YYYY hh24:mi&apos;)
         AND NVL(DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END, &apos;DD.MM.YYYY hh24:mi&apos;)
    GROUP BY CODOBIECT, TIPLIVR
     )
  LOOP
    IF V_REC.TIPLIVR = 14 THEN
     UPDATE
       TMP_BALANTA_STOC
     SET
      DIMINUATE = NVL(DIMINUATE, 0) + V_REC.CANT
     WHERE
      CODOBIECT = V_REC.CODOBIECT;
    ELSE
    IF V_REC.TIPLIVR IN (12, 13, 23) THEN
     UPDATE
       TMP_BALANTA_STOC
     SET
      TRANSFERATE = NVL(TRANSFERATE, 0) + V_REC.CANT
     WHERE
      CODOBIECT = V_REC.CODOBIECT;
    ELSE
      IF V_REC.TIPLIVR IN (16, 19, 20) THEN
       UPDATE
         TMP_BALANTA_STOC
       SET
        VANDUTE = NVL(VANDUTE, 0) + V_REC.CANT
       WHERE
        CODOBIECT = V_REC.CODOBIECT;
    ELSE
      IF V_REC.TIPLIVR IN (24) THEN
        UPDATE
          TMP_BALANTA_STOC
        SET
          CONSUMATE = NVL(CONSUMATE, 0) + V_REC.CANT
        WHERE
          CODOBIECT = V_REC.CODOBIECT;
      END IF;
    END IF;
    END IF;
    END IF;

  END LOOP;

  FOR V_REC IN
 (
  SELECT
    NS.CODOBIECT,
    NS.CANTNIR CANT
   FROM
     NIRSTOC NS,
     NIR N,
     NARTOBJ O,
     NART A,
     IOART1 IO1
  WHERE
     NS.CODNIR        = N.CODNIR
     AND N.GEST       = aGEST
     AND O.CODOBIECT  = NS.CODOBIECT
     AND O.CODARTICOL = A.CODARTICOL
     AND NVL(A.CASADEMARCAT, 1) = 1
     AND IO1.CODIOART = NS.CODIOART
     AND IO1.MG &lt;&gt; 5
     AND NVL(N.DATANIR, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aData_START, &apos;DD.MM.YYYY hh24:mi&apos;)
     AND NVL(N.DATANIR, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END, &apos;DD.MM.YYYY hh24:mi&apos;)
     AND N.TIPNIR in (12,13)
     AND EXTRACT(YEAR FROM N.DATANIR)*12+EXTRACT(MONTH FROM N.DATANIR) BETWEEN IO1.ALSTART AND IO1.ALSTOP
  ) loop
    MERGE INTO TMP_BALANTA_STOC SD
    USING (select v_rec.codobiect codobiect, v_rec.cant cant from dual) N
    ON (N.CODOBIECT = SD.CODOBIECT)
    WHEN NOT MATCHED THEN INSERT (CODOBIECT, TRANSFERATE) VALUES (N.CODOBIECT, - N.CANT)
    WHEN     MATCHED THEN UPDATE SET SD.TRANSFERATE = COALESCE(SD.TRANSFERATE,0) - N.CANT;
  end loop;

 COMMIT;
END;

PROCEDURE SCADENEPRELUATE(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2) IS
  dData_Start DATE := TO_DATE(aData_Start, &apos;DD.MM.YYYY hh24:mi&apos;);
  dData_End   DATE := TO_DATE(aData_End,   &apos;DD.MM.YYYY hh24:mi&apos;);
  vAn   NUMERIC(4) := EXTRACT(YEAR  FROM dData_End);
  vLuna NUMERIC(2) := EXTRACT(MONTH FROM dData_End);
  vArtServValoric VARCHAR2(10000) := Coalesce(pkg_categconst.GetValConstanta(&apos;ArtServValoric&apos;,  vAn, vLuna),&apos;-1&apos;);
BEGIN
  DELETE FROM tmp_manevra3;
  IF vArtServValoric &lt;&gt; &apos;-1&apos; THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra3(CODUNIC) SELECT DISTINCT CodObiect FROM NARTOBJ WHERE CodObiect IN (&apos;||vArtServValoric||&apos;)&apos;;
  END IF;

  DELETE FROM TMP_LIVR_LA_DATA;
  -- SCAD DIN STOC INITIAL VANZARI NEPRELUATE ANTERIOARE DATAEI

  INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM EMULARE E
    INNER JOIN RESTNP       NP ON NP.CODRESTNP  = E.CODRESTNP
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    INNER JOIN NARTOBJ      O  ON O.CODOBIECT   = C1.CODOBIECT
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(E.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; dData_Start
    AND Coalesce(E.PRELUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_LA_DATA N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, -N.CANTNIR, 0, 0)
  WHEN     MATCHED THEN UPDATE SET SD.STOCINITIAL = NVL(SD.STOCINITIAL, 0) -  N.CANTNIR;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM EMULARE E
    INNER JOIN RESTNP       NP ON NP.CODRESTNP  = E.CODRESTNP
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    INNER JOIN NARTOBJ      O  ON O.CODOBIECT   = C1.CODOBIECT
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(E.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;=  dData_Start
    AND Coalesce(E.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= dData_End
    AND Coalesce(E.PRELUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD USING TMP_LIVR_IN_INTERVALUL N ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI, VANDUTE) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = Coalesce(SD.IESIRI, 0) + N.CANTNIR, SD.VANDUTE = Coalesce(SD.VANDUTE, 0) + N.CANTNIR;

  COMMIT;
END;

PROCEDURE SCADEPROTOCOL(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2) IS
  dData_Start DATE := TO_DATE(aData_Start, &apos;DD.MM.YYYY hh24:mi&apos;);
  dData_End   DATE := TO_DATE(aData_End,   &apos;DD.MM.YYYY hh24:mi&apos;);
  vAn   NUMERIC(4) := EXTRACT(YEAR  FROM dData_End);
  vLuna NUMERIC(2) := EXTRACT(MONTH FROM dData_End);
  vArtServValoric VARCHAR2(10000) := Coalesce(pkg_categconst.GetValConstanta(&apos;ArtServValoric&apos;,  vAn, vLuna),&apos;-1&apos;);
BEGIN
  DELETE FROM tmp_manevra3;
  IF vArtServValoric &lt;&gt; &apos;-1&apos; THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO tmp_manevra3(CODUNIC) SELECT DISTINCT CodObiect FROM NARTOBJ WHERE CodObiect IN (&apos;||vArtServValoric||&apos;)&apos;;
  END IF;

  DELETE FROM TMP_LIVR_LA_DATA;
  -- SCAD DIN STOC INITIAL VANZARI NEPRELUATE ANTERIOARE DATAEI

  INSERT INTO TMP_LIVR_LA_DATA(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM RESTNP NP
    INNER JOIN RESTCMD      C  ON C.CODRESTCMD  = NP.CODRESTCMD
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt; dData_Start
    AND Coalesce(NP.PROTOCOL, 0) = 1
    AND Coalesce(C.DIMINUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_LA_DATA N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI) VALUES (N.CODOBIECT, -N.CANTNIR, 0, 0)
  WHEN     MATCHED THEN UPDATE SET SD.STOCINITIAL = NVL(SD.STOCINITIAL, 0) -  N.CANTNIR;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM RESTNP NP
    INNER JOIN RESTCMD      C  ON C.CODRESTCMD  = NP.CODRESTCMD
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;=  dData_Start
    AND Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= dData_End
    AND Coalesce(NP.PROTOCOL, 0) = 1
    AND Coalesce(C.DIMINUAT, 0) = 0
    AND C1.CODGEST = aGEST
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD USING TMP_LIVR_IN_INTERVALUL N ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI, VANDUTE) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI  = Coalesce(SD.IESIRI, 0) + N.CANTNIR, SD.VANDUTE = Coalesce(SD.VANDUTE, 0) + N.CANTNIR;

  DELETE FROM TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT C1.CODOBIECT, SUM(CASE WHEN T.CODUNIC IS NULL THEN C1.CANT ELSE C1.CANT * C1.PRET END)
  FROM RESTNP NP
    INNER JOIN RESTCMD      C  ON C.CODRESTCMD  = NP.CODRESTCMD
    INNER JOIN RESTCMD1     C1 ON C1.CODRESTCMD = NP.CODRESTCMD
    LEFT  JOIN TMP_MANEVRA3 T  ON T.CODUNIC     = C1.CODOBIECT
  WHERE Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= dData_Start
    AND Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END,  &apos;DD.MM.YYYY hh24:mi&apos;)
    AND Coalesce(NP.PROTOCOL, 0) = 0
    AND Coalesce(C.DIMINUAT, 0) = 0
    AND C1.CODGEST = aGEST
    AND NP.FACTURARE = 1
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD USING TMP_LIVR_IN_INTERVALUL N ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN NOT MATCHED THEN INSERT (CODOBIECT, STOCINITIAL, INTRARI, IESIRI, VANDUTE) VALUES (N.CODOBIECT, 0, 0, N.CANTNIR, N.CANTNIR)
  WHEN     MATCHED THEN UPDATE SET SD.IESIRI = Coalesce(SD.IESIRI, 0) + N.CANTNIR, SD.VANDUTE = Coalesce(SD.VANDUTE, 0) +  N.CANTNIR;

  COMMIT;
END;

PROCEDURE CALCUALEAZADISCOUNT(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
BEGIN
  DELETE TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT NP1.CODOBIECT, SUM(NP1.CANT*NP1.PRET*NP1.DISCOUNT/100)
  FROM RESTNP NP
    INNER JOIN RESTNP1           NP1 ON NP1.CODRESTNP = NP.CODRESTNP
    INNER JOIN RESTCMD           C   ON C.CODRESTCMD = NP.CODRESTCMD
    LEFT  JOIN MESE              M   ON M.CODMASA = C.CODMASA
    LEFT  JOIN SALI              S   ON S.CODSALA = M.CODSALA
    LEFT  JOIN RESTGESTIMPLICITE RG  ON RG.CODRESTAURANT = S.CODRESTAURANT
  WHERE NP1.CODOBIECT = RG.CODOBIECT
    AND Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aData_Start, &apos;DD.MM.YYYY hh24:mi&apos;)
    AND Coalesce(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END,  &apos;DD.MM.YYYY hh24:mi&apos;)
    AND Coalesce(NP.PROTOCOL, 0) = 0
    AND RG.GESTIMPLICITA = aGEST
  GROUP BY NP1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD USING TMP_LIVR_IN_INTERVALUL N ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN MATCHED THEN UPDATE SET SD.DISCOUNT = Coalesce(SD.DISCOUNT, 0) + N.CANTNIR;

  COMMIT;
END;
/*
PROCEDURE NEPRELUATE(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
BEGIN
    DELETE TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT
     C1.CODOBIECT,
     SUM(C1.CANT) AS CANT
  FROM
    EMULARE E,
    RESTNP NP,
    RESTCMD1 C1,
    RESTCMD C,
    NARTOBJ O
  WHERE
    C.CODRESTCMD = C1.CODRESTCMD
    AND NVL(E.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt; TO_DATE(aData_Start, &apos;DD.MM.YYYY hh24:mi&apos;)
    AND NVL(E.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END,  &apos;DD.MM.YYYY hh24:mi&apos;)
    AND (
         (NVL(E.PRELUAT, 0) = 0) OR
         ((NVL(NP.protocol, 0) + NVL(NP.facturare, 0)  &gt;0 ) and nvl(C.diminuat,0)= 0)
        )
    AND NP.CODRESTNP = E.CODRESTNP
    AND C1.CODRESTCMD = NP.CODRESTCMD
    AND C1.CODGEST = aGEST
    AND O.CODOBIECT = C1.CODOBIECT
    --AND (NP.protocol &gt; 0 or NP.facturare &gt;0 ) and nvl(C.diminuat,0) &lt;&gt; 1
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN MATCHED THEN UPDATE SET SD.NEPRELUATE  = NVL(SD.NEPRELUATE, 0)  +  N.CANTNIR;

  COMMIT;
END;
*/
PROCEDURE NEPRELUATE(aGEST IN NUMBER, aDATA_START IN VARCHAR2, aDATA_END IN VARCHAR2)
IS
BEGIN
    DELETE TMP_LIVR_IN_INTERVALUL;
  -- ACTUALIZE VANZARI NEPRELUATE IN INTERVALUL ANALIZAT

  INSERT INTO TMP_LIVR_IN_INTERVALUL(CODOBIECT, CANTNIR)
  SELECT
     C1.CODOBIECT,
     SUM(C1.CANT) AS CANT
  FROM
    RESTNP NP
    LEFT JOIN EMULARE E ON E.CODRESTNP = NP.CODRESTNP,
    RESTCMD1 C1,
    RESTCMD C,
    NARTOBJ O
  WHERE
    C.CODRESTCMD = C1.CODRESTCMD
    AND NVL(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &gt;= TO_DATE(aData_Start, &apos;DD.MM.YYYY hh24:mi&apos;)
    AND NVL(NP.DATACREARE, TO_DATE(&apos;01.01.2000&apos;, &apos;DD.MM.YYYY&apos;)) &lt;= TO_DATE(aData_END,  &apos;DD.MM.YYYY hh24:mi&apos;)
    AND (

         (NVL(E.PRELUAT, 0) + NVL(NP.protocol, 0) + NVL(NP.facturare, 0) = 0 ) OR
         ((NVL(NP.protocol, 0) + NVL(NP.facturare, 0)  &gt;0 ) and nvl(C.diminuat,0)= 0)
        )
    AND C1.CODRESTCMD = NP.CODRESTCMD
    AND C1.CODGEST = aGEST
    AND O.CODOBIECT = C1.CODOBIECT
  GROUP BY C1.CODOBIECT;

  MERGE INTO TMP_BALANTA_STOC SD
  USING TMP_LIVR_IN_INTERVALUL N
  ON (N.CODOBIECT = SD.CODOBIECT)
  WHEN MATCHED THEN UPDATE SET SD.NEPRELUATE  = NVL(SD.NEPRELUATE, 0)  +  N.CANTNIR;

  COMMIT;
END;

PROCEDURE GET_COMANDA(aCODCOMANDA IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTCMD;
  DELETE TMP_RESTCMD1;
  DELETE TMP_RESTCMD1_INITIAL;

  INSERT INTO TMP_RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, NUMEPERS)
  SELECT CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA,  R.OBS, NRPERS, P.NUME || &apos; &apos; || P.PRENUME
  FROM
    RESTCMD R
    LEFT OUTER JOIN OSPATARI O ON O.COD  = R.CODOSPATAR
    LEFT OUTER JOIN NPERS P ON P.CODPERS = O.CODPERS
  WHERE
    CODRESTCMD = ACODCOMANDA;--  AND NVL(INCHISA, 0) = 1 ORDER BY CODRESTCMD;

  INSERT INTO TMP_RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, DENUMIRE, DUM, VALOARE, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
  SELECT
    R1.CODRESTCMD1,
    R1.CODRESTCMD,
    R1.INDEXLOCAL,
    R1.CODOBIECT,
    R1.UMSEC,
    R1.PRET,
    R1.CANT,
    R1.OBS,
    O.DENUMIRE,
    U1.DEN_UM1,
    R1.CANT * R1.PRET,
    R1.CODGEST,
    R1.LISTAREGEST,
    R1.FARALISTARE,
    R1.TIPUM,
    R1.CANTARIT,
    COALESCE(R1.PROCTVA, PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU)
    ),
    R1.ORDINE,
    R1.TAXA
  FROM
    RESTCMD1 R1,
    NARTOBJ O,
    NART A,
    NUM1 U1
  WHERE
    EXISTS (SELECT R.CODRESTCMD FROM TMP_RESTCMD R WHERE R.CODRESTCMD = R1.CODRESTCMD)
    AND O.CODOBIECT = R1.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND U1.CODUM1 = R1.UMSEC;

 INSERT INTO TMP_RESTCMD1_INITIAL(CODRESTCMD1) SELECT CODRESTCMD1 FROM TMP_RESTCMD1;


  UPDATE  TMP_RESTCMD
  SET
    NEWRECORD = 0;

  UPDATE  TMP_RESTCMD1
  SET
    NEWRECORD = 0;
 COMMIT;
END;



PROCEDURE GET_COMENZI_MASA(aCODMASA IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTCMD;
  DELETE TMP_RESTCMD1;
  DELETE TMP_RESTCMD1_INITIAL;

  INSERT INTO TMP_RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, NUMEPERS, ADRESALIVRARE)
  SELECT CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA,  R.OBS, NRPERS, P.NUME || &apos; &apos; || P.PRENUME, ADRESALIVRARE
  FROM
    RESTCMD R
    LEFT OUTER JOIN OSPATARI O ON O.COD  = R.CODOSPATAR
    LEFT OUTER JOIN NPERS P ON P.CODPERS = O.CODPERS
  WHERE
    CODMASA = ACODMASA  AND NVL(INCHISA, 0) = 0  ORDER BY CODRESTCMD;

  INSERT INTO TMP_RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, DENUMIRE, DUM, VALOARE, CODGEST, LISTAREGEST, FARALISTARE, PARITATE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
  SELECT
    R1.CODRESTCMD1,
    R1.CODRESTCMD,
    R1.INDEXLOCAL,
    R1.CODOBIECT,
    R1.UMSEC,
    R1.PRET * NVL(U1.PARITATE, 1),
    R1.CANT / NVL(U1.PARITATE, 1),
    R1.OBS,
    O.DENUMIRE,
    U1.DEN_UM1,
    R1.CANT * R1.PRET,
    R1.CODGEST,
    R1.LISTAREGEST,
    R1.FARALISTARE,
    U1.PARITATE,
    R1.TIPUM,
    R1.CANTARIT,
    COALESCE(R1.PROCTVA, PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU)),
    R1.ORDINE,
    R1.TAXA
  FROM
    RESTCMD1 R1,
    NARTOBJ O,
    NART A,
    NUM1 U1
  WHERE
    EXISTS (SELECT R.CODRESTCMD FROM TMP_RESTCMD R WHERE R.CODRESTCMD = R1.CODRESTCMD)
    AND O.CODOBIECT = R1.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND U1.CODUM1 = R1.UMSEC;

 INSERT INTO TMP_RESTCMD1_INITIAL(CODRESTCMD1) SELECT CODRESTCMD1 FROM TMP_RESTCMD1;


  UPDATE  TMP_RESTCMD
  SET
    NEWRECORD = 0;

  UPDATE  TMP_RESTCMD1
  SET
    NEWRECORD = 0;
 COMMIT;
END;

PROCEDURE POST_COMANDA
IS
BEGIN
  UPDATE TMP_RESTCMD C
  SET
   VALOARE = (SELECT SUM(PRET*CANT) FROM TMP_RESTCMD1 C1 WHERE C1.CODRESTCMD = C.CODRESTCMD);

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD
      SET
        NRCOMANDA  = V_REC.NRCOMANDA,
        CODMASA    = V_REC.CODMASA,
        CODOSPATAR = V_REC.CODOSPATAR,
        VALOARE    = V_REC.VALOARE,
        DESCHIDERE = V_REC.DESCHIDERE,
        INCHIDERE  = V_REC.INCHIDERE,
        INCHISA    = V_REC.INCHISA,
        OBS        = V_REC.OBS,
        NRPERS     = V_REC.NRPERS,
        ADRESALIVRARE = V_REC.ADRESALIVRARE
      WHERE
        CODRESTCMD = V_REC.CODRESTCMD;
    ELSE
      INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS, ADRESALIVRARE)
      VALUES (V_REC.CODRESTCMD, V_REC.NRCOMANDA, V_REC.CODMASA, V_REC.CODOSPATAR, V_REC.VALOARE, V_REC.DESCHIDERE, V_REC.INCHIDERE, V_REC.INCHISA, V_REC.OBS, V_REC.NRPERS, V_REC.ADRESALIVRARE);
    END IF;
  END LOOP;


 DELETE FROM RESTCMD1 R1 WHERE CODRESTCMD = (SELECT CODRESTCMD FROM TMP_RESTCMD);

 FOR V_REC IN (SELECT * FROM TMP_RESTCMD1)
  LOOP
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
    VALUES (V_REC.CODRESTCMD1, V_REC.CODRESTCMD, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANT, V_REC.OBS, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT, V_REC.PROCTVA, V_REC.ORDINE, V_REC.TAXA);
  END LOOP;


 FOR V_REC IN (SELECT * FROM TMP_RESTCMD)
 LOOP
   UPDATE RESTCMD
   SET
     VALOARE = (SELECT SUM(CANT * PRET) FROM RESTCMD1 WHERE CODRESTCMD = V_REC.CODRESTCMD)
   WHERE
     CODRESTCMD = V_REC.CODRESTCMD;
 END LOOP;

 COMMIT;


END;

PROCEDURE POST_COMENZI_MASA(ACODMASA IN NUMBER)
IS
BEGIN
--  INSERT INTO XNR SELECT COUNT(*) FROM TMP_RESTCMD1;
  FOR V_REC IN
  (
  SELECT * FROM RESTCMD R
  WHERE
    CODMASA = ACODMASA  AND NVL(INCHISA, 0) = 0
  AND NOT EXISTS(SELECT CODRESTCMD FROM TMP_RESTCMD RT WHERE RT.CODRESTCMD = R.CODRESTCMD)
  )
  LOOP
    DELETE FROM NRCMDRESTLOCK
    WHERE
      USERID = PKG_GLOBALS.USERID
      AND CODMASA = V_REC.CODMASA
      AND USEDNR = V_REC.NRCOMANDA;

    DELETE FROM RESTCMD WHERE CODRESTCMD = V_REC.CODRESTCMD;
  END LOOP;



  /*
  DELETE FROM RESTCMD R
  WHERE
    CODMASA = ACODMASA  AND NVL(INCHISA, 0) = 0
  AND NOT EXISTS(SELECT CODRESTCMD FROM TMP_RESTCMD RT WHERE RT.CODRESTCMD = R.CODRESTCMD);
 */

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD
      SET
        NRCOMANDA  = V_REC.NRCOMANDA,
        CODMASA    = V_REC.CODMASA,
        CODOSPATAR = V_REC.CODOSPATAR,
        VALOARE    = V_REC.VALOARE,
        DESCHIDERE = V_REC.DESCHIDERE,
        INCHIDERE  = V_REC.INCHIDERE,
        INCHISA    = V_REC.INCHISA,
        OBS        = V_REC.OBS,
        NRPERS     = V_REC.NRPERS
      WHERE
        CODRESTCMD = V_REC.CODRESTCMD;
    ELSE
      INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, VALOARE, DESCHIDERE, INCHIDERE, INCHISA, OBS, NRPERS)
      VALUES (V_REC.CODRESTCMD, V_REC.NRCOMANDA, V_REC.CODMASA, V_REC.CODOSPATAR, V_REC.VALOARE, V_REC.DESCHIDERE, V_REC.INCHIDERE, V_REC.INCHISA, V_REC.OBS, V_REC.NRPERS);
    END IF;
  END LOOP;


 DELETE FROM RESTCMD1 R1
 WHERE
  EXISTS (SELECT CODRESTCMD1 FROM TMP_RESTCMD1_INITIAL RI WHERE RI.CODRESTCMD1 = R1.CODRESTCMD1) AND
  NOT EXISTS (SELECT CODRESTCMD1 FROM TMP_RESTCMD1 TR1 WHERE TR1.CODRESTCMD1 = R1.CODRESTCMD1);

  FOR V_REC IN (SELECT * FROM TMP_RESTCMD1)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCMD1
      SET
        CODRESTCMD  = V_REC.CODRESTCMD,
        INDEXLOCAL  = V_REC.INDEXLOCAL,
        CODOBIECT   = V_REC.CODOBIECT,
        UMSEC       = V_REC.UMSEC,
        PRET        = V_REC.PRET / NVL(V_REC.PARITATE, 1) ,
        CANT        = V_REC.CANT * NVL(V_REC.PARITATE, 1),
        OBS         = V_REC.OBS,
        CODGEST     = V_REC.CODGEST,
        LISTAREGEST = V_REC.LISTAREGEST,
        FARALISTARE = V_REC.FARALISTARE,
        TIPUM       = V_REC.TIPUM,
        CANTARIT    = V_REC.CANTARIT,
        PROCTVA     = V_REC.PROCTVA,
        ORDINE      = V_REC.ORDINE,
        TAXA        = V_REC.TAXA
      WHERE
        CODRESTCMD1 = V_REC.CODRESTCMD1;
    ELSE
      INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, OBS, CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT, PROCTVA, ORDINE, TAXA)
      VALUES (V_REC.CODRESTCMD1, V_REC.CODRESTCMD, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET /  NVL(V_REC.PARITATE, 1), V_REC.CANT *  NVL(V_REC.PARITATE, 1), V_REC.OBS, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT, V_REC.PROCTVA, V_REC.ORDINE, V_REC.TAXA);
    END IF;
  END LOOP;


  FOR V_REC IN --pe firedac APPLYUPDATEs la rtDeleted da uneori gres;  am recurs la solutia asta
  (
  SELECT * FROM RESTCMD R
  WHERE
    CODMASA = ACODMASA  AND NVL(INCHISA, 0) = 0
  AND (SELECT COUNT(*) FROM RESTCMD1 C1 WHERE C1.CODRESTCMD = R.CODRESTCMD) = 0
  )
  LOOP
    DELETE FROM NRCMDRESTLOCK
    WHERE
      USERID = PKG_GLOBALS.USERID
      AND CODMASA = V_REC.CODMASA
      AND USEDNR = V_REC.NRCOMANDA;

    DELETE FROM RESTCMD WHERE CODRESTCMD = V_REC.CODRESTCMD;
  END LOOP;



 COMMIT;
END;

FUNCTION CANLOCKNRCMD(aCODMASA IN NUMBER, aDATA IN VARCHAR2, aNRCMD IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF aCODMASA &gt; 0 THEN
    SELECT COUNT(*) INTO NR FROM NRCMDRESTLOCK
    WHERE
      CODMASA    = aCODMASA
      AND DATA   = TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;)
      AND USEDNR = TO_NUMBER(aNRCMD);
  ELSE
    SELECT COUNT(*) INTO NR FROM NRCMDRESTLOCK
    WHERE
      DATA   = TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;)
      AND USEDNR = TO_NUMBER(aNRCMD);
  END IF;

  IF NR &gt; 0 THEN RETURN 0;
  ELSE
    INSERT INTO NRCMDRESTLOCK(CODMASA, DATA, USERID, USEDNR)
    VALUES (aCODMASA, TO_DATE(aDATA, &apos;DD.MM.YYYY&apos;), PKG_GLOBALS.USERID, aNRCMD);
    COMMIT;
    RETURN 1;
  END IF;
END;

PROCEDURE RELEASELOCKNRCMD
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM NRCMDRESTLOCK
  WHERE
    USERID =  PKG_GLOBALS.USERID;
  COMMIT;
END;


PROCEDURE GET_GEST_VER_LIST
IS
BEGIN
  DELETE TMP_RESTGESTLISTVER;

  INSERT INTO TMP_RESTGESTLISTVER(COD, CODGEST, LISTVER, FARALISTARE, DENGEST, DENVER, NEWRECORD)
  SELECT
    R.COD,
    R.CODGEST,
    R.LISTVER,
    R.FARALISTARE,
    G.DEN_GEST,
    L.NAME,
    0
  FROM
    RESTGESTLISTVER R
    LEFT OUTER JOIN WINMADMIN.LISTS L ON L.LISTVER = R.LISTVER AND L.LISTID = 279,
    NGEST G
  WHERE
    G.CODGEST = R.CODGEST;

 COMMIT;
END;


PROCEDURE POST_GEST_VER_LIST
IS
BEGIN
  DELETE FROM RESTGESTLISTVER R
  WHERE
  NOT EXISTS(SELECT COD FROM TMP_RESTGESTLISTVER RT WHERE RT.COD = R.COD);


  FOR V_REC IN (SELECT * FROM TMP_RESTGESTLISTVER)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTGESTLISTVER
      SET
        CODGEST     = V_REC.CODGEST,
        LISTVER     = V_REC.LISTVER,
        FARALISTARE = V_REC.FARALISTARE
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO RESTGESTLISTVER(COD, CODGEST, LISTVER, FARALISTARE)
      VALUES (
      V_REC.COD,
      V_REC.CODGEST,
      V_REC.LISTVER,
      V_REC.FARALISTARE);
    END IF;
  END LOOP;

  COMMIT;
END;




PROCEDURE GET_OSPATARI(aCODRESTAURANT IN NUMBER)
IS
BEGIN
  DELETE TMP_OSPATARI;

  INSERT INTO TMP_OSPATARI(COD, CODPERS, PAROLA, CODRESTAURANT, SUPERVIZOR, VERLISTNP, NUMEPERS, NEWRECORD, DENVERLISTNP)
  SELECT
    O.COD,
    O.CODPERS,
    O.PAROLA,
    O.CODRESTAURANT,
    NVL(O.SUPERVIZOR, 0),
    O.VERLISTNP,
    P.NUME || &apos; &apos; || P.PRENUME,
    0,
    SUBSTR(L.NAME, 1, 50)
  FROM
    OSPATARI O
    LEFT JOIN WINMADMIN.LISTS L ON L.LISTID =282 AND L.LISTVER = O.VERLISTNP,
    NPERS P
  WHERE
    P.CODPERS = O.CODPERS
    AND CODRESTAURANT = aCODRESTAURANT;

 DELETE TMP_OSPATARI_INI;
 INSERT INTO TMP_OSPATARI_INI (COD) SELECT COD FROM TMP_OSPATARI;
 COMMIT;
END;


PROCEDURE POST_OSPATARI
IS
BEGIN
  DELETE FROM OSPATARI O
  WHERE
    EXISTS(SELECT COD FROM TMP_OSPATARI_INI OI WHERE OI.COD = O.COD)
    AND NOT EXISTS(SELECT COD FROM TMP_OSPATARI OT WHERE OT.COD = O.COD);


  FOR V_REC IN (SELECT * FROM TMP_OSPATARI)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE OSPATARI
      SET
        CODPERS        = V_REC.CODPERS,
        PAROLA         = V_REC.PAROLA,
        CODRESTAURANT  = V_REC.CODRESTAURANT,
        SUPERVIZOR     = V_REC.SUPERVIZOR,
        VERLISTNP      = V_REC.VERLISTNP
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO OSPATARI(COD, CODPERS, PAROLA, CODRESTAURANT, SUPERVIZOR, VERLISTNP)
      VALUES (V_REC.COD, V_REC.CODPERS, V_REC.PAROLA, V_REC.CODRESTAURANT, V_REC.SUPERVIZOR, V_REC.VERLISTNP);
    END IF;
  END LOOP;

  COMMIT;
END;



PROCEDURE GET_RESTCLASE(aCODRESTAURANT IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTCLASE;
  DELETE TMP_RESTARTINACTIVE;

  INSERT INTO TMP_RESTCLASE(COD, CODCLASEA, CODRESTAURANT, NEWRECORD)
  SELECT
    COD,
    CODCLASEA,
    CODRESTAURANT,
    0
  FROM
   RESTCLASE
  WHERE
    CODRESTAURANT = aCODRESTAURANT   ;

 DELETE TMP_RESTCLASE_INI;

 INSERT INTO TMP_RESTCLASE_INI (COD) SELECT COD FROM TMP_RESTCLASE;

 INSERT INTO TMP_RESTARTINACTIVE(CODRESTAURANT, CODOBIECT, CODCLASA, DENUMIRE, INACTIV)
 SELECT
   CODRESTAURANT,
   O.CODOBIECT,
   A.CLASA,
   O.DENUMIRE,
   1
 FROM
   RESTARTINACTIVE R,
   NARTOBJ O,
   NART A
 WHERE
   CODRESTAURANT = aCODRESTAURANT
   AND O.CODOBIECT = R.CODOBIECT
   AND A.CODARTICOL = O.CODARTICOL;



 INSERT INTO TMP_RESTARTINACTIVE(CODRESTAURANT, CODOBIECT, CODCLASA, DENUMIRE, INACTIV)
 SELECT
   aCODRESTAURANT,
   O.CODOBIECT,
   A.CLASA,
   O.DENUMIRE,
   0
 FROM
   NARTOBJ O,
   NART A
 WHERE
   A.CODARTICOL = O.CODARTICOL
   AND A.CASADEMARCAT = 1
   AND NOT EXISTS (SELECT CODOBIECT FROM RESTARTINACTIVE R WHERE R.CODRESTAURANT =aCODRESTAURANT AND R.CODOBIECT = O.CODOBIECT);


 COMMIT;
END;


PROCEDURE POST_RESTCLASE(aCODRESTAURANT IN NUMBER)
IS
aCODOBIECT NUMBER(20) := 0;
BEGIN
  DELETE FROM RESTCLASE O
  WHERE
   EXISTS(SELECT COD FROM TMP_RESTCLASE_INI OI WHERE OI.COD = O.COD)
   AND NOT EXISTS(SELECT COD FROM TMP_RESTCLASE OT WHERE OT.COD = O.COD);


  FOR V_REC IN (SELECT * FROM TMP_RESTCLASE)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTCLASE
      SET
       CODCLASEA = V_REC.CODCLASEA
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO RESTCLASE(COD, CODCLASEA, CODRESTAURANT)
      VALUES (V_REC.COD, V_REC.CODCLASEA, V_REC.CODRESTAURANT);
    END IF;
  END LOOP;

  DELETE FROM RESTARTINACTIVE RAI
  WHERE
    CODRESTAURANT = aCODRESTAURANT
    AND NOT EXISTS (SELECT CODOBIECT FROM TMP_RESTARTINACTIVE TRAI WHERE NVL(INACTIV, 0) = 1 AND TRAI.CODOBIECT = RAI.CODOBIECT);

  FOR V_REC IN (SELECT * FROM TMP_RESTARTINACTIVE WHERE NVL(INACTIV, 0) = 1)
  LOOP
    BEGIN
      SELECT COUNT(*) INTO aCODOBIECT FROM RESTARTINACTIVE WHERE CODRESTAURANT = aCODRESTAURANT AND CODOBIECT = V_REC.CODOBIECT;
      EXCEPTION WHEN OTHERS THEN aCODOBIECT := 0;
    END;

    IF aCODOBIECT = 0 THEN
      INSERT INTO RESTARTINACTIVE(COD, CODRESTAURANT, CODOBIECT)
      VALUES (SEQ_RESTARTINACTIVE_COD.NEXTVAL, aCODRESTAURANT, V_REC.CODOBIECT);
    END IF;
  END LOOP;

  COMMIT;
END;


PROCEDURE GET_NOTAPLATA(aCODRESTCMD IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTNP;
  DELETE TMP_RESTNP1;
  DELETE TMP_RESTNP1_INITIAL;

  DELETE TMP_RESTNP2;
  DELETE TMP_RESTNP2_INITIAL;

  INSERT INTO TMP_RESTNP(
  CODRESTNP,
  CODRESTCMD,
  NRDOC,
  DATADOC,
  CARNETDOC,
  CODPART,
  VALOARE,
  VALDISC,
  PROTOCOL,
  LISTATCM,
  TIPCASAMARCAT,
  TEXTNEFISCAL,
  NEWRECORD,
  SALA,
  MASA,
  OSPATAR,
  NRCOMANDA,
  FACTURARE,
  LISTAT,
  ADRESALIVRARE,
  CODPARTRETAIL,
  VALMARTOR_CMD
  )
  SELECT
  N.CODRESTNP,
  N.CODRESTCMD,
  N.NRDOC,
  N.DATADOC,
  N.CARNETDOC,
  N.CODPART,
  N.VALOARE,
  N.VALDISC,
  N.PROTOCOL,
  N.LISTATCM,
  N.TIPCASAMARCAT,
  N.TEXTNEFISCAL,
  0,
  S.DENUMIRE ,
  CASE
   WHEN M.TEXTAFISARE IS NOT NULL THEN TEXTAFISARE
   ELSE TO_CHAR(M.INDEXLOCAL)
  END,
  P.NUME || &apos; &apos; || P.PRENUME,
  R.NRCOMANDA,
  N.FACTURARE,
  N.LISTAT,
  R.ADRESALIVRARE,
  N.CODPARTRETAIL,
  N.VALMARTOR_CMD
  FROM
    RESTNP N,
    RESTCMD R
    LEFT OUTER JOIN OSPATARI O ON O.COD  = R.CODOSPATAR
    LEFT OUTER JOIN NPERS P ON P.CODPERS = O.CODPERS,
    SALI S,
    MESE M
  WHERE
    N.CODRESTCMD = aCODRESTCMD
    AND R.CODRESTCMD = aCODRESTCMD
    AND M.CODMASA = R.CODMASA
    AND S.CODSALA = M.CODSALA;


   DELETE FROM RESTNP1 WHERE CODRESTNP1 = 0;-- buleli firedac

   INSERT INTO TMP_RESTNP1(
    CODRESTNP1,
    CODRESTNP,
    INDEXLOCAL,
    CODOBIECT,
    UMSEC,
    CANT,
    PRET,
    DISCOUNT,
    VALOARE,
    DENUMIRE,
    DUM,
    PROCTVA,
    NEWRECORD,
    PARITATE,
    DISCMANUAL,
    TAXA
   )
  SELECT
    N1.CODRESTNP1,
    N1.CODRESTNP,
    N1.INDEXLOCAL,
    N1.CODOBIECT,
    N1.UMSEC,
    N1.CANT / NVL(U1.PARITATE, 1),
    N1.PRET * NVL(U1.PARITATE, 1),
    N1.DISCOUNT,
    N1.CANT * N1.PRET,
    O.DENUMIRE,
    U1.DEN_UM1,
    COALESCE(N1.PROCTVA, PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL,PKG_GLOBALS.ANLUCRU,PKG_GLOBALS.LUNALUCRU)),
    0,
    U1.PARITATE,
    DISCMANUAL,
    (SELECT MIN(TAXA) FROM RESTCMD1 WHERE CODRESTCMD = aCODRESTCMD AND CODOBIECT = N1.CODOBIECT)
  FROM
    RESTNP1 N1,
    NARTOBJ O,
    NART A,
    NUM1 U1
  WHERE
    EXISTS (SELECT N.CODRESTNP FROM TMP_RESTNP N WHERE N.CODRESTNP = N1.CODRESTNP)
    AND O.CODOBIECT = N1.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND U1.CODUM1 = N1.UMSEC;

   INSERT INTO TMP_RESTNP1_INITIAL(CODRESTNP1) SELECT CODRESTNP1 FROM TMP_RESTNP1;



   INSERT INTO TMP_RESTNP2(
    CODRESTNP2,
    CODRESTNP,
    TIPPLATA,
    VALOARE,
    DENUMIRE,
    NEWRECORD
   )
  SELECT
    N2.CODRESTNP2,
    N2.CODRESTNP,
    N2.TIPPLATA,
    N2.VALOARE,
    N2.DENUMIRE,
    0
  FROM
    RESTNP2 N2
  WHERE
    EXISTS (SELECT N.CODRESTNP FROM TMP_RESTNP N WHERE N.CODRESTNP = N2.CODRESTNP);

   INSERT INTO TMP_RESTNP2_INITIAL(CODRESTNP2) SELECT CODRESTNP2 FROM TMP_RESTNP2;

   COMMIT;
END;


PROCEDURE POST_NOTAPLATA
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_RESTNP)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP
      SET
        NRDOC          = V_REC.NRDOC,
        DATADOC        = V_REC.DATADOC,
        CARNETDOC      = V_REC.CARNETDOC,
        CODPART        = V_REC.CODPART,
        CODPARTRETAIL  = V_REC.CODPARTRETAIL,
        VALOARE        = V_REC.VALOARE,
        VALDISC        = V_REC.VALDISC,
        PROTOCOL       = V_REC.PROTOCOL,
        LISTATCM       = V_REC.LISTATCM,
        TIPCASAMARCAT  = V_REC.TIPCASAMARCAT,
        TEXTNEFISCAL   = V_REC.TEXTNEFISCAL,
        FACTURARE      = V_REC.FACTURARE,
        LISTAT         = V_REC.LISTAT,
        VALMARTOR_CMD  = V_REC.VALMARTOR_CMD
      WHERE
        CODRESTNP   = V_REC.CODRESTNP;
    ELSE
      INSERT INTO RESTNP(  CODRESTNP,
                           CODRESTCMD,
                           NRDOC,
                           DATADOC,
                           CARNETDOC,
                           CODPART,
                           CODPARTRETAIL,
                           VALOARE,
                           VALDISC,
                           PROTOCOL,
                           LISTATCM,
                           DATACREARE,
                           TIPCASAMARCAT,
                           TEXTNEFISCAL,
                           FACTURARE,
                           LISTAT,
                           VALMARTOR_CMD
      )
      VALUES (V_REC.CODRESTNP,
              V_REC.CODRESTCMD,
              V_REC.NRDOC,
              V_REC.DATADOC,
              V_REC.CARNETDOC,
              V_REC.CODPART,
              V_REC.CODPARTRETAIL,
              V_REC.VALOARE,
              V_REC.VALDISC,
              V_REC.PROTOCOL,
              V_REC.LISTATCM,
              SYSDATE,
              V_REC.TIPCASAMARCAT,
              V_REC.TEXTNEFISCAL,
              V_REC.FACTURARE,
              V_REC.LISTAT,
              V_REC.VALMARTOR_CMD);
    END IF;
    PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
  END LOOP;


 DELETE FROM RESTNP1 N1
 WHERE
  EXISTS (SELECT CODRESTNP1 FROM TMP_RESTNP1_INITIAL NI WHERE NI.CODRESTNP1 = N1.CODRESTNP1) AND
  NOT EXISTS (SELECT CODRESTNP1 FROM TMP_RESTNP1 TN1 WHERE TN1.CODRESTNP1 = N1.CODRESTNP1);

  FOR V_REC IN (SELECT * FROM TMP_RESTNP1 WHERE NVL(CODRESTNP1, 0) &gt; 0 )
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP1
      SET
        CODRESTNP   = V_REC.CODRESTNP,
        INDEXLOCAL  = V_REC.INDEXLOCAL,
        CODOBIECT   = V_REC.CODOBIECT,
        UMSEC       = V_REC.UMSEC,
        PRET        = V_REC.PRET / V_REC.PARITATE,
        CANT        = V_REC.CANT * V_REC.PARITATE,
        DISCOUNT    = V_REC.DISCOUNT,
        PROCTVA     = V_REC.PROCTVA,
        DISCMANUAL  = V_REC.DISCMANUAL
      WHERE
        CODRESTNP1 = V_REC.CODRESTNP1;
    ELSE
      INSERT INTO RESTNP1(CODRESTNP1,CODRESTNP, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT, DISCOUNT, PROCTVA, DISCMANUAL)
      VALUES(V_REC.CODRESTNP1,V_REC.CODRESTNP, V_REC.INDEXLOCAL, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET /  V_REC.PARITATE, V_REC.CANT *  V_REC.PARITATE, V_REC.DISCOUNT, V_REC.PROCTVA, V_REC.DISCMANUAL);
    END IF;
  END LOOP;


 DELETE FROM RESTNP2 N2
 WHERE
  EXISTS (SELECT CODRESTNP2 FROM TMP_RESTNP2_INITIAL NI WHERE NI.CODRESTNP2 = N2.CODRESTNP2) AND
  NOT EXISTS (SELECT CODRESTNP2 FROM TMP_RESTNP2 TN2 WHERE TN2.CODRESTNP2 = N2.CODRESTNP2);

  FOR V_REC IN (SELECT * FROM TMP_RESTNP2)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTNP2
      SET
       TIPPLATA = V_REC.TIPPLATA,
       VALOARE  = V_REC.VALOARE,
       DENUMIRE = V_REC.DENUMIRE
      WHERE
        CODRESTNP2 = V_REC.CODRESTNP2;
    ELSE
      INSERT INTO RESTNP2(CODRESTNP2, CODRESTNP, TIPPLATA, VALOARE, DENUMIRE)
      VALUES(V_REC.CODRESTNP2, V_REC.CODRESTNP, V_REC.TIPPLATA, V_REC.VALOARE, V_REC.DENUMIRE);
    END IF;
  END LOOP;




 COMMIT;
END;

PROCEDURE POST_BONEMULARE
IS
aCODEMULARE NUMBER(20);
BEGIN
    SELECT seq_emulare_codemulare.NextVal INTO aCODEMULARE FROM DUAL;
    INSERT INTO  EMULARE ( CodEmulare, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, USERID, DATACREARE, DATALISTARE, CODPART, CODPERS,  CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CODAGENT, OBS, CODRESTNP )
   ( SELECT  aCODEMULARE, NrBon, DataBon, Valoare, ValoareDiscount, Listat, Preluat, CodCasaMarcat, TVATOTAL, TVADISCOUNT, TIPCASAMARCAT, PKG_GLOBALS.USERID, SYSTIMESTAMP, DATALISTARE, CODPART, CODPERS,  CODIES, INCASARECLIENT, CODPOSTRETAIL, CODAECUSTODIE, CODLOCATIE, CODAGENT, OBS, CODRESTNP
       FROM TMP_EMULARE  ) ;


    INSERT INTO EMULARE1
    ( CodEmulare1,
      CodEmulare,
      CodObiect,
      INDEXLOCAL,
      PretArt,
      Pret,
      Cant  ,
      UmSec,
      Discount,
      TIPLINIE,
      TVA,
      CODGEST,
      CODIOART,
      PRETNIRSTOC,
      CONTSERV,
      FARASTOC,
      CODCOMANDA1,
      TIPLIVRARE,
      CADOU,
      PRETPROMO,
      CODGESTORIG,
      CODEMULSTINGERE
 )
      SELECT
       SEQ_EMULARE1_CODEMULARE1.Nextval ,
       aCODEMULARE ,
       CodObiect,
       INDEXLOCAL,
       PretArt / PARITATE ,
       Pret / PARITATE,
       Cant * PARITATE ,
       UmSec,
       Discount,
       TIPLINIE,
       TVA,
       CODGEST,
       CODIOART,
       PRETNIRSTOC,
       CONTSERV,
       FARASTOC,
       CODCOMANDA1,
       TIPLIVRARE,
       CADOU,
       PRETPROMO,
       CODGESTORIG,
       CODEMULSTINGERE
      FROM
       TMP_EMULARE1;

    INSERT INTO EMULARE2 ( CodEmulare2, CodEmulare, TipPlata, Valoare, Denumire )
    SELECT  SEQ_EMULARE2_CODEMULARE2.Nextval, aCODEMULARE, TipPlata, Valoare, Denumire
    FROM
      TMP_EMULARE2 ;

  COMMIT;

END;



PROCEDURE GET_GESTIMPLICITE(aCODRESTAURANT IN NUMBER)
IS
BEGIN
  DELETE TMP_RESTGESTIMPLICITE;

  INSERT INTO TMP_RESTGESTIMPLICITE(COD, CODRESTAURANT, CODOBIECT, GESTIMPLICITA, NEWRECORD, DENOBIECT, DENGEST, CODCLASA)
  SELECT
    R.COD,
    R.CODRESTAURANT,
    R.CODOBIECT,
    R.GESTIMPLICITA,
    0,
    O.DENUMIRE,
    G.DEN_GEST,
    A.CLASA
  FROM
    RESTGESTIMPLICITE R
    LEFT OUTER JOIN NGEST G ON G.CODGEST = R.GESTIMPLICITA
    LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = R.CODOBIECT
    LEFT OUTER JOIN NART A ON O.CODARTICOL = A.CODARTICOL
  WHERE
    CODRESTAURANT = aCODRESTAURANT;

 DELETE TMP_RESTGESTIMPLICITE_INI;
 INSERT INTO TMP_RESTGESTIMPLICITE_INI (COD) SELECT COD FROM TMP_RESTGESTIMPLICITE;
 COMMIT;
END;


PROCEDURE POST_GESTIMPLICITE
IS
BEGIN
  DELETE FROM RESTGESTIMPLICITE O
  WHERE
    EXISTS(SELECT COD FROM TMP_RESTGESTIMPLICITE_INI OI WHERE OI.COD = O.COD)
    AND NOT EXISTS(SELECT COD FROM TMP_RESTGESTIMPLICITE OT WHERE OT.COD = O.COD);


  FOR V_REC IN (SELECT * FROM TMP_RESTGESTIMPLICITE)
  LOOP
    IF NVL(V_REC.NEWRECORD, 0) = 0 THEN
      UPDATE RESTGESTIMPLICITE
      SET
        CODOBIECT = V_REC.CODOBIECT,
        GESTIMPLICITA = V_REC.GESTIMPLICITA
      WHERE
        COD = V_REC.COD;
    ELSE
      INSERT INTO RESTGESTIMPLICITE(COD, CODRESTAURANT, CODOBIECT, GESTIMPLICITA)
      VALUES (V_REC.COD, V_REC.CODRESTAURANT, V_REC.CODOBIECT, V_REC.GESTIMPLICITA);
    END IF;
  END LOOP;

  COMMIT;
END;


FUNCTION CANLOCKMASA(aCODMASA IN NUMBER, aCODOSPATAR IN NUMBER) RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  BEGIN
    SELECT NVL(BLOCATA, 0) INTO NR FROM MESE
    WHERE
     CODMASA = aCODMASA
     AND
     (
       (USERID  &lt;&gt; PKG_GLOBALS.USERID) OR
       (USERID  = PKG_GLOBALS.USERID AND NVL(CODOSPATAR, 0) &lt;&gt; NVL(aCODOSPATAR, 0))
     );
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;

  IF NR &gt; 0 THEN RETURN 0;
  ELSE
    UPDATE MESE
    SET
      BLOCATA = 1,
      USERID  = PKG_GLOBALS.USERID,
      CODOSPATAR = NVL(aCODOSPATAR, 0)
    WHERE
      CODMASA = aCODMASA;
    COMMIT;
    RETURN 1;
  END IF;
END;


PROCEDURE UNLOCKMASA(aCODMASA IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   UPDATE MESE
   SET
     BLOCATA = 0,
     USERID  = 0,
     CODOSPATAR = 0
   WHERE
     CODMASA = aCODMASA;
   COMMIT;
END;

PROCEDURE UNLOCK_MESE_RESTAURANT(aCODRESTAURANT IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
   UPDATE MESE M
   SET
     BLOCATA = 0,
     USERID  = 0,
     CODOSPATAR = 0
   WHERE
     USERID = PKG_GLOBALS.USERID
     AND (SELECT S.CODRESTAURANT FROM SALI S  WHERE S.CODSALA = M.CODSALA) = aCODRESTAURANT;
   COMMIT;
END;

PROCEDURE MUTACMD(CODCMDSURSA IN NUMBER, MASADEST IN NUMBER, DESTNRCMD IN NUMBER)
IS
 DESTCODCMD      NUMBER(20) := 0;
 OSPATARCMDSURSA NUMBER(20) := 0;
 aINDEXLOCAL     NUMBER(20) := 0;
 NR              NUMBER(20) := 0;
BEGIN
  SELECT SEQ_RESTCMD_CODRESTCMD.NEXTVAL INTO DESTCODCMD FROM DUAL;
  BEGIN
    SELECT NVL(CODOSPATAR, 0) INTO OSPATARCMDSURSA FROM RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
    EXCEPTION WHEN OTHERS THEN OSPATARCMDSURSA := 0;
  END;

  INSERT INTO RESTCMD(CODRESTCMD, NRCOMANDA, CODMASA, CODOSPATAR, DESCHIDERE)
  VALUES (DESTCODCMD, DESTNRCMD, MASADEST, OSPATARCMDSURSA, SYSDATE);
  aINDEXLOCAL := 0;
  FOR V_REC IN (SELECT M.*, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE, R1.TIPUM, R1.CANTARIT FROM TMP_MUTACMD M, RESTCMD1 R1 WHERE CANTMUTATA &gt; 0 AND R1.CODRESTCMD1 = M.CODRESTCMD1)
  LOOP
    aINDEXLOCAL := aINDEXLOCAL + 1;
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT,  CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT)
    VALUES (SEQ_RESTCMD1_CODRESTCMD1.NEXTVAL, DESTCODCMD, aIndexLocal, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANTMUTATA, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT);

    UPDATE RESTCMD1
    SET
      CANT = CANT - V_REC.CANTMUTATA
    WHERE
      CODRESTCMD1 = V_REC.CODRESTCMD1;

  END LOOP;

  DELETE FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA AND CANT = 0;
  SELECT COUNT(*) INTO NR FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA;
  IF NR = 0 THEN
    DELETE RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
  ELSE
    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM(PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA)
    WHERE
      CODRESTCMD = CODCMDSURSA;
  END IF;

    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM(PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = DESTCODCMD)
    WHERE
      CODRESTCMD = DESTCODCMD;

   UPDATE MESE
   SET
     STARE = 2
   WHERE
     CODMASA = MASADEST;
  COMMIT;
END;


PROCEDURE MUTA_PE_ALTA_CMD(CODCMDSURSA IN NUMBER, CODCMDDEST IN NUMBER)
IS
 aINDEXLOCAL     NUMBER(20) := 0;
 NR              NUMBER(20) := 0;
BEGIN

  BEGIN
    SELECT MAX(INDEXLOCAL) INTO aINDEXLOCAL FROM RESTCMD1 WHERE CODRESTCMD = CODCMDDEST;
    EXCEPTION WHEN OTHERS THEN aINDEXLOCAL := 0;
  END;

  FOR V_REC IN (SELECT M.*, R1.CODOBIECT, R1.UMSEC, R1.PRET, R1.CODGEST, R1.LISTAREGEST, R1.FARALISTARE, R1.TIPUM, R1.CANTARIT FROM TMP_MUTACMD M, RESTCMD1 R1 WHERE CANTMUTATA &gt; 0 AND R1.CODRESTCMD1 = M.CODRESTCMD1)
  LOOP
    aINDEXLOCAL := aINDEXLOCAL + 1;
    INSERT INTO RESTCMD1(CODRESTCMD1, CODRESTCMD, INDEXLOCAL, CODOBIECT, UMSEC, PRET, CANT,  CODGEST, LISTAREGEST, FARALISTARE, TIPUM, CANTARIT)
    VALUES (SEQ_RESTCMD1_CODRESTCMD1.NEXTVAL, CODCMDDEST, aIndexLocal, V_REC.CODOBIECT, V_REC.UMSEC, V_REC.PRET, V_REC.CANTMUTATA, V_REC.CODGEST, V_REC.LISTAREGEST, V_REC.FARALISTARE, V_REC.TIPUM, V_REC.CANTARIT);

    UPDATE RESTCMD1
    SET
      CANT = CANT - V_REC.CANTMUTATA
    WHERE
      CODRESTCMD1 = V_REC.CODRESTCMD1;

  END LOOP;

  DELETE FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA AND CANT = 0;
  SELECT COUNT(*) INTO NR FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA;
  IF NR = 0 THEN
    DELETE RESTCMD WHERE CODRESTCMD = CODCMDSURSA;
  ELSE
    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM(PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDSURSA)
    WHERE
      CODRESTCMD = CODCMDSURSA;
  END IF;

    UPDATE RESTCMD
    SET
      VALOARE = (SELECT SUM(PRET * CANT) FROM RESTCMD1 WHERE CODRESTCMD = CODCMDDEST)
    WHERE
      CODRESTCMD = CODCMDDEST;

  COMMIT;
END;

PROCEDURE LOCK_STOC_CANT(aCODRESTCMD1 IN NUMBER, aCODOBIECT IN NUMBER, aCODGEST IN NUMBER, aCANT IN NUMBER)
IS
NR NUMBER(10) := 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM STOCLOCKREST WHERE USERID = PKG_GLOBALS.USERID AND CODRESTCMD1 = aCODRESTCMD1;
  IF NR = 0 THEN
    INSERT INTO STOCLOCKREST (USERID, CODRESTCMD1, CODOBIECT, CODGEST, CANT)
    VALUES (PKG_GLOBALS.USERID, aCODRESTCMD1, aCODOBIECT, aCODGEST, aCANT);
  ELSE
    UPDATE STOCLOCKREST
    SET
      CANT = aCANT
    WHERE
     USERID = PKG_GLOBALS.USERID
     AND CODRESTCMD1 = aCODRESTCMD1;
 END IF;
 COMMIT;
END;

PROCEDURE RELEASE_ALL_STOCLOCK
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM  STOCLOCKREST
  WHERE
  USERID = PKG_GLOBALS.USERID OR USERID IS NULL;
  COMMIT;
END;

end PKG_RESTAURANT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RESTOBIECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C0740A4076EDDC61F2A7F6414CEAB8C9CD754E1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RESTOBIECTE is
PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT COD INTO Tmp FROM RESTOBIECT WHERE COD = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  -- AICI steregere detalii masa
  DELETE FROM RESTOBIECT WHERE COD = RecId ;
  
  NotifyModif(2, RecId, &apos;RESTOBIECT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_RESTOBIECT FIELDS( COD ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_RESTOBIECT(COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL)
  SELECT COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL
  FROM 
    RESTOBIECT
  WHERE 
    COD = RecId  ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  
    SELECT  COD INTO RecId FROM TMP_RESTOBIECT;

    UPDATE RESTOBIECT
    SET
      (DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL) = (SELECT DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL FROM TMP_RESTOBIECT)
    WHERE 
      COD = RECID;

  ELSE  
    SELECT SEQ_RESTOBIECTE_COD.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO RESTOBIECT(COD, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL)
    SELECT RECID, DENUMIRE, CODSALA, X, Y, WIDTH, HEIGHT,COLOR, TEXTAFISARE, FORMA, POZA, IS3D, NIVEL FROM TMP_RESTOBIECT;
  END IF;
  NotifyModif(Operation, RecId, &apos;RESTOBIECT&apos;);
  COMMIT;
END;

end PKG_RESTOBIECTE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RETURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>76DBD24E46E457140FF8A59AEC6827F9597E5698</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RETURO is
procedure CheckNewData
is
begin
  FOR V_REC in (SELECT T.*, R.SESSIONID AS OrigSessionID FROM TMP_RETURO T LEFT JOIN RETURO R ON T.SESSIONID = R.SESSIONID)
  LOOP
    IF V_rec.OrigSessionID IS NULL THEN
      INSERT INTO RETURO(CODRETURO,          
                         SESSIONID,          
                         STARTEDAT,          
                         REFUND,             
                         VOUCHERBARCODE,     
                         RVM_SERIALNUMBER,   
                         RVM_TYPE,           
                         LOCATION_CUSTOMERID,
                         LOCATION_NAME,
                         UPLOAD_DATE   
                         )
                         VALUES(SEQ_RETURO_codreturo.Nextval,
                                v_rec.SESSIONID,          
                                v_rec.STARTEDAT,          
                                v_rec.REFUND,             
                                v_rec.VOUCHERBARCODE,     
                                v_rec.RVM_SERIALNUMBER,   
                                v_rec.RVM_TYPE,           
                                v_rec.LOCATION_CUSTOMERID,
                                v_rec.LOCATION_NAME,
                                SYSDATE   
                               ); 
   
      
    END IF;  
  END LOOP;    
  COMMIT;
end;    

procedure UpdateUsedVouchers
is
aCODRETURO  NUMBER(20);
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_RETURO WHERE CODRETURO &gt; 0 )
  LOOP
    UPDATE RETURO
    SET
      IS_USED = 1,
      USED_DATE = SysDate
    WHERE
      CODRETURO = V_rec.Codreturo;  
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_RETURO WHERE CODRETURO &lt; 0 )
  LOOP
    SELECT MIN(CODRETURO) INTO aCODRETURO 
    FROM 
      RETURO 
    WHERE
      VOUCHERBARCODE = V_rec.VOUCHERBARCODE;     
      
    IF COALESCE(aCODRETURO, 0) &gt; 0 THEN
      UPDATE RETURO
      SET
        IS_USED = 1,
        USED_DATE = SysDate
      WHERE
        CODRETURO = aCodReturo;
    ELSE    
      INSERT INTO RETURO(CODRETURO, REFUND, VOUCHERBARCODE, IS_USED, USED_DATE)
                       VALUES(SEQ_RETURO_CODRETURO.NEXTVAL, v_rec.refund, V_rec.VOUCHERBARCODE, 1, SYSDATE);
    END IF;                 
  END LOOP;

  COMMIT;    
END;    
end PKG_RETURO;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_REZERVARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E154270033A5A75189D9E4DFCC74A39B3DAA0EB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_REZERVARI IS

procedure GET_TMP_REZURI IS
BEGIN
  GET_TMP_REZ_CCOM1;
  GET_TMP_REZ_REZ;
  GET_TMP_REZ_PROIECTNOD;
  GET_TMP_REZ_STOC(0);
END;

procedure GET_TMP_MANEVRA_LINIICOMENZI(aCodComanda in number) is
begin
  delete from TMP_MANEVRA_LINIICOMENZI;
  insert into TMP_MANEVRA_LINIICOMENZI
  (CodComanda1, Cant)
  ( Select CodComanda1, CantAcceptat 
    from Comanda1 
    where codcomanda = aCodComanda and cuLansare=1 and coalesce(CodProiect,0) &gt; 0
  );
  COMMIT;
end;


procedure GET_TMP_REZ_REZ is
begin
  delete from TMP_REZ_REZ;
  insert into TMP_REZ_REZ
  (
  CODCOMANDA1       ,                         
  DENUMIRE          ,                         
  CODOBIECT         ,                         
  CODGEST           ,                         
  CODIOART          ,                         
  Gest_IOArt        ,
  CANT              ,                         
  RESTCOM           ,                         
  UM                ,                         
  UMSEC             ,                         
  REZ               ,                         
  REZINI            ,                         
  REZFURN           ,                         
  REZCMDFURN        ,                         
  CODNIRSTOC        ,                         
  CODNIRSER         ,                         
  NECESAR           ,                         
  NECESARINI        ,                         
  IDX               ,                         
  REZOLVAT          ,                         
  REZFURNINI        ,
  DEN_UMSEC         ,
  DEN_UM1           ,
  DEN_UM2           ,
  DATADOC,
  CODEXTERN         ,
  D1,D2,D3,
  Paritate,
  RelatieUM1,
  CantUM1,
  CmdFLiber         ,
  REZCMDFURN_INI       
  )                         
  (
select 
  CODCOMANDA1       ,                         
  DENUMIRE          ,                         
  CODOBIECT         ,                         
  CODGEST           ,                         
  CODIOART          ,                         
  Substr(Den_gest, 1, 25) || chr(13) || Den_IOART as Gest_IOArt,
  coalesce(CANT,0)       ,                         
  coalesce(RESTCOM,0)    ,                         
  UM                ,                         
  UMSEC             ,                         
  coalesce(REZ,0)        ,                         
  coalesce(REZINI,0)     ,                         
  coalesce(REZFURN,0)    ,                         
  coalesce(REZCMDFURN,0) ,                         
  CODNIRSTOC        ,                         
  CODNIRSER         ,                         
  coalesce(NECESAR,0)    ,                         
  coalesce(NECESARINI,0) ,                         
  IDX               ,                         
  coalesce(REZOLVAT,0)   ,                         
  coalesce(REZFURNINI,0) ,
  DEN_UMSEC         ,
  DEN_UM1           ,
  DEN_UM2           ,
  DATADOC,
  CODEXTERN,
  D1,D2,D3,
  Paritate,
  RelatieUM1,
  CantUM1,
  Coalesce(CMDFLIBER,0),
  coalesce(REZCMDFURN,0)
from
  (select rr.codcomanda1,
         rr.Denumire,
         rr.codobiect,
         Imp.GESTIMPLICITA codGest,
         IMP.CONTIMPLICIT codIOArt,
         ioa.den_ioart DEN_IOART,
         G.den_gest DEN_GEST,                         
         rr.cant,
         0 RestCom,
         rr.UM,
         rr.UMSec,
         rr.den_umsec,
         rr.den_um1,
         rr.den_um2,
         rez.rest rez,
         rez.ini rezini,
         rezf.restfurn rezfurn,
         rezCmdf.restfurn rezCmdfurn,
         0 codnirstoc,
         0 codnirser,
         rr.necesar,
         rr.necesarini,
         rr.idx,
         coalesce(Rzv.Cant, 0) Rezolvat,
         rezf.restfurn rezfurnIni,
         rr.datadoc,
         rr.codextern,
         RR.D1,RR.D2,RR.D3,
         RR.Paritate,
         RR.RelatieUM1,
         RR.CantUM1,
         cmdfl.cant cmdfliber
    from (select pp.codcomanda1,
                 pp.Denumire,
                 pp.codobiect,
                 pp.idx,
                 pp.UM,
                 pp.UMSec,
                 pp.den_um1,
                 pp.den_um2,
                 pp.den_umsec,
                 pp.datadoc,
                 sum(pp.cant) cant,
                 sum(pp.RestAcceptat) necesar,
                 sum(pp.RestAcceptat) necesarini,
                 pp.codextern,
                 pp.D1,pp.D2,pp.D3,
                 pp.Paritate,
                 pp.RelatieUM1,
                 sum(
                   round(CASE
                           WHEN pp.RELATIEUM1 IN (1, 7) AND coalesce(pp.D1, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT/pp.D1
                           WHEN pp.RELATIEUM1 IN (2, 8) AND coalesce(pp.D1, 0) * coalesce(pp.D2, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT / (coalesce(pp.D1,0) * coalesce(pp.D2,0))
                           WHEN pp.RELATIEUM1 IN (3, 9) AND coalesce(pp.D1, 0) * coalesce(pp.D2, 0) * coalesce(pp.D3, 0) &lt;&gt; 0 THEN PP.RESTACCEPTAT / (coalesce(pp.D1,0) * coalesce(pp.D2,0) * coalesce(pp.D3,0))
                           WHEN pp.RELATIEUM1 IN (4, 10) THEN PP.RESTACCEPTAT * coalesce(pp.D1,0)
                           WHEN pp.RELATIEUM1 IN (5, 11) THEN PP.RESTACCEPTAT * coalesce(pp.D1, 0) * coalesce(pp.D2, 0)
                           WHEN pp.RELATIEUM1 IN (6, 12) THEN PP.RESTACCEPTAT * coalesce(pp.D1, 0) * coalesce(pp.D2, 0) * coalesce(pp.D3, 0)
                           ELSE NULL
                         END,7) 
                 ) CantUM1
            from (select c1.codcomanda1,
                         obj.denumire,
                         obj.codobiect,
                         um.den_um UM,
                         PN.CANT * decode(coalesce(ne.codobiect, 0), 0, 1, ne.paritate) cant,
                         um1.codum1 UMSec,
                         case
                           when coalesce(pn.nodoriginal, 0) = 0 then
                            0
                           else
                            decode(pn.tip,5,3,pn.tip)
                         end Idx,
                         case when pn.tip = 5 then pn.cant else 
                         c1.RestAcceptat * um1.paritate / PN0.CANT *
                         PN.CANT end *
                         decode(coalesce(ne.codobiect, 0), 0, 1, ne.paritate) RestAcceptat,
                         um1.den_um1 den_umsec,
                         um_1.den_um den_um1,
                         um_2.den_um den_um2,
                         c.datadoc,
                         obj.codextern,
                         coalesce(mat.d1,art.D1) d1,
                         coalesce(mat.d2,art.D2) d2,
                         coalesce(mat.d3,art.D3) d3,
                         um1.Paritate,
                         art.RelatieUM1
                    from comanda1 c1
                    inner join comanda c on c1.codcomanda = c.codcomanda
                    inner join tmp_manevra_liniicomenzi tmp on c1.codcomanda1 =
                                                              tmp.codcomanda1
                    left join proiectnod pn on c1.codproiect = pn.codproiect
                    left join prodmat mat on mat.codmat = pn.codprodmat
                    left join proiectnod pn0 on c1.codproiect =
                                                pn0.codproiect
                                            and coalesce(pn0.nodoriginal, 0) = 0
                    left join nodechiv ne on ne.codcomanda1 = c1.codcomanda1
                                         and ne.codproiectnod =
                                             pn.codproiectnod
                    left join nartobj obj on coalesce(ne.codobiect,pn.codobiect) = obj.codobiect                         
                    left join nart art on obj.codarticol = art.codarticol
                    left join num um on art.um = um.codum
                    left join num um_1 on art.um1 = um_1.codum
                    left join num um_2 on art.um2 = um_2.codum
                    left join num1 um1 on art.um = um1.codum
                                      and um1.secundara &lt;&gt; 1
                   where c1.codproiect &gt; 0
                     and c1.culansare = 1) pp
           group by pp.codcomanda1,
                    pp.Denumire,
                    pp.codobiect,
                    pp.umsec,
                    pp.den_umsec,
                    pp.den_um1,
                    pp.den_um2,
                    pp.datadoc,
                    pp.UM,
                    pp.idx,
                    pp.codextern,
                    pp.D1,pp.D2,pp.D3,
                    pp.Paritate,
                    pp.RelatieUM1) rr
    left join (select r.codcomanda1,
                      sum(r.rest) rest,
                      sum(r.RezervatIni) ini,
                      ns.codobiect
                 from rezervats r
                 inner join nirstoc ns on ns.codnirstoc = r.codnirstoc
                WHERE R.CODNIRSTOC &gt; 0
                group by r.codcomanda1,
                         ns.codobiect) rez on rr.codcomanda1 =
                                              rez.codcomanda1
                                          and rr.codobiect = rez.codobiect
    left join (select r.codcomanda1, sum(r.rest) restfurn, r.codobiect
                 from rezervats r
                WHERE coalesce(R.CODNIRSTOC, 0) = 0
                  and coalesce(R.CODCOMANDA1F, 0) = 0
                group by r.codcomanda1, r.codobiect) rezf on rr.codcomanda1 =
                                                             rezf.codcomanda1
                                                         and rr.codobiect =
                                                             rezf.codobiect
    left join (select codobiect, sum(restfurn) cant from 
              (
               select c1.codobiect, c1.restacceptat - coalesce((select sum(r.rest) from rezervats r where r.codcomanda1f = c1.codcomanda1 and codnirstoc = 0),0) restfurn
               from comanda1 c1
                    inner join comanda c on c.codcomanda = c1.codcomanda
               WHERE c.tipdoc = 8 and c.operat = 1 and c.anulat = 0
              )
               where restfurn &gt; 0
               group by codobiect
              ) cmdfl on rr.codobiect = cmdfl.codobiect
    left join (select r.codcomanda1, sum(r.rest) restfurn, r.codobiect
                 from rezervats r
                WHERE coalesce(R.CODNIRSTOC, 0) = 0
                  and coalesce(R.CODCOMANDA1F, 0) &gt; 0
                group by r.codcomanda1, r.codobiect) rezCmdf on rr.codcomanda1 =
                                                                rezCmdf.codcomanda1
                                                            and rr.codobiect =
                                                                rezCmdf.codobiect
    left join nartobj obj on obj.codobiect = rr.codobiect
    left join nartimplicite imp on obj.codarticol = imp.codarticol
                               and imp.codsubunit =
                                   pkg_globals.getsubunitate
    LEFT OUTER JOIN IOART IOA ON coalesce(IOA.CODIOART, 0) =
                                 coalesce(imp.contimplicit, 0)
    LEFT OUTER JOIN NGEST G ON coalesce(G.CODGEST, 0) =
                               coalesce(IMP.GestImplicita, 0)
    LEFT OUTER JOIN (select cmdmat.codobiect,
                            l.codcmd1 codcomanda1,
                            sum(lk.cant) cant
                       from iesprodlink lk
                      inner join cmdprodmat cmdmat on lk.codcmdprodmat =
                                                      cmdmat.codcmdprodmat
                      inner join comanda1 c1 on cmdmat.codcomanda1 =
                                                c1.codcomanda1
                      inner join lansare1 l1 on l1.codcmd1 = c1.codcomanda1
                      inner join lansare l on l1.codlansare = l.codlansare
                      group by cmdmat.codobiect, l.codcmd1) Rzv on Rzv.CodObiect =
                                                                   rr.codobiect
                                                               and Rzv.CodComanda1 =
                                                                   rr.codcomanda1
  ) where NecesarIni &lt;&gt; 0
  );

  COMMIT;
  
end;

procedure UpdateGestIoArt(aCodComanda1 in Number, aCodObiect in Number, aCodGest in Number, aCodIOArt in Number) is
begin
  update TMP_REZ_REZ 
  set 
      CodIOArt   = aCodIOArt, 
      CodGest    = aCodGest, 
      Gest_IOArt = Substr((select DEN_GEST from NGest where CodGest = aCodGest), 1, 25) || Chr(13) || (select DEN_IOART from IOArt where CodIOArt = aCodIOArt)
  where CodComanda1 = aCodComanda1 AND CodObiect = aCodObiect;

  COMMIT;
end;

procedure GET_TMP_REZ_CCOM1 is
  Cate Number(10);
begin
  delete from TMP_REZ_CCOM1;
  insert into TMP_REZ_CCOM1
  (
    CODCOMANDA1  ,                         
    DENUMIRE     ,                         
    TERMEN       ,                         
    CODOBIECT    ,                         
    UM           ,                         
    RESTACCEPTAT ,                         
    CANTACCEPTAT ,                         
    INDEXLOCAL   ,                         
    PARITATE     ,                         
    CODPROIECT   ,                         
    CODRETETA    ,                         
    TIPCOMANDA                            
  )
  (
    select codcomanda1, Denumire, Termen, codobiect, UM, Restacceptat, Cantacceptat, IndexLocal, Paritate, CodProiect, CodReteta, coalesce(DISPLIVRARE, 0)  TipComanda
    from (
    select c1.codcomanda1, c1.termen, obj.denumire, c1.codobiect, umsec.paritate,
            umsec.den_um1 UM, c1.restacceptat, c1.IndexLocal, c1.cantacceptat, c1.CodProiect, c1.CodReteta, C.DISPLIVRARE
    from comanda1 c1 
         inner join tmp_manevra_liniicomenzi tmp on c1.codcomanda1 = tmp.codcomanda1 
         left join nartobj obj on obj.codobiect = C1.codobiect
         left join nart art on obj.codarticol = art.codarticol
         left join num1 umsec on c1.umsec = umsec.codum1
         left join Comanda C on C.codComanda = C1.CodComanda
    where c1.codproiect &gt; 0 and c1.culansare = 1)
  );

  for v_COM in (select CodProiect from TMP_REZ_CCOM1) loop
    select Count(*) into Cate from ProiectNod where CodProiect = v_COM.CodProiect and coalesce(Nivel,0)=1;
    if Cate = 0 then 
      for v_Rec in (SELECT CODPROIECTNOD, level - 1 nivel
                    FROM PROIECTNOD 
                    WHERE CODPROIECT = v_COM.Codproiect
                    START WITH NODORIGINAL = 0 
                    CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL) loop
        
        update proiectnod set nivel = v_rec.nivel where codproiectnod = v_Rec.codproiectnod;            
                    
      end loop;
    end if;
  end loop;

  COMMIT;
end;
 
procedure GET_TMP_REZ_PROIECTNOD is
begin
  delete from TMP_REZ_PROIECTNOD;
  insert into TMP_REZ_PROIECTNOD
  (
    CODCOMANDA1    ,                         
    CODOBIECT      ,                         
    POZITIE        ,                         
    CODPROIECTNOD  ,                         
    NODORIGINAL    ,                         
    NIVEL          ,                         
    INDEXPARINTE   ,
    CANT           ,                         
    NECESAR        ,                         
    CODRETETA      ,                         
    REZERVAT       ,                                
    REZFURN        ,                                
    REZOLVAT       ,
    ORDINE
  )                         
  (
    select * from (select c1.codcomanda1, decode(coalesce(ne.codobiect, 0),0, pn.CodObiect, ne.CodObiect) codobiect, pn.pozitie, 
           pn.codproiectnod, pn.nodoriginal, PN.Nivel, Substr(PN.INDEXPARINTE, 4, 47), 
           1/PN0.CANT * PN.CANT * decode(coalesce(ne.codobiect, 0),0, 1, ne.paritate) Cant, 
           case when pn.tip = 5 then pn.cant else c1.RestAcceptat * umsec.paritate/PN0.CANT * PN.CANT end * decode(coalesce(ne.codobiect, 0),0, 1, ne.paritate) necesar, 
           pn.codreteta, 0 rezervat ,0 rezfurn ,0 rezolvat,coalesce(o.Ordine*10000 + pn.Pozitie,0)
    from comanda1 c1 
         inner join tmp_manevra_liniicomenzi tmp on c1.codcomanda1 = tmp.codcomanda1 
         left join num1 umsec on c1.umsec = umsec.codum1 
         left join proiectnod pn on c1.codproiect = pn.codproiect 
         left join proiectnod pn0 on c1.codproiect = pn0.codproiect and coalesce(pn0.nodoriginal, 0) = 0
         left join (select 
                      distinct px.Nivel, 
                      (Select Max(pxx.Nivel) from proiectnod pxx WHERE pxx.CodProiect = px.codproiect) - px.Nivel as Ordine, 
                      px.codproiect
                    from proiectnod px Group by px.Nivel,px.codproiect
                   ) O on O.Nivel = pn.Nivel and pn.codproiect = O.CodProiect
         left join prodcomp pc on pn.codreteta = pc.codprodcomp 
         left join nartobj obj on pn.codobiect = obj.codobiect 
         left join nart art on obj.codarticol = art.codarticol 
         left join num um on art.um = um.codum
         left join num1 um1 on um1.codum = art.um and um1.secundara = 0 
         left join nodechiv ne on ne.codcomanda1 = c1.codcomanda1 and ne.codproiectnod = pn.codproiectnod 
         left join nartobj obje on ne.codobiect = obje.codobiect 
         left join nart arte on obje.codarticol = arte.codarticol 
         left join num ume on arte.um = ume.codum 
    where c1.codproiect &gt; 0 and c1.culansare = 1 ) where cant &lt;&gt; 0
  );
  COMMIT;
end;

procedure GET_TMP_REZ_STOC(aCodComanda1 in number) is
begin
  delete from TMP_REZ_STOC;
  insert into TMP_REZ_STOC
  (
    CODNIRSER   ,                         
    CODNIRSTOC  ,                         
    CODOBIECT   ,                         
    STOC        ,                         
    CODGEST     ,                         
    CODIOART    ,                         
    REST                                 
  )                         
  (
    select 
    V.CODNIRSER   ,                         
    V.CODNIRSTOC  ,                         
    V.CODOBIECT   ,                         
    V.STOC        ,                         
    V.CODGEST     ,                         
    V.CODIOART    ,                         
    V.stoc rest
    from v_stoc_pt_rezervari v 
    WHERE ( SELECT Count(*) 
            FROM TMP_REZ_REZ 
            WHERE (aCodComanda1 = 0 or CodComanda1 = aCodComanda1)
                  AND CodObiect = v.CODObiect 
                  AND CodGest = v.CODGEST 
                  AND CODIOART = v.CODIOART
           ) &gt; 0
  );

  COMMIT;
  
  
end;

function IsTopItem(aCodComanda1 in number, aCodObiect in number) RETURN NUMBER  
is
NR NUMBER(20) := 0;  
BEGIN
  BEGIN
      SELECT count(*) INTO NR 
    FROM 
      TMP_REZ_ProiectNod  
    WHERE 
      CodComanda1 = aCodComanda1 and CodObiect = aCodObiect and NodOriginal = 0;
    EXCEPTION WHEN OTHERS THEN RETURN 0;        
   END;
   
   RETURN NR; 
END;

procedure BAGAREZERVARE(aCodComanda1 IN NUMBER, aCodCmdProdMat IN NUMBER, aCodNirStoc IN NUMBER, aCodNirSer IN NUMBER, aCant IN NUMBER, aUMSec IN NUMBER, aCodObiect IN NUMBER, aCodComanda1f IN NUMBER) IS
  vCodRezervatS NUMBER(20);
  aNr NUMBER(10);
  aNr1 NUMBER(10);
  vCant NUMBER(20,7);
begin

  select count(*) into aNr 
  from REZERVATS 
  where CodComanda1 = aCodComanda1 
        and coalesce(CodNirStoc, 0)    = aCodNirStoc 
        and coalesce(CodNirSer,  0)    = aCodNirSer
        and coalesce(CodObiect,  0)    = aCodObiect
        and coalesce(CodComanda1f, 0)  = aCodComanda1f;
  
  if aNr = 1 then
    update rezervats set RezervatIni = RezervatIni + aCant, 
                         rest        = rest        + aCant
    where CodComanda1 = aCodComanda1 and 
          coalesce(CodNirStoc, 0)   = aCodNirStoc and 
          coalesce(CodNirSer,  0)   = aCodNirSer  and 
          coalesce(CodObiect,  0)   = aCodObiect  and 
          coalesce(CodComanda1f, 0) = aCodComanda1f;                     
  else
    if aCodNirStoc = 0 and aCodNirser = 0 and aCodComanda1f &gt; 0 then
      select count(*) into aNr1 
      from REZERVATS 
      where CodComanda1 = aCodComanda1 
          and coalesce(CodNirStoc, 0) = 0 
          and coalesce(CodNirSer, 0) = 0
          and coalesce(CodObiect, 0) = aCodObiect
          and coalesce(CodComanda1f, 0) = 0;
      if aNr1 = 1 then 
        select rest into vCant 
          from REZERVATS 
        where CodComanda1 = aCodComanda1 
            and coalesce(CodNirStoc, 0) = 0 
            and coalesce(CodNirSer, 0) = 0
            and coalesce(CodObiect, 0) = aCodObiect
            and coalesce(CodComanda1f, 0) = 0
            and rownum = 1;
        
        if vCant &gt; aCant then
          update rezervats set RezervatIni = RezervatIni - aCant, 
                               rest        = rest        - aCant
          where CodComanda1 = aCodComanda1 and 
                coalesce(CodNirStoc, 0)  = 0 and 
                coalesce(CodNirSer, 0)   = 0 and 
                coalesce(CodObiect, 0)   = aCodObiect
                and coalesce(CodComanda1f, 0) = 0;
          
          select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
          insert into rezervats (codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          values (vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
        else
          if vCant = aCant then
            update rezervats set RezervatIni = 0, 
                                 rest        = 0
            where CodComanda1 = aCodComanda1 and 
                  coalesce(CodNirStoc, 0)  = 0 and 
                  coalesce(CodNirSer, 0)   = 0 and 
                  coalesce(CodObiect, 0)   = aCodObiect
                  and coalesce(CodComanda1f, 0) = 0;
            
            select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
            insert into rezervats (codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
            values (vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
          end if;      
        end if;
      else
        if aNr1 = 0 then 
          select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
          insert into rezervats 
          ( codrezervats, codnirstoc, codnirser, RezervatIni, rest, 
            codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
          values 
          ( vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, 
            aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
        end if;
      end if;
    else      
      select seq_rezervats_codrezervats.nextval into vCodRezervatS from dual;
      insert into rezervats (codrezervats, codnirstoc, codnirser, RezervatIni, rest, codcomanda1, codcmdprodmat, UMSec, CodObiect, CodComanda1f)
      values (vCodRezervatS, aCodNirStoc, aCodNirSer, aCant, aCant, aCodComanda1, aCodCmdProdMat, aUMSec, aCodObiect, aCodComanda1f);
    end if;
  end if;     
end;

procedure ActualizeazaNecesar(aCodComanda1 in Number, aCodProiectNod in Number, aParitate in Number) 
IS
begin
  for v_REZ in (select * from TMP_REZ_ProiectNod where CodComanda1 = aCodComanda1 and NodOriginal = aCodProiectNod)
  loop

      update TMP_REZ_ProiectNod set Necesar = Round(v_REZ.Cant * aParitate, 7) where CodProiectNod = v_REZ.codproiectnod;

      update TMP_REZ_REZ 
      set Rezolvat = Round(Rezolvat + v_REZ.Cant - v_REZ.Cant * aParitate,7)
      where CodObiect = v_REZ.codObiect and CodComanda1 = aCodComanda1;

  end loop;  
end;

function STERGEREZERVAREOBIECT(aCodComanda1 IN NUMBER, aCodObiect IN NUMBER, aTip IN NUMBER) return number IS
pragma autonomous_transaction;
aNr number(20);
begin
  for v_COM in
    (select CodComanda1 from TMP_REZ_CCOM1 where aCodcomanda1 = 0 or CodComanda1 = aCodComanda1)
  loop
    select count(S.codscenariu) into aNr
    from scenariilivr s
         inner join scenariilivr2 s2 on s.codscenariu = s2.codscenariu
    where coalesce(s.definitiv, 0) = 1 and s2.codcomanda1 = v_COM.CodComanda1;
  
    --if aNr = 0 then  --nu e folosit CodComanda1 in scenarii
    -- cand tip e 1 sau 3
      if aTip &lt;&gt; 2 then 
         delete rezervats 
         where codcomanda1 = v_COM.CodComanda1 
               and (aCodObiect = 0 or codobiect = aCodObiect)
               and coalesce(codnirstoc,0) = 0; 
      end if;
    
    -- cand tip e 2 sau 3
      if aTip &lt;&gt; 1 then 
        for v_Rec in 
          ( select r.codrezervats 
            from rezervats r
                 inner join nirstoc ns on r.codnirstoc = ns.codnirstoc
            where (aCodObiect = 0 or NS.codobiect = aCodObiect) and R.codcomanda1 = v_COM.CodComanda1
           ) 
        loop
          delete rezervats where codrezervats = v_rec.codrezervats;                 
        end loop;              
      end if;
    
      commit;
    --end if; --nu e folosit CodComanda1 in scenarii
  end loop;
  Return aNR;
end;

function AdaugaRezervari(aCodComanda1 in number, aCodObiect in number, aCodGest in number, aCodIOArt in number, aCant in number, aUMSec in number) return number is
aCantIni number(20,7);
aRest number(20,7);
STOC_Rest number(20,7);
begin
  if aCant &lt;= 0 then Return 0; end if;
  aCantIni := aCant;
  aRest    := aCant;
  for v_STOC in
    (select * from TMP_REZ_STOC where Rest &gt; 0 and CodObiect = aCodObiect and CodGest = aCodGest and CodIoart = aCodIOart)
  loop

    select Rest into STOC_Rest from TMP_REZ_STOC 
    where CodNIRStoc = v_Stoc.CodNIRSTOC 
          and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);

    if STOC_Rest &gt; aRest then
      update TMP_REZ_STOC set Rest = Rest - aRest 
      where CodNIRStoc = v_Stoc.CodNIRSTOC 
      and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);
     
      BAGAREZERVARE(aCodComanda1, 0, v_STOC.CodNirStoc, coalesce(v_STOC.CodNirSer, 0), aRest, aUMSec, aCodObiect, 0);
      aRest := 0;
    else 
      aRest := aRest - STOC_Rest;
      update TMP_REZ_STOC set Rest = 0 
      where CodNIRStoc = v_Stoc.CodNIRSTOC 
      and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);
      BAGAREZERVARE(aCodComanda1, 0, v_STOC.CodNirStoc, coalesce(v_STOC.CodNirSer, 0), STOC_Rest, aUMSec, aCodObiect, 0);
    end if;
    if aRest &lt;= 0 then Return aCantIni; end if;
  end loop;
  Return aCantIni - aRest;
end;

procedure DoRezervare(aCodComanda1 in number) is
          
  REZ_Rezervat   number(20,7);
  REZ_TOTAL      number(20,7);
  CATE_VREAU     number(20,7);
  ZEC            number(3);
  aParitate      number;
  NOD_Rezervat   number(20,7);
  NOD_Rezolvat   number(20,7);
  NOD_Necesar    number(20,7);
  NOD_RezFurn    number(20,7); 
  aCantIni       number(20,7);
  aRest          number(20,7);
  STOC_Rest      number(20,7);
  REZ_CodGest    number(20); 
  REZ_CodIOArt   number(20);
  REZ_UMSec      number(20);
  DenObiect      varchar2(100);

begin
  --init stoc disponibil
  GET_TMP_REZ_STOC(aCodComanda1); 
  -- initializari
  update TMP_REZ_REZ set Rez = 0 WHERE aCodComanda1 = 0 or Codcomanda1 = aCodcomanda1;

  for v_COM in ( select CodComanda1,TipComanda from TMP_REZ_CCOM1 
                 where aCodcomanda1 = 0 or CodComanda1 = aCodComanda1) 
  loop -- pentru fiecare linie de comanda
    for v_NOD in ( select * from TMP_REZ_ProiectNod 
                   where CodComanda1 = v_COM.Codcomanda1 and (NodOriginal &gt; 0 or v_COM.TipComanda &lt;&gt; 2) and
                   (
                   (codreteta = 0 and coalesce(to_number(pkg_categconst.GetValConstanta(&apos;CmdRezProd&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru)),2) &lt;&gt; 1)
                   or  coalesce(to_number(pkg_categconst.GetValConstanta(&apos;CmdRezProd&apos; ,pkg_globals.ANLUCRU,pkg_globals.lunalucru)),2) = 1
                   )
                   order by CodComanda1, Nivel, Pozitie) 
    loop--pentru fiecare nod din proiect
      select Denumire into DenObiect from TMP_REZ_REZ 
      where CodComanda1 = v_COM.CodComanda1 and CodObiect = v_NOD.CodObiect; 
      --preiau ProiectNod actualizat
      Select Rezervat,     RezFurn,     Necesar,     Rezolvat 
      into   NOD_Rezervat, NOD_RezFurn, NOD_Necesar, NOD_Rezolvat 
      from TMP_REZ_ProiectNod where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;
      ----------------------------------rezervarea
      --calculez necesar de rezervat pe nod curent 
      REZ_Rezervat := 0; 
      CATE_VREAU := NOD_Necesar  - NOD_Rezolvat - NOD_Rezervat - NOD_RezFurn;
      if CATE_VREAU &gt; 0 then 
        --gasesc informatii de stoc din 
        select CodGest, CodIOArt, UMSec into REZ_CodGest, REZ_CodIOArt, REZ_UMSec from TMP_REZ_REZ 
        where CodComanda1 = v_COM.CodComanda1 and CodObiect = v_NOD.CodObiect; 
        --rezolvare din stoc
        aRest := CATE_VREAU;
        for v_STOC in
          ( select * from TMP_REZ_STOC 
            where Rest &gt; 0 
                  and CodObiect = v_NOD.CodObiect 
                  and CodGest   = REZ_CodGest 
                  and CodIoart  = REZ_CodIOArt)
        loop
          if aRest &gt; 0 then 
            select Rest into STOC_Rest from TMP_REZ_STOC where CodNIRStoc = v_STOC.CodNIRSTOC and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);
        
            if STOC_Rest &gt; aRest then
              update TMP_REZ_STOC set Rest = Rest - aRest where CodNIRStoc = v_Stoc.CodNIRSTOC and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);
              BAGAREZERVARE(v_COM.CodComanda1, 0, v_STOC.CodNirStoc, coalesce(v_STOC.CodNirSer,0), aRest, REZ_UMSec, v_NOD.CodObiect, 0);
              aRest := 0;
            else 
              aRest := aRest - STOC_Rest;
              update TMP_REZ_STOC set Rest = 0 
              where  CodNIRStoc = v_Stoc.CodNIRSTOC and coalesce(CodNIRSer, 0) = coalesce(v_STOC.CodNIRSer, 0);
              BAGAREZERVARE(v_COM.CodComanda1, 0, v_STOC.CodNirStoc, coalesce(v_STOC.CodNirSer,0), STOC_Rest, REZ_UMSec, v_NOD.CodObiect, 0);
            end if;
          end if;
        end loop;
        REZ_Rezervat := CATE_VREAU - aRest;
      end if;  
      --rezervarea e gata, stiu REZ_Rezervat
      if REZ_Rezervat &lt;&gt; 0.0 then 

        update TMP_REZ_REZ set RezIni  = RezIni + REZ_Rezervat 
        where CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        update TMP_REZ_ProiectNod set Rezervat = Rezervat + REZ_Rezervat 
        where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;

        REZ_TOTAL := REZ_Rezervat;
        if REZ_TOTAL &lt;&gt; 0 then
          aParitate := REZ_TOTAL /  v_NOD.Necesar;
          --Zec := 7;
          for v_NODXXX in 
            ( SELECT CODPROIECTNOD,CODOBIECT,Necesar FROM TMP_REZ_ProiectNod 
              WHERE CODPROIECTNOD &lt;&gt; v_NOD.CodProiectNod 
              START WITH CODPROIECTNOD = v_NOD.CodProiectNod CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL ) 
          loop
            Select coalesce(u.Zecimale, 0) into ZEC from NUM u, NART a, NARTOBJ o 
            where o.CodObiect = v_NODXXX.CodObiect and a.CodArticol = o.CodArticol and u.CODUM = a.UM;
            update TMP_REZ_REZ set Rezolvat = Round(Rezolvat + v_NodXXX.Necesar * aParitate,ZEC) 
            where CodObiect = v_NodXXX.codObiect and CodComanda1 = v_COM.CodComanda1;
    
            update TMP_REZ_ProiectNod set Rezolvat = Round(Rezolvat + v_NodXXX.Necesar * aParitate,ZEC)
            where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NODXXX.CodProiectNod;
          end loop;  
        end if;
      end if;
    end loop;  
  end loop;
  update TMP_REZ_REZ set 
    RestCom = Round(NecesarIni -Rezolvat-RezIni-RezCmdFurn-RezFurnIni, 7)
  where (aCodComanda1 = 0 or Codcomanda1 = aCodcomanda1);
  COMMIT;
end;

PROCEDURE CERERE_ACHIZITIE(aCodComanda1 in number) IS
  REZ_Rezervat   number(20,7);
  REZ_TOTAL      number(20,7);
  CATE_VREAU     number(20,7);
  aParitate      number(25,12);
  Rezervat   number(20,7);
  Rezolvat   number(20,7);
  Necesar    number(20,7);
  RezFurn    number(20,7);
  RezCmdFurn number(20,7); 
  aCantIni       number(20,7);
  aRest          number(20,7);
  STOC_Rest      number(20,7);
  aCod           number(20);
  REZ_CodGest    number(20); 
  REZ_CodIOArt   number(20);
  REZ_UMSec      number(20);
begin
  -- initializari
  for v_rec in (select * from TMP_REZ_REZ where aCodComanda1 = 0 or Codcomanda1 = aCodcomanda1) loop
    update TMP_REZ_REZ set RezFurn = 0 WHERE codcomanda1 = v_rec.codcomanda1;
    delete rezervats where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect and coalesce(codnirstoc,0) = 0 and coalesce(codcomanda1f,0) = 0;
  end loop;  

  for v_COM in ( select CodComanda1 from TMP_REZ_CCOM1 
                 where aCodcomanda1 = 0 or CodComanda1 = aCodComanda1) 
  loop -- pentru fiecare linie de comanda
    for v_rez in ( select r.* from TMP_REZ_REZ r 
                   where  r.CodComanda1 = v_COM.Codcomanda1 
                          and r.Idx     = 3)
    loop
      Rezervat := v_rez.rez;
      Necesar  := v_rez.necesar;     
      Rezolvat := v_rez.rezolvat;      
      rezcmdfurn  := v_rez.rezcmdfurn;
       
      CATE_VREAU := coalesce(Necesar,0)  - coalesce(Rezolvat,0) - coalesce(Rezervat,0) - coalesce(RezFurn,0) - coalesce(RezCmdFurn,0);
      if CATE_VREAU &gt; 0 then 
        BAGAREZERVARE(v_COM.CodComanda1, 0, 0, 0, CATE_VREAU, v_rez.UMSec, v_rez.CodObiect, 0);

        update TMP_REZ_REZ set RezFurnIni  = RezFurnIni + CATE_VREAU,
                               RestCom     = NecesarIni -Rezolvat-RezIni-RezCmdFurn-RezFurnIni - CATE_VREAU,
                               RezFurn     = RezFurn + CATE_VREAU
        where CodComanda1 = v_rez.CodComanda1 and CodObiect = v_rez.CodObiect;
        update TMP_REZ_REZ set RestCom     = NecesarIni -Rezolvat-RezIni-RezCmdFurn-RezFurnIni - CATE_VREAU
        where CodComanda1 = v_rez.CodComanda1 and CodObiect = v_rez.CodObiect;
      end if;
    end loop;  
  end loop;
  COMMIT;
end;

procedure UpdateNecesarPeRez(aCodComanda1 in number default 0) is
          
  REST_Rez       number(20,7);
  REST_RezFurn   number(20,7);
  REST_RezCmdFurn   number(20,7);
  REZ_Rezervat   number(20,7);
  REZ_RezFURN    number(20,7);
  REZ_RezCmdFURN number(20,7);
  REZ_TOTAL      number(20,7);
  CATE_VREAU     number(20,7);
  aParitate      number;
  ZEC            number(3);
  NOD_Rezervat   number(20,7);
  NOD_Rezolvat   number(20,7);
  NOD_Necesar    number(20,7);
  NOD_RezFurn    number(20,7);
  NOD_RezCmdFurn number(20,7); 
  aCantIni       number(20,7);
  aRest          number(20,7);
  STOC_Rest      number(20,7);
  aCod           number(20);
  REZ_CodGest    number(20); 
  REZ_CodIOArt   number(20);
  REZ_UMSec      number(20);

begin
  --init stoc disponibil
  GET_TMP_REZ_STOC(aCodComanda1); 
  -- initializari
  update TMP_REZ_REZ set Rez = 0, RezFurn = 0, RezCmdFurn = 0, Rezolvat = 0 WHERE coalesce(aCodComanda1,0) = 0 or Codcomanda1 = coalesce(aCodComanda1,0);
  update TMP_REZ_ProiectNod set Rezervat = 0, RezFurn = 0, Rezolvat = 0, RezCmdFurn = 0 WHERE coalesce(aCodComanda1,0) = 0 or Codcomanda1 = coalesce(aCodComanda1,0);

  for v_COM in ( select CodComanda1,TipComanda, CodProiect from TMP_REZ_CCOM1 
                 where coalesce(aCodComanda1,0) = 0 or Codcomanda1 = coalesce(aCodComanda1,0))
  loop -- pentru fiecare linie de comanda
    for v_NOD in ( select tmp.*, case when pn.nodoriginal = 0 then 0 else decode(pn.Tip,5,3,pn.tip) end tip
                   from TMP_REZ_ProiectNod tmp
                        inner join proiectnod pn on pn.codproiectnod = tmp.codproiectnod
                   where  tmp.CodComanda1 = v_COM.Codcomanda1 and (tmp.NodOriginal &gt; 0 or v_COM.TipComanda &lt;&gt; 2)
                   order by tmp.CodComanda1, tmp.Nivel, tmp.Pozitie) 
    loop--pentru fiecare nod din proiect
      --preiau ProiectNod actualizat
      Select Rezervat, RezFurn, RezCmdFurn, Necesar, Rezolvat 
      into NOD_Rezervat, NOD_RezFurn, NOD_RezCmdFurn, NOD_Necesar, NOD_Rezolvat 
      from TMP_REZ_ProiectNod where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;
      --gasesc informatii de stoc din 
      select CodGest, CodIOArt, UMSec, REZINI - REZ, REZFURNINI-REZFURN, rezcmdfurn_ini rezcmdfurn into REZ_CodGest, REZ_CodIOArt, REZ_UMSec, REST_REZ, REST_REZFURN, REST_REZCMDFURN from TMP_REZ_REZ 
      where  CodComanda1 = v_COM.CodComanda1 and CodObiect = v_NOD.CodObiect and idx = v_nod.tip; 
      ----------------------------------rezervarea
      --calculez necesar de rezervat pe nod curent 
      REZ_Rezervat := 0; 
      REZ_RezFurn  := 0; 
      CATE_VREAU   := NOD_Necesar  - NOD_Rezolvat - NOD_Rezervat - NOD_RezFurn;
      
      if CATE_VREAU &lt; REST_Rez then 
         REZ_Rezervat := CATE_VREAU;
         CATE_VREAU   := 0;
      else
         REZ_Rezervat := REST_Rez;
         CATE_VREAU   := CATE_VREAU - REST_Rez;
      end if;
      
      if CATE_VREAU &lt; REST_RezCmdFurn then 
         REZ_RezCmdFurn := CATE_VREAU;
         CATE_VREAU     := 0;
      else
         REZ_RezCmdFurn := REST_RezCmdFurn;
         CATE_VREAU     := CATE_VREAU - REST_RezCmdFurn;
      end if;
      
      if CATE_VREAU &lt; REST_RezFurn then 
         REZ_RezFurn  := CATE_VREAU;
         CATE_VREAU   := 0;
      else
         REZ_RezFurn  := REST_RezFurn;
         CATE_VREAU   := CATE_VREAU - REST_RezFurn;
      end if;
      if REZ_Rezervat &lt;&gt; 0.0 then 

        update TMP_REZ_REZ set Rez  = Rez + REZ_Rezervat 
        where CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        update TMP_REZ_ProiectNod set Rezervat = Rezervat + REZ_Rezervat 
        where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;

        REZ_TOTAL := REZ_Rezervat;
        aParitate := REZ_TOTAL /  v_NOD.Necesar;
        for v_NODXXX in 
          ( SELECT CODPROIECTNOD,CODOBIECT,Necesar FROM TMP_REZ_ProiectNod 
            WHERE CODPROIECTNOD &lt;&gt; v_NOD.CodProiectNod 
            START WITH CODPROIECTNOD = v_NOD.CodProiectNod CONNECT BY PRIOR CODPROIECTNOD = NODORIGINAL ) 
        loop
          Select coalesce(u.Zecimale, 0) into ZEC from NUM u, NART a, NARTOBJ o 
          where o.CodObiect = v_NODXXX.CodObiect and a.CodArticol = o.CodArticol and u.CODUM = a.UM;
          update TMP_REZ_REZ set Rezolvat = Round(Rezolvat + v_NodXXX.Necesar * aParitate,ZEC) 
          where CodObiect = v_NodXXX.codObiect and CodComanda1 = v_COM.CodComanda1;
  
          update TMP_REZ_ProiectNod set Rezolvat = Round(Rezolvat + v_NodXXX.Necesar * aParitate,ZEC)
          where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NODXXX.CodProiectNod;
        end loop;  
      end if;
      
      if REZ_RezCmdFurn &lt;&gt; 0.0 then 
        update TMP_REZ_REZ set RezCmdFurn = RezCmdFurn + REZ_RezCmdFurn 
        where CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        update TMP_REZ_ProiectNod set RezCmdFurn = RezCmdFurn + REZ_RezCmdFurn
        where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;

      end if;
      
      if REZ_RezFurn &lt;&gt; 0.0 then 
        update TMP_REZ_REZ set RezFurn = RezFurn + REZ_RezFurn 
        where CodComanda1 = v_NOD.CodComanda1 and CodObiect = v_NOD.CodObiect;

        update TMP_REZ_ProiectNod set RezFurn = RezFurn + REZ_RezFurn
        where CodComanda1 = v_COM.CodComanda1 and CodProiectNod = v_NOD.CodProiectNod;

      end if;
    end loop;  
  end loop;
  update TMP_REZ_REZ set 
    RestCom = Round(NecesarIni -Rezolvat-RezIni-RezCmdFurn-RezFurnIni, 7)
  where (coalesce(aCodComanda1,0) = 0 or Codcomanda1 = coalesce(aCodComanda1,0));
  COMMIT;
end;

procedure EXEC_DEBUG IS
BEGIN
  PKG_GLOBALS.SetLunaLucru(2010,7);
  PKG_GLOBALS.SETSUBUNITATE(2);
  GET_TMP_MANEVRA_LINIICOMENZI(865);
  GET_TMP_REZURI;
  UpdateNecesarPeRez;
  DoRezervare(947); 
END;

/*
NuEDPS_NodZERO := Idx &gt; 0 or (select TipComanda from TMP_REZ_CCOM1 where CodComanda1 = aCodComanda1) &lt;&gt; 2
*/
end PKG_REZERVARI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ROPHARMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B39DCF217506D31289381A35CB34BA167BB8C577</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ROPHARMA IS


FUNCTION GET_SUBUNITATE_DEST(aCODSUBUNIT IN NUMBER) RETURN NUMBER
IS
 aCOD NUMBER(20) := 2;
BEGIN
    case
       when acodsubunit = 2      then aCOD := 2;
       when acodsubunit = 10000  then aCOD  := 107;
       when acodsubunit = 10001  then aCOD  := 108;
       when acodsubunit = 10006  then aCOD  := 108;
       when acodsubunit = 110029 then aCOD := 104;
       when acodsubunit = 310046 then aCOD := 105;
       when acodsubunit = 510067 then aCOD := 106;
       else aCOD := 2;  
     end CASE;
     RETURN aCOD;
END;  


FUNCTION GET_UMSEC_OF_OBJECT(aCODOBIECT IN NUMBER) RETURN NUMBER
IS
  SIR VARCHAR2(2000);
  aCOD NUMBER(20);
BEGIN
SIR := &apos;SELECT CODUM1 &apos; ||
       &apos;FROM &apos; ||
       &apos;  ROPH2014.NARTOBJ O, &apos; ||
       &apos;  ROPH2014.NART A,&apos; ||
       &apos; ROPH2014.NUM1 U1 &apos; ||
       &apos;WHERE &apos; ||
       &apos;  O.CODOBIECT = &apos; || TO_CHAR(aCODOBIECT) ||
       &apos;  AND O.CODARTICOL = A.CODARTICOL &apos; ||
       &apos;  AND U1.CODUM = A.UM &apos; ||
       &apos;  AND U1.SECUNDARA = 0&apos;;   
  BEGIN
    EXECUTE IMMEDIATE Sir INTO aCOD;
    EXCEPTION WHEN OTHERS THEN aCOD := 0;
  END; 
  RETURN aCOD;
END;    
  

FUNCTION GET_COD_OF_TABLE(TABELA IN VARCHAR2, IDCOLUMN IN VARCHAR2, IDCOLUMN_VALUE IN VARCHAR2, CODCOLUMN IN VARCHAR2) RETURN NUMBER
IS
 SIR VARCHAR2(1000);
 aCOD NUMBER(20);
BEGIN
  SIR := &apos;SELECT &apos; || CODCOLUMN || &apos; FROM ROPH2014.&apos; || TABELA || &apos; WHERE UPPER(&apos; || IDCOLUMN || &apos;)= &apos;&apos;&apos; || UPPER(IDCOLUMN_VALUE) || &apos;&apos;&apos;&apos;;
  BEGIN
    EXECUTE IMMEDIATE Sir INTO aCOD;
    EXCEPTION WHEN OTHERS THEN aCOD := 0;
  END; 
  RETURN aCOD;
END;    

FUNCTION GET_COD_OF_TABLE_EXT(TABELA IN VARCHAR2, IDCOLUMN IN VARCHAR2, IDCOLUMN_VALUE IN VARCHAR2, CODCOLUMN IN VARCHAR2, SKEMA IN VARCHAR2) RETURN NUMBER
IS
 SIR VARCHAR2(1000);
 aCOD NUMBER(20);
BEGIN
  SIR := &apos;SELECT &apos; || CODCOLUMN || &apos; FROM &apos; || SKEMA || &apos;.&apos; || TABELA || &apos; WHERE UPPER(&apos; || IDCOLUMN || &apos;)= &apos;&apos;&apos; || UPPER(IDCOLUMN_VALUE) || &apos;&apos;&apos;&apos;;
  BEGIN
    EXECUTE IMMEDIATE Sir INTO aCOD;
    EXCEPTION WHEN OTHERS THEN aCOD := 0;
  END; 
  RETURN aCOD;
END;    



FUNCTION GET_COD_LOCALIT_DEST(aDENLOCALIT IN VARCHAR2, aTIP IN VARCHAR2, aDENJUDET IN VARCHAR2, aSIMBAUTO IN VARCHAR2, aCODSIRUTA IN NUMBER)
RETURN NUMBER  
IS
 aCODLOCALIT NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODLOCALIT  INTO aCODLOCALIT 
    FROM 
      NLOCALIT 
    WHERE 
      UPPER(DEN_LOCALIT) = UPPER(aDENLOCALIT) 
      AND NVL(UPPER(TIP), &apos;?&apos;) = NVL(UPPER(aTIP), &apos;?&apos;) 
      AND NVL(CODJUDET, 0) = PKG_ROPHARMA.GETCODJUDET_DEST(&apos;ROPH2014&apos;, aDENJUDET, aSIMBAUTO)
      AND NVL(SIRUTA, 0) = NVL(aCODSIRUTA, 0); 
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;
  RETURN aCODLOCALIT;
END;    

PROCEDURE PREIA_NOM_TARI(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2)
IS
 
  S VARCHAR2(1000);
BEGIN
  /*
   GRANT ROLE_ROPH_OBJ TO ROPH2014;
   GRANT ROLE_ROPHIS_OBJ TO ROPH2014;
   GRANT ROLE_ROPHMS_OBJ TO ROPH2014;
   GRANT ROLE_ROPHBC_OBJ TO ROPH2014;
  */
  S := &apos;DECLARE  NR NUMBER(10) := 0;&apos; ||
  &apos;BEGIN &apos; ||
  &apos;FOR V_REC IN (SELECT CODTARA, DEN_TARA, SIMBAUTO, STATCOMUNITAR FROM &apos; || SKEMASURSA || &apos;.NTARI WHERE DEN_TARA IS NOT NULL )&apos; ||
  &apos;LOOP &apos; ||
  &apos;  SELECT COUNT(*) INTO NR &apos; ||
  &apos;  FROM &apos; ||
  &apos;    &apos; || SKEMADEST || &apos;.NTARI T &apos; ||
  &apos;  WHERE &apos; ||
  &apos;   UPPER(DEN_TARA) = UPPER(V_REC.DEN_TARA) &apos; ||
  &apos;   AND upper(NVL(T.SIMBAUTO, &apos;&apos;?&apos;&apos;)) = upper(NVL(V_REC.SIMBAUTO, &apos;&apos;?&apos;&apos;)); &apos; ||
  &apos;   IF NR = 0 THEN &apos; ||
  &apos;     INSERT INTO &apos; || SKEMADEST || &apos;.NTARI(CODTARA, DEN_TARA, SIMBAUTO, STATCOMUNITAR) &apos; ||
  &apos;     VALUES(SEQ_NTARI_CODTARA.NEXTVAL, V_REC.DEN_TARA, V_REC.SIMBAUTO, NVL(V_REC.STATCOMUNITAR, 0)); &apos; ||
  &apos;   END IF;  &apos; ||
  &apos;END LOOP;  &apos; ||
  &apos;END;&apos;;
  EXECUTE IMMEDIATE S;
  COMMIT;
END;


FUNCTION GETCODTARA_DEST(SKEMADEST IN VARCHAR2, aDENTARA IN VARCHAR2, aSIMBTARA IN VARCHAR2) RETURN NUMBER
IS
 S VARCHAR2(1000) := &apos;&apos;;
 aCODTARA NUMBER(20) := 0;
BEGIN
 BEGIN 
    S := &apos;SELECT CODTARA &apos;||
         &apos;   FROM &apos;||
         &apos;     &apos; || SKEMADEST ||&apos;.NTARI &apos;|| 
         &apos;   WHERE &apos; ||
         &apos;    UPPER(DEN_TARA) = &apos;&apos;&apos; || UPPER(aDENTARA) || &apos;&apos;&apos;&apos; || 
         &apos;    AND upper(NVL(SIMBAUTO, &apos;&apos;?&apos;&apos;)) = &apos;&apos;&apos; || upper(NVL(aSIMBTARA, &apos;?&apos;)) || &apos;&apos;&apos;&apos;;
    
--    INSERT INTO T(TEXT) VALUES (S);
--    COMMIT;
    EXECUTE IMMEDIATE   S  INTO aCODTARA;    
    EXCEPTION WHEN OTHERS THEN aCODTARA := 0;  
  END;
  
  RETURN aCODTARA;
END;    


FUNCTION GETCODJUDET_DEST(SKEMADEST IN VARCHAR2, aDENJUDET IN VARCHAR2, aSIMBTARA IN VARCHAR2) RETURN NUMBER
IS
 S VARCHAR2(1000) := &apos;&apos;;
 aCODJUDET NUMBER(20) := 0;
BEGIN
  
  
  BEGIN 
    S := &apos;SELECT CODJUDET &apos;||
         &apos;   FROM &apos;||
         &apos;     &apos; || SKEMADEST ||&apos;.NJUDET &apos;|| 
         &apos;   WHERE &apos; ||
         &apos;    UPPER(DEN_JUDET) = &apos;&apos;&apos; || UPPER(aDENJUDET) || &apos;&apos;&apos;&apos; ||
         &apos;    AND upper(NVL(SIMBAUTO, &apos;&apos;?&apos;&apos;)) = &apos;&apos;&apos; || upper(NVL(aSIMBTARA, &apos;?&apos;)) || &apos;&apos;&apos;&apos;;
    EXECUTE IMMEDIATE   S  INTO aCODJUDET;    
    EXCEPTION WHEN OTHERS THEN aCODJUDET := 0;  
  END;
  
  RETURN aCODJUDET;
END;    


PROCEDURE PREIA_JUDETE(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2)
IS
 S VARCHAR2(1000);
 NR NUMBER(10) := 0;
BEGIN
  
  s := &apos;DECLARE NR NUMBER(10) := 0;&apos; ||
       &apos;BEGIN &apos;||  
       &apos;  FOR V_REC IN (SELECT J.*, T.DEN_TARA, T.SIMBAUTO AS SIMBAUTOTARA FROM &apos; || SKEMASURSA|| &apos;.NJUDET J LEFT OUTER JOIN &apos; || SKEMASURSA || &apos;.NTARI T ON T.CODTARA = J.CODTARA WHERE DEN_JUDET IS NOT NULL)&apos; ||
       &apos;  LOOP &apos;||
       &apos;     SELECT COUNT(*) INTO NR FROM &apos; || SKEMADEST || &apos; .NJUDET &apos;||
       &apos;     WHERE &apos; ||
       &apos;       UPPER(DEN_JUDET) = upper(V_REC.DEN_JUDET); &apos;||
       &apos;  IF NR = 0 THEN &apos;||
       &apos;   INSERT INTO &apos; || SKEMADEST || &apos;.NJUDET(CODJUDET, DEN_JUDET, SIMBAUTO,  CODTARA, REGCOM, CODDRP, DENDRP, JS, ITM)&apos; ||
       &apos;   VALUES (&apos;|| SKEMADEST || &apos;.SEQ_NTARI_CODTARA.NEXTVAL, V_REC.DEN_JUDET, V_REC.SIMBAUTO, &apos;||
       &apos;   PKG_ROPHARMA.GETCODTARA_DEST(&apos;&apos;&apos; || SKEMADEST ||&apos;&apos;&apos;, V_REC.DEN_TARA, V_REC.SIMBAUTOTARA) , &apos;||
       &apos;   V_REC.REGCOM, V_REC.CODDRP, V_REC.DENDRP, V_REC.JS, V_REC.ITM);&apos; ||
       &apos;  END IF; &apos; ||    
       &apos;  END LOOP; &apos; || 
       &apos;END;&apos;;
  execute immediate s;
  COMMIT;     
END;           

PROCEDURE PREIA_LOCALITATI(SKEMASURSA IN VARCHAR2, SKEMADEST IN VARCHAR2)
IS
 S VARCHAR2(4000);
BEGIN
   S := &apos; DECLARE &apos; ||
        &apos;  NR NUMBER(10) := 0;&apos; ||
        &apos;  BEGIN &apos;||
        &apos;    FOR V_REC IN (SELECT  &apos; ||
        &apos;                  L.*, J.DEN_JUDET, J.SIMBAUTO, T.DEN_TARA, T.SIMBAUTO AS SIMBAUTOTARA &apos; ||
        &apos;                  FROM &apos; ||
        &apos;                    &apos; || SKEMASURSA || &apos;.NLOCALIT L  &apos; ||
        &apos;                    LEFT OUTER JOIN &apos; || SKEMASURSA || &apos;.NJUDET J ON J.CODJUDET = L.CODJUDET &apos;||
        &apos;                    LEFT OUTER JOIN &apos; || SKEMASURSA || &apos;.NTARI T ON T.CODTARA = L.CODTARA &apos;||
        &apos;                  WHERE DEN_LOCALIT IS NOT NULL &apos;||
        &apos;                )&apos;||
        &apos;    LOOP &apos;||
        &apos;        SELECT COUNT(*) INTO NR FROM &apos; || SKEMADEST || &apos;.NLOCALIT &apos; ||
        &apos;        WHERE &apos; ||
        &apos;          UPPER(DEN_LOCALIT) = UPPER(V_REC.DEN_LOCALIT) &apos; ||
        &apos;          AND NVL(UPPER(TIP), &apos;&apos;?&apos;&apos;) = NVL(UPPER(V_REC.TIP), &apos;&apos;?&apos;&apos;) &apos; ||
        &apos;          AND NVL(SIRUTA, 0) = NVL(V_REC.SIRUTA, 0) &apos; ||
        &apos;          AND NVL(CODJUDET, 0) = &apos; || SKEMADEST || &apos;.PKG_ROPHARMA.GETCODJUDET_DEST(&apos;&apos;&apos; || SKEMADEST || &apos;&apos;&apos;, V_REC.DEN_JUDET, V_REC.SIMBAUTO);&apos; ||
        &apos;          IF NR = 0 THEN &apos; ||
        &apos;            INSERT INTO &apos; || SKEMADEST || &apos; .NLOCALIT(CODLOCALIT, DEN_LOCALIT, TIP, CODJUDET, OBS, CODTARA, DENSUP, SIRUTA) &apos;||
        &apos;            VALUES(&apos; || SKEMADEST || &apos;.SEQ_NLOCALIT_CODLOCALIT.NEXTVAL, &apos; ||
        &apos;                   V_REC.DEN_LOCALIT, &apos; ||
        &apos;                   V_REC.TIP, &apos; ||
        &apos;                   &apos; || SKEMADEST || &apos;.PKG_ROPHARMA.GETCODJUDET_DEST(&apos;&apos;&apos; || SKEMADEST || &apos;&apos;&apos;, V_REC.DEN_JUDET, V_REC.SIMBAUTO), &apos; ||
        &apos;                   V_REC.OBS, &apos; || SKEMADEST ||&apos;.PKG_ROPHARMA.GETCODTARA_DEST(&apos;&apos;&apos; || SKEMADEST || &apos;&apos;&apos;, V_REC.DEN_TARA, V_REC.SIMBAUTOTARA), &apos; ||
        &apos;                   V_REC.DENSUP, V_REC.SIRUTA &apos; ||
        &apos;                  ); &apos; ||
        &apos;          END IF; &apos; ||       
        &apos;    END LOOP;&apos; ||    
        &apos;    END;&apos;;
  EXECUTE IMMEDIATE S;
  COMMIT;      
end;

PROCEDURE DO_PRELUARE_TARI
IS
BEGIN  
  PREIA_NOM_TARI(&apos;ROPH&apos;,   &apos;ROPH2014&apos;);
  PREIA_NOM_TARI(&apos;ROPHBC&apos;, &apos;ROPH2014&apos;);
  PREIA_NOM_TARI(&apos;ROPHIS&apos;, &apos;ROPH2014&apos;);
  PREIA_NOM_TARI(&apos;MURES&apos;, &apos;ROPH2014&apos;);
END;  



PROCEDURE DO_PRELUARE_JUDETE
IS
BEGIN
  PREIA_JUDETE(&apos;ROPH&apos;,   &apos;ROPH2014&apos;);
  PREIA_JUDETE(&apos;ROPHBC&apos;, &apos;ROPH2014&apos;);
  PREIA_JUDETE(&apos;ROPHIS&apos;, &apos;ROPH2014&apos;);
  PREIA_JUDETE(&apos;MURES&apos;, &apos;ROPH2014&apos;);
END;    

PROCEDURE DO_PRELUARE_LOCALITATI
IS
BEGIN
  PREIA_LOCALITATI(&apos;ROPH&apos;,   &apos;ROPH2014&apos;);
  PREIA_LOCALITATI(&apos;ROPHBC&apos;, &apos;ROPH2014&apos;);
  PREIA_LOCALITATI(&apos;ROPHIS&apos;, &apos;ROPH2014&apos;);
  PREIA_LOCALITATI(&apos;MURES&apos;,  &apos;ROPH2014&apos;);
END;    


end PKG_ROPHARMA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_RUPERE_FIRMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5070C99ACB7CFD5F8284E78798DBFC168124E6E3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_RUPERE_FIRMA IS

PROCEDURE DO_CURATA_TABDETLUNA( sTable VARCHAR2) IS
BEGIN
  EXECUTE IMMEDIATE &apos;DELETE FROM &apos;||sTable||&apos; WHERE ALSTOP &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||sTable||&apos; SET ANSTART = &apos;||AN_RUPERE||&apos;, LUNASTART = &apos;||LUNA_RUPERE||&apos; WHERE ANSTART*12+LUNASTART &lt; &apos;||sAL_RUPERE;
  PRC_AL_REFRESH(sTable);
END;

PROCEDURE DROP_TABLE(pTableName VARCHAR2) IS
  table_does_not_exist EXCEPTION;
  PRAGMA EXCEPTION_INIT(table_does_not_exist, -00942);
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||pTableName;
  EXECUTE IMMEDIATE &apos;DROP TABLE     &apos;||pTableName||&apos; PURGE&apos;;
EXCEPTION
  WHEN TABLE_DOES_NOT_EXIST THEN NULL;
END;

PROCEDURE DISABLE_REFERENCED_BY(pReferencedTab VARCHAR2) IS
BEGIN
  FOR vRec IN (
    SELECT
      &apos;ALTER TABLE &apos;||c1.owner||&apos;.&apos;||c1.table_name||&apos; DISABLE CONSTRAINT &apos;||c1.constraint_name disableFK
    FROM user_tables t
      INNER JOIN user_constraints c1 ON c1.table_name  = t.table_name
      INNER JOIN user_constraints c2 ON c2.constraint_name = c1.r_constraint_name
    WHERE c1.constraint_type =&apos;R&apos; AND c1.status = &apos;ENABLED&apos;
      AND c2.table_name = Upper(pReferencedTab)
  ) LOOP
    EXECUTE IMMEDIATE vRec.disableFK;
  END LOOP;
END;

PROCEDURE ENABLE_REFERENCED_BY(pReferencedTab VARCHAR2) IS
BEGIN
  FOR vRec IN (
    SELECT
      &apos;ALTER TABLE &apos;||c1.owner||&apos;.&apos;||c1.table_name||&apos; ENABLE CONSTRAINT &apos;||c1.constraint_name enableFK
    FROM user_tables t
      INNER JOIN user_constraints c1 ON c1.table_name  = t.table_name
      INNER JOIN user_constraints c2 ON c2.constraint_name = c1.r_constraint_name
    WHERE c1.constraint_type =&apos;R&apos; AND c1.status = &apos;DISABLED&apos;
      AND c2.table_name = Upper(pReferencedTab)
  ) LOOP
    BEGIN
      EXECUTE IMMEDIATE vRec.enableFK;
    EXCEPTION WHEN OTHERS THEN
      PKG_GLOBALS.PUT_INFO(&apos;ERROARE&apos;, sqlerrm);
    END;
  END LOOP;
END;

PROCEDURE CREATE_RF_CTC_AUXCOD IS
BEGIN
  DROP_TABLE(&apos;RF_CTC_AUXCOD&apos;);
  EXECUTE IMMEDIATE &apos;CREATE TABLE RF_CTC_AUXCOD (COD NUMBER(20,0) NULL) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE &apos;CREATE INDEX IDX_RF_CTC_AUXCOD ON RF_CTC_AUXCOD (COD)&apos;;
END;

PROCEDURE COPY_TRUNC_COPY_INIT(pFKValid BOOLEAN, pSRCTableName IN VARCHAR2, sPKCol OUT VARCHAR2, cFK OUT CLOB, bFK OUT BOOLEAN) IS
BEGIN
  DROP_TABLE(&apos;TMP_RF_CTC_AUXTABLE&apos;);
  EXECUTE IMMEDIATE &apos;CREATE GLOBAL TEMPORARY TABLE TMP_RF_CTC_AUXTABLE ON COMMIT PRESERVE ROWS AS SELECT * FROM &apos;||pSRCTableName||&apos; WHERE 1 = 0&apos;;

  IF Coalesce(bReuse_RF_CTC_AUXCOD, FALSE) THEN
    BEGIN
      EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_CTC_AUXCOD&apos;;
    EXCEPTION WHEN OTHERS THEN
      CREATE_RF_CTC_AUXCOD;
    END;
  ELSE
    CREATE_RF_CTC_AUXCOD;
  END IF;

  SELECT COLUMN_NAME INTO sPKCol FROM user_tab_columns WHERE TABLE_NAME = Upper(pSRCTableName) AND COLUMN_ID = 1;

  cFK := Empty_Clob();
  bFK := FALSE;

  IF pFKValid THEN
    FOR vRec IN (
      SELECT
        f_fk.table_name, f_fk.column_name,
        &apos;SELECT DISTINCT RT.&apos;||f_fk.column_name||&apos; AS COD FROM &apos;||c_fk.table_name||&apos; RT WHERE  = RT.&apos;||f_fk.column_name||&apos; IS NOT NULL&apos; cFKUnion
      FROM user_cons_columns f_fk
        INNER JOIN user_constraints  c_fk ON c_fk.constraint_name = f_fk.constraint_name
        INNER JOIN user_constraints  c_pk ON c_pk.constraint_name = c_fk.r_constraint_name
        INNER JOIN user_cons_columns f_pk ON f_pk.constraint_name = c_pk.constraint_name
      WHERE c_fk.constraint_type =&apos;R&apos; --AND c_fk.status = &apos;ENABLED&apos;
        AND f_pk.table_name = Upper(pSRCTableName)
    ) LOOP
      cFK := cFK||&apos; UNION
      &apos;||vRec.cFKUnion;
      bFK := TRUE;
    END LOOP;
  END IF;
END;

PROCEDURE COPY_TRUNC_COPY_START(pSRCTableName VARCHAR2, pSQL CLOB) IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;INFO SQL&apos;, pSQL);
  EXECUTE IMMEDIATE pSQL;                                                                              --Copiere in TMP_RF_CTC_AUXTABLE date ce trebuies pastrate
  DISABLE_REFERENCED_BY(pSRCTableName);                                                                --Dezactivare FK sa nu avem erori la Truncate
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||pSRCTableName;                                                  --Golire Tabela
  EXECUTE IMMEDIATE &apos;INSERT /*+ APPEND */ INTO &apos;||pSRCTableName||&apos; SELECT * FROM TMP_RF_CTC_AUXTABLE&apos;; --Copiere din TMP_RF_CTC_AUXTABLE
  COMMIT;

  DROP_TABLE(&apos;TMP_RF_CTC_AUXTABLE&apos;);
  IF Coalesce(bReuse_RF_CTC_AUXCOD, FALSE)
  THEN EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_CTC_AUXCOD&apos;;
  ELSE DROP_TABLE(&apos;RF_CTC_AUXCOD&apos;);
  END IF;
  ENABLE_REFERENCED_BY(pSRCTableName);                                                                 --Reactivare FK
END;

PROCEDURE COPY_TRUNC_COPY_KEEP(pFKValid BOOLEAN, pSRCTableName VARCHAR2, pSRCField VARCHAR2, pKeepTable VARCHAR2, pKeepField VARCHAR2, pMod NUMERIC DEFAULT 1) IS
  cSQL   CLOB;
  sPKCol VARCHAR2(50);
  cFK    CLOB;
  bFK    BOOLEAN;
BEGIN
  COPY_TRUNC_COPY_INIT(pFKValid, pSRCTableName, sPKCol, cFK, bFK);
  IF bFK THEN
    cSQL := &apos;INSERT /*+ APPEND */ INTO RF_CTC_AUXCOD
    SELECT DISTINCT S.&apos;||sPKCol||&apos; AS COD FROM &apos;||pKeepTable||&apos; T LEFT JOIN &apos;||pSRCTableName||&apos; S ON S.&apos;||pSRCField||&apos; = T.&apos;||pKeepField||&apos; WHERE S.&apos;||sPKCol||&apos; IS NOT NULL&apos;||
    cFK;
    PKG_GLOBALS.PUT_INFO(&apos;INFO SQL&apos;, cSQL);
    EXECUTE IMMEDIATE cSQL;
    COMMIT;

    cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM RF_CTC_AUXCOD T LEFT JOIN &apos;||pSRCTableName||&apos; S ON S.&apos;||sPKCol||&apos; = T.COD WHERE S.&apos;||sPKCol||&apos; IS NOT NULL&apos;;
  ELSE
    IF    pMod = 3 THEN cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S INNER JOIN &apos;||pKeepTable||&apos; C ON C.&apos;||pKeepField||&apos; = S.&apos;||pSRCField;
    ELSIF pMod = 2 THEN cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S WHERE EXISTS(SELECT 1 FROM &apos;||pKeepTable||&apos; C WHERE C.&apos;||pKeepField||&apos; = S.&apos;||pSRCField||&apos;)&apos;;
    ELSE                cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S WHERE S.&apos;||pSRCField||&apos; IN (SELECT DISTINCT &apos;||pKeepField||&apos; FROM &apos;||pKeepTable||&apos;)&apos;;
    END IF;
  END IF;
  COPY_TRUNC_COPY_START(pSRCTableName, cSQL);
END;

PROCEDURE COPY_TRUNC_COPY_EXCLUDE(pFKValid BOOLEAN, pSRCTableName VARCHAR2, pSRCField VARCHAR2, pExclTable VARCHAR2, pExclField VARCHAR2, pMod NUMERIC DEFAULT 1) IS
  vNr    NUMERIC;
  cSQL   CLOB;
  sPKCol VARCHAR2(50);
  cFK    CLOB;
  bFK    BOOLEAN;
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT COUNT(1) FROM &apos;||pExclTable||&apos; WHERE &apos;||pExclField||&apos; IS NOT NULL&apos; INTO vNr;
  IF vNr &gt; 0 THEN
    COPY_TRUNC_COPY_INIT(pFKValid, pSRCTableName, sPKCol, cFK, bFK);
    IF bFK THEN
      cSQL := &apos;INSERT /*+ APPEND */ INTO RF_CTC_AUXCOD
      SELECT DISTINCT S.&apos;||sPKCol||&apos; AS COD FROM &apos;||pSRCTableName||&apos; S LEFT JOIN &apos;||pExclTable||&apos; T ON S.&apos;||pSRCField||&apos; = T.&apos;||pExclField||&apos; WHERE T.&apos;||pExclField||&apos; IS NULL&apos;||
      cFK;
      PKG_GLOBALS.PUT_INFO(&apos;INFO SQL&apos;, cSQL);
      EXECUTE IMMEDIATE cSQL;
      COMMIT;

      cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM RF_CTC_AUXCOD T LEFT JOIN &apos;||pSRCTableName||&apos; S ON S.&apos;||sPKCol||&apos; = T.COD WHERE S.&apos;||sPKCol||&apos; IS NOT NULL&apos;;
    ELSE
      IF    pMod = 3 THEN cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S LEFT JOIN &apos;||pExclTable||&apos; C ON C.&apos;||pExclField||&apos; = S.&apos;||pSRCField||&apos; WHERE C.&apos;||pExclField||&apos; IS NULL&apos;;
      ELSIF pMod = 2 THEN cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S WHERE NOT EXISTS(SELECT 1 FROM &apos;||pExclTable||&apos; C WHERE C.&apos;||pExclField||&apos; = S.&apos;||pSRCField||&apos;)&apos;;
      ELSE                cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S WHERE NOT S.&apos;||pSRCField||&apos; IN (SELECT DISTINCT &apos;||pExclField||&apos; FROM &apos;||pExclTable||&apos;)&apos;;
      END IF;
    END IF;
    COPY_TRUNC_COPY_START(pSRCTableName, cSQL);
  END IF;
END;

PROCEDURE COPY_TRUNC_COPY_COND(pFKValid BOOLEAN, pSRCTableName VARCHAR2, pCond CLOB) IS
  cSQL   CLOB;
  sPKCol VARCHAR2(50);
  cFK    CLOB;
  bFK    BOOLEAN;
BEGIN
  COPY_TRUNC_COPY_INIT(pFKValid, pSRCTableName, sPKCol, cFK, bFK);
  IF bFK THEN
    cSQL := &apos;INSERT /*+ APPEND */ INTO RF_CTC_AUXCOD
    SELECT S.&apos;||sPKCol||&apos; AS COD FROM &apos;||pSRCTableName||&apos; S WHERE &apos;||pCond||
    cFK;
    PKG_GLOBALS.PUT_INFO(&apos;INFO SQL&apos;, cSQL);
    EXECUTE IMMEDIATE cSQL;
    COMMIT;

    cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM RF_CTC_AUXCOD T LEFT JOIN &apos;||pSRCTableName||&apos; S ON S.&apos;||sPKCol||&apos; = T.COD WHERE S.&apos;||sPKCol||&apos; IS NOT NULL&apos;;
  ELSE
    cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_CTC_AUXTABLE SELECT S.* FROM &apos;||pSRCTableName||&apos; S WHERE &apos;||pCond;
  END IF;
  COPY_TRUNC_COPY_START(pSRCTableName, cSQL);
END;

PROCEDURE DO_BLOCHEAZA_DURATA_MIFIX IS
BEGIN
  UPDATE MIFIX1 SET DFBLOCAT = 1, DFBLOCAT_F = 1, DFBLOCAT_G = 1, AMOBLOCAT = 1 WHERE ANSTART*12+LUNASTART = AL_RUPERE;
END;

PROCEDURE DO_CURATA_CONSTANTE IS
BEGIN
  DELETE FROM CONSTVAL    WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM CONSTLUNA WHERE USERID IS NULL OR ALSTOP &lt; AL_RUPERE);
  DELETE FROM CONSTVALPOS WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM CONSTLUNA WHERE USERID IS NULL OR ALSTOP &lt; AL_RUPERE);
  DELETE FROM CONSTLUNA   WHERE USERID IS NULL OR ALSTOP &lt; AL_RUPERE;

  PRC_AL_REFRESH(&apos;CONSTLUNA&apos;);
END;

PROCEDURE DO_SOLVE_CURS_REG_PART IS
BEGIN
  FOR V_REC IN (
    SELECT R.CODREG, R1.CODREG1, R1.CODGENERAL, R.CURS
    FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
    WHERE R.TIPREG = 46 AND R.AN*12+R.LUNA &lt; AL_RUPERE
    ORDER BY R.AN, R.LUNA
  )
  LOOP
    UPDATE GENERAL SET CURS = V_REC.CURS WHERE CODGENERAL = V_REC.CODGENERAL;
    DELETE REG1 WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;
  DELETE FROM REG WHERE TIPREG = 46 AND AN*12+LUNA &lt; AL_RUPERE;
END;

PROCEDURE SETANLUNARUPERE(aAN IN NUMBER, aLUNA IN NUMBER) IS
BEGIN
  AN_RUPERE    := aAN;
  LUNA_RUPERE  := aLUNA;
  AL_RUPERE    := aAN*12+aLUNA;

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(AN_RUPERE, LUNA_RUPERE, AN_INITIALIZARI, LUNA_INITIALIZARI);
  AL_INITIALIZARI := AN_INITIALIZARI*12+LUNA_INITIALIZARI;

  sAL_INITIALIZARI := To_Char(AL_INITIALIZARI, &apos;FM00000&apos;);
  sAL_RUPERE       := To_Char(AL_RUPERE      , &apos;FM00000&apos;);
END;

PROCEDURE REPARA_INCOERENTA_ICONTURI IS
BEGIN
  FOR V_REC IN (
    SELECT
      OSTINGATOR.CODOBLIGPIF AS CODOBLIGSTINGATOR,
      OSTINS.ICONT AS ICONTSTINS,
      OSTINGATOR.ICONT AS ICONTSTINGATOR,
      S.VALOARE
    FROM STINGERE S
      INNER JOIN OBLIGPIF OSTINS     ON OSTINS.CODOBLIGPIF     = S.CODSTINSPIF
      INNER JOIN OBLIGPIF OSTINGATOR ON OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
    WHERE OSTINS.ICONT &lt;&gt; OSTINGATOR.ICONT
  ) LOOP
    UPDATE OBLIGPIF SET ICONT = V_REC.ICONTSTINS
    WHERE CODOBLIGPIF = V_REC.CODOBLIGSTINGATOR;
  END LOOP;
END;

PROCEDURE DO_FIXARI_LUNI(bInclInchise BOOLEAN) IS
  ANTMP   NUMBER(5) := 0;
  LUNATMP NUMBER(2) := 0;
  ANP     NUMBER(5);
  LUNAP   NUMBER(2);
  ANC     NUMBER(5);
  LUNAC   NUMBER(2);
  bIesIni NUMBER(1);
  bIntIni NUMBER(1);
BEGIN
  IF NOT bInclInchise THEN
    SELECT ANINITIAL, LUNAINITIALA, ANCURENT, LUNACURENTA INTO ANTMP, LUNATMP, ANC, LUNAC FROM FIRMALUNI;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(ANTMP, LUNATMP, ANP, LUNAP);

    PKG_GLOBALS.PUT_INFO(&apos;01.BA&apos;,&apos;FIXARI LUNI - REPARA AVIZINTLUNA/AVIZIESLUNA CU CANTITATI DIN INITILIZARE DACA E CAZUL&apos;);
    SELECT
      CASE
        WHEN EXISTS (SELECT 1 FROM AVIZINTLUNA WHERE AN = ANP AND LUNA = LUNAP                                                                                                      ) THEN 1
        WHEN EXISTS (SELECT 1 FROM INTRARI I INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR WHERE I.AN = ANP AND I.LUNA = LUNAP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2) THEN 0
        ELSE 1
      END,
      CASE
        WHEN EXISTS (SELECT 1 FROM AVIZIESLUNA WHERE AN = ANP AND LUNA = LUNAP                                                                                                      ) THEN 1
        WHEN EXISTS (SELECT 1 FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES WHERE I.AN = ANP AND I.LUNA = LUNAP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 20   ) THEN 0
        ELSE 1
      END
    INTO
      bIntIni,
      bIesIni
    FROM DUAL;

    IF bIntIni = 0 THEN
      PKG_GLOBALS.PUT_INFO(&apos;01.BB&apos;,&apos;FIXARI LUNI - REPARA AVIZINTLUNA INSERT &apos;||ANP||&apos;.&apos;||LUNAP);
      INSERT INTO AVIZINTLUNA (CODINTR1, REST, AN, LUNA)
      SELECT I1.CODINTR1, I1.CANT REST, ANP,  LUNAP -- AVIZE DIN LUNA INITIALIZARE
      FROM INTRARI I INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
      WHERE I.AN = AnP AND I.LUNA = LunaP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2;

      COMMIT;
    END IF;

    IF bIesIni = 0 THEN
      PKG_GLOBALS.PUT_INFO(&apos;01.BC&apos;,&apos;FIXARI LUNI - REPARA AVIZIESLUNA INSERT &apos;||ANP||&apos;.&apos;||LUNAP);
      INSERT INTO AVIZIESLUNA (CODIES1, REST, AN, LUNA)
      SELECT I1.CODIES1, I1.CANT REST, ANP,  LUNAP -- AVIZE DIN LUNA INITIALIZARE
      FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
      WHERE I.AN = AnP AND I.LUNA = LunaP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2;

      COMMIT;
    END IF;

    WHILE ANTMP*12+LUNATMP &lt;= ANC*12+LUNAC LOOP
      IF bIntIni = 0 THEN
        PKG_GLOBALS.PUT_INFO(&apos;01.BD&apos;,&apos;FIXARI LUNI - REPARA AVIZINTLUNA MERGE LUNA &apos;||ANTMP||&apos;.&apos;||LUNATMP);

        MERGE INTO AVIZINTLUNA AIL
        USING (
          SELECT I1.CODINTR1, I1.CANT REST, ANTMP AN, LUNATMP LUNA
          FROM INTRARI I INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
          WHERE I.AN = AnP AND I.LUNA = LunaP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2
        ) I1INI ON (I1INI.CODINTR1 = AIL.CODINTR1 AND I1INI.AN = AIL.AN AND I1INI.LUNA = AIL.LUNA)
        WHEN     MATCHED THEN UPDATE SET AIL.REST = AIL.REST + I1INI.REST
        WHEN NOT MATCHED THEN INSERT(CODINTR1, REST, AN, LUNA) VALUES (I1INI.CODINTR1, I1INI.REST, I1INI.AN, I1INI.LUNA);

        COMMIT;
      END IF;

      IF bIesIni = 0 THEN
        PKG_GLOBALS.PUT_INFO(&apos;01.BE&apos;,&apos;FIXARI LUNI - REPARA AVIZIESLUNA MERGE LUNA &apos;||ANTMP||&apos;.&apos;||LUNATMP);
        MERGE INTO AVIZIESLUNA AIL
        USING (
          SELECT I1.CODIES1, I1.CANT REST, ANTMP AN, ANTMP LUNA
          FROM IESIRI I INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
          WHERE I.AN = AnP AND I.LUNA = LunaP AND I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 2
        ) I1INI ON (I1INI.CODIES1 = AIL.CODIES1 AND I1INI.AN = AIL.AN AND I1INI.LUNA = AIL.LUNA)
        WHEN     MATCHED THEN UPDATE SET AIL.REST = AIL.REST + I1INI.REST
        WHEN NOT MATCHED THEN INSERT(CODIES1, REST, AN, LUNA) VALUES (I1INI.CODIES1, I1INI.REST, I1INI.AN, I1INI.LUNA);

        COMMIT;
      END IF;
      PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(ANTMP, LUNATMP, ANTMP, LUNATMP);
    END LOOP;
  END IF;

  BEGIN
    IF bInclInchise
    THEN SELECT ANINITIAL, LUNAINITIALA INTO ANTMP, LUNATMP FROM FIRMALUNI;
    ELSE SELECT ANCURENT,  LUNACURENTA  INTO ANTMP, LUNATMP FROM FIRMALUNI;
    END IF;
  EXCEPTION WHEN OTHERS THEN
    ANTMP := 0; LUNATMP := 0;
  END;

  PKG_GLOBALS.PUT_INFO(&apos;01.AC&apos;,&apos;FIXARI LUNI - REPARA_INCOERENTA_ICONTURI&apos;);
  REPARA_INCOERENTA_ICONTURI;

  WHILE ANTMP*12+LUNATMP &lt; AL_RUPERE
  LOOP
    PKG_GLOBALS.PUT_INFO(&apos;01.AD&apos;,&apos;FIXARI LUNI - FIXARE LUNA :&apos;||ANTMP||&apos;/&apos;||LUNATMP);
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(ANTMP, LUNATMP, ANP, LUNAP);
    PKG_GLOBALS.SetLunaPRECEDENTA(ANP, LUNAP);
    PKG_GLOBALS.SetLunaTEMP(ANTMP, LUNATMP);
    PKG_INCHIDERI.MAKE_SOLD_BANK;
    PKG_INCHIDERI.MAKE_SOLD_PERS;
    PKG_INCHIDERI.MAKE_SOLD_PERS_SUB;
    PKG_INCHIDERI.MAKE_SOLD_PART_EXT;
    PKG_INCHIDERI.MAKE_SOLD_PART_SUB_EXT;
    PKG_INCHIDERI.MAKE_STOC_LUNA_EXT;
    PKG_INCHIDERI.MAKE_STOCVAL_LUNA;
    PKG_INCHIDERI.MAKE_PMP_LUNA;
    PKG_INCHIDERI.MAKE_REST_OBLIGPIF_LUNA;
    PKG_INCHIDERI.MAKE_AVIZINT_LUNA;
    PKG_INCHIDERI.MAKE_AVIZIES_LUNA;
    --PKG_INCHIDERI.MAKE_COMANDA1_LUNA;
    PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(ANTMP, LUNATMP, ANTMP, LUNATMP);
  END LOOP;
END;

PROCEDURE CREATE_TMP_RF_FAI_AE1 IS
BEGIN
  DROP_TABLE(&apos;TMP_RF_FAI_AE1&apos;);
  EXECUTE IMMEDIATE
  &apos;CREATE GLOBAL TEMPORARY TABLE TMP_RF_FAI_AE1 (
    CODI1 NUMBER(20,0) NULL,
    CODI  NUMBER(20,0) NULL,
    CANT  NUMBER(20,7) NULL,
    REST  NUMBER(20,7) NULL
  ) ON COMMIT PRESERVE ROWS&apos;;
END;

PROCEDURE CREATE_TMP_RF_FAI_FAE1 IS
BEGIN
  DROP_TABLE(&apos;TMP_RF_FAI_FAE1&apos;);
  EXECUTE IMMEDIATE
  &apos;CREATE GLOBAL TEMPORARY TABLE TMP_RF_FAI_FAE1 (
    CODI1 NUMBER(20,0) NULL,
    CODI  NUMBER(20,0) NULL
  ) ON COMMIT PRESERVE ROWS&apos;;
END;

PROCEDURE FIXEAZA_INITILIZARE_TREZOR IS
  cSQL CLOB;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;02.AB&apos;,&apos;FIXARE TREZOR AN LUNA&apos;);
  UPDATE TREZOR T
  SET (AN, LUNA) = (SELECT T1.AN, T1.LUNA FROM TREZOR1 T1 WHERE T1.CODTREZOR = T.CODTREZOR AND ROWNUM = 1)
  WHERE AN IS NULL;

  UPDATE TREZOR T
  SET AN = AN_INITIALIZARI , LUNA = LUNA_INITIALIZARI
  WHERE AN IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;02.BA&apos;,&apos;CREARE SI POPULARE - RF_T1_DE_STERS&apos;);

  DROP_TABLE(&apos;RF_T1_DE_STERS&apos;);
  cSQL := &apos;CREATE TABLE RF_T1_DE_STERS (
    CODGENERAL NUMBER(20,0) NULL,
    CODTREZOR1 NUMBER(20,0) NULL,
    CODTREZOR  NUMBER(20,0) NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_T1_DE_STERS(CODGENERAL, CODTREZOR1, CODTREZOR)
  SELECT G.CODGENERAL, T1.CODTREZOR1, T.CODTREZOR
  FROM GENERAL G
    INNER JOIN TREZOR1 T1 ON t1.codtrezor1 = g.coddoc
    INNER JOIN TREZOR  T  ON t.codtrezor = t1.codtrezor AND t.tipdoc = g.tipdoc
  WHERE G.SEMNIFICATIE IN (800, 801, 900, 901, 950, 951, 1000, 1100, 1101) AND T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;02.BB&apos;,&apos;STERGERE - OBLIGPIF&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM RF_T1_DE_STERS)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;02.BC&apos;,&apos;STERGERE - GENERAL&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM GENERAL WHERE CODGENERAL IN (SELECT CODGENERAL FROM RF_T1_DE_STERS)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;02.BD&apos;,&apos;STERGERE - TREZOR1&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM TREZOR1 WHERE CODTREZOR1 IN (SELECT CODTREZOR1 FROM RF_T1_DE_STERS)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;02.BE&apos;,&apos;STERGERE - TREZOR&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM TREZOR WHERE CODTREZOR IN (SELECT DISTINCT RF.CODTREZOR FROM RF_T1_DE_STERS RF WHERE NOT EXISTS (SELECT 1 FROM TREZOR1 T1 WHERE T1.CODTREZOR = RF.CODTREZOR))&apos;;

  COMMIT;
  DROP_TABLE(&apos;RF_T1_DE_STERS&apos;);
END;

PROCEDURE FIXEAZA_INITILIZARE_COMENZI IS
  cSQL CLOB;
BEGIN
  --mComenziFurnizori       =  8;
  --mComenziClienti         = 18;
  --mComenziGestiuni        = 43;
  --mComenziCatreSubunitati = 44;
  --mComenziProdComp        = 53;
  --mComenziDELASubunitati  = 60; // folosit impreuna cu flagul DispozitieLivrare la Centralizator comenzi de la subunitati
  --mComenziStorno          = 65;
  --mComenziStornoFurn      = 66;

  PKG_GLOBALS.PUT_INFO(&apos;03.BA&apos;,&apos;CREARE - RF TABS&apos;);

  DROP_TABLE(&apos;RF_CP&apos;);
  cSQL := &apos;CREATE TABLE RF_CP (
    CODCOMANDA    NUMBER(20,0) NULL,
    INCHISA       NUMBER(1)    NULL,
    LEGDUPARUPERE NUMBER(1)    NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;
  EXECUTE IMMEDIATE &apos;CREATE INDEX IDX_RF_CP ON RF_CP (CODCOMANDA)&apos;;

  DROP_TABLE(&apos;RF_C1_REST&apos;);
  cSQL := &apos;CREATE TABLE RF_C1_REST (
    CODCOMANDA1   NUMBER(20,0) NULL,
    CANTACCEPTAT  NUMBER(20,7) NULL,
    RESTACCEPTAT  NUMBER(20,7) NULL,
    INCHISA       NUMBER(1)    NULL,
    LEGDUPARUPERE NUMBER(1)    NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;
  EXECUTE IMMEDIATE &apos;CREATE INDEX IDX_RF_C1_REST ON RF_C1_REST (CODCOMANDA1)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;03.BB&apos;,&apos;POPULARE - RF_CP -&gt; TIPDOC = 53&apos;);

  UPDATE COMANDA SET INCHISA = 0 WHERE INCHISA IS NULL;
  COMMIT;

-- discutii productie
--SELECT * FROM cmdprodman;
--  manprodlink

--SELECT * FROM cmdprodmat;
--  tip 0 -&gt; intrprodlink (agregare    - comanda1 -&gt; consum = 1)
--        -&gt; iesprodlink  (dezagregare - comanda1 -&gt; consum = 2)
--  tip 1 -&gt; iesprodlink
--  tip 2 -&gt; intrprodlink

  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_CP(CODCOMANDA, INCHISA, LEGDUPARUPERE)
  SELECT D.CODCOMANDA, D.INCHISA, 0 LEGDUPARUPERE
  FROM COMANDA D
  WHERE D.TIPDOC = 53 AND D.INCHISA = 0
    AND D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos;
  UNION
  SELECT D.CODCOMANDA, D.INCHISA, 1 LEGDUPARUPERE
  FROM COMANDA D
    INNER JOIN COMANDA1    D1 ON D1.CODCOMANDA = D.CODCOMANDA
    INNER JOIN CMDPRODMAN  CP ON CP.CODCOMANDA1 = D1.CODCOMANDA1
    INNER JOIN MANPRODLINK L  ON L.CODCMDPRODMAN = CP.CODCMDPRODMAN
    INNER JOIN RAPORTP2    R2 ON R2.CODRAPORTP2 = L.CODRAPORTP2
    INNER JOIN RAPORTP1    R1 ON R1.CODRAPORTP1 = R2.CODRAPORTP1
    INNER JOIN RAPORTP     R  ON R.CODRAPORTP = R1.CODRAPORTP
  WHERE D.TIPDOC = 53 AND D.INCHISA = 1
    AND D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND R.AN*12+R.LUNA &gt;= &apos;||sAL_RUPERE||&apos;
  UNION
  SELECT D.CODCOMANDA, D.INCHISA, 1 LEGDUPARUPERE
  FROM COMANDA D
    INNER JOIN COMANDA1     D1 ON D1.CODCOMANDA = D.CODCOMANDA
    INNER JOIN CMDPRODMAT   CP ON CP.CODCOMANDA1 = D1.CODCOMANDA1
    INNER JOIN INTRPRODLINK L  ON L.CODLINIECOMANDA = CP.CODCMDPRODMAT
    INNER JOIN INTRARI1     I1 ON I1.CODINTR1 = L.CODINTR1
    INNER JOIN INTRARI      I  ON I.CODINTR = I1.CODINTR
  WHERE D.TIPDOC = 53 AND D.INCHISA = 1
    AND D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND I.AN*12+I.LUNA &gt;= &apos;||sAL_RUPERE||&apos;
  UNION
  SELECT D.CODCOMANDA, D.INCHISA, 1 LEGDUPARUPERE
  FROM COMANDA D
    INNER JOIN COMANDA1    D1 ON D1.CODCOMANDA = D.CODCOMANDA
    INNER JOIN CMDPRODMAT  CP ON CP.CODCOMANDA1 = D1.CODCOMANDA1
    INNER JOIN IESPRODLINK L  ON L.CODCMDPRODMAT = CP.CODCMDPRODMAT
    INNER JOIN IESIRI1     I1 ON I1.CODIES1 = L.CODIES1
    INNER JOIN IESIRI      I  ON I.CODIES = I1.CODIES
  WHERE D.TIPDOC = 53 AND D.INCHISA = 1
    AND D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND I.AN*12+I.LUNA &gt;= &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.BC&apos;,&apos;POPULARE - RF_C1_REST -&gt; TIPDOC IN (8, 18, 43, 44)&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_C1_REST(CODCOMANDA1, CANTACCEPTAT, RESTACCEPTAT, INCHISA, LEGDUPARUPERE)
  SELECT CODCOMANDA1, SUM(CANTACCEPTAT) AS CANTACCEPTAT, SUM(RESTACCEPTAT) AS RESTACCEPTAT, MAX(INCHISA) AS INCHISA, MAX(LEGDUPARUPERE) LEGDUPARUPERE
  FROM (
    SELECT -- COMENZI CREATE IN LUNILE ANALIZATE
      D1.CODCOMANDA1,
      D1.CANTACCEPTAT, D1.CANTACCEPTAT RESTACCEPTAT,
      Coalesce(D.INCHISA, 0) INCHISA,
      0 LegDupaRupere
    FROM COMANDA D
      INNER JOIN COMANDA1 D1 ON D1.CODCOMANDA = D.CODCOMANDA
    WHERE D.TIPDOC IN (8, 18, 43, 44)
      AND D.AN*12+LUNA &lt; &apos;||sAL_RUPERE||&apos;
    UNION ALL
    SELECT -- COMENZI STINSE IN LUNILE ANALIZATE -- RETUR
      C1.CODCOMANDA1,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN -L.CANT ELSE 0 END CANTACCEPTAT , -L.CANT RESTACCEPTAT,
      0 INCHISA,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN 0 ELSE 1 END LEGDUPARUPERE
    FROM CMDLIVRLINK L
      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODLINIECOMANDA
      INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
      INNER JOIN COMANDA1 D1 ON D1.CODCOMANDA1 = L.CODCOMANDA1
      INNER JOIN COMANDA  D  ON D1.CODCOMANDA  = D.CODCOMANDA
    WHERE C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND D.TIPDOC IN (65, 66)
    UNION ALL
    SELECT -- COMENZI STINSE IN LUNILE ANALIZATE -- COMENZI FURNIZORI
      C1.CODCOMANDA1,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN -L.CANT ELSE 0 END CANTACCEPTAT , -L.CANT RESTACCEPTAT,
      0 INCHISA,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN 0 ELSE 1 END LEGDUPARUPERE
    FROM INTRLINK L
      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODLINIECOMANDA
      INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
      INNER JOIN INTRARI1 D1 ON L.CODINTR1     = D1.CODINTR1
      INNER JOIN INTRARI  D  ON D1.CODINTR     = D.CODINTR
    WHERE C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND D.TIPDOC IN (1, 2, 3, 4, 5, 6, 7, 9)
    UNION ALL
    SELECT -- COMENZI CLIENTI + COMENZI SUBUNITATI
      C1.CODCOMANDA1,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN -L.CANT ELSE 0 END CANTACCEPTAT , -L.CANT RESTACCEPTAT,
      0 INCHISA,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN 0 ELSE 1 END LEGDUPARUPERE
    FROM IESLINK L
      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODLINIECOMANDA
      INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
      INNER JOIN IESIRI1  D1 ON L.CODIES1      = D1.CODIES1
      INNER JOIN IESIRI   D  ON D1.CODIES      = D.CODIES
    WHERE C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND D.TIPDOC IN (19, 20, 21, 22, 23, 24, 25, 26)
    UNION ALL
    SELECT -- COMENZI GESTIUNI
      C1.CODCOMANDA1,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN -L.CANT ELSE 0 END CANTACCEPTAT , -L.CANT RESTACCEPTAT,
      0 INCHISA,
      CASE WHEN D.AN*12+D.LUNA &lt; &apos;||sAL_RUPERE||&apos; THEN 0 ELSE 1 END LEGDUPARUPERE
    FROM TRANSFLINK L
      INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = L.CODLINIECOMANDA
      INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
      INNER JOIN TRANSF1  D1 ON L.CODTRANSF1   = D1.CODTRANSF1
      INNER JOIN TRANSF   D  ON D1.CODTRANSF   = D.CODTRANSF
    WHERE C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND D.TIPDOC = 12
  )
  GROUP BY CODCOMANDA1&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.BD&apos;,&apos;STERGERE - RF_C1_REST -&gt; WHERE INCHISA = 1 AND LEGDUPARUPERE = 0&apos;);
  cSQL := &apos;DELETE FROM RF_C1_REST WHERE INCHISA = 1 AND LEGDUPARUPERE = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CA&apos;,&apos;COPY_TRUNC_COPY_KEEP - CMDLIVRLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CL.CODCOMANDA1
  FROM CMDLIVRLINK CL
    INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = CL.CODCOMANDA1
    INNER JOIN COMANDA  C  ON C1.CODCOMANDA  = C.CODCOMANDA
  WHERE C.AN*12+C.LUNA &gt;= AL_RUPERE;
  COMMIT;

  COPY_TRUNC_COPY_KEEP(FALSE, &apos;CMDLIVRLINK&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.CB&apos;,&apos;DELETE OBSOLETE FROM INTRLINK&apos;);
  DELETE FROM INTRLINK IL
  WHERE Coalesce(IL.CODLINIECOMANDA, 0) &gt; 0
    AND EXISTS(SELECT 1 FROM INTRARI1 I1 INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR WHERE I1.CODINTR1 = IL.CODINTR1 AND I.AN*12+I.LUNA &lt; AL_RUPERE);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CC&apos;,&apos;DELETE OBSOLETE FROM IESLINK&apos;);
  DELETE FROM IESLINK IL
  WHERE Coalesce(IL.CODLINIECOMANDA, 0) &gt; 0
    AND EXISTS(SELECT 1 FROM IESIRI1 I1 INNER JOIN IESIRI I ON I.CODIES = I1.CODIES WHERE I1.CODIES1 = IL.CODIES1 AND I.AN*12+I.LUNA &lt; AL_RUPERE);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CD&apos;,&apos;COPY_TRUNC_COPY_KEEP - TRANSFLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT TL.CODTRANSF1
  FROM TRANSFLINK TL
    INNER JOIN TRANSF1 T1 ON TL.CODTRANSF1 = T1.CODTRANSF1
    INNER JOIN TRANSF  T  ON T1.CODTRANSF  = T.CODTRANSF
  WHERE T.AN*12+T.LUNA &gt;= AL_RUPERE;
  COMMIT;

  COPY_TRUNC_COPY_KEEP(FALSE, &apos;TRANSFLINK&apos;, &apos;CODTRANSF1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.CE&apos;,&apos;ANALIZA - MANPRODLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT L.CODRAPORTP2
  FROM MANPRODLINK L
    INNER JOIN RAPORTP2    R2 ON R2.CODRAPORTP2 = L.CODRAPORTP2
    INNER JOIN RAPORTP1    R1 ON R1.CODRAPORTP1 = R2.CODRAPORTP1
    INNER JOIN RAPORTP     R  ON R.CODRAPORTP = R1.CODRAPORTP
    INNER JOIN CMDPRODMAN  CP ON CP.CODCMDPRODMAN = L.CODCMDPRODMAN
    INNER JOIN COMANDA1    D1 ON D1.CODCOMANDA1 = CP.CODCOMANDA1
  WHERE R.AN*12+R.LUNA &gt;= &apos;||sAL_RUPERE||&apos; OR EXISTS(SELECT 1 FROM RF_CP RF WHERE RF.CODCOMANDA = D1.CODCOMANDA)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CF&apos;,&apos;COPY_TRUNC_COPY_KEEP - MANPRODLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;MANPRODLINK&apos;, &apos;CODRAPORTP2&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.CG&apos;,&apos;ANALIZA - INTRPRODLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT L.CODINTR1
  FROM INTRPRODLINK L
    INNER JOIN INTRARI1    I1 ON I1.CODINTR1 = L.CODINTR1
    INNER JOIN INTRARI     I  ON I.CODINTR = I1.CODINTR
    INNER JOIN CMDPRODMAT  CP ON CP.CODCMDPRODMAT = L.CODLINIECOMANDA
    INNER JOIN COMANDA1    D1 ON D1.CODCOMANDA1 = CP.CODCOMANDA1
  WHERE I.AN*12+I.LUNA &gt;= &apos;||sAL_RUPERE||&apos; OR EXISTS(SELECT 1 FROM RF_CP RF WHERE RF.CODCOMANDA = D1.CODCOMANDA)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CH&apos;,&apos;COPY_TRUNC_COPY_KEEP - INTRPRODLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;INTRPRODLINK&apos;, &apos;CODINTR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.CI&apos;,&apos;ANALIZA - IESPRODLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT L.CODIES1
  FROM IESPRODLINK L
    INNER JOIN IESIRI1     I1 ON I1.CODIES1 = L.CODIES1
    INNER JOIN IESIRI      I  ON I.CODIES = I1.CODIES
    INNER JOIN CMDPRODMAT  CP ON CP.CODCMDPRODMAT = L.CODCMDPRODMAT
    INNER JOIN COMANDA1    D1 ON D1.CODCOMANDA1 = CP.CODCOMANDA1
  WHERE I.AN*12+I.LUNA &gt;= &apos;||sAL_RUPERE||&apos; OR EXISTS(SELECT 1 FROM RF_CP RF WHERE RF.CODCOMANDA = D1.CODCOMANDA)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.CJ&apos;,&apos;COPY_TRUNC_COPY_KEEP - IESPRODLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;IESPRODLINK&apos;, &apos;CODIES1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.DA&apos;,&apos;ACTUALIZARE REST COMANDA1 -&gt; TIPDOC IN (8, 18, 43, 44)&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODCOMANDA1
  FROM RF_C1_REST
  WHERE CANTACCEPTAT &lt;&gt; 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  cSQL :=
  &apos;UPDATE COMANDA1 C1
  SET (CANTACCEPTAT, RESTACCEPTAT) = (SELECT TC1.CANTACCEPTAT, TC1.RESTACCEPTAT FROM RF_C1_REST TC1 WHERE TC1.CODCOMANDA1 = C1.CODCOMANDA1)
  WHERE CODCOMANDA1 IN (SELECT CODUNIC FROM TMP_MANEVRA)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.DB&apos;,&apos;COMANDA1 &lt;-&gt; TMP_MANEVRA / CODURI DE PASTRAT&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT C1.CODCOMANDA1
  FROM RF_CP RF INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = RF.CODCOMANDA&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT C1.CODCOMANDA1
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  WHERE C.AN*12+C.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;03.DB&apos;,&apos;COMANDA &lt;-&gt; TMP_MANEVRA2 / CODURI DE PASTRAT&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA2(CODUNIC)
  SELECT DISTINCT C1.CODCOMANDA
  FROM TMP_MANEVRA T LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = T.CODUNIC;
  COMMIT;

  --COMANDA1LUNA  -&gt; SE CURATA IN STERGE_FIXARI_LUNARE_ANTER;

  PKG_GLOBALS.PUT_INFO(&apos;03.EA&apos;,&apos;COPY_TRUNC_COPY_KEEP CMDPRODMAN&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;CMDPRODMAN&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EB&apos;,&apos;COPY_TRUNC_COPY_KEEP CMDPRODMAT&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;CMDPRODMAT&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EC&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA4&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA4&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.ED&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA3&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EE&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA2&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EF&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA1ET&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA1ET&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EG&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA1&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.EH&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;03.GA&apos;,&apos;ACTUALIZARE AN LUNA COMANDA &apos;);
  UPDATE COMANDA SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE AN*12+LUNA &lt; AL_INITIALIZARI;

  DROP_TABLE(&apos;RF_C1_REST&apos;);
  DROP_TABLE(&apos;RF_CP&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
END;

PROCEDURE FIXEAZA_INITILIZARE_STOCURI IS
  cSQL    CLOB;
BEGIN
  -- Initial erau TMP_RF_FSI_NIRSTOC si TMP_RF_FSI_LIVR1 (indexate amandoua)
  --dar se pare ca sunt ceva probleme cu statisticile la temporare si nu foloseste indexul corespunzator
  PKG_GLOBALS.PUT_INFO(&apos;04.AB&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI CURATENIE TMP NECESARE&apos;);
  DROP_TABLE(&apos;RF_FSI_NIRSTOC&apos;);
  DROP_TABLE(&apos;RF_FSI_LIVR1&apos;);

  cSQL := &apos;CREATE TABLE RF_FSI_NIRSTOC (
    CODNIRSTOC NUMBER(20,0) NULL,
    GEST       NUMBER(20,0) NULL,
    CODINTR    NUMBER(20,0) NULL,
    CODIES     NUMBER(20,0) NULL,
    CODTRANSF  NUMBER(20,0) NULL,
    REST       NUMBER(20,7) NULL,
    RESTUM1    NUMBER(20,7) NULL,
    RESTUM2    NUMBER(20,7) NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;CREATE INDEX IDX_RF_FSI_NIRSTOC ON RF_FSI_NIRSTOC (CODNIRSTOC)&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;CREATE TABLE RF_FSI_LIVR1 (
    CODLIVR1   NUMBER(20,0) NULL,
    CODINTR    NUMBER(20,0) NULL,
    CODIES     NUMBER(20,0) NULL,
    CODTRANSF  NUMBER(20,0) NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;CREATE INDEX IDX_RF_FSI_LIVR1 ON RF_FSI_LIVR1 (CODLIVR1)&apos;;
  EXECUTE IMMEDIATE cSQL;

  PKG_GLOBALS.PUT_INFO(&apos;04.AC&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_NIRSTOC DIN INTRARI&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_NIRSTOC
  SELECT
    NS.CODNIRSTOC, N.GEST, I.CODINTR, 0 CODIES, 0 CODTRANSF,
    Coalesce(NL.REST, 0) REST, Coalesce(NL.RESTUM1, 0) RESTUM1,  Coalesce(NL.RESTUM2, 0) RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
    INNER JOIN INTRARI I  ON I.CODINTR     = N.CODINTR     AND I.TIPDOC = N.TIPNIR
    LEFT  JOIN NIRLUNA NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN    = &apos;||AN_INITIALIZARI||&apos; AND NL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    LEFT  JOIN IOART1  IO ON IO.CODIOART   = NS.CODIOART   AND &apos;||sAL_RUPERE||&apos; BETWEEN IO.ALStart AND IO.ALStop
  WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND Coalesce(IO.MG, 0) &lt;&gt; 5&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AD&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_NIRSTOC DIN TRANSF&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_NIRSTOC
  SELECT
    NS.CODNIRSTOC, N.GEST, 0 CODINTR, 0 CODIES, T.CODTRANSF,
    Coalesce(NL.REST, 0) REST, Coalesce(NL.RESTUM1, 0) RESTUM1,  Coalesce(NL.RESTUM2, 0) RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
    INNER JOIN TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF   AND T.TIPDOC = N.TIPNIR
    LEFT  JOIN NIRLUNA NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN    = &apos;||AN_INITIALIZARI||&apos; AND NL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    LEFT  JOIN IOART1  IO ON IO.CODIOART   = NS.CODIOART   AND &apos;||sAL_RUPERE||&apos; BETWEEN IO.ALStart AND IO.ALStop
  WHERE T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND Coalesce(IO.MG, 0) &lt;&gt; 5&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AE&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_NIRSTOC DIN IESIRI&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_NIRSTOC
  SELECT
    NS.CODNIRSTOC, N.GEST, 0 CODINTR, E.CODIES, 0 CODTRANSF,
    Coalesce(NL.REST, 0) REST, Coalesce(NL.RESTUM1, 0) RESTUM1,  Coalesce(NL.RESTUM2, 0) RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
    INNER JOIN IESIRI  E  ON E.CODIES      = N.CODIES      AND E.TIPDOC = N.TIPNIR
    LEFT  JOIN NIRLUNA NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN    = &apos;||AN_INITIALIZARI||&apos; AND NL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    LEFT  JOIN IOART1  IO ON IO.CODIOART   = NS.CODIOART   AND &apos;||sAL_RUPERE||&apos; BETWEEN IO.ALStart AND IO.ALStop
  WHERE E.AN*12+E.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND Coalesce(IO.MG, 0) &lt;&gt; 5&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AF&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI REFACERE STOCINI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE STOCINI&apos;;
  PKG_REMAKE_SEQUENCES.REVAL_SEQUENCE(&apos;STOCINI&apos;,&apos;CODSTOCINI&apos;,&apos;SEQ_STOCINI_CODSTOCINI&apos;,TRUE);
  cSQL := &apos;INSERT INTO STOCINI(CODSTOCINI, CODGEST)
  SELECT SEQ_STOCINI_CODSTOCINI.NEXTVAL, GEST
  FROM (
    SELECT DISTINCT GEST
    FROM RF_FSI_NIRSTOC
    WHERE REST &lt;&gt; 0 OR RESTUM1 &lt;&gt; 0 OR RESTUM2 &lt;&gt; 0
  )&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AG&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE NIRSTOC REST = 0&apos;);
  cSQL := &apos;UPDATE NIRSTOC
  SET CANTNIR = 0, CANTUM1 = 0, CANTUM2 = 0
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM RF_FSI_NIRSTOC WHERE REST = 0 AND RESTUM1 = 0 AND RESTUM2 = 0)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AH&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE NIRSER REST = 0&apos;);
  cSQL := &apos;UPDATE NIRSER
  SET CANTNIR = 0, CANTUM1 = 0, CANTUM2 = 0
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM RF_FSI_NIRSTOC WHERE REST = 0 AND RESTUM1 = 0 AND RESTUM2 = 0)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AI&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE NIRSTOC REST &lt;&gt; 0&apos;);
  cSQL := &apos;UPDATE NIRSTOC NS
  SET (       CANTNIR,                CANTUM1,                CANTUM2 ) =
      (SELECT Coalesce(NL.REST   ,0), Coalesce(NL.RESTUM1,0), Coalesce(NL.RESTUM2,0)
       FROM NIRLUNA NL
       WHERE NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN = &apos;||AN_INITIALIZARI||&apos; AND NL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
      )
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM RF_FSI_NIRSTOC WHERE REST &lt;&gt; 0 OR RESTUM1 &lt;&gt; 0 OR RESTUM2 &lt;&gt; 0)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AJ&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE NIRSER REST &lt;&gt; 0&apos;);
  cSQL := &apos;UPDATE NIRSER NS
  SET (       CANTNIR,                     CANTUM1,                     CANTUM2) =
      (SELECT Coalesce(Max(NL.REST   ),0), Coalesce(Max(NL.RESTUM1),0), Coalesce(Max(NL.RESTUM2),0)
       FROM NIRSERLUNA NL
       WHERE NL.CODNIRSER = NS.CODNIRSER AND NL.AN = &apos;||AN_INITIALIZARI||&apos; AND NL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
      )
  WHERE CODNIRSTOC IN (SELECT CODNIRSTOC FROM RF_FSI_NIRSTOC WHERE REST &lt;&gt; 0 OR RESTUM1 &lt;&gt; 0 OR RESTUM2 &lt;&gt; 0)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AK&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE INTRARI AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODINTR IN (SELECT DISTINCT CODINTR FROM RF_FSI_NIRSTOC)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AL&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE IESIRI AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI  SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODIES IN (SELECT DISTINCT CODIES FROM RF_FSI_NIRSTOC)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.AM&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE TRANSF AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE TRANSF  SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODTRANSF IN (SELECT DISTINCT CODTRANSF FROM RF_FSI_NIRSTOC)&apos;;
  COMMIT;

  -- RUPERE LEGATURI LIVRARI ANTERIOARE LUNII DE RUPERE
  PKG_GLOBALS.PUT_INFO(&apos;04.BA&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_LIVR1 DIN INTRARI&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_LIVR1
  SELECT L1.CODLIVR1, I.CODINTR, 0 CODIES, 0 CODTRANSF
  FROM INTRARI I
    INNER JOIN LIVR  L  ON L.CODINTR  = I.CODINTR AND L.TIPLIVR = I.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
  WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND EXISTS (SELECT 1 FROM RF_FSI_NIRSTOC TMP WHERE TMP.CODNIRSTOC = L1.CODNIRSTOC)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.BB&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_LIVR1 DIN TRANSF&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_LIVR1
  SELECT L1.CODLIVR1, 0 CODINTR, 0 CODIES, T.CODTRANSF
  FROM TRANSF T
    INNER JOIN LIVR  L  ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR  = L.CODLIVR
  WHERE T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND EXISTS (SELECT 1 FROM RF_FSI_NIRSTOC TMP WHERE TMP.CODNIRSTOC = L1.CODNIRSTOC)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.BC&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI POPULARE RF_FSI_LIVR1 DIN IESIRI&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_LIVR1
  SELECT L1.CODLIVR1, 0 CODINTR, E.CODIES, 0 CODTRANSF
  FROM IESIRI E
    INNER JOIN LIVR  L  ON L.CODIES   = E.CODIES AND L.TIPLIVR = E.TIPDOC
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
  WHERE E.AN*12+E.LUNA &lt; &apos;||sAL_RUPERE||&apos;
    AND EXISTS (SELECT 1 FROM RF_FSI_NIRSTOC TMP WHERE TMP.CODNIRSTOC = L1.CODNIRSTOC)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.BD&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE LIVR1 CANT = 0&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE LIVR1 L1 SET CANT = 0, CANTUM1 = 0, CANTUM2 = 0 WHERE EXISTS (SELECT 1 FROM RF_FSI_LIVR1 T WHERE T.CODLIVR1 = L1.CODLIVR1)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;04.BE&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE INTRARI AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODINTR   IN (SELECT DISTINCT CODINTR   FROM RF_FSI_LIVR1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.BF&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE IESIRI AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI  SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODIES    IN (SELECT DISTINCT CODIES    FROM RF_FSI_LIVR1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.BG&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI ACTUALIZARE TRANSF AN / LUNA&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE TRANSF  SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODTRANSF IN (SELECT DISTINCT CODTRANSF FROM RF_FSI_LIVR1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;04.CA&apos;,&apos;FIXEAZA_INITILIZARE_STOCURI CURATA TMP&apos;);
  DROP_TABLE(&apos;RF_FSI_NIRSTOC&apos;);
  DROP_TABLE(&apos;RF_FSI_LIVR1&apos;);
END;

PROCEDURE FIXEAZA_INITILIZARE_STOCVAL
IS
 ERR      NUMBER(20) := 0;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;05.AB&apos;,&apos;STOCVALINI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE STOCVALINI&apos;;
  PKG_REMAKE_SEQUENCES.REVAL_SEQUENCE(&apos;STOCVALINI&apos;,&apos;CODSTOCVALINI&apos;,&apos;SEQ_STOCVALINI_CODSTOCVALINI&apos;,TRUE);

  INSERT INTO STOCVALINI(CODSTOCVALINI, GEST)
  SELECT SEQ_STOCVALINI_CODSTOCVALINI.NEXTVAL, GEST
  FROM ( SELECT DISTINCT GEST FROM STOCVALLUNA WHERE AN = AN_INITIALIZARI AND LUNA = LUNA_INITIALIZARI);

  -- CURAT NIRURI VALORICE ANTERIOARE RUPERII
  PKG_GLOBALS.PUT_INFO(&apos;05.AB&apos;,&apos;NIRSTOC&apos;);
  FOR V_REC IN (
    SELECT NS.CODNIRSTOC, N.GEST, I.CODINTR, E.CODIES, T.CODTRANSF
    FROM NIRSTOC NS
      INNER JOIN NIR     N ON N.CODNIR    = NS.CODNIR
      LEFT  JOIN INTRARI I ON I.CODINTR   = N.CODINTR   AND I.TIPDOC = N.TIPNIR
      LEFT  JOIN IESIRI  E ON E.CODIES    = N.CODIES    AND E.TIPDOC = N.TIPNIR
      LEFT  JOIN TRANSF  T ON T.CODTRANSF = N.CODTRANSF AND T.TIPDOC = N.TIPNIR
      LEFT  JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND AL_RUPERE BETWEEN IO.ALStart AND IO.ALStop
    WHERE Coalesce(I.AN,E.AN,T.AN)*12+Coalesce(I.LUNA,E.LUNA,T.LUNA) &lt; AL_RUPERE
      AND Coalesce(IO.MG, 0) = 5
  ) LOOP
    IF V_REC.CODINTR   IS NOT NULL THEN UPDATE INTRARI SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODINTR   = V_REC.CODINTR;   END IF;
    IF V_REC.CODIES    IS NOT NULL THEN UPDATE IESIRI  SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODIES    = V_REC.CODIES;    END IF;
    IF V_REC.CODTRANSF IS NOT NULL THEN UPDATE TRANSF  SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODTRANSF = V_REC.CODTRANSF; END IF;
    BEGIN
      DELETE NIRSER  WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
      DELETE NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
    EXCEPTION
      WHEN OTHERS THEN ERR := ERR + 1;
    END;
  END LOOP;

 -- CURAT LIVRARI VALORICE ANTERIOARE RUPERII
  PKG_GLOBALS.PUT_INFO(&apos;05.AB&apos;,&apos;LIVRVAL&apos;);
  FOR V_REC IN (
    SELECT LV.CODLIVRVAL, LV.CODLIVR1, I.CODINTR, E.CODIES, T.CODTRANSF
    FROM LIVRVAL LV
      INNER JOIN LIVR1   L1 ON LV.CODLIVR1  = L1.CODLIVR1
      INNER JOIN LIVR    L  ON L1.CODLIVR   = L.CODLIVR
      LEFT  JOIN INTRARI I  ON I.CODINTR    = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
      LEFT  JOIN IESIRI  E  ON E.CODIES     = L.CODIES    AND E.TIPDOC = L.TIPLIVR
      LEFT  JOIN TRANSF  T  ON T.CODTRANSF  = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR
    WHERE COALESCE(I.AN,E.AN,T.AN)*12+COALESCE(I.LUNA,E.LUNA,T.LUNA) &lt; AL_RUPERE
  ) LOOP
    IF V_REC.CODINTR   IS NOT NULL THEN UPDATE INTRARI SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODINTR   = V_REC.CODINTR;   END IF;
    IF V_REC.CODIES    IS NOT NULL THEN UPDATE IESIRI  SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODIES    = V_REC.CODIES;    END IF;
    IF V_REC.CODTRANSF IS NOT NULL THEN UPDATE TRANSF  SET AN = AN_INITIALIZARI, LUNA = LUNA_INITIALIZARI WHERE CODTRANSF = V_REC.CODTRANSF; END IF;
    BEGIN
      DELETE LIVRVAL WHERE CODLIVRVAL = V_REC.CODLIVRVAL;
      DELETE LIVR1   WHERE CODLIVR1   = V_REC.CODLIVR1;
    EXCEPTION WHEN OTHERS THEN ERR := ERR + 1;
    END;
  END LOOP;
  COMMIT;
END;

FUNCTION GETCODFACTURALITIGIU(aCODOBLIGASOCIAT IN NUMBER) RETURN NUMBER IS
  RES  NUMBER(20);
  K    NUMBER(10) := 0;
  CO   NUMBER(10);
  TEMP NUMBER(10);
BEGIN
  CO := aCODOBLIGASOCIAT;
  k  := 0;
  WHILE K = 0
  LOOP
    BEGIN
      SELECT Coalesce(CODOBLIGASOCIAT, 0) INTO TEMP FROM OBLIGPIF WHERE CODOBLIGPIF = CO;
    EXCEPTION
      WHEN OTHERS THEN TEMP := -1;
    END;
    IF TEMP = -1 THEN RETURN 0; END IF;

    IF TEMP = 0 THEN
      K    := 1;
      RES  := CO;
    ELSE
      CO := TEMP;
    END IF;
  END LOOP;

  RETURN RES;
END;

PROCEDURE REZOLVA_LITIGII IS
  CODASOCINI      NUMBER(20);
  CODFACTURA      NUMBER(20);
BEGIN
  FOR V_REC IN (
    SELECT
      C.CODCOMPENS, S.CODSTINGERE,
      O_Sting.CODOBLIGPIF AS CODOBLIG_1350, O_Sting.CODGENERAL AS CODGENERAL_1350,
      O_Litig.CODOBLIGPIF AS CODOBLIG_1303, O_Litig.CODGENERAL AS CODGENERAL_1303,
      O_Litig.CODOBLIGASOCIAT,
      Coalesce(OL.REST, 0) AS RESTLITIGIU
    FROM COMPENS C
      INNER JOIN GENERAL      G_Sting ON G_Sting.CODDOC          = C.CODCOMPENS        AND G_Sting.SEMNIFICATIE = 1350
      INNER JOIN OBLIGPIF     O_Sting ON O_Sting.CODGENERAL      = G_Sting.CODGENERAL
      INNER JOIN STINGERE     S       ON S.CODSTINGATORPIF       = O_Sting.CODOBLIGPIF
      INNER JOIN OBLIGPIF     O_Litig ON O_Litig.CODOBLIGASOCIAT = S.CODSTINSPIF       AND O_Litig.SEMNIFICATIE = 1303
      INNER JOIN GENERAL      G_Litig ON G_Litig.CODGENERAL      = O_Litig.CODGENERAL  AND G_Litig.CODDOC = G_Sting.CODDOC
      LEFT  JOIN OBLIGPIFLUNA OL      ON OL.CODOBLIGPIF          = O_Litig.CODOBLIGPIF AND OL.AN = AN_INITIALIZARI AND OL.luna = LUNA_INITIALIZARI
    WHERE C.AN*12+C.LUNA &lt; AL_RUPERE
  ) LOOP
    IF V_REC.RESTLITIGIU &gt; 0 THEN
      CODASOCINI := Coalesce(V_REC.CODOBLIGASOCIAT, 0);
      CODFACTURA := Coalesce(GETCODFACTURALITIGIU(V_REC.CODOBLIGASOCIAT), 0);
      IF CODASOCINI &lt;&gt; CODFACTURA AND Coalesce(CODFACTURA, 0) &lt;&gt; 0 THEN
        UPDATE OBLIGPIF SET CODOBLIGASOCIAT = CODFACTURA                              WHERE CODOBLIGPIF = V_REC.CODOBLIG_1303;
        UPDATE STINGERE SET CODSTINSPIF     = CODFACTURA, VALOARE = V_REC.RESTLITIGIU WHERE CODSTINGERE = V_REC.CODSTINGERE;
        UPDATE OBLIGPIF SET                               VALOARE = V_REC.RESTLITIGIU WHERE CODOBLIGPIF = CODFACTURA;
      END IF;
    ELSE
      DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIG_1350;
      FOR V_REC_S IN (SELECT * FROM STINGERE WHERE CODSTINSPIF =  V_REC.CODOBLIG_1303)
      LOOP
        DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC_S.CODSTINGATORPIF;
        DELETE FROM STINGERE WHERE CODSTINSPIF = V_REC_S.CODSTINGERE;
      END LOOP;
      --DELETE FROM STINGERE WHERE CODSTINSPIF =  V_REC.CODOBLIG_1303;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIG_1303;
      DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL_1350;
      DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL_1303;
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE RECALCUL_LINIE_TVAINCASARE IS
  cSQL CLOB;
  vCNT NUMBER;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;07.AB&apos;,&apos;RECALCUL_LINIE_TVAINCASARE - CREATE TMP_RF_RLT_INTR&apos;);
  BEGIN
    DROP_TABLE(&apos;TMP_RF_RLT_INTR&apos;);
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;
  EXECUTE IMMEDIATE &apos;CREATE GLOBAL TEMPORARY TABLE TMP_RF_RLT_INTR (CODINTR NUMBER(20,0), VAL_OBLIG  NUMBER(20,7), REST NUMBER(20,7)) ON COMMIT PRESERVE ROWS&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;07.AC&apos;,&apos;RECALCUL_LINIE_TVAINCASARE - ANALIZA INTRARI&apos;);
  cSQL := &apos;INSERT INTO TMP_RF_RLT_INTR
  SELECT
     I.CODINTR,
     SUM(Coalesce(O.VALOARE,0)) AS VAL_OBLIG,
     CASE WHEN ABS(SUM(Coalesce(OL.REST,0))) &lt; 0.01 THEN 0 ELSE SUM(Coalesce(OL.REST,0)) END AS REST
  FROM INTRARI I
    INNER JOIN GENERAL      G  ON G.CODDOC       = I.CODINTR     AND G.TIPDOC = I.TIPDOC AND G.SEMNIFICATIE = 100
    INNER JOIN OBLIGPIF     O  ON O.CODGENERAL   = G.CODGENERAL
    LEFT  JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
  WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.TVAINCASARE = 1
  HAVING SUM(Coalesce(O.VALOARE,0)) &lt;&gt; 0
  GROUP BY I.CODINTR&apos;;

  EXECUTE IMMEDIATE cSQL;

  PKG_GLOBALS.PUT_INFO(&apos;07.AD&apos;,&apos;RECALCUL_LINIE_TVAINCASARE - ACTULIZARE INTRARI CU REST = 0&apos;);
  cSQL := &apos;UPDATE INTRARI1 SET TVA = 0, CANT = 1, PU = 0, PRETORIG = 0, COEFDISCMAJ = 1 WHERE CODINTR IN (SELECT CODINTR FROM TMP_RF_RLT_INTR WHERE REST = 0)&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;DELETE FROM TMP_RF_RLT_INTR WHERE REST = 0&apos;;
  EXECUTE IMMEDIATE cSQL;

  PKG_GLOBALS.PUT_INFO(&apos;07.AE&apos;,&apos;RECALCUL_LINIE_TVAINCASARE - ACTUALIZARE INTRARI CU REST &lt;&gt; 0&apos;);
  EXECUTE IMMEDIATE  &apos;SELECT count(1) FROM TMP_RF_RLT_INTR&apos; INTO vCNT;
  cSQL := &apos;DECLARE
    aVAL NUMBER(20,7);
    aTVA NUMBER(20,7);
  BEGIN
    FOR vRec IN (
      SELECT
        I1.CODINTR1,
        (Coalesce(I1.PU*I1.CANT,0) + Coalesce(TVA,0))* T.REST/T.VAL_OBLIG NewValLin,
        CASE WHEN Coalesce(I1.PU*I1.CANT,0) = 0 THEN 0 ELSE Coalesce(TVA,0)/Coalesce(I1.PU*I1.CANT,0) END ProcTVA
      FROM TMP_RF_RLT_INTR T LEFT JOIN INTRARI1 I1 ON I1.CODINTR = T.CODINTR
      WHERE T.REST &lt;&gt; 0 AND I1.CODINTR1 IS NOT NULL
    ) LOOP
      aVAL := vRec.NewValLin/(1 + vRec.ProcTVA);
      aTVA := vRec.NewValLin/(1 + vRec.ProcTVA) * vRec.ProcTVA;
      UPDATE INTRARI1 SET TVA = aTVA, CANT = 1, PU = aVAL, PRETORIG = aVAL, COEFDISCMAJ = 1 WHERE CODINTR1 = vRec.CODINTR1;
    END LOOP;
  END;&apos;;
  IF vCNT &gt; 0 THEN
    EXECUTE IMMEDIATE cSQL;
  END IF;

  PKG_GLOBALS.PUT_INFO(&apos;07.AF&apos;,&apos;RECALCUL_LINIE_TVAINCASARE - DROP TMP_RF_RLT_INTR&apos;);
  DROP_TABLE(&apos;TMP_RF_RLT_INTR&apos;);
  COMMIT;
END;

PROCEDURE RUPE_LEGATURI_ANTERIOARE IS
  cSQL CLOB;
BEGIN
  DROP_TABLE(&apos;RF_RLA&apos;);
  cSQL := &apos;CREATE TABLE RF_RLA (
    CODSTINGERE   NUMBER(20,0) NULL,
    CODOBLIGPIF   NUMBER(20,0) NULL,
    CODGENERAL    NUMBER(20,0) NULL,
    CODDOC        NUMBER(20,0) NULL,
    CODLITIGIU    NUMBER(20,0) NULL,
    RESTCEC       NUMBER(20,7) NULL,
    VALSTING      NUMBER(20,7) NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;

  -- RUPERE LEGATURI STINGERI ANTERIOARE LUNII DE RUPERE

  -- TREZOR
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_RLA (CODSTINGERE, CODOBLIGPIF, CODGENERAL, CODDOC, RESTCEC, VALSTING)
    SELECT
      S.CODSTINGERE, O_STING.CODOBLIGPIF, O_STING.CODGENERAL, T.CODTREZOR,
      CASE WHEN ABS(Coalesce(OL_CEC.REST, 0)) &lt; 0.01 THEN 0 ELSE OL_CEC.REST END AS RESTCEC,
      O_STING.VALOARE AS VALSTING
    FROM STINGERE S
      INNER JOIN RF_FSI_VALINI RF      ON RF.CODOBLIGPIF      = S.CODSTINSPIF
      LEFT JOIN OBLIGPIF       O_STING ON O_STING.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT JOIN GENERAL        G_STING ON G_STING.CODGENERAL  = O_STING.CODGENERAL
      LEFT JOIN GENERAL        G_CEC   ON G_CEC.CODDOC        = G_STING.CODDOC AND G_CEC.TIPDOC = 31 AND G_CEC.SEMNIFICATIE IN (500, 600)
      LEFT JOIN OBLIGPIF       O_CEC   ON O_CEC.CODGENERAL    = G_CEC.CODGENERAL
      LEFT JOIN OBLIGPIFLUNA   OL_CEC  ON OL_CEC.CODOBLIGPIF  = O_CEC.CODOBLIGPIF AND OL_CEC.AN = &apos;||AN_INITIALIZARI||&apos; AND OL_CEC.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
      LEFT JOIN TREZOR1        T1      ON T1.CODTREZOR1       = G_STING.CODDOC
      LEFT JOIN TREZOR         T       ON T.CODTREZOR         = T1.CODTREZOR
    WHERE G_STING.TIPDOC IN (29, 30, 31, 33)
      AND T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND T.OPERAT = 1&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM RF_RLA WHERE RESTCEC = 0)&apos;;
  EXECUTE IMMEDIATE &apos;DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_RLA WHERE RESTCEC = 0)&apos;;
  EXECUTE IMMEDIATE &apos;DELETE FROM GENERAL  WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM RF_RLA WHERE RESTCEC = 0)&apos;;
  --EXECUTE IMMEDIATE &apos;UPDATE STINGERE SET VALOARE = 0 WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM RF_RLA WHERE RESTCEC &lt;&gt; 0)&apos;;
  --EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF SET VALOARE = 0 WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_RLA WHERE RESTCEC &lt;&gt; 0)&apos;;
  EXECUTE IMMEDIATE &apos;MERGE INTO OBLIGPIF O USING (SELECT CODOBLIGPIF, VALSTING AS VALOARE FROM RF_RLA WHERE RESTCEC &lt;&gt; 0) RF ON (RF.CODOBLIGPIF = O.CODOBLIGPIF) WHEN MATCHED THEN UPDATE SET O.VALOARE = RF.VALOARE&apos;;
  EXECUTE IMMEDIATE &apos;MERGE INTO STINGERE S USING (SELECT CODSTINGERE, 0        AS VALOARE FROM RF_RLA WHERE RESTCEC &lt;&gt; 0) RF ON (RF.CODSTINGERE = S.CODSTINGERE) WHEN MATCHED THEN UPDATE SET S.VALOARE = RF.VALOARE&apos;;

  EXECUTE IMMEDIATE &apos;UPDATE TREZOR SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODTREZOR IN (SELECT CODDOC FROM RF_RLA)&apos;;
  COMMIT;

  -- COMPENS
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_RLA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_RLA (CODSTINGERE, CODOBLIGPIF, CODGENERAL, CODDOC, CODLITIGIU)
    SELECT S.CODSTINGERE, O_STING.CODOBLIGPIF, O_STING.CODGENERAL, C.CODCOMPENS, Coalesce(O_LIT.CODOBLIGPIF, 0) AS CODLITIGIU
    FROM STINGERE S
      INNER JOIN RF_FSI_VALINI RF ON RF.CODOBLIGPIF      = S.CODSTINSPIF
      LEFT JOIN OBLIGPIF O_STING  ON O_STING.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT JOIN GENERAL  G        ON G.CODGENERAL        = O_STING.CODGENERAL
      LEFT JOIN COMPENS  C        ON C.CODCOMPENS        = G.CODDOC
      LEFT JOIN OBLIGPIF O_FACT   ON O_FACT.CODOBLIGPIF  = S.CODSTINSPIF AND O_FACT.SEMNIFICATIE = 200
      LEFT JOIN OBLIGPIF O_LIT    ON Coalesce(O_LIT.CODOBLIGASOCIAT, 0) &lt;&gt; 0
                                 AND Coalesce(O_LIT.CODOBLIGASOCIAT, 0) = Coalesce(O_FACT.CODOBLIGPIF, 0)
                                 AND O_LIT.REST &lt;&gt; 0 AND ROWNUM = 1
    WHERE G.TIPDOC IN (28)
      AND C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM RF_RLA WHERE CODLITIGIU = 0)&apos;;
  EXECUTE IMMEDIATE &apos;DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_RLA WHERE CODLITIGIU = 0)&apos;;
  EXECUTE IMMEDIATE &apos;DELETE FROM GENERAL  WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM RF_RLA WHERE CODLITIGIU = 0)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE COMPENS SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODCOMPENS IN (SELECT CODDOC FROM RF_RLA)&apos;;
  COMMIT;

  -- STORNO AVANS FACT INTRARI
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_RLA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_RLA (CODSTINGERE, CODOBLIGPIF, CODGENERAL, CODDOC)
    SELECT S.CODSTINGERE, O_STING.CODOBLIGPIF, O_STING.CODGENERAL, I.CODINTR
    FROM STINGERE S
      INNER JOIN RF_FSI_VALINI RF      ON RF.CODOBLIGPIF      = S.CODSTINSPIF
      LEFT JOIN OBLIGPIF       O_STING ON O_STING.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT JOIN GENERAL        G       ON G.CODGENERAL        = O_STING.CODGENERAL
      LEFT JOIN INTRARI        I       ON I.CODINTR           = G.CODDOC
    WHERE G.SEMNIFICATIE IN (111)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE STINGERE SET VALOARE = 0           WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF SET VALOARE = 0, REST = 0 WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE GENERAL  SET TVA = 0               WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI  SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODINTR IN (SELECT CODDOC FROM RF_RLA)&apos;;
  COMMIT;

  -- STORNO AVANS FACT IESIRI
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_RLA&apos;;

  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_RLA (CODSTINGERE, CODOBLIGPIF, CODGENERAL, CODDOC)
    SELECT S.CODSTINGERE, O_STING.CODOBLIGPIF, O_STING.CODGENERAL, I.CODIES
    FROM STINGERE S
      INNER JOIN RF_FSI_VALINI RF      ON RF.CODOBLIGPIF      = S.CODSTINSPIF
      LEFT JOIN OBLIGPIF       O_STING ON O_STING.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT JOIN GENERAL        G       ON G.CODGENERAL        = O_STING.CODGENERAL
      LEFT JOIN IESIRI         I       ON I.CODIES            = G.CODDOC
    WHERE G.SEMNIFICATIE IN (211)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE STINGERE SET VALOARE = 0           WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF SET VALOARE = 0, REST = 0 WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE GENERAL  SET TVA = 0               WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM RF_RLA)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI   SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODIES IN (SELECT CODDOC FROM RF_RLA)&apos;;
  COMMIT;

  DROP_TABLE(&apos;RF_RLA&apos;);
END;

PROCEDURE FIXEAZA_INITILIZARE_SOLDURI IS
  cSQL CLOB;
BEGIN
  DROP_TABLE(&apos;RF_FSI_VALINI&apos;);
  cSQL := &apos;CREATE TABLE RF_FSI_VALINI (
    CODOBLIGPIF   NUMBER(20,0) NULL,
    CODDOC        NUMBER(20,0) NULL,
    VALOAREINI    NUMBER(20,7) NULL
  ) NOLOGGING TABLESPACE WMDATA&apos;;
  EXECUTE IMMEDIATE cSQL;

  cSQL := &apos;CREATE INDEX IDX_RF_FSI_VALINI ON RF_FSI_VALINI (CODOBLIGPIF)&apos;;
  EXECUTE IMMEDIATE cSQL;

  PKG_GLOBALS.PUT_INFO(&apos;08.BA&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN INTRARI&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, I.CODINTR, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (100, 140)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI    SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODINTR     IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BB&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN AVANSURI PE FACTURI INTRARI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, I.CODINTR, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (110)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE -- actualizare TVA aferent OBLIGPIF ce urmeaza a fi modificate
   &apos;MERGE INTO GENERAL G
    USING (
      SELECT G.CODGENERAL, CASE WHEN SUM(O.VALOARE) = 0 THEN 0 ELSE Max(G.TVA) * SUM(VALOAREINI) / SUM(O.VALOARE) END TVA
      FROM RF_FSI_VALINI RF
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = RF.CODOBLIGPIF
        INNER JOIN GENERAL  G ON G.CODGENERAL  = O.CODGENERAL
      WHERE G.TVA &lt;&gt; 0 AND G.SEMNIFICATIE = 110
      GROUP BY G.CODGENERAL
    ) xG ON (xG.CODGENERAL = G.CODGENERAL)
    WHEN MATCHED THEN UPDATE SET G.TVA = xG.TVA&apos;;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI    SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODINTR     IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BC&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN DVI-URI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, I.CODINTR, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (130)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI    SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODINTR     IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BD&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN IESIRI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, I.CODIES, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN IESIRI I  ON  I.CODIES = G.CODDOC
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (200, 240)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI     SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODIES      IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BE&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN AVANSURI PE FACTURI IESIRI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, I.CODIES, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN IESIRI  I ON I.CODIES = G.CODDOC
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (210)
      AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE -- actualizare TVA aferent OBLIGPIF ce urmeaza a fi modificate
   &apos;MERGE INTO GENERAL G
    USING (
      SELECT G.CODGENERAL, CASE WHEN SUM(O.VALOARE) = 0 THEN 0 ELSE Max(G.TVA) * SUM(VALOAREINI) / SUM(O.VALOARE) END TVA
      FROM RF_FSI_VALINI RF
        INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = RF.CODOBLIGPIF
        INNER JOIN GENERAL  G ON G.CODGENERAL  = O.CODGENERAL
      WHERE G.TVA &lt;&gt; 0 AND G.SEMNIFICATIE = 210
      GROUP BY G.CODGENERAL
    ) xG ON (xG.CODGENERAL = G.CODGENERAL)
    WHEN MATCHED THEN UPDATE SET G.TVA = xG.TVA&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI     SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODIES      IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BF&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN TRANZACTII CASA/BANCA (PLATI/INCASARI AVANS)&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    -- plati in avans = 310, incasari in avans = 410
    SELECT O.CODOBLIGPIF, T.CODTREZOR, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL      G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN TREZOR1      T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT JOIN TREZOR       T  ON T.CODTREZOR   = T1.CODTREZOR
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600)
      AND G.TIPDOC IN (29, 30, 31, 33)
      AND T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND ((T1.INITIALIZARI = 1)OR(Coalesce(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE TREZOR     SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODTREZOR   IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE
   &apos;MERGE INTO TREZOR1 T1
    USING (
      SELECT T1.CODTREZOR1, RF.VALOAREINI
      FROM OBLIGPIF O
        INNER JOIN RF_FSI_VALINI RF ON RF.CODOBLIGPIF = O.CODOBLIGPIF
        INNER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      WHERE O.SEMNIFICATIE IN (500, 600)
    ) xTAB ON (xTAB.CODTREZOR1 = T1.CODTREZOR1)
    WHEN MATCHED THEN UPDATE SET T1.VALDOC = xTAB.VALOAREINI&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BG&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN NOTE CONTABILE&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, N.CODNC, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      LEFT JOIN GENERAL      G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN NC1          N1 ON N1.CODNC1 = G.CODDOC
      LEFT JOIN NC           N  ON N.CODNC = N1.CODNC
      LEFT JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE O.SEMNIFICATIE IN (1200, 1201, 1250, 1251)
      AND N.AN*12+N.LUNA &lt; &apos;||sAL_RUPERE||&apos;&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE NC         SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODNC       IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE NC1        SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODNC       IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.BG&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE OBLIGATII DE STINS PROVENITE DIN COMPENSARI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE RF_FSI_VALINI&apos;;
  --SCOS 1303 -&gt; sunt facute separat in REZOLVA_LITIGII
  cSQL := &apos;INSERT /*+ APPEND */ INTO RF_FSI_VALINI (CODOBLIGPIF, CODDOC, VALOAREINI)
    SELECT O.CODOBLIGPIF, C.CODCOMPENS, CASE WHEN ABS(Coalesce(OL.REST, 0)) &lt; 0.01 THEN 0 ELSE OL.REST END AS ValoareIni
    FROM OBLIGPIF O
      INNER JOIN GENERAL      G  ON G.CODGENERAL   = O.CODGENERAL
      LEFT  JOIN COMPENS      C  ON C.CODCOMPENS   = G.CODDOC
      LEFT  JOIN OBLIGPIFLUNA OL ON OL.CODOBLIGPIF = O.CODOBLIGPIF AND OL.AN = &apos;||AN_INITIALIZARI||&apos; AND OL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
    WHERE G.TIPDOC = 28
      AND O.SEMNIFICATIE IN (1301, 1351)
      AND C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos;&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  EXECUTE IMMEDIATE &apos;UPDATE OBLIGPIF O SET VALOARE = (SELECT VALOAREINI FROM RF_FSI_VALINI RF WHERE RF.CODOBLIGPIF = O.CODOBLIGPIF) WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM RF_FSI_VALINI)&apos;;
  EXECUTE IMMEDIATE &apos;UPDATE COMPENS    SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos;                               WHERE CODCOMPENS  IN (SELECT CODDOC      FROM RF_FSI_VALINI)&apos;;
  COMMIT;
  RUPE_LEGATURI_ANTERIOARE;

  PKG_GLOBALS.PUT_INFO(&apos;08.CA&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI ACTUALIZARE  AN, LUNA TREZOR1&apos;);
  UPDATE TREZOR1 T1 SET (AN, LUNA) = (SELECT T.AN, T.LUNA FROM TREZOR T WHERE T.CODTREZOR = T1.CODTREZOR);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;08.DA&apos;,&apos;FIXEAZA_INITILIZARE_SOLDURI REFACERE SOLDINI&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE SOLDINI&apos;;
  PKG_REMAKE_SEQUENCES.REVAL_SEQUENCE(&apos;SOLDINI&apos;,&apos;CODSOLDINI&apos;,&apos;SEQ_SOLDINI_CODSOLDINI&apos;,TRUE);

  INSERT INTO SOLDINI(CODSOLDINI, CODPART)
  SELECT SEQ_SOLDINI_CODSOLDINI.NEXTVAL, CODPART
  FROM (
    SELECT DISTINCT CODPART
    FROM NPARTSOLDLUNA
    WHERE AN = AN_INITIALIZARI AND LUNA = LUNA_INITIALIZARI AND (Coalesce(SOLDLEI, 0) &lt;&gt; 0 OR Coalesce(SOLDVALUTA, 0) &lt;&gt; 0)
  );
  COMMIT;
END;

PROCEDURE FIXEAZA_AVIZINT_INITIAL IS
  cSQL CLOB;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;09.BA&apos;,&apos;FIXEAZA_AVIZINT_INITIAL CURATENIE TMP NECESARE&apos;);
  CREATE_TMP_RF_FAI_AE1;
  CREATE_TMP_RF_FAI_FAE1;

  PKG_GLOBALS.PUT_INFO(&apos;09.BB&apos;,&apos;FIXEAZA_AVIZINT_INITIAL POPULARE TMP_RF_FAI_AE1&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_FAI_AE1
  SELECT I1.CODINTR1, I.CODINTR, Coalesce(I1.CANT, 0), CASE WHEN ABS(Coalesce(AL.REST, 0)) &lt; 0.01 THEN 0 ELSE AL.REST END AS ValoareIni
  FROM INTRARI I
    INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
    LEFT  JOIN AVIZINTLUNA AL ON AL.CODINTR1 = I1.CODINTR1 AND AL.AN = &apos;||AN_INITIALIZARI||&apos; AND AL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
  WHERE I.TIPDOC = 2 AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;09.BC&apos;,&apos;FIXEAZA_AVIZINT_INITIAL UPDATE INTRARI1 CANT = 0&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI1 SET TVA = 0, CANT = 0, RESTFACT = 0 WHERE CODINTR1 IN (SELECT CODI1 FROM TMP_RF_FAI_AE1 WHERE REST = 0 AND CANT &lt;&gt; 0)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;09.BD&apos;,&apos;FIXEAZA_AVIZINT_INITIAL UPDATE INTRARI1 CANT &lt;&gt; 0&apos;);
  cSQL := &apos;UPDATE INTRARI1 I1
  SET (       TVA,                                                                   CANT,    RESTFACT) =
      (SELECT CASE WHEN I1.CANT = 0 THEN 0 ELSE ROUND(I1.TVA*AL.REST/I1.CANT,2) END, AL.REST, AL.REST FROM AVIZINTLUNA AL WHERE AL.CODINTR1 = I1.CODINTR1 AND AL.AN = &apos;||AN_INITIALIZARI||&apos; AND AL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;)
  WHERE I1.CODINTR1 IN (SELECT CODI1 FROM TMP_RF_FAI_AE1 WHERE REST &lt;&gt; 0 AND REST &lt;&gt; CANT)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;09.BE&apos;,&apos;FIXEAZA_AVIZINT_INITIAL UPDATE INTRARI&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODINTR IN (SELECT DISTINCT CODI FROM TMP_RF_FAI_AE1)&apos;;
  COMMIT;

  -- RUPERE LEGATURI STINGERI ANTERIOARE LUNII DE RUPERE
  PKG_GLOBALS.PUT_INFO(&apos;09.CA&apos;,&apos;FIXEAZA_AVIZINT_INITIAL POPULARE TMP_RF_FAI_FAE1&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_FAI_FAE1
  SELECT DISTINCT I1.CODINTR1, I.CODINTR
  FROM TMP_RF_FAI_AE1 TMP
    INNER JOIN INTRLINK IL ON IL.CODLINIEAVIZ = TMP.CODI1
    INNER JOIN INTRARI1 I1 ON I1.CODINTR1     = IL.CODINTR1
    INNER JOIN INTRARI  I  ON I.CODINTR       = I1.CODINTR
  WHERE I.TIPDOC = 9 AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  --PKG_GLOBALS.PUT_INFO(&apos;09.CB&apos;,&apos;FIXEAZA_AVIZINT_INITIAL DELETE FROM INTRLINK&apos;);
  --EXECUTE IMMEDIATE &apos;DELETE FROM INTRLINK WHERE CODINTR1 IN (SELECT DISTINCT CODI1 FROM TMP_RF_FAI_FAE1)&apos;;
  --COMMIT;
  --FIXEAZA_INITILIZARE_COMENZI legaturile cu comenzile au fost sterse asa ca pastrez doar legaturi ulterioare lunii de rupere
  PKG_GLOBALS.PUT_INFO(&apos;09.CB&apos;,&apos;COPY_TRUNC_COPY_KEEP - INTRLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT IL.CODINTR1
  FROM INTRLINK IL
    INNER JOIN INTRARI1 I1 ON IL.CODINTR1 = I1.CODINTR1
    INNER JOIN INTRARI  I  ON I1.CODINTR  = I.CODINTR
  WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE;
  COMMIT;
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;INTRLINK&apos;, &apos;CODINTR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;09.CC&apos;,&apos;FIXEAZA_AVIZINT_INITIAL DELETE FROM CHELTAVANS&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM CHELTAVANS WHERE CODINTR1 IN (SELECT DISTINCT CODI1 FROM TMP_RF_FAI_FAE1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;09.CD&apos;,&apos;FIXEAZA_AVIZINT_INITIAL DELETE CU COPY/TRUNCATE FROM INTRARI1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;INTRARI1&apos;, &apos;CODINTR1&apos;, &apos;TMP_RF_FAI_FAE1&apos;, &apos;CODI1&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI1 SET CANT = 0 WHERE CODINTR1 IN (SELECT CODI1 FROM TMP_RF_FAI_FAE1)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;09.CE&apos;,&apos;FIXEAZA_AVIZINT_INITIAL UPDATE INTRARI&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE INTRARI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODINTR IN (SELECT DISTINCT CODI FROM TMP_RF_FAI_FAE1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;09.DA&apos;,&apos;FIXEAZA_AVIZINT_INITIAL CURATA TMP&apos;);
  DROP_TABLE(&apos;TMP_RF_FAI_AE1&apos;);
  DROP_TABLE(&apos;TMP_RF_FAI_FAE1&apos;);
END;

PROCEDURE FIXEAZA_AVIZIES_INITIAL IS
  cSQL     CLOB;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;10.BA&apos;,&apos;FIXEAZA_AVIZIES_INITIAL CURATENIE TMP NECESARE&apos;);
  CREATE_TMP_RF_FAI_AE1;
  CREATE_TMP_RF_FAI_FAE1;

  PKG_GLOBALS.PUT_INFO(&apos;10.BB&apos;,&apos;FIXEAZA_AVIZIES_INITIAL POPULARE TMP_RF_FAI_AE1&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_FAI_AE1
  SELECT I1.CODIES1, I.CODIES, Coalesce(I1.CANT, 0), Coalesce(AL.REST, 0)
  FROM IESIRI I
    INNER JOIN IESIRI1 I1 ON I1.CODIES = I.CODIES
    LEFT  JOIN AVIZIESLUNA AL ON AL.CODIES1 = I1.CODIES1 AND AL.AN = &apos;||AN_INITIALIZARI||&apos; AND AL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;
  WHERE I.TIPDOC = 20 AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;10.BC&apos;,&apos;FIXEAZA_AVIZIES_INITIAL UPDATE IESIRI1 CANT = 0&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI1 SET TVA = 0, CANT = 0, RESTFACT = 0 WHERE CODIES1 IN (SELECT CODI1 FROM TMP_RF_FAI_AE1 WHERE REST = 0 AND CANT &lt;&gt; 0)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;10.BD&apos;,&apos;FIXEAZA_AVIZIES_INITIAL UPDATE IESIRI1 CANT &lt;&gt; 0&apos;);
  cSQL := &apos;UPDATE IESIRI1 I1
  SET (       TVA,                                                                CANT,    RESTFACT) =
      (SELECT CASE WHEN I1.CANT = 0 THEN 0 ELSE ROUND(I1.TVA*AL.REST/I1.CANT,2) END, AL.REST, AL.REST FROM AVIZIESLUNA AL WHERE AL.CODIES1 = I1.CODIES1 AND AL.AN = &apos;||AN_INITIALIZARI||&apos; AND AL.LUNA = &apos;||LUNA_INITIALIZARI||&apos;)
  WHERE I1.CODIES1 IN (SELECT CODI FROM TMP_RF_FAI_AE1 WHERE REST &lt;&gt; 0 AND REST &lt;&gt; CANT)&apos;;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;10.BE&apos;,&apos;FIXEAZA_AVIZIES_INITIAL UPDATE IESIRI&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODIES IN (SELECT DISTINCT CODI FROM TMP_RF_FAI_AE1)&apos;;
  COMMIT;

  -- RUPERE LEGATURI STINGERI  ANTERIOARE LUNII DE RUPERE
  PKG_GLOBALS.PUT_INFO(&apos;10.CA&apos;,&apos;FIXEAZA_AVIZIES_INITIAL POPULARE TMP_RF_FAI_FAE1&apos;);
  cSQL := &apos;INSERT /*+ APPEND */ INTO TMP_RF_FAI_FAE1
  SELECT DISTINCT I1.CODIES1, I.CODIES
  FROM TMP_RF_FAI_AE1 TMP
    INNER JOIN IESLINK IL ON IL.CODLINIEAVIZ = TMP.CODI1
    INNER JOIN IESIRI1 I1 ON I1.CODIES1     = IL.CODIES1
    INNER JOIN IESIRI  I  ON I.CODIES       = I1.CODIES
  WHERE I.TIPDOC = 26 AND I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE;
  EXECUTE IMMEDIATE cSQL;
  COMMIT;

  --PKG_GLOBALS.PUT_INFO(&apos;10.CB&apos;,&apos;FIXEAZA_AVIZIES_INITIAL DELETE FROM IESLINK&apos;);
  --EXECUTE IMMEDIATE &apos;DELETE FROM IESLINK WHERE CODIES1 IN (SELECT CODI1 FROM TMP_RF_FAI_FAE1)&apos;;
  --COMMIT;
  --FIXEAZA_INITILIZARE_COMENZI legaturile cu comenzile au fost sterse asa ca pastrez doar legaturi ulterioare lunii de rupere
  PKG_GLOBALS.PUT_INFO(&apos;10.CB&apos;,&apos;COPY_TRUNC_COPY_KEEP - IESLINK&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT IL.CODIES1
  FROM IESLINK IL
    INNER JOIN IESIRI1 I1 ON IL.CODIES1 = I1.CODIES1
    INNER JOIN IESIRI  I  ON I1.CODIES = I.CODIES
  WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE;
  COMMIT;
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;IESLINK&apos;, &apos;CODIES1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;10.CC&apos;,&apos;FIXEAZA_AVIZIES_INITIAL DELETE FROM IESIRI1&apos;);
  EXECUTE IMMEDIATE &apos;DELETE FROM IESIRI1 WHERE CODIES1 IN (SELECT CODI1 FROM TMP_RF_FAI_FAE1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;10.CD&apos;,&apos;FIXEAZA_AVIZIES_INITIAL UPDATE IESIRI&apos;);
  EXECUTE IMMEDIATE &apos;UPDATE IESIRI SET AN = &apos;||AN_INITIALIZARI||&apos;, LUNA = &apos;||LUNA_INITIALIZARI||&apos; WHERE CODIES IN (SELECT DISTINCT CODI FROM TMP_RF_FAI_FAE1)&apos;;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;10.DA&apos;,&apos;FIXEAZA_AVIZIES_INITIAL CURATA TMP&apos;);
  DROP_TABLE(&apos;TMP_RF_FAI_AE1&apos;);
  DROP_TABLE(&apos;TMP_RF_FAI_FAE1&apos;);
END;

PROCEDURE SETEAZA_VALORI_FIRMALUNI IS
  vAC NUMBER(4);
  vLC NUMBER(2);
  vAB NUMBER(4);
  vLB NUMBER(2);
BEGIN
  SELECT ANCURENT, LUNACURENTA, ANBLOCAT, LUNABLOCATA INTO vAC, vLC, vAB, vLB  FROM FIRMALUNI;
  IF vAC*12+vLC &lt; AL_RUPERE THEN
    vAC := AN_RUPERE;
    vLC := LUNA_RUPERE;
  END IF;
  IF vAB*12+vLB &lt; AL_RUPERE THEN
    vAB := NULL;
    vLB := NULL;
  END IF;
  UPDATE FIRMALUNI
  SET ANCURENT  = vAC,       LUNACURENTA  = vLC,
      ANINITIAL = AN_RUPERE, LUNAINITIALA = LUNA_RUPERE,
      ANBLOCAT  = vAB,       LUNABLOCATA  = vLB;
  COMMIT;
END;

PROCEDURE  SET_RESTTVA IS
BEGIN
  FOR V_REC IN (
    SELECT G.CODGENERAL, OL.RESTTVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNEr JOIN GENERAL  G ON G.CODGENERAL = O.CODGENERAL
   WHERE OL.AN *12+OL.LUNA = AL_INITIALIZARI
     AND O.SEMNIFICATIE IN (310, 410)
  ) LOOP
    UPDATE GENERAL SET TVA = Coalesce(V_REC.RESTTVA, 0) WHERE CODGENERAL = V_REC.CODGENERAL;
  END LOOP;
  COMMIT;
END;

PROCEDURE CURATA_LIVR1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODLIVR1 FROM LIVR1 L1 INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR INNER JOIN INTRARI I ON I.CODINTR   = L.CODINTR   AND I.TIPDOC = L.TIPLIVR WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE UNION ALL
  SELECT CODLIVR1 FROM LIVR1 L1 INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR INNER JOIN TRANSF  T ON T.CODTRANSF = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR WHERE T.AN*12+T.LUNA &gt;= AL_RUPERE UNION ALL
  SELECT CODLIVR1 FROM LIVR1 L1 INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR INNER JOIN IESIRI  E ON E.CODIES    = L.CODIES    AND E.TIPDOC = L.TIPLIVR WHERE E.AN*12+E.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.BB&apos;,&apos;COPY_TRUNC_COPY_KEEP LIVRVAL&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LIVRVAL&apos;, &apos;CODLIVR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.BC&apos;,&apos;COPY_TRUNC_COPY_KEEP LIVR1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LIVR1&apos;  , &apos;CODLIVR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_NIRSTOC IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT NS.CODNIRSTOC
  FROM NIRSTOC NS
    INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
    LEFT  JOIN IOART1  IO ON IO.CODIOART   = NS.CODIOART   AND AL_RUPERE BETWEEN IO.ALSTART AND IO.ALSTOP
    LEFT  JOIN INTRARI I  ON I.CODINTR     = N.CODINTR     AND I.TIPDOC = N.TIPNIR
    LEFT  JOIN TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF   AND T.TIPDOC = N.TIPNIR
    LEFT  JOIN IESIRI  E  ON E.CODIES      = N.CODIES      AND E.TIPDOC = N.TIPNIR
    LEFT  JOIN NIRLUNA NL ON NL.CODNIRSTOC = NS.CODNIRSTOC AND NL.AN = AN_INITIALIZARI AND NL.LUNA = LUNA_INITIALIZARI
  WHERE Coalesce(I.AN,T.AN,E.AN)*12+Coalesce(I.LUNA,T.LUNA,E.LUNA) &lt; AL_RUPERE
    AND Coalesce(IO.MG, 0) &lt;&gt; 5
    AND Coalesce(NL.REST, 0) = 0
    AND NOT EXISTS (SELECT 1 FROM LIVR1 L1 WHERE L1.CODNIRSTOC = NS.CODNIRSTOC);
  COMMIT;

  --NIRLUNA -&gt; SE CURATA ULTERIOR IN STERGE_FIXARI_LUNARE_ANTER

  PKG_GLOBALS.PUT_INFO(&apos;13.CB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE NIRSER&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;NIRSER&apos;, &apos;CODNIRSTOC&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.CC&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE NIRSTOC&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;NIRSTOC&apos;, &apos;CODNIRSTOC&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_OBLIGPIF IS
  cSQL  CLOB;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;13.DB&apos;,&apos;CURATA OBLIGPIF - CREATE TMP_RF_CO_OG&apos;);
  BEGIN
    DROP_TABLE(&apos;TABLE TMP_RF_CO_OG&apos;);
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  EXECUTE IMMEDIATE &apos;CREATE GLOBAL TEMPORARY TABLE TMP_RF_CO_OG (CODOBLIGPIF NUMBER(20,0), CODGENERAL  NUMBER(20,0)) ON COMMIT PRESERVE ROWS&apos;;
  EXECUTE IMMEDIATE &apos;CREATE INDEX  IDX_TMP_RF_CO_OG_CODOBLIGPIF ON TMP_RF_CO_OG(CODOBLIGPIF)&apos;;
  EXECUTE IMMEDIATE &apos;CREATE INDEX  IDX_TMP_RF_CO_OG_CODGENERAL  ON TMP_RF_CO_OG(CODGENERAL)&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;13.DC&apos;,&apos;CURATA OBLIGPIF - ANALIZA DE STERS&apos;);
  cSQL := &apos;
  INSERT INTO TMP_RF_CO_OG ( CODOBLIGPIF, CODGENERAL)
  SELECT CODOBLIGPIF, CODGENERAL
  FROM (
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- ANTERIOARE RUPERI FARA SOLD SI REFERINTE IN STINGERE
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.SEMNIFICATIE IN (100, 140)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- AVANSURI PE FACTURA INTRARI
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos; AND I.OPERAT = 1 AND I.ANULAT = 0 AND O.SEMNIFICATIE IN (110)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- DE STINS PROVENITE DIN DVI-URI
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.SEMNIFICATIE IN (130)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- DE STINS PROVENITE DIN IESIRI
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN IESIRI I  ON I.CODIES     = G.CODDOC
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.SEMNIFICATIE IN (200, 240)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- AVANSURI PE FACTURA IESIRI
    FROM OBLIGPIF O
       LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
       LEFT JOIN IESIRI I  ON  I.CODIES = G.CODDOC
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.SEMNIFICATIE IN (210)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- MONETARE
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN IESIRI I  ON I.CODIES     = G.CODDOC
    WHERE I.AN*12+I.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND G.TIPDOC = 16
      AND O.SEMNIFICATIE IN (400)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- DE STINS PROVENITE DIN TRANZACTII CASA/BANCA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE T.AN*12+T.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND ((T1.INITIALIZARI = 1) OR (Coalesce(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))
      AND G.TIPDOC IN (29, 30, 31, 33)
      AND O.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600, 900, 950)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- DE STINS PROVENITE DIN COMPENSARI
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
    WHERE C.AN*12+C.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND O.SEMNIFICATIE IN (1301, 1303, 1351, 1302)
    UNION ALL
    SELECT G.TIPDOC, O.CODOBLIGPIF, O.CODGENERAL, O.VALOARE, O.SEMNIFICATIE -- DE STINS PROVENITE DIN NC
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL AND G.TIPDOC = 35
      LEFT JOIN NC1       ON NC1.CODNC1   = G.CODDOC
      LEFT JOIN NC        ON NC.CODNC     = NC1.CODNC
    WHERE NC.AN*12+NC.LUNA &lt; &apos;||sAL_RUPERE||&apos;
      AND O.SEMNIFICATIE IN (1200, 1201, 1250, 1251)
  ) A
  WHERE ((A.VALOARE = 0) OR (A.SEMNIFICATIE IN (900, 950, 1302)) OR A.TIPDOC IN (16))
    AND NOT EXISTS (SELECT 1 FROM STINGERE S WHERE S.CODSTINSPIF     = A.CODOBLIGPIF)
    AND NOT EXISTS (SELECT 1 FROM OBLIGPIF O WHERE O.CODOBLIGASOCIAT = A.CODOBLIGPIF)&apos;;
  EXECUTE IMMEDIATE cSQL;

  PKG_GLOBALS.PUT_INFO(&apos;13.DC&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE OBLIGPIF&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;OBLIGPIF&apos;, &apos;CODOBLIGPIF&apos;, &apos;TMP_RF_CO_OG&apos;, &apos;CODOBLIGPIF&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.DD&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE GENERAL&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;GENERAL&apos;, &apos;CODGENERAL&apos;, &apos;TMP_RF_CO_OG&apos;, &apos;CODGENERAL&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.DF&apos;,&apos;CURATA OBLIGPIF - DROP TMP_RF_CO_OG&apos;);
  DROP_TABLE(&apos;TMP_RF_CO_OG&apos;);
END;

PROCEDURE CURATA_INTRARI1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I1.CODINTR1
  FROM INTRARI1 I1 INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND Coalesce(I.TVAINCASARE, 0) = 0
    AND I.TIPDOC = 2 AND I1.CANT = 0
    AND NOT EXISTS (SELECT 1 FROM NIRSTOC      NS WHERE NS.CODINTR1    = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRLINK     L  WHERE L.CODLINIEAVIZ = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRPRODLINK L  WHERE L.CODINTR1     = I1.CODINTR1)
  UNION ALL
  SELECT I1.CODINTR1
  FROM INTRARI1 I1 INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND Coalesce(I.TVAINCASARE, 0) = 0
    AND I.TIPDOC &lt;&gt; 2
    AND NOT EXISTS (SELECT 1 FROM NIRSTOC      NS WHERE NS.CODINTR1 = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRLINK     L  WHERE L.CODINTR1  = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRPRODLINK L  WHERE L.CODINTR1  = I1.CODINTR1)
  UNION ALL
  SELECT I1.CODINTR1
  FROM INTRARI1 I1 INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND Coalesce(I.TVAINCASARE, 0) = 1
    AND I1.PU = 0 AND I1.CANT = 1
    AND NOT EXISTS (SELECT 1 FROM GENERAL      G  WHERE G.TIPDOC    = I.CODINTR   AND G.TIPDOC = I.TIPDOC)
    AND NOT EXISTS (SELECT 1 FROM NIRSTOC      NS WHERE NS.CODINTR1 = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRLINK     L  WHERE L.CODINTR1  = I1.CODINTR1)
    AND NOT EXISTS (SELECT 1 FROM INTRPRODLINK L  WHERE L.CODINTR1  = I1.CODINTR1);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.EB&apos;,&apos;CURATA INTRARI1 - DELETE FROM CHELTAVANS&apos;);
  DELETE FROM CHELTAVANS C WHERE EXISTS (SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = C.CODINTR1);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.EC&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE INTRARI1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;INTRARI1&apos;, &apos;CODINTR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.ED&apos;,&apos;COPY_TRUNC_COPY_KEEP -&gt; INTRLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;INTRLINK&apos;    , &apos;CODINTR1&apos;, &apos;INTRARI1&apos;, &apos;CODINTR1&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.EE&apos;,&apos;COPY_TRUNC_COPY_KEEP -&gt;  INTRPRODLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;INTRPRODLINK&apos;, &apos;CODINTR1&apos;, &apos;INTRARI1&apos;, &apos;CODINTR1&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_IESIRI1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I1.CODIES1
  FROM IESIRI1 I1 INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND Coalesce(I.TVAINCASARE, 0) = 0
    AND I.TIPDOC = 20 AND I1.CANT = 0
    AND NOT EXISTS (SELECT 1 FROM IESLINK     L WHERE L.CODLINIEAVIZ = I1.CODIES1)
    AND NOT EXISTS (SELECT 1 FROM IESPRODLINK L WHERE L.CODIES1      = I1.CODIES1)
  UNION ALL
  SELECT I1.CODIES1
  FROM IESIRI1 I1 INNER JOIN IESIRI I ON I.CODIES = I1.CODIES
  WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND Coalesce(I.TVAINCASARE, 0) = 0
    AND I.TIPDOC &lt;&gt; 20
    AND NOT EXISTS (SELECT 1 FROM IESPRODLINK L WHERE L.CODIES1      = I1.CODIES1);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.FB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE -&gt; IESIRI1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;IESIRI1&apos; , &apos;CODIES1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.FC&apos;,&apos;COPY_TRUNC_COPY_KEEP -&gt;  IESLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;IESLINK&apos;    , &apos;CODIES1&apos;, &apos;IESIRI1&apos;, &apos;CODIES1&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.FD&apos;,&apos;COPY_TRUNC_COPY_KEEP -&gt;  IESPRODLINK&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;IESPRODLINK&apos;, &apos;CODIES1&apos;, &apos;IESIRI1&apos;, &apos;CODIES1&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_CARNETEDOC IS
 NR    NUMBER(10) := 0;
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODCARNET
  FROM DOCCARNETE DC
  WHERE FREENR = 0
    AND NOT EXISTS (SELECT 1 FROM IESIRI  D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM COMANDA D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM TRANSF  D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM COMPENS D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM NC      D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM TREZOR1 D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM PACHETE D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM OFERTA  D WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND D.CARNETDOC = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM LIVR L INNER JOIN IESIRI  D ON L.CODIES    = D.CODIES    AND L.TIPLIVR = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND L.CARNETLIVR = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM LIVR L INNER JOIN TRANSF  D ON L.CODTRANSF = D.CODTRANSF AND L.TIPLIVR = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND L.CARNETLIVR = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM LIVR L INNER JOIN INTRARI D ON L.CODINTR   = D.CODINTR   AND L.TIPLIVR = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND L.CARNETLIVR = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM NIR N  INNER JOIN IESIRI  D ON N.CODIES    = D.CODIES    AND N.TIPNIR  = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND N.CARNETNIR  = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM NIR N  INNER JOIN TRANSF  D ON N.CODTRANSF = D.CODTRANSF AND N.TIPNIR  = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND N.CARNETNIR  = DC.CODCARNET)
    AND NOT EXISTS (SELECT 1 FROM NIR N  INNER JOIN INTRARI D ON N.CODINTR   = D.CODINTR   AND N.TIPNIR  = D.TIPDOC WHERE D.AN*12+D.LUNA &gt;= AL_RUPERE AND N.CARNETNIR  = DC.CODCARNET);
  COMMIT;
  SELECT Count(1) INTO NR FROM TMP_MANEVRA;

  IF NR &gt; 0 THEN
    DELETE DOCLOCK    WHERE CODCARNET IN (SELECT CODUNIC FROM TMP_MANEVRA);
    DELETE DOCLINK    WHERE CODCARNET IN (SELECT CODUNIC FROM TMP_MANEVRA);
    DELETE DOCFREE    WHERE CODCARNET IN (SELECT CODUNIC FROM TMP_MANEVRA);
    DELETE DOCUSERS   WHERE CODCARNET IN (SELECT CODUNIC FROM TMP_MANEVRA);
    DELETE DOCCARNETE WHERE CODCARNET IN (SELECT CODUNIC FROM TMP_MANEVRA);
  END IF;
  COMMIT;
END;

FUNCTION INTERVAL_CONTINUU RETURN NUMBER IS
  aNRCnt NUMBER(20) := 0;
  aNRMin NUMBER(20) := 0;
  aNRMax NUMBER(20) := 0;
BEGIN
  SELECT Count(1), Coalesce(MIN(NRDOC), 0), Coalesce(MAX(NRDOC), 0) INTO aNRCnt, aNRMin, aNRMax  FROM TMP_USED_ULTERIOR;
  IF    aNRCnt = 0                   THEN RETURN 1;
  ELSIF aNRCnt = aNRMax - aNRMin + 1 THEN RETURN 1;
  ELSE                                    RETURN 0;
  END IF;
END;

PROCEDURE FIXEAZA_STARTNR IS
  NR_ANTERIOR NUMBER(20) := 0;
  NR_ULTERIOR NUMBER(20) := 0;
  NEXT_NRDOC  NUMBER(20) := 0;
BEGIN
  FOR V_REC IN (SELECT CODCARNET FROM DOCCARNETE )
  LOOP
    DELETE TMP_USED_ANTERIOR;
    DELETE TMP_USED_ULTERIOR;
    -- IESIRI
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM IESIRI WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM IESIRI WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- COMANDA
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM COMANDA WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM COMANDA WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- TRANSF
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM TRANSF WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM TRANSF WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- COMPENS
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM COMPENS WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM COMPENS WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- NC
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM NC WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM NC WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- TREZOR1
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM TREZOR1 WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM TREZOR1 WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- PACHETE
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM PACHETE WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM PACHETE WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- OFERTA
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT NRDOC FROM OFERTA WHERE AN*12+LUNA &lt; AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;
    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT NRDOC NR_ANTERIOR FROM OFERTA WHERE AN*12+LUNA &gt;= AL_RUPERE AND CARNETDOC = V_REC.CODCARNET;

    -- LIVR DIN IESIRI
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN IESIRI I ON L.CODIES  = I.CODIES AND L.TIPLIVR = I.TIPDOC
    WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN IESIRI I ON L.CODIES  = I.CODIES AND L.TIPLIVR = I.TIPDOC
    WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    -- LIVR DIN TRANSF
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN TRANSF T ON L.CODTRANSF  = T.CODTRANSF AND L.TIPLIVR    = T.TIPDOC
    WHERE T.AN*12+T.LUNA &lt; AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ULTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN TRANSF T ON L.CODTRANSF  = T.CODTRANSF AND L.TIPLIVR    = T.TIPDOC
    WHERE T.AN*12+T.LUNA &gt;= AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    -- LIVR DIN INTRARI
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN INTRARI I ON L.CODINTR  = I.CODINTR AND L.TIPLIVR = I.TIPDOC
    WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT L.NRLIVR
    FROM LIVR L INNER JOIN INTRARI I ON L.CODINTR  = I.CODINTR AND L.TIPLIVR = I.TIPDOC
    WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE AND CARNETLIVR = V_REC.CODCARNET;

    -- NIR DIN IESIRI
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN IESIRI I ON N.CODIES  = I.CODIES AND N.TIPNIR  = I.TIPDOC
    WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN IESIRI I ON N.CODIES  = I.CODIES AND N.TIPNIR  = I.TIPDOC
    WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    -- NIR DIN INTRARI
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN INTRARI I ON N.CODINTR  = I.CODINTR AND N.TIPNIR   = I.TIPDOC
    WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN INTRARI I ON N.CODINTR  = I.CODINTR AND N.TIPNIR   = I.TIPDOC
    WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    -- NIR DIN TRANSF
    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN TRANSF T ON  N.CODTRANSF  = T.CODTRANSF AND N.TIPNIR     = T.TIPDOC
    WHERE T.AN*12+T.LUNA &lt; AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    INSERT INTO TMP_USED_ANTERIOR (NRDOC)
    SELECT N.NRNIR
    FROM NIR N INNER JOIN TRANSF T ON  N.CODTRANSF  = T.CODTRANSF AND N.TIPNIR     = T.TIPDOC
    WHERE T.AN*12+T.LUNA &gt;= AL_RUPERE AND CARNETNIR = V_REC.CODCARNET;

    NEXT_NRDOC := 0;
    SELECT Coalesce(MAX(NRDOC), 0) INTO NR_ANTERIOR FROM TMP_USED_ANTERIOR;
    SELECT Coalesce(MIN(NRDOC), 0) INTO NR_ULTERIOR FROM TMP_USED_ULTERIOR;
    IF    NR_ULTERIOR = 0                                                          THEN NEXT_NRDOC := NR_ANTERIOR + 1;
    ELSIF NR_ULTERIOR &gt; NR_ANTERIOR AND NR_ANTERIOR &lt;&gt; 0 AND INTERVAL_CONTINUU = 0 THEN NEXT_NRDOC := NR_ULTERIOR;
    --stef pusa ramura else fiindca nu se sterg documentele din initializare din cauza STARTNR
    ELSE                                                                                NEXT_NRDOC := NR_ULTERIOR;
    END IF;

    IF NEXT_NRDOC &lt;&gt; 0 THEN
      UPDATE DOCCARNETE SET STARTNRINI = STARTNR, STARTNR = NEXT_NRDOC WHERE CODCARNET = V_REC.CODCARNET;
    END IF;
  END LOOP;
  COMMIT;
END;

PROCEDURE CURATA_LIVR IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT L.CODLIVR
  FROM LIVR L
    LEFT JOIN IESIRI  E ON E.CODIES    = L.CODIES    AND E.TIPDOC = L.TIPLIVR
    LEFT JOIN INTRARI I ON I.CODINTR   = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
    LEFT JOIN TRANSF  T ON T.CODTRANSF = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR
  WHERE Coalesce(I.AN,T.AN,E.AN)*12+Coalesce(I.LUNA,T.LUNA,E.LUNA) &lt; AL_RUPERE
    AND NOT EXISTS(SELECT 1 FROM LIVR1 L1 WHERE L1.CODLIVR = L.CODLIVR)
    AND NOT EXISTS(SELECT 1 FROM DOCCARNETE DC WHERE DC.CODCARNET = L.CARNETLIVR AND DC.STARTNR &lt;= L.NRLIVR);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.IB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE LIVR&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;LIVR&apos;, &apos;CODLIVR&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_NIR IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT N.CODNIR
  FROM NIR N
    LEFT JOIN IESIRI  E ON E.CODIES    = N.CODIES    AND E.TIPDOC = N.TIPNIR
    LEFT JOIN INTRARI I ON I.CODINTR   = N.CODINTR   AND I.TIPDOC = N.TIPNIR
    LEFT JOIN TRANSF  T ON T.CODTRANSF = N.CODTRANSF AND T.TIPDOC = N.TIPNIR
  WHERE Coalesce(I.AN,T.AN,E.AN)*12+Coalesce(I.LUNA,T.LUNA,E.LUNA) &lt; AL_RUPERE
    AND NOT EXISTS(SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
    AND NOT EXISTS(SELECT 1 FROM DOCCARNETE DC WHERE DC.CODCARNET = N.CARNETNIR AND DC.STARTNR &lt;= N.NRNIR);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.JB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE NIR&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;NIR&apos;, &apos;CODNIR&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_TRANSF1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT T1.CODTRANSF1
  FROM TRANSF1 T1
    LEFT JOIN TRANSF T ON T.CODTRANSF = T1.CODTRANSF
    LEFT JOIN LIVR   L ON L.CODTRANSF = T.CODTRANSF
    LEFT JOIN NIR    N ON N.CODTRANSF = T.CODTRANSF
  WHERE T.AN*12+T.LUNA &lt; AL_RUPERE
    AND L.CODLIVR IS NULL
    AND N.CODNIR  IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.KB&apos;,&apos;CURATA TRANSF1 - DELETE FROM TRANSF1&apos;);
  DELETE FROM TRANSFLINK TL WHERE NOT EXISTS (SELECT 1 FROM TRANSF1 T1 WHERE T1.CODTRANSF1 = TL.CODTRANSF1);

  PKG_GLOBALS.PUT_INFO(&apos;13.KC&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE TRANSF1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;TRANSF1&apos;, &apos;CODTRANSF1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_TREZOR1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT T1.CODTREZOR1
  FROM trezor t
    INNER JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
    LEFT  JOIN general g ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
  WHERE T.AN*12+T.LUNA &lt; AL_RUPERE
    AND g.codgeneral IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.LB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE TREZOR1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;TREZOR1&apos;, &apos;CODTREZOR1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_NC1 IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT NC1.CODNC1
  FROM nc
    INNER JOIN nc1 ON nc1.codnc = nc.codnc
    LEFT  JOIN general g ON g.tipdoc = 35 AND g.coddoc = nc1.codnc1
  WHERE nc.an*12+nc.luna &lt; AL_RUPERE
    AND g.codgeneral IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.MB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE NC1&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;NC1&apos;, &apos;CODNC1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_INTRARI IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I.CODINTR FROM INTRARI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM NIR      N  WHERE N.CODINTR  = I.CODINTR AND N.TIPNIR = I.TIPDOC) UNION
  SELECT I.CODINTR FROM INTRARI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM GENERAL  G  WHERE G.CODDOC   = I.CODINTR AND G.TIPDOC = I.TIPDOC) UNION
  SELECT I.CODINTR FROM INTRARI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM INTRARI1 I1 WHERE I1.CODINTR = I.CODINTR);
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I.CODINTR FROM INTRARI I WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.NB&apos;,&apos;COPY_TRUNC_COPY_KEEP INTRARI&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;INTRARI&apos;, &apos;CODINTR&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_IESIRI IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM NIR        N  WHERE N.CODIES     = I.CODIES    AND N.TIPNIR    = I.TIPDOC) UNION
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM LIVR       L  WHERE L.CODIES     = I.CODIES    AND L.TIPLIVR   = I.TIPDOC) UNION
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM GENERAL    G  WHERE G.CODDOC     = I.CODIES    AND G.TIPDOC    = I.TIPDOC) UNION
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM DOCCARNETE DC WHERE DC.CODCARNET = I.CARNETDOC AND DC.STARTNR &lt;= I.NRDOC)  UNION
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM IESIRI1    I1 WHERE I1.CODIES    = I.CODIES);
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT I.CODIES FROM IESIRI I WHERE I.AN*12+I.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.OB&apos;,&apos;COPY_TRUNC_COPY_KEEP MODURIPLATI&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;MODURIPLATI&apos;, &apos;CODIES&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.OC&apos;,&apos;COPY_TRUNC_COPY_KEEP IESIRI&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;IESIRI&apos;     , &apos;CODIES&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_TRANSF IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT T.CODTRANSF FROM TRANSF T WHERE T.AN*12+T.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM NIR        N  WHERE N.CODTRANSF  = T.CODTRANSF AND N.TIPNIR    = T.TIPDOC) UNION
  SELECT T.CODTRANSF FROM TRANSF T WHERE T.AN*12+T.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM DOCCARNETE DC WHERE DC.CODCARNET = T.CARNETDOC AND DC.STARTNR &lt;= T.NRDOC)  UNION
  SELECT T.CODTRANSF FROM TRANSF T WHERE T.AN*12+T.LUNA &lt; AL_RUPERE AND EXISTS (SELECT 1 FROM TRANSF1    T1 WHERE T1.CODTRANSF = T.CODTRANSF);
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT T.CODTRANSF FROM TRANSF T WHERE T.AN*12+T.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.PB&apos;,&apos;COPY_TRUNC_COPY_KEEP TRANSF&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;TRANSF&apos;, &apos;CODTRANSF&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_TREZOR IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT T.CODTREZOR
  FROM trezor t LEFT JOIN trezor1 t1 ON t1.codtrezor = t.codtrezor
  WHERE t1.codtrezor IS NULL AND T.AN*12+T.LUNA &lt; AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.QB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE TREZOR&apos;);
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;TREZOR&apos;, &apos;CODTREZOR&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_COMPENS IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT C.CODCOMPENS
  FROM compens c LEFT JOIN general g ON g.tipdoc = 28 AND g.coddoc = c.codcompens
  WHERE C.AN*12+C.LUNA &lt; AL_RUPERE
    AND g.codgeneral IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.RB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE COMPENS&apos;);
  --DELETE FROM COMPENS WHERE CODCOMPENS IN (SELECT CODUNIC FROM TMP_MANEVRA)
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;COMPENS&apos;, &apos;CODCOMPENS&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_NC IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT NC.CODNC
  FROM nc LEFT JOIN nc1 ON nc1.codnc = nc.codnc
  WHERE nc.an*12+nc.luna &lt; AL_RUPERE
    AND nc1.codnc IS NULL;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.SB&apos;,&apos;COPY_TRUNC_COPY_EXCLUDE NC&apos;);
  --DELETE FROM NC WHERE CODNC IN (SELECT CODUNIC FROM TMP_MANEVRA)
  COPY_TRUNC_COPY_EXCLUDE(FALSE, &apos;NC&apos;, &apos;CODNC&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_OFERTA IS
BEGIN
  --mOferteClienti   = 50;
  --mOferteFurnizori = 51;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT O.CODOFERTA
  FROM OFERTA O
  WHERE O.DATAEND &gt;= To_Date(To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;,&apos;YYYYMMDD&apos;);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.TB&apos;,&apos;COPY_TRUNC_COPY_KEEP OFERTA1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;OFERTA1&apos;, &apos;CODOFERTA&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.TC&apos;,&apos;COPY_TRUNC_COPY_KEEP OFERTA&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;OFERTA&apos;, &apos;CODOFERTA&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_PROMO IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT P.CODPROMO
  FROM PROMO p
  WHERE P.DATAEND &gt;= To_Date(To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;,&apos;YYYYMMDD&apos;);
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;13.UB&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMOPRAG&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PROMOPRAG&apos;, &apos;CODPROMO&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UC&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMOSUB&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PROMOSUB&apos;, &apos;CODPROMO&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UD&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMOPART&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PROMOPART&apos;, &apos;CODPROMO&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UE&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMO1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PROMO1&apos;, &apos;CODPROMO&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UF&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMO&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PROMO&apos;, &apos;CODPROMO&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UG&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMO1SER&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;PROMO1SER&apos;, &apos;EXISTS (SELECT 1 FROM PROMO1 P1 WHERE P1.CODPROMO1 = S.CODPROMO1)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UH&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMO1SER&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;PROMO1CADOU&apos;, &apos;EXISTS (SELECT 1 FROM PROMO1 P1 WHERE P1.CODPROMO1 = S.CODPROMO1)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.UI&apos;,&apos;COPY_TRUNC_COPY_KEEP PROMO1SER&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;PROMO1CADOUSER&apos;, &apos;EXISTS (SELECT 1 FROM PROMO1CADOU P1C WHERE P1C.CODCADOU = S.CODCADOU)&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_COMANDA IS
BEGIN
-- introdus pasul 03 -&gt; FIXEAZA_INITILIZARE_COMENZI care face si curatenie in comenzi
-- DECI NU SE FOLOSESTE

  --mComenziFurnizori       =  8;
  --mComenziClienti         = 18;
  --mComenziGestiuni        = 43;
  --mComenziCatreSubunitati = 44;
  --mComenziProdComp        = 53;
  --mComenziDELASubunitati  = 60; // folosit impreuna cu flagul DispozitieLivrare la Centralizator comenzui de la subunitati
  --mComenziStorno          = 65;
  --mComenziStornoFurn      = 66;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT C1.CODCOMANDA1
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  WHERE C.AN*12+C.LUNA &lt; AL_RUPERE
    AND ( EXISTS (SELECT 1 FROM IESLINK    L WHERE L.CODLINIECOMANDA = C1.CODCOMANDA1) OR
          EXISTS (SELECT 1 FROM INTRLINK   L WHERE L.CODLINIECOMANDA = C1.CODCOMANDA1) OR
          EXISTS (SELECT 1 FROM TRANSFLINK L WHERE L.CODLINIECOMANDA = C1.CODCOMANDA1)
        );
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT C1.CODCOMANDA1
  FROM COMANDA1 C1 INNER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  WHERE C.AN*12+C.LUNA &gt;= AL_RUPERE;
  COMMIT;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA2(CODUNIC)
  SELECT DISTINCT C1.CODCOMANDA
  FROM TMP_MANEVRA T LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = T.CODUNIC;
  COMMIT;

  --COMANDA1LUNA  -&gt; SE CURATA IN STERGE_FIXARI_LUNARE_ANTER;

  PKG_GLOBALS.PUT_INFO(&apos;13.XB&apos;,&apos;COPY_TRUNC_COPY_KEEP CMDPRODMAN&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;CMDPRODMAN&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XC&apos;,&apos;COPY_TRUNC_COPY_KEEP CMDPRODMAT&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;CMDPRODMAT&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XD&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA4&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA4&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XE&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA3&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XF&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA2&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XG&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA1ET&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA1ET&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XH&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA1&apos;, &apos;CODCOMANDA1&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;13.XI&apos;,&apos;COPY_TRUNC_COPY_KEEP COMANDA&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;COMANDA&apos;, &apos;CODCOMANDA&apos;, &apos;TMP_MANEVRA2&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
END;

PROCEDURE STERGE_DOCUMENTE_LUNI_ANTER IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;13.BA&apos;,&apos;CURATA LIVR1&apos;);
  CURATA_LIVR1;

  PKG_GLOBALS.PUT_INFO(&apos;13.CA&apos;,&apos;CURATA NIRSTOC&apos;);
  CURATA_NIRSTOC;

  PKG_GLOBALS.PUT_INFO(&apos;13.DA&apos;,&apos;CURATA OBLIGPIF&apos;);
  CURATA_OBLIGPIF;

  PKG_GLOBALS.PUT_INFO(&apos;13.EA&apos;,&apos;CURATA INTRARI1&apos;);
  CURATA_INTRARI1;

  PKG_GLOBALS.PUT_INFO(&apos;13.FA&apos;,&apos;CURATA IESIRI1&apos;);
  CURATA_IESIRI1;

  PKG_GLOBALS.PUT_INFO(&apos;13.GA&apos;,&apos;CURATA CARNETDOC&apos;);
  CURATA_CARNETEDOC;

  PKG_GLOBALS.PUT_INFO(&apos;13.HA&apos;,&apos;FIXEAZA STARTNR&apos;);
  FIXEAZA_STARTNR;

  PKG_GLOBALS.PUT_INFO(&apos;13.IA&apos;,&apos;CURATA LIVR&apos;);
  CURATA_LIVR; -- MUTAT AICI DIN MOTIVE DE CARNETE

  PKG_GLOBALS.PUT_INFO(&apos;13.JA&apos;,&apos;CURATA NIR&apos;);
  CURATA_NIR;  -- MUTAT AICI DIN MOTIVE DE CARNETE

  PKG_GLOBALS.PUT_INFO(&apos;13.KA&apos;,&apos;CURATA TRANSF1&apos;);
  CURATA_TRANSF1;

  PKG_GLOBALS.PUT_INFO(&apos;13.LA&apos;,&apos;CURATA CURATA_TREZOR1&apos;);
  CURATA_TREZOR1;

  PKG_GLOBALS.PUT_INFO(&apos;13.MA&apos;,&apos;CURATA_NC1&apos;);
  CURATA_NC1;

  PKG_GLOBALS.PUT_INFO(&apos;13.NA&apos;,&apos;CURATA INTRARI&apos;);
  CURATA_INTRARI;

  PKG_GLOBALS.PUT_INFO(&apos;13.OA&apos;,&apos;CURATA IESIRI&apos;);
  CURATA_IESIRI;

  PKG_GLOBALS.PUT_INFO(&apos;13.PA&apos;,&apos;CURATA TRANSF&apos;);
  CURATA_TRANSF;

  PKG_GLOBALS.PUT_INFO(&apos;13.QA&apos;,&apos;CURATA_TREZOR&apos;);
  CURATA_TREZOR;

  PKG_GLOBALS.PUT_INFO(&apos;13.RA&apos;,&apos;CURATA_COMPENS TRANSF1&apos;);
  CURATA_COMPENS;

  PKG_GLOBALS.PUT_INFO(&apos;13.SA&apos;,&apos;CURATA_NC&apos;);
  CURATA_NC;

  PKG_GLOBALS.PUT_INFO(&apos;13.TA&apos;,&apos;CURATA OFERTA&apos;);
  CURATA_OFERTA;

  PKG_GLOBALS.PUT_INFO(&apos;13.UA&apos;,&apos;CURATA PROMO&apos;);
  CURATA_PROMO;

-- introdus pasul 03 -&gt; FIXEAZA_INITILIZARE_COMENZI care face si curatenie in comenzi
--  PKG_GLOBALS.PUT_INFO(&apos;13.XA&apos;,&apos;CURATA COMENZI&apos;);
--  CURATA_COMANDA;
END;

PROCEDURE STERGE_FIXARI_LUNARE_ANTER IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;14.AB&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NIRLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NIRLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI||&apos; AND EXISTS(SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = S.CODNIRSTOC)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;14.AC&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; STOCVALLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;STOCVALLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AD&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; OBLIGPIFLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;OBLIGPIFLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI||&apos; AND EXISTS(SELECT 1 FROM OBLIGPIF O WHERE O.CODOBLIGPIF = S.CODOBLIGPIF)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;14.AE&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NPARTSOLDLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NPARTSOLDLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AF&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NPARTSOLDLUNASUB&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NPARTSOLDLUNASUB&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AG&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NPERSSOLDLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NPERSSOLDLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AH&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NPERSSOLDLUNASUB&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NPERSSOLDLUNASUB&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AI&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NBANKSOLDLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NBANKSOLDLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AJ&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; AVIZINTLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;AVIZINTLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI||&apos; AND EXISTS(SELECT 1 FROM INTRARI1 I1 WHERE I1.CODINTR1 = S.CODINTR1)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;14.AK&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; AVIZIESLUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;AVIZIESLUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI||&apos; AND EXISTS(SELECT 1 FROM IESIRI1 I1 WHERE I1.CODIES1 = S.CODIES1)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;14.AL&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; COMANDA1LUNA&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;COMANDA1LUNA&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI||&apos; AND EXISTS(SELECT 1 FROM COMANDA1 C1 WHERE C1.CODCOMANDA1 = S.CODCOMANDA1)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;14.AM&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NCONTRUL&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;NCONTRUL&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;14.AN&apos;,&apos;STERGE_FIXARI_LUNARE_ANTER -&gt; NCONT1&apos;);
  UPDATE NCONT1 SET ANSTART = AN_RUPERE, LUNASTART = LUNA_RUPERE WHERE ANSTART*12+LUNASTART &lt; AL_RUPERE;
  COMMIT;
END;

PROCEDURE DO_CURATA_DETLUNA IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;15.BA&apos;,&apos;CURATA IOART1&apos;);
  DO_CURATA_TABDETLUNA(&apos;IOART1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.CA&apos;,&apos;CURATA IOBANK1&apos;);
  DO_CURATA_TABDETLUNA(&apos;IOBANK1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.DA&apos;,&apos;CURATA IOFILIAL1&apos;);
  DO_CURATA_TABDETLUNA(&apos;IOFILIAL1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.EA&apos;,&apos;CURATA IOPART1&apos;);
  DO_CURATA_TABDETLUNA(&apos;IOPART1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.FA&apos;,&apos;CURATA IOPERS1&apos;);
  DO_CURATA_TABDETLUNA(&apos;IOPERS1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.GA&apos;,&apos;CURATA NAGENDA1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NAGENDA1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.HA&apos;,&apos;CURATA NART1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NART1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.IA&apos;,&apos;CURATA NARTOBJ1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NARTOBJ1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.JA&apos;,&apos;CURATA NBANKCONT1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NBANKCONT1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.KA&apos;,&apos;CURATA NCONT1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NCONT1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.LA&apos;,&apos;CURATA NCONTS1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NCONTS1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.MA&apos;,&apos;CURATA NCONTT1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NCONTT1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.NA&apos;,&apos;CURATA NGEST1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NGEST1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.OA&apos;,&apos;CURATA NPART1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NPART1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.PA&apos;,&apos;CURATA NPERS1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NPERS1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.QA&apos;,&apos;CURATA NSUBUNIT1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NSUBUNIT1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.RA&apos;,&apos;CURATA NTAXE1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NTAXE1&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;15.SA&apos;,&apos;CURATA NTVA1&apos;);
  DO_CURATA_TABDETLUNA(&apos;NTVA1&apos;);
END;

PROCEDURE CURATA_JURNALE IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;21.AB&apos;,&apos;CURATA_JURNALE -&gt; JURNAL1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;JURNAL1&apos;, &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_RUPERE);
  PKG_GLOBALS.PUT_INFO(&apos;21.AC&apos;,&apos;CURATA_JURNALE -&gt; JURNAL&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;JURNAL&apos; , &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_RUPERE);
  --Stef JURNETALON nu era in procedura dar presupun ca trebuie curatat si asta
  PKG_GLOBALS.PUT_INFO(&apos;21.AD&apos;,&apos;CURATA_JURNALE -&gt; JURNETALON&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;JURNETALON&apos; , &apos;S.AN*12+S.LUNA&gt;=&apos;||sAL_RUPERE);
END;

PROCEDURE CURATA_LANSZ IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODLANSZ
  FROM LANSZ L
  WHERE L.AN*12+L.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;22.AB&apos;,&apos;CURATA_LANSZ -&gt; DFLANSZ1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DFLANSZ1&apos;         , &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;22.AC&apos;,&apos;CURATA_LANSZ -&gt; LANSZ1_MANEVRA1_L&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSZ1_MANEVRA1_L&apos;, &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;22.AD&apos;         ,&apos;CURATA_LANSZ -&gt; LANSZ1_MANEVRA1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSZ1_MANEVRA1&apos;  , &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;22.AE&apos;,&apos;CURATA_LANSZ -&gt; LANSZ1_MANEVRA&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSZ1_MANEVRA&apos;   , &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;22.AF&apos;,&apos;CURATA_LANSZ -&gt; LANSZ1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSZ1&apos;           , &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;22.AG&apos;,&apos;CURATA_LANSZ -&gt; LANSZ&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSZ&apos;            , &apos;CODLANSZ&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_XXXPROD IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODPLANIFPROD
  FROM PLANIFPROD P
  WHERE P.AN*12+P.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;23.BA&apos;,&apos;CURATA_PLANIFPROD -&gt; PLANIFNOD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PLANIFNOD&apos;  , &apos;CODPLANIFPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.BB&apos;,&apos;CURATA_PLANIFPROD -&gt; PLANIFPROD1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PLANIFPROD1&apos;, &apos;CODPLANIFPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.BC&apos;,&apos;CURATA_PLANIFPROD -&gt; PLANIFPROD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;PLANIFPROD&apos; , &apos;CODPLANIFPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODESTIMAREPROD
  FROM ESTIMARIPROD P
  WHERE P.AN*12+P.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;23.CA&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARINOD_C2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARINOD_C2&apos;, &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.CB&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARINOD_C1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARINOD_C1&apos;, &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.CC&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARINOD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARINOD&apos;   , &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;23.CD&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARIPROD1N&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARIPROD1N&apos;, &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.CE&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARIPROD1M&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARIPROD1M&apos;, &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.CF&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARIPROD1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARIPROD1&apos; , &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;23.CG&apos;,&apos;CURATA_ESTIMARIPROD -&gt; ESTIMARIPROD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;ESTIMARIPROD&apos;  , &apos;CODESTIMAREPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODLANSPROD
  FROM LANSPROD LP
  WHERE LP.AN*12+LP.LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;23.DA&apos;,&apos;CURATA_ESTIMARIPROD -&gt; LANSPROD1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSPROD1&apos;, &apos;CODLANSPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;23.DB&apos;,&apos;CURATA_LANSPROD -&gt; LANSPROD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;LANSPROD&apos; , &apos;CODLANSPROD&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_STAREESTIMARI IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT CODSTARE
  FROM STAREESTIMARI P
  WHERE P.AN &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;24.AB&apos;,&apos;CURATA_STAREESTIMARI -&gt; STAREESTIMARI2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;STAREESTIMARI2&apos;, &apos;CODSTARE&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;24.AC&apos;,&apos;CURATA_STAREESTIMARI -&gt; STAREESTIMARI1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;STAREESTIMARI1&apos;, &apos;CODSTARE&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;24.AD&apos;,&apos;CURATA_STAREESTIMARI -&gt; STAREESTIMARI&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;STAREESTIMARI&apos; , &apos;CODSTARE&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
END;

PROCEDURE CURATA_PREDARIPLUS IS
BEGIN
  COPY_TRUNC_COPY_COND(FALSE, &apos;PREDARIPLUS&apos;, &apos;S.DATADOC &gt;= To_Date(&apos;&apos;&apos;||To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
END;

PROCEDURE CURATA_DECLARATII IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;30.BA&apos;,&apos;CURATA_D300 -&gt; D300&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;D300&apos;, &apos;S.AN*12+S.LUNAD&gt;=&apos;||sAL_RUPERE);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODD390 FROM D390 WHERE AN*12+LUNAD &gt;= AL_RUPERE;
  COMMIT;
  PKG_GLOBALS.PUT_INFO(&apos;30.CA&apos;,&apos;CURATA_D390 -&gt; D390D&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D390D&apos;, &apos;CODD390&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.CB&apos;,&apos;CURATA_D390 -&gt; D390O&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D390O&apos;, &apos;CODD390&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.CC&apos;,&apos;CURATA_D390 -&gt; D390&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D390&apos; , &apos;CODD390&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODD394 FROM D394 WHERE AN*12+LUNAD &gt;= AL_RUPERE;
  COMMIT;
  PKG_GLOBALS.PUT_INFO(&apos;30.DA&apos;,&apos;CURATA_D394 -&gt; D394VC&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;D394VC&apos;, &apos;S.CodD394V IN (SELECT D.CodD394V FROM TMP_MANEVRA T INNER JOIN D394V D ON D.CodD394 = T.CODUNIC)&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DB&apos; ,&apos;CURATA_D394 -&gt; D394CC&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;D394CC&apos;, &apos;S.CodD394C IN (SELECT D.CodD394C FROM TMP_MANEVRA T INNER JOIN D394C D ON D.CodD394 = T.CODUNIC)&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DC&apos;,&apos;CURATA_D394 -&gt; D394V&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D394V&apos; , &apos;CodD394&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DD&apos;,&apos;CURATA_D394 -&gt; D394C&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D394C&apos; , &apos;CodD394&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DE&apos;,&apos;CURATA_D394 -&gt; D394L&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D394L&apos; , &apos;CodD394&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DF&apos;,&apos;CURATA_D394 -&gt; D394A&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D394A&apos; , &apos;CodD394&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.DG&apos;,&apos;CURATA_D394 -&gt; D394&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D394&apos;  , &apos;CodD394&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODD39416 FROM D39416 WHERE AN*12+LUNAD &gt;= AL_RUPERE;
  COMMIT;
  PKG_GLOBALS.PUT_INFO(&apos;30.EA&apos;,&apos;CURATA_D39416 -&gt; D39416NS2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416NS2&apos; ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EB&apos;,&apos;CURATA_D39416 -&gt; D39416N&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416N&apos;   ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EC&apos;,&apos;CURATA_D39416 -&gt; D39416UES2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416UES2&apos;,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.ED&apos;,&apos;CURATA_D39416 -&gt; D39416UE&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416UE&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EE&apos;,&apos;CURATA_D39416 -&gt; D39416I4&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I4&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EF&apos;,&apos;CURATA_D39416 -&gt; D39416I3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I3&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EG&apos;,&apos;CURATA_D39416 -&gt; D39416I2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I2&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EH&apos;,&apos;CURATA_D39416 -&gt; D39416I2A&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I2A&apos; ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EI&apos;,&apos;CURATA_D39416 -&gt; D39416I1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I1&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EJ&apos;,&apos;CURATA_D39416 -&gt; D39416I&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416I&apos;   ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EK&apos;,&apos;CURATA_D39416 -&gt; D39416G3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416G3&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EL&apos;,&apos;CURATA_D39416 -&gt; D39416G2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416G2&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EM&apos;,&apos;CURATA_D39416 -&gt; D39416G1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416G1&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EN&apos;,&apos;CURATA_D39416 -&gt; D39416G&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416G&apos;   ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EO&apos;,&apos;CURATA_D39416 -&gt; D39416RNS3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RNS3&apos;,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EP&apos;,&apos;CURATA_D39416 -&gt; D39416RNS2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RNS2&apos;,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EQ&apos;,&apos;CURATA_D39416 -&gt; D39416RN1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RN1&apos; ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.ER&apos;,&apos;CURATA_D39416 -&gt; D39416RN0&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RN0&apos; ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.ES&apos;,&apos;CURATA_D39416 -&gt; D39416RN&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RN&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.ET&apos;,&apos;CURATA_D39416 -&gt; D39416RPS3&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RPS3&apos;,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EU&apos;,&apos;CURATA_D39416 -&gt; D39416RPS2&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RPS2&apos;,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EV&apos;,&apos;CURATA_D39416 -&gt; D39416RP1&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RP1&apos; ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EX&apos;,&apos;CURATA_D39416 -&gt; D39416RP&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416RP&apos;  ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EY&apos;,&apos;CURATA_D39416 -&gt; D39416R&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416R&apos;   ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.EZ&apos;,&apos;CURATA_D39416 -&gt; D39416&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;D39416&apos;    ,&apos;CodD39416&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODDINTRASTAT FROM DIntrastat WHERE AN*12+LUNAD &gt;= AL_RUPERE;
  COMMIT;
  PKG_GLOBALS.PUT_INFO(&apos;30.FA&apos;,&apos;CURATA_DIntrastat -&gt; DIntrastatA&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DINTRASTATA&apos;,&apos;CodDIntrastat&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.FB&apos;,&apos;CURATA_DIntrastat -&gt; DIntrastatD&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DINTRASTATD&apos;,&apos;CodDIntrastat&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.FC&apos;,&apos;CURATA_DIntrastat -&gt; DIntrastat&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DINTRASTAT&apos; ,&apos;CodDIntrastat&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODDPROFIT FROM DPROFIT WHERE ANGENERARE*12+LUNAGENERARE &gt;= AL_RUPERE;
  COMMIT;
  PKG_GLOBALS.PUT_INFO(&apos;30.GA&apos;,&apos;CURATA_DPROFIT -&gt; DPROFITV&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DPROFITV&apos;,&apos;CODDPROFIT&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.GB&apos;,&apos;CURATA_DPROFIT -&gt; DPROFITC&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DPROFITC&apos;,&apos;CODDPROFIT&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;30.GC&apos;,&apos;CURATA_DPROFIT -&gt; DPROFIT&apos;);
  COPY_TRUNC_COPY_KEEP(FALSE, &apos;DPROFIT&apos; ,&apos;CODDPROFIT&apos;, &apos;TMP_MANEVRA&apos;, &apos;CODUNIC&apos;);
END;

PROCEDURE CURATA_EXPERT IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODEXPERT FROM EXPERT WHERE AN*12+LUNA &gt;= AL_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;84.BA&apos;,&apos;COPY_TRUNC_COPY_COND - EXPERT1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;EXPERT1&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODEXPERT)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;84.CA&apos;,&apos;COPY_TRUNC_COPY_COND - EXPERT&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;EXPERT&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODEXPERT)&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_REG IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODREG FROM REG WHERE AN &gt; AN_RUPERE;
  COMMIT;
  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC) SELECT CODREG FROM REG WHERE AN = AN_RUPERE AND LUNA &gt;= LUNA_RUPERE;
  COMMIT;

  PKG_GLOBALS.PUT_INFO(&apos;85.BA&apos;,&apos;COPY_TRUNC_COPY_COND - REG1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;REG1&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.BB&apos;,&apos;COPY_TRUNC_COPY_COND - REGTREZOR1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;REGTREZOR1&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.BC&apos;,&apos;COPY_TRUNC_COPY_COND - TREZOR1_REG&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;TREZOR1_REG&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.BD&apos;,&apos;COPY_TRUNC_COPY_COND - GENERAL_REG&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;GENERAL_REG&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.BE&apos;,&apos;COPY_TRUNC_COPY_COND - REGLEAS1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;REGLEAS1&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.BFD&apos;,&apos;COPY_TRUNC_COPY_COND - REGPERS1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;REGPERS1&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;85.CA&apos;,&apos;COPY_TRUNC_COPY_COND - REG1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;REG&apos;, &apos;EXISTS(SELECT 1 FROM TMP_MANEVRA T WHERE T.CODUNIC = S.CODREG)&apos;);

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE CURATA_MIFIX IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;86.BA&apos;,&apos;COPY_TRUNC_COPY_COND - MIFIX1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;MIFIX1&apos;, &apos;S.ANSTART*12+S.LUNASTART &gt;= &apos;||sAL_INITIALIZARI);

  PKG_GLOBALS.PUT_INFO(&apos;86.BB&apos;,&apos;COPY_TRUNC_COPY_COND - MIFIX&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;MIFIX&apos;, &apos;EXISTS(SELECT 1 FROM MIFIX1 M1 WHERE M1.CODMIFIX = S.CODMIFIX)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;86.BC&apos;,&apos;COPY_TRUNC_COPY_COND - MASTERMIFIX&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;MASTERMIFIX&apos;, &apos;EXISTS(SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = S.CODNIRSTOC)&apos;);

  --??? IMBMIFIXLINK
END;

PROCEDURE CURATA_INVENTAR IS
  sDataIni VARCHAR2(10) := To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;;
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;87.BA&apos;,&apos;COPY_TRUNC_COPY_COND - INVENTSTOC (INVENTAR)&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;INVENTSTOC&apos;, &apos;S.CODINVENTAR IN (SELECT CODINVENTAR FROM INVENTAR WHERE DATAINVENTAR &gt;= To_Date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;))&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;87.BB&apos;,&apos;COPY_TRUNC_COPY_COND - INVENTSTOC (NIRSTOC)&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;INVENTSTOC&apos;, &apos;EXISTS(SELECT 1 FROM NIRSTOC NS WHERE NS.CODNIRSTOC = S.CODNIRSTOC)&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;87.BC&apos;,&apos;COPY_TRUNC_COPY_COND - INVENTAR1&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;INVENTAR1&apos;, &apos;S.CODINVENTAR IN (SELECT CODINVENTAR FROM INVENTAR WHERE DATAINVENTAR &gt;= To_Date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;))&apos;);

  PKG_GLOBALS.PUT_INFO(&apos;87.BD&apos;,&apos;COPY_TRUNC_COPY_COND - INVENTAR&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;INVENTAR&apos;, &apos;S.DATAINVENTAR &gt;= To_Date(&apos;&apos;&apos;||sDataIni||&apos;&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
END;

PROCEDURE CURATA_TAB_DOCUMENTE IS
BEGIN
  COPY_TRUNC_COPY_COND(FALSE, &apos;DOCUMENTE&apos;, &apos;S.DATACREARE &gt;= To_Date(&apos;&apos;&apos;||To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
END;

PROCEDURE CURATA_MODIF IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;89.BA&apos;,&apos;COPY_TRUNC_COPY_COND - MODIFICARI&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;MODIFICARI&apos;, &apos;S.DATAMODIF &gt;= To_Date(&apos;&apos;&apos;||To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;89.BB&apos;,&apos;COPY_TRUNC_COPY_COND - TRIGAR_MODIF&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;TRIGAR_MODIF&apos;, &apos;S.DATAMODIF &gt;= To_Date(&apos;&apos;&apos;||To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
  PKG_GLOBALS.PUT_INFO(&apos;89.BC&apos;,&apos;COPY_TRUNC_COPY_COND - MODI_STATE&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;MODI_STATE&apos;, &apos;S.MODIDATE &gt;= To_Date(&apos;&apos;&apos;||To_Char(AN_RUPERE,&apos;FM0000&apos;)||To_Char(LUNA_RUPERE,&apos;FM00&apos;)||&apos;01&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)&apos;);
END;

PROCEDURE CURATA_LST_BALANTA IS
BEGIN
  FOR vRec IN (
    SELECT
      table_name,
      To_Number(Regexp_Replace(table_name,&apos;\D+&apos;, &apos;&apos;))*12+
      CASE SubStr(TABLE_NAME, 13, 3)
        WHEN &apos;IAN&apos; THEN  1
        WHEN &apos;FEB&apos; THEN  2
        WHEN &apos;MAR&apos; THEN  3
        WHEN &apos;APR&apos; THEN  4
        WHEN &apos;MAI&apos; THEN  5
        WHEN &apos;IUN&apos; THEN  6
        WHEN &apos;IUL&apos; THEN  7
        WHEN &apos;AUG&apos; THEN  8
        WHEN &apos;SEP&apos; THEN  9
        WHEN &apos;OCT&apos; THEN 10
        WHEN &apos;NOV&apos; THEN 11
        WHEN &apos;DEC&apos; THEN 12
        ELSE 99999
      END AL
    FROM user_tables
    WHERE SubStr(TABLE_NAME, 1, 12) = &apos;LST_BALANTA_&apos;
  ) LOOP
    IF vRec.AL &lt; AL_Rupere THEN
      DROP_TABLE(vRec.Table_Name);
    END IF;
  END LOOP;
END;

PROCEDURE CURATA_TAB_EXTENSII IS
BEGIN
  FOR vRec IN (
    SELECT To_Char(ROWNUM, &apos;fm000&apos;) NrCrt, UTC.TABLE_NAME TabExt, UTM.TABLE_NAME TabMaster, UTC.COLUMN_NAME Col
    FROM CFGTABLES CT
      LEFT JOIN USER_TAB_COLUMNS UTC ON UTC.TABLE_NAME  = CT.NUMETABELA   AND UTC.COLUMN_ID = 2
      LEFT JOIN USER_TAB_COLUMNS UTM ON UTM.COLUMN_NAME = UTC.COLUMN_NAME AND UTM.COLUMN_ID = 1
    WHERE UTM.TABLE_NAME IN (
                              &apos;BCAR&apos;,&apos;CENTRECOST&apos;,&apos;CERTIF&apos;,&apos;CHELTAVANS1&apos;,&apos;COMANDA&apos;,&apos;COMANDA1&apos;,&apos;CONTRACT&apos;,&apos;CONTRACT1&apos;,&apos;FAZ&apos;,&apos;IESIRI&apos;,&apos;IESIRI1&apos;,&apos;INTRARI&apos;,&apos;INTRARI1&apos;,&apos;MIFIX1&apos;,
                              &apos;NAGENDA&apos;,&apos;NARTOBJ&apos;,&apos;NBANKCONT&apos;,&apos;NC&apos;,&apos;NC1&apos;,&apos;NCONT&apos;,&apos;NCONTS&apos;,&apos;NGEST&apos;,&apos;NPARCAUT&apos;,&apos;NPART&apos;,&apos;NPERS&apos;,&apos;NSERTAR&apos;,&apos;OFERTA&apos;,&apos;OFERTA1&apos;,&apos;OPORTUNITATI&apos;,
                              &apos;PACHETE&apos;,&apos;PLATI&apos;,&apos;PROIECT&apos;,&apos;RAPORTP&apos;,&apos;RECLAMATII&apos;,&apos;SETTASK&apos;,&apos;TARGETAG&apos;,&apos;TARGETAG1&apos;,&apos;TRANSF&apos;,&apos;TRANSF1&apos;,&apos;TREZOR&apos;,&apos;TREZOR1&apos;,&apos;UTILAJE&apos;
                            )
  ) LOOP
    PKG_GLOBALS.PUT_INFO(&apos;92.B&apos;||vrec.NrCrt,&apos;COPY_TRUNC_COPY_KEEP -&gt; &apos;||vRec.TabExt);
    COPY_TRUNC_COPY_KEEP(FALSE, vRec.TabExt, vRec.Col, vRec.TabMaster, vRec.Col);
  END LOOP;
END;

PROCEDURE CURATA_TAB_DIVERSE IS
BEGIN
  PKG_GLOBALS.PUT_INFO(&apos;93.BA&apos;,&apos;COPY_TRUNC_COPY_COND - TAXDECL&apos;);
  COPY_TRUNC_COPY_COND(FALSE, &apos;TAXDECL&apos;, &apos;S.ANLUNA &gt;= &apos;||sAL_RUPERE);

  PKG_GLOBALS.PUT_INFO(&apos;93.CA&apos;,&apos;TRUNCATE TABLE DEBUG_LISTE&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE DEBUG_LISTE&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CB&apos;,&apos;TRUNCATE TABLE TMP_LST_FISAIMOB&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_LST_FISAIMOB&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CC&apos;,&apos;TRUNCATE TABLE TMP_STAREESTIMARI1_CENTR&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_STAREESTIMARI1_CENTR&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CD&apos;,&apos;TRUNCATE TABLE TMP_MANEVRA_INTR1_GRUPC&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA_INTR1_GRUPC&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CE&apos;,&apos;TRUNCATE TABLE TMP_PRODCOMP_MAN&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_PRODCOMP_MAN&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CF&apos;,&apos;TRUNCATE TABLE TMP_PLANIFCMDMAT&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_PLANIFCMDMAT&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CG&apos;,&apos;TRUNCATE TABLE TMP_PLANIFNODZTL&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_PLANIFNODZTL&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CH&apos;,&apos;TRUNCATE TABLE TMP_CMDTL&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_CMDTL&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CI&apos;,&apos;TRUNCATE TABLE TMP_MANEVRA_INTR1_GRUPL&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA_INTR1_GRUPL&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CJ&apos;,&apos;TRUNCATE TABLE X&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE X&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CK&apos;,&apos;TRUNCATE TABLE XXX&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE XXX&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;93.CL&apos;,&apos;STERGER SALVARI SAFT - SAV_TMP_SAFT% &apos;);
  FOR vRec IN (
    SELECT table_name FROM user_tables WHERE table_name LIKE &apos;SAV_TMP_SAFT%&apos;
  ) LOOP
    EXECUTE IMMEDIATE &apos;DROP TABLE &apos;||vRec.Table_Name||&apos; PURGE&apos;;
  END LOOP;

END;

PROCEDURE DO_SET_FLAG_INITIALIZARI IS
BEGIN
  --UPDATE IESIRI  SET INITIALIZARI = 1 WHERE AN*12+LUNA &lt; AL_RUPERE AND TVAINCASARE = 1;
  --UPDATE INTRARI SET INITIALIZARI = 1 WHERE AN*12+LUNA &lt; AL_RUPERE AND TVAINCASARE = 1;
  UPDATE IESIRI  SET INITIALIZARI = 1 WHERE AN*12+LUNA &lt; AL_RUPERE;
  UPDATE INTRARI SET INITIALIZARI = 1 WHERE AN*12+LUNA &lt; AL_RUPERE;
END;

PROCEDURE DO_REZOLVA_INCOERENTE IS
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT G.CODGENERAL
  FROM GENERAL G LEFT JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
  WHERE Coalesce(O.CODOBLIGPIF, 0) = 0;
  COMMIT;

  DELETE FROM GENERAL WHERE CODGENERAL IN (SELECT CODUNIC FROM TMP_MANEVRA);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;

  INSERT /*+ APPEND */ INTO TMP_MANEVRA(CODUNIC)
  SELECT S.CODSTINGERE
  FROM STINGERE S LEFT JOIN OBLIGPIF O ON S.CODSTINGATORPIF = O.CODOBLIGPIF
  WHERE Coalesce(O.CODOBLIGPIF, 0) = 0;
  COMMIT;

  DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODUNIC FROM TMP_MANEVRA);
  COMMIT;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA&apos;;
END;

PROCEDURE REPARA_REST_OBLIGPIF_INITIAL(ANINITIAL IN NUMBER, LUNAINITIALA IN NUMBER) IS
BEGIN
  FOR V_REC IN (
    SELECT O.CODOBLIGPIF, O.VALOARE, I.AN, I.LUNA
    FROM INTRARI I
      INNER JOIN GENERAL G ON I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE I.AN*12+I.LUNA &lt; ANINITIAL*12+LUNAINITIALA
      AND G.SEMNIFICATIE IN (100, 110, 140, 130)
  ) LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST) VALUES (V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;

  FOR V_REC IN  (
    SELECT O.CODOBLIGPIF, O.VALOARE, I.AN, I.LUNA
    FROM IESIRI I
      INNER JOIN GENERAL G ON I.TIPDOC = G.TIPDOC AND I.CODIES = G.CODDOC
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE I.AN*12+I.LUNA &lt; ANINITIAL*12+LUNAINITIALA
      AND G.SEMNIFICATIE IN (200, 210, 240)
  ) LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST) VALUES (V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;

  FOR V_REC IN (
    SELECT O.CODOBLIGPIF, O.VALOARE, T1.AN, T1.LUNA
    FROM TREZOR1 T1
      INNER JOIN GENERAL G ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33)
      INNER JOIN OBLIGPIF O ON O.CODGENERAL = G.CODGENERAL
    WHERE T1.AN*12+T1.LUNA &lt; ANINITIAL*12+LUNAINITIALA
      AND O.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600)
  ) LOOP
    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF AND AN = V_REC.AN AND LUNA = V_REC.LUNA;
    INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST) VALUES (V_REC.CODOBLIGPIF, V_REC.AN, V_REC.LUNA, V_REC.VALOARE);
  END LOOP;
END;

PROCEDURE REPARA_SOLDINI IS
  vAn   NUMBER;
  vLuna NUMBER;
BEGIN
  SELECT Coalesce(AnInitial, 0), Coalesce(LunaInitiala, 0) INTO vAN, vLUNA FROM FirmaLuni;

  IF vAN &lt;&gt; 0 AND vLUNA &lt;&gt; 0 THEN
    SetAnLunaRupere(vAN, vLUNA);
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE SOLDINI&apos;;
    PKG_REMAKE_SEQUENCES.REVAL_SEQUENCE(&apos;SOLDINI&apos;,&apos;CODSOLDINI&apos;,&apos;SEQ_SOLDINI_CODSOLDINI&apos;,TRUE);

    INSERT INTO SOLDINI(CODSOLDINI, CODPART)
    SELECT SEQ_SOLDINI_CODSOLDINI.NEXTVAL, CODPART
    FROM (
      SELECT DISTINCT CODPART
      FROM NPARTSOLDLUNA
      WHERE AN = AN_INITIALIZARI AND LUNA = LUNA_INITIALIZARI AND (Coalesce(SOLDLEI, 0) &lt;&gt; 0 OR Coalesce(SOLDVALUTA, 0) &lt;&gt; 0)
    );
    COMMIT;
  END IF;
END;

PROCEDURE DO_RUPERE_FIRMA(pAN IN NUMBER, pLUNA IN NUMBER, pFixareLuniInchise IN BOOLEAN) IS
  TYPE t_tab_vc2 IS TABLE OF VARCHAR2(200);
  bulk_trg t_tab_vc2;
  vNrU NUMERIC;
  UTILIZATORI_LOGATI exception;
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT Count(1) FROM winmadmin.firma f inner join winmadmin.utilizator u ON u.firmaactiva = f.codfirma WHERE Upper(f.skemafirma) = USER&apos; INTO vNrU;

  IF vNrU &gt; 0 THEN
    RAISE UTILIZATORI_LOGATI;
  END IF;

  CREATE_RF_CTC_AUXCOD;
  bReuse_RF_CTC_AUXCOD := TRUE;

  PKG_GLOBALS.PUT_INFO(&apos;00.AA&apos;,&apos;START&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE INFOBUFFER&apos;;

  PKG_GLOBALS.PUT_INFO(&apos;00.BA&apos;,&apos;SETARE LUNA LUCRU&apos;);
  SetAnLunaRupere(pAN, pLUNA);
  PKG_GLOBALS.SETLUNALUCRU(AN_RUPERE, LUNA_RUPERE);

  PKG_GLOBALS.PUT_INFO(&apos;00.CA&apos;,&apos;MAKE CONFIG LUNA&apos;);
  PKG_STOC_GENERARE_FACTURI.make_config_luna;

  PKG_GLOBALS.PUT_INFO(&apos;00.DA&apos;,&apos;DISABLE TRIGGERS&apos;);
  EXECUTE IMMEDIATE &apos;SELECT trigger_name FROM user_triggers WHERE status = &apos;&apos;ENABLED&apos;&apos;&apos; BULK COLLECT INTO bulk_trg;
  FOR i IN 1..bulk_trg.Count LOOP
    EXECUTE IMMEDIATE &apos;ALTER TRIGGER &apos;||bulk_trg(i)||&apos; DISABLE&apos;;
  END LOOP;

  PKG_GLOBALS.PUT_INFO(&apos;01.AA&apos;,&apos;FIXARI LUNI&apos;);
  DO_FIXARI_LUNI(pFixareLuniInchise);

  PKG_GLOBALS.PUT_INFO(&apos;02.AA&apos;,&apos;FIXARI TREZOR INI&apos;);
  FIXEAZA_INITILIZARE_TREZOR;

  PKG_GLOBALS.PUT_INFO(&apos;03.AA&apos;,&apos;FIXARI COMANDA1 INI&apos;);
  FIXEAZA_INITILIZARE_COMENZI;

  PKG_GLOBALS.PUT_INFO(&apos;04.AA&apos;,&apos;FIXARI STOC INI&apos;);
  FIXEAZA_INITILIZARE_STOCURI;

  PKG_GLOBALS.PUT_INFO(&apos;05.AA&apos;,&apos;FIXARI STOCVAL INI&apos;);
  FIXEAZA_INITILIZARE_STOCVAL;

  PKG_GLOBALS.PUT_INFO(&apos;06.AA&apos;,&apos;REZOLVA LITIGII&apos;);
  REZOLVA_LITIGII;

  PKG_GLOBALS.PUT_INFO(&apos;07.AA&apos;,&apos;FIXARI SOLD INI - RECALCUL_LINIE_TVAINCASARE&apos;);
  RECALCUL_LINIE_TVAINCASARE;--recalculul asta trebuie facut inainte de a modifica valorile obligatiilor

  PKG_GLOBALS.PUT_INFO(&apos;08.AA&apos;,&apos;FIXARI SOLD INI - FIXEAZA_INITILIZARE_SOLDURI&apos;);
  FIXEAZA_INITILIZARE_SOLDURI; -- contine stergeri de obligatii stingatoare

  PKG_GLOBALS.PUT_INFO(&apos;09.AA&apos;,&apos;FIXARI AVIZINT INI&apos;);
  FIXEAZA_AVIZINT_INITIAL;

  PKG_GLOBALS.PUT_INFO(&apos;10.AA&apos;,&apos;FIXARI AVIZIES INI&apos;);
  FIXEAZA_AVIZIES_INITIAL;

  PKG_GLOBALS.PUT_INFO(&apos;11.AA&apos;,&apos;SET FIRMALUNI&apos;);
  SETEAZA_VALORI_FIRMALUNI;

  PKG_GLOBALS.PUT_INFO(&apos;12.AA&apos;,&apos;SETEZE RESTTVA IN GENERAL&apos;);
  SET_RESTTVA;

  PKG_GLOBALS.PUT_INFO(&apos;13.AA&apos;,&apos;STERGE DOC ANTERIOARE&apos;);
  STERGE_DOCUMENTE_LUNI_ANTER; -- contine stergeri de obligatii

  PKG_GLOBALS.PUT_INFO(&apos;14.AA&apos;,&apos;STERGE FIXARI ANTERIOARE&apos;);
  STERGE_FIXARI_LUNARE_ANTER;

  PKG_GLOBALS.PUT_INFO(&apos;15.AA&apos;,&apos;CURATA DETALII LA NIVEL DE LUNA&apos;);
  DO_CURATA_DETLUNA;

  PKG_GLOBALS.PUT_INFO(&apos;16.AA&apos;,&apos;CURATA CONSTANTE&apos;);
  DO_CURATA_CONSTANTE;

  PKG_GLOBALS.PUT_INFO(&apos;17.AA&apos;,&apos;REZOLVA CURS REGULARIZAT PART &apos;);
  DO_SOLVE_CURS_REG_PART;

  PKG_GLOBALS.PUT_INFO(&apos;18.AA&apos;,&apos;SET FLAG INITIALIZARI LA TVAINCASARE&apos;);
  DO_SET_FLAG_INITIALIZARI;

  PKG_GLOBALS.PUT_INFO(&apos;19.AA&apos;,&apos;BLOCHEAZA DURATA MIFIX&apos;);
  DO_BLOCHEAZA_DURATA_MIFIX;

  PKG_GLOBALS.PUT_INFO(&apos;20.AA&apos;,&apos;REZOLVA INCOERENTE&apos;);
  DO_REZOLVA_INCOERENTE;

  -- STEF ??? Exista o procedura de curatare jurnale, dar nu era apelata
  -- aici se curata o cantitate mare de date BD - am sa o apelez si facem analiza daca e buna sau nu
  PKG_GLOBALS.PUT_INFO(&apos;21.AA&apos;,&apos;CURATARE JURNALE&apos;);
  CURATA_JURNALE;

  --STEF -- urmeaza cateva proceduri pentru alte tabele destul de mari care nu se curatau pana acuma - sper ca e ok abordarea
  PKG_GLOBALS.PUT_INFO(&apos;22.AA&apos;,&apos;CURATARE LANSZ&apos;);
  CURATA_LANSZ;

  PKG_GLOBALS.PUT_INFO(&apos;23.AA&apos;,&apos;CURATA TABELE PROD&apos;);
  CURATA_XXXPROD;

  PKG_GLOBALS.PUT_INFO(&apos;24.AA&apos;,&apos;CURATA STAREESTIMARI&apos;);
  CURATA_STAREESTIMARI;

  PKG_GLOBALS.PUT_INFO(&apos;25.AA&apos;,&apos;CURATA PREDARIPLUS&apos;);
  CURATA_PREDARIPLUS;

  PKG_GLOBALS.PUT_INFO(&apos;30.AA&apos;,&apos;CURATA DECLARATII&apos;);
  CURATA_DECLARATII;

  PKG_GLOBALS.PUT_INFO(&apos;84.AA&apos;,&apos;CURATARE EXPERT&apos;);
  CURATA_EXPERT;

  PKG_GLOBALS.PUT_INFO(&apos;85.AA&apos;,&apos;CURATARE REGULARIZARI&apos;);
  CURATA_REG;

  PKG_GLOBALS.PUT_INFO(&apos;86.AA&apos;,&apos;CURATARE MIJLOACE FIXE&apos;);
  CURATA_MIFIX;

  PKG_GLOBALS.PUT_INFO(&apos;87.AA&apos;,&apos;CURATARE INVENTAR&apos;);
  CURATA_INVENTAR;

  PKG_GLOBALS.PUT_INFO(&apos;88.AA&apos;,&apos;CURATARE TABELA DOCUMENTE&apos;);
  CURATA_TAB_DOCUMENTE;

  PKG_GLOBALS.PUT_INFO(&apos;89.AA&apos;,&apos;CURATARE - MONITORIZARE MODIFICARI&apos;);
  CURATA_MODIF;

  PKG_GLOBALS.PUT_INFO(&apos;90.AA&apos;,&apos;REFACERE NIRSTOC1&apos;);
  PKG_PRETPROD.PopuleazaNirStoc1;

  --STEF -- tabele care nu cred ca mai trebuie - sper ca e ok abordarea
  PKG_GLOBALS.PUT_INFO(&apos;91.AA&apos;,&apos;CURATARE LST_BALANTA_...&apos;);
  CURATA_LST_BALANTA;

  --STEF -- extensii
  PKG_GLOBALS.PUT_INFO(&apos;92.AA&apos;,&apos;CURATARE TABELE EXTENSII&apos;);
  CURATA_TAB_EXTENSII;

  PKG_GLOBALS.PUT_INFO(&apos;93.AA&apos;,&apos;CURATARE TABELE DIVERSE&apos;);
  CURATA_TAB_DIVERSE;

  PKG_GLOBALS.PUT_INFO(&apos;98.AA&apos;,&apos;ENABLE TRIGGERS&apos;);
  FOR i IN 1..bulk_trg.Count LOOP
    BEGIN
      EXECUTE IMMEDIATE &apos;ALTER TRIGGER &apos;||bulk_trg(i)||&apos; ENABLE&apos;;
    EXCEPTION WHEN OTHERS THEN
      PKG_GLOBALS.PUT_INFO(&apos;98.AB. ERR &apos;||bulk_trg(i), sqlerrm);
    END;
  END LOOP;
  bulk_trg := t_tab_vc2();

  PKG_GLOBALS.PUT_INFO(&apos;99.ZZ&apos;,&apos;GATA&apos;);

  COMMIT;

  DROP_TABLE(&apos;RF_CTC_AUXCOD&apos;);
EXCEPTION
  WHEN UTILIZATORI_LOGATI THEN DBMS_OUTPUT.PUT_LINE(&apos;Ruperea de firma nu poate fi executata cu utilizatori activi in WME.&apos;);
END;

END PKG_RUPERE_FIRMA;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SABLONDESCRIPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F1B2BC9FD952E733C23C2CBD00A6EFA936CDF48</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SABLONDESCRIPT IS
 

 PROCEDURE SP_INSERTRECORD IS
 BEGIN
  INSERT INTO tmp_SABLONDESCRIPT(CODSABLON) VALUES(0);
  COMMIT;
 END;
 
 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
 TMP NUMBER(20);
 BEGIN
   SELECT CODSABLON INTO TMP FROM SABLONDESCRIPT WHERE CODSABLON = RECID FOR UPDATE NOWAIT;
 END;
 
 PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
 BEGIN
   SP_LOCKRECORD(RECID);
   DELETE FROM SABLONDESCRIPT1 WHERE CODSABLON = RECID;
   DELETE FROM SABLONDESCRIPT  WHERE CODSABLON = RECID;
   NotifyModif(2, RecId, &apos;SABLONDESCRIPT&apos;);
   COMMIT;
 END;
 
 PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
 BEGIN
  INSERT INTO TMP_SABLONDESCRIPT(CODSABLON,DENUMIRE,SIMBOL,CODDESCRIPTOR)
   SELECT CODSABLON,DENUMIRE,SIMBOL,CODDESCRIPTOR FROM SABLONDESCRIPT WHERE CODSABLON = RECID;
   
  INSERT INTO TMP_SABLONDESCRIPT1(CODSABLON1,CODSABLON,CODDESCRIPTOR1,PROCENT,Valoare)
   SELECT S1.CODSABLON1,S1.CODSABLON,S1.CODDESCRIPTOR1,S1.PROCENT,D1.Valoare
     FROM SABLONDESCRIPT1  S1 INNER JOIN DESCRIPTORI1 D1 ON S1.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
     WHERE S1.CODSABLON = RECID;  
   
  COMMIT; 
 END;
 
 PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER ) IS
 BEGIN
  IF OPERATION = 0 THEN --UPDATE
    SELECT CODSABLON INTO RECID FROM TMP_SABLONDESCRIPT;
    
    UPDATE SABLONDESCRIPT SET (DENUMIRE,SIMBOL,CODDESCRIPTOR)=
     (SELECT DENUMIRE,SIMBOL,CODDESCRIPTOR FROM TMP_SABLONDESCRIPT)
    WHERE CODSABLON = RECID;
    
    DELETE FROM SABLONDESCRIPT1 WHERE CODSABLON = RECID AND CODSABLON1 NOT IN (SELECT CODSABLON1 FROM TMP_SABLONDESCRIPT1);
    
    INSERT INTO SABLONDESCRIPT1(CODSABLON1,CODSABLON,CODDESCRIPTOR1,PROCENT) 
     SELECT SEQ_SABLONDESCRIPT1_CODSABLON1.NEXTVAL,RECID,CODDESCRIPTOR1,PROCENT FROM TMP_SABLONDESCRIPT1 WHERE CODSABLON1 &lt;=0;
   
    FOR V_REC IN (SELECT * FROM TMP_SABLONDESCRIPT1 WHERE CODSABLON &gt; 0 ) LOOP
      UPDATE SABLONDESCRIPT1 SET
       CODDESCRIPTOR1 = V_REC.CODDESCRIPTOR1,
       PROCENT        = V_REC.PROCENT
      WHERE  CODSABLON1 = V_REC.CODSABLON1;
    END LOOP;
      
  ELSE --INSERT
    SELECT SEQ_SABLONDESCRIPT_CODSABLON.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO SABLONDESCRIPT(CODSABLON,DENUMIRE,SIMBOL,CODDESCRIPTOR)
     SELECT RECID,DENUMIRE,SIMBOL,CODDESCRIPTOR FROM TMP_SABLONDESCRIPT;
     
    INSERT INTO SABLONDESCRIPT1(CODSABLON1,CODSABLON,CODDESCRIPTOR1,PROCENT)
     SELECT SEQ_SABLONDESCRIPT1_CODSABLON1.NEXTVAL,RECID, CODDESCRIPTOR1,PROCENT FROM TMP_SABLONDESCRIPT1;
  END IF;
   NotifyModif(Operation, RecId, &apos;SABLONDESCRIPT&apos;);
   COMMIT;
 END;

 FUNCTION GET_VALORI_DESCRIPTOR(ACODDESCRIPTOR IN NUMBER) RETURN CRS IS 
  CRESULT  CRS;
 BEGIN
   BEGIN
      OPEN CRESULT FOR 
       SELECT D1.CODDESCRIPTOR1,D1.VALOARE
       FROM DESCRIPTORI1 D1 WHERE D1.CODDESCRIPTOR = ACODDESCRIPTOR;
   EXCEPTION WHEN OTHERS THEN
    OPEN CRESULT FOR SELECT -1 CODDESCRIPTOR1, &apos;-1&apos; VALOARE FROM DUAL;
   END;    
   
   RETURN CRESULT;
   
    
 END;

end pkg_sablondescript; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAFT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF33BD49AC8A70CAA6F8A1CABF2A581D4A2C20C2</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAFT IS

  pSaftDebug BOOLEAN;

-- constante CODAF -&gt; majoritatea legate de firma proprie
--01 -&gt;CODSAF_HEADER
--02 -&gt;CODSAF_SELECTIONCRITERIA
--06 -&gt;CODSAF_COMPANYSTRUCTURE
--07 -&gt;CODSAF_ADDRESS
--08 -&gt;CODSAF_CONTACT
--09 -&gt;CODSAF_CONTACTPERSON NUMERIC(20,0)
--10 -&gt;CODSAF_TAXREGISTRATION
--11 -&gt;CODSAF_BANKACCOUNT
--12 -&gt;CODSAF_TAXTABLEENTRY  -&gt; 000
--13 -&gt;CODSAF_TAXCODEDETAILS -&gt; 000
--20 -&gt;CODSAF_STOCKCHARACTERISTICS
--25 -&gt;CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD -&gt; 0
--26 -&gt;CODSAF_GENERALLEDGERENTRIES -&gt; 0
--33 -&gt;CODSAF_SALESINVOICES  -&gt; 0
--46 -&gt;CODSAF_PURCHASEINVOICES  -&gt; 0
--47 -&gt;CODSAF_PAYMENTS  -&gt; 0
--52 -&gt;CODSAF_MOVEMENTOFGOODS
--56 -&gt;CODSAF_ASSETTRANSACTIONS

--99 -&gt;CODSAF_AMOUNT -&gt; VALOARE 0

PROCEDURE TestTaxDecl IS
BEGIN
--  PKG_STOC_GENERARE_FACTURI.TESTARE;
--  PKG_SAFT.BEGIN_SAFT(1,2022,1,1);
  PKG_GLOBALS.SETCODFIRMA(5490); COMMIT;
  --6198 TESTE13
  PKG_SAFT.UpdateTaxDecl(1, 20473);
END;

PROCEDURE ActulizareCodSaftInNCont IS --propagare CodSaft de la radacina spre frunza
BEGIN
  FOR vRec IN (
    WITH /*recursive*/ cRec (CODCONT, CODSAFT) AS (
      SELECT C.CODCONT, C.CODSAFT
      FROM NCONT C
      WHERE Coalesce(c.codparinte, 0) = 0 AND C.CODCONT &lt;&gt; 0
      UNION ALL
      SELECT C.CODCONT, Coalesce(C.CODSAFT, CR.CODSAFT)
      FROM NCONT C INNER JOIN cRec cr ON cr.codcont = C.codparinte
    )
    SELECT CS.CODCONT, CS.CODSAFT
    FROM cRec CS INNER JOIN NCONT C ON C.CODCONT = CS.CODCONT
    WHERE CS.CODSAFT IS NOT NULL AND NULLIF(C.CODSAFT, &apos;&apos;) IS NULL
  ) LOOP
    UPDATE NCONT SET CODSAFT = vRec.CODSAFT WHERE CODCONT = vRec.CODCONT;
  END LOOP;
END;

/*
PROCEDURE UpdateDiscMonLuna(pAn IN NUMBER, pLuna IN NUMBER) IS
BEGIN
  FOR vRec IN (
    WITH Discount AS(
      SELECT I1.CodIes, Round(T.Procent,0) ProcTVA, Round(Sum(Coalesce(i1.ValDiscPret, 0)),2) VDisc,  Round(Sum(Coalesce(i1.ValDiscPret, 0)*T.Procent / (100+T.Procent)),2) TVADisc
      FROM (
          SELECT I.CodIes, Sum(Coalesce(I1.ValDiscPret,0)) SumDisc
          FROM Iesiri I INNER JOIN Iesiri1 I1 ON I1.CodIes = I.CodIes
          WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
          GROUP BY I.CodIes
          HAVING Sum(Coalesce(I1.ValDiscPret,0)) &lt;&gt; 0
        ) DiscPeLinie
        LEFT JOIN IESIRI1 I1 ON I1.CODIES = DiscPeLinie.CODIES
        LEFT JOIN (
          SELECT I1.CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1) Procent
          FROM Iesiri I
            INNER JOIN Iesiri1 I1 ON I1.CodIes     = I.CodIes
            LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
            LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
            LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
          WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
        ) T ON I1.CodIes1 = T.CodIes1
      GROUP BY I1.CodIes, Round(T.Procent,0)
    )
    SELECT I.CodIes, D.VDisc, D.TVADisc
    FROM iesiri I
      INNER JOIN (
        SELECT CodIes, Sum(VDisc) VDisc, Sum(TVADisc) TVADisc
        FROM Discount
        GROUP BY CodIes
      ) D ON D.CodIEs = I.CodIes
      LEFT JOIN (
        SELECT CodIes, Round(Sum(Coalesce(DISCOUNT, 0)),2) VDisc, Round(Sum(Coalesce(TVADISCOUNT, 0)),2) TVADisc
        FROM DiscMonetar
        GROUP BY CodIes
      ) DM ON DM.CodIes = I.CodIes
    WHERE
      Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(D.VDisc   ,0) or
      Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(D.TVADisc ,0) or
      Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(DM.VDisc  ,0) or
      Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(DM.TVADisc,0)
  ) LOOP
    Update Iesiri set VALDISCOUNT = Round(vRec.VDisc, 2), TVADISCOUNT= Round(vRec.TVADisc, 2) WHERE CodIEs = vRec.CodIes;
    Update Jurnal1 set Dirty = 1 WHERE TipDoc = 16 and CodDoc = vRec.CodIes;
    Delete Discmonetar WHERE CodIes = vRec.CodIes;
    Insert into DiscMonetar (CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
    SELECT SEQ_DISCMONETAR_CODDISCMONETAR.NextVal, CodIes, ProcTVA, VDisc,  TVADisc
    FROM (
      SELECT
        I.CodIes, Round(T.Procent,0) ProcTVA,
        Round(Sum(Coalesce(i1.ValDiscPret, 0)),2) VDisc,
        Round(Sum(Coalesce(i1.ValDiscPret, 0)*T.Procent / (100+T.Procent)),2) TVADisc
      FROM IESIRI i
        INNER JOIN Iesiri1 I1 ON I1.CodIes = I.CodIes
        INNER JOIN (
          SELECT CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1) Procent
          FROM Iesiri1 I1
            INNER JOIN Iesiri  I  ON i.CodIes      = I1.CodIes
            LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
            LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
            LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
        ) T ON I1.CodIes1 = T.CodIes1
      WHERE I.CodIes = vRec.CodIes
      GROUP BY I.CodIes, Round(T.Procent,0)
    );
  END LOOP;
  COMMIT;
END;
*/

PROCEDURE UpdateDiscMonLuna(pAn IN NUMBER, pLuna IN NUMBER) IS
  vCount INTEGER;
BEGIN
  -- new tratament bulk si nu mai limitez dupa ValDiscPret &lt;&gt; 0 (pentru orice eventualitate)
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DiscMonetar&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
  INSERT INTO TMP_DiscMonetar  (CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
  WITH D1 AS(
    SELECT CodIes, ProcTVA, Round(Sum(ValDiscPret),2) VDisc, Round(Sum(ValDiscPret)*ProcTVA/(100+ProcTVA),2) TVADisc, Max(CASE WHEN ValDiscPret &lt;&gt; 0 THEN 1 ELSE 0 END) AmDiscPret
    FROM (
      SELECT
        I.CodIes, Coalesce(I1.ValDiscPret,0) ValDiscPret,
        Round(PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1),0) ProcTVA
      FROM Iesiri I
        INNER JOIN Iesiri1 I1 ON I1.CodIes = I.CodIes
        LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
        LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
        AND Coalesce(I1.ValDiscPret,0) &lt;&gt; 0
    ) subs
    GROUP BY CodIes, ProcTva
  ),
  D2 AS(
    SELECT I.CodIes, DM.PROCTVA, Min(DM.CodDiscMonetar) CodDiscMonetar, Sum(DM.DISCOUNT) VDisc , Sum(DM.TVADISCOUNT) TVADisc
    FROM Iesiri I INNER JOIN DiscMonetar DM ON DM.CodIes = I.Codies
    WHERE i.tipdoc = 16 AND I.An = pAn AND I.Luna = pLuna
    GROUP BY I.CodIes, DM.PROCTVA
  ),
  D AS (
    SELECT
      D2.CodDiscMonetar, Coalesce(D1.Codies, D2.Codies) Codies, Coalesce(D1.ProcTva, D2.ProcTva) ProcTva, D1.VDisc, D1.TVADisc,
      Max(
        CASE
          WHEN Coalesce(D1.VDisc  , 0) &lt;&gt; Coalesce(D2.VDisc  , 0) THEN 1
          WHEN Coalesce(D1.TVADisc, 0) &lt;&gt; Coalesce(D2.TVADisc, 0) THEN 1
          ELSE 0
        END
      )                               OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) DifPeProc,
      Max(Coalesce(D1.AmDiscPret, 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) AmDiscPret,
      Sum(Coalesce(D1.VDisc     , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S1VDisc,
      Sum(Coalesce(D1.TVADisc   , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S1TVADisc,
      Sum(Coalesce(D2.VDisc     , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S2VDisc,
      Sum(Coalesce(D2.TVADisc   , 0)) OVER (PARTITION BY Coalesce(D1.Codies, D2.Codies)) S2TVADisc
    FROM d1 FULL JOIN d2 ON d1.CodIes = d2.CodIes AND d1.ProcTVA = d2.ProcTVA
  )
  SELECT D.CodDiscMonetar, D.CodIes, D.ProcTva, D.VDisc, D.TVADisc
  FROM D LEFT JOIN IESIRI I ON I.Codies = D.CodIes
  WHERE (
          Coalesce(D.DifPeProc  ,0) &lt;&gt; 0                       OR
          Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(D.S1VDisc  ,0) OR
          Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(D.S1TVADisc,0) OR
          Coalesce(I.VALDISCOUNT,0) &lt;&gt; Coalesce(D.S2VDisc  ,0) OR
          Coalesce(I.TVADISCOUNT,0) &lt;&gt; Coalesce(D.S2TVADisc,0)
        );
  --AND   Coalesce(D.AmDiscPret ,0) &lt;&gt; 1 -- de vazut daca dorim limitare la Monetare care au cel putin o linie cu ValDiscPret &lt;&gt; 0

  INSERT INTO TMP_MANEVRA2(CODUNIC) SELECT DISTINCT CODIES FROM TMP_DiscMonetar;
  SELECT Count(1) INTO vCount FROM TMP_MANEVRA2;
  IF vCount &gt; 0 THEN
    UPDATE Iesiri I
    SET (VALDISCOUNT, TVADISCOUNT) = (SELECT Sum(Coalesce(DISCOUNT,0)) , Sum(Coalesce(TVADISCOUNT,0)) FROM TMP_DiscMonetar T WHERE T.CodIes = I.CodIes)
    WHERE CodIes IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    UPDATE Jurnal1
    SET Dirty = 1
    WHERE TipDoc = 16
      AND CodDoc IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    DELETE FROM TMP_DiscMonetar WHERE DISCOUNT IS NULL;
    DELETE FROM Discmonetar     WHERE CodIes IN (SELECT CODUNIC FROM TMP_MANEVRA2);

    INSERT INTO DiscMonetar(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
    SELECT Coalesce(CODDISCMONETAR, SEQ_DISCMONETAR_CODDISCMONETAR.NEXTVAL), CODIES, PROCTVA, DISCOUNT, TVADISCOUNT
    FROM TMP_DiscMonetar;
    COMMIT;
  END IF;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_DiscMonetar&apos;;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
END;

PROCEDURE UpdateTaxDeclLuna(pAn IN NUMBER, pLuna IN NUMBER) IS
BEGIN
  FOR vRec IN (
    SELECT 0 AS CAZ, Codintr   AS CODDOC FROM intrari WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (1,3,4,5,9) UNION ALL
    SELECT 1 AS CAZ, Codies    AS CODDOC FROM iesiri  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (19,21,26)  UNION ALL
    SELECT 2 AS CAZ, Codies    AS CODDOC FROM iesiri  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (16)        UNION ALL
    SELECT 3 AS CAZ, CodTrezor AS CODDOC FROM trezor  WHERE an = pAn AND luna = pLuna AND Operat = 1 AND TipDoc IN (29,30,33)
  ) LOOP
    PKG_SAFT.UpdateTaxDecl(vRec.CAZ, vRec.CODDOC);
  END LOOP;
END;

PROCEDURE UpdateTaxDecl(pCaz NUMBER, pCodDoc NUMBER) IS
  aCod             NUMBER(20);
  aNeded           NUMBER;
  cTaxCode         VARCHAR2(30);
  aTax             NUMBER(20);
  cTaxa            VARCHAR2(30);
  cTd1             VARCHAR2(20);
  cTd2             VARCHAR2(20);
  cTx1             VARCHAR2(20);
  cTx2             VARCHAR2(20);
  cTxP             VARCHAR2(20);
  crTd1            VARCHAR2(20);
  crTx1            VARCHAR2(20);
  Taxa2            VARCHAR2(20);
  DoServCaStoc     BOOLEAN;
  bArt0            BOOLEAN;
  bArt1            BOOLEAN;
  bArt2            BOOLEAN;
  cCod1            VARCHAR2(30);
  cCod2            VARCHAR2(30);
  cCod3            VARCHAR2(30);
  cCod4            VARCHAR2(30);
  cCod5            VARCHAR2(30);
  cCod6            VARCHAR2(30);
  cCod7            VARCHAR2(30);
  cCod8            VARCHAR2(30);
  cKeia            VARCHAR2(300);
  aCODINTR1        Number(20);
	SuplimTipDoc3    Number(20,7);
  aValLinie        Number(20,7);
  aTVALinie        Number(20,7);
  aTaxBase         Number(20,7);
  aTaxVal          Number(20,7);

  aVal             Number(20,7);
  aDisc            Number(20,7);
  aProcTVADoc      Number(20,7);
  aTotBase         Number(20,7);
  aTotVal          Number(20,7);
  KIncas           Number(20,7);
  BazaTVAMarja     Number(20,7);
  aContSaft        Number(20);
  aTipDoc          Number(20);
  aAnulat          Number(1);
  aOperat          Number(1);
  aManual          Number(1);
  aTipTranzactie   Number(2);
  aTipTVA          Number(2);
  aTipFactura      Number(5);
  ArtIncasUlterior Number(20);
  IOArtIncasImed   Number(20);
  TVA0FaraDed      Number(20);
  aAn              Number(10);
  aLuna            Number(3);
  aCoefIO          Number(2);
	Semn             Number;
  aSubunit         Number(20);
	aCodFirma        NUMBER(20):= PKG_GLOBALS.GETCODFIRMA;
  aCursLinie       Number(1);
  ContTrezor       Number(20);

  FUNCTION  FirmaPlatitorTVA(pSubunit NUMBER, pAn number, pLuna number) RETURN Number IS
    aHolding        BOOLEAN  := &apos;1&apos; = Coalesce(pkg_categconst.GetValConstanta(&apos;Holding&apos; ,pAn,pLuna),&apos;2&apos;);
		CFisc           Varchar2(13);
    SubunitTVA      Number(1);
  BEGIN
		Select Coalesce(EFACT,0) into SubunitTVA from NSubunit where CodSubunit = pSubunit;
    IF (aHolding or (SubunitTVA = 1))AND (pSubunit &lt;&gt; 1) THEN
			SELECT S.CIF       INTO CFisc FROM NSUBUNIT S        WHERE S.CODSUBUNIT = pSubunit;
		ELSE
      -- la un client INFORMEDIA genera eroare merg pe loop sa aduc codul fiscal
      for v_rec in (
  			SELECT F.CODFISCAL FROM WINMADMIN.FIRMA F WHERE F.CODFIRMA = aCODFIRMA
      ) loop
        CFisc := v_rec.codfiscal;
        exit;
      end loop;
		END IF;
		RETURN InStr(Upper(CFisc),&apos;RO&apos;);
	END;

BEGIN
  pkg_globals.SetSeparator(&apos;,&apos;);
  aCursLinie := Coalesce(pkg_categconst.GetValConstanta(&apos;ContabCursLinie&apos; ,PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU),&apos;2&apos;);

  IF pCaz = 0 THEN
    SELECT TipDoc,  TipTranzactie,  TipTVA, Coalesce(TipFactura, 0), Coalesce(Anulat, 0), Coalesce(Operat, 1), Subunitatea
    INTO   aTipDoc, aTipTranzactie, aTipTVA, aTipFactura,            aAnulat,             aOperat,             aSubunit
    FROM Intrari
    WHERE CodIntr = pCodDoc;
    IF aAnulat = 1 OR aOperat = 0 or aTipFactura = 2 or (aTipTranzactie IN (4,5) and aTipDoc &lt;&gt; 2 and aTipTVA = 1) THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc;
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc AND MANUAL = 0;
      FOR vRec IN (
        WITH Intr (CodIntr, TipDoc, DataDoc, TVAIncasare, AnLuna, An, Luna, Curs, PlatitorTVA, Taxa1, TipTranzactie, TipTVA, Taxa2, TaxaI, Cheia1, Cheia2, RotEFact)
        AS (
          SELECT
            I.CodIntr, I.TipDoc, I.DataDoc, I.TVAIncasare, I.An*12+I.Luna AnLuna, I.An, I.Luna, Coalesce(NULLIF(I.Curs,0),1) Curs,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt; Chr(64) THEN &apos;1&apos; ELSE &apos;0&apos; END PlatitorTVA,
            CASE
              WHEN T.SimbAuto = &apos;RO&apos; THEN &apos;2&apos;
              WHEN Coalesce(T.STATCOMUNITAR,0) = 0 THEN &apos;0&apos;
              ELSE
                CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt; Chr(64)
                     THEN case
                            WHEN T.SimbAuto = SubStr(PCF.CodFiscal,1,2) then &apos;1&apos;
                            else &apos;3&apos;
                          end
                     ELSE &apos;1&apos;
                END
            END ||&apos;.&apos;||To_Char(TipTranzactie,&apos;FM900&apos;) Taxa1,
            I.TipTranzactie, I.TipTVA,
            CASE WHEN (TipSaft = 2)or(Extract(Year FROM I.DataDoc)*12+Extract(Month FROM I.DataDoc) &lt;&gt; I.An*12+I.Luna) THEN &apos;2&apos;
                 ELSE &apos;9&apos; END||&apos;.&apos;||Coalesce(TVAIncasare,0) Taxa2,
            CASE WHEN T.SimbAuto = &apos;RO&apos; THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||&apos;.&apos;||To_Char(TipTranzactie,&apos;FM900&apos;)||&apos;.&apos;||TipTVA||&apos;.&apos;||CASE WHEN TipSaft = 2 THEN &apos;2&apos; ELSE &apos;9&apos; END||&apos;.&apos;||Coalesce(TVAIncasare,0) TaxaI,
            CASE WHEN T.SimbAuto = &apos;RO&apos; THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||&apos;.&apos;||To_Char(TipTranzactie,&apos;FM900&apos;) Cheia1, TipSaft||&apos;.&apos;||Coalesce(TVAIncasare,0) Cheia2,
            I.RotEFact
          FROM  Intrari I
            LEFT JOIN NAGENDA      A   ON A.CODAGENDA = I.CodLocatie AND A.codpart = I.Partener
            LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = Coalesce(A.CODLOCALIT, 0)
            LEFT JOIN NTARI        T   ON T.CODTARA = Coalesce(L.CODTARA, 0)
            LEFT JOIN NPARTCODFISC PCF ON PCF.Cod_CODFISCAL = Coalesce(I.CodFiscal,0)
          WHERE CodIntr = pCodDoc
        )
        SELECT
          I1.CodIntr, I1.CodIntr1, I.TipDoc, I.An, I.Luna, I.AnLuna, I.TVAIncasare, I.PlatitorTVA, I.Cheia1, I.Cheia2, I.Taxa1, I.Taxa2, Coalesce(I1.Impozabil,0) Impozabil,
          Coalesce(D1.PretImport,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.PretOrig, I1.PU)*Coalesce(I1.CoefDiscMaj,1)) * I1.Cant Valoare,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*D1.PretValuta * I1.Cant ValoareDVI, Coalesce(D.TaxeIncluse,0) TaxeIncluse,
          CASE
            WHEN I.TIPDOC = 3
            THEN Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0)*Coalesce(I1.CoefDiscMaj,1)* CASE WHEN I1.ADDim = -100 THEN 0 ELSE 1/(1+Coalesce(I1.ADDim/100,0)) END
            ELSE Coalesce(D1.TVA,Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0))
          END TVA,
          TL.CODCONTDED, TL.CODCONTCOLE, TL.procent ProcTVAArt, I.TipTVA, I.TipTranzactie,
          A.TipArticol,
          CASE WHEN TL.PROCENT IS NULL THEN &apos;?&apos; WHEN TL.PROCENT = 0 THEN &apos;0&apos; ELSE &apos;1&apos; END CotaArtZero, I1.TVANEDED, I1.Codobiect,
          Coalesce(
            NULLIF(AE1.ContServ, 0),
            CASE
              WHEN D1.CodDVI1 IS NOT NULL AND AE1.CodIntr1 = I1.CodIntr1
              THEN
                COALESCE (
                  (
                    SELECT Min(io1.cont)
                    FROM nirstoc ns INNER JOIN ioart1 io1 ON io1.codioart = ns.codioart
                    WHERE ns.coddvi1 = D1.CodDVI1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  ),
                  (
                    SELECT Min(io1.cont)
                    FROM livr1 l1
                      LEFT JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
                      LEFT JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
                      LEFT JOIN ioart1 io1 ON io1.codioart  = Coalesce(lv.CodIOArt, ns.codioart)
                    WHERE l1.coddvi1 = D1.CodDVI1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  )
                )
              ELSE
                COALESCE (
                  (
                    SELECT Min(io1.cont)
                    FROM nirstoc ns INNER JOIN ioart1 io1 ON io1.codioart = ns.codioart
                    WHERE ns.codintr1 = ae1.codintr1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  ),
                  (
                    SELECT Min(io1.cont)
                    FROM livr1 l1
                      LEFT JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
                      LEFT JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
                      LEFT JOIN ioart1 io1 ON io1.codioart  = Coalesce(lv.CodIOArt, ns.codioart)
                    WHERE l1.codintr1 = ae1.codintr1 AND Coalesce(io1.cont, 0) &lt;&gt; 0
                      AND i.AnLuna BETWEEN io1.ALStart AND io1.ALStop
                  )
                )
            END
          ) ContSaft, I.DataDoc, Coalesce(I1.TVA, 0) TVALinie, Coalesce(AL.TaxCode, 0) TaxCodeArt,
          I.RotEFact, TD.Manual
        FROM Intr I
          INNER JOIN Intrari1 I1  ON I1.CodIntr    = I.CodIntr
          LEFT  JOIN DVI      D   ON D.CodIntr     = I.CodIntr
          LEFT  JOIN DVI1     D1  ON D1.CodIntr1   = I1.CodIntr1
          LEFT  JOIN IntrLink IK  ON IK.CodIntr1   = I1.CodIntr1
          LEFT  JOIN Intrari1 AE1 ON AE1.CodIntr1 = Coalesce(IK.CodLinieAviz, I1.CodIntr1)
          LEFT  JOIN NArtOBJ  O   ON O.CodObiect   = I1.CodObiect
          LEFT  JOIN NArt     A   ON A.CodArticol  = O.CodArticol
          LEFT  JOIN NArt1    AL  ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1    TL  ON TL.CodTVA     = AL.CodTVA AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
          LEFT  JOIN TAXDECL  TD  ON TD.TipDoc     = I.Tipdoc AND TD.Coddoc = I.CodIntr AND TD.Coddoc1 = I1.CODIntr1
        WHERE (Coalesce(I1.Impozabil, 0) &lt;&gt; 4)
--          AND (Coalesce(TD.Manual, 0) &lt;&gt; 1)
          AND (NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;))
          AND (Coalesce(I1.Cant,0) &lt;&gt; 0)
      ) LOOP
        cTd1  := &apos;&apos;; cTx1  := &apos;&apos;;  cTd2 := &apos;&apos;;  cTx2 := &apos;&apos;;  cTxP := &apos;&apos;;
        crTd1 := &apos;&apos;; crTx1 := &apos;&apos;;

        DoServCaStoc := vRec.TipDoc = 2;
        IF vRec.Tiparticol = &apos;1&apos; THEN --daca e serviciu
          SELECT Count(*) into aCod FROM Intrari1 WHERE CodIntr = pCodDoc and TipLinie = &apos;=&apos;;
          IF (vRec.TipDoc = 5)and (vRec.TipTranzactie IN (2,3)) THEN
            DoServCaStoc :=
              (aCod &gt; 0 and Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;1&apos;)
              or
              (InStr(&apos;,&apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;ServAICB&apos; ,vRec.An, vRec.Luna), &apos;0&apos;)||&apos;,&apos;, &apos;,&apos;||vRec.CodObiect||&apos;,&apos;) &gt; 0)
              or
              (InStr(&apos;,&apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;SERVIMPB&apos; ,vRec.An, vRec.Luna), &apos;0&apos;)||&apos;,&apos;, &apos;,&apos;||vRec.CodObiect||&apos;,&apos;) &gt; 0);
          END IF;
          IF (vRec.TipDoc IN (1,9)) and (vRec.TipTranzactie = 2) THEN
            DoServCaStoc :=
              (aCod &gt; 0 and Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;1&apos;)
              or
              (InStr(&apos;,&apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;ServAICB&apos; ,vRec.An, vRec.Luna), &apos;0&apos;)||&apos;,&apos;, &apos;,&apos;||vRec.CodObiect||&apos;,&apos;) &gt; 0);
          END IF;
          IF (vRec.TipDoc IN (1,9)) and (vRec.TipTranzactie = 3) THEN
             DoServCaStoc :=
                (aCod &gt; 0 and Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;1&apos;);
          END IF;
        END IF;

        bArt0 := vRec.Tiparticol = &apos;0&apos;;  bArt1 := vRec.Tiparticol = &apos;1&apos;;  bArt2 := vRec.Tiparticol = &apos;2&apos;;

        IF    vRec.TipDoc IN (1, 2, 3, 9) THEN cTd1 := &apos;98&apos;;  cTd2 := &apos;99&apos;;
        ELSIF vRec.TipDoc = 5             THEN cTd1 := &apos;05&apos;;  cTd2 := &apos;99&apos;;
        ELSIF vRec.TipDoc = 4             THEN cTd1 := &apos;04&apos;;  cTd2 := &apos;??&apos;;
        END IF;

        IF    bArt0 OR bArt2 OR DoServCaStoc THEN cTx1 := &apos;8&apos;; cTx2 := &apos;9&apos;;
        ELSIF bArt1                     THEN cTx1 := &apos;1&apos;; cTx2 := &apos;9&apos;;
        END IF;
        IF (vRec.TipDoc = 2) and Coalesce(pkg_categconst.GetValConstanta(&apos;AvizFaraTVANeex&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;2&apos; THEN cTx1 := &apos;0&apos;; cTx2 := &apos;0&apos;; END IF; crTx1 := vRec.TipArticol;

        aNeded := Coalesce(vRec.TVANEDED,0);
        cTd1 := vRec.PlatitorTVA||&apos;.&apos;||cTd1||&apos;.&apos;;
        cTd2 := vRec.PlatitorTVA||&apos;.&apos;||cTd2||&apos;.&apos;;

        crTd1 := cTd1;
        Taxa2 := vRec.Taxa2;
        IF (Extract(Year FROM vRec.DataDoc)*12+Extract(Month FROM vRec.DataDoc) &lt;&gt; vRec.AnLuna)
           and
           (vRec.TVALinie = 0)
         THEN Taxa2 := &apos;9.&apos;||Coalesce(vRec.TVAIncasare,0); END IF;

        IF vRec.Impozabil = 3  THEN
          cTaxa := vRec.Taxa1 ||&apos;.2.&apos;||Taxa2;
          cKeia := vRec.Cheia1||&apos;.2.&apos;||vRec.Cheia2;
        ELSE
          cTaxa := vRec.Taxa1 ||&apos;.&apos;||vRec.TipTVA||&apos;.&apos;||Taxa2;
          cKeia := vRec.Cheia1||&apos;.&apos;||vRec.TipTVA||&apos;.&apos;||vRec.Cheia2;
        END IF;

        cTx1  := cTaxa||&apos;.&apos;||cTx1 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
        cTx2  := cTaxa||&apos;.&apos;||cTx2 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
        crTx1 := cKeia||&apos;.&apos;||crTx1||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;

        IF vrec.TIPDOC=5 and vrec.TIPTRANZACTIE=2 and vrec.TIPTVA=2 and vrec.TAXEINCLUSE=1
				THEN aValLinie := vRec.ValoareDVI;
        ELSE aValLinie := vRec.Valoare;
				END IF;
        aTVALinie := vRec.TVA;

        SuplimTipDoc3 := 0;
        IF vRec.TipDoc = 3
        THEN
				  aValLinie := aValLinie - aTVALinie;
					SuplimTipDoc3 := aTVALinie;
        END IF;

        IF aValLinie &lt;&gt; 0
        THEN aProcTVADoc := Round(aTVALinie/aValLinie*100, 0);
        ELSE aProcTVADoc := 0;
        END IF;

        IF (vRec.TipTVA &lt;&gt; 9)
        OR (Coalesce(pkg_categconst.GetValConstanta(&apos;ProcTVAArt315&apos; ,vRec.An, vRec.Luna), To_Char(aProcTVADoc))&lt;&gt; To_Char(aProcTVADoc))
        THEN
          IF aValLinie = 0
          THEN aProcTVADoc := vRec.ProcTVAArt ;
          ELSE aProcTVADoc := PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(vRec.TIPDOC, vRec.An, vRec.Luna, 1, aValLinie + SuplimTipDoc3, vRec.TVA, vRec.CodObiect, vRec.ProcTVAArt, vRec.RotEFact, 1);
          END IF;
        END IF;

        cTxP  := To_Char(aProcTVADoc,&apos;FM900&apos;);

        cKeia := crTd1||crTx1|| cTxP ||&apos;.&apos;||aNeded;

        cCod1 := cTd1 ||cTx1 || cTxP ||&apos;.&apos;||aNeded;
        cCod2 := cTd1 ||cTx2 || cTxP ||&apos;.&apos;||aNeded;
        cCod3 := cTd1 ||cTx1 ||  &apos;99&apos;||&apos;.&apos;||aNeded;
        cCod4 := cTd1 ||cTx2 ||  &apos;99&apos;||&apos;.&apos;||aNeded;
        cCod5 := cTd2 ||cTx1 || cTxP ||&apos;.&apos;||aNeded;
        cCod6 := cTd2 ||cTx2 || cTxP ||&apos;.&apos;||aNeded;
        cCod7 := cTd2 ||cTx1 ||  &apos;99&apos;||&apos;.&apos;||aNeded;
        cCod8 := cTd2 ||cTx2 ||  &apos;99&apos;||&apos;.&apos;||aNeded;
        IF Coalesce(vRec.Impozabil,0) = 4 and Coalesce(vRec.TVANEDED,0) = 1 THEN
          aTax     := -1;
          cKeia := &apos;ok - decont intern&apos;;
          aTaxBase := aValLinie;
          aTaxVal  := aTVALinie;
          BEGIN
            SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = vRec.CODINTR1;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

					IF FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
						aTax := 0;
						cKeia := &apos;neplatitor TVA&apos;;
					END IF;

          IF aCod = 0 THEN
            aManual := 0;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
            VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODINTR, vRec.CODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia WHERE codTaxdecl = aCod;
            END IF;
          END IF;
        ELSE
          BEGIN
            aTaxBase := aValLinie;
            aTaxVal  := aTVALinie;
            aCODINTR1 := vRec.CodIntr1;
            IF aNEDED = 3 THEN
              aTaxBase := Round(aValLinie/2, 3);
              aTaxVal  := Round(aTVALinie/2, 3);
              aCODINTR1 := -vRec.CodIntr1;
            ELSIF aNEDED = 1 THEN
              aCODINTR1 := -vRec.CodIntr1;
            END IF;
            SELECT T.COD, T.TAXA INTO cTaxCode, aTax
            FROM WINMADMIN.Taxcode_i T
            WHERE T.Cod = cCod1 OR T.Cod = cCod2 OR T.Cod = cCod3 OR T.Cod = cCod4 OR T.Cod = cCod5 OR T.Cod = cCod6 OR T.Cod = cCod7 OR T.Cod = cCod8;
            cKeia := &apos;ok - &apos;||cTaxCode;
            IF VRec.Tiptranzactie &lt; 4 AND VREC.TipTVA = 2 THEN cKeia := &apos;&lt;D&apos;||VREC.CODCONTDED||&apos;D&gt;&lt;C&apos;||VREC.CODCONTCOLE||&apos;C&gt;&lt;V&apos;||To_Char(aTaxVal)||&apos;V&gt; &apos;||cKeia; END IF;
            IF VRec.Tiptranzactie &lt; 4 AND VREC.TipTVA = 4 THEN cKeia := &apos;&lt;P&apos;||VREC.CODCONTDED||&apos;P&gt; &apos;                                                    ||cKeia; END IF;
          EXCEPTION WHEN OTHERS THEN
            aTax  := 0;
            cKeia := &apos;?&apos;||&apos;==&apos;||cCod1||&apos;==&apos;||cCod2||&apos;==&apos;||cCod3||&apos;==&apos;||cCod4||&apos;==&apos;||cCod5||&apos;==&apos;||cCod6||&apos;==&apos;||cCod7||&apos;==&apos;||cCod8;
          END;

          BEGIN
            SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = aCODINTR1;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

          IF VREC.TaxCodeArt &gt; 0 THEN
            aTax := VREC.TaxCodeArt;
            cKeia := &apos;TaxCodeArt&apos;;
          END IF;

					IF FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
						aTax := 0;
						cKeia := &apos;neplatitor TVA&apos;;
					END IF;

          IF aCod = 0 THEN
            aManual := 0;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
            VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODINTR, aCODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia
              WHERE codTaxdecl = aCod;
            END IF;

          END IF;
          IF aNEDED &gt; 0 THEN
            cKeia := crTd1||crTx1|| cTxP ||&apos;.0&apos;;
            cCod1 := cTd1 ||cTx1 || cTxP ||&apos;.0&apos;;
            cCod2 := cTd1 ||cTx2 || cTxP ||&apos;.0&apos;;
            cCod3 := cTd1 ||cTx1 ||  &apos;99&apos;||&apos;.0&apos;;
            cCod4 := cTd1 ||cTx2 ||  &apos;99&apos;||&apos;.0&apos;;
            cCod5 := cTd2 ||cTx1 || cTxP ||&apos;.0&apos;;
            cCod6 := cTd2 ||cTx2 || cTxP ||&apos;.0&apos;;
            cCod7 := cTd2 ||cTx1 ||  &apos;99&apos;||&apos;.0&apos;;
            cCod8 := cTd2 ||cTx2 ||  &apos;99&apos;||&apos;.0&apos;;
            BEGIN
              aTaxBase := aValLinie;
              aTaxVal  := aTVALinie;
              SELECT T.COD, T.TAXA INTO cTaxCode, aTax
              FROM WINMADMIN.Taxcode_i T
              WHERE T.Cod = cCod1 OR T.Cod = cCod2 OR T.Cod = cCod3 OR T.Cod = cCod4 OR T.Cod = cCod5 OR T.Cod = cCod6 OR T.Cod = cCod7 OR T.Cod = cCod8;
              cKeia := &apos;ok - &apos;||cTaxCode;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
              cKeia := &apos;?&apos;||&apos;==&apos;||cCod1||&apos;==&apos;||cCod2||&apos;==&apos;||cCod3||&apos;==&apos;||cCod4||&apos;==&apos;||cCod5||&apos;==&apos;||cCod6||&apos;==&apos;||cCod7||&apos;==&apos;||cCod8;
            END;

            BEGIN
              SELECT codTaxdecl INTO aCod FROM TAXDECL WHERE TipDoc = vRec.TIPDOC AND CODDOC1 = vRec.CODINTR1;
            EXCEPTION WHEN OTHERS THEN
              aCod := 0;
            END;
            IF VREC.TaxCodeArt &gt; 0 THEN
              aTax := VREC.TaxCodeArt;
              cKeia := &apos;TaxCodeArt&apos;;
            END IF;

						IF FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
							aTax := 0;
							cKeia := &apos;neplatitor TVA&apos;;
						END IF;

            IF aCod = 0 THEN
              aManual := 0;
              INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,       coddoc1,       TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,       AnLuna)
              VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODINTR, vRec.CODINTR1, aTAX,    aTaxBase, aTaxVal, cKeia, aManual, vRec.ContSaft, vRec.AnLuna);
            ELSE
              IF vRec.Manual = 0 THEN
                UPDATE TAXDECL
                SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.ContSaft
                WHERE codTaxdecl = aCod;
              ELSE
                UPDATE TAXDECL
                SET TaxBase = aTaxBase, TaxVal = aTaxVal, CHEIA = cKeia
                WHERE codTaxdecl = aCod;
              END IF;
            END IF;
          END IF;
        END IF;

        COMMIT;
      END LOOP;
    END IF;
  ELSIF pCaz = 1 THEN
    SELECT An,  Luna,  TipDoc,  TipTVA,  TipTranzactie,  Coalesce(Anulat, 0), Coalesce(Operat, 1), Subunitatea
    INTO   aAn, aLuna, aTipDoc, aTipTVA, aTipTranzactie, aAnulat,             aOperat,             aSubunit
    FROM Iesiri
    WHERE CodIes = pCodDoc;
    IF aAnulat = 1 OR aOperat = 0 or (aTipTranzactie = 5 and aTipDoc &lt;&gt; 20) THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc;
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc = pCodDoc AND MANUAL = 0;
      TVA0FaraDed := Coalesce(pkg_categconst.GetValConstanta(&apos;TVA0FaraDed&apos; ,aAn, aLuna), &apos;0&apos;);
      FOR vRec IN (
        WITH IES (CodIES, TipDoc, An, Luna, AnLuna, TVAIncasare, Curs, TaxaI, CheiaI, INFOCM, TipFactura, TipTranzactie, RotEFact) AS  (
          SELECT
            I.CodIES, I.TipDoc, I.AN, I.Luna, I.An*12+I.Luna AnLuna, I.TVAIncasare, Coalesce(NULLIF(I.Curs,0),1) Curs,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt; Chr(64) THEN &apos;1&apos; ELSE &apos;0&apos; END ||&apos;.&apos;||
            CASE WHEN T.SimbAuto = &apos;RO&apos; THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||&apos;.&apos;||
            TipTranzactie||&apos;.&apos;||To_Char(TipTVA,&apos;FM900&apos;)||&apos;.&apos;||
            CASE WHEN TipSaft = 2 THEN &apos;2&apos; WHEN TipSaft = 3 THEN &apos;3&apos; ELSE &apos;9&apos; END||&apos;.&apos;||
            Case when Coalesce(TipFactura,0) = 7 or Coalesce(INFOCM,0) = 1 THEN 1 ELSE 0
            END TaxaI,
            CASE WHEN SubStr(PCF.CodFiscal,1,1) &gt; Chr(64) THEN 1 ELSE 0 END||&apos;.&apos;||
            CASE WHEN T.SimbAuto = &apos;RO&apos; THEN 2 ELSE Coalesce(T.STATCOMUNITAR,0) END||&apos;.&apos;||TipTranzactie||&apos;.&apos;||To_Char(TipTVA,&apos;FM900&apos;)||&apos;.&apos;||TipSaft||&apos;.&apos;||
            Case when Coalesce(TipFactura,0) = 7 or Coalesce(INFOCM,0) = 1 THEN 1 ELSE 0 END CheiaI,
            Coalesce(INFOCM,0) INFOCM, Coalesce(TipFactura,0) TipFactura, I.TipTranzactie, I.RotEFact
          FROM IESIRI I
            LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CodLocatie AND A.codpart = I.Partener
            LEFT JOIN NLOCALIT L ON L.CODLOCALIT = Coalesce(A.CODLOCALIT, 0)
            LEFT JOIN NTARI T ON T.CODTARA = Coalesce(L.CODTARA, 0)
            LEFT JOIN NPARTCODFISC PCFP ON PCFP.CodPart = I.Partener AND PCFP.PRINCIPAL = 1
            LEFT JOIN NPARTCODFISC PCF  ON PCF.Cod_CODFISCAL = Coalesce(NullIf(I.CodFiscal,0),PCFP.COD_CODFISCAL)
          WHERE CodIes = pCodDoc
        )
        SELECT
          I1.CodIES, I1.CodIES1, I.TipDoc, I.An, I.Luna, I.AnLuna, I.INFOCM, I.TipFactura, I.TVAIncasare, I.TipTranzactie,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.PretOrig, I1.PU)*Coalesce(I1.CoefDiscMaj,1)*I1.Cant Valoare,
          Case when aCursLinie = 1 then Coalesce(NULLIF(I1.CursFacturaAvans, 0), I.Curs) else I.Curs end*Coalesce(I1.TVA, 0)*Coalesce(I1.CoefDiscMaj,1)*CASE WHEN I1.ADDim = -100 THEN 0 ELSE 1/(1+Coalesce(I1.ADDim/100,0)) END TVA,
          TL.procent ProcTVAArt,
          I.CheiaI, I.TaxaI, A.TipArticol,I1.CodObiect,
          CASE WHEN TL.PROCENT IS NULL THEN &apos;?&apos; WHEN TL.CodTVA = TVA0FaraDed THEN &apos;0&apos; ELSE &apos;1&apos; END CotaArtZero,
          I1.TipLinie, AE1.CodIES1 CodAE1, AE1.ContServ, AE.ContIntermed, Coalesce(AL.TaxCode, 0) TaxCodeArt, I.RotEFact, I1.Impozabil,
					I1.Taxa, TD.Manual
        FROM IES I
          INNER JOIN Iesiri1  I1  ON I1.CodIES     = I.CodIES
          LEFT  JOIN IesLink  IK  ON IK.CodIes1    = I1.CodIes1
          LEFT  JOIN Iesiri1  AE1 ON AE1.CodIes1   = Coalesce(IK.CodLinieAviz, I1.CodIes1)
          LEFT  JOIN Iesiri   AE  ON AE.CodIes     = AE1.CodIes
          LEFT  JOIN NArtOBJ  O   ON O.CodObiect   = I1.CodObiect
          LEFT  JOIN NArt     A   ON A.CodArticol  = O.CodArticol
          LEFT  JOIN NArt1    AL  ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1    TL  ON TL.CodTVA     = AL.CodTVA AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
          LEFT  JOIN TAXDECL  TD  ON TD.TipDoc     = I.Tipdoc AND TD.Coddoc = I.CodIes and TD.Coddoc1 = I1.CODIES1
        WHERE NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;) and Coalesce(I1.Cant,0) &lt;&gt; 0
                      --AND (Coalesce(TD.Manual, 0) &lt;&gt; 1)

      ) LOOP
        IF vRec.TipLinie = &apos;=&apos; AND vRec.INFOCM = 1 THEN
          BEGIN
            SELECT codcont INTO aContSaft FROM ncont WHERE Simbol = &apos;707&apos;;
          EXCEPTION
            WHEN OTHERS THEN aContSaft := 0;
          END;
        ELSIF vRec.TipLinie = &apos;=&apos; THEN
          SELECT Min(venituri) INTO aContSaft
          FROM (
            SELECT ROW_NUMBER() OVER (ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
            Case when vrec.TipDoc = 14 THEN io1.CHELTTVACOLECTAT ELSE io1.venituri END venituri
            FROM livr1 l1
              LEFT JOIN LIVR    L   ON L.CodLivr     = L1.CodLivr
              LEFT JOIN IESIRI  I   ON I.CodIes      = L.CodIes AND I.TipDoc = L.TipLivr
              LEFT JOIN NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
              LEFT JOIN LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
              LEFT JOIN IOART1  IO1 ON IO1.CodIOArt  = Coalesce(Nullif(l1.contintermed, 0), Nullif(i.contintermed, 0), lv.CodIOArt, ns.codioart)
            WHERE l1.codies1 = vRec.CodAE1 AND Coalesce(io1.venituri, 0) &lt;&gt; 0
              AND vRec.AnLuna BETWEEN io1.ALStart AND io1.ALStop
          ) ssub
          WHERE RNOrd = 1;
        ELSE
          aContSaft := vRec.ContServ;
        END IF;

        cTd1 := &apos;&apos;; cTx1 := &apos;&apos;;
        DoServCaStoc := (Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;1&apos;);
        IF DoServCaStoc THEN
          SELECT Count(*) into aCod FROM Iesiri1 WHERE CodIes = pCodDoc and TipLinie = &apos;=&apos;;
          IF aCod = 0 THEN DoServCaStoc := False; END IF;
        END IF;
        IF (not DoServCaStoc) and (vRec.TipTranzactie = 2) THEN
          DoServCaStoc := InStr(&apos;,&apos;||Coalesce(pkg_categconst.GetValConstanta(&apos;ServLICB&apos; ,vRec.An, vRec.Luna), &apos;0&apos;)||&apos;,&apos;, &apos;,&apos;||vRec.CodObiect||&apos;,&apos;) &gt; 0;
        END IF;
        bArt0 := vRec.Tiparticol = &apos;0&apos;;  bArt1 := vRec.Tiparticol = &apos;1&apos;;  bArt2 := vRec.Tiparticol = &apos;2&apos;;
        IF    bArt0 OR bArt2 OR DoServCaStoc THEN cTx1 := &apos;8&apos;; cTx2 := &apos;9&apos;;
        ELSIF bArt1                     THEN cTx1 := &apos;1&apos;; cTx2 := &apos;9&apos;;
        END IF;
        IF (vRec.TipDoc = 20) and Coalesce(pkg_categconst.GetValConstanta(&apos;AvizFaraTVANeex&apos; ,vRec.An, vRec.Luna), &apos;2&apos;)=&apos;2&apos; THEN cTx1 := &apos;0&apos;; cTx2 := &apos;0&apos;; END IF; crTx1 := vRec.Tiparticol;
        IF vRec.Impozabil = 5 THEN
          cTaxa := Substr(vRec.TaxaI, 1, 6)||&apos;12&apos;||Substr(vRec.TaxaI, 9, 5);
          cTx1  := cTaxa ||&apos;.&apos;||cTx1 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
          cTx2  := cTaxa ||&apos;.&apos;||cTx2 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;

          cTaxa := Substr(vRec.CheiaI, 1, 6)||&apos;12&apos;||Substr(vRec.CheiaI, 9, 5);
          crTx1 := cTaxa||&apos;.&apos;||crTx1||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
        ELSE
          cTx1  := vRec.TaxaI ||&apos;.&apos;||cTx1 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
          cTx2  := vRec.TaxaI ||&apos;.&apos;||cTx2 ||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
          crTx1 := vRec.CheiaI||&apos;.&apos;||crTx1||&apos;.&apos;||vRec.CotaArtZero||&apos;.&apos;;
        END IF;

        aValLinie := vRec.Valoare;
        aTVALinie := vRec.TVA;
        IF vRec.TipDoc = 21
        THEN aValLinie := aValLinie - aTVALinie;
        END IF;
        BazaTVAMarja := 0; --pentru tva la marja de adaos
        IF aValLinie = 0
        THEN aProcTVADoc := 0;
        ELSE
          IF vRec.TipDoc = 14 --mMinuslainventar
          THEN
            IF vRec.TVA = 0
            THEN aProcTVADoc := 0;
            ELSE
              aProcTVADoc := vRec.ProcTVAArt;
              IF aProcTVADoc &lt;&gt; 0
              THEN aValLinie := Round(aTVALinie /(aProcTVADoc/100),2);
              END IF;
            END IF;
          ELSE
            IF aTipTVA IN (7,8) THEN
              aProcTVADoc  := vRec.ProcTVAArt;
              IF aProcTVADoc &lt;&gt; 0 THEN
                BazaTVAMarja := Round(aTVALinie / (aProcTVADoc/100),2);
              END IF;
            ELSE
              aProcTVADoc := PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(vRec.TIPDOC, vRec.An, vRec.Luna, 1, vRec.Valoare, vRec.TVA, vRec.CodObiect, vRec.ProcTVAArt, vRec.RotEFact, 1);
            END IF;
          END IF;
        END IF;
        cTxP := To_Char(aProcTVADoc,&apos;FM900&apos;);
        cKeia := crTx1 || cTxP ;
        cCod1 := cTx1  || cTxP ;
        cCod2 := cTx2  || cTxP ;
        cCod3 := cTx1  || &apos;99&apos;;
        cCod4 := cTx2  || &apos;99&apos;;
        IF VRec.TipDoc = 14 THEN
          aTax  := 0;
          cKeia := &apos;OK - hardcoded&apos;;
          IF    aProcTVADoc = 21 THEN aTax := 380006;
          ELSIF aProcTVADoc = 11 THEN aTax := 380007;
          ELSIF aProcTVADoc = 19 THEN aTax := 380001;
          ELSIF aProcTVADoc =  9 THEN aTax := 380002;
          ELSIF aProcTVADoc =  5 THEN aTax := 380003;
          ELSIF aProcTVADoc = 20 THEN aTax := 380004;
          ELSIF aProcTVADoc = 24 THEN aTax := 380005;
          END IF;
        ELSE
          IF (VRec.TVAIncasare = 1) AND (aTVALinie &lt;&gt; 0) THEN
						BEGIN
							SELECT T.COD, T.TAXA INTO cTaxCode, aTax
							FROM WINMADMIN.Taxcode_E2 T
							WHERE T.Cod = cCod1 OR T.Cod = cCod2 ;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
            END;
            IF aTax = 0 then
              BEGIN
                  SELECT T.COD, T.TAXA INTO cTaxCode, aTax
                  FROM WINMADMIN.Taxcode_E2 T
                  WHERE T.Cod = cCod3 OR T.Cod = cCod4 ;
              EXCEPTION WHEN OTHERS THEN
                aTax  := 0;
              END;
            end if;
          ELSE
            BEGIN
              SELECT T.COD, T.TAXA INTO cTaxCode, aTax
              FROM WINMADMIN.Taxcode_E T
              WHERE T.Cod = cCod1 OR T.Cod = cCod2 ;
            EXCEPTION WHEN OTHERS THEN
              aTax  := 0;
            END;
            IF aTax = 0 then
              BEGIN
                  SELECT T.COD, T.TAXA INTO cTaxCode, aTax
                  FROM WINMADMIN.Taxcode_E T
                  WHERE T.Cod = cCod3 OR T.Cod = cCod4 ;
              EXCEPTION WHEN OTHERS THEN
                aTax  := 0;
              END;
            end if;
					END IF;
          if aTax = 0 then cKeia := &apos;?&apos;||&apos;==&apos;||cCod1||&apos;==&apos;||cCod2||&apos;==&apos;||cCod3||&apos;==&apos;||cCod4;
                      else cKeia := &apos;ok - &apos;||cTaxCode; end if;
        END IF;

        IF BazaTVAMarja &lt;&gt; 0 THEN
           cKeia := &apos;&lt;BAZATVAMARJA&apos;||To_Char(BazaTVAMarja)||&apos;BAZATVAMARJA&gt; &apos;||cKeia;
        END IF;

        BEGIN
          SELECT T.codTaxdecl INTO aCod FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC1 = vRec.CODIES1;
        EXCEPTION WHEN OTHERS THEN
          aCod := 0;
        END;

        IF (VRec.TipDoc &lt;&gt; 14)or(aTVALinie &lt;&gt; 0) THEN --la 14 pun IN taxdecl numai daca linia are TVA
          IF VREC.TaxCodeArt &gt; 0 THEN
            aTax := VREC.TaxCodeArt;
            cKeia := &apos;TaxCodeArt&apos;;
          END IF;
					IF VREC.Taxa IN (3,4,5) and aTVALinie = 0 THEN
						aTax := 310324;
						cKeia := &apos;Hardcoded SGR&apos;;
					END IF;

					IF FirmaPlatitorTVA(aSubunit, vRec.An, vRec.Luna) = 0 THEN
						aTax := 0;
						cKeia := &apos;neplatitor TVA&apos;;
					END IF;

          IF aCod = 0 THEN
            aManual := 0;
            --IF VREC.TVAINCASARE = 1 THEN aManual := 2; ELSE aManual := 0; END IF;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual,  CodCont,   AnLuna)
            VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODIES, vRec.CODIES1, aTAX,    aValLinie, aTVALinie, cKeia, aManual, aContSaft, vRec.AnLuna);
          ELSE
            IF vRec.Manual = 0 THEN
              UPDATE TAXDECL
              SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = aContSaft
              WHERE codTaxdecl = aCod;
            ELSE
              UPDATE TAXDECL
              SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia
              WHERE codTaxdecl = aCod;
            END IF;
          END IF;
          COMMIT;
        END IF;
      END LOOP;
    END IF;
  ELSIF pCaz = 2 THEN
    SELECT An,  Luna,  Subunitatea INTO aAn, aLuna, aSubunit FROM Iesiri WHERE CodIes = pCodDoc;
    ArtIncasUlterior := Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasUlterior&apos;    ,aAn, aLuna), &apos;0&apos;);
    IOArtIncasImed   := Coalesce(pkg_categconst.GetValConstanta(&apos;ContIncasareFactura&apos; ,aAn, aLuna), &apos;0&apos;);
    DELETE FROM TaxDecl WHERE TipDoc = 16 AND CodDoc = pCodDoc;
    FOR vRec IN (
    WITH IES (CodIES, TipDoc, ContIntermed, TaxaI, AnLuna, DoServ) AS  (
      SELECT
        I.CodIes, I.TipDoc, I.ContIntermed, &apos;0.2.6.01.9.0.&apos; TaxaI, I.An*12+I.Luna AnLuna,
        Coalesce(pkg_categconst.GetValConstanta(&apos;InclServInValBunuri&apos;, I.An, I.Luna), &apos;2&apos;) DoServ
      FROM  IESIRI I
      WHERE CodIes = pCodDoc AND TipDoc = 16 AND Operat = 1 AND Anulat = 0
    ),
    TVADOC AS (
      SELECT
        CodIes1,
        Round(PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)/100, 2) KTVA,
        PU*Cant + Coalesce (ValDiscPret,0) ValFaraDisc
      FROM Iesiri I
        INNER JOIN Iesiri1 I1 ON i1.CodIes     = I.CodIes
        LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
        LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
        LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva    AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
      WHERE I.CodIes = pCodDoc
    ),
    DISCDOC AS (
      SELECT
        CodIes, Round(PROCTVA,0) PROCTVA, DISCOUNT, TVADISCOUNT
      FROM Discmonetar
      WHERE CodIes = pCodDoc
    ),
    CONTDOC AS (
      SELECT CodIes1, ContSaft, CodIOArt
      FROM (
        SELECT
          ROW_NUMBER() OVER (PARTITION BY I1.CodIes1 ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
          I1.CodIes1, CASE WHEN I1.tiplinie = &apos;=&apos; THEN io1.venituri ELSE i1.ContServ END ContSaft, Coalesce(lv.CodIOArt, Coalesce(ns.codioart, 0)) CodIOArt
        FROM IES I
          INNER JOIN Iesiri1 I1  ON I1.CodIes     = I.CodIes
          LEFT JOIN  livr1   l1  ON I1.CodIes1    = L1.CodIes1
          LEFT JOIN  NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
          LEFT JOIN  LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
          LEFT JOIN  IOART1  IO1 ON IO1.CodIOArt  = Coalesce(Nullif(l1.contintermed, 0), Nullif(i.contintermed, 0), lv.CodIOArt, ns.codioart) AND I.AnLuna BETWEEN io1.ALStart AND io1.ALStop
        WHERE NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;)
      ) asub
      WHERE asub.rnord = 1
    ),
    IES1 AS (
      SELECT
        CodIes AS CodDoc, AnLuna, ProcTVA AS CodDoc1, ContSaft, Cod1, Cod2, CoefIO,
        Sum(Coalesce(Valoare, 0)-Coalesce(TVA, 0)) Valoare , Sum(Coalesce(TVA, 0)) TVA, TaxCodeArt, TaxaSpec
      FROM (
        SELECT
          I.CodIes, I.AnLuna, Coalesce(TD.KTVA*100,0) PROCTVA, CD.ContSaft, TD.ValFaraDisc Valoare, Coalesce(I1.TVA, 0) + Coalesce(ValDiscPret,0)* KTVA / (1+KTVA) TVA,
          I.TaxaI||&apos;9.&apos;||CASE WHEN TL.PROCENT = 0 THEN &apos;0&apos; ELSE &apos;1&apos; END||&apos;.&apos;||To_Char(Round(TD.kTVA*100, 2),&apos;FM900&apos;) AS Cod1,
          I.TaxaI||&apos;9.&apos;||CASE WHEN TL.PROCENT = 0 THEN &apos;0&apos; ELSE &apos;1&apos; END||&apos;.&apos;||&apos;99&apos; AS Cod2,
          CASE WHEN CD.CodIOArt = IOArtIncasImed THEN 0 ELSE 1 END CoefIO, Coalesce(AL.TaxCode, 0) TaxCodeArt,
					CASE WHEN I1.Taxa IN (3,4,5) and I1.TVA = 0 THEN 1 ELSE 0 END TaxaSpec
        FROM IES I
          INNER JOIN IESIRI1 I1 ON I1.CodIes     = I.CodIes
          INNER JOIN TVADOC  TD ON TD.CodIes1    = I1.CodIes1
          LEFT  JOIN CONTDOC CD ON CD.CodIes1    = I1.CodIes1
          LEFT  JOIN NArtOBJ O  ON O .CodObiect  = I1.CodObiect
          LEFT  JOIN NArt    A  ON A .CodArticol = O.CodArticol
          LEFT  JOIN NArt1   AL ON AL.CODARTICOL = O.CODARTICOL AND I.AnLuna BETWEEN AL.ALStart AND AL.ALStop
          LEFT  JOIN NTva1   TL ON TL.CodTVA     = AL.CodTVA    AND I.AnLuna BETWEEN TL.ALStart AND TL.ALStop
        WHERE NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;) and Coalesce(I1.Cant,0) &lt;&gt; 0 and I1.CodObiect &lt;&gt; ArtIncasUlterior
      ) subs
      GROUP BY CodIes, AnLuna, PROCTVA, CoefIO, ContSaft, Cod1, Cod2, TaxCodeArt, TaxaSpec
    )
    SELECT
      I.CodDoc, I.CodDoc1, Case WHEN I.TaxaSpec = 1 THEN 310324 WHEN I.TaxCodeArt &gt; 0 THEN I.TaxCodeArt ELSE T.TAXA END AS TaxCode,
      I.Valoare AS TaxBase, I.TVA AS TaxVal, CoefIO,
      CASE
        WHEN T.TAXA &lt;&gt; 0 THEN  &apos;ok - &apos;||T.COD
        ELSE &apos;?ok - &apos;||T.COD||&apos;==&apos;||I.Cod1||&apos;==&apos;||I.Cod2
      END AS Cheia,
      0 AS Manual, I.ContSaft AS CodCont, I.AnLuna
    FROM Ies1 I LEFT JOIN DISCDOC D ON D.Codies = I.CodDoc and D.ProcTVA = I.CodDoc1
    LEFT JOIN WINMADMIN.Taxcode_E T ON T.Cod = I.Cod1 OR T.Cod = I.Cod2
    ) LOOP
      SELECT Count(*) into aCod FROM Iesiri1 I1 WHERE I1.CodIes = pCodDoc and Coalesce (ValDiscPret,0) &lt;&gt; 0;

			IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
				aTax := 0;
				cKeia := &apos;neplatitor TVA&apos;;
			ELSE
				aTax := VRec.Taxcode;
				cKeia := VRec.Cheia;
			END IF;

      IF aCod &lt;&gt; 0 -- am disc pe linie
      THEN
        INSERT INTO TaxDecl(CodTaxdecl, TipDoc, CodDoc, CodDoc1, TaxCode, TaxBase, TaxVal,Cheia, Manual, CodCont, AnLuna)
        VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, 16, vRec.CodDoc, vRec.CodDoc1, aTax, vRec.TaxBase, vRec.TaxVal, cKeia, vRec.Manual, vRec.CodCont, vRec.AnLuna);
      ELSE
        WITH
        TVADOC AS (
          SELECT
            CodIes1,
            Round(PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, T1.PROCENT, I.ROTEFACT, 1)/100, 2) KTVA,
            PU*Cant Val
          FROM Iesiri I
            INNER JOIN Iesiri1 I1 ON i1.CodIes     = I.CodIes
            LEFT  JOIN nartobj o  ON o.codobiect   = i1.codobiect
            LEFT  JOIN nart1   a1 ON a1.codarticol = o.codarticol AND i.an*12+i.luna BETWEEN a1.alstart AND a1.alstop
            LEFT  JOIN ntva1   t1 ON t1.codtva     = a1.codtva AND i.an*12+i.luna BETWEEN t1.alstart AND t1.alstop
          WHERE I.CodIes = pCodDoc
        ),
        CONTDOC AS (
          SELECT CodIes1, Case when CodIOArt = IOArtIncasImed THEN 0 ELSE 1 END CoefIO
          FROM (
            SELECT
              ROW_NUMBER() OVER (PARTITION BY I1.CodIes1 ORDER BY CASE WHEN Coalesce(l1.contintermed, 0) = 0 THEN 1 ELSE 0 END, L1.CODLIVR1) RNOrd,
              I1.CodIes1, Coalesce(lv.CodIOArt, Coalesce(ns.codioart, 0)) CodIOArt
            FROM IESIRI I
              INNER JOIN Iesiri1 I1  ON I1.CodIes     = I.CodIes
              LEFT JOIN  livr1   l1  ON I1.CodIes1    = L1.CodIes1
              LEFT JOIN  NIRSTOC NS  ON NS.CodNirStoc = L1.CodNirStoc
              LEFT JOIN  LIVRVAL LV  ON LV.CodLivr1   = L1.CodLivr1
              WHERE I.CodIes = pCodDoc AND TipDoc = 16 AND Operat = 1 AND Anulat = 0 AND (NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;))
          ) asub
          WHERE asub.rnord = 1
        ),
        IES1 AS (
          SELECT CodIes, ProcTVA, CoefIO, Sum(Coalesce(Val, 0)) Valoare
          FROM (
            SELECT I.CodIes, CD.CoefIO, Coalesce(TD.KTVA*100,0) PROCTVA, TD.Val
            FROM (
              SELECT CodIes
              FROM  IESIRI
              WHERE CodIes = pCodDoc AND Operat = 1
            ) I
              INNER JOIN IESIRI1 I1 ON I1.CodIes     = I.CodIes
              LEFT  JOIN CONTDOC CD ON CD.CodIes1    = I1.CodIes1
              INNER JOIN TVADOC  TD ON TD.CodIes1    = I1.CodIes1
            WHERE NOT I1.TipLinie IN (&apos;G&apos;,&apos;T&apos;) and Coalesce(I1.Cant,0) &lt;&gt; 0
          ) subs
          GROUP BY CodIes, CoefIO, PROCTVA
        )
        SELECT I.Valoare, I.CoefIO, Coalesce(D.Discount,0) Discount INTO aVal, aCoefIO, aDisc
        FROM Ies1 I LEFT JOIN (SELECT CodIes, Round(PROCTVA,0) PROCTVA, DISCOUNT FROM Discmonetar WHERE CodIes = pCodDoc ) D ON D.Codies = I.CodIes and D.ProcTVA = I.ProcTVA
        WHERE I.ProcTVA = vRec.Coddoc1 and I.CoefIO = VRec.CoefIO;
        IF aVal = 0 THEN KIncas := 1; ELSE KIncas := 1 + aCoefIO*aDisc/aVal; END IF;

				IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
					aTax := 0;
					cKeia := &apos;neplatitor TVA&apos;;
				ELSE
					aTax := VRec.Taxcode;
					cKeia := VRec.Cheia;
				END IF;

	      INSERT INTO TaxDecl(CodTaxdecl, TipDoc, CodDoc, CodDoc1, TaxCode, TaxBase, TaxVal,Cheia, Manual, CodCont, AnLuna)
        VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, 16, vRec.CodDoc, vRec.CodDoc1, aTax, Round(KIncas*vRec.TaxBase, 2), Round(KIncas*vRec.TaxVal, 2),cKeia, vRec.Manual, vRec.CodCont, vRec.AnLuna);
      END IF;
    END LOOP;
    COMMIT;
  ELSIF pCaz = 3 THEN
    SELECT TipDoc, Coalesce(Operat, 1), An, Luna, Subunitatea INTO aTipDoc, aOperat, aAn, aLuna, aSubunit FROM Trezor WHERE CodTrezor = pCodDoc;
    IF aOperat = 0 THEN
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND CodDoc IN (SELECT CodTrezor1 FROM Trezor1 WHERE CodTrezor = pCodDoc);
    ELSE
      DELETE FROM TaxDecl WHERE TipDoc = aTipDoc AND MANUAL = 0 AND CodDoc IN (SELECT CodTrezor1 FROM Trezor1 WHERE CodTrezor = pCodDoc);
      FOR vRec IN (
        SELECT
          bSub.coddoc, bSub.coddoc1, bSub.tipdoc, bSub.AnLuna,
          Coalesce(TE.Taxa, TI.Taxa, bSub.Taxa) Taxa, bSub.ValBaza, bSub.ValTaxa,
          bSub.cont, bSub.impozit, bSub.Simbol, bSub.TaxCode, bSub.TaxaI, bSub.TaxaE, bSub.TipTranz,bSub.ObiectTranz,
          bSub.TVAIncasare, bSub.ProcStopaj, bSub.CodIO, bSub.TipDocIO, bSub.TipIO
        FROM (
          SELECT
            aSub.CodDoc, aSub.CodDoc1, aSub.tipdoc, aSub.TipTranz, aSub.ObiectTranz,aSub.AnLuna, C.TaxCode Taxa, Round(T.ProcTaxa,0) proc,
            CASE
              WHEN Coalesce(c.impozit,0) = 1 AND Coalesce(T.ProcTaxa,0) = 0 THEN 0
              WHEN Coalesce(c.impozit,0) = 1                                THEN Round(aSub.Val/(T.ProcTaxa/100),2)
              ELSE aSub.Val - aSub.TVA
            END ValBaza,
            CASE WHEN Coalesce(c.impozit,0) = 1 THEN aSub.Val ELSE aSub.TVA END ValTaxa, T.COD TaxCode,
            aSub.TaxaE||To_Char(Round(PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),&apos;FM900&apos;)       TaxaE,
            aSub.TaxaI||To_Char(Round(PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),&apos;FM900&apos;)||&apos;.0&apos; TaxaI,
            aSub.cont, Coalesce(c.impozit,0) impozit, c.Simbol, TVAIncasare, ProcStopaj, aSub.CodIO, aSub.TipDocIO, aSub.TipIO
          FROM (
            SELECT
              t1.codtrezor1 coddoc, o.codobligpif coddoc1, t.tipdoc, t1.TipTranz, t1.ObiectTranz, T.An*12+T.Luna AnLuna,
              Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare, Coalesce(Intr.ProcStopaj,0) ProcStopaj,
              Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
              Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
              CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
              CASE
                WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
                ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(t1.codpart,t.an,t.luna))
              END cont,
              Coalesce(o.valoare,0) * Coalesce(NullIF(t1.curs,0),1) VAL,
              Coalesce(g.tva,0)     * Coalesce(NullIF(t1.curs,0),1) TVA,
--              Coalesce(o.valoare,0) * Coalesce(NullIF(g.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) VAL,
--              Coalesce(g.tva,0)     * Coalesce(NullIF(g.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) TVA,
              CASE
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 1 AND t1.ObiectTranz &lt;&gt; 1 THEN &apos;0.2.1.01.9.0.9.1.&apos;
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 0 AND t1.ObiectTranz  = 1 THEN &apos;0.2.1.01.9.0.9.1.&apos;
              ELSE &apos;?&apos;
              END TaxaE,
              CASE
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 1 AND t1.ObiectTranz  =  1 THEN &apos;1.98.2.01.1.3.0.9.1.&apos;
              WHEN Coalesce(g.tva,0) &lt;&gt; 0  AND t1.TipTranz = 0 AND t1.ObiectTranz  &lt;&gt; 1 THEN &apos;1.98.2.01.1.3.0.9.1.&apos;
              ELSE &apos;?&apos;
              END TaxaI
            FROM trezor t
              LEFT JOIN trezor1  t1   ON t.codtrezor = t1.codtrezor
              LEFT JOIN general  g    ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
              LEFT JOIN obligpif o    ON o.codgeneral = g.codgeneral
              LEFT JOIN stingere s    ON s.codstingatorpif = o.codobligpif
              LEFT JOIN obligpif os   ON os.codobligpif = s.codstinspif
              LEFT JOIN general  gs   ON gs.codgeneral = os.codgeneral
              LEFT JOIN intrari  intr ON intr.codintr = gs.coddoc and intr.tipdoc = gs.tipdoc
              LEFT JOIN iesiri   ies  ON ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
              LEFT JOIN trezor1  ts1  ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
              LEFT JOIN trezor   ts   ON ts.codtrezor = ts1.codtrezor
            WHERE T.CodTrezor = pCodDoc AND t1.tiptranz IN (0,1)
              AND (Coalesce( OS.SEMNIFICATIE , 0) = 0 or NOT OS.SEMNIFICATIE IN (500, 600))
              AND (   (t.TipDoc = 33 and t1.obiecttranz IN (3, 4))
                    OR(t.TipDoc &lt;&gt; 33 and t1.obiecttranz IN (4,5,6))
                    OR(o.semnificatie IN (310,320,330,410,420,430))
                    OR Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) =1
                    OR Coalesce(intr.PROCSTOPAJ, 0) &lt;&gt; 0
                  )
            UNION ALL
            SELECT
              t1.codtrezor1 coddoc, o.codobligpif coddoc1, t.tipdoc, t1.TipTranz, t1.ObiectTranz, T.An*12+T.Luna AnLuna,
              Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare, 0 ProcStopaj,
              Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
              Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
              CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
              PKG_TREZOR.CODCONTCEC(TS.CodBanca, OS.Semnificatie, TS1.Tipdecont, TS1.ObiectTranz, T.an, T.luna) Cont,
              Coalesce(O_STING_FACT.valoare,0) * Coalesce(NullIF(G_STING_FACT.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) VAL,
              Coalesce(G_STING_FACT.tva,0)     * Coalesce(NullIF(G_STING_FACT.curs,0),1)/Coalesce(NullIF(t1.curs,0),1) TVA,
              CASE WHEN t1.TipTranz = 1 AND Coalesce(g.tva,0) &lt;&gt; 0 THEN &apos;0.2.1.01.9.0.9.1.&apos; ELSE &apos;?&apos; END TaxaE,
              CASE WHEN t1.TipTranz = 1 AND Coalesce(g.tva,0) &lt;&gt; 0 THEN &apos;?&apos; ELSE &apos;1.98.2.01.1.3.0.9.1.&apos; END TaxaI
            FROM trezor t
              INNER JOIN trezor1  t1   ON t.codtrezor = t1.codtrezor
              INNER JOIN general  g    ON g.tipdoc = t.tipdoc AND g.coddoc = t1.codtrezor1
              INNER JOIN obligpif o    ON o.codgeneral = g.codgeneral
              INNER JOIN stingere s    ON s.codstingatorpif = o.codobligpif
              INNER JOIN obligpif os   ON os.codobligpif = s.codstinspif AND OS.SEMNIFICATIE IN (500, 600)
              INNER JOIN general  gs   ON gs.codgeneral = os.codgeneral
              INNER JOIN GENERAL G_STING_FACT ON G_STING_FACT.TIPDOC = GS.TIPDOC AND G_STING_FACT.CODDOC = GS.CODDOC
              INNER JOIN OBLIGPIF O_STING_FACT ON O_STING_FACT.CODGENERAL = G_STING_FACT.CODGENERAL
              INNER JOIN STINGERE S_STING_FACT ON S_STING_FACT.CODSTINGATORPIF = O_STING_FACT.CODOBLIGPIF
              INNER JOIN OBLIGPIF OBLIG_FACT ON OBLIG_FACT.CODOBLIGPIF = S_STING_FACT.CODSTINSPIF
              INNER JOIN GENERAL GENERAL_FACT ON OBLIG_FACT.CODGENERAL = GENERAL_FACT.CODGENERAL
              LEFT JOIN intrari  intr ON intr.codintr = GENERAL_FACT.coddoc and intr.tipdoc = GENERAL_FACT.tipdoc
              LEFT JOIN iesiri   ies  ON ies.codies = GENERAL_FACT.coddoc and ies.tipdoc = GENERAL_FACT.tipdoc
              LEFT JOIN trezor1 ts1 ON ts1.codtrezor1 = gs.coddoc AND gs.tipdoc IN (29,31)
              LEFT JOIN trezor ts ON ts.codtrezor = ts1.codtrezor
            WHERE T.CodTrezor = pCodDoc  AND t1.tiptranz IN (0,1) AND OS.SEMNIFICATIE IN (500, 600)
              AND Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) =1
          ) aSub
            LEFT JOIN NCONT                 C ON C.CodCont = aSub.Cont
            LEFT JOIN WINMADMIN.TAXCODESAFT T ON T.Cod     = C.TaxCode
        ) bSub
          LEFT JOIN WINMADMIN.TAXCODE_I TI ON TI.Cod    = TaxaI
          LEFT JOIN WINMADMIN.TAXCODE_E TE ON TE.Cod    = TaxaE
          LEFT JOIN TAXDECL             TD ON TD.TipDoc = bSub.TipDoc AND TD.CodDoc = bSub.CodDoc and TD.CodDoc1 = bSub.CodDoc1
        WHERE (Coalesce(TD.Manual, 0) &lt;&gt; 1)
      ) LOOP
        aValLinie := vRec.ValBaza;
        aTVALinie := vRec.ValTaxa;
        if aTVALinie = 0 and VRec.Procstopaj &lt;&gt; 0 then
          aTVALinie := Round(aValLinie*VRec.Procstopaj/100,2);
        end if;
        aTotBase  := 0;
        aTotVal   := 0;
        IF (vRec.Tvaincasare = 1) THEN
          --DELETE FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc AND T.CODDOC1 = vRec.CODDoc1;
          BEGIN
            SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl
            WHERE TipDoc = vRec.TipDocIO AND CodDoc = vRec.CodIO AND CodDoc1 &gt; 0;
          EXCEPTION WHEN OTHERS THEN
            aTotBase := 0; aTotVal := 0;
          END;
          aTotBase := Coalesce(aTotBase,0); aTotVal := Coalesce(aTotVal,0);
          IF (aTotBase + aTotVal) = 0 THEN
            BEGIN
              IF    vRec.TipDocIO &lt; 10 THEN UpdateTaxDecl(0, vRec.CodIO);
              ELSIF vRec.TipDocIO &lt; 27 THEN UpdateTaxDecl(1, vRec.CodIO);
              END IF;
              SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl WHERE TipDoc = vRec.TipDocIO and CodDoc = vRec.CodIO;
            EXCEPTION WHEN OTHERS THEN
              aTotBase := 0; aTotVal := 0;
            END;
          END IF;
        END IF;
        IF (vRec.Tvaincasare = 1)and(aTotVal) &lt;&gt; 0 THEN
          KIncas := (aValLinie + aTVALinie)/(aTotBase + aTotVal);
          FOR XRec IN (
            SELECT TaxCode, TVANeded, Sum(TotBase) TotBase, Sum(TotVal) TotVal
            FROM (
              SELECT TaxCode, Coalesce(I1.TVANeded, 0) TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari1 I1 ON I1.Codintr = T.Coddoc and I1.Codintr1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, Coalesce(I1.TVANeded, 0) TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari1 I1 ON I1.Codintr = T.Coddoc and I1.Codintr1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codintr and Tx.Coddoc1 = I1.Codintr1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT TaxCode, 0 TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri1 I1 ON I1.Codies = T.Coddoc and I1.Codies1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, 0 TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri1 I1 ON I1.Codies = T.Coddoc and I1.Codies1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codies and Tx.Coddoc1 = I1.Codies1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
            ) subs
            GROUP BY TaxCode, TVANeded
          ) LOOP
            IF ((XRec.Tvaneded = 0)or(xRec.TotBase &lt;&gt; 0)) and ((aValLinie + aTVALinie) &lt;&gt; 0) THEN
							IF vRec.TipTranz = 1  THEN
								IF vRec.ObiectTranz &lt;&gt; 1
								THEN
									cTaxa := &apos;0.2.1.01.9.0.9.1.&apos;||
									To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;);
									BEGIN
										SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
									EXCEPTION WHEN OTHERS THEN
										aTax := 0;
									END;
							  ELSE
									cTaxa := &apos;1.98.2.01.1.9.0.9.1.&apos;||
									To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;)||&apos;.0&apos;;
									BEGIN
										SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
									EXCEPTION WHEN OTHERS THEN
										aTax := 0;
									END;
								END IF;
							ELSE
								IF vRec.ObiectTranz = 1
								THEN
									cTaxa := &apos;0.2.1.01.9.0.9.1.&apos;||
									To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;);
									BEGIN
										SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
									EXCEPTION WHEN OTHERS THEN
										aTax := 0;
									END;
							  ELSE
									cTaxa := &apos;1.98.2.01.1.9.0.9.1.&apos;||
									To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;)||&apos;.0&apos;;
									BEGIN
										SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
									EXCEPTION WHEN OTHERS THEN
										aTax := 0;
									END;
								END IF;
							END IF;
              cKeia     := &apos;ok - &apos;||cTaxa;
              IF aTax = 0 THEN
                cKeia := &apos;?&apos;||cTaxa;
              END IF;
              BEGIN
                SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
                WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc  AND T.CODDOC1 = vRec.CODDoc1 and T.Taxcode = aTax ;
              EXCEPTION WHEN OTHERS THEN
                aCod := 0;
              END;
              IF xRec.TotVal = 0 THEN
								IF aCod &gt; 0 THEN
									DELETE FROM TAXDECL WHERE codTaxdecl = aCod;
								END IF;
              ELSE
								IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
									aTax := 0;
									cKeia := &apos;neplatitor TVA&apos;;
								END IF;
								IF aCod = 0 THEN
									Semn := +1;
									IF vRec.ObiectTranz = 1 THEN
										Semn := -1;
									END IF;
									aManual := 0;
									IF xRec.TotVal = 0 THEN aManual := 2; ELSE aManual := 0; END IF;
									INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,      coddoc1,      TaxCode, TaxBase,                  TaxVal,                  Cheia, Manual,  CodCont,   AnLuna)
									VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    Semn*xRec.Totbase*KIncas, Semn*xRec.TotVal*KIncas, cKeia, aManual, vRec.Cont, vRec.AnLuna);
								ELSE
									UPDATE TAXDECL
									SET TaxBase = TaxBase + Round(xRec.Totbase*KIncas,2), TaxVal = TaxVal + Round(xRec.TotVal*KIncas,2), CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
									WHERE codTaxdecl = aCod;
								END IF;
							END IF;
            END IF;
          END LOOP;
        ELSIF aTVALinie &lt;&gt; 0 THEN --nu e tva incasare
          aTax       := vRec.Taxa;
          ContTrezor := vRec.Cont;
          if VRec.Procstopaj &lt;&gt; 0 then
            aTax := 0;
						cKeia := &apos;stopaj&apos;;
            ContTrezor := Coalesce(pkg_categconst.GetValConstanta(&apos;ContStopNerez&apos; ,aAn,aLuna),&apos;0&apos;);
          end if;
          IF vRec.TipTranz = 1  THEN
            IF vRec.ObiectTranz &lt;&gt; 1 THEN cKeia := &apos;ok - &apos;||vRec.TaxaE;
                                     ELSE cKeia := &apos;ok - &apos;||vRec.TaxaI;
            END IF;
          ELSE
            IF vRec.ObiectTranz &lt;&gt; 1 THEN cKeia := &apos;ok - &apos;||vRec.TaxaI;
                                     ELSE cKeia := &apos;ok - &apos;||vRec.TaxaE;
            END IF;
          END IF;
          IF aTax = 0 and VRec.Procstopaj = 0 THEN
            IF vRec.TipTranz = 1
            THEN cKeia := &apos;?&apos;||vRec.TaxaE;
            ELSE cKeia := &apos;?&apos;||vRec.TaxaI;
            END IF;
          END IF;
          BEGIN
            SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
            WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC = vRec.CODDOC AND T.CODDOC1 = vRec.CODDOC1 ;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

					IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
						aTax := 0;
						cKeia := &apos;neplatitor TVA&apos;;
					END IF;

          IF Coalesce(aCod, 0) = 0 THEN
            IF vRec.ObiectTranz = 1 THEN
              aValLinie := -aValLinie;
              aTVALinie := -aTVALinie;
            END IF;
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual, CodCont,   AnLuna)
            VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    aValLinie, aTVALinie, cKeia, 0,      ContTrezor, vRec.AnLuna);
          ELSE
            UPDATE TAXDECL
            SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = ContTrezor
            WHERE codTaxdecl = aCod;
          END IF;
        END IF;--nu e tva incasare
        COMMIT;
      END LOOP;
    END IF;
  ELSIF pCaz = 4 THEN
    SELECT Subunitatea, An, Luna INTO aSubunit, aAn, aLuna FROM COMPENS WHERE CodCompens = pCodDoc;
    DELETE FROM TaxDecl WHERE TipDoc = 28 AND CodDoc = pCodDoc AND MANUAL = 0 ;
    FOR vRec IN (
		SELECT
			bSub.coddoc, bSub.coddoc1, bSub.tipdoc, bSub.AnLuna,
			Coalesce(TE.Taxa, TI.Taxa, bSub.Taxa) Taxa, bSub.ValBaza, bSub.ValTaxa,
			bSub.cont, bSub.impozit, bSub.Simbol, bSub.TaxCode, bSub.TaxaI, bSub.TaxaE, bSub.Retur, bSub.Debit,
			bSub.TVAIncasare, bSub.CodIO, bSub.TipDocIO, bSub.TipIO
		FROM (
			SELECT
				aSub.CodDoc, aSub.CodDoc1, aSub.tipdoc, aSub.Retur, aSub.Debit,aSub.AnLuna, C.TaxCode Taxa, Round(T.ProcTaxa,0) proc,
				CASE
					WHEN Coalesce(c.impozit,0) = 1 AND Coalesce(T.ProcTaxa,0) = 0 THEN 0
					WHEN Coalesce(c.impozit,0) = 1                                THEN Round(aSub.Val/(T.ProcTaxa/100),2)
					ELSE aSub.Val - aSub.TVA
				END ValBaza,
				CASE WHEN Coalesce(c.impozit,0) = 1 THEN aSub.Val ELSE aSub.TVA END ValTaxa, T.COD TaxCode,
				aSub.TaxaE||To_Char(Round(PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),&apos;FM900&apos;)       TaxaE,
				aSub.TaxaI||To_Char(Round(PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(CASE WHEN aSub.VAL-aSub.TVA = 0 THEN 0 ELSE aSub.TVA/(aSub.VAL-aSub.TVA) END*100, aSub.AnLuna),0),&apos;FM900&apos;)||&apos;.0&apos; TaxaI,
				aSub.cont, Coalesce(c.impozit,0) impozit, c.Simbol, TVAIncasare, aSub.CodIO, aSub.TipDocIO, aSub.TipIO
			FROM (
				SELECT
					t.codcompens coddoc, o.codobligpif coddoc1, 28 tipdoc,
					Case when intr.CodIntr is not null and SIGN(intr.Valdoc) &lt; 0 THEN 1
					     when Ies.CodIEs is not null and SIGN(Ies.ValDoc) &lt; 0 THEN 1
					     when gs.SEMNIFICATIE IN (310,410) THEN 1
							 else 0
					end Retur,
					Case when g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) THEN 1 else 0 end DEBIT,
					T.An*12+T.Luna AnLuna,
					Coalesce(ies.TVAIncasare, Coalesce(intr.TVAIncasare, 0)) TVAIncasare,
					Coalesce(ies.CodIes, Coalesce(intr.CodIntr, 0)) CodIO,
					Coalesce(ies.TipDoc, Coalesce(intr.TipDoc, 0)) TipDocIO,
					CASE WHEN ies.CodIes is not Null THEN 1 ELSE 0 END TipIO,
					CASE
            WHEN o.semnificatie IN (900,901, 950, 951) THEN o.icont
						ELSE PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(o.semnificatie, o.icont, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(o.codpart,t.an,t.luna))
					END cont,
					Case when G.Moneda = 0 then Coalesce(o.valoare,0) else Coalesce(o.valoare,0)*G.Curs end VAL,
					Case when G.Moneda = 0 then Coalesce(g.tva,0) else Coalesce(g.tva,0)*g.curs end   TVA,
          CASE
          WHEN g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) THEN  &apos;0.2.1.01.9.0.9.1.&apos;    --plata
          ELSE &apos;?&apos;
          END TaxaE,
          CASE
          WHEN g.SEMNIFICATIE IN (1350, 1351, 1352, 1353) THEN &apos;1.98.2.01.1.3.0.9.1.&apos; --incasare
          ELSE &apos;?&apos;
          END TaxaI
				FROM compens t
					LEFT JOIN general  g    ON g.tipdoc = 28 AND g.coddoc = t.codcompens
					LEFT JOIN obligpif o    ON o.codgeneral = g.codgeneral
					LEFT JOIN stingere s    ON s.codstingatorpif = o.codobligpif
					LEFT JOIN obligpif os   ON os.codobligpif = s.codstinspif
					LEFT JOIN general  gs   ON gs.codgeneral = os.codgeneral
					LEFT JOIN intrari  intr ON intr.codintr = gs.coddoc and intr.tipdoc = gs.tipdoc
					LEFT JOIN iesiri   ies  ON ies.codies = gs.coddoc and ies.tipdoc = gs.tipdoc
					LEFT JOIN compens  Cmp   ON Cmp.codcompens = gs.coddoc AND gs.tipdoc = 28
          LEFT JOIN TREZOR1  Tre1 ON Tre1.CODTREZOR1   = gs.CODDOC AND gs.TIPDOC IN (29, 30, 31, 33)
				WHERE T.codcompens = pCodDoc and Coalesce(o.codpart,0) &gt; 0
							and (g.SEMNIFICATIE IN (1300, 1301, 1302, 1303) or g.SEMNIFICATIE IN (1350, 1351, 1352, 1353))
				) aSub
            LEFT JOIN NCONT                 C ON C.CodCont = aSub.Cont
            LEFT JOIN WINMADMIN.TAXCODESAFT T ON T.Cod     = C.TaxCode
        ) bSub
          LEFT JOIN WINMADMIN.TAXCODE_I TI ON TI.Cod    = TaxaI
          LEFT JOIN WINMADMIN.TAXCODE_E TE ON TE.Cod    = TaxaE
        WHERE ((bsub.TVAIncasare = 1)or(bsub.ValTaxa &lt;&gt; 0))
      ) LOOP
        aValLinie := vRec.ValBaza;
        aTVALinie := vRec.ValTaxa;
        aTotBase  := 0;
        aTotVal   := 0;
        IF (vRec.Tvaincasare = 1) THEN
          --DELETE FROM TAXDECL T WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc AND T.CODDOC1 = vRec.CODDoc1;
          BEGIN
            SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl
            WHERE TipDoc = vRec.TipDocIO AND CodDoc = vRec.CodIO AND CodDoc1 &gt; 0;
          EXCEPTION WHEN OTHERS THEN
            aTotBase := 0; aTotVal := 0;
          END;
          aTotBase := Coalesce(aTotBase,0); aTotVal := Coalesce(aTotVal,0);
          IF (aTotBase + aTotVal) = 0 THEN
            BEGIN
              IF    vRec.TipDocIO &lt; 10 THEN UpdateTaxDecl(0, vRec.CodIO);
              ELSIF vRec.TipDocIO &lt; 27 THEN UpdateTaxDecl(1, vRec.CodIO);
              END IF;
              SELECT Sum(TaxBase), Sum(TaxVal) INTO aTotBase, aTotVal FROM TaxDecl WHERE TipDoc = vRec.TipDocIO and CodDoc = vRec.CodIO;
            EXCEPTION WHEN OTHERS THEN
              aTotBase := 0; aTotVal := 0;
            END;
          END IF;
        END IF;
        IF (vRec.Tvaincasare = 1)and(aTotVal) &lt;&gt; 0 THEN
          KIncas := (aValLinie + aTVALinie)/(aTotBase + aTotVal);
          FOR XRec IN (
            SELECT TaxCode, TVANeded, Sum(TotBase) TotBase, Sum(TotVal) TotVal
            FROM (
              SELECT TaxCode, Coalesce(I1.TVANeded, 0) TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari  I  ON I .Codintr = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Intrari1 I1 ON I1.Codintr = I.Codintr and I1.Codintr1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, Coalesce(I1.TVANeded, 0) TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Intrari  I  ON I .Codintr = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Intrari1 I1 ON I1.Codintr = I.Codintr and I1.Codintr1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codintr and Tx.Coddoc1 = I1.Codintr1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT TaxCode, 0 TVANeded, (TaxBase) TotBase, (TaxVal) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri   I  ON I .Codies = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Iesiri1 I1 ON I1.Codies = I.Codies and I1.Codies1 = T.Coddoc1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
              UNION ALL
              SELECT Tx.Taxcode, 0 TVANeded, Coalesce(-t.TaxBase, 0) TotBase, Coalesce(-t.TaxVal, 0) TotVal
              FROM TaxDecl T
                INNER JOIN Iesiri   I  ON I .Codies = T.Coddoc and I.TipDoc = T.TipDoc
                INNER JOIN Iesiri1 I1 ON I1.Codies = I.Codies and I1.Codies1 = -T.Coddoc1
                LEFT  JOIN TaxDecl Tx ON Tx.Coddoc = I1.Codies and Tx.Coddoc1 = I1.Codies1
              WHERE T.TipDoc = vRec.TipDocIO and T.CodDoc = vRec.CodIO
            ) subs
            GROUP BY TaxCode, TVANeded
          ) LOOP
            IF ((XRec.Tvaneded = 0)or(xRec.TotBase &lt;&gt; 0)) and ((aValLinie + aTVALinie) &lt;&gt; 0) THEN
              IF vRec.Debit = 1 THEN
                  if vRec.Retur = 0 then
                    cTaxa := &apos;1.98.2.01.1.9.0.9.1.&apos;||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;)||&apos;.0&apos;;
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                   else
                    cTaxa := &apos;0.2.1.01.9.0.9.1.&apos;||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;);
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                   end if;
              ELSE
                  if vRec.Retur = 0 then
                    cTaxa := &apos;0.2.1.01.9.0.9.1.&apos;||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;);
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                  else
                    cTaxa := &apos;1.98.2.01.1.9.0.9.1.&apos;||
                    To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;)||&apos;.0&apos;;
                    BEGIN
                      SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
                    EXCEPTION WHEN OTHERS THEN
                      aTax := 0;
                    END;
                  end if;
              END IF;
              cKeia     := &apos;ok - &apos;||cTaxa;
              IF aTax = 0 THEN
                cKeia := &apos;?&apos;||cTaxa;
              END IF;
              BEGIN
                SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
                WHERE T.TipDoc = vRec.TIPDoc AND T.CODDOC = vRec.CODDoc  AND T.CODDOC1 = vRec.CODDoc1 and T.Taxcode = aTax ;
              EXCEPTION WHEN OTHERS THEN
                aCod := 0;
              END;
              IF xRec.TotVal = 0 THEN
								IF aCod &gt; 0 THEN
									DELETE FROM TAXDECL WHERE codTaxdecl = aCod;
								END IF;
              ELSE
								IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
									aTax := 0;
									cKeia := &apos;neplatitor TVA&apos;;
								END IF;
  		          IF vRec.Retur = 1 THEN
									Semn := -1;
								ELSE
									Semn := +1;
                END IF;

								IF aCod = 0 THEN
									aManual := 0;
									IF xRec.TotVal = 0 THEN aManual := 2; ELSE aManual := 0; END IF;
									INSERT INTO TAXDECL(codTaxdecl,        tipdoc,      coddoc,      coddoc1,      TaxCode, TaxBase,                  TaxVal,                  Cheia, Manual,  CodCont,   AnLuna)
									VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    Semn*xRec.Totbase*KIncas, Semn*xRec.TotVal*KIncas, cKeia, aManual, vRec.Cont, vRec.AnLuna);
								ELSE
									UPDATE TAXDECL
									SET TaxBase = TaxBase + Semn*Round(xRec.Totbase*KIncas,2), TaxVal = TaxVal + Semn*Round(xRec.TotVal*KIncas,2), CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
									WHERE codTaxdecl = aCod;
								END IF;
							END IF;
            END IF;
          END LOOP;
        ELSIF aTVALinie &lt;&gt; 0 THEN --nu e tva incasare
          aTax      := vRec.Taxa;
/*
					IF vRec.Debit = 0  THEN
							cTaxa := &apos;1.98.2.01.1.9.0.9.1.&apos;||
							To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;)||&apos;.0&apos;;
							BEGIN
								SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_I WHERE Cod  = cTaxa;
							EXCEPTION WHEN OTHERS THEN
								aTax := 0;
							END;
					ELSE
							cTaxa := &apos;0.2.1.01.9.0.9.1.&apos;||
							To_Char(Round(CASE WHEN xRec.Totbase = 0 THEN 0 ELSE 100*xRec.Totval/xRec.Totbase END,0),&apos;FM900&apos;);
							BEGIN
								SELECT Taxa into aTax FROM WINMADMIN.TAXCODE_E WHERE Cod  = cTaxa;
							EXCEPTION WHEN OTHERS THEN
								aTax := 0;
							END;
				  END IF;
          cKeia     := &apos;ok - &apos;||cTaxa;
*/
          IF aTax = 0 THEN
           cKeia := &apos;?&apos;||cTaxa;
          END IF;
          BEGIN
            SELECT T.codTaxdecl INTO aCod FROM TAXDECL T
            WHERE T.TipDoc = vRec.TIPDOC AND T.CODDOC = vRec.CODDOC AND T.CODDOC1 = vRec.CODDOC1 ;
          EXCEPTION WHEN OTHERS THEN
            aCod := 0;
          END;

					IF FirmaPlatitorTVA(aSubunit, aAn, aLuna) = 0 THEN
						aTax := 0;
						cKeia := &apos;neplatitor TVA&apos;;
					END IF;

          IF vRec.Retur = 1 THEN
              aValLinie := -aValLinie;
              aTVALinie := -aTVALinie;
          END IF;
          IF Coalesce(aCod, 0) = 0 THEN
            INSERT INTO TAXDECL(codTaxdecl,        tipdoc, coddoc,      coddoc1,      TaxCode, TaxBase,   TaxVal,    Cheia, Manual, CodCont,   AnLuna)
            VALUES(SEQ_TAXDECL_CODTAXDECL.Nextval, vRec.TIPDOC, vRec.CODDOC, vRec.CODDOC1, aTAX,    aValLinie, aTVALinie, cKeia, 0,      vRec.Cont, vRec.AnLuna);
          ELSE
            UPDATE TAXDECL
            SET TaxBase = aValLinie, TaxVal = aTVALinie, CHEIA = cKeia, AnLuna = vRec.AnLuna, TaxCode = aTax, CodCont = vRec.Cont
            WHERE codTaxdecl = aCod;
          END IF;
        END IF;--nu e tva incasare
        COMMIT;
		 END LOOP;
	END IF;
END;

PROCEDURE UPDATE_SAFT_RESET_SEQ IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM SAFT_RESET_SEQ WHERE CURRENT_TIMESTAMP - APEL_TIMESTAMP &gt; INTERVAL &apos;2&apos; HOUR;
  INSERT INTO SAFT_RESET_SEQ VALUES (CURRENT_TIMESTAMP);
  COMMIT;
END;

PROCEDURE RESET_SEQ IS
  vCNT    NUMBER(5);
BEGIN
  UPDATE_SAFT_RESET_SEQ;
  SELECT Count(1) INTO vCNT FROM SAFT_RESET_SEQ;

  IF vCNT &lt;= 1 THEN
    PKG_REMAKE_SEQUENCES.RESTART_SEQUENCE(&apos;SEQ_SAFT&apos;);
    PKG_REMAKE_SEQUENCES.RESTART_SEQUENCE(&apos;SEQ_SAFT_TI&apos;);
  END IF;
END;

PROCEDURE TRUNCATE_TABLES IS
BEGIN
  FOR vRec IN (
    SELECT SURSA                    FROM SAFTTAB UNION
    SELECT &apos;TMP_SAFT_PARAMS&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NCONT&apos;         FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_CODSAF&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_TAXINFO&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_TAXINFO_MP&apos;    FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPART&apos;         FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPARTDET&apos;      FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPARTFUZ&apos;      FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNAL&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNAL1&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNALDET&apos;     FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_MIFIX1&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_CC4426&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_STOCKMOVEMENT&apos; FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_EXCL_J1&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_MANEVRA&apos;       FROM DUAL
  ) LOOP
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||vRec.SURSA;
  END LOOP;
END;

PROCEDURE SAVE_TABLES IS
BEGIN
  PUT_INFO(&apos;99.A&apos;,&apos;SAVE_TABLES&apos;);
  FOR vRec IN (
    SELECT SURSA                    FROM SAFTTAB UNION
    SELECT &apos;TMP_SAFT_PARAMS&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NCONT&apos;         FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_CODSAF&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_TAXINFO&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_TAXINFO_MP&apos;    FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPART&apos;         FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPARTDET&apos;      FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_NPARTFUZ&apos;      FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNAL&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNAL1&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_JURNALDET&apos;     FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_MIFIX1&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_CC4426&apos;        FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_STOCKMOVEMENT&apos; FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_EXCL_J1&apos;       FROM DUAL    UNION
    SELECT &apos;TMP_SAFT_MANEVRA&apos;       FROM DUAL
  ) LOOP
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP TABLE SAV_&apos;||vRec.SURSA||&apos; PURGE&apos;;
    EXCEPTION
      WHEN OTHERS THEN NULL;
    END;
    EXECUTE IMMEDIATE &apos;CREATE TABLE SAV_&apos;||vRec.SURSA||&apos; AS SELECT * FROM &apos;||vRec.SURSA;
  END LOOP;
END;

PROCEDURE UMPLE_T01 IS --SAF_HEADER
  vSubunit NUMBER(20);
BEGIN
  PUT_INFO(&apos;01.A&apos;,&apos;UMPLE_T01--SAF_HEADER&apos;);

  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT01
    SELECT
      01                           COL01,--CODSAF_HEADER                  NUMBER(20)
      &apos;1.0&apos;                        COL02,--AUDITFILEVERSION               NVARCHAR2(9)
      T.SIMBAUTO                   COL03,--AUDITFILECOUNTRY               NVARCHAR2(2)
      T.SIMBAUTO||&apos;-&apos;||J.SIMBAUTO  COL04,--AUDITFILEREGION                NVARCHAR2(9)
      SYSDATE                      COL05,--AUDITFILEDATECREATED           DATE
      &apos;TH JUNIOR SRL&apos;              COL06,--SOFTWARECOMPANYNAME            NVARCHAR2(70)
      &apos;WinMENTOR Enterprise&apos;       COL07,--SOFTWAREID                     NVARCHAR2(256)
      To_Char(V.Version, &apos;00D000&apos;) COL08,--SOFTWAREVERSION                NVARCHAR2(18)
      06                           COL09,--CODCOMPANYSAF_COMPANYSTRUCTURE NUMBER(20)
      NULL                         COL10,--CODPOSTALADDRESSSAF_ADDRESS    NUMBER(20)
      &apos;RON&apos;                        COL11,--DEFAULTCURRENCYCODE            NVARCHAR2(3)
      02                           COL12,--CODSAF_SELECTIONCRITERIA       NUMBER(20)
      CASE SP.TIP
        WHEN 1 THEN &apos;L&apos;
        WHEN 2 THEN &apos;T&apos;
        WHEN 3 THEN &apos;A&apos;
        WHEN 4 THEN &apos;C&apos;
        WHEN 5 THEN &apos;NL&apos;
        WHEN 6 THEN &apos;NT&apos;
        WHEN 7 THEN &apos;A&apos;
      END                          COL13,--HEADERCOMMENT                  NVARCHAR2(256)
      1                            COL14,--SEGMENTINDEX                   NVARCHAR2(9)
      1                            COL15,--TOTALSEGMENTSINSEQUENCE        NVARCHAR2(9)
      CASE F.TIPCONTA
        WHEN  1 THEN &apos;A&apos;
        WHEN  2 THEN &apos;I&apos;
        WHEN  3 THEN &apos;IFRS&apos;
        WHEN  4 THEN &apos;BANK&apos;
        WHEN  5 THEN &apos;INSURANCE&apos;
        WHEN  6 THEN &apos;NORMA39&apos;
        WHEN  7 THEN &apos;IFN&apos;
        WHEN  8 THEN &apos;NORMA14&apos;
        WHEN  9 THEN &apos;NORMA36&apos;
        WHEN 10 THEN &apos;ONG&apos;
        WHEN 11 THEN &apos;ONGE&apos;
      END                          COL16,--TAXACCOUNTINGBASIS             NVARCHAR2(18)
      &apos;Company&apos;                    COL17 --TAXENTITY                      NVARCHAR2(70)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN WINMADMIN.FIRMA    F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN WINMADMIN.NLOCALIT L ON L.CODLOCALIT = F.CODLOCALIT
      LEFT  JOIN WINMADMIN.NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN WINMADMIN.NTARI    T ON T.CODTARA    = L.CODTARA
      CROSS JOIN VERSION V;
   ELSE
    INSERT INTO TMP_SAFT01
    SELECT
      01                           COL01,--CODSAF_HEADER                  NUMBER(20)
      &apos;1.0&apos;                        COL02,--AUDITFILEVERSION               NVARCHAR2(9)
      T.SIMBAUTO                   COL03,--AUDITFILECOUNTRY               NVARCHAR2(2)
      T.SIMBAUTO||&apos;-&apos;||J.SIMBAUTO  COL04,--AUDITFILEREGION                NVARCHAR2(9)
      SYSDATE                      COL05,--AUDITFILEDATECREATED           DATE
      &apos;TH JUNIOR SRL&apos;              COL06,--SOFTWARECOMPANYNAME            NVARCHAR2(70)
      &apos;WinMENTOR Enterprise&apos;       COL07,--SOFTWAREID                     NVARCHAR2(256)
      To_Char(V.Version, &apos;00D000&apos;) COL08,--SOFTWAREVERSION                NVARCHAR2(18)
      06                           COL09,--CODCOMPANYSAF_COMPANYSTRUCTURE NUMBER(20)
      NULL                         COL10,--CODPOSTALADDRESSSAF_ADDRESS    NUMBER(20)
      &apos;RON&apos;                        COL11,--DEFAULTCURRENCYCODE            NVARCHAR2(3)
      02                           COL12,--CODSAF_SELECTIONCRITERIA       NUMBER(20)
      CASE SP.TIP
        WHEN 1 THEN &apos;L&apos;
        WHEN 2 THEN &apos;T&apos;
        WHEN 3 THEN &apos;A&apos;
        WHEN 4 THEN &apos;C&apos;
        WHEN 5 THEN &apos;NL&apos;
        WHEN 6 THEN &apos;NT&apos;
        WHEN 7 THEN &apos;A&apos;
      END                          COL13,--HEADERCOMMENT                  NVARCHAR2(256)
      1                            COL14,--SEGMENTINDEX                   NVARCHAR2(9)
      1                            COL15,--TOTALSEGMENTSINSEQUENCE        NVARCHAR2(9)
      CASE F.TIPCONTA
        WHEN  1 THEN &apos;A&apos;
        WHEN  2 THEN &apos;I&apos;
        WHEN  3 THEN &apos;IFRS&apos;
        WHEN  4 THEN &apos;BANK&apos;
        WHEN  5 THEN &apos;INSURANCE&apos;
        WHEN  6 THEN &apos;NORMA39&apos;
        WHEN  7 THEN &apos;IFN&apos;
        WHEN  8 THEN &apos;NORMA14&apos;
        WHEN  9 THEN &apos;NORMA36&apos;
        WHEN 10 THEN &apos;ONG&apos;
        WHEN 11 THEN &apos;ONGE&apos;
      END                          COL16,--TAXACCOUNTINGBASIS             NVARCHAR2(18)
      &apos;Company&apos;                    COL17 --TAXENTITY                      NVARCHAR2(70)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN NSUBUNIT        S ON S.CODSUBUNIT = SP.CODSUBUNIT
      INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN NAGENDA         A ON A.CODSUBUNIT = SP.CODSUBUNIT
      LEFT  JOIN NLOCALIT        L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT  JOIN NJUDET          J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN NTARI           T ON T.CODTARA    = L.CODTARA
      CROSS JOIN VERSION V;
   END IF;
  PUT_INFO(&apos;01.Z&apos;,&apos;UMPLE_T01--SAF_HEADER&apos;);
END;

PROCEDURE UMPLE_T02 IS --SAF_SELECTIONCRITERIA
BEGIN
  PUT_INFO(&apos;02.A&apos;,&apos;UMPLE_T02--SAF_SELECTIONCRITERIA&apos;);
  INSERT INTO TMP_SAFT02
  SELECT
    2                                       COL01,--CODSAF_SELECTIONCRITERIA NUMERIC(20,0)
    NULL                                    COL02,--TAXREPORTINGJURISDICTION STRING(35,0)
    NULL                                    COL03,--COMPANYENTITY            STRING(70,0)
    Trunc(
      To_Date(SP.ANINI||SP.LUNAINI, &apos;yyyymm&apos;),
      &apos;MM&apos;
    )                                       COL04,--SELECTIONSTARTDATE       DATE(10,0)
    LAST_DAY(
      To_Date(SP.ANFIN||SP.LUNAFIN, &apos;yyyymm&apos;)
    )                                       COL05,--SELECTIONENDDATE         DATE(10,0)
    SP.LUNAINI                              COL06,--PERIODSTART              NUMERIC(20,0)
    SP.ANINI                                COL07,--PERIODSTARTYEAR          NUMERIC(20,0)
    SP.LUNAFIN                              COL08,--PERIODEND                NUMERIC(20,0)
    SP.ANFIN                                COL09,--PERIODENDYEAR            NUMERIC(20,0)
    NULL                                    COL10,--DOCUMENTTYPE             STRING(255,0)
    NULL                                    COL11 --OTHERCRITERIA            STRING(255,0)
  FROM TMP_SAFT_PARAMS SP;
  PUT_INFO(&apos;02.Z&apos;,&apos;UMPLE_T02&apos;);
END;

PROCEDURE UMPLE_T03 IS --SAF_ACCOUNT
  vSubunit NUMBER(20);
BEGIN
  PUT_INFO(&apos;03.A&apos;,&apos;UMPLE_T03&apos;);
  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT03
  SELECT
    SEQ_SAFT.NEXTVAL                                  COL01,--CODSAF_ACCOUNT       -&gt; NUMERIC(20,0)
    CODSAFT                                           COL02,--ACCOUNTID            -&gt; STRING(70,0)
    DEN_CONT                                          COL03,--ACCOUNTDESCRIPTION   -&gt; STRING(255,0)
    SubStr(SIMBOL, 1, 35)                             COL04,--STANDARDACCOUNTID    -&gt; STRING(35,0)
    NULL                                              COL05,--GROUPINGCATEGORY     -&gt; STRING(35,0)
    NULL                                              COL06,--GROUPINGCODE         -&gt; STRING(35,0)
    CASE
      WHEN TIPCONT = 1  THEN &apos;Pasiv&apos;
      WHEN TIPCONT = 2  THEN &apos;Bifunctional&apos;
                        ELSE &apos;Activ&apos;
    END                                               COL07,--ACCOUNTTYPE          -&gt; STRING(18,0)
    NULL                                              COL08,--ACCOUNTCREATIONDATE  -&gt; DATE(10,0)
    CASE
      WHEN TIPCONT = 1                                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDINI &lt; 0                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDINI = 0 AND SOLDFIN &lt; 0 THEN NULL
      ELSE                                                  SOLDINI
    END                                               COL09,--OPENINGDEBITBALANCE  -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN -SOLDINI
      WHEN TIPCONT = 2 AND SOLDINI &lt; 0                 THEN -SOLDINI
      WHEN TIPCONT = 2 AND SOLDINI = 0 AND SOLDFIN &lt; 0 THEN -SOLDINI
      ELSE                                                  NULL
    END                                               COL10,--OPENINGCREDITBALANCE -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDFIN &lt; 0                 THEN NULL
      WHEN TIPCONT = 2 AND SOLDFIN = 0 AND SOLDINI &lt; 0 THEN NULL
      ELSE                                                  SOLDFIN
    END                                               COL11,--CLOSINGDEBITBALANCE  -&gt; NUMERIC(18,2)
    CASE
      WHEN TIPCONT = 1                                 THEN -SOLDFIN
      WHEN TIPCONT = 2 AND SOLDFIN &lt; 0                 THEN -SOLDFIN
      WHEN TIPCONT = 2 AND SOLDFIN = 0 AND SOLDINI &lt; 0 THEN -SOLDFIN
      ELSE                                                  NULL
    END                                               COL12 --CLOSINGCREDITBALANCE -&gt; NUMERIC(18,2)
  FROM (
    SELECT
      C.CODCONT, C.TIPCONT, C.CODSAFT, C.DEN_CONT, C.SIMBOL,
      CASE
        WHEN vSubunit = 1
        THEN Coalesce(CSI.SOLDID,0) - Coalesce(CSI.SOLDIC,0) +  Coalesce(CRI.RULAJPD,0) - Coalesce(CRI.RULAJPC,0)
        ELSE Coalesce(SSI.SOLDID,0) - Coalesce(SSI.SOLDIC,0) +  Coalesce(SRI.RULAJPD,0) - Coalesce(SRI.RULAJPC,0)
      END SOLDINI,
      CASE
        WHEN vSubunit = 1
        THEN Coalesce(CSF.SOLDID,0) - Coalesce(CSF.SOLDIC,0) +  Coalesce(CRF.RULAJPD,0) - Coalesce(CRF.RULAJPC,0) + Coalesce(CRF.RULAJCD,0) - Coalesce(CRF.RULAJCC,0)
        ELSE Coalesce(SSF.SOLDID,0) - Coalesce(SSF.SOLDIC,0) +  Coalesce(SRF.RULAJPD,0) - Coalesce(SRF.RULAJPC,0) + Coalesce(SRF.RULAJCD,0) - Coalesce(SRF.RULAJCC,0)
      END SOLDFIN
    FROM TMP_SAFT_NCONT C
      CROSS JOIN TMP_SAFT_PARAMS SP
      LEFT JOIN NCONTSOLD    CSI ON CSI.CODCONT = C.CODCONT AND CSI.AN = SP.ANINI AND CSI.LUNA = 1
      LEFT JOIN NCONTRUL     CRI ON CRI.CODCONT = C.CODCONT AND CRI.AN = SP.ANINI AND CRI.LUNA = SP.LUNAINI
      LEFT JOIN NCONTSOLD    CSF ON CSF.CODCONT = C.CODCONT AND CSF.AN = SP.ANFIN AND CSF.LUNA = 1
      LEFT JOIN NCONTRUL     CRF ON CRF.CODCONT = C.CODCONT AND CRF.AN = SP.ANFIN AND CRF.LUNA = SP.LUNAFIN
      LEFT JOIN NCONTSOLDSUB SSI ON SSI.CODCONTSOLD = CSI.CODCONTSOLD AND SSI.SUBUNITATEA = vSubunit AND SSI.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTRULSUB  SRI ON SRI.CODCONTRUL  = CRI.CODCONTRUL  AND SRI.SUBUNITATEA = vSubunit AND SRI.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTSOLDSUB SSF ON SSF.CODCONTSOLD = CSF.CODCONTSOLD AND SSF.SUBUNITATEA = vSubunit AND SSF.SUBUNITATEA &lt;&gt; 1
      LEFT JOIN NCONTRULSUB  SRF ON SRF.CODCONTRUL  = CRF.CODCONTRUL  AND SRF.SUBUNITATEA = vSubunit AND SRF.SUBUNITATEA &lt;&gt; 1
    WHERE C.FRUNZA = 1 AND C.CODSAFT IS NOT NULL
    ORDER BY C.CODSAFT
  ) ssub;
  PUT_INFO(&apos;03.Z&apos;,&apos;UMPLE_T03--SAF_SELECTIONCRITERIA&apos;);
END;

PROCEDURE UMPLE_T04 IS --SAF_CUSTOMER
BEGIN
  PUT_INFO(&apos;04.A&apos;,&apos;UMPLE_T04--SAF_CUSTOMER&apos;);
  INSERT INTO TMP_SAFT04
  SELECT
    SEQ_SAFT.NEXTVAL                             COL01,--CODSAF_CUSTOMER         NUMERIC(20,0)
    C06.CODSAF                                   COL02,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
    PD.PartID                                    COL03,--CUSTOMERID              STRING(35,0)
    NULL                                         COL04,--SELFBILLINGINDICATOR    STRING(9,0)
    P.CODSAFT                                    COL05,--ACCOUNTID               STRING(70,0)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDI
    END                                          COL06,--OPENINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDI
                                                         ELSE NULL
    END                                          COL07,--OPENINGCREDITBALANCE    NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDF

    END                                          COL08,--CLOSINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDF
                                                         ELSE NULL
    END                                          COL09 --CLOSINGCREDITBALANCE    NUMERIC(18,2)
  FROM (
    SELECT F.CODPARTFUZ AS CODPART, C.CODSAFT, C.TIPCONT, Sum(TP.SOLDI) SOLDI, Sum(TP.SOLDF) SOLDF
    FROM TMP_SAFT_NPART TP
      INNER JOIN TMP_SAFT_NCONT    C ON C.CODCONT = TP.CODCONT AND C.NO_SOLDPART = 0
      INNER JOIN TMP_SAFT_NPARTFUZ F ON F.CODPART = TP.CODPART
    WHERE TP.CLIENT = 1
    GROUP BY F.CODPARTFUZ, C.CODSAFT, C.TIPCONT
  ) P
    INNER JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = P.CODPART
    LEFT  JOIN TMP_SAFT_CODSAF   C06 ON C06.CODSURSA = P.CODPART AND C06.CodSAFTTab = 06;
  PUT_INFO(&apos;04.Z&apos;,&apos;UMPLE_T04--SAF_CUSTOMER&apos;);
END;

PROCEDURE UMPLE_T05 IS --SAF_SUPPLIER
BEGIN
  PUT_INFO(&apos;05.A&apos;,&apos;UMPLE_T05--SAF_SUPPLIER&apos;);
  INSERT INTO TMP_SAFT05
  SELECT
    SEQ_SAFT.NEXTVAL                             COL01,--CODSAF_SUPPLIER         NUMERIC(20,0)
    C06.CODSAF                                   COL02,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
    PD.PartID                                    COL03,--SUPPLIERID              STRING(35,0)
    NULL                                         COL04,--SELFBILLINGINDICATOR    STRING(9,0)
    P.CODSAFT                                    COL05,--ACCOUNTID               STRING(70,0)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDI
    END                                          COL06,--OPENINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDI
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDI
                                                         ELSE NULL
    END                                          COL07,--OPENINGCREDITBALANCE    NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN NULL
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN NULL
                                                         ELSE P.SOLDF

    END                                          COL08,--CLOSINGDEBITBALANCE     NUMERIC(18,2)
    CASE
      WHEN P.TIPCONT = 1                                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI &lt; 0                 THEN -P.SOLDF
      WHEN P.TIPCONT = 2 AND P.SOLDI = 0 AND P.SOLDF &lt; 0 THEN -P.SOLDF
                                                         ELSE NULL
    END                                          COL09 --CLOSINGCREDITBALANCE    NUMERIC(18,2)
  FROM (
    SELECT F.CODPARTFUZ AS CODPART, C.CODSAFT, C.TIPCONT, Sum(TP.SOLDI) SOLDI, Sum(TP.SOLDF) SOLDF
    FROM TMP_SAFT_NPART TP
      INNER JOIN TMP_SAFT_NCONT    C ON C.CODCONT = TP.CODCONT AND C.NO_SOLDPART = 0
      INNER JOIN TMP_SAFT_NPARTFUZ F ON F.CODPART = TP.CODPART
    WHERE TP.FURNIZOR = 1
    GROUP BY F.CODPARTFUZ, C.CODSAFT, C.TIPCONT
  ) P
    INNER JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = P.CODPART
    LEFT  JOIN TMP_SAFT_CODSAF   C06 ON C06.CODSURSA = P.CODPART AND C06.CodSAFTTab = 06;
  PUT_INFO(&apos;05.Z&apos;,&apos;UMPLE_T05--SAF_SUPPLIER&apos;);
END;

PROCEDURE UMPLE_T06 IS --SAF_COMPANYSTRUCTURE
  vSubunit NUMBER(20);
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;06.A&apos;,&apos;UMPLE_T06--SAF_COMPANYSTRUCTURE&apos;);
  SELECT TIP,  CODSUBUNIT
  INTO   vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT06
    SELECT
      06                                     COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      F.CODFISCAL                            COL02,--REGISTRATIONNUMBER      STRING(35,0)
      SubStr(F.DENFIRMA, 1, 70)              COL03,--NAME                    STRING(70,0)
      07                                     COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      08                                     COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      10                                     COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      11                                     COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE
    INSERT INTO TMP_SAFT06
    SELECT
      06                                     COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      S.CIF                                  COL02,--REGISTRATIONNUMBER      STRING(35,0)
      SubStr(S.DEN_SUBUNIT, 1, 70)           COL03,--NAME                    STRING(70,0)
      07                                     COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      08                                     COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      10                                     COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      11                                     COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT06
    SELECT
      C06.CODSAF                             COL01,--CODSAF_COMPANYSTRUCTURE NUMERIC(20,0)
      PD.PartID                              COL02,--REGISTRATIONNUMBER      STRING(35,0)
      Substr(P.DEN_PART, 1, 70)              COL03,--NAME                    STRING(70,0)
      C07.CODSAF                             COL04,--CODSAF_ADDRESS          NUMERIC(20,0)
      C08.CODSAF                             COL05,--CODSAF_CONTACT          NUMERIC(20,0)
      C10.CODSAF                             COL06,--CODSAF_TAXREGISTRATION  NUMERIC(20,0)
      C11.CODSAF                             COL07 --CODSAF_BANKACCOUNT      NUMERIC(20,0)
    FROM TMP_SAFT_CODSAF C06
      LEFT JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = C06.CODSURSA
      LEFT JOIN NPART             P   ON P.CODPART    = C06.CODSURSA
      LEFT JOIN NAGENDA           A   ON A.CODPART    = C06.CODSURSA     AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NPARTB            PB  ON PB.CODPART   = C06.CODSURSA     AND PB.IMPLICIT = 1
      LEFT JOIN TMP_SAFT_CODSAF   C07 ON C07.CODSURSA = A.CODAGENDA      AND C07.CodSAFTTab = 07
      LEFT JOIN TMP_SAFT_CODSAF   C08 ON C08.CODSURSA = C06.CODSURSA     AND C08.CodSAFTTab = 08
      LEFT JOIN TMP_SAFT_CODSAF   C10 ON C10.CODSURSA = PD.COD_CODFISCAL AND C10.CodSAFTTab = 10
      LEFT JOIN TMP_SAFT_CODSAF   C11 ON C11.CODSURSA = PB.CODPARTB      AND C11.CodSAFTTab = 11
    WHERE C06.CodSAFTTab = 06;
  END IF;
  PUT_INFO(&apos;06.Z&apos;,&apos;UMPLE_T06--SAF_COMPANYSTRUCTURE&apos;);
END;

PROCEDURE UMPLE_T07 IS --SAF_ADDRESS
  vSubunit NUMBER(20);
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;07.A&apos;,&apos;UMPLE_T07--SAF_ADDRESS&apos;);
  SELECT TIP,  CODSUBUNIT
  INTO   vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT07
    SELECT
      07                                               COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(F.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      Coalesce(Trim(F.NR1), &apos;&apos;)||
      CASE WHEN Coalesce(Length(Trim(F.NR1)),0) = 0 OR Coalesce(Length(Trim(F.NR2)),0) = 0 THEN &apos;&apos; ELSE &apos;-&apos; END||
      Coalesce(Trim(F.NR2), &apos;&apos;)                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(F.BLOC ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Bl.&apos;||F.BLOC  END||
        CASE WHEN NULLIF(Trim(F.SCARA), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Sc.&apos;||F.SCARA END||
        CASE WHEN NULLIF(Trim(F.ETAJ ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Et.&apos;||F.ETAJ  END||
        CASE WHEN NULLIF(Trim(F.AP   ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Ap.&apos;||F.AP    END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      To_Char(F.CodPostal, &apos;fm9999999990&apos;)             COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||&apos;-&apos;||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      &apos;PostalAddress&apos;                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN WINMADMIN.FIRMA    F ON F.CODFIRMA   = SP.CODFIRMA
      LEFT  JOIN WINMADMIN.NLOCALIT L ON L.CODLOCALIT = F.CODLOCALIT
      LEFT  JOIN WINMADMIN.NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN WINMADMIN.NTARI    T ON T.CODTARA    = L.CODTARA;
  ELSE
    INSERT INTO TMP_SAFT07
    SELECT
      07                                               COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(A.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      Coalesce(To_Char(A.NR1, &apos;fm99999&apos;), &apos;&apos;)||
      CASE WHEN Coalesce(A.NR1,0) = 0 OR Coalesce(Length(Trim(A.NR2)),0) = 0 THEN &apos;&apos; ELSE &apos;-&apos; END||
      Coalesce(Trim(A.NR2), &apos;&apos;)                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(A.BLOC ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Bl.&apos;||A.BLOC  END||
        CASE WHEN NULLIF(Trim(A.SCARA), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Sc.&apos;||A.SCARA END||
        CASE WHEN NULLIF(Trim(A.ETAJ ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Et.&apos;||A.ETAJ  END||
        CASE WHEN NULLIF(Trim(A.APART), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Ap.&apos;||A.APART END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      A.CodPostal                                      COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||&apos;-&apos;||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      &apos;PostalAddress&apos;                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_PARAMS SP
      INNER JOIN NAGENDA  A ON A.CODSUBUNIT = SP.CODSUBUNIT
      LEFT  JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT  JOIN NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT  JOIN NTARI    T ON T.CODTARA    = L.CODTARA;
  END IF;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT07
    SELECT
      C07.CODSAF                                       COL01,--CODSAF_ADDRESS          NUMERIC(20,0)
      SUBSTR(Trim(A.STRADA), 1, 70)                    COL02,--STREETNAME              STRING(70,0)
      Coalesce(To_Char(A.NR1, &apos;fm99999&apos;), &apos;&apos;)||
      CASE WHEN Coalesce(A.NR1,0) = 0 OR Coalesce(Length(Trim(A.NR2)),0) = 0 THEN &apos;&apos; ELSE &apos;-&apos; END||
      Coalesce(Trim(A.NR2), &apos;&apos;)                        COL03,--NUMBERX                 STRING(18,0)
      SubStr(
        CASE WHEN NULLIF(Trim(A.BLOC ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Bl.&apos;||A.BLOC  END||
        CASE WHEN NULLIF(Trim(A.SCARA), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Sc.&apos;||A.SCARA END||
        CASE WHEN NULLIF(Trim(A.ETAJ ), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Et.&apos;||A.ETAJ  END||
        CASE WHEN NULLIF(Trim(A.APART), &apos;&apos;) IS NULL THEN &apos;&apos; ELSE &apos;, Ap.&apos;||A.APART END
        , 3, 70
      )                                                COL04,--ADDITIONALADDRESSDETAIL STRING(70,0)
      NULL                                             COL05,--BUILDING                STRING(35,0)
      SubStr(L.DEN_LOCALIT, 1, 35)                     COL06,--CITY                    STRING(35,0)
      A.CodPostal                                      COL07,--POSTALCODE              STRING(18,0)
      T.SIMBAUTO||&apos;-&apos;||J.SIMBAUTO                      COL08,--REGION                  STRING(35,0)
      SubStr(Trim(T.SIMBAUTO), 1, 2)                   COL09,--COUNTRY                 STRING(2,0)
      &apos;PostalAddress&apos;                                  COL10 --ADDRESSTYPE             STRING(18,0)
    FROM TMP_SAFT_CODSAF C07
      LEFT JOIN NAGENDA  A ON A.CODAGENDA  = C07.CODSURSA
      LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NJUDET   J ON J.CODJUDET   = L.CODJUDET
      LEFT JOIN NTARI    T ON T.CODTARA    = L.CODTARA
    WHERE C07.CodSAFTTab = 07;
  END IF;

  UPDATE TMP_SAFT07 SET COL08 = NULL WHERE Coalesce(COL09, n&apos;~&apos;) &lt;&gt; &apos;RO&apos;;
  PUT_INFO(&apos;07.Z&apos;,&apos;UMPLE_T07--SAF_ADDRESS&apos;);
END;

PROCEDURE UMPLE_T08 IS --SAF_CONTACT
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;08.A&apos;,&apos;UMPLE_T08--SAF_CONTACT&apos;);
  SELECT TIP
  INTO   vTip
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT08
  SELECT
    08                          COL01,--CODSAF_CONTACT       NUMERIC(20,0)
    09                          COL02,--CODSAF_CONTACTPERSON NUMERIC(20,0)
    SubStr(A.TELEFON, 1, 18)    COL03,--TELEPHONE            STRING(18,0)
    SubStr(A.FAX,     1, 18)    COL04,--FAX                  STRING(18,0)
    SubStr(A.EMAIL,   1, 70)    COL05,--EMAIL                STRING(70,0)
    NULL                        COL06 --WEBSITE              STRING(100,0)
  FROM TMP_SAFT_PARAMS SP
    LEFT JOIN NPERS   P ON P.CODPERS   = SP.PERSCONTACT
    LEFT JOIN NAGENDA A ON A.CODAGENDA = P.AGENDA;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT08
    SELECT
      C08.CODSAF                  COL01,--CODSAF_CONTACT       NUMERIC(20,0)
      C09.CODSAF                  COL02,--CODSAF_CONTACTPERSON NUMERIC(20,0)
      SubStr(PC.TELEFON, 1, 18)   COL03,--TELEPHONE            STRING(18,0)
      NULL                        COL04,--FAX                  STRING(18,0)
      SubStr(PC.EMAIL, 1, 70)     COL05,--EMAIL                STRING(70,0)
      NULL                        COL06 --WEBSITE              STRING(100,0)
    FROM TMP_SAFT_CODSAF C08
      LEFT JOIN NPERSCONTACT    PC  ON PC.CodPart   = C08.CodSursa
      LEFT JOIN TMP_SAFT_CODSAF C09 ON C09.CODSURSA = PC.CODPERSC AND C09.CodSAFTTab = 09
    WHERE C08.CodSAFTTab = 08;
  END IF;
  PUT_INFO(&apos;08.Z&apos;,&apos;UMPLE_T08--SAF_CONTACT&apos;);
END;

PROCEDURE UMPLE_T09 IS --SAF_CONTACTPERSON
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;09.A&apos;,&apos;UMPLE_T09--SAF_CONTACTPERSON&apos;);
  SELECT TIP
  INTO   vTip
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT09
  SELECT
    09                                    COL01,--CODSAF_CONTACTPERSON NUMERIC(20,0)
    NULL                                  COL02,--TITLU                STRING(9,0)
    SubStr(P.PRENUME, 1, 35)              COL03,--FIRSTNAME            STRING(35,0)
    SubStr(P.NUME,    1, 1)||
    SubStr(P.PRENUME, 1, 1)               COL04,--INITIALS             STRING(18,0)
    NULL                                  COL05,--LASTNAMEPREFIX       STRING(18,0)
    SubStr(P.NUME, 1, 70)                 COL06,--LASTNAME             STRING(70,0)
    To_Char(P.DATAN, &apos;dd.mm.yyyy&apos;)        COL07,--BIRTHNAME            STRING(70,0)
    NULL                                  COL08,--SALUTATION           STRING(18,0)
    NULL                                  COL09 --OTHERTITLES          STRING(18,0)
  FROM TMP_SAFT_PARAMS SP LEFT JOIN NPERS P ON P.CODPERS = SP.PERSCONTACT;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT09
    SELECT
      C09.CODSAF                            COL01,--CODSAF_CONTACTPERSON NUMERIC(20,0)
      NULL                                  COL02,--TITLU                STRING(9,0)
      SubStr(PC.PRENUME, 1, 35)             COL03,--FIRSTNAME            STRING(35,0)
      SubStr(PC.NUME,    1, 1)||
      SubStr(PC.PRENUME, 1, 1)              COL04,--INITIALS             STRING(18,0)
      NULL                                  COL05,--LASTNAMEPREFIX       STRING(18,0)
      SubStr(PC.NUME, 1, 70)                COL06,--LASTNAME             STRING(70,0)
      To_Char(PC.DATANASTERE, &apos;dd.mm.yyyy&apos;) COL07,--BIRTHNAME            STRING(70,0)
      NULL                                  COL08,--SALUTATION           STRING(18,0)
      NULL                                  COL09 --OTHERTITLES          STRING(18,0)
    FROM TMP_SAFT_CODSAF C09 LEFT JOIN NPERSCONTACT PC ON PC.CODPERSC = C09.CodSursa
    WHERE C09.CodSAFTTab = 09;
  END IF;
  PUT_INFO(&apos;09.Z&apos;,&apos;UMPLE_T09--SAF_CONTACTPERSON&apos;);
END;

PROCEDURE UMPLE_T10 IS --SAF_TAXREGISTRATION
  vSubunit NUMBER(20);
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;10.A&apos;,&apos;UMPLE_T10--SAF_TAXREGISTRATION&apos;);
  SELECT TIP,  CODSUBUNIT
  INTO   vTip, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    INSERT INTO TMP_SAFT10
    SELECT
      10                                     COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      REGEXP_REPLACE(F.CODFISCAL,&apos;\D+&apos;,&apos;&apos;)   COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      NULL                                   COL03,--TAXTYPE                STRING(9,0)
      NULL                                   COL04,--TAXNUMBER              STRING(35,0)
      NULL                                   COL05,--TAXAUTHORITY           STRING(35,0)
      NULL                                   COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE
    INSERT INTO TMP_SAFT10
    SELECT
      10                                     COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      REGEXP_REPLACE(S.CIF,&apos;\D+&apos;,&apos;&apos;)         COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      NULL                                   COL03,--TAXTYPE                STRING(9,0)
      NULL                                   COL04,--TAXNUMBER              STRING(35,0)
      NULL                                   COL05,--TAXAUTHORITY           STRING(35,0)
      NULL                                   COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT10
    SELECT
      C10.CODSAF                             COL01,--CODSAF_TAXREGISTRATION NUMERIC(20,0)
      PD.PartID                              COL02,--TAXREGISTRATIONNUMBER  STRING(35,0)
      NULL                                   COL03,--TAXTYPE                STRING(9,0)
      NULL                                   COL04,--TAXNUMBER              STRING(35,0)
      NULL                                   COL05,--TAXAUTHORITY           STRING(35,0)
      NULL                                   COL06 --TAXVERIFICATIONDATE    DATE(10,0)
    FROM TMP_SAFT_CODSAF C10
      LEFT JOIN TMP_SAFT_NPARTDET PD ON PD.COD_CODFISCAL = C10.CodSursa
    WHERE C10.CodSAFTTab = 10;
  END IF;
  PUT_INFO(&apos;10.Z&apos;,&apos;UMPLE_T10--SAF_TAXREGISTRATION&apos;);
END;

PROCEDURE UMPLE_T11 IS --SAF_BANKACCOUNT
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;11.A&apos;,&apos;UMPLE_T11--SAF_BANKACCOUNT&apos;);
  SELECT TIP
  INTO   vTip
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT11
  SELECT
    11                             COL01,--CODSAF_BANKACCOUNT NUMERIC(20,0)
    CASE
      WHEN Coalesce(BC.CODBANKCONT, 0) = 0
      THEN NULL
      ELSE REPLACE(BC.NRCONT, &apos; &apos;, &apos;&apos;)
    END                            COL02,--IBANNUMBER         STRING(35,0)
    CASE
      WHEN Coalesce(BC.CODBANKCONT, 0) = 0
      THEN &apos;Fara cont bancar&apos;
      ELSE NULL
    END                            COL03,--BANKACCOUNTNUMBER  STRING(35,0)
    NULL                           COL04,--BANKACCOUNTNAME    STRING(70,0)
    NULL                           COL05 --SORTCODE           STRING(18,0)
  FROM TMP_SAFT_PARAMS SP
    LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = SP.CODBANKCONT
    LEFT JOIN NBANK     B  ON B.CODBANK      = BC.CODBANK;

  IF vTip &lt;&gt; 4 THEN
    INSERT INTO TMP_SAFT11
    SELECT DISTINCT
      C11.CODSAF                     COL01,--CODSAF_BANKACCOUNT NUMERIC(20,0)
      CASE
        WHEN C11.CodSursa = 0
        THEN NULL
        ELSE REPLACE(PB.CONTBANCA, &apos; &apos;, &apos;&apos;)
      END                            COL02,--IBANNUMBER         STRING(35,0)
      CASE
        WHEN C11.CodSursa = 0
        THEN &apos;Fara cont bancar&apos;
        ELSE NULL
      END                            COL03,--BANKACCOUNTNUMBER  STRING(35,0)
      NULL                           COL04,--BANKACCOUNTNAME    STRING(70,0)
      NULL                           COL05 --SORTCODE           STRING(18,0)
    FROM TMP_SAFT_CODSAF C11
      LEFT JOIN NPARTB PB ON PB.CODPARTB = C11.CodSursa
      LEFT JOIN NBANK  B  ON B.CODBANK   = PB.CODBANK
    WHERE C11.CodSAFTTab = 11;
  END IF;
  PUT_INFO(&apos;11.A&apos;,&apos;UMPLE_T11--SAF_BANKACCOUNT&apos;);
END;

PROCEDURE UMPLE_T12 IS --SAF_TAXTABLEENTRY
BEGIN
  PUT_INFO(&apos;12.A&apos;,&apos;UMPLE_T12--SAF_TAXTABLEENTRY&apos;);
  INSERT INTO TMP_SAFT12
  SELECT
    12                             COL01,--CODSAF_TAXTABLEENTRY  NUMBER(20)
    To_Char(TT.COD, &apos;fm999999000&apos;) COL02,--TAXTYPE               NVARCHAR2(9)
    SubStr(TT.Denumire, 1 , 256)   COL03,--DESCRIPTION           NVARCHAR2(256)
    1                              COL04 --DETSAF_TAXCODEDETAILS NUMBER(20)
  FROM WINMADMIN.TAXTYPESAFT TT
  WHERE TT.COD = 0;

  INSERT INTO TMP_SAFT12
  SELECT
    C12.CODSAF                     COL01,--CODSAF_TAXTABLEENTRY  NUMBER(20)
    To_Char(TT.COD, &apos;fm999999000&apos;) COL02,--TAXTYPE               NVARCHAR2(9)
    SubStr(TT.Denumire, 1 , 256)   COL03,--DESCRIPTION           NVARCHAR2(256)
    (
      SELECT Count(1)
      FROM TMP_SAFT_CODSAF C13
      WHERE C13.CodSAFTTab = 13
        AND C13.CodParinte = C12.CODSAF
    )                              COL04 --DETSAF_TAXCODEDETAILS NUMBER(20)
  FROM TMP_SAFT_CODSAF C12 LEFT JOIN WINMADMIN.TAXTYPESAFT TT ON TT.COD = C12.CodSursa
  WHERE C12.CodSAFTTab = 12;
  PUT_INFO(&apos;12.Z&apos;,&apos;UMPLE_T12--SAF_TAXTABLEENTRY&apos;);
END;

PROCEDURE UMPLE_T13 IS --SAF_TAXCODEDETAILS
BEGIN
  PUT_INFO(&apos;13.A&apos;,&apos;UMPLE_T13--SAF_TAXCODEDETAILS&apos;);
  INSERT INTO TMP_SAFT13
  SELECT
    13                             COL01,--CODSAF_TAXCODEDETAILS    NUMBER(20)
    12                             COL02,--CODSAF_MASTER            NUMBER(20)
    To_Char(TC.COD, &apos;fm999000000&apos;) COL03,--TAXCODE                  NVARCHAR2(9)
    NULL                           COL04,--EFFECTIVEDATE            DATE
    NULL                           COL05,--EXPIRATIONDATE           DATE
    SubStr(TC.Denumire, 1 , 256)   COL06,--DESCRIPTION              NVARCHAR2(256)
    Coalesce(TC.ProcTaxa, 0)       COL07,--TAXPERCENTAGE            NUMBER(22,7)
    NULL                           COL08,--CODFLATTAXRATESAF_AMOUNT NUMBER(20)
    1                              COL09,--BASERATE                 NUMBER(5,4)
    &apos;RO&apos;                           COL10,--COUNTRY                  NVARCHAR2(2)
    NULL                           COL11 --REGION                   NVARCHAR2(9)
  FROM WINMADMIN.TAXCODESAFT TC
  WHERE TC.COD = 0;

  INSERT INTO TMP_SAFT13
  SELECT
    C13.CODSAF                     COL01,--CODSAF_TAXCODEDETAILS    NUMBER(20)
    C13.CODPARINTE                 COL02,--CODSAF_MASTER            NUMBER(20)
    To_Char(TC.COD, &apos;fm999000000&apos;) COL03,--TAXCODE                  NVARCHAR2(9)
    NULL                           COL04,--EFFECTIVEDATE            DATE
    NULL                           COL05,--EXPIRATIONDATE           DATE
    SubStr(TC.Denumire, 1 , 256)   COL06,--DESCRIPTION              NVARCHAR2(256)
    Coalesce(TC.ProcTaxa, 0)       COL07,--TAXPERCENTAGE            NUMBER(22,7)
    NULL                           COL08,--CODFLATTAXRATESAF_AMOUNT NUMBER(20)
    1                              COL09,--BASERATE                 NUMBER(5,4)
    &apos;RO&apos;                           COL10,--COUNTRY                  NVARCHAR2(2)
    NULL                           COL11 --REGION                   NVARCHAR2(9)
  FROM TMP_SAFT_CODSAF C13 LEFT JOIN WINMADMIN.TAXCODESAFT TC ON TC.COD = C13.CodSursa
  WHERE C13.CodSAFTTab = 13;
  PUT_INFO(&apos;13.Z&apos;,&apos;UMPLE_T13--SAF_TAXCODEDETAILS&apos;);
END;

PROCEDURE UMPLE_T14 IS --SAF_UOMTABLEENTRY
BEGIN
  PUT_INFO(&apos;14.A&apos;,&apos;UMPLE_T14--SAF_UOMTABLEENTRY&apos;);
  INSERT INTO TMP_SAFT14
  SELECT
    C14.CODSAF                COL01,--CODSAF_UOMTABLEENTRY NUMBER(20)
    SUBSTR(UMS.CODSAFT, 1, 9) COL02,--UNITOFMEASURE        NVARCHAR2(9)
    UMS.DENUMIRE              COL03 --DESCRIPTION          NVARCHAR2(256)
  FROM TMP_SAFT_CODSAF C14 LEFT JOIN WINMADMIN.NUMSAFT UMS ON UMS.CODUMSAFT = C14.CodSursa
  WHERE C14.CodSAFTTab = 14;
  PUT_INFO(&apos;14.Z&apos;,&apos;UMPLE_T14--SAF_UOMTABLEENTRY&apos;);
END;

PROCEDURE UMPLE_T15 IS --SAF_ANALYSISTYPETABLEENTRY
  v_ALIni NUMBER(5);
  v_ALFin NUMBER(5);
BEGIN
  PUT_INFO(&apos;15.A&apos;,&apos;UMPLE_T15--SAF_ANALYSISTYPETABLEENTRY&apos;);
  SELECT ANINI*12+LUNAINI, ANFIN*12+LUNAFIN INTO v_ALIni, v_ALFin  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT15
  SELECT
    SEQ_SAFT.NEXTVAL               COL01,--CODSAF_ANALYSISTYPETABLEENTRY NUMBER(20)
    To_Char(TIPDOC, &apos;fm999999990&apos;) COL02,--ANALYSISTYPE                  NVARCHAR2(9)
    &apos;JURNALE&apos;                      COL03,--ANALYSISTYPEDESCRIPTION       NVARCHAR2(256)
    CASE
      WHEN J.TIPDOC =  1        THEN &apos;Facturi furnizori&apos;
      WHEN J.TIPDOC =  3        THEN &apos;Chitanta / bon fiscal furnizori&apos;
      WHEN J.TIPDOC =  4        THEN &apos;Bonuri de achizitie persoane fizice&apos;
      WHEN J.TIPDOC =  5        THEN &apos;Facturi import furnizori&apos;
      WHEN J.TIPDOC =  9        THEN &apos;Facturi la avize furnizori&apos;
      WHEN J.TIPDOC = 16        THEN &apos;Monetare&apos;
      WHEN J.TIPDOC = 19        THEN &apos;Facturi clienti&apos;
      WHEN J.TIPDOC = 21        THEN &apos;Chitanta/bon clienti&apos;
      WHEN J.TIPDOC = 26        THEN &apos;Facturi la avize clienti&apos;
      WHEN J.TIPDOC = 28        THEN &apos;Compensari&apos;
      WHEN J.TIPDOC = 29        THEN &apos;Tranzactii casa&apos;
      WHEN J.TIPDOC = 30        THEN &apos;Tranzactii curente banca&apos;
      WHEN J.TIPDOC = 31        THEN &apos;Tranzactii IN curs banca&apos;
      WHEN J.TIPDOC = 33        THEN &apos;Justificare Avans/Decontare&apos;
      WHEN M.CODMACHETA IS NULL THEN &apos;...nedefinit...&apos;
      ELSE M.NUMEPRESC
    END                            COL04,--ANALYSISID                    NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC =  1        THEN &apos;Intrari - facturi furnizori&apos;
      WHEN J.TIPDOC =  3        THEN &apos;Intrari - chitanta / bon fiscal&apos;
      WHEN J.TIPDOC =  4        THEN &apos;Intrari - bonuri de achizitie persoane fizice&apos;
      WHEN J.TIPDOC =  5        THEN &apos;Intrari - facturi import furnizori&apos;
      WHEN J.TIPDOC =  9        THEN &apos;Intrari - facturi la aviz furnizori&apos;
      WHEN J.TIPDOC = 16        THEN &apos;Monetare&apos;
      WHEN J.TIPDOC = 19        THEN &apos;Iesiri - facturi clienti&apos;
      WHEN J.TIPDOC = 21        THEN &apos;Iesiri - chitanta/bon&apos;
      WHEN J.TIPDOC = 26        THEN &apos;Iesiri - facturi la avize clienti&apos;
      WHEN J.TIPDOC = 28        THEN &apos;Compensari&apos;
      WHEN J.TIPDOC = 29        THEN &apos;Trezorerie - tranzactii casa&apos;
      WHEN J.TIPDOC = 30        THEN &apos;Trezorerie - tranzactii curente banca&apos;
      WHEN J.TIPDOC = 31        THEN &apos;Trezorerie - tranzactii IN curs banca&apos;
      WHEN J.TIPDOC = 33        THEN &apos;Trezorerie - justificare avans/decontare&apos;
      WHEN M.CODMACHETA IS NULL THEN &apos;...nedefinit...&apos;
      ELSE M.NUMEEXT
    END                            COL05 --ANALYSISIDDESCRIPTION         NVARCHAR2(256)
  FROM (SELECT DISTINCT TIPDOC FROM TMP_SAFT_JURNAL) J LEFT JOIN TMP_MACHETE M ON M.CODMACHETA = J.TIPDOC;

  PUT_INFO(&apos;15.A&apos;,&apos;UMPLE_T15--SAF_ANALYSISTYPETABLEENTRY&apos;);
END;

PROCEDURE UMPLE_T16 IS --SAF_MOVEMENTTYPETABLEENTRY
BEGIN
  PUT_INFO(&apos;16.A&apos;,&apos;UMPLE_T16--SAF_MOVEMENTTYPETABLEENTRY&apos;);
  INSERT INTO TMP_SAFT16
  SELECT
    SEQ_SAFT.NEXTVAL    COL01,--CODSAF_MOVEMENTTYPETABLEENTRY NUMBER(20)
    MOVEMENTTYPE        COL02,--MOVEMENTTYPE                  NVARCHAR2(9)
    CASE MOVEMENTTYPE
      WHEN  &apos;10&apos; THEN &apos;Achizitie&apos;
      WHEN  &apos;20&apos; THEN &apos;Productie&apos;
      WHEN  &apos;30&apos; THEN &apos;V?nzare&apos;
      WHEN  &apos;40&apos; THEN &apos;Retur produse v?ndute&apos;
      WHEN  &apos;50&apos; THEN &apos;Retur produse achizitionate&apos;
      WHEN  &apos;60&apos; THEN &apos;Reduceri comerciale primite&apos;
      WHEN  &apos;70&apos; THEN &apos;Consum&apos;
      WHEN  &apos;80&apos; THEN &apos;Transfer intern&apos;
      WHEN  &apos;90&apos; THEN &apos;Cheltuieli ulterioare incluse ?n valoarea de intrare&apos;
      WHEN &apos;100&apos; THEN &apos;Diferente de pret&apos;
      WHEN &apos;110&apos; THEN &apos;Plus de inventar&apos;
      WHEN &apos;120&apos; THEN &apos;Minus de inventar&apos;
      WHEN &apos;130&apos; THEN &apos;Ajustari pentru deprecierea stocurilor&apos;
      WHEN &apos;140&apos; THEN &apos;Reluari de ajustari pentru deprecierea stocurilor&apos;
      WHEN &apos;150&apos; THEN &apos;Bunuri acordate cu titlu gratuit&apos;
      WHEN &apos;160&apos; THEN &apos;Bunuri degradate&apos;
      WHEN &apos;170&apos; THEN &apos;Bunuri expirate&apos;
      WHEN &apos;180&apos; THEN &apos;Alte tranzactii&apos;
    END                 COL03 --DESCRIPTION                   NVARCHAR2(256)
  FROM (SELECT DISTINCT MOVEMENTTYPE FROM TMP_SAFT_STOCKMOVEMENT) subs;
END;

PROCEDURE UMPLE_T17 IS --SAF_PRODUCT
  vAL NUMBER;
BEGIN
  PUT_INFO(&apos;17.A&apos;,&apos;UMPLE_T17--SAF_PRODUCT&apos;);
  SELECT ANFIN*12+LUNAFIN INTO vAL FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT17
  SELECT
    C17.CODSAF                   COL01,--CODSAF_PRODUCT               NUMBER(20)
    To_Char(O.CodObiect)         COL02,--PRODUCTCODE                  NVARCHAR2(70)
    NULL                         COL03,--GOODSSERVICESID              NVARCHAR2(9)
    NULL                         COL04,--PRODUCTGROUP                 NVARCHAR2(70)
    O.Denumire                   COL05,--DESCRIPTION                  NVARCHAR2(256)
    CASE
      WHEN A.TIPARTICOL = 1
      THEN Coalesce(CN8.CN, &apos;99999999&apos;)
      ELSE Coalesce(CN8.CN, &apos;0&apos;)
    END                          COL06,--PRODUCTCOMMODITYCODE         NVARCHAR2(35)
    NULL                         COL07,--PRODUCTNUMBERCODE            NVARCHAR2(70)
    NULL                         COL08,--VALUATIONMETHOD              NVARCHAR2(9)
    SUBSTR(UMS.CODSAFT, 1, 9)    COL09,--UOMBASE                      NVARCHAR2(9)
    SUBSTR(UMS.CODSAFT, 1, 9)    COL10,--UOMSTANDARD                  NVARCHAR2(9)
    U.PARITATEUMSAFT             COL11,--UOMTOUOMBASECONVERSIONFACTOR NUMBER(22,7)
    C18.CODSAF                   COL12 --CODSAF_TAX                   NUMBER(20)
  FROM TMP_SAFT_CODSAF C17
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = C17.CodSursa
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN NArt1                  AL  ON AL.CODARTICOL = O.CODARTICOL     AND vAL BETWEEN AL.ALStart AND AL.ALStop
    LEFT JOIN NTva1                  TL  ON TL.CodTVA     = AL.CodTVA        AND vAL BETWEEN TL.ALStart AND TL.ALStop
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
    LEFT JOIN TMP_SAFT_CODSAF        C18 ON C18.CODSURSA  = TL.CodTVA        AND C18.CodSAFTTab = 18
  WHERE C17.CodSAFTTab = 17;
  PUT_INFO(&apos;17.Z&apos;,&apos;UMPLE_T17--SAF_PRODUCT&apos;);
END;

PROCEDURE UMPLE_T18 IS --SAF_TAX
BEGIN
  PUT_INFO(&apos;18.A&apos;,&apos;UMPLE_T18--SAF_TAX&apos;);
  INSERT INTO TMP_SAFT18
  SELECT
    SEQ_SAFT.NEXTVAL                     COL01,--CODSAF_TAX NUMBER(20)
    To_Char(C12.CODSURSA, &apos;fm999999990&apos;) COL02,--TAXTYPE    NVARCHAR2(9)
    To_Char(C13.CODSURSA, &apos;fm999999990&apos;) COL03 --TAXCODE    NVARCHAR2(9)
  FROM TMP_SAFT_CODSAF C13 LEFT JOIN TMP_SAFT_CODSAF C12 ON C12.CODSAF = C13.CODPARINTE
  WHERE C13.CodSAFTTab = 13;
  PUT_INFO(&apos;18.Z&apos;,&apos;UMPLE_T18--SAF_TAX&apos;);
END;

PROCEDURE UMPLE_T19 IS --SAF_PHYSICALSTOCKENTRY
  vTipAvizCustodie NUMBER(20);
  sFirmaID         VARCHAR2(35);
  vSubunit         NUMBER(20);
  vALFin           NUMBER(5);
BEGIN
  PUT_INFO(&apos;19.A&apos;,&apos;UMPLE_T19--SAF_PHYSICALSTOCKENTRY&apos;);
  BEGIN
    SELECT PKG_CATEGCONST.GetValConstanta(&apos;TipAvizCustodie&apos;, ANFIN,LUNAFIN) INTO vTipAvizCustodie FROM TMP_SAFT_PARAMS;
  EXCEPTION WHEN OTHERS THEN
    vTipAvizCustodie := -1;
  END;

  SELECT CODSUBUNIT INTO vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT &apos;00&apos;||REGEXP_REPLACE(F.CODFISCAL,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT &apos;00&apos;||REGEXP_REPLACE(S.CIF,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT19
  SELECT
    SEQ_SAFT.NEXTVAL         COL01,--CODSAF_PHYSICALSTOCKENTRY    NUMBER(20)
    T.COL02                  COL02,--WAREHOUSEID                  NVARCHAR2(35)
    NULL                     COL03,--LOCATIONID                   NVARCHAR2(18)
    To_Char(T.CODOBIECT)     COL04,--PRODUCTCODE                  NVARCHAR2(70)
    NULL                     COL05,--STOCKACCOUNTNO               NVARCHAR2(70)
    T.COL06                  COL06,--PRODUCTTYPE                  NVARCHAR2(18)
    NULL                     COL07,--PRODUCTSTATUS                NVARCHAR2(18)
    T.COL08                  COL08,--STOCKACCOUNTCOMMODITYCODE    NVARCHAR2(35)
    T.COL09                  COL09,--OWNERID                      NVARCHAR2(35)
    T.COL10                  COL10,--UOMPHYSICALSTOCK             NVARCHAR2(9)
    T.COL11                  COL11,--UOMTOUOMBASECONVERSIONFACTOR NUMBER(22,7)
    T.COL12                  COL12,--UNITPRICE                    NUMBER(18,2)
    T.COL13                  COL13,--OPENINGSTOCKQUANTITY         NUMBER(22,6)
    T.COL14                  COL14,--OPENINGSTOCKVALUE            NUMBER(18,2)
    T.COL15                  COL15,--CLOSINGSTOCKQUANTITY         NUMBER(22,6)
    T.COL16                  COL16,--CLOSINGSTOCKVALUE            NUMBER(18,2)
    Coalesce(C20.CODSAF, 20) COL17 --CODSAF_STOCKCHARACTERISTICS  NUMBER(20)
  FROM (
    SELECT
      COL02, CODOBIECT, COL06, COL08, COL09, COL10, COL11, COL12,
      Sum(Coalesce(COL13, 0)) AS COL13, Sum(Coalesce(COL14, 0)) AS COL14, Sum(COL15) AS COL15, Sum(COL16) AS COL16
    FROM (
      SELECT
        SubStr(Coalesce(G.SIMBOL, G.DEN_GEST), 1, 35) AS COL02,
        NS.CODOBIECT,
        Substr(C.SIMBOL,1,18) AS COL06, --To_Char(NS.CODIOART) AS COL06,
        Coalesce(NULLIF(SubStr(Trim(O.CODVAMAL),1,18), &apos;&apos;), &apos;0&apos;) AS COL08,
        Coalesce(NULLIF(Trim(F.PartID), &apos;&apos;), sFirmaID) AS COL09,
        SubStr(UMS.CODSAFT, 1, 9) AS COL10, Coalesce(UM.PARITATEUMSAFT, 1) AS COL11,
        Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0) AS COL12,
        NLP.REST AS COL13, NLP.REST * (Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0)) AS COL14,
        NLF.REST AS COL15, NLF.REST * (Coalesce(NS.PRET, 0) - Coalesce(NS.ADAOS, 0)) AS COL16
      FROM TMP_SAFT_PARAMS SP
        INNER JOIN NIRLUNA           NLF  ON NLF.AN = SP.ANFIN AND NLF.LUNA = SP.LUNAFIN
        LEFT  JOIN NIRLUNA           NLP  ON NLP.AN = SP.ANP   AND NLP.LUNA = SP.LUNAP AND NLP.CODNIRSTOC = NLF.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS   ON NS.CODNIRSTOC = NLF.CODNIRSTOC
        LEFT  JOIN NIR               N    ON N.CODNIR      = NS.CODNIR
        LEFT  JOIN NGEST             G    ON G.CODGEST     = N.GEST
        LEFT  JOIN TMP_SAFT_NPARTFUZ FF   ON FF.CODPART    = CASE WHEN NS.CODIOART = vTipAvizCustodie THEN NS.FURN ELSE NULL END
        LEFT  JOIN TMP_SAFT_NPARTDET F    ON F.CODPART     = FF.CODPARTFUZ
        LEFT  JOIN NUM1              UM1  ON UM1.CODUM1    = NS.UMSEC
        LEFT  JOIN NUM               UM   ON UM.CODUM      = UM1.CODUM
        LEFT  JOIN NARTOBJ           O    ON O.CODOBIECT   = NS.CODOBIECT
        LEFT  JOIN IOART1            IOA1 ON IOA1.CODIOART = NS.CODIOART AND SP.ANFIN*12+SP.LUNAFIN BETWEEN IOA1.ALSTART AND IOA1.ALSTOP
        LEFT  JOIN NCONT             C    ON C.CODCONT     = IOA1.CONT
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CObInventar&apos;, &apos;CMifix&apos;) AND AL = vALFin
        )                            MAN  ON MAN.CODUNIC   = IOA1.CONT
        LEFT  JOIN WINMADMIN.NUMSAFT UMS  ON UMS.CODUMSAFT = UM.CODUMSAFT
      WHERE MAN.CODUNIC IS NULL
        --AND Coalesce(NLF.REST, 0) &lt;&gt; 0
        AND CASE
              WHEN Coalesce(NLF.REST, 0) &lt;&gt; 0 THEN 1
              WHEN Coalesce(NLP.REST, 0) &lt;&gt; 0 THEN 1
              WHEN NLP.CODNIRSTOC IS NULL     THEN 1 -- pozitie creata IN perioada
              WHEN
                EXISTS (
                  SELECT 1
                  FROM LIVR1 L1
                    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
                    LEFT  JOIN IESIRI  IES   ON IES.CODIES      = L.CODIES
                    LEFT  JOIN INTRARI INTR  ON INTR.CODINTR    = L.CODINTR
                    LEFT  JOIN TRANSF  TRANF ON TRANF.CODTRANSF = L.CODTRANSF
                  WHERE L1.CODNIRSTOC = NLF.CODNIRSTOC
                    AND Coalesce(IES.AN*12+IES.LUNA, INTR.AN*12+INTR.LUNA, TRANF.AN*12+TRANF.LUNA, 0) BETWEEN SP.ANINI*12+SP.LUNAINI AND SP.ANFIN*12+SP.LUNAFIN
                )                             THEN 1
              ELSE 0
            END = 1
      UNION ALL
      SELECT
        WAREHOUSEID AS COL02,
        CODOBIECT,
        PRODUCTTYPE AS COL06,
        Coalesce(NULLIF(Trim(STOCKACCOUNTCOMMODITYCODE), &apos;&apos;), &apos;0&apos;) AS COL08,
        Coalesce(NULLIF(Trim(OWNERID), &apos;&apos;), sFirmaID) AS COL09,
        UOMPHYSICALSTOCK AS COL10, CAST(UOMTOUOMBASECONVERSIONFACTOR AS NUMBER(20,7)) AS COL11,
        UNITPRICE AS COL12,
        OPENINGSTOCKQUANTITY AS COL13, OPENINGSTOCKVALUE AS COL14,
        CLOSINGSTOCKQUANTITY AS COL15, CLOSINGSTOCKVALUE AS COL16
      FROM TMP_SAFT_PARAMS SP INNER JOIN STOCFAKE SF ON SF.AN = SP.ANFIN AND SF.LUNA = SP.LUNAFIN
    )
    GROUP BY COL02, CODOBIECT, COL06, COL08, COL09, COL10, COL11, COL12
  ) T LEFT JOIN TMP_SAFT_CODSAF C20 ON C20.CODSURSA = T.CODOBIECT AND CODSAFTTAB = 20;
  PUT_INFO(&apos;19.Z&apos;,&apos;UMPLE_T19--SAF_PHYSICALSTOCKENTRY&apos;);
END;

PROCEDURE UMPLE_T20 IS --SAF_STOCKCHARACTERISTICS
BEGIN
  PUT_INFO(&apos;20.A&apos;,&apos;UMPLE_T20--SAF_STOCKCHARACTERISTICS&apos;);
  INSERT INTO TMP_SAFT20
  SELECT
    20                                COL01,--CODSAF_STOCKCHARACTERISTICS NUMBER(20)
    &apos;0&apos;                               COL02,--STOCKCHARACTERISTIC         NVARCHAR2(18)
    NULL                              COL03 --STOCKCHARACTERISTICVALUE    NVARCHAR2(35)
  FROM dual;

  INSERT INTO TMP_SAFT20
  SELECT
    C20.CODSAF                        COL01,--CODSAF_STOCKCHARACTERISTICS NUMBER(20)
    Coalesce(O.COL02, SF.COL02, &apos;0&apos;)  COL02,--STOCKCHARACTERISTIC         NVARCHAR2(18)
    Coalesce(O.COL03, SF.COL03)       COL03 --STOCKCHARACTERISTICVALUE    NVARCHAR2(35)
  FROM TMP_SAFT_CODSAF C20
    LEFT JOIN (
      SELECT
        O.CODOBIECT,
        CASE A.TIPSTOC
          WHEN 1 THEN &apos;Blue35&apos;
          WHEN 2 THEN &apos;Yellow124&apos;
          ELSE &apos;0&apos;
        END AS COL02,
        Substr(
          CASE WHEN Coalesce(O.MASA,  0) &lt;&gt; 0 THEN To_Char(O.MASA) ||&apos;KG&apos; ELSE &apos;&apos; END||
          CASE WHEN Coalesce(O.VOLUM, 0) &lt;&gt; 0 THEN To_Char(O.VOLUM)||&apos;L&apos;  ELSE &apos;&apos; END,
          1, 35
        ) AS COL03
      FROM NARTOBJ O INNER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
      WHERE A.TIPSTOC IN (1, 2)
    ) O ON O.CODOBIECT = C20.CODSURSA
    LEFT JOIN (
      SELECT
        SF.CODOBIECT,
        Max(STOCKCHARACTERISTICS)     AS COL02,
        Max(STOCKCHARACTERISTICVALUE) AS COL03
      FROM TMP_SAFT_PARAMS SP
        INNER JOIN STOCFAKE SF ON SF.AN = SP.ANFIN AND SF.LUNA = SP.LUNAFIN
        LEFT  JOIN NARTOBJ  O  ON O.CODOBIECT  = SF.CODOBIECT
        LEFT  JOIN NART     A  ON A.CODARTICOL = O.CODARTICOL
      WHERE A.CODARTICOL IS NOT NULL
        AND Coalesce(SF.STOCKCHARACTERISTICS, &apos;0&apos;) &lt;&gt; &apos;0&apos;
      GROUP BY SF.CODOBIECT
    ) SF ON SF.CODOBIECT = C20.CODSURSA;
  PUT_INFO(&apos;20.Z&apos;,&apos;UMPLE_T20--SAF_STOCKCHARACTERISTICS&apos;);
END;

PROCEDURE UMPLE_T22 IS --SAF_ASSET
BEGIN
  INSERT INTO TMP_SAFT22
  SELECT
    C22.CODSAF                          COL01,--CODSAF_ASSET         NUMBER(20)
    M.NRINVENTAR                        COL02,--ASSETID              NVARCHAR2(35)
    C.CODSAFT                           COL03,--ACCOUNTID            NVARCHAR2(70)
    O.DENUMIRE                          COL04,--DESCRIPTION          NVARCHAR2(256)
    C23.CODSAF                          COL05,--CODSAF_ASSETSUPPLIER NUMBER(20)
    NULL                                COL06,--PURCHASEORDERDATE    DATE
    COALESCE(NS.DATAACHIZ, N.DATANIR)   COL07,--DATEOFAQUISITION     DATE
    CASE
      WHEN M.ANINTRARE IS NULL
      THEN To_Date(To_Char(M1.ANSTART,  &apos;0000&apos;)||To_Char(M1.LUNASTART,  &apos;00&apos;)||&apos;01&apos;,&apos;YYYYMMDD&apos;)
      ELSE To_Date(To_Char(M.ANINTRARE, &apos;0000&apos;)||To_Char(M.LUNAINTRARE, &apos;00&apos;)||&apos;01&apos;,&apos;YYYYMMDD&apos;)
    END                                 COL08,--STARTUPDATE          DATE
    C59.CODSAF                          COL09 --CODSAF_VALUATIONS    NUMBER(20)
  FROM TMP_SAFT_CODSAF C22
    LEFT JOIN TMP_SAFT_CODSAF C59 ON C59.CODPARINTE = C22.CODSAF           AND C59.CodSAFTTab = 59
    LEFT JOIN MIFIX           M   ON M.CODMIFIX     = C22.CODSURSA
    LEFT JOIN MIFIX1          M1  ON M1.CODMIFIX1   = C22.CODAUX
    LEFT JOIN NIRSTOC         NS  ON NS.CODNIRSTOC  = M1.CODNIRSTOC
    LEFT JOIN NIR             N   ON N.CODNIR       = NS.CODNIR
    LEFT JOIN TMP_SAFT_CODSAF C23 ON C23.CODSURSA   = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
    LEFT JOIN NARTOBJ         O   ON O.CODOBIECT    = NS.CODOBIECT
    LEFT JOIN IOART1          I1  ON I1.CODIOART    = NS.CODIOART          AND M1.ANSTART*12+M1.LUNASTART BETWEEN I1.ALSTART AND I1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT  C   ON C.CODCONT      = I1.CONT
  WHERE C22.CodSAFTTab = 22
  ORDER BY C59.CODSAF ASC;
END;

PROCEDURE UMPLE_T23 IS --SAF_ASSETSUPPLIER
BEGIN
  INSERT INTO TMP_SAFT23
  SELECT
    C23.CODSAF                  COL01,--CODSAF_ASSETSUPPLIER        NUMBER(20)
    SubStr(P.Den_Part, 1, 70)   COL02,--SUPPLIERNAME                NVARCHAR2(70)
    PD.PartID                   COL03,--SUPPLIERID                  NVARCHAR2(35)
    C07.CODSAF                  COL04 --CODPOSTALADDRESSSAF_ADDRESS NUMBER(20)
  FROM TMP_SAFT_CODSAF C23
    LEFT JOIN TMP_SAFT_NPARTDET PD  ON PD.CODPART   = C23.CODSURSA
    LEFT JOIN NPART             P   ON P.CODPART    = C23.CODSURSA
    LEFT JOIN NAGENDA           A   ON A.CODPART    = C23.CODSURSA     AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
    LEFT JOIN TMP_SAFT_CODSAF   C07 ON C07.CODSURSA = A.CODAGENDA      AND C07.CodSAFTTab = 07
  WHERE C23.CodSAFTTab = 23;
END;

PROCEDURE UMPLE_T59 IS --SAF_VALUATIONS
BEGIN
  INSERT INTO TMP_SAFT59
  SELECT
    C24.CODPARINTE COL01,--CODSAF_VALUATIONS NUMBER(20)
    1              COL02 --DETSAF_VALUATION  NUMBER(20)
  FROM TMP_SAFT_CODSAF C24
  WHERE C24.CodSAFTTab = 24
  GROUP BY C24.CODPARINTE;
END;

PROCEDURE UMPLE_T24 IS --SAF_VALUATION
  SP_ALFIN           NUMBER;
  SP_ALINI           NUMBER;
  cHolding           NUMBER;
BEGIN
  PUT_INFO(&apos;24.A&apos;,&apos;UMPLE_T24--SAF_VALUATION&apos;);
  SELECT ANFIN*12+LUNAFIN, Coalesce(pkg_categconst.GetValConstanta(&apos;HOLDING&apos;, ANFIN, LUNAFIN),&apos;-1&apos;), ANINI*12+LUNAINI
  INTO SP_ALFIN          , cHolding                                                                , SP_ALINI
  FROM TMP_SAFT_PARAMS;

  INSERT INTO TMP_SAFT24
  SELECT
    Max(COL01) COL01,
    Max(COL02),
    COL03,
    Max(COL04) COL04,
    CASE
      WHEN Max(J1I_TIPDOC) = 35 THEN Max(COL05)
      WHEN Max(IDX_GRUP) &gt;1     THEN Max(COL05)
      ELSE                           Sum(COL05)
    END COL05,
    CASE
      WHEN Max(J1I_TIPDOC) = 35 THEN Max(COL06)
      WHEN Max(IDX_GRUP) &gt;1     THEN Max(COL06)
      ELSE                           Sum(COL06)
    END COL06,
    Sum(COL07), Max(COL08), Max(COL09),
    Sum(COL10),
    CASE
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7
        AND Max(CONT_TRANSF) &lt;&gt; Max(TNB_CODUNIC)               THEN Sum(COL11)
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7
        AND Max(J1I_TIPDOC) = 23                               THEN Sum(COL11)
      WHEN Max(IDX_GRUP) &gt;1       AND Max(M1_F_STARE) = 7      THEN Max(COL11)
      ELSE                                                          Sum(COL11)
    END COL11,
    Sum(COL12), Max(COL13), Max(COL14), Max(COL15),
    CASE
      WHEN Max(M1_I_AMO) &gt; Max(M1_F_AMO)
        AND Max(J1I_TIPDOC) = 35     THEN Max(COL16) - Max(AMORTIZ_EXTRAORD)
      WHEN Max(J1I_TIPDOC) = 35      THEN Max(COL16)
      WHEN Max(M1_F_STARE) IN (8,9)  THEN Sum(COL16)
      WHEN Max(IDX_GRUP) &gt;1          THEN Max(COL16)
      ELSE                                Sum(COL16)
    END COL16,
    Sum(COL17), Max(COL18), Max(COL19),
    --BOOKVALUEEND = BOOKVALUEBEGIN (DOAR PRIMA LINIE) + ASSETADDITION + TRANSFERS + ASSETDISPOSAL + DEPRECIATIONFORPERIOD + APPRECIATIONFORPERIOD
    CASE
      WHEN Max(M1_F_STARE) IN (3, 4, 7, 8, 9, 10) OR Max(J1I_TIPDOC) = 23      THEN 0
      WHEN Max(J1I_TIPDOC) = 12   AND Max(J1I_VALOARE) &lt; 0                     THEN 0
      ELSE (
        CASE
          WHEN Max(J1I_TIPDOC) = 6
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Sum(COL17) - Max(NS_F_PROVIZION) + Max(COL19)
          WHEN Max(J1I_TIPDOC) = 35 AND Max(M1_I_AMO) &lt; Max(M1_F_AMO)
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION) + Min(AMORTIZ_EXTRAORD)
          WHEN Max(J1I_TIPDOC) = 35
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION)
          WHEN Max(IDX_GRUP)&gt;1
          THEN Max(COL13)+ Sum(COL10) + Sum(COL11) + Sum(COL12) + Max(COL16) + Sum(COL17) - Max(NS_F_PROVIZION)
          ELSE (
            CASE WHEN Min(IDX_GRUP) = 1 THEN Max(COL13) ELSE 0 END +
            CASE
              WHEN Max(IDX_GRUP) = 1 AND Max(M1_A_CODMIFIX1) IS NULL AND Max(M1_I_AMO) &gt; 0
                AND Max(M_I_ANINTRARE)*12 + Max(M_I_LUNAINTRARE) &lt; SP_ALINI                   THEN 0
              WHEN Max(IDX_GRUP) = 1 AND Max(M1_A_CODMIFIX1) IS NULL AND Max(M1_I_AMO) &gt; 0    THEN Max(COL19) - Max(COL16)
              ELSE                                                                                 0
              END +
        Sum(COL10) + Sum(COL11) + Sum(COL12) + Sum(COL16) + Sum(COL17) - Max(NS_F_PROVIZION))
        END)
    END COL20 --BOOKVALUEEND                               NUMBER(18,2)
  FROM (
    SELECT
      COL01, COL02, COL03, COL04, COL05, COL06, COL07, COL08, COL09, COL10,
      CASE
        WHEN J1I_TIPDOC = 1                                                                THEN 0
        WHEN J1I_TIPDOC = 6                   AND cHolding = 2                             THEN M1_I_pret
        WHEN J1I_TIPDOC = 15                  AND J1I_TIPTRANZACTIE = 5                    THEN M1_I_pret
        WHEN J1I_TIPDOC = 12                  AND J1I_ASSETTRANSACTIONTYPE = (&apos;100&apos;)       THEN 0
       -- WHEN J1I_TIPDOC = 12                  AND M1_F_ALSTART = SP_ALFIN                  THEN M1_I_pret - M1_I_amo
        WHEN J1I_TIPDOC = 12                  AND M1_F_STARE = 7
          AND  CONT_TRANSF &lt;&gt; Coalesce(TNB_CODUNIC,0)                                      THEN - M1_F_PRET
        WHEN J1I_TIPDOC = 12                  AND M1_F_STARE = 7                           THEN M1_F_amo  - M1_F_PRET
        WHEN J1I_TIPDOC = 12                  AND J1I_VALOARE &lt; 0                          THEN - M1_F_PRET
        WHEN J1I_TIPDOC = 7                                                                THEN M1_I_PRET
        WHEN J1I_TIPDOC = 35                                                               THEN 0
        WHEN J1I_TIPDOC = 23                                                               THEN - M1_F_PRET
        WHEN M1_F_STARE = 4                   AND J1I_ASSETTRANSACTIONTYPE =(&apos;40&apos;)         THEN - Coalesce(M1_F_PRET, 0)
        WHEN J1I_TIPDOC = 13                  AND J1I_TIPTRANZACTIE = 0
         AND J1I_ASSETTRANSACTIONTYPE IN (&apos;40&apos;)                                            THEN J1I_VALOARE
        WHEN J1IS_ASSETTRANSACTIONTYPE IN (&apos;20&apos;) AND J1IS_VALOARE &lt; 0                      THEN 0
        WHEN J1I_TIPDOC = 13                  AND TM_CODUNIC IS NOT NULL
         AND J1I_ASSETTRANSACTIONTYPE IN (&apos;40&apos;)                                            THEN M1_I_PRET
        WHEN J1I_TIPDOC = 13                  AND J1I_ICONTC = 3
         AND J1I_ASSETTRANSACTIONTYPE IN (&apos;40&apos;)                                            THEN M1_I_PRET
        WHEN NS_A_CODIOART =  NS_I_CODIOART   AND IDX_GRUP =1
         AND MAX(IDX_GRUP) OVER (PARTITION BY COL02) &gt; 1                                   THEN M1_U_amo  - M1_U_PRET
        WHEN M1_U_CODMIFIX IS NULL            AND M1_F_STARE IN (3,4)                      THEN 0
        WHEN M1_U_CODMIFIX IS NULL            AND NOT M1_F_STARE IN (8, 9)                 THEN M1_F_amo  - M1_F_PRET
        ELSE                                                                                    0
      END                                      COL11,---TRANSFERS                                  NUMBER(18,2)
      COL12, COL13, COL14, COL15, COL16, COL17, COL18, COL19,
      IDX_GRUP, M1_F_STARE, NS_F_PROVIZION, M1_A_CODMIFIX1, M1_I_AMO,J1I_TIPDOC, M_I_ANINTRARE, M_I_LUNAINTRARE,
      AMORTIZ_EXTRAORD, M1_F_AMO, CONT_TRANSF, TNB_CODUNIC, J1I_VALOARE, CODMIFIX_GRUP
    FROM (
      SELECT
        C24.CODSAF                             COL01,--CODSAF_VALUATION                           NUMBER(20)
        C24.CODPARINTE                         COL02,--CODSAF_MASTER                              NUMBER(20)
        &apos;CONTABIL&apos;                             COL03,--ASSETVALUATIONTYPE                         NVARCHAR2(18)
        SubStr(Trim(MFCL.SIMBOL),1,18)         COL04,--VALUATIONCLASS                             NVARCHAR2(18)
        CASE
          WHEN J1IS.ASSETTRANSACTIONTYPE =(&apos;20&apos;)    AND J1IS.VALOARE &lt; 0              THEN 0
          WHEN J1I.TIPDOC = 6                                                         THEN 0
          WHEN M_I.ANINTRARE*12+M_I.LUNAINTRARE &lt; SP_ALINI                            THEN Coalesce(M1_I.PRET, 0)
          WHEN M1_A.CODMIFIX IS NULL                AND Coalesce(J1I.TIPDOC, 0) = 12  THEN 0
          WHEN Coalesce(J1I.TIPDOC, 0) = 12                                           THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.ASSETTRANSACTIONTYPE =(&apos;40&apos;)     AND M1_I.STARE = 4                THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.ASSETTRANSACTIONTYPE =(&apos;10&apos;)     AND M1_I.STARE IN (8,9)
            AND  M1_I.AMO &gt; 0                                                         THEN Coalesce(M1_I.PRET, 0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND J1I.TIPDOC = 35                                                       THEN Coalesce(M1_I.PRET, 0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND J1I.ASSETTRANSACTIONTYPE &lt;&gt;(&apos;10&apos;)                                     THEN Coalesce(M1_I.PRET, 0)
          WHEN J1I.CODJURNAL1 IS NOT NULL                                             THEN 0
          ELSE                                                                             Coalesce(M1_I.PRET, 0)
        END                                    COL05,--ACQUISITIONANDPRODUCTIONCOSTSBEGIN         NUMBER(18,2)
        CASE
          WHEN M1_F.STARE IN (3, 4, 7, 8, 9,10)     THEN 0
          WHEN J1I.TIPDOC = 23                      THEN 0
          WHEN J1I.TIPDOC = 12 AND J1I.VALOARE &lt; 0  THEN 0
          ELSE                                      Coalesce(M1_F.PRET, 0)
        END                                    COL06,--ACQUISITIONANDPRODUCTIONCOSTSEND           NUMBER(18,2)
        Coalesce(
          (
            SELECT Sum(Coalesce(c1.valoare - c1.amo, 0))
            FROM cheltavans c INNER JOIN cheltavans1 c1 ON c1.codcheltavans = c.codcheltavans
            WHERE c.codmifix = M1_F.CODMIFIX and c1.anstart *12 + c1.lunastart = SP_ALFIN + 1
          ), 0
        )                                      COL07,--INVESTMENTSUPPORT                          NUMBER(18,2)
        Coalesce(MFCL.DURATA, M1_F.DURATAN, 0) COL08,--ASSETLIFEYEAR                              NUMBER(22,7)
        NULL                                   COL09,--ASSETLIFEMONTH                             NUMBER(22,7)
        (
          SELECT Coalesce(Sum(TJ1.VALOARE), 0)
          FROM TMP_SAFT_JURNAL1 TJ1
          WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
            AND TJ1.TIPDOC = 13
            AND TJ1.ASSETTRANSACTIONTYPE IN (&apos;130&apos;)
            AND TJ1.AN*12+ TJ1.LUNA BETWEEN M1_I.ANSTART*12+M1_I.LUNASTART  AND M1_F.ANSTART*12+M1_F.LUNASTART
        ) +
        CASE
          --WHEN J1I.ASSETTRANSACTIONTYPE IN (&apos;10&apos;) THEN Coalesce(M1_I.PRET, 0)
          WHEN Coalesce(NS_I.CANTNIR, 0) = 0
           AND J1I.ASSETTRANSACTIONTYPE IN (&apos;10&apos;) THEN J1I.VALOARE
          WHEN J1I.ASSETTRANSACTIONTYPE IN (&apos;10&apos;) THEN J1I.VALOARE / NS_I.CANTNIR
          WHEN J1I.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
           AND TM.CODUNIC IS NOT NULL             THEN 0
          WHEN J1I.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
           AND J1I.ICONTC IN (2,3)                THEN 0
          WHEN J1I.ASSETTRANSACTIONTYPE IN (&apos;80&apos;) THEN Coalesce(M1_I.PRET, 0)
          ELSE                                         0
        END                                    COL10,--ASSETADDITION                              NUMBER(18,2)
        (
          SELECT Max(IOA1.CONT)
          FROM TMP_SAFT_JURNAL1 TJ1
          LEFT JOIN TRANSF   T      ON T.CODTRANSF   = TJ1.CODDOC AND T.TIPDOC = TJ1.TIPDOC
          LEFT JOIN TRANSF1  T1     ON T1.CODTRANSF  = T.CODTRANSF
          LEFT JOIN NIRSTOC  NS     ON NS.CODTRANSF1 = T1.CODTRANSF1
          LEFT JOIN IOART    IOA    ON IOA.CODIOART  = NS.CODIOART
          LEFT JOIN IOART1   IOA1   ON IOA1.CODIOART = IOA.CODIOART AND TJ1.AN*12+TJ1.LUNA BETWEEN IOA1.ALSTART  AND IOA1.ALSTOP
          WHERE TJ1.CODMIFIX1 = M1_F.CODMIFIX1 AND TJ1.TIPDOC = 12
          GROUP BY TJ1.CODMIFIX1
            )                                   CONT_TRANSF,
        CASE
          WHEN J1IS.ASSETTRANSACTIONTYPE IN (&apos;20&apos;) AND Coalesce(J1IS.VALOARE,0) &lt; 0 THEN Coalesce(M1_I.PRET, 0)
          WHEN M1_F.STARE IN (3)                                                    THEN - Coalesce(M1_F.pret, 0) -- Coalesce(M1_F.amo, 0)
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)            THEN 0
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)
            AND (
            SELECT COUNT(*)
            FROM TMP_SAFT_JURNAL1 TJ1
            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                  AND TJ1.ASSETTRANSACTIONTYPE = &apos;40&apos;
            GROUP BY TJ1.CODMIFIX
          ) &gt;= 1                                                                    THEN 0
          WHEN M1_F.STARE IN (4)                                                    THEN - Coalesce(M1_F.pret, 0)
          ELSE                                                                           0
        END                                   COL12,--ASSETDISPOSAL                              NUMBER(18,2)
        CASE
          WHEN J1I.TIPDOC = 6                                           THEN 0
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
            AND Coalesce(J1I.TIPDOC, 0) = 35                            THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN Coalesce(J1I.TIPDOC, 0) = 12
           AND SP_ALFIN = M1_F.ANSTART *12 + M1_F.LUNASTART             THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN Coalesce(J1I.TIPDOC, 0) = 12                             THEN Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN (EXTRACT (YEAR FROM NS_I.DATAACHIZ) *12 + EXTRACT (MONTH FROM NS_I.DATAACHIZ)) &lt;  M1_I.ANSTART*12+M1_I.LUNASTART
           AND J1I.ASSETTRANSACTIONTYPE &lt;&gt;(&apos;10&apos;)                        THEN coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
          WHEN J1I.CODJURNAL1 IS NOT NULL                               THEN 0
          WHEN M1_F.STARE IN (4)                                        THEN 0
          WHEN J1IS.ASSETTRANSACTIONTYPE IN (&apos;20&apos;)
            AND Coalesce(J1IS.VALOARE,0) &lt; 0                            THEN 0
          ELSE                                                               Coalesce(M1_I.pret, 0) - Coalesce(M1_I.amo,  0)
        END                                    COL13,--BOOKVALUEBEGIN                             NUMBER(18,2)
        CASE
          WHEN M1_F.TIPAMO = 1 THEN &apos;LINIARA&apos;
          WHEN M1_F.TIPAMO = 2 THEN &apos;ACCELERATA&apos;
          WHEN M1_F.TIPAMO = 3 THEN &apos;DEGRESIVA&apos;
          WHEN M1_F.TIPAMO = 4 THEN &apos;DEGRESIVA&apos;
          ELSE                      &apos;...&apos;
        END                                    COL14,--DEPRECIATIONMETHOD                         NVARCHAR2(35)
        CASE
          WHEN Coalesce(MFCL.DURATA, M1_F.DURATAN, 0) = 0 THEN 0
          ELSE Round(1/Coalesce(MFCL.DURATA, M1_F.DURATAN), 2)
        END                                    COL15,--DEPRECIATIONPERCENTAGE                     NUMBER(22,7)
        CASE
          WHEN M1_F.STARE IN (4)  AND J1I.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)
            AND (
            SELECT COUNT(*)
            FROM TMP_SAFT_JURNAL1 TJ1
            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                  AND TJ1.ASSETTRANSACTIONTYPE = &apos;40&apos;
            GROUP BY TJ1.CODMIFIX
          ) &gt;= 1                                                                      THEN 0
          WHEN M1_F.STARE = 4 AND Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0) = 0   THEN 0
          WHEN M1_F.STARE = 4                                                         THEN Coalesce(M1_I.AMO,0) - Coalesce(M1_F.AMO,0)
          WHEN COALESCE(M1_I.TIPSTORNO,0) = 0 AND M1_F.Stare = 8
            and J1I.TIPTRANZACTIE = 1                                                 THEN 0
          WHEN (COALESCE(M1_F.TIPSTORNO,0) IN (1,2) AND M1_F.Stare = 8)
            OR (M1_F.Stare IN (9))                                                    THEN (
                         SELECT Sum(-TJ1.VALOARE)
                            FROM TMP_SAFT_JURNAL1 TJ1
                            WHERE TJ1.CODMIFIX = M1_I.CODMIFIX
                                  AND TJ1.TIPDOC = 36
                                  AND TJ1.ASSETTRANSACTIONTYPE = &apos;30&apos;
                            GROUP BY TJ1.CODMIFIX
                            )
          WHEN M1_F.Stare IN (7)                                                      THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0)
          WHEN J1I.TIPDOC = 35                                                        THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_U.AMO, 0) -
                CASE
                   WHEN TNA.CODUNIC IS NOT NULL                                       THEN(
                          SELECT SUM(-J1.VALOARE)
                             FROM TMP_SAFT_JURNAL1 J1
                             WHERE J1.CODMIFIX = M1_F.CODMIFIX
                                   AND J1.CONTD = (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CRezRepAmoMifixNC&apos;))
                             GROUP BY J1.CODMIFIX
                          )
                   ELSE                                                                    0
                 END
          WHEN J1I.TIPDOC = 23                                                        THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0)
          WHEN J1I.TIPDOC = 12 AND J1I.VALOARE &lt; 0                                    THEN Coalesce(M1_I.AMO, 0) - Coalesce(M1_F.AMO, 0) -
                                                                                           Round(((Coalesce(M1_F.PRET,0) - Coalesce(M1_F.AMO, 0))/M1_F.DURATAF),3)
          ELSE                                                                             Coalesce(M1_I.AMO, 0) - Coalesce(M1_U.AMO, 0)
        END                                    COL16,--DEPRECIATIONFORPERIOD                      NUMBER(18,2)
        CASE
          WHEN
            EXISTS (
              SELECT 1
              FROM MIFIX1 M1
              WHERE M1.CODMIFIX = M1_I.CODMIFIX
                AND M1.ANSTART*12+M1.LUNASTART BETWEEN M1_I.ANSTART*12+M1_I.LUNASTART AND M1_F.ANSTART*12+M1_F.LUNASTART
                AND M1.TIPREEVAL IN (0, 1)
            )
          THEN Coalesce(NS_F.PRET, 0) - Coalesce(NS_I.PRET, 0)
          ELSE 0
        END                                 COL17,--APPRECIATIONFORPERIOD                      NUMBER(18,2)
        C60.CODSAF                          COL18,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
        CASE
          WHEN M1_F.STARE IN (3, 4, 7, 8, 9, 10)       THEN 0
          WHEN J1I.TIPDOC IN (23)                      THEN 0
          WHEN J1I.TIPDOC IN (12) AND J1I.VALOARE &lt; 0  THEN 0
          WHEN M1_U.CODMIFIX IS NULL                   THEN - Coalesce(M1_F.amo, 0)
          ELSE                                              - Coalesce(M1_U.amo, 0)
        END                                 COL19,--ACCUMULATEDDEPRECIATION                    NUMBER(18,2)
        CASE
           WHEN TNA.CODUNIC IS NOT NULL           THEN(
                SELECT SUM(-J1.VALOARE)
                FROM TMP_SAFT_JURNAL1 J1
                WHERE J1.CODMIFIX = M1_F.CODMIFIX
                      AND J1.CONTD = (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CRezRepAmoMifixNC&apos;))
                GROUP BY J1.CODMIFIX
                          )
           ELSE                                        0
        END                                 AMORTIZ_EXTRAORD,
        Row_Number() OVER (PARTITION BY C24.CODPARINTE ORDER BY M1_I.ANSTART, M1_I.LUNASTART) IDX_GRUP,
        Coalesce(J1I.TIPDOC, 0) J1I_TIPDOC,
        M1_F.ANSTART*12+M1_F.LUNASTART M1_F_ALSTART,
        Coalesce(M1_A.pret,0) M1_A_Pret, Coalesce(M1_A.amo, 0) M1_A_amo, Coalesce(M1_A.CODCLASIF, 0) M1_A_CODCLASIF,  M1_A.CODMIFIX1 M1_A_CODMIFIX1,
        Coalesce(M1_I.pret,0) M1_I_Pret, Coalesce(M1_I.amo, 0) M1_I_amo, Coalesce(M1_I.CODCLASIF, 0) M1_I_CODCLASIF,
        Coalesce(M1_F.pret,0) M1_F_Pret, Coalesce(M1_F.amo, 0) M1_F_amo, Coalesce(M1_F.CODCLASIF, 0) M1_F_CODCLASIF, Coalesce(M1_F.STARE, 0) M1_F_STARE,
        Coalesce(M1_U.pret,0) M1_U_Pret, Coalesce(M1_U.amo, 0) M1_U_amo, Coalesce(M1_U.CODCLASIF, 0) M1_U_CODCLASIF,
        M1_U.CODMIFIX M1_U_CODMIFIX, NS_A.CODIOART NS_A_CODIOART, NS_I.CODIOART NS_I_CODIOART, COALESCE(NS_F.PROVIZION,0) NS_F_PROVIZION,
        J1I.ASSETTRANSACTIONTYPE J1I_ASSETTRANSACTIONTYPE, J1I.ICONTC J1I_ICONTC, TM.CODUNIC TM_CODUNIC, J1I.TIPTRANZACTIE J1I_TIPTRANZACTIE,
        J1IS.ASSETTRANSACTIONTYPE J1IS_ASSETTRANSACTIONTYPE, Coalesce(J1IS.VALOARE,0) J1IS_VALOARE, J1I.VALOARE J1I_VALOARE,
        M_I.ANINTRARE M_I_ANINTRARE, M_I.LUNAINTRARE M_I_LUNAINTRARE, TNB.CODUNIC TNB_CODUNIC, Coalesce(M1_F.CODMIFIX,C24.CODPARINTE) CODMIFIX_GRUP
      FROM TMP_SAFT_CODSAF C24
        LEFT  JOIN TMP_SAFT_CODSAF   C59   ON C59.CODSAF      = C24.CODPARINTE  AND C59.CODAUX = C24.CODAUX-- DISCUTIE -&gt; C29.CODSURSA &lt;&gt; M1_F.CODMIFIX
        LEFT  JOIN TMP_SAFT_CODSAF   C60   ON C60.CODPARINTE  = C24.CODSAF      AND C60.CodSAFTTab = 60
        LEFT  JOIN MIFIX1            M1_I  ON M1_I.CODMIFIX1  = C59.CODAUX
        LEFT  JOIN MIFIX             M_I   ON M_I.CODMIFIX    = M1_I.CODMIFIX
        LEFT  JOIN MIFIX1            M1_A  ON M1_A.CODMIFIX   = M1_I.CODMIFIX   AND M1_A.ANSTART*12+M1_A.LUNASTART = M1_I.ANSTART*12+M1_I.LUNASTART-1
        LEFT  JOIN TMP_SAFT_JURNAL1  J1I   ON J1I.CODMIFIX    = M1_I.CODMIFIX   AND J1I.TIPDOC IN (1,2,3,4,5,6,7,12,13,15,23,35)
        LEFT  JOIN (
                   SELECT CODMIFIX, Max(CODMIFIX1) MAX_CODMIFIX1
                   FROM MIFIX1
                   GROUP BY CODMIFIX
                   )                 M1_M  ON M1_M.CODMIFIX   = M_I.CODMIFIX
        LEFT  JOIN MIFIX1            M1_F  ON M1_F.CODMIFIX1  = CASE WHEN J1I.TIPDOC = 23 THEN M1_M.MAX_CODMIFIX1 ELSE C24.CODSURSA END
        LEFT  JOIN MIFIX1            M1_U  ON M1_U.CODMIFIX   = M1_F.CODMIFIX   AND M1_U.ANSTART*12+M1_U.LUNASTART = M1_F.ANSTART*12+M1_F.LUNASTART+1
        LEFT  JOIN NIRSTOC           NS_A  ON NS_A.CODNIRSTOC = M1_A.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS_I  ON NS_I.CODNIRSTOC = M1_I.CODNIRSTOC
        LEFT  JOIN NIRSTOC           NS_F  ON NS_F.CODNIRSTOC = M1_F.CODNIRSTOC
        LEFT  JOIN MFCLASIF          MFCL  ON MFCL.CODCLASIF  = M1_F.CODCLASIF
        LEFT  JOIN TMP_SAFT_JURNAL1  J1IS  ON J1IS.CODMIFIX   = M1_I.CODMIFIX   AND J1IS.TIPDOC IN (19) AND Coalesce(J1IS.VALOARE,0) &lt; 0
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CImbMifix&apos;, &apos;ProvMiFix&apos;)
        )                            TM    ON TM.CODUNIC      = J1I.CONTC
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CCheltAmoMifixNC&apos;)
        )                            TNC   ON TNC.CODUNIC     = J1I.CODDESCRD
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CRezRepAmoMifixNC&apos;)
        )                            TNA   ON TNA.CODUNIC     = J1I.CODDESCRD
        LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CMifix&apos;)
        )                            TNB   ON TNB.CODUNIC     = J1I.CONTD
      WHERE C24.CodSAFTTab = 24
    ) sub_a
  ) sub_b
  GROUP BY CODMIFIX_GRUP, COL03
  ORDER BY COL01 ASC;
END;

PROCEDURE UMPLE_T60 IS --SAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD
BEGIN
  INSERT INTO TMP_SAFT60
  SELECT
    C25.CODPARINTE COL01,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
    Count(1)       COL02 --DETSAF_EXTRAORDINARYDEPRECIATIONFORPERIOD  NUMBER(20)
  FROM TMP_SAFT_CODSAF C25
  WHERE C25.CodSAFTTab = 25
  GROUP BY C25.CODPARINTE;
END;

PROCEDURE UMPLE_T25 IS --SAF_EXTRAORDINARYDEPRECIATIONFORPERIOD
BEGIN
  INSERT INTO TMP_SAFT25
  SELECT
    DISTINCT C25.CODSAF        COL01,--CODSAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD NUMBER(20)
    C25.CODPARINTE             COL02,--CODSAF_MASTER                              NUMBER(20)
    CASE
      WHEN COALESCE(NS.PROVIZION,0) &lt;&gt; 0      THEN &apos;PROVIZION&apos;
      WHEN J1.ASSETTRANSACTIONTYPE = &apos;130&apos;
        AND J1.ICONTD = 10 AND J1.ICONTC = 0  THEN &apos;AMORTIZARE TRECUTA PE VENIT&apos;
      WHEN TNA.CODUNIC IS NOT NULL            THEN &apos;AMORTIZARE AN ANTERIOR&apos;
      ELSE                                         &apos;0&apos;
    END                        COL03,--EXTRAORDINARYDEPRECIATIONMETHOD            NVARCHAR2(35)
    CASE
      WHEN COALESCE(NS.PROVIZION,0) &lt;&gt; 0      THEN -COALESCE(NS.PROVIZION,0)
      WHEN J1.ASSETTRANSACTIONTYPE = &apos;130&apos;
        AND J1.ICONTD = 10 AND J1.ICONTC = 0  THEN J1.VALOARE
      WHEN TNA.CODUNIC IS NOT NULL            THEN - J1.VALOARE
      ELSE                                         0
    END                        COL04 --EXTRAORDINARYDEPRECIATIONAMOUNTFORPERIOD   NUMBER(18,2)
  FROM TMP_SAFT_CODSAF C25
       LEFT JOIN TMP_SAFT_CODSAF       C60   ON  C60.CODPARINTE  = C25.CODSAF     AND C60.CodSAFTTab = 60
       LEFT JOIN MIFIX1                M1    ON  M1.CODMIFIX1    = C25.CODAUX
       LEFT JOIN NIRSTOC               NS    ON  NS.CODNIRSTOC   = M1.CODNIRSTOC
       LEFT JOIN TMP_SAFT_JURNAL1      J1    ON  J1.CODMIFIX     = M1.CODMIFIX
       LEFT  JOIN (
          SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CRezRepAmoMifixNC&apos;)
        )                            TNA   ON TNA.CODUNIC     = J1.CONTD
  WHERE C25.CodSAFTTab = 25;
END;

PROCEDURE UMPLE_T26 IS --SAF_GENERALLEDGERENTRIES
  v_ALIni   NUMBER;
  v_ALFin   NUMBER;
  vCodSAF  NUMBER;
  vSubunit NUMBER;
  vTip     NUMBER(1);
BEGIN
  PUT_INFO(&apos;26.A&apos;,&apos;UMPLE_T26--SAF_GENERALLEDGERENTRIES&apos;);
  SELECT ANINI*12+LUNAINI, ANFIN*12+LUNAFIN, CodSubunit, Tip
  INTO   v_ALIni         , v_ALFin         , vSubunit  , vTip
  FROM TMP_SAFT_PARAMS;

  SELECT CODSAF
  INTO vCodSAF
  FROM TMP_SAFT_CODSAF WHERE CodSAFTTab = 26;

  IF vTip IN (4,7) THEN
    INSERT INTO TMP_SAFT26
    SELECT
      26                COL01,--CODSAF_GENERALLEDGERENTRIES NUMERIC(20,0)
      0                 COL02,--NUMBEROFENTRIES             NUMERIC(20,0)
      0                 COL03,--TOTALDEBIT                  NUMERIC(18,2)
      0                 COL04,--TOTALCREDIT                 NUMERIC(18,2)
      0                 COL05 --DETSAF_JOURNAL              NUMERIC(20,0)
    FROM DUAL;
  ELSE
    INSERT INTO TMP_SAFT26
    SELECT
      vCodSAF           COL01,--CODSAF_GENERALLEDGERENTRIES NUMERIC(20,0)
      Count(1)          COL02,--NUMBEROFENTRIES             NUMERIC(20,0)
      Sum(VALOARE)      COL03,--TOTALDEBIT                  NUMERIC(18,2)
      Sum(VALOARE)      COL04,--TOTALCREDIT                 NUMERIC(18,2)
      Count(1)          COL05 --DETSAF_JOURNAL              NUMERIC(20,0)
    FROM TMP_SAFT_JURNAL J
      INNER JOIN NCONT CD ON CD.CODCONT = J.CONTD
      INNER JOIN NCONT CC ON CC.CODCONT = J.CONTC
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND vSubunit = CASE WHEN vSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
      AND NOT(CD.CLASA IN (8,9) AND CC.CLASA IN (8,9));  --ticket 52580 fara clase 8,9
  END IF;
  PUT_INFO(&apos;26.Z&apos;,&apos;UMPLE_T26--SAF_GENERALLEDGERENTRIES&apos;);
END;

PROCEDURE UMPLE_T27 IS --SAF_JOURNAL
  vCodMaster NUMBER;
BEGIN
  PUT_INFO(&apos;27.A&apos;,&apos;UMPLE_T27--SAF_JOURNAL&apos;);
  SELECT CODSAF
  INTO vCodMaster
  FROM TMP_SAFT_CODSAF
  WHERE CodSAFTTab = 26;

  INSERT INTO TMP_SAFT27
  SELECT
    C27.CODSAF                                     COL01,--CODSAF_JOURNAL     NUMBER(20)
    vCodMaster                                     COL02,--CODSAF_MASTER      NUMBER(20)
    To_Char(J.CodJurnal,&apos;fm999999999999999999990&apos;) COL03,--JOURNALID          NVARCHAR2(18)
    J.DESCRIPTION                                  COL04,--DESCRIPTION        NVARCHAR2(256)
    To_Char(J.TipDoc ,&apos;fm99990&apos;)                   COL05,--TYPE               NVARCHAR2(9)
    1                                              COL06 --DETSAF_TRANSACTION NUMBER(20)
  FROM TMP_SAFT_CODSAF C27
    LEFT JOIN TMP_SAFT_JURNAL J  ON J.CODJURNAL   = C27.CODSURSA
  WHERE C27.CodSAFTTab = 27;
  PUT_INFO(&apos;27.Z&apos;,&apos;UMPLE_T27--SAF_JOURNAL&apos;);
END;

PROCEDURE UMPLE_T28 IS --SAF_TRANSACTION
  dDataTip32 DATE ;
  sFirmaID   VARCHAR2(35);
  vSubunit   NUMBER(20);
BEGIN
  PUT_INFO(&apos;28.A&apos;,&apos;UMPLE_T28--SAF_TRANSACTION&apos;);
  SELECT Last_Day( To_Date( To_Char(ANFIN,&apos;fm0000&apos;)||To_Char(LUNAFIN,&apos;fm00&apos;), &apos;yyyymm&apos;)), CODSUBUNIT INTO dDataTip32, vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT &apos;00&apos;||REGEXP_REPLACE(F.CODFISCAL,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT &apos;00&apos;||REGEXP_REPLACE(S.CIF,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT28
  WITH TMP_SAFT_PARTCONT (CODPART, CODCONT, CLIENT, FURNIZOR) AS (
    SELECT DISTINCT CODPART, CODCONT, CLIENT, FURNIZOR
    FROM TMP_SAFT_NPART
  )
  SELECT
    C28.CODSAF                                              COL01,--CODSAF_TRANSACTION     NUMBER(20)
    C27.CODSAF                                              COL02,--CODSAF_MASTER          NUMBER(20)
    To_Char(J.TipDoc)||&apos;_&apos;||
    To_Char(J.CodDoc)                                       COL03,--TRANSACTIONID          NVARCHAR2(70)
    J.LUNA                                                  COL04,--PERIOD                 NUMBER(20)
    J.AN                                                    COL05,--PERIODYEAR             NUMBER(20)
    JD.DATADOC                                              COL06,--TRANSACTIONDATE        DATE
    CASE
      WHEN J.TIPDOC IN (29, 30, 31, 35, 46, 81)
      THEN To_Char(J.IndexLocal)
    END                                                     COL07,--SOURCEID               NVARCHAR2(35)
    To_Char(J.TipDoc)                                       COL08,--TRANSACTIONTYPE        NVARCHAR2(18)
    J.DESCRIPTION                                           COL09,--DESCRIPTION            NVARCHAR2(256)
    NULL                                                    COL10,--BATCHID                NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC IN (25,32,36,45,46,47,52,58,71,81,106,108) THEN dDataTip32
      ELSE JD.DATACREARE
    END                                                     COL11,--SYSTEMENTRYDATE        DATE
    CASE
      WHEN J.TIPDOC IN (25,32,36,45,46,47,52,58,71,81,106,108) THEN dDataTip32
      ELSE JD.DATACREARE
    END                                                     COL12,--GLPOSTINGDATE          DATE
    CASE
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2D.CODCONT IS NOT NULL AND P2D.CLIENT   = 1 THEN PD2.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN &apos;0&apos;
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2C.CODCONT IS NOT NULL AND P2C.FURNIZOR = 1 THEN &apos;0&apos;
      WHEN J.TIPDOC IN (28, 35)                                                                                     THEN &apos;0&apos;
      WHEN J.TIPDOC IN (46, 59)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL                      THEN PD1.PartID
      WHEN J.TIPDOC IN (46, 59)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL                      THEN &apos;0&apos; --sFirmaID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0                                                     THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1                                                     THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0                                                     THEN sFirmaID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.CLIENT   = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1                                                     THEN sFirmaID
      WHEN IES_J.CODIES IS NULL          AND INT_J.CODINTR IS NULL                                                  THEN sFirmaID
      WHEN IES_J.CODIES IS NULL                                                                                     THEN &apos;0&apos;
      WHEN IES_J.TIPDOC = 14                                                                                        THEN sFirmaID
      WHEN IES_J.TIPDOC = 15                                                                                        THEN sFirmaID
      WHEN IES_J.TIPDOC = 16                                                                                        THEN &apos;080000000000000&apos;
      WHEN IES_J.TIPDOC = 23                                                                                        THEN sFirmaID
      WHEN IES_J.TIPDOC = 24                                                                                        THEN sFirmaID
      WHEN                                                             P1D.CODCONT IS NOT NULL                      THEN PD1.PartID
      WHEN                                                             P1C.CODCONT IS NOT NULL                      THEN PD1.PartID
                                                                                                                    ELSE sFirmaID -- PD1.PartID
    END                                                     COL13,--CUSTOMERID             NVARCHAR2(35)
    CASE
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2D.CODCONT IS NOT NULL AND P2D.FURNIZOR = 1 THEN PD2.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN J.TIPDOC IN (28, 35)          AND PD2.CODPART &lt;&gt; 0      AND P2C.CODCONT IS NOT NULL AND P2C.CLIENT   = 1 THEN &apos;0&apos;
      WHEN J.TIPDOC IN (28, 35)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL AND P1D.CLIENT   = 1 THEN &apos;0&apos;
      WHEN J.TIPDOC IN (28, 35)                                                                                     THEN &apos;0&apos;
      WHEN J.TIPDOC IN (46, 59)          AND PD1.CODPART &lt;&gt; 0      AND P1C.CODCONT IS NOT NULL                      THEN PD1.PartID
      WHEN J.TIPDOC IN (46, 59)          AND PD1.CODPART &lt;&gt; 0      AND P1D.CODCONT IS NOT NULL                      THEN &apos;0&apos; --sFirmaID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 0                                                     THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  1              AND JD.OBIECTTRANZ = 1                                                     THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1D.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0    AND P1C.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 0                                                     THEN sFirmaID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL AND P1D.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL AND P1C.FURNIZOR = 1 THEN PD1.PartID
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1D.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1    AND P1C.CODCONT IS NOT NULL                      THEN &apos;0&apos;
      WHEN JD.TIPTRANZ =  0              AND JD.OBIECTTRANZ = 1                                                     THEN sFirmaID
      WHEN IES_J.CODIES  IS NULL         AND INT_J.CODINTR IS NULL                                                  THEN sFirmaID
      WHEN INT_J.CODINTR IS NULL                                                                                    THEN &apos;0&apos;
      WHEN INT_J.TIPDOC =  6                                                                                        THEN sFirmaID
      WHEN INT_J.TIPDOC =  7                                                                                        THEN sFirmaID
      WHEN                                                             P1D.CODCONT IS NOT NULL                      THEN PD1.PartID
      WHEN                                                             P1C.CODCONT IS NOT NULL                      THEN PD1.PartID
      WHEN Coalesce(INT_J.TIPTVA, 0) = 2 AND CD.CodSAFT = &apos;4426&apos;   AND CC.CodSAFT = &apos;4427&apos;                          THEN PD1.PartID
                                                                                                                    ELSE sFirmaID -- PD1.PartID
    END                                                     COL14,--SUPPLIERID             NVARCHAR2(35)
    To_Char(Coalesce(INT_S.TipDoc, IES_S.TipDoc, J.CodDoc)) COL15,--SYSTEMID               NVARCHAR2(18)
    2                                                       COL16 --DETSAF_TRANSACTIONLINE NUMBER(20)
  FROM TMP_SAFT_CODSAF C28
    LEFT JOIN TMP_SAFT_CODSAF    C27   ON C27.CODSURSA  = C28.CODSURSA   AND C27.CodSAFTTab = 27
    LEFT JOIN TMP_SAFT_JURNAL    J     ON J.CODJURNAL   = C28.CODSURSA
    LEFT JOIN TMP_SAFT_JURNALDET JD    ON JD.CODJURNAL  = C28.CODSURSA
    LEFT JOIN IESIRI             IES_J ON IES_J.CODIES  = J.CODDOC       AND IES_J.TIPDOC   = J.TIPDOC
    LEFT JOIN INTRARI            INT_J ON INT_J.CODINTR = J.CODDOC       AND INT_J.TIPDOC   = J.TIPDOC
    LEFT JOIN INTRARI            INT_S ON INT_S.CODINTR = J.INDEXLOCAL   AND J.TIPDOC       = 81       AND J.CODDOC = 1
    LEFT JOIN IESIRI             IES_S ON IES_S.CODIES  = J.INDEXLOCAL   AND J.TIPDOC       = 81       AND J.CODDOC = 2
    LEFT JOIN TMP_SAFT_NPARTFUZ  P1    ON P1.CODPART    = JD.CODPART
    LEFT JOIN TMP_SAFT_NPARTFUZ  P2    ON P2.CODPART    = JD.CODPART_2
    LEFT JOIN TMP_SAFT_NPARTDET  PD1   ON PD1.CODPART   = P1.CODPARTFUZ
    LEFT JOIN TMP_SAFT_NPARTDET  PD2   ON PD2.CODPART   = P2.CODPARTFUZ
    LEFT JOIN TMP_SAFT_PARTCONT  P1D   ON P1D.CODPART   = P1.CODPART     AND P1D.CODCONT    = J.CONTD
    LEFT JOIN TMP_SAFT_PARTCONT  P1C   ON P1C.CODPART   = P1.CODPART     AND P1C.CODCONT    = J.CONTC
    LEFT JOIN TMP_SAFT_PARTCONT  P2D   ON P2D.CODPART   = P2.CODPART     AND P2D.CODCONT    = J.CONTD
    LEFT JOIN TMP_SAFT_PARTCONT  P2C   ON P2C.CODPART   = P2.CODPART     AND P2C.CODCONT    = J.CONTC
    LEFT JOIN TMP_SAFT_NCONT     CD    ON CD.CODCONT    = J.CONTD
    LEFT JOIN TMP_SAFT_NCONT     CC    ON CC.CodCont    = J.CONTC
  WHERE C28.CodSAFTTab = 28;

  UPDATE TMP_SAFT28
  SET    COL13 = sFirmaID,    COL14 = sFirmaID
  WHERE (COL13 = &apos;0&apos;      AND COL14 = &apos;0&apos;     ) OR
        (COL13 = &apos;0&apos;      AND COL14 = sFirmaID) OR
        (COL13 = sFirmaID AND COL14 = &apos;0&apos;     );

  PUT_INFO(&apos;28.Z&apos;,&apos;UMPLE_T28--SAF_TRANSACTION&apos;);
END;

PROCEDURE UMPLE_T29 IS --SAF_TRANSACTIONLINE
  sFirmaID   NVARCHAR2(35);
  vSubunit   NUMBER(20);
BEGIN
  PUT_INFO(&apos;29.A&apos;,&apos;UMPLE_T29--SAF_TRANSACTIONLINE&apos;);
  SELECT CODSUBUNIT INTO  vSubunit
  FROM TMP_SAFT_PARAMS;

  IF vSubunit = 1 THEN
    SELECT &apos;00&apos;||REGEXP_REPLACE(F.CODFISCAL,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA = SP.CODFIRMA;
  ELSE
    SELECT &apos;00&apos;||REGEXP_REPLACE(S.CIF,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID
    FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT29
  SELECT
    SEQ_SAFT.NEXTVAL                                    COL01,--CODSAF_TRANSACTIONLINE    NUMBER(20)
    S28.COL01                                           COL02,--CODSAF_MASTER             NUMBER(20)
    To_Char(J.DataDoc,&apos;YYYYMMDD&apos;)||
    Row_Number() OVER (PARTITION BY J.TIPDOC, J.CODDOC
                       ORDER BY J.CODJURNAL)            COL03,--RECORDID                  NVARCHAR2(18)
    C.CODSAFT                                           COL04,--ACCOUNTID                 NVARCHAR2(70)
    NULL                                                COL05,--CODSAF_ANALYSIS           NUMBER(20)
    NULL                                                COL06,--VALUEDATE                 DATE
    NULL                                                COL07,--SOURCEDOCUMENTID          NVARCHAR2(35)
    CASE
      WHEN P.CODPART IS NULL                       THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35) AND P.CLIENT = 0   THEN n&apos;0&apos;
      ELSE Coalesce(S28.COL13, n&apos;0&apos;)
    END                                                 COL08,--CUSTOMERID                NVARCHAR2(35)
    CASE
      WHEN P.CODPART IS NULL                       THEN sFirmaID
      WHEN J.TIPDOC IN (28, 35) AND P.FURNIZOR = 0 THEN n&apos;0&apos;
      ELSE Coalesce(S28.COL14, n&apos;0&apos;)
    END                                                 COL09,--SUPPLIERID                NVARCHAR2(35)
    J.DESCRIPTION                                       COL10,--DESCRIPTION               NVARCHAR2(256)
    CASE WHEN C31.CodSAFTTab = 3101 THEN C31.CODSAF END COL11,--CODDEBITAMOUNTSAF_AMOUNT  NUMBER(20)
    CASE WHEN C31.CodSAFTTab = 3102 THEN C31.CODSAF END COL12,--CODCREDITAMOUNTSAF_AMOUNT NUMBER(20)
    1                                                   COL13 --DETSAF_TAXINFORMATION     NUMBER(20)
  FROM TMP_SAFT_CODSAF C31
    LEFT JOIN TMP_SAFT_JURNAL    J    ON J.CODJURNAL  = C31.CODSURSA
    LEFT JOIN TMP_SAFT_JURNALDET JD   ON JD.CODJURNAL = C31.CODSURSA
    LEFT JOIN TMP_SAFT_NCONT     C    ON C.CODCONT    = CASE WHEN C31.CodSAFTTab = 3101 THEN J.CONTD ELSE J.CONTC END
    LEFT JOIN TMP_SAFT_NCONT     CTVA ON CTVA.CodCont = C.CodCont    AND CTVA.CodSAFT IN (&apos;4426&apos;, &apos;4427&apos;, &apos;4428&apos;)
    LEFT JOIN TMP_SAFT_CODSAF    C28  ON C28.CODSURSA = C31.CODSURSA AND C28.CodSAFTTab = 28
    LEFT JOIN TMP_SAFT28         S28  ON S28.COL01    = C28.CODSAF
    LEFT JOIN (
      SELECT DISTINCT CODPART, CODCONT, CLIENT, FURNIZOR
      FROM TMP_SAFT_NPART
    )                            P    ON P.CODPART    = CASE WHEN C31.CodSAFTTab = 3101 AND J.TIPDOC IN (28, 35) THEN JD.CODPART_2 ELSE JD.CODPART END
                                     AND P.CODCONT    = C.CODCONT
  WHERE C31.CodSAFTTab IN (3101, 3102);

  PUT_INFO(&apos;29.Z&apos;,&apos;UMPLE_T29--SAF_TRANSACTIONLINE&apos;);
END;

PROCEDURE UMPLE_T30 IS --SAF_ANALYSIS
BEGIN
  --INSERT INTO TMP_SAFT30
  NULL;
END;

PROCEDURE UMPLE_T31 IS --SAF_AMOUNT
BEGIN
  PUT_INFO(&apos;31.A&apos;,&apos;UMPLE_T31--SAF_AMOUNT&apos;);
  INSERT INTO TMP_SAFT31
  SELECT
    99    COL01,--CODSAF_AMOUNT  NUMBER(20)
    0     COL02,--AMOUNT         NUMBER(18,2)
    &apos;RON&apos; COL03,--CURRENCYCODE   NVARCHAR2(3)
    0     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    1     COL05 --EXCHANGERATE   NUMBER(18,4)
  FROM DUAL;

  INSERT INTO TMP_SAFT31
  SELECT
    subs.CODSAF                             COL01,--CODSAF_AMOUNT  NUMBER(20)
    subs.AMOUNT                             COL02,--AMOUNT         NUMBER(18,2)
    subs.CURRENCYCODE                       COL03,--CURRENCYCODE   NVARCHAR2(3)
    CASE
      WHEN subs.CURRENCYCODE &lt;&gt; &apos;RON&apos;
      THEN subs.AMOUNT/CASE WHEN subs.EXCHANGERATE = 0 THEN 1 ELSE subs.EXCHANGERATE END
      ELSE subs.AMOUNT
    END                                     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    subs.EXCHANGERATE                       COL05 --EXCHANGERATE   NUMBER(18,4)
  FROM (
    SELECT
      C31a.CODSAF,
      J.VALOARE AS AMOUNT,
      J.CURRENCYCODE, J.EXCHANGERATE --, &apos;RON&apos; CURRENCYCODE, 1 EXCHANGERATE
    FROM TMP_SAFT_CODSAF C31a
      LEFT JOIN TMP_SAFT_JURNAL J  ON J.CODJURNAL = C31a.CODSURSA
    WHERE C31a.CodSAFTTab IN (3101, 3102)
  ) subs;

  INSERT INTO TMP_SAFT31
  SELECT
    subs.CODSAF                             COL01,--CODSAF_AMOUNT  NUMBER(20)
    subs.AMOUNT                             COL02,--AMOUNT         NUMBER(18,2)
    subs.CURRENCYCODE                       COL03,--CURRENCYCODE   NVARCHAR2(3)
    CASE
      WHEN subs.CURRENCYCODE &lt;&gt; &apos;RON&apos;
      THEN subs.AMOUNT/CASE WHEN subs.EXCHANGERATE = 0 THEN 1 ELSE subs.EXCHANGERATE END
      ELSE subs.AMOUNT
    END                                     COL04,--CURRENCYAMOUNT NUMBER(18,2)
    subs.EXCHANGERATE                       COL05 --EXCHANGERATE   NUMBER(18,4)
  FROM (
    SELECT
      C31b.CODSAF,
      Coalesce(
        CASE
          WHEN J.TIPDOC = 14 AND CC.CodSAFT IN (&apos;4427&apos;) THEN 0
          WHEN J.TIPDOC = 35 AND CC.CodSAFT IN (&apos;4426&apos;) THEN 0
          WHEN Coalesce(TI.TAXCODE, n&apos;0&apos;) = &apos;310327&apos;    THEN 0
          WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        END,
        MTI.TAXVAL,
        TI.TAXVAL,
        0
      ) AS AMOUNT,
      J.CURRENCYCODE, J.EXCHANGERATE --, &apos;RON&apos; CURRENCYCODE, 1 EXCHANGERATE
    FROM  TMP_SAFT_CODSAF C31b
      LEFT JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31b.CODSURSA
      LEFT JOIN TMP_SAFT_NCONT      CC  ON CC.CODCONT  = J.CONTC
      LEFT JOIN IESIRI              IES ON IES.CODIES  = J.INDEXLOCAL AND IES.TIPDOC = J.TIPDOC
      LEFT JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODTI = C31b.CODAUX AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
                                       AND TI.CODCONT  = CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTD ELSE J.CONTC END
                                       AND                         CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTC ELSE J.CONTD END =
                                           Coalesce(TI.CODCONTDED, CASE WHEN C31b.CodSAFTTab = 3103 THEN J.CONTC ELSE J.CONTD END)
      LEFT JOIN TMP_SAFT_TAXINFO_MP MTI ON MTI.CODTI = C31b.CODAUX AND MTI.IDXLOCAL = C31b.IDXAUX AND MTI.CODCONT = J.CONTD
    WHERE C31b.CodSAFTTab IN (3103, 3104)
  ) subs;
  PUT_INFO(&apos;31.Z&apos;,&apos;UMPLE_T31--SAF_AMOUNT&apos;);
END;

PROCEDURE UMPLE_T32 IS --SAF_TAXINFORMATION
BEGIN
  PUT_INFO(&apos;32.A&apos;,&apos;UMPLE_T32--SAF_TAXINFORMATION&apos;);
  INSERT INTO TMP_SAFT32
  SELECT
    SEQ_SAFT.NEXTVAL          COL01,--CODSAF_TAXINFORMATION  NUMBER(20)
    S29.COL01                 COL02,--CODSAF_MASTER          NUMBER(20)
    Coalesce(
      TI.TAXTYPE,
      TID.TAXTYPE,
      TIP.TAXTYPE,
      TI5.TAXTYPE,
      TIT.TAXTYPE,
      TI14.TAXTYPE,
      TI35.TAXTYPE,
      n&apos;000&apos;
    )                         COL03,--TAXTYPE                NVARCHAR2(9)
    Coalesce(
      TI.TAXCODE,
      TID.TAXCODE,
      TIP.TAXCODE,
      TI5.TAXCODE,
      TIT.TAXCODE,
      TI14.TAXCODE,
      TI35.TAXCODE,
      n&apos;000000&apos;
    )                         COL04,--TAXCODE                NVARCHAR2(9)
    Coalesce(
      CASE
        WHEN J.TIPDOC = 14 AND CC.CodSAFT IN (&apos;4427&apos;) THEN 0
        WHEN J.TIPDOC = 35 AND CC.CodSAFT IN (&apos;4426&apos;) THEN 0
        WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        WHEN S29.COL04 IN (&apos;4426&apos;, &apos;4427&apos;, &apos;4428&apos;)    THEN 0
      END,
      TI.TAXPERCENTAGE
    )                         COL05,--TAXPERCENTAGE          NUMBER(22,4)
    COALESCE(
      CASE
        WHEN J.TIPDOC = 14 AND CC.CodSAFT IN (&apos;4427&apos;) THEN 0
        WHEN J.TIPDOC = 35 AND CC.CodSAFT IN (&apos;4426&apos;) THEN 0
        WHEN Coalesce(IES.TIPTVA, 0)    = 10          THEN 0
        WHEN S29.COL04 IN (&apos;4426&apos;, &apos;4427&apos;, &apos;4428&apos;)    THEN 0
      END,
      MTI.TAXBASE,
      TI.CHEIE_BAZATVAMARJA,
      TI.TAXBASE
    )                         COL06,--TAXBASE                NUMBER(22,4)
    Coalesce(
      TI.TAXBASEDESCRIPTION,
      TID.TAXBASEDESCRIPTION,
      TIP.TAXBASEDESCRIPTION,
      TI5.TAXBASEDESCRIPTION,
      TIT.TAXBASEDESCRIPTION,
      TI14.TAXBASEDESCRIPTION,
      TI35.TAXBASEDESCRIPTION
    )                         COL07,--TAXBASEDESCRIPTION     NVARCHAR2(70)
    Coalesce(C31b.CODSAF, 99) COL08,--CODTAXAMOUNTSAF_AMOUNT NUMBER(20)
    TI.TAXEXEMPTIONREASON     COL09,--TAXEXEMPTIONREASON     NVARCHAR2(70)
    TI.TAXDECLARATIONPERIOD   COL10 --TAXDECLARATIONPERIOD   NVARCHAR2(35)
  FROM TMP_SAFT29 S29
    LEFT JOIN TMP_SAFT_CODSAF     C31a ON C31a.CODSAF = Coalesce(S29.COL11, S29.COL12)
    LEFT JOIN TMP_SAFT_JURNAL     J    ON J.CODJURNAL = C31a.CODSURSA
    LEFT JOIN TMP_SAFT_NCONT      CD   ON CD.CODCONT  = J.CONTD
    LEFT JOIN TMP_SAFT_NCONT      CC   ON CC.CODCONT  = J.CONTC
    LEFT JOIN TMP_SAFT_CC4426     TSC  ON TSC.CodCont = J.CONTC
    LEFT JOIN TMP_SAFT_TAXINFO    TI   ON TI.TIPDOC   = J.TIPDOC
                                      AND CASE
                                            WHEN J.TIPDOC = 29 THEN J.INDEXLOCAL
                                            WHEN J.TIPDOC = 81 THEN J.CODJURNAL
                                            ELSE                    J.CODDOC
                                          END = TI.CODDOC
                                      AND CASE
                                            WHEN J.TIPDOC = 81 AND J.CODDOC = 1 AND C31a.CodSAFTTab = 3101 THEN TI.CODCONT
                                            WHEN J.TIPDOC = 81 AND J.CODDOC = 2 AND C31a.CodSAFTTab = 3102 THEN TI.CODCONT
                                            WHEN                                    C31a.CodSAFTTab = 3101 THEN J.CONTD
                                            ELSE                                                                J.CONTC
                                          END = Coalesce(TI.CODCONTDED, TI.CODCONT)
                                      -- urmatoarele linii sunt pentru cazul TvaDeductibil care se duce pe credit 4426
                                      -- mai putin cazul tipdoc = 32 Nota de inchidere TVA - ca se strica ticketul 54924
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE TI.CODCONTDED END =
                                          CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE J.CONTC       END
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE TI.CODCONT    END =
                                          CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN 0                        ELSE J.CONTD       END
                                      AND CASE WHEN J.TIPDOC = 32 THEN 0 WHEN TI.CODCONTDED IS NULL THEN J.CONTC                  ELSE 0             END &lt;&gt;
                                          CASE WHEN J.TIPDOC = 32 THEN 1 WHEN TI.CODCONTDED IS NULL THEN Coalesce(TSC.CodCont, 0) ELSE 1             END
                                      AND J.EXCL_TAXINFO = 0
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CHEIE_CODCONTDED, CHEIE_CODCONTCOL, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
    )                             TID  ON TID.TIPDOC   = J.TIPDOC AND TID.CODDOC  = J.CODDOC AND TID.CHEIE_CODCONTDED = J.CONTD AND TID.CHEIE_CODCONTCOL = J.CONTC
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CHEIE_CODCONTDED, CHEIE_CODCONTCOL, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
    )                             TIP  ON TIP.TIPDOC   = J.TIPDOC AND TIP.CODDOC  = J.CODDOC AND TIP.CHEIE_CODCONTCOL = J.CONTC AND S29.COL04 IN (&apos;4426&apos;)
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONTDED, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 5
    )                             TI5  ON TI5.TIPDOC   = J.TIPDOC AND TI5.CODDOC  = J.CODDOC AND TI5.CODCONTDED       = J.CONTD
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 14
    )                             TI14 ON TI14.TIPDOC  = J.TIPDOC AND TI14.CODDOC = J.CODDOC AND TI14.CODCONT         = J.CONTD AND CC.CodSAFT IN (&apos;4427&apos;)
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TIPDOC = 35
    )                             TI35 ON TI35.TIPDOC  = J.TIPDOC AND TI35.CODDOC = J.CODDOC AND TI35.CODCONT         = J.CONTD AND CC.CodSAFT IN (&apos;4426&apos;)
    LEFT JOIN INTRARI             INTT ON INTT.CODINTR = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 1 AND TI.TAXTYPE IS NULL
    LEFT JOIN IESIRI              IEST ON IEST.CODIES  = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 2 AND TI.TAXTYPE IS NULL
    LEFT JOIN (
      SELECT DISTINCT TIPDOC, CODDOC, TAXTYPE, TAXCODE, TAXBASEDESCRIPTION
      FROM TMP_SAFT_TAXINFO
      WHERE TAXBASE &lt;&gt; 0
    )                             TIT  ON TIT.TIPDOC   = Coalesce(INTT.TIPDOC, IEST.TIPDOC) AND TIT.CODDOC   = J.INDEXLOCAL
    LEFT JOIN IESIRI              IES  ON IES.CODIES   = J.INDEXLOCAL AND IES.TIPDOC = J.TIPDOC
    LEFT JOIN TMP_SAFT_TAXINFO_MP MTI  ON MTI.CODTI    = TI.CODTI AND MTI.CODCONT = J.CONTD
    LEFT JOIN TMP_SAFT_CODSAF     C31b ON C31b.CodSAFTTab IN (3103, 3104) AND C31b.CodSursa  = C31a.CodSursa AND C31b.CodParinte = C31a.CODSAF AND C31b.CODAUX = TI.CODTI
                                      AND Coalesce(MTI.IDXLOCAL, 0) = Coalesce(C31b.IDXAUX, 0);
  PUT_INFO(&apos;32.Z&apos;,&apos;UMPLE_T32--SAF_TAXINFORMATION&apos;);
END;

PROCEDURE UMPLE_T33 IS --SAF_SALESINVOICES
BEGIN
  INSERT INTO TMP_SAFT33
  SELECT
    33   COL01,--CODSAF_SALESINVOICES NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES      NUMBER(20)
    NULL COL03,--TOTALDEBIT           NUMBER(18,2)
    NULL COL04,--TOTALCREDIT          NUMBER(18,2)
    NULL COL05 --DETSAF_INVOICE       NUMBER(20)
  FROM DUAL;
END;

PROCEDURE UMPLE_T46 IS --SAF_PURCHASEINVOICES
BEGIN
  INSERT INTO TMP_SAFT46
  SELECT
    46   COL01,--CODSAF_PURCHASEINVOICES NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES         NUMBER(20)
    NULL COL03,--TOTALDEBIT              NUMBER(18,2)
    NULL COL04,--TOTALCREDIT             NUMBER(18,2)
    NULL COL05 --DETSAF_INVOICE          NUMBER(20)
  FROM DUAL;
END;

PROCEDURE UMPLE_T47 IS --SAF_PAYMENTS
BEGIN
  INSERT INTO TMP_SAFT47
  SELECT
    47   COL01,--CODSAF_PAYMENTS NUMBER(20)
    NULL COL02,--NUMBEROFENTRIES NUMBER(20)
    NULL COL03,--TOTALDEBIT      NUMBER(18,2)
    NULL COL04,--TOTALCREDIT     NUMBER(18,2)
    NULL COL05 --DETSAF_PAYMENT  NUMBER(20)
  FROM DUAL;
END;

PROCEDURE UMPLE_T52 IS --SAF_MOVEMENTOFGOODS
BEGIN
  PUT_INFO(&apos;52.A&apos;,&apos;UMPLE_T52--SAF_MOVEMENTOFGOODS&apos;);
  INSERT INTO TMP_SAFT52
  SELECT
    COL01,--CODSAF_MOVEMENTOFGOODS NUMBER(20)
    COL02,--NUMBEROFMOVEMENTLINES  NUMBER(20)
    COL03,--TOTALQUANTITYRECEIVED  NUMBER(22,6)
    COL04,--TOTALQUANTITYISSUED    NUMBER(22,6)
    COL05 --DETSAF_STOCKMOVEMENT   NUMBER(20)
  FROM (
    SELECT
      52 AS COL01,
      Sum(LINES_COUNT) COL02,
      Sum(CASE WHEN TAB = &apos;N&apos; THEN LINES_SUM ELSE 0 END) COL03,
      Sum(CASE WHEN TAB = &apos;L&apos; THEN LINES_SUM ELSE 0 END) COL04,
      Count(1) COL05
    FROM TMP_SAFT_STOCKMOVEMENT
  ) subs;
END;

PROCEDURE UMPLE_T53 IS --SAF_STOCKMOVEMENT
BEGIN
  PUT_INFO(&apos;53.A&apos;,&apos;UMPLE_T53--SAF_STOCKMOVEMENT&apos;);
  INSERT INTO TMP_SAFT53
  SELECT
    CODSAF                 COL01,--CODSAF_STOCKMOVEMENT     NUMBER(20)
    52                     COL02,--CODSAF_MASTER            NUMBER(20)
    TAB||&apos;.&apos;||
    To_Char(TIPDOC)||&apos;.&apos;||
    To_Char(CODDOC)        COL03,--MOVEMENTREFERENCE        NVARCHAR2(35)
    DATADOC                COL04,--MOVEMENTDATE             DATE
    NULL                   COL05,--MOVEMENTPOSTINGDATE      DATE
    NULL                   COL06,--MOVEMENTPOSTINGTIME      DATE
    NULL                   COL07,--TAXPOINTDATE             DATE
    MOVEMENTTYPE           COL08,--MOVEMENTTYPE             NVARCHAR2(9)
    NULL                   COL09,--SOURCEID                 NVARCHAR2(35)
    NULL                   COL10,--SYSTEMID                 NVARCHAR2(35)
    0                      COL11,--DETSAF_DOCUMENTREFERENCE NUMBER(20)
    1                      COL12 --DETSAF_STOCKMOVEMENTLINE NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT;
END;

PROCEDURE UMPLE_T54 IS --SAF_DOCUMENTREFERENCE
BEGIN
--  INSERT INTO TMP_SAFT54
--  SELECT
--    CAST(NULL AS NUMBER(20)   ) COL01,--CODSAF_DOCUMENTREFERENCE NUMBER(20)
--    CAST(NULL AS NUMBER(20)   ) COL02,--CODSAF_MASTER            NUMBER(20)
--    CAST(NULL AS NVARCHAR2(18)) COL03,--DOCUMENTTYPE             NVARCHAR2(18)
--    CAST(NULL AS NVARCHAR2(35)) COL04,--DOCUMENTNUMBER           NVARCHAR2(35)
--    CAST(NULL AS NVARCHAR2(18)) COL05 --DOCUMENTLINE             NVARCHAR2(18)
--  FROM DUAL;
  NULL;
END;

PROCEDURE UMPLE_T55 IS --SAF_STOCKMOVEMENTLINE
  v_ALFin  NUMBER(5);
  sFirmaID VARCHAR2(35);
  vSubunit NUMBER(20);
BEGIN
  PUT_INFO(&apos;55.A&apos;,&apos;UMPLE_T55--SAF_STOCKMOVEMENTLINE&apos;);
  SELECT CODSUBUNIT, ANFIN*12+LUNAFIN  INTO vSubunit, v_ALFin FROM TMP_SAFT_PARAMS;
  IF vSubunit = 1
  THEN SELECT &apos;00&apos;||REGEXP_REPLACE(F.CODFISCAL,&apos;\D+&apos;,&apos;&apos;) INTO sFirmaID FROM TMP_SAFT_PARAMS SP INNER JOIN WINMADMIN.FIRMA F ON F.CODFIRMA   = SP.CODFIRMA;
  ELSE SELECT &apos;00&apos;||REGEXP_REPLACE(S.CIF,&apos;\D+&apos;,&apos;&apos;)       INTO sFirmaID FROM TMP_SAFT_PARAMS SP INNER JOIN NSUBUNIT        S ON S.CODSUBUNIT = SP.CODSUBUNIT;
  END IF;

  INSERT INTO TMP_SAFT55
  SELECT
    SEQ_SAFT.NEXTVAL          COL01,--CODSAF_STOCKMOVEMENTLINE              NUMBER(20)
    T.CODSAF                  COL02,--CODSAF_MASTER                         NUMBER(20)
    L1.CODLIVR1               COL03,--LINENUMBER                            NVARCHAR2(18)
    C.CODSAFT                 COL04,--ACCOUNTID                             NVARCHAR2(70)
    NULL                      COL05,--TRANSACTIONID                         NVARCHAR2(70)
    Coalesce(PD.PARTID, &apos;0&apos;)  COL06,--CUSTOMERID                            NVARCHAR2(35)
    &apos;0&apos;                       COL07,--SUPPLIERID                            NVARCHAR2(35)
    NULL                      COL08,--CODSHIPTOSAF_SHIPPINGPOINT            NUMBER(20)
    NULL                      COL09,--CODSHIPFROMSAF_SHIPPINGPOINT          NUMBER(20)
    To_Char(O.CodObiect)      COL10,--PRODUCTCODE                           NVARCHAR2(70)
    NULL                      COL11,--STOCKACCOUNTNO                        NVARCHAR2(70)
    L1.CANT                   COL12,--QUANTITY                              NUMBER(22,6)
    SUBSTR(UMS.CODSAFT, 1, 9) COL13,--UNITOFMEASURE                         NVARCHAR2(9)
    U.PARITATEUMSAFT          COL14,--UOMTOUOMPHYSICALSTOCKCONVERSIONFACTOR NUMBER(22,7)
    NULL                      COL15,--BOOKVALUE                             NUMBER(18,2)
    MOVEMENTTYPE              COL16,--MOVEMENTSUBTYPE                       NVARCHAR2(9)
    NULL                      COL17,--MOVEMENTCOMMENTS                      NVARCHAR2(256)
    0                         COL18 --DETSAF_TAXINFORMATION                 NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT T
    LEFT JOIN TMP_SAFT_NPARTDET      PD  ON PD.CODPART    = T.CODPART
    LEFT JOIN LIVR1                  L1  ON L1.CODLIVR    = T.CODDOC
    LEFT JOIN NIRSTOC                NS  ON NS.CodNirStoc = L1.CodNirStoc
    LEFT JOIN LIVRVAL                LV  ON LV.CodLivr1   = L1.CodLivr1
    LEFT JOIN IOART1                 IO1 ON IO1.CodIOArt  = Coalesce(lv.codioart, ns.codioart) AND v_ALFin BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT         C   ON C.CODCONT     = IO1.CONT
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = Coalesce(lv.codobiect, ns.codobiect)
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
  WHERE T.TAB = &apos;L&apos;;

  INSERT INTO TMP_SAFT55
  SELECT
    SEQ_SAFT.NEXTVAL          COL01,--CODSAF_STOCKMOVEMENTLINE              NUMBER(20)
    T.CODSAF                  COL02,--CODSAF_MASTER                         NUMBER(20)
    NS.CODNIRSTOC             COL03,--LINENUMBER                            NVARCHAR2(18)
    C.CODSAFT                 COL04,--ACCOUNTID                             NVARCHAR2(70)
    NULL                      COL05,--TRANSACTIONID                         NVARCHAR2(70)
    &apos;0&apos;                       COL06,--CUSTOMERID                            NVARCHAR2(35)
    Coalesce(PD.PARTID, &apos;0&apos;)  COL07,--SUPPLIERID                            NVARCHAR2(35)
    NULL                      COL08,--CODSHIPTOSAF_SHIPPINGPOINT            NUMBER(20)
    NULL                      COL09,--CODSHIPFROMSAF_SHIPPINGPOINT          NUMBER(20)
    To_Char(O.CodObiect)      COL10,--PRODUCTCODE                           NVARCHAR2(70)
    NULL                      COL11,--STOCKACCOUNTNO                        NVARCHAR2(70)
    NS.CANTNIR                COL12,--QUANTITY                              NUMBER(22,6)
    SUBSTR(UMS.CODSAFT, 1, 9) COL13,--UNITOFMEASURE                         NVARCHAR2(9)
    U.PARITATEUMSAFT          COL14,--UOMTOUOMPHYSICALSTOCKCONVERSIONFACTOR NUMBER(22,7)
    NULL                      COL15,--BOOKVALUE                             NUMBER(18,2)
    MOVEMENTTYPE              COL16,--MOVEMENTSUBTYPE                       NVARCHAR2(9)
    NULL                      COL17,--MOVEMENTCOMMENTS                      NVARCHAR2(256)
    0                         COL18 --DETSAF_TAXINFORMATION                 NUMBER(20)
  FROM TMP_SAFT_STOCKMOVEMENT T
    LEFT JOIN TMP_SAFT_NPARTDET      PD  ON PD.CODPART    = T.CODPART
    LEFT JOIN NIRSTOC                NS  ON NS.CodNir     = T.Coddoc
    LEFT JOIN IOART1                 IO1 ON IO1.CodIOArt  = ns.codioart AND v_ALFin BETWEEN IO1.ALSTART AND IO1.ALSTOP
    LEFT JOIN TMP_SAFT_NCONT         C   ON C.CODCONT     = IO1.CONT
    LEFT JOIN NARTOBJ                O   ON O.CODOBIECT   = ns.codobiect
    LEFT JOIN NART                   A   ON A.CODARTICOL  = O.CODARTICOL
    LEFT JOIN WINMADMIN.INTRASTAT_NC CN8 ON CN8.CN        = Trim(O.CODVAMAL)
    LEFT JOIN NUM                    U   ON U.CODUM       = A.UM
    LEFT JOIN WINMADMIN.NUMSAFT      UMS ON UMS.CODUMSAFT = U.CODUMSAFT
  WHERE T.TAB = &apos;N&apos;;

  UPDATE TMP_SAFT55
  SET    COL06 = sFirmaID,    COL07 = sFirmaID
  WHERE (COL06 = &apos;0&apos;      AND COL07 = &apos;0&apos;     ) OR
        (COL06 = &apos;0&apos;      AND COL07 = sFirmaID) OR
        (COL06 = sFirmaID AND COL07 = &apos;0&apos;     );

  UPDATE TMP_SAFT53 S53 SET COL12 = (SELECT Count(1) FROM TMP_SAFT55 S55 WHERE S55.COL02 = S53.COL01);
END;

PROCEDURE UMPLE_T56 IS --SAF_ASSETTRANSACTIONS
BEGIN
  INSERT INTO TMP_SAFT56
  SELECT
    56             COL01,--CODSAF_ASSETTRANSACTIONS  NUMBER(20)
    Count(1)       COL02,--NUMBEROFASSETTRANSACTIONS NUMBER(20)
    Count(1)       COL03 --7   NUMBER(20)
  FROM TMP_SAFT_CODSAF C57
  WHERE C57.CodSAFTTab = 57
  GROUP BY C57.CodSAFTTab;
END;

PROCEDURE UMPLE_T57 IS --SAF_ASSETTRANSACTION
BEGIN
  INSERT INTO TMP_SAFT57
  SELECT
    C57.CODSAF                                      COL01,--CODSAF_ASSETTRANSACTION           NUMBER(20)
    56                                              COL02,--CODSAF_MASTER                     NUMBER(20)
    To_Char(J1.CodJurnal1,&apos;fm00000000000000000000&apos;) COL03,--ASSETTRANSACTIONID                NVARCHAR2(70)
    M.NRINVENTAR                                    COL04,--ASSETID                           NVARCHAR2(35)
    J1.ASSETTRANSACTIONTYPE                         COL05,--ASSETTRANSACTIONTYPE              NVARCHAR2(9)
    CASE J1.ASSETTRANSACTIONTYPE
      WHEN  &apos;10&apos; THEN &apos;Achizitie&apos;
      WHEN  &apos;20&apos; THEN &apos;V?nzare&apos;
      WHEN  &apos;30&apos; THEN &apos;Amortizare&apos;
      WHEN  &apos;40&apos; THEN &apos;Transfer intern&apos;
      WHEN  &apos;50&apos; THEN &apos;Casare mijloace fixe&apos;
      WHEN  &apos;60&apos; THEN &apos;Reevaluare negativa&apos;
      WHEN  &apos;70&apos; THEN &apos;Reevaluare pozitiva&apos;
      WHEN  &apos;80&apos; THEN &apos;Plus de inventar&apos;
      WHEN  &apos;90&apos; THEN &apos;Minus de inventar&apos;
      WHEN &apos;100&apos; THEN &apos;Ajustare de valoare negativa&apos;
      WHEN &apos;110&apos; THEN &apos;Reversare ajustare de valoare&apos;
      WHEN &apos;120&apos; THEN &apos;Bunuri acordate cu titlu gratuit&apos;
      ELSE            &apos;Alte tranzaciii&apos;
    END                                             COL06,--DESCRIPTION                       NVARCHAR2(256)
    J1.DATADOC                                      COL07,--ASSETTRANSACTIONDATE              DATE
    C23.CODSAF                                      COL08,--CODSAF_ASSETSUPPLIER              NUMBER(20)
    To_Char(J1.CodJurnal1,&apos;fm00000000000000000000&apos;) COL09,--TRANSACTIONID                     NVARCHAR2(70)
    C61.CODSAF                                      COL10 --CODSAF_ASSETTRANSACTIONVALUATIONS NUMBER(20)
  FROM TMP_SAFT_CODSAF C57
    LEFT  JOIN TMP_SAFT_CODSAF  C61 ON C61.CODPARINTE = C57.CODSAF           AND C61.CODSAFTTAB = 61
    INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSAF     = C57.CODPARINTE
    LEFT  JOIN TMP_SAFT_JURNAL1 J1  ON J1.CODJURNAL1  = C57.CODSURSA         AND J1.CODMIFIX1   = C57.CODAUX AND J1.CODMIFIX = C22.CODSURSA
    LEFT  JOIN MIFIX1           M1  ON M1.CODMIFIX1   = C57.CODAUX
    LEFT  JOIN MIFIX            M   ON M.CODMIFIX     = J1.CODMIFIX
    LEFT  JOIN NIRSTOC          NS  ON NS.CODNIRSTOC  = M1.CODNIRSTOC
    LEFT  JOIN TMP_SAFT_CODSAF  C23 ON C23.CODSURSA   = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
  WHERE C57.CodSAFTTab = 57
  ORDER BY C57.CODSAF ASC;
END;

PROCEDURE UMPLE_T61 IS --SAF_ASSETTRANSACTIONVALUATIONS
BEGIN
  INSERT INTO TMP_SAFT61
  SELECT
    C58.CODPARINTE COL01,--CODSAF_ASSETTRANSACTIONVALUATIONS NUMBER(20)
    Count(1)       COL02 --DETSAF_ASSETTRANSACTIONVALUATION  NUMBER(20)
  FROM TMP_SAFT_CODSAF C58
  WHERE C58.CodSAFTTab = 58
  GROUP BY C58.CODPARINTE;
END;

PROCEDURE UMPLE_T58 IS --SAF_ASSETTRANSACTIONVALUATION
BEGIN
  INSERT INTO TMP_SAFT58
  SELECT
    C58.CODSAF                  COL01,--CODSAF_ASSETTRANSACTIONVALUATION           NUMBER(20)
    C58.CODPARINTE              COL02,--CODSAF_MASTER                              NVARCHAR2(18)
    NULL                        COL03,--ASSETVALUATIONTYPE                         NVARCHAR2(18)
    CASE
      WHEN Coalesce(NS.CANTNIR, 0) = 0 AND
           J1.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)       THEN J1.VALOARE / NS.CANTNIR
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (6,7)                     THEN J1.VALOARE
      WHEN J1.TIPDOC IN (13)                       THEN J1.VALOARE
      --WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;60&apos;, &apos;70&apos;) THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;80&apos;)       THEN J1.VALOARE
      WHEN J1.TIPDOC IN (15)           AND
           J1.TIPTRANZACTIE = 5                    THEN J1.VALOARE
      ELSE                                              0
    END                         COL04,--ACQUISITIONANDPRODUCTIONCOSTSONTRANSACTION NUMBER(18,2)
    CASE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;20&apos;)       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;30&apos;)       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (6,7,13,15)               THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (23)                      THEN - M1.PRET
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (12) AND
        (
         SELECT Count(*)
         FROM TMP_SAFT_JURNAL1
         WHERE CODMIFIX1 = M1.CODMIFIX1
         GROUP BY CODMIFIX1
         ) &gt; 1                                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (12)                      THEN - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;50&apos;)       THEN - J1.VALOARE
      WHEN Coalesce(NS.CANTNIR, 0) = 0             THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;60&apos;)       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;70&apos;)       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;100&apos;)      THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;110&apos;)      THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;130&apos;)
        AND J1.TIPDOC IN (35)                      THEN - J1.VALOARE
      ELSE J1.VALOARE / NS.CANTNIR
    END                         COL05,--BOOKVALUEONTRANSACTION                     NUMBER(18,2)
    CASE
      WHEN Coalesce(NS.CANTNIR, 0) = 0 AND
           J1.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)       THEN J1.VALOARE / NS.CANTNIR
      --WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;10&apos;)       THEN Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;20&apos;)       THEN J1.VALOARE - Coalesce(M1.PRET, 0) + Coalesce(M1.AMO,  0)
      WHEN J1.TIPDOC IN (13)                       THEN J1.VALOARE
      WHEN J1.TIPDOC IN (15)           AND
           J1.TIPTRANZACTIE = 5                    THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;30&apos;)       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (6,7)                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (23)                      THEN - M1.PRET
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (12) AND
        (
         SELECT Count(*)
         FROM TMP_SAFT_JURNAL1
         WHERE CODMIFIX1 = M1.CODMIFIX1
         GROUP BY CODMIFIX1
         ) &gt; 1                                     THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)
        AND J1.TIPDOC IN (12)                      THEN - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;40&apos;)       THEN Coalesce(M1.AMO,  0) - Coalesce(M1.PRET, 0)
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;50&apos;)       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;60&apos;)       THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;70&apos;)       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;80&apos;)       THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;100&apos;)      THEN - J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;110&apos;)      THEN J1.VALOARE
      WHEN J1.ICONTD = 10             AND
           J1.ICONTC = 0                           THEN J1.VALOARE
      WHEN J1.ASSETTRANSACTIONTYPE IN (&apos;130&apos;)
        AND J1.TIPDOC IN (35)                      THEN - J1.VALOARE
      ELSE                                              0
    END                         COL06 --ASSETTRANSACTIONAMOUNT                     NUMBER(18,2)
  FROM TMP_SAFT_CODSAF C58
    INNER JOIN TMP_SAFT_CODSAF  C61 ON C61.CODSAF    = C58.CODPARINTE
    INNER JOIN TMP_SAFT_CODSAF  C57 ON C57.CODSAF    = C61.CODPARINTE
    INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSAF    = C57.CODPARINTE
    LEFT  JOIN TMP_SAFT_JURNAL1 J1  ON J1.CODJURNAL1 = C58.CODSURSA          AND J1.CODMIFIX1   = C58.CODAUX AND J1.CODMIFIX = C22.CODSURSA
    LEFT  JOIN MIFIX1           M1  ON M1.CODMIFIX1  = C58.CODAUX
    LEFT  JOIN MIFIX            M   ON M.CODMIFIX    = J1.CODMIFIX
    LEFT  JOIN NIRSTOC          NS  ON NS.CODNIRSTOC = M1.CODNIRSTOC
    LEFT  JOIN TMP_SAFT_CODSAF  C23 ON C23.CODSURSA  = Coalesce(NS.FURN, 0) AND C23.CodSAFTTab = 23
  WHERE C58.CodSAFTTab = 58
  ORDER BY C58.CODPARINTE ASC;
END;

PROCEDURE UMPLE_NPARTDET(pALStart NUMBER, pALStop NUMBER, bSaft BOOLEAN DEFAULT FALSE ) IS
  bCNPPersFiz BOOLEAN  := Coalesce(pkg_categconst.GetValConstanta(&apos;SAFTCodPartPersFiz&apos;,0,pALStop), &apos;2&apos;) = &apos;2&apos;;
BEGIN
  IF bSaft THEN
    INSERT INTO TMP_SAFT_NPARTDET (
      CODPART,
      PERSFIZICA, COD_CODFISCAL, CODFISCAL,
      STATCOMUNITAR, SIMBTARA
    )
    SELECT
      P.CODPART,
      Coalesce(P.PERSOANAFIZICA, 0) AS PERSFIZICA, PCF.COD_CODFISCAL, Upper(REPLACE(PCF.CODFISCAL, &apos; &apos;, &apos;&apos;)),
      Coalesce(T.STATCOMUNITAR, 0) AS STATCOMUNITAR, Coalesce(Upper(T.SIMBAUTO), &apos;X&apos;) SimbTara
    FROM (
      SELECT DISTINCT CODPART FROM TMP_SAFT_NPART
    ) TSP
      LEFT JOIN NPART        P   ON P.CODPART    = TSP.CODPART
      LEFT JOIN NPARTCODFISC PCF ON PCF.CODPART  = P.CODPART AND PCF.PRINCIPAL = 1
      LEFT JOIN NAGENDA      A   ON A.CODPART    = P.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NTARI        T   ON T.CODTARA    = L.CODTARA;
  ELSE
    INSERT INTO TMP_SAFT_NPARTDET (
      CODPART,
      PERSFIZICA, COD_CODFISCAL, CODFISCAL,
      STATCOMUNITAR, SIMBTARA
    )
    SELECT
      P.CODPART,
      Coalesce(P.PERSOANAFIZICA, 0) AS PERSFIZICA, PCF.COD_CODFISCAL, Upper(REPLACE(PCF.CODFISCAL, &apos; &apos;, &apos;&apos;)),
      Coalesce(T.STATCOMUNITAR, 0) AS STATCOMUNITAR, Coalesce(Upper(T.SIMBAUTO), &apos;X&apos;) SimbTara
    FROM NPART P
      LEFT JOIN NPARTCODFISC PCF ON PCF.CODPART  = P.CODPART AND PCF.PRINCIPAL = 1
      LEFT JOIN NAGENDA      A   ON A.CODPART    = P.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
      LEFT JOIN NLOCALIT     L   ON L.CODLOCALIT = A.CODLOCALIT
      LEFT JOIN NTARI        T   ON T.CODTARA    = L.CODTARA;
  END IF;

  UPDATE TMP_SAFT_NPARTDET -- daca codul fiscal pare cnp -&gt; PersoanaFizica
  SET PERSFIZICA = 1
  WHERE PERSFIZICA = 0 AND Length(CODFISCAL) = 13 AND REGEXP_REPLACE(CODFISCAL,&apos;\D+&apos;,&apos;&apos;) = CODFISCAL;

  IF NOT bCNPPersFiz THEN
    UPDATE TMP_SAFT_NPARTDET SET COD_CODFISCAL = NULL, CODFISCAL = NULL WHERE PERSFIZICA = 1;
  END IF;

  UPDATE TMP_SAFT_NPARTDET
  SET CODFISCAL = SubStr(CODFISCAL, 3)
  WHERE Length(SimbTara) = 2 AND SubStr(CODFISCAL, 1, 2) = SimbTara;

  UPDATE TMP_SAFT_NPARTDET
  SET CODFISCAL = SubStr(CODFISCAL, 3), SimbTara = SubStr(CODFISCAL, 1, 2)
  WHERE SubStr(CODFISCAL, 1, 2) IN (&apos;AT&apos;, &apos;BE&apos;, &apos;BG&apos;, &apos;CY&apos;, &apos;CZ&apos;, &apos;DE&apos;, &apos;DK&apos;, &apos;EE&apos;, &apos;EL&apos;, &apos;ES&apos;, &apos;FI&apos;, &apos;FR&apos;, &apos;HR&apos;, &apos;HU&apos;, &apos;IE&apos;, &apos;IT&apos;, &apos;LT&apos;, &apos;LU&apos;, &apos;LV&apos;, &apos;MT&apos;, &apos;NL&apos;, &apos;PL&apos;, &apos;PT&apos;, &apos;RO&apos;, &apos;SE&apos;, &apos;SI&apos;, &apos;SK&apos;);

  UPDATE TMP_SAFT_NPARTDET
  SET StatComunitar = 1
  WHERE SimbTara IN (&apos;AT&apos;, &apos;BE&apos;, &apos;BG&apos;, &apos;CY&apos;, &apos;CZ&apos;, &apos;DE&apos;, &apos;DK&apos;, &apos;EE&apos;, &apos;EL&apos;, &apos;ES&apos;, &apos;FI&apos;, &apos;FR&apos;, &apos;HR&apos;, &apos;HU&apos;, &apos;IE&apos;, &apos;IT&apos;, &apos;LT&apos;, &apos;LU&apos;, &apos;LV&apos;, &apos;MT&apos;, &apos;NL&apos;, &apos;PL&apos;, &apos;PT&apos;, &apos;RO&apos;, &apos;SE&apos;, &apos;SI&apos;, &apos;SK&apos;);

  UPDATE TMP_SAFT_NPARTDET SET CODFISCAL = REGEXP_REPLACE(CODFISCAL,&apos;\D+&apos;,&apos;&apos;) WHERE SimbTara = &apos;RO&apos;;

  UPDATE TMP_SAFT_NPARTDET SET COD_CODFISCAL = NULL WHERE CODFISCAL IS NULL;

  UPDATE TMP_SAFT_NPARTDET
  SET PartID = CASE
                 WHEN SimbTara = &apos;RO&apos;   AND PersFizica &lt;&gt; 1       THEN &apos;00&apos;||          Coalesce(CodFiscal,&apos;&apos;)
                 WHEN SimbTara = &apos;RO&apos;   AND CodFiscal IS NOT NULL THEN &apos;03&apos;||          Coalesce(CodFiscal,&apos;&apos;)
                 WHEN SimbTara = &apos;RO&apos;                             THEN &apos;04&apos;||          To_Char(CodPart)
                 WHEN StatComunitar = 1 AND CodFiscal IS NOT NULL THEN &apos;01&apos;||SimbTara||Coalesce(CodFiscal,&apos;&apos;)
                 WHEN StatComunitar = 1                           THEN &apos;05&apos;||SimbTara||To_Char(CodPart)
                 WHEN                       CodFiscal IS NOT NULL THEN &apos;02&apos;||SimbTara||Coalesce(CodFiscal,&apos;&apos;)
                                                                  ELSE &apos;06&apos;||SimbTara||To_Char(CodPart)
               END;
END;

PROCEDURE UMPLE_MANEVRA_CONT_FROM_CONST (pConst IN VARCHAR2, pAn NUMBER, pLuna NUMBER) IS
  cValConst CLOB;
  vAL       NUMBER(5) := pAn*12+pLuna;
BEGIN
  cValConst := Coalesce(PKG_CATEGCONST.GetValConstanta(pConst, pAn,pLuna), &apos;-1&apos;);
  DELETE FROM TMP_SAFT_MANEVRA WHERE FILTRU = pConst AND AL = vAL;
  EXECUTE IMMEDIATE
  &apos;INSERT INTO TMP_SAFT_MANEVRA (FILTRU, AL, CODUNIC)
  WITH /*RECURSIVE*/ tmpc (CODCONT) AS (
    SELECT codcont   FROM ncont WHERE codcont IN (&apos;||cValConst||&apos;) AND codcont &lt;&gt; 0 UNION ALL
    SELECT c.codcont FROM tmpc INNER JOIN ncont c ON c.codparinte = tmpc.codcont
  )
  SELECT :pConst, :vAL, codcont
  FROM (SELECT DISTINCT codcont FROM tmpc)&apos;
  USING pConst, vAL;
  COMMIT;
END;

PROCEDURE BEGIN_SAFT(pTip NUMBER, pAn NUMBER, pLuna NUMBER, pSubunit INTEGER DEFAULT 1) IS
  vAnIni             NUMBER(4):= pAn;
  vLunaIni           NUMBER(2):= pLuna;
  vAnFin             NUMBER(4):= pAn;
  vLunaFin           NUMBER(2):= pLuna;
  v_ALIni            NUMBER(5);
  v_ALFin            NUMBER(5);
  vAnP               NUMBER(4);
  vLunaP             NUMBER(2);
  sHolding           VARCHAR2(10) := Coalesce(pkg_categconst.GetValConstanta(&apos;Holding&apos;                     ,pAn,pLuna),&apos;2&apos;);
  bHolding           BOOLEAN      := (&apos;1&apos; =  sHolding);
  bPartContact       BOOLEAN      := (&apos;2&apos; =  Coalesce(pkg_categconst.GetValConstanta(&apos;SAFTPartContact&apos;     ,pAn,pLuna),&apos;2&apos;));
  bPartBanca         BOOLEAN      := (&apos;2&apos; =  Coalesce(pkg_categconst.GetValConstanta(&apos;SAFTPartBanca&apos;       ,pAn,pLuna),&apos;2&apos;));
  vCodPersContact    NUMBER;
  vCodBankCont       NUMBER;
  vTipTVAMixt100     NUMBER       := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;TipTVAMixt100&apos;     ,pAn,pLuna),&apos;0&apos;));
  vCCheltTVADed      NUMBER       := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;CCheltTVADed&apos;      ,pAn,pLuna),&apos;0&apos;));
  vCIntermedMarja    NUMBER;
  vLSAC_CNT          NUMBER;
  vLSAC_C_Val        NUMBER;
  vLSAC_C_AL         NUMBER;
  vLSAC_P_Val        NUMBER;
  vLSAC_P_AL         NUMBER;
  cSQL               CLOB;
  vAnTMP             NUMBER(4);
  vLunaTMP           NUMBER(4);
  v_ALTMP            NUMBER(5);
  vCount             NUMBER;
  vCodFirma          NUMBER(20):= PKG_GLOBALS.GETCODFIRMA;
  vUserID            NUMBER(20):= PKG_GLOBALS.GETUSERID;
BEGIN
  pSaftDebug := FALSE;
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE SAFT_INFO&apos;;
  TRUNCATE_TABLES;
  RESET_SEQ;

  IF    pTip = 1/*(L)  Lunara                  */ OR
        pTip = 4/*(C)  La cerere               */ OR
        pTip = 5/*(NL) Nerezidenti lunar       */ THEN vLunaIni := vLunaFin;
  ELSIF pTip = 2/*(T)  Trimestriala            */ OR
        pTip = 6/*(NT) Nerezidenti trimestrial */ THEN vLunaIni := CASE WHEN vLunaFin &gt; 9 THEN 10 WHEN vLunaFin &gt; 6 THEN 7 WHEN vLunaFin &gt; 3 THEN 4 ELSE 1 END;
  ELSIF pTip = 3/*(A)  Anuala                  */ THEN vLunaIni := 1;
  ELSIF pTip = 7/*(A)  Anuala - Active         */ THEN
    SELECT
      Max(vIdx) Cnt,
      Max(CASE WHEN vIdx = 1 THEN valoare ELSE 0 END) Valoare_C,
      Max(CASE WHEN vIdx = 1 THEN alstart ELSE 0 END) ALStart_C,
      Max(CASE WHEN vIdx = 2 THEN valoare ELSE 0 END) Valoare_P,
      Max(CASE WHEN vIdx = 2 THEN alstart ELSE 0 END) AlStart_P
    INTO
      vLSAC_CNT,
      vLSAC_C_Val,
      vLSAC_C_AL,
      vLSAC_P_Val,
      vLSAC_P_AL
    FROM (
      SELECT Row_Number() over (ORDER BY cl.alstart DESC) vIDX, cl.alstart, cl.alstop, To_Number(cv.valoare) valoare
      FROM const1 c1
        LEFT JOIN constluna cl ON cl.codconst1 = c1.codconst1
        LEFT JOIN constval cv ON cv.codconstluna = cl.codconstluna
      WHERE Upper(simbol) = &apos;LUNASTARTANCONTAB&apos;
        AND cl.alstart &lt; pAn*12+pLuna
    ) ssub
    WHERE vIDX &lt;= 2;

    vLunaIni := vLSAC_C_Val;
    vAnIni   := pAn - CASE WHEN vLunaFin &lt; vLunaIni THEN 1 ELSE 0 END;

    -- daca se modifica LunaStartAnContab pe perioada care afecteaza declaratia se extinde intervalul
    IF (vLSAC_CNT &gt; 1) AND (vLSAC_C_Val &lt;&gt; vLSAC_P_Val) AND (vLSAC_C_AL BETWEEN v_ALIni-11 AND v_ALIni) THEN
      vAnIni   := vAnIni - CASE WHEN vLSAC_C_Val &lt; vLSAC_P_Val THEN 1 ELSE 0 END;
      vLunaIni := vLSAC_P_Val;
    END IF;
  END IF;
  v_ALIni := vAnIni*12+vLunaIni;
  v_ALFin := vAnFin*12+vLunaFin;

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(vAnIni, vLunaIni, vAnP, vLunaP);

  IF bHolding AND (pSubunit &lt;&gt; 1) THEN
    SELECT CODBANKCONT,  CODPERS
    INTO   vCodBankCont, vCodPersContact
    FROM   nsubunit
    WHERE  CODSUBUNIT = pSubunit;
  ELSE
    vCodPersContact := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;SAFTPersContactFirma&apos;,pAn,pLuna),&apos;0&apos;));
    vCodBankCont    := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;BancaImplicita&apos;      ,pAn,pLuna),&apos;0&apos;));
  END IF;

  INSERT INTO TMP_SAFT_PARAMS( CODFIRMA,  USERID,  TIP,  ANINI,  LUNAINI,  ANFIN,  LUNAFIN,  ANP,  LUNAP,  CODBANKCONT,  CODSUBUNIT, PERSCONTACT)
  VALUES                     (vCodFirma, vUserID, pTip, vAnIni, vLunaIni, vAnFin, vLunaFin, vAnP, vLunaP, vCodBankCont, pSubunit,   vCodPersContact);

  INSERT INTO TMP_SAFT_CC4426 SELECT CodCont FROM ncont WHERE CodSaft = &apos;4426&apos;;

  PUT_INFO(&apos;00.A01&apos;,&apos;BEGIN_SAFT--ActulizareCodSaftInNCont&apos;);
  ActulizareCodSaftInNCont;
  COMMIT;

  PUT_INFO(&apos;00.A11&apos;,&apos;BEGIN_SAFT--Completare TMP_SAFT_MANEVRA&apos;);
  UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CObInventar&apos;, vLunaFin,vLunaFin);
  UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CMifix&apos;,      vLunaFin,vLunaFin);
  UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CImbMifix&apos;,   vLunaFin,vLunaFin);
  UMPLE_MANEVRA_CONT_FROM_CONST(&apos;ProvMiFix&apos;,   vLunaFin,vLunaFin);

  IF pTip = 7 THEN -- Anuala - Active
    vAnTmp   := vAnIni;
    vLunaTmp := vLunaIni;
    v_ALTMP  := v_ALIni;
    PUT_INFO(&apos;00.B01&apos;,&apos;BEGIN_SAFT--TMP_SAFT_MIFIX1&apos;);
    WHILE v_ALTMP &lt;= v_ALFin
    LOOP
      UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CMifix&apos;,            vAnTmp,vLunaTMP);
      UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CCheltAmoMifixNC&apos;,  vAnTmp,vLunaTMP);
      UMPLE_MANEVRA_CONT_FROM_CONST(&apos;CRezRepAmoMifixNC&apos;, vAnTmp,vLunaTMP);
      INSERT INTO TMP_SAFT_MIFIX1(CODMIFIX1, CODMIFIX, AN, LUNA, CONT)
      SELECT M1.CODMIFIX1, M1.CODMIFIX, M1.ANSTART, M1.LUNASTART, I1.CONT
      FROM mifix1 m1
        INNER JOIN nirstoc      ns ON ns.codnirstoc = m1.codnirstoc
        INNER JOIN nir          n  ON n.codnir      = ns.codnir
        INNER JOIN ngest        ng ON ng.codgest    = n.gest
        INNER JOIN ioart1       i1 ON i1.codioart   = ns.codioart AND m1.anstart*12+m1.lunastart BETWEEN i1.alstart AND i1.alstop
        INNER JOIN (
          SELECT DISTINCT codunic FROM TMP_SAFT_MANEVRA WHERE FILTRU = &apos;CMifix&apos; AND AL = v_ALTMP
        )                       t2 ON t2.codunic    = i1.cont
      WHERE m1.anstart = vAnTmp AND m1.lunastart = vLunaTMP
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE NG.CODSUBUNIT END;

      INSERT INTO TMP_SAFT_MIFIX1(CODMIFIX1, CODMIFIX, AN, LUNA, CONT)
      SELECT M1.CODMIFIX1, M.CODMIFIX, M1.ANSTART, M1.LUNASTART, I1.CONT
      FROM mifix m
        INNER JOIN mifix1       m1 ON m1.codmifix   = m.codmifixnou
        INNER JOIN nirstoc      ns ON ns.codnirstoc = m1.codnirstoc
        INNER JOIN nir          n  ON n.codnir      = ns.codnir
        INNER JOIN ngest        ng ON ng.codgest    = n.gest
        INNER JOIN ioart1       i1 ON i1.codioart   = ns.codioart AND m1.anstart*12+m1.lunastart BETWEEN i1.alstart AND i1.alstop
        INNER JOIN (
          SELECT DISTINCT codunic FROM TMP_SAFT_MANEVRA WHERE FILTRU = &apos;CMifix&apos; AND AL = v_ALTMP
        )                       t2 ON t2.codunic    = i1.cont
      WHERE m1.anstart = vAnTmp AND m1.lunastart = vLunaTMP
        AND m.anlunamifixnou = vAnTmp*12+vLunaTMP
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE NG.CODSUBUNIT END;

      PKG_GLOBALS.CALCULEAZA_LUNA_URMATOARE(vAnTmp, vLunaTmp, vAnTmp, vLunaTmp);
      v_ALTMP := v_ALTMP + 1;
    END LOOP;

    PUT_INFO(&apos;00.B02&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - amortizari&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      INNER JOIN JURNAL1 J1 ON J1.AN        = TM1.AN
                           AND J1.LUNA      = TM1.LUNA
                           AND J1.TIPDOC    = 36
                           AND J1.CODDOC    = TM1.CODMIFIX
    WHERE (J1.ICONTD = 4 OR (J1.ICONTD = 10 AND J1.ICONTC = 0)) AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    PUT_INFO(&apos;00.B03&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - casare si reevaluare&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      INNER JOIN JURNAL1 J1 ON J1.AN        = TM1.AN
                           AND J1.LUNA      = TM1.LUNA
                           AND J1.TIPDOC    = 36
                           AND J1.CODDOC    = TM1.CODMIFIX
    WHERE ((J1.ICONTD = 0 AND J1.ICONTC = 2 AND NOT M1.STARE IN (4)) OR (J1.ICONTD IN (2) AND J1.ICONTC IN (0, 6))
      OR (J1.ICONTD IN (10) AND J1.ICONTC IN (2) AND J1.TIPDOC = 14)) AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    PUT_INFO(&apos;00.B04&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - note contabile corectie amortizari&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      DISTINCT J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1  ON M1.CODMIFIX1 = TM1.CODMIFIX1
      LEFT  JOIN NC1     NC1 ON NC1.MFSAFT   = M1.CODMIFIX
      LEFT  JOIN NC      NC  ON NC.CODNC     = NC1.CODNC
      INNER JOIN JURNAL1 J1  ON J1.AN        = TM1.AN        AND J1.LUNA = TM1.LUNA AND J1.TIPDOC = 35 AND J1.CODDOC = NC.CODNC AND J1.INDEXLOCAL = NC1.CODNC1
      INNER JOIN (
          SELECT DISTINCT codunic FROM TMP_SAFT_MANEVRA WHERE FILTRU IN ( &apos;CCheltAmoMifixNC&apos;, &apos;CRezRepAmoMifixNC&apos; )
      )                  T4  ON T4.CODUNIC   = J1.CODDESCRD
    WHERE Abs(J1.VALOARE) &gt;= 0.01 AND NOT T4.CODUNIC IS NULL
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    PUT_INFO(&apos;00.B05&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - ajustari negative de valoare&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN MIFIX1  M1    ON M1.CODMIFIX1  = TM1.CODMIFIX1
      LEFT JOIN NIRSTOC NS     ON NS.CODNIRSTOC = M1.CODNIRSTOC
      LEFT JOIN NIR   N        ON N.CODNIR      = NS.CODNIR
      LEFT JOIN TRANSF T       ON T.CODTRANSF   = N.CODTRANSF
      INNER JOIN JURNAL1 J1    ON  J1.TIPDOC    = T.TIPDOC
                               AND J1.CODDOC    = T.CODTRANSF
                               AND J1.AN        = TM1.AN
                               AND J1.LUNA      = TM1.LUNA
    WHERE J1.ICONTC = 23 AND Abs(J1.VALOARE) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    PUT_INFO(&apos;00.B06&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - intrari&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    WITH /*recursive*/ wm1 (CODMIFIX1, CODMIFIX, CODMIFIXNEW, ANSTART, LUNASTART, TIPREEVAL, CODNIRSTOC, CODNIRSTOCPARINTE) AS (  --pentru mai multe operatii facute IN aceeasi luna
      SELECT M1.CODMIFIX1, TM1.CODMIFIX, M1.CODMIFIX CODMIFIXNEW, M1.ANSTART, M1.LUNASTART, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM TMP_SAFT_MIFIX1 TM1
        INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1  = TM1.CODMIFIX1
        INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      UNION ALL
      SELECT wm1.CODMIFIX1, wm1.CODMIFIX, wm1.CODMIFIXNEW, wm1.ANSTART, wm1.LUNASTART,  wm1.TIPREEVAL, NS.CODNIRSTOC, NS.CODNIRSTOCPARINTE
      FROM wm1 INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = wm1.CODNIRSTOCPARINTE
    )
    SELECT
      J1.CODJURNAL1, WM1.CODMIFIX1, WM1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE*CASE WHEN J1.ICONTD = 2 THEN 1 ELSE -1 END*CASE WHEN wm1.CODMIFIX = wm1.CODMIFIXNEW THEN 1 ELSE -1 END  AS VALOARE,
      J1.DATADOC, WM1.TIPREEVAL, Coalesce(I.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      CASE WHEN Coalesce(I1.Cant, 0) &lt; 0 THEN -1 ELSE 1 END SEMN
    FROM wm1
      INNER JOIN MIFIX    M  ON M.CODMIFIX    = WM1.CODMIFIX
      INNER JOIN NIRSTOC  NS ON NS.CODNIRSTOC = WM1.CODNIRSTOC
      INNER JOIN NIR      N  ON N.CODNIR      = NS.CODNIR
      LEFT  JOIN INTRARI  I  ON I.CODINTR     = N.CODINTR
      LEFT  JOIN INTRARI1 I1 ON I1.CODINTR1   = NS.CODINTR1
      INNER JOIN JURNAL1  J1 ON J1.AN         = WM1.ANSTART
                            AND J1.LUNA       = WM1.LUNASTART
                            AND J1.TIPDOC     = N.TIPNIR
                            AND J1.CODDOC     = Coalesce(n.codintr,   n.codtransf,   n.codies)
                            AND J1.INDEXLOCAL = Coalesce(ns.codintr1, ns.codtransf1, ns.coddvi1)
    WHERE ((J1.ICONTD = 2 OR J1.ICONTC = 2) AND J1.ICONTD &lt;&gt; 3)
        AND Abs(J1.VALOARE) &gt;= 0.01
        AND (
              J1.TIPDOC &lt;&gt; 6
              OR
              (J1.TIPDOC = 6 AND WM1.CODMIFIX &lt;&gt; COALESCE(M.CODMIFIXNOU,0) AND COALESCE(M.CODMIFIXNOU,0) = 0)
            )
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J1.SUBUNITATEA END;

    PUT_INFO(&apos;00.B07&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - iesiri&apos;);
    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL, Coalesce(I.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      CASE WHEN Coalesce(I1.Cant, 0) &lt; 0 THEN -1 ELSE 1 END SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      LEFT JOIN MIFIX1  M1 ON M1.CODMIFIX1 = TM1.CODMIFIX1
      LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
      LEFT JOIN LIVR1   L1 ON L1.CODNIRSTOC = NS.CODNIRSTOC
      LEFT JOIN LIVR    L  ON L.CODLIVR     = L1.CODLIVR
      LEFT JOIN IESIRI  I  ON I.CODIES      = L.CODIES
      LEFT JOIN IESIRI1 I1 ON I1.CODIES1    = L1.CODIES1
      LEFT JOIN JURNAL1 J1 ON J1.AN         = M1.ANSTART
                          AND J1.LUNA       = M1.LUNASTART
                          AND J1.TIPDOC     = L.TIPLIVR
                          AND J1.CODDOC     = Coalesce(l.codies,   l.codintr,   l.codtransf)
                          AND J1.INDEXLOCAL = Coalesce(l1.codies1, l1.codintr1, l1.coddvi1)
    WHERE ((COALESCE(J1.ICONTD, 0) IN (2, 23) OR (Coalesce(J1.ICONTC, 0) = 5) AND NOT J1.TIPCONTC IN (200))
      OR (NOT J1.TIPDOC IN (12, 19, 20, 21, 23) AND (COALESCE(J1.ICONTD, 0) = 10)))
      AND Abs(Coalesce(J1.VALOARE, 0)) &gt;= 0.01
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE Coalesce(J1.SUBUNITATEA, 0) END;

     PUT_INFO(&apos;00.B08&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL1 - fisamf - miscari multiple in luna&apos;);

    INSERT INTO TMP_SAFT_JURNAL1(
      CODJURNAL1, CODMIFIX1, CODMIFIX, AN, LUNA, TIPDOC, CODDOC,
      VALOARE, DATADOC, TIPREEVAL, TIPTRANZACTIE,
      CodDescrD, IcontD, TipContD, AnaliticContD,
      CodDescrC, IcontC, TipContC, AnaliticContC,
      SEMN
    )
    SELECT
      J1.CODJURNAL1, M1.CODMIFIX1, M1.CODMIFIX, J1.AN, J1.LUNA, J1.TIPDOC, J1.CODDOC,
      J1.VALOARE, J1.DATADOC, Coalesce(M1.TIPREEVAL, -1) TIPREEVAL,  coalesce( dies.TipTranzactie, dint.TipTranzactie, 0) TIPTRANZACTIE,
      j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
      j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC,
      1 SEMN
    FROM TMP_SAFT_MIFIX1 TM1
      INNER JOIN mifix1  m1   ON m1.codmifix1   = tm1.codmifix1
      INNER JOIN nirstoc ns   ON ns.codnirstoc  = m1.codnirstoc
      INNER JOIN nir     n    ON n.codnir       = ns.codnir
      INNER JOIN transf  t    ON t.codtransf    = n.codtransf
                             AND t.an           = m1.anstart
                             AND t.luna         = m1.lunastart
      INNER JOIN fisamf  f    ON f.tipdoc       = n.tipnir
                             AND f.codmifix     = m1.codmifix
                             AND f.dataoperatie = n.datanir
      INNER JOIN nirstoc nsp  ON nsp.codnirstoc = ns.codnirstocparinte
      INNER JOIN nir     np   ON np.codnir      = nsp.codnir
      INNER JOIN fisamf  fp   ON fp.tipdoc      = np.tipnir
                             AND fp.codmifix    = m1.codmifix
      INNER JOIN jurnal1 j1   ON j1.an          = m1.anstart
                             AND j1.luna        = m1.lunastart
                             AND j1.tipdoc      = fp.tipdoc
                             AND j1.indexlocal  = fp.coddoc1
      LEFT  JOIN iesiri  dies ON dies.codies    = np.codies
      LEFT  JOIN intrari dint ON dint.codintr   = np.codintr
    WHERE Trunc(f.dataoperatie, &apos;mm&apos;) = Trunc(fp.dataoperatie, &apos;mm&apos;)
      AND (COALESCE(J1.ICONTD, 0) = 2 OR Coalesce(J1.ICONTC, 0) = 5) AND Abs(Coalesce(J1.VALOARE, 0)) &gt;= 0.01
      AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_JURNAL1 TJ1 WHERE TJ1.CODJURNAL1 = Coalesce(J1.CODJURNAL1,0));

    UPDATE TMP_SAFT_JURNAL1 T
    SET CONTD                = PKG_JURNAL.GETCONTFORJURNAL(CodDescrD, IcontD, TipContD, AnaliticContD, An, Luna),
        CONTC                = PKG_JURNAL.GETCONTFORJURNAL(CodDescrC, IcontC, TipContC, AnaliticContC, An, Luna),
        ASSETTRANSACTIONTYPE =  CASE
                                  WHEN TIPDOC IN (1,2,3,4,5)                                          THEN  &apos;10&apos; --Achizitie
                                  WHEN TIPDOC IN (6)             AND sHolding = &apos;1&apos;                   THEN  &apos;10&apos; --Achizitie
                                  WHEN TIPDOC IN (6)                                                  THEN  &apos;40&apos; --Transfer intern
                                  WHEN TIPDOC IN (19,20,21)      AND IcontD = 23                      THEN &apos;110&apos; --Reversare ajustare de valoare
                                  WHEN TIPDOC IN (19,20,21)                                           THEN  &apos;20&apos; --V?nzare
                                  WHEN TIPDOC IN (23)            AND sHolding = &apos;1&apos;                   THEN  &apos;20&apos; --V?nzare
                                  WHEN TIPDOC IN (23)                                                 THEN  &apos;40&apos; --Transfer intern
                                  WHEN TIPDOC = 36               AND IcontD = 4                       THEN  &apos;30&apos; --Amortizare
                                  WHEN TIPDOC = 36               AND IcontD = 10     AND IcontC = 0   THEN &apos;130&apos; --Alte tranzactii
                                  WHEN TIPDOC = 35                                                    THEN  &apos;30&apos; --Amortizare
                                  WHEN TIPDOC = 12               AND IContD = 10                      THEN &apos;130&apos; --Alte tranzactii
                                  WHEN TIPDOC = 12               AND IContC = 23                      THEN &apos;100&apos; --Ajustare de valoare negativa
                                  WHEN TIPDOC IN (7)                                                  THEN  &apos;40&apos; --Transfer intern
                                  WHEN TIPDOC = 15               AND TIPTRANZACTIE IN (5)             THEN  &apos;40&apos; --Transfer intern
                                  WHEN TIPDOC = 12                                                    THEN  &apos;40&apos; --Transfer intern
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (  -1) AND VALOARE &gt; 0            THEN  &apos;40&apos; --Transfer intern - prin modificare de pret
                                  WHEN TIPDOC = 36               AND IcontC = 2                       THEN
                                    (
                                       SELECT
                                         CASE
                                           WHEN M1.STARE = 3                                          THEN  &apos;50&apos; --Casare mijloace fixe
                                           WHEN M1.STARE IN (8,9)                                     THEN  &apos;10&apos; --Achizitie
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &lt; M1.PRETVECHI     THEN  &apos;60&apos; --Reevaluare negativa
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &gt; M1.PRETVECHI     THEN  &apos;70&apos; --Reevaluare pozitiva
                                           ELSE                                                            &apos;130&apos; --Alte tranzactii
                                          END
                                       FROM MIFIX1 M1
                                       WHERE M1.CodMifix1 = T.CodMifix1
                                     )
                                  WHEN TIPDOC = 36               AND IcontD = 2                       THEN
                                    (
                                       SELECT
                                         CASE
                                           WHEN M1.TIPREEVAL IN (0, 1) AND M1.PRET &gt; M1.PRETVECHI     THEN  &apos;70&apos; --Reevaluare pozitiva
                                           ELSE                                                            &apos;130&apos; --Alte tranzactii
                                          END
                                       FROM MIFIX1 M1
                                       WHERE M1.CodMifix1 = T.CodMifix1
                                     )
                                  WHEN TIPDOC = 14                                                    THEN  &apos;50&apos; --Casare mijloace fixe
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (0, 1) AND VALOARE &lt; 0            THEN  &apos;60&apos; --Reevaluare negativa
                                  WHEN TIPDOC = 13 AND TIPREEVAL IN (0, 1) AND VALOARE &gt; 0            THEN  &apos;70&apos; --Reevaluare pozitiva
                                  WHEN TIPDOC = 15                                                    THEN  &apos;80&apos; --Plus de inventar
                                  WHEN TIPDOC = 14                                                    THEN  &apos;90&apos; --Minus de inventar
                                  --WHEN TIPDOC = 36      &apos;120&apos; --Bunuri acordate cu titlu gratuit
                                  ELSE                                                                     &apos;130&apos; --Alte tranzactii
                                END;

   --Setare TipTranzactie 130 pentru amortizarea aferenta anului anterior in cazul mijloacelor fixe stornate sau corectate
    UPDATE TMP_SAFT_JURNAL1
    SET ASSETTRANSACTIONTYPE = &apos;130&apos;
    WHERE CONTD IN ( SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU IN (&apos;CRezRepAmoMifixNC&apos;) )
      AND TIPDOC = 35;

    PUT_INFO(&apos;00.B07&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL - asset&apos;);
    UPDATE TMP_SAFT_JURNAL1 J1
    SET CODJURNAL = (
                      SELECT Min(J.CODJURNAL)
                      FROM JURNAL J
                      WHERE J.AN = J1.AN AND J.LUNA = J1.LUNA AND J.TIPDOC = J1.TIPDOC AND J.CODDOC = J1.CODDOC AND J.CONTD = J1.CONTD AND J.CONTC = J1.CONTC
                    );

    INSERT INTO TMP_SAFT_JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, VALOARE, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT)
    SELECT                      CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, VALOARE, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT
    FROM JURNAL J
    WHERE J.CODJURNAL IN (SELECT DISTINCT CODJURNAL FROM TMP_SAFT_JURNAL1);
  ELSE
    PUT_INFO(&apos;00.B10&apos;,&apos;BEGIN_SAFT--TMP_SAFT_JURNAL&apos;);
    INSERT INTO TMP_SAFT_JURNAL(CODJURNAL,  CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC,     VALOARE,  AN, LUNA, SUBUNITATEA, DATADOC,     DOCUMENT)
    SELECT                  Min(CODJURNAL), CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, Sum(VALOARE), AN, LUNA, SUBUNITATEA, DATADOC, Min(DOCUMENT)
    FROM JURNAL J
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
      AND CASE
            WHEN j.tipdoc =  32  AND Coalesce(j.Valoare, 0) = 0                        THEN 0
            WHEN j.tipdoc &lt;&gt; 35                                                        THEN 1
            WHEN EXISTS(SELECT 1 FROM NC WHERE NC.CODNC = J.CODDOC AND NC.SABLON = -1) THEN 0 -- j.tipdoc = 35 si SABLON = -1
            ELSE 1
          END = 1
    GROUP BY CODDOC, TIPDOC, CONTD, INDEXLOCAL, CONTC, AN, LUNA, SUBUNITATEA, DATADOC;
  END IF;

  UPDATE TMP_SAFT_JURNAL J
  SET DESCRIPTION =
        Coalesce((SELECT TD.NUMEEXT FROM TMP_MACHETE TD WHERE TD.CODMACHETA = J.TIPDOC), &apos;Jurnal contabil&apos;)||
        CASE
          WHEN J.TIPDOC IN (32, 36)                                                           THEN &apos;/&apos;||To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;)
          WHEN J.DOCUMENT IS NULL                                                             THEN &apos;/&apos;||To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;)
          WHEN J.TIPDOC IN (25)                                                               THEN &apos; &apos;||J.DOCUMENT
          WHEN J.TIPDOC IN (52, 76)                                                           THEN &apos; &apos;||J.DOCUMENT||&apos;/&apos;||To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;)
          WHEN J.TIPDOC = 81 AND InStr(J.DOCUMENT,&apos; din &apos;) = 0                                THEN &apos; &apos;||J.DOCUMENT
          WHEN J.TIPDOC = 81                                                                  THEN &apos; &apos;||SubStr(J.DOCUMENT, InStr(J.DOCUMENT,&apos; din &apos;) + 5)
          WHEN Length(J.DOCUMENT) &lt; 10                                                        THEN &apos; &apos;||J.DOCUMENT||&apos;/&apos;||To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;)
          WHEN SubStr(J.DOCUMENT,Length(J.DOCUMENT)- 9, 10) = To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;) THEN &apos; &apos;||J.DOCUMENT
          WHEN SubStr(J.DOCUMENT,Length(J.DOCUMENT)-10,  1) = &apos;/&apos;                             THEN &apos; &apos;||J.DOCUMENT
                                                                                              ELSE &apos; &apos;||J.DOCUMENT||&apos;/&apos;||To_Char(J.DataDoc,&apos;dd.mm.yyyy&apos;)
        END;

  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT i.moneda, i.curs FROM intrari i  WHERE i.codintr = j.coddoc)   WHERE TIPDOC IN ( 1, 2, 3, 4, 5, 9);
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT i.moneda, i.curs FROM iesiri  i  WHERE i.codies  = j.coddoc)   WHERE TIPDOC IN (19,20,21,22,26);
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT g.moneda, g.curs
                                                            FROM compens c
                                                              LEFT JOIN general   g  ON g.coddoc = c.codcompens AND g.tipdoc = 28
                                                            WHERE c.codcompens  = j.coddoc
                                                              AND ROWNUM = 1
                                                           )                                                                      WHERE TIPDOC = 28;
  UPDATE TMP_SAFT_JURNAL J SET (CODMONEDA, EXCHANGERATE) = (SELECT bc.codmoneda, t1.curs
                                                            FROM trezor1 t1
                                                              LEFT JOIN trezor    t  ON t.codtrezor    = t1.codtrezor
                                                              LEFT JOIN nbankcont bc ON bc.codbankcont = t.codbanca
                                                            WHERE t1.codtrezor1  = j.indexlocal
                                                              AND ROWNUM = 1
                                                           )                                                                      WHERE TIPDOC IN (29,30,31);
  UPDATE TMP_SAFT_JURNAL J SET CODMONEDA = 0, CURRENCYCODE = &apos;RON&apos;, EXCHANGERATE = 1                                              WHERE COALESCE(CODMONEDA, 0)  = 0;
  UPDATE TMP_SAFT_JURNAL J SET (CURRENCYCODE) = (SELECT Upper(SubStr(SIMBOL,1,3)) FROM nmonede m WHERE m.codmoneda = j.codmoneda) WHERE COALESCE(CODMONEDA, 0) &lt;&gt; 0;

  INSERT INTO TMP_SAFT_JURNALDET (
    CODJURNAL,
    CODPART,
    CODPART_2,
    DATADOC,
    DATACREARE,
    TIPTRANZ, OBIECTTRANZ)
  SELECT DISTINCT
    J.CODJURNAL,
    Coalesce(
      IES.PARTENER, INTR.PARTENER, TREZ1.CODPART,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTD = 1 THEN NULLIF(NC1.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTD = 1 THEN NULLIF(NC.PART,       0) END,
      CASE WHEN J.TIPDOC = 46                   THEN NULLIF(OBR.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 59                   THEN NULLIF(NCRED.CODPART, 0) END,
      COMP.PARTC
    ) AS CODPART,
    Coalesce(
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTC = 1 THEN NULLIF(NC1.CODPART,   0) END,
      CASE WHEN J.TIPDOC = 35 AND NC1.PARTC = 1 THEN NULLIF(NC.PART,       0) END,
      COMP.PARTD
    ) AS CODPART_2,
    Coalesce(IES.DATADOC,   INTR.DATADOC,   TRAN.DATADOC,   COMP.DATADOC,   TREZ.DATADOC,   NC.DATADOC,   J.DATADOC)        AS DATADOC,
    Coalesce(IES.DATACREARE,INTR.DATACREARE,TRAN.DATACREARE,COMP.DATACREARE,TREZ.DATACREARE,NC.DATACREARE,NCRED.DATACREARE) AS DATACREARE,
    TREZ1.TIPTRANZ, TREZ1.OBIECTTRANZ
  FROM TMP_SAFT_JURNAL   J
    LEFT JOIN IESIRI            IES   ON IES.CODIES       = J.CODDOC       AND IES.TIPDOC       = J.TIPDOC
    LEFT JOIN INTRARI           INTR  ON INTR.CODINTR     = J.CODDOC       AND INTR.TIPDOC      = J.TIPDOC
    LEFT JOIN TRANSF            TRAN  ON TRAN.CODTRANSF   = J.CODDOC       AND TRAN.TIPDOC      = J.TIPDOC
    LEFT JOIN COMPENS           COMP  ON COMP.CODCOMPENS  = J.CODDOC       AND J.TIPDOC         = 28
    LEFT JOIN TREZOR            TREZ  ON TREZ.CODTREZOR   = J.CODDOC       AND TREZ.TIPDOC      = J.TIPDOC
    LEFT JOIN TREZOR1           TREZ1 ON TREZ1.CODTREZOR  = TREZ.CODTREZOR AND TREZ1.CODTREZOR1 = J.INDEXLOCAL
    LEFT JOIN NC                NC    ON NC.CODNC         = J.CODDOC       AND J.TIPDOC         = 35
    LEFT JOIN NC1               NC1   ON NC1.CODNC1       = J.INDEXLOCAL   AND J.TIPDOC         = 35
    LEFT JOIN REG1              R1    ON R1.CODREG1       = J.INDEXLOCAL   AND J.TIPDOC         = 46
    LEFT JOIN OBLIGPIF          OBR   ON OBR.CODOBLIGPIF  = R1.CODOBLIGPIF
    LEFT JOIN NOTECREDIT        NCRED ON NCRED.CODNCREDIT = J.CODDOC       AND J.TIPDOC         = 59;

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM INTRARI I
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODINTR
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END
    AND ( (j1.tipbazad = 700 AND j1.tipbazac =   0 AND j1.tipcontc = 800) OR -- supliment receptie NIRSTOC
          (j1.tipbazac = 700 AND j1.tipbazad =   0 AND j1.tipcontc = 300) OR -- intrari cu diferente rotunjire pret
          (j1.tipbazad = 700 AND j1.tipbazac =   0 AND j1.tipcontc = 300) OR -- intrari cu adaos si TVA neexigibil - adaos
 --63846--(j1.tipbazad = 700 AND j1.tipbazac = 200 AND j1.tipcontc = 200) OR -- intrari cu adaos si TVA neexigibil - TVA
          (j1.tipbazad = 900 AND j1.tipbazac = 100 AND j1.tipcontc = 800) OR -- diferente curs valutare la stornare avans - venit
          (j1.tipbazac = 900 AND j1.tipbazad = 100 AND j1.tipcontd = 800)    -- diferente curs valutare la stornare avans - cheltuiala
        );

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM IESIRI I
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = I.TIPDOC AND J1.CODDOC = I.CODIES
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END
    AND ( (j1.tipbazad = 900 AND j1.tipbazac = 100 AND j1.tipcontc = 800) OR -- diferente curs valutare la stornare avans - venit
          (j1.tipbazac = 900 AND j1.tipbazad = 100 AND j1.tipcontd = 800)    -- diferente curs valutare la stornare avans - cheltuiala
        );

  INSERT INTO TMP_SAFT_EXCL_J1(
    TIPDOC, CODDOC, AN, LUNA,
    CodDescrD, IcontD, TipContD, AnaliticContD,
    CodDescrC, IcontC, TipContC, AnaliticContC
  )
  SELECT DISTINCT
    J1.TIPDOC, J1.CODDOC, J1.AN, J1.LUNA,
    j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD,
    j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC
  FROM TREZOR T
    INNER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    INNER JOIN JURNAL1 J1 ON J1.TIPDOC = T.TIPDOC AND J1.CODDOC = T.CODTREZOR AND J1.INDEXLOCAL = T1.CODTREZOR1
  WHERE T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE T.SUBUNITATEA END
    AND (j1.icontd = 2 AND j1.icontc = 2) -- stingere documente
  ;

  UPDATE TMP_SAFT_EXCL_J1
  SET CONTD = PKG_JURNAL.GETCONTFORJURNAL(CodDescrD, IcontD, TipContD, AnaliticContD, An, Luna),
      CONTC = PKG_JURNAL.GETCONTFORJURNAL(CodDescrC, IcontC, TipContC, AnaliticContC, An, Luna);

  UPDATE TMP_SAFT_JURNAL J
  SET EXCL_TAXINFO = 0;

  UPDATE TMP_SAFT_JURNAL J
  SET EXCL_TAXINFO = 1
  WHERE EXCL_TAXINFO = 0
    AND EXISTS (SELECT 1 FROM TMP_SAFT_EXCL_J1 EJ1 WHERE EJ1.TIPDOC  = J.TIPDOC AND EJ1.CODDOC = J.CODDOC AND EJ1.CONTD = J.CONTD AND EJ1.CONTC = J.CONTC);

  FOR vRec IN (
    SELECT DISTINCT AN, LUNA
    FROM TMP_SAFT_JURNAL
    WHERE TIPDOC IN (19, 26)
  ) LOOP
    vCIntermedMarja := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;CIntermedMarja&apos; ,vRec.AN,vRec.Luna),&apos;0&apos;));
    IF vCIntermedMarja &lt;&gt; 0 THEN
      UPDATE TMP_SAFT_JURNAL
      SET EXCL_TAXINFO = 1
      WHERE EXCL_TAXINFO = 0
        AND TIPDOC IN (19, 26)
        AND AN = vRec.AN AND LUNA = vRec.Luna
        AND vCIntermedMarja IN (CONTD, CONTC);
    END IF;
  END LOOP;

  PUT_INFO(&apos;00.C01&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
  IF pSubunit = 1 THEN
    -- caz 1 din NPARTSOLDLUNA
    PUT_INFO(&apos;00.C11&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, SOLDI, SOLDF)
    SELECT CODPART, ICONT, Sum(Coalesce(SOLDI, 0)), Sum(Coalesce(SOLDF, 0))
    FROM (
      SELECT CODPART, ICONT, SOLDLEI AS SOLDI, 0       AS SOLDF FROM NPARTSOLDLUNA WHERE AN = vAnP   AND LUNA = vLunaP   AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0 UNION ALL
      SELECT CODPART, ICONT, 0       AS SOLDI, SOLDLEI AS SOLDF FROM NPARTSOLDLUNA WHERE AN = vAnFin AND LUNA = vLunaFin AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0
    ) subs
    GROUP BY CODPART, ICONT;

    -- caz 2 din OBLIGPIFLUNA unde au fost modificari
    PUT_INFO(&apos;00.C12&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        0 AS SOLDI, 0 AS SOLDF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND ( (OLP.CODOBLIGPIF IS NULL) OR (OL.REST &lt;&gt; OLP.REST) )
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 3 din OBLIGPIFLUNA unde nu au fost modificari - de analizat daca are rost acest caz (si nu ar trebui sa fie deja incluse IN cazul 1)
    PUT_INFO(&apos;00.C13&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        OL.REST, Sum(OL.REST) OVER (PARTITION BY O.CODPART, O.ICONT) RestPartICont, O.CODOBLIGPIF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    WHERE subs.RestPartICont &lt;&gt; 0
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 4 din OBLIGPIFLUNA plati incasarie trezorerie
    PUT_INFO(&apos;00.C14&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 400 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 300 THEN 1 ELSE 0 END AS FURNIZOR
      FROM OBLIGPIF O
        INNER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
        INNER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR AND T.TIPDOC = G.TIPDOC
        INNER JOIN NPART   P  ON P.CODPART     = O.CODPART
      WHERE O.SEMNIFICATIE IN (300, 400)
        AND T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
        AND Coalesce(O.Valoare , 0) &lt;&gt; 0
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;
  ELSE
    -- caz 1 din NPARTSOLDLUNASUB
    PUT_INFO(&apos;00.C21&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, SOLDI, SOLDF)
    SELECT CODPART, ICONT, Sum(Coalesce(SOLDI, 0)), Sum(Coalesce(SOLDF, 0))
    FROM (
      SELECT CODPART, ICONT, SOLDLEI AS SOLDI, 0       AS SOLDF FROM NPARTSOLDLUNASUB WHERE AN = vAnP   AND LUNA = vLunaP   AND SUBUNITATEA = pSubunit AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0 UNION ALL
      SELECT CODPART, ICONT, 0       AS SOLDI, SOLDLEI AS SOLDF FROM NPARTSOLDLUNASUB WHERE AN = vAnFin AND LUNA = vLunaFin AND SUBUNITATEA = pSubunit AND Round(SOLDLEI,2) &lt;&gt; 0 AND CODPART &lt;&gt; 0 AND ICONT &lt;&gt; 0
    ) subs
    GROUP BY CODPART, ICONT;

    -- caz 2 din OBLIGPIFLUNA unde au fost modificari
    PUT_INFO(&apos;00.C22&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        CASE
          WHEN O.SEMNIFICATIE IN (100, 110, 120, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I            WHERE I.TIPDOC = G.TIPDOC AND I.CODINTR     = G.CODDOC)
          WHEN O.SEMNIFICATIE = 130                   THEN (SELECT SUBUNITATEA FROM DVI D, INTRARI I     WHERE 5        = G.TIPDOC AND D.CODDVI      = G.CODDOC AND I.CODINTR   = D.CODINTR)
          WHEN O.SEMNIFICATIE IN (200, 210, 220, 240) THEN (SELECT SUBUNITATEA FROM IESIRI I             WHERE I.TIPDOC = G.TIPDOC AND I.CODIES      = G.CODDOC)
          WHEN O.SEMNIFICATIE IN (310, 330, 410, 430) THEN (SELECT SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE T.TIPDOC = G.TIPDOC AND T1.CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR)
          WHEN O.SEMNIFICATIE IN (1200, 1201)         THEN (SELECT SUBUNITATEA FROM NC N, NC1 N1         WHERE 35       = G.TIPDOC AND N1.CODNC1     = G.CODDOC AND N.CODNC     = N1.CODNC)
          WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)   THEN (SELECT SUBUNITATEA FROM COMPENS C            WHERE 28       = G.TIPDOC AND C.CODCOMPENS  = G.CODDOC)
        END AS SUBUNITATEA
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND ( (OLP.CODOBLIGPIF IS NULL) OR (OL.REST &lt;&gt; OLP.REST) )
    ) subs
    WHERE subs.SUBUNITATEA = pSubunit
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 3 din OBLIGPIFLUNA unde nu au fost modificari - de analizat daca are rost acest caz (si nu ar trebui sa fie deja incluse IN cazul 1)
    PUT_INFO(&apos;00.C23&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 600 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 500 THEN 1 ELSE 0 END AS FURNIZOR,
        CASE
          WHEN O.SEMNIFICATIE IN (100, 110, 120, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I            WHERE I.TIPDOC = G.TIPDOC AND I.CODINTR     = G.CODDOC)
          WHEN O.SEMNIFICATIE = 130                   THEN (SELECT SUBUNITATEA FROM DVI D, INTRARI I     WHERE 5        = G.TIPDOC AND D.CODDVI      = G.CODDOC AND I.CODINTR   = D.CODINTR)
          WHEN O.SEMNIFICATIE IN (200, 210, 220, 240) THEN (SELECT SUBUNITATEA FROM IESIRI I             WHERE I.TIPDOC = G.TIPDOC AND I.CODIES      = G.CODDOC)
          WHEN O.SEMNIFICATIE IN (310, 330, 410, 430) THEN (SELECT SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE T.TIPDOC = G.TIPDOC AND T1.CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR)
          WHEN O.SEMNIFICATIE IN (1200, 1201)         THEN (SELECT SUBUNITATEA FROM NC N, NC1 N1         WHERE 35       = G.TIPDOC AND N1.CODNC1     = G.CODDOC AND N.CODNC     = N1.CODNC)
          WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)   THEN (SELECT SUBUNITATEA FROM COMPENS C            WHERE 28       = G.TIPDOC AND C.CODCOMPENS  = G.CODDOC)
        END AS SUBUNITATEA,
        OL.REST, Sum(OL.REST) OVER (PARTITION BY O.CODPART, O.ICONT) RestPartICont, O.CODOBLIGPIF
      FROM OBLIGPIFLUNA OL
        INNER JOIN OBLIGPIF     O   ON O.CODOBLIGPIF   = OL.CODOBLIGPIF
        INNER JOIN GENERAL      G   ON G.CODGENERAL    = O.CODGENERAL
        LEFT  JOIN IESIRI       I   ON I.CODIES        = G.CODDOC AND I.TIPDOC = G.TIPDOC
        INNER JOIN NPART        P   ON P.CODPART       = O.CODPART
        LEFT  JOIN OBLIGPIFLUNA OLP ON OLP.CODOBLIGPIF = OL.CODOBLIGPIF AND OLP.AN = OL.AN - CASE WHEN OL.LUNA = 1 THEN 1 ELSE 0 END AND OLP.LUNA = CASE WHEN OL.LUNA = 1 THEN 12 ELSE OL.LUNA-1 END
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
        AND OL.AN*12+OL.LUNA BETWEEN v_ALIni AND v_ALFin
        AND NOT ( Coalesce(O.Valoare , 0) = 0 AND Coalesce(I.CUSTODIE, 0) = 1 )
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
    ) subs
    WHERE subs.SUBUNITATEA = pSubunit
      AND subs.RestPartICont &lt;&gt; 0
    GROUP BY subs.CODPART, subs.ICONT;

    -- caz 4 din OBLIGPIFLUNA plati incasarie trezorerie
    PUT_INFO(&apos;00.C24&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
    INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
    SELECT subs.CODPART, subs.ICONT, Max(subs.CLIENT), Max(subs.FURNIZOR), 0 AS SOLDI, 0 AS SOLDF
    FROM (
      SELECT
        O.CODPART, O.ICONT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 400 THEN 1 ELSE 0 END AS CLIENT,
        CASE WHEN O.ICONT = 1 AND O.SEMNIFICATIE = 300 THEN 1 ELSE 0 END AS FURNIZOR
      FROM OBLIGPIF O
        INNER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
        INNER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
        INNER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR AND T.TIPDOC = G.TIPDOC
        INNER JOIN NPART   P  ON P.CODPART     = O.CODPART
      WHERE O.SEMNIFICATIE IN (300, 400)
        AND T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
        AND Coalesce(O.Valoare , 0) &lt;&gt; 0
        AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = O.CODPART AND T.ICONT = O.ICONT)
        AND O.CODPART &lt;&gt; 0 AND O.ICONT &lt;&gt; 0
        AND T.SUBUNITATEA = pSubunit
    ) subs
    GROUP BY subs.CODPART, subs.ICONT;
  END IF;

  PUT_INFO(&apos;00.C34&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
  UPDATE TMP_SAFT_NPART
  SET CLIENT   = CASE WHEN ICONT IN (0,1) THEN CLIENT   WHEN ICONT IN (3,5,7,10,11,18,20,23,24,30,31,32,33,34,61)                                                                                         THEN 1 ELSE 0 END,
      FURNIZOR = CASE WHEN ICONT IN (0,1) THEN FURNIZOR WHEN ICONT IN (2,4,6,8,9,12,13,14,15,16,17,19,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60) THEN 1 ELSE 0 END;

  PUT_INFO(&apos;00.C35&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
  DELETE FROM TMP_SAFT_NPART WHERE CLIENT = 0 AND FURNIZOR = 0;

  PUT_INFO(&apos;00.C36&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART&apos;);
  UPDATE_CODCONT_FROM_IOPART1 (&apos;TMP_SAFT_NPART&apos;, &apos;CODCONT&apos;, &apos;CODPART&apos;, &apos;ICONT&apos;, &apos;&apos;, v_ALFin);
  --UPDATE TMP_SAFT_NPART SET CODCONT = PKG_LIST_BASE_UTILS.iCont_CodCont(ICONT, CODPART, v_ALFin, 0);

  PUT_INFO(&apos;00.C37&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPART - VERIFICA INFOCM&apos;);
  INSERT INTO TMP_SAFT_NPART (CODPART, ICONT, CODCONT, CLIENT, FURNIZOR, SOLDI, SOLDF)
  SELECT DISTINCT PARTENER, 0 AS ICONT, 0 AS CODCONT, 1 AS CLIENT, 0 AS FURNIZOR, 0 AS SOLDI, 0 AS SOLDF
  FROM IESIRI I
  WHERE I.INFOCM = 1
    AND I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND NOT EXISTS (SELECT 1 FROM TMP_SAFT_NPART T WHERE T.CODPART = I.PARTENER AND T.CLIENT = 1)
    AND I.PARTENER &lt;&gt; 0
    AND I.SUBUNITATEA = Coalesce(NULLIF(pSubunit,1),I.SUBUNITATEA);

  PUT_INFO(&apos;00.D&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NPARTDET&apos;);
  UMPLE_NPARTDET(v_ALIni, v_ALFin, TRUE);
  INSERT INTO TMP_SAFT_NPARTFUZ SELECT Min(CodPart) OVER (PARTITION BY PARTID) CODPARTFUZ, CODPART FROM TMP_SAFT_NPARTDET;
  DELETE FROM TMP_SAFT_NPARTDET WHERE CodPart IN (SELECT CODPART FROM TMP_SAFT_NPARTFUZ WHERE CODPARTFUZ &lt;&gt; CODPART);

  PUT_INFO(&apos;00.E01&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT CODINTR
  FROM INTRARI I
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT J.INDEXLOCAL
  FROM JURNAL J
  WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    AND J.TIPDOC = 81 AND J.CODDOC = 1
    AND EXISTS(SELECT 1 FROM INTRARI I WHERE I.CODINTR = J.INDEXLOCAL AND I.AN*12+I.LUNA &lt; v_ALIni );
  COMMIT;

  PUT_INFO(&apos;00.E02&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CHEIE_CODCONTDED, CHEIE_CODCONTCOL, CHEIE_TAXVAL,
    CODCONTDED
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    To_Number(CHEIE_CODCONTDED) CHEIE_CODCONTDED, To_Number(Coalesce(CHEIE_CODCONTCOL, CHEIE_CODCONTPRORATA)) CHEIE_CODCONTCOL, To_Number(CHEIE_TAXVAL) CHEIE_TAXVAL,
    CASE
      WHEN subs.tipdoc = 5 AND subs.TIPTRANZACTIE = 3
      THEN (SELECT Max(c.codcont) FROM jurnal j INNER JOIN TMP_SAFT_CC4426 c ON c.codcont = j.contd WHERE j.tipdoc = subs.tipdoc AND j.coddoc = subs.coddoc)
      ELSE NULL
    END AS CODCONTDED
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD,
      SubStr(TD.Cheia, Instr(TD.Cheia, &apos;&lt;P&apos;)+2, Instr(TD.Cheia,&apos;P&gt;&apos;)-Instr(TD.Cheia,&apos;&lt;P&apos;)-2) CHEIE_CODCONTPRORATA,
      SubStr(TD.Cheia, Instr(TD.Cheia, &apos;&lt;D&apos;)+2, Instr(TD.Cheia,&apos;D&gt;&apos;)-Instr(TD.Cheia,&apos;&lt;D&apos;)-2) CHEIE_CODCONTDED,
      SubStr(TD.Cheia, Instr(TD.Cheia, &apos;&lt;C&apos;)+2, Instr(TD.Cheia,&apos;C&gt;&apos;)-Instr(TD.Cheia,&apos;&lt;C&apos;)-2) CHEIE_CODCONTCOL,
      SubStr(TD.Cheia, Instr(TD.Cheia, &apos;&lt;V&apos;)+2, Instr(TD.Cheia,&apos;V&gt;&apos;)-Instr(TD.Cheia,&apos;&lt;V&apos;)-2) CHEIE_TAXVAL,
      I.TIPTRANZACTIE
    FROM TMP_MANEVRA2 M
      INNER JOIN INTRARI               I  ON I.CODINTR  = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CODINTR
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &gt; 0
      AND TD.MANUAL  &lt;&gt; 2
      AND Coalesce(TD.CODDOC1, 0) &gt;= 0
      AND NOT ( Coalesce(TD.TAXBASE, 0) = 0 AND Coalesce(TD.TAXVAL, 0) = 0 )
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, I.TIPTRANZACTIE, TD.Cheia, TT.Description
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E03&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CODCONTDED
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT,
    TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    (SELECT Max(c.codcont) FROM jurnal j INNER JOIN TMP_SAFT_CC4426 c ON c.codcont = j.contc WHERE j.tipdoc = subs.tipdoc AND j.coddoc = subs.coddoc) AS CODCONTDED
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, C.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM TMP_MANEVRA2 M
      INNER JOIN INTRARI               I  ON I.CODINTR  = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CODINTR
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = CASE WHEN vTipTVAMixt100 = 2 THEN vCCheltTVADed ELSE TD.CodCont END
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &gt; 0
      AND TD.MANUAL  &lt;&gt; 2
      AND Coalesce(TD.CODDOC1, 0) &lt; 0
    GROUP BY TD.TIPDOC, TD.CODDOC, C.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, C.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E04&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANEVRA2&apos;;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT CODIES
  FROM IESIRI I
  WHERE I.AN*12+I.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE I.SUBUNITATEA END;
  INSERT INTO TMP_MANEVRA2(CODUNIC)
  SELECT J.INDEXLOCAL
  FROM JURNAL J
  WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
    AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    AND J.TIPDOC = 81 AND J.CODDOC = 2
    AND EXISTS(SELECT 1 FROM IESIRI I WHERE I.CODIES = J.INDEXLOCAL AND I.AN*12+I.LUNA &lt; v_ALIni );
  COMMIT;

  PUT_INFO(&apos;00.E05&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    CHEIE_BAZATVAMARJA
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD,
    To_Number(CHEIE_BAZATVAMARJA)
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD,
      CASE
        WHEN I.TIPTVA IN (7,8) THEN SubStr(TD.Cheia, Instr(TD.Cheia, &apos;&lt;BAZATVAMARJA&apos;)+13, Instr(TD.Cheia,&apos;BAZATVAMARJA&gt;&apos;)-Instr(TD.Cheia,&apos;&lt;BAZATVAMARJA&apos;)-13)
        ELSE NULL
      END AS CHEIE_BAZATVAMARJA
    FROM TMP_MANEVRA2 M
      INNER JOIN IESIRI                I  ON I.CODIES   = M.CODUNIC
      INNER JOIN TAXDECL               TD ON TD.TIPDOC  = I.TIPDOC AND TD.CODDOC = I.CodIes
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod     = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont  = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD     = CASE
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                            WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                            ELSE C.TAXTYPE
                                                          END
    WHERE TD.TaxCode &lt;&gt; 0
      AND TD.MANUAL  &lt;&gt; 2
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION, TD.Cheia, I.TIPTVA
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E06&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM TREZOR T
      INNER JOIN TREZOR1               T1 ON T1.CODTREZOR = T.CodTrezor
      INNER JOIN TAXDECL               TD ON TD.TIPDOC    = T.TIPDOC AND TD.CODDOC = T1.CodTrezor1
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE T.AN*12+T.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE T.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E07&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM COMPENS DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODCOMPENS AND TD.TIPDOC = 28
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE DOC.AN*12+DOC.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE DOC.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E08&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      TD.TIPDOC, TD.CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, Sum(TD.TAXBASE) TAXBASE, Sum(TD.TAXVAL) TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM NC DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODNC AND TD.TIPDOC = 35
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = TD.TaxCode
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT  JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE DOC.AN*12+DOC.LUNA BETWEEN v_ALIni AND v_ALFin
      AND TD.MANUAL  &lt;&gt; 2
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE DOC.SUBUNITATEA END
    GROUP BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa, TT.DESCRIPTION
    ORDER BY TD.TIPDOC, TD.CODDOC, TD.CODCONT, TT.COD, TD.TaxCode, TC.ProcTaxa
  ) subs;

  PUT_INFO(&apos;00.E09&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(DOC.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, 380200 TAXCODE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC = 32
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4426&apos;, &apos;4427&apos;)
      UNION
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, 380200 TAXCODE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC = 32
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4426&apos;, &apos;4427&apos;)
    ) DOC
      LEFT JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod        = DOC.TaxCode
      LEFT JOIN NCONT                 C  ON C.CodCont     = DOC.CodCont
      LEFT JOIN WINMADMIN.TaxTypeSaft TT ON TT.COD        = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
  ) subs;

  PUT_INFO(&apos;00.E10&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODJURNAL AS CODDOC, TD.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TC.Cod, 0), &apos;fm999000000&apos;) TAXCODE, TC.ProcTaxa TAXPERCENTAGE,
      (TD.TAXBASE-Coalesce(XD.TAXBASE, 0))*DOC.COEF TAXBASE, (TD.TAXVAL-Coalesce(XD.TAXVAL, 0))*DOC.COEF TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT
        J.CODJURNAL, J.TIPDOC,
        COALESCE(xINT.TIPDOC,  xIES.TIPDOC, 0) AS TIPX,
        COALESCE(xINT.CODINTR, xIES.CODIES, 0) AS CODX,
        CASE
          WHEN InStr(J.DOCUMENT, &apos;%&apos;) = 0                                                                                                  THEN 1
          WHEN SubStr(J.DOCUMENT, 1, InStr(J.DOCUMENT, &apos;%&apos;)-1) &lt;&gt; REGEXP_REPLACE(SubStr(J.DOCUMENT, 1, InStr(J.DOCUMENT, &apos;%&apos;)-1),&apos;\D+&apos;,&apos;&apos;) THEN 1
          ELSE To_Number(SubStr(J.DOCUMENT, 1, InStr(J.DOCUMENT, &apos;%&apos;)-1)) / 100
        END COEF,
        Coalesce(xINT.TVAINCASARE, xIES.TVAINCASARE, 0) TVAINCASARE
      FROM TMP_SAFT_JURNAL J
        LEFT JOIN INTRARI xINT ON xINT.CODINTR = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 1
        LEFT JOIN IESIRI  xIES ON xIES.CODIES  = J.INDEXLOCAL AND J.TIPDOC = 81 AND J.CODDOC = 2
      WHERE J.TIPDOC = 81
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ) DOC
      INNER JOIN TAXDECL               TD ON TD.CODDOC    = DOC.CODX AND TD.TIPDOC = DOC.TIPX AND TD.CODDOC1 &gt;= 0
      LEFT  JOIN TAXDECL               XD ON XD.CODDOC    = DOC.CODX AND XD.TIPDOC = DOC.TIPX AND XD.CODDOC1 &lt;  0 AND XD.CODDOC1 = -TD.CODDOC1 -- tichet 58523 am inlocuit INNER cu LEFT
      LEFT  JOIN WINMADMIN.TaxCodeSaft TC ON TC.Cod       = CASE
                                                              WHEN TD.TaxCode IN (301101, 301102, 301103, 301104, 301105) THEN TD.TaxCode
                                                              WHEN TD.TaxCode IN (361301, 361302, 361303, 361304, 361305) THEN TD.TaxCode
                                                              WHEN TD.TaxCode IN (310309, 310310, 310311, 310344, 310351) THEN TD.TaxCode
                                                              WHEN TD.TaxCode = 301301 /* 19% - intrari */                THEN 301101
                                                              WHEN TD.TaxCode = 301302 /*  9% - intrari */                THEN 301102
                                                              WHEN TD.TaxCode = 301303 /*  5% - intrari */                THEN 301103
                                                              WHEN TD.TaxCode = 301305 /* 21% - intrari */                THEN 301104
                                                              WHEN TD.TaxCode = 301306 /* 11% - intrari */                THEN 301105
                                                              WHEN TD.TaxCode = 310335 /* 19% - iesiri  */                THEN 310309
                                                              WHEN TD.TaxCode = 310336 /*  9% - iesiri  */                THEN 310310
                                                              WHEN TD.TaxCode = 310337 /*  5% - iesiri  */                THEN 310311
                                                              WHEN TD.TaxCode = 310350 /* 21% - iesiri  */                THEN 310344
                                                              WHEN TD.TaxCode = 310354 /* 11% - iesiri  */                THEN 310351
                                                              ELSE 0
                                                            END
      LEFT  JOIN NCONT                 C  ON C.CodCont    = TD.CodCont
      LEFT JOIN WINMADMIN.TaxTypeSaft  TT ON TT.COD       = CASE
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0 AND COALESCE(C.IMPOZIT, 0) = 1 THEN 0
                                                              WHEN COALESCE(C.TAXTYPE, 0) = 0                                THEN 300
                                                              ELSE C.TAXTYPE
                                                            END
    WHERE NOT (DOC.TVAINCASARE = 1 AND TD.TAXVAL = 0) -- exlud linii cu TVA 0 la incasare
  ) subs;

  PUT_INFO(&apos;00.E21&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  -- Facturi la avize de iesire
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT DISTINCT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, NULL TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC = 26
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4428&apos;)
    ) DOC
      INNER JOIN iesiri1               i1  ON i1.codies   = doc.coddoc
      INNER JOIN ieslink               il  ON il.codies1  = i1.codies1
      INNER JOIN iesiri1               ae1 ON ae1.codies1 = il.codlinieaviz AND Coalesce(ae1.tva, 0) &lt;&gt; 0
      INNER JOIN iesiri                ae  ON ae.codies   = ae1.codies
      LEFT  JOIN taxdecl               td  ON td.tipdoc   = ae.tipdoc AND td.coddoc = ae.codies AND td.coddoc1 = ae1.codies1
      LEFT  JOIN ncont                 c   ON c.codcont   = td.codcont
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt  ON tt.cod      = COALESCE(NULLIF(C.TAXTYPE, 0), 300)
  ) subs;

  PUT_INFO(&apos;00.E22&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  -- Facturi la avize de intrare
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT DISTINCT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, NULL TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC = 9
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4428&apos;)
    ) DOC
      INNER JOIN intrari1              i1  ON i1.codintr   = doc.coddoc
      INNER JOIN intrlink              il  ON il.codintr1  = i1.codintr1
      INNER JOIN intrari1              ae1 ON ae1.codintr1 = il.codlinieaviz AND Coalesce(ae1.tva, 0) &lt;&gt; 0
      INNER JOIN intrari               ae  ON ae.codintr   = ae1.codintr
      LEFT  JOIN taxdecl               td  ON td.tipdoc    = ae.tipdoc AND td.coddoc = ae.codintr AND td.coddoc1 = ae1.codintr1
      LEFT  JOIN ncont                 c   ON c.codcont    = td.codcont
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt  ON tt.cod       = COALESCE(NULLIF(C.TAXTYPE, 0), 300)
  ) subs;

  PUT_INFO(&apos;00.E23&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO&apos;);
  --Facturi la avize 4426, 4427
  INSERT INTO TMP_SAFT_TAXINFO (
    CODTI,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  )
  SELECT
    SEQ_SAFT_TI.NEXTVAL,
    TIPDOC, CODDOC, CODCONT, TAXTYPE, TAXCODE, TAXPERCENTAGE, TAXBASE, TAXVAL,
    TAXBASEDESCRIPTION, CODTAXAMOUNTSAF_AMOUNT, TAXEXEMPTIONREASON, TAXDECLARATIONPERIOD
  FROM (
    SELECT
      DOC.TIPDOC, DOC.CODDOC, DOC.CODCONT,
      To_Char(TT.COD, &apos;fm999000&apos;) TAXTYPE, To_Char(Coalesce(TD.TaxCode, 0), &apos;fm999000000&apos;) TAXCODE, NULL TAXPERCENTAGE, 0 TAXBASE, 0 TAXVAL,
      SubStr(TT.DESCRIPTION,1,70) TAXBASEDESCRIPTION, NULL CODTAXAMOUNTSAF_AMOUNT, NULL TAXEXEMPTIONREASON, NULL TAXDECLARATIONPERIOD
    FROM (
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, C.TAXTYPE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTD
      WHERE J.TIPDOC IN (9, 26)
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4426&apos;, &apos;4427&apos;)
      UNION
      SELECT J.TIPDOC, J.CODDOC, C.CODCONT, C.TAXTYPE
      FROM TMP_SAFT_JURNAL J INNER JOIN NCONT C ON C.CODCONT = J.CONTC
      WHERE J.TIPDOC IN (9, 26)
        AND J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
        AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
        AND c.codsaft IN (&apos;4426&apos;, &apos;4427&apos;)
    ) DOC
      LEFT  JOIN taxdecl               td ON td.tipdoc = doc.tipdoc AND td.coddoc = doc.coddoc
      LEFT  JOIN WINMADMIN.TaxTypeSaft tt ON tt.cod    = COALESCE(NULLIF(DOC.TAXTYPE, 0), 300)
  ) subs;

  PUT_INFO(&apos;00.E90&apos;,&apos;BEGIN_SAFT--TMP_SAFT_TAXINFO_MP&apos;);
  INSERT INTO TMP_SAFT_TAXINFO_MP (
    CODTI, IDXLOCAL, CODCONT,
    TAXBASE,
    TAXVAL)
  SELECT
    codti, Row_Number() OVER (PARTITION BY codti ORDER BY mp_valoare) IdxLocal, cont,
    Round(taxbase*mp_valoare/Sum(mp_valoare) OVER (PARTITION BY codti),2) mp_taxbase,
    Round(taxval *mp_valoare/Sum(mp_valoare) OVER (PARTITION BY codti),2) mp_taxval
  FROM (
    SELECT
      ti.codti, iob1.cont, ti.taxbase, ti.taxval,
      Sum(mp.valoare) mp_valoare
    FROM tmp_saft_taxinfo ti
      INNER JOIN moduriplati mp   ON mp.codies = ti.coddoc
      INNER JOIN iesiri      i    ON i.codies  = mp.codies
      INNER JOIN nbankcont1  bc1  ON bc1.codbankcont = mp.codbankcont AND i.an*12+i.luna BETWEEN bc1.ALStart  AND bc1.ALSTOP
      INNER JOIN iobank1     iob1 ON iob1.codiobank = bc1.codiobanca  AND i.an*12+i.luna BETWEEN iob1.ALStart AND iob1.ALSTOP
    WHERE ti.tipdoc = 16 AND Coalesce(mp.valoare, 0) &lt;&gt; 0
    GROUP BY ti.codti, iob1.cont, ti.taxbase, ti.taxval
  ) ss1;

  PUT_INFO(&apos;00.F06&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 06, CODPART, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT CODPART
    FROM TMP_SAFT_NPARTDET /*TMP_SAFT_NPART*/
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.F07&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 07, CODAGENDA, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT CODAGENDA
    FROM TMP_SAFT_NPARTDET /*TMP_SAFT_NPART*/ TP INNER JOIN NAGENDA A ON A.CODPART = TP.CODPART AND A.SEDIUSOCIAL BETWEEN 4 AND 7 AND Coalesce(A.INACTIV, 0) = 0
    ORDER BY 1
  ) subs;

  IF bPartContact THEN
    PUT_INFO(&apos;00.F08&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 08, CODSURSA, SEQ_SAFT.NEXTVAL
    FROM (
      SELECT CODSURSA
      FROM TMP_SAFT_CODSAF C06
      WHERE C06.CodSAFTTab = 06 AND EXISTS (SELECT 1 FROM NPERSCONTACT PC WHERE PC.CodPart = C06.CODSURSA)
      ORDER BY 1
    ) subs;

    PUT_INFO(&apos;00.F09&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 09, CODPERSC, SEQ_SAFT.NEXTVAL
    FROM (
      SELECT DISTINCT PC.CODPERSC
      FROM TMP_SAFT_CODSAF C08 LEFT JOIN NPERSCONTACT PC ON PC.CodPart = C08.CODSURSA
      WHERE C08.CodSAFTTab = 08
      ORDER BY 1
    ) subs;
  END IF;

  PUT_INFO(&apos;00.F10&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 10, COD_CODFISCAL, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT PCF.COD_CODFISCAL
    FROM TMP_SAFT_CODSAF C06 INNER JOIN TMP_SAFT_NPARTDET PCF ON PCF.CODPART = C06.CODSURSA
    WHERE C06.CodSAFTTab = 06 AND PCF.CODFISCAL IS NOT NULL
    ORDER BY 1
  ) subs;

  IF bPartBanca THEN
    PUT_INFO(&apos;00.F11&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 11, CODPARTB, SEQ_SAFT.NEXTVAL
    FROM (
      SELECT DISTINCT Coalesce(PB.CODPARTB, 0) CODPARTB
      FROM TMP_SAFT_CODSAF C06 LEFT JOIN NPARTB PB ON PB.CODPART = C06.CODSURSA AND PB.IMPLICIT = 1
      WHERE C06.CodSAFTTab = 06
      ORDER BY 1
    ) subs;
  END IF;

  PUT_INFO(&apos;00.F14&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  cSQL := &apos;INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 14, codumsaft, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT ums.codumsaft
    FROM iesiri i
      INNER JOIN iesiri1           i1  ON i1.codies    = i.codies
      INNER JOIN num1              u1  ON u1.codum1     = i1.umsec
      INNER JOIN num               u   ON u.codum       = u1.codum
      INNER JOIN winmadmin.numsaft ums ON ums.codumsaft = u.codumsaft
    WHERE I.AN*12+i.LUNA BETWEEN &apos;||To_Char(v_ALIni, &apos;fm99990&apos;)||&apos; AND &apos;||To_Char(v_ALFin, &apos;fm99990&apos;)||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(u.codumsaft,0) &lt;&gt; 0&apos;||
      CASE WHEN pSubunit = 1 THEN &apos;&apos; ELSE &apos; AND I.SUBUNITATEA = &apos;||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN &apos;&apos; ELSE &apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos;&apos;                 END ||&apos;
    UNION
    SELECT DISTINCT ums.codumsaft
    FROM intrari i
      INNER JOIN intrari1          i1  ON i1.codintr    = i.codintr
      INNER JOIN num1              u1  ON u1.codum1     = i1.umsec
      INNER JOIN num               u   ON u.codum       = u1.codum
      INNER JOIN winmadmin.numsaft ums ON ums.codumsaft = u.codumsaft
    WHERE I.AN*12+i.LUNA BETWEEN &apos;||To_Char(v_ALIni, &apos;fm99990&apos;)||&apos; AND &apos;||To_Char(v_ALFin, &apos;fm99990&apos;)||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(u.codumsaft,0) &lt;&gt; 0&apos;||
      CASE WHEN pSubunit = 1 THEN &apos;&apos; ELSE &apos; AND I.SUBUNITATEA = &apos;||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN &apos;&apos; ELSE &apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos;&apos;                 END ||&apos;
    ORDER BY 1
  ) subs&apos;;
  EXECUTE IMMEDIATE cSQL;

  PUT_INFO(&apos;00.F17&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  cSQL := &apos;INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 17, O.CODOBIECT, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT I1.CODOBIECT
    FROM iesiri i INNER JOIN iesiri1 i1 ON i1.codies = i.codies
    WHERE I.AN*12+i.LUNA BETWEEN &apos;||To_Char(v_ALIni, &apos;fm99990&apos;)||&apos; AND &apos;||To_Char(v_ALFin, &apos;fm99990&apos;)||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(I1.CODOBIECT,0) &lt;&gt; 0&apos;||
      CASE WHEN pSubunit = 1 THEN &apos;&apos; ELSE &apos; AND I.SUBUNITATEA = &apos;||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN &apos;&apos; ELSE &apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos;&apos;                 END ||&apos;
    UNION
    SELECT DISTINCT I1.CODOBIECT
    FROM intrari i INNER JOIN intrari1 i1 ON i1.codintr = i.codintr
    WHERE I.AN*12+i.LUNA BETWEEN &apos;||To_Char(v_ALIni, &apos;fm99990&apos;)||&apos; AND &apos;||To_Char(v_ALFin, &apos;fm99990&apos;)||&apos;
      AND I.OPERAT = 1 AND I.ANULAT = 0 AND Coalesce(I1.CODOBIECT,0) &lt;&gt; 0&apos;||
      CASE WHEN pSubunit = 1 THEN &apos;&apos; ELSE &apos; AND I.SUBUNITATEA = &apos;||To_Char(pSubunit) END ||
      CASE WHEN pTip    &lt;&gt; 4 THEN &apos;&apos; ELSE &apos; AND i1.tiplinie = &apos;&apos;=&apos;&apos;&apos;                 END ||&apos;
    ORDER BY 1
  ) subs
    INNER JOIN nartobj o ON o.codobiect = subs.codobiect
  WHERE Coalesce(o.saft_export, 1) = 1 &apos;;
  EXECUTE IMMEDIATE cSQL; -- pus sql dinamic deaorece am gasit gasit cazuri IN care o lua pe aratura si nu inteleg de ce

  IF pTip = 4 THEN -- La Cerere - include stocuri
    PUT_INFO(&apos;00.F20&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
    SELECT 20, T.CODOBIECT, SEQ_SAFT.NEXTVAL
    FROM (
      SELECT o.codobiect
      FROM (
        SELECT DISTINCT codobiect
        FROM nirstoc ns INNER JOIN nirluna nl ON nl.codnirstoc = ns.codnirstoc
        WHERE nl.an = vAnFin AND nl.luna = vLunaFin AND Coalesce(nl.rest, 0) &lt;&gt; 0
      ) t
        INNER JOIN nartobj o ON o.codobiect = t.codobiect
        INNER JOIN nart    a ON a.codarticol = o.codarticol
      WHERE a.tipstoc IN (1, 2)
      UNION
      SELECT codobiect
      FROM stocfake
      WHERE an = vAnFin AND luna = vLunaFin
    ) T;

    PUT_INFO(&apos;00.F53&apos;,&apos;BEGIN_SAFT--TMP_SAFT_STOCKMOVEMENT&apos;);
    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, i.tipdoc, n.codnir, i.codintr, &apos;N&apos;, &apos;10&apos;, n.datanir, p.codpartfuz
    FROM intrari i
      INNER JOIN nir               n ON n.codintr = i.codintr AND n.tipnir = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, i.tipdoc, n.codnir, i.codies, &apos;N&apos;, &apos;30&apos;, n.datanir, p.codpartfuz
    FROM iesiri i
      INNER JOIN nir               n ON n.codies = i.codies AND n.tipnir = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, i.tipdoc, l.codlivr, i.codies, &apos;L&apos;, &apos;40&apos;, l.datalivr, p.codpartfuz
    FROM iesiri i
      INNER JOIN livr              l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, i.tipdoc, l.codlivr, i.codintr, &apos;L&apos;, &apos;50&apos;, l.datalivr, p.codpartfuz
    FROM intrari i
      INNER JOIN livr              l ON l.codintr = i.codintr AND l.tiplivr = i.tipdoc
      LEFT  JOIN tmp_saft_npartfuz p ON p.codpart = i.partener
    WHERE i.an = vAnFin AND i.luna = vLunaFin AND i.operat = 1 AND i.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, t.tipdoc, n.codnir, t.codtransf, &apos;N&apos;, &apos;80&apos;, n.datanir, 0
    FROM transf t
      INNER JOIN nir               n ON n.codtransf = t.codtransf AND n.tipnir = t.tipdoc
    WHERE t.an = vAnFin AND t.luna = vLunaFin AND t.operat = 1 AND t.anulat = 0;

    INSERT INTO TMP_SAFT_STOCKMOVEMENT(CODSAF, TIPDOC, CODDOC, CODPARINTE, TAB, MOVEMENTTYPE, DATADOC, CODPART)
    SELECT SEQ_SAFT.NEXTVAL, t.tipdoc, l.codlivr, t.codtransf, &apos;L&apos;, &apos;80&apos;, l.datalivr, 0
    FROM transf t
      INNER JOIN livr              l ON l.codtransf = t.codtransf AND l.tiplivr = t.tipdoc
    WHERE t.an = vAnFin AND t.luna = vLunaFin AND t.operat = 1 AND t.anulat = 0;

    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET MOVEMENTTYPE =
        CASE
          WHEN TAB = &apos;N&apos; AND TIPDOC IN (1,2,3,4,5,6)               THEN  &apos;10&apos; --Achizitie
          WHEN TAB = &apos;N&apos; AND TIPDOC IN (7, 24)                     THEN  &apos;20&apos; --Productie
          WHEN TAB = &apos;L&apos; AND TIPDOC IN (19,20,21,23)               THEN  &apos;30&apos; --V?nzare
          WHEN TAB = &apos;N&apos; AND TIPDOC IN (19,20,21,23)               THEN  &apos;40&apos; --Retur produse v?ndute
          WHEN TAB = &apos;L&apos; AND TIPDOC IN (1,2,3,4,5,6,7)             THEN  &apos;50&apos; --Retur produse achizitionate
          --WHEN                                                   THEN  &apos;60&apos; --Reduceri comerciale primite
          WHEN TAB = &apos;L&apos; AND TIPDOC IN (7, 24)                     THEN  &apos;70&apos; --Consum
          WHEN TIPDOC = 12                                         THEN  &apos;80&apos; --Transfer intern
          --WHEN                                                   THEN  &apos;90&apos; --Cheltuieli ulterioare incluse ?n valoarea de intrare
          WHEN TIPDOC = 13                                         THEN &apos;100&apos; --Diferente de pret
          WHEN TIPDOC = 15                                         THEN &apos;110&apos; --Plus de inventar
          WHEN TIPDOC = 14                                         THEN &apos;120&apos; --Minus de inventar
          --WHEN                                                   THEN &apos;130&apos; --Ajustari pentru deprecierea stocurilor
          --WHEN                                                   THEN &apos;140&apos; --Reluari de ajustari pentru deprecierea stocurilor
          --WHEN                                                   THEN &apos;150&apos; --Bunuri acordate cu titlu gratuit
          --WHEN                                                   THEN &apos;160&apos; --Bunuri degradate
          --WHEN                                                   THEN &apos;170&apos; --Bunuri expirate
          ELSE                                                          &apos;180&apos; --Alte tranzactii
        END;

    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET (LINES_COUNT, LINES_SUM) = (SELECT Count(1), Sum(Cant) FROM LIVR1 L1 WHERE L1.CODLIVR = T.CODDOC)
    WHERE T.TAB = &apos;L&apos;;

    UPDATE TMP_SAFT_STOCKMOVEMENT T
    SET (LINES_COUNT, LINES_SUM) = (SELECT Count(1), Sum(CantNir) FROM NIRSTOC NS WHERE NS.CODNIR = T.CODDOC)
    WHERE T.TAB = &apos;N&apos;;
  END IF;

  IF pTip = 7 THEN -- Anuala - Active
    PUT_INFO(&apos;00.F22&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODAUX)
    SELECT 22, CODMIFIX, SEQ_SAFT.NEXTVAL, CODMIFIX1
    FROM (
      SELECT CODMIFIX, CODMIFIX1
      FROM (
        SELECT CODMIFIX, CODMIFIX1, Row_Number() OVER (PARTITION BY CODMIFIX ORDER BY AN ASC, LUNA ASC) CODMIFIX_IDX_A
        FROM TMP_SAFT_MIFIX1 m1
      ) ssa
      WHERE ssa.CODMIFIX_IDX_A = 1
      ORDER BY CODMIFIX
    ) ssb;

--    PUT_INFO(&apos;00.F23&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
--    campul AssetSupplier este optional si nu trebuie sa se exporte datele (macar pt moment pt a scapa de erori
--    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
--    SELECT 23, CODFURN, SEQ_SAFT.NEXTVAL
--    FROM (
--      SELECT DISTINCT Coalesce(NS.FURN, 0) CODFURN
--      FROM TMP_SAFT_CODSAF C22
--        INNER JOIN mifix1 m1 ON m1.codmifix1 = C22.CODAUX
--        INNER JOIN nirstoc ns ON ns.codnirstoc = m1.codnirstoc
--      WHERE c22.codsafttab = 22
--      ORDER BY 1
--    ) ssa;

    PUT_INFO(&apos;00.F59&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 59, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 22;

    PUT_INFO(&apos;00.F24&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 24, CODMIFIX1_FIN, SEQ_SAFT.NEXTVAL, CODSAF, CODMIFIX1_INI
    FROM (
      SELECT
        CODSAF,
        Max(CASE WHEN CODMIFIX_IDX_A = 1 THEN CODMIFIX1 ELSE 0 END) CODMIFIX1_INI,
        Max(CASE WHEN CODMIFIX_IDX_D = 1 THEN CODMIFIX1 ELSE 0 END) CODMIFIX1_FIN
      FROM (
        SELECT
          C59.CODSAF, xJ1.ALSTART, M1.CODMIFIX1,
          Row_Number() OVER (PARTITION BY M1.CODMIFIX, xJ1.ALSTART ORDER BY M1.AL ASC ) CODMIFIX_IDX_A,
          Row_Number() OVER (PARTITION BY M1.CODMIFIX, xJ1.ALSTART ORDER BY M1.AL DESC) CODMIFIX_IDX_D
        FROM TMP_SAFT_CODSAF C59
          INNER JOIN (
            SELECT CODMIFIX1, CODMIFIX, AN*12+LUNA AL
            FROM TMP_SAFT_MIFIX1
          ) M1 ON M1.CODMIFIX = C59.CODSURSA
          LEFT JOIN (
            SELECT CODMIFIX, ALSTART, ALSTOP
            FROM (
              SELECT CODMIFIX, Min(AL) ALSTART, Max(AL) ALSTOP
              FROM (
                SELECT
                  TM1.CODMIFIX, NS.CODIOART,
                  ROW_NUMBER () OVER (PARTITION BY TM1.CODMIFIX              ORDER BY TM1.AN, TM1.LUNA) -
                  ROW_NUMBER () OVER (PARTITION BY TM1.CODMIFIX, NS.CODIOART ORDER BY TM1.AN, TM1.LUNA) Grup,
                  TM1.AN*12+TM1.LUNA AL
                FROM TMP_SAFT_MIFIX1 TM1
                  INNER JOIN MIFIX1  M1 ON M1.CODMIFIX1  = TM1.CODMIFIX1
                  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
                  INNER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
              ) aJ1
              GROUP BY aJ1.CODMIFIX, aJ1.CODIOART, aJ1.Grup
            ) bJ1
          ) xJ1 ON xJ1.CODMIFIX = M1.CODMIFIX AND M1.AL BETWEEN xJ1.ALSTART AND xJ1.ALSTOP
        WHERE c59.codsafttab = 59
      ) ssa
      GROUP BY CODSAF, ALSTART
      ORDER BY CODSAF, ALSTART
    ) ssb ;

    PUT_INFO(&apos;00.F60&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSAF, CODPARINTE, CODAUX)
    SELECT 60, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODSURSA
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 24;

    PUT_INFO(&apos;00.F25&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSAF, CODPARINTE, CODAUX)
    SELECT 25, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 60;

--    PUT_INFO(&apos;00.F56&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
--    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
--    SELECT 56, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODAUX
--    FROM TMP_SAFT_CODSAF
--    WHERE codsafttab = 22;

    PUT_INFO(&apos;00.F57&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 57, T.CODJURNAL1, SEQ_SAFT.NEXTVAL AS CODSAF, T.CODPARINTE, T.CODMIFIX1
    FROM (
      SELECT DISTINCT J1.CODJURNAL1, C22.CODSAF AS CODPARINTE, M1.CODMIFIX1
      FROM         TMP_SAFT_JURNAL1 J1
        INNER JOIN TMP_SAFT_MIFIX1  M1  ON M1.CODMIFIX1 = J1.CODMIFIX1
        INNER JOIN TMP_SAFT_CODSAF  C22 ON C22.CODSURSA = M1.CODMIFIX AND C22.CODSAFTTAB = 22
    ) T;

    PUT_INFO(&apos;00.F61&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 61, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF
    WHERE codsafttab = 57;

    PUT_INFO(&apos;00.F58&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
    INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX)
    SELECT 58, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODSAF AS CODPARINTE, CODAUX
    FROM TMP_SAFT_CODSAF C61
    WHERE c61.codsafttab = 61;
  END IF;

  PUT_INFO(&apos;00.F26&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 26, 0, SEQ_SAFT.NEXTVAL FROM DUAL;

  PUT_INFO(&apos;00.F27&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 27, CODJURNAL, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT J.CODJURNAL
    FROM TMP_SAFT_JURNAL J
      INNER JOIN NCONT CD ON CD.CODCONT = J.CONTD
      INNER JOIN NCONT CC ON CC.CODCONT = J.CONTC
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND NOT(CD.CLASA IN (8,9) AND CC.CLASA IN (8,9))
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.F28&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 28, CODJURNAL, SEQ_SAFT.NEXTVAL
  FROM (
    SELECT CODJURNAL
    FROM TMP_SAFT_JURNAL J
    WHERE J.AN*12+J.LUNA BETWEEN v_ALIni AND v_ALFin
      AND pSubunit = CASE WHEN pSubunit = 1 THEN 1 ELSE J.SUBUNITATEA END
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.F3101&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 3101, CODSURSA, SEQ_SAFT.NEXTVAL -- 31 ContD
  FROM (
    SELECT C28.CODSURSA
    FROM TMP_SAFT_CODSAF C28
    WHERE C28.CodSAFTTab = 28
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.F3102&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 3102, CODSURSA, SEQ_SAFT.NEXTVAL -- 31 ContC
  FROM (
    SELECT C28.CODSURSA
    FROM TMP_SAFT_CODSAF C28
    WHERE C28.CodSAFTTab = 28
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.F3103&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX, IDXAUX)
  SELECT 3103, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODPARINTE, CODAUX, IDXAUX -- 31 TVA
  FROM (
    SELECT C31.CODSURSA, C31.CODSAF AS CODPARINTE, TI.CODTI AS CODAUX, TIM.IDXLOCAL AS IDXAUX
    FROM TMP_SAFT_CODSAF C31
      INNER JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31.CODSURSA
      INNER JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODCONT = J.CONTD AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
      LEFT  JOIN TMP_SAFT_TAXINFO_MP TIM ON TIM.CODTI   = TI.CODTI
      LEFT  JOIN TAXDECL             TD  ON TD.TIPDOC   = J.TIPDOC AND TD.CODCONT = J.CONTD AND TD.CODDOC = J.CODDOC
                                        AND TD.TIPDOC IN (28, 35)  AND TD.CHEIA = &apos;&lt;D&apos;||Trim(To_Char(J.CONTD))||&apos;D&gt;&lt;C&apos;||Trim(To_Char(J.CONTC))||&apos;C&gt;&lt;V&apos;||REPLACE(Trim(To_Char(J.VALOARE)),&apos;,&apos;,&apos;.&apos;)||&apos;V&gt;&apos;
    WHERE C31.CodSAFTTab = 3101
      AND CASE WHEN J.TIPDOC IN (28, 35) THEN TD.CODDOC ELSE TI.CODDOC END IS NOT NULL
    ORDER BY 1,2
  ) subs;

  PUT_INFO(&apos;00.F3104&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE, CODAUX, IDXAUX)
  SELECT 3104, CODSURSA, SEQ_SAFT.NEXTVAL AS CODSAF, CODPARINTE, CODAUX, IDXAUX -- 31 TVA
  FROM (
    SELECT C31.CODSURSA, C31.CODSAF AS CODPARINTE, TI.CODTI AS CODAUX, TIM.IDXLOCAL AS IDXAUX
    FROM TMP_SAFT_CODSAF C31
      INNER JOIN TMP_SAFT_JURNAL     J   ON J.CODJURNAL = C31.CODSURSA
      INNER JOIN TMP_SAFT_TAXINFO    TI  ON TI.TIPDOC   = J.TIPDOC AND TI.CODCONT = J.CONTC AND TI.CODDOC = CASE WHEN J.TIPDOC IN (29, 30, 31) THEN J.INDEXLOCAL ELSE J.CODDOC END
      LEFT  JOIN TMP_SAFT_TAXINFO_MP TIM ON TIM.CODTI   = TI.CODTI
      LEFT  JOIN TAXDECL             TD  ON TD.TIPDOC   = J.TIPDOC AND TD.CODCONT = J.CONTC AND TD.CODDOC = J.CODDOC
                                        AND TD.TIPDOC IN (28, 35)  AND TD.CHEIA = &apos;&lt;D&apos;||Trim(To_Char(J.CONTD))||&apos;D&gt;&lt;C&apos;||Trim(To_Char(J.CONTC))||&apos;C&gt;&lt;V&apos;||REPLACE(Trim(To_Char(J.VALOARE)),&apos;,&apos;,&apos;.&apos;)||&apos;V&gt;&apos;
    WHERE C31.CodSAFTTab = 3102
      AND CASE WHEN J.TIPDOC IN (28, 35) THEN TD.CODDOC ELSE TI.CODDOC END IS NOT NULL
    ORDER BY 1,2
  ) subs;

  PUT_INFO(&apos;00.G12&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF)
  SELECT 12, To_Number(TaxType, &apos;999999990&apos;), SEQ_SAFT.NEXTVAL
  FROM (
    SELECT DISTINCT TaxType
    FROM TMP_SAFT_TAXINFO
    ORDER BY 1
  ) subs;

  PUT_INFO(&apos;00.G13&apos;,&apos;BEGIN_SAFT--TMP_SAFT_CODSAF&apos;);
  INSERT INTO TMP_SAFT_CODSAF(CodSAFTTab, CODSURSA, CODSAF, CODPARINTE)
  SELECT 13, To_Number(TaxCode, &apos;999999990&apos;), SEQ_SAFT.NEXTVAL, C12.CODSAF
  FROM (
    SELECT DISTINCT TaxType, TaxCode
    FROM TMP_SAFT_TAXINFO
    ORDER BY 1, 2
  ) subs LEFT JOIN TMP_SAFT_CODSAF C12 ON C12.CodSAFTTab = 12 AND C12.CODSURSA = To_Number(TaxType, &apos;999999990&apos;);

  PUT_INFO(&apos;00.H1&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NCONT&apos;);
  UMPLE_MANEVRA_CONT_FROM_CONST(&apos;SAFTPartConturi&apos;, vLunaFin,vLunaFin);

  INSERT INTO TMP_SAFT_NCONT (
    CODCONT, SIMBOL, CODSAFT, CLASA, DEN_CONT, TIPCONT, NIVEL, NO_SOLDPART, VALID,
    FRUNZA
  )
  WITH /*recursive*/ cRec (CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, CODPARINTE, CODSINTETIC, CODSAFT, LVL, NO_SOLDPART) AS (
    SELECT
      C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, C.CODCONT CODSINTETIC, C.CODSAFT, 0 AS LVL,
      CASE WHEN M.CODUNIC IS NOT NULL THEN 1 ELSE 0 END NO_SOLDPART
    FROM NCONT C
      INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
      LEFT  JOIN (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU = &apos;SAFTPartConturi&apos;) M ON M.CODUNIC = C.CODCONT
    WHERE Coalesce(c.codparinte, 0) = 0
      AND NOT (C.CODCONT = 0 OR C.SIMBOL  = &apos;999&apos; OR C.CLASA = 9)
      AND NOT EXISTS (SELECT 1 FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_ALFin )
      AND NOT Coalesce(NULLIF(C.AnInactiv*12+C.LunaInactiv, 0), v_ALIni) &lt; v_ALIni
    UNION ALL
    SELECT
      C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, CR.CODSINTETIC, Coalesce(C.CODSAFT, CR.CODSAFT), CR.LVL + 1 AS LVL,
      CASE WHEN M.CODUNIC IS NOT NULL THEN 1 ELSE cr.NO_SOLDPART END NO_SOLDPART
    FROM NCONT C
      INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin BETWEEN C1.ALSTART AND C1.ALSTOP
      INNER JOIN cRec   cr ON cr.codcont = C.codparinte
      LEFT  JOIN (SELECT DISTINCT CODUNIC FROM TMP_SAFT_MANEVRA WHERE FILTRU = &apos;SAFTPartConturi&apos;) M ON M.CODUNIC = C.CODCONT
    WHERE NOT EXISTS (SELECT 1 FROM NCONTECHIV CE WHERE CE.CONTVECHI = C.CODCONT AND (CE.AN * 12 + CE.LUNA) &lt;= v_ALFin )
      AND NOT Coalesce(NULLIF(C.AnInactiv*12+C.LunaInactiv, 0), v_ALIni) &lt; v_ALIni
  )
  SELECT
    C.CODCONT, C.SIMBOL, C.CODSAFT, C.CLASA, C.DEN_CONT, Coalesce(C.TIPCONT,0), C.LVL, C.NO_SOLDPART, 0 AS VALID,
    CASE WHEN EXISTS(SELECT 1 FROM cRec xc WHERE xc.CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
  FROM cRec C;

  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_TAXINFO B WHERE B.CODCONT = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_MIFIX1  B WHERE B.CONT    = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_JURNAL  B WHERE B.CONTD   = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_JURNAL  B WHERE B.CONTC   = A.CODCONT);
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTSOLD        B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnIni AND B.LUNA = 1        AND NOT (B.SOLDID  = 0 AND B.SOLDIC  = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTRUL         B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnIni AND B.LUNA = vLunaIni AND NOT (B.RULAJPD = 0 AND B.RULAJPC = 0 AND B.RULAJCD = 0 AND B.RULAJCC = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTSOLD        B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnFin AND B.LUNA = 1        AND NOT (B.SOLDID  = 0 AND B.SOLDIC  = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM NCONTRUL         B WHERE B.CODCONT = A.CODCONT AND B.AN = vAnFin AND B.LUNA = vLunaFin AND NOT (B.RULAJPD = 0 AND B.RULAJPC = 0 AND B.RULAJCD = 0 AND B.RULAJCC = 0));
  UPDATE TMP_SAFT_NCONT A SET VALID = 1 WHERE VALID = 0 AND EXISTS(SELECT 1 FROM TMP_SAFT_NPART   B WHERE B.CODCONT = A.CODCONT) AND NO_SOLDPART = 0;

  DELETE FROM TMP_SAFT_NCONT WHERE VALID = 0;

  IF pTip IN (   7) THEN
    PUT_INFO(&apos;00.H2&apos;,&apos;BEGIN_SAFT--TMP_SAFT_NCONT-active&apos;);
    DELETE FROM TMP_MANEVRA2;
    INSERT INTO TMP_MANEVRA2 SELECT DISTINCT CONT FROM TMP_SAFT_MIFIX1;
    DELETE FROM TMP_MANEVRA2 WHERE CODUNIC IN (SELECT CODCONT FROM TMP_SAFT_NCONT);
    SELECT Count(1) INTO vCount FROM TMP_MANEVRA2;

    IF vCount &gt; 0 THEN
      INSERT INTO TMP_SAFT_NCONT (
        CODCONT, SIMBOL, CODSAFT, CLASA, DEN_CONT, TIPCONT, NIVEL, NO_SOLDPART, VALID,
        FRUNZA
      )
      WITH /*recursive*/ cRec (CODCONT, CLASA, SIMBOL, DEN_CONT, TIPCONT, CODPARINTE, CODSINTETIC, CODSAFT, LVL) AS (
        SELECT C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, C.CODCONT CODSINTETIC, C.CODSAFT, 0 AS LVL
        FROM NCONT C
          INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin &gt;= C1.ALSTART AND v_ALIni &lt;=  C1.ALSTOP
        WHERE Coalesce(c.codparinte, 0) = 0
        UNION ALL
        SELECT C.CODCONT, C.CLASA, C.SIMBOL, C.DEN_CONT, C.TIPCONT, C.CODPARINTE, CR.CODSINTETIC, Coalesce(C.CODSAFT, CR.CODSAFT), CR.LVL + 1 AS LVL
        FROM NCONT C
          INNER JOIN NCONT1 C1 ON C.CODCONT = C1.CODCONT AND v_ALFin &gt;= C1.ALSTART AND v_ALIni &lt;=  C1.ALSTOP
          INNER JOIN cRec   cr ON cr.codcont = C.codparinte
      )
      SELECT
        C.CODCONT, C.SIMBOL, C.CODSAFT, C.CLASA, C.DEN_CONT, Coalesce(C.TIPCONT,0), C.LVL, 0 NO_SOLDPART, 1 AS VALID,
        CASE WHEN EXISTS(SELECT 1 FROM cRec xc WHERE xc.CODPARINTE = C.CODCONT) THEN 0 ELSE 1 END FRUNZA
      FROM TMP_MANEVRA2 T INNER JOIN cRec C ON C.CODCONT = T.CODUNIC;
    END IF;
  END IF;

  UPDATE TMP_SAFT_TAXINFO SET TAXBASE = Round(TAXBASE,2), TAXVAL = Round(TAXVAL,2);
  PUT_INFO(&apos;00.Z&apos;,&apos;BEGIN_SAFT&apos;);

                                   UMPLE_T01;         --SAF_HEADER
                                   UMPLE_T02;         --SAF_SELECTIONCRITERIA
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T03; END IF; --SAF_ACCOUNT
  IF NOT pTip IN (4, 5, 6, 7) THEN UMPLE_T04; END IF; --SAF_CUSTOMER
  IF NOT pTip IN (4, 5, 6, 7) THEN UMPLE_T05; END IF; --SAF_SUPPLIER
                                   UMPLE_T06;         --SAF_COMPANYSTRUCTURE
                                   UMPLE_T07;         --SAF_ADDRESS
                                   UMPLE_T08;         --SAF_CONTACT
                                   UMPLE_T09;         --SAF_CONTACTPERSON
                                   UMPLE_T10;         --SAF_TAXREGISTRATION
                                   UMPLE_T11;         --SAF_BANKACCOUNT
  IF NOT pTip IN (         7) THEN UMPLE_T12; END IF; --SAF_TAXTABLEENTRY
  IF NOT pTip IN (         7) THEN UMPLE_T13; END IF; --SAF_TAXCODEDETAILS
  IF NOT pTip IN (         7) THEN UMPLE_T14; END IF; --SAF_UOMTABLEENTRY
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T15; END IF; --SAF_ANALYSISTYPETABLEENTRY
  IF     pTip IN (4         ) THEN UMPLE_T16; END IF; --SAF_MOVEMENTTYPETABLEENTRY
  IF NOT pTip IN (         7) THEN UMPLE_T17; END IF; --SAF_PRODUCT
  IF NOT pTip IN (   5, 6, 7) THEN UMPLE_T18; END IF; --SAF_TAX
  IF     pTip IN (4         ) THEN UMPLE_T19; END IF; --SAF_PHYSICALSTOCKENTRY
  IF     pTip IN (4         ) THEN UMPLE_T20; END IF; --SAF_STOCKCHARACTERISTICS
--IF     pTip IN (4         ) THEN UMPLE_T21; END IF; --SAF_OWNER
  IF     pTip IN (         7) THEN UMPLE_T22; END IF; --SAF_ASSET
  IF     pTip IN (         7) THEN UMPLE_T23; END IF; --SAF_ASSETSUPPLIER
  IF     pTip IN (         7) THEN UMPLE_T59; END IF; --SAF_VALUATIONS
  IF     pTip IN (         7) THEN UMPLE_T24; END IF; --SAF_VALUATION
  IF     pTip IN (         7) THEN UMPLE_T60; END IF; --SAF_EXTRAORDINARYDEPRECIATIONSFORPERIOD
  IF     pTip IN (         7) THEN UMPLE_T25; END IF; --SAF_EXTRAORDINARYDEPRECIATIONFORPERIOD
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T26; END IF; --SAF_GENERALLEDGERENTRIES
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T27; END IF; --SAF_JOURNAL
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T28; END IF; --SAF_TRANSACTION
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T29; END IF; --SAF_TRANSACTIONLINE
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T30; END IF; --SAF_ANALYSIS
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T31; END IF; --SAF_AMOUNT
  IF NOT pTip IN (   5, 6   ) THEN UMPLE_T32; END IF; --SAF_TAXINFORMATION
  IF     pTip IN (4,       7) THEN UMPLE_T33; END IF; --SAF_SALESINVOICES
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T34; END IF; --SAF_INVOICE
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T35; END IF; --SAF_CUSTOMERINFO
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T36; END IF; --SAF_SUPPLIERINFO
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T37; END IF; --SAF_SHIPPINGPOINT
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T38; END IF; --SAF_INVOICELINE
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T39; END IF; --SAF_ORDERREFERENCES
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T40; END IF; --SAF_DELIVERY
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T41; END IF; --SAF_DELIVERYPERIOD
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T42; END IF; --SAF_REFERENCES
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T43; END IF; --SAF_CREDITNOTE
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T44; END IF; --SAF_INVOICESETTLEMENT
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T45; END IF; --SAF_INVOICEDOCUMENTTOTALS
  IF     pTip IN (4,       7) THEN UMPLE_T46; END IF; --SAF_PURCHASEINVOICES
  IF     pTip IN (4,       7) THEN UMPLE_T47; END IF; --SAF_PAYMENTS
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T48; END IF; --SAF_PAYMENT
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T49; END IF; --SAF_PAYMENTLINE
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T50; END IF; --SAF_PAYMENTSETTLEMENT
--IF NOT pTip IN (   5, 6   ) THEN UMPLE_T51; END IF; --SAF_PAYMENTDOCUMENTTOTALS
  IF     pTip IN (4         ) THEN UMPLE_T52; END IF; --SAF_MOVEMENTOFGOODS
  IF     pTip IN (4         ) THEN UMPLE_T53; END IF; --SAF_STOCKMOVEMENT
  IF     pTip IN (4         ) THEN UMPLE_T54; END IF; --SAF_DOCUMENTREFERENCE
  IF     pTip IN (4         ) THEN UMPLE_T55; END IF; --SAF_STOCKMOVEMENTLINE
  IF     pTip IN (         7) THEN UMPLE_T56; END IF; --SAF_ASSETTRANSACTIONS
  IF     pTip IN (         7) THEN UMPLE_T57; END IF; --SAF_ASSETTRANSACTION
  IF     pTip IN (         7) THEN UMPLE_T61; END IF; --SAF_ASSETTRANSACTIONVALUATIONS
  IF     pTip IN (         7) THEN UMPLE_T58; END IF; --SAF_ASSETTRANSACTIONVALUATION

  COMMIT;
END;

PROCEDURE END_SAFT IS
BEGIN
  IF pSaftDebug THEN
    SAVE_TABLES;
  END IF;
  TRUNCATE_TABLES;

--PT DEBUG decomentati SAVE_TABLES si folositi umatorul SQL:
--SELECT
--&apos;BEGIN
--  pkg_globals.setuserid(&apos;||userid||&apos;);
--  pkg_globals.setcodfirma(&apos;||codfirma||&apos;);
--  PKG_SAFT.BEGIN_SAFT(&apos;||tip||&apos;, &apos;||anfin||&apos;, &apos;||lunafin||&apos;, &apos;||codsubunit||&apos;);
--END;&apos;
--FROM SAV_TMP_SAFT_PARAMS;
END;

PROCEDURE PUT_INFO(pINFOLINE IN VARCHAR2, pDETALII CLOB) IS
  PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  IF pSaftDebug THEN
    INSERT INTO SAFT_INFO VALUES (CURRENT_TIMESTAMP, pINFOLINE, pDETALII);
    COMMIT;
  END IF;
END;

END PKG_SAFT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SALI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD5E417A0E9F3D3F84A3BF0D528873AE19761232</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SALI is


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODSALA INTO Tmp FROM SALI WHERE CODSALA = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	 FOR V_REC IN (SELECT * FROM MESE WHERE CODSALA = RECID)
  LOOP
   -- aici de bagat stergere detalii masa
    DELETE FROM MESE WHERE CODMASA = V_REC.CODMASA;
  END LOOP;
  
  DELETE FROM SALIUSERI WHERE CODSALA = RecId ;
  DELETE FROM SALI WHERE CODSALA = RecId ;
  NotifyModif(2, RecId, &apos;SALI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SALI FIELDS( CODSALA ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_SALI(CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET)
  SELECT CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET 
  FROM 
    SALI 
  WHERE CODSALA = RecId  ;

  INSERT INTO TMP_SALIUSERI 
  SELECT * FROM SALIUSERI WHERE CODSALA = RECID;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  
    SELECT  CODSALA INTO RecId FROM TMP_SALI;

    UPDATE SALI 
    SET
      (CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET) = (SELECT CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET FROM TMP_SALI)
    WHERE 
      CODSALA = RECID;

   DELETE FROM SALIUSERI 
   WHERE 
     CODSALA = RECID
     AND COD NOT IN (SELECT COD FROM TMP_SALIUSERI);
     
    FOR V_REC IN (SELECT * FROM TMP_SALIUSERI)
    LOOP
      IF V_REC.COD &lt; 0 THEN
        INSERT INTO SALIUSERI(COD, CODSALA, USERNAME)
        VALUES (SEQ_SALI_CODSALA.NEXTVAL, RECID, V_REC.USERNAME);
      ELSE
        UPDATE SALIUSERI
        SET
          USERNAME = V_REC.USERNAME
        WHERE
          COD = V_REC.COD;  
      END IF;    
    END LOOP;     

  ELSE  
    SELECT SEQ_SALI_CODSALA.NEXTVAL INTO RECID FROM DUAL;
    
    INSERT INTO SALI(CODSALA, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET)
    SELECT RECID, DENUMIRE, CODPERS, NUMARMESE, CODRESTAURANT, CODCATPRET FROM TMP_SALI;
    
    INSERT INTO SALIUSERI(COD, CODSALA, USERNAME)
    SELECT SEQ_SALI_CODSALA.NEXTVAL, RECID, USERNAME FROM TMP_SALIUSERI;
    
    
  END IF;
  NotifyModif(Operation, RecId, &apos;SALI&apos;);
  COMMIT;
END;


end PKG_SALI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_CATRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A7E65EF743F65C7E87E78CCC593F85F77E691B6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_CATRET IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCATRET INTO Tmp FROM SAL_CATRET WHERE CODCATRET = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc nvarchar2(500);
BEGIN
    SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_CATRET;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATRET&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  SP_LOCKRECORD(RecId);
  DELETE FROM SAL_CATRET WHERE CODCATRET = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SAL_CATRET FIELDS( CODCATRET ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master SAL_CATRET
  INSERT INTO  TMP_SAL_CATRET ( CODCATRET, Denumire, Simbol )
    ( SELECT CODCATRET, Denumire, Simbol FROM SAL_CATRET WHERE CODCATRET = RecId ) ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc nvarchar2(500); 
BEGIN
  SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_CATRET;
  IF Operation = 0 THEN  -- UPDATE
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATRET&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
-- Master SAL_CATRET
    SELECT  CODCATRET INTO RecId FROM TMP_SAL_CATRET;
    UPDATE SAL_CATRET SET (Denumire, Simbol) = ( SELECT Denumire, Simbol FROM TMP_SAL_CATRET )  WHERE CODCATRET = RecId ;
  ELSE  -- INSERT
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATRET&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
-- Master SAL_CATRET
  SELECT SEQ_SAL_CATRET_CODCATRET.NextVal INTO RecId FROM DUAL;
  INSERT INTO  SAL_CATRET ( CODCATRET,Denumire, Simbol ) ( SELECT  RecId, Denumire, Simbol FROM TMP_SAL_CATRET  ) ;
  END IF;
	NotifyModif(Operation, RecId, &apos;SAL_CATRET&apos;);
  COMMIT;
END;

end PKG_SAL_CATRET; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_CATSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>818A63DC946CFA999369034C9EC20646A2D613EC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_CATSPOR IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCATSPOR INTO Tmp FROM SAL_CATSPOR WHERE CODCATSPOR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
   aDoc nvarchar2(500);
BEGIN
  SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_SPORURI;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATSPORURI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  SP_LOCKRECORD(RecId);
  DELETE FROM SAL_CATSPOR WHERE CODCATSPOR = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SAL_CATSPOR FIELDS( CODCATSPOR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master SAL_CATSPOR
  INSERT INTO  TMP_SAL_CATSPOR ( CODCATSPOR, Denumire, Simbol )
    ( SELECT CODCATSPOR, Denumire, Simbol FROM SAL_CATSPOR WHERE CODCATSPOR = RecId ) ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc nvarchar2(500);
BEGIN
  SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_SPORURI;
  IF Operation = 0 THEN  -- UPDATE
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATSPOR&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
-- Master SAL_CATSPOR
    SELECT  CODCATSPOR INTO RecId FROM TMP_SAL_CATSPOR;
    UPDATE SAL_CATSPOR SET (Denumire, Simbol) = ( SELECT Denumire, Simbol FROM TMP_SAL_CATSPOR )  WHERE CODCATSPOR = RecId ;
  ELSE  -- INSERT
-- Master SAL_CATSPOR
   IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CATSPOR&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
  SELECT SEQ_SAL_CATSPOR_CODCATSPOR.NextVal INTO RecId FROM DUAL;
  INSERT INTO  SAL_CATSPOR ( CODCATSPOR,Denumire, Simbol ) ( SELECT  RecId, Denumire, Simbol FROM TMP_SAL_CATSPOR  ) ;
  END IF;
	NotifyModif(Operation, RecId, &apos;SAL_CATSPOR&apos;);
  COMMIT;
END;

end PKG_SAL_CATSPOR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_CONTRPP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D0BB8FCBC547C0802BE7F197054B7F8A4128BEF</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_CONTRPP IS
CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCONTRPP INTO Tmp FROM SAL_CONTRPP WHERE CODCONTRPP = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc   VARCHAR2(500);
BEGIN
  SELECT codCONTRPP INTO aDoc FROM TMP_SAL_CONTRPP;
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CONTRPP&apos;, 
                                      PKG_GLOBALS.USERNAME, &apos;S&apos;, 
                                      RECID,PKG_GLOBALS.FIRMANAME, 
                                      pkg_globals.SUBUNITATE, null, aDoc, null, 
                                      PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  SP_LOCKRECORD(RecId);
  DELETE FROM SAL_CONTRPP1 WHERE CODCONTRPP = RecId ;
  DELETE FROM SAL_CONTRPP WHERE CODCONTRPP = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SAL_CONTRPP FIELDS( CODCONTRPP ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_SAL_CONTRPP1 (   codCONTRPP1 ,
                                    codCONTRPP ,
                                    ANGAJAT ,
                                    NRCONTRACT ,
                                    DATASTART, 
                                    DATASTOP, 
                                    FOND, 
                                    PLATAFIRMA, 
                                    CONTBANCAR, 
                                    MODPLATA, 
                                    RATA, 
                                    ZIPLATA, 
                                    DATAINREG, 
                                    PLAFONLEI, 
                                    PLAFONEURO,
                                    DIFERENTE, 
                                    VALRATEAN, 
                                    RETNEIMPOZ, 
                                    RETIMPOZ)
                        ( SELECT    codCONTRPP1 ,
                                    codCONTRPP ,
                                    ANGAJAT ,
                                    NRCONTRACT ,
                                    DATASTART, 
                                    DATASTOP, 
                                    FOND, 
                                    PLATAFIRMA, 
                                    CONTBANCAR, 
                                    MODPLATA, 
                                    RATA, 
                                    ZIPLATA, 
                                    DATAINREG, 
                                    PLAFONLEI, 
                                    PLAFONEURO,
                                    DIFERENTE, 
                                    VALRATEAN, 
                                    RETNEIMPOZ, 
                                    RETIMPOZ
                            FROM SAL_CONTRPP1 WHERE codCONTRPP = RecId ) ;
-- Master SAL_CONTRPP
  INSERT INTO  TMP_SAL_CONTRPP ( CODCONTRPP, 
                                 SUCURSALA )
    ( SELECT CODCONTRPP, 
             SUCURSALA FROM SAL_CONTRPP WHERE CODCONTRPP = RecId ) ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
   aDoc   VARCHAR2(500);
BEGIN
  SELECT codCONTRPP INTO aDoc FROM TMP_SAL_CONTRPP;
  SELECT codCONTRPP INTO RECID FROM TMP_SAL_CONTRPP;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_CONTRPP&apos;, 
                                      PKG_GLOBALS.USERNAME, &apos;M&apos;, 
                                      RECID,PKG_GLOBALS.FIRMANAME, 
                                      pkg_globals.SUBUNITATE, null, aDoc, null, 
                                      PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

 
  IF Operation = 0 THEN  -- UPDATE

-- Master SAL_CONTRPP
    SELECT  CODCONTRPP INTO RecId FROM TMP_SAL_CONTRPP;
    UPDATE SAL_CONTRPP SET (SUCURSALA) = ( SELECT SUCURSALA FROM TMP_SAL_CONTRPP )  WHERE CODCONTRPP = RecId ;
    
    -- DETAIL SPORURI1
      DELETE FROM SAL_CONTRPP1 WHERE codCONTRPP = RECID AND codCONTRPP1 NOT IN (SELECT codCONTRPP1 FROM TMP_SAL_CONTRPP1);
      INSERT INTO SAL_CONTRPP1 ( codCONTRPP1 ,
                                 codCONTRPP ,
                                    ANGAJAT ,
                                    NRCONTRACT ,
                                    DATASTART, 
                                    DATASTOP, 
                                    FOND, 
                                    PLATAFIRMA, 
                                    CONTBANCAR, 
                                    MODPLATA, 
                                    RATA, 
                                    ZIPLATA, 
                                    DATAINREG, 
                                    PLAFONLEI, 
                                    PLAFONEURO,
                                    DIFERENTE, 
                                    VALRATEAN, 
                                    RETNEIMPOZ, 
                                    RETIMPOZ)
                            SELECT SEQ_SAL_CONTRPP1_CODCONTRPP1.NEXTVAL, 
                                    RECID,  
                                    ANGAJAT ,
                                    NRCONTRACT ,
                                    DATASTART, 
                                    DATASTOP, 
                                    FOND, 
                                    PLATAFIRMA, 
                                    CONTBANCAR, 
                                    MODPLATA, 
                                    RATA, 
                                    ZIPLATA, 
                                    DATAINREG, 
                                    PLAFONLEI, 
                                    PLAFONEURO,
                                    DIFERENTE, 
                                    VALRATEAN, 
                                    RETNEIMPOZ, 
                                    RETIMPOZ
                   FROM TMP_SAL_CONTRPP1 
                   WHERE codCONTRPP1 &lt; 0;
  ELSE  -- INSERT
-- Master SAL_CONTRPP
   IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_SPORURI&apos;, 
                                      PKG_GLOBALS.USERNAME, &apos;M&apos;, 
                                      RECID,PKG_GLOBALS.FIRMANAME, 
                                      pkg_globals.SUBUNITATE, null, aDoc, null, 
                                      PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

  SELECT SEQ_SAL_CONTRPP_CODCONTRPP.NextVal INTO RecId FROM DUAL;
  INSERT INTO  SAL_CONTRPP ( CODCONTRPP, 
                             SUCURSALA ) ( SELECT  RecId, SUCURSALA FROM TMP_SAL_CONTRPP  ) ;
  END IF;
	NotifyModif(Operation, RecId, &apos;SAL_CONTRPP&apos;);
  COMMIT;
END;

end PKG_SAL_CONTRPP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_DEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38E4139F361E7FF588DE278383E9DA5EDDB408CB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_DEDGEN IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT CODDEDGEN
      INTO Tmp
      FROM SAL_DEDGEN
     WHERE CODDEDGEN = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
   aDoc VARCHAR2(500);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_DEDGEN;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_DEDGEN&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_DEDGEN1 WHERE CODDEDGEN = RecId;
    DELETE FROM SAL_DEDGEN0 WHERE CODDEDGEN = RecId;
    DELETE FROM SAL_DEDGEN WHERE CODDEDGEN = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_DEDGEN FIELDS (CODDEDGEN) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT   NUMBER(4);
    ALUNASFARSIT NUMBER(2);
  BEGIN
    INSERT INTO TMP_SAL_DEDGEN0
      (coddedgen0,
       coddedgen,
       contract,
       conventie,
       conventiecm,
       cumuls,
       cumulp,
       special,
       specialcv,
       asimilate,
       calcul,
       marime,
       rot,
       modrot,
       coop,
       internship,
       anstart,
       lunastart,
       alstart,
       alstop)
      (SELECT coddedgen0,
              coddedgen,
              contract,
              conventie,
              conventiecm,
              cumuls,
              cumulp,
              special,
              specialcv,
              asimilate,
              calcul,
              marime,
              rot,
              modrot,
              coop,
              internship,
              anstart,
              lunastart,
              alstart,
              alstop
         FROM SAL_DEDGEN0
        WHERE CODDEDGEN = RecId);
  
    INSERT INTO TMP_SAL_DEDGEN1
      (CODDEDGEN1, CODDEDGEN0, CODDEDGEN, PERS, LIMSUP, LIMINF, RELATIE)
      (SELECT CODDEDGEN1,
              CODDEDGEN0,
              CODDEDGEN,
              PERS,
              LIMSUP,
              LIMINF,
              RELATIE
         FROM SAL_DEDGEN1
        WHERE CODDEDGEN = RecId);
  
    -- Master SAL_DEDGEN
    INSERT INTO TMP_SAL_DEDGEN
      (CODDEDGEN, DENUMIRE, BAZA)
      (SELECT CODDEDGEN, DENUMIRE, BAZA
         FROM SAL_DEDGEN
        WHERE CODDEDGEN = RecId);
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT CODDEDGEN0, ANSTART, LUNASTART
                    FROM TMP_SAL_DEDGEN0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_DEDGEN0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE coddedgen0 = V_REC.CODDEDGEN0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
  
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
    vCod NUMBER(20);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_DEDGEN;
    IF Operation = 0 THEN
      -- UPDATE
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_DEDGEN&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      -- Master SAL_DEDGEN
      SELECT CODDEDGEN INTO RecId FROM TMP_SAL_DEDGEN;
      UPDATE SAL_DEDGEN
         SET (DENUMIRE, BAZA) =
             (SELECT DENUMIRE, BAZA FROM TMP_SAL_DEDGEN)
       WHERE CODDEDGEN = RecId;
      --DELETE 
      DELETE FROM SAL_DEDGEN0
       WHERE coddedgen = RECID
         AND coddedgen0 NOT IN
             (SELECT ts0.coddedgen0 FROM TMP_SAL_DEDGEN0 ts0);
      DELETE FROM SAL_DEDGEN1
       WHERE coddedgen = RECID
         AND (coddedgen0 NOT IN
             (SELECT ts0.coddedgen0 FROM TMP_SAL_DEDGEN0 ts0) 
             or coddedgen1 not in (SELECT ts1.coddedgen1 FROM TMP_SAL_DEDGEN1 ts1))   ;
    
      --UPDATE              
      UPDATE SAL_DEDGEN0 s0
         SET (coddedgen0,
              coddedgen,
              contract,
              conventie,
              conventiecm,
              cumuls,
              cumulp,
              special,
              specialcv,
              asimilate,
              calcul,
              marime,
              rot,
              modrot,
              coop,
              internship,
              anstart,
              lunastart,
              alstart,
              alstop) =
             (SELECT coddedgen0,
                     coddedgen,
                     contract,
                     conventie,
                     conventiecm,
                     cumuls,
                     cumulp,
                     special,
                     specialcv,
                     asimilate,
                     calcul,
                     marime,
                     rot,
                     modrot,
                     coop,
                     internship,
                     anstart,
                     lunastart,
                     alstart,
                     alstop
                FROM TMP_SAL_DEDGEN0 ts
               WHERE ts.coddedgen0 &gt; 0
                 and ts.coddedgen0 = s0.coddedgen0)
       WHERE s0.coddedgen = RecId;
    
      for v_rec in (select * from TMP_SAL_DEDGEN0 WHERE coddedgen0 &lt; 0) loop
        select SEQ_SAL_DEDGEN0_CODDEDGEN0.Nextval into vcod from dual;
        update TMP_SAL_DEDGEN1
           set coddedgen0 = vcod
         where coddedgen0 = v_rec.coddedgen0;
      
        INSERT INTO SAL_DEDGEN0
          (coddedgen0,
           coddedgen,
           contract,
           conventie,
           conventiecm,
           cumuls,
           cumulp,
           special,
           specialcv,
           asimilate,
           calcul,
           marime,
           rot,
           modrot,
           coop,
           internship,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.contract,
           v_rec.conventie,
           v_rec.conventiecm,
           v_rec.cumuls,
           v_rec.cumulp,
           v_rec.special,
           v_rec.specialcv,
           v_rec.asimilate,
           v_rec.calcul,
           v_rec.marime,
           v_rec.rot,
           v_rec.modrot,
           v_rec.coop,
           v_rec.internship,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
      --update/insert SAL_DEDGEN1
      UPDATE SAL_DEDGEN1 s1
         SET (coddedgen1,
              coddedgen0,
              coddedgen,
              pers,
              limsup,
              liminf,
              relatie) =
             (SELECT coddedgen1,
                     coddedgen0,
                     coddedgen,
                     pers,
                     limsup,
                     liminf,
                     relatie
                FROM TMP_SAL_DEDGEN1 ts1
               WHERE ts1.coddedgen1 &gt; 0
                 and ts1.coddedgen1 = s1.coddedgen1)
       WHERE s1.coddedgen1 in (select ti.coddedgen1
                                 from TMP_SAL_DEDGEN1 ti
                                WHERE ti.coddedgen1 &gt; 0);
      INSERT INTO SAL_DEDGEN1
        (coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie)
        SELECT SEQ_SAL_DEDGEN1_CODDEDGEN1.NEXTVAL,
               coddedgen0,
               coddedgen,
               pers,
               limsup,
               liminf,
               relatie
          FROM TMP_SAL_DEDGEN1
         WHERE coddedgen1 &lt; 0;
    
    ELSE
      -- INSERT
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_DEDGEN&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT SEQ_SAL_DEDGEN_CODDEDGEN.NextVal INTO RecId FROM DUAL;
    
      -- Master SAL_DEDGEN
      INSERT INTO SAL_DEDGEN
        (CODDEDGEN, DENUMIRE, BAZA)
        (SELECT RecId, DENUMIRE, BAZA FROM TMP_SAL_DEDGEN);
    
      for v_rec in (select * from TMP_SAL_DEDGEN0) loop
        select SEQ_SAL_DEDGEN0_CODDEDGEN0.Nextval into vcod from dual;
        update TMP_SAL_DEDGEN1
           set coddedgen0 = vcod
         where coddedgen0 = v_rec.coddedgen0;
      
        -- DETAIL SPORURI0
        INSERT INTO SAL_DEDGEN0
          (coddedgen0,
           coddedgen,
           contract,
           conventie,
           conventiecm,
           cumuls,
           cumulp,
           special,
           specialcv,
           asimilate,
           calcul,
           marime,
           rot,
           modrot,
           coop,
           internship,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.contract,
           v_rec.conventie,
           v_rec.conventiecm,
           v_rec.cumuls,
           v_rec.cumulp,
           v_rec.special,
           v_rec.specialcv,
           v_rec.asimilate,
           v_rec.calcul,
           v_rec.marime,
           v_rec.rot,
           v_rec.modrot,
           v_rec.coop,
           v_rec.internship,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
    
      INSERT INTO SAL_DEDGEN1
        (coddedgen1, coddedgen0, coddedgen, pers, limsup, liminf, relatie)
        SELECT SEQ_SAL_DEDGEN1_CODDEDGEN1.NEXTVAL,
               coddedgen0,
               RecId,
               pers,
               limsup,
               liminf,
               relatie
          FROM TMP_SAL_DEDGEN1
         where coddedgen0 &gt; 0;
    
    END IF;
    NotifyModif(Operation, RecId, &apos;SAL_DEDGEN&apos;);
    COMMIT;
  END;

end PKG_SAL_DEDGEN;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_FONDP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23351F9A9C89127E296C9B8AEE3BCEF1829076B1</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_FONDP IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODFONDP INTO Tmp FROM SAL_FONDP WHERE CODFONDP = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
   aDoc nvarchar2(500);
BEGIN
  SELECT denumire INTO aDoc FROM TMP_SAL_SPORURI;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_SPORURI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  SP_LOCKRECORD(RecId);
  DELETE FROM SAL_FONDP WHERE CODFONDP = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SAL_FONDP FIELDS( CODFONDP ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master SAL_FONDP
  INSERT INTO  TMP_SAL_FONDP ( CODFONDP, Denumire )
    ( SELECT CODFONDP, Denumire FROM SAL_FONDP WHERE CODFONDP = RecId ) ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc nvarchar2(500);
BEGIN
   SELECT denumire INTO aDoc FROM TMP_SAL_SPORURI;
  IF Operation = 0 THEN  -- UPDATE
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_FONDP&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
-- Master SAL_FONDP
    SELECT  CODFONDP INTO RecId FROM TMP_SAL_FONDP;
    UPDATE SAL_FONDP SET (Denumire) = ( SELECT Denumire FROM TMP_SAL_FONDP )  WHERE CODFONDP = RecId ;
  ELSE  -- INSERT
     IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_FONDP&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
-- Master SAL_FONDP
  SELECT SEQ_SAL_FONDP_CODFONDP.NextVal INTO RecId FROM DUAL;
  INSERT INTO  SAL_FONDP ( CODFONDP,Denumire ) ( SELECT  RecId, Denumire FROM TMP_SAL_FONDP  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;SAL_FONDP&apos;);
  COMMIT;
END;

end PKG_SAL_FONDP; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_IMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>743AC1F4DD957AFC656F103B861B11C14FD49FEB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_IMPOZ IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT CODIMPOZ
      INTO Tmp
      FROM SAL_IMPOZ
     WHERE CODIMPOZ = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
   aDoc VARCHAR2(500);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_IMPOZ;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_IMPOZ&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_IMPOZ1 WHERE CODIMPOZ = RecId;
    DELETE FROM SAL_IMPOZ0 WHERE CODIMPOZ = RecId;
    DELETE FROM SAL_IMPOZ WHERE CODIMPOZ = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_IMPOZ FIELDS (CODIMPOZ) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT   NUMBER(4);
    ALUNASFARSIT NUMBER(2);
  BEGIN
    INSERT INTO TMP_SAL_IMPOZ0
      (codimpoz0,
       codimpoz,
       lacontr,
       laconv,
       laconvcm,
       lacumulsal,
       lacumulpens,
       laspecial,
       laspecialcv,
       laasimilate,
       rot,
       trunchiere,
       coop,
       internship,
       anstart,
       lunastart,
       alstart,
       alstop)
      (SELECT codimpoz0,
              codimpoz,
              lacontr,
              laconv,
              laconvcm,
              lacumulsal,
              lacumulpens,
              laspecial,
              laspecialcv,
              laasimilate,
              rot,
              trunchiere,
              coop,
              internship,
              anstart,
              lunastart,
              alstart,
              alstop
         FROM SAL_IMPOZ0
        WHERE CODIMPOZ = RecId);
  
    INSERT INTO TMP_SAL_IMPOZ1
      (CODIMPOZ1, CODIMPOZ0, CODIMPOZ, LIMINF, LIMSUP, VALFIXA, PROCENT)
      (SELECT CODIMPOZ1,
              CODIMPOZ0,
              CODIMPOZ,
              LIMINF,
              LIMSUP,
              VALFIXA,
              PROCENT
         FROM SAL_IMPOZ1
        WHERE CODIMPOZ = RecId);
  
    -- Master SAL_IMPOZ
    INSERT INTO TMP_SAL_IMPOZ
      (CODIMPOZ, DENUMIRE, LUNAR)
      (SELECT CODIMPOZ, DENUMIRE, LUNAR
         FROM SAL_IMPOZ
        WHERE CODIMPOZ = RecId);
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT CODIMPOZ0, ANSTART, LUNASTART
                    FROM TMP_SAL_IMPOZ0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_IMPOZ0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE codimpoz0 = V_REC.CODIMPOZ0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
  
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
    vCod NUMBER(20);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_IMPOZ;
    IF Operation = 0 THEN
      -- UPDATE
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_IMPOZ&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
      -- Master SAL_IMPOZ
      SELECT CODIMPOZ INTO RecId FROM TMP_SAL_IMPOZ;
      UPDATE SAL_IMPOZ
         SET (DENUMIRE, LUNAR) =
             (SELECT DENUMIRE, LUNAR FROM TMP_SAL_IMPOZ)
       WHERE CODIMPOZ = RecId;
      --DELETE 
      DELETE FROM SAL_IMPOZ0
       WHERE codimpoz = RECID
         AND codimpoz0 NOT IN
             (SELECT ts0.codimpoz0 FROM TMP_SAL_IMPOZ0 ts0);
      DELETE FROM SAL_IMPOZ1
       WHERE codimpoz = RECID
         AND (codimpoz0 NOT IN
             (SELECT ts0.codimpoz0 FROM TMP_SAL_IMPOZ0 ts0) or
             codimpoz1 not in
             (SELECT ts1.codimpoz1 FROM TMP_SAL_IMPOZ1 ts1));
    
      --UPDATE              
      UPDATE SAL_IMPOZ0 s0
         SET (codimpoz0,
              codimpoz,
              lacontr,
              laconv,
              laconvcm,
              lacumulsal,
              lacumulpens,
              laspecial,
              laspecialcv,
              laasimilate,
              rot,
              trunchiere,
              coop,
              internship,
              anstart,
              lunastart,
              alstart,
              alstop) =
             (SELECT codimpoz0,
                     codimpoz,
                     lacontr,
                     laconv,
                     laconvcm,
                     lacumulsal,
                     lacumulpens,
                     laspecial,
                     laspecialcv,
                     laasimilate,
                     rot,
                     trunchiere,
                     coop,
                     internship,
                     anstart,
                     lunastart,
                     alstart,
                     alstop
                FROM TMP_SAL_IMPOZ0 ts
               WHERE ts.codimpoz0 &gt; 0
                 and ts.codimpoz0 = s0.codimpoz0)
       WHERE s0.codimpoz = RecId;
    
      for v_rec in (select * from TMP_SAL_IMPOZ0 WHERE codimpoz0 &lt; 0) loop
        select SEQ_SAL_IMPOZ0_CODIMPOZ0.Nextval into vcod from dual;
        update TMP_SAL_IMPOZ1
           set codimpoz0 = vcod
         where codimpoz0 = v_rec.codimpoz0;
      
        INSERT INTO SAL_IMPOZ0
          (codimpoz0,
           codimpoz,
           lacontr,
           laconv,
           laconvcm,
           lacumulsal,
           lacumulpens,
           laspecial,
           laspecialcv,
           laasimilate,
           rot,
           trunchiere,
           coop,
           internship,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.lacontr,
           v_rec.laconv,
           v_rec.laconvcm,
           v_rec.lacumulsal,
           v_rec.lacumulpens,
           v_rec.laspecial,
           v_rec.laspecialcv,
           v_rec.laasimilate,
           v_rec.rot,
           v_rec.trunchiere,
           v_rec.coop,
           v_rec.internship,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
      --update/insert SAL_IMPOZ1
      UPDATE SAL_IMPOZ1 s1
         SET (codimpoz1,
              codimpoz0,
              codimpoz,
              liminf,
              limsup,
              valfixa,
              procent) =
             (SELECT codimpoz1,
                     codimpoz0,
                     codimpoz,
                     liminf,
                     limsup,
                     valfixa,
                     procent
                FROM TMP_SAL_IMPOZ1 ts1
               WHERE ts1.codimpoz1 &gt; 0
                 and ts1.codimpoz1 = s1.codimpoz1)
       WHERE s1.codimpoz1 in (select ti.codimpoz1
                                from TMP_SAL_IMPOZ1 ti
                               WHERE ti.codimpoz1 &gt; 0);
      INSERT INTO SAL_IMPOZ1
        (codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent)
        SELECT SEQ_SAL_IMPOZ1_CODIMPOZ1.NEXTVAL,
               codimpoz0,
               codimpoz,
               liminf,
               limsup,
               valfixa,
               procent
          FROM TMP_SAL_IMPOZ1
         WHERE codimpoz1 &lt; 0;
    
    ELSE
      -- INSERT
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_IMPOZ&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT SEQ_SAL_IMPOZ_CODIMPOZ.NextVal INTO RecId FROM DUAL;
    
      -- Master SAL_IMPOZ
      INSERT INTO SAL_IMPOZ
        (CODIMPOZ, DENUMIRE, LUNAR)
        (SELECT RecId, DENUMIRE, LUNAR FROM TMP_SAL_IMPOZ);
    
      for v_rec in (select * from TMP_SAL_IMPOZ0) loop
        select SEQ_SAL_IMPOZ0_CODIMPOZ0.Nextval into vcod from dual;
        update TMP_SAL_IMPOZ1
           set codimpoz0 = vcod
         where codimpoz0 = v_rec.codimpoz0;
      
        -- DETAIL SPORURI0
        INSERT INTO SAL_IMPOZ0
          (codimpoz0,
           codimpoz,
           lacontr,
           laconv,
           laconvcm,
           lacumulsal,
           lacumulpens,
           laspecial,
           laspecialcv,
           laasimilate,
           rot,
           trunchiere,
           coop,
           internship,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.lacontr,
           v_rec.laconv,
           v_rec.laconvcm,
           v_rec.lacumulsal,
           v_rec.lacumulpens,
           v_rec.laspecial,
           v_rec.laspecialcv,
           v_rec.laasimilate,
           v_rec.rot,
           v_rec.trunchiere,
           v_rec.coop,
           v_rec.internship,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
    
      INSERT INTO SAL_IMPOZ1
        (codimpoz1, codimpoz0, codimpoz, liminf, limsup, valfixa, procent)
        SELECT SEQ_SAL_IMPOZ1_CODIMPOZ1.NEXTVAL,
               codimpoz0,
               RecId,
               liminf,
               limsup,
               valfixa,
               procent
          FROM TMP_SAL_IMPOZ1
         where codimpoz0 &gt; 0;
    
    END IF;
    NotifyModif(Operation, RecId, &apos;SAL_IMPOZ&apos;);
    COMMIT;
  END;

end PKG_SAL_IMPOZ;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_NASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAA909DEFFA0213E80A92EB73F0375927F7DF350</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_NASIG IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT codnasig
      INTO Tmp
      FROM SAL_NASIG
     WHERE codnasig = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
    aDoc VARCHAR2(500);
  BEGIN
    SELECT tip INTO aDoc FROM TMP_SAL_NASIG;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                            CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NASIG&apos;,
                                       PKG_GLOBALS.USERNAME,
                                       &apos;S&apos;,
                                       RECID,
                                       PKG_GLOBALS.FIRMANAME,
                                       pkg_globals.SUBUNITATE,
                                       null,
                                       aDoc,
                                       null,
                                       PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_NASIG3 SG3
     WHERE SG3.codnasig0 IN (SELECT ISG0.codnasig0
                               FROM SAL_NASIG0 ISG0
                              WHERE ISG0.codnasig = RecId);
    DELETE FROM SAL_NASIG2 SG2
     WHERE SG2.codnasig0 IN (SELECT ISG0.codnasig0
                               FROM SAL_NASIG0 ISG0
                              WHERE ISG0.codnasig = RecId);
    DELETE FROM SAL_NASIG1 SG1
     WHERE SG1.codnasig0 IN (SELECT ISG0.codnasig0
                               FROM SAL_NASIG0 ISG0
                              WHERE ISG0.codnasig = RecId);
    DELETE FROM SAL_NASIG0 WHERE codnasig = RecId;
    DELETE FROM SAL_NASIG WHERE codnasig = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_NASIG FIELDS (codnasig) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT   NUMBER(4);
    ALUNASFARSIT NUMBER(2);
    codAsig0Debug NUMBER(20);
    nrInreg       Number(20);
  BEGIN
    -- Master SAL_NASIG
    INSERT INTO TMP_SAL_NASIG
      (codnasig, tip, codasig, caracter, intrerupere)
      (SELECT codnasig, tip, codasig, caracter, intrerupere
         FROM SAL_NASIG
        WHERE codnasig = RecId);
    -- DETAIL SAL_NASIG0
    INSERT INTO TMP_SAL_NASIG0
      (codnasig0,
       codnasig,
       Bazacalcul,
       Angajator,
       Cont1,
       Asigurare,
       Cont2,
       ContribSalMinEcFirma,
       ContribSalMinEcCAS,
       Penalizare,
       Impozit,
       CrestereCopil,
       SuspendareCM,
       Buget,
       NoAngajat,
       NoAngajator,
       ZilePlataFirma,
       NeavizatCAS,
       Plafonare,
       NoDeducere,
       Constructii,
       ANSTART,
       LUNASTART,
       ALSTART,
       ALSTOP)
      (SELECT codnasig0,
              codnasig,
              Bazacalcul,
              Angajator,
              Cont1,
              Asigurare,
              Cont2,
              ContribSalMinEcFirma,
              ContribSalMinEcCAS,
              Penalizare,
              Impozit,
              CrestereCopil,
              SuspendareCM,
              Buget,
              NoAngajat,
              NoAngajator,
              ZilePlataFirma,
              NeavizatCAS,
              Plafonare,
              NoDeducere,
              Constructii,
              ANSTART,
              LUNASTART,
              ALSTART,
              ALSTOP
         FROM SAL_NASIG0
        WHERE codnasig = RecId);
    -- DETAIL SAL_NASIG1
    INSERT INTO TMP_SAL_NASIG1
      (codnasig1,
       codnasig0,
       modcalcul,
       conditionare,
       umv,
       dmodcalc,
       dcond,
       dum)
      (SELECT nasg1.codnasig1,
              nasg1.codnasig0,
              nasg1.modcalcul,
              nasg1.conditionare,
              nasg1.umv,
              mdc.denumire,
              condas.denumire,
              case nasg1.umv 
                when 0 then &apos;&apos;
                when 1 then &apos;luni&apos;
                when 2 then &apos;ani&apos;
                else &apos;???&apos; end as dum
         FROM SAL_NASIG1 nasg1
         LEFT JOIN SAL_NMODC mdc
           on mdc.codmodc = nasg1.modcalcul
         LEFT JOIN SAL_NCONDAS condas
           on condas.codncondas = nasg1.conditionare
        WHERE codnasig0 IN
              (SELECT tnasig.codnasig0 from TMP_SAL_NASIG0 tnasig));
    -- DETAIL SAL_NASIG2
    INSERT INTO TMP_SAL_NASIG2
      (codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup)
      (SELECT codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
         FROM SAL_NASIG2
        WHERE codnasig0 IN
              (SELECT tnasig.codnasig0 from TMP_SAL_NASIG0 tnasig));
    -- DETAIL SAL_NASIG3 
    INSERT INTO TMP_SAL_NASIG3
      (codnasig3,
       codnasig0,
       tip,
       elemcalcul,
       multiplicare,
       codcont,
       contributie)
      (SELECT codnasig3,
              codnasig0,
              tip,
              elemcalcul,
              multiplicare,
              codcont,
              contributie
         FROM SAL_NASIG3
        WHERE codnasig0 IN
              (SELECT tnasig.codnasig0 from TMP_SAL_NASIG0 tnasig));
  
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT codnasig0, ANSTART, LUNASTART
                    FROM TMP_SAL_NASIG0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_NASIG0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE codnasig0 = V_REC.codnasig0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
    vCod NUMBER(20);
  BEGIN
    SELECT tip INTO aDoc FROM TMP_SAL_NASIG;
    IF Operation = 0 THEN
      -- UPDATE
      -- Master SAL_NASIG
      SELECT codnasig INTO RECID FROM TMP_SAL_NASIG;
    
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NASIG&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      UPDATE SAL_NASIG
         SET (codnasig, tip, codasig, caracter, intrerupere) =
             (SELECT codnasig, tip, codasig, caracter, intrerupere
                FROM TMP_SAL_NASIG)
       WHERE codnasig = RecId;
      DELETE FROM SAL_NASIG3
       where (codnasig0 in (SELECT nasig0.codnasig0
                              from SAL_NASIG0 nasig0
                             where nasig0.codnasig = RecId) and
             codnasig3 not in (Select codnasig3 from TMP_SAL_NASIG3))
          OR (codnasig0 in (SELECT nasig0.codnasig0
                              from SAL_NASIG0 nasig0
                              left join TMP_SAL_NASIG0 tns0
                                on tns0.codnasig0 = nasig0.codnasig0
                             where nasig0.codnasig = RecId
                               and tns0.codnasig0 is null));
    
      DELETE FROM SAL_NASIG2
       where (codnasig0 in (SELECT nasig0.codnasig0
                              from SAL_NASIG0 nasig0
                             where nasig0.codnasig = RecId) and
             codnasig2 not in (Select codnasig2 from TMP_SAL_NASIG2))
          OR (codnasig0 in (SELECT nasig0.codnasig0
                              from SAL_NASIG0 nasig0
                              left join TMP_SAL_NASIG0 tns0
                                on tns0.codnasig0 = nasig0.codnasig0
                             where nasig0.codnasig = RecId
                               and tns0.codnasig0 is null));
    
      DELETE FROM SAL_NASIG1
       where (codnasig0 in (SELECT nasig0.codnasig0
                             from SAL_NASIG0 nasig0
                            where nasig0.codnasig = RecId)
         and codnasig1 not in (Select codnasig1 from TMP_SAL_NASIG1))
          OR (codnasig0 in (SELECT nasig0.codnasig0
                              from SAL_NASIG0 nasig0
                              left join TMP_SAL_NASIG0 tns0
                                on tns0.codnasig0 = nasig0.codnasig0
                             where nasig0.codnasig = RecId
                               and tns0.codnasig0 is null));
    
      DELETE FROM SAL_NASIG0
       where codnasig = RecId
         and codnasig0 not in (Select codnasig0 from TMP_SAL_NASIG0);
    
      UPDATE SAL_NASIG0 asg0
         SET (codnasig0,
              codnasig,
              Bazacalcul,
              Angajator,
              Cont1,
              Asigurare,
              Cont2,
              ContribSalMinEcFirma,
              ContribSalMinEcCAS,
              Penalizare,
              Impozit,
              CrestereCopil,
              SuspendareCM,
              Buget,
              NoAngajat,
              NoAngajator,
              ZilePlataFirma,
              NeavizatCAS,
              Plafonare,
              NoDeducere,
              Constructii,
              ANSTART,
              LUNASTART,
              ALSTART,
              ALSTOP) =
             (SELECT codnasig0,
                     codnasig,
                     Bazacalcul,
                     Angajator,
                     Cont1,
                     Asigurare,
                     Cont2,
                     ContribSalMinEcFirma,
                     ContribSalMinEcCAS,
                     Penalizare,
                     Impozit,
                     CrestereCopil,
                     SuspendareCM,
                     Buget,
                     NoAngajat,
                     NoAngajator,
                     ZilePlataFirma,
                     NeavizatCAS,
                     Plafonare,
                     NoDeducere,
                     Constructii,
                     ANSTART,
                     LUNASTART,
                     ALSTART,
                     ALSTOP
                FROM TMP_SAL_NASIG0 tnc
               WHERE tnc.codnasig0 &gt; 0
                 and tnc.codnasig0 = asg0.codnasig0)
       WHERE asg0.codnasig = RecId;
    
      for v_rec in (select * from TMP_SAL_NASIG0 WHERE codnasig0 &lt; 0) loop
        select SEQ_SAL_NASIG0_CODNASIG0.Nextval into vcod from dual;
        update TMP_SAL_NASIG1
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
        update TMP_SAL_NASIG2
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
        update TMP_SAL_NASIG3
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
      
        INSERT INTO SAL_NASIG0
          (codnasig0,
           codnasig,
           Bazacalcul,
           Angajator,
           Cont1,
           Asigurare,
           Cont2,
           ContribSalMinEcFirma,
           ContribSalMinEcCAS,
           Penalizare,
           Impozit,
           CrestereCopil,
           SuspendareCM,
           Buget,
           NoAngajat,
           NoAngajator,
           ZilePlataFirma,
           NeavizatCAS,
           Plafonare,
           NoDeducere,
           Constructii,
           ANSTART,
           LUNASTART,
           ALSTART,
           ALSTOP)
        VALUES
          (vcod,
           RecId,
           v_rec.Bazacalcul,
           v_rec.Angajator,
           v_rec.Cont1,
           v_rec.Asigurare,
           v_rec.Cont2,
           v_rec.ContribSalMinEcFirma,
           v_rec.ContribSalMinEcCAS,
           v_rec.Penalizare,
           v_rec.Impozit,
           v_rec.CrestereCopil,
           v_rec.SuspendareCM,
           v_rec.Buget,
           v_rec.NoAngajat,
           v_rec.NoAngajator,
           v_rec.ZilePlataFirma,
           v_rec.NeavizatCAS,
           v_rec.Plafonare,
           v_rec.NoDeducere,
           v_rec.Constructii,
           v_rec.ANSTART,
           v_rec.LUNASTART,
           v_rec.ALSTART,
           v_rec.ALSTOP);
      end loop;
      --update/insert nasig1
      UPDATE SAL_NASIG1 asg1
         SET (codnasig1, codnasig0, modcalcul, conditionare, umv) =
             (SELECT codnasig1, codnasig0, modcalcul, conditionare, umv
                FROM TMP_SAL_NASIG1 tasg
               WHERE tasg.codnasig1 &gt; 0
                 and tasg.codnasig1 = asg1.codnasig1)
       WHERE asg1.codnasig1 in (select ti.codnasig1
                                  from TMP_SAL_NASIG1 ti
                                 WHERE ti.codnasig1 &gt; 0);
      for v_rec in (select * from TMP_SAL_NASIG1 WHERE codnasig1 &lt; 0) loop
        select SEQ_SAL_NASIG1_CODNASIG1.Nextval into vcod from dual;
        update TMP_SAL_NASIG2
           set codnasig1 = vcod
         where codnasig1 = v_rec.codnasig1;
        INSERT INTO SAL_NASIG1
          (codnasig1, codnasig0, modcalcul, conditionare, umv)
        VALUES
          (vcod,
           v_rec.codnasig0,
           v_rec.modcalcul,
           v_rec.conditionare,
           v_rec.umv);
      end loop;
    
      --update/insert nasig2
      UPDATE SAL_NASIG2 asg2
         SET (codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup) =
             (SELECT codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup
                FROM TMP_SAL_NASIG2 tasg
               WHERE tasg.codnasig2 &gt; 0
                 and tasg.codnasig2 = asg2.codnasig2)
       WHERE asg2.codnasig2 in (select ti.codnasig2
                                  from TMP_SAL_NASIG2 ti
                                 WHERE ti.codnasig2 &gt; 0);
    
      INSERT INTO SAL_NASIG2
        (codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup)
        (SELECT SEQ_SAL_NASIG2_CODNASIG2.NEXTVAL,
                codnasig0,
                codnasig1,
                cuantum,
                liminf,
                limsup
           FROM TMP_SAL_NASIG2 tnc
          WHERE tnc.codnasig2 &lt; 0);
      --update/insert nasig3  
      UPDATE SAL_NASIG3 asg3
         SET (codnasig3,
              codnasig0,
              tip,
              elemcalcul,
              multiplicare,
              codcont,
              contributie) =
             (SELECT codnasig3,
                     codnasig0,
                     tip,
                     elemcalcul,
                     multiplicare,
                     codcont,
                     contributie
                FROM TMP_SAL_NASIG3 tasg
               WHERE tasg.codnasig3 &gt; 0
                 and tasg.codnasig3 = asg3.codnasig3)
       WHERE asg3.codnasig3 in (select ti.codnasig3
                                  from TMP_SAL_NASIG3 ti
                                 WHERE ti.codnasig3 &gt; 0);
    
      INSERT INTO SAL_NASIG3
        (codnasig3,
         codnasig0,
         tip,
         elemcalcul,
         multiplicare,
         codcont,
         contributie)
        (SELECT SEQ_SAL_NASIG3_CODNASIG3.NEXTVAL,
                codnasig0,
                tip,
                elemcalcul,
                multiplicare,
                codcont,
                contributie
           FROM TMP_SAL_NASIG3 tnc
          WHERE tnc.codnasig3 &lt; 0);
    
    ELSE
      -- INSERT
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NASIG&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT SEQ_SAL_NASIG_codnasig.NextVal INTO RecId FROM DUAL;
      -- Master SAL_NASIG
      INSERT INTO SAL_NASIG
        (codnasig, tip, codasig, caracter, intrerupere)
        (SELECT RecId, tip, codasig, caracter, intrerupere
           FROM TMP_SAL_NASIG);
    
      for v_rec in (select * from TMP_SAL_NASIG0) loop
        select SEQ_SAL_NASIG0_CODNASIG0.Nextval into vcod from dual;
        update TMP_SAL_NASIG1
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
        update TMP_SAL_NASIG2
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
        update TMP_SAL_NASIG3
           set codnasig0 = vcod
         where codnasig0 = v_rec.codnasig0;
        --insert nasig0
        INSERT INTO SAL_NASIG0
          (codnasig0,
           codnasig,
           Bazacalcul,
           Angajator,
           Cont1,
           Asigurare,
           Cont2,
           ContribSalMinEcFirma,
           ContribSalMinEcCAS,
           Penalizare,
           Impozit,
           CrestereCopil,
           SuspendareCM,
           Buget,
           NoAngajat,
           NoAngajator,
           ZilePlataFirma,
           NeavizatCAS,
           Plafonare,
           NoDeducere,
           Constructii,
           ANSTART,
           LUNASTART,
           ALSTART,
           ALSTOP)
        VALUES
          (vcod,
           RecId,
           v_rec.Bazacalcul,
           v_rec.Angajator,
           v_rec.Cont1,
           v_rec.Asigurare,
           v_rec.Cont2,
           v_rec.ContribSalMinEcFirma,
           v_rec.ContribSalMinEcCAS,
           v_rec.Penalizare,
           v_rec.Impozit,
           v_rec.CrestereCopil,
           v_rec.SuspendareCM,
           v_rec.Buget,
           v_rec.NoAngajat,
           v_rec.NoAngajator,
           v_rec.ZilePlataFirma,
           v_rec.NeavizatCAS,
           v_rec.Plafonare,
           v_rec.NoDeducere,
           v_rec.Constructii,
           v_rec.ANSTART,
           v_rec.LUNASTART,
           v_rec.ALSTART,
           v_rec.ALSTOP);
      end loop;
      --insert nasig1
      for v_rec in (select * from TMP_SAL_NASIG1) loop
        select SEQ_SAL_NASIG1_CODNASIG1.Nextval into vcod from dual;
        update TMP_SAL_NASIG2
           set codnasig1 = vcod
         where codnasig1 = v_rec.codnasig1;
        INSERT INTO SAL_NASIG1
          (codnasig1, codnasig0, modcalcul, conditionare, umv)
        VALUES
          (vcod,
           v_rec.codnasig0,
           v_rec.modcalcul,
           v_rec.conditionare,
           v_rec.umv);
      end loop;
      --insert nasig2
      INSERT INTO SAL_NASIG2
        (codnasig2, codnasig0, codnasig1, cuantum, liminf, limsup)
        (SELECT SEQ_SAL_NASIG2_CODNASIG2.NEXTVAL,
                codnasig0,
                codnasig1,
                cuantum,
                liminf,
                limsup
           FROM TMP_SAL_NASIG2 tnc);
    
      --insert nasig3
      INSERT INTO SAL_NASIG3
        (codnasig3,
         codnasig0,
         tip,
         elemcalcul,
         multiplicare,
         codcont,
         contributie)
        (SELECT SEQ_SAL_NASIG3_CODNASIG3.NEXTVAL,
                codnasig0,
                tip,
                elemcalcul,
                multiplicare,
                codcont,
                contributie
           FROM TMP_SAL_NASIG3 tnc
          WHERE tnc.codnasig3 &lt; 0);
    END IF;
    PRC_AL_REFRESH(&apos;SAL_NASIG0&apos;, RECID);
    NotifyModif(Operation, RecId, &apos;SAL_NASIG&apos;);
    COMMIT;
  END;

end PKG_SAL_NASIG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_NCONTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91EDB3E5D4213B945CBC437F789CD29EE1F0DC3F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_NCONTRIB IS
CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codncontrib INTO Tmp FROM SAL_NCONTRIB WHERE codncontrib = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc   VARCHAR2(500);
BEGIN
  SELECT denumire INTO aDoc FROM TMP_SAL_NCONTRIB;
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NCONTRIB&apos;,
                                      PKG_GLOBALS.USERNAME, &apos;S&apos;,
                                      RECID,PKG_GLOBALS.FIRMANAME,
                                      pkg_globals.SUBUNITATE, null, aDoc, null,
                                      PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  SP_LOCKRECORD(RecId);
  DELETE FROM SAL_NCONTRIB1  WHERE codncontrib = RecId ;
  DELETE FROM SAL_NCONTRIB  WHERE codncontrib = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SAL_NCONTRIB FIELDS( codncontrib ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  AANSFARSIT   NUMBER(4);
  ALUNASFARSIT NUMBER(2);
BEGIN
    -- Master SAL_NCONTRIB
    INSERT INTO  TMP_SAL_NCONTRIB ( codncontrib,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie    )
                        ( SELECT codncontrib,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie
                            FROM SAL_NCONTRIB WHERE codncontrib = RecId ) ;
-- DETAIL SAL_NCONTRIB1
          INSERT INTO  TMP_SAL_NCONTRIB1 ( codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP
                                  )
                        ( SELECT codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP
                            FROM SAL_NCONTRIB1 WHERE codncontrib = RecId ) ;
  AANSFARSIT := 0; ALUNASFARSIT := 0;
  FOR V_REC IN (SELECT codncontrib1, ANSTART, LUNASTART FROM TMP_SAL_NCONTRIB1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (AANSFARSIT &lt;&gt; 0)AND(ALUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_SAL_NCONTRIB1
      SET
        ANSFARSIT   = AANSFARSIT,
        LUNASFARSIT = ALUNASFARSIT
       WHERE
       codncontrib1 = V_REC.codncontrib1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, AANSFARSIT, ALUNASFARSIT);
  END LOOP;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc   VARCHAR2(500);
BEGIN
  SELECT denumire INTO aDoc FROM TMP_SAL_NCONTRIB;
  IF Operation = 0 THEN  -- UPDATE
    -- Master SAL_NCONTRIB
    SELECT  codncontrib INTO RECID FROM TMP_SAL_NCONTRIB;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NCONTRIB&apos;,
                                      PKG_GLOBALS.USERNAME, &apos;M&apos;,
                                      RECID,PKG_GLOBALS.FIRMANAME,
                                      pkg_globals.SUBUNITATE, null, aDoc, null,
                                      PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE SAL_NCONTRIB SET (codncontrib,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie    ) =
                   ( SELECT codncontrib,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie    FROM TMP_SAL_NCONTRIB )  WHERE codncontrib = RecId ;

     DELETE FROM SAL_NCONTRIB1 where codncontrib = RecId and codncontrib1 not in (Select codncontrib1 from TMP_SAL_NCONTRIB1);
     
     UPDATE SAL_NCONTRIB1 nc SET (codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP                 ) =
                   ( SELECT      codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP               FROM TMP_SAL_NCONTRIB1 tnc WHERE tnc.codncontrib1 &gt; 0 and tnc.codncontrib1 = nc.codncontrib1 )
                     WHERE nc.codncontrib = RecId;
    INSERT INTO SAL_NCONTRIB1  (codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP                 )
                   ( SELECT SEQ_SAL_NCONTRIB1_CODNCONTRIB1.Nextval,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP               FROM TMP_SAL_NCONTRIB1  WHERE codncontrib1 &lt; 0 );

  ELSE  -- INSERT
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NCONTRIB&apos;,
                                      PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                      RECID,PKG_GLOBALS.FIRMANAME,
                                      pkg_globals.SUBUNITATE, null, aDoc, null,
                                      PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    SELECT SEQ_SAL_NCONTRIB_CODNCONTRIB.NextVal INTO RecId FROM DUAL;
    -- Master SAL_NCONTRIB
    INSERT INTO  SAL_NCONTRIB (   codncontrib,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie     )
                    ( SELECT      RecId,
                                  Tip               ,
                                  Denumire          ,
                                  TipContributie
                         FROM TMP_SAL_NCONTRIB  ) ;

    INSERT INTO  SAL_NCONTRIB1 ( codncontrib1,
                                  codncontrib       ,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP              )
                    ( SELECT      SEQ_SAL_NCONTRIB1_CODNCONTRIB1.Nextval,
                                  RecId,
                                  Marime            ,
                                  Modcalcul         ,
                                  ImpozitatCtr      ,
                                  CodCont           ,
                                  CodContchelt      ,
                                  CodContCAS        ,
                                  CodContAMBP       ,
                                  LaContr           ,
                                  LaConv            ,
                                  LaConvCM          ,
                                  LaCumulSal        ,
                                  LaCumulPens       ,
                                  LaPartSal         ,
                                  LaPreaviz         ,
                                  LaSpecial         ,
                                  LaSpecialCV       ,
                                  LaAsimilate       ,
                                  Grupa1            ,
                                  Grupa2            ,
                                  Grupa3            ,
                                  Grupa4            ,
                                  SpecialCB         ,
                                  ImpozitatCv       ,
                                  ImpozitatCvCM     ,
                                  ImpozitatCS       ,
                                  ImpozitatCP       ,
                                  ImpozitatSpec     ,
                                  ImpozitatSpecCV   ,
                                  ImpozitatAS       ,
                                  VarstaMin         ,
                                  VenitMin          ,
                                  VenitMax          ,
                                  TipContractual    ,
                                  Buget             ,
                                  TipLimitare       ,
                                  Referinta         ,
                                  Multiplic         ,
                                  Constructii       ,
                                  LaCoop            ,
                                  LaInternship      ,
                                  ANSTART           ,
                                  LUNASTART         ,
                                  ALSTART           ,
                                  ALSTOP
                         FROM TMP_SAL_NCONTRIB1  ) ;

  END IF;
  PRC_AL_REFRESH(&apos;SAL_NCONTRIB1&apos;, RECID);
  NotifyModif(Operation, RecId, &apos;SAL_NCONTRIB&apos;);
  COMMIT;
END;

end PKG_SAL_NCONTRIB;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_NDREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB8CBB4ADD838C0424DD2759C080B8D935E352D6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_NDREP is
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT codndrep
      INTO Tmp
      FROM SAL_NDREP
     WHERE codndrep = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
    aDoc VARCHAR2(500);
  BEGIN
    SELECT tip INTO aDoc FROM TMP_SAL_NDREP;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NDREP&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_NDREP1 WHERE codndrep = RecId;
    DELETE FROM SAL_NDREP0 WHERE codndrep = RecId;
    DELETE FROM SAL_NDREP WHERE codndrep = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_NDREP FIELDS (codndrep) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT    NUMBER(4);
    ALUNASFARSIT  NUMBER(2);
  BEGIN
    -- Master SAL_NDREP
    INSERT INTO TMP_SAL_NDREP
      (codndrep, denumire, tip, modcalc, dataadaug)
      (SELECT codndrep, denumire, tip, modcalc, dataadaug
         FROM SAL_NDREP
        WHERE codndrep = RecId);
    -- DETAIL SAL_NDREP0
    INSERT INTO TMP_SAL_NDREP0
      (codndrep0,
       codndrep,
       art,
       marime,
       impozit,
       deduceri,
       tva,
       ziua,
       gest,
       codcont,
       totalcant,
       totalval,
       totalcutva,
       tichetmasa,
       coddoc,
       altededuceri,
       anstart,
       lunastart,
       alstart,
       alstop,
       art_den)
      (SELECT dr0.codndrep0,
              dr0.codndrep,
              dr0.art,
              dr0.marime,
              dr0.impozit,
              dr0.deduceri,
              dr0.tva,
              dr0.ziua,
              dr0.gest,
              dr0.codcont,
              dr0.totalcant,
              dr0.totalval,
              dr0.totalcutva,
              dr0.tichetmasa,
              dr0.coddoc,
              dr0.altededuceri,
              dr0.anstart,
              dr0.lunastart,
              dr0.alstart,
              dr0.alstop,
              obj.denumire
         FROM SAL_NDREP0 dr0
         LEFT JOIN NARTOBJ obj on obj.codobiect = dr0.art 
        WHERE dr0.codndrep = RecId);
    -- DETAIL SAL_NDREP1
    INSERT INTO TMP_SAL_NDREP1
      (codndrep1, codndrep0, codndrep, contrib, tip_contrib)
      (SELECT drp1.codndrep1, drp1.codndrep0, drp1.codndrep, drp1.contrib, nctr.tipcontributie 
         FROM SAL_NDREP1 drp1
         LEFT JOIN SAL_NCONTRIB nctr on nctr.codncontrib = drp1.contrib
        WHERE codndrep0 IN
              (SELECT tnasig.codndrep0 from TMP_SAL_NDREP0 tnasig));
  
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT codndrep0, ANSTART, LUNASTART
                    FROM TMP_SAL_NDREP0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_NDREP0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE codndrep0 = V_REC.codndrep0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
    vCod NUMBER(20);
  BEGIN
    SELECT tip INTO aDoc FROM TMP_SAL_NDREP;
    IF Operation = 0 THEN
      -- UPDATE
      -- Master SAL_NDREP
      SELECT codndrep INTO RECID FROM TMP_SAL_NDREP;
    
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NDREP&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      UPDATE SAL_NDREP
         SET (codndrep, denumire, tip, modcalc, dataadaug) =
             (SELECT codndrep, denumire, tip, modcalc, dataadaug
                FROM TMP_SAL_NDREP)
       WHERE codndrep = RecId;
    
      DELETE FROM SAL_NDREP1
       where codndrep = RecId
         and codndrep0 not in (Select ts0.codndrep0 from TMP_SAL_NDREP0 ts0);
    
      DELETE FROM SAL_NDREP0
       where codndrep = RecId
         and codndrep0 not in (Select ts0.codndrep0 from TMP_SAL_NDREP0 ts0);
    
      UPDATE SAL_NDREP0 s0
         SET (codndrep0,
              codndrep,
              art,
              marime,
              impozit,
              deduceri,
              tva,
              ziua,
              gest,
              codcont,
              totalcant,
              totalval,
              totalcutva,
              tichetmasa,
              coddoc,
              altededuceri,
              anstart,
              lunastart,
              alstart,
              alstop) =
             (SELECT codndrep0,
                     codndrep,
                     art,
                     marime,
                     impozit,
                     deduceri,
                     tva,
                     ziua,
                     gest,
                     codcont,
                     totalcant,
                     totalval,
                     totalcutva,
                     tichetmasa,
                     coddoc,
                     altededuceri,
                     anstart,
                     lunastart,
                     alstart,
                     alstop
                FROM TMP_SAL_NDREP0 ts
               WHERE ts.codndrep0 &gt; 0
                 and ts.codndrep0 = s0.codndrep0)
       WHERE s0.codndrep = RecId;
    
      for v_rec in (select * from TMP_SAL_NDREP0 WHERE codndrep0 &lt; 0) loop
        select SEQ_SAL_NDREP0_codndrep0.Nextval into vcod from dual;
        update TMP_SAL_NDREP1
           set codndrep0 = vcod
         where codndrep0 = v_rec.codndrep0;
      
        INSERT INTO SAL_NDREP0
          (codndrep0,
           codndrep,
           art,
           marime,
           impozit,
           deduceri,
           tva,
           ziua,
           gest,
           codcont,
           totalcant,
           totalval,
           totalcutva,
           tichetmasa,
           coddoc,
           altededuceri,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.art,
           v_rec.marime,
           v_rec.impozit,
           v_rec.deduceri,
           v_rec.tva,
           v_rec.ziua,
           v_rec.gest,
           v_rec.codcont,
           v_rec.totalcant,
           v_rec.totalval,
           v_rec.totalcutva,
           v_rec.tichetmasa,
           v_rec.coddoc,
           v_rec.altededuceri,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
    
      --update/insert SAL_NDREP1
      UPDATE SAL_NDREP1 s1
         SET (codndrep1, codndrep0, codndrep, contrib) =
             (SELECT codndrep1, codndrep0, codndrep, contrib
                FROM TMP_SAL_NDREP1 ts1
               WHERE ts1.codndrep1 &gt; 0
                 and ts1.codndrep1 = s1.codndrep1)
       WHERE s1.codndrep1 in (select ti.codndrep1
                                from TMP_SAL_NDREP1 ti
                               WHERE ti.codndrep1 &gt; 0);
    
      INSERT INTO SAL_NDREP1
        (codndrep1, codndrep0, codndrep, contrib)
        SELECT SEQ_SAL_NDREP1_codndrep1.Nextval,
               t1.codndrep0,
               t1.codndrep,
               t1.contrib
          FROM TMP_SAL_NDREP1 t1
         where t1.codndrep1 &lt; 0;
    ELSE
      -- INSERT
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_NDREP&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT SEQ_SAL_NDREP_codndrep.NextVal INTO RecId FROM DUAL;
      -- Master SAL_NDREP
      INSERT INTO SAL_NDREP
        (codndrep, denumire, tip, modcalc, dataadaug)
        (SELECT RecId, denumire, tip, modcalc, dataadaug FROM TMP_SAL_NDREP);
    
      for v_rec in (select * from TMP_SAL_NDREP0) loop
        select SEQ_SAL_NDREP0_codndrep0.Nextval into vcod from dual;
        update TMP_SAL_NDREP1
           set codndrep0 = vcod
         where codndrep0 = v_rec.codndrep0;
      
        --insert nasig0
        INSERT INTO SAL_NDREP0
          (codndrep0,
           codndrep,
           art,
           marime,
           impozit,
           deduceri,
           tva,
           ziua,
           gest,
           codcont,
           totalcant,
           totalval,
           totalcutva,
           tichetmasa,
           coddoc,
           altededuceri,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.art,
           v_rec.marime,
           v_rec.impozit,
           v_rec.deduceri,
           v_rec.tva,
           v_rec.ziua,
           v_rec.gest,
           v_rec.codcont,
           v_rec.totalcant,
           v_rec.totalval,
           v_rec.totalcutva,
           v_rec.tichetmasa,
           v_rec.coddoc,
           v_rec.altededuceri,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
      --insert nasig1
    
      INSERT INTO SAL_NDREP1
        (codndrep1, codndrep0, codndrep, contrib)
        select SEQ_SAL_NDREP1_codndrep1.Nextval,
               codndrep0,
               RecId,
               contrib
          from TMP_SAL_NDREP1;
    END IF;
    PRC_AL_REFRESH(&apos;SAL_NDREP0&apos;, RECID);
    NotifyModif(Operation, RecId, &apos;SAL_NDREP&apos;);
    COMMIT;
  END;

end PKG_SAL_NDREP;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_RETINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B229596D44DA4AD9F621CE7671237032C47AF22C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_RETINERI IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;
  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT CODRETINERE
      INTO Tmp
      FROM SAL_RETINERI
     WHERE CODRETINERE = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
   aDoc VARCHAR2(500);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_RETINERI;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_RETINERI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_RETINERI0 WHERE CODRETINERE = RecId;
    DELETE FROM SAL_RETINERI WHERE CODRETINERE = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_RETINERI FIELDS (CODRETINERE) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT   NUMBER(4);
    ALUNASFARSIT NUMBER(2);
  BEGIN
    INSERT INTO TMP_SAL_RETINERI0
      (codretinere0,
       codretinere,
       marime,
       modcalcul,
       caracter,
       cont,
       tert,
       neimpoz,
       nrcontr,
       datacontr,
       anstart,
       lunastart,
       alstart,
       alstop)
      (SELECT codretinere0,
              codretinere,
              marime,
              modcalcul,
              caracter,
              cont,
              tert,
              neimpoz,
              nrcontr,
              datacontr,
              anstart,
              lunastart,
              alstart,
              alstop
         FROM SAL_RETINERI0
        WHERE codretinere = RecId);
    -- Master SAL_RETINERI
    INSERT INTO TMP_SAL_RETINERI
      (codretinere, denumire, codcatret)
      (SELECT codretinere, denumire, codcatret
         FROM SAL_RETINERI
        WHERE CODRETINERE = RecId);
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT codretinere0, ANSTART, LUNASTART
                    FROM TMP_SAL_RETINERI0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_RETINERI0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE codretinere0 = V_REC.codretinere0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
    COMMIT;
  
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
  BEGIN
    SELECT denumire INTO aDoc FROM TMP_SAL_RETINERI;
  
    IF Operation = 0 THEN
      -- UPDATE
      SELECT codretinere INTO RECID FROM TMP_SAL_RETINERI;
    
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_RETINERI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      -- Master SAL_RETINERI
      SELECT CODRETINERE INTO RecId FROM TMP_SAL_RETINERI;
      UPDATE SAL_RETINERI
         SET (codretinere, denumire, codcatret) =
             (SELECT codretinere, denumire, codcatret FROM TMP_SAL_RETINERI)
       WHERE CODRETINERE = RecId;
      --DELETE
      DELETE FROM SAL_RETINERI0
       WHERE codretinere = RECID
         AND codretinere0 NOT IN
             (SELECT ts0.codretinere0 FROM TMP_SAL_RETINERI0 ts0);
    
      UPDATE SAL_RETINERI0 s0
         SET (codretinere0,
              codretinere,
              marime,
              modcalcul,
              caracter,
              cont,
              tert,
              neimpoz,
              nrcontr,
              datacontr,
              anstart,
              lunastart,
              alstart,
              alstop) =
             (SELECT codretinere0,
                     codretinere,
                     marime,
                     modcalcul,
                     caracter,
                     cont,
                     tert,
                     neimpoz,
                     nrcontr,
                     datacontr,
                     anstart,
                     lunastart,
                     alstart,
                     alstop
                FROM TMP_SAL_RETINERI0 ts
               WHERE ts.codretinere0 &gt; 0
                 and ts.codretinere0 = s0.codretinere0)
       WHERE s0.codretinere = RecId;
    
      INSERT INTO SAL_RETINERI0
        (codretinere0,
         codretinere,
         marime,
         modcalcul,
         caracter,
         cont,
         tert,
         neimpoz,
         nrcontr,
         datacontr,
         anstart,
         lunastart,
         alstart,
         alstop)
        (SELECT SEQ_SAL_RETINERI0_CODRETINERE0.Nextval,
                RecId,
                marime,
                modcalcul,
                caracter,
                cont,
                tert,
                neimpoz,
                nrcontr,
                datacontr,
                anstart,
                lunastart,
                alstart,
                alstop
           FROM TMP_SAL_RETINERI0
          WHERE codretinere0 &lt; 0);
    
    ELSE
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_RETINERI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      -- INSERT
      -- Master SAL_RETINERI
      SELECT SEQ_SAL_RETINERI_CODRETINERE.NextVal INTO RecId FROM DUAL;
      INSERT INTO SAL_RETINERI
        (codretinere, denumire, codcatret)
        (SELECT RecId, denumire, codcatret FROM TMP_SAL_RETINERI);
      INSERT INTO SAL_RETINERI0
        (codretinere0,
         codretinere,
         marime,
         modcalcul,
         caracter,
         cont,
         tert,
         neimpoz,
         nrcontr,
         datacontr,
         anstart,
         lunastart,
         alstart,
         alstop)
        (SELECT SEQ_SAL_RETINERI0_CODRETINERE0.Nextval,
                RecId,
                marime,
                modcalcul,
                caracter,
                cont,
                tert,
                neimpoz,
                nrcontr,
                datacontr,
                anstart,
                lunastart,
                alstart,
                alstop
           FROM TMP_SAL_RETINERI0);
    END IF;
    NotifyModif(Operation, RecId, &apos;SAL_RETINERI&apos;);
    COMMIT;
  END;

end PKG_SAL_RETINERI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SAL_SPORURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32CA6D1BB59F6D815ED03FBB449C3690E51396ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SAL_SPORURI IS
  CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_5&apos;;

  PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
    Tmp NUMBER(20);
  BEGIN
    SELECT codspor
      INTO Tmp
      FROM SAL_SPORURI
     WHERE codspor = RecId
       FOR UPDATE NOWAIT;
  END;

  PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
    aDoc VARCHAR2(500);
  BEGIN
    SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_SPORURI;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_SPORURI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;S&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    SP_LOCKRECORD(RecId);
    DELETE FROM SAL_SPORURI1 WHERE codspor = RecId;
    DELETE FROM SAL_SPORURI2 WHERE codspor = RecId;
    DELETE FROM SAL_SPORURI0 WHERE codspor = RecId;
    DELETE FROM SAL_SPORURI WHERE codspor = RecId;
    COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
    INSERT INTO TMP_SAL_SPORURI FIELDS (codspor) VALUES (0);
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
    AANSFARSIT   NUMBER(4);
    ALUNASFARSIT NUMBER(2);
  BEGIN
    -- DETAIL SPORURI1
    INSERT INTO TMP_SAL_SPORURI1
      (codspor1, codspor0, codspor, LimInf, Limsup, ValSpor)
      (SELECT codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
         FROM SAL_SPORURI1
        WHERE codspor = RecId);
    -- DETAIL SPORURI2
    INSERT INTO TMP_SAL_SPORURI2
      (codspor2, codspor0, codspor, codsporexclus, denexcl)
      (SELECT sp2.codspor2,
              codspor0,
              sp2.codspor,
              sp2.codsporexclus,
              sp.denumire
         FROM SAL_SPORURI2 sp2
         join SAL_SPORURI sp
           on sp.codspor = sp2.codsporexclus
        WHERE sp2.codspor = RecId);
    -- DETAIL SPORURI0                                                     
    INSERT INTO TMP_SAL_SPORURI0
      (codspor0,
       codspor,
       tip,
       tiptransa,
       tipcalcspor,
       zilenemo,
       valoare,
       buget,
       itmtip,
       itmspor,
       tarifarrefl,
       intrs,
       intrc,
       intrsns,
       intrsnc,
       anstart,
       lunastart,
       alstart,
       alstop)
      (SELECT codspor0,
              codspor,
              tip,
              tiptransa,
              tipcalcspor,
              zilenemo,
              valoare,
              buget,
              itmtip,
              itmspor,
              tarifarrefl,
              intrs,
              intrc,
              intrsns,
              intrsnc,
              anstart,
              lunastart,
              alstart,
              alstop
         FROM SAL_SPORURI0
        WHERE codspor = RecId);
    -- Master SAL_SPORURI                                                      
    INSERT INTO TMP_SAL_SPORURI
      (codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza)
      (SELECT codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
         FROM SAL_SPORURI
        WHERE codspor = RecId);
    AANSFARSIT   := 0;
    ALUNASFARSIT := 0;
    FOR V_REC IN (SELECT codspor0, ANSTART, LUNASTART
                    FROM TMP_SAL_SPORURI0
                   ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
      IF (AANSFARSIT &lt;&gt; 0) AND (ALUNASFARSIT &lt;&gt; 0) THEN
        UPDATE TMP_SAL_SPORURI0
           SET ANSFARSIT = AANSFARSIT, LUNASFARSIT = ALUNASFARSIT
         WHERE codspor0 = V_REC.codspor0;
      END IF;
    
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART,
                                             V_REC.LUNASTART,
                                             AANSFARSIT,
                                             ALUNASFARSIT);
    END LOOP;
    COMMIT;
  END;

  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
    aDoc VARCHAR2(500);
    vCod NUMBER(20);
  
  BEGIN
    SELECT denumire || &apos;(&apos; || simbol || &apos;)&apos; INTO aDoc FROM TMP_SAL_SPORURI;
    IF Operation = 0 THEN
      -- UPDATE
      -- Master SAL_SPORURI
      SELECT codspor INTO RECID FROM TMP_SAL_SPORURI;
    
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_SPORURI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;M&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT codspor INTO RecId FROM TMP_SAL_SPORURI;
    
      UPDATE SAL_SPORURI
         SET (codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza) =
             (SELECT codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza
                FROM TMP_SAL_SPORURI)
       WHERE codspor = RecId;
      -- DELETE
      DELETE FROM SAL_SPORURI1
       WHERE codspor = RECID
         AND codspor0 NOT IN
             (SELECT ts0.codspor0 FROM TMP_SAL_SPORURI0 ts0);
      DELETE FROM SAL_SPORURI2
       WHERE codspor = RECID
         AND codspor0 NOT IN
             (SELECT ts0.codspor0 FROM TMP_SAL_SPORURI0 ts0);
      DELETE FROM SAL_SPORURI0
       WHERE codspor = RECID
         AND codspor0 NOT IN
             (SELECT ts0.codspor0 FROM TMP_SAL_SPORURI0 ts0);
    
      UPDATE SAL_SPORURI0 s0
         SET (codspor0,
              codspor,
              tip,
              tiptransa,
              tipcalcspor,
              zilenemo,
              valoare,
              buget,
              itmtip,
              itmspor,
              tarifarrefl,
              intrs,
              intrc,
              intrsns,
              intrsnc,
              anstart,
              lunastart,
              alstart,
              alstop) =
             (SELECT codspor0,
                     codspor,
                     tip,
                     tiptransa,
                     tipcalcspor,
                     zilenemo,
                     valoare,
                     buget,
                     itmtip,
                     itmspor,
                     tarifarrefl,
                     intrs,
                     intrc,
                     intrsns,
                     intrsnc,
                     anstart,
                     lunastart,
                     alstart,
                     alstop
                FROM TMP_SAL_SPORURI0 ts
               WHERE ts.codspor0 &gt; 0
                 and ts.codspor0 = s0.codspor0)
       WHERE s0.codspor = RecId;
    
      for v_rec in (select * from TMP_SAL_SPORURI0 WHERE codspor0 &lt; 0) loop
        select SEQ_SAL_SPORURI0_CODSPOR0.Nextval into vcod from dual;
        update TMP_SAL_SPORURI1
           set codspor0 = vcod
         where codspor0 = v_rec.codspor0;
        update TMP_SAL_SPORURI2
           set codspor0 = vcod
         where codspor0 = v_rec.codspor0;
      
        INSERT INTO SAL_SPORURI0
          (codspor0,
           codspor,
           tip,
           tiptransa,
           tipcalcspor,
           zilenemo,
           valoare,
           buget,
           itmtip,
           itmspor,
           tarifarrefl,
           intrs,
           intrc,
           intrsns,
           intrsnc,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.tip,
           v_rec.tiptransa,
           v_rec.tipcalcspor,
           v_rec.zilenemo,
           v_rec.valoare,
           v_rec.buget,
           v_rec.itmtip,
           v_rec.itmspor,
           v_rec.tarifarrefl,
           v_rec.intrs,
           v_rec.intrc,
           v_rec.intrsns,
           v_rec.intrsnc,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
      --update/insert SAL_SPORURI1
      UPDATE SAL_SPORURI1 s1
         SET (codspor1, codspor0, codspor, LimInf, Limsup, ValSpor) =
             (SELECT codspor1, codspor0, codspor, LimInf, Limsup, ValSpor
                FROM TMP_SAL_SPORURI1 ts1
               WHERE ts1.codspor1 &gt; 0
                 and ts1.codspor1 = s1.codspor1)
       WHERE s1.codspor1 in (select ti.codspor1
                               from TMP_SAL_SPORURI1 ti
                              WHERE ti.codspor1 &gt; 0);
      INSERT INTO SAL_SPORURI1
        (codspor1, codspor0, codspor, LimInf, Limsup, ValSpor)
        SELECT SEQ_SAL_SPORURI1_CODSPOR1.NEXTVAL,
               codspor0,
               RECID,
               LimInf,
               Limsup,
               ValSpor
          FROM TMP_SAL_SPORURI1
         WHERE codspor1 &lt; 0;
      -- DETAIL SPORURI2
      UPDATE SAL_SPORURI2 s2
         SET (codspor2, codspor0, codspor, codsporexclus) =
             (SELECT codspor2, codspor0, codspor, codsporexclus
                FROM TMP_SAL_SPORURI2 ts2
               WHERE ts2.codspor2 &gt; 0
                 and ts2.codspor2 = s2.codspor2)
       WHERE s2.codspor2 in (select ti.codspor2
                               from TMP_SAL_SPORURI2 ti
                              WHERE ti.codspor2 &gt; 0);
      INSERT INTO SAL_SPORURI2
        (codspor2, codspor0, codspor, codsporexclus)
        SELECT SEQ_SAL_SPORURI2_CODSPOR2.NEXTVAL,
               codspor0,
               RECID,
               codsporexclus
          FROM TMP_SAL_SPORURI2
         WHERE codspor2 &lt; 0;
    ELSE
      -- INSERT
      IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,
                                              CT_MONITOR) THEN
        WINMADMIN.PKG_USERFIRME.PostLog(&apos;SAL_SPORURI&apos;,
                                        PKG_GLOBALS.USERNAME,
                                        &apos;A&apos;,
                                        RECID,
                                        PKG_GLOBALS.FIRMANAME,
                                        pkg_globals.SUBUNITATE,
                                        null,
                                        aDoc,
                                        null,
                                        PKG_GLOBALS.GET_EXE_VERSION);
      END IF;
    
      SELECT SEQ_SAL_SPORURI_CODSPOR.NextVal INTO RecId FROM DUAL;
      -- Master SAL_SPORURI
      INSERT INTO SAL_SPORURI
        (codspor, simbol, denumire, codcatspor, salbaza, nivelsalbaza)
        (SELECT RecId, simbol, denumire, codcatspor, salbaza, nivelsalbaza FROM TMP_SAL_SPORURI);
        
      for v_rec in (select * from TMP_SAL_SPORURI0) loop
        select SEQ_SAL_SPORURI0_CODSPOR0.Nextval into vcod from dual;
        update TMP_SAL_SPORURI1
           set codspor0 = vcod
         where codspor0 = v_rec.codspor0;
        update TMP_SAL_SPORURI2
           set codspor0 = vcod
         where codspor0 = v_rec.codspor0; 
      
       -- DETAIL SPORURI0
        INSERT INTO SAL_SPORURI0
          (codspor0,
           codspor,
           tip,
           tiptransa,
           tipcalcspor,
           zilenemo,
           valoare,
           buget,
           itmtip,
           itmspor,
           tarifarrefl,
           intrs,
           intrc,
           intrsns,
           intrsnc,
           anstart,
           lunastart,
           alstart,
           alstop)
        VALUES
          (vcod,
           RecId,
           v_rec.tip,
           v_rec.tiptransa,
           v_rec.tipcalcspor,
           v_rec.zilenemo,
           v_rec.valoare,
           v_rec.buget,
           v_rec.itmtip,
           v_rec.itmspor,
           v_rec.tarifarrefl,
           v_rec.intrs,
           v_rec.intrc,
           v_rec.intrsns,
           v_rec.intrsnc,
           v_rec.anstart,
           v_rec.lunastart,
           v_rec.alstart,
           v_rec.alstop);
      end loop;
        
      -- DETAIL SPORURI1
      INSERT INTO SAL_SPORURI1
        (codspor1, codspor0, codspor, LimInf, Limsup, ValSpor)
        SELECT SEQ_SAL_SPORURI1_CODSPOR1.NEXTVAL,
               codspor0,
               RECID,
               LimInf,
               Limsup,
               ValSpor
          FROM TMP_SAL_SPORURI1 where codspor0 &gt; 0;
      -- DETAIL SPORURI2
      INSERT INTO SAL_SPORURI2
        (codspor2, codspor0, codspor, codsporexclus)
        SELECT SEQ_SAL_SPORURI2_CODSPOR2.NEXTVAL, codspor0, RECID, codsporexclus
          FROM TMP_SAL_SPORURI2 where codspor0 &gt; 0;
    END IF;
    NotifyModif(Operation, RecId, &apos;SAL_SPORURI&apos;);
    COMMIT;
  END;

end PKG_SAL_SPORURI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SCADENTARTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8235C68523A7E5A65FA5BA3F5F2EFBE9ECD78FFB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_scadentartl IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodScadTL INTO Tmp FROM NScadTL WHERE CodScadTL = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NScadTL WHERE CodScadTL = RecId ;
  NotifyModif(2, RecId, &apos;NSCADTL&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NScadTL FIELDS(CodScadTL) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NScadTL
  INSERT INTO TMP_NScadTL ( CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea)
  SELECT CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea
  FROM NScadTL
  WHERE CodScadTL = RecId ;

  INSERT INTO TMP_NScadTL1 (CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total)
  SELECT CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total
  FROM NScadTL1
  WHERE CodScadTL = RecId ;

  UPDATE TMP_NScadTL SET (TotRata, TotDobanda) = (SELECT Sum(Rata), Sum(Dobanda) FROM TMP_NScadTL1);

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodScadTL INTO RecId FROM TMP_NScadTL;

    UPDATE NScadTL
    SET ( CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea) = (SELECT CodScadTL, CodBanca, NrContr, DataContr, DataExp, Nvl(Moneda,0), Valoare, Subunitatea FROM TMP_NScadTL)
    WHERE CodScadTL = RecId;

    DELETE NScadTL1 WHERE CodScadTL = RecId AND NOT CodScadTL1 IN (SELECT CodScadTL1 FROM TMP_NScadTL1);

    FOR V_REC IN (SELECT * FROM TMP_NScadTL1 WHERE CodScadTL1 &gt; 0) LOOP
      UPDATE NScadTL1
      SET
        DATASCAD = V_REC.DATASCAD,
        RATA     = V_REC.RATA,
        DOBANDA  = V_REC.DOBANDA,
        TOTAL    = V_REC.TOTAL
      WHERE CODSCADTL1 = V_REC.CODSCADTL1;
    END LOOP;

    INSERT INTO NScadTL1(CODSCADTL1, CODSCADTL, DATASCAD, RATA, DOBANDA, TOTAL)
    SELECT SEQ_NScadTL1_CodScadTL1.NEXTVAL, RECID, DATASCAD, RATA, DOBANDA, TOTAL
    FROM TMP_NScadTL1
    WHERE Nvl(CodScadTL1,0) &lt;= 0;

  ELSE  -- INSERT
-- Master NScadTL
    SELECT SEQ_NScadTL_CodScadTL.NextVal INTO RecId FROM DUAL;

    INSERT INTO  NScadTL (CodScadTL, CodBanca, NrContr, DataContr, DataExp, Moneda, Valoare, Subunitatea, USERID, DATACREARE)
    SELECT RecId, CodBanca, NrContr, DataContr, DataExp, Nvl(Moneda,0), Valoare, Subunitatea, PKG_GLOBALS.USERID, SYSTIMESTAMP
    FROM TMP_NScadTL ;

    INSERT INTO NScadTL1(CodScadTL1, CodScadTL, DataScad, Rata, Dobanda, Total)
    SELECT SEQ_NScadTL1_CodScadTL1.NEXTVAL, RecId, DataScad, Rata, Dobanda, Total
    FROM  TMP_NScadTL1;
  END IF;
  NotifyModif(Operation, RecId, &apos;NSCADTL&apos;);
  COMMIT;

END;

END PKG_ScadentarTL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99E200201AC9D8C62EA3E25E3F22D20FD2CA9F0B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SCENARIILIVR IS

DoCommit boolean := true;

procedure Set_Do_Commit(aDoCommit IN BOOLEAN) IS
begin
  DoCommit := aDoCommit;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODSCENARIU INTO Tmp FROM SCENARIILIVR WHERE CODSCENARIU = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  UPDATE LANSARE0 SET CODSCENARIU = NULL WHERE CODSCENARIU = RECID;
  DELETE FROM NODECHIV1 WHERE CODSCENARIU = RECID;
  DELETE FROM SCENARIILIVR2 WHERE CODSCENARIU = RecId ;
  DELETE FROM SCENARIILIVR1 WHERE CODSCENARIU = RecId ;
  DELETE FROM SCENARIILIVR WHERE CODSCENARIU = RecId ;
  NotifyModif(2, RecId, &apos;SCENARIILIVR&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SCENARIILIVR FIELDS( CODSCENARIU ) VALUES (0) ;
  COMMIT;
END;

procedure Populeaza_TMPURI( G_SUBUNIT in number,DataLivrS in varchar2,  DataLivrF in varchar2,DataCmdS  in varchar2,  DataCmdF  in varchar2, SCENARIU in number default 0) IS
   NOD_Rezervat   Number(20,7); 
   NOD_RezFurn    Number(20,7); 
   TOT_RestCmd    Number(20,7); 
   TOT_RestFurn   Number(20,7);
   Init           number(1);
   Zec            number(2);
   LastProiectNod number(20);
   RezolvareLansari number(1);
begin
  delete from TMP_SIM_CCOM1;
  delete from TMP_SIM_LANS;
  delete from TMP_SIM_LANS1;
  delete from TMP_SIM_NODECHIV1;
INSERT INTO TMP_SIM_CCOM1
  (NRDOC,
   DATADOC,
   DENOBIECT,
   DEN_CLIENT,
   CODCOMANDA1,
   CODOBIECT,
   CODPROIECT,
   VERSIUNE,
   CODCOMANDA,
   TIPDOC,
   CODCLIENT,
   TERMEN,
   MASAO,
   VOLUMO,
   CODGRUPA,
   PARITATEGRUPA,
   GrupaE,
   ObjGeneric,
   CODTARA,
   DEN_TARA,
   CODZONA,
   DEN_ZONA,
   CODLOCALIT,
   DEN_LOCALIT,
   UMSEC,
   OK,
   ACTIV,
   TIPCOMANDA,
   CODEXTERN,
   DENMAT,
   TRASEU,
   POZTRASEU,
   HTAG,
   CANTACCEPTAT,
   STOCREZERVAT,
   SCENDEFINITIVE,
   ALTESCENARII,
   REST,
   DEREZOLVAT,
   LANSSCENARIU,
   LANSAT,
   Masa, 
   Volum,
	 TipClient
   )
  (SELECT C.NRDOC,
          C.DATADOC,
          NOBJ.DENUMIRE DENOBIECT,
          NP.DEN_PART DEN_CLIENT,
          C1.CODCOMANDA1,
          C1.CODOBIECT,
          C1.CODPROIECT,
          PR.VERSIUNE,
          C.CODCOMANDA,
          C.TIPDOC,
          NP.CODPART CODCLIENT,
          C1.TERMEN,
          NOBJ.MASA MASAO,
          NOBJ.VOLUM/1000000 VOLUMO,
          NE.CODGRUPA,
          NE.PARITATE PARITATEGRUPA,
          GE.DENUMIRE GrupaE,
          NOBJE.DENUMIRE ObjGeneric,
          TARA.CODTARA,
          TARA.DEN_TARA,
          NZ.CODZONA,
          NZ.DEN_ZONA,
          NLOC.CODLOCALIT,
          NLOC.DEN_LOCALIT,
          C1.UMSEC,
          0 OK,
          CASE WHEN COALESCE(SCEN1.CANT, 0) = 0 THEN 0 ELSE 1 END ACTIV,
          C.DISPLIVRARE,
          NOBJ.CODEXTERN,
          NOBJMAT.DENUMIRE DENMAT,
          TR.DENTRASEU TRASEU,
          NAG.POZTRASEU,
          COALESCE(PR.OBS1, &apos;&apos;) || COALESCE(PC.OBS1, &apos;&apos;) HTAG,
          C1.CANTACCEPTAT CANTACCEPTAT,
          REZ.REZERVAT STOCREZERVAT,
          COALESCE(SCDEF.CANT, 0) SCENDEFINITIVE,
          COALESCE(SC.CANT, 0) ALTESCENARII,
          C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0)  REST,
          C1.CANTACCEPTAT - COALESCE(SC.CANT, 0) - COALESCE(SCDEF.CANT, 0) - COALESCE(SCEN1.LANS, 0) DEREZOLVAT,
          COALESCE(SCEN1.LANS, 0) LANSSCENARIU,
          COALESCE(CMDINT.CANTCMDINT, 0) LANSAT,
          COALESCE(NOBJ.MASA,0) * COALESCE(SCEN1.LANS, 0),
          CASE WHEN COALESCE(SCEN1.LANS, 0) = 0 THEN 0 ELSE Round(COALESCE(NOBJ.VOLUM,0)/1000000 * COALESCE(SCEN1.LANS, 0), 2) END,
					decode(BITand(NP.Strategic,1),1,&apos;strategic &apos;,&apos;&apos;) || 
					decode(BITand(NP.tippartener,1),1,&apos;intern &apos;,&apos;&apos;) || 
					decode(BITand(NP.tippartener,2),2,&apos;extern &apos;,&apos;&apos;) || 
					decode(BITand(NP.tippartener,4),4,&apos;produc. &apos;,&apos;&apos;) || 
					decode( BITand(NP.tippartener,8),8,&apos;asig.&apos;,&apos;&apos;) || 
					decode( BITand(NP.tippartener,16),16,&apos;comis.&apos;,&apos;&apos;) as TipClient
     FROM TMP_SCENARIILIVR1 SCEN1 
     INNER JOIN COMANDA1 C1 ON SCEN1.CODCOMANDA1 = C1.CODCOMANDA1     
     INNER JOIN COMANDA  C  ON C.CODCOMANDA = C1.CODCOMANDA
     INNER JOIN NARTOBJ NOBJ       ON NOBJ.CODOBIECT = C1.CODOBIECT     
     LEFT  JOIN NPART NP       ON NP.CODPART = C.PARTENER
     LEFT JOIN PROIECT PR       ON PR.CODPROIECT = C1.CODPROIECT
     LEFT JOIN PROIECTNOD PRN       ON PRN.CODPROIECT = PR.CODPROIECT      AND PRN.NODORIGINAL = 0
     LEFT JOIN ( SELECT CODPRODCOMP, CODOBIECT  FROM PRODMAT WHERE PRINCIPAL = 1
               ) MAT      ON MAT.CODPRODCOMP = PRN.CODRETETA  AND ROWNUM = 1
     LEFT JOIN NARTOBJ NOBJMAT ON NOBJMAT.CODOBIECT = MAT.CODOBIECT
     LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = PRN.CODRETETA
     LEFT OUTER JOIN NECHIV NE   ON NE.CODOBIECT = C1.CODOBIECT
     LEFT OUTER JOIN GRECHIV GE   ON GE.CODGRECHIV = NE.CODGRUPA
     LEFT OUTER JOIN NECHIV NG   ON NG.CODGRUPA = NE.CODGRUPA  AND NG.GENERIC = 1
     LEFT JOIN NARTOBJ NOBJE ON NOBJE.CODOBIECT = NG.CODOBIECT
     LEFT JOIN NAGENDA NAG  ON NAG.CODAGENDA = C.CODLOCATIE
     LEFT JOIN TRASEULIVR TR   ON TR.CODTRASEULIVR = NAG.CODTRASEU
     LEFT JOIN NLOCALIT NLOC   ON NLOC.CODLOCALIT = NAG.CODLOCALIT
     LEFT JOIN NZONE NZ       ON NZ.CODZONA = NLOC.CODZONA
     LEFT JOIN NTARI TARA       ON TARA.CODTARA = NLOC.CODTARA
     LEFT JOIN ( SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT FROM SCENARIILIVR1 S1
                 INNER JOIN SCENARIILIVR S ON S1.CODSCENARIU = S.CODSCENARIU 
                 WHERE COALESCE(S.DEFINITIV,0) = 1 AND S.CODSCENARIU &lt;&gt; SCENARIU GROUP BY S1.CODCOMANDA1
               ) SCDEF     ON SCDEF.CODCOMANDA1 = C1.CODCOMANDA1
     LEFT JOIN ( SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT FROM SCENARIILIVR1 S1
                 INNER JOIN SCENARIILIVR S ON S1.CODSCENARIU = S.CODSCENARIU 
                 WHERE COALESCE(S.DEFINITIV,0) = 0 AND S.CODSCENARIU &lt;&gt; SCENARIU GROUP BY S1.CODCOMANDA1
                ) SC       ON SC.CODCOMANDA1 = C1.CODCOMANDA1
     LEFT JOIN ( SELECT R.CODCOMANDA1, SUM(R.REST) REZERVAT, NS.CODOBIECT FROM REZERVATS R
                 INNER JOIN NIRSTOC NS ON R.CODNIRSTOC = NS.CODNIRSTOC
                 WHERE COALESCE(CODCMDPRODMAT, 0) = 0 GROUP BY R.CODCOMANDA1, NS.CODOBIECT
                ) REZ ON REZ.CODCOMANDA1 = C1.CODCOMANDA1 AND NOBJ.CODOBIECT = REZ.CODOBIECT
     LEFT JOIN (
                SELECT L0.Codcmd1 CmdCli, C1.CodObiect, L0.CODSCENARIU,SUM(C1.CANTAcceptat) CANTCMDINT
                FROM LANSARE1 L1 
                inner join LANSARE0 L0 on L0.CodLansare0 = L1.CodLansare0
                inner join Comanda1 C1 on C1.CODCOMANDA1 = L1.CodCmd1
                GROUP BY L0.Codcmd1, C1.CodObiect, L0.CODSCENARIU
               )CMDINT ON CMDINT.CMDCLI = C1.CODCOMANDA1 and NOBJ.CODOBIECT = CMDINT.CODOBIECT
    );
--------------------------------------
  insert into TMP_SIM_LANS1
  (
  DENUMIRE      ,                         
  CODOBIECT     ,                         
  CODCOMANDA1   ,                         
  PREF          ,                         
  NIVEL         ,                         
  POZITIE       ,                         
  CODPROIECTNOD ,                         
  NODORIGINAL   ,                         
  TIP           ,                         
  NECESARP      ,                         
  NECESAR       ,                         
  REZERVAT      ,                         
  NESOSIT       ,                         
  DataStart     ,
  CERERE        ,
  STOC          ,                         
  CMDINT        ,                         
  DIFERENTE     ,                         
  ZECIMALE      ,
  UMSEC         ,
  DEN_UM        ,
  MatEchiv      ,
  CodExtern     ,
  DataStartCmdInt,
  CodComanda1I  ,
  IndexParinte  ,
  REZOLVAT
  )                         
  (
  select 
  DENUMIRE         ,                         
  CODOBIECT        ,                         
  CODCMD1          ,
  PREF             ,                         
  NIVEL            ,                         
  POZITIE          ,                         
  CODPROIECTNOD    ,                          
  NODORIGINAL      ,                         
  TIP              ,                         
  COALESCE(NECESARP,0)  ,
  0 NECESAR        , 
  COALESCE(TotRezervat,0), 
  COALESCE(RestDeSosit,0),
  DataStart        ,
  COALESCE(RestCerere, 0),
  COALESCE(STOC       ,0),
  COALESCE(CantCMDINT ,0), 
  0 DIFERENTE      ,
  Zecimale         ,
  UMSEC            ,
  DEN_UM,
  MatEchiv,
  CodExtern,
  DataStartCmdInt,
  CodComanda1I,
  IndexParinte,
  0
  FROM (
    SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1,Y.PREF,Y.NIVEL,Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, 
           Y.TotRezervat , RestFurn.RestDeSosit, RestFurn.DataStart, CEREFURN.RestCerere,
           Y.STOC, Y.NECESARP, CMDI.CANTCMDINT,
           ( Select COALESCE(u.Zecimale, 0) 
             from NUM u, NART a, NARTOBJ o 
             where o.CodObiect = Y.CodObiect 
                   and a.CodArticol = o.CodArticol 
                   and u.CODUM = a.UM
           ) Zecimale,
           0 UMSEC,
           ( Select DEN_UM
             from NUM u, NART a, NARTOBJ o 
             where o.CodObiect = Y.CodObiect 
                   and a.CodArticol = o.CodArticol 
                   and u.CODUM = a.UM
           ) DEN_UM,
           MatEchiv,
           CodExtern, trunc(cmdi.datastartcmdint) datastartcmdint, cmdi.codcomanda1 codcomanda1i, Y.INDEXPARINTE
    FROM
       (SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1,C1.CODCOMANDA1)  CODCMD1,
               X.PREF,X.NIVEL,X.POZITIE,X.CODPROIECTNOD,X.NODORIGINAL,X.Tip,X.CANT,
               REZ.TotRezervat, 
               NS.REST * COALESCE(NE.PARITATE,1) STOC, 
               X.CANT/ORIG.CANT * COALESCE(NE.PARITATE,1) NECESARP, x.MatEchiv,
               NOBJ.CodExtern, X.IndexParinte
        FROM COMANDA1 C1
             INNER JOIN  ( SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD,PN.CODPROIECT,PN.CANT,PN.NODORIGINAL,PN.TIP,PN.CODOBIECT,
                                  PN.NIVEL,PN.POZITIE, SUBSTR(PN.INDEXPARINTE, 3, 47) PREF, case when MECHIV.Nr &gt; 0 then PN.Codprodmat else 0 end MatEchiv,
                                  PN.INDEXPARINTE
                           FROM PROIECTNOD PN
                                INNER JOIN PROIECTNOD PN0 ON PN0.CODPROIECT=PN.CODPROIECT AND PN0.NODORIGINAL = 0
                                LEFT JOIN (select count(*) nr, codmat from prodmat group by codmat) MECHIV on MECHIV.CODMAT = PN.CODPRODMAT
                           ) X ON X.CODPROIECT = C1.CODPROIECT
             LEFT JOIN PROIECTNOD ORIG ON ORIG.CODPROIECTNOD = X.NODORIG
             LEFT JOIN NODECHIV NE ON NE.CODCOMANDA1 = C1.CODCOMANDA1 AND NE.CODPROIECTNOD = X.CODPROIECTNOD
             LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = COALESCE(NE.CODOBIECT, X.CODOBIECT)
             LEFT JOIN (select sum(NSS.REST - coalesce((select sum(r.rest) from rezervats r where codnirstoc = nss.codnirstoc),0)) REST, NSS.CODOBIECT
                        from NIRSTOC NSS
                             INNER JOIN NIR ON NSS.CODNIR = NIR.CodNIR
                             INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST
                        WHERE (G_SUBUNIT = 1 OR NG.CodSubunit = G_SUBUNIT)
                        GROUP BY NSS.CODOBIECT
                        ) NS ON NS.CODOBIECT = NOBJ.CODOBIECT
             LEFT JOIN (SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REZERVATINI) TotRezervat
                        from REZERVATS R 
                        INNER JOIN NIRSTOC NSR ON R.CODNIRSTOC = NSR.CodNIRSTOC
                        GROUP BY R.CodCOmanda1, NSR.CodObiect
                        ) REZ ON REZ.CodComanda1 = C1.CodComanda1 AND NOBJ.CODOBIECT = REZ.CodObiect
             WHERE EXISTS (SELECT TMP.CODPROIECT FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODPROIECT = X.CODPROIECT)
                   AND
                   EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1,C1.CODCOMANDA1))
       ) Y
       LEFT JOIN 
               ( 
                  SELECT L0.Codcmd1 CmdCli1,L0.CODSCENARIU, L1.CODPROIECTNOD, SUM(C1.CANTAcceptat) CANTCMDINT, c1.datastart datastartcmdint, c1.codcomanda1
                  FROM LANSARE1 L1 
                  inner join LANSARE0 L0 on L0.CodLansare0 = L1.CodLansare0
                  inner join TMP_SIM_CCOM1 CC1 on CC1.CODCOMANDA1 = L0.CodCmd1
                  inner join Comanda1 C1 on C1.CODCOMANDA1 = L1.CodCmd1
                  WHERE L0.CODSCENARIU = SCENARIU
                  GROUP BY L0.Codcmd1, L1.CODPROIECTNOD , L0.CODSCENARIU, c1.datastart,c1.codcomanda1 
                ) CMDI ON CMDI.CmdCli1 = Y.CodCmd1 and CMDI.Codproiectnod = Y.CODPROIECTNOD 
       LEFT OUTER JOIN (select R.CodComanda1, NS.CodObiect, sum(r.rest) RestDeConsumat
                        from rezervats r 
                             inner join nirstoc ns on ns.codnirstoc = r.codnirstoc 
                             where COALESCE(r.codnirstoc, 0) &gt; 0
                             group by NS.CodObiect, R.CodComanda1
                       ) RESTREZ ON RESTREZ.CodObiect = Y.CodObiect 
                                 AND RESTREZ.CodComanda1 = Y.CodCmd1
       LEFT OUTER JOIN (select R.CodComanda1, R.CodObiect, Max(C1.Termen) DataStart, sum(r.rest) RestDeSosit
                        from rezervats r
                        inner join Comanda1 C1 on C1.CodComanda1 = r.CODCOMANDA1F
                        where COALESCE(r.codnirstoc, 0) = 0 and COALESCE(r.CODCOMANDA1F, 0) &lt;&gt; 0 
                        group by r.CodObiect, r.codcomanda1
                       ) RESTFURN ON RESTFURN.CodObiect = Y.CodObiect and RESTFURN.CodComanda1 = Y.CodCmd1
       LEFT OUTER JOIN (select R.CodComanda1, R.CodObiect, sum(r.rest) RestCerere
                        from rezervats r
                        where COALESCE(r.codnirstoc, 0) = 0 and COALESCE(r.CODCOMANDA1F, 0) = 0 
                        group by r.CodObiect, r.codcomanda1
                       ) CEREFURN ON CEREFURN.CodObiect = Y.CodObiect and CEREFURN.CodComanda1 = Y.CodCmd1
   ORDER BY Y.DENUMIRE) where NecesarP &gt; 0
  );
  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, 
                                CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV,CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP,
         L1.CODOBIECT, L1.NODORIGINAL, COALESCE(NS.REST,0), NE1.CANT/COALESCE(NE1.PARITATE,1), OBJ.DENUMIRE,OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
       INNER JOIN NODECHIV1 NE1 ON L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND L1.CODPROIECTNOD = NE1.CODPROIECTNOD
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NE1.CODOBIECT
       LEFT JOIN (select sum(NSS.REST) REST, NSS.CODOBIECT
                        from NIRSTOC NSS
                             INNER JOIN NIR ON NSS.CODNIR = NIR.CodNIR
                             INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST
                        WHERE (G_SUBUNIT = 1 OR NG.CodSubunit = G_SUBUNIT)
                        GROUP BY NSS.CODOBIECT) NS ON NS.CODOBIECT = OBJ.CODOBIECT;

  if Scenariu = 0 then RezolvareLansari := 0; else RezolvareLansari := 1; end if;
	PKG_SimLans.LoadScenariiLivr(Scenariu);
end;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
	 g_SUBUNIT    Number(20);
	 SCENARIU     Number(20);
	 aDStart      Date; 
	 aDEnd        Date;
	 DataLivrS Date := Null;
	 DataLivrF Date := Null;
	 DataCmdS  Date := Null;
	 DataCmdF  Date := Null;
	 aTipData number;    
	 NOD_Rezervat   Number(20,7); 
	 NOD_RezFurn    Number(20,7); 
	 TOT_RestCmd    Number(20,7); 
	 TOT_RestFurn   Number(20,7);
	 eDefinitiv     number(1);
	 Init           number(1);
	 Zec            number(2);
	 LastProiectNod number(20);
BEGIN
		INSERT INTO  TMP_SCENARIILIVR (
        CODSCENARIU ,
        DEN_SCENARIU,
        CODTRASEU   ,
        TIP         ,
        DEFINITIV   ,
        OBS         ,
        SUBUNITATEA ,
				DStart      , 
				DEnd        ,
        TipData, Masa, Volum     ,
				AN          ,
        LUNA        ,
        USERID )
     SELECT
        CODSCENARIU ,
        DEN_SCENARIU,
        CODTRASEU   ,
        TIP         ,
        DEFINITIV   ,
        OBS         ,
        SUBUNITATEA ,
				DStart      , 
				DEnd        ,
        TipData, Masa, Volum     ,
        AN          ,
        LUNA        ,
        USERID      
     FROM SCENARIILIVR WHERE CODSCENARIU = RecId  ;

     SELECT
        CODSCENARIU ,
				SUBUNITATEA ,
				Coalesce(Definitiv,0) ,
				DStart      , 
				DEnd        ,
        TipData        
				into
        SCENARIU     ,
				g_SUBUNIT    ,
				eDefinitiv   ,
				aDStart      , 
				aDEnd        ,
        aTipData     
     FROM TMP_SCENARIILIVR WHERE CODSCENARIU = RecId  ;

 if aTipData = 0 then 
	 DataLivrS := aDStart;
	 DataLivrF := aDEnd  ;
 else 
	 DataCmdS  := aDStart;
	 DataCmdF  := aDEnd  ;
 end if;

  INSERT INTO TMP_SCENARIILIVR1 ( CODSCENARIU1,CODSCENARIU, CODCOMANDA1, CANT, LANS)
    SELECT CODSCENARIU1,CODSCENARIU, CODCOMANDA1, CANT, LANS
    FROM SCENARIILIVR1 WHERE CODSCENARIU = RECID;

  INSERT INTO TMP_SCENARIILIVR2 ( CODSCENARIU2,CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART  )
  SELECT CODSCENARIU2,CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART 
  FROM SCENARIILIVR2 WHERE CODSCENARIU = RECID;

  INSERT INTO TMP_NODECHIV1 (CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, CODOBIECTORIG, NODORIGINAL, 
                             CANTECHIVALATA, DENOBIECTECHIV)
  SELECT tmp2.codscenariu, tmp2.codcomanda1, tmp2.codproiectnod, ne1.codobiect, ne1.cant, ne1.paritate, NOD.CODOBIECT, NOD.NODORIGINAL,
         NE1.CANT / NE1.PARITATE, OBJ.DENUMIRE
  FROM TMP_SCENARIILIVR2 TMP2
       INNER JOIN NODECHIV1 NE1 ON NE1.CODCOMANDA1 = TMP2.CODCOMANDA1 AND NE1.CODPROIECTNOD = TMP2.CODPROIECTNOD AND NE1.CODSCENARIU = TMP2.CODSCENARIU
       INNER JOIN PROIECTNOD NOD ON NOD.CODPROIECTNOD = NE1.CODPROIECTNOD  
       INNER JOIN NARTOBJ OBJ ON NE1.CODOBIECT = OBJ.CODOBIECT;

  Populeaza_TMPURI( G_SUBUNIT, 
	                              To_Char(DataLivrS, &apos;DD,MM,YYYY&apos;), To_Char(DataLivrF, &apos;DD,MM,YYYY&apos;),
																To_Char(DataCmdS, &apos;DD,MM,YYYY&apos;), To_Char(DataCmdF, &apos;DD,MM,YYYY&apos;), 
																SCENARIU);
     
  IF  DoCommit THEN
    COMMIT;
  END IF;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS

BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CODSCENARIU INTO RecId FROM TMP_SCENARIILIVR;

    UPDATE SCENARIILIVR 
    SET  (DEN_SCENARIU, CODTRASEU, TIP, TipData, Masa, Volum, DStart, DEnd,DEFINITIV, OBS )
       = (SELECT DEN_SCENARIU, CODTRASEU, TIP, TipData, Masa, Volum, DStart, DEnd,DEFINITIV, OBS FROM TMP_SCENARIILIVR )
    WHERE CODSCENARIU = RecId ;

    DELETE FROM SCENARIILIVR1 where CODSCENARIU = RecId and CODSCENARIU1 not in (Select CODSCENARIU1 from TMP_SCENARIILIVR1);
    DELETE FROM SCENARIILIVR2 where CODSCENARIU = RecId and CODSCENARIU2 not in (Select CODSCENARIU2 from TMP_SCENARIILIVR2);

    INSERT INTO SCENARIILIVR1 ( CODSCENARIU1,CODSCENARIU, CODCOMANDA1, CANT, LANS )
     SELECT SEQ_scenariilivr1_CODSCENARIU1.Nextval , RecId , CODCOMANDA1, CANT, LANS
     FROM TMP_SCENARIILIVR1 WHERE CODSCENARIU1 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_SCENARIILIVR1 WHERE COALESCE(CODSCENARIU1,-1) &gt; 0 ORDER BY CODSCENARIU1 ) LOOP
       UPDATE SCENARIILIVR1
       SET
        CANT        = V_REC.CANT,
				LANS        = V_REC.LANS,
        CODCOMANDA1 = V_REC.CODCOMANDA1
       WHERE CODSCENARIU1  = v_rec.CODSCENARIU1;
    END LOOP;

    INSERT INTO SCENARIILIVR2 ( CODSCENARIU2,CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DATASTART)
     SELECT SEQ_scenariilivr2_CODSCENARIU2.Nextval , RecId , CODCOMANDA1, CODPROIECTNOD, DATASTART 
     FROM TMP_SCENARIILIVR2 WHERE CODSCENARIU2 &lt; 0;

    FOR v_rec IN ( SELECT * FROM TMP_SCENARIILIVR2 WHERE COALESCE(CODSCENARIU2,-1) &gt; 0 ORDER BY CODSCENARIU2 ) LOOP
       UPDATE SCENARIILIVR2
       SET
        CODPROIECTNOD = V_REC.CODPROIECTNOD,
				DATASTART      = V_REC.DATASTART
       WHERE CODSCENARIU2  = v_rec.CODSCENARIU2;
    END LOOP;

  ELSE  -- INSERT

  SELECT SEQ_SCENARIILIVR_CODSCENARIU.NextVal INTO RecId FROM DUAL;

  INSERT INTO  SCENARIILIVR (
        CODSCENARIU ,
        DEN_SCENARIU,
        CODTRASEU   ,
        TIP         , TipData, Masa, Volum, DStart, DEnd,
        DEFINITIV   ,
        OBS         ,
        SUBUNITATEA ,
        AN          ,
        LUNA        ,
        USERID      ,
        DATACREARE  )
  SELECT  RecId,
        DEN_SCENARIU,
        CODTRASEU   ,
        TIP         ,TipData, Masa, Volum, DStart, DEnd,
        DEFINITIV   ,
        OBS         ,
        SUBUNITATEA ,
        AN          ,
        LUNA        ,
        pkg_globals.USERID,
        systimestamp
  FROM TMP_SCENARIILIVR   ;

  INSERT INTO SCENARIILIVR1 ( CODSCENARIU1,CODSCENARIU, CODCOMANDA1, CANT, LANS         )
  SELECT SEQ_scenariilivr1_CODSCENARIU1.Nextval , RecId , CODCOMANDA1, CANT, LANS FROM TMP_SCENARIILIVR1;

  INSERT INTO SCENARIILIVR2 ( CODSCENARIU2,CODSCENARIU, CODCOMANDA1, CODPROIECTNOD, DataStart)
  SELECT SEQ_scenariilivr2_CODSCENARIU2.Nextval , RecId , CODCOMANDA1, CODPROIECTNOD, DataStart FROM TMP_SCENARIILIVR2;

  END IF;

  DELETE NODECHIV1 WHERE CODSCENARIU = RECID;
  INSERT INTO NODECHIV1(CODSCENARIU,CODCOMANDA1,CODPROIECTNOD,CODOBIECT,CANT,PARITATE,TIP)
  SELECT CODSCENARIU,CODCOMANDA1,CODPROIECTNOD,CODOBIECT,CANT,PARITATE,TIP FROM TMP_NODECHIV1;
  
  NotifyModif(Operation, RecId, &apos;SCENARIILIVR&apos;);
  IF  DoCommit THEN
    COMMIT;
  END IF;
END;

PROCEDURE GOTO_ALL(G_SUBUNIT in number, aData1 in varchar2, aData2 in varchar2, NrCCli out number, NrScen out number )  is
Data1 Date;
Data2 Date;

begin
  Data1 := To_Date(aData1, &apos;DD.MM.YYYY&apos;);
  Data2 := To_Date(aData2, &apos;DD.MM.YYYY&apos;) ;
	
	SELECT Count(*) into NrCCli 
	FROM COMANDA  C  
	INNER JOIN COMANDA1 C1 ON C.CODCOMANDA = C1.CODCOMANDA     
	left join SCENARIILIVR1 S1 on S1.CODCOMANDA1 = C1.CODCOMANDA1     
	where C.TipDoc = 18 and C.Operat = 1 and COALESCE(C.Inchisa,0) = 0 and C1.RESTACCEPTAT &gt; 0
			 and (C.DataDoc between Data1 and Data2 and S1.CodComanda1 is null)
			 AND (G_SUBUNIT = 1 OR C.SUBUNITATEA = G_SUBUNIT);

	SELECT Count(*) into NrScen
	FROM SCENARIILIVR1 S1 
	inner join SCENARIILIVR S on S.CodScenariu = S1.CodScenariu
	left join LANSARE0 L0 on L0.CODScenariu = S1.CODScenariu     
	where S.DStart &gt;= Data1 and S.DEnd &lt;= Data2  and L0.CODScenariu is null
			 AND (G_SUBUNIT = 1 OR S.SUBUNITATEA = G_SUBUNIT);
			 
end;

end PKG_SCENARIILIVR; 

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SELECTARTICOLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>110BD275B587304EE6D54D70D1E9C1DBDA164C94</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SELECTARTICOLE IS


FUNCTION CHECK_TABLE_FOR_OBIECT(aTABLENAME IN VARCHAR2, aCODOBIECT IN NUMBER ) RETURN NUMBER
IS
  NR NUMBER(10) := 0;
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT COUNT(*) FROM &apos; || aTABLENAME || &apos; WHERE CODOBIECT = &apos; || TO_CHAR(aCODOBIECT) INTO NR;
  RETURN NR;
END;

FUNCTION OBIECT_IMPLICAT_IN_TRANZACTII(aCODOBIECT IN NUMBER) RETURN NUMBER IS
  NR NUMBER(10) := 0;
BEGIN
  NR := CHECK_TABLE_FOR_OBIECT(&apos;NIRSTOC&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;CERTIF&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;CMDPRODMAT&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;CMDPRODREZ&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;COMANDA1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;CONTRACT1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;DISCART&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;DVI1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;EMULARE1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;IESIRI1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;INTRARI1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;INVENTAR1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;LIVRVAL&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;
--  NR := CHECK_TABLE_FOR_OBIECT(&apos;NARTAMB&apos;, aCODOBIECT);
--  IF NR &gt; 0 THEN
--    RETURN 1;
--  END IF;

--  NR := CHECK_TABLE_FOR_OBIECT(&apos;NARTCLI&apos;, aCODOBIECT);
--  IF NR &gt; 0 THEN
--    RETURN 1;
--  END IF;

--  NR := CHECK_TABLE_FOR_OBIECT(&apos;NARTOBJSUBUNIT&apos;, aCODOBIECT);
--  IF NR &gt; 0 THEN
--    RETURN 1;
--  END IF;
  NR := CHECK_TABLE_FOR_OBIECT(&apos;NECHIV&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;NODECHIV&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;NSERII&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;OFERTA1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PLUCASE&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PMPLUNA&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PMP_ALL_LUNA&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

--  NR := CHECK_TABLE_FOR_OBIECT(&apos;PRETM&apos;, aCODOBIECT);
--  IF NR &gt; 0 THEN
--    RETURN 1;
--  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PRODCOMP&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PRODMAT&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;PRODREZ&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;STOCLOCKEMUL&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;STOCPOSURI&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  NR := CHECK_TABLE_FOR_OBIECT(&apos;TRANSF1&apos;, aCODOBIECT);
  IF NR &gt; 0 THEN
    RETURN 1;
  END IF;

  RETURN 0;
END;

PROCEDURE SETOBIECTANALIZAT(aCODOBIECT IN NUMBER)
IS
BEGIN
  COD_OBIECT_ANALIZAT:= aCODOBIECT;
END;

FUNCTION GETOBIECTANALIZAT RETURN NUMBER
IS
BEGIN
  RETURN COD_OBIECT_ANALIZAT;
END;

PROCEDURE SET_OBIECT_TAXE_FACTURARE(aOBIECT IN NUMBER)
IS
BEGIN
  OBIECT_TAXE_FACTURARE := aObiect;
END;

FUNCTION GET_OBIECT_TAXE_FACTURARE RETURN NUMBER
IS
BEGIN
  RETURN OBIECT_TAXE_FACTURARE;
END;

PROCEDURE SET_OBIECT_ECHIVALAT(aOBIECT IN NUMBER)
IS
BEGIN
  OBIECT_ECHIVALAT := aObiect;
  BEGIN
    SELECT CodGrupa, Paritate into GRUPA_OBIECT_ECHIVALAT, PARITATE_OBIECT_ECHIVALAT  FROM NEchiv WHERE CODOBIECT = aObiect;
    EXCEPTION WHEN OTHERS THEN GRUPA_OBIECT_ECHIVALAT := -1;
  END;
END;

FUNCTION GET_PARITATE_OBIECT_ECHIVALAT RETURN NUMBER
IS
BEGIN
  if Coalesce(PARITATE_OBIECT_ECHIVALAT,0) = 0 then PARITATE_OBIECT_ECHIVALAT := 1; end if;
	RETURN PARITATE_OBIECT_ECHIVALAT;
END;

FUNCTION GET_OBIECT_ECHIVALAT RETURN NUMBER
IS
BEGIN
  RETURN OBIECT_ECHIVALAT;
END;

FUNCTION GET_GRUPA_OBIECT_ECHIVALAT RETURN NUMBER
IS
BEGIN
  RETURN NVL(GRUPA_OBIECT_ECHIVALAT, 0);
END;

PROCEDURE SETCLASA(CLASA IN NUMBER)
IS
BEGIN
  CODCLASA := CLASA;
END;

PROCEDURE SETCODART(ART IN NUMBER)
IS
BEGIN
  CODARTICOL := ART;
END;


FUNCTION GETCLASACURENTA RETURN NUMBER
IS
BEGIN
  RETURN CODCLASA;
END;

FUNCTION GETCODARTCURENT RETURN NUMBER IS
BEGIN
  RETURN CODARTICOL;
END;

FUNCTION GETDENOBIECT(OBIECT IN NUMBER) RETURN VARCHAR IS
  DEN VARCHAR(100):= &apos;&apos;;
  NR NUMBER := 0;
  I  NUMBER := 0;
BEGIN
  SELECT COUNT(*) INTO NR FROM NATROBJ WHERE CODOBIECT = OBIECT;
  IF NR = 0
  THEN RETURN &apos;... FARA ATRIBUTE ...&apos;;
  ELSE
    FOR V_REC IN (
      SELECT  T.VALOARE AS VALOARE
      FROM NATROBJ O, NATRIB1 T
      WHERE O.CODOBIECT = OBIECT AND O.CODVALATR = T.CODVALATR
    ) LOOP
      IF I = 0
      THEN DEN := V_REC.VALOARE;
      ELSE DEN := DEN || &apos; &apos; || V_REC.VALOARE;
      END IF;
      I := I + 1;
    END LOOP;
    RETURN DEN;
  END IF;
END;

FUNCTION GETDENOBIECTEXT(OBIECT IN NUMBER) RETURN VARCHAR IS
  ACOD NUMBER(20);
  DEN  VARCHAR(100):= &apos;&apos;;
BEGIN
  BEGIN
    SELECT O.CODOBIECT, A.DEN_ARTICOL || &apos; &apos; || STRING_AGG(B.VALOARE) INTO ACOD, DEN
    FROM NARTOBJ O
      LEFT JOIN NART    A ON A.CODARTICOL = O.CODARTICOL
      LEFT JOIN NATROBJ T ON T.CODOBIECT  = O.CODOBIECT
      LEFT JOIN NATRIB1 B ON T.CODVALATR  = B.CODVALATR
    WHERE O.CODOBIECT = OBIECT
    GROUP BY O.CODOBIECT, A.DEN_ARTICOL;
  EXCEPTION WHEN OTHERS THEN
    RETURN &apos;&apos;;
  END;
  RETURN DEN;
END;

FUNCTION GET_JUST_DENOBIECT(OBIECT IN NUMBER) RETURN VARCHAR IS
  ACOD NUMBER(20);
  DEN  VARCHAR(250):= &apos;&apos;;
  LUNG NUMBER(10) := 0;
BEGIN
  BEGIN
    SELECT O.DENUMIRE, LENGTH(A.DEN_ARTICOL) INTO DEN, LUNG
    FROM NARTOBJ O, NART A WHERE O.CODOBIECT = OBIECT AND O.CODARTICOL = A.CODARTICOL;
  EXCEPTION
    WHEN OTHERS THEN RETURN NULL;
  END;
  RETURN TRIM(SUBSTR(DEN, LUNG + 1, LENGTH(DEN)));
END;

FUNCTION GETDEN_ART_OBJ(DENART IN VARCHAR, OBIECT IN NUMBER) RETURN VARCHAR IS
  DEN VARCHAR(100):= &apos;&apos;;
BEGIN
  DEN := DENART;
  FOR V_REC IN (
    SELECT T.VALOARE AS VALOARE  FROM NATROBJ O, NATRIB1 T
    WHERE O.CODOBIECT = OBIECT AND O.CODVALATR = T.CODVALATR
  ) LOOP
    DEN := DEN || &apos; &apos; || V_REC.VALOARE;
  END LOOP;
  RETURN DEN;
END;

FUNCTION GETOBIECTIMPLICIT(
  ARTCOD      IN  NUMBER,
  UMAMBALARE  OUT NUMBER,
  ZILEPLATA   OUT NUMBER,
  TIPPRETMAX  OUT NUMBER,
  PRETMAXIMAL OUT NUMBER,
  PROCADAOS   OUT NUMBER,
  CODEXTERN   OUT VARCHAR2,
  CODINTERN   OUT VARCHAR2,
  BLOCAT      OUT NUMBER,
  ROTUNJIRE   OUT NUMBER
) RETURN NUMBER IS
  COD NUMBER  := -1;
  aUMAMBALARE NUMBER := 0;
BEGIN
  FOR V_REC IN (
    SELECT
      O.CODOBIECT, O.PROCADAOSNIR, O.UMAMBALARE, O.TERMENPLATA, O.CODEXTERN, O.CODINTERN,O.BLOCAT,O.ROTVALUTA,
      O1.TIPPRETMAX, O1.PRETMAXIMAL
    FROM NARTOBJ O LEFT JOIN NARTOBJ1 O1 ON O1.CODOBIECT = O.CODOBIECT AND PKG_GLOBALS.AnLunaLucru BETWEEN O1.ALStart AND O1.ALStop
    WHERE CODARTICOL = ARTCOD
  ) LOOP
    UMAMBALARE  := V_REC.UMAMBALARE;
    ZILEPLATA   := V_REC.TERMENPLATA;
    TIPPRETMAX  := V_REC.TIPPRETMAX;
    PRETMAXIMAL := V_REC.PRETMAXIMAL;
    PROCADAOS   := V_REC.PROCADAOSNIR;
    CODEXTERN   := V_REC.CODEXTERN;
    CODINTERN   := V_REC.CODINTERN;
    BLOCAT      := V_REC.BLOCAT;
    ROTUNJIRE   := V_REC.ROTVALUTA;
    RETURN V_REC.CODOBIECT;
  END LOOP;
  UMAMBALARE := aUMAMBALARE;
  RETURN COD;
END;

FUNCTION CONDITIECLASA(OCLASA IN NUMBER) RETURN NUMBER IS
BEGIN
  IF CODCLASA = 0
  THEN RETURN 1;
  ELSE RETURN PKG_GLOBALS.IS_SUBCLAS_OF(OCLASA, CODCLASA);
  END IF;
END;

PROCEDURE SETUMPRINCIPALA(UMP IN NUMBER) IS
BEGIN
  UMPRINCIPALA := UMP;
END;

FUNCTION CONDITIEUMPRINCIPALA(UMP IN NUMBER) RETURN NUMBER IS
BEGIN
  IF UMPRINCIPALA = UMP
  THEN RETURN 1;
  ELSE RETURN 0;
  END IF;
END;

FUNCTION GETARTOFOBJECT(CODOBJ IN NUMBER) RETURN NUMBER IS
ART NUMBER(20);
BEGIN
  ART := 0;
  BEGIN
    SELECT CODARTICOL INTO ART FROM NARTOBJ WHERE CODOBIECT = CODOBJ;
  EXCEPTION
    WHEN OTHERS THEN ART := 0;
  END;
  RETURN  ART;
END;

FUNCTION GETCLASAOFART(CODART IN NUMBER) RETURN NUMBER IS
OCLASA NUMBER(20);
BEGIN
  OCLASA := 0;
  BEGIN
    SELECT CLASA INTO OCLASA FROM NART WHERE CODARTICOL = CODART;
  EXCEPTION
    WHEN OTHERS THEN OCLASA := 0;
  END;
  RETURN  OCLASA;
END;

FUNCTION GETPROCENTTVA(CODART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN NUMBER IS
  APROCENT NUMBER(20, 6) := -1;
  CTVA     NUMBER(20)    := -1;
  AL       NUMBER(5)     := AN*12+LUNA;
BEGIN
  BEGIN
    SELECT Coalesce(CODTVA, 0) INTO CTVA
    FROM NART1 N1
    WHERE N1.CODARTICOL = CODART AND AL BETWEEN N1.ALStart AND N1.ALStop;
  EXCEPTION
    WHEN OTHERS THEN APROCENT := -1;
  END;

  BEGIN
    IF CTVA &gt; 0 THEN
      SELECT Coalesce(PROCENT, -1) INTO APROCENT
      FROM NTVA1 T1
      WHERE T1.CODTVA = CTVA AND AL BETWEEN T1.ALStart AND T1.ALStop;
    END IF;
  EXCEPTION
    WHEN OTHERS THEN APROCENT := -1;
  END;
  RETURN APROCENT;
END;

FUNCTION ARTICOLPROMOTIONAL(aCODOBIECT IN NUMBER, aPROCDISC OUT NUMBER) RETURN NUMBER IS
 PROMO NUMBER(10) := 0;
BEGIN
  aPROCDISC := 0;
  BEGIN
    SELECT PROMOTIE, DISCPROMO INTO PROMO, aPROCDISC FROM NARTOBJ WHERE CODOBIECT = aCODOBIECT;
    EXCEPTION WHEN OTHERS THEN BEGIN
      PROMO     := 0;
      aPROCDISC := 0;
    END;
  END;
  RETURN PROMO;
END;

FUNCTION ARTICOLPROMOTIONALRETAIL(aCODOBIECT IN NUMBER, aCODPOSTRETAIL IN NUMBER, aPROCDISC OUT NUMBER) RETURN NUMBER IS
 PROMO NUMBER(10) := 0;
BEGIN
  aPROCDISC := 0;
  BEGIN
    SELECT
      PROMOTIE,
      NVL(RP.DISCPROMO, O.DISCPROMO) AS DISCPROMO INTO PROMO, aPROCDISC
    FROM
      NARTOBJ O
      LEFT JOIN DISCPROMORETAIL RP ON RP.CODOBIECT = O.CODOBIECT AND RP.CODPOSTRETAIL = aCODPOSTRETAIL
    WHERE
      O.CODOBIECT = aCODOBIECT;
    EXCEPTION WHEN OTHERS THEN BEGIN
      PROMO     := 0;
      aPROCDISC := 0;
    END;
  END;
  RETURN PROMO;
END;

FUNCTION GET_RECORD_NART(ACODART IN NUMBER) RETURN NART_CURSOR IS
TMPCURSOR NART_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT A.CODARTICOL,
          DEN_ARTICOL,
          TIPARTICOL,
          CLASA,
          UM,
          UM1,
          UM2,
          TIPSERIE,
          AI.CONTIMPLICIT,
          AI.GESTIMPLICITA,
          AI.LOCATIEIMPLICITA,
          CERTIFICAT,
          ARETG,
          EVOLUTIEPRET,
          CONTSERVICIU,
          INCREMENTSERIE,
          A.RELATIEUM1,
          A.RELATIEUM2,
          A.D1,
          A.D2,
          A.D3,
          A.CODCENTRU,
          CLA.DEN_CLASEA,
					A.ParitateD1,
          A.ParitateD2,
          A.ParitateD3,
          A.CODMASCA,
          A.RiscFiscal,
          A.CLASASTATIST
    FROM
      NART A
      LEFT JOIN NCLASEA CLA  ON CLA.CODCLASEA = A.CLASA
      LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
    WHERE A.CODARTICOL = ACODART;
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_RECORD_NART1(ACODART IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NART_CURSOR IS
  TMPCURSOR NART_CURSOR;
  AL        NUMBER(5) := aAn*12+aLuna;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT *
    FROM NART1 A1
    WHERE A1.CODARTICOL = ACODART AND AL BETWEEN A1.ALStart AND A1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_RECORD_NARTOBJ1(ACODOBIECT IN NUMBER, aAN IN NUMBER, aLUNA IN NUMBER) RETURN NART_CURSOR IS
  TMPCURSOR NART_CURSOR;
  AL        NUMBER(5) := aAn*12+aLuna;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT *
    FROM NARTOBJ1 O1
    WHERE O1.CODOBIECT = ACODOBIECT AND AL BETWEEN O1.ALStart AND O1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_RECORD_NARTOBJ(ACODOBIECT IN NUMBER) RETURN NARTOBJ_CURSOR IS
  TMPCURSOR NARTOBJ_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      O.*,
      A.UM,
      A.TIPARTICOL,
      A.ARETG,
      A.RELATIEUM1,
      A.RELATIEUM2,
      A.TIPSERIE,
      A.UM1,
      A.UM2,
      AI.CODIMPLICIT,
      AI.CODARTICOL,
      AI.CODSUBUNIT,
      CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END CONTIMPLICIT,
      CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END GESTIMPLICITA,
      AI.NEVANDABIL,
      CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END LOCATIEIMPLICITA,
      O1.TIPPRETMAX,
      O1.PRETMAXIMAL,
      O1.PRETREFERINTA,
      NPRT.DEN_PART AS PRODUCATOR,
      NCLS.DEN_CLASEA AS ClasaArticol, O.Masa,
      U.Den_UM DUM
    FROM NARTOBJ O
      LEFT JOIN NART          A  ON A.CODARTICOL  = O.CODARTICOL
      LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
      LEFT JOIN NARTOBJIMP    OI ON OI.CODOBIECT  = O.CODOBIECT  AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
      LEFT JOIN NARTOBJ1      O1 ON O1.CODOBIECT  = O.CODOBIECT  AND PKG_GLOBALS.AnLunaLucru BETWEEN O1.ALStart AND O1.ALStop
      LEFT JOIN NPART NPRT ON O.CODPRODUCATOR = NPRT.CODPART
      LEFT JOIN NCLASEA NCLS ON NCLS.Codclasea = A.CLASA
      LEFT JOIN NUM U ON U.CodUM = A.UM
    WHERE O.CODOBIECT = ACODOBIECT;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_INFO_OBIECT_LUNA(aCODOBIECT IN NUMBER) RETURN NARTOBJ_CURSOR IS
 TMPCURSOR OBJ_STOCINFO_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
       Coalesce(A.TIPARTICOL, &apos;0&apos;) AS TIPARTICOL,
       NTVA.PROCENT,
       NUM1.CODUM1 AS UMSEC,
       NUM1.DEN_UM1,
       NTVA.CODTVA,
       CASE WHEN COALESCE(OI.CONTIMPLICIT,0)     = 0 THEN AI.CONTIMPLICIT     ELSE COALESCE(OI.CONTIMPLICIT,0)     END CONTIMPLICIT,
       CASE WHEN COALESCE(OI.GESTIMPLICITA,0)    = 0 THEN AI.GESTIMPLICITA    ELSE COALESCE(OI.GESTIMPLICITA,0)    END GESTIMPLICITA,
       CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END LOCATIEIMPLICITA,
       O.DENUMIRE,
       A.ARETG,
       A.TIPSERIE,
       A.CONTSERVICIU,
       O.CodObiect,
       O.UMAMBALARE,
       UMA.DEN_UM1 AS DEN_UMAMB,
       UMA.PARITATE AS PARITATEAMB,
       O.PROMOTIE,
       O.ROTUNJIRE,
       A.UM
    FROM NARTOBJ O
      LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
      LEFT JOIN NUM1 UMA           ON O.UMAMBALARE   = UMA.CODUM1,
      NART A
      LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
      LEFT JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL
      LEFT JOIN TMP_NTVA_LUNA NTVA ON NTVA.CODTVA    = NAL.CODTVA
      LEFT JOIN NUM1               ON NUM1.CODUM     = A.UM AND NUM1.SECUNDARA = 0
    WHERE O.CODOBIECT = aCODOBIECT AND A.CODARTICOL = O.CODARTICOL;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GETINFOSTOC(ACODOBIECT IN NUMBER) RETURN OBJ_STOCINFO_CURSOR IS
 TMPCURSOR OBJ_STOCINFO_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT G.DEN_GEST, IO.DEN_IOART, NUM.DEN_UM, SUM(NS.REST) AS STOC
    FROM
      NIRSTOC NS
      LEFT JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART ,
      NIR N,
      NGEST G,
      IOART IO,
      NARTOBJ O,
      NART A,
      NUM
    WHERE
      NS.CODOBIECT = ACODOBIECT AND N.CODNIR = NS.CODNIR AND NS.REST &lt;&gt; 0
      AND G.CODGEST = N.GEST
      AND NS.CODIOART = IO.CODIOART
      AND IOA.MG &lt;&gt; 5
      AND O.CODOBIECT = ACODOBIECT AND A.CODARTICOL = O.CODARTICOL AND A.UM = NUM.CODUM
    GROUP BY G.DEN_GEST, IO.DEN_IOART, NUM.DEN_UM;
    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT NULL, NULL, 0, NULL FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GETRECORDTVA(CODART IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN LUNA_REF_CURSOR IS
  CTVA      NUMBER(20) := -1;
  TMPCURSOR LUNA_REF_CURSOR;
  AL        NUMBER(5) := An*Luna;
BEGIN
  BEGIN
    SELECT Coalesce(CODTVA, 0) INTO CTVA
    FROM NART1 N1
    WHERE N1.CODARTICOL = CODART AND AL BETWEEN N1.ALStart AND N1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1 FROM DUAL;
  END;

  BEGIN
    IF CTVA &gt; 0 THEN
      OPEN TMPCURSOR FOR SELECT * FROM NTVA1 T1 WHERE T1.CODTVA = CTVA AND AL BETWEEN T1.ALStart AND T1.ALStop;
    ELSE
      OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
    END IF;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;

  RETURN TMPCURSOR;
END;

FUNCTION GETRECORDIOART(IOARTCOD IN NUMBER, AN IN NUMBER, LUNA IN NUMBER) RETURN LUNA_REF_CURSOR IS
  TMPCURSOR LUNA_REF_CURSOR;
  AL        NUMBER(5) := An*Luna;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
      SELECT I1.*, IO.CODVANZARE
      FROM IOART1 I1 LEFT JOIN IOART IO ON IO.CODIOART = I1.CODIOART
      WHERE I1.CODIOART = IOARTCOD AND AL BETWEEN I1.ALStart AND I1.ALStop;
  EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR SELECT -1 FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

PROCEDURE SETPARITATESTOCMOMENT(PARITATE IN NUMBER) IS
BEGIN
  PARITATESTOCMOMENT := PARITATE;
END;

FUNCTION GETPARITATESTOCMOMENT RETURN NUMBER IS
BEGIN
  RETURN PARITATESTOCMOMENT;
END;

FUNCTION GETDENGEST(GEST IN NUMBER) RETURN VARCHAR IS
DEN VARCHAR(30) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT NVL(DEN_GEST, &apos;&apos;) INTO DEN FROM NGEST WHERE CODGEST = GEST;
    EXCEPTION WHEN OTHERS THEN DEN := &apos;&apos;;
  END;
  RETURN DEN;
END;

FUNCTION GETDENIOART(IOART IN NUMBER) RETURN VARCHAR
IS
DEN VARCHAR(30) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT NVL(DEN_IOART, &apos;&apos;) INTO DEN FROM IOART WHERE CODIOART = IOART;
  EXCEPTION WHEN OTHERS THEN DEN := &apos;&apos;;
  END;
  RETURN DEN;
END;

PROCEDURE SETCODINTREXCLUS(COD IN NUMBER)
IS
BEGIN
  COD_INTR_EXCLUS := COD;
END;

FUNCTION GETCODINTREXCLUS RETURN NUMBER
IS
BEGIN
  RETURN COD_INTR_EXCLUS;
END;

FUNCTION EXCLUDSTOCDININTRAREA(ACODINTR IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF COD_INTR_EXCLUS = 0
  THEN RETURN 0;
  ELSE
    IF ACODINTR = COD_INTR_EXCLUS
    THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  END IF;
END;

PROCEDURE SETCODTRANSFEXCLUS(COD IN NUMBER)
IS
BEGIN
  COD_TRANSF_EXCLUS := COD;
END;

FUNCTION GETCODTRANSFEXCLUS RETURN NUMBER
IS
BEGIN
  RETURN COD_TRANSF_EXCLUS;
END;

FUNCTION EXCLUDSTOCDINTRANSFERUL(ACODTRANSF IN NUMBER) RETURN NUMBER
IS
BEGIN
  IF COD_TRANSF_EXCLUS = 0  THEN RETURN 0;
  ELSE
    IF ACODTRANSF = COD_TRANSF_EXCLUS
    THEN RETURN 1;
    ELSE RETURN 0;
    END IF;
  END IF;
END;

FUNCTION EXCLUDSTOCDINTRANSF1(ACODTRANSF1 IN NUMBER) RETURN NUMBER
IS
ACODTRANSF NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT CODTRANSF INTO ACODTRANSF FROM TRANSF1 WHERE CODTRANSF1 = ACODTRANSF1;
  EXCEPTION WHEN OTHERS THEN ACODTRANSF := 0;
  END;
  RETURN  EXCLUDSTOCDINTRANSFERUL(ACODTRANSF);
END;

FUNCTION GETPROCTVALUNALUCRU(CODART IN NUMBER) RETURN NUMBER IS
BEGIN
  RETURN GETPROCENTTVA(CODART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
END;

FUNCTION GETGRUPAOBIECT(aCODOBIECT IN NUMBER) RETURN VARCHAR2 IS
  aGRUPA VARCHAR2(20) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT GRUPA INTO aGRUPA FROM TMP_NARTOBJ_LUNA WHERE CODOBIECT = aCODOBIECT;
    EXCEPTION WHEN OTHERS THEN aGRUPA := &apos;&apos;;
  END;
  RETURN aGRUPA;
END;

PROCEDURE SETRETURNABIL(aRETURNABIL IN NUMBER) IS
BEGIN
  RETURNABIL := Coalesce(aRETURNABIL,0);
END;

FUNCTION CONDITIERETURNABIL(aRETURNABIL IN NUMBER) RETURN NUMBER IS
BEGIN
  IF RETURNABIL = 0
  THEN RETURN 1;
  ELSE RETURN Coalesce(aReturnabil,0);
  END IF;
END;

PROCEDURE MAKE_DEN_OBIECTE_CU_ATRIBUTE IS
DEN VARCHAR2(200);
BEGIN
  FOR V_REC IN (SELECT * FROM NARTOBJ O WHERE (SELECT COUNT(*) FROM NATROBJ AO WHERE AO.CODOBIECT = O.CODOBIECT) &gt; 0)
  LOOP
    SELECT DEN_ARTICOL INTO DEN FROM NART WHERE CODARTICOL = V_REC.CODARTICOL;
    FOR VREC_ATR IN (
      SELECT A1.VALOARE
      FROM NATROBJ AO, NARTATR AA, NATRIB1 A1
      WHERE AO.CODOBIECT = V_REC.CODOBIECT AND AA.CODARTATR = AO.CODARTATR AND A1.CODVALATR = AO.CODVALATR ORDER BY AA.INDEXLOCAL
    ) LOOP
      DEN := DEN || &apos; &apos; || VREC_ATR.VALOARE;
    END LOOP;

    UPDATE NARTOBJ
    SET DENUMIRE = DEN
    WHERE CODOBIECT = V_REC.CODOBIECT;
  END LOOP;
  COMMIT;
END;

FUNCTION CLASA_OBIECT_VALID_PE_LOCATIE (aCODLOCATIE IN NUMBER, aCODCLASA IN NUMBER, aCODOBIECT IN NUMBER) RETURN NUMBER IS
 aCODTIPSEDIU NUMBER(20);
 aICLASA      NUMBER(5);
 RES          NUMBER(5);
BEGIN
  BEGIN
    SELECT Coalesce(CODTIPSEDIU, 0) INTO aCODTIPSEDIU FROM NAGENDA WHERE CODAGENDA = aCODLOCATIE;
  EXCEPTION WHEN OTHERS THEN aCODTIPSEDIU := 0;
  END;

  IF aCODTIPSEDIU = 0 THEN RETURN 1; END IF;

  BEGIN
    SELECT Coalesce(ICLASA, 1) INTO aICLASA FROM NTIPSEDII WHERE CODTIPSEDIU = aCODTIPSEDIU;
  EXCEPTION WHEN OTHERS THEN aICLASA := 1;
  END;

  IF aICLASA = 1 THEN RETURN 1; END IF;

  SELECT COUNT(*) INTO RES
  FROM NTIPSEDII1
  WHERE CODTIPSEDIU = aCODTIPSEDIU
		AND ((Coalesce(CODCLASEA, 0) &lt;&gt; 0 AND CODCLASEA = aCODCLASA) OR (Coalesce(CODOBIECT, 0) &lt;&gt; 0 AND CODOBIECT = aCODOBIECT));

  IF RES &gt; 0 THEN RETURN 1; ELSE RETURN 0; END IF;
END;

END PKG_SELECTARTICOLE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27A461BC1AB018EF710C030AB5BFDF150B62DA1E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SERII IS

PROCEDURE SET_SEQ_SERIE_UNICA(NR IN NUMBER)
IS
PRAGMA AUTONOMOUS_TRANSACTION;
  sInsert  VARCHAR2(20000);
  X number;
BEGIN
  SELECT SEQ_SERIE_UNICA.NEXTVAL into X FROM dual;
  if X &lt; NR then 
    sInsert := &apos;ALTER SEQUENCE SEQ_SERIE_UNICA INCREMENT BY &apos;||to_char(NR - X);
    EXECUTE IMMEDIATE sInsert;
    SELECT SEQ_SERIE_UNICA.NEXTVAL INTO X FROM dual;
    sInsert := &apos;ALTER SEQUENCE SEQ_SERIE_UNICA INCREMENT BY 1&apos;; 
    EXECUTE IMMEDIATE sInsert;
  end if;
END;

FUNCTION GetMascaLastSerie(aMasca in varchar2) RETURN varchar2 IS
sSerie varchar2(100) := &apos;&apos;;
BEGIN
  BEGIN
		with Ser as (select * from nserii where aMasca = &apos;%&apos; or SERIE like aMasca)
		Select Serie into sSerie from NSERII
			where CodSerie = ( Select NS.CodSerie from NIRSER NS 
												 where NS.CodNIRSer = (select Max(NS.CodNirSer) from NirSer NS inner join Ser on NS.CodSerie = Ser.CodSerie));
  EXCEPTION
		WHEN OTHERS THEN sSerie := &apos;&apos;;
	END;
	Return sSerie;
END;

PROCEDURE SETOBIECTCURENT(ACODOBIECT IN NUMBER) IS
BEGIN
  OBIECTCURENT := ACODOBIECT;
END;

FUNCTION GETOBIECTCURENT RETURN NUMBER IS
BEGIN
  RETURN OBIECTCURENT;
END;

PROCEDURE SP_LOCKRECORD(RECID IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT SERIE INTO TMP FROM NSERII WHERE CODSERIE = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NSERII FIELDS(CODSERIE) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_DELETERECORD(RECID IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RECID);
	DELETE FROM NSERII WHERE CODSERIE = RECID ;
  NotifyModif(2, RecId, &apos;NSERII&apos;);
	COMMIT;
END;

PROCEDURE SP_GOTORECORD(RECID IN NUMBER) IS
BEGIN
  INSERT INTO TMP_NSERII (CODSERIE, SERIE, CODOBIECT, OBS)
    (SELECT CODSERIE, SERIE, CODOBIECT, OBS FROM NSERII WHERE CODSERIE = RECID);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER) IS
BEGIN
  IF OPERATION = 0 THEN -- UPDATE
    SELECT CODSERIE INTO RECID FROM TMP_NSERII;
    UPDATE NSERII SET (CODSERIE, SERIE, CODOBIECT, OBS)
      = (SELECT CODSERIE, SERIE, CODOBIECT, OBS FROM TMP_NSERII)
      WHERE CODSERIE = RECID;
  ELSE -- INSERT
    SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO  NSERII ( CODSERIE, SERIE, CODOBIECT, OBS)
      (SELECT RECID, SERIE, CODOBIECT, OBS FROM TMP_NSERII);
  END IF;
  NotifyModif(Operation, RecId, &apos;NSERII&apos;);
  COMMIT;
END;

END PKG_SERII; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D5F28898B81650E02DE4C653EAA0F1A5CF78CAE</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SERTAR IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_68&apos;;

PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodSertar INTO Tmp FROM NSERTAR WHERE CodSertar = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
aCODSUBUNIT NUMBER(20) := 0;
aDATADOC DATE := NULL;
aDOC VARCHAR2(10) := NULL;
BEGIN
  SP_LOCKRECORD(RecId);

  BEGIN
    SELECT 
      SUBUNITATE, 
       DATADOC, 
      &apos;SER&apos; 
    INTO  
      aCodSubunit, 
      aDataDoc, 
      aDoc 
    FROM 
    NSERTAR 
      WHERE CODSERTAR = RECID;
  EXCEPTION WHEN OTHERS THEN NULL;   
  END;   
  -- mSertar --&gt; 69
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 69);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
  THEN
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSERTAR&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                      aCodSubunit, aDataDoc, aDoc,null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;                                    
  -- DETAIL
  DELETE FROM NSERTAR1 WHERE CodSertar = RecId;
  -- MASTER
	DELETE FROM NSERTAR WHERE CodSertar = RecId;
  NotifyModif(2, RecId, &apos;NSERTAR&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_NSERTAR FIELDS(CodSertar) VALUES (0);
  --mSertar --&gt; 69
  PKG_CFGTABLES.EXT_INSERTRECORD(69); 
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  -- MASTER
  DELETE FROM TMP_NSERTAR;
  INSERT INTO TMP_NSERTAR
    (CodSertar, CodEmitent, CodPartener, Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, Depus, DataCreare, UserID, Obs, DataOblig, 
     Banca, Moneda, Emitent, Partener, NRI)
    (SELECT
       NS.CodSertar, NS.CodEmitent, NS.CodPartener, NS.Subunitate, NS.Tip, NS.Decont, NS.Doc, NS.NrDoc, NS.DataDoc, NS.Valoare, NS.DataDecont, NS.Depus, NS.DataCreare, NS.UserID, NS.Obs, NS.DataOblig, 
       NS.Banca, NS.Moneda, NPE.Den_Part, NPP.Den_Part, NS.NRI
     FROM NSERTAR NS
     LEFT OUTER JOIN NPART NPE ON NPE.CodPart = NS.CodEmitent
     LEFT OUTER JOIN NPART NPP ON NPP.CodPart = NS.CodPartener
     WHERE NS.CodSertar = RecId);
  -- DETAIL
  DELETE FROM TMP_NSERTAR1;
  INSERT INTO TMP_NSERTAR1
    (CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
    (SELECT
       NS1.CodSertar1, NS1.CodSertar, NS1.CodObligPIF, NS1.Valoare, DenDocLegatura, O.CodGeneral
     FROM NSERTAR1 NS1
     INNER JOIN OBLIGPIF O ON O.CodObligPIF = NS1.CodObligPIF
     WHERE CodSertar = RecId);
   -- DETAIL INITIAL
   DELETE FROM TMP_NSERTAR1_INITIAL;
   INSERT INTO TMP_NSERTAR1_INITIAL (SELECT * FROM TMP_NSERTAR1);
   -- mSertar --&gt; 69
   PKG_CFGTABLES.EXT_GOTORECORD(69);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
  aCODSUBUNIT NUMBER(20) := 0;
  aDATADOC DATE := NULL;
  aDOC VARCHAR2(10) := NULL;
BEGIN
  -- mSertar --&gt; 69
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (69); 
  BEGIN
    SELECT 
      SUBUNITATE, 
      DATADOC, 
      &apos;SER&apos; 
    INTO  
      aCodSubunit, 
      aDataDoc, 
      aDoc 
    FROM 
      TMP_NSERTAR; 
    EXCEPTION WHEN OTHERS THEN NULL;   
  END;   

  IF Operation = 0 THEN -- UPDATE
    SELECT CodSertar INTO RecId FROM TMP_NSERTAR;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSERTAR&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    -- MASTER
    UPDATE NSERTAR
    SET (CodSertar, CodEmitent, CodPartener, Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, 
         Depus, DataCreare, UserID, Obs, DataOblig, Banca, Moneda, NrI) =
        (SELECT
           CodSertar, CodEmitent, CodPartener, Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, 
           Depus, DataCreare, UserID, Obs, DataOblig, Banca, Moneda, NrI
         FROM TMP_NSERTAR)
    WHERE CodSertar = RecId;
    -- DETAIL
    DELETE FROM NSERTAR1 WHERE CodSertar = RecId;
    INSERT INTO NSERTAR1
      (CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
      (SELECT SEQ_NSERTAR1_CODSERTAR1.NextVal, RecId, TNS1.CodObligPIF, NVL(TNS1.Valoare, 0), TNS1.DenDocLegatura, O.CodGeneral
       FROM TMP_NSERTAR1 TNS1
       INNER JOIN OBLIGPIF O ON O.CodObligPIF = TNS1.CodObligPIF);
  ELSE  -- INSERT
    SELECT SEQ_NSERTAR_CODSERTAR.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;NSERTAR&apos;, RecId);
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR)
    THEN
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;NSERTAR&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    -- MASTER
    INSERT INTO NSERTAR (CodSertar, CodEmitent, CodPartener, Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, Depus, 
                         DataCreare, UserID, Obs, DataOblig, Banca, Moneda, NrI)
      (SELECT RecId, CodEmitent, CodPartener, PKG_GLOBALS.Subunitate, Tip, Decont, Doc, NrDoc, DataDoc, Valoare, DataDecont, 0, 
              SYSDATE, PKG_GLOBALS.UserID, Obs, DataOblig, Banca, Moneda, NRI
       FROM TMP_NSERTAR);
    -- DETAIL
    INSERT INTO NSERTAR1 (CodSertar1, CodSertar, CodObligPIF, Valoare, DenDocLegatura, CodGeneral)
    (SELECT SEQ_NSERTAR1_CODSERTAR1.NextVal, RecId, TNS1.CodObligPIF, NVL(TNS1.Valoare, 0), DenDocLegatura, O.CodGeneral
     FROM TMP_NSERTAR1 TNS1
     INNER JOIN OBLIGPIF O ON O.CodObligPIF = TNS1.CodObligPIF);
  END IF;
  -- mSertar --&gt; 69
  PKG_CFGTABLES.EXT_POSTRECORDS(69); 
  NotifyModif(Operation, RecId, &apos;NSERTAR&apos;);
  COMMIT;
END;

END PKG_SERTAR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SERVFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C115462DC5A6EE30D1D9682D743A5B84EA73B3E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SERVFACT IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20);
BEGIN
  SELECT CODSERVFACT INTO Tmp FROM SERVFACT WHERE CODSERVFACT = RecId FOR UPDATE NOWAIT;
END;



PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SERVFACT FIELDS( CODSERVFACT ) VALUES (0) ;
  COMMIT;
END;



PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);


  DELETE FROM SERVFACT1 WHERE CODSERVFACT = RecId ;
  DELETE FROM SERVFACT  WHERE CODSERVFACT = RecId ;
  NotifyModif(2, RecId, &apos;SERVFACT&apos;);
  COMMIT;
END;


PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
BEGIN
 INSERT INTO TMP_SERVFACT(CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD)
 SELECT CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT, PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD FROM SERVFACT WHERE CODSERVFACT = RECID;

 INSERT INTO TMP_SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
 SELECT CODSERVFACT1, CODSERVFACT, PANALA, VALOARE FROM SERVFACT1 WHERE CODSERVFACT = RECID ORDER BY PANALA;

  
 COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vModcalcul NUMBER;
BEGIN
  BEGIN 
   SELECT MODCALCUL INTO vModcalcul FROM TMP_SERVFACT;
   IF vModcalcul = 5 THEN --VOUCHER..nu are detalii
     DELETE FROM TMP_SERVFACT1;
   END IF;
   IF OPERATION = 0 THEN --UPDATE
    
   SELECT CODSERVFACT INTO RECID FROM TMP_SERVFACT;
  
   UPDATE SERVFACT
   SET
    (DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT,  PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD) = (SELECT DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT,  PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD FROM TMP_SERVFACT)
   WHERE
     CODSERVFACT = RECID;
      
  
    DELETE FROM SERVFACT1 S1 WHERE CODSERVFACT = RECID
    AND NOT EXISTS (SELECT CODSERVFACT1 FROM TMP_SERVFACT1 WHERE CODSERVFACT1 = S1.CODSERVFACT1);
  
    FOR V_REC IN (SELECT * FROM TMP_SERVFACT1)
    LOOP
      IF V_REC.CODSERVFACT1 &lt; 0 THEN
        INSERT INTO SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
        VALUES (SEQ_SERVFACT1_CODSERVFACT1.NEXTVAL, RECID, V_REC.PANALA, V_REC.VALOARE);
      ELSE
        UPDATE SERVFACT1
        SET
          PANALA  = V_REC.PANALA,
          VALOARE = V_REC.VALOARE
        WHERE
          CODSERVFACT1 = V_REC.CODSERVFACT1;  
      END IF;
    END LOOP;
    
    
   ELSE -- INSERT
     SELECT SEQ_SERVFACT_CODSERVFACT.NEXTVAL INTO RECID FROM DUAL;
    
     INSERT INTO SERVFACT(CODSERVFACT, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT,  PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD)
     SELECT RECID, DENUMIRE, CODOBIECT, SUMAPORNIREKM, SUMAPORNIRECANT,  PROCPORNIREKM, PROCPORNIRECANT, MODCALCUL, COD FROM TMP_SERVFACT;
     
     INSERT INTO SERVFACT1(CODSERVFACT1, CODSERVFACT, PANALA, VALOARE)
     SELECT SEQ_SERVFACT1_CODSERVFACT1.NEXTVAL, RECID, PANALA, VALOARE FROM TMP_SERVFACT1;
     
   END IF; 
   NotifyModif(Operation, RecId, &apos;SERVFACT&apos;);
   COMMIT; 
 
 EXCEPTION WHEN OTHERS THEN 
   ROLLBACK;
   RAISE;
 END;  
END;


end PKG_SERVFACT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SERVICE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F706902F279643DA0BC0EE0B8B42FD1C5805161</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SERVICE IS

tncTermen number(1) := 1;
tncVolum number(1) := 2;
tncCantitate number(1) := 3;
tncCadouri number(1) := 4;
tncProvizioane number(1) := 5;
tncPenalizari number(1) := 6;

PROCEDURE INDEXARE_EXTENSII
IS
BEGIN
  IF PKG_LIST_STRUCT.TmpExists(&apos;COMANDC&apos;) = 1 THEN
    BEGIN
      EXECUTE IMMEDIATE &apos;DROP INDEX IDX_COMANDC_CODCOMANDC&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
    END;
    EXECUTE IMMEDIATE &apos;CREATE INDEX IDX_COMANDC_CODCOMANDC ON COMANDC(CODCOMANDC)&apos;;

    BEGIN
      EXECUTE IMMEDIATE &apos;DROP INDEX IDX_COMANDC_CODCOMANDA&apos;;
      EXCEPTION WHEN OTHERS THEN NULL;
    END;
    EXECUTE IMMEDIATE &apos;CREATE INDEX IDX_COMANDC_CODCOMANDA ON COMANDC(CODCOMANDA)&apos;;


  END IF;
END;



PROCEDURE KEEP_ALIVE IS
/* NU FACE ABSOLUT NIMIC
   E APELATA PE UN TIMER DOAR CA SA NU INCHIDA SYSTEMU DE OPERARE CONEXIUEA !!!
*/
BEGIN
  NULL;
END;

PROCEDURE CHECK_STRUCT_EXTENSIE_TASK
IS
  NR  NUMBER(10) := 0;
  DT  VARCHAR2(100);
  SIR VARCHAR2(1000);
  VG  VARCHAR2(100);
  NR1 NUMBER(10) := 0;
  SKEMA VARCHAR2(250);
BEGIN
  SELECT COUNT(*) INTO NR FROM USER_TAB_COLS WHERE TABLE_NAME = &apos;SETTASKEXT&apos; AND COLUMN_ID IS NOT NULL ORDER BY COLUMN_ID;
  IF NR &gt; 0 THEN
    Sir := &apos;CREATE GLOBAL TEMPORARY TABLE TMP_SETTASKEXT(&apos; ;
    FOR V_REC IN (SELECT * FROM USER_TAB_COLS WHERE TABLE_NAME = &apos;SETTASKEXT&apos; AND COLUMN_ID IS NOT NULL ORDER BY COLUMN_ID)
    LOOP
      IF V_REC.DATA_TYPE = &apos;VARCHAR2&apos; THEN DT := &apos; VARCHAR2(&apos; || V_REC.DATA_LENGTH || &apos;) &apos;;
      ELSE
      IF V_REC.DATA_TYPE = &apos;DATE&apos; THEN DT := &apos; DATE &apos;;
      ELSE
       DT := &apos; NUMBER(&apos; || V_REC.DATA_PRECISION || &apos;,&apos; || V_REC.DATA_SCALE || &apos;) &apos;;
      END IF;
      END IF;

      IF V_REC.COLUMN_ID &lt; NR  THEN VG := &apos;, &apos;;
      ELSE
       VG := &apos;&apos;;
      END IF;
      DT := DT || VG;
      SIR := SIR || &apos; &apos; || V_REC.COLUMN_NAME || &apos; &apos; || DT;
    END LOOP;
    SIR := SIR || &apos; ) ON COMMIT PRESERVE ROWS&apos;;
    INSERT INTO X(TEST) VALUES(SIR);
    COMMIT;
    execute immediate SIR;
  END IF;
END;

PROCEDURE CALCUL_NIRSTOC_PUVAL
IS
 aAN     NUMBER (5)    := 0;
 aLUNA   NUMBER (2)    := 0;
 aMONEDA NUMBER(20)    := 0;
 aBANCA  NUMBER(20)    := 0;
 aCURS   NUMBER(20, 7) := 0;
BEGIN
 SELECT EXTRACT(MONTH FROM SYSDATE) INTO aLUNA FROM DUAL;
 SELECT EXTRACT(YEAR  FROM SYSDATE) INTO aAN FROM DUAL;

 BEGIN
   SELECT TO_NUMBER(NVL(PKG_CATEGCONST.GetValConstanta(&apos;MONEDASITV&apos;, aAN, aLUNA), &apos;0&apos;)) INTO aMONEDA FROM DUAL;
   EXCEPTION WHEN OTHERS THEN aMONEDA := 0;
 END;

 BEGIN
   SELECT TO_NUMBER(NVL(PKG_CATEGCONST.GetValConstanta(&apos;BANCASITV&apos;, aAN, aLUNA), &apos;0&apos;)) INTO aBANCA FROM DUAL;
   EXCEPTION WHEN OTHERS THEN aBANCA := 0;
 END;

 IF aBANCA &lt;&gt; 0 AND aMONEDA &lt;&gt; 0 THEN
    FOR V_REC IN
    (
      SELECT
        I.DATADOC,
        N.DATANIR,
        NS.CODNIRSTOC,
        NS.PRET,
        N.TIPNIR,
        I.CURS,
        PKG_MONEDE.GETCURSMONEDA(
        CASE WHEN
         NVL(I.MONEDA,0) = 0 THEN aMONEDA
         ELSE I.MONEDA
        END,
        aBANCA,
        TO_CHAR(N.DATANIR, &apos;DD.MM.YYYY&apos;)) AS CURSLADATA
      FROM
        NIRSTOC NS,
        NIR N,
        INTRARI I
      WHERE
           N.CODNIR = NS.CODNIR
       AND N.CODINTR IS NOT NULL
       AND (NVL(PUVAL, 0) = 0 OR PRET = NVL(PUVAL, 0))
       AND N.TIPNIR IN (1, 2, 3, 4, 5)
       AND I.CODINTR = N.CODINTR
    )
    LOOP
      aCURS := V_REC.CURSLADATA;

      IF NVL(aCURS, 0) &lt;&gt; 0 THEN
        UPDATE NIRSTOC
        SET
          PUVAL = PRET / aCURS
        WHERE
          CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;
    END LOOP;

    FOR V_REC IN
    (
      SELECT
        I.DATADOC,
        N.DATANIR,
        NS.CODNIRSTOC,
        NS.PRET,
        N.TIPNIR,
        I.CURS,
        PKG_MONEDE.GETCURSMONEDA(
        aMONEDA,
        aBANCA,
        TO_CHAR(N.DATANIR, &apos;DD.MM.YYYY&apos;)) AS CURSLADATA
      FROM
        NIRSTOC NS,
        NIR N,
        IESIRI I
      WHERE
           N.CODNIR = NS.CODNIR
       AND N.CODINTR IS NOT NULL
       AND NVL(PUVAL, 0) = 0
       AND N.TIPNIR IN (19, 20)
       AND I.CODIES = N.CODIES
    )
    LOOP
       aCURS := V_REC.CURSLADATA;

      IF NVL(aCURS, 0) &lt;&gt; 0 THEN
        UPDATE NIRSTOC
        SET
          PUVAL = PRET / aCURS
        WHERE
          CODNIRSTOC = V_REC.CODNIRSTOC;
      END IF;
    END LOOP;

    COMMIT;

 END IF;

END;



PROCEDURE UNLOCK_USER_RECORDS IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
 DELETE FROM CMDCANTLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM DOCLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM NRBONLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM NRINVLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM OBLIGPIFLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM STOCLOCK WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 DELETE FROM STOCLOCKEMUL WHERE USERID = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 UPDATE COMANDA SET USERIDBLOCAJ = NULL WHERE USERIDBLOCAJ = (Select /*+ cardinality(X,1) */ USERID from TMP_PKG_GLOBALS X);
 COMMIT;
END;


PROCEDURE CHECK_REGULOSS_LUNA
IS
  nrModificari number;
BEGIN
  FOR V_REC_MARE IN
   (SELECT * /*+ cardinality(X,1) */
    FROM
      REGOSS, TMP_PKG_GLOBALS X
    WHERE
      TIPREG   = 108
      AND AN   = ANLUCRU
      AND LUNA = LUNALUCRU
    ) LOOP

    DELETE FROM TMP_REGOSS;
    INSERT INTO TMP_REGOSS (CODREGOSS, TIPREG)
      (SELECT r.CODREGOSS,
               r.TIPREG
         FROM REGOSS r
         WHERE r.CODREGOSS = V_REC_MARE.CODREGOSS);

    DELETE FROM TMP_REGOSS1;
    nrModificari := 0;
    INSERT INTO TMP_REGOSS1
      (CODREGOSS1,
       CODREGOSS,
       CODDOC,
       TIPDOC,
       TVADOCVAL,
       TVADOC,
       TVADOCREG,
       CODGEST,
       CONT,
       SEMN,
       CURS,
       SEMNIFICATIE,
       DIFERENTA,
       CODPART,
       DEN_PART,
       DOC,
       SUBUNITATEA,
       modificari)
      select rs1.CODREGOSS1,
             rs1.CODREGOSS,
             rs1.CODDOC,
             rs1.TIPDOC,
             rs1.TVADOCVAL,
             rs1.TVADOC,
             rs1.TVADOCREG,
             rs1.CODGEST,
             rs1.CONT,
             rs1.SEMN,
             rs1.CURS,
             rs1.SEMNIFICATIE,
             rs1.TVADOCREG - rs1.TVADOCVAL,
             part.codpart,
             part.den_part,
             ies.seriadoc||&apos; &apos;||ies.nrdoc||&apos;/&apos;||to_char(ies.datadoc, &apos;dd.mm.yyyy&apos;) as doc,
             ies.subunitatea,
             0
        from REGOSS1 rs1
        join iesiri ies on ies.codies = rs1.coddoc
        join npart part on part.codpart = ies.partener
       where CODREGOSS = V_REC_MARE.CODREGOSS;
       pkg_regoss.GenerateDataXTrimestru(V_REC_MARE.Trimestrul, V_REC_MARE.Curs,V_REC_MARE.CODMONEDA);
       select count(*) into nrModificari from TMP_REGOSS1 ros1 where coalesce(ros1.modificari,0) = 1;
       if nrModificari = 0 then
         select count(*) into nrModificari
         from regoss1 rs1
         left join tmp_regoss1 trs1 on trs1.codregoss1 = rs1.codregoss1
         where rs1.codregoss = V_REC_MARE.CODREGOSS
         and trs1.codregoss1 is null;
       end if;
       if nrModificari &gt; 0 then
          update jurnal1 j1 set dirty = 1 where j1.coddoc = V_REC_MARE.CODREGOSS and j1.tipdoc = V_REC_MARE.TIPREG;
       end if;
 END LOOP;
END;

PROCEDURE CHECK_REGULPERS_LUNA
IS
      PARAM_REG_DATA DATE;
      PARAM_REG_MONEDA NUMBER(20);
      PARAM_REG_CURS NUMBER(20,7);
      LunaPrecedentaReg NUMBER(2);
      AnPrecedentReg NUMBER(20);
      DIFERENTE NUMBER(1) := 0;
      aTIPCONT NUMBER(10) := 0;
      aSEMN    NUMBER(10) := 0;

BEGIN
   FOR V_REC_MARE IN
   (SELECT * /*+ cardinality(X,1) */
    FROM
      REG, TMP_PKG_GLOBALS X
    WHERE
      TIPREG   = 47
      AND AN   = ANLUCRU
      AND LUNA = LUNALUCRU
    )
   LOOP

      -- pregatesc PARAMS din PKG_REG
      SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM DUAL;

      PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);

      -- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
      PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
      PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
      PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);

    DELETE TMP_REGPERS1_MARTOR;
    INSERT INTO TMP_REGPERS1_MARTOR(CODPERS, ICONT, SOLDDOCVAL)
    SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) FROM REGPERS1
    WHERE
      CODREG = V_REC_MARE.CODREG
    GROUP BY CODPERS, ICONT;

      -- populez TMP_REGPERS;
      DELETE FROM TMP_REGPERS1;
      DELETE TMP_SOLDPERS_SUB;

   -- folosesc manevra TMP_SOLDPERS pentru ca trebuie sa interpretez semnului soldului in functie de TIPUL CONTULUI
    INSERT INTO TMP_SOLDPERS_SUB
    (CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA)
    SELECT
      CODPERS,
      ICONT,
      CODMONEDA,
      SUBUNITATEA,
      SOLDLEI,
      SOLDVALUTA
    FROM
      V_SOLDPERS_TRANZACTII_SUB
    WHERE
      CODMONEDA =  PKG_REG.moneda_reg;
     FOR V_REC IN
     (
      SELECT * FROM TMP_SOLDPERS_SUB S
     )
     LOOP
       BEGIN
         SELECT /*+ cardinality(X,1) */ NVL(TIPCONT, 0) INTO ATIPCONT
				 FROM NCONT, TMP_PKG_GLOBALS X
				 WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, ANLUCRU, LUNALUCRU));
         EXCEPTION WHEN OTHERS THEN aTIPCONT := 0;
       END;

       IF NVL(aTIPCONT, 0) = 1 THEN aSEMN := -1;
       ELSE
       aSEMN := 1;
       END IF;

       UPDATE TMP_SOLDPERS_SUB
       SET
        SEMN  = aSEMN
       WHERE
         CODPERS = V_REC.CODPERS
         AND CODMONEDA = V_REC.CODMONEDA
         AND ICONT = V_REC.ICONT;
     END LOOP;

 		INSERT INTO TMP_REGPERS1
  	  (
  	    CodRegPers1,
        SoldDoc,
        SoldDocVal,
        SoldDocReg,
        CodPers,
        CodCont,
        ICONT,
        SUBUNITATEA,
        Diferenta,
        Den_Pers,
        Den_Cont
  		)

  SELECT  -1 * ROWNUM,
          SOLDVALUTA,
          SOLDLEI,
          SoldValuta * PKG_REG.GetCursReg,
          CodPers,
          CodCont,
          ICONT,
          SUBUNITATEA,
  				SoldValuta * PKG_REG.GetCursReg - SoldLei,
          Prenume || &apos; &apos; || Nume,
          Den_Cont
  FROM
 (
  SELECT /*+ cardinality(X,1) */
    T1.CODPERS,
    SOLDVALUTA,
    SOLDLEI,
    NUME,
    PRENUME,
    ICONT,
    SUBUNITATEA,
    PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, ANLUCRU, LUNALUCRU))) AS DEN_CONT,
    PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, ANLUCRU, LUNALUCRU)) AS CODCONT
  FROM  TMP_PKG_GLOBALS X,
  (
      SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
      FROM
      (
        SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, NVL(SOLDLEI,0) * NVL(SEMN, 1) SOLDLEI , NVL(SOLDVALUTA,0) * NVL(SEMN, 1) SOLDVALUTA
        FROM
          TMP_SOLDPERS_SUB

          UNION ALL

         SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
          FROM
           V_SOLDPERS_PREC_SUB
          WHERE
            CODMONEDA =  PKG_REG.moneda_reg

       )
       GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
    ) T1,
      NPERS NP
    WHERE
      NP.CodPers = T1.CodPers
      AND CODMONEDA = PKG_REG.GetMonedaReg
      AND	T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
    );

    -- VERIFIC DIFERENTELE APARUTE FATA DE ULTIMA REGULARIZARE
    FOR V_REC IN
      (
        SELECT
          INTBL.CODPERS,
          INTBL.SOLDDOCVAL SOLDIN,
          OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          TMP_REGPERS1_MARTOR INTBL
          LEFT OUTER JOIN
          (SELECT
             CODPERS,
             ICONT,
             SUM(SOLDDOCVAL) AS SOLDDOCVAL
           FROM
             TMP_REGPERS1
           GROUP BY
             CODPERS, ICONT
          ) OUTTBL ON OUTTBL.CODPERS = INTBL.CODPERS AND OUTTBL.ICONT = INTBL.ICONT
        UNION
        SELECT
          OUTTBL.CODPERS,
          INTBL.SOLDDOCVAL SOLDIN,
          OUTTBL.SOLDDOCVAL SOLDOUT
        FROM
          (SELECT CODPERS, ICONT, SUM(SOLDDOCVAL) AS SOLDDOCVAL FROM TMP_REGPERS1 GROUP BY CODPERS, ICONT) OUTTBL
          LEFT OUTER JOIN TMP_REGPERS1_MARTOR INTBL ON INTBL.CODPERS = OUTTBL.CODPERS AND INTBL.ICONT = OUTTBL.ICONT
      )
    LOOP
      IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
        DIFERENTE := 1; EXIT;
      END IF;
    END LOOP;

    IF DIFERENTE = 1 THEN
    UPDATE JURNAL1
    SET
      DIRTY = 1
    WHERE
      TIPDOC = 47 AND CODDOC = V_REC_MARE.CODREG;


    END IF;


  END LOOP;
END;



PROCEDURE CHECK_REGULTREZOR_LUNA
IS
  		PARAM_REG_DATA DATE;
	 	 PARAM_REG_MONEDA NUMBER(20);
		  PARAM_REG_CURS NUMBER(20,7);
		  LunaPrecedentaReg NUMBER(2);
		  AnPrecedentReg NUMBER(20);
    DIFERENTE NUMBER(1) := 0;

BEGIN
   FOR V_REC_MARE IN
   (SELECT * /*+ cardinality(X,1) */
    FROM
      REG, TMP_PKG_GLOBALS X
    WHERE
      TIPREG   = 45
      AND AN       = ANLUCRU
      AND LUNA = LUNALUCRU
    )
  LOOP

  		-- pregatesc PARAMS din PKG_REG
		  SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM DUAL;

		  PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);

  		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
  		PKG_GLOBALS.SETLUNATEMP(V_REC_MARE.ANLUCRU, V_REC_MARE.LUNALUCRU);
  		PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC_MARE.ANLUCRU, V_REC_MARE.LUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
  		PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);

    DELETE TMP_REGTREZOR1_MARTOR;
    INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
    SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;

  		-- populez TMP_REGTREZOR1;
      DELETE FROM TMP_REGTREZOR1;
    		INSERT INTO TMP_REGTREZOR1
    		  (
    		    CodRegTrezor1,
    				SoldDoc,
    				SoldDocVal,
    				SoldDocReg,
    				CodBank,
    				CodBankCont,
    				Diferenta,
    				Den_Cont,
    				NrCont,
    				Filiala,
    				Credit,
        SUBUNITATEA
    			)
    		  (
    			  SELECT
    				  -1 * ROWNUM,
    					T1.SoldValuta,
    					T1.SoldLei,
    					T1.SoldValuta * PKG_REG.GetCursReg,
    					NBC.CodBank,
    					T1.CodBankCont,
    					T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei,
    					NBC.Den_Cont,
    					NBC.NrCont,
    					NBC.Filiala,
    					NBC.Credit,
         NBC.SUBUNITATEA
    				FROM
    				(
              SELECT
    					  SoldValuta,
    						SoldLei,
    					  CodBankCont
              FROM
    					  V_SOLDURIBANCILUNA
             ) T1
    				 INNER JOIN NBANKCONT NBC ON NBC.CodBankCont = T1.CodBankCont
    				 WHERE
    				   NBC.CodMoneda = PKG_REG.GetMonedaReg AND
    					 T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
    			 );


  -- VERIFIC DIFERENTELE APARUTE FATA DE ULTIMA REGULARIZARE
      DIFERENTE :=0;
      FOR V_REC IN
       (
         SELECT  INTBL.CODBANKCONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT
         FROM
          TMP_REGTREZOR1_MARTOR INTBL
          LEFT OUTER JOIN TMP_REGTREZOR1 OUTTBL ON OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
         UNION
         SELECT  OUTTBL.CODBANKCONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT
         FROM
          TMP_REGTREZOR1 OUTTBL
          LEFT OUTER JOIN TMP_REGTREZOR1_MARTOR INTBL ON INTBL.CODBANKCONT = OUTTBL.CODBANKCONT)
        LOOP
          IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
            DIFERENTE := 1;
            EXIT;
          END IF;
        END LOOP;

        IF DIFERENTE = 1 THEN

            UPDATE JURNAL1
            SET
              DIRTY = 1
            WHERE
              TIPDOC = 45 AND CODDOC = V_REC_MARE.CODREG;

           FOR V_REC_TREZOR IN
           (SELECT T.* FROM
             TREZOR T,
             NBANKCONT BC
            WHERE
              TIPDOC IN (29, 30, 31)
              AND BC.CODBANKCONT = T.CODBANCA
              AND BC.CREDIT = 1
              AND
              EXISTS
              (
                SELECT CODBANKCONT FROM
                (
                  SELECT CODBANKCONT
                  FROM
                    TMP_REGTREZOR1
                  UNION
                  SELECT CODBANKCONT
                  FROM
                    TMP_REGTREZOR1_MARTOR
                )
                WHERE
                  CODBANKCONT = T.CODBANCA
              )
              AND AN * 12 + LUNA &gt; V_REC_MARE.AN * 12 + V_REC_MARE.LUNA
            )
           LOOP
              UPDATE JURNAL1
              SET
                DIRTY = 1
              WHERE
                TIPDOC = V_REC_TREZOR.TIPDOC
                AND CODDOC = V_REC_TREZOR.CODTREZOR;
           END LOOP;
        END IF;
  END LOOP;
END;


PROCEDURE CHECK_REGUL_LUNA
IS
 aCODREG NUMBER(20) := 0;
 REG1CONT_IDX_LOCAL NUMBER(10) := 0;
 REG1_IDX_LOCAL     NUMBER(20);
 PARAM_REG_DATA     DATE;
 PARAM_REG_MONEDA   NUMBER(20);
 PARAM_REG_CURS     NUMBER(20,7);
 DIFERENTE          number(1) := 0;
 COUNTIN            NUMBER(20) := 0;
 COUNTOUT           NUMBER(20) := 0;
 NR                 NUMBER(20) := 0;
BEGIN
   FOR V_REC_MARE IN
   (SELECT * /*+ cardinality(X,1) */
    FROM
      REG, TMP_PKG_GLOBALS X
    WHERE
      TIPREG   = 46
      AND AN       = ANLUCRU
      AND LUNA = LUNALUCRU
--      AND CODMONEDA = 105
    )
  LOOP
     DELETE TMP_REG;
     DELETE TMP_REG1;
     DELETE TMP_REG1CONT;

  -- REG
  		  DELETE FROM TMP_REG;

      INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST)
      SELECT R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol AS SIMBOLMONEDA, B.Simbol AS SIMBOLBANK, R.Provizion, R.An, R.Luna, R.CODGEST
      FROM REG R
         LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
         LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
      WHERE
          CODREG = V_REC_MARE.CODREG;


      BEGIN
        SELECT CODREG INTO aCODREG FROM TMP_REG;
        EXCEPTION WHEN OTHERS THEN aCODREG := 0;
      END;

      IF aCODREG = 0 THEN RETURN;
      END IF;

      DELETE TMP_REG1CONT_MARTOR;

    		REG1CONT_IDX_LOCAL := 0;
    		FOR V_REG1CONT IN
      		(
      		  SELECT
      				SUM(SoldDoc/* * Semn*/) AS SoldDoc,
      				SUM(SoldDocVal/* * Semn*/) AS SoldDocVal,
      				SUM(SoldDocReg/* * Semn*/) AS SoldDocReg,
      				SUM((SoldDocReg/* * Semn*/) - (SoldDocVal/* * Semn*/)) AS Diferenta,
      				Cont
      			FROM
      			  REG1 R1
         WHERE
            R1.CODREG = aCODREG
      			GROUP BY Cont
      		)
    		LOOP
    		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
    		  INSERT INTO TMP_REG1CONT_MARTOR
        		(
        		  CodReg1Cont,
        		 	SoldDoc,
        		 	SoldDocVal,
        		 	SoldDocReg,
        		 	Diferenta,
        		 	Cont
        		)
    			VALUES
      			(
      			 -1 * REG1CONT_IDX_LOCAL,
      				V_REG1CONT.SoldDoc,
      				V_REG1CONT.SoldDocVal,
      				V_REG1CONT.SoldDocReg,
        			V_REG1CONT.Diferenta,
        			V_REG1CONT.Cont
      			);
    		END LOOP;

  		SELECT DataDoc, CodMoneda, Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM TMP_REG;
  		PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);
  		-- populez TMP_REG1;
      DELETE FROM TMP_REG1;
  		  REG1_IDX_LOCAL := 0;



/* FORMA NOUA */
  PKG_REGPART.MAKE_REGPART_LUNA;
  FOR V_REC IN
  (SELECT RP.*, P.DEN_PART
   FROM
		 TMP_REGPART_LUNA RP
     LEFT OUTER JOIN NPART P ON P.CODPART = RP.CODPART
   )
  LOOP
--     IF V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal &lt;&gt; 0 THEN
     IF ABS(V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal) &gt; 0.0000001 THEN
    		  REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
    		  INSERT INTO TMP_REG1
        (
       	  CodReg1,
       			CodGeneral,
       	  Cont,
       			PrefixDoc,
          NrDoc,
          DataDoc,
        		CodPart,
          DenPart,
    					 SimbolCont,
        		SoldDocVal,
          SoldDoc,
          SoldDocReg,
        		Diferenta,
        		Document,
        		CodGest,
    					 Semn,
    					 Curs,
    					 Semnificatie,
  						  CoefProvizion,
          SUBUNITATEA,
          CODOBLIGPIF
        		)
    			VALUES
    			  ( -1 * REG1_IDX_LOCAL,
        		 	V_REC.CodGeneral,
        		  V_REC.ICONT ,
        			 V_REC.PrefixDoc,
            V_REC.NrDoc,
            V_REC.DataDoc,
        			 V_REC.CodPart,
            V_REC.Den_Part,
    					   PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)),
        			 V_REC.SoldDocVal,
            V_REC.SoldDoc,
            V_REC.SoldDoc * PARAM_REG_CURS,
        			 V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
        			 V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;),
        		  V_REC.CodGest,
    					1,
    					V_REC.Curs,
    					V_REC.Semnificatie,
  					 	V_REC.CoefProvizion,
         V_REC.SUBUNITATEA,
         V_REC.CODOBLIGPIF
    				);
     END IF;
  END LOOP;
/*END FORMA NOUA */

  FOR V_REC IN (
    SELECT /*+ cardinality(X,1) */
      R1.CODREG1, R1.CODREG, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.OBIECTTRANZ, X.ANLUCRU, X.LUNALUCRU
     FROM TMP_PKG_GLOBALS X, TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
     WHERE R1.CODOBLIGPIF = O.CODOBLIGPIF
       AND O.SEMNIFICATIE IN (500, 600)
       AND G.CODGENERAL  = O.CODGENERAL
       AND T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
    SET CONT = PKG_TREZOR.CODCONTCEC(V_REC.CONTBANKTRANZACTIE, V_REC.SEMNIFICATIE, V_REC.TIPDECONT, V_REC.OBIECTTRANZ, V_REC.AnLucru, V_REC.LunaLUCRU )
    WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;

		REG1CONT_IDX_LOCAL := 0;
		FOR V_REG1CONT IN
  		(
  		  SELECT
  				SUM(SoldDoc/* * Semn*/) AS SoldDoc,
  				SUM(SoldDocVal/* * Semn*/) AS SoldDocVal,
  				SUM(SoldDocReg/* * Semn*/) AS SoldDocReg,
  				SUM((SoldDocReg/* * Semn*/) - (SoldDocVal/* * Semn*/)) AS Diferenta,
  				Cont
--      ,
--  				SimbolCont
  			FROM
  			  TMP_REG1
  			GROUP BY
  				 Cont
--       ,
--  				 SimbolCont
  		)
		LOOP
		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
		  INSERT INTO TMP_REG1CONT
    		(
    		  CodReg1Cont,
    			 SoldDoc,
    			 SoldDocVal,
    			 SoldDocReg,
    			 Diferenta,
    			 Cont
--        ,  SimbolCont
    		)
  		VALUES
    			(
    			  -1 * REG1CONT_IDX_LOCAL,
    				 V_REG1CONT.SoldDoc,
    			 	V_REG1CONT.SoldDocVal,
    		 		V_REG1CONT.SoldDocReg,
      			V_REG1CONT.Diferenta,
      			V_REG1CONT.Cont
--         ,
--      			V_REG1CONT.SimbolCont
    		);
		END LOOP;



    DIFERENTE := 0;
    SELECT COUNT(*) INTO COUNTIN FROM TMP_REG1CONT_MARTOR;
    SELECT COUNT(*) INTO COUNTOUT FROM TMP_REG1CONT;

    IF COUNTIN &lt;&gt; COUNTOUT THEN DIFERENTE := 1;
    ELSE
      FOR V_REC IN
       (
         SELECT  INTBL.CONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT,
                 INTBL.SOLDDOCREG SOLDREGIN,
                 OUTTBL.SOLDDOCREG SOLDREGOUT
         FROM
           TMP_REG1CONT_MARTOR INTBL
           LEFT OUTER JOIN TMP_REG1CONT OUTTBL ON OUTTBL.CONT = INTBL.CONT
         UNION
         SELECT  OUTTBL.CONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT,
                 INTBL.SOLDDOCREG SOLDREGIN,
                 OUTTBL.SOLDDOCREG SOLDREGOUT
         FROM
           TMP_REG1CONT OUTTBL
           LEFT OUTER JOIN TMP_REG1CONT_MARTOR INTBL ON INTBL.CONT = OUTTBL.CONT
       )
      LOOP
        IF (NVL(V_REC.SOLDIN, 0)    &lt;&gt; NVL(V_REC.SOLDOUT, 0))OR
           (NVL(V_REC.SOLDREGIN, 0) &lt;&gt; NVL(V_REC.SOLDREGOUT, 0))
        THEN
          DIFERENTE := 1;
          EXIT;
        END IF;
      END LOOP;
    END IF;


      IF DIFERENTE &gt; 0 THEN
        SELECT COUNT(*) INTO NR FROM JURNAL1 WHERE TIPDOC = 46 AND CODDOC = aCODREG;
        IF NR = 0 THEN
          INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, DIRTY)
          VALUES (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, aCODREG, 46, -1, 1);
        ELSE
          UPDATE JURNAL1 SET DIRTY = 1 WHERE TIPDOC = 46 AND CODDOC = aCODREG;
        END IF;
      END IF;
      COMMIT;
   END LOOP;
END;


PROCEDURE DoMonitor (codExternMonitor varchar2,Obs IN varchar2 default  &apos; &apos;, IDVer in number default 0) is
PRAGMA AUTONOMOUS_TRANSACTION;
sDoc varchar2(100);
denSubunit varchar2(100);
oper varchar2(10);
aUserName varchar2(100);
aFirmaName varchar2(100);
aSubunitate varchar2(100);
aEXEVERSION varchar2(20);

begin

 Select /*+ cardinality(X,1) */ UserName,FirmaName, Subunitate,ExeVersion
                           into aUserName,aFirmaName, aSubunitate, aEXEVERSION
 from TMP_PKG_GLOBALS X;

IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,codExternMonitor) then

 sDoc:= CASE codExternMonitor
         WHEN &apos;MON_17&apos; THEN &apos;Refacere jurnal &apos;
         WHEN &apos;MON_18&apos; THEN &apos;Actualizare constante &apos;
         WHEN &apos;MON_19&apos; THEN &apos;Fixare stocuri / solduri de fina luna &apos;
         WHEN &apos;MON_20&apos; THEN &apos;Actualizare rulaj precedent conturi &apos;
         WHEN &apos;MON_21&apos; THEN &apos;Refacere stocuri la moment &apos;
         WHEN &apos;MON_22&apos; THEN &apos;Verificare repartizare solduri pe analitice noi de cont &apos;
         WHEN &apos;MON_23&apos; THEN &apos;Inregistrari cod zero &apos;
         WHEN &apos;MON_24&apos; THEN &apos;Refacere carnete de documente &apos;
         WHEN &apos;MON_25&apos; THEN &apos;Refacere codificare automata - SysID &apos;
         WHEN &apos;MON_26&apos; THEN &apos;Inchidere luna &apos;||Obs
         WHEN &apos;MON_27&apos; THEN &apos;Anulare inchidere luna &apos;||Obs
         WHEN &apos;MON_31&apos; THEN &apos;Regularizare casa/banca &apos;||SUBSTR(Obs,1,INSTR(OBS,&apos;|&apos;)-1)
         WHEN &apos;MON_32&apos; THEN &apos;Regularizare parteneri &apos;||SUBSTR(Obs,1,INSTR(OBS,&apos;|&apos;)-1)
         WHEN &apos;MON_33&apos; THEN &apos;Regularizare personal &apos;||SUBSTR(Obs,1,INSTR(OBS,&apos;|&apos;)-1)
        END;
 oper := CASE  codExternMonitor
            WHEN &apos;MON_17&apos; THEN  &apos;R&apos;
            WHEN &apos;MON_18&apos; THEN  &apos;C&apos;
            WHEN &apos;MON_19&apos; THEN  &apos;F&apos;
            WHEN &apos;MON_20&apos; THEN  &apos;C&apos;
            WHEN &apos;MON_21&apos; THEN  &apos;R&apos;
            WHEN &apos;MON_22&apos; THEN  &apos;V&apos;
            WHEN &apos;MON_23&apos; THEN  &apos;R&apos;
            WHEN &apos;MON_24&apos; THEN  &apos;R&apos;
            WHEN &apos;MON_25&apos; THEN  &apos;R&apos;
            WHEN &apos;MON_26&apos; THEN  &apos;I&apos;
            WHEN &apos;MON_27&apos; THEN  &apos;D&apos;
            WHEN &apos;MON_35&apos; THEN  &apos;LST&apos;
          END;
--insert into x(sql) values (oper);
 IF codExternMonitor IN (&apos;MON_31&apos;,&apos;MON_32&apos;,&apos;MON_33&apos;) THEN
   IF INSTR(obs,&apos;|A&apos;) &gt; 0 THEN
     OPER := &apos;A&apos;;
   ELSE
     OPER := &apos;S&apos;;
   END IF;
 END IF;
 if IDVer &gt; 0 then
   winmadmin.pkg_userfirme.PostLog(null,aUSERNAME,oper,IDVer,aFIRMANAME,
                                   aSUBUNITATE,sysdate,sDoc,obs,aEXEVERSION);
 else
   winmadmin.pkg_userfirme.PostLog(null,aUSERNAME,oper,null,aFIRMANAME,
                                   aSUBUNITATE,sysdate,sDoc,obs,aEXEVERSION);
 end if;
/*
WINMADMIN.PKG_USERFIRME.PostLog(&apos;IESIRI&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    aCodSubunit, aDataDoc, aDoc);
*/
 commit;
END IF;
end;

function LoWord(Nr in number) return number is
aNr number(20);
begin
  begin
    select Nr - trunc(Nr / power(2,16)) * power(2,16) into aNr from dual;
  exception when others then aNr := 0;
  end;

  return aNr;
end;

function HiWord(Nr in number) return number is
aNr number(20);
begin
  begin
    select trunc(Nr / power(2,16)) into aNr from dual;
  exception when others then aNr := 0;
  end;

  return aNr;
end;

PROCEDURE CLEAR_DIRTY_FLAGS
IS
BEGIN
  UPDATE JURNAL1
    SET DIRTY = 0
  WHERE DIRTY &gt; 0 AND AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
END;


PROCEDURE SET_TIP_REFACERE_JURNAL(TIP IN NUMBER) IS
BEGIN
  TIPJURNAL := TIP;
END;

PROCEDURE MAKE_MANEVRA_DIRTY_DOCS IS
BEGIN
  DELETE TMP_DOC_DIRTY;

  INSERT INTO TMP_DOC_DIRTY
  SELECT DISTINCT CODDOC, TIPDOC
  FROM JURNAL1
	WHERE DIRTY &gt; 0 AND AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);

  COMMIT;-- musai commit
END;

PROCEDURE CLEAR_RULAJE_FOR_JURNAL
IS
BEGIN
  DELETE FROM JURNAL WHERE AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  UPDATE NCONTRUL
  SET
    RULAJCD      = 0,
    RULAJCC      = 0,
    RULAJVCD     = 0,
    RULAJVCC     = 0,
    RULAJC_IFRS  = 0,
    RULAJVC_IFRS = 0,
    RULAJC_GRUP  = 0,
    RULAJVC_GRUP = 0
  WHERE
  AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);
  COMMIT;-- musai commit
END;

FUNCTION IS_DIRTY_DOC(aTIPDOC IN NUMBER, aCODDOC IN NUMBER, aTIPDOC1 IN NUMBER default 0) RETURN NUMBER
IS
NR NUMBER(10) := 0;
BEGIN
  IF TIPJURNAL = 0 THEN RETURN 1;
  ELSE BEGIN
    BEGIN
      SELECT COUNT(*) INTO NR FROM TMP_DOC_DIRTY WHERE CODDOC = aCODDOC AND TIPDOC in (aTIPDOC, aTIPDOC1);
      EXCEPTION WHEN OTHERS THEN NR := 0;
    END;
    IF NR = 0
      THEN RETURN 0;
      ELSE RETURN 1;
    END IF;
  END;
  END IF;
END;

PROCEDURE GET_DOCUMENTE_FOR_JURNAL
IS
BEGIN
  DELETE TMP_INTRARI;
  DELETE TMP_DVI;
  DELETE TMP_DVI1;
  DELETE TMP_INTRARI1;
  DELETE TMP_INTRLINK;
  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;
  DELETE TMP_LIVR;
  DELETE TMP_LIVR1;
  DELETE TMP_LIVRTOT;
  DELETE TMP_IOPARTDOC;
  DELETE TMP_IOPARTVAMA;


  DELETE TMP_JURNAL;
  DELETE TMP_JURNAL1;
  DELETE TMP_RULAJ;

  DELETE TMP_IESIRI;
  DELETE TMP_IESIRI1;
  DELETE TMP_IESLINK;


  DELETE TMP_LIVR1_INITIAL;
  DELETE TMP_STINGERE_INITIAL;
  DELETE TMP_OBLIGPIF_INITIAL;
  DELETE TMP_INTRLINK_INITIAL;

--  GET_INTRARI_FOR_JURNAL;
--  GET_IESIRI_FOR_JURNAL;

--  COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_JURNAL
IS
BEGIN
  DELETE TMP_INTRARI;
  DELETE TMP_INTRARI1;
  DELETE TMP_DVI;
  DELETE TMP_DVI1;
  DELETE TMP_INTRLINK;
  DELETE TMP_INTRASTEPTLINK;
  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;
  DELETE TMP_LIVR;
  DELETE TMP_LIVR1;
  DELETE TMP_LIVRTOT;
  DELETE TMP_MODURIPLATI;
  DELETE TMP_DISCMONETAR;
  DELETE TMP_IESDISC;
  DELETE TMP_IOPARTDOC;
  DELETE TMP_IOPARTVAMA;

 --test
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;

  DELETE TMP_IESIRI;
  DELETE TMP_IESIRI1;
  DELETE TMP_IESLINK;

  DELETE TMP_LIVR1_INITIAL;
  DELETE TMP_STINGERE_INITIAL;
  DELETE TMP_OBLIGPIF_INITIAL;
  DELETE TMP_INTRLINK_INITIAL;
  DELETE TMP_INTRASTEPTLINK_INITIAL;

  --COMMIT;
END;

PROCEDURE EMPTY_DOCUMENTE_FOR_MIFIX
IS
BEGIN
  DELETE TMP_MIFIX;
--  DELETE TMP_JURNAL;
--  DELETE TMP_JURNAL1;
--  DELETE TMP_RULAJ;
  --COMMIT;
END;

PROCEDURE EMPTY_DOCUMENTE_FOR_NOTECREDIT
IS
BEGIN
  DELETE TMP_NOTECREDIT;
  DELETE TMP_NOTECREDITT;
  DELETE TMP_NOTECREDITV;
  DELETE TMP_NOTECREDITC;
  DELETE TMP_NOTECREDITP;
  DELETE TMP_NOTECREDITZ;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_TREZOR
IS
BEGIN
  DELETE TMP_TREZOR;
  DELETE TMP_TREZOR1;
  DELETE TMP_GENERAL;
  DELETE TMP_OBLIGPIF;
  DELETE TMP_STINGERE;

 --DELETE TMP_JURNAL;
 --DELETE TMP_JURNAL1;
 --DELETE TMP_RULAJ;

  DELETE TMP_STINGERE_INITIAL;
  DELETE TMP_OBLIGPIF_INITIAL;

  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_COMPENS
IS
BEGIN
  DELETE TMP_COMPENS;
  DELETE TMP_GENERAL;

  DELETE TMP_OBLIGPIF;
  DELETE TMP_OBLIGPIF_ASOCIAT;
  DELETE TMP_OBLIGPIF_INITIAL;

  DELETE TMP_STINGERE;
  DELETE TMP_STINGERE_ASOCIAT;
  DELETE TMP_STINGERE_INITIAL;

  --DELETE TMP_JURNAL;
 -- DELETE TMP_JURNAL1;
 -- DELETE TMP_RULAJ;
  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_NC
IS
BEGIN
  DELETE TMP_NC;
  DELETE TMP_NC1;
  DELETE TMP_GENERAL;
  DELETE TMP_OBLIGPIF;
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;
  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_REG
IS
BEGIN
  DELETE TMP_REG;
  DELETE TMP_REG1;
  DELETE TMP_REG1CONT;
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;
  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_REGTREZOR
IS
BEGIN
  DELETE TMP_REG;
  DELETE TMP_REGTREZOR1;
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;
  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_REGPERS
IS
BEGIN
  DELETE TMP_REG;
  DELETE TMP_REGPERS1;
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;
  --COMMIT;
END;


PROCEDURE EMPTY_DOCUMENTE_FOR_REGOSS
IS
BEGIN
  DELETE TMP_REGOSS;
  DELETE TMP_REGOSS1;
  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;
  --COMMIT;
END;


FUNCTION GET_INTRARI_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM INTRARI
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPDOC, CODINTR) = 1;

  RETURN NR;
END;

FUNCTION GET_IESIRI_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM IESIRI
  WHERE
    AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS)
    AND COALESCE(INFOCM, 0) = 0
    AND PKG_SERVICE.IS_DIRTY_DOC(TIPDOC, CODIES) = 1;

  RETURN NR;
END;

FUNCTION GET_TREZOR_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM TREZOR
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPDOC, CODTREZOR) = 1;

  RETURN NR;
END;

FUNCTION GET_DIFPretPROD_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM DIFPretPROD
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(80, CODDifPretProd) = 1;

  RETURN NR;
END;

FUNCTION GET_COMPENS_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM COMPENS
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(28, CODCOMPENS) = 1;

  RETURN NR;
END;

FUNCTION GET_NC_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM NC
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(35, CODNC) = 1;

  RETURN NR;
END;

FUNCTION GET_PRODNET_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM PRODNET
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(71, CODPRODNET) = 1;

  RETURN NR;
END;

FUNCTION GET_CONTRACT_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM CONTRACT
  WHERE TIPDOC = 25;

  RETURN NR;
END;

FUNCTION GET_REG_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM REG
  WHERE TIPREG = 46 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN NR;
END;

FUNCTION GET_REGTREZOR_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM REG
  WHERE TIPREG = 45 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN NR;
END;

FUNCTION GET_REGPERS_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM REG
  WHERE TIPREG = 47 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPREG, CODREG) = 1;

  RETURN NR;
END;

FUNCTION GET_REGOSS_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM REGOSS
  WHERE TIPREG = 108 AND AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPREG, CODREGOSS) = 1;

  RETURN NR;
END;

FUNCTION GET_NOTECREDIT_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM NOTECREDIT
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPDOC, CODNCREDIT) = 1;

  RETURN NR;
END;

FUNCTION GET_POSTCALCUL_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM PCALCUL
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(72, CODPC) = 1;

  RETURN NR;
END;

FUNCTION GET_DISTRIBCHELT_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM DISTRIBCHELT
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(76, CODDISTRIBCHELT) = 1;

  RETURN NR;
END;

FUNCTION GET_MIFIX_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM MIFIX1 MF1 INNER JOIN MIFIX  MF  ON MF.CODMIFIX = MF1.CODMIFIX
  WHERE MF1.ANSTART*12+ MF1.LUNASTART = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(36, MF.CODMIFIX) = 1;

  RETURN NR;
END;

FUNCTION GET_INTERNE_RECORDCOUNT RETURN NUMBER IS
  NR NUMBER(20) := 0;
BEGIN
  SELECT COUNT(1) INTO NR
  FROM TRANSF
  WHERE AN*12+LUNA = (SELECT /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU FROM TMP_PKG_GLOBALS) AND PKG_SERVICE.IS_DIRTY_DOC(TIPDOC, CODTRANSF) = 1;

  RETURN NR;
END;

PROCEDURE GET_MIFIX_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
NR NUMBER(20, 0) := 0;
BEGIN
  EMPTY_DOCUMENTE_FOR_MIFIX;
  INSERT INTO  TMP_MIFIX
    (CODMIFIX,
     TIP,
     NRINVENTAR,
     ANINTRARE,
     LUNAINTRARE,
     CODMIFIX1,
     CODNIRSTOC,
     PRET,
     CANT,
     CODCLASIF,
     TIPAMO,
     STARE,
     DURATAN,
     GRADU,
     DURATAF,
     AMO,
     NEUTIL,
     DFBLOCAT,
     CODPERS,
     ANSTART,
     LUNASTART,
     CODIOART,
     CODGEST,
     TIPREEVAL,
     DATAREEVAL,
     INCLUDRATA,
     AMOVECHI,
     PRETVECHI,
     NEUTILVECHI,
     SUBUNITATEA,
     CodAnalizaNod,
     CodCentru,
     TipStorno,
     DENUMIRE,
     DURATANF,
     DURATAFF,
     AMOF,
     DURATANG,
     DURATAFG,
     AMOG,
     ANINTRAREG,
     LUNAINTRAREG,
     DFBlocat_F,
     DFBlocat_G,
     REZERVA,
     AMOREZERVA,
     AMORBLOCAT,
     PRETINITIAL
     )
   SELECT
   CODMIFIX, TIP, NRINVENTAR, ANINTRARE, LUNAINTRARE, CODMIFIX1, CODNIRSTOC, PRET, CANT, CODCLASIF, TIPAMO, STARE,
   DURATAN,
           GRADU, DURATAF, AMO, NEUTIL, DFBLOCAT, CODPERS,  ANSTART,  LUNASTART, CODIOART, GEST,
            TIPREEVAL, DATAREEVAL, INCLUDRATA, AMOVECHI, PRETVECHI, NEUTILVECHI, CODSUBUNIT, CodAnalizaNod, 
            CodCentru, 
            TipStorno, 
            DENUMIRE,
            DURATANF,
            DURATAFF,
            AMOF,
            DURATANG,
            DURATAFG,
            AMOG,
            ANINTRAREG,
            LUNAINTRAREG,
            DFBlocat_F,
            DFBlocat_G,
            REZERVA,
            AMOREZERVA,
            AMORBLOCAT,
            PRETINITIAL
    FROM
  (
   SELECT
     ROWNUM AS RN,
     MF_LUNA.CODMIFIX,
     MF_LUNA.TIP,
     MF_LUNA.NRINVENTAR,
     MF_LUNA.ANINTRARE,
     MF_LUNA.LUNAINTRARE,
     MF_LUNA.CODMIFIX1,
     MF_LUNA.CODNIRSTOC,
     MF_LUNA.PRET,
     MF_LUNA.CANT,
     MF_LUNA.CODCLASIF,
     MF_LUNA.TIPAMO,
     MF_LUNA.STARE,
     MF_LUNA.DURATAN,
     MF_LUNA.GRADU,
     MF_LUNA.DURATAF,
     MF_LUNA.AMO,
     MF_LUNA.NEUTIL,
     MF_LUNA.DFBLOCAT,
     MF_LUNA.CODPERS,
     MF_LUNA.ANSTART,
     MF_LUNA.LUNASTART,
     MF_LUNA.CODIOART,
     MF_LUNA.GEST,
     MF_LUNA.TIPREEVAL,
     MF_LUNA.DATAREEVAL,
     MF_LUNA.INCLUDRATA,
     MF_LUNA.AMOVECHI,
     MF_LUNA.PRETVECHI,
     MF_LUNA.NEUTILVECHI,
     MF_LUNA.CODSUBUNIT,
     MF_LUNA.CodAnalizaNod,
     MF_LUNA.CodCentru,
     MF_LUNA.TipStorno,
     MF_LUNA.DENUMIRE,
     MF_LUNA.DURATANF,
     MF_LUNA.DURATAFF,
     MF_LUNA.AMOF,
     MF_LUNA.DURATANG,
     MF_LUNA.DURATAFG,
     MF_LUNA.AMOG,
     MF_LUNA.ANINTRAREG,
     MF_LUNA.LUNAINTRAREG,
     MF_LUNA.DFBlocat_F,
     MF_LUNA.DFBlocat_G,
     MF_LUNA.REZERVA,
     MF_LUNA.AMOREZERVA,
     MF_LUNA.AMORBLOCAT,
     MF_LUNA.PRETINITIAL
    FROM
     (SELECT DISTINCT
        MF.CODMIFIX,
        MF.TIP,
        NRINVENTAR,
        ANINTRARE,
        LUNAINTRARE,
        CODMIFIX1,
        MF1.CODNIRSTOC,
        MF1.PRET,
        CANT,
        CODCLASIF,
        TIPAMO,
        STARE,
        DURATAN,
        GRADU,
        DURATAF,
        AMO,
        NEUTIL,
        DFBLOCAT,
        CODPERS,
        ANSTART,
        LUNASTART,
        NS.CODIOART,
        N.GEST,
         TIPREEVAL,
         DATAREEVAL,
         INCLUDRATA,
         AMOVECHI,
         PRETVECHI,
         NEUTILVECHI,
         G.CODSUBUNIT,
         mf1.CodAnalizaNod,
         mf1.CodCentru,
         mf1.TipStorno,
         O.DENUMIRE,
         DURATANF,
         DURATAFF,
         AMOF,
         DURATANG,
         DURATAFG,
         AMOG,
         ANINTRAREG,
         LUNAINTRAREG,
         DFBlocat_F,
         DFBlocat_G,
         REZERVA,
         AMOREZERVA,
         AMORBLOCAT,
         PRETINITIAL
      FROM
        MIFIX MF,
        MIFIX1 MF1
        LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = MF1.CODNIRSTOC
        LEFT OUTER JOIN NIR     N  ON N.CODNIR      = NS.CODNIR
        LEFT OUTER JOIN NGEST   G  ON G.CODGEST     = N.GEST,
        NARTOBJ O
      WHERE
        MF.CODMIFIX = MF1.CODMIFIX AND
        MF1.ANSTART * 12 + MF1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
        AND O.CODOBIECT = NS.CODOBIECT
        AND IS_DIRTY_DOC(36, MF.CODMIFIX) = 1
      ORDER BY CODMIFIX
     ) MF_LUNA
    ) WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;

END;

PROCEDURE GET_NC_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
BEGIN
  EMPTY_DOCUMENTE_FOR_NC;
-- NC --
  INSERT INTO  TMP_NC ( CodNC,Part, JurnalTVA, TipTranz, TipTVA, Valoare, Moneda, Curs, Obs,  NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON )
  SELECT CodNC, Part, JurnalTVA, TipTranz, TipTVA, Valoare, Moneda, Curs, Obs,  NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON
  FROM
  (
  SELECT
   ROWNUM AS RN,
    NC_LUNA.CodNC,
    NC_LUNA.Part,
    NC_LUNA.JurnalTVA,
    NC_LUNA.TipTranz,
    NC_LUNA.TipTVA,
    NC_LUNA.Valoare,
    NC_LUNA.Moneda,
    NC_LUNA.Curs,
    NC_LUNA.Obs,
    NC_LUNA.NrDoc,
    NC_LUNA.DataDoc,
    NC_LUNA.AN,
    NC_LUNA.LUNA,
    NC_LUNA.SUBUNITATEA,
    NC_LUNA.SABLON
  FROM
  ( SELECT ROWNUM RN, CodNC, Part, JurnalTVA, TipTranz, TipTVA, Valoare, Moneda, Curs, Obs,  NrDoc, DataDoc, AN, LUNA, SUBUNITATEA, SABLON
    FROM
      NC
    WHERE
     AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
     AND(IS_DIRTY_DOC(35, NC.CODNC) = 1)
    ORDER BY CODNC
   ) NC_LUNA
   ) WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;


-- Detail NC1
  INSERT INTO  TMP_NC1 ( IndexLocal, PartD, PartC, PersD, PersC, CodNC1, CodNC, ContD, ContC, ICONTD, ICONTC, Valoare, Obs, Agent, CodCentru,CodGest, CodAnalizaNod, CODPART)
    SELECT * FROM
    ( SELECT IndexLocal, PartD, PartC, PersD, PersC, CodNC1, CodNC, ContD, ContC, ICONTD, ICONTC, Valoare,Obs, Agent, CodCentru,CodGest, CodAnalizaNod, CODPART
     FROM NC1
     WHERE EXISTS (SELECT CODNC FROM TMP_NC WHERE CODNC = NC1.CODNC)
     )
     ORDER BY INDEXLOCAL  ;

END;

PROCEDURE GET_DifPretProd_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
BEGIN
  DELETE TMP_DIFPretPROD;
  DELETE TMP_DIFPretPROD1;

  INSERT INTO  TMP_DIFPretPROD(CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest)
  SELECT  CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest
   FROM
   (
    SELECT ROWNUM RN, S.* FROM
    ( SELECT CodDIFPretPROD, An, Luna, Obs, Operat, Subunitatea, CodGest
      FROM
       DIFPretPROD PN
     WHERE
       AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) AND(IS_DIRTY_DOC(80, PN.CODDIFPretPROD) = 1)
       ORDER BY CodDIFPretPROD
    ) S
   )
    WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;

  insert into tmp_DIFPRETPROD1(  CODDIFPRETPROD1, CODDIFPRETPROD, CodCOMANDA1, CODNIRSTOC, DifPret, CODCENTRU, CODANALIZANOD, DIRTY,
     Curent, AnLuna, INTRARI, IESIRI,
     XDIFPRET,   XCODCENTRU, XCODANALIZANOD, XCurent, XINTRARI, XIESIRI,
     PRET, PretReal, NRDOC, DATADOC, CodGest, Codioart, CodObiect, DENUMIRE)
  (
   select DP1.codDIFPRETPROD1,DP1.codDIFPRETPROD,DP1.CodCOMANDA1,DP1.CODNIRSTOC, DP1.DifPret,DP1.CODCENTRU, DP1.CODANALIZANOD,DP1.DIRTY,
          DP1.Curent, DP1.AnLuna, DP1.INTRARI, DP1.IESIRI,
          DP0.DIFPRET,   DP0.CODCENTRU, DP0.CODANALIZANOD, DP0.Curent, DP0.INTRARI, DP0.IESIRI,
          NS.Pret,
          Nvl(obj1.ValMat,0) + (2-Nvl(obj1.TipPret,1))*(Nvl(obj1.ValMan,0) + Nvl(obj1.ValRegie,0)),
          c.nrdoc, c.datadoc, C.CodGest, Ns.Codioart, c1.CodObiect, obj.denumire
   from DIFPRETPROD1 DP1
        inner join comanda1 c1 on DP1.CodCOMANDA1   = c1.codcomanda1
        inner join comanda   c on c1.codcomanda = c.codcomanda
        inner join nartobj obj on obj.codobiect = c1.codobiect
        inner join Tmp_Nartobj_Luna obj1 on obj1.codobiect = c1.codobiect
        inner join NirStoc Ns   on  DP1.codNirStoc = Ns.codNirStoc
        left join DIFPRETPROD1 DP0 on DP0.CodCOMANDA1=DP1.codcomanda1 and DP0.CodNirStoc=DP1.CodNirStoc and DP0.AnLuna=DP1.AnLuna-1
   where EXISTS (SELECT CODDIFPretPROD FROM TMP_DIFPretPROD WHERE CODDIFPretPROD = DP1.CODDIFPretPROD));
END;

PROCEDURE GET_PRODNET_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
BEGIN
  DELETE TMP_PRODNET;
  DELETE TMP_PRODNET1;

  INSERT INTO  TMP_prodnet(Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest)
   SELECT  Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest
   FROM
   (
    SELECT ROWNUM AS RN, S.*
    FROM
    ( SELECT Codprodnet, An, Luna, Obs, Tip, Subunitatea, CodGest
      FROM
       prodnet PN
     WHERE
       AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) AND(IS_DIRTY_DOC(71, PN.CODPRODNET) = 1)
     ORDER BY Codprodnet
      )S
   )
    WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;

  for v_rec in (select CodProdNet from TMP_ProdNet) loop
     PKG_PRODNET.REFACEREDIRTY(v_rec.codprodnet, 0); -- fara commit;
  end loop;

  insert into tmp_prodnet1(codprodnet1,codprodnet,coddoc1,explicatii,valmat,valman,codcentru,denumire, nrdoc, datadoc)
  (select pn1.codprodnet1,pn1.codprodnet,pn1.coddoc1,pn1.explicatii,pn1.valmat,pn1.valman,pn1.codcentru,
          obj.denumire, c.nrdoc, c.datadoc
   from prodnet1 pn1
        left join comanda1 c1 on pn1.coddoc1   = c1.codcomanda1
        left join comanda   c on c1.codcomanda = c.codcomanda
        left join nartobj obj on obj.codobiect = c1.codobiect
   where
   EXISTS (SELECT CODPRODNET FROM TMP_PRODNET WHERE CODPRODNET = PN1.CODPRODNET)
  );


END;


PROCEDURE GET_DISTRIBCHELT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
ANLUNA_START number(10);
NR           number(20);
BEGIN
  DELETE TMP_DISTRIBCHELT;
  DELETE TMP_DISTRIBCHELT1;
  DELETE TMP_DISTRIBCHELT2;

  INSERT INTO TMP_DISTRIBCHELT (CODDISTRIBCHELT,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,BLOCAT,OPERAT)
  SELECT CODDISTRIBCHELT,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,BLOCAT,OPERAT
  FROM
  (
     SELECT  ROWNUM AS RN, S.* FROM
    ( SELECT
       CODDISTRIBCHELT,TIPDOC,OBS,AN,LUNA,SUBUNITATEA,USERID,DATACREARE,BLOCAT,OPERAT
       FROM
         DISTRIBCHELT DC
       WHERE
         AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) AND(IS_DIRTY_DOC(76, DC.CODDISTRIBCHELT) = 1)

       ORDER BY CODDISTRIBCHELT
     ) S
  )
   WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;



  INSERT INTO TMP_DISTRIBCHELT1 (CodDISTRIBCHELT1, CodDISTRIBCHELT, INDEXLOCAL, CODNEST, VAL, CODD, CODC, CODCC, CODGEST, DENGEST, CENTRU, DEBIT, CREDIT, BUTON)
  SELECT
    PCF.CodDISTRIBCHELT1,
    PCF.CodDISTRIBCHELT,
    PCF.INDEXLOCAL,
    PCF.CODNEST,
    PCF.VAL,
    NS.CODCONTD,
    NS.CODCONTC,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20),
    &apos;   c&apos;
  FROM DISTRIBCHELT1 PCF
       LEFT JOIN NESTJURNAL NS ON PCF.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCF.CodDISTRIBCHELT IN (SELECT CODDISTRIBCHELT FROM TMP_DISTRIBCHELT);

  INSERT INTO TMP_DISTRIBCHELT2
   (CodDISTRIBCHELT2,
    CodDISTRIBCHELT1,
    CodDISTRIBCHELT,
    INDEXLOCAL,CODGEST,CODCENTRU,OBS,PROCENT,DENGEST,CENTRU)
  SELECT
    PCF.CodDISTRIBCHELT2,
    PCF.CodDISTRIBCHELT1,
    PCF.CodDISTRIBCHELT,
    PCF.INDEXLOCAL,PCF.CODGEST,PCF.CODCENTRU,PCF.OBS,PCF.PROCENT,
    Substr(G.DEN_GEST,1,30),  CC.Simbol
  FROM DISTRIBCHELT2 PCF
       LEFT JOIN NGEST G ON G.CODGEST = PCF.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = PCF.CODCENTRU
  WHERE PCF.CodDISTRIBCHELT IN (SELECT CODDISTRIBCHELT FROM TMP_DISTRIBCHELT);

  for v_rec in (select CodDISTRIBCHELT1 from Tmp_DISTRIBCHELT1) loop
     Select Count(*) into Nr from TMP_DISTRIBCHELT2 where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1;
     if Nvl(Nr,0) &gt; 0 then Update Tmp_DISTRIBCHELT1 set Buton = &apos;u&apos; where CodDISTRIBCHELT1 = v_rec.CodDISTRIBCHELT1; end if;
  end loop;
END;

PROCEDURE GET_CONTRACT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
BEGIN
   DELETE TMP_CONTRACT;
   DELETE TMP_CONTRACT0;
   DELETE TMP_CONTRACT1;
-- CONTRACT --

  INSERT INTO  TMP_CONTRACT(CODCONTRACT, NRDOC, DATADOC,Partener,Subunitatea,Anulat,Operat)
  SELECT CODCONTRACT, NRDOC, DATADOC,Partener,Subunitatea,Anulat,Operat
  FROM (
    SELECT ROWNUM RN, S.*
    FROM (
      SELECT  C.*
      FROM CONTRACT C
      WHERE TIPDOC = 25 AND IS_DIRTY_DOC(25, C.CODCONTRACT) = 1
      ORDER BY CODCONTRACT
    ) S
  )
  WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;

-- Detail CONTRACT0

  INSERT INTO TMP_CONTRACT0
  SELECT * FROM CONTRACT0 C0
  WHERE
   EXISTS (SELECT CODCONTRACT FROM TMP_CONTRACT WHERE CODCONTRACT = C0.CODCONTRACT)
   AND C0.TIPLINIE = 2
   AND EXTRACT(YEAR FROM DATA) * 12 + EXTRACT(MONTH FROM DATA) =
   (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X);

  INSERT INTO TMP_CONTRACT1(CODCONTRACT, GestAct, Codcentru)
  SELECT CODCONTRACT, GestAct, Codcentru FROM CONTRACT1
  WHERE CODCONTRACT IN (SELECT CODCONTRACT FROM TMP_CONTRACT);
END;


PROCEDURE GET_NOTECREDIT_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
BEGIN
  EMPTY_DOCUMENTE_FOR_NOTECREDIT;

  INSERT INTO TMP_NOTECREDIT (CodNCredit,
                              CodContract2,
                              CodPart,
                              TipDoc,
                              Subunitatea,
                              DataStart,
                              DataStop,
                              CODCONTV, CODCONTT, CODCONTC, CODCONTP,
                              DataStartD,
                              DataStopD,
                              DataFact,
                              Contract, An, Luna,
                              TipARticol,
                              Obs,
                              CodContract,
                              CodMoneda,
                              VolumPeArticole,
                              CODCONTZ,
                              PretBrutC,
                              PretBrutV,
                              CodCarnet,
                              TipDiscV,
                              Trimestriala,
                              Corectie,
                              COdNCCorectie,
                              PrefixDoc,
                              CarnetDoc,
                              NrDoc,
                              SeriaDoc,
                              AreCarnetDoc,
                              Previzionare,
                              IesiriPeVolum,
                              Curs,
                              Inchisa
                              )
                    SELECT   CodNCredit,
                              CodContract2,
                              CodPart,
                              TipDoc,
                              Subunitatea,
                              DataStart,
                              DataStop,
                              CODCONTV, CODCONTT, CODCONTC, CODCONTP,
                              DataStartD,
                              DataStopD,
                              DataFact,
                              Contract, An, Luna,
                              TipARticol,
                              Obs,
                              CodContract,
                              CodMoneda,
                              VolumPeArticole,
                              CODCONTZ,
                              PretBrutC,
                              PretBrutV,
                              CodCarnet,
                              TipDiscV,
                              Trimestriala,
                              Corectie,
                              COdNCCorectie,
                              PrefixDoc,
                              CarnetDoc,
                              NrDoc,
                              SeriaDoc,
                              AreCarnetDoc,
                              Previzionare,
                              IesiriPeVolum,
                              Curs,
                              Inchisa
                    FROM
                    (
                    SELECT ROWNUM RN, S.* FROM
                    (
                       SELECT NC.CodNCredit,
                              NC.CodContract2,
                              NC.CodPart,
                              NC.TipDoc,
                              NC.Subunitatea,
                              NC.Datastart,
                              NC.DataStop,
                              nc.CODCONTV, nc.CODCONTT, nc.CODCONTC, nc.CODCONTP,
                              NC.DataStart DataStartD,
                              NC.DataStop DATASTOPD,
                              SysDate DATAFACT,
                              case
                                when NVL(NC.CodContract2, nvl(NC.CodContract,0)) = 0 then &apos;...fara...&apos;
                                else case when nvl(NC.CodContract,0) = 0 then C.Nrdoc||&apos;/&apos;||to_char(C.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(C.DataStop, &apos;DD.MM.YYYY&apos;)
                                          else CNC.Nrdoc||&apos;/&apos;||to_char(CNC.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(CNC.DataStop, &apos;DD.MM.YYYY&apos;)
                                     end
                              end CONTRACT,
                              NC.An,
                              NC.Luna,
                              NC.TipArticol,
                              NC.Obs,
                              case when nvl(nc.codcontract2, 0) = 0 then NC.CodContract else C.Codcontract end CODCONTRACT,
                              nvl(NC.CodMoneda, C.Moneda) CODMONEDA,
                              nvl(NC.VOLUMPEARTICOLE,0) VOLUMPEARTICOLE,
                              nc.CODCONTZ,
                              nvl(nc.pretbrutc,0) PRETBRUTC,
                              nvl(nc.pretbrutv,0) PRETBRUTV,
                              nc.codcarnet,
                              case
                                when decode(NVL(NC.CodContract2,0),0,nvl(NC.CodContract,0),NC.CodContract2) = 0 then
                                  case
                                    when nvl(NC.Volumpearticole,0) = 0 then 3
                                    else 4
                                  end
                                else
                                  case when nvl(NC.CodContract,0) = 0 then
                                    NVL(C.TIPTARGETV,0)
                                  else NVL(CNC.TIPTARGETV,0)
                                  end
                              end  TipDiscV,
                              nvl(NC.Trimestriala,0) TRIMESTRIALA,
                              NC.Corectie,
                              NC.CodNCCorectie,
                              NC.PrefixDoc,
                              NC.CarnetDoc,
                              NC.NrDoc,
                              NC.SeriaDoc,
                              Decode(Nvl(NC.CARNETDOC,0),0,0,1) ARECARNETDOC,
                              NC.Previzionare,
                              NC.IesiriPeVolum,
                              NC.Curs,
                              NC.Inchisa

                       FROM NOTECREDIT NC
                            LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
                            LEFT JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
                            LEFT JOIN CONTRACT CNC ON CNC.Codcontract = nc.codcontract
                       WHERE
                          NC.AN*12+NC.LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
                          AND
                        (IS_DIRTY_DOC(NC.TIPDOC, NC.CODNCREDIT) = 1)
                       ORDER BY  NC.CodNCredit
                    ) S
                   )
                    WHERE
                     RN &gt;= STARTREC AND RN &lt;= ENDREC;

  INSERT INTO TMP_NOTECREDITT (CODNCREDIT1, CODNCREDIT,VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU)
  SELECT CODNCREDIT1, CODNCREDIT,VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU FROM NOTECREDIT1
  WHERE
   CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
   AND TIP = tncTermen;

  INSERT INTO TMP_NOTECREDITV (CODNCREDIT1, CODNCREDIT,VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU)
  SELECT CODNCREDIT1, CODNCREDIT, VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU FROM NOTECREDIT1
  WHERE
   CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
   AND TIP = tncVolum;

  INSERT INTO TMP_NOTECREDITC (CODNCREDIT1, CODNCREDIT,VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU)
  SELECT CODNCREDIT1, CODNCREDIT, VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU FROM NOTECREDIT1
  WHERE
   CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
   AND TIP = tncCantitate;

  INSERT INTO TMP_NOTECREDITP (CODNCREDIT1, CODNCREDIT,VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU)
  SELECT CODNCREDIT1, CODNCREDIT, VALOARE,VALOAREOLD, CODANALIZANOD, CODCENTRU FROM NOTECREDIT1
  WHERE
   CODNCREDIT IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT)
   AND TIP = tncPenalizari;

   INSERT INTO TMP_NOTECREDITZ (CodNCredit1,
                                CodNCredit,
                                Valoare,
                                CodObligStins,
                                CodDoc,
                                TipDoc,
                                CodObligStingator,
                                Obs,
                                ValDif,
                                Valoareold,
                                DOC,
                                NRDOC,
                                DATADOC,
                                MONEDA,
                                SEDIU,
                                CURS,
                                VALDOC,
                                VALLEI,
                                DISCOUNT,
                                DENCRITERIU,
                                 --CREDITAT,
                                DEN_CLASEDISC,
                                CODCLASEDISC,
                                CODNCREDIT1ORIG,
                                CODDISCOUNT,
                                PROCTVA,
                                CODANALIZANOD,
                                CODCENTRU
                                )
                          SELECT NC1.CodNCredit1,
                                 NC1.CodNCredit,
                                 NC1.Valoare,
                                 I.CodIes,
                                 NC1.CodDoc,
                                 NC1.TipDoc,
                                 NC1.CodObligStingator,
                                 NC1.Obs,
                                 NC1.ValDif,
                                 NC1.Valoareold,
                                 I.PREFIXDOC Doc,
                                 I.NRDOC NrDoc,
                                 I.DATADOC DataDoc,
                                 PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) MONEDA,
                                 A.OBS Sediu,
                                 DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)) CURS,
                                 I.ValDoc - I.TVADOC,
                                 ROUND((I.ValDoc - I.TVADOC) * DECODE(NVL(GREG.CURS, G.CURS), 0, 1, NVL(GREG.CURS, G.CURS)), 4) ValLei,
                                 0,
                                 CD.DENCRITERIU,
                                 --nvl(ALTE.CREDITAT,0),
                                 CLSDISC.DEN_CLASEDISC,
                                 CLSDISC.CODCLASEDISC,
                                 NC1.CODNCREDIT1ORIG,
                                 NC1.CODDISCOUNT,
                                 nvl(nc1.proctva,24),
                                CODANALIZANOD,
                                CODCENTRU
                          FROM NOTECREDIT1 NC1
                               INNER JOIN NOTECREDIT NC ON NC.CODNCREDIT = NC1.CODNCREDIT
                               LEFT JOIN IESDISC ID ON NC1.CODDOC = ID.CODIESDISC
                               LEFT JOIN DISCOUNT D ON NVL(ID.CODDISCOUNT,NC1.CODDISCOUNT) = D.CODDISCOUNT
                               LEFT JOIN CRITERIIDISC CD ON CD.CODCRITERIU = D.CODCRITERIU
                               LEFT JOIN IESIRI I ON I.CODIES = ID.CodIes AND NC1.TipDoc = I.TipDoc
                               LEFT  JOIN NCLASEDISC CLSDISC ON CLSDISC.CODCLASEDISC = CD.CLASA
                               LEFT OUTER JOIN GENERAL G ON I.CODIES = G.CODDOC AND I.TipDoc = G.TipDoc
                               LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                               LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE
                          WHERE NC1.CodNCredit IN (SELECT CODNCREDIT FROM TMP_NOTECREDIT) AND NC1.Tip = tncProvizioane
                                AND nvl(g.semnificatie,0) &lt;&gt; 240 and nvl(g.semnificatie,0) &lt;&gt; 500
                                and nvl(g.semnificatie,0) &lt;&gt; 211 and nvl(g.semnificatie,0) &lt;&gt; 210;

  --update tmp_notecreditz set discount = valoare where nvl(coddoc,0) = 0;


      for v_rec in (with IProc as (
                    select distinct I1.CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz ncz
                         INNER JOIN TMP_NOTECREDIT N ON N.CODNCREDIT = NCZ.CODNCREDIT AND N.TIPDOC = 58
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join iesiri i on id.codies = i.codies
                         inner join iesiri1 I1 on i.codies = i1.codies
                         INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                         INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol
                         INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva
                    where I.AN*12+I.LUNA BETWEEN ART1.ALSTART AND ART1.ALSTOP
                      and I.AN*12+I.LUNA BETWEEN TVA1.ALSTART AND TVA1.ALSTOP
                    ),
                    IProcVal as (
                                  select IProc.ProcTVA, I.CodIes,
                                         sum(i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) -
                                             case
                                               when not i.tipdoc in (16,21) then 0
                                               else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                             end) BazaTVA
                                  FROM (select distinct id.codies
                                        from tmp_notecreditz ncz
                                             inner join iesdisc id on id.codiesdisc = NCZ.CODDOC) ii
                                        inner join iesiri i on ii.codies = i.codies
                                        inner join iesiri1 I1 on i.codies = i1.codies
                                        INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                  group by IProc.ProcTVA, I.CodIes
                                 )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA
                    where id.offinvoice = 2 and ncz.coddoc &gt; 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;


      for v_rec in (with IProc as (
                    select distinct I1.CodIes1, PKG_LIST_BASE_UTILS.CALC_MATCH_TVA(I.TIPDOC, I.AN, I.LUNA, I1.CANT, I1.PU, I1.TVA, I1.CODOBIECT, TVA1.PROCENT, I.ROTEFACT, 1) ProcTVA
                    FROM tmp_notecreditz ncz
                         INNER JOIN TMP_NOTECREDIT N ON N.CODNCREDIT = NCZ.CODNCREDIT AND N.TIPDOC &lt;&gt; 58
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join iesiri i on id.codies = i.codies
                         inner join iesiri1 I1 on i.codies = i1.codies
                         INNER JOIN nartobj obj ON i1.codobiect = obj.codobiect
                         INNER JOIN nart1 art1 ON art1.codarticol = obj.codarticol
                         INNER JOIN ntva1 tva1 ON tva1.codtva = art1.codtva
                    where I.AN*12+I.LUNA BETWEEN ART1.ALSTART AND ART1.ALSTOP
                      and I.AN*12+I.LUNA BETWEEN TVA1.ALSTART AND TVA1.ALSTOP
                    ),
                    IProcVal as (
                                  select IProc.ProcTVA, I.CodIes,
                                         sum(i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1) -
                                             case
                                               when not i.tipdoc in (16,21) then 0
                                               else i1.PretOrig*i1.cant*nvl(i1.coefdiscmaj,1)*pkg_list_base_utils.get_cota_tva_art(i1.codobiect, i.an, i.luna)/100
                                             end) BazaTVA
                                  FROM tmp_notecreditz ncz
                                       inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                                       inner join iesiri i on id.codies = i.codies
                                       inner join iesiri1 I1 on i.codies = i1.codies
                                       INNER JOIN IProc ON i1.codies1 = IProc.codies1
                                  group by IProc.ProcTVA, I.CodIes
                                 )
                    select ncz.codncredit1, id.procent*IProcVal.BazaTVA/100 valdisc
                    from tmp_notecreditz ncz
                         inner join iesdisc id on id.codiesdisc = NCZ.CODDOC
                         inner join IProcVal on IProcVal.CodIes = id.COdIes and ncz.proctva = IProcVal.ProcTVA
                    where id.offinvoice = 3) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and coddoc &gt; 0;
      end loop;
      for v_rec in (select ncz.codncredit1, n1.valoare valdisc, n1.proctva
                    from tmp_notecreditz ncz
                         inner join notecredit1 n1 on n1.codncredit1 = ncz.codncredit1orig
                    where nvl(ncz.coddoc,0) = 0
                   ) loop
        update tmp_notecreditz set discount = v_Rec.valdisc where codncredit1 = v_rec.codncredit1 and nvl(coddoc,0) = 0 and proctva = v_rec.proctva;
      end loop;

    update tmp_notecreditz set discount = valoare where nvl(coddoc,0) = 0 and nvl(codncredit1orig,0) = 0;



    update tmp_notecredit n set
      TOTALT     = (select Round(sum(valdoc),2) from tmp_notecreditt WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALLEIT  = (select Round(sum(vallei),2) from tmp_notecreditt WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALV     = (select Round(sum(valdoc),2) from tmp_notecreditv WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALLEIV  = (select Round(sum(vallei),2) from tmp_notecreditv WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALC     = (select Round(sum(val),2) from tmp_notecreditc WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALLEIC  = (select Round(sum(vallei),2) from tmp_notecreditc WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALP     = (select Round(sum(valdoc),2) from tmp_notecreditp WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALLEIP  = (select Round(sum(vallei),2) from tmp_notecreditp WHERE CODNCREDIT= N.CODNCREDIT),
      TOTALZ     = (select Round(SUM(valdoc),2) from tmp_notecreditz where codobligstins &gt; 0 AND CODNCREDIT= N.CODNCREDIT),
      TOTALLEIZ  = (select Round(sum(vallei),2) from tmp_notecreditz where codobligstins &gt; 0 AND CODNCREDIT= N.CODNCREDIT),
   --   TOTALZ     = (select Round(sum(valdoc),2) from (select distinct codobligstins, valdoc from tmp_notecreditz where codobligstins &gt; 0 AND CODNCREDIT= N.CODNCREDIT)),
   --   TOTALLEIZ  = (select Round(sum(vallei),2) from (select distinct codobligstins, vallei from tmp_notecreditz where codobligstins &gt; 0 AND CODNCREDIT= N.CODNCREDIT)),
      TOTALDISCZ = (select Round(sum(valoare - nvl(valoareold,0)),2) from tmp_notecreditz WHERE CODNCREDIT= N.CODNCREDIT);

    update tmp_notecredit set
      TOTALZ     = TOTALZ + (select nvl(Round(sum(valdoc),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0),
      TOTALLEIZ  = TOTALLEIZ + (select nvl(Round(sum(vallei),2),0) from tmp_notecreditz where nvl(codobligstins,0) = 0);


END;


PROCEDURE GET_POSTCALCUL_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
TipValMatPC number;
BEGIN
  DELETE TMP_PCALCUL;
  DELETE TMP_PCGEST;
  DELETE TMP_PCART;
  DELETE TMP_PCSECTII;
  DELETE TMP_PCSECTII2;
  DELETE TMP_PCSECTII3;
  DELETE TMP_PCSECTII5;

  INSERT INTO TMP_PCALCUL (CODPC, AN, LUNA, SUBUNITATEA, CUMULAT, operat, VARIANTA, DATADOC, TIPPUNCT, OBSERVATII, TipAloc,ValF)
  SELECT
    CODPC,
    AN,
    LUNA,
    SUBUNITATEA,
    CUMULAT,
    operat,
    VARIANTA,
    DATADOC,
    TIPPUNCT,
    OBSERVATII,
    TipAloc,
    ValF
  FROM
  (
    SELECT ROWNUM AS RN, S.* FROM
    (
    SELECT
      CODPC,
      AN,
      LUNA,
      SUBUNITATEA,
      CUMULAT,
      operat,
      VARIANTA,
      DATADOC,
      TIPPUNCT,
      OBSERVATII,
      NVL(TipAloc, 0) AS TIPALOC,
      ValF
    FROM
      PCALCUL
    WHERE
      AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
      AND
      (IS_DIRTY_DOC(72, CODPC) = 1)
    ORDER BY CODPC
    ) S
 )
  WHERE
    RN &gt;= STARTREC AND RN &lt;= ENDREC;


  INSERT INTO TMP_PCGEST (CODPCGEST, CODPC, CODGEST, MANS, PUNCTE, VALi, VALA, ValG, ValC, VALMAT, VALMAN, ValPUNCT, COEFMAN, DENGEST, ValD, ValS, TOTAL)
  SELECT
    PCG.CODPCGEST,
    PCG.CODPC,
    PCG.CODGEST,
    PCG.ManS,
    PCG.Puncte,
    PCG.VALi, PCG.VALa, PCG.ValG, PCG.ValC, PCG.VALMAT, PCG.VALMAN,
    case Nvl(PCG.Puncte,0) when 0 then 0 else Nvl((Nvl(PCG.VALi,0)+ Nvl(PCG.VALA,0)+ Nvl(PCG.ValG,0)+ Nvl(PCG.ValC,0)),0)/PCG.Puncte end,
    case Nvl(PCG.MANS,0) when 0 then 0 else Nvl(PCG.VALMAN,0)/Nvl(PCG.MANS, 0) end,
    Case PCG.CODGEST when 0 then &apos;.TOTAL&apos; else Substr(G.DEN_GEST,1,30) end,
    PCG.VALMAT + PCG.VALMAN,
    PCG.VALi+ PCG.VALA+ PCG.ValG+ PCG.ValC,
    PCG.VALMAT + PCG.VALMAN+ PCG.VALi+ PCG.VALA+ PCG.ValG+ PCG.ValC
  FROM
    PCGEST PCG
    LEFT JOIN NGEST G ON G.CODGEST = PCG.CODGEST
  WHERE PCG.CODPC IN (SELECT CODPC FROM TMP_PCALCUL);

  TipValMatPC := pkg_categconst.GetValConstanta(&apos;TipValMatPC&apos;,PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
  INSERT INTO TMP_PCART
   (
    CODPCART ,
    CODPC    ,
    CODCMD1  ,
    CODIOART ,
    CANT     ,
    VAL      ,
    VALS     ,
    VALi    ,
    VALa    ,
    ValG, ValC     ,
    MAT     ,
    CODGEST  ,
    CODFORMATIE,
    COEF,
    MAN,
    VALMAN,
    CODCC    ,
    REST     ,
    ANLUNA   ,
    PUCALC   ,
    PretMat  ,
    CODOBIECT,
    PUNCTE  ,
    CENTRU   ,
    DENOBIECT,
    DENIOART ,
    DENUM,
    PRETREFERINTA,
    PRETRETETA
    )
  SELECT
    PCA.CODPCART,
    PCA.CODPC,
    PCA.CODCMD1,
    PCA.CODIOART,
    Nvl(PCA.CANT, 0),
    PCA.VAL,
    PCA.VALS,
    PCA.VALi,
    PCA.VALa,
    PCA.ValG, ValC,
    PCA.MAT,
    PCA.CODGEST,
    PCA.CODFORMATIE,
    PCA.COEF,
    PCA.MAN,
    PCA.VALMAN,
    PCA.CODCC,
    MAT.REST,
   (PCC.AN * 12 + PCC.LUNA) - (C.AN * 12 + C.LUNA),
    Round(CASE
            WHEN NVL(PCA.CANT, 0) = 0 THEN 0
            ELSE CASE WHEN TipValMatPC = 2 THEN (NVL(PCA.MAT, 0)+NVL(PCA.MAN, 0)+NVL(PCA.VALS, 0))/NVL(PCA.CANT, 0) ELSE (NVL(PCA.VAL, 0)+NVL(PCA.MAN, 0)+NVL(PCA.VALS, 0))/NVL(PCA.CANT, 0) END
          END,5),
    Round(CASE WHEN NVL(PCA.CANT, 0) = 0 THEN 0 ELSE NVL(PCA.MAT, 0)/NVL(PCA.CANT, 0) END, 5),
    C1.CODOBIECT,
    PCA.PUNCTE,
    CC.Simbol,
    OBJ.DENUMIRE,
    Substr(IOA.DEN_IOART,1,50),
    Substr(UM.DEN_UM,1,15),
    OBJ1.PRETREFERINTA,
    PC.PRET
  FROM PCART PCA
       INNER JOIN PCALCUL PCC ON PCC.CODPC = PCA.CODPC
       LEFT JOIN NGEST G ON G.CODGEST = PCA.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = PCA.CODCC
       LEFT JOIN COMANDA1 C1 ON PCA.CODCMD1 = C1.CODCOMANDA1
       INNER JOIN COMANDA  C  ON C.CODCOMANDA = C1.CODCOMANDA
       LEFT JOIN CMDPRODMAT MAT ON MAT.CODCOMANDA1 = C1.CODCOMANDA1 AND MAT.TIP = 0
       LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = C1.CODRETETA
       LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = C1.CODOBIECT
       LEFT JOIN NARTOBJ1 OBJ1 ON OBJ1.CODOBIECT = OBJ.CODOBIECT
       LEFT JOIN NART    ART ON OBJ.CODARTICOL = ART.CODARTICOL
       LEFT JOIN NUM UM ON UM.CODUM = ART.UM
       LEFT JOIN IOART IOA ON PCA.CODIOART = IOA.CODIOART
  WHERE PCA.CODPC IN (SELECT CODPC FROM TMP_PCALCUL)
    and PCC.AN*12+PCC.LUNA BETWEEN obj1.ALSTART AND obj1.ALSTOP;

  INSERT INTO TMP_PCSECTII (
    CODPCSECTII,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL) and PCS.FAZA = 0;

  INSERT INTO TMP_PCSECTII2 (
    CODPCSECTII2,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL) and PCS.FAZA = 2;


  INSERT INTO TMP_PCSECTII3 (
    CODPCSECTII3,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL) and PCS.FAZA = 3;

  INSERT INTO TMP_PCSECTII5 (
    CODPCSECTII5,
    CODPC,
    CODNEST,
    VAL,
    FAZA,
    CODD,
    CODC,
    CODCC,
    CODGEST,
    DENGEST,
    CENTRU,
    DEBIT,
    CREDIT)
  SELECT
    PCS.CODPCSECTII,
    PCS.CODPC,
    PCS.CODNEST,
    PCS.VAL,
    PCS.FAZA,
    debit.codcont,
    CREDIT.CODCONT,
    NS.CODCENTRU,
    NS.CODGEST,
    Substr(G.DEN_GEST,1,30),
    CC.Simbol,
    Substr(DEBIT.SIMBOL,1,20),
    Substr(CREDIT.SIMBOL,1,20)
  FROM PCSECTII PCS
       LEFT JOIN NESTJURNAL NS ON PCS.CODNEST = NS.CODNESTJURNAL
       LEFT JOIN NGEST G ON G.CODGEST = NS.CODGEST
       LEFT JOIN CENTRECOST CC ON CC.CODCENTRU = NS.CODCENTRU
       LEFT JOIN NCONT DEBIT ON NS.CODCONTD = DEBIT.CODCONT
       LEFT JOIN NCONT CREDIT ON NS.CODCONTC = CREDIT.CODCONT
  WHERE PCS.CODPC IN (SELECT CODPC FROM TMP_PCALCUL) and PCS.FAZA = 5;


END;


PROCEDURE GET_REG_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 		REG1CONT_IDX_LOCAL NUMBER(10) := 0;
   REG1_IDX_LOCAL     NUMBER(20);
 	 PARAM_REG_DATA     DATE;
 	 PARAM_REG_MONEDA   NUMBER(20);
   PARAM_REG_CURS    NUMBER(20,7);
   DIFERENTE          number(1) := 0;
   DATANEXTREG        DATE;
   CODNEXTREG         NUMBER(20);
--   aCODREG            NUMBER(20);

BEGIN
  EMPTY_DOCUMENTE_FOR_REG;
-- REG
		  DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg,
                         TipReg,
                         NrDoc,
                         DataDoc,
                         CodBank,
                         CodMoneda,
                         Curs, CURS_IFRS,
                         Dirty,
                         Obs,
                         CodSubunit,
                         SimbolMoneda,
                         SimbolBank,
                         Provizion,
                         An,
                         Luna,
                         CODGEST,
                         CodCentru, CodAnalizaNod
                          )
    SELECT CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, CURS_IFRS, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST, CodCentru, CodAnalizaNod
    FROM
    (SELECT ROWNUM RN,
           R.CodReg,
           R.TipReg,
           R.NrDoc,
           R.DataDoc,
           R.CodBank,
           R.CodMoneda,
           R.Curs,
           R.CURS_IFRS,
           R.Dirty,
           R.Obs,
           R.CodSubunit,
           M.Simbol AS SIMBOLMONEDA,
           B.Simbol AS SIMBOLBANK,
           R.Provizion,
           R.An,
           R.Luna,
           R.CODGEST,
           R.CodCentru,
           R.CodAnalizaNod
     FROM REG R
       LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
       LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
     WHERE
        TIPREG = 46
        AND AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
        AND(IS_DIRTY_DOC(46, R.CODREG) = 1)
      )
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;


  DELETE FROM TMP_REG1;

  FOR V_REC_MARE IN (SELECT * FROM TMP_REG)
  LOOP

    DELETE TMP_REG1CONT_MARTOR;

   	REG1CONT_IDX_LOCAL := 0;
  		FOR V_REG1CONT IN
    		(
    		  SELECT
    				SUM(SoldDoc)    AS SoldDoc,
    				SUM(SoldDocVal) AS SoldDocVal,
    				SUM(SoldDocReg) AS SoldDocReg,
    				SUM((SoldDocReg) - (SoldDocVal)) AS Diferenta,
    				Cont
    			FROM
    			  REG1 R1
       WHERE
         R1.CODREG = V_REC_MARE.CODREG
    			GROUP BY Cont
    		)
  		LOOP
  		  REG1CONT_IDX_LOCAL := REG1CONT_IDX_LOCAL + 1;
  		  INSERT INTO TMP_REG1CONT_MARTOR
      		(
      		  CodReg1Cont,
      		 	SoldDoc,
      		 	SoldDocVal,
      		 	SoldDocReg,
      		 	Diferenta,
      		 	Cont
      		)
  			VALUES
    			(
    			  -1 * REG1CONT_IDX_LOCAL,
    			  	V_REG1CONT.SoldDoc,
    				  V_REG1CONT.SoldDocVal,
    				  V_REG1CONT.SoldDocReg,
      			 V_REG1CONT.Diferenta,
      			 V_REG1CONT.Cont
    			);
  		END LOOP;

		  SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM DUAL;
	  	PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);


		  -- populez TMP_REG1;
  	 REG1_IDX_LOCAL := 0;


   PKG_REGPART.MAKE_REGPART_LUNA;

   FOR V_REC IN
   (SELECT RP.*, P.DEN_PART
   FROM
     TMP_REGPART_LUNA RP -- umplu REG1 din TMP_REGPART_LUNA pemtru ca acolo am traduse toate coloanele necesare jurnalului
     LEFT OUTER JOIN NPART P ON P.CODPART = RP.CODPART
   )
   LOOP
      IF ABS(V_REC.SoldDoc * PKG_REG.CURS_REG - V_REC.SoldDocVal) &gt; 0.0000001 THEN
      	  REG1_IDX_LOCAL := REG1_IDX_LOCAL + 1;
      	  INSERT INTO TMP_REG1
         (
        	  CODREG,
           CodReg1,
        			CodGeneral,
        	  Cont,
        			PrefixDoc,
           NrDoc,
           DataDoc,
         		CodPart,
           DenPart,
      				 SimbolCont,
         		SoldDocVal,
           SoldDoc,
           SoldDocReg,
         		Diferenta,
         		Document,
         		CodGest,
      				 Semn,
      				 Curs,
      				 Semnificatie,
      				 CoefProvizion,
           SUBUNITATEA,
           CODOBLIGPIF
         		)
      		VALUES
      		  ( V_REC_MARE.CODREG,
            -1 * REG1_IDX_LOCAL,
         		 	V_REC.CodGeneral,
         		  V_REC.ICONT ,
         			 V_REC.PrefixDoc,
             V_REC.NrDoc,
             V_REC.DataDoc,
         			 V_REC.CodPart,
             V_REC.Den_Part,
      				   PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(V_REC.Semnificatie, V_REC.ICont, V_REC.CodIOPart1)),
         			 V_REC.SoldDocVal,
             V_REC.SoldDoc,
             V_REC.SoldDoc * PARAM_REG_CURS,
         			 V_REC.SoldDoc * PARAM_REG_CURS - V_REC.SoldDocVal,
         			 V_REC.PREFIXDOC || TO_CHAR(V_REC.NRDOC) || &apos;/&apos; || TO_CHAR(V_REC.DATADOC, &apos;DD.MM.YYYY&apos;),
         		  V_REC.CodGest,
      				   1,
      			   	V_REC.Curs,
      				   V_REC.Semnificatie,
      					  V_REC.CoefProvizion,
             V_REC.SUBUNITATEA,
             V_REC.CODOBLIGPIF
      			);
      END IF;
   END LOOP;
   /*END FORMA NOUA */
/*

		-- repopulez si REG1;
		DELETE FROM REG1 WHERE CodReg = V_REC_MARE.CODREG;
    INSERT INTO REG1 (CodReg1, CodReg, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, Cont, Semn, Curs, Semnificatie, SUBUNITATEA)
      (SELECT SEQ_REG1_CODREG1.NEXTVAL, V_REC_MARE.CODREG, CodGeneral, SoldDocVal, SoldDoc, SoldDocReg, CodGest, Cont, Semn, Curs, Semnificatie, SUBUNITATEA
      FROM TMP_REG1 WHERE CodReg = V_REC_MARE.CODREG);


*/
   END LOOP;

  FOR V_REC IN (
    SELECT /*+ cardinality(X,1) */
      R1.CODREG1, R1.CODREG, O.CONTBANKTRANZACTIE, O.SEMNIFICATIE, T1.TIPDECONT, T1.OBIECTTRANZ, X.ANLUCRU, X.LUNALUCRU
    FROM TMP_PKG_GLOBALS X, TMP_REG1 R1, OBLIGPIF O, GENERAL G, TREZOR1 T1
    WHERE R1.CODOBLIGPIF = O.CODOBLIGPIF
      AND O.SEMNIFICATIE IN (500, 600)
      AND G.CODGENERAL  = O.CODGENERAL
      AND T1.CODTREZOR1 = G.CODDOC
  ) LOOP
    UPDATE TMP_REG1
    SET CONT = PKG_TREZOR.CODCONTCEC(V_REC.CONTBANKTRANZACTIE, V_REC.SEMNIFICATIE, V_REC.TIPDECONT, V_REC.OBIECTTRANZ, V_REC.AnLucru, V_REC.LunaLUCRU )
    WHERE CODREG1 = V_REC.CODREG1;
  END LOOP;
END;


PROCEDURE GET_COMPENS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 aCODSUBUNITSTINS NUMBER(20) := 0;
BEGIN
  EMPTY_DOCUMENTE_FOR_COMPENS;

  -- COMPENS
  INSERT INTO TMP_COMPENS (CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, VALDEBIT, VALCREDIT, SUBUNITATEA, CODGEST, TIPCOMPENS, CODCENTRU,CODANALIZA)
  SELECT CODCOMPENS, DATADOC, CARNETDOC, NRDOC, AN, LUNA, PARTD, PARTC, OBSD, OBSC, 0, 0, SUBUNITATEA , CODGEST, TIPCOMPENS, CODCENTRU,CODANALIZA
  FROM
  (
    SELECT ROWNUM RN, S.* FROM
    ( SELECT CODCOMPENS,
             DATADOC,
             CARNETDOC,
             NRDOC,
             AN,
             LUNA,
             PARTD,
             PARTC,
             OBSD,
             OBSC,
             0 AS VALDEBIT,
             0 AS VALCREDIT,
             SUBUNITATEA,
             CODGEST,
             TIPCOMPENS,
             CODCENTRU,
             CODANALIZA
       FROM
        COMPENS C
       WHERE
         AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)  AND(IS_DIRTY_DOC(28, C.CODCOMPENS) = 1)
       ORDER BY CODCOMPENS
    ) S
  )
   WHERE
     RN &gt;= STARTREC AND RN &lt;= ENDREC;


-- GENERAL
    INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
    SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
    FROM
      GENERAL G
    WHERE
      TIPDOC = 28
    AND EXISTS (SELECT CODCOMPENS FROM TMP_COMPENS WHERE CODCOMPENS = G.CODDOC);



-- OBLIGPIF
-- pentru liniile ce reprezinta compensari pe DEBIT  folosesc ca temporar TMP_OBLIGPIF
-- pentru liniile ce reprezinta compensari pe CREDIT folosesc ca temporar TMP_OBLIGPIF_ASOCIAT

     INSERT INTO TMP_OBLIGPIF
     (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION, CODCENTRU, DINCARETVA)
     SELECT * FROM
     (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, PKG_COMPENSARI.SEMNCOMPENS(O.SEMNIFICATIE, O.ICONT) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU, DINCARETVA
      FROM OBLIGPIF O
     WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL) AND SEMNIFICATIE IN (1300, 1301, 1302, 1303)
     )
     ORDER BY CODOBLIGPIF;


     INSERT INTO TMP_OBLIGPIF_ASOCIAT
     (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, VALPROVIZION, CODCENTRU, DINCARETVA)
     SELECT * FROM
      (SELECT CODOBLIGPIF, CODGENERAL, TERMEN,  PKG_COMPENSARI.SEMNCOMPENS(O.SEMNIFICATIE, O.ICONT) * VALOARE, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, COEFPROVIZION, 0, CODCENTRU, DINCARETVA
     FROM OBLIGPIF O
     WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL) AND SEMNIFICATIE IN (1350, 1351, 1352)
     )
     ORDER BY CODOBLIGPIF;

-- STINGERE
-- pentru liniile ce reprezinta compensari pe DEBIT  folosesc TMP_STINGERE
-- pentru liniile ce reprezinta compensari pe CREDIT folosesc TMPSTINGERE_ASOCIAT
     INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
     (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));

     INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA)
     (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, DINCARETVA FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT));


       -- memorez starea la intrare a stingerilor
       DELETE TMP_OBLIGPIF_INITIAL;
       INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF);
       INSERT INTO TMP_OBLIGPIF_INITIAL (SELECT * FROM TMP_OBLIGPIF_ASOCIAT);

       DELETE TMP_STINGERE_INITIAL;
       INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE UNION SELECT * FROM TMP_STINGERE_ASOCIAT);


       -- OBLIGPIF DEBIT
       UPDATE TMP_OBLIGPIF OB
       SET

           CURS    = (SELECT DECODE(NVL(CURS, 0),
                                       0, 1,
                                       CURS
                                       )

                          FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),


           TVA    = (SELECT NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),


           MONEDA       = NVL((SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
           SUMALEI      = ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6),
           VALPROVIZION = ROUND(ROUND(NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),


         CURSISTORIC  =
            NVL((SELECT G.CURS
                 FROM
                 STINGERE S
                 LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1),0),

           SEMNIFCODSTINS = NVL(( SELECT NVL(O.SEMNIFICATIE, 0)
                           FROM
                             STINGERE S
                             LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                           WHERE
                             S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0),

/*
           CURSDOCSTINS = NVL(( SELECT G.CURS
                           FROM
                             STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                             LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                           WHERE
                             S.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;= 1), 0)
*/



              CURSDOCSTINS = NVL(( SELECT NVL(GREG.CURS, G.CURS)
                             FROM
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0)
                             ;



      -- OBLIGPIF CREDIT
       UPDATE TMP_OBLIGPIF_ASOCIAT OB
       SET
         CURS   = (SELECT DECODE(NVL(CURS, 0),
                                     0, 1,
                                     CURS
                                     )

                        FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),


         TVA    = (SELECT NVL(TVA, 0) FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL),
         MONEDA         = NVL((SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
         SUMALEI        = ROUND(NVL((SELECT CURS   FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6),
         VALPROVIZION   = ROUND(ROUND(NVL((SELECT CURS   FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1) * OB.VALOARE, 6) * OB.COEFPROVIZION, 6),
         SEMNIFCODSTINS = NVL(( SELECT NVL(O.SEMNIFICATIE, 0)
                         FROM
                           STINGERE S
                           LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                         WHERE
                             S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0),
/*
         CURSDOCSTINS = NVL(( SELECT G.CURS
                         FROM
                           STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                           LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                         WHERE
                           S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;= 1), 0)
*/
             CURSISTORIC   = NVL(( SELECT G.CURS
                             FROM
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),


              CURSDOCSTINS = NVL(( SELECT NVL(GREG.CURS, G.CURS)
                             FROM
                               STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                               LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                             LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
                             WHERE
                               S.CODSTINGATORPIF = OB.CODOBLIGPIF), 0) ;





   FOR V_REC IN
   (SELECT
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM
      TMP_STINGERE S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL
   )LOOP
      aCODSUBUNITSTINS := 0;

      IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
          WHERE
            CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
          WHERE
            N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
          WHERE
            T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
          WHERE
            C.CODCOMPENS = V_REC.CODDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      END IF;
      END IF;
      END IF;
      END IF;
      END IF;

      UPDATE TMP_STINGERE
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
    END LOOP;

   FOR V_REC IN
   (SELECT
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM
      TMP_STINGERE_ASOCIAT S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL
   )LOOP
      aCODSUBUNITSTINS := 0;

      IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (200, 210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
          WHERE
            CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
          WHERE
            N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
          WHERE
            T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      ELSE
      IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
          WHERE
            C.CODCOMPENS = V_REC.CODDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;
      END IF;
      END IF;
      END IF;
      END IF;
      END IF;

      UPDATE TMP_STINGERE_ASOCIAT
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
    END LOOP;

    UPDATE TMP_OBLIGPIF O
    SET
     CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);

    UPDATE TMP_OBLIGPIF_ASOCIAT O
    SET
     CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);

    UPDATE TMP_OBLIGPIF_INITIAL O
    SET
     CODTREZOR1 = (SELECT CODDOC FROM GENERAL G WHERE G.CODGENERAL = O.CODGENERAL);

END;




PROCEDURE GET_TREZOR_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 aCODSUBUNITSTINS NUMBER(20) := 0;
 NEWCONSTVALUE  VARCHAR(100) := &apos;&apos;;
 NEWCONSTSIMBOL  VARCHAR(100) := &apos;&apos;;
 aCODNBANKCONT1  NUMBER(20) := 0;
 aCODIOBANK      NUMBER(20) := 0;
 aProcStopaj     NUMBER(5, 2) := 0;
BEGIN
   EMPTY_DOCUMENTE_FOR_TREZOR;
   PKG_CONTURIBANCI.MAKE_CURS_BANKCONT_LUNA(&apos;01.&apos; ||  TO_CHAR(PKG_GLOBALS.LUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.ANLUCRU) );
  --TREZOR
    INSERT INTO TMP_TREZOR
     (CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, CODMONEDA, OPERAT, SUBUNITATEA, CREDIT, CURSREG, AN, LUNA)
      SELECT CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, CODMONEDA, OPERAT, SUBUNITATEA, CREDIT, CURS, AN, LUNA
      FROM
      (
        SELECT ROWNUM AS RN, S.*
        FROM
        (
          SELECT T.CODTREZOR, T.TIPDOC, T.CODBANCA, T.ICONTPERS, T.MONEDAPERS, T.An, T.Luna, B.CODMONEDA, OPERAT, T.SUBUNITATEA, B.CREDIT, REG.CURS
          FROM
            TREZOR T
            LEFT OUTER JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
            LEFT OUTER JOIN TMP_CURS_BANKCONT_LUNA REG ON REG.CODBANKCONT = T.CODBANCA
          WHERE
           AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
           AND(IS_DIRTY_DOC(T.TIPDOC, T.CODTREZOR) = 1)
          ORDER BY T.CODTREZOR
        ) S
      )
      WHERE
        RN &gt;= STARTREC AND RN &lt;= ENDREC;

  --TREZOR1
     INSERT INTO TMP_TREZOR1
    (
     CODTREZOR1, CODTREZOR,   INDEXLOCAL, TIPTRANZ, DOC,  NRDOC, DATADOC, VALDOC, CURS, COMISION,
     OBIECTTRANZ, CODPART, TIPDECONT, PLATATVA,  DATADECONT,   OBS, CodCentru,ANULAT
    )
    SELECT * FROM
    (SELECT
      CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC,  NRDOC, DATADOC, VALDOC, CURS, COMISION,
      OBIECTTRANZ, CODPART, TIPDECONT, PLATATVA,  DATADECONT, OBS, CodCentru,ANULAT
    FROM
      TREZOR1 T1
    WHERE EXISTS (SELECT CODTREZOR FROM TMP_TREZOR T WHERE T.CODTREZOR = T1.CODTREZOR)
    )
    ORDER BY INDEXLOCAL;

/*
       UPDATE TMP_TREZOR1 T
       SET
       DENTRANZ = SUBSTR(
       (CASE
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 0 THEN &apos;Furnizor :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1 THEN &apos;Retur Client :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ IN (0, 1) AND OBIECTTRANZ = 3 THEN &apos;Viramente interne :&apos;  || chr(13) ||
          (SELECT B.SIMBOL || &apos; - &apos; || NRCONT FROM NBANKCONT BC LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK  WHERE CODBANKCONT = T.CODPART)

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 0 THEN &apos;Client: &apos;  || ( CASE
                                                                        WHEN T.AGENT &lt;&gt; 0 THEN &apos;(Agent:&apos; || T.NUMEAGENT || &apos;)&apos;
                                                                        ELSE &apos;&apos;
                                                                       END )  || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1 THEN &apos;Retur Furnizor :&apos; || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

          WHEN OBIECTTRANZ = 2 THEN &apos;Personal angajat :&apos; || chr(13) || NVL((SELECT NUME || &apos; &apos; || PRENUME FROM NPERS P WHERE CODPERS = T.CODPART), &apos;&apos;)


          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 4 THEN &apos;Servicii, articole fara NIR...&apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 900))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 4 THEN &apos;Direct pe venituri...&apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 901))

          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 5 THEN &apos;Datorii, taxe, impozite &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 950))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 5 THEN &apos;Imprumuturi, subventii &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 951))

        END
       ), 1, 100);

*/
-- GENERAL
     INSERT INTO TMP_GENERAL
     ( CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA,  SEMNIFICATIE )

     (SELECT
        CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
      FROM
        GENERAL G
      WHERE
        TIPDOC IN (29, 30, 31, 33) AND EXISTS (SELECT CODTREZOR1 FROM TMP_TREZOR1 WHERE CODTREZOR1 = G.CODDOC)
     );



-- OBLIGPIF
       INSERT INTO TMP_OBLIGPIF
       (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, DINCARETVA, RESTTVA, TVAAFISAT)
       SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD,
       TVANEDED, PROCTVA, DINCARETVA, RESTTVA, TVAAFISAT
       FROM
       (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL))
       ORDER BY CODOBLIGPIF;
/*
       INSERT INTO TMP_OBLIGPIF
       (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CodCentru,CODTRANSA, COEFPROVIZION,CODANALIZANOD, TVANEDED)
       SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CodCentru,CODTRANSA, COEFPROVIZION,CODANALIZANOD, TVANEDED
       FROM
       (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL))
       ORDER BY CODOBLIGPIF;
*/

-- STINGERE
       INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
       (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));


       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          I.SUBUNITATEA,
          I.PROCSTOPAJ
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          INTRARI I
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (100, 110, 130)
          AND G.CODDOC = I.CODINTR
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA,
            PROCSTOPAJ      = V_REC.PROCSTOPAJ
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;


        EXECUTE IMMEDIATE &apos;TRUNCATE TABLE MAN_IESIRI&apos;;
        INSERT INTO MAN_IESIRI(CODIES, SUBUNITATEA)
               SELECT
                  G.CODDOC,
                  I.SUBUNITATEA
                FROM
                  TMP_STINGERE S,
                  OBLIGPIF O,
                  GENERAL G
                  INNER JOIN IESIRI I ON  G.CODDOC = I.CODIES
                WHERE
                  S.CODSTINSPIF = O.CODOBLIGPIF
                  AND G.CODGENERAL = O.CODGENERAL
                  AND G.SEMNIFICATIE IN (200, 210);


       FOR V_REC IN
       (SELECT
          /*+ INDEX(I, IDX_MANIESIRI_CODIES) */
          S.CODSTINGERE,
          I.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          MAN_IESIRI I
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (200, 210)
          AND G.CODDOC = I.CODIES
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;


       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          NC.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          NC1,
          NC
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (1200, 1201)
          AND G.CODDOC = NC1.CODNC1
          AND NC.CODNC = NC1.CODNC
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;

       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          T.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          TREZOR1 T1,
          TREZOR T
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (310, 330, 410, 430)
          AND G.CODDOC = T1.CODTREZOR1
          AND T.CODTREZOR = T1.CODTREZOR
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;

       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          C.SUBUNITATEA
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G,
          COMPENS C
        WHERE
          S.CODSTINSPIF = O.CODOBLIGPIF
          AND G.CODGENERAL = O.CODGENERAL
          AND G.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352)
          AND G.CODDOC = C.CODCOMPENS
        )
        LOOP
          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = V_REC.SUBUNITATEA
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;


/*
       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G
        WHERE
         S.CODSTINSPIF = O.CODOBLIGPIF
         AND G.CODGENERAL = O.CODGENERAL
       )LOOP
          aCODSUBUNITSTINS := 0; aProcStopaj := 0;

          IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
            BEGIN
              SELECT SUBUNITATEA, PROCSTOPAJ INTO aCODSUBUNITSTINS, aProcStopaj FROM INTRARI
              WHERE
                CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
              EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
            END;
          ELSE
          IF V_REC.SEMNIFICATIE IN (200, 210) THEN
            BEGIN
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
              WHERE
                CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
              EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
            END;
           ELSE
           IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
             BEGIN
               SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
               WHERE
                 N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
               EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
             END;
             ELSE
             IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
               BEGIN
                 SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
                 WHERE
                   T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
                 EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
               END;
             ELSE
             IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
               BEGIN
                 SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
                 WHERE
                   C.CODCOMPENS = V_REC.CODDOC;
                 EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
               END;
             END IF;
             END IF;

          END IF;
          END IF;
          END IF;

          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = aCODSUBUNITSTINS,
            PROCSTOPAJ      = aProcStopaj
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;
        END LOOP;
*/
      UPDATE TMP_OBLIGPIF OB
       SET
        (CODTREZOR1,CURS, MONEDA, TVA) = (SELECT CODDOC, NVL(CURS, 1), NVL(MONEDA, 0), NVL(TVA, 0) FROM GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL),
        (CURSISTORIC,
          SEMNIFCODSTINS
        )  = (
                    SELECT
                       NVL(CURS, 1),
                       NVL(O.SEMNIFICATIE, 0)
                    FROM
                      STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                       LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                      WHERE
                         S.CODSTINGATORPIF = OB.CODOBLIGPIF
             );


/*
       UPDATE TMP_OBLIGPIF OB
       SET

         CODTREZOR1 = (SELECT CODDOC FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL),
         CURS       = NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1),
         MONEDA     = NVL((SELECT MONEDA FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
         TVA        = NVL((SELECT TVA  FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
         CURSISTORIC   = NVL(( SELECT G.CURS
                         FROM
                           TMP_STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                           LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                         WHERE
                           S.CODSTINGATORPIF = OB.CODOBLIGPIF), 1),
         SEMNIFCODSTINS =
            NVL((SELECT O.SEMNIFICATIE
                 FROM
                 TMP_STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF),0);
*/
-- recodificare ICONT CECuri

      FOR V_REC IN
      (SELECT O.CODOBLIGPIF, T1.TIPDECONT
       FROM
         TMP_OBLIGPIF O,
         TMP_GENERAL G,
         TMP_TREZOR1 T1
       WHERE
         O.SEMNIFICATIE IN (500, 600)
         AND O.CODGENERAL = G.CODGENERAL
         AND T1.CODTREZOR1 = G.CODDOC
       )
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           ICONT = V_REC.TIPDECONT
         WHERE
           CODOBLIGPIF = V_REC.CODOBLIGPIF;
       END LOOP;


-- recodificare ICONT CEC-uri stinse

       FOR V_REC IN
       (
       SELECT
         O.CODOBLIGPIF,
         OS.SEMNIFICATIE,
         T1.TIPDECONT,
         T1.OBIECTTRANZ,
         T.CODBANCA
       FROM
         TMP_OBLIGPIF O,
         TMP_STINGERE S,
         OBLIGPIF OS,
         GENERAL GS,
         TREZOR1 T1,
         TREZOR T
       WHERE
         S.CODSTINGATORPIF = O.CODOBLIGPIF
         AND OS.CODOBLIGPIF = S.CODSTINSPIF
         AND OS.SEMNIFICATIE IN (500, 600)
         AND O.SEMNIFICATIE IN (300, 320, 400, 420)
         AND GS.CODGENERAL = OS.CODGENERAL
         AND T1.CODTREZOR1 = GS.CODDOC
         AND T1.CODTREZOR  = T.CODTREZOR
       )
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           ICONT              = V_REC.TIPDECONT,
           CONTBANKTRANZACTIE = V_REC.CODBANCA,
           OBIECTTRANZSTINS   = V_REC.OBIECTTRANZ
--         SIMBOLCONT  = SIMBOLCONTCEC(CODNBANKCONT, V_REC.SEMNIFICATIE, V_REC.TIPDECONT)
         WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;

       END LOOP;



/*
               FOR V_REC IN
               (
               SELECT
                 O.CODOBLIGPIF,
                 OS.SEMNIFICATIE,
                 TS.TIPDECONT,
                 T.CODBANCA,
                 T.CODTREZOR
               FROM
                 TMP_OBLIGPIF O,
                 TMP_STINGERE S,
                 OBLIGPIF OS,
                 GENERAL GS,
                 TREZOR1 TS,
                 TMP_TREZOR1 T1,
                 TMP_TREZOR T
               WHERE
                 S.CODSTINGATORPIF = O.CODOBLIGPIF
                 AND OS.CODOBLIGPIF = S.CODSTINSPIF
                 AND OS.SEMNIFICATIE IN (500, 600)
                 AND GS.CODGENERAL = OS.CODGENERAL
                 AND TS.CODTREZOR1 = GS.CODDOC
                 AND T1.CODTREZOR1 = O.CODTREZOR1
                 AND T.CODTREZOR = T1.CODTREZOR
                 AND T.TIPDOC = 30
               )
               LOOP
                  aCODNBANKCONT1 := PKG_CONTURIBANCI.GET_COD_NBANKCONT1(V_REC.CODBANCA, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) ;
                  IF aCODNBANKCONT1 &gt; 0 THEN
                     BEGIN
                       SELECT CODIOBANCA INTO aCODIOBANK FROM NBANKCONT1 WHERE CODBANKCONT1 = aCODNBANKCONT1;
                       EXCEPTION WHEN OTHERS THEN  aCODIOBANK := 0;
                     END;
                   END IF;


                    NEWCONSTSIMBOL := PKG_TREZOR.GetSimbolConstantaCEC (V_REC.SEMNIFICATIE, V_REC.TIPDECONT, aCODIOBANK);
                    NEWCONSTVALUE  := pkg_categconst.GetValConstanta(NEWCONSTSIMBOL, pkg_globals.GETANLUCRU, pkg_globals.GETLUNALUCRU);
                    UPDATE TMP_OBLIGPIF
                    SET
                      ICONT = PKG_CATEGCONST.GetCodConstBySimbol(NEWCONSTSIMBOL)
                    WHERE
                     CODOBLIGPIF = V_REC.CODOBLIGPIF;
               END LOOP;
*/

     FOR V_REC IN
     (
       SELECT CODTREZOR1, CODOBLIGPIF FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410)
     )
     LOOP
       UPDATE TMP_TREZOR1
       SET
         CODAVANS = V_REC.CODOBLIGPIF
       WHERE
         CODTREZOR1 = V_REC.CODTREZOR1;
     END LOOP;
/*

       UPDATE TMP_TREZOR1 T
       SET
       CODAVANS = NVL((SELECT CODOBLIGPIF FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND SEMNIFICATIE IN (310, 410)), 0);
*/

       FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE NVL(CODTRANSA, 0) &lt;&gt; 0)
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           CURSTRANSA = (SELECT G.CURS FROM OBLIGPIF O, GENERAL G WHERE O.CODOBLIGPIF = V_REC.CODTRANSA AND G.CODGENERAL = O.CODGENERAL)
         WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
       END LOOP;



       UPDATE TMP_TREZOR1 T
       SET
       DENTRANZ = SUBSTR(
       (CASE
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 0 THEN &apos;Furnizor :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1 THEN &apos;Retur Client :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ IN (0, 1) AND OBIECTTRANZ = 3 THEN &apos;Viramente interne :&apos;  || chr(13) ||
          (SELECT B.SIMBOL || &apos; - &apos; || NRCONT FROM NBANKCONT BC LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK  WHERE CODBANKCONT = T.CODPART)

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 0 THEN &apos;Client: &apos;  || ( CASE
                                                                        WHEN T.AGENT &lt;&gt; 0 THEN &apos;(Agent:&apos; || T.NUMEAGENT || &apos;)&apos;
                                                                        ELSE &apos;&apos;
                                                                       END )  || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1 THEN &apos;Retur Furnizor :&apos; || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

          WHEN OBIECTTRANZ = 2 THEN &apos;Personal angajat :&apos; || chr(13) || NVL((SELECT NUME || &apos; &apos; || PRENUME FROM NPERS P WHERE CODPERS = T.CODPART), &apos;&apos;)


          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 4 THEN &apos;Servicii, articole fara NIR...&apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 900 AND ROWNUM = 1))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 4 THEN &apos;Direct pe venituri...&apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 901 AND ROWNUM = 1))

          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 5 THEN &apos;Datorii, taxe, impozite &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 950 AND ROWNUM = 1))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 5 THEN &apos;Imprumuturi, subventii &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 951 AND ROWNUM = 1))

        END
       ), 1, 100);


END;


PROCEDURE GET_INTRARI_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
  NR NUMBER(20, 0) := 0;
  LUNAREF      PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
  IOPART1REC   IOPART1 % ROWTYPE;
  aCODSUBUNITSTINS NUMBER(20);
  TIPINTR number(5);
  aCurs number(20,7);

BEGIN
  EMPTY_DOCUMENTE_FOR_JURNAL;

  -- INTRARI--
  INSERT INTO TMP_INTRARI
    (CODINTR,   TIPDOC, ANULAT, BLOCAT,  OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER, NRAVIZ, RotEFact,
     CARNETDOC, VALDOC, TVADOC, MAJORARI, AN,    LUNA,      OBS,   SATELIT, COMPLEX, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC, BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, CODGESTPROD,
     MONEDA,
     CURS,
     SUBUNITATEA,
     TVAIncasare,
     Prorata,
     TIPTVA,
     TIPTRANZACTIE
     )

     SELECT CODINTR,   TIPDOC, ANULAT, BLOCAT,  OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER, NRAVIZ,RotEFact,
            CARNETDOC, VALDOC, TVADOC, MAJORARI, AN,    LUNA,      OBS,   SATELIT, COMPLEX, CODSUBUNIT, CODFISCAL, CONTSUPLIM, SERIADOC,  BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, CODGESTPROD,
            MONEDA,    CURS, SUBUNITATEA, TVAIncasare, Prorata,
            TIPTVA,
            TIPTRANZACTIE
     FROM
    (
     SELECT ROWNUM AS RN, S.* FROM
      (SELECT DISTINCT
         I.CODINTR,   TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, PREFIXDOC, NRDOC, DATADOC, PARTENER, NRAVIZ,RotEFact,
         CARNETDOC, VALDOC, TVADOC, MAJORARI, AN,    LUNA,      I.OBS,   SATELIT, COMPLEX, I.CODSUBUNIT, I.CODFISCAL, CONTSUPLIM, SERIADOC,  BUGETARE, VALSUPLIM, TIPREPSUPLIM, CODLOCATIE, TIPFACTURA, CODGESTPROD,
         I.MONEDA,
         I.CURS, I.SUBUNITATEA, I.TVAIncasare, I.Prorata, I.TIPTVA, I.TIPTRANZACTIE
       FROM
         INTRARI I
       WHERE
          AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
					 AND
          (IS_DIRTY_DOC(I.TIPDOC, I.CODINTR) = 1) -- pentru a elimina IESIRILE IN ROSU
        ORDER BY CODINTR
      ) S
    )
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;


  -- INTRARI1 --
   DELETE INTRARI1_MAN;
   INSERT INTO INTRARI1_MAN (SELECT * FROM INTRARI1 WHERE CODINTR IN (SELECT CODINTR FROM TMP_INTRARI));

  INSERT INTO TMP_DVI(CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TIPREPSUPLIM, VALSUPLIM, CONTSUPLIM, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA)
  SELECT CODDVI, CODINTR, CODVAMA, NRDOC, DATADOC, CONTCHELT, CONTTVA, TAXEINCLUSE, FISAVAMA, TAXEPECHELT, TIPREPSUPLIM, VALSUPLIM, CONTSUPLIM, OBS, TIPIMPORT, VALDOCVAMA, TVADOCVAMA
  FROM
    DVI
  WHERE
   CODINTR IN (SELECT CODINTR FROM TMP_INTRARI);


  INSERT INTO  TMP_INTRARI1
    (CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA,
     CodCentru,CONTSERV, CONTDISCOUNT, GESTACT, CODOBIECT, PRETORIG, PU, CANT, TVA, ADDIM, RESTFACT, NRCERTIF, TG, PUMAXIMAL, PURIDICATA, PROCADAOS, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO,
     CURSFACTURAAVANS, DENUM, VALOARE, PARITATE, PROCTVA, GESTIMPLICITA, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, CODCMDINT1, DENOBIECT, SIMBOLCONTSERV, TVANEDED,ICONTPART,CODANALIZANOD, IMPOZABIL, MIFIX )

    SELECT * FROM
     (SELECT /*+ cardinality(X,1) */
		         I1.CODINTR1, I1.CODINTR, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.AN, I1.LUNA,
             i1.CodCentru,I1.CONTSERV, I1.CONTDISCOUNT, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * NVL(U1.PARITATE, 1),
             I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.ADDIM,
             I1.RESTFACT, I1.NRCERTIF, I1.TG, I1.PUMAXIMAL, I1.PURIDICATA, I1.PROCADAOS, I1.FURNAVIZSUBUNIT,  I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
             CASE
               WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
               ELSE U1.DEN_UM1
             END,
             (
               CASE
                 WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
                 ELSE I1.RESTFACT
               END
             ),
             U1.PARITATE,
             CASE
               WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, X.ANLUCRU, X.LUNALUCRU)
               ELSE 0
             END,
             A.GESTIMPLICITA,
             NART1LUNA.CODTVA,
             NART1LUNA.CODACCIZE,
             NART1LUNA.CODTAXA1,
             NART1LUNA.CODTAXA2,
             I1.CODCMDINT1,
             O.DENUMIRE,
             ( --SIMBOLCONTSERV--
              CASE
                WHEN I1.CODOBIECT &lt;&gt; 0 AND UPPER(I1.TIPLINIE) IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;(&apos; || C.SIMBOL || &apos;)&apos;
                WHEN UPPER(I1.TIPLINIE) IN (&apos;S&apos;, &apos;V&apos;) THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;
                ELSE &apos;&apos;
              END
              ),
              I1.TVANEDED, I1.ICONTPART,
              I1.CODANALIZANOD,
              I1.IMPOZABIL,
              I1.MIFIX
      FROM
        TMP_PKG_GLOBALS X,
        INTRARI1_MAN I1
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
        LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN
        TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
        LEFT OUTER JOIN NCONT C ON C.CODCONT = I1.CODOBIECT
      WHERE
        EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR)
     )
     ORDER BY CODINTR, INDEXLOCAL;



     UPDATE TMP_INTRARI1 I1
     SET
       NRDOCLINK = (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
                    FROM
                      INTRLINK IL
                      LEFT OUTER JOIN INTRARI1 II1 ON II1.CodINTR1 = IL.CODLINIEAVIZ
                      LEFT OUTER JOIN INTRARI  II ON II.CodINTR    = II1.CODINTR
                    WHERE
                      I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND IL.CODINTR1 = I1.CODINTR1
                    )
     WHERE
       I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL((SELECT TIPDOC FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR), 0) = 9;

     UPDATE TMP_INTRARI1 I1 SET VALOARE = Round(Valoare, 2)
     WHERE  COALESCE((SELECT ROTEFACT FROM TMP_INTRARI WHERE CODINTR = I1.CODINTR), 0) = 1;


     UPDATE TMP_INTRARI1
     SET
     SIMBOLCONTSERV = CASE
                   WHEN  NVL(CONTDISCOUNT, 0) &lt;&gt; 0 THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(NVL(CONTDISCOUNT, 0)) || &apos;)&apos;
                   ELSE &apos;&apos;
                 END
     WHERE
       TIPLINIE IN (&apos;G&apos;, &apos;T&apos;);



   UPDATE TMP_INTRARI1
   SET
     SIMBOLCONTSERV = &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(CONTSERV) || &apos;)&apos;
   WHERE
     UPPER(TIPLINIE) IN (&apos;S&apos;, &apos;V&apos;);



   INSERT INTO TMP_DVI1
   (CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT, PUMAXIMAL, CONTDISCOUNT, PRETVALUTA, PRETORIGINAL, TVA, UMSEC, ADDIM, CODOBIECT, CANT, PARITATE, PROCTVA, VALOARE, DENUM, GESTIMPLICITA, TVANEDED)
   SELECT /*+ cardinality(X,1) */
   CODDVI1, CODDVI, CODINTR1, TIPLINIE, INDEXLOCAL, PRETIMPORT * NVL(U1.PARITATE, 1), PUMAXIMAL * NVL(U1.PARITATE, 1), CONTDISCOUNT, PRETVALUTA * NVL(U1.PARITATE, 1), PRETORIGINAL, TVA, UMSEC, ADDIM,
   CODOBIECT,
   CANT/ NVL(U1.PARITATE, 1),
   U1.PARITATE,

   CASE
     WHEN TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT), X.ANLUCRU, X.LUNALUCRU)
     ELSE 0
   END,

   CASE
     WHEN TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PRETIMPORT * CANT
     ELSE VALOARETAXA
   END,
   CASE
     WHEN TIPLINIE IN (&apos;A&apos;, &apos;X&apos;, &apos;C&apos;) THEN &apos;%&apos;
     ELSE U1.DEN_UM1
   END,
   CASE
     WHEN TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN (SELECT GESTIMPLICITA FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT))
     ELSE 0
   END,
   TVANEDED

   FROM
     TMP_PKG_GLOBALS X,
     DVI1 D1
     LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1 = D1.UMSEC
   WHERE
    CODDVI IN (SELECT CODDVI FROM TMP_DVI);


  UPDATE TMP_DVI1 D1
  SET
    DENOBIECT  = CASE
                   WHEN TIPLINIE = &apos;X&apos; THEN &apos;Taxa vamala&apos;
                   WHEN TIPLINIE = &apos;A&apos; THEN &apos;Accize in vama&apos;
                   WHEN TIPLINIE = &apos;C&apos; THEN &apos;Comision vamal&apos;
                   ELSE NVL((SELECT DENOBIECT FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), &apos;&apos;)
                  END,
    INFOSUPLIM = CASE
                   WHEN TIPLINIE IN (&apos;X&apos;, &apos;A&apos;, &apos;C&apos;) AND CONTDISCOUNT &lt;&gt; 0 THEN PKG_PLANCONTURI.GETSIMBOLCONT(CONTDISCOUNT)
                 END,
   PROCADAOS   = NVL((SELECT PROCADAOS FROM TMP_INTRARI1 WHERE CODINTR1 = D1.CODINTR1), 0),
   (MASA, VOLUM) =  (SELECT NVL(MASA, 0), NVL(VOLUM, 0) FROM NARTOBJ O WHERE O.CODOBIECT = D1.CODOBIECT),
   (CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO,CODANALIZANOD ) =
   (SELECT CONTSERV, SIMBOLCONTSERV, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, GESTACT, CODCENTRU, CURSFACTURAAVANS, CODOBLIGSTORNO,CODANALIZANOD FROM TMP_INTRARI1 I1 WHERE I1.CODINTR1 = D1.CODINTR1);


-- INTRLINK --
     INSERT INTO TMP_INTRLINK
       (CODINTR1, CODLINIECOMANDA, CODLINIEAVIZ, CANT, MONEDAAVIZ, CURSAVIZ, PRETAVIZ, CANTAVIZ, TVAAVIZ, SUBUNITAVIZ)
       (SELECT L.CODINTR1, L.CODLINIECOMANDA, L.CODLINIEAVIZ, L.CANT,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.MONEDA
          ELSE 0
        END,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.CURS
          ELSE 0
        END,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.PU
          ELSE 0
        END,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.CANT
          ELSE 0
        END,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.TVA
          ELSE 0
        END,
        CASE
          WHEN I.TIPDOC = 9 THEN AVIZ.SUBUNITATEA
          ELSE 0
        END
     FROM
       INTRLINK L
       LEFT OUTER JOIN INTRARI1 I1 ON L.CODINTR1  = I1.CODINTR1
       LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = I1.CODINTR
       LEFT OUTER JOIN
      (SELECT
         G.MONEDA,
         NVL(GREG.CURS, G.CURS) AS CURS,
         S.PU,
         S.CANT,
         S.TVA,
         S.CODINTR1,
         SM.SUBUNITATEA
       FROM
         INTRARI1 S,
         INTRARI SM,
         GENERAL G
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      WHERE
        G.TIPDOC = 2 AND G.CODDOC = S.CODINTR
        AND S.CODINTR = SM.CODINTR
      ) AVIZ
       ON AVIZ.CODINTR1 = L.CODLINIEAVIZ
     WHERE
       EXISTS (SELECT * FROM TMP_INTRARI1 WHERE CODINTR1 = L.CODINTR1)
    );


   -- Detail INTRASTERPTLINK
   INSERT INTO TMP_INTRASTEPTLINK
   (CODINTR1, CODLINIEFACTURA, CANT)
   (SELECT CODINTR1, CODLINIEFACTURA, CANT
   FROM
   INTRASTEPTLINK L
   WHERE
   L.CODINTR1 IN (SELECT CODINTR1 FROM TMP_INTRARI1)
  );

  UPDATE TMP_INTRASTEPTLINK L
  SET
    (MONEDAFACT, CURSFACT, PRETFACT, TVAFACT, DATAFACT, CONTFACT) =
    (SELECT
       G.MONEDA,
       NVL(GREG.CURS, G.CURS),
       S.PU,
       S.TVA,
       I.DATADOC,
       S.CONTSERV
     FROM
       INTRARI1 S,
       GENERAL G
       LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL,
       INTRARI I
     WHERE
       S.CODINTR1 = L.CODLINIEFACTURA
       AND  G.CODDOC = S.CODINTR
       AND I.CODINTR= S.CODINTR
       AND G.TIPDOC = 9
       AND G.SEMNIFICATIE = 140
      );


-- NIR --
  INSERT INTO TMP_NIR
    ( CODNIR, CODINTR, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT, VALOARE )
    ( SELECT
        N.CODNIR, N.CODINTR, N.CARNETNIR, N.NRNIR, N.DATANIR, N.GEST, N.OBS, N.TIPNIR, N.ANULAT, N.BLOCAT, N.OPERAT,
     (SELECT SUM(NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
      FROM
        NIR N WHERE EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = N.CODINTR)
    );

-- NIRSTOC --

  DELETE NIRSTOC_MAN;
  INSERT INTO NIRSTOC_MAN
  SELECT * FROM NIRSTOC NS WHERE EXISTS (SELECT CODNIR FROM TMP_NIR WHERE CODNIR = NS.CODNIR);

  INSERT INTO  TMP_NIRSTOC
    (CODNIRSTOC, CODNIR, CODINTR1, CODDVI1, CANTNIR, UMSEC, CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, ADAOS, TVA, TIPSERIE, CODLIVR1, REST, PROCENTADAOS, SUPLIMENT, SuplNeded,
     DENUM, PARITATE, VALOARE, CANTFURN, MG, DIFPRET, ARETVANEEX, PUStandard, ANALITICTVA, CONT,
		 PRETACHIZ,PROVIZION,
		 PROCTVA, CODTVA, DENOBIECT)
    SELECT  * FROM
    ( SELECT /*+ cardinality(X,1) */
        NS.CODNIRSTOC, NS.CODNIR,  NS.CODINTR1, NS.CODDVI1, NS.CANTNIR / U1.PARITATE, NS.UMSEC, NS.CODOBIECT, NS.CODIOART, NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA,
        NS.ADAOS * U1.PARITATE, NS.TVA, NS.TIPSERIE, NS.CODLIVR1, NS.REST, NS.PROCENTADAOS, NS.SUPLIMENT, NS.SuplNeded,  U1.DEN_UM1, U1.PARITATE,
        NS.CANTNIR * NS.PRET, NS.CANTFURN / U1.PARITATE,
        IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.PUStandard, IOALUNA.TVANEEX AS ANALITICTVA, IOALUNA.CONT,
--        I1.PU * U1.PARITATE,
        NS.pret - NS.Adaos,NS.PROVIZION,
        PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, X.ANLUCRU, X.LUNALUCRU),
        NART1LUNA.CODTVA,
        O.DENUMIRE
      FROM
        Tmp_Pkg_Globals X,
        NIRSTOC_MAN NS
        LEFT OUTER JOIN TMP_INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
        LEFT OUTER JOIN TMP_IOART_LUNA IOALUNA ON IOALUNA.CODIOART = NS.CODIOART
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT   = NS.CODOBIECT
        LEFT OUTER JOIN NART A ON A.CODARTICOL     = O.CODARTICOL
        LEFT OUTER JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL,
        NUM1 U1
      WHERE
        EXISTS (SELECT * FROM TMP_NIR WHERE CODNIR = NS.CODNIR ) AND U1.CODUM1 = NS.UMSEC
      )
     ORDER BY CODNIR, CODINTR1;


-- LIVR --
    INSERT INTO  TMP_LIVR
      ( CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
      ( SELECT
          CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
        FROM
        LIVR L WHERE EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = L.CODINTR)
      );

-- LIVR1 --
  INSERT INTO  TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODINTR1,
       CODDVI1,
       CODNIRSTOC,
       CANT,
       CODNIRSER,
       PMP,
       UMSEC,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE,
       PROVIZION )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODINTR1,
         L1.CODDVI1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CODNIRSER,
         L1.PMP,
         L1.UMSEC,
         U1.DEN_UM1,
         U1.PARITATE,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,


         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,

        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
        NS.PROVIZION
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         EXISTS (SELECT * FROM TMP_INTRARI WHERE CODINTR = L.CODINTR ) AND U1.CODUM1 = L1.UMSEC
     );


-- LIVRTOT --
  INSERT INTO TMP_LIVRTOT
   (
   CODLIVRTOT,
   CODLIVR,
   CODIESINT1,
   UMSEC,
   GEST,
   CODIOART,
   CODOBIECT,
   DENUM,
   PARITATE,
   DIFPRET,
   ARETVANEEX,
   MG,
   CONT,
   SUFIXTVANEEX,
   PROCTVA,
   CANT,
   PRETINREG,
   PRETACHIZ)
   SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODINTR1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         IOALUNA.DIFPRET,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         NTVALUNA.PROCENT,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT))
       FROM TMP_LIVR1 L1
         CROSS JOIN TMP_PKG_GLOBALS TG
         LEFT OUTER JOIN TMP_LIVR L ON L.CODLIVR = L1.CODLIVR
         LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = L1.CODOBIECT
         LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
         LEFT OUTER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
         LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
         LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
         LEFT OUTER JOIN NTVA1 NTVALUNA  ON NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
        WHERE L.TIPLIVR &lt;&gt; 5
       GROUP BY
         0, L1.CODLIVR, L1.CODINTR1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE , IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT,  IOALUNA.TVANEEX, NTVALUNA.PROCENT
     )
  ORDER BY CODLIVR, CODINTR1;

  INSERT INTO TMP_LIVRTOT
   (
   CODLIVRTOT,
   CODLIVR,
   CODIESINT1,
   UMSEC,
   GEST,
   CODIOART,
   CODOBIECT,
   DENUM,
   PARITATE,
   DIFPRET,
   ARETVANEEX,
   MG,
   CONT,
   SUFIXTVANEEX,
   PROCTVA,
   CANT,
   PRETINREG,
   PRETACHIZ)
   SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODDVI1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         IOALUNA.DIFPRET,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         NTVALUNA.PROCENT,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT))
       FROM TMP_LIVR1 L1
         CROSS JOIN TMP_PKG_GLOBALS TG
         LEFT OUTER JOIN TMP_LIVR L ON L.CODLIVR = L1.CODLIVR
         LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = L1.CODOBIECT
         LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
         LEFT OUTER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
         LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
         LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
         LEFT OUTER JOIN NTVA1 NTVALUNA  ON NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
       WHERE L.TIPLIVR = 5
       GROUP BY
         0, L1.CODLIVR, L1.CODDVI1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST, L1.CODIOART,  L1.DENUM, L1.PARITATE , IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT,  IOALUNA.TVANEEX, NTVALUNA.PROCENT
     )
  ORDER BY CODLIVR, CODDVI1;


   UPDATE TMP_LIVRTOT T
   SET
   CODLIVRTOT  = ROWNUM;



-- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
   UPDATE TMP_LIVR1 L1
   SET
    CODLIVRTOT =
     ( SELECT CODLIVRTOT FROM TMP_LIVRTOT
       WHERE
         CODLIVR    = L1.CODLIVR  AND
         CODIESINT1 = L1.CODINTR1 AND
         UMSEC      = L1.UMSEC    AND
         PARITATE   = L1.PARITATE AND
         GEST       = L1.GEST     AND
         CODIOART   = L1.CODIOART
      )
    WHERE
      (SELECT TIPLIVR FROM TMP_LIVR L WHERE L.CODLIVR = L1.CODLIVR) &lt;&gt; 5
     ;

   UPDATE TMP_LIVR1 L1
   SET
    CODLIVRTOT =
     ( SELECT CODLIVRTOT FROM TMP_LIVRTOT
       WHERE
         CODLIVR    = L1.CODLIVR  AND
         CODIESINT1 = L1.CODDVI1  AND
         UMSEC      = L1.UMSEC    AND
         PARITATE   = L1.PARITATE AND
         GEST       = L1.GEST     AND
         CODIOART   = L1.CODIOART
      )
    WHERE
      (SELECT TIPLIVR FROM TMP_LIVR L WHERE L.CODLIVR = L1.CODLIVR) = 5
     ;


-- PENTRU PARTENERII DIN INTRARI + DVI COMPLETEZ  TMP_IOPARTDOC + TMP_IOPARTDOCVAMA;

 FOR V_REC IN (SELECT /*+ cardinality(X,1) */ Y.*, X.AnLucru AnX, X.LunaLucru LunaX FROM TMP_INTRARI Y, TMP_PKG_GLOBALS X WHERE Y.TIPDOC IN (1, 2, 3, 5, 4, 9))
 LOOP
   SELECT COUNT(*) INTO NR FROM TMP_IOPARTDOC WHERE CODPART = V_REC.PARTENER;
   IF NR = 0 THEN
       LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(V_REC.PARTENER, V_REC.AnX, V_REC.LUNAX);
       LOOP
         FETCH LUNAREF INTO IOPART1REC;
         EXIT WHEN LUNAREF%NOTFOUND;
         IF IOPART1REC.CODIOPART1 &gt; 0 THEN
             INSERT INTO TMP_IOPARTDOC
             ( CODPART,
               CODIOPART1,
               CODIOPART,
               CONTFURNIZOR,
               CONTCLIENT,
               CONTFURNAVANS,
               CONTCLIENTAVANS,
               CONTFURNAVIZ,
               CONTCLIENTAVIZ,
               CONTFURNMF,
               CONTCREDITD,
               CONTDEBITD,
               CONTLITIGII,
               CONTFURNAVS,
               CONTFURNAVIC,
               CONTFURNAVIN,
               CONTTERTI,
               TvaNeexF, TvaNeexP, TvaNeexI,
               TVANEEXC,
               TIP
               )
               VALUES
               (V_REC.PARTENER,
                IOPART1REC.CODIOPART1,
                IOPART1REC.CODIOPART,
                IOPART1REC.CONTFURNIZOR,
                IOPART1REC.CONTCLIENT,
                IOPART1REC.CONTFURNAVANS,
                IOPART1REC.CONTCLIENTAVANS,
                IOPART1REC.CONTFURNAVIZ,
                IOPART1REC.CONTCLIENTAVIZ,
                IOPART1REC.CONTFURNMF,
                IOPART1REC.CONTCREDITD,
                IOPART1REC.CONTDEBITD,
                IOPART1REC.CONTLITIGII,
                IOPART1REC.CONTFURNAVS,
                IOPART1REC.CONTFURNAVIC,
                IOPART1REC.CONTFURNAVIN,
                IOPART1REC.CONTTERTI,
                IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
                IOPART1REC.TVANEEXC,
                IOPART1REC.TIP
               );
         END IF;
       END LOOP;
   END IF;
 END LOOP;


 FOR V_REC IN (SELECT * FROM TMP_DVI, TMP_PKG_GLOBALS X)
 LOOP
   SELECT COUNT(*) INTO NR FROM TMP_IOPARTVAMA WHERE CODPART = V_REC.CODVAMA;
   IF NR = 0 THEN
       LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(V_REC.CODVAMA, V_REC.ANLUCRU, V_REC.LUNALUCRU);
       LOOP
         FETCH LUNAREF INTO IOPART1REC;
         EXIT WHEN LUNAREF%NOTFOUND;
         IF IOPART1REC.CODIOPART1 &gt; 0 THEN
             INSERT INTO TMP_IOPARTVAMA
             ( CODPART,
               CODIOPART1,
               CODIOPART,
               CONTFURNIZOR,
               CONTCLIENT,
               CONTFURNAVANS,
               CONTCLIENTAVANS,
               CONTFURNAVIZ,
               CONTCLIENTAVIZ,
               CONTFURNMF,
               CONTCREDITD,
               CONTDEBITD,
               CONTLITIGII,
               CONTFURNAVS,
               CONTFURNAVIC,
               CONTFURNAVIN,
               CONTTERTI,
               TvaNeexF, TvaNeexP, TvaNeexI,
               TVANEEXC,
               TIP
               )
               VALUES
               (V_REC.CODVAMA,
                IOPART1REC.CODIOPART1,
                IOPART1REC.CODIOPART,
                IOPART1REC.CONTFURNIZOR,
                IOPART1REC.CONTCLIENT,
                IOPART1REC.CONTFURNAVANS,
                IOPART1REC.CONTCLIENTAVANS,
                IOPART1REC.CONTFURNAVIZ,
                IOPART1REC.CONTCLIENTAVIZ,
                IOPART1REC.CONTFURNMF,
                IOPART1REC.CONTCREDITD,
                IOPART1REC.CONTDEBITD,
                IOPART1REC.CONTLITIGII,
                IOPART1REC.CONTFURNAVS,
                IOPART1REC.CONTFURNAVIC,
                IOPART1REC.CONTFURNAVIN,
                IOPART1REC.CONTTERTI,
                IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
                IOPART1REC.TVANEEXC,
                IOPART1REC.TIP
               );
         END IF;
       END LOOP;
   END IF;
 END LOOP;



 -- GENERAL
 DELETE TMP_GENERAL;
 INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
 (SELECT CODGENERAL,
         TIPDOC,
         CODDOC,
         MONEDA,
         CURS,
         TVA,
         SEMNIFICATIE,
         ICONTAVANS,
         PROCTVAAVANS
   FROM
       GENERAL G WHERE EXISTS (SELECT CODINTR FROM TMP_INTRARI WHERE CODINTR = G.CODDOC AND TIPDOC = G.TIPDOC)

 );




-- OBLIGPIF
 DELETE TMP_OBLIGPIF;
 INSERT INTO TMP_OBLIGPIF
 (CODOBLIGPIF,CODGENERAL)
 (SELECT CODOBLIGPIF,CODGENERAL
 FROM
 OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));


 -- STINGERE
   DELETE TMP_STINGERE;
   INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
   (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));



   FOR V_REC IN
   (SELECT
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM
      TMP_STINGERE S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL
   )LOOP
      aCODSUBUNITSTINS := 0;
      IF V_REC.SEMNIFICATIE IN (110) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM INTRARI
          WHERE
            CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;

      UPDATE TMP_STINGERE
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
      END IF;
    END LOOP;


END;

PROCEDURE GET_IESIRI_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 NR NUMBER(20, 0) := 0;
 LUNAREF      PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
 IOPART1REC   IOPART1 % ROWTYPE;
 aCODSUBUNITSTINS NUMBER(20);
BEGIN

  EMPTY_DOCUMENTE_FOR_JURNAL;
-- IESIRI --
  INSERT INTO TMP_IESIRI
  ( CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC, RotEFact,
    NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED, NUMEDELEGAT,
    MONEDA, TIPCHELT, TipTVA,CODTVASERV, CODCONTTVAOSS,
    CURS, SUBUNITATEA, INFOCM, CONTSUPLIM, CUSTODIE, TVAIncasare, DataTVA, TIPTRANZACTIE,  NOACCIZE, FLAGS)
    SELECT
      CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,RotEFact,
      NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
      ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED, NUMEDELEGAT,
      MONEDA, TIPCHELT, TipTVA,CODTVASERV, CODCONTTVAOSS,
      CURS, SUBUNITATEA, INFOCM, CONTSUPLIM, CUSTODIE, TVAIncasare, DataTVA, TIPTRANZACTIE, NOACCIZE, FLAGS
    FROM
      (
       SELECT ROWNUM AS RN, S.* FROM
       (
       SELECT
         CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,RotEFact,
         NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
         ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED,
         NVL((SELECT SUBSTR(DELEGAT,1, 50) FROM NPARTTR WHERE CODPARTTR = I.DELEGAT), &apos;&apos;) AS NUMEDELEGAT,
         I.MONEDA, I.TIPCHELT, I.TipTVA, I.CODTVASERV, tsr1.codcont as CODCONTTVAOSS,
				 I.CURS, I.SUBUNITATEA, I.INFOCM, I.CONTSUPLIM, I.CUSTODIE, I.TVAIncasare, I.DataTVA, I.TIPTRANZACTIE, i.NOACCIZE, i.FLAGS
       FROM
         IESIRI I
         LEFT JOIN tvaserv1 tsr1 on tsr1.codtvaserv = I.Codtvaserv
                                                                 and (i.an*12+i.luna) BETWEEN tsr1.ALSTART AND tsr1.ALSTOP
       WHERE
         AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
         AND COALESCE(INFOCM, 0) = 0
         AND (IS_DIRTY_DOC(I.TIPDOC, I.CODIES) = 1)
       ORDER BY  CODIES
       ) S
      )
     WHERE RN &gt;=STARTREC AND RN &lt;= ENDREC ;

     update tmp_iesiri e
     set e.TotDiscOffInvoiceC = (select Sum(Nvl(d.Procent, 0)) from Iesdisc d where d.CodIes = E.CodIes and d.OffInvoice = 2),
         e.TotDiscOffInvoiceF = (select Sum(Nvl(d.Procent, 0)) from Iesdisc d where d.CodIes = E.CodIes and d.OffInvoice = 3);



  DELETE IESIRI1_MAN;
  INSERT INTO IESIRI1_MAN SELECT * FROM IESIRI1 I1
   WHERE
     EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = I1.CODIES);


-- IESIRI1 --
  INSERT INTO TMP_IESIRI1
    (CODIES1,  CODIES,    INDEXLOCAL,  TIPLINIE,       UMSEC,ValDiscPret,
     CodCentru,CONTSERV, GESTACT,   CODOBIECT,   PRETORIG,       PU,
     CANT,     TVA,       CONT,        PROCDISC,       ADDIM,
     RESTFACT, PUMAXIMAL, GARANTIE,    DENUM,          VALOARE,
     PARITATE, PROCTVA,   CODOBLIGSTORNO, CURSFACTURAAVANS, TipLivrare,    CUSTODIEINTRARE,
     CODTVA,   CODACCIZE, CODTAXA1,    CODTAXA2, CODCMDINT1,
     DENOBIECT, SIMBOLCONTSERV, CONTDISCOUNT,CODANALIZANOD, MIFIX, CODMIFIX, ICONTPART
    )
    SELECT * FROM
     (SELECT /*+ cardinality(X,1) */
        I1.CODIES1,  I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC, I1.ValDiscPret,
        i1.CodCentru,I1.CONTSERV, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * NVL(U1.PARITATE,1),
        I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM,
        I1.RESTFACT,
        I1.PUMAXIMAL, I1.GARANTIE,
        CASE
          WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
          ELSE U1.DEN_UM1
        END,
        (
         CASE
           WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
           ELSE I1.RESTFACT
         END
        ),
        U1.PARITATE,

        CASE
          WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU)
          ELSE 0
        END,
        I1.CODOBLIGSTORNO,
        I1.CURSFACTURAAVANS,
        I1.TipLivrare,
        I1.CUSTODIEINTRARE,
        NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE,
        NART1LUNA.CODTAXA1,
        NART1LUNA.CODTAXA2,
        I1.CODCMDINT1,
        O.DENUMIRE,
        CASE
          WHEN TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND nvl(I1.CODOBIECT,0) = 0 THEN &apos;(&apos; || C.SIMBOL || &apos;)&apos;
          WHEN TIPLINIE IN (&apos;S&apos;, &apos;V&apos;) THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(I1.CONTSERV) || &apos;)&apos;
          ELSE &apos;&apos;
        END,
        I1.CONTDISCOUNT,
        I1.CODANALIZANOD,
        I1.MIFIX,
        I1.CODMIFIX, I1.ICONTPART
      FROM IESIRI1_MAN I1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
        LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
        LEFT OUTER JOIN NCONT C ON C.CODCONT = I1.CONTDISCOUNT
     )
     ORDER BY CODIES, INDEXLOCAL;



     UPDATE TMP_IESIRI1 I1
     SET NRDOCLINK =
      (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
       FROM
         IESLINK IL
         LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODLINIEAVIZ
         LEFT OUTER JOIN IESIRI  II ON II.CODIES    = II1.CODIES
       WHERE
         IL.CODIES1 = I1.CODIES1)
      WHERE
      I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL((SELECT TIPDOC FROM TMP_IESIRI WHERE CODIES = I1.CODIES), 0) = 26;

      UPDATE TMP_IESIRI1 I1 SET VALOARE = Round(Valoare, 2)
      WHERE  COALESCE((SELECT ROTEFACT FROM TMP_IESIRI WHERE CODIES = I1.CODIES), 0) = 1;

-- IESLINK --
     INSERT INTO TMP_IESLINK
       (CODIES1,
        CODLINIEAVIZ,
        CANT,
        MONEDAAVIZ,
        CURSAVIZ,
        PRETAVIZ,
        CANTAVIZ,
        TVAAVIZ,
        CUSTODIE,
        DATAAVIZ,
        SUBUNITAVIZ,
        PROCDISCAVIZ,
				FLAGS
        )
       (SELECT
          L.CODIES1,
          L.CODLINIEAVIZ,
          L.CANT,
          IA.MONEDA,
          NVL(GREG.CURS, G.CURS),
          I1A.PU,
          I1A.CANT,
          I1A.TVA,
          IA.CUSTODIE,
          IA.DATADOC,
          IA.SUBUNITATEA,
          I1A.PROCDISC,
					IA.FLAGS
        FROM
          TMP_IESIRI1 I1,
          TMP_IESIRI I,
          IESLINK L,
          IESIRI1 I1A,
          IESIRI IA
          LEFT JOIN GENERAL G ON G.TIPDOC = 20 AND G.CODDOC = IA.CODIES AND ROWNUM = 1
          LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
         WHERE
           I1.CODIES1 = L.CODIES1
           AND I.CODIES = I1.CODIES
           AND I.TIPDOC = 26
           AND L.CODLINIEAVIZ = I1A.CODIES1
           AND IA.CODIES = I1A.CODIES
        );

--  LIVR
  INSERT INTO TMP_LIVR
    ( CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    ( SELECT
        CODLIVR,  CODIES, CODINTR, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
      FROM
        LIVR L
      WHERE
      EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = L.CODIES)
    );



-- LIVR1 --
  INSERT INTO  TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODIES1,
       CODNIRSTOC,
       CANT,
       CODNIRSER,
       PMP,
       UMSEC,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CONTINTERMED,CODPROIECT,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE,
       PROVIZION )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODIES1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CODNIRSER,
         L1.PMP,
         L1.UMSEC,
         U1.DEN_UM1,
         U1.PARITATE,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,
         NVL(L1.CONTINTERMED,0),NVL(L1.CODPROIECT,0),
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NVL(NS.ADAOS, 0)) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,


         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,

        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
        NS.PROVIZION
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = L.CODIES ) AND U1.CODUM1 = L1.UMSEC
     );


-- LIVRTOT --
  INSERT INTO TMP_LIVRTOT
   (
   CODLIVRTOT,
   CODLIVR,
   CODIESINT1,
   UMSEC,
   GEST,
   CODIOART,
   CONTINTERMED,CODPROIECT,
   CODOBIECT,
   DENUM,
   PARITATE,
   DIFPRET,
   ARETVANEEX,
   MG,
   CONT,
   PROCTVA,
   CANT,
   PRETINREG,
   PRETACHIZ)
   SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODIES1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0), NVL(L1.CODPROIECT,0),
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         IOALUNA.DIFPRET,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         NTVALUNA.PROCENT,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE( SUM(L1.CANT),0,1,SUM(L1.CANT) ),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE( SUM(L1.CANT),0,1,SUM(L1.CANT) )
       FROM TMP_LIVR1 L1
         CROSS JOIN TMP_PKG_GLOBALS TG
         LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = L1.CODOBIECT
         LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
         LEFT OUTER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
         LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
         LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
         LEFT OUTER JOIN NTVA1 NTVALUNA  ON NTVALUNA.CODTVA = NART1LUNA.CODTVA AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NTVALUNA.ALSTART AND NTVALUNA.ALSTOP
       GROUP BY
         0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST, L1.CODIOART,NVL(L1.CONTINTERMED, 0), NVL(L1.CODPROIECT,0),L1.DENUM, L1.PARITATE , IOALUNA.DIFPRET, IOALUNA.ARETVANEEX, IOALUNA.MG, IOALUNA.CONT,  NTVALUNA.PROCENT
     )
  ORDER BY CODLIVR, CODIES1;

  UPDATE TMP_LIVRTOT T
  SET
   CODLIVRTOT  = ROWNUM;


-- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
/*
   UPDATE TMP_LIVR1 L1
    SET
       CODLIVRTOT = ( SELECT CODLIVRTOT FROM TMP_LIVRTOT
                      WHERE
                        NVL(CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
                        NVL(CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
                        NVL(UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
                        NVL(PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
                        NVL(GEST, 0)         = NVL(L1.GEST, 0)     AND
                        NVL(CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
                        NVL(CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0)
                    );

*/
   MERGE INTO TMP_LIVR1 L1
   USING TMP_LIVRTOT LT
   ON (
                        NVL(LT.CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
                        NVL(LT.CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
                        NVL(LT.UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
                        NVL(LT.PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
                        NVL(LT.GEST, 0)         = NVL(L1.GEST, 0)     AND
                        NVL(LT.CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
                        NVL(LT.CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0) AND
                        NVL(LT.CODPROIECT, 0)   = NVL(L1.CODPROIECT, 0)
   )
   WHEN MATCHED THEN UPDATE SET L1.CODLIVRTOT = LT.CODLIVRTOT;

-- TABELE FOLOSTE PENTRU IESIRI IN ROSU
-- NIR
  INSERT INTO TMP_NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
  SELECT CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT
  FROM  NIR N
  WHERE EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = N.CODIES AND TIPDOC = N.TIPNIR);
----------------------
/*   INSERT INTO TMP_NIR(CODNIR, CODINTR, CODIES, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
   SELECT CODNIR, CODINTR, RECID, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT
   FROM NIR WHERE TIPNIR = TIPIES AND CODIES = RECID;
*/
----------------------
-- NIRSTOC
   INSERT INTO TMP_NIRSTOC
    (CODNIRSTOC,
     CODNIR,
     CODINTR1,
     CANTNIR,
     REST,
     UMSEC,
     CODOBIECT,
     CODIOART,
     PRET,
     ADAOS,
     TVA,
     TIPSERIE)
   SELECT CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC,
          CODOBIECT, CODIOART,
          PRET,
          ADAOS,
          TVA,
          TIPSERIE
   FROM
     NIRSTOC NS
   WHERE
--     EXISTS (SELECT * FROM TMP_NIR WHERE TIPNIR IN (19, 20, 21, 22, 26) AND CODNIR = NS.CODNIR);
----------------- am modificat pt ca nu-mi venea nirstoc pt iesiri din nirstoc generat LOCO
     CODNIR IN (SELECT CODNIR FROM TMP_NIR);
---------------



-- PENTRU PARTENERII DIN INTRARI + DVI COMPLETEZ  TMP_IOPARTDOC + TMP_IOPARTDOC;

 FOR V_REC IN (SELECT Y.*, X.AnLucru AnX, X.LunaLucru LunaX FROM TMP_IESIRI Y, TMP_PKG_GLOBALS X WHERE Y.TIPDOC IN (19, 20, 21, 22, 26))
 LOOP
   SELECT COUNT(*) INTO NR FROM TMP_IOPARTDOC WHERE CODPART = V_REC.PARTENER;
   IF NR = 0 THEN
       LUNAREF := PKG_NOMPART.GET_RECORD_PART_CARACT_LUNA(V_REC.PARTENER, V_REC.AnX, V_REC.LunaX);
       LOOP
         FETCH LUNAREF INTO IOPART1REC;
         EXIT WHEN LUNAREF%NOTFOUND;
         IF IOPART1REC.CODIOPART1 &gt; 0 THEN
             INSERT INTO TMP_IOPARTDOC
             ( CODPART,
               CODIOPART1,
               CODIOPART,
               CONTFURNIZOR,
               CONTCLIENT,
               CONTFURNAVANS,
               CONTCLIENTAVANS,
               CONTFURNAVIZ,
               CONTCLIENTAVIZ,
               CONTFURNMF,
               CONTCREDITD,
               CONTDEBITD,
               CONTLITIGII,
               CONTFURNAVS,
               CONTFURNAVIC,
               CONTFURNAVIN,
							 contgarantieEF,
               contgarantieTF,
               contgarantieEC,
               contgarantieTC,
               CONTTERTI,
               TvaNeexF, TvaNeexP, TvaNeexI,
               TVANEEXC,
               TIP
               )
               VALUES
               (V_REC.PARTENER,
                IOPART1REC.CODIOPART1,
                IOPART1REC.CODIOPART,
                IOPART1REC.CONTFURNIZOR,
                IOPART1REC.CONTCLIENT,
                IOPART1REC.CONTFURNAVANS,
                IOPART1REC.CONTCLIENTAVANS,
                IOPART1REC.CONTFURNAVIZ,
                IOPART1REC.CONTCLIENTAVIZ,
                IOPART1REC.CONTFURNMF,
                IOPART1REC.CONTCREDITD,
                IOPART1REC.CONTDEBITD,
                IOPART1REC.CONTLITIGII,
                IOPART1REC.CONTFURNAVS,
                IOPART1REC.CONTFURNAVIC,
                IOPART1REC.CONTFURNAVIN,
								IOPART1REC.contgarantieEF,
                IOPART1REC.contgarantieTF,
                IOPART1REC.contgarantieEC,
                IOPART1REC.contgarantieTC,
                IOPART1REC.CONTTERTI,
                IOPART1REC.TvaNeexF, IOPART1REC.TvaNeexP, IOPART1REC.TvaNeexI,
                IOPART1REC.TVANEEXC,
                IOPART1REC.TIP
               );
         END IF;
       END LOOP;
   END IF;
 END LOOP;


  INSERT INTO TMP_MODURIPLATI(CODMODPLATA, CODIES, TIPPLATA, CODBANKCONT, VALOARE, DENMODPLATA)
              SELECT * FROM MODURIPLATI WHERE CODIES IN (SELECT CODIES FROM TMP_IESIRI);


  INSERT INTO TMP_DISCMONETAR(CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT)
              SELECT
                CODDISCMONETAR, CODIES, PROCTVA, DISCOUNT, TVADISCOUNT
              FROM
                DISCMONETAR
             WHERE
               CODIES IN (SELECT CODIES FROM TMP_IESIRI);


  INSERT INTO TMP_IESDISC (CODIESDISC, CODIES, CODDISCOUNT, OFFINVOICE, PROCENT, CODOBIECT, Valoare, Cumulat)
              SELECT I.*, C.Cumulat FROM IESDISC I,  Discount D, CriteriiDisc C
							WHERE CODIES IN (SELECT CODIES FROM TMP_IESIRI)
							and D.CodDiscount = I.CodDiscount and D.CODCRITERIU = C.CODCRITERIU;

 -- GENERAL
 DELETE TMP_GENERAL;
 INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
 (SELECT CODGENERAL,
         TIPDOC,
         CODDOC,
         MONEDA,
         CURS,
         TVA,
         SEMNIFICATIE,
         ICONTAVANS,
         PROCTVAAVANS
   FROM
       GENERAL G WHERE EXISTS (SELECT CODIES FROM TMP_IESIRI WHERE CODIES = G.CODDOC AND TIPDOC = G.TIPDOC)

 );




-- OBLIGPIF
 DELETE TMP_OBLIGPIF;
 INSERT INTO TMP_OBLIGPIF
 (CODOBLIGPIF,CODGENERAL)
 (SELECT CODOBLIGPIF,CODGENERAL
 FROM
 OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));


 -- STINGERE
   DELETE TMP_STINGERE;
   INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
   (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));


   FOR V_REC IN
   (SELECT
      S.CODSTINGERE,
      G.TIPDOC,
      G.CODDOC,
      G.SEMNIFICATIE
    FROM
      TMP_STINGERE S,
      OBLIGPIF O,
      GENERAL G
    WHERE
     S.CODSTINSPIF = O.CODOBLIGPIF
     AND G.CODGENERAL = O.CODGENERAL
   )LOOP
      aCODSUBUNITSTINS := 0;
      IF V_REC.SEMNIFICATIE IN (210) THEN
        BEGIN
          SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
          WHERE
            CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
          EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
        END;

      UPDATE TMP_STINGERE
      SET
        CODSUBUNITSTINS = aCODSUBUNITSTINS
      WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
      END IF;
    END LOOP;


   FOR V_REC IN
   (SELECT CODIES1
    FROM
      TMP_IESIRI1 I1,
      TMP_IESIRI I
    WHERE
      I.TIPDOC = 26
      AND I1.CODIES = I.CODIES
    )
    LOOP
      UPDATE TMP_IESIRI1 I1
      SET
        CUSTODIE = (SELECT CUSTODIE FROM TMP_IESLINK IL WHERE IL.CODIES1 = I1.CODIES1 AND ROWNUM = 1)
      WHERE
        CODIES1 = V_REC.CODIES1;
    END LOOP;
END;

PROCEDURE EMPTY_DOC_INTERNE_FOR_JURNAL
IS
BEGIN
  DELETE TMP_TRANSF;
  DELETE TMP_TRANSF1;
  DELETE TMP_NIR;
  DELETE TMP_NIRSTOC;

  DELETE TMP_LIVR;
  DELETE TMP_LIVR1;
  DELETE TMP_LIVRTOT;
  DELETE TMP_LIVRVAL;


  --DELETE TMP_JURNAL;
  --DELETE TMP_JURNAL1;
  --DELETE TMP_RULAJ;


  --COMMIT;
END;


PROCEDURE GET_INTERNE_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
NR NUMBER(20, 0) := 0;
LUNAREF      PKG_NOMPART.DESCR_CONT_LUNA_CURSOR;
IOPART1REC   IOPART1 % ROWTYPE;

BEGIN
  EMPTY_DOC_INTERNE_FOR_JURNAL;



  INSERT INTO TMP_TRANSF
  ( CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, SERIADOC, CARNETDOC,
    NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET,
    SUBUNITATEA, REEVALUARE, Corectie
   )
   SELECT
     CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, SERIADOC, CARNETDOC,
     NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC, OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, SUBUNITATEA, REEVALUARE, Corectie
   FROM
   (
     SELECT ROWNUM AS RN, S.* FROM
     (SELECT
        CODTRANSF, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, SERIADOC, CARNETDOC,
         NRDOC, DATADOC, CARNETAE, NRAE, VALDOC, TVADOC,
         OBS, AN, LUNA, VALSUPLIM, CONTSUPLIM, TIPREPSUPLIM, DELEGAT, CODPART, STORNO, TIPMODIFPRET, SUBUNITATEA, REEVALUARE, Corectie
       FROM
         TRANSF  WHERE AN*12+LUNA = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X) AND(IS_DIRTY_DOC(TIPDOC, CODTRANSF) = 1)
       ORDER BY CODTRANSF
     ) S
   )
    WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC;

  INSERT INTO  TMP_TRANSF1
    (CODTRANSF1, CODTRANSF, INDEXLOCAL, TIPLINIE, UMSEC, CODCONT, CODOBIECT, PU, CANT,
     TVA, CodCentru,DENUM, VALOARE, PARITATE, PROCTVA,
     CODTVA,   CODACCIZE, CODTAXA1, CODTAXA2,
     DENOBIECT, CODANALIZANOD
    )
    SELECT * FROM
     (SELECT /*+ cardinality(X,1) */
        T1.CODTRANSF1, T1.CODTRANSF, T1.INDEXLOCAL, TIPLINIE, T1.UMSEC, T1.CODCONT,
        T1.CODOBIECT, T1.PU * U1.PARITATE, T1.CANT/ U1.PARITATE, T1.TVA, t1.CodCentru,
        U1.DEN_UM1, T1.CANT * T1.PU, U1.PARITATE,
        PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU),
        NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE,
        NART1LUNA.CODTAXA1,
        NART1LUNA.CODTAXA2,
        O.DENUMIRE, T1.CODANALIZANOD
      FROM TRANSF1 T1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = T1.CODOBIECT
        LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1 = T1.UMSEC
      WHERE
        EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = T1.CODTRANSF)
     ) ORDER BY INDEXLOCAL;



-- DETAIL LIVR
  INSERT INTO TMP_LIVR
    ( CODLIVR,  CODIES, CODINTR, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT )
    ( SELECT
      CODLIVR,  CODIES, CODINTR, CODTRANSF, CARNETLIVR, NRLIVR, DATALIVR, OBS, TIPLIVR, ANULAT, BLOCAT, OPERAT
      FROM
        LIVR L
      WHERE
        EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF));



-- DETAIL LIVR1

  INSERT INTO  TMP_LIVR1
     ( CODLIVR1,
       CODLIVR,
       CODIES1,
       CODNIRSTOC,
       CANT,
       CODNIRSER,
       PMP,
       UMSEC,
       DENUM,
       PARITATE,
       GEST,
       CODIOART,
       CONTINTERMED,CODPROIECT,
       CODOBIECT,
       DENOBIECT,
       CODLIVRTOT,
       TIPLINIE,
       PRETINREG,
       ADAOS,
       TVANEEX,
       PRETACHIZ,
       TIPSERIE,
       CODSERIE,
       SERIE,
       TG,
       PUMAXIMAL,
       FURN,
       DATAACHIZ,
       TIPDOCACHIZ,
       CODGESTPROD,
       SUBUNITATEA,
       PROVIZION )
     ( SELECT
         L1.CODLIVR1,
         L1.CODLIVR,
         L1.CODIES1,
         L1.CODNIRSTOC,
         L1.CANT / U1.PARITATE,
         L1.CODNIRSER,
         L1.PMP,
         L1.UMSEC,
         U1.DEN_UM1,
         U1.PARITATE,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN N.GEST
           ELSE LV.GEST
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODIOART
           ELSE LV.CODIOART
         END,
         NVL(L1.CONTINTERMED, 0),NVL(L1.CODPROIECT,0),
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.CODOBIECT
           ELSE LV.CODOBIECT
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN PKG_SELECTARTICOLE.GETDENOBIECTEXT(NS.CODOBIECT)
           ELSE PKG_SELECTARTICOLE.GETDENOBIECTEXT(LV.CODOBIECT)
         END,
         0,
         &apos;=&apos;,
         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.PRET * U1.PARITATE
           ELSE LV.PRETINREG * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.ADAOS * U1.PARITATE
           ELSE (LV.PRETINREG - LV.PRETACHIZ) * U1.PARITATE
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TVA
           ELSE LV.TVANEEX
         END,

         CASE
           WHEN LV.CODLIVR1 IS NULL THEN (NS.PRET - NS.ADAOS) * U1.PARITATE
           ELSE LV.PRETACHIZ * U1.PARITATE
         END,


         CASE
           WHEN LV.CODLIVR1 IS NULL THEN NS.TIPSERIE
           ELSE 0
         END,

        (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER),
        (SELECT SERIE FROM NSERII WHERE CODSERIE = (SELECT CODSERIE FROM NIRSER WHERE CODNIRSER = L1.CODNIRSER)),
         NS.TG,
         NS.PUMAXIMAL,
         NS.FURN,
         NS.DATAACHIZ,
         NS.TIPDOCACHIZ,
         NS.CODGESTPROD,
         NS.SUBUNITATEA,
         NS.PROVIZION
       FROM
         LIVR1 L1
         LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
         LEFT OUTER JOIN LIVRVAL LV ON LV.CODLIVR1   = L1.CODLIVR1
         LEFT OUTER JOIN NIR N      ON N.CODNIR      = NS.CODNIR
         LEFT OUTER JOIN LIVR L     ON L.CODLIVR     = L1.CODLIVR,
         NUM1 U1
       WHERE
         CODUM1 = L1.UMSEC AND
         EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF)
         );


-- DETAIL LIVRTOT
  INSERT INTO TMP_LIVRTOT
   (CODLIVRTOT,
    CODLIVR,
    CODIESINT1,
    UMSEC,
    GEST,
    CODIOART,
    CODOBIECT,
    CONTINTERMED,CODPROIECT,
    DENUM,
    PARITATE,
    DENGESTIOART,
    DIFPRET,
    ACCIZELATRANSFER,
    ARETVANEEX,
    MG,
    CONT,
    SUFIXTVANEEX,
    STOCREZOLVAT,
    CANT,
    PRETINREG,
    PRETACHIZ
    )
  SELECT * FROM
     ( SELECT
         0,
         L1.CODLIVR,
         L1.CODIES1,
         L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),NVL(L1.CODPROIECT,0),
         L1.CODOBIECT,
         L1.DENUM,
         L1.PARITATE,
         G.DEN_GEST || CHR(13) || IO.DEN_IOART,
         IOALUNA.DIFPRET,
         IOALUNA.ACCIZELATRANSFER,
         IOALUNA.ARETVANEEX,
         IOALUNA.MG,
         IOALUNA.CONT,
         IOALUNA.TVANEEX,
         1,
         SUM(L1.CANT ),
         SUM(L1.PRETINREG * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT)),
         SUM(L1.PRETACHIZ * L1.CANT) / DECODE(SUM(L1.CANT), 0, 1, SUM(L1.CANT))
       FROM TMP_LIVR1 L1
         CROSS JOIN TMP_PKG_GLOBALS TG
         LEFT OUTER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = L1.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
         LEFT OUTER JOIN LIVR L   ON L.CODLIVR   = L1.CODLIVR
         LEFT OUTER JOIN NGEST G  ON G.CODGEST   = L1.GEST
         LEFT OUTER JOIN IOART IO ON IO.CODIOART = L1.CODIOART
       WHERE
         EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = L.CODTRANSF)
       GROUP BY
         0, L1.CODLIVR, L1.CODIES1, L1.CODOBIECT, L1.UMSEC,
         L1.GEST,
         L1.CODIOART,
         NVL(L1.CONTINTERMED, 0),NVL(L1.CODPROIECT,0),
         L1.DENUM,
         L1.PARITATE , G.DEN_GEST || CHR(13) || IO.DEN_IOART,  IOALUNA.DIFPRET,
         IOALUNA.ACCIZELATRANSFER,
         IOALUNA.ARETVANEEX, IOALUNA.MG,
         IOALUNA.CONT, IOALUNA.TVANEEX
     )
  ORDER BY CODLIVR, CODIES1;


   UPDATE TMP_LIVRTOT T SET
   CODLIVRTOT  = ROWNUM,
   DENOBIECT   = PKG_SELECTARTICOLE.GETDENOBIECTEXT(T.CODOBIECT),
   INDEXMASTER = (SELECT INDEXLOCAL FROM TMP_TRANSF1 WHERE CODTRANSF1 = T.CODIESINT1),
   GESTIMPLICITA = (SELECT GESTIMPLICITA FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT)),
   PROCTVA     = PKG_SELECTARTICOLE.GETPROCENTTVA
                 (PKG_SELECTARTICOLE.GETARTOFOBJECT(T.CODOBIECT), (Select /*+ cardinality(X,1) */ ANLUCRU from TMP_PKG_GLOBALS), (Select /*+ cardinality(X,1) */ LunaLUCRU from TMP_PKG_GLOBALS));



-- DETAIL TMP_LIVRVAL;
   INSERT INTO TMP_LIVRVAL SELECT * FROM LIVRVAL WHERE CODLIVR1 IN (SELECT CODLIVR1 FROM TMP_LIVR1);


-- FAC LEGATURA INTRE LIVR1 SI LIVRTOT
/*
    UPDATE TMP_LIVR1 L1
    SET
    (CODLIVRTOT, GESTIMPLICITA) =
    ( SELECT CODLIVRTOT, GESTIMPLICITA
     FROM TMP_LIVRTOT
      WHERE
        CODLIVR    = L1.CODLIVR  AND
        CODIESINT1 = L1.CODIES1  AND
        UMSEC      = L1.UMSEC    AND
        PARITATE   = L1.PARITATE AND
        GEST       = L1.GEST     AND
        CODIOART   = L1.CODIOART
     );

*/
   MERGE INTO TMP_LIVR1 L1
   USING TMP_LIVRTOT LT
   ON (
                        NVL(LT.CODLIVR, 0)      = NVL(L1.CODLIVR, 0)  AND
                        NVL(LT.CODIESINT1, 0)   = NVL(L1.CODIES1, 0)  AND
                        NVL(LT.UMSEC, 0)        = NVL(L1.UMSEC, 0)    AND
                        NVL(LT.PARITATE, 0)     = NVL(L1.PARITATE, 0) AND
                        NVL(LT.GEST, 0)         = NVL(L1.GEST, 0)     AND
                        NVL(LT.CODIOART, 0)     = NVL(L1.CODIOART, 0) AND
                        NVL(LT.CONTINTERMED, 0) = NVL(L1.CONTINTERMED, 0)
   )
   WHEN MATCHED THEN UPDATE SET
     L1.CODLIVRTOT = LT.CODLIVRTOT,
     L1.GESTIMPLICITA = LT.GESTIMPLICITA;



-- DETAIL NIR
  INSERT INTO  TMP_NIR
    ( CODNIR, CODINTR, CODTRANSF, CARNETNIR, NRNIR, DATANIR, GEST, OBS, TIPNIR, ANULAT, BLOCAT, OPERAT, VALOARE )
    ( SELECT
        N.CODNIR, N.CODINTR,N.CODTRANSF,  N.CARNETNIR, N.NRNIR, N.DATANIR, N.GEST, N.OBS, N.TIPNIR, N.ANULAT, N.BLOCAT, N.OPERAT,
     (SELECT SUM(NS.CANTNIR * NS.PRET) FROM NIRSTOC NS WHERE NS.CODNIR = N.CODNIR)
      FROM NIR N
      WHERE
       EXISTS (SELECT * FROM TMP_TRANSF WHERE CODTRANSF = N.CODTRANSF));


-- DETAIL NIRSTOC
  INSERT INTO  TMP_NIRSTOC
    ( CODNIRSTOC, CODNIR, CODINTR1, CODTRANSF1, CODNIRSTOCPARINTE, FURN, CANTNIR, UMSEC,
      CODOBIECT, CODIOART, PRET, ROTLEI, ROTVALUTA, CODLOCATIE,  PUMAXIMAL, ADAOS, TVA, TIPSERIE,
      CODLIVR1, REST, PROCENTADAOS, Supliment, TG, DATAACHIZ, DENUM, PARITATE, VALOARE, CANTFURN,
      MG, DIFPRET, ACCIZELATRANSFER, ARETVANEEX, PUSTANDARD, PRETACHIZ, PROCTVA,
      DISCLIKISTOC, DENOBIECT, CANTUM1, CANTUM2, UM1, UM2, RelatieUM1, D1,D2,D3, CODGESTPROD, TIPDOCACHIZ,PUVAL, PROVIZION)
    SELECT * FROM
    ( SELECT /*+ cardinality(X,1) */
        NS.CODNIRSTOC, NS.CODNIR,  NS.CODINTR1, NS.CODTRANSF1, NS.CODNIRSTOCPARINTE, NS.FURN, NS.CANTNIR / U1.PARITATE, NS.UMSEC,
        NS.CODOBIECT, NS.CODIOART, NS.PRET * U1.PARITATE, NS.ROTLEI, NS.ROTVALUTA, NS.CODLOCATIE, NS.PUMAXIMAL * U1.PARITATE, NS.ADAOS * U1.PARITATE, NS.TVA, NS.TIPSERIE,
        NS.CODLIVR1, NS.REST, NS.PROCENTADAOS, NS.Supliment, NS.TG, NS.DATAACHIZ, U1.DEN_UM1, U1.PARITATE, NS.CANTNIR * NS.PRET, NS.CANTFURN / U1.PARITATE,
--      (NS.CANTNIR + NVL((SELECT SUM(DIFERENTA) FROM NIR1 WHERE CODNIRSTOC = NS.CODNIRSTOC), 0)) / U1.PARITATE,
        IOALUNA.MG, IOALUNA.DIFPRET, IOALUNA.ACCIZELATRANSFER, IOALUNA.ARETVANEEX, IOALUNA.PUSTANDARD,
        (NS.PRET - NS.ADAOS -
        CASE
          WHEN NVL(NS.CANTNIR, 0) = 0 THEN 0
          ELSE NVL(NS.SUPLIMENT, 0) /(NS.CANTNIR / U1.PARITATE)
        END) * u1.Paritate,

        PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU),
        DISCLIKISTOC,
        O.DENUMIRE,
        NS.CANTUM1,
        NS.CANTUM2,
        A.UM1,
        A.UM2,
        A.RelatieUM1,
        NS.D1,
        NS.D2,
        NS.D3,
        NS.CODGESTPROD,
        NS.TIPDOCACHIZ,
        NS.PUVAL,
        NS.PROVIZION
      FROM NIRSTOC NS
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT OUTER JOIN IOART1 IOALUNA ON IOALUNA.CODIOART = NS.CODIOART AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN IOALUNA.ALSTART AND IOALUNA.ALSTOP
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
        LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL,
        NUM1 U1
      WHERE
        NS.CODNIR IN (SELECT CODNIR FROM TMP_NIR) AND U1.CODUM1 = NS.UMSEC
      )
     ORDER BY CODNIR, CODINTR1;
end;


PROCEDURE SETZERORECORDS
IS
NR NUMBER (20);
BEGIN
  -- ANALIZA
  SELECT COUNT(*) INTO Nr FROM ANALIZA WHERE CodANALIZA = 0;
  IF Nr = 0 THEN
    INSERT INTO ANALIZA (CodANALIZA, DEN_ANALIZA) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ANALIZA SET den_ANALIZA = &apos;... nedefinit ...&apos; WHERE codANALIZA = 0;
  END IF;

  -- ELEMENTE
  SELECT COUNT(*) INTO Nr FROM ELEMENTE WHERE CodELEMENT = 0;
  IF Nr = 0 THEN
    INSERT INTO ELEMENTE (CodELEMENT, DEN_ELEMENT) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ELEMENTE SET den_ELEMENT = &apos;... nedefinit ...&apos; WHERE codELEMENT = 0;
  END IF;

  --ELEMBUGET
  SELECT COUNT(*) INTO Nr FROM ELEMBUGET WHERE CodELEMBUGET = 0;
  IF Nr = 0 THEN
    INSERT INTO ELEMBUGET (CodELEMBUGET, ELEMENT, SIMBOL) VALUES (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ELEMBUGET SET ELEMENT = &apos;... nedefinit ...&apos;, simbol = &apos;... nedefinit ...&apos; WHERE codELEMBUGET = 0;
  END IF;

  -- NART
  SELECT COUNT(*) INTO Nr FROM NART WHERE CodARTICOL = 0;
  IF Nr = 0 THEN
    INSERT INTO NART (CodARTICOL, DEN_ARTICOL) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE nart SET den_articol = &apos;... nedefinit ...&apos; WHERE codarticol = 0;
  END IF;

  -- NARTOBJ
  SELECT COUNT(*) INTO Nr FROM NARTOBJ WHERE CodOBIECT = 0;
  IF Nr = 0 THEN
    INSERT INTO NARTOBJ (CodOBIECT, CodARTICOL, DENUMIRE ) VALUES (0, 0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE nartObj SET denumire = &apos;... nedefinit ...&apos; WHERE codobiect = 0;
  END IF;

  -- FUNCTII
  SELECT COUNT(*) INTO Nr FROM FUNCTII WHERE CodFUNCTIE = 0;
  IF Nr = 0 THEN
    INSERT INTO FUNCTII (CodFUNCTIE, DENUMIRE ) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE FUNCTII SET denumire = &apos;... nedefinit ...&apos; WHERE codFUNCTIE = 0;
  END IF;
  -- PROIECT
  SELECT COUNT(*) INTO Nr FROM PROIECT WHERE CODPROIECT = 0;
  IF Nr = 0 THEN
    INSERT INTO PROIECT (CODPROIECT, CODOBIECTPROD, VERSIUNE ) values (0, 0, &apos;... nedefinit ...&apos;);

	ELSE
	  UPDATE PROIECT SET CODOBIECTPROD=0, VERSIUNE  =&apos;... nedefinit ...&apos; WHERE CODPROIECT = 0;
  END IF;

  -- PRODCOMP
  SELECT COUNT(*) INTO Nr FROM PRODCOMP WHERE CODPRODCOMP = 0;
  IF Nr = 0 THEN
    INSERT INTO PRODCOMP (CODPRODCOMP, CODOBIECT, OBS) values (0, 0, &apos;... nedefinit ...&apos;);

	ELSE
	  UPDATE PRODCOMP SET CODOBIECT=0, OBS =&apos;... nedefinit ...&apos; WHERE CODPRODCOMP = 0;
  END IF;
  SELECT COUNT(*) INTO Nr FROM PRODCOMP WHERE CODPRODCOMP = 1;
  IF Nr = 0 THEN
    INSERT INTO PRODCOMP (CODPRODCOMP, CODOBIECT, OBS) values (1, 0, &apos;... consum nedefinit...&apos;);

	ELSE
	  UPDATE PRODCOMP SET CODOBIECT=0, OBS =&apos;... consum nedefinit ...&apos; WHERE CODPRODCOMP = 1;
  END IF;
  -- GRECHIV
  SELECT COUNT(*) INTO Nr FROM GRECHIV WHERE CODGRECHIV = 0;
  IF Nr = 0 THEN
    INSERT INTO GRECHIV (CODGRECHIV, DENUMIRE) values (0, &apos;... nedefinita ...&apos;);

	ELSE
	  UPDATE GRECHIV SET DENUMIRE =&apos;... nedefinita ...&apos; WHERE CODGRECHIV = 0;
  END IF;

  -- SCENARIILIVR
  SELECT COUNT(*) INTO Nr FROM SCENARIILIVR WHERE CODSCENARIU = 0;
  IF Nr = 0 THEN
    INSERT INTO SCENARIILIVR (CODSCENARIU, DEN_SCENARIU) values (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE SCENARIILIVR SET DEN_SCENARIU =&apos;... nedefinit ...&apos; WHERE CODSCENARIU = 0;
  END IF;

  -- NTAXE
  SELECT COUNT(*) INTO Nr FROM NTAXE WHERE CodTAXA = 0;
  IF Nr = 0 THEN
    INSERT INTO NTAXE (CodTAXA, Den_TAXA) values (0, &apos;... nedefinita ...&apos;);
	ELSE
	  UPDATE ntaxe SET den_taxa =&apos;... nedefinita ...&apos; WHERE codtaxa = 0;
  END IF;

  -- activitati
  SELECT COUNT(*) INTO Nr FROM NActivit WHERE CODACTIVIT = 0;
  IF Nr = 0 THEN
    INSERT INTO nactivit (CODACTIVIT, DEN_ACTIVIT) values (0, &apos;... nedefinita ...&apos;);
	ELSE
	  UPDATE NActivit SET den_activit =&apos;... nedefinita ...&apos; WHERE codactivit = 0;
  END IF;

  -- formatii
  SELECT COUNT(*) INTO Nr FROM formatii WHERE CodFormatie = 0;
  IF Nr = 0 THEN
    INSERT INTO formatii (CodFormatie, Den_Formatie, simbol, codgest) values (0, &apos;... nedefinita ...&apos;, &apos;...&apos;, 0);
	ELSE
	  UPDATE formatii SET den_Formatie =&apos;... nedefinita ...&apos; WHERE codFormatie = 0;
  END IF;

  -- prestatii
  SELECT COUNT(*) INTO Nr FROM prestatii WHERE Codprestatie = 0;
  IF Nr = 0 THEN
    INSERT INTO prestatii (Codprestatie, cod, denumire) values (0, &apos;... nedefinit ...&apos;, &apos;...nedefinit...&apos;);
	ELSE
	  UPDATE prestatii SET cod =&apos;... nedefinit ...&apos;, denumire =&apos;... nedefinit ...&apos; WHERE codprestatie = 0;
  END IF;

  -- NTIPSEDII
  SELECT COUNT(*) INTO Nr FROM NTIPSEDII WHERE CODTIPSEDIU = 0;
  IF Nr = 0 THEN
    INSERT INTO NTIPSEDII (CODTIPSEDIU, DENUMIRE) values (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ntipsedii SET denumire = &apos;... nedefinit ...&apos;	WHERE codtipsediu = 0;
  END IF;


  -- NCLASEA
  SELECT COUNT(*) INTO Nr FROM NCLASEA WHERE CodClaseA = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseA (CodClaseA, Den_Clasea, Simbol) values (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
	  UPDATE nclasea SET
		       den_clasea =&apos;... nedefinit ...&apos;,
					 simbol    =&apos;... nedefinit ...&apos;
		WHERE codclasea = 0;
  END IF;

  -- NCLASEAS
  SELECT COUNT(*) INTO Nr FROM NCLASEAS WHERE CodCLASEAS = 0;
  IF Nr = 0 THEN
    INSERT INTO NCLASEAS (CodCLASEAS, Den_CLASEAS, Simbol) values (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
	  UPDATE nCLASEAS SET
		       den_CLASEAS =&apos;... nedefinit ...&apos;,
					 simbol    =&apos;... nedefinit ...&apos;
		WHERE codCLASEAS = 0;
  END IF;

  -- NCLASEPROD
  SELECT COUNT(*) INTO Nr FROM NCLASEPROD WHERE CodClaseProd = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseProd (CodClaseProd, Den_ClaseProd, Simbol) values (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
	  UPDATE nclaseprod SET
		       den_claseprod =&apos;... nedefinit ...&apos;,
					 simbol    =&apos;... nedefinit ...&apos;
		WHERE codclaseprod = 0;
  END IF;

  -- NCLASEP
  SELECT COUNT(*) INTO Nr FROM NCLASEP WHERE CodClaseP = 0;
  IF Nr = 0 THEN
    INSERT INTO NClaseP (CodClaseP, Den_ClaseP, Simbol) values (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
	  UPDATE nclasep SET
		   den_clasep = &apos;... nedefinit ...&apos;,
			 simbol     = &apos;... nedefinit ...&apos;
		WHERE codclasep = 0;
	END IF;

  -- NCLASEG
	SELECT COUNT(*) INTO nr FROM nclaseg WHERE codclaseg = 0;
	IF nr = 0 THEN
	  INSERT INTO nclaseg (codclaseg,den_claseg,simbol)VALUES (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE nclaseg SET
		    den_claseg = &apos;... nedefinit ...&apos;,
				simbol     = &apos;... nedefinit ...&apos;
		WHERE codclaseg = 0;
	END IF;
	-- NPART
  SELECT COUNT(*) INTO Nr FROM NPART WHERE CodPART = 0;
  IF Nr = 0 THEN
    INSERT INTO NPART (CodPART, DEN_PART) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE npart SET den_part = &apos;... nedefinit ...&apos; WHERE codpart = 0;
  END IF;

  -- NPERS
  SELECT COUNT(*) INTO Nr FROM NPERS WHERE CodPERS = 0;
  IF Nr = 0 THEN
    INSERT INTO NPERS (CodPERS, NUME, PRENUME) VALUES (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
	  UPDATE npers SET
	    nume    = &apos;... nedefinit ...&apos;,
			prenume = &apos;... nedefinit ...&apos;
	 	WHERE codpers = 0;
	END IF;

  -- NGEST
  SELECT COUNT(*) INTO Nr FROM NGEST WHERE CodGEST = 0;
  IF Nr = 0 THEN
    INSERT INTO NGEST (CodGEST, DEN_GEST) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ngest SET den_gest = &apos;... nedefinit ...&apos; WHERE codgest = 0;
  END IF;

  -- IOART
  SELECT COUNT(*) INTO Nr FROM IOART WHERE CodIOART = 0;
  IF Nr = 0 THEN
    INSERT INTO IOART (CodIOART, DEN_IOART) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ioart SET den_ioart = &apos;... nedefinit ...&apos; WHERE codioart = 0;
  END IF;

  -- IOPART
  SELECT COUNT(*) INTO Nr FROM IOPART WHERE CodIOPART = 0;
  IF Nr = 0 THEN
    INSERT INTO IOPART (CodIOPART, DEN_IOPART) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE iopart SET den_iopart = &apos;... nedefinit ...&apos; WHERE codiopart = 0;
  END IF;

  -- IOPERS
  SELECT COUNT(*) INTO Nr FROM IOPERS WHERE CodIOPERS = 0;
  IF Nr = 0 THEN
    INSERT INTO IOPERS (CodIOPERS, DEN_IOPERS) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE iopers SET den_iopers = &apos;... nedefinit ...&apos; WHERE codiopers = 0;
  END IF;

  -- IOBANK
  SELECT COUNT(*) INTO Nr FROM IOBANK WHERE CodIOBANK = 0;
  IF Nr = 0 THEN
    INSERT INTO IOBANK (CodIOBANK, DEN_IOBANK) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE iobank SET den_iobank = &apos;... nedefinit ...&apos; WHERE codiobank = 0;
  END IF;

  -- NTVA
  SELECT COUNT(*) INTO Nr FROM NTVA WHERE CodTVA = 0;
  IF Nr = 0 THEN
    INSERT INTO NTVA (CodTVA, DEN_TVA) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE ntva SET den_tva = &apos;... nedefinit ...&apos; WHERE codtva = 0;
  END IF;

  -- NMONEDE
  SELECT COUNT(*) INTO Nr FROM NMONEDE WHERE CodMONEDA = 0;
  IF Nr = 0 THEN
    INSERT INTO NMONEDE (CodMONEDA, Den_MONEDA, Simbol) values (0, &apos;Lei&apos;, &apos;RON&apos;);
  ELSE
	  UPDATE nmonede SET
	         den_moneda = &apos;Lei&apos;,
					 simbol     = &apos;RON&apos;
		WHERE codmoneda = 0;
  END IF;

  --NTARI
	 SELECT COUNT(*) INTO NR FROM NTARI WHERE CODTARA = 0 ;
	 IF NR = 0 THEN
	  INSERT INTO NTARI(CODTARA,DEN_TARA) VALUES(0,&apos;...nedefinita...&apos;);
	 ELSE
	  UPDATE ntari SET den_tara = &apos;... nedefinita ...&apos;	WHERE codtara = 0;
	 END IF;

	-- njudet
	SELECT COUNT(*) INTO NR FROM NJUDET WHERE CODJUDET = 0;
	IF NR = 0 THEN
	  INSERT INTO NJUDET(CODJUDET,DEN_JUDET,CODTARA) VALUES(0,&apos;...nedefinit...&apos;,0);
	ELSE
	  UPDATE njudet SET
		       den_judet = &apos;... nedefinit ...&apos;,
					 codtara   = 0
		WHERE codjudet = 0;
	END IF;

	--nzone
	SELECT COUNT(*) INTO NR FROM NZONE WHERE CODZONA = 0;
	IF NR = 0 THEN
	  INSERT INTO NZONE (CODZONA,DEN_ZONA) VALUES(0,&apos;...nedefinita...&apos;);
	ELSE
	  UPDATE nzone SET den_zona = &apos;... nedefinita ...&apos;	WHERE codzona = 0;
	END IF;

	-- NLOCALIT
  SELECT COUNT(*) INTO Nr FROM NLOCALIT WHERE CODLOCALIT = 0;
  IF Nr = 0 THEN
    INSERT INTO NLOCALIT (codlocalit,DEN_LOCALIT,CODJUDET,CODZONA) VALUES (0,&apos;...nedefinita...&apos;,0,0);
  END IF;

    -- NBANK
  SELECT COUNT(*) INTO Nr FROM NBANK WHERE CodBANK = 0;
  IF Nr = 0 THEN
    INSERT INTO NBANK (CodBANK, DENUMIRE, SIMBOL) values (0, &apos;... nedefinita ...&apos;, &apos;...&apos;);
	ELSE
	  UPDATE nbank SET
		       DENUMIRE = &apos;... nedefinita ...&apos;	,
					 simbol   = &apos;...&apos;
		WHERE codbank = 0;
  END IF;

    -- NCONT
  SELECT COUNT(*) INTO Nr FROM NCONT WHERE CodCONT = 0;
  IF Nr = 0 THEN
    INSERT INTO NCONT (CodCONT, DEN_CONT, SIMBOL, CLASA, TIPCONT) values (0, &apos;... nedefinit ...&apos;, &apos;...&apos;, 0, 0);
  ELSE
	  UPDATE ncont SET
		       DEN_CONT = &apos;... nedefinit ...&apos;,
					 SIMBOL   = &apos;...&apos;,
					 CLASA    = 0,
					 TIPCONT  = 0
		WHERE codcont = 0;

	END IF;

  SELECT COUNT(*) INTO Nr FROM NCONTS WHERE CodCONTS = 0;
  IF Nr = 0 THEN
    INSERT INTO NCONTS (CodCONTS, DEN_CONT, SIMBOL, CLASA, TIPCONT) values (0, &apos;... nedefinit ...&apos;, &apos;...&apos;, 0, 0);
  ELSE
	  UPDATE ncontS SET
		       DEN_CONT = &apos;... nedefinit ...&apos;,
					 SIMBOL   = &apos;...&apos;,
					 CLASA    = 0,
					 TIPCONT  = 0
		WHERE codconts = 0;

	END IF;

	SELECT  COUNT(*) INTO nr FROM ncontt WHERE codcontt = 0;
    IF nr = 0 THEN
        INSERT INTO ncontt ( codcontt, den_cont, simbol, clasa, tipcont ) VALUES ( 0, &apos;... nedefinit ...&apos;, &apos;...&apos;, 0, 0);
    ELSE
        UPDATE ncontt  SET
            den_cont = &apos;... nedefinit ...&apos;,
                simbol = &apos;...&apos;,
                clasa = 0,
                tipcont = 0
        WHERE
            codcontt = 0;
    END IF;

    -- NCATPRET
  SELECT COUNT(*) INTO Nr FROM NCATPRET WHERE CODCATPRET = 0;
  IF Nr = 0 THEN
    INSERT INTO NCATPRET (CODCATPRET, DEN_CATPRET, TIP, SIMBOL)
    VALUES (0, &apos;... nedefinit ...&apos;, 0, &apos;...&apos;);
	ELSE
	  UPDATE ncatpret SET
		       DEN_CATPRET = &apos;... nedefinit ...&apos; ,
					 TIP         = 0,
					 SIMBOL 	   =&apos;...&apos;
		WHERE codcatpret = 0;
  END IF;


  -- NSUBUNIT
  SELECT COUNT(*) INTO NR FROM NSUBUNIT WHERE CODSUBUNIT = 0;
  IF NR = 0 THEN
    INSERT INTO NSUBUNIT (CODSUBUNIT, DEN_SUBUNIT) VALUES (0, &apos;... nedefinita ...&apos;);
	ELSE
	  UPDATE nsubunit SET den_subunit = &apos;... nedefinita ...&apos; WHERE codsubunit = 0;
  END IF;

  SELECT COUNT(*) INTO NR FROM NSUBUNIT WHERE CODSUBUNIT = 1;
  IF NR = 0 THEN
    INSERT INTO NSUBUNIT (CODSUBUNIT, DEN_SUBUNIT) VALUES (1, &apos;Cumulat Firma&apos;);
	ELSE
	  UPDATE nsubunit SET den_subunit = &apos;Cumulat Firma&apos; WHERE codsubunit = 1;
  END IF;


  -- NUM
  SELECT COUNT(*) INTO Nr FROM NUM WHERE CodUM = 0;
  IF Nr = 0 THEN
    INSERT INTO NUM (CodUM, DEN_UM) VALUES (0, &apos;......&apos;);
	ELSE
	  UPDATE num SET den_um = &apos;......&apos; WHERE codum = 0;
  END IF;
-- NUM1
  SELECT COUNT(*) INTO Nr FROM NUM1 WHERE CodUM1 = 0;
  IF Nr = 0 THEN
    INSERT INTO NUM1 (COdUM1, CODUM, SECUNDARA, PARITATE, DEN_UM1) VALUES (0, 0, 0, 1, &apos;.....&apos;);
	ELSE
	  UPDATE num1 SET
		       CODUM      = 0,
					 SECUNDARA  = 0,
					 PARITATE   = 1,
					 DEN_UM1    = &apos;.....&apos;
		WHERE codum1 = 0;
  END IF;

-- NLOCATII
  SELECT COUNT(*) INTO nr FROM nlocatii WHERE CODLOCATIE = 0;
	IF NR = 0 THEN
	  INSERT INTO NLOCATII (CODLOCATIE,CODGEST,DENUMIRE) VALUES (0,0,&apos;...nedefinita...&apos;);
	ELSE
	  UPDATE nlocatii SET
	         codgest = 0 ,
				   denumire = &apos;...nedefinita...&apos;
		WHERE codlocatie  = 0;
	END IF;

-- NAGENDA
  SELECT COUNT(*) INTO NR FROM NAGENDA WHERE CODAGENDA = 0;

	IF NR = 0 THEN
	 insert into nagenda (codagenda,codlocalit,codpart,codgest) values(0,0,0,0);
	ELSE
	 UPDATE nagenda SET
	        codlocalit = 0,
					codpart    = 0,
					codgest    = 0
		WHERE codagenda = 0;
	END IF;

SELECT COUNT(*) INTO nr FROM nparcaut WHERE CODnparcaut = 0;
	IF NR = 0 THEN
	  insert into nparcaut (codnparcaut, nrinreg, codart, nrinv) values (0, &apos;..nedefinit..&apos;, 0, 0);
	ELSE
	  UPDATE nparcaut SET
	         codart  = 0 ,
				   nrinreg = &apos;..nedefinit..&apos;,
           nrinv   = 0
		WHERE codnparcaut  = 0;
	END IF;

-- TRASEULIVR
  SELECT COUNT(*) INTO nr FROM TraseuLivr WHERE CodTraseuLivr = 0;
  IF nr = 0 THEN
    INSERT INTO TraseuLivr(CodTraseuLivr, DenTraseu, SimbolTraseu) VALUES (0, &apos;..nedefinit..&apos;, &apos;..nedefinit..&apos;);
  ELSE
    UPDATE TraseuLivr SET DenTraseu = &apos;..nedefinit..&apos;, SimbolTraseu = &apos;..nedefinit..&apos; WHERE CodTraseuLivr = 0;
  END IF;

  SELECT COUNT(*) INTO nr FROM TraseuLivr WHERE CodTraseuLivr = 1;
  IF nr = 0 THEN
    INSERT INTO TraseuLivr(CodTraseuLivr, DenTraseu, SimbolTraseu) VALUES (1, &apos;TRANSPORT ASIGURAT DE CLIENT&apos;, &apos;TAC&apos;);
  ELSE
    UPDATE TraseuLivr SET DenTraseu = &apos;TRANSPORT ASIGURAT DE CLIENT&apos;, SimbolTraseu = &apos;TAC&apos; WHERE CodTraseuLivr = 1;
  END IF;

-- SETLISTE DE PE WINMADMIN , PRIND EXCEPTIA CA POATE NU ISI ACTUALIZEAZA BAIETII SKEMA SERVICE SI SA NU O IA IN BALARII
 BEGIN
    SELECT COUNT(*) INTO nr FROM winmadmin.Setliste WHERE codset = 0;
		 IF nr = 0 THEN
		  INSERT INTO winmadmin.setliste (codset,denumire) VALUES (0,&apos;Set Baza&apos;);
		 ELSE
		  UPDATE winmadmin.Setliste SET
			  denumire = &apos;Set Baza&apos;
			WHERE codset = 0;
		 END IF;

		SELECT COUNT(*) INTO nr FROM winmadmin.Setliste WHERE codset = 1;
		 IF nr = 0 THEN
		  INSERT INTO winmadmin.setliste (codset,denumire) VALUES (1,&apos;Set General&apos;);
		 ELSE
		  UPDATE winmadmin.Setliste SET
			  denumire = &apos;Set General&apos;
			WHERE codset = 1;
		 END IF;
	EXCEPTION WHEN OTHERS THEN
    insert into x(test)  values(&apos;exceptie&apos;);
    commit;
  END;

-- CRITERIIDISC
  SELECT COUNT(*) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 9;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC(CODCRITERIU,
    DENCRITERIU,EXCLUDVOLTR, EXCLUDCANTFACT, EXCLUDTERMEN, EXCLUDVALDOC, EXCLUDDISTANTA, PECLASE, CUMULAT)
    VALUES (9, &apos;Facturi in baza comenzii&apos;, 0, 0, 0, 0, 0, 0, 0);
  END IF;

  SELECT COUNT(*) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 10;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC(CODCRITERIU,
    DENCRITERIU,EXCLUDVOLTR, EXCLUDCANTFACT, EXCLUDTERMEN, EXCLUDVALDOC, EXCLUDDISTANTA, PECLASE, CUMULAT)
    VALUES (10, &apos;Transport asigurat de client&apos;, 0, 0, 0, 0, 0, 0, 0);
  END IF;


  SELECT COUNT(*) INTO Nr FROM CRITERIIDISC WHERE CODCRITERIU = 11;
  IF Nr = 0 THEN
    INSERT INTO CRITERIIDISC(CODCRITERIU,
    DENCRITERIU,EXCLUDVOLTR, EXCLUDCANTFACT, EXCLUDTERMEN, EXCLUDVALDOC, EXCLUDDISTANTA, PECLASE, CUMULAT)
    VALUES (11, &apos;Zi de nastere&apos;, 0, 0, 0, 0, 0, 0, 0);
  END IF;


-- CENTRECOST
 SELECT COUNT(*) INTO NR FROM CENTRECOST WHERE CODCENTRU = 0;
 IF NR = 0 THEN
   INSERT INTO CENTRECOST(CODCENTRU,SIMBOL,DENUMIRE) VALUES (0,&apos;... nedefinit ...&apos;,&apos;... nedefinit ...&apos;);
 ELSE
  UPDATE CENTRECOST SET
   SIMBOL   = &apos;... nedefinit ...&apos;,
   DENUMIRE = &apos;... nedefinit ...&apos;
  WHERE CODCENTRU = 0;
 END IF;

-- CARDURI
 SELECT COUNT(*) INTO NR FROM CARDURI WHERE CODCARD = 0;
 IF NR = 0 THEN
   INSERT INTO CARDURI(CODCARD,SIMBOL,DENUMIRE) VALUES (0,&apos;... nedefinit ...&apos;,&apos;... nedefinit ...&apos;);
 ELSE
  UPDATE CARDURI SET
   SIMBOL   = &apos;... nedefinit ...&apos;,
   DENUMIRE = &apos;... nedefinit ...&apos;
  WHERE CODCARD = 0;
 END IF;

-- NCASEMARCAT
 SELECT COUNT(*) INTO NR FROM NCASEMARCAT WHERE CODCASEMARCAT = 0;
 IF NR = 0 THEN
   INSERT INTO NCASEMARCAT(CODCASEMARCAT, DENUMIRE) VALUES (0, &apos;... nedefinita ...&apos;);
 END IF;

-- Descriptori
 SELECT COUNT(*) INTO NR FROM DESCRIPTORI WHERE CODDESCRIPTOR = 0;
 IF NR = 0 THEN
   INSERT INTO DESCRIPTORI(CODDESCRIPTOR,SIMBOL,DEN_DESCRIPTOR, TIP) VALUES (0,&apos;-&apos;,&apos;... nedefinit ...&apos;,0);
 ELSE
  UPDATE DESCRIPTORI SET
   SIMBOL   = &apos;-&apos;,
   DEN_DESCRIPTOR = &apos;... nedefinit ...&apos;
  WHERE CODDESCRIPTOR = 0;
 END IF;

  -- NLIMBA
  SELECT COUNT(*) INTO NR FROM NLIMBA WHERE CodLimba = 0;
  IF NR = 0 THEN
    INSERT INTO NLIMBA
      (CodLimba, DenLimba, CodTara, ExtLink)
    VALUES
      (0, &apos;... nedefinit ...&apos;, 0, &apos;--&apos;);
  ELSE
    UPDATE NLIMBA SET
      DenLimba = &apos;... nedefinit ...&apos;,
      CodTara = 0,
      ExtLink = &apos;--&apos;
    WHERE CodLimba = 0;
  END IF;

  -- MESERII
  SELECT COUNT(*) INTO NR FROM NMESERII WHERE CODMESERIE = 0;
  IF NR = 0 THEN
      INSERT INTO NMESERII (CODMESERIE, DEN_MESERIE) VALUES (0, &apos;... nedefinit ...&apos;);
  ELSE
    UPDATE NMESERII SET DEN_MESERIE = &apos;... nedefinit ...&apos; WHERE CODMESERIE = 0;
  END IF;

  -- CURSURI
  SELECT COUNT(*) INTO NR FROM CURSURI WHERE CODCURS = 0;
  IF NR = 0 THEN
    INSERT INTO CURSURI (CODCURS, DEN_CURS) VALUES (0, &apos;... nedefinit ...&apos;);
  ELSE
    UPDATE CURSURI SET DEN_CURS = &apos;... nedefinit ...&apos; WHERE CODCURS = 0;
  END IF;

  -- FORMATORI
  SELECT COUNT(*) INTO NR FROM FORMATORI WHERE CODFORMATOR = 0;
  IF NR = 0 THEN
      INSERT INTO FORMATORI (CODFORMATOR, DEN_FORMATOR, TELEFON, EMAIL, CODPERS) VALUES (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;,0);
  ELSE
    UPDATE FORMATORI SET DEN_FORMATOR = &apos;... nedefinit ...&apos; WHERE CODFORMATOR = 0;
  END IF;

  -- TEME
  SELECT COUNT(*) INTO NR FROM TEME WHERE CODTEMA = 0;
  IF NR = 0 THEN
    INSERT INTO TEME (CODTEMA, DEN_TEMA, ORE, PRET, CODFORMATOR) VALUES (0, &apos;... nedefinit ...&apos;, 0, 0, 0);
  ELSE
    UPDATE TEME SET DEN_TEMA = &apos;... nedefinit ...&apos; WHERE CODTEMA = 0;
  END IF;

  -- FUNCTII
  SELECT COUNT(*) INTO NR FROM FUNCTII WHERE CODFUNCTIE = 0;
  IF NR = 0 THEN
      INSERT INTO FUNCTII (CODFUNCTIE, DENUMIRE, CODEXTERN) VALUES (0, &apos;... nedefinit ...&apos;,0);
  ELSE
    UPDATE FUNCTII SET DENUMIRE = &apos;... nedefinit ...&apos; WHERE CODFUNCTIE = 0;
  END IF;

  -- CONCURENTI
  SELECT COUNT(*) INTO NR FROM CONCURENTI WHERE CodConcurent = 0;
  IF NR = 0 THEN
    INSERT INTO CONCURENTI
      (CodConcurent, DenConcurent)
    VALUES
      (0, &apos;... nedefinit ...&apos;);
  ELSE
    UPDATE CONCURENTI SET
      DenConcurent = &apos;... nedefinit ...&apos;
    WHERE CodConcurent = 0;
  END IF;

  -- CAMPANII
  SELECT COUNT(*) INTO NR FROM CAMPANII WHERE CodCampanie = 0;
  IF NR = 0 THEN
    INSERT INTO CAMPANII
      (CodCampanie, DenCampanie, Obiectiv, Target)
    VALUES
      (0, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;, &apos;... nedefinit ...&apos;);
  ELSE
    UPDATE CAMPANII SET
      DenCampanie = &apos;... nedefinit ...&apos;,
      Obiectiv = &apos;... nedefinit ...&apos;,
      Target = &apos;... nedefinit ...&apos;
    WHERE CodCampanie = 0;
  END IF;

  -- CERTIFICATE
  SELECT COUNT(*) INTO NR FROM CERTIF WHERE CodCertif = 0;
  IF NR = 0 THEN
    begin
    INSERT INTO CERTIF
      (CodCertif, NrCertif, CodObiect)
    VALUES
      (0, &apos;... nedefinit ...&apos;, 0);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  ELSE
    UPDATE CERTIF SET
      NrCertif = &apos;... nedefinit ...&apos;
    WHERE CodCertif = 0;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 101;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (101, &apos;I (M)&apos;, &apos;D1&apos;, 0.9, &apos;Drumuri asfaltate in stare buna (beton asfaltic, macadan asfaltic, macadan cu tratament dublu, balast bituminat, beton ciment).&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 102;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (102, &apos;II (K)&apos;, &apos;D2&apos;, 1, &apos;Drumuri pavate (cu calupuri, cu pavele normale sau abnorme) in stare buna. Drumuri macadamizate si impietruite in stare buna.&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 103;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (103, &apos;III (T)&apos;, &apos;D3&apos;, 1.1, &apos;Drumuri asfaltate, pavate, macadamizate si impietruite in stare mediocra, care impun schimbari de viteza pe cca.20% din parcurs. Drumuri de pamant si terasamente in stare buna. Drumuripavate cu piatra bruta, bolovani de rau si nisipate, in&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 104;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (104, &apos;IV (L)&apos;, &apos;D4&apos;, 1.2, &apos;Drumuri impietruite cu piatra sparta, pietris sau macadamizate si pavate cu piatra si bolovani de rau , in stare mediocra. Drumuri de categoria K si T cu declivitati ce impun scimbari de viteza pe cca.40% din parcurs.&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 105;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (105, &apos;V (E)&apos;, &apos;D5&apos;, 1.4, &apos;Drumuri a caror stare impune schimbari de viteza pe cca.70% din parcurs. Drumuri de pamant si terasamente, in stare mediocra. Drumuri pavate cu bolovani de rau sau cu piatra in stare rea.&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  SELECT COUNT(*) INTO NR FROM GRUPEDRUM WHERE CODGRUPA = 106;
  IF NR = 0 THEN
    begin
      INSERT INTO GRUPEDRUM (CODGRUPA, DENUMIRE, SIMBOL, COEF, DESCRIERE)
      VALUES (106, &apos;VI (H)&apos;, &apos;D6&apos;, 1.6, &apos;Toate celelalte drumuri cu o stare de viabilitate sau care prezinta declivitati ce nu permit circulatia cu viteze mai mari de 15  km/ora pe toata lungimea lor.&apos;);
    exception when others then insert into x(test)  values(&apos;exceptie&apos;);
    commit;
    end;
  END IF;

  -- NGAMEART
  SELECT COUNT(*) INTO Nr FROM NGAMEART WHERE CodGama = 0;
  IF Nr = 0 THEN
    INSERT INTO NGAMEART (CodGama, DENUMIRE) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE NGAMEART SET DENUMIRE = &apos;... nedefinit ...&apos; WHERE codGAMA = 0;
  END IF;

  -- TIPCHELT
  SELECT COUNT(*) INTO Nr FROM TIPCHELT WHERE CodTipChelt = 0;
  IF Nr = 0 THEN
    INSERT INTO TIPCHELT (CodTipChelt, DENUMIRE) VALUES (0, &apos;... nedefinit ...&apos;);
	ELSE
	  UPDATE TIPCHELT SET DENUMIRE = &apos;... nedefinit ...&apos; WHERE CodTipChelt = 0;
  END IF;

  -- TVAServ
  SELECT COUNT(*) INTO NR FROM TVAServ WHERE CODTVASERV = 0;
  IF NR = 0 THEN
    INSERT INTO TVASERV(CODTVASERV,DENUMIRE, CODCONT, SIMBOL) values (0, &apos;...nedefinit...&apos;, 0, &apos;...nedefinit...&apos;);
  END IF;

  -- TarifeMan
  SELECT COUNT(*) INTO NR FROM TARIFEMAN WHERE CODTARIF = 0;
  IF NR = 0 THEN
    INSERT INTO TARIFEMAN(CODTARIF,DENUMIRE) values (0, &apos;...nedefinit...&apos;);
  END IF;

  -- NOPER
  SELECT COUNT(*) INTO NR FROM NOPER WHERE CODOP = 0;
  IF NR = 0 THEN
    INSERT INTO NOPER(CODOP, DENUMIRE) values (0, &apos;...nedefinit...&apos;);
  END IF;

  -- TIPLUCRARISA
  SELECT COUNT(*) INTO NR FROM TIPLUCRARISA WHERE CODTIPLUCRARE = 0;
  IF NR = 0 THEN
    INSERT INTO TIPLUCRARISA(CODTIPLUCRARE, DENUMIRE) values (0, &apos;...nedefinit...&apos;);
  END IF;

  -- efcustom
  SELECT COUNT(*) INTO NR FROM EFCUSTOM WHERE CODEFCUSTOM = 0;
  IF NR = 0 THEN
    INSERT INTO EFCUSTOM(CODEFCUSTOM,DEN_EFCUSTOM) values (0, &apos;...nedefinit...&apos;);
  END IF;

  SELECT COUNT ( *) INTO Nr FROM nbankcont WHERE codbankcont = 0;
  IF Nr = 0 THEN
    INSERT INTO nbankcont (codbankcont, DEN_cont) VALUES (0, &apos;... nedefinit ...&apos;);
  ELSE
    UPDATE nbankcont SET DEN_cont = &apos;... nedefinit ...&apos; WHERE codbankcont = 0;
  END IF;

  COMMIT;
END;

PROCEDURE EMPTY_DOCUMENTE_FOR_CHELTAVANS
IS
BEGIN
  DELETE TMP_CHELTAVANS;
  DELETE TMP_CHELTAVANS1;
END;

FUNCTION GET_CHELTAVANS_RECORDCOUNT(flg_ISVENIT IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
 BEGIN
     SELECT  COUNT(*) INTO NR  FROM
        CHELTAVANS AV
        LEFT OUTER JOIN TMP_IOART_LUNA IOL  ON IOL.CODIOART = AV.CODIOART,
        CHELTAVANS1 AV1
     WHERE
       NVL(AV.ISVENIT, 0) = flg_ISVENIT
       AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS AND
       AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
			 AND (IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1)
       AND
       (
         EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
         OR
         EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = TO_CHAR(IOL.CONT))
       );
      EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;


PROCEDURE GET_CHELTAVANS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER, flg_ISVENIT IN NUMBER)
IS
NR NUMBER(20, 0) := 0;
BEGIN
  EMPTY_DOCUMENTE_FOR_CHELTAVANS;


  INSERT INTO TMP_CHELTAVANS
  (
     CODCHELTAVANS,
     CODINTR1,
     ANINCEPUT,
     LUNAINCEPUT,
     CODIOART,
     CODGEST,
     DEN_GEST,
     CODSUBUNIT,
     NRDOC,
     DEN_PART,
     OBS,
     PREFIXDOC,
     SERIADOC,
     DATASTART,
     DATAEND,
     TIPINTERVAL, IsVenit
   )
   (
   SELECT
     CODCHELTAVANS,
     CODINTR1,
     ANINCEPUT,
     LUNAINCEPUT,
     CODIOART,
     CODGEST,
  	 DEN_GEST,
     SUBUNITATEA,
     NRDOC,
     DEN_PART,
     OBS,
     PREFIXDOC,
     SERIADOC,
     DATASTART,
     DATAEND,
     0, IsVenit
   FROM
   (
   SELECT ROWNUM RN, S.* FROM
   (
      SELECT  CHELTAV.*
      FROM
      (
       SELECT
         AV.CODCHELTAVANS,
         AV.CODINTR1,
         AV.CODOBLIGPIF,
         AV.CODNC1,
         AV.ANINCEPUT,
         AV.LUNAINCEPUT,
         AV.CODIOART,
         G.CODGEST,
         G.DEN_GEST,
         I.SUBUNITATEA,
         I.NRDOC,
         P.DEN_PART,
         I1.OBS,
         I.PREFIXDOC,
         I.SERIADOC,
         AV.DATASTART,
         AV.DATAEND, AV.IsVenit
       FROM
         CHELTAVANS AV
         LEFT JOIN TMP_IOART_LUNA IOL  ON IOL.CODIOART = AV.CODIOART,
         CHELTAVANS1 AV1,
         INTRARI I,
         INTRARI1 I1
         LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT,
         NPART P
       WHERE
         NVL(AV.ISVENIT, 0) = flg_ISVENIT
         AND AV1.CODCHELTAVANS = AV.CODCHELTAVANS
         AND I1.CODINTR1 = AV.CODINTR1
         AND I.CODINTR = I1.CODINTR
         AND AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
				 AND(PKG_SERVICE.IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1)
         AND P.CODPART = I.PARTENER
         AND
          (
            EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
            OR
           EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = TO_CHAR(IOL.CONT))
          )

       UNION ALL

       SELECT
         AV.CODCHELTAVANS,
         AV.CODINTR1,
         AV.CODOBLIGPIF,
         AV.CODNC1,
         AV.ANINCEPUT,
         AV.LUNAINCEPUT,
         AV.CODIOART,
         G.CODGEST,
         G.DEN_GEST,
         I.SUBUNITATEA,
         I.NRDOC,
         P.DEN_PART,
         I1.OBS,
         I.PREFIXDOC,
         I.SERIADOC,
         AV.DATASTART,
         AV.DATAEND, AV.IsVenit
       FROM
         CHELTAVANS AV
         LEFT JOIN TMP_IOART_LUNA IOL  ON IOL.CODIOART = AV.CODIOART,
         CHELTAVANS1 AV1,
         IESIRI I
         LEFT JOIN NPART P ON P.CODPART = I.PARTENER AND I.TIPDOC IN (19, 20, 21, 26),
         IESIRI1 I1
         LEFT JOIN NGEST G ON G.CODGEST = I1.GESTACT
--       NPART P
       WHERE
          NVL(AV.ISVENIT, 0) = flg_ISVENIT
          AND AV1.CODCHELTAVANS = AV.CODCHELTAVANS
          AND I1.CODIES1 = AV.CODIES1
          AND I.CODIES= I1.CODIES
          AND AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
				  AND(PKG_SERVICE.IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1)
--        AND P.CODPART = I.PARTENER
         AND
         (
           EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
           OR
           EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = TO_CHAR(IOL.CONT))
         )

         UNION ALL


         SELECT
           AV.CODCHELTAVANS,
           AV.CODINTR1,
           AV.CODOBLIGPIF,
           AV.CODNC1,
           AV.ANINCEPUT,
           AV.LUNAINCEPUT,
           AV.CODIOART,
           O.CODGEST,
           NG.DEN_GEST,
           T.SUBUNITATEA,
           T1.NRDOC,
           NULL AS DEN_PART,
           T1.OBS,
           T1.DOC,
           NULL AS SERIADOC,
           AV.DATASTART,
           AV.DATAEND, AV.IsVenit
         FROM
           CHELTAVANS AV
           LEFT JOIN TMP_IOART_LUNA IOL  ON IOL.CODIOART = AV.CODIOART,
           CHELTAVANS1 AV1,
           OBLIGPIF O
           LEFT JOIN NGEST NG ON NG.CODGEST = O.CODGEST,
           GENERAL G,
           TREZOR1 T1,
           TREZOR T
         WHERE
           NVL(AV.ISVENIT, 0) = flg_ISVENIT
           AND AV1.CODCHELTAVANS = AV.CODCHELTAVANS
           AND O.CODOBLIGPIF = AV.CODOBLIGPIF
           AND G.CODGENERAL  = O.CODGENERAL
           AND T1.CODTREZOR1 = G.CODDOC
           AND T.CODTREZOR   = T1.CODTREZOR
--         AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
           AND
             (
               EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
               OR
               EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = TO_CHAR(IOL.CONT))
             )
           AND AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
					AND(PKG_SERVICE.IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1)

         UNION ALL

         SELECT
           AV.CODCHELTAVANS,
           AV.CODINTR1,
           AV.CODOBLIGPIF,
           AV.CODNC1,
           AV.ANINCEPUT,
           AV.LUNAINCEPUT,
           AV.CODIOART,
           N1.CODGEST,
           NG.DEN_GEST,
           N.SUBUNITATEA,
           N.NRDOC,
           NULL AS DEN_PART,
           N1.OBS,
           &apos;NC&apos; AS DOC,
           NULL AS SERIADOC,
           AV.DATASTART,
           AV.DATAEND, AV.IsVenit
         FROM
           CHELTAVANS AV
           LEFT JOIN TMP_IOART_LUNA IOL  ON IOL.CODIOART = AV.CODIOART,
           CHELTAVANS1 AV1,
           NC1 N1
           LEFT JOIN NGEST NG ON NG.CODGEST = N1.CODGEST,
           NC N
         WHERE
           NVL(AV.ISVENIT, 0) = flg_ISVENIT
           AND AV1.CODCHELTAVANS = AV.CODCHELTAVANS
           AND N1.CODNC1     = AV.CODNC1
           AND N.CODNC       = N1.CODNC
--            AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
           AND
           (
             EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(IOL.CONT))
             OR
             EXISTS (SELECT CONTVENITAVANS FROM TMP_CONTVENITAVANS WHERE CONTVENITAVANS = TO_CHAR(IOL.CONT))
           )
           AND AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
					AND(PKG_SERVICE.IS_DIRTY_DOC(52, AV.CODCHELTAVANS, 106) = 1)
       ) CHELTAV
       ORDER BY CODCHELTAVANS
     ) S
    )
     WHERE RN &gt;= STARTREC AND RN &lt;= ENDREC
     );

     INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA)
     SELECT CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODGEST, CODANALIZANOD, DATAENDNOUA, DATAENDBLOCATA FROM CHELTAVANS1 AV1
     WHERE
       AV1.ANSTART * 12 + AV1.LUNASTART = (Select /*+ cardinality(X,1) */ ANLUCRU*12+LUNALUCRU from TMP_PKG_GLOBALS X)
       AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);
/*
  UPDATE TMP_CHELTAVANS
  SET
    TIPINTERVAL = 1
  WHERE
    DATASTART IS NOT NULL
    AND
    DATAEND IS NOT NULL;
*/

  UPDATE TMP_CHELTAVANS C
  SET
    TIPINTERVAL = 1
  WHERE
    DATASTART IS NOT NULL
    AND
  (
    DATAEND IS NOT NULL
    OR (SELECT COUNT(*) FROM TMP_CHELTAVANS1 C1 WHERE C1.CODCHELTAVANS = C.CODCHELTAVANS AND DATAENDNOUA IS NOT NULL) &gt; 0
  );

  FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1)
  LOOP
    IF V_REC.DATAENDNOUA IS NOT NULL THEN
      UPDATE TMP_CHELTAVANS
      SET
        DATAEND = V_REC.DATAENDNOUA
      WHERE
        CODCHELTAVANS = V_REC.CODCHELTAVANS;
    END IF;
  END LOOP;


END;

PROCEDURE GET_REGTREZOR_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 		REG1CONT_IDX_LOCAL NUMBER(10) := 0;
   REG1_IDX_LOCAL     NUMBER(20);
 	 PARAM_REG_DATA     DATE;
 	 PARAM_REG_MONEDA   NUMBER(20);
	 PARAM_REG_CURS     NUMBER(20,7);
   DIFERENTE          number(1) := 0;
   DATANEXTREG        DATE;
   CODNEXTREG         NUMBER(20);
   AnPrecedentReg     NUMBER(20);
   LunaPrecedentaReg  NUMBER(20);
BEGIN
  EMPTY_DOCUMENTE_FOR_REGTREZOR;
-- REG
		  DELETE FROM TMP_REG;
    INSERT INTO TMP_REG (CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST, CodCentru, CodAnalizaNod)
    SELECT /*+ cardinality(X,1) */
		CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty, Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, An, Luna, CODGEST, CodCentru, CodAnalizaNod
    FROM
    (SELECT ROWNUM RN, R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty, R.Obs, R.CodSubunit, M.Simbol AS SIMBOLMONEDA, B.Simbol AS SIMBOLBANK, R.Provizion, R.An, R.Luna, R.CODGEST, R.CodCentru, R.CodAnalizaNod
     FROM TMP_PKG_GLOBALS X,REG R
       LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
       LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
     WHERE
        TIPREG = 45
        AND AN = X.ANLUCRU
        AND LUNA = X.LUNALUCRU
        AND(IS_DIRTY_DOC(45, R.CODREG) = 1)
      )
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;



    DELETE FROM TMP_REGTREZOR1;

    FOR V_REC_MARE IN (SELECT * FROM TMP_REG)
    LOOP

      DELETE TMP_REGTREZOR1_MARTOR;
      INSERT INTO TMP_REGTREZOR1_MARTOR(CODBANKCONT, SOLDDOCVAL)
      SELECT CODBANKCONT, SOLDDOCVAL FROM REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;



  		  SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM DUAL;

  	  	PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);

		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
   		PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
   		PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
   		PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);

   		INSERT INTO TMP_REGTREZOR1
   		  (
   		    CODREG,
         CodRegTrezor1,
     				SoldDoc,
   		  		SoldDocVal,
   				  SoldDocReg,
   				  CodBank,
   				  CodBankCont,
   				  Diferenta,
   				  Den_Cont,
   				  NrCont,
   				  Filiala,
   				  Credit,
         SUBUNITATEA
   			)
   		  (
   			  SELECT
   				  V_REC_MARE.CODREG,
         -1 * ROWNUM,
   					 T1.SoldValuta,
   					 T1.SoldLei,
   					 T1.SoldValuta * PKG_REG.GetCursReg,
   					 NBC.CodBank,
   					 T1.CodBankCont,
   					 T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei,
   					 NBC.Den_Cont,
   					 NBC.NrCont,
   					 NBC.Filiala,
   					 NBC.Credit,
         NBC.SUBUNITATEA
   				FROM
   				(
        SELECT
   					  SoldValuta,
     						SoldLei,
   		 			  CodBankCont
        FROM
   					  V_SOLDURIBANCILUNA
            ) T1
   				 INNER JOIN NBANKCONT NBC ON NBC.CodBankCont = T1.CodBankCont AND NVL(NBC.FARAREG, 0) = 0
   				 WHERE
   				   NBC.CodMoneda = PKG_REG.GetMonedaReg AND
   					 T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
   			 );




  -- VERIFIC DIFERENTELE APARUTE FATA DE ULTIMA REGULARIZARE
      DIFERENTE :=0;
      FOR V_REC IN
       (
         SELECT  INTBL.CODBANKCONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT
         FROM
           TMP_REGTREZOR1_MARTOR INTBL
           LEFT OUTER JOIN TMP_REGTREZOR1 OUTTBL ON OUTTBL.CODBANKCONT = INTBL.CODBANKCONT
         WHERE
           OUTTBL.CODREG = V_REC_MARE.CODREG
         UNION
         SELECT  OUTTBL.CODBANKCONT,
                 INTBL.SOLDDOCVAL SOLDIN,
                 OUTTBL.SOLDDOCVAL SOLDOUT
         FROM
           TMP_REGTREZOR1 OUTTBL
           LEFT OUTER JOIN TMP_REGTREZOR1_MARTOR INTBL ON INTBL.CODBANKCONT = OUTTBL.CODBANKCONT
         WHERE
           OUTTBL.CODREG = V_REC_MARE.CODREG
         )
       LOOP
          IF NVL(V_REC.SOLDIN, 0) &lt;&gt; NVL(V_REC.SOLDOUT, 0) THEN
            DIFERENTE := 1;
            EXIT;
          END IF;
        END LOOP;

        IF DIFERENTE = 1 THEN
          DELETE REGTREZOR1 WHERE CODREG = V_REC_MARE.CODREG;
          INSERT INTO REGTREZOR1 (CodRegTrezor1, CodReg, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont)
            (SELECT SEQ_REGTREZOR1_CODREGTREZOR1.NEXTVAL, V_REC_MARE.CODREG, SoldDoc, SoldDocVal, SoldDocReg, CodBank, CodBankCont
            FROM TMP_REGTREZOR1 WHERE CODREG =  V_REC_MARE.CODREG);

        END IF;

     END LOOP;
END;

PROCEDURE GET_REGPERS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
 	REG1CONT_IDX_LOCAL  NUMBER(10) := 0;
   REG1_IDX_LOCAL     NUMBER(20);
 	 PARAM_REG_DATA     DATE;
 	 PARAM_REG_MONEDA   NUMBER(20);
   PARAM_REG_CURS     NUMBER(20,7);
   DIFERENTE          number(1) := 0;
   DATANEXTREG        DATE;
   CODNEXTREG         NUMBER(20);
   AnPrecedentReg     NUMBER(20);
   LunaPrecedentaReg  NUMBER(20);
   ATIPCONT           NUMBER(5) := 0;
   ASEMN              NUMBER(2) := 1;

BEGIN
  EMPTY_DOCUMENTE_FOR_REGPERS;
-- REG
	 DELETE FROM TMP_REG;

   INSERT INTO TMP_REG
      (
        CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty,
        Obs, CodSubunit, SimbolMoneda, SimbolBank, Provizion, Luna, An, CODGEST, CodCentru, CodAnalizaNod
      )
    SELECT
        CodReg, TipReg, NrDoc, DataDoc, CodBank, CodMoneda, Curs, Dirty,
        Obs, CodSubunit, SimbolMoneda, SimbolBAnk, Provizion, Luna, An, CODGEST, CodCentru, CodAnalizaNod
    FROM
      (
        SELECT /*+ cardinality(X,1) */
          ROWNUM RN,
          R.CodReg, R.TipReg, R.NrDoc, R.DataDoc, R.CodBank, R.CodMoneda, R.Curs, R.Dirty,
          R.Obs, R.CodSubunit, M.Simbol SimbolMoneda, B.Simbol SIMBOLBANK, R.Provizion, R.Luna, R.An, R.CODGEST, R.CodCentru, R.CodAnalizaNod
        FROM
          TMP_PKG_GLOBALS X,REG R
          LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
          LEFT OUTER JOIN NBANK B ON B.CODBANK = R.CODBANK
        WHERE
          TIPREG = 47
          AND AN = X.ANLUCRU
          AND LUNA = X.LUNALUCRU
          AND(IS_DIRTY_DOC(47, R.CODREG) = 1)
      )
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;

    DELETE TMP_REGPERS1;
    DELETE TMP_SOLDPERS_SUB;

   -- folosesc manevra TMP_SOLDPERS pentru ca trebuie sa interpretez semnului soldului in functie de TIPUL CONTULUI
    INSERT INTO TMP_SOLDPERS_SUB
    (CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA)

    SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, SUBUNITATEA FROM V_SOLDPERS_TRANZACTII_SUB;

     FOR V_REC IN
     (
      SELECT /*+ cardinality(X,1) */ * FROM TMP_SOLDPERS_SUB S, TMP_PKG_GLOBALS X
     )
     LOOP
       BEGIN
         SELECT NVL(TIPCONT, 0) INTO ATIPCONT FROM NCONT WHERE CODCONT = PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, V_REC.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(V_REC.CODPERS, V_REC.ANLUCRU,  V_REC.LUNALUCRU));
         EXCEPTION WHEN OTHERS THEN aTIPCONT := 0;
       END;

       IF NVL(aTIPCONT, 0) = 1 THEN aSEMN := -1;
       ELSE
       aSEMN := 1;
       END IF;

       UPDATE TMP_SOLDPERS_SUB
       SET
        SEMN  = aSEMN
       WHERE
         CODPERS = V_REC.CODPERS
         AND CODMONEDA = V_REC.CODMONEDA
         AND ICONT = V_REC.ICONT;
     END LOOP;




    FOR V_REC_MARE IN (SELECT * FROM TMP_REG)
    LOOP
       DELETE TMP_REGPERS1_MARTOR;

       INSERT INTO TMP_REGPERS1_MARTOR(CODPERS, SOLDDOCVAL, ICONT)
       SELECT CODPERS, SOLDDOCVAL, ICONT
       FROM REGPERS1
         WHERE CODREG = V_REC_MARE.CODREG;


  		 SELECT V_REC_MARE.DataDoc, V_REC_MARE.CodMoneda, V_REC_MARE.Curs INTO PARAM_REG_DATA, PARAM_REG_MONEDA, PARAM_REG_CURS FROM DUAL;

  	   PKG_REG.SetParamsReg(TO_CHAR(PARAM_REG_DATA, &apos;DD.MM.YYYY&apos;), PARAM_REG_MONEDA, PARAM_REG_CURS);

		-- setez LUNATEMP si ANTEMP din PKG_GLOBALS, folosite in V_SOLDURIBANCILUNA
   		 PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU);
   		 PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU, AnPrecedentReg, LunaPrecedentaReg);
   		 PKG_GLOBALS.SETLUNAPRECEDENTA(AnPrecedentReg, LunaPrecedentaReg);


     		INSERT INTO TMP_REGPERS1
      	  (
       	    CodRegPers1,
            CODREG,
            SoldDoc,
            SoldDocVal,
            SoldDocReg,
            CodPers,
            CodCont,
            ICONT,
            SUBUNITATEA,
            Diferenta,
            Den_Pers,
            Den_Cont
      		)

      SELECT  -1 * ROWNUM,
              V_REC_MARE.CODREG,
              SOLDVALUTA,
              SOLDLEI,
              SoldValuta * PKG_REG.GetCursReg,
              CodPers,
              CodCont,
              ICONT,
              SUBUNITATEA,
      				SoldValuta * PKG_REG.GetCursReg - SoldLei,
              Prenume || &apos; &apos; || Nume,
              Den_Cont
      FROM
     (
      SELECT /*+ cardinality(X,1) */
        T1.CODPERS,
        SOLDVALUTA,
        SOLDLEI,
        NUME,
        ICONT,
        SUBUNITATEA,
        PRENUME,
        PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS,  X.ANLUCRU, X.LUNALUCRU))) AS DEN_CONT,
        PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T1.CODPERS, X.ANLUCRU, X.LUNALUCRU)) AS CODCONT
      FROM
      TMP_PKG_GLOBALS X,(
          SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVALUTA) SOLDVALUTA
          FROM
          (
            SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, NVL(SOLDLEI,0) * NVL(SEMN, 1) SOLDLEI , NVL(SOLDVALUTA,0) * NVL(SEMN, 1) SOLDVALUTA
            FROM
              TMP_SOLDPERS_SUB

              UNION ALL

             SELECT CODPERS, ICONT, CODMONEDA,SUBUNITATEA,  SOLDLEI, SOLDVALUTA
              FROM
               V_SOLDPERS_PREC_SUB
           )
           GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA
        ) T1,
          NPERS NP
        WHERE
          NP.CodPers = T1.CodPers
          AND CODMONEDA = PKG_REG.GetMonedaReg
          AND	T1.SoldValuta * PKG_REG.GetCursReg - T1.SoldLei &lt;&gt; 0
        );
   END LOOP;

END;

PROCEDURE GET_REGOSS_FOR_JURNAL(STARTREC IN NUMBER, ENDREC IN NUMBER)
IS
  	REG1CONT_IDX_LOCAL  NUMBER(10) := 0;
   REG1_IDX_LOCAL     NUMBER(20);
 	 PARAM_REG_DATA     DATE;
 	 PARAM_REG_MONEDA   NUMBER(20);
   PARAM_REG_CURS     NUMBER(20,7);
   DIFERENTE          number(1) := 0;
   DATANEXTREG        DATE;
   CODNEXTREG         NUMBER(20);
   AnPrecedentReg     NUMBER(20);
   LunaPrecedentaReg  NUMBER(20);
   ATIPCONT           NUMBER(5) := 0;
   ASEMN              NUMBER(2) := 1;

BEGIN
   EMPTY_DOCUMENTE_FOR_REGOSS;

   INSERT INTO TMP_REGOSS
      (CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,SIMBOLMONEDA)
    SELECT
       CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,SIMBOLMONEDA
			FROM
      (
        SELECT /*+ cardinality(X,1) */
          ROWNUM RN,
          CODREGOSS,TIPREG,NRDOC,DATADOC,TRIMESTRUL,r.CODMONEDA,CURS,DIRTY,OBS,CODSUBUNIT,AN,LUNA,CODGEST,CODANALIZANOD,CODCENTRU,m.SIMBOL SIMBOLMONEDA
        FROM
          TMP_PKG_GLOBALS X,REGOSS R
          LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = R.CODMONEDA
        WHERE
          TIPREG = 108
          AND AN = X.ANLUCRU
          AND LUNA = X.LUNALUCRU
          AND(IS_DIRTY_DOC(108, R.CODREGOSS) = 1)
      )
     WHERE
       RN &gt;= STARTREC AND RN &lt;= ENDREC;
    FOR V_REC in (Select * from TMP_REGOSS)
		loop
				INSERT INTO TMP_REGOSS1
					(CODREGOSS1,
					 CODREGOSS,
					 CODDOC,
					 TIPDOC,
					 TVADOCVAL,
					 TVADOC,
					 TVADOCREG,
					 CODGEST,
					 CONT,
					 SEMN,
					 CURS,
					 SEMNIFICATIE,
					 DIFERENTA,
					 CODPART,
					 DEN_PART,
					 DOC,
					 SUBUNITATEA)
					select rs1.CODREGOSS1,
								 rs1.CODREGOSS,
								 rs1.CODDOC,
								 rs1.TIPDOC,
								 rs1.TVADOCVAL,
								 rs1.TVADOC,
								 rs1.TVADOCREG,
								 rs1.CODGEST,
								 rs1.CONT,
								 rs1.SEMN,
								 rs1.CURS,
								 rs1.SEMNIFICATIE,
								 rs1.TVADOCREG - rs1.TVADOCVAL,
								 part.codpart,
								 part.den_part,
								 ies.seriadoc||&apos; &apos;||ies.nrdoc||&apos;/&apos;||to_char(ies.datadoc, &apos;dd.mm.yyyy&apos;) as doc,
								 ies.subunitatea
						from REGOSS1 rs1
						join iesiri ies on ies.codies = rs1.coddoc
						join npart part on part.codpart = ies.partener
				where rs1.CODREGOSS = v_rec.CODREGOSS;
    end loop;
END;



PROCEDURE REPARTIZARE_SOLDURI_RULAJE(aSUBUNIT IN NUMBER)
IS
 ANI   NUMBER(5) := 0;
 LUNAI NUMBER(2) := 0;
 NR    NUMBER(5) := 0;
BEGIN
  SELECT ANINITIAL, LUNAINITIALA INTO ANI, LUNAI FROM FIRMALUNI;
  FOR V_REC IN  (SELECT * FROM NCONTSOLD WHERE AN = ANI AND LUNA = 1)
  LOOP
    DELETE FROM NCONTSOLDSUB WHERE CODCONTSOLD = V_REC.CODCONTSOLD;
    INSERT INTO NCONTSOLDSUB(CODCONTSOLDSUB, CODCONTSOLD, SUBUNITATEA, SOLDID, SOLDIC, SOLDVID, SOLDVIC,
    SOLDI_IFRS, SOLDVI_IFRS,
    SOLDI_GRUP, SOLDVI_GRUP
    )
    VALUES (SEQ_NCONTSOLDSUB_CODSOLDSUB.NEXTVAL, V_REC.CODCONTSOLD, aSUBUNIT, V_REC.SOLDID, V_REC.SOLDIC, V_REC.SOLDVID, V_REC.SOLDVIC,
    V_REC.SOLDI_IFRS, V_REC.SOLDVI_IFRS,
    V_REC.SOLDI_GRUP, V_REC.SOLDVI_GRUP
    );
  END LOOP;

  FOR V_REC IN  (SELECT * FROM NCONTRUL WHERE AN = ANI AND LUNA = LUNAI)
  LOOP
    UPDATE NCONTRULSUB
    SET
      RULAJPD      = 0,
      RULAJPC      = 0,
      RULAJVPD     = 0,
      RULAJVPC     = 0,
      RULAJP_IFRS  = 0,
      RULAJVP_IFRS = 0,
      RULAJP_GRUP  = 0,
      RULAJVP_GRUP = 0
    WHERE
      CODCONTRUL = V_REC.CODCONTRUL;

    SELECT COUNT(*) INTO NR FROM NCONTRULSUB
    WHERE
      CODCONTRUL = V_REC.CODCONTRUL
      AND SUBUNITATEA = aSUBUNIT;

    IF NR = 0 THEN
      INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, SUBUNITATEA, RULAJPD, RULAJPC,RULAJVPD, RULAJVPC, RULAJCD, RULAJCC,RULAJVCD, RULAJVCC,
      RULAJP_IFRS, RULAJVP_IFRS, RULAJC_IFRS, RULAJVC_IFRS,
      RULAJP_GRUP, RULAJVP_GRUP, RULAJC_GRUP, RULAJVC_GRUP
      )
      VALUES (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC.CODCONTRUL,  aSUBUNIT,  V_REC.RULAJPD,  V_REC.RULAJPC, V_REC.RULAJVPD,  V_REC.RULAJVPC, 0, 0, 0, 0,
      V_REC.RULAJP_IFRS, V_REC.RULAJVP_IFRS, 0, 0,
      V_REC.RULAJP_GRUP, V_REC.RULAJVP_GRUP, 0, 0
      );
    ELSE
      UPDATE NCONTRULSUB
      SET
        RULAJPD      = V_REC.RULAJPD,
        RULAJPC      = V_REC.RULAJPC,
        RULAJVPD     = V_REC.RULAJVPD,
        RULAJVPC     = V_REC.RULAJVPC,
        RULAJP_IFRS  = NVL(V_REC.RULAJP_IFRS, 0),
        RULAJVP_IFRS = NVL(V_REC.RULAJVP_IFRS, 0),
        RULAJP_GRUP  = NVL(V_REC.RULAJP_GRUP, 0),
        RULAJVP_GRUP = NVL(V_REC.RULAJVP_GRUP, 0)
      WHERE
       CODCONTRUL = V_REC.CODCONTRUL AND SUBUNITATEA = aSUBUNIT;

    END IF;
  END LOOP;
END;

PROCEDURE ACT_STOC_MEDIU IS
NR NUMBER(20);
BEGIN
 FOR V_REC IN (SELECT DISTINCT CODOBIECT ,CODSUBUNIT ,STOCMEDIUSUBUNIT FROM TMP_ACT_STOCMED) LOOP


   SELECT COUNT(*) INTO NR FROM NARTOBJSUBUNIT WHERE CODOBIECT = V_REC.CODOBIECT
                                                     AND (codgest is null or codgest = 0)
                                                     AND SUBUNITATE = V_REC.CODSUBUNIT;
   IF NR = 0 THEN
     INSERT INTO NARTOBJSUBUNIT(CODS,CODOBIECT,SUBUNITATE,STOCMED) VALUES
       (SEQ_NARTOBJSUBUNIT_CODS.NEXTVAL,V_REC.CODOBIECT,V_REC.CODSUBUNIT,V_REC.STOCMEDIUSUBUNIT);
   ELSE
     UPDATE NARTOBJSUBUNIT SET STOCMED = V_REC.STOCMEDIUSUBUNIT WHERE CODOBIECT = V_REC.CODOBIECT
                                                                AND (codgest is null or codgest = 0)
                                                                AND SUBUNITATE = V_REC.CODSUBUNIT;
  END IF;

 END LOOP;
 COMMIT;
END;
PROCEDURE GET_IESIRI_FOR_COEFDISCMAJ(aAN NUMBER, aLUNA NUMBER)
IS
BEGIN

   EMPTY_DOCUMENTE_FOR_JURNAL;
   -- IESIRI --
  INSERT INTO TMP_IESIRI
  ( CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
    NRDOC, DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
    ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED,
    --NUMEDELEGAT,
    MONEDA,
    TIPCHELT,
    TipTVA,
    CURS,
    SUBUNITATEA,
    INFOCM,
    CONTSUPLIM,
    CUSTODIE,
    TVAIncasare,
    DataTVA,
    TIPTRANZACTIE )

    SELECT
      CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, CARNETDOC,
      NRDOC,  DATADOC, PARTENER, CODSUBUNIT, CARNETAE, NRAE, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CONTDISCOUNT,
      ACCIZE, DELEGAT, AGENT, MAJORARI, OBS, AN, LUNA, CODFISCAL, SERIADOC, BUGETARE, CODLOCATIE, TIPFACTURA, CODGESTPROD, CONTINTERMED,
      --NUMEDELEGAT,
      MONEDA, TIPCHELT, TipTVA,
      CURS, SUBUNITATEA, INFOCM, CONTSUPLIM, CUSTODIE, TVAIncasare, DataTVA, TIPTRANZACTIE
    FROM
       IESIRI I
       WHERE
         AN*12+LUNA = aAN * 12 + aLUNA
         AND TIPDOC IN (19, 20, 26)
         AND OPERAT = 1 AND ANULAT = 0
      ORDER BY  CODIES;

--    update tmp_iesiri e
--     set e.TotDiscOffInvoiceC = (select Sum(Nvl(d.Procent, 0)) from Iesdisc d where d.CodIes = E.CodIes and d.OffInvoice = 2),
 --        e.TotDiscOffInvoiceF = (select Sum(Nvl(d.Procent, 0)) from Iesdisc d where d.CodIes = E.CodIes and d.OffInvoice = 3);

  DELETE IESIRI1_MAN;
  INSERT INTO IESIRI1_MAN SELECT * FROM IESIRI1 I1
   WHERE
     EXISTS (SELECT * FROM TMP_IESIRI WHERE CODIES = I1.CODIES);

-- IESIRI1 --
  INSERT INTO TMP_IESIRI1
    (CODIES1,  CODIES,    INDEXLOCAL,  TIPLINIE,       UMSEC,
     CodCentru,CONTSERV, GESTACT,   CODOBIECT,   PRETORIG,       PU,
     CANT,     TVA,       CONT,        PROCDISC,       ADDIM,
     RESTFACT, PUMAXIMAL, GARANTIE,    DENUM,          VALOARE,
     PARITATE, PROCTVA,   CODOBLIGSTORNO, CURSFACTURAAVANS, TipLivrare,    CUSTODIEINTRARE,
     CODTVA,   CODACCIZE, CODTAXA1,    CODTAXA2, CODCMDINT1,
     DENOBIECT, SIMBOLCONTSERV, CONTDISCOUNT,CODANALIZANOD, MIFIX, CODMIFIX, ICONTPART, TAXA
    )
    SELECT * FROM
     (SELECT /*+ cardinality(X,1) */
        I1.CODIES1,  I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC,
        i1.CodCentru,I1.CONTSERV, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG * NVL(U1.PARITATE,1), I1.PU * NVL(U1.PARITATE,1),
        I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM,
        I1.RESTFACT,
        I1.PUMAXIMAL, I1.GARANTIE,
        CASE
          WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
          ELSE U1.DEN_UM1
        END,
        (
         CASE
           WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
           ELSE I1.RESTFACT
         END
        ),
        U1.PARITATE,

        CASE
          WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, TG.ANLUCRU, TG.LUNALUCRU)
          ELSE 0
        END,
        I1.CODOBLIGSTORNO,
        I1.CURSFACTURAAVANS,
        I1.TipLivrare,
        I1.CUSTODIEINTRARE,
        NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE,
        NART1LUNA.CODTAXA1,
        NART1LUNA.CODTAXA2,
        I1.CODCMDINT1,
        O.DENUMIRE,
        CASE
          WHEN TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) AND nvl(I1.CODOBIECT,0) = 0 THEN &apos;(&apos; || C.SIMBOL || &apos;)&apos;
          WHEN TIPLINIE IN (&apos;S&apos;, &apos;V&apos;) THEN &apos;(&apos; || PKG_PLANCONTURI.GETSIMBOLCONT(I1.CONTSERV) || &apos;)&apos;
          ELSE &apos;&apos;
        END,
        I1.CONTDISCOUNT,
        I1.CODANALIZANOD,
        I1.MIFIX,
        I1.CODMIFIX, I1.ICONTPART, I1.TAXA
      FROM IESIRI1_MAN I1
        CROSS JOIN TMP_PKG_GLOBALS TG
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
        LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND TG.ANLUCRU*12+TG.LUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
        LEFT OUTER JOIN NCONT C ON C.CODCONT = I1.CONTDISCOUNT
     )
     ORDER BY CODIES, INDEXLOCAL;

     UPDATE TMP_IESIRI1 I1
     SET NRDOCLINK =
      (SELECT II.PREFIXDOC || TO_CHAR(II.NRDOC)
       FROM
         IESLINK IL
         LEFT OUTER JOIN IESIRI1 II1 ON II1.CODIES1 = IL.CODLINIEAVIZ
         LEFT OUTER JOIN IESIRI  II ON II.CODIES    = II1.CODIES
       WHERE
         IL.CODIES1 = I1.CODIES1)
      WHERE
      I1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;) AND NVL((SELECT TIPDOC FROM TMP_IESIRI WHERE CODIES = I1.CODIES), 0) = 26;



END;

END PKG_SERVICE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SERVPOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C46027F5814423F66364C9EF707D9FDDA0F6F581</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SERVPOST IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_59&apos;;

PROCEDURE SP_LockRecord(RecId in NUMBER) IS
  Tmp NUMBER(20);
begin
  SELECT CodServiciu INTO Tmp FROM ServPost WHERE CodServiciu = RecId FOR UPDATE NOWAIT;
end;

procedure SP_DeleteRecord(RecId in NUMBER) is
  aDoc varchar2(250);
begin
  SP_LockRecord(RecId);

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Serviciu Pst Vanzare &quot;&apos;||denserviciu||&apos;&quot;&apos; INTO aDoc FROM ServPost WHERE codserviciu = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;ServPost&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  DELETE FROM ServPost WHERE CodServiciu = RecId;
  NotifyModif(2, RecId, &apos;SERVPOST&apos;);
  COMMIT;
end;

procedure SP_InsertRecord is
begin
  INSERT INTO Tmp_ServPost FIELDS(CodServiciu) VALUES (0);
  COMMIT;
end;

procedure SP_GoToRecord(RecId in NUMBER) is
begin
  INSERT INTO Tmp_ServPost (
    CodServiciu,
    DenServiciu,
    CodObiect,
    Tarif,
    Denumire
  )(
    SELECT
      SP.CodServiciu,
      SP.DenServiciu,
      SP.CodObiect,
      SP.Tarif,
      OBJ.DENUMIRE
    FROM ServPost SP
      INNER JOIN NARTOBJ OBJ ON SP.CodObiect = OBJ.CODOBIECT
    WHERE SP.CodServiciu = RecId
  );
  COMMIT;
end;

procedure SP_PostRecords(Operation in NUMBER, RecId out NUMBER) is
  aDoc varchar2(250);
begin
  if Operation = 0 then -- UPDATE
    SELECT CodServiciu INTO RecId FROM Tmp_ServPost;
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Serviciu Pst Vanzare &quot;&apos;||denserviciu||&apos;&quot;&apos; INTO aDoc FROM ServPost WHERE codserviciu = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;ServPost&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    UPDATE ServPost SET (
      CodServiciu,
      DenServiciu,
      CodObiect,
      Tarif
    ) = (
      SELECT
        CodServiciu,
        DenServiciu,
        CodObiect,
        Tarif
      FROM Tmp_ServPost
    )
    WHERE CodServiciu = RecId;
  else -- INSERT
    SELECT Seq_ServPost_CodServiciu.NextVal INTO RecId FROM DUAL;
    INSERT INTO ServPost (
      CodServiciu,
      DenServiciu,
      CodObiect,
      Tarif
    )(
      SELECT
        RecId,
        DenServiciu,
        CodObiect,
        Tarif
      FROM Tmp_ServPost
    );
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Serviciu Pst Vanzare &quot;&apos;||denserviciu||&apos;&quot;&apos; INTO aDoc FROM ServPost WHERE codserviciu = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;ServPost&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, null, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
  end if;
  NotifyModif(Operation, RecId, &apos;SERVPOST&apos;);
  COMMIT;
end;

end PKG_SERVPOST; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SETLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EB00E88DACD1EECE4AA097B59A334ECAB696F49</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SETLISTE IS

 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodSet INTO Tmp FROM WINMADMIN.Setliste WHERE CodSet = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM WINMADMIN.SETUSERS WHERE CODSET = RecId ;
	DELETE FROM WINMADMIN.Setliste WHERE CodSet = RecId ;
  NotifyModif(2, RecId, &apos;WINMADMIN.SETLISTE&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_SETLISTE FIELDS( CodSet ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NCATPRET
  INSERT INTO  TMP_SETLISTE ( CodSet, Denumire, DEDICAT )
    ( SELECT CodSet, Denumire, DEDICAT
      FROM WINMADMIN.SETLISTE WHERE CodSet = RecId ) ;

  INSERT INTO TMP_SETUSERS (CODSETUSERS, CODSET, CODUSER, USERNAME)
  (SELECT 
     CODSETUSERS, CODSET, CODUSER, 
     (SELECT t.USERNAME FROM Tmp_Utilizator t WHERE t.codutilizator = D.CODUSER) USERNAME 
   FROM WINMADMIN.SETUSERS D WHERE CODSET = RecId and CODUSER &gt; 0) ;

  INSERT INTO TMP_SETGROUPS (CODSETUSERS, CODSET, CODUSER, USERNAME)
  (SELECT 
     CODSETUSERS, CODSET, -CODUSER, 
     (SELECT t.DENGRUPUSER FROM 
		 WinMADMIN.grupuser t WHERE t.CODGRUPUSER = -D.CODUSER) USERNAME 
   FROM WINMADMIN.SETUSERS D WHERE CODSET = RecId and CODUSER &lt; 0) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CodSet INTO RecId FROM TMP_SETLISTE;

    DELETE FROM WINMADMIN.SETUSERS WHERE CODSET = RECID AND CODSETUSERS NOT IN (SELECT CODSETUSERS FROM TMP_SETUSERS)
                                                        AND CODSETUSERS NOT IN (SELECT CODSETUSERS FROM TMP_SETGROUPS);

    UPDATE WINMADMIN.SETLISTE SET ( Denumire, DEDICAT )
       = ( SELECT Denumire, DEDICAT
          FROM TMP_SETLISTE )
      WHERE CodSet = RecId ;

    -- SETUSERS
    FOR v_rec IN (SELECT * FROM TMP_SETUSERS WHERE NVL(CODUSER,0) &gt; 0 )  LOOP
      IF V_REC.CODSETUSERS &lt; 0 THEN
        INSERT INTO WINMADMIN.SETUSERS (CODSETUSERS, CODSET, CODUSER) VALUES
        (WINMADMIN.pkg_userfirme.getSeqNextVal(&apos;SEQ_SETUSERS_CODSETUSERS&apos;), RECID, V_REC.CODUSER); 
      ELSE
        UPDATE WINMADMIN.SETUSERS
        SET
          CODSET    = V_REC.CODSET,
          CODUSER   = V_REC.CODUSER     
        WHERE CODSETUSERS = V_REC.CODSETUSERS;
      END IF;
    END LOOP;
    -- SETGROUPS
    FOR v_rec IN (SELECT * FROM TMP_SETGROUPS WHERE NVL(CODUSER,0) &gt; 0 )  LOOP
      IF V_REC.CODSETUSERS &lt; 0 THEN
        INSERT INTO WINMADMIN.SETUSERS (CODSETUSERS, CODSET, CODUSER) VALUES
        (WINMADMIN.pkg_userfirme.getSeqNextVal(&apos;SEQ_SETUSERS_CODSETUSERS&apos;), RECID, -V_REC.CODUSER); 
      ELSE
        UPDATE WINMADMIN.SETUSERS
        SET
          CODSET    = V_REC.CODSET,
          CODUSER   = -V_REC.CODUSER     
        WHERE CODSETUSERS = V_REC.CODSETUSERS;
      END IF;
    END LOOP;


  ELSE  -- INSERT
  
    SELECT WINMADMIN.pkg_userfirme.getSeqNextVal(&apos;Seq_Setliste_Codset&apos;) INTO RecId FROM DUAL;
    INSERT INTO  WINMADMIN.SETLISTE ( CodSet, Denumire, DEDICAT )
    ( SELECT  RecId, Denumire, DEDICAT
      FROM TMP_SETLISTE  ) ;
      
    INSERT INTO WINMADMIN.SETUSERS (CODSETUSERS, CODSET, CODUSER)
    (SELECT WINMADMIN.pkg_userfirme.getSeqNextVal(&apos;SEQ_SETUSERS_CODSETUSERS&apos;), RECID, CODUSER FROM TMP_SETUSERS); 

    INSERT INTO WINMADMIN.SETUSERS (CODSETUSERS, CODSET, CODUSER)
    (SELECT WINMADMIN.pkg_userfirme.getSeqNextVal(&apos;SEQ_SETUSERS_CODSETUSERS&apos;), RECID, -CODUSER FROM TMP_SETGROUPS); 

  END IF;
  NotifyModif(Operation, RecId, &apos;WINMADMIN.SETLISTE&apos;);
  COMMIT;
END;

end pkg_SetListe; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SETLUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A621B6EAFB621C493FE05074003542CBF9D632A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SETLUNI IS

  procedure CreazaLunaMaxima(An in Number, Luna in Number)
  is
   PRAGMA AUTONOMOUS_TRANSACTION;
    Nr Number;
    UnAn Number;
    OLuna Number;
  begin
    Nr := 0;
    select count(*) into nr from FIRMALUNI;
    if nr = 0 then
      insert into FIRMALUNI values (0, 0, 0, 0, An, Luna, 0, 0);
    else 
      UnAn := 0;  OLuna := 0;
      Select AnMaxim , LunaMaxima into UnAn, OLuna from FIRMALUNI;

      if UnAn * 12 + OLuna &lt; An * 12 + Luna then
        Update FIRMALUNI set AnMaxim = An, LunaMaxima = Luna;
      end if;
    end if;
    Commit;
    PKG_GLOBALS.AnMaxim    := An;
    PKG_GLOBALS.LunaMaxima := Luna;
  end;



  procedure SetLunaCurenta( An in Number, Luna in Number)
  is
  Nr Number;
  begin
    Nr := 0;
    select count(*) into nr from FIRMALUNI;
    if nr = 0 then
     insert into FIRMALUNI values (An, Luna, 0, 0, 0, 0, 0, 0);
    else 
     update FIRMALUNI set AnCurent = An, LunaCurenta = Luna;
    end if;
    SetLunaMaxima( An, Luna);
    Commit;
-- actualizez si variabilele globale --
    PKG_GLOBALS.AnCurent    := An;
    PKG_GLOBALS.LunaCurenta := Luna;
  end;



  procedure GetLunaCurenta(An out Number, Luna out Number)
  is
  begin
    An := 0; Luna := 0;
    select AnCurent, LunaCurenta into An, Luna from FIRMALUNI;


-- actualizez si variabilele globale --
    PKG_GLOBALS.AnCurent    := An;
    PKG_GLOBALS.LunaCurenta := Luna;
  end;


  procedure SetLunaInitiala(An in Number, Luna in Number)
  is
  Nr Number;
  begin
    Nr := 0;
    select count(*) into nr from FIRMALUNI;
    if nr = 0 then
     insert into FIRMALUNI values (0, 0, An, Luna, 0, 0, 0, 0);
    else 
     update FIRMALUNI set AnInitial = An, LunaInitiala = Luna;
    end if;
    SetLunaMaxima(An, Luna);
    Commit;
-- actualizez si variabilele globale --
    PKG_GLOBALS.AnInitial    := An;
    PKG_GLOBALS.LunaInitiala := Luna;
  end;

  procedure GetLunaInitiala(An out Number, Luna out Number)
  is
  begin
    An := 0; Luna := 0;
    select AnInitial, LunaInitiala into An, Luna from FIRMALUNI;


-- actualizez si variabilele globale --
    PKG_GLOBALS.AnInitial    := An;
    PKG_GLOBALS.LunaInitiala := Luna;
  end;
  
  
  procedure SetLunaMaxima(An in Number, Luna in Number)
  is
  Nr Number;
  UnAn Number;
  OLuna Number;
  begin
    Nr := 0;
    select count(*) into nr from FIRMALUNI;
    if nr = 0 then
      insert into FIRMALUNI values (0, 0, 0, 0, An, Luna, 0, 0);
    else 
      UnAn := 0;  OLuna := 0;
      Select AnMaxim , LunaMaxima into UnAn, OLuna from FIRMALUNI;

      if UnAn * 12 + OLuna &lt; An * 12 + Luna then
        Update FIRMALUNI set AnMaxim = An, LunaMaxima = Luna;
      end if;
    end if;
    Commit;
    PKG_GLOBALS.AnMaxim    := An;
    PKG_GLOBALS.LunaMaxima := Luna;
  end;

  procedure GetLunaMaxima(An out Number, Luna out Number)
  is
  begin
    An := 0; Luna := 0;
    select AnMaxim, LunaMaxima into An, Luna from FIRMALUNI;


-- actualizez si variabilele globale --
    PKG_GLOBALS.AnMaxim    := An;
    PKG_GLOBALS.LunaMaxima := Luna;
  end;
  


end PKG_SETLUNI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SETTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05A9343F0215929BFFA34C8CBAC0316F2460C570</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_settask IS

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

FUNCTION ObjExists (tmpName IN Varchar2, Tip in varchar2) RETURN NUMBER IS
SIR VARCHAR2(5000);  
sResult NUMBER (1);
BEGIN
  if Tip = &apos;TABLE&apos; then
    SIR := &apos;SELECT COUNT(*) FROM &apos;||TMPNAME;
    begin
      execute immediate SIR;                   
      sResult := 1;
    exception when others then
      sResult := 0;
    end;    
  end if;
  if Tip = &apos;SEQUENCE&apos; then
    BEGIN
      execute immediate &apos;ALTER SEQUENCE &apos;||TMPNAME||&apos; INCREMENT BY 1&apos;;
      sResult := 1;
    EXCEPTION WHEN OTHERS THEN sResult := 0;
    end;
  end if;                     
	RETURN sResult;
END;

PROCEDURE CHECK_STRUCT_EXTENSIE(CODSKEMA IN NUMBER)
IS
  NR  NUMBER(10) := 0;
  DT  VARCHAR2(100);
  SIR VARCHAR2(1000);
  VG  VARCHAR2(100);
  NR1 NUMBER(10) := 0;
  SKEMA VARCHAR2(250);
BEGIN
  SKEMA := WINMADMIN.PKG_USERFIRME.GetSkemaFirma(CODSKEMA) ;
  
  IF ObjExists(&apos;SETTASKEXT&apos;, &apos;TABLE&apos;) = 0 THEN
    execute immediate &apos;CREATE TABLE SETTASKEXT(CODSETTASKEXT NUMBER(20), CODTASK NUMBER(20) ) &apos;;
    PKG_CFGTABLES.SETGRANTMODUL(&apos;SETTASKEXT&apos;, SKEMA);
  END IF;

  IF ObjExists(&apos;SEQ_SETTASKEXT_CODSETTASKEXT&apos;, &apos;SEQUENCE&apos;) = 0 THEN
    PKG_REMAKE_SEQUENCES.REMAKE_SEQUENCE(&apos;SETTASKEXT&apos;, &apos;CODSETTASKEXT&apos;, &apos;SEQ_SETTASKEXT_CODSETTASKEXT&apos;);
  END IF;

  IF ObjExists(&apos;TMP_SETTASKEXT&apos;,&apos;TABLE&apos;) = 1 THEN
    NR1 := OBJEXISTS(&apos;SETTASKEXT&apos;,&apos;TABLE&apos;);
    NR  := OBJEXISTS(&apos;SETTASK&apos;,&apos;TABLE&apos;); 
    IF NR1 &lt;&gt; NR THEN
      EXECUTE IMMEDIATE &apos;DROP TABLE TMP_SETTASKEXT&apos; ;
      commit;
    END IF;
  END IF;

  IF ObjExists(&apos;TMP_SETTASKEXT&apos;,&apos;TABLE&apos;) = 0 THEN
    Sir := &apos;BEGIN PKG_SERVICE.CHECK_STRUCT_EXTENSIE_TASK; END;&apos;;
    EXECUTE IMMEDIATE SIR;
  END IF;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODTASK INTO Tmp FROM SETTASK WHERE CODTASK = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  UPDATE settask SET sters = 1 where codtask = RecID;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_SETTASK FIELDS( CODTASK) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  SKEMA       varchar2(100);
  aCODFIRMA   number(20);
  aCODCOMANDA number(20);
  aCODFACTURA number(20);
  aCODOFERTA  number(20);
  sSql        varchar2(1000) := &apos;;
  sSqlx       varchar2(100) := &apos;;
  Nr          number(20);
BEGIN
  BEGIN
  	SELECT nvl(CODFIRMA,0), nvl(CODCOMANDA,0), nvl(CODFACTURA,0), nvl(CODOFERTA,0)
    INTO   aCODFIRMA,       aCODCOMANDA,       aCODFACTURA,       aCODOFERTA
    FROM SETTASK
    WHERE CODTASK = RecId;
  EXCEPTION WHEN OTHERS THEN
	  aCODFIRMA   := 0;
		aCODCOMANDA := 0;
		aCODFACTURA := 0;
		aCODOFERTA  := 0;
	END;

	IF aCODCOMANDA &gt; 0 THEN
		SELECT count(*) INTO NR FROM COMANDA WHERE CODCOMANDA = aCODCOMANDA;
		IF Nr = 0 THEN
			UPDATE SETTASK SET CODCOMANDA = 0 WHERE CODTASK=RecId; 
		END IF;
	END IF;
	IF aCODFACTURA &gt; 0 THEN
		SELECT count(*)  INTO NR FROM IESIRI WHERE CODIES =aCODFACTURA;
		IF Nr = 0 THEN
			UPDATE SETTASK SET CODFACTURA = 0, FACTURAT = 0 WHERE CODTASK=RecId; 
		END IF;
	END IF;
	IF aCODOFERTA &gt; 0 THEN
		SELECT count(*) INTO NR FROM OFERTA WHERE CODOFERTA = aCODOFERTA;
		IF Nr = 0 THEN
			UPDATE SETTASK SET CODOFERTA = 0 WHERE CODTASK=RecId; 
		END IF;
	END IF;

--  CHECK_STRUCT_EXTENSIE(PKG_USERFIRME.GETCODFIRMA); 

	INSERT INTO  TMP_SETTASK (
    CODTASK,PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,
    TERMEN, DATATASK,
    DATAREZ,
    DOMENIU,TIP,REZOLVARE,OBSERVATII,PRIORITATE,DONE,MODIFICAT,
    MESAJCATRE, PROIECT,
    CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA,
		CODCOMANDA,CODFACTURA,CODOFERTA,
		COMANDA,FACTURA,OFERTA,FIRMA,
		CODPART,CODPERS,CODSERVICIU,CODCONTRACT1,
    ORATASK, ORAREZ,
    VERSIUNE, PREFIXDOC, NRDOC, CARNETDOC, SERIADOC,
    ARTICOLASOCIAT)
  SELECT
    CODTASK,PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,
    TRUNC(TERMEN),TRUNC(DATATASK), TRUNC(DATAREZ),
    DOMENIU,TIP,REZOLVARE,OBSERVATII,PRIORITATE,DONE,MODIFICAT,
    MESAJCATRE, PROIECT,
    CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, S.CODFIRMA, S.SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA,
		CODCOMANDA,CODFACTURA,CODOFERTA,
    CASE WHEN Nvl(CODCOMANDA,0) = 0 THEN &apos;?&apos; ELSE &apos;Ok&apos; END,
    CASE WHEN Nvl(CODFACTURA,0) = 0 THEN &apos;?&apos; ELSE &apos;Ok&apos; END,
    CASE WHEN Nvl(CODOFERTA,0)  = 0 THEN &apos;?&apos; ELSE &apos;Ok&apos; END,
		&apos;&apos;, --F.DENFIRMA,
		CODPART, S.CODPERS,S.CODSERVICIU,S.CODCONTRACT1,
    TO_CHAR(DATATASK, &apos;HH24:MI&apos;), TO_CHAR(DATAREZ, &apos;HH24:MI&apos;),
    VERSIUNE, S.PREFIXDOC, S.NRDOC, S.CARNETDOC, S.SERIADOC,
    S.ARTICOLASOCIAT
  FROM SETTASK S
--    LEFT JOIN FIRMA F on F.Codfirma = S.CodFirma
  WHERE CODTASK = RecId;

  INSERT INTO TMP_SETTASKOBJ (
    CODTASKOBJ, CODTASK, CODOBIECT, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL)
  SELECT
    S.CODTASKOBJ, S.CODTASK, S.CODOBIECT, S.CANT, NVL(S.NEPRELUABIL,0), S.PRET, S.CODPERS, S.INDEXLOCAL
  FROM SETTASKOBJ S
  WHERE S.CODTASK = RecId AND Nvl(S.CODOBIECT,0) &gt; 0;
  
  INSERT INTO TMP_SETTASKOBJASOC (CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL)
  SELECT CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL
  FROM SETTASKOBJASOC
  WHERE CODTASK = RECID;

  BEGIN
     UPDATE TMP_SETTASK TMP
      SET (CODCONTRACT1, CONTRACT) =
          (SELECT NVL(C1.CODCONTRACT1,0), CASE WHEN NVL(C.CODCONTRACT,0) = 0 THEN &apos;?&apos; ELSE c.seriadoc||&apos; &apos;||c.nrdoc||&apos;/&apos;||to_char(c.datadoc, &apos;dd.mm.yyyy&apos;) END
           FROM CONTRACT C INNER JOIN CONTRACT1 C1 ON C1.CODCONTRACT = C.CODCONTRACT
           WHERE TMP.CODCONTRACT1 = C1.CODCONTRACT1);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASK TMP
      SET (CODCOMANDA, COMANDA) =
          (SELECT NVL(C.CODCOMANDA,0), CASE WHEN NVL(C.CODCOMANDA,0) = 0 THEN &apos;?&apos; ELSE c.PREFIXDOC||&apos; &apos;||c.nrdoc||&apos;/&apos;||to_char(c.datadoc, &apos;dd.mm.yyyy&apos;) END
           FROM COMANDA C
           WHERE TMP.CODCOMANDA = C.CODCOMANDA);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASK TMP
      SET (CODFACTURA, FACTURA) =
          (SELECT NVL(I.CODIES,0), CASE WHEN NVL(I.CODIES,0) = 0 THEN &apos;?&apos; ELSE i.PREFIXDOC||&apos; &apos;||i.nrdoc||&apos;/&apos;||to_char(i.datadoc, &apos;dd.mm.yyyy&apos;) END
           FROM IESIRI I
           WHERE TMP.CODFACTURA = I.CODIES);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASK TMP
      SET CODOBIECT = (SELECT NVL(SP.CODOBIECT,0) FROM SERVPOST SP WHERE SP.CODSERVICIU = TMP.CODSERVICIU);
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASKOBJ TMP
      SET (CODOBIECT, DEN_OBIECT) =
          (SELECT NVL(O.CODOBIECT,0), CASE WHEN NVL(O.CODOBIECT,0) = 0 THEN &apos;?&apos; ELSE O.DENUMIRE END
           FROM NARTOBJ O
           WHERE O.CODOBIECT = TMP.CODOBIECT),
           (CODPERS,PERSOANA) = 
           (SELECT NVL(P.CODPERS,0), CASE WHEN NVL(P.CODPERS,0) = 0 THEN &apos;?&apos; ELSE P.NUME||&apos; &apos;||P.PRENUME END
            FROM  NPERS P
            WHERE P.CODPERS = TMP.CODPERS),
           VALOARE = PRET * CANT,
           DEN_UM =  
           (SELECT NUM.DEN_UM
           FROM  NARTOBJ O
                INNER JOIN  NART A ON O.CODARTICOL = A.CODARTICOL
                INNER JOIN  NUM ON NUM.CODUM = A.UM
           WHERE O.CODOBIECT = TMP.CODOBIECT) ;
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASKOBJ TMP
      SET (DEN_OBIECT) =
          (SELECT O.DENUMIRE
           FROM  NARTOBJ O
           WHERE O.CODOBIECT = TMP.CodObiect) ;
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

  BEGIN
     UPDATE TMP_SETTASKOBJASOC TMP
      SET DENUMIRE =
          (SELECT O.DENUMIRE
           FROM  NARTOBJ O
           WHERE O.CODOBIECT = TMP.CODOBIECT) ;
  EXCEPTION WHEN OTHERS THEN NULL;
  END;
/*
  IF ObjExists(&apos;SETTASKEXT&apos;, Skema,&apos;TABLE&apos;) = 1 AND ObjExists(&apos;TMP_SETTASKEXT&apos;, Skema,&apos;TABLE&apos;) = 1 THEN
    EXECUTE IMMEDIATE &apos;INSERT INTO  TMP_SETTASKEXT SELECT * FROM  SETTASKEXT WHERE CODTASK = &apos; || RECID;
  END IF;
*/
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  OLD_MESAJCATRE VARCHAR2(30);
  NEW_MESAJCATRE VARCHAR2(30);
  aSkema         VARCHAR2(50);
  Cati number(20);
  aDoMSg   number(1);
  aDoMail  number(1);
  aZBefore1 number(2);
  aZBefore2 number(2);
  Old_DoMail  number(1);
  Old_ZBefore2 number(2);

	MSGID    number(20);
  MSGID1   number(20);
  MAILID   number(20);

	aCodPers number(20);
  aMesajCatre varchar2(100);
  aUSERNAME   varchar2(100);
  ExecMSG  number(1) := 0;
  ExecMail number(1) := 0;
  aMes varchar2(4000);
  aProblema varchar2(4000);
  aDataMail date;
  aJobName varchar2(100);
  aTERMEN date;
  aCITIT number(1);
  aSTERS number(1);
  CateErau number(5);
  aDATA     date;
  aDATAAfis date;
  aDESTINATAR varchar2(256);
  aPROIECT varchar2(256);
  aEMail varchar2(256);
  vDataRez date;
  aCARNETDOC    NUMBER(20);
  aNRDOC        NUMBER(20);
	aCodLink      NUMBER(20); 
	aTipLink      NUMBER(20);
	aCodFirma     NUMBER(20);
BEGIN
  ExecMSG := 0;
	aCodFirma := WINMADMIN.PKG_USERFIRME.GetCodFirma; --iau firma din WinMAdmin, nu schimba!
  aSkema    := WINMADMIN.PKG_USERFIRME.GetSkemaFirma(aCodFirma);
--	insert into X(VIEW_NAME) values (&apos;aProblema=&apos;||aProblema||&apos;;&apos;); commit;
  
  SELECT  Nvl(CodPers,0), USERNAME, DESTINATAR, PROIECT,TERMEN, TRANSLATE(Problema, &apos;&apos;&apos;&apos;, &apos;&quot;&apos;), MesajCatre, NVL(CodMail,0), NVL(CodMSG1,0), NVL(DoMSg,0), NVL(DoMail,0),
          CARNETDOC, NRDOC
  INTO    aCodPers, aUSERNAME, aDESTINATAR, aPROIECT,aTERMEN, aProblema, aMesajCatre, MailID, MSGID1, aDoMSg, aDoMail,
          aCARNETDOC, aNRDOC
  FROM TMP_SETTASK;

	SELECT COUNT(*) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ1 = MSGID1;
	if CateErau = 0 then MSGID1 := 0; end if;

	SELECT COUNT(*) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ1 = MSGID1;
	if CateErau = 0 then aDoMSg := 0; MSGID1 := 0; end if;
	
	aMes := &apos;Task:&apos;||Chr(13)||aProblema ||
					Case when aTermen is null then &apos;&apos; else &apos;; Termen:&apos;||aTermen end||
					Case when aDESTINATAR is null then &apos;&apos; else &apos;; Dest:&apos;||aDESTINATAR end||
					Case when aPROIECT is null then &apos;&apos; else &apos;; Proiect:&apos;||aPROIECT end;

  
	begin
		SELECT  CodLink, TipLink	INTO aCodLink, aTipLink	FROM TMP_SETTASK;
	exception when others then
		aCodLink := 0;
	end;    

  aEMail := &apos;?&apos;;
	if aCodPers &gt; 0 then
    aEMail := WinMAdmin.PKG_UserFirme.GetEMailFromNPers(aCodPers, aSkema);
	else
    aEMail := WinMAdmin.PKG_UserFirme.GetEMailFromUtilizator(aMesajCatre);
	end if;
	if aEMail = &apos;?&apos; then aEMail := aMesajCatre; end if;
	IF aDoMSg = -2 THEN
    aDoMsg := 0;
    aZBefore1 := -1;
  ELSE
    IF aDoMSg = -1 THEN aZBefore1 := -1; ELSE aZBefore1 := aDoMsg; END IF;
    aDoMsg := 1;
  END IF;

  IF aDoMail = -2 THEN
    aDoMail := 0;
    aZBefore2 := -1;
  ELSE
    IF aDoMail = -1 THEN aZBefore2 := -1; ELSE aZBefore2 := aDoMail; END IF;
    aDoMail := 1;
  END IF;

  IF Operation = 0 THEN  -- UPDATE
    SELECT  CODTASK INTO RecId FROM TMP_SETTASK;
    IF MSGID1 = 0 THEN --nu a fost mesaj
      ExecMSG := aDoMsg;
    ELSE -- a fost mesaj
      IF aDOMSG = 0 THEN -- a fost mesaj si acuma&apos; nu mai este
        UPDATE WinMAdmin.Mesaje1
        SET Sters = 1
        WHERE CodMesaj1 = MSGID1;
      ELSE -- a fost mesaj si este si acuma&apos;
        --corectare mesaj existent daca e cazul
				SELECT CODMESAJ, TO_USER, CITIT, STERS INTO MSGID, OLD_MESAJCATRE, aCITIT, aSTERS 
				FROM WinMAdmin.MESAJE1 
				WHERE CODMESAJ1 = MSGID1;
        
				SELECT COUNT(*) INTO CateErau FROM WinMAdmin.MESAJE1 WHERE CODMESAJ = MSGID;
        SELECT DATA, DATAAfis INTO aDATA, aDATAAfis FROM WinMAdmin.MESAJE WHERE CODMESAJ = MSGID;

				SELECT MESAJCATRE INTO NEW_MESAJCATRE FROM TMP_SETTASK WHERE CODTASK = RECID;

				IF UPPER(NEW_MESAJCATRE) &lt;&gt; UPPER(OLD_MESAJCATRE) THEN
          ExecMSG := 1;
        ELSE
          IF CateErau = 1 THEN --inseamna ca pot face borsh cu el,  e unic destinatar
             IF aData = aDataAfis THEN --a fost mesaj dar cu afisare instant
               IF aZBefore1 = -1 THEN
                 ExecMSG := 0;
               ELSE
                 ExecMSG := 1;
               END IF;
             ELSE --a fost mesaj cu afisare ULTERIOARA
               IF aCitit = 0 THEN
                 UPDATE WinMAdmin.Mesaje SET DataAfis = aTERMEN - aZBefore1 where CodMesaj = MSGID;
                 ExecMSG := 0;
               ELSE
                 ExecMSG := 1;
               END IF;
             END IF;
          ELSE --erau mai multi destinatari
             IF aData = aDataAfis THEN --a fost mesaj dar cu afisare instant
               IF aZBefore1 = -1 THEN
                 ExecMSG := 0;
               ELSE
                 ExecMSG := 1;
               END IF;
             ELSE --a fost mesaj cu afisare ULTERIOARA
               UPDATE WinMAdmin.Mesaje1 SET Sters = 1 where CodMesaj1 = MSGID1;
               ExecMSG := 1;
             END IF;
          END IF;
        END IF;
      END IF;
    END IF;
    IF ExecMsg = 1 THEN
      IF aZBefore1 = -1 THEN
        aDataMail := SysDate;
      ELSE
        aDataMail := aTERMEN - aZBefore1;
      END IF;
      SELECT WinMAdmin.SEQ_MESAJE_CODMESAJ.NEXTVAL INTO MSGID FROM DUAL;
      INSERT INTO WinMAdmin.MESAJE(CODMESAJ,TEXT, FROM_USER,SKEMAFIRMA , DATA, TIP_MESAJ,DATAAFIS)
      SELECT MSGID, aMes, USERNAME, aSKEMA , SYSDATE, 2 , aDataMail FROM TMP_SETTASK;
      MSGID1 := WinMAdmin.SEQ_MESAJE1_CODMESAJ1.NEXTVAL;
      INSERT INTO WinMAdmin.MESAJE1(CODMESAJ1,CODMESAJ,TO_USER,STERS,citit)
             VALUES(MSGID1,MSGID,aMesajCatre, 0, 0);
    END IF;

    IF MailID = 0 THEN
      ExecMail := aDOMail;
    ELSE
      IF aDoMail = 1 THEN
        SELECT  DoMail, ZBefore INTO Old_DoMail, Old_ZBefore2 FROM SETTASK where CODTASK = RECID;

        IF Old_DoMail = -2 THEN
          Old_DoMail := 0;
          Old_ZBefore2 := -1;
        ELSE
          IF Old_DoMail = -1 THEN Old_ZBefore2 := -1; ELSE Old_ZBefore2 := Old_DoMail; END IF;
          aDoMail := 1;
        END IF;

        IF Old_DoMail &lt;&gt; aDoMail or OLD_ZBefore2 &lt;&gt; aZBefore2 THEN
          aJobName := &apos;Mail&apos;||WinMAdmin.PKG_UserFirme.GETCODFIRMA||&apos;_&apos;||MailID;
          dbms_scheduler.Drop_Job(aJobName);
          ExecMail := 1;
        END IF;
      ELSE
        aJobName := &apos;Mail&apos;||WinMAdmin.PKG_UserFirme.GETCODFIRMA||&apos;_&apos;||MailID;
        dbms_scheduler.Drop_Job(aJobName);
      END IF;
    END IF;

    IF ExecMail = 1 THEN
			IF aZBefore2 = -1 THEN
        WinMAdmin.PKG_USERFIRME.SendEMail(SysDate, True, aSkema, aUSERNAME, aEMail, &apos;Task:&apos;||aTermen||&apos;; Dest:&apos;||aDESTINATAR||&apos;; Proiect:&apos;||aPROIECT, aPROBLEMA,MAILID);
      ELSE
        aDataMail := aTERMEN - aZBefore2;
				WinMAdmin.PKG_USERFIRME.SendEMail(aDataMail, False, aSkema, aUSERNAME, aEMail, &apos;Task:&apos;||aTermen||&apos;; Dest:&apos;||aDESTINATAR||&apos;; Proiect:&apos;||aPROIECT, aPROBLEMA, MAILID);
      END IF;
    END IF;

    select datarez into vDataRez from tmp_settask;
    if not vDataRez is null then
      select TO_DATE(TO_CHAR(DATAREZ,&apos;DD.MM.YYYY&apos;)||&apos; &apos;||CASE WHEN ORAREZ = &apos;  :  &apos; THEN &apos;00:00&apos; ELSE ORAREZ END, &apos;DD.MM.YYYY HH24:MI&apos;) into vDataRez from tmp_settask;
    end if;

    UPDATE SETTASK
    SET
      ( PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,TERMEN,
        DATATASK,DATAREZ,
        DOMENIU,TIP,REZOLVARE,OBSERVATII,PRIORITATE,DONE,
        MODIFICAT, MESAJCATRE, PROIECT, CODMAIL, CODMSG1, DOMSG, DOMAIL, ZBEFORE, CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE,
        CODMONEDA,CODCOMANDA,CODFACTURA,CODOFERTA,CODPART,CODPERS,CODSERVICIU,CODCONTRACT1, VERSIUNE,
        PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT )
      =
      (SELECT
        PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,TERMEN,
        TO_DATE(TO_CHAR(DATATASK,&apos;DD.MM.YYYY&apos;)||&apos; &apos;||CASE WHEN ORATASK = &apos;  :  &apos; THEN &apos;00:00&apos; ELSE oratask END, &apos;DD.MM.YYYY HH24:MI&apos;),
        vDataRez,
        DOMENIU,TIP,REZOLVARE,OBSERVATII,PRIORITATE,DONE,
        MODIFICAT, MESAJCATRE, PROIECT, MAILID, MSGID1, DOMSG, DOMAIL, ZBEFORE, aCODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE,
        CODMONEDA,CODCOMANDA,CODFACTURA,CODOFERTA,CODPART,CODPERS,CODSERVICIU,CODCONTRACT1, VERSIUNE,
        PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT
      FROM TMP_SETTASK )
    WHERE CODTASK = RecId;

    DELETE SETTASKOBJ
    WHERE CODTASK = RecId
      AND CODTASKOBJ NOT IN (SELECT CODTASKOBJ FROM TMP_SETTASKOBJ);

    MERGE INTO SETTASKOBJ O
    USING (SELECT codtaskobj, codtask, codobiect, cant, nepreluabil, pret, codpers, indexlocal FROM TMP_SETTASKOBJ) T ON (T.CODTASKOBJ = O.CODTASKOBJ)
    WHEN     MATCHED THEN UPDATE SET O.CodObiect = T.CodObiect, O.cant = t.cant, O.nepreluabil = t.nepreluabil, O.pret = t.pret, O.codpers = t.codpers, O.indexlocal = t.indexlocal
    WHEN NOT MATCHED THEN INSERT (codtaskobj, codtask, codobiect,cant,nepreluabil,pret,codpers,indexlocal) 
                          VALUES (SEQ_SETTASKOBJ_CODTASKOBJ.NEXTVAL, RecId, T.CodObiect, T.Cant, T.Nepreluabil, T.Pret,T.Codpers,T.IndexLocal);
                          
    DELETE SETTASKOBJASOC
    WHERE CODTASK = RecId
      AND CODTASKOBJASOC NOT IN (SELECT CODTASKOBJASOC FROM TMP_SETTASKOBJASOC);

    MERGE INTO SETTASKOBJASOC O
    USING (SELECT CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL 
           FROM TMP_SETTASKOBJASOC) T ON (T.CODTASKOBJASOC = O.CODTASKOBJASOC)
    WHEN     MATCHED THEN UPDATE SET 
      O.CODTASK   = T.CODTASK, 
      O.CODOBIECT = T.CODOBIECT, 
      O.SERII     = T.SERII, 
      O.CODINTERN = T.CODINTERN, 
      O.CODIES1   = T.CODIES1,
      O.INDEXLOCAL = T.INDEXLOCAL
    WHEN NOT MATCHED THEN INSERT (CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL) 
                          VALUES (SEQ_STOBJASOC_CODSTOBJASOC.NEXTVAL, RECID, T.CODOBIECT, T.SERII, T.CODINTERN, T.CODIES1, T.INDEXLOCAL);
                          
  ELSE  -- INSERT
    SELECT Count(*) INTO Cati from TMP_SETTASK1;
    IF Cati = 0 THEN
      INSERT INTO  TMP_SETTASK1 (MESAJCATRE, CodPers)
      (SELECT MESAJCATRE, CodPers from TMP_SETTASK);
    END IF;
    IF aDoMSG = 1 THEN
      IF aZBefore1 = -1 THEN
        aDataMail := SysDate;
      ELSE
        aDataMail := aTERMEN - aZBefore1;
      END IF;
      SELECT winmadmin.SEQ_MESAJE_CODMESAJ.NEXTVAL INTO MSGID FROM DUAL;
      INSERT INTO winmadmin.MESAJE(CODMESAJ,TEXT, FROM_USER,SKEMAFIRMA, DATA, TIP_MESAJ, DATAAFIS)
      SELECT MSGID, aMes, USERNAME, aSKEMA , SYSDATE, 2 , aDataMail FROM TMP_SETTASK;
    END IF;
    MSGID1 := 0;
    FOR v_rec in (SELECT * from TMP_SetTask1) LOOP
      IF aDoMSG = 1 THEN
        MSGID1 := winmadmin.SEQ_MESAJE1_CODMESAJ1.NEXTVAL;
        INSERT INTO winmadmin.MESAJE1(CODMESAJ1,CODMESAJ,TO_USER,STERS,citit)
               VALUES(MSGID1,MSGID,v_rec.MesajCatre, 0, 0);
      END IF;

      IF aDoMail = 1 THEN
				if Nvl(v_rec.CodPers,0) = 0 then
          aEMail := winmadmin.PKG_UserFirme.GetEMailFromUtilizator(v_rec.MesajCatre);
				end if;
				if aEMail = &apos;?&apos; then aEMail := v_rec.MesajCatre; end if;
        IF aZBefore2 = -1 THEN
          winmadmin.PKG_USERFIRME.SendEMail(SysDate, True, aSkema, aUSERNAME,aEMail, &apos;Task:&apos;||aTermen||&apos;; Dest:&apos;||aDESTINATAR||&apos;; Proiect:&apos;||aPROIECT, aPROBLEMA ,MAILID);
        ELSE
          aDataMail := aTERMEN - aZBefore2;
          winmadmin.PKG_USERFIRME.SendEMail(aDataMail, False, aSkema, aUSERNAME, aEMail, &apos;Task:&apos;||aTermen||&apos;; Dest:&apos;||aDESTINATAR||&apos;; Proiect:&apos;||aPROIECT, aPROBLEMA, MAILID);
        END IF;
      END IF;

      SELECT Seq_SETTASK_CODTASK.NextVal INTO RecId FROM DUAL;

      INSERT INTO  SETTASK (
        CODTASK,PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,TERMEN,
        DATATASK,DATAREZ,
        DOMENIU,TIP,REZOLVARE,
        OBSERVATII,PRIORITATE,DONE,MODIFICAT, MESAJCATRE, PROIECT, CODMSG1, CODMAIL, DOMSG, DOMAIL, ZBEFORE,
        CODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA,CODCOMANDA,CODFACTURA,CODOFERTA,CODPART,CODPERS,
        CODSERVICIU,CODCONTRACT1,VERSIUNE,PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT)
      SELECT
        RecId, PROBLEMA,DESTINATAR,v_rec.MesajCATRE,USERNAME,TERMEN,
        TO_DATE(TO_CHAR(DATATASK,&apos;DD.MM.YYYY&apos;)||&apos; &apos;||ORATASK, &apos;DD.MM.YYYY HH24:MI&apos;),
        Decode(DATAREZ, NULL, NULL, TO_DATE(TO_CHAR(DATAREZ,&apos;DD.MM.YYYY&apos;)||&apos; &apos;||CASE WHEN ORAREZ = &apos;  :  &apos; THEN &apos;00:00&apos; ELSE ORAREZ END, &apos;DD.MM.YYYY HH24:MI&apos;)),
        DOMENIU,TIP,REZOLVARE,
        OBSERVATII,PRIORITATE,DONE,MODIFICAT, v_rec.MesajCATRE, PROIECT, MSGID1, MAILID, DOMSG, DOMAIL, ZBEFORE,
        aCODFIRMA, SUBUNITATEA, FACTURABIL, FACTURAT, VALOARE, CODMONEDA,CODCOMANDA,CODFACTURA,CODOFERTA,CODPART,CODPERS,
        CODSERVICIU,CODCONTRACT1,VERSIUNE,PREFIXDOC, NRDOC, CARNETDOC, SERIADOC, ARTICOLASOCIAT
      FROM TMP_SETTASK;

      INSERT INTO SETTASKOBJ ( CODTASKOBJ, CODTASK, CODOBIECT, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL)
      SELECT SEQ_SETTASKOBJ_CODTASKOBJ.NEXTVAL, RecId, CodObiect, CANT, NEPRELUABIL, PRET, CODPERS, INDEXLOCAL
      FROM TMP_SETTASKOBJ;

      INSERT INTO SETTASKOBJASOC (CODTASKOBJASOC, CODTASK, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL)
      SELECT SEQ_STOBJASOC_CODSTOBJASOC.NEXTVAL, RECID, CODOBIECT, SERII, CODINTERN, CODIES1, INDEXLOCAL
      FROM TMP_SETTASKOBJASOC;

      INSERT INTO SETTASKLOG(CODLOG,CODTASK,DATA,USER_SRC,USER_DST)
      SELECT SEQ_SETTASKLOG_CODLOG.NEXTVAL, RecId, SYSDATE, USERNAME, v_rec.MesajCatre
      FROM TMP_SETTASK;
      if aCodLink &gt; 0 then
         PKG_RECLAMATII.UmpleDocAsoc(aCodLink,aTipLink,RECID,54); 
			end if;
    END LOOP;
  END IF;
  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I,NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;
  
  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC,ANRDOC);
  END IF;
  
  COMMIT;
END;

PROCEDURE BagaInTaskLog(CODLOG in number,CODTASK in number,DATA in date,USER_SRC in varchar2,USER_DST in varchar2) is
BEGIN
  INSERT INTO SETTASKLOG(CODLOG,CODTASK,DATA,USER_SRC,USER_DST)
  VALUES (CODLOG,CODTASK,DATA,USER_SRC,USER_DST);

  COMMIT;
END;

FUNCTION TASKURI_NOI (aUserName varchar2) return number is
  iResult NUMBER(20);
BEGIN
  SELECT COUNT(1) INTO iResult
  FROM settask
  WHERE UPPER(Executant) = UPPER(aUserName) AND NVL(STERS,0) = 0 AND NVL(DONE,0) = 0;
  RETURN iResult;
END;

PROCEDURE IMPORTXLS(
  aSUBUNITATE    in varchar2,
  aRESPONSABIL  in varchar2,
  aPROBLEMA    in varchar2,
  aDATACREARE  in varchar2,
  aCONSTRUCTOR in varchar2,
  aJUDET_C     in varchar2,
  aPROIECTANT  in varchar2,
  aNRPROIECT   in varchar2,
  aPROIECT     in varchar2,
  aJUDET_P     in varchar2,
  aSTADIU      in varchar2,
  aBENEFICIAR  in varchar2,
  aAREGEO      in varchar2,
  aVALOARE     in varchar2,
  aNROFERTA    in varchar2,
  aDATAOFERTA  in varchar2,
  aDATACONTACT in varchar2,
  aDATACT      in varchar2,
  aCOMENTARII  in varchar2,
  aOBSERVATII  in varchar2,
  aDVOBSERVATII in varchar2,
  aCASTIGATOR  in varchar2,
  aACTIUNI     in varchar2,
  aFORECAST    in varchar2
) is
aAux varchar2(50);
begin
  aAux := &apos;&apos;;
  /*insert into task_imp(
    SUBUNITATE  ,
    RESPONSABIL ,
    PROBLEMA    ,
    DATACREARE  ,
    CONSTRUCTOR ,
    JUDET_C     ,
    PROIECTANT  ,
    NRPROIECT   ,
    PROIECT     ,
    JUDET_P     ,
    STADIU      ,
    BENEFICIAR  ,
    AREGEO      ,
    VALOARE     ,
    NROFERTA    ,
    DATAOFERTA  ,
    DATACONTACT ,
    DATACT      ,
    COMENTARII  ,
    OBSERVATII  ,
    DVOBSERVATII,
    CASTIGATOR  ,
    ACTIUNI     ,
    FORECAST
)
values (
    aSUBUNITATE  ,
    aRESPONSABIL ,
    aPROBLEMA    ,
    aDATACREARE  ,
    aCONSTRUCTOR ,
    aJUDET_C     ,
    aPROIECTANT  ,
    aNRPROIECT   ,
    aPROIECT     ,
    aJUDET_P     ,
    aSTADIU      ,
    aBENEFICIAR  ,
    aAREGEO      ,
    aVALOARE     ,
    aNROFERTA    ,
    aDATAOFERTA  ,
    aDATACONTACT ,
    aDATACT      ,
    aCOMENTARII  ,
    aOBSERVATII  ,
    aDVOBSERVATII,
    aCASTIGATOR  ,
    aACTIUNI     ,
    aFORECAST
);
  commit;*/    
end;

procedure import_date is
vCod number(20);
vVal number(20,7);
sAuxObs varchar2(1000);
aCodSubunit number(20);
aCodOferta number(20);
aCodPart number(20);
aPos number(10);
sConstructor varchar2(1000);
aCodPers number(20);
vDataCreare date;
aDataA date;
aDataC date;
aCodPart3 number(20);
aCodPart1 number(20);
aCodPart2 number(20);
aCodPartP number(20);
aJudP number(20);
aJudC number(20);
sConstructor1 varchar2(1000);
sProiectant1 varchar2(1000);
sBeneficiar1 varchar2(1000);
begin
  aPos := 0;
  /*for v_rec in (select * from task_imp) loop
    select seq_settask_codtask.nextval into vCod from dual;
    
    sAuxObs := &apos;&apos;;
    begin
      vVal := to_number(replace(v_rec.valoare,&apos;.&apos;,&apos;&apos;));
    exception when others then
      vVal := 0;
      sAuxObs := v_rec.valoare;
    end;
    
    aCodPers :=0;
    begin
      select codpers into aCodPers
      from npers
      where upper(nume) = upper(v_rec.responsabil);
    exception when others then aCodPers := 0;
    end;
    
    aCodOferta := 0;
    if nvl(v_rec.nroferta,&apos;&apos;) &lt;&gt; &apos;&apos; then
      begin
        select codoferta into aCodOferta
        from oferta 
        where nrdoc = to_number(v_rec.nroferta) and dataoferta = to_date(v_rec.dataoferta,&apos;dd.mm.yyyy&apos;)
             and rownum = 1;
      exception when others then aCodOferta := 0;
      end;
    end if; 
    
    aCodPart := 0;
    sConstructor := &apos;&apos;;
    if nvl(v_rec.constructor,&apos;&apos;) &lt;&gt; &apos;&apos; then
      aPos := instr(v_rec.constructor, &apos;/&apos;);
      if aPos &gt; 0 then 
        begin
          select nvl(codpart,0) into aCodPart from npart 
          where upper(den_part) = upper(substr(v_rec.constructor,1,aPos - 1));
          sConstructor := substr(v_rec.constructor,aPos + 1,Length(v_rec.constructor) - aPos);
        exception when others then aCodPart := 0;
        end;
        begin
          select nvl(codpart,0) into aCodPart3 from npart where upper(den_part) = upper(sconstructor);
        exception when others then aCodPart3 := 0;
        end;
      else
        begin
          select nvl(codpart,0) into aCodPart3 from npart where upper(den_part) = upper(v_rec.constructor);
        exception when others then aCodPart3 := 0;
        end;
      end if;
    end if;
    sConstructor1 := &apos;&apos;;
    if nvl(aCodPart3,0) = 0 then sConstructor1 := v_rec.constructor; end if;
    
    
    begin
      vDataCreare := to_date(v_rec.datacreare,&apos;dd.mm.yyyy&apos;);
    exception when others then vDataCreare := null;
    end;
    
    if Length(v_rec.datacontact) &gt; 0 then
      aPos := instr(v_rec.datacontact, &apos;/&apos;);
      if aPos &gt; 0 then
        begin
          aDataC := to_date(substr(v_rec.datacontact,1,aPos - 1),&apos;dd.mm.yyyy&apos;);
        exception when others then aDataC := null;
        end;
      else
        begin
          aDataC := to_date(v_rec.datacontact,&apos;dd.mm.yyyy&apos;);
        exception when others then aDataC := null;
        end;
      end if;
    end if;
    
    if Length(v_rec.datact) &gt; 0 then
      aPos := instr(v_rec.datact, &apos;/&apos;);
      if aPos &gt; 0 then
        begin
          aDataA := to_date(substr(v_rec.datact,1,aPos - 1),&apos;dd.mm.yyyy&apos;);
        exception when others then aDataA := null;
        end;
      else
        begin
          aDataA := to_date(v_rec.datact,&apos;dd.mm.yyyy&apos;);
        exception when others then aDataA := null;
        end;
      end if;
    end if;
    
    begin
      select codpart into aCodPartP from npart where upper(den_part) = upper(v_rec.proiectant);
    exception when others then aCodPartP := 0;
    end;
    sProiectant1 := &apos;&apos;;
    if nvl(aCodPartP,0) = 0 then sProiectant1 := v_rec.proiectant; end if;
    
    begin
      select codjudet into aJudP from njudet where upper(den_judet) = upper(v_rec.judet_p);
    exception when others then aJudP := 0;
    end;
    
    begin
      select codjudet into aJudC from njudet where upper(den_judet) = upper(v_rec.judet_c);
    exception when others then aJudC := 0;
    end;
    
    begin
      select codpart into aCodPart1 from npart where upper(den_part) = upper(v_rec.beneficiar);
    exception when others then aCodPart1 := 0;
    end;
    
    sBeneficiar1 := &apos;&apos;;
    if nvl(aCodPart1,0) = 0 then sBeneficiar1 := v_rec.beneficiar; end if;
    
    begin
      select codpart into aCodPart2 from npart where upper(den_part) = upper(v_rec.castigator);
    exception when others then aCodPart2 := 0;
    end;
    
    insert into settask(
      CODTASK,PROBLEMA,DESTINATAR,EXECUTANT,USERNAME,
      DATATASK,TIP,
      OBSERVATII, 
      CODFIRMA, SUBUNITATEA, VALOARE, 
      CODMONEDA,CODOFERTA,CODPART,CODPERS)
    values (vcod,v_rec.proiect,substr(v_rec.beneficiar,1,30),v_rec.responsabil,v_rec.responsabil,
            vdatacreare,v_rec.problema,
            v_rec.observatii,
            5517,nvl((select codsubunit from nsubunit where upper(den_subunit)=upper(v_rec.subunitate)),0),vVal,
            0,acodoferta, acodpart, aCodPers);
            
    insert into settaskext(
      CODSETTASKEXT,
      CODTASK,
      DATACONTACTARII,
      DATAACTUALIZARE,
      CODPART3,
      CODPART,
      JUDETPROIECTANT,
      NRPROIECT,
      STADIU,
      AREGEO,
      CODPART1,
      DVOBSERVATII,
      CODPART2,
      ACTIUNICASTIGATOR,
      COMENTARIIBAZADATE,
      JUDETCONSTRUCTOR,
      FORECAST,
      constructor1,
      proiectant1,
      beneficiar1
    )
    values (
      seq_settaskext_codsettaskext.nextval,
      vcod,
      aDataA,
      aDataC,
      aCodPart3,
      aCodPartP,
      v_rec.judet_p,
      v_rec.nrproiect,
      v_rec.stadiu,
      v_rec.aregeo,
      acodpart1,
      v_rec.dvobservatii,
      acodpart2,
      v_rec.actiuni,
      v_rec.comentarii,
      v_rec.judet_c,
      v_rec.forecast,
      sconstructor1,
      sproiectant1,
      sbeneficiar1
    );
  end loop;
  */
end;

END pkg_SETTASK; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEDF0087550BD4C6769C06AE2375233CEAC105FB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SGRCOLECT is


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODSGRCOLECT INTO Tmp FROM SGRCOLECT WHERE CODSGRCOLECT = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
   DELETE FROM SGRCOLECT1 WHERE CODSGRCOLECT = RecId ;
   DELETE FROM SGRCOLECT  WHERE CODSGRCOLECT = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SGRCOLECT FIELDS( CODSGRCOLECT ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_SGRCOLECT SELECT * FROM SGRCOLECT WHERE CODSGRCOLECT = RECID;
  INSERT INTO TMP_SGRCOLECT1(CODSGRCOLECT1,CODSGRCOLECT,CODOBIECT,PRET,CANT,DENUMIRE, VALOARE)
  SELECT 
    C1.CODSGRCOLECT1,
    C1.CODSGRCOLECT,
    C1.CODOBIECT,
    C1.PRET,
    C1.CANT,
    O.DENUMIRE,
    C1.PRET * C1.CANT
  FROM
    SGRCOLECT1 C1
    LEFT JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
  WHERE
    C1.CODSGRCOLECT = RECID;  
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CODSGRCOLECT INTO RECID FROM TMP_SGRCOLECT;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE SGRCOLECT
    SET
     (DATA, VALOARE, CODMARIRE,VOUCHERBARCODE) = (SELECT DATA, VALOARE, CODMARIRE,VOUCHERBARCODE FROM TMP_SGRCOLECT)
    WHERE
      CODSGRCOLECT = RECID;
      
   FOR V_REC IN (SELECT * FROM TMP_SGRCOLECT1)
   LOOP
     IF V_REC.CODSGRCOLECT1 &lt; 0 THEN
       INSERT INTO SGRCOLECT1(CODSGRCOLECT1, CODSGRCOLECT, CODOBIECT, PRET, CANT)
       VALUES (SEQ_SGRCOLECT1_CODSGRCOLECT1.NEXTVAL, RECID, V_REC.CODOBIECT, V_REC.PRET, V_REC.CANT);
     ELSE
       UPDATE SGRCOLECT1
       SET
        CODOBIECT = V_REC.CODOBIECT,
        PRET      = V_REC.PRET, 
        CANT      = V_REC.CANT
       WHERE
         CODSGRCOLECT1 = V_REC.CODSGRCOLECT1;
     END IF;      
   END LOOP;       
      
  ELSE  -- INSERT
    SELECT SEQ_SGRCOLECT_CODSGRCOLECT.NextVal INTO RecId FROM DUAL;
    INSERT INTO SGRCOLECT(CODSGRCOLECT, DATA, VALOARE, CODMARIRE,VOUCHERBARCODE, DATACREARE)
    SELECT RECID, DATA, VALOARE, CODMARIRE,VOUCHERBARCODE, SYSDATE FROM TMP_SGRCOLECT;
    
    INSERT INTO SGRCOLECT1(CODSGRCOLECT1, CODSGRCOLECT, CODOBIECT, PRET, CANT)    
    SELECT SEQ_SGRCOLECT1_CODSGRCOLECT1.NEXTVAL, RECID, CODOBIECT, PRET, CANT FROM TMP_SGRCOLECT1;
  END IF; 

  NotifyModif(Operation, RecId, &apos;SGRCOLECT&apos;);
  COMMIT;
  
END;


end PKG_SGRCOLECT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SIMLANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7BF482D4E37C7EC8623F2C2D9B8F05925E3AFFA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SIMLANS IS

procedure UpdataDataStocPlus(SCENARIU in number) IS
begin
  for V_REC in ( Select  L1.CODCMD1, Sm1.DATASTART from scenariilivr2 SL2, lansare0 L0, lansare1 L1, tmp_sim_lans1 sm1  
                         Where SL2.Codscenariu = SCENARIU and L0.CODSCENARIU = SL2.Codscenariu and L0.Codcmd1 = SL2.Codcomanda1
                               and sm1.codcomanda1 = sl2.codcomanda1 and sm1.codproiectnod = sl2.codproiectnod
                          and L1.CodLansare0 = L0.CodLansare0 and L1.CODPROIECTNOD = SL2.Codproiectnod and sm1.DATASTART is not Null)
  loop
    update Comanda1 set DataStart = V_REC.DataStart where CodComanda1 = V_REC.CodCmd1;
	end loop;
	Commit;
end;

procedure Populeaza_TMPURI( G_SUBUNIT in number,DataLivrS in varchar2,  DataLivrF in varchar2,DataCmdS  in varchar2,  DataCmdF  in varchar2, SCENARIU in number default 0, vCodComanda1 in number default 0) IS
NOD_Rezervat   Number(20,7); 
NOD_RezFurn    Number(20,7); 
TOT_RestCmd    Number(20,7); 
TOT_RestFurn   Number(20,7);
Init           number(1);
Zec            number(2);
LastProiectNod number(20);
RezolvareLansari number(1);
begin
  if vCodComanda1 = 0 then
    delete from TMP_SIM_CCOM1;
    delete from TMP_SIM_LANS;
    delete from TMP_SIM_LANS1;
    delete from TMP_SIM_NODECHIV1;
  end if;  
  INSERT INTO TMP_SIM_CCOM1
    (NRDOC,
     DATADOC,
     DENOBIECT,
     DEN_CLIENT,
     CODCOMANDA1,
     CODOBIECT,
     CODPROIECT,
     VERSIUNE,
     CODCOMANDA,
     TIPDOC,
     CODCLIENT,
     TERMEN,
     MASAO,
     VOLUMO,
     CODGRUPA,
     PARITATEGRUPA,
     GrupaE,
     ObjGeneric,
     CODTARA,
     DEN_TARA,
     CODZONA,
     DEN_ZONA,
     CODLOCALIT,
     DEN_LOCALIT,
     UMSEC,
     OK,
     ACTIV,
     TIPCOMANDA,
     CODEXTERN,
     DENMAT,
     TRASEU,
     POZTRASEU,
     HTAG,
     CANTACCEPTAT,
     STOCREZERVAT,
     SCENDEFINITIVE,
     ALTESCENARII,
     REST,
     DEREZOLVAT,
     LANSSCENARIU,
     LANSAT,
     Masa, 
     Volum,
     TipClient
     )
    select * from 
    (SELECT C.NRDOC,
            C.DATADOC,
            NOBJ.DENUMIRE DENOBIECT,
            NP.DEN_PART DEN_CLIENT,
            C1.CODCOMANDA1,
            C1.CODOBIECT,
            C1.CODPROIECT,
            PR.VERSIUNE,
            C.CODCOMANDA,
            C.TIPDOC,
            NP.CODPART CODCLIENT,
            C1.TERMEN,
            NOBJ.MASA MASAO,
            NOBJ.VOLUM/1000000 VOLUMO,
            NE.CODGRUPA,
            NE.PARITATE PARITATEGRUPA,
            GE.DENUMIRE GrupaE,
            NOBJE.DENUMIRE ObjGeneric,
            TARA.CODTARA,
            TARA.DEN_TARA,
            NZ.CODZONA,
            NZ.DEN_ZONA,
            NLOC.CODLOCALIT,
            NLOC.DEN_LOCALIT,
            C1.UMSEC,
            0 OK,
            CASE WHEN COALESCE(SCEN1.CANT, 0) = 0 THEN 0 ELSE 1 END ACTIV,
            C.DISPLIVRARE,
            NOBJ.CODEXTERN,
            NOBJMAT.DENUMIRE DENMAT,
            TR.DENTRASEU TRASEU,
            NAG.POZTRASEU,
            NVL(PR.OBS1, &apos;&apos;) || NVL(PC.OBS1, &apos;&apos;) HTAG,
            C1.CANTACCEPTAT CANTACCEPTAT,
            REZ.REZERVAT STOCREZERVAT,
            NVL(SCDEF.CANT, 0) SCENDEFINITIVE,
            NVL(SC.CANT, 0) ALTESCENARII,
            C1.CANTACCEPTAT - NVL(SC.CANT, 0) - NVL(SCDEF.CANT, 0)  REST,
            C1.CANTACCEPTAT - NVL(SC.CANT, 0) - NVL(SCDEF.CANT, 0) - NVL(SCEN1.LANS, 0) DEREZOLVAT,
            NVL(SCEN1.LANS, C1.CANTACCEPTAT - NVL(SC.CANT, 0) - NVL(SCDEF.CANT, 0)) LANSSCENARIU,
            NVL(CMDINT.CANTCMDINT, 0) LANSAT,
            NVL(NOBJ.MASA,0) * NVL(SCEN1.LANS, 0),
            Round(NVL(NOBJ.VOLUM,0)/1000000 * NVL(SCEN1.LANS, 0), 2),
            decode(BITand(NP.Strategic,1),1,&apos;strategic &apos;,&apos;&apos;) || 
            decode(BITand(NP.tippartener,1),1,&apos;intern &apos;,&apos;&apos;) || 
            decode(BITand(NP.tippartener,2),2,&apos;extern &apos;,&apos;&apos;) || 
            decode(BITand(NP.tippartener,4),4,&apos;produc. &apos;,&apos;&apos;) || 
            decode( BITand(NP.tippartener,8),8,&apos;asig.&apos;,&apos;&apos;) || 
            decode( BITand(NP.tippartener,16),16,&apos;comis.&apos;,&apos;&apos;) as TipClient
       FROM COMANDA C INNER JOIN COMANDA1 C1      ON C.CODCOMANDA = C1.CODCOMANDA
       INNER JOIN NARTOBJ NOBJ       ON NOBJ.CODOBIECT = C1.CODOBIECT     
       LEFT JOIN NPART NP       ON NP.CODPART = C.PARTENER
       LEFT JOIN TMP_SCENARIILIVR1 SCEN1       ON SCEN1.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN PROIECT PR       ON PR.CODPROIECT = C1.CODPROIECT
       LEFT JOIN PROIECTNOD PRN       ON PRN.CODPROIECT = PR.CODPROIECT      AND PRN.NODORIGINAL = 0
       LEFT JOIN ( SELECT CODPRODCOMP, CODOBIECT  FROM PRODMAT WHERE PRINCIPAL = 1
                 ) MAT      ON MAT.CODPRODCOMP = PRN.CODRETETA  AND ROWNUM = 1
       LEFT JOIN NARTOBJ NOBJMAT ON NOBJMAT.CODOBIECT = MAT.CODOBIECT
       LEFT JOIN PRODCOMP PC ON PC.CODPRODCOMP = PRN.CODRETETA
       LEFT OUTER JOIN NECHIV NE   ON NE.CODOBIECT = C1.CODOBIECT
       LEFT OUTER JOIN GRECHIV GE   ON GE.CODGRECHIV = NE.CODGRUPA
       LEFT OUTER JOIN NECHIV NG   ON NG.CODGRUPA = NE.CODGRUPA  AND NG.GENERIC = 1
       LEFT JOIN NARTOBJ NOBJE ON NOBJE.CODOBIECT = NG.CODOBIECT
       LEFT JOIN NAGENDA NAG  ON NAG.CODAGENDA = C.CODLOCATIE
       LEFT JOIN TRASEULIVR TR   ON TR.CODTRASEULIVR = NAG.CODTRASEU
       LEFT JOIN NLOCALIT NLOC   ON NLOC.CODLOCALIT = NAG.CODLOCALIT
       LEFT JOIN NZONE NZ       ON NZ.CODZONA = NLOC.CODZONA
       LEFT JOIN NTARI TARA       ON TARA.CODTARA = NLOC.CODTARA
       LEFT JOIN ( SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT FROM SCENARIILIVR1 S1
                   INNER JOIN SCENARIILIVR S ON S1.CODSCENARIU = S.CODSCENARIU 
                   WHERE NVL(S.DEFINITIV,0) = 1 AND S.CODSCENARIU &lt;&gt; SCENARIU GROUP BY S1.CODCOMANDA1
                 ) SCDEF     ON SCDEF.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN ( SELECT S1.CODCOMANDA1, SUM(S1.LANS) CANT FROM SCENARIILIVR1 S1
                   INNER JOIN SCENARIILIVR S ON S1.CODSCENARIU = S.CODSCENARIU 
                   WHERE NVL(S.DEFINITIV,0) = 0 AND S.CODSCENARIU &lt;&gt; SCENARIU GROUP BY S1.CODCOMANDA1
                  ) SC       ON SC.CODCOMANDA1 = C1.CODCOMANDA1
       LEFT JOIN ( SELECT R.CODCOMANDA1, SUM(R.REST) REZERVAT, NS.CODOBIECT FROM REZERVATS R
                   INNER JOIN NIRSTOC NS ON R.CODNIRSTOC = NS.CODNIRSTOC
                   WHERE NVL(CODCMDPRODMAT, 0) = 0 GROUP BY R.CODCOMANDA1, NS.CODOBIECT
                  ) REZ ON REZ.CODCOMANDA1 = C1.CODCOMANDA1 AND NOBJ.CODOBIECT = REZ.CODOBIECT
       LEFT JOIN (
                  SELECT L0.Codcmd1 CmdCli, C1.CodObiect, L0.CODSCENARIU,SUM(C1.CANTAcceptat) CANTCMDINT
                  FROM LANSARE1 L1 
                  inner join LANSARE0 L0 on L0.CodLansare0 = L1.CodLansare0
                  inner join Comanda1 C1 on C1.CODCOMANDA1 = L1.CodCmd1
                  GROUP BY L0.Codcmd1, C1.CodObiect, L0.CODSCENARIU
                 )CMDINT ON CMDINT.CMDCLI = C1.CODCOMANDA1 and NOBJ.CODOBIECT = CMDINT.CODOBIECT
        WHERE C.TIPDOC in (18,44) AND NVL(C1.CULANSARE,0) = 1 AND (G_SUBUNIT = 1 OR ((C.SUBUNITATEA = G_SUBUNIT and C.TIPDOC = 18) OR (C.SUBUNITSURSA = G_SUBUNIT and C.TIPDOC = 44)))
              AND NVL(C.INCHISA,0) = 0 AND C.OPERAT = 1 AND NVL(C1.CodProiect,0) &gt; 0 AND C1.RESTACCEPTAT &lt;&gt; 0
              AND (C1.CODCOMANDA1 = vCODCOMANDA1 or (vCODCOMANDA1 = 0 and (DataLivrS is NULL OR (C1.TERMEN BETWEEN TO_DATE(DataLivrS,&apos;DD.MM.YYYY&apos;) AND TO_DATE(DataLivrF,&apos;DD.MM.YYYY&apos;)))))
              AND (C1.CODCOMANDA1 = vCODCOMANDA1 or (vCODCOMANDA1 = 0 and (DataCmdS is NULL OR (C.DATADOC BETWEEN TO_DATE(DataCmdS,&apos;DD.MM.YYYY&apos;) AND TO_DATE(DataCmdF,&apos;DD.MM.YYYY&apos;)))))
              AND (vCODCOMANDA1 = 0 OR C1.CODCOMANDA1 = vCODCOMANDA1)
      ) where Scenariu &gt; 0  or Rest &gt; 0;
--------------------------------------
  insert into TMP_SIM_LANS1
  (
  DENUMIRE      ,                         
  CODOBIECT     ,                         
  CODCOMANDA1   ,                         
  PREF          ,                         
  NIVEL         ,                         
  POZITIE       ,                         
  CODPROIECTNOD ,                         
  NODORIGINAL   ,                         
  TIP           ,                         
  NECESARP      ,                         
  NECESAR       ,                         
  REZERVAT      ,                         
  NESOSIT       ,                         
	DataStart     ,
	CERERE        ,
  STOC          ,                         
  CMDINT        ,                         
  DIFERENTE     ,                         
  ZECIMALE      ,
  UMSEC         ,
  DEN_UM        ,
  MatEchiv      ,
  CodExtern     ,
  IndexParinte  ,
  Rezolvat
  )                         
  (
  select 
  DENUMIRE         ,                         
  CODOBIECT        ,                         
  CODCMD1          ,
  PREF             ,                         
  NIVEL            ,                         
  POZITIE          ,                         
  CODPROIECTNOD    ,                          
  NODORIGINAL      ,                         
  TIP              ,                         
  NVL(NECESARP,0)  ,
  0 NECESAR        , 
  NVL(TotRezervat,0), 
  NVL(RestDeSosit,0),
	DataStart        ,
	NVL(RestCerere, 0),
  NVL(STOC       ,0),
  NVL(CantCMDINT ,0), 
  0 DIFERENTE      ,
  Zecimale         ,
  UMSEC            ,
  DEN_UM           ,
  MatEchiv         ,
  CodExtern        ,
  IndexParinte     ,
  0
  FROM (
    SELECT Y.DENUMIRE, Y.CODOBIECT, Y.CODCMD1,Y.PREF,Y.NIVEL,Y.POZITIE, Y.CODPROIECTNOD, Y.NODORIGINAL, Y.Tip, Y.CANT, 
           Y.TotRezervat , RestFurn.RestDeSosit, Trunc(RestFurn.DataStart) DataStart, CEREFURN.RestCerere,
           Y.STOC, Y.NECESARP, CMDI.CANTCMDINT,
           ( Select NVL(u.Zecimale, 0) 
             from NUM u, NART a, NARTOBJ o 
             where o.CodObiect = Y.CodObiect 
                   and a.CodArticol = o.CodArticol 
                   and u.CODUM = a.UM
           ) Zecimale,
           0 UMSEC,
           ( Select DEN_UM
             from NUM u, NART a, NARTOBJ o 
             where o.CodObiect = Y.CodObiect 
                   and a.CodArticol = o.CodArticol 
                   and u.CODUM = a.UM
           ) DEN_UM,
           MatEchiv,
           CodExtern, Y.IndexParinte
    FROM
       (SELECT NOBJ.DENUMIRE, NOBJ.CODOBIECT, COALESCE(NE.CODCOMANDA1,C1.CODCOMANDA1)  CODCMD1,
               X.PREF,X.NIVEL,X.POZITIE,X.CODPROIECTNOD,X.NODORIGINAL,X.Tip,X.CANT,
               REZ.TotRezervat, 
               NS.REST * NVL(NE.PARITATE,1) STOC, 
               X.CANT/ORIG.CANT * NVL(NE.PARITATE,1) NECESARP, x.MatEchiv,
               NOBJ.CodExtern, X.IndexParinte
        FROM COMANDA1 C1
             INNER JOIN  ( SELECT PN0.CODPROIECTNOD NODORIG, PN.CODPROIECTNOD,PN.CODPROIECT,PN.CANT,PN.NODORIGINAL,PN.TIP,PN.CODOBIECT,
                                  PN.NIVEL,PN.POZITIE, SUBSTR(PN.INDEXPARINTE, 3, 47) PREF, case when MECHIV.Nr &gt; 0 then PN.Codprodmat else 0 end MatEchiv,
                                  PN.INDEXPARINTE
                           FROM PROIECTNOD PN
                                INNER JOIN PROIECTNOD PN0 ON PN0.CODPROIECT=PN.CODPROIECT AND PN0.NODORIGINAL = 0
                                LEFT JOIN (select count(*) nr, codmat from prodmat group by codmat) MECHIV on MECHIV.CODMAT = PN.CODPRODMAT
                           ) X ON X.CODPROIECT = C1.CODPROIECT
             LEFT JOIN PROIECTNOD ORIG ON ORIG.CODPROIECTNOD = X.NODORIG
             LEFT JOIN NODECHIV NE ON NE.CODCOMANDA1 = C1.CODCOMANDA1 AND NE.CODPROIECTNOD = X.CODPROIECTNOD
             LEFT JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = COALESCE(NE.CODOBIECT, X.CODOBIECT)
             LEFT JOIN (select sum(NSS.REST) REST, NSS.CODOBIECT
                        from NIRSTOC NSS
                             INNER JOIN NIR ON NSS.CODNIR = NIR.CodNIR
                             INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST
                        WHERE (G_SUBUNIT = 1 OR NG.CodSubunit = G_SUBUNIT)
                        GROUP BY NSS.CODOBIECT
												) NS ON NS.CODOBIECT = NOBJ.CODOBIECT
             LEFT JOIN (SELECT R.CodComanda1, NSR.CodObiect, SUM(R.REZERVATINI) TotRezervat
                        from REZERVATS R 
                        INNER JOIN NIRSTOC NSR ON R.CODNIRSTOC = NSR.CodNIRSTOC
                        GROUP BY R.CodCOmanda1, NSR.CodObiect
                        ) REZ ON REZ.CodComanda1 = C1.CodComanda1 AND NOBJ.CODOBIECT = REZ.CodObiect
             WHERE EXISTS (SELECT TMP.CODPROIECT FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODPROIECT = X.CODPROIECT)
                   AND
                   EXISTS (SELECT TMP.CODCOMANDA1 FROM TMP_SIM_CCOM1 TMP WHERE TMP.CODCOMANDA1 = COALESCE(NE.CODCOMANDA1,C1.CODCOMANDA1) AND (vCODCOMANDA1 = 0 OR tmp.CODCOMANDA1 = vCODCOMANDA1))
       ) Y
       LEFT JOIN 
			         ( 
									SELECT L0.Codcmd1 CmdCli1,L0.CODSCENARIU, L1.CODPROIECTNOD, SUM(C1.CANTAcceptat) CANTCMDINT
									FROM LANSARE1 L1 
									inner join LANSARE0 L0 on L0.CodLansare0 = L1.CodLansare0
									inner join TMP_SIM_CCOM1 CC1 on CC1.CODCOMANDA1 = L0.CodCmd1
									inner join Comanda1 C1 on C1.CODCOMANDA1 = L1.CodCmd1
                  GROUP BY L0.Codcmd1, L1.CODPROIECTNOD , L0.CODSCENARIU
                ) CMDI ON CMDI.CmdCli1 = Y.CodCmd1 and CMDI.Codproiectnod = Y.CODPROIECTNOD
       LEFT OUTER JOIN (select R.CodComanda1, NS.CodObiect, sum(r.rest) RestDeConsumat
                        from rezervats r 
                             inner join nirstoc ns on ns.codnirstoc = r.codnirstoc 
                             where nvl(r.codnirstoc, 0) &gt; 0
														 group by NS.CodObiect, R.CodComanda1
                       ) RESTREZ ON RESTREZ.CodObiect = Y.CodObiect 
                                 AND RESTREZ.CodComanda1 = Y.CodCmd1
       LEFT OUTER JOIN (select R.CodComanda1, R.CodObiect, Max(C1.Termen) DataStart, sum(r.rest) RestDeSosit
                        from rezervats r
                        inner join Comanda1 C1 on C1.CodComanda1 = r.CODCOMANDA1F
                        where nvl(r.codnirstoc, 0) = 0 and nvl(r.CODCOMANDA1F, 0) &lt;&gt; 0 
                        group by r.CodObiect, r.codcomanda1
                       ) RESTFURN ON RESTFURN.CodObiect = Y.CodObiect and RESTFURN.CodComanda1 = Y.CodCmd1
       LEFT OUTER JOIN (select R.CodComanda1, R.CodObiect, sum(r.rest) RestCerere
                        from rezervats r
                        where nvl(r.codnirstoc, 0) = 0 and nvl(r.CODCOMANDA1F, 0) = 0 
                        group by r.CodObiect, r.codcomanda1
                       ) CEREFURN ON CEREFURN.CodObiect = Y.CodObiect and CEREFURN.CodComanda1 = Y.CodCmd1
   ORDER BY Y.DENUMIRE) where NecesarP &gt; 0
  );
  
  INSERT INTO TMP_SIM_NODECHIV1(CODCOMANDA1, CODPROIECTNOD, CODOBIECT, CANT, PARITATE, TIP, 
                                CODOBIECTORIG, NODORIGINAL, STOC, CANTECHIVALATA, DENOBIECTECHIV,CODEXTERN)
  SELECT NE1.CODCOMANDA1, NE1.CODPROIECTNOD, NE1.CODOBIECT, NE1.CANT, NE1.PARITATE, NE1.TIP,
         L1.CODOBIECT, L1.NODORIGINAL, NVL(NS.REST,0), NE1.CANT/NE1.PARITATE, OBJ.DENUMIRE,OBJ.CODEXTERN
  FROM TMP_SIM_LANS1 L1
       INNER JOIN NODECHIV1 NE1 ON L1.CODCOMANDA1 = NE1.CODCOMANDA1 AND L1.CODPROIECTNOD = NE1.CODPROIECTNOD
       INNER JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = NE1.CODOBIECT
       LEFT JOIN (select sum(NSS.REST) REST, NSS.CODOBIECT
                        from NIRSTOC NSS
                             INNER JOIN NIR ON NSS.CODNIR = NIR.CodNIR
                             INNER JOIN NGEST NG ON NG.CODGEST = NIR.GEST
                  WHERE (G_SUBUNIT = 1 OR NG.CodSubunit = G_SUBUNIT)
                  GROUP BY NSS.CODOBIECT) NS ON NS.CODOBIECT = OBJ.CODOBIECT
  WHERE vCODCOMANDA1 = 0 OR L1.CODCOMANDA1 = vCODCOMANDA1;

  if Scenariu = 0 then RezolvareLansari := 0; else RezolvareLansari := 1; end if;
	PKG_SimLans.LoadScenariiLivr(Scenariu);
  update TMP_SIM_CCOM1 tmp set lansscenariu = (select t.lans from TMP_SCENARIILIVR1 t where tmp.codcomanda1 = t.codcomanda1);--repun
end;

procedure LoadScenariiLivr(aCodScenariu in number) is
vRez number(20,7);
vNes number(20,7);
vCer number(20,7);
vCod number(20);
	
	procedure setdatastart(acodproiectnod in number, acodcomanda1 in number) is 
	aCount number(10);   
	begin 
		select count(*) into acount from tmp_sim_lans1 where nodoriginal = acodproiectnod and codcomanda1 = acodcomanda1; 
		if acount &gt; 0 then
			for v_Rec in (select codproiectnod, codcomanda1 from tmp_sim_lans1 where nodoriginal = acodproiectnod and codcomanda1 = acodcomanda1) loop 
				setdatastart(v_rec.codproiectnod, v_rec.codcomanda1); 
			end loop; 
			update tmp_sim_lans1 t set datastart = (select max(tt.datastart) from tmp_sim_lans1 tt where tt.nodoriginal = acodproiectnod and codcomanda1 = acodcomanda1) 
			where t.codproiectnod = acodproiectnod and t.codcomanda1 = acodcomanda1; 
		end if; 
	end;
	
  procedure Rezolva(aCodComanda1 in number, aCodProiectNod in number, aParitate in number) is
  vRezervat number(20,7);
  vRezolvat number(20,7);
  vNecesar  number(20,7);
  vNod number(20);
  begin
    update tmp_sim_lans1 set rezolvat = necesar * aParitate where codcomanda1 = aCodComanda1 and codproiectnod = aCodProiectNod;
    select rezolvat, rezervat, NodOriginal, Necesar into vRezolvat, vRezervat, vNod, vNecesar from tmp_sim_lans1 where codcomanda1 = aCodComanda1 and codproiectnod = aCodProiectNod;
    if vNod = 0 then vRezolvat := 0; end if;
    for v_rec in (select * from tmp_sim_lans1 where codcomanda1 = aCodComanda1 and NodOriginal = aCodProiectNod) loop
      Rezolva(aCodComanda1, v_rec.codproiectnod, (vRezolvat+vRezervat)/vNecesar);
    end loop;
  end;
  
begin
  for V_CC1 in (Select * from TMP_SIM_CCOM1) 
	Loop
    update TMP_SIM_LANS1 set NECESAR = NECESARP*V_CC1.Lansscenariu where CodComanda1 = V_CC1.CodComanda1;
    --select codproiectnod, rezervat/necesar into vCod, vCer from tmp_sim_lans1 where codcomanda1 = v_cc1.codcomanda1 and nodoriginal = 0;
    --if vCer &gt; 0 then
    --  Rezolva(v_cc1.codcomanda1, vCod, vCer);
    --end if;
    for v_tmp in (select * from tmp_sim_lans1
                  where codcomanda1 = v_cc1.codcomanda1 and tip &lt;&gt; 3
                  order by nivel desc, pozitie
                 ) loop
      select codproiectnod, rezervat/necesar into vCod, vCer from tmp_sim_lans1 where codcomanda1 = v_cc1.codcomanda1 and codproiectnod = v_tmp.codproiectnod;
      if vCer &gt; 0 then
        Rezolva(v_cc1.codcomanda1, vCod, vCer);
      end if;
    end loop;  
	  --update TMP_SIM_LANS1 set DIFERENTE = NECESAR - REZERVAT- NESOSIT - CERERE - CmdInt - case when nodoriginal &gt; 0 then REZOLVAT else 0 end
		--where CodComanda1 = V_CC1.CodComanda1 and NECESAR &lt;&gt; 0;
	end loop;
  
	update tmp_sim_lans1 set diferente = coalesce(necesar,0) - coalesce(cmdint,0);
  for V_Rec in (	Select distinct CodComanda1, CodObiect, rezervat
		              from TMP_SIM_LANS1 
									where Nvl(Necesar,0) &lt;&gt; 0 and rezervat &gt; 0
               ) 
	Loop
    vRez := v_rec.rezervat;
    update tmp_sim_lans1 set rezervat = 0 where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect;
    for v_tmp in (select * from tmp_sim_lans1
                  where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect
                  order by nivel desc, pozitie
                 ) loop
      if v_tmp.Diferente &gt; 0 and vRez &gt; 0 then
        if v_tmp.Diferente &lt; vRez then
          --se acopera cu rezervarile
          update tmp_sim_lans1 set rezervat = v_tmp.diferente, diferente = 0
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vRez := vRez - v_tmp.diferente;
        else
          update tmp_sim_lans1 set rezervat = vRez, diferente = diferente - vRez
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vRez := 0;
        end if;           
      end if;  
    end loop;
  end loop;
  for V_Rec in (	Select distinct CodComanda1, CodObiect, nesosit
		              from TMP_SIM_LANS1 
									where Nvl(Necesar,0) &lt;&gt; 0 and nesosit &gt; 0
               ) 
	Loop
    vNes := v_rec.nesosit;
    update tmp_sim_lans1 set nesosit = 0 where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect;
    for v_tmp in (select * from tmp_sim_lans1
                  where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect
                  order by nivel desc, pozitie
                 ) loop
      if v_tmp.Diferente &gt; 0 and vNes &gt; 0 then
        if v_tmp.Diferente &lt; vNes then
          update tmp_sim_lans1 set nesosit = v_tmp.diferente, diferente = 0
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vNes := vNes - v_tmp.diferente;
        else
          update tmp_sim_lans1 set nesosit = vNes, diferente = diferente - vNes
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vNes := 0;
        end if;           
      end if;  
    end loop;
  end loop;
  
  --execute immediate &apos;create table tmp_sim_lans11 as select * from tmp_sim_lans1&apos;;
  
  for V_Rec in (	Select distinct CodComanda1, CodObiect, cerere
		              from TMP_SIM_LANS1 
									where Nvl(Necesar,0) &lt;&gt; 0 and cerere &gt; 0
               ) 
	Loop
    vCer := v_rec.cerere;
    update tmp_sim_lans1 set cerere = 0 where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect;
    for v_tmp in (select * from tmp_sim_lans1
                  where codcomanda1 = v_rec.codcomanda1 and codobiect = v_rec.codobiect
                  order by nivel desc, pozitie
                 ) loop
      if v_tmp.Diferente &gt; 0 and vCer &gt; 0 then
        if v_tmp.Diferente &lt; vCer then
          update tmp_sim_lans1 set cerere = v_tmp.diferente, diferente = 0
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vCer := vCer - v_tmp.diferente;
        else
          update tmp_sim_lans1 set cerere = vCer, diferente = diferente - vCer
          where codcomanda1 = v_tmp.codcomanda1 and codobiect = v_rec.codobiect and codproiectnod = v_tmp.codproiectnod;
          vCer := 0;
        end if;           
      end if;  
    end loop;
  end loop;
  
  update TMP_SIM_LANS1 set DIFERENTE = NECESAR - REZERVAT- NESOSIT - CERERE - CmdInt - case when nodoriginal &gt; 0 then Rezolvat else 0 end;
  update TMP_SIM_LANS1 set DIFERENTE = 0 WHERE DIFERENTE &lt; 0;
  
  for v_rec in (select * from tmp_sim_lans1) loop
    if coalesce(v_rec.necesar,0) &lt;= coalesce(v_rec.rezervat,0) and coalesce(v_rec.necesar,0) &gt; 0 then
      update tmp_sim_lans1 set datastart = pkg_globals.GetDataDeAzi where codcomanda1 = v_rec.codcomanda1 and INSTRB(indexparinte, v_rec.indexparinte) = 1;
    end if;
  end loop;
	update tmp_sim_lans1 set datastart = to_date(&apos;31.12.9999&apos;,&apos;dd.mm.yyyy&apos;) where datastart is null; 
	for v_Rec in (select codproiectnod, codcomanda1 from tmp_sim_lans1 where coalesce(necesar,0) &gt; coalesce(rezervat,0) and coalesce(necesar,0) &gt; 0 and tip &lt; 3) loop
		setdatastart(v_rec.codproiectnod, v_rec.codcomanda1);
	end loop; 
	update tmp_sim_lans1 set datastart = null where datastart = to_date(&apos;31.12.9999&apos;,&apos;dd.mm.yyyy&apos;);
end;


end PKG_SIMLANS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8191C21CB51D3FF73DA6614C4922CAC9B56237A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SITFIN IS

tcA              number := 1;
tcB              number := 2;
tcSoldI          number := 3;
tcSoldF          number := 4;
tcRulCumAC       number := 5;
tcRulCumAP       number := 6;
tcSoldFInchideri number := 7;
tcIntrodusa      number := 8;
tcPrecSoldI      number := 9;
tcPrecSoldIAj    number := 10;
tcPrecSoldICuAj  number := 11;
tcCurSoldI       number := 12;
tcCurSoldIAj     number := 13;
tcCurSoldICuAj   number := 14;
tcPrecRulCum     number := 15;
tcPrecRulCumAj   number := 16;
tcPrecRulCumCuAj number := 17;
tcCurRulCum      number := 18;
tcCurRulCumAj    number := 19;
tcCurRulCumCuAj  number := 20;
tcPrecTotal      number := 21;             
tcPrecTotalAj    number := 22;             
tcPrecTotalCuAj  number := 23;
tcCurTotal       number := 24;
tcCurTotalAj     number := 25;
tcCurTotalCuAj   number := 26;
tcPrecSoldF      number := 27;
tcPrecSoldFAj    number := 28;
tcPrecSoldFCuAj  number := 29;
tcCurSoldF       number := 30;
tcCurSoldFAj     number := 31;
tcCurSoldFCuAj   number := 32;
tcObs            number := 33;
tcRulAC          number := 35;

FUNCTION BOOL_EVALUATE(Exp in varchar2) RETURN NUMBER IS
Rez NUMBER(1);
sSelect varchar2(200);
begin
  begin
    sSelect := &apos;select 1 from dual where &apos;||Exp;
    EXECUTE IMMEDIATE sSelect into Rez;
    return 1;
  exception
    when others then
    return 0;
  end;
end;

FUNCTION GetCodSitFinByCodF(aCodF in varchar2) RETURN NUMBER is
aCodSitFin NUMBER(20);
begin
  begin
    EXECUTE IMMEDIATE &apos;SELECT NVL(CodSitFin, 0) FROM SITFIN WHEN CodF = &apos;&apos;&apos;||aCodF||&apos;&apos;&apos;&apos; INTO aCodSitFin;
  exception when others then
    aCodSitFin := 0;
  end;
  RETURN aCodSitFin;
end;

FUNCTION EVALUATE(Expr IN VARCHAR2, Val OUT NUMBER ) RETURN BOOLEAN IS
aVal NUMBER(20, 7);
BEGIN
  BEGIN
    EXECUTE IMMEDIATE &apos;SELECT &apos;||Expr||&apos; FROM DUAL&apos; INTO aVal;
    Val := aVal;
    RETURN True;
  EXCEPTION WHEN OTHERS THEN 
    Val := -1;
    RETURN False;
  END;
END;

procedure TESTCOLOANE(aCodSitFin in number) is
aCount number(10);
begin
  select count(*) into aCount from sitfincol where codsitfin = aCodSitFin and nvl(nrcol,0) = 0;
  if aCount &gt; 0 then 
    for v_rec in (select codcoloana, rownum as NrCol
                  from (select codcoloana from sitfincol where codsitfin = aCodSitFin order by codcoloana)
                 ) loop
      update sitfincol set nrcol = v_rec.nrcol where codcoloana = v_rec.codcoloana;           
    end loop;
    commit;
  end if;
end;  

FUNCTION GetExprPrelucrata(Expr IN VARCHAR2) RETURN VARCHAR2 IS
i number(10);
T varchar2(250);
Simbol varchar2(20);
Operand varchar2(250);
BEGIN
  i := 1;
  T := &apos;&apos;;
  while i &lt;= Length(Expr)
  loop
    if (SUBSTR(Expr, i, 1) = &apos;+&apos;) or (SUBSTR(Expr, i, 1) = &apos;-&apos;) or (SUBSTR(Expr, i, 1) = &apos;*&apos;) or (SUBSTR(Expr, i, 1) = &apos;/&apos;)
    or (SUBSTR(Expr, i, 1) = &apos;(&apos;) or (SUBSTR(Expr, i, 1) = &apos;)&apos;) then
      T := T||SUBSTR(Expr, i, 1);
      i := i + 1;
    else
      Operand := &apos;&apos;;
      while ((i &lt;= Length(Expr) and (not ((SUBSTR(Expr, i, 1) = &apos;+&apos;) or (SUBSTR(Expr, i, 1) = &apos;-&apos;) or (SUBSTR(Expr, i, 1) = &apos;*&apos;) or (SUBSTR(Expr, i, 1) = &apos;/&apos;)
            or (SUBSTR(Expr, i, 1) = &apos;(&apos;) or (SUBSTR(Expr, i, 1) = &apos;)&apos;))))) loop
        Operand := Operand||SUBSTR(Expr, i, 1);
        i := i + 1;
      end loop;
      if (Substr(Operand, Length(Operand), 1) = &apos;D&apos;) or (Substr(Operand, Length(Operand), 1) = &apos;C&apos;) then
        Simbol := Substr(Operand, 1, Length(Operand) - 1);
        if Simbol &lt;&gt; &apos;&apos; then
          T := T||Simbol||Substr(Operand, Length(Operand), 1);
        else
          T := T||&apos;???&apos;||Substr(Operand, Length(Operand), 1);
        end if;
      else
        T := T||Operand;
      end if;
    end if;  
  end loop;
  
  RETURN T;
END;

procedure CompleteazaSabloane is 
begin
  DELETE FROM TMP_SABLCOL;
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcA,               1, &apos;A - Denumire indicator&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcB,               2, &apos;B - Numar rand&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcSoldI,           3, &apos;Balanta: Solduri initiale&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcSoldF,           4, &apos;Balanta: Solduri finale&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcRulCumAC,        5, &apos;Balanta: Rulaje cumulate - an curent&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcRulCumAP,        6, &apos;Balanta: Rulaje cumulate - an precedent&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcSoldFInchideri,  7, &apos;Solduri fara inchiderere&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcIntrodusa,       8, &apos;Introdusa&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldI,       9, &apos;Balanta: Solduri initiale - perioada precedenta&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldIAj,    10, &apos;Balanta: Solduri initiale - perioada precedenta - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldICuAj,  11, &apos;Balanta: Solduri initiale - perioada precedenta - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldI,       12, &apos;Balanta: Solduri initiale - perioada actuala&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldIAj,     13, &apos;Balanta: Solduri initiale - perioada actuala - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldICuAj,   14, &apos;Balanta: Solduri initiale - perioada actuala - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecRulCum,     15, &apos;Balanta: Rulaje cumulate - perioada precedenta&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecRulCumAj,   16, &apos;Balanta: Rulaje cumulate - perioada precedenta - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecRulCumCuAj, 17, &apos;Balanta: Rulaje cumulate - perioada precedenta - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurRulCum,      18, &apos;Balanta: Rulaje cumulate - perioada actuala&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurRulCumAj,    19, &apos;Balanta: Rulaje cumulate - perioada actuala - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurRulCumCuAj,  20, &apos;Balanta: Rulaje cumulate - perioada actuala - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecTotal,      21, &apos;Balanta: Total sume - perioada precedenta&apos;);             
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecTotalAj,    22, &apos;Balanta: Total sume - perioada precedenta - ajustari&apos;);             
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecTotalCuAj,  23, &apos;Balanta: Total sume - perioada precedenta - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurTotal,       24, &apos;Balanta: Total sume - perioada actuala&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurTotalAj,     25, &apos;Balanta: Total sume - perioada actuala - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurTotalCuAj,   26, &apos;Balanta: Total sume - perioada actuala - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldF,      27, &apos;Balanta: Solduri finale - perioada precedenta&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldFAj,    28, &apos;Balanta: Solduri finale - perioada precedenta - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcPrecSoldFCuAj,  29, &apos;Balanta: Solduri finale - perioada precedenta - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldF,       30, &apos;Balanta: Solduri finale - perioada actuala&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldFAj,     31, &apos;Balanta: Solduri finale - perioada actuala - ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcCurSoldFCuAj,   32, &apos;Balanta: Solduri finale - perioada actuala - valori cu ajustari&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcObs,            33, &apos;Observatii&apos;);
  INSERT INTO TMP_SABLCOL ( CodSablon, IndexLocal, Denumire ) VALUES (tcRulAC,          34, &apos;Balanta: Rulaje curente - an curent&apos;);
end;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_SITFIN FIELDS( CodSitFin, TipPlan ) VALUES (0, 0);
  CompleteazaSabloane;            
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM CORELAT1    WHERE CodSitFin = RecId;
  DELETE FROM CORELAT2    WHERE CodSitFin = RecId;
  DELETE FROM CONDCOR1    WHERE CodSitFin = RecId;
  DELETE FROM SITFINBUGET WHERE CodSitFin = RecId;
  DELETE FROM SITFINLIN   WHERE CodSitFin = RecId;
  DELETE FROM SITFINCOL   WHERE CodSitFin = RecId;
  DELETE FROM SITFINALTE  WHERE CodSitFin = RecId;
  DELETE FROM SITFIN      WHERE CodSitFin = RecId;
  NotifyModif(2, RecId, &apos;SITFIN&apos;);
  COMMIT;
END;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodSitFin INTO Tmp FROM SITFIN WHERE CodSitFin = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  CompleteazaSabloane;
  INSERT INTO  TMP_SITFIN ( CodSitFin,
                            CodF,     
                            Denumire,
                            Sectiune,
                            UserId,
                            DataCreare,
                            Tip,
                            TipPlan,
                            PeLuni )
                   ( SELECT CodSitFin,
                            CodF,     
                            Denumire,
                            Sectiune,
                            UserId,
                            DataCreare,
                            Tip,
                            Nvl(TipPlan,0),
                            Nvl(PeLuni,0)
                     FROM SITFIN
                     WHERE CodSitFin = RecId );
  
  INSERT INTO  TMP_SITFINSEC ( CodSitFin,
                            CodF,     
                            Denumire,
                            Sectiune )
                   ( SELECT CodSitFin,
                            CodF,     
                            Denumire,
                            Sectiune
                     FROM SITFIN 
                     WHERE CodSitFin = RecId );                   
                     
  INSERT INTO TMP_SITFINCOL ( CodColoana,
                              CodSitFin,
                              NrCol,
                              Denumire,
                              TipCol,
                              Corelatie,
                              IdentificatorCol,
                              DenTipCol,
                              flgExport,
                              Conta )
                     ( SELECT * from (select BC.CodColoana CodColoana,
                              BC.CodSitFin CodSitFin,
                              BC.NrCol NrCol,
                              BC.Denumire Denumire,
                              BC.TipCol TipCol,
                              BC.Corelatie Corelatie,
                              BC.IDENTIFICATORCOL IdentificatorCol,
                              SC.Denumire DenTipCol,
                              BC.Flgexport,
                              coalesce(BC.Conta,0)
                       FROM SITFINCOL BC
                            INNER JOIN TMP_SABLCOL SC ON BC.TipCol = SC.CodSablon
                       WHERE CodSitFin = RecId
                       ORDER BY NrCol));
  
  INSERT INTO TMP_SITFINLIN ( CodLinie, 
                              CodSitFin, 
                              NrLinie, 
                              Denumire, 
                              Total, 
                              Corelatie,
                              Rnd,
                              TipConta,
                              CorSimb,
                              Obs,
                              ValSuplim,
                              FaraNegative )
                     ( SELECT * from (select SF.CodLinie, 
                              SF.CodSitFin, 
                              RowNum, 
                              SF.Denumire, 
                              SF.Total, 
                              SF.Corelatie,
                              SF.Rnd,
                              nvl(SF.TipConta,0),
                              SF.Corelatie CodSimb,
                              SF.Obs,
                              SF.ValSuplim,
                              SF.FaraNegative
                       FROM SITFINLIN SF
                       WHERE SF.CodSitFin = RecId
                       ORDER BY SF.NrLinie));
                       
  INSERT INTO TMP_SITFINBUGET ( 
                               CODSITFINBUGET,
                               CODSITFINLIN,
                               CODSITFIN,
                               AN,
                               LUNA,
                               VALOARE
                              )
                       select CODSITFINBUGET,
                              CODSITFINLIN,
                              CODSITFIN,
                              AN,
                              LUNA,
                              VALOARE
                       FROM SITFINBUGET
                       WHERE CodSitFin = RecId;                     
                       
  INSERT INTO TMP_SITFINALTE (CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA)
  SELECT CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA FROM SITFINALTE WHERE CODSITFIN = RECID;
                       
  INSERT INTO TMP_CONDCOR1 ( CodCondCor1, 
                             CodSitFin,
                             IndexLocal,
                             Rnd1,
                             Col1,
                             Rel,
                             Rnd2,
                             Col2 )
                    ( SELECT CodCondCor1, 
                             CodSitFin,
                             IndexLocal,
                             Rnd1,
                             Col1,
                             Rel,
                             Rnd2,
                             Col2
                      FROM CONDCOR1 WHERE CodSitFin = RecId );                  
  
  INSERT INTO TMP_CORELAT1 ( CodCorelat1, 
                             CodSitFin,
                             IndexLocal,
                             Rnd1,
                             Col1,
                             Rel,
                             Rnd2,
                             Col2,
                             Cond,
                             IsNumeric )
                    ( SELECT CodCorelat1, 
                             CodSitFin,
                             IndexLocal,
                             Rnd1,
                             Col1,
                             Rel,
                             Rnd2,
                             Col2,
                             Cond,
                             IsNumeric
                      FROM CORELAT1 WHERE CodSitFin = RecId );
  
  INSERT INTO TMP_CORELAT2 ( CodCorelat2,
                             CodSitFin,
                             CodF1,
                             Rnd1,
                             Col1,
                             CodF2,
                             Rnd2,
                             Col2,
                             Cod1,
                             Cod2)
                    ( SELECT C2.CodCorelat2,
                             C2.CodSitFin,
                             C2.CodF1,
                             C2.Rnd1,
                             C2.Col1,
                             C2.CodF2,
                             C2.Rnd2,
                             C2.Col2,
                             S1.CODF,
                             S2.CODF
                      FROM CORELAT2 C2
                           LEFT JOIN SITFIN S1 ON S1.CODSITFIN = C2.CODF1
                           LEFT JOIN SITFIN S2 ON S2.CODSITFIN = C2.CODF2
                      WHERE C2.CodSitFin = RecId );                                    
  
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod number(20);  
BEGIN
  for v_rec in (select c.*, row_number() over (order by c.nrcol) newnr from tmp_sitfincol c) loop
    update tmp_sitfincol set nrcol = v_rec.newnr where codcoloana = v_rec.codcoloana;
  end loop;
  IF Operation = 0 THEN  
    SELECT CodSitFin INTO RecId FROM TMP_SITFIN;
    UPDATE SITFIN SET ( CodF,Denumire,Sectiune, Tip, TipPlan, PeLuni )
             = ( SELECT CodF,Denumire,Sectiune, Tip, TipPlan, PeLuni
             FROM TMP_SITFIN )
    WHERE CodSitFin = RecId ;

    DELETE FROM SITFINCOL WHERE CodSitFin = RecId AND CodColoana NOT IN (SELECT CodColoana FROM TMP_SITFINCOL);
    FOR v_rec IN ( SELECT * FROM TMP_SITFINCOL ORDER BY CodColoana ) LOOP 
      IF v_rec.CodColoana &lt; 0 THEN
        INSERT INTO SITFINCOL ( CodColoana, 
                                CodSitFin, 
                                NrCol, 
                                Denumire, 
                                TipCol, 
                                Corelatie, 
                                IdentificatorCol,
                                flgExport,
                                Conta )
                       VALUES ( SEQ_SITFINCOL_CODCOLOANA.NextVal, 
                                RecId, 
                                v_rec.NrCol, 
                                v_rec.Denumire, 
                                v_rec.TipCol, 
                                v_rec.Corelatie,
                                v_rec.IdentificatorCol,
                                v_rec.flgexport,
                                v_rec.Conta );
      ELSE
        UPDATE SITFINCOL
        SET
          NrCol          = v_rec.NrCol,
          Denumire       = v_rec.Denumire,
          TipCol         = v_rec.TipCol,
          Corelatie      = v_rec.Corelatie,
          IdentificatorCol = v_rec.IdentificatorCol,
          flgExport      = v_rec.flgExport,
          Conta          = v_rec.Conta
        WHERE CodColoana = v_rec.CodColoana;
      END IF;
    END LOOP;
    
    DELETE FROM SITFINLIN WHERE CodSitFin = RecId AND CodLinie NOT IN (SELECT CodLinie FROM TMP_SITFINLIN);
    FOR v_rec IN ( SELECT * FROM TMP_SITFINLIN ORDER BY CodLinie ) LOOP 
      IF v_rec.CodLinie &lt; 0 THEN
        select seq_sitfinlin_codlinie.nextval into vCod from dual;
        update tmp_sitfinbuget set codsitfinlin = vCod where codsitfinlin = v_rec.codlinie;
        INSERT INTO SITFINLIN ( CodLinie, 
                                CodSitFin, 
                                NrLinie, 
                                Denumire, 
                                Total, 
                                Corelatie,
                                Rnd,
                                TipConta,
                                Obs,
                                ValSuplim,
                                FaraNegative )
                       VALUES ( vCod,
                                RecId,
                                v_rec.NrLinie,
                                v_rec.Denumire,
                                v_rec.Total,
                                v_rec.Corelatie,
                                v_rec.Rnd,
                                v_rec.TipConta,
                                v_rec.Obs,
                                v_rec.ValSuplim,
                                v_rec.Faranegative );
      ELSE
        UPDATE SITFINLIN
        SET
          NrLinie        = v_rec.NrLinie,
          Denumire       = v_rec.Denumire,
          Total          = v_rec.Total,
          Corelatie      = v_rec.Corelatie,
          Rnd            = v_rec.Rnd,
          TipConta       = v_rec.TipConta,
          Obs            = v_rec.Obs,
          ValSuplim      = v_rec.ValSuplim,
          FaraNegative   = v_rec.faranegative
        WHERE CodLinie = v_rec.CodLinie;
      END IF;
    END LOOP;
    
    DELETE FROM SITFINBUGET WHERE CodSitFin = RecId AND CodSitFinBuget NOT IN (SELECT CodSitFinBuget FROM TMP_SITFINBUGET);
    FOR v_rec IN (SELECT * FROM TMP_SITFINBUGET) LOOP
      IF v_rec.CodSitFinBuget &lt; 0 THEN
        INSERT INTO SITFINBUGET ( CodSitFinBuget,
                                  CodSitFinLin,
                                  CodSitFin,
                                  An,
                                  Luna,
                                  Valoare
                                )
                       VALUES ( seq_sitfinbuget_codsitfinbuget.nextval,
                                v_rec.codsitfinlin,
                                RecId,
                                v_rec.An,
                                v_rec.Luna,
                                v_rec.Valoare 
                              );
      ELSE
        UPDATE SITFINBUGET
        SET
          CodSitFinLin   = v_rec.CodSitFinLin,
          CodSitFin      = RecId,
          An             = v_rec.An,
          Luna           = v_rec.Luna,
          Valoare        = v_rec.Valoare
        WHERE CodSitFinBuget = v_rec.CodSitFinBuget;
      END IF;
    END LOOP;
    
    DELETE FROM CONDCOR1 WHERE CodSitFin = RecId AND CodCondCor1 NOT IN (SELECT CodCondCor1 FROM TMP_CONDCOR1);
    FOR v_rec IN ( SELECT * FROM TMP_CONDCOR1 ORDER BY CodCondCor1 ) LOOP 
      IF v_rec.CodCondCor1 &lt; 0 THEN
        INSERT INTO CONDCOR1 ( CodCondCor1, 
                               CodSitFin, 
                               IndexLocal, 
                               Rnd1, 
                               Col1,
                               Rel,
                               Rnd2,
                               Col2 )
                      VALUES ( SEQ_CONDCOR1_CODCONDCOR1.NextVal, 
                               RecId, 
                               v_rec.IndexLocal, 
                               v_rec.Rnd1, 
                               v_rec.Col1, 
                               v_rec.Rel,
                               v_rec.Rnd2,
                               v_rec.Col2 );
      ELSE
        UPDATE CONDCOR1
        SET
          IndexLocal = v_rec.IndexLocal,
          Rnd1       = v_rec.Rnd1,
          Col1       = v_rec.Col1,
          Rel        = v_rec.Rel,
          Rnd2       = v_rec.Rnd2,
          Col2       = v_rec.Col2
        WHERE CodCondCor1 = v_rec.CodCondCor1;
      END IF;
    END LOOP;
    
    DELETE FROM CORELAT1 WHERE CodSitFin = RecId AND CodCorelat1 NOT IN (SELECT CodCorelat1 FROM TMP_CORELAT1);
    FOR v_rec IN ( SELECT * FROM TMP_CORELAT1 ORDER BY CodCorelat1 ) LOOP 
      IF v_rec.CodCorelat1 &lt; 0 THEN
        INSERT INTO CORELAT1 ( CodCorelat1, 
                               CodSitFin, 
                               IndexLocal, 
                               Rnd1, 
                               Col1, 
                               Rel,
                               Rnd2,
                               Col2,
                               Cond,
                               IsNumeric )
                      VALUES ( SEQ_CORELAT1_CODCORELAT1.NextVal, 
                               RecId, 
                               v_rec.IndexLocal, 
                               v_rec.Rnd1, 
                               v_rec.Col1, 
                               v_rec.Rel,
                               v_rec.Rnd2,
                               v_rec.Col2,
                               v_rec.Cond,
                               v_rec.IsNumeric );
      ELSE
        UPDATE CORELAT1
        SET
          IndexLocal = v_rec.IndexLocal,
          Rnd1       = v_rec.Rnd1,
          Col1       = v_rec.Col1,
          Rel        = v_rec.Rel,
          Rnd2       = v_rec.Rnd2,
          Col2       = v_rec.Col2,
          Cond       = v_rec.Cond,
          IsNumeric  = v_rec.IsNumeric
        WHERE CodCorelat1 = v_rec.CodCorelat1;
      END IF;
    END LOOP;    
    
    DELETE FROM CORELAT2 WHERE CodSitFin = RecId AND CodCorelat2 NOT IN (SELECT CodCorelat2 FROM TMP_CORELAT2);
    FOR v_rec IN ( SELECT * FROM TMP_CORELAT2 ORDER BY CodCorelat2 ) LOOP 
      IF v_rec.CodCorelat2 &lt; 0 THEN
        INSERT INTO CORELAT2 ( CodCorelat2,
                               CodSitFin, 
                               CodF1, 
                               Rnd1, 
                               Col1, 
                               CodF2,
                               Rnd2,
                               Col2 )
                      VALUES ( SEQ_CORELAT2_CODCORELAT2.NextVal,
                               RecId, 
                               v_rec.CodF1, 
                               v_rec.Rnd1, 
                               v_rec.Col1, 
                               v_rec.CodF2,
                               v_rec.Rnd2,
                               v_rec.Col2 );
      ELSE
        UPDATE CORELAT2
        SET
          CodF1 = v_rec.CodF1,
          Rnd1  = v_rec.Rnd1,
          Col1  = v_rec.Col1,
          CodF2 = v_rec.CodF2,
          Rnd2  = v_rec.Rnd2,
          Col2  = v_rec.Col2
        WHERE CodCorelat2 = v_rec.CodCorelat2;
      END IF;
    END LOOP;
    
    DELETE FROM SITFINALTE WHERE CodSitFin = RecId AND CodAlte NOT IN (SELECT CodAlte FROM TMP_SITFINALTE);
    FOR v_rec IN (SELECT * FROM TMP_SITFINALTE) LOOP 
      IF v_rec.CODALTE &lt; 0 THEN
        INSERT INTO SITFINALTE(CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA) 
        VALUES (SEQ_SITFINALTE_CODALTE.NextVal,RecId,upper(v_rec.FUNCTIE),v_rec.RAND,v_rec.COLOANA);
      ELSE
        UPDATE SITFINALTE
        SET
          FUNCTIE = upper(V_REC.FUNCTIE),
          RAND    = V_REC.RAND,
          COLOANA = V_REC.COLOANA  
        WHERE CODALTE = v_rec.CODALTE;
      END IF;
    END LOOP;
  ELSE  
    SELECT SEQ_SITFIN_CODSITFIN.NextVal INTO RecId FROM DUAL;
    INSERT INTO SITFIN ( CodSitFin,
                         CodF,
                         Denumire,
                         Sectiune,
                         UserId,
                         DataCreare,
                         Tip,
                         TipPlan,
                         PeLuni )
                ( SELECT RecId,
                         CodF,
                         Denumire,
                         Sectiune,
                         pkg_globals.USERID,
                         systimestamp,
                         Tip,
                         TipPlan,
                         PeLuni
                  FROM TMP_SITFIN );
     
    INSERT INTO SITFINCOL ( CodColoana, 
                            CodSitFin, 
                            NrCol, 
                            Denumire, 
                            TipCol, 
                            Corelatie,
                            IdentificatorCol,
                            flgExport,
                            Conta )
                   ( SELECT SEQ_SITFINCOL_CODCOLOANA.NextVal, 
                            RecId, 
                            NrCol, 
                            Denumire, 
                            TipCol, 
                            Corelatie,
                            IdentificatorCol,
                            flgExport,
                            Conta 
                     FROM TMP_SITFINCOL );
    
    for v_rec in (select * from tmp_sitfinlin) loop
      select seq_sitfinlin_codlinie.nextval into vCod from dual;
      update tmp_sitfinbuget set codsitfinlin = vCod where codsitfinlin = v_rec.codlinie;
      INSERT INTO SITFINLIN ( CodLinie, 
                              CodSitFin, 
                              NrLinie, 
                              Denumire, 
                              Total, 
                              Corelatie,
                              Rnd,
                              TipConta,
                              Obs,
                              ValSuplim,
                              FaraNegative )
      VALUES                ( vCod, 
                              RecId, 
                              v_rec.NrLinie, 
                              v_rec.Denumire, 
                              v_rec.Total, 
                              v_rec.Corelatie,
                              v_rec.Rnd,
                              v_rec.TipConta,
                              v_rec.Obs,
                              v_rec.ValSuplim,
                              v_rec.faranegative );
    end loop;
    
    insert into sitfinbuget (codsitfinbuget, codsitfinlin, codsitfin, an, luna, valoare)
    select seq_sitfinbuget_codsitfinbuget.nextval, codsitfinlin, RecId, an, luna, valoare
    from tmp_sitfinbuget;
                      
    INSERT INTO CONDCOR1 ( CodCondCor1, 
                           CodSitFin, 
                           IndexLocal, 
                           Rnd1, 
                           Col1,
                           Rel,
                           Rnd2,
                           Col2 )
                  ( SELECT SEQ_CONDCOR1_CODCONDCOR1.NextVal, 
                           RecId, 
                           IndexLocal, 
                           Rnd1, 
                           Col1, 
                           Rel,
                           Rnd2,
                           Col2 
                    FROM TMP_CONDCOR1);
                     
    INSERT INTO CORELAT1 ( CodCorelat1, 
                           CodSitFin, 
                           IndexLocal, 
                           Rnd1, 
                           Col1, 
                           Rel,
                           Rnd2,
                           Col2,
                           Cond,
                           IsNumeric )
                  ( SELECT SEQ_CORELAT1_CODCORELAT1.NextVal, 
                           RecId, 
                           IndexLocal, 
                           Rnd1, 
                           Col1, 
                           Rel,
                           Rnd2,
                           Col2,
                           Cond,
                           IsNumeric 
                    FROM TMP_CORELAT1);
                    
    INSERT INTO CORELAT2 ( CodCorelat2,
                           CodSitFin, 
                           CodF1, 
                           Rnd1, 
                           Col1, 
                           CodF2,
                           Rnd2,
                           Col2 )
                  ( SELECT SEQ_CORELAT2_CODCORELAT2.NextVal,
                           RecId, 
                           CodF1, 
                           Rnd1, 
                           Col1, 
                           CodF2,
                           Rnd2,
                           Col2 
                    FROM TMP_CORELAT2);
    
    INSERT INTO SITFINALTE(CODALTE, CODSITFIN, FUNCTIE, RAND, COLOANA) 
    SELECT SEQ_SITFINALTE_CODALTE.NextVal, RecId, upper(FUNCTIE), RAND, COLOANA FROM TMP_SITFINALTE;                                                                                    
  END IF;
  NotifyModif(Operation, RecId, &apos;SITFIN&apos;);
  COMMIT;
END;

end pkg_sitfin; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SMS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F96C9BA902E7ACA890C57C902B27E69D99027EAC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SMS is

FUNCTION md5hash (str IN VARCHAR2)
    RETURN VARCHAR2
    IS v_checksum VARCHAR2(32);
    BEGIN
        v_checksum := LOWER( RAWTOHEX( UTL_RAW.CAST_TO_RAW( sys.dbms_obfuscation_toolkit.md5(input_string =&gt; str) ) ) );
        RETURN v_checksum;
        EXCEPTION
            WHEN NO_DATA_FOUND THEN
            NULL;
        WHEN OTHERS THEN
            -- Consider logging the error and then re-raise
            RAISE;
END md5hash;

FUNCTION SEND_SMS_ORANGE(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2, MSG_EROARE OUT Varchar2) RETURN NUMBER
IS
 USERNAME   VARCHAR2(100);
 AUTHKEY    VARCHAR2(100); 
 SENDER     VARCHAR2(100); 
 FromMSG    VARCHAR2(1000) := &apos;WME&apos;;
 aREq       utl_http.req;
 data       varchar2(2000);
 URL        varchar2(2000);
 RESP       utl_http.resp;
 value      VARCHAR2(32767);  
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);
 --HOST_PORT  VARCHAR2(100);

BEGIN
  MSG_EROARE := &apos;&apos;;
 --HOST_PORT := WINMADMIN.PKG_USERFIRME.Get_user_SMS_Provider(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;))||&apos;&apos;;
 
 -- HOST_PORT := WINMADMIN.PKG_USERFIRME.Get_user_SMS_Provider(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;))||&apos;:8085&apos;;
  
  USERNAME := SMS_content_Value;
  SENDER   := SMS_fromValue;
  AUTHKEY  := API_Key;
  MSG_EROARE := &apos;&apos;;
-- URL        := &apos;http://&apos; || HOST_PORT || &apos;/root/WMEServer/SendSMS_Orange&apos;;
 URL        := SMS_Url;
 -- areq       := UTL_HTTP.BEGIN_REQUEST (URL, &apos;POST&apos;);
  areq       := UTL_HTTP.BEGIN_REQUEST (lower(URL), SMS_Metoda);
  
  UTL_HTTP.SET_HEADER (areq, &apos;Content-Type&apos;, SMS_content_type );

  
   data := &apos;{&quot;UserName&quot;:&quot;&apos; || UserName || &apos;&quot;, &quot;AuthKey&quot;:&quot;&apos; || AuthKey || &apos;&quot;, &quot;Sender&quot;:&quot;&apos; || Sender || &apos;&quot;, &quot;Telefon&quot;:&quot;&apos; || NRTELEFON || &apos;&quot;,&quot;Mesaj&quot;:&quot;&apos; || Mesaj || &apos;&quot;}&apos;;

   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));

   UTL_HTTP.WRITE_TEXT (areq, data);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;  

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

   RETURN RES;
END;    



FUNCTION SEND_SMS_NOTIFICA(NRTELEFON IN VARCHAR2, aMESAJ IN VARCHAR2, MSG_EROARE OUT VARCHAR2) RETURN NUMBER
IS
 USERNAME   VARCHAR2(100);
 AUTHKEY    VARCHAR2(300); 
 SENDER     VARCHAR2(100); 
 FromMSG    VARCHAR2(1000) := &apos;WME&apos;;
 aREq       utl_http.req;
 data       varchar2(2000);
 URL        varchar2(2000);
 RESP       utl_http.resp;
 value      VARCHAR2(32767);  
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);
 --HOST_PORT  VARCHAR2(100);


BEGIN
  MSG_EROARE := &apos;&apos;;
  --HOST_PORT := WINMADMIN.PKG_USERFIRME.Get_user_SMS_Provider(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;))||&apos;:8085&apos;;
  USERNAME := SMS_content_Value;
  SENDER   := SMS_fromValue;
  AUTHKEY  := API_Key;
  
  
  MSG_EROARE := &apos;&apos;;
  --URL        := &apos;http://&apos; || HOST_PORT || &apos;/root/WMEServer/SendSMS_Advert&apos;;
  URL := SMS_Url;

  
  areq       := UTL_HTTP.BEGIN_REQUEST ( LOWER(URL), SMS_Metoda );
  
  UTL_HTTP.SET_HEADER (areq, &apos;Content-Type&apos;, SMS_content_type );




  
   data := &apos;{&quot;API_Key&quot;:&quot;&apos; || API_Key ||&apos;&quot;, &quot;API_Secret&quot;:&quot;&apos; || API_Secret ||&apos;&quot;, &quot;Telefon&quot;:&quot;&apos; || NRTELEFON || &apos;&quot;,&quot;Mesaj&quot;:&quot;&apos; || aMesaj || &apos;&quot;}&apos;;

   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));


   UTL_HTTP.WRITE_TEXT (areq, data);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;  

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

   RETURN RES;
END;


/*

FUNCTION SEND_SMS_NOTIFICA(NRTELEFON IN VARCHAR2, aMESAJ IN VARCHAR2, MSG_EROARE OUT VARCHAR2) RETURN NUMBER
IS
 FromMSG    VARCHAR2(1000) := &apos;WME&apos;;
 aREq       utl_http.req;
 URL        VARCHAR2(1000); 
 chk        varchar2(1000);
 js         varchar2(1000);
 data       varchar2(2000);
 RESP       utl_http.resp;
 value      VARCHAR2(32767);  
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);
 MESAJ      VARCHAR2(160);
 TimeStampu NUMBER;
 
 FUNCTION REPLACEPARAMS(T in Varchar2) RETURN VARCHAR2 IS
 TXT Varchar2(1000) := T;
 begin
   TXT := replace(TXT, &apos;%JSONPARAM%&apos; , JS); 
   TXT := replace(TXT, &apos;%TIMESTAMP%&apos; , TIMESTAMPU);
   TXT := replace(TXT, &apos;%CHECKSUM%&apos;  , CHK);
   TXT := replace(TXT, &apos;%NRTELEFON%&apos; , NRTELEFON);
   TXT := replace(TXT, &apos;%FROMMSG%&apos;   , SMS_fromValue);
   TXT := replace(TXT, &apos;%MESAJ%&apos;     , MESAJ);
   TXT := replace(TXT, &apos;%API_SECRET%&apos;, API_SECRET);
   TXT := replace(TXT, &apos;%API_KEY%&apos;   , API_KEY);
   Return Txt;
 end;
 
BEGIN
  TimeStampu := date_to_unix_ts (systimestamp);
  URL        := ReplaceParams(SMS_url);
  areq       := UTL_HTTP.BEGIN_REQUEST (URL, SMS_Metoda);
  UTL_HTTP.SET_HEADER (areq, 
                       SMS_content_type,    
                       ReplaceParams(SMS_content_Value) 
                      );
   data := ReplaceParams(SMS_json_Data);  
   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));
   UTL_HTTP.WRITE_TEXT (areq, data);
   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, SMS_err_marker);
    			IF aPOS &gt; 0 THEN
						aPOS     := aPOS + 11;
						StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
						EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
						IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
							MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
						END IF;
					END IF;
			END LOOP;
			UTL_HTTP.END_RESPONSE(resp);
		 EXCEPTION
			WHEN UTL_HTTP.END_OF_BODY THEN
				UTL_HTTP.END_RESPONSE(resp);

	 END;  
   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;  
   RETURN RES;
END;   
 
*/


FUNCTION SEND_SMS_CENTRALATELEFONICA(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2, MSG_EROARE out VARCHAR2) RETURN NUMBER
IS
 USERNAME   VARCHAR2(100);
 AUTHKEY    VARCHAR2(300); 
 SENDER     VARCHAR2(100); 
 FromMSG    VARCHAR2(1000) := &apos;WME&apos;;
 aREq       utl_http.req;
 data       varchar2(2000);
 URL        varchar2(2000);
 RESP       utl_http.resp;
 value      VARCHAR2(32767);  
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);
 --HOST_PORT  VARCHAR2(100);


BEGIN
  MSG_EROARE := &apos;&apos;;

  --HOST_PORT := WINMADMIN.PKG_USERFIRME.Get_user_SMS_Provider(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;))||&apos;:8085&apos;;
  USERNAME := SMS_content_Value;
  SENDER   := SMS_fromValue;
  AUTHKEY  := API_Key;
  
  
  MSG_EROARE := &apos;&apos;;
  --URL        := &apos;http://&apos; || HOST_PORT || &apos;/root/WMEServer/SendSMS_Advert&apos;;
  URL := SMS_Url;
  --areq       := UTL_HTTP.BEGIN_REQUEST (URL, &apos;POST&apos;);
  areq       := UTL_HTTP.BEGIN_REQUEST ( LOWER(URL), SMS_Metoda );
  
  UTL_HTTP.SET_HEADER (areq, &apos;Content-Type&apos;, SMS_content_type );

  
   data := &apos;{&quot;UserName&quot;:&quot;&apos; || AuthKey ||&apos;&quot;, &quot;Secret&quot;:&quot;&apos; || Api_Secret || &apos;&quot;, &quot;ServerTCP&quot;:&quot;&apos; || SMS_CONTENT_VALUE || &apos;&quot;,  &quot;Telefon&quot;:&quot;&apos; || NRTELEFON || &apos;&quot;,&quot;Mesaj&quot;:&quot;&apos; || Mesaj || &apos;&quot;}&apos;;

   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));

   UTL_HTTP.WRITE_TEXT (areq, data);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;  

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

   RETURN RES;
END;



FUNCTION SEND_SMS_ADVERT(NRTELEFON IN VARCHAR2, MESAJ IN VARCHAR2, MSG_EROARE out VARCHAR2) RETURN NUMBER
IS
 USERNAME   VARCHAR2(100);
 AUTHKEY    VARCHAR2(300); 
 SENDER     VARCHAR2(100); 
 FromMSG    VARCHAR2(1000) := &apos;WME&apos;;
 aREq       utl_http.req;
 data       varchar2(2000);
 URL        varchar2(2000);
 RESP       utl_http.resp;
 value      VARCHAR2(32767);  
 Res        NUMBER(1) := 0;
 aPos       Number(10);
 StartPos   Number(10);
 EndPos     Number(10);
 --HOST_PORT  VARCHAR2(100);


BEGIN
  MSG_EROARE := &apos;&apos;;

  --HOST_PORT := WINMADMIN.PKG_USERFIRME.Get_user_SMS_Provider(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;))||&apos;:8085&apos;;
  USERNAME := SMS_content_Value;
  SENDER   := SMS_fromValue;
  AUTHKEY  := API_Key;
  
  
  MSG_EROARE := &apos;&apos;;
  --URL        := &apos;http://&apos; || HOST_PORT || &apos;/root/WMEServer/SendSMS_Advert&apos;;
  URL := SMS_Url;
  --areq       := UTL_HTTP.BEGIN_REQUEST (URL, &apos;POST&apos;);
  areq       := UTL_HTTP.BEGIN_REQUEST ( LOWER(URL), SMS_Metoda );
  
  UTL_HTTP.SET_HEADER (areq, &apos;Content-Type&apos;, SMS_content_type );

  
   data := &apos;{&quot;AuthKey&quot;:&quot;&apos; || AuthKey ||&apos;&quot;, &quot;Telefon&quot;:&quot;&apos; || NRTELEFON || &apos;&quot;,&quot;Mesaj&quot;:&quot;&apos; || Mesaj || &apos;&quot;}&apos;;

   utl_http.set_header(areq, &apos;Content-Length&apos;, length(Data));

   UTL_HTTP.WRITE_TEXT (areq, data);

   BEGIN
     resp := UTL_HTTP.GET_RESPONSE (areq);
      LOOP
        UTL_HTTP.READ_LINE(resp, value, TRUE); 
          aPos := INSTRB(VALUE, &apos;&quot;result&quot;&apos;);
          IF aPOS &gt; 0 THEN
            aPOS     := aPOS + 8;
            StartPos := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 1);
            EndPos   := INSTRB(VALUE, &apos;&quot;&apos;, aPos, 2);
            IF StartPos &gt; 0 AND EndPos &gt; 0 AND StartPos &lt; EndPos then 
              MSG_EROARE := Substr(Value, StartPos, EndPos - StartPos + 1);
            END IF;
          END IF;
      END LOOP;
      UTL_HTTP.END_RESPONSE(resp);
     EXCEPTION
      WHEN UTL_HTTP.END_OF_BODY THEN
        UTL_HTTP.END_RESPONSE(resp);

   END;  

   IF MSG_Eroare = &apos;&quot;ok&quot;&apos; THEN RES := 1; END IF;

   RETURN RES;
END;

FUNCTION SEND_SMS_Full(NRTELEFON IN VARCHAR2, aMESAJ IN VARCHAR2, aNume IN VARCHAR2, aCodDoc in Number, aCodDoc1 in Number, aTipDoc in Number, ForceResend in number, MSG_EROARE OUT VARCHAR2, vNoCommit in number default 0) RETURN NUMBER
IS
 Res        NUMBER(1) := 0;
 MESAJ      VARCHAR2(1000);
 TimeStampu NUMBER;
 NrCaractereMax NUMBER;
 Nr NUMBER;
 
BEGIN
  if ForceResend = 0 then 
		Select Count(*) into Nr from SMSURI 
		where TELEFON= NRTELEFON 
		      and MESAJ  = aMesaj
					and Status = 1 
					and CodDoc = aCodDoc 
					and CodDoc1= aCodDoc1 
					and TipDoc = aTipDoc; 
  	if Nr &gt; 0 then 
  		Res := -1;
	  	MSG_EROARE := &apos;Allready sended&apos;;
			RETURN RES;
		end if;
	end if;
  if (API_Key = &apos;?&apos;) then
    WINMADMIN.PKG_USERFIRME.Get_user_SMS_Full(sys_context(&apos;USERENV&apos;,&apos;CURRENT_SCHEMA&apos;), 
         SMS_url           , 
         SMS_metoda        , 
         SMS_content_type  , 
         SMS_content_Value , 
         SMS_fromValue     , 
         SMS_chksum_param  , 
         SMS_json_param    , 
         SMS_json_data     , 
         SMS_err_marker    , 
         API_Key, 
         API_Secret);
  end if;
  if (API_Key = &apos;?&apos;) then 
    MSG_Eroare := &apos;&quot;Not API_Key active&quot;&apos;; 
  else
    TimeStampu := date_to_unix_ts (systimestamp);

    NrCaractereMax := 999;
		if    
			InSTR(SMS_url, &apos;NOTIFICA&apos;, 1,1) &gt; 0 then NrCaractereMax := 160;
		elsif 
		  InSTR(SMS_url, &apos;ORANGE&apos;,   1,1) &gt; 0 then NrCaractereMax := 160;
		elsif 
		  InSTR(SMS_url, &apos;ADVERT&apos;,   1,1) &gt; 0 then NrCaractereMax := 480;
		end if;    

  Mesaj := aMesaj;

    -- scoate caracterele speciale 
		if InSTR(Mesaj,Chr(13)||Chr(10), 1,1) = 1 then 
      Mesaj := Substr(Mesaj,3);
		end if;

		if InSTR(Mesaj,Chr(13)||Chr(10), length(Mesaj)-2, 1) &gt; 0 then 
      Mesaj := Substr(Mesaj, 1, length(Mesaj)-2);
		end if;

    -- truncheaza mesajul daca e cazul, in functie de NrCaractereMax, si adauga &quot;...more...&quot; la sfarsit
    if length(Mesaj) &gt; NrCaractereMax then
      Mesaj := Substr(Mesaj,1,NrCaractereMax-10) || &apos;...more...&apos;;
    end if;		 
  
    MSG_EROARE := &apos;&apos;;
		SMS_url := Upper(SMS_url);
		if    
			InSTR(upper(SMS_url), &apos;CENTRALATELEFONICA&apos;, 1,1) &gt; 0 then RES := SEND_SMS_CENTRALATELEFONICA(NRTELEFON, MESAJ, MSG_EROARE);
		elsif 
			InSTR(SMS_url, &apos;NOTIFICA&apos;, 1,1) &gt; 0 then RES := SEND_SMS_NOTIFICA(NRTELEFON, MESAJ, MSG_EROARE);
		elsif 
		  InSTR(SMS_url, &apos;ORANGE&apos;,   1,1) &gt; 0 then RES := SEND_SMS_ORANGE(NRTELEFON, MESAJ, MSG_EROARE);
		elsif 
		  InSTR(SMS_url, &apos;ADVERT&apos;,   1,1) &gt; 0 then RES := SEND_SMS_ADVERT(NRTELEFON, MESAJ, MSG_EROARE);
		else
		  MSG_Eroare := &apos;&quot;Unknown provider!&quot;&apos;; 
		  RES := 0;
		end if;
  end if;
	insert into SMSURI 
		(CODSMS,DATA,USERID,TELEFON,MESAJ,EROARE,Nume, Status, CodDoc,CodDoc1,TipDoc) 
	values
		(SEQ_SMSURI_CODSMS.Nextval, SysDate, PKG_GLOBALS.GetUserID, NRTELEFON, MESAJ, MSG_Eroare,aNume, Res, aCodDoc,aCodDoc1,aTipDoc); 
  if vNoCommit &lt;&gt; 1 then
    commit;
  end if;  
	RETURN RES;
END;   
 

end PKG_SMS; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SOLDINITIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC55A3BEC42229F087C9316AEAADA3A26F29407A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SOLDINITIAL IS

FUNCTION SOLD_INI_STINSE(aCODPART IN NUMBER) RETURN NUMBER
IS
NR NUMBER(20) := 0;
BEGIN
  DELETE TMP_GENERAL;

 -- OBLIGATII DIN INTRARI
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G WHERE TIPDOC IN (1, 2, 3, 4, 5, 9) AND
  (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

--OBLIGATII DIN IESIRI
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G WHERE TIPDOC IN (19, 20, 21, 22, 26) AND
  (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

--OBLIGATII DIN TREZOR1
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE
    TIPDOC IN (29, 30, 31, 33) AND
    SEMNIFICATIE &lt;&gt; 800 AND
    SEMNIFICATIE &lt;&gt; 801 AND
  (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART AND
  (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


-- LITIGII
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM
    GENERAL G,
    COMPENS C
  WHERE
    SEMNIFICATIE = 1303
    AND TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


-- TREBUIE SA CURAT FACTURILE CARE AU FOST TRECUTE PE LITIGIU
  FOR V_REC IN
  (SELECT
     OBF.CODGENERAL
   FROM
     TMP_GENERAL G,
     OBLIGPIF O,
     OBLIGPIF OBF
   WHERE
     G.SEMNIFICATIE = 1303
     AND O.CODGENERAL = G.CODGENERAL
     AND OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT
   )
   LOOP
     DELETE FROM TMP_GENERAL WHERE CODGENERAL = V_REC.CODGENERAL;
   END LOOP;

  SELECT COUNT(*) INTO NR FROM STINGERE WHERE VALOARE &lt;&gt; 0 AND CODSTINSPIF IN
  (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL));


  DELETE TMP_GENERAL;

  RETURN NR;
END;


FUNCTION LINII_AVIZE_INI_STINSE(aCODPART IN NUMBER) RETURN NUMBER
IS
  NR NUMBER(20) := 0;
BEGIN
   DELETE TMP_GENERAL;

 -- AVIZE INTRARE
  INSERT INTO TMP_GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G WHERE TIPDOC IN (2) AND
  (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

--OBLIGATII DIN IESIRI
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G WHERE TIPDOC IN (20) AND
  (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    IF V_REC.TIPDOC = 2
      THEN NR := PKG_INTRARI.AMFACTURALAAVIZ(V_REC.CODDOC);
      ELSE NR := PKG_IESIRI.AMFACTURALAAVIZ (V_REC.CODDOC);
    END IF;

    IF NR &lt;&gt; 0 THEN RETURN NR;
    END IF;
  END LOOP;

  RETURN NR;
END;


PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT CODSOLDINI INTO TMP FROM SOLDINI WHERE CODSOLDINI = RECID FOR UPDATE NOWAIT;
END;


PROCEDURE SP_INSERTRECORD
IS
BEGIN
  INSERT INTO TMP_SOLDINI FIELDS( CODSOLDINI ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
 aCODPART NUMBER(20);
 ANI      NUMBER(5);
 LUNAI    NUMBER(2);

BEGIN
  SP_LOCKRECORD(RecId);
 	SELECT CODPART INTO aCODPART FROM SOLDINI WHERE CODSOLDINI = RecID;

  DELETE TMP_GENERAL;-- e posibil sa aiba inregistrari din apelul functiei SOLD_INI_STINSE
  DELETE TMP_GENERAL_LITIGII;
  DELETE TMP_OBLIGVAMA_INITIAL;
  DELETE TMP_STINGERE_ASOCIAT;

-- OBLIGATII DIN LITIGII
  INSERT INTO TMP_GENERAL_LITIGII(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT
    G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE
  FROM
    GENERAL G,
    COMPENS C
  WHERE
    G.TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
    AND G.SEMNIFICATIE = 1350;

  INSERT INTO TMP_OBLIGVAMA_INITIAL(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE)
  SELECT CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE
  FROM
    OBLIGPIF O
  WHERE
    EXISTS (SELECT CODGENERAL FROM TMP_GENERAL_LITIGII WHERE CODGENERAL = O.CODGENERAL);

  INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM
    STINGERE S
  WHERE
    EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = S.CODSTINGATORPIF);


-- ACUM PUN IN TMP_GENERAL SI  CELE CU 1303
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM
    GENERAL G,
    COMPENS C
  WHERE
    SEMNIFICATIE = 1303
    AND TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


-- OBLIGATII DIN INTRARI
  INSERT INTO TMP_GENERAL
   (CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE)
  SELECT
    CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE
  FROM
    GENERAL G
  WHERE
  --TIPDOC IN (1, 2, 3, 4, 5, 9)
   ((TIPDOC IN (1, 2, 3, 4, 9)) OR (TIPDOC = 5 AND SEMNIFICATIE &lt;&gt; 130))
  AND
  (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--OBLIGATII VAMA
  INSERT INTO TMP_GENERAL
   (CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG)
  SELECT
    CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG
  FROM
    GENERAL G
  WHERE
   TIPDOC = 5
   AND SEMNIFICATIE = 130
   AND
  (SELECT CODVAMA FROM DVI D WHERE CODDVI = G.CODDOC) = aCODPART
   AND (SELECT I.AN * 12 + I.LUNA
   FROM
    INTRARI I,
    DVI D
   WHERE
       CODDVI = G.CODDOC
   AND D.CODINTR = I.CODINTR
   )  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--OBLIGATII DIN IESIRI
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G WHERE TIPDOC IN (19, 20, 21, 22, 26) AND
  (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

--OBLIGATII DIN TREZOR1
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE
  TIPDOC IN (29, 30, 31, 33)
  AND SEMNIFICATIE  NOT IN (300, 400, 500, 600, 800, 801 ) -- exclud CECURI SI LINI CE STING CECURI (TRATATE MAI JOS)
  AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
  AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--OBLIGATII DIN NOTE CONTABILE
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS)
  SELECT
     G.CODGENERAL,
     G.TIPDOC,
     G.CODDOC,
     G.MONEDA,
     G.CURS,
     G.TVA,
     G.SEMNIFICATIE,
     G.ICONTAVANS,
     G.PROCTVAAVANS
   FROM
     GENERAL G,
     NC1 N1,
     NC N
  WHERE
    G.TIPDOC = 35
    AND G.SEMNIFICATIE  IN (1200, 1201 )
    AND N1.CODNC1 = G.CODDOC
    AND N.CODNC = N1.CODNC
    AND N.PART  = aCODPART
    AND N.AN * 12 + N.LUNA   &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

  DELETE TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF) SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL);

-- am completat TMP_GENERAL;
/* DEOARECE UNELE LINII DE AICI (AVANSURI) POT FI LEGATE LA CEC-uri (TRATATE MAI JOS) STRGERILE DE MAI JOS SA_AU MUTAT DUPA STERGEEREA CECURILOR
  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    IF V_REC.TIPDOC IN (1, 2, 3, 4, 5) THEN
      DELETE INTRARI1 WHERE CODINTR = V_REC.CODDOC;
      DELETE INTRARI  WHERE CODINTR = V_REC.CODDOC;
    ELSE
    IF V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN
      DELETE IESIRI1 WHERE CODIES = V_REC.CODDOC;
      DELETE IESIRI  WHERE CODIES = V_REC.CODDOC;
    ELSE
    IF V_REC.TIPDOC IN (29, 30, 31) THEN
      FOR V_REC_TREZ1 IN (SELECT * FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
      LOOP
        --DELETE TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;
        DELETE TREZOR1 WHERE CODTREZOR1 = V_REC_TREZ1.CODTREZOR1;
        DELETE TREZOR  WHERE CODTREZOR  = V_REC_TREZ1.CODTREZOR;
      END LOOP;
    END IF;
    END IF;
    END IF;

    DELETE FROM OBLIGPIF WHERE CODGENERAL = V_REC.CODGENERAL;

    DELETE FROM GENERAL  WHERE CODGENERAL = V_REC.CODGENERAL;

  END LOOP;
*/
--START CECURI
  DELETE TMP_GENERAL_CECURI;
  INSERT INTO TMP_GENERAL_CECURI(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE TIPDOC  = 31
    AND SEMNIFICATIE IN (500, 600) -- CECURI
    AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
    AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

  DELETE TMP_TREZOR1;
  INSERT INTO TMP_TREZOR1 (
    CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC,  NRDOC, DATADOC, VALDOC, CURS, COMISION,
    OBIECTTRANZ, CODPART, CODBANCA,  TIPDECONT, DATADECONT,  AN, LUNA, OBS, AGENT, ANULAT, INFOCONTBANCAR, SUBUNITATEA )
  SELECT
    T1.CODTREZOR1, T1.CODTREZOR,   INDEXLOCAL, T1.TIPTRANZ, T1.CARNETDOC, T1.DOC,  T1.NRDOC, T1.DATADOC, VALDOC, CURS, COMISION,
    OBIECTTRANZ, CODPART, T.CODBANCA, TIPDECONT, DATADECONT,  T1.AN, T1.LUNA, T1.OBS, T1.AGENT, ANULAT,
    BK.SIMBOL || &apos;/&apos; || BC.NRCONT || CHR(13) || M.SIMBOL,
    T.SUBUNITATEA
  FROM TREZOR1 T1
    INNER JOIN TREZOR  T ON T.CODTREZOR = T1.CODTREZOR
    LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
    LEFT OUTER JOIN NBANK     BK ON BK.CODBANK   = BC.CODBANK
    LEFT OUTER JOIN NMONEDE   M  ON M.CODMONEDA   = BC.CODMONEDA
  WHERE CODTREZOR1 IN (SELECT CODDOC FROM TMP_GENERAL_CECURI);


   -- MI-AM TRAS IN TMP_GENERAL_CECURI LINIILE CU 500/600 (adica CEC-ri).
   -- TREBUIE SA IDENTIFIC SI LINIILE CU CARE CEC-urile fac stingeri
  INSERT INTO TMP_GENERAL_CECURI(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE TIPDOC = 31
    AND SEMNIFICATIE IN (300, 400)
    AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);


  INSERT INTO TMP_OBLIGPIF_ASOCIAT (
    CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA,
    CODTREZOR1)
  SELECT
    CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA,
    (SELECT DISTINCT CODTREZOR1 FROM TMP_TREZOR1 T1, TMP_GENERAL_CECURI G WHERE G.CODGENERAL = OB.CODGENERAL AND T1.CODTREZOR1 = G.CODDOC)
  FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL_CECURI)) OB
  ORDER BY CODOBLIGPIF;

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM STINGERE WHERE CODSTINSPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF) AND CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT));

  DELETE FROM STINGERE  WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);
  DELETE FROM OBLIGPIF  WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT);
  DELETE FROM GENERAL   WHERE CODGENERAL  IN (SELECT CODGENERAL  FROM TMP_GENERAL_CECURI);


  DELETE FROM STINGERE S WHERE EXISTS (SELECT CODSTINGERE FROM TMP_STINGERE_ASOCIAT  WHERE CODSTINGERE = S.CODSTINGERE);
  DELETE FROM OBLIGPIF O WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = O.CODOBLIGPIF);
  DELETE FROM GENERAL  G WHERE EXISTS (SELECT CODGENERAL  FROM TMP_GENERAL_LITIGII   WHERE CODGENERAL  = G.CODGENERAL );


  FOR V_REC IN (SELECT * FROM TMP_TREZOR1) LOOP
   DELETE FROM TREZOR   WHERE CODTREZOR = V_REC.CODTREZOR;
   DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1;
  END LOOP;

-- END CECURI

  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
    IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
      DELETE INTRARI1 WHERE CODINTR = V_REC.CODDOC;
--    DELETE INTRARI  WHERE CODINTR = V_REC.CODDOC;
    ELSE
    IF V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN
      DELETE IESIRI1 WHERE CODIES = V_REC.CODDOC;
--    DELETE IESIRI  WHERE CODIES = V_REC.CODDOC;
    ELSE
    IF V_REC.TIPDOC IN (29, 30, 31, 33) THEN
      FOR V_REC_TREZ1 IN (SELECT * FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
      LOOP
      --DELETE TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;
        DELETE TREZOR1 WHERE CODTREZOR1 = V_REC_TREZ1.CODTREZOR1;
--      DELETE TREZOR  WHERE CODTREZOR  = V_REC_TREZ1.CODTREZOR;
      END LOOP;
    ELSE
    IF V_REC.TIPDOC IN (28) THEN
        DELETE FROM COMPENS WHERE CODCOMPENS = V_REC.CODDOC;
    ELSE
    IF V_REC.TIPDOC IN (35) THEN
        DELETE FROM NC1 WHERE CODNC1 = V_REC.CODDOC;
    END IF;
    END IF;
    END IF;
    END IF;
    END IF;

    FOR V_REC_O IN (SELECT * FROM OBLIGPIF  WHERE CODGENERAL = V_REC.CODGENERAL)
    LOOP
      DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC_O.CODOBLIGPIF;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC_O.CODOBLIGPIF;
    END LOOP;

    DELETE FROM GENERAL  WHERE CODGENERAL = V_REC.CODGENERAL;

  END LOOP;


  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);

  DELETE FROM NPARTSOLDLUNA    WHERE CODPART = aCODPART AND AN = ANI AND LUNA = LUNAI;
  DELETE FROM NPARTSOLDLUNASUB WHERE CODPART = aCODPART AND AN = ANI AND LUNA = LUNAI;
  DELETE FROM SOLDINI WHERE CODSOLDINI = RECID;
  NotifyModif(2, RecId, &apos;SOLDINI&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RecId IN NUMBER)
IS
aCODPART NUMBER(20) := 0;
aCODGENERAL_AVANS  NUMBER(5) := 0;
aCODOBLIGPIF_AVANS NUMBER(5) := 0;
aCODIOPART NUMBER(20):= 0;
BEGIN

  INSERT INTO TMP_SOLDINI (CODSOLDINI, CODPART)
  SELECT CODSOLDINI, CODPART FROM SOLDINI WHERE CODSOLDINI = RECID;

  OLDCODPART := 0;

  IF RECID &gt; 0 THEN
    SELECT NVL(CODPART, 0) INTO aCODPART FROM TMP_SOLDINI;
    OLDCODPART := aCODPART;

    UPDATE TMP_SOLDINI
    SET
     (VOLUMTRANZC, VOLUMTRANZF) = (SELECT VOLUMTRANZC, VOLUMTRANZF FROM NPART1 WHERE CODPART = aCODPART AND ANSTART = PKG_GLOBALS.ANINITIAL AND LUNASTART = PKG_GLOBALS.LUNAINITIALA);
  END IF;


  DELETE TMP_GENERAL;-- e posibil sa aiba inregistrari din apelul functiei SOLD_INI_STINSE

  DELETE TMP_GENERAL_LITIGII;

-- OBLIGATII DIN LITIGII
  INSERT INTO TMP_GENERAL_LITIGII(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT
    G.CODGENERAL, G.TIPDOC, G.CODDOC, G.MONEDA, G.CURS, G.TVA, G.SEMNIFICATIE
  FROM
    GENERAL G,
    COMPENS C
  WHERE
    G.TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
    AND G.SEMNIFICATIE = 1350;

  INSERT INTO TMP_OBLIGVAMA_INITIAL(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE)
  SELECT CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE
  FROM
    OBLIGPIF O
  WHERE
    EXISTS (SELECT CODGENERAL FROM TMP_GENERAL_LITIGII WHERE CODGENERAL = O.CODGENERAL);

  INSERT INTO TMP_STINGERE_ASOCIAT (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM
    STINGERE S
  WHERE
    EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL WHERE CODOBLIGPIF = S.CODSTINGATORPIF);




  -- ACUM PUN IN TMP_GENERAL SI TMP_OBLIGPIF CELE CU 1303
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE
  FROM
    GENERAL G,
    COMPENS C
  WHERE
    SEMNIFICATIE  IN (1301, 1303)
    AND TIPDOC IN (28)
    AND C.CODCOMPENS = G.CODDOC
    AND C.PARTD = aCODPART
    AND C.PARTC = aCODPART
    AND C.AN * 12 + C.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;



--OBLIGATII DIN INTRARI
  INSERT INTO TMP_GENERAL
   (CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG)
  SELECT
    CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG
  FROM
    GENERAL G
  WHERE
--   TIPDOC IN (1, 2, 3, 4, 5, 9)
   ((TIPDOC IN (1, 2, 3, 4, 9)) OR (TIPDOC = 5 AND SEMNIFICATIE &lt;&gt; 130))
   AND
  (SELECT PARTENER FROM INTRARI I WHERE CODINTR = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM INTRARI I WHERE CODINTR = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--OBLIGATII VAMA
  INSERT INTO TMP_GENERAL
   (CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG)
  SELECT
    CODGENERAL,
    TIPDOC,
    CODDOC,
    MONEDA,
    CURS,
    TVA,
    SEMNIFICATIE,
    ICONTAVANS,
    PROCTVAAVANS,
    FARAREG
  FROM
    GENERAL G
  WHERE
   TIPDOC = 5
   AND SEMNIFICATIE = 130
   AND
  (SELECT CODVAMA FROM DVI D WHERE CODDVI = G.CODDOC) = aCODPART
   AND (SELECT I.AN * 12 + I.LUNA
   FROM
    INTRARI I,
    DVI D
   WHERE
       CODDVI = G.CODDOC
   AND D.CODINTR = I.CODINTR
   )  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;



--OBLIGATII DIN IESIRI
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG FROM GENERAL G WHERE TIPDOC IN (19, 20, 21, 22, 26) AND
  (SELECT PARTENER FROM IESIRI I WHERE CODIES = G.CODDOC) = aCODPART AND
  (SELECT I.AN * 12 + I.LUNA FROM IESIRI I WHERE CODIES = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;

--OBLIGATII DIN TREZOR1
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG FROM GENERAL G
  WHERE
    TIPDOC IN (29, 30, 31, 33)
    AND SEMNIFICATIE  NOT IN (300, 400, 500, 600, 800, 801 ) -- exclud CECURI SI LINI CE STING CECURI (TRATATE MAI JOS)
    AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
    AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--OBLIGATII DIN NOTE CONTABILE
  INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG)
  SELECT
     G.CODGENERAL,
     G.TIPDOC,
     G.CODDOC,
     G.MONEDA,
     G.CURS,
     G.TVA,
     G.SEMNIFICATIE,
     G.ICONTAVANS,
     G.PROCTVAAVANS,
     G.FARAREG
   FROM
     GENERAL G,
     NC1 N1,
     NC N
  WHERE
    G.TIPDOC = 35
    AND G.SEMNIFICATIE  IN (1200, 1201 )
    AND N1.CODNC1 = G.CODDOC
    AND N.CODNC = N1.CODNC
    AND N.PART  = aCODPART
    AND N.AN * 12 + N.LUNA   &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


--am completat TMP_GENERAL; preiau TMP_OBLIGPIF
  FOR V_REC IN (SELECT * FROM TMP_GENERAL) LOOP
  INSERT INTO TMP_OBLIGPIF
    (CODOBLIGPIF,
     CODGENERAL,
     VALOARE,
     TERMEN,
     MAJORARI,
     ADAOSDOC,
     GRATIE,
     CODPART,
     ICONT,
     SEMNIFICATIE,
     MONEDA,
     FARAREG,
     CURS,
     TVA,
     SUMALEI,
     SUMAVALUTA,
     NRDOC,
     DATADOC,
     AGENT,
     CODLOCATIE,
     OBS,
     SIMBOLCONT,
     DESCRSEMNIF,
     SUBUNITATEA,
     PROCTVAAVANS,
     CODOBLIGASOCIAT,
     VALPROVIZION,
     TIPTVA,
     TIPTRANZACTIE,
     PRORATA,
     SERIADOC,
     CURSDOCSTINS,
     CODCENTRU,
     CODTIPPARTINCERT)

   SELECT
     CODOBLIGPIF,
     CODGENERAL,
     VALOARE,
     TERMEN,
     MAJORARI,
     ADAOSDOC,
     GRATIE,
     CODPART,
     ICONT,
     SEMNIFICATIE,
     V_REC.MONEDA,
     V_REC.FARAREG,
     V_REC.CURS,
     V_REC.TVA,
   (CASE
       WHEN V_REC.MONEDA =  0 THEN O.VALOARE
       WHEN V_REC.MONEDA &lt;&gt; 0 THEN ROUND(O.VALOARE * V_REC.CURS, 2)
    END),

   (CASE
       WHEN V_REC.MONEDA =  0 THEN 0
       WHEN V_REC.MONEDA &lt;&gt; 0 THEN O.VALOARE
    END),

    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT NRDOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130   THEN (SELECT NRDOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130   THEN (SELECT NRDOC FROM DVI D WHERE CODDVI  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT NRDOC FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT NRDOC FROM TREZOR1 WHERE CODTREZOR1  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT I.NRDOC FROM OBLIGPIF OBF, GENERAL GF, IESIRI I WHERE OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT AND GF.CODGENERAL = OBF.CODGENERAL AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC )
        WHEN V_REC.TIPDOC IN (35)                 THEN (SELECT NRDOC FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
     END),

    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT DATADOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND SEMNIFICATIE &lt;&gt; 130   THEN (SELECT DATADOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND SEMNIFICATIE = 130   THEN (SELECT DATADOC FROM DVI WHERE CODDVI  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT DATADOC FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT DATADOC FROM TREZOR1 WHERE CODTREZOR1  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT I.DATADOC FROM OBLIGPIF OBF, GENERAL GF, IESIRI I WHERE OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT AND GF.CODGENERAL = OBF.CODGENERAL AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC )
        WHEN V_REC.TIPDOC IN (35)                 THEN (SELECT DATADOC FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
     END),

    (CASE
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT AGENT   FROM IESIRI  WHERE CODIES     = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT I.AGENT FROM OBLIGPIF OBF, GENERAL GF, IESIRI I WHERE OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT AND GF.CODGENERAL = OBF.CODGENERAL AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC )
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT AGENT FROM TREZOR1 WHERE CODTREZOR1  = V_REC.CODDOC)
        ELSE 0
     END),

    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT CODLOCATIE FROM INTRARI WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130   THEN (SELECT CODLOCATIE FROM INTRARI WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT CODLOCATIE FROM IESIRI  WHERE CODIES     = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)         THEN (SELECT CODLOCATIE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT I.CODLOCATIE FROM OBLIGPIF OBF, GENERAL GF, IESIRI I WHERE OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT AND GF.CODGENERAL = OBF.CODGENERAL AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC )
        ELSE 0
     END),
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT SUBSTR(OBS, 1, 250)   FROM INTRARI WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130   THEN (SELECT SUBSTR(OBS, 1, 250)    FROM INTRARI WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130   THEN (SELECT SUBSTR(OBS, 1, 250)    FROM DVI WHERE CODDVI    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT SUBSTR(OBS, 1, 250) FROM IESIRI   WHERE CODIES    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT SUBSTR(OBS, 1, 250) FROM TREZOR1  WHERE CODTREZOR1 = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT SUBSTR(I.OBS, 1, 250)  FROM OBLIGPIF OBF, GENERAL GF, IESIRI I WHERE OBF.CODOBLIGPIF = O.CODOBLIGASOCIAT AND GF.CODGENERAL = OBF.CODGENERAL AND I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC )
        WHEN V_REC.TIPDOC IN (35)                 THEN (SELECT SUBSTR(N.OBS, 1, 250) FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
        ELSE NULL
     END),

     PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA))),

--    (CASE
--        WHEN V_REC.SEMNIFICATIE IN (310, 410) THEN &apos;F&apos;
--        ELSE &apos;P/I&apos;
--     END),

     (CASE
        WHEN V_REC.SEMNIFICATIE IN (100, 130 ) THEN
          CASE
          WHEN (SELECT NVL(VALOARE, 0) FROM OBLIGPIF O WHERE O.CODGENERAL = V_REC.CODGENERAL AND ROWNUM = 1)  &lt; 0
            THEN &apos;De incasat&apos;
            ELSE &apos;De platit&apos;
          END
        WHEN V_REC.SEMNIFICATIE IN (200 ) THEN
          CASE
          WHEN (SELECT NVL(VALOARE, 0) FROM OBLIGPIF O WHERE O.CODGENERAL = V_REC.CODGENERAL AND ROWNUM = 1)  &lt; 0
            THEN &apos;De platit&apos;
            ELSE &apos;De incasat&apos;
          END
        WHEN V_REC.SEMNIFICATIE IN (1303)       THEN &apos;Litigii&apos;
        WHEN V_REC.SEMNIFICATIE IN (1301)       THEN &apos;De incasat&apos;
        WHEN V_REC.SEMNIFICATIE IN (110, 210)   THEN &apos;Avans facturat&apos;
        WHEN V_REC.SEMNIFICATIE IN (120, 220)   THEN &apos;Garantie&apos;
        WHEN V_REC.SEMNIFICATIE IN (140, 240)   THEN &apos;De facturat&apos;
        WHEN V_REC.SEMNIFICATIE IN (310)        THEN &apos;Avans platit&apos;
        WHEN V_REC.SEMNIFICATIE IN (330, 430)   THEN &apos;Avans din retur&apos;
        WHEN V_REC.SEMNIFICATIE IN (410)        THEN &apos;Avans incasat&apos;
        WHEN V_REC.SEMNIFICATIE IN (1200) AND  ICONT &lt;&gt; 3   THEN &apos;De platit&apos;
        WHEN V_REC.SEMNIFICATIE IN (1200) AND  ICONT IN (3) THEN &apos;De incasat&apos;
        WHEN V_REC.SEMNIFICATIE IN (1201)       THEN &apos;De incasat&apos;
      END),


    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4,9)   THEN (SELECT SUBUNITATEA   FROM INTRARI              WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130   THEN (SELECT SUBUNITATEA   FROM INTRARI              WHERE CODINTR    = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE = 130   THEN (SELECT I.SUBUNITATEA  FROM DVI D, INTRARI I     WHERE D.CODDVI = V_REC.CODDOC AND I.CODINTR = D.CODINTR)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT SUBUNITATEA   FROM IESIRI               WHERE CODIES     = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT T.SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE CODTREZOR1 = V_REC.CODDOC AND T1.CODTREZOR = T.CODTREZOR)
        WHEN V_REC.TIPDOC IN (28)                 THEN (SELECT SUBUNITATEA   FROM COMPENS              WHERE CODCOMPENS  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (35)                 THEN (SELECT N.SUBUNITATEA FROM NC N, NC1 N1 WHERE N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC)
     END),
     V_REC.PROCTVAAVANS,
     CODOBLIGASOCIAT,
     CASE
       WHEN V_REC.SEMNIFICATIE = 1303
       THEN
          (
           CASE
             WHEN NVL(V_REC.MONEDA, 0) =  0 THEN ROUND(O.VALOARE * O.COEFPROVIZION, 3)
             ELSE ROUND(ROUND(O.VALOARE * V_REC.CURS, 2) * O.COEFPROVIZION, 3)
           END
          )
       ELSE 0
     END,
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4,9)   THEN (SELECT TIPTVA   FROM INTRARI              WHERE CODINTR    = V_REC.CODDOC)
        ELSE NULL
     END),
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4,9)   THEN (SELECT TIPTRANZACTIE   FROM INTRARI              WHERE CODINTR    = V_REC.CODDOC)
        ELSE NULL
     END),
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4,9)   THEN (SELECT PRORATA   FROM INTRARI              WHERE CODINTR    = V_REC.CODDOC)
        ELSE NULL
     END),
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT SERIADOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC = 5 AND V_REC.SEMNIFICATIE &lt;&gt; 130   THEN (SELECT SERIADOC FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT SERIADOC FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (29, 30, 31, 33)     THEN (SELECT SERIEDOC FROM TREZOR1 WHERE CODTREZOR1  = V_REC.CODDOC)
     END),
    (CASE
        WHEN V_REC.TIPDOC IN (1, 2, 3, 4, 9)   THEN (SELECT CURS FROM INTRARI WHERE CODINTR  = V_REC.CODDOC)
        WHEN V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT CURS FROM IESIRI  WHERE CODIES  = V_REC.CODDOC)
     END),
     CODCENTRU,
     CASE
        WHEN V_REC.TIPDOC IN (28) THEN (SELECT CODTIPPARTINCERT FROM COMPENS  WHERE CODCOMPENS  = V_REC.CODDOC)
        ELSE NULL
     END
    FROM
      OBLIGPIF O
    WHERE
      CODGENERAL = V_REC.CODGENERAL;
  END LOOP;

-- TEBUIE SA STERG DIN TMP_OBLIGPIF FACTURILE CARE AU FOST TRECUTE PE LITIGIU
  FOR V_REC IN
  (SELECT
     CODOBLIGPIF,
     CODGENERAL
   FROM
     TMP_OBLIGPIF O
   WHERE
     O.SEMNIFICATIE = 200
--     AND O.VALOARE = 0
     AND EXISTS (SELECT CODOBLIGASOCIAT FROM TMP_OBLIGPIF WHERE CODOBLIGASOCIAT = O.CODOBLIGPIF)
   )
   LOOP
     DELETE FROM TMP_GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL;
     DELETE FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
   END LOOP;

-- PE OBLIGATIILE CU 1303 PUN PE COLOANA PROCENT CODGENERAL FACTURA
UPDATE TMP_OBLIGPIF O
SET
 PROCENT = (SELECT CODGENERAL FROM OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGASOCIAT);



--START CECURI
  INSERT INTO TMP_GENERAL_CECURI(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE
    TIPDOC  = 31
    AND SEMNIFICATIE IN (500, 600) -- CECURI
    AND (SELECT CODPART FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC) = aCODPART
    AND (SELECT T.AN * 12 + T.LUNA FROM TREZOR1 T WHERE CODTREZOR1 = G.CODDOC)  &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA;


   INSERT INTO TMP_TREZOR1
    (
     CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC,  NRDOC, DATADOC, VALDOC, CURS, COMISION, CODMONEDA,
     OBIECTTRANZ, CODPART, CODBANCA,  TIPDECONT, DATADECONT,  AN, LUNA, OBS, AGENT, ANULAT, INFOCONTBANCAR, SUBUNITATEA
    )
    SELECT
      T1.CODTREZOR1, T1.CODTREZOR,   INDEXLOCAL, T1.TIPTRANZ, T1.CARNETDOC, T1.DOC,  T1.NRDOC, T1.DATADOC, VALDOC, CURS, COMISION, M.CODMONEDA,
      OBIECTTRANZ, CODPART, T.CODBANCA, TIPDECONT, DATADECONT,  T1.AN, T1.LUNA, T1.OBS, T1.AGENT, ANULAT,
       BK.SIMBOL || &apos;/&apos; || BC.NRCONT || CHR(13) || M.SIMBOL,
       T.SUBUNITATEA
     FROM
       TREZOR1 T1,
       TREZOR  T
        LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
        LEFT OUTER JOIN NBANK     BK ON BK.CODBANK   = BC.CODBANK
        LEFT OUTER JOIN NMONEDE   M  ON M.CODMONEDA   = BC.CODMONEDA
     WHERE
       CODTREZOR1 IN (SELECT CODDOC FROM TMP_GENERAL_CECURI)
       AND T.CODTREZOR = T1.CODTREZOR
;


   -- MI-AM TRAS IN TMP_GENERAL_CECURI LINIILE CU 500/600 (adica CEC-ri).
   -- TREBUIE SA IDENTIFIC SI LINIILE CU CARE CEC-urile fac stingeri
  INSERT INTO TMP_GENERAL_CECURI(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
  SELECT CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE FROM GENERAL G
  WHERE TIPDOC = 31
    AND SEMNIFICATIE IN (300, 400)
    AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);

  INSERT INTO TMP_OBLIGPIF_ASOCIAT (
    CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, ADAOSDOC, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, VALOAREAFISATA,
    CODTREZOR1)
  SELECT
    CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, ADAOSDOC, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, VALOAREAFISATA,
    (SELECT DISTINCT CODTREZOR1 FROM TMP_TREZOR1 T1, TMP_GENERAL_CECURI G WHERE G.CODGENERAL = OB.CODGENERAL AND T1.CODTREZOR1 = G.CODDOC)
  FROM (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL_CECURI)) OB
  ORDER BY CODOBLIGPIF;

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  SELECT CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE
  FROM STINGERE
  WHERE CODSTINSPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
    AND CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT);

  DELETE TMP_STINGERE_INITIAL;
  INSERT INTO TMP_STINGERE_INITIAL
  SELECT * FROM TMP_STINGERE;

  INSERT INTO TMP_STINGERE_INITIAL
  SELECT * FROM TMP_STINGERE_ASOCIAT;

  UPDATE TMP_OBLIGPIF_ASOCIAT OA
  SET
    CODTREZOR1      = NVL((SELECT CODDOC FROM TMP_GENERAL_CECURI WHERE CODGENERAL = OA.CODGENERAL), 0),
    DENDOCLEGATURA  = NVL((SELECT TO_CHAR(NRDOC) || &apos;/&apos; || DATADOC FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)), &apos;???&apos;),
    SIMBOLCONT      = NVL((SELECT SIMBOLCONT FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)), &apos;???&apos;),
    CODOBLIGASOCIAT = NVL((SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF), 0),
    CURS            = NVL((SELECT CURS FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = (SELECT CODSTINSPIF FROM TMP_STINGERE WHERE CODSTINGATORPIF = OA.CODOBLIGPIF)), 1)
  WHERE SEMNIFICATIE IN (300, 400);


-- INSEREZ LINII CARE FAC LEGATURA INTRE AVANSURI SI CEC-uri (linii CARE NU SUNT SALVATE IN BAZA DE DATE)

  FOR V_REC_AVANSURI IN
  (SELECT G.CODGENERAL, G.TIPDOC, G.CODDOC, G.SEMNIFICATIE, O.CODOBLIGPIF, O.NRDOC, O.DATADOC, O.SIMBOLCONT, O.SUMALEI,
         O.SUMAVALUTA, G.MONEDA
   FROM
   TMP_GENERAL G, TMP_OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL AND G.SEMNIFICATIE  IN (310, 410) AND G.TIPDOC = 31)
  LOOP
    aCODGENERAL_AVANS := 0;
    aCODOBLIGPIF_AVANS := 0;
    FOR VREC_TREZOR1_CEC IN (SELECT * FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC_AVANSURI.CODDOC)
    LOOP
      aCODGENERAL_AVANS  := aCODGENERAL_AVANS  + 1;
      aCODOBLIGPIF_AVANS := aCODOBLIGPIF_AVANS + 1;

      INSERT INTO TMP_GENERAL_CECURI(CODGENERAL, TIPDOC, CODDOC, SEMNIFICATIE)
      VALUES (aCODGENERAL_AVANS, 31, VREC_TREZOR1_CEC.CODTREZOR1, -V_REC_AVANSURI.SEMNIFICATIE);

      INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, VALOARE, SEMNIFICATIE, CODOBLIGASOCIAT, DENDOCLEGATURA, SIMBOLCONT, CODTREZOR1)
      VALUES(aCODOBLIGPIF_AVANS, aCODGENERAL_AVANS,
      CASE
       WHEN V_REC_AVANSURI.MONEDA = 0 THEN V_REC_AVANSURI.SUMALEI
       ELSE V_REC_AVANSURI.SUMAVALUTA
      END, -V_REC_AVANSURI.SEMNIFICATIE, V_REC_AVANSURI.CODOBLIGPIF,
            TO_CHAR(V_REC_AVANSURI.NRDOC) || &apos;\&apos; || V_REC_AVANSURI.DATADOC, V_REC_AVANSURI.SIMBOLCONT,
            VREC_TREZOR1_CEC.CODTREZOR1);
    END LOOP;
  END LOOP;

-- END CECURI




 -- ACTUALIZEZ CAMPUL &quot;INITIALIZARI&quot; PENTRU OBLIGATIILE BAGATE MANUAL PE MACHETA DE INITIALIZARI
   UPDATE TMP_GENERAL G
   SET
     INITIALIZARI =
     ( CASE
         WHEN TIPDOC IN (1, 2, 3, 4, 5, 9)     THEN (SELECT INITIALIZARI FROM INTRARI WHERE CODINTR    = G.CODDOC)
         WHEN TIPDOC IN (19, 20, 21, 22, 26) THEN (SELECT INITIALIZARI FROM IESIRI  WHERE CODIES     = G.CODDOC)
         WHEN TIPDOC IN (29, 30, 31, 33)     THEN (SELECT INITIALIZARI FROM TREZOR1 WHERE CODTREZOR1 = G.CODDOC)
         ELSE 0
       END
     );


-- LINII AVIZE INTRARE
  INSERT INTO  TMP_INTRARI1
    (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GESTACT, CodObiect, PretOrig, PU, Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact, NrCertif, TG, PUMaximal, PURidicata, ProcAdaos, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, DenUM, Valoare, Paritate, ProcTVA, GestImplicita, ARETG, CERTIFICAT, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, DenObiect, CODGENERAL )
    SELECT * FROM
     (SELECT i1.CodIntr1, i1.CodIntr, i1.IndexLocal, I1.CUSTODIE, i1.TipLinie, i1.Umsec, i1.An, i1.Luna,
             i1.ContServ, i1.CONTDISCOUNT, i1.GestAct, i1.CodObiect, i1.PretOrig, i1.PU * NVL(u1.Paritate, 1),
             i1.Cant/ NVL(u1.Paritate, 1), i1.TVA, i1.AdDim, I1.MIFIX, I1.CODOBIECTORIG, I1.PARITATEORIG, I1.COEFDISCMAJ, I1.OBS,

             i1.RestFact, i1.NrCertif, i1.TG, i1.PUMaximal, i1.PURidicata, i1.procadaos, i1.FURNAVIZSUBUNIT,  I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
             CASE
               WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
               ELSE u1.Den_UM1
             END,
             (
               CASE
                 WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  i1.Cant * i1.PU
                 ELSE I1.RESTFACT
               END
             ),
             u1.Paritate,
             CASE
               WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
               ELSE 0
             END,
             A.GESTIMPLICITA,
             A.ARETG,
             A.CERTIFICAT,
             NART1LUNA.CODTVA,
             NART1LUNA.CODACCIZE,
             NART1LUNA.CODTAXA1,
             NART1LUNA.CODTAXA2,
             O.DENUMIRE,
             G.CODGENERAL
      FROM
        INTRARI1 i1
        left outer join NartObj o ON o.CodObiect  = i1.CodObiect
        left outer join Nart a    ON a.CodArticol = o.CodArticol
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND PKG_GLOBALS.ANLUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
        LEFT OUTER JOIN NUM1 u1   ON u1.CodUM1    = i1.UmSec,
        TMP_GENERAL G
      WHERE
        i1.CodIntr =  G.CODDOC AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;) AND
        G.TIPDOC = 2 AND G.SEMNIFICATIE = 140
     )
     ORDER BY IndexLocal;



-- LINII AVIZE IESIRE
  INSERT INTO TMP_IESIRI1
    (CODIES1,  CODIES,    INDEXLOCAL,  TIPLINIE,       UMSEC,
     CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT,   CODOBIECT,   PRETORIG,       PU,
     CANT,     TVA,       CONT,        PROCDISC,       ADDIM,
     RESTFACT, PUMAXIMAL, GARANTIE,    DENUM,          VALOARE,
     PARITATE, PROCTVA,   CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG,
     CODTVA,   CODACCIZE, CODTAXA1,    CODTAXA2, CODCLASA,
     DENOBIECT, CODGENERAL
    )
    SELECT * FROM
     (SELECT
        I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC,
        I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU, I1.MIFIX, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * NVL(U1.PARITATE,1),
        I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM,
        I1.RESTFACT,
        I1.PUMAXIMAL, I1.GARANTIE,
        CASE
          WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
          ELSE U1.DEN_UM1
        END,
        (
         CASE
           WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
           ELSE I1.RESTFACT
         END
        ),
        U1.PARITATE,

        CASE
          WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
          ELSE 0
        END,
        I1.CODOBLIGSTORNO,
        I1.CURSFACTURAAVANS,
        I1.COEFDISCMAJ, I1.OBS,
        I1.CODOBIECTORIG, I1.PARITATEORIG,
        NART1LUNA.CODTVA,
        NART1LUNA.CODACCIZE,
        NART1LUNA.CODTAXA1,
        NART1LUNA.CODTAXA2, A.CLASA,
        O.DENUMIRE,
        G.CODGENERAL
      FROM
        IESIRI1 I1
        LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
        LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
        LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND PKG_GLOBALS.ANLUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP 
        LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC,
        TMP_GENERAL G
      WHERE
        I1.CODIES =  G.CODDOC AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;) AND
        G.TIPDOC  = 20 AND G.SEMNIFICATIE = 240
     ) ORDER BY INDEXLOCAL;


  UPDATE TMP_OBLIGPIF
  SET
  PLATA = CASE
           WHEN SEMNIFICATIE IN (330, 430) THEN 2
           WHEN SEMNIFICATIE = 310         THEN 1
           WHEN SEMNIFICATIE = 410         THEN 1
           WHEN SEMNIFICATIE = 110         THEN 0
           WHEN SEMNIFICATIE = 210         THEN 0
           WHEN SEMNIFICATIE = 120         THEN 0
           WHEN SEMNIFICATIE = 220         THEN 0
           ELSE 1
          END
  WHERE
  ICONT IN (4, 5, 12, 13, 14);


  UPDATE TMP_GENERAL G
  SET SUBUNITATEA = (SELECT DISTINCT SUBUNITATEA FROM TMP_OBLIGPIF O WHERE O.CODGENERAL = G.CODGENERAL);


  FOR V_REC IN
  (SELECT O.CODOBLIGPIF, G.CODDOC
   FROM
     TMP_OBLIGPIF O,
     TMP_GENERAL G
     WHERE
       O.SEMNIFICATIE = 200
       AND O.CODGENERAL = G.CODGENERAL
   )
   LOOP
     UPDATE
       TMP_OBLIGPIF
     SET
       TVA = (SELECT TVADOC FROM IESIRI WHERE CODIES = V_REC.CODDOC)
     WHERE
       CODOBLIGPIF = V_REC.CODOBLIGPIF;
   END LOOP;


   FOR V_REC IN (SELECT * FROM TMP_GENERAL WHERE SEMNIFICATIE = 100)
   LOOP
     UPDATE TMP_OBLIGPIF
     SET
       TVAINCASARE = (SELECT TVAINCASARE FROM INTRARI WHERE CODINTR = V_REC.CODDOC)
     WHERE
       CODGENERAL = V_REC.CODGENERAL  ;
   END LOOP;

   FOR V_REC IN (SELECT * FROM TMP_GENERAL WHERE SEMNIFICATIE = 200)
   LOOP
     UPDATE TMP_OBLIGPIF
     SET
       TVAINCASARE = (SELECT TVAINCASARE FROM IESIRI WHERE CODIES = V_REC.CODDOC)
     WHERE
       CODGENERAL = V_REC.CODGENERAL  ;
   END LOOP;


   FOR V_REC IN (SELECT G.TIPDOC, G.CODDOC, O.SEMNIFICATIE, G.CODGENERAL FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.TVAINCASARE = 1 AND O.CODGENERAL = G.CODGENERAL)
   LOOP
     IF V_REC.SEMNIFICATIE = 100 THEN
      INSERT INTO  TMP_INTRARI1_TVAINCAS
           (CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct, CodObiect, PretOrig, PU, Cant, TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact, NrCertif, TG, PUMaximal, PURidicata, ProcAdaos, FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, DenUM, Valoare, Paritate, ProcTVA, GestImplicita, TVANEDED, ARETG, CERTIFICAT, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, DenObiect, CODGENERAL )
           SELECT * FROM
            (SELECT i1.CodIntr1, i1.CodIntr, i1.IndexLocal, I1.CUSTODIE, i1.TipLinie, i1.Umsec, i1.An, i1.Luna,
                    i1.ContServ, i1.CONTDISCOUNT, i1.GestAct, i1.CodObiect, i1.PretOrig, i1.PU * NVL(u1.Paritate, 1),
                    i1.Cant/ NVL(u1.Paritate, 1), i1.TVA, i1.AdDim, I1.MIFIX, I1.CODOBIECTORIG, I1.PARITATEORIG, I1.COEFDISCMAJ, I1.OBS,

                    i1.RestFact, i1.NrCertif, i1.TG, i1.PUMaximal, i1.PURidicata, i1.procadaos, i1.FURNAVIZSUBUNIT,  I1.DATAACHIZAVIZSUBUNIT, I1.CODOBLIGSTORNO, I1.CURSFACTURAAVANS,
                    CASE
                      WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
                      ELSE u1.Den_UM1
                    END,
                    (
                      CASE
                        WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  i1.Cant * i1.PU
                        ELSE I1.RESTFACT
                      END
                    ),
                    u1.Paritate,
                    CASE
                      WHEN UPPER(I1.TIPLINIE) IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(a.CodArticol, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
                      ELSE 0
                    END,
                    A.GESTIMPLICITA,
                    I1.TVANEDED,
                    A.ARETG,
                    A.CERTIFICAT,
                    NART1LUNA.CODTVA,
                    NART1LUNA.CODACCIZE,
                    NART1LUNA.CODTAXA1,
                    NART1LUNA.CODTAXA2,
                    O.DENUMIRE,
                    V_REC.CODGENERAL
             FROM
               INTRARI  I,
               INTRARI1 i1
               left outer join NartObj o ON o.CodObiect  = i1.CodObiect
               left outer join Nart a    ON a.CodArticol = o.CodArticol
               LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND PKG_GLOBALS.ANLUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
               LEFT OUTER JOIN NUM1 u1   ON u1.CodUM1    = i1.UmSec
             WHERE
               I.CODINTR = V_REC.CODDOC AND I.TIPDOC = V_REC.TIPDOC
               AND I1.CodIntr =  I.CODINTR AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;)
            )
            ORDER BY IndexLocal;
     END IF;

     IF V_REC.SEMNIFICATIE = 200 THEN
      INSERT INTO TMP_IESIRI1_TVAINCAS
        (CODIES1,  CODIES,    INDEXLOCAL,  TIPLINIE,       UMSEC,
         CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT,   CODOBIECT,   PRETORIG,       PU,
         CANT,     TVA,       CONT,        PROCDISC,       ADDIM,
         RESTFACT, PUMAXIMAL, GARANTIE,    DENUM,          VALOARE,
         PARITATE, PROCTVA,   CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG,
         CODTVA,   CODACCIZE, CODTAXA1,    CODTAXA2, CODCLASA,
         DENOBIECT, CODGENERAL
        )
        SELECT * FROM
         (SELECT
            I1.CODIES1, I1.CODIES, I1.INDEXLOCAL, I1.TIPLINIE, I1.UMSEC,
            I1.CONTSERV, I1.CONTDISCOUNT, I1.CODCRITERIU, I1.MIFIX, I1.GESTACT, I1.CODOBIECT, I1.PRETORIG, I1.PU * NVL(U1.PARITATE,1),
            I1.CANT/ NVL(U1.PARITATE, 1), I1.TVA, I1.CONT, I1.PROCDISC, I1.ADDIM,
            I1.RESTFACT,
            I1.PUMAXIMAL, I1.GARANTIE,
            CASE
              WHEN I1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN &apos;%&apos;
              ELSE U1.DEN_UM1
            END,
            (
             CASE
               WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN  I1.CANT * I1.PU
               ELSE I1.RESTFACT
             END
            ),
            U1.PARITATE,

            CASE
              WHEN I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;) THEN PKG_SELECTARTICOLE.GETPROCENTTVA(A.CODARTICOL, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
              ELSE 0
            END,
            I1.CODOBLIGSTORNO,
            I1.CURSFACTURAAVANS,
            I1.COEFDISCMAJ, I1.OBS,
            I1.CODOBIECTORIG, I1.PARITATEORIG,
            NART1LUNA.CODTVA,
            NART1LUNA.CODACCIZE,
            NART1LUNA.CODTAXA1,
            NART1LUNA.CODTAXA2, A.CLASA,
            O.DENUMIRE,
            V_REC.CODGENERAL
          FROM
            IESIRI I,
            IESIRI1 I1
            LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT  = I1.CODOBIECT
            LEFT OUTER JOIN NART A    ON A.CODARTICOL = O.CODARTICOL
            LEFT OUTER JOIN NART1 NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL AND PKG_GLOBALS.ANLUNALUCRU BETWEEN NART1LUNA.ALSTART AND NART1LUNA.ALSTOP
            LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1    = I1.UMSEC
          WHERE
            I.CODIES = V_REC.CODDOC AND I.TIPDOC = V_REC.TIPDOC
            AND I1.CODIES =  I.CODIES AND I1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;)
         ) ORDER BY INDEXLOCAL;
     END IF;
   END LOOP;

-- memorez liniile de obligatii la intrare pentru a putea sti la iesire ce linii s-au sters
  DELETE TMP_OBLIGPIF_INITIAL;
  INSERT INTO TMP_OBLIGPIF_INITIAL
  SELECT * FROM TMP_OBLIGPIF
  UNION ALL
  SELECT * FROM TMP_OBLIGPIF_ASOCIAT
  UNION ALL
  SELECT * FROM TMP_OBLIGVAMA_INITIAL; -- aici tin obligatii 1350



   DELETE TMP_TREZOR1_INITIAL;

   INSERT INTO TMP_TREZOR1_INITIAL (CODTREZOR1) SELECT CODTREZOR1 FROM TMP_TREZOR1;

   COMMIT;
END;


PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
 ANI                NUMBER(5);
 LUNAI              NUMBER(2);
 ANP                NUMBER(5);
 LUNAP              NUMBER(2);

 aPART              NUMBER(20);
 V_CODDOC           NUMBER(20);
 V_COD              NUMBER(20);
 V_CODGENERAL       NUMBER(20);
 NRDOC              NUMBER(20);
 aCODTREZOR         NUMBER(20);
 aCODTREZOR1        NUMBER(20);
 aCODOBLIGPIF       NUMBER(20);
 NRDOCS             NUMBER(20);
 NRNIRS             NUMBER(20);
 NR                 NUMBER(20);
 CODFACTURA         NUMBER(20);
 CODOBLIGFACTURA    NUMBER(20);
 CODGENERALFACTURA  NUMBER(20);
 CODOBLIGCOMPENS    NUMBER(20);
 CODGENERALCOMPENS  NUMBER(20);
 aVALOARE           NUMBER(20, 7);
 aVOLUMTRANZF       NUMBER(20, 7);
 aVOLUMTRANZC       NUMBER(20, 7);
 DATANEXTREG        DATE;
 aDATATVA           DATE;
 aTVAINCASARE       NUMBER(1) := 0;
BEGIN

 PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);

 SELECT CODPART INTO aPART FROM TMP_SOLDINI;

 IF OPERATION = 0 THEN -- UPDATE


   SELECT  CODSOLDINI INTO RecId FROM TMP_SOLDINI;
   UPDATE SOLDINI SET CODPART = aPART WHERE CODSOLDINI = RecID;



-- VERIFIC INREGISTRARILE CARE AU FOST STERSE;

  DELETE FROM INTRARI1 WHERE
  (CODINTR IN (SELECT G.CODDOC FROM TMP_OBLIGPIF_INITIAL O, GENERAL G WHERE G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 2 AND G.SEMNIFICATIE = 140 ))AND
  (CODINTR1 NOT IN (SELECT CODINTR1 FROM TMP_INTRARI1));

  DELETE FROM IESIRI1 WHERE
  (CODIES IN (SELECT G.CODDOC FROM TMP_OBLIGPIF_INITIAL O, GENERAL G WHERE G.CODGENERAL = O.CODGENERAL AND  G.TIPDOC = 20 AND G.SEMNIFICATIE = 240 ))AND
  (CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1));


  DELETE FROM INTRARI1 WHERE
  (CODINTR IN (SELECT G.CODDOC FROM TMP_OBLIGPIF_INITIAL O, GENERAL G WHERE O.TVAINCASARE = 1 AND G.CODGENERAL = O.CODGENERAL AND G.SEMNIFICATIE = 100 ))AND
  (CODINTR1 NOT IN (SELECT CODINTR1 FROM TMP_INTRARI1_TVAINCAS));

  DELETE FROM IESIRI1 WHERE
  (CODIES IN (SELECT G.CODDOC FROM TMP_OBLIGPIF_INITIAL O, GENERAL G WHERE O.TVAINCASARE = 1 AND G.CODGENERAL = O.CODGENERAL AND G.SEMNIFICATIE = 200 ))AND
  (CODIES1 NOT IN (SELECT CODIES1 FROM TMP_IESIRI1_TVAINCAS));


  DELETE FROM STINGERE WHERE
  CODSTINGERE     IN (SELECT CODSTINGERE FROM TMP_STINGERE_INITIAL) AND
  CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE)AND
  CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE_ASOCIAT);


  DELETE TMP_DOCS;

  --  CAUT SA VAD DACA NU TREBUIE SA CURAT  OBLIGATIILE DIN FACTURILE TRECUTE IN LITIGIU
  FOR V_REC IN
  (SELECT
    OI.*,
    G.TIPDOC,
    G.CODDOC,
    NVL(OO.CODOBLIGASOCIAT, 0) AS CODFACTURA
   FROM
     TMP_OBLIGPIF_INITIAL OI
     LEFT OUTER JOIN TMP_OBLIGPIF OO ON OO.CODOBLIGPIF = OI.CODOBLIGPIF,
     GENERAL G
   WHERE
    OI.SEMNIFICATIE = 1303
    AND NVL(OI.CODOBLIGASOCIAT, 0) &lt;&gt; 0
    AND NVL(OI.PROCENT, 0) &lt;&gt; 0
    AND G.CODGENERAL = OI.PROCENT
  )
  LOOP
    IF V_REC.CODOBLIGASOCIAT &lt;&gt; V_REC.CODFACTURA THEN

      SELECT COUNT(*) INTO NRDOCS FROM TMP_DOCS WHERE TIPDOC = V_REC.TIPDOC AND CODDOC = V_REC.CODDOC;
      IF NRDOCS = 0 THEN
        INSERT INTO TMP_DOCS (CODDOC, TIPDOC) VALUES (V_REC.CODDOC, V_REC.TIPDOC);
      END IF;

      DELETE FROM GENERAL WHERE CODGENERAL       = V_REC.PROCENT;
      DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGASOCIAT;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF     = V_REC.CODOBLIGASOCIAT;
    END IF;
  END LOOP;


  FOR V_REC IN
  (SELECT * FROM TMP_OBLIGPIF_INITIAL
   WHERE
     CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF) AND
     CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_ASOCIAT) AND
     CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGVAMA_INITIAL)
   )
  LOOP
    FOR V_RECGENERAL IN (SELECT * FROM GENERAL WHERE CODGENERAL = V_REC.CODGENERAL)
    LOOP
      SELECT COUNT(*) INTO NRDOCS FROM TMP_DOCS WHERE TIPDOC = V_RECGENERAL.TIPDOC AND CODDOC = V_RECGENERAL.CODDOC;
      IF NRDOCS = 0 THEN
        INSERT INTO TMP_DOCS (CODDOC, TIPDOC) VALUES (V_RECGENERAL.CODDOC, V_RECGENERAL.TIPDOC);
      END IF;
      DELETE FROM GENERAL WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
    END LOOP;

    DELETE FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;

-- AM CURATAT DETALII DIN OBLIGPIF SI GENERAL; VERIFIC DACA POT CURATA SI DOCUMENTELE
  FOR V_REC IN (SELECT * FROM TMP_DOCS) LOOP
    SELECT COUNT(*) INTO NRDOCS FROM GENERAL WHERE TIPDOC = V_REC.TIPDOC AND CODDOC = V_REC.CODDOC;
    NRNIRS := 0;

    IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
      SELECT COUNT(*) INTO NRNIRS FROM NIR WHERE TIPNIR = V_REC.TIPDOC AND CODINTR = V_REC.CODDOC;
    END IF;


    IF NRDOCS + NRNIRS = 0 THEN
       IF V_REC.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN
         DELETE FROM INTRARI1 WHERE CODINTR = V_REC.CODDOC;
--         DELETE FROM INTRARI WHERE CODINTR = V_REC.CODDOC;
       ELSE
       IF V_REC.TIPDOC IN (19, 20, 21, 22, 26) THEN
         DELETE FROM IESIRI1 WHERE CODIES = V_REC.CODDOC;
--         DELETE FROM IESIRI  WHERE CODIES = V_REC.CODDOC;
       ELSE
       IF V_REC.TIPDOC IN (29, 30, 31, 33) THEN
         FOR V_REC_TREZOR1 IN (SELECT * FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC)
         LOOP
           DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;
--           DELETE FROM TREZOR  WHERE CODTREZOR  = V_REC_TREZOR1.CODTREZOR;
         END LOOP;
       ELSE
       IF V_REC.TIPDOC IN (28) THEN
          DELETE FROM COMPENS  WHERE CODCOMPENS  = V_REC.CODDOC;
       ELSE
       IF V_REC.TIPDOC IN (35) THEN
          DELETE FROM NC1  WHERE CODNC1  = V_REC.CODDOC;
       END IF;
       END IF;
       END IF;
       END IF;
       END IF;
    END IF;
  END LOOP;



/*
-- ESTE POSIBIL CA UTILIZATORUL SA MODIFICE TIPUL CONTULUI ASFTEL INCAT SA FIU NEVOIT SA RENUNT LA INREGISTREA DIN INTRARI/IESIRI/TREZOR1
-- SOLUTIA NU-I ACTIVA PENTRU CA MAI TREBUIE ANALIZATA IN CAZUL CAND SOLDURILE INITIALE PROVIN DIN RUPERE DE FIRME
-- SI AM DETALII LA INTRARI/IESIRI/TREZOR1

   FOR V_RECGENERAL IN
     (SELECT OLDREC.TIPDOC AS OLDTIPDOC, OLDREC.CODDOC AS OLDCODDOC, NEWREC.TIPDOC AS NEWTIPDOC, NEWREC.CODDOC AS NEWCODDOC
      FROM
        TMP_OBLIGPIF_INITIAL OI,
        GENERAL OLDREC,
        TMP_GENERAL NEWREC
      WHERE
        OI.CODGENERAL = OLDREC.CODGENERAL AND OLDREC.CODGENERAL = NEWREC.CODGENERAL
      )
   LOOP
     IF V_RECGENERAL.OLDTIPDOC  IN (1, 2, 3, 4, 5) AND V_RECGENERAL.NEWTIPDOC  NOT IN (1, 2, 3, 4, 5)
     THEN
       DELETE FROM INTRARI WHERE CODINTR = V_RECGENERAL.OLDCODDOC;
     ELSE
     IF V_RECGENERAL.OLDTIPDOC  IN (19, 20, 21, 22, 26) AND V_RECGENERAL.NEWTIPDOC  NOT IN (19, 20, 21, 22, 26)
     THEN
       DELETE FROM IESIRI WHERE CODIES = V_RECGENERAL.OLDCODDOC;
     ELSE
     IF V_RECGENERAL.OLDTIPDOC  IN (29, 30, 31) AND V_RECGENERAL.NEWTIPDOC  NOT IN (29, 30, 31)
      THEN
        DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_RECGENERAL.OLDCODDOC;
     END IF;
     END IF;
     END IF;
   END LOOP;
*/
 -- GENERAL
   FOR V_RECGENERAL IN
   (SELECT * FROM TMP_GENERAL )
   LOOP
     IF (V_RECGENERAL.CODDOC IS NULL) OR (V_RECGENERAL.CODDOC = 0) THEN -- user-ul a umblat la semnificatie si am pierdut legatura cu tabela MASTER
      SELECT
      (
        CASE
          WHEN V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9)   THEN SEQ_INTRARI_CODINTR.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE &lt;&gt; 130  THEN SEQ_INTRARI_CODINTR.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE = 130   THEN SEQ_DVI_CODDVI.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN SEQ_IESIRI_CODIES.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (29, 30, 31, 33)     THEN SEQ_TREZOR1_CODTREZOR1.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (28)                 THEN SEQ_COMPENS_CODCOMPENS.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (35)                 THEN SEQ_NC1_CODNC1.NEXTVAL
        END
      ) INTO V_CODDOC FROM DUAL ;
    ELSE
      V_CODDOC := V_RECGENERAL.CODDOC;
    END IF;


    BEGIN
      SELECT TVAINCASARE, DATADOC INTO aTVAINCASARE, aDATATVA FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
      EXCEPTION WHEN OTHERS THEN aTVAINCASARE := NULL; aDATATVA := NULL;
    END;

-- testez daca SUNT PE UN AVANS PE CARE L-AM ASIGNAT UNUI CEC
-- DACA DA, PROPAG NOUL COD DE TREZOR1 PE TABELELE CARE TIN CECUL
   IF V_RECGENERAL.SEMNIFICATIE IN (310, 410) THEN

    BEGIN
      SELECT T1.CODTREZOR  INTO ACODTREZOR
      FROM
        TREZOR1 T1
      WHERE
        T1.CODTREZOR1 = V_RECGENERAL.CODDOC;
     EXCEPTION WHEN OTHERS THEN ACODTREZOR := 0;
    END;

     FOR V_REC_LINK_AVANS_CEC IN
    (SELECT OA.CODTREZOR1
     FROM
        TMP_OBLIGPIF O,
        TMP_OBLIGPIF_ASOCIAT OA
      WHERE
        O.CODGENERAL = V_RECGENERAL.CODGENERAL
        AND OA.CODOBLIGASOCIAT = O.CODOBLIGPIF
        AND OA.SEMNIFICATIE = - V_RECGENERAL.SEMNIFICATIE
     )
     LOOP

 --      UPDATE TMP_TREZOR1          SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
       FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1 WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1)
       LOOP
         UPDATE TMP_TREZOR1
         SET
           CODTREZOR  = aCODTREZOR,
           CODTREZOR1 = V_CODDOC
          WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1;

         UPDATE TREZOR
         SET
          TIPDOC = 31,
          CODBANCA = V_REC_TREZOR1.CODBANCA
         WHERE
         CODTREZOR = aCODTREZOR;
       END LOOP;
       UPDATE TMP_GENERAL_CECURI   SET CODDOC     = V_CODDOC WHERE CODDOC     =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
       UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
       V_RECGENERAL.TIPDOC := 31;
     END LOOP;
   END IF;

    IF V_RECGENERAL.CODGENERAL &lt; 0 THEN
      SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO V_CODGENERAL FROM DUAL;

      INSERT INTO GENERAL
      (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG, DATATVA) VALUES
      (V_CODGENERAL, V_RECGENERAL.TIPDOC, V_CODDOC, V_RECGENERAL.MONEDA, ROUND(V_RECGENERAL.CURS, 7),
      CASE
        WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA
        ELSE NULL
      END,
      V_RECGENERAL.SEMNIFICATIE, V_RECGENERAL.ICONTAVANS, V_RECGENERAL.PROCTVAAVANS, V_RECGENERAL.FARAREG,
      CASE
        WHEN aTVAINCASARE = 1 THEN aDATATVA
        ELSE NULL
      END);
    ELSE
      V_CODGENERAL := V_RECGENERAL.CODGENERAL;
      UPDATE GENERAL SET
        TIPDOC       = V_RECGENERAL.TIPDOC,
        CODDOC       = V_CODDOC,
        MONEDA       = V_RECGENERAL.MONEDA,
        CURS         = ROUND(V_RECGENERAL.CURS, 7),
        TVA          =  CASE
                          WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA
                          ELSE NULL
                        END,
        SEMNIFICATIE = V_RECGENERAL.SEMNIFICATIE,
        ICONTAVANS   = V_RECGENERAL.ICONTAVANS,
        PROCTVAAVANS = V_RECGENERAL.PROCTVAAVANS,
        FARAREG      = V_RECGENERAL.FARAREG,
        DATATVA      = CASE
                         WHEN aTVAINCASARE = 1 THEN aDATATVA
                         ELSE NULL
                       END
      WHERE
        CODGENERAL = V_CODGENERAL;
    END IF;

-- OBLIGPIF
    FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
      CODOBLIGFACTURA := NULL;
      IF V_RECOBLIG.MONEDA = 0 THEN aVALOARE := V_RECOBLIG.SUMALEI; ELSE aVALOARE := V_RECOBLIG.SUMAVALUTA;END IF;

      IF (V_RECOBLIG.SEMNIFICATIE = 1303)AND(NVL(V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt;&gt; 0) THEN
       -- LITIGII: PE V_RECOBLIG.CODOBLIGASOCIAT SI V_RECOBLIG.PROCENT TIN LEGATURA CU FACTURA IN LITIGIU
       --          IN TMP_OBLIGVAMA_INITIAL, TMP_GENERAL_LITIGII SI TMP_STINGERE_ASOCIAT TIN OBLIGATIA CARE STINGE FACTURA IN LITIGIU


        -- TRATEZ LEGATURA CU FACTURA
        IF NVL(V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt; 0 THEN
          SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO CODOBLIGFACTURA FROM DUAL;
          SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL   INTO CODGENERALFACTURA FROM DUAL;
          SELECT SEQ_IESIRI_CODIES.NEXTVAL        INTO CODFACTURA FROM DUAL;

          INSERT INTO IESIRI (CODIES, PREFIXDOC, TIPDOC, ANULAT, OPERAT, PARTENER, NRDOC, DATADOC, SUBUNITATEA, AN, LUNA, TVADOC, SERIADOC, MONEDA, CURS)
                             VALUES(CODFACTURA, &apos;F&apos;, 19, 0, 1, V_RECOBLIG.CODPART, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.SUBUNITATEA, ANI, LUNAI, V_RECOBLIG.TVA, V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);


          INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
                      VALUES (CODGENERALFACTURA, 19, CODFACTURA, V_RECOBLIG.MONEDA, ROUND(V_RECOBLIG.CURS,7), 200);


          INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
                      VALUES (CODOBLIGFACTURA, CODGENERALFACTURA, V_RECOBLIG.TERMEN, aVALOARE, 0, V_RECOBLIG.CODPART, 3, 200, V_RECOBLIG.CODCENTRU);



          UPDATE TMP_STINGERE_ASOCIAT
          SET
            CODSTINSPIF = CODOBLIGFACTURA
          WHERE
            CODSTINSPIF = V_RECOBLIG.CODOBLIGASOCIAT;
        ELSE
          CODOBLIGFACTURA   := V_RECOBLIG.CODOBLIGASOCIAT;
          CODGENERALFACTURA := V_RECOBLIG.PROCENT;
          BEGIN
            SELECT CODDOC INTO CODFACTURA FROM GENERAL WHERE CODGENERAL = CODGENERALFACTURA;
            EXCEPTION WHEN OTHERS THEN CODFACTURA := 0;
          END;

          UPDATE IESIRI
          SET
            PARTENER    = V_RECOBLIG.CODPART,
            NRDOC       = V_RECOBLIG.NRDOC,
            SERIADOC    = V_RECOBLIG.SERIADOC,
            DATADOC     = V_RECOBLIG.DATADOC,
            SUBUNITATEA = V_RECOBLIG.SUBUNITATEA,
            TVADOC      = V_RECOBLIG.TVA,
            MONEDA      = V_RECOBLIG.MONEDA,
            CURS        = V_RECOBLIG.CURSDOCSTINS
          WHERE
            CODIES = CODFACTURA;

          UPDATE GENERAL
          SET
            MONEDA = V_RECOBLIG.MONEDA,
            CURS   = ROUND(V_RECOBLIG.CURS, 7)
--          TVA    = V_RECOBLIG.TVA
          WHERE
            CODGENERAL = CODGENERALFACTURA;


           UPDATE OBLIGPIF
           SET
             TERMEN        = V_RECOBLIG.TERMEN,
             CODPART       = V_RECOBLIG.CODPART,
             CODCENTRU     = V_RECOBLIG.CODCENTRU,
             VALOARE       = aVALOARE
           WHERE
             CODOBLIGPIF = CODOBLIGFACTURA;
        END IF;

       -- TRATEZ LEGATURA CU COMPENSAREA CARE STINGE FACTURA
         FOR V_REC_STINGEREFACT IN
         (SELECT O.CODOBLIGPIF,
                 G.CODGENERAL,
                 S.CODSTINGERE
          FROM
            TMP_OBLIGVAMA_INITIAL O,
            TMP_GENERAL_LITIGII G,
            TMP_STINGERE_ASOCIAT S
          WHERE
           S.CODSTINSPIF = CODOBLIGFACTURA
           AND O.CODOBLIGPIF = S.CODSTINGATORPIF
           AND G.CODGENERAL  = O.CODGENERAL
          )
          LOOP
             IF V_REC_STINGEREFACT.CODOBLIGPIF &lt; 0 THEN
                SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO CODOBLIGCOMPENS FROM DUAL;
                SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO CODGENERALCOMPENS FROM DUAL;

                INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
                VALUES (CODGENERALCOMPENS, 28, V_CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS, 1350);

                IF V_RECOBLIG.MONEDA = 0 THEN aVALOARE := V_RECOBLIG.SUMALEI; ELSE aVALOARE := V_RECOBLIG.SUMAVALUTA;END IF;

                INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
                            VALUES (CODOBLIGCOMPENS, CODGENERALCOMPENS, aVALOARE, V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, 1350, V_RECOBLIG.CODCENTRU);


                INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
                VALUES (SEQ_STINGERE_CODSTINGERE.NEXTVAL, CODOBLIGFACTURA, CODOBLIGCOMPENS, aVALOARE);
             ELSE
                UPDATE GENERAL
                SET
                  MONEDA = V_RECOBLIG.MONEDA,
                  CURS   = ROUND(V_RECOBLIG.CURS, 7)
                WHERE
                  CODGENERAL = V_REC_STINGEREFACT.CODGENERAL;

                UPDATE OBLIGPIF
                SET
                  VALOARE = aVALOARE,
                  CODCENTRU     = V_RECOBLIG.CODCENTRU,
                  CODPART = V_RECOBLIG.CODPART
                WHERE
                  CODOBLIGPIF = V_REC_STINGEREFACT.CODOBLIGPIF;

                UPDATE STINGERE
                SET
                  VALOARE = aVALOARE
                WHERE
                  CODSTINGERE =  V_REC_STINGEREFACT.CODSTINGERE;
             END IF;
          END LOOP;

      END IF;

      IF V_RECOBLIG.CODOBLIGPIF &lt; 0 THEN
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO aCODOBLIGPIF FROM DUAL;
        UPDATE TMP_STINGERE SET CODSTINSPIF = aCODOBLIGPIF WHERE CODSTINSPIF =  V_RECOBLIG.CODOBLIGPIF;

        IF V_RECOBLIG.MONEDA = 0 THEN aVALOARE := V_RECOBLIG.SUMALEI; ELSE aVALOARE := V_RECOBLIG.SUMAVALUTA;END IF;

        INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, MAJORARI, ADAOSDOC, GRATIE, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODOBLIGASOCIAT, COEFPROVIZION, CODCENTRU)
        VALUES
        (aCODOBLIGPIF, V_CODGENERAL, V_RECOBLIG.TERMEN, V_RECOBLIG.MAJORARI, V_RECOBLIG.ADAOSDOC, V_RECOBLIG.GRATIE,
         (CASE
           WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI
           ELSE  V_RECOBLIG.SUMAVALUTA
          END ),

         (CASE
           WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI
           ELSE  V_RECOBLIG.SUMAVALUTA
          END ),
         aPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE,
         CODOBLIGFACTURA,
         CASE
          WHEN V_RECOBLIG.SEMNIFICATIE = 1303
          THEN
           (
             CASE
               WHEN V_RECOBLIG.SUMALEI = 0 THEN 0
               ELSE ROUND(V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI, 6)
             END
           )
          ELSE NULL
         END,
         V_RECOBLIG.CODCENTRU
        );

        INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
               VALUES
               (aCODOBLIGPIF,
               ANI,
               LUNAI,
               (CASE
                  WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI
                  ELSE  V_RECOBLIG.SUMAVALUTA
                END),
                CASE
                  WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_RECOBLIG.TVA, 0)
                  ELSE NULL
                END
               );
      ELSE
        UPDATE OBLIGPIF SET
          CODGENERAL   = V_CODGENERAL,
          TERMEN       = V_RECOBLIG.TERMEN,
          MAJORARI     = V_RECOBLIG.MAJORARI,
          ADAOSDOC     = V_RECOBLIG.ADAOSDOC,
          GRATIE       = V_RECOBLIG.GRATIE,
          CODCENTRU    = V_RECOBLIG.CODCENTRU,
          VALOARE      = (CASE
                            WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
                            ELSE NVL(V_RECOBLIG.SUMAVALUTA, 0)
                          END ),

          REST         = (CASE
                            WHEN (V_RECOBLIG.MONEDA = 0) AND( V_RECOBLIG.SUMALEI   &gt;= 0)  THEN V_RECOBLIG.SUMALEI    - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF), 0)
                            WHEN (V_RECOBLIG.MONEDA = 0) AND( V_RECOBLIG.SUMALEI   &lt; 0)  THEN V_RECOBLIG.SUMALEI    + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF), 0)
                            WHEN (V_RECOBLIG.MONEDA &lt;&gt; 0)AND( V_RECOBLIG.SUMAVALUTA &gt;= 0) THEN V_RECOBLIG.SUMAVALUTA - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF), 0)
                            WHEN (V_RECOBLIG.MONEDA &lt;&gt; 0)AND( V_RECOBLIG.SUMAVALUTA &lt; 0) THEN V_RECOBLIG.SUMAVALUTA + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF), 0)
                          END ),
          CODPART         = aPART,
          ICONT           = V_RECOBLIG.ICONT,
          CODOBLIGASOCIAT = CODOBLIGFACTURA,
          SEMNIFICATIE    = V_RECOBLIG.SEMNIFICATIE,
          COEFPROVIZION   = CASE
                              WHEN V_RECOBLIG.SEMNIFICATIE = 1303
                              THEN
                               (
                                 CASE
                                   WHEN  V_RECOBLIG.SUMALEI = 0 THEN 0
                                   ELSE ROUND(V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI, 7)
                                 END
                               )
                              ELSE NULL
                             END
        WHERE
          CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;
/*
        UPDATE OBLIGPIFLUNA
        SET
          REST         = (CASE
                            WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
                            ELSE NVL(V_RECOBLIG.SUMAVALUTA, 0)
                          END ),
          RESTTVA         = NVL(V_RECOBLIG.TVA, 0)
        WHERE
         CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNAI;
*/
        SELECT COUNT(*) INTO NR FROM OBLIGPIFLUNA WHERE CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNAI;

        IF NR = 0 THEN
          INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
                 VALUES
                 (V_RECOBLIG.CODOBLIGPIF,
                 ANI,
                 LUNAI,
                 (CASE
                    WHEN V_RECOBLIG.MONEDA = 0 THEN V_RECOBLIG.SUMALEI
                    ELSE  V_RECOBLIG.SUMAVALUTA
                  END),
                  CASE
                    WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_RECOBLIG.TVA, 0)
                    ELSE NULL
                  END
                 );

        ELSE
          UPDATE OBLIGPIFLUNA
          SET
            REST         = (CASE
                              WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
                              ELSE NVL(V_RECOBLIG.SUMAVALUTA, 0)
                            END ),
            RESTTVA         =  CASE
                                WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_RECOBLIG.TVA, 0)
                                ELSE NULL
                               END
            --NVL(V_RECOBLIG.TVA, 0)


          WHERE
           CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNAI;
        END IF;





      END IF;

      -- DOCUMENTE PARINTE
      NRDOC := 1;

      IF V_RECGENERAL.TIPDOC = 5 AND V_RECGENERAL.SEMNIFICATIE = 130 THEN
        SELECT COUNT(*) INTO NRDOC FROM DVI WHERE CODDVI = V_CODDOC;
        -- CAZUL CU NRDOC = 0 NU POATE APARE PENTRU CA PE INITIALIZARI NU POT ADAUGA OBLIGATII CU SEMNIFICATIE 130
        -- SINGURUL CAZ ESTE CAND ACESTE OBLIGATII PROVIN DIN RUPERE
        IF NRDOC &gt; 0 THEN
          UPDATE DVI SET
            NRDOC        = V_RECOBLIG.NRDOC,
            DATADOC      = V_RECOBLIG.DATADOC,
            OBS          = V_RECOBLIG.OBS,
            CODVAMA      = aPART
          WHERE
            CODDVI = V_CODDOC;
        END IF;
      END IF;


      IF
       (
        (V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9))
        OR
        (V_RECGENERAL.TIPDOC =5 AND V_RECGENERAL.SEMNIFICATIE &lt;&gt; 130)
       )
       THEN -- INTRARI
        SELECT COUNT(*) INTO NRDOC FROM INTRARI WHERE CODINTR = V_CODDOC;
        IF NRDOC = 0 THEN
          INSERT INTO INTRARI
          (CODINTR,
           TIPDOC,
           ANULAT,
           BLOCAT,
           OPERAT,
           PREFIXDOC,
           NRDOC,
           DATADOC,
           CODLOCATIE,
           OBS,
           PARTENER,
           AN,
           LUNA,
           INITIALIZARI,
           SUBUNITATEA,
           TVAINCASARE,
           TIPTVA,
           TIPTRANZACTIE,
           PRORATA,
           VALDOC,
           SERIADOC,
           MONEDA,
           CURS
           )
          VALUES
          (V_CODDOC,
           V_RECGENERAL.TIPDOC,
           0,
           0,
           1,
           PKG_GLOBALS.GETPREFIXDOC(V_RECGENERAL.TIPDOC),
           V_RECOBLIG.NRDOC,
           V_RECOBLIG.DATADOC,
           V_RECOBLIG.CODLOCATIE,
           V_RECOBLIG.OBS,
           aPART,
           ANI,
           LUNAI,
           1,
           V_RECOBLIG.SUBUNITATEA,
           aTVAINCASARE,
           V_RECOBLIG.TIPTVA,
           V_RECOBLIG.TIPTRANZACTIE,
           V_RECOBLIG.PRORATA,
            CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
            END,
            V_RECOBLIG.SERIADOC,
            V_RECOBLIG.MONEDA,
            V_RECOBLIG.CURSDOCSTINS
           );
        ELSE
          UPDATE INTRARI SET
            TIPDOC        = V_RECGENERAL.TIPDOC,
            NRDOC         = V_RECOBLIG.NRDOC,
            SERIADOC      = V_RECOBLIG.SERIADOC,
            DATADOC       = V_RECOBLIG.DATADOC,
            CODLOCATIE    = V_RECOBLIG.CODLOCATIE,
            OBS           = V_RECOBLIG.OBS,
            PARTENER      = aPART,
            SUBUNITATEA   = V_RECOBLIG.SUBUNITATEA,
            INITIALIZARI  = V_RECGENERAL.INITIALIZARI,
            TVAINCASARE   = aTVAINCASARE,
            TIPTVA        = V_RECOBLIG.TIPTVA,
            TIPTRANZACTIE = V_RECOBLIG.TIPTRANZACTIE,
            PRORATA       = V_RECOBLIG.PRORATA,
            VALDOC        =   CASE
                                WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
                                ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
                              END,
            MONEDA        = V_RECOBLIG.MONEDA,
            CURS          = V_RECOBLIG.CURSDOCSTINS
          WHERE
            CODINTR = V_CODDOC;
        END IF;
      ELSE
        IF V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN
          SELECT COUNT(*) INTO NRDOC FROM IESIRI WHERE CODIES = V_CODDOC;
          IF NRDOC = 0 THEN
            INSERT INTO IESIRI(CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, AGENT, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA, TVADOC, TVAINCASARE, DATATVA, VALDOC, SERIADOC, MONEDA, CURS)
            VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
            --&apos;F&apos;,
            PKG_GLOBALS.GETPREFIXDOC(V_RECGENERAL.TIPDOC),
            V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.AGENT, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI, 1, V_RECOBLIG.SUBUNITATEA, V_RECOBLIG.TVA, aTVAINCASARE, aDATATVA,
            CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
            END,
            V_RECOBLIG.SERIADOC,
            V_RECOBLIG.MONEDA,
            V_RECOBLIG.CURS
           );
          ELSE
            UPDATE IESIRI SET
              TIPDOC       = V_RECGENERAL.TIPDOC,
              NRDOC        = V_RECOBLIG.NRDOC,
              SERIADOC     = V_RECOBLIG.SERIADOC,
              DATADOC      = V_RECOBLIG.DATADOC,
              AGENT        = V_RECOBLIG.AGENT,
              CODLOCATIE   = V_RECOBLIG.CODLOCATIE,
              OBS          = V_RECOBLIG.OBS,
              SUBUNITATEA  = V_RECOBLIG.SUBUNITATEA,
              PARTENER     = aPART,
              INITIALIZARI = V_RECGENERAL.INITIALIZARI,
              TVADOC       = V_RECOBLIG.TVA,
              TVAINCASARE  = aTVAINCASARE,
              DATATVA      = aDATATVA,
              VALDOC       =   CASE
                                  WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
                                  ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
                               END,
              MONEDA        = V_RECOBLIG.MONEDA,
              CURS          = V_RECOBLIG.CURSDOCSTINS
            WHERE
              CODIES = V_CODDOC;
           END IF;
        ELSE
          IF V_RECGENERAL.TIPDOC IN (29, 30, 31, 33) THEN
            SELECT COUNT(*) INTO NRDOC FROM TREZOR1 WHERE CODTREZOR1 = V_CODDOC;
            IF NRDOC = 0 THEN
              SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL INTO aCODTREZOR FROM DUAL;
              INSERT INTO TREZOR(CODTREZOR, TIPDOC, SUBUNITATEA, AN, LUNA, OPERAT) VALUES (aCODTREZOR, V_RECGENERAL.TIPDOC, V_RECGENERAL.SUBUNITATEA, ANI, LUNAI, 1);
              INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, NRDOC, DATADOC, CODLOCATIE, CODPART, AN, LUNA, INITIALIZARI, AGENT, SERIEDOC, OBS)
              VALUES (V_CODDOC, aCODTREZOR, 1, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.CODLOCATIE, aPART, ANI, LUNAI, 1, V_RECOBLIG.AGENT, V_RECOBLIG.SERIADOC, V_RECOBLIG.OBS);
              UPDATE TMP_TREZOR1 SET CODTREZOR = aCODTREZOR WHERE CODTREZOR1 = V_CODDOC;-- sincronizez cu CEC-uri
            ELSE
              UPDATE TREZOR1 SET
                NRDOC        = V_RECOBLIG.NRDOC,
                SERIEDOC     = V_RECOBLIG.SERIADOC,
                DATADOC      = V_RECOBLIG.DATADOC,
                CODLOCATIE   = V_RECOBLIG.CODLOCATIE,
                CODPART      = aPART,
                AGENT        = V_RECOBLIG.AGENT,
                INITIALIZARI = V_RECGENERAL.INITIALIZARI,
                OBS          = V_RECOBLIG.OBS
              WHERE
                CODTREZOR1 = V_CODDOC;

              UPDATE TREZOR SET SUBUNITATEA = V_RECOBLIG.SUBUNITATEA WHERE CODTREZOR = (SELECT CODTREZOR FROM TREZOR1 WHERE CODTREZOR1 = V_CODDOC);
             END IF;

          ELSE
            IF V_RECGENERAL.TIPDOC IN (28) THEN
              SELECT COUNT(*) INTO NRDOC FROM COMPENS WHERE CODCOMPENS = V_CODDOC;
              IF NRDOC = 0 THEN
                INSERT INTO COMPENS(CODCOMPENS, DATADOC, NRDOC, AN, LUNA, PARTD, PARTC, SUBUNITATEA, CODTIPPARTINCERT, TIPCOMPENS)
                VALUES (V_CODDOC, V_RECOBLIG.DATADOC, 0, ANI, LUNAI,  V_RECOBLIG.CODPART,  V_RECOBLIG.CODPART, V_RECOBLIG.SUBUNITATEA,
                         V_RECOBLIG.CODTIPPARTINCERT,
                           CASE
                              WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
                              WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
                              ELSE 0
                            END
                         );
              ELSE
                UPDATE COMPENS
                SET
                  PARTD            = V_RECOBLIG.CODPART,
                  PARTC            = V_RECOBLIG.CODPART,
                  CODTIPPARTINCERT = V_RECOBLIG.CODTIPPARTINCERT,
                  SUBUNITATEA      = V_RECOBLIG.SUBUNITATEA,
                  TIPCOMPENS       = CASE
                                        WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
                                        WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
                                        ELSE 0
                                      END

                WHERE
                 CODCOMPENS = V_CODDOC;
              END IF;
              ELSE
              IF V_RECGENERAL.TIPDOC = 35 THEN
                UPDATE NC
                SET
                  SUBUNITATEA = V_RECOBLIG.SUBUNITATEA
                WHERE
                  CODNC = (SELECT CODNC FROM NC1 WHERE CODNC1 = V_CODDOC);
              END IF;

            END IF;
          END IF;
        END IF;
      END IF;

      FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)  LOOP
          IF NVL(V_RECINTRARI1.CodIntr1, 0) &gt; 0 THEN
            UPDATE INTRARI1 SET
               IndexLocal       = V_RECINTRARI1.IndexLocal,
               TipLinie         = V_RECINTRARI1.TipLinie,
               UmSec            = V_RECINTRARI1.UmSec,
               An               = V_RECINTRARI1.An,
               Luna             = V_RECINTRARI1.Luna,
               ContServ         = V_RECINTRARI1.ContServ,
               CONTDISCOUNT     = V_RECINTRARI1.CONTDISCOUNT,
               GestAct          = V_RECINTRARI1.GestAct,
               CodObiect        = V_RECINTRARI1.CodObiect,
               PretOrig         = V_RECINTRARI1.PretOrig,
               PU               = V_RECINTRARI1.PU   / NVL(V_RECINTRARI1.Paritate, 1),
               Cant             = V_RECINTRARI1.Cant * NVL(V_RECINTRARI1.Paritate, 1),
               TVA              = V_RECINTRARI1.TVA,
               AdDim            = V_RECINTRARI1.AdDim,
               MIFIX            = V_RECINTRARI1.MIFIX,
               CODOBIECTORIG    = V_RECINTRARI1.CODOBIECTORIG,
               PARITATEORIG     = V_RECINTRARI1.PARITATEORIG,
               COEFDISCMAJ      = V_RECINTRARI1.COEFDISCMAJ,
               CUSTODIE         = V_RECINTRARI1.CUSTODIE,
               OBS              = V_RECINTRARI1.OBS,
               CODOBLIGSTORNO   = V_RECINTRARI1.CODOBLIGSTORNO,
               CURSFACTURAAVANS = V_RECINTRARI1.CURSFACTURAAVANS,

    -- SUNT PE AVIZ - RECALCULEZ RESTUL
               RestFact   =
               CASE
                 WHEN V_RECINTRARI1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)
                 THEN V_RECINTRARI1.Cant * V_RECINTRARI1.Paritate -
                   (SELECT NVL(SUM(IL.CANT), 0)
                    FROM
                      INTRLINK IL
                      LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = IL.CODINTR1
                      LEFT OUTER JOIN INTRARI   I ON I.CODINTR   = I1.CODINTR
                    WHERE
                    IL.CODLINIEAVIZ = V_RECINTRARI1.CodINTR1 AND I.TIPDOC = 9 AND I.OPERAT = 1 AND I.ANULAT = 0
                   )
                 +
                 (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                  FROM
                    INTRARI1 AE1,
                    INTRARI  AE
                  WHERE
                    AE1.CODINTR1STORNO = V_RECINTRARI1.CODINTR1 AND AE.CODINTR = AE1.CODINTR
                   AND AE.TIPDOC = 2 AND AE.OPERAT = 1 AND AE.ANULAT = 0
                 )
                 ELSE 0
               END,
               NrCertif             = V_RECINTRARI1.NrCertif,
               TG                   = V_RECINTRARI1.TG,
               PUMaximal            = V_RECINTRARI1.PUMaximal,
               PURidicata           = V_RECINTRARI1.PURidicata,
               ProcAdaos            = V_RECINTRARI1.ProcAdaos,
               FURNAVIZSUBUNIT      = V_RECINTRARI1.FURNAVIZSUBUNIT,
               DATAACHIZAVIZSUBUNIT = V_RECINTRARI1.DATAACHIZAVIZSUBUNIT
            WHERE
               CodIntr1   = V_RECINTRARI1.CodIntr1;
         ELSE
           SELECT seq_INTRARI1_CodIntr1.Nextval INTO V_COD from Dual;
           INSERT INTO INTRARI1
           ( CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA, AdDim, MIFIX,  CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact,NrCertif,TG,PUMaximal,PURidicata, ProcAdaos,
           FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS)
           VALUES
           (V_COD,  V_CODDOC, V_RECINTRARI1.IndexLocal ,  V_RECINTRARI1.CUSTODIE,   V_RECINTRARI1.TipLinie,  V_RECINTRARI1.Umsec,  V_RECINTRARI1.An,  V_RECINTRARI1.Luna,  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT,
             V_RECINTRARI1.GestAct,  V_RECINTRARI1.CodObiect,  V_RECINTRARI1.PretOrig,  V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
             V_RECINTRARI1.Cant *  NVL(V_RECINTRARI1.Paritate, 1),  V_RECINTRARI1.TVA, V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX,  V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG, V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS,
             (CASE
                WHEN V_RECINTRARI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_RECINTRARI1.VALOARE -- valoare discount memorez pe RESTFACT
                ELSE V_RECINTRARI1.Cant *  V_RECINTRARI1.Paritate
              END),
             V_RECINTRARI1.NrCertif,  V_RECINTRARI1.TG,  V_RECINTRARI1.PUMaximal,  V_RECINTRARI1.PURidicata, V_RECINTRARI1.ProcAdaos, V_RECINTRARI1.FURNAVIZSUBUNIT, V_RECINTRARI1.DATAACHIZAVIZSUBUNIT, V_RECINTRARI1.CODOBLIGSTORNO, V_RECINTRARI1.CURSFACTURAAVANS);
          END IF;
      END LOOP; -- INTRARI1



  -- INTRARI1 TVA_INCASARE
      FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)  LOOP
          IF NVL(V_RECINTRARI1.CodIntr1, 0) &gt; 0 THEN
            UPDATE INTRARI1 SET
               IndexLocal       = V_RECINTRARI1.IndexLocal,
               TipLinie         = V_RECINTRARI1.TipLinie,
               UmSec            = V_RECINTRARI1.UmSec,
               An               = V_RECINTRARI1.An,
               Luna             = V_RECINTRARI1.Luna,
               ContServ         = V_RECINTRARI1.ContServ,
               CONTDISCOUNT     = V_RECINTRARI1.CONTDISCOUNT,
               GestAct          = V_RECINTRARI1.GestAct,
               CodObiect        = V_RECINTRARI1.CodObiect,
               PretOrig         = V_RECINTRARI1.PretOrig,
               PU               = V_RECINTRARI1.PU   / NVL(V_RECINTRARI1.Paritate, 1),
               Cant             = V_RECINTRARI1.Cant * NVL(V_RECINTRARI1.Paritate, 1),
               TVA              = V_RECINTRARI1.TVA,
               AdDim            = V_RECINTRARI1.AdDim,
               MIFIX            = V_RECINTRARI1.MIFIX,
               CODOBIECTORIG    = V_RECINTRARI1.CODOBIECTORIG,
               PARITATEORIG     = V_RECINTRARI1.PARITATEORIG,
               COEFDISCMAJ      = V_RECINTRARI1.COEFDISCMAJ,
               OBS              = V_RECINTRARI1.OBS,
               TVANEDED         = V_RECINTRARI1.TVANEDED
            WHERE
               CodIntr1   = V_RECINTRARI1.CodIntr1;
         ELSE
           SELECT seq_INTRARI1_CodIntr1.Nextval INTO V_COD from Dual;
           INSERT INTO INTRARI1
           (
             CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, TVANEDED
           )
           VALUES
           ( V_COD, V_CODDOC, V_RECINTRARI1.IndexLocal ,  V_RECINTRARI1.CUSTODIE,   V_RECINTRARI1.TipLinie,  V_RECINTRARI1.Umsec,  V_RECINTRARI1.An,  V_RECINTRARI1.Luna,  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT,
             V_RECINTRARI1.GestAct,  V_RECINTRARI1.CodObiect,  V_RECINTRARI1.PretOrig,  V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
             V_RECINTRARI1.Cant *  NVL(V_RECINTRARI1.Paritate, 1),  V_RECINTRARI1.TVA, V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG, V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS, V_RECINTRARI1.TVANEDED
           );
          END IF;
      END LOOP; -- INTRARI1_TVAINCAS

      IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9) THEN
        UPDATE INTRARI
        SET
          TVADOC = (SELECT SUM(TVA) FROM INTRARI1 WHERE CODINTR = V_CODDOC)
        WHERE
          CODINTR = V_CODDOC;
      END IF;




      FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)  LOOP

          IF NVL(V_RECIESIRI1.CODIES1, 0) &gt; 0  THEN
            UPDATE IESIRI1 SET
             INDEXLOCAL       = V_RECIESIRI1.INDEXLOCAL,
             TIPLINIE         = V_RECIESIRI1.TIPLINIE,
             UMSEC            = V_RECIESIRI1.UMSEC,
             CONTSERV         = V_RECIESIRI1.CONTSERV,
             CONTDISCOUNT     = V_RECIESIRI1.CONTDISCOUNT,
             CODCRITERIU      = V_RECIESIRI1.CODCRITERIU,
             MIFIX            = V_RECIESIRI1.MIFIX,
             GESTACT          = V_RECIESIRI1.GESTACT,
             CODOBIECT        = V_RECIESIRI1.CODOBIECT,
             PRETORIG         = V_RECIESIRI1.PU   / NVL(V_RECIESIRI1.PARITATE, 1),
             PU               = V_RECIESIRI1.PU   / NVL(V_RECIESIRI1.PARITATE, 1),
             CANT             = V_RECIESIRI1.CANT * NVL(V_RECIESIRI1.PARITATE, 1),
             TVA              = V_RECIESIRI1.TVA,
             CONT             = V_RECIESIRI1.CONT,
             PROCDISC         = V_RECIESIRI1.PROCDISC,
             CODOBLIGSTORNO   = V_RECIESIRI1.CODOBLIGSTORNO,
             CURSFACTURAAVANS = V_RECIESIRI1.CURSFACTURAAVANS,
             COEFDISCMAJ      = V_RECIESIRI1.COEFDISCMAJ,
             OBS              = V_RECIESIRI1.OBS,
             CODOBIECTORIG    = V_RECIESIRI1.CODOBIECTORIG,
             PARITATEORIG     = V_RECIESIRI1.PARITATEORIG,
             ADDIM            = V_RECIESIRI1.ADDIM,

    -- SUNT PE AVIZ - RECALCULEZ RESTUL
             RESTFACT     =
             CASE
               WHEN V_RECIESIRI1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)
               THEN V_RECIESIRI1.CANT * V_RECIESIRI1.PARITATE -
                 (SELECT NVL(SUM(IL.CANT), 0)
                  FROM
                    IESLINK IL
                    LEFT OUTER JOIN IESIRI1 I1 ON I1.CODIES1 = IL.CODIES1
                    LEFT OUTER JOIN IESIRI   I ON I.CODIES   = I1.CODIES
                  WHERE
                    IL.CODLINIEAVIZ = V_RECIESIRI1.CODIES1 AND I.TIPDOC = 26 AND I.OPERAT = 1 AND I.ANULAT = 0
                 )
                 +
                 (SELECT NVL(SUM(AE1.CANT), 0) -- STINGERI PRIN STORNARI AVIZE
                  FROM
                    IESIRI1 AE1,
                    IESIRI  AE
                  WHERE
                    AE1.CODIES1STORNO = V_RECIESIRI1.CODIES1 AND AE.CODIES = AE1.CODIES
                   AND AE.TIPDOC = 20 AND AE.OPERAT = 1 AND AE.ANULAT = 0
                 )
               WHEN V_RECIESIRI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_RECIESIRI1.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT LA LINIILE DE DISCOUNT
               ELSE 0
             END,
             PUMAXIMAL = V_RECIESIRI1.PUMAXIMAL,
             GARANTIE  = V_RECIESIRI1.GARANTIE
            WHERE
            CODIES1 = V_RECIESIRI1.CODIES1;
         ELSE
           SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO V_COD FROM DUAL;

           INSERT INTO IESIRI1
            (
             CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC,
             CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG, PU,
             CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL,
             TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG
            )
           VALUES
           ( V_COD,   V_CODDOC, V_RECIESIRI1.INDEXLOCAL , V_RECIESIRI1.TIPLINIE,  V_RECIESIRI1.UMSEC,
             V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT,  V_RECIESIRI1.CODOBIECT,
             V_RECIESIRI1.PU /  NVL(V_RECIESIRI1.PARITATE,1),
             V_RECIESIRI1.PU /  NVL(V_RECIESIRI1.PARITATE,1),  V_RECIESIRI1.CANT *  NVL(V_RECIESIRI1.PARITATE, 1),
             V_RECIESIRI1.TVA, V_RECIESIRI1.CONT, V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,
             (
              CASE
                WHEN V_RECIESIRI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_RECIESIRI1.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
                ELSE V_RECIESIRI1.CANT *  NVL(V_RECIESIRI1.PARITATE, 1)
              END
              ),
              V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
          END IF;
      END LOOP; -- IESIRI1



      FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)  LOOP

          IF NVL(V_RECIESIRI1.CODIES1, 0) &gt; 0  THEN
            UPDATE IESIRI1 SET
             INDEXLOCAL       = V_RECIESIRI1.INDEXLOCAL,
             TIPLINIE         = V_RECIESIRI1.TIPLINIE,
             UMSEC            = V_RECIESIRI1.UMSEC,
             CONTSERV         = V_RECIESIRI1.CONTSERV,
             CONTDISCOUNT     = V_RECIESIRI1.CONTDISCOUNT,
             CODCRITERIU      = V_RECIESIRI1.CODCRITERIU,
             MIFIX            = V_RECIESIRI1.MIFIX,
             GESTACT          = V_RECIESIRI1.GESTACT,
             CODOBIECT        = V_RECIESIRI1.CODOBIECT,
             PRETORIG         = V_RECIESIRI1.PU   / NVL(V_RECIESIRI1.PARITATE, 1),
             PU               = V_RECIESIRI1.PU   / NVL(V_RECIESIRI1.PARITATE, 1),
             CANT             = V_RECIESIRI1.CANT * NVL(V_RECIESIRI1.PARITATE, 1),
             TVA              = V_RECIESIRI1.TVA,
             CONT             = V_RECIESIRI1.CONT,
             PROCDISC         = V_RECIESIRI1.PROCDISC,
             CODOBLIGSTORNO   = V_RECIESIRI1.CODOBLIGSTORNO,
             CURSFACTURAAVANS = V_RECIESIRI1.CURSFACTURAAVANS,
             COEFDISCMAJ      = V_RECIESIRI1.COEFDISCMAJ,
             OBS              = V_RECIESIRI1.OBS,
             CODOBIECTORIG    = V_RECIESIRI1.CODOBIECTORIG,
             PARITATEORIG     = V_RECIESIRI1.PARITATEORIG,
             ADDIM            = V_RECIESIRI1.ADDIM,
             PUMAXIMAL = V_RECIESIRI1.PUMAXIMAL,
             GARANTIE  = V_RECIESIRI1.GARANTIE
            WHERE
            CODIES1 = V_RECIESIRI1.CODIES1;
         ELSE
           SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO V_COD FROM DUAL;

           INSERT INTO IESIRI1
            (
             CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC,
             CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG, PU,
             CANT, TVA, CONT, PROCDISC, ADDIM, PUMAXIMAL,
             TIPLIVRARE, GARANTIE, CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG
            )
           VALUES
           ( V_COD,   V_CODDOC, V_RECIESIRI1.INDEXLOCAL , V_RECIESIRI1.TIPLINIE,  V_RECIESIRI1.UMSEC,
             V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT,  V_RECIESIRI1.CODOBIECT,
             V_RECIESIRI1.PU /  NVL(V_RECIESIRI1.PARITATE,1),
             V_RECIESIRI1.PU /  NVL(V_RECIESIRI1.PARITATE,1),  V_RECIESIRI1.CANT *  NVL(V_RECIESIRI1.PARITATE, 1),
             V_RECIESIRI1.TVA, V_RECIESIRI1.CONT, V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,
             V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG);
          END IF;
      END LOOP; -- IESIRI1_TVAINCAS

    END LOOP; -- OBLIGPIF
  END LOOP; -- GENERAL


-- START CECURI
 -- TREZOR1
   FOR V_REC_TREZ_D IN (
     SELECT
       TI.CODTREZOR1 CODI,
       NVL(T1.CODTREZOR1, 0) AS CODF
     FROM
       TMP_TREZOR1_INITIAL TI
       LEFT JOIN TMP_TREZOR1 T1 ON T1.CODTREZOR1 = TI.CODTREZOR1
     )
    LOOP
       IF V_REC_TREZ_D.CODF = 0 THEN
         FOR V_REC_GEN_D IN (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = 31 AND CODDOC =  V_REC_TREZ_D.CODI)
         LOOP
           DELETE FROM OBLIGPIF WHERE CODGENERAL =  V_REC_GEN_D .CODGENERAL;
           DELETE FROM GENERAL WHERE CODGENERAL =  V_REC_GEN_D .CODGENERAL;
         END LOOP;
         DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC_TREZ_D.CODI;
       END IF;
    END LOOP;


   FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1) LOOP
     IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
       SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL INTO aCODTREZOR FROM DUAL;
       SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL INTO aCODTREZOR1 FROM DUAL;
       INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA)
          VALUES (aCODTREZOR, 31,  V_REC_TREZOR1.CODBANCA, ANI, LUNAI, 1, 0, V_REC_TREZOR1.SUBUNITATEA);
       INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, DOC, NRDOC, DATADOC, CODPART, TIPTRANZ, VALDOC, CURS, TIPDECONT, OBS, DATADECONT,  AN, LUNA, INITIALIZARI, ANULAT, AGENT)
       VALUES (aCODTREZOR1, aCODTREZOR, 1, V_REC_TREZOR1.DOC, V_REC_TREZOR1.NRDOC, V_REC_TREZOR1.DATADOC, aPART,
               V_REC_TREZOR1.TIPTRANZ,
               V_REC_TREZOR1.VALDOC,
               V_REC_TREZOR1.CURS,
               V_REC_TREZOR1.TIPDECONT,
               V_REC_TREZOR1.OBS,
               V_REC_TREZOR1.DATADECONT,
               ANI,
               LUNAI,
               1,
               0,
               V_REC_TREZOR1.AGENT);
        UPDATE TMP_GENERAL_CECURI   SET CODDOC     = aCODTREZOR1 WHERE CODDOC     =  V_REC_TREZOR1.CODTREZOR1;
        UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = aCODTREZOR1 WHERE CODTREZOR1 =  V_REC_TREZOR1.CODTREZOR1;

        FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE CODDOC =  aCODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO V_CODGENERAL FROM DUAL;
          UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL =  V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;
          INSERT INTO GENERAL  (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
          VALUES   (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA, ROUND(V_REC_GENERAL.CURS, 7),
          V_REC_GENERAL.TVA,
          V_REC_GENERAL.SEMNIFICATIE);
        END LOOP;

        FOR V_REC_OBLIG IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE CODTREZOR1 = aCODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO ACODOBLIGPIF FROM DUAL;
          UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_REC_OBLIG.CODOBLIGPIF;

          INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
           VALUES( aCODOBLIGPIF, V_REC_OBLIG.CODGENERAL,
            V_REC_OBLIG.VALOARE,
            V_REC_OBLIG.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_REC_OBLIG.CODOBLIGPIF),0),
            V_REC_OBLIG.CODPART, V_REC_OBLIG.ICONT, V_REC_OBLIG.SEMNIFICATIE, V_REC_OBLIG.CONTBANKTRANZACTIE);


          INSERT INTO OBLIGPIFLUNA(CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
          VALUES (
          aCODOBLIGPIF,
          ANI,
          LUNAI,
          V_REC_OBLIG.VALOARE /* - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_REC_OBLIG.CODOBLIGPIF),0)*/,
--          NVL(V_REC_OBLIG.TVA, 0)
                CASE
                  WHEN V_REC_OBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_REC_OBLIG.TVA, 0)
                  ELSE NULL
                END
          )
          ;

        END LOOP;
     ELSE -- CODTREZOR1 &gt; 0
       UPDATE TREZOR SET
         CODBANCA    = V_REC_TREZOR1.CODBANCA,
         SUBUNITATEA = V_REC_TREZOR1.SUBUNITATEA
       WHERE
       CODTREZOR = V_REC_TREZOR1.CODTREZOR;

       UPDATE TREZOR1 SET
        CODTREZOR          = V_REC_TREZOR1.CODTREZOR,
        DOC                = V_REC_TREZOR1.DOC,
        NRDOC              = V_REC_TREZOR1.NRDOC,
        DATADOC            = V_REC_TREZOR1.DATADOC,
        CODPART            = V_REC_TREZOR1.CODPART,
        TIPTRANZ           = V_REC_TREZOR1.TIPTRANZ,
        VALDOC             = V_REC_TREZOR1.VALDOC,
        CURS               = V_REC_TREZOR1.CURS,
        TIPDECONT          = V_REC_TREZOR1.TIPDECONT,
        OBS                = V_REC_TREZOR1.OBS,
        DATADECONT         = V_REC_TREZOR1.DATADECONT,
        AN                 = ANI,
        LUNA               = LUNAI,
        AGENT              = V_REC_TREZOR1.AGENT
       WHERE
         CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;


       FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE CODDOC = V_REC_TREZOR1.CODTREZOR1 AND SEMNIFICATIE &gt; 0) LOOP
          IF V_REC_GENERAL.CODGENERAL &lt; 0 THEN
              SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO V_CODGENERAL FROM DUAL;
              UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL =  V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;
              INSERT INTO GENERAL  (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
              VALUES   (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA, ROUND(V_REC_GENERAL.CURS, 7), V_REC_GENERAL.TVA, V_REC_GENERAL.SEMNIFICATIE);
          ELSE
            UPDATE GENERAL SET
              TIPDOC       = V_REC_GENERAL.TIPDOC,
              CODDOC       = V_REC_GENERAL.CODDOC,
              MONEDA       = V_REC_GENERAL.MONEDA,
              CURS         = ROUND(V_REC_GENERAL.CURS, 7),
              TVA          = V_REC_GENERAL.TVA,
              SEMNIFICATIE = V_REC_GENERAL.SEMNIFICATIE
            WHERE
              CODGENERAL = V_REC_GENERAL.CODGENERAL;
          END IF;
       END LOOP; -- GENERAL

       FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1 AND SEMNIFICATIE &gt; 0)
       LOOP
          IF V_RECOBLIG.CODOBLIGPIF &lt; 0 THEN
            SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO ACODOBLIGPIF FROM DUAL;
            UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_RECOBLIG.CODOBLIGPIF;
            INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
            VALUES
            (aCODOBLIGPIF, V_RECOBLIG.CODGENERAL,
              V_RECOBLIG.VALOARE,
              CASE
               WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE
               ELSE 0
              END,
              V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE, V_RECOBLIG.CONTBANKTRANZACTIE);

             INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
             VALUES (aCODOBLIGPIF, ANI, LUNAI,
             CASE
               WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE
               ELSE 0
              END,
--              NVL(V_RECOBLIG.TVA, 0)
                CASE
                  WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_RECOBLIG.TVA, 0)
                  ELSE NULL
                END
              );


          ELSE
            UPDATE OBLIGPIF SET
              CODGENERAL         = V_RECOBLIG.CODGENERAL,
              VALOARE            = V_RECOBLIG.VALOARE,
              REST               = CASE
                                     WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF),0)
                                     ELSE 0
                                  END,
              CODPART            = V_RECOBLIG.CODPART,
              ICONT              = V_RECOBLIG.ICONT,
              SEMNIFICATIE       = V_RECOBLIG.SEMNIFICATIE,
              CODCENTRU          = V_RECOBLIG.CODCENTRU,
              CONTBANKTRANZACTIE = V_RECOBLIG.CONTBANKTRANZACTIE
            WHERE
              CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;

            UPDATE OBLIGPIFLUNA
            SET
              REST  = CASE
                        WHEN V_RECOBLIG.SEMNIFICATIE IN (500, 600) THEN V_RECOBLIG.VALOARE /*- NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF),0)*/
                        ELSE 0
                      END
            WHERE
              CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF AND AN = ANI AND LUNA = LUNA;
          END IF;
       END LOOP; -- OBLIGIF
     END IF;
   END LOOP; -- TREZOR1

  FOR V_REC IN (SELECT * FROM TMP_STINGERE) LOOP
    IF V_REC.CODSTINGERE &lt; 0 THEN
      INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (SEQ_STINGERE_CODSTINGERE.NEXTVAL, V_REC.CODSTINSPIF, V_REC.CODSTINGATORPIF, V_REC.VALOARE);
    ELSE
     UPDATE STINGERE SET
      VALOARE = V_REC.VALOARE
     WHERE
       CODSTINGERE = V_REC.CODSTINGERE;
    END IF;
  END LOOP;

  -- END CECURI


  -- daca s-au modificat cursuri pe GENERAL apar implicatii in TREZOR1 si COMPENS
  -- le propag;
  FOR V_REC IN
  (
     SELECT
       G.MONEDA,
       OSTINS.DATADOC,
       G.CURS AS OLDCURSREG,
       GSTINGATOR.CODGENERAL,
       GSTINGATOR.CURS AS CURSSTINGATOR,
       T1.CODTREZOR,
       T1.DATADOC AS DATASTINGERE,
       G.CODGENERAL AS CODGENERALSTINS
     FROM
       TMP_GENERAL G,
       TMP_OBLIGPIF OSTINS,
       STINGERE S,
       OBLIGPIF OSTINGATOR,
       GENERAL GSTINGATOR,
       TREZOR1 T1
     WHERE
       NVL(G.MONEDA, 0) &lt;&gt; 0
       AND G.CODGENERAL = OSTINS.CODGENERAL
       AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
       AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
       AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
       AND GSTINGATOR.TIPDOC IN (29, 30, 31, 33)
       AND T1.CODTREZOR1 = GSTINGATOR.CODDOC
       AND G.CURS &lt;&gt; GSTINGATOR.CURS
   )
   LOOP
      SELECT MIN(DATADOC) INTO DATANEXTREG
      FROM
       REG R,
       REG1 R1
      WHERE
        TIPREG = 46
        AND R.DATADOC   &gt; V_REC.DATADOC
        AND R.CODMONEDA = V_REC.MONEDA
        AND R1.CODREG = R.CODREG
        AND R1.CODGENERAL = V_REC.CODGENERALSTINS;


      IF PKG_REGPART.DATA_DOC_CORECTA(V_REC.DATASTINGERE,  V_REC.DATADOC, DATANEXTREG) = 1 THEN
        UPDATE GENERAL
        SET
          CURS = V_REC.OLDCURSREG
        WHERE
          CODGENERAL = V_REC.CODGENERAL;

        UPDATE JURNAL1
        SET
          DIRTY = 1
        WHERE
          TIPDOC IN (29, 30, 31, 33) AND CODDOC = v_rec.codtrezor;
      END IF;
   END LOOP;



  FOR V_REC IN
  (
     SELECT
       G.MONEDA,
       OSTINS.DATADOC,
       G.CURS AS OLDCURSREG,
       GSTINGATOR.CODGENERAL,
       GSTINGATOR.CURS AS CURSSTINGATOR,
       C.CODCOMPENS,
       C.DATADOC AS  DATASTINGERE,
       G.CODGENERAL AS CODGENERALSTINS
     FROM
       TMP_GENERAL G,
       TMP_OBLIGPIF OSTINS,
       STINGERE S,
       OBLIGPIF OSTINGATOR,
       GENERAL GSTINGATOR,
       COMPENS C
     WHERE
       NVL(G.MONEDA, 0) &lt;&gt; 0
       AND G.CODGENERAL = OSTINS.CODGENERAL
       AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
       AND OSTINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
       AND GSTINGATOR.CODGENERAL = OSTINGATOR.CODGENERAL
       AND GSTINGATOR.TIPDOC IN (28)
       AND C.CODCOMPENS = GSTINGATOR.CODDOC
  )
  LOOP
      SELECT MIN(DATADOC) INTO DATANEXTREG
      FROM
        REG R,
        REG1 R1
      WHERE
        TIPREG = 46
        AND R.DATADOC   &gt; V_REC.DATADOC
        AND R.CODMONEDA = V_REC.MONEDA
        AND R1.CODREG = R.CODREG
        AND R1.CODGENERAL = V_REC.CODGENERALSTINS;

      IF PKG_REGPART.DATA_DOC_CORECTA(V_REC.DATASTINGERE,  V_REC.DATADOC, DATANEXTREG) = 1 THEN
        UPDATE JURNAL1
        SET
          DIRTY = 1
        WHERE
          TIPDOC = 28 AND CODDOC = V_REC.CODCOMPENS;
      END IF;


  END LOOP;

 ELSE  -- INSERT

   SELECT SEQ_SOLDINI_CODSOLDINI.NEXTVAL INTO RECID FROM DUAL;

   INSERT INTO SOLDINI
   SELECT RECID, aPART FROM DUAL;

 -- GENERAL
    FOR V_RECGENERAL IN (SELECT * FROM TMP_GENERAL) LOOP
      SELECT
      (
        CASE
          WHEN V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 5, 9)   THEN SEQ_INTRARI_CODINTR.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN SEQ_IESIRI_CODIES.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (29, 30, 31, 33)         THEN SEQ_TREZOR1_CODTREZOR1.NEXTVAL
          WHEN V_RECGENERAL.TIPDOC IN (28)                 THEN SEQ_COMPENS_CODCOMPENS.NEXTVAL
        END
      ) INTO V_CODDOC FROM DUAL ;



       BEGIN
         SELECT TVAINCASARE, DATADOC INTO aTVAINCASARE, aDATATVA FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL;
         EXCEPTION WHEN OTHERS THEN aTVAINCASARE := NULL; aDATATVA := NULL;
       END;



    -- testez daca SUNT PE UN AVANS PE CARE L-AM ASIGNAT UNUI CEC
    -- DACA DA, PROPAG NOUL COD DE TREZOR1 PE TABELELE CARE TIN CECUL
       IF V_RECGENERAL.SEMNIFICATIE IN (310, 410) THEN
         FOR V_REC_LINK_AVANS_CEC IN
         (SELECT OA.CODTREZOR1 FROM
           TMP_OBLIGPIF O, TMP_OBLIGPIF_ASOCIAT OA
          WHERE
            O.CODGENERAL = V_RECGENERAL.CODGENERAL AND OA.CODOBLIGASOCIAT = O.CODOBLIGPIF AND OA.SEMNIFICATIE = - V_RECGENERAL.SEMNIFICATIE)
         LOOP
           UPDATE TMP_TREZOR1          SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
           UPDATE TMP_GENERAL_CECURI   SET CODDOC     = V_CODDOC WHERE CODDOC     =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
           UPDATE TMP_OBLIGPIF_ASOCIAT SET CODTREZOR1 = V_CODDOC WHERE CODTREZOR1 =  V_REC_LINK_AVANS_CEC.CODTREZOR1;
           V_RECGENERAL.TIPDOC := 31;
         END LOOP;
       END IF;



   -- codific linii noi din GENERAL si le sincronizez cu OBLIGPIF
      SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO V_CODGENERAL FROM DUAL;

      INSERT INTO GENERAL
      (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, ICONTAVANS, PROCTVAAVANS, FARAREG, DATATVA) VALUES
      (V_CODGENERAL, V_RECGENERAL.TIPDOC, V_CODDOC, V_RECGENERAL.MONEDA, ROUND(V_RECGENERAL.CURS, 7),
      CASE
        WHEN V_RECGENERAL.SEMNIFICATIE &lt;&gt; 200 THEN V_RECGENERAL.TVA
        ELSE NULL
      END,
      V_RECGENERAL.SEMNIFICATIE, V_RECGENERAL.ICONTAVANS, V_RECGENERAL.PROCTVAAVANS,
      V_RECGENERAL.FARAREG,
      CASE
        WHEN aTVAINCASARE = 1 THEN aDATATVA
        ELSE NULL
      END);


-- OBLIGPIF
      FOR V_RECOBLIG IN (SELECT * FROM TMP_OBLIGPIF WHERE CODGENERAL = V_RECGENERAL.CODGENERAL) LOOP
          CODOBLIGFACTURA := NULL;
          IF V_RECOBLIG.MONEDA = 0 THEN aVALOARE := V_RECOBLIG.SUMALEI; ELSE aVALOARE := V_RECOBLIG.SUMAVALUTA;END IF;

          IF (V_RECOBLIG.SEMNIFICATIE = 1303)AND(NVL(V_RECOBLIG.CODOBLIGASOCIAT, 0) &lt;&gt; 0) THEN
           -- LITIGII: PE V_RECOBLIG.CODOBLIGASOCIAT SI V_RECOBLIG.PROCENT TIN LEGATURA CU FACTURA IN LITIGIU
           --          IN TMP_OBLIGVAMA_INITIAL, TMP_GENERAL_LITIGII SI TMP_STINGERE_ASOCIAT TIN OBLIGATIA CARE STINGE FACTURA IN LITIGIU

            -- TRATEZ LEGATURA CU FACTURA
              SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO CODOBLIGFACTURA FROM DUAL;
              SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL   INTO CODGENERALFACTURA FROM DUAL;
              SELECT SEQ_IESIRI_CODIES.NEXTVAL        INTO CODFACTURA FROM DUAL;

              INSERT INTO IESIRI (CODIES, PREFIXDOC, TIPDOC, ANULAT, OPERAT, PARTENER, NRDOC, DATADOC, SUBUNITATEA, AN, LUNA, TVADOC, TVAINCASARE, SERIADOC, MONEDA, CURS)
                                 VALUES(CODFACTURA, &apos;F&apos;, 19, 0, 1, V_RECOBLIG.CODPART, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.SUBUNITATEA, ANI, LUNAI, V_RECOBLIG.TVA, aTVAINCASARE, V_RECOBLIG.SERIADOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURSDOCSTINS);


              INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
                          VALUES (CODGENERALFACTURA, 19, CODFACTURA, V_RECOBLIG.MONEDA, ROUND(V_RECOBLIG.CURS, 7),  200);


              INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
                          VALUES (CODOBLIGFACTURA, CODGENERALFACTURA, V_RECOBLIG.TERMEN, aVALOARE, 0, V_RECOBLIG.CODPART, 3, 200, V_RECOBLIG.CODCENTRU);


              UPDATE TMP_STINGERE_ASOCIAT
              SET
                CODSTINSPIF = CODOBLIGFACTURA
              WHERE
                CODSTINSPIF = V_RECOBLIG.CODOBLIGASOCIAT;

           -- TRATEZ LEGATURA CU COMPENSAREA CARE STINGE FACTURA
             FOR V_REC_STINGEREFACT IN
             (SELECT O.CODOBLIGPIF,
                     G.CODGENERAL,
                     S.CODSTINGERE
              FROM
                TMP_OBLIGVAMA_INITIAL O,
                TMP_GENERAL_LITIGII G,
                TMP_STINGERE_ASOCIAT S
              WHERE
               S.CODSTINSPIF = CODOBLIGFACTURA
               AND O.CODOBLIGPIF = S.CODSTINGATORPIF
               AND G.CODGENERAL  = O.CODGENERAL
              )
              LOOP
                 SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO CODOBLIGCOMPENS FROM DUAL;
                 SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO CODGENERALCOMPENS FROM DUAL;

                 INSERT INTO GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
                 VALUES (CODGENERALCOMPENS, 28, V_CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS, 1350);

                 IF V_RECOBLIG.MONEDA = 0 THEN aVALOARE := V_RECOBLIG.SUMALEI; ELSE aVALOARE := V_RECOBLIG.SUMAVALUTA;END IF;

                 INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CODCENTRU)
                             VALUES (CODOBLIGCOMPENS, CODGENERALCOMPENS, aVALOARE, V_RECOBLIG.CODPART, V_RECOBLIG.ICONT, 1350, V_RECOBLIG.CODCENTRU);


                 INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
                 VALUES (SEQ_STINGERE_CODSTINGERE.NEXTVAL, CODOBLIGFACTURA, CODOBLIGCOMPENS, aVALOARE);
              END LOOP;

          END IF;


          SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO aCODOBLIGPIF FROM DUAL;
          UPDATE TMP_STINGERE SET CODSTINSPIF = aCODOBLIGPIF WHERE CODSTINSPIF = V_RECOBLIG.CODOBLIGPIF;

          INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, TERMEN, MAJORARI, ADAOSDOC, GRATIE, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CODOBLIGASOCIAT, COEFPROVIZION, CODCENTRU)
          VALUES
          (aCODOBLIGPIF, V_CODGENERAL, V_RECOBLIG.TERMEN,  V_RECOBLIG.MAJORARI, V_RECOBLIG.ADAOSDOC, V_RECOBLIG.GRATIE,
           (CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
            END ),
           (CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
            END ),
           aPART, V_RECOBLIG.ICONT, V_RECOBLIG.SEMNIFICATIE,
           CODOBLIGFACTURA,
           CASE
            WHEN V_RECOBLIG.SEMNIFICATIE = 1303
            THEN
             (
               CASE
                 WHEN V_RECOBLIG.SUMALEI = 0 THEN 0
                 ELSE ROUND(V_RECOBLIG.VALPROVIZION / V_RECOBLIG.SUMALEI, 7)
               END
             )
            ELSE NULL
           END,
           V_RECOBLIG.CODCENTRU
           );

          INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA) VALUES
          (aCODOBLIGPIF,
           ANI,
           LUNAI,
           (CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
            END ),
--             NVL(V_RECOBLIG.TVA, 0)
                CASE
                  WHEN V_RECOBLIG.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_RECOBLIG.TVA, 0)
                  ELSE NULL
                END
            );


        -- DOCUMENTE PARINTE
        IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 5, 9) THEN -- INTRARI
          INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA, TVAINCASARE, TIPTVA, TIPTRANZACTIE, PRORATA, VALDOC, SERIADOC, MONEDA, CURS)
          VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
          --&apos;F&apos;,
          PKG_GLOBALS.GETPREFIXDOC(V_RECGENERAL.TIPDOC),
          V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI, 1, V_RECGENERAL.SUBUNITATEA, aTVAINCASARE,
          V_RECOBLIG.TIPTVA, V_RECOBLIG.TIPTRANZACTIE, V_RECOBLIG.PRORATA,
          CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
          END,
          V_RECOBLIG.SERIADOC,
          V_RECOBLIG.MONEDA,
          V_RECOBLIG.CURSDOCSTINS
          );
        ELSE
        IF V_RECGENERAL.TIPDOC IN (19, 20, 21, 22, 26) THEN -- IESIRI
          INSERT INTO IESIRI(CODIES, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, NRDOC, DATADOC, AGENT, CODLOCATIE, OBS, PARTENER, AN, LUNA, INITIALIZARI, SUBUNITATEA, TVADOC, TVAINCASARE, VALDOC, SERIADOC, MONEDA, CURS)
          VALUES (V_CODDOC, V_RECGENERAL.TIPDOC, 0, 0, 1,
          --&apos;F&apos;,
           PKG_GLOBALS.GETPREFIXDOC(V_RECGENERAL.TIPDOC),
           V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, V_RECOBLIG.AGENT, V_RECOBLIG.CODLOCATIE, V_RECOBLIG.OBS, aPART, ANI, LUNAI, 1, V_RECGENERAL.SUBUNITATEA, V_RECOBLIG.TVA, aTVAINcasare,
           CASE
             WHEN V_RECOBLIG.MONEDA = 0 THEN NVL(V_RECOBLIG.SUMALEI, 0)
             ELSE  NVL(V_RECOBLIG.SUMAVALUTA, 0)
           END,
           V_RECOBLIG.SERIADOC,
           V_RECOBLIG.MONEDA,
           V_RECOBLIG.CURSDOCSTINS
           );
        ELSE
        IF V_RECGENERAL.TIPDOC IN (29, 30, 31, 33) THEN -- TREZOR1
           SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL INTO aCODTREZOR FROM DUAL;
           INSERT INTO TREZOR(CODTREZOR, TIPDOC, SUBUNITATEA, AN, LUNA, OPERAT) VALUES (aCODTREZOR, V_RECGENERAL.TIPDOC, V_RECGENERAL.SUBUNITATEA, ANI, LUNAI, 1);
           INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, NRDOC, DATADOC, CODPART, CODLOCATIE, AN, LUNA, INITIALIZARI, AGENT, SERIEDOC, OBS)
           VALUES (V_CODDOC, aCODTREZOR, 1, V_RECOBLIG.NRDOC, V_RECOBLIG.DATADOC, aPART, V_RECOBLIG.CODLOCATIE, ANI, LUNAI, 1, V_RECOBLIG.AGENT, V_RECOBLIG.SERIADOC, V_RECOBLIG.OBS);
           UPDATE TMP_TREZOR1 SET CODTREZOR = aCODTREZOR WHERE CODTREZOR1 = V_CODDOC; -- SINCRONIZARE CEC-uri
        ELSE
         IF V_RECGENERAL.TIPDOC IN (28) THEN
           INSERT INTO COMPENS(CODCOMPENS, DATADOC, NRDOC, AN, LUNA, PARTD, PARTC, SUBUNITATEA, CODTIPPARTINCERT, TIPCOMPENS)
           VALUES (V_CODDOC, V_RECOBLIG.DATADOC, 0, ANI, LUNAI,  V_RECOBLIG.CODPART,  V_RECOBLIG.CODPART, V_RECOBLIG.SUBUNITATEA,
             V_RECOBLIG.CODTIPPARTINCERT,
             CASE
              WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 11 THEN 1
              WHEN V_RECOBLIG.SEMNIFICATIE = 1303 AND V_RECOBLIG.ICONT = 10 THEN 4
              ELSE 0
            END
           );
         END IF;
        END IF;
        END IF;
        END IF;


        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)
        LOOP
          SELECT seq_INTRARI1_CodIntr1.Nextval INTO V_COD from Dual;

          INSERT INTO INTRARI1
           ( CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, RestFact,NrCertif,TG,PUMaximal,PURidicata, ProcAdaos,
           FURNAVIZSUBUNIT, DATAACHIZAVIZSUBUNIT, CODOBLIGSTORNO, CURSFACTURAAVANS, TVANEDED)
           VALUES
             (V_COD,  V_CODDOC, V_RECINTRARI1.IndexLocal , V_RECINTRARI1.CUSTODIE,   V_RECINTRARI1.TipLinie,  V_RECINTRARI1.Umsec,  V_RECINTRARI1.An,  V_RECINTRARI1.Luna,  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT,
              V_RECINTRARI1.GestAct,  V_RECINTRARI1.CodObiect,
              V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
              V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
              V_RECINTRARI1.Cant *  NVL(V_RECINTRARI1.Paritate, 1),  V_RECINTRARI1.TVA, V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG, V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS,
             (CASE
                WHEN V_RECINTRARI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;) THEN V_RECINTRARI1.VALOARE -- valoare discount memorez pe RESTFACT
                ELSE V_RECINTRARI1.Cant *  V_RECINTRARI1.Paritate
              END),
             V_RECINTRARI1.NrCertif,  V_RECINTRARI1.TG,  V_RECINTRARI1.PUMaximal,  V_RECINTRARI1.PURidicata, V_RECINTRARI1.ProcAdaos, V_RECINTRARI1.FURNAVIZSUBUNIT, V_RECINTRARI1.DATAACHIZAVIZSUBUNIT, V_RECINTRARI1.CODOBLIGSTORNO, V_RECINTRARI1.CURSFACTURAAVANS, V_RECINTRARI1.TVANEDED);
        END LOOP; -- INTRARI1



        FOR V_RECINTRARI1 IN (SELECT * FROM TMP_INTRARI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)
        LOOP
          SELECT seq_INTRARI1_CodIntr1.Nextval INTO V_COD from Dual;

          INSERT INTO INTRARI1
           ( CodIntr1, CodIntr, IndexLocal, CUSTODIE, TipLinie, Umsec, An, Luna, ContServ, CONTDISCOUNT, GestAct,CodObiect,PretOrig,PU,Cant,TVA, AdDim, MIFIX, CODOBIECTORIG, PARITATEORIG, COEFDISCMAJ, OBS, TVANEDED
           )
           VALUES
             (V_COD,  V_CODDOC, V_RECINTRARI1.IndexLocal , V_RECINTRARI1.CUSTODIE,   V_RECINTRARI1.TipLinie,  V_RECINTRARI1.Umsec,  V_RECINTRARI1.An,  V_RECINTRARI1.Luna,  V_RECINTRARI1.ContServ, V_RECINTRARI1.CONTDISCOUNT,
              V_RECINTRARI1.GestAct,  V_RECINTRARI1.CodObiect,
              V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
              V_RECINTRARI1.PU /  NVL(V_RECINTRARI1.Paritate, 1),
              V_RECINTRARI1.Cant *  NVL(V_RECINTRARI1.Paritate, 1),  V_RECINTRARI1.TVA, V_RECINTRARI1.AdDim, V_RECINTRARI1.MIFIX, V_RECINTRARI1.CODOBIECTORIG, V_RECINTRARI1.PARITATEORIG, V_RECINTRARI1.COEFDISCMAJ, V_RECINTRARI1.OBS,
              V_RECINTRARI1.TVANeded );
        END LOOP; -- INTRARI1_TVAINCASARE

        IF V_RECGENERAL.TIPDOC IN (1, 2, 3, 4, 9) THEN
          UPDATE INTRARI
          SET
            TVADOC = (SELECT SUM(TVA) FROM INTRARI1 WHERE CODINTR = V_CODDOC)
          WHERE
            CODINTR = V_CODDOC;
        END IF;



        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1 WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)
        LOOP
           SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO V_COD FROM DUAL;

           INSERT INTO IESIRI1
               ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG, PU,
                 CANT, TVA, CONT, PROCDISC, ADDIM, RESTFACT, PUMAXIMAL, TIPLIVRARE, GARANTIE,  CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG )
           VALUES
               ( V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL,  V_RECIESIRI1.TIPLINIE,  V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT,
                 V_RECIESIRI1.PRETORIG,  V_RECIESIRI1.PU / NVL(V_RECIESIRI1.PARITATE,1), V_RECIESIRI1.CANT * NVL(V_RECIESIRI1.PARITATE, 1),
                 V_RECIESIRI1.TVA, V_RECIESIRI1.CONT, V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,

                 CASE
                   WHEN V_RECIESIRI1.TIPLINIE IN (&apos;S&apos;, &apos;=&apos;)  THEN V_RECIESIRI1.CANT * V_RECIESIRI1.PARITATE
                   WHEN V_RECIESIRI1.TIPLINIE IN (&apos;G&apos;, &apos;T&apos;)  THEN V_RECIESIRI1.VALOARE -- VALOARE DISCOUNT MEMOREZ PE RESTFACT
                   ELSE 0
                 END,
                 V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG
                );

        END LOOP; -- IESIRI1


        FOR V_RECIESIRI1 IN (SELECT * FROM TMP_IESIRI1_TVAINCAS WHERE CODGENERAL = V_RECGENERAL.CODGENERAL)
        LOOP
           SELECT SEQ_IESIRI1_CODIES1.NEXTVAL INTO V_COD FROM DUAL;

           INSERT INTO IESIRI1
               ( CODIES1, CODIES, INDEXLOCAL, TIPLINIE, UMSEC, CONTSERV, CONTDISCOUNT, CODCRITERIU, MIFIX, GESTACT, CODOBIECT, PRETORIG, PU,
                 CANT, TVA, CONT, PROCDISC, ADDIM, PUMAXIMAL, TIPLIVRARE, GARANTIE,  CODOBLIGSTORNO, CURSFACTURAAVANS, COEFDISCMAJ, OBS, CODOBIECTORIG, PARITATEORIG )
           VALUES
               ( V_COD, V_CODDOC, V_RECIESIRI1.INDEXLOCAL,  V_RECIESIRI1.TIPLINIE,  V_RECIESIRI1.UMSEC, V_RECIESIRI1.CONTSERV, V_RECIESIRI1.CONTDISCOUNT, V_RECIESIRI1.CODCRITERIU, V_RECIESIRI1.MIFIX, V_RECIESIRI1.GESTACT, V_RECIESIRI1.CODOBIECT,
                 V_RECIESIRI1.PRETORIG,  V_RECIESIRI1.PU / NVL(V_RECIESIRI1.PARITATE,1), V_RECIESIRI1.CANT * NVL(V_RECIESIRI1.PARITATE, 1),
                 V_RECIESIRI1.TVA, V_RECIESIRI1.CONT, V_RECIESIRI1.PROCDISC, V_RECIESIRI1.ADDIM,
                 V_RECIESIRI1.PUMAXIMAL, V_RECIESIRI1.TIPLIVRARE, V_RECIESIRI1.GARANTIE, V_RECIESIRI1.CODOBLIGSTORNO, V_RECIESIRI1.CURSFACTURAAVANS, V_RECIESIRI1.COEFDISCMAJ, V_RECIESIRI1.OBS, V_RECIESIRI1.CODOBIECTORIG, V_RECIESIRI1.PARITATEORIG
                );
        END LOOP; -- IESIRI1_TVAINCAS
      END LOOP; -- OBLIGPIF
  END LOOP; -- GENERAL



-- START CECURI

   FOR V_REC_TREZOR1 IN (SELECT * FROM TMP_TREZOR1) LOOP

     SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL INTO aCODTREZOR FROM DUAL;

     IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
       SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL INTO aCODTREZOR1 FROM DUAL;
     ELSE
       aCODTREZOR1 := V_REC_TREZOR1.CODTREZOR1;
     END IF;


     IF V_REC_TREZOR1.CODTREZOR1 &lt; 0 THEN
         INSERT INTO TREZOR (CODTREZOR, TIPDOC, CODBANCA, AN, LUNA, OPERAT, BLOCAT, SUBUNITATEA)
         VALUES (aCODTREZOR, 31,  V_REC_TREZOR1.CODBANCA, ANI, LUNAI, 1, 0, V_REC_TREZOR1.SUBUNITATEA );

         INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, DOC, NRDOC, DATADOC, CODPART, TIPTRANZ, VALDOC, CURS, TIPDECONT, OBS, DATADECONT,  AN, LUNA, INITIALIZARI, ANULAT)
         VALUES (aCODTREZOR1, aCODTREZOR, 1, V_REC_TREZOR1.DOC, V_REC_TREZOR1.NRDOC, V_REC_TREZOR1.DATADOC, aPART,
                 V_REC_TREZOR1.TIPTRANZ,
                 V_REC_TREZOR1.VALDOC,
                 V_REC_TREZOR1.CURS,
                 V_REC_TREZOR1.TIPDECONT,
                 V_REC_TREZOR1.OBS,
                 V_REC_TREZOR1.DATADECONT,
                 ANI,
                 LUNAI,
                 1,
                 0);
     ELSE
         UPDATE TREZOR
         SET
           TIPDOC       = 31,
           CODBANCA     = V_REC_TREZOR1.CODBANCA,
           AN           = ANI,
           LUNA         = LUNAI,
           OPERAT       = 1,
           BLOCAT       = 0,
           SUBUNITATEA  = V_REC_TREZOR1.SUBUNITATEA
         WHERE
          CODTREZOR = V_REC_TREZOR1.CODTREZOR;

         UPDATE TREZOR1 SET
          DOC                = V_REC_TREZOR1.DOC,
          NRDOC              = V_REC_TREZOR1.NRDOC,
          DATADOC            = V_REC_TREZOR1.DATADOC,
          CODPART            = V_REC_TREZOR1.CODPART,
          TIPTRANZ           = V_REC_TREZOR1.TIPTRANZ,
          VALDOC             = V_REC_TREZOR1.VALDOC,
          CURS               = V_REC_TREZOR1.CURS,
          TIPDECONT          = V_REC_TREZOR1.TIPDECONT,
          OBS                = V_REC_TREZOR1.OBS,
          DATADECONT         = V_REC_TREZOR1.DATADECONT,
          AN         = ANI,
          LUNA       = LUNAI
         WHERE
           CODTREZOR1 = V_REC_TREZOR1.CODTREZOR1;
      END IF;


      UPDATE TMP_GENERAL_CECURI SET CODDOC = aCODTREZOR1 WHERE CODDOC =  V_REC_TREZOR1.CODTREZOR1;

   END LOOP; -- TREZOR1

  FOR V_REC_GENERAL IN (SELECT * FROM TMP_GENERAL_CECURI WHERE SEMNIFICATIE &gt; 0) LOOP
    SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL INTO V_CODGENERAL FROM DUAL;
    UPDATE TMP_OBLIGPIF_ASOCIAT SET CODGENERAL =  V_CODGENERAL WHERE CODGENERAL = V_REC_GENERAL.CODGENERAL;
    INSERT INTO GENERAL  (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
    VALUES   (V_CODGENERAL, V_REC_GENERAL.TIPDOC, V_REC_GENERAL.CODDOC, V_REC_GENERAL.MONEDA, ROUND(V_REC_GENERAL.CURS,7), V_REC_GENERAL.TVA, V_REC_GENERAL.SEMNIFICATIE);
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT WHERE SEMNIFICATIE &gt; 0)
  LOOP
    SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO aCODOBLIGPIF FROM DUAL;
    UPDATE TMP_STINGERE SET CODSTINGATORPIF = aCODOBLIGPIF WHERE CODSTINGATORPIF = V_REC.CODOBLIGPIF;

    INSERT INTO OBLIGPIF (CODOBLIGPIF, CODGENERAL, VALOARE, REST, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE)
    VALUES (aCODOBLIGPIF, V_REC.CODGENERAL, V_REC.VALOARE,
    CASE
     WHEN V_REC.SEMNIFICATIE IN (500, 600) THEN V_REC.VALOARE
     ELSE 0
    END,
    V_REC.CODPART, V_REC.ICONT, V_REC.SEMNIFICATIE, V_REC.CONTBANKTRANZACTIE);

    INSERT INTO OBLIGPIFLUNA (CODOBLIGPIF, AN, LUNA, REST, RESTTVA)
           VALUES
         (aCODOBLIGPIF, ANI, LUNAI,
    CASE
     WHEN V_REC.SEMNIFICATIE IN (500, 600) THEN V_REC.VALOARE
     ELSE 0
    END,
--    NVL(V_REC.TVA, 0)
                CASE
                  WHEN V_REC.SEMNIFICATIE &lt;&gt; 200 THEN NVL(V_REC.TVA, 0)
                  ELSE NULL
                END

    );

  END LOOP;

  INSERT INTO STINGERE(CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
  (SELECT SEQ_STINGERE_CODSTINGERE.NEXTVAL, CODSTINSPIF, CODSTINGATORPIF, VALOARE FROM TMP_STINGERE);

-- END CECURI


 END IF;


 -- MEMOREZ IN NPARTSOLDLUNA;
  PKG_GLOBALS.ANTEMP := ANI; PKG_GLOBALS.LUNATEMP := LUNAI; -- AM NEVOIE DE VARIABILE GLOBALE IN VIEW-urile de solduri de mai jos

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(ANI, LUNAI, ANP, LUNAP);
  PKG_GLOBALS.ANPRECEDENT := ANP; PKG_GLOBALS.LUNAPRECEDENTA := LUNAP;
  PKG_NOMPART.SET_CODPART_SOLD_ANALIZAT(aPART);

  DELETE FROM NPARTSOLDLUNA WHERE AN = ANI AND LUNA = LUNAI AND CODPART = aPART;

  IF aPART &lt;&gt; OLDCODPART THEN
    DELETE FROM NPARTSOLDLUNA WHERE AN = ANI AND LUNA = LUNAI AND CODPART = OLDCODPART;
    DELETE FROM NPARTSOLDLUNASUB WHERE AN = ANI AND LUNA = LUNAI AND CODPART = OLDCODPART;
  END IF;


  INSERT INTO NPARTSOLDLUNA(CODPARTSOLDLUNA, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  (SELECT SEQ_NPARTSOLDLUNA_CODSOLDLUNA.NextVal, CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, PKG_GLOBALS.GETANTEMP, PKG_GLOBALS.GETLUNATEMP
  FROM V_SOLDPART_EXT WHERE CODPART = aPART);


  DELETE FROM NPARTSOLDLUNASUB WHERE AN = ANI AND LUNA = LUNAI AND CODPART = aPART;
/*
  IF aPART &lt;&gt; OLDCODPART THEN
    DELETE FROM NPARTSOLDLUNASUB WHERE AN = ANI AND LUNA = LUNAI AND CODPART = OLDCODPART;
  END IF;
*/

  INSERT INTO NPARTSOLDLUNASUB(CODPARTSOLDLUNASUB, CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, AN, LUNA)
  (SELECT SEQ_NPARTSOLDLUNASUB_COD.NextVal, CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA, PKG_GLOBALS.GETANTEMP, PKG_GLOBALS.GETLUNATEMP
  FROM V_SOLDPARTSUB_EXT WHERE CODPART = aPART);


  -- PROPAG ICONT-ul din OBLIGPIF (daca s-a modificat) PE LINIILE DE OBLIGPIF CARE FAC STINGERI
  FOR V_REC IN
  (SELECT O.CODOBLIGPIF, O.ICONT AS ICONTSTINS, S.CODSTINGATORPIF, OS.ICONT AS ICONTSTINGATOR
   FROM
    TMP_OBLIGPIF O, STINGERE S, OBLIGPIF OS
   WHERE
    S.CODSTINSPIF = O.CODOBLIGPIF AND S.CODSTINGATORPIF = OS.CODOBLIGPIF
   )
  LOOP
    IF V_REC.ICONTSTINS &lt;&gt; V_REC.ICONTSTINGATOR THEN
      UPDATE OBLIGPIF SET ICONT = V_REC.ICONTSTINS WHERE CODOBLIGPIF = V_REC.CODSTINGATORPIF;
    END IF;
  END LOOP;

  SELECT NVL(VOLUMTRANZC, 0), NVL(VOLUMTRANZF, 0) INTO aVOLUMTRANZC, aVOLUMTRANZF FROM TMP_SOLDINI;

  IF aVOLUMTRANZF + aVOLUMTRANZC &gt; 0 THEN
    SELECT COUNT(*) INTO NR
    FROM
      NPART1
    WHERE
      CODPART       = aPART
      AND ANSTART   = PKG_GLOBALS.ANINITIAL
      AND LUNASTART = PKG_GLOBALS.LUNAINITIALA;

    IF NR = 0 THEN
      INSERT INTO NPART1(CODPART1, CODPART, CODIOPART, VOLUMTRANZC, VOLUMTRANZF, ANSTART, LUNASTART)
      VALUES
      (
        SEQ_NPART1_CODPART1.NEXTVAL,
        aPART,
        101,
        aVOLUMTRANZC,
        aVOLUMTRANZF,
        PKG_GLOBALS.ANINITIAL,
        PKG_GLOBALS.LUNAINITIALA
      );
      PRC_AL_REFRESH(&apos;NPART1&apos;, aPART);
    ELSE
      UPDATE NPART1
      SET
        VOLUMTRANZF = aVOLUMTRANZF,
        VOLUMTRANZC = aVOLUMTRANZC
      WHERE
        CODPART       = aPART
        AND ANSTART   = PKG_GLOBALS.ANINITIAL
        AND LUNASTART = PKG_GLOBALS.LUNAINITIALA;
    END IF;
  END IF;
  NotifyModif(Operation, RecId, &apos;SOLDINI&apos;);
  COMMIT;
END;
END PKG_SOLDINITIAL;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SOLDPERSINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06773D549D03AB834C3D278D5F2AB6B9E54F3BAD</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SOLDPERSINI IS


PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT CODSOLDPERSINI INTO TMP FROM SOLDPERSINI WHERE CODSOLDPERSINI = RECID FOR UPDATE NOWAIT;
END; 


PROCEDURE SP_INSERTRECORD
IS
BEGIN
  INSERT INTO TMP_SOLDPERSINI FIELDS( CODSOLDPERSINI ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
 aCODPERS NUMBER(20);
 ANI      NUMBER(5);
 LUNAI    NUMBER(2);

BEGIN
  SELECT CODPERS INTO aCODPERS FROM SOLDPERSINI WHERE CODSOLDPERSINI = RecID; 
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

  DELETE FROM NPERSSOLDLUNA    WHERE CODPERS = aCODPERS AND AN = ANI AND LUNA = LUNAI;
  DELETE FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS AND AN = ANI AND LUNA = LUNAI;
  DELETE FROM SOLDPERSINI   WHERE CODSOLDPERSINI = RECID;
  NotifyModif(2, RecId, &apos;SOLDPERSINI&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RecId IN NUMBER)
IS
  ANI      NUMBER(5);
  LUNAI    NUMBER(2);
  aCODPERS NUMBER(20) := 0;
  aCODIOPERS NUMBER(20) := 0;
  NR    NUMBER(20) := 0;

BEGIN
  INSERT INTO TMP_SOLDPERSINI(CODSOLDPERSINI, CODPERS) 
  SELECT CODSOLDPERSINI, CODPERS FROM SOLDPERSINI WHERE CODSOLDPERSINI = RECID;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

  IF RECID &gt; 0 THEN 
    SELECT NVL(CODPERS, 0) INTO aCODPERS FROM TMP_SOLDPERSINI;
  END IF;

  BEGIN
    SELECT COUNT(*) INTO NR FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS AND AN = ANI AND LUNA = LUNAI;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END; 

  IF NR = 0 THEN  
    INSERT INTO TMP_NPERSSOLDLUNA(CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA)
    SELECT CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, 2 FROM NPERSSOLDLUNA WHERE CODPERS = aCODPERS AND AN = ANI AND LUNA = LUNAI;
  ELSE
    INSERT INTO TMP_NPERSSOLDLUNA(CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA)
    SELECT CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA FROM NPERSSOLDLUNASUB WHERE CODPERS = aCODPERS AND AN = ANI AND LUNA = LUNAI;
  END IF;


  UPDATE TMP_NPERSSOLDLUNA S
  SET
    SIMBOL = PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, S.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(S.CODPERS, PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA)));

  UPDATE TMP_SOLDPERSINI SET SOLDTOTAL = (SELECT SUM(SOLDLEI) FROM TMP_NPERSSOLDLUNA); 
    

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
  aCODPERS NUMBER(20);
  ANI      NUMBER(5);
  LUNAI    NUMBER(2);
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 
  SELECT CODPERS INTO aCODPERS FROM TMP_SOLDPERSINI; 

  IF OPERATION = 0 THEN -- UPDATE
    SELECT  CODSOLDPERSINI INTO RecId FROM TMP_SOLDPERSINI;
    UPDATE SOLDPERSINI SET CODPERS = aCODPERS WHERE CODSOLDPERSINI = RecID;
    
   -- sterg pozitiile care au disparut

/*

    DELETE FROM NPERSSOLDLUNA 
    WHERE 
      AN = ANI AND LUNA = LUNAI AND CODPERS = aCODPERS AND CODPERSSOLDLUNA NOT IN (SELECT CODPERSSOLDLUNA FROM TMP_NPERSSOLDLUNA);
    

    FOR V_REC IN (SELECT * FROM TMP_NPERSSOLDLUNA) LOOP
      IF V_REC.CODPERSSOLDLUNA &lt; 0 THEN
        INSERT INTO NPERSSOLDLUNA (CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
        VALUES (SEQ_NPERSSOLDLUNA_CODSOLDLUNA.NEXTVAL, V_REC.CODPERS, V_REC.ICONT, V_REC.CODMONEDA, V_REC.SOLDLEI, V_REC.SOLDVALUTA, V_REC.AN, V_REC.LUNA) ;
      ELSE
        UPDATE NPERSSOLDLUNA
        SET
          CODPERS    = V_REC.CODPERS, 
          ICONT      = V_REC.ICONT, 
          CODMONEDA  = V_REC.CODMONEDA, 
          SOLDLEI    = V_REC.SOLDLEI, 
          SOLDVALUTA = V_REC.SOLDVALUTA, 
          AN         = V_REC.AN, 
          LUNA       = V_REC.LUNA 
        WHERE CODPERSSOLDLUNA = V_REC.CODPERSSOLDLUNA; 
      END IF;    
    END LOOP;  
 */   
  
  -- a intervenit si defalcarea pe subunitati si trebuie sa simplific algoritmii;

    DELETE FROM NPERSSOLDLUNA 
    WHERE 
      AN = ANI AND LUNA = LUNAI AND CODPERS = aCODPERS; 
  

    DELETE FROM NPERSSOLDLUNASUB 
    WHERE 
      AN = ANI AND LUNA = LUNAI AND CODPERS = aCODPERS; 


     INSERT INTO NPERSSOLDLUNA (CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
     SELECT  SEQ_NPERSSOLDLUNA_CODSOLDLUNA.NEXTVAL,  CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA
     FROM
    ( 
     SELECT CODPERS, ICONT, CODMONEDA, AN, LUNA, SUM(NVL(SOLDLEI, 0)) AS SOLDLEI, SUM(NVL(SOLDVALUTA, 0)) AS SOLDVALUTA
     FROM 
       TMP_NPERSSOLDLUNA 
     GROUP BY  
      CODPERS, ICONT, CODMONEDA, AN, LUNA
      ) ;
     
         
     INSERT INTO NPERSSOLDLUNASUB (CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA)
     SELECT SEQ_NPERSSOLDLUNASUB_COD.NEXTVAL, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA FROM TMP_NPERSSOLDLUNA;



  ELSE  -- INSERT
    SELECT SEQ_SOLDPERSINI_CODSOLDPERSINI.NEXTVAL INTO RECID FROM DUAL;

    INSERT INTO SOLDPERSINI 
    SELECT RECID, aCODPERS FROM DUAL;
/*
    INSERT INTO NPERSSOLDLUNA(CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
    SELECT SEQ_NPERSSOLDLUNA_CODSOLDLUNA.NEXTVAL, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA FROM TMP_NPERSSOLDLUNA;
*/    


     INSERT INTO NPERSSOLDLUNA (CODPERSSOLDLUNA, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA)
     SELECT  SEQ_NPERSSOLDLUNA_CODSOLDLUNA.NEXTVAL,  CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA
     FROM
    ( 
     SELECT CODPERS, ICONT, CODMONEDA, AN, LUNA, SUM(NVL(SOLDLEI, 0)) AS SOLDLEI, SUM(NVL(SOLDVALUTA, 0)) AS SOLDVALUTA
     FROM 
       TMP_NPERSSOLDLUNA 
     GROUP BY  
      CODPERS, ICONT, CODMONEDA, AN, LUNA
      ) ;
     
         
     INSERT INTO NPERSSOLDLUNASUB (CODPERSSOLDLUNASUB, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA)
     SELECT SEQ_NPERSSOLDLUNASUB_COD.NEXTVAL, CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA, AN, LUNA, SUBUNITATEA FROM TMP_NPERSSOLDLUNA;


  END IF;
  NotifyModif(Operation, RecId, &apos;SOLDPERSINI&apos;);
  COMMIT;
END;  

END PKG_SOLDPERSINI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02B391950DB1BC01279D684CACDEA2D3555F9DD6</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SPLITCHELT IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodSPLITCHELT INTO Tmp FROM SPLITCHELT WHERE CodSPLITCHELT = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM SPLITCHELT1 WHERE CodSPLITCHELT = RecId ;
  DELETE FROM SPLITCHELT WHERE CodSPLITCHELT = RecId ;
  NotifyModif(2, RecId, &apos;SPLITCHELT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_SPLITCHELT FIELDS(CodSPLITCHELT, Activ) VALUES (0, 1);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master SPLITCHELT
  INSERT INTO  TMP_SPLITCHELT (CODSPLITCHELT, TIPDOC, CODGest, CODCONT, CODCentru, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA,FAZA, USERID, DATACREARE, ACTIV, Den_Obiect)
    ( SELECT S.CODSPLITCHELT, S.TIPDOC, S.CODGest, S.CODCONT, S.CODCentru, S.CODOBIECT, S.OBS, S.AN, S.LUNA, S.SUBUNITATEA,S.FAZA, S.USERID, S.DATACREARE, S.ACTIV, 
             OBJ.Denumire 
      FROM SPLITCHELT S left join NARTOBJ OBJ on Obj.CODOBIECT = S.CODOBIECT  WHERE CodSPLITCHELT = RecId ) ;

-- Detail SPLITCHELT1
  INSERT INTO  TMP_SPLITCHELT1 ( CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODANALIZANOD, CODCENTRU, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS )
  SELECT CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODANALIZANOD, CODCENTRU, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS   FROM SPLITCHELT1
  WHERE CodSPLITCHELT = RecId
  ORDER BY INDEXLOCAL ;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vCod NUMBER(20);
BEGIN
BEGIN
  IF Operation = 0 THEN  -- UPDATE
  -- Master SPLITCHELT
      SELECT  CodSPLITCHELT INTO RecId FROM TMP_SPLITCHELT;

      UPDATE SPLITCHELT SET ( TIPDOC, CODGest, CODCONT, CODCentru, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA,FAZA, ACTIV )
         = ( SELECT TIPDOC, CODGest, CODCONT, CODCentru, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA,FAZA, ACTIV
            FROM TMP_SPLITCHELT )
      WHERE CodSPLITCHELT = RecId ;

  -- Detail SPLITCHELT1

      DELETE FROM SPLITCHELT1 WHERE  CodSPLITCHELT = RecId 
                              AND CodSPLITCHELT1 NOT IN ( SELECT CodSPLITCHELT1 FROM TMP_SPLITCHELT1);
      FOR v_rec IN ( SELECT * FROM TMP_SPLITCHELT1 ORDER BY INDEXLOCAL) LOOP
        IF v_rec.CodSPLITCHELT1 &lt; 0 THEN
          SELECT SEQ_SPLITCHELT1_CodSPLITCHELT1.NEXTVAL INTO vCod FROM DUAL;
          INSERT INTO SPLITCHELT1 (
            CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODCENTRU, CODANALIZANOD, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS)
          VALUES (
            vCod, RecID, v_rec.INDEXLOCAL, v_rec.CODGEST, v_rec.CODCENTRU, v_rec.CODANALIZANOD, v_rec.CODAUTO, v_rec.CODFORMATIE, v_rec.PROCENT, v_rec.PUNCTE, v_rec.OBS);
        ELSE
          UPDATE SPLITCHELT1 SET
            INDEXLOCAL = v_rec. INDEXLOCAL,
            CODGEST    = v_rec. CODGEST   ,
            CODCENTRU  = v_rec. CODCENTRU ,
            CODAUTO    = v_rec. CODAUTO   ,
						CODFORMATIE= v_rec. CODFORMATIE, 
            PUNCTE     = v_rec.PUNCTE,   
            PROCENT    = v_rec.PROCENT,
            OBS        = v_rec. OBS
          WHERE CodSPLITCHELT1  = v_rec.CodSPLITCHELT1;
        END IF;
      END LOOP;

  ELSE  -- INSERT
  -- Master SPLITCHELT
    SELECT SEQ_SPLITCHELT_CodSPLITCHELT.NEXTVAL INTO RECId FROM DUAL;

    INSERT INTO  SPLITCHELT ( 
      CODSPLITCHELT, TIPDOC, CODGest, CODCONT, CODCENTRU, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA,FAZA, USERID, DATACREARE, ACTIV)
    SELECT 
      RecId, TIPDOC, CODGest, CODCONT, CODCENTRU, CODOBIECT, OBS, AN, LUNA, SUBUNITATEA,FAZA, pkg_globals.USERID,systimestamp, ACTIV
    FROM TMP_SPLITCHELT;
  -- Detail
      FOR v_rec IN ( SELECT * FROM TMP_SPLITCHELT1 ORDER BY INDEXLOCAL) LOOP
        SELECT SEQ_SPLITCHELT1_CodSPLITCHELT1.NEXTVAL INTO vCod FROM DUAL;
        INSERT INTO SPLITCHELT1 (
          CODSPLITCHELT1, CODSPLITCHELT, INDEXLOCAL, CODGEST, CODCENTRU, CODANALIZANOD, CODAUTO, CODFORMATIE, PROCENT, PUNCTE, OBS)
        VALUES (
          vCod, RecID, v_rec.INDEXLOCAL, v_rec.CODGEST, v_rec.CODCENTRU, v_rec.CODANALIZANOD, v_rec.CODAUTO, v_rec.CODFORMATIE, v_rec.PROCENT, v_rec.PUNCTE, v_rec.OBS);
      END LOOP;
  END IF;
  NotifyModif(Operation, RecId, &apos;SPLITCHELT&apos;);
  COMMIT;
 EXCEPTION WHEN OTHERS THEN BEGIN
   ROLLBACK;
   RAISE;
 END;
END;

END;


END pkg_SPLITCHELT; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SPLITTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2DAA5D0140162A0356D8D4160EF1B0C72113706</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SPLITTVA is

FUNCTION TVASTINS_OBLIG_BEFORE_SPLIT(aCODOBLIGPIF  IN NUMBER, VALOBLIG IN NUMBER, TVAOBLIG IN NUMBER) RETURN NUMBER
IS
  TVASTINS NUMBER(20, 7) := 0;
BEGIN
  RETURN 0;
/*
  IF VALOBLIG = 0 THEN  RETURN 0; END IF;
  
  SELECT 
    ROUND(SUM(NVL(TVASTINS, 0)), 2) INTO TVASTINS
  FROM
  (    
  SELECT
    TVAOBLIG * S.VALOARE /  VALOBLIG AS TVASTINS
  FROM
    STINGERE S,
    OBLIGPIF O_STINGATOR
  WHERE
       S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF
      AND NVL(O_STINGATOR.SPLITTVAACTIV, 0) = 0
      AND S.CODSTINSPIF = aCODOBLIGPIF
      AND VALOBLIG &lt;&gt; 0
  );
  RETURN NVL(TVASTINS, 0);  
*/  
END;    

/*

FUNCTION TVASTINS_OBLIGINT_BEFORE_SPLIT(aCODOBLIGPIF  IN NUMBER) RETURN NUMBER
IS
  TVASTINS NUMBER(20, 7);
BEGIN
  SELECT 
    ROUND(SUM(NVL(TVASTINS, 0)), 2) INTO TVASTINS
  FROM
  (    
  SELECT
    O_STINS.CODOBLIGPIF,
    O_STINS.VALOBLIG,
    O_STINS.TVAOBLIG,
    S.VALOARE AS VALSTINSA,
    O_STINS.TVAOBLIG * S.VALOARE/  O_STINS.VALOBLIG AS TVASTINS,
    O_STINS.TVAOBLIG * (O_STINS.VALOBLIG - S.VALOARE) / O_STINS.VALOBLIG AS RESTTVA
  FROM
    STINGERE S,
    OBLIGPIF O_STINGATOR,
    (
    SELECT
      O.CODOBLIGPIF,
      O.VALOARE AS VALOBLIG,
      O.VALOARE * I.TVADOC/I.VALDOC AS TVAOBLIG
    FROM
      OBLIGPIF O,
      GENERAL G,
      INTRARI I
    WHERE
      O.CODOBLIGPIF    = aCODOBLIGPIF
      AND O.CODGENERAL = G.CODGENERAL
      AND G.TIPDOC     = I.TIPDOC
      AND G.CODDOC     = I.CODINTR
    ) O_STINS
    WHERE
       S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF
      AND NVL(O_STINGATOR.SPLITTVAACTIV, 0) = 0
      AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
      AND O_STINS.VALOBLIG &lt;&gt; 0
  );
  RETURN NVL(TVASTINS, 0);  
  
END;    
*/

PROCEDURE SPLITTVA_OBLIGPART_INTRARI(aCODPART IN NUMBER)
IS
BEGIN
  /*
  FOR V_REC IN
  (  
    SELECT 
      CODOBLIGPIF,
      VALOBLIG,
      TVAOBLIG,
      SUM(NVL(VALSTINSA, 0)) AS VALSTINSA,
      ROUND(SUM(NVL(TVASTINS, 0)), 2) AS TVASTINS
    FROM
    (  
    SELECT
      O_STINS.CODOBLIGPIF,
      O_STINS.VALOBLIG,
      O_STINS.TVAOBLIG,
      S.VALOARE AS VALSTINSA,
      O_STINS.TVAOBLIG * S.VALOARE/  O_STINS.VALOBLIG AS TVASTINS
    FROM
      STINGERE S,
      OBLIGPIF O_STINGATOR,
    (
    SELECT
      O.CODOBLIGPIF,
      O.VALOARE AS VALOBLIG,
      NVL(O.VALOARE * I.TVADOC/I.VALDOC, 0) AS TVAOBLIG
    FROM
      OBLIGPIF O,
      GENERAL G,
      INTRARI I
    WHERE
      O.CODPART = aCODPART 
      AND  O.SEMNIFICATIE IN (100)
      AND O.CODGENERAL = G.CODGENERAL
      AND G.TIPDOC = I.TIPDOC
      AND G.CODDOC = I.CODINTR
      AND O.REST &lt;&gt; 0
      AND NVL(O.DINCARETVA, 0) = 0
    )  O_STINS
    WHERE
       S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF
      AND NVL(O_STINGATOR.SPLITTVAACTIV, 0) = 0
      AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
      AND O_STINS.VALOBLIG &lt;&gt; 0
    )
    GROUP BY 
      CODOBLIGPIF,
      VALOBLIG,
      TVAOBLIG
  )
  LOOP
    UPDATE OBLIGPIF
    SET
      DINCARETVA = V_REC.TVAOBLIG - V_REC.TVASTINS,
      RESTTVA    = V_REC.TVAOBLIG - V_REC.TVASTINS
    WHERE
      CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;     
  COMMIT;
*/  
NULL;
END;    


PROCEDURE MAKE_DINCARETVA_LUNA(aCODPART IN NUMBER) -- populeaza COLOANA DINCARETVA DIN OBLIGPIFLUNA DOAR PE LUNA TEMP
IS
BEGIN
  /*
  DELETE TMP_STINGERETVA_LUNA;
  IF aCODPART = 0 THEN 
    INSERT INTO TMP_STINGERETVA_LUNA(CODOBLIGPIF) 
    SELECT 
      CODOBLIGPIF 
    FROM 
      OBLIGPIFLUNA
    WHERE
      AN = PKG_GLOBALS.ANTEMP  AND LUNA = PKG_GLOBALS.LUNATEMP;
  ELSE
    INSERT INTO TMP_STINGERETVA_LUNA(CODOBLIGPIF) 
    SELECT 
      OL.CODOBLIGPIF 
    FROM 
      OBLIGPIFLUNA OL,
      OBLIGPIF O
    WHERE
      OL.AN = PKG_GLOBALS.ANTEMP  
      AND OL.LUNA = PKG_GLOBALS.LUNATEMP
      AND O.CODOBLIGPIF = OL.CODOBLIGPIF
      AND O.CODPART = aCODPART;
  END IF;  

-- POPULEZ COLOANELE VALOAREOBLIGATIE SI TVAOBLIGATIE PENTRU CA AM NEVOIE DE ELE LA PONDERI
  FOR V_REC IN 
  (SELECT 
     TS.CODOBLIGPIF,
     O.VALOARE,
     NVL(E.TVADOC, I.TVADOC) AS TVAOBLIG
   FROM 
     TMP_STINGERETVA_LUNA TS
     INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = TS.CODOBLIGPIF
     INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
     LEFT JOIN INTRARI I ON I.TIPDOC = G.TIPDOC AND I.CODINTR = G.CODDOC
     LEFT JOIN IESIRI E ON E.TIPDOC = G.TIPDOC  AND E.CODIES = G.CODDOC
  )
  LOOP
    UPDATE TMP_STINGERETVA_LUNA
    SET
      VALOBLIG = NVL(V_REC.VALOARE,0),
      TVAOBLIG = NVL(V_REC.TVAOBLIG, 0)
    WHERE
      CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP;  
  
  -- stingeri inainte de SPLITTVA
  UPDATE TMP_STINGERETVA_LUNA TS
  SET
    BEFORESPLIT = (SELECT
                    SUM(TS.TVAOBLIG * S.VALOARE /  TS.VALOBLIG)
                  FROM
                    STINGERE S,
                    OBLIGPIF O_STINGATOR,
                    GENERAL G_STINGATOR
                    LEFT JOIN TREZOR1 T1 ON G_STINGATOR.TIPDOC IN (29, 30, 31) AND T1.CODTREZOR1 = G_STINGATOR.CODDOC
                    LEFT JOIN COMPENS C  ON G_STINGATOR.TIPDOC = 28 AND C.CODCOMPENS = G_STINGATOR.CODDOC
                  WHERE
                    S.CODSTINSPIF = TS.CODOBLIGPIF
                    AND S.CODSTINGATORPIF = O_STINGATOR.CODOBLIGPIF
                    AND NVL(O_STINGATOR.SPLITTVAACTIV, 0) = 0
                    AND O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL
                    AND NVL(T1.AN, C.AN) = PKG_GLOBALS.ANTEMP
                    AND NVL(T1.LUNA, C.LUNA) = PKG_GLOBALS.LUNATEMP
                 )
  WHERE
    NVL(VALOBLIG, 0) &lt;&gt; 0;

  
  -- stingeri dupa SPLITTVA
  UPDATE TMP_STINGERETVA_LUNA TS
  SET
    AFTERSPLIT = (
                  SELECT SUM(NVL(S.DINCARETVA, 0))
                  FROM 
                    STINGERE S,
                    OBLIGPIF O_STINGATOR,
                    GENERAL G_STINGATOR,
                    TREZOR1 T1
                  WHERE
                    S.CODSTINSPIF = TS.CODOBLIGPIF 
                    AND O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                    AND O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL
                    AND G_STINGATOR.TIPDOC IN (29, 30, 31)
                    AND T1.CODTREZOR1 = G_STINGATOR.CODDOC
                    AND T1.AN = PKG_GLOBALS.ANTEMP
                    AND T1.LUNA = PKG_GLOBALS.LUNATEMP
                 ) +   
                 (
                  SELECT SUM(NVL(S.DINCARETVA, 0))
                  FROM 
                    STINGERE S,
                    OBLIGPIF O_STINGATOR,
                    GENERAL G_STINGATOR,
                    COMPENS C
                  WHERE
                    S.CODSTINSPIF = TS.CODOBLIGPIF 
                    AND O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
                    AND O_STINGATOR.CODGENERAL = G_STINGATOR.CODGENERAL
                    AND G_STINGATOR.TIPDOC = 28
                    AND C.CODCOMPENS = G_STINGATOR.CODDOC
                    AND C.AN = PKG_GLOBALS.ANTEMP
                    AND C.LUNA = PKG_GLOBALS.LUNATEMP
                    
                 ); 
      
  
  FOR V_REC IN (SELECT  
                  OL.CODOBLIGPIF, 
                  NVL(OL_PREC.DINCARETVA, TS.TVAOBLIG) AS TVAOBLIG, 
                  NVL(TS.BEFORESPLIT, 0) +  NVL(TS.AFTERSPLIT, 0) AS TVASTINS
                FROM 
                  OBLIGPIFLUNA OL
                  LEFT JOIN OBLIGPIFLUNA OL_PREC ON OL.CODOBLIGPIF = OL_PREC.CODOBLIGPIF 
                          AND OL_PREC.AN = PKG_GLOBALS.ANPRECEDENT
                          AND OL_PREC.LUNA = PKG_GLOBALS.LUNAPRECEDENTA,
                  TMP_STINGERETVA_LUNA TS
                WHERE
                  OL.AN = PKG_GLOBALS.ANTEMP AND OL.LUNA = PKG_GLOBALS.LUNATEMP
                  AND OL.CODOBLIGPIF = TS.CODOBLIGPIF
               )
                  
  LOOP
    UPDATE OBLIGPIFLUNA OL
    SET
      DINCARETVA = ROUND(V_REC.TVAOBLIG - V_REC.TVASTINS, 2)
    WHERE
      OL.CODOBLIGPIF = V_REC.CODOBLIGPIF
      AND  OL.AN = PKG_GLOBALS.ANTEMP AND OL.LUNA = PKG_GLOBALS.LUNATEMP;
  END LOOP;                  
    
  COMMIT;
*/
 NULL;  
END;    

PROCEDURE MAKE_DINCARETVA_LUNA_ALL(aCODPART IN NUMBER)
IS
  ANMIN     NUMBER(5);
  ANMAX     NUMBER(5);
  aANPREC   NUMBER(5);

  LUNAMIN   NUMBER(2);
  LUNAMAX   NUMBER(2);
  aLUNAPREC NUMBER(2);
  
BEGIN
  /*
  IF aCODPART = 0 THEN 
    SELECT DISTINCT AN, LUNA INTO ANMIN, LUNAMIN from obligpifluna where an * 12 + luna = (SELECT MIN(AN * 12 + LUNA) FROM OBLIGPIFLUNA);
    SELECT DISTINCT AN, LUNA INTO ANMAX, LUNAMAX from obligpifluna where an * 12 + luna = (SELECT MAX(AN * 12 + LUNA) FROM OBLIGPIFLUNA);
  ELSE
    SELECT DISTINCT AN, LUNA INTO ANMIN, LUNAMIN 
    FROM 
      obligpifluna OL, 
      OBLIGPIF O 
    WHERE 
      OL.CODOBLIGPIF = O.CODOBLIGPIF
      AND O.CODPART = aCODPART
      AND AN * 12 + LUNA = (SELECT MIN(AN * 12 + LUNA) 
                            FROM 
                               OBLIGPIFLUNA OL,
                               OBLIGPIF O
                            WHERE
                               OL.CODOBLIGPIF = O.CODOBLIGPIF
                               AND O.CODPART = aCODPART  
                             );

    SELECT DISTINCT AN, LUNA INTO ANMAX, LUNAMAX 
    FROM 
      OBLIGPIFLUNA OL, 
      OBLIGPIF O 
    WHERE 
      OL.CODOBLIGPIF = O.CODOBLIGPIF
      AND O.CODPART = aCODPART
      AND AN * 12 + LUNA = (SELECT MAX(AN * 12 + LUNA) 
                            FROM 
                              OBLIGPIFLUNA OL,
                              OBLIGPIF O
                            WHERE
                              OL.CODOBLIGPIF = O.CODOBLIGPIF
                              AND O.CODPART = aCODPART  
                           );

  END IF;    

  WHILE ANMIN * 12 + LUNAMIN &lt;= ANMAX * 12 + LUNAMAX 
  LOOP
     IF LUNAMIN = 1 THEN
       aLUNAPREC := 12;
       aANPREC   := ANMIN - 1;
     ELSE
       aANPREC    := ANMIN;
       aLUNAPREC  := LUNAMIN - 1; 
     END IF;    
     
     PKG_GLOBALS.SetLunaPrecedenta(aANPREC, aLUNAPREC);
     PKG_GLOBALS.SetLunaTemp(ANMIN, LUNAMIN);
     MAKE_DINCARETVA_LUNA(aCODPART);
     

     IF LUNAMIN = 12 THEN
       LUNAMIN := 1;
       ANMIN   := ANMIN + 1;
     ELSE
       LUNAMIN  := LUNAMIN + 1; 
     END IF;    
      
  END LOOP;  
*/
  NULL;  
END;    


end PKG_SPLITTVA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SPVARHIVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF96E21479541C47EE883209727F2C2B972B0D4F</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SPVARHIVA is
procedure CheckNewData
is
begin

  FOR V_REC in (SELECT T.*, SA.IDDESCARCARE AS OrigIdDescarcare,
                            SA. ID_DS AS OrigIDDS, 
                            SA.CIF AS OrigCIF,
                            SA.DATADOCSPV AS OrigDataSPV,
                            SA.CIF_PARTENER AS OrigCIF_PARTENER,
                            SA.VAL_DOC_SPV AS OrigVAL_DOC_SPV,
                            SA.TVA_DOC_SPV AS OrigTVA_DOC_SPV,
                            SA.ID_DOC_SPV AS OrigID_DOC_SPV
                            FROM TMP_SPVARHIVA T 
                            LEFT JOIN SPVARHIVA SA ON T.IDDESCARCARE = SA.IDDESCARCARE and t.tipdoc = sa.tipdoc)
  LOOP
    IF V_rec.OrigIdDescarcare IS NULL THEN
        INSERT INTO SPVARHIVA(CODSPVARHIVA,          
                             AN,          
                             LUNA,          
                             IDDESCARCARE,             
                             DATAINCARCARE,     
                             ZIP,
                             TIPDOC,
                             ID_DS,
                             CIF,
                             DATADOCSPV,
                             CIF_PARTENER,
                             VAL_DOC_SPV,
                             TVA_DOC_SPV,
                             ID_DOC_SPV  
                             )
                             VALUES(SEQ_SPVARHIVA_CODSPVARHIVA.Nextval,
                                    v_rec.AN,          
                                    v_rec.LUNA,          
                                    v_rec.IDDESCARCARE,             
                                    v_rec.DATAINCARCARE,     
                                    v_rec.ZIP,
                                    v_rec.TIPDOC,
                                    v_rec.ID_DS,
                                    v_rec.CIF,
                                    v_rec.DATADOCSPV,
                                    v_rec.CIF_PARTENER,
                                    v_rec.VAL_DOC_SPV,
                                    v_rec.TVA_DOC_SPV,
                                    v_rec.ID_DOC_SPV    
                                   ); 
   
    ELSE 
        IF (V_rec.OrigIDDS IS NULL )THEN 
                UPDATE SPVARHIVA SV SET SV.ID_DS = v_rec.ID_DS
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc ;
           END IF; 
        IF (V_rec.OrigCIF IS NULL) THEN 
                 UPDATE SPVARHIVA SV SET SV.CIF = v_rec.CIF
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
        IF (V_rec.OrigDataSPV IS NULL)THEN 
                 UPDATE SPVARHIVA SV SET SV.DATADOCSPV = v_rec.DATADOCSPV 
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;                        
        IF (V_rec.OrigCIF_PARTENER IS NULL)THEN 
                 UPDATE SPVARHIVA SV SET SV.CIF_PARTENER = v_rec.CIF_PARTENER 
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
        IF (V_rec.OrigVAL_DOC_SPV IS NULL) OR (V_rec.OrigTVA_DOC_SPV IS NULL) THEN 
                 UPDATE SPVARHIVA SV SET SV.VAL_DOC_SPV = v_rec.VAL_DOC_SPV, 
                                         SV.TVA_DOC_SPV = v_rec.TVA_DOC_SPV
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;                        
        IF (V_rec.OrigID_DOC_SPV IS NULL)THEN 
                 UPDATE SPVARHIVA SV SET SV.ID_DOC_SPV = v_rec.ID_DOC_SPV 
                           WHERE SV.IDDESCARCARE = V_rec.OrigIdDescarcare and sv.tipdoc = V_rec.tipdoc;
        END IF;
    END IF;  
  END LOOP;    
  COMMIT;
end;    

end PKG_SPVARHIVA;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STATCON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9A3D168BCD6F2DB3009772632866217F57552E3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_StatCon is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodStatCon INTO Tmp FROM StatCon WHERE CodStatCon = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM StatCon WHERE CodStatCon = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_StatCon FIELDS( CodStatCon ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_StatCon 
	(
   CodStatCon ,
   CodEvalS, 
   Atribut,
   Den_evaluare	
  )
	SELECT 
   S.CodStatCon ,
   S.CodEvalS, 
   S.Atribut,
   E.Den_evaluare
  FROM StatCon S 
  Left Join evals E on E.CODEVALS=S.Codevals
  WHERE CodStatCon = RECID;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodStatCon INTO RECID FROM TMP_StatCon;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE StatCon
    SET
     (
        CodEvalS, 
        Atribut,
        Den_evaluare	
			)
			= 
			(SELECT
       S.CodEvalS, 
       S.Atribut,
       I.Nume	
		FROM TMP_StatCon S
    Left join EvalS E on E.Codevals = S.Codevals
    Left join IdentEvalS I on I.CodIdentEvalS = E.CodIdentEvalS)
    WHERE CodStatCon = RECID;

ELSE  -- INSERT
    SELECT SEQ_StatCon_CodStatCon.NextVal INTO RecId FROM DUAL;
    INSERT INTO StatCon(
     CodStatCon ,
     CodEvalS, 
     Atribut,
     Den_evaluare	
    )
    SELECT 
  	RECID   , 
    S.CodEvalS, 
    S.Atribut,
    I.Nume	
		FROM TMP_StatCon S
    Left join EvalS E on E.Codevals = S.Codevals
    Left join IdentEvalS I on I.CodIdentEvalS = E.CodIdentEvalS;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;StatCon&apos;);
  COMMIT;
 
END;


end PKG_StatCon; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STATCOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA7E565CF75EC81292F89E29BB79C397DD1EBAA8</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_StatCor is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodStatCor INTO Tmp FROM StatCor WHERE CodStatCor = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
   DELETE FROM StatCor WHERE CodStatCor = RecId ;
   DELETE FROM StatCor1 WHERE CodStatCor = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_StatCor FIELDS( CodStatCor ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_StatCor 
  (
   CodStatCor ,
   CodEvalS, 
   Atribut,
   Den_evaluare  
  )
  SELECT 
   S.CodStatCor ,
   S.CodEvalS, 
   S.Atribut,
   E.Den_evaluare
  FROM StatCor S 
  Left Join evals E on E.CODEVALS=S.Codevals
  WHERE CodStatCor = RECID;

  
  INSERT INTO  TMP_StatCor1 
  (
    codstatcor1,
    codStatcor, 
    CodTesatura,
    Valoare,
    Ai,
    Rii  
  )
  SELECT 
    S1.codstatCor1,
    S1.codStatCor, 
    T.CodTes,
    S1.Valoare,  
    S1.Ai,  
    S1.Rii  
  FROM StatCor1 S1 
  LEFT JOIN StatCor S on S.CodStatCor = S1.CodStatCor
  LEFT JOIN EvalSTes T on T.CodEvalS = S.CodEvalS
  WHERE S1.CodStatCor = RECID;
  
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodStatCor INTO RECID FROM TMP_StatCor;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE StatCor
    SET
     (
        CodEvalS, 
        Atribut,
        Den_evaluare  
      )
      = 
      (SELECT
        CodEvalS, 
        Atribut,
        Den_evaluare  
    FROM TMP_StatCor)
    WHERE CodStatCor = RECID;

    DELETE FROM StatCor1 
    where CODStatCor = RecID 
    and CodStatCor1 not in (Select CODStatCor1 from Tmp_StatCor1);

    for v_rec in (select * from Tmp_StatCor1) loop
      if V_Rec.CodStatCor1 &lt; 0 then 
        INSERT INTO StatCor1
          ( 
              codstatcor1,
              codStatcor, 
              CodTesatura,
              Valoare,
              Ai,
              Rii  
          )
          Values 
          ( SEQ_StatCor1_CodStatCor1.Nextval,
            RecId ,
            V_REC.CodTesatura,
            V_REC.Valoare,  
            V_REC.Ai,  
            V_REC.Rii  
          );
      else 
        UPDATE StatCor1
        SET 
          CODStatCor = V_REC.CODStatCor
        WHERE CodStatCor1  = v_rec.CodStatCor1;
      end if;
    end loop;


ELSE  -- INSERT
    SELECT SEQ_StatCor_CodStatCor.NextVal INTO RecId FROM DUAL;

    INSERT INTO StatCor(
     CodStatCor ,
     CodEvalS, 
     Atribut,
     Den_evaluare  
    )
    SELECT 
      RECID   , 
      CodEvalS, 
      Atribut,
      Den_evaluare  
    FROM TMP_StatCor;   


    INSERT INTO StatCor1 (
      CodStatCor1, 
      CodStatCor,
      CodTesatura, 
      Valoare,
      Ai,
      Rii
    )
    SELECT 
      SEQ_StatCor1_CodStatCor1.Nextval, 
      RECID, 
      CodTesatura, 
      Valoare,
      Ai,
      Rii
    FROM TMP_StatCor1;

  END IF; 

  NotifyModif(Operation, RecId, &apos;StatCor&apos;);
  COMMIT;
 
END;


end PKG_StatCor; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STOCINIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0C1BAB33C91AF7D7F21CEA18E5F4E04D3F5987A</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STOCINIART IS

PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT CODSTOCINI INTO TMP FROM STOCINI WHERE CODSTOCINI = RECID FOR UPDATE NOWAIT;
END; 


PROCEDURE SP_INSERTRECORD
IS
BEGIN
  INSERT INTO TMP_STOCINI FIELDS( CODSTOCINI ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
  aGEST  NUMBER(20);
  ANI    NUMBER(5);
  LUNAI  NUMBER(2);
BEGIN

  SELECT CODGEST INTO aGEST FROM STOCINI WHERE CODSTOCINI = RecID; 

  DELETE FROM STOCINI WHERE CODSTOCINI = RecID;

  DELETE TMP_NIRSTOCINI;
  
  INSERT INTO TMP_NIRSTOCINI 
  (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI)

  (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.TVA, I1.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI
   FROM 
     NIRSTOC NS
     LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
     LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
     LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
   WHERE 
   N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
   );

  FOR v_rec IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
    DELETE NIRSER   WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRSERLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
--  DELETE NIR      WHERE CODNIR     = v_rec.CODNIR; riscant dupa rupere de firme
--  DELETE INTRARI1 WHERE CODINTR1   = v_rec.CODINTR1;
--  DELETE INTRARI  WHERE CODINTR    = v_rec.CODINTR;
  END LOOP;

--  DELETE FROM INTRARI WHERE CODINTR IN (SELECT CODINTR FROM TMP_INTRARI);   


-- RECALCULEZ FIXARILE DE PMP;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 
  DELETE FROM PMPLUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR)  AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST
   )
   GROUP BY CODOBIECT, CODSUBUNIT
   )
  LOOP
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CODSUBUNIT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;



  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
   )
   GROUP BY CODOBIECT
   )
  LOOP
    INSERT INTO PMP_ALL_LUNA (CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMP_ALL_LUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;


  NotifyModif(2, RecId, &apos;STOCINI&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RecId IN NUMBER)
IS
aCODGEST NUMBER(20);
BEGIN

   PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO TMP_STOCINI SELECT * FROM STOCINI WHERE CODSTOCINI = RECID;

  IF RECID &gt; 0 THEN 
    SELECT NVL(CODGEST, 0) INTO aCODGEST FROM TMP_STOCINI;
  END IF;

  INSERT INTO TMP_OBJSTOCINI (CODOBIECT, DENOBIECT, TIPSERIE, ARETG, CERTIFICAT, CONTIMPLICIT, PUMAXIMAL, D1, D2, D3, STOCTOTAL) 
  ( SELECT NS.CODOBIECT, O.DENUMIRE, A.TIPSERIE, A.ARETG,  A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, A.D1, A.D2, A.D3 , SUM(CANTNIR) 
    FROM 
      NIRSTOC NS,
      NARTOBJ O
      LEFT OUTER JOIN TMP_NARTOBJ_LUNA OBJLUNA ON OBJLUNA.CODOBIECT = O.CODOBIECT,
      NART A
    WHERE 
     O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND 
     (
       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODINTR FROM INTRARI WHERE CODINTR = N.CODINTR AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 

       OR

       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODTRANSF FROM TRANSF WHERE CODTRANSF = N.CODTRANSF AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 
     )       
    GROUP BY NS.CODOBIECT, O.DENUMIRE, A.TIPSERIE, A.ARETG, A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, a.D1, a.D2, a.D3
  ); 
  
  -- completez temporarele cu valori implicite;
  
    UPDATE TMP_OBJSTOCINI O 
    SET
      CODOBJSTOCINI = ROWNUM,
      DENUM         = PKG_UMSEC.GETDENUM((SELECT UM FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT))),
      UMSEC         = PKG_UMSEC.GETCODUMIMPLICITA((SELECT UM FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT))),
      TVA           = PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT), PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA) / 100,
      (UM1, UM2, RELATIEUM1, RELATIEUM2) = (SELECT NVL(UM1, 0), NVL(UM2, 0), NVL(RELATIEUM1, 0), NVL(RELATIEUM2, 0) FROM NART A WHERE A.CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(O.CODOBIECT));

  
     INSERT INTO TMP_NIRSTOCINI 
     (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE,
     D1, D2, D3, NRCERTIF)
     (SELECT 
         NS.CODNIRSTOC, 
         NS.CODNIR, 
         I1.CODINTR1, 
         I.CODINTR, 
         I.DATADOC, 
         NS.CODOBIECT, 
         NS.CODIOART, 
         NS.UMSEC, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.PRET * U1.PARITATE, 
         NS.TVA, 
         NS.TG, 
         NS.TIPSERIE, 
         NS.CANTNIR /  U1.PARITATE, 
         NS.CODLOCATIE, I.PARTENER, 
         I.INITIALIZARI, 
         NS.PUMAXIMAL * U1.PARITATE, 
         NS.CANTUM1, NS.CANTUM2, 
         NS.PROCENTADAOS, 
         U1.DEN_UM1, 
         U1.PARITATE,
         NS.D1,
         NS.D2,
         NS.D3,
         I1.NRCERTIF
      FROM 
        NIRSTOC NS -- NIR-uri din INTRARI
        LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
        LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC     = U1.CODUM1 AND N.TIPNIR &lt; 10 
     );
  


     INSERT INTO TMP_NIRSTOCINI 
     (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE,
     D1, D2, D3, NRCERTIF)
     (SELECT 
         NS.CODNIRSTOC, 
         NS.CODNIR, 
         I1.CODINTR1, 
         I.CODINTR, 
         I.DATADOC, 
         NS.CODOBIECT, 
         NS.CODIOART, 
         NS.UMSEC, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.PRET * U1.PARITATE, 
         NS.TVA, 
         NS.TG, 
         NS.TIPSERIE, 
         NS.CANTNIR /  U1.PARITATE, 
         NS.CODLOCATIE, I.PARTENER, 
         I.INITIALIZARI, 
         NS.PUMAXIMAL * U1.PARITATE, 
         NS.CANTUM1, NS.CANTUM2, 
         NS.PROCENTADAOS, 
         U1.DEN_UM1, 
         U1.PARITATE,
         NS.D1,
         NS.D2,
         NS.D3,
         I1.NRCERTIF
      FROM 
        NIRSTOC NS -- NIR-uri din IESIRI
        LEFT OUTER JOIN NIR N       ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
        LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
        LEFT OUTER JOIN IESIRI   E  ON E.CODIES    = N.CODIES,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST 
        AND E.AN * 12 + E.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC  = U1.CODUM1 AND N.TIPNIR &gt;= 14 
     );


     INSERT INTO TMP_NIRSTOCINI 
     (CODNIRSTOC, CODNIR, CODTRANSF1, CODTRANSF, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE)
     (SELECT NS.CODNIRSTOC, NS.CODNIR, T1.CODTRANSF1, T.CODTRANSF, T.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, (NS.PRET - NS.ADAOS) * U1.PARITATE, NS.PRET * U1.PARITATE, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR /  U1.PARITATE, NS.CODLOCATIE, NS.FURN,  NS.PUMAXIMAL * U1.PARITATE, NS.CANTUM1, NS.CANTUM2, NS.PROCENTADAOS, U1.DEN_UM1, U1.PARITATE
      FROM 
        NIRSTOC NS -- NIR-uri din TRANSFERURI
        LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1  
        LEFT OUTER JOIN TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST AND T.AN * 12 + T.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC = U1.CODUM1 AND N.TIPNIR IN (12, 13)
     );

  
     INSERT INTO TMP_NIRSERINI (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, CANTUM2, OBS, CodCertif, DataProd, Stare, SERIE, NRCERTIF, TG) 
     (SELECT 
        CODNIRSER, 
        CODNIRSTOC, 
        NS.CODSERIE, 
        CANTNIR,
        CANTUM1,
        CANTUM2, 
        NS.OBS, 
        NS.CodCertif, NS.DataProd, NS.Stare,
        NVL((SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), &apos;&apos;),
        C.NRCERTIF,
        NS.TG
      FROM 
        NIRSER NS
        LEFT OUTER JOIN CERTIF C ON C.CODCERTIF = NS.CODCERTIF
      WHERE 
         CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI));


  UPDATE TMP_NIRSTOCINI NS
  SET
  CODOBJSTOCINI             = (SELECT CODOBJSTOCINI FROM TMP_OBJSTOCINI WHERE CODOBIECT = NS.CODOBIECT),
  (MG, DIFPRET, ARETVANEEX, PUSTANDARD) = (SELECT MG, DIFPRET, ARETVANEEX, PUSTANDARD FROM TMP_IOART_LUNA I1 WHERE I1.CODIOART = NS.CODIOART);


   UPDATE TMP_NIRSERINI NSE
    SET
      PARITATE = NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC AND ROWNUM &lt;= 1),           1), 
      CANTNIR  = CANTNIR / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1), 
      CANTUM1  = CANTUM1 / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1), 
      CANTUM2  = CANTUM2 / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
 ANI           NUMBER(5);
 LUNAI         NUMBER(2);
 vCODINTR      NUMBER(20);
 vCODINTR1     NUMBER(20);
 vCODNIR       NUMBER(20);
 vCODNIRSTOC   NUMBER(20);
 aGEST         NUMBER(20);
 aPERS         NUMBER(20);
 aCODSERIE     NUMBER(20);
 NOMSERIE      VARCHAR2(30);
 vCODNIRSER    NUMBER(20);
BEGIN

 PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

 SELECT CODGEST, CODPERS INTO aGEST, aPERS FROM TMP_STOCINI; 
 
 IF OPERATION = 0 THEN -- UPDATE
  SELECT  CODSTOCINI INTO RecId FROM TMP_STOCINI;

   UPDATE STOCINI 
   SET 
     CODGEST = aGEST, 
     CODPERS = aPERS
   WHERE 
     CODSTOCINI = RecID;
   
  
  -- verific linii serii si stoc sterse;
  FOR V_REC IN 
  (SELECT * FROM NIRSER WHERE CODNIRSTOC IN 
    (SELECT NS.CODNIRSTOC
     FROM 
       NIRSTOC NS
       LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
       LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
     WHERE 
       N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
    ) AND CODNIRSER NOT IN (SELECT CODNIRSER FROM TMP_NIRSERINI)
  ) 
  LOOP
    DELETE NIRSERLUNA  WHERE CODNIRSER = v_rec.CODNIRSER;
    DELETE FROM NIRSER WHERE CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

  FOR V_REC IN  
  (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR
    FROM 
      NIRSTOC NS
      LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
      LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
      LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
    WHERE 
      N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA AND NS.CODNIRSTOC NOT IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI)
  ) 
  LOOP
      DELETE NIRSER   WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE NIRLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

      DELETE NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
--    DELETE NIR      WHERE CODNIR     = v_rec.CODNIR; // riscant dupa ruperi de firma
--    DELETE INTRARI1 WHERE CODINTR1   = v_rec.CODINTR1;
--    DELETE INTRARI  WHERE CODINTR    = v_rec.CODINTR;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     IF V_REC.CODNIRSTOC &lt; 0 THEN -- linie stoc noua de stoc
       SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
       SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
       SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
       SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
       
       INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
       VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);
       
       INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF)
       VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ  / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF );
       
       INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
       VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);

       INSERT INTO NIRSTOC
       (CODNIRSTOC, 
        CODNIR, 
        CODINTR1, 
        CANTNIR, 
        REST, 
        UMSEC, 
        CODOBIECT, 
        CODIOART, 
        PRET, 
        ADAOS, 
        TVA, 
        TIPSERIE, 
        FURN, 
        DATAACHIZ, 
        TIPDOCACHIZ, 
        PUMAXIMAL, 
        CODLOCATIE, 
        TG, 
        CANTUM1, 
        RESTUM1,  
        CANTUM2, 
        RESTUM2, 
        PROCENTADAOS,
        D1,
        D2,
        D3)
       VALUES (vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR * V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.PRETINREG  / V_REC.PARITATE, (V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE,
          V_REC.FURNIZOR,
          V_REC.DATADOC,
          1,
          V_REC.PUMAXIMAL  / V_REC.PARITATE,
          V_REC.CODLOCATIE,
          V_REC.TG,
          V_REC.CANTUM1, 
          V_REC.CANTUM1,  
          V_REC.CANTUM2, 
          V_REC.CANTUM2,
          V_REC.PROCENTADAOS,  
          V_REC.D1,  
          V_REC.D2,  
          V_REC.D3  
           );

       INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR  * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);


       FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
       
          IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
          BEGIN
            SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
            EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
          END;
          
          IF NVL(aCODSERIE, 0) = 0 THEN 
            SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
            INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
          END IF; 
        ELSE
          aCODSERIE := V_RECNIRSER.CODSERIE;  
          -- verific daca la editare nu a schimbat seria
          SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
          
          IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
            UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
          END IF;  
        END IF;

       SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCODNIRSER FROM DUAL;
       

       INSERT INTO NIRSER 
       (CODNIRSER,  CODNIRSTOC,  CODSERIE,  
       CANTNIR, REST, 
       CANTUM1, RESTUM1, 
       CANTUM2, RESTUM2, 
       OBS, CodCertif, DataProd, Stare, TG) 
       VALUES             
       (vCODNIRSER, vCODNIRSTOC, aCODSERIE, 
       V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
       V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, 
       V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
       V_RECNIRSER.OBS, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);

       INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);

      END LOOP;

     ELSE
       UPDATE INTRARI
       SET 
         DATADOC  = v_rec.DATADOC, 
         PARTENER = v_rec.FURNIZOR
       WHERE  
         CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR);
       
       UPDATE INTRARI1
       SET
         UMSEC     = V_REC.UMSEC,
         PRETORIG  = v_rec.PRETACHIZ / v_rec.PARITATE, 
         PU        = v_rec.PRETACHIZ / v_rec.PARITATE, 
         CANT      = v_rec.CANTNIR * v_rec.PARITATE, 
         TG        = v_rec.TG,
         NRCERTIF  = V_REC.NRCERTIF, 
         PUMAXIMAL = v_rec.PUMaximal / v_rec.PARITATE
       WHERE 
         CODINTR1 = v_rec.CODINTR1 ;  
         

       UPDATE NIR
       SET
         DATANIR = v_rec.DATADOC, 
         GEST    = aGEST
       WHERE 
         CODNIR = v_rec.CODNIR ;  


       UPDATE NIRSTOC
       SET
         CANTNIR      = V_REC.CANTNIR * V_REC.PARITATE, 
         CANTUM1      = V_REC.CANTUM1, 
         CANTUM2      = V_REC.CANTUM2, 
         CODIOART     = V_REC.CODIOART, 
         UMSEC        = V_REC.UMSEC,
         PRET         = V_REC.PRETINREG / v_rec.PARITATE, 
         ADAOS        = (V_REC.PRETINREG - V_REC.PRETACHIZ) / v_rec.PARITATE, 
         TVA          = V_REC.TVA,
         REST         = PKG_INTRARI.GET_REST_STOC(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * v_rec.PARITATE),
         RESTUM1      = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
         RESTUM2      = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
         FURN         = V_REC.FURNIZOR,
         DATAACHIZ    = V_REC.DATADOC,
         TIPDOCACHIZ  = 1,
         PUMAXIMAL    = V_REC.PUMAXIMAL / v_rec.PARITATE,
         CODLOCATIE   = V_REC.CODLOCATIE,
         TG           = V_REC.TG,
         PROCENTADAOS = V_REC.PROCENTADAOS,
         D1           = V_REC.D1,
         D2           = V_REC.D2,
         D3           = V_REC.D3
       WHERE 
          CODNIRSTOC = v_rec.CODNIRSTOC;
       
       --propag din nou furnizorul pe pozitiile de stoc generate prin transfer
       PropagaFurn(v_rec.codnirstoc, v_rec.furnizor);          

       FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP


          IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :2; verific daca trebuie sa actualizez si NSERII
            BEGIN
              SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
              EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
            END;
            
            IF NVL(aCODSERIE, 0) = 0 THEN 
              SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
              INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
            END IF; 
          ELSE
            aCODSERIE := V_RECNIRSER.CODSERIE;  
            -- verific daca la editare nu a schimbat seria
            SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
            
            IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
              UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
            END IF;  
          END IF;


         IF V_RECNIRSER.CODNIRSER &lt; 0 THEN      
           SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL  INTO vCODNIRSER FROM DUAL;

           INSERT INTO NIRSER 
           (CODNIRSER, CODNIRSTOC, CODSERIE, 
           CANTNIR, REST, 
           CANTUM1, RESTUM1, 
           CANTUM2, RESTUM2, 
           Obs, CodCertif, DataProd, Stare, TG) 
           VALUES 
           (vCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, 
           V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,  
           V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1,  
           V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
           V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);       

           INSERT INTO NIRSERLUNA (CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2) 
           VALUES (vCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,  V_RECNIRSER.CANTUM1,  V_RECNIRSER.CANTUM2);       
         ELSE
           UPDATE NIRSER
           SET
             CODSERIE = aCODSERIE, 
             CANTNIR  = V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
             CANTUM1  = V_RECNIRSER.CANTUM1, 
             CANTUM2  = V_RECNIRSER.CANTUM2, 
             OBS      = V_RECNIRSER.Obs, 
             CodCertif= V_RECNIRSER.CodCertif, 
             DataProd = V_RECNIRSER.DataProd, 
             Stare    = V_RECNIRSER.Stare   , 
             TG       = V_RECNIRSER.TG , 
             REST     = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE),
             RESTUM1  = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1),
             RESTUM2  = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2)
           WHERE
             CODNIRSER = V_RECNIRSER.CODNIRSER;  

           UPDATE NIRSERLUNA
           SET
             REST    = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE),
             RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1),
             RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2)
           WHERE
             CODNIRSER = V_RECNIRSER.CODNIRSER;  

         END IF;
       END LOOP;


        UPDATE NIRLUNA
        SET
          REST    = V_REC.CANTNIR * V_REC.PARITATE,
          RESTUM1 = V_REC.CANTUM1,
          RESTUM2 = V_REC.CANTUM2
        WHERE 
          CODNIRSTOC = v_rec.CODNIRSTOC;       
     END IF; 
  END LOOP;
 ELSE -- INSERT
   SELECT SEQ_STOCINI_CODSTOCINI.NEXTVAL INTO RECID FROM DUAL;
   INSERT INTO STOCINI (SELECT RECID, CODGEST, CODPERS FROM TMP_STOCINI);
   
   FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
     SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
     SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
     SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
       
     INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
     VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);
       
     INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMaximal, NRCERTIF)
     VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ  / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF);
       
     INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
     VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);


     INSERT INTO NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, PRET, ADAOS, TVA, TIPSERIE, FURN, DATAACHIZ, TIPDOCACHIZ, PUMAXIMAL, CODLOCATIE, TG, CANTUM1, RESTUM1, CANTUM2, RESTUM2, PROCENTADAOS, D1, D2, D3)
     VALUES (vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR  * V_REC.PARITATE, v_rec.CANTNIR  * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.PRETINREG / V_REC.PARITATE, (V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE,
             V_REC.FURNIZOR, V_REC.DATADOC, 1, V_REC.PUMAXIMAL  / V_REC.PARITATE, V_REC.CODLOCATIE, V_REC.TG, V_REC.CANTUM1, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CANTUM2, V_REC.PROCENTADAOS,
             V_REC.D1, V_REC.D2, V_REC.D3);


     INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
     VALUES (vCODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);
   
     FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
       IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :3; verific daca trebuie sa actualizez si NSERII
         BEGIN
           SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = (SELECT CODOBIECT FROM NIRSTOC WHERE CODNIRSTOC = V_REC.CODNIRSTOC);
           EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
         END;
         
         IF NVL(aCODSERIE, 0) = 0 THEN 
           SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
           INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
         END IF; 
       ELSE
         aCODSERIE := V_RECNIRSER.CODSERIE;  
         -- verific daca la editare nu a schimbat seria
         SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
         
         IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
           UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
         END IF;  
       END IF;
   
       SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCODNIRSER FROM DUAL;
 
       INSERT INTO NIRSERLUNA (CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2) 
           VALUES (vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2);
 
       INSERT INTO NIRSER 
       (CODNIRSER, CODNIRSTOC, CODSERIE, 
       CANTNIR, REST, 
       CANTUM1, RESTUM1, 
       CANTUM2, RESTUM2, 
       Obs, CodCertif, DataProd, Stare, TG) 
       VALUES 
       (vCODNIRSER, vCODNIRSTOC, aCODSERIE, 
       V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
       V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, 
       V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
       V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, V_RECNIRSER.Stare, V_RECNIRSER.TG);
     END LOOP;
   END LOOP;
   
 END IF;

-- RECALCULEZ FIXARILE DE PMP;
  DELETE FROM PMPLUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR)  AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST
   )
   GROUP BY CODOBIECT, CODSUBUNIT
   )
  LOOP
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CODSUBUNIT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;



  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
   )
   GROUP BY CODOBIECT
   )
  LOOP
    INSERT INTO PMP_ALL_LUNA (CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMP_ALL_LUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;

  NotifyModif(Operation, RecId, &apos;STOCINI&apos;);
  COMMIT;  
END;

procedure PropagaFurn(acodnirstoc in number, afurn in number) is
begin
  for v_Rec in (select codnirstoc
                from nirstoc where codnirstocparinte = acodnirstoc) loop
    update nirstoc set furn = afurn where codnirstoc = v_rec.codnirstoc;
    PropagaFurn(v_rec.codnirstoc,afurn);            
  end loop;
end;

END PKG_STOCINIART; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STOCINITIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13C8CD0D4E206F1FB3B4D26BB5114985E2224F2E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STOCINITIAL IS


PROCEDURE TEST
IS
BEGIN
  PKG_GLOBALS.SETUSERID(1);COMMIT;
  PKG_GLOBALS.SETSUBUNITATE(2);COMMIT;
  PKG_GLOBALS.ANINITIAL := 2019; 
  PKG_GLOBALS.LUNAINITIALA := 1; 
  PKG_GLOBALS.SETLUNALUCRU(2019, 1); 
  PKG_STOC_GENERARE_FACTURI.make_config_luna;
  PKG_STOCINITIAL.SP_GOTORECORD(104);
END;    

PROCEDURE UNLOCK_CODGEST(aUSERID IN NUMBER)
IS
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  DELETE FROM CODGESTLOCK WHERE USERID = aUSERID OR USERID IS NULL;
  COMMIT;
END;


FUNCTION CAN_LOCK_CODGEST(aCOD IN NUMBER, aUSERID IN NUMBER)RETURN NUMBER
IS
 NR NUMBER(10) := 0;
 PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  SELECT COUNT(*) INTO NR FROM CODGESTLOCK
  WHERE 
   GEST   = aCOD
   AND USERID &lt;&gt; aUSERID;

   
  IF NR &gt; 0 THEN RETURN 0;
  ELSE 
    INSERT INTO CODGESTLOCK (COD, GEST, USERID)
    VALUES (SEQ_CODGESTLOCK_COD.NEXTVAL, aCOD, aUSERID);
    COMMIT;
    RETURN 1;
  END IF;  
END;



PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT CODSTOCINI INTO TMP FROM STOCINI WHERE CODSTOCINI = RECID FOR UPDATE NOWAIT;
END; 


PROCEDURE SP_INSERTRECORD
IS
BEGIN
  INSERT INTO TMP_STOCINI FIELDS( CODSTOCINI ) VALUES (0) ;
  COMMIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
  aGEST  NUMBER(20);
  ANI    NUMBER(5);
  LUNAI  NUMBER(2);
BEGIN
  SELECT CODGEST INTO aGEST FROM STOCINI WHERE CODSTOCINI = RecID; 

  DELETE FROM STOCINI WHERE CODSTOCINI = RecID;
  DELETE TMP_INTRARI1;
  DELETE TMP_TRANSF1;

  DELETE TMP_NIRSTOCINI;
  
  INSERT INTO TMP_NIRSTOCINI 
  (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, TIPNIR)

  (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.PUVAL, NS.TVA, I1.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, I.PARTENER, I.INITIALIZARI, N.TIPNIR
   FROM 
     NIRSTOC NS
     LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
     LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
     LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
   WHERE 
      N.GEST = aGEST 
      AND COALESCE(N.TIPNIR, 0) NOT IN (12, 13) 
      AND 
      (
        I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        OR
        EXTRACT(YEAR FROM I.DATADOC) * 12 + EXTRACT(MONTH FROM I.DATADOC) &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
      )  
   );
  

  INSERT INTO TMP_NIRSTOCINI 
  (CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ, PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, TIPNIR)

  (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODTRANSF1, I.CODTRANSF, I.DATADOC, NS.CODOBIECT, NS.CODIOART, NS.UMSEC, NS.PRET - NS.ADAOS, NS.PRET, NS.PUVAL, NS.TVA, NS.TG, NS.TIPSERIE, NS.CANTNIR, NS.CODLOCATIE, 0, 1, N.TIPNIR
   FROM 
     NIRSTOC NS
     LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
     LEFT OUTER JOIN TRANSF1 I1 ON I1.CODTRANSF1 = NS.CODTRANSF1  
     LEFT OUTER JOIN TRANSF  I  ON I.CODTRANSF   = N.CODTRANSF
   WHERE 
      N.GEST = aGEST 
      AND COALESCE(N.TIPNIR, 0) IN (12, 13) 
      AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
   );



  DELETE TMP_MANEVRA;
  INSERT INTO TMP_MANEVRA (CodUnic)
  SELECT codnirstoc FROM TMP_NIRSTOCINI;
  pkg_pretprod.SetDirtyStructura;
  
  FOR v_rec IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
    DELETE NIRSER   WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRSERLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
    DELETE NIRSTOC1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
--  DELETE NIR      WHERE CODNIR     = v_rec.CODNIR; riscant dupa rupere de firme
    
    IF V_REC.TIPNIR NOT IN (12, 13) THEN
      INSERT INTO TMP_INTRARI1(CODINTR1) VALUES (v_rec.CODINTR1);
    ELSE  
      INSERT INTO TMP_TRANSF1(CODTRANSF1) VALUES (v_rec.CODINTR1);
    END IF;  
      
--  DELETE INTRARI1 WHERE CODINTR1   = v_rec.CODINTR1;
--  DELETE INTRARI  WHERE CODINTR    = v_rec.CODINTR;
  END LOOP;

  FOR v_rec IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     DELETE NIR N WHERE CODNIR     = v_rec.CODNIR AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODNIR = V_REC.CODNIR) = 0;
  END LOOP;


--  DELETE FROM INTRARI WHERE CODINTR IN (SELECT CODINTR FROM TMP_INTRARI);   

  DELETE FROM INTRARI1 I1
  WHERE
    EXISTS (SELECT CODINTR1 FROM TMP_INTRARI1 TI1 WHERE TI1.CODINTR1 = I1.CODINTR1)
    AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODINTR1 = I1.CODINTR1) = 0;
  
  DELETE FROM TRANSF1 I1
  WHERE
    EXISTS (SELECT CODTRANSF1 FROM TMP_TRANSF1 TI1 WHERE TI1.CODTRANSF1 = I1.CODTRANSF1)
    AND (SELECT COUNT(*) FROM NIRSTOC WHERE CODTRANSF1 = I1.CODTRANSF1) = 0;

  
-- RECALCULEZ FIXARILE DE PMP;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 
  DELETE FROM PMPLUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR)  AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST

   UNION ALL 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     TRANSF I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODTRANSF = N.CODTRANSF
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST

   UNION ALL 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     IESIRI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (14, 15, 19) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODIES = N.CODIES
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST


   )
   GROUP BY CODOBIECT, CODSUBUNIT
   )
  LOOP
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CODSUBUNIT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;



  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
   UNION ALL  
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     TRANSF I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODTRANSF = N.CODTRANSF
     AND I.AN = ANI AND I.LUNA = LUNAI
   UNION ALL  
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     IESIRI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (14, 15, 19) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODIES = N.CODIES
     AND I.AN = ANI AND I.LUNA = LUNAI
   )
   GROUP BY CODOBIECT
   )
  LOOP
    INSERT INTO PMP_ALL_LUNA (CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA)
   VALUES 
   ( SEQ_PMP_ALL_LUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI
   ); 
  END LOOP;


  NotifyModif(2, RecId, &apos;STOCINI&apos;);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RecId IN NUMBER)
IS
aCODGEST NUMBER(20);
BEGIN

   PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;

  INSERT INTO TMP_STOCINI SELECT * FROM STOCINI WHERE CODSTOCINI = RECID;

  IF RECID &gt; 0 THEN 
    SELECT NVL(CODGEST, 0) INTO aCODGEST FROM TMP_STOCINI;
  END IF;

  INSERT INTO TMP_OBJSTOCINI (CODOBJSTOCINI, 
                              CODOBIECT, 
                              DENOBIECT, 
                              CODEXTERN, 
                              CODINTERN, 
                              TIPSERIE, 
                              ARETG, 
                              CERTIFICAT, 
                              CONTIMPLICIT, 
                              PUMAXIMAL, 
                              D1, 
                              D2, 
                              D3, 
                              STOCTOTAL,
                              UMSEC,  
                              DENUM,
                              UM1,
                              UM2, 
                              RELATIEUM1,
                              RELATIEUM2,
                              TVA
                              ) 
 SELECT ROWNUM, 
        OI.CODOBIECT,
        O.DENUMIRE,
        O.CODEXTERN, 
        O.CODINTERN, 
        A.TIPSERIE,
        A.ARETG,
        A.CERTIFICAT, 
        A.CONTIMPLICIT, 
        OBJLUNA.PRETMAXIMAL, 
        A.D1, 
        A.D2, 
        A.D3,
        OI.CANTNIR,
        USEC.CODUM1,
        U.DEN_UM,
        A.UM1,
        A.UM2, 
        A.RELATIEUM1,
        A.RELATIEUM2, 
        TL.PROCENT/100
FROM     
 (                        
 SELECT CODOBIECT, SUM(CANTNIR) AS CANTNIR
 FROM
   NIRSTOC NS
 WHERE
     (
       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODINTR FROM INTRARI WHERE CODINTR = N.CODINTR AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 

       OR

       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODTRANSF FROM TRANSF WHERE CODTRANSF = N.CODTRANSF AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 



       OR

       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODIES FROM IESIRI WHERE CODIES = N.CODIES AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 


     )    
 GROUP BY CODOBIECT       
 ) OI,
   NARTOBJ O
   LEFT OUTER JOIN TMP_NARTOBJ_LUNA OBJLUNA ON OBJLUNA.CODOBIECT = O.CODOBIECT,
   NART A,
   NUM U,
   NUM1 USEC,
   TMP_NART_LUNA AL,
   TMP_NTVA_LUNA TL 
 WHERE
    OI.CODOBIECT = O.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND U.CODUM = A.UM
    AND USEC.CODUM = U.CODUM
    AND USEC.SECUNDARA = 0
    AND AL.CODARTICOL = A.CODARTICOL
    AND  TL.CODTVA = AL.CODTVA;
     
   

/*
  SELECT ROWNUM, OI.* FROM
  ( SELECT NS.CODOBIECT, O.DENUMIRE, O.CODEXTERN, O.CODINTERN, A.TIPSERIE, A.ARETG,  A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, A.D1, A.D2, A.D3 , SUM(CANTNIR) AS CANTNIR 
    FROM 
      NIRSTOC NS,
      NARTOBJ O
      LEFT OUTER JOIN TMP_NARTOBJ_LUNA OBJLUNA ON OBJLUNA.CODOBIECT = O.CODOBIECT,
      NART A
    WHERE 
     O.CODOBIECT = NS.CODOBIECT
     AND A.CODARTICOL = O.CODARTICOL
     AND 
     (
       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODINTR FROM INTRARI WHERE CODINTR = N.CODINTR AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 

       OR

       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODTRANSF FROM TRANSF WHERE CODTRANSF = N.CODTRANSF AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 



       OR

       EXISTS (SELECT CODNIR FROM NIR N WHERE N.CODNIR = NS.CODNIR AND GEST = aCODGEST AND EXISTS
              (SELECT CODIES FROM IESIRI WHERE CODIES = N.CODIES AND AN * 12 + LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA)) 


     )       
    GROUP BY NS.CODOBIECT, O.DENUMIRE, O.CODEXTERN, O.CODINTERN, A.TIPSERIE, A.ARETG, A.CERTIFICAT, A.CONTIMPLICIT, OBJLUNA.PRETMAXIMAL, a.D1, a.D2, a.D3
  ) OI; 
*/  
  -- completez temporarele cu valori implicite;
 /* 
    UPDATE TMP_OBJSTOCINI O 
    SET
      CODOBJSTOCINI = ROWNUM,
      DENUM         = PKG_UMSEC.GETDENUM((SELECT UM FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT))),
      UMSEC         = PKG_UMSEC.GETCODUMIMPLICITA((SELECT UM FROM NART WHERE CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT))),
      TVA           = PKG_SELECTARTICOLE.GETPROCENTTVA(PKG_SELECTARTICOLE.GETARTOFOBJECT(CODOBIECT), PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA) / 100,
      (UM1, UM2, RELATIEUM1, RELATIEUM2) = (SELECT NVL(UM1, 0), NVL(UM2, 0), NVL(RELATIEUM1, 0), NVL(RELATIEUM2, 0) FROM NART A WHERE A.CODARTICOL = PKG_SELECTARTICOLE.GETARTOFOBJECT(O.CODOBIECT));
*/


     INSERT INTO TMP_NIRSTOCINI 
     (CODOBJSTOCINI, CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE,
     D1, D2, D3, 
     NRCERTIF,
     ROTLEI,
     ROTVALUTA,
     TIPNIR,
     CODGESTPROD,
     REST,
     SERIELOT,
     CODCENTRU, 
     TIPIMPORT,
     PROVIZION,
     UM1,
     UM2,
     MG,
     DIFPRET,
     ARETVANEEX,
     PUSTANDARD,
     DENOBIECT,
     PRETINITIAL,
     ACHIZINITIAL,
     CODIOARTINITIAL, 
     EUDR_RN, EUDR_VN
     )
     (SELECT 
         OI.CODOBJSTOCINI,
         NS.CODNIRSTOC, 
         NS.CODNIR, 
         I1.CODINTR1, 
         I.CODINTR, 
         I.DATADOC, 
         NS.CODOBIECT, 
         NS.CODIOART, 
         NS.UMSEC, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.PRET * U1.PARITATE, 
         NS.PUVAL * U1.PARITATE, 
         NS.TVA, 
         NS.TG, 
         NS.TIPSERIE, 
         NS.CANTNIR /  U1.PARITATE, 
         NS.CODLOCATIE, I.PARTENER, 
         I.INITIALIZARI, 
         NS.PUMAXIMAL * U1.PARITATE, 
         NS.CANTUM1, NS.CANTUM2, 
         NS.PROCENTADAOS, 
         U1.DEN_UM1, 
         U1.PARITATE,
         NS.D1,
         NS.D2,
         NS.D3,
         I1.NRCERTIF,
         NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
         NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
         N.TIPNIR,
         NS.CODGESTPROD,
         NS.REST,
         NS.SERIELOT,
         I1.CODCENTRU,
         Nvl(D.TIPIMPORT, 0),
         NS.PROVIZION,
         A.UM1,
         A.UM2,
         IOA.MG,
         IOA.DIFPRET,
         IOA.ARETVANEEX,
         IOA.PUSTANDARD,
         NOBJ.DENUMIRE,
         NS.PRET * U1.PARITATE, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.CODIOART, 
         NS.EUDR_RN, NS.EUDR_VN
      FROM 
        NIRSTOC NS -- NIR-uri din INTRARI
        LEFT JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART
        LEFT JOIN TMP_OBJSTOCINI OI ON OI.CODOBIECT = NS.CODOBIECT
        LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1
        LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT  
        LEFT OUTER JOIN NART A ON A.CODARTICOL = NOBJ.CODARTICOL
        LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
        LEFT OUTER JOIN DVI D  ON D.CODINTR   = N.CODINTR,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC     = U1.CODUM1 AND N.TIPNIR &lt; 10
     );
  


     INSERT INTO TMP_NIRSTOCINI 
     (CODOBJSTOCINI, CODNIRSTOC, CODNIR, CODINTR1, CODINTR, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, INITIALIZARI, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE,
     D1, D2, D3, 
     NRCERTIF,
     ROTLEI,
     ROTVALUTA,
     TIPNIR,
     CODGESTPROD,
     REST,
     SERIELOT,
     PROVIZION,
     UM1,
     UM2,
     MG,
     DIFPRET,
     ARETVANEEX,
     PUSTANDARD,
     DENOBIECT,
     PRETINITIAL,
     ACHIZINITIAL,
     CODIOARTINITIAL, 
     EUDR_RN, EUDR_VN
     )
     (SELECT 
         OI.CODOBJSTOCINI,
         NS.CODNIRSTOC, 
         NS.CODNIR, 
         I1.CODINTR1, 
         I.CODINTR, 
         I.DATADOC, 
         NS.CODOBIECT, 
         NS.CODIOART, 
         NS.UMSEC, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.PRET * U1.PARITATE, 
         NS.PUVAL * U1.PARITATE, 
         NS.TVA, 
         NS.TG, 
         NS.TIPSERIE, 
         NS.CANTNIR /  U1.PARITATE, 
         NS.CODLOCATIE, I.PARTENER, 
         I.INITIALIZARI, 
         NS.PUMAXIMAL * U1.PARITATE, 
         NS.CANTUM1, NS.CANTUM2, 
         NS.PROCENTADAOS, 
         U1.DEN_UM1, 
         U1.PARITATE,
         NS.D1,
         NS.D2,
         NS.D3,
         I1.NRCERTIF,
         NVL(NS.ROTLEI , NOBJ.ROTUNJIRE),
         NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA),
         N.TIPNIR,
         NS.CODGESTPROD,
         NS.REST,
         NS.SERIELOT,
         NS.PROVIZION,
         A.UM1,
         A.UM2,
         IOA.MG,
         IOA.DIFPRET,
         IOA.ARETVANEEX,
         IOA.PUSTANDARD,
         NOBJ.DENUMIRE,
         NS.PRET * U1.PARITATE, 
         (NS.PRET - NS.ADAOS) * U1.PARITATE, 
         NS.CODIOART, 
         NS.EUDR_RN, NS.EUDR_VN
      FROM 
        NIRSTOC NS -- NIR-uri din IESIRI
        LEFT JOIN TMP_OBJSTOCINI OI ON OI.CODOBIECT = NS.CODOBIECT
        LEFT JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART
        LEFT OUTER JOIN NIR N       ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
        LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
        LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT  
        LEFT JOIN NART A ON A.CODARTICOL = NOBJ.CODARTICOL
        LEFT OUTER JOIN IESIRI   E  ON E.CODIES    = N.CODIES,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST 
        AND E.AN * 12 + E.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC  = U1.CODUM1 AND N.TIPNIR &gt;= 14 
     );


     INSERT INTO TMP_NIRSTOCINI 
     (CODOBJSTOCINI, CODNIRSTOC, CODNIR, CODTRANSF1, CODTRANSF, DATADOC, CODOBIECT, CODIOART, UMSEC, PRETACHIZ , PRETINREG, PUVAL, TVA, TG, TIPSERIE, CANTNIR, CODLOCATIE, FURNIZOR, PUMAXIMAL, CANTUM1, CANTUM2, PROCENTADAOS, DENUM, PARITATE,
     ROTLEI,
     ROTVALUTA,
     TIPNIR,
     CODGESTPROD,
     REST,
     SERIELOT,
     CODCENTRU,
     PROVIZION,
     UM1,
     UM2,
     MG,
     DIFPRET,
     ARETVANEEX,
     PUSTANDARD,
     DENOBIECT,
     PRETINITIAL,
     ACHIZINITIAL,
     CODIOARTINITIAL, 
     EUDR_RN, EUDR_VN
     )
     (SELECT 
       OI.CODOBJSTOCINI,
       NS.CODNIRSTOC, 
       NS.CODNIR, 
       T1.CODTRANSF1, 
       T.CODTRANSF, 
       T.DATADOC, 
       NS.CODOBIECT, 
       NS.CODIOART, 
       NS.UMSEC, 
       (NS.PRET - NS.ADAOS) * U1.PARITATE, 
       NS.PRET * U1.PARITATE,  
       NS.PUVAL * U1.PARITATE, 
       NS.TVA, 
       NS.TG, 
       NS.TIPSERIE, 
       NS.CANTNIR /  U1.PARITATE, 
       NS.CODLOCATIE, 
       NS.FURN,  
       NS.PUMAXIMAL * U1.PARITATE, 
       NS.CANTUM1, 
       NS.CANTUM2, 
       NS.PROCENTADAOS, 
       U1.DEN_UM1, 
       U1.PARITATE,
       NVL(NS.ROTLEI , NOBJ.ROTUNJIRE), 
       NVL(NS.ROTVALUTA, NOBJ.ROTVALUTA), 
       N.TIPNIR,
       NS.CODGESTPROD,
       NS.REST,
       NS.SERIELOT,
       T1.CODCENTRU,
       NS.PROVIZION,
       A.UM1,
       A.UM2,
       IOA.MG,         
       IOA.DIFPRET,
       IOA.ARETVANEEX,
       IOA.PUSTANDARD,
       NOBJ.DENUMIRE,
       NS.PRET * U1.PARITATE, 
       (NS.PRET - NS.ADAOS) * U1.PARITATE, 
       NS.CODIOART, 
       NS.EUDR_RN, NS.EUDR_VN
      FROM 
        NIRSTOC NS -- NIR-uri din TRANSFERURI
        LEFT JOIN TMP_OBJSTOCINI OI ON OI.CODOBIECT = NS.CODOBIECT
        LEFT JOIN TMP_IOART_LUNA IOA ON IOA.CODIOART = NS.CODIOART
        LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
        LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1
        LEFT JOIN NARTOBJ NOBJ ON NS.CODOBIECT = NOBJ.CODOBIECT    
        LEFT JOIN NART    A    ON NOBJ.CODARTICOL = A.CODARTICOL
        LEFT OUTER JOIN TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF,
        NUM1 U1
      WHERE 
        N.GEST = aCODGEST AND T.AN * 12 + T.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
        AND NS.UMSEC = U1.CODUM1 AND N.TIPNIR IN (12, 13)
     );

  
     INSERT INTO TMP_NIRSERINI (CODNIRSER, CODNIRSTOC, CODSERIE, CANTNIR, CANTUM1, 
                                                       CANTUM2, OBS, CodCertif, DataProd, Stare, Divizor, Bucati, SERIE, NRCERTIF, TG, DataProd1, TG1, Codproducator) 
     (SELECT 
        CODNIRSER, 
        CODNIRSTOC, 
        NS.CODSERIE, 
        CANTNIR,
        CANTUM1,
        CANTUM2, 
        NS.OBS, 
        NS.CodCertif, NS.DataProd, NS.Stare, NS.Divizor, NS.Bucati,
        NVL((SELECT SERIE FROM NSERII WHERE CODSERIE = NS.CODSERIE), &apos;&apos;),
        C.NRCERTIF,
        NS.TG,
        NS.DataProd1,
        NS.TG1,
        NS.CodProducator
      FROM 
        NIRSER NS
        LEFT OUTER JOIN CERTIF C ON C.CODCERTIF = NS.CODCERTIF
      WHERE 
         CODNIRSTOC IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI));

/*

  UPDATE TMP_NIRSTOCINI NS
  SET
 -- CODOBJSTOCINI             = (SELECT CODOBJSTOCINI FROM TMP_OBJSTOCINI WHERE CODOBIECT = NS.CODOBIECT),
  (MG, DIFPRET, ARETVANEEX, PUSTANDARD) = (SELECT MG, DIFPRET, ARETVANEEX, PUSTANDARD FROM TMP_IOART_LUNA I1 WHERE I1.CODIOART = NS.CODIOART);


  UPDATE TMP_NIRSTOCINI NS
  SET
    DENOBIECT       = (SELECT DENOBIECT FROM TMP_OBJSTOCINI WHERE CODOBJSTOCINI = NS.CODOBJSTOCINI),
    PRETINITIAL     = PRETINREG,
    ACHIZINITIAL    = PRETACHIZ,
    CODIOARTINITIAL = CODIOART;

*/
/*
   UPDATE TMP_NIRSERINI NSE
   SET
      PARITATE = NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC AND ROWNUM &lt;= 1),           1), 
      CANTNIR  = CANTNIR / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1), 
      CANTUM1  = CANTUM1 / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1), 
      CANTUM2  = CANTUM2 / NVL((SELECT PARITATE FROM TMP_NIRSTOCINI WHERE CODNIRSTOC = NSE.CODNIRSTOC  AND ROWNUM &lt;= 1),1);
*/
  FOR V_REC IN (SELECT CODNIRSER, NS.PARITATE FROM TMP_NIRSERINI NSE, TMP_NIRSTOCINI NS WHERE NSE.CODNIRSTOC = NS.CODNIRSTOC)
  LOOP
   UPDATE TMP_NIRSERINI NSE
   SET
      PARITATE = NVL(V_REC.PARITATE, 1), 
      CANTNIR  = CANTNIR / NVL(V_REC.PARITATE,1), 
      CANTUM1  = CANTUM1 / NVL(V_REC.PARITATE,1), 
      CANTUM2  = CANTUM2 / NVL(V_REC.PARITATE,1)
   WHERE
     CODNIRSER = V_REC.CODNIRSER;   
    
  END LOOP;    
      
  
  INSERT INTO TMP_NIRSTOC(CODNIRSTOC)
  SELECT CODNIRSTOC FROM TMP_NIRSTOCINI;
  
  INSERT INTO TMP_NIRSTOC1
  SELECT NS1.* FROM NIRSTOC1 NS1 WHERE EXISTS (SELECT NS.CODNIRSTOC FROM TMP_NIRSTOCINI NS WHERE NS1.CODNIRSTOC = NS.CODNIRSTOC);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
 ANI           NUMBER(5);
 LUNAI         NUMBER(2);
 vCODINTR      NUMBER(20);
 vCODINTR1     NUMBER(20);
 vCODNIR       NUMBER(20);
 vCODNIRSTOC   NUMBER(20);
 vCODDVI       NUMBER(20);
 aGEST         NUMBER(20);
 aPERS         NUMBER(20);
 aCODSERIE     NUMBER(20);
 NOMSERIE      VARCHAR2(75);
 vCODNIRSER    NUMBER(20);
 NR            NUMBER(20) := 0;
 NRMIFIX       NUMBER(20) := 0;
 aVALOARE      NUMBER(20, 7) := 0;
 aTIPDOCNirStoc1 integer;
BEGIN

  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

  delete tmp_manevra;
  insert into tmp_manevra(codunic)
  select codnirstoc
  from tmp_nirstoc
  union
  select codnirstoc
  from tmp_nirstocini; 

 SELECT CODGEST, CODPERS INTO aGEST, aPERS FROM TMP_STOCINI; 
 
 IF OPERATION = 0 THEN -- UPDATE
  SELECT  CODSTOCINI INTO RecId FROM TMP_STOCINI;

   UPDATE STOCINI 
   SET 
     CODGEST = aGEST, 
     CODPERS = aPERS
   WHERE 
     CODSTOCINI = RecID;
   
  
  -- verific linii serii si stoc sterse;
  FOR V_REC IN 
  (SELECT * FROM NIRSER WHERE CODNIRSTOC IN 
    (SELECT NS.CODNIRSTOC
     FROM 
       NIRSTOC NS
       LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
       LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
     WHERE 
       N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
    ) AND CODNIRSER NOT IN (SELECT CODNIRSER FROM TMP_NIRSERINI)
  ) 
  LOOP
    DELETE NIRSERLUNA  WHERE CODNIRSER = v_rec.CODNIRSER;
    DELETE FROM NIRSER WHERE CODNIRSER = V_REC.CODNIRSER;
  END LOOP;

  FOR V_REC IN  
  (SELECT NS.CODNIRSTOC, NS.CODNIR, I1.CODINTR1, I.CODINTR
    FROM 
      NIRSTOC NS
      LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
      LEFT OUTER JOIN INTRARI1 I1 ON I1.CODINTR1 = NS.CODINTR1  
      LEFT OUTER JOIN INTRARI  I  ON I.CODINTR   = N.CODINTR
    WHERE 
      N.GEST = aGEST AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA AND NS.CODNIRSTOC NOT IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI)
  ) 
  LOOP
      DELETE NIRSER   WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE NIRLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

      DELETE NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE NIRSTOC1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
--    DELETE NIR      WHERE CODNIR     = v_rec.CODNIR; // riscant dupa ruperi de firma
      DELETE INTRARI1 I1 WHERE CODINTR1   = v_rec.CODINTR1 AND 
     (SELECT COUNT(*) FROM NIRSTOC WHERE CODINTR1 = I1.CODINTR1) = 0;
--    DELETE INTRARI  WHERE CODINTR    = v_rec.CODINTR;
  END LOOP;


  FOR V_REC IN  
  (SELECT NS.CODNIRSTOC, NS.CODNIR, T1.CODTRANSF1, T.CODTRANSF
    FROM 
      NIRSTOC NS
      LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR  
      LEFT OUTER JOIN TRANSF1 T1 ON T1.CODTRANSF1 = NS.CODTRANSF1  
      LEFT OUTER JOIN TRANSF  T  ON T.CODTRANSF   = N.CODTRANSF
    WHERE 
      N.GEST = aGEST 
      AND T.AN * 12 + T.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA 
      AND NS.CODNIRSTOC NOT IN (SELECT CODNIRSTOC FROM TMP_NIRSTOCINI)
  ) 
  LOOP
      DELETE NIRSER   WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE NIRLUNA  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;

      DELETE NIRSTOC  WHERE CODNIRSTOC = v_rec.CODNIRSTOC;
      DELETE NIRSTOC1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
--    DELETE NIR      WHERE CODNIR     = v_rec.CODNIR; // riscant dupa ruperi de firma
      DELETE TRANSF1 T1 WHERE CODTRANSF1   = v_rec.CODTRANSF1 AND 
     (SELECT COUNT(*) FROM NIRSTOC WHERE CODTRANSF1 = T1.CODTRANSF1) = 0;
--    DELETE INTRARI  WHERE CODINTR    = v_rec.CODINTR;
  END LOOP;



  FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     IF V_REC.CODNIRSTOC &lt; 0 THEN -- linie stoc noua de stoc
       SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
       SELECT SEQ_DVI_CODDVI.NEXTVAL INTO vCODDVI FROM DUAL;
       SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
       SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
       SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
       
       INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
       VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);
       
       INSERT INTO DVI(CODINTR, CODDVI, TIPIMPORT)
       VALUES (vCODINTR, vCODDVI, v_rec.tipimport);
       
       INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMAXIMAL, NRCERTIF, CODCENTRU)
       VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ  / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF, V_REC.CODCENTRU );
       
       INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
       VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);

       INSERT INTO NIRSTOC
       (CODNIRSTOC, 
        CODNIR, 
        CODINTR1, 
        CANTNIR, 
        REST, 
        UMSEC, 
        CODOBIECT, 
        CODIOART, 
        PRET, 
        PUVAL,
        ADAOS, 
        TVA, 
        TIPSERIE, 
        FURN, 
        DATAACHIZ, 
        TIPDOCACHIZ, 
        PUMAXIMAL, 
        CODLOCATIE, 
        TG, 
        CANTUM1, 
        RESTUM1,  
        CANTUM2, 
        RESTUM2, 
        PROCENTADAOS,
        D1,
        D2,
        D3,ROTLEI,ROTVALUTA, SERIELOT,
        PROVIZION,
        EUDR_RN, EUDR_VN)
       VALUES (vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR * V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, 
              V_REC.PRETINREG  / V_REC.PARITATE, 
              V_REC.PUVAL  / V_REC.PARITATE, 
             (V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE,
          V_REC.FURNIZOR,
          V_REC.DATADOC,
          1,
          V_REC.PUMAXIMAL  / V_REC.PARITATE,
          V_REC.CODLOCATIE,
          V_REC.TG,
          V_REC.CANTUM1, 
          V_REC.CANTUM1,  
          V_REC.CANTUM2, 
          V_REC.CANTUM2,
          V_REC.PROCENTADAOS,  
          V_REC.D1,  
          V_REC.D2,  
          V_REC.D3 ,
          V_REC.ROTLEI,
          V_REC.ROTVALUTA,
          V_REC.SERIELOT,
          V_REC.PROVIZION,
          V_REC.EUDR_RN, V_REC.EUDR_VN 
           );
       
       aTIPDOCNirStoc1 := 1 - 2*1*nvl(v_rec.Tipimport,0);
       
       INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
       VALUES (vCODNIRSTOC, vCODNIRSTOC, aTIPDOCNirStoc1,  
       case when aTIPDOCNirStoc1 &lt; 0 then 0 else V_REC.PRETINREG  / V_REC.PARITATE - (V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE end, 0, 1, 0);

       INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSTOC, ANI, LUNAI, v_rec.CANTNIR  * V_REC.PARITATE, NVL(V_REC.CANTUM1,0),  NVL(V_REC.CANTUM2, 0));

       FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
       
          IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :1; verific daca trebuie sa actualizez si NSERII
          BEGIN
            SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = V_REC.CODOBIECT;
            EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
          END;
          
          IF NVL(aCODSERIE, 0) = 0 THEN 
            SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
            INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
          END IF; 
        ELSE
          aCODSERIE := V_RECNIRSER.CODSERIE;  
          -- verific daca la editare nu a schimbat seria
          SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
          
          IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
            UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
          END IF;  
        END IF;

       SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO vCODNIRSER FROM DUAL;
       

       INSERT INTO NIRSER 
       (CODNIRSER,  CODNIRSTOC,  CODSERIE,  
       CANTNIR, REST, 
       CANTUM1, RESTUM1, 
       CANTUM2, RESTUM2, 
       OBS, CodCertif, DataProd, Stare, Divizor, Bucati, TG, DataProd1, TG1) 
       VALUES             
       (vCODNIRSER, vCODNIRSTOC, aCODSERIE, 
       V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
       V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, 
       V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
       V_RECNIRSER.OBS, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd,
        V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.DataProd1, V_RECNIRSER.TG1);

       INSERT INTO NIRSERLUNA(CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
       VALUES (vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, NVL(V_REC.CANTUM1,0),  NVL(V_REC.CANTUM2, 0));

      END LOOP;

     ELSE
       UPDATE INTRARI
       SET 
         DATADOC  = v_rec.DATADOC, 
         PARTENER = v_rec.FURNIZOR
       WHERE  
         CODINTR = (SELECT CODINTR FROM NIR WHERE CODNIR = v_rec.CODNIR);
         
       SELECT CODINTR into vCodIntr FROM NIR WHERE CODNIR = v_rec.CODNIR;
       Select Count(*) into NR from DVI where CodIntr = vCodIntr ;    
       if Nr = 0 then 
         SELECT SEQ_DVI_CODDVI.NEXTVAL INTO vCODDVI FROM DUAL;
         INSERT INTO DVI(CODDVI, CODINTR, TIPIMPORT)
         VALUES (vCODDVI, vCodIntr , V_REC.TIPIMPORT); 
       else
         update DVI set 
           TipImport = v_REC.Tipimport
         where CodIntr = vCodIntr ;
       end if;
       
       UPDATE INTRARI1
       SET
         UMSEC     = V_REC.UMSEC,
         PRETORIG  = v_rec.PRETACHIZ / v_rec.PARITATE, 
         PU        = v_rec.PRETACHIZ / v_rec.PARITATE, 
         CANT      = v_rec.CANTNIR * v_rec.PARITATE, 
         TG        = v_rec.TG,
         NRCERTIF  = V_REC.NRCERTIF, 
         CODCENTRU = V_REC.CODCENTRU,
         CODOBIECT = V_REC.CODOBIECT, 
         PUMAXIMAL = v_rec.PUMaximal / v_rec.PARITATE
       WHERE 
         CODINTR1 = v_rec.CODINTR1 ;  
         

       UPDATE NIR
       SET
         DATANIR = v_rec.DATADOC, 
         GEST    = aGEST
       WHERE 
         CODNIR = v_rec.CODNIR ;  


       UPDATE NIRSTOC
       SET
         CANTNIR      = V_REC.CANTNIR * V_REC.PARITATE, 
         CANTUM1      = V_REC.CANTUM1, 
         CANTUM2      = V_REC.CANTUM2, 
         CODIOART     = V_REC.CODIOART, 
         CODOBIECT    = V_REC.CODOBIECT, 
         UMSEC        = V_REC.UMSEC,
         PRET         = V_REC.PRETINREG / v_rec.PARITATE, 
         PUVAL        = V_REC.PUVAL / v_rec.PARITATE, 
         ADAOS        = (V_REC.PRETINREG - V_REC.PRETACHIZ) / v_rec.PARITATE, 
         TVA          = V_REC.TVA,
         REST         = PKG_INTRARI.GET_REST_STOC(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTNIR * v_rec.PARITATE),
         RESTUM1      = PKG_INTRARI.GET_REST_STOC_UM1(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM1),
         RESTUM2      = PKG_INTRARI.GET_REST_STOC_UM2(V_REC.CODNIR, V_REC.CODNIRSTOC, V_REC.CANTUM2),
         FURN         = V_REC.FURNIZOR,
         DATAACHIZ    = V_REC.DATADOC,
         TIPDOCACHIZ  = 1,
         PUMAXIMAL    = V_REC.PUMAXIMAL / v_rec.PARITATE,
         CODLOCATIE   = V_REC.CODLOCATIE,
         TG           = V_REC.TG,
         PROCENTADAOS = V_REC.PROCENTADAOS,
         D1           = V_REC.D1,
         D2           = V_REC.D2,
         D3           = V_REC.D3,
         SERIELOT     = V_REC.SERIELOT,
         PROVIZION    = V_REC.PROVIZION,
         EUDR_RN      = V_REC.EUDR_RN,
         EUDR_VN      = V_REC.EUDR_VN
       WHERE 
          CODNIRSTOC = v_rec.CODNIRSTOC;     
       --propag EUDR     
       FOR V_REC_COPII IN (SELECT * FROM NIRSTOC1 NS1 WHERE CODNIRSTOCORIG &lt;&gt; CODNIRSTOC AND CODNIRSTOCORIG = v_rec.CODNIRSTOC)
       loop
         UPDATE NIRSTOC
         SET
           EUDR_RN = V_REC.EUDR_RN,
           EUDR_VN = V_REC.EUDR_VN
         WHERE
           CODNIRSTOC = V_REC_COPII.CODNIRSTOC;  
       end loop;  
       --propag din nou furnizorul pe pozitiile de stoc generate prin transfer
       PropagaFurn(v_rec.codnirstoc, v_rec.furnizor);
       
       aTIPDOCNirStoc1 := 1 - 2*1*nvl(v_rec.Tipimport,0);
       
       UPDATE NIRSTOC1 SET 
         TIPDOC = aTIPDOCNirStoc1, 
         PRETMAT = case when aTIPDOCNirStoc1 &lt; 0 then 0 else V_REC.PRETINREG / v_rec.PARITATE - (V_REC.PRETINREG - V_REC.PRETACHIZ) / V_REC.PARITATE end,
         DIRTY = 0, 
         DINSTOC = 1, 
         CODCOMANDA1 = 0
       WHERE CODNIRSTOC = V_REC.CODNIRSTOC;

       BEGIN
         SELECT COUNT(*) INTO NRMIFIX FROM MIFIX1 WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
         EXCEPTION WHEN OTHERS THEN NRMIFIX :=0;
       END;

       IF NRMIFIX &gt; 0 THEN
         aVALOARE :=  v_rec.PretINREG / v_rec.Paritate;

         FOR V_MIFIX1 IN
         (SELECT *
          FROM
            MIFIX1 MF1
          WHERE
            MF1.CODNIRSTOC = V_REC.CODNIRSTOC
            AND PRET &lt;&gt; aVALOARE
         )
         LOOP
           UPDATE MIFIX1
           SET
             PRET = aVALOARE
           WHERE
             CODMIFIX1 = V_MIFIX1.CODMIFIX1;

           UPDATE JURNAL1
           SET
             DIRTY = 1
           WHERE
             CODDOC     = V_MIFIX1.CODMIFIX
             AND TIPDOC = 36
             AND AN * 12 + LUNA &gt;= V_MIFIX1.ANSTART * 12 +  V_MIFIX1.LUNASTART;
         END LOOP;
       END IF;

       FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP


         IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :2; verific daca trebuie sa actualizez si NSERII
           BEGIN
             SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = V_REC.CODOBIECT;
             EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
           END;
           
           IF NVL(aCODSERIE, 0) = 0 THEN 
             SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
             INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
           END IF; 
         ELSE
           aCODSERIE := V_RECNIRSER.CODSERIE;  
           -- verific daca la editare nu a schimbat seria
           SELECT NVL(SERIE, &apos;&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
           
           IF NVL(NOMSERIE, &apos;&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
             UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
           END IF;  
         END IF;


         IF V_RECNIRSER.CODNIRSER &lt; 0 THEN      
           SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL  INTO vCODNIRSER FROM DUAL;

           INSERT INTO NIRSER 
           (CODNIRSER, CODNIRSTOC, CODSERIE, 
           CANTNIR, REST, 
           CANTUM1, RESTUM1, 
           CANTUM2, RESTUM2, 
           Obs, CodCertif, DataProd, Stare, Divizor, Bucati, TG, DataProd1, TG1, CodProducator) 
           VALUES 
           (vCODNIRSER, V_REC.CODNIRSTOC, aCODSERIE, 
           V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,  
           V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1,  
           V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
           V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd, 
           V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.DataProd1, V_RECNIRSER.TG1, v_recnirser.codproducator);       

           INSERT INTO NIRSERLUNA (CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2) 
           VALUES (vCODNIRSER, V_REC.CODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE,  V_RECNIRSER.CANTUM1,  V_RECNIRSER.CANTUM2);       
         ELSE
           UPDATE NIRSER
           SET
             CODSERIE = aCODSERIE, 
             CANTNIR  = V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
             CANTUM1  = V_RECNIRSER.CANTUM1, 
             CANTUM2  = V_RECNIRSER.CANTUM2, 
             OBS      = V_RECNIRSER.Obs, 
             CodCertif= V_RECNIRSER.CodCertif, 
             DataProd = V_RECNIRSER.DataProd, 
             Stare    = V_RECNIRSER.Stare   , 
             Divizor  = V_RECNIRSER.Divizor, 
             Bucati   = V_RECNIRSER.Bucati,
             TG       = V_RECNIRSER.TG , 
             REST     = PKG_INTRARI.GET_REST_STOC_SERIE((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE),
             RESTUM1  = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1),
             RESTUM2  = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2), 
             DataProd1 = V_RECNIRSER.DataProd1,
             TG1       = V_RECNIRSER.TG1,
             codproducator = V_RECNIRSER.codproducator
           WHERE
             CODNIRSER = V_RECNIRSER.CODNIRSER;  


            SELECT COUNT(*) INTO NR 
            FROM 
              NIRSERLUNA 
             WHERE 
               CODNIRSER = V_RECNIRSER.CODNIRSER  
               AND AN = ANI
               AND LUNA = LUNAI;       
     
             IF NR = 0 THEN
               INSERT INTO NIRSERLUNA(CODNIRSTOC, CODNIRSER, AN, LUNA, REST, RESTUM1, RESTUM2)
               VALUES (V_REC.CODNIRSTOC, V_RECNIRSER.CODNIRSER, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);
             ELSE 
               UPDATE NIRSERLUNA
               SET
                 REST    = V_RECNIRSER.CANTNIR * V_REC.PARITATE,
                 RESTUM1 = V_RECNIRSER.CANTUM1,
                 RESTUM2 = V_RECNIRSER.CANTUM2
               WHERE 
                 CODNIRSER = v_recNIRSER.CODNIRSER
                 AND AN = ANI
                 AND LUNA = LUNAI;       
             END IF;    
/*
           UPDATE NIRSERLUNA
           SET
             REST    = RECNIRSER.CodNirSer, V_RECNIRSER.CantNir * V_RECNIRSER.PARITATE),
             RESTUM1 = PKG_INTRARI.GET_REST_STOC_SERIE_UM1((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM1),
             RESTUM2 = PKG_INTRARI.GET_REST_STOC_SERIE_UM2((SELECT CODNIR FROM NIRSTOC WHERE CODNIRSTOC = V_RECNIRSER.CODNIRSTOC), V_RECNIRSER.CodNirSer, V_RECNIRSER.CantUM2)
           WHERE
             CODNIRSER = V_RECNIRSER.CODNIRSER;  
*/
         END IF;
       END LOOP;

       SELECT COUNT(*) INTO NR 
       FROM 
         NIRLUNA 
        WHERE 
          CODNIRSTOC = v_rec.CODNIRSTOC
          AND AN = ANI
          AND LUNA = LUNAI;       

        IF NR = 0 THEN
          INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
          VALUES (V_REC.CODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, NVL(V_REC.CANTUM1,0),  NVL(V_REC.CANTUM2, 0));
        ELSE 
          UPDATE NIRLUNA
          SET
            REST    = V_REC.CANTNIR * V_REC.PARITATE,
            RESTUM1 = NVL(V_REC.CANTUM1, 0),
            RESTUM2 = NVL(V_REC.CANTUM2, 0)
          WHERE 
            CODNIRSTOC = v_rec.CODNIRSTOC
            AND AN = ANI
            AND LUNA = LUNAI;       
        END IF;    
     END IF; 
  END LOOP;
 ELSE -- INSERT
   SELECT SEQ_STOCINI_CODSTOCINI.NEXTVAL INTO RECID FROM DUAL;
   INSERT INTO STOCINI (SELECT RECID, CODGEST, CODPERS FROM TMP_STOCINI);
   
   FOR V_REC IN (SELECT * FROM TMP_NIRSTOCINI) LOOP
     SELECT SEQ_INTRARI_CODINTR.NEXTVAL INTO vCODINTR FROM DUAL;
     SELECT SEQ_DVI_CODDVI.NEXTVAL INTO vCODDVI FROM DUAL;
     SELECT SEQ_INTRARI1_CODINTR1.NEXTVAL INTO vCODINTR1 FROM DUAL;
     SELECT SEQ_NIR_CODNIR.NEXTVAL INTO vCODNIR FROM DUAL;
     SELECT SEQ_NIRSTOC_CODNIRSTOC.NEXTVAL INTO vCODNIRSTOC FROM DUAL;
       
     INSERT INTO INTRARI(CODINTR, TIPDOC, ANULAT, BLOCAT, OPERAT, PREFIXDOC, DATADOC, PARTENER, AN, LUNA, SUBUNITATEA)
     VALUES (vCODINTR, 1, 0, 0, 1, &apos;F&apos;, v_rec.DATADOC, v_rec.FURNIZOR, ANI, LUNAI, PKG_GLOBALS.SUBUNITATE_DOC);
     
     INSERT INTO DVI(CODINTR, CODDVI, TIPIMPORT)
     VALUES (vCODINTR, vCODDVI, v_rec.tipimport);
       
     INSERT INTO INTRARI1(CODINTR1, CODINTR, INDEXLOCAL, TIPLINIE, UMSEC, AN, LUNA, CODOBIECT, PRETORIG, PU, CANT, TG, PUMaximal, NRCERTIF, CODCENTRU)
     VALUES (vCODINTR1, vCODINTR, 1, &apos;=&apos;, V_REC.UMSEC, ANI, LUNAI, v_rec.CODOBIECT, v_rec.PRETACHIZ / V_REC.PARITATE, v_rec.PRETACHIZ  / V_REC.PARITATE, v_rec.CANTNIR * V_REC.PARITATE, v_rec.TG, V_REC.PUMAXIMAL / V_REC.PARITATE, V_REC.NRCERTIF, V_REC.CODCENTRU);
       
     INSERT INTO NIR(CODNIR, CODINTR, DATANIR,  GEST, TIPNIR, ANULAT, BLOCAT, OPERAT)
     VALUES (vCODNIR, vCODINTR, v_rec.DATADOC, aGEST, 1, 0, 0, 1);


     INSERT INTO NIRSTOC(CODNIRSTOC, CODNIR, CODINTR1, CANTNIR, REST, UMSEC, CODOBIECT, CODIOART, 
                                     PRET, PUVAL, ADAOS, TVA, TIPSERIE, FURN, DATAACHIZ, TIPDOCACHIZ, 
                                     PUMAXIMAL, CODLOCATIE, TG, CANTUM1, RESTUM1, CANTUM2, RESTUM2, 
                                     PROCENTADAOS, D1, D2, D3,ROTLEI,ROTVALUTA, SERIELOT, PROVIZION,
                                     EUDR_RN, EUDR_VN)
     VALUES (vCODNIRSTOC, vCODNIR, vCODINTR1, v_rec.CANTNIR  * V_REC.PARITATE, v_rec.CANTNIR  * V_REC.PARITATE, V_REC.UMSEC, V_REC.CODOBIECT, V_REC.CODIOART, V_REC.PRETINREG / V_REC.PARITATE,  V_REC.PUVAL / V_REC.PARITATE, (V_REC.PRETINREG - V_REC.PRETACHIZ)  / V_REC.PARITATE, V_REC.TVA, V_REC.TIPSERIE,
             V_REC.FURNIZOR, V_REC.DATADOC, 1, V_REC.PUMAXIMAL  / V_REC.PARITATE, V_REC.CODLOCATIE, V_REC.TG, V_REC.CANTUM1, V_REC.CANTUM1, V_REC.CANTUM2, V_REC.CANTUM2, V_REC.PROCENTADAOS,
             V_REC.D1, V_REC.D2, V_REC.D3,V_REC.ROTLEI,V_REC.ROTVALUTA, V_REC.SERIELOT, V_REC.PROVIZION,
             V_REC.EUDR_RN, V_REC.EUDR_VN);
     
     aTIPDOCNirStoc1 := 1 - 2*1*nvl(v_rec.Tipimport,0);
     INSERT INTO NIRSTOC1(CODNIRSTOC, CODNIRSTOCORIG, TIPDOC, PRETMAT, DIRTY, DINSTOC, CODCOMANDA1)
     VALUES (vCODNIRSTOC, vCODNIRSTOC, aTIPDOCNirStoc1, 
             case when aTIPDOCNirStoc1 &lt; 0 then 0 else nvl(V_REC.PRETINREG,0) / nvl(V_REC.PARITATE,0) - (nvl(V_REC.PRETINREG,0) - nvl(V_REC.PRETACHIZ,0))/ nvl(V_REC.PARITATE,0) end, 
             0, 1, 0); 

     INSERT INTO NIRLUNA(CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2)
     VALUES (vCODNIRSTOC, ANI, LUNAI, V_REC.CANTNIR * V_REC.PARITATE, V_REC.CANTUM1, V_REC.CANTUM2);
   
     FOR V_RECNIRSER IN (SELECT * FROM TMP_NIRSERINI WHERE CODNIRSTOC = V_REC.CODNIRSTOC) LOOP
       IF V_RECNIRSER.CODSERIE &lt; 0 THEN -- serie noua :3; verific daca trebuie sa actualizez si NSERII
         BEGIN
           SELECT NVL(CODSERIE, 0) INTO aCODSERIE FROM NSERII WHERE SERIE = V_RECNIRSER.SERIE AND CODOBIECT = V_REC.CODOBIECT;
           EXCEPTION WHEN OTHERS THEN aCODSERIE := 0;
         END;
         
         IF NVL(aCODSERIE, 0) = 0 THEN 
           SELECT SEQ_NSERII_CODSERIE.NEXTVAL INTO aCODSERIE FROM DUAL;
           INSERT INTO NSERII (CODSERIE, SERIE, CODOBIECT) VALUES (aCODSERIE, V_RECNIRSER.SERIE, V_REC.CODOBIECT);
         END IF; 
       ELSE
         aCODSERIE := V_RECNIRSER.CODSERIE;  
         -- verific daca la editare nu a schimbat seria
         BEGIN
           SELECT NVL(SERIE, &apos;?&apos;) INTO NOMSERIE  FROM NSERII WHERE CODSERIE = aCODSERIE;
           EXCEPTION WHEN OTHERS THEN NOMSERIE := &apos;?&apos;;
         END;  
         
         IF NVL(NOMSERIE, &apos;?&apos;) &lt;&gt; V_RECNIRSER.SERIE THEN
           UPDATE NSERII SET SERIE = V_RECNIRSER.SERIE  WHERE CODSERIE = aCODSERIE;
         END IF;  
       END IF;
   
       SELECT SEQ_NIRSER_CODNIRSER.NEXTVAL INTO VCODNIRSER FROM DUAL;
 
       INSERT INTO NIRSERLUNA (CODNIRSER, CODNIRSTOC, AN, LUNA, REST, RESTUM1, RESTUM2) 
           VALUES (vCODNIRSER, vCODNIRSTOC, ANI, LUNAI, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM2);
 
       INSERT INTO NIRSER 
       (CODNIRSER, CODNIRSTOC, CODSERIE, 
       CANTNIR, REST, 
       CANTUM1, RESTUM1, 
       CANTUM2, RESTUM2, 
       Obs, CodCertif, DataProd, Stare, Divizor, Bucati, TG, DataProd1, TG1, codproducator) 
       VALUES 
       (vCODNIRSER, vCODNIRSTOC, aCODSERIE, 
       V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, V_RECNIRSER.CANTNIR * V_RECNIRSER.PARITATE, 
       V_RECNIRSER.CANTUM1, V_RECNIRSER.CANTUM1, 
       V_RECNIRSER.CANTUM2, V_RECNIRSER.CANTUM2, 
       V_RECNIRSER.Obs, V_RECNIRSER.CodCertif, V_RECNIRSER.DataProd,
       V_RECNIRSER.Stare, V_RECNIRSER.Divizor, V_RECNIRSER.Bucati, V_RECNIRSER.TG, V_RECNIRSER.DataProd1, V_RECNIRSER.TG1, V_RECNIRSER.codproducator);
     END LOOP;
   END LOOP;
   
 END IF;

  pkg_pretprod.SetDirtyStructura;

-- RECALCULEZ FIXARILE DE PMP;
  DELETE FROM PMPLUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR)  AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
     NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST
  
   UNION ALL   

   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
     NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     TRANSF I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODTRANSF = N.CODTRANSF
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST

   UNION ALL
   SELECT 
     NS.CODOBIECT,  
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
     (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
     NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     IESIRI I,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (14, 15, 19) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODIES = N.CODIES
     AND I.AN = ANI AND I.LUNA = LUNAI
     AND G.CODGEST = N.GEST
     
   )
   GROUP BY CODOBIECT, CODSUBUNIT
   )
  LOOP
    INSERT INTO PMPLUNA (CODPMPLUNA, CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, REST, AN, LUNA,VALVALUTA)
   VALUES 
   ( SEQ_PMPLUNA_CODPMPLUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CODSUBUNIT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI,
     V_REC.VALVALUTA
   ); 
  END LOOP;



  DELETE FROM PMP_ALL_LUNA WHERE AN = ANI AND LUNA = LUNAI;
  FOR V_REC IN 
  ( 
   SELECT 
     CODOBIECT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA,
     ANI,
     LUNAI    
   FROM
   ( 
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
    NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     INTRARI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODINTR = N.CODINTR
     AND I.AN = ANI AND I.LUNA = LUNAI

   UNION ALL

   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
    NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     TRANSF I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODTRANSF = N.CODTRANSF
     AND I.AN = ANI AND I.LUNA = LUNAI

   UNION ALL
   SELECT 
     NS.CODOBIECT,  
     NS.CANTNIR AS CANTINTR,
     (NS.PRET - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
    NS.CANTNIR - PKG_INTRARI.SUMA_LIVRARI_DIN_NIR_IN_LUNA(NS.CodNirStoc, ANI, LUNAI) AS RESTLUNA,
    NS.PUVAL * NS.CANTNIR AS VALVALUTA
   FROM 
     NIRSTOC NS,
     NIR N,
     TMP_IOART_LUNA IO,
     IESIRI I
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (14, 15, 19) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND I.CODIES = N.CODIES
     AND I.AN = ANI AND I.LUNA = LUNAI

   )


   GROUP BY CODOBIECT
   )
  LOOP
    INSERT INTO PMP_ALL_LUNA (CODPMP_ALL_LUNA, CODOBIECT, CANTINTR, VALINTR, REST, AN, LUNA,VALVALUTA)
   VALUES 
   ( SEQ_PMP_ALL_LUNA.NEXTVAL, 
     V_REC.CODOBIECT, 
     V_REC.CANTINTR, 
     V_REC.VALINTR, 
     V_REC.RESTLUNA, 
     ANI, 
     LUNAI,
     V_REC.VALVALUTA
   ); 
  END LOOP;

-- actualizez modif pret nirstoc
    FOR V_REC IN ( SELECT CodNirStoc, PRETINREG FROM Tmp_NIRSTOCINI WHERE ActualizPret = 1 )
     LOOP
       PKG_Jurnal.setDirtyNirStoc(V_REC.CODNIRSTOC, V_Rec.PRETINREG, &apos;0&apos;, 0); 
     END LOOP;
  NotifyModif(Operation, RecId, &apos;STOCINI&apos;);
  COMMIT;  
END;

procedure PropagaFurn(acodnirstoc in number, afurn in number) is
begin
  for v_Rec in (select codnirstoc
                from nirstoc where codnirstocparinte = acodnirstoc) loop
    update nirstoc set furn = afurn where codnirstoc = v_rec.codnirstoc;
    PropagaFurn(v_rec.codnirstoc,afurn);            
  end loop;
end;

END PKG_STOCINITIAL; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STOCPOSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A0DD7213392908FE7E541AE02B07F76E78A6EAB</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STOCPOSURI IS

 PROCEDURE SET_CATPRET_POSURI(aCATPRET IN NUMBER)
 IS
 BEGIN
   CODCATPRETPOSURI := aCATPRET;
 END;


PROCEDURE SP_GOTO
IS
BEGIN
  DELETE TMP_STOCPOSURI;
  INSERT INTO TMP_STOCPOSURI 
  (CODSTOCPOS, 
   CODPOS, 
   TIPPOS, 
   CODGEST, 
   CODOBIECT, 
   CODIOART, 
   TVA, 
   PRET,
	 CODDEP,
	 PLU, 
	 PRETNOU,
	 STOC,
	 BARCODE,
	 CANTARIBIL,
	 DENOBIECT,
	 SERVICIU,
   DEN_UM,
   UMSEC,
   PROCTVA,
   CODTVA,
   CONTSERV,
   SIMBOLCONTSERV,
   SIMBOLGEST,
   DEN_GEST,
   MODIFICARI,
   PRETART, 
   DIFPRET
  )
  SELECT  
    SP.CODSTOCPOS, 
    SP.CODPOS, 
    SP.TIPPOS, 
    SP.CODGEST, 
    SP.CODOBIECT, 
    SP.CODIOART, 
    SP.TVA, 
    SP.PRET,
	  SP.CODDEP,
	  SP.PLU, 
	  SP.PRETNOU,
	  SP.STOC,
	  SP.BARCODE,
	  U.TipUM,
    O.DENUMIRE,
	  A.TIPARTICOL,
    U1.DEN_UM1,
    U1.CODUM1,
    TVAL.PROCENT,
    TVAL.CODTVA,
    A.CONTSERVICIU,
    NC.SIMBOL,
    G.SIMBOL,
    G.DEN_GEST,
    CASE
      WHEN SP.DENOBIECT IS NOT NULL AND SP.DENOBIECT &lt;&gt; O.DENUMIRE THEN 1
      ELSE NVL(SP.MODIFICARI, 0)
    END IF,
    SP.PRETART,
    SP.DIFPRET      
  FROM 
    STOCPOSURI SP
    LEFT JOIN NGEST G ON G.CODGEST = SP.CODGEST
    INNER JOIN TMP_MANEVRA M ON M.CODUNIC = SP.CODPOS,
    NARTOBJ O,
    NART A
    LEFT OUTER JOIN TMP_NART_LUNA AL   ON AL.CODARTICOL = A.CODARTICOL
    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA   = AL.CODTVA
    LEFT OUTER JOIN NCONT NC ON NC.CODCONT   = A.CONTSERVICIU,
    NUM1 U1,
    NUM  U
  WHERE 
     SP.CODOBIECT = O.CODOBIECT
    AND A.CODARTICOL = O.CODARTICOL
    AND A.UM         = U.CODUM 
    AND A.UM         = U1.CODUM 
    AND U1.SECUNDARA = 0; 
  COMMIT;  
END;

PROCEDURE SP_POST
IS
 NR       NUMBER(10) := 0;
 aSUBUNIT NUMBER(20) := 0;
BEGIN
  DELETE FROM STOCPOSURI SP WHERE CODPOS IN (SELECT CODUNIC FROM TMP_MANEVRA)
  AND NOT EXISTS (SELECT CODSTOCPOS FROM TMP_STOCPOSURI WHERE CODSTOCPOS = SP.CODSTOCPOS);

  FOR V_REC IN (SELECT * FROM TMP_STOCPOSURI)
  LOOP
    IF V_REC.CODSTOCPOS &lt; 0 THEN
       INSERT INTO STOCPOSURI
       (
         CODSTOCPOS,
         CODPOS, 
         TIPPOS, 
         CODGEST, 
         CODOBIECT, 
         CODIOART, 
         TVA,
         PRET, 
         CODDEP, 
         PLU, 
         PRETNOU, 
         STOC, 
         BARCODE,
         DENOBIECT,
         MODIFICARI,
         PRETART,
         DIFPRET
       )
       VALUES
       ( 
         SEQ_STOCPOSURI_CODSTOCPOSURI.NEXTVAL,
         V_REC.CODPOS, 
         V_REC.TIPPOS, 
         V_REC.CODGEST, 
         V_REC.CODOBIECT, 
         V_REC.CODIOART, 
         V_REC.TVA,
         V_REC.PRET, 
         V_REC.CODDEP, 
         V_REC.PLU, 
         V_REC.PRETNOU, 
         V_REC.STOC, 
         V_REC.BARCODE,
         V_REC.DENOBIECT,
         NVL(V_REC.MODIFICARI, 0),
         V_REC.PRETART,
         V_REC.DIFPRET
       );
    ELSE
      UPDATE STOCPOSURI
      SET
        CODPOS      = V_REC.CODPOS, 
        TIPPOS      = V_REC.TIPPOS, 
        CODGEST     = V_REC.CODGEST, 
        CODOBIECT   = V_REC.CODOBIECT, 
        CODIOART    = V_REC.CODIOART, 
        TVA         = V_REC.TVA,
        PRET        = V_REC.PRET, 
        CODDEP      = V_REC.CODDEP, 
        PLU         = V_REC.PLU, 
        PRETNOU     = V_REC.PRETNOU, 
        STOC        = V_REC.STOC, 
        BARCODE     = V_REC.BARCODE,
        DENOBIECT   = V_REC.DENOBIECT,
        MODIFICARI  = NVL(V_REC.MODIFICARI, 0),
        PRETART     = V_REC.PRETART,
        DIFPRET     = V_REC.DIFPRET
       WHERE
         CODSTOCPOS = V_REC.CODSTOCPOS;  
    END IF;
  END LOOP;


 SELECT DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE) INTO aSUBUNIT FROM DUAL;

--  aSUBUNIT := DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, 2, PKG_GLOBALS.GETSUBUNITATE);

  FOR V_REC IN (SELECT * FROM TMP_STOCPOSURI)
  LOOP
    SELECT COUNT(*) INTO NR FROM PLUCASE 
    WHERE
      CODOBIECT   = V_REC.CODOBIECT
      AND CODCASA = V_REC.CODPOS; 
      
    IF NR = 0 THEN
      INSERT INTO PLUCASE (CODPLUCASE, CODCASA, CODOBIECT, CODPLU)
      VALUES (SEQ_PLUCASE_CODPLUCASE.NEXTVAL, V_REC.CODPOS, V_REC.CODOBIECT, V_REC.PLU);
    ELSE
      UPDATE PLUCASE 
      SET 
        CODPLU = V_REC.PLU
      WHERE 
        CODOBIECT   = V_REC.CODOBIECT
        AND CODCASA = V_REC.CODPOS; 
    END IF;  
    
    IF NVL(V_REC.PRETUPDATED, 0) &lt;&gt; 0 THEN
      SELECT COUNT(*) INTO NR FROM PRETM 
      WHERE
        CODOBIECT       = V_REC.CODOBIECT
        AND SUBUNITATEA = aSUBUNIT
        AND CODCATPRET  = CODCATPRETPOSURI; 
       
      IF NR = 0 THEN
        INSERT INTO PRETM(CODPRETM, CODOBIECT, CODCATPRET, LEI, MONEDA, SUBUNITATEA)
        VALUES (SEQ_PRETM_CODPRETM.NEXTVAL, 
                V_REC.CODOBIECT, 
                CODCATPRETPOSURI, 
                V_REC.PRETUPDATED,
                0,
                aSUBUNIT);
      ELSE
        UPDATE PRETM
        SET
          LEI = V_REC.PRETUPDATED
        WHERE
          CODOBIECT       = V_REC.CODOBIECT
          AND SUBUNITATEA = aSUBUNIT
          AND CODCATPRET  = CODCATPRETPOSURI; 
      END IF; 
    END IF;
  END LOOP;

  COMMIT;
END;

end PKG_STOCPOSURI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STOCVALINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4195530A23A718E37817AB171EF82D5A1EC374B9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STOCVALINI IS

PROCEDURE SP_LOCKRECORD (RecId IN NUMBER) IS
TMP NUMBER(20);
BEGIN
  SELECT CODSTOCVALINI INTO TMP FROM STOCVALINI WHERE CODSTOCVALINI = RECID FOR UPDATE NOWAIT;
END;


PROCEDURE SP_INSERTRECORD
IS
BEGIN
  INSERT INTO TMP_STOCVALINI FIELDS( CODSTOCVALINI ) VALUES (0) ;
  COMMIT;
END;



PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
IS
 aCODGEST NUMBER(20);
 ANI      NUMBER(5);
 LUNAI    NUMBER(2);

BEGIN
  SP_LOCKRECORD(RecId);
	SELECT GEST INTO aCODGEST FROM STOCVALINI WHERE CODSTOCVALINI = RecID;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);

  DELETE FROM STOCVALLUNA WHERE GEST = aCODGEST AND AN = ANI AND LUNA = LUNAI;
  DELETE FROM STOCVALINI  WHERE CODSTOCVALINI = RECID;
  NotifyModif(2, RecId, &apos;STOCVALINI&apos;);
  COMMIT;
END;



PROCEDURE SP_GOTORECORD (RecId IN NUMBER)
IS
  ANI      NUMBER(5);
  LUNAI    NUMBER(2);
  aCODGEST NUMBER(20) := 0;
BEGIN
  INSERT INTO TMP_STOCVALINI(CODSTOCVALINI, GEST)
  SELECT CODSTOCVALINI, GEST FROM STOCVALINI WHERE CODSTOCVALINI = RECID;
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);

  IF RECID &gt; 0 THEN
    SELECT NVL(GEST, 0) INTO aCODGEST FROM TMP_STOCVALINI;
  END IF;


  INSERT INTO TMP_STOCVALLUNA(CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
  SELECT * FROM STOCVALLUNA WHERE GEST = aCODGEST AND AN = ANI AND LUNA = LUNAI;

  UPDATE TMP_STOCVALLUNA SV
  SET
    VALACHIZ = SOLD - ADAOS,
    (DIFPRET, ARETVANEEX, PUSTANDARD, MG) =
    ( SELECT IO1.DIFPRET, IO1.ARETVANEEX, IO1.PUSTANDARD, IO1.MG FROM IOART1 IO1
      WHERE IO1.CODIOART = SV.CODIOART AND PKG_GLOBALS.ANLUNALUCRU BETWEEN IO1.ALSTART AND IO1.ALSTOP
    );

  UPDATE TMP_STOCVALINI SET SOLDTOTAL = (SELECT SUM(SOLD) FROM TMP_STOCVALLUNA);

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
  aCODGEST NUMBER(20);
  ANI      NUMBER(5);
  LUNAI    NUMBER(2);
BEGIN
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI);
  SELECT GEST INTO aCODGEST FROM TMP_STOCVALINI;

  IF OPERATION = 0 THEN -- UPDATE
    SELECT  CODSTOCVALINI INTO RecId FROM TMP_STOCVALINI;
    UPDATE STOCVALINI SET GEST = aCODGEST WHERE CODSTOCVALINI = RecID;

   -- sterg pozitiile care au disparut
    DELETE FROM STOCVALLUNA
    WHERE
    AN = ANI AND LUNA = LUNAI AND GEST= aCODGEST AND CODSTOCVALLUNA NOT IN (SELECT CODSTOCVALLUNA FROM TMP_STOCVALLUNA);


    FOR V_REC IN (SELECT * FROM TMP_STOCVALLUNA) LOOP
      IF V_REC.CODSTOCVALLUNA &lt; 0 THEN
        INSERT INTO STOCVALLUNA (CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
        VALUES (SEQ_STOCVALLUNA_CODSTOCVALLUNA.NEXTVAL, V_REC.GEST, V_REC.CODIOART, V_REC.TVA, V_REC.SOLD, V_REC.ADAOS, V_REC.SOLDINTR, V_REC.ADAOSINTR,  V_REC.AN, V_REC.LUNA) ;
      ELSE
        UPDATE STOCVALLUNA
        SET
          GEST      = V_REC.GEST,
          CODIOART  = V_REC.CODIOART,
          TVA       = V_REC.TVA,
          SOLD      = V_REC.SOLD,
          ADAOS     = V_REC.ADAOS,
          SOLDINTR  = V_REC.SOLDINTR,
          ADAOSINTR = V_REC.ADAOSINTR,
          AN        = V_REC.AN,
          LUNA      = V_REC.LUNA
        WHERE
          CODSTOCVALLUNA = V_REC.CODSTOCVALLUNA;
      END IF;
    END LOOP;
  ELSE  -- INSERT
    SELECT SEQ_STOCVALINI_CODSTOCVALINI.NEXTVAL INTO RECID FROM DUAL;

    INSERT INTO STOCVALINI
    SELECT RecID, aCODGEST FROM DUAL;
    INSERT INTO STOCVALLUNA(CODSTOCVALLUNA, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA)
    SELECT SEQ_STOCVALLUNA_CODSTOCVALLUNA.NEXTVAL, GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR, AN, LUNA FROM TMP_STOCVALLUNA;
  END IF;
  NotifyModif(Operation, RecId, &apos;STOCVALINI&apos;);
  COMMIT;
END;


end PKG_STOCVALINI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STOC_GENERARE_FACTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40B34372F867E0FCA2D200AA820B3D5132B203CC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STOC_GENERARE_FACTURI IS

g_viewName VARCHAR2(50);

PROCEDURE TESTARE IS
BEGIN
  PKG_GLOBALS.SETUSERID(1);          COMMIT;
  PKG_GLOBALS.SETSUBUNITATE(2);      COMMIT;
  PKG_GLOBALS.SETFIRMA_ID(1);        COMMIT;
  PKG_GLOBALS.SetLunaLucru(2019, 9); COMMIT;
  PKG_STOC_GENERARE_FACTURI.make_config_luna;
END;

PROCEDURE SET_FILTRU_MEDEX(aFILTER IN VARCHAR2) IS
BEGIN
  FILTRUMEDEX := aFILTER;
END;

PROCEDURE FILLCODIOARTCORESP IS
NR NUMBER(10):= 0;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  FOR V_REC IN (SELECT DISTINCT PROCENT FROM TMP_NTVA_LUNA)
  LOOP
    SELECT COUNT(*) INTO NR FROM CODIOARTCORESP
    WHERE
      PROCTVA = V_REC.PROCENT;
    IF NR = 0 THEN
      INSERT INTO CODIOARTCORESP(COD, PROCTVA)
      VALUES (SEQ_CODIOARTCORESP_COD.NEXTVAL, V_REC.PROCENT);
    END IF;
  END LOOP;
  COMMIT;
END;


PROCEDURE SET_CODLINIECOMANDA(aCODLINIECOMANDA IN NUMBER) IS
BEGIN
  CODLINIECOMANDA := aCODLINIECOMANDA;
END;


PROCEDURE SET_MOD_LIVRARE_AUTOMATA(aMODLIVRARE IN NUMBER) IS
BEGIN
  MODLIVRAUTOMATA := aMODLIVRARE;
END;

PROCEDURE SET_INTERFACE_FILTER(aFILTER IN VARCHAR2) IS
BEGIN
  INTERFACEFILTER := aFILTER;
END;

PROCEDURE POSTDISCLIKISTOC IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NIRSTOC)
  LOOP
    UPDATE NIRSTOC
    SET DISCLIKISTOC = V_REC.DISCLIKISTOC
    WHERE CODNIRSTOC = V_REC.CODNIRSTOC;
  END LOOP;
  COMMIT;
END;

PROCEDURE POSTSTARE IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_NIRSER)
  LOOP
    UPDATE NIRSER
    SET
      STARE = V_REC.STARE,
      OBS   = V_REC.OBS
    WHERE CODNIRSER = V_REC.CODNIRSER;
  END LOOP;
  COMMIT;
END;

PROCEDURE DropViewStoc  IS
  cnt  NUMBER(1);
BEGIN
  SELECT COUNT(*) INTO cnt FROM user_views WHERE upper(view_name) = upper(g_viewName);
  IF cnt &gt; 0 THEN
    EXECUTE IMMEDIATE &apos;DROP VIEW &apos;||g_viewName;
  END IF;
END;

PROCEDURE make_config_luna IS
PRAGMA AUTONOMOUS_TRANSACTION;
  AnLunaLucru     NUMBER(20);
  aUSER_ID        NUMBER(20)   := -1;
  aNART_FLG       NUMBER(1)    := 0;
  aNARTObj_FLG    NUMBER(1)    := 0;
  aIOART_FLG      NUMBER(1)    := 0;
  aNTVA_FLG       NUMBER(1)    := 0;
  aNTAXE_FLG      NUMBER(1)    := 0;
  aTARIFE_FLG     NUMBER(1)    := 0;
  aPRETM_FLG      NUMBER(1)    := 0;
  aIOPART_FLG     NUMBER(1)    := 0;
  aIOFILIAL_FLG   NUMBER(1)    := 0;
  aIOBANK_FLG     NUMBER(1)    := 0;
  aIOPERS_FLG     NUMBER(1)    := 0;

  isWMRETAIL      NUMBER(1)    := 0;
  vPrPtRetail     NUMBER       := 0;

  NEEDREFRESHART  NUMBER(1)    := 1;
  aValConst       NUMBER(5)    := 0;
  sCodCatPretEmul VARCHAR2(10) := NULL;
  CODCATPRETEMUL  NUMBER(20)   := 0;
  aSUBUNIT        NUMBER(20);
  CATPRET_11      NUMBER(10);
  sInsert         CLOB;
  sValuta         CLOB;
  SJoin_PACHVAL   CLOB;
BEGIN
  pkg_globals.DATA0 := to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;);
  NEEDREFRESHART    := 1;

  BEGIN
    aValConst := Coalesce(PKG_CATEGCONST.GetValConstanta(&apos;ManualRefreshNart&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;0&apos;);
  EXCEPTION
    WHEN OTHERS THEN aValConst := 0;
  END;

  IF aValConst = 1 THEN NEEDREFRESHART := 0; END IF;

  BEGIN
    SELECT
      Coalesce(USERID,-1), Coalesce(NART_FLG,0), Coalesce(NARTOBJ_FLG,0), Coalesce(IOART_FLG,0), Coalesce(NTVA_FLG,0), Coalesce(NTAXE_FLG,0), Coalesce(TARIFE_FLG,0), Coalesce(PRETM_FLG,0),
      Coalesce(IOPART_FLG,0), Coalesce(IOFILIAL_FLG,0), Coalesce(IOBANK_FLG,0), Coalesce(IOPERS_FLG,0)
    INTO
      aUSER_ID, aNART_FLG, aNARTObj_FLG, aIOART_FLG, aNTVA_FLG, aNTAXE_FLG, aTARIFE_FLG, aPRETM_FLG,
      aIOPART_FLG, aIOFILIAL_FLG, aIOBANK_FLG, aIOPERS_FLG
    FROM LUNA_RECORDS_FLAGS
    WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  IF aUSER_ID = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(
      USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG,
      NART_FLG_CONTA, NARTOBJ_FLG_CONTA, IOART_FLG_CONTA, NTVA_FLG_CONTA, NTAXE_FLG_CONTA, IOPART_FLG_CONTA, IOPERS_FLG_CONTA, IOFILIAL_FLG_CONTA,
      IOBANK_FLG_CONTA, NGEST1_FLG_CONTA, NPART1_FLG_CONTA, NPERS1_FLG_CONTA, NBANK1_FLG_CONTA)
    Select USERID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    FROM TMP_PKG_GLOBALS;

    INSERT INTO TMP_LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG)
    Select USERID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    FROM TMP_PKG_GLOBALS;
    NEEDREFRESHART := 1;
  END IF;

  SELECT anlucru  * 12 + lunalucru INTO AnLunaLucru FROM tmp_pkg_globals;

  IF aIOART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOART1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IOART_LUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_IOART_LUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_IOART_LUNA (
      CODIOART1, CODIOART, CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT, CONTROTUNJIRI, DIVERSE, CUSTODIE, ACCIZELATRANSFER,
      DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG, ANSTART, LUNASTART, PUSTANDARD, PROVIZION, CHELTPROVIZION, VENITPROVIZION, DEN_IOART,
      ESTEMIFIX,
      ESTEOBINV,
      ESTECUSTODIE)
    SELECT  /*+ INDEX(IO1, IDX_IOART1_CODIOART) */
      IO1.CODIOART1, IO1.CODIOART, IO1.CONT, IO1.DIFERENTE, IO1.CHELTUIELI, IO1.VENITURI, IO1.PLUSINVENTAR, IO1.MINUSINVENTAR, IO1.CHELTTVACOLECTAT, IO1.CONTROTUNJIRI, IO1.DIVERSE, IO1.CUSTODIE, IO1.ACCIZELATRANSFER,
      IO1.DESCARCAREG, IO1.CONTABGEST, IO1.BAZA, IO1.DIFPRET, IO1.ARETVANEEX, IO1.TVANEEX, IO1.MG, IO1.ANSTART, IO1.LUNASTART, IO1.PUSTANDARD, IO1.PROVIZION, IO1.CHELTPROVIZION, IO1.VENITPROVIZION, IO.DEN_IOART,
      CASE WHEN NVL(CMF.CODCONT, 0)    &lt;&gt; 0 THEN 1 ELSE 0 END ESTEMIFIX,
      CASE WHEN NVL(COBINV.CODCONT, 0) &lt;&gt; 0 THEN 1 ELSE 0 END ESTEOBINV,
      CASE WHEN NVL(CCUST.CODCONT, 0)  &lt;&gt; 0 THEN 1 ELSE 0 END ESTECUSTODIE
    FROM IOART IO
      INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART
      LEFT JOIN TMP_CONTMIFIX CMF ON IO1.CONT = CMF.CODCONT
      LEFT JOIN TMP_CONTOBINV COBINV ON IO1.CONT = COBINV.CODCONT
      LEFT JOIN TMP_CONTCUSTODIE CCUST ON IO1.CONT = CCUST.CODCONT
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN IO1.ALSTART AND IO1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;


    UPDATE LUNA_RECORDS_FLAGS SET IOART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOART_FLG = 0;
  END IF;

  IF aIOPART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOPART1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IOPART_CFGLUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_IOPART_CFGLUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_IOPART_CFGLUNA (
      CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC,
      CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC,
      ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, ContSuplimF6, ContSuplimF7, ContSuplimF8, ContSuplimF9,
      ContSuplimF10, ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20, ContSuplimF21, ContSuplimF22,
      ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
      TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP )
    SELECT
      CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC,
       CONTFURNAVIN, CONTTERTI, CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC,
      ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5, ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, ContSuplimF6, ContSuplimF7, ContSuplimF8, ContSuplimF9,
      ContSuplimF10, ContSuplimF11, ContSuplimF12, ContSuplimF13, ContSuplimF14, ContSuplimF15, ContSuplimF16, ContSuplimF17, ContSuplimF18, ContSuplimF19, ContSuplimF20, ContSuplimF21, ContSuplimF22,
      ContSuplimF23, ContSuplimF24, ContSuplimF25, ContSuplimF26, ContSuplimF27, ContSuplimF28, ContSuplimF29, ContSuplimF30,
      TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP
    FROM IOPART1 n1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET IOPART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPART_FLG = 0;
  END IF;

  IF aIOFILIAL_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOFILIAL1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IOFILIAL_LUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_IOFILIAL_LUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_IOFILIAL_LUNA(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP)
    SELECT CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP
    FROM IOFILIAL1 n1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 0;
  END IF;

  IF aIOBANK_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOBANK1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IOBANK_LUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_IOBANK_LUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_IOBANK_LUNA ( CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM )
    SELECT CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM
    FROM IOBANK1 n1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET IOBANK_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOBANK_FLG = 0;
  END IF;


  IF aIOPERS_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOPERS
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_IOPERS_CFGLUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_IOPERS_CFGLUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_IOPERS_CFGLUNA (CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT)
    SELECT CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT
    FROM IOPERS1 n1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET IOPERS_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPERS_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1)AND(aNART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0) THEN
    --NART1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_nart_luna&apos;;
    TRUNCATE_TABLE(&apos;tmp_nart_luna&apos;);
    sInsert := &apos;
    INSERT INTO tmp_nart_luna(codarticol1,codarticol,codtva,codaccize,codaccizedvi,codtaxa1,codtaxa2,anstart,lunastart)
    SELECT codarticol1,codarticol,codtva,codaccize,codaccizedvi,codtaxa1,codtaxa2,anstart,lunastart
    FROM nart1 n1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET NART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  END IF;

  IF aNTVA_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --NTVA1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_ntva_luna&apos;;
    TRUNCATE_TABLE(&apos;tmp_ntva_luna&apos;);
    sInsert := &apos;
    INSERT INTO tmp_ntva_luna(codtva1,codtva,procent,codcontded,codcontcole,codcontneex,anstart,lunastart,den_tva)
    SELECT n1.codtva1,n1.codtva,n1.procent,n1.codcontded,n1.codcontcole,n1.codcontneex,n1.anstart,n1.lunastart,n.den_tva
    FROM ntva1 n1 INNER JOIN ntva n ON n1.codtva = n.codtva
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET NTVA_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTVA_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1)AND(aPRETM_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0)  THEN

    BEGIN
      ISWMRETAIL := Coalesce(WINMADMIN.PKG_USERFIRME.GET_FIRMA_ISWMRETAIL(PKG_GLOBALS.CODFIRMA), 0);
    EXCEPTION
      WHEN OTHERS THEN ISWMRETAIL := 0;
    END;

--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_MANPRETM&apos;;
    TRUNCATE_TABLE(&apos;TMP_MANPRETM&apos;);

    IF ISWMRETAIL = 1 THEN
      sCodCatPretEmul := Coalesce(pkg_categconst.GetValConstanta(&apos;CodCatPretEmulUsr&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;0&apos;);
      IF sCodCatPretEmul = &apos;0&apos; THEN
        sCodCatPretEmul := Coalesce(pkg_categconst.GetValConstanta(&apos;CodCatPretEmul&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU), &apos;0&apos;);
      END IF;

      BEGIN
        CODCATPRETEMUL := TO_NUMBER(sCodCatPretEmul);
      EXCEPTION
        WHEN OTHERS THEN CODCATPRETEMUL := 0;
      END;

      sInsert := &apos;
      INSERT INTO TMP_MANPRETM
      SELECT
        PM.CODOBIECT,
        CASE
          WHEN CAT.TIP = 1 THEN LEI
          WHEN CAT.TIP = 2 THEN ROUND(LEI * (1 + Coalesce(T.PROCENT, 0) / 100), 2)
          ELSE NULL
        END LEI,
        VALUTA,
        SUBUNITATEA
      FROM PRETM PM, NARTOBJ O, TMP_NART_LUNA A, TMP_NTVA_LUNA T, NCATPRET CAT
      WHERE CAT.CODCATPRET = PM.CODCATPRET
        AND O.CODOBIECT = PM.CODOBIECT
        AND A.CODARTICOL = O.CODARTICOL
        AND A.CODTVA = T.CODTVA
        AND Coalesce(PM.subunitatea, 0) = &apos;||To_Char(Coalesce(pkg_globals.GETSUBUNITATE,0))||&apos;
        AND CAT.CODCATPRET = &apos;||To_Char(CODCATPRETEMUL);
        EXECUTE IMMEDIATE sInsert;
    ELSE
      IF  pkg_globals.GETSUBUNITATE = 1
      THEN aSUBUNIT := Coalesce(pkg_globals.GETSUBUNITATE_DOC, 0);
      ELSE aSUBUNIT := Coalesce(pkg_globals.GETSUBUNITATE, 0);
      END IF;

      BEGIN
        SELECT COUNT(*) INTO CATPRET_11 FROM PRETM PM INNER JOIN NCATPRET CP ON CP.CODCATPRET = PM.CODCATPRET AND CP.TIP = 11;
        EXCEPTION WHEN OTHERS THEN CATPRET_11 := 0;
      END;

      IF CATPRET_11 &gt; 0 THEN
        SValuta := &apos;
        CASE
          WHEN CAT.TIP = 11 THEN Coalesce(PUACHVAL.PUVAL, 0) * (1 + Coalesce(Lei, 0) / 100)
          ELSE VALUTA
        END VALUTA,&apos;;
        SJoin_PACHVAL := &apos;
        LEFT JOIN (
          SELECT DISTINCT
            CODOBIECT,
            MONEDA,
            FIRST_VALUE(PUVAL)   OVER (PARTITION BY CODOBIECT, MONEDA ORDER BY DATANIR DESC) PUVAL,
            FIRST_VALUE(DATANIR) OVER (PARTITION BY CODOBIECT, MONEDA ORDER BY DATANIR DESC) DATANIR
          FROM (
            SELECT NS.CODOBIECT, I.MONEDA, NS.PRET - Coalesce(NS.ADAOS,0) / COALESCE(NULLIF(I.CURS, 0), 1)  PUVAL, N.DATANIR
            FROM NIRSTOC NS
              INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
              INNER JOIN INTRARI I ON I.CODINTR = N.CODINTR
            WHERE TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 15) AND I.MONEDA &lt;&gt; 0 AND N.OPERAT = 1 AND N.ANULAT = 0
          ) ss
        ) PUACHVAL ON PUACHVAL.CODOBIECT = PM.CODOBIECT AND PUACHVAL.MONEDA = PM.MONEDA&apos;;
      ELSE
        SValuta := &apos; VALUTA, &apos;;
        SJoin_PACHVAL := &apos;&apos;;
      END IF;

      DELETE TMP_LASTPRETACHIZ;
      INSERT INTO TMP_LASTPRETACHIZ
      SELECT NS.CODOBIECT, Max(NS.PRET - NVL(NS.ADAOS, 0)) KEEP (Dense_Rank LAST ORDER BY N.DATANIR) PRETACHIZ
      FROM NIRSTOC NS
        INNER JOIN NIR N       ON N.CODNIR = NS.CODNIR
        INNER JOIN PRETM PM    ON PM.CODOBIECT = NS.CODOBIECT
        INNER JOIN NCATPRET CP ON CP.CODCATPRET = PM.CODCATPRET
      WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 7, 8, 9, 15) AND N.OPERAT = 1 AND N.ANULAT = 0
        AND PM.SUBUNITATEA = aSUBUNIT AND PM.IMPLICIT = 1
        AND CP.TIP = 10
      GROUP BY NS.CODOBIECT;

      vPrPtRetail := Coalesce(PKG_GLOBALS.PretPentruRetail, 0);
      sInsert := &apos;
      INSERT INTO TMP_MANPRETM
      SELECT
        PM.CODOBIECT,
        CASE
          WHEN CAT.TIP =  1 THEN LEI
          WHEN CAT.TIP =  2 AND &apos;||To_Char(vPrPtRetail)||&apos; = 1 THEN ROUND(LEI * (1 + Coalesce(T.PROCENT, 0) / 100), 2)
          WHEN CAT.TIP =  2 AND &apos;||To_Char(vPrPtRetail)||&apos; = 0 THEN Lei
          WHEN CAT.TIP = 10 THEN  Coalesce(PACH.PRETACHIZ, 0) * (1 + Coalesce(Lei, 0) / 100)
        END LEI,&apos;||
        sVAluta||&apos;
        SUBUNITATEA
      FROM PRETM PM
        INNER JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET
        LEFT JOIN TMP_LASTPRETACHIZ PACH ON PACH.CODOBIECT = PM.CODOBIECT &apos;||
        SJoin_PACHVAL ||&apos;
        INNER JOIN NARTOBJ O ON O.CODOBIECT = PM.CODOBIECT
        INNER JOIN NART1 A ON A.CODARTICOL = O.CODARTICOL AND &apos;||To_Char(ANLUNALUCRU)||&apos; BETWEEN A.ALSTART AND A.ALSTOP
        INNER JOIN NTVA1 T ON A.CODTVA     = T.CODTVA     AND &apos;||To_Char(ANLUNALUCRU)||&apos; BETWEEN T.ALSTART AND T.ALSTOP
      WHERE Coalesce(PM.subunitatea, 0) = &apos;||To_Char(aSUBUNIT)||&apos; AND Coalesce(PM.IMPLICIT, 0) = 1 AND CAT.TIP IN (1, 2, 10, 11)&apos;;
      EXECUTE IMMEDIATE sInsert;
    END IF;

    UPDATE LUNA_RECORDS_FLAGS SET PRETM_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET PRETM_FLG = 0;
  END IF;

  IF aNTAXE_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --NTAXE1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE tmp_ntaxe_luna&apos;;
    TRUNCATE_TABLE(&apos;tmp_ntaxe_luna&apos;);
    sInsert := &apos;
    INSERT INTO tmp_ntaxe_luna(
      CODTAXA1,CODTAXA,VALOARE,LACEAPLIC,CODCONT,CODCONTCHELT,ORICARETIP,CODIOARTEXCL,
      EXCLUSACCIZE,EXCLUSEXPORT,JACHIZ,JVANZ,CUMJACHIZ,CUMJVANZ,BazaMax,BazaMin,CODSERVFACT,
      FACTURABIL,STOPAJ,ANSTART,LUNASTART,SERVICIUMONETAR, ProcDiminuareB, DEN_TAXA, Rotvaloare)
    SELECT
      n1.CODTAXA1,n1.CODTAXA,n1.VALOARE,n1.LACEAPLIC,n1.CODCONT,n1.CODCONTCHELT,n1.ORICARETIP,n1.CODIOARTEXCL,
      n1.EXCLUSACCIZE,n1.EXCLUSEXPORT,n1.JACHIZ,n1.JVANZ,n1.CUMJACHIZ,n1.CUMJVANZ,n1.BazaMax,n1.BazaMin,n1.CODSERVFACT,
      n1.FACTURABIL,n1.STOPAJ,n1.ANSTART,n1.LUNASTART,n1.SERVICIUMONETAR,n1.ProcDiminuareB, n.den_taxa, N1.ROTVALOARE
    FROM ntaxe1 n1 INNER JOIN ntaxe n ON n1.codtaxa = n.codtaxa
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN N1.ALSTART AND N1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET NTAXE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTAXE_FLG = 0;
  END IF;

  IF (NEEDREFRESHART = 1)AND(aNARTOBJ_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0) THEN
    --nartobj1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_NARTOBJ_LUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_NARTOBJ_LUNA&apos;);

    sInsert := &apos;
    INSERT INTO TMP_NARTOBJ_LUNA (
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART, PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT, CODMONEDA,
      PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate )
    SELECT
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART, PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT, CODMONEDA,
      PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate
    FROM nartobj1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN ALSTART AND ALSTOP&apos;;

    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  END IF;

  IF aTARIFE_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --nartobj1
--    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_TARIFEMAN_LUNA&apos;;
    TRUNCATE_TABLE(&apos;TMP_TARIFEMAN_LUNA&apos;);
    sInsert := &apos;
    INSERT INTO TMP_TARIFEMAN_LUNA ( CODTARIF1, CODTARIF, TARIF, ANSTART, LUNASTART )
    SELECT T1.CODTARIF1, T1.CODTARIF, T1.TARIF, T1.ANSTART, T1.LUNASTART
    FROM TARIFEMAN1 T1
    WHERE &apos;||ANLUNALUCRU||&apos; BETWEEN T1.ALSTART AND T1.ALSTOP&apos;;
    EXECUTE IMMEDIATE sInsert;

    UPDATE LUNA_RECORDS_FLAGS SET TARIFE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET TARIFE_FLG = 0;
  END IF;

  pkg_globals.LUNARECORDSFLAG := 1;

  COMMIT;
END;

PROCEDURE SET_INCLUSIV_STOC_ZERO (aFLAG NUMBER) IS
BEGIN
  INCLUSIV_STOC_ZERO := aFLAG;
END;


PROCEDURE MAKE_STOC_GENERARE_FACTURI IS
  sInsert VARCHAR2(30000);
  sFilter VARCHAR2(2000);
  nr  NUMBER(20);
  subDedicata NUMBER (20);
  pUserName VARCHAR2(50);
  pUser VARCHAR2(50);
  CONDITIE_STOC varchar2(100);
BEGIN
  make_config_luna;
  IF Coalesce(INCLUSIV_STOC_ZERO, 0) = 1
  THEN CONDITIE_STOC := &apos;1 = 1&apos;;
  ELSE CONDITIE_STOC := &apos;NS.REST &lt;&gt; 0&apos;;
  END IF;

  sInsert := &apos;SELECT * FROM(
  SELECT
    O.DENUMIRE AS DENOBIECT,
    O.CODEXTERN,
    O.CODINTERN,
    U1.DEN_UM1 AS DENUMSTOCARE,
    U.DEN_UM   AS DENUM,
    U.CODUM,
    NS.CODNIRSTOC,
    NS.UMSEC,
    NS.CODOBIECT,
    NS.CODIOART,
    NIRCURENT.GEST,
    NS.PRET - Coalesce( NS.ADAOS, 0) AS PRETACHIZ,
    NS.PRET  AS PRET,
    Coalesce(NS.ADAOS, 0) AS ADAOS,
    NS.TVA,
    NS.TIPSERIE,
    CASE
      WHEN NS.TIPSERIE &gt; 0
      THEN NSE.REST - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER  = NSE.CODNIRSER), 0) - Coalesce((SELECT SUM(REST) FROM REZERVATS RS WHERE CODNIRSER  = NSE.CODNIRSER AND RS.CODCOMANDA1 &lt;&gt; &apos; || PKG_STOC_GENERARE_FACTURI.CODLINIECOMANDA || &apos;), 0)
      ELSE NS.REST  - Coalesce((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NS.CODNIRSTOC), 0) - Coalesce((SELECT SUM(REST) FROM REZERVATS RS WHERE CODNIRSTOC = NS.CODNIRSTOC AND RS.CODCOMANDA1 &lt;&gt; &apos; || PKG_STOC_GENERARE_FACTURI.CODLINIECOMANDA || &apos;), 0)
    END AS STOC,
    NS.PROCENTADAOS,
    NIRCURENT.DATANIR AS INTRATLA,
    Coalesce(NSE.TG, NS.TG) TG,
    NS.PUMAXIMAL,
    NS.FURN AS CODPART,
    CASE WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE) ELSE &apos;&apos;&apos;&apos; END AS SERIE,
    Coalesce(NSE.CODNIRSER, 0) CODNIRSER,
    NSE.CODSERIE,
    NS.DATAACHIZ,
    NS.TIPDOCACHIZ,
    NIRCURENT.TIPNIR AS TIPINTRARESTOC,
    L.DENUMIRE AS LOCATIE,
    NART1LUNA.CODTVA,
    Coalesce(TVALUNA.PROCENT, -1) AS PROCTVA,
    NART1LUNA.CODACCIZE,
    NART1LUNA.CODTAXA1,
    NART1LUNA.CODTAXA2,
    A.TIPARTICOL,
    O.TERMENPLATA,
    O.ADAOSEXCEPTIE,
    P.DEN_PART AS DENFURN,
    &apos;&apos; &apos;&apos; AS SUPLIMENT,
    CAR.DEN_CARSUPART,
    NARTOBJ1LUNA.TIPCOMPENSARE,
    G.DEN_GEST,
    IOART.DEN_IOART,
    PROD.DEN_PART AS PRODUCATOR,
    O.ROTUNJIRE AS ROTLEI,
    NARTOBJ1LUNA.GRUPA,
    O.BLOCAT,
    O.PROMOTIE,
    CL.DEN_CLASEA,
    A.CLASA,
    NS.DISCLIKISTOC,
    A.UM1,
    A.RELATIEUM1,
    NS.RESTUM1,
    NS.D1,
    NS.D2,
    NS.D3,
    NSE.CODCERTIF,
    C.NRCERTIF,
    NSE.STARE,
    NSE.DATAPROD,
    NSE.OBS,
    IOALUNA.DIFPRET,
    NS.CODGESTPROD,
    GPROD.DEN_GEST AS DENGESTPROD,
    O.NEFACTURABIL,
    NS.PROVIZION,
    A.DCI,
    NS.CODLOCATIE,
    G.CODSUBUNIT,
    S.DEN_SUBUNIT
  FROM NIRSTOC NS
    LEFT  JOIN NGEST            GPROD        ON GPROD.CODGEST          = NS.CODGESTPROD
    LEFT  JOIN NPART            P            ON P.CODPART              = NS.FURN
    LEFT  JOIN NIRSER           NSE          ON NSE.CODNIRSTOC         = NS.CODNIRSTOC
    LEFT  JOIN NLOCATII         L            ON L.CODLOCATIE           = Coalesce(NS.CODLOCATIE, 0)
    LEFT  JOIN CERTIF           C            ON C.CODCERTIF            = NSE.CODCERTIF
    INNER JOIN NIR              NIRCURENT    ON NIRCURENT.CODNIR       = NS.CODNIR
    INNER JOIN NGEST            G            ON G.CODGEST              = NIRCURENT.GEST
    INNER JOIN NSUBUNIT         S            ON G.CODSUBUNIT           = S.CODSUBUNIT
    INNER JOIN NARTOBJ          O            ON O.CODOBIECT            = NS.CODOBIECT
    INNER JOIN NART             A            ON A.CODARTICOL           = O.CODARTICOL
    LEFT  JOIN NPART            PROD         ON PROD.CODPART           = O.CODPRODUCATOR
    LEFT  JOIN tmp_nartobj_luna NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = o.codobiect
    LEFT  JOIN NCARSUPART       CAR          ON CODCARSUPART           = O.CODCARACT
    LEFT  JOIN tmp_nart_luna    NART1LUNA    ON NART1LUNA.CODARTICOL   = A.CODARTICOL
    LEFT  JOIN tmp_ntva_luna    TVALUNA      ON TVALUNA.CODTVA         = NART1LUNA.CODTVA
    LEFT  JOIN NCLASEA          CL           ON CL.CODCLASEA           = A.CLASA
    INNER JOIN NUM1             U1           ON U1.CODUM1              = NS.UMSEC
    INNER JOIN NUM              U            ON U.CODUM                = U1.CODUM
    INNER JOIN IOART                         ON IOART.CODIOART         = NS.CODIOART
    INNER JOIN tmp_ioart_luna   ioaluna      ON IOALUNA.CODIOART       = NS.CODIOART
  WHERE &apos;||CONDITIE_STOC||&apos;
    AND (SELECT COUNT(*) FROM REZERVATS R WHERE REST &gt; 0 AND Coalesce(R.CODINVENTAR1, 0) &lt;&gt; 0 AND R.CODNIRSTOC = NS.CODNIRSTOC) = 0
    AND (IOALUNA.MG &lt;&gt; 5)
     &apos;||FILTRUMEDEX ;








  IF  pkg_configart.CODIOART_FILTRU_GENERATOR &gt; 0 THEN
    sFilter := &apos;
    AND IOALUNA.CODIOART= &apos;||pkg_configart.CODIOART_FILTRU_GENERATOR;
  END IF;

  IF pkg_nomgest.GEST_FILTRU_GENERATOR &gt; 0 THEN
    sFilter := sFilter ||&apos;
    AND NIRCURENT.GEST= &apos;||pkg_nomgest.GEST_FILTRU_GENERATOR;
  END IF;

  IF  pkg_claseart.CODCLASA_FILTRU_GENERATOR &gt; 0 THEN
    sFilter := sFilter ||&apos;
    AND A.CLASA = &apos;||pkg_claseart.CODCLASA_FILTRU_GENERATOR;
  END IF;

  SELECT COUNT(1) INTO nr FROM tmp_gestdedicate;
  IF nr &gt; 0 THEN
    sFilter := sFilter ||&apos;
    AND EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = NIRCURENT.GEST) &apos;;
  END IF;

  subDedicata:= PKG_GLOBALS.GETSUBUNITATE;
  IF subDedicata &gt; 1 THEN -- 1=cumulata firma
    sFilter := sFilter ||&apos;
    AND G.CODSUBUNIT = &apos;||subDedicata;
  END IF;

  sInsert := sInsert || sFilter || &apos;) &apos;;

  IF Length(Trim(INTERFACEFILTER)) &gt; 0 THEN
  sInsert := sInsert ||&apos; WHERE &apos; ||INTERFACEFILTER;
  END IF;

  IF MODLIVRAUTOMATA = 0
    THEN SINSERT := SINSERT || &apos; ORDER BY DENOBIECT, Coalesce(TG, TO_DATE(&apos;&apos;01.01.1900&apos;&apos;, &apos;&apos;dd.mm.yyyy&apos;&apos;)), DATAACHIZ, SERIE&apos;;
    ELSE SINSERT := SINSERT || &apos; ORDER BY DENOBIECT, DATAACHIZ, SERIE&apos;;
  END IF;

  SELECT pkg_globals.USERNAME INTO pUserName FROM dual;
  SELECT (Select USERID FROM TMP_PKG_GLOBALS) INTO pUser FROM dual;
  g_viewName := &apos;V_STOC_GEN_FACT_&apos;||pUser;
--  insert into x (test) values (&apos;CREATE OR REPLACE VIEW &apos;||g_ViewName||&apos; AS &apos;||sInsert);
--  commit;
  EXECUTE IMMEDIATE &apos;CREATE OR REPLACE VIEW &apos;||g_ViewName||&apos; AS &apos;||sInsert;
  EXECUTE IMMEDIATE  &apos;GRANT SELECT ON &apos;||g_viewName||&apos; TO &apos;||pUserName;

  --COMMIT;
END;


PROCEDURE MAKE_CONFIG_LUNA_EXT IS
--PRAGMA AUTONOMOUS_TRANSACTION;

  AnLunaLucru    NUMBER(20);
  aUSER_ID       NUMBER(20) := -1;
  aNART_FLG      NUMBER(1)  := 0;
  aNARTObj_FLG   NUMBER(1)  := 0;
  aIOART_FLG     NUMBER(1)  := 0;
  aNTVA_FLG      NUMBER(1)  := 0;
  aNTAXE_FLG     NUMBER(1)  := 0;
  aTARIFE_FLG    NUMBER(1)  := 0;
  aPRETM_FLG     NUMBER(1)  := 0;
  aIOPART_FLG    NUMBER(1)  := 0;
  aIOFILIAL_FLG  NUMBER(1)  := 0;
  aIOBANK_FLG    NUMBER(1)  := 0;
  aIOPERS_FLG    NUMBER(1)  := 0;
BEGIN
  pkg_globals.DATA0 := to_date(&apos;30.12.1899&apos;,&apos;dd.mm.yyyy&apos;);
  BEGIN
    SELECT
      Coalesce(USERID,-1), Coalesce(NART_FLG,0), Coalesce(NARTOBJ_FLG,0), Coalesce(IOART_FLG,0), Coalesce(NTVA_FLG,0), Coalesce(NTAXE_FLG,0), Coalesce(TARIFE_FLG,0),
      Coalesce(PRETM_FLG,0), Coalesce(IOPART_FLG,0), Coalesce(IOFILIAL_FLG,0), Coalesce(IOBANK_FLG,0), Coalesce(IOPERS_FLG,0)
    INTO
      aUSER_ID, aNART_FLG, aNARTObj_FLG, aIOART_FLG, aNTVA_FLG, aNTAXE_FLG, aTARIFE_FLG,
      aPRETM_FLG, aIOPART_FLG, aIOFILIAL_FLG, aIOBANK_FLG, aIOPERS_FLG
    FROM LUNA_RECORDS_FLAGS
    WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;

  IF aUSER_ID = -1 THEN
    INSERT INTO LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG) VALUES ((Select USERID from TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    INSERT INTO TMP_LUNA_RECORDS_FLAGS(USERID, NART_FLG, NARTOBJ_FLG, IOART_FLG, NTVA_FLG, NTAXE_FLG, TARIFE_FLG, PRETM_FLG, IOPART_FLG, IOFILIAL_FLG, IOBANK_FLG, IOPERS_FLG) VALUES ((Select USERID from TMP_PKG_GLOBALS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  END IF;
  AnLunaLucru := PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU;

  IF aIOART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOART1
    DELETE FROM tmp_ioart_luna;
    INSERT INTO TMP_IOART_LUNA (
      CODIOART1, CODIOART, CONT, DIFERENTE, CHELTUIELI, VENITURI, PLUSINVENTAR, MINUSINVENTAR, CHELTTVACOLECTAT, CONTROTUNJIRI, DIVERSE, CUSTODIE, ACCIZELATRANSFER,
      DESCARCAREG, CONTABGEST, BAZA, DIFPRET, ARETVANEEX, TVANEEX, MG, ANSTART, LUNASTART, PUSTANDARD, PROVIZION, CHELTPROVIZION, VENITPROVIZION, DEN_IOART,
      ESTEMIFIX,
      ESTEOBINV,
      ESTECUSTODIE)
    SELECT
      IO1.CODIOART1, IO1.CODIOART, IO1.CONT, IO1.DIFERENTE, IO1.CHELTUIELI, IO1.VENITURI, IO1.PLUSINVENTAR, IO1.MINUSINVENTAR, IO1.CHELTTVACOLECTAT, IO1.CONTROTUNJIRI, IO1.DIVERSE, IO1.CUSTODIE, IO1.ACCIZELATRANSFER,
      IO1.DESCARCAREG, IO1.CONTABGEST, IO1.BAZA, IO1.DIFPRET, IO1.ARETVANEEX, IO1.TVANEEX, IO1.MG, IO1.ANSTART, IO1.LUNASTART, IO1.PUSTANDARD, IO1.PROVIZION, IO1.CHELTPROVIZION, IO1.VENITPROVIZION, IO.DEN_IOART,
      PKG_CATEGCONST.ESTEMIFIX(IO1.CONT),
      PKG_CATEGCONST.ESTEOBINV(IO1.CONT),
      PKG_CATEGCONST.ESTECUSTODIE(IO1.CONT)
    FROM IOART IO INNER JOIN IOART1 IO1 ON IO.CODIOART = IO1.CODIOART
    WHERE AnLunaLucru BETWEEN IO1.ALStart AND IO1.ALStop;
    UPDATE LUNA_RECORDS_FLAGS SET IOART_FLG = 1 WHERE UserID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOART_FLG = 0;
  END IF;

  IF aIOPART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
      --IOPART1
    DELETE FROM TMP_IOPART_CFGLUNA;

    INSERT INTO TMP_IOPART_CFGLUNA (
      CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI,
      CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC, ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5,
      ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP )
    SELECT
      CODIOPART1, CODIOPART, CONTFURNIZOR, CONTCLIENT, CONTFURNAVANS, CONTCLIENTAVANS, CONTFURNAVIZ, CONTCLIENTAVIZ, CONTFURNMF, CONTCREDITD, CONTDEBITD, CONTLITIGII, CONTFURNAVS, CONTFURNAVIC, CONTFURNAVIN, CONTTERTI,
      CONTFURNLEAS, CONTNCRF, CONTNCRC, CONTCHELTAVANS, CONTVENITAVANS, contgarantieEF, contgarantieTF, contgarantieEC, contgarantieTC, ContSuplimF1, ContSuplimF2, ContSuplimF3, ContSuplimF4, ContSuplimF5,
      ContSuplimC1, ContSuplimC2, ContSuplimC3, ContSuplimC4, ContSuplimC5, TVANEEXF, TVANEEXC, TVANEEXP, TVANEEXI, TIP
    FROM IOPART1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET IOPART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPART_FLG = 0;
  END IF;


  IF aIOFILIAL_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOFILIAL1
    DELETE FROM TMP_IOFILIAL_LUNA;
    INSERT INTO TMP_IOFILIAL_LUNA(CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP)
    SELECT CODIOFILIAL1, CODIOFILIAL, CONTDECONTARE, CONTDECONTAREF, ISFIRMA, CONTDECONTSERV, CONTDECONTCB, CONTDECONTCMP
    FROM IOFILIAL1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOFILIAL_FLG = 0;
  END IF;


  IF aIOBANK_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --IOBANK1
    DELETE FROM TMP_IOBANK_LUNA;
    INSERT INTO TMP_IOBANK_LUNA (  CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM )
    SELECT CODIOBANK1, CODIOBANK, CONT, DOBANDA, COMISION, CHELTUIELICV, VENITURICV, PCEC, PEFECTE, PEFECTEREM, ICEC, IEFECTE, IEFECTEREM
    FROM IOBANK1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET IOBANK_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOBANK_FLG = 0;
  END IF;


  IF aIOPERS_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
      --IOPERS
    DELETE FROM TMP_IOPERS_CFGLUNA;
    INSERT INTO TMP_IOPERS_CFGLUNA ( CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT )
    SELECT CODIOPERS1, CODIOPERS, CONTAVANSDECONT, CONTIMPUTATII, CONTGARANTII, CONTALTERETINERI, CONTAVANS, CONTLIKI, CONTNERIDICATE, CONTBOALA, CONTPARTSAL, CONTNATURA, CONTECHIPAMENT, CONTIMPOZIT
    FROM IOPERS1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET IOPERS_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET IOPERS_FLG = 0;
  END IF;

  IF aPRETM_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    DELETE TMP_MANPRETM;
    IF Coalesce(pkg_globals.GETSUBUNITATE, 0) &lt;&gt; 1 THEN
      INSERT INTO TMP_MANPRETM
      SELECT CODOBIECT, LEI, VALUTA, SUBUNITATEA
      FROM PRETM PM, NCATPRET CAT
      WHERE CAT.CODCATPRET = PM.CODCATPRET
        AND Coalesce(PM.subunitatea, 0) = Coalesce(pkg_globals.GETSUBUNITATE,0)
        AND Coalesce(PM.IMPLICIT, 0) = 1
        AND CAT.TIP IN (1, 2);

      UPDATE LUNA_RECORDS_FLAGS SET PRETM_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
      UPDATE TMP_LUNA_RECORDS_FLAGS SET PRETM_FLG = 0;
    END IF;
  END IF;

  IF aNART_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --NART1
    DELETE FROM tmp_nart_luna;
    INSERT INTO tmp_nart_luna(codarticol1,codarticol,codtva,codaccize,codtaxa1,codtaxa2,anstart,lunastart)
    SELECT codarticol1,codarticol,codtva,codaccize,codtaxa1,codtaxa2,anstart,lunastart
    FROM nart1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;
    UPDATE LUNA_RECORDS_FLAGS SET NART_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NART_FLG = 0;
  END IF;

  IF aNTVA_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --NTVA1
    DELETE FROM tmp_ntva_luna;
    INSERT INTO tmp_ntva_luna(codtva1,codtva,procent,codcontded,codcontcole,codcontneex,anstart,lunastart,den_tva)
    SELECT n1.codtva1,n1.codtva,n1.procent,n1.codcontded,n1.codcontcole,n1.codcontneex,n1.anstart,n1.lunastart,n.den_tva
    FROM ntva1 n1 INNER JOIN ntva n ON n1.codtva = n.codtva
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET NTVA_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTVA_FLG = 0;
  END IF;


  IF aNTAXE_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --NTAXE1
    DELETE FROM tmp_ntaxe_luna;
    INSERT INTO tmp_ntaxe_luna(CODTAXA1,CODTAXA,VALOARE,LACEAPLIC,CODCONT,CODCONTCHELT,ORICARETIP,CODIOARTEXCL,
                              EXCLUSACCIZE,EXCLUSEXPORT,JACHIZ,JVANZ,CUMJACHIZ,CUMJVANZ,BazaMax,BazaMin,CODSERVFACT,
                              FACTURABIL,STOPAJ,ANSTART,LUNASTART,SERVICIUMONETAR, ProcDiminuareB, DEN_TAXA, Rotvaloare)
    SELECT n1.CODTAXA1,n1.CODTAXA,n1.VALOARE,n1.LACEAPLIC,n1.CODCONT,n1.CODCONTCHELT,n1.ORICARETIP,n1.CODIOARTEXCL,
           n1.EXCLUSACCIZE,n1.EXCLUSEXPORT,n1.JACHIZ,n1.JVANZ,n1.CUMJACHIZ,n1.CUMJVANZ,n1.BazaMax,n1.BazaMin,n1.CODSERVFACT,
           n1.FACTURABIL,n1.STOPAJ,n1.ANSTART,n1.LUNASTART,n1.SERVICIUMONETAR,n1.ProcDiminuareB,
          n.den_taxa, N1.ROTVALOARE
    FROM ntaxe1 n1 INNER JOIN ntaxe n ON n1.codtaxa = n.codtaxa
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET NTAXE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NTAXE_FLG = 0;
  END IF;

  IF aNARTOBJ_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --nartobj1
    DELETE FROM TMP_NARTOBJ_LUNA;
    INSERT INTO TMP_NARTOBJ_LUNA (
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,
      PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT,codmoneda, PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, SISTAVE, REFRACTIE, INDICE_W, TOXINA_DON, BOABE_TOXICE)
    SELECT
      CODOBIECT1,CODOBIECT,PRETMAXIMAL,PROCADAOSMAXIMAL,ADAOSLA,ANSTART,LUNASTART,
      PRETREFERINTA,TIPPRETMAX,COMPENSAT,TIPCOMPENSARE, GRUPA, UPLIFT,codmoneda, PUNCTE, Umiditate, CORPURI_STRAINE, Incoltit, Hectolitrica, Gluten, Fuzaritate, Cadere, Deformare, Sticlozitate, Sparturi, PUNCTESECTIE, TIPPRET,
      VALMAT, VALMAN, VALREGIE, D390EXCLUS, COST, CANTSERVAUTO,proteina, aflatoxina, atac_plosnita, continut_ulei, aciditate, SISTAVE, REFRACTIE, INDICE_W, TOXINA_DON, BOABE_TOXICE
    FROM nartobj1 n1
    WHERE AnLunaLucru BETWEEN N1.ALStart AND N1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET NARTOBJ_FLG = 0;
  END IF;

  IF aTARIFE_FLG = 0 or pkg_globals.LUNARECORDSFLAG = 0 THEN
    --nartobj1
    DELETE FROM TMP_TARIFEMAN_LUNA;
    INSERT INTO TMP_TARIFEMAN_LUNA ( CODTARIF1, CODTARIF, TARIF, ANSTART, LUNASTART )
    SELECT T1.CODTARIF1, T1.CODTARIF, T1.TARIF, T1.ANSTART, T1.LUNASTART
    FROM tarifeman1 t1
    WHERE AnLunaLucru BETWEEN t1.ALStart AND t1.ALStop;

    UPDATE LUNA_RECORDS_FLAGS SET TARIFE_FLG = 1 WHERE USERID = (Select USERID from TMP_PKG_GLOBALS);
    UPDATE TMP_LUNA_RECORDS_FLAGS SET TARIFE_FLG = 0;
  END IF;

  pkg_globals.LUNARECORDSFLAG := 1;

  COMMIT;
END;

END PKG_STOC_GENERARE_FACTURI;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_STRUCTURARETRASEU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC367286ADE2E0A2E2044B1F34FA6C90C4A778DA</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_STRUCTURARETRASEU IS

PROCEDURE PRELUARE_TRASEU(aTraseu IN NUMBER) IS
aTipTraseu number(2);
BEGIN
  DELETE TMP_NAGENDA_TRASEU;

  Select Coalesce(Tip,0) into aTipTraseu from TraseuLivr where CodTraseuLivr = aTraseu;

  INSERT INTO TMP_NAGENDA_TRASEU (
    CODAGENDA, FIRMA, SEDIU, ZONA, JUDET, LOCALITATE, POZTRASEU,
    SSOC,
    ADRESA, CODTRASEULIVR, Lat, Lng, CodPart )
  SELECT
    A.CODAGENDA, P.DEN_PART, A.OBS, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT,
		(Case when aTipTraseu = 0 then A.POZTRASEU else A.POZTRASEU1 end) POZTRASEU,
    CASE WHEN A.SEDIUSOCIAL BETWEEN 4 AND 7 THEN 1 ELSE 0 END,
    GETADRESA(A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL), aTraseu, A.Latitudine, A.Longitudine, A.CodPart
  FROM NAGENDA A
    INNER JOIN NPART P ON P.CODPART = A.CODPART
    LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
    LEFT JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
    LEFT JOIN NZONE Z ON Z.CODZONA = L.CODZONA
  WHERE ( aTipTraseu = 0 and CODTRASEU = aTraseu) or ( aTipTraseu = 1 and CODTRASEU1 = aTraseu)
    AND Coalesce(A.INACTIV,0) = 0;
  COMMIT;

END;

PROCEDURE SALVARE_TRASEU(aTraseu IN NUMBER) IS PRAGMA AUTONOMOUS_TRANSACTION;
vCOUNT INTEGER;
aTipTraseu number(2);
BEGIN
  vCOUNT := 0;
  FOR v_rec IN (SELECT CODAGENDA, POZTRASEU, CODTRASEULIVR FROM TMP_NAGENDA_TRASEU) LOOP
    Select Coalesce(Tip,0) into aTipTraseu from TraseuLivr where CodTraseuLivr = v_rec.CODTRASEULIVR;
    if aTipTraseu = 0 then
			UPDATE NAGENDA A
			SET
				A.POZTRASEU = v_rec.PozTraseu,
				A.CODTRASEU = V_REC.CODTRASEULIVR
			WHERE CODAGENDA = v_rec.CodAgenda;
		else
			UPDATE NAGENDA A
			SET
				A.POZTRASEU1 = v_rec.PozTraseu,
				A.CODTRASEU1 = V_REC.CODTRASEULIVR
			WHERE CODAGENDA = v_rec.CodAgenda;
		end if;
  END LOOP;

  COMMIT;
END;


END PKG_STRUCTURARETRASEU;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_SUBSIDIARY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC1CDBB7DCE218EFE01E276A41FAE9926D3C21AC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_SUBSIDIARY IS

  vDataIni DATE;
  iDataIni DATE;
  vDataFin DATE;
  cDataIni DATE;
  cDataFin DATE;

FUNCTION Get_zcliehier3(pCodPart NUMBER) RETURN VARCHAR2 IS
  vRESULT VARCHAR2(200);
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT MAX(HIER3) FROM NPARTDET WHERE CODPART = :1 &apos; INTO vRESULT USING pCodPart;
  RETURN vResult;
EXCEPTION
  WHEN OTHERS THEN RETURN NULL;
END;

PROCEDURE UMPLE_TMP(
  sDataIni IN VARCHAR2,
  sDataFin IN VARCHAR2,
  bOrder   IN BOOLEAN,
  bInvoice IN BOOLEAN,
  bStock   IN BOOLEAN DEFAULT FALSE)
IS
  vCLimba         NUMBER;
  vArtDiscAcTer   NUMBER :=  NVL(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcTer&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vArtDiscAcVol   NUMBER :=  NVL(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcVol&apos;,  PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  vArtDiscAcCant  NUMBER :=  NVL(PKG_CATEGCONST.GetValConstanta(&apos;ArtDiscAcCant&apos;, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  --vArtPenAc       NUMBER :=  NVL(PKG_CATEGCONST.GetValConstanta(&apos;ArtPenAc&apos;,      PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU), 0);
  AnStock         NUMBER(4);
  LunaStock       NUMBER(2);
  AnPrec          NUMBER(4);
  LunaPrec        NUMBER(2);
BEGIN
  vDataIni := To_Date(sDataIni,&apos;dd.mm.yyyy&apos;);
  vDataFin := To_Date(sDataFin,&apos;dd.mm.yyyy&apos;);

  iDataIni := vDataIni - CASE WHEN vDataIni = vDataFin THEN 5 ELSE 0 END;
  cDataFin := Greatest( Add_Months(vDataIni,12), vDataFin);
  cDataIni := Add_Months(vDataIni,-12);

  DELETE TMP_SUBSID_MAT;
  DELETE TMP_SUBSID_STK;
  DELETE TMP_SUBSID_NSG;
  DELETE TMP_SUBSID_CUS;
  DELETE TMP_SUBSID_ORD;
  DELETE TMP_SUBSID_INV;

  SELECT AnMaxim, LunaMaxima INTO AnStock, LunaStock FROM FirmaLuni;
  IF AnStock*12+LunaStock &gt; EXTRACT(YEAR  FROM vDataFin)*12+EXTRACT(MONTH FROM vDataFin) THEN
    AnStock   := EXTRACT(YEAR  FROM vDataFin);
    LunaStock := EXTRACT(MONTH FROM vDataFin);
  END IF;
  pkg_globals.Calculeaza_Luna_Precedenta(AnStock,LunaStock,AnPrec,LunaPrec);

  INSERT INTO TMP_SUBSID_NSG( codobiect, qty, val)
  WITH ioa1 AS (
    SELECT codioart, Max(cont) KEEP (Dense_Rank last ORDER BY anstart, lunastart) cont
    FROM ioart1
    WHERE anstart*12 + lunastart &lt;= AnStock*12+LunaStock
    GROUP BY codioart)
  SELECT CODOBIECT, SUM(REST) QTY, Sum(VAL) VAL
  FROM (
    SELECT NS.CODOBIECT, N.REST, N.REST * NS.PRET VAL
    FROM NIRLUNA N
      INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NARTOBJ o ON O.CODOBIECT = NS.CODOBIECT
    WHERE N.AN = AnPrec AND N.LUNA = LunaPrec
      AND IOA1.CONT IN (SELECT CODCONT FROM ncont CONNECT BY CODPARINTE = PRIOR CODCONT START WITH SIMBOL = &apos;371&apos;)
      AND O.CODINTERN NOT IN (&apos;919191&apos;)
    UNION ALL -- NIRURI LUNA
    SELECT NS.CODOBIECT, NS.CANTNIR REST, NS.CANTNIR * NS.PRET VAL
    FROM NIRSTOC NS
      INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NARTOBJ o ON O.CODOBIECT = NS.CODOBIECT
      LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
      LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
    WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
      AND N.DATANIR &lt;= vDataFin
      AND COALESCE(I.AN,T.AN) = AnStock
      AND COALESCE(I.LUNA,T.LUNA ) = LunaStock
      AND IOA1.CONT IN (SELECT CODCONT FROM ncont CONNECT BY CODPARINTE = PRIOR CODCONT START WITH SIMBOL = &apos;371&apos;)
      AND O.CODINTERN NOT IN (&apos;919191&apos;)
    UNION ALL
    SELECT NS.CODOBIECT, CASE WHEN L.TIPLIVR = 15 THEN 1 ELSE -1 END * L1.CANT REST, CASE WHEN L.TIPLIVR = 15 THEN 1 ELSE -1 END * L1.CANT * NS.PRET VAL
    FROM LIVR L
      INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
      INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN IOA1 ON IOA1.CODIOART = NS.CODIOART
      INNER JOIN NARTOBJ o ON O.CODOBIECT = NS.CODOBIECT
      LEFT  JOIN INTRARI I ON I.CODINTR = L.CODINTR
      LEFT  JOIN IESIRI IES ON IES.CODIES = L.CODIES
      LEFT  JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
    WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
      AND L.DATALIVR &lt;= vDataFin
      AND COALESCE(I.AN,IES.AN,T.AN) = AnStock
      AND COALESCE(I.LUNA,IES.LUNA,T.LUNA ) = LunaStock
      AND IOA1.CONT IN (SELECT CODCONT FROM ncont CONNECT BY CODPARINTE = PRIOR CODCONT START WITH SIMBOL = &apos;371&apos;)
      AND O.CODINTERN NOT IN (&apos;919191&apos;)
  )
  GROUP BY CODOBIECT;

  IF bStock THEN
    INSERT INTO TMP_SUBSID_STK( codobiect, comp_code, plant, salesorg, distr_chan, day, material, stor_loc, supplier, val, loc_currcy, qty, stor_unit )
    SELECT
      o.codobiect,  &apos;0380&apos;, &apos;DI38&apos;, &apos;OR38&apos;, &apos;CD&apos;, To_Char(vDataFin,&apos;yyyymmdd&apos;), o.codintern, &apos;M380&apos;, NULL,
      TO_CHAR(s.val,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;), &apos;RON&apos;,
      TO_CHAR(s.qty,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;), u.den_um
    FROM TMP_SUBSID_NSG s
      INNER JOIN nartobj o ON o.codobiect = s.codobiect
      INNEr JOIN nart a ON a.codarticol = o.codarticol
      INNER JOIN num u ON u.codum = a.um
    WHERE s.qty &lt;&gt; 0;
  END IF;


  IF bOrder THEN
    INSERT INTO TMP_SUBSID_ORD(
      codcomanda, codobiect, codpart, comp_code, salesorg, distr_chan,
      division,
      doc_number, sold_to, doc_type, doc_categ_ord, zabrvw, zvdatu, loc_currcy,
      s_ord_item,
      item_categ_ord,
      material, zeedatu, zerdat, reason_rej, doc_currcy, plant, zkztlf,
      billtoprty,
      payer,
      ship_to,
      zkdmat2, req_date, conf_qty, sales_unit, gi_date, load_date, matav_date,
      zcmd_val, zval_lc, zccost_dc, zccost_lc)
    SELECT
      c.codcomanda, c1.codobiect, c.codlocatie, &apos;0380&apos;, &apos;OR38&apos;, &apos;CD&apos;,
      CASE
        WHEN UPPER(tsoc.simbauto) = &apos;RO&apos; THEN &apos;S1&apos;
        WHEN tsoc.simbauto IS NULL THEN &apos;S1&apos;
        ELSE &apos;S2&apos;
      END,
      c.nrdoc, Nvl(slivr.idsediu,&apos;...undefined... &apos;), &apos;ZPER&apos;, &apos;C&apos;, NULL, To_Char(c.datadoc,&apos;yyyymmdd&apos;), &apos;RON&apos;,
      ROW_NUMBER() OVER (PARTITION BY C.CODCOMANDA ORDER BY C1.CODCOMANDA1),
      Decode(c.faratransport,1,0,1),
      o.codintern, To_Char(c1.termen,&apos;yyyymmdd&apos;), To_Char(c.datadoc,&apos;yyyymmdd&apos;), NULL, m.simbol, &apos;DI38&apos;, NULL,
      PKG_D394.ExtrageNr(cfi.codfiscal),
      PKG_D394.ExtrageNr(cfi.codfiscal),
      Nvl(slivr.idsediu,&apos;...undefined... &apos;),
      ac.codextern, To_Char(c1.termen,&apos;yyyymmdd&apos;), TO_CHAR(c1.cantacceptat/u.paritate,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;), u.den_um1,
      To_Char(c1.termen,&apos;yyyymmdd&apos;), To_Char(c1.termen,&apos;yyyymmdd&apos;), To_Char(c1.termen,&apos;yyyymmdd&apos;),
      TO_CHAR(c1.pu*Nvl(1+c1.procdisc/100,1)*c1.cantacceptat,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR(c1.pu*Nvl(1+c1.procdisc/100,1)*c1.cantacceptat*c.curs,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR( (
        SELECT Sum ((NS.PRET-NS.ADAOS)*R.REZERVATINI)
        FROM REZERVATS R INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        WHERE R.CODCOMANDA1 = C1.CODCOMANDA1)/c.curs,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR( (
        SELECT Sum ((NS.PRET-NS.ADAOS)*R.REZERVATINI)
        FROM REZERVATS R INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = R.CODNIRSTOC
        WHERE R.CODCOMANDA1 = C1.CODCOMANDA1)/c.curs,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;)
    FROM comanda c
      INNER JOIN comanda1 c1 ON c1.codcomanda = c.codcomanda
      INNER JOIN nmonede m ON m.codmoneda = c.moneda
      INNER JOIN npart p ON p.codpart = c.partener
      INNER JOIN nartobj o ON o.codobiect = c1.codobiect
      INNER JOIN num1 u ON u.codum1 = c1.umsec
      LEFT JOIN nagenda ssoc ON ssoc.codpart = c.partener AND ssoc.sediusocial between 4 and 7 AND NVL(ssoc.inactiv, 0) = 0
      LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
      LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
      LEFT JOIN nagenda slivr ON slivr.codagenda = c.codlocatie
      LEFT JOIN nagenda sfact ON sfact.codagenda = CASE
                                                    WHEN slivr.sediusocial IN (1,5,9) AND Nvl(slivr.codcoresp,0) &lt;&gt; 0 THEN slivr.codcoresp
                                                    WHEN slivr.sediusocial IN (3,7) THEN slivr.codagenda
                                                    WHEN ssoc.sediusocial  IN (6,7) THEN ssoc.codagenda
                                                    ELSE 0
                                                  END
      LEFT JOIN npartcodfisc cfi ON cfi.codpart = c.partener AND cfi.principal = 1
      LEFT JOIN nartcli ac ON ac.codobiect = c1.codobiect AND ac.codpart = c.partener
    WHERE c.operat = 1 AND c.anulat = 0 AND c.tipdoc = 18
      AND Coalesce(c1.termen,c.datadoc) BETWEEN cDataIni AND cDataFin
      AND Coalesce(c1.restacceptat, 0) &lt;&gt; 0
      AND O.CODINTERN NOT IN (&apos;919191&apos;);
  END IF;

  IF bInvoice THEN
    INSERT INTO TMP_SUBSID_INV(
      codies, codobiect, codpart, comp_code, salesorg, distr_chan,
      division,
      bill_num, sold_to,
      bill_type,
      doc_categ_inv,
      bill_date, doc_currcy, loc_currcy,
      bill_item,
      item_categ_inv,
      material,
      billtoprty,
      payer,
      ship_to,
      inv_qty, sales_unit,
      netval_inv, znet_val,
      cost, zcost,
      co_area, plant, doc_number, s_ord_item, doc_type)
    SELECT
      i.codies, i1.codobiect, i.codlocatie, &apos;0380&apos;, &apos;OR38&apos;, &apos;CD&apos;,
      CASE
        WHEN UPPER(tsoc.simbauto) = &apos;RO&apos; THEN &apos;S1&apos;
        WHEN tsoc.simbauto IS NULL THEN &apos;S1&apos;
        ELSE &apos;S2&apos;
      END,
      i.nrdoc, Nvl(slivr.idsediu,&apos;...undefined... &apos;),
      CASE
        WHEN i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN &apos;G2&apos;
        WHEN i1.codobiect IN (vArtDiscAcTer, vArtDiscAcVol, vArtDiscAcCant) THEN &apos;G2&apos;
        WHEN Upper(o.codintern) LIKE &apos;REFUND%&apos; THEN &apos;G2&apos;
        WHEN i1.cant &gt;= 0 THEN &apos;Z1F2&apos;
        ELSE &apos;RE&apos;
      END,
      &apos;M&apos;,
      To_Char(i.datadoc,&apos;yyyymmdd&apos;), m.simbol, &apos;RON&apos;,
      ROW_NUMBER() OVER (PARTITION BY i.codies ORDER BY i1.indexlocal),
      &apos;TAN&apos;,
      CASE
        WHEN i1.tiplinie IN (&apos;G&apos;,&apos;T&apos;) THEN &apos;REFUND&apos;
        ELSE o.codintern
      END,
      PKG_D394.ExtrageNr(cfi.codfiscal),
      PKG_D394.ExtrageNr(cfi.codfiscal),
      Nvl(slivr.idsediu,&apos;...undefined... &apos;),
      TO_CHAR(i1.cant/u.paritate,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;), u.den_um1,
      TO_CHAR(i1.pu*Nvl(1+i1.procdisc/100,1)*i1.cant,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR(i1.pu*Nvl(1+i1.procdisc/100,1)*i1.cant*i.curs,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR( (
        SELECT Sum ( Nvl(LV.PRETACHIZ,NS.PRET-NS.ADAOS)*L1.CANT)
        FROM LIVR L
          INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
          LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
          LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        WHERE L.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1)/i.curs,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      TO_CHAR( (
        SELECT Sum ( Nvl(LV.PRETACHIZ,NS.PRET-NS.ADAOS)*L1.CANT)
        FROM LIVR L
          INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
          LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
          LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        WHERE L.CODIES = I.CODIES AND L1.CODIES1 = I1.CODIES1),&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;),
      &apos;0200&apos;, &apos;DI38&apos;, c.nrdoc,
      CASE WHEN C1.codcomanda1 IS NOT NULL THEN (SELECT Count(1) FROM comanda1 x WHERE x.codcomanda = c1.codcomanda AND x.codcomanda1 &lt;= c1.codcomanda1) END,
      &apos;ZPER&apos;
    FROM iesiri i
      INNER JOIN iesiri1 i1 ON i1.codies = i.codies
      INNER JOIN nmonede m ON m.codmoneda = i.moneda
      INNER JOIN npart p ON p.codpart = i.partener
      INNER JOIN nartobj o ON o.codobiect = i1.codobiect
      INNER JOIN num1 u ON u.codum1 = i1.umsec
      LEFT JOIN nagenda ssoc ON ssoc.codpart = i.partener AND ssoc.sediusocial between 4 and 7 AND NVL(ssoc.inactiv, 0) = 0
      LEFT JOIN nlocalit lsoc ON lsoc.codlocalit = ssoc.codlocalit
      LEFT JOIN ntari tsoc ON tsoc.codtara = lsoc.codtara
      LEFT JOIN nagenda slivr ON slivr.codagenda = i.codlocatie
      LEFT JOIN nagenda sfact ON sfact.codagenda = CASE
                                                    WHEN slivr.sediusocial IN (1,5,9) AND Nvl(slivr.codcoresp,0) &lt;&gt; 0 THEN slivr.codcoresp
                                                    WHEN slivr.sediusocial IN (3,7) THEN slivr.codagenda
                                                    WHEN ssoc.sediusocial  IN (6,7) THEN ssoc.codagenda
                                                    ELSE 0
                                                  END
      LEFT JOIN npartcodfisc cfi ON cfi.codpart = i.partener AND cfi.principal = 1
      LEFT JOIN nartcli ac ON ac.codobiect = i1.codobiect AND ac.codpart = i.partener
      --LEFT JOIN ieslink ilae ON ilae.codies1 = i1.codies1
      --LEFT JOIN ieslink ilcom ON ilcom.codies1 = NVL(ilae.codlinieaviz, i1.codies1)
      LEFT JOIN ieslink ilcom ON ilcom.codies1 = i1.codies1
      LEFT JOIN comanda1 c1 ON c1.codcomanda1 = ilcom.codliniecomanda
      LEFT JOIN comanda c ON c.codcomanda = c1.codcomanda
    WHERE i.operat = 1 AND i.anulat = 0 AND i.tipdoc IN (19,20,21,22)
      AND i.datadoc BETWEEN iDataIni AND vDataFin
      AND O.CODINTERN NOT IN (&apos;919191&apos;);

  END IF;

  INSERT INTO TMP_SUBSID_MAT( codobiect, plant, salesorg, distr_chan, material)
  SELECT codobiect, plant, salesorg, distr_chan, material FROM TMP_SUBSID_ORD
  UNION
  SELECT codobiect, plant, salesorg, distr_chan, material FROM TMP_SUBSID_INV
  UNION
  SELECT codobiect, plant, salesorg, distr_chan, material FROM TMP_SUBSID_STK;

  SELECT Nvl(Min(CodLimba),-1) INTO vCLimba
  FROM NLIMBA
  WHERE DenLimba = &apos;ENGLEZA&apos;;

  UPDATE TMP_SUBSID_MAT T
  SET (   maktx, f, zmmsta, zmtpos, mat_stgrp, zvprsv, val_class,
          zverpr, currency, mat_type ) =
      ( SELECT
          SubStr(Nvl(tr.denumiretrad,o.denumire),1,40), &apos;F&apos;, &apos;10&apos;, &apos;NORM&apos;, Decode(a.tiparticol, 0, 1, 0), &apos;V&apos;, &apos;3100&apos;,
          TO_CHAR(s.val/s.qty,&apos;fm9999999990D00&apos;, &apos;NLS_NUMERIC_CHARACTERS=&apos;&apos;.,&apos;&apos;&apos;), &apos;RON&apos;, &apos;FP&apos;
        FROM nartobj o
          INNER JOIN nart a ON a.codarticol = o.codarticol
          LEFT JOIN tmp_subsid_nsg s ON s.codobiect = o.codobiect AND s.qty &lt;&gt; 0
          LEFT JOIN nartobjtrad tr ON tr.codlimba = vCLimba and tr.codobiect = o.codobiect
        WHERE o.codobiect = t.codobiect
      );

  INSERT INTO TMP_SUBSID_CUS(
    codpart, comp_code, salesorg, distr_chan, division, customerf )
  SELECT codpart, comp_code, salesorg, distr_chan, division, sold_to FROM TMP_SUBSID_ORD
  UNION
  SELECT codpart, comp_code, salesorg, distr_chan, division, sold_to FROM TMP_SUBSID_INV
  UNION
  SELECT ss.codagenda, t.comp_code, t.salesorg, t.distr_chan, t.division, t.payer
  FROM TMP_SUBSID_ORD T
    INNER JOIN nagenda sl ON sl.codagenda = t.codpart
    INNER JOIN nagenda ss ON ss.codpart = sl.codpart AND ss.sediusocial between 4 and 7 AND NVL(ss.inactiv, 0) = 0
  UNION
  SELECT ss.codagenda, t.comp_code, t.salesorg, t.distr_chan, t.division, t.payer
  FROM TMP_SUBSID_INV T
    INNER JOIN nagenda sl ON sl.codagenda = t.codpart
    INNER JOIN nagenda ss ON ss.codpart = sl.codpart AND ss.sediusocial between 4 and 7 AND NVL(ss.inactiv, 0) = 0;

  UPDATE TMP_SUBSID_CUS T
  SET (   customer, country, zattrib1, zkdkg1, zcliehier1, zcliehier3,
          sales_off,
          sales_grp,
          sales_dist, cust_group, cust_grp1
      ) =
      ( SELECT
          sed.obs, tsed.simbauto, &apos;01&apos;, NULL, np.codextern, pkg_subsidiary.Get_zcliehier3(sed.codpart),
          CASE WHEN Upper(clsp.den_clasep) = &apos;TRADITIONAL&apos; THEN &apos;Iulian&apos; ELSE &apos;Cristina&apos; END,
          CASE WHEN Nvl(ag.codpers,0) &lt;&gt; 0 THEN ag.nume ||&apos; &apos;||ag.prenume ELSE ag.nume END ,
          jsed.den_judet, clsp.den_clasep, cls.den_clasep
        FROM nagenda sed
          LEFT JOIN nlocalit lsed ON lsed.codlocalit = sed.codlocalit
          LEFT JOIN ntari tsed ON tsed.codtara = lsed.codtara
          LEFT JOIN nzone zsed ON zsed.codzona = lsed.codzona
          LEFT JOIN njudet jsed ON jsed.codjudet = lsed.codjudet
          LEFT JOIN npart np ON np.codpart = sed.codpart
          LEFT JOIN ncatpret cp ON cp.codcatpret = np.codcategpret
          LEFT JOIN nclasep cls ON cls.codclasep = np.codclasa
          LEFT JOIN nclasep clsp ON clsp.codclasep = Decode(cls.codparinte,0,cls.codclasep,NULL,cls.codclasep,cls.codparinte)
          LEFT JOIN npers ag ON ag.codpers = Nvl(sed.codagent,0)
        WHERE sed.codagenda = t.codpart
      );

  COMMIT;

END;

PROCEDURE AUX_TMP(
  sTMP      IN  VARCHAR2,
  sHeader   OUT VARCHAR2,
  sFooter   OUT VARCHAR2,
  sFileName OUT VARCHAR2
) IS
  vTMP      VARCHAR2(100) := Upper(sTMP);
  vLastCol  INTEGER;
  vCount    INTEGER;
  vFirstCol INTEGER;
BEGIN

  SELECT count(1) INTO vLastCol
  FROM user_tab_columns
  WHERE Upper(table_name) = &apos;TMP_SUBSID_&apos;||vTMP;

  sFileName := To_Char(vDataFin,&apos;yymmdd&apos;)||&apos;-0380-&apos;||vTMP||&apos;.txt&apos;;
  IF vTMP = &apos;MAT&apos; THEN
    vFirstCol := 1;
    sHeader :=
      &apos;Plant|Sales Organization|Distribution Channel|Material|Designation|Procurement Type|&apos;||
      &apos;Status|Qty per Inner|Qty per Master|Qty per Layer|Qty per Pallet|MRP Controller|Material Group 1|&apos;||
      &apos;Item Category Group|Statistic group|&apos;||
      &apos;Material Group 4 Product responible|Price Control Indicator|Valuation Class|Moving Average Price|Standard Price|Currency|Volume Unit|Master Volume|Material Type&apos;;
    SELECT Count(1) INTO vCount FROM TMP_SUBSID_MAT;
  ELSIF vTMP = &apos;STK&apos; THEN
    vFirstCol := 1;
    sHeader :=
      &apos;Plant|Company|Sales Organization|Distribution Channel|DAY|Material|Storage location|Supplier|Value|Local Currency|Quantity|Unit&apos;;
    SELECT Count(1) INTO vCount FROM TMP_SUBSID_STK;
  ELSIF vTMP = &apos;CUS&apos; THEN
    vFirstCol := 1;
    sHeader :=
      &apos;Company|Sales Organization|Distribution Channel|Division|Customer Code|Customer Name|Country|Attribut 1|Condition Group 1|&apos;||
      &apos;Customers hierarchy lev 1|Customers hierarchy lev 2|Customers hierarchy lev 3|Sales office|Sales group|Sales district|Customer Group|&apos;||
      &apos;Price group|Price List|Customer activity|Logistic|Pallet Type|Shipment type&apos;;
    SELECT Count(1) INTO vCount FROM TMP_SUBSID_CUS;
  ELSIF vTMP = &apos;ORD&apos; THEN
    vFirstCol := 3;
    sHeader :=
      &apos;Company code|Sales Organization|Distribution Channel|Division|Sales Order Number|Sold to party|Order type|Type of Document|&apos;||
      &apos;EDI Order|Initial Delivery date |Company Currency|Item|Doc Item category|Material|Delivery date by Item|Creation date by Item|&apos;||
      &apos;Reason for rejection |Sales order currency|Plant|Partial delivery|Bill to party|Payer|Ship to party|Customer material number|&apos;||
      &apos;Delivery date by schedule lines|Confirmed quantity|Sales unit|Goods issue date|Loading date|Material avail.date|&apos;||
      &apos;Net price (sales order currency)|Net price (internal currency)|Cost  (sales order currency)|Cost  (Internal currency)&apos;;
    SELECT Count(1) INTO vCount FROM TMP_SUBSID_ORD;
  ELSIF vTMP = &apos;INV&apos; THEN
    vFirstCol := 3;
    sHeader :=
      &apos;Company code|Sales Organization|Distribution Channel|Division|Invoice Number|Sold to party|Invoice type|Type of Document|&apos;||
      &apos;Invoice date|Invoice currency|Company Currency|Payer|Invoice Item|Invoice Item type|Material|Bill to party|Ship to party|Invoice Quantity|&apos;||
      &apos;Sales unit|Net price (sales order currency)|Net price (internal currency)|Cost  (sales order currency)|Cost  (Internal currency)|&apos;||
      &apos;Controlling Area|Plant|Sales Order Number|Sales Order Item|Order type&apos;;
    SELECT Count(1) INTO vCount FROM TMP_SUBSID_INV;
  END If;
  sFooter := &apos;EOF|&apos;||vCount||&apos;|&apos;||To_Char(CASE WHEN vTMP = &apos;ORD&apos; THEN cDataIni ELSE iDataIni END,&apos;yyyymmdd&apos;)||&apos;|&apos;||To_Char(CASE WHEN vTMP = &apos;ORD&apos; THEN cDataFin ELSE vDataFin END,&apos;yyyymmdd&apos;);
  sFooter := RPad(sFooter,Length(sFooter)+vLastCol-vFirstCol-5,&apos;|&apos;);
END;

FUNCTION getCursorTmp(pTMP IN  VARCHAR2) RETURN SYS_REFCURSOR IS
  cResult SYS_REFCURSOR;
BEGIN
  IF Upper(pTMP) = &apos;MAT&apos; THEN
    OPEN cResult FOR
      SELECT
        plant||&apos;|&apos;||salesorg||&apos;|&apos;||distr_chan||&apos;|&apos;||material||&apos;|&apos;||maktx||&apos;|&apos;||f||&apos;|&apos;||zmmsta||&apos;|&apos;||znbspcb||&apos;|&apos;||znbpcb||&apos;|&apos;||znbbox||&apos;|&apos;||znbpal||&apos;|&apos;||mrp_contrl||&apos;|&apos;||mat_kondm||&apos;|&apos;||zmtpos||&apos;|&apos;||mat_stgrp||&apos;|&apos;||
        matl_grp_4||&apos;|&apos;||zvprsv||&apos;|&apos;||val_class||&apos;|&apos;||zverpr||&apos;|&apos;||zstprs||&apos;|&apos;||currency||&apos;|&apos;||volumeunit||&apos;|&apos;||zvolpcb||&apos;|&apos;||mat_type linie
      FROM TMP_SUBSID_MAT;
  ELSIF Upper(pTMP) = &apos;STK&apos; THEN
    OPEN cResult FOR
      SELECT plant||&apos;|&apos;||comp_code||&apos;|&apos;||salesorg||&apos;|&apos;||distr_chan||&apos;|&apos;||day||&apos;|&apos;||material||&apos;|&apos;||stor_loc||&apos;|&apos;||supplier||&apos;|&apos;||val||&apos;|&apos;||loc_currcy||&apos;|&apos;||qty||&apos;|&apos;||stor_unit linie
      FROM TMP_SUBSID_STK;
  ELSIF Upper(pTMP) = &apos;CUS&apos; THEN
    OPEN cResult FOR
      SELECT
        comp_code||&apos;|&apos;||salesorg||&apos;|&apos;||distr_chan||&apos;|&apos;||division||&apos;|&apos;||customerf||&apos;|&apos;||customer||&apos;|&apos;||country||&apos;|&apos;||zattrib1||&apos;|&apos;||zkdkg1||&apos;|&apos;||zcliehier1||&apos;|&apos;||zcliehier2||&apos;|&apos;||zcliehier3||&apos;|&apos;||sales_off||&apos;|&apos;||
        sales_grp||&apos;|&apos;||sales_dist||&apos;|&apos;||cust_group||&apos;|&apos;||price_grp||&apos;|&apos;||price_list||&apos;|&apos;||cust_grp1||&apos;|&apos;||cust_grp2||&apos;|&apos;||cust_grp3||&apos;|&apos;||cust_grp4 linie
      FROM TMP_SUBSID_CUS;
  ELSIF Upper(pTMP) = &apos;ORD&apos; THEN
    OPEN cResult FOR
      SELECT
        comp_code||&apos;|&apos;||salesorg||&apos;|&apos;||distr_chan||&apos;|&apos;||division||&apos;|&apos;||doc_number||&apos;|&apos;||sold_to||&apos;|&apos;||doc_type||&apos;|&apos;||doc_categ_ord||&apos;|&apos;||zabrvw||&apos;|&apos;||zvdatu||&apos;|&apos;||loc_currcy||&apos;|&apos;||s_ord_item||&apos;|&apos;||item_categ_ord||&apos;|&apos;||
        material||&apos;|&apos;||zeedatu||&apos;|&apos;||zerdat||&apos;|&apos;||reason_rej||&apos;|&apos;||doc_currcy||&apos;|&apos;||plant||&apos;|&apos;||zkztlf||&apos;|&apos;||billtoprty||&apos;|&apos;||payer||&apos;|&apos;||ship_to||&apos;|&apos;||zkdmat2||&apos;|&apos;||req_date||&apos;|&apos;||conf_qty||&apos;|&apos;||sales_unit||&apos;|&apos;||
        gi_date||&apos;|&apos;||load_date||&apos;|&apos;||matav_date||&apos;|&apos;||zcmd_val||&apos;|&apos;||zval_lc||&apos;|&apos;||zccost_dc||&apos;|&apos;||zccost_lc linie
      FROM TMP_SUBSID_ORD;
  ELSIF Upper(pTMP) = &apos;INV&apos; THEN
    OPEN cResult FOR
      SELECT
        comp_code||&apos;|&apos;||salesorg||&apos;|&apos;||distr_chan||&apos;|&apos;||division||&apos;|&apos;||bill_num||&apos;|&apos;||sold_to||&apos;|&apos;||bill_type||&apos;|&apos;||doc_categ_inv||&apos;|&apos;||bill_date||&apos;|&apos;||doc_currcy||&apos;|&apos;||loc_currcy||&apos;|&apos;||payer||&apos;|&apos;||bill_item||&apos;|&apos;||
        item_categ_inv||&apos;|&apos;||material||&apos;|&apos;||billtoprty||&apos;|&apos;||ship_to||&apos;|&apos;||inv_qty||&apos;|&apos;||sales_unit||&apos;|&apos;||netval_inv||&apos;|&apos;||znet_val||&apos;|&apos;||cost||&apos;|&apos;||zcost||&apos;|&apos;||co_area||&apos;|&apos;||plant||&apos;|&apos;||doc_number||&apos;|&apos;||
        s_ord_item||&apos;|&apos;||doc_type linie
      FROM TMP_SUBSID_INV;
  END If;

  RETURN cResult;
END;

PROCEDURE expCursor(pTMP IN VARCHAR2) IS
  sHeader   VARCHAR2(1000);
  sFooter   VARCHAR2(1000);
  sFileName VARCHAR2(1000);
  vCusor    SYS_REFCURSOR;
  vLinie    VARCHAR2 (32767);
  L_HANDLER UTL_FILE.FILE_TYPE;
BEGIN
  AUX_TMP( pTMP, sHeader, sFooter, sFileName);
  L_HANDLER := UTL_FILE.FOPEN(&apos;EXP_SUBSID&apos;, sFileName, &apos;W&apos;);
  UTL_FILE.PUTF(L_HANDLER, sHeader);
  vCusor := getCursorTmp(pTMP);
  LOOP
    FETCH vCusor INTO vLinie;
    EXIT WHEN vCusor%NOTFOUND;
    UTL_FILE.NEW_LINE(L_HANDLER, 1);
    UTL_FILE.PUTF(L_HANDLER, vLinie);
  END LOOP;
  CLOSE vCusor;
  UTL_FILE.NEW_LINE(L_HANDLER, 1);
  UTL_FILE.PUTF(L_HANDLER, sFooter);
  UTL_FILE.FCLOSE(L_HANDLER);
END;

PROCEDURE EXPORT(bStock IN BOOLEAN DEFAULT FALSE) IS
  sHeader   VARCHAR2(1000);
  sFooter   VARCHAR2(1000);
  sFileName VARCHAR2(1000);
  vFirstCol INTEGER;
  L_HANDLER UTL_FILE.FILE_TYPE;
BEGIN
--CREATE DIRECTORY EXP_SUBSID AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_SUBSID TO **USER**;

  expCursor(&apos;MAT&apos;);
  IF bStock THEN
    expCursor(&apos;STK&apos;);
  END IF;
  expCursor(&apos;CUS&apos;);
  expCursor(&apos;ORD&apos;);
  expCursor(&apos;INV&apos;);
END;

PROCEDURE EXPORT_ZILNIC(bStock IN BOOLEAN DEFAULT FALSE) IS
  vData     DATE      := Trunc(SYSDATE);
  vAn       NUMBER(4) := EXTRACT(YEAR  FROM vDATA);
  vLuna     NUMBER(2) := EXTRACT(MONTH FROM vDATA);
BEGIN
  PKG_GLOBALS.SetLunaLucru(vAn, vLuna);
  UMPLE_TMP(To_Char(vData,&apos;dd.mm.yyyy&apos;), To_Char(vData,&apos;dd.mm.yyyy&apos;), TRUE, TRUE, bStock);
  EXPORT(bStock);
END;

PROCEDURE EXPORT_LUNAR(bStock IN BOOLEAN DEFAULT FALSE) IS
  vDataIni  DATE      := Trunc(Add_Months(SYSDATE,-1),&apos;MM&apos;);
  vDataFin  DATE      := Last_Day(vDataIni);
  vAn       NUMBER(4) := EXTRACT(YEAR  FROM vDataIni);
  vLuna     NUMBER(2) := EXTRACT(MONTH FROM vDataIni);
BEGIN
  PKG_GLOBALS.SetLunaLucru(vAn, vLuna);
  UMPLE_TMP(To_Char(vDataIni,&apos;dd.mm.yyyy&apos;), To_Char(vDataFin,&apos;dd.mm.yyyy&apos;), TRUE, TRUE, bStock);
  EXPORT(bStock);
END;

END pkg_subsidiary;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TARGETAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACCBA554E798DCC4D015E379B6A67A84BAB61AA9</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_targetag IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_29&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodTARGETAG INTO Tmp FROM TARGETAG WHERE CodTARGETAG = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 17);
  SP_LOCKRECORD(RecId);
 	DELETE FROM TARGETAG1 WHERE CodTARGETAG = RecId ;
 	DELETE FROM TARGETAG  WHERE CodTARGETAG = RecId ;
  NotifyModif(2, RecId, &apos;TARGETAG&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_TARGETAG FIELDS( CodTARGETAG ) VALUES (0) ;
  PKG_CFGTABLES.EXT_INSERTRECORD(17);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aTipTarget number;
BEGIN
  -- Master TARGETAG
  INSERT INTO  TMP_TARGETAG (
    CodTARGETAG, TipDoc, Anulat, Blocat, Operat, Activ,
    DataStart, DataStop, TipTarget,
    Moneda, Obs, Subunitatea, An, Luna,
    UserId, DataCreare, Agent, Client, ClasaPart, TipPart,
    LunaStart, AnStart, LunaEnd, AnEnd, Nrclienti
    )
  SELECT
    CodTARGETAG, TipDoc, Anulat, Blocat, Operat, Activ,
    DataStart, DataStop, TipTarget,
    Moneda, Obs, Subunitatea, PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GetLunaLucru,
    UserId, DataCreare, Agent,Client, ClasaPart, TipPart,
    LunaStart,  AnStart, LunaEnd, AnEnd, Nrclienti
  FROM TARGETAG
  WHERE CodTARGETAG = RecId;

  -- Detail TARGETAG1
  INSERT INTO  TMP_TARGETAG1 (
    CodTARGETAG1, CodTARGETAG, CodObiect, CodClasa, CodClasaS, UMSec,
    Cant, Valoare, Masa, Volum,
    Obs, CantMin, CantMax,
    IndexLocal,
    TipLinie,
    DenObiect, DenUM, Paritate,
    CodArticol)
  SELECT
    C1.CodTARGETAG1, C1.CodTARGETAG, C1.CodObiect, C1.CodClasa, CodClasaS, C1.UMSec,
    C1.Cant / decode(nvl(U.Paritate,1),0,1,nvl(U.Paritate,1)), C1.Valoare, C1.Masa, C1.Volum,
    C1.Obs, C1.CantMin, C1.CantMax,
    ROW_NUMBER() OVER (PARTITION BY C1.CodTARGETAG ORDER BY C1.CodTARGETAG1 ASC),
    Decode(A.TipArticol, &apos;0&apos;, &apos;=&apos;, &apos;S&apos;),
    O.Denumire, U.Den_UM1, decode(nvl(U.Paritate,1),0,1,nvl(U.Paritate,1)),
    O.CodArticol
  FROM TARGETAG C
    INNER JOIN TARGETAG1 C1 ON C1.CodTARGETAG = C.CodTARGETAG
    LEFT JOIN NArtObj O ON O.CodObiect = C1.CodObiect
    LEFT JOIN NArt A ON A.CodArticol = O.CodArticol
    LEFT JOIN NUM1 U ON U.CodUM1 = C1.UMSec
  WHERE C.CodTARGETAG = RecId;

  select TipTarget into aTipTarget from TMP_TARGETAG;
  if aTipTarget = 2 then 
	  update TMP_TARGETAG1 T1 set T1.DenObiect = (Select DEN_CLASEA from NCLASEA C where CodCLASEA = T1.Codclasa);
	elsif aTipTarget = 3 then
	  update TMP_TARGETAG1 T1 set T1.DenObiect = (Select DEN_CLASEAS from NCLASEAS C where CodCLASEAS = T1.Codclasas);
	end if;
  PKG_CFGTABLES.EXT_GOTORECORD(17);
  COMMIT;

END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo        INTEGER := 0;
  vCod          NUMBER(20);
  vCodPart      NPart.CodPart%TYPE;
  vtest         NUMBER;
  vDenumire     NArtCli.Denumire%TYPE;
  vCodExtern    NArtCli.CodExtern%TYPE;
  vUmSec        NArtCli.UMSec%TYPE;
  aCarnetDoc    NUMBER (20);
  aNrDoc        NUMBER (20);
  aCodSubunit   NUMBER(20);
  aDataDoc      DATE;
  aDoc          VARCHAR2(200);
  aTipTarget   number;

BEGIN
  SELECT CodTARGETAG, Subunitatea, TipTarget
  INTO RecId, aCodSubunit, aTipTarget
  FROM TMP_TARGETAG;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (17); 
  IF Operation = 0 THEN  -- UPDATE

    -- Master TARGETAG
    UPDATE TARGETAG
    SET  (CodTARGETAG, TipDoc, Anulat, Blocat, Operat, Activ,
          DataStart, DataStop, TipTarget,
          Moneda,
          Obs, Subunitatea, UserId, DataCreare, Agent, Client, ClasaPart, TipPart, LunaStart,  AnStart, LunaEnd, AnEnd, Nrclienti
          )
       =(SELECT
            CodTARGETAG, TipDoc, Anulat, Blocat, Operat, Activ,
            DataStart, DataStop, TipTarget,
            Moneda,
            Obs, Subunitatea, UserId, DataCreare, Agent, Client, ClasaPart, TipPart, LunaStart,  AnStart, LunaEnd, AnEnd, Nrclienti
          FROM TMP_TARGETAG )
    WHERE CodTARGETAG = RecId;

    -- Detail TARGETAG1
    DELETE FROM TARGETAG1 C1
    WHERE C1.CodTARGETAG = RecID
      AND NOT EXISTS (SELECT 1 FROM TMP_TARGETAG1 TC1 WHERE TC1.CodTARGETAG1 = C1.CodTARGETAG1);

    FOR v_rec IN (
      SELECT CodTARGETAG1, CodTARGETAG, CodObiect, CodClasa, CodClasaS, UmSec, Cant * decode(Nvl(Paritate,1),0,1,Nvl(Paritate,1)) Cant, Valoare, Masa, Volum, Obs,
			       CantMin, CantMax
      FROM TMP_TARGETAG1)
    LOOP
      IF nvl(v_rec.CodTARGETAG1,0) &gt; 0 THEN
        UPDATE TARGETAG1
        SET    CodObiect      = v_rec.CodObiect,
               CodClasa       = v_rec.CodClasa,
							 CodClasaS      = v_rec.CodClasaS,
               UMSec          = v_rec.UMSec,
               Cant           = v_rec.Cant,
               Valoare        = v_rec.Valoare,
               Masa           = v_rec.Masa,
               Volum          = v_rec.Volum,
               Obs            = v_rec.Obs,
               CantMin        = v_rec.CantMin,
               CantMax        = v_rec.CantMax
        WHERE  CodTARGETAG1 = v_rec.CodTARGETAG1;

      ELSE
        SELECT seq_TARGETAG1_CodTARGETAG1.NEXTVAL INTO vCod FROM dual;
        PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TARGETAG1&apos;, vCod, v_rec.CodTARGETAG1);
        INSERT INTO  TARGETAG1 (
          CodTARGETAG1, CodTARGETAG, CodObiect, CodClasa, CodClasaS, UMSec, Cant, Valoare, Masa, Volum,
          Obs, CantMin, CantMax)
        VALUES (
          vCod , RecId, v_rec.CodObiect, v_rec.CodClasa, v_rec.CodClasaS, v_rec.UMSec, v_rec.Cant, v_rec.Valoare, v_rec.Masa, v_rec.Volum,
          v_rec.Obs, v_rec.CantMin, v_rec.CantMax);
      END IF;

    END LOOP;

  ELSE  -- INSERT
    -- Master TARGETAG
    SELECT seq_TARGETAG_CodTARGETAG.NextVal INTO RecId FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TARGETAG&apos;, RecId);
    INSERT INTO  TARGETAG (
      CodTARGETAG, TipDoc, Anulat, Blocat, Operat, Activ,
      DataStart, DataStop, TipTarget,
      Moneda,
      Obs, Subunitatea, An, Luna, UserId, DataCreare, Agent, Client, ClasaPart, TipPart, LunaStart,  AnStart, LunaEnd, AnEnd, Nrclienti)
    SELECT
      RecId, TipDoc, Anulat, Blocat, Operat, Activ,
      DataStart, DataStop, TipTarget,
      Moneda,
      Obs, Subunitatea, An, Luna, UserId, DataCreare, Agent, Client, ClasaPart, TipPart, LunaStart,  AnStart, LunaEnd, AnEnd, Nrclienti
    FROM TMP_TARGETAG;

    -- Detail TARGETAG1
    SELECT COUNT(1) INTO vRecNo FROM TMP_TARGETAG1;

    FOR v_rec IN (
      SELECT CodTARGETAG1, CodTARGETAG, CodObiect, CodClasa, CodClasaS, UmSec, Cant * decode(Nvl(Paritate,1),0,1,Nvl(Paritate,1)) Cant, Valoare, Masa, Volum, Obs, CantMin, CantMax
      FROM TMP_TARGETAG1)
    LOOP
      SELECT seq_TARGETAG1_CodTARGETAG1.NEXTVAL INTO vCod FROM dual;
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TARGETAG1&apos;, vCod, v_rec.CodTARGETAG1);
      INSERT INTO  TARGETAG1 (
        CodTARGETAG1, CodTARGETAG, CodObiect, CodClasa, CodClasaS, UMSec, Cant, Valoare, Masa, Volum, Obs, CantMin, CantMax)
      VALUES (
        vCod , RecId, v_rec.CodObiect, v_rec.CodClasa, v_rec.CodClasaS, v_rec.UMSec, v_rec.Cant, v_rec.Valoare, v_rec.Masa, v_rec.Volum, v_rec.Obs, v_rec.CantMin, v_rec.CantMax);

    END LOOP;

  END IF;

  NotifyModif(Operation, RecId, &apos;TARGETAG&apos;);
  PKG_CFGTABLES.EXT_POSTRECORDS(17);
  COMMIT;

END;

FUNCTION  LIMITE_INTERVAL( aCODSubunit IN NUMBER, aCODTARGETAG IN NUMBER, aAGENT IN NUMBER, aCLIENT IN NUMBER, 
	                         aClasaPart IN NUMBER, aDATASTART IN OUT VARCHAR2, aDATASTOP IN OUT VARCHAR2, 
													 aTipTarget IN NUMBER) RETURN NUMBER
IS
--pragma autonomous_transaction;
  Suprapus  NUMBER(1);
  DStart      DATE;
  DStop       DATE;
BEGIN
  Suprapus  := 0;
  FOR v_rec IN (
    SELECT
      DATASTART, DATASTOP
     FROM
      TargetAG
     WHERE
       (CODTargetAG  &lt;&gt; aCODTargetAG)   AND
       (Nvl(AGENT, 0) =  aAGENT)        AND
       (Nvl(CLIENT, 0)=  aCLIENT)       AND
       (Nvl(ClasaPart, 0)=  aCLASAPART) AND
       (Nvl(TipTarget, 0)=  aTipTarget) AND
       (SUBUNITATEA   = aCODSubunit)    AND
       (NVL(ANULAT, 0) = 0)             AND
       (NVL(OPERAT, 0) = 1)             AND
       (NVL(ACTIV,  0) = 1)
    ORDER BY DATASTART
    )
  LOOP
--    Insert into X(SQL) values (aCODTARGETAG || &apos;*&apos; ||  aAGENT || &apos;*&apos; || aDATASTART  || &apos;*&apos; ||  aDATASTOP);
--    commit;
    DStart := To_Date(aDATASTART, &apos;dd.mm.yyyy&apos;);
    DStop  := To_Date(aDATASTOP, &apos;dd.mm.yyyy&apos;);
    IF DStart BETWEEN v_rec.datastart AND v_rec.datastop THEN
      SUPRAPUS := 1;
      aDATASTART := To_Char(v_rec.datastop + 1, &apos;dd.mm.yyyy&apos;);
    END IF;
    IF DStop BETWEEN v_rec.datastart AND v_rec.datastop THEN
      SUPRAPUS := 1;
      aDATASTOP := To_Char(v_rec.datastart - 1, &apos;dd.mm.yyyy&apos;);
    END IF;
    if SUPRAPUS = 0 THEN
      IF v_rec.datastart BETWEEN  DSTART AND DSTOP THEN
        SUPRAPUS := 1;
        aDATASTART := To_Char(v_rec.datastop + 1, &apos;dd.mm.yyyy&apos;);
      END IF;
      IF v_rec.datastop BETWEEN  DSTART AND DSTOP THEN
        SUPRAPUS := 1;
        aDATASTOP := To_Char(v_rec.datastart - 1, &apos;dd.mm.yyyy&apos;);
      END IF;
    END IF;

  END LOOP;

  RETURN Suprapus;
END;

END PKG_TARGETAG;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AF0CEDF22B0C71E38501D04F2D592060FF557BC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY &quot;PKG_TARI&quot; IS


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codtara INTO Tmp FROM NTARI WHERE codtara = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM NTARI WHERE codtara = RecId ;
  NotifyModif(2, RecId, &apos;NTARI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NTARI FIELDS( codtara ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NTARI
  INSERT INTO  TMP_NTARI ( codtara,den_tara,simbauto,codmoneda,obs, STATCOMUNITAR, CodLimba )
    ( SELECT codtara,den_tara,simbauto,codmoneda,obs, STATCOMUNITAR, CodLimba
      FROM NTARI WHERE codtara = RecId ) ;

  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

-- Master NTARI
    SELECT  codtara INTO RecId FROM TMP_NTARI;
    UPDATE NTARI SET ( den_tara,simbauto,codmoneda,obs, STATCOMUNITAR, CodLimba )
       = ( SELECT den_tara,simbauto,codmoneda,obs, STATCOMUNITAR, CodLimba
          FROM TMP_NTARI )
      WHERE codtara = RecId ;

  ELSE  -- INSERT
-- Master NTARI
  SELECT seq_NTARI_codtara.NextVal INTO RecId FROM DUAL;
  INSERT INTO  NTARI ( codtara,den_tara,simbauto,codmoneda,obs,STATCOMUNITAR, CodLimba )
 ( SELECT  RecId ,den_tara,simbauto,codmoneda,obs, STATCOMUNITAR, CodLimba
     FROM TMP_NTARI  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;NTARI&apos;);
  COMMIT;
END;



END pkg_Tari; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TARIFEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A717E6815D0FCAB50C82D72978BF38C291A3584</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TARIFEMAN IS

gOwner  varchar2(50);

PROCEDURE SET_VARIABILE(aOwner in varchar2) is
begin
 gOwner  := aOwner ; 
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20);
BEGIN
  select CodTarif into tmp from tarifeman where codtarif = recid for update nowait;  
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
 delete from tarifeman1 where codtarif = RecId;
 delete from tarifeman where codtarif = RecId;
 NotifyModif(2, RecId, &apos;tarifeman&apos;);
 COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
 INSERT INTO TMP_TarifeMan (CodTarif) VALUES (0);
 COMMIT;
END;

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
  aANSFARSIT NUMBER(18);
  aLUNASFARSIT NUMBER(18);
BEGIN
  insert into tmp_tarifeman(Codtarif, Denumire, CodExtern, CodMoneda)
         (select Codtarif, Denumire, CodExtern, coalesce(CodMoneda,0) from tarifeman where Codtarif = RecId);

  insert into tmp_tarifeman1
	(codtarif1, codtarif, 
	 Tarif, 
	 Tarif1,
	 Tarif2,
	 Tarif3,
	 Tarif4,
	 Tarif5,
	 Tarif6,
	 Tarif7,
	 Tarif8,
	 Tarif9,
	 anstart, lunastart)
  select
    T1.Codtarif1,
    T1.Codtarif,
    T1.Tarif,
		T1.Tarif1,
    T1.Tarif2,
    T1.Tarif3,
    T1.Tarif4,
    T1.Tarif5,
    T1.Tarif6,
    T1.Tarif7,
    T1.Tarif8,
    T1.Tarif9,
    T1.AnStart,
    T1.LunaStart
  from tarifeman1 T1 where Codtarif = RecId;

  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CodTarif1, Anstart, LUNAstart FROM TMP_tarifeman1 ORDER BY ANstart * 12 + LUNAstart DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN 
      UPDATE TMP_TARIFEMAN1
      SET
        ANSfarsit   = aANSFARSIT,
        LUNASfarsit  = aLUNASFARSIT
      WHERE
      CodTarif1 = V_REC.CodTarif1;
    END IF;

    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANStart, V_REC.LUNAStart, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
  
  commit;  
 END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  if Operation = 0 then
    select codtarif into recid from tmp_tarifeman;
    
    UPDATE TarifeMan SET (Denumire, CodExtern, CodMoneda) = (SELECT Denumire, CodExtern, CodMoneda FROM TMP_TarifeMan)
    WHERE codtarif = RecId;
      
    delete from tarifeman1 where codtarif = recid and codtarif1 not in (select codtarif1 from tmp_tarifeman1);
    
    for v_rec in (select * from tmp_tarifeman1) loop
      if v_rec.codtarif1 &gt; 0 then
        update tarifeman1 
        set
          tarif  = v_rec.tarif,
          tarif1 = v_rec.tarif1,
          tarif2 = v_rec.tarif2,
          tarif3 = v_rec.tarif3,
          tarif4 = v_rec.tarif4,
          tarif5 = v_rec.tarif5,
          tarif6 = v_rec.tarif6,
          tarif7 = v_rec.tarif7,
          tarif8 = v_rec.tarif8,
          tarif9 = v_rec.tarif9
        where codtarif1 = v_rec.codtarif1;  
      else
        insert into tarifeman1 (codtarif1, codtarif, 
				 Tarif, 
				 Tarif1,
				 Tarif2,
				 Tarif3,
				 Tarif4,
				 Tarif5,
				 Tarif6,
				 Tarif7,
				 Tarif8,
				 Tarif9,
			   AnStart, LunaStart)
        values (seq_tarifeman1_codtarif1.nextval, RecId, 
				 v_rec.tarif, 
				 v_rec.Tarif1,
				 v_rec.Tarif2,
				 v_rec.Tarif3,
				 v_rec.Tarif4,
				 v_rec.Tarif5,
				 v_rec.Tarif6,
				 v_rec.Tarif7,
				 v_rec.Tarif8,
				 v_rec.Tarif9,
				 v_rec.AnStart, v_Rec.LunaStart);
      end if;
    end loop;
  else
    select seq_tarifeman_codtarif.nextval into RecId from dual;
    
    insert into tarifeman (codtarif, Denumire, CodExtern, CodMoneda) 
    Select RecId, Denumire, CodExtern, CodMoneda from tmp_tarifeman;
    
    insert into tarifeman1 
	(codtarif1, codtarif, 
	 Tarif, 
	 Tarif1,
	 Tarif2,
	 Tarif3,
	 Tarif4,
	 Tarif5,
	 Tarif6,
	 Tarif7,
	 Tarif8,
	 Tarif9,
	 anstart, lunastart)
  select seq_tarifeman1_codtarif1.nextval, RecId, 
    Tarif,
		Tarif1,
    Tarif2,
    Tarif3,
    Tarif4,
    Tarif5,
    Tarif6,
    Tarif7,
    Tarif8,
    Tarif9,
    AnStart,
    LunaStart
    from tmp_tarifeman1;
  end if;
  
  PRC_AL_REFRESH(&apos;TARIFEMAN1&apos;, RecId);
  NotifyModif(Operation, RecId, &apos;tarifeman&apos;);
  commit;     
END;

end pkg_tarifeman; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TAXE_ACCIZE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F79CC26F6CD27B557658C521E0BD6C4EFAEC1F32</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TAXE_ACCIZE IS

PROCEDURE PREGATESTE_TEMPORAR_ACCIZE(aTip in number)
IS
semn integer;

BEGIN
    DELETE TMP_TAXE_ACCIZE;
    INSERT INTO TMP_TAXE_ACCIZE
    (
    CODOBIECT  ,
    CODSERVFACT,
    VALOARE    ,
    CODTAXA    ,
    LACEAPLIC  ,
    MASA       ,
    VOLUM      ,
    CANT       ,
    PRET       ,
    BAZAMAX    ,
    BAZAMIN    ,
    PROC,
    CODLINIE,
    ROTVALOARE
    )

    SELECT *
    FROM
    (
       (
        SELECT
          INFOOBIECT.CODOBIECT,
          TAXELUNA.CODSERVFACT,
          TAXELUNA.VALOARE,
          TAXELUNA.CODTAXA,
          TAXELUNA.LACEAPLIC,
          INFOOBIECT.MASA,
          INFOOBIECT.VOLUM,
          INFOOBIECT.CANT,
          INFOOBIECT.PRET,
          TAXELUNA.BazaMax,
          TAXELUNA.BazaMin,
          0 AS PROC,
          INFOOBIECT.CODLINIE,
          TAXELUNA.ROTVALOARE
        FROM
        (
          SELECT
            O.CODOBIECT,
            NART1LUNA.CODACCIZE,
            NART1LUNA.CODTAXA1,
            NART1LUNA.CODTAXA2,
            NVL(O.MASA, 0) AS MASA,
            NVL(O.VOLUM, 0) AS VOLUM,
            O_F.CANT,
            O_F.PRET,
            O_F.CODLINIE 
          FROM
           TMP_OBIECTE_FACTURATE O_F,
           NARTOBJ O
           LEFT OUTER JOIN
           TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
           O.CODOBIECT = O_F.CODOBIECT
        ) INFOOBIECT,
        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
          FROM NTAXE1 T1
          WHERE PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALSTART AND T1.ALSTOP
            AND T1.FACTURABIL = 1 AND Coalesce(T1.CODSERVFACT, 0) &lt;&gt; 0
            AND ((aTip = 1 and Coalesce(T1.JAchiz, 0)=1)or(aTip &gt;= 2 and Coalesce(T1.JVanz, 1)=1))
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODACCIZE = TAXELUNA.CODTAXA
       )
       UNION ALL
       (
        SELECT
          INFOOBIECT.CODOBIECT,
          TAXELUNA.CODSERVFACT,
          TAXELUNA.VALOARE,
          TAXELUNA.CODTAXA,
          TAXELUNA.LACEAPLIC,
          INFOOBIECT.MASA,
          INFOOBIECT.VOLUM,
          INFOOBIECT.CANT,
          INFOOBIECT.PRET,
          TAXELUNA.BazaMax,
          TAXELUNA.BazaMin,
          0 AS PROC,
          INFOOBIECT.CODLINIE,        
          TAXELUNA.ROTVALOARE
        FROM
        (
          SELECT
            O.CODOBIECT,
            NART1LUNA.CODACCIZE,
            NART1LUNA.CODTAXA1,
            NART1LUNA.CODTAXA2,
            NVL(O.MASA, 0) AS MASA,
            NVL(O.VOLUM, 0) AS VOLUM,
            O_F.CANT,
            O_F.PRET,
            O_F.CODLINIE
          FROM
           TMP_OBIECTE_FACTURATE O_F,
           NARTOBJ O
           LEFT OUTER JOIN
           TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
           O.CODOBIECT = O_F.CODOBIECT
        ) INFOOBIECT,
        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
          FROM NTAXE1 T1
          WHERE PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALSTART AND T1.ALSTOP
            AND T1.FACTURABIL = 1 AND Coalesce(T1.CODSERVFACT, 0) &lt;&gt; 0
            AND ((aTip = 1 and Coalesce(T1.JAchiz, 0)=1)or(aTip &gt;= 2 and Coalesce(T1.JVanz, 1)=1))
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODTAXA1 = TAXELUNA.CODTAXA
       )
       UNION ALL
       (
        SELECT
          INFOOBIECT.CODOBIECT,
          TAXELUNA.CODSERVFACT,
          TAXELUNA.VALOARE,
          TAXELUNA.CODTAXA,
          TAXELUNA.LACEAPLIC,
          INFOOBIECT.MASA,
          INFOOBIECT.VOLUM,
          INFOOBIECT.CANT,
          INFOOBIECT.PRET,
          TAXELUNA.BazaMax,
          TAXELUNA.BazaMin,
          0 AS PROC,
          INFOOBIECT.CODLINIE,
          TAXELUNA.ROTVALOARE
        FROM
        (
          SELECT
            O.CODOBIECT,
            NART1LUNA.CODACCIZE,
            NART1LUNA.CODTAXA1,
            NART1LUNA.CODTAXA2,
            NVL(O.MASA, 0) AS MASA,
            NVL(O.VOLUM, 0) AS VOLUM,
            O_F.CANT,
            O_F.PRET,
            O_F.CODLINIE
          FROM
           TMP_OBIECTE_FACTURATE O_F,
           NARTOBJ O
           LEFT OUTER JOIN
           TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
           O.CODOBIECT = O_F.CODOBIECT
        ) INFOOBIECT,
        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, BazaMax, BazaMin, ROTVALOARE
          FROM NTAXE1 T1
          WHERE PKG_GLOBALS.ANLUNALUCRU BETWEEN T1.ALSTART AND T1.ALSTOP
            AND T1.FACTURABIL = 1 AND Coalesce(T1.CODSERVFACT, 0) &lt;&gt; 0
            AND ((aTip = 1 and Coalesce(T1.JAchiz, 0)=1)or(aTip &gt;= 2 and Coalesce(T1.JVanz, 1)=1))
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODTAXA2 = TAXELUNA.CODTAXA
       )
    );

--aTip=1 intrari; aTip=2 Iesiri
  if aTip = 1 then Semn := -1; else Semn := 1; end if;
  update TMP_TAXE_ACCIZE SET PROC = Semn*Round(Pret * VALOARE/(100 +  VALOARE),2) WHERE LACEAPLIC = 1;
  update TMP_TAXE_ACCIZE SET PROC = Semn*Round(Pret * VALOARE/100 , 2) WHERE LACEAPLIC = 2;

END;

end PKG_TAXE_ACCIZE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TEME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C821EC40B2E4BD9ED1D3AAAAE6DE34984CAE40F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TEME IS


  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
  BEGIN
  SELECT CodTEMA INTO Tmp FROM TEME WHERE CodTEMA = RecId FOR UPDATE NOWAIT;
  END;


  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM TEME WHERE CodTEMA = RecId ;
  NotifyModif(2, RecId, &apos;TEME&apos;);
  COMMIT;
  END;

  PROCEDURE SP_INSERTRECORD IS
  BEGIN
  INSERT INTO  TMP_TEME FIELDS( CodTEMA ) VALUES (0) ;
  COMMIT;
  END;

  PROCEDURE TEME_GETPERS IS
	begin
    INSERT INTO TMP_NPERSCURS0
		( CODPERS ,
			NUME    ,
			PRENUME ,
			FORMATIE,
			FUNCTIE ,
			MESERIE ,
			SCHIMB  ,
			DataAngajarii,
			DataPlecarii,
			Plecat,
			ACTIV,
			SELECTAT
		)
    select
		  CODPERS ,
			NUME    ,
			PRENUME ,
			FORMATIE,
			FUNCTIE ,
			MESERIE ,
			SCHIMB  ,
			DataAngajarii, DataPlecarii,
      case when LuniRamase &lt;0 then 1 else 0 end,
			ACTIV,
			SELECTAT
		from
		(Select P.CodPers, P.Nume, P.Prenume, C.Den_Formatie formatie, F.DENUMIRE functie, M.DEN_MESERIE meserie, P1.Schimb, p.DataAngajarii, p.DataPlecarii,
    Extract (YEAR from NVL(DataPlecarii, Sysdate)) *12 + Extract (MONTH from NVL(DataPlecarii, sysdate)) - PKG_GLOBALS.AnLunaLucru LuniRamase, nvl(p.ACTIV,1) Activ,
		0 selectat
		from NPers P
		     inner join NPERS1 P1 on P1.CodPers = P.CodPers AND PKG_GLOBALS.ANLUNALUCRU BETWEEN P1.ALSTART AND p1.ALSTOP
		     left join Formatii C on C.CodFormatie = P1.CodFormatie
		     left join Functii F on F.CodFunctie = P1.CodFunctie
		     left join NMESERII M on M.CodMeserie = P1.CodMeserie
		where (nvl(p.ACTIV,1) = 1) or  (p.ACTIV=0 and Extract (YEAR from DataPlecarii) *12 + Extract (MONTH from DataPlecarii)  &gt;= PKG_GLOBALS.AnLunaLucru ))
	  where LuniRamase &gt;=-1;
		Commit;
	end;

  PROCEDURE TEME_GOTORECORD IS
  BEGIN
		INSERT INTO TMP_NPERSCURS
		( CODNPERSCURS,
			CODPERS     ,
			CODFUNCTIE  ,
			CODCURS     ,
			CODTEMA     ,
			STARE       ,
			DATA        ,
			NOTA        ,
			DATAPLAN    ,
			ORE_REALIZ  ,
			SUPLIM      ,
			DEN_CURS    ,
			DEN_TEMA    ,
			SSTARE      ,
			ORE_AFER    ,
			Nume        ,
			Prenume     ,
      Activ, DataPlecarii, DataAngajarii, Plecat, TipFormare, NivelFormare, CodObiectiv, Den_Obiectiv,
			Sel
			)
    with CF as
          (
            Select distinct P1.CodPers, F1.CodCurs, F1.CodTema, x.Activ, x.DataPlecarii, x.DataAngajarii, x.Plecat, 0 Suplim
            from NPERS1 P1
                inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie
								inner join ( select CodPers, Activ, DataPlecarii, DataAngajarii, Plecat
								             from TMP_NPERSCURS0
														 where Selectat = 1) X on X.CodPers = P1.CodPers),
         PC as
          (Select NP.CodPers, NP.CODNPERSCURS, Nvl(NP.codfunctie,0) codfunctie,  NP.CodCurs, NP.CodTema,
                  Nvl(NP.STARE,0) Stare, Case when Nvl(NP.codfunctie,0) = 0 then 1 else 0 end Suplim ,
                  NP.Nota,
                  NP.Data,
                  NP.DataPlan, NP.TipFormare, NP.NivelFormare, NP.CodObiectiv,
									NP.ORE_REALIZ, x.Activ, x.DataPlecarii, x.DataAngajarii, x.Plecat
           from NPERSCURS NP
								inner join ( select CodPers, Activ, DataPlecarii, DataAngajarii, Plecat
								             from TMP_NPERSCURS0
														 where Selectat = 1) X on X.CodPers = NP.CodPers)
    Select TMP.CODNPERSCURS, TMP.CODPERS, TMP.CodFunctie, TMP.CODCURS, TMP.CODTEMA, TMP.STARE, TMP.DATA, TMP.NOTA, TMP.DATAPLAN, TMP.ORE_REALIZ, TMP.Suplim,
           CC.DEN_CURS, TT.DEN_TEMA,
           &apos;xxxxxxxxxx&apos;, TT.ORE, P.Nume, P.Prenume, TMP.Activ, TMP.DataPlecarii, TMP.DataAngajarii, TMP.Plecat, TMP.TipFormare, TMP.NivelFormare, TMP.CodObiectiv, O.Den_Obiectiv, 0 sel
    from
    (
    Select PC.CODNPERSCURS,
		       PC.CodPers,
    			 Nvl(PC.CodFunctie, 0) CodFunctie,
					 PC.CodCurs,
					 PC.CodTema,
					 PC.DATA,
					 PC.DATAPLAN,
					 PC.ORE_REALIZ,
					 nvl(PC.STARE,0) STARE,
					 PC.Nota,
					 PC.Activ, PC.DataPlecarii, PC.DataAngajarii, PC.Plecat, PC.Suplim, Nvl(PC.TipFormare,0) TipFormare, Nvl(PC.NivelFormare,0) NivelFormare, Nvl(PC.CodObiectiv,0) CodObiectiv
    from PC
    union all
		Select  -RowNum CODNPERSCURS,
		        CF.CODPERS,
						-1 CodFunctie,
						Nvl(CF.CodCurs, 0) CodCurs,
						Nvl(CF.CodTema, 0) CodTema,
						null Data,
						null DATAPLAN,
						0 ORE_REALIZ,
						0 STARE,
						null Nota,
						CF.Activ, CF.DataPlecarii, CF.DataAngajarii, CF.Plecat, 0 Suplim, 0 TipFormare, 0 NivelFormare, 0 CodObiectiv
    from CF
    where not Exists ( select CodNPERSCURS
		                   from NPERSCURS
											 where Nvl(CodFunctie,0) &lt;&gt; 0 and
											       CodCurs = CF.CodCurs and
														 CodTema = CF.CodTema and
														 Codpers = CF.CodPers)
		) TMP
    inner join Npers P on   P.Codpers  = TMP.CodPers
    left join CURSURI CC on CC.CodCurs = TMP.CodCurs
    left join TEME    TT on TT.CodTema = TMP.CodTEMA
    left join OBIECTIVE O on O.CodObiectiv = TMP.CodObiectiv;
--		where tmp.codtema=141;
    COMMIT;
  END;

  PROCEDURE TEME_POSTRECORD IS
  BEGIN
    for V_X in (select CodPers from TMP_NPERSCURS0 where Selectat = 1) loop
      DELETE FROM NPERSCURS where CodPers = V_X.CodPers and CodNPERSCURS IN
     ( SELECT CodNPERSCURS FROM NPERSCURS where CodPers = V_X.CodPers AND CodNPERSCURS NOT IN (SELECT CodNPERSCURS FROM TMP_NPERSCURS));


			FOR v_rec IN ( SELECT * FROM TMP_NPERSCURS WHERE Sel = 1 and CodNPERSCURS &gt; 0 and CODPERS=V_X.CodPers) LOOP
				 UPDATE NPERSCURS
				 SET
					CODCURS   = V_REC.CODCURS ,
					CODTEMA   = V_REC.CODTEMA ,
					STARE     = V_REC.STARE   ,
					NOTA      = V_REC.NOTA    ,
					DATA      = V_REC.DATA    ,
					DATAPLAN  = V_REC.DATAPLAN,
					TipFormare= V_REC.TipFormare,
					NivelFormare= V_REC.NivelFormare,
					CodObiectiv= V_REC.CodObiectiv,
					CodFunctie =
					( Select Min(P1.CodFunctie) from NPERS1 P1
						                            inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie
				    where P1.CodPers = V_X.CodPers and F1.CodTema = V_REC.CodTema and F1.CodCurs = V_REC.CodCurs)  ,
					ORE_REALIZ= V_REC.ORE_REALIZ
				 WHERE CodNPERSCURS  = v_rec.CODNPERSCURS;
			END LOOP;

			INSERT INTO NPERSCURS( CodNPERSCURS, CODPERS, CODFUNCTIE, CODCURS, CODTEMA, STARE, NOTA, DATA, DATAPLAN, TipFormare, NivelFormare, CodObiectiv, ORE_REALIZ)
			SELECT SEQ_NPERSCURS_CodNPERSCURS.Nextval ,  V_X.CodPers ,
								( Select Min(P1.CodFunctie) from NPERS1 P1
						                            inner join FUNCTII1 F1 on F1.CodFunctie = P1.Codfunctie
				    where P1.CodPers = V_X.CodPers and F1.CodTema = CodTema and F1.CodCurs = CodCurs)  ,
			CODCURS, CODTEMA, STARE, NOTA, DATA, DATAPLAN, TipFormare, NivelFormare, CodObiectiv, ORE_REALIZ
			FROM TMP_NPERSCURS WHERE CodNPERSCURS &lt; 0  and CODPERS=V_X.CodPers;
    end loop;
    COMMIT;
  END;

  PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
	BEGIN
  -- Master TEME

	INSERT INTO  TMP_TEME ( CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR)
    ( SELECT CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR
    FROM TEME WHERE CodTEMA = RecId ) ;

  INSERT INTO TMP_NPERSCURSY (CODNPERSCURS, CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN, ORE_REALIZ)
     select -RowNum, CODPERS, CODCURS, STARE, NOTA, DATA, DATAPLAN, ORE_REALIZ
     from
        (Select NP.CodPers, NP.CodCurs,
               Nvl(NP.STARE,0) Stare,
               NP.Nota nota,
               NP.Data,
               NP.DataPlan,
               NP.ORE_REALIZ
        from NPERSCURS NP where NP.CodTema = RecID);

  COMMIT;
  END;


  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aCurs number(20);
	aIndexLocal number(20);
  BEGIN
  IF Operation = 0 THEN  -- UPDATE
  -- Master TEME
    SELECT CodTEMA INTO RecId FROM TMP_TEME;

    UPDATE TEME
    SET ( den_TEMA, ORE, PRET, CodFORMATOR )
    = ( SELECT den_TEMA, ORE, PRET, CodFORMATOR FROM TMP_TEME )
    WHERE CodTEMA = RecId ;

  ELSE  -- INSERT
  -- Master TEME
    SELECT SEQ_TEME_CodTEMA.NextVal INTO RecId FROM DUAL;

    INSERT INTO  TEME ( CodTEMA, den_TEMA, ORE, PRET, CodFORMATOR )
              ( SELECT  RecId ,den_TEMA, ORE, PRET, CodFORMATOR
                FROM TMP_TEME  ) ;
		select nvl(CodCurs,0) into aCurs from TMP_TEME;
		if aCurs &lt;&gt; 0 then
		  Select Count(*) into aIndexLocal from Cursuri1 where CodCurs = aCurs;
			INSERT INTO CURSURI1
			( CodCurs1, CodCurs, IndexLocal, CodTema)
			VALUES (SEQ_CURSURI1_CodCurs1.Nextval , aCurs, aIndexLocal + 1, RecId);
		end if;
  END IF;
  NotifyModif(Operation, RecId, &apos;TEME&apos;);
  COMMIT;

END;



END PKG_TEME;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TESATURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99D78D1FD89736BFE18D720689F4D805E00E381B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TESATURI is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodTESATURA INTO Tmp FROM TESATURI WHERE CodTESATURA = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM TESATURI WHERE CodTESATURA = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_TESATURI FIELDS( CodTESATURA ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_TESATURI 
	(  CODTESATURA   ,                         
     DENUMIRE       ,                        
     COMPOZITIE      ,                       
     MASASPECIFICA   ,                       
     LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE      
		)
	SELECT 
     CODTESATURA   ,                         
     DENUMIRE       ,                        
     COMPOZITIE      ,                       
     MASASPECIFICA   ,                       
     LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE      
  FROM TESATURI WHERE CodTESATURA = RECID;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodTESATURA INTO RECID FROM TMP_TESATURI;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE TESATURI
    SET
     (
     DENUMIRE       ,                        
     COMPOZITIE      ,                       
     MASASPECIFICA   ,                       
     LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE      
			)
			= 
			(SELECT 
     DENUMIRE       ,                        
     COMPOZITIE      ,                       
     MASASPECIFICA   ,                       
     LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE      
			FROM TMP_TESATURI)
    WHERE
      CodTESATURA = RECID;

ELSE  -- INSERT
    SELECT SEQ_TESATURI_CODTESATURA.NextVal INTO RecId FROM DUAL;
    INSERT INTO TESATURI(
      CODTESATURA   ,                         
     DENUMIRE       ,                        
     COMPOZITIE      ,                       
     MASASPECIFICA   ,                       
     LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE     ) 
    SELECT 
  		RECID   , 
      DENUMIRE       ,                        
      COMPOZITIE      ,                       
      MASASPECIFICA   ,                       
      LEGATURA       ,                        
     DESIMEU,
     DESIMEB,
     CATEGORIE      
		FROM TMP_TESATURI;   

  END IF; 

  NotifyModif(Operation, RecId, &apos;TESATURI&apos;);
  COMMIT;
 
END;


end PKG_TESATURI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TIPCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F41079AC36B4CD8E1B09F69C9296B134D0560E50</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TIPCHELT IS


 PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
 TMP NUMBER(20);
  BEGIN
    SELECT CODTIPCHELT INTO TMP FROM TIPCHELT WHERE CODTIPCHELT = RECID FOR UPDATE NOWAIT;
  END;
   
  PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
   
  BEGIN
   DELETE FROM TIPCHELT WHERE CODTIPCHELT = RECID;
   NotifyModif(2, RecId, &apos;TIPCHELT&apos;);
   COMMIT;
  END;
  
  PROCEDURE SP_INSERTRECORD IS
  BEGIN
   INSERT INTO TMP_TIPCHELT(CODTIPCHELT) VALUES (0);
   COMMIT;
  END;
  
  PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS 
  BEGIN
   INSERT INTO TMP_TIPCHELT(CODTIPCHELT,DENUMIRE,CODCONT) 
     SELECT CODTIPCHELT,DENUMIRE,CODCONT FROM TIPCHELT WHERE CODTIPCHELT = RECID;
   COMMIT;  
  END;
  
  PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  BEGIN
   IF OPERATION = 0 THEN
     SELECT CODTIPCHELT INTO RECID FROM TMP_TIPCHELT;
       UPDATE TIPCHELT SET (DENUMIRE,CODCONT) = (SELECT DENUMIRE,CODCONT FROM TMP_TIPCHELT)
       WHERE CODTIPCHELT = RECID;
   ELSE
     SELECT SEQ_TIPCHELT_CODTIPCHELT.NEXTVAL INTO RECID FROM DUAL;
     
     INSERT INTO TIPCHELT(CODTIPCHELT,DENUMIRE,CODCONT)
     SELECT RECID , DENUMIRE, CODCONT FROM TMP_TIPCHELT;
   END IF;
   NotifyModif(Operation, RecId, &apos;TIPCHELT&apos;);
   COMMIT;
  END;
  
end pkg_tipChelt; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TIPLUCRARISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74AC2CC5F47559069F47201747F1B5DE51264D8D</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TipLucrariSA IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodTipLucrare INTO Tmp FROM TIPLUCRARISA WHERE CodTipLucrare = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM TIPLUCRARISA  WHERE CodTipLucrare = RecId ;
  DELETE FROM TIPLUCRARISA1   WHERE CodTipLucrare = RecId ;
  NotifyModif(2, RECID, &apos;TIPLUCRARISA&apos;);  
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_TIPLUCRARISA FIELDS( CodTipLucrare ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
n number;
BEGIN
  INSERT INTO  TMP_TIPLUCRARISA ( CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE)
    ( SELECT CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE
      FROM TIPLUCRARISA WHERE CodTipLucrare = RecId ) ;



-- TMP_TIPLUCRARISA1
INSERT INTO TMP_TIPLUCRARISA1 (CodTipLucrare1, CodTipLucrare, CodPers, nume, prenume, obs)
    (SELECT T.CodTipLucrare1, T.CodTipLucrare, T.CodPers, P.nume, P.prenume,P.obs 
     FROM TIPLUCRARISA1 T 
     INNER JOIN NPERS P on P.Codpers = T.Codpers 
     WHERE CodTipLucrare = RECID);     
  
  COMMIT;    
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
Cod number(20);
n number(20);

BEGIN
  IF Operation = 0 THEN  -- UPDATE
--!!!!!!!!!!
    SELECT CodTipLucrare INTO RECID FROM TMP_TIPLUCRARISA;
--!!!!!!!!!!
    UPDATE TIPLUCRARISA SET ( Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE )
       = ( SELECT Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE
          FROM TMP_TIPLUCRARISA )
      WHERE CodTipLucrare = RecId ;


    DELETE FROM TIPLUCRARISA1 
		where CODTIPLUCRARE = RecID 
		and CodTIPLUCRARE1 not in (Select CODTIPLUCRARE1 from TMP_TIPLUCRARISA1);
	
		for v_rec in (select * from TMP_TIPLUCRARISA1) loop
      if V_Rec.CodTIPLUCRARE1 &lt; 0 then 
				INSERT INTO TIPLUCRARISA1
					( 
					  CODTIPLUCRARE1,
            CODTIPLUCRARE,      
            CODPERS         
					)
					Values 
					( SEQ_TIPLUCRARISA1_CODTIPLUCR1.Nextval,
						RecId ,
						V_REC.CODPERS );
	    else 
				UPDATE TIPLUCRARISA1
				SET 
					CODPERS = V_REC.CODPERS
				WHERE CODTIPLUCRARE1  = v_rec.CODTIPLUCRARE1;
	    end if;
	  end loop;

    
  ELSE  -- INSERT
    SELECT SEQ_TIPLUCRARISA_CODTIPLUCRARE.NextVal INTO RecId FROM DUAL;
    INSERT INTO TIPLUCRARISA ( CodTipLucrare, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE)
    ( SELECT  RecId, Denumire, ArtServFact, ClasaLucrari, Toti, CodGest,CODINTERVENTIE
      FROM TMP_TIPLUCRARISA ) ;

     -- DETAIL PersCalif
   INSERT INTO TIPLUCRARISA1 (CodTipLucrare1, CodTipLucrare, CodPers)
        (SELECT SEQ_TIPLUCRARISA1_CODTIPLUCR1.NEXTVAL, RECID,CodPers FROM TMP_TIPLUCRARISA1);
  END IF;
  NotifyModif(OPERATION, RECID, &apos;TIPLUCRARISA&apos;);  

  COMMIT;
END;
  
end PKG_TipLucrariSA; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TIPPARTINCERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB7BD270F3BF10FB02B812B94C70331B2A29F817</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TIPPARTINCERT is



PROCEDURE SP_LOCKRECORD(RecId IN NUMBER) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODTIPPARTINCERT INTO Tmp FROM TIPPARTINCERT WHERE CODTIPPARTINCERT = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD(RecId IN NUMBER) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM TIPPARTINCERT WHERE CODTIPPARTINCERT = RecId;
  NotifyModif(2, RecId, &apos;TIPPARTINCERT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_TIPPARTINCERT FIELDS(CODTIPPARTINCERT) VALUES (0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD(RecId IN NUMBER) IS
BEGIN
  INSERT INTO TMP_TIPPARTINCERT
  (SELECT * FROM TIPPARTINCERT WHERE CodTIPPARTINCERT = RecId);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER) IS
BEGIN
  IF Operation = 0 THEN -- UPDATE
    SELECT CodTIPPARTINCERT INTO RecId FROM TMP_TIPPARTINCERT;
    UPDATE TIPPARTINCERT
    SET 
      (TIPCLIENT, TIPIMPOZITARE) = (SELECT TIPCLIENT, TIPIMPOZITARE FROM TMP_TIPPARTINCERT)
    WHERE 
      CODTIPPARTINCERT = RecId;
  ELSE  -- INSERT
    SELECT SEQ_TIPPARTINCERT_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO TIPPARTINCERT (CODTIPPARTINCERT, TIPCLIENT, TIPIMPOZITARE)
    (SELECT RecId, TIPCLIENT, TIPIMPOZITARE FROM TMP_TIPPARTINCERT);
  END IF;
  NotifyModif(Operation, RecId, &apos;TIPPARTINCERT&apos;);
  COMMIT;
END;

end PKG_TIPPARTINCERT;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TIPSEDII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B24F05DF5E6B2C597E4190D5DF7A8D59AA9991A5</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TIPSEDII IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODTIPSEDIU INTO Tmp FROM NTIPSEDII WHERE CODTIPSEDIU = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM NTIPSEDII1 WHERE CODTIPSEDIU = RecId ;
	DELETE FROM NTIPSEDII WHERE CODTIPSEDIU = RecId ;
  NotifyModif(2, RecId, &apos;NTIPSEDII&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NTIPSEDII FIELDS( CODTIPSEDIU, ICLASA ) VALUES (0, 0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_NTIPSEDII (CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR )
  SELECT CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR
  FROM NTIPSEDII
  WHERE CODTIPSEDIU = RecId;

  INSERT INTO  TMP_NTIPSEDII1 (CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT, DENCLASEA, DENOBIECT )
  SELECT N1.CODTIPSEDIU1, N1.CODTIPSEDIU, N1.CODCLASEA, N1.CODOBIECT, A.simbol, O.DENUMIRE
  FROM NTIPSEDII1 N1
    LEFT JOIN NCLASEA A ON N1.CodClasea  = A.CODCLASEA
    LEFT JOIN NARTOBJ O ON N1.CodObiect =  O.CODOBIECT
  WHERE N1.CODTIPSEDIU = RecId AND NVL(N1.CODCLASEA, 0) &lt;&gt; 0;

  INSERT INTO  TMP_NTIPSEDII2 (CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT, DENCLASEA, DENOBIECT )
  SELECT N1.CODTIPSEDIU1, N1.CODTIPSEDIU, N1.CODCLASEA, N1.CODOBIECT, A.simbol, O.DENUMIRE
  FROM NTIPSEDII1 N1
    LEFT JOIN NCLASEA A ON N1.CodClasea  = A.CODCLASEA
    LEFT JOIN NARTOBJ O ON N1.CodObiect =  O.CODOBIECT
  WHERE N1.CODTIPSEDIU = RecId AND NVL(N1.CODOBIECT, 0) &lt;&gt; 0;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    select CODTIPSEDIU into RecId from TMP_NTIPSEDII;
		UPDATE NTIPSEDII SET (DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR) = ( SELECT DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR FROM TMP_NTIPSEDII )
    WHERE CODTIPSEDIU = RecId ;

    DELETE FROM NTIPSEDII1
		WHERE CodTipSediu = RecId
  		AND CodTipSediu1 NOT IN (SELECT CodTipSediu1 FROM TMP_NTIPSEDII1 UNION SELECT CodTipSediu1 FROM TMP_NTIPSEDII2);

    INSERT INTO NTIPSEDII1 ( CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT seq_tipsedii1_codtipsediu1.NextVal, RecId, CodClaseA, CODOBIECT
    FROM TMP_NTIPSEDII1 WHERE CodTipSediu1 &lt; 0;

    INSERT INTO NTIPSEDII1 ( CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT seq_tipsedii1_codtipsediu1.NextVal, RecId, CodClaseA, CODOBIECT
    FROM TMP_NTIPSEDII2 WHERE CodTipSediu1 &lt; 0;

    FOR v_rec IN (
      SELECT CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT FROM tmp_ntipsedii1 WHERE Coalesce(codtipsediu1, 0) &gt; 0 UNION
      SELECT CODTIPSEDIU1, CODTIPSEDIU, CODCLASEA, CODOBIECT FROM tmp_ntipsedii2 WHERE Coalesce(codtipsediu1, 0) &gt; 0
    ) LOOP
      UPDATE NTIPSEDII1
      SET CodTipSediu = v_rec.codtipsediu,
          CodClaseA   = v_rec.codclasea,
          CODOBIECT   = v_rec.Codobiect
      WHERE CodTipSediu1 = v_rec.codtipsediu1;
    END LOOP;
  ELSE  -- INSERT
    SELECT SEQ_NTIPSEDII_CODTIPSEDIU.NextVal INTO RECID FROM DUAL;
    INSERT INTO NTIPSEDII (CODTIPSEDIU, DENUMIRE, ICLASA, CONTRONLY, TIPBENEFICIAR)
    SELECT RecId, DENUMIRE, IClasa, CONTRONLY, TIPBENEFICIAR
    FROM TMP_NTIPSEDII;

    INSERT INTO NTIPSEDII1 (CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT seq_tipsedii1_codtipsediu1.NextVal, RecId, codclasea, CODOBIECT
    FROM tmp_ntipsedii1;

    INSERT INTO NTIPSEDII1 (CodTipSediu1, Codtipsediu, CODCLASEA, CODOBIECT)
    SELECT seq_tipsedii1_codtipsediu1.NextVal, RecId, codclasea, CODOBIECT
    FROM tmp_ntipsedii2;
  END IF;
  NotifyModif(Operation, RecId, &apos;NTIPSEDII&apos;);
  COMMIT;
END;

END PKG_TIPSEDII;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TRANSEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BDD009D450B6C5B939176351B778C0DA1ED664C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TRANSEINI IS


  PROCEDURE SP_INSERTRECORD
  IS
  BEGIN
    INSERT INTO  TMP_TRANSEINI  FIELDS( CODBANKCONT ) VALUES (0) ;
    COMMIT;
  END;

  PROCEDURE SP_DELETERECORD( RecId IN NUMBER )
  IS
   NR NUMBER(10) := 0;
  BEGIN
    FOR V_REC IN 
    (
      SELECT 
      T1.CODTREZOR1, 
      T1.DOC,
      T1.NRDOC,
      T1.DATADOC,
      T1.OBS, 
      T.SUBUNITATEA,
      T.CODTREZOR
      FROM 
        TREZOR T,
        NBANKCONT BC,
        TREZOR1 T1
      WHERE
        T.TIPDOC = 30
        AND T.AN * 12 + T.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
        AND T.CODBANCA = RECID
        AND BC.CODBANKCONT = T.CODBANCA
        AND BC.CREDIT = 1
        AND T1.CODTREZOR = T.CODTREZOR
        AND T1.TIPTRANZ = 0
        AND T1.OBIECTTRANZ = 3
    )
    LOOP
       FOR V_RECOBLIG IN
       (
         SELECT 
           G.CODGENERAL,
           G.CODDOC,
           G.MONEDA,
           G.CURS,
           O.CODOBLIGPIF,
           O.CODPART,
           O.ICONT,
           O.VALOARE
         FROM 
           GENERAL G, 
           OBLIGPIF O
         WHERE
          G.TIPDOC = 30
          AND G.CODDOC = V_REC.CODTREZOR1
          AND G.CODGENERAL = O.CODGENERAL
       )
       LOOP
         DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_RECOBLIG.CODOBLIGPIF;
         DELETE FROM GENERAL  WHERE CODGENERAL  = V_RECOBLIG.CODGENERAL;

         SELECT COUNT(*) INTO NR FROM GENERAL WHERE CODGENERAL = V_REC.CODTREZOR1 AND CODDOC = 30;
         IF NR = 0 THEN 
           DELETE FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1;
 
           SELECT COUNT(*) INTO NR FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR;
           IF NR = 0 THEN 
             DELETE FROM TREZOR WHERE CODTREZOR = V_REC.CODTREZOR;
           END IF; 
         END IF; 
       END LOOP; 
    END LOOP;

    DELETE FROM TRANSEINI WHERE CODBANKCONT = RECID;
    NotifyModif(2, RecId, &apos;TRANSEINI&apos;);
    COMMIT;
  END;


  PROCEDURE SP_GOTORECORD( RecId IN NUMBER )
  IS
  BEGIN
    INSERT INTO TMP_TRANSEINI (CODBANKCONT, INFOCONT, CODMONEDA)
    SELECT I.CODBANKCONT, B.SIMBOL || &apos;/&apos; || BC.NRCONT || &apos;/&apos; || M.SIMBOL, M.CODMONEDA
    FROM
      TRANSEINI  I,
      NBANKCONT BC,
      NBANK      B,
      NMONEDE M
    WHERE
      I.CODBANKCONT     = RECID
      AND I.CODBANKCONT = BC.CODBANKCONT
      AND B.CODBANK     = BC.CODBANK
      AND M.CODMONEDA   = BC.CODMONEDA;



    FOR V_REC IN 
    (
      SELECT 
      T1.CODTREZOR1, 
      T1.DOC,
      T1.NRDOC,
      T1.DATADOC,
      T1.OBS, 
      T.SUBUNITATEA
      FROM 
        TREZOR T,
        NBANKCONT BC,
        TREZOR1 T1
      WHERE
        T.TIPDOC = 30
        AND T.AN * 12 + T.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA
        AND T.CODBANCA = RECID
        AND BC.CODBANKCONT = T.CODBANCA
        AND BC.CREDIT = 1
        AND T1.CODTREZOR = T.CODTREZOR
        AND T1.TIPTRANZ = 0
        AND T1.OBIECTTRANZ = 3
    )
    LOOP
       FOR V_RECOBLIG IN
       (
         SELECT 
           G.CODGENERAL,
           G.CODDOC,
           G.MONEDA,
           G.CURS,
           O.CODOBLIGPIF,
           O.CODPART,
           O.ICONT,
           O.VALOARE
         FROM 
           GENERAL G, 
           OBLIGPIF O
         WHERE
          G.TIPDOC = 30
          AND G.CODDOC = V_REC.CODTREZOR1
          AND G.CODGENERAL = O.CODGENERAL
       )
       LOOP
         INSERT INTO TMP_GENERAL(CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS)
         VALUES (V_RECOBLIG.CODGENERAL, 30, V_RECOBLIG.CODDOC, V_RECOBLIG.MONEDA, V_RECOBLIG.CURS);

         INSERT INTO TMP_OBLIGPIF
                (CODOBLIGPIF, 
                CODGENERAL, 
                INFOTRANSA, 
                NRDOC, 
                DATADOC, 
                SUMAVALUTA, 
                CURS, 
                CODPART, 
                ICONT,
                OBS)
         VALUES (V_RECOBLIG.CODOBLIGPIF, 
                 V_RECOBLIG.CODGENERAL, 
                 V_REC.DOC,
                 V_REC.NRDOC,
                 V_REC.DATADOC,
                 V_RECOBLIG.VALOARE, 
                 V_RECOBLIG.CURS, 
                 V_RECOBLIG.CODPART,
                 V_RECOBLIG.ICONT,
                 V_REC.OBS 
                 );
       END LOOP; 
    END LOOP;


    UPDATE TMP_OBLIGPIF O 
    SET
      DENDOCLEGATURA = (SELECT BK.SIMBOL || &apos; - &apos; || BC.NRCONT 
                        FROM
                          NBANK BK,
                          NBANKCONT BC
                        WHERE
                          BC.CODBANKCONT = O.CODPART
                          AND BC.CODBANK = BK.CODBANK
                        ),
     SIMBOLCONT = PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(O.ICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU));                     

    DELETE TMP_OBLIGPIF_INITIAL;
    INSERT INTO TMP_OBLIGPIF_INITIAL 
    SELECT * FROM TMP_OBLIGPIF;
    
    COMMIT;  
  END;
  
  
  PROCEDURE SP_LOCKRECORD( RecId IN NUMBER )
  IS
  TMP NUMBER(20);
  BEGIN
    SELECT CODBANKCONT INTO TMP FROM TRANSEINI WHERE CODBANKCONT = RecId FOR UPDATE NOWAIT;
  END;
  
  PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
  IS
    aCODOBLIGPIF NUMBER(20);
    aCODGENERAL  NUMBER(20);
    aCODTREZOR1  NUMBER(20);
    aCODTREZOR   NUMBER(20);
    aCODMONEDA   NUMBER(20);
    ANI          NUMBER(5);
    LUNAI        NUMBER(2);
  BEGIN
    -- RECID ESTE CODBANKCONT;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 
    
    
    SELECT CODBANKCONT, CODMONEDA INTO RECID, aCODMONEDA FROM TMP_TRANSEINI;
    IF Operation = 0 THEN

      UPDATE TRANSEINI SET CODBANKCONT = RECID
      WHERE
         CODBANKCONT = RECID;   

   -- TESTEZ DACA SUNT STERGERI   
       FOR V_REC IN 
       (
         SELECT 
           O.CODOBLIGPIF,  
           O.CODGENERAL,
           T1.CODTREZOR1  
         FROM
           OBLIGPIF O,
           GENERAL G,
           TREZOR1 T1
         WHERE
          O.SEMNIFICATIE = 800
          AND G.CODGENERAL= O.CODGENERAL
          AND G.TIPDOC = 30
          AND G.CODDOC = T1.CODTREZOR1
          AND T1.AN * 12 + T1.LUNA &lt; PKG_GLOBALS.ANINITIAL * 12 + PKG_GLOBALS.LUNAINITIALA  
          AND EXISTS     (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_INITIAL WHERE CODOBLIGPIF = O.CODOBLIGPIF)
          AND NOT EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGPIF)
       )
       LOOP
         DELETE FROM GENERAL  WHERE CODGENERAL  = V_REC.CODGENERAL;
         DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
       END LOOP;
   
       FOR V_REC IN (SELECT O.*, G.CODDOC FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.CODGENERAL = G.CODGENERAL)
       LOOP
         IF V_REC.CODOBLIGPIF &lt; 0 THEN
           SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL  INTO aCODGENERAL FROM DUAL;
           SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL  INTO aCODTREZOR1 FROM DUAL;
           SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL    INTO aCODTREZOR  FROM DUAL;
           SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO aCODOBLIGPIF  FROM DUAL;
          
           UPDATE TMP_OBLIGPIF
           SET
             CODOBLIGPIF = aCODOBLIGPIF
           WHERE
             CODOBLIGPIF = V_REC.CODOBLIGPIF;
     
           INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE, VALOAREAFISATA)
           VALUES(aCODOBLIGPIF, aCODGENERAL, V_REC.SUMAVALUTA, V_REC.CODPART, V_REC.ICONT, 800, RECID, V_REC.SUMAVALUTA);

           INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
           VALUES(aCODGENERAL, 30, aCODTREZOR1, aCODMONEDA, V_REC.CURS, 800);
           
           INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, CODPART, OBIECTTRANZ, OBS, AN, LUNA, ANULAT, USERID, DATACREARE)  
           VALUES(aCODTREZOR1, aCODTREZOR, 1, 0, V_REC.INFOTRANSA, V_REC.NRDOC, V_REC.DATADOC, V_REC.SUMAVALUTA, V_REC.CURS, V_REC.CODPART, 3, V_REC.OBS, ANI, LUNAI, 0, PKG_GLOBALS.USERID, SYSDATE);            

           INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA,DATADOC, AN, LUNA, OPERAT, USERID, DATACREARE, SUBUNITATEA)  
           VALUES(aCODTREZOR, 30, RECID, V_REC.DATADOC, ANI, LUNAI, 1, PKG_GLOBALS.USERID, SYSDATE, V_REC.SUBUNITATEA);
         ELSE           
           UPDATE OBLIGPIF
           SET
             VALOARE            = V_REC.SUMAVALUTA,
             CODPART            = V_REC.CODPART,
             VALOAREAFISATA     = V_REC.SUMAVALUTA,
             CONTBANKTRANZACTIE = RECID
           WHERE
             CODOBLIGPIF = V_REC.CODOBLIGPIF; 
             
           UPDATE GENERAL
           SET  
             MONEDA = aCODMONEDA,
             CURS   = V_REC.CURS
           WHERE
            CODGENERAL = V_REC.CODGENERAL;
           
           UPDATE TREZOR1
           SET 
             DOC     = V_REC.INFOTRANSA,
             NRDOC   = V_REC.NRDOC,
             DATADOC = V_REC.DATADOC,
             VALDOC  = V_REC.SUMAVALUTA,
             CURS    = V_REC.CURS, 
             CODPART = V_REC.CODPART,
             OBS     = V_REC.OBS
           WHERE
             CODTREZOR1 = V_REC.CODDOC;
           
           SELECT CODTREZOR INTO aCODTREZOR FROM TREZOR1 WHERE CODTREZOR1 = V_REC.CODDOC;
           UPDATE TREZOR
           SET
             CODBANCA = RECID,
             DATADOC  = V_REC.DATADOC
           WHERE
            CODTREZOR = aCODTREZOR; 
               
         END IF;
       END LOOP;
    ELSE
      FOR V_REC IN (SELECT O.*, G.CODDOC FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.CODGENERAL = G.CODGENERAL)
      LOOP
        INSERT INTO TRANSEINI ( CODBANKCONT) VALUES (RECID);
        SELECT SEQ_GENERAL_CODGENERAL.NEXTVAL   INTO aCODGENERAL FROM DUAL;
        SELECT SEQ_TREZOR1_CODTREZOR1.NEXTVAL   INTO aCODTREZOR1 FROM DUAL;
        SELECT SEQ_TREZOR_CODTREZOR.NEXTVAL     INTO aCODTREZOR  FROM DUAL;
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NEXTVAL INTO aCODOBLIGPIF  FROM DUAL;
       
        UPDATE TMP_OBLIGPIF
        SET
          CODOBLIGPIF = aCODOBLIGPIF
        WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
  
        INSERT INTO OBLIGPIF(CODOBLIGPIF, CODGENERAL, VALOARE, CODPART, ICONT, SEMNIFICATIE, CONTBANKTRANZACTIE, VALOAREAFISATA)
        VALUES(aCODOBLIGPIF, aCODGENERAL, V_REC.SUMAVALUTA, V_REC.CODPART, V_REC.ICONT, 800, RECID, V_REC.SUMAVALUTA);
  
        INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, SEMNIFICATIE)
        VALUES(aCODGENERAL, 30, aCODTREZOR1, aCODMONEDA, V_REC.CURS, 800);
        
        INSERT INTO TREZOR1(CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, DOC, NRDOC, DATADOC, VALDOC, CURS, CODPART, OBIECTTRANZ, OBS, AN, LUNA, ANULAT, USERID, DATACREARE)  
        VALUES(aCODTREZOR1, aCODTREZOR, 1, 0, V_REC.INFOTRANSA, V_REC.NRDOC, V_REC.DATADOC, V_REC.SUMAVALUTA, V_REC.CURS, V_REC.CODPART, 3, V_REC.OBS, ANI, LUNAI, 0, PKG_GLOBALS.USERID, SYSDATE);            
  
        INSERT INTO TREZOR(CODTREZOR, TIPDOC, CODBANCA,DATADOC, AN, LUNA, OPERAT, USERID, DATACREARE, SUBUNITATEA)  
        VALUES(aCODTREZOR, 30, RECID, V_REC.DATADOC, ANI, LUNAI, 1, PKG_GLOBALS.USERID, SYSDATE, V_REC.SUBUNITATEA);
      END LOOP;
    END IF;


   
   FOR V_REC IN 
    (
     SELECT 
       OI.CODOBLIGPIF
     FROM 
       TMP_OBLIGPIF_INITIAL OI
      UNION
     SELECT 
       OI.CODOBLIGPIF 
     FROM 
       TMP_OBLIGPIF OI
    )
    LOOP
      UPDATE OBLIGPIF
      SET
        RESTTRANSA = VALOARE - NVL((SELECT SUM(VALOARE) FROM OBLIGPIF WHERE CODTRANSA = V_REC.CODOBLIGPIF), 0)  
      WHERE
        CODOBLIGPIF = V_REC.CODOBLIGPIF;
    END LOOP; 


-- actualizez restul pentru tranzactiile care nasc obligatii de plata/incasare iar pe cele care doar sting le pun pe zero;
  UPDATE OBLIGPIF O
  SET 
   REST = 0
--   ( CASE
--      WHEN VALOARE &gt; 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
 --     WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
 --    END
--   )
    WHERE 
      EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF_INITIAL WHERE CODOBLIGPIF = O.CODOBLIGPIF)
      OR
      EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGPIF);
      NotifyModif(Operation, RecId, &apos;TRANSEINI&apos;);

    COMMIT;
  END;

end PKG_TRANSEINI; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>312538F3985501BED2A02436A74827F73A2D88A3</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TRANSPORT IS

vStareRepartizare number(5);
vTipRepartizare number(5);
vValSuplim number(20,7);
aDataTransport TIMESTAMP(6);                        
aINDICATIV  VARCHAR2(100);

procedure SETVARSUPLIM(aStareRepartizare in number, aTipRepart in number, aValSuplim in number) is
begin
  vStareRepartizare := aStareRepartizare;
  vTipRepartizare   := aTipRepart;
  vValSuplim        := aValSuplim;       
end;  

procedure SetValSuplimInDVI(aCodIntr in number, aTipRepart in number, aValSuplim in number) is pragma autonomous_transaction;
begin
  update dvi set
    ValSuplim = aValSuplim,
    TipRepSuplim = aTipRepart
  where DVi.Codintr = aCodIntr;
  commit;
end;  

procedure GETVARSUPLIM(aStareRepartizare out number, aTipRepart out number, aValSuplim out number) is
begin
  aStareRepartizare := vStareRepartizare;
  aTipRepart        := vTipRepartizare;
  aValSuplim        := vValSuplim;
end;

function GETSTAREREP return number is
begin
  return vStareRepartizare;
end;  



procedure GetDataTransportIndicativ is
begin
 For v_rec in ( SELECT
    DataTransport, Indicativ
  FROM
    Transport
  WHERE
   CODTransport = ( Select * from (select CodTransport from transport order by codtransport desc) where rownum=1)) loop
     aDataTransport := v_rec.DataTransport;
     aIndicativ  := v_rec.indicativ;   
   end loop;
end;


procedure SETSTAREREP(aStareRepartizare in number) is
begin
  vStareRepartizare := aStareRepartizare;
end;  

function GetValServ(aCodIntr IN NUMBER) return number is
ArtTransDVI  number(20);
ArtAsigDVI number(20);
aVal NUMBER(20,7);
begin
  ArtTransDVI := pkg_categconst.GetValConstanta(&apos;ArtTransDVI&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLunaLucru);
  ArtAsigDVI  := pkg_categconst.GetValConstanta(&apos;ArtAsigDVI&apos;, pkg_globals.GetANLUCRU, pkg_globals.GetLunaLucru);
  select sum((I1.Cant * I1.PU)*decode(nvl(i.curs, 0), 0, 1, i.curs)) into aVal from
  intrari1 i1 
  inner join intrari i on i1.codintr = i.codintr
  where i1.codintr = aCodIntr and i1.codobiect in (ArtTransDVI, ArtAsigDVI);
  return aVal;
end;

function GetMasaFactIntr(aCodIntr IN NUMBER) return number is
aMasa NUMBER(20,7);
begin
  SELECT
    SUM(nvl(O.MASA, 0) * I1.CANT) into aMASA
  FROM
   Intrari1 I1,
   NARTOBJ O
  WHERE
   I1.CODIntr = aCodIntr
   AND O.CODOBIECT = I1.CODOBIECT
   AND I1.TIPLINIE = &apos;=&apos;;
  return aMasa; 
end;

function GetVolumFactIntr(aCodIntr IN NUMBER) return number is
aVolum NUMBER(20,7);
begin
  SELECT
    SUM(nvl(O.VOLUM, 0)* I1.CANT) into aVOLUM
  FROM
   Intrari1 I1,
   NARTOBJ O
  WHERE
   I1.CODIntr = aCodIntr
   AND O.CODOBIECT = I1.CODOBIECT
   AND I1.TIPLINIE = &apos;=&apos;;
  return aVolum; 
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodTransport INTO Tmp FROM TRANSPORT WHERE CodTransport = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
vTip number(1);
BEGIN
  SP_LOCKRECORD(RecId);
  select tip into vtip from transport WHERE CodTransport = RecId;
  if vTip = 0 then 
		FOR v_rec IN ( SELECT T1.CodTransf1 CodDoc1
                       FROM TRANSPORT1 TR1
                            LEFT JOIN TRANSF T ON TR1.CodDoc = T.CodTransf
                            LEFT JOIN TRANSF1 T1 ON T.CodTransf = T1.CodTransf
                       WHERE TR1.CODTRANSPORT = RecId and TR1.TipDoc IN (12, 13)) LOOP
			UPDATE TRANSF1
			SET
				CostTransport = 0
			WHERE CodTransf1 = v_rec.CodDoc1;
		END LOOP;
		    
		FOR v_rec IN ( SELECT I1.CodIes1 CodDoc1
                       FROM TRANSPORT1 TR1
                            LEFT JOIN IESIRI I ON TR1.CodDoc = I.CodIes
                            LEFT JOIN IESIRI1 I1 ON I.CodIes = I1.CodIes
                       WHERE TR1.CODTRANSPORT = RecId and TR1.TipDoc NOT IN (12, 13)) LOOP
			UPDATE IESIRI1
			SET
				CostTransport = 0
			WHERE CodIes1 = v_rec.CodDoc1;
		END LOOP;
  end if;
  DELETE FROM TRANSPORT2 WHERE CodTransport = RecId;
  DELETE FROM TRANSPORT1 WHERE CodTransport = RecId;
  DELETE FROM TRANSPORT  WHERE CodTransport = RecId;
  NotifyModif(2, RecId, &apos;TRANSPORT&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  pkg_transport.GetDataTransportIndicativ;
  INSERT INTO  TMP_TRANSPORT FIELDS( CodTransport, Rep_Transf, Rep_Subunit, TipLivrare/*, DataTransport, Indicativ */) VALUES (0, 0, 0, 3/*, aDataTransport, aIndicativ*/) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
aTip NUMBER(1);
BEGIN
    INSERT INTO TMP_TRANSPORT ( CodTransport,
                                DataTransport,
                                UserId,       
                                DataCreare,   
                                Subunitate,   
                                Indicativ,        
                                Operat,       
                                Blocat,       
                                Anulat,       
                                An,           
                                Luna,         
                                Valoare,
                                TipRepart,
                                CodParcAuto,
                                CodSofer,
                                Colete,
                                rep_transf,
                                Rep_Subunit,
                                Tip,
                                Masina,
                                Sarcina,
                                Volum,
                                DataStart,
                                DataStop,
                                DataStartDVI,
                                DataStopDVI,
                                TipLivrare)
                       ( select TR.CodTransport,
                                TR.DataTransport,
                                TR.UserId,       
                                TR.DataCreare,   
                                TR.Subunitate,   
                                TR.Indicativ,        
                                TR.Operat,       
                                TR.Blocat,       
                                TR.Anulat,       
                                TR.An,           
                                TR.Luna,         
                                TR.Valoare,
                                TR.TipRepart,
                                TR.CodParcAuto,
                                TR.CodSofer,
                                TR.Colete,
                                TR.Rep_Transf,
                                tr.rep_subunit,
                                TR.Tip,
                                OBJ.DENUMIRE,
                                Round(NVL(PA.MasaU, 0), 5),
                                Round(NVL(PA.Lung, 0) * NVL(PA.Lat, 0) * NVL(PA.Inalt, 0)/1000000, 5),
                                to_date(&apos;01.&apos;||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU), &apos;DD.MM.YYYY&apos;),
                                last_day(to_date(&apos;01.&apos;||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU), &apos;DD.MM.YYYY&apos;)),
                                to_date(&apos;01.&apos;||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU), &apos;DD.MM.YYYY&apos;),
                                last_day(to_date(&apos;01.&apos;||to_char(pkg_globals.GetLUNALUCRU)||&apos;.&apos;||to_char(pkg_globals.GetANLUCRU), &apos;DD.MM.YYYY&apos;)),
                                3
                         FROM TRANSPORT TR 
                              LEFT JOIN NPARCAUT PA ON TR.CodParcAuto = PA.CODNPARCAUT
                              LEFT JOIN NARTOBJ OBJ ON PA.CODART = OBJ.CODOBIECT
                         WHERE CodTransport = RecId ) ;

    select nvl(Tip, 0) into aTip from tmp_transport;
    
    if aTip = 0 then
    INSERT INTO TMP_TRANSPORT1 ( CodTransport1,                    
                                 CodTransport,                     
                                 CodColet,                         
                                 CodDoc,                           
                                 TipDoc,                           
                                 SerieColet,                       
                                 NrColet,                          
                                 DataColet,                        
                                 SerieDoc,                         
                                 NrDoc,                            
                                 DataDoc,                          
                                 TipPartener,                      
                                 CodPart,                          
                                 Partener,
                                 PrefixDoc)                         
                        ( select T1.CodTransport1,                 
                                 T1.CodTransport,                  
                                 T1.CodColet,
                                 T1.CodDoc,
                                 T1.TipDoc,
                                 DOCPK.Serie,
                                 PK.NrDoc,
                                 PK.DataP,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN DOCT.Serie
                                   ELSE DOCIES.Serie
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN T.NrDoc
                                   ELSE I.NrDoc
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN T.DataDoc
                                   ELSE I.DataDoc
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN &apos;GESTIUNE&apos;
                                   WHEN T1.TipDoc = 13 THEN &apos;...NEDEFINIT...&apos;
                                   WHEN T1.TipDoc = 23 THEN &apos;SUBUNITATE&apos;
                                   ELSE &apos;PARTENER&apos;
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN G.CodGest
                                   WHEN T1.TipDoc = 13 THEN 0
                                   WHEN T1.TipDoc = 23 THEN S.CodSubunit
                                   ELSE P.CodPart
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN G.Den_Gest
                                   WHEN T1.TipDoc = 13 THEN &apos;...NEDEFINIT...&apos;
                                   WHEN T1.TipDoc = 23 THEN S.Den_Subunit
                                   ELSE P.Den_Part
                                 END,
                                 COALESCE(I.PREFIXDOC,T.PREFIXDOC)  
                         FROM TRANSPORT1 T1
                              LEFT JOIN PACHETE PK ON T1.CodColet = PK.CODPACHETE
                              LEFT JOIN DOCCARNETE DOCPK ON PK.Carnetdoc = DOCPK.CODCARNET
                              LEFT JOIN IESIRI I ON T1.CodDoc = I.CodIes AND NVL(I.Anulat, 0) &lt;&gt; 1
                              LEFT JOIN DOCCARNETE DOCIES ON I.CarnetDoc = DOCIES.CODCARNET
                              LEFT JOIN NPART P ON I.Partener = P.Codpart
                              LEFT JOIN NSUBUNIT S ON I.CodSubunit = S.Codsubunit
                              LEFT JOIN TRANSF T ON T1.CodDoc = T.Codtransf AND NVL(T.Anulat, 0) &lt;&gt; 1
                              LEFT JOIN DOCCARNETE DOCT ON T.CarnetDoc = DOCT.CodCarnet
                              LEFT JOIN NGEST G ON T.CodGestCmd = G.CodGest 
                         WHERE T1.CodTransport = RecId );

  INSERT INTO TMP_TRANSPORT1_INI (CodTransport1,          
                                 CodTransport,            
                                 CodColet,
                                 CodDoc,
                                 TipDoc,    
                                 SerieColet,
                                 NrColet,   
                                 DataColet, 
                                 SerieDoc,                      
                                 NrDoc,                     
                                 DataDoc,                   
                                 TipPartener,
                                 CodPart,                   
                                 Partener)
                        ( select T1.CodTransport1,
                                 T1.CodTransport,
                                 T1.CodColet,
                                 T1.CodDoc,
                                 T1.TipDoc,
                                 DOCPK.Serie,
                                 PK.NrDoc,
                                 PK.DataP,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN DOCT.Serie
                                   ELSE DOCIES.Serie
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN T.NrDoc
                                   ELSE I.NrDoc
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc IN (12, 13) THEN T.DataDoc
                                   ELSE I.DataDoc
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN &apos;GESTIUNE&apos;
                                   WHEN T1.TipDoc = 13 THEN &apos;...NEDEFINIT...&apos;
                                   WHEN T1.TipDoc = 23 THEN &apos;SUBUNITATE&apos;
                                   ELSE &apos;PARTENER&apos;
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN G.CodGest
                                   WHEN T1.TipDoc = 13 THEN 0
                                   WHEN T1.TipDoc = 23 THEN S.CodSubunit
                                   ELSE P.CodPart
                                 END,
                                 CASE 
                                   WHEN T1.TipDoc = 12 THEN G.Den_Gest
                                   WHEN T1.TipDoc = 13 THEN &apos;...NEDEFINIT...&apos;
                                   WHEN T1.TipDoc = 23 THEN S.Den_Subunit
                                   ELSE P.Den_Part
                                 END  
                         FROM TRANSPORT1 T1
                              LEFT JOIN PACHETE PK ON T1.CodColet = PK.CODPACHETE
                              LEFT JOIN DOCCARNETE DOCPK ON PK.Carnetdoc = DOCPK.CODCARNET
                              LEFT JOIN IESIRI I ON T1.CodDoc = I.CodIes AND NVL(I.Anulat, 0) &lt;&gt; 1
                              LEFT JOIN DOCCARNETE DOCIES ON I.CarnetDoc = DOCIES.CODCARNET
                              LEFT JOIN NPART P ON I.Partener = P.Codpart
                              LEFT JOIN NSUBUNIT S ON I.CodSubunit = S.Codsubunit
                              LEFT JOIN TRANSF T ON T1.CodDoc = T.Codtransf AND NVL(T.Anulat, 0) &lt;&gt; 1
                              LEFT JOIN DOCCARNETE DOCT ON T.CarnetDoc = DOCT.CodCarnet
                              LEFT JOIN NGEST G ON T.CodGestCmd = G.CodGest 
                         WHERE T1.CodTransport = RecId );                       
  
  INSERT INTO TMP_TRANSPORT2 (CodTransport2,
                              CodTransport1,
                              CodDoc1,
                              TipDoc,
                              Articol,
                              Cant,
                              Den_UM1,
                              Document,
                              Valoare,
                              Val,
                              Masa,
                              Volum,
                              operat)
                     ( SELECT RowNum CodTranport2,          
                              TR1.CodTransport1,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.CodTransf1
                                ELSE I1.CodIes1
                              END CodDoc1,
                              TR1.TipDoc,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN TOBJ.Denumire
                                ELSE IOBJ.Denumire
                              END Articol,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant
                                ELSE I1.Cant
                              END cant,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN TUM1.Den_UM1
                                ELSE IUM1.Den_UM1
                              END Den_UM1,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T.PREFIXDOC||T.NrDoc||&apos;/&apos;||TO_CHAR(T.DATADOC,&apos;DD.MM.YYYY&apos;)
                                ELSE I.PREFIXDOC||I.NrDoc||&apos;/&apos;||TO_CHAR(I.DATADOC,&apos;DD.MM.YYYY&apos;)
                              END Document,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.CostTransport
                                ELSE I1.CostTransport
                              END Valoare,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant * T1.Pu
                                ELSE I1.Cant * I1.PU
                              END Val,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN 
                                  CASE
                                    WHEN NVL(AMBT.CODAMB, -1) = -1 THEN TOBJ.Masa
                                    ELSE AMBT.Masa
                                  END
                                ELSE
                                  CASE
                                    WHEN NVL(AMBI.CODAMB, -1) = -1 THEN IOBJ.Masa
                                    ELSE AMBI.Masa
                                  END
                              END *
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant
                                ELSE I1.Cant
                              END Masa,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN 
                                  CASE
                                    WHEN NVL(AMBT.CODAMB, -1) = -1 THEN TOBJ.Volum
                                    ELSE NVL(AMBT.Inaltime, 0) * NVL(AMBT.Lungime, 0) * NVL(AMBT.Latime, 0)
                                  END
                                ELSE
                                  CASE
                                    WHEN NVL(AMBI.CODAMB, -1) = -1 THEN IOBJ.Volum
                                    ELSE NVL(AMBI.Inaltime, 0) * NVL(AMBI.Lungime, 0) * NVL(AMBI.Latime, 0)
                                  END
                              END *
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T1.Cant
                                ELSE I1.Cant
                              END Volum,
                              CASE 
                                WHEN TR1.TipDoc IN (12, 13) THEN T.Operat
                                ELSE I.Operat
                              END Operat
                       FROM TRANSPORT1 TR1
                            LEFT JOIN IESIRI I ON TR1.CodDoc = I.CodIes
                            LEFT JOIN DOCCARNETE DOCI ON I.CARNETDOC = DOCI.CodCarnet
                            LEFT JOIN IESIRI1 I1 ON I.CodIes = I1.CodIes
                            LEFT JOIN NARTOBJ IOBJ ON I1.CodObiect = IOBJ.CodObiect
                            LEFT JOIN NUM1 IUM1 ON I1.UMSec = IUM1.CodUM1
                            LEFT JOIN NARTAMB AMBI ON IOBJ.CodObiect = AMBI.CodOBiect AND I1.UMSec = AMBI.UMSec
                            LEFT JOIN TRANSF T ON TR1.CodDoc = T.CodTransf
                            LEFT JOIN DOCCARNETE DOCT ON T.CARNETDOC = DOCT.CodCarnet
                            LEFT JOIN TRANSF1 T1 ON T.CodTransf = T1.CodTransf
                            LEFT JOIN NARTOBJ TOBJ ON T1.CodObiect = TOBJ.CodObiect
                            LEFT JOIN NUM1 TUM1 ON T1.UMSec = TUM1.CodUM1
                            LEFT JOIN NARTAMB AMBT ON TOBJ.CodObiect = AMBT.CodOBiect AND T1.UMSec = AMBT.UMSec
                       WHERE TR1.CODTRANSPORT = RecId );
  else
  
  INSERT INTO TMP_TRANSPORT1 ( CODTRANSPORT1,                         
                               CODTRANSPORT,                         
                               CODDOC,                         
                               TIPDOC,                         
                               SERIEDOC,                         
                               NRDOC,                         
                               DATADOC,                         
                               CODPART,                         
                               PARTENER,                         
                               PREFIXDOC,                         
                               VALOARE)                         
                        ( select T1.CodTransport1,                 
                                 T1.CodTransport,                  
                                 T1.CodDoc,
                                 T1.TipDoc,
                                 DOC.Serie,
                                 I.NrDoc,
                                 I.DataDoc,
                                 P.CodPart,
                                 P.Den_Part,
                                 I.PrefixDoc,
                                 pkg_transport.GetValServ(I.CodIntr)
                         FROM TRANSPORT1 T1
                              LEFT JOIN INTRARI I ON T1.CodDoc = I.CodIntr AND NVL(I.Anulat, 0) &lt;&gt; 1
                              LEFT JOIN DOCCARNETE DOC ON I.CarnetDoc = DOC.CODCARNET
                              LEFT JOIN NPART P ON I.Partener = P.Codpart
                         WHERE T1.CodTransport = RecId );

  INSERT INTO TMP_TRANSPORT2 (CODTRANSPORT2,                         
                              CODTRANSPORT,                         
                              CODDOC,                         
                              TIPDOC,                         
                              VALOARE,                         
                              VAL,
                              MASA,                         
                              VOLUM,                         
                              SERIEDOC,                         
                              NRDOC,                         
                              DATADOC,                         
                              CODPART,                         
                              PARTENER,                         
                              PREFIXDOC,
                              OPERAT)
                     ( SELECT TR2.CodTransport2,          
                              TR2.CodTransport,
                              TR2.CodDoc,
                              TR2.TipDoc,
                              I.ValDoc * I.Curs,
                              DVI.ValSuplim,
                              pkg_TRANsPORT.GetMasaFactIntr(TR2.CodDoc),
                              pkg_TRANsPORT.GetVolumFactIntr(TR2.CodDoc),
                              DOC.SERIE,
                              I.NRDOC,
                              I.DATADOC,
                              P.CODPART,
                              P.DEN_PART,
                              I.PREFIXDOC,
                              I.OPERAT
                       FROM TRANSPORT2 TR2
                            INNER JOIN INTRARI I ON TR2.CodDoc = I.CodIntr
                            INNER JOIN DVI ON DVI.CODINTR = I.CodIntr
                            INNER JOIN NPART P ON I.PARTENER = P.CodPart
                            LEFT JOIN DOCCARNETE DOC ON I.CARNETDOC = DOC.CodCarnet
                       WHERE TR2.CODTRANSPORT = RecId );
  
  end if;
                       
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
vCod number(20);
vTip number(1);
vTipRepart number(1);
BEGIN
  select tip into vtip from tmp_transport;
  select tiprepart into vtiprepart from tmp_transport;
  
  IF Operation = 0 THEN  -- UPDATE

    SELECT CodTransport INTO RecId FROM TMP_TRANSPORT;
    UPDATE TRANSPORT SET ( CodTransport,                    
                           DataTransport,
                           UserId,       
                           DataCreare,   
                           Subunitate,   
                           Indicativ,        
                           Operat,       
                           Blocat,       
                           Anulat,       
                           An,           
                           Luna,         
                           Valoare,
                           TipRepart,
                           CodParcAuto, 
                           CodSofer,
                           Colete,
                           Rep_Transf,
                           Rep_Subunit,
                           Tip )
                = ( SELECT RecId,
                           DataTransport,
                           UserId,       
                           DataCreare,   
                           Subunitate,   
                           Indicativ,        
                           Operat,       
                           Blocat,       
                           Anulat,       
                           An,           
                           Luna,         
                           Valoare,
                           TipRepart,
                           CodParcAuto, 
                           CodSofer,
                           Colete,
                           Rep_Transf,
                           Rep_Subunit,
                           Tip
              FROM TMP_TRANSPORT )
      WHERE CodTransport = RecId ;

    DELETE FROM TRANSPORT1 where CodTransport = RecId and CodTransport1 not in (Select CodTransport1 from TMP_TRANSPORT1);
    INSERT INTO TRANSPORT1 (CodTransport1,
                            CodTransport,
                            CodColet,
                            CodDoc,
                            TipDoc)
                   ( SELECT SEQ_TRANSPORT1_CODTRANSPORT1.Nextval,
                            RecId,
                            CodColet,
                            CodDoc,
                            TipDoc
                     FROM TMP_TRANSPORT1 WHERE NVL(CodTransport1, -1) &lt; 0 );
    FOR v_rec IN ( SELECT * FROM TMP_TRANSPORT1 WHERE NVL(CodTransport1, -1) &gt; 0 ORDER BY CodTransport1 ) LOOP
       UPDATE TRANSPORT1
       SET
        CodColet = v_rec.CodColet,
        CodDoc   = v_rec.CodDoc,
        TipDoc   = v_rec.TipDoc
       WHERE CodTransport1  = v_rec.CodTransport1;
    END LOOP;
    
    if vTip = 0 then
      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc IN (12, 13)) LOOP
        UPDATE TRANSF1
        SET
          CostTransport = v_rec.valoare
        WHERE CodTransf1 = v_rec.CodDoc1;
      END LOOP;
      
      FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc NOT IN (12, 13)) LOOP
        UPDATE IESIRI1
        SET
          CostTransport = v_rec.valoare
        WHERE CodIes1 = v_rec.CodDoc1;
      END LOOP;
    else
      delete from transport2 where codtransport = recid and codtransport2 not in
      (select codtransport2 from tmp_transport2);
      
      insert into transport2(
      CODTRANSPORT2,                         
      CODTRANSPORT,                          
      CODDOC,                                
      TIPDOC)
      (select 
       seq_transport2_codtransport2.nextval,
       RecId,
       CodDoc,
       TipDoc from tmp_transport2 where nvl(codtransport2, -1) &lt; 0);        
       
       FOR v_rec IN ( SELECT * FROM TMP_TRANSPORT2 WHERE NVL(CodTransport2, -1) &gt; 0 ORDER BY CodTransport2 ) LOOP
       UPDATE TRANSPORT2
       SET
        CodDoc   = v_rec.CodDoc,
        TipDoc   = v_rec.TipDoc
       WHERE CodTransport2  = v_rec.CodTransport2;
    END LOOP;
    
    for v_rec IN ( SELECT * FROM TMP_TRANSPORT2 ORDER BY CodDoc ) LOOP
      update dvi set
        ValSuplim = v_rec.val,
        TipRepSuplim = vTiprepart
      where DVi.Codintr = v_rec.coddoc;  
    end loop;
       
    end if;  
  ELSE

  SELECT Seq_TRANSPORT_CodTransport.NextVal INTO RecId FROM DUAL;
  INSERT INTO TRANSPORT ( CodTransport,
                          DataTransport,
                          UserId,       
                          DataCreare,   
                          Subunitate,   
                          Indicativ,        
                          Operat,       
                          Blocat,       
                          Anulat,       
                          An,           
                          Luna,         
                          Valoare,
                          TipRepart,
                          CodParcAuto, 
                          CodSofer,
                          Colete,
                          Rep_Transf,
                          Rep_Subunit,
                          Tip )
                 ( select RecId,
                          DataTransport,
                          UserId,       
                          DataCreare,   
                          Subunitate,   
                          Indicativ,        
                          Operat,       
                          Blocat,       
                          Anulat,       
                          An,           
                          Luna,         
                          Valoare,
                          TipRepart,
                          CodParcAuto, 
                          CodSofer,
                          Colete,
                          Rep_Transf,
                          Rep_Subunit,
                          Tip
                   FROM TMP_TRANSPORT ) ;
  INSERT INTO TRANSPORT1 ( CodTransport1,
                           CodTransport,
                           CodColet,
                           CodDoc,
                           TipDoc )
                  ( select Seq_transport1_CodTransport1.Nextval,
                           RecId,
                           CodColet,
                           CodDoc,
                           TipDoc
                    FROM TMP_TRANSPORT1 ) ;
  
    FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc IN (12, 13)) LOOP
      UPDATE TRANSF1
      SET
        CostTransport = v_rec.valoare
      WHERE CodTransf1 = v_rec.CodDoc1;
    END LOOP;
    
    FOR v_rec IN (SELECT * FROM TMP_TRANSPORT2 WHERE TipDoc NOT IN (12, 13)) LOOP
      UPDATE IESIRI1
      SET
        CostTransport = v_rec.valoare
      WHERE CodIes1 = v_rec.CodDoc1;
    END LOOP;
  
    if vTip &gt; 0 then
      insert into transport2 (codtransport2, codtransport, coddoc, tipdoc)
      (select seq_transport2_codtransport2.nextval, RecId, coddoc, tipdoc from tmp_transport2);
      
      for v_rec IN ( SELECT * FROM TMP_TRANSPORT2 ORDER BY CodDoc ) LOOP
      update dvi set
        ValSuplim = v_rec.val,
        TipRepSuplim = vTiprepart
      where DVi.Codintr = v_rec.coddoc;  
    end loop;
      
    end if;
    
  END IF;
  NotifyModif(Operation, RecId, &apos;TRANSPORT&apos;);
  COMMIT;
END;  

end pkg_transport; 

/*ALTER TABLE TMP_TRANSPORT2 ADD (
OPERAT NUMBER(1)
);*/ 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TRASEULIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87F0C6F9386D23CEBEE45AA91BBE68D9FC7E3379</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TRASEULIVR IS

FromManevra number(1);

procedure ClearTemps is
begin
  delete TMP_TraseuLivr_Comenzi;
  delete TMP_TraseuLivr_TotalArt;
  delete TMP_TraseuLivr_ComenziClienti;
  delete TMP_TraseuLivr_Incarcare;
  delete TMP_TraseuLivr_ArtLivr;
  delete TMP_TraseuLivr_Livrare;
  delete tmp_traseulivr_allcmd;
  delete tmp_traseulivr_allcmd_baza;
  delete tmp_traseulivr_auto;
  commit;
end;  

procedure SP_GOTORECORD(RecId in number) is
aTipTraseu number(2);
aCODLOCALIT number(20);
aAdresa Varchar(100); 
aLat number(20,7); 
aLng number(20,7); 
aDEN_ZONA Varchar(100);    
aSIMBAUTO Varchar(100);  
aDEN_LOCALIT Varchar(100);  
begin
  insert into TMP_TraseuLivr (CodTraseuLivr, DenTraseu, SimbolTraseu, CODLOCALIT, Adresa, Opriri, Ore, Minute, Tip, Lat, Lng)
  select CodTraseuLivr, DenTraseu, SimbolTraseu, CODLOCALIT, Adresa, Opriri, Ore, Minute, Nvl(Tip,0), Lat, Lng 
	from TraseuLivr where CodTraseuLivr = RecId;

	Select Nvl(T.Tip,0), T.CODLOCALIT, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT, T.Adresa, T.Lat, T.Lng  
	  into aTipTraseu,   aCODLOCALIT, aDEN_ZONA,   aSIMBAUTO, aDEN_LOCALIT, aAdresa, aLat, aLng   
	from Tmp_TraseuLivr T
		LEFT JOIN NLOCALIT L ON L.CODLOCALIT = T.CODLOCALIT
		LEFT JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
		LEFT JOIN NZONE Z ON Z.CODZONA = L.CODZONA;

	INSERT INTO TMP_NAGENDA_TRASEU (
		CODAGENDA, FIRMA, SEDIU, ZONA, JUDET, LOCALITATE, POZTRASEU, SSOC,
		ADRESA, CODTRASEULIVR, Lat, Lng, CodPart )
		                         
	SELECT
		A.CODAGENDA, P.DEN_PART, A.OBS, Z.DEN_ZONA, J.SIMBAUTO, L.DEN_LOCALIT, 
		(Case when aTipTraseu = 0 then A.POZTRASEU else A.POZTRASEU1 end) POZTRASEU,
		CASE WHEN A.SEDIUSOCIAL BETWEEN 4 AND 7 THEN 1 ELSE 0 END,
		GETADRESA(A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL), 
		RecId, A.Latitudine, A.Longitudine, A.CodPart
	FROM NAGENDA A
		INNER JOIN NPART P ON P.CODPART = A.CODPART
		LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
		LEFT JOIN NJUDET J ON J.CODJUDET = L.CODJUDET
		LEFT JOIN NZONE Z ON Z.CODZONA = L.CODZONA
	WHERE ( aTipTraseu = 0 and Nvl(CODTRASEU,0) = RecID) or ( aTipTraseu = 1 and Nvl(CODTRASEU1,0) = RecID) 
		AND Nvl(A.INACTIV,0) = 0
  union all
	SELECT 0, &apos;Start&apos;, &apos;&apos;, aDEN_ZONA,   aSIMBAUTO, aDEN_LOCALIT, 0, null, aAdresa, 0, To_Char(aLat), To_Char(aLng), -1 from dual;
	commit;
end;

procedure SP_LOCKRECORD(RecId in number) is
tmp_recid number(20);
begin
  select CodTraseuLivr into tmp_recid from TraseuLivr where CodTraseuLivr = RecId for update nowait;
end;

procedure SP_POSTRECORDS(Operation in number, RecId out number) is
aTipTraseu number(2);
xTipTraseu number(2);
BEGIN
	Select Nvl(Tip,0) into aTipTraseu from TMP_TraseuLivr;
	
	if Operation = 0 then -- UPDATE

		select CodTraseuLivr into RecId from TMP_TraseuLivr;
  	Select Nvl(Tip,0) into xTipTraseu from TraseuLivr where CodTraseuLivr = RecID;
		
		update	TraseuLivr
		set	(DenTraseu, SimbolTraseu, CodLocalit, ADRESA, Opriri, Ore, Minute, Tip, Lat, Lng) =
		(select DenTraseu, SimbolTraseu, CodLocalit, ADRESA, Opriri, Ore, Minute, Tip, Lat, Lng from TMP_TraseuLivr)
		where	CodTraseuLivr = RecId;

    if aTipTraseu = 0 then 
			if xTipTraseu = 0 then 
				FOR v_rec IN (
					SELECT CODAGENDA FROM NAGENDA WHERE  CodTraseu = RecID 
					and CodAgenda not in (Select CodAgenda From TMP_NAGENDA_TRASEU where CodAgenda &lt;&gt; 0)) 
				LOOP
					Update NAgenda Set CodTraseu = 0 , PozTraseu = null  WHERE  CodAgenda = v_rec.CodAgenda;
				END LOOP;
			else  -- a fost tip=1
  			Update NAgenda Set CodTraseu1 = 0 , PozTraseu1 = null  WHERE  CodTraseu1 = RecID;
			end if;
			FOR v_rec IN (
				SELECT CODAGENDA,PozTraseu, Lat, Lng FROM TMP_NAGENDA_TRASEU where CodAgenda &lt;&gt; 0) 
			LOOP
					UPDATE NAGENDA A SET 
						A.Latitudine  = v_rec.Lat,
						A.Longitudine = v_rec.Lng,
						A.POZTRASEU   = v_rec.PozTraseu,
						A.CODTRASEU   = RecID
					WHERE CODAGENDA = v_rec.CodAgenda;
			END LOOP;
		else -- este 1
			if xTipTraseu = 1 then 
				FOR v_rec IN (
					SELECT CODAGENDA FROM NAGENDA WHERE  CodTraseu1 = RecID 
					and CodAgenda not in (Select CodAgenda From TMP_NAGENDA_TRASEU where CodAgenda &lt;&gt; 0)) 
				LOOP
					Update NAgenda Set CodTraseu1 = 0 , PozTraseu1 = null  WHERE  CodAgenda = v_rec.CodAgenda;
				END LOOP;
			else  -- a fost tip=0
  			Update NAgenda Set CodTraseu = 0 , PozTraseu = null  WHERE  CodTraseu = RecID;
			end if;
			FOR v_rec IN (
				SELECT CODAGENDA,PozTraseu, Lat, Lng FROM TMP_NAGENDA_TRASEU where CodAgenda &lt;&gt; 0) 
			LOOP
					UPDATE NAGENDA A SET 
						A.Latitudine  = v_rec.Lat,
						A.Longitudine = v_rec.Lng,
						A.POZTRASEU1  = v_rec.PozTraseu,
						A.CODTRASEU1  = RecID
					WHERE CODAGENDA = v_rec.CodAgenda;
			END LOOP;
		end if;
	else -- INSERT
		select SEQ_TraseuLivr_CodTraseuLivr.nextval into RecId from Dual;
		insert into TraseuLivr
		(CodTraseuLivr, DenTraseu, SimbolTraseu, CodLocalit, ADRESA, Opriri, Ore, Minute, Tip, Lat, Lng)
				(select RecId, DenTraseu, SimbolTraseu, CodLocalit, ADRESA, Opriri, Ore, Minute, Tip, Lat, Lng from TMP_TraseuLivr);
		
		FOR v_rec IN (SELECT CODAGENDA, POZTRASEU, CODTRASEULIVR, Lat, Lng FROM TMP_NAGENDA_TRASEU where CodAgenda &lt;&gt; 0) LOOP
			if aTipTraseu = 0 then 
				UPDATE NAGENDA A
				SET
					A.Latitudine  = v_rec.Lat,
					A.Longitudine = v_rec.Lng,
					A.POZTRASEU   = v_rec.PozTraseu,
					A.CODTRASEU   = RecID
				WHERE CODAGENDA = v_rec.CodAgenda;
			else
				UPDATE NAGENDA A
				SET
					A.Latitudine  = v_rec.Lat,
					A.Longitudine = v_rec.Lng,
					A.POZTRASEU1  = v_rec.PozTraseu,
					A.CODTRASEU1  = RecID
				WHERE CODAGENDA = v_rec.CodAgenda;
			end if;
		END LOOP;
	end if;
  NotifyModif(Operation, RecId, &apos;TraseuLivr&apos;);
	commit;
end;

procedure SP_DELETERECORD(RecId in number) is
begin
	 SP_LOCKRECORD(RecId);
	 update NAgenda Set CodTraseu = 0,  PozTraseu = null  where CodTraseu = RecId;
	 update NAgenda Set CodTraseu1 = 0, PozTraseu1 = null  where CodTraseu1 = RecId;

	 delete from TraseuLivr where CodTraseuLivr = RecId;
	 NotifyModif(2, RecId, &apos;TraseuLivr&apos;);
	 commit;
end;

procedure SP_INSERTRECORD is
begin
	   insert into TMP_TraseuLivr (CodTraseuLivr) values (0);
		  commit;
end;

procedure CLEAR_LOCK_COMENZI is
begin
	update Comanda set UserIDBlocaj = null where UserIDBlocaj = PKG_GLOBALS.UserID;
	commit;
end;

procedure GET_TMP_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number, aCC in boolean, aCS in boolean, aCG in boolean) is
  lOraDateStart  date;
  lOraDateEnd    date;
  lRezervat      number(20,7);
  lStoc          number(20,7);
  lComenziInCurs number(20,7);
begin
  lOraDateStart := to_date(aDateStart, &apos;DD.MM.YYYY&apos;);
  lOraDateEnd   := to_date(aDateEnd, &apos;DD.MM.YYYY&apos;);
  -- pregatesc TMP_IOArt_Luna
    -- PKG_GLOBALS.SETLUNALUCRU(extract(year from lOraDateStart), extract(month from lOraDateStart));
    -- PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
  delete TMP_TraseuLivr_AllCmd;
  delete TMP_TraseuLivr_AllCmd_baza;
  delete TMP_TraseuLivr_Auto;
  delete from TMP_TraseuLivr_Comenzi;
  if aCC then
    insert into TMP_TraseuLivr_Comenzi
    (
      CodComanda, TipDoc, CodComanda1,
      CodObiect, CodArticol, CodObiectEchiv, CodArticolEchiv,
      CantComandat, CantAcceptat, CantDisponibil, CantRezervat, CantComenzi,
      CodUM, ZecimaleUM,
      CodClient,
      CodAgenda, CodJudet, CodLocalit,
      NrDoc, DataDoc,
      CodTraseu,
      PozTraseu,
      Masa, Volum,
      CodMijlTransp, MasaU, VolumU, Delegat, Insotitor, -- DataSosirii,
      InregNula,
      MasaO, VolumO, DenObiect,
      FlagLucru,
      CodTara, CodZona, Den_Zona, Den_Tara, Den_Judet, Den_Localit, Den_Client,
      TRANSPCLIENT,
      CODGRUPA, PARITATEGRUPA,
      D1, D2, D3
    )
    (
      select distinct
        C.CodComanda, C.TipDoc, C1.CodComanda1,
        C1.CodObiect, NAO.CodArticol, 0, 0, -- CodObiectEchiv, CodArticolEchiv
        nvl(C1.CantComandat, 0), nvl(C1.CantAcceptat, 0), 0, 0, 0, -- CantDisponibil, CantRezervat, CantComenzi
        nvl(NA.UM, 0), nvl(NUM.Zecimale, 2),
        C.Partener,
        nvl(NAG.CodAgenda, 0), nvl(NL.CodJudet, 0), nvl(NAG.CodLocalit, 0),
        C.NrDoc, C.DataDoc,
        (case
          when nvl(C.FaraTransport, 0) = 1 then 1 -- 1 = &apos;TRANSPORT ASIGURAT DE CLIENT&apos;, 0 = &apos;NEDEFINIT&apos;
          else
            (case
              when nvl(C.CodTraseuLivr, 0) = 0 then nvl(NAG.CodTraseu, 0)
              else C.CodTraseuLivr
            end)
        end),
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else
            (case
              when nvl(C.ORDINELIVRARE, 0) = 0 then nvl(NAG.POZTRASEU, 0)
              else C.ORDINELIVRARE
            end)
        end),
        nvl(C1.CantAcceptat * NAO.Masa, 0), nvl(C1.CantAcceptat * NAO.Volum, 0) / 1000000,
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Mijltransp, 0)
        end), -- CodMijlTransp
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.MasaU, 0)
        end), -- MasaU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.VolumU, 0) / 1000000
        end), -- VolumU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Delegat, 0)
        end), -- Delegat
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Insotitor, 0)
        end), -- Insotitor
        --null, -- DataSosirii
        0, -- InregNula
        nvl(NAO.Masa, 0), nvl(NAO.Volum, 0) / 1000000, NAO.Denumire,
        0, -- FlagLucru
        nvl(NL.CodTara, 0), nvl(NL.CodZona, 0), NZ.Den_Zona, NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit,
        P.Den_Part,
        (case
          when nvl(C.Faratransport, 0) = 0 then NVL(NAG.TRANSPCLIENT, 0)
          else 2
        end),
        NE.CODGRUPA, NE.PARITATE,
        C1.D1, C1.D2, C1.D3
      from
        Comanda C
        inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        inner join NArtObj NAO on NAO.CodObiect = C1.CodObiect
        inner join NArt NA on NA.CodArticol = NAO.CodArticol
        inner join NUM on NUM.CodUM = NA.UM
        inner join NPart P on P.CodPart = C.Partener
        left join NAgenda NAG on NAG.CodAgenda = C.CodLocatie
        left join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left join NJudet NJ on NJ.CodJudet = NL.CodJudet
        left join NTari NT on NT.CodTara = NL.CodTara
        left join NZone NZ on NZ.CodZona = NL.Codzona
        left join NParcAut NPA on NPA.CodNParcAut = C.MijlTransp
        left join NEchiv NE on NE.CodObiect = C1.CodObiect
      where
        NVL(C.Inchisa,0) = 0 and -- comenzi care nu sunt INCHISE
        C1.Termen between lOraDateStart and lOraDateEnd and
        C.Subunitatea = aSubunit and
        C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila, &lt;=&gt; comenzi NEFACTURATE
        C.UserIDBlocaj = PKG_GLOBALS.UserID and
        C.TipDoc = 18 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
        C1.CantComandat &gt; 0 and NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
    );
    
    insert into TMP_TraseuLivr_AllCmd
    (
     codcomanda, 
     tipdoc,
     partener,
     codagenda,
     codjudet,
     codlocalit,
     nrdoc,
     datadoc,
     masa,
     volum,
     codauto,
     delegat,
     selectie,
     sediu,
     judet,
     localitate,
     codtraseu  
    )
    (
      select distinct
        C.CodComanda, 
        C.TipDoc, 
        p.Den_part,
        nvl(NAG.CodAgenda, 0), 
        nvl(NL.CodJudet, 0), 
        nvl(NAG.CodLocalit, 0),
        C.NrDoc, 
        C.DataDoc,
        (
         select sum(nvl(C1.CantAcceptat * NAO.Masa, 0)) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart a on a.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda
               and c1.termen between lOraDateStart and lOraDateEnd
               and to_number(a.tiparticol) in (0,2)
        ), 
        (
         select sum(nvl(C1.CantAcceptat * NAO.Volum, 0) / 1000000) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart a on a.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda      
               and c1.termen between lOraDateStart and lOraDateEnd 
               and to_number(a.tiparticol) in (0,2)
        ),
        nvl(c.MIJLTRANSP,0),
        c.delegat,
        0,
        nag.obs,
        nj.den_judet,
        nl.den_localit,
        nvl(c.codtraseulivr,0) 
      from
        Comanda C
        inner join NPart P on P.CodPart = C.Partener
        left join NAgenda NAG on NAG.CodAgenda = C.CodLocatie
        left join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left join NJudet NJ on NJ.CodJudet = NL.CodJudet
      where
        NVL(C.Inchisa,0) = 0 and
        exists (select C1.Termen from comanda1 c1 where c1.codcomanda = c.codcomanda and c1.termen between lOraDateStart and lOraDateEnd) and
        C.Subunitatea = aSubunit and
        C.TipDoc = 18 and
        NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
    );
  end if;  
  if aCS then 
    insert into TMP_TraseuLivr_Comenzi
    (
      CodComanda, TipDoc, CodComanda1,
      CodObiect, CodArticol, CodObiectEchiv, CodArticolEchiv,
      CantComandat, CantAcceptat, CantDisponibil, CantRezervat, CantComenzi,
      CodUM, ZecimaleUM,
      CodClient,
      CodAgenda, CodJudet, CodLocalit,
      NrDoc, DataDoc,
      CodTraseu,
      PozTraseu,
      Masa, Volum,
      CodMijlTransp, MasaU, VolumU, Delegat, Insotitor, -- DataSosirii,
      InregNula,
      MasaO, VolumO, DenObiect,
      FlagLucru,
      CodTara, CodZona, Den_Zona, Den_Tara, Den_Judet, Den_Localit, Den_Client,
      TRANSPCLIENT,
      CODGRUPA, PARITATEGRUPA,
      D1, D2, D3
    )
    (
      select distinct
        C.CodComanda, C.TipDoc, C1.CodComanda1,
        C1.CodObiect, NAO.CodArticol, 0, 0, -- CodObiectEchiv, CodArticolEchiv
        nvl(C1.CantComandat, 0), nvl(C1.CantAcceptat, 0), 0, 0, 0, -- CantDisponibil, CantRezervat, CantComenzi
        nvl(NA.UM, 0), nvl(NUM.Zecimale, 2),
        C.Subunitatea,
        nvl(NAG.CodAgenda, 0), nvl(NL.CodJudet, 0), nvl(NAG.CodLocalit, 0),
        C.NrDoc, C.DataDoc,
        (case
          when nvl(C.FaraTransport, 0) = 1 then 1 -- 1 = &apos;TRANSPORT ASIGURAT DE CLIENT&apos;, 0 = &apos;NEDEFINIT&apos;
          else
            (case
              when nvl(C.CodTraseuLivr, 0) = 0 then nvl(NAG.CodTraseu, 0)
              else C.CodTraseuLivr
            end)
        end),
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else
            (case
              when nvl(C.ORDINELIVRARE, 0) = 0 then nvl(NAG.POZTRASEU, 0)
              else C.ORDINELIVRARE
            end)
        end),
        nvl(C1.CantAcceptat * NAO.Masa, 0), nvl(C1.CantAcceptat * NAO.Volum, 0) / 1000000,
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Mijltransp, 0)
        end), -- CodMijlTransp
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.MasaU, 0)
        end), -- MasaU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.VolumU, 0) / 1000000
        end), -- VolumU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Delegat, 0)
        end), -- Delegat
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Insotitor, 0)
        end), -- Insotitor
        --null, -- DataSosirii
        0, -- InregNula
        CASE WHEN NA.TIPARTICOL = &apos;1&apos; THEN 0 ELSE nvl(NAO.Masa, 0) END, CASE WHEN NA.TIPARTICOL = &apos;1&apos; THEN 0 ELSE nvl(NAO.Volum, 0) END/ 1000000, NAO.Denumire,
        0, -- FlagLucru
        nvl(NL.CodTara, 0), nvl(NL.CodZona, 0), NZ.Den_Zona, NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit,
        NS.Den_Subunit, 
        (case
          when nvl(C.Faratransport, 0) = 0 then NVL(NAG.TRANSPCLIENT, 0)
          else 2
        end),
        NE.CODGRUPA, NE.PARITATE,
        C1.D1, C1.D2, C1.D3
      from
        Comanda C
        inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        inner join NArtObj NAO on NAO.CodObiect = C1.CodObiect
        inner join NArt NA on NA.CodArticol = NAO.CodArticol
        inner join NUM on NUM.CodUM = NA.UM
        left join NAgenda NAG on NAG.CodSubunit = C.Subunitsursa
        left join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left join NJudet NJ on NJ.CodJudet = NL.CodJudet
        left join NTari NT on NT.CodTara = NL.CodTara
        left join NZone NZ on NZ.CodZona = NL.Codzona
        left join NParcAut NPA on NPA.CodNParcAut = C.MijlTransp
        left join RezervatS RS on RS.CodComanda1 = C1.CodComanda1
        left join NPARTTR DEL on C.Delegat = DEL.CODPARTTR
        left join NEchiv NE on NE.CodObiect = C1.CodObiect
        left join NSubunit NS on NS.CodSubunit = C.Subunitatea
      where
        NVL(C.Inchisa,0) = 0 and -- comenzi care nu sunt INCHISE
        C1.Termen between lOraDateStart and lOraDateEnd and
        C.SubunitSursa = aSubunit and
        C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila, &lt;=&gt; comenzi NEFACTURATE
        C.UserIDBlocaj = PKG_GLOBALS.UserID and
        C.TipDoc = 44 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
        C1.CantComandat &gt; 0 and NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
    );
    insert into TMP_TraseuLivr_AllCmd
    (
     codcomanda, 
     tipdoc,
     partener,
     codagenda,
     codjudet,
     codlocalit,
     nrdoc,
     datadoc,
     masa,
     volum,
     codauto,
     delegat,
     selectie,
     sediu,
     judet,
     localitate,
     codtraseu
    )
    (
      select distinct
        C.CodComanda, 
        C.TipDoc, 
        ns.Den_Subunit,
        nvl(NAG.CodAgenda, 0), 
        nvl(NL.CodJudet, 0), 
        nvl(NAG.CodLocalit, 0),
        C.NrDoc, 
        C.DataDoc,
        (
         select sum(nvl(C1.CantAcceptat * case when a.tiparticol = &apos;1&apos; then 0 else coalesce(NAO.Masa,0) end, 0)) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart a on a.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda
               and c1.termen between lOraDateStart and lOraDateEnd      
        ), 
        (
         select sum(nvl(C1.CantAcceptat * case when a.tiparticol = &apos;1&apos; then 0 else coalesce(NAO.Volum,0) end, 0) / 1000000) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart a on a.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda      
                and c1.termen between lOraDateStart and lOraDateEnd 
        ),
        nvl(c.MIJLTRANSP,0),
        c.delegat,
        0,
        nag.obs,
        nj.den_judet,
        nl.den_localit,
        nvl(c.codtraseulivr,0) 
      from
        Comanda C
        inner join NSubunit NS on NS.CodSubunit = C.Subunitatea
        left join NAgenda NAG on NAG.CodAgenda = C.CodLocatie
        left join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left join NJudet NJ on NJ.CodJudet = NL.CodJudet
      where
        NVL(C.Inchisa,0) = 0 and
        exists (select C1.Termen from comanda1 c1 where c1.codcomanda = c.codcomanda and c1.termen between lOraDateStart and lOraDateEnd) and
        C.SubunitSursa = aSubunit and
        C.TipDoc = 44 and
        NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
     );
  end if;
  if aCG then
    insert into TMP_TraseuLivr_Comenzi
    (
      CodComanda, TipDoc, CodComanda1,
      CodObiect, CodArticol, CodObiectEchiv, CodArticolEchiv,
      CantComandat, CantAcceptat, CantDisponibil, CantRezervat, CantComenzi,
      CodUM, ZecimaleUM,
      CodClient,
      CodAgenda, CodJudet, CodLocalit,
      NrDoc, DataDoc,
      CodTraseu,
      PozTraseu,
      Masa, Volum,
      CodMijlTransp, MasaU, VolumU, Delegat, Insotitor, -- DataSosirii,
      InregNula,
      MasaO, VolumO, DenObiect,
      FlagLucru,
      CodTara, CodZona, Den_Zona, Den_Tara, Den_Judet, Den_Localit, Den_Client,
      TRANSPCLIENT,
      CODGRUPA, PARITATEGRUPA,
      D1, D2, D3
    )
    (
      select distinct
        C.CodComanda, C.TipDoc, C1.CodComanda1,
        C1.CodObiect, NAO.CodArticol, 0, 0, -- CodObiectEchiv, CodArticolEchiv
        nvl(C1.CantComandat, 0), nvl(C1.CantAcceptat, 0), 0, 0, 0, -- CantDisponibil, CantRezervat, CantComenzi
        nvl(NA.UM, 0), nvl(NUM.Zecimale, 2),
        C.Codgest,
        nvl(NAG.CodAgenda, 0), nvl(NL.CodJudet, 0), nvl(NAG.CodLocalit, 0),
        C.NrDoc, C.DataDoc,
        case
          when nvl(C.FaraTransport, 0) = 1 then 1 -- 1 = &apos;TRANSPORT ASIGURAT DE CLIENT&apos;, 0 = &apos;NEDEFINIT&apos;
          else
            (case
              when nvl(C.CodTraseuLivr, 0) = 0 then nvl(NAG.CodTraseu, 0)
              else C.CodTraseuLivr
            end)
        end,
        case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else
            (case
              when nvl(C.ORDINELIVRARE, 0) = 0 then nvl(NAG.POZTRASEU, 0)
              else C.ORDINELIVRARE
            end)
        end,
        nvl(C1.CantAcceptat * case when na.tiparticol = &apos;1&apos; then 0 else NAO.Masa end, 0), nvl(C1.CantAcceptat * case when na.tiparticol = &apos;1&apos; then 0 else NAO.Volum end, 0) / 1000000,
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Mijltransp, 0)
        end), -- CodMijlTransp
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.MasaU, 0)
        end), -- MasaU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(NPA.VolumU, 0) / 1000000
        end), -- VolumU
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Delegat, 0)
        end), -- Delegat
        (case
          when nvl(C.FaraTransport, 0) = 1 then 0
          else nvl(C.Insotitor, 0)
        end), -- Insotitor
        --null, -- DataSosirii
        0, -- InregNula
        case when na.tiparticol = &apos;1&apos; then 0 else nvl(NAO.Masa, 0) end, case when na.tiparticol = &apos;1&apos; then 0 else nvl(NAO.Volum, 0) / 1000000 end, NAO.Denumire,
        0, -- FlagLucru
        nvl(NL.CodTara, 0), nvl(NL.CodZona, 0), NZ.Den_Zona, NT.Den_Tara, NJ.Den_Judet, NL.Den_Localit,
        NGE.Den_Gest, 
        case
          when nvl(C.Faratransport, 0) = 0 then NVL(NAG.TRANSPCLIENT, 0)
          else 2
        end,
        NE.CODGRUPA, NE.PARITATE,
        C1.D1, C1.D2, C1.D3
      from
        Comanda C
        inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        inner join NArtObj NAO on NAO.CodObiect = C1.CodObiect
        inner join NArt NA on NA.CodArticol = NAO.CodArticol
        inner join NUM on NUM.CodUM = NA.UM
        left outer join NAgenda NAG on NAG.CodGest = C.CodGest
        left outer join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left outer join NJudet NJ on NJ.CodJudet = NL.CodJudet
        left outer join NTari NT on NT.CodTara = NL.CodTara
        left outer join NZone NZ on NZ.CodZona = NL.Codzona
        left outer join NParcAut NPA on NPA.CodNParcAut = C.MijlTransp
        left outer join NPARTTR DEL on C.Delegat = DEL.CODPARTTR
        left outer join NEchiv NE on NE.CodObiect = C1.CodObiect
        left outer join NGest NGE ON NGE.CodGest = C.CodGest
      where
        NVL(C.Inchisa,0) = 0 and -- comenzi care nu sunt INCHISE
        C1.Termen between lOraDateStart and lOraDateEnd and
        C.Subunitatea = aSubunit and
        C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila, &lt;=&gt; comenzi NEFACTURATE
        C.UserIDBlocaj = PKG_GLOBALS.UserID and
        C.TipDoc = 43 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
        C1.CantComandat &gt; 0 and NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
    );
    insert into TMP_TraseuLivr_AllCmd
    (
     codcomanda, 
     tipdoc,
     partener,
     codagenda,
     codjudet,
     codlocalit,
     nrdoc,
     datadoc,
     masa,
     volum,
     codauto,
     delegat,
     selectie,
     sediu,
     judet,
     localitate,
     codtraseu  
    )
    (
      select distinct
        C.CodComanda, 
        C.TipDoc, 
        nge.Den_gest,
        nvl(NAG.CodAgenda, 0), 
        nvl(NL.CodJudet, 0), 
        nvl(NAG.CodLocalit, 0),
        C.NrDoc, 
        C.DataDoc,
        (
         select sum(nvl(C1.CantAcceptat * case when na.tiparticol = &apos;1&apos; then 0 else NAO.Masa end, 0)) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart na on na.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda
               and c1.termen between lOraDateStart and lOraDateEnd      
        ), 
        (
         select sum(nvl(C1.CantAcceptat * case when na.tiparticol = &apos;1&apos; then 0 else NAO.Volum end, 0) / 1000000) 
         from comanda1 c1
              inner join nartobj nao on nao.codobiect = c1.codobiect
              inner join nart na on na.codarticol = nao.codarticol
         where c1.codcomanda = c.codcomanda      
                and c1.termen between lOraDateStart and lOraDateEnd 
        ),
        nvl(c.MIJLTRANSP,0),
        c.delegat,
        0,
        nag.obs,
        nj.den_judet,
        nl.den_localit,
        nvl(c.codtraseulivr,0) 
      from
        Comanda C
        inner join NGest NGE ON NGE.CodGest = C.CodGest
        left join NAgenda NAG on NAG.CodAgenda = C.CodLocatie
        left join NLocalit NL on NL.CodLocalit = NAG.CodLocalit
        left join NJudet NJ on NJ.CodJudet = NL.CodJudet
        left join NSubunit NS on NS.CodSubunit = C.Subunitatea
      where
        NVL(C.Inchisa,0) = 0 and
        exists (select C1.Termen from comanda1 c1 where c1.codcomanda = c.codcomanda and c1.termen between lOraDateStart and lOraDateEnd) and
        C.Subunitatea = aSubunit and
        C.TipDoc = 43 and
        NVL(C.Displivrare,0) = 0
        and coalesce(C.faratransport,0) = 0
     );
  end if;
  
  insert into tmp_traseulivr_auto 
  (
    CODAUTO,
    MODEL,
    MARCA,
    SOFER,
    MASAU,
    VOLUMU,
    denumire,
    CodTraseu
  )
  select distinct 
    a.codnparcaut,
    mo.model,
    ma.marca,
    s.nume||&apos; &apos;||s.prenume,
    a.masau,
    a.volumu,
    obj.denumire,
    tmp.codtraseu
  from tmp_traseulivr_allcmd tmp
       inner join nparcaut a on a.codnparcaut = tmp.codauto
       left  join nartobj obj on obj.codobiect = a.codart
       left  join nmarciauto ma on ma.codmarciauto = a.marca
       left  join nmodeleauto mo on mo.codmodeleauto = a.model
       left  join npers s on s.codpers = a.sofer
  where tmp.codauto &gt; 0;
  
  update tmp_traseulivr_auto a
  set
    masai = nvl(masai,0) + (select sum(nvl(c.masa,0)) from tmp_traseulivr_allcmd c where c.codauto = a.codauto),
    volumi = nvl(volumi,0) + (select sum(nvl(c.volum,0)) from tmp_traseulivr_allcmd c where c.codauto = a.codauto);
  
  for v_rec in (select CodObiect, CodComanda1, CodAgenda from TMP_TraseuLivr_Comenzi)
  loop
    lRezervat := 0;
    select
      nvl(sum(RS.REST), 0) into lRezervat
    from
      RezervatS RS
      inner join Comanda1 C1 on C1.CodComanda1 = RS.CodComanda1
      inner join Comanda C on C.CodComanda = C1.CodComanda
    where
      C.Inchisa = 0 and -- comenzi care nu sunt INCHISE
      C1.Termen between lOraDateStart and lOraDateEnd and
      C.Subunitatea = aSubunit and
      C1.CantAcceptat = C1.RestAcceptat and -- conditia de adus in grila, &lt;=&gt; comenzi NEFACTURATE
      C1.CodComanda1 = v_rec.CodComanda1 and
      C.TipDoc in (18, 43, 44) and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
      coalesce(C.faratransport,0) = 0 and
      C1.CantComandat &gt; 0; -- nu iau in considerare liniile care au comandat negativ
        
    lStoc := 0;
    select
      sum(nvl(NS.Rest, 0)) into lStoc
    from
      NIRStoc NS
      left outer join TMP_IOArt_Luna TIOAL on TIOAL.CodIOArt = NS.CodIOArt
      left outer join NIR on NIR.CodNIR = NS.CodNIR
      left outer join IOArt IOA ON IOA.CodIOArt = NS.CodIOArt
    where
      NS.CodObiect = v_rec.CodObiect and
      TIOAL.MG &lt;&gt; 5 and	-- Metoda de Gestiune: 5 = &apos;articole/stocuri valorice&apos;
      NS.Rest &lt;&gt; 0;
			  
    lComenziInCurs := 0;
    select
      sum(nvl(C1.RestAcceptat, 0)) into lComenziInCurs
    from
      Comanda1 C1
      inner join Comanda C on C.CodComanda = C1.CodComanda
    where
      C1.CodObiect = v_rec.CodObiect and
      C.Subunitatea = aSubunit and
      C1.Termen between lOraDateStart and lOraDateEnd and
      C1.RestAcceptat &gt; 0 and	-- comenzi interne in curs lansate
      coalesce(C.faratransport,0) = 0 and 
      C.TipDoc in (8, 11); --  8 = &apos;comenzi furnizori&apos;, 11 = &apos;comenzi interne&apos;
      
    update TMP_TraseuLivr_Comenzi
    set
      CantRezervat   = lRezervat,
      CantDisponibil = lStoc,
      CantComenzi    = lComenziInCurs
    where
      CodObiect = v_rec.CodObiect and
      CodComanda1 = v_rec.CodComanda1 and
      CodAgenda = v_rec.CodAgenda;
  end loop;
  if FromManevra = 0 then 
    insert into TMP_TRASEULIVR_ALLCMD_BAZA
    select * from TMP_TRASEULIVR_ALLCMD;
  end if;  
  commit;
end;

function LOCK_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number, aCC in boolean, aCS in boolean, aCG in boolean, aFromManevra in number) return varchar2 is
  lOraDateStart date;
  lOraDateEnd date;
  tmp_recid number(20);
  lOraError varchar2(2000);
  COMANDA_BLOCATA exception;
  pragma exception_init(COMANDA_BLOCATA, -20999);
begin
  FromManevra := aFromManevra; 
  lOraDateStart := to_date(aDateStart, &apos;DD.MM.YYYY&apos;);
  lOraDateEnd := to_date(aDateEnd, &apos;DD.MM.YYYY&apos;);
  lOraError := &apos;&apos;;
  if aCC then
    for v_rec in
      (
        select distinct
          C.CodComanda,
          C.NrDoc,
          nvl(C.UserIDBlocaj, 0) as UserIDBlocaj
        from
          Comanda C
          inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        where
          C.Inchisa = 0 and
          C1.Termen between lOraDateStart and lOraDateEnd and
          C.Subunitatea = aSubunit and
          C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila
          C.TipDoc = 18 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
          C1.CantComandat &gt; 0 -- nu iau in considerare liniile care au comandat negativ
          and ((FromManevra = 0) or exists (select t.codunic from tmp_manevra t where t.codunic = c.codcomanda))
          and coalesce(C.faratransport,0) = 0
      )
    loop
      begin
        select CodComanda into tmp_recid from Comanda where CodComanda = v_rec.CodComanda for update nowait;
        if v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; PKG_GLOBALS.UserID then raise COMANDA_BLOCATA; end if;
        update Comanda
        set UserIDBlocaj = PKG_GLOBALS.UserID
        where CodComanda = v_rec.CodComanda;
      exception when COMANDA_BLOCATA then
        lOraError := lOraError || to_char(v_rec.NrDoc) || &apos;, &apos;;
      end;
    end loop;
  end if;
  
  if aCS then
    for v_rec in
      (
        select distinct
          C.CodComanda,
          C.NrDoc,
          nvl(C.UserIDBlocaj, 0) as UserIDBlocaj
        from
          Comanda C
          inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        where
          C.Inchisa = 0 and
          C1.Termen between lOraDateStart and lOraDateEnd and
          C.SubunitSursa = aSubunit and
          C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila
          C.TipDoc = 44 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
          C1.CantComandat &gt; 0 -- nu iau in considerare liniile care au comandat negativ
          and ((FromManevra = 0) or exists (select t.codunic from tmp_manevra t where t.codunic = c.codcomanda))
          and coalesce(C.faratransport,0) = 0
      )
    loop
      begin
        select CodComanda into tmp_recid from Comanda where CodComanda = v_rec.CodComanda for update nowait;
        if v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; PKG_GLOBALS.UserID then raise COMANDA_BLOCATA; end if;
        update Comanda
        set UserIDBlocaj = PKG_GLOBALS.UserID
        where CodComanda = v_rec.CodComanda;
      exception when COMANDA_BLOCATA then
        lOraError := lOraError || to_char(v_rec.NrDoc) || &apos;, &apos;;
      end;
    end loop;
  end if;
  
  if aCG then
    for v_rec in
      (
        select distinct
          C.CodComanda,
          C.NrDoc,
          nvl(C.UserIDBlocaj, 0) as UserIDBlocaj
        from
          Comanda C
          inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        where
          C.Inchisa = 0 and
          C1.Termen between lOraDateStart and lOraDateEnd and
          C.Subunitatea = aSubunit and
          C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila
          C.TipDoc = 43 and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
          C1.CantComandat &gt; 0 -- nu iau in considerare liniile care au comandat negativ
          and ((FromManevra = 0) or exists (select t.codunic from tmp_manevra t where t.codunic = c.codcomanda))
          and coalesce(C.faratransport,0) = 0
      )
    loop
      begin
        select CodComanda into tmp_recid from Comanda where CodComanda = v_rec.CodComanda for update nowait;
        if v_rec.UserIDBlocaj &lt;&gt; 0 and v_rec.UserIDBlocaj &lt;&gt; PKG_GLOBALS.UserID then raise COMANDA_BLOCATA; end if;
        update Comanda
        set UserIDBlocaj = PKG_GLOBALS.UserID
        where CodComanda = v_rec.CodComanda;
      exception when COMANDA_BLOCATA then
        lOraError := lOraError || to_char(v_rec.NrDoc) || &apos;, &apos;;
      end;
    end loop;
  end if;
    
  commit;
  return lOraError;
end;

  /*procedure UNLOCK_COMENZI(aDateStart in varchar2, aDateEnd in varchar2, aSubunit in number) is
    lOraDateStart date;
    lOraDateEnd date;
    tmp_recid number(20);
  begin
    lOraDateStart := to_date(aDateStart, &apos;DD.MM.YYYY&apos;);
    lOraDateEnd := to_date(aDateEnd, &apos;DD.MM.YYYY&apos;);
    for v_rec in
      (
        select distinct
          C.CodComanda
        from
          Comanda C
          inner join Comanda1 C1 on C1.CodComanda = C.CodComanda
        where
          C1.Termen between lOraDateStart and lOraDateEnd and
          C.Subunitatea = aSubunit and
          -- C1.CantAcceptat = C1.RestAcceptat and -- conditia de aducere in grila, nu mai e valabila la unlock
          nvl(C.UserIDBlocaj, 0) = PKG_GLOBALS.UserID and
          -- se poate lasa doar asta, daca dorim deblocarea comenzilor ramase blocate in alte instante
          C.TipDoc in (18, 43, 60) and -- doar comenzi clienti, comenzi de la gestiuni, comenzi de la subunitati
          C1.CantComandat &gt; 0 -- nu iau in considerare liniile care au comandat negativ
      )
    loop
      select CodComanda into tmp_recid from Comanda where CodComanda = v_rec.CodComanda for update nowait;
      update Comanda set UserIDBlocaj = null
      where CodComanda = v_rec.CodComanda;
    end loop;
    commit;
  end;*/

 	function GET_SysDate return varchar2 is
 	begin
    return to_char(sysdate, &apos;DD.MM.YYYY&apos;);
 	end;

  procedure GET_TMP_TOTALART(peEchiv boolean default false) is
    lPeEchiv number(1);
  begin
  lPeEchiv := 0;
  if peEchiv then lPeEchiv := 1; end if;
  delete from TMP_TraseuLivr_TotalArt;
  insert into TMP_TraseuLivr_TotalArt
    (
	     CodUM,
	     CantComandat, CantAcceptat, CantDisponibil, CantRezervat, CantComenzi,
       CodObiect,
       ZecimaleUM,
       InregNula,
       DenObiect,
       RestAcceptat,
       CodGrupa, ParitateGrupa,
       D1, D2, D3
    )
    (
      select
        (case
          when lPeEchiv = 1 then CodUMEchivGen
          else CodUM
        end),
        (case
          when lPeEchiv = 1 then sum(CantComandat * ParitateEchivGen)
          else sum(CantComandat)
        end), --sum(decode(InregNula, 0, CantComandat, 1, 0)),
			   		(case
          when lPeEchiv = 1 then sum(decode(InregNula, 0, CantAcceptat * ParitateEchivGen, 1, 0))
          else sum(decode(InregNula, 0, CantAcceptat, 1, 0))
        end),
        (case
          when lPeEchiv = 1 then sum(CantDisponibil * ParitateEchivGen)
          else sum(CantDisponibil)
        end),
        (case
          when lPeEchiv = 1 then sum(CantRezervat * ParitateEchivGen)
          else sum(CantRezervat)
        end),
        (case
          when lPeEchiv = 1 then sum(CantComenzi * ParitateEchivGen)
          else sum(CantComenzi)
        end),
        (case
          when lPeEchiv = 1 then CodObiectEchivGen
          else CodObiect
        end),
        (case
          when lPeEchiv = 1 then ZecimaleUMEchivGen
          else ZecimaleUM
        end),
        0,
        (case
          when lPeEchiv = 1 then DenObiectEchivGen
          else DenObiect
        end),
        0,
        CodGrupa, ParitateGrupa,
        COALESCE(D1,0), COALESCE(D2,0), COALESCE(D3,0)
      from
        TMP_TraseuLivr_Comenzi
      group by
        (case
          when lPeEchiv = 1 then CodUMEchivGen
          else CodUM
        end),
        (case
          when lPeEchiv = 1 then CodObiectEchivGen
          else CodObiect
        end),
        (case
          when lPeEchiv = 1 then ZecimaleUMEchivGen
          else ZecimaleUM
        end),
        0,
        (case
          when lPeEchiv = 1 then DenObiectEchivGen
          else DenObiect
        end),
        CodGrupa, ParitateGrupa,
        COALESCE(D1,0), COALESCE(D2,0), COALESCE(D3,0)
    );
    commit;
  end;

  procedure GET_TMP_COMENZICLIENTI(peEchiv boolean default false) is
    lPeEchiv number(1);
  begin
    lPeEchiv := 0;
    if peEchiv then lPeEchiv := 1; end if;
    delete from TMP_TraseuLivr_ComenziClienti;
    insert into TMP_TraseuLivr_ComenziClienti
  		(
		 	  CodClient,	CodJudetClient, CodLocalitClient,
  				NrComanda,	DataComanda,
  				CodUM,
      CantComandat, CantAcceptat, CantRezervat,
  				CodObiect,
  				ZecimaleUM,
  				InregNula,
  				CodComanda, CodComanda1,
      CodAgenda,
      FlagLucru,
      Den_Client,
      TipDoc
    )
    (
      select
        CodClient, CodJudet, CodLocalit,
        NrDoc, DataDoc,
        (case
          when lPeEchiv = 1 then CodUMEchivGen
          else CodUM
        end),
        (case
          when lPeEchiv = 1 then sum(CantComandat * ParitateEchivGen)
          else sum(CantComandat)
        end),
					   (case
          when lPeEchiv = 1 then sum(CantAcceptat * ParitateEchivGen)
          else sum(CantAcceptat)
        end),
        (case
          when lPeEchiv = 1 then sum(CantRezervat * ParitateEchivGen)
          else sum(CantRezervat)
        end),
        (case
          when lPeEchiv = 1 then CodObiectEchivGen
          else CodObiect
        end),
        (case
          when lPeEchiv = 1 then ZecimaleUMEchivGen
          else ZecimaleUM
        end),
        InregNula,
        CodComanda, CodComanda1,
        CodAgenda,
        FlagLucru,
        Den_Client,
        TipDoc
      from
        TMP_TraseuLivr_Comenzi
      group by
        CodClient, CodJudet, CodLocalit,
        NrDoc, DataDoc,
        (case
          when lPeEchiv = 1 then CodUMEchivGen
          else CodUM
        end),
        (case
          when lPeEchiv = 1 then CodObiectEchivGen
          else CodObiect
        end),
        (case
          when lPeEchiv = 1 then ZecimaleUMEchivGen
          else ZecimaleUM
        end),
        InregNula,
        CodComanda, CodComanda1,
        CodAgenda,
        FlagLucru,
        Den_Client,
        TipDoc
      );
    commit;
  end;

 	procedure GET_TMP_INFOCOMANDA(aCodComanda in number) is
 	begin
	  	delete from TMP_TRASEULIVR_COMANDA;
  		insert into TMP_TRASEULIVR_COMANDA
		  (
			   CodComanda,
  				Partener, Den_Partener,
  				Moneda,
  				NrDoc,	DataDoc,	Obs
  		)
			 (
			   select
				    C.CodComanda,
   					C.Partener, NP.Den_Part,
   					C.Moneda,
   					C.NrDoc, C.DataDoc,	C.Obs
  				from
		  		  Comanda C
				 	  inner join NPART NP ON NP.CodPart = C.Partener
				  where
				    CodComanda = aCodComanda
			 );
		  delete from TMP_TRASEULIVR_COMANDA1;
		  insert into TMP_TRASEULIVR_COMANDA1
		  (
			   CodComanda1, CodComanda,
				  IndexLocal,
				  CodObiect, CodArt,
				  CodUM,
      CantComandat, CantAcceptat,
				  PU, Valoare,
				  Termen,
				  AdDim,
				  ProcDisc,
				  Consum,
				  CuLansare,
				  Scadenta,
				  Obs,
				  D1, D2, D3,
      DenObiect
			 )
			 (
			   select
				    C1.CodComanda1, C1.CodComanda,
					   C1.IndexLocal,
					   C1.CodObiect, NAO.CodArticol,
   					NUM.CodUM,
   					C1.CantComandat, TTLC.CantAcceptat, -- C1.CantAcceptat,
			   		C1.PU, C1.PU * TTLC.CantAcceptat, -- C1.PU * C1.CantAcceptat,
   					C1.Termen,
		   			C1.AdDim,
					   C1.ProcDisc,
					   C1.Consum,
				   	C1.CuLansare,
				   	C1.Scadenta,
				   	C1.Obs,
        C1.D1, C1.D2, C1.D3,
        NAO.Denumire
				  from
				    Comanda1 C1
					   inner join NArtObj NAO on NAO.CodObiect = C1.CodObiect
					   inner join NArt NA on NA.CodArticol = NAO.CodArticol
					   inner join NUM ON NUM.CodUM = NA.UM
        inner join TMP_TraseuLivr_Comenzi TTLC on TTLC.CodComanda1 = C1.CodComanda1
				  where
				    C1.CodComanda = aCodComanda
			 );
		  commit;
	 end;

	 procedure GET_TMP_INCARCARE is
  begin
    delete from TMP_TraseuLivr_Incarcare;
    insert into TMP_TraseuLivr_Incarcare
      ( 
        CodTraseu, Delegat, Insotitor, MijlocTransp, DataSosirii, MasaUtila, VolumUtil, 
        Masa, Volum, 
        DifMasa, DifVolum
      )
      (
        select   
          CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, DataSosirii, MasaU, VolumU,
          sum(Masa), sum(Volum),
          MasaU - sum(Masa),VolumU - sum(Volum)
        from
          TMP_TraseuLivr_Comenzi where TRANSPCLIENT &lt;&gt; 2
        group by
          CodTraseu, Delegat, Insotitor, CODMIJLTRANSP, DataSosirii, MasaU, VolumU
      );
    update TMP_TraseuLivr_Incarcare set TmpIdx = RowNum;
    commit;
  end;

  procedure GET_TMP_DETALIIDISTRIB is
  begin
    delete from TMP_TraseuLivr_Livrare;
    insert into TMP_TraseuLivr_Livrare
      (
        CodComanda, CodClient, CodJudetClient, CodLocalitClient, NrComanda, DataComanda,
        CodTraseu, Pozitie, Delegat, MIJLOCTRANSP, Insotitor, CodAgenda,
				    Masa,Volum, Den_Client
      )
      (
        select
          CodComanda, CodClient, CodJudet, CodLocalit, NrDoc, DataDoc,
          CodTraseu, PozTraseu, Delegat, CODMIJLTRANSP, Insotitor, CodAgenda,
          sum(Masa), sum(Volum), Den_Client
        from
          TMP_TraseuLivr_Comenzi where TRANSPCLIENT &lt;&gt; 2
        group by
          CodComanda, CodClient, CodJudet, CodLocalit, NrDoc, DataDoc,
          CodTraseu, PozTraseu, Delegat, CODMIJLTRANSP, Insotitor, CodAgenda,
          Den_Client
      );
    commit;
  end;

  procedure GET_TMP_ARTICOLELIVRATE is
  begin
    delete from TMP_TraseuLivr_ArtLivr;
    insert into TMP_TraseuLivr_ArtLivr
      (
        CodTraseu, Delegat, Insotitor, MIJLOCTRANSP,
        CodObiect, CodArticol,
        CodUM,
        CantComandat, CantAcceptat,
        Masa, Volum,
        DenObiect
      )
      (
        select
          CodTraseu, Delegat, Insotitor, CODMIJLTRANSP,
          CodObiect, CodArticol,
          CodUM,
          sum(CantComandat), sum(CantAcceptat),
          sum(Masa), sum(Volum),
          DenObiect
        from
          TMP_TraseuLivr_Comenzi
        where TRANSPCLIENT &lt;&gt; 2
        group by
          CodTraseu, Delegat, Insotitor, CODMIJLTRANSP,
          CodObiect, CodArticol,
          CodUM,
          DenObiect
      );
    commit;
  end;

  procedure GET_TMP_TRASEUART(aCodTraseu in number, aCodObiect in number) is
  begin
    delete from TMP_TraseuLivr_TraseuArtInfo;
    insert into TMP_TraseuLivr_TraseuArtInfo
      (
        CodTraseu, DenTraseu, SimbolTraseu,
        CodObiect
      )
      (
        select
          CodTraseuLivr, DenTraseu, SimbolTraseu,
          aCodObiect
        from
          TraseuLivr
        where
          CodTraseuLivr = aCodTraseu
      );
    update
      TMP_TraseuLivr_TraseuArtInfo
    set
      (CodArticol, DenArticol) =
      (
        select
          NAO.CodArticol, NA.Den_Articol
        from
          NArtObj NAO
          inner join NArt NA on NA.CodArticol = NAO.CodArticol
        where
          NAO.CodObiect = aCodObiect
      );
    delete from TMP_TraseuLivr_TraseuArt;
    insert into TMP_TraseuLivr_TraseuArt
      (
        CodClient,
        NrComanda, DataComanda,
        CodUM,
        CantComandat, CantAcceptat, CantRezervat,
        Masa, Volum,
        CodObiect,
        CodComanda1, CodComanda,
        MasaUM, VolumUM,
        InregNula
      )
      (
        select
          CodClient,
          NrDoc, DataDoc,
          CodUM,
          CantComandat, CantAcceptat, CantRezervat,
          Masa, Volum,
          CodObiect,
          CodComanda1, CodComanda,
          MasaO, VOlumO,
          InregNula
        from
          TMP_TraseuLivr_Comenzi
        where
          CodTraseu = aCodTraseu and
          CodObiect = aCodObiect
      );
    commit;
  end;

  procedure SET_ACCEPTAT is
  begin
    -- CantAcceptat
    for v_rec in
      (
        select
          CodComanda1,
          CantAcceptat
        from
          TMP_TraseuLivr_TraseuArt
      )
    loop
      update
        TMP_TraseuLivr_Comenzi
      set
        CantAcceptat = v_rec.CantAcceptat,
        Masa         = v_rec.CantAcceptat * MasaO,
        Volum        = v_rec.CantAcceptat * VolumO
      where
        CodComanda1 = v_rec.CodComanda1;
    end loop;
    commit;
  end;

  procedure UPD_COMENZICLIENTI(aDateInc in varchar2, aCheckFlagLucru in number) is
    lOraDateInc date;
    lVal number(20, 7);
    lDisc number(20, 7);
    lOldVal number(20, 7);
    lOldDisc number(20, 7);
  begin
    lOraDateInc := to_date(aDateInc, &apos;DD.MM.YYYY&apos;);
    for v_rec in
      (
        select
          CodComanda, CodComanda1, CantAcceptat,
          CodTraseu, PozTraseu, CodMijlTransp,
          Delegat, Insotitor,
          DataSosirii,
          InregNula
        from
          TMP_TraseuLivr_Comenzi
        where
          (aCheckFlagLucru = 0) or
          (FlagLucru = 1)
      )
    loop
      select
        nvl(CantAcceptat, 0) * nvl(PU, 0), -- lOldVal
        -(nvl(CantAcceptat, 0) * nvl(PU, 0) - nvl(CantAcceptat, 0) * nvl(PU, 0) * nvl(CoefDiscMaj, 1)), -- lOldDisc
        nvl(v_rec.CantAcceptat, 0) * nvl(PU, 0), -- lVal
        -(nvl(v_rec.CantAcceptat, 0) * nvl(PU, 0) - nvl(v_rec.CantAcceptat, 0) * nvl(PU, 0) * nvl(CoefDiscMaj, 1)) -- lDisc
      into
        lOldVal,
        lOldDisc,
        lVal,
        lDisc
      from Comanda1
      where CodComanda1 = v_rec.CodComanda1;
      update Comanda1
      set
        DataIncarcarii = lOraDateInc,
        CantAcceptat   = v_rec.CantAcceptat,
        RestAcceptat   = v_rec.CantAcceptat
      where
        CodComanda1 = v_rec.CodComanda1;
      update Comanda
      set
        --CodTraseuLivr = v_rec.CodTraseu,
        OrdineLivrare = v_rec.PozTraseu,
        --MijlTransp    = v_rec.CodMijlTransp,
        Insotitor     = v_rec.Insotitor,
        Delegat       = v_rec.Delegat,
        Valoare       = nvl(Valoare, 0) - (lOldVal + lOldDisc) + (lVal + lDisc),
        ValDiscount   = nvl(ValDiscount, 0) - lOldDisc + lDisc
      where
        CodComanda = v_rec.CodComanda;

    end loop;
    commit;
  end;

  procedure UPD_TRASEECLIENTI is
  begin
    for v_rec in
      (
        select
          CodTraseu,
          PozTraseu,
          CodAgenda
        from
          TMP_TraseuLivr_Comenzi
      )
    loop
      update
        NAgenda
      set
        CodTraseu = v_rec.CodTraseu,
        PozTraseu = v_rec.PozTraseu
      where
        CodAgenda = v_rec.CodAgenda;
    end loop;
    commit;
  end;

end PKG_TRASEULIVR; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0C6340AF2DA0A5499228E4A1FB04ADF1B1DF83E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TREZOR IS

CT_MONITOR constant varchar2(50) := &apos;MON_16&apos;;



PROCEDURE CUMULEAZA_EXTRASE(aCodMaster in number, aTipDoc in number, aCodBanca in number, aCodSubunit in number, aDataDoc in varchar2)
is
  aIndexLocal number;
  nr          number;
begin
  select count(*) into nr from trezor where codtrezor = aCodMaster;
  if nr = 1 then
    select nvl(max(IndexLocal), 0) into aIndexLocal from Trezor1 where codtrezor = aCodMaster;
    for v_rec in (SELECT * FROM TREZOR
                  WHERE
                    CODTREZOR         &lt;&gt; aCODMASTER
                    and TIPDOC        = aTipDoc
                    and SUBUNITATEA   = aCodSubunit
                    and CodBanca      = aCodBanca
                    and DataDoc       = to_date(aDataDoc, &apos;dd.mm.yyyy&apos;)
                 )
    loop
      for v_rec1 in (SELECT * FROM TREZOR1 WHERE CODTREZOR = V_REC.CODTREZOR ORDER BY INDEXLOCAL)
      loop
        aIndexLocal := aIndexLocal + 1;
        update trezor1
        set
          codtrezor = aCodMaster,
          IndexLocal = aIndexLocal
        where
          codTrezor1 = v_rec1.codtrezor1;
      end loop;
      
      update documente
      set
        coddoc = aCodMaster
      where
        coddoc = v_rec.codtrezor
        and tipdoc = aTipDoc;  

      update expert
      set
        coddoc = aCodMaster
      where
        coddoc = v_rec.codtrezor
        and tipdoc = aTipDoc;  


      delete from trezor  where codtrezor = v_rec.codtrezor;
      delete from jurnal  where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      delete from jurnal1 where Coddoc  = v_rec.codtrezor and tipdoc = aTipDoc;
      update jurnal1 set Dirty = 1
      where
        TipDoc = aTipDoc
        and CodDoc = aCodMaster;
    end loop;
  end if;
  commit;
end;






 PROCEDURE SAVE_CONSENT_INFO(aTipAPI IN NUMBER, aIBAN IN VARCHAR2, aTOKEN IN VARCHAR2, aConsentID IN VARCHAR2, aExternalID IN VARCHAR2)
 is
 PRAGMA AUTONOMOUS_TRANSACTION;
 nr number;
 begin
   select count(*) into nr from BANKAUTENTIF 
   WHERE
     COALESCE(TIP_API, 0) = aTipAPI
     AND IBAN = aIBAN;
     
   IF NR = 0 THEN
     INSERT INTO BANKAUTENTIF(COD, TIP_API, IBAN, TOKEN, CONSENTID, EXTERNALID, DATATOKEN)
     VALUES (SEQ_BANKAUTENTIF_COD.NEXTVAL, aTIPAPI, aIBAN, aTOKEN, aCONSENTID, aExternalID, SysDate);
   ELSE
     UPDATE BANKAUTENTIF
     SET
     (TIP_API, IBAN, TOKEN, CONSENTID, EXTERNALID, DATATOKEN) = (SELECT aTIPAPI, aIBAN, aTOKEN, aCONSENTID, aExternalID, SysDate FROM DUAL)
   WHERE
     COALESCE(TIP_API, 0) = aTipAPI
     AND IBAN = aIBAN;
   END IF;  
         
   COMMIT;     
 end;  
   
 
   



procedure NotifyStergereIncasareFact(aCodStingere in number)
is
begin
  FOR V_REC IN 
  ( select 
      g.coddoc,
      g.tipdoc
    from 
      stingere s
      inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
      inner join general g on g.codgeneral = o.codgeneral
    where
      s.codstingere = aCodStingere
  )
  LOOP
    NotifyModif(11, v_rec.coddoc, &apos;IESIRI&apos;);
  END LOOP;      

end;   
 
procedure NotifyModifSoldFact
is
begin
  FOR V_REC IN 
  (    
      SELECT
        stinse_out.coddoc,
        stinse_out.tipdoc,
        stinse_out.valoare,
        nvl(stinse_ini.valoare, 0) as valoare_in
      FROM  
      (
      select 
        g.coddoc,
        g.tipdoc,
        sum(s.valoare) as valoare 
      from 
        tmp_stingere s
        inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
        inner join general g on g.codgeneral = o.codgeneral
      group by g.coddoc, g.tipdoc
      ) stinse_out
       left join   
      (
      select 
        g.coddoc,
        g.tipdoc,
        sum(s.valoare) as valoare 
      from 
        tmp_stingere_initial s
        inner join obligpif o on o.codobligpif = s.codstinspif and o.semnificatie = 200
        inner join general g on g.codgeneral = o.codgeneral
      group by g.coddoc, g.tipdoc
      ) stinse_ini on stinse_ini.coddoc = stinse_out.coddoc and stinse_ini.tipdoc = stinse_out.tipdoc 
    where
      nvl(stinse_ini.valoare, 0) &lt;&gt; nvl(stinse_out.valoare, 0)  
  )
  LOOP
    NotifyModif(11, v_rec.coddoc, &apos;IESIRI&apos;);
  END LOOP;      

end;    


PROCEDURE SET_SKIPANALIZASOLD(FLAG IN NUMBER)
IS
BEGIN
  SkipAnalizaSOld := Flag;
END;

PROCEDURE SETNRDOC_I(aNRDOC IN NUMBER, aCARNET IN NUMBER)
IS
BEGIN
  CARNETDOC_I := ACARNET;
  NRDOC_I     := ANRDOC;
END;

FUNCTION PRELSERIADOC(aSERIADOC VARCHAR2) RETURN VARCHAR2
IS
  PRELSER VARCHAR2(10) := NULL;
BEGIN
 IF TRIM(aSERIADOC) IS NOT NULL THEN
   RETURN &apos; &apos; || aSERIADOC || &apos; &apos;;
 ELSE
   RETURN NULL;
 END IF;
END;

PROCEDURE UPDATE_VALTRANZ_STINGERI(RECID IN NUMBER)
IS
 BANCASITV   NUMBER(20) := 0;
 MONEDASITV  NUMBER(20) := 0;
BEGIN
  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;BancaSitV&apos;,  PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO BANCASITV  FROM DUAL;
    EXCEPTION WHEN OTHERS THEN BANCASITV := 0;
  END;

  BEGIN
    SELECT pkg_categconst.GetValConstanta(&apos;MonedaSitV&apos;, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU) INTO MONEDASITV FROM DUAL;
    EXCEPTION WHEN OTHERS THEN MONEDASITV := 0;
  END;



  -- Volum tranzactii CLIENT
  FOR V_REC IN
  (
  SELECT
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   TREZOR1 T1,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   IESIRI I
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC IN (29, 30, 31, 33)
    AND G_STG.CODDOC = T1.CODTREZOR1
    AND T1.CODTREZOR = RECID
    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 200
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODIES
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZC = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

-- Volum tranzactii FURNIZORI
-- INTRARI
  FOR V_REC IN
  (
  SELECT
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   TREZOR1 T1,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   INTRARI I
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC IN (29, 30, 31, 33)
    AND G_STG.CODDOC = T1.CODTREZOR1
    AND T1.CODTREZOR = RECID
    AND S.CODSTINSPIF = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 100
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = I.TIPDOC
    AND GSTINS.CODDOC = I.CODINTR
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;

  -- stingeri de DVI-uri
  FOR V_REC IN
  (
  SELECT
   CODSTINGERE,
   S.VALOARE * DECODE(NVL(GSTINS.CURS, 0), 0, 1, NVL(GSTINS.CURS, 0)) / PKG_MONEDE.GETCURSMONEDA(MONEDASITV, BANCASITV,TO_CHAR(D.DATADOC, &apos;DD.MM.YYYY&apos;)) AS VALOAREV
  FROM
   STINGERE S,
   OBLIGPIF O_STG,
   GENERAL  G_STG,
   TREZOR1 T1,
   OBLIGPIF OSTINS,
   GENERAL  GSTINS,
   DVI D
  WHERE
    S.CODSTINGATORPIF    = O_STG.CODOBLIGPIF
    AND G_STG.CODGENERAL = O_STG.CODGENERAL
    AND G_STG.TIPDOC IN (29, 30, 31, 33)
    AND G_STG.CODDOC    = T1.CODTREZOR1
    AND T1.CODTREZOR    = RECID
    AND S.CODSTINSPIF   = OSTINS.CODOBLIGPIF
    AND OSTINS.SEMNIFICATIE = 130
    AND GSTINS.CODGENERAL = OSTINS.CODGENERAL
    AND GSTINS.TIPDOC = 5
    AND GSTINS.CODDOC = D.CODDVI
  )
  LOOP
    UPDATE STINGERE
    SET
     VALTRANZF = V_REC.VALOAREV
    WHERE
      CODSTINGERE = V_REC.CODSTINGERE;
  END LOOP;



END;



FUNCTION CODCONTCEC(aCODNBANKCONT IN NUMBER, aSEMNIFICATIE IN NUMBER, aTIPDECONT IN NUMBER, aOBIECTTRANZ IN NUMBER, pAn IN NUMBER DEFAULT NULL, pLuna IN NUMBER DEFAULT NULL) RETURN NUMBER
IS
 aCODCONTCEC     NUMBER(20);
 FROMIOBANK      NUMBER(1)     := 0;
 aCODIOBANK      NUMBER(20)    := 0;
 aCODIOBANK1     NUMBER(20)    := 0;
 aCODNBANKCONT1  NUMBER(20)    := 0;
 aTIPTRANZINCURS VARCHAR2(10)  := &apos;?&apos;;
 aSIMBCONST      VARCHAR2(100) := &apos;?&apos;;
 acontPCEC       NUMBER(20)    := 0;
 acontPEFECTE    NUMBER(20)    := 0;
 acontPEFECTEREM NUMBER(20)    := 0;
 acontICEC       NUMBER(20)    := 0;
 acontIEFECTE    NUMBER(20)    := 0;
 acontIEFECTEREM NUMBER(20)    := 0;
 aAn             NUMBER(4)     := Nvl(pAn,   PKG_GLOBALS.AnLUCRU);
 aLuna           NUMBER(4)     := Nvl(pLuna, PKG_GLOBALS.LunaLUCRU);
BEGIN

  IF ASEMNIFICATIE = 500 OR (aSEMNIFICATIE = 600 AND aOBIECTTRANZ = 1)THEN
    IF    aTIPDECONT = 1 THEN aSIMBCONST := &apos;CPLATICEC&apos;;
    ELSIF aTIPDECONT = 2 THEN aSIMBCONST := &apos;CEFECTEPLATA&apos;;
    ELSIF aTIPDECONT = 3 THEN aSIMBCONST := &apos;CEFECTEREMISEPLATA&apos;;
    END IF;
  ELSE
    IF    aTIPDECONT = 1 THEN aSIMBCONST := &apos;CINCASARICEC&apos;;
    ELSIF aTIPDECONT = 2 THEN aSIMBCONST := &apos;CEFECTEINCASAT&apos;;
    ELSIF aTIPDECONT = 3 THEN aSIMBCONST := &apos;CEFECTEREMISEINCASAT&apos;;
    END IF;
  END IF;

  aCODCONTCEC := PKG_CATEGCONST.GETVALCONSTANTA(aSIMBCONST, aAn, aLuna);
  aTIPTRANZINCURS :=  Nvl(pkg_categconst.GetValConstanta(&apos;TIPTRANZINCURS&apos;, aAn, aLuna),&apos;?&apos;);

  IF aTIPTRANZINCURS = &apos;2&apos; THEN
    aCODNBANKCONT1 := PKG_CONTURIBANCI.GET_COD_NBANKCONT1(aCODNBANKCONT, aAn, aLuna) ;
    IF aCODNBANKCONT1 &gt; 0 THEN
      BEGIN
        SELECT CODIOBANCA INTO aCODIOBANK FROM NBANKCONT1 WHERE CODBANKCONT1 = aCODNBANKCONT1;
        EXCEPTION WHEN OTHERS THEN aCODIOBANK := 0;
      END;
      IF aCODIOBANK &gt; 0 THEN
        aCODIOBANK1 := PKG_CONFIGBANK.GETCODCARACTLUNA(aCODIoBank, aAn, aLuna);
      END IF;
    END IF;
  END IF;

  IF aTIPTRANZINCURS = &apos;2&apos; AND aCODIOBANK1 &gt; 0 THEN
    FROMIOBANK := 1;
  END IF;

  IF FROMIOBANK = 1 THEN
    BEGIN
      SELECT NVL(PCEC,0), NVL(PEFECTE, 0), NVL(PEFECTEREM, 0), NVL(ICEC, 0), NVL(IEFECTE, 0), NVL(IEFECTEREM, 0)
      INTO   acontPCEC,   acontPEFECTE,    acontPEFECTEREM,    acontICEC,    acontIEFECTE,    acontIEFECTEREM
      FROM IOBANK1
      WHERE CODIOBANK1 = aCODIOBANK1;
    EXCEPTION WHEN OTHERS THEN
      acontPCEC       := 0;
      acontPEFECTE    := 0;
      acontIEFECTEREM := 0;
      acontICEC       := 0;
      acontIEFECTE    := 0;
      acontIEFECTEREM := 0;
    END;

    IF ASEMNIFICATIE = 500 THEN
      IF    aTIPDECONT = 1 AND acontPCEC       &lt;&gt; 0 THEN aCODCONTCEC := acontPCEC;
      ELSIF aTIPDECONT = 2 AND acontPEFECTE    &lt;&gt; 0 THEN aCODCONTCEC := acontPEFECTE;
      ELSIF aTIPDECONT = 3 AND acontPEFECTEREM &lt;&gt; 0 THEN aCODCONTCEC := acontPEFECTEREM;
      END IF;
    ELSE
      IF    aTIPDECONT = 1 AND acontICEC       &lt;&gt; 0 THEN aCODCONTCEC := acontICEC;
      ELSIF aTIPDECONT = 2 AND acontIEFECTE    &lt;&gt; 0 THEN aCODCONTCEC := acontIEFECTE;
      ELSIF aTIPDECONT = 3 AND acontIEFECTEREM &lt;&gt; 0 THEN aCODCONTCEC := acontIEFECTEREM;
      END IF;
    END IF;

  END IF;

  RETURN Nvl(aCODCONTCEC,0);
END;

FUNCTION SIMBOLCONTCEC(aCODNBANKCONT IN NUMBER, aSEMNIFICATIE IN NUMBER, aTIPDECONT IN NUMBER, aOBIECTTRANZ IN NUMBER, aAn IN NUMBER DEFAULT NULL, aLuna IN NUMBER DEFAULT NULL) RETURN VARCHAR2
IS
BEGIN
  RETURN PKG_PLANCONTURI.GETSIMBOLCONT(CODCONTCEC(aCODNBANKCONT, aSEMNIFICATIE, aTIPDECONT, aOBIECTTRANZ, aAn, aLuna));
END;

FUNCTION GETDENPARTDIECTPECONT (aCODPART IN NUMBER) RETURN VARCHAR2
IS
aDENPART VARCHAR2(150);
BEGIN
  IF aCODPART = 0 THEN RETURN &apos;&apos;;
  ELSE
    BEGIN
      SELECT DEN_PART INTO aDENPART FROM NPART WHERE CODPART = aCODPART;
      EXCEPTION WHEN OTHERS THEN aDENPART := &apos;&apos;;
    END;
    RETURN &apos;(&apos; || aDENPART || &apos;)&apos;;
  END IF;
END;

FUNCTION GETGESTEVIDENTA(aGEST IN NUMBER) RETURN VARCHAR2
IS
 aDENGEST VARCHAR2(30) := &apos;&apos;;
BEGIN
/*
  IF NVL(aGEST, 0) &lt;&gt; 0 THEN
    BEGIN
      SELECT DEN_GEST INTO aDENGEST FROM NGEST WHERE CODGEST = aGEST;
      EXCEPTION WHEN OTHERS THEN aDENGEST := &apos;&apos;;
    END;
  END IF;*/
  RETURN &apos;(&apos; || aDENGEST || &apos;)&apos;;
END;

PROCEDURE SP_POSTRECORD_FROM_IMPORT( RecId OUT NUMBER ) IS
  TIPDOCCASABANCA INTEGER := 0;
  NR              INTEGER := 0;
  vCOD            NUMBER(20);
  MONEDA          NUMBER(20);
  OLDCARNETDOC    NUMBER (20) := 0;
  OLDNRDOC        NUMBER (20) := 0;

BEGIN
  SELECT TIPDOC INTO TIPDOCCASABANCA FROM TMP_TREZOR;
  SELECT CODMONEDA INTO MONEDA FROM TMP_TREZOR;

  SELECT SEQ_TREZOR_CODTREZOR.NextVal INTO RecID FROM DUAL;
  UPDATE TMP_TREZOR1 SET CODTREZOR = RecID;

    -- TREZOR
  INSERT INTO TREZOR ( CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,userid,datacreare,IDIMPORT)
  (SELECT RecId, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,pkg_globals.USERID,systimestamp, IDIMPORT  FROM TMP_TREZOR);

    -- TREZOR1
  FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL)  LOOP
    SELECT SEQ_TREZOR1_CODTREZOR1.NextVal INTO vCOD FROM DUAL;
    UPDATE TMP_GENERAL SET CODDOC = vCOD WHERE CODDOC = v_rec.CODTREZOR1;

    UPDATE TMP_OBLIGPIF SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;

    INSERT INTO TREZOR1
    ( CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC,
      DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA,  DATADECONT, AN, LUNA, OBS, AGENT, ANULAT,userid,datacreare)
   VALUES
   (vCod, RecID, v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC,
    v_rec.DOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC, v_rec.CURS, v_rec.COMISION,
    v_rec.OBIECTTRANZ, V_REC.SERIEDOC, v_rec.CODPART, v_rec.TIPDECONT, V_REC.PLATATVA, v_rec.DATADECONT,v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT,pkg_globals.USERID,systimestamp);
  END LOOP;

  -- GENERAL
  FOR v_rec IN (SELECT * FROM TMP_GENERAL)  LOOP
    SELECT SEQ_GENERAL_CODGENERAL.NextVal INTO vCOD FROM DUAL;
    UPDATE TMP_OBLIGPIF SET CODGENERAL = vCOD
    WHERE
    CODGENERAL = v_rec.CODGENERAL;

    INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE)
    VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE);
  END LOOP;



   -- OBLIGPIF
     DELETE TMP_OBLIGPIF_ASOCIAT;
     INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODANALIZANOD, TVANEDED, PROCTVA)
     (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA,CODANALIZANOD, TVANEDED, PROCTVA FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751));
     DELETE TMP_OBLIGPIF  WHERE SEMNIFICATIE IN (700, 701, 750, 751);

    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF)  LOOP
      IF V_REC.CODOBLIGPIF &lt; 0 THEN
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;
      ELSE
        vCOD := V_REC.CODOBLIGPIF;
      END IF;

      UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

      UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA)
      VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE,
      v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, v_rec.CODGEST, V_REC.CODNPARCAUT, v_Rec.CODANALIZANOD,
      V_REC.TVANEDED, V_REC.PROCTVA) ;
    END LOOP;


    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF)  LOOP
      IF V_REC.CODOBLIGPIF &lt; 0 THEN
        SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;
      ELSE
        vCOD := V_REC.CODOBLIGPIF;
      END IF;


      UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = vCOD WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;

      UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA)
      VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST,
              v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, v_rec.CODGEST, V_REC.CODNPARCAUT,
              v_rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA) ;
    END LOOP;


    -- STINGERE --
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;
      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE);
    END LOOP;


-- actualizez restul obligatiilor stinse de tranzactiile documentului salvat

  UPDATE OBLIGPIF O
  SET
    REST =
      (
        CASE
         WHEN VALOARE &gt;= 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        END
       )
    WHERE
     O.CODOBLIGPIF IN
     ( SELECT CODSTINSPIF FROM TMP_STINGERE UNION SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
       UNION
       SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
     );

-- actualizez restul pentru tranzactiile care nasc obligatii de plata/incasare iar pe cele care doar sting le pun pe zero;
  UPDATE OBLIGPIF O
  SET
    O.REST  =
     (
      CASE
        WHEN ((O.SEMNIFICATIE IN   (310, 410, 500, 600, 330, 430))OR(O.SEMNIFICATIE IN (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND O.VALOARE &gt;= 0 THEN O.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        WHEN ((O.SEMNIFICATIE IN   (310, 410, 500, 600, 330, 430))OR(O.SEMNIFICATIE IN (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND O.VALOARE &lt; 0 THEN O.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
        WHEN O.SEMNIFICATIE NOT IN (310, 410, 500, 600, 800, 801, 1100, 1101, 330, 430) THEN 0
        WHEN O.SEMNIFICATIE IN     (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) = 0 THEN 0
        WHEN O.SEMNIFICATIE IN (1100, 1101) THEN O.VALOARE
      END)
    WHERE
    O.CODGENERAL IN
    (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RECID));

  COMMIT;
END;



FUNCTION EXISTADOCUMENTUL(CODDOC IN NUMBER) RETURN NUMBER
IS
  NR NUMBER(10) := 0;
BEGIN
  BEGIN
    SELECT COUNT(*) INTO NR FROM TREZOR WHERE CODTREZOR = CODDOC;
    EXCEPTION WHEN OTHERS THEN NR := 0;
  END;
  RETURN NR;
END;


FUNCTION OBLIGATIE_STINSA(aCODOBLIGPIF IN NUMBER) RETURN NUMBER
IS
NR NUMBER(18) := 0;
BEGIN
  SELECT NVL(COUNT(*), 0) INTO NR FROM STINGERE WHERE CODSTINSPIF = aCODOBLIGPIF AND VALOARE &lt;&gt; 0;


  IF NR = 0 THEN
    SELECT NVL(COUNT(*), 0) INTO NR FROM NSERTAR1 WHERE CODOBLIGPIF = aCODOBLIGPIF;
  END IF;

  IF NR = 0 THEN
    SELECT NVL(COUNT(*), 0) INTO NR FROM PLATI1 WHERE CODOBLIGPIF = aCODOBLIGPIF;
  END IF;


  RETURN NR;
END;


FUNCTION TOTAL_STINS_OBLIGATIE(aCODOBLIGPIF IN NUMBER) RETURN NUMBER
IS
TOTAL NUMBER(20, 7) := 0;
BEGIN
  SELECT SUM(VALOARE) INTO TOTAL FROM STINGERE WHERE CODSTINSPIF = aCODOBLIGPIF;
  RETURN TOTAL;
END;


FUNCTION OPERAT_ANULAT_OK(aTIPDOC IN NUMBER, aCODDOC IN NUMBER) RETURn NUMBER
IS
 aOPERAT NUMBER(1) := 1;
 aANULAT NUMBER(1) := 0;

BEGIN
  IF aTIPDOC IN (1, 2, 3, 4, 5, 6, 7) THEN
    BEGIN
      SELECT OPERAT, ANULAT INTO aOPERAT, aANULAT FROM INTRARI WHERE CODINTR = aCODDOC;
      EXCEPTION WHEN OTHERS THEN aOPERAT := 0; aANULAT := 1;
    END;
  END IF;

  IF aTIPDOC IN (19, 20, 21, 22, 24, 25, 26) THEN
    BEGIN
      SELECT OPERAT, ANULAT INTO aOPERAT, aANULAT FROM IESIRI WHERE CODIES = aCODDOC;
      EXCEPTION WHEN OTHERS THEN aOPERAT := 0; aANULAT := 1;
    END;
  END IF;


  IF aTIPDOC IN (29, 30, 31, 33) THEN
    BEGIN
      SELECT  ANULAT INTO aANULAT FROM TREZOR1 WHERE CODTREZOR1 = aCODDOC;
      EXCEPTION WHEN OTHERS THEN aOPERAT := 0; aANULAT := 1;
    END;
  END IF;

  IF aOPERAT = 1 AND aANULAT = 0 THEN RETURN 1;
                                 ELSE RETURN 0;
  END IF;
END;

FUNCTION TOTAL_STINS_TVA(aCODOBLIGPIF IN NUMBER) RETURN NUMBER
IS
  TOTAL NUMBER(20, 7)  := 0;
BEGIN

  SELECT SUM(NVL(G.TVA, 0)) INTO TOTAL
  FROM
    STINGERE S,
    OBLIGPIF O,
    GENERAL  G
  WHERE
    S.CODSTINSPIF = aCODOBLIGPIF AND O.CODOBLIGPIF = S.CODSTINGATORPIF AND G.CODGENERAL = O.CODGENERAL
    AND OPERAT_ANULAT_OK(G.TIPDOC, G.CODDOC) = 1;


  RETURN TOTAL;
END;


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CODTREZOR INTO Tmp FROM TREZOR
  WHERE CODTREZOR = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
TIPDOCCASABANCA NUMBER(20);

 aCodSubunit NUMBER(20);
 aDataDoc DATE;
 aDoc varchar2(200);
 aCARNETDOC NUMBER(20);
 aNRDOC NUMBER(20);


BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;
  SP_LOCKRECORD(RecId);
  SELECT TIPDOC, SUBUNITATEA, DATADOC, NUMEDOC||&apos;/&apos;||DATADOC, NVL(CARNETDOC,0),  NVL(NRDOC, 0) INTO
         TIPDOCCASABANCA , aCodSubunit, aDataDoc ,aDoc, aCARNETDOC, aNRDOC
  FROM TREZOR WHERE CODTREZOR = RecID;

 IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

   WINMADMIN.PKG_USERFIRME.PostLog(&apos;TREZOR&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME,
                                    aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
 END IF;
  PKG_CFGTABLES.EXT_DELETERECORD (recId, TIPDOCCASABANCA);
  DELETE TMP_TREZOR1;
  INSERT INTO TMP_TREZOR1 (CODTREZOR1, CODSERTAR, CodPLATA1)
  (SELECT CODTREZOR1, CODSERTAR, CodPLATA1 FROM TREZOR1 WHERE CODTREZOR = RECID);

  DELETE TMP_OBLIGPIF;
  INSERT INTO TMP_OBLIGPIF (CODOBLIGPIF, CODTRANSA)
  (SELECT CODOBLIGPIF, CODTRANSA FROM OBLIGPIF WHERE CODGENERAL IN
     (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN
       (SELECT CODTREZOR1 FROM TMP_TREZOR1)
      )
  );

  DELETE TMP_STINGERE;
  INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODPLATA1)
  SELECT CODSTINGERE, CODSTINSPIF, CODPLATA1 FROM STINGERE WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

-- ordinea de stergere trebuie pastrata pentru a nu viola un constraint
-- DELETE FROM STINGERE WHERE CODSTINGERE IN (SELECT CODSTINGERE FROM TMP_STINGERE);
   FOR V_REC IN (SELECT * FROM TMP_STINGERE)
   LOOP
     NotifyStergereIncasareFact( V_REC.CODSTINGERE);
     DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;
     IF NVL(V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
       UPDATE PLATI1
       SET
         STINSA = 0,
         REST = VALOARE
       WHERE
         CODPLATA1 = V_REC.CODPLATA1;
     END IF;
   END LOOP;


--  DELETE FROM OBLIGPIF WHERE CODOBLIGPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);

  FOR V_REC IN
  (SELECT * FROM OBLIGPIF O  WHERE EXISTS (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF WHERE CODOBLIGPIF = O.CODOBLIGPIF))
  LOOP
     FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF)
     LOOP

       FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC in  (52, 106)) LOOP
         UPDATE NCONTRUL
         SET
           RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
           RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV,
  				 RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
					 RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
         WHERE
           CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

         FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTD AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
         LOOP
           UPDATE NCONTRULSUB
           SET
             RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
             RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV,
  				   RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
					   RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
           WHERE
             CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
         END LOOP;


         UPDATE NCONTRUL
         SET
           RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
           RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV,
  				 RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
					 RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
         WHERE
           CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

         FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA)
         LOOP
           UPDATE NCONTRULSUB
           SET
             RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
             RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV,
    				 RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
	  				 RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
           WHERE
             CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_RECJURN.SUBUNITATEA;
         END LOOP;

       END LOOP;



       DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC in (52, 106);
       DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
       DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
       DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
     END LOOP;

     DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
     DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
  END LOOP ;



  DELETE GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1);


-- inainte de stergere din TREZOR1 reactivez numerele
  FOR V_REC IN (SELECT * FROM TREZOR1 WHERE  CodTREZOR = RecId)
  LOOP
    DELETE FROM TAXDECL WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
    IF V_REC.CARNETDOC &lt;&gt; 0 AND V_REC.NRDOC &lt;&gt; 0
    THEN
      PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
      PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETDOC);
    END IF;
  END LOOP;


  DELETE FROM TREZOR1 WHERE CODTREZOR = RecID;
  DELETE FROM TREZOR WHERE CODTREZOR = RecID;

  UPDATE OBLIGPIF O
  SET
    REST =
      (CASE
         WHEN VALOARE &gt;= 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END),
    RESTTVA =
      (CASE
         WHEN VALOARE &gt;= 0 THEN NVL(DINCARETVA, 0)  - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
         WHEN VALOARE &lt; 0  THEN  NVL(DINCARETVA, 0) + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       END)
  WHERE
    O.CODOBLIGPIF IN (SELECT CODSTINSPIF FROM TMP_STINGERE);


  FOR V_REC IN (SELECT * FROM JURNAL WHERE CODDOC = RecID AND TIPDOC = TIPDOCCASABANCA) LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV,
 		  RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
    WHERE
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTD AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCD  = RULAJCD  - V_REC.VALOARE,
        RULAJVCD = RULAJVCD - V_REC.VALOAREV,
				RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
				RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV,
    	RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
			RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
    WHERE
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    FOR V_REC_JURN_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CONTC AND  AN = V_REC.AN AND LUNA = V_REC.LUNA)
    LOOP
      UPDATE NCONTRULSUB
      SET
        RULAJCC  = RULAJCC  - V_REC.VALOARE,
        RULAJVCC = RULAJVCC - V_REC.VALOAREV,
  			RULAJC_IFRS   = RULAJC_IFRS   - V_REC.VALOARE_IFRS,
				RULAJVC_IFRS  = RULAJVC_IFRS  - V_REC.VALOAREV_IFRS
      WHERE
        CODCONTRUL = V_REC_JURN_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
    END LOOP;


  END LOOP;

  DELETE FROM JURNAL  WHERE CODDOC = RecID AND TIPDOC = TIPDOCCASABANCA;
  DELETE FROM JURNAL1 WHERE CODDOC = RecID AND TIPDOC = TIPDOCCASABANCA;

  DELETE EXPERT1 WHERE CODEXPERT in (SELECT CODEXPERT FROM EXPERT WHERE CODDOC = RecID and TIPDOC = TIPDOCCASABANCA);
  DELETE EXPERT WHERE CODDOC = RecID and TIPDOC = TIPDOCCASABANCA;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE NVL(CODTRANSA, 0) &lt;&gt; 0)
  LOOP
    UPDATE OBLIGPIF
    SET
     RESTTRANSA = VALOARE - NVL((SELECT SUM(O.VALOARE * NVL(G.CURS, 1) / NVL(T1.CURS, 1))
                                 FROM
                                   OBLIGPIF O,
                                   GENERAL G,
                                   TREZOR1 T1
                                  WHERE
                                    CODTRANSA = V_REC.CODTRANSA
                                    AND G.CODGENERAL = O.CODGENERAL
                                    AND T1.CODTREZOR1 = G.CODDOC
                                  ),
                                 0)
    WHERE
     CODOBLIGPIF = V_REC.CODTRANSA;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE NVL(CODSERTAR, 0) &lt;&gt; 0)
  LOOP
    UPDATE NSERTAR
    SET
     DEPUS = 0
    WHERE
      CODSERTAR = V_REC.CODSERTAR;
  END LOOP;
  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE NVL(CODPLATA1, 0) &lt;&gt; 0)
  LOOP
    UPDATE PLATI1
    SET
      STINSA = 0,
      REST = VALOARE
    WHERE
      CODPLATA1 = V_REC.CODPLATA1;
  END LOOP;
  DELETE FROM DocAsoc    WHERE (CODDOC = RECID AND TIPDOC = TIPDOCCASABANCA)or(CODDOCASOC = RECID AND TIPDOCASOC = TIPDOCCASABANCA);

  IF aCARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(aCARNETDOC, aNRDOC);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(aCARNETDOC);
  END IF;



  NotifyModif(2, RecId, &apos;TREZOR&apos;);


  COMMIT;
END;


PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_TREZOR FIELDS( CODTREZOR ) VALUES (0) ;
  -- mTrezor (104)
  PKG_CFGTABLES.EXT_INSERTRECORD(104); 
  COMMIT;
END;



PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
TIPDOCCASABANCA NUMBER(20);
CODNBANKCONT    NUMBER(20);
MONEDA          NUMBER(20);
aICONTPERS      NUMBER(20);
aMONEDAPERS     NUMBER(20);
DOCOPERAT       NUMBER(1) := 0;
aCODSUBUNITSTINS NUMBER(20) := 0;
NEWCONSTVALUE  VARCHAR(100) := &apos;&apos;;
NEWCONSTSIMBOL  VARCHAR(100) := &apos;&apos;;
aCODNBANKCONT1  NUMBER(20) := 0;
aCODIOBANK      NUMBER(20) := 0;
SOLDLEIBANKA    NUMBER(20, 7) := 0;
SOLDVALUTABANKA NUMBER(20, 7) := 0;

SOLDLEIPERS     NUMBER(20, 7) := 0;
SOLDVALUTAPERS  NUMBER(20, 7) := 0;
aProcStopaj     NUMBER(5, 2)  := 0;

BEGIN
  PKG_STOC_GENERARE_FACTURI.MAKE_CONFIG_LUNA;
 -- pregatesc variabilele antemp si anprec pentru calcul sold cont
  PKG_GLOBALS.SETLUNATEMP(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
  PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, PKG_GLOBALS.ANPRECEDENT, PKG_GLOBALS.LUNAPRECEDENTA);

  PKG_CONTURIBANCI.MAKE_CURS_BANKCONT_LUNA(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.LUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.ANLUCRU));

  IF RECID &gt; 0  THEN
      SELECT TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, OPERAT
      INTO  TIPDOCCASABANCA,CODNBANKCONT, aICONTPERS, aMONEDAPERS, DOCOPERAT
      FROM
        TREZOR
      WHERE
       CODTREZOR = RecID;

 -- pregatesc variabila CONTBANCACURENT pentru calcul sold cont
      
      IF SkipAnalizaSold = 0 then
        IF TIPDOCCASABANCA &lt;&gt; 33 THEN
          PKG_CONTURIBANCI.SETCONTBANCACURENT(CODNBANKCONT);
          BEGIN
            SELECT SOLDLEI, SOLDVALUTA  INTO SOLDLEIBANKA, SOLDVALUTABANKA FROM V_SOLDBANKLUNA ;
            EXCEPTION WHEN OTHERS THEN BEGIN
              SOLDLEIBANKA    := 0;
              SOLDVALUTABANKA := 0;
            END;
          END;
        ELSE
          PKG_NOMPERS.SET_PERSOANA_CURENTA(CODNBANKCONT);
          PKG_NOMPERS.SET_ICONTPERS_CURENT(aICONTPERS);
          PKG_NOMPERS.SET_MONEDAPERS_CURENT(aMONEDAPERS);

          BEGIN
            SELECT SOLDLEI, SOLDVALUTA  INTO SOLDLEIPERS, SOLDVALUTAPERS FROM V_SOLDPERSOANA_LUNA;
            EXCEPTION WHEN OTHERS THEN BEGIN
              SOLDLEIPERS    := 0;
              SOLDVALUTAPERS := 0;
            END;
          END;
        END IF;
      END IF;  


-- TREZOR1  INAINTE DE TREZOR pentru a calcula suma PLATI si INCASARI
       INSERT INTO TMP_TREZOR1
        (
         CODTREZOR1, CODTREZOR,   INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC,  NRDOC, DATADOC, VALDOC, CURS, COMISION,
         OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA,  CODSERTAR, NRI, CODCOMANDA, CODPLATA1, DATADECONT,  AN, LUNA, OBS, AGENT, ANULAT, NUMEAGENT,CODCENTRU,
         IDENTIFLINIE, CODGEST, CODCMDINT1, CMDINT, TAXCODE, TAXBASE
        )
       SELECT * FROM
       (SELECT
          T1.CODTREZOR1, T1.CODTREZOR, T1.INDEXLOCAL, T1.TIPTRANZ, T1.CARNETDOC, T1.DOC,  T1.NRDOC, T1.DATADOC, T1.VALDOC, T1.CURS, T1.COMISION,
          T1.OBIECTTRANZ, T1.SERIEDOC, T1.CODPART, T1.TIPDECONT, T1.PLATATVA, T1.CODSERTAR, T1.NRI, T1.CODCOMANDA, CODPLATA1, T1.DATADECONT, T1.AN, T1.LUNA, T1.OBS, T1.AGENT, T1.ANULAT, (SELECT NUME || &apos; &apos; || PRENUME FROM NPERS WHERE CODPERS = T1.AGENT) ,T1.CODCENTRU,
          T1.DOC||&apos; &apos;||T1.NRDOC||&apos;/&apos;||TO_CHAR(T1.DATADOC, &apos;DD.MM.YYYY&apos;)||&apos; - Valoare : &apos;||T1.VALDOC IDENTIFLINIE, T1.CODGEST, T1.CODCMDINT1, C.NRDOC CMDINT,
          CASE WHEN LENGTH(TXDL.TAXCODE_STR) &gt; 250 THEN SUBSTR(TXDL.TAXCODE_STR,0,246)||&apos;...&apos; ELSE TXDL.TAXCODE_STR END,
          CASE WHEN LENGTH(TXDL.TAXBASE_STR) &gt; 250 THEN SUBSTR(TXDL.TAXBASE_STR,0,246)||&apos;...&apos; ELSE TXDL.TAXBASE_STR END
        FROM
          TREZOR1 T1
          LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA = T1.CODCMDINT1
          LEFT JOIN COMANDA C ON C1.CODCOMANDA = C.CODCOMANDA
          LEFT JOIN (SELECT TXD.TIPDOC,
                              TXD.CODDOC,
                              VC2_NT_TO_VC3200(CAST(COLLECT(TO_CHAR(TXD.TAXCODE)
                                                            ORDER BY
                                                            TXD.CODDOC1) AS
                                                    vc2_nt) ,
                                               &apos;;&apos;) AS TAXCODE_STR,
                              VC2_NT_TO_VC3200(CAST(COLLECT(TO_CHAR(TXD.TAXBASE)
                                                            ORDER BY
                                                            TXD.CODDOC1) AS
                                                    vc2_nt),
                                               &apos;;&apos;) AS TAXBASE_STR
                         FROM TAXDECL TXD
                        GROUP BY TXD.TIPDOC, TXD.CODDOC) TXDL
                                                               ON TXDL.TIPDOC = TIPDOCCASABANCA
                                                              and TXDL.CODDOC = T1.CODTREZOR1
        WHERE t1.CODTREZOR = RecID
        )
        ORDER BY INDEXLOCAL;

-- returo
    insert into TMP_RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
     select  rs.CODRETUROSTINS,
                rs.CODRETURO,
                rs.CODDOC,
                rs.TIPDOC,
                rs.VALOARE,
                rs.STARTEDAT,
                rs.VOUCHERBARCODE
     from RETUROSTINS rs where rs.tipdoc = TIPDOCCASABANCA and rs.coddoc in (select ttrz1.CODTREZOR1 from TMP_TREZOR1 ttrz1);    
      
-- TREZOR
      INSERT INTO TMP_TREZOR
      (CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, CODBANK,
       NRCONT, CODMONEDA, SIMBOLMONEDA, SOLDCURENT, INCASARI, PLATI, AGENT, OPERAT, BLOCAT, SUBUNITATEA, CREDIT, CURSREG, UserID,
       CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
      (
        SELECT T.CODTREZOR, T.TIPDOC, T.CODBANCA, T.ICONTPERS, T.MONEDAPERS, T.DATADOC,
               T.NUMEDOC,   T.AN,     T.LUNA,    NVL(B.CODBANK, 0),
       CASE
         WHEN TIPDOC = 33 THEN
         PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(1100, T.ICONTPERS, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(T.CODBANCA, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
         ELSE B.NRCONT
       END,
--     B.CODMONEDA,
       CASE
         WHEN TIPDOC &lt;&gt; 33 THEN B.CODMONEDA
         ELSE NULL
       END,

       CASE
         WHEN TIPDOC = 33 THEN PKG_MONEDE.GET_SIMBOL_MONEDA(T.MONEDAPERS)
         ELSE M.SIMBOL
       END,-- simbolmoneda

       NVL
       (CASE
         WHEN TIPDOC &lt;&gt; 33 AND B.CODMONEDA  =  0 THEN SOLDLEIBANKA
         WHEN TIPDOC &lt;&gt; 33 AND B.CODMONEDA  &lt;&gt; 0 THEN SOLDVALUTABANKA
         WHEN TIPDOC =  33 AND T.MONEDAPERS =  0 THEN SOLDLEIPERS
         WHEN TIPDOC =  33 AND T.MONEDAPERS &lt;&gt; 0 THEN SOLDVALUTAPERS
       END, 0),-- soldCURENT

       (SELECT NVL(SUM(VALDOC), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 AND ANULAT = 0 AND TIPTRANZ = 1),-- incasari

       (SELECT NVL(SUM(VALDOC), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 AND ANULAT = 0 AND TIPTRANZ = 0) +
       (SELECT NVL(SUM(COMISION), 0) FROM TMP_TREZOR1 WHERE DOCOPERAT = 1 AND ANULAT = 0)
       , -- plati
       AGENT,
       OPERAT,
       BLOCAT,
       T.SUBUNITATEA,
       CASE
         WHEN TIPDOC = 33 THEN  0
         ELSE B.CREDIT
       END AS CREDIT,
       CASE
         WHEN TIPDOC = 33 THEN  0
         ELSE REG.CURS
       END AS CURSREG,
       UserID,
       T.CODANALIZA,
       T.CARNETDOC,
       T.NRDOC,
       T.SERIADOC,
       T.LISTAT
      FROM
        TREZOR T
        LEFT OUTER JOIN NBANKCONT B ON B.CODBANKCONT = T.CODBANCA
        LEFT OUTER JOIN TMP_CURS_BANKCONT_LUNA REG ON REG.CODBANKCONT = T.CODBANCA
        LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA     = B.CODMONEDA
      WHERE
      CODTREZOR = RecID
      );
-- GENERAL
       INSERT INTO TMP_GENERAL
       ( CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA,  SEMNIFICATIE, FARAREG )

       (SELECT
          CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG
        FROM
          GENERAL
        WHERE
          TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TMP_TREZOR1)
        );

-- OBLIGPIF
       INSERT INTO TMP_OBLIGPIF
       (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, DINCARETVA, RESTTVA, TVAAFISAT)
       SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD,
       TVANEDED, PROCTVA, DINCARETVA, RESTTVA, TVAAFISAT
       FROM
       (SELECT * FROM OBLIGPIF WHERE CODGENERAL IN (SELECT CODGENERAL FROM TMP_GENERAL))
       ORDER BY CODOBLIGPIF;

-- STINGERE
       INSERT INTO TMP_STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, Tipdocplati, DINCARETVA)
       ( SELECT CODSTINGERE, CODSTINSPIF, S.CODSTINGATORPIF, S.VALOARE, S.CODPLATA1, P.TipDoc, S.DINCARETVA
			   FROM STINGERE S
				 left join PLATI1 P1 on P1.CodPlata1 = S.CodPlata1
				 left join PLATI  P  on P .CodPlata  = P1.CodPlata
				 WHERE CODSTINGATORPIF IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF));



      SELECT CODMONEDA INTO MONEDA FROM TMP_TREZOR;


-- recodificare ICONT CECURI
      FOR V_REC IN
      (SELECT O.CODOBLIGPIF, T1.TIPDECONT
       FROM
         TMP_OBLIGPIF O,
         TMP_GENERAL G,
         TMP_TREZOR1 T1
       WHERE
         O.SEMNIFICATIE IN (500, 600)
         AND O.CODGENERAL = G.CODGENERAL
         AND T1.CODTREZOR1 = G.CODDOC
       )
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           ICONT = V_REC.TIPDECONT
         WHERE
           CODOBLIGPIF = V_REC.CODOBLIGPIF;
       END LOOP;



     -- recodificare ICONT CEC-uri stinse
       FOR V_REC IN
       (
       SELECT
         O.CODOBLIGPIF,
         OS.SEMNIFICATIE,
         TS1.TIPDECONT,
         TS1.OBIECTTRANZ,
         TS.CODBANCA
       FROM
         TMP_OBLIGPIF O,
         TMP_STINGERE S,
         OBLIGPIF OS,
         GENERAL GS,
         TREZOR1 TS1,
         TREZOR TS
       WHERE
         S.CODSTINGATORPIF = O.CODOBLIGPIF
         AND OS.CODOBLIGPIF = S.CODSTINSPIF
         AND OS.SEMNIFICATIE IN (500, 600)
         AND O.SEMNIFICATIE IN (300, 320, 400, 420)
         AND GS.CODGENERAL  = OS.CODGENERAL
         AND TS1.CODTREZOR1 = GS.CODDOC
         AND TS.CODTREZOR   = TS1.CODTREZOR
       )
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           ICONT              = V_REC.TIPDECONT,
           SIMBOLCONT         = SIMBOLCONTCEC(V_REC.CODBANCA, V_REC.SEMNIFICATIE, V_REC.TIPDECONT, V_REC.OBIECTTRANZ),
           CONTBANKTRANZACTIE = V_REC.CODBANCA,
           OBIECTTRANZSTINS   = V_REC.OBIECTTRANZ
         WHERE
           CODOBLIGPIF = V_REC.CODOBLIGPIF;

       END LOOP;


       UPDATE TMP_OBLIGPIF OB
       SET
         SIMBOLCONT =
          CASE
             WHEN SEMNIFICATIE IN (300, 320) AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1), 0) = 500
             THEN OB.SIMBOLCONT -- le-am codificat mai sus PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(OB.ICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))



             WHEN SEMNIFICATIE IN (400, 420) AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1), 0) = 600
             THEN OB.SIMBOLCONT-- le-am codificat mai sus PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(OB.ICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))

             WHEN SEMNIFICATIE IN (800, 801) THEN 
						    CASE WHEN OB.ICONT &lt; 10000  
								THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(OB.ICONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU))
								ELSE PKG_PLANCONTURI.GETSIMBOLCONT(OB.ICONT)
								END
             WHEN SEMNIFICATIE IN (900, 901, 950, 951) THEN PKG_PLANCONTURI.GETSIMBOLCONT(OB.ICONT)
             WHEN SEMNIFICATIE = 1000 THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(CODNBANKCONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
             WHEN SEMNIFICATIE IN (1100, 1101)  THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPERS.GET_PERS_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))

             ELSE  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(OB.SEMNIFICATIE, OB.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(OB.CODPART, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)))
         END,

         FARAREG    = (SELECT FARAREG FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL),
         CODTREZOR1 = (SELECT CODDOC FROM TMP_GENERAL G WHERE G.CODGENERAL = OB.CODGENERAL),
         CURS       = NVL((SELECT CURS FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 1),
         TVA        = NVL((SELECT TVA  FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
         MONEDA     = NVL((SELECT MONEDA  FROM TMP_GENERAL WHERE CODGENERAL = OB.CODGENERAL), 0),
         SEMNIFCODSTINS =
            NVL((SELECT O.SEMNIFICATIE
                 FROM
                 TMP_STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1),0),
         CURSISTORIC  =
            NVL((SELECT G.CURS
                 FROM
                 TMP_STINGERE S
                 LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1),0),
         DENDOCLEGATURA =
         ( CASE
             /* PLATA FURN - FACTURA IN NEGRU*/
             WHEN SEMNIFICATIE  = 300 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 100
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) ||  I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN INTRARI I ON I.CODINTR = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* PLATA FURN - DVI*/
             WHEN SEMNIFICATIE  = 300 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 130
             THEN
             ( SELECT &apos;DVOT&apos; || D.NRDOC || &apos;(&apos; || to_char(D.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN DVI D ON D.CODDVI = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* INCASARE CLIENT - FACTURA IN NEGRU*/
             WHEN SEMNIFICATIE  = 400 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 200
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN IESIRI I ON I.CODIES = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* PLATA FURN - NOTA CONTABILA IN NEGRU*/
             WHEN SEMNIFICATIE  = 300 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1201
             THEN
             ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                 LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* PLATA FURN - OBLIGATIE DIN COMPENSARI IN NEGRU*/
             WHEN SEMNIFICATIE  = 300 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1351
             THEN
             ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* INCASARE CLIENT - NOTA CONTABILA IN NEGRU*/
             WHEN SEMNIFICATIE  = 400 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1200
             THEN
             ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                 LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* INCASARE CLIENT - COMPENSARE IN NEGRU*/
             WHEN SEMNIFICATIE  = 400 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN ( 1301)
             THEN
             ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* LITIGII*/
             WHEN SEMNIFICATIE  = 400 AND
                  NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN (1303)
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S
                 LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
                 LEFT OUTER JOIN OBLIGPIF F ON F.CODOBLIGPIF = O.CODOBLIGASOCIAT
                 LEFT OUTER JOIN GENERAL GF ON GF.CODGENERAL = F.CODGENERAL
                 LEFT OUTER JOIN IESIRI I ON I.CODIES = GF.CODDOC AND I.TIPDOC = GF.TIPDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* PLATA FURN - STINGERE CEC */
             WHEN SEMNIFICATIE  = 300 AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 500
             THEN
             ( SELECT T.DOC || PRELSERIADOC(T.SERIEDOC) || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* INCASARE CLIENT - STINGERE CEC */
             WHEN SEMNIFICATIE  = 400 AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 600
             THEN
             ( SELECT T.DOC || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR FURN* - PLATA AVANS SAU RETUR CEC */
             WHEN SEMNIFICATIE  = 320 AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN (310, 330,  500)
             THEN
             ( SELECT T.DOC || PRELSERIADOC(T.SERIEDOC) || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
             )

             /* RETUR CLIENT* - INCASARE AVANS SAU RETUR CEC */
             WHEN SEMNIFICATIE  = 420 AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN (410, 430, 600)
             THEN
             ( SELECT T.DOC || PRELSERIADOC(T.SERIEDOC) || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
             )

             /* RETUR FURN* - FACTURA IN ROSU */
             WHEN SEMNIFICATIE  = 320 AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 100
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN INTRARI I ON I.CODINTR = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR FURN* - FACTURA IN ROSU VAMA */
             WHEN SEMNIFICATIE  = 320 AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 130
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN DVI D ON D.CODDVI = G.CODDOC AND G.TIPDOC = 5
                 LEFT OUTER JOIN INTRARI I ON I.CODINTR = D.CODINTR
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR FURN* - OBLIGATIE DIN NOTE CONTABILE */
             WHEN SEMNIFICATIE  IN (320, 420) AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1200
             THEN
             ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                 LEFT OUTER JOIN NC   N ON N.CODNC   = N1.CODNC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR FURN* - OBLIGATIE DIN COMPENSARI */
             WHEN SEMNIFICATIE  = 320 AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN (1301)
             THEN
             ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )


             /* RETUR CLIENT* - FACTURA IN ROSU */
             WHEN SEMNIFICATIE  = 420 AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 200
             THEN
             ( SELECT I.PREFIXDOC || PRELSERIADOC(I.SERIADOC) || I.NRDOC || &apos;(&apos; || to_char(I.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN IESIRI I ON I.CODIES = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR CLIENT* - OBLIGATII DIN NOTE CONTABILE */
             WHEN SEMNIFICATIE  IN (320, 420) AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1201
              THEN
             ( SELECT &apos;NC&apos; || N.NRDOC || &apos;(&apos; || to_char(N.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
                 LEFT OUTER JOIN NC   N ON N.CODNC   = N1.CODNC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             /* RETUR CLIENT* - OBLIGATII DIN COMPENSARI */
             WHEN SEMNIFICATIE  = 420 AND NVL((SELECT OO.SEMNIFICATIE FROM
                           STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                           WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) = 1351
              THEN
             ( SELECT &apos;PV&apos; || C.NRDOC || &apos;(&apos; || to_char(C.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1
              )

             WHEN SEMNIFICATIE  IN (310, 330) THEN &apos;Plata in avans&apos;
             WHEN SEMNIFICATIE  IN (410, 430) THEN &apos;Incasare in avans&apos;

             WHEN SEMNIFICATIE  IN (800, 801/* viramente*/) AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF  AND ROWNUM &lt;=1), 0) IN (800, 801)
             THEN
             ( SELECT T.DOC || PRELSERIADOC(T.SERIEDOC) || T.NRDOC || &apos;(&apos; || to_char(T.DATADOC, &apos;dd.mm.yyyy&apos;) || &apos;)&apos;
               FROM
                 STINGERE S LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = S.CODSTINSPIF
                 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
                 LEFT OUTER JOIN TREZOR1 T ON T.CODTREZOR1 = G.CODDOC
               WHERE
                 S.CODSTINGATORPIF = OB.CODOBLIGPIF   AND ROWNUM &lt;=1-- viramente cu legatura
              )

             WHEN SEMNIFICATIE  IN (800, 801 /* viramente*/) AND NVL((SELECT OO.SEMNIFICATIE FROM
                  STINGERE SS LEFT OUTER JOIN OBLIGPIF OO ON SS.CODSTINSPIF = OO.CODOBLIGPIF
                  WHERE SS.CODSTINGATORPIF = OB.CODOBLIGPIF AND ROWNUM &lt;=1), 0) = 0  -- viramente fara legatura
             THEN &apos;Viramente interne&apos;

             WHEN SEMNIFICATIE  = 900           THEN &apos;Pe cheltuieli&apos;  --|| GetGestEvidenta(OB.CODGEST)
             WHEN SEMNIFICATIE  = 901           THEN &apos;Pe venituri&apos;    --|| GetGestEvidenta(OB.CODGEST)
             WHEN SEMNIFICATIE  IN (950, 951)   THEN &apos;Direct pe cont&apos; --|| GetGestEvidenta(OB.CODGEST)
             WHEN SEMNIFICATIE  = 1000          THEN &apos;Dobanda&apos;        --|| GetGestEvidenta(OB.CODGEST)
             WHEN SEMNIFICATIE  IN (1100, 1101) THEN &apos;Angajat&apos;

             ELSE &apos;???&apos;
           END)
         ;


         FOR V_REC IN
         (SELECT
           O.CODOBLIGPIF, O_STINS.TERMEN
          FROM
            TMP_OBLIGPIF O,
            STINGERE S,
            OBLIGPIF O_STINS
          WHERE
            O.CODOBLIGPIF = S.CODSTINGATORPIF
            AND O_STINS.CODOBLIGPIF = S.CODSTINSPIF
          )
          LOOP
            UPDATE TMP_OBLIGPIF
            SET
              TERMEN = V_REC.TERMEN
            WHERE
              CODOBLIGPIF = V_REC.CODOBLIGPIF;
          END LOOP;



       UPDATE TMP_TREZOR1 T
       SET
       DENTRANZ = SUBSTRB(
       (CASE
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 0 THEN &apos;Furnizor :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
--        WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1 THEN &apos;Retur Client :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1 THEN &apos;Retur :&apos;  || chr(13) || (SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART)
          WHEN TIPTRANZ IN (0, 1) AND OBIECTTRANZ = 3 THEN &apos;Viramente interne :&apos;  || chr(13) ||
          (SELECT B.SIMBOL || &apos; - &apos; || NRCONT FROM NBANKCONT BC LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK  WHERE CODBANKCONT = T.CODPART)

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 0 THEN &apos;Client: &apos;  || ( CASE
                                                                        WHEN T.AGENT &lt;&gt; 0 THEN &apos;(Agent:&apos; || T.NUMEAGENT || &apos;)&apos;
                                                                        ELSE &apos;&apos;
                                                                       END )  || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

--          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1 THEN &apos;Retur Furnizor :&apos; || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)
          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1 THEN &apos;Retur :&apos; || chr(13) || NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T.CODPART), &apos;&apos;)

          WHEN OBIECTTRANZ = 2 THEN &apos;Personal angajat :&apos; || chr(13) || NVL((SELECT NUME || &apos; &apos; || PRENUME FROM NPERS P WHERE CODPERS = T.CODPART), &apos;&apos;)


          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 4 THEN &apos;Servicii, articole fara NIR...&apos; || GETDENPARTDIECTPECONT(NVL(CODPART, 0)) || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 900 AND ROWNUM &lt;= 1))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 4 THEN &apos;Direct pe venituri...&apos; || GETDENPARTDIECTPECONT(NVL(CODPART, 0)) || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 901 AND ROWNUM &lt;= 1))

          WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 5 THEN &apos;Datorii, taxe, impozite &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 950 AND ROWNUM &lt;= 1))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 5 THEN &apos;Imprumuturi, subventii &apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT((SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND O.SEMNIFICATIE = 951 AND ROWNUM &lt;= 1))

          WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 6 THEN &apos;Dobanda la depozit:&apos; || chr(13) ||
          PKG_PLANCONTURI.GETDENCONT
          (PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG
          ( 1000,
            (SELECT NVL(ICONT, -1) FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1  AND O.SEMNIFICATIE = 1000 AND ROWNUM &lt;= 1),
            PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(CODNBANKCONT, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU)
          ))
         ELSE &apos;&apos;
        END
       ), 1, 100),
--     CODAVANS = NVL((SELECT CODOBLIGPIF FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND SEMNIFICATIE IN (310, 410)), 0);
       CODAVANS = NVL((SELECT CODOBLIGPIF FROM TMP_OBLIGPIF O WHERE O.CODTREZOR1 = T.CODTREZOR1 AND SEMNIFICATIE IN (310, 410) AND ROWNUM = 1), 0);

       FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE NVL(CODTRANSA, 0) &lt;&gt; 0)
       LOOP
         UPDATE TMP_OBLIGPIF
         SET
           CURSTRANSA = (SELECT G.CURS FROM OBLIGPIF O, GENERAL G WHERE O.CODOBLIGPIF = V_REC.CODTRANSA AND G.CODGENERAL = O.CODGENERAL),
           INFOTRANSA = (SELECT T1.DOC || TO_CHAR(T1.NRDOC) || &apos;/&apos; || TO_CHAR(T1.DATADOC, &apos;DD.MM.YYYY&apos;) FROM OBLIGPIF O, GENERAL G, TREZOR1 T1 WHERE O.CODOBLIGPIF = V_REC.CODTRANSA AND G.CODGENERAL = O.CODGENERAL AND G.TIPDOC IN (30, 31) AND T1.CODTREZOR1 = G.CODDOC)
         WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
       END LOOP;




       FOR V_REC IN
       (SELECT
          S.CODSTINGERE,
          G.TIPDOC,
          G.CODDOC,
          G.SEMNIFICATIE,
          S.CODSTINGATORPIF
        FROM
          TMP_STINGERE S,
          OBLIGPIF O,
          GENERAL G
        WHERE
         S.CODSTINSPIF = O.CODOBLIGPIF
         AND G.CODGENERAL = O.CODGENERAL
       )LOOP
          aCODSUBUNITSTINS := 0; aProcStopaj := 0;

          IF V_REC.SEMNIFICATIE IN (100, 110, 130) THEN
            BEGIN
              SELECT SUBUNITATEA, PROCSTOPAJ INTO aCODSUBUNITSTINS, aProcStopaj FROM INTRARI
              WHERE
                CODINTR = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
              EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0; aProcSTopaj := 0;
            END;
          ELSE
          IF V_REC.SEMNIFICATIE IN (200, 210) THEN
            BEGIN
              SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM IESIRI
              WHERE
                CODIES = V_REC.CODDOC AND TIPDOC = V_REC.TIPDOC;
              EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
            END;
           ELSE
           IF V_REC.SEMNIFICATIE IN (1200, 1201) THEN
             BEGIN
               SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM NC N, NC1 N1
               WHERE
                 N1.CODNC1 = V_REC.CODDOC AND N.CODNC = N1.CODNC;
               EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
             END;
             ELSE
             IF V_REC.SEMNIFICATIE IN (310, 330, 410, 430) THEN
               BEGIN
                 SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM TREZOR T, TREZOR1 T1
                 WHERE
                   T1.CODTREZOR1 = V_REC.CODDOC AND T.CODTREZOR = T1.CODTREZOR;
                 EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
               END;
             ELSE
             IF V_REC.SEMNIFICATIE IN (1300, 1301, 1302, 1303, 1350, 1351, 1352) THEN
               BEGIN
                 SELECT SUBUNITATEA INTO aCODSUBUNITSTINS FROM COMPENS C
                 WHERE
                   C.CODCOMPENS = V_REC.CODDOC;
                 EXCEPTION WHEN OTHERS THEN aCODSUBUNITSTINS := 0;
               END;
             END IF;
             END IF;

          END IF;
          END IF;
          END IF;

          UPDATE TMP_STINGERE
          SET
            CODSUBUNITSTINS = aCODSUBUNITSTINS,
            PROCSTOPAJ      = aProcStopaj
          WHERE
           CODSTINGERE = V_REC.CODSTINGERE;

          UPDATE TMP_OBLIGPIF
          SET
            SUBUNITATEA = aCODSUBUNITSTINS
          WHERE
            CODOBLIGPIF = V_REC.CODSTINGATORPIF;

        END LOOP;

        UPDATE TMP_OBLIGPIF
        SET
          SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE
        WHERE
           SUBUNITATEA IS NULL;



       -- memorez starea la intrare a stingerilor
       DELETE TMP_OBLIGPIF_INITIAL;
       INSERT INTO TMP_OBLIGPIF_INITIAL
       SELECT * FROM TMP_OBLIGPIF;
--       (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, TVA)
--       (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, TVA FROM TMP_OBLIGPIF);

       DELETE TMP_STINGERE_INITIAL;
       INSERT INTO TMP_STINGERE_INITIAL (SELECT * FROM TMP_STINGERE);



       INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC = RECID);
       INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC = RECID);

       DELETE TMP_RULAJ;

  END IF;

  DELETE TMP_TREZOR1_INITIAL;
  INSERT INTO TMP_TREZOR1_INITIAL(CODTREZOR1, CODTREZOR, CURS, TIPTRANZ, OBIECTTRANZ, CODPART, VALDOC) SELECT CODTREZOR1, CODTREZOR, CURS, TIPTRANZ, OBIECTTRANZ, CODPART, VALDOC FROM TMP_TREZOR1;



  UPDATE TMP_TREZOR1 T1
  SET
    INFOCMD = (SELECT PrefixDoc || NrDoc || &apos;/&apos; || DataDoc FROM COMANDA C WHERE C.CODCOMANDA = T1.CODCOMANDA)
  WHERE
    NVL(CODCOMANDA, 0) &lt;&gt; 0;


  UPDATE TMP_TREZOR1 T1
  SET
    TIPTRANZ = 2
  WHERE
    PLATATVA = 1;

  FOR V_REC IN (SELECT T1.CODTREZOR1 FROM TMP_RETUROSTINS R INNER JOIN TMP_TREZOR1 T1 ON T1.CODTREZOR1 = R.CODDOC)
  LOOP
    UPDATE TMP_TREZOR1
    SET
      LINKRETURO = 1
    WHERE
      CODTREZOR1 = V_REC.CODTREZOR1;  
  END LOOP;    

  PKG_CFGTABLES.EXT_GOTORECORD(TIPDOCCASABANCA);
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
 TIPDOCCASABANCA INTEGER := 0;
 NR              INTEGER := 0;
 vCOD            NUMBER(20);
 MONEDA          NUMBER(20);
 OLDCARNETDOC    NUMBER (20) := 0;
 OLDNRDOC        NUMBER (20) := 0;
 aVALOARE        NUMBER(20, 7) := 0;
 aCodSubunit NUMBER(20);
 aDataDoc DATE;
 aDoc varchar2(200);
 aCREDIT NUMBER(1) := 0;
 aCODBANKCONT    NUMBER (20) := 0;
 aCARNETDOC  NUMBER(20) := 0;
 aNRDOC NUMBER := 0;
 aANULAT NUMBER := 0;
 aOPERAT NUMBER := 0;

BEGIN
  UPDATE TMP_TREZOR1
  SET
    TIPTRANZ = 0
  WHERE
    TIPTRANZ = 2;

BEGIN
  SELECT
     TIPDOC,
		 OPERAT, 
     SUBUNITATEA,
     DATADOC,
     NUMEDOC || &apos;/&apos; || DATADOC,
     CODBANCA,
     NVL(CARNETDOC, 0),
     NVL(NRDOC, 0)
  INTO
     TIPDOCCASABANCA,
		 aOPERAT, 
     aCodSubunit,
     aDataDoc,
     aDoc,
     aCODBANKCONT,
     aCARNETDOC,
     aNRDOC
  FROM TMP_TREZOR;
  SELECT CODMONEDA INTO MONEDA FROM TMP_TREZOR;
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (TIPDOCCASABANCA);


  IF OPERATION = 0 THEN  -- UPDATE

    SELECT  CODTREZOR INTO RecId FROM TMP_TREZOR;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

         WINMADMIN.PKG_USERFIRME.PostLog(&apos;TREZOR&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;,
                                         RECID,PKG_GLOBALS.FIRMANAME,
                                         aCodSubunit, aDataDoc, aDoc,&apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

-- VERIFIC DACA NU S-AU RUPT LEGATURUILE CU CHELTAVANS;

  FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (900, 901, 950, 951))
  LOOP
    IF PKG_CATEGCONST.ESTECHELTAVANS(V_REC.ICONT) +  PKG_CATEGCONST.ESTEVENITAVANS(V_REC.ICONT)  = 0 THEN
      SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      IF NR &gt; 0 THEN
        FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF)
        LOOP
          FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
            UPDATE NCONTRUL
            SET
              RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
              RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV,
							RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
							RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
            WHERE
              CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

            UPDATE NCONTRUL
            SET
              RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
              RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV,
							RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
							RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
            WHERE
              CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
          END LOOP;

          DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
          DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
          DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
          DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
        END LOOP;
        DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END IF;
    END IF;
  END LOOP;


   -- sterg inregistrarile care au fost initial si acum nu mai exista; ORDINEA STERGERILOR E IMPORTANTA

  FOR V_REC IN
  (SELECT * FROM STINGERE WHERE
     CODSTINGATORPIF IN
     (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN
     (SELECT CODGENERAL  FROM GENERAL  WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN
     (SELECT CODTREZOR1  FROM TREZOR1  WHERE CODTREZOR = RecID)))
     AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE)
   )
   LOOP
     NotifyStergereIncasareFact( V_REC.CODSTINGERE);

     DELETE FROM STINGERE WHERE CODSTINGERE = V_REC.CODSTINGERE;
     
     
     IF NVL(V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
       UPDATE PLATI1
       SET
         STINSA = 0,
         REST = VALOARE
       WHERE
         CODPLATA1 = V_REC.CODPLATA1;
     END IF;
   END LOOP;

/*
    DELETE FROM STINGERE WHERE
     CODSTINGATORPIF IN
     (SELECT CODOBLIGPIF FROM OBLIGPIF WHERE CODGENERAL IN
     (SELECT CODGENERAL  FROM GENERAL  WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN
     (SELECT CODTREZOR1  FROM TREZOR1  WHERE CODTREZOR = RecID)))
     AND CODSTINGERE NOT IN (SELECT CODSTINGERE FROM TMP_STINGERE) ;

*/

/*
    DELETE FROM OBLIGPIF WHERE CODGENERAL IN
    ( SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN
     (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID)
    ) AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF);
*/

    FOR V_REC IN
    (
      SELECT * FROM OBLIGPIF WHERE CODGENERAL IN
      ( SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN
       (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID)
      ) AND CODOBLIGPIF NOT IN (SELECT CODOBLIGPIF FROM TMP_OBLIGPIF)
    )
    LOOP
      FOR V_RECAV IN (SELECT * FROM CHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF)
      LOOP
        FOR V_RECJURN IN ( SELECT * FROM JURNAL WHERE CODDOC = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106)) LOOP
          UPDATE NCONTRUL
          SET
            RULAJCD  = RULAJCD  - V_RECJURN.VALOARE,
            RULAJVCD = RULAJVCD - V_RECJURN.VALOAREV,
						RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
						RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS
          WHERE
            CODCONT = V_RECJURN.CONTD AND AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;

          UPDATE NCONTRUL
          SET
            RULAJCC  = RULAJCC  - V_RECJURN.VALOARE,
            RULAJVCC = RULAJVCC - V_RECJURN.VALOAREV,
						RULAJC_IFRS   = RULAJC_IFRS   - V_RECJURN.VALOARE_IFRS,
						RULAJVC_IFRS  = RULAJVC_IFRS  - V_RECJURN.VALOAREV_IFRS

          WHERE
            CODCONT = V_RECJURN.CONTC AND  AN = V_RECJURN.AN AND LUNA = V_RECJURN.LUNA;
        END LOOP;


        DELETE FROM JURNAL1     WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
        DELETE FROM JURNAL      WHERE CODDOC        = V_RECAV.CODCHELTAVANS AND TIPDOC IN (52, 106);
        DELETE FROM CHELTAVANS1 WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
        DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_RECAV.CODCHELTAVANS;
      END LOOP;

      DELETE FROM MASTERCHELTAVANS WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
      DELETE FROM TAXDECL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC1 =  V_REC.CODOBLIGPIF;
      DELETE FROM OBLIGPIF WHERE CODOBLIGPIF = V_REC.CODOBLIGPIF;
    END LOOP;

    DELETE FROM GENERAL
    WHERE
    TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RecID) AND
    CODGENERAL NOT IN (SELECT CODGENERAL FROM TMP_GENERAL);



    FOR V_REC IN
    (SELECT * FROM TREZOR1 WHERE CODTREZOR = RecID AND CODTREZOR1 NOT IN (SELECT CODTREZOR1 FROM TMP_TREZOR1))
    LOOP
      IF V_REC.CARNETDOC &lt;&gt; 0 AND  V_REC.NRDOC &lt;&gt; 0
      THEN
        PKG_CARNETEDOC.RELEASENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
        PKG_CARNETEDOC.COMPACTEAZAINTERVALE(V_REC.CARNETDOC);
      END IF;
      DELETE FROM TAXDECL WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
      --returo delete 
      DELETE FROM RETUROSTINS WHERE TipDoc = TIPDOCCASABANCA and CODDOC = V_REC.CodTrezor1;
    END LOOP;

    FOR V_REC IN
		(SELECT * FROM TREZOR1 WHERE CODTREZOR = RecID AND CODTREZOR1 NOT IN (SELECT CODTREZOR1 FROM TMP_TREZOR1))
    LOOP
      DELETE FROM TREZOR1
      WHERE
        CODTREZOR1 = V_REC.CODTREZOR1;

      IF NVL(V_REC.CODSERTAR, 0) &lt;&gt; 0 THEN
        UPDATE NSERTAR
        SET
          DEPUS = 0
        WHERE
         CODSERTAR = V_REC.CODSERTAR;
      END IF;
      IF NVL(V_REC.CODPLATA1, 0) &lt;&gt; 0 THEN
        UPDATE PLATI1
        SET
          STINSA = 0,
          REST = VALOARE
        WHERE
         CODPLATA1 = V_REC.CODPLATA1;
      END IF;
    END LOOP;


      -- TREZOR
      SELECT CODTREZOR INTO RecId FROM TMP_TREZOR;
      UPDATE TREZOR
      SET (TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
      =
      (SELECT TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT FROM TMP_TREZOR)
      WHERE CODTREZOR = RecId ;

     -- TREZOR1
      FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL) LOOP
        IF v_rec.CODTREZOR1 &gt; 0  THEN
          --returo delete
          DELETE FROM RETUROSTINS where tipdoc = TIPDOCCASABANCA 
                                                      and coddoc = v_rec.CODTREZOR1
                                                      and CODRETUROSTINS not in (Select CODRETUROSTINS from TMP_RETUROSTINS); 
          -- verific daca s-au schimbat CARNETELE de DOCUMENTE
          SELECT NVL(CARNETDOC, 0), NVL(NRDOC, 0) INTO OLDCARNETDOC, OLDNRDOC FROM TREZOR1
          WHERE
          NVL(CodTREZOR1,0) = NVL(v_rec.CodTREZOR1, 0);

          IF (OLDCARNETDOC&lt;&gt; 0)AND(OLDNRDOC &lt;&gt; 0)AND(V_REC.CARNETDOC &lt;&gt; OLDCARNETDOC OR V_REC.NRDOC &lt;&gt; OLDNRDOC)
          THEN
            IF OLDCARNETDOC &lt;&gt; 0 AND  OLDNRDOC &lt;&gt; 0
            THEN
              PKG_CARNETEDOC.RELEASENUMARDOC(OLDCARNETDOC, OLDNRDOC);
              PKG_CARNETEDOC.COMPACTEAZAINTERVALE(OLDCARNETDOC);
            END IF;
          END IF;


          UPDATE TREZOR1
          SET
            INDEXLOCAL    = v_rec.INDEXLOCAL,
            TIPTRANZ      = v_rec.TIPTRANZ,
            CARNETDOC     = v_rec.CARNETDOC,
            DOC           = v_rec.DOC,
            NRDOC         = v_rec.NRDOC,
            DATADOC       = v_rec.DATADOC,
            VALDOC        = v_rec.VALDOC,
            CURS          = v_rec.CURS,
            COMISION      = v_rec.COMISION,
            OBIECTTRANZ   = v_rec.OBIECTTRANZ,
            SERIEDOC      = V_REC.SERIEDOC,
            CODPART       = v_rec.CODPART,
            TIPDECONT     = v_rec.TIPDECONT,
            PLATATVA      = V_REC.PLATATVA,
            CODSERTAR     = V_REC.CODSERTAR,
            NRI           = V_REC.NRI,
            CODCOMANDA    = V_REC.CODCOMANDA,
            CODPLATA1     = V_REC.CODPLATA1,
            DATADECONT    = v_rec.DATADECONT,
            AN            = v_rec.AN,
            LUNA          = v_rec.LUNA,
            OBS           = v_rec.OBS,
            AGENT         = v_rec.AGENT,
            ANULAT        = v_rec.ANULAT,
            CODCENTRU     = V_REC.CODCENTRU,
            CODGEST       = V_REC.CODGEST,
            CODCMDINT1    = V_REC.CODCMDINT1
          WHERE
            CODTREZOR1 = v_rec.CODTREZOR1;
       ELSE
          SELECT SEQ_TREZOR1_CODTREZOR1.NextVal INTO vCOD FROM DUAL;

          UPDATE TMP_TREZOR1 SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
          UPDATE TMP_GENERAL  SET CODDOC = vCOD WHERE CODDOC = v_rec.CODTREZOR1;
          UPDATE TMP_OBLIGPIF SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
          -- returo 
          UPDATE TMP_RETUROSTINS  SET CODDOC = vCOD WHERE CODDOC = v_rec.CODTREZOR1;
          UPDATE TMP_JURNAL  SET INDEXLOCAL = VCOD WHERE INDEXLOCAL =  v_rec.CODTREZOR1;
          UPDATE TMP_JURNAL1 SET INDEXLOCAL = VCOD WHERE INDEXLOCAL =  v_rec.CODTREZOR1;
          PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TREZOR1&apos;, vCOD, v_rec.CODTREZOR1); 

          INSERT INTO TREZOR1
          (CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC, DATADOC, VALDOC, CURS, COMISION,
           OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA,  CODSERTAR, NRI, CODCOMANDA, CODPLATA1, DATADECONT, AN, LUNA, OBS, AGENT, ANULAT,USERID,DATACREARE,CODCENTRU,
           CODGEST,CODCMDINT1)
          VALUES
          (vCOD, v_rec.CODTREZOR,   v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC, v_rec.DOC,
                 v_rec.NRDOC,       v_rec.DATADOC,    v_rec.VALDOC,    v_rec.CURS, v_rec.COMISION,
                 v_rec.OBIECTTRANZ, V_REC.SERIEDOC,   v_rec.CODPART,    v_rec.TIPDECONT, V_REC.PLATATVA,  V_REC.CODSERTAR,
                 V_REC.NRI,  V_REC.CODCOMANDA, V_REC.CODPLATA1, v_rec.DATADECONT,v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT,pkg_globals.userid,systimestamp,V_REC.CODCENTRU,
                 v_rec.CODGEST,v_rec.CODCMDINT1 );
        END IF;
      END LOOP;
      
           --returo 
       insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  SEQ_RETUROSTINS_CODRETUROSTINS.Nextval,
                  rs.CODRETURO,
                  rs.CODDOC,
                  TIPDOCCASABANCA,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs where rs.CODRETUROSTINS &lt; 0;
       
       FOR v_rec IN ( SELECT * FROM TMP_RETUROSTINS WHERE NVL(CODRETUROSTINS,-1) &gt; 0 ORDER BY CODRETUROSTINS ) LOOP
           update RETUROSTINS 
            set CODRETURO            = v_rec.CODRETURO,
                  CODDOC                 = v_rec.CODDOC,
                  TIPDOC                   = TIPDOCCASABANCA,
                  VALOARE                 = v_rec.VALOARE,
                  STARTEDAT              = v_rec.STARTEDAT,
                  VOUCHERBARCODE  = v_rec.VOUCHERBARCODE
             WHERE
                   CODRETUROSTINS  = v_rec.CODRETUROSTINS;                  
                  
       END LOOP;    

      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410))
      LOOP
        UPDATE TMP_OBLIGPIF
        SET
         TERMEN = (SELECt DATADOC FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1)
        WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;

      -- GENERAL
      FOR v_rec IN (SELECT * FROM TMP_GENERAL) LOOP
        IF v_rec.CODGENERAL &gt; 0  THEN
          UPDATE GENERAL
          SET
            TIPDOC       = v_rec.TIPDOC,
            CODDOC       = v_rec.CODDOC,
            MONEDA       = v_rec.MONEDA,
            CURS         = v_rec.CURS,
            TVA          = v_rec.TVA,
            SEMNIFICATIE = v_rec.SEMNIFICATIE,
            FARAREG      = V_REC.FARAREG
          WHERE
            CODGENERAL = v_rec.CODGENERAL;
        ELSE
          SELECT SEQ_GENERAL_CODGENERAL.NextVal INTO vCOD FROM DUAL;

          UPDATE TMP_OBLIGPIF O SET CODGENERAL = vCOD WHERE O.CODGENERAL = v_rec.CODGENERAL;
          INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA,  SEMNIFICATIE, FARAREG)
          VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
        END IF;
      END LOOP;

     -- OBLIGPIF

     DELETE TMP_OBLIGPIF_ASOCIAT;
     INSERT INTO TMP_OBLIGPIF_ASOCIAT (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, RESTTVA)
      (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, NVL(RESTTVA, 0) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751));
     DELETE TMP_OBLIGPIF  WHERE SEMNIFICATIE IN (700, 701, 750, 751);

     FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF) LOOP
       IF v_rec.CODOBLIGPIF &gt; 0  THEN
         UPDATE OBLIGPIF
         SET
           CODGENERAL         = v_rec.CODGENERAL,
           TERMEN             = v_rec.TERMEN,
           VALOARE            = V_REC.VALOARE,
           CODPART            = v_rec.CODPART,
           ICONT              = v_rec.ICONT,
           TIPPLATA           = v_rec.TIPPLATA,
           MAJORARI           = v_rec.MAJORARI,
           SEMNIFICATIE       = v_rec.SEMNIFICATIE,
           TIP                = v_rec.TIP,
           CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
           CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
           VALOAREAFISATA     = v_rec.VALOAREAFISATA,
           TVAAFISAT          = v_rec.TVAAFISAT,
           CODGEST            = v_rec.CODGEST,
           CODNPARCAUT        = V_REC.CODNPARCAUT,
           CODTRANSA          = V_REC.CODTRANSA,
           COEFPROVIZION      = V_REC.COEFPROVIZION,
           CODCENTRU          = V_REC.CODCENTRU,
           CODANALIZANOD      = v_Rec.Codanalizanod,
           TVANEDED           = V_REC.TVANEDED,
           PROCTVA            = V_REC.PROCTVA,
           DINCARETVA         = V_REC.DINCARETVA
         WHERE
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
       ELSE
         SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;


         UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = vCOD WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;

         UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

         UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

         INSERT INTO OBLIGPIF
         (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
         VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE,
           v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, V_REC.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU, v_Rec.codanalizanod, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.TVAAFISAT,
           V_REC.DINCARETVA, NVL(V_REC.RESTTVA, 0));
       END IF;
     END LOOP;

     FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT) LOOP
       IF v_rec.CODOBLIGPIF &gt; 0  THEN
         UPDATE OBLIGPIF
         SET
           CODGENERAL         = v_rec.CODGENERAL,
           TERMEN             = v_rec.TERMEN,
           VALOARE            = v_rec.VALOARE,
           REST               = v_rec.REST,
           CODPART            = v_rec.CODPART,
           ICONT              = v_rec.ICONT,
           TIPPLATA           = v_rec.TIPPLATA,
           MAJORARI           = v_rec.MAJORARI,
           SEMNIFICATIE       = v_rec.SEMNIFICATIE,
           TIP                = v_rec.TIP,
           CONTBANKTRANZACTIE = v_rec.CONTBANKTRANZACTIE,
           CODOBLIGASOCIAT    = v_rec.CODOBLIGASOCIAT,
           VALOAREAFISATA     = v_rec.VALOAREAFISATA,
           TVAAFISAT          = v_rec.TVAAFISAT,
           CODGEST            = v_rec.CODGEST,
           CODNPARCAUT        = V_REC.CODNPARCAUT,
           CODTRANSA          = V_REC.CODTRANSA,
           COEFPROVIZION      = V_REC.COEFPROVIZION,
           CODCENTRU          = V_REC.CODCENTRU,
           CODANALIZANOD      = V_REC.CODANALIZANOD,
           TVANEDED           = V_REC.TVANEDED,
           PROCTVA            = V_REC.PROCTVA,
           DINCARETVA         = v_rec.DINCARETVA,
           RESTTVA            = v_rec.RESTTVA
         WHERE
           CODOBLIGPIF = v_rec.CODOBLIGPIF;
       ELSE
         SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

         UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

         INSERT INTO OBLIGPIF
         (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
         VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST, v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU,
         v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.TVAAFISAT, V_REC.DINCARETVA, NVL(V_REC.RESTTVA, 0));
       END IF;
     END LOOP;


    -- STINGERE
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      IF v_rec.CODSTINGERE &gt; 0  THEN
        UPDATE STINGERE
        SET
          CODSTINSPIF     = v_rec.CODSTINSPIF,
          CODSTINGATORPIF = v_rec.CODSTINGATORPIF,
          VALOARE         = v_rec.VALOARE,
          DINCARETVA      = v_rec.DINCARETVA,
          CODPLATA1       = V_REC.CODPLATA1
        WHERE
          CODSTINGERE = v_rec.CODSTINGERE;
      ELSE
        SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO vCOD FROM DUAL;
        INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, DINCARETVA)
        VALUES (vCOD, v_rec.CODSTINSPIF,  v_rec.CODSTINGATORPIF,  v_rec.VALOARE, V_REC.CODPLATA1, V_REC.DINCARETVA);
      END IF;
    END LOOP;





-- detail JURNAlL1

DELETE FROM JURNAl1 WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC = RECID AND CODJURNAL1 NOT IN
(SELECT CODJURNAL1 FROM TMP_JURNAl1);

FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
 IF V_REC.CODJURNAL1 &gt; 0 THEN
  UPDATE JURNAL1
  SET
    CODDOC       = V_REC.CODDOC,
    TIPDOC       = V_REC.TIPDOC,
    INDEXLOCAL   = V_REC.INDEXLOCAL,

    CODBAZAD     = V_REC.CODBAZAD,
    ICONTBAZAD   = V_REC.ICONTBAZAD,
    TIPBAZAD     = V_REC.TIPBAZAD,
    CODBAZAC     = V_REC.CODBAZAC,
    ICONTBAZAC   = V_REC.ICONTBAZAC,
    TIPBAZAC     = V_REC.TIPBAZAC,

    CODDESCRD     = V_REC.CODDESCRD,
    ICONTD        = V_REC.ICONTD,
    TIPCONTD      = V_REC.TIPCONTD,
    ANALITICCONTD = V_REC.ANALITICCONTD,
    CODDESCRC     = V_REC.CODDESCRC,
    ICONTC        = V_REC.ICONTC,
    TIPCONTC      = V_REC.TIPCONTC,
    ANALITICCONTC = V_REC.ANALITICCONTC,
    GEST          = V_REC.GEST,
    VALOARE       = V_REC.VALOARE,
    VALOAREV      = V_REC.VALOAREV,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    OBS           = V_REC.OBS,
    AN            = V_REC.AN,
    LUNA          = V_REC.LUNA,
    DIRTY         = V_REC.DIRTY,
    SUBUNITATEA   = V_REC.SUBUNITATEA,
    CODCENTRU     = v_rec.CODCENTRU,
    DATADOC       = V_REC.DATADOC,
    DOCUMENT      = V_REC.DOCUMENT,
    CODANALIZANOD = V_REC.CODANALIZANOD
  WHERE
    CODJURNAL1 = V_REC.CODJURNAl1;
 ELSE
   INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD )
   VALUES
   (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA,v_rec.CODCENTRU, V_REC.DATADOC,V_REC.DOCUMENT,v_Rec.CODANALIZANOD);
 END IF;
END LOOP;


-- detail JURNAL

DELETE FROM JURNAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC = RECID AND CODJURNAL NOT IN
(SELECT CODJURNAL FROM TMP_JURNAl);

FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
 IF V_REC.CODJURNAL &gt; 0 THEN
  UPDATE JURNAL
  SET
    CODDOC     = V_REC.CODDOC,
    TIPDOC     = V_REC.TIPDOC,
    INDEXLOCAL = V_REC.INDEXLOCAL,
    CONTD      = V_REC.CONTD,
    CONTC      = V_REC.CONTC,
    GEST       = V_REC.GEST,
    VALOARE    = V_REC.VALOARE,
    VALOAREV   = V_REC.VALOAREV,
    VALOARE_IFRS  = V_REC.VALOARE_IFRS,
    VALOAREV_IFRS = V_REC.VALOAREV_IFRS,
    OBS        = V_REC.OBS,
    AN         = V_REC.AN,
    LUNA       = V_REC.LUNA,
    SUBUNITATEA= V_REC.SUBUNITATEA ,
    CODCENTRU  = v_rec.CODCENTRU,
    DATADOC    = V_REC.DATADOC,
    DOCUMENT   = V_REC.DOCUMENT,
    CODANALIZANOD = v_rec.CODANALIZANOD
  WHERE
    CODJURNAL = V_REC.CODJURNAl;
 ELSE
 INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
 VALUES
 ( SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.VALOARE_IFRS, V_REC.VALOAREV_IFRS, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, v_rec.CODCENTRU, V_REC.DATADOC, V_REC.DOCUMENT,v_rec.CODANALIZANOD);
 END IF;
END LOOP;


ELSE -- INSERT
  SELECT SEQ_TREZOR_CODTREZOR.NextVal INTO RecID FROM DUAL;
  PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TREZOR&apos;, RecId); 
  

  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN

     WINMADMIN.PKG_USERFIRME.PostLog(&apos;TREZOR&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;,
                                     RECID,PKG_GLOBALS.FIRMANAME,
                                     aCodSubunit, aDataDoc, aDoc,&apos;&apos;,PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

    UPDATE TMP_TREZOR1 SET CODTREZOR = RecID;

    -- TREZOR
    INSERT INTO TREZOR ( CODTREZOR, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,userid,datacreare, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT)
    (SELECT RecId, TIPDOC, CODBANCA, ICONTPERS, MONEDAPERS, DATADOC, NUMEDOC, AN, LUNA, AGENT, OPERAT, BLOCAT, SUBUNITATEA,pkg_globals.USERID,systimestamp, IDIMPORT, CODANALIZA, CARNETDOC, NRDOC, SERIADOC, LISTAT FROM TMP_TREZOR);

    -- TREZOR1
    FOR v_rec IN (SELECT * FROM TMP_TREZOR1 ORDER BY INDEXLOCAL)  LOOP
      SELECT SEQ_TREZOR1_CODTREZOR1.NextVal INTO vCOD FROM DUAL;

      UPDATE TMP_TREZOR1 SET CODTREZOR1 = vCOD WHERE CODTREZOR1 = v_rec.CODTREZOR1;
      UPDATE TMP_GENERAL SET CODDOC = vCOD WHERE CODDOC = v_rec.CODTREZOR1;
      UPDATE TMP_OBLIGPIF SET CODTREZOR1 = VCOD WHERE CODTREZOR1 = V_REC.CODTREZOR1;
 -- returo 
      UPDATE TMP_RETUROSTINS  SET CODDOC = vCOD WHERE CODDOC = v_rec.CODTREZOR1;
      
      UPDATE TMP_JURNAL  SET INDEXLOCAL = VCOD WHERE INDEXLOCAL =  v_rec.CODTREZOR1;
      UPDATE TMP_JURNAL1 SET INDEXLOCAL = VCOD WHERE INDEXLOCAL =  v_rec.CODTREZOR1;
      
      PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;TREZOR1&apos;, vCOD, v_rec.CODTREZOR1);

      INSERT INTO TREZOR1
      ( CODTREZOR1, CODTREZOR, INDEXLOCAL, TIPTRANZ, CARNETDOC, DOC, NRDOC,
        DATADOC, VALDOC, CURS, COMISION, OBIECTTRANZ, SERIEDOC, CODPART, TIPDECONT, PLATATVA,  CODSERTAR, NRI,
        CODCOMANDA, CODPLATA1,  DATADECONT, AN, LUNA, OBS, AGENT, ANULAT,userid,datacreare,CODCENTRU,CODGEST,CODCMDINT1)
     VALUES
     (vCod, RecID, v_rec.INDEXLOCAL, v_rec.TIPTRANZ, v_rec.CARNETDOC,
      v_rec.DOC, v_rec.NRDOC, v_rec.DATADOC, v_rec.VALDOC, v_rec.CURS, v_rec.COMISION,
      v_rec.OBIECTTRANZ, V_REC.SERIEDOC, v_rec.CODPART, v_rec.TIPDECONT, V_REC.PLATATVA,  V_REC.CODSERTAR, V_REC.NRI, V_REC.CODCOMANDA, V_REC.CODPLATA1, v_rec.DATADECONT,v_rec.AN, v_rec.LUNA, v_rec.OBS, V_REC.AGENT, V_REC.ANULAT,pkg_globals.USERID,systimestamp,V_REC.CODCENTRU,
      V_REC.CODGEST,V_REC.CODCMDINT1);
    END LOOP;
           --returo 
       insert into RETUROSTINS (CODRETUROSTINS,
                                                    CODRETURO,
                                                    CODDOC,
                                                    TIPDOC,
                                                    VALOARE,
                                                    STARTEDAT,
                                                    VOUCHERBARCODE)
       select  SEQ_RETUROSTINS_CODRETUROSTINS.Nextval,
                  rs.CODRETURO,
                  rs.CODDOC,
                  TIPDOCCASABANCA,
                  rs.VALOARE,
                  rs.STARTEDAT,
                  rs.VOUCHERBARCODE
       from TMP_RETUROSTINS rs ;

      FOR V_REC IN (SELECT * FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (310, 410))
      LOOP
        UPDATE TMP_OBLIGPIF
        SET
         TERMEN = (SELECt DATADOC FROM TMP_TREZOR1 WHERE CODTREZOR1 = V_REC.CODTREZOR1)
        WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;


    -- GENERAL
    FOR v_rec IN (SELECT * FROM TMP_GENERAL)  LOOP
      SELECT SEQ_GENERAL_CODGENERAL.NextVal INTO vCOD FROM DUAL;
      UPDATE TMP_OBLIGPIF SET CODGENERAL = vCOD
      WHERE
      CODGENERAL = v_rec.CODGENERAL;

      INSERT INTO GENERAL (CODGENERAL, TIPDOC, CODDOC, MONEDA, CURS, TVA, SEMNIFICATIE, FARAREG)
      VALUES (vCOD, v_rec.TIPDOC, v_rec.CODDOC, v_rec.MONEDA, v_rec.CURS, v_rec.TVA, v_rec.SEMNIFICATIE, V_REC.FARAREG);
    END LOOP;

   -- OBLIGPIF
     DELETE TMP_OBLIGPIF_ASOCIAT;
     INSERT INTO TMP_OBLIGPIF_ASOCIAT(CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION,CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, RESTTVA)
     (SELECT CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU,CODANALIZANOD, TVANEDED, PROCTVA, NVL(RESTTVA, 0) FROM TMP_OBLIGPIF WHERE SEMNIFICATIE IN (700, 701, 750, 751));
     DELETE TMP_OBLIGPIF  WHERE SEMNIFICATIE IN (700, 701, 750, 751);

    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF ORDER BY CODOBLIGPIF)  LOOP
      SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;

      UPDATE TMP_OBLIGPIF SET CODOBLIGPIF = vCOD WHERE CODOBLIGPIF = v_rec.CODOBLIGPIF;

      UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;


      UPDATE TMP_OBLIGPIF_ASOCIAT SET CODOBLIGASOCIAT = vCOD WHERE CODOBLIGASOCIAT = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODTRANSA, COEFPROVIZION, CODCENTRU, CODANALIZANOD, TVANEDED, PROCTVA, TVAAFISAT, DINCARETVA, RESTTVA)
      VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, V_REC.VALOARE, V_REC.VALOARE,
      v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT, V_REC.CODTRANSA, V_REC.COEFPROVIZION, V_REC.CODCENTRU,v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA,
      V_REC.TVAAFISAT, V_REC.DINCARETVA, V_REC.RESTTVA) ;
    END LOOP;


    FOR v_rec IN (SELECT * FROM TMP_OBLIGPIF_ASOCIAT ORDER BY CODOBLIGPIF)  LOOP
      SELECT SEQ_OBLIGPIF_CODOBLIGPIF.NextVal INTO vCOD FROM DUAL;
      UPDATE TMP_STINGERE SET CODSTINGATORPIF = vCOD WHERE CODSTINGATORPIF = v_rec.CODOBLIGPIF;

      INSERT INTO OBLIGPIF
      (CODOBLIGPIF, CODGENERAL, TERMEN, VALOARE, REST, CODPART, ICONT, TIPPLATA, MAJORARI, SEMNIFICATIE, TIP, CONTBANKTRANZACTIE, CODOBLIGASOCIAT, VALOAREAFISATA, CODGEST, CODNPARCAUT, CODANALIZANOD, TVANEDED, PROCTVA, COEFPROVIZION, TVAAFISAT, DINCARETVA, RESTTVA)
      VALUES (vCOD, v_rec.CODGENERAL, v_rec.TERMEN, v_rec.VALOARE, v_rec.REST,
              v_rec.CODPART, v_rec.ICONT, v_rec.TIPPLATA, v_rec.MAJORARI, v_rec.SEMNIFICATIE, v_rec.TIP, v_rec.CONTBANKTRANZACTIE, v_rec.CODOBLIGASOCIAT, v_rec.VALOAREAFISATA, V_REC.CODGEST, V_REC.CODNPARCAUT,v_Rec.CODANALIZANOD, V_REC.TVANEDED, V_REC.PROCTVA, V_REC.COEFPROVIZION,
              V_REC.TVAAFISAT, V_REC.DINCARETVA, V_REC.RESTTVA) ;
    END LOOP;


    -- STINGERE --
    FOR v_rec in (SELECT * FROM TMP_STINGERE) LOOP
      SELECT SEQ_STINGERE_CODSTINGERE.NextVal INTO VCod FROM DUAL;
      INSERT INTO STINGERE (CODSTINGERE, CODSTINSPIF, CODSTINGATORPIF, VALOARE, CODPLATA1, DINCARETVA)
      VALUES (vCod, v_rec.CODSTINSPIF, v_rec.CODSTINGATORPIF, v_rec.VALOARE, V_REC.CODPLATA1, V_REC.DINCARETVA);
    END LOOP;



    INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD )
    (SELECT SEQ_JURNAL1_CODJURNAL1.NEXTVAL, RECID, TIPDOC, INDEXLOCAL,  CODBAZAD,  ICONTBAZAD,  TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD, ANALITICCONTD,  CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, DIRTY, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT, CODANALIZANOD FROM TMP_JURNAL1);

    INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC, DOCUMENT,CODANALIZANOD)
    ( SELECT SEQ_JURNAL_CODJURNAL.NEXTVAL, RECID, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, VALOARE_IFRS, VALOAREV_IFRS, OBS, AN, LUNA, SUBUNITATEA, CODCENTRU, DATADOC , DOCUMENT,CODANALIZANOD FROM TMP_JURNAL);

  END IF;


-- actualizez restul obligatiilor stinse de tranzactiile documentului salvat

  UPDATE OBLIGPIF O
  SET
  REST =
    (
      CASE
       WHEN VALOARE &gt;= 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      END
     ),
  RESTTVA =
    (
      CASE
       WHEN VALOARE &gt;= 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0)  + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      END
     )
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE UNION SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
     UNION
     SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
   );
/*
  UPDATE PLATI1 O
  SET
  REST =
    (
      CASE
       WHEN VALOARE &gt;= 0 THEN VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       WHEN VALOARE &lt; 0 THEN VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      END
     ),
  DINCARETVA =
    (
      CASE
       WHEN VALOARE &gt;= 0 THEN NVL(DINCARETVA, 0) - NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
       WHEN VALOARE &lt; 0 THEN NVL(DINCARETVA, 0)  + NVL((SELECT SUM(NVL(DINCARETVA, 0)) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      END
     )
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE UNION SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
     UNION
     SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
   );
*/
/*
  UPDATE PLATI1 O
  SET
  O.Stinsa = 1
  WHERE
   O.CODOBLIGPIF IN
   ( SELECT CODSTINSPIF FROM TMP_STINGERE UNION SELECT CODSTINSPIF FROM TMP_STINGERE_INITIAL
     UNION
     SELECT CODOBLIGPIF AS CODSTINSPIF FROM TMP_OBLIGPIF_INITIAL WHERE SEMNIFICATIE IN (310, 410, 500, 600, 800, 801)
   )
	 and REST = 0;
*/

 -- ACTUALIZEZ RESTUL TRANSELOR CAND TRANZACTIILE DE PE DOCUMENTUL SALVAT STING TRANSE
FOR V_REC IN
(
 SELECT
   OI.VALOARE,
   OI.CODTRANSA
 FROM
--   TMP_STINGERE_INITIAL SI,
   TMP_OBLIGPIF_INITIAL OI
 WHERE
--  SI.CODSTINGATORPIF = OI.CODOBLIGPIF
  OI.SEMNIFICATIE = 801
  AND NVL(OI.CODTRANSA, 0) &lt;&gt; 0
  UNION
 SELECT
   OI.VALOARE,
   OI.CODTRANSA
 FROM
--   TMP_STINGERE SI,
   TMP_OBLIGPIF OI
 WHERE
--  SI.CODSTINGATORPIF = OI.CODOBLIGPIF
   OI.SEMNIFICATIE = 801
  AND NVL(OI.CODTRANSA, 0) &lt;&gt; 0
)
LOOP
/*
  UPDATE OBLIGPIF
  SET
   RESTTRANSA = VALOARE - NVL((SELECT SUM(VALOARE) FROM OBLIGPIF WHERE CODTRANSA = V_REC.CODTRANSA), 0)
  WHERE
   CODOBLIGPIF = V_REC.CODTRANSA;
*/

    UPDATE OBLIGPIF
    SET
      RESTTRANSA = VALOARE - NVL((SELECT SUM(O.VALOARE * NVL(G.CURS, 1) / NVL(T1.CURS, 1))
                                 FROM
                                   OBLIGPIF O,
                                   GENERAL G,
                                   TREZOR1 T1
                                  WHERE
                                    CODTRANSA = V_REC.CODTRANSA
                                    AND G.CODGENERAL = O.CODGENERAL
                                    AND T1.CODTREZOR1 = G.CODDOC
                                  ),
                                 0)
    WHERE
      CODOBLIGPIF = V_REC.CODTRANSA;

END LOOP;


 -- ACTUALIZEZ RESTUL TRANSELOR CAND TRANZACTIILE DE PE DOCUMENTUL SALVAT DECLANSEAZA URMARIRE TRANSE
 -- AICI MAI TREBUIE O CONDITIE DE CONTBANCAR DE TIP CREDIT;
IF TIPDOCCASABANCA IN (30, 31) THEN
   BEGIN
     SELECT CREDIT INTO aCREDIT FROM NBANKCONT WHERE CODBANKCONT = aCODBANKCONT;
     EXCEPTION WHEN OTHERS THEN aCREDIT := 0;
   END;

   IF aCREDIT = 1 THEN
     FOR V_REC IN
      (
       SELECT
         OI.CODOBLIGPIF
       FROM
         TMP_OBLIGPIF_INITIAL OI
       WHERE
        OI.SEMNIFICATIE = 800
        UNION
       SELECT
         OI.CODOBLIGPIF
       FROM
         TMP_OBLIGPIF OI
       WHERE
        OI.SEMNIFICATIE = 800
      )
      LOOP
        UPDATE OBLIGPIF
        SET
          RESTTRANSA = VALOARE - NVL(
                                     (SELECT
                                        SUM(O.VALOARE * NVL(G.CURS, 1) / NVL(T1.CURS, 1))
                                      FROM
                                        OBLIGPIF O, GENERAL G, TREZOR1 T1
                                      WHERE
                                        CODTRANSA = V_REC.CODOBLIGPIF
                                        AND G.CODGENERAL = O.CODGENERAL
                                        AND T1.CODTREZOR1 = G.CODDOC
                                     ),
                                    0)
        WHERE
          CODOBLIGPIF = V_REC.CODOBLIGPIF;
      END LOOP;
   END IF;
END IF;


-- actualizez restul pentru tranzactiile care nasc obligatii de plata/incasare iar pe cele care doar sting le pun pe zero;
  UPDATE OBLIGPIF O
  SET O.REST  =
   (
    CASE
      WHEN ((O.SEMNIFICATIE IN   (310, 410, 500, 600, 330, 430))OR(O.SEMNIFICATIE IN (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND O.VALOARE &gt;= 0 THEN O.VALOARE - NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      WHEN ((O.SEMNIFICATIE IN   (310, 410, 500, 600, 330, 430))OR(O.SEMNIFICATIE IN (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) &lt;&gt; 0)) AND O.VALOARE &lt; 0 THEN O.VALOARE + NVL((SELECT SUM(VALOARE) FROM STINGERE WHERE CODSTINSPIF = O.CODOBLIGPIF), 0)
      WHEN O.SEMNIFICATIE NOT IN (310, 410, 500, 600, 800, 801, 1100, 1101, 330, 430) THEN 0
      WHEN O.SEMNIFICATIE IN     (800, 801) AND NVL(CONTBANKTRANZACTIE, 0) = 0 THEN 0
      WHEN O.SEMNIFICATIE IN (1100, 1101) THEN O.VALOARE
    END)
  WHERE
  O.CODGENERAL IN
  (SELECT CODGENERAL FROM GENERAL WHERE TIPDOC = TIPDOCCASABANCA AND CODDOC IN (SELECT CODTREZOR1 FROM TREZOR1 WHERE CODTREZOR = RECID));

  -- ACTUALIZARE RULAJE CONTURI
   FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP

     SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
     IF NR = 0 THEN
       INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
       VALUES
       (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
     END IF;

     UPDATE NCONTRUL
     SET
       RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
       RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
       RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
  		 RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
			 RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS
     WHERE
      CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

      IF NVL(V_REC.SUBUNITATEA, 0) &lt;&gt; 0 THEN
        FOR V_REC_SUB IN (SELECT * FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU)
        LOOP
          SELECT COUNT(*) INTO NR FROM NCONTRULSUB WHERE CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;

          IF NR = 0 THEN
            INSERT INTO NCONTRULSUB(CODCONTRULSUB, CODCONTRUL, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, SUBUNITATEA)
            VALUES
            (SEQ_NCONTRULSUB_CODRULSUB.NEXTVAL, V_REC_SUB.CODCONTRUL,  0, 0, 0, 0, 0, 0, 0, 0, V_REC.SUBUNITATEA);
          END IF;

          UPDATE NCONTRULSUB
          SET
            RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
            RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
            RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
            RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END),
						RULAJC_IFRS   = RULAJC_IFRS   + V_REC.VALOARE_IFRS,
						RULAJVC_IFRS  = RULAJVC_IFRS  + V_REC.VALOAREV_IFRS
          WHERE
            CODCONTRUL = V_REC_SUB.CODCONTRUL AND SUBUNITATEA = V_REC.SUBUNITATEA;
        END LOOP;
      END IF;


   END LOOP;


    FOR V_REC IN (SELECT * FROM TREZOR1 WHERE CODTREZOR = RecId)
    LOOP
      IF (V_REC.CARNETDOC &lt;&gt; 0) AND (V_REC.NRDOC &lt;&gt; 0)
      THEN
        PKG_CARNETEDOC.SOLVENUMARDOC(V_REC.CARNETDOC, V_REC.NRDOC);
      END IF;
    END LOOP;


  FOR V_REC IN (SELECT O.VALOARE, O.CODOBLIGPIF, G.TVA, G.CURS FROM TMP_OBLIGPIF O, TMP_GENERAL G WHERE O.SEMNIFICATIE IN (900, 950, 901, 951) AND G.CODGENERAL = O.CODGENERAL )
  LOOP

    SELECT  NVL(V_REC. VALOARE, 0) * DECODE(NVL(V_REC.CURS, 0), 0, 1, NVL(V_REC.CURS, 0)) - NVL(V_REC.TVA, 0) INTO aVALOARE FROM DUAL;

    FOR V_CHELT1 IN
    (SELECT CA1.CODCHELTAVANS1, CA1.CODCHELTAVANS
     FROM
       CHELTAVANS CA,
       CHELTAVANS1 CA1
     WHERE
       CA.CODOBLIGPIF = V_REC.CODOBLIGPIF
       AND CA1.CODCHELTAVANS = CA.CODCHELTAVANS AND VALOARE &lt;&gt; aVALOARE
    )
    LOOP
      UPDATE CHELTAVANS1
      SET
        VALOARE = aVALOARE
      WHERE
        CODCHELTAVANS1 = V_CHELT1.CODCHELTAVANS1;

     UPDATE JURNAL1
     SET  DIRTY = 1
     WHERE CODDOC = V_CHELT1.CODCHELTAVANS AND TIPDOC IN (52, 106);


    END LOOP;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_STINGERE_INITIAL WHERE NVL(CODPLATA1, 0) &lt;&gt; 0)
  LOOP
    UPDATE PLATI1
    SET
     STINSA = 0, REST = VALOARE
    WHERE
      CODPLATA1 = V_REC.CODPLATA1;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_STINGERE WHERE NVL(CODPLATA1, 0) &lt;&gt; 0)
  LOOP
    UPDATE PLATI1
    SET
     STINSA = 1, REST = 0
    WHERE
      CODPLATA1 = V_REC.CODPLATA1;
  END LOOP;


  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE NVL(CODSERTAR, 0) &lt;&gt; 0)
  LOOP
    UPDATE NSERTAR
    SET
     DEPUS = 1
    WHERE
      CODSERTAR = V_REC.CODSERTAR;
  END LOOP;

  FOR V_REC IN (SELECT * FROM TMP_TREZOR1 WHERE NVL(CODPLATA1, 0) &lt;&gt; 0)
  LOOP
    UPDATE PLATI1
    SET
     STINSA = 1
    WHERE
      CODPLATA1 = V_REC.CODPLATA1;
  END LOOP;


  PKG_GLOBALS.MarkDirtyJurnal;

  UPDATE_VALTRANZ_STINGERI(RECID);
  NotifyModif(Operation, RecId, &apos;TREZOR&apos;);

  IF (CARNETDOC_I &lt;&gt; 0)AND(NRDOC_I &lt;&gt; 0)AND(ACARNETDOC &lt;&gt; CARNETDOC_I OR ANRDOC &lt;&gt; NRDOC_I)
  THEN
    PKG_CARNETEDOC.RELEASENUMARDOC(CARNETDOC_I, NRDOC_I);
    PKG_CARNETEDOC.COMPACTEAZAINTERVALE(CARNETDOC_I);
  END IF;

  IF ACARNETDOC &lt;&gt; 0 THEN
    PKG_CARNETEDOC.SOLVENUMARDOC(ACARNETDOC, ANRDOC);
  END IF;

  if TIPDOCCASABANCA in (29, 30, 33) then
    PKG_SAFT.UpdateTaxDecl(3, RecId);
	end if;
 
  PKG_CFGTABLES.EXT_POSTRECORDS(TIPDOCCASABANCA, Operation);
  
  NotifyModifSoldFact;
  
  COMMIT;

 EXCEPTION WHEN OTHERS THEN BEGIN
   ROLLBACK;
   RAISE;
 END;
END;

END;

end PKG_TREZOR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TRIGAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>097133D907D335E4F6F23FACAB4E39351AF7292B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TRIGAR IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodTRIGAR INTO Tmp FROM TRIGAR WHERE CodTRIGAR = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE BAGA_IN_TRIGAR_MODIF(aUserID in number, aCodMaster in number, aCod in number, aTableName in varchar2, aFieldName in varchar2, aOldValue in varchar2, aNewValue in varchar2) IS pragma autonomous_transaction;
BEGIN
  insert into trigar_modif(
  DATAMODIF,
  USERMODIF,
  CODMASTER,
  COD,
  TABLENAME,
  FIELDNAME,
  OLDVALUE,
  NEWVALUE,
  CODMODIF )
  values (sysdate, aUserID, aCodMaster, aCod, aTableName, aFieldName, aOldValue, aNewValue, seq_trigar_modif.nextval);
  commit;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
tblName varchar2(300);
BEGIN
  SP_LOCKRECORD(RecId);
  Select tablename into TblName FROM TRIGAR  WHERE CodTRIGAR = RecId ;
  TblName := &apos;DROP TRIGGER WME_&apos;||tblname||&apos;_&apos;||RecID;
  DELETE FROM TRIGAR1 WHERE CodTRIGAR = RecId ;
  DELETE FROM TRIGAR  WHERE CodTRIGAR = RecId ;
  NotifyModif(2, RecId, &apos;TRIGAR&apos;);
  begin
    Execute immediate(TblName);
  exception when others then null;
  end;  
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_TRIGAR FIELDS( CodTRIGAR ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  -- Master TRIGAR
  INSERT INTO  TMP_TRIGAR ( CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile, 
                            Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv)
  SELECT CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile, 
         Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,coalesce(inactiv,0)
  FROM TRIGAR WHERE CodTRIGAR = RecId;

  INSERT INTO  TMP_TRIGAR1 ( CodTRIGAR1, CodTRIGAR,FieldName )
  SELECT CodTRIGAR1, CodTRIGAR,FieldName
  FROM TRIGAR1 WHERE CodTRIGAR = RecId ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
	aSQL CLOB;
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    SELECT CodTRIGAR INTO RecId FROM TMP_TRIGAR;

    UPDATE TRIGAR SET (  tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv )
                       = ( SELECT  tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv FROM TMP_TRIGAR )
    WHERE CodTRIGAR = RecId ;

    DELETE FROM TRIGAR1 WHERE CodTRIGAR = RecId and CodTRIGAR1 NOT IN (Select CodTRIGAR1 from TMP_TRIGAR1);

    FOR v_rec IN ( SELECT * FROM TMP_TRIGAR1 WHERE CodTRIGAR1 &gt; 0 ) LOOP
      UPDATE TRIGAR1
      SET FIELDNAME  = V_REC.FIELDNAME
      WHERE CodTRIGAR1  = v_rec.CodTRIGAR1;
    END LOOP;

    INSERT INTO TRIGAR1 ( CodTRIGAR1, CodTRIGAR, FieldName)
    SELECT SEQ_TRIGAR1_CodTRIGAR1.Nextval , RecId ,FieldName
    FROM TMP_TRIGAR1 WHERE CodTRIGAR1 &lt; 0;

  ELSE  -- INSERT

    SELECT Seq_TRIGAR_CodTRIGAR.NextVal INTO RecId FROM DUAL;

    INSERT INTO  TRIGAR ( CodTRIGAR, tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv )
    SELECT  RecId , tablename, masterField, masterTable, mainTable, trig, Variabile, Tip, operatie, initiator,destinatar,subiect,antet,final, moment,obs,inactiv
    FROM Tmp_TRIGAR;

    INSERT INTO TRIGAR1 ( CodTRIGAR1, CodTRIGAR, FieldName)
    SELECT SEQ_TRIGAR1_CodTRIGAR1.Nextval , RecId , FieldName
    FROM TMP_TRIGAR1;
  END IF;
  NotifyModif(Operation, RecId, &apos;TRIGAR&apos;);
  COMMIT;
END;

FUNCTION  GET_DDL( RecId IN NUMBER, pPrefix IN VARCHAR2) RETURN CLOB IS
  s_Prefix       VARCHAR2(100);
        
  v_Tip          NUMBER(1);
  s_TableName    VARCHAR2(100);
  v_Operatie     NUMBER(1);
  v_Moment       NUMBER(1);
  c_Trig         CLOB;
  c_Variabile    CLOB;
  s_MasterField  VARCHAR2(100);
  s_KeyField     VARCHAR2(100);
  s_AuxCompare   VARCHAR2(1000);
  s_AuxInsert    VARCHAR2(1000);
  s_Operatii     VARCHAR2(1000);
  c_DDL          CLOB;
BEGIN
  s_Prefix := Trim(pPrefix);
  IF s_Prefix IS NOT NULL THEN 
    IF SubStr(s_Prefix, -1) &lt;&gt; &apos;.&apos; THEN
      s_Prefix := s_Prefix||&apos;.&apos;;
    END IF;
  END IF;

  BEGIN
    SELECT t.Tip, t.TableName, t.Operatie, t.Moment, t.Variabile, t.Trig, t.MasterField, c.Column_Name
    INTO   v_Tip, s_TableName, v_Operatie, v_Moment, c_Variabile, c_Trig, s_MasterField, s_KeyField
    FROM trigar t
      LEFT JOIN user_tab_columns c ON c.table_name = Upper(t.TableName) AND c.column_id = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION 
    WHEN no_data_found THEN v_Tip := 0;
  END;

  IF    v_Tip = 1 THEN
    IF s_MasterField IS NULL THEN 
      s_MasterField := s_KeyField;
    END IF;

    c_DDL :=  &apos;CREATE OR REPLACE TRIGGER &apos;||s_Prefix||&apos;WME_&apos;||s_TableName||&apos;_&apos;||RecId||Chr(13)||
              &apos;  after update on &apos;||s_Prefix||s_TableName||Chr(13)||
              &apos;  for each row&apos;||Chr(13)||
              &apos;declare&apos;||Chr(13)||
              &apos;begin&apos;;

    FOR vRec IN (
      SELECT t1.FieldName, tc.Data_Type
      FROM trigar t
        INNER JOIN trigar1 t1 ON t1.CodTrigar = t.CodTrigar 
        LEFT JOIN user_tab_columns tc ON tc.table_name = Upper(t.TableName) AND tc.column_name = Upper(t1.FieldName)
      WHERE t.CodTrigar = RecId
      ORDER BY codtrigar1
    ) LOOP

      IF vRec.Data_Type IN (&apos;BLOB&apos;, &apos;CLOB&apos;) THEN 
        s_AuxCompare := &apos;dbms_lob.compare(:New.&apos;||vRec.FieldName||&apos;,:Old.&apos;||vRec.FieldName||&apos;) &lt;&gt; 0&apos;;
        s_AuxInsert  := &apos;NULL, NULL&apos;;
      ELSE
        s_AuxCompare := &apos;:New.&apos;||vRec.FieldName||&apos; &lt;&gt; :Old.&apos;||vRec.FieldName;
        s_AuxInsert  := &apos;SubstrB(:Old.&apos;||vRec.FieldName||&apos;,1,100), SubstrB(:New.&apos;||vRec.FieldName||&apos;,1,100)&apos;;
      END IF; 

      c_DDL := c_DDL||Chr(13)||
              &apos;  IF (:New.&apos;||vRec.FieldName||&apos; is Null and :Old.&apos;||vRec.FieldName||&apos; is not Null) &apos;||Chr(13)||
              &apos;  OR (:New.&apos;||vRec.FieldName||&apos; is not Null and :Old.&apos;||vRec.FieldName||&apos; is Null) &apos;||Chr(13)||
              &apos;  OR (&apos;||s_AuxCompare||&apos;)&apos;||Chr(13)|| 
              &apos;  THEN &apos;||Chr(13)||
              &apos;    INSERT INTO trigar_modif (CodModif, DatAmodif, UserModif, Cod, CodMaster, TableName, FieldName, OldValue, NewValue)&apos;||Chr(13)||
              &apos;    VALUES(SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, :Old.&apos;||s_KeyField||&apos;,:Old.&apos;||s_MasterField||&apos;, &apos;&apos;&apos;||s_TableName||&apos;&apos;&apos;, &apos;&apos;&apos;||vRec.FieldName||&apos;&apos;&apos;, &apos;||s_AuxInsert||&apos;);&apos;||Chr(13)||
              &apos;  END IF;&apos;;
    END LOOP; 
    c_DDL := c_DDL||Chr(13)||
              &apos;END WME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;;&apos;;
  ELSIF v_Tip = 2 THEN
    s_Operatii := &apos;&apos;;
    IF BITand(v_Operatie,1) = 1 THEN s_Operatii := &apos;insert&apos;; end if;
    if BITand(v_Operatie,2) = 2 then
      if Length(s_Operatii) &gt; 0 then
        s_Operatii := s_Operatii||&apos; or update&apos;;
      else
        s_Operatii := &apos;update&apos;;
      end if;
    end if;
    if BITand(v_Operatie,4) = 4 then
      if Length(s_Operatii) &gt; 0 then
        s_Operatii := s_Operatii||&apos; or delete&apos;;
      else
        s_Operatii := &apos;delete&apos;;
      end if;
    end if;
   
    c_DDL :=  &apos;CREATE OR REPLACE TRIGGER &apos;||s_Prefix||&apos;WME_&apos;||s_TableName||&apos;_&apos;||RecId||Chr(13)||
              &apos;  &apos;||CASE v_Moment WHEN 1 THEN &apos;before&apos; ELSE &apos;after&apos; END||&apos; &apos;||s_Operatii||&apos; on &apos;||s_Prefix||s_TableName||Chr(13)||
              &apos;  for each row&apos;||Chr(13)||
              &apos;declare&apos;||Chr(13)||
              c_Variabile||Chr(13)||
              &apos;begin&apos;||Chr(13)||
              c_Trig||Chr(13)||
              &apos;END WME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;;&apos;;
  END IF;

  RETURN c_DDL;
END;

FUNCTION GET_DDL_ACTIV( RecId IN NUMBER, pPrefix IN VARCHAR2) RETURN CLOB IS
  s_Prefix       VARCHAR2(100);
  s_TableName    VARCHAR2(100);
  c_DDL          CLOB;
  sActiv         VARCHAR2(50);
  vInactiv       NUMBER(1);
BEGIN
  s_Prefix := Trim(pPrefix);
  IF s_Prefix IS NOT NULL THEN 
    IF SubStr(s_Prefix, -1) &lt;&gt; &apos;.&apos; THEN
      s_Prefix := s_Prefix||&apos;.&apos;;
    END IF;
  END IF;

  BEGIN
    SELECT t.TableName, coalesce(t.inactiv,0)
    INTO   s_TableName, vInactiv
    FROM trigar t
      LEFT JOIN user_tab_columns c ON c.table_name = Upper(t.TableName) AND c.column_id = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION 
    WHEN no_data_found THEN s_TableName := &apos;&apos;;
  END;
  if Length(s_TableName) &gt; 0 then
    if vInactiv = 1 then
      sActiv := &apos; DISABLE&apos;;
    else
      sActiv := &apos; ENABLE&apos;;
    end if;
  end if;

  c_DDL := &apos;ALTER TRIGGER &apos;||s_Prefix||&apos;WME_&apos;||s_TableName||&apos;_&apos;||RecId||sActiv;          
  RETURN c_DDL;
END;

PROCEDURE SET_DDL_TRG(RecId IN NUMBER, pPrefix IN VARCHAR2) IS
  s_Prefix       VARCHAR2(100);
        
  v_Tip          NUMBER(1);
  s_TableName    VARCHAR2(100);
  v_Operatie     NUMBER(1);
  v_Moment       NUMBER(1);
  c_Trig         CLOB;
  c_Variabile    CLOB;
  s_MasterField  VARCHAR2(100);
  s_KeyField     VARCHAR2(100);
  s_AuxCompare   VARCHAR2(1000);
  s_AuxInsert    VARCHAR2(1000);

  c_DDL          CLOB;
  sActiv         VARCHAR2(50);
  vInactiv       NUMBER(1);
BEGIN
  s_Prefix := Trim(pPrefix);
  IF s_Prefix IS NOT NULL THEN 
    IF SubStr(s_Prefix, -1) &lt;&gt; &apos;.&apos; THEN
      s_Prefix := s_Prefix||&apos;.&apos;;
    END IF;
  END IF;

  BEGIN
    SELECT t.Tip, t.TableName, t.Operatie, t.Moment, t.Variabile, t.Trig, t.MasterField, c.Column_Name,coalesce(t.inactiv,0)
    INTO   v_Tip, s_TableName, v_Operatie, v_Moment, c_Variabile, c_Trig, s_MasterField, s_KeyField, vInactiv
    FROM trigar t
      LEFT JOIN user_tab_columns c ON c.table_name = Upper(t.TableName) AND c.column_id = 1
    WHERE t.codtrigar = RecId;
  EXCEPTION 
    WHEN no_data_found THEN v_Tip := 0;
  END;   

  if vInactiv = 1 then
      sActiv := &apos; DISABLE&apos;;
    else
      sActiv := &apos; ENABLE&apos;;
    end if;

  IF v_Tip = 1 THEN
    IF s_MasterField IS NULL THEN 
      s_MasterField := s_KeyField;
    END IF;

    c_DDL :=  &apos;CREATE OR REPLACE FUNCTION &apos;||s_Prefix||&apos;FWME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;()&apos;||Chr(13)||
              &apos;  RETURNS TRIGGER &apos;||Chr(13)||
              &apos;  LANGUAGE PLPGSQL AS $function$ &apos;||Chr(13)||
              &apos;begin&apos;;

    FOR vRec IN (
      SELECT t1.FieldName, tc.Data_Type
      FROM trigar t
        INNER JOIN trigar1 t1 ON t1.CodTrigar = t.CodTrigar 
        LEFT JOIN user_tab_columns tc ON tc.table_name = Upper(t.TableName) AND tc.column_name = Upper(t1.FieldName)
      WHERE t.CodTrigar = RecId
      ORDER BY codtrigar1
    ) LOOP

      s_AuxCompare := &apos;New.&apos;||vRec.FieldName||&apos; &lt;&gt; Old.&apos;||vRec.FieldName;
      s_AuxInsert  := &apos;Substr(Old.&apos;||vRec.FieldName||&apos;::varchar,1,100), Substr(New.&apos;||vRec.FieldName||&apos;::varchar,1,100)&apos;;

      c_DDL := c_DDL||Chr(13)||
              &apos;  IF (New.&apos;||vRec.FieldName||&apos; is Null and Old.&apos;||vRec.FieldName||&apos; is not Null) &apos;||Chr(13)||
              &apos;  OR (New.&apos;||vRec.FieldName||&apos; is not Null and Old.&apos;||vRec.FieldName||&apos; is Null) &apos;||Chr(13)||
              &apos;  OR (&apos;||s_AuxCompare||&apos;)&apos;||Chr(13)|| 
              &apos;  THEN &apos;||Chr(13)||
              &apos;    INSERT INTO trigar_modif (CodModif, DatAmodif, UserModif, Cod, CodMaster, TableName, FieldName, OldValue, NewValue)&apos;||Chr(13)||
              &apos;    VALUES(SEQ_TRIGAR_MODIF.NextVal, sysDate, pkg_globals.GETUSERID, Old.&apos;||s_KeyField||&apos;,Old.&apos;||s_MasterField||&apos;, &apos;&apos;&apos;||s_TableName||&apos;&apos;&apos;, &apos;&apos;&apos;||vRec.FieldName||&apos;&apos;&apos;, &apos;||s_AuxInsert||&apos;);&apos;||Chr(13)||
              &apos;  END IF;&apos;;
    END LOOP; 
    c_DDL := c_DDL||Chr(13)||
              &apos;END;&apos;||
              &apos;$function$&apos;;
  ELSIF v_Tip = 2 THEN 
    c_DDL :=  &apos;CREATE OR REPLACE FUNCTION &apos;||s_Prefix||&apos;FWME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;()&apos;||Chr(13)||
              &apos;  RETURNS TRIGGER &apos;||Chr(13)||
              &apos;  LANGUAGE PLPGSQL AS $function$ &apos;||Chr(13)||
              &apos;declare&apos;||Chr(13)||
              c_Variabile||Chr(13)||
              &apos;begin&apos;||Chr(13)||
              c_Trig||Chr(13)||
              &apos;END; &apos;||chr(13)||
              &apos;$function$&apos;;
  END IF;
  execute immediate c_DDL;

  c_DDL :=  &apos;DO $$ &apos;||CHR(13)||
            &apos;BEGIN DROP TRIGGER IF EXISTS TWME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos; ON &apos;||s_Prefix||&apos;.&apos;||s_TableName||&apos;; &apos;||CHR(13)||
            &apos;CREATE OR REPLACE TRIGGER TWME_&apos;||s_TableName||&apos;_&apos;||RecId||Chr(13)||
            &apos;  &apos;||CASE v_Moment WHEN 1 THEN &apos;before&apos; ELSE &apos;after&apos; END||&apos; &apos;||CASE v_Operatie WHEN 1 THEN &apos;insert&apos; WHEN 2 THEN &apos;update&apos; ELSE &apos;delete&apos; END||&apos; on &apos;||s_Prefix||s_TableName||Chr(13)||
            &apos;  for each row&apos;||Chr(13)||
            &apos;  EXECUTE PROCEDURE &apos;||s_Prefix||&apos;FWME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;();&apos;||chr(13)||
            &apos;  ALTER TABLE &apos;||s_Prefix||s_TableName||sActiv||&apos; TRIGGER TWME_&apos;||s_TableName||&apos;_&apos;||RecId||&apos;;&apos;||chr(13)||
            &apos;END $$;&apos;;
  
  execute immediate c_DDL;
END;

procedure TaskToUser(acodUser in number, aCodPArt in number, aPROBLEMA in varchar2, SursaMesaj in varchar2, FaraCommit in number default 0) is
  aUsername varchar2(100);
  TaskFirma number(1);
begin
  SELECT NVL(pkg_categconst.GetValConstanta(&apos;TaskFirma&apos;, pkg_globals.ANLUCRU,pkg_globals.lunalucru), &apos;0&apos;)
	INTO TaskFirma from dual;
	select winmadmin.pkg_userfirme.getUserName(aCoduser) into ausername from dual;
  if TaskFirma = 2 then
		INSERT INTO SETTASK (
				CODTASK,
				PROBLEMA, Subunitatea, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART
			)
		VALUES (
				Seq_SETTASK_CODTASK.Nextval,
				aPROBLEMA, 1, &apos;AUTOMAT&apos;, SursaMesaj, &apos;FIRMA&apos;, aUSERNAME, PKG_GLOBALS.getUSERNAME, aUSERNAME, SysDate,SysDate,&apos;ORA&apos;,0,1, PKG_GLOBALS.getCODFIRMA, aCodPArt
			) ;
	else	
		INSERT INTO WINMADMIN.SETTASK (
				CODTASK,
				PROBLEMA, OBSERVATII, PROIECT, DESTINATAR, EXECUTANT, USERNAME, MESAJCATRE, TERMEN,DATATASK,DOMENIU,TIP,PRIORITATE, CODFIRMA, CODPART
			)
		VALUES (
        winmadmin.PKG_USERFIRME.getSeqNextVal(&apos;Seq_SETTASK_CODTASK&apos;),
				aPROBLEMA, &apos;AUTOMAT&apos;, SursaMesaj, &apos;FIRMA&apos;, aUSERNAME, PKG_GLOBALS.getUSERNAME, aUSERNAME, SysDate,SysDate,&apos;ORA&apos;,0,1, PKG_GLOBALS.getCODFIRMA, aCodPArt
			) ;
 end if;
 if FaraCommit = 0 then
   commit;
 end if;  
end;

procedure TaskToPers(aCodPers in number, aCodPArt in number, aPROBLEMA in varchar2, SursaMesaj in varchar2) is
aCodUser number; 
begin
	aCodUser := null;
  select LOGONNAME into aCodUser from NPers where CodPers = aCodPers; 
  if Coalesce(acodUser, 0) &lt;&gt; 0 then 
		TaskToUser(aCodUser, aCodPArt, aPROBLEMA, SursaMesaj);
	end if;
end;

procedure MessageToUser(acodUser in number, Mesaj in varchar2, SursaMesaj in varchar) is
aUsername varchar2(100);
begin
	select winmadmin.pkg_userfirme.getUserName(aCoduser) into aUsername from dual;
	insert into winmadmin.mesaje(codmesaj,   text,                from_user,  skemafirma,data,   tip_mesaj) values
		(winmadmin.seq_mesaje_codmesaj.nextval,substr(Mesaj,1,4000),SursaMesaj, null ,     sysdate,0);

	insert into winmadmin.mesaje1(codmesaj1,codmesaj,to_user) values
	 (winmadmin.seq_mesaje1_codmesaj1.nextval,winmadmin.seq_mesaje_codmesaj.currval,aUsername);
  --commit;
end;

procedure MessageToPers(aCodPers in number, Mesaj in varchar2, SursaMesaj in varchar) is
aCodUser number; 
begin
	aCodUser := null;
  select LOGONNAME into aCodUser from NPers where CodPers = aCodPers; 
  if Coalesce(acodUser, 0) &lt;&gt; 0 then MessageToUser(acodUser, Mesaj, SursaMesaj); end if;
end;

procedure SendSMS(NrTelefon in varchar2, Mesaj in varchar2, NoCommit in number default 0) is
res number;
MSG_EROARE VARCHAR2(300);
begin
  res := PKG_SMS.SEND_SMS_Full(NRTELEFON, MESAJ, &apos;Automat&apos;, 0,0,0,1, MSG_EROARE, NoCommit);
end;

procedure SMSToPart(aCodPart in number, Mesaj in varchar2) is
NrTelefon varchar2(100);
begin
  select Coalesce(Telefon,&apos;?&apos;) into NrTelefon from NAgenda where codpart = aCodPart;
  SendSMS(NrTelefon, Mesaj);
	Commit;
end;

procedure SMSToPers(aCodPers in number, Mesaj in varchar2, NoCommit in number default 0) is
NrTelefon varchar2(100);
begin
	if Coalesce(aCodPers, 0) &gt; 0 then 
		select Coalesce(Telefon,&apos;?&apos;) into NrTelefon from NAgenda a
		inner join NPERS p on p.Agenda = a.CodAgenda where p.codpers = aCodPers;
  	SendSMS(NrTelefon, Mesaj,NoCommit);
    if NoCommit &lt;&gt; 1 then
  	  Commit;
    end if;  
	end if;
end;

procedure SMSToUSER(aCodUSER in number, Mesaj in varchar2, NoCommit in number default 0) is
aCodPers number;
begin
  select CodPers into aCodPers from NPers where LOGONNAME = aCodUser and RowNum = 1; 
  SMSToPers(aCodPers, Mesaj, NoCommit); 
end;
END PKG_TRIGAR;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_TVASERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADF1F7953176EFBB65BDAC974FCC71C09553457E</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_TVASERV is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
Tmp NUMBER(20);
BEGIN
  SELECT CodTVASERV INTO Tmp FROM TVASERV WHERE CodTVASERV = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM TVASERV WHERE CodTVASERV = RecId;
  NotifyModif(2, RecId, &apos;TVASERV&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_TVASERV FIELDS( CodTVASERV ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  aANSFARSIT   NUMBER(4);
  aLUNASFARSIT NUMBER(2);
BEGIN
  INSERT INTO TMP_TVASERV(CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL)
  SELECT CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL
  FROM TVASERV WHERE CodTVASERV = RecId;
  
  -- Detail TVASERV1
  INSERT INTO  TMP_TVASERV1 (CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
    ( SELECT CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP
      FROM TVASERV1 WHERE CodTVASERV = RecId);
  aANSFARSIT := 0; aLUNASFARSIT := 0;
  FOR V_REC IN (SELECT CODTVASERV1, ANSTART, LUNASTART FROM TMP_TVASERV1 ORDER BY ANSTART * 12 + LUNASTART DESC) LOOP
    IF (aANSFARSIT &lt;&gt; 0)AND(aLUNASFARSIT &lt;&gt; 0) THEN
      UPDATE TMP_TVASERV1
      SET
        ANSFARSIT   = aANSFARSIT,
        LUNASFARSIT = aLUNASFARSIT
       WHERE
       CODTVASERV1 = V_REC.CODTVASERV1;
    END IF;
    PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(V_REC.ANSTART, V_REC.LUNASTART, aANSFARSIT, aLUNASFARSIT);
  END LOOP;
  COMMIT;
END;

PROCEDURE makeJurnalDirty(pCodTVAServ IN NUMBER,  pALStart IN NUMBER, pALStop IN NUMBER) IS
BEGIN
  for v_rec in (select i.codies, i.tipdoc 
                                                    from iesiri i
                                                    where i.codtvaserv = pCodTVAServ
                                                    and (i.an * 12 + i.luna) between pALStart and pALStop) loop
      update jurnal1 j1
             set dirty = 1   
      where j1.coddoc = v_rec.codies and  j1.tipdoc = v_rec.tipdoc;
  end loop;
  commit;                                                    
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  tRecId NUMBER;
BEGIN
  delete from tmp_manevra;
  IF Operation = 0 THEN
    select codtvaserv into recid from tmp_tvaserv;
    UPDATE TVASERV
    SET (DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL) = (SELECT DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL FROM TMP_TVASERV)
    WHERE CodTVASERV = RecId;

-- Detail NTVA1
   for v_rec in 
              (select * from TVASERV1 
                where CODTVASERV = RecId 
                     and (CODTVASERV1 not in (Select CODTVASERV1 from TMP_TVASERV1))) LOOP
      makeJurnalDirty(RecId,  v_rec.alstart,  v_rec.alstop);                  
    END LOOP;
    
    DELETE FROM TVASERV1 where CODTVASERV = RecId and CODTVASERV1 not in (Select CODTVASERV1 from TMP_TVASERV1);
    
    for v_rec in (
      SELECT   CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP FROM TMP_TVASERV1 WHERE CODTVASERV1 &lt; 0
      ) LOOP
      tRecId := SEQ_TVASERV1_CODTVASERV1.Nextval;
       INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
                                VALUES( tRecId , RecId , v_rec.CODCONT, v_rec.ANSTART, v_rec.LUNASTART, v_rec.ALSTART, v_rec.ALSTOP);
       INSERT INTO tmp_manevra values(tRecId);                         
    END LOOP;

    FOR v_rec IN ( SELECT * FROM TMP_TVASERV1 WHERE NVL(CODTVASERV1,-1) &gt; 0 ORDER BY CODTVASERV1 ) LOOP
      SELECT  CASE WHEN CODCONT = v_rec.CODCONT THEN 0 ELSE 1 END , anstart, lunastart INTO vRecNo,vAn,vLuna
      FROM TVASERV1 WHERE CODTVASERV1 = COALESCE(v_rec.CODTVASERV1,0);
      IF (vRecNo &gt; 0) THEN
        IF (v_rec.anstart = vAn) and (v_rec.lunastart = vLuna) THEN
          UPDATE TVASERV1 SET CODCONT = v_rec.CODCONT WHERE CODTVASERV1 = v_rec.CODTVASERV1;
          INSERT INTO tmp_manevra values(v_rec.CODTVASERV1); 
        ELSE
          tRecId := SEQ_TVASERV1_CODTVASERV1.Nextval;
          INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP ) 
          VALUES ( tRecId, RecId,v_rec.CODCONT,v_rec.ANSTART,v_rec.LUNASTART,v_rec.ALSTART,v_rec.ALSTOP );
          INSERT INTO tmp_manevra values(tRecId); 
        END IF;
      END IF;
    END LOOP;
    
  ELSE -- INSERT
    SELECT seq_TVASERV_CodTVASERV.NextVal INTO RecId FROM DUAL;

    INSERT INTO TVASERV(CODTVASERV,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL)
    SELECT RecId,DENUMIRE,CODTARA,TIPCOTA,PROCENT,CODCONT,SIMBOL
    FROM TMP_TVASERV;
    
    INSERT INTO TVASERV1 ( CODTVASERV1,  CODTVASERV, CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP )
    SELECT  SEQ_TVASERV1_CODTVASERV1.Nextval , RecId , CODCONT, ANSTART, LUNASTART, ALSTART, ALSTOP
    FROM TMP_TVASERV1;

  END IF;
  PRC_AL_REFRESH(&apos;TVASERV1&apos;, RecId);
  
  for v_rec in (select * from TVASERV1 where CODTVASERV1 in (select tm.codunic from tmp_manevra tm) ) loop
      makeJurnalDirty(RecId,  v_rec.alstart,  v_rec.alstop);                     
  end loop;
  delete from tmp_manevra;
  NotifyModif(Operation, RecId, &apos;TVASERV&apos;);
  COMMIT;
END;

end PKG_TVASERV;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_UM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CA4B387B18CE720D3D04CFF3E5CE29E40CF0DCC</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_UM IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodUM INTO Tmp FROM NUM WHERE CodUM = RecId FOR UPDATE NOWAIT;
END;

function GetCoefUM(aCodUM1 in number) return number is
Rez number(20,7);
begin
  Rez := 1.0;

  begin
    SELECT nvl(num.COEF,0) into Rez
    FROM NUM
         inner join num1 on num.codum = num1.codum
    WHERE num1.CODUM1 = aCodUM1;
  exception when others then Rez := 1.0;
  end;

  if Rez = 0.0 then Rez := 1.0; end if;
  return Rez;
end;

function GetSpecificCantUM(aUM in number, aUM1 in number, aPrincipala in number, aPrincipala1 in number,
                           aRel in number, aD1 in number, aD2 in number, aD3 in number, aCant1 in number, aCoef in number) return number is
Rez number(20,7);
Coef number(20,7);
Cant1 number(20,7);
Rel number(20,7);
D1 number(20,7);
D2 number(20,7);
D3 number(20,7);
begin
  D1 := aD1;
  D2 := aD2;
  D3 := aD3;
  Rez := 0.0;
  Coef := aCoef;
  if Coef = 0 then Coef := 1; end if;
  Cant1 := aCant1;
  Cant1 := Cant1 * pkg_um.GetCoefUM(aUM1);
  Rel := aRel;
  if Rel in (1,2,3,7,8,9) then
    Rez := Cant1 * D1;
    if Rel in (2,3,8,9) then
      Rez := Rez * D2;
      if Rel in (3,9) then Rez := Rez * D3; end if;
    end if;
    Rez := Coef * Rez / pkg_um.GetCoefUM(aUM);
  else
    if Rel in (4,5,6,10,11,12) then
      Rez := 0.0;
      if D1 &lt;&gt; 0.0 then Rez := Cant1 / D1; end if;
      if Rel in (5,6,11,12) then
        if D2 &lt;&gt; 0.0 then Rez := Rez / D2; end if;
        if Rel in (6,12) then
          if D3 &lt;&gt; 0.0 then Rez := Rez / D3; end if;
        end if;
      end if;
      Rez := Rez / Coef / pkg_um.GetCoefUM(aUM);
    end if;
  end if;
  return Rez;
end;

function  GetSpecificCantUM1(aUM in number, aUM1 in number, aPrincipala in number, aPrincipala1 in number,
                             aRel in number, aD1 in number, aD2 in number, aD3 in number, aCant in number, aCoef in number) return number is
Rez number(20,7);
Coef number(20,7);
Cant number(20,7);
Rel number(20,7);
D1 number(20,7);
D2 number(20,7);
D3 number(20,7);
begin
  D1 := aD1;
  D2 := aD2;
  D3 := aD3;
  Rez := 0.0;
  Coef := aCoef;
  if Coef = 0 then Coef := 1; end if;
  Cant := aCant;
  Cant := Cant * pkg_um.GetCoefUM(aUM);
  Rel := aRel;

  if Rel in (1,2,3,7,8,9) then
    if D1 &lt;&gt; 0.0 then Rez := Cant / D1; end if;
    if Rel in (2,3,8,9) then
      if D2 &lt;&gt; 0.0 then Rez := Rez / D2; end if;
      if Rel in (3,9) then
        if D3 &lt;&gt; 0.0 then Rez := Rez / D3; end if;
      end if;
    end if;
    Rez := Rez / Coef / pkg_um.GetCoefUM(aUM1);
  else
    if Rel in (4,5,6,10,11,12) then
      Rez := Cant * D1;
      if Rel in (5,6,11,12) then
        Rez := Rez * D2;
        if Rel in (6,12) then Rez := Rez * D3; end if;
      end if;
      Rez := Rez * Coef / pkg_um.GetCoefUM(aUM1);
    end if;
  end if;
  return Rez;
end;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
	DELETE FROM num1 WHERE CodUM = recid;
	DELETE FROM NUM WHERE CodUM = RecId ;
  NotifyModif(2, RecId, &apos;NUM&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NUM FIELDS( CodUM ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master NUM
  INSERT INTO  TMP_NUM (CodUM, Den_UM, Tip, Zecimale, TipUM, Coef, ActualizArt, CodUMSaft, ParitateUMSaft )
  SELECT CodUM, Den_UM, Tip, Zecimale, Nvl(TipUM,0), Coef, 0 ActualizArt, CodUMSaft, ParitateUMSaft
  FROM NUM WHERE CodUM = RecId ;

  UPDATE TMP_NUM SET (OBS, CodExtern, Den_EANCom, Den_Intrastat) = (SELECT OBS, CodExtern, Den_EANCom, Den_Intrastat FROM NUM1 WHERE CodUM = RecId and Secundara = 0) ;

-- Detail NUM1
  INSERT INTO  TMP_NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft)
  SELECT CodUM1, CodUM, Secundara,Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
  FROM NUM1 WHERE CodUM = RecId AND Secundara = 1 ;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo    INTEGER := 0;
  vAn       INTEGER := 0;
  vLuna     INTEGER := 0;
  Nr        NUMBER(20);
  aTipUM    NUMBER(1);
  aCoef     NUM.COEF%TYPE;
  aActArt   NUMBER(1);

BEGIN
  IF Operation = 0 THEN  -- UPDATE
    -- Master NUM
    SELECT CodUM,  TipUM,  Coef,  ActualizArt
    INTO   RecId, aTipUM, aCoef, aActArt
    FROM TMP_NUM;

    UPDATE NUM1
    SET (Den_UM1, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft) = (SELECT Den_UM, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft FROM TMP_NUM)
    WHERE CodUM = RecId AND Secundara = 0;

    UPDATE NUM
    SET ( Den_UM, Tip, Zecimale, TipUM, Coef, CodUMSaft, ParitateUMSaft) = (SELECT Den_UM, Tip, Zecimale, TipUM, Coef, CodUMSaft, ParitateUMSaft FROM TMP_NUM )
    WHERE CodUM = RecId ;

    -- Detail NUM1
    DELETE FROM NUM1
    WHERE CodUM = RecId AND Secundara = 1 AND CodUM1 NOT IN ( SELECT CodUM1 FROM TMP_NUM1 WHERE NVL(CodUM1,0) &lt;&gt; 0);

    INSERT INTO NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft)
    SELECT  seq_NUM1_CodUM1.Nextval, RecId, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM1
    WHERE CodUM1 &lt; 0; --NVL(g_CodUM1, 0);

    FOR v_rec IN ( SELECT * FROM TMP_NUM1 WHERE NVL(CodUM1,-1) &gt; 0 ORDER BY CodUM1 )
    LOOP
      SELECT Count(*) INTO vRecNo FROM NUM1 WHERE CodUM1 = NVL(v_rec.CodUM1,0);
      IF (vRecNo=1) THEN
        UPDATE NUM1
        SET CodUM          = RecId,
            Secundara      = v_rec.Secundara,
            Den_UM1        = v_rec.Den_UM1,
            Paritate       = v_rec.paritate,
            Zecimale       = v_rec.Zecimale,
            Obs            = v_rec.Obs,
            CodExtern      = v_rec.Codextern,
            Den_EANCom     = v_rec.Den_EANCom,
            Den_Intrastat  = v_rec.Den_Intrastat,
            Inactiv        = v_rec.Inactiv,
            CodUMSaft      = v_rec.CodUMSaft,
            ParitateUMSaft = v_rec.ParitateUMSaft
        WHERE CodUM1 = v_rec.CodUM1;
      END IF;
    END LOOP;

    IF aActArt = 1 AND aCoef &lt;&gt; 0 THEN
      IF    aTipUM = 1 THEN -- masa
         UPDATE (SELECT o.masa  FROM nart a INNER JOIN nartobj o ON o.codarticol = a.codarticol WHERE a.um = RecId)
         SET masa = 1 / aCoef;
      ELSIF aTipUM = 2 THEN  -- volum
         UPDATE (SELECT o.volum FROM nart a INNER JOIN nartobj o ON o.codarticol = a.codarticol WHERE a.um = RecId)
         SET volum = 1 / aCoef;
      END IF;
    END IF;
  ELSE  -- INSERT
    -- Master NUM
    SELECT seq_NUM_CodUM.NextVal INTO RecId FROM DUAL;

    INSERT INTO  NUM ( CodUM, Den_UM, Tip, Zecimale, TipUM, Coef, CodUMSaft, ParitateUMSaft )
    SELECT  RecId, Den_UM, Tip, Zecimale, TipUM, Coef, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM ;

    -- Detail NUM1
    INSERT INTO  NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft )
    SELECT  seq_NUM1_CodUM1.Nextval, RecId, Secundara, Den_UM1, Paritate, Zecimale, OBS, CodExtern, Den_EANCom, Den_Intrastat, Inactiv, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM1
    WHERE Secundara = 1;
  END IF;

  /* inregistrarea cu UM principala */
  SELECT COUNT(*) into Nr FROM NUM1 where CodUM = RecID and Secundara = 0;
  IF Nr = 0 THEN
    INSERT INTO NUM1 (CodUM1, CodUM, Secundara, Den_UM1, Paritate, ZECIMALE, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft)
    SELECT seq_NUM1_CodUM1.Nextval, RecId, 0, Den_UM, 1, ZECIMALE, OBS, CodExtern, Den_EANCom, Den_Intrastat, CodUMSaft, ParitateUMSaft
    FROM TMP_NUM;
  END IF;
  NotifyModif(Operation, RecId, &apos;NUM&apos;);
  COMMIT;
END;

FUNCTION TEST_UNICITATE_UM(DenUM IN varchar2, Cod IN NUMBER) RETURN NUMBER
is PRAGMA AUTONOMOUS_TRANSACTION;
  Nr NUMBER(20);
BEGIN
  SELECT COUNT(*) INTO Nr FROM NUM WHERE Upper(Den_UM) = Upper(DenUM) AND CodUM &lt;&gt; Cod;
  RETURN Nr;
END;

END PKG_UM;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EAD3816790793767E102765B249E31E677E83560</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_UMSEC IS

FUNCTION GETDENUM(ACODUM IN NUMBER) RETURN VARCHAR
IS
DEN VARCHAR2(30);
BEGIN
  BEGIN
    SELECT DEN_UM INTO DEN FROM NUM WHERE CODUM = ACODUM;
    EXCEPTION WHEN OTHERS THEN DEN := &apos; &apos;;
  END;  
  RETURN NVL(DEN, &apos; &apos;);
END;

PROCEDURE GETINFOUMSEC(ACODUMSEC IN NUMBER, DEN OUT VARCHAR, PARIT OUT NUMBER)
IS
BEGIN
  DEN := &apos;&apos;; PARIT := 1;
  BEGIN
    SELECT DEN_UM1, PARITATE INTO DEN, PARIT FROM NUM1 WHERE CODUM1 = ACODUMSEC;
    EXCEPTION WHEN OTHERS THEN BEGIN DEN := &apos;&apos;;PARIT := 1;END;
  END;
END;

PROCEDURE GetUMSecDupaDEN(ACODUM IN NUMBER, DEN IN VARCHAR, ACODUMSEC OUT NUMBER)
IS
BEGIN
  ACODUMSEC := 0;
  BEGIN
    SELECT CODUM1 INTO aCODUMSec FROM NUM1 WHERE CODUM = ACODUM AND UPPER(DEN_UM1) LIKE DEN;
    EXCEPTION WHEN OTHERS THEN BEGIN ACODUMSEC := 0; END;
  END;
END;



PROCEDURE GETINFOUMIMPLICITA(ACODUM IN NUMBER, CODUMSEC OUT NUMBER, DEN OUT VARCHAR)
IS
BEGIN
  CODUMSEC := 0; DEN := &apos;&apos;;
  BEGIN
    SELECT CODUM1, DEN_UM1 INTO CODUMSEC, DEN FROM NUM1 WHERE CODUM = ACODUM AND SECUNDARA = 0;
    EXCEPTION WHEN OTHERS THEN CODUMSEC := 0; DEN := &apos;&apos;;
  END;   
END;


-- SELECTEAZA DIN NUM1 CODUL UM PRINCIPALA AL UNEI UMSEC
FUNCTION GETCODUMPRINCIPALA(ACODUM1 IN NUMBER) RETURN NUMBER
IS
 ACOD NUMBER;
BEGIN
  BEGIN
    SELECT CODUM INTO ACOD FROM NUM1 WHERE CODUM1 = ACODUM1;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;
  RETURN NVL(ACOD, 0);
END;


FUNCTION GETCODUMIMPLICITA(ACODUMPRINCIPALA IN NUMBER) RETURN NUMBER
IS
CODUMSEC NUMBER(18) := 0;
BEGIN
  BEGIN
    SELECT CODUM1 INTO CODUMSEC FROM NUM1 WHERE  CODUM = ACODUMPRINCIPALA AND SECUNDARA = 0;
    EXCEPTION WHEN OTHERS THEN RETURN 0;
  END;
  RETURN NVL(CODUMSEC, 0);
END;



PROCEDURE SP_LOCKRECORD( RECID IN NUMBER ) IS
  TMP NUMBER(20);
BEGIN
  SELECT CODUM1 INTO TMP FROM NUM1 WHERE CODUM1 = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RECID IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RECID);
  DELETE FROM NUM1 WHERE CODUM1 = RECID ;
  NotifyModif(2, RecId, &apos;NUM1&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_NUM1 FIELDS( CODUM1) VALUES ( 0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RECID IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_NUM1 (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft)
  ( SELECT CODUM1, CODUM, SECUNDARA,DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft
    FROM NUM1 WHERE CODUM1 = RECID ) ;

  COMMIT;

END;


PROCEDURE SP_POSTRECORDS(OPERATION IN NUMBER, RECID OUT NUMBER ) IS
BEGIN
  IF OPERATION = 0 THEN  -- UPDATE
    SELECT  CODUM1 INTO RECID FROM TMP_NUM1;
    UPDATE NUM1 SET ( CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft)
       = ( SELECT CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft FROM TMP_NUM1 )
    WHERE CODUM1 = RECID ;
  ELSE  -- INSERT
    SELECT SEQ_NUM1_CODUM1.NEXTVAL INTO RECID FROM DUAL;
    INSERT INTO  NUM1 (CODUM1, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft)
    (SELECT  RECID, CODUM, SECUNDARA, DEN_UM1, PARITATE, ZECIMALE, OBS, CodUMSaft, ParitateUMSaft FROM TMP_NUM1) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;NUM1&apos;);
COMMIT;
END;



END PKG_UMSEC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A74DBFF7B0D17B321FC1477D72BC00825A5F230B</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_utilaje IS

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_53&apos;;

vCodUtilaj2C number(20);


PROCEDURE GETLASTAPELURI(NRAPELURI IN NUMERIC)
IS
BEGIN
  DELETE TMP_APELTELEFON;
  INSERT INTO TMP_APELTELEFON(CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT, MODIFICAT)
  SELECT * FROM
  (
    SELECT CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT, 0
    FROM APELTELEFON
    ORDER BY DATAORA DESC 
  )
  WHERE 
    ROWNUM &lt;= NRAPELURI;  
  COMMIT;  
END;    

PROCEDURE POSTAPELURI
IS
BEGIN
  FOR V_REC IN (SELECT * FROM TMP_APELTELEFON WHERE MODIFICAT = 1)
  LOOP
    IF V_REC.CODAPEL &lt; 0 THEN
      INSERT INTO APELTELEFON(CODAPEL, IDAPEL, STARE, TELEFON, APELANT, DATAORA, PRELUAT, CLIENT)
      VALUES(SEQ_APELTELEFON_CODAPEL.NEXTVAL, V_REC.IDAPEL, V_REC.STARE, V_REC.TELEFON, V_REC.APELANT, V_REC.DATAORA, V_REC.PRELUAT, V_REC.CLIENT);
    ELSE
      UPDATE APELTELEFON
      SET
        STARE = V_REC.STARE,
        PRELUAT = V_REC.PRELUAT
      WHERE
        CODAPEL = V_REC.CODAPEL; 
    END IF;       
  END LOOP;    

  COMMIT;  
END;    



procedure GENUTILAJ(vCodObiect in number, vUM in number, vCodPart in number) is pragma autonomous_transaction;
RecID number(20);
begin
  delete tmp_utilaje;
  insert into tmp_utilaje(codutilaj, CodObiect, UM, CodPart)
  values (0, vCodObiect, vUM, vCodPart);
  commit;
  SP_POSTRECORDS(-1, RecId);
end;

function AduUltimaCitire(aCodUtilaj in number, pTipIndex in number default 0 ) return number is
vCod number(20);
begin
  vCod := 0;
  for v_rec in (select codutilaj3
                from utilaje3
                where codutilaj = aCodUtilaj
                and coalesce(tip_index, 0) = pTipIndex
                order by an, luna, databord) loop
    vCod := v_rec.codutilaj3;
  end loop;
  return vCod;
end;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
TMP NUMBER(20);
BEGIN
  SELECT CODUTILAJ INTO TMP FROM UTILAJE WHERE CODUTILAJ = RECID FOR UPDATE NOWAIT;
END;

PROCEDURE SETCODUTILAJ2C( aCodUtilaj2C IN NUMBER ) IS
BEGIN
  vCodUtilaj2C := aCodUtilaj2C;
END;

function GETCODUTILAJ2C return number IS
BEGIN
  return vCodUtilaj2C;
END;

function GetSectieInterventie(aCodProdComp in number) return number is
aCount number(10);
begin
  if aCodProdComp = 0 then return 0; end if;
  select count(*) into acount
  from prodcomp pc
       inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
  where pc.codprodcomp = aCodProdComp;

  if acount = 1 then
    select pg.codgest into acount
    from prodcomp pc
         inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
    where pc.codprodcomp = aCodProdComp;
  end if;
  return aCount;
end;

function GetDenSectieInterventie(aCodProdComp in number) return varchar2 is
aCount number(10);
aDen varchar2(100);
begin
  if aCodProdComp = 0 then return &apos;... nedefinit ...&apos;; end if;
  select count(*) into acount
  from prodcomp pc
       inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
  where pc.codprodcomp = aCodProdComp;

  if acount = 1 then
    select g.den_gest into aDen
    from prodcomp pc
         inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
         inner join ngest g on g.codgest = pg.codgest
    where pc.codprodcomp = aCodProdComp;
  end if;
  return aDen;
end;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  aDoc varchar2(200);
BEGIN
  SP_LOCKRECORD(RecId);
  -- nomUtilaje --&gt; 508
  PKG_CFGTABLES.EXT_DELETERECORD (recId, 508);
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
    SELECT &apos;Utilaj &quot;&apos;||nrinventar||&apos;&quot;&apos; INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
    WINMADMIN.PKG_USERFIRME.PostLog(&apos;UTILAJE&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;

  update iesiri1 set codutilaj = null where codutilaj = recid;
  DELETE FROM UTILAJE2P WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE2C WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE2  WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJEDEV WHERE CODUTILAJ = RECID;
  FOR V_REC IN (SELECT CODUTILAJ20, STARE
                  FROM UTILAJE20 U20
                  WHERE U20.CODUTILAJ = RecID
                  ) LOOP
      DELETE UTILAJE20 WHERE CODUTILAJ20 = V_REC.CODUTILAJ20;
      INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, TIPMODIF)
      VALUES (SEQ_UTILAJEMON_CODMONITORIZARE.NEXTVAL, V_REC.CODUTILAJ20, PKG_GLOBALS.GETUSERID, SYSDATE, V_REC.STARE, &apos;STERGERE&apos;);            
    END LOOP;
  DELETE FROM UTILAJE1  WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJETIPINDEX WHERE CODUTILAJ = RECID;
  DELETE FROM UTILAJE   WHERE CODUTILAJ = RECID;
  NotifyModif(2, RecId, &apos;UTILAJE&apos;);
  COMMIT;
END;

PROCEDURE InitUtilajeTipIndex(pCodUtilaj IN NUMBER, pMaxIndexNum IN NUMBER DEFAULT 1) IS
  existingNum number(10);  
  existingUM   number(20);
  existingPlafon number(20,7);
  denIndex varchar2(100);
BEGIN
  select count(*) into existingNum from TMP_UTILAJETIPINDEX;
  if existingNum &lt; pMaxIndexNum then
    for i in existingNum .. pMaxIndexNum-1 loop
      existingUM     := null;
      existingPlafon := null;
      denIndex := &apos; Index &apos;|| i;
      if (i=0) then
        denIndex := &apos;bord&apos;; 
        begin
          select tu.um, tu.plafoncantf into existingUM, existingPlafon from tmp_utilaje tu;
        exception 
           when others then 
                existingUM     := null;
                existingPlafon := null;
          end;      
      end if;
      insert into TMP_UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf) 
                  VALUES (-1, pCodUtilaj, i, denIndex, existingUM, existingPlafon); 
    end loop;
  end if;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_UTILAJE(CODUTILAJ, TIP) VALUES(0, 0);
  -- nomUtilaje --&gt; 508
  PKG_CFGTABLES.EXT_INSERTRECORD(508);
  InitUtilajeTipIndex(0);
  COMMIT;
END;

PROCEDURE SP_GOTORECORD (RECID IN NUMBER) IS
aCount number(10);
LastIndex number(10);
DataLastIndex Date;
vAlerta number(2);

vDataI       Date;
vDataF       Date;
vDurata      number(20,7);
vOreStart    number(20,7);
vOreStop     number(20,7);
vOreSchimb   number(20,7);
vOrePeZi     number(20,7);
vNrSchimburi number(10);
vZile        Integer(10);
BEGIN
  INSERT INTO TMP_UTILAJE(CODUTILAJ,CODOBIECT,
       NRINVENTAR,
       ETICHETA,
       TIPUTILAJ,
       FLOTA,
       MODEL,
       ANF,
       SERIEF,
       INCARCARE,
       DATAGARANTIE,
       DATAGARANTIEI,
       INGARANTIE,
       LUNGIME,
       LATIME,
       INALTIME, OBS, DENUMIRE, INACTIV,CORECTIEINDEX, UM, CodGest, PLAFONCANTF,
       CodPart, Dincontract,
       CodIes1,
       FURNIZOR,
       DOC,
       APROBAT,
       DATASTART,
       NRCONTR,
       DATACONTR,
       CODCONTRFACT,
       CODFURNIZOR,
       TIP,
       CODLOCALIT,
       ADRESA,
       HFACTOR,
       AGENT,CODPRODUCATOR,CODLOCATIE)
  SELECT U.CODUTILAJ,U.CODOBIECT,
       case when U.NRINVENTAR = 0 then null else U.NRINVENTAR end,
       U.ETICHETA,
       U.TIPUTILAJ,
       U.FLOTA,
       U.MODEL,
       U.ANF,
       U.SERIEF,
       U.INCARCARE,
       U.DATAGARANTIE,
       U.DATAGARANTIEI,
       U.INGARANTIE,
       U.LUNGIME,
       U.LATIME,
       U.INALTIME, U.OBS, NOBJ.DENUMIRE, U.INACTIV, NVL(U.CORECTIEINDEX,-1),U.UM, U.CodGest, U.PLAFONCANTF,
       U.CodPart,
       (select count(*)
        from contract1 c1
             inner join contract c on c.codcontract = c1.codcontract
        where nvl(c.anulat,0) = 0 and c1.codutilaj = u.codutilaj),
        U.CodIes1,
        nvl(P.DEN_PART,&apos;?&apos;),
        case when U.DOC is null and U.CODIES1 &gt; 0 then I.NRDoc||&apos;/&apos;||to_char(I.DataDoc,&apos;DD.MM.YYYY&apos;) else U.DOC end,
        nvl(U.Aprobat,0),
        U.DATASTART,
        U.NRCONTR,
        U.DATACONTR,
        NVL(C1.CODCONTRACT,C.CODCONTRACT),
        U.CODFURNIZOR,
        CASE 
          WHEN U.TIP IS NULL AND U.CODPART &gt; 0 THEN 2 
          ELSE       
            CASE 
              WHEN (SELECT COUNT(*) FROM UTILAJE1 WHERE CODUTILAJ = RECID) &gt; 0 AND U.TIP IS NULL THEN 1
              ELSE NVL(U.TIP,0)
            END    
        END,
        U.CODLOCALIT,
        U.ADRESA,
        U.HFACTOR,
        U.AGENT,U.CODPRODUCATOR,U.CODLOCATIE 
  FROM UTILAJE U 
       INNER JOIN NARTOBJ NOBJ ON NOBJ.CODOBIECT = U.CODOBIECT
       LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = U.CODIES1
       LEFT JOIN IESIRI I ON I1.CODIES = I.CODIES
       LEFT JOIN NPART P ON U.CODFURNIZOR = P.CODPART
       LEFT JOIN CONTRACT1 C1 ON C1.CODCONTRACT1 = I1.CODCONTRACT1
       LEFT JOIN CONTRACT C ON C.CODCONTRACT = I.CODCONTRACT
  WHERE U.CODUTILAJ = RECID;

  INSERT INTO TMP_UTILAJE1
     ( CODUTILAJ1,
       CODUTILAJ,
       NRCONTR,
       CARNETCONTR,
       STATUS_PART,
       STATUS_DEPO,
       CODPART,
       CODLOCATIE,
       DATA,
       OBS,
       STATUS_SERVICE,
       Denlocatie,
       INDEXLOCAL,
       CODPERS,
       DATACREARE,
       RESPONSABIL,
       ESTETIC)
  SELECT
      U1.CODUTILAJ1,U1.CODUTILAJ,
      U1.NRCONTR,U1.CARNETCONTR,
      U1.STATUS_PART,U1.STATUS_DEPO,
      U1.CODPART,nvl(U1.CODLOCATIE,0),
      U1.DATA ,U1.OBS,U1.STATUS_SERVICE ,NAG.OBS,U1.INDEXLOCAL,
      U1.CODPERS,
      U1.Datacreare, P.NUME||&apos; &apos;||P.PRENUME, U1.ESTETIC
  FROM UTILAJE1 U1
       LEFT JOIN NPERS P ON P.CODPERS = NVL(U1.CODPERS,0)
       LEFT JOIN NAGENDA NAG ON U1.CODLOCATIE =  NAG.CODAGENDA
  WHERE CODUTILAJ = RECID;

  INSERT INTO TMP_UTILAJE20(CODUTILAJ20, CODUTILAJ, NRDOC, DATADOC, DESCRIERE, STARE, OPERATOR, OBS, DENOPERATOR, 
                            CODIES, FACTURARE,BONCONSUM,CODLOCALIT,ADRESA,CODPERSC,TELEFON, CALLCENTER, CODBC, PRIORITATE)
  SELECT U.CODUTILAJ20, U.CODUTILAJ, U.NRDOC, U.DATADOC, U.DESCRIERE, CASE WHEN U.STARE = 5 AND I.CODIES IS NULL THEN 4 ELSE U.STARE END, U.OPERATOR, U.OBS, UT.USERNAME DENOPERATOR, 
         I.CODIES,
         CASE WHEN I.CODIES IS NOT NULL THEN I.PREFIXDOC||I.NRDOC||&apos;/&apos;||TO_CHAR(I.DATADOC,&apos;DD.MM.YYYY&apos;) END,
         CASE WHEN BC.CODIES IS NOT NULL THEN BC.PREFIXDOC||BC.NRDOC||&apos;/&apos;||TO_CHAR(BC.DATADOC,&apos;DD.MM.YYYY&apos;) END,
         U.CODLOCALIT,U.ADRESA,U.CODPERSC,C.TELEFON, U.CALLCENTER, BC.CODIES, U.PRIORITATE
  FROM UTILAJE20 U
       LEFT JOIN TMP_UTILIZATOR UT ON U.OPERATOR = UT.CODUTILIZATOR
       LEFT JOIN NPERSCONTACT C ON U.CODPERSC = C.CODPERSC
       LEFT JOIN IESIRI I ON I.CODIES = U.CODIES
       LEFT JOIN IESIRI BC ON BC.CODIES = U.CODBC
  WHERE U.CODUTILAJ = RECID;
  
  INSERT INTO TMP_UTILAJEDEV(CODUTILAJDEV, CODUTILAJ, CODUTILAJ20, CODOBIECT, CANT, PRET, CANTFACT, FACTURABIL, CODIES1, DENUMIRE, CODUTILAJ2, SERVICIU, DENSERVICIU,
                             TIPLIVRARE,CODAUTO,TVA, VALOARE, CONSUMABIL, CANTCONS)
  SELECT D.CODUTILAJDEV, D.CODUTILAJ, D.CODUTILAJ20, D.CODOBIECT, D.CANT, D.PRET, D.CANTFACT, D.FACTURABIL, D.CODIES1, OBJ.DENUMIRE, D.CODUTILAJ2,
         IV.SERVICIU, SERV.DENUMIRE, D.TIPLIVRARE, U2.CODAUTO, NVL(D.TVA, D.CANT * D.PRET * OBJTVA.PROCENT / 100), D.CANT * D.PRET,
         D.CONSUMABIL,D.CANTCONS
  FROM UTILAJEDEV D
       LEFT JOIN UTILAJE2 U2 ON U2.CODUTILAJ2 = D.CODUTILAJ2
       LEFT JOIN NINTERVENTIIAUTO IV ON IV.CODINTERVENTIIAUTO = U2.INTERVENTIE
       LEFT JOIN NARTOBJ OBJ ON OBJ.CODOBIECT = D.CODOBIECT
       LEFT JOIN NARTOBJ SERV ON SERV.CODOBIECT = IV.SERVICIU
       LEFT JOIN (
                  SELECT
                    NTVA.PROCENT,
                    O.CODOBIECT
                  FROM
                    NARTOBJ O
                    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = O.CODARTICOL
                    LEFT OUTER JOIN TMP_NTVA_LUNA NTVA ON NTVA.CODTVA    = NAL.CODTVA
                 ) OBJTVA ON OBJTVA.CODOBIECT = D.CODOBIECT
  WHERE D.CODUTILAJ = RECID;

  UPDATE TMP_UTILAJE20 TMP SET
  DEVIZ = CASE WHEN (SELECT COUNT(*) FROM TMP_UTILAJEDEV D WHERE D.CODUTILAJ20 = TMP.CODUTILAJ20) &gt; 0 THEN 1 ELSE 0 END;

  INSERT INTO TMP_UTILAJE2 (CODUTILAJ2, CODUTILAJ,INTERVENTIE,CODCOMANDA1,CODOBIECT,CODRETETA,UMSec,
                            Denumire,Den_UM1,D1,D2,D3,RelatieUM1,RESTDEPREDAT, PERTIP, PERDURATA, PERKM, ATENTIONAREZILE, ATENTIONAREKM, DATACURENTA,
                            den_interventie, accidentala, CODUTILAJ20,CODAUTO,KMPARCURSI,DURATA,NRSCHIMBURI,ORESCHIMB,ORASTART)
  SELECT U2.CODUTILAJ2, U2.CODUTILAJ,U2.INTERVENTIE,U2.CODCOMANDA1,IA.Serviciu, IA.Codreteta,
         num1.codum1, obj.denumire, num1.den_um1, a.d1, a.d2, a.d3, a.relatieum1, nvl(prod.rest,0), ia.PERTIP, ia.PERDURATA, ia.PERKM, ia.ATENTIONAREZILE, ia.ATENTIONAREKM,
         to_date(sysdate, &apos;dd.mm.yyyy&apos;), ia.denumire, nvl(ia.accidentala,0), U2.CODUTILAJ20,U2.CODAUTO,U2.KMPARCURSI,
         PC.DURATA, G.NRSCHIMBURI, G.ORESCHIMB, G.ORASTART
  FROM UTILAJE2 U2
       left join ninterventiiauto ia on u2.interventie = ia.codinterventiiauto
       left join nartobj obj on ia.serviciu = obj.codobiect
       left join nart a on obj.codarticol = a.codarticol
       left join num1 on a.UM = num1.codum and nvl(num1.secundara,0) = 0
       left join comanda1 c1 on u2.codcomanda1 = c1.codcomanda1
       left join cmdprodmat prod on c1.codcomanda1 = prod.codcomanda1 and nvl(prod.tip,0) = 0
       left join prodcomp pc on pc.codprodcomp = ia.codreteta
       left join prodgest pg on pc.codprodcomp = pg.codprodcomp and coalesce(pg.timpest,0) = 0
       left join ngest g on pg.codgest = g.codgest
  WHERE u2.CODUTILAJ = RECID;

  for v_rec in (select * from tmp_utilaje2) loop
    select count(*) into acount
    from prodcomp pc
         inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
    where pc.codprodcomp = v_rec.codreteta;

    if acount = 1 then
      select pg.codgest into acount
      from prodcomp pc
           inner join prodgest pg on pg.codprodcomp = pc.codprodcomp
      where pc.codprodcomp = v_rec.codreteta;

      update tmp_utilaje2 set codgest = acount where codutilaj2 = v_rec.codutilaj2;
    end if;
  end loop;

  INSERT INTO TMP_UTILAJE2C (CODUTILAJ2C, CODUTILAJ2, CODUTILAJ, INDEXC, DATAINDEXC, CODCOMANDA1, indexv, datav, resetat, IndexLocal,
                             NrDoc, Datadoc, Den_Gest, Codcomanda, TipDoc, Explicatii,
                             DATASTART, DATAEND, DURATA, DATASTARTS, DATAENDS, CODINTR1, INDEXA, DATAA, ZiV, ORESTART, ORESTOP)
  SELECT u2c.CODUTILAJ2C, u2c.CODUTILAJ2, u2c.CODUTILAJ, u2c.INDEXC, u2c.DATAINDEXC, nvl(c1.CODCOMANDA1,0), u2c.indexv, u2c.datav, u2c.resetat, nvl(u2c.indexlocal, Row_Number() over (partition by u2c.codutilaj order by u2c.datav, u2c.indexv) ),
         c.nrdoc, c.datadoc, G.Den_Gest, c.codcomanda, c.tipdoc, u2c.Explicatii, u2c.datastart, u2c.dataend,
         case when coalesce(pc.durata,0) &gt; 0 then pc.durata
         else 
           case 
             when (not u2c.datastart is null) and (not u2c.dataend is null) then trunc(24 * 60 * (CAST(u2c.dataend AS DATE)- CAST(u2c.datastart AS DATE)))
           end
         end,
         to_char(u2c.datastart, &apos;DD.MM.YYYY HH24:MI&apos;), to_char(u2c.dataend, &apos;DD.MM.YYYY HH24:MI&apos;), i1.codintr1, U2C.INDEXV - NVL(I.ATENTIONAREKM,0), U2C.DATAV - NVL(I.ATENTIONAREZILE,0),
         to_char(trunc(u2c.datav), &apos;Day&apos;, &apos;NLS_DATE_LANGUAGE=ROMANIAN&apos;), U2C.ORESTART, U2C.ORESTOP
  FROM UTILAJE2C U2C
       INNER JOIN UTILAJE2 U2 ON U2C.CODUTILAJ2 = U2.CODUTILAJ2
       INNER JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
       left join comanda1 c1 on u2c.codcomanda1 = c1.codcomanda1
       left join comanda c on c1.codcomanda = c.codcomanda
       left join ngest g on g.codgest = c.codgest
       left join intrari1 i1 on c1.codcomanda1 = i1.codcmdint1
       left join prodcomp pc on pc.codprodcomp = i.codreteta
  WHERE u2c.CODUTILAJ = RECID;

  for v_rec in (
                select u2c.codutilaj2c, u2.codutilaj2, pc.durata, g.nrschimburi, g.oreschimb, g.orastart, u2c.datastart
                from utilaje2 u2
                     INNER JOIN NINTERVENTIIAUTO I ON I.CODINTERVENTIIAUTO = U2.INTERVENTIE
                     inner join prodcomp pc on pc.codprodcomp = i.codreteta
                     inner join utilaje2c u2c on u2c.codutilaj2 = u2.codutilaj2
                     inner join prodgest pg on pg.codprodcomp = pc.codprodcomp and coalesce(pg.timpest,0) = 0
                     inner join ngest g on g.codgest = pg.codgest
                where i.accidentala = 1 and pc.durata &lt;&gt; 0
               ) loop
    vDurata      := v_rec.Durata;
    vOreSchimb   := v_rec.OreSchimb;
    vNrSchimburi := v_rec.NrSchimburi;
    if vNrSchimburi = 0 then vNrSchimburi := 1; end if;
    if (vOreSchimb = 0) and (vNrSchimburi = 1) then vOreSchimb := 24;
    else
      if (vOreSchimb = 0) and (vNrSchimburi &gt; 1) then
        vOreSchimb := 24/vNrSchimburi;
      end if;
    end if;
    vOrePeZi := vOreSchimb * vNrSchimburi;
    update tmp_utilaje2c set durata = vDurata where codutilaj2c = v_rec.codutilaj2c;
    vDataI   := v_rec.DataStart;
    vZile    := Trunc(vDurata / 60 / vOrePeZi);
    if vZile = 0 then
      update utilaje2c set OreStart = vDurata / 60 where codutilaj2c = v_rec.codutilaj2c;
      update tmp_utilaje2c set OreStart = vDurata / 60 where codutilaj2c = v_rec.codutilaj2c;
      vOreStart := vDurata / 60;
    else
      if vOrePeZi &gt; 24 then
        update utilaje2c set OreStart = 24 where codutilaj2c = v_rec.codutilaj2c;
        update tmp_utilaje2c set OreStart = 24 where codutilaj2c = v_rec.codutilaj2c;
        vOreStart := 24;
        vOrePeZi := 24;
      else
        if vDurata/60 &lt; vOreSchimb * vNrSchimburi then
          update utilaje2c set OreStart = vDurata/60 where codutilaj2c = v_rec.codutilaj2c;
          update tmp_utilaje2c set OreStart = vDurata/60 where codutilaj2c = v_rec.codutilaj2c;
          vOreStart := vDurata / 60;
        else
          update utilaje2c set OreStart = vOreSchimb * vNrSchimburi where codutilaj2c = v_rec.codutilaj2c;
          update tmp_utilaje2c set OreStart = vOreSchimb * vNrSchimburi where codutilaj2c = v_rec.codutilaj2c;
          vOreStart := vOreSchimb * vNrSchimburi;
        end if;
      end if;
    end if;
    vDataF   := vDataI + vZile;
    vOreStop := 0;
    if vZile &gt; 0 then
      vOreStop := vDurata / 60 - (vZile - 1) * vOrePeZi - vOreStart;
    end if;  
    update utilaje2c set OreStop = vOreStop where codutilaj2c = v_rec.codutilaj2c;  
    update tmp_utilaje2c set OreStop = vOreStop where codutilaj2c = v_rec.codutilaj2c;  
    if vZile &gt; 0 then
      vOreStop := vDurata / 60 - (vZile - 1) * vOrePeZi - vOreStart;
    else
      vOreStop := vDurata / 60;
    end if; 
    vDataF   := vDataF + vOreStop/24;
    update tmp_utilaje2c set DataEnd = vDataF where codutilaj2c = v_rec.codutilaj2c;  
  end loop;

  insert into tmp_utilaje2p (codutilaj2p, codutilaj2, codutilaj, codpers, angajat, marca)
  select u2p.codutilaj2p, u2p.codutilaj2, u2p.codutilaj, u2p.codpers, p.nume||&apos; &apos;||p.prenume, p.marca
  from utilaje2p u2p
       left join npers p on p.codpers = u2p.codpers
  where u2p.codutilaj = recid;

  INSERT INTO TMP_UTILAJE3(CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, TIP_INDEX, INDEXRESETAT)
  SELECT CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, COALESCE(TIP_INDEX,0), CASE WHEN NVL(CORECTIEINDEX, 0) &lt;&gt; 0 THEN 1 ELSE 0 END
  FROM UTILAJE3 WHERE CODUTILAJ = RECID;

  -- aici trebe facut update la alerta in tmp_utilaje2c
  LastIndex := 0;
  DataLastIndex := null;
  for v_rec in (select * from tmp_utilaje3 where coalesce (tip_index,0) = 0 order by An, Luna, DataBord) loop
    LastIndex := v_rec.indexbord;
    DataLastIndex := v_Rec.Databord;
  end loop;

  for v_Rec in (select * from tmp_utilaje2c) loop
    vAlerta := 0;
    if ((LastIndex &gt; 0) and (LastIndex &gt;= nvl(v_Rec.IndexA,0)) and (LastIndex &lt; nvl(v_Rec.IndexV,0)) and (nvl(v_rec.CodIntr1,0) = 0))
       or
       ((DataLastIndex is not null) and (DataLastIndex &gt;= v_rec.DataA) and (DataLastIndex &lt; v_Rec.DataV)  and (nvl(v_rec.CodIntr1,0) = 0)) then
      vAlerta := 1;
    end if;
    if LastIndex &gt; 0 then
      if nvl(v_rec.IndexV,0) &gt; 0 then
        if LastIndex &gt;= nvl(v_rec.IndexV,0) then
          if (nvl(v_Rec.CodComanda1,0) &gt; 0) and (nvl(v_rec.CodIntr1,0) = 0) then vAlerta := 2;
          else if nvl(v_rec.CodComanda1,0) = 0 then vAlerta := 3; end if;
          end if;
        end if;
      end if;
    end if;
    if DataLastIndex is not null then
      if v_rec.DataV is not null then
        if DataLastIndex &gt;= v_rec.DataV then
          if (nvl(v_Rec.CodComanda1,0) &gt; 0) and (nvl(v_rec.CodIntr1,0) = 0) then if vAlerta = 0 then vAlerta := 2; end if;
          else if nvl(v_rec.CodComanda1,0) = 0 then if vAlerta = 0 then vAlerta := 3; end if; end if;
          end if;
        end if;
      end if;
    end if;
    update tmp_utilaje2c set alerta = vAlerta where codutilaj2c = v_rec.codutilaj2c;
  end loop;
  
  INSERT INTO TMP_UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
  SELECT CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf
  FROM UTILAJETIPINDEX WHERE CODUTILAJ = RECID;
  InitUtilajeTipIndex(RECID);
  -- nomUtilaje --&gt; 508
  PKG_CFGTABLES.EXT_GOTORECORD(508);
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  aDoc varchar2(200);
  aCod number(20);
  aOldCodIes1 number(20);
  aNewCodIes1 number(20);
  aTip number(10);
  aCodPart number(20);
  aOldCodPart number(20);
  aCount number(10);
BEGIN
  aOldCodIes1 := 0;
  aNewCodIes1 := 0;
  select Tip, coalesce(codpart,0) into aTip, aCodPart from tmp_utilaje;
  
  if not aTip in (1,4) then delete tmp_utilaje1; end if;
  -- nomUtilaje --&gt; 508
  PKG_CFGTABLES.EXT_POSTRECORDS_INIT (508); 
  IF OPERATION = 0 THEN -- UPDATE
    SELECT codutilaj INTO RECID FROM TMP_UTILAJE;
    begin
      select coalesce(codpart,0) into aOldCodPart from utilaje where codutilaj = recid;
    exception when others then aOldCodPart := 0;
    end;
    update tmp_utilaje20 set codutilaj = recid;
    
    select nvl(codies1,0) into aNewCodIes1 from tmp_utilaje;
    select nvl(codies1,0) into aOldCodIes1 from utilaje where codutilaj = recid;
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Utilaj &quot;&apos;||nrinventar||&apos;&quot;&apos; INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;UTILAJE&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    UPDATE UTILAJE U SET (
      CODOBIECT,
      NRINVENTAR,
      ETICHETA,
      TIPUTILAJ,
      FLOTA,
      MODEL,
      ANF,
      SERIEF,
      INCARCARE,
      DATAGARANTIE,
      DATAGARANTIEI,
      INGARANTIE,
      LUNGIME,
      LATIME,
      INALTIME, OBS, INACTIV, CORECTIEINDEX, UM, CodGest, PLAFONCANTF, CODPART, CODIES1, APROBAT,
      DATASTART, NRCONTR, DATACONTR, CODFURNIZOR, DOC, TIP,CODLOCALIT,ADRESA,HFACTOR,AGENT,CODPRODUCATOR,CODLOCATIE) =
       ( SELECT CODOBIECT,
                      NRINVENTAR,
                      ETICHETA,
                      TIPUTILAJ,
                      FLOTA,
                      MODEL,
                      ANF,
                      SERIEF,
                      INCARCARE,
                      DATAGARANTIE,
                      DATAGARANTIEI,
                      INGARANTIE,
                      LUNGIME,
                      LATIME,
                      INALTIME, OBS, INACTIV, CORECTIEINDEX, UM, CodGest, PLAFONCANTF, CODPART, CODIES1, APROBAT,
                      DATASTART, NRCONTR, DATACONTR, CODFURNIZOR, DOC, TIP,CODLOCALIT,ADRESA,HFACTOR,AGENT,CODPRODUCATOR,CODLOCATIE
            FROM TMP_UTILAJE)
    WHERE  U.CODUTILAJ = RECID;

    DELETE FROM UTILAJE1 U1
    WHERE U1.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJ1 FROM TMP_UTILAJE1 TMP WHERE TMP.CODUTILAJ1 = U1.CODUTILAJ1);

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE1 where codutilaj1 &gt; 0) LOOP
      UPDATE UTILAJE1 U1 SET
        U1.NRCONTR = V_REC.NRCONTR,
        U1.CARNETCONTR         = V_REC.CARNETCONTR,
        U1.STATUS_PART  = V_REC.STATUS_PART,
        U1.STATUS_DEPO  = V_REC.STATUS_DEPO,
        U1.CODPART      = V_REC.CODPART,
        U1.CODLOCATIE   = V_REC.CODLOCATIE,
        U1.DATA         = V_REC.DATA,
        U1.OBS          = V_REC.OBS,
        U1.STATUS_SERVICE = V_REC.STATUS_SERVICE,
        U1.INDEXLOCAL    = V_REC.INDEXLOCAL,
        U1.CODPERS      = V_REC.CODPERS,
        U1.ESTETIC      = V_REC.ESTETIC
      WHERE U1.CODUTILAJ1 = V_REC.CODUTILAJ1;
    END LOOP;

    INSERT INTO UTILAJE1(CODUTILAJ1,CODUTILAJ,NRCONTR,CARNETCONTR,STATUS_PART,STATUS_DEPO,CODPART,CODLOCATIE,DATA,OBS,STATUS_SERVICE,USERID,DATACREARE,INDEXLOCAL,CODPERS,ESTETIC)
    SELECT SEQ_UTILAJE1_CODUTILAJ1.NEXTVAL,RECID,NRCONTR,CARNETCONTR,STATUS_PART,STATUS_DEPO,CODPART,CODLOCATIE,DATA,OBS,STATUS_SERVICE,PKG_GLOBALS.GETUSERID,SYSDATE,INDEXLOCAL,CODPERS,ESTETIC FROM TMP_UTILAJE1 WHERE CODUTILAJ1 &lt; 0;

    FOR V_REC IN (SELECT CODUTILAJ20, STARE
                  FROM UTILAJE20 U20
                  WHERE U20.CODUTILAJ = RecID
                        AND NOT EXISTS (SELECT TMP.CODUTILAJ20 FROM TMP_UTILAJE20 TMP WHERE TMP.CODUTILAJ20 = U20.CODUTILAJ20)
                  ) LOOP
      DELETE UTILAJE20 WHERE CODUTILAJ20 = V_REC.CODUTILAJ20;
      INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, TIPMODIF)
      VALUES (SEQ_UTILAJEMON_CODMONITORIZARE.NEXTVAL, V_REC.CODUTILAJ20, PKG_GLOBALS.GETUSERID, SYSDATE, V_REC.STARE, &apos;STERGERE&apos;);            
    END LOOP;
                        
    DELETE FROM UTILAJEDEV DEV
    WHERE DEV.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJDEV FROM TMP_UTILAJEDEV TMP WHERE TMP.CODUTILAJDEV = DEV.CODUTILAJDEV);      
    DELETE FROM UTILAJE2C U2C
    WHERE U2C.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJ2C FROM TMP_UTILAJE2C TMP WHERE TMP.CODUTILAJ2C = U2C.CODUTILAJ2C);
    DELETE FROM UTILAJE2P U2P
    WHERE U2P.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJ2P FROM TMP_UTILAJE2P TMP WHERE TMP.CODUTILAJ2P = U2P.CODUTILAJ2P);
    DELETE FROM UTILAJE2 U2
    WHERE U2.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJ2 FROM TMP_UTILAJE2 TMP WHERE TMP.CODUTILAJ2 = U2.CODUTILAJ2);

    FOR V_REC IN (SELECT TMP.*, U20.STARE STAREVECHE 
                  FROM TMP_UTILAJE20 TMP
                       LEFT JOIN UTILAJE20 U20 ON U20.CODUTILAJ20 = TMP.CODUTILAJ20
                  ) LOOP
      if v_rec.codutilaj20 &gt; 0 then
        UPDATE UTILAJE20 SET
          NRDOC     = V_REC.NRDOC, 
          DATADOC   = V_REC.DATADOC, 
          DESCRIERE = V_REC.DESCRIERE, 
          STARE     = V_REC.STARE, 
          OPERATOR  = V_REC.OPERATOR, 
          OBS       = V_REC.OBS,
          CODIES    = V_REC.CODIES,
          CODLOCALIT = V_REC.CODLOCALIT,
          ADRESA     = V_REC.ADRESA,
          CODPERSC   = V_REC.CODPERSC,
          CALLCENTER = V_REC.CALLCENTER,
          CODBC      = V_REC.CODBC,
          PRIORITATE = V_REC.PRIORITATE
        where codutilaj20 = v_rec.codutilaj20;
        IF V_REC.STAREVECHE &lt;&gt; V_REC.STARE THEN
          INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREV, STAREN, TIPMODIF)
          VALUES (SEQ_UTILAJEMON_CODMONITORIZARE.NEXTVAL, V_REC.CODUTILAJ20, PKG_GLOBALS.GETUSERID, SYSDATE, V_REC.STAREVECHE, V_REC.STARE, &apos;MODIFICARE&apos;);
        END IF;
      else
        select SEQ_UTILAJE20_CODUTILAJ20.NEXTVAL into aCod from dual;
        update tmp_utilaje2 set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
        update tmp_utilajedev set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
        update tmp_utilaje20 set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
        INSERT INTO UTILAJE20 (CODUTILAJ20, CODUTILAJ, NRDOC, DATADOC, DESCRIERE, STARE, OPERATOR, OBS, CODIES, 
                               CODLOCALIT, ADRESA, CODPERSC, CALLCENTER, CODBC, PRIORITATE)
        values (aCod, RecId, V_REC.NRDOC, V_REC.DATADOC, V_REC.DESCRIERE, V_REC.STARE, V_REC.OPERATOR, V_REC.OBS, V_REC.CODIES, 
                V_REC.CODLOCALIT, V_REC.ADRESA, V_REC.CODPERSC, V_REC.CALLCENTER, V_REC.CODBC, V_REC.PRIORITATE);
        INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREN, TIPMODIF)
        VALUES (SEQ_UTILAJEMON_CODMONITORIZARE.NEXTVAL, aCod, PKG_GLOBALS.GETUSERID, SYSDATE, V_REC.STARE, &apos;ADAUGARE&apos;);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJEDEV) LOOP
      IF V_REC.CODUTILAJDEV &gt; 0 THEN
        UPDATE UTILAJEDEV SET
          CODUTILAJ20 = V_REC.CODUTILAJ20, 
          CODOBIECT   = V_REC.CODOBIECT, 
          CANT        = V_REC.CANT, 
          PRET        = V_REC.PRET, 
          CANTFACT    = V_REC.CANTFACT, 
          FACTURABIL  = V_REC.FACTURABIL, 
          CODIES1     = V_REC.CODIES1,
          CODUTILAJ2  = V_REC.CODUTILAJ2,
          TIPLIVRARE  = V_REC.TIPLIVRARE,
          TVA         = V_REC.TVA,
          CONSUMABIL  = V_REC.CONSUMABIL,
          CANTCONS    = V_REC.CANTCONS
        WHERE CODUTILAJDEV = V_REC.CODUTILAJDEV;
      ELSE
        INSERT INTO UTILAJEDEV(CODUTILAJDEV, CODUTILAJ, CODUTILAJ20, CODOBIECT, CANT, PRET, CANTFACT, FACTURABIL, CODIES1, CODUTILAJ2, TIPLIVRARE, TVA,
                               CONSUMABIL, CANTCONS)
        VALUES (SEQ_UTILAJEDEV_CODUTILAJDEV.NEXTVAL, RECID, V_REC.CODUTILAJ20, V_REC.CODOBIECT, V_REC.CANT, V_REC.PRET, V_REC.CANTFACT, 
                V_REC.FACTURABIL, V_REC.CODIES1, V_REC.CODUTILAJ2, V_REC.TIPLIVRARE, V_REC.TVA, V_REC.CONSUMABIL, V_REC.CANTCONS);
      END IF;
    END LOOP;
    
    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2) LOOP
      if v_rec.codutilaj2 &gt; 0 then
        UPDATE UTILAJE2 SET
          INTERVENTIE = v_rec.INTERVENTIE,
          CODCOMANDA1 = V_REC.CODCOMANDA1,
          CODUTILAJ20 = V_REC.CODUTILAJ20,
          CODAUTO     = V_REC.CODAUTO,
          KMPARCURSI  = V_REC.KMPARCURSI
        where codutilaj2 = v_rec.codutilaj2;
      else
        select SEQ_UTILAJE2_CODUTILAJ2.NEXTVAL into aCod from dual;
        update tmp_utilaje2c set codutilaj2 = aCod where codutilaj2 = v_rec.codutilaj2;
        update tmp_utilaje2p set codutilaj2 = aCod where codutilaj2 = v_rec.codutilaj2;
        INSERT INTO UTILAJE2 (CODUTILAJ2, CODUTILAJ,INTERVENTIE,CODCOMANDA1,CODUTILAJ20,CODAUTO,KMPARCURSI)
        values (aCod, RecId,v_rec.INTERVENTIE,V_REC.CODCOMANDA1,V_REC.CODUTILAJ20,V_REC.CODAUTO,v_rec.KMPARCURSI);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2C) LOOP
      if v_rec.codutilaj2C &gt; 0 then
        UPDATE UTILAJE2C SET
          INDEXC      = V_rEC.Indexc,
          DATAINDEXC  = V_REC.DATAINDEXC,
          CODCOMANDA1 = V_REC.CODCOMANDA1,
          Explicatii  = V_REC.Explicatii,
          DATASTART   = V_REC.DATASTART,
          DATAEND     = V_REC.DATAEND,
          INDEXV      = V_rEC.IndexV,
          DATAV       = V_REC.DATAV,
          RESETAT     = V_REC.RESETAT,
          INDEXLOCAL  = V_REC.INDEXLOCAL,
          ORESTART    = V_REC.ORESTART,
          ORESTOP     = V_REC.ORESTOP
        where codutilaj2C = v_rec.codutilaj2C;
      else
        INSERT INTO UTILAJE2C (CODUTILAJ2C, CODUTILAJ2, CODUTILAJ, INDEXC, DATAINDEXC, CODCOMANDA1, Explicatii, 
                               DataStart, DataEnd, indexv, datav,resetat, indexlocal,ORESTART,ORESTOP)
        values (SEQ_UTILAJE2C_CODUTILAJ2C.NEXTVAL, V_REC.CODUTILAJ2, RECID, V_rEC.INDEXC, V_REC.DATAINDEXC, V_REC.CODCOMANDA1, V_REC.Explicatii, v_rec.datastart, v_rec.dataend,
                v_rec.indexv, v_rec.datav, v_rec.resetat,v_rec.indexlocal,v_Rec.Orestart,v_rec.orestop);
      end if;
    END LOOP;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE2P) LOOP
      if v_rec.codutilaj2P &gt; 0 then
        UPDATE UTILAJE2P SET
          CODPERS = V_REC.CODPERS
        where codutilaj2P = v_rec.codutilaj2P;
      else
        INSERT INTO UTILAJE2P (CODUTILAJ2P, CODUTILAJ2, CODUTILAJ, CODPERS)
        values (SEQ_UTILAJE2P_CODUTILAJ2P.NEXTVAL, V_REC.CODUTILAJ2, RECID, V_REC.CODPERS);
      end if;
    END LOOP;

    DELETE FROM UTILAJE3 U3
    WHERE U3.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODUTILAJ3 FROM TMP_UTILAJE3 TMP WHERE TMP.CODUTILAJ3 = U3.CODUTILAJ3);

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE3) LOOP
      if v_rec.codutilaj3 &gt; 0 then
        UPDATE UTILAJE3 SET
          DATABORD        = v_rec.databord,
          INDEXBORD       = v_rec.indexbord,
          AN                     =  v_Rec.An,
          LUNA                 = v_rec.luna,
          CORECTIEINDEX = v_rec.CORECTIEINDEX,
          TIP_INDEX          =  v_rec.TIP_INDEX
        where codutilaj3 = v_rec.codutilaj3;
      else
        INSERT INTO UTILAJE3(CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA, CORECTIEINDEX, TIP_INDEX)
        values (SEQ_UTILAJE3_CODUTILAJ3.NEXTVAL,RecId,v_rec.DATABORD,v_rec.INDEXBORD,v_rec.AN,v_rec.LUNA, V_REC.CORECTIEINDEX, V_REC.TIP_INDEX);
      end if;
    END LOOP;
    
    DELETE FROM UTILAJETIPINDEX UTI
    WHERE UTI.CODUTILAJ = RecID
          AND NOT EXISTS (SELECT TMP.CODTINDEX FROM TMP_UTILAJETIPINDEX TMP WHERE TMP.CODTINDEX = UTI.CODTINDEX);

     FOR V_REC IN (SELECT * FROM TMP_UTILAJETIPINDEX) LOOP
      if v_rec.CODTINDEX &gt; 0 then
        UPDATE UTILAJETIPINDEX SET
          DENUMIRE          =  v_rec.DENUMIRE,
          UM                     =  v_rec.UM,
          PLAFONCANTF    =  v_rec.PLAFONCANTF
        where CODTINDEX = v_rec.CODTINDEX;
      else
      INSERT INTO UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
        values (SEQ_UTILAJETIPINDEX_CODTINDEX.NEXTVAL,RecId,v_rec.TIP_INDEX,v_rec.DENUMIRE, v_rec.UM, v_rec.PLAFONCANTF);
      end if;
    END LOOP;          

    
  ELSE -- INSERT
    aOldCodPart := 0;
    select nvl(codies1,0) into aOldCodIes1 from tmp_utilaje;
    SELECT seq_utilaje_codutilaj.nextval INTO RECID FROM DUAL;
    PKG_CFGTABLES.EXT_UPDATE_COD_CORESP(&apos;UTILAJE&apos;, RecId); 
    update tmp_utilaje20 set codutilaj = recid;
    INSERT INTO UTILAJE(
      CODUTILAJ,
      CODOBIECT,
      NRINVENTAR,
      ETICHETA,
      TIPUTILAJ,
      FLOTA,
      MODEL,
      ANF,
      SERIEF,
      INCARCARE,
      DATAGARANTIE,
      DATAGARANTIEI,
      INGARANTIE,
      LUNGIME,
      LATIME,
      INALTIME,
      OBS,
      INACTIV,
      CORECTIEINDEX, UM, CodGest, PLAFONCANTF, CODPART, CODIES1, APROBAT,
      DATASTART, NRCONTR, DATACONTR, CODFURNIZOR, DOC, TIP, CODLOCALIT, ADRESA,
      HFACTOR,AGENT,CODPRODUCATOR,CODLOCATIE)
    SELECT RecId,
      CODOBIECT,
      NRINVENTAR,
      ETICHETA,
      TIPUTILAJ,
      FLOTA,
      MODEL,
      ANF,
      SERIEF,
      INCARCARE,
      DATAGARANTIE,
      DATAGARANTIEI,
      INGARANTIE,
      LUNGIME,
      LATIME,
      INALTIME,
      OBS, 
      INACTIV,
      CORECTIEINDEX, UM, CodGest, PLAFONCANTF, CODPART, CODIES1, APROBAT,
      DATASTART, NRCONTR, DATACONTR, CODFURNIZOR, DOC, TIP, CODLOCALIT, ADRESA,
      HFACTOR,AGENT,CODPRODUCATOR,CODLOCATIE
    FROM TMP_UTILAJE;

    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) THEN
      SELECT &apos;Utilaj &quot;&apos;||nrinventar||&apos;&quot;&apos; INTO aDoc FROM UTILAJE WHERE codutilaj = recid;
      WINMADMIN.PKG_USERFIRME.PostLog(&apos;UTILAJE&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, pkg_globals.SUBUNITATE, null, aDoc, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;

    INSERT INTO UTILAJE1(CODUTILAJ1,CODUTILAJ,NRCONTR,CARNETCONTR,STATUS_PART,STATUS_DEPO,CODPART,CODLOCATIE,DATA,OBS,STATUS_SERVICE,USERID,DATACREARE,INDEXLOCAL,CODPERS,ESTETIC)
    SELECT SEQ_UTILAJE1_CODUTILAJ1.NEXTVAL,SEQ_UTILAJE_CODUTILAJ.CURRVAL,NRCONTR,CARNETCONTR,STATUS_PART,STATUS_DEPO,CODPART,CODLOCATIE,DATA,OBS,STATUS_SERVICE,PKG_GLOBALS.GETUSERID,SYSDATE,INDEXLOCAL,CODPERS,ESTETIC FROM TMP_UTILAJE1 ;

    FOR V_REC IN (SELECT * FROM TMP_UTILAJE20) LOOP
      select SEQ_UTILAJE20_CODUTILAJ20.NEXTVAL into aCod from dual;
      update tmp_utilaje2 set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
      update tmp_utilajedev set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
      update tmp_utilaje20 set codutilaj20 = aCod where codutilaj20 = v_rec.codutilaj20;
      INSERT INTO UTILAJE20 (CODUTILAJ20, CODUTILAJ, NRDOC, DATADOC, DESCRIERE, STARE, OPERATOR, OBS, CODIES, 
                             CODLOCALIT, ADRESA, CODPERSC, CODBC, PRIORITATE)
      values (aCod, RecId, V_REC.NRDOC, V_REC.DATADOC, V_REC.DESCRIERE, V_REC.STARE, V_REC.OPERATOR, V_REC.OBS, V_REC.CODIES, 
              V_REC.CODLOCALIT, V_REC.ADRESA, V_REC.CODPERSC, V_REC.CODBC, V_REC.PRIORITATE);
      INSERT INTO UTILAJEMON (CODMONITORIZARE, CODUTILAJ20, USERID, DATAMODIF, STAREN, TIPMODIF)
      VALUES (SEQ_UTILAJEMON_CODMONITORIZARE.NEXTVAL, aCod, PKG_GLOBALS.GETUSERID, SYSDATE, V_REC.STARE, &apos;ADAUGARE&apos;);
    END LOOP;

    INSERT INTO UTILAJEDEV(CODUTILAJDEV, CODUTILAJ, CODUTILAJ20, CODOBIECT, CANT, PRET, CANTFACT, FACTURABIL, CODIES1, CODUTILAJ2, TIPLIVRARE,TVA,
                           CONSUMABIL, CANTCONS)
    SELECT SEQ_UTILAJEDEV_CODUTILAJDEV.NEXTVAL, RECID, D.CODUTILAJ20, D.CODOBIECT, D.CANT, D.PRET, D.CANTFACT, D.FACTURABIL, D.CODIES1,
           D.CODUTILAJ2, D.TIPLIVRARE,D.TVA, D.CONSUMABIL, D.CANTCONS
    FROM TMP_UTILAJEDEV D;
  
    for v_rec in (select * from tmp_utilaje2) loop
      select SEQ_UTILAJE2_CODUTILAJ2.NEXTVAL into aCod from dual;
      update tmp_utilaje2c set codutilaj2 = aCod where codutilaj2 = v_rec.codutilaj2;
      update tmp_utilaje2P set codutilaj2 = aCod where codutilaj2 = v_rec.codutilaj2;
      INSERT INTO UTILAJE2 (CODUTILAJ2, CODUTILAJ,INTERVENTIE,CODCOMANDA1,CODUTILAJ20,CODAUTO,KMPARCURSI)
      values (aCod,SEQ_UTILAJE_CODUTILAJ.CURRVAL,v_rec.INTERVENTIE,v_rec.CODCOMANDA1,V_REC.CODUTILAJ20,V_REC.CODAUTO,V_REC.KMPARCURSI);
    end loop;

    INSERT INTO UTILAJE2C(CODUTILAJ2C, CODUTILAJ2, CODUTILAJ, INDEXC, DATAINDEXC, CODCOMANDA1, EXPLICATII, DATASTART, DATAEND, INDEXV, DATAV,RESETAT,INDEXLOCAL)
    SELECT SEQ_UTILAJE2C_CODUTILAJ2C.NEXTVAL, CODUTILAJ2, RECID, INDEXC, DATAINDEXC, CODCOMANDA1, EXPLICATII, DATASTART, DATAEND, INDEXV, DATAV,RESETAT,INDEXLOCAL
    FROM TMP_UTILAJE2C;

    INSERT INTO UTILAJE2P(CODUTILAJ2P, CODUTILAJ2, CODUTILAJ, CODPERS)
    SELECT SEQ_UTILAJE2P_CODUTILAJ2P.NEXTVAL, CODUTILAJ2, RECID, CODPERS FROM TMP_UTILAJE2P;

    INSERT INTO UTILAJE3(CODUTILAJ3,CODUTILAJ,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, TIP_INDEX)
    SELECT SEQ_UTILAJE3_CODUTILAJ3.NEXTVAL,SEQ_UTILAJE_CODUTILAJ.CURRVAL,DATABORD,INDEXBORD,AN,LUNA,CORECTIEINDEX, TIP_INDEX
    FROM TMP_UTILAJE3;
    
    INSERT INTO UTILAJETIPINDEX(CODTINDEX, codutilaj, tip_index, denumire, um, plafoncantf)
    SELECT SEQ_UTILAJETIPINDEX_CODTINDEX.NEXTVAL,SEQ_UTILAJE_CODUTILAJ.CURRVAL,TIP_INDEX,DENUMIRE, UM, PLAFONCANTF
    FROM TMP_UTILAJETIPINDEX;

    
  END IF;
  
  if aOldCodIes1 &lt;&gt; aNewCodIes1 then
    if aOldCodIes1 &gt; 0 then 
      update iesiri1 set codutilaj = null where codies1 = aOldCodIes1;
    end if;
    if aNewCodIes1 &gt; 0 then
      update iesiri1 set codutilaj = recid where codies1 = aNewCodIes1;
    end if;
  end if;
  
  INSERT INTO UTILAJE20_MON(CODUTILAJ20,CODUTILAJ,NRDOC,DATADOC,DESCRIERE,STARE,OPERATOR,OBS,CODIES,CODLOCALIT,ADRESA,DENOPERATOR,FACTURARE,DEVIZ,DATAMODIF)
  SELECT CODUTILAJ20,RECID,NRDOC,DATADOC,DESCRIERE,STARE,PKG_GLOBALS.GETUSERID,OBS,CODIES,CODLOCALIT,ADRESA,PKG_GLOBALS.GETUSERNAME,FACTURARE,DEVIZ,SYSDATE
  FROM TMP_UTILAJE20;
  
  if aOldCodPart &lt;&gt; aCodPart then
    update utilaje1 set status_part = 3 where codutilaj = recid and codpart = aOldCodPart;
    if aCodPart &gt; 0 then
      aCount := 0;
      select count(*) into aCount from utilaje1 where codutilaj = recid;
      aCount := aCount + 1;
      insert into UTILAJE1(CODUTILAJ1,
                           CODUTILAJ,
                           STATUS_PART,
                           STATUS_DEPO,
                           CODPART,
                           DATA,
                           USERID,
                           DATACREARE,
                           STATUS_SERVICE,
                           INDEXLOCAL,
                           ESTETIC,
                           CODLOCATIE)
      select seq_utilaje1_codutilaj1.nextval, 
             codutilaj,
             2,
             1,
             aCodPart,
             trunc(sysdate),
             pkg_globals.GETUSERID,
             sysdate,
             1,
             aCount,
             1,
             (SELECT AG.CODAGENDA FROM NAGENDA AG WHERE CODPART = ACODPART AND SEDIUSOCIAL BETWEEN 4 AND 7)
      from utilaje where codutilaj = recid;
    end if;  
  end if;
  -- nomUtilaje --&gt; 508
  PKG_CFGTABLES.EXT_POSTRECORDS(508);
  NotifyModif(Operation, RecId, &apos;UTILAJE&apos;);
  COMMIT;
END;

procedure ImportXLS is
oData timestamp;  
vdatag date;
vdatagi date;
vdatac date;
vdatapif date;
begin
  select sysdate into oData from dual;
  /*update utilaje_xls
  set
    datapif = replace(datapif, &apos;,&apos;,&apos;.&apos;),
    datai = replace(datai, &apos;,&apos;,&apos;.&apos;),
    dataf = replace(dataf, &apos;,&apos;,&apos;.&apos;);
  for uxls in (select
                  utilaj,model,codintern,serie,anf,client,localitate,adresa,doc,
                  agent,furnizor,codies1,codies,contract,datapif,datai,dataf,
                  ingarantie,obs, codclient, codfurnizor
                from utilaje_xls xls
                     where not exists (select i1.codies1 from utilaje i1 where to_number(nvl(xls.codies1,&apos;0&apos;)) = i1.codies1)
               ) loop
    begin 
      vdatapif := to_date(uxls.datapif,&apos;dd.mm.yyyy&apos;);
    exception when others then vdatag := null;
    end;  
             
    begin 
      vdatag := to_date(uxls.dataf,&apos;dd.mm.yyyy&apos;);
    exception when others then vdatag := null;
    end;
        
    begin 
      vdatagi := to_date(uxls.datai,&apos;dd.mm.yyyy&apos;);
    exception when others then vdatagi := null;
    end;
        
    begin 
      vdatac := to_date(substr(uxls.contract, instrb(uxls.contract, &apos;/&apos;, 1) + 1, length(uxls.contract) - instrb(uxls.contract, &apos;/&apos;, 1)), &apos;dd.mm.yyyy&apos;);
    exception when others then vdatac := null;
    end;
           
    insert into utilaje(
      CODUTILAJ,
      CODOBIECT,
      TIP,
      MODEL,
      ANF,
      SERIEF,
      DATAGARANTIE,
      INGARANTIE,
      OBS,
      INACTIV,
      CODPART,
      CODIES1,
      DATAGARANTIEI,
      APROBAT,
      DATASTART,
      NRCONTR,
      DATACONTR,
      CODFURNIZOR,
      DOC,
      CODLOCALIT,
      ADRESA,
      AGENT
    )
    values (
      seq_utilaje_codutilaj.nextval,
      (select codobiect from nartobj where codintern = uxls.codintern),
      2,
      uxls.model,
      case when not uxls.anf is null then to_number(uxls.anf) end,
      uxls.serie,
      vdatag,
      case when upper(uxls.ingarantie) = &apos;DA&apos; then 1 else 0 end,
      uxls.obs,
      0,
      to_number(NVL(uxls.codclient,&apos;0&apos;)),
      to_number(NVL(uxls.codies1,&apos;0&apos;)),
      vDatagi,
      1,
      vdatapif,
      case when not uxls.contract is null then substr(uxls.contract, 1, instrb(uxls.contract, &apos;/&apos;, 1) - 1) end,
      vdatac,
      to_number(NVL(uxls.codfurnizor,&apos;0&apos;)),
      uxls.doc,
      (select codlocalit from (select max(codlocalit) codlocalit, upper(den_localit) den_localit from nlocalit group by upper(den_localit)) loc where upper(loc.den_localit) = upper(uxls.localitate) ),
      --l.codlocalit,
      uxls.adresa,
      (select codpers from npers where upper(nume||&apos; &apos;||prenume) = upper(uxls.agent))
      );
--    from utilaje_xls uxls
--         inner join nartobj obj on obj.codintern = uxls.codintern
--         left join localitati l on upper(l.den_localit) = upper(uxls.localitate)
--         left join npers ag on upper(ag.nume||&apos; &apos;||ag.prenume) = upper(uxls.agent);
  end loop;
  
  --rollback;
  commit;*/
  
/*  
  create table UTILAJE_XLS
(
  utilaj     VARCHAR2(250),
  model      VARCHAR2(250),
  codintern  VARCHAR2(250),
  serie      VARCHAR2(250),
  anf        VARCHAR2(250),
  client     VARCHAR2(250),
  localitate VARCHAR2(250),
  adresa     VARCHAR2(250),
  doc        VARCHAR2(250),
  agent      VARCHAR2(250),
  furnizor   VARCHAR2(250),
  codies1    VARCHAR2(250),
  codies     VARCHAR2(250),
  contract   VARCHAR2(250),
  datapif    VARCHAR2(250),
  datai      VARCHAR2(250),
  dataf      VARCHAR2(250),
  ingarantie VARCHAR2(250),
  obs        VARCHAR2(250),
  codclient  VARCHAR2(250),
  codfurnizor VARCHAR2(250)
)
tablespace WMDATA
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
  */
  
end;

procedure Test is
vCodUtilaj number(20);
vCodUtilaj20 number(20);
vCodUtilaj2 number(20);
vCodUtilaj2C number(20);
vCodInterventie number(20);  
begin
  begin
    select CODINTERVENTIIAUTO into vCodInterventie from ninterventiiauto where denumire = &apos;MONTAJ&apos;;
  exception when others then vCodInterventie := 0;
  end;
  
  if vCodInterventie &gt; 0 then
    begin
      select u.codutilaj into vCodUtilaj
      from utilaje u
           inner join nartobj o on o.codobiect = u.codobiect
      where o.denumire = &apos;LINIE AMENAJARE VITRINE MYA&apos; AND U.SERIEF = &apos;182014,182015,182016&apos;;
    exception when others then vCodUtilaj := 0;
    end;
    if vCodUtilaj &gt; 0 then
      for v_cmd in (select distinct c1.codcomanda1
                    from comanda1 c1
                         inner join comanda c on c.codcomanda = c1.codcomanda
                         inner join raportp0 r0 on r0.codcomanda1 = c1.codcomanda1
                         inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                         inner join raportp r on r0.codraportp = r.codraportp
                    where c.nrdoc = 1264
                          and c.tipdoc = 53
                          and r.nrdoc = 1307
                   ) loop
        select seq_utilaje20_codutilaj20.nextval into vCodUtilaj20 from dual;
        select seq_utilaje2_codutilaj2.nextval into vCodUtilaj2 from dual;
        select seq_utilaje2c_codutilaj2c.nextval into vCodUtilaj2 from dual;
        insert into utilaje20(codutilaj20,codutilaj,datadoc,descriere,stare)
        values (vCodUtilaj20,vCodUtilaj,to_date(&apos;02.07.2018&apos;,&apos;dd.mm.yyyy&apos;),&apos;Deviz montaj&apos;,7);
        insert into utilaje2(codutilaj2,codutilaj,interventie,codutilaj20)
        values (vCodUtilaj2,vCodUtilaj,vCodInterventie,vCodUtilaj20);
        insert into utilaje2c(codutilaj2c,codutilaj2,codutilaj,codcomanda1,datastart,dataend)
        values(seq_utilaje2c_codutilaj2c.nextval,vcodutilaj2,vcodutilaj,v_cmd.codcomanda1,to_date(&apos;02.07.2018&apos;,&apos;dd.mm.yyyy&apos;),to_date(&apos;03.07.2018&apos;,&apos;dd.mm.yyyy&apos;));
        for v_rec in (select r1.angajat
                      from raportp0 r0 
                           inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                           inner join raportp r on r0.codraportp = r.codraportp
                      where r0.codcomanda1 = v_cmd.codcomanda1
                     ) loop
          insert into utilaje2p(codutilaj2p,codutilaj2,codutilaj,codpers)
          values(seq_utilaje2p_codutilaj2p.nextval,vCodUtilaj2,vCodUtilaj,v_rec.angajat);
        end loop;
      end loop;  
      commit;
    end if;
    
    begin
      select u.codutilaj into vCodUtilaj
      from utilaje u
           inner join nartobj o on o.codobiect = u.codobiect
      where o.denumire = &apos;MODERNIZARE SILOZURI CIMENT&apos; AND U.SERIEF = &apos;2017&apos;;
    exception when others then vCodUtilaj := 0;
    end;
    if vCodUtilaj &gt; 0 then
      for v_cmd in (select distinct c1.codcomanda1,
                           case
                             when c.nrdoc = 1390 then to_date(&apos;31.07.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1403 then to_date(&apos;29.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1404 then to_date(&apos;07.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1406,1407,1408,1409) then to_date(&apos;27.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1484,1483) then to_date(&apos;17.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1447 then to_date(&apos;04.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1777 then to_date(&apos;08.01.2019&apos;,&apos;dd.mm.yyyy&apos;)
                           end datastart,
                           case
                             when c.nrdoc = 1390 then to_date(&apos;29.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1403 then to_date(&apos;29.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1404 then to_date(&apos;07.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1406,1407,1408,1409) then to_date(&apos;27.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1484,1483) then to_date(&apos;17.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1447 then to_date(&apos;04.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1777 then to_date(&apos;08.01.2019&apos;,&apos;dd.mm.yyyy&apos;)
                           end dataend,
                           case
                             when c.nrdoc = 1390 then to_date(&apos;29.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1403 then to_date(&apos;29.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1404 then to_date(&apos;07.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1406 then to_date(&apos;27.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1407,1408,1409) then to_date(&apos;20.08.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc in (1484,1483) then to_date(&apos;17.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1447 then to_date(&apos;04.09.2018&apos;,&apos;dd.mm.yyyy&apos;)
                             when c.nrdoc = 1777 then to_date(&apos;08.01.2019&apos;,&apos;dd.mm.yyyy&apos;)
                           end datai
                    from comanda1 c1
                         inner join comanda c on c.codcomanda = c1.codcomanda
                         inner join raportp0 r0 on r0.codcomanda1 = c1.codcomanda1
                         inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                         inner join raportp r on r0.codraportp = r.codraportp
                    where c.nrdoc in (1390,1403,1404,1406,1407,1408,1409,1483,1484,1447,1777)
                          and r.nrdoc in (1434,1447,1448,1450,1451,1452,1453,1530,1529,1492,1823)
                          and c.tipdoc = 53
                   ) loop
        select seq_utilaje20_codutilaj20.nextval into vCodUtilaj20 from dual;
        select seq_utilaje2_codutilaj2.nextval into vCodUtilaj2 from dual;
        select seq_utilaje2c_codutilaj2c.nextval into vCodUtilaj2 from dual;
        insert into utilaje20(codutilaj20,codutilaj,datadoc,descriere,stare)
        values (vCodUtilaj20,vCodUtilaj,v_cmd.datai,&apos;Deviz montaj&apos;,7);
        insert into utilaje2(codutilaj2,codutilaj,interventie,codutilaj20)
        values (vCodUtilaj2,vCodUtilaj,vCodInterventie,vCodUtilaj20);
        insert into utilaje2c(codutilaj2c,codutilaj2,codutilaj,codcomanda1,datastart,dataend)
        values(seq_utilaje2c_codutilaj2c.nextval,vcodutilaj2,vcodutilaj,v_cmd.codcomanda1,v_cmd.datastart,v_cmd.dataend);
        for v_rec in (select r1.angajat
                      from raportp0 r0 
                           inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                           inner join raportp r on r0.codraportp = r.codraportp
                      where r0.codcomanda1 = v_cmd.codcomanda1
                     ) loop
          insert into utilaje2p(codutilaj2p,codutilaj2,codutilaj,codpers)
          values(seq_utilaje2p_codutilaj2p.nextval,vCodUtilaj2,vCodUtilaj,v_rec.angajat);
        end loop;
      end loop;  
      commit;
    end if;
    
    begin
      select u.codutilaj into vCodUtilaj
      from utilaje u
           inner join nartobj o on o.codobiect = u.codobiect
      where o.denumire = &apos;CUPTOR REVENT MODEL 725 O/G&apos;  AND U.SERIEF = &apos;19.2531.117&apos;;
    exception when others then vCodUtilaj := 0;
    end;
    if vCodUtilaj &gt; 0 then
      for v_cmd in (select distinct c1.codcomanda1
                    from comanda1 c1
                         inner join comanda c on c.codcomanda = c1.codcomanda
                         inner join raportp0 r0 on r0.codcomanda1 = c1.codcomanda1
                         inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                         inner join raportp r on r0.codraportp = r.codraportp
                    where c.nrdoc = 2090
                          and c.tipdoc = 53
                          and r.nrdoc = 2139
                   ) loop
        select seq_utilaje20_codutilaj20.nextval into vCodUtilaj20 from dual;
        select seq_utilaje2_codutilaj2.nextval into vCodUtilaj2 from dual;
        select seq_utilaje2c_codutilaj2c.nextval into vCodUtilaj2 from dual;
        insert into utilaje20(codutilaj20,codutilaj,datadoc,descriere,stare)
        values (vCodUtilaj20,vCodUtilaj,to_date(&apos;07.05.2019&apos;,&apos;dd.mm.yyyy&apos;),&apos;Deviz montaj&apos;,7);
        insert into utilaje2(codutilaj2,codutilaj,interventie,codutilaj20)
        values (vCodUtilaj2,vCodUtilaj,vCodInterventie,vCodUtilaj20);
        insert into utilaje2c(codutilaj2c,codutilaj2,codutilaj,codcomanda1,datastart,dataend)
        values(seq_utilaje2c_codutilaj2c.nextval,vcodutilaj2,vcodutilaj,v_cmd.codcomanda1,to_date(&apos;23.04.2019&apos;,&apos;dd.mm.yyyy&apos;),to_date(&apos;07.05.2019&apos;,&apos;dd.mm.yyyy&apos;));
        for v_rec in (select r1.angajat
                      from raportp0 r0 
                           inner join raportp1 r1 on r1.codraportp0 = r0.codraportp0 and r1.codraportp = r0.codraportp
                           inner join raportp r on r0.codraportp = r.codraportp
                      where r0.codcomanda1 = v_cmd.codcomanda1
                     ) loop
          insert into utilaje2p(codutilaj2p,codutilaj2,codutilaj,codpers)
          values(seq_utilaje2p_codutilaj2p.nextval,vCodUtilaj2,vCodUtilaj,v_rec.angajat);
        end loop;
      end loop;
      commit;
    end if;  
  end if;
end;  

end PKG_UTILAJE;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_VANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90A356DB4B1CC9E4A7A4C1ED0EBCA1C3EAED91F0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_VANZARI is


PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT codVanzare INTO Tmp FROM VANZARI WHERE CODVANZARE = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM VANZARI WHERE CODVANZARE = RecId ;
  NotifyModif(2, RecId, &apos;VANZARI&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_VANZARI FIELDS( CODVANZARE ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
-- Master 
  INSERT INTO TMP_VANZARI(CODVANZARE, 
                          CODPART, 
                          DATADOC, 
                          VALDOC, 
                          TVADOC, 
                          VALDISCOUNT, 
                          TVADISCOUNT, 
                          CODEMULARE, 
                          CODEMULAREFACT, 
                          INFOBON, 
                          INFOFACT, 
                          CODIES, 
                          OBS,
                          VALBON,                                  
                          TVABON,                                  
                          VALDISCBON,                              
                          TVADISCBON,                              
                          VALFACTURA,                              
                          TVAFACTURA,                              
                          VALDISCFACTURA,                          
                          TVADISCFACTURA )
    ( SELECT  
        CODVANZARE, 
        V.CODPART, 
        V.DATADOC, 
        V.VALDOC, 
        V.TVADOC, 
        V.VALDISCOUNT, 
        V.TVADISCOUNT, 
        V.CODEMULARE, 
        V.CODEMULAREFACT,
        &apos;Bon &apos; || TO_CHAR(E.NRBON) || &apos;/&apos; || TO_CHAR(E.DATABON, &apos;DD.MM.YYYY&apos;),
        &apos;Factura &apos; || I.SERIADOC || &apos; &apos; || TO_CHAR(I.NRDOC) || &apos;/&apos; || TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;),  
        I.CODIES,
        V.OBS,
        E.VALOARE,
        E.TVATOTAL,
        E.VALOAREDISCOUNT,
        E.TVADISCOUNT,  
        EFACT.VALOARE,
        EFACT.TVATOTAL,
        EFACT.VALOAREDISCOUNT,
        EFACT.TVADISCOUNT
      FROM 
        VANZARI V
        LEFT JOIN EMULARE E ON E.CODEMULARE = V.CODEMULARE
        LEFT JOIN EMULARE EFACT ON EFACT.CODEMULARE = V.CODEMULAREFACT
        LEFT JOIN IESIRI  I ON EFACT.CODIES = I.CODIES
      WHERE 
        CODVANZARE = RecId 
      ) ;

  UPDATE TMP_VANZARI
  SET
    VALDOC      = NVL(VALBON, 0) + NVL(VALFACTURA, 0),
    TVADOC      = NVL(TVABON, 0) + NVL(TVAFACTURA, 0),
    VALDISCOUNT = NVL(VALDISCBON, 0) + NVL(VALDISCFACTURA, 0),
    TVADISCOUNT = NVL(TVADISCBON, 0) + NVL(TVADISCFACTURA, 0);

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  vRecNo INTEGER := 0;
  vAn INTEGER := 0;
  vLuna INTEGER := 0;
  vCod NUMBER(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE

    SELECT  CODVANZARE INTO RecId FROM TMP_VANZARI;
    UPDATE VANZARI SET
    ( CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS) = 
    
    ( SELECT CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS 
      FROM 
        TMP_VANZARI
     ) 
      WHERE CODVANZARE = RecId ;

  ELSE  -- INSERT
  SELECT seq_VANZARI_codvanzare.NextVal INTO RecId FROM DUAL;
--  insert into t (select recid, den_localit from TMP_NLOCALIT);
  INSERT INTO  VANZARI (CODVANZARE, CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS)
 ( SELECT  RecId , CODPART, DATADOC, VALDOC, TVADOC, VALDISCOUNT, TVADISCOUNT, CODEMULARE, CODEMULAREFACT, OBS 
     FROM TMP_VANZARI  ) ;
  END IF;
  NotifyModif(Operation, RecId, &apos;VANZARI&apos;);
  COMMIT;
END;

end PKG_VANZARI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_VENITAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D7D4272517B344AD16F9F263B212FC3C11E0F91</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_VENITAVANS_INI is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS 
Tmp NUMBER(20);
BEGIN
  BEGIN
    SELECT CODIES1 INTO Tmp FROM MASTERCHELTAVANS WHERE CODIES1 = RecId FOR UPDATE NOWAIT;
    EXCEPTION WHEN OTHERS THEN TMP := 0;
  END;  
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
  NR NUMBER(10) := 0;
  aDoc varchar2(200);
BEGIN
  PKG_GLOBALS.MarkDirtyJurnal;  
  SP_LOCKRECORD(RecId);
  DELETE TMP_MANEVRA;
  
  FOR V_REC IN 
  (SELECT 
     CV.CODCHELTAVANS,   
     CV1.CODCHELTAVANS1   
   FROM 
     CHELTAVANS1 CV1, 
     CHELTAVANS CV 
   WHERE
    CV.CODIES1 = RECID
    AND CV.ISVENIT = 1
    AND CV.CODCHELTAVANS = CV1.CODCHELTAVANS
  )
  LOOP
    INSERT INTO TMP_MANEVRA(CODUNIC) VALUES (V_REC.CODCHELTAVANS);
    DELETE CHELTAVANS1 WHERE CODCHELTAVANS1 = V_REC.CODCHELTAVANS1; 
  END LOOP;
  
  FOR V_REC IN 
   (SELECT DISTINCT CODUNIC FROM TMP_MANEVRA )
  LOOP
    DELETE FROM CHELTAVANS  WHERE CODCHELTAVANS = V_REC.CODUNIC;
  END LOOP;  

  DELETE FROM MASTERCHELTAVANS WHERE CODIES1 = RECID;

 FOR V_RECIES IN 
 (SELECT I.CODIES, CODIES1 
  FROM 
    IESIRI  I, 
    IESIRI1 I1
  WHERE
   I1.CODIES1 = RECID  AND I.CODIES = I1.CODIES AND I.INITIALIZARI = 1)
  LOOP
    DELETE FROM IESIRI1 WHERE CODIES1 = V_RECIES.CODIES1;
    DELETE FROM IESIRI  WHERE CODIES  = V_RECIES.CODIES;
  END LOOP; 


  FOR V_REC IN 
 (SELECT * FROM JURNAL J WHERE EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 106 ) 
  LOOP
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  - V_REC.VALOARE,
      RULAJVCD = RULAJVCD - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTD AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;

    UPDATE NCONTRUL
    SET
      RULAJCC  = RULAJCC  - V_REC.VALOARE,
      RULAJVCC = RULAJVCC - V_REC.VALOAREV
    WHERE 
      CODCONT = V_REC.CONTC AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  END LOOP;
   
  DELETE FROM JURNAL J   WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 106 ;  
  DELETE FROM JURNAL1 J  WHERE  EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = J.CODDOC) AND TIPDOC = 106 ;  

  NotifyModif(2, RecId, &apos;MASTERCHELTAVANS&apos;);
  COMMIT;
END;



PROCEDURE SP_INSERTRECORD IS
BEGIN
  DELETE TMP_MIFIX_INITIAL;
  DELETE TMP_MASTERCHELTAVANS; 
  INSERT INTO  TMP_MASTERCHELTAVANS FIELDS(CODIES1 ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
  NR  NUMBER(7) := 0;
BEGIN 
  IF RECID &gt; 0 THEN 
      SELECT COUNT(*) INTO NR FROM MASTERCHELTAVANS WHERE NVL(CODIES1, 0) = RecId;
      
      IF RECID &gt; 0 AND NR = 0 THEN
        INSERT INTO MASTERCHELTAVANS (CODIES1) VALUES (RECID);
      END IF;  

      SELECT COUNT(*) INTO NR FROM CHELTAVANS WHERE CODIES1 = RECID;
      IF RECID &gt; 0 AND NR = 0 THEN
        INSERT INTO CHELTAVANS (CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, ISVENIT) VALUES (SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL, RECID, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU, 1);
      END IF;  

      INSERT INTO TMP_MASTERCHELTAVANS SELECT * FROM MASTERCHELTAVANS WHERE CODIES1 = RECID;  

      INSERT INTO TMP_CHELTAVANS
      (CODCHELTAVANS, 
       CODIES1, 
       ANINCEPUT, 
       LUNAINCEPUT, 
       CODIOART, 
       CODGEST, 
        DEN_GEST, 
       CODSUBUNIT, 
       NRDOC, 
       DEN_PART, 
       OBS,
       CODPART,
       DATADOC,
       CODOBIECT,
       CONTSERV, 
       CODINTR,--folosesc coloana asta pt manevra
       PREFIXDOC,
       SERIADOC,
       DATASTART,
       DATAEND,
       TIPINTERVAL,
       OBSERVATII
       )
       (SELECT 
          CAV.CODCHELTAVANS, 
          CAV.CODIES1, 
          CAV.ANINCEPUT, 
          CAV.LUNAINCEPUT, 
          CAV.CODIOART,
          G.CODGEST,
          G.DEN_GEST,
          I.SUBUNITATEA,
          I.NRDOC,
          P.DEN_PART,
          I1.OBS,
          I.PARTENER,
          I.DATADOC,
          I1.CODOBIECT,
          I1.CONTSERV,
          I.CODIES,
          I.PREFIXDOC,
          I.SERIADOC,
          CAV.DATASTART,
          CAV.DATAEND,
          0,
          CAV.OBSERVATII 
        FROM 
         CHELTAVANS CAV, 
         IESIRI I, 
         IESIRI1 I1
         LEFT OUTER JOIN NGEST G ON G.CODGEST = I1.GESTACT,
         NPART P
         WHERE 
          CAV.CODIES1 = RECID
          AND I1.CODIES1 = RECID
          AND I.CODIES = I1.CODIES
          AND P.CODPART = I.PARTENER);

      INSERT INTO TMP_CHELTAVANS1(CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD)
      SELECT 
       CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, ANSTART, LUNASTART, AMO, CODCENTRU, CODANALIZANOD
       FROM CHELTAVANS1 AV1 WHERE ANSTART = PKG_GLOBALS.ANLUCRU AND LUNASTART = PKG_GLOBALS.LUNALUCRU AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = AV1.CODCHELTAVANS);



      INSERT INTO TMP_JURNAL  (SELECT * FROM JURNAL  J WHERE TIPDOC = 106 AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC)  AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);
      INSERT INTO TMP_JURNAL1 (SELECT * FROM JURNAL1 J WHERE TIPDOC = 106 AND EXISTS (SELECT CODCHELTAVANS FROM TMP_CHELTAVANS WHERE CODCHELTAVANS = J.CODDOC) AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU);

      DELETE TMP_RULAJ;



      DELETE TMP_MIFIX_INITIAL;
      INSERT INTO TMP_MIFIX_INITIAL (CODMIFIX) SELECT CODCHELTAVANS FROM TMP_CHELTAVANS;


      UPDATE TMP_CHELTAVANS
      SET
        TIPINTERVAL = 1
      WHERE
        DATASTART IS NOT NULL
        AND 
        DATAEND IS NOT NULL;

  END IF;
  COMMIT;
END;



PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  ACODIES  NUMBER(20); 
  ACOD     NUMBER(20); 
  ANI      NUMBER(5) := 0;
  LUNAI    NUMBER(2) := 0;
  NR       NUMBER(5) := 0;
BEGIN
  IF OPERATION = 0 THEN  -- UPDATE
    SELECT CODIES1 INTO RECID FROM TMP_MASTERCHELTAVANS;  
    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS) LOOP
    
      UPDATE CHELTAVANS
      SET
        ANINCEPUT   = V_REC.ANINCEPUT,
        LUNAINCEPUT = V_REC.LUNAINCEPUT,
        CODIOART    = V_REC.CODIOART,
        DATASTART   = V_REC.DATASTART,
        DATAEND     = V_REC.DATAEND,
        OBSERVATII  = V_REC.OBSERVATII,
        ISVENIT     = 1
      WHERE
       CODCHELTAVANS = V_REC.CODCHELTAVANS;
    
      UPDATE IESIRI
      SET
        PARTENER    = V_REC.CODPART,
        SUBUNITATEA = V_REC.CODSUBUNIT,
        NRDOC       = V_REC.NRDOC,
        DATADOC     = V_REC.DATADOC,
        SERIADOC    = V_REC.SERIADOC
      WHERE
        CODIES = V_REC.CODINTR;-- in temporar folosesc coloana codintr
    
      UPDATE IESIRI1
      SET
        CODOBIECT = V_REC.CODOBIECT,
        GESTACT   = V_REC.CODGEST,
        CONTSERV  = V_REC.CONTSERV,
        CANT      = 1,
        OBS       = V_REC.OBS,
        PU        = (SELECT VALOARE FROM TMP_CHELTAVANS1)
      WHERE
        CODIES1 = V_REC.CODIES1;
    
    END LOOP;
  


    FOR V_REC IN (SELECT * FROM TMP_CHELTAVANS1) LOOP

      UPDATE CHELTAVANS1
        SET
         VALOARE   = V_REC.VALOARE, 
         DURATAN   = V_REC.DURATAN, 
         DURATAF   = V_REC.DURATAF, 
         DFBLOCAT  = V_REC.DFBLOCAT, 
         AMO       = V_REC.AMO, 
         ANSTART   = V_REC.ANSTART, 
         LUNASTART = V_REC.LUNASTART
        WHERE
         CODCHELTAVANS1 = V_REC.CODCHELTAVANS1;
        
       UPDATE CHELTAVANS1
       SET 
         VALOARE = V_REC.VALOARE
       WHERE
        CODCHELTAVANS = V_REC.CODCHELTAVANS
        AND ANSTART * 12 + LUNASTART &gt; V_REC.ANSTART * 12 + V_REC.LUNASTART ;
    END LOOP;
  ELSE --INSERT  
  
     PKG_GLOBALS.CALCULEAZA_LUNA_PRECEDENTA(PKG_GLOBALS.ANINITIAL, PKG_GLOBALS.LUNAINITIALA, ANI, LUNAI); 

     SELECT seq_IESIRI1_CODIES1.NextVal INTO RecId FROM DUAL;
     SELECT seq_IESIRI_CODIES.NextVal INTO aCODIES FROM DUAL;
     
     INSERT INTO MASTERCHELTAVANS (CODIES1) VALUES (RECID);
     INSERT INTO IESIRI(CODIES, TIPDOC, ANULAT, OPERAT, NRDOC, DATADOC, PARTENER, SUBUNITATEA, INITIALIZARI, AN, LUNA, SERIADOC, PREFIXDOC)
     (SELECT aCODIES, 19, 0, 1, NRDOC, DATADOC, CODPART, CODSUBUNIT, 1, ANI, LUNAI, SERIADOC, &apos;F&apos; FROM TMP_CHELTAVANS); 
  
     INSERT INTO IESIRI1(CODIES1, CODIES, TIPLINIE, CONTSERV, GESTACT, CODOBIECT, PU, CANT, OBS)
     (SELECT RECID, aCODIES, &apos;S&apos;, CONTSERV, CODGEST, CODOBIECT, (SELECT VALOARE FROM TMP_CHELTAVANS1), 1, OBS FROM TMP_CHELTAVANS); 
  

     SELECT SEQ_CHELTAVANS_CODCHELTAVANS.NEXTVAL INTO ACOD FROM DUAL;
     UPDATE TMP_CHELTAVANS1 SET CODCHELTAVANS = ACOD;
     UPDATE TMP_JURNAL  SET CODDOC = aCOD, INDEXLOCAL = aCOD;
     UPDATE TMP_JURNAL1 SET CODDOC = aCOD, INDEXLOCAL = aCOD, IContBazaD = aCOD, IContBazaC = aCOD;
     
     
     INSERT INTO CHELTAVANS (CODCHELTAVANS, CODIES1, ANINCEPUT, LUNAINCEPUT, CODIOART, DATASTART, DATAEND, OBSERVATII, ISVENIT)
     (SELECT ACOD, RECID, ANINCEPUT, LUNAINCEPUT,  CODIOART, DATASTART, DATAEND, OBSERVATII, 1 FROM TMP_CHELTAVANS);

     INSERT INTO CHELTAVANS1 (CODCHELTAVANS1, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART)
     (SELECT SEQ_CHELTAVANS1_CODCHELTAVANS1.NEXTVAL, CODCHELTAVANS, VALOARE, DURATAN, DURATAF, DFBLOCAT, AMO, ANSTART, LUNASTART FROM TMP_CHELTAVANS1 );
  END IF;


 -- detail JURNAlL1
  DELETE FROM JURNAl1 J1
  WHERE 
    TIPDOC = 106 
    AND AN = PKG_GLOBALS.ANLUCRU 
    AND LUNA = PKG_GLOBALS.LUNALUCRU 
    AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J1.CODDOC) AND NOT EXISTS
  ( SELECT CODJURNAL1 FROM TMP_JURNAl1 WHERE CODJURNAL1 = J1.CODJURNAL1);
  
  FOR V_REC IN (SELECT * FROM TMP_JURNAL1) LOOP
   IF V_REC.CODJURNAL1 &gt; 0 THEN
    UPDATE JURNAL1
    SET 
      CODDOC       = V_REC.CODDOC,       
      TIPDOC       = V_REC.TIPDOC,
      INDEXLOCAL   = V_REC.INDEXLOCAL,
  
      CODBAZAD     = V_REC.CODBAZAD,
      ICONTBAZAD   = V_REC.ICONTBAZAD,
      TIPBAZAD     = V_REC.TIPBAZAD,
      CODBAZAC     = V_REC.CODBAZAC,
      ICONTBAZAC   = V_REC.ICONTBAZAC,
      TIPBAZAC     = V_REC.TIPBAZAC,
  
      CODDESCRD     = V_REC.CODDESCRD,
      ICONTD        = V_REC.ICONTD,
      TIPCONTD      = V_REC.TIPCONTD,
      ANALITICCONTD = V_REC.ANALITICCONTD,
      CODDESCRC     = V_REC.CODDESCRC,
      ICONTC        = V_REC.ICONTC,
      TIPCONTC      = V_REC.TIPCONTC,
      ANALITICCONTC = V_REC.ANALITICCONTC,
      GEST          = V_REC.GEST,
      VALOARE       = V_REC.VALOARE,
      VALOAREV      = V_REC.VALOAREV,
      OBS           = V_REC.OBS,
      AN            = V_REC.AN,
      LUNA          = V_REC.LUNA,
      SUBUNITATEA   = V_REC.SUBUNITATEA, 
      DATADOC       = V_REC.DATADOC,
      DOCUMENT      = V_REC.DOCUMENT
    WHERE 
      CODJURNAL1 = V_REC.CODJURNAl1; 
   ELSE
     INSERT INTO JURNAL1 (CODJURNAL1, CODDOC, TIPDOC, INDEXLOCAL, CODBAZAD, ICONTBAZAD, TIPBAZAD, CODDESCRD, ICONTD, TIPCONTD,  ANALITICCONTD,   CODBAZAC,  ICONTBAZAC,  TIPBAZAC, CODDESCRC, ICONTC, TIPCONTC, ANALITICCONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, DIRTY, SUBUNITATEA, DATADOC, DOCUMENT ) 
     VALUES 
     (SEQ_JURNAL1_CODJURNAL1.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL,  V_REC.CODBAZAD,  V_REC.ICONTBAZAD,  V_REC.TIPBAZAD, V_REC.CODDESCRD, V_REC.ICONTD, V_REC.TIPCONTD, V_REC.ANALITICCONTD,  V_REC.CODBAZAC,  V_REC.ICONTBAZAC,  V_REC.TIPBAZAC, V_REC.CODDESCRC, V_REC.ICONTC, V_REC.TIPCONTC, V_REC.ANALITICCONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.DIRTY, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
   END IF; 
  END LOOP;
  
  DELETE  
  FROM 
    JURNAL J 
  WHERE 
    TIPDOC = 106 
    AND AN = PKG_GLOBALS.ANLUCRU 
    AND LUNA = PKG_GLOBALS.LUNALUCRU 
    AND EXISTS (SELECT CODMIFIX FROM TMP_MIFIX_INITIAL WHERE CODMIFIX = J.CODDOC) AND NOT EXISTS 
   (SELECT CODJURNAL FROM TMP_JURNAL WHERE CODJURNAL = J.CODJURNAL);
  
  FOR V_REC IN (SELECT * FROM TMP_JURNAL) LOOP
    IF V_REC.CODJURNAL &gt; 0 THEN
      UPDATE JURNAL
      SET  
        CODDOC     = V_REC.CODDOC,
        TIPDOC     = V_REC.TIPDOC, 
        INDEXLOCAL = V_REC.INDEXLOCAL, 
        CONTD      = V_REC.CONTD, 
        CONTC      = V_REC.CONTC,
        GEST       = V_REC.GEST,
        VALOARE    = V_REC.VALOARE, 
        VALOAREV   = V_REC.VALOAREV, 
        OBS        = V_REC.OBS, 
        AN         = V_REC.AN, 
        LUNA       = V_REC.LUNA,
        SUBUNITATEA= V_REC.SUBUNITATEA,
        DATADOC    = V_REC.DATADOC,
        DOCUMENT   = V_REC.DOCUMENT
      WHERE 
       CODJURNAL = V_REC.CODJURNAl; 
    ELSE
     INSERT INTO JURNAL(CODJURNAL, CODDOC, TIPDOC, INDEXLOCAL, CONTD, CONTC, GEST, VALOARE, VALOAREV, OBS, AN, LUNA, SUBUNITATEA, DATADOC, DOCUMENT)  
     VALUES
      (SEQ_JURNAL_CODJURNAL.NEXTVAL, V_REC.CODDOC, V_REC.TIPDOC, V_REC.INDEXLOCAL, V_REC.CONTD, V_REC.CONTC, V_REC.GEST, V_REC.VALOARE, V_REC.VALOAREV, V_REC.OBS, V_REC.AN, V_REC.LUNA, V_REC.SUBUNITATEA, V_REC.DATADOC, V_REC.DOCUMENT);
    END IF; 
  END LOOP;

-- ACTUALIZARE RULAJE CONTURI
  FOR V_REC IN (SELECT * FROM TMP_RULAJ) LOOP
  
    SELECT COUNT(*) INTO NR FROM NCONTRUL WHERE CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
    IF NR = 0 THEN
      INSERT INTO NCONTRUL(CODCONTRUL, CODCONT, RULAJPD, RULAJPC, RULAJCD, RULAJCC, RULAJVPD, RULAJVPC, RULAJVCD, RULAJVCC, AN, LUNA)
      VALUES
      (SEQ_NCONTRUL_CODCONTRUL.NEXTVAL, V_REC.CODCONT,  0, 0, 0, 0, 0, 0, 0, 0, PKG_GLOBALS.ANLUCRU, PKG_GLOBALS.LUNALUCRU);
    END IF;
 
    UPDATE NCONTRUL
    SET
      RULAJCD  = RULAJCD  + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJCC  = RULAJCC  + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOARE  ELSE 0 END),
      RULAJVCD = RULAJVCD + (CASE WHEN V_REC.TIP = &apos;D&apos; THEN V_REC.VALOAREV ELSE 0 END),
      RULAJVCC = RULAJVCC + (CASE WHEN V_REC.TIP = &apos;C&apos; THEN V_REC.VALOAREV ELSE 0 END)
    WHERE 
     CODCONT = V_REC.CODCONT AND AN = PKG_GLOBALS.ANLUCRU AND LUNA = PKG_GLOBALS.LUNALUCRU;
  END LOOP;

  PKG_GLOBALS.MarkDirtyJurnal;
  NotifyModif(Operation, RecId, &apos;MASTERCHELTAVANS&apos;);  
  COMMIT;
END;  


end PKG_VENITAVANS_INI;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F25CBEAB792785998814F230E80DE49577EB0479</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_VOUCHER is

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodVoucher INTO Tmp FROM VOUCHER WHERE CodVoucher = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
 	DELETE FROM VOUCHER WHERE CodVoucher = RecId ;
	COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_VOUCHER FIELDS( CodVoucher ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_VOUCHER 
	(   CODVOUCHER  ,   
			CODPARTENER ,
			OBS         ,
			DATASTART   ,
			DATASTOP    ,
			MONEDA, CodGest      ,
			VALOARE     ,
      CodCmd, CodIes, Rest,
      Obs1
		)
	SELECT 
      V.CODVOUCHER,
      V.CODPARTENER,
      V.OBS,
      V.DATASTART,
      V.DATASTOP,
      V.MONEDA, V.CodGest,
      V.VALOARE,
      V.CodCmd, V.CodIes, V.Valoare - Nvl((Select Sum(Nvl(Valoare,0)) from VOUCHERLINK where CodVoucher = RecID),0),
      V.Obs1
  FROM VOUCHER V
  LEFT  JOIN Comanda C on Abs(C.CodComanda) = NVL(V.CODCMD,0)  
  LEFT  JOIN RAC_REZ R on C.CodComanda = R.CodComanda  
  LEFT  JOIN NGEST   G on G.CodGest = NVL(R.CodGestSursa,0)  
  WHERE V.CodVoucher = RECID;

  INSERT INTO  TMP_VOUCHER1 
	(   Cod  ,   
      codDoc,
      TipDoc,
      Doc,
      Datadoc,
			VALOARE
		)
	SELECT 
      RowNum,
      Case when Nvl(C.CodComanda,0) &gt; 0 then C.CodComanda  
			     when Nvl(e.Codies,0) &gt; 0 then e.codies 
					 else 0 
			end, 
      Case when Nvl(C.CodComanda,0) &gt; 0 then C.TipDoc      
			     when Nvl(e.Codies,0) &gt; 0 then e.TipDoc 
					 else 0 
			end, 
      Case when Nvl(C.CodComanda,0) &gt; 0 then C.PrefixDoc||C.SeriaDoc||C.NrDoc     
			     when Nvl(e.Codies,0) &gt; 0 then e.PrefixDoc||e.SeriaDoc||e.NrDoc     
					 else &apos;?&apos;
			end, 
      Case when Nvl(C.CodComanda,0) &gt; 0 then C.DataDoc     
			     when Nvl(e.Codies,0) &gt; 0 then e.DataDoc 
					 else null 
			end, 
      L.VALOARE
  FROM 
	  VOUCHERLINK L 
	  left join Comanda1 C1 on C1.CodComanda1 = L.CodCmd
	  left join Comanda  C on  C.CodComanda = C1.CodComanda
	  left join Iesiri1 e1 on e1.Codies1 = L.CodIes
	  left join Iesiri  e  on e.Codies   = e1.CodIes
  WHERE CodVoucher = RECID;
  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
Cod number(20);
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT CodVOUCHER INTO RECID FROM TMP_VOUCHER;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE VOUCHER
    SET
     (
      CODVOUCHER,
      CODPARTENER,
      OBS,
      DATASTART,
      DATASTOP,
      MONEDA, CodGest,
      VALOARE,
      CodCmd, CodIes,
      OBS1 
     )
			= 
     (SELECT 
      CODVOUCHER,
      CODPARTENER,
      OBS,
      DATASTART,
      DATASTOP,
      nvl(MONEDA,0), CodGest,
      VALOARE,
      CodCmd, CodIes,
      OBS1
     FROM TMP_VOUCHER)
     WHERE CodVoucher = RECID;
  
 

ELSE  -- INSERT
    SELECT SEQ_VOUCHER_CODVOUCHER.NextVal INTO RecId FROM DUAL;
    INSERT INTO VOUCHER(
           CODVOUCHER,  
           CODPARTENER,  
           OBS   ,  
           DATASTART    ,      
           DATASTOP     ,
           MONEDA, CodGest,
           VALOARE,
           CodCmd, CodIes,
           OBS1 ) 	
    SELECT 
  		RECID   , 
      CODPARTENER,  
      OBS   ,  
      DATASTART    ,
      DATASTOP     ,
      nvl(MONEDA,0), CodGest,
      VALOARE,
      CodCmd, CodIes,
      OBS1 
		FROM TMP_VOUCHER; 
  END IF;
 NotifyModif(Operation, RecId, &apos;VOUCHER&apos;);
COMMIT;
 
END; 


end PKG_VOUCHER; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_VOUCHERCADOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DC211D9495B88437FEC1C25BD5FA953D79D0EE0</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_VOUCHERCADOU is

PROCEDURE SOLVEVOUCHERCADOU(TIPOPERATIE IN NUMBER) -- 1=activare; 2=stingere )
IS
  NR NUMBER;
BEGIN
  IF TIPOPERATIE = 4 THEN  
    FOR V_REC IN 
     (SELECT V.BARCODE 
      FROM 
        TMP_VOUCHERCADOU T 
        INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
     )
     LOOP
       UPDATE VOUCHERCADOU
       SET
         IS_USED = NULL,
         USED_DATE = NULL  
       WHERE
         BARCODE = V_REC.BARCODE;  
     END LOOP;               

  ELSE 

  IF TIPOPERATIE = 3 THEN  
    FOR V_REC IN 
     (SELECT V.COD 
      FROM 
        TMP_VOUCHERCADOU T 
        INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
     )
     LOOP
       DELETE FROM VOUCHERCADOU WHERE  COD = V_REC.COD;  
     END LOOP;               
   
  ELSE 
  IF TIPOPERATIE = 1 THEN
    FOR V_REC IN 
     (SELECT  T.BARCODE, T.VALOARE, T.DATASTART, T.DATASTOP 
      FROM 
        TMP_VOUCHERCADOU T 
     )
     LOOP
       SELECT COUNT(*) INTO NR FROM VOUCHERCADOU WHERE BARCODE = V_REC.BARCODE;

       IF NR = 0 THEN 
         INSERT INTO VOUCHERCADOU(COD, BARCODE, VALOARE, DATASTART, DATASTOP)
         VALUES (SEQ_VOUCHERCADOU_COD.NEXTVAL, V_REC.BARCODE, V_REC.VALOARE, V_REC.DATASTART, V_REC.DATASTOP);
       ELSE
         UPDATE VOUCHERCADOU
         SET
           VALOARE    = V_REC.VALOARE,
           DATASTART  = V_REC.DATASTART, 
           DATASTOP   = V_REC.DATASTOP,
           IS_USED    = NULL,
           USED_DATE  = NULL
         WHERE
           BARCODE = V_REC.BARCODE
           AND COALESCE(IS_USED, 0) = 0;  
       END IF;    
        
     END LOOP;               
  ELSE
    FOR V_REC IN 
     (SELECT V.COD 
      FROM 
        TMP_VOUCHERCADOU T 
        INNER JOIN VOUCHERCADOU V ON V.BARCODE = T.BARCODE
     )
     LOOP
       UPDATE VOUCHERCADOU
       SET
         IS_USED   = 1,
         USED_DATE = SYSDATE
       WHERE
         COD = V_REC.COD;  
     END LOOP;               
  END IF; 
  END IF;   
  END IF;           
--COMMIT; 
END;    



PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT COD INTO Tmp FROM VOUCHERCADOU WHERE COD = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM VOUCHERCADOU WHERE COD = RecId ;
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_VOUCHERCADOU FIELDS( COD ) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO  TMP_VOUCHERCADOU SELECT * FROM VOUCHERCADOU WHERE COD = RECID;
  COMMIT;
END;


PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
BEGIN
  IF Operation = 0 THEN  -- UPDATE
    BEGIN
      SELECT COD INTO RECID FROM TMP_VOUCHERCADOU;
      EXCEPTION WHEN OTHERS THEN RECID := 0;
    END;
    UPDATE VOUCHERCADOU
    SET
     ( 
       BARCODE,  
       VALOARE,  
       DATASTART,
       DATASTOP, 
       IS_USED,  
       USED_DATE
     ) = 
     (SELECT 
        BARCODE,  
        VALOARE,  
        DATASTART,
        DATASTOP, 
        IS_USED,  
        USED_DATE
      FROM 
        TMP_VOUCHERCADOU
     )
    WHERE
      COD = RECID;
  ELSE  -- INSERT
    SELECT SEQ_VOUCHERCADOU_COD.NextVal INTO RecId FROM DUAL;
    INSERT INTO VOUCHERCADOU(COD, BARCODE, VALOARE, DATASTART, DATASTOP, IS_USED, USED_DATE)
    SELECT RECID, BARCODE, VALOARE, DATASTART, DATASTOP, IS_USED, USED_DATE FROM TMP_VOUCHERCADOU;
  END IF; 

  NotifyModif(Operation, RecId, &apos;VOUCHERCADOU&apos;);
  COMMIT;
  
END;


end PKG_VOUCHERCADOU;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_WEEKCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>441FC3331061448D362431ED42B279562FA6E82C</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_WEEKCASHFLOW is

CT_MONITOR CONSTANT VARCHAR2(50) := &apos;MON_65&apos;;

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CODCASHFLOW INTO Tmp FROM WEEKCASHFLOW WHERE CODCASHFLOW = RecId FOR UPDATE NOWAIT;
END;


PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);    
BEGIN
  SP_LOCKRECORD(RecId);
  
  SELECT DATADOC, SUBUNITATEA, NRDOC
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM WEEKCASHFLOW
  WHERE CODCASHFLOW = RecID;
  
  IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
  THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;CODCASHFLOW&apos;, PKG_GLOBALS.USERNAME, &apos;S&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
  END IF;
  
  FOR V_REC IN (SELECT * FROM WEEKCASHFLOW1 WHERE CODCASHFLOW = RecId )
  LOOP
    DELETE FROM WEEKCASHPLATI WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;
    DELETE FROM WEEKCASHFLOW1 WHERE CODCASHFLOW1 = V_REC.CODCASHFLOW1;
  END LOOP;    
  
  DELETE FROM WEEKCASHFLOW  WHERE CODCASHFLOW = RecId ;
  DELETE FROM WEEKCASHSOLD  WHERE CODCASHFLOW = RecId ;
  NotifyModif(2, RecId, &apos;WEEKCASHFLOW&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO  TMP_WEEKCASHFLOW FIELDS(CODCASHFLOW) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_WEEKCASHFLOW  SELECT * FROM WEEKCASHFLOW  WHERE CODCASHFLOW = RECID;
  INSERT INTO TMP_WEEKCASHFLOW1 SELECT * FROM WEEKCASHFLOW1 WHERE CODCASHFLOW = RECID;

  INSERT INTO TMP_WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, CODLIMCREDIT, SOLD, REST, PLATI, CODMONEDA, DEN_CONT) 
  SELECT  
    WS.CODSOLD, 
    WS.CODCASHFLOW, 
    WS.CODBANKCONT, 
    WS.CODLIMCREDIT,
    WS.SOLD, 
    WS.REST,
    WS.PLATI,
    BK.CODMONEDA,
    BK.DEN_CONT    
  FROM 
    WEEKCASHSOLD WS,
    NBANKCONT BK
  WHERE 
    CODCASHFLOW = RECID
    AND WS.CODBANKCONT = BK.CODBANKCONT;
    
  INSERT INTO TMP_WEEKCASHSOLD(CODSOLD, CODCASHFLOW, CODBANKCONT, CODLIMCREDIT, SOLD, REST, PLATI, CODMONEDA, DEN_CONT) 
  SELECT  
    WS.CODSOLD, 
    WS.CODCASHFLOW, 
    WS.CODBANKCONT, 
    WS.CODLIMCREDIT,
    WS.SOLD, 
    WS.REST,
    WS.PLATI,
    L.MONEDA,
    &apos;Limita credit &apos; || &apos; &apos; || BK.DENUMIRE    
  FROM 
    WEEKCASHSOLD WS,
    NLIMCREDIT L,
    NBANK BK
  WHERE 
    CODCASHFLOW = RECID
    AND WS.CODLIMCREDIT = L.CODLIMCREDIT
    AND BK.CODBANK = L.CODBANCA;


  INSERT INTO TMP_WEEKCASHPLATI( CODCASHPLATI, 
                                 CODCASHFLOW1, 
                                 CODOBLIGPIF,
                                 DATAPLATA,
                                 SUMAPLATA,
                                 NRDOC,
                                 DATADOC,
                                 PREFIXDOC,
                                 TERMENOBLIG,
                                 RESTOBLIG,
                                 CODDOC,
                                 TIPDOC,
                                 OLDDATAPLATA,
                                 OLDSUMAPLATA,
                                 RESTOBLIGRAMAS,
                                 CODBANKCONT,
                                 DEN_CONT,
                                 OLDCODBANKCONT
                                ) 
    
  SELECT 
    CODCASHPLATI, 
    CODCASHFLOW1, 
    CODOBLIGPIF, 
    DATAPLATA, 
    SUMAPLATA, 
    NRDOC, 
    DATADOC, 
    PREFIXDOC, 
    TERMENOBLIG, 
    RESTOBLIG, 
    CODDOC, 
    TIPDOC, 
    DATAPLATA, 
    SUMAPLATA, 
    RESTOBLIG - SUMAPLATA, 
    P.CODBANKCONT,
    BK.DEN_CONT,
    P.CODBANKCONT 
    FROM 
      WEEKCASHPLATI P
      LEFT OUTER JOIN NBANKCONT BK ON BK.CODBANKCONT = P.CODBANKCONT
    WHERE EXISTS (SELECT CODCASHFLOW1 FROM TMP_WEEKCASHFLOW1 T WHERE T.CODCASHFLOW1 = P.CODCASHFLOW1);

   FOR V_REC IN (
     SELECT 
       CODCASHPLATI, 
       P.DEN_PART,
       O.CODPART,
       M.CODMONEDA,
       M.SIMBOL AS SIMBOLMONEDA,
       W1.SIMBOLCONT,
       G.TIPDOC,
       G.CODDOC
     FROM
       TMP_WEEKCASHPLATI T,
       OBLIGPIF O,
       NPART P,
       GENERAL G
       LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA,
       TMP_WEEKCASHFLOW1 W1
     WHERE
       T.CODOBLIGPIF = O.CODOBLIGPIF
       AND G.CODGENERAL = O.CODGENERAL
       AND P.CODPART = O.CODPART  
       AND W1.CODCASHFLOW1 = T.CODCASHFLOW1
       AND NVL(T.TIPDOC, 0) &lt;&gt; 8
     )
    LOOP
      UPDATE TMP_WEEKCASHPLATI
      SET
       CODPART      = V_REC.CODPART,
       DEN_PART     = V_REC.DEN_PART,
       CODMONEDA    = V_REC.CODMONEDA,
       SIMBOLMONEDA = V_REC.SIMBOLMONEDA,
       SIMBOLCONT   = V_REC.SIMBOLCONT
     WHERE
       CODCASHPLATI = V_REC.CODCASHPLATI;  
    END LOOP;   


   FOR V_REC IN (
     SELECT 
       CODCASHPLATI, 
       P.DEN_PART,
       P.CODPART,
       M.CODMONEDA,
       M.SIMBOL AS SIMBOLMONEDA,
       W1.SIMBOLCONT
     FROM
       TMP_WEEKCASHPLATI T,
       COMANDA C,
       NPART P,
       NMONEDE M,
       TMP_WEEKCASHFLOW1 W1
     WHERE
       NVL(T.TIPDOC, 0)    = 8
       AND T.CODDOC        = C.CODCOMANDA
       AND P.CODPART       = C.PARTENER 
       AND W1.CODCASHFLOW1 = T.CODCASHFLOW1
       AND M.CODMONEDA     = NVL(C.MONEDA, 0)
     )
    LOOP
      UPDATE TMP_WEEKCASHPLATI
      SET
       CODPART      = V_REC.CODPART,
       DEN_PART     = V_REC.DEN_PART,
       CODMONEDA    = V_REC.CODMONEDA,
       SIMBOLMONEDA = V_REC.SIMBOLMONEDA,
       SIMBOLCONT   = V_REC.SIMBOLCONT
     WHERE
       CODCASHPLATI = V_REC.CODCASHPLATI;  
    END LOOP;   



  DELETE TMP_WEEKCASHPLATI_INI;
  INSERT INTO TMP_WEEKCASHPLATI_INI SELECt CODCASHPLATI FROM TMP_WEEKCASHPLATI;
  COMMIT;
END;  

PROCEDURE SP_POSTRECORDS( Operation IN NUMBER, RecId OUT NUMBER )
IS
vCOD NUMBER(20);
aDATADOC    DATE;
aCodSubunit NUMBER(20);
aDoc        VARCHAR2(200);    
BEGIN
  SELECT DATADOC, SUBUNITATEA, NRDOC
  INTO ADATADOC, aCodSubunit, aDoc 
  FROM TMP_WEEKCASHFLOW;
  
  IF Operation = 0 THEN
    SELECT CODCASHFLOW INTO RECID FROM TMP_WEEKCASHFLOW;
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;WEEKCASHFLOW&apos;, PKG_GLOBALS.USERNAME, &apos;M&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
    
    UPDATE WEEKCASHFLOW
    SET
    (NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP) = (SELECT NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP FROM TMP_WEEKCASHFLOW)
    WHERE
      CODCASHFLOW = RECID;
    
    DELETE 
    FROM 
      WEEKCASHFLOW1 
    WHERE 
      CODCASHFLOW = RECID
      AND CODCASHFLOW1 NOT IN (SELECT CODCASHFLOW1 FROM TMP_WEEKCASHFLOW1);
    

     FOR V_REC IN (SELECT * FROM TMP_WEEKCASHFLOW1)
     LOOP
        IF V_REC.CODCASHFLOW1 &gt; 0 THEN
         UPDATE WEEKCASHFLOW1
         SET
           CODCASHFLOW    = RECID,
           INDEXTIPLINIE  = V_REC.INDEXTIPLINIE,
           INDEXLOCAL     = V_REC.INDEXLOCAL,
           INDEXSECUNDAR  = V_REC.INDEXSECUNDAR,
           TITLU          = V_REC.TITLU,
           DENUMIRE       = V_REC.DENUMIRE,
           SIMBOLCONT     = V_REC.SIMBOLCONT,
           VALOARE        = V_REC.VALOARE,
           RESTANTE       = V_REC.RESTANTE,
           VIZIBIL        = V_REC.VIZIBIL,
           AREDETALII     = V_REC.AREDETALII,
           EXPANDAT       = V_REC.EXPANDAT,
           ESTETOTAL      = V_REC.ESTETOTAL,
           EDITABIL       = V_REC.EDITABIL,
           OBS            = V_REC.OBS,
           DETALIU        = V_REC.DETALIU,
           CODPART        = V_REC.CODPART,
           HEADERFOOTER   = V_REC.HEADERFOOTER,
           WEEK1          = V_REC.WEEK1,
           WEEK2          = V_REC.WEEK2,
           WEEK3          = V_REC.WEEK3,
           WEEK4          = V_REC.WEEK4,
           WEEK5          = V_REC.WEEK5,
           WEEK6          = V_REC.WEEK6,
           WEEK7          = V_REC.WEEK7,
           WEEK8          = V_REC.WEEK8,
           WEEK9          = V_REC.WEEK9,
           WEEK10         = V_REC.WEEK10,
           WEEK11          = V_REC.WEEK11,
           WEEK12          = V_REC.WEEK12,
           WEEK13          = V_REC.WEEK13,
           WEEK14          = V_REC.WEEK14,
           WEEK15          = V_REC.WEEK15,
           WEEK16          = V_REC.WEEK16,
           WEEK17          = V_REC.WEEK17,
           WEEK18          = V_REC.WEEK18,
           WEEK19          = V_REC.WEEK19,
           WEEK20          = V_REC.WEEK20,
           WEEK21         = V_REC.WEEK21,
           WEEK22          = V_REC.WEEK22,
           WEEK23          = V_REC.WEEK23,
           WEEK24          = V_REC.WEEK24,
           WEEK25          = V_REC.WEEK25,
           WEEK26          = V_REC.WEEK26,
           WEEK27          = V_REC.WEEK27,
           WEEK28          = V_REC.WEEK28,
           WEEK29          = V_REC.WEEK29,
           WEEK30          = V_REC.WEEK30,
           WEEK31          = V_REC.WEEK31,
           WEEK32          = V_REC.WEEK32,
           WEEK33          = V_REC.WEEK33,
           WEEK34          = V_REC.WEEK34,
           WEEK35          = V_REC.WEEK35,
           WEEK36          = V_REC.WEEK36,
           WEEK37          = V_REC.WEEK37,
           WEEK38          = V_REC.WEEK38,
           WEEK39          = V_REC.WEEK39,
           WEEK40          = V_REC.WEEK40,
           WEEK41          = V_REC.WEEK41,
           WEEK42          = V_REC.WEEK42,
           WEEK43          = V_REC.WEEK43,
           WEEK44          = V_REC.WEEK44,
           WEEK45          = V_REC.WEEK45,
           WEEK46          = V_REC.WEEK46,
           WEEK47          = V_REC.WEEK47,
           WEEK48          = V_REC.WEEK48,
           WEEK49          = V_REC.WEEK49,
           WEEK50          = V_REC.WEEK50,
           WEEK51          = V_REC.WEEK51,
           WEEK52          = V_REC.WEEK52,
           PESTE52         = V_REC.PESTE52,
           CODDOC          = V_REC.CODDOC
         WHERE
           CODCASHFLOW1 = V_REC.CODCASHFLOW1;   
        ELSE
          VCOD := SEQ_WEEKCASHFLOW1_CODCASHFLOW1.NEXTVAL;
          UPDATE TMP_WEEKCASHPLATI 
          SET 
            CODCASHFLOW1 = VCOD
          WHERE
            CODCASHFLOW1 = V_REC.CODCASHFLOW1;
              
        INSERT INTO WEEKCASHFLOW1
          (CODCASHFLOW1, 
          CODCASHFLOW, 
          INDEXTIPLINIE, 
          INDEXLOCAL, 
          INDEXSECUNDAR, 
          TITLU, 
          DENUMIRE, 
          SIMBOLCONT, 
          VALOARE, 
          RESTANTE, 
          VIZIBIL, 
          AREDETALII, EXPANDAT, ESTETOTAL, EDITABIL, OBS, DETALIU, 
          CODPART, 
          HEADERFOOTER, WEEK1, WEEK2, WEEK3, WEEK4, WEEK5, WEEK6, WEEK7, WEEK8, WEEK9, WEEK10, WEEK11, WEEK12, WEEK13, WEEK14, WEEK15, WEEK16, WEEK17, WEEK18, WEEK19, WEEK20, WEEK21, WEEK22, WEEK23, WEEK24, WEEK25, WEEK26, WEEK27, WEEK28, WEEK29, WEEK30, WEEK31, WEEK32, WEEK33, WEEK34, WEEK35, WEEK36, WEEK37, WEEK38, WEEK39, WEEK40, WEEK41, WEEK42, WEEK43, WEEK44, WEEK45, WEEK46, WEEK47, WEEK48, WEEK49, WEEK50, WEEK51, WEEK52, PESTE52, CODDOC)
          VALUES (VCOD, RECID, V_REC.INDEXTIPLINIE, V_REC.INDEXLOCAL, V_REC.INDEXSECUNDAR, V_REC.TITLU, V_REC.DENUMIRE, V_REC.SIMBOLCONT, V_REC.VALOARE, V_REC.RESTANTE, 
          V_REC.VIZIBIL, V_REC.AREDETALII, V_REC.EXPANDAT, V_REC.ESTETOTAL, V_REC.EDITABIL, V_REC.OBS,  V_REC.DETALIU,
          V_REC.CODPART, V_REC.HEADERFOOTER, V_REC.WEEK1, V_REC.WEEK2, V_REC.WEEK3, V_REC.WEEK4, V_REC.WEEK5, V_REC.WEEK6, V_REC.WEEK7, V_REC.WEEK8, V_REC.WEEK9, V_REC.WEEK10, V_REC.WEEK11, V_REC.WEEK12, V_REC.WEEK13, V_REC.WEEK14, V_REC.WEEK15, V_REC.WEEK16, V_REC.WEEK17, V_REC.WEEK18, V_REC.WEEK19, V_REC.WEEK20, V_REC.WEEK21, V_REC.WEEK22, V_REC.WEEK23, V_REC.WEEK24, V_REC.WEEK25, V_REC.WEEK26, V_REC.WEEK27, V_REC.WEEK28, V_REC.WEEK29, V_REC.WEEK30, V_REC.WEEK31, V_REC.WEEK32, V_REC.WEEK33, V_REC.WEEK34, V_REC.WEEK35, V_REC.WEEK36, V_REC.WEEK37, V_REC.WEEK38, V_REC.WEEK39, V_REC.WEEK40, V_REC.WEEK41, V_REC.WEEK42, V_REC.WEEK43, V_REC.WEEK44, V_REC.WEEK45, V_REC.WEEK46, V_REC.WEEK47, V_REC.WEEK48, V_REC.WEEK49, V_REC.WEEK50, V_REC.WEEK51, V_REC.WEEK52, V_REC.PESTE52, V_REC.CODDOC);
        END IF;    
     END LOOP;  
     
     DELETE FROM WEEKCASHPLATI
     WHERE
      CODCASHPLATI IN (SELECT CODCASHPLATI FROM TMP_WEEKCASHPLATI_INI) 
      AND CODCASHPLATI NOT IN (SELECT CODCASHPLATI FROM TMP_WEEKCASHPLATI);
      
     FOR V_REC IN (SELECT * FROM TMP_WEEKCASHPLATI)
     LOOP
       IF V_REC.CODCASHPLATI &gt; 0 THEN
          UPDATE WEEKCASHPLATI
          SET
            CODCASHFLOW1 =  V_REC.CODCASHFLOW1,
            CODOBLIGPIF  =  V_REC.CODOBLIGPIF, 
            DATAPLATA    =  V_REC.DATAPLATA,   
            SUMAPLATA    =  V_REC.SUMAPLATA,   
            PREFIXDOC    =  V_REC.PREFIXDOC,   
            NRDOC        =  V_REC.NRDOC,       
            DATADOC      =  V_REC.DATADOC,
            RESTOBLIG    = V_REC.RESTOBLIG,
            CODDOC       = V_REC.CODDOC,
            TIPDOC       = V_REC.TIPDOC,
            TERMENOBLIG  = V_REC.TERMENOBLIG,
            CODBANKCONT  = V_REC.CODBANKCONT              
          WHERE  
            CODCASHPLATI = V_REC.CODCASHPLATI;
       ELSE
         INSERT INTO WEEKCASHPLATI(CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, CODDOC, TIPDOC, TERMENOBLIG, CODBANKCONT)     
         VALUES (SEQ_WEEKCASHPLATI_CODCASHPLATI.NEXTVAL, V_REC.CODCASHFLOW1, V_REC.CODOBLIGPIF, V_REC.DATAPLATA, V_REC.SUMAPLATA, V_REC.PREFIXDOC, V_REC.NRDOC, V_REC.DATADOC, V_REC.RESTOBLIG, V_REC.CODDOC, V_REC.TIPDOC, V_REC.TERMENOBLIG, V_REC.CODBANKCONT);    
       END IF;       
     END LOOP;   
     
     
    DELETE 
    FROM 
      WEEKCASHSOLD
    WHERE 
      CODCASHFLOW = RECID
      AND CODSOLD NOT IN (SELECT CODSOLD FROM TMP_WEEKCASHSOLD);
     
    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHSOLD) LOOP
      IF V_REC.CODSOLD &lt; 0 THEN
        INSERT INTO WEEKCASHSOLD (CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT)
        VALUES (SEQ_WEEKCASHSOLD_CODSOLD.NEXTVAL, RECID, V_REC.CODBANKCONT, V_REC.SOLD, V_REC.REST, V_REC.PLATI, V_REC.CODLIMCREDIT);
      ELSE
        UPDATE WEEKCASHSOLD
        SET
          CODBANKCONT  = V_REC.CODBANKCONT,
          CODLIMCREDIT = V_REC.CODLIMCREDIT,
          SOLD         = V_REC.SOLD,
          PLATI        = V_REC.PLATI,
          REST         = V_REC.REST
        WHERE
          CODSOLD = V_REC.CODSOLD;
      END IF;    
    END LOOP;         
  ELSE
    SELECT SEQ_WEEKCASHFLOW_CODCASHFLOW.Nextval INTO RecID From DUAL;
    
    IF WINMADMIN.PKG_USERFIRME.ValidPostLog(PKG_GLOBALS.USERID,CT_MONITOR) 
    THEN WINMADMIN.PKG_USERFIRME.PostLog(&apos;WEEKCASHFLOW&apos;, PKG_GLOBALS.USERNAME, &apos;A&apos;, RECID,PKG_GLOBALS.FIRMANAME, aCodSubunit, aDataDoc, aDoc, &apos;&apos;, PKG_GLOBALS.GET_EXE_VERSION);
    END IF;
     
    INSERT INTO WEEKCASHFLOW (CODCASHFLOW, NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP) SELECT RECID, NRDOC, DATADOC, SAPTAMANA, SUBUNITATEA, TIP FROM TMP_WEEKCASHFLOW;  

    FOR V_REC IN (SELECT * FROM TMP_WEEKCASHFLOW1)
    LOOP
      VCOD := SEQ_WEEKCASHFLOW1_CODCASHFLOW1.NEXTVAL;
      UPDATE TMP_WEEKCASHPLATI 
      SET
        CODCASHFLOW1 = VCOD
      WHERE
        CODCASHFLOW1 = V_REC.CODCASHFLOW1;
          
     INSERT INTO WEEKCASHFLOW1
     (CODCASHFLOW1, CODCASHFLOW, INDEXTIPLINIE, INDEXLOCAL, INDEXSECUNDAR, TITLU, DENUMIRE, SIMBOLCONT, VALOARE, RESTANTE, 
      VIZIBIL, 
      AREDETALII, EXPANDAT, ESTETOTAL, EDITABIL, OBS, DETALIU,
      CODPART, HEADERFOOTER, WEEK1, WEEK2, WEEK3, WEEK4, WEEK5, WEEK6, WEEK7, WEEK8, WEEK9, WEEK10, WEEK11, WEEK12, WEEK13, WEEK14, WEEK15, WEEK16, WEEK17, WEEK18, WEEK19, WEEK20, WEEK21, WEEK22, WEEK23, WEEK24, WEEK25, WEEK26, WEEK27, WEEK28, WEEK29, WEEK30, WEEK31, WEEK32, WEEK33, WEEK34, WEEK35, WEEK36, WEEK37, WEEK38, WEEK39, WEEK40, WEEK41, WEEK42, WEEK43, WEEK44, WEEK45, WEEK46, WEEK47, WEEK48, WEEK49, WEEK50, WEEK51, WEEK52, PESTE52, CODDOC
     )
   VALUES
    ( 
      VCOD, 
      RECID, 
      V_REC.INDEXTIPLINIE, 
      V_REC.INDEXLOCAL, 
      V_REC.INDEXSECUNDAR, 
      V_REC.TITLU, 
      V_REC.DENUMIRE, 
      V_REC.SIMBOLCONT, 
      V_REC.VALOARE, 
      V_REC.RESTANTE, 
      V_REC.VIZIBIL, 
      V_REC.AREDETALII, 
      V_REC.EXPANDAT, 
      V_REC.ESTETOTAL, 
      V_REC.EDITABIL, 
      V_REC.OBS,
      V_REC.DETALIU,
      V_REC.CODPART, 
      V_REC.HEADERFOOTER, 
      V_REC.WEEK1, 
      V_REC.WEEK2, 
      V_REC.WEEK3, 
      V_REC.WEEK4, 
      V_REC.WEEK5, 
      V_REC.WEEK6, 
      V_REC.WEEK7, 
      V_REC.WEEK8, 
      V_REC.WEEK9, 
      V_REC.WEEK10, 
      V_REC.WEEK11, 
      V_REC.WEEK12, 
      V_REC.WEEK13, 
      V_REC.WEEK14, 
      V_REC.WEEK15, 
      V_REC.WEEK16, 
      V_REC.WEEK17, 
      V_REC.WEEK18, 
      V_REC.WEEK19, 
      V_REC.WEEK20, 
      V_REC.WEEK21, 
      V_REC.WEEK22, 
      V_REC.WEEK23, 
      V_REC.WEEK24, 
      V_REC.WEEK25, 
      V_REC.WEEK26, 
      V_REC.WEEK27, 
      V_REC.WEEK28, 
      V_REC.WEEK29, 
      V_REC.WEEK30, 
      V_REC.WEEK31, 
      V_REC.WEEK32, 
      V_REC.WEEK33, 
      V_REC.WEEK34, 
      V_REC.WEEK35, 
      V_REC.WEEK36, 
      V_REC.WEEK37, 
      V_REC.WEEK38, 
      V_REC.WEEK39, 
      V_REC.WEEK40, 
      V_REC.WEEK41, 
      V_REC.WEEK42, 
      V_REC.WEEK43, 
      V_REC.WEEK44, 
      V_REC.WEEK45, 
      V_REC.WEEK46, 
      V_REC.WEEK47, 
      V_REC.WEEK48, 
      V_REC.WEEK49, 
      V_REC.WEEK50, 
      V_REC.WEEK51, 
      V_REC.WEEK52,
      V_REC.PESTE52,
      V_REC.CODDOC
     );
    
    END LOOP;    
    
    INSERT INTO WEEKCASHPLATI(CODCASHPLATI, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, TERMENOBLIG, CODBANKCONT )    
           SELECT SEQ_WEEKCASHPLATI_CODCASHPLATI.NEXTVAL, CODCASHFLOW1, CODOBLIGPIF, DATAPLATA, SUMAPLATA, PREFIXDOC, NRDOC, DATADOC, RESTOBLIG, TERMENOBLIG, CODBANKCONT FROM TMP_WEEKCASHPLATI;
  
  
    INSERT INTO WEEKCASHSOLD (CODSOLD, CODCASHFLOW, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT)
    SELECT SEQ_WEEKCASHSOLD_CODSOLD.NEXTVAL, RECID, CODBANKCONT, SOLD, REST, PLATI, CODLIMCREDIT FROM TMP_WEEKCASHSOLD;
  
  
  END IF;
  NotifyModif(Operation, RecId, &apos;WEEKCASHFLOW&apos;);  
  COMMIT;
END;    
end PKG_WEEKCASHFLOW;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_WMEONLINE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>122A3561BB259110706E33016355A190B5122F48</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY pkg_wmeonline IS

FUNCTION TOKENIZE_STRING(p_list IN VARCHAR2, token IN VARCHAR2)
RETURN WORD_ARRAY
AS
	l_string       VARCHAR2(32767) := p_list || token;
	l_comma_index  PLS_INTEGER;
	l_index        PLS_INTEGER := 1;
	l_tab          WORD_ARRAY := WORD_ARRAY();
BEGIN
	LOOP
		l_comma_index := INSTR(l_string, token, l_index);
		EXIT WHEN l_comma_index = 0;
		l_tab.EXTEND;
		l_tab(l_tab.COUNT) := SUBSTR(l_string, l_index, l_comma_index - l_index);
		l_index := l_comma_index + 1;
	END LOOP;
	RETURN l_tab;
END TOKENIZE_STRING;

PROCEDURE SetGestiuni (pUser IN NUMBER ,pFirma IN NUMBER, aCODPERS IN NUMBER)
IS
  TYPE t_rows IS TABLE OF TMP_MANEVRA%ROWTYPE INDEX BY PLS_INTEGER;
  NGESTCURSOR   NGEST_CURSOR;
  SUBCURSOR     NSUBUNIT_CURSOR;
  aCODGEST      NUMBER(20);
  NR            NUMBER(10);
BEGIN
  DELETE TMP_GESTDEDICATE;
  BEGIN
    SELECT NVL(CODGEST, 0) INTO aCODGEST FROM NPERS WHERE CODPERS = aCODPERS;
  EXCEPTION
    WHEN OTHERS THEN aCODGEST := 0;
  END;

  IF aCODGEST &lt;&gt; 0 THEN
    INSERT INTO TMP_GESTDEDICATE(CODGEST) VALUES (aCODGEST);
  ELSE
    SUBCURSOR := WINMADMIN.PKG_USERFIRME.getSubunitati(pUser, pFirma);
    NGESTCURSOR := WINMADMIN.PKG_USERFIRME.getGestiuni(pUSER, pFIRMA);
    SELECT COUNT(*) INTO NR FROM TMP_GESTDEDICATE;
    IF NR = 0 THEN
      INSERT INTO TMP_GESTDEDICATE  SELECT CODGEST FROM NGEST;
    END IF;
  END IF;
  COMMIT;
END;


FUNCTION getSubunitati (pUser IN NUMBER ,pFirma IN NUMBER) RETURN NSUBUNIT_CURSOR
IS
  TYPE t_rows IS TABLE OF TMP_MANEVRA%ROWTYPE INDEX BY PLS_INTEGER;
  s_rows        T_ROWS;
  NSUBCURSOR    NSUBUNIT_CURSOR;
  RESULT_CURSOR NSUBUNIT_CURSOR;
BEGIN
  DELETE TMP_MANEVRA;
  NSUBCURSOR := WINMADMIN.PKG_USERFIRME.getSubunitati(pUSER, pFIRMA);
  FETCH NSUBCURSOR BULK COLLECT INTO s_rows;
  FORALL i IN 1..s_rows.COUNT INSERT INTO TMP_MANEVRA VALUES s_rows(i);
  OPEN RESULT_CURSOR FOR SELECT S.CODSUBUNIT, S.DEN_SUBUNIT FROM TMP_MANEVRA T INNER JOIN NSUBUNIT S ON S.CODSUBUNIT = T.CODUNIC;
  RETURN RESULT_CURSOR;
END;

FUNCTION GET_INFOPERS_BY_LOGONNAME(aUSERNAME IN VARCHAR2) RETURN NPERS_CURSOR
IS
TMPCURSOR NPERS_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      P.CODPERS,
      NUME,
      PRENUME,
      NVL(P.CODSUBUNIT, 0) AS CODSUBUNIT,
      S.DEN_SUBUNIT
    FROM
      NPERS P
      LEFT OUTER JOIN NSUBUNIT S ON NVL(P.CODSUBUNIT, 0) = S.CODSUBUNIT
    WHERE
      upper(LOGONNAME) = upper(aUserName);

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODPERS FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION COUNT_CLIENTI(aDEN_PART IN VARCHAR2, aCODFISCAL IN VARCHAR2) RETURN NPART_CURSOR
IS
TMPCURSOR NPART_CURSOR;

BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT COUNT (*) AS CLIENTCOUNT FROM (
    SELECT
      DISTINCT
      P.CODPART,
      P.DEN_PART,
      NVL(M.CODMONEDA,0) AS CODMONEDA,
      M.SIMBOL AS SIMBOL_MONEDA,
      CF.COD_CODFISCAL,
      CF.CODFISCAL
    FROM
      NAGENDA A,
      NPART P
      LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(P.CODMONEDA, 0)
      LEFT OUTER JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND A.CODPART = P.CODPART
      AND UPPER(CF.CODFISCAL) LIKE &apos;%&apos;||UPPER(aCODFISCAL)||&apos;%&apos;
      AND UPPER(DEN_PART) LIKE &apos;%&apos;||UPPER(aDEN_PART)||&apos;%&apos;)
 ;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODPART FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;

FUNCTION GET_CLIENTI(aDEN_PART IN VARCHAR2, aCODFISCAL IN VARCHAR2) RETURN NPART_CURSOR
IS
TMPCURSOR NPART_CURSOR;

BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      DISTINCT
      P.CODPART,
      P.DEN_PART,
      NVL(M.CODMONEDA,0) AS CODMONEDA,
      M.SIMBOL AS SIMBOL_MONEDA,
      CF.COD_CODFISCAL,
      CF.CODFISCAL,
      P.CODEXTERN
    FROM
      NAGENDA A,
      NPART P
      LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(P.CODMONEDA, 0)
      LEFT OUTER JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND A.CODPART = P.CODPART
      AND UPPER(CF.CODFISCAL) LIKE &apos;%&apos;||UPPER(aCODFISCAL)||&apos;%&apos;
      AND UPPER(DEN_PART) LIKE &apos;%&apos;||UPPER(aDEN_PART)||&apos;%&apos;
      ORDER BY P.DEN_PART
 ;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODPART FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION GET_SEDII_CLIENT(aCODPART IN NUMBER) RETURN NAGENDA_CURSOR
IS
TMPCURSOR NAGENDA_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      A.CODAGENDA,
      A.OBS AS SEDIU,
      L.DEN_LOCALIT,
      getadresa(A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL) AS ADRESA
    FROM
      NAGENDA A,
      NLOCALIT L
    WHERE
      A.TIP = 0
      AND A.CODPART = aCODPART
      AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODAGENDA FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION GET_CLIENTI_AGENT(aCODPERS IN NUMBER) RETURN NPART_CURSOR
IS
TMPCURSOR NPART_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      DISTINCT
      P.CODPART,
      (SELECT TRANSLATE(P.DEN_PART, &apos;ÂâÎî&apos;, &apos;AaIi&apos;) FROM DUAL) AS DEN_PART,
      NVL(M.CODMONEDA,0) AS CODMONEDA,
      M.SIMBOL AS SIMBOL_MONEDA,
      CF.COD_CODFISCAL,
      CF.CODFISCAL,
      P.CODEXTERN
    FROM
      NAGENDA A,
      NPART P
      LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(P.CODMONEDA, 0)
      LEFT OUTER JOIN NPARTCODFISC CF ON CF.CODPART = P.CODPART AND CF.PRINCIPAL = 1
    WHERE
      A.TIP = 0
      AND NVL(A.CODAGENT, 0) = aCODPERS
      AND A.CODPART = P.CODPART
      ORDER BY DEN_PART
      ;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODPART FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION GET_SEDII_CLIENT_FOR_AGENT(aCODPART IN NUMBER,  aCODPERS IN NUMBER) RETURN NAGENDA_CURSOR
IS
TMPCURSOR NAGENDA_CURSOR;
BEGIN
  BEGIN
    OPEN TMPCURSOR FOR
    SELECT
      A.CODAGENDA,
      A.OBS AS SEDIU,
      L.DEN_LOCALIT,
      getadresa(A.SECTOR, A.STRADA, A.NR1, A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL) AS ADRESA
    FROM
      NAGENDA A,
      NLOCALIT L
    WHERE
      A.TIP = 0
      AND NVL(A.CODAGENT, 0) = aCODPERS
      AND A.CODPART = aCODPART
      AND L.CODLOCALIT = A.CODLOCALIT;

    EXCEPTION WHEN OTHERS THEN
    OPEN TMPCURSOR FOR  SELECT -1  AS CODAGENDA FROM DUAL;
  END;
  RETURN TMPCURSOR;
END;


FUNCTION getListaGestiuni RETURN NGEST_CURSOR
IS
  NGESTCURSOR    NGEST_CURSOR;
BEGIN
  OPEN NGESTCURSOR FOR
  SELECT
    G.CODGEST, (SELECT TRANSLATE(G.DEN_GEST, &apos;–&apos;, &apos;-&apos;) FROM DUAL) AS DEN_GEST, G.SIMBOL
  FROM
    TMP_GESTDEDICATE D,
    NGEST G
  WHERE
    G.CODGEST = D.CODGEST
    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
  ORDER BY DEN_GEST;
  RETURN NGESTCURSOR;
END;


FUNCTION GETSTOCURI( aCODPART   IN NUMBER,
                     aDenObiect IN VARCHAR2,
                     aDenClasa  IN VARCHAR2,
                     aCodGest   IN NUMBER,
                     aCODEXTERN IN VARCHAR2,
                     aCODINTERN IN VARCHAR2)
                   RETURN STOC_CURSOR IS
  STOCCURSOR STOC_CURSOR;

  FILTRU_ART   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CLASA VARCHAR2(1000) := &apos;&apos;;
  FILTRU_GEST  VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODEXTERN   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODINTERN   VARCHAR2(1000) := &apos;&apos;;
  S            VARCHAR2(4000);
  AN           NUMBER(5);
  LUNA         NUMBER(2);
  aCODCATPRET  NUMBER(20) := 0;

BEGIN
  AN   := EXTRACT(YEAR FROM SYSDATE);
  LUNA := EXTRACT(MONTH FROM SYSDATE);
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(AN, Luna);
  PKG_STOC_GENERARE_FACTURI.make_config_luna_EXT;
  BEGIN
    SELECT NVL(CODCATEGPRET, 0) INTO aCODCATPRET FROM NPART WHERE CODPART = aCODPART;
    EXCEPTION WHEN OTHERS THEN aCODCATPRET := 0;
  END;

  S := &apos; SELECT * FROM &apos; ||
       &apos; ( &apos; ||
       &apos;    SELECT &apos; ||
       &apos;      1 AS TIPARTICOL, &apos; ||
       &apos;      O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;      O.CODEXTERN, &apos; ||
       &apos;      O.CODINTERN,&apos; ||
	   &apos;      O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;      A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;      A.UM1 AS DUM1,&apos; || 
       &apos;      A.COMENZIONLINE,&apos; ||
       &apos;      U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;      NULL as DEN_GEST, &apos; ||
       &apos;      O.CODOBIECT, &apos; ||
       &apos;      0 as CODGEST, &apos; ||
       &apos;      CASE &apos; ||
       &apos;        WHEN CAT.TIP = 1 THEN ROUND(NVL(PM.LEI, 0) / (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos; ||
       &apos;        ELSE NVL(PM.LEI, 0) &apos; ||
       &apos;      END  AS PRET, &apos; ||
       &apos;      0 AS STOC, &apos; ||
       &apos;      P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;      CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;      U.DEN_UM, &apos; ||
       &apos;      U1.CODUM1 &apos; ||
       &apos;    FROM  &apos; ||
       &apos;      NART A   &apos; ||
	   &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA &apos; ||
       &apos;      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, &apos; ||
       &apos;      NARTOBJ O &apos; ||
       &apos;      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = &apos; || TO_CHAR(NVL(PKG_GLOBALS.GETSUBUNITATE, 0)) ||
       &apos;      AND CODCATPRET = &apos; || TO_CHAR(aCODCATPRET) ||
       &apos;      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
       &apos;    WHERE O.CODARTICOL = A.CODARTICOL AND A.TIPARTICOL = 1 AND NVL(A.COMENZIONLINE, 0) = 1 &apos; ||
       &apos; UNION ALL &apos; ||
       &apos; SELECT &apos; ||
       &apos;    0 AS TIPARTICOL, &apos; ||
       &apos;    O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;    O.CODEXTERN,&apos; ||
       &apos;    O.CODINTERN, &apos; ||
	   &apos;    O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;    A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;    A.UM1 AS DUM1,&apos; ||
       &apos;      A.COMENZIONLINE,&apos; ||
       &apos;    U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;    G.DEN_GEST, &apos; ||
       &apos;    STOCVIEW.CODOBIECT, &apos; ||
       &apos;    STOCVIEW.CODGEST,&apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN ROUND(NVL(PM.LEI, 0) / (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos; ||
       &apos;      ELSE NVL(PM.LEI, 0) &apos; ||
       &apos;    END  AS PRET, &apos; ||
       &apos;    STOCVIEW.STOC, &apos; ||
       &apos;    P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;    CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;    U.DEN_UM, &apos; ||
       &apos;    U1.CODUM1 &apos; ||
       &apos; FROM &apos; ||
       &apos;    ( &apos; ||  -- stoc cumulat
       &apos;     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC &apos; ||
       &apos;     FROM &apos; ||
       &apos;         ( &apos; ||
       &apos;           SELECT  CODOBIECT, CODGEST, STOC FROM &apos; ||
       &apos;                (  &apos; ||
       &apos;                   SELECT &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST AS CODGEST,&apos; ||
       &apos;                      SUM(NS.REST - NVL((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC &apos; ||
       &apos;                   FROM &apos; ||
       &apos;                      NIRSTOC NS  &apos; ||
       &apos;                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, &apos; ||
       &apos;                      NIR     N &apos; ||
       &apos;                   WHERE &apos; ||
       &apos;                      NS.REST &gt; 0 &apos; ||
       &apos;                      AND N.CODNIR = NS.CODNIR &apos; ||
       &apos;                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) &apos; ||
--       &apos;                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  &apos; ||
       &apos;                      AND IOAL.MG &lt;&gt; 5  &apos; ||
       &apos;                      AND NVL(IOAL.ESTEMIFIX, 0) = 0    &apos; ||
       &apos;                      AND NVL(IOAL.ESTEOBINV, 0) = 0    &apos; ||
       &apos;                   GROUP BY &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST &apos; ||
       &apos;                ) &apos; ||
       &apos;           WHERE STOC &gt;= 0 &apos; ||
       &apos;         ) &apos; ||
       &apos;     GROUP BY CODOBIECT, CODGEST &apos; ||
       &apos;    ) STOCVIEW,  &apos; ||
       &apos;    NARTOBJ O &apos; ||
       &apos;    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND CODCATPRET = &apos; || TO_CHAR(aCODCATPRET) ||
       &apos;    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  &apos; ||
	  &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  &apos; ||
       &apos;    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, &apos; ||
       &apos;    NGEST G &apos; ||
       &apos;  WHERE &apos; ||
       &apos;    G.CODGEST = STOCVIEW.CODGEST &apos; ||
       &apos;    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE &apos; ||
       &apos;    AND O.CODOBIECT = STOCVIEW.CODOBIECT &apos; ||
       &apos; ) &apos; ||
       &apos;  WHERE 1=1&apos;;

  IF NVL(aDENOBIECT, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_ART := &apos; AND UPPER(DENOBIECT) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENOBIECT) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aCODEXTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODEXTERN := &apos; AND UPPER(CODEXTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODEXTERN) || &apos;%&apos;&apos;&apos;;
  END IF;


  IF NVL(aCODINTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODINTERN := &apos; AND UPPER(CODINTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODINTERN) || &apos;%&apos;&apos;&apos;;
  END IF;


  IF NVL(aDENCLASA, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CLASA := &apos; AND UPPER(CLASA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENCLASA) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aCODGEST, 0) &lt;&gt; 0 THEN
    FILTRU_GEST := &apos; AND CODGEST = &apos; || TO_CHAR(aCODGEST);
  END IF;

  OPEN STOCCURSOR FOR S || FILTRU_ART || &apos; &apos; || FILTRU_CLASA || &apos; &apos; || FILTRU_GEST || FILTRU_CODEXTERN || &apos; &apos; || FILTRU_CODINTERN || &apos; ORDER BY DENOBIECT &apos;;
  RETURN STOCCURSOR;

END;

FUNCTION GETSTOCURI_STOC0( aCODPART   IN NUMBER,
                     aDenObiect IN VARCHAR2,
                     aDenClasa  IN VARCHAR2,
                     aCodGest   IN NUMBER,
                     aCODEXTERN IN VARCHAR2,
                     aCODINTERN IN VARCHAR2,
                     aToggleVAT IN NUMBER,
                     aCODMONEDA IN NUMBER)
                   RETURN STOC_CURSOR IS
  STOCCURSOR STOC_CURSOR;

  FILTRU_ART   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CLASA VARCHAR2(1000) := &apos;&apos;;
  FILTRU_GEST  VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODEXTERN   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODINTERN   VARCHAR2(1000) := &apos;&apos;;
  S            VARCHAR2(32000);
  S_PRET 	   VARCHAR2(1000) := &apos;PM.LEI&apos;;
  COND_PM 	   VARCHAR2(1000) := &apos;&apos;;
  AN           NUMBER(5);
  LUNA         NUMBER(2);
  aCODCATPRET  NUMBER(20) := 0;
  COMPUTE_VAT   VARCHAR2(1000) := &apos; NVL(PM.LEI, 0) &apos;;
  REVERSE_VAT   VARCHAR2(1000) := &apos; NVL(PM.LEI, 0) &apos;;
  var_table_varchar WORD_ARRAY;

BEGIN
  AN   := EXTRACT(YEAR FROM SYSDATE);
  LUNA := EXTRACT(MONTH FROM SYSDATE);
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(AN, Luna);
  PKG_STOC_GENERARE_FACTURI.make_config_luna_EXT;
  BEGIN
    SELECT NVL(CODCATEGPRET, 0) INTO aCODCATPRET FROM NPART WHERE CODPART = aCODPART;
    EXCEPTION WHEN OTHERS THEN aCODCATPRET := 0;
  END;
  
  IF NVL(aCODMONEDA, 0) &lt;&gt; 0 THEN
    S_PRET := &apos;PM.VALUTA&apos;;
	COND_PM := &apos; AND PM.MONEDA = &apos; || aCODMONEDA || &apos; &apos;;
  END IF;
  
  COMPUTE_VAT := &apos; NVL(&apos; || S_PRET || &apos;, 0) &apos;;
  REVERSE_VAT := &apos; NVL(&apos; || S_PRET || &apos;, 0) &apos;;

  IF NVL(aToggleVAT, 0) = 1 THEN
    COMPUTE_VAT := &apos; ROUND(NVL(&apos; || S_PRET || &apos;, 0) * (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;
  
  IF NVL(aToggleVAT, 0) = 1 THEN
    REVERSE_VAT := &apos; ROUND(NVL(&apos; || S_PRET || &apos;, 0) / (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;
  
  S := &apos; SELECT distinct * FROM &apos; ||
       &apos; ( &apos; ||
       &apos;    SELECT &apos; ||
       &apos;      1 AS TIPARTICOL, &apos; ||
       &apos;      O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;      O.CODEXTERN, &apos; ||
       &apos;      O.CODINTERN,&apos; ||
	   &apos;      O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;      A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;      A.UM1 AS DUM1,&apos; || 
       &apos;      A.COMENZIONLINE,&apos; || 
       &apos;      U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;      NULL as DEN_GEST, &apos; ||
       &apos;      O.CODOBIECT, &apos; ||
       &apos;      0 as CODGEST, &apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN &apos;|| REVERSE_VAT || &apos; &apos; ||
       &apos;      ELSE NVL(&apos; || S_PRET || &apos;, 0) &apos; ||
       &apos;    END  AS PRET, &apos; ||
       &apos;      NVL(TVAL.PROCENT, 0) AS TVA, &apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN NVL(&apos; || S_PRET || &apos;, 0) &apos; ||
       &apos;      ELSE &apos;|| COMPUTE_VAT || &apos; &apos; ||
       &apos;    END  AS PRET_TVA, &apos; ||
       &apos;      0 AS STOC, &apos; ||
       &apos;      P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;      CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;      CLAS.CODCLASEA, &apos; ||
       &apos;      U.DEN_UM, &apos; ||
       &apos;      U1.CODUM1 &apos; ||
       &apos;    FROM  &apos; ||
       &apos;      NART A   &apos; ||
	   &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA &apos; ||
       &apos;      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, &apos; ||
       &apos;      NARTOBJ O &apos; ||
       &apos;      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = &apos; || TO_CHAR(NVL(PKG_GLOBALS.GETSUBUNITATE, 0)) || &apos; &apos; || COND_PM ||
       &apos;      AND CODCATPRET = &apos; || TO_CHAR(aCODCATPRET) ||
       &apos;      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
--       &apos;    WHERE O.CODARTICOL = A.CODARTICOL AND NVL(O.INACTIV, 0) &lt;&gt;1 AND NVL(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL = 1 ) OR (A.TIPARTICOL = 0 AND ((SELECT COUNT(*) FROM NIRSTOC NS WHERE NS.CODOBIECT=O.CODOBIECT) = 0) and 2&gt; 1 ) ) &apos; ||
       &apos;    WHERE O.CODARTICOL = A.CODARTICOL AND NVL(O.INACTIV, 0) &lt;&gt;1 AND NVL(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL = 1 ) OR 
      (A.TIPARTICOL = 0 AND 
       (SELECT COUNT(*) 
        FROM NIRSTOC NS
             JOIN NIR N ON N.CODNIR = NS.CODNIR
             JOIN NGEST G ON G.CODGEST = N.GEST
        WHERE NS.CODOBIECT = O.CODOBIECT
          AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
       ) = 0
       AND 2 &gt; 1 
      ) 
    ) &apos; ||
       &apos; UNION ALL &apos; ||
       &apos; SELECT &apos; ||
       &apos;    0 AS TIPARTICOL, &apos; ||
       &apos;    O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;    O.CODEXTERN,&apos; ||
       &apos;    O.CODINTERN, &apos; ||
	   &apos;    O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;    A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;    A.UM1 AS DUM1,&apos; ||
       &apos;      A.COMENZIONLINE,&apos; || 
       &apos;    U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;    G.DEN_GEST, &apos; ||
       &apos;    STOCVIEW.CODOBIECT, &apos; ||
       &apos;    STOCVIEW.CODGEST,&apos; ||
       
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN &apos;|| REVERSE_VAT || &apos; &apos; ||
       &apos;      ELSE NVL(&apos; || S_PRET || &apos;, 0) &apos; ||
       &apos;    END  AS PRET, &apos; ||
       &apos;      NVL(TVAL.PROCENT, 0) AS TVA, &apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN NVL(&apos; || S_PRET || &apos;, 0) &apos; ||
       &apos;      ELSE &apos;|| COMPUTE_VAT || &apos; &apos; ||
       &apos;    END  AS PRET_TVA, &apos; ||
       
       &apos;    STOCVIEW.STOC, &apos; ||
       &apos;    P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;    CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;    CLAS.CODCLASEA, &apos; ||
       &apos;    U.DEN_UM, &apos; ||
       &apos;    U1.CODUM1 &apos; ||
       &apos; FROM &apos; ||
       &apos;    ( &apos; ||  -- stoc cumulat
       &apos;     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC &apos; ||
       &apos;     FROM &apos; ||
       &apos;         ( &apos; ||
       &apos;           SELECT  CODOBIECT, CODGEST, STOC FROM &apos; ||
       &apos;                (  &apos; ||
       &apos;                   SELECT &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST AS CODGEST,&apos; ||
       &apos;                      SUM(NS.REST - NVL((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC &apos; ||
       &apos;                   FROM &apos; ||
       &apos;                      NIRSTOC NS  &apos; ||
       &apos;                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, &apos; ||
       &apos;                      NIR     N &apos; ||
       &apos;                   WHERE &apos; ||
--     &apos;                      NS.REST &gt;= 0 &apos; ||
       &apos;                      N.CODNIR = NS.CODNIR &apos; ||
       &apos;                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) &apos; ||
  --       &apos;                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  &apos; ||
         &apos;                      AND IOAL.MG &lt;&gt; 5  &apos; ||
       &apos;                      AND NVL(IOAL.ESTEMIFIX, 0) = 0    &apos; ||
       &apos;                      AND NVL(IOAL.ESTEOBINV, 0) = 0    &apos; ||
       &apos;                   GROUP BY &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST &apos; ||
       &apos;                ) &apos; ||
--       &apos;           WHERE STOC &gt;= 0 &apos; ||
       &apos;         ) &apos; ||
       &apos;     GROUP BY CODOBIECT, CODGEST &apos; ||
       &apos;    ) STOCVIEW,  &apos; ||
       &apos;    NARTOBJ O &apos; ||
       &apos;    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE AND CODCATPRET = &apos; || TO_CHAR(aCODCATPRET) || &apos; &apos; || COND_PM ||
       &apos;    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  &apos; ||
	  &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  &apos; ||
       &apos;    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, &apos; ||
       &apos;    NGEST G &apos; ||
       &apos;  WHERE &apos; ||
       &apos;    G.CODGEST = STOCVIEW.CODGEST &apos; ||
       &apos;    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE &apos; ||
       &apos;    AND O.CODOBIECT = STOCVIEW.CODOBIECT AND NVL(O.INACTIV, 0) &lt;&gt;1 AND NVL(O.BLOCAT, 0) NOT IN (1, 3) &apos; ||
       &apos; ) &apos; ||
       &apos;  WHERE 1=1&apos;;

  IF NVL(aDENOBIECT, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
  /*
    FILTRU_ART := &apos; AND UPPER(DENOBIECT) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENOBIECT) || &apos;%&apos;&apos;&apos;;
    */
    var_table_varchar := TOKENIZE_STRING(aDENOBIECT, &apos; &apos;);
        for elem in 1 .. var_table_varchar.count    
        loop
         FILTRU_ART := FILTRU_ART || &apos; AND UPPER(DENOBIECT) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(var_table_varchar(elem)) || &apos;%&apos;&apos;&apos;;
        end loop;
  END IF;

  IF NVL(aCODEXTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODEXTERN := &apos; AND UPPER(CODEXTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODEXTERN) || &apos;%&apos;&apos;&apos;;
  END IF;


  IF NVL(aCODINTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODINTERN := &apos; AND UPPER(CODINTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODINTERN) || &apos;%&apos;&apos;&apos;;
  END IF;


  IF NVL(aDENCLASA, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CLASA := &apos; AND UPPER(CLASA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENCLASA) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  
  IF NVL(aDENOBIECT, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aDENOBIECT, 1, 1) = &apos;=&apos; THEN
    FILTRU_ART := &apos; AND UPPER(DENOBIECT) = &apos;&apos;&apos; ||  LTRIM(UPPER(aDENOBIECT), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  
IF NVL(aCODEXTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aCODEXTERN, 1, 1) = &apos;=&apos; THEN
    FILTRU_CODEXTERN := &apos; AND UPPER(CODEXTERN) = &apos;&apos;&apos; ||  LTRIM(UPPER(aCODEXTERN), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  
IF NVL(aCODINTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aCODINTERN, 1, 1) = &apos;=&apos; THEN
    FILTRU_CODINTERN := &apos; AND UPPER(CODINTERN) = &apos;&apos;&apos; ||  LTRIM(UPPER(aCODINTERN), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  
IF NVL(aDENCLASA, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aDENCLASA, 1, 1) = &apos;=&apos; THEN
    FILTRU_CLASA := &apos; AND UPPER(CLASA) = &apos;&apos;&apos; ||  LTRIM(UPPER(aDENCLASA), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  

  IF NVL(aCODGEST, 0) &lt;&gt; 0 THEN
    FILTRU_GEST := &apos; AND CODGEST = &apos; || TO_CHAR(aCODGEST);
  END IF;

  OPEN STOCCURSOR FOR S || FILTRU_ART || &apos; &apos; || FILTRU_CLASA || &apos; &apos; || FILTRU_GEST || FILTRU_CODEXTERN || &apos; &apos; || FILTRU_CODINTERN || &apos; ORDER BY DENOBIECT &apos;;
  RETURN STOCCURSOR;

END;


FUNCTION GETSTOCURI_STOC0_FARA_PARTENER(
                     aDenObiect IN VARCHAR2,
                     aDenClasa  IN VARCHAR2,
                     aCodGest   IN NUMBER,
                     aCODEXTERN IN VARCHAR2,
                     aCODINTERN IN VARCHAR2,
                     aToggleVAT IN NUMBER)
                   RETURN STOC_CURSOR IS
  STOCCURSOR STOC_CURSOR;

  FILTRU_ART   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CLASA VARCHAR2(1000) := &apos;&apos;;
  FILTRU_GEST  VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODEXTERN   VARCHAR2(1000) := &apos;&apos;;
  FILTRU_CODINTERN   VARCHAR2(1000) := &apos;&apos;;
  S            VARCHAR2(32000);
  AN           NUMBER(5);
  LUNA         NUMBER(2);
  aCODCATPRET  NUMBER(20) := 0;
  COMPUTE_VAT   VARCHAR2(1000) := &apos; NVL(PM.LEI, 0) &apos;;
  REVERSE_VAT   VARCHAR2(1000) := &apos; NVL(PM.LEI, 0) &apos;;
  var_table_varchar WORD_ARRAY;

BEGIN
  AN   := EXTRACT(YEAR FROM SYSDATE);
  LUNA := EXTRACT(MONTH FROM SYSDATE);
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(AN, Luna);
  PKG_STOC_GENERARE_FACTURI.make_config_luna_EXT;
  
  IF NVL(aToggleVAT, 0) = 1 THEN
    COMPUTE_VAT := &apos; ROUND(NVL(PM.LEI, 0) * (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;
  
   IF NVL(aToggleVAT, 0) = 1 THEN
    REVERSE_VAT := &apos; ROUND(NVL(PM.LEI, 0) / (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;

  S := &apos; SELECT distinct * FROM &apos; ||
       &apos; ( &apos; ||
       &apos;    SELECT &apos; ||
       &apos;      1 AS TIPARTICOL, &apos; ||
       &apos;      O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;      O.CODEXTERN, &apos; ||
       &apos;      O.CODINTERN,&apos; ||
	   &apos;      O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;      A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;      A.UM1 AS DUM1,&apos; || 
       &apos;      A.COMENZIONLINE,&apos; || 
       &apos;      U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;      NULL as DEN_GEST, &apos; ||
       &apos;      O.CODOBIECT, &apos; ||
       &apos;      0 as CODGEST, &apos; ||
       
        &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN &apos;|| REVERSE_VAT || &apos; &apos; ||
       &apos;      ELSE NVL(PM.LEI, 0) &apos; ||
       &apos;    END  AS PRET, &apos; ||
       &apos;      NVL(TVAL.PROCENT, 0) AS TVA, &apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN NVL(PM.LEI, 0) &apos; ||
       &apos;      ELSE &apos;|| COMPUTE_VAT || &apos; &apos; ||
       &apos;    END  AS PRET_TVA, &apos; ||
       
       &apos;      0 AS STOC, &apos; ||
       &apos;      P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;      CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;      U.DEN_UM, &apos; ||
       &apos;      U1.CODUM1 &apos; ||
       &apos;    FROM  &apos; ||
       &apos;      NART A   &apos; ||
	   &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;      LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA &apos; ||
       &apos;      LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;      LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;      LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA, &apos; ||
       &apos;      NARTOBJ O &apos; ||
       &apos;      LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1&apos; ||
       &apos;      LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;      LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
       &apos;    WHERE O.CODARTICOL = A.CODARTICOL AND NVL(O.INACTIV, 0) &lt;&gt;1 AND NVL(O.BLOCAT, 0) NOT IN (1, 3) AND ( (A.TIPARTICOL = 1 ) OR (A.TIPARTICOL = 0 AND ((SELECT COUNT(*) FROM NIRSTOC NS WHERE NS.CODOBIECT=O.CODOBIECT) = 0) and 2&gt; 1 ) ) &apos; ||
       &apos; UNION ALL &apos; ||
       &apos; SELECT &apos; ||
       &apos;    0 AS TIPARTICOL, &apos; ||
       &apos;    O.DENUMIRE AS DENOBIECT, &apos; ||
       &apos;    O.CODEXTERN,&apos; ||
       &apos;    O.CODINTERN, &apos; ||
	   &apos;    O.CODARTICOL,&apos; ||
     &apos;      O.INACTIV, &apos; ||
       &apos;    A.DEN_ARTICOL AS DEN_ART,&apos; ||  
       &apos;    A.UM1 AS DUM1,&apos; ||
       &apos;      A.COMENZIONLINE,&apos; || 
       &apos;    U0.DEN_UM1 AS DENUM1,&apos; || 
       &apos;    G.DEN_GEST, &apos; ||
       &apos;    STOCVIEW.CODOBIECT, &apos; ||
       &apos;    STOCVIEW.CODGEST,&apos; ||
       
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN &apos;|| REVERSE_VAT || &apos; &apos; ||
       &apos;      ELSE NVL(PM.LEI, 0) &apos; ||
       &apos;    END  AS PRET, &apos; ||
       &apos;      NVL(TVAL.PROCENT, 0) AS TVA, &apos; ||
       &apos;    CASE &apos; ||
       &apos;      WHEN CAT.TIP = 1 THEN NVL(PM.LEI, 0) &apos; ||
       &apos;      ELSE &apos;|| COMPUTE_VAT || &apos; &apos; ||
       &apos;    END  AS PRET_TVA, &apos; ||
       
       &apos;    STOCVIEW.STOC, &apos; ||
       &apos;    P.DEN_PART AS PRODUCATOR, &apos; ||
       &apos;    CLAS.DEN_CLASEA AS CLASA, &apos; ||
       &apos;    U.DEN_UM, &apos; ||
       &apos;    U1.CODUM1 &apos; ||
       &apos; FROM &apos; ||
       &apos;    ( &apos; ||  -- stoc cumulat
       &apos;     SELECT CODOBIECT, CODGEST, SUM(STOC) AS STOC &apos; ||
       &apos;     FROM &apos; ||
       &apos;         ( &apos; ||
       &apos;           SELECT  CODOBIECT, CODGEST, STOC FROM &apos; ||
       &apos;                (  &apos; ||
       &apos;                   SELECT &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST AS CODGEST,&apos; ||
       &apos;                      SUM(NS.REST - NVL((SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC), 0)) AS STOC &apos; ||
       &apos;                   FROM &apos; ||
       &apos;                      NIRSTOC NS  &apos; ||
       &apos;                      LEFT OUTER JOIN TMP_IOART_LUNA IOAL ON IOAL.CODIOART = NS.CODIOART, &apos; ||
       &apos;                      NIR     N &apos; ||
       &apos;                   WHERE &apos; ||
--     &apos;                      NS.REST &gt;= 0 &apos; ||
       &apos;                      N.CODNIR = NS.CODNIR &apos; ||
       &apos;                      AND (((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0) OR (EXISTS (SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST))) &apos; ||
--       &apos;                      AND IOAL.MG &lt;&gt; 3 AND IOAL.MG &lt;&gt; 5  &apos; ||
       &apos;                      AND IOAL.MG &lt;&gt; 5  &apos; ||
       &apos;                      AND NVL(IOAL.ESTEMIFIX, 0) = 0    &apos; ||
       &apos;                      AND NVL(IOAL.ESTEOBINV, 0) = 0    &apos; ||
       &apos;                   GROUP BY &apos; ||
       &apos;                      NS.CODOBIECT, &apos; ||
       &apos;                      N.GEST &apos; ||
       &apos;                ) &apos; ||
--       &apos;           WHERE STOC &gt;= 0 &apos; ||
       &apos;         ) &apos; ||
       &apos;     GROUP BY CODOBIECT, CODGEST &apos; ||
       &apos;    ) STOCVIEW,  &apos; ||
       &apos;    NARTOBJ O &apos; ||
       &apos;    LEFT OUTER JOIN PRETM PM ON PM.CODOBIECT = O.CODOBIECT AND PM.IMPLICIT = 1 &apos; || 
       &apos;    LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = PM.CODCATPRET &apos; ||
       &apos;    LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL  &apos; ||
	  &apos;      LEFT OUTER JOIN NUM1 U0 ON U0.CODUM1 = A.UM1 &apos; ||
       &apos;    LEFT OUTER JOIN NUM U ON U.CODUM = A.UM &apos; ||
       &apos;    LEFT OUTER JOIN NUM1 U1 ON U1.CODUM = U.CODUM AND U1.SECUNDARA = 0&apos; ||
       &apos;    LEFT OUTER JOIN NCLASEA CLAS ON CLAS.CODCLASEA = CLASA  &apos; ||
       &apos;    LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = A.CODARTICOL  &apos; ||
       &apos;    LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA, &apos; ||
       &apos;    NGEST G &apos; ||
       &apos;  WHERE &apos; ||
       &apos;    G.CODGEST = STOCVIEW.CODGEST &apos; ||
       &apos;    AND G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE &apos; ||
       &apos;    AND O.CODOBIECT = STOCVIEW.CODOBIECT AND NVL(O.INACTIV, 0) &lt;&gt;1 AND NVL(O.BLOCAT, 0) NOT IN (1, 3) &apos; ||
       &apos; ) &apos; ||
       &apos;  WHERE 1=1&apos;;

  IF NVL(aDENOBIECT, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
  /*
    FILTRU_ART := &apos; AND UPPER(DENOBIECT) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENOBIECT) || &apos;%&apos;&apos;&apos;;
    */
    var_table_varchar := TOKENIZE_STRING(aDENOBIECT, &apos; &apos;);
        for elem in 1 .. var_table_varchar.count    
        loop
         FILTRU_ART := FILTRU_ART || &apos; AND UPPER(DENOBIECT) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(var_table_varchar(elem)) || &apos;%&apos;&apos;&apos;;
        end loop;
  END IF;

  IF NVL(aDENOBIECT, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aDENOBIECT, 1, 1) = &apos;=&apos; THEN
    FILTRU_ART := &apos; AND UPPER(DENOBIECT) = &apos;&apos;&apos; ||  LTRIM(UPPER(aDENOBIECT), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  

  IF NVL(aCODEXTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODEXTERN := &apos; AND UPPER(CODEXTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODEXTERN) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aCODEXTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aCODEXTERN, 1, 1) = &apos;=&apos; THEN
    FILTRU_CODEXTERN := &apos; AND UPPER(CODEXTERN) = &apos;&apos;&apos; ||  LTRIM(UPPER(aCODEXTERN), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;


  IF NVL(aCODINTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CODINTERN := &apos; AND UPPER(CODINTERN) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aCODINTERN) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aCODINTERN, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aCODINTERN, 1, 1) = &apos;=&apos; THEN
    FILTRU_CODINTERN := &apos; AND UPPER(CODINTERN) = &apos;&apos;&apos; ||  LTRIM(UPPER(aCODINTERN), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;


  IF NVL(aDENCLASA, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_CLASA := &apos; AND UPPER(CLASA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENCLASA) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aDENCLASA, &apos;?&apos;) &lt;&gt; &apos;?&apos; AND SUBSTR(aDENCLASA, 1, 1) = &apos;=&apos; THEN
    FILTRU_CLASA := &apos; AND UPPER(CLASA) = &apos;&apos;&apos; ||  LTRIM(UPPER(aDENCLASA), &apos;=&apos;) || &apos;&apos;&apos; &apos;;
  END IF;
  

  IF NVL(aCODGEST, 0) &lt;&gt; 0 THEN
    FILTRU_GEST := &apos; AND CODGEST = &apos; || TO_CHAR(aCODGEST);
  END IF;

  OPEN STOCCURSOR FOR S || FILTRU_ART || &apos; &apos; || FILTRU_CLASA || &apos; &apos; || FILTRU_GEST || FILTRU_CODEXTERN || &apos; &apos; || FILTRU_CODINTERN || &apos; ORDER BY DENOBIECT &apos;;
  RETURN STOCCURSOR;

END;



FUNCTION GET_CARNET_WMEONLINE(aCODSUBUNIT IN NUMBER, TIPMACHETA IN NUMBER) RETURN NUMBER
IS
 aCODCARNET NUMBER := 0;
BEGIN
  BEGIN
    SELECT CODCARNET INTO aCODCARNET
    FROM
      DOCCARNETE C
    WHERE
      SUBUNITATEA = aCODSUBUNIT AND NVL(COMENZIONLINE, 0) = 1 AND ROWNUM = 1
      AND EXISTS(SELECT DL.CODCARNET FROM DOCLINK DL WHERE DL.CODMACHETA = TIPMACHETA AND DL.CODCARNET = C.CODCARNET);
    EXCEPTION WHEN OTHERS THEN aCODCARNET := 0;
  END;
  RETURN aCODCARNET;
END;
FUNCTION GET_NEXT_NUMAR_DOC(aCODCARNET IN NUMBER, SERIEDOC OUT VARCHAR2) return varchar2
IS
 NRDOC      VARCHAR2(100) := &apos;0&apos;;
 PASI       NUMBER := 0;
 aSIMBOLDOC VARCHAR2(100) := &apos;&apos;;
BEGIN
  WHILE 1 = 1 LOOP
    NRDOC := PKG_CARNETEDOC.GETNEXTNRDOC(aCODCARNET , SERIEDOC , aSIMBOLDOC);
    IF PKG_CARNETEDOC.CANLOCKNUMARDOC(aCODCARNET, NRDOC) = 1 OR PASI &gt; 1000 THEN
      EXIT;
    END IF;
    PASI := PASI + 1;
  END LOOP;
  RETURN NRDOC;
END;

FUNCTION GET_OFERTE_AGENT (aCODPERS IN NUMBER,  aDenPART IN VARCHAR2, aDATAREF IN VARCHAR2 ) RETURN OFERTA_CURSOR
IS
  S   VARCHAR2(4000);
  OFERTACURSOR OFERTA_CURSOR;
  FILTRU_PART VARCHAR2(500) := &apos;&apos;;
 BEGIN

  IF NVL(aDENPART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_PART := &apos; AND UPPER(DEN_PART) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENPART) || &apos;%&apos;&apos;&apos;;
  END IF;

  S := &apos;SELECT * FROM (
         SELECT OFE.*
          FROM
          (
        SELECT
          CODOFERTA, TIPDOC, ANULAT, BLOCAT, OPERAT, SERIE, NRDOC, DATASTART, DATAEND, PARTENER,
          AN, LUNA, OBS, MONEDA, CODLOCATIE, SUBUNITATEA, CODFISCAL, USERID, DATACREARE, DATAOFERTA,
          PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT, SUBUNITATEDOC, SEDIU, NUMEAGENT,
          PCNume, PCTel, PCEmail, Aprobari, NRI, Utilizator, Valoare
        FROM (
         SELECT
          O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT, O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART, O.DATAEND, O.PARTENER,
          O.AN, O.LUNA, O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA, O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
          Decode(O.TipBeneficiar, 1, &apos;&apos;DA&apos;&apos;, &apos;&apos;NU&apos;&apos;) PE_CLASA, Coalesce(P.Den_Part, CP.Den_Clasep, &apos;&apos;...&apos;&apos;) Den_Part, M.Den_Moneda, L.Den_Localit, S.DEN_SUBUNIT SUBUNITATEDOC, SED.OBS SEDIU,
          Decode(A.CodPers,0,A.Nume,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME) NUMEAGENT, O.NRI,
          PC.Nume||&apos;&apos; &apos;&apos;||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator,
          (SELECT Sum(Nvl(O1.CANTMIN*O1.PRET*Coalesce(1+O1.PROCADAOS/100,1)*Coalesce(1+O1.ProcDiscount/100,1) ,0)) FROM OFERTA1 O1 WHERE O1.CodOferta = O.CodOferta) Valoare,   &apos;&apos; &apos;&apos; AS  Aprobari
         FROM OFERTA O
          LEFT JOIN NPART     P ON NVL(O.Partener, 0)  = P.Codpart    AND Nvl(TipBeneficiar, 0) = 0
          LEFT JOIN NCLASEP  CP ON NVL(O.CodClaseP, 0) = CP.CodClaseP AND Nvl(TipBeneficiar, 0) = 1
          LEFT JOIN NAGENDA SED ON SED.Codagenda = O.CodLocatie
          LEFT JOIN NLOCALIT  L ON L.Codlocalit = SED.CodLocalit
          LEFT JOIN NMONEDE   M ON M.CodMoneda = O.Moneda
          LEFT JOIN NSUBUNIT  S ON S.CODSUBUNIT = O.SUBUNITATEA
          LEFT JOIN NPERS     A ON A.CODPERS = Nvl(O.AGENT,0)
          LEFT JOIN NPERSCONTACT PC ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
          LEFT JOIN DOCCARNETE C ON C.CODCARNET = O.CARNETDOC
          LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = O.USERID
         WHERE
           O.TipDoc = 50
           AND O.AGENT = &apos; ||  TO_CHAR(aCODPERS) ||
         &apos; AND DATASTART &lt;= TO_DATE(&apos;&apos;&apos; || aDATAREF || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;)
           AND DATAEND   &gt;= TO_DATE(&apos;&apos;&apos; || aDATAREF || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;)
           AND (Nvl(O.ToateSubunit,0) = 1 or O.SUBUNITATEA= PKG_GLOBALS.GETSUBUNITATE) )) OFE
        )
         WHERE 1=1&apos; ||
         Filtru_Part;

  OPEN OFERTACURSOR FOR S;
  RETURN OFERTACURSOR;

END;


FUNCTION GET_OFERTE_AGENT_SI_FARA_AGENT (aCODPERS IN NUMBER, aDenPART IN VARCHAR2, aDATAREF IN VARCHAR2, aNRDOC IN VARCHAR2, aDATASTART IN VARCHAR2, aDATAEND IN VARCHAR2, aOBS IN VARCHAR2, aDATAOFERTA IN VARCHAR2) RETURN OFERTA_CURSOR
IS
  S   VARCHAR2(4000);
  OFERTACURSOR OFERTA_CURSOR;
  FILTRU_PART VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRDOC VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATASTART VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATAEND VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATAOFERTA VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATAREF VARCHAR2(500) := &apos;&apos;;
  FILTRU_OBS VARCHAR2(500) := &apos;&apos;;
 BEGIN

  IF NVL(aDENPART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
     FILTRU_PART := &apos; AND (UPPER(DEN_PART) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENPART) || &apos;%&apos;&apos; OR NVL(PARTENER, 0) = 0)&apos;;
  END IF;
  IF NVL(aDATASTART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATASTART := &apos; AND DATASTART = TO_DATE(&apos;&apos;&apos; || aDATASTART || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  IF NVL(aDATAEND, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATAEND := &apos; AND DATAEND = TO_DATE(&apos;&apos;&apos; || aDATAEND || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  IF NVL(aDATAOFERTA, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATAOFERTA := &apos; AND DATAOFERTA = TO_DATE(&apos;&apos;&apos; || aDATAOFERTA || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  IF NVL(aDATAREF, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATAREF:= &apos; AND DATASTART &lt;= TO_DATE(&apos;&apos;&apos; || aDATAREF || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;)
					   AND DATAEND   &gt;= TO_DATE(&apos;&apos;&apos; || aDATAREF || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  IF NVL(aNRDOC, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRDOC := &apos; AND UPPER(NRDOC) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRDOC) || &apos;%&apos;&apos;&apos;;
  END IF;
  IF NVL(aOBS, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_OBS := &apos; AND UPPER(OBS) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aOBS) || &apos;%&apos;&apos;&apos;;
  END IF;

  S := &apos;SELECT * FROM (
         SELECT OFE.*
          FROM
          (
        SELECT
          CODOFERTA, TIPDOC, ANULAT, BLOCAT, OPERAT, SERIE, NRDOC, DATASTART, DATAEND, PARTENER,
          AN, LUNA, OBS, MONEDA, CODLOCATIE, SUBUNITATEA, CODFISCAL, USERID, DATACREARE, DATAOFERTA,
          PE_CLASA, DEN_PART, DEN_MONEDA, DEN_LOCALIT, SUBUNITATEDOC, SEDIU, NUMEAGENT,
          PCNume, PCTel, PCEmail, Aprobari, NRI, Utilizator, Valoare
        FROM (
         SELECT
          O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT, O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART, O.DATAEND, O.PARTENER,
          O.AN, O.LUNA, O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA, O.CODFISCAL, O.USERID, O.DATACREARE, O.DATAOFERTA,
          Decode(O.TipBeneficiar, 1, &apos;&apos;DA&apos;&apos;, &apos;&apos;NU&apos;&apos;) PE_CLASA, Coalesce(P.Den_Part, CP.Den_Clasep, &apos;&apos;...&apos;&apos;) Den_Part, M.Den_Moneda, L.Den_Localit, S.DEN_SUBUNIT SUBUNITATEDOC, SED.OBS SEDIU,
          Decode(A.CodPers,0,A.Nume,A.NUME||&apos;&apos; &apos;&apos;||A.PRENUME) NUMEAGENT, O.NRI,
          PC.Nume||&apos;&apos; &apos;&apos;||PC.Prenume PCNume, PC.TELEFON PCTel, PC.EMAIL PCEmail, UT.UserName Utilizator,
          (SELECT Sum(Nvl(O1.CANTMIN*O1.PRET*Coalesce(1+O1.PROCADAOS/100,1)*Coalesce(1+O1.ProcDiscount/100,1) ,0)) FROM OFERTA1 O1 WHERE O1.CodOferta = O.CodOferta) Valoare,   &apos;&apos; &apos;&apos; AS  Aprobari
         FROM OFERTA O
          LEFT JOIN NPART     P ON NVL(O.Partener, 0)  = P.Codpart    AND Nvl(TipBeneficiar, 0) = 0
          LEFT JOIN NCLASEP  CP ON NVL(O.CodClaseP, 0) = CP.CodClaseP AND Nvl(TipBeneficiar, 0) = 1
          LEFT JOIN NAGENDA SED ON SED.Codagenda = O.CodLocatie
          LEFT JOIN NLOCALIT  L ON L.Codlocalit = SED.CodLocalit
          LEFT JOIN NMONEDE   M ON M.CodMoneda = O.Moneda
          LEFT JOIN NSUBUNIT  S ON S.CODSUBUNIT = O.SUBUNITATEA
          LEFT JOIN NPERS     A ON A.CODPERS = Nvl(O.AGENT,0)
          LEFT JOIN NPERSCONTACT PC ON PC.CodPart = P.CodPart AND PC.CodPersC = O.CodPersC
          LEFT JOIN DOCCARNETE C ON C.CODCARNET = O.CARNETDOC
          LEFT JOIN TMP_UTILIZATOR UT ON UT.CODUTILIZATOR = O.USERID
         WHERE
           O.TipDoc = 50
           AND O.OFERTAT = 1
           AND (O.AGENT = &apos; ||  TO_CHAR(aCODPERS) || &apos; OR NVL(O.AGENT, 0) = 0)
           AND (Nvl(O.ToateSubunit,0) = 1 or O.SUBUNITATEA= PKG_GLOBALS.GETSUBUNITATE) )) OFE
        )
         WHERE 1=1&apos; ||
         Filtru_Part || FILTRU_NRDOC || FILTRU_DATASTART || FILTRU_DATAEND || FILTRU_DATAOFERTA || FILTRU_DATAREF || FILTRU_OBS || &apos; ORDER BY DEN_PART, NRDOC DESC&apos;;

  OPEN OFERTACURSOR FOR S;
  RETURN OFERTACURSOR;

END;


FUNCTION GET_COMENZI_AGENT (aCODPERS IN NUMBER,  
                            aDenPART IN VARCHAR2, 
                            DATASTART IN VARCHAR2,
                            aOBS IN VARCHAR2,
                            aSTARE IN VARCHAR2,
                            aNRDOC IN VARCHAR2
                            ) RETURN CMD_CURSOR
IS
  S   VARCHAR2(4000);
  COMANDACURSOR CMD_CURSOR;
  FILTRU_PART VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATA VARCHAR2(500) := &apos;&apos;;
  FILTRU_OBS    VARCHAR2(500) := &apos;&apos;;
  FILTRU_STARE  VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRDOC  VARCHAR2(500) := &apos;&apos;;
 BEGIN

  IF NVL(aDENPART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_PART := &apos; AND UPPER(DEN_PART) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aDENPART) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(DATASTART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATA := &apos; AND TO_DATE(DATADOC, &apos;&apos;DD-MM-YYYY&apos;&apos;) &gt;= TO_DATE(&apos;&apos;&apos; || DATASTART || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  
  IF NVL(aOBS, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_OBS := &apos; AND UPPER(OBS) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aOBS) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aSTARE, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_STARE := &apos; AND UPPER(STARECOMANDA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aSTARE) || &apos;%&apos;&apos;&apos;;
    IF UPPER(aSTARE) = &apos;TOATE&apos; THEN
		FILTRU_STARE := &apos;&apos;;
	END IF;
  END IF;

  IF NVL(aNRDOC, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRDOC := &apos; AND UPPER(NRDOC) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRDOC) || &apos;%&apos;&apos;&apos;;
  END IF;


   S := &apos;SELECT * FROM &apos; ||
        &apos;(SELECT &apos; ||
        &apos;   CODCOMANDA, &apos; ||
        &apos;   TIPDOC, &apos; ||
        &apos;   ANULAT, &apos; ||
        &apos;   BLOCAT, &apos; ||
        &apos;   OPERAT, &apos; ||
        &apos;   PREFIXDOC, &apos; ||
        &apos;   INCHISA, &apos; ||
        &apos;   NRDOC, &apos; ||
        &apos;   DATADOC, &apos; ||
        &apos;   NUMEAGENT, &apos; ||
        &apos;   DEN_LOCALIT, &apos; ||
        &apos;   to_char(DATACREARE, &apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;) DATACREARE, &apos; ||
        &apos;   VERIFICAT, &apos; ||
        &apos;   FACTURABIL, &apos; ||
        &apos;   NRI,  &apos; ||
        &apos;   SERIADOC, &apos; ||
        &apos;   PARTENER,&apos; ||
        &apos;   VALOARE, &apos; ||
        &apos;   AN, &apos; ||
        &apos;   LUNA,  &apos; ||
        &apos;   OBS, &apos; ||
        &apos;   MONEDA, &apos; ||
        &apos;   DEN_PART, &apos; ||
        &apos;   SIMBOL, &apos; ||
        &apos;   SUBUNITATEDOC, &apos; ||
        &apos;   SEDIULIVRARE, &apos; ||
        &apos;   DELEGAT, &apos; ||
        &apos;   PC_CODPERSC, &apos; ||
        &apos;   PC_NUME, &apos; ||
        &apos;   PC_PRENUME, &apos; ||
        &apos;   PC_TELEFON, &apos; ||
        &apos;   PC_EMAIL, &apos; ||
        &apos;   PC_CNP, &apos; ||
        &apos;    (  &apos; ||
        &apos;   CASE &apos; ||
        &apos;     WHEN FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN &apos;&apos;NEFACTURATA&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos; &apos; ||
        &apos;     ELSE &apos;&apos;&apos;&apos; &apos; ||
        &apos;   END &apos; ||
        &apos;    ) AS STARECOMANDA  &apos; ||
        &apos;   FROM  &apos; ||
        &apos;   ( &apos; ||
        &apos;  SELECT &apos; ||
        &apos;    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, NVL(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  &apos; ||
        &apos;    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || &apos;&apos; &apos;&apos; || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  &apos; ||
        &apos;    NPC.CODPERSC PC_CODPERSC, NPC.NUME PC_NUME, NPC.PRENUME PC_PRENUME, NPC.TELEFON PC_TELEFON, NPC.EMAIL PC_EMAIL, NPC.CNP PC_CNP, &apos; ||
        &apos;    (SELECT DECODE(COUNT(*), 0, 0, 1) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  &apos; ||
        &apos;    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, &apos; ||
        &apos;    (SELECT NVL(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND NVL(CANTACCEPTAT, 0) &gt; 0 AND NVL(RESTACCEPTAT, 0) &gt; 0) AS CU_REST &apos; ||
        &apos;  FROM  &apos; ||
        &apos;     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  &apos; ||
        &apos;     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA &apos; ||
        &apos;     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE &apos; ||
        &apos;     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT &apos; ||
        &apos;     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0) &apos; ||
        &apos;     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA &apos; ||
        &apos;     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT &apos; ||
        &apos;     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT &apos; ||
        &apos;     LEFT OUTER JOIN NPERSCONTACT NPC ON NPC.CODPERSC = C.CODPERSC &apos; ||
        &apos;  WHERE &apos; ||
        &apos;     NVL(C.DISPLIVRARE,0) = 0 &apos; ||
        &apos;      AND C.TIPDOC =  18 &apos; ||
        &apos;      AND C.AGENT = &apos; || TO_CHAR(aCODPERS) ||
        &apos;      AND c.SUBUNITATEA =PKG_GLOBALS.GETSUBUNITATE &apos; ||
        &apos;  ) &apos; ||
        &apos;) &apos; ||
        &apos; WHERE &apos; ||
        &apos; 1 = 1 &apos; ||
        Filtru_Part ||
        FILTRU_DATA ||
        FILTRU_OBS   ||
        FILTRU_STARE ||
        FILTRU_NRDOC ||
        &apos; ORDER BY DATADOC DESC, NRDOC DESC&apos;  ;

  OPEN COMANDACURSOR FOR S;
  RETURN COMANDACURSOR;

END;


FUNCTION GET_COMENZI_CLIENT (aCODPART      IN NUMBER,  
                             DATASTART     IN VARCHAR2,
                             aSEDIULIVRARE IN VARCHAR2,
                             aOBS          IN VARCHAR2,
                             aSTARE        IN VARCHAR2,
                             aNRDOC        IN VARCHAR2,
                             aFACTURABIL   IN VARCHAR2,
                             aNRI          IN VARCHAR2
                            ) RETURN CMD_CURSOR
IS
  S   VARCHAR2(4000);
  COMANDACURSOR CMD_CURSOR;
  FILTRU_DATA   VARCHAR2(500) := &apos;&apos;;
  FILTRU_SEDIU  VARCHAR2(500) := &apos;&apos;;
  FILTRU_OBS    VARCHAR2(500) := &apos;&apos;;
  FILTRU_STARE  VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRDOC  VARCHAR2(500) := &apos;&apos;;
  FILTRU_FACTURABIL  VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRI  VARCHAR2(500) := &apos;&apos;;
 BEGIN


  IF NVL(DATASTART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATA := &apos; AND TO_DATE(DATADOC, &apos;&apos;DD-MM-YYYY&apos;&apos;) &gt;= TO_DATE(&apos;&apos;&apos; || DATASTART || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;

  IF NVL(aSEDIULIVRARE, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_SEDIU := &apos; AND UPPER(SEDIULIVRARE) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aSEDIULIVRARE) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aOBS, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_OBS := &apos; AND UPPER(OBS) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aOBS) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aSTARE, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_STARE := &apos; AND UPPER(STARECOMANDA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aSTARE) || &apos;%&apos;&apos;&apos;;
	IF UPPER(aSTARE) = &apos;FIC&apos; THEN
		FILTRU_STARE := &apos; AND ( UPPER(STARECOMANDA) = &apos;&apos;NEFACTURATA&apos;&apos; OR UPPER(STARECOMANDA) = &apos;&apos;FACTURATA PARTIAL&apos;&apos; ) &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;ANULATA&apos; THEN
		FILTRU_STARE := &apos; AND ANULAT = 1 &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;INCHISA&apos; THEN
		FILTRU_STARE := &apos; AND INCHISA = 1 &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;TOATE&apos; THEN
		FILTRU_STARE := &apos;&apos;;
	END IF;
  END IF;

  IF NVL(aNRDOC, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRDOC := &apos; AND UPPER(NRDOC) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRDOC) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aFACTURABIL, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_FACTURABIL := &apos; AND TO_CHAR(FACTURABIL) LIKE &apos; || &apos;&apos;&apos;%&apos; || aFACTURABIL || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aNRI, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRI := &apos; AND UPPER(NRI) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRI) || &apos;%&apos;&apos;&apos;;
  END IF;


   S := &apos;SELECT * FROM &apos; ||
        &apos;(SELECT &apos; ||
        &apos;   CODCOMANDA, &apos; ||
        &apos;   TIPDOC, &apos; ||
        &apos;   ANULAT, &apos; ||
        &apos;   BLOCAT, &apos; ||
        &apos;   OPERAT, &apos; ||
        &apos;   PREFIXDOC, &apos; ||
        &apos;   INCHISA, &apos; ||
        &apos;   NRDOC, &apos; ||
        &apos;   DATADOC, &apos; ||
        &apos;   NUMEAGENT, &apos; ||
        &apos;   DEN_LOCALIT, &apos; ||
        &apos;   to_char(DATACREARE, &apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;) DATACREARE, &apos; ||
        &apos;   VERIFICAT, &apos; ||
        &apos;   FACTURABIL, &apos; ||
        &apos;   NRI,  &apos; ||
        &apos;   SERIADOC, &apos; ||
        &apos;   PARTENER,&apos; ||
        &apos;   VALOARE, &apos; ||
        &apos;   AN, &apos; ||
        &apos;   LUNA,  &apos; ||
        &apos;   OBS, &apos; ||
        &apos;   MONEDA, &apos; ||
        &apos;   DEN_MONEDA, &apos; ||
        &apos;   DEN_PART, &apos; ||
        &apos;   SIMBOL, &apos; ||
        &apos;   SUBUNITATEDOC, &apos; ||
        &apos;   SEDIULIVRARE, &apos; ||
        &apos;   DELEGAT, &apos; ||
        &apos;    (  &apos; ||
        &apos;   CASE &apos; ||
        &apos;     WHEN ANULAT = 1 THEN &apos;&apos;ANULATA&apos;&apos; &apos; ||
        &apos;     WHEN INCHISA = 1 THEN &apos;&apos;INCHISA&apos;&apos; &apos; ||
        &apos;     WHEN FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN &apos;&apos;NEFACTURATA&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos; &apos; ||
        &apos;     ELSE &apos;&apos;&apos;&apos; &apos; ||
        &apos;   END &apos; ||
        &apos;    ) AS STARECOMANDA  &apos; ||
        &apos;   FROM  &apos; ||
        &apos;   ( &apos; ||
        &apos;  SELECT &apos; ||
        &apos;    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, NVL(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  &apos; ||
        &apos;    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || &apos;&apos; &apos;&apos; || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  &apos; ||
        &apos;    (SELECT DECODE(COUNT(*), 0, 0, 1) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  &apos; ||
        &apos;    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, &apos; ||
        &apos;    (SELECT NVL(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND NVL(CANTACCEPTAT, 0) &gt; 0 AND NVL(RESTACCEPTAT, 0) &gt; 0) AS CU_REST &apos; ||
        &apos;  FROM  &apos; ||
        &apos;     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  &apos; ||
        &apos;     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA &apos; ||
        &apos;     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE &apos; ||
        &apos;     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT &apos; ||
        &apos;     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0) &apos; ||
        &apos;     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA &apos; ||
        &apos;     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT &apos; ||
        &apos;     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT &apos; ||
        &apos;  WHERE &apos; ||
        &apos;     NVL(C.DISPLIVRARE,0) = 0 &apos; ||
        &apos;      AND C.TIPDOC =  18 &apos; ||
        &apos;      AND C.PARTENER = &apos; || TO_CHAR(aCODPART) ||
        &apos;      AND c.SUBUNITATEA =PKG_GLOBALS.GETSUBUNITATE &apos; ||
        &apos;  ) &apos; ||
        &apos;) &apos; ||
        &apos; WHERE &apos;    ||
        &apos; 1 = 1 &apos;    ||
        FILTRU_DATA  ||
        FILTRU_SEDIU ||
        FILTRU_OBS   ||
        FILTRU_STARE ||
        FILTRU_NRDOC ||
        FILTRU_FACTURABIL ||
        FILTRU_NRI ||
        &apos; ORDER BY DATADOC&apos;  ;

  OPEN COMANDACURSOR FOR S;
  RETURN COMANDACURSOR;

END;

FUNCTION GET_COMENZI_CLIENT_INTERVAL (aCODPART IN NUMBER,  
                             DATASTART IN VARCHAR2,
                             DATAEND IN VARCHAR2,
                             aSEDIULIVRARE IN VARCHAR2,
                             aOBS IN VARCHAR2,
                             aSTARE IN VARCHAR2,
                             aNRDOC IN VARCHAR2,
                             aFACTURABIL   IN VARCHAR2,
                             aNRI          IN VARCHAR2
                            ) RETURN CMD_CURSOR
IS
  S   VARCHAR2(4000);
  COMANDACURSOR CMD_CURSOR;
  FILTRU_DATA1   VARCHAR2(500) := &apos;&apos;;
  FILTRU_DATA2  VARCHAR2(500) := &apos;&apos;;
  FILTRU_SEDIU  VARCHAR2(500) := &apos;&apos;;
  FILTRU_OBS    VARCHAR2(500) := &apos;&apos;;
  FILTRU_STARE  VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRDOC  VARCHAR2(500) := &apos;&apos;;
  FILTRU_FACTURABIL  VARCHAR2(500) := &apos;&apos;;
  FILTRU_NRI  VARCHAR2(500) := &apos;&apos;;
 BEGIN


  IF NVL(DATASTART, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATA1 := &apos; AND TO_DATE(DATADOC, &apos;&apos;DD-MM-YYYY&apos;&apos;) &gt;= TO_DATE(&apos;&apos;&apos; || DATASTART || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;
  
   IF NVL(DATAEND, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_DATA2 := &apos; AND TO_DATE(DATADOC, &apos;&apos;DD-MM-YYYY&apos;&apos;) &lt;= TO_DATE(&apos;&apos;&apos; || DATAEND || &apos;&apos;&apos;,&apos;&apos;DD-MM-YYYY&apos;&apos;) &apos;;
  END IF;

  IF NVL(aSEDIULIVRARE, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_SEDIU := &apos; AND UPPER(SEDIULIVRARE) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aSEDIULIVRARE) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aOBS, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_OBS := &apos; AND UPPER(OBS) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aOBS) || &apos;%&apos;&apos;&apos;;
  END IF;

  IF NVL(aSTARE, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_STARE := &apos; AND UPPER(STARECOMANDA) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aSTARE) || &apos;%&apos;&apos;&apos;;
	IF UPPER(aSTARE) = &apos;FIC&apos; THEN
		FILTRU_STARE := &apos; AND ( UPPER(STARECOMANDA) = &apos;&apos;NEFACTURATA&apos;&apos; OR UPPER(STARECOMANDA) = &apos;&apos;FACTURATA PARTIAL&apos;&apos; ) &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;ANULATA&apos; THEN
		FILTRU_STARE := &apos; AND ANULAT = 1 &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;INCHISA&apos; THEN
		FILTRU_STARE := &apos; AND INCHISA = 1 &apos;;
	END IF;
    IF UPPER(aSTARE) = &apos;TOATE&apos; THEN
		FILTRU_STARE := &apos;&apos;;
	END IF;
  END IF;

  IF NVL(aNRDOC, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRDOC := &apos; AND UPPER(NRDOC) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRDOC) || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aFACTURABIL, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_FACTURABIL := &apos; AND TO_CHAR(FACTURABIL) LIKE &apos; || &apos;&apos;&apos;%&apos; || aFACTURABIL || &apos;%&apos;&apos;&apos;;
  END IF;
  
  IF NVL(aNRI, &apos;?&apos;) &lt;&gt; &apos;?&apos; THEN
    FILTRU_NRI := &apos; AND UPPER(NRI) LIKE &apos; || &apos;&apos;&apos;%&apos; || UPPER(aNRI) || &apos;%&apos;&apos;&apos;;
  END IF;


   S := &apos;SELECT * FROM &apos; ||
        &apos;(SELECT &apos; ||
        &apos;   CODCOMANDA, &apos; ||
        &apos;   TIPDOC, &apos; ||
        &apos;   ANULAT, &apos; ||
        &apos;   BLOCAT, &apos; ||
        &apos;   OPERAT, &apos; ||
        &apos;   PREFIXDOC, &apos; ||
        &apos;   INCHISA, &apos; ||
        &apos;   NRDOC, &apos; ||
        &apos;   DATADOC, &apos; ||
        &apos;   NUMEAGENT, &apos; ||
        &apos;   DEN_LOCALIT, &apos; ||
        &apos;   to_char(DATACREARE, &apos;&apos;dd.mm.yyyy hh24:mi&apos;&apos;) DATACREARE, &apos; ||
        &apos;   VERIFICAT, &apos; ||
        &apos;   FACTURABIL, &apos; ||
        &apos;   NRI,  &apos; ||
        &apos;   SERIADOC, &apos; ||
        &apos;   PARTENER,&apos; ||
        &apos;   VALOARE, &apos; ||
        &apos;   AN, &apos; ||
        &apos;   LUNA,  &apos; ||
        &apos;   OBS, &apos; ||
        &apos;   MONEDA, &apos; ||
        &apos;   DEN_MONEDA, &apos; ||
        &apos;   DEN_PART, &apos; ||
        &apos;   SIMBOL, &apos; ||
        &apos;   SUBUNITATEDOC, &apos; ||
        &apos;   SEDIULIVRARE, &apos; ||
        &apos;   DELEGAT, &apos; ||
        &apos;    (  &apos; ||
        &apos;   CASE &apos; ||
        &apos;     WHEN ANULAT = 1 THEN &apos;&apos;ANULATA&apos;&apos; &apos; ||
        &apos;     WHEN INCHISA = 1 THEN &apos;&apos;INCHISA&apos;&apos; &apos; ||
        &apos;     WHEN FARAFACTURA = 1 THEN &apos;&apos;FARA FACTURARE&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT = 0 THEN &apos;&apos;NECONFIRMATA&apos;&apos; &apos; ||
        &apos;     WHEN CANTACCEPTAT =  RESTACCEPTAT THEN &apos;&apos;NEFACTURATA&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &lt;&gt; 0 AND CU_REST = 0 THEN &apos;&apos;FACTURATA INTEGRAL&apos;&apos;  &apos; ||
        &apos;     WHEN CANTACCEPTAT &gt; RESTACCEPTAT  THEN &apos;&apos;FACTURATA PARTIAL&apos;&apos; &apos; ||
        &apos;     ELSE &apos;&apos;&apos;&apos; &apos; ||
        &apos;   END &apos; ||
        &apos;    ) AS STARECOMANDA  &apos; ||
        &apos;   FROM  &apos; ||
        &apos;   ( &apos; ||
        &apos;  SELECT &apos; ||
        &apos;    c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC, C.INCHISA, C.DATACREARE, C.VERIFICAT, C.FACTURABIL, NVL(C.FARAFACTURA, 0) FARAFACTURA, C.NRI, C.LISTAT, C.SERIADOC,  &apos; ||
        &apos;    c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA, PER.NUME || &apos;&apos; &apos;&apos; || PER.PRENUME AS NUMEAGENT, L.DEN_LOCALIT,  &apos; ||
        &apos;    (SELECT DECODE(COUNT(*), 0, 0, 1) FROM DOCUMENTE D WHERE D.TIPDOC = C.TIPDOC AND D.CODDOC = C.CODCOMANDA) AS ATASAMENT,  &apos; ||
        &apos;    c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL, M.DEN_MONEDA, SUB.DEN_SUBUNIT AS SUBUNITATEDOC,  A.OBS AS SEDIULIVRARE, D.DELEGAT, &apos; ||
        &apos;    (SELECT NVL(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT, &apos; ||
        &apos;    (SELECT NVL(COUNT(*), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA AND NVL(CANTACCEPTAT, 0) &gt; 0 AND NVL(RESTACCEPTAT, 0) &gt; 0) AS CU_REST &apos; ||
        &apos;  FROM  &apos; ||
        &apos;     COMANDA c LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER  &apos; ||
        &apos;     LEFT OUTER JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA &apos; ||
        &apos;     LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA = C.CODLOCATIE &apos; ||
        &apos;     LEFT OUTER JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT &apos; ||
        &apos;     LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0) &apos; ||
        &apos;     LEFT OUTER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = C.SUBUNITATEA &apos; ||
        &apos;     LEFT OUTER JOIN NPERS PER ON PER.CODPERS = C.AGENT &apos; ||
        &apos;     LEFT OUTER JOIN NPARTTR D ON D.CODPARTTR = C.DELEGAT &apos; ||
        &apos;  WHERE &apos; ||
        &apos;     NVL(C.DISPLIVRARE,0) = 0 &apos; ||
        &apos;      AND C.TIPDOC =  18 &apos; ||
        &apos;      AND C.PARTENER = &apos; || TO_CHAR(aCODPART) ||
        &apos;      AND c.SUBUNITATEA =PKG_GLOBALS.GETSUBUNITATE &apos; ||
        &apos;  ) &apos; ||
        &apos;) &apos; ||
        &apos; WHERE &apos;    ||
        &apos; 1 = 1 &apos;    ||
        FILTRU_DATA1  ||
        FILTRU_DATA2  ||
        FILTRU_SEDIU ||
        FILTRU_OBS   ||
        FILTRU_STARE ||
        FILTRU_NRDOC ||
        FILTRU_FACTURABIL ||
        FILTRU_NRI ||
        &apos; ORDER BY DATADOC&apos;  ;

  OPEN COMANDACURSOR FOR S;
  RETURN COMANDACURSOR;

END;


FUNCTION GET_DETALII_COMANDA (aCODCOMANDA IN NUMBER) RETURN CMD1_CURSOR
IS
  S              VARCHAR2(4000);
  COMANDA1CURSOR CMD1_CURSOR;
BEGIN
  S := &apos; SELECT
		   C1.CODOBIECT,
           O.DENUMIRE,
           U1.DEN_UM1,
           C1.PU,
           C1.CANTCOMANDAT,
           C1.CANTACCEPTAT ,
           C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT,
           C1.OBS,
		   C1.TERMEN,
           C1.D1,
           C1.D2,
           C1.D3,
           C1.ACCEPTUM1,
           C1.CANTUM1,
           C1.PROCDISC,
           O.CODEXTERN,
           O.CODINTERN
        FROM
          COMANDA1 C1,
          NARTOBJ O,
          NUM1 U1,
          COMANDA C
        WHERE
          C1.CODCOMANDA = &apos; || TO_CHAR(aCODCOMANDA) || &apos;
          AND C.CODCOMANDA = C1.CODCOMANDA
          AND C1.UMSEC = U1.CODUM1
          AND O.CODOBIECT = C1.CODOBIECT&apos;;
  OPEN COMANDA1CURSOR FOR S;
  RETURN COMANDA1CURSOR;


END;

FUNCTION GET_PRET_OFERTA(aCODPART   IN NUMBER,
                         aCODMONEDA IN NUMBER,
                         aCODOBIECT IN NUMBER)
RETURN PRETOFERTA_CURSOR
IS
  S              VARCHAR2(4000);
 aPRETOFERTA_CURSOR PRETOFERTA_CURSOR;
BEGIN
   S := &apos;SELECT PRET, SIMBOL, NrDoc, DATAOFERTA, DATASTART, DATAEND, CANTMIN, ZILEL, ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS
    FROM
      OFERTA O,
      OFERTA1 O1,
      NMONEDE M
    WHERE O1.CODOBIECT = &apos; || TO_CHAR(aCODOBIECT) ||&apos;
      AND O.CODOFERTA = O1.CODOFERTA
      AND O.TIPDOC = 50
      AND O.OPERAT = 1
      AND O.ANULAT = 0
      AND M.CODMONEDA = O.MONEDA
      AND O.MONEDA = &apos; || TO_CHAR(aCODMONEDA) ||&apos;
      AND O.DATASTART &lt;= SYSDATE
      AND O.DATAEND &gt;= SysDate
      AND (PARTENER = &apos;|| TO_CHAR(aCODPART) ||&apos;  OR NVL(PARTENER, 0) = 0)
    ORDER BY NrDoc&apos;;


  OPEN aPRETOFERTA_CURSOR FOR S;
  RETURN aPRETOFERTA_CURSOR;

END;

FUNCTION GET_PRET_OFERTA_AGENT(aCODPART   IN NUMBER,
                               aCODMONEDA IN NUMBER,
                               aCODOBIECT IN NUMBER,
                               aCODPERS IN NUMBER
                              )
         RETURN PRETOFERTA_CURSOR
IS
  S              VARCHAR2(4000);
 aPRETOFERTA_CURSOR PRETOFERTA_CURSOR;
BEGIN
   S := &apos;SELECT PRET, SIMBOL, NrDoc, DATAOFERTA, DATASTART, DATAEND, CANTMIN, ZILEL, ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS, CODMONEDA, O1.CODOFERTA1
    FROM
      OFERTA O,
      OFERTA1 O1,
      NMONEDE M
    WHERE O1.CODOBIECT = &apos; || TO_CHAR(aCODOBIECT) ||&apos;
      AND O.CODOFERTA = O1.CODOFERTA
      AND O.TIPDOC = 50
      AND O.OPERAT = 1
      AND O.ANULAT = 0
      AND M.CODMONEDA = O.MONEDA
      AND O.MONEDA = &apos; || TO_CHAR(aCODMONEDA) ||&apos;
      AND O.DATASTART &lt;= SYSDATE
      AND O.DATAEND &gt;= SysDate
      AND (PARTENER = &apos;|| TO_CHAR(aCODPART) ||&apos;  OR NVL(PARTENER, 0) = 0)
      AND (O.AGENT = &apos; ||  TO_CHAR(aCODPERS) || &apos; OR O.AGENT = 0)
    ORDER BY NrDoc&apos;;


  OPEN aPRETOFERTA_CURSOR FOR S;
  RETURN aPRETOFERTA_CURSOR;

END;

FUNCTION GET_PRET_OFERTA_AGENT_VALUTA(aCODPART   IN NUMBER,
                               aCODOBIECT IN NUMBER,
                               aCODPERS IN NUMBER
                              )
         RETURN PRETOFERTA_CURSOR
IS
  S              VARCHAR2(4000);
 aPRETOFERTA_CURSOR PRETOFERTA_CURSOR;
BEGIN
   S := &apos;SELECT PRET, SIMBOL, NrDoc, DATAOFERTA, DATASTART, DATAEND, CANTMIN, ZILEL, ZILEC, PROCDISCOUNT, O1.OBS, O1.PROCADAOS, CODMONEDA, O1.CODOFERTA1
    FROM
      OFERTA O,
      OFERTA1 O1,
      NMONEDE M
    WHERE O1.CODOBIECT = &apos; || TO_CHAR(aCODOBIECT) ||&apos;
      AND O.CODOFERTA = O1.CODOFERTA
      AND O.TIPDOC = 50
      AND O.OPERAT = 1
      AND O.ANULAT = 0
      AND M.CODMONEDA = O.MONEDA
      AND O.DATASTART &lt;= SYSDATE
      AND O.DATAEND &gt;= SysDate
      AND (PARTENER = &apos;|| TO_CHAR(aCODPART) ||&apos;  OR NVL(PARTENER, 0) = 0 OR CODCLASEP = (SELECT CODCLASA FROM NPART WHERE CODPART = &apos;|| TO_CHAR(aCODPART) ||&apos;)  )
      AND (O.AGENT = &apos; ||  TO_CHAR(aCODPERS) || &apos; OR NVL(O.AGENT, 0) = 0)
    ORDER BY NrDoc&apos;;


  OPEN aPRETOFERTA_CURSOR FOR S;
  RETURN aPRETOFERTA_CURSOR;

END;

FUNCTION GET_DETALII_OFERTA (aCODOFERTA IN NUMBER) RETURN OFERTA1_CURSOR
IS
  S              VARCHAR2(4000);
  OFERTA1CURSOR OFERTA1_CURSOR;
BEGIN
  S := &apos; SELECT
           O1.CODOFERTA1, N.DENUMIRE, O1.PRET, O1.CANTMIN, O1.ZILEL, O1.ZILEC, O1.PROCDISCOUNT, O1.OBS, O1.CODOBIECT, N.CODARTICOL, U1.DEN_UM1, O1.CODOFERTA, O1.UMSEC, O1.PROCADAOS, O1.D1, O1.D2, O1.D3, O1.INDEXLOCAL, O1.PRETREF,
           N.CODEXTERN, N.CODINTERN
        FROM
          OFERTA1 O1,
          NARTOBJ N,
          NUM1 U1, OFERTA O
        WHERE
          O1.CODOFERTA = &apos; || TO_CHAR(aCODOFERTA) || &apos;
          AND O.CODOFERTA = O1.CODOFERTA
          AND O1.UMSEC = U1.CODUM1
          AND O1.CODOBIECT = N.CODOBIECT
        ORDER BY O1.INDEXLOCAL  
          &apos;;
  OPEN OFERTA1CURSOR FOR S;
  RETURN OFERTA1CURSOR;


END;

FUNCTION GET_DETALII_OFERTA_TVA (aCODOFERTA IN NUMBER, aToggleVAT IN NUMBER) RETURN OFERTA2_CURSOR
IS
  S              VARCHAR2(4000);
  AN           NUMBER(5);
  LUNA         NUMBER(2);
  COMPUTE_VAT   VARCHAR2(1000) := &apos; NVL(O1.PRET, 0) &apos;;
  OFERTA2CURSOR OFERTA2_CURSOR;
BEGIN
  AN   := EXTRACT(YEAR FROM SYSDATE);
  LUNA := EXTRACT(MONTH FROM SYSDATE);
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(AN, Luna);
  PKG_STOC_GENERARE_FACTURI.make_config_luna_EXT;
  
  IF NVL(aToggleVAT, 0) = 1 THEN
    COMPUTE_VAT := &apos; ROUND(NVL(O1.PRET, 0) * (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;
  
    S := &apos; SELECT distinct
           O1.CODOFERTA1, N.DENUMIRE, O1.PRET, NVL(TVAL.PROCENT, 0) AS TVA, &apos; || COMPUTE_VAT || &apos; AS PRET_TVA , O1.CANTMIN, O1.ZILEL, O1.ZILEC, O1.PROCDISCOUNT, O1.OBS, O1.CODOBIECT, N.CODARTICOL, U1.DEN_UM1, O1.CODOFERTA, O1.UMSEC, O1.PROCADAOS, O1.D1, O1.D2, O1.D3, O1.INDEXLOCAL, O1.PRETREF,
           NART.CODEXTERNART||NART.SUFIXCODEXTERN AS CODCATALOG, N.CODEXTERN, N.CODINTERN
        FROM
          OFERTA1 O1,
          NUM1 U1,
          NART,
         NARTOBJ N
          LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = N.CODARTICOL  
          LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA 
        WHERE
          O1.CODOFERTA = &apos; || TO_CHAR(aCODOFERTA) || &apos;
          AND O1.UMSEC = U1.CODUM1
          AND O1.CODOBIECT = N.CODOBIECT
          AND N.CODARTICOL = NART.CODARTICOL
        ORDER BY O1.INDEXLOCAL  
          &apos;;
  OPEN OFERTA2CURSOR FOR S;
  RETURN OFERTA2CURSOR;


END;

FUNCTION GET_DETALII_COMANDA_TVA (aCODCOMANDA IN NUMBER, aToggleVAT IN NUMBER) RETURN CMD2_CURSOR
IS
  S              VARCHAR2(4000);
  AN           NUMBER(5);
  LUNA         NUMBER(2);
  COMPUTE_VAT   VARCHAR2(1000) := &apos; NVL(C1.PU, 0) &apos;;
  COMANDA2CURSOR CMD2_CURSOR;
BEGIN
  AN   := EXTRACT(YEAR FROM SYSDATE);
  LUNA := EXTRACT(MONTH FROM SYSDATE);
  PKG_GLOBALS.SETLUNALUCRU_SIMPLA(AN, Luna);
  PKG_STOC_GENERARE_FACTURI.make_config_luna_EXT;
  
  IF NVL(aToggleVAT, 0) = 1 THEN
    COMPUTE_VAT := &apos; ROUND(NVL(C1.PU, 0) * (1 + NVL(TVAL.PROCENT, 0) / 100), 2) &apos;;
  END IF;

  S := &apos; SELECT distinct
		   C1.CODOBIECT,
           O.DENUMIRE,
           U1.DEN_UM1,
		   O.CODEXTERN,
		   O.CODINTERN,
		   N.CODEXTERNART||N.SUFIXCODEXTERN AS CODCATALOG,
           C1.PU,
		   NVL(TVAL.PROCENT, 0) AS TVA, &apos; || COMPUTE_VAT || &apos; AS PRET_TVA,
           C1.CANTCOMANDAT,
           C1.CANTACCEPTAT ,
           C1.CANTACCEPTAT - C1.RESTACCEPTAT AS FACTURAT,
           C1.OBS,
		   C1.TERMEN,
           C1.D1,
           C1.D2,
           C1.D3,
           C1.ACCEPTUM1,
           C1.CANTUM1,
           C1.PRETORIG,
           C1.PROCDISC,
           C1.ADDIM
        FROM
          COMANDA1 C1,
          NUM1 U1,
		  NART N,
          NARTOBJ O
          LEFT OUTER JOIN TMP_NART_LUNA NAL  ON NAL.CODARTICOL = O.CODARTICOL  
          LEFT OUTER JOIN TMP_NTVA_LUNA TVAL ON TVAL.CODTVA = NAL.CODTVA
        WHERE
          C1.CODCOMANDA = &apos; || TO_CHAR(aCODCOMANDA) || &apos;
          AND C1.UMSEC = U1.CODUM1
		  AND O.CODARTICOL = N.CODARTICOL
          AND O.CODOBIECT = C1.CODOBIECT&apos;;
  OPEN COMANDA2CURSOR FOR S;
  RETURN COMANDA2CURSOR;
END;

procedure SetRecordCmdProdMat (aCodObiect in number, aCodComanda1 in number, aCant in number, aCodCmdProdMat out number) is
aCod number(20);
aIndexLocal number(10);
begin
  begin
    select codcmdprodmat into aCodCmdProdMat from cmdprodmat where codcomanda1 = aCodComanda1 and codobiect = aCodObiect;
  exception when others then aCodCmdProdMat := 0;
  end;
  if aCodCmdProdMat &gt; 0 then
    update cmdprodmat set cant = coalesce(cant,0) + aCant where codcmdprodmat = aCodCmdProdMat;
  else  
    begin
      select max(indexlocal) + 1 into aIndexLocal from cmdprodmat where codcomanda1 = acodcomanda1;
    exception when others then aIndexLocal := 1;
    end;
      
    select seq_cmdprodmat_codcmdprodmat.nextval into aCodCmdProdMat from dual;
    insert into cmdprodmat (codcmdprodmat,
                            codcomanda1,
                            codobiect,
                            cant,
                            pret,
                            rest,
                            tip,
                            indexlocal)
    values (aCodCmdProdMat, aCodComanda1, aCodObiect, aCant, 0, 0, 1, aIndexLocal);                        
  end if;
end;  

end PKG_WMEONLINE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PACKAGE BODY</TYPE>
  <NAME>PKG_ZINELUC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A26813FBB05D452EDE7B8EEB1EF3F9C116E27705</HASHVAL>
  <TEXT>CREATE OR REPLACE PACKAGE BODY PKG_ZINELUC IS

PROCEDURE SP_LOCKRECORD( RecId IN NUMBER ) IS
  Tmp NUMBER(20);
BEGIN
  SELECT CodZiNeluc INTO Tmp FROM ZINELUC WHERE CodZiNeluc = RecId FOR UPDATE NOWAIT;
END;

PROCEDURE SP_DELETERECORD( RecId IN NUMBER ) IS
BEGIN
  SP_LOCKRECORD(RecId);
  DELETE FROM ZINELUC1 WHERE CodZiNeluc = RecId ;
  DELETE FROM ZINELUC  WHERE CodZiNeluc = RecId ;
  NotifyModif(2, RecId, &apos;ZINELUC&apos;);
  COMMIT;
END;

PROCEDURE SP_INSERTRECORD IS
BEGIN
  INSERT INTO TMP_ZINELUC FIELDS(CodZiNeluc) VALUES (0) ;
  COMMIT;
END;

PROCEDURE SP_GOTORECORD( RecId IN NUMBER ) IS
BEGIN
  INSERT INTO TMP_ZINELUC (CodZiNeluc, An, Luna, AnCal, LunaCal)
  SELECT CodZiNeluc, PKG_GLOBALS.GetAnLucru, PKG_GLOBALS.GetLunaLucru, An, Luna
  FROM ZINELUC
  WHERE CodZiNeluc = RecId;


  INSERT INTO TMP_ZINELUC1 (CodZiNeluc1, CodZiNeluc, Zi, Data)
  SELECT CodZiNeluc1, CodZiNeluc, Zi, Data
  FROM ZINELUC1
  WHERE CodZiNeluc = RecId;

  COMMIT;
END;

PROCEDURE SP_POSTRECORDS(Operation IN NUMBER, RecId OUT NUMBER ) IS
  dAnLuna DATE;
  ZiMax   INTEGER;
BEGIN
  SELECT To_Date(AnCal||&apos;.&apos;||LunaCal,&apos;yyyy.mm&apos;) -1 INTO dAnLuna FROM TMP_ZINELUC;
  ZiMax := To_Char(Last_Day(dAnLuna + 1),&apos;DD&apos;);
  DELETE TMP_ZINELUC1 WHERE Zi &gt; ZiMax;
  UPDATE TMP_ZINELUC1 SET DATA = dAnLuna + ZI;

  IF Operation = 0 THEN  -- UPDATE                     
    SELECT  CodZiNeluc INTO RecId FROM TMP_ZINELUC;

    UPDATE ZINELUC
    SET ( An, Luna ) =( SELECT AnCal, LunaCal FROM TMP_ZINELUC)
    WHERE CodZiNeluc = RecId ;

    DELETE FROM ZINELUC1 LC1 WHERE LC1.CodZiNeluc = RecId AND Zi NOT IN (SELECT Zi FROM TMP_ZINELUC1);
    DELETE FROM TMP_ZINELUC1 WHERE Zi IN (SELECT Zi FROM ZINELUC1 WHERE CodZiNeluc = RecId);
    UPDATE ZINELUC1 SET DATA = dAnLuna + ZI WHERE CodZiNeluc = RecId AND DATA IS NULL;

    INSERT INTO ZINELUC1 (CodZiNeluc1, CodZiNeluc, Zi, Data)
    SELECT SEQ_ZINELUC1_CodZiNeluc1.Nextval, RecId, Zi, Data
    FROM (SELECT DISTINCT ZI, DATA FROM TMP_ZINELUC1);
  ELSE
    SELECT Seq_ZINELUC_CodZiNeluc.NextVal INTO RecId FROM DUAL;

    INSERT INTO ZINELUC (CodZiNeluc, An, Luna, UserID, DataCreare)
    SELECT RecId, AnCal, LunaCal, Pkg_Globals.UserId, SysTimeStamp
    FROM TMP_ZINELUC;

    INSERT INTO ZINELUC1 (CodZiNeluc1, CodZiNeluc, Zi, Data)
    SELECT SEQ_ZINELUC1_CodZiNeluc1.Nextval, RecId, Zi, Data
    FROM (SELECT DISTINCT ZI, DATA FROM TMP_ZINELUC1);
  END IF;
  NotifyModif(Operation, RecId, &apos;ZINELUC&apos;);
  COMMIT;
END;

FUNCTION GET_DATAFIN( vDataStart IN DATE, vZile IN NUMBER) RETURN DATE IS
  vDataFin DATE;
  vDataAux DATE;
  vZileAux INTEGER := Ceil(vZile);
BEGIN
  vDataAux := vDataStart;
  vDataFin := vDataStart + vZileAux;
  LOOP
    SELECT Count(1) INTO vZileAux FROM ZiNeluc1 WHERE DATA BETWEEN vDataAux AND vDataFin;
    vDataAux := vDataFin + 1;
    vDataFin := vDataFin + vZileAux;
    EXIT WHEN vDataAux &gt; vDataFin;
  END LOOP;

  RETURN (vDataFin);
END;

FUNCTION GET_DATAFIN_STRING( vDataStart IN VARCHAR2, vZile IN NUMBER) RETURN VARCHAR2 IS
  vData DATE := To_Date(vDataStart,&apos;dd.mm.yyyy&apos;);
BEGIN
  vData := PKG_ZINELUC.GET_DATAFIN(vData, vZile);
  RETURN To_Char(vdata,&apos;dd.mm.yyyy&apos;);
END;


end pkg_ZINELUC; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>BIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>474B34ACC9EF50A2361F516F2894AF8BCDE59052</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE BIV IS
  sSQL varchar2(22000);
BEGIN
  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_ARTICOLE AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
         CAST (O.CodObiect AS VARCHAR(32)) CodObiect, O.CODINTERN, O.CODEXTERN, O.DENUMIRE Articol, A.tiparticol, CA.Den_ClaseA DenClasaArt, CA.simbol simbclasaart,
         U.Den_UM UM, U1.Den_UM UM1, U2.Den_UM UM2, Trunc(SYSDATE) datasystem
       FROM &apos;||v_rec.Skema||&apos;.NARTOBJ O
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NART A ON A.CODARTICOL = O.CODARTICOL
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U ON U.CODUM = A.UM
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U1 ON U1.CODUM = A.UM1
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U2 ON U2.CODUM = A.UM2
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NCLASEA CA ON CA.CODCLASEA = A.CLASA&apos;;
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
         CAST (O.CodObiect AS VARCHAR(32)) CodObiect, O.CODINTERN, O.CODEXTERN, O.DENUMIRE Articol, A.tiparticol, CA.Den_ClaseA DenClasaArt, CA.simbol simbclasaart,
         U.Den_UM UM, U1.Den_UM UM1, U2.Den_UM UM2, Trunc(SYSDATE) datasystem
       FROM &apos;||v_rec.Skema||&apos;.NARTOBJ O
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NART A ON A.CODARTICOL = O.CODARTICOL
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U ON U.CODUM = A.UM
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U1 ON U1.CODUM = A.UM1
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U2 ON U2.CODUM = A.UM2
         LEFT JOIN &apos;||v_rec.Skema||&apos;.NCLASEA CA ON CA.CODCLASEA = A.CLASA&apos;;
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_COMENZI (
     numedoc, coddoc, tipdoc, prefixdoc, nrdoc, datadoc, moneda, curs, partener, codpart,
     codgest, cudsubunit, codobiect, denobiect, denum, cantcomandat, cantacceptat,
     restacceptat, pu, indexdoc, datasystem, anluna
   ) AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
     &apos;SELECT
        XM.NUMEPRESC NUMEDOC,
        C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.NRDOC, C.DATADOC, Mon.SIMBOL MONEDA, Round(C.CURS,4) Curs,
        DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part) Partener, NP.CodPart, NG.CodGest, NS.CodSubunit,
        C1.CodObiect, nobj.denumire denobiect, num1.den_um1 denum,
        c1.cantcomandat/num1.paritate cantcomandat, c1.cantacceptat/num1.paritate cantacceptat, c1.restacceptat/num1.paritate restacceptat, c1.pu*num1.paritate pu,
        C1.IndexLocal IndexDoc, Trunc(SYSDATE) datasystem, c.an*100+c.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.comanda c
        LEFT JOIN &apos;||v_rec.Skema||&apos;.comanda1 c1 ON c.codcomanda = c1.codcomanda
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = c.tipdoc
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nmonede mon ON mon.codmoneda = c.moneda
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nartobj nobj ON nobj.codobiect = c1.codobiect
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nart art ON nobj.codarticol = art.codarticol
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nartobjsubunit nobjs ON nobjs.codobiect = nobj.codobiect AND nobjs.subunitate = DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.num1 ON num1.codum1 = c1.umsec
        LEFT JOIN &apos;||v_rec.Skema||&apos;.num us ON us.codum = art.um1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.npers ag on c.agent = ag.codpers
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nclasea cla on art.clasa = cla.codclasea
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nclaseas cs on art.clasastatist = cs.codclaseas
        LEFT JOIN &apos;||v_rec.Skema||&apos;.npart np ON np.codpart = c.partener
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest ng ON ng.codgest = c.codgest
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nsubunit ns ON ns.codsubunit = c.subunitatea
        LEFT JOIN &apos;||v_rec.Skema||&apos;.nsubunit s On s.codsubunit = c.subunitatea
      WHERE c.anulat = 0 AND c.operat = 1&apos;;
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
         XM.NUMEPRESC NUMEDOC,
         C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.NRDOC, C.DATADOC, Mon.SIMBOL MONEDA, Round(C.CURS,4) Curs,
         DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part) Partener, NP.CodPart, NG.CodGest, NS.CodSubunit,
         C1.CodObiect, nobj.denumire denobiect, num1.den_um1 denum,
         c1.cantcomandat/num1.paritate cantcomandat, c1.cantacceptat/num1.paritate cantacceptat, c1.restacceptat/num1.paritate restacceptat, c1.pu*num1.paritate pu,
         C1.IndexLocal IndexDoc, Trunc(SYSDATE) datasystem, c.an*100+c.luna AnLuna
       FROM &apos;||v_rec.Skema||&apos;.comanda c
         LEFT JOIN &apos;||v_rec.Skema||&apos;.comanda1 c1 ON c.codcomanda = c1.codcomanda
         LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = c.tipdoc
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nmonede mon ON mon.codmoneda = c.moneda
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nartobj nobj ON nobj.codobiect = c1.codobiect
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nart art ON nobj.codarticol = art.codarticol
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nartobjsubunit nobjs ON nobjs.codobiect = nobj.codobiect AND nobjs.subunitate = DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)
         LEFT JOIN &apos;||v_rec.Skema||&apos;.num1 ON num1.codum1 = c1.umsec
         LEFT JOIN &apos;||v_rec.Skema||&apos;.num us ON us.codum = art.um1
         LEFT JOIN &apos;||v_rec.Skema||&apos;.npers ag on c.agent = ag.codpers
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nclasea cla on art.clasa = cla.codclasea
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nclaseas cs on art.clasastatist = cs.codclaseas
         LEFT JOIN &apos;||v_rec.Skema||&apos;.npart np ON np.codpart = c.partener
         LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest ng ON ng.codgest = c.codgest
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nsubunit ns ON ns.codsubunit = c.subunitatea
         LEFT JOIN &apos;||v_rec.Skema||&apos;.nsubunit s On s.codsubunit = c.subunitatea
       WHERE c.anulat = 0 AND c.operat = 1&apos;;
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;


  sSQL :=&apos;CREATE OR REPLACE VIEW V_BI_IESIRI AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, Trunc(vc.vechime) VECHIMECLIENT,
        CAST(I1.CODOBIECT AS VARCHAR(32)) CODOBIECT,
        Round(I1.CANT*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT),4) Cant,
        Round(I1.Pretorig,4) PretOrig, Round(I1.PU,4) PU,
        Round(PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret),4) PretFinal,
        Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT) END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODLIVR1, CAST(AE1.CODIES  AS VARCHAR(32)) CODAE, CAST(AE1.CODIES1  AS VARCHAR(32)) CODAE1, CAST(L1.NRLIVR AS VARCHAR(32)) NRLIVR,
        CASE WHEN L1.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L1.DATALIVR ELSE NULL END DATALIVR,
        llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume agent,
        Round(CASE WHEN L1.PretAchizOrig IS NOT NULL THEN L1.PretAchizOrig WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchizOrig,
        Round(CASE WHEN L1.PretAchiz     IS NOT NULL THEN L1.PretAchiz     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchiz,
        Round(CASE WHEN L1.PretInreg     IS NOT NULL THEN L1.PretInreg     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretInreg,
        L1.DATAACHIZ, F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor,
        G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, c1.termen TermenLivr,
        Trunc(SYSDATE) datasystem,
        ioa.mg,
        i.an*100+i.luna AnLuna,
        CREF.CURS CURSSITV
      FROM &apos;||v_rec.Skema||&apos;.IESIRI1 I1
        INNER JOIN &apos;||v_rec.Skema||&apos;.IESIRI I ON I.CODIES  = I1.CODIES
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(I.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESLINK ILAE ON ILAE.CODIES1 = I1.CODIES1 AND I.TIPDOC = 26 AND ILAE.CODLINIEAVIZ IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI1 AE1 ON AE1.CODIES1 = ILAE.CODLINIEAVIZ
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI AE ON AE.CODIES = AE1.CODIES
        LEFT JOIN (
          SELECT
            l1.codlivr1, l1.codlivr, l1.codies1, l1.cant, l.nrlivr, l.datalivr,
            CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
            CASE WHEN nso.codnirstoc IS NOT NULL THEN Nvl(nso.pret-nso.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretachiz,0) ELSE NULL END PretAchizOrig,
            CASE WHEN ns.codnirstoc  IS NOT NULL THEN Nvl(ns.pret - ns.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretachiz,0) ELSE NULL END PretAchiz,
            CASE WHEN ns.codnirstoc  IS NOT NULL THEN Nvl(ns.pret,0)            WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretinreg,0) ELSE NULL END PretInreg,
            Ns.furn,
            Coalesce(LV.GEST, N.GEST, 0) gest,
            NS.CODLOCATIE,
            COALESCE(lv.codioart, ns.codioart,0) codioart
          FROM &apos;||v_rec.Skema||&apos;.Livr1 L1
            INNER JOIN &apos;||v_rec.Skema||&apos;.livr l ON l.codlivr = l1.codlivr
            INNER JOIN &apos;||v_rec.Skema||&apos;.iesiri i ON l.codies = i.codies AND l.tiplivr = i.tipdoc
            LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        ) L1 ON l1.codies1 = Coalesce(ae1.codies1, i1.codies1)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = I.PARTENER
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = L1.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = L1.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = L1.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AG ON AG.CODPERS  = I.AGENT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NAGENDA slivr ON slivr.codagenda = i.codlocatie
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCALIT llivr ON llivr.codlocalit = slivr.codlocalit
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NJUDET jlivr ON jlivr.codjudet = llivr.codjudet
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = COALESCE(ae1.codioartcust,l1.codioart)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 IOA1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON nc.codcont = Nvl(ioa.cont, i1.cont)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESLINK ILC ON ILC.CODIES1 = Nvl(AE1.CODIES1, I1.CODIES1) AND ILC.CODLINIECOMANDA IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
        LEFT JOIN (SELECT partener, Min(datadoc) vechime FROM &apos;||v_rec.Skema||&apos;.iesiri  WHERE partener IS not null AND datadoc BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY partener) vc ON vc.partener = i.partener
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime   FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = l1.furn
        LEFT JOIN (
          SELECT
            CASE WHEN N1.DATA = Min(N1.DATA) OVER (ORDER BY N1.DATA) THEN To_Date(&apos;&apos;00010101&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;) ELSE N1.DATA END DATASTART,
            Coalesce(LEAD(N1.DATA) OVER (ORDER BY N1.DATA) - 1,To_Date(&apos;&apos;25001231&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)) DATASTOP,
            N1.VALOARE CURS
          FROM (
            SELECT
              Max (CASE WHEN SIMB = &apos;&apos;BANCASITV&apos;&apos;  THEN To_Number(Valoare) ELSE 0 END) Codbanca,
              Max (CASE WHEN SIMB = &apos;&apos;MONEDASITV&apos;&apos; THEN To_Number(Valoare) ELSE 0 END) CodMoneda
            FROM (
              SELECT
                UPPER(C1.simbol) SIMB,
                Max(CL.CODCONSTLUNA) KEEP (Dense_Rank LAST ORDER BY ANSTART, LUNASTART) CODCONSTLUNA
              FROM &apos;||v_rec.Skema||&apos;.CONST1 C1
                INNER JOIN &apos;||v_rec.Skema||&apos;.CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
                INNER JOIN &apos;||v_rec.Skema||&apos;.CONSTLUNA CL ON CL.codconst1 = C1.codConst1
              WHERE UPPER(C1.simbol) IN (&apos;&apos;BANCASITV&apos;&apos;, &apos;&apos;MONEDASITV&apos;&apos;)
                AND CL.USERID = 0
              GROUP BY UPPER(C1.simbol)
            ) CL LEFT JOIN &apos;||v_rec.Skema||&apos;.CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
          ) TMP INNER JOIN &apos;||v_rec.Skema||&apos;.NMONEDE1 N1 ON N1.Codbanca = TMP.CodBanca AND N1.CodMoneda = TMP.CodMoneda
        ) CREF ON CREF.DATASTART &lt;= I.DATADOC AND CREF.DATASTOP &gt;= I.DATADOC
      WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)
        AND I.TIPDOC NOT IN (14,15)&apos;||CHR(13);
  ELSE
    sSQL := sSQL||
    &apos;UNION ALL
     SELECT
        XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, Trunc(vc.vechime) VECHIMECLIENT,
        CAST(I1.CODOBIECT AS VARCHAR(32)) CODOBIECT,
        Round(I1.CANT*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT),4) Cant,
        Round(I1.Pretorig,4) PretOrig, Round(I1.PU,4) PU,
        Round(PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret),4) PretFinal,
        Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT) END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODLIVR1, CAST(AE1.CODIES  AS VARCHAR(32)) CODAE, CAST(AE1.CODIES1  AS VARCHAR(32)) CODAE1, CAST(L1.NRLIVR AS VARCHAR(32)) NRLIVR,
        CASE WHEN L1.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L1.DATALIVR ELSE NULL END DATALIVR,
        llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume agent,
        Round(CASE WHEN L1.PretAchizOrig IS NOT NULL THEN L1.PretAchizOrig WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchizOrig,
        Round(CASE WHEN L1.PretAchiz     IS NOT NULL THEN L1.PretAchiz     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchiz,
        Round(CASE WHEN L1.PretInreg     IS NOT NULL THEN L1.PretInreg     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretInreg,
        L1.DATAACHIZ, F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor,
        G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, c1.termen TermenLivr,
        Trunc(SYSDATE) datasystem,
        ioa.mg,
        i.an*100+i.luna AnLuna,
        CREF.CURS CURSSITV
      FROM &apos;||v_rec.Skema||&apos;.IESIRI1 I1
        INNER JOIN &apos;||v_rec.Skema||&apos;.IESIRI I ON I.CODIES  = I1.CODIES
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(I.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESLINK ILAE ON ILAE.CODIES1 = I1.CODIES1 AND I.TIPDOC = 26 AND ILAE.CODLINIEAVIZ IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI1 AE1 ON AE1.CODIES1 = ILAE.CODLINIEAVIZ
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI AE ON AE.CODIES = AE1.CODIES
        LEFT JOIN (
          SELECT
            l1.codlivr1, l1.codlivr, l1.codies1, l1.cant, l.nrlivr, l.datalivr,
            CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
            CASE WHEN nso.codnirstoc IS NOT NULL THEN Nvl(nso.pret-nso.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretachiz,0) ELSE NULL END PretAchizOrig,
            CASE WHEN ns.codnirstoc  IS NOT NULL THEN Nvl(ns.pret - ns.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretachiz,0) ELSE NULL END PretAchiz,
            CASE WHEN ns.codnirstoc  IS NOT NULL THEN Nvl(ns.pret,0)            WHEN lv.codlivrval IS NOT NULL THEN Nvl(lv.pretinreg,0) ELSE NULL END PretInreg,
            Ns.furn,
            Coalesce(LV.GEST, N.GEST, 0) gest,
            NS.CODLOCATIE,
            COALESCE(lv.codioart, ns.codioart,0) codioart
          FROM &apos;||v_rec.Skema||&apos;.Livr1 L1
            INNER JOIN &apos;||v_rec.Skema||&apos;.livr l ON l.codlivr = l1.codlivr
            INNER JOIN &apos;||v_rec.Skema||&apos;.iesiri i ON l.codies = i.codies AND l.tiplivr = i.tipdoc
            LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
            LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        ) L1 ON l1.codies1 = Coalesce(ae1.codies1, i1.codies1)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = I.PARTENER
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = L1.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = L1.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = L1.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AG ON AG.CODPERS  = I.AGENT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NAGENDA slivr ON slivr.codagenda = i.codlocatie
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCALIT llivr ON llivr.codlocalit = slivr.codlocalit
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NJUDET jlivr ON jlivr.codjudet = llivr.codjudet
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = COALESCE(ae1.codioartcust,l1.codioart)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 IOA1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON nc.codcont = Nvl(ioa.cont, i1.cont)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESLINK ILC ON ILC.CODIES1 = Nvl(AE1.CODIES1, I1.CODIES1) AND ILC.CODLINIECOMANDA IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
        LEFT JOIN (SELECT partener, Min(datadoc) vechime FROM &apos;||v_rec.Skema||&apos;.iesiri  WHERE partener IS not null AND datadoc BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY partener) vc ON vc.partener = i.partener
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime   FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = l1.furn
        LEFT JOIN (
          SELECT
            CASE WHEN N1.DATA = Min(N1.DATA) OVER (ORDER BY N1.DATA) THEN To_Date(&apos;&apos;00010101&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;) ELSE N1.DATA END DATASTART,
            Coalesce(LEAD(N1.DATA) OVER (ORDER BY N1.DATA) - 1,To_Date(&apos;&apos;25001231&apos;&apos;,&apos;&apos;YYYYMMDD&apos;&apos;)) DATASTOP,
            N1.VALOARE CURS
          FROM (
            SELECT
              Max (CASE WHEN SIMB = &apos;&apos;BANCASITV&apos;&apos;  THEN To_Number(Valoare) ELSE 0 END) Codbanca,
              Max (CASE WHEN SIMB = &apos;&apos;MONEDASITV&apos;&apos; THEN To_Number(Valoare) ELSE 0 END) CodMoneda
            FROM (
              SELECT
                UPPER(C1.simbol) SIMB,
                Max(CL.CODCONSTLUNA) KEEP (Dense_Rank LAST ORDER BY ANSTART, LUNASTART) CODCONSTLUNA
              FROM &apos;||v_rec.Skema||&apos;.CONST1 C1
                INNER JOIN &apos;||v_rec.Skema||&apos;.CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
                INNER JOIN &apos;||v_rec.Skema||&apos;.CONSTLUNA CL ON CL.codconst1 = C1.codConst1
              WHERE UPPER(C1.simbol) IN (&apos;&apos;BANCASITV&apos;&apos;, &apos;&apos;MONEDASITV&apos;&apos;)
                AND CL.USERID = 0
              GROUP BY UPPER(C1.simbol)
            ) CL LEFT JOIN &apos;||v_rec.Skema||&apos;.CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
          ) TMP INNER JOIN &apos;||v_rec.Skema||&apos;.NMONEDE1 N1 ON N1.Codbanca = TMP.CodBanca AND N1.CodMoneda = TMP.CodMoneda
        ) CREF ON CREF.DATASTART &lt;= I.DATADOC AND CREF.DATASTOP &gt;= I.DATADOC
      WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)
        AND I.TIPDOC NOT IN (14,15)&apos;||CHR(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_INTRARI AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        XM.NUMEPRESC NUMEDOC, CAST(I.CODINTR AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, Trunc(vc.vechime) VECHIMEFURN,
        CAST(i1.CodObiect AS VARCHAR(32)) CodObiect, Round(Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT),4) Cant, Round(I1.Pretorig,4) PretOrig, Round(I1.PU,4) PU,
        Round(I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj),4) PretFinal,
        Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT)/I1.CANT END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(NS.CODNIRSTOC,0) AS CHAR(32)) CODNIRSTOC, CAST(AE1.CODINTR AS VARCHAR(32)) CODAE, CAST(AE1.CODINTR1 AS VARCHAR(32)) CODAE1, CAST(N.NRNIR AS VARCHAR(32)) NRRECEPT,
        CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATARECEPT,
        llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume agent,
        Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret - ns.adaos WHEN lv.codlivrval IS NOT NULL THEN lv.pretachiz ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretAchiz,
        Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret WHEN lv.codlivrval IS NOT NULL THEN lv.pretinreg ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, c1.termen TermenLivr, Trunc(SYSDATE) datasystem,
        ioa1.mg, i.an*100+i.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.INTRARI I
        INNER JOIN &apos;||v_rec.Skema||&apos;.INTRARI1 I1 ON I1.CODINTR  = I.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(I.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRLINK ILAE ON ILAE.CODINTR1 = I1.CODINTR1 AND I.TIPDOC = 9 AND ILAE.CODLINIEAVIZ IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI1 AE1 ON AE1.CODINTR1 = ILAE.CODLINIEAVIZ
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI AE ON AE.CODINTR = AE1.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI ON DVI.CODINTR = I.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI1 ON DVI1.CODDVI = DVI.CODDVI AND DVI1.CODINTR1 = I1.CODINTR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODINTR1 = I1.CODINTR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODOBIECT = I1.CODOBIECT AND ( ((L1.CODLIVR1 IS NOT NULL) AND (NS.CODNIRSTOC = L1.CODNIRSTOC)) OR ((L1.CODLIVR1 IS NULL) AND ((NS.CODINTR1 = NVL(AE1.CODINTR1,I1.CODINTR1)) OR (NS.CODDVI1 = DVI1.CODDVI1))))
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODINTR = NVL(AE.CODINTR, I.CODINTR) AND N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = I.PARTENER
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AG ON AG.CODPERS  = I.AGENT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCALIT LLIVR ON LLIVR.CODLOCALIT = SLIVR.CODLOCALIT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NJUDET JLIVR ON JLIVR.CODJUDET = LLIVR.CODJUDET
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = COALESCE(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = IOA1.CONT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRLINK ILC ON ILC.CODINTR1 = Nvl(AE1.CODINTR1, I1.CODINTR1) AND ILAE.CODLINIECOMANDA IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
        LEFT JOIN (SELECT PARTENER, MIN(DATADOC) VECHIME FROM &apos;||v_rec.Skema||&apos;.INTRARI WHERE PARTENER IS NOT NULL AND DATADOC BETWEEN TO_DATE(1970,&apos;&apos;YYYY&apos;&apos;) AND ADD_MONTHS(TRUNC(SYSDATE),120) GROUP BY PARTENER) VC ON VC.PARTENER = I.PARTENER
      WHERE NVL(I.OPERAT,0) = 1 AND NVL(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        XM.NUMEPRESC NUMEDOC, CAST(I.CODINTR AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, Trunc(vc.vechime) VECHIMEFURN,
        CAST(i1.CodObiect AS VARCHAR(32)) CodObiect, Round(Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT),4) Cant, Round(I1.Pretorig,4) PretOrig, Round(I1.PU,4) PU,
        Round(I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj),4) PretFinal,
        Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT)/I1.CANT END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(NS.CODNIRSTOC,0) AS CHAR(32)) CODNIRSTOC, CAST(AE1.CODINTR AS VARCHAR(32)) CODAE, CAST(AE1.CODINTR1 AS VARCHAR(32)) CODAE1, CAST(N.NRNIR AS VARCHAR(32)) NRRECEPT,
        CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATARECEPT,
        llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos;&apos; &apos;&apos;||ag.prenume agent,
        Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret - ns.adaos WHEN lv.codlivrval IS NOT NULL THEN lv.pretachiz ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretAchiz,
        Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret WHEN lv.codlivrval IS NOT NULL THEN lv.pretinreg ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, c1.termen TermenLivr, Trunc(SYSDATE) datasystem,
        ioa1.mg, i.an*100+i.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.INTRARI I
        INNER JOIN &apos;||v_rec.Skema||&apos;.INTRARI1 I1 ON I1.CODINTR  = I.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(I.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRLINK ILAE ON ILAE.CODINTR1 = I1.CODINTR1 AND I.TIPDOC = 9 AND ILAE.CODLINIEAVIZ IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI1 AE1 ON AE1.CODINTR1 = ILAE.CODLINIEAVIZ
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI AE ON AE.CODINTR = AE1.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI ON DVI.CODINTR = I.CODINTR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI1 ON DVI1.CODDVI = DVI.CODDVI AND DVI1.CODINTR1 = I1.CODINTR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODINTR1 = I1.CODINTR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODOBIECT = I1.CODOBIECT AND ( ((L1.CODLIVR1 IS NOT NULL) AND (NS.CODNIRSTOC = L1.CODNIRSTOC)) OR ((L1.CODLIVR1 IS NULL) AND ((NS.CODINTR1 = NVL(AE1.CODINTR1,I1.CODINTR1)) OR (NS.CODDVI1 = DVI1.CODDVI1))))
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODINTR = NVL(AE.CODINTR, I.CODINTR) AND N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = I.PARTENER
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AG ON AG.CODPERS  = I.AGENT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCALIT LLIVR ON LLIVR.CODLOCALIT = SLIVR.CODLOCALIT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NJUDET JLIVR ON JLIVR.CODJUDET = LLIVR.CODJUDET
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = COALESCE(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart1 = iox.codioart1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = IOA1.CONT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRLINK ILC ON ILC.CODINTR1 = Nvl(AE1.CODINTR1, I1.CODINTR1) AND ILAE.CODLINIECOMANDA IS NOT NULL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
        LEFT JOIN (SELECT PARTENER, MIN(DATADOC) VECHIME FROM &apos;||v_rec.Skema||&apos;.INTRARI WHERE PARTENER IS NOT NULL AND DATADOC BETWEEN TO_DATE(1970,&apos;&apos;YYYY&apos;&apos;) AND ADD_MONTHS(TRUNC(SYSDATE),120) GROUP BY PARTENER) VC ON VC.PARTENER = I.PARTENER
      WHERE NVL(I.OPERAT,0) = 1 AND NVL(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

 sSQL :=
  &apos;CREATE OR REPLACE VIEW v_bi_jurnal1_cu_articol AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        case
          when j1.tipdoc IN (1,2,3,4,6,7,9) THEN i1.codobiect
          when j1.tipdoc = 5 THEN dvi1.codobiect
          when j1.tipdoc IN (12,13) THEN t1.codobiect
          when j1.tipdoc IN (14,15,19,20,21,22,23,24,26) THEN ies1.codobiect
        END codobiect,
        o.denumire, cls.den_clasea Clasa,
        cd.simbol simbol_debit,
        cc.simbol simbol_credit,
        j1.CODJURNAL1,j1.CODDOC,j1.TIPDOC,j1.INDEXLOCAL,j1.CODBAZAD,j1.TIPBAZAD,
        j1.ICONTBAZAD,j1.CODDESCRD,j1.ICONTD,j1.TIPCONTD,j1.ANALITICCONTD,j1.CODBAZAC,
        j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,
        j1.GEST,j1.VALOARE,j1.VALOAREV,j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
        j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,j1.VALOARE_IFRS,j1.VALOAREV_IFRS
      FROM &apos;||v_rec.Skema||&apos;.jurnal1 j1
           inner join &apos;||v_rec.Skema||&apos;.ncont cd on cd.codcont = &apos;||v_rec.Skema||&apos;.pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
           inner join &apos;||v_rec.Skema||&apos;.ncont cc on cc.codcont = &apos;||v_rec.Skema||&apos;.pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
           left join &apos;||v_rec.Skema||&apos;.intrari1 i1 on i1.codintr1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.dvi1 on dvi1.coddvi1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.transf1 t1 on t1.codtransf1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.iesiri1 ies1 on ies1.codies1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.nartobj o on o.codobiect = coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect)
           left join &apos;||v_rec.Skema||&apos;.nart a on a.codarticol = o.codarticol
           left join &apos;||v_rec.Skema||&apos;.nclasea cls on cls.codclasea = a.clasa
      where coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect) &gt; 0&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        case
          when j1.tipdoc IN (1,2,3,4,6,7,9) THEN i1.codobiect
          when j1.tipdoc = 5 THEN dvi1.codobiect
          when j1.tipdoc IN (12,13) THEN t1.codobiect
          when j1.tipdoc IN (14,15,19,20,21,22,23,24,26) THEN ies1.codobiect
        END codobiect,
        o.denumire, cls.den_clasea Clasa,
        cd.simbol simbol_debit,
        cc.simbol simbol_credit,
        j1.CODJURNAL1,j1.CODDOC,j1.TIPDOC,j1.INDEXLOCAL,j1.CODBAZAD,j1.TIPBAZAD,
        j1.ICONTBAZAD,j1.CODDESCRD,j1.ICONTD,j1.TIPCONTD,j1.ANALITICCONTD,j1.CODBAZAC,
        j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,
        j1.GEST,j1.VALOARE,j1.VALOAREV,j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
        j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,j1.VALOARE_IFRS,j1.VALOAREV_IFRS
      FROM &apos;||v_rec.Skema||&apos;.jurnal1 j1
           inner join &apos;||v_rec.Skema||&apos;.ncont cd on cd.codcont = &apos;||v_rec.Skema||&apos;.pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
           inner join &apos;||v_rec.Skema||&apos;.ncont cc on cc.codcont = &apos;||v_rec.Skema||&apos;.pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
           left join &apos;||v_rec.Skema||&apos;.intrari1 i1 on i1.codintr1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.dvi1 on dvi1.coddvi1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.transf1 t1 on t1.codtransf1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.iesiri1 ies1 on ies1.codies1 = j1.indexlocal
           left join &apos;||v_rec.Skema||&apos;.nartobj o on o.codobiect = coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect)
           left join &apos;||v_rec.Skema||&apos;.nart a on a.codarticol = o.codarticol
           left join &apos;||v_rec.Skema||&apos;.nclasea cls on cls.codclasea = a.clasa
      where coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect) &gt; 0&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_JURNAL_1 AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        CD.Simbol &quot;CONT DEBIT SIMBOL&quot;,
        CD.Den_Cont &quot;CONT DEBIT DESCRIERE&quot;,
        CC.Simbol &quot;CONT CREDIT SIMBOL&quot;,
        CC.Den_Cont &quot;CONT CREDIT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.AN*10+J.Luna ANLUNALUCRU,
        J.DOCUMENT
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont cd ON cd.codcont = contd
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont cc ON cc.codcont = contc
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        CD.Simbol &quot;CONT DEBIT SIMBOL&quot;,
        CD.Den_Cont &quot;CONT DEBIT DESCRIERE&quot;,
        CC.Simbol &quot;CONT CREDIT SIMBOL&quot;,
        CC.Den_Cont &quot;CONT CREDIT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.AN*10+J.Luna ANLUNALUCRU,
        J.DOCUMENT
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont cd ON cd.codcont = contd
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont cc ON cc.codcont = contc
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_JURNAL_2
   AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
        &apos;&apos;DEBITARE&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.DOCUMENT,
        J.AN*10+J.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = j.contd
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest
      UNION ALL
      SELECT
        Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
        &apos;&apos;CREDITARE&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.DOCUMENT,
        J.AN*10+J.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = j.contc
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest
      UNION ALL
      SELECT
        tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
        &apos;&apos;SOLD DEBITOR&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        NULL TipDoc,
        NULL CodDoc,
        NULL IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        NULL &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        To_Date( To_Char(cr.an,&apos;&apos;fm0000&apos;&apos;)||To_Char(cr.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;) Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldid, 0) + Nvl(cr.rulajpd, 0) END VALOARE,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvid,0) + Nvl(cr.rulajvpd,0) END VALOAREV,
        NULL GESTIUNE,
        NULL OBSERVATII,
        NULL DOCUMENT,
        CR.AN*10+CR.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.ncontrul cr
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = cr.codcont
        CROSS JOIN (SELECT Count(1) Nr FROM &apos;||v_rec.Skema||&apos;.Jurnal) tmp
      UNION ALL
      SELECT
        tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
        &apos;&apos;SOLD CREDITOR&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        NULL TipDoc,
        NULL CodDoc,
        NULL IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        NULL &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        To_Date( To_Char(cr.an,&apos;&apos;fm0000&apos;&apos;)||To_Char(cr.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;) Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldic, 0) + Nvl(cr.rulajpc, 0) END VALOARE,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvic,0) + Nvl(cr.rulajvpc,0) END VALOAREV,
        NULL GESTIUNE,
        NULL OBSERVATII,
        NULL DOCUMENT,
        CR.AN*10+CR.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.ncontrul cr
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = cr.codcont
        CROSS JOIN (SELECT Count(1) Nr FROM &apos;||v_rec.Skema||&apos;.Jurnal) tmp&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
        &apos;&apos;DEBITARE&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.DOCUMENT,
        J.AN*10+J.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = j.contd
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest
      UNION ALL
      SELECT
        Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
        &apos;&apos;CREDITARE&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
        CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
        IndexLocal IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        J.CodJurnal &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        DataDoc Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        J.VALOARE,
        J.VALOAREV,
        g.den_gest GESTIUNE,
        J.OBS OBSERVATII,
        J.DOCUMENT,
        J.AN*10+J.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.jurnal j
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = j.contc
        LEFT JOIN &apos;||v_rec.Skema||&apos;.ngest g ON g.codgest = j.gest
      UNION ALL
      SELECT
        tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
        &apos;&apos;SOLD DEBITOR&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        NULL TipDoc,
        NULL CodDoc,
        NULL IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        NULL &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        To_Date( To_Char(cr.an,&apos;&apos;fm0000&apos;&apos;)||To_Char(cr.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;) Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldid, 0) + Nvl(cr.rulajpd, 0) END VALOARE,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvid,0) + Nvl(cr.rulajvpd,0) END VALOAREV,
        NULL GESTIUNE,
        NULL OBSERVATII,
        NULL DOCUMENT,
        CR.AN*10+CR.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.ncontrul cr
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = cr.codcont
        CROSS JOIN (SELECT Count(1) Nr FROM &apos;||v_rec.Skema||&apos;.Jurnal) tmp
      UNION ALL
      SELECT
        tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
        &apos;&apos;SOLD CREDITOR&apos;&apos; OPERATIE,
        C.CODCONT &quot;COD INTERN&quot;,
        C.CODPARINTE &quot;COD PARINTE&quot;,
        NULL TipDoc,
        NULL CodDoc,
        NULL IndexDoc,
        Decode(c.tipcont,0,&apos;&apos;Debitor&apos;&apos;,1,&apos;&apos;Creditor&apos;&apos;,&apos;&apos;Debitor/Creditor&apos;&apos;) &quot;TIP CONT&quot;,
        NULL &quot;COD INREGISTRARE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
        CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
        CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
        To_Date( To_Char(cr.an,&apos;&apos;fm0000&apos;&apos;)||To_Char(cr.luna,&apos;&apos;fm00&apos;&apos;),&apos;&apos;yyyymm&apos;&apos;) Data,
        C.Simbol &quot;CONT SIMBOL&quot;,
        C.Den_Cont &quot;CONT DESCRIERE&quot;,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldic, 0) + Nvl(cr.rulajpc, 0) END VALOARE,
        CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvic,0) + Nvl(cr.rulajvpc,0) END VALOAREV,
        NULL GESTIUNE,
        NULL OBSERVATII,
        NULL DOCUMENT,
        CR.AN*10+CR.Luna ANLUNALUCRU,
        Decode(c.vizibilbalanta,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;VIZIBIL BALANTA&quot;,
        Decode(c.balantasintetica,1,&apos;&apos;DA&apos;&apos;,&apos;&apos;NU&apos;&apos;) &quot;BALANTA SINTETICA&quot;
      FROM &apos;||v_rec.Skema||&apos;.ncontrul cr
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
        INNER JOIN &apos;||v_rec.Skema||&apos;.ncont c ON c.codcont = cr.codcont
        CROSS JOIN (SELECT Count(1) Nr FROM &apos;||v_rec.Skema||&apos;.Jurnal) tmp&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_MISCINT AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT ------- diminuari si mariri -------
        XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE seriedoc, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        CAST(I1.CodObiect AS VARCHAR(32)) CodObiect, Round(Nvl(L1.CANT, I1.CANT),4) Cant, Round(I1.PU,4) PU, Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Nvl(L1.CANT, I1.CANT)/I1.CANT END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
        CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
        Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, i.an*100+i.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.IESIRI I
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN &apos;||v_rec.Skema||&apos;.IESIRI1 I1 ON I1.CODIES1  = L1.CODIES1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, I1.CONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)
        AND I.TIPDOC IN (14,15)
      UNION ALL
      SELECT -- iesiri prin transfer
        XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
        CAST(T1.CodObiect AS VARCHAR(32)) CodObiect, -Round(Nvl(L1.CANT, T1.CANT),4) Cant, Round(T1.PU,4) PU, -Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(L1.CANT, T1.CANT)/T1.CANT END,4) TvaLin,
        T1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
        CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
        Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, t.an*100+t.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.TRANSF T
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR L ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN &apos;||v_rec.Skema||&apos;.TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND T1.CODTRANSF1 = L1.CODIES1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = T.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON L1.CODLIVR1 = LV.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = T1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND t.an*12+t.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0
      UNION ALL
      SELECT -- intrari prin transfer
        XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)), CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
        CAST(T1.CodObiect AS VARCHAR(32)), Round(Nvl(NS.CANTNIR, T1.CANT),4) Cant, Round(T1.PU,4) PU, Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(NS.CANTNIR, T1.CANT)/T1.CANT END,4) TvaLin,
        T1.INDEXLOCAL INDEXDOC, CAST( Nvl(NS.CODNIRSTOC,0) AS VARCHAR(32))  CODDOC1, CAST(N.NRNIR AS VARCHAR(32))  NRLIVREC, CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATALIVREC,
        Round(ns.pret - ns.adaos,4) PretAchiz, Round(ns.pret,4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, t.an*100+t.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.TRANSF T
        INNER JOIN &apos;||v_rec.Skema||&apos;.TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIR N ON T.CODTRANSF = N.CODTRANSF
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODTRANSF1 = T1.CODTRANSF1 AND NS.CODNIR = N.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = T.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = T1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = N.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NS.CODIOART
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND t.an*12+t.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT ------- diminuari si mariri -------
        XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE seriedoc, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
        CAST(I1.CodObiect AS VARCHAR(32)) CodObiect, Round(Nvl(L1.CANT, I1.CANT),4) Cant, Round(I1.PU,4) PU, Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Nvl(L1.CANT, I1.CANT)/I1.CANT END,4) TvaLin,
        I1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
        CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
        Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, i.an*100+i.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.IESIRI I
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN &apos;||v_rec.Skema||&apos;.IESIRI1 I1 ON I1.CODIES1  = L1.CODIES1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = I.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = I1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, I1.CONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
        AND I1.TIPLINIE IN (&apos;&apos;=&apos;&apos;,&apos;&apos;S&apos;&apos;,&apos;&apos;V&apos;&apos;)
        AND I.TIPDOC IN (14,15)
      UNION ALL
      SELECT -- iesiri prin transfer
        XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)) NRDOC,
        CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
        CAST(T1.CodObiect AS VARCHAR(32)) CodObiect, -Round(Nvl(L1.CANT, T1.CANT),4) Cant, Round(T1.PU,4) PU, -Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(L1.CANT, T1.CANT)/T1.CANT END,4) TvaLin,
        T1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
        CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
        Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, t.an*100+t.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.TRANSF T
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR L ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
        INNER JOIN &apos;||v_rec.Skema||&apos;.TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND T1.CODTRANSF1 = L1.CODIES1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = T.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.LIVRVAL LV ON L1.CODLIVR1 = LV.CODLIVR1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = T1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND t.an*12+t.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0
      UNION ALL
      SELECT -- intrari prin transfer
        XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)), CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
        CAST(T1.CodObiect AS VARCHAR(32)), Round(Nvl(NS.CANTNIR, T1.CANT),4) Cant, Round(T1.PU,4) PU, Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(NS.CANTNIR, T1.CANT)/T1.CANT END,4) TvaLin,
        T1.INDEXLOCAL INDEXDOC, CAST( Nvl(NS.CODNIRSTOC,0) AS VARCHAR(32))  CODDOC1, CAST(N.NRNIR AS VARCHAR(32))  NRLIVREC, CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATALIVREC,
        Round(ns.pret - ns.adaos,4) PretAchiz, Round(ns.pret,4) PretInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, t.an*100+t.luna AnLuna
      FROM &apos;||v_rec.Skema||&apos;.TRANSF T
        INNER JOIN &apos;||v_rec.Skema||&apos;.TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIR N ON T.CODTRANSF = N.CODTRANSF
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODTRANSF1 = T1.CODTRANSF1 AND NS.CODNIR = N.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = T.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM1 U1 ON U1.CODUM1  = T1.UMSEC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = N.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NS.CODIOART
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND t.an*12+t.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_OBLIGATII AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        G.CODDOC, G.TIPDOC, XM.NUMEPRESC NUMEDOC,
        COALESCE(INTR.VALDOC, IES.VALDOC, T1.VALDOC, NC1.VALOARE, O.VALOARE) ValDoc,
        CAST (COALESCE(INTR.NRDOC, IES.NRDOC, C.NRDOC, T1.NRDOC, NC.NRDOC) AS VARCHAR2(20)) NrDoc,
        COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) DataDoc,
        O.CODOBLIGPIF CodOblig, O.SEMNIFICATIE TipOblig, XS.SIMB SimbOblig, XS.OBS ObsOblig,
        XS.Semn* (O.VALOARE - XS.TVA*NVL(G.TVA, 0)) ValOblig,
        XS.Semn*XS.TVA*NVL(G.TVA, 0) TVAOblig,
        CASE
          WHEN O.TERMEN IS NULL THEN COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
          WHEN O.TERMEN &gt;= COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) THEN O.TERMEN
          ELSE COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
        END TermenOblig,
        M.SIMBOL MONEDA, COALESCE(REG.CURS,G.CURS,1) CURS, O.CODPART, P.Den_Part Partener,
        GS.CodDoc CodDocStingere, GS.TipDoc TipDocStingere, XMS.NUMEPRESC NumeDocStingere,
        XSS.Semn* (OS.VALOARE - XSS.TVA*NVL(GS.TVA, 0)) ValStingere,
        XSS.Semn*XSS.TVA*NVL(GS.TVA, 0) TVAStingere,
        OS.CODOBLIGPIF CodStingere, OS.SEMNIFICATIE TipStingere, XSS.SIMB SimbStingere, XSS.OBS ObsStingere,
        COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) DataStingere,
        CASE
          WHEN GS.TIPDOC = 31 THEN (
            SELECT
              CASE
                WHEN T1X.DATADOC IS NULL THEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
                WHEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) IS NULL THEN T1X.DATADOC
                ELSE Greatest( T1X.DATADOC, COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC))
              END
            FROM &apos;||v_rec.Skema||&apos;.general gc
              INNER JOIN &apos;||v_rec.Skema||&apos;.obligpif oc ON oc.codgeneral = gc.codgeneral
              INNER JOIN &apos;||v_rec.Skema||&apos;.stingere sc ON sc.codstinspif = oc.codobligpif
              INNER JOIN &apos;||v_rec.Skema||&apos;.obligpif osc ON osc.codobligpif = sc.codstingatorpif
              INNER JOIN &apos;||v_rec.Skema||&apos;.general gsc ON gsc.codgeneral = osc.codgeneral
              INNER JOIN &apos;||v_rec.Skema||&apos;.trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
            WHERE gc.semnificatie IN (500,600) AND gc.tipdoc = 31 AND gc.coddoc = gs.coddoc
          )
          ELSE COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
        END DataDecont,
        Trunc(SYSDATE) datasystem,
        COALESCE(INTR.AN*100+INTR.Luna, IES.AN*100+IES.Luna, C.AN*100+C.Luna, T.AN*100+T.Luna, NC.AN*100+NC.Luna) AnLuna,
        NumePrenume(AGD.NUME, AGD.Prenume) AgentDoc,
        NumePrenume(AGS.NUME, AGS.Prenume) AgentSting,
        COALESCE(INTRS.AN*100+INTRS.Luna, IESS.AN*100+IESS.Luna, CS.AN*100+CS.Luna, TS.AN*100+TS.Luna) AnLunaSting,
        COALESCE(G.CURS,1) CURSORIG,
        CONTS.SIMBOL SIMBCONTSTING,
        CONTS.DEN_CONT DENCONTSTING,
        CONTD.SIMBOL SIMBCONTDOC,
        CONTD.DEN_CONT DENCONTDOC
      FROM &apos;||v_rec.Skema||&apos;.OBLIGPIF O
        INNER JOIN &apos;||v_rec.Skema||&apos;.V_SEMNIFICATII XS ON XS.SEMNIFICATIE = O.SEMNIFICATIE AND Decode(XS.ICONT,0,1,O.ICONT,1,0) = 1
        INNER JOIN &apos;||v_rec.Skema||&apos;.GENERAL G ON G.CODGENERAL = O.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(G.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = G.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI ON G.CODDOC = DVI.CODDVI AND O.SEMNIFICATIE = 130
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI INTR ON INTR.CODINTR = Nvl(DVI.CODINTR, G.CODDOC) AND INTR.TIPDOC = G.TIPDOC -- 100, 110, 120, 130, 140
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC -- 200, 210, 220, 240
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28 AND O.SEMNIFICATIE IN (1301, 1351, 1303)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33) AND G.SEMNIFICATIE IN (310, 410, 330, 430)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR T ON T.CODTREZOR = T1.CODTREZOR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35 AND O.SEMNIFICATIE IN (1200, 1201)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NC ON NC.CODNC = NC1.CODNC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = O.CODPART
        LEFT OUTER JOIN (
          SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
          FROM &apos;||v_rec.Skema||&apos;.REG R INNER JOIN &apos;||v_rec.Skema||&apos;.REG1 R1 ON R1.CODREG = R.CODREG
          WHERE R.TIPREG = 46
          GROUP BY R1.CODGENERAL
        ) REG ON REG.CODGENERAL = G.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT JOIN &apos;||v_rec.Skema||&apos;.OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN &apos;||v_rec.Skema||&apos;.GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.V_SEMNIFICATII XSS ON XSS.SEMNIFICATIE = OS.SEMNIFICATIE AND Decode(XSS.ICONT,0,1,OS.ICONT,1,0) = 1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XMS ON XMS.CODMACHETA = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI INTRS ON INTRS.CODINTR = GS.CODDOC AND INTRS.TIPDOC = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI IESS ON IESS.CODIES = GS.CODDOC AND IESS.TIPDOC = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR1 T1S ON T1S.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29, 30, 31, 33)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AGD ON AGD.CODPERS = Coalesce(INTR.AGENT,  IES.AGENT,  C.AGENT,  T1.AGENT,  T.AGENT)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AGS ON AGS.CODPERS = Coalesce(INTRS.AGENT, IESS.AGENT, CS.AGENT, T1S.AGENT, TS.AGENT)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT CONTD ON CONTD.CODCONT = &apos;||v_rec.Skema||&apos;.PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart, COALESCE(INTR.AN*12+INTR.Luna, IES.AN*12+IES.Luna, C.AN*12+C.Luna, T.AN*12+T.Luna, NC.AN*12+NC.Luna) ,o.semnificatie)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT CONTS ON CONTS.CODCONT = &apos;||v_rec.Skema||&apos;.PKG_LIST_BASE_UTILS.iCont_CodCont(os.icont,os.codpart, COALESCE(INTRS.AN*12+INTRS.Luna, IESS.AN*12+IESS.Luna, CS.AN*12+CS.Luna, TS.AN*12+TS.Luna) ,os.semnificatie)
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, /*140, */200, 210, 220, /*240, */310, 330, 410, 430, 1200, 1201, 1301, 1303, 1351)
        AND G.TIPDOC NOT IN (2, 20)
      ORDER BY O.CODOBLIGPIF&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        G.CODDOC, G.TIPDOC, XM.NUMEPRESC NUMEDOC,
        COALESCE(INTR.VALDOC, IES.VALDOC, T1.VALDOC, NC1.VALOARE, O.VALOARE) ValDoc,
        CAST (COALESCE(INTR.NRDOC, IES.NRDOC, C.NRDOC, T1.NRDOC, NC.NRDOC) AS VARCHAR2(20)) NrDoc,
        COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) DataDoc,
        O.CODOBLIGPIF CodOblig, O.SEMNIFICATIE TipOblig, XS.SIMB SimbOblig, XS.OBS ObsOblig,
        XS.Semn* (O.VALOARE - XS.TVA*NVL(G.TVA, 0)) ValOblig,
        XS.Semn*XS.TVA*NVL(G.TVA, 0) TVAOblig,
        CASE
          WHEN O.TERMEN IS NULL THEN COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
          WHEN O.TERMEN &gt;= COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) THEN O.TERMEN
          ELSE COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
        END TermenOblig,
        M.SIMBOL MONEDA, COALESCE(REG.CURS,G.CURS,1) CURS, O.CODPART, P.Den_Part Partener,
        GS.CodDoc CodDocStingere, GS.TipDoc TipDocStingere, XMS.NUMEPRESC NumeDocStingere,
        XSS.Semn* (OS.VALOARE - XSS.TVA*NVL(GS.TVA, 0)) ValStingere,
        XSS.Semn*XSS.TVA*NVL(GS.TVA, 0) TVAStingere,
        OS.CODOBLIGPIF CodStingere, OS.SEMNIFICATIE TipStingere, XSS.SIMB SimbStingere, XSS.OBS ObsStingere,
        COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) DataStingere,
        CASE
          WHEN GS.TIPDOC = 31 THEN (
            SELECT
              CASE
                WHEN T1X.DATADOC IS NULL THEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
                WHEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) IS NULL THEN T1X.DATADOC
                ELSE Greatest( T1X.DATADOC, COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC))
              END
            FROM &apos;||v_rec.Skema||&apos;.general gc
              INNER JOIN &apos;||v_rec.Skema||&apos;.obligpif oc ON oc.codgeneral = gc.codgeneral
              INNER JOIN &apos;||v_rec.Skema||&apos;.stingere sc ON sc.codstinspif = oc.codobligpif
              INNER JOIN &apos;||v_rec.Skema||&apos;.obligpif osc ON osc.codobligpif = sc.codstingatorpif
              INNER JOIN &apos;||v_rec.Skema||&apos;.general gsc ON gsc.codgeneral = osc.codgeneral
              INNER JOIN &apos;||v_rec.Skema||&apos;.trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
            WHERE gc.semnificatie IN (500,600) AND gc.tipdoc = 31 AND gc.coddoc = gs.coddoc
          )
          ELSE COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
        END DataDecont,
        Trunc(SYSDATE) datasystem,
        COALESCE(INTR.AN*100+INTR.Luna, IES.AN*100+IES.Luna, C.AN*100+C.Luna, T.AN*100+T.Luna, NC.AN*100+NC.Luna) AnLuna,
        NumePrenume(AGD.NUME, AGD.Prenume) AgentDoc,
        NumePrenume(AGS.NUME, AGS.Prenume) AgentSting,
        COALESCE(INTRS.AN*100+INTRS.Luna, IESS.AN*100+IESS.Luna, CS.AN*100+CS.Luna, TS.AN*100+TS.Luna) AnLunaSting,
        COALESCE(G.CURS,1) CURSORIG,
        CONTS.SIMBOL SIMBCONTSTING,
        CONTS.DEN_CONT DENCONTSTING,
        CONTD.SIMBOL SIMBCONTDOC,
        CONTD.DEN_CONT DENCONTDOC
      FROM &apos;||v_rec.Skema||&apos;.OBLIGPIF O
        INNER JOIN &apos;||v_rec.Skema||&apos;.V_SEMNIFICATII XS ON XS.SEMNIFICATIE = O.SEMNIFICATIE AND Decode(XS.ICONT,0,1,O.ICONT,1,0) = 1
        INNER JOIN &apos;||v_rec.Skema||&apos;.GENERAL G ON G.CODGENERAL = O.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NMONEDE M ON M.CODMONEDA = Nvl(G.MONEDA,0)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XM ON XM.CODMACHETA = G.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.DVI ON G.CODDOC = DVI.CODDVI AND O.SEMNIFICATIE = 130
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI INTR ON INTR.CODINTR = Nvl(DVI.CODINTR, G.CODDOC) AND INTR.TIPDOC = G.TIPDOC -- 100, 110, 120, 130, 140
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC -- 200, 210, 220, 240
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28 AND O.SEMNIFICATIE IN (1301, 1351, 1303)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33) AND G.SEMNIFICATIE IN (310, 410, 330, 430)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR T ON T.CODTREZOR = T1.CODTREZOR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35 AND O.SEMNIFICATIE IN (1200, 1201)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NC ON NC.CODNC = NC1.CODNC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART P ON P.CODPART = O.CODPART
        LEFT OUTER JOIN (
          SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
          FROM &apos;||v_rec.Skema||&apos;.REG R INNER JOIN &apos;||v_rec.Skema||&apos;.REG1 R1 ON R1.CODREG = R.CODREG
          WHERE R.TIPREG = 46
          GROUP BY R1.CODGENERAL
        ) REG ON REG.CODGENERAL = G.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
        LEFT JOIN &apos;||v_rec.Skema||&apos;.OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
        LEFT JOIN &apos;||v_rec.Skema||&apos;.GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.V_SEMNIFICATII XSS ON XSS.SEMNIFICATIE = OS.SEMNIFICATIE AND Decode(XSS.ICONT,0,1,OS.ICONT,1,0) = 1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.MACHETE XMS ON XMS.CODMACHETA = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.INTRARI INTRS ON INTRS.CODINTR = GS.CODDOC AND INTRS.TIPDOC = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.IESIRI IESS ON IESS.CODIES = GS.CODDOC AND IESS.TIPDOC = GS.TIPDOC
        LEFT JOIN &apos;||v_rec.Skema||&apos;.COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR1 T1S ON T1S.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29, 30, 31, 33)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AGD ON AGD.CODPERS = Coalesce(INTR.AGENT,  IES.AGENT,  C.AGENT,  T1.AGENT,  T.AGENT)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPERS AGS ON AGS.CODPERS = Coalesce(INTRS.AGENT, IESS.AGENT, CS.AGENT, T1S.AGENT, TS.AGENT)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT CONTD ON CONTD.CODCONT = &apos;||v_rec.Skema||&apos;.PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart, COALESCE(INTR.AN*12+INTR.Luna, IES.AN*12+IES.Luna, C.AN*12+C.Luna, T.AN*12+T.Luna, NC.AN*12+NC.Luna) ,o.semnificatie)
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT CONTS ON CONTS.CODCONT = &apos;||v_rec.Skema||&apos;.PKG_LIST_BASE_UTILS.iCont_CodCont(os.icont,os.codpart, COALESCE(INTRS.AN*12+INTRS.Luna, IESS.AN*12+IESS.Luna, CS.AN*12+CS.Luna, TS.AN*12+TS.Luna) ,os.semnificatie)
      WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, /*140, */200, 210, 220, /*240, */310, 330, 410, 430, 1200, 1201, 1301, 1303, 1351)
        AND G.TIPDOC NOT IN (2, 20)
      ORDER BY O.CODOBLIGPIF&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

  sSQL :=
  &apos;CREATE OR REPLACE VIEW V_BI_STOC AS&apos;||chr(13);
  FOR v_rec IN (SELECT skema, rownum FROM skemebi) LOOP
    IF v_rec.rownum = 1 THEN
      sSQL := sSQL||
      &apos;SELECT
        CAST(Ns.CodObiect AS VARCHAR(32)) CodObiect, NL.REST, NL.RESTUM1, NL.RESTUM2, Last_Day(To_Date(NL.An||&apos;&apos;.&apos;&apos;||NL.Luna,&apos;&apos;yyyy.mm&apos;&apos;)) DataStoc, Round(ns.pret - ns.adaos,4) PAchiz, ns.pret PInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, nl.an*100+nl.luna anluna
      FROM &apos;||v_rec.Skema||&apos;.NIRLUNA NL
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
        INNER JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NS.CODIOART
        INNER JOIN &apos;||v_rec.Skema||&apos;.IOART1 IOA1 ON IOA1.CODIOART = NS.CODIOART AND nl.an*12+nl.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = IOA1.CONT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NART A ON A.CODARTICOL = O.CODARTICOL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U  ON U.CODUM  = A.UM
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U1 ON U1.CODUM = A.UM1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U2 ON U2.CODUM = A.UM2
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCLASEA CA ON CA.CODCLASEA = A.CLASA
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = N.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime   FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE NL.AN*12+NL.LUNA &lt;= (SELECT AnCurent*12+LunaCurenta-1 FROM &apos;||v_rec.Skema||&apos;.FIRMALUNI)
        AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
        AND IOA1.MG &lt;&gt; 5&apos;||chr(13);
    ELSE
      sSQL := sSQL||
      &apos;UNION ALL
       SELECT
        CAST(Ns.CodObiect AS VARCHAR(32)) CodObiect, NL.REST, NL.RESTUM1, NL.RESTUM2, Last_Day(To_Date(NL.An||&apos;&apos;.&apos;&apos;||NL.Luna,&apos;&apos;yyyy.mm&apos;&apos;)) DataStoc, Round(ns.pret - ns.adaos,4) PAchiz, ns.pret PInreg,
        CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
        F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
        ioa1.mg, nl.an*100+nl.luna anluna
      FROM &apos;||v_rec.Skema||&apos;.NIRLUNA NL
        INNER JOIN &apos;||v_rec.Skema||&apos;.NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
        INNER JOIN &apos;||v_rec.Skema||&apos;.NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
        INNER JOIN &apos;||v_rec.Skema||&apos;.IOART IOA ON IOA.CODIOART = NS.CODIOART
        INNER JOIN &apos;||v_rec.Skema||&apos;.IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND nl.an*12+nl.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCONT NC ON NC.CODCONT = IOA1.CONT
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NART A ON A.CODARTICOL = O.CODARTICOL
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U  ON U.CODUM  = A.UM
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U1 ON U1.CODUM = A.UM1
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NUM U2 ON U2.CODUM = A.UM2
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NCLASEA CA ON CA.CODCLASEA = A.CLASA
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NPART F ON F.CODPART = NS.FURN
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NIR N ON N.CODNIR = NS.CODNIR
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NGEST G ON G.CODGEST = N.GEST
        LEFT JOIN &apos;||v_rec.Skema||&apos;.NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
        LEFT JOIN (SELECT furn, Min(dataachiz) vechime   FROM &apos;||v_rec.Skema||&apos;.nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;&apos;yyyy&apos;&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
      WHERE NL.AN*12+NL.LUNA &lt;= (SELECT AnCurent*12+LunaCurenta-1 FROM &apos;||v_rec.Skema||&apos;.FIRMALUNI)
        AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
        AND IOA1.MG &lt;&gt; 5&apos;||chr(13);
    END IF;
  END LOOP;
  EXECUTE IMMEDIATE sSQL;

END BIV;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>CONST_USER_CHECK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAB8CB04334624BF8F46706B86D2E676FE006134</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE CONST_USER_CHECK(pUserID NUMBER) IS
  NR              NUMBER(20)    := 0;
  NR2             NUMBER(20)    := 0;
  aVAL            VARCHAR2(300) := NULL;
  NewCodConstLuna NUMBER(20)    := 0;
  vUserIDCheck    NUMBER(1)     := 1;
  vAnIni          NUMBER(4);
  vLunaIni        NUMBER(2);
BEGIN
  IF Coalesce(pUserID, 0) &gt; 0 THEN
    SELECT Count(1) INTO vUserIDCheck FROM CONSTUSERCHECK WHERE UserID = pUserID;
  END IF;

  IF vUserIDCheck = 0 THEN
    SELECT /*+ cardinality(X,1) */ ANINITIAL, LUNAINITIALA INTO vAnIni, vLunaIni FROM FIRMALUNI X;

    DELETE FROM TMP_CONSTLUNA;
    DELETE FROM TMP_CONSTVALPOS;
    DELETE FROM TMP_CONSTVAL;

    INSERT INTO TMP_CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
    SELECT CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID
    FROM CONSTLUNA
    WHERE USERID = 0
      AND CODCONST1 IN (SELECT CODCONST1 FROM CONST1 WHERE CODCATEG IN (SELECT CODCATEG FROM CATEGCONST WHERE TIPCATEG = &apos;U&apos;));

    INSERT INTO TMP_CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA)
    SELECT COD, IDX, VALPOSIBILE, CODCONSTLUNA
    FROM CONSTVALPOS
    WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA);

    INSERT INTO TMP_CONSTVAL (VALOARE, CODCONSTLUNA)
    SELECT VALOARE, CODCONSTLUNA
    FROM CONSTVAL
    WHERE CODCONSTLUNA IN (SELECT CODCONSTLUNA FROM TMP_CONSTLUNA);

    FOR Rec_Constluna IN (
      SELECT CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART
      FROM TMP_CONSTLUNA
    ) LOOP
      SELECT COUNT(1) INTO NR
      FROM CONSTLUNA
      WHERE CODCONST1 = Rec_ConstLuna.CODCONST1 AND USERID = pUserID;

      IF NR = 0 THEN -- NU AM DESCRIERE LA NIVEL DE LUNA PENTRU USER-ul curent
        SELECT SEQ_CONSTLUNA_CODCONSTLUNA.NEXTVAL INTO NewCodConstLuna FROM DUAL;

        -- CONSTLUNA
        INSERT INTO CONSTLUNA (CODCONSTLUNA, CODCONST1, ANSTART, LUNASTART, USERID)
        VALUES (
          NewCodConstLuna,
          Rec_ConstLuna.CODCONST1,
          CASE WHEN Rec_ConstLuna.ANSTART   = 0 THEN vAnIni   ELSE Rec_ConstLuna.AnSTART   END,
          CASE WHEN Rec_ConstLuna.LUNASTART = 0 THEN vLunaIni ELSE Rec_ConstLuna.LunaSTART END,
          pUserID
        );

        -- CONSTVALPOS
        INSERT INTO CONSTVALPOS (COD, IDX, VALPOSIBILE, CODCONSTLUNA)
        SELECT SEQ_CONSTVALPOS_COD.NEXTVAL, TMP.IDX, TMP.VALPOSIBILE, NewCodConstLuna
        FROM TMP_CONSTVALPOS TMP
        WHERE TMP.CODCONSTLUNA = Rec_Constluna.CODCONSTLUNA;

        -- CONSTVAL
        INSERT INTO CONSTVAL (VALOARE, CODCONSTLUNA)
        SELECT TMP.VALOARE, NewCodConstLuna
        FROM TMP_CONSTVAL TMP
        WHERE TMP.CODCONSTLUNA = Rec_Constluna.CODCONSTLUNA;
      ELSE
        SELECT COUNT(1) INTO NR2 FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = REC_CONSTLUNA.CODCONSTLUNA;

        FOR V_REC_CONSTLUNA IN (
          SELECT CODCONSTLUNA
          FROM CONSTLUNA
          WHERE CODCONST1 = Rec_COnstLuna.CODCONST1 AND USERID = pUserID
        ) LOOP
          SELECT COUNT(1) INTO NR FROM CONSTVALPOS WHERE CODCONSTLUNA = v_REC_CONSTLUNA.CODCONSTLUNA;
          IF NR &lt;&gt; NR2 THEN
            DELETE CONSTVALPOS WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA;
            INSERT INTO CONSTVALPOS(COD, IDX, VALPOSIBILE, CODCONSTLUNA)
            SELECT SEQ_CONSTVALPOS_COD.NEXTVAL, IDX, VALPOSIBILE, V_REC_CONSTLUNA.CODCONSTLUNA
            FROM TMP_CONSTVALPOS
            WHERE CODCONSTLUNA = REC_CONSTLUNA.CODCONSTLUNA;
          END IF;

          FOR V_REC_CONSTVALPOS IN (
            SELECT *
            FROM CONSTVALPOS
            WHERE CODCONSTLUNA = V_REC_CONSTLUNA.CODCONSTLUNA
          ) LOOP
            BEGIN
              SELECT VALPOSIBILE INTO aVAL FROM TMP_CONSTVALPOS WHERE CODCONSTLUNA = Rec_COnstLuna.Codconstluna AND IDX = V_REC_CONSTVALPOS.IDX;
            EXCEPTION
              WHEN OTHERS THEN aVAL := NULL;
            END;

            IF aVAL IS NOT NULL AND aVAL &lt;&gt; V_REC_CONSTVALPOS.VALPOSIBILE THEN
              UPDATE CONSTVALPOS SET VALPOSIBILE = aVAL WHERE Cod = V_REC_CONSTVALPOS.COD;
            END IF;
          END LOOP;
        END LOOP;
      END IF;
    END LOOP;
    PRC_AL_CHECK(&apos;CONSTLUNA&apos;);
    INSERT INTO CONSTUSERCHECK (USERID) VALUES (pUserID);
    COMMIT;
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>DELAY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7610ED0CF59C570DBEF7AE601833B6957A521805</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE delay(x_millis in number) AS language JAVA NAME &apos;java.lang.Thread.sleep(int)&apos;;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>GETRECORDCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7E8A4446D0AD2F77B9C7E13A6F645662C3AA524</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE GETRECORDCOUNT( RECCOUNT OUT NUMBER, TABLENAME IN VARCHAR2 ) AS
begin
  commit;
  execute immediate &apos;select count( * ) from &apos; || TableName into RecCount;
end; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>GRANTBI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B92F46ACF0A435D77B822C61EE8230ED8912F441</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE grantbi(aSkema in varchar2) is
sSQL varchar2(500);
begin
  for v_rec in (select table_name from user_tables) loop
    sSQL := &apos;grant select on &apos;||v_rec.table_name||&apos; to &apos;||aSkema;
    execute immediate sSQL;
  end loop;
  for v_rec in (select name from user_source where type = &apos;PACKAGE&apos;
                union all
                select name from user_source where type = &apos;PACKAGE BODY&apos;
               ) loop
    sSQL := &apos;grant execute on &apos;||v_rec.name||&apos; to &apos;||aSkema;
    execute immediate sSQL;
  end loop;
  for v_rec in (select view_name from user_views
               ) loop
    sSQL := &apos;grant select on &apos;||v_rec.view_name||&apos; to &apos;||aSkema;
    execute immediate sSQL;  
  end loop;              
end grantbi;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>IESIRI_CALC_DISCLIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F909C92C244382BA13422997A822261706D28AB5</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE IESIRI_CALC_DISCLIN(pCodIes IN NUMBER) IS
  vTipDoc NUMBER;
BEGIN
  DELETE FROM TMP_IES_DISCLIN;
  BEGIN
    SELECT TipDoc INTO vTipDoc FROM iesiri WHERE codies = pCodIes;
  EXCEPTION WHEN OTHERS THEN
    vTipDoc := 0;
  END;

  IF vTipDoc IN (19,21,26) THEN
    INSERT INTO TMP_IES_DISCLIN (CodIes1, LinVal, LinTVA, DiscVal, DiscTVA, DV_Calc, DT_Calc)
    WITH
      doc AS (
        SELECT
          CodIes, ValDoc - TvaDoc vVDoc,
          Coalesce(pkg_categconst.GetValConstanta(&apos;ModAplicProcDisc&apos;,an,luna),&apos;1&apos;) vMAPD,
          Coalesce(pkg_categconst.GetValConstanta(&apos;DiscBrutPretOrig&apos;,an,luna),&apos;1&apos;) vDBPO,
          CASE Coalesce(ROTEFACT, 0) WHEN 1 THEN 2 ELSE 7 END vROT
        FROM iesiri
        WHERE codies = pCodIes
      ),
      dx AS (
        SELECT
          --CASE WHEN CD.Cumulat = 1 THEN 1 ELSE 0 END DiscLaPU,
          --CASE WHEN CD.Cumulat = 1 THEN 0 ELSE 1 END CoefDiscPrec,
          Row_Number() OVER (PARTITION BY i1a.codies1 ORDER BY i1d.indexlocal) Idx,
          i.vMAPD, i.vDBPO, i.vROT,
          i1a.codies1, i1a.TVA,
          i1d.codies1 codiesd, i1d.restfact ValDisc, i1d.TVA TvaDISC,
          CASE WHEN i.vMAPD = 2 THEN i1a.pretorig ELSE i1a.pretorig*i1a.cant END pretorig,
          CASE WHEN i.vMAPD = 2 THEN i1a.pu       ELSE i1a.pu*i1a.cant       END pu,
          CASE WHEN i.vMAPD = 2 THEN i1a.cant     ELSE 1                     END cant,
          CASE WHEN i.vMAPD = 2 THEN i1a.pu       ELSE i1a.pu*i1a.cant       END * Coalesce(i1a.ProcDisc, 0)/100 du,
          CASE
            WHEN Coalesce(i1a.ProcDisc, 0) = 0
            THEN 0
            ELSE Round(i1a.TVA * (1 + Coalesce(i1a.ProcDisc/100, 0)), i.vROT) - i1a.TVA
          END dtva,
          i1d.cant proc, Coalesce(cd.codcriteriu,0) CodCriteriu, Coalesce(cd.cumulat,0) cumulat,
          CASE WHEN cd.codcriteriu IS NULL THEN Coalesce(i1d.ContDiscount,0) ELSE 0 END ContDiscount
        FROM doc i
          INNER JOIN iesiri1      i1d ON i1d.codies = i.codies AND i1d.tiplinie     IN (&apos;G&apos;,&apos;T&apos;)
          INNER JOIN iesiri1      i1a ON i1a.codies = i.codies AND i1a.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;) AND i1a.indexlocal &lt; i1d.indexlocal
          LEFT JOIN  criteriidisc cd  ON cd.codcriteriu = i1d.codcriteriu
        WHERE CASE
                WHEN i1d.tiplinie &lt;&gt; &apos;G&apos; THEN 0
                WHEN (SELECT Max(a.indexlocal) FROM iesiri1 a WHERE a.codies = i.codies AND a.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;) AND a.indexlocal &gt;= i1a.indexlocal AND a.indexlocal &lt;  i1d.indexlocal) &gt;
                     (SELECT Min(b.indexlocal) FROM iesiri1 b WHERE b.codies = i.codies AND b.tiplinie     IN (&apos;G&apos;,&apos;T&apos;) AND b.indexlocal &gt;  i1a.indexlocal AND b.indexlocal &lt;= i1d.indexlocal)
                THEN 1
                ELSE 0
              END = 0
          AND NOT Coalesce(i1a.taxa, 0) IN (3, 4, 5)
      ),
      dy (codies1, codiesd, codcriteriu, contdiscount, idx, du, dtva, proc, cumulat, vRot, bd, d, t, d0, d1, d2) AS (
        SELECT
          dx.codies1, dx.codiesd, dx.codcriteriu, dx.contdiscount, dx.idx, dx.du, dx.dtva, dx.proc, dx.cumulat, dx.vRot,
          Round(
            CASE dx.cumulat
              WHEN 0 THEN dx.pu+dx.du
              WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END
              WHEN 2 THEN dx.pu+dx.du
              ELSE 0
            END*dx.cant,
            dx.vRot
          ) bd,
          Round(
            CASE dx.cumulat
              WHEN 0 THEN dx.pu+dx.du
              WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END
              WHEN 2 THEN dx.pu+dx.du
              ELSE 0
            END*dx.cant*dx.proc/100,
            dx.vRot
          ) d,
          Round(
            CASE
              WHEN dx.pu = 0                    THEN 0
              WHEN dx.cumulat = 1 AND vDBPO = 1 THEN Round(dx.pretorig*dx.tva/dx.pu, dx.vRot)
              WHEN dx.cumulat = 1               THEN dx.tva
              ELSE                                   dx.tva + dx.dtva
            END*dx.proc/100,
            dx.vRot
          ) t,
          CASE dx.cumulat WHEN 0 THEN dx.pu+dx.du                                         ELSE 0 END*dx.proc/100 d0,
          CASE dx.cumulat WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END ELSE 0 END*dx.proc/100 d1,
          CASE dx.cumulat WHEN 2 THEN dx.pu+dx.du                                         ELSE 0 END*dx.proc/100 d2
        FROM dx
        WHERE idx=1
        UNION ALL
        SELECT
          dx.codies1, dx.codiesd, dx.codcriteriu, dx.contdiscount, dx.idx, dx.du, dx.dtva, dx.proc, dx.cumulat, dx.vRot,
          Round(
            CASE dx.cumulat
              WHEN 0 THEN dx.pu+dy.du+dy.d0+dy.d1+dy.d2
              WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END +dy.d0+dy.d2
              WHEN 2 THEN dx.pu+dy.du+dy.d0+dy.d1
              ELSE 0
            END * dx.cant,
            dx.vRot
          ) bd,
          Round(
            CASE dx.cumulat
              WHEN 0 THEN dx.pu+dy.du+dy.d0+dy.d1+dy.d2
              WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END +dy.d0+dy.d2
              WHEN 2 THEN dx.pu+dy.du+dy.d0+dy.d1
              ELSE 0
            END*dx.cant*dx.proc/100,
            dx.vRot
          ) d,
          Round(
            CASE dx.cumulat
              WHEN 0 THEN dx.pu+dy.du+dy.d0+dy.d1+dy.d2
              WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END +dy.d0+dy.d2
              WHEN 2 THEN dx.pu+dy.du+dy.d0+dy.d1
              ELSE 0
            END * CASE WHEN dx.pu = 0 THEN 0 ELSE dx.proc/100*dx.tva/dx.pu END,
            dx.vRot
          ) t,
          CASE dx.cumulat WHEN 0 THEN dx.pu+dx.du+dy.d0+dy.d1+dy.d2                                   ELSE 0 END*dx.proc/100 + dy.d0 d0,
          CASE dx.cumulat WHEN 1 THEN CASE vDBPO WHEN &apos;1&apos; THEN dx.pretorig ELSE dx.pu END+dy.d0+dy.d2 ELSE 0 END*dx.proc/100 + dy.d1 d1,
          CASE dx.cumulat WHEN 2 THEN dx.pu+dx.du+dy.d0+dy.d1                                         ELSE 0 END*dx.proc/100 + dy.d2 d2
        FROM dy INNER JOIN dx ON dx.codies1 = dy.codies1 AND dx.idx = dy.idx + 1
      ),
      dz AS (
        SELECT
          Row_Number() OVER (PARTITION BY dy.codiesd ORDER BY dy.codies1) LinIdx,
          Count(1)     OVER (PARTITION BY dy.codiesd)                     LinCnt,
          dy.codies1, dy.codiesd, dy.d, dy.t,
          i1d.restfact sum_d_real, Sum(dy.d) OVER (PARTITION BY dy.codiesd) sum_d_calc,
          i1d.tva      sum_t_real, Sum(dy.t) OVER (PARTITION BY dy.codiesd) sum_t_calc
        FROM DY INNER JOIN IESIRI1 i1d ON i1d.codies1 = dy.codiesd
      ),
      d AS (
        SELECT
          codies1, codiesd, d, t,
          CASE WHEN LinCnt = 1 THEN sum_d_real ELSE d END + CASE WHEN LinCnt = 1 THEN 0 WHEN LinIdx &gt; 1 THEN 0 ELSE sum_d_real - sum_d_calc END valdisc_r,
          CASE WHEN LinCnt = 1 THEN sum_t_real ELSE t END + CASE WHEN LinCnt = 1 THEN 0 WHEN LinIdx &gt; 1 THEN 0 ELSE sum_t_real - sum_t_calc END valtva_r
        FROM dz
      ),
      doc1 AS (
        SELECT
          i1.codies, i1.codies1, i1.tiplinie, i1.indexlocal,
          Round(i1.pu*i1.cant*(1+Coalesce(i1.procdisc/100,0)),doc.vRot) LinVal, Sum(Coalesce(d.valdisc_r,0)) DiscVal, Sum(Coalesce(d.d,0)) dv_calc,
          Round(i1.tva       *(1+Coalesce(i1.procdisc/100,0)),doc.vRot) LinTVA, Sum(Coalesce(d.valtva_r ,0)) DiscTVA, Sum(Coalesce(d.t,0)) dt_calc
        FROM doc
          LEFT JOIN iesiri1 i1 ON i1.codies = doc.codies
          LEFT JOIN d          ON d.codies1 = i1.codies1
        WHERE i1.tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;)
        GROUP BY
          doc.vRot,
          i1.codies, i1.codies1, i1.tiplinie, i1.indexlocal,
          i1.pretorig, i1.pu, i1.cant, i1.coefdiscmaj, i1.addim, i1.procdisc, i1.tva
      )
    SELECT CodIes1, LinVal, LinTVA, DiscVal, DiscTVA, DV_Calc, DT_Calc
    FROM doc1;
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>INCARCA_XML</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A74AF917D1F32FC417CF1D7D6842D9DA6D3118ED</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE INCARCA_XML(pTableName VARCHAR2, cXML CLOB) IS
  dbVer VARCHAR2(20);

  PROCEDURE INCARCA_XML_MOD1 IS
    insCtx DBMS_XMLSTORE.ctxType;
    vCount NUMBER;
  BEGIN
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||pTableName;
    insCtx := DBMS_XMLSTORE.newContext(pTableName); -- Get saved context
    DBMS_XMLSTORE.clearUpdateColumnList(insCtx);    -- Clear the update settings

    -- Set the columns to be updated as a list of values
    FOR vRec IN (
      SELECT column_name
      FROM USER_TAB_COLUMNS
      WHERE TABLE_NAME = pTableName
      ORDER BY COLUMN_ID
    ) LOOP
      DBMS_XMLSTORE.setUpdateColumn(insCtx, vRec.column_name);
    END LOOP;
    -- Insert the doc.
    vCount := DBMS_XMLSTORE.insertXML(insCtx, cXML);
    -- Close the context
    DBMS_XMLSTORE.closeContext(insCtx);
    COMMIT;
  END;

  PROCEDURE INCARCA_XML_MOD2 IS
    varSQL  CLOB;
  BEGIN
    varSQL :=
      &apos;DECLARE
        varXML XMLTYPE;
      BEGIN
        varXML:=:refXML;

        INSERT INTO &apos;||pTableName||&apos;
        SELECT *
        FROM XMLTABLE (&apos;&apos;/ROWSET/ROW&apos;&apos; PASSING varXML
            COLUMNS&apos;;
    FOR vRec IN (
      SELECT
        column_id,
        column_name||&apos; &apos;||data_type||
        CASE
          WHEN data_type IN (&apos;VARCHAR2&apos;,&apos;VARCHAR&apos;,&apos;CHAR&apos;) THEN &apos;(&apos;||data_length||&apos;)&apos;
          WHEN data_precision IS NOT NULL THEN &apos;(&apos;||data_precision||&apos;,&apos;||data_scale||&apos;)&apos;
        END||
        &apos; PATH &apos;&apos;&apos;||column_name||&apos;&apos;&apos;&apos; xmlcol
      FROM USER_TAB_COLUMNS
      WHERE TABLE_NAME = pTableName
      ORDER BY COLUMN_ID
    ) LOOP
      varSQL := varSQL||CASE WHEN vRec.column_id &gt; 1 THEN &apos;,&apos; END||&apos;
              &apos;||vRec.xmlcol;
    END LOOP;
    varSQL := varSQL||&apos;
        );
        COMMIT;
      END;&apos;;

    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||pTableName;
    EXECUTE IMMEDIATE varSQL USING xmltype(cXML);
  END;
BEGIN
  SELECT Max(version)
  INTO dbVer
  FROM PRODUCT_COMPONENT_VERSION
  WHERE Upper(SubStr(PRODUCT,1,15)) = &apos;ORACLE DATABASE&apos; ;

  IF SubStr(dbVer,1,8) IN ( &apos;11.2.0.4&apos;, &apos;12.1.0.2&apos; )
  THEN INCARCA_XML_MOD2;
  ELSE INCARCA_XML_MOD1;
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>LIST_BAGA_DINAMIC_COLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EECF7323980633EB329B1D467569155B2E045494</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE LIST_BAGA_DINAMIC_COLS (aListID IN NUMBER) IS
  vListId NUMBER := Coalesce(aListId, 0);
BEGIN
  IF    vListId IN (13, 137, 190 ) THEN
    PKG_LIST_BASE_DISTRIBSTOC.BAGA_DINAMIC_COLS;
  ELSIF vListId =  35 THEN
    IF PKG_LIST_SELECTPERIOADA.optiunea1 THEN PKG_LIST_BASE_SINTTREZ.BAGA_DINAMIC_COLS; END IF;
  ELSIF vListId =  45 THEN
    IF PKG_LIST_ALEGPERIOADA.optiunea3 THEN PKG_LIST_BASE_COMANDA.BAGA_DINAMIC_COLS; END IF;  
  ELSIF vListId =  38 THEN
    PKG_LIST_BASE_FISASAH.BagaDinamicCols;
  ELSIF vListId IN (73, 74, 75, 76, 157) THEN
    PKG_LIST_BASE_VANZPER.BAGA_DINAMIC_COLS;
  ELSIF vListId = 165 THEN
    PKG_LIST_BASE_MONETAREMP.BAGA_DINAMIC_COLS;
  ELSIF vListId = 204 THEN
    IF PKG_LIST_BASE_REALGEST.GetDetLunara OR PKG_LIST_BASE_REALGEST.GetDetCCost THEN PKG_LIST_BASE_REALGEST2.BAGA_DINAMIC_COLS; END IF;
  ELSIF vListId = 219 THEN
    PKG_LIST_BASE_RAPSTOC.BagaDinamicCols;
  ELSIF vListId = 286 THEN
    PKG_LIST_BASE_FISACONT2.BAGA_DINAMIC_COLS;
  ELSIF vListId = 395 THEN
    PKG_LIST_BASE_ACHIZFURNART.BAGA_DINAMIC_COLS;
  ELSIF vListId = 405 THEN
    PKG_LIST_BASE_SCADCHELTAVANS.BAGA_DINAMIC_COLS;
  ELSIF vListId = 488 THEN
    PKG_LIST_BASE_SITBONRETAILSINT.BAGA_DINAMIC_COLS;
  END IF;
END LIST_BAGA_DINAMIC_COLS;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>LIST_EXECUTE_IMMEDIATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47928D2826609C9F79F0126BF51414CB44E8FB34</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE LIST_EXECUTE_IMMEDIATE (aSQL CLOB, aListID IN NUMBER, aListVer IN NUMBER) IS

  PROCEDURE SQL_INSERT IS
  BEGIN
    INSERT INTO debug_liste(userid, sql_lista, listid, listver, sql_time) VALUES ( PKG_GLOBALS.getuserid, aSQL, aListID, aListVer, CURRENT_TIMESTAMP);
    COMMIT;
  END;

BEGIN
  IF COALESCE(PKG_GLOBALS.ISDEBUGMODE,0) = 1
  THEN SQL_INSERT;
  END IF;

  BEGIN
    EXECUTE IMMEDIATE aSQL;
  EXCEPTION
    WHEN OTHERS THEN
      IF COALESCE(PKG_GLOBALS.ISDEBUGMODE,0) = 0
      THEN SQL_INSERT;
      END IF;
      RAISE;
  END;
END LIST_EXECUTE_IMMEDIATE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>MONETARE_CALC_DISCLIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55BF20C92E29038143BCCCC9F33F26369DBFEC9C</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE MONETARE_CALC_DISCLIN(pCodIes IN NUMBER) IS
  vTipDoc      NUMBER;
  vAN          NUMBER;
  vLuna        NUMBER;
  vCoteDisc    NUMBER;
  vCIntermedCM NUMBER;
  vConIncFact  NUMBER;
  sArtExcl     VARCHAR2(4000);
BEGIN
-- FLAG PT PG -&gt; &apos;TMP_MON_DISCLIN&apos;
  TRUNCATE_TABLE(&apos;TMP_MON_DISCLIN&apos;);
  TRUNCATE_TABLE(&apos;TMP_MON_DISCPROC&apos;);
  BEGIN
    SELECT TipDoc, An, Luna INTO vTipDoc, vAN, vLuna FROM iesiri WHERE codies = pCodIes;
  EXCEPTION WHEN OTHERS THEN
    vTipDoc := 0;
  END;

  IF vTipDoc IN (16) THEN
    SELECT Count(1) INTO vCoteDisc
    FROM discmonetar
    WHERE codies = pCodIes;

    INSERT INTO TMP_MON_DISCLIN (CodIes1, CodObiect, ProcTVA, Calc, LinVal, LinTVA, DiscVal, DiscTVA)
    SELECT
      i1.CodIes1, i1.CodObiect,
      CASE
        WHEN (i1.cant*i1.pu-i1.tva) = 0 THEN 0
        ELSE PKG_LIST_BASE_UTILS.MATCH_TVA_PROC(i1.tva*100/(i1.cant*i1.pu-i1.tva), i.An*12+i.Luna)
      END ProcTVA,
      CASE
        WHEN (i1.cant*i1.pu-i1.tva) = 0       THEN 0
        WHEN i1.tiplinie = &apos;V&apos;                THEN 0
        WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 0
        ELSE                                       1
      END Calc,
      i1.pu*i1.cant LinVal, i1.tva LinTVA,
      Coalesce(i1.valdiscpret,0) DiscVal, Coalesce(i1.tva*i1.valdiscpret/NullIF(i1.pu*i1.cant,0), 0) DiscTVA
    FROM iesiri i inner join iesiri1 i1 ON i1.codies = i.codies
    WHERE i.codies = pCodIes;

    IF vCoteDisc = 0 THEN
      UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE Calc = -1;
    ELSE
      pkg_globals.SetSeparator(&apos;,&apos;);
      SELECT STRING_AGG(x) INTO sArtExcl
      FROM (
        SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtFaraDiscMonetar&apos;,vAn,vLuna),&apos;0&apos;) x FROM dual UNION
        SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasImediat&apos;   ,vAn,vLuna),&apos;0&apos;) x FROM dual UNION
        SELECT Coalesce(pkg_categconst.GetValConstanta(&apos;ArtIncasUlterior&apos;  ,vAn,vLuna),&apos;0&apos;) x FROM dual
      );
      IF NULLIF(sArtExcl, &apos;&apos;) IS NOT NULL THEN
        sArtExcl := &apos;,&apos;||sArtExcl||&apos;,&apos;;
        UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE Calc = -1 AND InStr(sArtExcl, &apos;,&apos;||CodObiect||&apos;,&apos;) &gt; 0;
      END IF;

      vCIntermedCM := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;CIntermedCM&apos;        ,vAn,vLuna),&apos;-1&apos;));
      IF vCIntermedCM &gt; 0 THEN
        UPDATE TMP_MON_DISCLIN SET Calc = 0
        WHERE Calc = -1
          AND Codies1 IN (
            SELECT CodIes1
            FROM Iesiri1
            WHERE CodIes = pCodIes AND Coalesce(ContServ,-1) = vCIntermedCM
          );
      END IF;

      vConIncFact  := To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;ContIncasareFactura&apos;,vAn,vLuna),&apos;-1&apos;));
      IF vConIncFact &gt; 0 THEN
        UPDATE TMP_MON_DISCLIN SET Calc = 0
        WHERE Calc = -1
          AND Codies1 IN (
            SELECT CodIes1
            FROM LIVR L
              INNER JOIN LIVR1   L1 ON L1.Codlivr    = L.CodLivr
              LEFT  JOIN LIVRVAL LV ON LV.CodLivr1   = L1.CodLivr1
              LEFT  JOIN NIRSTOC NS ON NS.CodNirStoc = L1.CodNirStoc
            WHERE L.TipLivr = 16 AND L.CodIes = pCodIes AND Coalesce(NS.CodIoart,LV.CodIoart, 0) = vConIncFact
          );
      END IF;

      INSERT INTO TMP_MON_DISCPROC (ProcTVA, REST_VAL, REST_TVA, DTOT_VAL, DTOT_TVA, DREP_VAL, DREP_TVA)
      SELECT dm.ProcTVA, di1.REST_VAL, di1.REST_TVA, dm.DISCOUNT, dm.TVADISCOUNT, di1.DREP_VAL, di1.DREP_TVA
      FROM discmonetar dm
        LEFT JOIN (
          SELECT
            ProcTVA,
            Sum(CASE WHEN CALC = 1 THEN LINVAL ELSE 0  END) REST_VAL,
            Sum(CASE WHEN CALC = 1 THEN LINTVA ELSE 0  END) REST_TVA,
            Sum(CASE WHEN CALC = 1 THEN 0 ELSE DISCVAL END) DREP_VAL,
            Sum(CASE WHEN CALC = 1 THEN 0 ELSE DISCTVA END) DREP_TVA
          FROM TMP_MON_DISCLIN
          GROUP BY ProcTVA
        ) di1 ON di1.ProcTVA = dm.ProcTVA
      WHERE dm.Codies = pCodIes;
    END IF;

    UPDATE TMP_MON_DISCLIN SET Calc = 0 WHERE NOT ProcTVA IN (SELECT DISTINCT ProcTVA FROM TMP_MON_DISCPROC);

    UPDATE TMP_MON_DISCLIN DL
    SET (DiscVal, DiscTVA) =
        (SELECT LINVAL*(DTOT_VAL-DREP_VAL)/REST_VAL, LINTVA*(DTOT_TVA-DREP_TVA)/REST_TVA
         FROM TMP_MON_DISCPROC DP
         WHERE DP.ProcTVA = DL.ProcTVA  )
    WHERE Calc = 1;

  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>NEUTRALIZARE_GDPR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3066A8954327842D22ED12AD2284367ED6B527D0</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE NEUTRALIZARE_GDPR(pSkemaFirma IN VARCHAR2) AS
  cUpdate CLOB;
  sSkema  VARCHAR2(128) := Upper(pSkemaFirma);

  PROCEDURE Curata(pTable IN VARCHAR2, pCols IN VARCHAR2, pWhere IN VARCHAR2, pTip IN NUMBER DEFAULT 0 ) IS
    sTable  VARCHAR2(128)  := Upper(pTable);
    sCols   VARCHAR2(3000) := &apos;,&apos;||REPLACE(Upper(pCols),&apos; &apos;)||&apos;,&apos;;
    vCount  NUMBER         := 0;
    vCodId  NUMBER;
    vCodDen VARCHAR2(100);
    vCodLen NUMBER;
  BEGIN
    SELECT Coalesce(Max(COLUMN_ID), 0), Max(COLUMN_NAME), Max(data_precision)
    INTO vCodId, vCodDen, vCodLen 
    FROM all_tab_columns
    WHERE owner = sSkema AND table_name = sTable AND COLUMN_ID = 1 AND data_type = &apos;NUMBER&apos;;

    FOR vRec IN (
      SELECT
        column_name, 
        CASE
          WHEN pTip = 1 THEN &apos;&apos;&apos;0&apos;&apos;&apos; 
          WHEN vCodId = 0 THEN &apos;NULL&apos;
          WHEN DATA_TYPE IN (&apos;VARCHAR2&apos;,&apos;VARCHAR&apos;,&apos;CHAR&apos;) THEN &apos;Substr(&apos;||vCodDen||&apos;, 1, &apos;||CHAR_LENGTH||&apos;)&apos;
          WHEN Coalesce(data_precision, 0) &gt;= vCodLen THEN vCodDen
          WHEN data_precision IS NOT NULL THEN &apos;&apos;&apos;0&apos;&apos;&apos; 
          ELSE &apos;NULL&apos;
        END NewVal   
      FROM all_tab_columns
      WHERE owner = sSkema AND table_name = sTable
        AND InStr(sCols, &apos;,&apos;||column_name||&apos;,&apos;) &gt; 0
      ORDER BY COLUMN_ID
    ) LOOP
      vCount := vCount + 1;
      IF vCount = 1 THEN
        cUpdate := &apos;UPDATE &apos;||sSkema||&apos;.&apos;||sTable||&apos; SET &apos;||vRec.column_name||&apos; = &apos;||vRec.NewVal;
      ELSE
        cUpdate := cUpdate ||&apos;, &apos;||vRec.column_name||&apos; = &apos;||vRec.NewVal;
      END IF;
    END LOOP;
    IF vCount &gt; 0 THEN
      IF pWhere IS NOT NULL THEN
        cUpdate := cUpdate||&apos; &apos;||pWhere;
      END IF;
      EXECUTE IMMEDIATE cUpdate;
      COMMIT;
    END IF;
  END;

  PROCEDURE Goleste(pTable IN VARCHAR2) IS
    sTable  VARCHAR2(128)  := Upper(pTable);
  BEGIN
    EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||sSkema||&apos;.&apos;||sTable;
  EXCEPTION WHEN OTHERS THEN NULL;
  END;

BEGIN
  --nomenclator personal
  Curata(&apos;NPERS&apos;,   &apos;CNP,BISERIA,BINR,ADRESA,PRENUMET,PRENUMEM,DATAN,BIELIBERATDE,LADATADE  &apos;, &apos;&apos;);
  Curata(&apos;NAGENDA&apos;, &apos;TELEFON,FAX,EMAIL,SECTOR,STRADA,NR1,NR2,BLOC,SCARA,ETAJ,APART,CODPOSTAL,CODFISCAL&apos;, &apos;WHERE codagenda &lt;&gt; 0 AND codagenda IN (SELECT AGENDA FROM &apos;||sSkema||&apos;.&apos;||&apos;NPERS)&apos;);

  --Log email
  Goleste(&apos;MAILURI1&apos;);
  Goleste(&apos;MAILURI&apos;);

  --nomenclator delegati
  Curata(&apos;NPARTTR&apos;, &apos;CNP,DOC,SERIEDOC,NRDOC,ELIBERAT,MIJLTRANSP,NRTRANSP,DATADOC,PERMIS,NRPASS,TELEFON,EMAIL&apos;, &apos;&apos;);

  --nomenclator parteneri cu tip &quot;persoana fizica&quot; -&gt; CNP, data nastere, tip, serie si nr buletin, permis, pasaport, mailuri, conturi bancare
  Curata(&apos;NPART&apos;,   &apos;DATANASTERE&apos;, &apos;WHERE Coalesce(Persoanafizica, 0) = 1&apos;);
  Curata(&apos;NPARTCODFISC&apos;,  &apos;CODFISCAL&apos;, &apos;WHERE codpart IN (SELECT CODPART FROM &apos;||sSkema||&apos;.&apos;||&apos;NPART WHERE Coalesce(Persoanafizica, 0) = 1)&apos;, 1);
  --Curata(&apos;NPARTTR&apos;, &apos;CNP,DOC,SERIEDOC,NRDOC,ELIBERAT,DATADOC,PERMIS,NRPASS&apos;, &apos;WHERE codpart IN (SELECT CODPART FROM &apos;||sSkema||&apos;.&apos;||&apos;NPART WHERE Coalesce(Persoanafizica, 0) = 1)&apos;);
  Curata(&apos;NAGENDA&apos;, &apos;TELEFON,FAX,EMAIL,CODFISCAL&apos;,  &apos;WHERE codagenda &lt;&gt; 0 AND codpart IN (SELECT CODPART FROM &apos;||sSkema||&apos;.&apos;||&apos;NPART WHERE Coalesce(Persoanafizica, 0) = 1)&apos;);
  Curata(&apos;NPARTB&apos;,  &apos;CONTBANCA,CODSWIFT&apos;, &apos;WHERE codpart IN (SELECT CODPART FROM &apos;||sSkema||&apos;.&apos;||&apos;NPART WHERE Coalesce(Persoanafizica, 0) = 1)&apos;);
  --nomenclator parteneri &gt; persoane de contact -&gt; mail, telefon, data nasterii
  Curata(&apos;NPERSCONTACT&apos;,   &apos;TELEFON,EMAIL,DATANASTERE,SERIEBI,NRBI,ELIBERATBI,DATABI,CNP&apos;, &apos;&apos;);

  --d39416
  Curata(&apos;D39416RNS2&apos;,   &apos;CUI,CODLOCALIT,STRP,NRP,BLP,APP&apos;, &apos;WHERE CUIVALID IN (5,6,7)&apos;, 1);
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>NOTIFYMODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>440C5F26A5BAEE611FA341D2E887576A4A5EF285</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE NotifyModif(aTip in Number, aCodDoc in NUMBER, aTABLENAME IN VARCHAR2 ) IS
COD number(20);
Nume varchar2(20);
/* 
TIPMODIF :
-13 - Monitorizare preluari de date de la RETAIL. CodMaster = codpostretail; TABLENAME = PRELUARE RETAIL
-12- Preluari de la RETAIL (modificari)
-11- Preluari de la RETAIL (adaugare)
-10- Import RESTSERVER
-4 - Import eFact clienti
-3 - Import eFact furnizori
-2 - AfterCommit
-1 - Import (alte module)
 0 - Modificare
 1 - Adaugare
 2 - Stergere
 3 - eFactura
 4 - Modificare rezervare
 5 - Constatari WMS
 7 - Anulare inchidere luna   CodMaster = An*12 + Luna, TABLENAME = Anulare
 8 - Inchidere luna           CodMaster = An*12 + Luna, TABLENAME = Inchidere
     select (CodMaster/12-Trunc(CodMaster/12))*12 lunaInchisa, Trunc(CodMaster/12) AnInchis from modificari where tipmodif = 8;
		 
 9 - Monitorizare Liste CODMASTER = ListID, la Create: TABLENAME = START, la final  TABLENAME = Durata in secunde sau minute!
 10 - regenerare inventar
 11 - modificare sold factura
*/
begin
  Nume := Upper(aTABLENAME );
	Cod := SEQ_MODIFICARI_CODMODIFICARE.NextVal;
  Insert into Modificari (	CODMODIFICARE, CODMASTER, TABLENAME, DATAMODIF, USERMODIF, TIPMODIF)
  Values (Cod, aCodDoc, Nume, Sysdate, PKG_GLOBALS.GETMASTER_OR_USERID, aTip);
/*
  Update Modi_State set MODIDATE = SysDate, TipModif = aTip where CODMASTER = aCodDoc and TableName = Nume;
  if SQL%ROWCOUNT = 0 then 
		Insert into Modi_State (	CodModi_State, CODMASTER, TABLENAME, MODIDATE, TIPMODIF)
		Values (Cod, aCodDoc, Nume, SysDate, aTip);
	end if;
*/
end; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PRC_AL_CHECK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE570D2B97ACDE79962B1FC970E3BE68CF24ACE2</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PRC_AL_CHECK(pTable IN VARCHAR2, pCod IN NUMBER DEFAULT 0) AS
  vRefresh NUMERIC;
  sALStart VARCHAR2(50);
  sALStop  VARCHAR2(50);
  sCol2    VARCHAR2(50);
  sAnd     VARCHAR2(200) := &apos;&apos;;
BEGIN
  BEGIN
    SELECT COLUMN_NAME INTO sALStart FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_NAME IN (&apos;ALSTART&apos;, &apos;ANLUNASTART&apos;);
    SELECT COLUMN_NAME INTO sALStop  FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_NAME IN (&apos;ALSTOP&apos;,  &apos;ANLUNASTOP&apos;);
  EXCEPTION
    WHEN No_Data_Found THEN RETURN;
  END;

  IF Coalesce(pCod, 0) &lt;&gt; 0 THEN
    SELECT COLUMN_NAME INTO sCol2 FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_ID = 2;
    sAnd := &apos; AND A.&apos;||sCol2||&apos; = &apos;||To_Char(pCod, &apos;fm9999999999999999999999&apos;);
  END IF;

  EXECUTE IMMEDIATE &apos;SELECT CASE WHEN EXISTS(SELECT 1 FROM &apos;||pTable||&apos; A WHERE (A.&apos;||sALStart||&apos; IS NULL OR A.&apos;||sALStop||&apos; IS NULL)&apos;||sAnd||&apos;) THEN 1 ELSE 0 END FROM DUAL&apos; INTO vRefresh;
  IF vRefresh = 1 THEN
    PRC_AL_REFRESH(pTable, pCod);
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PRC_AL_REFRESH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4630B1758423BF842A6F25869454CFB8826DCF38</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PRC_AL_REFRESH(pTable IN VARCHAR2, pCod IN NUMBER DEFAULT 0) AS
  sSQL       CLOB;
  sWhere     CLOB;
  sCol1      VARCHAR2( 50);
  sCol2      VARCHAR2( 50);
  sPartition VARCHAR2(200);
  sALIni     VARCHAR2( 50);
  sALStart   VARCHAR2( 50);
  sALStop    VARCHAR2( 50);
BEGIN
  BEGIN
    SELECT COLUMN_NAME INTO sALStart FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_NAME IN (&apos;ALSTART&apos;, &apos;ANLUNASTART&apos;);
    SELECT COLUMN_NAME INTO sALStop  FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_NAME IN (&apos;ALSTOP&apos;,  &apos;ANLUNASTOP&apos;);
  EXCEPTION
    WHEN No_Data_Found THEN RETURN;
  END;

  SELECT COLUMN_NAME INTO sCol1 FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_ID = 1;
  SELECT COLUMN_NAME INTO sCol2 FROM user_tab_columns WHERE TABLE_NAME = Upper(pTable) AND COLUMN_ID = 2;

  sWhere := &apos;
  WHERE A.&apos;||sCol2||&apos; = &apos;||To_Char(pCod, &apos;fm9999999999999999999999&apos;);
  IF pCod = 0 THEN
    sWhere := &apos;&apos;;
  END IF;

  sPartition := &apos;A.&apos;||sCol2;
  IF Upper(pTable) IN (&apos;CONSTLUNA&apos;, &apos;TMP_CONSTLUNA&apos;) THEN
    sPartition := sPartition ||&apos;, A.USERID&apos;;
  END IF;

  SELECT To_Char(ANINITIAL*12+LUNAINITIALA, &apos;fm99999&apos;) INTO sALIni FROM FIRMALUNI;

  sSQL := &apos;
  INSERT INTO TMP_AL_REFRESH(COD, CODP, ALSTART, ALSTOP)
  SELECT
    A.&apos;||sCol1||&apos;, A.&apos;||sCol2||&apos;,
    CASE
      WHEN LAG(Coalesce(A.ANSTART*12+A.LUNASTART,0)) OVER (PARTITION BY &apos;||sPartition||&apos; ORDER BY Coalesce(A.ANSTART*12+A.LUNASTART,0)) IS NOT NULL THEN A.ANSTART*12+A.LUNASTART
      WHEN Coalesce(A.ANSTART*12+A.LUNASTART,0) = &apos;||sALIni||&apos; THEN 0
      ELSE Coalesce(A.ANSTART*12+A.LUNASTART,0)
    END ALSTART,
    Coalesce(LEAD(Coalesce(A.ANSTART*12+A.LUNASTART,0)) OVER (PARTITION BY &apos;||sPartition||&apos; ORDER BY Coalesce(A.ANSTART*12+A.LUNASTART,0)) - 1,99999) ALSTOP
  FROM &apos;||pTable||&apos; A&apos;||
  sWhere;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_AL_REFRESH&apos;;
  EXECUTE IMMEDIATE sSQL;

  sSQL := &apos;UPDATE &apos;||pTable||&apos; A
  SET (&apos;||sALStart||&apos;,&apos;||sALStop||&apos;) = (SELECT B.ALSTART, B.ALSTOP FROM TMP_AL_REFRESH B WHERE B.COD = A.&apos;||sCol1||&apos;)&apos;||
  sWhere;

  EXECUTE IMMEDIATE sSQL;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PRC_MAKECODIDENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBFA11EEE9F11D96C3DC89927063224CEDB1729C</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PRC_MAKECODIDENT(pTabName IN VARCHAR2, pColCod IN VARCHAR2) AS
  cSQL CLOB;
BEGIN
  cSQL := &apos;INSERT INTO TMP_&apos;||pTabName||&apos;(&apos;||pColCod||&apos;, CODIDENT)
  WITH a(&apos;||pColCod||&apos;, CODIDENT) AS (
    -- Anchor member.
    SELECT &apos;||pColCod||&apos;, To_Char(&apos;||pColCod||&apos;) CODIDENT
    FROM   &apos;||pTabName||&apos;
    WHERE  Coalesce(codparinte,0) = 0 AND &apos;||pColCod||&apos; &gt; 0
    UNION ALL
    SELECT ca.&apos;||pColCod||&apos;, a.CODIDENT||&apos;&apos;.&apos;&apos;||To_Char(ca.&apos;||pColCod||&apos;) CODIDENT
    FROM   &apos;||pTabName||&apos; ca
    INNER JOIN a ON a.&apos;||pColCod||&apos; = ca.CODPARINTE
  )
  SELECT &apos;||pColCod||&apos;, CODIDENT
  FROM a&apos;;

  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_&apos;||pTabName;
  EXECUTE IMMEDIATE cSQL;
  EXECUTE IMMEDIATE &apos;UPDATE &apos;||pTabName||&apos; A SET CODIDENT = (SELECT B.CODIDENT FROM TMP_&apos;||pTabName||&apos; B WHERE B.&apos;||pColCod||&apos; = A.&apos;||pColCod||&apos;)&apos;;
  COMMIT;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PREGATIRE_INCARCARE_STRUCT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5266D54FC27E94039E1B6B170C85535E69F2F854</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PREGATIRE_INCARCARE_STRUCT ( cDDL_Hash CLOB ) IS
-- PROCEDURA SPECIALA PENTRU INCARCAREA STUCTURILOR DE TIP MARTOR
  vCnt PLS_INTEGER;
BEGIN
  --VERIFICARE EXISTENTA TABELA HASH
  SELECT Count(1) INTO vCnt FROM USER_TABLES WHERE TABLE_NAME = &apos;SRC_SCRIPTS_HASH&apos;;

  IF vCnt = 0 THEN
    EXECUTE IMMEDIATE &apos;CREATE TABLE SRC_SCRIPTS_HASH(TYPE VARCHAR2(30), NAME VARCHAR2(30), TEMP VARCHAR2(1), REFTABLE  VARCHAR2(30), HASHVAL VARCHAR2(64), HASHNEW VARCHAR2(64) ) TABLESPACE WMDATA&apos;;
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PROCESS_TMP_LST_EXTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACBF1AE4773E8EB7826F15A131C74E97288BD81F</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PROCESS_TMP_LST_EXTERNE IS
BEGIN
  FOR vRec IN (SELECT SqlText, ListId, ListVER FROM TMP_LST_EXTERNE ORDER BY ORDINE)
  LOOP
    LIST_EXECUTE_IMMEDIATE (vRec.SqlText, vRec.ListId, vRec.ListVER);
  END LOOP;
END PROCESS_TMP_LST_EXTERNE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>PURGE_RECYCLEBIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0708AA91C9D9F14046A2AA9445BBBB981C494384</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE PURGE_RECYCLEBIN IS
BEGIN
  EXECUTE IMMEDIATE &apos;PURGE RECYCLEBIN&apos;;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_CSV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7113A40400E21E2292B0DC19D2D563330433F65</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_CSV(p_sql IN VARCHAR2, p_dir IN VARCHAR2, p_file IN VARCHAR2, DataStart in date DEFAULT null, DataStop in date DEFAULT null, p_header BOOLEAN DEFAULT FALSE) IS
  vFile   UTL_FILE.FILE_TYPE;
  vLine   VARCHAR2(32000);
  sVal    VARCHAR2(4000);
  nVal    NUMBER;
  dVal    DATE;
  D varchar2(30);
	mySQL clob;
  v_ret   NUMBER;
  curid   NUMBER;
  curres  NUMBER;
  col_cnt INTEGER;
  tDesc   DBMS_SQL.DESC_TAB;
BEGIN
  mySQL := p_SQL;
	if DataStart &lt;&gt; null then 
  	D := To_Char(DataStart,&apos;dd.mm.yyyy&apos;);
	  mySQL := Replace(MySQL, &apos;%DATASTART%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;); 
	end if;
	if DataStop &lt;&gt; null then 
  	D := To_Char(DataStop,&apos;dd.mm.yyyy&apos;);
	  mySQL := Replace(MySQL, &apos;%DATASTOP%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
	end if;

  curid := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(curid, mySQL, DBMS_SQL.NATIVE);
  curres := DBMS_SQL.EXECUTE(curid);
  DBMS_SQL.DESCRIBE_COLUMNS(curid, col_cnt, tDesc);

  vLine := &apos;&apos;;
  FOR i in 1..col_cnt
  LOOP
    IF    tDesc(i).col_type IN ( 1, 9, 96 ) THEN --VARCHAR;VARCHAR2;CHAR;
      DBMS_SQL.DEFINE_COLUMN(curid, i, sVal, 4000);
      vLine := vLine||trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSIF tDesc(i).col_type IN ( 2 )        THEN --NUMBER
      DBMS_SQL.DEFINE_COLUMN(curid, i, nVal);
      vLine := vLine||Trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSIF tDesc(i).col_type IN ( 12)        THEN --DATE
      DBMS_SQL.DEFINE_COLUMN(curid, i, dVal);
      vLine := vLine||Trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSE
      vLine := vLine||&apos;?,&apos;;-- tipuri de date nesuportate pentru moment
    END IF;
  END LOOP;
  vFile := UTL_FILE.FOPEN(UPPER(p_dir),p_file,&apos;W&apos;, 32767);

  IF p_header THEN
    UTL_FILE.PUT_LINE(vFile, vLine);
  END IF;

  LOOP
    v_ret := DBMS_SQL.FETCH_ROWS(curid);
    EXIT WHEN v_ret = 0;
    vLine := &apos;&apos;;
    FOR i IN 1..col_cnt LOOP
      IF    tDesc(i).col_type IN ( 1, 9, 96 ) THEN --VARCHAR;VARCHAR2;CHAR;
        DBMS_SQL.COLUMN_VALUE(curid,i,sVal);
        vLine := vLine||&apos;&quot;&apos;||sVal||&apos;&quot;,&apos;;
      ELSIF tDesc(i).col_type IN ( 2 )        THEN --NUMBER
        DBMS_SQL.COLUMN_VALUE(curid,i,nVal);
        vLine := vLine||nVal||&apos;,&apos;;
      ELSIF tDesc(i).col_type IN ( 12)        THEN --DATE
        DBMS_SQL.COLUMN_VALUE(curid,i,dVal);
        vLine := vLine||to_char(dVal,&apos;DD/MM/YYYY HH24:MI:SS&apos;)||&apos;,&apos;;
      ELSE
        NULL; -- tipuri de date nesuportate pentru moment
      END IF;
    END LOOP;
    UTL_FILE.PUT_LINE(vFile, vLine);
  END LOOP;
  UTL_FILE.FCLOSE(vFile);
  DBMS_SQL.CLOSE_CURSOR(curid);
END; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_CSV_BARLETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D20E9C1CE717FFDCBD81FF543013D1B005D31D1E</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_CSV_Barleta(p_sql IN VARCHAR2, p_dir IN VARCHAR2, p_file IN VARCHAR2, DataStart in date DEFAULT null, DataStop in date DEFAULT null, p_header BOOLEAN DEFAULT FALSE) IS
  vFile   UTL_FILE.FILE_TYPE;
  vLine   VARCHAR2(32000);
  sVal    VARCHAR2(4000);
  nVal    NUMBER;
  dVal    DATE;
  D varchar2(30);
  mySQL clob;
  v_ret   NUMBER;
  curid   NUMBER;
  curres  NUMBER;
  col_cnt INTEGER;
  tDesc   DBMS_SQL.DESC_TAB;
BEGIN
  mySQL := p_SQL;
  if DataStart &lt;&gt; null then
    D := To_Char(DataStart,&apos;dd.mm.yyyy&apos;);
    mySQL := Replace(MySQL, &apos;%DATASTART%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
  end if;
  if DataStop &lt;&gt; null then
    D := To_Char(DataStop,&apos;dd.mm.yyyy&apos;);
    mySQL := Replace(MySQL, &apos;%DATASTOP%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
  end if;

  curid := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(curid, mySQL, DBMS_SQL.NATIVE);
  curres := DBMS_SQL.EXECUTE(curid);
  DBMS_SQL.DESCRIBE_COLUMNS(curid, col_cnt, tDesc);

  vLine := &apos;&apos;;
  FOR i in 1..col_cnt
  LOOP
    IF    tDesc(i).col_type IN ( 1, 9, 96 ) THEN --VARCHAR;VARCHAR2;CHAR;
      DBMS_SQL.DEFINE_COLUMN(curid, i, sVal, 4000);
      vLine := vLine||trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSIF tDesc(i).col_type IN ( 2 )        THEN --NUMBER
      DBMS_SQL.DEFINE_COLUMN(curid, i, nVal);
      vLine := vLine||Trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSIF tDesc(i).col_type IN ( 12)        THEN --DATE
      DBMS_SQL.DEFINE_COLUMN(curid, i, dVal);
      vLine := vLine||Trim(tDesc(i).col_name)||&apos;,&apos;;
    ELSE
      vLine := vLine||&apos;?,&apos;;-- tipuri de date nesuportate pentru moment
    END IF;
  END LOOP;
  vFile := UTL_FILE.FOPEN(UPPER(p_dir),p_file,&apos;W&apos;, 32767);

  IF p_header THEN
    UTL_FILE.PUT_LINE(vFile, vLine);
  END IF;

  LOOP
    v_ret := DBMS_SQL.FETCH_ROWS(curid);
    EXIT WHEN v_ret = 0;
    vLine := &apos;&apos;;
    FOR i IN 1..col_cnt LOOP
      IF    tDesc(i).col_type IN ( 1, 9, 96 ) THEN --VARCHAR;VARCHAR2;CHAR;
        DBMS_SQL.COLUMN_VALUE(curid,i,sVal);
        vLine := vLine||&apos;&apos;||sVal||&apos;,&apos;;
      ELSIF tDesc(i).col_type IN ( 2 )        THEN --NUMBER
        DBMS_SQL.COLUMN_VALUE(curid,i,nVal);
        vLine := vLine|| TO_CHAR(nVal,&apos;fm9999999999990D009999&apos;) ||&apos;,&apos;;
      ELSIF tDesc(i).col_type IN ( 12)        THEN --DATE
        DBMS_SQL.COLUMN_VALUE(curid,i,dVal);
        vLine := vLine||to_char(dVal,&apos;DD/MM/YYYY HH24:MI:SS&apos;)||&apos;,&apos;;
      ELSE
        NULL; -- tipuri de date nesuportate pentru moment
      END IF;
    END LOOP;
    UTL_FILE.PUT_LINE(vFile, RTRIM(vLine,&apos;,&apos;));
  END LOOP;
  UTL_FILE.FCLOSE(vFile);
  DBMS_SQL.CLOSE_CURSOR(curid);
END;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_EXCEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32F93F28224E6DEA1427D0F79B9244A1497A4913</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_EXCEL(aSql IN VARCHAR2, aDir IN VARCHAR2, aName IN VARCHAR2, DataStart in date DEFAULT null, DataStop in date DEFAULT null) IS
  sFileName VARCHAR2(1000);
  MySQL clob;
	D varchar2(30);
  File UTL_FILE.FILE_TYPE;
BEGIN
--CREATE DIRECTORY EXP_HEINECKEN AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_HEINECKEN TO **USER**;
		mySQL := aSQL;
		if DataStart &lt;&gt; null then 
			D := To_Char(DataStart,&apos;dd.mm.yyyy&apos;);
			mySQL := Replace(MySQL, &apos;%DATASTART%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;); 
		end if;
		if DataStop &lt;&gt; null then 
			D := To_Char(DataStop,&apos;dd.mm.yyyy&apos;);
			mySQL := Replace(MySQL, &apos;%DATASTOP%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
		end if;

    sFileName := aName;
	  ORA_EXCEL.new_document;  
    ORA_EXCEL.set_1900_date_system;
 	  ORA_EXCEL.add_sheet(aName);  
	  ORA_EXCEL.query_to_sheet(mySQL);  
	  ORA_EXCEL.save_to_file(aDir, sFileName);  
END; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_TXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A678EB060C2780BA316CE7C4A51A5D72EC4C8482</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_TXT(aSql IN VARCHAR2, aDir IN VARCHAR2, aName IN VARCHAR2, DataStart in date DEFAULT null, DataStop in date DEFAULT null) IS
  sFileName VARCHAR2(1000);
  sSelect clob;
  mySQL clob;
	D varchar2(30);
	DD Date;
  File UTL_FILE.FILE_TYPE;
BEGIN
--CREATE DIRECTORY EXP_HEINECKEN AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_HEINECKEN TO **USER**;
  mySQL := aSQL;
	if DataStart &lt;&gt; null then 
		D := To_Char(DataStart,&apos;dd.mm.yyyy&apos;);
		mySQL := Replace(MySQL, &apos;%DATASTART%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;); 
	end if;
	if DataStop &lt;&gt; null then 
		D := To_Char(DataStop,&apos;dd.mm.yyyy&apos;);
		mySQL := Replace(MySQL, &apos;%DATASTOP%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
	end if;
	
  sFileName := aName;
	Delete TMP_EXPLINES;
	sSelect := &apos;Insert into TMP_EXPLINES (&apos;||mySQL||&apos;)&apos;;  
	EXECUTE IMMEDIATE sSelect;
	File := UTL_FILE.FOPEN(aDIR, sFileName, &apos;W&apos;);
	FOR v_rec IN ( SELECT * from TMP_EXPLINES) LOOP
		if Nvl(v_rec.Linie,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
	  	UTL_FILE.PUTF(File, v_rec.Linie);
  		UTL_FILE.NEW_LINE(File, 1);
		end if;
	END LOOP;
	UTL_FILE.FCLOSE(File);
END; 
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_TXT_ORD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81A23B44D921679685AD30C1B2E0AEE2FF3572DD</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_TXT_ORD(aSql IN VARCHAR2, aDir IN VARCHAR2, aName IN VARCHAR2, DataStart in date DEFAULT null, DataStop in date DEFAULT null) IS
  sFileName VARCHAR2(1000);
  sSelect clob;
  mySQL clob;
	D varchar2(30);
	DD Date;
  File UTL_FILE.FILE_TYPE;
BEGIN
--CREATE DIRECTORY EXP_HEINECKEN AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_HEINECKEN TO **USER**;
  mySQL := aSQL;
	IF DataStart &lt;&gt; NULL THEN
		D := To_Char(DataStart,&apos;dd.mm.yyyy&apos;);
		mySQL := Replace(MySQL, &apos;%DATASTART%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
	END IF;
	IF DataStop &lt;&gt; NULL THEN
		D := To_Char(DataStop,&apos;dd.mm.yyyy&apos;);
		mySQL := Replace(MySQL, &apos;%DATASTOP%&apos;, &apos;&apos;&apos;&apos;||D||&apos;&apos;&apos;&apos;);
	END IF;

  sFileName := aName;
	Delete TMP_EXPLINES_ORD;
	sSelect := &apos;INSERT into TMP_EXPLINES_ORD (&apos;||mySQL||&apos;)&apos;;
	EXECUTE IMMEDIATE sSelect;
	File := UTL_FILE.FOPEN(aDIR, sFileName, &apos;W&apos;);
	FOR v_rec IN ( SELECT * FROM TMP_EXPLINES_ORD ORDER BY ORD) LOOP
		IF Coalesce(v_rec.Linie,&apos;?&apos;) &lt;&gt; &apos;?&apos; then
	  	UTL_FILE.PUTF(File, v_rec.Linie);
  		UTL_FILE.NEW_LINE(File, 1);
		END IF;
	END LOOP;
	UTL_FILE.FCLOSE(File);
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>QUERY_TO_TXT_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>994917AAC07FC56EE0A69D977CD15FC1088AB378</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE QUERY_TO_TXT_STOC(aSql IN VARCHAR2, aDir IN VARCHAR2, aName IN VARCHAR2, DataStoc IN Date, Cate IN number) IS
  sFileName VARCHAR2(1000);
  sSelect   clob;
  sData VARCHAR2(12);
  sDataStoc VARCHAR2(10);
  mySQL     clob;
	i         number;
  File      UTL_FILE.FILE_TYPE;
BEGIN
--CREATE DIRECTORY EXP_HEINECKEN AS **CALE_DIRECTOR**;
--GRANT READ, WRITE ON DIRECTORY EXP_HEINECKEN TO **USER**;
  sFileName := aName;
	Delete TMP_EXPLINES;
	FOR i IN 0 .. Cate LOOP
    PKG_GLOBALS.SetLunaTemp(Extract(Year FROM DataStoc-i), Extract(Month FROM DataStoc-i) );
    PKG_GLOBALS.SetLunaPrecedenta(Extract(Year FROM Trunc(DataStoc-i,&apos;mm&apos;)-1), Extract(Month FROM Trunc(DataStoc-i,&apos;mm&apos;)-1) );
    sData := To_Char(DataStoc-i,&apos;ddmmyyyy&apos;) || &apos;0000&apos;;
    sDataStoc := To_Char(DataStoc-i,&apos;dd.mm.yyyy&apos;);
    PKG_LIST_SELFISAMAG.setAllParams(sDataStoc,sDataStoc,sDataStoc,1,1,1,0);
		mySQL := Replace(Upper(aSQL), &apos;%DATA%&apos;, &apos;&apos;&apos;&apos;||sData||&apos;&apos;&apos;&apos; );
		mySQL := Replace(MySQL, &apos;%DATASTOC%&apos;, &apos;&apos;&apos;&apos;||sDataStoc||&apos;&apos;&apos;&apos;);
		sSelect := &apos;Insert into TMP_EXPLINES (&apos;||mySQL||&apos;)&apos;;
		commit;
		EXECUTE IMMEDIATE sSelect;
	end loop;
	File := UTL_FILE.FOPEN(aDIR, sFileName, &apos;W&apos;);
	FOR v_rec IN ( SELECT * from TMP_EXPLINES) LOOP
		UTL_FILE.PUTF(File, v_rec.Linie);
    UTL_FILE.NEW_LINE(File, 1);
  END LOOP;
  UTL_FILE.FCLOSE(File);
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>REMAKE_COEFDISCMAJ_IES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD1940A84EE7807690E5DA7334BA6A84D9C5F219</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE REMAKE_COEFDISCMAJ_IES(pCodIes IN NUMBER, pRes OUT NUMBER) IS
  --pRes 0 -- nu e necesar; 1 -- nu sunt linii; 7 -- recalcul identic -- 8 recalcul; -- 9 recalcul invalid
  sSql   VARCHAR2(10000);
  vMAPD  NUMBER;
  vTDoc  NUMBER;
  vVDoc  NUMBER;
  vNrLin NUMBER;
  vNrUpd NUMBER;
  vOVLin NUMBER;
  vNVLin NUMBER;
BEGIN
  PKG_IESIRI.SP_LOCKRECORD(pCodIes);
  SELECT TipDoc, ValDoc - TvaDoc, Coalesce(pkg_categconst.GetValConstanta(&apos;ModAplicProcDisc&apos;,an,luna),&apos;1&apos;) INTO vTDoc, vVDoc, vMAPD FROM iesiri WHERE codies = pCodIes;
  SELECT Sum(Coalesce(pretorig,pu,0)*Coalesce(cant,0)*Coalesce(coefdiscmaj,1)), Count(1) INTO vOVLin, vNrLin FROM iesiri1 WHERE codies = pCodIes AND tiplinie NOT IN (&apos;G&apos;,&apos;T&apos;);

  sSql  := &apos;INSERT INTO tmp_upd_coefdiscmaj
  WITH
  x AS (
    SELECT
      i1a.codies1, i1d.codies1 codiesd, Row_Number() OVER (PARTITION BY i1a.codies1 ORDER BY i1d.indexlocal) Idx,
      CASE WHEN &apos;||vMAPD||&apos; = 2 THEN i1a.pu   ELSE i1a.pu*i1a.cant END pu,
      CASE WHEN &apos;||vMAPD||&apos; = 2 THEN i1a.cant ELSE 1               END cant,
      i1d.cant proc, Coalesce(cd.codcriteriu,0) CodCriteriu, Coalesce(cd.cumulat,0) cumulat,
      CASE WHEN cd.codcriteriu IS NULL THEN Coalesce(i1d.ContDiscount,0) ELSE 0 END ContDiscount
    FROM iesiri i
      INNER JOIN iesiri1 i1d ON i1d.codies = i.codies AND i1d.tiplinie     IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)
      INNER JOIN iesiri1 i1a ON i1a.codies = i.codies AND i1a.tiplinie NOT IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND i1a.indexlocal &lt; i1d.indexlocal
      LEFT JOIN  criteriidisc cd ON cd.codcriteriu = i1d.codcriteriu
    WHERE i.tipdoc IN (19,26)
      AND i.codies = &apos;||pCodIes||&apos;
      AND CASE
            WHEN i1d.tiplinie &lt;&gt; &apos;&apos;G&apos;&apos; THEN 0
            WHEN (SELECT Max(x.indexlocal) FROM iesiri1 x WHERE x.codies = i.codies AND x.tiplinie NOT IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND x.indexlocal &gt;= i1a.indexlocal AND x.indexlocal &lt;  i1d.indexlocal) &gt;
                 (SELECT Min(y.indexlocal) FROM iesiri1 y WHERE y.codies = i.codies AND y.tiplinie     IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;) AND y.indexlocal &gt;  i1a.indexlocal AND y.indexlocal &lt;= i1d.indexlocal)
            THEN 1
            ELSE 0
          END = 0
    ORDER BY i.an*12+i.luna,i.codies, i1a.codies),
  y (codies1, codcriteriu, contdiscount, idx, proc, cumulat, bd, d, d0, d1, d2) AS (
    SELECT
      x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat,
      x.cant * x.pu bd,
      x.cant * x.pu*x.proc/100 d,
      CASE WHEN x.cumulat = 0 THEN x.pu*x.proc/100 ELSE 0 END d0,
      CASE WHEN x.cumulat = 1 THEN x.pu*x.proc/100 ELSE 0 END d1,
      CASE WHEN x.cumulat = 2 THEN x.pu*x.proc/100 ELSE 0 END d2
    FROM x
    WHERE idx=1
    UNION ALL
    SELECT
      x.codies1, x.codcriteriu, x.contdiscount, x.idx, x.proc, x.cumulat,
      x.cant * CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2 WHEN 1 THEN x.pu WHEN 2 THEN x.pu+y.d0+y.d1 ELSE 0 END bd,
      x.cant * CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2 WHEN 1 THEN x.pu WHEN 2 THEN x.pu+y.d0+y.d1 ELSE 0 END*x.proc/100 d,
      y.d0 +   CASE x.cumulat WHEN 0 THEN x.pu+y.d0+y.d1+y.d2                                             ELSE 0 END*x.proc/100 d0,
      y.d1 +   CASE x.cumulat WHEN 1 THEN x.pu                                                            ELSE 0 END*x.proc/100 d1,
      y.d2 +   CASE x.cumulat WHEN 2 THEN x.pu+y.d0+y.d1                                                  ELSE 0 END*x.proc/100 d2
    FROM y INNER JOIN x ON x.codies1 = y.codies1 AND x.idx = y.idx + 1)
  SELECT
    i1.codies1, i1.coefdiscmaj OldCoefDiscMaj,
    CASE
      WHEN Coalesce(i1.pretorig, i1.pu, 0) = 0 THEN 1
      WHEN Coalesce(i1.cant,0) = 0 THEN 0
      WHEN Sum(Coalesce(y.d,0)) = 0 THEN (1+Coalesce(i1.addim/100,0))*(1+Coalesce(i1.procdisc/100,0))
      ELSE (i1.pu*i1.cant*(1+Coalesce(i1.procdisc/100,0))+Sum(Coalesce(y.d,0)) )/Coalesce(i1.pretorig, i1.pu)/i1.cant
    END NewCoefDiscMaj
  FROM iesiri1 i1 LEFT JOIN y ON y.codies1 = i1.codies1
  WHERE i1.codies = &apos;||pCodIes||&apos; AND i1.tiplinie NOT IN (&apos;&apos;G&apos;&apos;,&apos;&apos;T&apos;&apos;)
  --FROM y LEFT JOIN iesiri1 i1 ON i1.codies1 = y.codies1
  GROUP BY i1.codies1, i1.pretorig, i1.pu, i1.cant, i1.coefdiscmaj, i1.addim, i1.procdisc&apos;;


  IF Round(vOVLin,2) = Round(vVDoc,2) THEN
    pRes := 0;
  ELSIF vNrLin = 0 THEN
    pRes := 1;
  ELSE
    DELETE tmp_upd_coefdiscmaj;
    EXECUTE IMMEDIATE sSql;
    SELECT Sum(i1.pretorig*i1.cant*t.newcoefdiscmaj) INTO vNVLin FROM tmp_upd_coefdiscmaj t INNER JOIN iesiri1 i1 ON i1.codies1 = t.codies1;
    DELETE tmp_upd_coefdiscmaj WHERE OldCoefDiscMaj IS NOT NULL AND Coalesce(OldCoefDiscMaj, 0) = NewCoefDiscMaj;
    SELECT Count(1) INTO vNrUpd FROM tmp_upd_coefdiscmaj;

    IF vNrUpd = 0 THEN
      pRes := 7;
    ELSIF Round(vNVLin,2) = Round(vVDoc,2) THEN
      FOR vRec IN (SELECT codies1, NewCoefDiscMaj FROM tmp_upd_coefdiscmaj)
      LOOP
        UPDATE iesiri1 SET CoefDiscMaj = vRec.NewCoefDiscMaj WHERE CodIes1 = vRec.CodIes1;
      END LOOP;
      pRes := 8;
    ELSE
      pRes := 9;
    END IF;
  END IF;
  COMMIT;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>REMAKE_SEQUENCE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BDEA872FEF9442BA87A39C2C9337F0B960CB85E</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE REMAKE_SEQUENCE(NUME_SEQ IN VARCHAR2,NUME_TBL IN VARCHAR2,NUME_COLCOD IN VARCHAR2)IS
  VAL_COL NUMBER(10);
BEGIN
  EXECUTE IMMEDIATE &apos;SELECT MAX(&apos; || NUME_COLCOD || &apos;) + 1 FROM &apos; || NUME_TBL INTO VAL_COL;
  VAL_COL := GREATEST(Coalesce(VAL_COL, 0), 101);
  BEGIN
    EXECUTE IMMEDIATE &apos;DROP SEQUENCE &apos;||NUME_SEQ;
  EXCEPTION
    WHEN OTHERS THEN NULL;
  END;
  EXECUTE IMMEDIATE &apos;CREATE SEQUENCE &apos;||NUME_SEQ||&apos; START WITH &apos;||VAL_COL||&apos; INCREMENT BY 1&apos;;
END;
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>SP_CLEARTABLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58F8B01A4382424E3714835147504DA2D52437B0</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE &quot;SP_CLEARTABLE&quot; ( TABLENAME IN VARCHAR2 ) AS
BEGIN
  BEGIN
    execute immediate &apos;begin delete &apos; || TableName ||&apos;; end;&apos;;
    COMMIT;
   END;
END; 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>TRUNCATE_TABLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B833E04C22B897610A2C896D262289FE406B9A19</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE TRUNCATE_TABLE(TableName varchar) is
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE &apos;||TableName;
EXCEPTION WHEN OTHERS THEN
  EXECUTE IMMEDIATE &apos;DELETE FROM &apos;   ||TableName;
END TRUNCATE_TABLE;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>UMPLE_TMP_AL_CURSLINIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7D8386271FCA20EBF12108D59FA5CDEA2051F1B</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE UMPLE_TMP_AL_CURSLINIE (aALStart IN NUMBER, aALStop IN NUMBER) IS
BEGIN
  --FLAG PENTRU PG -&gt; TMP_AL_CURSLINIE
  TRUNCATE_TABLE(&apos;TMP_AL_CURSLINIE&apos;);

  INSERT INTO TMP_AL_CURSLINIE
  WITH /*recursive*/ cRec (AL) AS (
    SELECT aALStart AS AL FROM dual                    UNION ALL
    SELECT AL+1     AS AL FROM cRec WHERE al &lt; aALStop
  )
  SELECT AL, To_Number(Coalesce(pkg_categconst.GetValConstanta(&apos;ContabCursLinie&apos; ,0, AL),&apos;2&apos;))
  FROM cRec;

  COMMIT;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>UMPLE_TMP_CONST_PROCTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D602761FAAA4C50BCA301FE7A5AFAABDCC5B7223</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE UMPLE_TMP_CONST_PROCTVA (pAnLuna NUMBER) IS
BEGIN
  TRUNCATE_TABLE(&apos;TMP_CONST_PROCTVA&apos;);

  INSERT INTO TMP_CONST_PROCTVA (SIMBOL, ORD, TIP, PROCTVA, LIMINF, LIMSUP)
  SELECT
    SIMBOL,
    Row_Number()               OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC ) Ord,
    Tip,
    ProcTva,
    (ProcTva + Lag (ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC )) / 2 LimInf,
    (ProcTva + Lead(ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC )) / 2 LimSup
  FROM (
    SELECT
      SIMBOL, TIP,
      CASE WHEN ProcTva = Lag(ProcTva,1) OVER (ORDER BY ProcTva ASC NULLS LAST, TIP ASC) THEN NULL ELSE ProcTva END ProcTva
    FROM (
      SELECT
        SIMBOL, NULLIF(TO_NUMBER(VALOARE), 0) ProcTva,
        CASE c1.SIMBOL
          WHEN &apos;PROCTVAMED&apos;  THEN 1 WHEN &apos;PROCTVAMIN&apos;  THEN 2 WHEN &apos;PROCTVAMAX&apos;  THEN 3
          WHEN &apos;PROCTVAREG&apos;  THEN 4 WHEN &apos;PROCTVAREG2&apos; THEN 5
          WHEN &apos;PROCTVAREG3&apos; THEN 6 WHEN &apos;PROCTVAREG4&apos; THEN 7 WHEN &apos;PROCTVAREG5&apos; THEN 8
        END TIP
      FROM (
        SELECT codconst1, UPPER(SIMBOL) SIMBOL
        FROM const1
        WHERE UPPER(SIMBOL) IN (&apos;PROCTVAMIN&apos;,&apos;PROCTVAMED&apos;,&apos;PROCTVAMAX&apos;,&apos;PROCTVAREG&apos;,&apos;PROCTVAREG2&apos;,&apos;PROCTVAREG3&apos;,&apos;PROCTVAREG4&apos;,&apos;PROCTVAREG5&apos;)
      ) c1
        LEFT JOIN constluna cl ON cl.codconst1    = c1.codconst1 AND pAnLuna BETWEEN CL.ALSTART AND CL.ALSTOP
        LEFT JOIN constval  cv ON cv.codconstluna = cl.codconstluna
    ) a
  ) b;

  COMMIT;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>UMPLE_TMP_ZILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D29CB24806ED04DCD6C27857FA6F93DD031CEC7</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE umple_tmp_zile (aDataIni IN DATE, aDataFin IN DATE) IS
  vNrZile NUMBER;
BEGIN
  EXECUTE IMMEDIATE &apos;TRUNCATE TABLE TMP_ZILE&apos;;

  vNrZile := Trunc(aDataFin) - Trunc(aDataIni) + 1;

  INSERT INTO TMP_ZILE
  SELECT Trunc(aDataIni) + LEVEL - 1
  FROM DUAL
  CONNECT BY LEVEL &lt;= vNrZile;

  COMMIT;

END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>UPDATE_CODCONT_FROM_IOPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F96AD0F46AABE05466C38EDBAFDE797FACDCDEF</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE UPDATE_CODCONT_FROM_IOPART1(pTable IN VARCHAR2, pColCodCont IN VARCHAR2, pColCodPart IN VARCHAR2, pColICont IN VARCHAR2, pColAL IN VARCHAR2, pValAL IN NUMBER) AS
  TYPE t_tab IS TABLE OF VARCHAR2(500);
  v_data t_tab;
  vCNT   NUMBER        := 0;
  sAL    VARCHAR2(100) := &apos;0&apos;;
  sSQL   CLOB;
  sDef   CLOB;
BEGIN
  -- Construire sAL
  IF pColAL IS NOT NULL         THEN sAL := &apos;T.&apos;||sAL;
  ELSIF Coalesce(pValAL, 0) &gt; 0 THEN sAL := To_Char(pValAL);
  END IF;

  -- Construire query dinamic pentru coloane
  IF sAL &lt;&gt; &apos;0&apos; THEN
    sDef := &apos;SELECT &apos;&apos;WHEN &apos;&apos;||To_Char(T.ICONT, &apos;&apos;fm00&apos;&apos;)||&apos;&apos; THEN IP1.&apos;&apos;||(SELECT COLUMN_NAME FROM USER_TAB_COLUMNS C WHERE C.TABLE_NAME = &apos;&apos;IOPART1&apos;&apos; AND C.COLUMN_ID = T.ICONT + 1) &apos;||Chr(10)||
    &apos;FROM (SELECT DISTINCT &apos;||pColICont||&apos; AS ICONT FROM TMP_SAFT_NPART) T &apos;||Chr(10)||
    &apos;ORDER BY T.ICONT&apos;;
    EXECUTE IMMEDIATE sDef BULK COLLECT INTO v_data;
    vCNT := v_data.Count;
  END IF;

  -- Construire si executare UPDATE/MERGE doar daca avem date
  IF vCNT &gt; 0 THEN
    sSQL :=
      &apos;MERGE INTO &apos;||pTable||&apos; T &apos;||Chr(10)||
      &apos;USING ( &apos;||Chr(10)||
      &apos;  SELECT &apos;||Chr(10)||
      &apos;    T.&apos;||pColCodPart||&apos; AS CODPART, T.&apos;||pColICont||&apos; AS ICONT, &apos;||Chr(10)||
      &apos;    CASE T.&apos;||pColICont;
    FOR i IN 1..vCNT LOOP
      sSQL := sSQL ||Chr(10)||
      &apos;      &apos;||v_data(i);
    END LOOP;
    sSQL := sSQL ||Chr(10)||
      &apos;    END AS NEW_CODCONT &apos;||Chr(10)||
      &apos;  FROM TMP_SAFT_NPART T &apos;||Chr(10)||
      &apos;    LEFT JOIN NPART1  NP1 ON NP1.CODPART   = T.CODPART     AND &apos;||sAL||&apos; BETWEEN NP1.ALStart AND NP1.ALStop &apos;||Chr(10)||
      &apos;    LEFT JOIN IOPART1 IP1 ON IP1.CODIOPART = NP1.CODIOPART AND &apos;||sAL||&apos; BETWEEN IP1.ALStart AND IP1.ALStop &apos;||Chr(10)||
      &apos;  ) SRC ON (T.&apos;||pColCodPart||&apos; = SRC.CODPART AND T.&apos;||pColICont||&apos; = SRC.ICONT) &apos;||Chr(10)||
      &apos;WHEN MATCHED THEN UPDATE SET T.&apos;||pColCodCont||&apos; = SRC.NEW_CODCONT&apos;;
    EXECUTE IMMEDIATE sSQL;
  END IF;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>PROCEDURE</TYPE>
  <NAME>X_ERR_INSERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7386D6F368B0A10F50EF84961FFB56B40CD253D</HASHVAL>
  <TEXT>CREATE OR REPLACE PROCEDURE X_ERR_INSERT(pVal IN CLOB) is
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  INSERT INTO x(VIEW_NAME, TEST) VALUES (to_char(CURRENT_TIMESTAMP, &apos;yyyymmdd_hh24mmss&apos;), pVal);
  COMMIT;
END X_ERR_INSERT;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_390_394_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4AC490B3F9B641B70FC155CFDD61A7E5C2D9117</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_390_394_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_AMEF_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60E726665E7A3CDC0E4EF111BE95B5DD1DA51529</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_AMEF_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21F8FD3A6276229CEC2B6CF0AD5B8A9E92F5D2AB</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_ETRANSPORT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB1482AFE59BF818D05B26F99BD96C8DE616EA9A</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_ETRANSPORT_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_FACTURA_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2361B00BB27D8D0DC9318A611D00921161E35C3</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_FACTURA_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_FACTURA_TVA_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>894ED1F4A6B200B6F1B41CCAB8D7C58809E4055C</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_FACTURA_TVA_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_LOCUINTE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D032C02B158DDE5A6F0797EDA8837DA7BB83D646</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_LOCUINTE_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_VAMA_EXPORT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97A96A60BA037123E0D77D99C62CDBAE3E001CD5</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_VAMA_EXPORT_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>ETVA_VAMA_IMPORT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A033D7BB7F2690D98ACFAB72AAEA96807A1B63C</HASHVAL>
  <TEXT>CREATE SEQUENCE ETVA_VAMA_IMPORT_COD INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ADAOSM1_CODADAOSM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2EEFE9149145C2A6202DC25FE3B60E2E2001AD3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ADAOSM1_CODADAOSM1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ADAOSM_CODADAOSM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E40B829C2E381D7FA544366977D7A09E13925706</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ADAOSM_CODADAOSM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTA_INFO_CODALERTEINFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBD091529B52822A4CAFBBEF8AA3DDE6A5BFBC35</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTA_INFO_CODALERTEINFO INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTA_INFO_RULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BA8376F4F360032EDA15AC2852A3B26CD1BB711</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTA_INFO_RULARE INCREMENT BY 1 NOCACHE START WITH 221</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTE0_CODALERTA0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6396ADFB98F66F1A29AA2606082622C0E040CF41</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTE0_CODALERTA0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTE1_CODALERTA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C724D623FA514C254B5FEC47473266731B31552E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTE1_CODALERTA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTE1_DEF_CODALERTEDEF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D2EF96BC61D535A69C63C5C78CDCA5C1640901C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTE1_DEF_CODALERTEDEF1 INCREMENT BY 1 NOCACHE START WITH 167</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTE_CODALERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC096B755E405609C72590ED2F57D60B46DEA8E9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTE_CODALERTA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ALERTE_DEF_CODALERTEDEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>557C6E0D160316237A22CDB84765D5F96497D781</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ALERTE_DEF_CODALERTEDEF INCREMENT BY 1 NOCACHE START WITH 166</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ANALIZA1_CODANALIZA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7574F0225A6F4F73809859F02DD40838A470E07</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ANALIZA1_CODANALIZA1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ANALIZANOD_CODANALIZANOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03F18E53E9BAF18FC09F6A33B8D94B420106274D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ANALIZANOD_CODANALIZANOD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ANALIZA_CODANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85853B6A7A276F4A14E0FF65141BF083AF2E572A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ANALIZA_CODANALIZA INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_APELTELEFON_CODAPEL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>565F5D074364EC7BF0A8FA82AC6432A84C22D56A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_APELTELEFON_CODAPEL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ASIGURARI1_CODASIGURARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA7A1B2F45D76AB8DD7CCA9ED1D35BC1F4FEFEB8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ASIGURARI1_CODASIGURARE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ASIGURARI_CODASIGURARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACD7C6AA4814C28ABB58F6EB2904C9F83132A7C7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ASIGURARI_CODASIGURARE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_AUTORIZATII_CODAUTORIZATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9AA53E314F86148EF136C3A5E823E186FD627532</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_AUTORIZATII_CODAUTORIZATII INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_AVARIECAROSERIE_CODAVARIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7AAEBBAE2905C5F71DDBFB053020F93D153DFEF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_AVARIECAROSERIE_CODAVARIE INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_AWBCOMANDA_CODAWBCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8E1E7EE596946112899953D7582032D3CC54286</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_AWBCOMANDA_CODAWBCOMANDA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BALSTOCREST_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28A238D7347EC1D1E31BC3732CCE7F6FF943859C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BALSTOCREST_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BANKAUTENTIF_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9BB59CBF550F75AC2D5A38308E87E9818B56AA8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BANKAUTENTIF_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BCAR_CODBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF538D53FF7E70E0934E785DEF489EAB284AE2C5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BCAR_CODBCAR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BONLINKERR_CODBONLINKERR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3BA8E3EF194C5E6D5C5138ABF4DC26F3781B11AA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BONLINKERR_CODBONLINKERR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BONMASA_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68360D6AABB64FF11335A8EBE639BDD2F0C440CF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BONMASA_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETCAP1_CODBUGETCAP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92429961343580BA0E1C1697C06D045F7AAEE240</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETCAP1_CODBUGETCAP1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETCAP_CODBUGETCAP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81DF945FE7A82C5276DD5B8FB682E19078D1C5A2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETCAP_CODBUGETCAP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETCL_CODBUGETCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6D408B57BBDD0CFF4BE101A1E312CCB34D4226F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETCL_CODBUGETCL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETMF1_CODBUGETMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02E38080E731B8973F5EB788D550F241F1409917</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETMF1_CODBUGETMF1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETMF_CODBUGETMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6A6C8E7A315D04C9459B658F93E59DDE1967892</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETMF_CODBUGETMF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETPRODP_CODP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E852FFA06D4312A5EEADEEC48E849C4692C48DFA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETPRODP_CODP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETPRODT_CODT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>418DEC6B30A2088F4E6BE31CC7D0AE4D4F977CC4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETPRODT_CODT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETPRODV_CODV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A8FCADE035C85C89B684587D64A783BD821FF24</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETPRODV_CODV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETPROD_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97D1787AE7DAFF34B0BBCDF62D2A432DF9212176</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETPROD_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETRECTIF1_CODBUGETRECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67B098D3222D93764ED5C073C7A701A1300CFE26</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETRECTIF1_CODBUGETRECT1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETRECTIF_CODBUGETRECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2CCDAA2930AE17A37387784D6182EC79E71151FD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETRECTIF_CODBUGETRECT INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETSTOC_CODBUGETSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBD7EA2940D560A54FE8D0604C1E5AAEC12BFEBC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETSTOC_CODBUGETSTOC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETVCL_CODBUGETVCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFC9587006B697BF5584C3AF0F453CBA1D9168BA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETVCL_CODBUGETVCL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_BUGETVL_CODBUGETVL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19531BB397822732E52F35BEF767F60DD88BD70B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_BUGETVL_CODBUGETVL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CAENSEC_CODCAENSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4FD7C37EF3BFC057CF52143AA83039AA54196FF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CAENSEC_CODCAENSEC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CAMPANIICOST_CODCC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>039900B036A0397548CA9008143F6C77B69F2512</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CAMPANIICOST_CODCC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CAMPANIIPART_CODCP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC7C03C3F9EC7B371D12E961D750224EF3E001A6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CAMPANIIPART_CODCP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CAMPANIIVENIT_CODCV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFEF8072743ECD920C740D1CCBDBF65081436888</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CAMPANIIVENIT_CODCV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CAMPANII_CODCAMPANIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03D95659D0883C62C88E4D832FD69E4D4885F232</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CAMPANII_CODCAMPANIE INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CANAMED1_CODCANAMED1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F83F889F469C97CA240A84C9F5EE91C72E7209C6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CANAMED1_CODCANAMED1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CANAMED_CODCANAMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>458DF17E4EF471B65B45369BB93D5C74A8AA2E1D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CANAMED_CODCANAMED INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CANTARE_CODCANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6335F9C7B784D5F555479E37B3B40B4671B5E091</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CANTARE_CODCANTAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CANTAR_CODCANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23E8432AA11F532AFD42F48EF49D87005FFDBE3A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CANTAR_CODCANTAR INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CARDURI_CODCARD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48ACD7A39B6E510A1166F2B225F5F86507E16746</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CARDURI_CODCARD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CASHFLOW1_CODCASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68DBB9BC8E66127DD922240D544903C33424B9E5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CASHFLOW1_CODCASHFLOW1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CASHFLOW2_CODCASHFLOW2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>729356755A3DE1AB8F924BC6568D6086007A16F6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CASHFLOW2_CODCASHFLOW2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CASHFLOW_CODCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>851B3C546A9540BBC73A4A401085D1AA4DE2D608</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CASHFLOW_CODCASHFLOW INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CASTOTPREPAY_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88E8DA83F667E55F7A894AD3206BB95FCE9F7738</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CASTOTPREPAY_COD INCREMENT BY 1 NOCACHE START WITH 100</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CASTOTUTILITY_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0271DAA3FB0899DECF7924B74B682CE54715F1F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CASTOTUTILITY_COD INCREMENT BY 1 NOCACHE START WITH 100</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CATEGARTTI_CODCATEGARTTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B73D94153886D31475AC742B6F869533BBA867C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CATEGARTTI_CODCATEGARTTI INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CATEGCONST_CODCATEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC51E669198874C6B87A6E14E7E0916F75AEA208</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CATEGCONST_CODCATEG INCREMENT BY 1 NOCACHE START WITH 255</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CENTRALIZARENC_CODC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34BC8C7A69E59F20F13DEE6684314EF6D8B151BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CENTRALIZARENC_CODC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CENTRECOSTA_CODCENTRUA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F153594C8E28A354729CC50DDE26ECAFD98BFEF2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CENTRECOSTA_CODCENTRUA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CENTRECOST_CODCENTRU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DBD6FC5E7C28EA417169DE84B949450B31EF0190</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CENTRECOST_CODCENTRU INCREMENT BY 1 NOCACHE START WITH 105</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CERTIF_CODCERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7641ABE0F3116C352490B5C1C170A8C601F5FB06</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CERTIF_CODCERTIF INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CFGACTIONS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F2D32743168AF8E4C5385484C32E8ED3D6D9690</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CFGACTIONS INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CFGTABLES1_CODCFGTABLE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8C50DCBFD092E9DC1D7659F9239348BC0687CEB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CFGTABLES1_CODCFGTABLE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CFGTABLES2_CODCFGTABLE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70382AC3F9245A5A77F7605DE35DE216E1621602</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CFGTABLES2_CODCFGTABLE2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CFGTABLES_CODCFGTABLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45D83D6EC0CB8C3FC4CE56BAAE92DBEA9C9AB46D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CFGTABLES_CODCFGTABLE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CHELTAVANS1_CODCHELTAVANS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24DB28E68A3F005544A9BC53979606B32C9FB1C5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CHELTAVANS1_CODCHELTAVANS1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CHELTAVANS_CODCHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0826397F196E9B9B4A0DC1D96856543D250B2A4D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CHELTAVANS_CODCHELTAVANS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CHELTOPER1_CODCHELTOPER1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>515AA3F0B2EEF0BD44429F0802A924AE5A045CF4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CHELTOPER1_CODCHELTOPER1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CHELTOPER_CODCHELTOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F4EBF4B3DE485C15A7B2182B96927CC8D0DF92F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CHELTOPER_CODCHELTOPER INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDAPROBARI_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0D5EC015A2E8FA3A24DC060FA09379249739C51</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDAPROBARI_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDAVANS_CODCMDAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A4B4ABF56948B1E0EE37B612AF6944DBBCC2D696</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDAVANS_CODCMDAVANS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDPRODMAN_CODCMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF2E18CE54189143EF7DC20AD88CA0A6E3D0FD8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDPRODMAN_CODCMDPRODMAN INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDPRODMAT_CODCMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55EFDC24D94F4357CAE69368955E4B73C878F88B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDPRODMAT_CODCMDPRODMAT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDPRODREZ_CODCMDPRODREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53EEF45C79A592E372050F443A17CB628ACD8D23</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDPRODREZ_CODCMDPRODREZ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CMDTL_CODCMDTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62131AEE1474D28422B1C6EDAC1FE77A14DB85A0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CMDTL_CODCMDTL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODEXTALT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>562EE417C5CB13FBB6F611F106CE96A2287970FC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODEXTALT_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODEXTARTLOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57006530C4AC24502F171361FB675BD8A70E612B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODEXTARTLOCK_COD INCREMENT BY 1 NOCACHE START WITH 121</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODEXTPARTLOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F58FFC0FD3D569DD1B24E16519F15B1F2694B280</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODEXTPARTLOCK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODGESTLOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D32135B73222564966E68F4C48959AEC34B1716</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODGESTLOCK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODINTALT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB7DD1E5CCAE04A7AEBDE988EF16B9F5C0A4E166</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODINTALT_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODINTARTLOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>575B40D450638702DABF6FBC0DD5EC86F8A93669</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODINTARTLOCK_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODINTPARTLOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3FF1E62DFCF62ECCAF42A74D1EBBFACC63FE124C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODINTPARTLOCK_COD INCREMENT BY 1 NOCACHE START WITH 119</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CODIOARTCORESP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4529CFA3BDE425727075504B34209908C0C9D10E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CODIOARTCORESP_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA1ET_CODCOMANDA1ET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75BD2EB5767120B426341B68540370A93342D42A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA1ET_CODCOMANDA1ET INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA1_CODCOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23C2EE60A7E2071E0BF58DD8A75DDB206A3A6203</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA1_CODCOMANDA1 INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA1_CODCOMANDA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1366B08AA687D590AE5CAA47BA3AC517CB6CC25F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA1_CODCOMANDA2 INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA2_CODCOMANDA3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B05162F8C95599AFCB3095EF3F0D99B8FA28DA5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA2_CODCOMANDA3 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA4_CODCOMANDA4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51ADA954EF48B8D4463D464265C3A28BDCED9969</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA4_CODCOMANDA4 INCREMENT BY 1 NOCACHE START WITH 286</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMANDA_CODCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2DF688C0FCFCD75DFD1C5B122E4E5EB4293C784</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMANDA_CODCOMANDA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMENZIONLINE_NRDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9636D62695946A3F8D89BB1F182DEF1D887140D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMENZIONLINE_NRDOC INCREMENT BY 1 NOCACHE START WITH 21</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_COMPENS_CODCOMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8EEB40ED2DE4AE9F8308B5FD2331A638104616DD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_COMPENS_CODCOMPENS INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONCURENTI_CODCONCURENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A8DC955EC0439CDCB7D6054040DE8A654672BB4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONCURENTI_CODCONCURENT INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONDCOR1_CODCONDCOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACD017733444FB24E6963FBE6B32D0CFE3A34926</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONDCOR1_CODCONDCOR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONST1_CODCONST1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F2E3F7088877ACFB6B2AE28B0310E867D11A008</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONST1_CODCONST1 INCREMENT BY 1 NOCACHE START WITH 6499</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONSTLUNA_CODCONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACC652921CCA3B78E22D461534892B49928BA27F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONSTLUNA_CODCONSTLUNA INCREMENT BY 1 NOCACHE START WITH 6310</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONSTMAKETA_CODCONSTMAKETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C919F637B786526BB75B4050E9F248EFC66B0EE2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONSTMAKETA_CODCONSTMAKETA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONSTVALPOS_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C77E129351E5FFED8A6F311657712E2EB3B232FE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONSTVALPOS_COD INCREMENT BY 1 NOCACHE START WITH 6818</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACT0_CODCONTRACT0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F2533BA5098CC8BF1829207F5850A5376D0DD25</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACT0_CODCONTRACT0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACT1_CODCONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58408478991B9B0ABE97F88C8A1D59375FFF4248</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACT1_CODCONTRACT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACT2_CODCONTRACT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1576DACE0FBEDE4F283801145BAE114B0768154</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACT2_CODCONTRACT2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTC0_CODCONTRACTC0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36B60D9B50DCC65ABC5EEE46AFC81E5CD849B049</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTC0_CODCONTRACTC0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTC_CODCONTRACTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA58A9E837D701924509C66CADCB4D014C46AA8B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTC_CODCONTRACTC INCREMENT BY 1 NOCACHE START WITH 119</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTT_CODCONTRACTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>284400C2C8D0412B4671D044C986E530A5DEC849</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTT_CODCONTRACTT INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTV_CODCONTRACTV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFDC9846FE01617FBA6640EC5777893A143609DD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTV_CODCONTRACTV INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTXX_CODCONTRACTXX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB55A1CD4895762DDE5C5DFFFAF1E732A2FCA4B9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTXX_CODCONTRACTXX INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACTX_CODCONTRACTX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>335A0AB910258E2E2E462F1D4545AFEAC7A2CFA3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACTX_CODCONTRACTX INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONTRACT_CODCONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22F2A64700A013B4613717E8AA6B32C309E5C483</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONTRACT_CODCONTRACT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CONVERTCURSPERS_CODCONVERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A74D153E6582DD1E2C0F0F47526C68E9E297B82</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CONVERTCURSPERS_CODCONVERT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CORELAT1_CODCORELAT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>870908D1F649A28B2E0847609BE4D95766B35D92</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CORELAT1_CODCORELAT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CORELAT2_CODCORELAT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>991346E1F80B39B14987C0C9A0876B788A70376D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CORELAT2_CODCORELAT2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CREANTE1_CODCREANTA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC64A5E3FB42AB51FA020408111BE0CF94C9AA2B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CREANTE1_CODCREANTA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CREANTE_CODCREANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C2D16D82441C1EB14A4E20135DA5E430442F06A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CREANTE_CODCREANTA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CRITERIIDISC1_CODCRITERIU1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69BB428741FD3A3BE5DAAD4048B019D336CBDA8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CRITERIIDISC1_CODCRITERIU1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CRITERIIDISC_CODCRITERIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>710975681FE99B53AC3903A9673B531B7D11AAC3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CRITERIIDISC_CODCRITERIU INCREMENT BY 1 NOCACHE START WITH 109</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CRONOCASHFLOW_CODCRONO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>237C771BB4852757ABDF9E5274E0045CF63BDC10</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CRONOCASHFLOW_CODCRONO INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CURSCASHFLOW_CODCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20B88FE95F9E00C92EBEA2495687ED1C463E2D9E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CURSCASHFLOW_CODCURS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CURSURI1_CODCURS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE9E463472ADE0B3B3A7CCAB25A9D5EAFE75A7A4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CURSURI1_CODCURS1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CURSURI_CODCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AA1B9D62459231468AB5AB14C2490B2590BD0C9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CURSURI_CODCURS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_CUSTODIEINI_CODCUSTODIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AD0FDFA12D1A564755D720A95EAC2A5DC3BDC41</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_CUSTODIEINI_CODCUSTODIE INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D300_CODD300</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E7FDEAF8A53557B3EF37ED9D98DE9C98E1AC796</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D300_CODD300 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D390CA_CODD390CA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DAAB4AE1F7C4D6BA1BA08F87251D33C5ADB3DB4F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D390CA_CODD390CA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D390CB_CODD390CB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0FFA412AF665A30BC7C1BED5056110308D0D435</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D390CB_CODD390CB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D390D_CODD390D</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2CFCAEC0E8D5EC06FCCFC3783E2B189A2C868EC7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D390D_CODD390D INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D390O_CODD390O</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42D8FA23617EA09BBCC4A837E263B25C02482CF3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D390O_CODD390O INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D390_CODD390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD50D8DE91B7136925B0568E7D7E6CC9FD981000</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D390_CODD390 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416G1_CODD39416G1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00394B026A4B47E4AA76D33C458B7B6905916CD4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416G1_CODD39416G1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416G2_CODD39416G2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA4189C441DECEF9340A31D19080F6695C93A0F1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416G2_CODD39416G2 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416G3_CODD39416G3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C1F3F71799698338EE1D70D53486F6D3A7FD565</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416G3_CODD39416G3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416G_CODD39416G</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC219B001DA9057874F7ECDB41A632B0DC29E413</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416G_CODD39416G INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I1_CODD39416I1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C77A16104699447DDE09F5CC0D53A6B390E698BD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I1_CODD39416I1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I2A_CODD39416I2A</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62A29D1B65E4874F75E30838EBF8ECD2FD6E6D05</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I2A_CODD39416I2A INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I2_CODD39416I2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B40B0980B5494898F4AD4D5F4C301516AEBAB234</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I2_CODD39416I2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I3_CODD39416I3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>17189273FB245F042DE7A30A4FFC45AC20CC48A8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I3_CODD39416I3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I4_CODD39416I4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E033BD0FC4520B15CDC49D989B23AE64C1A0036</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I4_CODD39416I4 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416I_CODD39416I</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7707EEA510521C2868CE7075ED2075BF95A17CB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416I_CODD39416I INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416NS2_CODD39416NS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7256BD63F3EFD9590668BA65736756B7D9EA910</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416NS2_CODD39416NS2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416N_CODD39416N</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>646AF498EB5B04BA0D10F5F06224201C21CF4484</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416N_CODD39416N INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RN0_CODD39416RN0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B67A49B6872BC04A3C90E476FC92ED3E0973FFA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RN0_CODD39416RN0 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RN1_CODD39416RN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>671E86FA872AC1DC796DC31950BBB294E712D445</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RN1_CODD39416RN1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RNS2_CODD39416RNS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7891E7635642CC757EC61CB9CDC13F455D1337BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RNS2_CODD39416RNS2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RNS3_CODD39416RNS3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F89C72115D0C7613FFC99659795F5B2EB81373E0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RNS3_CODD39416RNS3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RN_CODD39416RN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B34D2A3ACA8F05D9B4E443BBDD06B710E9C0F799</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RN_CODD39416RN INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RP1_CODD39416RP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77A050F712300527DC920F593F6BBF009955EC37</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RP1_CODD39416RP1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RPS2_CODD39416RPS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27679CAE2C9B5B14F60BFF50D9BF4674E6A4C462</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RPS2_CODD39416RPS2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RPS3_CODD39416RPS3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE280BB19653D5A5AF2A5AFA0C95004F04ECECDE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RPS3_CODD39416RPS3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416RP_CODD39416RP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E57A17E329B87739923D40278D33EB285A2DEFF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416RP_CODD39416RP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416R_CODD39416R</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45CD896387D254B4E756560E6E0BDCAF531F03CC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416R_CODD39416R INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416UES2_CODD39416UES2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0226553F8385BBAC38E11E894515D98682A8FBE6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416UES2_CODD39416UES2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416UE_CODD39416UE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>134E3DE06B196F97F079EB8084CE2CC62F83046F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416UE_CODD39416UE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D39416_CODD39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB3DD128A2FE1B3568F77A35FAACCC747419DBD8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D39416_CODD39416 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394A_CODD394A</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D45F7CA288E800468529F07ED84B233BD6DCC5D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394A_CODD394A INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394CC_CODD394CC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E307557DD372CBFD2CC14F6C73221842DBAB36D5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394CC_CODD394CC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394C_CODD394C</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97E5E3E73D60E237CB1CFB728F17DE936AE02301</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394C_CODD394C INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394L_CODD394L</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B885BD0ADDFC0F2521276A196E8BBAF48048BDE3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394L_CODD394L INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394VC_CODD394VC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>241071BE27013EA2E9951826B8B25A3670865D00</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394VC_CODD394VC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394V_CODD394V</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C081E36945C28080C2CC17D02302EFDD2F5BC1DD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394V_CODD394V INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_D394_CODD394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B29121633888EB28DF5096721CAA8F781E80F66C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_D394_CODD394 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DATAWAREHOUSE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C51825804D95623973A1387C4A8A104691FB5ED</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DATAWAREHOUSE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DESCRIPT1_CODDESCRIPTOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CA00E70CD7B01637FF4CB25AAA42E95F378179F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DESCRIPT1_CODDESCRIPTOR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DESCRIP_CODDESCRIPTOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1CB3BEBE7C1F7D1F38E3AFA145882CA81078BDB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DESCRIP_CODDESCRIPTOR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DESTINATII_CODDESTINATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E89E3196DDD9BC7CE6965F286D19751989FA9373</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DESTINATII_CODDESTINATIE INCREMENT BY 1 NOCACHE START WITH 107</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DETALIIET1_CODDETALIUET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE8D97685BE69D1A42771AED872571D9FAEC0213</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DETALIIET1_CODDETALIUET1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DETALIIET_CODDETALIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79642D197DBD8F782D90DDEFFBB3D0EE385BA225</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DETALIIET_CODDETALIU INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DIFICULTATI_CODDIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04471B639CFC51D12F0EA22DA5BCE47BFC4CD321</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DIFICULTATI_CODDIF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DINTRASTATA_CODDINTRASTATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66BE921DDA941BCA065ECFBBA93D01B3B8A84A46</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DINTRASTATA_CODDINTRASTATA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DINTRASTATD_CODDINTRASTATD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1EAC908B34E66BD21F9CB65EA08A8D1E13DD9C3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DINTRASTATD_CODDINTRASTATD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DINTRASTAT_CODDINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3052ADB78E324C80B2E5F28466A5AD518C89053</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DINTRASTAT_CODDINTRASTAT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCART_CODDISCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E97764A0CBA4D457A5AA561EE50DC7C4A6C3C3A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCART_CODDISCART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCEXCEPTII_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D21A4E1F76A5ECD57938BE31246D7CA2F3EC7F13</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCEXCEPTII_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCINTERVAL_CODDISCINTERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B1D99391EB26F6CCE458FB8DFBA20B6382A47D3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCINTERVAL_CODDISCINTERV INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCMONETAR_CODDISCMONETAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E57A88B94F75C91C242A190110E9D1DC45C2AD54</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCMONETAR_CODDISCMONETAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCOUNT_CODDISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4ECD7B0184B4AF2C51C334ABEDF8427D51861A0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCOUNT_CODDISCOUNT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISCPROMORETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35D1E0B5DEBF33EAC97C305F2BB0B1EAF76609DE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISCPROMORETAIL_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTANTA_CODDISTANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1AA9CB0B3F8434431377A91B8010BEB8BDB7C9D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTANTA_CODDISTANTA INCREMENT BY 1 NOCACHE START WITH 115</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIB1_CODDISTRIB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37CAAB567FC39883A76D30B5FFCBB95E54576512</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIB1_CODDISTRIB1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIB2_CODDISTRIB2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E819B4C621529E28327A3C7700B3CBA575F6B004</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIB2_CODDISTRIB2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIB3_CODDISTRIB3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CD0FDD609DD9E440195B56C66B39008D9498B7D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIB3_CODDISTRIB3 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIBCHELT1_CODDC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C823DCF28FC4D2F1F7B2EE79BFA58AB6A871ED57</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIBCHELT1_CODDC1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIBCHELT2_CODDC2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CF3DF00BA32DE348377C6EA77EEF1CCD7A1BD15</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIBCHELT2_CODDC2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIBCHELT_CODDC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA7F90028D0F81A75626E1D24368C5A6A9B79176</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIBCHELT_CODDC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DISTRIB_CODDISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EB2E760122B5CD4B7E8F91EB5DA82740E7FA228</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DISTRIB_CODDISTRIB INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCCARNETE_CODCARNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C2B60DAF48D671EA0969176AB9E71ED6BA722A8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCCARNETE_CODCARNET INCREMENT BY 1 NOCACHE START WITH 135</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCEDITAT_CODDOCEDITAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>01BEF09E4F7921A47022BF882104243E71AEA4DE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCEDITAT_CODDOCEDITAT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCFREE_CODDOCFREE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA9D17F9FF265FC9B847F74CF8500F17C196EA0E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCFREE_CODDOCFREE INCREMENT BY 1 NOCACHE START WITH 135</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCLINK_CODDOCLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DBBF9592BE9395A0D18F598D09AAAD568AA5696C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCLINK_CODDOCLINK INCREMENT BY 1 NOCACHE START WITH 139</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCLOCK_CODDOCLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3FA632BC1A74036A3E920CEF5B51C688EF117BA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCLOCK_CODDOCLOCK INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCSUPLIM1_CODDOCSUPLIM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36D6C88AB74D04CC40F6D0D1C4F1EEE6940A2318</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCSUPLIM1_CODDOCSUPLIM1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCSUPLIM_CODDOCSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06C993EF5A3A3FAFB01429E061BA6F58690E55FC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCSUPLIM_CODDOCSUPLIM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCUMENTE_CODDOCUMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D722BB0FC85C546E5F6FD9A7B65A77BC2EA2AC8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCUMENTE_CODDOCUMENT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOCUSERS_CODDOCUSERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45C80C0371F27E0786C728F21CE09769A6B17E1E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOCUSERS_CODDOCUSERS INCREMENT BY 1 NOCACHE START WITH 126</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOMENIIACT_CODDOMENIUACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D3D9B3E74B29D6ABE78AF4864C270D55EECD7B2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOMENIIACT_CODDOMENIUACT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DOSARE_CODDOSAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>524E56666A61262CEF1B95139AC97712F8DA3395</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DOSARE_CODDOSAR INCREMENT BY 1 NOCACHE START WITH 402</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DPP1_CODDIFPRETPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61CBA5404C509827E703668702DAF5566FB1B550</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DPP1_CODDIFPRETPROD1 INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DPP_CODDIFPRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8BF26007DAFEF0526CC96972593A64BDEBDB1C5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DPP_CODDIFPRETPROD INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DPROFITC_CODDPROFITC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>91696C26589C149D3AAB4CAA468076B8AE9D9695</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DPROFITC_CODDPROFITC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DPROFITV_CODDPROFITV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA618383B2D94612CA04B7BA71B5A20119551F76</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DPROFITV_CODDPROFITV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DPROFIT_CODDPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03619F4D859FBEB609A274FD89F273CA9DB60DA6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DPROFIT_CODDPROFIT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DVI1_CODDVI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37D307E3C4811D9456ADEA5C34F9F78DCB58E9D9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DVI1_CODDVI1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_DVI_CODDVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>719F32FD48AA3DEA28346982A5B3EB6B509631BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_DVI_CODDVI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EFACT_CUSTOM_CODEFACTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A7B1FF2DAF7C968B7026BE8536812809C85A5E1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EFACT_CUSTOM_CODEFACTC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EFCUSTOM_CODEFCUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24C6790C9AC35B79D98EE8EEACDC5DB9655FDDC5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EFCUSTOM_CODEFCUSTOM INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMBUGET1_CODELEMBUGET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>138F347873AC517D3EE40A73F40C482AEA63E603</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMBUGET1_CODELEMBUGET1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMBUGET2_CODELEMBUGET2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D84561B08534AF2317F9D73CA0BE8212D9C91FA2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMBUGET2_CODELEMBUGET2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMBUGET_CODELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9DB5923479DDEFA96E7EB07DBDA9A99A3F31E7B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMBUGET_CODELEMBUGET INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMENTEA_CODELEMENTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ABC55EFFE490C8B2C58812C6FB2F629B946153BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMENTEA_CODELEMENTA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMENTEC_CODELEMENTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF91B030419FE0D2F5FCFCEEB50097B5CFBE01DF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMENTEC_CODELEMENTC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMENTEM_CODELEMENTM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25D583F2EEA73AE20F593B2767781CA9CD37A508</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMENTEM_CODELEMENTM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ELEMENTE_CODELEMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D989C901D7C2B3B9EE9FEF6344A88B822E7768F9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ELEMENTE_CODELEMENT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULARE1_CODEMULARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57173ED19FD13C8AA438BBE38269D3D38ED96910</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULARE1_CODEMULARE1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULARE2_CODEMULARE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>032957DA6AE60625F47F4D7EE33EA95BCA43B843</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULARE2_CODEMULARE2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULARE_BONID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66787CB157F83FBA441B7103E010E318B523B1F3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULARE_BONID INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULARE_CODEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29507E3252B09AC41B7E47F8B09F45E10416797E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULARE_CODEMULARE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULPUNCTEUSED_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>150A700BBBCCDB8B19951585702667894781F987</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULPUNCTEUSED_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EMULSTINGERI_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F51429ECE63FE81A9955A2A4859DE8A3B9DFA367</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EMULSTINGERI_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ESTIMARINOD_CODESTIMARENOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD716E412C98F9A60EF4D63EB002E334FA93D672</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ESTIMARINOD_CODESTIMARENOD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ESTIMARIPROD1_CODESTPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84CB12E40BD8ED5AC1597390196AA500F5EBC02A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ESTIMARIPROD1_CODESTPROD1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ESTIMARIPROD_CODESTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B34A0C0D76DBB44CD8BC7BED169CC1C4B60521C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ESTIMARIPROD_CODESTPROD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ESTPROD1M_CODESTPROD1M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>65704E46680DF9B795C4098D1DAB01384FE5594F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ESTPROD1M_CODESTPROD1M INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ESTPROD1N_CODESTPROD1N</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8991963202E79DD82D6DAE5C48A2220BD1A97C0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ESTPROD1N_CODESTPROD1N INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ETICHCOLET_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70A725D8116D08B12FADDF2B5EBD18F7C9D30631</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ETICHCOLET_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EURO_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCF105FF65B0D16527F0FFF4A0F3CF946A58A2D2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EURO_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EVALSEV_CODEVALSEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29698959F5A20056F36BEC9EF0C0314D948E1A96</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EVALSEV_CODEVALSEV INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EVALSTES_CODEVALSTES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B82D75EE9FD7A2E539BB98E57073B69994A42904</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EVALSTES_CODEVALSTES INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EVALS_CODEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF6F30832CF44C0E3129ABC3B39E5466AEF3019F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EVALS_CODEVALS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EVALUARI_CODEVALUARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA7C028FF5F7633C58A7AC831C8229AF203A73C5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EVALUARI_CODEVALUARE INCREMENT BY 1 NOCACHE START WITH 267</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EVALUATORI_CODEVALUATOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>065FA3EB03293EB1B6C018F04D3DFC56D6076333</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EVALUATORI_CODEVALUATOR INCREMENT BY 1 NOCACHE START WITH 135</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EXPERT1_CODEXPERT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD97812E855485D252FDDC8017CD6A12A96AD970</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EXPERT1_CODEXPERT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_EXPERT_CODEXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72988EF591C9B6024D9768617AEEF941B0EA852B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_EXPERT_CODEXPERT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZ0_CODFAZ0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>356686B45FB684419539A27CB546D5C318568C87</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZ0_CODFAZ0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZ1_CODFAZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C9002B7385AD49359D1870D0E24E798DFBD521F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZ1_CODFAZ1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZ2_CODFAZ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36D51ED13B7C67CF2BF94837D999F6EC97731217</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZ2_CODFAZ2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZ3_CODFAZ3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBD7E5C108A8F2347F1A93DF96AB4ED93898095F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZ3_CODFAZ3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZINTR_CODFAZINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED7BF02B28547934FA93CD1DBD0D951DE1D08375</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZINTR_CODFAZINTR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FAZ_CODFAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C50F2340E52588AF384D29F4BADF665896C690BC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FAZ_CODFAZ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FIRMECUPLATE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72712E1ABEAB172F3DAA85619006E0853A803A67</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FIRMECUPLATE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAEVALP_CODFISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B77741686BDC17AF5D7E84339488498114499948</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAEVALP_CODFISA INCREMENT BY 1 NOCACHE START WITH 285</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAEVALT_CODFISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B1C1513AEE26879AEB5F2878F6BA2C8E178573B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAEVALT_CODFISA INCREMENT BY 1 NOCACHE START WITH 182</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAINF_CODFISAINF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5000712DED861F896296232B4622DCD42C29CAF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAINF_CODFISAINF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAMAND_CODFISAMAND</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26D358A6332F9683D9776A80636789B1B2A6A761</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAMAND_CODFISAMAND INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAMAN_CODFISAMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAE5B92B383B016DF75580867DE8408DA97530E0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAMAN_CODFISAMAN INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAMAS1_CODFISAMAS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E6E836C76A095EE118163EE78F88E6F4BA2795E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAMAS1_CODFISAMAS1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAMAS_CODFISAMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C07B8CB5DDABE3A1CE46D07939EA8E66401A893F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAMAS_CODFISAMAS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAMF_CODFISAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20C141C9FAB58D41D70501C33547C7642A20EF80</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAMF_CODFISAMF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISAREZ_CODFISAREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>86475CD25EB3D56E068D0658178C634A6B2F5DA2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISAREZ_CODFISAREZ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISASDV_CODFISASDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B110223E1AB755FA1B31C21A7BB05E3389281D3E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISASDV_CODFISASDV INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISASUP_CODFISASUP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3508F45AFD643D9FAEEBFC2DD06EE7434891D0AF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISASUP_CODFISASUP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FISATEH_CODFISATEH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E75867752AC6B63E0D2D1A2F3BF8B2E1EFAE2E3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FISATEH_CODFISATEH INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FORMATII1_CODFORMATIE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21C641B51826038588B39968F4E81E898DC05B01</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FORMATII1_CODFORMATIE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FORMATII_CODFORMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>623BD5513B4D73A44CDF716996CD61050F198C6D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FORMATII_CODFORMATIE INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FORMATORI_CODFORMATOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF0B1F25A8DEFAFD91B60F81C6B330CB1E51B8A2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FORMATORI_CODFORMATOR INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FUNCTII1_CODFUNCTIE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F019864FC1216C8AFB5D65C73E0EEC2839DF4234</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FUNCTII1_CODFUNCTIE1 INCREMENT BY 1 NOCACHE START WITH 112</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_FUNCTII_CODFUNCTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56884ACD2A33CE0B27613C406D3C92D4CEBA6009</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_FUNCTII_CODFUNCTIE INCREMENT BY 1 NOCACHE START WITH 107</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_GANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46514DB3AEB756DADDC275200E697BC99CADBA1E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_GANTT INCREMENT BY 1 NOCACHE START WITH 221</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_GANTT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F891CF9C551699B6A742BAFC501C6951DEC96D7E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_GANTT1 INCREMENT BY 1 NOCACHE START WITH 3776</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_GENERAL_CODGENERAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BB345453836ED6D289202DB486752F513CE615A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_GENERAL_CODGENERAL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_GRECHIV_CODGRECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3AC6FECD9FB10E848DF52989D439BC78518DCEB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_GRECHIV_CODGRECHIV INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_GRUPEDRUM_CODGRUPA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1516FF3F2A6B4BAD09A896B10F7C7DA0DEC0A433</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_GRUPEDRUM_CODGRUPA INCREMENT BY 1 NOCACHE START WITH 123</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IDCANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E5C299DBB23B2BBB966433C620F9616D731EE19</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IDCANTAR INCREMENT BY 1 NOCACHE START WITH 100</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IDENTEVALS_CODIDENTEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66D5F0820CCFD877C3F38308453A11CC9542A5DA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IDENTEVALS_CODIDENTEVALS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IDSEDIULOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE04C9EECB32B7CDAAC396CFC09ACEC2AB6E874F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IDSEDIULOCK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESDISC_CODIESDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F0F3DE8C7CCA9FA178100BAFB562C09156F9721</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESDISC_CODIESDISC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESIRI1R_CODIES1R</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BE70A5C3A65EBFB7D03CE19752746ECFB3EF34F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESIRI1R_CODIES1R INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESIRI1_CODIES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88B6B117FCA3C367A4B1CDB3EDE3FBFA15160BE1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESIRI1_CODIES1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESIRIR_CODIESR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F0F9ACF50698D1E3854B5C67D7576BD160C8ED3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESIRIR_CODIESR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESIRI_CODIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A21A7401377926D774377FA6065E3C6159EA2179</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESIRI_CODIES INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IESPUNCTE_CODIESPUNCTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1F5F61164AB15B5E65AB707840C9902EC9FA816</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IESPUNCTE_CODIESPUNCTE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IMBMIFIXLINK_CODIMBMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58EA6CA7A18EAE60638A963F72E4FCE93A7186D7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IMBMIFIXLINK_CODIMBMF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INACTIVRETAIL_CODINACTIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF696BE6037CE2625548DC437F57E0533AEF024E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INACTIVRETAIL_CODINACTIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INTERFATAKLG_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8B55E589D557191250A251CFFE40A4EDE6BA69F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INTERFATAKLG_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INTRARI1_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DC7C981F3EC4424ADFDFC96D9180076A1BA1619</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INTRARI1_CODINTR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INTRARI_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3127B45C2FCFA86DB64EC48E23079241769A83A0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INTRARI_CODINTR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INTRDOCTRANSP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B88297F42B98927B7B7147B205F7910841FBE791</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INTRDOCTRANSP_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTAR1_CODINVENTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>013AA935F8DD9F0557A07DF218E1461FF62769F7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTAR1_CODINVENTAR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTAR_CODINVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A051EF5A3C5BF0122DA836D97A2D4AB8C16E2496</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTAR_CODINVENTAR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTCLASES_CODINVCLASES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23794922F557C1D4FA8963F66EA39A2AE052E715</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTCLASES_CODINVCLASES INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTCLASE_CODINVENTCLASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F79F5C0F1207657727E02439D6951EE7C8564FF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTCLASE_CODINVENTCLASE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTCONT_CODINVENTCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5E77C8F6273D80B0B4D8825293DED8A8BCD0F08</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTCONT_CODINVENTCONT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTLOC_CODINVENTLOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06986CB5734A755569094347045661CC972F0B38</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTLOC_CODINVENTLOC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTPROD_CODINVENTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>109093144FD0E388F28D087F621219C265823CAB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTPROD_CODINVENTPROD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTREZ_CODREZOLVARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A3FE7116E3448524AEFC791F62DD95FF60285B8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTREZ_CODREZOLVARE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_INVENTSTOC_CODINVENTSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC53B03F26B4C2780E0569E8433BE99F3BC500F9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_INVENTSTOC_CODINVENTSTOC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOART1_CODIOART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48C0BB18B34AC6AA568F01DB7604EA719CC66B58</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOART1_CODIOART1 INCREMENT BY 1 NOCACHE START WITH 133</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOARTLINK_CODIOARTLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1DA4236FF6C43672E1862DBED912BF16A656FF2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOARTLINK_CODIOARTLINK INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOART_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31E630D351C63CD69FE5F22F4495A9D483B0A9F0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOART_CODIOART INCREMENT BY 1 NOCACHE START WITH 134</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOBANK1_CODIOBANK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB48D9446A2DF12651AD1B353094F557BF12D93D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOBANK1_CODIOBANK1 INCREMENT BY 1 NOCACHE START WITH 108</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOBANK_CODIOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD0DD439B9C0D7BB5F67C0E4C7F2476C6573EA3F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOBANK_CODIOBANK INCREMENT BY 1 NOCACHE START WITH 116</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOFILIAL1_CODIOFILIAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D7DDDAC6017FE20A9D999E56BEB73382192371A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOFILIAL1_CODIOFILIAL1 INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOFILIAL_CODIOFILIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9A44C93CF70BA6BA68FF4359F87556633340BEB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOFILIAL_CODIOFILIAL INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOPART1_CODIOPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7A37E3DE342C1127C29F422445C3FD948365830</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOPART1_CODIOPART1 INCREMENT BY 1 NOCACHE START WITH 105</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOPART_CODIOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66AB64E6D0336F87D42C8843FC36EAAC4BC33DFA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOPART_CODIOPART INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOPERS1_CODIOPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12A4A70F8A1D16BE428D8B63D05868EBFA5ADF68</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOPERS1_CODIOPERS1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_IOPERS_CODIOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC70B16A0665861E9E233D6F816738D1BEAFA64A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_IOPERS_CODIOPERS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBCORELREZ_CODCORELREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA1991178C04A1C32FD17F755AF93652CDF77D27</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBCORELREZ_CODCORELREZ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBCOREL_CODCOREL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28312005D8E7A36912272C669103311D037E984C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBCOREL_CODCOREL INCREMENT BY 1 NOCACHE START WITH 432</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBLISTE1_CODJOB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA44A08FD5533DC5FE351151DE22DE564D301769</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBLISTE1_CODJOB1 INCREMENT BY 1 NOCACHE START WITH 122</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBLISTEFIN_CODJOBLISTEFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3007C3D2C047CA5F23E60C633DF1BE1A33CDF68</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBLISTEFIN_CODJOBLISTEFIN INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBLISTE_CODJOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E4494B148CEEA7F2FC2841D628B3BC8F82FB811</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBLISTE_CODJOB INCREMENT BY 1 NOCACHE START WITH 122</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOBUNIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69E8FE84028C071D91A94E0CECA52F5B9D1D494A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOBUNIC INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOB_LISTCONFIG_CODJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1330DD0F8E1D73F5A12C76ACDE31324D03014BB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOB_LISTCONFIG_CODJ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JOB_LISTE_TABLEID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E4A0E16706243A3F2A623267F06ACFF027D3B1C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JOB_LISTE_TABLEID INCREMENT BY 1 NOCACHE START WITH 2</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JURNAL1_CODJURNAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC86AA76934F3F5587C658CEC4E9DC96609360D3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JURNAL1_CODJURNAL1 INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_JURNAL_CODJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A70D589FADEA30DC7B965603E26C9407CAFAB292</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_JURNAL_CODJURNAL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSARE0_CODLANSARE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D05C5B93AC0BB56A7B15A80B3C5809A444B18ED</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSARE0_CODLANSARE0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSARE1_CODLANSARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>585A13CD86FF220D3B841B9F3C7E3943D1904B77</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSARE1_CODLANSARE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSARE_CODLANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D48A4C62030C3C456387B3F7745C34DC67007FD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSARE_CODLANSARE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSGEST_CODLANSGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F90690716323954FE7B8D37DBC2D796FC704C03E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSGEST_CODLANSGEST INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSPROD1_CODLANSPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5298FBCC50547B9F724B3A41E01AEE472FA56D0E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSPROD1_CODLANSPROD1 INCREMENT BY 1 NOCACHE START WITH 229</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSPROD2S_CODLANSPROD2S</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF4DD66A68FC355A50C451A458246FF88BDB2405</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSPROD2S_CODLANSPROD2S INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSPROD2_CODLANSPROD2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>258B6A3FB6AB536BD6F121A89CE49F589EB06EE8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSPROD2_CODLANSPROD2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSPROD_CODLANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DAE5808F9A7C84848D1A63C239B2A06430C9968</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSPROD_CODLANSPROD INCREMENT BY 1 NOCACHE START WITH 129</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSZ1_CODLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EB970B5395411114A2CDA80F3BF9EB3A211FB5B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSZ1_CODLANSZ1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LANSZ_CODLANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5D26FE03DAE017DCE33CF3957DD875706631C4A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LANSZ_CODLANSZ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LIST_COUNTER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD40324B2F112492C3EBF19D59D937495C181CD7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LIST_COUNTER INCREMENT BY 1 NOCACHE START WITH 2</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LIVR1_CODLIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35B757865A58D9CBD3502246EE478C64CA0476CD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LIVR1_CODLIVR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LIVRVAL_CODLIVRVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFFD7352132AF9ED73493DD1F5C55358C5FF479A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LIVRVAL_CODLIVRVAL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LIVR_CODLIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2FAD6C55BC30705E1FCCE02DFC0E087BCC01415</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LIVR_CODLIVR INCREMENT BY 1 NOCACHE START WITH 105</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LOCMUNCA1_CODLOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAF2783A89E0827ACA1712511D90324610C7E2BD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LOCMUNCA1_CODLOC1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LOCMUNCA2_CODLOC2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE489124E3B830D49E5974AF7D4885A0EDD5C863</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LOCMUNCA2_CODLOC2 INCREMENT BY 1 NOCACHE START WITH 121</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LOCMUNCA_CODLOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06D6CEAC83A75576629B181F6EA2FD821A31123C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LOCMUNCA_CODLOC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LOCURIMUNCAOBS_ID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36A86DA97887CAEDA3FDD5CF393ED8B5037A49AE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LOCURIMUNCAOBS_ID INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_LOGIMPORTDOC_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56F44C7B58F28D990C49824F77CBA2E3CA69CF91</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_LOGIMPORTDOC_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MAILURI1_CODMAIL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B55EE54C4A30D2DDF6BA7685EB7CE7933C8AD75</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MAILURI1_CODMAIL1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MAILURIDOCS_CODMAILDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59101B621230BC44EB8F77744FB0A28DA74F2F1D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MAILURIDOCS_CODMAILDOC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MAILURI_CODMAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A253620E86DEB9852037E703C81E0866F5DF7BE9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MAILURI_CODMAIL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MARCALOCK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D14C5AB7300E9D1FF5FE15FD9DFFAB5728917622</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MARCALOCK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MASCASERART1_CODMASCA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>121E666AE4D4E092C8E0868EABD60929E0605A35</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MASCASERART1_CODMASCA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MASCASERART_CODMASCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B76627344F15B4D22FC4415A8372D77FB26A3115</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MASCASERART_CODMASCA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MEDEX1_CODMEDEX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70F96DD02CE68922A58AA367ED4CD97F22D0DA7F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MEDEX1_CODMEDEX1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MEDEX2_CODMEDEX2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DC7843417B13D87CE5A24066F1BEDCA4A9EADBD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MEDEX2_CODMEDEX2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MEDEXT_CODMEDEXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>671DE3DEF913099B1796A26757DA1ACFD7FB8553</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MEDEXT_CODMEDEXT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MEDEX_CODMEDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FFA792A5C33AD7F83765B6CD9D3B42BAE29F82A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MEDEX_CODMEDEX INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MENUDASH0_CODMENUDASH0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77A984A76B91655267591A8D0DABA65FBB74538A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MENUDASH0_CODMENUDASH0 INCREMENT BY 1 NOCACHE START WITH 729</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MENUDASH1_CODMENUDASH1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3411D2F85D1E9A6253CD2C733156F6A6F7AF9D11</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MENUDASH1_CODMENUDASH1 INCREMENT BY 1 NOCACHE START WITH 107</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MENUDASH_CODMENUDASH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCAFD0E10F0B32767E101416FA00074BD32BE722</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MENUDASH_CODMENUDASH INCREMENT BY 1 NOCACHE START WITH 106</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MENUDATE1_CODMENUDATE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>400963EB7F42B054A30FC5A1A4E4E8FD53A66379</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MENUDATE1_CODMENUDATE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MENUDATE_CODMENUDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14441FAB0CDCFE82FCD852B6375B3101AD87AB37</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MENUDATE_CODMENUDATE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MESAJE_KLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52E35BF4BBFE73A6F13E7A410D8F87AC44614E20</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MESAJE_KLG INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MESE1_CODMASA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D684F4DD4B203CD13AFE63265B69C45D820D2E59</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MESE1_CODMASA1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MESE_CODMASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63A696C085ADC4A8A28D481D5DFEA0AA95D84EF7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MESE_CODMASA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MFCLASIF_CODCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0C7AAD1F0943CB2C10B612C4B578299626B41F7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MFCLASIF_CODCLASIF INCREMENT BY 1 NOCACHE START WITH 609</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MIFIX1_CODMIFIX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>666B2CEBEF383B1D876CB95F07BA5A947BAC1073</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MIFIX1_CODMIFIX1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MIFIX_CODMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CD36945F7C857D53753C0151A199B93C14C2CE5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MIFIX_CODMIFIX INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MODIFICARIPRET_CODMODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10EEA4B7B0EBD0F6A1A0C7129D75FFF4C53FE78E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MODIFICARIPRET_CODMODIF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MODIFICARI_CODMODIFICARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C555B18AF08C4EFCF0567E1E2C73B2B2E9368E83</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MODIFICARI_CODMODIFICARE INCREMENT BY 1 NOCACHE START WITH 2505</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MODPLATA2_CODMODPLATA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>335CCE9AD796CCE9E98F758AD6BF3050DAAA9353</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MODPLATA2_CODMODPLATA2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MODPLATAIESRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4E2EDB483E99DFAB17F4EECEA2CDBC621F05C5D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MODPLATAIESRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MODURIPLATI_CODMODPLATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A915BD00B0F94DA27BBF14E1B1F4F51BCFA5274</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MODURIPLATI_CODMODPLATA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MOTIVEP_CODMOTIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EDE25FF3ABF40DAE9C2A74E02591843BE11ACCA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MOTIVEP_CODMOTIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MOTIVE_CODMOTIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF77249AF709ECF8F8B94F4460980FDB1AF37976</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MOTIVE_CODMOTIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MPBCAR1_CODMPBCAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A79F42153290012D3D7BD6FA2A05D3D30326113</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MPBCAR1_CODMPBCAR1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MPBCAR2_CODMPBCAR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>296A1CCBE58E67C6AE6943C04871AE6678E332D8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MPBCAR2_CODMPBCAR2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_MPBCAR_CODMPBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE93C7973A5AA698E3D3DF2F31454A93A988AC59</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_MPBCAR_CODMPBCAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NACTIVIT_CODACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81962FE0386DCC35D1FF9179F2B127726ECEC0A5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NACTIVIT_CODACTIVIT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NAGENDA1_CODAGENDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A981544B27AA6BC14E1D002498F7BE9D48B52A4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NAGENDA1_CODAGENDA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NAGENDA_CODAGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2FF5FF5A34A19AFF52CB877BF98422B3720C171</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NAGENDA_CODAGENDA INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NAGENTI1_CODAGENT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9598F7B0B20121F4E6D599E3B6662F70FCA65B74</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NAGENTI1_CODAGENT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NAGENTIPROC_CODAGENTPROC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0010640F47A4332268A5FB90C0C51DE3D6EACC0A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NAGENTIPROC_CODAGENTPROC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NAGENTIVAL_CODAGENTVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C326AFA8D8C0BA4A005882D351D3ADC9B5A02C96</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NAGENTIVAL_CODAGENTVAL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NART1_CODARTICOL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E56D741AE15A0EBEBFFA7F7F99135E2030C8D98</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NART1_CODARTICOL1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTAMB_CODAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3468A581A2A8285273AE82E6A1355D43C8D9B076</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTAMB_CODAMB INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTATR_CODARTATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>80D86AF440810C9CDE696FE06F9620763CEA9094</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTATR_CODARTATR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTCLI_CODARTCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FCF5AE1CE2926C261594E86BE17E90E06D3014B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTCLI_CODARTCLI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTDIM_CODARTDIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E110E3A6D82198F0D5884AC53B6D08893B2F439D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTDIM_CODARTDIM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTIMPLICITE_CODIMPLICIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49CA1478D5DC5280BF774F9132DBFCFF1AD41B18</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTIMPLICITE_CODIMPLICIT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJ1_CODOBIECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05F45D281C3EC18FB4BCCDBC9C3E5C596CF2EBF7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJ1_CODOBIECT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJCOLET_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88DC61FBE451D87C13E9C93DC2660A5D917A11A6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJCOLET_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJIMP_CODOBJIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>695EFC904AD13DF93C4C5A9EC3537E440BF0DFBE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJIMP_CODOBJIMP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJSUBUNIT_CODS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C90C6C21D8878BAEB16B932CA27575C5D0576B37</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJSUBUNIT_CODS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJTRAD_CODOBIECTTRAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B141D8A542BFFB8DC3907F764284C6558961DD87</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJTRAD_CODOBIECTTRAD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOBJ_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39F2992E382CAE8204F5444654350409941BD9F6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOBJ_CODOBIECT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NARTOPT_CODOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CECBA2D3A6CCE12088F7FCB549367EC069B9D168</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NARTOPT_CODOPT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NART_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72FB99513C90652DCDCF081922C1965A6CBACBE5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NART_CODARTICOL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATRIB1TRAD_CODATRIB1TRAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D0D267389497E622559A8CC107C2C02BECB9CDF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATRIB1TRAD_CODATRIB1TRAD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATRIB1_CODVALATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3047B0A49A4CADEB1BFA53EA44DE486FE225D32</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATRIB1_CODVALATR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATRIB2_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDFB72EEA828788A348E5BF5516115F36A99FD8C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATRIB2_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATRIB_CODATRIBUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF676137D4CBE7483F230E028C97DC1538BA1FAF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATRIB_CODATRIBUT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATROBJ_CODATROBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70F820EDA5E4547B507B5E8CACDB8080570890DA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATROBJ_CODATROBJ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NATRTRAD_CODNATRTRAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C95E9912091960AEC2317517F2D0F498A39BD1F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NATRTRAD_CODNATRTRAD INCREMENT BY 1 NOCACHE START WITH 122</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NBANCIRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CFA64C79BA7E2A5D24B9A00AA12E18DA843159AE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NBANCIRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NBANKCONT1_CODBANKCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4F4843D982F4B56718409B1AFC0B8DB1458187C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NBANKCONT1_CODBANKCONT1 INCREMENT BY 1 NOCACHE START WITH 122</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NBANKCONT_CODBANKCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D65214013AB0551D3A2F647977EB902AD829D8F5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NBANKCONT_CODBANKCONT INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NBANKSOLDLUNA_CODSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6DEED753464B03D7249FBF07D45EA7B5985939DE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NBANKSOLDLUNA_CODSOLDLUNA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NBANK_CODBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4117DC630B3FDBB9C07ACBF49083FA20221CBFE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NBANK_CODBANK INCREMENT BY 1 NOCACHE START WITH 137</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NC1_CODNC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9B10A0DEEC38ACD366DEF4606FAE13F95C5B66B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NC1_CODNC1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCARSUPART_CODCARSUPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>157B5F408F46E6C687757090624FFC66FCEB8B8D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCARSUPART_CODCARSUPART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCASEMARCAT1_CODCASE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EB842D74E8EF45EF43E72BF861611C27F5CE455</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCASEMARCAT1_CODCASE1 INCREMENT BY 1 NOCACHE START WITH 122</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCASEMARCAT2_CODCASE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>537A281E0C0120CA7235D0205ED4C0D92A4BC4C9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCASEMARCAT2_CODCASE2 INCREMENT BY 1 NOCACHE START WITH 142</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCASEMARCAT_CODCASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02229CF37A66D0F393BB7DCB28FD5FFE3C54E4D6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCASEMARCAT_CODCASE INCREMENT BY 1 NOCACHE START WITH 144</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCATPRET_CODCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E10203CBE0CF7AE3F2D343D827934B4A63F355C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCATPRET_CODCATPRET INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCCADOURI_CODNCCADOURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0096949A23B028BA8888FCED93552F036D67F053</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCCADOURI_CODNCCADOURI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEAS_CODCLASEAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A692C6DF55FDB5A639B35197ABE3263BF0A7CB8C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEAS_CODCLASEAS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEA_CODCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11C99ADDFBF59EDE5AC03CC9CC66B2A05B25E0A1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEA_CODCLASEA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEDISC_CODCLASEDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>729A38C39B74CDED990A950590B13803788CCC25</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEDISC_CODCLASEDISC INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEG_CODCLASEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBED92FAA7890E0B34D7C227E1CC0D860F732482</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEG_CODCLASEG INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEINT_CODCLASEINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53B19C0782A6548A18F94D7A01EB19B8FD247A42</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEINT_CODCLASEINT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEMF_CODCLASEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B2BCDD042A8AE76FD6541DA2E6FEC03767B0627</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEMF_CODCLASEMF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEOPT_CODCLASEOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E25B768A67F179FE3C1C8B93FA3819CF3A787773</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEOPT_CODCLASEOPT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEOP_CODCLASEOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48622BD8468275C38D35180ADDE5C7606869DB35</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEOP_CODCLASEOP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEPROD_CODCLASEPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56848530469D130C0092F651A315A8E4CF1CD9F8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEPROD_CODCLASEPROD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCLASEP_CODCLASEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F930EB5F68DDC70C702DB432894A19F49CE68779</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCLASEP_CODCLASEP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCODFISCRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34A681851248D400862B295D7C215AD6181AEDD3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCODFISCRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONT1SUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C19B8DDF2161C3FF46625A5DC2B0D59FFB08010A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONT1SUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONT1_CODCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87DC19FE5BC3A0435BD7E7E8BF847059CADF307B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONT1_CODCONT1 INCREMENT BY 1 NOCACHE START WITH 1579</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTCOMUN_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>812740856DA93E0FE406D72D113D8A16CBE64204</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTCOMUN_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTECHIVSUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>732983C346845BD661C30D21514D27F44476D958</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTECHIVSUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTECHIV_CODCONTECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>573F279B42420E3EA74F9E89030184352D473721</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTECHIV_CODCONTECHIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTFIRMECUPL_CODUNIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA25393E7866748C971BD7C2412BD5C3A24AE73C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTFIRMECUPL_CODUNIC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTREPRULSUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EC92B403C1283D9F8158A55E7CBEBBB94B0415E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTREPRULSUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTREPRUL_CODCONTREPRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A26D916BF893EC90079679AF5DB1DA05C55C7620</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTREPRUL_CODCONTREPRUL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTREPSOLDSUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7646B0450923F047BEE2E3128DA23D12540E8FEA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTREPSOLDSUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTREPSOLD_CODCONTREPS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>620CE86CB4054B453DFFCF7F5FAF32E5843B563B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTREPSOLD_CODCONTREPS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTREP_CODCONTREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9458D7945D14A0FDDAD9B8A685AD40F8B26B95F9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTREP_CODCONTREP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTRULSUB_CODRULSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7314C8347401D47D6154E40A2A66A495716966E6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTRULSUB_CODRULSUB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTRULS_CODCONTRULS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA3DF2C740C18CE0967041D559B3F9A62C995994</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTRULS_CODCONTRULS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTRULT_CODCONTRULT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEA078CD805C0C9ADD51C3DEE2FC37E135AAA6DC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTRULT_CODCONTRULT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTRUL_CODCONTRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05B855696B265A3967D67DF5ED2AD2F5F68D59B9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTRUL_CODCONTRUL INCREMENT BY 1 NOCACHE START WITH 14790</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTS1_CODCONTS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E0BFAA4330F97B0EF1F4EA4CF1FCA4CA1ECACF4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTS1_CODCONTS1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTSOLDSUB_CODSOLDSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98D0CEFF2E69DFD77E5D2761B81A4F5CF8F6DE9B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTSOLDSUB_CODSOLDSUB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTSOLDS_CODCONTSOLDS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EEEE24FE7DADA41D6C4B214DE8AEAD440D0F6F3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTSOLDS_CODCONTSOLDS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTSOLDT_CODCONTSOLDT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>288C0203F9B9D3E5718C6E79D3097D362CDAF98F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTSOLDT_CODCONTSOLDT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTSOLD_CODCONTSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9933DA4D93156D790366B88C677A8AF9F606A37A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTSOLD_CODCONTSOLD INCREMENT BY 1 NOCACHE START WITH 1400</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTS_CODCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89266BF58593D4B26307F1AB528CD1A1E5620747</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTS_CODCONTS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTT1_CODCONTT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>117630B32A421EC724100597FEFE38C91FAE7B0B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTT1_CODCONTT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONTT_CODCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F514E179184B54B5E59094F9E269F67C66416BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONTT_CODCONTT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NCONT_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42498D59E11B6FDDCA558A1C2F0518D16F58308E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NCONT_CODCONT INCREMENT BY 1 NOCACHE START WITH 11230</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NC_CODNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A8725BA3CC2E6C4B2032E598F1B7C4171CEC4D7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NC_CODNC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NDELEGATRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9F52763461E3E088B2A45A8FC76F48206A18CDC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NDELEGATRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NECESAR_CODNECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70FAB35AB7BD0093B889D18D19DD676BAAAF1980</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NECESAR_CODNECESAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NECHIV_CODECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B23C9C1C5FD518207449B9A0E2B6F1EB1EC09A8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NECHIV_CODECHIV INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NELEMAERO_CODELEMAERO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>473D960ABFFC98CEBF32CF702BA68B31AEB43C50</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NELEMAERO_CODELEMAERO INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NESTJURNAL_CODNESTJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF591FF0F9EB0E70E5E69CCA6D0C28FD2CF12C3F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NESTJURNAL_CODNESTJURNAL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NGAMEART_CODGAMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4E90AC651EA685455BA5193CC8B4D87AB69AC27</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NGAMEART_CODGAMA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NGEST1_CODGEST1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40C017C3A96F37C74AAFC52A95329D63DA66BB7B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NGEST1_CODGEST1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NGEST_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D09BA25E2A1EA26E4AFFDF7000EF7797803157C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NGEST_CODGEST INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NGRUPEAUTO_CODGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F06721BC1A2B9722630ADA77710A87C22FDEE142</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NGRUPEAUTO_CODGRUPEAUTO INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NIMOB_CODNIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCA0E519BA566DAE34D9E1BD68AB5C86A6FC0DDF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NIMOB_CODNIMOB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NINSTAUTO_CODINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC66AD1D6F5C7392BA1B8D1C3FEAD8814F97CA20</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NINSTAUTO_CODINSTAUTO INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NINTERV_CODINTERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B00ED41C60482D4526CC38B4F5C6153C1614A43</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NINTERV_CODINTERV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NIRSER_CODNIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9487DFD1A786C4BC021BCEA64AD1C0326715E59A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NIRSER_CODNIRSER INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NIRSTOC_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0729FAE3B2B5203F72ACA3FC15742134C706675C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NIRSTOC_CODNIRSTOC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NIR_CODNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8215924EBFC954A2B3B771C73F5376817B4F64B1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NIR_CODNIR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NJUDET_CODJUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D89ECFB149C928626EF16F7ADB0F2B07B57476AA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NJUDET_CODJUDET INCREMENT BY 1 NOCACHE START WITH 144</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NLIMBA_CODLIMBA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07DCBB219EE39DF0C24F325E758AA2AA9315C00E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NLIMBA_CODLIMBA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NLIMCREDIT1_CODLIMCREDIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92B28B34A893932367B647334B77EA47414E9D26</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NLIMCREDIT1_CODLIMCREDIT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NLIMCREDIT_CODLIMCREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8F1DA6F158FFC5C83E695FA4D270409C535F210</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NLIMCREDIT_CODLIMCREDIT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NLOCALIT_CODLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CADE957D9D02770C2DD9D42CA880EE775F7915BC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NLOCALIT_CODLOCALIT INCREMENT BY 1 NOCACHE START WITH 13855</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NLOCATII_CODLOCATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C9747BB0D71AFC05D5C2A46BB10C6EF7E7F3EBD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NLOCATII_CODLOCATIE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMAKETE_CODMAKETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D9F1DBB5CD6D468E7DB0E7ADC803BFAF321EE7D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMAKETE_CODMAKETA INCREMENT BY 1 NOCACHE START WITH 511</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMARCIAUTO_CODMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5EF91BC7D5AC5ED228A204EFDC39E91B4B0A4BC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMARCIAUTO_CODMARCIAUTO INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMESERII_CODMESERIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E66BB0599AE5ABC48F72D565A241DB6D3382F8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMESERII_CODMESERIE INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMODELEAUTO_CODMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E42A8F088D51FBEB80F8A59D305A305022AB957</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMODELEAUTO_CODMODELEAUTO INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMONEDE1_CODMONEDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D47569B59A992B8CFA92EA5797C5C252BCB6725</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMONEDE1_CODMONEDA1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMONEDE_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>041CA34B2224A73912C1AC35EB34C23E09349328</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMONEDE_CODMONEDA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NMVS_CODNMVS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CA6BCE7E368443EF13D333914A97BD7250B8FF4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NMVS_CODNMVS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NOPER1_CODOP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA837DC19962DE086BE1E20682430ECB42D2EDB7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NOPER1_CODOP1 INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NOPER_CODOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>58F79462B47BEC7BE5FB07B2F9B452D8CCE49596</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NOPER_CODOP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NORMEMAT_CODNORMEMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED7B54A6B56218D1894F9EC8B6285620FCEDE261</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NORMEMAT_CODNORMEMAT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NOTECREDIT1_CODNCREDIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F2A2C39BABFAA4140766F6D9C141C21EC4C8518</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NOTECREDIT1_CODNCREDIT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NOTECREDITFACT_CODNCFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A84F743553A2239D8134D323AAEB9A4F7E5DF0DC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NOTECREDITFACT_CODNCFACT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NOTECREDIT_CODNCREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>180D44AB38CE406C54D46872A8A0B29F7B19E6BB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NOTECREDIT_CODNCREDIT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARC0_CODNPARC0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>321552D3556E755F1768CE36635B94DC08AB25DF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARC0_CODNPARC0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARC1_CODNPARC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FCAC92074EC788F986AF353FB3AA071BB43D443</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARC1_CODNPARC1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARC2_CODNPARC2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37EB384530F78FCACEC528F6FA8DF04E464B0909</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARC2_CODNPARC2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARC3_CODNPARC0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5ECE83AE2CAF74FD2DE1D080E437590AA354A02C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARC3_CODNPARC0 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARC3_CODNPARC3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B708D83FECE3ED4BFD35ED1D309016EC4E871D6A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARC3_CODNPARC3 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARCAUT_CODNPARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC7DC4048698B4BD359CBCAD2FB050964711F540</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARCAUT_CODNPARCAUT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARCCOM_CODNPARCCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD2FF4FEE41BABF7A060D4858CFF5FFC56977879</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARCCOM_CODNPARCCOM INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARCG_CODNPARCG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>343F847FB083783DF575C8071A81EE6A7165F501</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARCG_CODNPARCG INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPART1CRM_CODPART1CRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51225B6DD6E9A5918D410DE4A1D1E5BB53934D61</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPART1CRM_CODPART1CRM INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPART1_CODPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>592F860A732516A81B57FB09925B60B23F137DCD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPART1_CODPART1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTACTIVIT_CPA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C3C969AA311B12918EE05684C5E18E530A42A1D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTACTIVIT_CPA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTB_CODPARTB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2518F4CAF4692D6D3154B723AC2A1E8E8ABF2A3E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTB_CODPARTB INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTCODFISC_COD_CODFISCAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2073A61867DDC21726DE96ED6FDB0E15B1BADC3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTCODFISC_COD_CODFISCAL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTCONCURENTI_CPC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A57C94332F0A2DEE2C8F340A7AA1F707F4A7725</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTCONCURENTI_CPC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTDISCRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB1157A3BED26B3F27BDB64E5829F683271BEAD8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTDISCRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTDISC_CODPARTDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12C58207A4FD307F4FA17F61D06B17BB03256E0E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTDISC_CODPARTDISC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTDOMACT_CODPARTDOMACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6121E6CF0A0308B26A39D6F7803865FF1986885</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTDOMACT_CODPARTDOMACT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTLC_CODNPARTLC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94D3F5787FEDD0BAFDD97F17D2A52CAA25038819</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTLC_CODNPARTLC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTOPORTUNITATI_CPO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>001A1251D8152E162363464A3CC575EFD42E780D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTOPORTUNITATI_CPO INCREMENT BY 1 NOCACHE START WITH 100</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTRETAIL_CODPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4FBD389AEB2E1BCFD09ACD0445B13D69389DC0E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTRETAIL_CODPARTRETAIL INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTSOLDLUNASUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED6503CB05073A5342D23FF7DF19C4043F36168D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTSOLDLUNASUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTSOLDLUNA_CODSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A78188AAB87AB424A978CAD4D5BF9E4FA26ACF53</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTSOLDLUNA_CODSOLDLUNA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTSUBUNIT_CODPARTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14BBE65C145BB4D2331355894183FF806CBF65B3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTSUBUNIT_CODPARTS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTTR_CODPARTTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16CB19D5E385AF82014D7012AA0189FA915D3942</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTTR_CODPARTTR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTTR_LNK1_CODPARTTRLNK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70C67C8E6D463F99BCC3AD6BEC26D7FBF9AB55EC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTTR_LNK1_CODPARTTRLNK1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPARTTR_LNK_CODPARTTRLNK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E06802E658C50A96AE840CBA5DCC542DE1ED69D5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPARTTR_LNK_CODPARTTRLNK INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPART_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EAB9490F2E8B3F5A5C03185704E7054DDC8871FF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPART_CODPART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERS1_CODPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B794870C1F98A821D1B1CFF82E403DB19760A0F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERS1_CODPERS1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCONTACT_CODPERSC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2BBC38BE8C5F6E294327447BD9F1967B01411E9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCONTACT_CODPERSC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCURS_CODNPERSCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EE2DF7331AF4C57FA581334DE0A6CC7347CC5AD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCURS_CODNPERSCURS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCVLOCM_CODPERSCVLOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC1BC026D8115C30CB95AFA611D7CC4B85974D39</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCVLOCM_CODPERSCVLOCM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCVPAS_CODPERSCVPAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5715FBA4507397D9CA9889D6FBE4F6E14A2EF5B1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCVPAS_CODPERSCVPAS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCVSCOL_CODPERSCVSCOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E884D6A688C6C7056CE8460F2BE09D4F67850D52</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCVSCOL_CODPERSCVSCOL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSCVSKIL_CODPERSCVSKIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>238CCE6670679063716A473D184B9E974F785AFE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSCVSKIL_CODPERSCVSKIL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSSOLDLUNASUB_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C2FD16FCD9EE9C10C37E274C8ABFB822E755D20</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSSOLDLUNASUB_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSSOLDLUNA_CODSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38CDD52478A33DF9A389833391F09AAD948DD1D8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSSOLDLUNA_CODSOLDLUNA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERSTIPLUCR_CODTIPLUCR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDC66F71731257CAF6B07893AC3C5E81DD387417</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERSTIPLUCR_CODTIPLUCR INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NPERS_CODPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BF06DEAD76EA9B6F797128539163B6CCEB7C98C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NPERS_CODPERS INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NREMAUTO_CODREMAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED735EC6E36EFD85527CFC00030BDBD5412C31DD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NREMAUTO_CODREMAUTO INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NRINVLOCK_CODINVLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90A03A94D98799D43F5CF10541660CE6AD7F9F0B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NRINVLOCK_CODINVLOCK INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NRINV_MF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05137A38F7E06210ABC105BC23956AACC615E1A1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NRINV_MF INCREMENT BY 1 NOCACHE START WITH 2</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NRI_CMDINTERNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82822396193EC5F5AC5F4D8F65649AC7838BE0BD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NRI_CMDINTERNA INCREMENT BY 1 NOCACHE START WITH 1000</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSCADTL1_CODSCADTL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29E19B29877B57E6DEAF817A967B4696CC670ECB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSCADTL1_CODSCADTL1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSCADTL_CODSCADTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>802820058FCD57E72EFA4AD9E1B7C134E4D3B91C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSCADTL_CODSCADTL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSEDIIPARTRETAIL_CODSEDIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34FF05BB1A2373BE8216B7CBC1842D6F2032B935</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSEDIIPARTRETAIL_CODSEDIU INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSERII_CODSERIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B328A3489D479950466A33E71E90B079B3CF668E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSERII_CODSERIE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSERTAR1_CODSERTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3796BE0C44A8A24ADB5C96CEB6986C3D14D0E387</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSERTAR1_CODSERTAR1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSERTAR_CODSERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E908BCA550A256AD1FC35D0F504DA389ED5693A6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSERTAR_CODSERTAR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSUBUNIT1_CODSUBUNIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>025171D77DD38FE9A2872423AE889A8547BD53B7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSUBUNIT1_CODSUBUNIT1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NSUBUNIT_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBF53E6B37C6CF7072E237691E3972A0B00C2A87</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NSUBUNIT_CODSUBUNIT INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTARI_CODTARA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>225A6BFA961E8434058F99DCB825936A171B26B5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTARI_CODTARA INCREMENT BY 1 NOCACHE START WITH 362</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTAXE1_CODTAXA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B40F80FBFE6C0A22A6D30CDF508FBD1C8C3695D3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTAXE1_CODTAXA1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTAXE_CODTAXA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A30A2F40299FEEB677A00E3B052F88223D6769E7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTAXE_CODTAXA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTIPSEDII_CODTIPSEDIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F75092C2AD203A4786A711A8782AC4FBD656228A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTIPSEDII_CODTIPSEDIU INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTVA1_CODTVA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6B2B0AE088C34EBF1AA4B43A4B5888A854A338B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTVA1_CODTVA1 INCREMENT BY 1 NOCACHE START WITH 106</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NTVA_CODTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>019FE297ACA7C702A42B35E8CE0FF20D93A072F6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NTVA_CODTVA INCREMENT BY 1 NOCACHE START WITH 116</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NUM1_CODUM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A22C558F694946A3E84C776639CCC362A331142</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NUM1_CODUM1 INCREMENT BY 1 NOCACHE START WITH 119</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NUM_CODUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21DF31B0552EC8BE228A3199D6346BB90CF3C974</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NUM_CODUM INCREMENT BY 1 NOCACHE START WITH 117</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_NZONE_CODZONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5D2B8A074C9953FC3F8F57E78B24E28DEA6ED62</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_NZONE_CODZONA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OBIECTIVE_CODOBIECTIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00339C693EF14065791E8C985EDBEB1A9FE16714</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OBIECTIVE_CODOBIECTIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OBLIGPIF_CODOBLIGPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC7AFB3F02C1D2E72677F79862BD58050BE487B5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OBLIGPIF_CODOBLIGPIF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OFERTA1_CODOFERTA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>260B192C0A760986FBEA7BAC8677C72CBBD75AA3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OFERTA1_CODOFERTA1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OFERTA_CODOFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6785AF133F343C4C4B9141268F40AC7BE58AAD39</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OFERTA_CODOFERTA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPORTUNITATI1_CO1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A62AA773B13C8DA3528F2F59ADECB434E4E8799B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPORTUNITATI1_CO1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPORTUNITATI_CO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D78D126405CABEA3527D4E2671D188EF9E49CAB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPORTUNITATI_CO INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPPER1_CODOPPER1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37CB19FAF89172CE23DE361A4599D998EA3B6E8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPPER1_CODOPPER1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPPER_CODOPPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51E64AEC85DB12E63AA63A19751A4F331C9FB1F6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPPER_CODOPPER INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPREG1_CODOPREG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6C9F3EB7F2644B86EE37381A3C0EBED77D17D73</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPREG1_CODOPREG1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OPREG_CODOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EED337F43D7CFD931330F71962E9AC166ACF6141</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OPREG_CODOP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ORAR_CODORAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4E6DA45F1A8D1DFA80ACB1FD026B757B8F0FD3A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ORAR_CODORAR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ORELM_CODORELM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>175539577D498CF37F6B511F0A38AA37CD5AFA3B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ORELM_CODORELM INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_OSPATARI_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBD6B4498AA3C971EDD9BCD3E859871C5726846C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_OSPATARI_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACHETE1_CODPACHETE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2ADEE74E2A5040F97C6F295CD0136B8FB621B712</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACHETE1_CODPACHETE1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACHETEOBJL_CODPACHETEOBJL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1F82CABF18820188A8010D0F09F7C2927DB2DC9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACHETEOBJL_CODPACHETEOBJL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACHETEOBJ_CODPACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB37F84B95DC73502A46B030B76CE31C56C5FDBA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACHETEOBJ_CODPACHETEOBJ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACHETE_CODPACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3693753B3124814A8D90DE8BBA33715EC16439E3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACHETE_CODPACHETE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACKING1_CODPACKING1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D44C0CA282E5512DEB43F4EC5C0AE78F49CF48A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACKING1_CODPACKING1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACKING2_CODPACKING2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9459F3C9B31C5EA0BACF02A7CA9BAB0996E30D7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACKING2_CODPACKING2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACKING3_CODPACKING3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59F597B3F8D626A6792AB11AB2BD00D630AC7E18</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACKING3_CODPACKING3 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PACKING_CODPACKING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8F3B8037F17AB6B637D53EBB467EC602A0E8DA2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PACKING_CODPACKING INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PARAMLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B565A6A2772508191CB820267E305E40109D3A95</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PARAMLISTE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PARTICIP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8DF022990153AF8394AFCF2C09BBA7ECE04B79A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PARTICIP_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PARTPUNCTE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CAB1CC11C83582187463B2B2B15EF5CD04B711E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PARTPUNCTE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PARTTOT_CODPARTTOT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DDB3CEFA2C8ABAE25D873735D32E06846380E6C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PARTTOT_CODPARTTOT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCALCUL_CODPC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8530D954986F0C8B3D41E7DAB0F709BACA92E85</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCALCUL_CODPC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCART_CODPCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15ED2FA3A0734224594F9471FC9E94402469CE19</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCART_CODPCART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCDIR_CODPCDIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA585834DE25906D6AB522700FDC1565C7E04A12</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCDIR_CODPCDIR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCDISTRIB_CODPCDISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAAEDE00373216164FD094EE1E5A071A1369CC0A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCDISTRIB_CODPCDISTRIB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCFIRMA_CODPCFIRMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C695789A26C3FBB41F8A3EA6882F7E6A6B5E1A87</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCFIRMA_CODPCFIRMA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCGEST_CODPCGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E96272894FC8185A38BB676771B3593C81974869</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCGEST_CODPCGEST INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PCSECTII_CODPCSECTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>938592BA31B6488C8DCEA66E888ABB07D37C2FEB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PCSECTII_CODPCSECTII INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PERISABIL1_CODPERISABIL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D22604CD3C18855608073A5875D886B0F9B61A86</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PERISABIL1_CODPERISABIL1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PERISABIL2_CODPERISABIL2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27CA5E58E42F5E2B5E1A13AB5933BECBB8FE86FF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PERISABIL2_CODPERISABIL2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PERISABIL_CODPERISABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7AF806863D3FAC65F01DAE3790443282DA5F6D5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PERISABIL_CODPERISABIL INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PGS1_CODPGS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9826567A9F1BC1D2932BC3C9712FA62C4C057736</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PGS1_CODPGS1 INCREMENT BY 1 NOCACHE START WITH 114</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PGS_CODPGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5674DA5A50C86736926C1588CE925F072B7EFEE0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PGS_CODPGS INCREMENT BY 1 NOCACHE START WITH 109</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLANCURS1_CODPLANCURS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71EB76719D65EBB13501463C78DD51819929DB7D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLANCURS1_CODPLANCURS1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLANCURS_CODPLANCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>80A4E93C804B6C7B13E1B531CEFD81BE4852BACB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLANCURS_CODPLANCURS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLANIFNOD_CODPLANIFNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00FABF31470B118D7B3D99E1B77828441A9B6131</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLANIFNOD_CODPLANIFNOD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLANIFPROD1_CODPLANIFPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1D8130822449D103D7FD31B2B1469FAC212CA75</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLANIFPROD1_CODPLANIFPROD1 INCREMENT BY 1 NOCACHE START WITH 429</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLANIFPROD_CODPLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>817763424203A8D2DEBC083203BC089AB5FF2071</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLANIFPROD_CODPLANIFPROD INCREMENT BY 1 NOCACHE START WITH 329</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLATI1_CODPLATA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>710C615DF91CC952DCA1F515DF0268EE4BC563D2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLATI1_CODPLATA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLATI2_CODPLATA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE0DFFE65BD6806CD52035BB83BCB20894D89FCC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLATI2_CODPLATA2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLATI_CODPLATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08A2EAAAB5F48EB6FC1726F5256A63D3732BC53A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLATI_CODPLATA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PLUCASE_CODPLUCASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>86248E525DFCDD754746AFAB19CB3282AE8361DE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PLUCASE_CODPLUCASE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PMPLUNA_CODPMPLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AA304B602F013EE847B118C340D784683076D46</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PMPLUNA_CODPMPLUNA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PMP_ALL_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62F1A5433AA0D387AB0AD15BDEBF9395AA013BD2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PMP_ALL_LUNA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_POSBANCAR_CODPOSBANCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9303C61B4477FAE3105D4C764403839A15CDF8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_POSBANCAR_CODPOSBANCAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_POSTRETAIL_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB6DC5F3F550F52BC1FF28FF76AF77B3E0593931</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_POSTRETAIL_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRECOMANDA1_CODPRECOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC04EBDC204D5CB51295431A779EFB4BA77732F8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRECOMANDA1_CODPRECOMANDA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRECOMANDA_CODPRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9850D4C032E99BFCFEB7C1522060802938E6B24B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRECOMANDA_CODPRECOMANDA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PREDARIPLUS_IDINREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>819AC877862C740AD5F65DCF53C39B88C619FDEC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PREDARIPLUS_IDINREG INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRELPRET_RETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>791DECFA9781473595CAEC8BC6DC16BE0B58E5B3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRELPRET_RETAIL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRESTATII_CODPRESTATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04B1BC52AE6A10F7F37D43270C1579FE20AC93B3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRESTATII_CODPRESTATIE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRETMAMB_CODPRETMAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99467F8C6E2E47C308EA243BD0E5D9F770D4E54A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRETMAMB_CODPRETMAMB INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRETM_CODPRETM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A0AF714E69955C8E2500097161A192E3810F9A3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRETM_CODPRETM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRIORITATEGANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FD8586B746EE89D8336F31AB1D0F0B69C28128D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRIORITATEGANTT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROCACTDATE1_CODPROCACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C4EBE088CF37C8C596E540E4DCF74871F5AEB9AF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROCACTDATE1_CODPROCACT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROCACTDATE_CODPROCACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94954E8F2A2A018BBE85FAEB54E1C80A9791BBF9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROCACTDATE_CODPROCACT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROCACTDEF_CODPROCDEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>758E3BEB36C810878B32829BD1F4AE7D2C52EF4D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROCACTDEF_CODPROCDEF INCREMENT BY 1 NOCACHE START WITH 105</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODCOMP_CODPRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>005B9FBCC32A0061AA8A441A09B9BB0863C345D7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODCOMP_CODPRODCOMP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODGEST_CODPRODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D10018F229D04BE15D638C8B5D4F0BA8CB739C6A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODGEST_CODPRODGEST INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODMAN_CODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D1E739606371F5C4F8036ED7FE74BC4D5154154</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODMAN_CODMAN INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODMAS_CODPRODMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C23DC8830DB053DEA749C6D5C9E7927D9D3FB31C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODMAS_CODPRODMAS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODMATECHIV_CODMATECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CC765CE4E1899ABDF22BABC832DD59104C1FD1D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODMATECHIV_CODMATECHIV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODMAT_CODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF0E02B5360486950468360ED2745CBD9EC5227C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODMAT_CODMAT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODNET1_CODPRODNET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>331DF3738EF566BBC7603D5CC59D95AD77E7184C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODNET1_CODPRODNET1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODNET_CODPRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74FEDD954B5BCC3728C72A93FEA72B51208D9567</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODNET_CODPRODNET INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODNORME_CODNORMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C4B731060D5A3AF6CD869F2C60E7B8B7D3569CE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODNORME_CODNORMA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODREZ_CODREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B20063FB18CA4A85FBB221EA318D7ACB6114A943</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODREZ_CODREZ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PRODSDV_CODPRODSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EFDAA7D806D11254EDE7BC32EA276F86490A4A80</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PRODSDV_CODPRODSDV INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROGRAMF1_CODPROGRAMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0F92ED7B0C34F23F7C771DA071D1C6E0F8A7500</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROGRAMF1_CODPROGRAMF1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROGRAMFLMC_CODLMC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1574A648D3F30B36B1119C6FE58F59A9DBF078EC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROGRAMFLMC_CODLMC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROGRAMFMAN_CODPROGRAMFMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E670B530345D2AB34DECF68E0FA431D1DB388575</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROGRAMFMAN_CODPROGRAMFMAN INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROGRAMFSDV_CODPROGRAMFSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C77F63D4A12A088B8C801370BABB57CEEA129DD3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROGRAMFSDV_CODPROGRAMFSDV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROGRAMF_CODPROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BAAB83116706E3EDFD60AEC240FC3A7F4C051F0D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROGRAMF_CODPROGRAMF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROIECTCRM_CODPROIECTCRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6ABF61C0C4D2730176F8159DA336220A1758B580</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROIECTCRM_CODPROIECTCRM INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROIECTNOD_CODPROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF1495CB659F813EAABD0B7AAF6190138A3BA061</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROIECTNOD_CODPROIECTNOD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROIECT_CODPROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>527B2F9D61A9EC2B7B91D31D9EDB7F97D7125AC4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROIECT_CODPROIECT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMO1CADOUSER_CODCADOUS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A360E0873A49AD9B8D211B5F282B3DA0CD8C156F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMO1CADOUSER_CODCADOUS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMO1CADOU_CODCADOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A799D11D830D1F9F4C8C6BC0D19A2B2D085E0B3C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMO1CADOU_CODCADOU INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMO1SER_CODPROMO1S</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84AB8317C655C6FF077925682EFB567D917FD5C5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMO1SER_CODPROMO1S INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMO1_CODPROMO1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A31F25A436212EAF97FAE6323B7758905100DE16</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMO1_CODPROMO1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMOPART_CODPROMOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7469E3D282796ED663F520846E5043C4F4FE66F1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMOPART_CODPROMOPART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMOPRAG_CODPRAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A03472729E308B1C8EC9C1C3A8E890A60CD70D1E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMOPRAG_CODPRAG INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMOSUB_CODPROMOSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0C25664D5359157E925B1B9F422DA4A1BF44D44</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMOSUB_CODPROMOSUB INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PROMO_CODPROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF22FDA5054E41BA210F75F37E58BA5FFB6357AE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PROMO_CODPROMO INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PUNCTAJE_CODPUNCTAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A30482977B4FA114B8CD62D58AF5DAD1C4637D3F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PUNCTAJE_CODPUNCTAJ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PUNCTAJVALDOC_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5AE50F6CF84E1DE305B80F015202BD8FCD3A959</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PUNCTAJVALDOC_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_PUNCTEUSE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FBDE6DEC8EF57004A4456C06436C35534040003</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_PUNCTEUSE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_CATP1_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1999C6E04A83680A877D7D4760FF1A9E04DDF6BD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_CATP1_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_CATP2_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E99DF52A411591ACAC4B4195DD9D8F5FA9C5981</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_CATP2_COD INCREMENT BY 1 NOCACHE START WITH 131</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_CATP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E08B08251FDFCA68D04A10E72DBCD7EB93F7D1CC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_CATP_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_P0_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD848F01EE8EE882AA64BAF8771286815BE6CF3F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_P0_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_P1_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E87FCBE09BAD75CD8BB0C2BC3D77CBD60759707F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_P1_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_P_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E25197C3E69C31FB8C1ABDB131265EC890B4EDE9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_P_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_REZP_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2BC24FB32B6A895A0677B1F6C1B5E719060BA97</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_REZP_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_REZS_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4AFAC8FA0E3A03EE81D6087DA581761C2EB556A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_REZS_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAC_REZ_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF89253CCA622B5F29C45DAA0495BDF940BFA01B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAC_REZ_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPORTP0_CODRAPORTP0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F47BAF528DF7CA45D2907CD455E5EBDE0584E53</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPORTP0_CODRAPORTP0 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPORTP1_CODRAPORTP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D50125BAF5D05DB75D5323535B318AA424BF716</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPORTP1_CODRAPORTP1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPORTP2_CODRAPORTP2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EC7BC9C694970C7A22EEB5AE20CD0FB65B166F1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPORTP2_CODRAPORTP2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPORTP3_CODRAPORTP3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5582648346B1DDE65319EADECF4AC699C31264E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPORTP3_CODRAPORTP3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPORTP_CODRAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C0E6D87908019B035D11EBEDAA5BF83B2866C19</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPORTP_CODRAPORTP INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RAPSTOCMEDIST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>830170EC986485F072901C6A87AAEBD7BBA739FF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RAPSTOCMEDIST INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RECLAMATII1_CODRECLAMATIE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7E9E6B91A5E7EFCA8D66567CD0E1C7BC33080F5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RECLAMATII1_CODRECLAMATIE1 INCREMENT BY 1 NOCACHE START WITH 114</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RECLAMATII2_CODRECLAMATIE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7754DEF58EC8157CE05241E15316AEEBE676F415</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RECLAMATII2_CODRECLAMATIE2 INCREMENT BY 1 NOCACHE START WITH 262</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RECLAMATII_CODRECLAMATIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6D28FA1A616011148F121540607E78CFE276AAA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RECLAMATII_CODRECLAMATIE INCREMENT BY 1 NOCACHE START WITH 114</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REG1_CODREG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECB8E95C974D073470CB24A05AF50C49E26E8B8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REG1_CODREG1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REGOSS1_CODREGOSS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B70B75ECD1A05EE8F74FC2E4669DFC4DF9953912</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REGOSS1_CODREGOSS1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REGOSS_CODREGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40B23FACD0617564F6C50E9479DEA0623613A09D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REGOSS_CODREGOSS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REGPERS1_CODREGPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>379CA67355AC177CB9BBE8E5DA89D6BF67556669</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REGPERS1_CODREGPERS1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REGTREZOR1_CODREGTREZOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>386D6F5AF64B91022D96D43694C233D6F315CA9D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REGTREZOR1_CODREGTREZOR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REG_CODREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AB41A00B4994114357AC291426A5BDA52F654C4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REG_CODREG INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTARTINACTIVE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2BC038510422B10C25A0AEC3CF1665918A6AF18</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTARTINACTIVE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTAURANTE_CODRESTAURANT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2973040A9785584C1F3F150E8E5FE4E23026BA61</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTAURANTE_CODRESTAURANT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTCLASE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC65DBB9CDBF5A5E763A137641076C22239E9A3F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTCLASE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTCMD1_CODRESTCMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47B21DD6EE20EB0A12ECEFBCD6B6D6C2C402A94C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTCMD1_CODRESTCMD1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTCMD_CODRESTCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97ABC7D3C5DAC2BAB0895BC6976CB87110F42EA1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTCMD_CODRESTCMD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTGESTIMPLICITE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>928D857D76F8B145509885E917BF78B4F4B74519</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTGESTIMPLICITE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTGESTLISTVER_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB2FB2AC88D2CEF7FA65AE2B8C3B9B9FF8079681</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTGESTLISTVER_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTLISTGEST_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>936C3D7F264BD843ADFD477874304EF7EF837DF9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTLISTGEST_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTNP1_CODRESTNP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>897C7E296E2A33565F00109FAE5F218E609D1772</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTNP1_CODRESTNP1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTNP2_CODRESTNP2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FD8466EC192DBCC4BF01F9F548BB53AE6291238</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTNP2_CODRESTNP2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTNP_CODRESTNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6DD8C7926DA7B921DD23E7B2E0D4A3F7CCE03A47</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTNP_CODRESTNP INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTOBIECTE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D1449EFE01D88DBED37A5655CECB99478BCED1A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTOBIECTE_COD INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTOBSART_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3BAF97C8B15528AEEC1E7373393356BC74D3B79</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTOBSART_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RESTRAPORTZ_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49C768B8830F93723D8916009F9E8A08E54FD5DC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RESTRAPORTZ_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RETUROSTINS_CODRETUROSTINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0DA8917BA51F6DF630A3C6027249A9D2C4E2C142</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RETUROSTINS_CODRETUROSTINS INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_RETURO_CODRETURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D523384872885595C978212D785EBDC416F25F1F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_RETURO_CODRETURO INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_REZERVATS_CODREZERVATS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>061341E8267B09F09C38AF2A780DD0AE47148803</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_REZERVATS_CODREZERVATS INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SABLONDESCRIPT1_CODSABLON1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EFA895ED7D369EEEAF942C0F22E9C1432C64B44</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SABLONDESCRIPT1_CODSABLON1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SABLONDESCRIPT_CODSABLON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FA06D3D8393510388296514FE3FA827EB2B3026</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SABLONDESCRIPT_CODSABLON INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAFT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D471C8D5E04AE04F2DC042CF8247007368A2DF45</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAFT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAFT_TI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C2C6587E78FA4D2BE9E9DC719E398B715B387CF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAFT_TI INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SALIUSERI_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5090DFDB935044E1997AC7CECBF4AAB536644C2E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SALIUSERI_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SALI_CODSALA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA09C1BE353B573397EA60EC453461D7B0540CFB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SALI_CODSALA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_CATRET_CODCATRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEC31A01D55C17ECE3F170346EC2DA42507AD792</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_CATRET_CODCATRET INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_CATSPOR_CODCATSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D9CE7966EFDA08DD966C82C76154A4525B6AD95</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_CATSPOR_CODCATSPOR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_CONTRPP1_CODCONTRPP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC1D1BDBC66BC0186F79FB4D3985DE2FE06E2134</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_CONTRPP1_CODCONTRPP1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_CONTRPP_CODCONTRPP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3018B2E3E610C2597C9B4CF19B5FE6F1D738027</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_CONTRPP_CODCONTRPP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_DEDGEN0_CODDEDGEN0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB65A1A184323CDDA7E5DFC88771EA39E9004DA2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_DEDGEN0_CODDEDGEN0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_DEDGEN1_CODDEDGEN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3158B50F7B3A149A33548614B424AC00EFA00E87</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_DEDGEN1_CODDEDGEN1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_DEDGEN_CODDEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F85910975A77FEC9F2C494455CD435E41B51EB7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_DEDGEN_CODDEDGEN INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_FONDP_CODFONDP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2E13717F3EA856576C2359CC5ACFDDE429C605B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_FONDP_CODFONDP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_IMPOZ0_CODIMPOZ0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0658678B2A38B5AAD2B1CC302230FCCFBC4BD488</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_IMPOZ0_CODIMPOZ0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_IMPOZ1_CODIMPOZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC78B1C93FD7EB62D8420EFCD385A9808008CAF3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_IMPOZ1_CODIMPOZ1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_IMPOZ_CODIMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>462CC7081A0C3F66F7949DD566BD2DB2845F94A8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_IMPOZ_CODIMPOZ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NASIG0_CODNASIG0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBC10C219974B2E5FE1F5367BFA6AC39E110CC2C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NASIG0_CODNASIG0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NASIG1_CODNASIG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8897340D850417F345BB5A5371BD663C3584FCA9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NASIG1_CODNASIG1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NASIG2_CODNASIG2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F4F4875BFBE5B4C23E48E4B4A1C3B5C406B38C3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NASIG2_CODNASIG2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NASIG3_CODNASIG3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75693A1F563C2589D96ACC1C8F4F20EE52F9AAEA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NASIG3_CODNASIG3 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NASIG_CODNASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9148288C0747D62B1837FD00A529574C43E9D0D7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NASIG_CODNASIG INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NCONTRIB1_CODNCONTRIB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0675F25DD67FBE8C863C7EC66C50B8F03A655CD5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NCONTRIB1_CODNCONTRIB1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NCONTRIB_CODNCONTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92828EC2E0C636C567006E6A5BFB71C9A7EF3DFA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NCONTRIB_CODNCONTRIB INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NDREP0_CODNDREP0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E82B50E05727CAB77EE8D27F51CB608F62DA3C30</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NDREP0_CODNDREP0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NDREP1_CODNDREP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE9412456C025C8F571B616B50194C3B83036395</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NDREP1_CODNDREP1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_NDREP_CODNDREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E2CA2E7275B70B4634DEF7DB5C2EEB5A5CB8AD4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_NDREP_CODNDREP INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_RETINERI0_CODRETINERE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EC1749EE8FB09FB1F437C348115B54D48E15B69</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_RETINERI0_CODRETINERE0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_RETINERI_CODRETINERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DDFEEAD47507DD2F4A40BDE4D165E938002E6CB9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_RETINERI_CODRETINERE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_SPORURI0_CODSPOR0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FD6E3E4CEAA356AE50855B72B9B0A94FE4E91B1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_SPORURI0_CODSPOR0 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_SPORURI1_CODSPOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D608D90CF17CED200052A2E96DE86EFDFCCB00EB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_SPORURI1_CODSPOR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_SPORURI2_CODSPOR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D330DBA447B9547CAB7FCF0FFC21DD6266EAC82</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_SPORURI2_CODSPOR2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SAL_SPORURI_CODSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4374D07B6E8E2226FAF23FCD05435434A804C9ED</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SAL_SPORURI_CODSPOR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SCENARIILIVR1_CODSCENARIU1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDE21EAEB10CB3B64F4E1253A748E1A26DF1756B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SCENARIILIVR1_CODSCENARIU1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SCENARIILIVR2_CODSCENARIU2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13EE815E4243BDCDB82A5D3A49B4EF079876CF39</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SCENARIILIVR2_CODSCENARIU2 INCREMENT BY 1 NOCACHE START WITH 109</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SCENARIILIVR_CODSCENARIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB80BD6368A3832AFB959EC3C1EA6F7DB52C4A49</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SCENARIILIVR_CODSCENARIU INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERIE_UNICA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D893DB272F3379C726C6467A281FCE1315440E9B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERIE_UNICA INCREMENT BY 1 NOCACHE START WITH 249</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERIICMD_CODSERIECMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97BCA4EE7AFFB5E4FA2DC9B6E592DFDB954FEB39</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERIICMD_CODSERIECMD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERIIIES_CODSERIEIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B29A85B38B161EFA7CA08ECB6D49CB927C9E038</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERIIIES_CODSERIEIES INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERIIINTR_CODSERIEINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1663D4274BB6E73E602180EA88867C4F8D5DF286</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERIIINTR_CODSERIEINTR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERIITRANSF_CODSERIETRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1606270F4E1CE1425B132A8FC43560A3D9C0411F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERIITRANSF_CODSERIETRANSF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERVFACT1_CODSERVFACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DE603348F7F966A40DE428C89B5D44FE30260FD6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERVFACT1_CODSERVFACT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERVFACT_CODSERVFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FA47F13754AFA789DDF495EDA6605A4D39C51CC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERVFACT_CODSERVFACT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SERVPOST_CODSERVICIU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F4E4155C0DBDE0C7DAA42AC56DE1D38D4224E67</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SERVPOST_CODSERVICIU INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SETTASKLOG_CODLOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A60F1A73A4F92D8EA7784DF55193EA7CCC812FB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SETTASKLOG_CODLOG INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SETTASKOBJ_CODTASKOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B84BD755B57AC31FEC2AEDE8F5F352975DD3527</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SETTASKOBJ_CODTASKOBJ INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SETTASK_CODTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>104A555D28D5047D6D03B4AD7D498B03AD940BDD</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SETTASK_CODTASK INCREMENT BY 1 NOCACHE START WITH 320</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SGRCOLECT1_CODSGRCOLECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81FB1BB0485774B87BD4AB8E8A81C3CFD0A541D8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SGRCOLECT1_CODSGRCOLECT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SGRCOLECT_CODSGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0746F92B347D7AC0753D9C540BB127AD70201FBB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SGRCOLECT_CODSGRCOLECT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SINTEZAEMUL1_CODSINTEZA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5C8A53515ED4AC03A0E0B3D72B98FAD53B9F92D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SINTEZAEMUL1_CODSINTEZA1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SINTEZAEMUL2_CODSINTEZA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CED242672B04825E4A928DFCFBE7F8553261356</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SINTEZAEMUL2_CODSINTEZA2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SINTEZAEMULARE_CODSINTEZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F55B720894100B8C32A809907769F5CA39A6505</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SINTEZAEMULARE_CODSINTEZA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SITFINALTE_CODALTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6780B70D5EFE08BC90F6ADE3089580D0463C0D21</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SITFINALTE_CODALTE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SITFINBUGET_CODSITFINBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D24E6A3F2DBB07FABAA8A7EE728A8BF28932AA5D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SITFINBUGET_CODSITFINBUGET INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SITFINCOL_CODCOLOANA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>936C41C9322ED81BA1ED4EF8EB4579261EF87043</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SITFINCOL_CODCOLOANA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SITFINLIN_CODLINIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16C5F62344273557CEF9D89F1A7F2B9BDFDA677A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SITFINLIN_CODLINIE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SITFIN_CODSITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3177AD79BF3AB4D83471D685948E536352E56F38</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SITFIN_CODSITFIN INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SMSURI_CODSMS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2BBBB66D35B874CAD13941A36A00F5AA65522AB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SMSURI_CODSMS INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SOLDCASHFLOW_CODSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DE07A23EA8D581CA77CDC9EC8CA7788B5BB362D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SOLDCASHFLOW_CODSOLD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SOLDINI_CODSOLDINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC11E1FEEC661EF2FD2E595E1411C1A28AD5B7CE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SOLDINI_CODSOLDINI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SOLDPART_CODSOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41AC47F1950D0C4D4FA2F4A7C1FDEE9A97D46A8E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SOLDPART_CODSOLDPART INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SOLDPERSINI_CODSOLDPERSINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36BC5FF8BC05876666BBD341BFFFA563A770007B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SOLDPERSINI_CODSOLDPERSINI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SPLITCHELT1_CODSPLITCHELT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>718C9B76BE12173CF30289C8F4120DFAA856BA82</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SPLITCHELT1_CODSPLITCHELT1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SPLITCHELT_CODSPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CD4EB336749A0468FC45B10BFBD53124B26172C</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SPLITCHELT_CODSPLITCHELT INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SPVARHIVA_CODSPVARHIVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC402998DBE612A08DCE85D3CFF54F1F313AE1B7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SPVARHIVA_CODSPVARHIVA INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STAREESTIMARI1_CODSTARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>395FB91E168BE5F870C0E6D0A2E94E3E61375B57</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STAREESTIMARI1_CODSTARE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STAREESTIMARI2_CODSTARE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43AD8969A5F25C5133DD879143787A694EF65835</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STAREESTIMARI2_CODSTARE2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STAREESTIMARI_CODSTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FD36308C090DDA49506219FEA987E2C25676EC2</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STAREESTIMARI_CODSTARE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STATCON_CODSTATCON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F6B1FA2A95764D0E22F4F0E59F4DC12575A6E0B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STATCON_CODSTATCON INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STATCOR1_CODSTATCOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B2239223726D537069C20BB031C4C7D815AB0E6</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STATCOR1_CODSTATCOR1 INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STATCOR_CODSTATCOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>649468DB5F5BA334BF551283F663EBDAC5587CDF</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STATCOR_CODSTATCOR INCREMENT BY 1 NOCACHE START WITH 103</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STATUSDECL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4F9DAF78A873F658B7749E1205F67716E9090B4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STATUSDECL INCREMENT BY 1 NOCACHE START WITH 166</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STINGERE_CODSTINGERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED6B099BCF85D3483496975CDAEA84B57EA3A68A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STINGERE_CODSTINGERE INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOBJASOC_CODSTOBJASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63BBAD8786E50B60BE8608F3D68168B941A1A504</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOBJASOC_CODSTOBJASOC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCFAKE1_CODSTOCFAKE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DB0838707DCFFAFE60E661F3828CA0948C65748</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCFAKE1_CODSTOCFAKE1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCFAKE_CODSTOCFAKE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A09D19919A34679AB9F6A086F20255C8EE44309</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCFAKE_CODSTOCFAKE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCINI_CODSTOCINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06532F26212260D929F55C5E1D649274E0554763</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCINI_CODSTOCINI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCPOSURI_CODSTOCPOSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B8CD98D6C3E2609C4BF1A44D1E46F50EA7CA013</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCPOSURI_CODSTOCPOSURI INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCVALINI_CODSTOCVALINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C042A8D34ABA816F829027ECFB66F44850E6138</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCVALINI_CODSTOCVALINI INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STOCVALLUNA_CODSTOCVALLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F836E48B11C3671A0D0AF79E12CDDC2EE2CE8AA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STOCVALLUNA_CODSTOCVALLUNA INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_STORNOCMDF_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2366D188D36E89DACB5209942753EECA438BB059</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_STORNOCMDF_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SYNCPARTRETAIL_CODSYNCPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>333126CBEB5DD088BA9212FC8737B8D096FD91D5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SYNCPARTRETAIL_CODSYNCPART INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SYNCPROMORETAIL_CODSYNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE83529FAF1D1C1E481DBDB33DF412B4E3336CF9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SYNCPROMORETAIL_CODSYNC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_SYSNPRETRETAIL_CODSYNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FCB9637B281B2CB32B5F3E6FB05BFA85735F5ED5</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_SYSNPRETRETAIL_CODSYNC INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TARGETAG1_CODTARGETAG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE3245A9204C5C16DDC857EFF813AE335A314C9D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TARGETAG1_CODTARGETAG1 INCREMENT BY 1 NOCACHE START WITH 123</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TARGETAG_CODTARGETAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8B9F988E59408FF57CC9C59348372C8E9D8C5EA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TARGETAG_CODTARGETAG INCREMENT BY 1 NOCACHE START WITH 123</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TARIFEMAN1_CODTARIF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75FE79918C81A46C4957032A39D03DA7C6215400</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TARIFEMAN1_CODTARIF1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TARIFEMAN_CODTARIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F29136EB381A8E9B51A3CE98B996BFE264E6194</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TARIFEMAN_CODTARIF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TARIFEMASTER_CODTARIFM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>131D2F4C70E1E647154C9DF45C19B01055429BD3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TARIFEMASTER_CODTARIFM INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TAXDECL_CODTAXDECL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EDB0D097D258370AE6155A6294C08ACE745EB8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TAXDECL_CODTAXDECL INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TEME_CODTEMA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>986AE425E2AD73043AE29D4888170622A381C491</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TEME_CODTEMA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TERMENECMD_CODTERMEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBEADFCC046ED68BEF562EB2DEFE18681C16DDF4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TERMENECMD_CODTERMEN INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TESATURI_CODTESATURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACCF98203F316EB4A81CA0D83327A01D2BAAFDA0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TESATURI_CODTESATURA INCREMENT BY 1 NOCACHE START WITH 143</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPCHELT_CODTIPCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AE6A16FD5144C80A199FF5910C8982DFB19EF88</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPCHELT_CODTIPCHELT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPLUCRARISA1_CODTIPLUCR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23B199B2583237C53918330B00136D7737654C63</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPLUCRARISA1_CODTIPLUCR1 INCREMENT BY 1 NOCACHE START WITH 130</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPLUCRARISA_CODTIPLUCRARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>360B59F089338EE48518094EE85470C76EE80E8E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPLUCRARISA_CODTIPLUCRARE INCREMENT BY 1 NOCACHE START WITH 104</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPPARTINCERT_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBD397D00D0EBC839B87C81CDE506A003E64D6DB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPPARTINCERT_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPSEDII1_CODTIPSEDIU1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EDE18178363305D7970F375216667099C971DC1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPSEDII1_CODTIPSEDIU1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TIPURIPLATI_CODTIPPLATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99E7DD2A32B95709C0B80009841049AD8348E291</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TIPURIPLATI_CODTIPPLATA INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TMP_PLUNA_CODPLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAB52D971330D35BFB583BD13679D61A92ABCA1F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TMP_PLUNA_CODPLUNA INCREMENT BY 1 NOCACHE START WITH 2381</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TOTALPUNCTE_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>715849CC4BCEB53BBC52E8054095897AEE40C5B4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TOTALPUNCTE_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TOWORD_CODTOWORD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>512FF895D1F255349921A9B8CEFB401AABFF63E3</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TOWORD_CODTOWORD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSACARD_CODTRANSACARD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CFC01530EBDE8DE521EF460253EA960C77188C1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSACARD_CODTRANSACARD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSF1_CODTRANSF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2DBAE036348EE6BA88E3B198004C59D46336752</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSF1_CODTRANSF1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSF_CODTRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CDF62BC81523699DF89A1AEEC6D6354BC82401D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSF_CODTRANSF INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSPORT1_CODTRANSPORT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7EFA0A812CFBA5767676EEC27F997BE884BCCD0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSPORT1_CODTRANSPORT1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSPORT2_CODTRANSPORT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E1F2758897D0E109114C467D7294BC56F5C2024</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSPORT2_CODTRANSPORT2 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRANSPORT_CODTRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46E8656F254493AE995ACA26D80617BDA7C0FB92</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRANSPORT_CODTRANSPORT INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRASEULIVR_CODTRASEULIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F09E622DF379000E7046E5E68B04B265A86C55BE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRASEULIVR_CODTRASEULIVR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRASEU_CODTRASEU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21E0982E6E74B8CF4F353594D6440575D1E7D16A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRASEU_CODTRASEU INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TREZOR1_CODTREZOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44A09A5003805248D31788F881BD2836BC2E1EB9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TREZOR1_CODTREZOR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TREZOR_CODTREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35B1B1D4241F55D2EC748FF0BEF0CD3F18DF1629</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TREZOR_CODTREZOR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRIGAR1_CODTRIGAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E81F30AB16062C63ACDCF902AAA256B1FCF5260</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRIGAR1_CODTRIGAR1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRIGAR_CODTRIGAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32CC41A5705AA2870C80D716D82C8808FA8CA5FA</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRIGAR_CODTRIGAR INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TRIGAR_MODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1840ACBCE679BE13F433F44A706AEA8964C2E19F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TRIGAR_MODIF INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TVADISC_CODTVADISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2C15FFE7D875F80B9B505E7A4F2C4EE6C30A237</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TVADISC_CODTVADISC INCREMENT BY 1 NOCACHE START WITH 100</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TVAMONETAR_CODTVAMONETAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FFE5F840AECACA8741E1FFF9AE023DBDDD6B06E</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TVAMONETAR_CODTVAMONETAR INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TVASERV1_CODTVASERV1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40C15F01C143F5B0B3721AAF4DFD292D3CD77F48</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TVASERV1_CODTVASERV1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_TVASERV_CODTVASERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42D25552662E8EBAE603AC37F9381EAB1F39C15A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_TVASERV_CODTVASERV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_USERSQL1_CODSQL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>749EE2505AA5EDE1043AE7DF914F476041411036</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_USERSQL1_CODSQL1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_USERSQL2_CODSQL2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>257C17C05D904B36C5FCD15701DED41C7A3DA234</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_USERSQL2_CODSQL2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_USERSQL_CODSQL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49622BE78AFEC1755808E903E4C2B7AF1E69E417</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_USERSQL_CODSQL INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_USER_LISTS_LISTID</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7114099F01FE52DC35FDA6C9D799036599F4EDC</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_USER_LISTS_LISTID INCREMENT BY 1 NOCACHE START WITH 10001</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE1_CODUTILAJ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA7F79406E18C2655421D709BF1E0EA547E1E92A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE1_CODUTILAJ1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE20_CODUTILAJ20</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E281E28E9F274256F4E9C8CCB8A1ECA7592BB92D</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE20_CODUTILAJ20 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE2C_CODUTILAJ2C</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF25A8D0A15477259D0A4AEBCD35E5D682453790</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE2C_CODUTILAJ2C INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE2P_CODUTILAJ2P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>891179F88B21222108892E858ADE6893F513FD9A</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE2P_CODUTILAJ2P INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE2_CODUTILAJ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9F6CD71CF18C98AB8222364108489307F171771</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE2_CODUTILAJ2 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE3_CODUTILAJ3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>323AF1D330978579BDC816E6B17414F69E91F6D8</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE3_CODUTILAJ3 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJEDEV_CODUTILAJDEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11FE4C2D90AFD3C8BA52E2DEEEB80B325C832179</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJEDEV_CODUTILAJDEV INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJEMON_CODMONITORIZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8506C3589E12C78FA941F4C916C17F4D94C7077</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJEMON_CODMONITORIZARE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJETIPINDEX_CODTINDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>106A8A599AE97A6AD60A2A6B5B1C57A406C6D0B7</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJETIPINDEX_CODTINDEX INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_UTILAJE_CODUTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C93A7D22CDF0A3E34650927D175B977611E35781</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_UTILAJE_CODUTILAJ INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VALATREXCEPTII_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2D40514E29BF3675B4EBFC3AD63C639907DE860</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VALATREXCEPTII_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VANZARI_CODVANZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6954BFB58FD2634FB3B0107927D47926AE9A83A4</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VANZARI_CODVANZARE INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VIEW_JOINS_CODVIEW_JOINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18C1AA575E97FAFD55447787F33AD87605CE92FB</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VIEW_JOINS_CODVIEW_JOINS INCREMENT BY 1 NOCACHE START WITH 118</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VOUCHERCADOULINK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44FA732B951459E7A14CD600E9A41AFDF39E2F38</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VOUCHERCADOULINK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VOUCHERCADOU_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF0C5D4A8F8C7E5372957A1EE07282C5EB5B1174</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VOUCHERCADOU_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VOUCHERLINK_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EFE531338CC421D62FC7BCA82273AAE71E2347B</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VOUCHERLINK_COD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_VOUCHER_CODVOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08E16B941997A806C5AE9418393E189C99AB08D1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_VOUCHER_CODVOUCHER INCREMENT BY 1 NOCACHE START WITH 113</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_WEEKCASHFLOW1_CODCASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87E8D373AF8417561A7EE11F7D3CCBBD49ACA7D9</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_WEEKCASHFLOW1_CODCASHFLOW1 INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_WEEKCASHFLOW_CODCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AFBBAEB9556253EAAA987E3F9D41B0C617472B0</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_WEEKCASHFLOW_CODCASHFLOW INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_WEEKCASHPLATI_CODCASHPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BD28AE1C46AF234120D42845C43676CC3EF8D8F</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_WEEKCASHPLATI_CODCASHPLATI INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_WEEKCASHSOLD_CODSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F7C32512BAD123E43BD91E2482B89E00320CA03</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_WEEKCASHSOLD_CODSOLD INCREMENT BY 1 NOCACHE START WITH 101</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ZEURO_COD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>881ECDD12FECC0D1ADF36DC6E8266580B0972F96</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ZEURO_COD INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ZINELUC1_CODZINELUC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A896217983748EECF118C5FC2FBBF48A6F1119AE</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ZINELUC1_CODZINELUC1 INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>SEQUENCE</TYPE>
  <NAME>SEQ_ZINELUC_CODZINELUC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5ACBABB52666D0DD858F706931F074750CA0CA1</HASHVAL>
  <TEXT>CREATE SEQUENCE SEQ_ZINELUC_CODZINELUC INCREMENT BY 1 NOCACHE START WITH 102</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ADAOSM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DA43E7FCD8235362F0131BFA7B320C8E10063D7</HASHVAL>
  <TEXT>CREATE TABLE ADAOSM (
  CODADAOSM NUMBER(20,0) NOT NULL,
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ADAOSM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DEE0CF64BEE1CE9A1C69D35A45A326F998994E5</HASHVAL>
  <TEXT>CREATE TABLE ADAOSM1 (
  CODADAOSM1 NUMBER(20,0) NOT NULL,
  CODADAOSM NUMBER(20,0),
  LIMSUP NUMBER(20,7),
  COTAADAOST NUMBER(20,7),
  COTAADAOSD NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB96F8A692AB02FCB3F2F035DD3AAB1E9034A917</HASHVAL>
  <TEXT>CREATE TABLE ALERTE (
  CODALERTA NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  TIPALERTA NUMBER(1,0),
  OBS VARCHAR2(200),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODORAR NUMBER(20,0),
  MAILTO VARCHAR2(1000),
  CUSTOMMESSAGE CLOB,
  MAIL_INDIVIDUAL NUMBER(1,0),
  CUSTOMSUBJECT VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  SQL CLOB,
  CODFIRMA NUMBER(20,0),
  CUSTOMFOOTER CLOB,
  FIELDURI VARCHAR2(1000),
  TITLUXLS VARCHAR2(100),
  TIPEXPORT NUMBER(2,0),
  ORDONARE VARCHAR2(200),
  SQLCUSMS NUMBER(1,0),
  JOBID NUMBER(20,0),
  WEBSERVER NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ALERTE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>077CF92F7E4B597635F6838C57B239F9B1E417E7</HASHVAL>
  <TEXT>CREATE TABLE ALERTE0 (
  CODALERTA0 NUMBER(20,0) NOT NULL,
  CODALERTA NUMBER(20,0),
  USERNAME VARCHAR2(50),
  USERID NUMBER(20,0),
  RECIPIENT VARCHAR2(200),
  EMAIL NUMBER(1,0),
  MESS NUMBER(1,0),
  TASK NUMBER(1,0),
  SMS NUMBER(1,0),
  TEL VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ALERTE_DEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA2DE3D0DA564610E5333F9E0A11D538C65514CD</HASHVAL>
  <TEXT>CREATE TABLE ALERTE_DEF (
  CODALERTADEF NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  SQL CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ALERTE_INFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FCC194178F844CFB693D8DDA5B5FD37068033C9</HASHVAL>
  <TEXT>CREATE TABLE ALERTE_INFO (
  CODALERTAINFO NUMBER(20,0),
  CODALERTA NUMBER(20,0),
  DATAEXEC DATE,
  REZULTAT CLOB,
  INFO_FILTRE CLOB,
  CODRULARE NUMBER(20,0),
  MAILTO VARCHAR2(500),
  TASKTO VARCHAR2(100),
  MESSTO VARCHAR2(100),
  SMSTO VARCHAR2(50),
  FILENAME VARCHAR2(50),
  FILEBODY BLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AL_TABLES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69C279BA17980944DC931EDD00F732C04E67707A</HASHVAL>
  <TEXT>CREATE TABLE AL_TABLES (
  TABLE_NAME VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11BA47CF07D92C25B70C135E0DB356719D6A1C69</HASHVAL>
  <TEXT>CREATE TABLE ANALIZA (
  CODANALIZA NUMBER(20,0) NOT NULL,
  DEN_ANALIZA VARCHAR2(100),
  IDELEMENT NUMBER(10,0),
  IDCENTRU NUMBER(10,0),
  INACTIV NUMBER(1,0),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ANALIZA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF5FFE825499F83A53D0F8B8E823F9AD11DC15B9</HASHVAL>
  <TEXT>CREATE TABLE ANALIZA1 (
  CODANALIZA1 NUMBER(20,0) NOT NULL,
  CODANALIZA NUMBER(20,0),
  CODDESCRIPTOR NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ANALIZANOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87FEF867EFE1F1830F38B2B000D149C9D9719662</HASHVAL>
  <TEXT>CREATE TABLE ANALIZANOD (
  CODANALIZANOD NUMBER(20,0) NOT NULL,
  CODANALIZA NUMBER(20,0),
  NODPARINTE NUMBER(20,0),
  CODANALIZA1 NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  POZITIE NUMBER(10,0),
  INACTIV NUMBER(1,0),
  SIMBOLNOD VARCHAR2(100),
  DENNOD VARCHAR2(200),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>APELTELEFON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BB3E504E5AA52FE1A6C61D22CD585DBC360CDC8</HASHVAL>
  <TEXT>CREATE TABLE APELTELEFON (
  CODAPEL NUMBER(20,0) NOT NULL,
  IDAPEL VARCHAR2(20),
  STARE VARCHAR2(20),
  TELEFON VARCHAR2(20),
  APELANT VARCHAR2(100),
  DATAORA TIMESTAMP(6),
  PRELUAT NUMBER(1,0),
  CLIENT VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ASIGURARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F18756FDF550D10949A03FF7B4AE0E552CD51DB</HASHVAL>
  <TEXT>CREATE TABLE ASIGURARI (
  CODASIGURARE NUMBER(20,0) NOT NULL,
  NRDOC VARCHAR2(50),
  CODPART NUMBER(20,0),
  DATASTART DATE,
  TERMEN DATE,
  CODCLASEMF NUMBER(20,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ASIGURARI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5A8475023352140C6B48E1EAF429EE671BA07D6</HASHVAL>
  <TEXT>CREATE TABLE ASIGURARI1 (
  CODASIGURARE1 NUMBER(20,0) NOT NULL,
  CODASIGURARE NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODMIFIX NUMBER(20,0),
  VALASIG NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AVARIECAROSERIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06833DE6CAF5FE8BAF57DA9317F3195824E370BD</HASHVAL>
  <TEXT>CREATE TABLE AVARIECAROSERIE (
  CODAVARIE NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(10,0),
  DEFECT NUMBER(1,0),
  CAND NUMBER(1,0),
  X NUMBER(5,0),
  Y NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AVIZCANTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A3A93E42915BC67946ACBF6D971F197CA288206</HASHVAL>
  <TEXT>CREATE TABLE AVIZCANTLOCK (
  CODLINIEAVIZ NUMBER(20,0),
  CODLINIEFACT NUMBER(20,0),
  TIPAVIZ NUMBER(2,0),
  CANT NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AVIZIESLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CC78A85223ECCBADBEE76F8BAB687BF367120B5</HASHVAL>
  <TEXT>CREATE TABLE AVIZIESLUNA (
  CODIES1 NUMBER(20,0),
  REST NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AVIZINTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5BF9543885AFDC6486FB855D0AE3E0143881B61</HASHVAL>
  <TEXT>CREATE TABLE AVIZINTLUNA (
  CODINTR1 NUMBER(20,0),
  REST NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>AWBCOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E2359C1AF152EB302C22498974C6BB5919AB256</HASHVAL>
  <TEXT>CREATE TABLE AWBCOMANDA (
  CODAWBCOMANDA NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  CURIER NUMBER(2,0),
  NUMAR VARCHAR2(30),
  DOC CLOB,
  PDF BLOB,
  INFOSTADIU VARCHAR2(500),
  POSTAT NUMBER(1,0),
  DATAPOSTARE DATE,
  TARIF NUMBER(10,2),
  TVA NUMBER(10,2),
  TIPDOC NUMBER(5,0),
  SHIPMENTID NUMBER(20,0),
  PARCELSID CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BAL_STOC_REST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5816C2417CBC2845E30CCCDAA2DE5CAFE1A8A2F</HASHVAL>
  <TEXT>CREATE TABLE BAL_STOC_REST (
  COD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BANKAUTENTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD0288D4BE2496DA64D1786448CDAD183FA6D55B</HASHVAL>
  <TEXT>CREATE TABLE BANKAUTENTIF (
  COD NUMBER(20,0) NOT NULL,
  TIP_API NUMBER(2,0),
  IBAN VARCHAR2(30),
  TOKEN VARCHAR2(2000),
  CONSENTID VARCHAR2(100),
  EXTERNALID VARCHAR2(100),
  DATATOKEN DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEF92BF833DF0458BE43280C37CFC6BF8C5F219D</HASHVAL>
  <TEXT>CREATE TABLE BCAR (
  CODBCAR NUMBER(20,0) NOT NULL,
  OPERAT NUMBER(1,0),
  CODCANTARIN NUMBER(20,0),
  CODCANTAROUT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  PREFIXDOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  PREFIXAVIZIN VARCHAR2(2),
  NRAVIZIN NUMBER(20,0),
  NRAVIZOUT NUMBER(20,0),
  DATAAVIZIN DATE,
  ISUMIDITATE NUMBER(20,7),
  IAUMIDITATE NUMBER(20,7),
  ISSTRAINE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  ISINCOLTIT NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  ISHECTOLITRICA NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  ISGLUTEN NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  ISFUZARITATE NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  ISCADERE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  ISDEFORMARE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  ISSTICLOZITATE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  ISSPARTURI NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  BRUTKG NUMBER(20,7),
  TARA NUMBER(20,7),
  NETKG NUMBER(20,7),
  UTILKG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETUSCARE NUMBER(20,7),
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODDELEGAT NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODSERIE NUMBER(20,0),
  RETUR NUMBER(1,0),
  MODCANTAR NUMBER(1,0),
  USERIDBLOCAJ NUMBER(20,0),
  TIPBCAR NUMBER(1,0),
  CODGESTIMPL NUMBER(20,0),
  CODLOCATIMPL NUMBER(20,0),
  OBSERVATII VARCHAR2(40),
  CODPERS NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODAUTO NUMBER(20,0),
  ICUMIDITATE NUMBER(20,7),
  ICSTRAINE NUMBER(20,7),
  ICINCOLTIT NUMBER(20,7),
  ICHECTOLITRICA NUMBER(20,7),
  ICGLUTEN NUMBER(20,7),
  ICFUZARITATE NUMBER(20,7),
  ICCADERE NUMBER(20,7),
  ICDEFORMARE NUMBER(20,7),
  ICSTICLOZITATE NUMBER(20,7),
  ICSPARTURI NUMBER(20,7),
  NETKGCLIENT NUMBER(20,7),
  UTILKGCLIENT NUMBER(20,7),
  INFOCLIENT NUMBER(1,0),
  CODDOC1STORNO NUMBER(20,0),
  CODBCARDEST NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  NRREMORCA VARCHAR2(15),
  CODREMORCA NUMBER(20,0),
  UTILSTASKG NUMBER(20,7),
  PRETCONFIRMAT NUMBER(20,7),
  ISPROTEINA NUMBER(20,7),
  ISAFLATOXINA NUMBER(20,7),
  ISATAC_PLOSNITA NUMBER(20,7),
  ISCONTINUT_ULEI NUMBER(20,7),
  ISACIDITATE NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  ICPROTEINA NUMBER(20,7),
  ICAFLATOXINA NUMBER(20,7),
  ICATAC_PLOSNITA NUMBER(20,7),
  ICCONTINUT_ULEI NUMBER(20,7),
  ICACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7),
  ISSISTAVE NUMBER(20,7),
  ISREFRACTIE NUMBER(20,7),
  ISINDICE_W NUMBER(20,7),
  ISTOXINA_DON NUMBER(20,7),
  ISBOABE_TOXICE NUMBER(20,7),
  ICSISTAVE NUMBER(20,7),
  ICREFRACTIE NUMBER(20,7),
  ICINDICE_W NUMBER(20,7),
  ICTOXINA_DON NUMBER(20,7),
  ICBOABE_TOXICE NUMBER(20,7),
  PIERDERITEH NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CURS NUMBER(22,4),
  ID_CITIRE1 VARCHAR2(20),
  ID_CITIRE2 VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BONLINKERR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC6FDD9E75F52FC1746C673FC3357E9620D108C9</HASHVAL>
  <TEXT>CREATE TABLE BONLINKERR (
  CODBONLINKERR NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  BONURI CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BONMASA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB60D3C357D53D4A9D4777A81194249599D352A2</HASHVAL>
  <TEXT>CREATE TABLE BONMASA (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A9494ABD121DBC0443639DEE599271EB79E0B1E</HASHVAL>
  <TEXT>CREATE TABLE BUGETANALIZA (
  CODANALIZA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODELEMENT NUMBER(20,0),
  BUGET NUMBER(20,7),
  TIP NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETCAP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05EBE3B6A0F606E012BB4B11674C4AA062C68464</HASHVAL>
  <TEXT>CREATE TABLE BUGETCAP (
  CODBUGETCAP NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  TIPCAP NUMBER(5,0),
  CODCLASEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETCAP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>842FA4964D92FA74F4FAEFE80C59E4EC23257BE7</HASHVAL>
  <TEXT>CREATE TABLE BUGETCAP1 (
  CODBUGETCAP1 NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E29830762DD9136EFAB8080B556887CF5E39B7E</HASHVAL>
  <TEXT>CREATE TABLE BUGETCL (
  CODBUGETCL NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22C9A657FD37CA47DB211615F22F746E00F92981</HASHVAL>
  <TEXT>CREATE TABLE BUGETMF (
  CODBUGETMF NUMBER(20,0) NOT NULL,
  CODMIFIX NUMBER(20,0),
  USERID NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF96A65BB796ACE67339374A9C08E19AC234D10C</HASHVAL>
  <TEXT>CREATE TABLE BUGETMF1 (
  CODBUGETMF1 NUMBER(20,0) NOT NULL,
  CODBUGETMF NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(200),
  VALOARE NUMBER(20,7),
  DATABUGET DATE,
  OBS VARCHAR2(250),
  STADIU NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3453461790C97C69C0D58B4FC3714695AE1D9198</HASHVAL>
  <TEXT>CREATE TABLE BUGETPROD (
  CODBUGETPROD NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS VARCHAR2(400),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(2,0),
  ANIMPORT NUMBER(4,0),
  SAPTAMANAF NUMBER(2,0),
  ANF NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETPRODP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13AB57F31977A80172FDBBB6936B5B395CE4B8D8</HASHVAL>
  <TEXT>CREATE TABLE BUGETPRODP (
  CODBUGETPRODP NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETPRODT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A6F28B84927602A19358F55A586677B040F592E5</HASHVAL>
  <TEXT>CREATE TABLE BUGETPRODT (
  CODBUGETPRODT NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETPRODV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9FB527813E2603F42EAD45996F14F847DA53F6C</HASHVAL>
  <TEXT>CREATE TABLE BUGETPRODV (
  CODBUGETPRODV NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETRECTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA28F5B20F90BDABC3871883362376FAB19414AB</HASHVAL>
  <TEXT>CREATE TABLE BUGETRECTIF (
  CODBUGETRECTIF NUMBER(20,0) NOT NULL,
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(4,0),
  LUNASURSA NUMBER(2,0),
  LUNADEST NUMBER(20,0),
  OBS VARCHAR2(250),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODANALIZA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETRECTIF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D463E1222C265F412281B895656FB522844D50F</HASHVAL>
  <TEXT>CREATE TABLE BUGETRECTIF1 (
  CODBUGETRECTIF1 NUMBER(20,0) NOT NULL,
  CODBUGETRECTIF NUMBER(20,0),
  CODNODSURSA NUMBER(20,0),
  CODNODDEST NUMBER(20,0),
  VCREDIT NUMBER(20,7),
  VANGAJAPROB NUMBER(20,7),
  VANGAJREAL NUMBER(20,7),
  VPLATAAPROB NUMBER(20,7),
  VPLATAREAL NUMBER(20,7),
  VCHELT NUMBER(20,7),
  VPLANIF NUMBER(20,7),
  VFACT NUMBER(20,7),
  VINCASREAL NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB71097E627F01FD2C5D49750450EA8DD8026F4D</HASHVAL>
  <TEXT>CREATE TABLE BUGETSTOC (
  CODBUGETSTOC NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  STOC NUMBER(20,7),
  COEFUM NUMBER(20,7),
  VALTOTAL NUMBER(20,7),
  VALMAT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETVCL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD40D1B382B600F82143B2BDBDA3E37F4076850C</HASHVAL>
  <TEXT>CREATE TABLE BUGETVCL (
  CODBUGETVCL NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  TIPCAP NUMBER(1,0),
  COEFUM NUMBER(20,7),
  L1_CAP NUMBER(20,7),
  L1_STOC NUMBER(20,7),
  L1_VANZ NUMBER(20,7),
  L1_TARGET NUMBER(20,7),
  L1_NPCANT NUMBER(20,7),
  L1_PRET NUMBER(20,7),
  L1_NPVAL NUMBER(20,7),
  L1_COEFCAP NUMBER(20,7),
  L1_NPFCANT NUMBER(20,7),
  L1_NPFVAL NUMBER(20,7),
  L1_PRETMMR NUMBER(20,7),
  L1_PRETMAT NUMBER(20,7),
  L1_VAR NUMBER(20,7),
  L1_EST NUMBER(20,7),
  L2_CAP NUMBER(20,7),
  L2_STOC NUMBER(20,7),
  L2_VANZ NUMBER(20,7),
  L2_TARGET NUMBER(20,7),
  L2_NPCANT NUMBER(20,7),
  L2_PRET NUMBER(20,7),
  L2_NPVAL NUMBER(20,7),
  L2_COEFCAP NUMBER(20,7),
  L2_NPFCANT NUMBER(20,7),
  L2_NPFVAL NUMBER(20,7),
  L2_PRETMMR NUMBER(20,7),
  L2_PRETMAT NUMBER(20,7),
  L2_VAR NUMBER(20,7),
  L2_EST NUMBER(20,7),
  L3_CAP NUMBER(20,7),
  L3_STOC NUMBER(20,7),
  L3_VANZ NUMBER(20,7),
  L3_TARGET NUMBER(20,7),
  L3_NPCANT NUMBER(20,7),
  L3_PRET NUMBER(20,7),
  L3_NPVAL NUMBER(20,7),
  L3_COEFCAP NUMBER(20,7),
  L3_NPFCANT NUMBER(20,7),
  L3_NPFVAL NUMBER(20,7),
  L3_PRETMMR NUMBER(20,7),
  L3_PRETMAT NUMBER(20,7),
  L3_VAR NUMBER(20,7),
  L3_EST NUMBER(20,7),
  L4_CAP NUMBER(20,7),
  L4_STOC NUMBER(20,7),
  L4_VANZ NUMBER(20,7),
  L4_TARGET NUMBER(20,7),
  L4_NPCANT NUMBER(20,7),
  L4_PRET NUMBER(20,7),
  L4_NPVAL NUMBER(20,7),
  L4_COEFCAP NUMBER(20,7),
  L4_NPFCANT NUMBER(20,7),
  L4_NPFVAL NUMBER(20,7),
  L4_PRETMMR NUMBER(20,7),
  L4_PRETMAT NUMBER(20,7),
  L4_VAR NUMBER(20,7),
  L4_EST NUMBER(20,7),
  L5_CAP NUMBER(20,7),
  L5_STOC NUMBER(20,7),
  L5_VANZ NUMBER(20,7),
  L5_TARGET NUMBER(20,7),
  L5_NPCANT NUMBER(20,7),
  L5_PRET NUMBER(20,7),
  L5_NPVAL NUMBER(20,7),
  L5_COEFCAP NUMBER(20,7),
  L5_NPFCANT NUMBER(20,7),
  L5_NPFVAL NUMBER(20,7),
  L5_PRETMMR NUMBER(20,7),
  L5_PRETMAT NUMBER(20,7),
  L5_VAR NUMBER(20,7),
  L5_EST NUMBER(20,7),
  L6_CAP NUMBER(20,7),
  L6_STOC NUMBER(20,7),
  L6_VANZ NUMBER(20,7),
  L6_TARGET NUMBER(20,7),
  L6_NPCANT NUMBER(20,7),
  L6_PRET NUMBER(20,7),
  L6_NPVAL NUMBER(20,7),
  L6_COEFCAP NUMBER(20,7),
  L6_NPFCANT NUMBER(20,7),
  L6_NPFVAL NUMBER(20,7),
  L6_PRETMMR NUMBER(20,7),
  L6_PRETMAT NUMBER(20,7),
  L6_VAR NUMBER(20,7),
  L6_EST NUMBER(20,7),
  L7_CAP NUMBER(20,7),
  L7_STOC NUMBER(20,7),
  L7_VANZ NUMBER(20,7),
  L7_TARGET NUMBER(20,7),
  L7_NPCANT NUMBER(20,7),
  L7_PRET NUMBER(20,7),
  L7_NPVAL NUMBER(20,7),
  L7_COEFCAP NUMBER(20,7),
  L7_NPFCANT NUMBER(20,7),
  L7_NPFVAL NUMBER(20,7),
  L7_PRETMMR NUMBER(20,7),
  L7_PRETMAT NUMBER(20,7),
  L7_VAR NUMBER(20,7),
  L7_EST NUMBER(20,7),
  L8_CAP NUMBER(20,7),
  L8_STOC NUMBER(20,7),
  L8_VANZ NUMBER(20,7),
  L8_TARGET NUMBER(20,7),
  L8_NPCANT NUMBER(20,7),
  L8_PRET NUMBER(20,7),
  L8_NPVAL NUMBER(20,7),
  L8_COEFCAP NUMBER(20,7),
  L8_NPFCANT NUMBER(20,7),
  L8_NPFVAL NUMBER(20,7),
  L8_PRETMMR NUMBER(20,7),
  L8_PRETMAT NUMBER(20,7),
  L8_VAR NUMBER(20,7),
  L8_EST NUMBER(20,7),
  L9_CAP NUMBER(20,7),
  L9_STOC NUMBER(20,7),
  L9_VANZ NUMBER(20,7),
  L9_TARGET NUMBER(20,7),
  L9_NPCANT NUMBER(20,7),
  L9_PRET NUMBER(20,7),
  L9_NPVAL NUMBER(20,7),
  L9_COEFCAP NUMBER(20,7),
  L9_NPFCANT NUMBER(20,7),
  L9_NPFVAL NUMBER(20,7),
  L9_PRETMMR NUMBER(20,7),
  L9_PRETMAT NUMBER(20,7),
  L9_VAR NUMBER(20,7),
  L9_EST NUMBER(20,7),
  L10_CAP NUMBER(20,7),
  L10_STOC NUMBER(20,7),
  L10_VANZ NUMBER(20,7),
  L10_TARGET NUMBER(20,7),
  L10_NPCANT NUMBER(20,7),
  L10_PRET NUMBER(20,7),
  L10_NPVAL NUMBER(20,7),
  L10_COEFCAP NUMBER(20,7),
  L10_NPFCANT NUMBER(20,7),
  L10_NPFVAL NUMBER(20,7),
  L10_PRETMMR NUMBER(20,7),
  L10_PRETMAT NUMBER(20,7),
  L10_VAR NUMBER(20,7),
  L10_EST NUMBER(20,7),
  L11_CAP NUMBER(20,7),
  L11_STOC NUMBER(20,7),
  L11_VANZ NUMBER(20,7),
  L11_TARGET NUMBER(20,7),
  L11_NPCANT NUMBER(20,7),
  L11_PRET NUMBER(20,7),
  L11_NPVAL NUMBER(20,7),
  L11_COEFCAP NUMBER(20,7),
  L11_NPFCANT NUMBER(20,7),
  L11_NPFVAL NUMBER(20,7),
  L11_PRETMMR NUMBER(20,7),
  L11_PRETMAT NUMBER(20,7),
  L11_VAR NUMBER(20,7),
  L11_EST NUMBER(20,7),
  L12_CAP NUMBER(20,7),
  L12_STOC NUMBER(20,7),
  L12_VANZ NUMBER(20,7),
  L12_TARGET NUMBER(20,7),
  L12_NPCANT NUMBER(20,7),
  L12_PRET NUMBER(20,7),
  L12_NPVAL NUMBER(20,7),
  L12_COEFCAP NUMBER(20,7),
  L12_NPFCANT NUMBER(20,7),
  L12_NPFVAL NUMBER(20,7),
  L12_PRETMMR NUMBER(20,7),
  L12_PRETMAT NUMBER(20,7),
  L12_VAR NUMBER(20,7),
  L12_EST NUMBER(20,7),
  L1_NPFVAL_ORIG NUMBER(20,7),
  L2_NPFVAL_ORIG NUMBER(20,7),
  L3_NPFVAL_ORIG NUMBER(20,7),
  L4_NPFVAL_ORIG NUMBER(20,7),
  L5_NPFVAL_ORIG NUMBER(20,7),
  L6_NPFVAL_ORIG NUMBER(20,7),
  L7_NPFVAL_ORIG NUMBER(20,7),
  L8_NPFVAL_ORIG NUMBER(20,7),
  L9_NPFVAL_ORIG NUMBER(20,7),
  L10_NPFVAL_ORIG NUMBER(20,7),
  L11_NPFVAL_ORIG NUMBER(20,7),
  L12_NPFVAL_ORIG NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>BUGETVL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BF8ECBA42B50DE8028C91247F264CD3344A18FB7</HASHVAL>
  <TEXT>CREATE TABLE BUGETVL (
  CODBUGETVL NUMBER(20,0) NOT NULL,
  CODBUGETPROD NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CAENSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C962C61715B024DBA01015D43DE7FF7BFFE1DDB6</HASHVAL>
  <TEXT>CREATE TABLE CAENSEC (
  CODCAENSEC NUMBER(20,0) NOT NULL,
  CAEN NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CAMPANII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11FB66A5553E7EB545F4A66D3C48C4B5695290BD</HASHVAL>
  <TEXT>CREATE TABLE CAMPANII (
  CODCAMPANIE NUMBER(20,0) NOT NULL,
  DENCAMPANIE VARCHAR2(200),
  OBIECTIV VARCHAR2(2000),
  TARGET VARCHAR2(200),
  DATAINIT DATE,
  DATAFIN DATE,
  CODMONEDA NUMBER(20,0),
  CODRESPONSABIL NUMBER(20,0),
  COSTESTIMAT NUMBER(20,7),
  VENITESTIMAT NUMBER(20,7),
  CODSUBUNITATE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CAMPANIICOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B883540A8F69E0B203219C3CC1DB4C598F4DAFE8</HASHVAL>
  <TEXT>CREATE TABLE CAMPANIICOST (
  CODCAMPANIECOST NUMBER(20,0) NOT NULL,
  CODCAMPANIE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  PREFIXDOC VARCHAR2(10),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CAMPANIIPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C124190148CE1F17CCC01315C19A5FE3C8C684E</HASHVAL>
  <TEXT>CREATE TABLE CAMPANIIPART (
  CODCAMPANIEPART NUMBER(20,0) NOT NULL,
  CODCAMPANIE NUMBER(20,0),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CAMPANIIVENIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EFB798C184B5A78777669FBCAD9A57ED8CB79C8</HASHVAL>
  <TEXT>CREATE TABLE CAMPANIIVENIT (
  CODCAMPANIEVENIT NUMBER(20,0) NOT NULL,
  CODCAMPANIE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  PREFIXDOC VARCHAR2(10),
  CODPART NUMBER(20,0),
  VALFACT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CANAMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92BC1A1EE13490F2F3A7310A6F3348341A8C8DD6</HASHVAL>
  <TEXT>CREATE TABLE CANAMED (
  CODCANAMED NUMBER(20,0) NOT NULL,
  DATALISTA DATE,
  OBS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CANAMED1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1AC7943824AD7B8D383018D38AECA558FDE3FC1F</HASHVAL>
  <TEXT>CREATE TABLE CANAMED1 (
  CODCANAMED1 NUMBER(20,0) NOT NULL,
  CODCANAMED NUMBER(20,0),
  CODCNPM VARCHAR2(20),
  CODCIM VARCHAR2(20),
  DENPRODUS VARCHAR2(250),
  FORMA VARCHAR2(250),
  CONCENTR VARCHAR2(150),
  FIRMA VARCHAR2(250),
  DCI VARCHAR2(250),
  AMBALAJ VARCHAR2(350),
  GRUPA VARCHAR2(100),
  PRETPROD NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRETAM NUMBER(20,7),
  STATUTFRM VARCHAR2(50),
  STATUTANM VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>811239D94AAC797BA8F23A5DF95349B84803B8E8</HASHVAL>
  <TEXT>CREATE TABLE CANTAR (
  CODCANTAR NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TOTAL_KG NUMBER(20,7),
  TARA_KG NUMBER(20,7),
  NET_KG NUMBER(20,7),
  AMB1_COD NUMBER(20,0),
  AMB1_KG NUMBER(20,7),
  AMB1_CANT NUMBER(20,0),
  AMB1_RETURNABIL NUMBER(1,0),
  AMB2_COD NUMBER(20,0),
  AMB2_KG NUMBER(20,7),
  AMB2_CANT NUMBER(20,0),
  AMB2_RETURNABIL NUMBER(1,0),
  AMB3_COD NUMBER(20,0),
  AMB3_KG NUMBER(20,7),
  AMB3_CANT NUMBER(20,0),
  AMB3_RETURNABIL NUMBER(1,0),
  AMB4_COD NUMBER(20,0),
  AMB4_KG NUMBER(20,7),
  AMB4_CANT NUMBER(20,0),
  AMB4_RETURNABIL NUMBER(1,0),
  PALET_KG NUMBER(20,7),
  TRANSP1_COD NUMBER(20,0),
  TRANSP1_KG NUMBER(20,7),
  TRANSP1_CANT NUMBER(20,0),
  TRANSP2_COD NUMBER(20,0),
  TRANSP2_KG NUMBER(20,7),
  TRANSP2_CANT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  USERIDBLOCAJ NUMBER(20,0),
  ANULAT NUMBER(1,0),
  INDEXCANTAR NUMBER(2,0),
  RETUR NUMBER(1,0),
  SERIE NUMBER(20,0),
  IDCANTAR NUMBER(20,0),
  FURNIZOR NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  DESTINATIE NUMBER(1,0),
  CLIENT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODCMD1 NUMBER(20,0),
  AMB5_COD NUMBER(20,0),
  AMB5_KG NUMBER(20,7),
  AMB5_CANT NUMBER(20,0),
  AMB5_RETURNABIL NUMBER(1,0),
  AMB6_COD NUMBER(20,0),
  AMB6_KG NUMBER(20,7),
  AMB6_CANT NUMBER(20,0),
  AMB6_RETURNABIL NUMBER(1,0),
  ID_CANTARIRE VARCHAR2(20),
  TRANSPORTATOR VARCHAR2(50),
  NRVEHICOL VARCHAR2(20),
  NRREMORCA VARCHAR2(20),
  CANTDOC NUMBER(20,7),
  SERIEAVIZ VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CANTARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19192EF20E47A531FC94D472F3E972E47D91B455</HASHVAL>
  <TEXT>CREATE TABLE CANTARE (
  CODCANTAR NUMBER(20,0),
  TIP NUMBER(5,0),
  DENUMIRE VARCHAR2(50),
  IP VARCHAR2(20),
  DIREXPORT VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CARDURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25BA2B8E8F740219E5C52D8B78C89FB42B3306AE</HASHVAL>
  <TEXT>CREATE TABLE CARDURI (
  CODCARD NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(100),
  DENUMIRE VARCHAR2(250),
  OBS VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C4C88A808B9DB7542243EEE950B2DE932D33AB8</HASHVAL>
  <TEXT>CREATE TABLE CASHFLOW (
  CODCASHFLOW NUMBER(20,0),
  DATA DATE,
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  VALOAREDEREPARTIZAT NUMBER(20,0),
  APROBAT NUMBER(1,0),
  ZILE NUMBER(5,0),
  CODMONEDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B31163B83A2CFB6A08DEECB89455CBAA22EF97B</HASHVAL>
  <TEXT>CREATE TABLE CASHFLOW1 (
  CODCASHFLOW1 NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  RESTCONV NUMBER(20,7),
  DATAPROPUSA DATE,
  CODOP1 NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  TIP NUMBER(1,0),
  OBS VARCHAR2(300)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASHFLOW2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B69B1F4AF6D179FF311FA08C14EDE6C410FF13A</HASHVAL>
  <TEXT>CREATE TABLE CASHFLOW2 (
  CODCASHFLOW2 NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  RESTCONV NUMBER(20,7),
  DATAPROPUSA DATE,
  CODOP1 NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  TIP NUMBER(1,0),
  OBS VARCHAR2(300)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASTOT_CURSPREPAY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7CBD9E5A6E375F8783E869714E85C96EE7D1427</HASHVAL>
  <TEXT>CREATE TABLE CASTOT_CURSPREPAY (
  IDFURNIZOR NUMBER(10,0),
  FURNIZOR VARCHAR2(50),
  CURS NUMBER(20,7),
  TIPSERVICIU NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASTOT_PREPAY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CB6BC0DA8DFD82F2BD3709BEAA5478B383967D0E</HASHVAL>
  <TEXT>CREATE TABLE CASTOT_PREPAY (
  COD_CASTOTPREPAY NUMBER(20,0) NOT NULL,
  FURNIZOR VARCHAR2(50),
  IDFURNIZOR NUMBER(10,0),
  SERVICIU VARCHAR2(50),
  IDSERVICIU VARCHAR2(50),
  TELEFON VARCHAR2(20),
  MONEDA VARCHAR2(5),
  VALOARE NUMBER(20,7),
  VALOARERON NUMBER(20,7),
  TRACKINGNUMBER VARCHAR2(20),
  DATATRANZACTIE TIMESTAMP(6),
  PINCODE VARCHAR2(20),
  PINCODEVALID VARCHAR2(10),
  LISTATCM NUMBER(1,0),
  LISTATCHITANTA NUMBER(1,0),
  CODEMULARE NUMBER(20,0),
  JSONRESPONSE CLOB,
  COD_SCALA VARCHAR2(25),
  PINCODE_SERIALNO VARCHAR2(25),
  FOOTER_TEXT CLOB,
  IDTRANZACTIE VARCHAR2(25),
  NRTRANZWME VARCHAR2(25),
  TIPINCARCARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CASTOT_UTILITY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20B8C8F11933195CB6DA71F0ADD7403CD1551F66</HASHVAL>
  <TEXT>CREATE TABLE CASTOT_UTILITY (
  COD_CASTOTUTILITY NUMBER(20,0) NOT NULL,
  FURNIZOR VARCHAR2(80),
  SERVICIU VARCHAR2(80),
  DEPLATA NUMBER(20,7),
  PLATIT NUMBER(20,7),
  PLATIT_TEXT VARCHAR2(80),
  COD_SCALA VARCHAR2(50),
  DATATRANZACTIE TIMESTAMP(6),
  CODCLIENT VARCHAR2(50),
  TELEFON VARCHAR2(20),
  NRFACTURA VARCHAR2(30),
  DATAFACTURA TIMESTAMP(6),
  SUCURSALA VARCHAR2(30),
  ATMCOD VARCHAR2(30),
  CUSTOMCODE1 VARCHAR2(30),
  CUSTOMPAYMENTFIELD3 VARCHAR2(30),
  JSONRESPONSE CLOB,
  LISTAT NUMBER(1,0),
  LISTATCM NUMBER(1,0),
  CODEMULARE NUMBER(20,0),
  CARD NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CATEGARTTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B137165FE930E90083542CCCAA344412D7BFFFB5</HASHVAL>
  <TEXT>CREATE TABLE CATEGARTTI (
  CODCATEGARTTI NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  SIMBOLP NUMBER(20,0),
  SIMBOLN NUMBER(20,0),
  SIMBOLP1 NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  DENUMIREP VARCHAR2(200),
  CODP NUMBER(20,0),
  CODN_STOC NUMBER(20,0),
  CODN_SERV NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50187D234D9243D11BA862BDF442046E65132FAE</HASHVAL>
  <TEXT>CREATE TABLE CATEGCONST (
  CODCATEG NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  INDEXLOCAL VARCHAR2(10),
  TIPCATEG VARCHAR2(1)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CENTRALIZARENC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07D0685FFA97FE03071431AA0C2102CEF07E9B1B</HASHVAL>
  <TEXT>CREATE TABLE CENTRALIZARENC (
  CODCENTRALIZARE NUMBER(20,0) NOT NULL,
  CODNCREDIT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTASOC NUMBER(20,0),
  CODOBIECTASOCSEC NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DIFERENTE NUMBER(20,7),
  TIPARTICOL NUMBER(20,0),
  FACTURAT NUMBER(20,7),
  PROCTVA NUMBER(6,3),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(450),
  CANT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A31587310E79E7A3FD0B99FD961BC5CB3F674413</HASHVAL>
  <TEXT>CREATE TABLE CENTRECOST (
  CODCENTRU NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(100),
  DENUMIRE VARCHAR2(100),
  TIPCHELT NUMBER(2,0),
  TIPALOC NUMBER(2,0),
  TIP NUMBER(1,0),
  INACTIV NUMBER(1,0),
  DOMENIU VARCHAR2(20),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CENTRECOSTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3B51333483ABA0E8A8BD05F5DD0E38F3F22A69E</HASHVAL>
  <TEXT>CREATE TABLE CENTRECOSTA (
  CODCENTRUA NUMBER(20,0) NOT NULL,
  CODCENTRU NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  NODMAXIMANALIZA1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>856599A59B40FD1FB514090B4F065AE1C894C0E0</HASHVAL>
  <TEXT>CREATE TABLE CERTIF (
  CODCERTIF NUMBER(20,0) NOT NULL,
  NRCERTIF VARCHAR2(100),
  DATAPRIMIRE DATE,
  FISIER BLOB,
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  NUMEFISIER VARCHAR2(250),
  EXT VARCHAR2(4),
  SUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  PROVENIENTA VARCHAR2(250),
  CODTARA NUMBER(20,0),
  OBS VARCHAR2(250),
  TIPPART NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CFGACTIONS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC0F9725BA43E0FEDB05D4347379A58AEA433F83</HASHVAL>
  <TEXT>CREATE TABLE CFGACTIONS (
  CODCFGACTIONS NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(5,0),
  TIPSQL NUMBER(1,0),
  TIP NUMBER(1,0),
  ID NUMBER(5,0),
  SQLITE CLOB,
  MESAJ VARCHAR2(150)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CFGTABLES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0ABAAFD160E08C7F53A56CE33F34477D4D1BF5F3</HASHVAL>
  <TEXT>CREATE TABLE CFGTABLES (
  CODCFGTABLE NUMBER(20,0),
  NUMETABELA VARCHAR2(20),
  TIPCONFIG NUMBER(1,0),
  MASTER VARCHAR2(20),
  LINKKEY VARCHAR2(20),
  TIPLINK NUMBER(1,0),
  DESCRIERE VARCHAR2(100),
  SUPLIMSQL CLOB,
  UPDATESQL CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CFGTABLES1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C641858F34B956839C176603644C895285974A9</HASHVAL>
  <TEXT>CREATE TABLE CFGTABLES1 (
  CODCFGTABLE1 NUMBER(20,0),
  CODCFGTABLE NUMBER(20,0),
  INDEXLOCAL NUMBER(6,0),
  NUMECAMP VARCHAR2(20),
  CAPTION VARCHAR2(30),
  TIP VARCHAR2(1),
  MARIME NUMBER(6,0),
  ZECIMALE NUMBER(6,0),
  COLWIDTH NUMBER(6,0),
  COLOR NUMBER(10,0),
  OBLIGATORIU NUMBER(1,0),
  NOMLINK NUMBER(10,0),
  LOOKUPDISPLAY VARCHAR2(50),
  TIPFILTRUAFIS NUMBER(2,0),
  FILTRUAFIS VARCHAR2(2000),
  HASTOTAL NUMBER(1,0),
  TMP NUMBER(1,0),
  TOBEUPDATED NUMBER(1,0),
  SQLONCHANGE VARCHAR2(3000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CFGTABLES2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9B2459B06F71B3E7F732CE6145FBAB78E46DCC1</HASHVAL>
  <TEXT>CREATE TABLE CFGTABLES2 (
  CODCFGTABLE2 NUMBER(20,0),
  CODCFGTABLE1 NUMBER(20,0),
  VALOARE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6197BD4E397AF75AB2DC1A6BFBEFEC3796C05A0C</HASHVAL>
  <TEXT>CREATE TABLE CHELTAVANS (
  CODCHELTAVANS NUMBER(20,0) NOT NULL,
  CODINTR1 NUMBER(20,0),
  ANINCEPUT NUMBER(5,0),
  LUNAINCEPUT NUMBER(2,0),
  CODIOART NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  OBSERVATII VARCHAR2(100),
  CODIES1 NUMBER(20,0),
  ISVENIT NUMBER(1,0),
  CODMIFIX NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CHELTAVANS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4CC59019CD1403501F29A67B364996D73D3EA9B</HASHVAL>
  <TEXT>CREATE TABLE CHELTAVANS1 (
  CODCHELTAVANS1 NUMBER(20,0) NOT NULL,
  CODCHELTAVANS NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DURATAN NUMBER(10,0),
  DURATAF NUMBER(10,0),
  DFBLOCAT NUMBER(1,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  AMO NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  DATAENDNOUA DATE,
  DATAENDBLOCATA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0),
  CENTRUBLOCAT NUMBER(1,0),
  CODGESTBLOCAT NUMBER(1,0),
  CODANALIZABLOCAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CHELTOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98A95D47ED1C5205EA33D32B00830C13778F2916</HASHVAL>
  <TEXT>CREATE TABLE CHELTOPER (
  CODCHELTOPER NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ANSTOP NUMBER(4,0),
  LUNASTOP NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CHELTOPER1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7632B50C67976543ADB5AC4608FE50B0E7B4545C</HASHVAL>
  <TEXT>CREATE TABLE CHELTOPER1 (
  CODCHELTOPER1 NUMBER(20,0) NOT NULL,
  CODCHELTOPER NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDAPROBARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A07F8B257897B9D8F685178C63823FAE7006F95D</HASHVAL>
  <TEXT>CREATE TABLE CMDAPROBARI (
  COD NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  NIVEL NUMBER(3,0),
  STARE NUMBER(20,0),
  OBS VARCHAR2(100),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5958921BFC54D49F151F98005506015F084CF79D</HASHVAL>
  <TEXT>CREATE TABLE CMDAVANS (
  CODCMDAVANS NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODIESAVANS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDCANTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82AD81EB9D151F7198347B0C8BB02295EE1B473E</HASHVAL>
  <TEXT>CREATE TABLE CMDCANTLOCK (
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIESTINGATOARE NUMBER(20,0),
  CANT NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6ABF302E8852B2488542C33791878DA76B07E4D</HASHVAL>
  <TEXT>CREATE TABLE CMDLINK (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDLIVRLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>911248C534058BC6CB7CFE7BDDD2F947605530FF</HASHVAL>
  <TEXT>CREATE TABLE CMDLIVRLINK (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDPRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A45A6D42799E616A9D18743FFE7C081F6DA9E81</HASHVAL>
  <TEXT>CREATE TABLE CMDPRODMAN (
  CODCMDPRODMAN NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODMAN NUMBER(20,0),
  NROP NUMBER(10,0),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DSV NUMBER(20,7),
  BPS NUMBER(20,7),
  TPI NUMBER(20,7),
  OBS VARCHAR2(1000),
  DETALII NUMBER(10,0),
  DATASTART DATE,
  CODCOMANDA3 NUMBER(20,0),
  FIX NUMBER(1,0),
  NIVEL NUMBER(5,0),
  CODUTILAJ NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  COEFBPS NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDPRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E51F37A0D7670B46BB4853E390A3B672899A33A8</HASHVAL>
  <TEXT>CREATE TABLE CMDPRODMAT (
  CODCMDPRODMAT NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  REZIDUU NUMBER(1,0),
  CODPRODMAT NUMBER(20,0),
  PARITATEECHIV NUMBER(20,7),
  TIPECHIV NUMBER(1,0),
  CUMSEC NUMBER(20,0),
  CCANT NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CODCOMANDA3 NUMBER(20,0),
  UMSEC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDPRODREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A15C1A64DFDE0D69743AF7581EAC84F9C23AD588</HASHVAL>
  <TEXT>CREATE TABLE CMDPRODREZ (
  CODCMDPRODREZ NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CODCOMANDA3 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CMDPROIECTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0169E7418E833084DEF7F0A30297FDE993CEC1DD</HASHVAL>
  <TEXT>CREATE TABLE CMDPROIECTREZ (
  CODCMDPROIECTREZ NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODEXTALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EC59E5B6D10C19B1E3EA294BEB3D023BC8FF588</HASHVAL>
  <TEXT>CREATE TABLE CODEXTALT (
  COD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODEXTARTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>149D4858793D4DAE91D6ED29F097B54580F9FC39</HASHVAL>
  <TEXT>CREATE TABLE CODEXTARTLOCK (
  COD NUMBER(20,0),
  CODEXTERN NUMBER(30,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODEXTPARTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42657E1233C05A2EE2A7D3136C9A29A0F447A39A</HASHVAL>
  <TEXT>CREATE TABLE CODEXTPARTLOCK (
  COD NUMBER(20,0),
  CODEXTERN NUMBER(30,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODGESTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>691A47D7F520E8FA5639DB13F760FA7895D24942</HASHVAL>
  <TEXT>CREATE TABLE CODGESTLOCK (
  COD NUMBER(20,0),
  GEST NUMBER(20,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODINTALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED7177FB4283667C3B36481CAC3A84FAE2DA08A2</HASHVAL>
  <TEXT>CREATE TABLE CODINTALT (
  COD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODINTARTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A551CF9C365D261B14F30B329A0EF558B9F31DC0</HASHVAL>
  <TEXT>CREATE TABLE CODINTARTLOCK (
  COD NUMBER(20,0),
  CODINTERN NUMBER(30,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODINTPARTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BAAFE28D7695A2A5F700983592DFFF1D17F0B78</HASHVAL>
  <TEXT>CREATE TABLE CODINTPARTLOCK (
  COD NUMBER(20,0),
  CODINTERN NUMBER(30,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CODIOARTCORESP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E112E0538B15D15AB8126937A4D7FBA13835B863</HASHVAL>
  <TEXT>CREATE TABLE CODIOARTCORESP (
  COD NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  CODIOART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F88132C5515FB7C48D36013117D1D4D6306E3A09</HASHVAL>
  <TEXT>CREATE TABLE COMANDA (
  CODCOMANDA NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODCMDPARINTE NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  VALDISCOUNT NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODGEST NUMBER(20,0),
  INCHISA NUMBER(1,0),
  SUBUNITSURSA NUMBER(20,0),
  SCADENTAV NUMBER(5,0),
  SERIADOC VARCHAR2(20),
  USERIDBLOCAJ NUMBER(20,0),
  NRI VARCHAR2(30),
  CODTRASEULIVR NUMBER(20,0),
  ORDINELIVRARE NUMBER(20,0),
  MIJLTRANSP NUMBER(20,0),
  INSOTITOR NUMBER(20,0),
  DISPLIVRARE NUMBER(1,0),
  VERIFICAT NUMBER(1,0),
  CODIES NUMBER(20,0),
  FARATRANSPORT NUMBER(1,0),
  PLATAPELOC NUMBER(1,0),
  DATAINREG TIMESTAMP(6),
  FACTURABIL NUMBER(1,0),
  CURS NUMBER(20,7),
  SCHIMB NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  IDIMPORT VARCHAR2(30),
  LISTAT NUMBER(10,0),
  FACTURA_APL_EXT NUMBER(1,0),
  CODPERS_APL_EXT NUMBER(20,0),
  LOT NUMBER(10,0),
  NRTRANSP VARCHAR2(30),
  CODIESAVANS NUMBER(20,0),
  FARAFACTURA NUMBER(1,0),
  DINONLINE NUMBER(1,0),
  PRETCUAMANUNT NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  TIPTRANZACTIE NUMBER(1,0),
  SUBUNITDEST NUMBER(20,0),
  NRMAXAPROBARI NUMBER(10,0),
  STADIUWMS NUMBER(2,0),
  CODPERSC NUMBER(20,0),
  MOTIVINCHIDERE VARCHAR2(80),
  CODPARTCOMIS NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  GRATIE NUMBER(10,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  MODINCHIDERE NUMBER(1,0),
  PLATFORMA_ONLINE NUMBER(2,0),
  REMORCA NUMBER(20,0),
  ROTEFACT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BC190CB9FA74DE36BDA41265CA407D9AD82CA16</HASHVAL>
  <TEXT>CREATE TABLE COMANDA1 (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTACCEPTAT NUMBER(20,7),
  CULANSARE NUMBER(1,0),
  RESTLANSAT NUMBER(20,7),
  TERMEN DATE,
  ANULAT NUMBER(1,0),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  CODCATPRET NUMBER(20,0),
  CONSUM NUMBER(20,0),
  REZERVATINI NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPSURSA NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  DATAINCARCARII DATE,
  CANTRETURNAT NUMBER(20,7),
  ACCEPTUM1 NUMBER(20,7),
  TIPPLATA NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODRETETA NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  PUCORELAT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  POZITIE NUMBER(10,0),
  TIPLIVRARE NUMBER(1,0),
  CODANALIZANOD NUMBER(20,0),
  EXCEPTIONAL NUMBER(1,0),
  CODCONTRACT1 NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODNORMA NUMBER(20,0),
  MODINCHIDERE NUMBER(1,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODMIFIX NUMBER(20,0),
  TIPLINIESA NUMBER(1,0),
  PRIORITATE NUMBER(5,0),
  DATASTART TIMESTAMP(6),
  CODPROMO1 NUMBER(20,0),
  SUBUNITSURSA NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  DISCMANUAL NUMBER(1,0),
  FURNIZOR NUMBER(20,0),
  PUPROD NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA1ET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03678282B787C9940DF666D090C7F8645F3483AC</HASHVAL>
  <TEXT>CREATE TABLE COMANDA1ET (
  CODCOMANDA1ET NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODCOLET VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA1LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>839E407C43541CBE6EB157F6808CA0D96E701DC9</HASHVAL>
  <TEXT>CREATE TABLE COMANDA1LUNA (
  CODCOMANDA1 NUMBER(20,0),
  REST NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CBB50BB37A1526D6087C785CC88077A1726F93A6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE COMANDA1_MAN (
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AD9883DBE462DF37E8EE59FF6C46C86078CD563</HASHVAL>
  <TEXT>CREATE TABLE COMANDA2 (
  CODCOMANDA2 NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(10,0),
  CODLUCRARE NUMBER(20,0),
  OBS VARCHAR2(100),
  CODPART NUMBER(20,0),
  GARANTIE NUMBER(1,0),
  CODNPARCAUT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  ORE NUMBER(10,4)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3273ADD75CCFCB0170D1733F3A0B34E5435073B2</HASHVAL>
  <TEXT>CREATE TABLE COMANDA3 (
  CODCOMANDA3 NUMBER(20,0) NOT NULL,
  CODCOMANDA2 NUMBER(20,0),
  CODOPERATIE NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  OBS VARCHAR2(100),
  TIP NUMBER(1,0),
  EXECUTAT NUMBER(1,0),
  CODCOMANDA NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  DATA DATE,
  CODINTR1_1 NUMBER(20,0),
  CODINTR1_2 NUMBER(20,0),
  CODINTR1_3 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DURATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  TARIF NUMBER(20,7),
  DATASTART DATE,
  CATEGPRET NUMBER(5,0),
  CODPRESTATIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMANDA4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EA294CB05349146B5BDA1E6EAE2DFA21545F11C</HASHVAL>
  <TEXT>CREATE TABLE COMANDA4 (
  CODCOMANDA4 NUMBER(20,0) NOT NULL,
  CODCOMANDA3 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(200),
  CODCOMANDA NUMBER(20,0),
  ELIBERAT NUMBER(1,0),
  ORE NUMBER(10,2),
  CODCOMANDA2 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9586734F3F4E995F022379856E8AF2169E5197A</HASHVAL>
  <TEXT>CREATE TABLE COMPENS (
  CODCOMPENS NUMBER(20,0) NOT NULL,
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  PARTD NUMBER(20,0),
  PARTC NUMBER(20,0),
  OBSD VARCHAR2(100),
  OBSC VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODGEST NUMBER(20,0),
  TIPCOMPENS NUMBER(1,0),
  CODCENTRU NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODTIPPARTINCERT NUMBER(20,0),
  FLAGS NUMBER(2,0),
  EXCLUSSAFT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONCURENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FA491860C6FF02BE99CBA98DEB6D58F60FEA265</HASHVAL>
  <TEXT>CREATE TABLE CONCURENTI (
  CODCONCURENT NUMBER(20,0) NOT NULL,
  DENCONCURENT VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONDCOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9035F00A2EF1328D264B0DE71DC630582C77C92D</HASHVAL>
  <TEXT>CREATE TABLE CONDCOR1 (
  CODCONDCOR1 NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RND1 NUMBER(10,0),
  COL1 NUMBER(10,0),
  REL VARCHAR2(2),
  RND2 NUMBER(10,0),
  COL2 NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONST1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51DF9C40D3870A25DE5CD56D5633D1C251848CF8</HASHVAL>
  <TEXT>CREATE TABLE CONST1 (
  CODCONST1 NUMBER(20,0) NOT NULL,
  CODCATEG NUMBER(10,0),
  INDEXLOCAL VARCHAR2(10),
  SIMBOL VARCHAR2(20),
  DENUMIRE VARCHAR2(100),
  TIP NUMBER(10,0),
  DESCRIERE CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3687E2C64A2E9D00322A3C3C040973979C292B3F</HASHVAL>
  <TEXT>CREATE TABLE CONSTLUNA (
  CODCONSTLUNA NUMBER(20,0) NOT NULL,
  CODCONST1 NUMBER(10,0),
  ANSTART NUMBER(10,0),
  LUNASTART NUMBER(2,0),
  USERID NUMBER(10,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTMAKETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA46BED533FA35D720EC5672DB26770704C7A815</HASHVAL>
  <TEXT>CREATE TABLE CONSTMAKETA (
  CODCONSTMAKETA NUMBER(20,0) NOT NULL,
  CODMAKETA NUMBER(20,0),
  CODCONST1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTNMAKETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E1B82D1F56D81A003B053A5ADD6EFAB1CDDAC9C</HASHVAL>
  <TEXT>CREATE TABLE CONSTNMAKETE (
  CODCONSTMAKETA NUMBER(20,0),
  CODMAKETA NUMBER(20,0),
  CODCONST1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTUSERCHECK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3DFCAE6A6FC7DE11D479877C4808BFB96195A73</HASHVAL>
  <TEXT>CREATE TABLE CONSTUSERCHECK (
  USERID NUMBER(20,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36F258A168260152D8687F373B7B35528402FA60</HASHVAL>
  <TEXT>CREATE TABLE CONSTVAL (
  VALOARE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSTVALPOS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>546DA8B61835F99EC16699933E3D9F0984CB186F</HASHVAL>
  <TEXT>CREATE TABLE CONSTVALPOS (
  COD NUMBER(20,0) NOT NULL,
  IDX NUMBER(10,0),
  VALPOSIBILE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONSUMURI_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>593261897D0F592762985699F1C92D699765134A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE CONSUMURI_MAN (
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22731C1F3CC656B5EC628AEE3C1276460809EC97</HASHVAL>
  <TEXT>CREATE TABLE CONTRACT (
  CODCONTRACT NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DATASTART DATE,
  DATASTOP DATE,
  TIPCONTRACT NUMBER(1,0),
  TIPTARGET NUMBER(1,0),
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  PERTARGET NUMBER(1,0),
  NRLUNI NUMBER(20,0),
  PERFACT NUMBER(2,0),
  ZIFACT NUMBER(2,0),
  PROCMAJ NUMBER(8,5),
  PERCITIRE NUMBER(2,0),
  ZICITIRE NUMBER(2,0),
  TRANSPPART NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER,
  DATACREARE TIMESTAMP(6),
  AGENT NUMBER(20,0),
  CURS NUMBER(22,4),
  AVANS NUMBER(20,2),
  DOBANDA NUMBER(8,5),
  TIPDOBANDA NUMBER(1,0),
  CALCDOBANDA NUMBER(1,0),
  REZIDUALA NUMBER(20,2),
  REZIDUALASEPARAT NUMBER(1,0),
  FACTLEI NUMBER(1,0),
  ASIGANUAL NUMBER(20,2),
  LUNIGRATIE NUMBER(2,0),
  GRATIEFARADOB NUMBER(1,0),
  CODBANCA NUMBER(20,0),
  PROCMAJCURS NUMBER(8,5),
  AUTOPRELUNGIRE NUMBER(1,0),
  LUNIPRELUNGIRE NUMBER(4,0),
  TIPARTICOL NUMBER(1,0),
  TIPUM NUMBER(1,0),
  TIPTARGETV NUMBER(1,0),
  SEMNAT NUMBER(1,0),
  EXPLICATII VARCHAR2(50),
  STOPAJ NUMBER(20,0),
  SUMA1 NUMBER(20,7),
  DISCOUNT1 NUMBER(20,7),
  SUMA2 NUMBER(20,7),
  DISCOUNT2 NUMBER(20,7),
  SUMA3 NUMBER(20,7),
  DISCOUNT3 NUMBER(20,7),
  SUMA4 NUMBER(20,7),
  DISCOUNT4 NUMBER(20,7),
  NRI VARCHAR2(30),
  CASS NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  MAXREPLSIMULTANE NUMBER(5,0),
  MAXZILEREPLA NUMBER(5,0),
  TIPLIVRARE NUMBER(2,0),
  TIPPERFACT NUMBER(1,0),
  MAJORARI NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGENERIC NUMBER(20,0),
  FACTPRETSTANDARD NUMBER(1,0),
  CREDITE_PLAFON NUMBER(20,7),
  CREDITE_PU NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACT0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37BD68239238FBDA049D3FE3265DC977C70AE94A</HASHVAL>
  <TEXT>CREATE TABLE CONTRACT0 (
  CODCONTRACT0 NUMBER(20,0) NOT NULL,
  CODCONTRACT NUMBER(20,0),
  TIPLINIE NUMBER(1,0),
  DATA DATE,
  CURS NUMBER(20,7),
  SUMA NUMBER(20,7),
  FACTURAT NUMBER(1,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DOBANDA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  OLDCURS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F60F910E2EB4E6E7B0E269A0C912BB61FCDA74A9</HASHVAL>
  <TEXT>CREATE TABLE CONTRACT1 (
  CODCONTRACT1 NUMBER(20,0) NOT NULL,
  CODCONTRACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROCDISC NUMBER(5,2),
  ZILEL NUMBER(5,0),
  ZILEC NUMBER(5,0),
  LANSARE NUMBER(1,0),
  ANEXA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(200),
  GESTACT NUMBER(20,0),
  TVA NUMBER(20,7),
  VALTARGET NUMBER(20,7),
  LIMITACADOU NUMBER(20,7),
  CANTCADOU NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODOBIECTSEC NUMBER(20,0),
  LIMITACADOUSEC NUMBER(20,7),
  TERMENFIX DATE,
  TIPPRET NUMBER(1,0),
  SEDIULIVRARE NUMBER(20,0),
  TIPDISCOUNT NUMBER(1,0),
  TIPDISCOUNTT NUMBER(1,0),
  TIPDISCOUNTC NUMBER(1,0),
  SUMAFIXA NUMBER(20,7),
  TIPDISCOUNTT1 NUMBER(1,0),
  CODCLASA NUMBER(20,0),
  DISCTCUMULAT NUMBER(1,0),
  DISCT NUMBER(20,7),
  CODCONTR1CADRU NUMBER(20,0),
  ADDIM NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIPOBIECT NUMBER(1,0),
  CANTGLOBAL NUMBER(20,7),
  PRETSTANDARD NUMBER(20,7),
  STARE NUMBER(1,0),
  DATALIVR DATE,
  CODAUTO NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  INDEXPARINTE NUMBER(10,0),
  TAXAUSCARE NUMBER(20,7),
  TAXACONDITIONARE NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  UTILAJ_TIP_INDEX NUMBER(2,0),
  VERIFUMA NUMBER(1,0),
  LUSCARE NUMBER(20,7),
  LCONDITIONARE NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRETUM1 NUMBER(20,7),
  PARITATECREDIT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>19FDCF75039B5A352AFFD0A34C5EC97830542567</HASHVAL>
  <TEXT>CREATE TABLE CONTRACT2 (
  CODCONTRACT2 NUMBER(20,0) NOT NULL,
  CODCONTRACT NUMBER(20,0),
  DATA DATE,
  DATASTOP DATE,
  SUMA NUMBER(20,7),
  DOBANDA NUMBER(20,7),
  ASIGURARE NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SUSPENDAT NUMBER(1,0),
  SEDIULIVRARE NUMBER(20,0),
  INDEXLOCAL NUMBER(12,2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODDOCT NUMBER(20,0),
  TIPDOCT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2075AB763D3CFD7CBF0C215BD5EA0E4F8618EE5A</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTC (
  CODCONTRACTC NUMBER(20,0) NOT NULL,
  CODCONTRACT1 NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTC0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FE03B524FB8EA2ABA5B672B16650BDD5BBBFD9E</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTC0 (
  CODCONTRACTC0 NUMBER(20,0) NOT NULL,
  CODCONTRACT NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0390E07D72B7B422631E363EFA9DA308992635D</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTT (
  CODCONTRACTT NUMBER(20,0) NOT NULL,
  CODCONTRACT1 NUMBER(20,0),
  ZILE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TERMENFIX DATE,
  PROCVALDOC NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTT_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67281F3941C43692883883D386D6FF076D7539C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE CONTRACTT_MANEVRA (
  CODCONTRACTT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  ZILE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TERMENFIX DATE,
  PROCVALDOC NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  CUMULAT NUMBER(1,0),
  ZILEDELA NUMBER(20,7),
  TERMENFIXDELA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B6514859983A75D96900AFA6E3E29C55568A48C</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTV (
  CODCONTRACTV NUMBER(20,0) NOT NULL,
  CODCONTRACT NUMBER(20,0),
  SUMA NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  CODCONTRACT1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F64E2912C45475ED1E8CAD88B45813FC4435A2D</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTX (
  CODCONTRACTX NUMBER(20,0) NOT NULL,
  CODCONTRACT1 NUMBER(20,0),
  PARAMETRU NUMBER(2,0),
  VALMIN NUMBER(20,7),
  PROCPU NUMBER(20,7),
  CORECTIEPU NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONTRACTXX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C39D0C4C37EFD700CC9C346E1DD1FE1720E289F</HASHVAL>
  <TEXT>CREATE TABLE CONTRACTXX (
  CODCONTRACTXX NUMBER(20,0) NOT NULL,
  CODCONTRACT1 NUMBER(20,0),
  PARAMETRU NUMBER(2,0),
  VALSTART NUMBER(20,7),
  VALSTOP NUMBER(20,7),
  ABATERE NUMBER(20,7),
  STARTPROC NUMBER(20,7),
  STARTCORECTIE NUMBER(20,7),
  PROC NUMBER(20,7),
  CORECTIE NUMBER(20,7),
  GENERARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CONVERTCURSPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DF22033E6563A16CF5D24273E8F6C6125DF50A8</HASHVAL>
  <TEXT>CREATE TABLE CONVERTCURSPERS (
  CODCONVERT NUMBER(20,0),
  CODPERS NUMBER(20,0),
  ICONTPERS NUMBER(3,0),
  MONEDA_IN NUMBER(20,0),
  MONEDA_OUT NUMBER(20,0),
  SOLDVALUTA_IN NUMBER(20,7),
  SOLDLEI NUMBER(20,7),
  SOLDVALUTA_OUT NUMBER(20,7),
  CURSCONVERSIE NUMBER(20,7),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  OBS VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CORELAT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C3E10DEFB217E36E786A8318BB36D57EEB5E8CE</HASHVAL>
  <TEXT>CREATE TABLE CORELAT1 (
  CODCORELAT1 NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RND1 VARCHAR2(250),
  COL1 VARCHAR2(20),
  REL VARCHAR2(2),
  RND2 VARCHAR2(250),
  COL2 VARCHAR2(20),
  COND VARCHAR2(100),
  ISNUMERIC NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CORELAT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06AC8D0FE6F58A0F615200A4EEA9D1290311B7D2</HASHVAL>
  <TEXT>CREATE TABLE CORELAT2 (
  CODCORELAT2 NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  CODF1 NUMBER(20,0),
  RND1 VARCHAR2(250),
  COL1 VARCHAR2(20),
  CODF2 NUMBER(20,0),
  RND2 VARCHAR2(250),
  COL2 VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CREANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2CB27683E4A0FA2157B482D0EF5839FA0CB28A85</HASHVAL>
  <TEXT>CREATE TABLE CREANTE (
  CODCREANTA NUMBER(20,0) NOT NULL,
  ANC NUMBER(4,0),
  LUNAC NUMBER(2,0),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CREANTE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>539148BF5F7D53DCC8A66F83A4F7DB3E5876F9CC</HASHVAL>
  <TEXT>CREATE TABLE CREANTE1 (
  CODCREANTA1 NUMBER(20,0) NOT NULL,
  CODCREANTA NUMBER(20,0),
  COD NUMBER(20,0),
  CODCONT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CRITERIIDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEAA44FDFF2EAC502D22F81C86CFF65935A3847A</HASHVAL>
  <TEXT>CREATE TABLE CRITERIIDISC (
  CODCRITERIU NUMBER(20,0) NOT NULL,
  DENCRITERIU VARCHAR2(40),
  EXCLUDVOLTR NUMBER(1,0),
  EXCLUDCANTFACT NUMBER(1,0),
  EXCLUDTERMEN NUMBER(1,0),
  EXCLUDVALDOC NUMBER(1,0),
  EXCLUDDISTANTA NUMBER(1,0),
  PECLASE NUMBER(1,0),
  CUMULAT NUMBER(1,0),
  OFFINVOICE NUMBER(1,0),
  NIVEL NUMBER(5,0),
  CLASA NUMBER(20,0),
  TIPINTERVAL NUMBER(10,0),
  PUNCTE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CRITERIIDISC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F5FEB84CC2D1BC185D5C95EA4371FCC643EE591</HASHVAL>
  <TEXT>CREATE TABLE CRITERIIDISC1 (
  CODCRITERIU1 NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  DATASTART DATE,
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CRONOCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48355BC6FD715DA49F63746556461C3DB9F5CFBC</HASHVAL>
  <TEXT>CREATE TABLE CRONOCASHFLOW (
  CODCRONO NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  DATA DATE,
  SOLD NUMBER(20,7),
  PLATI NUMBER(20,7),
  SOLDFINAL NUMBER(20,7),
  INCASARI NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CURSCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78088F503606B514463346D526016C44974E7EA6</HASHVAL>
  <TEXT>CREATE TABLE CURSCASHFLOW (
  CODCURS NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CURSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A6632F4461F6D8DD4C9DF8A4E63E0623AB159EC</HASHVAL>
  <TEXT>CREATE TABLE CURSURI (
  CODCURS NUMBER(20,0) NOT NULL,
  DEN_CURS VARCHAR2(30),
  FORMATOR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CURSURI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8570B146DF4A805F4EAE8E114CC1FF0B42B16F7F</HASHVAL>
  <TEXT>CREATE TABLE CURSURI1 (
  CODCURS1 NUMBER(20,0) NOT NULL,
  CODCURS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>CUSTODIEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>018FFF46252AEE32DAB46BEF457F7CBD38AD7DA7</HASHVAL>
  <TEXT>CREATE TABLE CUSTODIEINI (
  CODCUSTODIE NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D300</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4625ECF2BB70D09C38A054F0DBEEF2111264901E</HASHVAL>
  <TEXT>CREATE TABLE D300 (
  CODD300 NUMBER(20,0) NOT NULL,
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  BIFA_INTERNE NUMBER(1,0),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  OBS VARCHAR2(250),
  CISTVA NUMBER(10,0),
  DENCONTRIB VARCHAR2(200),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(15),
  FAX VARCHAR2(15),
  EMAIL VARCHAR2(200),
  BANCA VARCHAR2(50),
  CONT VARCHAR2(50),
  CAEN VARCHAR2(5),
  TIP_DECONT VARCHAR2(1),
  PRO_RATA NUMBER(7,2),
  BIFA_CEREALE VARCHAR2(1),
  SOLICIT_RAMB VARCHAR2(1),
  NR_EVID VARCHAR2(23),
  V_01_0 NUMBER(15,0),
  V_02_0 NUMBER(15,0),
  V_03_0 NUMBER(15,0),
  V_03_1 NUMBER(15,0),
  V_04_0 NUMBER(15,0),
  V_05_0 NUMBER(15,0),
  T_05_0 NUMBER(15,0),
  V_05_1 NUMBER(15,0),
  T_05_1 NUMBER(15,0),
  V_06_0 NUMBER(15,0),
  T_06_0 NUMBER(15,0),
  V_07_0 NUMBER(15,0),
  T_07_0 NUMBER(15,0),
  V_07_1 NUMBER(15,0),
  T_07_1 NUMBER(15,0),
  V_08_0 NUMBER(15,0),
  T_08_0 NUMBER(15,0),
  V_09_0 NUMBER(15,0),
  T_09_0 NUMBER(15,0),
  V_10_0 NUMBER(15,0),
  T_10_0 NUMBER(15,0),
  V_11_0 NUMBER(15,0),
  T_11_0 NUMBER(15,0),
  V_12_0 NUMBER(15,0),
  T_12_0 NUMBER(15,0),
  V_13_0 NUMBER(15,0),
  V_14_0 NUMBER(15,0),
  V_15_0 NUMBER(15,0),
  V_16_0 NUMBER(15,0),
  T_16_0 NUMBER(15,0),
  V_17_0 NUMBER(15,0),
  T_17_0 NUMBER(15,0),
  V_18_0 NUMBER(15,0),
  T_18_0 NUMBER(15,0),
  V_18_1 NUMBER(15,0),
  T_18_1 NUMBER(15,0),
  V_19_0 NUMBER(15,0),
  T_19_0 NUMBER(15,0),
  V_20_0 NUMBER(15,0),
  T_20_0 NUMBER(15,0),
  V_20_1 NUMBER(15,0),
  T_20_1 NUMBER(15,0),
  V_21_0 NUMBER(15,0),
  T_21_0 NUMBER(15,0),
  V_22_0 NUMBER(15,0),
  T_22_0 NUMBER(15,0),
  V_23_0 NUMBER(15,0),
  T_23_0 NUMBER(15,0),
  V_24_0 NUMBER(15,0),
  T_24_0 NUMBER(15,0),
  V_25_0 NUMBER(15,0),
  T_25_0 NUMBER(15,0),
  V_26_0 NUMBER(15,0),
  V_26_1 NUMBER(15,0),
  V_27_0 NUMBER(15,0),
  T_27_0 NUMBER(15,0),
  T_28_0 NUMBER(15,0),
  T_29_0 NUMBER(15,0),
  V_30_0 NUMBER(15,0),
  T_30_0 NUMBER(15,0),
  T_31_0 NUMBER(15,0),
  T_32_0 NUMBER(15,0),
  T_33_0 NUMBER(15,0),
  T_34_0 NUMBER(15,0),
  T_35_0 NUMBER(15,0),
  T_36_0 NUMBER(15,0),
  T_37_0 NUMBER(15,0),
  T_38_0 NUMBER(15,0),
  T_39_0 NUMBER(15,0),
  T_40_0 NUMBER(15,0),
  T_41_0 NUMBER(15,0),
  T_42_0 NUMBER(15,0),
  NR_FACTURI NUMBER(15,0),
  BAZA NUMBER(15,0),
  TVA NUMBER(15,0),
  V_A NUMBER(15,0),
  T_A NUMBER(15,0),
  V_B NUMBER(15,0),
  T_B NUMBER(15,0),
  TEMEI NUMBER(1,0),
  BIFA_MOB VARCHAR2(1),
  BIFA_DISP VARCHAR2(1),
  BIFA_CONS VARCHAR2(1),
  V_12_1 NUMBER(15,0),
  T_12_1 NUMBER(15,0),
  V_12_2 NUMBER(15,0),
  T_12_2 NUMBER(15,0),
  V_12_3 NUMBER(15,0),
  T_12_3 NUMBER(15,0),
  V_25_1 NUMBER(15,0),
  T_25_1 NUMBER(15,0),
  V_25_2 NUMBER(15,0),
  T_25_2 NUMBER(15,0),
  V_25_3 NUMBER(15,0),
  T_25_3 NUMBER(15,0),
  NR_FACTURI_P NUMBER(15,0),
  BAZA_P NUMBER(15,0),
  TVA_P NUMBER(15,0),
  V_A1 NUMBER(15,0),
  T_A1 NUMBER(15,0),
  V_B1 NUMBER(15,0),
  T_B1 NUMBER(15,0),
  T_43_0 NUMBER(15,0),
  T_44_0 NUMBER(15,0),
  V_64_0 NUMBER(15,0),
  T_64_0 NUMBER(15,0),
  V_65_0 NUMBER(15,0),
  T_65_0 NUMBER(15,0),
  TOT_PRECEDENT NUMBER(15,0),
  TOT_CURENT NUMBER(15,0),
  NR_FACTURI_E NUMBER(15,0),
  BAZA_E NUMBER(15,0),
  TVA_E NUMBER(15,0),
  DEPUSREPREZ NUMBER(1,0),
  V_14_1 NUMBER(15,0),
  V_14_2 NUMBER(15,0),
  ETVA NUMBER(1,0),
  V_09_1 NUMBER(15,0),
  T_09_1 NUMBER(15,0),
  V_10_1 NUMBER(15,0),
  T_10_1 NUMBER(15,0),
  V_11_1 NUMBER(15,0),
  T_11_1 NUMBER(15,0),
  V_12_4 NUMBER(15,0),
  T_12_4 NUMBER(15,0),
  V_12_5 NUMBER(15,0),
  T_12_5 NUMBER(15,0),
  V_22_1 NUMBER(15,0),
  T_22_1 NUMBER(15,0),
  V_23_1 NUMBER(15,0),
  T_23_1 NUMBER(15,0),
  V_25_4 NUMBER(15,0),
  T_25_4 NUMBER(15,0),
  V_25_5 NUMBER(15,0),
  T_25_5 NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D390</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9FE3570374A8B3581EA179D2BEEB2711B9204C8</HASHVAL>
  <TEXT>CREATE TABLE D390 (
  CODD390 NUMBER(20,0) NOT NULL,
  TIPD390 NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CISTVA VARCHAR2(15),
  DENCONTRIB VARCHAR2(100),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(30),
  FAX VARCHAR2(30),
  EMAIL VARCHAR2(80),
  NRTOTOP NUMBER(20,0),
  BAZAL NUMBER(20,7),
  BAZAT NUMBER(20,7),
  BAZAA NUMBER(20,7),
  BAZAP NUMBER(20,7),
  BAZAS NUMBER(20,7),
  TOTALBAZA NUMBER(20,7),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  OBS VARCHAR2(450),
  NRFIRMECDS NUMBER(20,0),
  BAZAR NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D390CA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>437582C711150E0B31412DFBF3B0DC580E070DC9</HASHVAL>
  <TEXT>CREATE TABLE D390CA (
  CODD390CA NUMBER(20,0) NOT NULL,
  CODD390 NUMBER(20,0),
  TARA_M1 VARCHAR2(2),
  COD_M1 VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D390CB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBCCCF0A3D9217F7A443243EE101D0120407C75D</HASHVAL>
  <TEXT>CREATE TABLE D390CB (
  CODD390CB NUMBER(20,0) NOT NULL,
  CODD390 NUMBER(20,0),
  TARA_M1 VARCHAR2(2),
  COD_M1 VARCHAR2(15),
  MOTIV NUMBER(2,0),
  TARA_M2 VARCHAR2(2),
  COD_M2 VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D390D</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5505349F2BB22750E88002933585FEC6A570CA8C</HASHVAL>
  <TEXT>CREATE TABLE D390D (
  CODD390D NUMBER(20,0) NOT NULL,
  CODD390O NUMBER(20,0),
  CODD390 NUMBER(20,0),
  IDXFIRMA NUMBER(20,0),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  DOC VARCHAR2(50),
  MONEDADOC VARCHAR2(50),
  TIP VARCHAR2(1),
  BAZAVAL NUMBER(20,7),
  CURS NUMBER(20,7),
  BAZALEI NUMBER(20,7),
  OBS VARCHAR2(500),
  STERS NUMBER(1,0),
  CAZSPECIAL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D390O</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FBC66EE5F8E66C5FF283990FB2BB724F2865FDE</HASHVAL>
  <TEXT>CREATE TABLE D390O (
  CODD390O NUMBER(20,0) NOT NULL,
  CODD390 NUMBER(20,0),
  TIP VARCHAR2(1),
  TARA VARCHAR2(2),
  CODO VARCHAR2(15),
  DENO VARCHAR2(100),
  BAZA NUMBER(20,7),
  OBS VARCHAR2(500),
  CAZSPECIAL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3399C6EF47D19C855B6DBBFA4B2B77D0281E552C</HASHVAL>
  <TEXT>CREATE TABLE D394 (
  CODD394 NUMBER(20,0) NOT NULL,
  TIPD394 VARCHAR2(1),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CISTVA VARCHAR2(15),
  DENCONTRIB VARCHAR2(100),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(30),
  FAX VARCHAR2(30),
  EMAIL VARCHAR2(80),
  CIFREPRFISC VARCHAR2(15),
  DENREPRFISC VARCHAR2(100),
  DOMFISCREPRFISC VARCHAR2(1000),
  TELREPRFISC VARCHAR2(30),
  FAXREPRFISC VARCHAR2(30),
  EMAILREPRFISC VARCHAR2(80),
  NRTOTFB NUMBER(20,0),
  BAZALIVR NUMBER(20,7),
  TVALIVR NUMBER(20,7),
  BAZAACHIZ NUMBER(20,7),
  TVAACHIZ NUMBER(20,7),
  BAZAV NUMBER(20,7),
  TVAV NUMBER(20,7),
  BAZAVC NUMBER(20,7),
  TVAVC NUMBER(20,7),
  BAZAC NUMBER(20,7),
  TVAC NUMBER(20,7),
  BAZACC NUMBER(20,7),
  TVACC NUMBER(20,7),
  SUMACONTROL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  CENTRALIZAT NUMBER(1,0),
  TIP NUMBER(1,0),
  SEMESTRU VARCHAR2(2),
  OBS VARCHAR2(250),
  NRFACTL NUMBER(15,0),
  NRFACTA NUMBER(15,0),
  NRFACTV NUMBER(15,0),
  NRFACTC NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A61237CC562495DB064D0A30B4AE777AF0746A75</HASHVAL>
  <TEXT>CREATE TABLE D39416 (
  CODD39416 NUMBER(20,0) NOT NULL,
  SUBUNITATEA NUMBER(20,0),
  TIPD VARCHAR2(1),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CUI VARCHAR2(50),
  DEN VARCHAR2(100),
  CAEN VARCHAR2(5),
  ADRESA VARCHAR2(160),
  TELEFON VARCHAR2(15),
  FAX VARCHAR2(15),
  EMAIL VARCHAR2(80),
  CIFR VARCHAR2(13),
  DENR VARCHAR2(100),
  ADRESAR VARCHAR2(160),
  TELEFONR VARCHAR2(15),
  FAXR VARCHAR2(15),
  EMAILR VARCHAR2(80),
  CALITATER VARCHAR2(50),
  TIPI NUMBER(1,0),
  DENI VARCHAR2(100),
  CODI VARCHAR2(13),
  FUNCTIEI VARCHAR2(35),
  CALITATEI VARCHAR2(50),
  TVAINCAS NUMBER(1,0),
  OPEFECTUATE NUMBER(1,0),
  ACORDACCESP NUMBER(1,0),
  ACORDACCESC NUMBER(1,0),
  SUMACONTROL NUMBER(20,0),
  RPNO NUMBER(20,0),
  RNNO NUMBER(20,0),
  UENO NUMBER(20,0),
  NONUENO NUMBER(20,0),
  OPEFCFGEN NUMBER(1,0),
  DATAXMLVALID DATE,
  OBS VARCHAR2(200),
  NEREZIDENT NUMBER(1,0),
  PRSAFILIAT NUMBER(1,0),
  EDITMANUAL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416G</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>009A748EEC5171754054B343E3E47C973E043AF1</HASHVAL>
  <TEXT>CREATE TABLE D39416G (
  CODD39416G NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  BF NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416G1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9234646D96D959BB05DEE984F2EBE7AF46709838</HASHVAL>
  <TEXT>CREATE TABLE D39416G1 (
  CODD39416G1 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,0),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416G2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF311176AD2ED0F17C3F35850537972775029CEA</HASHVAL>
  <TEXT>CREATE TABLE D39416G2 (
  CODD39416G2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  LUNA NUMBER(2,0),
  NRAMEF NUMBER(20,0),
  BF NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416G3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3082BE5E7E89A7C9A716A14EF4A0F2746A39C2D1</HASHVAL>
  <TEXT>CREATE TABLE D39416G3 (
  CODD39416G3 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  LUNA NUMBER(2,0),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,0),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CACE0A2351D56C2CEAF6662B049E1E28A22B4DCC</HASHVAL>
  <TEXT>CREATE TABLE D39416I (
  CODD39416I NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TOTALFACT NUMBER(20,0),
  TOTALFACTBEN NUMBER(20,0),
  TOTALFACTTERTI NUMBER(20,0),
  SOLICIT NUMBER(20,0),
  ACHIZPE NUMBER(20,0),
  ACHIZCR NUMBER(20,0),
  ACHIZCB NUMBER(20,0),
  ACHIZCI NUMBER(20,0),
  ACHIZA NUMBER(20,0),
  ACHIZB24 NUMBER(20,0),
  ACHIZB20 NUMBER(20,0),
  ACHIZB19 NUMBER(20,0),
  ACHIZB9 NUMBER(20,0),
  ACHIZB5 NUMBER(20,0),
  ACHIZS24 NUMBER(20,0),
  ACHIZS20 NUMBER(20,0),
  ACHIZS19 NUMBER(20,0),
  ACHIZS9 NUMBER(20,0),
  ACHIZS5 NUMBER(20,0),
  IMPORTB NUMBER(20,0),
  ACINECORP NUMBER(20,0),
  LIVRARIBI NUMBER(20,0),
  LIVRARIB24 NUMBER(20,0),
  LIVRARIB20 NUMBER(20,0),
  LIVRARIB19 NUMBER(20,0),
  LIVRARIB9 NUMBER(20,0),
  LIVRARIB5 NUMBER(20,0),
  LIVRARIB0 NUMBER(20,0),
  LIVRARITI NUMBER(20,0),
  PREST24 NUMBER(20,0),
  PREST20 NUMBER(20,0),
  PREST19 NUMBER(20,0),
  PREST9 NUMBER(20,0),
  PREST5 NUMBER(20,0),
  PREST0 NUMBER(20,0),
  LIVRARIUE NUMBER(20,0),
  PRESTUE NUMBER(20,0),
  EXPORT NUMBER(20,0),
  LIVINECORP NUMBER(20,0),
  EFECTUAT NUMBER(20,0),
  ACHIZB21 NUMBER(20,0),
  ACHIZB11 NUMBER(20,0),
  ACHIZS21 NUMBER(20,0),
  ACHIZS11 NUMBER(20,0),
  LIVRARIB21 NUMBER(20,0),
  LIVRARIB11 NUMBER(20,0),
  PREST21 NUMBER(20,0),
  PREST11 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98430DD208BCB72DCF6E0BDAFEBAE450B2C41D5F</HASHVAL>
  <TEXT>CREATE TABLE D39416I1 (
  CODD39416I1 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  BAZAFSLCOD NUMBER(20,7),
  TVAFSLCOD NUMBER(20,7),
  BAZAFSL NUMBER(20,7),
  TVAFSL NUMBER(20,7),
  BAZAFSA NUMBER(20,7),
  TVAFSA NUMBER(20,7),
  BAZAFSAI NUMBER(20,7),
  TVAFSAI NUMBER(20,7),
  BAZABFAI NUMBER(20,7),
  TVABFAI NUMBER(20,7),
  TVADED NUMBER(20,7),
  TVADEDI NUMBER(20,7),
  TVACOL NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53256BFA5E86B3589D652312AD058E6CB5ABAFEB</HASHVAL>
  <TEXT>CREATE TABLE D39416I2 (
  CODD39416I2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  NUMARF NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I2A</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BA5D5A3DB364D195A361A0B47BFEAD709029DD4</HASHVAL>
  <TEXT>CREATE TABLE D39416I2A (
  CODD39416I2A NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  NUMARF NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEDEA94E675A96D9A5195E179EFDB479EFD386C9</HASHVAL>
  <TEXT>CREATE TABLE D39416I3 (
  CODD39416I3 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPFACTURA NUMBER(20,0),
  SERIEF VARCHAR2(20),
  NUMARF NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416I4</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15299820D8E8613D7291267469E958E37A20D90D</HASHVAL>
  <TEXT>CREATE TABLE D39416I4 (
  CODD39416I4 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  CAEN VARCHAR2(5),
  TIPOPER NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416N</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A80D840751C92DEF888EE18CA2D6EC1D08D7FE2</HASHVAL>
  <TEXT>CREATE TABLE D39416N (
  CODD39416N NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416NS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FFA29E02DD7BD4614B0812B6755D1C7ED458079</HASHVAL>
  <TEXT>CREATE TABLE D39416NS2 (
  CODD39416NS2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416R</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DBCB889F1A1A86857EB0DA05BEFAF004972FE8E0</HASHVAL>
  <TEXT>CREATE TABLE D39416R (
  CODD39416R NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  LIVRARIF NUMBER(20,0),
  LIVRARIB NUMBER(20,7),
  LIVRARITVA NUMBER(20,7),
  ACHIZF NUMBER(20,0),
  ACHIZB NUMBER(20,7),
  ACHIZTVA NUMBER(20,7),
  ACHIZIF NUMBER(20,0),
  ACHIZIB NUMBER(20,7),
  ACHIZITVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA2D862C6DE325B6D5BD91AF8DCAF8035FC2A7DD</HASHVAL>
  <TEXT>CREATE TABLE D39416RN (
  CODD39416RN NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RN0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6EC639F680C11B4A6F8ECC56A5AC50E9946806C0</HASHVAL>
  <TEXT>CREATE TABLE D39416RN0 (
  CODD39416RN0 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  L_PF_F NUMBER(20,0),
  L_PF_BI24 NUMBER(20,7),
  L_PF_TVA24 NUMBER(20,7),
  L_PF_BI20 NUMBER(20,7),
  L_PF_TVA20 NUMBER(20,7),
  L_PF_BI19 NUMBER(20,7),
  L_PF_TVA19 NUMBER(20,7),
  L_PF_BI9 NUMBER(20,7),
  L_PF_TVA9 NUMBER(20,7),
  L_PF_BI5 NUMBER(20,7),
  L_PF_TVA5 NUMBER(20,7),
  LS_PF_F NUMBER(20,0),
  LS_PF_VAL NUMBER(20,7),
  L_PF_BI21 NUMBER(20,7),
  L_PF_TVA21 NUMBER(20,7),
  L_PF_BI11 NUMBER(20,7),
  L_PF_TVA11 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D27D7B8CF88D637B43AD8CBC0484787DDF96FFCA</HASHVAL>
  <TEXT>CREATE TABLE D39416RN1 (
  CODD39416RN1 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CATEGTXINV NUMBER(20,0),
  F NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RNS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADE371F2F2EFC7100CBA32A8121118AB0B1B44FB</HASHVAL>
  <TEXT>CREATE TABLE D39416RNS2 (
  CODD39416RNS2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  STRP VARCHAR2(75),
  NRP VARCHAR2(15),
  BLP VARCHAR2(30),
  APP VARCHAR2(10),
  TIPDOC NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7),
  DETP VARCHAR2(100),
  CUIVALID NUMBER(1,0),
  LOCP VARCHAR2(50),
  JUDP VARCHAR2(2),
  TARAP VARCHAR2(3),
  SAJUDP VARCHAR2(2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RNS3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FE2702A700D14AC5C625F35AC2924FAF7D114AC7</HASHVAL>
  <TEXT>CREATE TABLE D39416RNS3 (
  CODD39416RNS3 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  CODD39416RN1 NUMBER(20,0),
  CODD39416RNS2 NUMBER(20,0),
  F NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODD394 VARCHAR2(8)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>871E3E41DB2E753019C9B435FDD36D80A69E8AED</HASHVAL>
  <TEXT>CREATE TABLE D39416RP (
  CODD39416RP NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5694E248B69AFD8A295735626918798AB662FAA</HASHVAL>
  <TEXT>CREATE TABLE D39416RP1 (
  CODD39416RP1 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CATEGTXINV NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RPS2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F292CC8FD8747084C508F4579669C57D6BB04C73</HASHVAL>
  <TEXT>CREATE TABLE D39416RPS2 (
  CODD39416RPS2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7),
  CUIVALID NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416RPS3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>70517FD99A8AD568F2BB0E1365C303B47773AA2D</HASHVAL>
  <TEXT>CREATE TABLE D39416RPS3 (
  CODD39416RPS3 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  CATEGTXINV NUMBER(20,0),
  CODD394 VARCHAR2(8),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416UE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA8EB0F591EB0A28995B6E4CFF3E97A87F366CDD</HASHVAL>
  <TEXT>CREATE TABLE D39416UE (
  CODD39416UE NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416UES2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30FA9832BEF93CC703B78572DE8216F4FB82390B</HASHVAL>
  <TEXT>CREATE TABLE D39416UES2 (
  CODD39416UES2 NUMBER(20,0) NOT NULL,
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D39416_ANAF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>657C581FDB8EDC03610DC80EF22B89F6EE9189DF</HASHVAL>
  <TEXT>CREATE TABLE D39416_ANAF (
  CUI NUMBER(20,0) NOT NULL,
  DATA DATE NOT NULL,
  CONTRIBUABIL NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394A</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89D0FD29E38E24BB8E9AF5A7FB8FD877872FDEBE</HASHVAL>
  <TEXT>CREATE TABLE D394A (
  CODD394A NUMBER(20,0) NOT NULL,
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(15),
  DENBFP VARCHAR2(100),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(20),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394C</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>092DFBEB7688A165059E2880CDF991D93E342687</HASHVAL>
  <TEXT>CREATE TABLE D394C (
  CODD394C NUMBER(20,0) NOT NULL,
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(15),
  DENBFP VARCHAR2(200),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(20),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394CC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9B19B33E4897CABC4FAD5A6DED5C6EB6B7EAEE4</HASHVAL>
  <TEXT>CREATE TABLE D394CC (
  CODD394CC NUMBER(20,0) NOT NULL,
  CODD394C NUMBER(20,0),
  DENPRODUS VARCHAR2(200),
  CODNC VARCHAR2(8),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  CODSURSA1 NUMBER(20,0),
  OBS VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394L</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C021AD3002AEC95AD298B45118D1D029E2DFB453</HASHVAL>
  <TEXT>CREATE TABLE D394L (
  CODD394L NUMBER(20,0) NOT NULL,
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(15),
  DENBFP VARCHAR2(100),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(20),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394V</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1727352EC72A7D26550E68B2D4970E0E8A321DA2</HASHVAL>
  <TEXT>CREATE TABLE D394V (
  CODD394V NUMBER(20,0) NOT NULL,
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(15),
  DENBFP VARCHAR2(200),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(20),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>D394VC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53031EF6352F047B9FAA23EB7B8291013F6998E1</HASHVAL>
  <TEXT>CREATE TABLE D394VC (
  CODD394VC NUMBER(20,0) NOT NULL,
  CODD394V NUMBER(20,0),
  DENPRODUS VARCHAR2(200),
  CODNC VARCHAR2(8),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  CODSURSA1 NUMBER(20,0),
  OBS VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DATAWAREHOUSE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECE77AC2CF9F0142F4118BD97548F4E865028B2A</HASHVAL>
  <TEXT>CREATE TABLE DATAWAREHOUSE (
  COD NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  TABLA VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  SKEMAFIRMA VARCHAR2(100),
  LISTANAME VARCHAR2(1000),
  DATAGEN DATE,
  TABLE_TYPE NUMBER(1,0),
  DEPONAME VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DEBUG_LISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFA713D9A572031FF3B7274DB3F2653AF3E0AF92</HASHVAL>
  <TEXT>CREATE TABLE DEBUG_LISTE (
  USERID NUMBER(20,0),
  SQL_LISTA CLOB,
  LISTID NUMBER(20,0),
  LISTVER NUMBER(20,0),
  SQL_TIME TIMESTAMP(6),
  SQL_ERR CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DEP_STATUS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2560F2287419B40D2EEC8E18DC994D9541A2800</HASHVAL>
  <TEXT>CREATE TABLE DEP_STATUS (
  ACTIV NUMBER(1,0),
  AL NUMBER(5,0),
  DATADEP DATE,
  HASHVAL VARCHAR2(64),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DEP_TABLES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A26A4E4014F13BC3DE86EEC698B99087C64EE6AD</HASHVAL>
  <TEXT>CREATE TABLE DEP_TABLES (
  TABNAME VARCHAR2(50),
  SEL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D5FD8DD97E78F381F6BE53B0887898EC6B9C2F5</HASHVAL>
  <TEXT>CREATE TABLE DESCRIPTORI (
  CODDESCRIPTOR NUMBER(20,0) NOT NULL,
  DEN_DESCRIPTOR VARCHAR2(50),
  SIMBOL VARCHAR2(10),
  TIP NUMBER(30,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DESCRIPTORI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B905282581DDDD0F8060DE4EBE8665791459B4C9</HASHVAL>
  <TEXT>CREATE TABLE DESCRIPTORI1 (
  CODDESCRIPTOR1 NUMBER(20,0) NOT NULL,
  CODDESCRIPTOR NUMBER(20,0),
  VALOARE VARCHAR2(50),
  CODASOCIAT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DESTINATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23BECE0A2C6BF31F7FAB8D51CDF14BE5E4E8C1ED</HASHVAL>
  <TEXT>CREATE TABLE DESTINATII (
  CODDESTINATIE NUMBER(20,0),
  NUMEDESTINATIE VARCHAR2(200),
  PENTRU VARCHAR2(200),
  SEZON VARCHAR2(200),
  ARTICOL VARCHAR2(200),
  ACTIVITATE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DETAILMAK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16433B747F920E4E3031E5E0A2FD8A66561E45D7</HASHVAL>
  <TEXT>CREATE TABLE DETAILMAK (
  CODDETAILMAK NUMBER(20,0) NOT NULL,
  CODMASTERMAK NUMBER(20,0),
  CODDOC NUMBER(20,0),
  COD1 NUMBER(20,0),
  COD2 NUMBER(20,0),
  COD3 NUMBER(20,0),
  COD4 NUMBER(20,0),
  COD5 NUMBER(20,0),
  V1 NUMBER(20,7),
  V2 NUMBER(20,7),
  V3 NUMBER(20,7),
  V4 NUMBER(20,7),
  V5 NUMBER(20,7),
  DATA1 DATE,
  DATA2 DATE,
  OBS1 VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DETALIIET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1088AED870F8543C747429941EE0E94B8FCA8FB</HASHVAL>
  <TEXT>CREATE TABLE DETALIIET (
  CODDETALIU NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODLOCINC NUMBER(20,0),
  ADRESAINC VARCHAR2(150),
  DATATRANSPORT DATE,
  CODLOCDESC NUMBER(20,0),
  ADRESADESC VARCHAR2(150),
  CODPTF NUMBER(20,0),
  CODBV NUMBER(20,0),
  CODPARTTR NUMBER(20,0),
  NRAUTO VARCHAR2(15),
  NRREMORCA1 VARCHAR2(15),
  NRREMORCA2 VARCHAR2(15),
  CODPARTRETAILTR NUMBER(20,0),
  GREUTATE_BRUTA NUMBER(10,2),
  TIPLOCINC NUMBER(5,0),
  TIPLOCDESC NUMBER(5,0),
  CODPTFDESC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DETALIIET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9A2E5945D2B7582B32E1E28B8FCCE0E59F1C90D</HASHVAL>
  <TEXT>CREATE TABLE DETALIIET1 (
  CODDETALIUET1 NUMBER(20,0) NOT NULL,
  CODDETALIUET NUMBER(20,0),
  DATATRANSPORT TIMESTAMP(6),
  NRAUTO VARCHAR2(15),
  NRREMORCA1 VARCHAR2(15),
  NRREMORCA2 VARCHAR2(15),
  OBS VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DEZASAMBLARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6887DA62907DC5FD51D53C5B8FC9500C1B90AF0</HASHVAL>
  <TEXT>CREATE TABLE DEZASAMBLARI (
  CODLIVR1 NUMBER(20,0) NOT NULL,
  CODNIRSTOC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  INCHISA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DEZASAMBLARI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5552FE96D1B14EE95315C56A33D6DF5AB6A9C70</HASHVAL>
  <TEXT>CREATE TABLE DEZASAMBLARI1 (
  CODINTRLINK NUMBER(20,0) NOT NULL,
  CODLIVR1 NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DFLANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9902ABBD2AA634B83A954FE3EDCC9F956C9D6E58</HASHVAL>
  <TEXT>CREATE TABLE DFLANSZ1 (
  CODLANSZ NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  AN NUMBER(4,0),
  SAPTAMANA NUMBER(2,0),
  DIRTY NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIFERENTE_BALANTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AE4B57012B738732E5DE836B9238C4F79EB65B82</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE DIFERENTE_BALANTA (
  SIMBOL VARCHAR2(100),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  NOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIFERENTE_JURNAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1D74C997546FF188E5F44BCB729369A5889B49DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE DIFERENTE_JURNAL (
  SIMBOLD VARCHAR2(100),
  SIMBOLC VARCHAR2(100),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  GEST VARCHAR2(200),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  SUBUNITATEA VARCHAR2(200),
  DATADOC DATE,
  DOCUMENT VARCHAR2(30),
  NOU NUMBER(1,0),
  VALOAREGRUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIFICULTATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77CCA327DD3C37CDB7E9EC293B1E92AF2BB53161</HASHVAL>
  <TEXT>CREATE TABLE DIFICULTATI (
  CODDIF NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(150)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIFPRETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBD18A1131A87E1B9468FDCA93A0B49247CFA7F1</HASHVAL>
  <TEXT>CREATE TABLE DIFPRETPROD (
  CODDIFPRETPROD NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  OPERAT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIFPRETPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4391D8C4AF9C77D30EEE40FDFBC07DB86C5C5E33</HASHVAL>
  <TEXT>CREATE TABLE DIFPRETPROD1 (
  CODDIFPRETPROD1 NUMBER(20,0) NOT NULL,
  CODDIFPRETPROD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  ANLUNA NUMBER(5,0),
  DIFPRET NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DIRTY NUMBER(1,0),
  CURENT NUMBER(1,0),
  INTRARI NUMBER(20,7),
  IESIRI NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49B0C2158E839736252094035CBCD79228282618</HASHVAL>
  <TEXT>CREATE TABLE DINTRASTAT (
  CODDINTRASTAT NUMBER(20,0) NOT NULL,
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  TIPA NUMBER(1,0),
  TIPD NUMBER(1,0),
  VATNR VARCHAR2(30),
  FIRMNAME VARCHAR2(100),
  CPLASTNAME VARCHAR2(200),
  CPFIRSTNAME VARCHAR2(200),
  CPPOSITION VARCHAR2(50),
  CPPHONE VARCHAR2(15),
  CPFAX VARCHAR2(15),
  CPEMAIL VARCHAR2(80),
  DTP NUMBER(1,0),
  DTPVATNR VARCHAR2(30),
  DTPFIRMNAME VARCHAR2(100),
  DTPSTREET VARCHAR2(100),
  DTPSTREETNUMBER VARCHAR2(15),
  DTPBLOCK VARCHAR2(5),
  DTPSTAIRS VARCHAR2(5),
  DTPAPARTMENT VARCHAR2(10),
  DTPCODLOCALIT NUMBER(20,0),
  DTPPOSTALCODE VARCHAR2(10),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DINTRASTATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FEBA160E8CA9A67AF7E39935B8C0C69A94794D6</HASHVAL>
  <TEXT>CREATE TABLE DINTRASTATA (
  CODDINTRASTATA NUMBER(20,0) NOT NULL,
  CODDINTRASTAT NUMBER(20,0),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,0),
  STATISTICALVALUE NUMBER(20,0),
  NETMASS NUMBER(20,0),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(3),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,0),
  COUNTRYOFCONSIGNMENT VARCHAR2(3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DINTRASTATD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16EC5823C610E8B714FFAE939995CF7D8A3940B2</HASHVAL>
  <TEXT>CREATE TABLE DINTRASTATD (
  CODDINTRASTATD NUMBER(20,0) NOT NULL,
  CODDINTRASTAT NUMBER(20,0),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,0),
  STATISTICALVALUE NUMBER(20,0),
  NETMASS NUMBER(20,0),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(3),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,0),
  COUNTRYOFDESTINATION VARCHAR2(3),
  PARTNERCOUNTRYCODE VARCHAR2(3),
  PARTNERVATNR VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIRTYJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6C7185C0C48A1E3B0584D1EC0D3D9AAEC11782F</HASHVAL>
  <TEXT>CREATE TABLE DIRTYJURNAL (
  ANLUNA NUMBER(5,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CC626562D0BE9FB4F69A32A7FCD95D37B173219</HASHVAL>
  <TEXT>CREATE TABLE DISCART (
  CODDISCART NUMBER(20,0) NOT NULL,
  CODDISCOUNT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  GRUPA VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCEXCEPTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D26E1077C2A83D3C1E880738B891FAC1D8E56321</HASHVAL>
  <TEXT>CREATE TABLE DISCEXCEPTII (
  CODDISCEXCEPTIE NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCINTERVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C66FE2F716B7356151C81854095594612D9FB8DC</HASHVAL>
  <TEXT>CREATE TABLE DISCINTERVAL (
  CODDISCINTERVAL NUMBER(20,0) NOT NULL,
  CODDISCOUNT NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCMONETAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0E0C61F5389EC4AA57EC18CE403A76995E3E3B0</HASHVAL>
  <TEXT>CREATE TABLE DISCMONETAR (
  CODDISCMONETAR NUMBER(20,0),
  CODIES NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCOUNT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A9AF4BE2E3AAC005F6D6A1855CC59E4192BFD01</HASHVAL>
  <TEXT>CREATE TABLE DISCOUNT (
  CODDISCOUNT NUMBER(20,0) NOT NULL,
  CODCRITERIU NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  CODCRITERIU1 NUMBER(20,0),
  CODTIPSEDIU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISCPROMORETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BDF9799095590E6BC23D80A35B9DF1E00A5293A0</HASHVAL>
  <TEXT>CREATE TABLE DISCPROMORETAIL (
  COD NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DISCPROMO NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ACD37722904C9F16D9327CDB248C1B2D57DCCA49</HASHVAL>
  <TEXT>CREATE TABLE DISTANTA (
  CODDISTANTA NUMBER(20,0) NOT NULL,
  CODGEST_START NUMBER(20,0),
  CODGEST_STOP NUMBER(20,0),
  CODLOCALIT_START NUMBER(20,0),
  CODLOCALIT_STOP NUMBER(20,0),
  KM NUMBER(20,0),
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(22,2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69D8DCDF71242BA27CCDDCB5E35A864599B16FF8</HASHVAL>
  <TEXT>CREATE TABLE DISTRIB (
  CODDISTRIB NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  ZI NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0DEA1B9CCF246A9BD4318B4E4066EE0C5EA0BAFD</HASHVAL>
  <TEXT>CREATE TABLE DISTRIB1 (
  CODDISTRIB1 NUMBER(20,0) NOT NULL,
  CODDISTRIB NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CODTRASEU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIB2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3A9DEF6CEA767EF54E2F2515FDDA352E7F373AF</HASHVAL>
  <TEXT>CREATE TABLE DISTRIB2 (
  CODDISTRIB2 NUMBER(20,0) NOT NULL,
  CODDISTRIB NUMBER(20,0),
  CODDISTRIB1 NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  SOLD NUMBER(20,7),
  POZTRASEU NUMBER(20,0),
  DEN_PART VARCHAR2(50),
  OBS VARCHAR2(30),
  ADRESA VARCHAR2(200),
  DEN_JUDET VARCHAR2(30),
  DEN_LOCALIT VARCHAR2(50),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIB3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71A34AE0B6CF515B97C75B113BE436215BDE1E22</HASHVAL>
  <TEXT>CREATE TABLE DISTRIB3 (
  CODDISTRIB3 NUMBER(20,0) NOT NULL,
  CODDISTRIB NUMBER(20,0),
  CODDISTRIB1 NUMBER(20,0),
  CODDISTRIB2 NUMBER(20,0),
  DOC VARCHAR2(100),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  VALREAL NUMBER(20,7),
  RESTREAL NUMBER(20,7),
  TERMEN DATE,
  ZILESCADENTE NUMBER(10,0),
  SIMBOLCONT VARCHAR2(100),
  DEN_SUBUNIT VARCHAR2(150),
  PREFIXDOC VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIBCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4F4AE9EEF3B45F9765D2B6FFF1D23B3BDC1233A</HASHVAL>
  <TEXT>CREATE TABLE DISTRIBCHELT (
  CODDISTRIBCHELT NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(2,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  FAZA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  COEFPROD NUMBER(20,7),
  CODCENTRU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIBCHELT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2947D086C9BDCDE24C8D22E8BF65B4F2DDF5342D</HASHVAL>
  <TEXT>CREATE TABLE DISTRIBCHELT1 (
  CODDISTRIBCHELT1 NUMBER(20,0) NOT NULL,
  CODDISTRIBCHELT NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DISTRIBCHELT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B090BE1853BD9AC7A50FA41A7AD4A20A69C4E003</HASHVAL>
  <TEXT>CREATE TABLE DISTRIBCHELT2 (
  CODDISTRIBCHELT2 NUMBER(20,0) NOT NULL,
  CODDISTRIBCHELT1 NUMBER(20,0),
  CODDISTRIBCHELT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(50),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DIVERSE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A85D3028E5AEBFCB35A08CD780C484047A2E2B7E</HASHVAL>
  <TEXT>CREATE TABLE DIVERSE (
  TIP NUMBER(3,0),
  COD NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPDOC NUMBER(3,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81DC2EA67ADA6E702E582AF7A7724934DDB69DBB</HASHVAL>
  <TEXT>CREATE TABLE DOCASOC (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOCASOC NUMBER(20,0),
  TIPDOCASOC NUMBER(20,0),
  OBS VARCHAR2(400)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCCARNETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC62F3588B953BA00BFFE4BFABAB05ADDF564657</HASHVAL>
  <TEXT>CREATE TABLE DOCCARNETE (
  CODCARNET NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(10),
  DENUMIRE VARCHAR2(50),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  FREENR NUMBER(20,0),
  INACTIV NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  LIMITA NUMBER(20,0),
  STARTNRINI NUMBER(20,0),
  DEDICAT NUMBER(1,0),
  COMENZIONLINE NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  FARASALVARE NUMBER(1,0),
  IN_UPDATE NUMBER(1,0),
  ALLSUBUNIT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCEDITAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C10A04C08A761AECCA24E96262A4E7D3CE0E4A9B</HASHVAL>
  <TEXT>CREATE TABLE DOCEDITAT (
  CODDOCEDITAT NUMBER(20,0),
  CODDOC NUMBER(10,0),
  TABELA VARCHAR2(30),
  USERID NUMBER
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCEXTRA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F1050D8F9171728C2C959426CEC285525487016</HASHVAL>
  <TEXT>CREATE TABLE DOCEXTRA (
  TIPDOC NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0) NOT NULL,
  EXPORT_EDI NUMBER(1,0),
  EXPORT_EDI_DATA TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCFREE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EDE9CB3ACC699C664E5287A3801CF05524610D8</HASHVAL>
  <TEXT>CREATE TABLE DOCFREE (
  CODDOCFREE NUMBER(20,0) NOT NULL,
  CODCARNET NUMBER(20,0),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCFREEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22ECC24A7BBECDCB375AE7D70D8D061AA4440AA6</HASHVAL>
  <TEXT>CREATE TABLE DOCFREEX (
  STARTNR NUMBER(20,0) NOT NULL,
  ENDNR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A183AC673821DC982B155B8E56CAF535450EA56</HASHVAL>
  <TEXT>CREATE TABLE DOCLINK (
  CODDOCLINK NUMBER(20,0) NOT NULL,
  CODCARNET NUMBER(20,0),
  CODMACHETA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31B035D056BD37A5E7A6EBB85B6978DD4D806803</HASHVAL>
  <TEXT>CREATE TABLE DOCLOCK (
  CODDOCLOCK NUMBER(20,0) NOT NULL,
  CODCARNET NUMBER(20,0),
  USEDNO NUMBER(20,0),
  USERID NUMBER(20,0),
  CONNINDEX NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCSUPLIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D453E7086A6778DC67C0A6B57968F2FA8FF1F024</HASHVAL>
  <TEXT>CREATE TABLE DOCSUPLIM (
  CODDOCSUPLIM NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(2,0),
  DENDOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCSUPLIM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B5135486876BF11C333767CAA3C57F399A963A4</HASHVAL>
  <TEXT>CREATE TABLE DOCSUPLIM1 (
  CODDOCSUPLIM1 NUMBER(20,0) NOT NULL,
  CODDOCSUPLIM NUMBER(20,0),
  DENLINIE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCUMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EA963A29D335C84FC719334A6131145ACDC002E</HASHVAL>
  <TEXT>CREATE TABLE DOCUMENTE (
  CODDOCUMENT NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  FILENAME VARCHAR2(200),
  DOC BLOB,
  OBS VARCHAR2(4000),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODDOSAR NUMBER(20,0),
  CODDEPOZIT NUMBER(20,0),
  TIPDOCUMENT NUMBER(2,0),
  EXPEFACT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOCUSERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C73C4CF2B2735B8A62FC412D5DEBFF36564062D</HASHVAL>
  <TEXT>CREATE TABLE DOCUSERS (
  CODDOCUSERS NUMBER(20,0) NOT NULL,
  CODCARNET NUMBER(20,0),
  CODUSER NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOMENIIACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F85B350ACF4CD9B6410350DBCD5C6CFF8977B55C</HASHVAL>
  <TEXT>CREATE TABLE DOMENIIACT (
  CODDOMENIUACT NUMBER(20,0) NOT NULL,
  DENDOMENIUACT VARCHAR2(160),
  CODCAEN VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DOSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>105FA74945CB01F89FCC6DDFFF147518D912265D</HASHVAL>
  <TEXT>CREATE TABLE DOSARE (
  CODDOSAR NUMBER(6,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  DULAP VARCHAR2(20),
  RAFT VARCHAR2(20),
  TIP NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DPROFIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE08BAE1C789CE7C433436EE94AF59C02BB19C7D</HASHVAL>
  <TEXT>CREATE TABLE DPROFIT (
  CODDPROFIT NUMBER(20,0) NOT NULL,
  TIPPROFIT NUMBER(5,0),
  TIPAN NUMBER(5,0),
  ELEMSIMVENIT NUMBER(20,7),
  ELEMSIMCHELT NUMBER(20,7),
  DEDUCERI NUMBER(20,7),
  DEDREZLEG NUMBER(20,7),
  DEDPROFITR NUMBER(20,7),
  DEDALTE NUMBER(20,7),
  CHELTAFVENIT NUMBER(20,7),
  CHELTPRADM NUMBER(20,7),
  CHELTPRNEDED NUMBER(20,7),
  PIERDERE NUMBER(20,7),
  PROFITCONTA NUMBER(20,7),
  PROFITIMPOZ NUMBER(20,7),
  SUMAMAX NUMBER(20,7),
  CHELTSPONSOR NUMBER(20,7),
  IMPOZITPROFIT NUMBER(20,7),
  IMPOZITPROFITD NUMBER(20,7),
  AN NUMBER(4,0),
  TRIMESTRU NUMBER(1,0),
  TOTALRULAJV NUMBER(20,7),
  TOTALVENITURI NUMBER(20,7),
  TOTALSUMEV NUMBER(20,7),
  TOTALRULAJC NUMBER(20,7),
  TOTALCHELT NUMBER(20,7),
  TOTALSUMEC NUMBER(20,7),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AMOFISC NUMBER(20,7),
  CHELTDOBPREC NUMBER(20,7),
  PROVFISC NUMBER(20,7),
  CREDITFISCEXT NUMBER(20,7),
  IMPPROFREINV NUMBER(20,7),
  ALTESCUTIRI NUMBER(20,7),
  CIFRAAFACERI NUMBER(20,7),
  CREDITFISCAL NUMBER(20,7),
  IMPOZITPROFITC NUMBER(20,7),
  IMPPROFDIF NUMBER(20,7),
  ANGENERARE NUMBER(4,0),
  LUNAGENERARE NUMBER(2,0),
  SPONSORREPORT NUMBER(20,7),
  CODNC NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TRIMESTRUT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DPROFITC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3927214B8EB2EA47D9AEE7CEFD8DCD0F2196214F</HASHVAL>
  <TEXT>CREATE TABLE DPROFITC (
  CODDPROFITC NUMBER(20,0) NOT NULL,
  CODDPROFIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  RULAJ NUMBER(20,7),
  CHELTUIELI NUMBER(20,7),
  SUMA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DPROFITV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>602F2A192F4FDFB88F6493CBD014F3406A9E1D90</HASHVAL>
  <TEXT>CREATE TABLE DPROFITV (
  CODDPROFITV NUMBER(20,0) NOT NULL,
  CODDPROFIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  RULAJ NUMBER(20,7),
  VENITURI NUMBER(20,7),
  SUMA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA9F1860A956BDC202ACCA67F68F3CEE7A3DBE92</HASHVAL>
  <TEXT>CREATE TABLE DVI (
  CODDVI NUMBER(20,0) NOT NULL,
  CODINTR NUMBER(20,0),
  CODVAMA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CONTCHELT NUMBER(20,0),
  CONTTVA NUMBER(20,0),
  TAXEINCLUSE NUMBER(1,0),
  FISAVAMA NUMBER(1,0),
  TAXEPECHELT NUMBER(1,0),
  TIPREPSUPLIM NUMBER(1,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPIMPORT NUMBER(1,0),
  VALDOCVAMA NUMBER(20,7),
  TVADOCVAMA NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  SERIADOC VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>DVI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>474E7584AB07A4DA264C51CCC585F61762942F8D</HASHVAL>
  <TEXT>CREATE TABLE DVI1 (
  CODDVI1 NUMBER(20,0) NOT NULL,
  CODDVI NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  INDEXLOCAL NUMBER(7,0),
  PRETIMPORT NUMBER(20,7),
  PRETVALUTA NUMBER(20,7),
  PRETORIGINAL NUMBER(20,7),
  TVA NUMBER(20,7),
  UMSEC NUMBER(10,0),
  ADDIM NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARETAXA NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  TVANEDED NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EFACTURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A28621D20AD46AB6BCBA5DF8373EDB84E15AE247</HASHVAL>
  <TEXT>CREATE TABLE EFACTURA (
  CODIES NUMBER(20,0) NOT NULL,
  IDINCARCARE VARCHAR2(20),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  STARE VARCHAR2(20),
  TIPMEDIU NUMBER(1,0),
  MESAJE CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EFACT_CUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBE16F5A8C266920556163800F1C14A0A3E02B6D</HASHVAL>
  <TEXT>CREATE TABLE EFACT_CUSTOM (
  CODEFACTC NUMBER(20,0),
  DEN_EFCUSTOM VARCHAR2(200),
  SQLCAMPURI CLOB,
  SQLCAMPURI1 CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EFCUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A4009F35677221DE5D7C99493EBD040C3512D0C</HASHVAL>
  <TEXT>CREATE TABLE EFCUSTOM (
  CODEFCUSTOM NUMBER(20,0) NOT NULL,
  DEN_EFCUSTOM VARCHAR2(30),
  SQLCAMPURI CLOB,
  SQLCAMPURI1 CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D089AE70A1DE1B5E36140805D72E1B87066DF506</HASHVAL>
  <TEXT>CREATE TABLE ELEMBUGET (
  CODELEMBUGET NUMBER(20,0) NOT NULL,
  ELEMENT VARCHAR2(250),
  SIMBOL VARCHAR2(30),
  TIP NUMBER(5,0),
  FUNCTIE NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMBUGET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D803A4F2383B23D6BBFD1A4730EE7AA2DD74B05B</HASHVAL>
  <TEXT>CREATE TABLE ELEMBUGET1 (
  CODELEMBUGET1 NUMBER(20,0) NOT NULL,
  CODELEMBUGET NUMBER(20,0),
  CODCLASEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMBUGET2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F83557611DA76BD3CE3E4613CD0F9A7537C675E4</HASHVAL>
  <TEXT>CREATE TABLE ELEMBUGET2 (
  CODELEMBUGET2 NUMBER(20,0) NOT NULL,
  CODELEMBUGET NUMBER(20,0),
  AN NUMBER(4,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18DDC7DA0C4D67D4BB03A6DF2FA522DC947F427C</HASHVAL>
  <TEXT>CREATE TABLE ELEMENTE (
  CODELEMENT NUMBER(20,0) NOT NULL,
  DEN_ELEMENT VARCHAR2(100),
  TIP NUMBER(2,0),
  CODDESCRIPTORBAZA NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  CV NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMENTEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4CA115FB7A3D0F677BF494290631C351CB8A1717</HASHVAL>
  <TEXT>CREATE TABLE ELEMENTEA (
  CODELEMENTA NUMBER(20,0) NOT NULL,
  CODELEMENT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  NODMAXIMANALIZA1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMENTEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95CC3AC623B8120EE59429E560961DA5F810BADD</HASHVAL>
  <TEXT>CREATE TABLE ELEMENTEC (
  CODELEMENTC NUMBER(20,0) NOT NULL,
  CODELEMENTM NUMBER(20,0),
  MASCA VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ELEMENTEM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2E976960FD292FD1411B70E9E463AD8F6CB88EC</HASHVAL>
  <TEXT>CREATE TABLE ELEMENTEM (
  CODELEMENTM NUMBER(20,0) NOT NULL,
  CODELEMENT NUMBER(20,0),
  TIPDOC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>558C8E2893E92EA52C14AFE3C7B3BD5A0BAEA133</HASHVAL>
  <TEXT>CREATE TABLE EMULARE (
  CODEMULARE NUMBER(20,0) NOT NULL,
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  TIPCASAMARCAT NUMBER(5,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  INCASARECLIENT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODRESTNP NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTSIMPLIF NUMBER(1,0),
  IDBON NUMBER,
  FACTURARE NUMBER(1,0),
  DELEGAT NUMBER(20,0),
  EXCLUSDISCOUNT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  CODSEDIURETAIL NUMBER(20,0),
  PUNCTECUMUL NUMBER(20,0),
  VALPUNCTECUMUL NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  VALVALUTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0494C4B4E1A42BC9215DA42AE989AA85C5DD088C</HASHVAL>
  <TEXT>CREATE TABLE EMULARE1 (
  CODEMULARE1 NUMBER(20,0) NOT NULL,
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0),
  DISCMANUAL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  PRETNEPROMO NUMBER(20,7),
  PROMOTIONAT NUMBER(1,0),
  FORCEPROMO NUMBER(1,0),
  INFOPROMO VARCHAR2(100),
  INFOPROMODISC VARCHAR2(100),
  CODPROMO1 NUMBER(20,0),
  PROCTVABON NUMBER(20,7),
  TAXA NUMBER(1,0),
  CODEMUL1AVANS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARE1RETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53C6CC345AC72B4FF706194DE58EDEDE07D5CFDF</HASHVAL>
  <TEXT>CREATE TABLE EMULARE1RETAIL (
  CODEMULARE1 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0),
  DISCMANUAL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  PRETNEPROMO NUMBER(20,7),
  PROMOTIONAT NUMBER(1,0),
  FORCEPROMO NUMBER(1,0),
  INFOPROMO VARCHAR2(100),
  INFOPROMODISC VARCHAR2(100),
  CODPROMO1 NUMBER(20,0),
  PROCTVABON NUMBER(20,7),
  TAXA NUMBER(1,0),
  CODEMUL1AVANS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B41C61FD34A22B7C89CEAC3A5CB1926E9E3FC45</HASHVAL>
  <TEXT>CREATE TABLE EMULARE2 (
  CODEMULARE2 NUMBER(20,0) NOT NULL,
  CODEMULARE NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODBANKCONT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODCARD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARE2RETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E84EE514C3D32360864AEE55267FD11E8D04450D</HASHVAL>
  <TEXT>CREATE TABLE EMULARE2RETAIL (
  CODEMULARE2 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODBANKCONT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODCARD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULARERETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98EAEF1759E3CDDB843E2DEC81A7D4CEA2D13044</HASHVAL>
  <TEXT>CREATE TABLE EMULARERETAIL (
  CODEMULARE NUMBER(20,0) NOT NULL,
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  TIPCASAMARCAT NUMBER(5,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  INCASARECLIENT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODRESTNP NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTSIMPLIF NUMBER(1,0),
  IDBON NUMBER,
  FACTURARE NUMBER(1,0),
  DELEGAT NUMBER(20,0),
  EXCLUSDISCOUNT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  CODSEDIURETAIL NUMBER(20,0),
  PUNCTECUMUL NUMBER(20,0),
  VALPUNCTECUMUL NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  VALVALUTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULEDITAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>721E4A698648DEE32E215E77EF89A4BB5848E31C</HASHVAL>
  <TEXT>CREATE TABLE EMULEDITAT (
  USERID NUMBER(20,0),
  CODEMULARE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULPUNCTEUSED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CA68748729A6BE8F8C18115FB3606B955EF56DB</HASHVAL>
  <TEXT>CREATE TABLE EMULPUNCTEUSED (
  COD NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  PUNCTEUSED NUMBER(20,7),
  VALACORDATA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EMULSTINGERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C42D98C9526CE870531862AA7A1F2C61668B892F</HASHVAL>
  <TEXT>CREATE TABLE EMULSTINGERI (
  CODEMULSTINGERE NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,7),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ERRORSDELETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D445D3183400D6A569F67F53C1ADEDCBFC08FA1</HASHVAL>
  <TEXT>CREATE TABLE ERRORSDELETE (
  NUMETABELA VARCHAR2(30),
  COD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARINOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02EF4A30804E35C0C9BC7912AF99C79CB2A82077</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARINOD (
  CODESTIMARENOD NUMBER(20,0) NOT NULL,
  CODESTIMAREPROD NUMBER(20,0),
  CODESTIMAREPROD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  SAPTAMANA NUMBER(2,0),
  AN NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARINOD_C1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A6C8FF2F41B1374564870765DB4FD8A1A5AF2A6B</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARINOD_C1 (
  CODESTIMARENOD NUMBER(20,0) NOT NULL,
  CODESTIMAREPROD NUMBER(20,0),
  CODESTIMAREPROD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  SAPTAMANA NUMBER(2,0),
  AN NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARINOD_C2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C918F95BE8F37DF370716063EA75AD46E607EFEB</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARINOD_C2 (
  CODESTIMARENOD NUMBER(20,0),
  CODESTIMAREPROD NUMBER(20,0),
  CODESTIMAREPROD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  SAPTAMANA NUMBER(2,0),
  AN NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARIPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F3EE3C88BB521AFF60F98814BD2F6B7E4CB208A1</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARIPROD (
  CODESTIMAREPROD NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS VARCHAR2(400),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(2,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(10),
  ANIMPORT NUMBER(4,0),
  SAPTAMANAF NUMBER(2,0),
  ANF NUMBER(4,0),
  CODOFERTA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARIPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E74B5554A5531DDE6473E904AF473561C2A5960A</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARIPROD1 (
  CODESTIMAREPROD1 NUMBER(20,0) NOT NULL,
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  PRET NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  VAL_C1 NUMBER(20,7),
  VAL_C2 NUMBER(20,7),
  VAL_C3 NUMBER(20,7),
  VAL_C4 NUMBER(20,7),
  VAL_C5 NUMBER(20,7),
  VAL_C6 NUMBER(20,7),
  VAL_C7 NUMBER(20,7),
  VAL_C8 NUMBER(20,7),
  VAL_C9 NUMBER(20,7),
  VAL_C10 NUMBER(20,7),
  VAL_C11 NUMBER(20,7),
  VAL_C12 NUMBER(20,7),
  VAL_C13 NUMBER(20,7),
  VAL_C14 NUMBER(20,7),
  VAL_C15 NUMBER(20,7),
  VAL_C16 NUMBER(20,7),
  VAL_C17 NUMBER(20,7),
  VAL_C18 NUMBER(20,7),
  VAL_C19 NUMBER(20,7),
  VAL_C20 NUMBER(20,7),
  VAL_C21 NUMBER(20,7),
  VAL_C22 NUMBER(20,7),
  VAL_C23 NUMBER(20,7),
  VAL_C24 NUMBER(20,7),
  VAL_C25 NUMBER(20,7),
  VAL_C26 NUMBER(20,7),
  VAL_C27 NUMBER(20,7),
  VAL_C28 NUMBER(20,7),
  VAL_C29 NUMBER(20,7),
  VAL_C30 NUMBER(20,7),
  VAL_C31 NUMBER(20,7),
  VAL_C32 NUMBER(20,7),
  VAL_C33 NUMBER(20,7),
  VAL_C34 NUMBER(20,7),
  VAL_C35 NUMBER(20,7),
  VAL_C36 NUMBER(20,7),
  VAL_C37 NUMBER(20,7),
  VAL_C38 NUMBER(20,7),
  VAL_C39 NUMBER(20,7),
  VAL_C40 NUMBER(20,7),
  VAL_C41 NUMBER(20,7),
  VAL_C42 NUMBER(20,7),
  VAL_C43 NUMBER(20,7),
  VAL_C44 NUMBER(20,7),
  VAL_C45 NUMBER(20,7),
  VAL_C46 NUMBER(20,7),
  VAL_C47 NUMBER(20,7),
  VAL_C48 NUMBER(20,7),
  VAL_C49 NUMBER(20,7),
  VAL_C50 NUMBER(20,7),
  VAL_C51 NUMBER(20,7),
  VAL_C52 NUMBER(20,7),
  VAL_C53 NUMBER(20,7),
  VAL_N1 NUMBER(20,7),
  VAL_N2 NUMBER(20,7),
  VAL_N3 NUMBER(20,7),
  VAL_N4 NUMBER(20,7),
  VAL_N5 NUMBER(20,7),
  VAL_N6 NUMBER(20,7),
  VAL_N7 NUMBER(20,7),
  VAL_N8 NUMBER(20,7),
  VAL_N9 NUMBER(20,7),
  VAL_N10 NUMBER(20,7),
  VAL_N11 NUMBER(20,7),
  VAL_N12 NUMBER(20,7),
  VAL_N13 NUMBER(20,7),
  VAL_N14 NUMBER(20,7),
  VAL_N15 NUMBER(20,7),
  VAL_N16 NUMBER(20,7),
  VAL_N17 NUMBER(20,7),
  VAL_N18 NUMBER(20,7),
  VAL_N19 NUMBER(20,7),
  VAL_N20 NUMBER(20,7),
  VAL_N21 NUMBER(20,7),
  VAL_N22 NUMBER(20,7),
  VAL_N23 NUMBER(20,7),
  VAL_N24 NUMBER(20,7),
  VAL_N25 NUMBER(20,7),
  VAL_N26 NUMBER(20,7),
  VAL_N27 NUMBER(20,7),
  VAL_N28 NUMBER(20,7),
  VAL_N29 NUMBER(20,7),
  VAL_N30 NUMBER(20,7),
  VAL_N31 NUMBER(20,7),
  VAL_N32 NUMBER(20,7),
  VAL_N33 NUMBER(20,7),
  VAL_N34 NUMBER(20,7),
  VAL_N35 NUMBER(20,7),
  VAL_N36 NUMBER(20,7),
  VAL_N37 NUMBER(20,7),
  VAL_N38 NUMBER(20,7),
  VAL_N39 NUMBER(20,7),
  VAL_N40 NUMBER(20,7),
  VAL_N41 NUMBER(20,7),
  VAL_N42 NUMBER(20,7),
  VAL_N43 NUMBER(20,7),
  VAL_N44 NUMBER(20,7),
  VAL_N45 NUMBER(20,7),
  VAL_N46 NUMBER(20,7),
  VAL_N47 NUMBER(20,7),
  VAL_N48 NUMBER(20,7),
  VAL_N49 NUMBER(20,7),
  VAL_N50 NUMBER(20,7),
  VAL_N51 NUMBER(20,7),
  VAL_N52 NUMBER(20,7),
  VAL_N53 NUMBER(20,7),
  DEPASIRE NUMBER(20,7),
  VAL_T1 NUMBER(20,7),
  VAL_T2 NUMBER(20,7),
  VAL_T3 NUMBER(20,7),
  VAL_T4 NUMBER(20,7),
  VAL_T5 NUMBER(20,7),
  VAL_T6 NUMBER(20,7),
  VAL_T7 NUMBER(20,7),
  VAL_T8 NUMBER(20,7),
  VAL_T9 NUMBER(20,7),
  VAL_T10 NUMBER(20,7),
  VAL_T11 NUMBER(20,7),
  VAL_T12 NUMBER(20,7),
  VAL_T13 NUMBER(20,7),
  VAL_T14 NUMBER(20,7),
  VAL_T15 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARIPROD1M</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1475489EB53CAE5FF6CABDC7B22B837D66070C78</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARIPROD1M (
  CODESTIMAREPROD1M NUMBER(20,0) NOT NULL,
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  NEC_C1 NUMBER(20,7),
  NEC_C2 NUMBER(20,7),
  NEC_C3 NUMBER(20,7),
  NEC_C4 NUMBER(20,7),
  NEC_C5 NUMBER(20,7),
  NEC_C6 NUMBER(20,7),
  NEC_C7 NUMBER(20,7),
  NEC_C8 NUMBER(20,7),
  NEC_C9 NUMBER(20,7),
  NEC_C10 NUMBER(20,7),
  NEC_C11 NUMBER(20,7),
  NEC_C12 NUMBER(20,7),
  NEC_C13 NUMBER(20,7),
  NEC_C14 NUMBER(20,7),
  NEC_C15 NUMBER(20,7),
  NEC_C16 NUMBER(20,7),
  NEC_C17 NUMBER(20,7),
  NEC_C18 NUMBER(20,7),
  NEC_C19 NUMBER(20,7),
  NEC_C20 NUMBER(20,7),
  NEC_C21 NUMBER(20,7),
  NEC_C22 NUMBER(20,7),
  NEC_C23 NUMBER(20,7),
  NEC_C24 NUMBER(20,7),
  NEC_C25 NUMBER(20,7),
  NEC_C26 NUMBER(20,7),
  NEC_C27 NUMBER(20,7),
  NEC_C28 NUMBER(20,7),
  NEC_C29 NUMBER(20,7),
  NEC_C30 NUMBER(20,7),
  NEC_C31 NUMBER(20,7),
  NEC_C32 NUMBER(20,7),
  NEC_C33 NUMBER(20,7),
  NEC_C34 NUMBER(20,7),
  NEC_C35 NUMBER(20,7),
  NEC_C36 NUMBER(20,7),
  NEC_C37 NUMBER(20,7),
  NEC_C38 NUMBER(20,7),
  NEC_C39 NUMBER(20,7),
  NEC_C40 NUMBER(20,7),
  NEC_C41 NUMBER(20,7),
  NEC_C42 NUMBER(20,7),
  NEC_C43 NUMBER(20,7),
  NEC_C44 NUMBER(20,7),
  NEC_C45 NUMBER(20,7),
  NEC_C46 NUMBER(20,7),
  NEC_C47 NUMBER(20,7),
  NEC_C48 NUMBER(20,7),
  NEC_C49 NUMBER(20,7),
  NEC_C50 NUMBER(20,7),
  NEC_C51 NUMBER(20,7),
  NEC_C52 NUMBER(20,7),
  NEC_N1 NUMBER(20,7),
  NEC_N2 NUMBER(20,7),
  NEC_N3 NUMBER(20,7),
  NEC_N4 NUMBER(20,7),
  NEC_N5 NUMBER(20,7),
  NEC_N6 NUMBER(20,7),
  NEC_N7 NUMBER(20,7),
  NEC_N8 NUMBER(20,7),
  NEC_N9 NUMBER(20,7),
  NEC_N10 NUMBER(20,7),
  NEC_N11 NUMBER(20,7),
  NEC_N12 NUMBER(20,7),
  NEC_N13 NUMBER(20,7),
  NEC_N14 NUMBER(20,7),
  NEC_N15 NUMBER(20,7),
  NEC_N16 NUMBER(20,7),
  NEC_N17 NUMBER(20,7),
  NEC_N18 NUMBER(20,7),
  NEC_N19 NUMBER(20,7),
  NEC_N20 NUMBER(20,7),
  NEC_N21 NUMBER(20,7),
  NEC_N22 NUMBER(20,7),
  NEC_N23 NUMBER(20,7),
  NEC_N24 NUMBER(20,7),
  NEC_N25 NUMBER(20,7),
  NEC_N26 NUMBER(20,7),
  NEC_N27 NUMBER(20,7),
  NEC_N28 NUMBER(20,7),
  NEC_N29 NUMBER(20,7),
  NEC_N30 NUMBER(20,7),
  NEC_N31 NUMBER(20,7),
  NEC_N32 NUMBER(20,7),
  NEC_N33 NUMBER(20,7),
  NEC_N34 NUMBER(20,7),
  NEC_N35 NUMBER(20,7),
  NEC_N36 NUMBER(20,7),
  NEC_N37 NUMBER(20,7),
  NEC_N38 NUMBER(20,7),
  NEC_N39 NUMBER(20,7),
  NEC_N40 NUMBER(20,7),
  NEC_N41 NUMBER(20,7),
  NEC_N42 NUMBER(20,7),
  NEC_N43 NUMBER(20,7),
  NEC_N44 NUMBER(20,7),
  NEC_N45 NUMBER(20,7),
  NEC_N46 NUMBER(20,7),
  NEC_N47 NUMBER(20,7),
  NEC_N48 NUMBER(20,7),
  NEC_N49 NUMBER(20,7),
  NEC_N50 NUMBER(20,7),
  NEC_N51 NUMBER(20,7),
  NEC_N52 NUMBER(20,7),
  NEC_C53 NUMBER(20,7),
  NEC_N53 NUMBER(20,7),
  CF_C1 NUMBER(20,7),
  CF_C2 NUMBER(20,7),
  CF_C3 NUMBER(20,7),
  CF_C4 NUMBER(20,7),
  CF_C5 NUMBER(20,7),
  CF_C6 NUMBER(20,7),
  CF_C7 NUMBER(20,7),
  CF_C8 NUMBER(20,7),
  CF_C9 NUMBER(20,7),
  CF_C10 NUMBER(20,7),
  CF_C11 NUMBER(20,7),
  CF_C12 NUMBER(20,7),
  CF_C13 NUMBER(20,7),
  CF_C14 NUMBER(20,7),
  CF_C15 NUMBER(20,7),
  CF_C16 NUMBER(20,7),
  CF_C17 NUMBER(20,7),
  CF_C18 NUMBER(20,7),
  CF_C19 NUMBER(20,7),
  CF_C20 NUMBER(20,7),
  CF_C21 NUMBER(20,7),
  CF_C22 NUMBER(20,7),
  CF_C23 NUMBER(20,7),
  CF_C24 NUMBER(20,7),
  CF_C25 NUMBER(20,7),
  CF_C26 NUMBER(20,7),
  CF_C27 NUMBER(20,7),
  CF_C28 NUMBER(20,7),
  CF_C29 NUMBER(20,7),
  CF_C30 NUMBER(20,7),
  CF_C31 NUMBER(20,7),
  CF_C32 NUMBER(20,7),
  CF_C33 NUMBER(20,7),
  CF_C34 NUMBER(20,7),
  CF_C35 NUMBER(20,7),
  CF_C36 NUMBER(20,7),
  CF_C37 NUMBER(20,7),
  CF_C38 NUMBER(20,7),
  CF_C39 NUMBER(20,7),
  CF_C40 NUMBER(20,7),
  CF_C41 NUMBER(20,7),
  CF_C42 NUMBER(20,7),
  CF_C43 NUMBER(20,7),
  CF_C44 NUMBER(20,7),
  CF_C45 NUMBER(20,7),
  CF_C46 NUMBER(20,7),
  CF_C47 NUMBER(20,7),
  CF_C48 NUMBER(20,7),
  CF_C49 NUMBER(20,7),
  CF_C50 NUMBER(20,7),
  CF_C51 NUMBER(20,7),
  CF_C52 NUMBER(20,7),
  CF_C53 NUMBER(20,7),
  CF_N1 NUMBER(20,7),
  CF_N2 NUMBER(20,7),
  CF_N3 NUMBER(20,7),
  CF_N4 NUMBER(20,7),
  CF_N5 NUMBER(20,7),
  CF_N6 NUMBER(20,7),
  CF_N7 NUMBER(20,7),
  CF_N8 NUMBER(20,7),
  CF_N9 NUMBER(20,7),
  CF_N10 NUMBER(20,7),
  CF_N11 NUMBER(20,7),
  CF_N12 NUMBER(20,7),
  CF_N13 NUMBER(20,7),
  CF_N14 NUMBER(20,7),
  CF_N15 NUMBER(20,7),
  CF_N16 NUMBER(20,7),
  CF_N17 NUMBER(20,7),
  CF_N18 NUMBER(20,7),
  CF_N19 NUMBER(20,7),
  CF_N20 NUMBER(20,7),
  CF_N21 NUMBER(20,7),
  CF_N22 NUMBER(20,7),
  CF_N23 NUMBER(20,7),
  CF_N24 NUMBER(20,7),
  CF_N25 NUMBER(20,7),
  CF_N26 NUMBER(20,7),
  CF_N27 NUMBER(20,7),
  CF_N28 NUMBER(20,7),
  CF_N29 NUMBER(20,7),
  CF_N30 NUMBER(20,7),
  CF_N31 NUMBER(20,7),
  CF_N32 NUMBER(20,7),
  CF_N33 NUMBER(20,7),
  CF_N34 NUMBER(20,7),
  CF_N35 NUMBER(20,7),
  CF_N36 NUMBER(20,7),
  CF_N37 NUMBER(20,7),
  CF_N38 NUMBER(20,7),
  CF_N39 NUMBER(20,7),
  CF_N40 NUMBER(20,7),
  CF_N41 NUMBER(20,7),
  CF_N42 NUMBER(20,7),
  CF_N43 NUMBER(20,7),
  CF_N44 NUMBER(20,7),
  CF_N45 NUMBER(20,7),
  CF_N46 NUMBER(20,7),
  CF_N47 NUMBER(20,7),
  CF_N48 NUMBER(20,7),
  CF_N49 NUMBER(20,7),
  CF_N50 NUMBER(20,7),
  CF_N51 NUMBER(20,7),
  CF_N52 NUMBER(20,7),
  CF_N53 NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  COEFUM NUMBER(20,7),
  PRET NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  VAL_C1 NUMBER(20,7),
  VAL_C2 NUMBER(20,7),
  VAL_C3 NUMBER(20,7),
  VAL_C4 NUMBER(20,7),
  VAL_C5 NUMBER(20,7),
  VAL_C6 NUMBER(20,7),
  VAL_C7 NUMBER(20,7),
  VAL_C8 NUMBER(20,7),
  VAL_C9 NUMBER(20,7),
  VAL_C10 NUMBER(20,7),
  VAL_C11 NUMBER(20,7),
  VAL_C12 NUMBER(20,7),
  VAL_C13 NUMBER(20,7),
  VAL_C14 NUMBER(20,7),
  VAL_C15 NUMBER(20,7),
  VAL_C16 NUMBER(20,7),
  VAL_C17 NUMBER(20,7),
  VAL_C18 NUMBER(20,7),
  VAL_C19 NUMBER(20,7),
  VAL_C20 NUMBER(20,7),
  VAL_C21 NUMBER(20,7),
  VAL_C22 NUMBER(20,7),
  VAL_C23 NUMBER(20,7),
  VAL_C24 NUMBER(20,7),
  VAL_C25 NUMBER(20,7),
  VAL_C26 NUMBER(20,7),
  VAL_C27 NUMBER(20,7),
  VAL_C28 NUMBER(20,7),
  VAL_C29 NUMBER(20,7),
  VAL_C30 NUMBER(20,7),
  VAL_C31 NUMBER(20,7),
  VAL_C32 NUMBER(20,7),
  VAL_C33 NUMBER(20,7),
  VAL_C34 NUMBER(20,7),
  VAL_C35 NUMBER(20,7),
  VAL_C36 NUMBER(20,7),
  VAL_C37 NUMBER(20,7),
  VAL_C38 NUMBER(20,7),
  VAL_C39 NUMBER(20,7),
  VAL_C40 NUMBER(20,7),
  VAL_C41 NUMBER(20,7),
  VAL_C42 NUMBER(20,7),
  VAL_C43 NUMBER(20,7),
  VAL_C44 NUMBER(20,7),
  VAL_C45 NUMBER(20,7),
  VAL_C46 NUMBER(20,7),
  VAL_C47 NUMBER(20,7),
  VAL_C48 NUMBER(20,7),
  VAL_C49 NUMBER(20,7),
  VAL_C50 NUMBER(20,7),
  VAL_C51 NUMBER(20,7),
  VAL_C52 NUMBER(20,7),
  VAL_C53 NUMBER(20,7),
  VAL_N1 NUMBER(20,7),
  VAL_N2 NUMBER(20,7),
  VAL_N3 NUMBER(20,7),
  VAL_N4 NUMBER(20,7),
  VAL_N5 NUMBER(20,7),
  VAL_N6 NUMBER(20,7),
  VAL_N7 NUMBER(20,7),
  VAL_N8 NUMBER(20,7),
  VAL_N9 NUMBER(20,7),
  VAL_N10 NUMBER(20,7),
  VAL_N11 NUMBER(20,7),
  VAL_N12 NUMBER(20,7),
  VAL_N13 NUMBER(20,7),
  VAL_N14 NUMBER(20,7),
  VAL_N15 NUMBER(20,7),
  VAL_N16 NUMBER(20,7),
  VAL_N17 NUMBER(20,7),
  VAL_N18 NUMBER(20,7),
  VAL_N19 NUMBER(20,7),
  VAL_N20 NUMBER(20,7),
  VAL_N21 NUMBER(20,7),
  VAL_N22 NUMBER(20,7),
  VAL_N23 NUMBER(20,7),
  VAL_N24 NUMBER(20,7),
  VAL_N25 NUMBER(20,7),
  VAL_N26 NUMBER(20,7),
  VAL_N27 NUMBER(20,7),
  VAL_N28 NUMBER(20,7),
  VAL_N29 NUMBER(20,7),
  VAL_N30 NUMBER(20,7),
  VAL_N31 NUMBER(20,7),
  VAL_N32 NUMBER(20,7),
  VAL_N33 NUMBER(20,7),
  VAL_N34 NUMBER(20,7),
  VAL_N35 NUMBER(20,7),
  VAL_N36 NUMBER(20,7),
  VAL_N37 NUMBER(20,7),
  VAL_N38 NUMBER(20,7),
  VAL_N39 NUMBER(20,7),
  VAL_N40 NUMBER(20,7),
  VAL_N41 NUMBER(20,7),
  VAL_N42 NUMBER(20,7),
  VAL_N43 NUMBER(20,7),
  VAL_N44 NUMBER(20,7),
  VAL_N45 NUMBER(20,7),
  VAL_N46 NUMBER(20,7),
  VAL_N47 NUMBER(20,7),
  VAL_N48 NUMBER(20,7),
  VAL_N49 NUMBER(20,7),
  VAL_N50 NUMBER(20,7),
  VAL_N51 NUMBER(20,7),
  VAL_N52 NUMBER(20,7),
  VAL_N53 NUMBER(20,7),
  DEPASIRE NUMBER(20,7),
  VAL_T1 NUMBER(20,7),
  VAL_T2 NUMBER(20,7),
  VAL_T3 NUMBER(20,7),
  VAL_T4 NUMBER(20,7),
  VAL_T5 NUMBER(20,7),
  VAL_T6 NUMBER(20,7),
  VAL_T7 NUMBER(20,7),
  VAL_T8 NUMBER(20,7),
  VAL_T9 NUMBER(20,7),
  VAL_T10 NUMBER(20,7),
  VAL_T11 NUMBER(20,7),
  VAL_T12 NUMBER(20,7),
  VAL_T13 NUMBER(20,7),
  VAL_T14 NUMBER(20,7),
  VAL_T15 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ESTIMARIPROD1N</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A98E4A0AC92ED2362F3AA946558CF474EABF4D7</HASHVAL>
  <TEXT>CREATE TABLE ESTIMARIPROD1N (
  CODESTIMAREPROD1N NUMBER(20,0) NOT NULL,
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NEC_C1 NUMBER(20,7),
  NEC_C2 NUMBER(20,7),
  NEC_C3 NUMBER(20,7),
  NEC_C4 NUMBER(20,7),
  NEC_C5 NUMBER(20,7),
  NEC_C6 NUMBER(20,7),
  NEC_C7 NUMBER(20,7),
  NEC_C8 NUMBER(20,7),
  NEC_C9 NUMBER(20,7),
  NEC_C10 NUMBER(20,7),
  NEC_C11 NUMBER(20,7),
  NEC_C12 NUMBER(20,7),
  NEC_C13 NUMBER(20,7),
  NEC_C14 NUMBER(20,7),
  NEC_C15 NUMBER(20,7),
  NEC_C16 NUMBER(20,7),
  NEC_C17 NUMBER(20,7),
  NEC_C18 NUMBER(20,7),
  NEC_C19 NUMBER(20,7),
  NEC_C20 NUMBER(20,7),
  NEC_C21 NUMBER(20,7),
  NEC_C22 NUMBER(20,7),
  NEC_C23 NUMBER(20,7),
  NEC_C24 NUMBER(20,7),
  NEC_C25 NUMBER(20,7),
  NEC_C26 NUMBER(20,7),
  NEC_C27 NUMBER(20,7),
  NEC_C28 NUMBER(20,7),
  NEC_C29 NUMBER(20,7),
  NEC_C30 NUMBER(20,7),
  NEC_C31 NUMBER(20,7),
  NEC_C32 NUMBER(20,7),
  NEC_C33 NUMBER(20,7),
  NEC_C34 NUMBER(20,7),
  NEC_C35 NUMBER(20,7),
  NEC_C36 NUMBER(20,7),
  NEC_C37 NUMBER(20,7),
  NEC_C38 NUMBER(20,7),
  NEC_C39 NUMBER(20,7),
  NEC_C40 NUMBER(20,7),
  NEC_C41 NUMBER(20,7),
  NEC_C42 NUMBER(20,7),
  NEC_C43 NUMBER(20,7),
  NEC_C44 NUMBER(20,7),
  NEC_C45 NUMBER(20,7),
  NEC_C46 NUMBER(20,7),
  NEC_C47 NUMBER(20,7),
  NEC_C48 NUMBER(20,7),
  NEC_C49 NUMBER(20,7),
  NEC_C50 NUMBER(20,7),
  NEC_C51 NUMBER(20,7),
  NEC_C52 NUMBER(20,7),
  NEC_N1 NUMBER(20,7),
  NEC_N2 NUMBER(20,7),
  NEC_N3 NUMBER(20,7),
  NEC_N4 NUMBER(20,7),
  NEC_N5 NUMBER(20,7),
  NEC_N6 NUMBER(20,7),
  NEC_N7 NUMBER(20,7),
  NEC_N8 NUMBER(20,7),
  NEC_N9 NUMBER(20,7),
  NEC_N10 NUMBER(20,7),
  NEC_N11 NUMBER(20,7),
  NEC_N12 NUMBER(20,7),
  NEC_N13 NUMBER(20,7),
  NEC_N14 NUMBER(20,7),
  NEC_N15 NUMBER(20,7),
  NEC_N16 NUMBER(20,7),
  NEC_N17 NUMBER(20,7),
  NEC_N18 NUMBER(20,7),
  NEC_N19 NUMBER(20,7),
  NEC_N20 NUMBER(20,7),
  NEC_N21 NUMBER(20,7),
  NEC_N22 NUMBER(20,7),
  NEC_N23 NUMBER(20,7),
  NEC_N24 NUMBER(20,7),
  NEC_N25 NUMBER(20,7),
  NEC_N26 NUMBER(20,7),
  NEC_N27 NUMBER(20,7),
  NEC_N28 NUMBER(20,7),
  NEC_N29 NUMBER(20,7),
  NEC_N30 NUMBER(20,7),
  NEC_N31 NUMBER(20,7),
  NEC_N32 NUMBER(20,7),
  NEC_N33 NUMBER(20,7),
  NEC_N34 NUMBER(20,7),
  NEC_N35 NUMBER(20,7),
  NEC_N36 NUMBER(20,7),
  NEC_N37 NUMBER(20,7),
  NEC_N38 NUMBER(20,7),
  NEC_N39 NUMBER(20,7),
  NEC_N40 NUMBER(20,7),
  NEC_N41 NUMBER(20,7),
  NEC_N42 NUMBER(20,7),
  NEC_N43 NUMBER(20,7),
  NEC_N44 NUMBER(20,7),
  NEC_N45 NUMBER(20,7),
  NEC_N46 NUMBER(20,7),
  NEC_N47 NUMBER(20,7),
  NEC_N48 NUMBER(20,7),
  NEC_N49 NUMBER(20,7),
  NEC_N50 NUMBER(20,7),
  NEC_N51 NUMBER(20,7),
  NEC_N52 NUMBER(20,7),
  NEC_C53 NUMBER(20,7),
  NEC_N53 NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  COEFUM NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C1338714C0D6113C4EF8F1DE8A643FF56D06F85</HASHVAL>
  <TEXT>CREATE TABLE ETVA (
  CODETVA NUMBER(20,0) NOT NULL,
  CIF VARCHAR2(75),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  DATA_INCARCARE DATE,
  DENUMIRE VARCHAR2(200),
  ID VARCHAR2(50),
  CONSOLIDAT VARCHAR2(50),
  DATA_SPV DATE,
  ID_SPV VARCHAR2(50),
  DOMICILIU VARCHAR2(150),
  SUBUNITATEA NUMBER(20,0),
  RD1_1_VAL_ETRANS NUMBER(20,7),
  RD1_VAL NUMBER(20,7),
  RD1_VAL_390 NUMBER(20,7),
  RD10_TVA NUMBER(20,7),
  RD10_TVA_394 NUMBER(20,7),
  RD10_TVA_AMEF NUMBER(20,7),
  RD10_TVA_EFCT NUMBER(20,7),
  RD10_VAL NUMBER(20,7),
  RD10_VAL_394 NUMBER(20,7),
  RD10_VAL_AMEF NUMBER(20,7),
  RD10_VAL_EFCT NUMBER(20,7),
  RD101_TVA_REGAC NUMBER(20,7),
  RD101_VAL_REGAC NUMBER(20,7),
  RD11_TVA NUMBER(20,7),
  RD11_TVA_394 NUMBER(20,7),
  RD11_TVA_AMEF NUMBER(20,7),
  RD11_TVA_EFCT NUMBER(20,7),
  RD11_VAL NUMBER(20,7),
  RD11_VAL_394 NUMBER(20,7),
  RD11_VAL_AMEF NUMBER(20,7),
  RD11_VAL_EFCT NUMBER(20,7),
  RD111_TVA_REGAC NUMBER(20,7),
  RD111_VAL_REGAC NUMBER(20,7),
  RD12_TVA NUMBER(20,7),
  RD12_TVA_394 NUMBER(20,7),
  RD12_TVA_EFCT NUMBER(20,7),
  RD12_VAL NUMBER(20,7),
  RD12_VAL_394 NUMBER(20,7),
  RD12_VAL_EFCT NUMBER(20,7),
  RD121_TVA NUMBER(20,7),
  RD121_TVA_394 NUMBER(20,7),
  RD121_VAL NUMBER(20,7),
  RD121_VAL_394 NUMBER(20,7),
  RD122_TVA NUMBER(20,7),
  RD122_TVA_394 NUMBER(20,7),
  RD122_VAL NUMBER(20,7),
  RD122_VAL_394 NUMBER(20,7),
  RD123_TVA NUMBER(20,7),
  RD123_TVA_394 NUMBER(20,7),
  RD123_VAL NUMBER(20,7),
  RD123_VAL_394 NUMBER(20,7),
  RD13_VAL NUMBER(20,7),
  RD13_VAL_EFCT NUMBER(20,7),
  RD14_15_VAL NUMBER(20,7),
  RD14_15_VAL_AMEF NUMBER(20,7),
  RD14_15_VAL_EFCT NUMBER(20,7),
  RD14_15_VAL_VAMA NUMBER(20,7),
  RD2_VAL NUMBER(20,7),
  RD2_VAL_390 NUMBER(20,7),
  RD20_TVA NUMBER(20,7),
  RD20_VAL NUMBER(20,7),
  RD201_TVA NUMBER(20,7),
  RD201_VAL NUMBER(20,7),
  RD21_TVA NUMBER(20,7),
  RD21_VAL NUMBER(20,7),
  RD22_TVA NUMBER(20,7),
  RD22_VAL NUMBER(20,7),
  RD221_TVA NUMBER(20,7),
  RD221_VAL NUMBER(20,7),
  RD23_TVA NUMBER(20,7),
  RD23_VAL NUMBER(20,7),
  RD24_TVA NUMBER(20,7),
  RD24_TVA_394 NUMBER(20,7),
  RD24_TVA_EFCT_I NUMBER(20,7),
  RD24_TVA_EFCT_N NUMBER(20,7),
  RD24_TVA_EFCT_T NUMBER(20,7),
  RD24_TVA_VAMA NUMBER(20,7),
  RD24_VAL NUMBER(20,7),
  RD24_VAL_394 NUMBER(20,7),
  RD24_VAL_EFCT_I NUMBER(20,7),
  RD24_VAL_EFCT_N NUMBER(20,7),
  RD24_VAL_EFCT_T NUMBER(20,7),
  RD24_VAL_VAMA NUMBER(20,7),
  RD25_TVA NUMBER(20,7),
  RD25_TVA_394 NUMBER(20,7),
  RD25_TVA_EFCT_I NUMBER(20,7),
  RD25_TVA_EFCT_N NUMBER(20,7),
  RD25_TVA_EFCT_T NUMBER(20,7),
  RD25_TVA_VAMA NUMBER(20,7),
  RD25_VAL NUMBER(20,7),
  RD25_VAL_394 NUMBER(20,7),
  RD25_VAL_EFCT_I NUMBER(20,7),
  RD25_VAL_EFCT_N NUMBER(20,7),
  RD25_VAL_EFCT_T NUMBER(20,7),
  RD25_VAL_VAMA NUMBER(20,7),
  RD26_TVA NUMBER(20,7),
  RD26_TVA_394 NUMBER(20,7),
  RD26_TVA_EFCT_I NUMBER(20,7),
  RD26_TVA_EFCT_N NUMBER(20,7),
  RD26_TVA_EFCT_T NUMBER(20,7),
  RD26_TVA_VAMA NUMBER(20,7),
  RD26_VAL NUMBER(20,7),
  RD26_VAL_394 NUMBER(20,7),
  RD26_VAL_EFCT_I NUMBER(20,7),
  RD26_VAL_EFCT_N NUMBER(20,7),
  RD26_VAL_EFCT_T NUMBER(20,7),
  RD26_VAL_VAMA NUMBER(20,7),
  RD27_TVA NUMBER(20,7),
  RD27_VAL NUMBER(20,7),
  RD271_TVA NUMBER(20,7),
  RD271_VAL NUMBER(20,7),
  RD272_TVA NUMBER(20,7),
  RD272_VAL NUMBER(20,7),
  RD273_TVA NUMBER(20,7),
  RD273_VAL NUMBER(20,7),
  RD28_TVA NUMBER(20,7),
  RD28_TVA_EFCT NUMBER(20,7),
  RD3_VAL NUMBER(20,7),
  RD3_VAL_390 NUMBER(20,7),
  RD30_VAL NUMBER(20,7),
  RD30_VAL_EFCT NUMBER(20,7),
  RD30_VAL_VAMA NUMBER(20,7),
  RD31_VAL NUMBER(20,7),
  RD31_VAL_390 NUMBER(20,7),
  RD4_VAL NUMBER(20,7),
  RD4_VAL_390 NUMBER(20,7),
  RD5_TVA NUMBER(20,7),
  RD5_TVA_390 NUMBER(20,7),
  RD5_VAL NUMBER(20,7),
  RD5_VAL_390 NUMBER(20,7),
  RD51_TVA NUMBER(20,7),
  RD51_TVA_390 NUMBER(20,7),
  RD51_VAL NUMBER(20,7),
  RD51_VAL_390 NUMBER(20,7),
  RD52_TVA_ETRANS NUMBER(20,7),
  RD52_VAL_ETRANS NUMBER(20,7),
  RD6_TVA NUMBER(20,7),
  RD6_TVA_390 NUMBER(20,7),
  RD6_VAL NUMBER(20,7),
  RD6_VAL_390 NUMBER(20,7),
  RD7_TVA NUMBER(20,7),
  RD7_TVA_390 NUMBER(20,7),
  RD7_TVA_VAMA NUMBER(20,7),
  RD7_VAL NUMBER(20,7),
  RD7_VAL_390 NUMBER(20,7),
  RD7_VAL_VAMA NUMBER(20,7),
  RD71_TVA NUMBER(20,7),
  RD71_TVA_390 NUMBER(20,7),
  RD71_VAL NUMBER(20,7),
  RD71_VAL_390 NUMBER(20,7),
  RD8_TVA NUMBER(20,7),
  RD8_TVA_390 NUMBER(20,7),
  RD8_VAL NUMBER(20,7),
  RD8_VAL_390 NUMBER(20,7),
  RD9_TVA NUMBER(20,7),
  RD9_TVA_394 NUMBER(20,7),
  RD9_TVA_AMEF NUMBER(20,7),
  RD9_TVA_EFCT NUMBER(20,7),
  RD9_VAL NUMBER(20,7),
  RD9_VAL_394 NUMBER(20,7),
  RD9_VAL_AMEF NUMBER(20,7),
  RD9_VAL_EFCT NUMBER(20,7),
  RD9_1_TVA NUMBER(20,7),
  RD9_1_TVA_394 NUMBER(20,7),
  RD9_1_TVA_AMEF NUMBER(20,7),
  RD9_1_TVA_EFCT NUMBER(20,7),
  RD9_1_VAL NUMBER(20,7),
  RD9_1_VAL_394 NUMBER(20,7),
  RD9_1_VAL_AMEF NUMBER(20,7),
  RD9_1_VAL_EFCT NUMBER(20,7),
  RD11_1_TVA NUMBER(20,7),
  RD11_1_TVA_394 NUMBER(20,7),
  RD11_1_TVA_AMEF NUMBER(20,7),
  RD11_1_TVA_EFCT NUMBER(20,7),
  RD11_1_VAL NUMBER(20,7),
  RD11_1_VAL_394 NUMBER(20,7),
  RD11_1_VAL_AMEF NUMBER(20,7),
  RD11_1_VAL_EFCT NUMBER(20,7),
  RD111_1_TVA_REGAC NUMBER(20,7),
  RD111_1_VAL_REGAC NUMBER(20,7),
  RD124_TVA NUMBER(20,7),
  RD124_TVA_394 NUMBER(20,7),
  RD124_VAL NUMBER(20,7),
  RD124_VAL_394 NUMBER(20,7),
  RD125_TVA NUMBER(20,7),
  RD125_TVA_394 NUMBER(20,7),
  RD125_VAL NUMBER(20,7),
  RD125_VAL_394 NUMBER(20,7),
  RD24_1_TVA NUMBER(20,7),
  RD24_1_TVA_394 NUMBER(20,7),
  RD24_1_TVA_EFCT_I NUMBER(20,7),
  RD24_1_TVA_EFCT_N NUMBER(20,7),
  RD24_1_TVA_EFCT_T NUMBER(20,7),
  RD24_1_TVA_VAMA NUMBER(20,7),
  RD24_1_VAL NUMBER(20,7),
  RD24_1_VAL_394 NUMBER(20,7),
  RD24_1_VAL_EFCT_I NUMBER(20,7),
  RD24_1_VAL_EFCT_N NUMBER(20,7),
  RD24_1_VAL_EFCT_T NUMBER(20,7),
  RD24_1_VAL_VAMA NUMBER(20,7),
  RD25_1_TVA NUMBER(20,7),
  RD25_1_TVA_394 NUMBER(20,7),
  RD25_1_TVA_EFCT_I NUMBER(20,7),
  RD25_1_TVA_EFCT_N NUMBER(20,7),
  RD25_1_TVA_EFCT_T NUMBER(20,7),
  RD25_1_TVA_VAMA NUMBER(20,7),
  RD25_1_VAL NUMBER(20,7),
  RD25_1_VAL_394 NUMBER(20,7),
  RD25_1_VAL_EFCT_I NUMBER(20,7),
  RD25_1_VAL_EFCT_N NUMBER(20,7),
  RD25_1_VAL_EFCT_T NUMBER(20,7),
  RD25_1_VAL_VAMA NUMBER(20,7),
  RD274_TVA NUMBER(20,7),
  RD274_VAL NUMBER(20,7),
  RD275_TVA NUMBER(20,7),
  RD275_VAL NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_390_394</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC5966FB1D206DA1649B32632CCED37A6E8890EF</HASHVAL>
  <TEXT>CREATE TABLE ETVA_390_394 (
  CODETVA_390_394 NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  TIP VARCHAR2(10),
  NUMAR_INREGISTRARE VARCHAR2(75),
  DATA_INREGISTRARE DATE,
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  TIP_DUK VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_AMEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFE0C0EFBF2D9B08542681CD61D2E582509F206C</HASHVAL>
  <TEXT>CREATE TABLE ETVA_AMEF (
  CODETVA_AMEF NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  DATA_Z DATE,
  NUI VARCHAR2(20),
  NR_Z VARCHAR2(20),
  VALOARE_19 NUMBER(20,7),
  TVA_19 NUMBER(20,7),
  VALOARE_9 NUMBER(20,7),
  TVA_9 NUMBER(20,7),
  VALOARE_5 NUMBER(20,7),
  TVA_5 NUMBER(20,7),
  VALOARE_0 NUMBER(20,7),
  TVA_0 NUMBER(20,7),
  VALOARE_21 NUMBER(20,7),
  TVA_21 NUMBER(20,7),
  VALOARE_11 NUMBER(20,7),
  TVA_11 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_ETRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DB041BF998B5C937486B83491BD82C207872D99</HASHVAL>
  <TEXT>CREATE TABLE ETVA_ETRANSPORT (
  CODETVA_ETRANSPORT NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DOMICILIU VARCHAR2(150),
  NUMAR_TRN VARCHAR2(20),
  PC_COD VARCHAR2(75),
  PC_DENUMIRE VARCHAR2(100),
  PC_COD_TARA VARCHAR2(5),
  TIP VARCHAR2(100),
  SCOP VARCHAR2(100),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_FACTURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>672AF77AB3D8D315F95FB0D919F69C4CA0908F61</HASHVAL>
  <TEXT>CREATE TABLE ETVA_FACTURA (
  CODETVA_FACTURA NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  DATA_SELECTIE DATE,
  DATA_INCEPUT DATE,
  DEN_CUMPARATOR VARCHAR2(200),
  NR_FACTURA VARCHAR2(50),
  TIP_FACTURA NUMBER(20,0),
  CUMP_CUI VARCHAR2(75),
  DATA_SFARSIT DATE,
  TIP VARCHAR2(10),
  DATA_EMITERE DATE,
  VANZ_CUI VARCHAR2(75),
  DEN_VANZATOR VARCHAR2(200),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  ID VARCHAR2(20),
  CIF VARCHAR2(75),
  DATA_INREGISTRARE DATE,
  DATA_LIVRARE DATE,
  DATA_SCADENTA DATE,
  COD_DATA_EXIGIBILA NUMBER(3,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_FACTURA_TVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE69FFFDAE12084F68ED34BE1FE36CE1138B60EF</HASHVAL>
  <TEXT>CREATE TABLE ETVA_FACTURA_TVA (
  CODETVA_FACTURA_TVA NUMBER(20,0) NOT NULL,
  CODETVA_FACTURA NUMBER(20,0),
  CODETVA NUMBER(20,0),
  BAZA_LEI NUMBER(20,7),
  BAZA_CALCUL NUMBER(20,7),
  COTA_TVA NUMBER(20,7),
  CATEG_TVA VARCHAR2(20),
  TVA_LEI NUMBER(20,7),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_LOCUINTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F88AB093A10F452D120057CCFB55948DF85B43A</HASHVAL>
  <TEXT>CREATE TABLE ETVA_LOCUINTE (
  CODETVA_LOCUINTE NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DOMICILIU VARCHAR2(200),
  DATA_INREGISTRARE DATE,
  NUMAR_INCHEIERE_AUTENTIF VARCHAR2(50),
  DATA_INCHEIERE_AUTENTIF DATE,
  VALOARE_LOCUINTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_VAMA_EXPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74D1E208EA6F5A8B838E33D4C726CEE8F0BB4892</HASHVAL>
  <TEXT>CREATE TABLE ETVA_VAMA_EXPORT (
  CODETVA_VAMA_EXPORT NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  NR_MRN VARCHAR2(100),
  DATA_MRN DATE,
  VALOARE NUMBER(20,7),
  MONEDA VARCHAR2(20),
  CURS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ETVA_VAMA_IMPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD6365A3ADD036E5210728A65F03D636DCF7D992</HASHVAL>
  <TEXT>CREATE TABLE ETVA_VAMA_IMPORT (
  CODETVA_VAMA_IMPORT NUMBER(20,0) NOT NULL,
  CODETVA NUMBER(20,0),
  NR_MRN VARCHAR2(100),
  DATA_MRN DATE,
  ARTICOL VARCHAR2(100),
  VAL_IMPOZABILA NUMBER(20,7),
  COTA_TVA NUMBER(2,0),
  TVA NUMBER(20,7),
  TIP_PLATA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CA1D377D55124A362BBC5FEED118C6AB5543CF9</HASHVAL>
  <TEXT>CREATE TABLE EURO (
  COD NUMBER(20,0) NOT NULL,
  CODCASA NUMBER(20,0),
  PLU NUMBER(10,0),
  DEP NUMBER(10,0),
  TVACASA NUMBER(10,0),
  OBIECT NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CONT NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  STOC NUMBER(20,7),
  FARACTRL NUMBER(1,0),
  VANDUT NUMBER(20,7),
  BARCOD VARCHAR2(30),
  PLULINK NUMBER(20,0),
  DESCRIPTIV NUMBER(1,0),
  SERVICIU NUMBER(1,0),
  CANTAR NUMBER(1,0),
  STERS NUMBER(1,0),
  SELECTAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20DABCE074D2ECECA0EF4D41B60B52E6123EA9E2</HASHVAL>
  <TEXT>CREATE TABLE EVALS (
  CODEVALS NUMBER(20,0),
  CODIDENTEVALS NUMBER(20,0),
  DEN_EVALUARE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVALSEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFD43D1B2D0643F340AE3E41AA1A306B32F87F8E</HASHVAL>
  <TEXT>CREATE TABLE EVALSEV (
  CODEVALSEV NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  CODEVALUATOR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVALSTES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D646F7441570265345E6EE04366117E04B27D8D</HASHVAL>
  <TEXT>CREATE TABLE EVALSTES (
  CODEVALSTES NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  CODTES NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVALUARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A7987F4734B2DDA816BA9EB38AD9D7345DED5D1</HASHVAL>
  <TEXT>CREATE TABLE EVALUARI (
  CODEVALUARE NUMBER(20,0),
  CODEVALUATOR NUMBER(20,0),
  DATAORA DATE,
  RUNDAEVALUARE NUMBER(20,0),
  NREVALUATORI NUMBER(20,0),
  NRESANTIOANE NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  CODDESTINATIE NUMBER(20,0),
  NUMETESATURA VARCHAR2(200),
  OBS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVALUATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49088EAA87D66919D2BAEEF2D967FE8DA5FD17FB</HASHVAL>
  <TEXT>CREATE TABLE EVALUATORI (
  CODEVALUATOR NUMBER(20,0),
  NUME VARCHAR2(200),
  ORDINE NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16D4E55700BAD43EF67FF2522B6672C71BC0BACA</HASHVAL>
  <TEXT>CREATE TABLE EVIDENTAMF (
  CODMIFIX NUMBER(20,0) NOT NULL,
  CODPART1 NUMBER(20,0),
  CODPART2 NUMBER(20,0),
  CODPART3 NUMBER(20,0),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EVOLUTIE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DA2F53460FB89E112068648B667E3212C344156</HASHVAL>
  <TEXT>CREATE TABLE EVOLUTIE (
  USERID NUMBER(20,0),
  TOTAL NUMBER(20,0),
  CURENT NUMBER(20,0),
  ACTIUNE VARCHAR2(100),
  ID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EXPCOCACOLA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6DA9FC97DEC040A850A108CD235C6EA460C6E949</HASHVAL>
  <TEXT>CREATE TABLE EXPCOCACOLA (
  STO1 TIMESTAMP(6),
  STO2 TIMESTAMP(6),
  STO3 TIMESTAMP(6),
  OTHERS TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>683C0B208AEA9D5CC7A81729C67381CB11FF803F</HASHVAL>
  <TEXT>CREATE TABLE EXPERT (
  CODEXPERT NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DIRTY NUMBER(1,0),
  CODANALIZA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EXPERT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B19591CA9F4F352D902CA7AAA7654D6A2E280402</HASHVAL>
  <TEXT>CREATE TABLE EXPERT1 (
  CODEXPERT1 NUMBER(20,0) NOT NULL,
  CODEXPERT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  INDEXJURN NUMBER(20,0),
  GESTJURN NUMBER(20,0),
  SUBUNITJURN NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  TIPCONT NUMBER(1,0),
  CODELEMENT NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  ANALIZANODJURN NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>EXPORTWME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77CFE098EE8BAF3424EC9BDB2ACB614FD7484F5F</HASHVAL>
  <TEXT>CREATE TABLE EXPORTWME (
  CODEXPORT NUMBER(20,0),
  TIPDOCUMENT VARCHAR2(20),
  ANCONTABIL NUMBER(5,0),
  LUNACONTABILA NUMBER(2,0),
  DATAORA TIMESTAMP(6),
  DATEEXPORT CLOB,
  PROCESAT NUMBER(1,0),
  IMPORTAT NUMBER(1,0),
  ERORI CLOB,
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FACTSALINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>527F44508C2B0BE7A93A063E80BB1D2CEC7DCD63</HASHVAL>
  <TEXT>CREATE TABLE FACTSALINK (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>30F7F49A87005C042B890D627DE626D99F935D58</HASHVAL>
  <TEXT>CREATE TABLE FAZ (
  CODFAZ NUMBER(20,0) NOT NULL,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CODPERS NUMBER(20,0),
  DIAGRAMA NUMBER(20,0),
  ALIMPOMPA NUMBER(20,7),
  ALIMBCF NUMBER(20,7),
  ALIMAVANS NUMBER(20,7),
  KMPLECARE NUMBER(10,0),
  KMSOSIRE NUMBER(10,0),
  KMN NUMBER(10,0),
  CSARCINA NUMBER(20,7),
  CSARCINAR NUMBER(20,7),
  CSTART NUMBER(20,7),
  CIMOTOR NUMBER(20,7),
  CCURSE NUMBER(20,7),
  CRAER NUMBER(20,7),
  CIARNA NUMBER(20,7),
  OREREGIE NUMBER(20,7),
  OREACORD NUMBER(20,7),
  OREN NUMBER(20,7),
  TONES NUMBER(20,7),
  ORES NUMBER(20,7),
  TSTART NUMBER(20,0),
  TIMOTOR NUMBER(20,0),
  TCURSE NUMBER(20,0),
  RAER NUMBER(1,0),
  PARCURSN NUMBER(1,0),
  REZERVORPLECARE NUMBER(20,7),
  CODFAZS NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CONSUM NUMBER(20,7),
  REZERVORCALC NUMBER(20,7),
  REZERVOR NUMBER(20,7),
  OBS VARCHAR2(250),
  TIPPARCURS NUMBER(10,0),
  CODBC NUMBER(20,0),
  CODDECONT NUMBER(20,0),
  CODAUTO1 NUMBER(20,0),
  CODAUTO2 NUMBER(20,0),
  PARCURSR1 NUMBER(20,7),
  PARCURSR2 NUMBER(20,7),
  PARCURS1 NUMBER(20,7),
  PARCURS2 NUMBER(20,7),
  T1 NUMBER(20,7),
  T2 NUMBER(20,7),
  ECHIV1 NUMBER(20,7),
  ECHIV2 NUMBER(20,7),
  CODGRAUTO NUMBER(20,0),
  PARCURSB NUMBER(20,7),
  PARCURSM NUMBER(20,7),
  PARCURSO NUMBER(20,7),
  B NUMBER(20,7),
  M NUMBER(20,7),
  O NUMBER(20,7),
  ECHIVB NUMBER(20,7),
  ECHIVM NUMBER(20,7),
  ECHIVO NUMBER(20,7),
  TIPAERODIN NUMBER(20,0),
  NRREM NUMBER(20,7),
  PARCURSAERO NUMBER(20,7),
  AEROSR NUMBER(20,7),
  ECHIVAERO NUMBER(20,7),
  ECHIVINST NUMBER(20,7),
  CODINTR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODTREZOR NUMBER(20,0),
  CMM NUMBER(20,7),
  CONSSTAT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZ0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F419E38212370313D5BBEFB7AC28EACD44CA5B20</HASHVAL>
  <TEXT>CREATE TABLE FAZ0 (
  CODFAZ0 NUMBER(20,0) NOT NULL,
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  KMPLECARE NUMBER(20,7),
  KMSOSIRE NUMBER(20,7),
  DATAPLECARE DATE,
  CODPERS NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDOC VARCHAR2(30),
  NRDOC VARCHAR2(30),
  RUTA VARCHAR2(200),
  TIPTRANSPORT VARCHAR2(50),
  CANT NUMBER(20,7),
  KMINC NUMBER(20,7),
  KMGOL NUMBER(20,7),
  OBS VARCHAR2(250),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EBD910C3D9D071F1FC0A04E83B0FC4DF2E5238F1</HASHVAL>
  <TEXT>CREATE TABLE FAZ1 (
  CODFAZ1 NUMBER(20,0) NOT NULL,
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  KM NUMBER(20,7),
  INCARCAT NUMBER(1,0),
  TIPSURSA NUMBER(20,0),
  CATDRUM NUMBER(20,0),
  COEF NUMBER(20,7),
  CODFAZ0 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZ2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD1A67336F65C39F4E0E19F500737840B688861A</HASHVAL>
  <TEXT>CREATE TABLE FAZ2 (
  CODFAZ2 NUMBER(20,0) NOT NULL,
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODINSTAUTO NUMBER(20,0),
  CANT NUMBER(20,7),
  SPOR NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZ3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF0230A80D1746A3408E395EA27BFC716D98BFA6</HASHVAL>
  <TEXT>CREATE TABLE FAZ3 (
  CODFAZ3 NUMBER(20,0) NOT NULL,
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODTRASEU NUMBER(20,0),
  PARCURGERI NUMBER(10,0),
  KMTRASEU NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FAZINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02CFB9DABB8F0FE305B9EAE476E7FD0FAFCF0656</HASHVAL>
  <TEXT>CREATE TABLE FAZINTR (
  CODFAZINTR NUMBER(20,0) NOT NULL,
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CANTCOMB NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FIRMALUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1428B9AA41966CD878407E4A69A82437D9F9DB35</HASHVAL>
  <TEXT>CREATE TABLE FIRMALUNI (
  ANCURENT NUMBER(4,0),
  LUNACURENTA NUMBER(2,0),
  ANINITIAL NUMBER(4,0),
  LUNAINITIALA NUMBER(2,0),
  ANMAXIM NUMBER(4,0),
  LUNAMAXIMA NUMBER(2,0),
  ANBLOCAT NUMBER(4,0),
  LUNABLOCATA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FIRMECUPLATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>899FEE8549852BB32AEA967155EE1195A9AC67F2</HASHVAL>
  <TEXT>CREATE TABLE FIRMECUPLATE (
  COD NUMBER(20,0),
  ID VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAEVALP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5423B03B979C5405875C9FE5D6EA587FC04E367A</HASHVAL>
  <TEXT>CREATE TABLE FISAEVALP (
  CODFISA NUMBER(20,0),
  CODEVALUARE NUMBER(20,0),
  CR NUMBER(2,0),
  EN NUMBER(2,0),
  MT NUMBER(2,0),
  FR NUMBER(2,0),
  SG NUMBER(2,0),
  NA NUMBER(2,0),
  AN NUMBER(2,0),
  UG NUMBER(2,0),
  NUMETESATURA VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAEVALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>734D6871F0A3487077063AF13830A1EF6DFC71C1</HASHVAL>
  <TEXT>CREATE TABLE FISAEVALT (
  CODFISA NUMBER(20,0),
  CODEVALUARE NUMBER(20,0),
  NOTA NUMBER(2,0),
  NUMETESATURA VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAINF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8AE18200C1E06A13A5693C458143C62BFC39839</HASHVAL>
  <TEXT>CREATE TABLE FISAINF (
  CODFISAINF NUMBER(20,0) NOT NULL,
  CODFISASUP NUMBER(20,0),
  POZNOM NUMBER(10,0),
  CODOBIECTINF NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANTINSUP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  DIMT VARCHAR2(50),
  COMPLEX NUMBER(1,0),
  MATERIAL NUMBER(1,0),
  CODFISAPRO NUMBER(20,0),
  UMDIMT NUMBER(20,0),
  CONSUMATOR NUMBER(20,0),
  MASA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A29E654BDFD1B7531CF4FA420DE15337361312EC</HASHVAL>
  <TEXT>CREATE TABLE FISAMAN (
  CODFISAMAN NUMBER(20,0) NOT NULL,
  CODTRASEU NUMBER(20,0),
  NROP NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODLOCM NUMBER(20,0),
  CODDIF NUMBER(10,0),
  DSV NUMBER(10,0),
  TPI NUMBER(10,0),
  TU NUMBER(10,0),
  BPS NUMBER(10,0),
  FINAL NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  CODFISATEH NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAMAND</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>337B54E8FD3C81FD8EF8DDFAE38086AD761D1C5A</HASHVAL>
  <TEXT>CREATE TABLE FISAMAND (
  CODFISAMAND NUMBER(20,0) NOT NULL,
  CODFISAMAN NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODDIF NUMBER(20,0),
  TPI NUMBER(10,0),
  TU NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A19C25240D33260BD9F70DF6FBC37B712E3E8980</HASHVAL>
  <TEXT>CREATE TABLE FISAMAS (
  CODFISAMAS NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  CODRESPONSABIL NUMBER(20,0),
  CODINSPECTOR NUMBER(20,0),
  OBS VARCHAR2(250),
  APROBAT NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAMAS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4CF6D399BEB7D2EF8E4C3E67E799A8B3D31AEAC0</HASHVAL>
  <TEXT>CREATE TABLE FISAMAS1 (
  CODFISAMAS1 NUMBER(20,0),
  CODFISAMAS NUMBER(20,0),
  CODPRODMAS NUMBER(20,0),
  VALOARE NUMBER(20,7),
  STARE NUMBER(10,0),
  OBS VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75F7EC7B00ED3ED1FD21A8FFE8E1139A8C5CDB03</HASHVAL>
  <TEXT>CREATE TABLE FISAMF (
  CODFISAMF NUMBER(20,0) NOT NULL,
  CODMIFIX NUMBER(20,0),
  CODOPERATIE NUMBER(5,0),
  DATAOPERATIE DATE,
  GESTSURSA NUMBER(20,0),
  GESTDEST NUMBER(20,0),
  PRETI NUMBER(20,7),
  PRETE NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISAREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>111E88D08DB78416AA078A08B662C35A35117445</HASHVAL>
  <TEXT>CREATE TABLE FISAREZ (
  CODFISAREZ NUMBER(20,0) NOT NULL,
  CODTRASEU NUMBER(20,0),
  CODPREZ NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  CODFISATEH NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISASDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A1ECF68488F9172BE2F76F8D3D05041674E8C3C</HASHVAL>
  <TEXT>CREATE TABLE FISASDV (
  CODFISASDV NUMBER(20,0) NOT NULL,
  CODFISAMAN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODSDV NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISASUP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BD91E4BDA22D5B79C752F94C54BDEEDBA4AD2BA</HASHVAL>
  <TEXT>CREATE TABLE FISASUP (
  CODFISASUP NUMBER(20,0) NOT NULL,
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECTNOD NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  OBS VARCHAR2(3000),
  PROIECTANT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  BLOCAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FISATEH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9509CC0DAB17F36E90F2A88CEBC3C925664BD3EF</HASHVAL>
  <TEXT>CREATE TABLE FISATEH (
  CODFISATEH NUMBER(20,0) NOT NULL,
  CODFISASUP NUMBER(20,0),
  INTOCMITA NUMBER(20,0),
  DATAFISA DATE,
  FINALIZATA NUMBER(1,0),
  BLOCATA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FORMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E64F83D51D8356D2CF9E8686B21BA7AC2ACA250</HASHVAL>
  <TEXT>CREATE TABLE FORMATII (
  CODFORMATIE NUMBER(20,0) NOT NULL,
  DEN_FORMATIE VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FORMATII1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DDC0B3050B9D94947874FD40CA01806B0315BFC</HASHVAL>
  <TEXT>CREATE TABLE FORMATII1 (
  CODFORMATIE1 NUMBER(20,0) NOT NULL,
  CODFORMATIE NUMBER(20,0),
  LOCMUNCA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FORMATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFCF31D025FF9E258A0374D05E9B1E9C345B0A74</HASHVAL>
  <TEXT>CREATE TABLE FORMATORI (
  CODFORMATOR NUMBER(20,0) NOT NULL,
  DEN_FORMATOR VARCHAR2(30),
  EMAIL VARCHAR2(100),
  TELEFON VARCHAR2(20),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUNCTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8EDB36F2C9AD0B67654444FC5DEF66C0031C85FB</HASHVAL>
  <TEXT>CREATE TABLE FUNCTII (
  CODFUNCTIE NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  CODEXTERN VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUNCTII1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54776D5780C3C7739BC7985D43020501414A38B1</HASHVAL>
  <TEXT>CREATE TABLE FUNCTII1 (
  CODFUNCTIE1 NUMBER(20,0) NOT NULL,
  CODFUNCTIE NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B968A356D98CC2C26712CC16448EC62832F534F3</HASHVAL>
  <TEXT>CREATE TABLE FUZART (
  CODARTINIT NUMBER(20,0),
  CODARTFIN NUMBER(20,0),
  CODOBJINIT NUMBER(20,0),
  CODOBJFIN NUMBER(20,0),
  CODEXTERNINIT VARCHAR2(80),
  CODEXTERNFIN VARCHAR2(80),
  PRODINIT VARCHAR2(50),
  PRODFIN VARCHAR2(50),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE,
  CODINTERNINIT VARCHAR2(80),
  CODINTERNFIN VARCHAR2(80)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C462A71C406DC27BC8ADF3731FF496B5930B870</HASHVAL>
  <TEXT>CREATE TABLE FUZAUTO (
  CODAUTOINIT NUMBER(20,0),
  CODAUTOFIN NUMBER(20,0),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>155BBDF9C7E3377D4FD99BD82EBB18330D2C9FEB</HASHVAL>
  <TEXT>CREATE TABLE FUZGEST (
  CODGESTINIT NUMBER(20,0),
  CODGESTFIN NUMBER(20,0),
  SUBUNITINIT VARCHAR2(100),
  SUBUNITFIN VARCHAR2(100),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC2D1790BA35CADE50253C4345E8E9B6E42CBDE5</HASHVAL>
  <TEXT>CREATE TABLE FUZLOCALIT (
  CODLOCALITINIT NUMBER(20,0),
  CODLOCALITFIN NUMBER(20,0),
  SIMBAUTOINIT VARCHAR2(2),
  SIMBAUTOFIN VARCHAR2(2),
  DENSUPINIT VARCHAR2(50),
  DENSUPFIN VARCHAR2(50),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AD82BD6E11521E4FE54FCA458CB52075990BEAE</HASHVAL>
  <TEXT>CREATE TABLE FUZPART (
  CODPARTINIT NUMBER(20,0),
  CODPARTFIN NUMBER(20,0),
  CODLOCINIT NUMBER(20,0),
  CODLOCFIN NUMBER(20,0),
  CODEXTINIT VARCHAR2(50),
  CODEXTFIN VARCHAR2(50),
  CODFISCINIT VARCHAR2(75),
  CODFISCFIN VARCHAR2(75),
  LOCALITINIT VARCHAR2(50),
  LOCALITFIN VARCHAR2(50),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE,
  TELEFONINIT VARCHAR2(40),
  TELEFONFIN VARCHAR2(40)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>FUZPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1DA5A04C3203D78990B84190B885E4910428731</HASHVAL>
  <TEXT>CREATE TABLE FUZPERS (
  CODPERSINIT NUMBER(20,0),
  CODPERSFIN NUMBER(20,0),
  SUBUNITINIT VARCHAR2(100),
  SUBUNITFIN VARCHAR2(100),
  INFOINIT VARCHAR2(750),
  INFOFIN VARCHAR2(750),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D59DE42AB2409A4E82F30622DFC8DA38D3D36FE7</HASHVAL>
  <TEXT>CREATE TABLE GANTT (
  CODGANTT NUMBER(20,0) NOT NULL,
  CODCMDPRODMAN NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DSTART DATE,
  CANT NUMBER(10,0),
  NSTART DATE,
  OSTART NUMBER(7,3),
  PRIORITATE NUMBER(20,0),
  DIRECTIE NUMBER(1,0),
  OSTOP NUMBER(7,3),
  BLOCAT NUMBER(1,0),
  ORDINE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GANTT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26A7D038C6CB21FFFCB1FC7F68A7C62951D1F6DD</HASHVAL>
  <TEXT>CREATE TABLE GANTT1 (
  CODGANTT1 NUMBER(20,0) NOT NULL,
  CODGANTT NUMBER(20,0),
  DEPLASARE NUMBER,
  CANT NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GENERAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3ABE1C1EC9B16C95B58B0537877742095F36019A</HASHVAL>
  <TEXT>CREATE TABLE GENERAL (
  CODGENERAL NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  ICONTAVANS NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  DATATVA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GENERAL_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>299DFD5E56849D6AE42E79171FBA193890344472</HASHVAL>
  <TEXT>CREATE TABLE GENERAL_REG (
  CODREG NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  CURS NUMBER(20,7),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GENMONETARERETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49444FE1B91472FA0C977F882767071701805E11</HASHVAL>
  <TEXT>CREATE TABLE GENMONETARERETAIL (
  CODPOSTRETAIL NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  CARNETCMD NUMBER(20,0),
  CARNETNP NUMBER(20,0),
  CARNETBC NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  CONTCASH NUMBER(20,0),
  CONTCEC NUMBER(20,0),
  CONTCARD NUMBER(20,0),
  CONTTICHET NUMBER(20,0),
  DESCARCAREPROD NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GRECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A19F79EE82F7A47CA67517F49A2DED16FD3C0E29</HASHVAL>
  <TEXT>CREATE TABLE GRECHIV (
  CODGRECHIV NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(250),
  COD VARCHAR2(32),
  IND NUMBER(10,0),
  INFO VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>GRUPEDRUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1AAEE77A2C140B1E0CAC743905F8758DF9A4A8A1</HASHVAL>
  <TEXT>CREATE TABLE GRUPEDRUM (
  CODGRUPA NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  COEF NUMBER(20,7),
  DESCRIERE CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IDENTEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7030BDE85A7C5FD40D441F3D739F94F16471CD2C</HASHVAL>
  <TEXT>CREATE TABLE IDENTEVALS (
  CODIDENTEVALS NUMBER(20,0),
  NUME VARCHAR2(50),
  DATAORA DATE,
  NREVALUATORI NUMBER(3,0),
  NRESANTIOANE NUMBER(3,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IDSEDIULOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7CEBB829B56A2ED9FB86FB1821AAB07F7E490CD</HASHVAL>
  <TEXT>CREATE TABLE IDSEDIULOCK (
  COD NUMBER(20,0),
  IDSEDIU VARCHAR2(20),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69F980BEBF41D1AC1C61D1BEDB69E49A2499CD4C</HASHVAL>
  <TEXT>CREATE TABLE IESDISC (
  CODIESDISC NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  OFFINVOICE NUMBER(1,0),
  PROCENT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C48E67D3B984CAE5128F3F1E9136C12A089B640F</HASHVAL>
  <TEXT>CREATE TABLE IESIRI (
  CODIES NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  CARNETAE NUMBER(20,0),
  NRAE NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ACCIZE NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  MAJORARI NUMBER(20,7),
  OBS VARCHAR2(500),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  BUGETARE NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  TIPFACTURA NUMBER(10,0),
  CODGESTPROD NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  TIPCONSUMATOR NUMBER(2,0),
  CODAUTO NUMBER(20,0),
  PARTCUSTODIE NUMBER(20,0),
  CODCMDINTERNA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  COMISION NUMBER(20,7),
  CODBANKCONT NUMBER(20,0),
  TIPCASAMARCAT NUMBER(5,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPTRANZACTIE NUMBER(5,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  DISCVOL NUMBER(20,7),
  DISCTER NUMBER(20,7),
  MONEDATRANSF NUMBER(20,7),
  NRI VARCHAR2(50),
  CONTSUPLIM NUMBER(20,0),
  DATAINREG TIMESTAMP(6),
  CUSTODIE NUMBER(1,0),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  CARNETCERTIF NUMBER(20,0),
  NRCERTIF NUMBER(20,0),
  SERIACERTIF VARCHAR2(10),
  STARERESTITUIRE NUMBER(1,0),
  IDIMPORT VARCHAR2(30),
  LISTATCERTIF NUMBER(1,0),
  FARAREG NUMBER(1,0),
  CODPERSC NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  CODIESMAMB NUMBER(20,0),
  PROCTVADOC NUMBER(20,7),
  CODANALIZA NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  TVAINCASARE NUMBER(1,0),
  DATATVA DATE,
  CODCONTRACT NUMBER(20,0),
  FACTSIMPLIF NUMBER(1,0),
  TRANSPORTATOR NUMBER(20,0),
  STADIUWMS NUMBER(2,0),
  CODMONETAR NUMBER(20,0),
  NUMARBONURI NUMBER(5,0),
  EMISADECLIENT NUMBER(1,0),
  NRINFOCM NUMBER(5,0),
  NRINCASULT NUMBER(5,0),
  NRINCASIM NUMBER(5,0),
  CODPARTTERT NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  NATURATRANZ NUMBER(2,0),
  MODTRANSP NUMBER(2,0),
  SPLITTVA NUMBER(1,0),
  GRATIE NUMBER(10,0),
  TIPSAFT NUMBER(2,0),
  CODTVASERV NUMBER(20,0),
  PROCTVAOSS NUMBER(6,3),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  NOACCIZE NUMBER(1,0),
  NRNIR VARCHAR2(20),
  DATANIR DATE,
  PLATFORMA_ONLINE NUMBER(2,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7),
  REMORCA NUMBER(20,0),
  PROIECT VARCHAR2(20),
  CONTRACT VARCHAR2(20),
  COMANDA VARCHAR2(20),
  EXCLUSINTRASTAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>641073333E5D9DDA1961F92573EB36FA89BA0FFA</HASHVAL>
  <TEXT>CREATE TABLE IESIRI1 (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  TIPLIVRARE NUMBER(1,0),
  GARANTIE NUMBER(20,0),
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  MIFIX NUMBER(1,0),
  ZILE NUMBER(5,0),
  COSTTRANSPORT NUMBER(20,7),
  ZILECMD NUMBER(20,0),
  CODLIVR1PRODVAL NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CADOU NUMBER(20,0),
  TIPPLATA NUMBER(1,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODIOARTCUST NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  CANTCORELAT NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  CODOBLIGMONETAR NUMBER(20,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1D3BCS NUMBER(1,0),
  CODOBLIGMAJORAT NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  ICONTPART NUMBER(2,0),
  CANTCONSTATAT NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  IMPOZABIL NUMBER(1,0),
  PRETUM1 NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODPARTCOMISEMUL NUMBER(20,0),
  ADMAX NUMBER(20,7),
  VALFIN NUMBER(20,7),
  TVAFIN NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRI1RETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E2EEE2B658EEACF1E5067A8C5A59E296165BFB3</HASHVAL>
  <TEXT>CREATE TABLE IESIRI1RETAIL (
  CODIES1RETAIL NUMBER(20,0) NOT NULL,
  CODIESRETAIL NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  GARANTIE NUMBER(20,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  ZILE NUMBER(5,0),
  CADOU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  TAXA NUMBER(1,0),
  CODAGENTEMULARE NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODIOARTVAL NUMBER(20,0),
  TVANEEX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRI1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E9892432BCEABF6DAE8B9D2D213E4B6564EF82D3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE IESIRI1_MAN (
  CODIES1 NUMBER(20,0),
  CODIES NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  TIPLIVRARE NUMBER(1,0),
  GARANTIE NUMBER(20,0),
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  MIFIX NUMBER(1,0),
  ZILE NUMBER(5,0),
  COSTTRANSPORT NUMBER(20,7),
  ZILECMD NUMBER(20,0),
  CODLIVR1PRODVAL NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CADOU NUMBER(20,0),
  TIPPLATA NUMBER(1,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODIOARTCUST NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  CANTCORELAT NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  CODOBLIGMONETAR NUMBER(20,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1D3BCS NUMBER(1,0),
  CODOBLIGMAJORAT NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  ICONTPART NUMBER(2,0),
  CANTCONSTATAT NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  IMPOZABIL NUMBER(1,0),
  PRETUM1 NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODPARTCOMISEMUL NUMBER(20,0),
  ADMAX NUMBER(20,7),
  VALFIN NUMBER(20,7),
  TVAFIN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRIRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1E7AA1066A73BA72297D54982CB1A3AA1F974046</HASHVAL>
  <TEXT>CREATE TABLE IESIRIRETAIL (
  CODIESRETAIL NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODPARTRETAIL NUMBER(20,0),
  PARTENER NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  OBS VARCHAR2(450),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODFISCALRETAIL NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODSEDIURETAIL NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  NRI VARCHAR2(30),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  PROCTVADOC NUMBER(20,7),
  DATATVA DATE,
  TIPMODIF VARCHAR2(1),
  AGENT NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESIRI_PDX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>579AED8043AC7BE38F966ACF779AF5C406C07EF2</HASHVAL>
  <TEXT>CREATE TABLE IESIRI_PDX (
  CODIES NUMBER(20,0),
  NRDOC NUMBER(20,0),
  ZI NUMBER(20,0),
  PART NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  ART NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  CANTIES1 NUMBER(20,7),
  PRET NUMBER(20,7),
  CANTLIVR NUMBER(20,7),
  CODSTOC NUMBER(20,0),
  PART_WME NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  DATADOC DATE,
  TIPDOC NUMBER(5,0),
  PREFIXDOC VARCHAR2(5),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72EA0B9FB1BAC0FE91AC64823767C37E710F8EEA</HASHVAL>
  <TEXT>CREATE TABLE IESLINK (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESPRODLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EF59E2D46D73204FCA799008343CEDA4CA07DEE</HASHVAL>
  <TEXT>CREATE TABLE IESPRODLINK (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODCMDPRODMAT NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESPUNCTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E7E91EAAF3E000DF21655AB86E354FB4B2EC8C95</HASHVAL>
  <TEXT>CREATE TABLE IESPUNCTE (
  CODIESPUNCTE NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  PUNCTEDOC NUMBER(20,7),
  PUNCTEANULATE NUMBER(20,7),
  PUNCTESTINSE NUMBER(20,7),
  BLOCAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IESVALLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BF0C11AB45E46AB83C4DC8F48812E405C7BD046</HASHVAL>
  <TEXT>CREATE TABLE IESVALLINK (
  CODIES1 NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES NUMBER(20,0),
  TIPLINK NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IMBMIFIXLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6EE32B23B5DB9F98071162E24149B895811BE8D3</HASHVAL>
  <TEXT>CREATE TABLE IMBMIFIXLINK (
  CODIMBMIFIXLINK NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IMP_CODP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC0C6396D755957A5BFA61E4FC84FA63676AE948</HASHVAL>
  <TEXT>CREATE TABLE IMP_CODP (
  SIRUTA VARCHAR2(500),
  CODPOSTAL VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IMP_UM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22AD45C5B0BEBA14BBAF1B8C7D71F7DCC8E2A865</HASHVAL>
  <TEXT>CREATE TABLE IMP_UM (
  CODSAFT VARCHAR2(500),
  NAME VARCHAR2(1000),
  DENUMIRE VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INACTIVRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1B09CEFD02CA5D33C92428229844B522798DFCC</HASHVAL>
  <TEXT>CREATE TABLE INACTIVRETAIL (
  CODINACTIVRETAIL NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INFOACTUALCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E90D0C43E4BA71DE7793BDC5B4D744129573CB11</HASHVAL>
  <TEXT>CREATE TABLE INFOACTUALCONST (
  CODCONST1 NUMBER(20,0),
  DENCONST VARCHAR2(100),
  SIMBOL VARCHAR2(100),
  INDEXCONST VARCHAR2(10),
  TIPOPER VARCHAR2(1),
  VALOARE VARCHAR2(300),
  TIPCONST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INFOBUFFER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8DCCB50A528BF2C1E6CFB2D16253E2708A1A94E</HASHVAL>
  <TEXT>CREATE TABLE INFOBUFFER (
  INFOTIME TIMESTAMP(6),
  INFOLINE VARCHAR2(200),
  DETALII CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INPUTBUFFER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8651045FCD9A1F9AE812B311279FD863380A8854</HASHVAL>
  <TEXT>CREATE TABLE INPUTBUFFER (
  LINE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTERFATAKLG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0FA30AAE437EE254A52CAE142FA2456244D3CE9</HASHVAL>
  <TEXT>CREATE TABLE INTERFATAKLG (
  COD NUMBER(20,0) NOT NULL,
  TIPMESAJ VARCHAR2(30),
  DATA TIMESTAMP(6),
  NUMEFISIER VARCHAR2(50),
  XML CLOB,
  IDMESAJ VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8EC1FA3E92EF989B16C7278501DA6A2F6D6725F0</HASHVAL>
  <TEXT>CREATE TABLE INTRARI (
  CODINTR NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  MAJORARI NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  COMPLEX NUMBER(1,0),
  SATELIT NUMBER(1,0),
  INITIALIZARI NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  BUGETARE NUMBER(1,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  TIPREPSUPLIM NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  TIPFACTURA NUMBER(10,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPTRANZACTIE NUMBER(5,0),
  DISCVOL NUMBER(20,7),
  DISCTER NUMBER(20,7),
  NRI VARCHAR2(20),
  SCHIMB NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  IDIMPORT VARCHAR2(30),
  DELEGAT NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  PRORATA NUMBER(3,0),
  CODCONTRACT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  TVAINCASARE NUMBER(1,0),
  TVAINCASARE_F NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  TRANSPORTATOR NUMBER(20,0),
  VALTRANSPORT NUMBER(20,7),
  CUSTODIE NUMBER(1,0),
  FACTSIMPLIF NUMBER(1,0),
  AGENT NUMBER(20,0),
  CURSNIR NUMBER(20,7),
  STADIUWMS NUMBER(2,0),
  DATAREFSCAD DATE,
  AUTOFACTURARE NUMBER(1,0),
  TIPLIVRARE NUMBER(2,0),
  NATURATRANZ NUMBER(2,0),
  MODTRANSP NUMBER(2,0),
  SPLITTVA NUMBER(1,0),
  ORDONANTAT NUMBER(1,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  PROCSTOPAJ NUMBER(5,2),
  TIPSAFT NUMBER(2,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  ROTEFACT NUMBER(1,0),
  IDDESCARCARE VARCHAR2(20),
  VALDOCEFACT NUMBER(20,7),
  DATATVA DATE,
  APROBAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRARI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADA8B06B47B8830338E0811060A0E146F3A822DA</HASHVAL>
  <TEXT>CREATE TABLE INTRARI1 (
  CODINTR1 NUMBER(20,0) NOT NULL,
  CODINTR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(10,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  CONTSERV NUMBER(10,0),
  GESTACT NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  ADDIM NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  NRCERTIF VARCHAR2(25),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  PURIDICATA NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  FURNAVIZSUBUNIT NUMBER(20,0),
  DATAACHIZAVIZSUBUNIT DATE,
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  MIFIX NUMBER(1,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(200),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ZILE NUMBER(5,0),
  CODCMD1AE NUMBER(20,0),
  ZILECMD NUMBER(5,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODINTR1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CUSTODIE NUMBER(1,0),
  RESTASTEPTARE NUMBER(20,7),
  CONTASTEPTARE NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  TAXA NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  TERMENCONTRACT DATE,
  PRETUM1 NUMBER(20,7),
  ICONTPART NUMBER(2,0),
  ROTVALTAXA NUMBER(2,0),
  CODINTR1LINK NUMBER(20,0),
  CODNIMOB NUMBER(20,0),
  GESTPRODAVIZSUB NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  IMPOZABIL NUMBER(1,0),
  TIPDOCIMP NUMBER(5,0),
  ADMAX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRARI1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0FF5FD0464B0FDE65EDBFA848AF02F9851C6143D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE INTRARI1_MAN (
  CODINTR1 NUMBER(20,0),
  CODINTR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(10,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  CONTSERV NUMBER(10,0),
  GESTACT NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  ADDIM NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  NRCERTIF VARCHAR2(25),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  PURIDICATA NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  FURNAVIZSUBUNIT NUMBER(20,0),
  DATAACHIZAVIZSUBUNIT DATE,
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  MIFIX NUMBER(1,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(200),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ZILE NUMBER(5,0),
  CODCMD1AE NUMBER(20,0),
  ZILECMD NUMBER(5,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODINTR1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CUSTODIE NUMBER(20,0),
  RESTASTEPTARE NUMBER(20,7),
  CONTASTEPTARE NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  TAXA NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  TERMENCONTRACT DATE,
  PRETUM1 NUMBER(20,7),
  ICONTPART NUMBER(2,0),
  ROTVALTAXA NUMBER(2,0),
  CODINTR1LINK NUMBER(20,0),
  CODNIMOB NUMBER(20,0),
  GESTPRODAVIZSUB NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  IMPOZABIL NUMBER(1,0),
  TIPDOCIMP NUMBER(5,0),
  ADMAX NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRASTEPTLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EA477CF7493F46BB8B644B55BE356956D5051C8</HASHVAL>
  <TEXT>CREATE TABLE INTRASTEPTLINK (
  CODINTR1 NUMBER(20,0),
  CODLINIEFACTURA NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRDOCTRANSP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3907027FED44A58CE49FB96B431D48AD662CC3C9</HASHVAL>
  <TEXT>CREATE TABLE INTRDOCTRANSP (
  COD NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODINTRLINK NUMBER(20,0),
  VALTRANSPORT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A20805ED2041F44AB779720A905010CF7C9EC41</HASHVAL>
  <TEXT>CREATE TABLE INTRLINK (
  CODINTR1 NUMBER(20,0) NOT NULL,
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INTRPRODLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A7D3C35506D08566275191C82E3B8C0E4E4F3AE3</HASHVAL>
  <TEXT>CREATE TABLE INTRPRODLINK (
  CODINTR1 NUMBER(20,0) NOT NULL,
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74133B7B0A45AE8D051CD0421CCE7570F69F534E</HASHVAL>
  <TEXT>CREATE TABLE INVENTAR (
  CODINVENTAR NUMBER(20,0) NOT NULL,
  NRINVENTAR NUMBER(10,0),
  DATAINVENTAR DATE,
  GESTIUNE NUMBER(20,0),
  RESPONSABIL NUMBER(20,0),
  OBSERVATII VARCHAR2(250),
  TIP NUMBER(1,0),
  DIMINUARE NUMBER(20,0),
  MARIRE NUMBER(20,0),
  FACTURARE NUMBER(20,0),
  IART NUMBER(1,0),
  ITIPCONT NUMBER(1,0),
  SUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPREZOLVARE NUMBER(10,0),
  FLGPALM NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ICLASE NUMBER(1,0),
  IPROD NUMBER(1,0),
  ICLASES NUMBER(1,0),
  ICLASEW NUMBER(1,0),
  REZDIF NUMBER(1,0),
  MARJA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C236D66D21049FFA5C5CE32FB9C9F29C25F41AFE</HASHVAL>
  <TEXT>CREATE TABLE INVENTAR1 (
  CODINVENTAR1 NUMBER(20,0) NOT NULL,
  CODINVENTAR NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  SCRIPTIC NUMBER(20,7),
  FAPTIC NUMBER(20,7),
  SCRIPTICUM1 NUMBER(20,7),
  FAPTICUM1 NUMBER(20,7),
  SCRIPTICUM2 NUMBER(20,7),
  FAPTICUM2 NUMBER(20,7),
  EXPIRARE DATE,
  REZOLVAT NUMBER(1,0),
  VALOARE NUMBER(20,7),
  ORDINE NUMBER(20,0),
  UM1 NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPSERIE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTAR1_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DBABCCB7BD5715CBCB922FA25C4C4FA795347804</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE INVENTAR1_CLONA (
  CODINVENTAR1 NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  SCRIPTIC NUMBER(20,7),
  FAPTIC NUMBER(20,7),
  SCRIPTICUM1 NUMBER(20,7),
  FAPTICUM1 NUMBER(20,7),
  SCRIPTICUM2 NUMBER(20,7),
  FAPTICUM2 NUMBER(20,7),
  EXPIRARE DATE,
  REZOLVAT NUMBER(1,0),
  VALOARE NUMBER(20,7),
  ORDINE NUMBER(20,0),
  UM1 NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPSERIE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTCLASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85734C9C502B65972E4138EEA5AFDBA0870AD607</HASHVAL>
  <TEXT>CREATE TABLE INVENTCLASE (
  CODINVENTCLASE NUMBER(20,0) NOT NULL,
  CODINVENTAR NUMBER(20,0),
  CODCLASEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTCLASES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7901B0D012DFB56A3808D42F8E5633E168FBDAA</HASHVAL>
  <TEXT>CREATE TABLE INVENTCLASES (
  CODINVENTCLASES NUMBER(20,0) NOT NULL,
  CODINVENTAR NUMBER(20,0),
  CODCLASEAS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79FB3B15A5D14B7EAEEA832F72D4F5D4E1D80FC3</HASHVAL>
  <TEXT>CREATE TABLE INVENTCONT (
  CODINVENTCONT NUMBER(20,0) NOT NULL,
  CODINVENTAR NUMBER(20,0),
  CODTIPCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>251581A7A2678C5B0F27D0D85E16EBCD9415A733</HASHVAL>
  <TEXT>CREATE TABLE INVENTPROD (
  CODINVENTPROD NUMBER(20,0) NOT NULL,
  CODINVENTAR NUMBER(20,0),
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03F23D0EA0F754DF444BD4BEC1B31F181234A7FB</HASHVAL>
  <TEXT>CREATE TABLE INVENTREZ (
  CODREZOLVARE NUMBER(20,0) NOT NULL,
  CODINVENTAR1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  REZOLVAT NUMBER(20,7),
  REZOLVATUM1 NUMBER(20,7),
  REZOLVATUM2 NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  TVA NUMBER(10,7),
  TG TIMESTAMP(6),
  PRETMAXIMAL NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  DATAACHIZ DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DFB0A32E31E87B4008CCCFE118BD7B4028F48BFC</HASHVAL>
  <TEXT>CREATE TABLE INVENTSTOC (
  CODINVENTSTOC NUMBER(20,0) NOT NULL,
  CODINVENTAR1 NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>INVENTSTOC_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8178E669F0A666714812046B3ADC7BBF08A91B73</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE INVENTSTOC_CLONA (
  CODINVENTSTOC NUMBER(20,0) NOT NULL,
  CODINVENTAR1 NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D8439857F95F2C6F72DECEE64BBA703D8EDBDD8</HASHVAL>
  <TEXT>CREATE TABLE IOART (
  CODIOART NUMBER(20,0) NOT NULL,
  DEN_IOART VARCHAR2(60),
  SIMBOL VARCHAR2(15),
  CODVANZARE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>362E408B8297AD30A49F21E47AD172CF5108B1FB</HASHVAL>
  <TEXT>CREATE TABLE IOART1 (
  CODIOART1 NUMBER(20,0) NOT NULL,
  CODIOART NUMBER(20,0),
  CONT NUMBER(20,0),
  DIFERENTE NUMBER(20,0),
  CHELTUIELI NUMBER(20,0),
  VENITURI NUMBER(20,0),
  PLUSINVENTAR NUMBER(20,0),
  MINUSINVENTAR NUMBER(20,0),
  CHELTTVACOLECTAT NUMBER(20,0),
  CONTROTUNJIRI NUMBER(20,0),
  DIVERSE NUMBER(20,0),
  CUSTODIE NUMBER(20,0),
  ACCIZELATRANSFER NUMBER(1,0),
  DESCARCAREG NUMBER(1,0),
  CONTABGEST NUMBER(1,0),
  BAZA NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  TVANEEX VARCHAR2(10),
  MG NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PUSTANDARD NUMBER(1,0),
  PROVIZION NUMBER(20,0),
  CHELTPROVIZION NUMBER(20,0),
  VENITPROVIZION NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOARTLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CBC9A2EEBD80899F0D3E4A7D733BA21F4850FA6C</HASHVAL>
  <TEXT>CREATE TABLE IOARTLINK (
  CODIOARTLINK NUMBER(20,0) NOT NULL,
  CODIOART NUMBER(20,0),
  CODMACHETA NUMBER(10,0),
  CODIOARTECHIV NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA1CCC204096D35C30B4CFF41BD1ED8106DEA8AD</HASHVAL>
  <TEXT>CREATE TABLE IOBANK (
  CODIOBANK NUMBER(20,0) NOT NULL,
  DEN_IOBANK VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOBANK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0E9EACCD63DC748F652FAF200C08E502777360E</HASHVAL>
  <TEXT>CREATE TABLE IOBANK1 (
  CODIOBANK1 NUMBER(30,0),
  CODIOBANK NUMBER(20,0),
  CONT NUMBER(20,0),
  DOBANDA NUMBER(20,0),
  COMISION NUMBER(20,0),
  CHELTUIELICV NUMBER(20,0),
  VENITURICV NUMBER(20,0),
  PCEC NUMBER(20,0),
  PEFECTE NUMBER(20,0),
  PEFECTEREM NUMBER(20,0),
  ICEC NUMBER(20,0),
  IEFECTE NUMBER(20,0),
  IEFECTEREM NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOFILIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0AF1F92E834CBB265DD96A511303F742AC7E7705</HASHVAL>
  <TEXT>CREATE TABLE IOFILIAL (
  CODIOFILIAL NUMBER(20,0) NOT NULL,
  DEN_IOFILIAL VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOFILIAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD4BA8B88EBE665DB4B0B322E9DC01EC63EDB8F6</HASHVAL>
  <TEXT>CREATE TABLE IOFILIAL1 (
  CODIOFILIAL1 NUMBER(20,0) NOT NULL,
  CODIOFILIAL NUMBER(10,0),
  CONTDECONTARE NUMBER(20,0),
  CONTDECONTSERV NUMBER(20,0),
  CONTDECONTCB NUMBER(20,0),
  CONTDECONTCMP NUMBER(20,0),
  CONTDECONTAREF NUMBER(20,0),
  ISFIRMA NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>347C2A8C99388289FAF5CA5A4402415DF5EC9388</HASHVAL>
  <TEXT>CREATE TABLE IOPART (
  CODIOPART NUMBER(20,0) NOT NULL,
  DEN_IOPART VARCHAR2(30),
  SIMBOL VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DAD47AC68506C488A6734F0E4E299CE9C776451</HASHVAL>
  <TEXT>CREATE TABLE IOPART1 (
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  CONTSUPLIMF6 NUMBER(20,0),
  CONTSUPLIMF7 NUMBER(20,0),
  CONTSUPLIMF8 NUMBER(20,0),
  CONTSUPLIMF9 NUMBER(20,0),
  CONTSUPLIMF10 NUMBER(20,0),
  CONTSUPLIMF11 NUMBER(20,0),
  CONTSUPLIMF12 NUMBER(20,0),
  CONTSUPLIMF13 NUMBER(20,0),
  CONTSUPLIMF14 NUMBER(20,0),
  CONTSUPLIMF15 NUMBER(20,0),
  CONTSUPLIMF16 NUMBER(20,0),
  CONTSUPLIMF17 NUMBER(20,0),
  CONTSUPLIMF18 NUMBER(20,0),
  CONTSUPLIMF19 NUMBER(20,0),
  CONTSUPLIMF20 NUMBER(20,0),
  CONTSUPLIMF21 NUMBER(20,0),
  CONTSUPLIMF22 NUMBER(20,0),
  CONTSUPLIMF23 NUMBER(20,0),
  CONTSUPLIMF24 NUMBER(20,0),
  CONTSUPLIMF25 NUMBER(20,0),
  CONTSUPLIMF26 NUMBER(20,0),
  CONTSUPLIMF27 NUMBER(20,0),
  CONTSUPLIMF28 NUMBER(20,0),
  CONTSUPLIMF29 NUMBER(20,0),
  CONTSUPLIMF30 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPART1X</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A626E8FB3A5AA62F6586DF8CFD6D605FC037371F</HASHVAL>
  <TEXT>CREATE TABLE IOPART1X (
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPART1_X</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59761E4E6FB8A494A63B1BCCB239EC0D9DE258FB</HASHVAL>
  <TEXT>CREATE TABLE IOPART1_X (
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AE5F86D2A178A5982F6E3ED5E01EB27FF465428</HASHVAL>
  <TEXT>CREATE TABLE IOPERS (
  CODIOPERS NUMBER(20,0) NOT NULL,
  DEN_IOPERS VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>IOPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>882A10B074954A684079E6712417EF9E83D4A3B8</HASHVAL>
  <TEXT>CREATE TABLE IOPERS1 (
  CODIOPERS1 NUMBER(20,0) NOT NULL,
  CODIOPERS NUMBER(20,0),
  CONTAVANSDECONT NUMBER(20,0),
  CONTIMPUTATII NUMBER(20,0),
  CONTGARANTII NUMBER(20,0),
  CONTALTERETINERI NUMBER(20,0),
  CONTAVANS NUMBER(20,0),
  CONTLIKI NUMBER(20,0),
  CONTNERIDICATE NUMBER(20,0),
  CONTBOALA NUMBER(20,0),
  CONTPARTSAL NUMBER(20,0),
  CONTNATURA NUMBER(20,0),
  CONTECHIPAMENT NUMBER(20,0),
  CONTIMPOZIT NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBCOREL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>744AF0F0B2DAF2FD03AF9E9233E9D87ABF8B916C</HASHVAL>
  <TEXT>CREATE TABLE JOBCOREL (
  CODCOREL NUMBER(20,0) NOT NULL,
  CODJOB NUMBER(20,0),
  CODJOB1_1 NUMBER(20,0),
  TABLA1 VARCHAR2(50),
  LOOKUPFIELD1 VARCHAR2(50),
  VALDESCRIP1 VARCHAR2(1000),
  CODJOB1_2 NUMBER(20,0),
  TABLA2 VARCHAR2(50),
  LOOKUPFIELD2 VARCHAR2(50),
  VALDESCRIP2 VARCHAR2(1000),
  STARE NUMBER(2,0),
  ZECIMALE NUMBER(2,0),
  LOOKUPFIELD11 VARCHAR2(50),
  LOOKUPFIELD21 VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBCORELREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A237AC54E67C3B58E034CC9DBF3DAC5965D62AD</HASHVAL>
  <TEXT>CREATE TABLE JOBCORELREZ (
  CODCORELREZ NUMBER(20,0) NOT NULL,
  CODCOREL NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(300),
  VALOARE1 NUMBER(20,7),
  VALOARE2 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C1956DE12CAD25EAF7EF9FDFB32DE0B7105527D</HASHVAL>
  <TEXT>CREATE TABLE JOBLISTE (
  CODJOB NUMBER(20,0) NOT NULL,
  USERID NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODORAR NUMBER(20,0),
  TIPJOB NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  NEWDEPO NUMBER(1,0),
  WEBSERVER NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBLISTE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2728E8F187CAC3DCF054432C548117FD66E0E645</HASHVAL>
  <TEXT>CREATE TABLE JOBLISTE1 (
  CODJOB1 NUMBER(20,0) NOT NULL,
  CODJOB NUMBER(20,0),
  LISTAID NUMBER(20,0),
  LISTAVER NUMBER(10,0),
  TIPEXECUTIE NUMBER(1,0),
  DATAEXECUTIE TIMESTAMP(6),
  PERIOADA NUMBER(10,0),
  EXECUTATA NUMBER(1,0),
  PRINTARE NUMBER(1,0),
  ACTION NUMBER(37,0),
  FISIER_EXPORT VARCHAR2(200),
  EXPORT NUMBER(1,0),
  OBS VARCHAR2(3000),
  ACTIV NUMBER(1,0),
  ARECONFIG NUMBER(1,0),
  TIPINTERVAL NUMBER(1,0),
  TABLA VARCHAR2(200),
  EMAIL VARCHAR2(200),
  JOBID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBLISTECONFIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84AD0A6EE0922DE8CEAEBA1E2B1189F5B0D4EED1</HASHVAL>
  <TEXT>CREATE TABLE JOBLISTECONFIG (
  CODJOBCONFIG NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  FILENAME VARCHAR2(100),
  FILECONFIG BLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOBLISTEFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8310AD21AFDD2B424AEA90F5C50A36D74171016F</HASHVAL>
  <TEXT>CREATE TABLE JOBLISTEFIN (
  CODJOBLISTEFIN NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  TABLA VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  SKEMAFIRMA VARCHAR2(100),
  LISTANAME VARCHAR2(1000),
  DATAGEN DATE,
  TABLE_TYPE NUMBER(1,0),
  TIPDEPO NUMBER(3,0),
  DEPONAME VARCHAR2(50),
  LISTID NUMBER(20,0),
  LISTVER NUMBER(20,0),
  DATAINI DATE,
  DATAFIN DATE,
  FARATOTAL VARCHAR2(3200),
  CEAMSELECTAT VARCHAR2(3200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JOB_DINAMIC_COLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D99C5C76DBD3DF9E0E1E0F2F97BC323481E2B31</HASHVAL>
  <TEXT>CREATE TABLE JOB_DINAMIC_COLS (
  TABLENAME VARCHAR2(100),
  FIELDNAME VARCHAR2(50),
  DISPLAY VARCHAR2(200),
  INDEXLOCAL NUMBER(20,0),
  FTYPE NUMBER(1,0),
  FSIZE NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6DE3CC1CB5E2634078045AEADD8EA89B4481CF1</HASHVAL>
  <TEXT>CREATE TABLE JURNAL (
  CODJURNAL NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A404EF01BF2CEBF271BC83179DB103BB53B0F601</HASHVAL>
  <TEXT>CREATE TABLE JURNAL1 (
  CODJURNAL1 NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(20,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45D8AA3F12A793F3B3EC47E2FCAABFBC6DC0F09F</HASHVAL>
  <TEXT>CREATE TABLE JURNALS (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNALS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A3F3E4CD1AF73C2427E6EA5339FD27989FA4BCF</HASHVAL>
  <TEXT>CREATE TABLE JURNALS1 (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(5,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(5,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNALSHORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E755A89E45D3C0994B4C4C0875B99D4AE9AB9D95</HASHVAL>
  <TEXT>CREATE TABLE JURNALSHORT (
  MACHETE VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNETALON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEBF33838BC926680418AC15994154E6EDF70535</HASHVAL>
  <TEXT>CREATE TABLE JURNETALON (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>JURNREFAC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>843CA994549ABFD00BAB9E15E278A69F23E6B5BE</HASHVAL>
  <TEXT>CREATE TABLE JURNREFAC (
  USERID NUMBER(20,0),
  ANLUNA NUMBER(20,0),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02003A297C20AB7C35A1DF2B7D3EB7368D3D9380</HASHVAL>
  <TEXT>CREATE TABLE LANSARE (
  CODLANSARE NUMBER(20,0) NOT NULL,
  CODCMD1 NUMBER(20,0),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  CANT NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  ANULAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  AUTOMAT NUMBER(1,0),
  CODSCENARIU NUMBER(20,0),
  OBS VARCHAR2(450)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSARE0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB678CA312C4430E414D2909FC491FA82E2D8AFB</HASHVAL>
  <TEXT>CREATE TABLE LANSARE0 (
  CODLANSARE0 NUMBER(20,0) NOT NULL,
  CODLANSARE NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  CODSCENARIU NUMBER(20,0),
  TERMEN DATE,
  CANTUM1 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5EC308908DD720F1166637CB85925F2B24270B2</HASHVAL>
  <TEXT>CREATE TABLE LANSARE1 (
  CODLANSARE1 NUMBER(20,0) NOT NULL,
  CODLANSARE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODREZERVATS NUMBER(20,0),
  CODLANSARE0 NUMBER(20,0),
  OBS VARCHAR2(500),
  NODPARINTE NUMBER(20,0),
  CODCMD1P NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSARENEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13393F35B9DA6636A8D5EAA43CE040764F63C259</HASHVAL>
  <TEXT>CREATE TABLE LANSARENEC (
  CODLANSARE0 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CANT NUMBER(20,7),
  NECESARP NUMBER(20,7),
  NECESAR NUMBER(20,7),
  REZOLVAT NUMBER(20,7),
  REZERVAT NUMBER(20,7),
  NESOSIT NUMBER(20,7),
  RESTREZERVAT NUMBER(20,7),
  RESTNESOSIT NUMBER(20,7),
  TOTREZERVAT NUMBER(20,7),
  TOTNESOSIT NUMBER(20,7),
  STOC NUMBER(20,7),
  CMDINT NUMBER(20,7),
  DIFERENTE NUMBER(20,7),
  PARITATEECHIV NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E10B9E957B2C2142C09A1DDA17FED624215D46B6</HASHVAL>
  <TEXT>CREATE TABLE LANSGEST (
  CODLANSGEST NUMBER(20,0) NOT NULL,
  CODLANSPROD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  NRSCHIMBURI NUMBER(5,0),
  CAPACITATE NUMBER(10,0),
  INCARCARE NUMBER(10,0),
  INCARCARER NUMBER(10,0),
  DEN_GEST VARCHAR2(100),
  SIMBOL VARCHAR2(15),
  ORESCHIMB NUMBER(4,2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>769954F4ADD925B5E441892C36910B2228F7A05F</HASHVAL>
  <TEXT>CREATE TABLE LANSPROD (
  CODLANSPROD NUMBER(20,0) NOT NULL,
  SAPTAMANA NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  OBS VARCHAR2(250),
  DIRTY NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>427E859F6AE0F5994E07FEC36DE35889DE366F08</HASHVAL>
  <TEXT>CREATE TABLE LANSPROD1 (
  CODLANSPROD1 NUMBER(20,0) NOT NULL,
  CODLANSPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTCOMANDATF NUMBER(20,7),
  STOC NUMBER(20,7),
  CANTLANSAT NUMBER(20,7),
  STOCESTIMAT NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  CANTCOMANDATN NUMBER(20,7),
  NECESAR NUMBER(20,7),
  OBS VARCHAR2(250),
  NECESART NUMBER(20,7),
  PREDARI NUMBER(20,7),
  PRET NUMBER(20,7),
  COEFUM NUMBER(20,7),
  VALOARE NUMBER(20,7),
  VALOAREACC NUMBER(20,7),
  CODGEST NUMBER(20,0),
  TIMPEST NUMBER(20,7),
  RESTD NUMBER(20,7),
  EXCLUS NUMBER(1,0),
  STOCMAX NUMBER(20,7),
  ACCPREV NUMBER(20,7),
  AVGSPI NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSPROD2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AC1057BD716524BF13F8A6E610576D739478FB6</HASHVAL>
  <TEXT>CREATE TABLE LANSPROD2 (
  CODLANSPROD2 NUMBER(20,0) NOT NULL,
  CODLANSPROD1 NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CANT NUMBER(20,7),
  TIMP NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSPROD2S</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E98DE437217F26DEE9F315884F13964FC8FE9C9</HASHVAL>
  <TEXT>CREATE TABLE LANSPROD2S (
  CODLANSPROD2S NUMBER(20,0) NOT NULL,
  CODLANSPROD1 NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIMPEST NUMBER(20,7),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1CD477EC09A48BF5E7932946274FDF096B973D9</HASHVAL>
  <TEXT>CREATE TABLE LANSZ (
  CODLANSZ NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OBS VARCHAR2(250),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SAPTAMANA NUMBER(10,0),
  DIRTY NUMBER(1,0),
  FINALIZAT NUMBER(1,0),
  ALLGEST NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BC4896EFA9F853520E181335C5CF8DA8802D5C0</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1 (
  CODLANSZ1 NUMBER(20,0) NOT NULL,
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>04D4A1241395AACBEF45802092FBC39766D60B1F</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1_CMD (
  CODLANSZ1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  ZI NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1_MANEVRA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC5E8E45FF445BF52B2E91ECD5A090774D0375FC</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1_MANEVRA (
  CODLANSZ1 NUMBER(20,0),
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  USERID NUMBER(20,0),
  CODGEST NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  GESTIMPLICITA VARCHAR2(100),
  GESTRETETA VARCHAR2(100),
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  ORDINE NUMBER(10,0),
  DEN_CLASEAS VARCHAR2(50),
  RETETA VARCHAR2(250),
  DEN_CLASEPROD VARCHAR2(50),
  DENUMIRE VARCHAR2(200),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7),
  ALTE NUMBER(20,7),
  REPORTALTE NUMBER(20,7),
  RESTDELANSAT NUMBER(20,7),
  DIRTY NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1_MANEVRA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E72AC09F160DF9AD8719F6F01863890CBF5BAAE</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1_MANEVRA1 (
  CODLANSZ1 NUMBER(20,0),
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  USERID NUMBER(20,0),
  CODGEST NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  GESTIMPLICITA VARCHAR2(100),
  GESTRETETA VARCHAR2(100),
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  ORDINE NUMBER(10,0),
  DEN_CLASEAS VARCHAR2(50),
  RETETA VARCHAR2(250),
  DEN_CLASEPROD VARCHAR2(50),
  DENUMIRE VARCHAR2(200),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7),
  ALTE NUMBER(20,7),
  REPORTALTE NUMBER(20,7),
  RESTDELANSAT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1_MANEVRA1_L</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C1FF2DA860F239BF6552FA62A88181429E8C1A30</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1_MANEVRA1_L (
  CODLANSZ1 NUMBER(20,0),
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  USERID NUMBER(20,0),
  CODGEST NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  GESTIMPLICITA VARCHAR2(100),
  GESTRETETA VARCHAR2(100),
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  ORDINE NUMBER(10,0),
  DEN_CLASEAS VARCHAR2(50),
  RETETA VARCHAR2(250),
  DEN_CLASEPROD VARCHAR2(50),
  DENUMIRE VARCHAR2(200),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7),
  ALTE NUMBER(20,7),
  REPORTALTE NUMBER(20,7),
  RESTDELANSAT NUMBER(20,7),
  DIRTY NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LANSZ1_MANEVRA_L</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE2E3A9C49C828E6DF7EC97B72EC684DDB2F0CF7</HASHVAL>
  <TEXT>CREATE TABLE LANSZ1_MANEVRA_L (
  CODLANSZ1 NUMBER(20,0),
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  USERID NUMBER(20,0),
  CODGEST NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  GESTIMPLICITA VARCHAR2(100),
  GESTRETETA VARCHAR2(100),
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  ORDINE NUMBER(10,0),
  DEN_CLASEAS VARCHAR2(50),
  RETETA VARCHAR2(250),
  DEN_CLASEPROD VARCHAR2(50),
  DENUMIRE VARCHAR2(200),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7),
  ALTE NUMBER(20,7),
  REPORTALTE NUMBER(20,7),
  RESTDELANSAT NUMBER(20,7),
  DIRTY NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LISTCOLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C23A9FB5B90613F4CE26C8D6BE0A801189215B66</HASHVAL>
  <TEXT>CREATE TABLE LISTCOLS (
  CODLISTCOLS NUMBER(20,0),
  LISTID NUMBER(20,0),
  LISTVER NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  FIELDNAME VARCHAR2(50),
  FIELDTYPE NUMBER(2,0),
  FIELDSIZE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FA720376DEEFC3CBE3A2BFF6D74F10CE6D5A42F</HASHVAL>
  <TEXT>CREATE TABLE LIVR (
  CODLIVR NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  DATALIVR DATE,
  OBS VARCHAR2(100),
  TIPLIVR NUMBER(2,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  EXPORTAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AE99143C51360802A5611C0C92BB3C4340FBB27</HASHVAL>
  <TEXT>CREATE TABLE LIVR1 (
  CODLIVR1 NUMBER(20,0) NOT NULL,
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LIVR1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3E9FED30CDA0DCDE0140F17878EA6113872F17A3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LIVR1_MAN (
  CODLIVR1 NUMBER(20,0) NOT NULL,
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LIVRVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D89A04082C68083FDA66CA617F9B3369B758CD1</HASHVAL>
  <TEXT>CREATE TABLE LIVRVAL (
  CODLIVRVAL NUMBER(20,0) NOT NULL,
  CODLIVR1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  GEST NUMBER(20,0),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  TVANEEX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOCKPOSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A453A6A7D09314D65B774C6F7042189E34DAEB73</HASHVAL>
  <TEXT>CREATE TABLE LOCKPOSTRETAIL (
  USERID NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE9F450AF53E21280644E5FBD91B489BB8E65655</HASHVAL>
  <TEXT>CREATE TABLE LOCMUNCA (
  CODLOC NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(10),
  DENUMIRE VARCHAR2(250),
  TIP NUMBER(1,0),
  DSV NUMBER(10,0),
  ACTIVI NUMBER(10,0),
  SPECIAL NUMBER(1,0),
  CODLOCDEF NUMBER(20,0),
  MINUTEON NUMBER(4,0),
  MINUTEOFF NUMBER(4,0),
  FARA_GANT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOCMUNCA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10D6A728B62850B3C4BF03F7466FF1BAC10B7733</HASHVAL>
  <TEXT>CREATE TABLE LOCMUNCA1 (
  CODLOC1 NUMBER(20,0) NOT NULL,
  CODLOC NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  ORE NUMBER(10,7),
  CODUTILAJ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  NICKNAME VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOCMUNCA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44DA448BA1CC278DA22934AF9120CD23CA3460AE</HASHVAL>
  <TEXT>CREATE TABLE LOCMUNCA2 (
  CODLOC2 NUMBER(20,0) NOT NULL,
  CODLOC1 NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODLOC1ASOC NUMBER(20,0),
  ORESTART NUMBER(7,3),
  DATASTART DATE,
  ORESTOP NUMBER(7,3),
  DATASTOP DATE,
  MINUNEON NUMBER(4,0),
  MINUNEOFF NUMBER(4,0),
  OREACTIV NUMBER(7,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOCURIMUNCAOBS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2DAD10614167ABBFB3F8BDAA4F766BBE949F61E5</HASHVAL>
  <TEXT>CREATE TABLE LOCURIMUNCAOBS (
  IDOBS NUMBER(20,0),
  CODPROGRAMF1 NUMBER(20,0),
  CODLOCMUNCA NUMBER(20,0),
  OBS VARCHAR2(3000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOGIMPORTDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5C503C75A08EC5556770830FED5B5895A8C07C4</HASHVAL>
  <TEXT>CREATE TABLE LOGIMPORTDOC (
  COD NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  IDIMPORT VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DATAIMPORT TIMESTAMP(6),
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  TIPOPERATIE VARCHAR2(1),
  CANTVECHI NUMBER(20,7),
  CANTNOU NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LOGUSERTAB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4860E21110313203C5FB118743D7D2551122528A</HASHVAL>
  <TEXT>CREATE TABLE LOGUSERTAB (
  NUMEUSER VARCHAR2(50) NOT NULL,
  ANCURENT NUMBER(4,0),
  LUNACURENTA NUMBER(2,0),
  ANINITIAL NUMBER(4,0),
  LUNAINITIALA NUMBER(2,0),
  ANMAXIM NUMBER(4,0),
  LUNAMAXIMA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_IES1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A860836A0F0166C71FB0B605161BEEB06E63677E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_IES1 (
  CODIES NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  AL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECT1 NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTCORELAT NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  PIES NUMBER(20,7),
  TVA NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  VORIG NUMBER(20,7),
  VU NUMBER(20,7),
  VIESL NUMBER(20,7),
  MINPDISC NUMBER(20,7),
  MAXPDISC NUMBER(20,7),
  MINADDIM NUMBER(20,7),
  MAXADDIM NUMBER(20,7),
  PARITATE NUMBER(20,7),
  DEN_UMSEC VARCHAR2(15),
  DEN_UM1 VARCHAR2(15),
  DEN_UM2 VARCHAR2(15),
  DEN_UMCOR VARCHAR2(15),
  ART_ASOCIAT VARCHAR2(200),
  PRODUCATOR VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_ML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E58A0FACD7BA55EC17D318F7183FBF90A18E1C9B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_ML (
  CODIES1 NUMBER(20,0),
  CODAE1 NUMBER(20,0),
  CODAE NUMBER(20,0),
  CODCOM1 NUMBER(20,0),
  CODDL1 NUMBER(20,0),
  CODDL NUMBER(20,0),
  CODCC1 NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_NS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84DA1540212D2CAEDA6A81823B7A80AF6A106AED</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_NS (
  CODIES1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PU NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  TG VARCHAR2(200),
  NRCERTIF VARCHAR2(300),
  DIM VARCHAR2(2000),
  D1 VARCHAR2(2000),
  EUDR_RN VARCHAR2(3200),
  EUDR_VN VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_NSIN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FA2E1E96F7617D873A020BE280F8B33580385A2B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_NSIN (
  CODNIRSTOC NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_SER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>340509A21BE968A86765EFF5319E6A57022BC8CB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_SER (
  CODIES1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PU NUMBER(20,7),
  SERII VARCHAR2(3200),
  SER VARCHAR2(3200),
  SERTG VARCHAR2(3200),
  SERCANT VARCHAR2(3200),
  SEROBS VARCHAR2(3200),
  SERII_TG VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_DOCIES_TVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>901F8991235B4B5E8E5C24E155D8147FD96522F9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_DOCIES_TVA (
  TVA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  BAZA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_SETTASK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D189F00D657E625624D6810E25BFB5680F99E3A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_SETTASK (
  CODTASK NUMBER(20,0),
  PROBLEMA VARCHAR2(4000),
  DESTINATAR VARCHAR2(30),
  EXECUTANT VARCHAR2(30),
  USERNAME VARCHAR2(30),
  TERMEN DATE,
  DATATASK DATE,
  DATAREZ DATE,
  DOMENIU VARCHAR2(50),
  TIP VARCHAR2(50),
  REZOLVARE VARCHAR2(4000),
  OBSERVATII VARCHAR2(4000),
  PRIORITATE NUMBER(6,0),
  DONE NUMBER(1,0),
  MODIFICAT NUMBER(1,0),
  MESAJCATRE VARCHAR2(30),
  STERS NUMBER(1,0),
  PROIECT VARCHAR2(50),
  DOMSG NUMBER(1,0),
  CODMSG1 NUMBER(20,0),
  DOMAIL NUMBER(1,0),
  CODMAIL NUMBER(20,0),
  ZBEFORE NUMBER(2,0),
  CODFIRMA NUMBER(20,0),
  CODPART NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  FACTURAT NUMBER(1,0),
  VALOARE NUMBER(20,2),
  CODMONEDA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODFACTURA NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODSERVICIU NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VERSIUNE NUMBER(7,3),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  ARTICOLASOCIAT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_SETTASKLOG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A3BC2C2D1424B36297B48DA7EF8D16EAAD201DDA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_SETTASKLOG (
  CODLOG NUMBER(20,0),
  CODTASK NUMBER(20,0),
  DATA DATE,
  USER_SRC VARCHAR2(30),
  USER_DST VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LST_SETTASKOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CA3CA5FE4D19FD86D81E0D5614707AF000E6426F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE LST_SETTASKOBJ (
  CODTASKOBJ NUMBER(20,0),
  CODTASK NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NEPRELUABIL NUMBER(1,0),
  PRET NUMBER(20,7),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>LUNA_RECORDS_FLAGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D25C37D8177310FF270432246483AF3D7E18DB27</HASHVAL>
  <TEXT>CREATE TABLE LUNA_RECORDS_FLAGS (
  USERID NUMBER(20,0),
  NART_FLG NUMBER(1,0),
  NARTOBJ_FLG NUMBER(1,0),
  IOART_FLG NUMBER(1,0),
  NTVA_FLG NUMBER(1,0),
  NTAXE_FLG NUMBER(1,0),
  IOPART_FLG NUMBER(1,0),
  IOPERS_FLG NUMBER(1,0),
  TARIFE_FLG NUMBER(1,0),
  PRETM_FLG NUMBER(1,0),
  IOFILIAL_FLG NUMBER(1,0),
  IOBANK_FLG NUMBER(1,0),
  NART_FLG_CONTA NUMBER(1,0),
  NARTOBJ_FLG_CONTA NUMBER(1,0),
  IOART_FLG_CONTA NUMBER(1,0),
  NTVA_FLG_CONTA NUMBER(1,0),
  NTAXE_FLG_CONTA NUMBER(1,0),
  IOPART_FLG_CONTA NUMBER(1,0),
  IOPERS_FLG_CONTA NUMBER(1,0),
  IOFILIAL_FLG_CONTA NUMBER(1,0),
  IOBANK_FLG_CONTA NUMBER(1,0),
  NGEST1_FLG_CONTA NUMBER(1,0),
  NPART1_FLG_CONTA NUMBER(1,0),
  NPERS1_FLG_CONTA NUMBER(1,0),
  NBANK1_FLG_CONTA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51345AB73005BEF6965D511CAA34ED4F089A6F7E</HASHVAL>
  <TEXT>CREATE TABLE MACHETE (
  CODMACHETA NUMBER(20,0),
  PREFIX VARCHAR2(3),
  NUMEPRESC VARCHAR2(15),
  NUMEEXT VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAILURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>332978DF84E4E45BB8B5D2498214C91060881528</HASHVAL>
  <TEXT>CREATE TABLE MAILURI (
  CODMAIL NUMBER(20,0) NOT NULL,
  SENDER VARCHAR2(200),
  RECIPIENTS VARCHAR2(500),
  SUBJECT VARCHAR2(200),
  MESSAGE VARCHAR2(3000),
  USERID NUMBER(20,0),
  DATA DATE,
  STATUS NUMBER(1,0),
  EROARE VARCHAR2(3000),
  HOST VARCHAR2(200),
  PORT NUMBER(20,0),
  DOMAIN VARCHAR2(200),
  CODFIRMA NUMBER(20,0),
  CODSERVER NUMBER(20,0),
  MSG CLOB,
  CODDOC1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  WEBSERVER NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAILURI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7C47EA7D732AF413162D3244D17C4271E16F016</HASHVAL>
  <TEXT>CREATE TABLE MAILURI1 (
  CODMAIL1 NUMBER(20,0) NOT NULL,
  CODMAIL NUMBER(20,0),
  FILENAME VARCHAR2(100),
  ATTACHFILE BLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAILURIDOCS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2BFC59D0910131622B444AC5C0E3759FC1F6B04</HASHVAL>
  <TEXT>CREATE TABLE MAILURIDOCS (
  CODMAILDOC NUMBER(20,0) NOT NULL,
  CODMAIL NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODAGENDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_CONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C5917CEC62592C8EE79972A159AC256CBF924CA</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_CONSUM (
  CODOBIECT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CANT NUMBER(20,7),
  VALRET NUMBER(20,7),
  CANTRET NUMBER(20,7),
  NODPARINTE NUMBER(20,0),
  PRODUS NUMBER(20,0),
  CANT_PROD NUMBER(20,7),
  S_IDX VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45B0BC4D1F215C773B4775CE7BEFC9799E3AB19C</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_NOTECREDIT (
  CODOBIECT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE_B NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRETURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E639932066F4097E49633E6E957F60CB3B03E1C1</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRETURI (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  STARE NUMBER(1,0),
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTEKIV NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRETURI_D</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8FDE1FF13A745F63878BCFFB7D0D40D16AA525D</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRETURI_D (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  CODNIRSTOC NUMBER(20,7),
  STARE NUMBER(1,0),
  ORDINE NUMBER(10,0),
  CANT NUMBER(20,7),
  DATAACHIZ DATE,
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTGENERIC NUMBER(20,0),
  OBJ_CODEXTERN VARCHAR2(80),
  OBJ_CODINTERN VARCHAR2(80)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRETURI_D_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA7C8A35F4916DD07A69263C75B894951FE7C281</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRETURI_D_P (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  CODNIRSTOC NUMBER(20,7),
  STARE NUMBER(1,0),
  ORDINE NUMBER(10,0),
  CANT NUMBER(20,7),
  DATAACHIZ DATE,
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTGENERIC NUMBER(20,0),
  OBJ_CODEXTERN VARCHAR2(80),
  OBJ_CODINTERN VARCHAR2(80)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRETURI_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B17BD609E6358123EB26FC63C72BFDE19693C776</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRETURI_P (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  STARE NUMBER(1,0),
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTEKIV NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODCOMP_CLONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0DD0DCE0F172C4AF968563D2CD351A872C0A3A7</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODCOMP_CLONA (
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  VALREGIEMAN NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODCOMP_CLONA_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9F2F41734BAE7DD4BCB1FAE836A0BE0247C7CDE</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODCOMP_CLONA_P (
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  VALREGIEMAN NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODMAN_CLONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6F344E59E42BF2F4E960E05219963935B440CC8</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODMAN_CLONA (
  CODMAN NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  VALOARE_V NUMBER(20,7),
  VALOARE_N NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODMAN_CLONA_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41E204A65D2802F15FF9ED36A6C30385BC1D33FD</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODMAN_CLONA_P (
  CODMAN NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  VALOARE_V NUMBER(20,7),
  VALOARE_N NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODMAT_CLONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1927730DA162585C0DCEB9B7C82772740F2E5EE</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODMAT_CLONA (
  CODMAT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PRODMAT_CLONA_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C06F687A4EF2F9FB48446C8373ECA7954FE213D</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_PRODMAT_CLONA_P (
  CODMAT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_PROIECTMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EACC695854784976F3BDBB35E212DEA549A5CB80</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MANEVRA_PROIECTMAN (
  CODLANSARE0 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  DEN_OBIECT VARCHAR2(200),
  TIP NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DURATA NUMBER(20,7),
  CANT NUMBER(20,7),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(10,0),
  DURATANOD NUMBER(20,7),
  COPILMAXIM NUMBER(20,7),
  NODCRITIC VARCHAR2(100),
  BARA VARCHAR2(100),
  DECALAJ NUMBER(20,7),
  INCEPERE NUMBER(20,7),
  TERMEN DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANEVRA_UNIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94FE7E966C277EC8DD7DDA4BE06B6B761C55E5FB</HASHVAL>
  <TEXT>CREATE TABLE MANEVRA_UNIC (
  CODUNIC NUMBER(20,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MANPRODLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1C1E199B761B0E9063E5B5F088635F5692433CF9</HASHVAL>
  <TEXT>CREATE TABLE MANPRODLINK (
  CODRAPORTP2 NUMBER(20,0) NOT NULL,
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39A47C80DFF9E730175659381ECBFE1253A49258</HASHVAL>
  <TEXT>CREATE TABLE MAN_ALERTE (
  USERID NUMBER(20,0),
  MESAJ VARCHAR2(3200),
  ORDINE NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_CMDPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2DB368ADBFF67E896B0054150F3B0C01579EC694</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MAN_CMDPRODMAT (
  CODCMDPRODMAT NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  REZIDUU NUMBER(1,0),
  CODPRODMAT NUMBER(20,0),
  PARITATEECHIV NUMBER(20,7),
  TIPECHIV NUMBER(1,0),
  CUMSEC NUMBER(20,0),
  CCANT NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CODCOMANDA3 NUMBER(20,0),
  UMSEC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_COMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>017F68F2A62EEF914571C6A133A161015A0FBAEC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MAN_COMANDA (
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODCMDPARINTE NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  VALDISCOUNT NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODGEST NUMBER(20,0),
  INCHISA NUMBER(1,0),
  SUBUNITSURSA NUMBER(20,0),
  SCADENTAV NUMBER(5,0),
  SERIADOC VARCHAR2(20),
  USERIDBLOCAJ NUMBER(20,0),
  NRI VARCHAR2(30),
  CODTRASEULIVR NUMBER(20,0),
  ORDINELIVRARE NUMBER(20,0),
  MIJLTRANSP NUMBER(20,0),
  INSOTITOR NUMBER(20,0),
  DISPLIVRARE NUMBER(1,0),
  VERIFICAT NUMBER(1,0),
  CODIES NUMBER(20,0),
  FARATRANSPORT NUMBER(1,0),
  PLATAPELOC NUMBER(1,0),
  DATAINREG TIMESTAMP(6),
  FACTURABIL NUMBER(1,0),
  CURS NUMBER(20,7),
  SCHIMB NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  IDIMPORT VARCHAR2(30),
  LISTAT NUMBER(10,0),
  FACTURA_APL_EXT NUMBER(1,0),
  CODPERS_APL_EXT NUMBER(20,0),
  LOT NUMBER(10,0),
  NRTRANSP VARCHAR2(30),
  CODIESAVANS NUMBER(20,0),
  FARAFACTURA NUMBER(1,0),
  DINONLINE NUMBER(1,0),
  PRETCUAMANUNT NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  TIPTRANZACTIE NUMBER(1,0),
  SUBUNITDEST NUMBER(20,0),
  NRMAXAPROBARI NUMBER(10,0),
  STADIUWMS NUMBER(2,0),
  CODPERSC NUMBER(20,0),
  MOTIVINCHIDERE VARCHAR2(80),
  CODPARTCOMIS NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  GRATIE NUMBER(10,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  MODINCHIDERE NUMBER(1,0),
  PLATFORMA_ONLINE NUMBER(2,0),
  REMORCA NUMBER(20,0),
  ROTEFACT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_IESIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>07822E1139D0D2D626CE46FE11B664D8220F8668</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MAN_IESIRI (
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  CARNETAE NUMBER(20,0),
  NRAE NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ACCIZE NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  MAJORARI NUMBER(20,7),
  OBS VARCHAR2(500),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  BUGETARE NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  TIPFACTURA NUMBER(10,0),
  CODGESTPROD NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  TIPCONSUMATOR NUMBER(2,0),
  CODAUTO NUMBER(20,0),
  PARTCUSTODIE NUMBER(20,0),
  CODCMDINTERNA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  COMISION NUMBER(20,7),
  CODBANKCONT NUMBER(20,0),
  TIPCASAMARCAT NUMBER(5,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPTRANZACTIE NUMBER(5,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  DISCVOL NUMBER(20,7),
  DISCTER NUMBER(20,7),
  MONEDATRANSF NUMBER(20,7),
  NRI VARCHAR2(50),
  CONTSUPLIM NUMBER(20,0),
  DATAINREG TIMESTAMP(6),
  CUSTODIE NUMBER(1,0),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  CARNETCERTIF NUMBER(20,0),
  NRCERTIF NUMBER(20,0),
  SERIACERTIF VARCHAR2(10),
  STARERESTITUIRE NUMBER(1,0),
  IDIMPORT VARCHAR2(30),
  LISTATCERTIF NUMBER(1,0),
  FARAREG NUMBER(1,0),
  CODPERSC NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  CODIESMAMB NUMBER(20,0),
  PROCTVADOC NUMBER(20,7),
  CODANALIZA NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  TVAINCASARE NUMBER(1,0),
  DATATVA DATE,
  CODCONTRACT NUMBER(20,0),
  FACTSIMPLIF NUMBER(1,0),
  TRANSPORTATOR NUMBER(20,0),
  STADIUWMS NUMBER(2,0),
  CODMONETAR NUMBER(20,0),
  NUMARBONURI NUMBER(5,0),
  EMISADECLIENT NUMBER(1,0),
  NRINFOCM NUMBER(5,0),
  NRINCASULT NUMBER(5,0),
  NRINCASIM NUMBER(5,0),
  CODPARTTERT NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  NATURATRANZ NUMBER(2,0),
  MODTRANSP NUMBER(2,0),
  SPLITTVA NUMBER(1,0),
  GRATIE NUMBER(10,0),
  TIPSAFT NUMBER(2,0),
  CODTVASERV NUMBER(20,0),
  PROCTVAOSS NUMBER(6,3),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  NOACCIZE NUMBER(1,0),
  NRNIR VARCHAR2(20),
  DATANIR DATE,
  PLATFORMA_ONLINE NUMBER(2,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7),
  REMORCA NUMBER(20,0),
  PROIECT VARCHAR2(20),
  CONTRACT VARCHAR2(20),
  COMANDA VARCHAR2(20),
  EXCLUSINTRASTAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_IESIRI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D41081B213828E7D9657518F3147BFFF96670AA2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MAN_IESIRI1 (
  CODIES1 NUMBER(20,0),
  CODIES NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  TIPLIVRARE NUMBER(1,0),
  GARANTIE NUMBER(20,0),
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  MIFIX NUMBER(1,0),
  ZILE NUMBER(5,0),
  COSTTRANSPORT NUMBER(20,7),
  ZILECMD NUMBER(20,0),
  CODLIVR1PRODVAL NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CADOU NUMBER(20,0),
  TIPPLATA NUMBER(1,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODIOARTCUST NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  CANTCORELAT NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  CODOBLIGMONETAR NUMBER(20,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1D3BCS NUMBER(1,0),
  CODOBLIGMAJORAT NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  ICONTPART NUMBER(2,0),
  CANTCONSTATAT NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  IMPOZABIL NUMBER(1,0),
  PRETUM1 NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODPARTCOMISEMUL NUMBER(20,0),
  ADMAX NUMBER(20,7),
  VALFIN NUMBER(20,7),
  TVAFIN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8458AC11C1A2401B3D9CB608C6F62C129B413DFF</HASHVAL>
  <TEXT>CREATE TABLE MAN_JURNAL (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(30),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MAN_JURNAL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D4C5B84545B9E3654D7C7FF0A48F0347B2C28A0</HASHVAL>
  <TEXT>CREATE TABLE MAN_JURNAL1 (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(20,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(30),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MARCALOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7CB280874A1E5E957D71543F0D89E75202B2565</HASHVAL>
  <TEXT>CREATE TABLE MARCALOCK (
  COD NUMBER(20,0),
  MARCA NUMBER(20,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MASCASERART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D5A9DC934654A75933471844D82C7DBA39B12FC</HASHVAL>
  <TEXT>CREATE TABLE MASCASERART (
  CODMASCA NUMBER(20,0) NOT NULL,
  MASCA VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MASCASERART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E7A7C5733260F4043EF9C17EFD9D1CCF1C7F3DD</HASHVAL>
  <TEXT>CREATE TABLE MASCASERART1 (
  CODMASCA1 NUMBER(20,0) NOT NULL,
  CODMASCA NUMBER(20,0),
  DENELEMENT VARCHAR2(100),
  VALORI VARCHAR2(100),
  ELEMENT VARCHAR2(10),
  LUNGIME NUMBER(10,0),
  FILL VARCHAR2(10)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MASTERCHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C72291CA413619F5673871C67FE92D67551A8D7</HASHVAL>
  <TEXT>CREATE TABLE MASTERCHELTAVANS (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MASTERMAK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>624AA622D83F7841228678356A5FD97F6F41E2F1</HASHVAL>
  <TEXT>CREATE TABLE MASTERMAK (
  CODMASTERMAK NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(6,0),
  COD1 NUMBER(20,0),
  COD2 NUMBER(20,0),
  COD3 NUMBER(20,0),
  COD4 NUMBER(20,0),
  COD5 NUMBER(20,0),
  V1 NUMBER(20,7),
  V2 NUMBER(20,7),
  V3 NUMBER(20,7),
  V4 NUMBER(20,7),
  V5 NUMBER(20,7),
  DATA1 DATE,
  DATA2 DATE,
  OBS1 VARCHAR2(50),
  OBS2 VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MASTERMIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6FE01F1E72C3624CF3A92776C8A44237BE798333</HASHVAL>
  <TEXT>CREATE TABLE MASTERMIFIX (
  CODNIRSTOC NUMBER(20,0),
  CODCLASIF NUMBER(20,0),
  DURATAN NUMBER(10,0),
  DURATANF NUMBER(10,0),
  DURATANG NUMBER(10,0),
  CODANALIZA NUMBER(20,0),
  CODCLASIFBLOCAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MEDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>005EDBD0E86C877F11C7ABA9BED9D34641FB66E3</HASHVAL>
  <TEXT>CREATE TABLE MEDEX (
  CODMEDEX NUMBER(20,0) NOT NULL,
  DATALISTA DATE,
  OBS VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MEDEX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9F2E683CDFAC727F59ED021E859399EAB6AF5D1</HASHVAL>
  <TEXT>CREATE TABLE MEDEX1 (
  CODMEDEX1 NUMBER(20,0) NOT NULL,
  CODMEDEX NUMBER(20,0),
  CODCIM VARCHAR2(20),
  DENUMIRE VARCHAR2(500),
  PREZENTARE VARCHAR2(500),
  NARCOTIC NUMBER(1,0),
  FRACTIONAL NUMBER(1,0),
  SPECIAL NUMBER(1,0),
  AREBIOECHIVALENT NUMBER(1,0),
  CANT NUMBER(10,0),
  PRETAM NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRESCRIERE VARCHAR2(100),
  VALIDDELA DATE,
  VALIDPANALA DATE,
  DCI VARCHAR2(250),
  CONC VARCHAR2(250),
  FORMAFARM VARCHAR2(500),
  PRODUCATOR VARCHAR2(250),
  TARA VARCHAR2(50),
  GRUPA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MEDEX2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A8364C1C0AE0D5310B40A2BC058CBCB839FBE439</HASHVAL>
  <TEXT>CREATE TABLE MEDEX2 (
  CODMEDEX2 NUMBER(20,0) NOT NULL,
  CODMEDEX NUMBER(20,0),
  TIPCOMPENS VARCHAR2(10),
  CODCIM VARCHAR2(20),
  CODBOALA VARCHAR2(10),
  PRETAM NUMBER(20,7),
  PRETAMUT NUMBER(20,7),
  COPLATA NUMBER(20,7),
  COPLATA90 NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRETREF NUMBER(20,7),
  LEGISPECIALE NUMBER(1,0),
  APROBARE VARCHAR2(10),
  VALPESTE NUMBER(20,7),
  SPECIALITATE NUMBER(1,0),
  INSULINA VARCHAR2(10),
  DCI VARCHAR2(250),
  GRUPA VARCHAR2(50),
  VALIDDELA DATE,
  VALIDPANALA DATE,
  NHPCODE VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MEDEX_TARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADA53E21D7EFFC7392F801CF7C36297C91BB6306</HASHVAL>
  <TEXT>CREATE TABLE MEDEX_TARI (
  CODMEDEXT NUMBER(20,0) NOT NULL,
  CODMEDEX NUMBER(20,0),
  COD VARCHAR2(50),
  TARA VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENUDASH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35A6C90A1DAF655C0EB8250564E96CC36D57A0FA</HASHVAL>
  <TEXT>CREATE TABLE MENUDASH (
  CODMENUDASH NUMBER(20,0) NOT NULL,
  CAPTION VARCHAR2(250),
  MODUL NUMBER(2,0),
  MENU NUMBER(2,0),
  PROG NUMBER(2,0),
  UNI NUMBER(1,0),
  LISTID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENUDASH0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>396DD6FAF8D0002F12C30EE3D454308F0BFE48D7</HASHVAL>
  <TEXT>CREATE TABLE MENUDASH0 (
  CODMENUDASH0 NUMBER(20,0) NOT NULL,
  CODMENUDASH NUMBER(20,0),
  AUTOSHOW NUMBER(2,0),
  USERID NUMBER(20,0),
  CONFIG BLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENUDASH1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45341E45219B3912AE4CBA03A7851908C04F3FC0</HASHVAL>
  <TEXT>CREATE TABLE MENUDASH1 (
  CODMENUDASH1 NUMBER(20,0) NOT NULL,
  CODMENUDASH NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0),
  NUME VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENUDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>181B1CA46381CB041E60F757BF1C646ACA7015C6</HASHVAL>
  <TEXT>CREATE TABLE MENUDATE (
  CODMENUDATE NUMBER(20,0) NOT NULL,
  DEN_MENU VARCHAR2(100),
  USERID VARCHAR2(20),
  NRBUTON NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENUDATE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E208E4BB0F3F7AD306F443373754FAA80DC94A18</HASHVAL>
  <TEXT>CREATE TABLE MENUDATE1 (
  CODMENUDATE1 NUMBER(20,0) NOT NULL,
  CODMENUDATE NUMBER(20,0),
  DEN_MENU VARCHAR2(100),
  ACTION VARCHAR2(100),
  INDEXLOCAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MENULISTE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>32C5573E28700CEAF9931B14894B6B2C267A72C7</HASHVAL>
  <TEXT>CREATE TABLE MENULISTE1 (
  CODMENU1 NUMBER(20,0) NOT NULL,
  CODMENU NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MESAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33DDF4B17C11B5859913FCC19F572B1930DF66FA</HASHVAL>
  <TEXT>CREATE TABLE MESAJE (
  IDMESAJ NUMBER(20,0),
  TEXT VARCHAR2(3000),
  USERN VARCHAR2(100),
  TIP_MESAJ NUMBER(3,0),
  DATA TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MESE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E029CD1C593E1DCFC1CD93768D0FBFDAC2B8F7BA</HASHVAL>
  <TEXT>CREATE TABLE MESE (
  CODMASA NUMBER(20,0) NOT NULL,
  CODSALA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  STARE NUMBER(5,0),
  X NUMBER(10,0),
  Y NUMBER(10,0),
  WIDTH NUMBER(10,0),
  HEIGHT NUMBER(10,0),
  NUMARLOCURI NUMBER(10,0),
  TEXTAFISARE VARCHAR2(100),
  FORMA NUMBER(1,0),
  BLOCATA NUMBER(1,0),
  USERID NUMBER(20,0),
  CODOSPATAR NUMBER(20,0),
  MODPLATAIMPLICIT NUMBER(3,0),
  PROTOCOL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MESE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F2519F1E6838DBDC526527D3E8FB2D739612A75</HASHVAL>
  <TEXT>CREATE TABLE MESE1 (
  CODMASA1 NUMBER(20,0) NOT NULL,
  CODMASA NUMBER(20,0),
  CODOSPATAR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC57D3B694741A31364805F78A954107B8735275</HASHVAL>
  <TEXT>CREATE TABLE MFCLASIF (
  CODCLASIF NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(1200),
  SIMBOL VARCHAR2(20),
  DURATA NUMBER(6,0),
  DURATAF NUMBER(6,0),
  DURATAG NUMBER(6,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EED728A87CE36A8FF71B71F5C01CF8F5F4F8578</HASHVAL>
  <TEXT>CREATE TABLE MIFIX (
  CODMIFIX NUMBER(20,0) NOT NULL,
  TIP VARCHAR2(2),
  NRINVENTAR NUMBER(20,0),
  ANINTRARE NUMBER(4,0),
  LUNAINTRARE NUMBER(2,0),
  OBS VARCHAR2(30),
  ANINTRAREG NUMBER(4,0),
  LUNAINTRAREG NUMBER(2,0),
  SERIEINV VARCHAR2(30),
  CODMIFIXIMB NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  ANSTOPDEGRESIV NUMBER(4,0),
  LUNASTOPDEGRESIV NUMBER(2,0),
  CODMIFIXNOU NUMBER(20,0),
  ANLUNAMIFIXNOU NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MIFIX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00743D9F7ED2F649E82B03AC7C7528311B0AD40C</HASHVAL>
  <TEXT>CREATE TABLE MIFIX1 (
  CODMIFIX1 NUMBER(20,0) NOT NULL,
  CODMIFIX NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  CODCLASIF NUMBER(20,0),
  TIPAMO NUMBER(3,0),
  STARE NUMBER(3,0),
  DURATAN NUMBER(10,0),
  GRADU NUMBER(8,4),
  DURATAF NUMBER(10,0),
  AMO NUMBER(20,7),
  NEUTIL NUMBER(20,7),
  DFBLOCAT NUMBER(1,0),
  CODPERS NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODNIRSER NUMBER(20,0),
  TIPREEVAL NUMBER(1,0),
  DATAREEVAL DATE,
  INCLUDRATA NUMBER(1,0),
  AMOVECHI NUMBER(20,7),
  PRETVECHI NUMBER(20,7),
  NEUTILVECHI NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DURATANF NUMBER(10,0),
  DURATAFF NUMBER(10,0),
  AMOF NUMBER(20,7),
  DURATANG NUMBER(10,0),
  DURATAFG NUMBER(10,0),
  AMOG NUMBER(20,7),
  DFBLOCAT_F NUMBER(1,0),
  DFBLOCAT_G NUMBER(1,0),
  PRETINITIAL NUMBER(20,7),
  REZERVA NUMBER(20,7),
  REZERVABLOCAT NUMBER(1,0),
  CODSABLON NUMBER(20,0),
  AMOBLOCAT NUMBER(1,0),
  CENTRUBLOCAT NUMBER(1,0),
  CODCLASIFBLOCAT NUMBER(1,0),
  CODPERSBLOCAT NUMBER(1,0),
  NODANALIZABLOCAT NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  AMOREZERVA NUMBER(20,7),
  AMORBLOCAT NUMBER(1,0),
  AMOFBLOCAT NUMBER(1,0),
  AMOGBLOCAT NUMBER(1,0),
  PRETINIBLOCAT NUMBER(1,0),
  PRETINITIAL_F NUMBER(20,7),
  PRETINITIAL_FBLOCAT NUMBER(1,0),
  TIPSTORNO NUMBER(1,0),
  AMOANPREC NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MIFIX1_SIMULARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>801BF6F0E67F9B2BBD8583525286C74AB1568D1C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MIFIX1_SIMULARE (
  CODMIFIX1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  CODCLASIF NUMBER(20,0),
  TIPAMO NUMBER(3,0),
  STARE NUMBER(3,0),
  DURATAN NUMBER(10,0),
  GRADU NUMBER(4,0),
  DURATAF NUMBER(10,0),
  AMO NUMBER(20,7),
  NEUTIL NUMBER(20,7),
  DFBLOCAT NUMBER(1,0),
  CODPERS NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODNIRSER NUMBER(20,0),
  TIPREEVAL NUMBER(1,0),
  DATAREEVAL DATE,
  INCLUDRATA NUMBER(1,0),
  AMOVECHI NUMBER(20,7),
  PRETVECHI NUMBER(20,7),
  NEUTILVECHI NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DURATANF NUMBER(10,0),
  DURATAFF NUMBER(10,0),
  AMOF NUMBER(20,7),
  DURATANG NUMBER(10,0),
  DURATAFG NUMBER(10,0),
  AMOG NUMBER(20,7),
  DFBLOCAT_F NUMBER(1,0),
  DFBLOCAT_G NUMBER(1,0),
  PRETINITIAL NUMBER(20,7),
  REZERVA NUMBER(20,7),
  REZERVABLOCAT NUMBER(1,0),
  CODSABLON NUMBER(20,0),
  AMOBLOCAT NUMBER(1,0),
  CENTRUBLOCAT NUMBER(1,0),
  CODCLASIFBLOCAT NUMBER(1,0),
  CODPERSBLOCAT NUMBER(1,0),
  NODANALIZABLOCAT NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  AMOREZERVA NUMBER(20,7),
  AMORBLOCAT NUMBER(1,0),
  AMOFBLOCAT NUMBER(1,0),
  AMOGBLOCAT NUMBER(1,0),
  PRETINIBLOCAT NUMBER(1,0),
  PRETINITIAL_F NUMBER(20,7),
  PRETINITIAL_FBLOCAT NUMBER(1,0),
  TIPSTORNO NUMBER(1,0),
  AMOANPREC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MIFIX_SIMULARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>827BA26FB76F6210D53A13BC3CF42E6303DA78F3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE MIFIX_SIMULARE (
  CODMIFIX NUMBER(20,0),
  TIP VARCHAR2(2),
  NRINVENTAR NUMBER(20,0),
  ANINTRARE NUMBER(4,0),
  LUNAINTRARE NUMBER(2,0),
  OBS VARCHAR2(30),
  ANINTRAREG NUMBER(4,0),
  LUNAINTRAREG NUMBER(2,0),
  SERIEINV VARCHAR2(30),
  CODMIFIXIMB NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  ANSTOPDEGRESIV NUMBER(4,0),
  LUNASTOPDEGRESIV NUMBER(2,0),
  CODMIFIXNOU NUMBER(20,0),
  ANLUNAMIFIXNOU NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODIFICARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66A2D49435B653B1567E2CD22E08B6473AC8E343</HASHVAL>
  <TEXT>CREATE TABLE MODIFICARI (
  CODMODIFICARE NUMBER(20,0) NOT NULL,
  CODMASTER NUMBER(20,0),
  TABLENAME VARCHAR2(20),
  DATAMODIF DATE,
  USERMODIF NUMBER(10,0),
  TIPMODIF NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODIFICARIPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>715B8A33763C8CC37008A5748297202B378A32D0</HASHVAL>
  <TEXT>CREATE TABLE MODIFICARIPRET (
  CODMODIF NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  PRETNOU NUMBER(20,7),
  DATA DATE,
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODI_STATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FAAE06AA9C3E625DBD59388290066F4B3F2BE96</HASHVAL>
  <TEXT>CREATE TABLE MODI_STATE (
  CODMODI_STATE NUMBER(20,0) NOT NULL,
  CODMASTER NUMBER(20,0),
  TABLENAME VARCHAR2(20),
  MODIDATE TIMESTAMP(6),
  TIPMODIF NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODPLATA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A772E14AB55412EED04EF2A060DA9873A036BC27</HASHVAL>
  <TEXT>CREATE TABLE MODPLATA2 (
  CODMODPLATA2 NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  CODCARD NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODPLATAIESRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>021FEEE7640A809A87A07B4C2B22FC5EA8F567B7</HASHVAL>
  <TEXT>CREATE TABLE MODPLATAIESRETAIL (
  COD NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  CODBANKCONT NUMBER(20,0),
  VOUCHERSGR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MODURIPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0222B26A411EB201C580E386AA5FEBE92F174263</HASHVAL>
  <TEXT>CREATE TABLE MODURIPLATI (
  CODMODPLATA NUMBER(20,0) NOT NULL,
  CODIES NUMBER(20,0),
  TIPPLATA NUMBER(5,0),
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DENMODPLATA VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MOTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>716D5210434F93569E945ED2298F667AEE5C9C9A</HASHVAL>
  <TEXT>CREATE TABLE MOTIVE (
  CODMOTIV NUMBER(20,0) NOT NULL,
  CONTINUT VARCHAR2(200),
  TIP NUMBER(2,0),
  COD VARCHAR2(50),
  MOTIV VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MOTIVEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0118735A5DEA427A3C56340D0A27AFCD7E040842</HASHVAL>
  <TEXT>CREATE TABLE MOTIVEP (
  CODMOTIV NUMBER(20,0) NOT NULL,
  DENMOTIV VARCHAR2(80),
  MOTIV VARCHAR2(240)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MPBCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>457A3F3C9FA8ECAB71F16F3E6A9BD4532996816B</HASHVAL>
  <TEXT>CREATE TABLE MPBCAR (
  CODMPBCAR NUMBER(20,0) NOT NULL,
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODPART NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  TIPBCAR NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MPBCAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62C63959256CFE5D539B586A14C9959021C732B9</HASHVAL>
  <TEXT>CREATE TABLE MPBCAR1 (
  CODMPBCAR1 NUMBER(20,0) NOT NULL,
  CODMPBCAR NUMBER(20,0),
  CODBCAR NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DENOBIECT VARCHAR2(200),
  CODOBIECT NUMBER(20,0),
  NETKG NUMBER(20,7),
  UTILKG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETUSCARE NUMBER(20,7),
  PRETLASTAS NUMBER(20,7),
  TIPBCAR NUMBER(1,0),
  PRETACHIZNOU NUMBER(20,7),
  CODCONTRACT1 NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(22,4),
  IAUMIDITATE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MPBCAR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F01C9B50EA0EC18A041A6B25354FCDA5857EEF5D</HASHVAL>
  <TEXT>CREATE TABLE MPBCAR2 (
  CODMPBCAR2 NUMBER(20,0) NOT NULL,
  CODMPBCAR NUMBER(20,0),
  IAUMIDITATE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MURES_NS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE6709F86F0878D071AAA0DD81B95572EC590F6F</HASHVAL>
  <TEXT>CREATE TABLE MURES_NS (
  OLD NUMBER(20,0),
  NEW NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>MURES_OB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F93E7283CCEFA9FCDB86B5B10EA87958B24EB4E</HASHVAL>
  <TEXT>CREATE TABLE MURES_OB (
  OLD NUMBER(20,0),
  NEW NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42B254CDB83D5AE20E29B8C923FDFC3B7631F74D</HASHVAL>
  <TEXT>CREATE TABLE NACTIVIT (
  CODACTIVIT NUMBER(20,0) NOT NULL,
  DEN_ACTIVIT VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E8642A9965A328BB26B77E1384199C58FE1BA37</HASHVAL>
  <TEXT>CREATE TABLE NAGENDA (
  CODAGENDA NUMBER(20,0) NOT NULL,
  TIP NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  SEDIUSOCIAL NUMBER(1,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(350),
  SECTOR NUMBER(2,0),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  CODPOSTAL VARCHAR2(10),
  KM NUMBER(7,2),
  OBS VARCHAR2(100),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODTIPSEDIU NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  CODAGENT NUMBER(20,0),
  CODCLIENT VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  POZTRASEU NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODCORESP NUMBER(20,0),
  TRANSPCLIENT NUMBER(1,0),
  COEFUTILAJE NUMBER(7,2),
  SUPRAFATA NUMBER(10,2),
  MODSERVIRE NUMBER(1,0),
  IDSEDIU VARCHAR2(20),
  COD_CODFISCAL NUMBER(20,0),
  TELEFONP VARCHAR2(40),
  EDI_EXPTIP NUMBER(1,0),
  EDI_PARTTIP NUMBER(1,0),
  EDI_PARTID VARCHAR2(20),
  EDI_OBJTIP NUMBER(1,0),
  GLN VARCHAR2(13),
  GESTLIVRARE NUMBER(20,0),
  LONGITUDINE VARCHAR2(50),
  LATITUDINE VARCHAR2(50),
  OBS2 VARCHAR2(400),
  EDI_IMPTIP NUMBER(1,0),
  EDI_FURNTIP NUMBER(1,0),
  EDI_FURNID VARCHAR2(20),
  EDI_OBJTIPIMP NUMBER(1,0),
  EDI_EXPCUMUL NUMBER(1,0),
  EDI_EXPEAN NUMBER(1,0),
  EDI_OBJTIP2 NUMBER(1,0),
  CODTRASEU1 NUMBER(20,0),
  POZTRASEU1 NUMBER(20,0),
  CODANTREPOZIT VARCHAR2(20),
  ZILETRANSPORT NUMBER(3,0),
  EDI_DENUM NUMBER(1,0),
  EDI_SUBDIREXP VARCHAR2(30),
  VERFACT NUMBER(10,0),
  VERDISPLIVR NUMBER(10,0),
  VERPROFORMA NUMBER(10,0),
  VERFACTAVIZ NUMBER(10,0),
  VERAVIZIES NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAGENDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1002A13CCE511DDF1148DA4A3CB203D46EF23187</HASHVAL>
  <TEXT>CREATE TABLE NAGENDA1 (
  CODAGENDA1 NUMBER(20,0) NOT NULL,
  CODAGENDA NUMBER(20,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  CREDITCLIENT NUMBER(18,2),
  ZILEDEPASIRE NUMBER(10,0),
  NRFACTSOLD NUMBER(10,0),
  SCADENTAV NUMBER(5,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAGENTI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66466889F89108E383C017C9E1C4DF3580548A2B</HASHVAL>
  <TEXT>CREATE TABLE NAGENTI1 (
  CODAGENT1 NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAGENTIPROC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E0B95862CFC02E29ABAC47B1D8A0DE5017AA4B91</HASHVAL>
  <TEXT>CREATE TABLE NAGENTIPROC (
  CODAGENTPROC NUMBER(20,0) NOT NULL,
  CODAGENT1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PECLASEA NUMBER(1,0),
  CODPART NUMBER(20,0),
  PECLASEP NUMBER(1,0),
  PROC NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAGENTIVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D9B6D91C040BC99E5D0412E36CAC34509991229</HASHVAL>
  <TEXT>CREATE TABLE NAGENTIVAL (
  CODAGENTVAL NUMBER(20,0) NOT NULL,
  CODAGENT1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  VALMAX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5FC4D51B50CAFFEA081AF4B757A021F7AFA88E3</HASHVAL>
  <TEXT>CREATE TABLE NART (
  CODARTICOL NUMBER(20,0) NOT NULL,
  DEN_ARTICOL VARCHAR2(100),
  TIPARTICOL VARCHAR2(1),
  CLASA NUMBER(20,0),
  UM NUMBER(20,0),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  CONTIMPLICIT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  CERTIFICAT NUMBER(1,0),
  ARETG NUMBER(1,0),
  EVOLUTIEPRET NUMBER(1,0),
  CONTSERVICIU NUMBER(20,0),
  INCREMENTSERIE NUMBER(10,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  CASADEMARCAT NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CLASASTATIST NUMBER(20,0),
  COMENZIONLINE NUMBER(1,0),
  CODEXTERNART VARCHAR2(30),
  SUFIXCODEXTERN VARCHAR2(60),
  RESTNEGLIJCMD NUMBER(10,5),
  MUSAICALITATE NUMBER(1,0),
  NRZILESTOCMEDIU NUMBER(4,0),
  CODCENTRU NUMBER(20,0),
  DCI VARCHAR2(100),
  PARITATED1 NUMBER(12,7),
  PARITATED2 NUMBER(12,7),
  PARITATED3 NUMBER(12,7),
  CULOARE NUMBER(8,0),
  CLASAW NUMBER(20,0),
  CHECKISAUTENTIC NUMBER(1,0),
  PROCPERISAB NUMBER(8,4),
  CODMASCA NUMBER(20,0),
  TIPSTOC NUMBER(2,0),
  CONSTRUCTIENOUA NUMBER(1,0),
  RISCFISCAL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48B6F0B4FA29C97A63125A8FFAEA1727D1D5EAA1</HASHVAL>
  <TEXT>CREATE TABLE NART1 (
  CODARTICOL1 NUMBER(20,0) NOT NULL,
  CODARTICOL NUMBER(20,0),
  CODTVA NUMBER(20,0),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODACCIZEDVI NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  TAXCODE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15841933DC9E7D843FCD45ABA29C8013DD76F0D4</HASHVAL>
  <TEXT>CREATE TABLE NARTAMB (
  CODAMB NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODOBIECTRETURN NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODEXTERN VARCHAR2(40),
  CODPLU NUMBER(20,0),
  CODINTERN VARCHAR2(32),
  MASA NUMBER(20,7),
  LUNGIME NUMBER(20,7),
  LATIME NUMBER(20,7),
  INALTIME NUMBER(20,7),
  LXLAT NUMBER(1,0),
  LXH NUMBER(1,0),
  LATXH NUMBER(1,0),
  GREUTSPECIFICA NUMBER(20,7),
  IMPLICITTIPDOC NUMBER(20,0),
  TIP NUMBER(1,0),
  RETURNABIL NUMBER(1,0),
  NR_RANDURI NUMBER(3,0),
  ADMAX NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63C66E2BC541FD8F4CD55FD8D671869E02C7DF64</HASHVAL>
  <TEXT>CREATE TABLE NARTATR (
  CODARTATR NUMBER(20,0) NOT NULL,
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  ACTIV NUMBER(1,0),
  CODVALPREDEF NUMBER(20,0),
  OBLIGATORIU NUMBER(1,0),
  SELECTIE NUMBER(1,0),
  FACTURABIL NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  OBS VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTCLI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48EC2DFEABB433FC738B5EFF7192094952A33545</HASHVAL>
  <TEXT>CREATE TABLE NARTCLI (
  CODARTCLI NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(30),
  UMSEC NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  PRET NUMBER(20,7),
  TIPCODAFISAT NUMBER(1,0),
  UMCORELAT NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLACLIENT VARCHAR2(30),
  CODCLASEP NUMBER(20,0),
  CODGAMA NUMBER(20,0),
  CODINTERN VARCHAR2(30),
  OBS VARCHAR2(100),
  OBS2 VARCHAR2(400),
  UMSECIMPDOC NUMBER(20,0),
  DURATATR NUMBER(20,7),
  ZILESTOC NUMBER(20,7),
  GLN VARCHAR2(13),
  IDSPECIFIC VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTDELETED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>950387419F1BB5DA77CD1181BFE049C2EC124AD1</HASHVAL>
  <TEXT>CREATE TABLE NARTDELETED (
  CODARTICOL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTDIM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>225E58FF112C1719B3C12E813E1380DAB7C1B67D</HASHVAL>
  <TEXT>CREATE TABLE NARTDIM (
  CODARTDIM NUMBER(20,0) NOT NULL,
  CODARTICOL NUMBER(20,0),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTIMPLICITE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAF6BDA4F4D30595B91D41A6B7D80698541A6451</HASHVAL>
  <TEXT>CREATE TABLE NARTIMPLICITE (
  CODIMPLICIT NUMBER(20,0) NOT NULL,
  CODARTICOL NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CONTIMPLICIT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  LOCATIEIMPLICITA NUMBER(20,0),
  NEVANDABIL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F83D628DB729A9A86ED934A20DDAF348D3E0896</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJ (
  CODOBIECT NUMBER(20,0) NOT NULL,
  CODARTICOL NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  VOLUM NUMBER(20,5),
  STOCMIN NUMBER(20,5),
  STOCMAX NUMBER(20,5),
  RETURNABIL NUMBER(1,0),
  LUNIGARANTIE NUMBER(4,0),
  OBS VARCHAR2(300),
  PROCADAOSNIR NUMBER(5,2),
  ROTUNJIRE NUMBER(2,0),
  ADAOSEXCEPTIE NUMBER(5,2),
  PROMOTIE NUMBER(1,0),
  ROTVALUTA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  UMAMBALARE NUMBER(20,0),
  PRETMINIM NUMBER(20,5),
  TERMENPLATA NUMBER(5,0),
  DATAADAUGARII DATE,
  CODPLU NUMBER(20,0),
  USESTOCMED NUMBER(1,0),
  DURMAXAPROV NUMBER(10,0),
  CODCNAS VARCHAR2(20),
  CODCARACT NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  DISCPROMO NUMBER(20,7),
  TARAORIGINE NUMBER(20,0),
  ZILEVALABIL NUMBER(10,0),
  ZILEDISTRIB NUMBER(10,0),
  CODPERISABIL NUMBER(20,0),
  NEFACTURABIL NUMBER(1,0),
  GREUTSPECIFICA NUMBER(20,7),
  STOCMED NUMBER(20,5),
  INACTIVCMDONLINE NUMBER(1,0),
  PRODUSPROPRIU NUMBER(1,0),
  MESAJINACTIV VARCHAR2(100),
  AUTORIZATIE VARCHAR2(20),
  EXPIRAREAUTORIZ DATE,
  TRADUCARTGENERIC NUMBER(1,0),
  CODD394 VARCHAR2(8),
  INACTIV NUMBER(1,0),
  FARACMDFURN NUMBER(1,0),
  FARANIVELAPROB NUMBER(1,0),
  DESCARCAREINTEGRALA NUMBER(1,0),
  FARASTOC NUMBER(1,0),
  CODCATEGARTTI NUMBER(20,0),
  COEFCNAS NUMBER(20,7),
  EXPORTEMCS NUMBER(1,0),
  CODNC VARCHAR2(10),
  CODACCIZABIL VARCHAR2(10),
  RAPCNAS NUMBER(1,0),
  LANSIMP NUMBER(1,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  CODANALIZANOD NUMBER(20,0),
  SAFT_EXPORT NUMBER(1,0),
  CANTVANZ NUMBER(20,7),
  CODCPV VARCHAR2(10),
  EXCLUSLISTARECM NUMBER(1,0),
  ANTIBIOTIC NUMBER(1,0),
  CERTIF_DDS NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7027EE48886835298CF6E4968D7E73F04C98D568</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJ1 (
  CODOBIECT1 NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  PRETMAXIMAL NUMBER(24,7),
  PROCADAOSMAXIMAL NUMBER(24,7),
  ADAOSLA NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PRETREFERINTA NUMBER(24,7),
  TIPPRETMAX NUMBER(1,0),
  COMPENSAT NUMBER(1,0),
  TIPCOMPENSARE VARCHAR2(10),
  GRUPA VARCHAR2(20),
  UPLIFT NUMBER(10,7),
  CODMONEDA NUMBER(20,0),
  PUNCTE NUMBER(10,0),
  UMIDITATE NUMBER(20,7),
  CORPURI_STRAINE NUMBER(20,7),
  INCOLTIT NUMBER(20,7),
  HECTOLITRICA NUMBER(20,7),
  GLUTEN NUMBER(20,7),
  FUZARITATE NUMBER(20,7),
  CADERE NUMBER(20,7),
  DEFORMARE NUMBER(20,7),
  STICLOZITATE NUMBER(20,7),
  SPARTURI NUMBER(20,7),
  PUNCTESECTIE NUMBER(10,0),
  TIPPRET NUMBER(1,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  D390EXCLUS NUMBER(1,0),
  COST NUMBER(20,7),
  CANTSERVAUTO NUMBER(20,7),
  PROTEINA NUMBER(20,7),
  AFLATOXINA NUMBER(20,7),
  ATAC_PLOSNITA NUMBER(20,7),
  CONTINUT_ULEI NUMBER(20,7),
  ACIDITATE NUMBER(20,7),
  SISTAVE NUMBER(20,7),
  REFRACTIE NUMBER(20,7),
  INDICE_W NUMBER(20,7),
  TOXINA_DON NUMBER(20,7),
  BOABE_TOXICE NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  MAX_UMIDITATE NUMBER(20,7),
  MAX_CORPURI_STRAINE NUMBER(20,7),
  MAX_INCOLTIT NUMBER(20,7),
  MAX_HECTOLITRICA NUMBER(20,7),
  MAX_GLUTEN NUMBER(20,7),
  MAX_FUZARITATE NUMBER(20,7),
  MAX_CADERE NUMBER(20,7),
  MAX_DEFORMARE NUMBER(20,7),
  MAX_STICLOZITATE NUMBER(20,7),
  MAX_SPARTURI NUMBER(20,7),
  MAX_PROTEINA NUMBER(20,7),
  MAX_AFLATOXINA NUMBER(20,7),
  MAX_ATAC_PLOSNITA NUMBER(20,7),
  MAX_CONTINUT_ULEI NUMBER(20,7),
  MAX_ACIDITATE NUMBER(20,7),
  MAX_SISTAVE NUMBER(20,7),
  MAX_REFRACTIE NUMBER(20,7),
  MAX_INDICE_W NUMBER(20,7),
  MAX_TOXINA_DON NUMBER(20,7),
  MAX_BOABE_TOXICE NUMBER(20,7),
  MIN_UMIDITATE NUMBER(20,7),
  MIN_CORPURI_STRAINE NUMBER(20,7),
  MIN_INCOLTIT NUMBER(20,7),
  MIN_HECTOLITRICA NUMBER(20,7),
  MIN_GLUTEN NUMBER(20,7),
  MIN_FUZARITATE NUMBER(20,7),
  MIN_CADERE NUMBER(20,7),
  MIN_DEFORMARE NUMBER(20,7),
  MIN_STICLOZITATE NUMBER(20,7),
  MIN_SPARTURI NUMBER(20,7),
  MIN_PROTEINA NUMBER(20,7),
  MIN_AFLATOXINA NUMBER(20,7),
  MIN_ATAC_PLOSNITA NUMBER(20,7),
  MIN_CONTINUT_ULEI NUMBER(20,7),
  MIN_ACIDITATE NUMBER(20,7),
  MIN_SISTAVE NUMBER(20,7),
  MIN_REFRACTIE NUMBER(20,7),
  MIN_INDICE_W NUMBER(20,7),
  MIN_TOXINA_DON NUMBER(20,7),
  MIN_BOABE_TOXICE NUMBER(20,7),
  PRETPROD NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJCOLET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDDF61F65D5149E2076C79AAD4702D691985E59E</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJCOLET (
  CODOBJCOLET NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CONTINUT VARCHAR2(30),
  IDCOLET VARCHAR2(10),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CB5A19A3A7E4EEE62383C33D45C9BE8A7B7207F</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJGEST (
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  D4 NUMBER(20,7),
  D5 NUMBER(20,7),
  D6 NUMBER(20,7),
  D7 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33C06F2D5FEE5A2B08219DFBF1BF06083465F42F</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJIMP (
  CODOBJIMP NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  LOCATIEIMPLICITA NUMBER(20,0),
  DURMAXAPROV NUMBER(10,0),
  CONTIMPLICIT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA4CB6D180F04E9BCC86F6EDA66978367768D057</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJSUBUNIT (
  CODS NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7),
  STOCMED NUMBER(20,7),
  PROCSTOCMIN NUMBER(20,7),
  PROCSTOCMAX NUMBER(20,7),
  PROCSTOCMED NUMBER(20,7),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOBJTRAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B6C8AF5651D2956088258E1075239F526BC6F0F</HASHVAL>
  <TEXT>CREATE TABLE NARTOBJTRAD (
  CODOBIECTTRAD NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODLIMBA NUMBER(20,0),
  DENUMIRETRAD VARCHAR2(200),
  DESCRIERE NCLOB,
  AVERTIZARE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BACF5BB8E3A3951D6CEB8843989BA9E2A8030D3A</HASHVAL>
  <TEXT>CREATE TABLE NARTOPT (
  CODOPT NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODOBIECTOPT NUMBER(20,0),
  STANDARD NUMBER(1,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODTIPLOCATIE NUMBER(20,0),
  FORCELEI NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NARTOPTIUNI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02F3583A17901A873D4E51AD825F2AE57602222F</HASHVAL>
  <TEXT>CREATE TABLE NARTOPTIUNI (
  CODOPTIUNE NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NATRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7A98AB053FA2D5D67402E9BBC0298C301864AAE</HASHVAL>
  <TEXT>CREATE TABLE NATRIB (
  CODATRIBUT NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  TIPVALOARE NUMBER(1,0),
  PREFIX VARCHAR2(20),
  COLSUPLIM VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NATRIB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EE9C38EB8CDC6A223460495BB5685A4C0D2CE19</HASHVAL>
  <TEXT>CREATE TABLE NATRIB1 (
  CODVALATR NUMBER(20,0) NOT NULL,
  CODATRIBUT NUMBER(20,0),
  VALOARE VARCHAR2(50),
  CODOBIECTASOC NUMBER(20,0),
  CODEXTERN VARCHAR2(10),
  GRUPA VARCHAR2(5),
  INACTIV NUMBER(1,0),
  PROCMAJPU NUMBER(8,5),
  INACTIVCMDONLINE NUMBER(1,0),
  MESAJINACTIV VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NATRIB1TRAD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B3DC586C4ECBDBB517227C499750A53D2316895</HASHVAL>
  <TEXT>CREATE TABLE NATRIB1TRAD (
  CODATRIB1TRAD NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODLIMBA NUMBER(20,0),
  MESAJINACTIV VARCHAR2(100),
  DENUMIRE VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NATRIB2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CF1B05C68B1822352A17F81931FCDD20EF5BAA31</HASHVAL>
  <TEXT>CREATE TABLE NATRIB2 (
  CODATRIB2 NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  PROCMAJ NUMBER(8,5)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NATROBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D93F30D7DE7504C0AB9A315705CB99979930661E</HASHVAL>
  <TEXT>CREATE TABLE NATROBJ (
  CODATROBJ NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODARTATR NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NAUTORIZATIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3DA4790A3EE93D93EE372F3B8EE4234FD093A366</HASHVAL>
  <TEXT>CREATE TABLE NAUTORIZATIIAUTO (
  CODAUTORIZATII NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  ATENTIONARE NUMBER(10,0),
  CODSERVICIU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NBANCIRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ADB1EEB506DAC756438D69BFE4D19B8CD2895ADA</HASHVAL>
  <TEXT>CREATE TABLE NBANCIRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODBANK NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  CONTBANCA VARCHAR2(30),
  SUCURSALA VARCHAR2(20),
  CODMONEDA NUMBER(20,0),
  DENBANCA VARCHAR2(50),
  DENLOCALIT VARCHAR2(50),
  CODPARTB NUMBER(20,0),
  CODJUDET NUMBER(20,0),
  CODTARA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92B88D59CFBD412116FCFA471D5A7BF6895E0D21</HASHVAL>
  <TEXT>CREATE TABLE NBANK (
  CODBANK NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  CODSWIFT VARCHAR2(30),
  CODBNR VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NBANKCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>994DD53787ADA573E7E2A2DD2D3E1C32C98244AB</HASHVAL>
  <TEXT>CREATE TABLE NBANKCONT (
  CODBANKCONT NUMBER(20,0) NOT NULL,
  CODBANK NUMBER(20,0),
  DEN_CONT VARCHAR2(30),
  CODLOCALITATE NUMBER(20,0),
  NRCONT VARCHAR2(30),
  CODMONEDA NUMBER(20,0),
  FILIALA VARCHAR2(20),
  DATADESKIS DATE,
  DATAINKIS DATE,
  CREDIT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  POS NUMBER(1,0),
  POSID VARCHAR2(30),
  CONTTVA NUMBER(1,0),
  FARAREG NUMBER(1,0),
  FARA_CASH_FLOW NUMBER(1,0),
  OBS VARCHAR2(300),
  IMPLICITEF NUMBER(1,0),
  INSTITPUBLICE NUMBER(1,0),
  ORDINE NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NBANKCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>102731AFB076760ACC5D2B86BE86494C7B1FAE7E</HASHVAL>
  <TEXT>CREATE TABLE NBANKCONT1 (
  CODBANKCONT1 NUMBER(20,0) NOT NULL,
  CODBANKCONT NUMBER(20,0),
  CODIOBANCA NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NBANKSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>681E7C5429D7F831F708229D94F5E7BBC77B2B2B</HASHVAL>
  <TEXT>CREATE TABLE NBANKSOLDLUNA (
  CODBANKSOLDLUNA NUMBER(20,0) NOT NULL,
  CODBANKCONT NUMBER(20,0),
  SOLDLEI NUMBER(24,7),
  SOLDVALUTA NUMBER(24,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A385C1AC9F9EC2BC8C44E17A1C03C6FA38536D74</HASHVAL>
  <TEXT>CREATE TABLE NC (
  CODNC NUMBER(20,0) NOT NULL,
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PART NUMBER(20,0),
  JURNALTVA NUMBER(5,0),
  TIPTRANZ NUMBER(5,0),
  TIPTVA NUMBER(5,0),
  VALOARE NUMBER(20,3),
  MONEDA NUMBER(21,0),
  CURS NUMBER(20,7),
  OBS VARCHAR2(100),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SABLON NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  APROBAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCE84605811271A1DAF1E719B08041356D990DA0</HASHVAL>
  <TEXT>CREATE TABLE NC1 (
  CODNC1 NUMBER(20,0) NOT NULL,
  CODNC NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,3),
  OBS VARCHAR2(80),
  CODGEST NUMBER(20,0),
  PARTD NUMBER(1,0),
  PARTC NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  ICONTD NUMBER(3,0),
  ICONTC NUMBER(3,0),
  TIPLINIETVA NUMBER(5,0),
  CODCENTRU NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  PERSD NUMBER(1,0),
  PERSC NUMBER(1,0),
  CODPART NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODCMDINT1 NUMBER(20,0),
  MFSAFT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NC1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C8CE567E7050F65C84F7D46DD3D103A9F4C69EEC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE NC1_MAN (
  CODNC1 NUMBER(20,0),
  CODNC NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,3),
  OBS VARCHAR2(80),
  CODGEST NUMBER(20,0),
  PARTD NUMBER(1,0),
  PARTC NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  ICONTD NUMBER(3,0),
  ICONTC NUMBER(3,0),
  TIPLINIETVA NUMBER(5,0),
  CODCENTRU NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  PERSD NUMBER(1,0),
  PERSC NUMBER(1,0),
  CODPART NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODCMDINT1 NUMBER(20,0),
  MFSAFT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCARSUPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>678D4607DEAAC008A11F5FB07A1B81127BB4B3CD</HASHVAL>
  <TEXT>CREATE TABLE NCARSUPART (
  CODCARSUPART NUMBER(20,0) NOT NULL,
  DEN_CARSUPART VARCHAR2(80),
  CULOARE NUMBER(8,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCASEMARCAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B203A94CF7A994C1E15D4283C9EDD12B9CF40372</HASHVAL>
  <TEXT>CREATE TABLE NCASEMARCAT (
  CODCASEMARCAT NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  NUMAR NUMBER(10,0),
  PORT NUMBER(20,0),
  TIP NUMBER(10,0),
  MODEL NUMBER(10,0),
  CODFISCAL VARCHAR2(12),
  CODBARECANTAR NUMBER(1,0),
  PLUMAXCANTAR NUMBER(20,0),
  NRMAXPLU NUMBER(20,0),
  LUNGIMETEXT NUMBER(5,0),
  TIPDRIVER NUMBER(5,0),
  RATA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  GESTDESTTRANSF NUMBER(20,0),
  CODIOARTDESTTRANSF NUMBER(20,0),
  TIPINFOART NUMBER(2,0),
  CODCARNETTRANSF NUMBER(20,0),
  TEXTPROMO VARCHAR2(300),
  CODCARNETNIR NUMBER(20,0),
  INACTIV NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCASEMARCAT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C04B5AB6551DA300473EA653DEAD2105FDDDF5C</HASHVAL>
  <TEXT>CREATE TABLE NCASEMARCAT1 (
  CODCASEMARCAT1 NUMBER(20,0) NOT NULL,
  CODCASEMARCAT NUMBER(20,0),
  CODGESTIUNE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCASEMARCAT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>51EA121ABD9D928141E05F895518B45006CAC0AE</HASHVAL>
  <TEXT>CREATE TABLE NCASEMARCAT2 (
  CODCASEMARCAT2 NUMBER(20,0) NOT NULL,
  CODCASEMARCAT NUMBER(20,0),
  PROCENT_TVA NUMBER(20,7),
  PARAMCASA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEC5801EB866B8D6823334E451969195F4C5523A</HASHVAL>
  <TEXT>CREATE TABLE NCATPRET (
  CODCATPRET NUMBER(20,0) NOT NULL,
  DEN_CATPRET VARCHAR2(30),
  TIP NUMBER(2,0),
  SIMBOL VARCHAR2(10),
  PROCDINIMPLICIT NUMBER(20,7),
  SUMAFIXAIMPLICIT NUMBER(20,7),
  CODCATMASTER NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCCADOURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2C319925C6827EDDFC5CD29F89AF72C4508E6F1</HASHVAL>
  <TEXT>CREATE TABLE NCCADOURI (
  CODNCCADOURI NUMBER(20,0) NOT NULL,
  CODNCREDIT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTASOC NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DIFERENTE NUMBER(20,7),
  CODOBIECTASOCSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTFACT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>550A37A5CCC6FBDE75C3631DC1AEF72CE10881FC</HASHVAL>
  <TEXT>CREATE TABLE NCLASEA (
  CODCLASEA NUMBER(20,0) NOT NULL,
  DEN_CLASEA VARCHAR2(150),
  SIMBOL VARCHAR2(50),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  VERLISTSUPLFACT NUMBER(10,0),
  VERLISTSUPLTOALL NUMBER(1,0),
  CODIDENT VARCHAR2(250),
  VERLISTSUPLAVIZ NUMBER(20,0),
  DISCOFE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D23E2C3774E73AEB94124D6A341AE76F1875CFFB</HASHVAL>
  <TEXT>CREATE TABLE NCLASEAS (
  CODCLASEAS NUMBER(20,0) NOT NULL,
  DEN_CLASEAS VARCHAR2(250),
  SIMBOL VARCHAR2(250),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  VERLISTSUPLFACT NUMBER(10,0),
  VERLISTSUPLTOALL NUMBER(1,0),
  TIP NUMBER(1,0),
  CODIDENT VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DAAE255704C575CAA77991605C5D1C45AA30A22</HASHVAL>
  <TEXT>CREATE TABLE NCLASEDISC (
  CODCLASEDISC NUMBER(20,0),
  DEN_CLASEDISC VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20EF57948F1FC6B11C0C3E1B6577F38204AC0BF8</HASHVAL>
  <TEXT>CREATE TABLE NCLASEG (
  CODCLASEG NUMBER(20,0) NOT NULL,
  DEN_CLASEG VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>482B94B83CD4EB37DD63E345F60EA576D2A5FCF3</HASHVAL>
  <TEXT>CREATE TABLE NCLASEINT (
  CODCLASEINT NUMBER(20,0) NOT NULL,
  DEN_CLASEINT VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07A8C512D033FC435A81DE162EC4E31ECDD4224D</HASHVAL>
  <TEXT>CREATE TABLE NCLASEMF (
  CODCLASEMF NUMBER(20,0) NOT NULL,
  DEN_CLASEMF VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6CDB6B5A0E7BA6D3B4BE36A3F0E78094BE2044BD</HASHVAL>
  <TEXT>CREATE TABLE NCLASEOP (
  CODCLASEOP NUMBER(20,0) NOT NULL,
  DEN_CLASEOP VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEOPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D3A6E848AE39DD8AD705EC5492D75CC2E9235EBD</HASHVAL>
  <TEXT>CREATE TABLE NCLASEOPT (
  CODCLASEOPT NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62AC22DE2C38210C251BBC4E85A7BD765725B24C</HASHVAL>
  <TEXT>CREATE TABLE NCLASEP (
  CODCLASEP NUMBER(20,0) NOT NULL,
  DEN_CLASEP VARCHAR2(30),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(2,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  CODIDENT VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCLASEPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E94667AB1B30620E4206AB38A90F08F9282C2859</HASHVAL>
  <TEXT>CREATE TABLE NCLASEPROD (
  CODCLASEPROD NUMBER(20,0) NOT NULL,
  DEN_CLASEPROD VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCODFISCRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C44556B113CE99284054777EF8F56009AC7BE46</HASHVAL>
  <TEXT>CREATE TABLE NCODFISCRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  PRINCIPAL NUMBER(1,0),
  COD_CODFISCAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03426FA2E62B4BE22BEE8E0045755F9F6405559F</HASHVAL>
  <TEXT>CREATE TABLE NCONT (
  CODCONT NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(200),
  NAME VARCHAR2(150),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50),
  ANINACTIV NUMBER(5,0),
  LUNAINACTIV NUMBER(2,0),
  CODSAFT VARCHAR2(70),
  TAXTYPE NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  IMPOZIT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F090DC822FFC8B0A63FEC3C73BEC35D4E370E867</HASHVAL>
  <TEXT>CREATE TABLE NCONT1 (
  CODCONT1 NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  CONTSECUNDAR NUMBER(20,0),
  CONTTERTIAR NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  TIPINCHIDERE NUMBER(1,0),
  CONTSECUNDARG NUMBER(20,0),
  CONTSECUNDARGO NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODCENTRUS NUMBER(20,0),
  CODCENTRUSG NUMBER(20,0),
  CODCENTRUSGO NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT1SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64C18715F45FEDD48B9692B0D12C584465557B8B</HASHVAL>
  <TEXT>CREATE TABLE NCONT1SUB (
  COD NUMBER(20,0),
  CODCONT1 NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPINCHIDERE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT1_SOCBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90717B44D0AD733352E8B87985519DE7A38002CF</HASHVAL>
  <TEXT>CREATE TABLE NCONT1_SOCBANK (
  CODCONT1 NUMBER(20,0),
  CODCONT NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  CONTSECUNDAR NUMBER(20,0),
  CONTTERTIAR NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  TIPINCHIDERE NUMBER(1,0),
  CONTSECUNDARG NUMBER(20,0),
  CONTSECUNDARGO NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODCENTRUS NUMBER(20,0),
  CODCENTRUSG NUMBER(20,0),
  CODCENTRUSGO NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTCOMUN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E84E38617B01AD8C523D12C7E755207F4886329</HASHVAL>
  <TEXT>CREATE TABLE NCONTCOMUN (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  TIPCONT NUMBER(1,0),
  BALSINT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  CODPARINTE NUMBER(20,0),
  DEN_CONT VARCHAR2(200),
  NRANALITICE NUMBER(3,0),
  VIZIBILBALANTA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCEE7623CB2138B99A42C0CBED00309BC445AEB0</HASHVAL>
  <TEXT>CREATE TABLE NCONTECHIV (
  CODCONTECHIV NUMBER(20,0),
  CONTVECHI NUMBER(20,0),
  CONTNOU NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTECHIVSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A7AD97534F45508BFEA1D6B6571F4B671B125C1</HASHVAL>
  <TEXT>CREATE TABLE NCONTECHIVSUB (
  CODCONTECHIVSUB NUMBER(20,0),
  CODCONTECHIV NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTFIRMECUPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CEF6A75C3F3B7BBF02DA7A21ABB669D6CD3E6D6</HASHVAL>
  <TEXT>CREATE TABLE NCONTFIRMECUPL (
  CODUNIC NUMBER(20,0),
  CODFIRMACUPL NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCONTCOMUN NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  TIPCONT NUMBER(1,0),
  BALSINT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  CODPARINTE NUMBER(20,0),
  DEN_CONT VARCHAR2(200),
  NRANALITICE NUMBER(3,0),
  SIMBOLCONTCOMUN VARCHAR2(30),
  LEGATURAINVALIDA NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>98599CE58F0BA86BA3D7EE97E9EEFF1D7C1B59E9</HASHVAL>
  <TEXT>CREATE TABLE NCONTREP (
  CODCONTREP NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTREPRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10310FCB4033EB46C351006F4462A9AE5A137C6B</HASHVAL>
  <TEXT>CREATE TABLE NCONTREPRUL (
  CODCONTREPRUL NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTREPRULSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B34E0C0866D0657E0D68A44B3BFC22E3961F10D9</HASHVAL>
  <TEXT>CREATE TABLE NCONTREPRULSUB (
  CODREPRULSUB NUMBER(20,0),
  CODCONTREPRUL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  RULAJPD NUMBER(20,7),
  RULAJPC NUMBER(20,7),
  RULAJVPD NUMBER(20,7),
  RULAJVPC NUMBER(20,7),
  RULAJP_IFRS NUMBER(20,7),
  RULAJC_IFRS NUMBER(20,7),
  RULAJVP_IFRS NUMBER(20,7),
  RULAJVC_IFRS NUMBER(20,7),
  RULAJP_GRUP NUMBER(20,7),
  RULAJC_GRUP NUMBER(20,7),
  RULAJVP_GRUP NUMBER(20,7),
  RULAJVC_GRUP NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTREPSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DB831620C9E65368174461FE43F3D23E20C369A</HASHVAL>
  <TEXT>CREATE TABLE NCONTREPSOLD (
  CODCONTREPSOLD NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTREPSOLDSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D7DF6DBB4DEE515CE6155EF41CDB6C439BB768A</HASHVAL>
  <TEXT>CREATE TABLE NCONTREPSOLDSUB (
  CODREPSOLDSUB NUMBER(20,0),
  CODCONTREPSOLD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SOLDID NUMBER(20,7),
  SOLDIC NUMBER(20,7),
  SOLDVID NUMBER(20,7),
  SOLDVIC NUMBER(20,7),
  SOLDI_IFRS NUMBER(20,7),
  SOLDVI_IFRS NUMBER(20,7),
  SOLDI_GRUP NUMBER(20,7),
  SOLDVI_GRUP NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CA35889E83F1ED54714A4098DC19EF0A65294D2</HASHVAL>
  <TEXT>CREATE TABLE NCONTRUL (
  CODCONTRUL NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTRULS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C033EFF39ED626D30CE98C1C5E0D794266306CC</HASHVAL>
  <TEXT>CREATE TABLE NCONTRULS (
  CODCONTRULS NUMBER(20,0) NOT NULL,
  CODCONTS NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTRULSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8ADEEE01BFBB18AFB1BCB98CFF387A33223922B</HASHVAL>
  <TEXT>CREATE TABLE NCONTRULSUB (
  CODCONTRULSUB NUMBER(20,0),
  CODCONTRUL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTRULT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85A60F57847FFC101923C1D2303F83726ACD80E3</HASHVAL>
  <TEXT>CREATE TABLE NCONTRULT (
  CODCONTRULT NUMBER(20,0) NOT NULL,
  CODCONTT NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F235CD2E99214B7307006B42C3225933A4B09C66</HASHVAL>
  <TEXT>CREATE TABLE NCONTS (
  CODCONTS NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(30),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(50),
  NAME VARCHAR2(50),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C968E8808D4DCE35E443679C8EE9B9E12AD982B</HASHVAL>
  <TEXT>CREATE TABLE NCONTS1 (
  CODCONTS1 NUMBER(20,0) NOT NULL,
  CODCONTS NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  SUPLCENTRE NUMBER(1,0),
  CODCONT NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5C2FC7496480D52C588E4F342C9841F530A68CF</HASHVAL>
  <TEXT>CREATE TABLE NCONTSOLD (
  CODCONTSOLD NUMBER(20,0) NOT NULL,
  CODCONT NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTSOLDS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>278A7A4A825BB2226D80F36729D941F1973301E8</HASHVAL>
  <TEXT>CREATE TABLE NCONTSOLDS (
  CODCONTSOLDS NUMBER(20,0) NOT NULL,
  CODCONTS NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTSOLDSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5858DF8C4867CF96AA3EB5393B6AB2AEA2A70A10</HASHVAL>
  <TEXT>CREATE TABLE NCONTSOLDSUB (
  CODCONTSOLDSUB NUMBER(20,0) NOT NULL,
  CODCONTSOLD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTSOLDT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>269437E12C24224F95AC43DF7E1819232F68DF57</HASHVAL>
  <TEXT>CREATE TABLE NCONTSOLDT (
  CODCONTSOLDT NUMBER(20,0) NOT NULL,
  CODCONTT NUMBER(20,0),
  SOLDID NUMBER(20,0),
  SOLDIC NUMBER(20,0),
  SOLDVID NUMBER(20,0),
  SOLDVIC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>297B90C94FF05FF4AD0480745AA428C675F6FCBA</HASHVAL>
  <TEXT>CREATE TABLE NCONTT (
  CODCONTT NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(30),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(50),
  NAME VARCHAR2(50),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONTT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>197283136EE99EEF98809B0B920BA1AA6783EEC9</HASHVAL>
  <TEXT>CREATE TABLE NCONTT1 (
  CODCONTT1 NUMBER(20,0) NOT NULL,
  CODCONTT NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  SUPLCENTRE NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT_BAK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EB51A2F0796CCE6A2034876986B3523B84302C0</HASHVAL>
  <TEXT>CREATE TABLE NCONT_BAK (
  CODCONT NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(50),
  NAME VARCHAR2(50),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT_NEWENTRY</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F1965C02735B3BE4D8C03837E6A3551F855FCA49</HASHVAL>
  <TEXT>CREATE TABLE NCONT_NEWENTRY (
  CODCONT NUMBER(5,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  NAME VARCHAR2(150),
  TIPCONT NUMBER(1,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  DONE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCONT_SOCBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DEF432CE4313766FEC0247BF2BDC0801F9DC2F8</HASHVAL>
  <TEXT>CREATE TABLE NCONT_SOCBANK (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(200),
  NAME VARCHAR2(150),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50),
  ANINACTIV NUMBER(5,0),
  LUNAINACTIV NUMBER(2,0),
  CODSAFT VARCHAR2(70),
  TAXTYPE NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  IMPOZIT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NCREANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>737F1E41BEDA03EE8285366482C7A21A4210BDA3</HASHVAL>
  <TEXT>CREATE TABLE NCREANTE (
  COD NUMBER(20,0),
  SIMBOL NUMBER(10,0),
  DENUMIRE VARCHAR2(90),
  TIP NUMBER(10,0),
  CONTB VARCHAR2(10),
  PERIOADAR VARCHAR2(1),
  SCADENTA NUMBER(10,0),
  RAPMULTIPLA NUMBER(1,0),
  DEDUCTIBIL NUMBER(1,0),
  DERESTITUIT NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  SURSA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NDELEGATRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35227766230349C4D5BCE173636CD5F3282A6789</HASHVAL>
  <TEXT>CREATE TABLE NDELEGATRETAIL (
  COD NUMBER(20,0) NOT NULL,
  CODPARTRETAIL NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  DATADOC DATE,
  ACTIV NUMBER(1,0),
  IMPLICIT NUMBER(1,0),
  OBS VARCHAR2(250),
  CODPARTTR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECESAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E48F24C2C5F2C7C931174AAA7E552EAEC2E6B3BD</HASHVAL>
  <TEXT>CREATE TABLE NECESAR (
  CODNECESAR NUMBER(20,0) NOT NULL,
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  OBS VARCHAR2(250),
  SAPTAMANA NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  VALPMP NUMBER(20,7),
  TIPNECESAR NUMBER(1,0),
  SUPLIMENT NUMBER(1,0),
  AN NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECESAR5</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>025639320A974F15C0152D8F01664A02C2842BAA</HASHVAL>
  <TEXT>CREATE TABLE NECESAR5 (
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  FURNIZOR VARCHAR2(250),
  NRINDICATOR NUMBER(2,0),
  INDICATOR VARCHAR2(200),
  STOCMIN NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  PRET NUMBER(20,7),
  ORDINE NUMBER(1,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECESARCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>22608F3C04BA6CA63031976C9F8A7FDFA365B306</HASHVAL>
  <TEXT>CREATE TABLE NECESARCMD (
  CODNECESAR NUMBER(20,0),
  CODCOMANDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECESARDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5804AB6835D746A64A5CB39EA0587E9B49F62082</HASHVAL>
  <TEXT>CREATE TABLE NECESARDOC (
  CODNECESAR NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECESAROBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>311ECA6EB43995C154C79E8E4609F20E93E90B10</HASHVAL>
  <TEXT>CREATE TABLE NECESAROBJ (
  CODNECESAR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  ACCEPTAT NUMBER(20,7),
  ACCEPTATUM1 NUMBER(20,7),
  PLANIFPER NUMBER(20,7),
  PLANIFPREC NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCMIN NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  STOCMAX NUMBER(20,7),
  REZERVAT NUMBER(20,7),
  CC NUMBER(20,7),
  CF NUMBER(20,7),
  CIIES NUMBER(20,7),
  CCPANALA NUMBER(20,7),
  CIIESPANALA NUMBER(20,7),
  PMP NUMBER(20,7),
  VALPMP NUMBER(20,7),
  CFPER NUMBER(20,7),
  NECESAR NUMBER(20,7),
  CFNEXT NUMBER(20,7),
  PLANIF NUMBER(20,7),
  CONSUM NUMBER(20,7),
  CONSUMPREC NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>518F08C7B1C19EF789090755E24F0F28AF12645A</HASHVAL>
  <TEXT>CREATE TABLE NECHIV (
  CODECHIV NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  CODGRUPA NUMBER(20,0),
  GENERIC NUMBER(1,0),
  INDEXLOCAL NUMBER(7,0),
  IND NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NELEMAEROAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>345704E68E76BC10C18163525DC24A993E6D1E74</HASHVAL>
  <TEXT>CREATE TABLE NELEMAEROAUTO (
  CODELEMAEROAUTO NUMBER(20,0) NOT NULL,
  ELEMENT VARCHAR2(200),
  SPOR NUMBER(20,2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NESTJURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AFF3BB1702ABC3364FC9E43FD6624227B56DC1B6</HASHVAL>
  <TEXT>CREATE TABLE NESTJURNAL (
  CODNESTJURNAL NUMBER(20,0) NOT NULL,
  CODCONTD NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NGAMEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C344851B7DB3EA9D8A23CF7AF6B891F0635BA68</HASHVAL>
  <TEXT>CREATE TABLE NGAMEART (
  CODGAMA NUMBER(20,0),
  DENUMIRE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FDD9145CBF0D4EDB4C87BF2B9F2A9FD4DE98A62</HASHVAL>
  <TEXT>CREATE TABLE NGEST (
  CODGEST NUMBER(20,0) NOT NULL,
  DEN_GEST VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  CODCLASA NUMBER(20,0),
  CODACTIVIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  CODGESTIONAR NUMBER(20,0),
  CUSTODIE NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  VERDISPLIVR NUMBER(10,0),
  VERDISPLIVRTRANSF NUMBER(10,0),
  VERDISPLIVRSUBUNIT NUMBER(10,0),
  VERNIR NUMBER(10,0),
  VERNIRTRANSF NUMBER(10,0),
  VERNIRSUBUNIT NUMBER(10,0),
  TIP NUMBER(1,0),
  GMASTER NUMBER(1,0),
  NRSCHIMBURI NUMBER(5,0),
  ORESCHIMB NUMBER(4,2),
  ORASTART DATE,
  COEFCHELTMAT NUMBER(20,7),
  COEFCHELTMAN NUMBER(20,7),
  VEREMULARE NUMBER(10,0),
  CODPOSTRETAIL NUMBER(20,0),
  ANALITICCONT VARCHAR2(10),
  CANTITATE NUMBER(20,7),
  INACTIV NUMBER(1,0),
  VERFACTIES NUMBER(20,0),
  VERCHITANTA NUMBER(20,0),
  CODCAENSEC NUMBER(20,0),
  CODGESTTR NUMBER(20,0),
  ZILETERMEN NUMBER(10,0),
  ZILELUCR NUMBER(5,0),
  CODANTREPOZIT VARCHAR2(20),
  CAPPROD NUMBER(20,7),
  CARNETCMDINT NUMBER(20,0),
  CARNETBC NUMBER(20,0),
  CARNETNP NUMBER(20,0),
  CARNETRP NUMBER(20,0),
  OBS VARCHAR2(300)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NGEST1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B244FC664AA182F43C81C2B84B0F3BD557306514</HASHVAL>
  <TEXT>CREATE TABLE NGEST1 (
  CODGEST1 NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  TIPGEST NUMBER(2,0),
  CHELTUIELI NUMBER(20,0),
  CHELTUIELIAUX NUMBER(20,0),
  CHELTUIELIIND NUMBER(20,0),
  CHELTUIELIADMIN NUMBER(20,0),
  CHELTUIELIDESF NUMBER(20,0),
  VENITURI NUMBER(20,0),
  VENITURIK NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SUPRAFATA NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NGRUPEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E5B500124207DA2A5CF5E154D26DE48A08DE371</HASHVAL>
  <TEXT>CREATE TABLE NGRUPEAUTO (
  CODGRUPEAUTO NUMBER(20,0) NOT NULL,
  GRUPA VARCHAR2(200),
  SPORB NUMBER(20,7),
  SPORRES NUMBER(20,7),
  SPORALTE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6EF30A2F66D90DE147E6E1F27531969542B0DFE</HASHVAL>
  <TEXT>CREATE TABLE NIMOB (
  CODNIMOB NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  DATASTART DATE,
  DATASTOP DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NINSTAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>911A1D3FC57B6F44BC83AD90844E016B819A26CA</HASHVAL>
  <TEXT>CREATE TABLE NINSTAUTO (
  CODINSTAUTO NUMBER(20,0) NOT NULL,
  INSTALATIE VARCHAR2(200),
  PRESTATIE VARCHAR2(200),
  SPOR NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NINTERVENTIIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>537B39EE698483653FA48D3C6E8EE69FCEAF474B</HASHVAL>
  <TEXT>CREATE TABLE NINTERVENTIIAUTO (
  CODINTERVENTIIAUTO NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  PERTIP NUMBER(1,0),
  PERDURATA NUMBER(10,0),
  PERKM NUMBER(10,0),
  ATENTIONAREZILE NUMBER(10,0),
  ATENTIONAREKM NUMBER(10,0),
  TIP NUMBER(1,0),
  SERVICIU NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  ACCIDENTALA NUMBER(1,0),
  CLASA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NINTRASTAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>328127DB31F3489AAEECFCE1406EA141D0EC064A</HASHVAL>
  <TEXT>CREATE TABLE NINTRASTAT (
  CODNINTRASTAT NUMBER(20,0) NOT NULL,
  TIP NUMBER(2,0),
  ALEGERE NUMBER(1,0),
  SIMBOL VARCHAR2(50),
  DENUMIRE VARCHAR2(300),
  OBS VARCHAR2(300),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0EC88716FFB7B82A7BCD985D24DECBD8C9EECF69</HASHVAL>
  <TEXT>CREATE TABLE NIR (
  CODNIR NUMBER(20,0) NOT NULL,
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CODIES NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  NRNIR NUMBER(20,0),
  DATANIR DATE,
  GEST NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPNIR NUMBER(3,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>14B142571B94ABDC2E53542935F713587E0248D5</HASHVAL>
  <TEXT>CREATE TABLE NIR1 (
  CODNIRSTOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DIFERENTA NUMBER(20,6),
  TIPDIF VARCHAR2(1),
  CUIIMPUT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3210CD57B1B7FED892FD35042E56A6EE42BF2180</HASHVAL>
  <TEXT>CREATE TABLE NIRLUNA (
  CODNIRSTOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45D54697AA2427CA1BFA7A06E5A4F64BC7FA5972</HASHVAL>
  <TEXT>CREATE TABLE NIRSER (
  CODNIRSER NUMBER(20,0) NOT NULL,
  CODNIRSTOC NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  REST NUMBER(20,7),
  OBS VARCHAR2(200),
  CANTUM1 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  CODCERTIF NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  TG DATE,
  DIVIZOR NUMBER(10,0),
  BUCATI NUMBER(10,0),
  DATAPROD1 DATE,
  TG1 DATE,
  CODPRODUCATOR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRSERLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>019B25CAA90133FCB5DCE60AB7E7C929F7A864BD</HASHVAL>
  <TEXT>CREATE TABLE NIRSERLUNA (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8BCEEB6F4747D8333A471A541A7E33C52E76DC34</HASHVAL>
  <TEXT>CREATE TABLE NIRSTOC (
  CODNIRSTOC NUMBER(20,0) NOT NULL,
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODLIVR1 NUMBER(20,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DISCLIKISTOC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SUPLNEDED NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  ADMAX NUMBER(20,7),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRSTOC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>92826F8CC700D40D6002A5E6EDE1650ABF572A30</HASHVAL>
  <TEXT>CREATE TABLE NIRSTOC1 (
  CODNIRSTOC NUMBER(20,0) NOT NULL,
  CODNIRSTOCORIG NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  PRETMAT NUMBER(20,7),
  DIRTY NUMBER(1,0),
  DINSTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NIRSTOC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>03771BED517E19A38B1F8A30B7190F067429182A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE NIRSTOC_MAN (
  CODNIRSTOC NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODLIVR1 NUMBER(20,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DISCLIKISTOC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SUPLNEDED NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  ADMAX NUMBER(20,7),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NJUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA3F70699DBF1A13F47752D27CF7902E839DF53F</HASHVAL>
  <TEXT>CREATE TABLE NJUDET (
  CODJUDET NUMBER(20,0) NOT NULL,
  DEN_JUDET VARCHAR2(30),
  SIMBAUTO VARCHAR2(2),
  OBS VARCHAR2(500),
  CODTARA NUMBER(20,0),
  REGCOM NUMBER(3,0),
  CODDRP NUMBER(3,0),
  DENDRP VARCHAR2(15),
  JS NUMBER(3,0),
  ITM NUMBER(3,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NLIMBA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D48D884EF4DEB7CBDFB911D048ABE657EE178F2</HASHVAL>
  <TEXT>CREATE TABLE NLIMBA (
  CODLIMBA NUMBER(20,0) NOT NULL,
  DENLIMBA VARCHAR2(100),
  CODTARA NUMBER(20,0),
  EXTLINK VARCHAR2(2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NLIMCREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8E19E10EA742DA99D144901E850DB8B88A98273</HASHVAL>
  <TEXT>CREATE TABLE NLIMCREDIT (
  CODLIMCREDIT NUMBER(20,0) NOT NULL,
  CODBANCA NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  DATACONTR DATE,
  DATAEXP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  INVESTITIE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NLIMCREDIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B63226B8BA05D6135D98B88215D03D1510867286</HASHVAL>
  <TEXT>CREATE TABLE NLIMCREDIT1 (
  CODLIMCREDIT1 NUMBER(20,0),
  CODLIMCREDIT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  DATA DATE,
  SUMA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3565DB57D196379D6363851118C73397B387E5F3</HASHVAL>
  <TEXT>CREATE TABLE NLOCALIT (
  CODLOCALIT NUMBER(20,0) NOT NULL,
  DEN_LOCALIT VARCHAR2(50),
  TIP VARCHAR2(20),
  CODJUDET NUMBER(20,0),
  OBS VARCHAR2(300),
  CODTARA NUMBER(20,0),
  DENSUP VARCHAR2(50),
  SIRUTA NUMBER(10,0),
  CODZONA NUMBER(20,0),
  LATITUDINE NUMBER(20,7),
  LONGITUDINE NUMBER(20,7),
  CODPOSTAL VARCHAR2(10)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NLOCATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54591330F5FE7D84547B5B5049D1C824B41FA787</HASHVAL>
  <TEXT>CREATE TABLE NLOCATII (
  CODLOCATIE NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  INDEXLOCAL NUMBER(10,0),
  NRCELULE NUMBER(10,0),
  DESCRIERE VARCHAR2(200),
  CODEXTERN VARCHAR2(20),
  TIPLOCATIE NUMBER(1,0),
  CODLOCFIXA NUMBER(20,0),
  CODVECINLEFT NUMBER(20,0),
  CODVECINRIGHT NUMBER(20,0),
  COORDX NUMBER(10,0),
  INACTIV NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMAKETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6CA555D66FEFAD3933223FB54A0D5F15A9A00E8</HASHVAL>
  <TEXT>CREATE TABLE NMAKETE (
  CODMAKETA NUMBER(20,0) NOT NULL,
  ESTELISTA NUMBER(1,0),
  DENMAKETA VARCHAR2(30),
  DISPLAY VARCHAR2(75),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMARCIAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02A067288D4D6C3453EF7F85C37E4AB93A5CEC5C</HASHVAL>
  <TEXT>CREATE TABLE NMARCIAUTO (
  CODMARCIAUTO NUMBER(20,0) NOT NULL,
  MARCA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMESERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F3AED4311801DC437E7B87C37ACE606F96048BE</HASHVAL>
  <TEXT>CREATE TABLE NMESERII (
  CODMESERIE NUMBER(20,0) NOT NULL,
  DEN_MESERIE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2D2BBF9CD1CA60A89559126D8C3CB666B879FE2</HASHVAL>
  <TEXT>CREATE TABLE NMODELEAUTO (
  CODMODELEAUTO NUMBER(20,0) NOT NULL,
  MODEL VARCHAR2(50),
  CODMARCIAUTO NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMONEDE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC1CB4B886F1A1FD7BDC4254F8A6B605D6414A17</HASHVAL>
  <TEXT>CREATE TABLE NMONEDE (
  CODMONEDA NUMBER(20,0) NOT NULL,
  DEN_MONEDA VARCHAR2(30),
  SIMBOL VARCHAR2(5),
  SDENUMIRE VARCHAR2(30),
  SSIMBOL VARCHAR2(5),
  ZECIMALE NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMONEDE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F61377C9CB7678F5D132FAB2A8D3F5C56F4D2CC5</HASHVAL>
  <TEXT>CREATE TABLE NMONEDE1 (
  CODMONEDA1 NUMBER(20,0) NOT NULL,
  CODMONEDA NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  DATA DATE,
  VALOARE NUMBER(23,6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NMVS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D6FE86006A1A6B1D187F56CAE4BC6173AEFB646</HASHVAL>
  <TEXT>CREATE TABLE NMVS (
  USERID NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATAVERIF TIMESTAMP(6),
  GTIN VARCHAR2(100),
  DATAEXP VARCHAR2(100),
  LOT VARCHAR2(100),
  SN VARCHAR2(100),
  SKEMETYPE VARCHAR2(100),
  MESAJ VARCHAR2(1000),
  CODMESAJ VARCHAR2(100),
  STATUS VARCHAR2(100),
  MOTIV VARCHAR2(100),
  CODFUNCTIE VARCHAR2(100),
  GLN VARCHAR2(50),
  CODNMVS NUMBER(20,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NODECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>71392FFD79D218E8869A78AAADCA863D14DD5382</HASHVAL>
  <TEXT>CREATE TABLE NODECHIV (
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NODECHIV1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8F618A08D940D7A8EFF0B06AC1DD7AD9FEB8400</HASHVAL>
  <TEXT>CREATE TABLE NODECHIV1 (
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PARITATE NUMBER(20,7),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43BDB8E7421AA8C36D2F4442FE2DF9D3477C3B2E</HASHVAL>
  <TEXT>CREATE TABLE NOPER (
  CODOP NUMBER(20,0) NOT NULL,
  CODEXTERN VARCHAR2(15),
  DENUMIRE VARCHAR2(60),
  CLASAOP NUMBER(20,0),
  TIP NUMBER(1,0),
  ACTIV NUMBER(1,0),
  CODSERVICIU NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  LOCMUNCA NUMBER(20,0),
  MARCAAUTO NUMBER(20,0),
  MODELAUTO NUMBER(20,0),
  FACTURABIL NUMBER(2,0),
  DURATA NUMBER(20,0),
  CODTIPLUCRARE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODPRESTATIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOPER1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6DA5763FADFC47E0783AA6CA1538478CAEFC6FB</HASHVAL>
  <TEXT>CREATE TABLE NOPER1 (
  CODOP1 NUMBER(20,0) NOT NULL,
  CODOP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(10,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NORMEMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>084FC654D5A1AA32A975DFA02CF0FAB8DFE31AC9</HASHVAL>
  <TEXT>CREATE TABLE NORMEMAT (
  CODNORMEMAT NUMBER(20,0) NOT NULL,
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CANTUM1 NUMBER(20,7),
  CODMAT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOTECONTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1D54919A06987AAFD2C5E8B685729F4B03BBB27</HASHVAL>
  <TEXT>CREATE TABLE NOTECONTA (
  CODNOTA NUMBER(2,0),
  DENUMIRE VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83E2374801ACD544660D29342D62157CD9F4346D</HASHVAL>
  <TEXT>CREATE TABLE NOTECREDIT (
  CODNCREDIT NUMBER(20,0) NOT NULL,
  CODCONTRACT2 NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  CODCONTV NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  DATAFACT DATE,
  TIPARTICOL NUMBER(1,0),
  OBS VARCHAR2(300),
  CODCONTRACT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  VOLUMPEARTICOLE NUMBER(1,0),
  CODCONTZ NUMBER(20,0),
  PRETBRUTC NUMBER(1,0),
  PRETBRUTV NUMBER(1,0),
  CODCARNET NUMBER(20,0),
  TRIMESTRIALA NUMBER(1,0),
  CORECTIE NUMBER(1,0),
  CODNCCORECTIE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(3),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  PREVIZIONARE NUMBER(1,0),
  IESIRIPEVOLUM NUMBER(1,0),
  CURS NUMBER(20,7),
  INCHISA NUMBER(20,0),
  VALORIGTER NUMBER(1,0),
  CODANALIZA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOTECREDIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FC5DF3E121B6EEF6898833D464AD196C7775C7D</HASHVAL>
  <TEXT>CREATE TABLE NOTECREDIT1 (
  CODNCREDIT1 NUMBER(20,0) NOT NULL,
  CODNCREDIT NUMBER(20,0),
  TIPOPER VARCHAR2(1),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  PREVIZIONAT NUMBER(20,7),
  CODDISCOUNT NUMBER(20,0),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  TIP NUMBER(1,0),
  PROCTVA NUMBER(6,3),
  OBSNAV VARCHAR2(450),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOTECREDITFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27D4A60683B419293EDAADE91B86B21B1195C35C</HASHVAL>
  <TEXT>CREATE TABLE NOTECREDITFACT (
  CODNCFACT NUMBER(20,0) NOT NULL,
  CODNCREDIT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  VALT NUMBER(20,7),
  CODDOC1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NOVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C847084101D8F32725E696C2336820E59D484D1</HASHVAL>
  <TEXT>CREATE TABLE NOVA (
  CODOBIECT NUMBER(20,0),
  PRETACHIZ NUMBER
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARC0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90EA2A0B76CFA8ADA76120EC5DDC7493270A720C</HASHVAL>
  <TEXT>CREATE TABLE NPARC0 (
  CODNPARC0 NUMBER(20,0) NOT NULL,
  CODNPARCAUT NUMBER(20,0),
  DATABORD DATE,
  KMBORD NUMBER(10,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  CODPERS NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  CODCMD NUMBER(20,0),
  COMB NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D0CE3D33B1CDB5C2BF197B3381130AD4AC00D42</HASHVAL>
  <TEXT>CREATE TABLE NPARC1 (
  CODNPARC1 NUMBER(20,0) NOT NULL,
  INDEXLOCAL NUMBER(10,0),
  ART NUMBER(20,0),
  CANT NUMBER(10,0),
  POZITIE NUMBER(1,0),
  BORDINSTAL NUMBER(10,0),
  ATENTIE NUMBER(10,0),
  COD NUMBER(20,0),
  CODPART NUMBER(20,0),
  MONTAT NUMBER(1,0),
  ANOTIMP NUMBER(1,0),
  ADANCIME NUMBER(2,0),
  LATIME NUMBER(4,0),
  INALTIME NUMBER(3,0),
  DIAMETRU NUMBER(3,0),
  GAMA NUMBER(1,0),
  RUNFLAT NUMBER(1,0),
  SUV NUMBER(1,0),
  OFFROAD NUMBER(1,0),
  XL NUMBER(1,0),
  MS NUMBER(1,0),
  OBS VARCHAR2(500),
  SERIA VARCHAR2(75),
  DOT NUMBER(4,0),
  BORDDEM NUMBER(10,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARC2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A68096C24D6173C35902D9F6BE95334FE4A908F4</HASHVAL>
  <TEXT>CREATE TABLE NPARC2 (
  CODNPARC2 NUMBER(20,0) NOT NULL,
  INDEXLOCAL NUMBER(20,0),
  DOC NUMBER(20,0),
  SN VARCHAR2(20),
  ELIBERAT DATE,
  EXPIRA DATE,
  ATENTIE NUMBER(10,0),
  COD NUMBER(20,0),
  OBS VARCHAR2(500),
  VALOARE NUMBER(20,7),
  CODINTR1 NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARC3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F037440344C8D2E93297383F5D6CAE2F5FBBD5F</HASHVAL>
  <TEXT>CREATE TABLE NPARC3 (
  CODNPARC3 NUMBER(20,0) NOT NULL,
  COD NUMBER(20,0),
  INTERVENTIE NUMBER(20,0),
  DATAU DATE,
  KMU NUMBER(10,0),
  DATAV DATE,
  KMV NUMBER(10,0),
  DATAA DATE,
  KMA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  CODCMD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B423C6AB7C11D4A3D47C980F7237372DBBFBFA31</HASHVAL>
  <TEXT>CREATE TABLE NPARCAUT (
  CODNPARCAUT NUMBER(20,0) NOT NULL,
  CODART NUMBER(20,0),
  NRINV NUMBER(20,0),
  NRINREG VARCHAR2(20),
  SOFER NUMBER(20,0),
  KMPORNIRE NUMBER(20,0),
  TIP NUMBER(1,0),
  DATAINREG DATE,
  MARCA NUMBER(20,0),
  MODEL NUMBER(20,0),
  ANF NUMBER(4,0),
  SERIEC VARCHAR2(20),
  CULOARE NUMBER(20,0),
  LUNG NUMBER(10,0),
  LAT NUMBER(10,0),
  INALT NUMBER(10,0),
  TIPMOTOR VARCHAR2(20),
  SERIEM VARCHAR2(20),
  MOTOR NUMBER(20,0),
  CILINDREE NUMBER(10,0),
  PUTERE NUMBER(10,0),
  CMM NUMBER(10,2),
  CMU NUMBER(10,2),
  CME NUMBER(10,2),
  TIPINCARC NUMBER(1,0),
  GREUTATE NUMBER(10,0),
  MASAM NUMBER(10,0),
  MASAU NUMBER(10,0),
  MASAURDF NUMBER(10,0),
  MASAURFDF NUMBER(10,0),
  LOCT NUMBER(4,0),
  LOCF NUMBER(4,0),
  LOCS NUMBER(4,0),
  LOCP NUMBER(4,0),
  ANVRECOMF VARCHAR2(15),
  ANVRECOMS VARCHAR2(15),
  ANVOPT1F VARCHAR2(15),
  ANVOPT1S VARCHAR2(15),
  ANVOPT2F VARCHAR2(15),
  ANVOPT2S VARCHAR2(15),
  KG NUMBER(10,2),
  KGR NUMBER(10,2),
  SARCINA NUMBER(20,0),
  CODPUTERE NUMBER(20,0),
  GRUPAUTO NUMBER(20,0),
  TIPREM NUMBER(20,0),
  INSTSP NUMBER(20,0),
  AER NUMBER(20,0),
  REZERVOR NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  CULOAREC VARCHAR2(50),
  SURSAE VARCHAR2(50),
  EXTERN NUMBER(1,0),
  PARTENER NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODGEST NUMBER(20,0),
  PARTLEAS NUMBER(20,0),
  NRCONTR VARCHAR2(50),
  MONEDA NUMBER(20,0),
  RATALEAS NUMBER(10,2),
  RATARCA NUMBER(10,2),
  RATACASCO NUMBER(10,2),
  DATAACHIZ DATE,
  DATAENDLEAS DATE,
  PARTUTILIZ NUMBER(20,0),
  PERSUTILIZ NUMBER(20,0),
  OBS VARCHAR2(200),
  TIPULEI VARCHAR2(50),
  TIPVEHICUL NUMBER(1,0),
  CODDEALER NUMBER(20,0),
  LIMITAKM NUMBER(8,0),
  DOTARI VARCHAR2(500),
  CODRADIO VARCHAR2(15),
  TRANSMISIE NUMBER(1,0),
  TRACTIUNE NUMBER(1,0),
  GPS NUMBER(1,0),
  GPL NUMBER(1,0),
  FRIGO NUMBER(1,0),
  CODPARTGPS NUMBER(20,0),
  CODEXTERN VARCHAR2(100),
  CODARTCOMB NUMBER(20,0),
  CONSSTATH NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARCCOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D19DE502F6FB818908C49569ED2D59667176DE0D</HASHVAL>
  <TEXT>CREATE TABLE NPARCCOM (
  CODNPARCCOM NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  KMBORD NUMBER(10,0),
  TIPCOMSA NUMBER(1,0),
  DATAINCHIDERII DATE,
  INMATRROM NUMBER(1,0),
  INSPECTIE NUMBER(1,0),
  PIESECLIENT NUMBER(1,0),
  PROBADRUM NUMBER(1,0),
  SPALARE NUMBER(1,0),
  DZ NUMBER(1,0),
  NIVREZERVOR NUMBER(2,0),
  NRDOSARDAUNE VARCHAR2(30),
  NRAUTREP VARCHAR2(30),
  DATAAUTREP DATE,
  KMGARANTIE NUMBER(6,0),
  DATAGARANTIE DATE,
  TIPCOMANDA VARCHAR2(20),
  ASIGURATOR NUMBER(20,0),
  DISTANTA NUMBER(5,0),
  ADRESASEDIU VARCHAR2(30),
  OBS VARCHAR2(1500),
  RECOMANDARI VARCHAR2(500),
  NRORE NUMBER(20,7),
  CATEGPRET NUMBER(5,0),
  KMBORDE NUMBER(10,0),
  IDRAR NUMBER(20,0),
  ANULATRAR NUMBER(5,0),
  FINALIZATRAR NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARCG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95A763B65CFF10EE956DF55590B486F1A65016D9</HASHVAL>
  <TEXT>CREATE TABLE NPARCG (
  CODNPARCG NUMBER(20,0) NOT NULL,
  CODNPARCAUT NUMBER(20,0),
  CODGESTINI NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCMD NUMBER(20,0),
  STATUS NUMBER(1,0),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AEC1CA105432014681A7F5252FBB116CFA3612A</HASHVAL>
  <TEXT>CREATE TABLE NPART (
  CODPART NUMBER(20,0) NOT NULL,
  DEN_PART VARCHAR2(100),
  REGCOM VARCHAR2(20),
  CODEXTERN VARCHAR2(50),
  CODMONEDA NUMBER(20,0),
  AUTORIZATIE VARCHAR2(50),
  CODINTERN VARCHAR2(50),
  CODCLASA NUMBER(20,0),
  CODCATEGPRET NUMBER(20,0),
  TIPPART NUMBER(1,0),
  SCADENTAC NUMBER(5,0),
  SCADENTAV NUMBER(5,0),
  DISCOUNT NUMBER(6,3),
  CODCATEGDISC NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPPARTENER NUMBER(2,0),
  DATAADAUGARII DATE,
  OBS VARCHAR2(300),
  POZA BLOB,
  PERSOANAFIZICA NUMBER(1,0),
  VERFACT NUMBER(10,0),
  VERDISPLIVR NUMBER(10,0),
  COLDISCOUNT NUMBER(1,0),
  INFOBLOCAT VARCHAR2(100),
  EXPIRAREAUTORIZ DATE,
  CODSTATISTICBNR VARCHAR2(20),
  MUSAICOLET NUMBER(1,0),
  STRATEGIC NUMBER(1,0),
  CIFRAAFACERI NUMBER(20,7),
  DOMENIUACTIV VARCHAR2(200),
  NRANGAJATI NUMBER(20,0),
  SURSALEAD NUMBER(20,0),
  LEAD NUMBER(1,0),
  TVALAINCASARE NUMBER(1,0),
  MODAPLICPROCDISC NUMBER(1,0),
  PROCCURSTRANSF NUMBER(20,7),
  VERPROFORMA NUMBER(10,0),
  FIDELIZARE NUMBER(1,0),
  MAJORARI NUMBER(20,7),
  TIPBLOCAJ NUMBER(1,0),
  POPRIRE_ANAF NUMBER(1,0),
  CODRESPONSABIL NUMBER(20,0),
  CODDOMENIUACT NUMBER(20,0),
  DOCDEFONORCOM NUMBER(1,0),
  MODPROMOFACTCOM NUMBER(1,0),
  VALIDAREPRETOFERTA NUMBER(1,0),
  IESCUCOMANDA NUMBER(1,0),
  VERFACTAVIZ NUMBER(10,0),
  VALMINCMD NUMBER(20,7),
  CANTMINCMD NUMBER(20,7),
  ZIAPROVIZ NUMBER(10,0),
  PERAPROVIZ NUMBER(10,0),
  CODCONTRACTCADRU NUMBER(20,0),
  DATANASTERE DATE,
  SPLITTVA NUMBER(1,0),
  GDPR NUMBER(1,0),
  ZILELIVRARE NUMBER(5,0),
  SAFT_EXPORT NUMBER(1,0),
  FARAPENALIZARI NUMBER(1,0),
  INACTIV NUMBER(1,0),
  PREOFEFURNVAR NUMBER(1,0),
  TIPANALIZAPRET NUMBER(1,0),
  VERAVIZIES NUMBER(10,0),
  EF_ITEM NUMBER(1,0),
  EF_PARTY NUMBER(1,0),
  EF_IMPARTGEN NUMBER(1,0),
  EF_CUSTOM NUMBER(20,0),
  EF_TAXE NUMBER(1,0),
  CATEGTARIF NUMBER(2,0),
  EF_PROIECT VARCHAR2(20),
  ZILEACHIZ NUMBER(5,0),
  CULOARE NUMBER(8,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39C396EF8369CBC398E4766D44137A04883024F7</HASHVAL>
  <TEXT>CREATE TABLE NPART1 (
  CODPART1 NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CREDITCLIENT NUMBER(18,2),
  VOLUMTRANZC NUMBER(18,2),
  CREDITFURN NUMBER(18,2),
  VOLUMTRANZF NUMBER(16,2),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SCADENTAV NUMBER(5,0),
  SCADENTAC NUMBER(5,0),
  DISCOUNT NUMBER(6,3),
  CASSBAZAMIN NUMBER(1,0),
  SIMBOLCASS VARCHAR2(2),
  GDPR NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPART1CRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D60C4A0F65F52F34431498CFE9C4EF98A22BC25D</HASHVAL>
  <TEXT>CREATE TABLE NPART1CRM (
  CODPART1CRM NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CIFRAAFACERI NUMBER(20,7),
  NRANGAJATI NUMBER(20,0),
  LEAD NUMBER(1,0),
  SURSALEAD NUMBER(20,0),
  CODRESPONSABIL NUMBER(20,0),
  STARE NUMBER(2,0),
  MODPLATA NUMBER(20,0),
  CIP NUMBER(1,0),
  DATASTART DATE,
  DATAEND DATE,
  PROFIT NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPART1X</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F97299ED0E125445C726AFB5C973B2631CD57B8</HASHVAL>
  <TEXT>CREATE TABLE NPART1X (
  CODPART1 NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CREDITCLIENT NUMBER(18,2),
  VOLUMTRANZC NUMBER(18,2),
  CREDITFURN NUMBER(18,2),
  VOLUMTRANZF NUMBER(16,2),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC7810BBB25C915C0926B965FD683DFDD9FB3229</HASHVAL>
  <TEXT>CREATE TABLE NPARTACTIVIT (
  CODPARTACTIVIT NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODACTIVIT NUMBER(20,0),
  DIM NUMBER(10,2),
  CODPART1CRM NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>48A7D21F28807CE6EA8C447594B683428442705A</HASHVAL>
  <TEXT>CREATE TABLE NPARTB (
  CODPARTB NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODBANK NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  CONTBANCA VARCHAR2(30),
  SUCURSALA VARCHAR2(20),
  CODSWIFT VARCHAR2(30),
  CODMONEDA NUMBER(20,0),
  TIPCOMISION NUMBER(1,0),
  OBS VARCHAR2(100),
  CONTTVA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTCODFISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BADF4A2143C3104A3949122AB9587666B45A8F1B</HASHVAL>
  <TEXT>CREATE TABLE NPARTCODFISC (
  COD_CODFISCAL NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  PRINCIPAL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTCONCURENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B41AF8852BC4A596FBD8DB24438781ED61064160</HASHVAL>
  <TEXT>CREATE TABLE NPARTCONCURENTI (
  CODPARTCONCURENT NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODCONCURENT NUMBER(20,0),
  CODPART1CRM NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81C6E68C1F12EEB131C9B4F957316326AEFB6030</HASHVAL>
  <TEXT>CREATE TABLE NPARTDISC (
  CODPARTDISC NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODCATEGDISC NUMBER(20,0),
  INDEXLOCAL NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTDISCRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DCFEEA5BC2C4B0E68E6BC2E1351F8BDE9C2AADC9</HASHVAL>
  <TEXT>CREATE TABLE NPARTDISCRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODCATEGDISC NUMBER(20,0),
  INDEXLOCAL NUMBER(4,0),
  CODPARTDISC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTDOMACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E4EF159B30FC217661096EDEE9CF56DA175DCB9</HASHVAL>
  <TEXT>CREATE TABLE NPARTDOMACT (
  CODPARTDOMACT NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODDOMENIUACT NUMBER(20,0),
  CODPART1CRM NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTLSTCLASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31EC22345624E9255DFDF2386C921156ED8F7A24</HASHVAL>
  <TEXT>CREATE TABLE NPARTLSTCLASE (
  CODNPARTLSTCLASE NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODCLASA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4C64679DF5983C4E4856F646B295F3BD0422E81</HASHVAL>
  <TEXT>CREATE TABLE NPARTRETAIL (
  CODPARTRETAIL NUMBER(20,0),
  CODPART NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  REGCOM VARCHAR2(20),
  OBS VARCHAR2(300),
  CODEXTERN VARCHAR2(50),
  CODINTERN VARCHAR2(50),
  TIPPART NUMBER(1,0),
  COLDISCOUNT NUMBER(1,0),
  DATACREARE TIMESTAMP(6),
  USERID NUMBER(20,0),
  TIPMODIF VARCHAR2(1),
  CODCLASA NUMBER(20,0),
  FIDELIZARE NUMBER(1,0),
  DATANASTERE DATE,
  BLOCAT NUMBER(1,0),
  INFOBLOCAT VARCHAR2(100),
  CODCATEGPRET NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5A2E5173CB13692BAB059EAC4B20713817AB70A</HASHVAL>
  <TEXT>CREATE TABLE NPARTSOLDLUNA (
  CODPARTSOLDLUNA NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  SOLD_IFRS NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTSOLDLUNASUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA617BDEC9AF889DB061378B670859249787461E</HASHVAL>
  <TEXT>CREATE TABLE NPARTSOLDLUNASUB (
  CODPARTSOLDLUNASUB NUMBER(20,0),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  SOLD_IFRS NUMBER(20,3),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B20C6142AFFB86A690C4D42DF045E428DC3D1EAB</HASHVAL>
  <TEXT>CREATE TABLE NPARTSUBUNIT (
  CODPARTSUBUNIT NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  ZIAPROVIZ NUMBER(10,0),
  PERAPROVIZ NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>942ECA6FCD34529729A36F838E3A3970DFAC3B4D</HASHVAL>
  <TEXT>CREATE TABLE NPARTTR (
  CODPARTTR NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  ACTIV NUMBER(1,0),
  DATADOC DATE,
  CODPERS NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  OBS VARCHAR2(250),
  PERMIS VARCHAR2(20),
  NRPASS VARCHAR2(12),
  CODTARA VARCHAR2(3),
  ADRESA VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  TELEFON VARCHAR2(20),
  EMAIL VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTTR_LNK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10C9A26BDB8F1D947808454178CB50366FA0F288</HASHVAL>
  <TEXT>CREATE TABLE NPARTTR_LNK (
  CODPARTTRLNK NUMBER(20,0),
  CODPARTTR NUMBER(20,0),
  CODPART NUMBER(20,0),
  SEDII NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPARTTR_LNK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11393E443C55EE09FE198C3322ECF494DF37DAAF</HASHVAL>
  <TEXT>CREATE TABLE NPARTTR_LNK1 (
  CODPARTTRLNK1 NUMBER(20,0),
  CODPARTTRLNK NUMBER(20,0),
  CODAGENDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B30C49E00FA98124C66B45ABD87CEA0002F471D</HASHVAL>
  <TEXT>CREATE TABLE NPERS (
  CODPERS NUMBER(20,0) NOT NULL,
  MARCA NUMBER(20,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  CNP VARCHAR2(30),
  BISERIA VARCHAR2(3),
  BINR VARCHAR2(8),
  LOCNASTERE NUMBER(20,0),
  ADRESA VARCHAR2(200),
  PRENUMET VARCHAR2(100),
  PRENUMEM VARCHAR2(100),
  LOCALITN NUMBER(20,0),
  DATAN DATE,
  SCIVILA NUMBER(1,0),
  SMILITAR NUMBER(1,0),
  ACTIV NUMBER(1,0),
  STRAINATATE NUMBER(1,0),
  AGENT NUMBER(1,0),
  DELEGAT NUMBER(1,0),
  AGENDA NUMBER(20,0),
  BIELIBERATDE VARCHAR2(100),
  LADATADE DATE,
  TARAN NUMBER(20,0),
  CETATENIE NUMBER(1,0),
  POZA BLOB,
  LOGONNAME NUMBER(20,0),
  ACCMAS VARCHAR2(100),
  COMISION NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODLOC NUMBER(20,0),
  DATAPLECARII DATE,
  DATAANGAJARII DATE,
  OBS VARCHAR2(250),
  OREPEZI NUMBER(4,2),
  CODCENTRU NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  IBAN VARCHAR2(30),
  CODBANK NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6960110B5A0045ADA6E285DCE540CBA8293E4B9</HASHVAL>
  <TEXT>CREATE TABLE NPERS1 (
  CODPERS1 NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  CODIOPERS NUMBER(20,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  CODFORMATIE NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0),
  CODMESERIE NUMBER(20,0),
  SCHIMB NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCONTACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CA84A52F9FA71C7822110DA79F0657D08861B28</HASHVAL>
  <TEXT>CREATE TABLE NPERSCONTACT (
  CODPERSC NUMBER(20,0) NOT NULL,
  NUME VARCHAR2(20),
  PRENUME VARCHAR2(40),
  TELEFON VARCHAR2(40),
  EMAIL VARCHAR2(100),
  FUNCTIE VARCHAR2(100),
  DATANASTERE DATE,
  RZONA NUMBER(1,0),
  ID NUMBER(10,0),
  TIP NUMBER(1,0),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  SERIEBI VARCHAR2(3),
  NRBI VARCHAR2(10),
  ELIBERATBI VARCHAR2(100),
  DATABI DATE,
  CNP VARCHAR2(30),
  OBS VARCHAR2(240),
  CODLOCATIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E1501BFB39F16AB7EEC7521914468D518B1945C</HASHVAL>
  <TEXT>CREATE TABLE NPERSCURS (
  CODNPERSCURS NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  STARE NUMBER(1,0),
  DATA DATE,
  NOTA NUMBER(10,0),
  DATAPLAN DATE,
  ORE_REALIZ NUMBER(10,0),
  TIPFORMARE NUMBER(1,0),
  NIVELFORMARE NUMBER(1,0),
  CODOBIECTIV NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCVLOCM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>50A6EB7517CFA7B32A0069808B1999B9682994D8</HASHVAL>
  <TEXT>CREATE TABLE NPERSCVLOCM (
  CODPERSCVLOCM NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DELA DATE,
  PANALA DATE,
  LOCMUNCA VARCHAR2(30),
  CODFISCAL VARCHAR2(75)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCVPAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85AFCB8FE7048201606EA1227E0D4CFA626A89BE</HASHVAL>
  <TEXT>CREATE TABLE NPERSCVPAS (
  CODPERSCVPAS NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  PASIUNE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCVSCOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A45F784C2DAD128473211138100C18865F5FFC08</HASHVAL>
  <TEXT>CREATE TABLE NPERSCVSCOL (
  CODPERSCVSCOL NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DELA DATE,
  PANALA DATE,
  SCOALA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSCVSKIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA3A2680D63A917C6B43D322867C22A8B237EF87</HASHVAL>
  <TEXT>CREATE TABLE NPERSCVSKIL (
  CODPERSCVSKIL NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SKILL VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSSOLDLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>872BF53F17831382D5305527D0D1D70B8FC55DF7</HASHVAL>
  <TEXT>CREATE TABLE NPERSSOLDLUNA (
  CODPERSSOLDLUNA NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPERSSOLDLUNASUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>853CC0889789C5FC1AC161C2BDA08529A84047F2</HASHVAL>
  <TEXT>CREATE TABLE NPERSSOLDLUNASUB (
  CODPERSSOLDLUNASUB NUMBER(20,0),
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NPLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2BBE0C9D0257165A31E4EF3D6F9245B0EBED60E</HASHVAL>
  <TEXT>CREATE TABLE NPLINK (
  CODNIRSTOC NUMBER(20,0),
  CODLIVR1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NRBONLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A866F58945B67B6C25634D336679E7864C6AEA4</HASHVAL>
  <TEXT>CREATE TABLE NRBONLOCK (
  CODCASAMARCAT NUMBER(20,0),
  USERID NUMBER(20,0),
  USEDNO NUMBER(20,0),
  CONNINDEX NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NRCMDRESTLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F84887A305D6F786731AA2C62CC13D192818F904</HASHVAL>
  <TEXT>CREATE TABLE NRCMDRESTLOCK (
  CODMASA NUMBER(20,0),
  DATA DATE,
  USERID NUMBER(20,0),
  USEDNR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NREMAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB0CD4F857EEB77F402DA1DC8AB60077EEEF82C3</HASHVAL>
  <TEXT>CREATE TABLE NREMAUTO (
  CODREMAUTO NUMBER(20,0) NOT NULL,
  TIPURIREMORCI VARCHAR2(200),
  SPOR_150_1 NUMBER(10,2),
  SPOR_150_2 NUMBER(10,2),
  SPOR150_215_1 NUMBER(10,2),
  SPOR150_215_2 NUMBER(10,2),
  SPOR215_1 NUMBER(10,2),
  SPOR215_2 NUMBER(10,2)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NRINVLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36CAA98A76644766BB2D5A2FBEF9D9366794EAFD</HASHVAL>
  <TEXT>CREATE TABLE NRINVLOCK (
  CODINVLOCK NUMBER(20,0) NOT NULL,
  TIP VARCHAR2(2),
  USEDNO NUMBER(20,0),
  USERID NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSCADTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>268249A57B1DBAC22CCF321E7DC42EA3DD6520DD</HASHVAL>
  <TEXT>CREATE TABLE NSCADTL (
  CODSCADTL NUMBER(20,0) NOT NULL,
  CODBANCA NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  DATACONTR DATE,
  DATAEXP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSCADTL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA41F8646986E13E59CF0B909C615A4C6D29324C</HASHVAL>
  <TEXT>CREATE TABLE NSCADTL1 (
  CODSCADTL1 NUMBER(20,0) NOT NULL,
  CODSCADTL NUMBER(20,0),
  DATASCAD DATE,
  RATA NUMBER(20,7),
  DOBANDA NUMBER(20,7),
  TOTAL NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSEDIIPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>114D71ECD7DF47C1E68D93264C440135831B7EAC</HASHVAL>
  <TEXT>CREATE TABLE NSEDIIPARTRETAIL (
  CODSEDIU NUMBER(20,0) NOT NULL,
  CODPARTRETAIL NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  DENLOCALIT VARCHAR2(50),
  CODJUDET NUMBER(20,0),
  CODTARA NUMBER(20,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(350),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  SECTOR NUMBER(2,0),
  CODPOSTAL VARCHAR2(10),
  SEDIUSOCIAL NUMBER(1,0),
  CODAGENDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D59633470E1CA7296ADDABC22F0DC26A73ECDAED</HASHVAL>
  <TEXT>CREATE TABLE NSERII (
  CODSERIE NUMBER(20,0) NOT NULL,
  SERIE VARCHAR2(75),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODPARINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F825B0D0183D7C69CA6AD64D0575EEAD4B79671A</HASHVAL>
  <TEXT>CREATE TABLE NSERTAR (
  CODSERTAR NUMBER(20,0) NOT NULL,
  CODEMITENT NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  TIP NUMBER(1,0),
  DECONT NUMBER(1,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALOARE NUMBER(20,7),
  DATADECONT DATE,
  DEPUS NUMBER(1,0),
  DATACREARE DATE,
  USERID NUMBER(20,0),
  OBS VARCHAR2(500),
  DATAOBLIG DATE,
  BANCA NUMBER(20,0),
  MONEDA NUMBER(20,0),
  NRI VARCHAR2(30),
  INDEXLOCAL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSERTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>419D9CA965A5A438F4699C4B108AF044F4B3F8AB</HASHVAL>
  <TEXT>CREATE TABLE NSERTAR1 (
  CODSERTAR1 NUMBER(20,0) NOT NULL,
  CODSERTAR NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CODGENERAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BFE783A68693BD3782C8EEF318A3DBFD0845F49</HASHVAL>
  <TEXT>CREATE TABLE NSUBUNIT (
  CODSUBUNIT NUMBER(20,0) NOT NULL,
  DEN_SUBUNIT VARCHAR2(100),
  CIF VARCHAR2(30),
  REGCOM VARCHAR2(20),
  CODBANKCONT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  SATELITWM NUMBER(1,0),
  ANPORNIRE NUMBER(5,0),
  LUNAPORNIRE NUMBER(2,0),
  NUMEPRESC VARCHAR2(8),
  NOECONOMICACTIV NUMBER(1,0),
  CODSIUI VARCHAR2(15),
  CODCASA NUMBER(20,0),
  CAPITAL_SOCIAL NUMBER(20,2),
  CODBANKCONTTREZ NUMBER(20,0),
  EFACT NUMBER(1,0),
  TIPUNITJURIDICA NUMBER(1,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NSUBUNIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>290B77C8F523B695CD7160C1A3AF8D73B6612264</HASHVAL>
  <TEXT>CREATE TABLE NSUBUNIT1 (
  CODSUBUNIT1 NUMBER(20,0) NOT NULL,
  CODSUBUNIT NUMBER(20,0),
  CODIOFILIAL NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  TVALAINCASARE NUMBER(1,0),
  CAEN VARCHAR2(5),
  CODTVA NUMBER(20,0),
  ISFIRMA NUMBER(1,0),
  GRDECLARATIE NUMBER(3,0),
  MODEDITAREJURNAL NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  PRELCANTBCAR NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A8AFD55043C0BF7279983FBE8903825F2E5E6E34</HASHVAL>
  <TEXT>CREATE TABLE NTARI (
  CODTARA NUMBER(20,0) NOT NULL,
  DEN_TARA VARCHAR2(30),
  SIMBAUTO VARCHAR2(3),
  CODMONEDA NUMBER(20,0),
  OBS VARCHAR2(300),
  STATCOMUNITAR NUMBER(1,0),
  CODLIMBA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTAXE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>218503E3AF64F7651E8952B1CA067BABA8C8A5F1</HASHVAL>
  <TEXT>CREATE TABLE NTAXE (
  CODTAXA NUMBER(20,0) NOT NULL,
  DEN_TAXA VARCHAR2(30),
  CENTRALIZAT NUMBER(1,0),
  TIPPART NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTAXE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0304D271081FA74F40B1B2455AB2FB7134FBA9FF</HASHVAL>
  <TEXT>CREATE TABLE NTAXE1 (
  CODTAXA1 NUMBER(20,0) NOT NULL,
  CODTAXA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  LACEAPLIC NUMBER(1,0),
  CODCONT NUMBER(20,0),
  CODCONTCHELT NUMBER(20,0),
  ORICARETIP NUMBER(1,0),
  CODIOARTEXCL NUMBER(20,0),
  EXCLUSACCIZE NUMBER(1,0),
  EXCLUSEXPORT NUMBER(1,0),
  JACHIZ NUMBER(1,0),
  JVANZ NUMBER(1,0),
  CUMJACHIZ NUMBER(1,0),
  CUMJVANZ NUMBER(1,0),
  BAZAMAX NUMBER(20,7),
  BAZAMIN NUMBER(20,7),
  CODSERVFACT NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  STOPAJ NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SERVICIUMONETAR NUMBER(20,0),
  PROCDIMINUAREB NUMBER(12,2),
  ROTVALOARE NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  BAZAMED NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTIPSEDII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>561E4369D7A2E4005AA6BFBE590D850B51CD0105</HASHVAL>
  <TEXT>CREATE TABLE NTIPSEDII (
  CODTIPSEDIU NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  ICLASA NUMBER(1,0),
  CONTRONLY NUMBER(1,0),
  TIPBENEFICIAR NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTIPSEDII1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B996DF61903185A12F3EDE052BCED5CE64E9CB09</HASHVAL>
  <TEXT>CREATE TABLE NTIPSEDII1 (
  CODTIPSEDIU1 NUMBER(20,0) NOT NULL,
  CODTIPSEDIU NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9FD7B07D82B3B6677CF97FCE95A79D163A3B343</HASHVAL>
  <TEXT>CREATE TABLE NTVA (
  CODTVA NUMBER(20,0) NOT NULL,
  DEN_TVA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NTVA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90E17ABF7AB533CB7A8A213CE5A49E718EC0E1B5</HASHVAL>
  <TEXT>CREATE TABLE NTVA1 (
  CODTVA1 NUMBER(20,0) NOT NULL,
  CODTVA NUMBER(20,0),
  PROCENT NUMBER(6,3),
  CODCONTDED NUMBER(20,0),
  CODCONTCOLE NUMBER(20,0),
  CODCONTNEEX NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24A74D6C6FF03DD7DF79575142686D1B314C09D5</HASHVAL>
  <TEXT>CREATE TABLE NUM (
  CODUM NUMBER(20,0) NOT NULL,
  DEN_UM VARCHAR2(15),
  TIP VARCHAR2(20),
  ZECIMALE NUMBER(4,0),
  TIPUM NUMBER(1,0),
  COEF NUMBER(20,5),
  CODUMSAFT NUMBER(20,0),
  PARITATEUMSAFT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NUM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10F2572C16E3CEAAF6BEFE30C7CA2F286AEC46B3</HASHVAL>
  <TEXT>CREATE TABLE NUM1 (
  CODUM1 NUMBER(20,0) NOT NULL,
  CODUM NUMBER(20,0),
  SECUNDARA NUMBER(1,0),
  DEN_UM1 VARCHAR2(15),
  PARITATE NUMBER(30,15),
  ZECIMALE NUMBER(4,0),
  OBS VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  DEN_EANCOM VARCHAR2(15),
  DEN_INTRASTAT VARCHAR2(15),
  INACTIV NUMBER(1,0),
  CODUMSAFT NUMBER(20,0),
  PARITATEUMSAFT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>NZONE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>34236CCAF514893B62FCF6FD4ECFD4EC3C9A4520</HASHVAL>
  <TEXT>CREATE TABLE NZONE (
  CODZONA NUMBER(20,0) NOT NULL,
  DEN_ZONA VARCHAR2(50),
  SIMBOL VARCHAR2(10),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OBIECTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E72E080CC68C2FA26E6CB15D833529A66510D87</HASHVAL>
  <TEXT>CREATE TABLE OBIECTIVE (
  CODOBIECTIV NUMBER(20,0) NOT NULL,
  TIP NUMBER(1,0),
  DEN_OBIECTIV VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OBJ_CMDINT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BEA2CFD912D28A67E192CC9B150B804359EBE8D4</HASHVAL>
  <TEXT>CREATE TABLE OBJ_CMDINT1 (
  CODOBIECT NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OBLIGPIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D491A060E46B965518BE821E533E033D14296F8</HASHVAL>
  <TEXT>CREATE TABLE OBLIGPIF (
  CODOBLIGPIF NUMBER(20,0) NOT NULL,
  CODGENERAL NUMBER(20,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  TIPPLATA NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  TIP VARCHAR2(1),
  CONTBANKTRANZACTIE NUMBER(20,0),
  CODOBLIGASOCIAT NUMBER(20,0),
  VALOAREAFISATA NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODTRANSA NUMBER(20,0),
  RESTTRANSA NUMBER(20,7),
  COEFPROVIZION NUMBER(20,7),
  ADAOSDOC NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  TVAAFISAT NUMBER(20,7),
  SPLITTVA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OBLIGPIFLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>523C1813570209698FF7B44CEC20FA59A05F282C</HASHVAL>
  <TEXT>CREATE TABLE OBLIGPIFLOCK (
  CODOBLIGPIF NUMBER(20,0),
  CODSTINGATORPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OBLIGPIFLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D658D55C0CB9E0B91B2AE2A01ACB1D1B882A2FE0</HASHVAL>
  <TEXT>CREATE TABLE OBLIGPIFLUNA (
  CODOBLIGPIF NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  REST NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  RESTSPLITTVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E150E112EFEF2F7B4EA714681B9CAEC681C43058</HASHVAL>
  <TEXT>CREATE TABLE OFERTA (
  CODOFERTA NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  PARTENER NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODPERSC NUMBER(20,0),
  DATACERERE DATE,
  DATAOFERTA DATE,
  OFERTAT NUMBER(1,0),
  TOATESUBUNIT NUMBER(1,0),
  AGENT NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  NRMAXAPROBARI NUMBER(5,0),
  TIPBENEFICIAR NUMBER(1,0),
  CODCLASEP NUMBER(20,0),
  NRI VARCHAR2(30),
  CODNPARCAUT NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  PROCDISC NUMBER(20,7),
  CODANALIZA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OFERTA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB4162F11511253877E7AC519ADFBFCF2B6E83AE</HASHVAL>
  <TEXT>CREATE TABLE OFERTA1 (
  CODOFERTA1 NUMBER(20,0) NOT NULL,
  CODOFERTA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  PRET NUMBER(20,7),
  OBS VARCHAR2(200),
  ZILEL NUMBER(10,0),
  ZILEC NUMBER(10,0),
  PROCADAOS NUMBER(20,2),
  PROCDISCOUNT NUMBER(25,7),
  CODEXTOFE VARCHAR2(30),
  CANTMINUM1 NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CANTMAX NUMBER(20,7),
  CODCATPRET NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CANTOPTIMUM1 NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  PRETREF NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  DATACERTIFI DATE,
  DATACERTIFF DATE,
  CODCENTRU NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OFERTA1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6D020F49E1ADBCB985D85BFEEA992BC4222FB1E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE OFERTA1_MAN (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPORTUNITATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D63A4BD1BFBD0C9CBA8C7644D615792AC7A7B22D</HASHVAL>
  <TEXT>CREATE TABLE OPORTUNITATI (
  CODOPORTUNITATE NUMBER(20,0) NOT NULL,
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODCARNETDOC NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODAGENT NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  VENITEST NUMBER(20,7),
  VENITPROB NUMBER(3,0),
  CODSUBUNITATE NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  PROBVANZ NUMBER(3,0),
  DATASEMNARE DATE,
  CODCONTRACT NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODLEAD NUMBER(20,0),
  CODTASK NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODPROIECTCRM NUMBER(20,0),
  CODCLASEOPT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(500),
  CURS NUMBER(20,7),
  CODFISCAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPORTUNITATI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0082EA7AD86B70626CDF614266511B3058CEF0AF</HASHVAL>
  <TEXT>CREATE TABLE OPORTUNITATI1 (
  CODOPORTUNITATE1 NUMBER(20,0) NOT NULL,
  CODOPORTUNITATE NUMBER(20,0),
  INDEXLOCAL NUMBER(3,0),
  STADIU NUMBER(1,0),
  CODAGENT NUMBER(20,0),
  INFO VARCHAR2(2000),
  DATAC DATE,
  CODMOTIV NUMBER(20,0),
  FOLLOWUP DATE,
  CODTASK NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPPER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A12B8E144B4B723E45D9AC766B6C83012862350</HASHVAL>
  <TEXT>CREATE TABLE OPPER (
  CODOPPER NUMBER(20,0),
  OBS VARCHAR2(100),
  AN NUMBER(4,0),
  VALOARE NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPPER1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BB659E1E0DA5CB510552418FF481B86CE5D20D3</HASHVAL>
  <TEXT>CREATE TABLE OPPER1 (
  CODOPPER1 NUMBER(20,0),
  CODOPPER NUMBER(20,0),
  SAPTAMANA NUMBER(2,0),
  TIPOPER NUMBER(2,0),
  VALOARE NUMBER(20,7),
  TERMEN DATE,
  OBS VARCHAR2(250),
  CODELEMBUGET NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3BADC9D1C649E17A1F265FC2B98577EA44C0681D</HASHVAL>
  <TEXT>CREATE TABLE OPREG (
  CODOP NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPTRANZ NUMBER(1,0),
  TIPDECONT NUMBER(3,0),
  ZIDECONT NUMBER(2,0),
  CODMONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN_START NUMBER(4,0),
  LUNA_START NUMBER(2,0),
  AN_MAX NUMBER(4,0),
  LUNA_MAX NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OPREG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C265C345711547C9FB142347DD774FDE4202224</HASHVAL>
  <TEXT>CREATE TABLE OPREG1 (
  CODOP1 NUMBER(20,0) NOT NULL,
  CODOP NUMBER(20,0),
  TERMEN DATE,
  STINS NUMBER(1,0),
  OBS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ORAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CF470B8DA6997A3D35AFC19C4D2CFAB23A78ADB</HASHVAL>
  <TEXT>CREATE TABLE ORAR (
  CODORAR NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  OBS VARCHAR2(50),
  REPETARE NUMBER(1,0),
  INTERVAL NUMBER(4,0),
  ORA NUMBER(2,0),
  MIN NUMBER(2,0),
  ZILE_SAPT VARCHAR2(30),
  ZILE_LUNA VARCHAR2(300),
  DATA_START DATE,
  DATA_FIN DATE,
  DATACREARE DATE,
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ORELM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A96634B84133CED629EF5E907D3FC3DC352127C4</HASHVAL>
  <TEXT>CREATE TABLE ORELM (
  CODORELM NUMBER(20,0) NOT NULL,
  DATALM DATE NOT NULL,
  CODLM NUMBER(20,0),
  CODLM1 NUMBER(20,0),
  ORE NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OREPONTAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>351C54F31223ABA38138CAD78FF368A1E92800DD</HASHVAL>
  <TEXT>CREATE TABLE OREPONTAJ (
  CODFORMATIE NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  ORE NUMBER(5,0),
  SALAR NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>OSPATARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E2559E17B248C5904448B57396F32A736A5B6E0</HASHVAL>
  <TEXT>CREATE TABLE OSPATARI (
  COD NUMBER(20,0),
  CODPERS NUMBER(20,0),
  PAROLA VARCHAR2(50),
  CODRESTAURANT NUMBER(20,0),
  SUPERVIZOR NUMBER(1,0),
  VERLISTNP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>94D77137BB665EE620D08EBDBA91C3D51FCF3DCB</HASHVAL>
  <TEXT>CREATE TABLE PACHETE (
  CODPACHETE NUMBER(20,0) NOT NULL,
  DATAP TIMESTAMP(6),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATE NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(10,0),
  COLECTOR NUMBER(20,0),
  DATACOLECTARE TIMESTAMP(6),
  VERIFICATOR NUMBER(20,0),
  DATAVERIFICARE TIMESTAMP(6),
  TRANSPORTATOR NUMBER(20,0),
  DATATRANSPORT TIMESTAMP(6),
  NRPACHETE NUMBER(10,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  IDENTIFICATORP VARCHAR2(50),
  LISTAT NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPPART VARCHAR2(100),
  SEDIU NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  TIPLIVRARE NUMBER(10,0),
  TIPPACHET NUMBER(1,0),
  SPONSORIZARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF85C9BE29EAD1DB5C0461B25AF6DA35608F52B6</HASHVAL>
  <TEXT>CREATE TABLE PACHETE1 (
  CODPACHETE1 NUMBER(20,0) NOT NULL,
  CODPACHETE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETEDLLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C6CD1A10836203A874F0BF87ABA5BDB35521DF64</HASHVAL>
  <TEXT>CREATE TABLE PACHETEDLLINK (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETELINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11A9BBE216BBC4F8A2089FE5E105E26ED345AC1F</HASHVAL>
  <TEXT>CREATE TABLE PACHETELINK (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETEOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C31E9806783B1EB4AD9FD8EF8CC545EECBE77A01</HASHVAL>
  <TEXT>CREATE TABLE PACHETEOBJ (
  CODPACHETEOBJ NUMBER(20,0) NOT NULL,
  CODPACHETE NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  CANTUM1 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETEOBJL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83FB3AAD031E2B5C9AE10C345F84A4D81DDD02A0</HASHVAL>
  <TEXT>CREATE TABLE PACHETEOBJL (
  CODPACHETEOBJL NUMBER(20,0) NOT NULL,
  CODPACHETE NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PACHET NUMBER(10,0),
  CODREZERVATS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACHETEOBJLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DC1B8879323525E4DF976E40FDE7EDA62E8D7E7</HASHVAL>
  <TEXT>CREATE TABLE PACHETEOBJLINK (
  CODIES1 NUMBER(20,0) NOT NULL,
  CODPACHETEOBJL NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACKING</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72C2E06EC6AC54AC87E559200EA78FC432278283</HASHVAL>
  <TEXT>CREATE TABLE PACKING (
  CODPACKING NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  OBS VARCHAR2(200),
  DIRTY NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACKING1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>135EB718CFF362FB23F56D6F7F93C4D88B3E7860</HASHVAL>
  <TEXT>CREATE TABLE PACKING1 (
  CODPACKING1 NUMBER(20,0) NOT NULL,
  CODPACKING NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODAMB_PRIMAR NUMBER(20,0),
  CODAMB_SECUNDAR NUMBER(20,0),
  CODAMB_TERTIAR NUMBER(20,0),
  CANTAMB NUMBER(20,7),
  CANTAMBXPRIMAR NUMBER(20,7),
  CANTAMBXSECUNDAR NUMBER(20,7),
  CANTAMBXTERTIAR NUMBER(20,7),
  CANTCOMANDA NUMBER(20,7),
  CANTOBJ NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACKING2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A3E3CF8DEC62A3CF91E8CDA774946D2FBAC4B2E</HASHVAL>
  <TEXT>CREATE TABLE PACKING2 (
  CODPACKING2 NUMBER(20,0) NOT NULL,
  CODPACKING1 NUMBER(20,0),
  SSCC VARCHAR2(18),
  OBS VARCHAR2(2500),
  CODAMB_FINAL NUMBER(20,0),
  CANTOBJ NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PACKING3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>397EAF6D47418D24D144004B4D24F77D18DBE364</HASHVAL>
  <TEXT>CREATE TABLE PACKING3 (
  CODPACKING3 NUMBER(20,0) NOT NULL,
  CODPACKING2 NUMBER(20,0),
  CODREZERVATS NUMBER(20,0),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PARAMLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3998E82A85ACD6BC45D065E7CAF6BD0FEAAED1B5</HASHVAL>
  <TEXT>CREATE TABLE PARAMLISTE (
  CODPARAMLISTE NUMBER(20,0) NOT NULL,
  USERID NUMBER(20,0),
  LISTID NUMBER(20,0),
  LISTVER NUMBER(20,0),
  DATA1 DATE,
  DATA2 DATE,
  AN1 NUMBER(4,0),
  LUNA1 NUMBER(2,0),
  AN2 NUMBER(4,0),
  LUNA2 NUMBER(2,0),
  INT1DATA1 DATE,
  INT1DATA2 DATE,
  INT1AN1 NUMBER(4,0),
  INT1LUNA1 NUMBER(2,0),
  INT1AN2 NUMBER(4,0),
  INT1LUNA2 NUMBER(2,0),
  INT2DATA1 DATE,
  INT2DATA2 DATE,
  INT2AN1 NUMBER(4,0),
  INT2LUNA1 NUMBER(2,0),
  INT2AN2 NUMBER(4,0),
  INT2LUNA2 NUMBER(2,0),
  INT3DATA1 DATE,
  INT3DATA2 DATE,
  INT3AN1 NUMBER(4,0),
  INT3LUNA1 NUMBER(2,0),
  INT3AN2 NUMBER(4,0),
  INT3LUNA2 NUMBER(2,0),
  INT4DATA1 DATE,
  INT4DATA2 DATE,
  INT4AN1 NUMBER(4,0),
  INT4LUNA1 NUMBER(2,0),
  INT4AN2 NUMBER(4,0),
  INT4LUNA2 NUMBER(2,0),
  INT5DATA1 DATE,
  INT5DATA2 DATE,
  INT5AN1 NUMBER(4,0),
  INT5LUNA1 NUMBER(2,0),
  INT5AN2 NUMBER(4,0),
  INT5LUNA2 NUMBER(2,0),
  VAL1 VARCHAR2(100),
  VAL2 VARCHAR2(100),
  VAL3 VARCHAR2(100),
  VAL4 VARCHAR2(100),
  VAL5 VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>836BD79331F142A26D25D6ED6ED1623B66A4BEA9</HASHVAL>
  <TEXT>CREATE TABLE PARTICIP (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PARTPUNCTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEBA391769767A7BBECD95C1E9B7245C05FDE151</HASHVAL>
  <TEXT>CREATE TABLE PARTPUNCTE (
  COD NUMBER(20,0),
  CODPART NUMBER(20,0),
  DATA DATE,
  CODEMULARE NUMBER(20,0),
  PUNCTE NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PARTTOT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A13208B4294B89ECC4C39026FE598CAAFA0E389D</HASHVAL>
  <TEXT>CREATE TABLE PARTTOT (
  CODPARTTOT NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  SOLDREAL NUMBER(20,2),
  NEOPERAT NUMBER(20,2),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PASS_MODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F0EC6D93ED0D7C24522084FF70CD3A9A3C2F6BB</HASHVAL>
  <TEXT>CREATE TABLE PASS_MODIF (
  DATAMODIF DATE,
  PERSMODIF NUMBER(10,0),
  CODMASTER NUMBER(20,0),
  TABLENAME VARCHAR2(20),
  FIELDNAME VARCHAR2(20),
  OLDVALUE VARCHAR2(30),
  NEWVALUE VARCHAR2(30),
  EXPLIC CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PCALCUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26F7595DC4B3C78A633F9961CAB29800386A10F9</HASHVAL>
  <TEXT>CREATE TABLE PCALCUL (
  CODPC NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  CUMULAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  VARIANTA NUMBER(20,0),
  DATADOC DATE,
  TIPPUNCT NUMBER(3,0),
  OBSERVATII VARCHAR2(50),
  TIPALOC NUMBER(2,0),
  VALF NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PCART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B55C7D73D9FEA1C5C3658823866408891F7E8F9F</HASHVAL>
  <TEXT>CREATE TABLE PCART (
  CODPCART NUMBER(20,0) NOT NULL,
  CODPC NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CANT NUMBER(20,7),
  VAL NUMBER(20,7),
  VALS NUMBER(20,7),
  VALI NUMBER(20,7),
  VALA NUMBER(20,7),
  VALC NUMBER(20,7),
  VALG NUMBER(20,7),
  MAT NUMBER(20,7),
  PUNCTE NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  COEF NUMBER(20,7),
  MAN NUMBER(20,7),
  VALMAN NUMBER(20,7),
  CANTTOT NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  VALTOT NUMBER(20,7),
  VALLINIE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PCDIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3B3169B9B9F5D81997A18864E726F2FA3A0F9E4</HASHVAL>
  <TEXT>CREATE TABLE PCDIR (
  CODPCDIR NUMBER(20,0) NOT NULL,
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  VAL NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PCGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE46940D7210A6C099FEFE0CD4392F9EC5B333AE</HASHVAL>
  <TEXT>CREATE TABLE PCGEST (
  CODPCGEST NUMBER(20,0) NOT NULL,
  CODPC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  MANS NUMBER(20,7),
  VALI NUMBER(20,7),
  VALA NUMBER(20,7),
  VALC NUMBER(20,7),
  VALG NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  PUNCTE NUMBER(20,7),
  VALMATN NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PCSECTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9E750D8805F6F1C84DF15F73D2D053DA4B4561F</HASHVAL>
  <TEXT>CREATE TABLE PCSECTII (
  CODPCSECTII NUMBER(20,0) NOT NULL,
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  FAZA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PERISABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83295FE8124EC0147715DD263EB4D3093AEF0278</HASHVAL>
  <TEXT>CREATE TABLE PERISABIL (
  CODPERISABIL NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PERISABIL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC07A6239DCB7E1470096B0F22ACF5915F6C42FD</HASHVAL>
  <TEXT>CREATE TABLE PERISABIL1 (
  CODPERISABIL1 NUMBER(20,0) NOT NULL,
  CODPERISABIL NUMBER(20,0),
  LUNA_INI NUMBER(20,0),
  LUNA_FIN NUMBER(20,0),
  NRZILE NUMBER(3,0),
  OBS1 VARCHAR2(200),
  NRZILEDIR NUMBER(3,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PERISABIL2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40C84E317D5EC5CC5B3E0E2DFF289D8E8E7AECB4</HASHVAL>
  <TEXT>CREATE TABLE PERISABIL2 (
  CODPERISABIL2 NUMBER(20,0) NOT NULL,
  CODPERISABIL NUMBER(20,0),
  LUNA_INI NUMBER(2,0),
  LUNA_FIN NUMBER(2,0),
  ZI_INI NUMBER(2,0),
  ZI_FIN NUMBER(2,0),
  STOCMEDIU NUMBER(20,7),
  TIPSEZON NUMBER(1,0),
  OBS1 VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54C2686EE2017B111B1C94FC858A5895985AF3C6</HASHVAL>
  <TEXT>CREATE TABLE PGS (
  CODPGS NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PGS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A63A1A78BC0387429547FB6CB60ED55597F0DC92</HASHVAL>
  <TEXT>CREATE TABLE PGS1 (
  CODPGS1 NUMBER(20,0) NOT NULL,
  CODPGS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ED129FCF03D40117FB4FE45F38DFB6B3798A2C49</HASHVAL>
  <TEXT>CREATE TABLE PLANCURS (
  CODPLANCURS NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  NR NUMBER(20,0),
  DATACURS DATE,
  TIP VARCHAR2(100),
  AN NUMBER(4,0),
  LUNA VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANCURS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>241C12A44C9A0D47757E3980EDEC0C9D51F5C0AB</HASHVAL>
  <TEXT>CREATE TABLE PLANCURS1 (
  CODPLANCURS1 NUMBER(20,0) NOT NULL,
  CODPLANCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  DATAPLAN DATE,
  STARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>104AE08AB064503CBD2DEE5B5233D68645D17265</HASHVAL>
  <TEXT>CREATE TABLE PLANIFLINK (
  CODCOMANDA1 NUMBER(20,0),
  CODSTARE1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>209A848020521884E610C52ED90095496A0ED675</HASHVAL>
  <TEXT>CREATE TABLE PLANIFLOCK (
  USERID NUMBER(20,0),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43E999CC56733871398FC773BB1BA0F484E1B0C6</HASHVAL>
  <TEXT>CREATE TABLE PLANIFNOD (
  CODPLANIFNOD NUMBER(20,0) NOT NULL,
  CODPLANIFPROD1 NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>441CBC59732A397656975D9282001102E18969F0</HASHVAL>
  <TEXT>CREATE TABLE PLANIFPROD (
  CODPLANIFPROD NUMBER(20,0) NOT NULL,
  CODLANSPROD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  OBS VARCHAR2(250),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(10,0),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(3),
  INSAPTAMANA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFPROD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF83B6768742F643E0173139727EA2FDAB781EC0</HASHVAL>
  <TEXT>CREATE TABLE PLANIFPROD1 (
  CODPLANIFPROD1 NUMBER(20,0) NOT NULL,
  CODPLANIFPROD NUMBER(20,0),
  CODLANSPROD1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  OBS VARCHAR2(250),
  NECESAR NUMBER(20,7),
  CANT NUMBER(20,7),
  CUPROIECT NUMBER(1,0),
  CODPROIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFPRODLUN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02712DD7D5DCA1373995E224379EA405F2F6965C</HASHVAL>
  <TEXT>CREATE TABLE PLANIFPRODLUN (
  CODOBIECT NUMBER(20,0),
  PLWEEK1 NUMBER(20,7),
  PLWEEK2 NUMBER(20,7),
  PLWEEK3 NUMBER(20,7),
  PLWEEK4 NUMBER(20,7),
  PLWEEK5 NUMBER(20,7),
  ANLUNA NUMBER(20,0),
  PLANIFICAT NUMBER(20,7),
  LANSARE NUMBER(20,7),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLANIFSTRUCT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D4138D38117EC242DF9487B5A0C09A3C9536FB3</HASHVAL>
  <TEXT>CREATE TABLE PLANIFSTRUCT (
  CODOBIECT NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  AN NUMBER(4,0),
  SAPTAMANA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>96C0A2057AF3A5035BB2AF366F811BF87DCC53A4</HASHVAL>
  <TEXT>CREATE TABLE PLATI (
  CODPLATA NUMBER(20,0),
  DATA DATE,
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  VALOAREDEREPARTIZAT NUMBER(20,0),
  APROBAT NUMBER(1,0),
  TIPDOC NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODANALIZA NUMBER(20,0),
  OBS VARCHAR2(500),
  CURS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLATI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44D1A96000824D3065757E2851392B7BA589D2A4</HASHVAL>
  <TEXT>CREATE TABLE PLATI1 (
  CODPLATA1 NUMBER(20,0),
  CODPLATA NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  CONTDEST VARCHAR2(50),
  ADRESAFURN VARCHAR2(200),
  INDEXLOCAL NUMBER(20,0),
  STINSA NUMBER(1,0),
  CODSWIFT VARCHAR2(30),
  CODBNR VARCHAR2(30),
  CODSTATISTICBNR VARCHAR2(30),
  CODBANK NUMBER(20,0),
  TIPCOMISION VARCHAR2(6),
  CODPART NUMBER(20,0),
  SPLITTVA NUMBER(1,0),
  REST NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODANALIZANODX NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLATI2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>526E490E5352F01A4D0207C3ED9FFF65B9CB9444</HASHVAL>
  <TEXT>CREATE TABLE PLATI2 (
  CODPLATA2 NUMBER(20,0),
  CODPLATA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CONTDEST VARCHAR2(30),
  CODSWIFT VARCHAR2(30),
  VALOARE NUMBER(20,7),
  NRDOC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PLUCASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BFE73FDB5C63C33A3B70234791E037965CF9D32</HASHVAL>
  <TEXT>CREATE TABLE PLUCASE (
  CODPLUCASE NUMBER(20,0),
  CODCASA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPLU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PMPLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>322C3520998DF8E0CF340181B75D518EE6DFEED7</HASHVAL>
  <TEXT>CREATE TABLE PMPLUNA (
  CODPMPLUNA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CANTINTR NUMBER(20,7),
  VALINTR NUMBER(20,7),
  REST NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  VALVALUTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PMP_ALL_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>334F42BF9418C061E788085424D8B61D25139504</HASHVAL>
  <TEXT>CREATE TABLE PMP_ALL_LUNA (
  CODPMP_ALL_LUNA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANTINTR NUMBER(20,7),
  VALINTR NUMBER(20,7),
  REST NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  VALVALUTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>POSBANCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6288351BF4494142CD73E3B3F22F8BF9B74B44B8</HASHVAL>
  <TEXT>CREATE TABLE POSBANCAR (
  CODPOSBANCAR NUMBER(5,0) NOT NULL,
  INDEXLOCAL NUMBER(2,0),
  TIPPOS NUMBER(3,0),
  PORTSERIAL NUMBER(2,0),
  IP VARCHAR2(50),
  INACTIV NUMBER(1,0),
  USERID NUMBER(20,0),
  REMOTE NUMBER(1,0),
  IPSERVERPOS VARCHAR2(50),
  PORTSERVERPOS NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>POSTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9438A7D0A11660D80A199FA38ECFD14610C2C27</HASHVAL>
  <TEXT>CREATE TABLE POSTRETAIL (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  ID NUMBER(3,0),
  NUMEFIRMA VARCHAR2(30),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PPLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A338E2A9F844272B5938EAA5FEA36509371023D</HASHVAL>
  <TEXT>CREATE TABLE PPLINK (
  IDINREG NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRECMDLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B1DCDB3D6E5C2F2B2546A31ADBAA821ABFBE1DD</HASHVAL>
  <TEXT>CREATE TABLE PRECMDLINK (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODPRECOMANDA1 NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRECOMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD3077714207A582E13A76FEE0C019302F8DB0C6</HASHVAL>
  <TEXT>CREATE TABLE PRECOMANDA (
  CODPRECOMANDA NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  VALOARE NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(200),
  MONEDA NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  INCHISA NUMBER(1,0),
  SERIADOC VARCHAR2(20),
  VERIFICAT NUMBER(1,0),
  CODSTARE1 NUMBER(20,0),
  SAPTAMANAC NUMBER(2,0),
  ANC NUMBER(4,0),
  SAPTAMANAG NUMBER(10,0),
  ANG NUMBER(4,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRECOMANDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE8423721892BBD5C299FF9CF77F6A4E88A544D1</HASHVAL>
  <TEXT>CREATE TABLE PRECOMANDA1 (
  CODPRECOMANDA1 NUMBER(20,0) NOT NULL,
  CODPRECOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  TERMEN DATE,
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CODCONTRACT1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CODSTARE1 NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PREDARIPLUS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55EA9EC02F35B9B2F26954E9BFE53D975605C6B5</HASHVAL>
  <TEXT>CREATE TABLE PREDARIPLUS (
  IDINREG NUMBER(20,0) NOT NULL,
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  CODAFA VARCHAR2(50),
  CODEXTERN VARCHAR2(100),
  UA VARCHAR2(15),
  SECTIE VARCHAR2(15),
  CANTITATE NUMBER(20,7),
  DATAMODIF TIMESTAMP(6),
  NRCMD VARCHAR2(50),
  DATACMD DATE,
  FSC VARCHAR2(500),
  SCHIMB VARCHAR2(50),
  FORMATIE VARCHAR2(100),
  NRNP VARCHAR2(50),
  DATANP DATE,
  USERIDBLOCAJ NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CANTITATEWME NUMBER(20,7),
  DATAWME TIMESTAMP(6),
  LINIA VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PREDARI_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>30F6C28BE71B933598821C14406292309D4D798E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE PREDARI_MAN (
  CANT NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRESTATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9FEC9F534E134B31A6ABBE5C201D2F25EE9539D7</HASHVAL>
  <TEXT>CREATE TABLE PRESTATII (
  CODPRESTATIE NUMBER(20,0) NOT NULL,
  COD VARCHAR2(50),
  DENUMIRE VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRETM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90299C65628C6AC7005A27642D8957E6EB06EE46</HASHVAL>
  <TEXT>CREATE TABLE PRETM (
  CODPRETM NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  LEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  MONEDA NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  PROC NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  SUBUNITATEA NUMBER(20,0),
  GRUPA VARCHAR2(10),
  ROTUNJIRE NUMBER(2,0),
  SUMAFIXAIMPLICIT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRETMAMB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1984511A871C0A92E5154F4D819AC3C10A00F41B</HASHVAL>
  <TEXT>CREATE TABLE PRETMAMB (
  CODPRETMAMB NUMBER(20,0) NOT NULL,
  CODPRETM NUMBER(20,0),
  CODAMB NUMBER(20,0),
  LEI NUMBER(20,7),
  VALUTA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRETM_AUTOUPD_LOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3346F5CC86AB9128F73487130388F434DEF5ADFD</HASHVAL>
  <TEXT>CREATE TABLE PRETM_AUTOUPD_LOG (
  COD_MONEDA NUMBER NOT NULL,
  COD_BANCA NUMBER NOT NULL,
  RUN_DATE DATE NOT NULL,
  STARTED_BY VARCHAR2(30) NOT NULL,
  START_TS TIMESTAMP(6) NOT NULL,
  END_TS TIMESTAMP(6),
  STATUS VARCHAR2(10) NOT NULL,
  ERROR_MSG VARCHAR2(4000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROC_ACT_DEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB92F05606528084B5C412342BD12B106530EDDA</HASHVAL>
  <TEXT>CREATE TABLE PROC_ACT_DEF (
  CODPROCACTDEF NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  SQL CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23FE5A694CDCE6E93AEAE8D44F7F3EDC4B457C2D</HASHVAL>
  <TEXT>CREATE TABLE PRODCOMP (
  CODPRODCOMP NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(250),
  DATA DATE,
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  CANT NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPRETETA NUMBER(1,0),
  CANTUM1 NUMBER(20,7),
  PRET NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  IMPLICIT NUMBER(1,0),
  DESCRIERE CLOB,
  INACTIV NUMBER(1,0),
  GEST NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  OBSERVATII VARCHAR2(3000),
  PROIECTANT NUMBER(20,0),
  CODCLASAPROD NUMBER(20,0),
  INVIZIBILA NUMBER(1,0),
  GENERIC NUMBER(1,0),
  DURATA NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  HFACTOR NUMBER(2,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  TIPPRET NUMBER(1,0),
  CODPROIECT NUMBER(20,0),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  CODMONEDA NUMBER(20,0),
  PRETVALUTA NUMBER(20,7),
  AG NUMBER(20,7),
  VALAG NUMBER(20,7),
  PROFIT NUMBER(20,7),
  VALPROFIT NUMBER(20,7),
  PRETFINAL NUMBER(20,7),
  VALPROFITV NUMBER(20,7),
  PRETFINALV NUMBER(20,7),
  TOTPRETCOEF NUMBER(20,7),
  TOTPRETFIX NUMBER(20,7),
  TOTPRETCOEFV NUMBER(20,7),
  TOTPRETFIXV NUMBER(20,7),
  VALREGIEMAN NUMBER(20,7),
  ASCUNS NUMBER(1,0),
  CODUTILIZARE NUMBER(20,0),
  NOHFACTOR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODCOMP_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ED1AFA256A3D05ACD52E0361B07B033DBF1BA485</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE PRODCOMP_CLONA (
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  VALREGIEMAN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2C37E88303175542E580A965A665E1E266746369</HASHVAL>
  <TEXT>CREATE TABLE PRODGEST (
  CODPRODGEST NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODGEST NUMBER(20,0),
  COEFMAT NUMBER(20,7),
  COEFMAN NUMBER(20,7),
  TIMPEST NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C196F42A71359F906CDEB0CA7C7B71D3D365725F</HASHVAL>
  <TEXT>CREATE TABLE PRODMAN (
  CODMAN NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  NROP NUMBER(10,0),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DSV NUMBER(20,7),
  BPS NUMBER(20,7),
  TPI NUMBER(20,7),
  OBS VARCHAR2(1000),
  DETALII NUMBER(10,0),
  FIX NUMBER(1,0),
  NIVEL NUMBER(5,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  COEFBPS NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMAN_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D1463244BB921B7A3CDD1D5EDDB54890A123FA0E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE PRODMAN_CLONA (
  CODMAN NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  VALOARE_V NUMBER(20,7),
  VALOARE_N NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>410284968318EE928DD199832EDC0F14660B3D51</HASHVAL>
  <TEXT>CREATE TABLE PRODMAS (
  CODPRODMAS NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  CODPRODGEST NUMBER(20,0),
  DESCRIERE VARCHAR2(200),
  FRECVENTA VARCHAR2(20),
  METODA VARCHAR2(150),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3ADCBFEFFC22781D2289DEA796550ABBB0724CC8</HASHVAL>
  <TEXT>CREATE TABLE PRODMAT (
  CODMAT NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CANTUM1 NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  TIP NUMBER(1,0),
  CODATRIBUT NUMBER(20,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  OBS VARCHAR2(300),
  ADDDIM NUMBER(20,7),
  ADDDIM_TRANSP NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PROCREAL NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  CODMAN NUMBER(20,0),
  COPYD1 NUMBER(12,7),
  COPYD2 NUMBER(12,7),
  COPYD3 NUMBER(12,7),
  ETAPA NUMBER(10,0),
  PRETV NUMBER(20,7),
  PRINCIPAL NUMBER(1,0),
  CONSUM NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMATECHIV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A56AB62625A770411FA0E424989184D0E5D1ACB</HASHVAL>
  <TEXT>CREATE TABLE PRODMATECHIV (
  CODMATECHIV NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  CODMAT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  ORDINE NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODMAT_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7389845614F60520E41F1DA40ED106A50EE1FC75</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE PRODMAT_CLONA (
  CODMAT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODNET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28D194E1403B06FC7105C2A41E043B0BA7FD727F</HASHVAL>
  <TEXT>CREATE TABLE PRODNET (
  CODPRODNET NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  TIP NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODNET1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2572AC6CDDEEFC5E9D95F1569B71613845BACF3C</HASHVAL>
  <TEXT>CREATE TABLE PRODNET1 (
  CODPRODNET1 NUMBER(20,0) NOT NULL,
  CODPRODNET NUMBER(20,0),
  TIP NUMBER(1,0),
  CODDOC1 NUMBER(20,0),
  EXPLICATII VARCHAR2(150),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  DIFCANT NUMBER(20,7),
  CANTREAL NUMBER(20,7),
  PRET NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  DIRTY NUMBER(1,0),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODNORME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31787BFC6A72EA4BE568CE01599CC2758F87E116</HASHVAL>
  <TEXT>CREATE TABLE PRODNORME (
  CODNORMA NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  NORMA VARCHAR2(250),
  INDEXLOCAL NUMBER(10,0),
  IMPLICIT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  DATAACTIV DATE,
  DATAINACTIV DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BCA25C94CD3BF5434B1050DE8938A9F19BF1DEF</HASHVAL>
  <TEXT>CREATE TABLE PRODREZ (
  CODREZ NUMBER(20,0) NOT NULL,
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  REZIDUU NUMBER(1,0),
  CANTUM1 NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  OBS VARCHAR2(300)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODREZ_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F8C75E86622EE40BE2466DC950529F09497BB60C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE PRODREZ_CLONA (
  CODREZ NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PRET_V NUMBER(20,7),
  PRET_N NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PRODSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF11BF1E890FD04AEB1DEB4439AF18466EFC64D8</HASHVAL>
  <TEXT>CREATE TABLE PRODSDV (
  CODPRODSDV NUMBER(20,0) NOT NULL,
  CODPRODMAN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODSDV NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CODPRODCOMP NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CA5F946FABC4653144ADEAE84087EF6688B18B1C</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMF (
  CODPROGRAMF NUMBER(20,0) NOT NULL,
  DATAINREG DATE,
  VDELA DATE,
  VPANALA DATE,
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  TIP NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  TIPDURATA NUMBER(1,0),
  NRDOC NUMBER(10,0),
  OBS VARCHAR2(200),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  ALLGEST NUMBER(1,0),
  ALLTIPCONT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5F4FB0081E89CFEC8D89B112359352A6ABA38FDD</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMF1 (
  CODPROGRAMF1 NUMBER(20,0) NOT NULL,
  CODPROGRAMF NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODGEST NUMBER(20,0),
  PRIORITATE NUMBER(10,0),
  TERMEN DATE,
  CANTPROGRAMAT NUMBER(20,7),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMFCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2B50F74AE66558A9C9FE045244382FF059EEEFF</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMFCONT (
  CODPROGRAMF NUMBER(20,0),
  CODIOART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMFGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0F09ABB45B8727C4B9719191354A09DE31A0F6A</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMFGEST (
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMFLMC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F83586747FDC600070CA53D0640686FEC22FAAD</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMFLMC (
  CODLMC NUMBER(20,0) NOT NULL,
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DATAPROGRAMARE DATE,
  CODOP NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMFMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00056E19DA3D29FFF33CB20E35FA133F1232ED81</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMFMAN (
  CODPFMAN NUMBER(20,0) NOT NULL,
  CODPROGRAMF NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROGRAMFSDV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA7B5F7B936889D4AD58F88E93DC2109AE0B96B5</HASHVAL>
  <TEXT>CREATE TABLE PROGRAMFSDV (
  CODPROGRAMFSDV NUMBER(20,0) NOT NULL,
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>151048352C978BA2F6E5D0DEA945997EE5B97B75</HASHVAL>
  <TEXT>CREATE TABLE PROIECT (
  CODPROIECT NUMBER(20,0) NOT NULL,
  CODVERSIUNE NUMBER(10,0),
  CODOBIECTPROD NUMBER(20,0),
  VERSIUNE VARCHAR2(100),
  INTOCMITA NUMBER(20,0),
  DATAPROIECT DATE,
  CLASA NUMBER(20,0),
  PROCESARE NUMBER(1,0),
  COMPLEX NUMBER(1,0),
  ACTIV NUMBER(1,0),
  FINALIZAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  INVIZIBILA NUMBER(1,0),
  GENERIC NUMBER(1,0),
  IMPLICIT NUMBER(1,0),
  DURATA NUMBER(20,7),
  MARJAORDINE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  CODEXTERN VARCHAR2(80),
  ASCUNS NUMBER(1,0),
  CODUTILIZARE NUMBER(20,0),
  CODIDENTIFICARE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROIECTCRM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC1435AB6B0508748735E10A9AFC3E93FAAA3B32</HASHVAL>
  <TEXT>CREATE TABLE PROIECTCRM (
  CODPROIECTCRM NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  DESCRIERE VARCHAR2(500),
  VALOARE NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROIECTNOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0E010991C28279420FD567E49EB981A75082D19</HASHVAL>
  <TEXT>CREATE TABLE PROIECTNOD (
  CODPROIECTNOD NUMBER(20,0) NOT NULL,
  CODPROIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3320E67B835EC13E6730450569853D7C45E0848A</HASHVAL>
  <TEXT>CREATE TABLE PROMO (
  CODPROMO NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  TIPPROMOTIE NUMBER(1,0),
  TIPCONDITIE NUMBER(1,0),
  OBS VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPCLASEP NUMBER(1,0),
  TIPSERVIRE NUMBER(1,0),
  DEMANA NUMBER(1,0),
  VALMIN NUMBER(20,7),
  PRAGURI NUMBER(1,0),
  CANTMIN NUMBER(20,7),
  ORASTART VARCHAR2(5),
  ORASTOP VARCHAR2(5),
  EXCLALTEPROMO NUMBER(1,0),
  PRETCUAMANUNT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMO1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2BD9D9E1A665BB74932082E6A8FE38A306E466B4</HASHVAL>
  <TEXT>CREATE TABLE PROMO1 (
  CODPROMO1 NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  ZILEC NUMBER(5,0),
  TIPLIMITA NUMBER(1,0),
  TG_MAX DATE,
  ZILE_EXP NUMBER(5,0),
  GRUPAPRET VARCHAR2(5),
  VALMIN NUMBER(20,7),
  PRETAMANUNT NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  MODAPLIC NUMBER(1,0),
  VALDISC NUMBER(20,7),
  CUECHIVALENTE NUMBER(1,0),
  CANT_MAX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMO1CADOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36FC7B4EBB6F172A5F7630DFF2BA36052C8E1D83</HASHVAL>
  <TEXT>CREATE TABLE PROMO1CADOU (
  CODCADOU NUMBER(20,0) NOT NULL,
  CODPROMO1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  TIPLIMITA NUMBER(1,0),
  TG_MAX DATE,
  ZILE_EXP NUMBER(5,0),
  CODPROMO NUMBER(20,0),
  VALMIN NUMBER(20,7),
  CANTMIN NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMO1CADOUSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A03363BEC2D0ED2DF4A92514A0ED158FF49FB839</HASHVAL>
  <TEXT>CREATE TABLE PROMO1CADOUSER (
  CODCADOUS NUMBER(20,0) NOT NULL,
  CODCADOU NUMBER(20,0),
  SERIE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMO1SER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A5146C72469B82BBBF1C8A310B270D32F898251B</HASHVAL>
  <TEXT>CREATE TABLE PROMO1SER (
  CODPROMO1S NUMBER(20,0) NOT NULL,
  CODPROMO1 NUMBER(20,0),
  SERIE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>189FDBA6A094296ADABA59F8DDE3D94B6FF9286C</HASHVAL>
  <TEXT>CREATE TABLE PROMOPART (
  CODPROMOPART NUMBER(20,0) NOT NULL,
  CODPROMO NUMBER(20,0),
  CODCLASEP NUMBER(20,0),
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  PRIORITAR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMOPRAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3BFB445B4F6E9725394581949520F6138F7BD4B6</HASHVAL>
  <TEXT>CREATE TABLE PROMOPRAG (
  CODPRAG NUMBER(20,0) NOT NULL,
  CODPROMO NUMBER(20,0),
  VALMIN NUMBER(20,7),
  PROCDISC NUMBER(20,2),
  CANTMIN NUMBER(20,7),
  VALDISC NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PROMOSUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>559DCF88DE5E20EE586F18E304B442CED1D23D7A</HASHVAL>
  <TEXT>CREATE TABLE PROMOSUB (
  CODPROMOSUB NUMBER(20,0) NOT NULL,
  CODPROMO NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PUNCTAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DAC7E41B4C23283A477C94A23647DCB205CB12F3</HASHVAL>
  <TEXT>CREATE TABLE PUNCTAJE (
  CODPUNCTAJ NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  DATASTART DATE,
  DATAEND DATE,
  TIP NUMBER(5,0),
  CASADEMARCAT NUMBER(1,0),
  FACTURARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PUNCTAJVALDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>258FBD01262D4DB8C7993990AE79843B14FFDC7B</HASHVAL>
  <TEXT>CREATE TABLE PUNCTAJVALDOC (
  COD NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  LIMITAVAL NUMBER(20,7),
  PUNCTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>PUNCTEUSE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99472935D2F518FB767B1C21DFA661965B36F567</HASHVAL>
  <TEXT>CREATE TABLE PUNCTEUSE (
  COD NUMBER(20,0) NOT NULL,
  CODPUNCTAJ NUMBER(20,0),
  PUNCTE NUMBER(20,0),
  VALACORDATA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RACDASHMAN_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>57DF5E070342B17B2EDE20CA1CFDBA5900586452</HASHVAL>
  <TEXT>CREATE TABLE RACDASHMAN_DOC (
  COD NUMBER(3,0) NOT NULL,
  GEST VARCHAR2(100),
  DATA VARCHAR2(10),
  ANALIZA VARCHAR2(100),
  CANTITATE VARCHAR2(15),
  ZILEREZ VARCHAR2(15),
  DURATAMEDIE VARCHAR2(15),
  RPD VARCHAR2(15),
  VENITTOTAL VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RACDASHOP_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>256CA728114B3E3ED991AF351C4266131D1B6229</HASHVAL>
  <TEXT>CREATE TABLE RACDASHOP_DOC (
  COD NUMBER(3,0) NOT NULL,
  GEST VARCHAR2(100),
  DATA VARCHAR2(10),
  DETALIU VARCHAR2(100),
  VALOARE VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RACDETALIEREINFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85731A65F0CA7E33FE67452D1B0BF78DF6CBBC18</HASHVAL>
  <TEXT>CREATE TABLE RACDETALIEREINFO (
  COD NUMBER(20,0) NOT NULL,
  SUBUNITATE VARCHAR2(100),
  GESTIUNE VARCHAR2(100),
  LOCATIE VARCHAR2(100),
  CLASA VARCHAR2(50),
  NRAUTO VARCHAR2(30),
  MARCA VARCHAR2(20),
  MODEL VARCHAR2(40),
  ANFAB VARCHAR2(10),
  KMBORD VARCHAR2(20),
  COMB VARCHAR2(100),
  DATABORD VARCHAR2(100),
  STATUS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RACDETALIEREINFOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8E5949DE19C2DB55AB7471AB9C669B3A76A42C9A</HASHVAL>
  <TEXT>CREATE TABLE RACDETALIEREINFOG (
  COD NUMBER(20,0) NOT NULL,
  SUBUNITATE VARCHAR2(100),
  GESTIUNE VARCHAR2(100),
  LOCATIE VARCHAR2(100),
  CLASA VARCHAR2(50),
  NRAUTO VARCHAR2(30),
  MARCA VARCHAR2(20),
  MODEL VARCHAR2(40),
  DATASOSIRE VARCHAR2(40),
  STATUS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_AUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F829F07E4215366848A024E7DDF38D49AA9E45E</HASHVAL>
  <TEXT>CREATE TABLE RAC_AUTO (
  CODAUTO NUMBER,
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER,
  TRANSFERAT NUMBER,
  Q NUMBER,
  DATASTART DATE,
  DATASTOP DATE,
  CODCLASA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_AUTO_CEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A9E1B31D65787C3ADEC93A1F0389A25CFC31BF93</HASHVAL>
  <TEXT>CREATE TABLE RAC_AUTO_CEN (
  CODAUTO NUMBER,
  CODGEST NUMBER,
  Q NUMBER
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_CARS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11947881389F3452B370B96EE696518A031B9D1D</HASHVAL>
  <TEXT>CREATE TABLE RAC_CARS (
  CODAUTO NUMBER(20,0) NOT NULL,
  DATA DATE,
  CODGEST NUMBER,
  GESTIUNE VARCHAR2(100),
  SUBUNITATE NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  INACTIV NUMBER,
  EXTERN NUMBER,
  CODOBIECT NUMBER(20,0),
  NRAUTO VARCHAR2(20),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  ANF NUMBER(4,0),
  CODGRECHIV NUMBER,
  IND NUMBER,
  CLASA VARCHAR2(250),
  GENERIC NUMBER
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_CATP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9EDAC3C5F27431897026B4545146AA729B92C56</HASHVAL>
  <TEXT>CREATE TABLE RAC_CATP (
  CODRAC_CATP NUMBER(20,0) NOT NULL,
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(50),
  CODCONTRACT NUMBER(20,0),
  ABONAMENT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_CATP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DC39B7459B8B2691CA8C2CCE04206BA629BA2AD</HASHVAL>
  <TEXT>CREATE TABLE RAC_CATP1 (
  CODRAC_CATP1 NUMBER(20,0) NOT NULL,
  CODRAC_CATP NUMBER(20,0),
  CODRAC_P NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_CATP2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E79E382B8340CE8CA4E4CC6B792D49EA59F0F9A7</HASHVAL>
  <TEXT>CREATE TABLE RAC_CATP2 (
  CODRAC_CATP2 NUMBER(20,0) NOT NULL,
  CODRAC_CATP NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_EMU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E86007EC6201BF9DCB1628F00D06AC3135213FB</HASHVAL>
  <TEXT>CREATE TABLE RAC_EMU (
  CODCOMANDA NUMBER(20,0),
  CANT NUMBER
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EA48EB8A80BE7F469324587DB33A27DAC98CFF4</HASHVAL>
  <TEXT>CREATE TABLE RAC_P (
  CODRAC_P NUMBER(20,0) NOT NULL,
  OBS VARCHAR2(100),
  TIP NUMBER(1,0),
  MONEDA NUMBER(20,0),
  I1 NUMBER(6,0),
  I2 NUMBER(6,0),
  I3 NUMBER(6,0),
  I4 NUMBER(6,0),
  I5 NUMBER(6,0),
  I6 NUMBER(6,0),
  VALFIXA NUMBER(20,7),
  LINIAR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_P0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C267B45B144A264EB6C848F873298D42721677B</HASHVAL>
  <TEXT>CREATE TABLE RAC_P0 (
  CODRAC_P0 NUMBER(20,0) NOT NULL,
  CODRAC_P NUMBER(20,0),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_P1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E49CC451409DB4CA263A3628EE8AA63B3FBAD655</HASHVAL>
  <TEXT>CREATE TABLE RAC_P1 (
  CODRAC_P1 NUMBER(20,0) NOT NULL,
  CODRAC_P0 NUMBER(20,0),
  CODGRUPA NUMBER(20,0),
  P1 NUMBER(20,7),
  P2 NUMBER(20,7),
  P3 NUMBER(20,7),
  P4 NUMBER(20,7),
  P5 NUMBER(20,7),
  P6 NUMBER(20,7),
  FIX NUMBER(20,7),
  GARANTIE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_REZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>589FD47AEC7F4761B370F4EF7986BAF220DC7D92</HASHVAL>
  <TEXT>CREATE TABLE RAC_REZ (
  CODRAC_REZ NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  NR_REF VARCHAR2(100),
  CODCOMISIONAR NUMBER(20,0),
  CODLOCALIT_PREL NUMBER(20,0),
  ADRESA_PREL VARCHAR2(150),
  CODLOCALIT_LIVR NUMBER(20,0),
  ADRESA_LIVR VARCHAR2(150),
  NR_ZBOR VARCHAR2(20),
  CODCONTR_PRELIVR NUMBER(20,0),
  FACTLUNARA NUMBER(1,0),
  SUMAGARANTIE NUMBER(20,7),
  CODCMDACCIDENT NUMBER(20,0),
  NUME_CARD VARCHAR2(100),
  EXPIRA_CARD DATE,
  CODCCV NUMBER(20,0),
  OBS_CONTRACT VARCHAR2(100),
  CODTIPASIG NUMBER(20,0),
  EMAIL VARCHAR2(100),
  TELEFON VARCHAR2(100),
  TIPREZERVARE NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  CODDELEGAT1 NUMBER(20,0),
  CODDELEGAT2 NUMBER(20,0),
  CODGESTSURSA NUMBER(20,0),
  CODGESTDEST NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  KMIN NUMBER(10,0),
  KMOUT NUMBER(10,0),
  COMBIN NUMBER(10,0),
  COMBOUT NUMBER(10,0),
  KMNEXTREV NUMBER(10,0),
  CODSEDIUCOMIS NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  CODMODEL NUMBER(20,0),
  CODMARCA NUMBER(20,0),
  DATAFACT DATE,
  CODPARTEXT NUMBER(20,0),
  PROCCEDAT NUMBER(5,2),
  DATAPRED DATE,
  CODVOUCHER NUMBER(20,0),
  PREDAT NUMBER(1,0),
  CODSOFER NUMBER(20,0),
  VALSOFERCM NUMBER(20,7),
  VALSOFERF NUMBER(20,7),
  VALCLIENTCM NUMBER(20,7),
  VALCLIENTF NUMBER(20,7),
  CODSOFER1 NUMBER(20,0),
  CODSOFER2 NUMBER(20,0),
  FARATVA NUMBER(1,0),
  SURSACLIENT VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAC_TRANSFER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C32274A4922C136D206B8D094B4001EE1FCD235E</HASHVAL>
  <TEXT>CREATE TABLE RAC_TRANSFER (
  CODGESTSURSA NUMBER(20,0),
  CODGESTDEST NUMBER(20,0),
  CODAUTO NUMBER,
  DATASTART DATE,
  DATASTOP DATE,
  DATAPRED DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EE2020E31145ACACBF24256B6574EAA89F88511</HASHVAL>
  <TEXT>CREATE TABLE RAPORTP (
  CODRAPORTP NUMBER(20,0) NOT NULL,
  NRDOC NUMBER(20,0),
  DATAI DATE,
  DATAS DATE,
  PE_FORMATIE NUMBER(1,0),
  SECTIE NUMBER(20,0),
  FORMATIE NUMBER(20,0),
  PROGRAMF NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  INTRERUPERI NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  SCHIMB NUMBER(1,0),
  OBS VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPORTP0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6807655072E0E771602F0B2C5F1FA2556A1FF97B</HASHVAL>
  <TEXT>CREATE TABLE RAPORTP0 (
  CODRAPORTP0 NUMBER(20,0) NOT NULL,
  CODRAPORTP NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  OBS VARCHAR2(400)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPORTP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9DEEAC55F2C15D45654EF802A5BBFAA87E25F25</HASHVAL>
  <TEXT>CREATE TABLE RAPORTP1 (
  CODRAPORTP1 NUMBER(20,0) NOT NULL,
  CODRAPORTP0 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  ANGAJAT NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  INDICE NUMBER(20,7),
  PRODREALIZAT NUMBER(20,7),
  PRODREBUT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPORTP2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FC20A738AAA74437FE532FF5B47E6FB66BE999C4</HASHVAL>
  <TEXT>CREATE TABLE RAPORTP2 (
  CODRAPORTP2 NUMBER(20,0) NOT NULL,
  CODRAPORTP1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODMAN NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  CODUTILAJ NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  REFACUT NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  OBS VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPORTP3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFD7ED5C2125A03112D131B4C1A8683DCB2A0AB6</HASHVAL>
  <TEXT>CREATE TABLE RAPORTP3 (
  CODRAPORTP3 NUMBER(20,0) NOT NULL,
  CODRAPORTP1 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  CODMOTIV NUMBER(20,0),
  ORE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RAPSTOCMEDIST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D6FFDC3409F5520510ABDC0682BAA66B2BA0354</HASHVAL>
  <TEXT>CREATE TABLE RAPSTOCMEDIST (
  CODRAPMEDIST NUMBER(20,0) NOT NULL,
  CODENTITATE VARCHAR2(20),
  CODWORKPLACE VARCHAR2(20),
  DATA DATE,
  COD NUMBER(20,0),
  MESAJ VARCHAR2(400),
  IDTRANZACTIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E05ABDB73B75B6EA44717B6B82304B71DD135824</HASHVAL>
  <TEXT>CREATE TABLE RECLAMATII (
  CODRECLAMATIE NUMBER(20,0) NOT NULL,
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODUTILIZATOR NUMBER(20,0),
  MOTIV VARCHAR2(500),
  RECLAMATIE VARCHAR2(300),
  CODPART NUMBER(20,0),
  CODDOCR NUMBER(20,0),
  TIPDOCR NUMBER(20,0),
  REZOLVAT NUMBER(1,0),
  DATAREZ DATE,
  CODRESP NUMBER(20,0),
  IMPUTABILA NUMBER(1,0),
  TIPIMPUT NUMBER(1,0),
  CODPIMPUT NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  CODLOCATIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RECLAMATII1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9FF1F02AD20B08475F1B556DBFA44A6027B05C1</HASHVAL>
  <TEXT>CREATE TABLE RECLAMATII1 (
  CODRECLAMATIE1 NUMBER(20,0) NOT NULL,
  CODRECLAMATIE NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(300),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUMS NUMBER(20,7),
  PU NUMBER(20,7),
  IMPUTABIL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RECLAMATII2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9164F9D3C245698C4F6B1C2A475599F3A4C4C292</HASHVAL>
  <TEXT>CREATE TABLE RECLAMATII2 (
  CODRECLAMATIE2 NUMBER(20,0) NOT NULL,
  CODRECLAMATIE NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REC_LIST_BALANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB8047EC0280C6ED92213CBE12214D59EB308C64</HASHVAL>
  <TEXT>CREATE TABLE REC_LIST_BALANTA (
  CODCONT NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AC672599E1C04328C47841348510F67AC14379AC</HASHVAL>
  <TEXT>CREATE TABLE REG (
  CODREG NUMBER(20,0) NOT NULL,
  TIPREG NUMBER(10,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODBANK NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(23,7),
  DIRTY NUMBER(1,0),
  OBS VARCHAR2(300),
  CODSUBUNIT NUMBER(20,0),
  PROVIZION NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CURS_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>007D8CE6B491DE23D3B14D0EC9D8B0393A649682</HASHVAL>
  <TEXT>CREATE TABLE REG1 (
  CODREG1 NUMBER(20,0) NOT NULL,
  CODREG NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CONT NUMBER(20,0),
  SEMN NUMBER(1,0),
  CURS NUMBER(23,7),
  SEMNIFICATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REGLEAS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>389F60D52B8A3F45D0391E18A6E3E9DC519D7FFD</HASHVAL>
  <TEXT>CREATE TABLE REGLEAS1 (
  CODREGLEAS1 NUMBER(20,0) NOT NULL,
  CODREG NUMBER(20,0),
  SOLDREG NUMBER(20,7),
  CODCONTRACT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>951F0DB77A680FB92DAD37865B5B68AF0B3A71B7</HASHVAL>
  <TEXT>CREATE TABLE REGOSS (
  CODREGOSS NUMBER(20,0) NOT NULL,
  TIPREG NUMBER(10,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TRIMESTRUL NUMBER(1,0),
  CODBANK NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(23,7),
  DIRTY NUMBER(1,0),
  OBS VARCHAR2(300),
  CODSUBUNIT NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CURS_IFRS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REGOSS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D4C03BD10B42E291E52FB9F56DD3B062C7435CE</HASHVAL>
  <TEXT>CREATE TABLE REGOSS1 (
  CODREGOSS1 NUMBER(20,0) NOT NULL,
  CODREGOSS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TVADOCVAL NUMBER(20,7),
  TVADOC NUMBER(20,7),
  TVADOCREG NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CONT NUMBER(20,0),
  SEMN NUMBER(1,0),
  CURS NUMBER(23,7),
  SEMNIFICATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REGPERS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC6132E970D0BDD9C9E7A2B150E611F59EB2E0BB</HASHVAL>
  <TEXT>CREATE TABLE REGPERS1 (
  CODREGPERS1 NUMBER(20,0) NOT NULL,
  CODREG NUMBER(20,0),
  SOLDDOC NUMBER(20,7),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  ICONT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REGTREZOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F69859F5076863FBF60EEABAE1C4C70DD1C402E</HASHVAL>
  <TEXT>CREATE TABLE REGTREZOR1 (
  CODREGTREZOR1 NUMBER(20,0) NOT NULL,
  CODREG NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODBANK NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTARTINACTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A31F18B4C39FE312F7C61B2A9FA2419BD888EEA</HASHVAL>
  <TEXT>CREATE TABLE RESTARTINACTIVE (
  COD NUMBER(20,0) NOT NULL,
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTAURANTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D002A9EFAAC4A9E61001328C4C26BD5D3232AB4</HASHVAL>
  <TEXT>CREATE TABLE RESTAURANTE (
  CODRESTAURANT NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  SUBUNITATEA NUMBER(20,0),
  TIPORAR NUMBER(1,0),
  ORASTART TIMESTAMP(6),
  ORAEND TIMESTAMP(6),
  TIPUNICITATE NUMBER(1,0),
  TIPGESTIMPLICITA NUMBER(1,0),
  POSTWMRETAIL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTCLASE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>333CE163CB57E029C56177F428A0E0649DE65D2D</HASHVAL>
  <TEXT>CREATE TABLE RESTCLASE (
  COD NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTCMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>36DE36F86155DD772772991813614F6208361E7B</HASHVAL>
  <TEXT>CREATE TABLE RESTCMD (
  CODRESTCMD NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  CODMASA NUMBER(20,0),
  CODOSPATAR NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DESCHIDERE TIMESTAMP(6),
  INCHIDERE TIMESTAMP(6),
  INCHISA NUMBER(1,0),
  OBS VARCHAR2(100),
  NRPERS NUMBER(5,0),
  DIMINUAT NUMBER(1,0),
  ADRESALIVRARE VARCHAR2(400)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTCMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A8BF50DC07B2F5759FC84DA3EE3D9B8F148F720</HASHVAL>
  <TEXT>CREATE TABLE RESTCMD1 (
  CODRESTCMD1 NUMBER(20,0),
  CODRESTCMD NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODGEST NUMBER(20,0),
  LISTAREGEST NUMBER(1,0),
  FARALISTARE NUMBER(1,0),
  TIPUM NUMBER(1,0),
  CANTARIT NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  ORDINE NUMBER(3,0),
  TAXA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTGESTIMPLICITE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8819E8BB52D0CA60282016C34481C446A665F152</HASHVAL>
  <TEXT>CREATE TABLE RESTGESTIMPLICITE (
  COD NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTGESTLISTVER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3B498543C3B926DC13A9675F39C2B7EF3EBB41D</HASHVAL>
  <TEXT>CREATE TABLE RESTGESTLISTVER (
  COD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  LISTVER NUMBER(20,0),
  FARALISTARE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTLISTGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE6DF8F5E51AA79DF0026EDC178DD2838A137A73</HASHVAL>
  <TEXT>CREATE TABLE RESTLISTGEST (
  CODRESTLISTGEST NUMBER(20,0),
  CODRESTCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(250),
  DATAORA TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTNP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD14D88D099C8487FCB49CAA154E10AAB19B98B7</HASHVAL>
  <TEXT>CREATE TABLE RESTNP (
  CODRESTNP NUMBER(20,0),
  CODRESTCMD NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  CODPART NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALDISC NUMBER(20,7),
  PROTOCOL NUMBER(1,0),
  LISTATCM NUMBER(1,0),
  DATACREARE TIMESTAMP(6),
  TIPCASAMARCAT NUMBER(10,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTURARE NUMBER(1,0),
  LISTAT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  VALMARTOR_CMD NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTNP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45E603096F127C8043CFA06F8DB0A89EF9AE112E</HASHVAL>
  <TEXT>CREATE TABLE RESTNP1 (
  CODRESTNP1 NUMBER(20,0),
  CODRESTNP NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  DISCMANUAL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTNP2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>00CE017ED782BDB11ED1616AA0DF4569A7321893</HASHVAL>
  <TEXT>CREATE TABLE RESTNP2 (
  CODRESTNP2 NUMBER(20,0),
  CODRESTNP NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FDE6C1FDE1C3B39F1333EA906166D5155AA6E2AB</HASHVAL>
  <TEXT>CREATE TABLE RESTOBIECT (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  CODSALA NUMBER(20,0),
  X NUMBER(20,0),
  Y NUMBER(20,0),
  WIDTH NUMBER(20,0),
  HEIGHT NUMBER(20,0),
  COLOR NUMBER(20,0),
  TEXTAFISARE VARCHAR2(100),
  FORMA NUMBER(1,0),
  POZA BLOB,
  IS3D NUMBER(1,0),
  NIVEL NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTOBSART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25E60BD2C8010264529BD2D5899E23B119AD74F1</HASHVAL>
  <TEXT>CREATE TABLE RESTOBSART (
  COD NUMBER(20,0) NOT NULL,
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RESTRAPORTZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBB042FB757732AA7093ACBC8EEC54D067545960</HASHVAL>
  <TEXT>CREATE TABLE RESTRAPORTZ (
  COD NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RETURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A941D9BE75FDDBDC4839A1A1785023807BCC18C7</HASHVAL>
  <TEXT>CREATE TABLE RETURO (
  CODRETURO NUMBER(20,0) NOT NULL,
  SESSIONID VARCHAR2(100),
  STARTEDAT TIMESTAMP(6),
  REFUND NUMBER(20,7),
  VOUCHERBARCODE VARCHAR2(100),
  RVM_SERIALNUMBER VARCHAR2(100),
  RVM_TYPE VARCHAR2(100),
  LOCATION_CUSTOMERID VARCHAR2(100),
  LOCATION_NAME VARCHAR2(100),
  IS_USED NUMBER(1,0),
  USED_DATE TIMESTAMP(6),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  UPLOAD_DATE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RETUROSTINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>964AB219F3AAA8974C42AE659DB15DE9CA328246</HASHVAL>
  <TEXT>CREATE TABLE RETUROSTINS (
  CODRETUROSTINS NUMBER(20,0) NOT NULL,
  CODRETURO NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  STARTEDAT TIMESTAMP(6),
  VOUCHERBARCODE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REZERVATS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F6F70DA2E667B251E874E22183046B06250AE71</HASHVAL>
  <TEXT>CREATE TABLE REZERVATS (
  CODREZERVATS NUMBER(20,0) NOT NULL,
  CODCOMANDA1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  REST NUMBER(30,17),
  UMSEC NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  REZERVATINI NUMBER(30,17),
  CODOBIECT NUMBER(20,0),
  CODCOMANDA1F NUMBER(20,0),
  CODINVENTAR1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>REZERVATS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5E6BC591FDB9D55BD5C390A39162C1D10183F29</HASHVAL>
  <TEXT>CREATE TABLE REZERVATS1 (
  CODREZERVATS1 NUMBER(20,0),
  CODREZERVATS NUMBER(20,0),
  CODPART NUMBER(20,0),
  CANT NUMBER(30,17),
  UMSEC NUMBER(20,0),
  TERMEN DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>RF_CTC_AUXCOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>341040A24096F69760DFAF799CF71681065302F9</HASHVAL>
  <TEXT>CREATE TABLE RF_CTC_AUXCOD (
  COD NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SABLONDESCRIPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>702B195D2A051CA58915846FEDAA95FCF8F964DB</HASHVAL>
  <TEXT>CREATE TABLE SABLONDESCRIPT (
  CODSABLON NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  SIMBOL VARCHAR2(50),
  CODDESCRIPTOR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SABLONDESCRIPT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A8104F16E4BFCFC627F20C42A4218ADCABE4A0D5</HASHVAL>
  <TEXT>CREATE TABLE SABLONDESCRIPT1 (
  CODSABLON1 NUMBER(20,0) NOT NULL,
  CODSABLON NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SABLONNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6F27827828E9E068D1BF6F995259CB989F471990</HASHVAL>
  <TEXT>CREATE TABLE SABLONNC (
  TIPDOC NUMBER(2,0),
  INDEXLOCAL NUMBER(2,0),
  D VARCHAR2(10),
  C VARCHAR2(10),
  OBS VARCHAR2(200),
  NRNOTA NUMBER(20,0),
  NUMENOTA VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SABLONNOTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7155189CA45C55521CC264211BD9F91243201BF8</HASHVAL>
  <TEXT>CREATE TABLE SABLONNOTE (
  TIPDOC NUMBER(5,0),
  SIMBOLD VARCHAR2(50),
  SIMBOLC VARCHAR2(50),
  CODNOTA NUMBER(2,0),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAFTCOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD9007B852F3FDCD0FA063E762306997D98501AF</HASHVAL>
  <TEXT>CREATE TABLE SAFTCOL (
  CODSAFTTAB NUMBER(20,0) NOT NULL,
  IDXLOCAL NUMBER(5,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  TIP VARCHAR2(100),
  SURSA VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAFTTAB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41521DF458B2C6523187DCF47F0D69A6BFDDABE9</HASHVAL>
  <TEXT>CREATE TABLE SAFTTAB (
  CODSAFTTAB NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  SURSA VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAFTTIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9948C01A4F96196FFE80B92DB6B4B1725A6D3F71</HASHVAL>
  <TEXT>CREATE TABLE SAFTTIP (
  DENUMIRE VARCHAR2(100),
  DELPHITIP VARCHAR2(100),
  DELPHILEN NUMBER(3,0),
  ORACLETIP VARCHAR2(100),
  STRFORMAT VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAFT_INFO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75961F72B22E548CC9B3B6B8D1AE0A228A7BDA57</HASHVAL>
  <TEXT>CREATE TABLE SAFT_INFO (
  INFOTIME TIMESTAMP(6),
  INFOLINE VARCHAR2(200),
  DETALII CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAFT_RESET_SEQ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33B4EF0513E53997C875C5C8B879B9375E0D9656</HASHVAL>
  <TEXT>CREATE TABLE SAFT_RESET_SEQ (
  APEL_TIMESTAMP TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SALI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>459D6DA30C83371B743FD9F39866077CFC9972AA</HASHVAL>
  <TEXT>CREATE TABLE SALI (
  CODSALA NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  CODPERS NUMBER(20,0),
  NUMARMESE NUMBER(5,0),
  CODRESTAURANT NUMBER(20,0),
  CODCATPRET NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SALIUSERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>08BA82598920450D85544A4DF6FC5E10C298318E</HASHVAL>
  <TEXT>CREATE TABLE SALIUSERI (
  COD NUMBER(20,0),
  CODSALA NUMBER(20,0),
  USERNAME VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_CATRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A42FA55A449FED48F838C211C6848ADFC4D7528E</HASHVAL>
  <TEXT>CREATE TABLE SAL_CATRET (
  CODCATRET NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_CATSPOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2E94C88517BC1161D5713C81719B8D211252D2A</HASHVAL>
  <TEXT>CREATE TABLE SAL_CATSPOR (
  CODCATSPOR NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_CONTRPP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C43D73414DF9D22E5EACA9E9B654573DC09F00E</HASHVAL>
  <TEXT>CREATE TABLE SAL_CONTRPP (
  CODCONTRPP NUMBER(20,0) NOT NULL,
  SUCURSALA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_CONTRPP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>605F5B9F9AD193CC78BE33B1D4D6C1962A9806D7</HASHVAL>
  <TEXT>CREATE TABLE SAL_CONTRPP1 (
  CODCONTRPP1 NUMBER(2,0) NOT NULL,
  CODCONTRPP NUMBER(2,0),
  ANGAJAT NUMBER(20,0),
  NRCONTRACT VARCHAR2(15),
  DATASTART DATE,
  DATASTOP DATE,
  FOND NUMBER(2,0),
  PLATAFIRMA NUMBER(1,0),
  CONTBANCAR VARCHAR2(30),
  MODPLATA NUMBER(2,0),
  RATA NUMBER(2,0),
  ZIPLATA NUMBER(2,0),
  DATAINREG DATE,
  PLAFONLEI NUMBER(2,0),
  PLAFONEURO NUMBER(2,0),
  DIFERENTE NUMBER(2,0),
  VALRATEAN NUMBER(2,0),
  RETNEIMPOZ NUMBER(2,0),
  RETIMPOZ NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_DEDGEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F978EB98B23A691117DDDA2CFACF7CED198CCDE0</HASHVAL>
  <TEXT>CREATE TABLE SAL_DEDGEN (
  CODDEDGEN NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  BAZA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_DEDGEN0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>884CF1549A62F9E92DBA837971CDA290681EE75B</HASHVAL>
  <TEXT>CREATE TABLE SAL_DEDGEN0 (
  CODDEDGEN0 NUMBER(20,0) NOT NULL,
  CODDEDGEN NUMBER(20,0),
  CONTRACT NUMBER(1,0),
  CONVENTIE NUMBER(1,0),
  CONVENTIECM NUMBER(1,0),
  CUMULS NUMBER(1,0),
  CUMULP NUMBER(1,0),
  SPECIAL NUMBER(1,0),
  SPECIALCV NUMBER(1,0),
  ASIMILATE NUMBER(1,0),
  CALCUL NUMBER(2,0),
  MARIME NUMBER(20,7),
  ROT NUMBER(20,7),
  MODROT NUMBER(2,0),
  COOP NUMBER(1,0),
  INTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_DEDGEN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>184B5B803863E3D4DB3D67EA624F3D32133AA57B</HASHVAL>
  <TEXT>CREATE TABLE SAL_DEDGEN1 (
  CODDEDGEN1 NUMBER(20,0) NOT NULL,
  CODDEDGEN0 NUMBER(20,0),
  CODDEDGEN NUMBER(20,0),
  PERS NUMBER(2,0),
  LIMSUP NUMBER(20,7),
  LIMINF NUMBER(20,7),
  RELATIE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_FONDP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56E6EADEB4D313E18D5564EF3C9D8F220623B2EC</HASHVAL>
  <TEXT>CREATE TABLE SAL_FONDP (
  CODFONDP NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_IMPOZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA93B0F6525AC5ABC8455509485F2EA4066DA68F</HASHVAL>
  <TEXT>CREATE TABLE SAL_IMPOZ (
  CODIMPOZ NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  LUNAR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_IMPOZ0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FB92BD4B397314F02C25EAC07D3846E2C897F5C</HASHVAL>
  <TEXT>CREATE TABLE SAL_IMPOZ0 (
  CODIMPOZ0 NUMBER(20,0) NOT NULL,
  CODIMPOZ NUMBER(20,0),
  LACONTR NUMBER(1,0),
  LACONV NUMBER(1,0),
  LACONVCM NUMBER(1,0),
  LACUMULSAL NUMBER(1,0),
  LACUMULPENS NUMBER(1,0),
  LASPECIAL NUMBER(1,0),
  LASPECIALCV NUMBER(1,0),
  LAASIMILATE NUMBER(1,0),
  ROT NUMBER(20,0),
  TRUNCHIERE NUMBER(1,0),
  COOP NUMBER(1,0),
  INTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_IMPOZ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB587574D232D4EF900C19000FC63E19ADDDA2A7</HASHVAL>
  <TEXT>CREATE TABLE SAL_IMPOZ1 (
  CODIMPOZ1 NUMBER(20,0) NOT NULL,
  CODIMPOZ0 NUMBER(20,0),
  CODIMPOZ NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  VALFIXA NUMBER(20,7),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_INTRERUP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB46AC9C2A985BCEAD244C7865739F4F70014F62</HASHVAL>
  <TEXT>CREATE TABLE SAL_INTRERUP (
  CODINTRERUP NUMBER(20,0) NOT NULL,
  SIMBOL VARCHAR2(3),
  DENUMIRE VARCHAR2(30),
  VECHTOT NUMBER(1,0),
  VECHFIRMA NUMBER(1,0),
  MODCALCUL NUMBER(6,0),
  ASIGSOC NUMBER(1,0),
  IN_SPOR NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NASIG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6957A58D6302D4178858795C853DC3F25FB872C5</HASHVAL>
  <TEXT>CREATE TABLE SAL_NASIG (
  CODNASIG NUMBER(20,0) NOT NULL,
  TIP VARCHAR2(50),
  CODASIG NUMBER(20,0),
  CARACTER NUMBER(2,0),
  INTRERUPERE NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NASIG0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3165FD66955F98E61597BE2DCB81F0C77FC35C01</HASHVAL>
  <TEXT>CREATE TABLE SAL_NASIG0 (
  CODNASIG0 NUMBER(20,0) NOT NULL,
  CODNASIG NUMBER(20,0),
  BAZACALCUL NUMBER(6,0),
  ANGAJATOR NUMBER(1,0),
  CONT1 NUMBER(20,0),
  ASIGURARE NUMBER(1,0),
  CONT2 NUMBER(20,0),
  CONTRIBSALMINECFIRMA NUMBER(6,0),
  CONTRIBSALMINECCAS NUMBER(6,0),
  PENALIZARE NUMBER(20,7),
  IMPOZIT NUMBER(1,0),
  CRESTERECOPIL NUMBER(1,0),
  SUSPENDARECM NUMBER(1,0),
  BUGET NUMBER(6,0),
  NOANGAJAT NUMBER(1,0),
  NOANGAJATOR NUMBER(1,0),
  ZILEPLATAFIRMA NUMBER(6,0),
  NEAVIZATCAS NUMBER(1,0),
  PLAFONARE NUMBER(6,0),
  NODEDUCERE NUMBER(1,0),
  CONSTRUCTII NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NASIG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FA1280B108CC3DECAB32D79FEBE119C76FFC7958</HASHVAL>
  <TEXT>CREATE TABLE SAL_NASIG1 (
  CODNASIG1 NUMBER(20,0) NOT NULL,
  CODNASIG0 NUMBER(20,0),
  MODCALCUL NUMBER(2,0),
  CONDITIONARE NUMBER(2,0),
  UMV NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NASIG2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A429D9B638FB73559EF4A58596F781967768E2E</HASHVAL>
  <TEXT>CREATE TABLE SAL_NASIG2 (
  CODNASIG2 NUMBER(20,0) NOT NULL,
  CODNASIG0 NUMBER(20,0),
  CODNASIG1 NUMBER(20,0),
  CUANTUM NUMBER(20,7),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NASIG3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20E58C8467E9A71E9D16E2402ED1A37062A0E608</HASHVAL>
  <TEXT>CREATE TABLE SAL_NASIG3 (
  CODNASIG3 NUMBER(20,0) NOT NULL,
  CODNASIG0 NUMBER(20,0),
  TIP NUMBER(2,0),
  ELEMCALCUL NUMBER(2,0),
  MULTIPLICARE NUMBER(20,7),
  CODCONT NUMBER(20,0),
  CONTRIBUTIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NBAZACAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E323F597C98E7286604CA2F77F106A956C119C24</HASHVAL>
  <TEXT>CREATE TABLE SAL_NBAZACAL (
  CODNBAZACAL NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NCONDAS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8E56F0BC971F6E8969EE46B1F7CEAA8CB9E5708</HASHVAL>
  <TEXT>CREATE TABLE SAL_NCONDAS (
  CODNCONDAS NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NCONTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6705D205D48C1C456EB2F5BBA4EEC2B2B3B8D0C4</HASHVAL>
  <TEXT>CREATE TABLE SAL_NCONTRIB (
  CODNCONTRIB NUMBER(20,0) NOT NULL,
  TIP NUMBER(2,0),
  DENUMIRE VARCHAR2(30),
  TIPCONTRIBUTIE NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NCONTRIB1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EFC2A6C783E746309867142801872B21444A2AF</HASHVAL>
  <TEXT>CREATE TABLE SAL_NCONTRIB1 (
  CODNCONTRIB1 NUMBER(20,0) NOT NULL,
  CODNCONTRIB NUMBER(20,0),
  MARIME NUMBER(20,7),
  MODCALCUL NUMBER(2,0),
  IMPOZITATCTR NUMBER(1,0),
  CODCONT NUMBER(20,0),
  CODCONTCHELT NUMBER(20,0),
  CODCONTCAS NUMBER(20,0),
  CODCONTAMBP NUMBER(20,0),
  LACONTR NUMBER(1,0),
  LACONV NUMBER(1,0),
  LACONVCM NUMBER(1,0),
  LACUMULSAL NUMBER(1,0),
  LACUMULPENS NUMBER(1,0),
  LAPARTSAL NUMBER(1,0),
  LAPREAVIZ NUMBER(1,0),
  LASPECIAL NUMBER(1,0),
  LASPECIALCV NUMBER(1,0),
  LAASIMILATE NUMBER(1,0),
  GRUPA1 NUMBER(1,0),
  GRUPA2 NUMBER(1,0),
  GRUPA3 NUMBER(1,0),
  GRUPA4 NUMBER(1,0),
  SPECIALCB NUMBER(1,0),
  IMPOZITATCV NUMBER(1,0),
  IMPOZITATCVCM NUMBER(1,0),
  IMPOZITATCS NUMBER(1,0),
  IMPOZITATCP NUMBER(1,0),
  IMPOZITATSPEC NUMBER(1,0),
  IMPOZITATSPECCV NUMBER(1,0),
  IMPOZITATAS NUMBER(1,0),
  VARSTAMIN NUMBER(2,0),
  VENITMIN NUMBER(20,7),
  VENITMAX NUMBER(20,7),
  TIPCONTRACTUAL NUMBER(2,0),
  BUGET NUMBER(2,0),
  TIPLIMITARE NUMBER(2,0),
  REFERINTA NUMBER(2,0),
  MULTIPLIC NUMBER(20,7),
  CONSTRUCTII NUMBER(1,0),
  LACOOP NUMBER(1,0),
  LAINTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NDREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CB3F06BE925FE65BFCB2923F0A751D4947553A0</HASHVAL>
  <TEXT>CREATE TABLE SAL_NDREP (
  CODNDREP NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50),
  TIP NUMBER(2,0),
  MODCALC NUMBER(2,0),
  DATAADAUG DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NDREP0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>787E381114AFB398B063EC3F4426261D594ECC45</HASHVAL>
  <TEXT>CREATE TABLE SAL_NDREP0 (
  CODNDREP0 NUMBER(20,0) NOT NULL,
  CODNDREP NUMBER(20,0),
  ART NUMBER(20,0),
  MARIME NUMBER(20,7),
  IMPOZIT NUMBER(1,0),
  DEDUCERI NUMBER(1,0),
  TVA NUMBER(1,0),
  ZIUA NUMBER(20,0),
  GEST NUMBER(20,0),
  CODCONT NUMBER(20,0),
  TOTALCANT NUMBER(20,7),
  TOTALVAL NUMBER(20,7),
  TOTALCUTVA NUMBER(20,7),
  TICHETMASA NUMBER(1,0),
  CODDOC NUMBER(20,0),
  ALTEDEDUCERI NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NDREP1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C19048FFA49600D1340DA215796CD5592434C5AD</HASHVAL>
  <TEXT>CREATE TABLE SAL_NDREP1 (
  CODNDREP1 NUMBER(20,0) NOT NULL,
  CODNDREP0 NUMBER(20,0),
  CODNDREP NUMBER(20,0),
  CONTRIB NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_NMODC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F79B37599CCFF738C8540B2ED470C8A04D375C53</HASHVAL>
  <TEXT>CREATE TABLE SAL_NMODC (
  CODMODC NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_RA21</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD70D923776C50494837A96BCE23E00E16C33C93</HASHVAL>
  <TEXT>CREATE TABLE SAL_RA21 (
  COD NUMBER(6,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  CODSPOR VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_RA24</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E112C6DE9DCDC9C4E3B73076C8E864C02EB3D16C</HASHVAL>
  <TEXT>CREATE TABLE SAL_RA24 (
  COD NUMBER(6,0) NOT NULL,
  DENUMIRE VARCHAR2(36),
  CODTIPSP VARCHAR2(17)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_RETINERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2860198D60F4F2587314AEF0DD81A6D2D2E17EFF</HASHVAL>
  <TEXT>CREATE TABLE SAL_RETINERI (
  CODRETINERE NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  CODCATRET NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_RETINERI0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1C7AF5438559863622E433E1B6052E7F41B145FE</HASHVAL>
  <TEXT>CREATE TABLE SAL_RETINERI0 (
  CODRETINERE0 NUMBER(20,0) NOT NULL,
  CODRETINERE NUMBER(20,0),
  MARIME NUMBER(20,7),
  MODCALCUL NUMBER(2,0),
  CARACTER NUMBER(2,0),
  CONT NUMBER(2,0),
  TERT NUMBER(20,0),
  NEIMPOZ NUMBER(1,0),
  NRCONTR VARCHAR2(15),
  DATACONTR DATE,
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_SPORURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E607701090D7E9428632D343F91DD308419E267E</HASHVAL>
  <TEXT>CREATE TABLE SAL_SPORURI (
  CODSPOR NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7),
  CODCATSPOR NUMBER(20,0),
  SALBAZA NUMBER(1,0),
  NIVELSALBAZA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_SPORURI0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>585987D94C6E278B25821CE451E1BB10280C3F08</HASHVAL>
  <TEXT>CREATE TABLE SAL_SPORURI0 (
  CODSPOR0 NUMBER(20,0) NOT NULL,
  CODSPOR NUMBER(20,0),
  TIP NUMBER(2,0),
  TIPTRANSA NUMBER(2,0),
  TIPCALCSPOR NUMBER(2,0),
  ZILENEMO NUMBER(3,0),
  VALOARE NUMBER(20,7),
  BUGET NUMBER(2,0),
  ITMTIP NUMBER(6,0),
  ITMSPOR NUMBER(6,0),
  TARIFARREFL NUMBER(1,0),
  INTRS VARCHAR2(50),
  INTRC VARCHAR2(50),
  INTRSNS VARCHAR2(50),
  INTRSNC VARCHAR2(50),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_SPORURI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4FA8B656E9C95D921742C4571C1E0C2C7B7165ED</HASHVAL>
  <TEXT>CREATE TABLE SAL_SPORURI1 (
  CODSPOR1 NUMBER(20,0) NOT NULL,
  CODSPOR NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  VALSPOR NUMBER(20,7),
  CODSPOR0 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SAL_SPORURI2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D701103A230AFC122593FB20A14670BA95C0F05</HASHVAL>
  <TEXT>CREATE TABLE SAL_SPORURI2 (
  CODSPOR2 NUMBER(20,0) NOT NULL,
  CODSPOR NUMBER(20,0),
  CODSPOREXCLUS NUMBER(20,0),
  CODSPOR0 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SCENARIILIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81CB184B88CC2076D13417C173CDF6EABAF1D8FD</HASHVAL>
  <TEXT>CREATE TABLE SCENARIILIVR (
  CODSCENARIU NUMBER(20,0) NOT NULL,
  DEN_SCENARIU VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  TIP NUMBER(1,0),
  OBS VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DEFINITIV NUMBER(1,0),
  DSTART DATE,
  DEND DATE,
  TIPDATA NUMBER(1,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SCENARIILIVR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5D32785B559CD359E2F54F002F0169F6DCFC765</HASHVAL>
  <TEXT>CREATE TABLE SCENARIILIVR1 (
  CODSCENARIU1 NUMBER(20,0) NOT NULL,
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CANT NUMBER(30,17),
  LANS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SCENARIILIVR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D7FF60E346B53CA976666EA459007C30E36E781</HASHVAL>
  <TEXT>CREATE TABLE SCENARIILIVR2 (
  CODSCENARIU2 NUMBER(20,0) NOT NULL,
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  DATASTART DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERIICMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>07E7EF6DEC537A078365EA317A9A1F897FC118D7</HASHVAL>
  <TEXT>CREATE TABLE SERIICMD (
  CODSERIECMD NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  DATAEXP VARCHAR2(10),
  RASPUNS VARCHAR2(500),
  STATUS VARCHAR2(50),
  DATAVERIF DATE,
  GTIN VARCHAR2(100),
  CODRASPUNS VARCHAR2(50),
  SCHEMETYPE VARCHAR2(10),
  GLN VARCHAR2(50),
  USERID NUMBER(20,0),
  MOTIV VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERIIIES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2027D5068B71FB815653672250C9C4E229B71F6</HASHVAL>
  <TEXT>CREATE TABLE SERIIIES (
  CODSERIEIES NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  DATAEXP VARCHAR2(10),
  RASPUNS VARCHAR2(500),
  STATUS VARCHAR2(50),
  DATAVERIF DATE,
  GTIN VARCHAR2(100),
  CODRASPUNS VARCHAR2(50),
  SCHEMETYPE VARCHAR2(10),
  GLN VARCHAR2(50),
  USERID NUMBER(20,0),
  MOTIV VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERIIINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7EAAC45E5A27632F95F7BC386657774489702EAF</HASHVAL>
  <TEXT>CREATE TABLE SERIIINTR (
  CODSERIEINTR NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  DATAEXP VARCHAR2(10),
  RASPUNS VARCHAR2(500),
  STATUS VARCHAR2(50),
  DATAVERIF DATE,
  GTIN VARCHAR2(100),
  CODRASPUNS VARCHAR2(50),
  SCHEMETYPE VARCHAR2(10),
  GLN VARCHAR2(50),
  USERID NUMBER(20,0),
  MOTIV VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERIITRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E335B984F20EFD4073A92AF208D3B3CED627AA5</HASHVAL>
  <TEXT>CREATE TABLE SERIITRANSF (
  CODSERIETRANSF NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  DATAEXP VARCHAR2(10),
  RASPUNS VARCHAR2(500),
  STATUS VARCHAR2(50),
  DATAVERIF DATE,
  GTIN VARCHAR2(100),
  CODRASPUNS VARCHAR2(50),
  SCHEMETYPE VARCHAR2(10),
  GLN VARCHAR2(50),
  USERID NUMBER(20,0),
  MOTIV VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERVFACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E345A49015F04D132A99BC67120D18836CF26F3</HASHVAL>
  <TEXT>CREATE TABLE SERVFACT (
  CODSERVFACT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODOBIECT NUMBER(20,0),
  MODCALCUL NUMBER(5,0),
  SUMAPORNIREKM NUMBER(20,7),
  SUMAPORNIRECANT NUMBER(20,7),
  PROCPORNIREKM NUMBER(20,7),
  PROCPORNIRECANT NUMBER(20,7),
  COD VARCHAR2(10)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERVFACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2A2047C884FD1BDA5E9D467DCC00CECEE6CA883</HASHVAL>
  <TEXT>CREATE TABLE SERVFACT1 (
  CODSERVFACT1 NUMBER(20,0),
  CODSERVFACT NUMBER(20,0),
  PANALA NUMBER(20,7),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SERVPOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AF5B48CE65C08A60F54C46CD8130CDAD2F1101CC</HASHVAL>
  <TEXT>CREATE TABLE SERVPOST (
  CODSERVICIU NUMBER(20,0) NOT NULL,
  DENSERVICIU VARCHAR2(160),
  CODOBIECT NUMBER(20,0),
  TARIF NUMBER(20,4)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SETTASK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9440122E100B65E3237EE70500F65BB3CED1A3AE</HASHVAL>
  <TEXT>CREATE TABLE SETTASK (
  CODTASK NUMBER(20,0) NOT NULL,
  PROBLEMA VARCHAR2(4000),
  DESTINATAR VARCHAR2(30),
  EXECUTANT VARCHAR2(30),
  USERNAME VARCHAR2(30),
  TERMEN DATE,
  DATATASK DATE,
  DATAREZ DATE,
  DOMENIU VARCHAR2(50),
  TIP VARCHAR2(50),
  REZOLVARE VARCHAR2(4000),
  OBSERVATII VARCHAR2(4000),
  PRIORITATE NUMBER(6,0),
  DONE NUMBER(1,0),
  MODIFICAT NUMBER(1,0),
  MESAJCATRE VARCHAR2(30),
  STERS NUMBER(1,0),
  PROIECT VARCHAR2(50),
  DOMSG NUMBER(1,0),
  CODMSG1 NUMBER(20,0),
  DOMAIL NUMBER(1,0),
  CODMAIL NUMBER(20,0),
  ZBEFORE NUMBER(2,0),
  CODFIRMA NUMBER(20,0),
  CODPART NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  FACTURAT NUMBER(1,0),
  VALOARE NUMBER(20,2),
  CODMONEDA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODFACTURA NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODSERVICIU NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VERSIUNE NUMBER(7,3),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  ARTICOLASOCIAT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SETTASKLOG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DA27E7D00B0E4A562564BD4E1D857A93F14BD56</HASHVAL>
  <TEXT>CREATE TABLE SETTASKLOG (
  CODLOG NUMBER(20,0),
  CODTASK NUMBER(20,0),
  DATA DATE,
  USER_SRC VARCHAR2(30),
  USER_DST VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SETTASKOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE174F11DD4E963FA4D623CB7296A1EAB4E13BF7</HASHVAL>
  <TEXT>CREATE TABLE SETTASKOBJ (
  CODTASKOBJ NUMBER(20,0) NOT NULL,
  CODTASK NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NEPRELUABIL NUMBER(1,0),
  PRET NUMBER(20,7),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SETTASKOBJASOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A3A3FC1C813167CA9312DA0F21ED254A497DE9FB</HASHVAL>
  <TEXT>CREATE TABLE SETTASKOBJASOC (
  CODTASKOBJASOC NUMBER(20,0) NOT NULL,
  CODTASK NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  SERII VARCHAR2(2500),
  CODINTERN VARCHAR2(250),
  CODIES1 NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SGRCOLECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB8A4C43296843ECC2D3A4AA16E68C9DE96FFD5A</HASHVAL>
  <TEXT>CREATE TABLE SGRCOLECT (
  CODSGRCOLECT NUMBER(20,0) NOT NULL,
  DATA DATE,
  VALOARE NUMBER(20,7),
  DATACREARE TIMESTAMP(6),
  CODMARIRE NUMBER(20,0),
  VOUCHERBARCODE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SGRCOLECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD482AD1244BA3B7EDCD04745727C20321F59039</HASHVAL>
  <TEXT>CREATE TABLE SGRCOLECT1 (
  CODSGRCOLECT1 NUMBER(20,0) NOT NULL,
  CODSGRCOLECT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(10,2),
  CANT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SINTEZAEMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42546883AB576B1B4D2128BA6373C699982F8BD8</HASHVAL>
  <TEXT>CREATE TABLE SINTEZAEMULARE (
  CODSINTEZA NUMBER(20,0),
  CODEMULARE NUMBER(20,0) NOT NULL,
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  IDBON NUMBER,
  DELEGAT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SINTEZAEMULARE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD30BDE17791ACA863071C3F0D56D45D8AE9628D</HASHVAL>
  <TEXT>CREATE TABLE SINTEZAEMULARE1 (
  CODSINTEZA1 NUMBER(20,0),
  CODSINTEZA NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  CONTSERV NUMBER(20,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SINTEZAEMULARE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>056D2F27CBC1E8CB9C540ACE6DE118DA92855921</HASHVAL>
  <TEXT>CREATE TABLE SINTEZAEMULARE2 (
  CODSINTEZA2 NUMBER(20,0),
  CODSINTEZA NUMBER(20,0),
  CODEMULARE2 NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODBANKCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7DAE6331B50A03F9FEFC24CF3684B5C05B2F6722</HASHVAL>
  <TEXT>CREATE TABLE SITFIN (
  CODSITFIN NUMBER(20,0) NOT NULL,
  CODF VARCHAR2(10),
  DENUMIRE VARCHAR2(100),
  SECTIUNE VARCHAR2(50),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIP NUMBER(1,0),
  TIPPLAN NUMBER(1,0),
  PELUNI NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SITFINALTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECAF61491A8A1DD394C58F4B9991D2C8EC8A078C</HASHVAL>
  <TEXT>CREATE TABLE SITFINALTE (
  CODALTE NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  FUNCTIE VARCHAR2(250),
  RAND NUMBER(10,0),
  COLOANA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SITFINBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>667A9739F75D8F8E1C407DF72DC247BC0154F02D</HASHVAL>
  <TEXT>CREATE TABLE SITFINBUGET (
  CODSITFINBUGET NUMBER(20,0) NOT NULL,
  CODSITFINLIN NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SITFINCOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28D75402FAD02DE76FAFBA905ABCFB4A29968E5C</HASHVAL>
  <TEXT>CREATE TABLE SITFINCOL (
  CODCOLOANA NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  NRCOL NUMBER(10,0),
  DENUMIRE VARCHAR2(100),
  TIPCOL NUMBER(5,0),
  CORELATIE VARCHAR2(100),
  IDENTIFICATORCOL VARCHAR2(10),
  FLGEXPORT NUMBER(1,0),
  CONTA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SITFINLIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C42BD15F82AB586A3D7BBE7B612473C54A46100</HASHVAL>
  <TEXT>CREATE TABLE SITFINLIN (
  CODLINIE NUMBER(20,0) NOT NULL,
  CODSITFIN NUMBER(20,0),
  NRLINIE NUMBER(10,0),
  DENUMIRE VARCHAR2(250),
  TOTAL NUMBER(1,0),
  CORELATIE VARCHAR2(1500),
  RND NUMBER(10,0),
  TIPCONTA NUMBER(5,0),
  OBS VARCHAR2(250),
  VALSUPLIM NUMBER(20,7),
  FARANEGATIVE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SKEMEBI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31AEA02DD239F1B992C0BFBDEEDAB09926D73F14</HASHVAL>
  <TEXT>CREATE TABLE SKEMEBI (
  SKEMA VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SMSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6D66BE4EDB63D5F313A427D0F3238031910B8ED7</HASHVAL>
  <TEXT>CREATE TABLE SMSURI (
  CODSMS NUMBER(20,0) NOT NULL,
  DATA DATE,
  USERID NUMBER(20,0),
  TELEFON VARCHAR2(20),
  MESAJ VARCHAR2(1000),
  EROARE VARCHAR2(50),
  CODDOC1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  STATUS NUMBER(1,0),
  NUME VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AE76EACE7473C25825DB23B32BDF8DB10E3736D5</HASHVAL>
  <TEXT>CREATE TABLE SOLDCASHFLOW (
  CODSOLD NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  SOLD NUMBER(20,7),
  SOLDCONV NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>72D56C653911CCC987E80F93EBDC787F7F38E57A</HASHVAL>
  <TEXT>CREATE TABLE SOLDINI (
  CODSOLDINI NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0BE86297A5FF3577934D711ADCB061585B217648</HASHVAL>
  <TEXT>CREATE TABLE SOLDPART (
  CODSOLDPART NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDPARTLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E5DF1B07C6D50AD7CAA8B0F5E415276506B7329</HASHVAL>
  <TEXT>CREATE TABLE SOLDPARTLUNA (
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDPERSINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9BD40D755E6C1CF98BDFA32B1EB826505A8613DB</HASHVAL>
  <TEXT>CREATE TABLE SOLDPERSINI (
  CODSOLDPERSINI NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SOLDPERSLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3FB5F5A0BE415395FAEB6D87C33DD9AA1FE5DDBB</HASHVAL>
  <TEXT>CREATE TABLE SOLDPERSLUNA (
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SPLITCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A154ED73B1C620329713FDA16F8B1825042FC9FE</HASHVAL>
  <TEXT>CREATE TABLE SPLITCHELT (
  CODSPLITCHELT NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(2,0),
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  ACTIV NUMBER(1,0),
  CODCONT NUMBER(20,0),
  FAZA NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SPLITCHELT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8D5E10C02C85760F42FCCF4EF18993FBF5F49646</HASHVAL>
  <TEXT>CREATE TABLE SPLITCHELT1 (
  CODSPLITCHELT1 NUMBER(20,0) NOT NULL,
  CODSPLITCHELT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  PROCENT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  PUNCTE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SPVARHIVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF87FC1256B4B30F7822EA1B0EDF1C00BF3EE946</HASHVAL>
  <TEXT>CREATE TABLE SPVARHIVA (
  CODSPVARHIVA NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  ZIP BLOB,
  TIPDOC NUMBER(3,0),
  ID_DS VARCHAR2(20),
  CIF VARCHAR2(30),
  CODDOCWME NUMBER(20,0),
  DATADOCSPV DATE,
  CIF_PARTENER VARCHAR2(75),
  VAL_DOC_SPV NUMBER(20,7),
  TVA_DOC_SPV NUMBER(20,7),
  ID_DOC_SPV VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SRC_DOCCARNETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6378F2CD0C0464763D427ABE7C578064CD499620</HASHVAL>
  <TEXT>CREATE TABLE SRC_DOCCARNETE (
  CODCARNET NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  DENUMIRE VARCHAR2(50),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  FREENR NUMBER(20,0),
  INACTIV NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  LIMITA NUMBER(20,0),
  STARTNRINI NUMBER(20,0),
  DEDICAT NUMBER(1,0),
  COMENZIONLINE NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SRC_DOCFREE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3166AEFF4F8BB992D33AC4906991B9AD874F9313</HASHVAL>
  <TEXT>CREATE TABLE SRC_DOCFREE (
  CODDOCFREE NUMBER(20,0),
  CODCARNET NUMBER(20,0),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SRC_DOCLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2142E5A8BCFC367290BEF9DA108F21499A693637</HASHVAL>
  <TEXT>CREATE TABLE SRC_DOCLINK (
  CODDOCLINK NUMBER(20,0),
  CODCARNET NUMBER(20,0),
  CODMACHETA NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STAREESTIMARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FE5A5FD6ED60D35AB58CB3D58466632FCD267B2</HASHVAL>
  <TEXT>CREATE TABLE STAREESTIMARI (
  CODSTARE NUMBER(20,0) NOT NULL,
  SAPTAMANA NUMBER(10,0),
  AN NUMBER(4,0),
  SAPTAMANAG NUMBER(10,0),
  ANG NUMBER(4,0),
  DATACREARE TIMESTAMP(6),
  USERID NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  OBS VARCHAR2(250),
  CODOFERTA NUMBER(20,0),
  DIRTY NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STAREESTIMARI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFF038FD6B0795BE6B7C0E8362C983D10C83919F</HASHVAL>
  <TEXT>CREATE TABLE STAREESTIMARI1 (
  CODSTARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NECESAR NUMBER(20,7),
  ESTIMAT NUMBER(20,7),
  STOCMIN NUMBER(20,7),
  CODSTARE1 NUMBER(20,0) NOT NULL,
  PRET NUMBER(20,7),
  NECESARACC NUMBER(20,7),
  PART1NEC NUMBER(20,7),
  DIRTY NUMBER(10,0),
  ACCEPTATTS NUMBER(20,7),
  CMDF NUMBER(20,7),
  STOCINI NUMBER(20,7),
  DIRTYCMDF NUMBER(10,0),
  BLOCAT NUMBER(10,0),
  BLOCAT1 NUMBER(10,0),
  CONSUM NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STAREESTIMARI2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4876A5F2779D12BD44629C441225193CEB26658</HASHVAL>
  <TEXT>CREATE TABLE STAREESTIMARI2 (
  CODSTARE2 NUMBER(20,0) NOT NULL,
  CODSTARE NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  RESTACCEPTAT NUMBER(20,7),
  PU NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  TERMEN DATE,
  SAPTAMANA NUMBER(2,0),
  CODSTARE1 NUMBER(20,0),
  PROPRIE NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STATCON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46B02E1CEB0B16511F1BD21F608253ED4E056A82</HASHVAL>
  <TEXT>CREATE TABLE STATCON (
  CODSTATCON NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  ATRIBUT NUMBER(1,0),
  DEN_EVALUARE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STATCOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A1CCEDA7788E1223FCE3CC2D672F6FD9F963B8A</HASHVAL>
  <TEXT>CREATE TABLE STATCOR (
  CODSTATCOR NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  ATRIBUT NUMBER(1,0),
  DEN_EVALUARE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STATCOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5212609DC9925007A5ABDAEF4E2438AAE4144ABD</HASHVAL>
  <TEXT>CREATE TABLE STATCOR1 (
  CODSTATCOR1 NUMBER(20,0),
  CODSTATCOR NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  VALOARE NUMBER(10,8),
  AI NUMBER(2,1),
  RII NUMBER(2,1)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STATUSDECL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63E8A994F9725C51E9FB7DDCD8E4E21AB9700643</HASHVAL>
  <TEXT>CREATE TABLE STATUSDECL (
  CODSTATUSDECL NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  IDINCARCARE VARCHAR2(20),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  STARE VARCHAR2(20),
  TIPMEDIU NUMBER(1,0),
  USERNAME VARCHAR2(20),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  COMPNAME VARCHAR2(20),
  FILENAME VARCHAR2(250),
  MESAJE CLOB,
  CIF VARCHAR2(20),
  SERIE_CERTIF VARCHAR2(250),
  UIT VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STINGERE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6A3F3541E0060AF8E668AEEDC58B2BFA23521BA0</HASHVAL>
  <TEXT>CREATE TABLE STINGERE (
  CODSTINGERE NUMBER(20,0) NOT NULL,
  CODSTINSPIF NUMBER(20,0),
  CODSTINGATORPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPLATA1 NUMBER(20,0),
  VALTRANZF NUMBER(20,7),
  VALTRANZC NUMBER(20,7),
  DINCARETVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCFAKE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6ED2BEE557121F5FD9E6FA4F2CAC38FCEC710A66</HASHVAL>
  <TEXT>CREATE TABLE STOCFAKE (
  CODSTOCFAKE NUMBER(20,0),
  CODOBIECT NUMBER(20,0) NOT NULL,
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  WAREHOUSEID VARCHAR2(35),
  LOCATIONID VARCHAR2(18),
  PRODUCTCODE VARCHAR2(70),
  STOCKACCOUNTNO VARCHAR2(70),
  PRODUCTTYPE VARCHAR2(18),
  PRODUCTSTATUS VARCHAR2(18),
  STOCKACCOUNTCOMMODITYCODE VARCHAR2(35),
  OWNERID VARCHAR2(35),
  UOMPHYSICALSTOCK VARCHAR2(9),
  UOMTOUOMBASECONVERSIONFACTOR VARCHAR2(2),
  UNITPRICE NUMBER(18,2),
  OPENINGSTOCKQUANTITY NUMBER(22,6),
  OPENINGSTOCKVALUE NUMBER(18,2),
  CLOSINGSTOCKQUANTITY NUMBER(22,6),
  CLOSINGSTOCKVALUE NUMBER(18,2),
  STOCKCHARACTERISTICS VARCHAR2(18),
  STOCKCHARACTERISTICVALUE VARCHAR2(35),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCFAKE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>63026B4C194C02A7D75EBEF0C79D85320B12F3B4</HASHVAL>
  <TEXT>CREATE TABLE STOCFAKE1 (
  CODSTOCFAKE1 NUMBER(20,0) NOT NULL,
  CODSTOCFAKE NUMBER(20,0),
  TG DATE,
  SERIE VARCHAR2(75),
  IDGESTIUNE VARCHAR2(15),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>080EB99AB12BD86664DBCC2EB8670929C46D05B9</HASHVAL>
  <TEXT>CREATE TABLE STOCINI (
  CODSTOCINI NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCINIART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23D7D8D9EBCDF2428325524365FE20D6D8C3C6BE</HASHVAL>
  <TEXT>CREATE TABLE STOCINIART (
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCLOCK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>440F0E784AA979B3B09742223A5A43361526EE28</HASHVAL>
  <TEXT>CREATE TABLE STOCLOCK (
  USERID NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCLOCKEMUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AAF942EDA314CF62C9F391D5023692A17D317638</HASHVAL>
  <TEXT>CREATE TABLE STOCLOCKEMUL (
  USERID NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCLOCKREST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B441D5F921CBA43FF14C219572819FD134AB07BF</HASHVAL>
  <TEXT>CREATE TABLE STOCLOCKREST (
  USERID NUMBER(20,0),
  CODRESTCMD1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCMPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2B3095891D5473D400A4B04180992024F722A12</HASHVAL>
  <TEXT>CREATE TABLE STOCMPART (
  CODLOCATIE NUMBER(20,0),
  CODEXTERN VARCHAR2(30),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCPOSURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0591B2BF9195C575936886A1A22E25B605646999</HASHVAL>
  <TEXT>CREATE TABLE STOCPOSURI (
  CODSTOCPOS NUMBER(20,0) NOT NULL,
  CODPOS NUMBER(20,0),
  TIPPOS NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  CODDEP NUMBER(3,0),
  PLU NUMBER(20,0),
  PRETNOU NUMBER(20,7),
  STOC NUMBER(20,7),
  BARCODE VARCHAR2(30),
  DENOBIECT VARCHAR2(200),
  MODIFICARI NUMBER(1,0),
  PRETART NUMBER(20,7),
  DIFPRET NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCVALINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2011C9D8FEFAEC6A5DBE5D76DAB63819EE7B222</HASHVAL>
  <TEXT>CREATE TABLE STOCVALINI (
  CODSTOCVALINI NUMBER(20,0) NOT NULL,
  GEST NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STOCVALLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0308592FB3298FD79D622FA09860786961F19DDE</HASHVAL>
  <TEXT>CREATE TABLE STOCVALLUNA (
  CODSTOCVALLUNA NUMBER(20,0) NOT NULL,
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  TVA NUMBER(20,7),
  SOLD NUMBER(20,7),
  ADAOS NUMBER(20,7),
  SOLDINTR NUMBER(20,7),
  ADAOSINTR NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>STORNOCMDF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B318E7473DF5F829EEAC165EDE19D6841DD57B5</HASHVAL>
  <TEXT>CREATE TABLE STORNOCMDF (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SYNCPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>970519E95B7893E7208CDED78DEFE7433266B19D</HASHVAL>
  <TEXT>CREATE TABLE SYNCPARTRETAIL (
  CODSYNCPART NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  SINCRONIZAT NUMBER(1,0),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SYNCPRETRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CAEBA16DB6D85B469160370BDDA085BB80A83C29</HASHVAL>
  <TEXT>CREATE TABLE SYNCPRETRETAIL (
  CODSYNC NUMBER(20,0) NOT NULL,
  CODPOSTRETAIL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  PRETVECHI NUMBER(20,7),
  PRETNOU NUMBER(20,7),
  DATA DATE,
  SINCRONIZAT NUMBER(1,0),
  IDPRELUARE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>SYNCPROMORETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>77A1F0EE0E214B1863E14835444C77E140A2A3FB</HASHVAL>
  <TEXT>CREATE TABLE SYNCPROMORETAIL (
  CODSYNCPROMO NUMBER(20,0) NOT NULL,
  CODPROMO NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  SINCRONIZAT NUMBER(1,0),
  DATA DATE,
  TIPMODIF NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TABIMPCOD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>25F2ED6FD87A83A15DE26A01479D7910E5CA53DB</HASHVAL>
  <TEXT>CREATE TABLE TABIMPCOD (
  IMPTABNAME VARCHAR2(30),
  IMPPKVAL NUMBER(20,0),
  TABNAME VARCHAR2(30),
  TABPKVAL NUMBER(20,0),
  IMPCOLVAL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TABIMPCODWM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>403F388A4D2A8F567C4F5A8DF05026DDC60D45E5</HASHVAL>
  <TEXT>CREATE TABLE TABIMPCODWM (
  IMPTABNAME VARCHAR2(30),
  IMPPKVAL NUMBER(20,0),
  TABNAME VARCHAR2(30),
  TABPKVAL NUMBER(20,0),
  IMPCOLVAL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TARGETAG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C434773A0E22B3F346D7D5126709A08C85DA30C6</HASHVAL>
  <TEXT>CREATE TABLE TARGETAG (
  CODTARGETAG NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  AGENT NUMBER(20,0),
  MONEDA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  TIPTARGET NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER,
  DATACREARE TIMESTAMP(6),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0),
  LUNAEND NUMBER(2,0),
  ANEND NUMBER(4,0),
  NRCLIENTI NUMBER(10,0),
  CLIENT NUMBER(20,0),
  CLASAPART NUMBER(20,0),
  TIPPART NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TARGETAG1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C09C2429E5D818939F14A3CA6E24A37060818B77</HASHVAL>
  <TEXT>CREATE TABLE TARGETAG1 (
  CODTARGETAG1 NUMBER(20,0) NOT NULL,
  CODTARGETAG NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARE NUMBER(20,7),
  OBS VARCHAR2(200),
  MASA NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  CANTMAX NUMBER(20,7),
  CODCLASAS NUMBER(20,0),
  VOLUM NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TARIFEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68FD66CC092A36677CF30D79F65B8F2D2D475A5C</HASHVAL>
  <TEXT>CREATE TABLE TARIFEMAN (
  CODTARIF NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(150),
  CODEXTERN VARCHAR2(80),
  CODMONEDA NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TARIFEMAN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AD21EC1E0027CF83A09AA2AACE096CDD5F72E7F3</HASHVAL>
  <TEXT>CREATE TABLE TARIFEMAN1 (
  CODTARIF1 NUMBER(20,0) NOT NULL,
  CODTARIF NUMBER(20,0),
  TARIF NUMBER(20,7),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  TARIF1 NUMBER(20,7),
  TARIF2 NUMBER(20,7),
  TARIF3 NUMBER(20,7),
  TARIF4 NUMBER(20,7),
  TARIF5 NUMBER(20,7),
  TARIF6 NUMBER(20,7),
  TARIF7 NUMBER(20,7),
  TARIF8 NUMBER(20,7),
  TARIF9 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TARIFE_MASTER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A47877A2ECE440C9472B55035FE2D26B932BCA46</HASHVAL>
  <TEXT>CREATE TABLE TARIFE_MASTER (
  CODTARIFM NUMBER(20,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TAXDECL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61402BDAFA072732107EEAE081C82FF72BA890B9</HASHVAL>
  <TEXT>CREATE TABLE TAXDECL (
  CODTAXDECL NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  TAXBASE NUMBER(22,7),
  CHEIA VARCHAR2(400),
  MANUAL NUMBER(1,0),
  CODCONT NUMBER(20,0),
  TAXVAL NUMBER(22,7),
  ANLUNA NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TEME</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E8C1E7D1361C6BE4A787D9AF418397493EF6C7C5</HASHVAL>
  <TEXT>CREATE TABLE TEME (
  CODTEMA NUMBER(20,0) NOT NULL,
  DEN_TEMA VARCHAR2(60),
  ORE NUMBER(10,0),
  PRET NUMBER(20,7),
  CODFORMATOR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TERMENECMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6FE07187B779C8DC5B549641417C910675689A5</HASHVAL>
  <TEXT>CREATE TABLE TERMENECMD (
  CODTERMEN NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  ZILE NUMBER(5,0),
  PROCENT NUMBER(20,7),
  TIPPLATA NUMBER(2,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TESATURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F5437538E0F2482564C155E55B2B31F195083E57</HASHVAL>
  <TEXT>CREATE TABLE TESATURI (
  CODTESATURA NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  COMPOZITIE VARCHAR2(300),
  MASASPECIFICA VARCHAR2(200),
  LEGATURA VARCHAR2(200),
  DESIMEU VARCHAR2(200),
  DESIMEB VARCHAR2(200),
  CATEGORIE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3710608D4CD83A4600B99A2622D20C978A40FB2</HASHVAL>
  <TEXT>CREATE TABLE TIMP (
  TIMP VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIPCHELT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1370B91BB068A31D8B0D358CF0EC58DBB4F2DA42</HASHVAL>
  <TEXT>CREATE TABLE TIPCHELT (
  CODTIPCHELT NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  CODCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIPLUCRARISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1FDD339EDA79C35C5AA3D04A42D974BA5C93F239</HASHVAL>
  <TEXT>CREATE TABLE TIPLUCRARISA (
  CODTIPLUCRARE NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(60),
  ARTSERVFACT NUMBER(20,0),
  CLASALUCRARI VARCHAR2(40),
  CODGEST NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  TOTI NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIPLUCRARISA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>46574E322971CAF89AE7C37B2D6419D752ACA186</HASHVAL>
  <TEXT>CREATE TABLE TIPLUCRARISA1 (
  CODTIPLUCRARE1 NUMBER(20,0) NOT NULL,
  CODTIPLUCRARE NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIPPARTINCERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CD6BCF439411939A7B51C71C487C878B593FAFF</HASHVAL>
  <TEXT>CREATE TABLE TIPPARTINCERT (
  CODTIPPARTINCERT NUMBER(20,0),
  TIPCLIENT VARCHAR2(50),
  TIPIMPOZITARE VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TIPURIPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D61DF5B6530294CA361324ECE3C4AAD5540447AC</HASHVAL>
  <TEXT>CREATE TABLE TIPURIPLATI (
  CODTIPPLATA NUMBER(20,0) NOT NULL,
  TIPCASA NUMBER(5,0),
  TIPPLATA NUMBER(5,0),
  DENPLATA VARCHAR2(30),
  INVIZIBIL NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ACTABON_ART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC6C5BBCABF8F8D66BAAC3F015D126E8A736CFD6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ACTABON_ART (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  COEF NUMBER(20,7),
  CANT NUMBER(20,7),
  CODOBIECTN NUMBER(20,0),
  UMSECN NUMBER(20,0),
  TIPPRET NUMBER(1,0),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(5,2),
  DATASTART DATE,
  DATASTOP DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ACT_STOCMED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>040718B72A0ED09E258DFF8D2B1D66BF3A22C753</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ACT_STOCMED (
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  STOCMEDIUFIRMA NUMBER(20,7),
  STOCMEDIUSUBUNIT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ADAOSM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>098BB19E810E109202A90B983A5924E3FB5A2CB2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ADAOSM (
  CODADAOSM NUMBER(20,0),
  DATA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ADAOSM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>295C9438954A3462A292CA78FC33827657FDCB73</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ADAOSM1 (
  CODADAOSM1 NUMBER(20,0),
  CODADAOSM NUMBER(20,0),
  LIMSUP NUMBER(20,7),
  COTAADAOST NUMBER(20,7),
  COTAADAOSD NUMBER(20,7),
  LIMINF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ALERTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>72724ED4E6E837DE28746E2B1E0CACE4CFFEE0BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ALERTE (
  CODALERTA NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  TIPALERTA NUMBER(1,0),
  OBS VARCHAR2(200),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODORAR NUMBER(20,0),
  MAILTO VARCHAR2(1000),
  CUSTOMMESSAGE CLOB,
  MAIL_INDIVIDUAL NUMBER(1,0),
  CUSTOMSUBJECT VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  SQL CLOB,
  CODFIRMA NUMBER(20,0),
  CUSTOMFOOTER CLOB,
  FIELDURI VARCHAR2(1000),
  TITLUXLS VARCHAR2(100),
  TIPEXPORT NUMBER(2,0),
  ORDONARE VARCHAR2(200),
  SQLCUSMS NUMBER(1,0),
  JOBID NUMBER(20,0),
  WEBSERVER NUMBER(1,0),
  ACTIV NUMBER(1,0),
  CODALERTADEF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ALERTE0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EE7DCA33E4D1F1515E2B9FF1A75FCB6DA03AE28D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ALERTE0 (
  CODALERTA0 NUMBER(20,0),
  CODALERTA NUMBER(20,0),
  USERNAME VARCHAR2(50),
  USERID NUMBER(20,0),
  RECIPIENT VARCHAR2(100),
  EMAIL NUMBER(1,0),
  MESS NUMBER(1,0),
  TASK NUMBER(1,0),
  SMS NUMBER(1,0),
  TEL VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ALERTE_DEF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BFC66C8812EBAF086BC6483290EB11BC69B654DD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ALERTE_DEF (
  CODALERTADEF NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  SQL CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ALERTE_INFO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8E0E6F4CFD0A4480BACAB51A904663A77FB5178C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ALERTE_INFO (
  CODALERTAINFO NUMBER(20,0),
  CODALERTA NUMBER(20,0),
  DATAEXEC DATE,
  REZULTAT CLOB,
  INFO_FILTRE CLOB,
  CODRULARE NUMBER(20,0),
  MAILTO VARCHAR2(500),
  TASKTO VARCHAR2(100),
  MESSTO VARCHAR2(100),
  SMSTO VARCHAR2(50),
  FILENAME VARCHAR2(50),
  FILEBODY BLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AL_CURSLINIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>095498EB065016F52E2C78FC9DD8AE952351ED5F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AL_CURSLINIE (
  AL NUMBER(5,0),
  VAL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AL_REFRESH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CBE8D908B5FA374A104DC80FEBAD55C55FEFF333</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AL_REFRESH (
  COD NUMBER(20,0),
  CODP NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AMBDELEGAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D302B54F6E0806EE35F9B3DBC5189E9436E24D11</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AMBDELEGAT (
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  MONEDA NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  FARATRANSPORT NUMBER(1,0),
  SCADENTAV NUMBER(5,0),
  OBS VARCHAR2(500),
  DEN_PART VARCHAR2(100),
  SEDIU VARCHAR2(100),
  SIMB_MON VARCHAR2(5),
  CODIES NUMBER(20,0),
  TIPIES NUMBER(20,0),
  CARNETIES NUMBER(20,0),
  DENCARNETIES VARCHAR2(50),
  REST_TOT NUMBER(20,7),
  OK_REZERVATS NUMBER(1,0),
  REZOLVAT NUMBER(1,0),
  TIPCUSTODIE NUMBER(1,0),
  DENAGENT VARCHAR2(500),
  NRIES NUMBER(20,0),
  TIPORIG NUMBER(20,0),
  CODORIG NUMBER(20,0),
  DOCORIG VARCHAR2(50),
  CODPARTTR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AMBDELEGAT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5071FBEF6326AB084469B5D13875090D15B7973F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AMBDELEGAT1 (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  UMSEC NUMBER(10,0),
  DENUM VARCHAR2(15),
  CANTCOMANDAT NUMBER(20,7),
  CANTRETURNAT NUMBER(20,7),
  ORIGRETURNAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTACCEPTAT NUMBER(20,7),
  CANTFACTURAT NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,6),
  PROCDISC NUMBER(20,7),
  ADDIM NUMBER(20,7),
  OBS VARCHAR2(200),
  SCADENTA NUMBER(5,0),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  TERMENPLATA NUMBER(5,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  PROCTVA NUMBER(6,3),
  TEMPACCEPTAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANALIZA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>15BD97A98E5B4B37F1257D3F17A961167A8A3BD5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANALIZA (
  CODANALIZA NUMBER(20,0),
  DEN_ANALIZA VARCHAR2(100),
  IDELEMENT NUMBER(10,0),
  IDCENTRU NUMBER(10,0),
  INACTIV NUMBER(1,0),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANALIZA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>89F6126A61A0DA06F97755DC1C252EB926FC8D2C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANALIZA1 (
  CODANALIZA1 NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODDESCRIPTOR NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DEN_DESCRIPTOR VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANALIZANOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6721628D5D1395B228C4702D75B9F85E559828DD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANALIZANOD (
  CODANALIZANOD NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  NODPARINTE NUMBER(20,0),
  CODANALIZA1 NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  POZITIE NUMBER(10,0),
  INACTIV NUMBER(1,0),
  SIMBOLNOD VARCHAR2(100),
  DENNOD VARCHAR2(200),
  TIP NUMBER(1,0),
  INDEXLOCAL NUMBER(20,0),
  DEN_DESCRIPTOR VARCHAR2(300),
  VAL_DESCRIPTOR1 VARCHAR2(150),
  CODASOCIAT NUMBER(20,0),
  DEN_ASOCIAT VARCHAR2(100),
  SIMBOL VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANALIZANOD_REF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>23094052E2D061E7082266E3EA92D50162DD673A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANALIZANOD_REF (
  CODANALIZANOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODREF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANLUNA_VAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>61BA653C4974F477FA797467275B97AB0792B8D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANLUNA_VAL (
  AL NUMBER(20,0),
  VALOARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANTEC_IMPL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>82553709D061416903986E1B3DC31028C914D3BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANTEC_IMPL (
  OBSPREL VARCHAR2(250),
  CODPRODCOMPPREL NUMBER(20,0),
  PRELUARE NUMBER(1,0),
  OBS VARCHAR2(250),
  DENUMIRE VARCHAR2(200),
  CODPRODCOMP NUMBER(20,0),
  DENUMIRESEMI VARCHAR2(200),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DATA DATE,
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  NRMAT NUMBER(10,0),
  DEN_CLASEPROD VARCHAR2(50),
  DEN_CLASEA VARCHAR2(50),
  DEN_CLASEAS VARCHAR2(50),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANTEC_PROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>804AB88948D9F808AE78694BD99E1A645F7DA027</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANTEC_PROD (
  OBS VARCHAR2(250),
  CODPRODCOMP NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DATA DATE,
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  DEN_CLASEPROD VARCHAR2(50),
  DEN_CLASEA VARCHAR2(50),
  DEN_CLASEAS VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ANTEC_SEMI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E37F5E3EA934AC151A7281C88CDADD0BA4CFC9DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ANTEC_SEMI (
  OBSPREL VARCHAR2(250),
  CODPRODCOMPPREL NUMBER(20,0),
  OBS VARCHAR2(250),
  DENUMIRE VARCHAR2(200),
  CODPRODCOMP NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DATA DATE,
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  DEN_CLASEPROD VARCHAR2(50),
  DEN_CLASEA VARCHAR2(50),
  DEN_CLASEAS VARCHAR2(50),
  DENUMIREPREL VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_APELTELEFON</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7321BA49782C295B00F56A2C6C9E580D926AB144</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_APELTELEFON (
  CODAPEL NUMBER(20,0),
  IDAPEL VARCHAR2(20),
  STARE VARCHAR2(20),
  TELEFON VARCHAR2(20),
  APELANT VARCHAR2(100),
  DATAORA TIMESTAMP(6),
  PRELUAT NUMBER(1,0),
  CLIENT VARCHAR2(100),
  MODIFICAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_APROVIZ_PART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9454983FB948DF36D2B5E10E8FD7E1CFD9B56016</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_APROVIZ_PART (
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  DENLACLIENT VARCHAR2(200),
  CODEXTERNCLI VARCHAR2(30),
  SEDIU VARCHAR2(100),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7),
  STOC NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  PRET NUMBER(20,7),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODCATPRET NUMBER(20,0),
  UMSEC NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ASIGURARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>50C3937B819FD14E9B34798CC2906AB1D1781610</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ASIGURARI (
  CODASIGURARE NUMBER(20,0),
  NRDOC VARCHAR2(50),
  CODPART NUMBER(20,0),
  DATASTART DATE,
  TERMEN DATE,
  CODCLASEMF NUMBER(20,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ASIGURARI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8CA8F4EA81A44C99F99FA3EBB2683A99B42AC437</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ASIGURARI1 (
  CODASIGURARE1 NUMBER(20,0),
  CODASIGURARE NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODMIFIX NUMBER(20,0),
  VALASIG NUMBER(20,7),
  NRINVENTAR NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  VALMF NUMBER(20,7),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ATENTIONARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B0DB64CCCD915C5EB279FF330242C9116F2FF6B9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ATENTIONARI (
  TIP NUMBER(1,0),
  CAMP1 NUMBER(20,0),
  CAMP2 NUMBER(20,0),
  CAMP3 NUMBER(20,0),
  CAMP4 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AUX_D300</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CC7309C3DEF961BA5E580623F11749DB5F3A328F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AUX_D300 (
  V_01_0 NUMBER(15,0),
  V_03_0 NUMBER(15,0),
  V_03_1 NUMBER(15,0),
  V_05_0 NUMBER(15,0),
  T_05_0 NUMBER(15,0),
  V_05_1 NUMBER(15,0),
  T_05_1 NUMBER(15,0),
  V_06_0 NUMBER(15,0),
  T_06_0 NUMBER(15,0),
  V_07_0 NUMBER(15,0),
  T_07_0 NUMBER(15,0),
  V_07_1 NUMBER(15,0),
  T_07_1 NUMBER(15,0),
  V_08_0 NUMBER(15,0),
  T_08_0 NUMBER(15,0),
  V_09_0 NUMBER(15,0),
  T_09_0 NUMBER(15,0),
  V_09_1 NUMBER(15,0),
  T_09_1 NUMBER(15,0),
  V_10_0 NUMBER(15,0),
  T_10_0 NUMBER(15,0),
  V_10_1 NUMBER(15,0),
  T_10_1 NUMBER(15,0),
  V_11_0 NUMBER(15,0),
  T_11_0 NUMBER(15,0),
  V_11_1 NUMBER(15,0),
  T_11_1 NUMBER(15,0),
  V_12_0 NUMBER(15,0),
  T_12_0 NUMBER(15,0),
  V_12_1 NUMBER(15,0),
  T_12_1 NUMBER(15,0),
  V_12_2 NUMBER(15,0),
  T_12_2 NUMBER(15,0),
  V_12_3 NUMBER(15,0),
  T_12_3 NUMBER(15,0),
  V_12_4 NUMBER(15,0),
  T_12_4 NUMBER(15,0),
  V_12_5 NUMBER(15,0),
  T_12_5 NUMBER(15,0),
  V_13_0 NUMBER(15,0),
  V_14_0 NUMBER(15,0),
  V_14_1 NUMBER(15,0),
  V_14_2 NUMBER(15,0),
  V_15_0 NUMBER(15,0),
  V_16_0 NUMBER(15,0),
  T_16_0 NUMBER(15,0),
  V_22_0 NUMBER(15,0),
  T_22_0 NUMBER(15,0),
  V_22_1 NUMBER(15,0),
  T_22_1 NUMBER(15,0),
  V_23_0 NUMBER(15,0),
  T_23_0 NUMBER(15,0),
  V_23_1 NUMBER(15,0),
  T_23_1 NUMBER(15,0),
  V_24_0 NUMBER(15,0),
  T_24_0 NUMBER(15,0),
  V_26_0 NUMBER(15,0),
  V_26_1 NUMBER(15,0),
  T_29_0 NUMBER(15,0),
  V_30_0 NUMBER(15,0),
  T_30_0 NUMBER(15,0),
  T_43_0 NUMBER(15,0),
  T_44_0 NUMBER(15,0),
  V_64_0 NUMBER(15,0),
  T_64_0 NUMBER(15,0),
  AUX_T_28_0 NUMBER(15,0),
  V_A NUMBER(15,0),
  T_A NUMBER(15,0),
  V_B NUMBER(15,0),
  T_B NUMBER(15,0),
  V_A1 NUMBER(15,0),
  T_A1 NUMBER(15,0),
  V_B1 NUMBER(15,0),
  T_B1 NUMBER(15,0),
  TOT_PREC NUMBER(15,0),
  TOT_CUR NUMBER(15,0),
  AUX_SUM NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AUX_STINGATORI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67C9A89D0E6FF38069E49FFFB99F485AA95173DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AUX_STINGATORI (
  CODOBLIGPIF NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODSTINSPIF NUMBER(20,0),
  CODDOCS NUMBER(20,0),
  TIPDOCS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AVARIECAROSERIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>013FFDDA646AE6D590E7BAB414199F3AE3BD65BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AVARIECAROSERIE (
  CODAVARIE NUMBER(20,0),
  CODCOMANDA NUMBER(10,0),
  DEFECT NUMBER(1,0),
  CAND NUMBER(1,0),
  X NUMBER(5,0),
  Y NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AVARIECAROSERIE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC866B0A34FE8F94B33B7B060EF3F7BBAEA26BBF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AVARIECAROSERIE1 (
  CODAVARIE NUMBER(20,0),
  CODCOMANDA NUMBER(10,0),
  DEFECT NUMBER(1,0),
  CAND NUMBER(1,0),
  X NUMBER(5,0),
  Y NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_AWBCOMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6B9C7D4D13BF43B88A17C96B25668C6304F4CB01</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_AWBCOMANDA (
  CODAWBCOMANDA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CURIER NUMBER(2,0),
  NUMAR VARCHAR2(30),
  DOC CLOB,
  PDF BLOB,
  INFOSTADIU VARCHAR2(500),
  POSTAT NUMBER(1,0),
  DATAPOSTARE DATE,
  TARIF NUMBER(10,2),
  TVA NUMBER(10,2),
  TIPDOC NUMBER(5,0),
  SHIPMENTID NUMBER(20,0),
  PARCELSID CLOB,
  HASPDF NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BALANTA_STOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B8878FF4E2C688B687B686AF5240270D5B5E4B42</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BALANTA_STOC (
  CODOBIECT NUMBER(20,0),
  STOCINITIAL NUMBER(20,7),
  INTRARI NUMBER(20,7),
  IESIRI NUMBER(20,7),
  PRET NUMBER(20,7),
  DIMINUATE NUMBER(20,7),
  TRANSFERATE NUMBER(20,7),
  VANDUTE NUMBER(20,7),
  CONSUMATE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  NEPRELUATE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BCAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>745E91E73176011D855230EFAD20F366B7A31921</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BCAR (
  CODBCAR NUMBER(20,0),
  OPERAT NUMBER(1,0),
  CODCANTARIN NUMBER(20,0),
  CODCANTAROUT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  PREFIXDOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  PREFIXAVIZIN VARCHAR2(2),
  NRAVIZIN NUMBER(20,0),
  NRAVIZOUT NUMBER(20,0),
  DATAAVIZIN DATE,
  ISUMIDITATE NUMBER(20,7),
  IAUMIDITATE NUMBER(20,7),
  ISSTRAINE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  ISINCOLTIT NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  ISHECTOLITRICA NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  ISGLUTEN NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  ISFUZARITATE NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  ISCADERE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  ISDEFORMARE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  ISSTICLOZITATE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  ISSPARTURI NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  BRUTKG NUMBER(20,7),
  TARA NUMBER(20,7),
  NETKG NUMBER(20,7),
  UTILKG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETUSCARE NUMBER(20,7),
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODDELEGAT NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODSERIE NUMBER(20,0),
  RETUR NUMBER(1,0),
  MODCANTAR NUMBER(1,0),
  USERIDBLOCAJ NUMBER(20,0),
  TIPBCAR NUMBER(1,0),
  CODGESTIMPL NUMBER(20,0),
  CODLOCATIMPL NUMBER(20,0),
  OBSERVATII VARCHAR2(40),
  CODPERS NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODAUTO NUMBER(20,0),
  ICUMIDITATE NUMBER(20,7),
  ICSTRAINE NUMBER(20,7),
  ICINCOLTIT NUMBER(20,7),
  ICHECTOLITRICA NUMBER(20,7),
  ICGLUTEN NUMBER(20,7),
  ICFUZARITATE NUMBER(20,7),
  ICCADERE NUMBER(20,7),
  ICDEFORMARE NUMBER(20,7),
  ICSTICLOZITATE NUMBER(20,7),
  ICSPARTURI NUMBER(20,7),
  NETKGCLIENT NUMBER(20,7),
  UTILKGCLIENT NUMBER(20,7),
  INFOCLIENT NUMBER(1,0),
  CODDOC1STORNO NUMBER(20,0),
  CODBCARDEST NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  NRREMORCA VARCHAR2(15),
  CODREMORCA NUMBER(20,0),
  UTILSTASKG NUMBER(20,7),
  PRETCONFIRMAT NUMBER(20,7),
  ISPROTEINA NUMBER(20,7),
  ISAFLATOXINA NUMBER(20,7),
  ISATAC_PLOSNITA NUMBER(20,7),
  ISCONTINUT_ULEI NUMBER(20,7),
  ISACIDITATE NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  ICPROTEINA NUMBER(20,7),
  ICAFLATOXINA NUMBER(20,7),
  ICATAC_PLOSNITA NUMBER(20,7),
  ICCONTINUT_ULEI NUMBER(20,7),
  ICACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7),
  ISSISTAVE NUMBER(20,7),
  ISREFRACTIE NUMBER(20,7),
  ISINDICE_W NUMBER(20,7),
  ISTOXINA_DON NUMBER(20,7),
  ISBOABE_TOXICE NUMBER(20,7),
  ICSISTAVE NUMBER(20,7),
  ICREFRACTIE NUMBER(20,7),
  ICINDICE_W NUMBER(20,7),
  ICTOXINA_DON NUMBER(20,7),
  ICBOABE_TOXICE NUMBER(20,7),
  PIERDERITEH NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CURS NUMBER(22,4),
  ID_CITIRE1 VARCHAR2(20),
  ID_CITIRE2 VARCHAR2(20),
  NUMEDELEGAT VARCHAR2(150),
  INFOCONTRACT1 VARCHAR2(40),
  DOCUMENT VARCHAR2(40),
  CODCONTRACT NUMBER(20,0),
  TIPCONTRACT NUMBER(10,0),
  PRETLASTAS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BCAR_MAN1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF30D4E824A23A507C7B1FFAD02FE7884BB55280</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BCAR_MAN1 (
  CODBCAR NUMBER(20,0),
  OPERAT NUMBER(1,0),
  CODCANTARIN NUMBER(20,0),
  CODCANTAROUT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  PREFIXDOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  PREFIXAVIZIN VARCHAR2(2),
  NRAVIZIN NUMBER(20,0),
  NRAVIZOUT NUMBER(20,0),
  DATAAVIZIN DATE,
  ISUMIDITATE NUMBER(20,7),
  IAUMIDITATE NUMBER(20,7),
  ISSTRAINE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  ISINCOLTIT NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  ISHECTOLITRICA NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  ISGLUTEN NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  ISFUZARITATE NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  ISCADERE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  ISDEFORMARE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  ISSTICLOZITATE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  ISSPARTURI NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  BRUTKG NUMBER(20,7),
  TARA NUMBER(20,7),
  NETKG NUMBER(20,7),
  UTILKG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETUSCARE NUMBER(20,7),
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODDELEGAT NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODSERIE NUMBER(20,0),
  RETUR NUMBER(1,0),
  MODCANTAR NUMBER(1,0),
  USERIDBLOCAJ NUMBER(20,0),
  TIPBCAR NUMBER(1,0),
  CODGESTIMPL NUMBER(20,0),
  CODLOCATIMPL NUMBER(20,0),
  OBSERVATII VARCHAR2(40),
  CODPERS NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODAUTO NUMBER(20,0),
  ICUMIDITATE NUMBER(20,7),
  ICSTRAINE NUMBER(20,7),
  ICINCOLTIT NUMBER(20,7),
  ICHECTOLITRICA NUMBER(20,7),
  ICGLUTEN NUMBER(20,7),
  ICFUZARITATE NUMBER(20,7),
  ICCADERE NUMBER(20,7),
  ICDEFORMARE NUMBER(20,7),
  ICSTICLOZITATE NUMBER(20,7),
  ICSPARTURI NUMBER(20,7),
  NETKGCLIENT NUMBER(20,7),
  UTILKGCLIENT NUMBER(20,7),
  INFOCLIENT NUMBER(1,0),
  CODDOC1STORNO NUMBER(20,0),
  CODBCARDEST NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  NRREMORCA VARCHAR2(15),
  CODREMORCA NUMBER(20,0),
  UTILSTASKG NUMBER(20,7),
  PRETCONFIRMAT NUMBER(20,7),
  ISPROTEINA NUMBER(20,7),
  ISAFLATOXINA NUMBER(20,7),
  ISATAC_PLOSNITA NUMBER(20,7),
  ISCONTINUT_ULEI NUMBER(20,7),
  ISACIDITATE NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  ICPROTEINA NUMBER(20,7),
  ICAFLATOXINA NUMBER(20,7),
  ICATAC_PLOSNITA NUMBER(20,7),
  ICCONTINUT_ULEI NUMBER(20,7),
  ICACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7),
  ISSISTAVE NUMBER(20,7),
  ISREFRACTIE NUMBER(20,7),
  ISINDICE_W NUMBER(20,7),
  ISTOXINA_DON NUMBER(20,7),
  ISBOABE_TOXICE NUMBER(20,7),
  ICSISTAVE NUMBER(20,7),
  ICREFRACTIE NUMBER(20,7),
  ICINDICE_W NUMBER(20,7),
  ICTOXINA_DON NUMBER(20,7),
  ICBOABE_TOXICE NUMBER(20,7),
  PIERDERITEH NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CURS NUMBER(22,4),
  ID_CITIRE1 VARCHAR2(20),
  ID_CITIRE2 VARCHAR2(20),
  NUMEDELEGAT VARCHAR2(150),
  INFOCONTRACT1 VARCHAR2(40),
  DOCUMENT VARCHAR2(40),
  CODCONTRACT NUMBER(20,0),
  TIPCONTRACT NUMBER(10,0),
  PRETLASTAS NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  PRETACHIZNOU NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BCAR_MAN2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F588D56EA7C0587AB706B92B39B6B099EF2E00FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BCAR_MAN2 (
  IDX NUMBER(20,0),
  TIPI VARCHAR2(10),
  IAUMIDITATE NUMBER(20,7),
  IASTRAINE NUMBER(20,7),
  IAINCOLTIT NUMBER(20,7),
  IAHECTOLITRICA NUMBER(20,7),
  IAGLUTEN NUMBER(20,7),
  IAFUZARITATE NUMBER(20,7),
  IACADERE NUMBER(20,7),
  IADEFORMARE NUMBER(20,7),
  IASTICLOZITATE NUMBER(20,7),
  IASPARTURI NUMBER(20,7),
  IAPROTEINA NUMBER(20,7),
  IAAFLATOXINA NUMBER(20,7),
  IAATAC_PLOSNITA NUMBER(20,7),
  IACONTINUT_ULEI NUMBER(20,7),
  IAACIDITATE NUMBER(20,7),
  IASISTAVE NUMBER(20,7),
  IAREFRACTIE NUMBER(20,7),
  IAINDICE_W NUMBER(20,7),
  IATOXINA_DON NUMBER(20,7),
  IABOABE_TOXICE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BCAR_PE_LOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>017B99405DA87F8A112ECBECA58CD20C1FCBDC92</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BCAR_PE_LOT (
  CODBCAR NUMBER(20,0),
  FURNIZOR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NETKG NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  CODSERIE NUMBER(20,0),
  DATADOC DATE,
  UTILKG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETUSCARE NUMBER(20,7),
  SELECTIE NUMBER(1,0),
  GRUP NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  AUTO VARCHAR2(30),
  NRAVIZIN NUMBER(20,0),
  RETUR NUMBER(1,0),
  CODGESTIMPL NUMBER(20,0),
  CODLOCATIMPL NUMBER(20,0),
  CODPERS NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODAUTO NUMBER(20,0),
  NUMEDELEGAT VARCHAR2(150),
  CODDELEGAT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  UTILSTASKG NUMBER(20,7),
  PRETCONFIRMAT NUMBER(20,7),
  PRETLASTAS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BONMASA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>02D1DC670AE9E6759D6DE9479310DFF196980A0F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BONMASA (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETANALIZA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6E0BD0A44E48C4411B8AD1F7E98C26ECC3D2168</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETANALIZA (
  COD NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODELEMENT NUMBER(20,0),
  TOTAL NUMBER(20,7),
  B1 NUMBER(20,7),
  B2 NUMBER(20,7),
  B3 NUMBER(20,7),
  B4 NUMBER(20,7),
  B5 NUMBER(20,7),
  B6 NUMBER(20,7),
  B7 NUMBER(20,7),
  B8 NUMBER(20,7),
  B9 NUMBER(20,7),
  B10 NUMBER(20,7),
  B11 NUMBER(20,7),
  B12 NUMBER(20,7),
  NODPARINTE NUMBER(20,0),
  ZERO NUMBER(20,0),
  DENCENTRU VARCHAR2(100),
  DENELEMENT VARCHAR2(100),
  SIMBOLCENTRU VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETCAP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0D57827E921D4217D46B5B4B815B32083CBB8D7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETCAP (
  CODBUGETCAP NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  TIPCAP NUMBER(5,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETCAPC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4BB564304D7B6AE20C4AF9668570841F96E69B4C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETCAPC (
  CODBUGETCAP1 NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  DEN_CLASEA VARCHAR2(50),
  TIPCAP NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETCAPV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CEBF3804EB5D83B3BFA0808B7F989D5F861D7361</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETCAPV (
  CODBUGETCAP1 NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  DEN_CLASEA VARCHAR2(50),
  TIPCAP NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETCL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E0D76A392008E8CFAE12B06CA59552837AB19720</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETCL (
  CODBUGETCL NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  ELEMENT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETCL_T</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6E84DAEBA88BC761AED695DAF9505D60DDF71E6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETCL_T (
  ELEMENT VARCHAR2(250),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EA24860D9B1F9D47E23549F56A5E7D1EFCAC20FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETMF (
  CODBUGETMF NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  USERID NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  NRINVENTAR NUMBER(20,0),
  TOTAL NUMBER(20,7),
  REST NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  ACHIZITII NUMBER(20,7),
  COMENZI NUMBER(20,7),
  TOTALAPROBAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETMF1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6BF91302AAAF55B3E0E1A615331617DA3BC5DB96</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETMF1 (
  CODBUGETMF1 NUMBER(20,0),
  CODBUGETMF NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(200),
  VALOARE NUMBER(20,7),
  DATABUGET DATE,
  OBS VARCHAR2(250),
  STADIU NUMBER(5,0),
  OLDSTADIU NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>21FF5E2F15CF967D6F3152ABDDFE315B47922611</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETPROD (
  CODBUGETPROD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS VARCHAR2(400),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(2,0),
  ANIMPORT NUMBER(4,0),
  SAPTAMANAF NUMBER(2,0),
  ANF NUMBER(4,0),
  DATASTART DATE,
  DATASTOP DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETPRODP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D07C6E9D5D40F84A36D5B893F47D3F377A5C8FB8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETPRODP (
  CODBUGETPRODP NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETPRODT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1129427A68A1131E20F05FA49E0F26BBDBEC700</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETPRODT (
  CODBUGETPRODT NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETPRODV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>25DCFB91B79973D260BB55E7D3B7867FF9262CE8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETPRODV (
  CODBUGETPRODV NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETRECTIF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>30DC17EE4F7EDEDBE7698DC940A77AD6A61DBB9E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETRECTIF (
  CODBUGETRECTIF NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(4,0),
  LUNASURSA NUMBER(2,0),
  LUNADEST NUMBER(20,0),
  OBS VARCHAR2(250),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODANALIZA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETRECTIF1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6C7F21E00CD60A03C4EFFC9C8F4EC7898AAC36B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETRECTIF1 (
  CODBUGETRECTIF1 NUMBER(20,0),
  CODBUGETRECTIF NUMBER(20,0),
  CODNODSURSA NUMBER(20,0),
  CODNODDEST NUMBER(20,0),
  VCREDIT NUMBER(20,7),
  VANGAJAPROB NUMBER(20,7),
  VANGAJREAL NUMBER(20,7),
  VPLATAAPROB NUMBER(20,7),
  VPLATAREAL NUMBER(20,7),
  VCHELT NUMBER(20,7),
  VPLANIF NUMBER(20,7),
  VFACT NUMBER(20,7),
  VINCASREAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B4DA440919796BD3B23C1D8D932AA2987524013D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETSTOC (
  CODBUGETSTOC NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  STOC NUMBER(20,7),
  COEFUM NUMBER(20,7),
  VALTOTAL NUMBER(20,7),
  VALMAT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  DENUMIRE VARCHAR2(200),
  DEN_CLASEA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETVCL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78F96B55F5DEA7339C8B033CD6CD64F3B4A1E8EE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETVCL (
  CODBUGETVCL NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  TIPCAP NUMBER(1,0),
  COEFUM NUMBER(20,7),
  L1_CAP NUMBER(20,7),
  L1_STOC NUMBER(20,7),
  L1_VANZ NUMBER(20,7),
  L1_TARGET NUMBER(20,7),
  L1_NPCANT NUMBER(20,7),
  L1_PRET NUMBER(20,7),
  L1_NPVAL NUMBER(20,7),
  L1_COEFCAP NUMBER(20,7),
  L1_NPFCANT NUMBER(20,7),
  L1_NPFVAL NUMBER(20,7),
  L1_PRETMMR NUMBER(20,7),
  L1_PRETMAT NUMBER(20,7),
  L1_VAR NUMBER(20,7),
  L1_EST NUMBER(20,7),
  L2_CAP NUMBER(20,7),
  L2_STOC NUMBER(20,7),
  L2_VANZ NUMBER(20,7),
  L2_TARGET NUMBER(20,7),
  L2_NPCANT NUMBER(20,7),
  L2_PRET NUMBER(20,7),
  L2_NPVAL NUMBER(20,7),
  L2_COEFCAP NUMBER(20,7),
  L2_NPFCANT NUMBER(20,7),
  L2_NPFVAL NUMBER(20,7),
  L2_PRETMMR NUMBER(20,7),
  L2_PRETMAT NUMBER(20,7),
  L2_VAR NUMBER(20,7),
  L2_EST NUMBER(20,7),
  L3_CAP NUMBER(20,7),
  L3_STOC NUMBER(20,7),
  L3_VANZ NUMBER(20,7),
  L3_TARGET NUMBER(20,7),
  L3_NPCANT NUMBER(20,7),
  L3_PRET NUMBER(20,7),
  L3_NPVAL NUMBER(20,7),
  L3_COEFCAP NUMBER(20,7),
  L3_NPFCANT NUMBER(20,7),
  L3_NPFVAL NUMBER(20,7),
  L3_PRETMMR NUMBER(20,7),
  L3_PRETMAT NUMBER(20,7),
  L3_VAR NUMBER(20,7),
  L3_EST NUMBER(20,7),
  L4_CAP NUMBER(20,7),
  L4_STOC NUMBER(20,7),
  L4_VANZ NUMBER(20,7),
  L4_TARGET NUMBER(20,7),
  L4_NPCANT NUMBER(20,7),
  L4_PRET NUMBER(20,7),
  L4_NPVAL NUMBER(20,7),
  L4_COEFCAP NUMBER(20,7),
  L4_NPFCANT NUMBER(20,7),
  L4_NPFVAL NUMBER(20,7),
  L4_PRETMMR NUMBER(20,7),
  L4_PRETMAT NUMBER(20,7),
  L4_VAR NUMBER(20,7),
  L4_EST NUMBER(20,7),
  L5_CAP NUMBER(20,7),
  L5_STOC NUMBER(20,7),
  L5_VANZ NUMBER(20,7),
  L5_TARGET NUMBER(20,7),
  L5_NPCANT NUMBER(20,7),
  L5_PRET NUMBER(20,7),
  L5_NPVAL NUMBER(20,7),
  L5_COEFCAP NUMBER(20,7),
  L5_NPFCANT NUMBER(20,7),
  L5_NPFVAL NUMBER(20,7),
  L5_PRETMMR NUMBER(20,7),
  L5_PRETMAT NUMBER(20,7),
  L5_VAR NUMBER(20,7),
  L5_EST NUMBER(20,7),
  L6_CAP NUMBER(20,7),
  L6_STOC NUMBER(20,7),
  L6_VANZ NUMBER(20,7),
  L6_TARGET NUMBER(20,7),
  L6_NPCANT NUMBER(20,7),
  L6_PRET NUMBER(20,7),
  L6_NPVAL NUMBER(20,7),
  L6_COEFCAP NUMBER(20,7),
  L6_NPFCANT NUMBER(20,7),
  L6_NPFVAL NUMBER(20,7),
  L6_PRETMMR NUMBER(20,7),
  L6_PRETMAT NUMBER(20,7),
  L6_VAR NUMBER(20,7),
  L6_EST NUMBER(20,7),
  L7_CAP NUMBER(20,7),
  L7_STOC NUMBER(20,7),
  L7_VANZ NUMBER(20,7),
  L7_TARGET NUMBER(20,7),
  L7_NPCANT NUMBER(20,7),
  L7_PRET NUMBER(20,7),
  L7_NPVAL NUMBER(20,7),
  L7_COEFCAP NUMBER(20,7),
  L7_NPFCANT NUMBER(20,7),
  L7_NPFVAL NUMBER(20,7),
  L7_PRETMMR NUMBER(20,7),
  L7_PRETMAT NUMBER(20,7),
  L7_VAR NUMBER(20,7),
  L7_EST NUMBER(20,7),
  L8_CAP NUMBER(20,7),
  L8_STOC NUMBER(20,7),
  L8_VANZ NUMBER(20,7),
  L8_TARGET NUMBER(20,7),
  L8_NPCANT NUMBER(20,7),
  L8_PRET NUMBER(20,7),
  L8_NPVAL NUMBER(20,7),
  L8_COEFCAP NUMBER(20,7),
  L8_NPFCANT NUMBER(20,7),
  L8_NPFVAL NUMBER(20,7),
  L8_PRETMMR NUMBER(20,7),
  L8_PRETMAT NUMBER(20,7),
  L8_VAR NUMBER(20,7),
  L8_EST NUMBER(20,7),
  L9_CAP NUMBER(20,7),
  L9_STOC NUMBER(20,7),
  L9_VANZ NUMBER(20,7),
  L9_TARGET NUMBER(20,7),
  L9_NPCANT NUMBER(20,7),
  L9_PRET NUMBER(20,7),
  L9_NPVAL NUMBER(20,7),
  L9_COEFCAP NUMBER(20,7),
  L9_NPFCANT NUMBER(20,7),
  L9_NPFVAL NUMBER(20,7),
  L9_PRETMMR NUMBER(20,7),
  L9_PRETMAT NUMBER(20,7),
  L9_VAR NUMBER(20,7),
  L9_EST NUMBER(20,7),
  L10_CAP NUMBER(20,7),
  L10_STOC NUMBER(20,7),
  L10_VANZ NUMBER(20,7),
  L10_TARGET NUMBER(20,7),
  L10_NPCANT NUMBER(20,7),
  L10_PRET NUMBER(20,7),
  L10_NPVAL NUMBER(20,7),
  L10_COEFCAP NUMBER(20,7),
  L10_NPFCANT NUMBER(20,7),
  L10_NPFVAL NUMBER(20,7),
  L10_PRETMMR NUMBER(20,7),
  L10_PRETMAT NUMBER(20,7),
  L10_VAR NUMBER(20,7),
  L10_EST NUMBER(20,7),
  L11_CAP NUMBER(20,7),
  L11_STOC NUMBER(20,7),
  L11_VANZ NUMBER(20,7),
  L11_TARGET NUMBER(20,7),
  L11_NPCANT NUMBER(20,7),
  L11_PRET NUMBER(20,7),
  L11_NPVAL NUMBER(20,7),
  L11_COEFCAP NUMBER(20,7),
  L11_NPFCANT NUMBER(20,7),
  L11_NPFVAL NUMBER(20,7),
  L11_PRETMMR NUMBER(20,7),
  L11_PRETMAT NUMBER(20,7),
  L11_VAR NUMBER(20,7),
  L11_EST NUMBER(20,7),
  L12_CAP NUMBER(20,7),
  L12_STOC NUMBER(20,7),
  L12_VANZ NUMBER(20,7),
  L12_TARGET NUMBER(20,7),
  L12_NPCANT NUMBER(20,7),
  L12_PRET NUMBER(20,7),
  L12_NPVAL NUMBER(20,7),
  L12_COEFCAP NUMBER(20,7),
  L12_NPFCANT NUMBER(20,7),
  L12_NPFVAL NUMBER(20,7),
  L12_PRETMMR NUMBER(20,7),
  L12_PRETMAT NUMBER(20,7),
  L12_VAR NUMBER(20,7),
  L12_EST NUMBER(20,7),
  L1_NPFVAL_ORIG NUMBER(20,7),
  L2_NPFVAL_ORIG NUMBER(20,7),
  L3_NPFVAL_ORIG NUMBER(20,7),
  L4_NPFVAL_ORIG NUMBER(20,7),
  L5_NPFVAL_ORIG NUMBER(20,7),
  L6_NPFVAL_ORIG NUMBER(20,7),
  L7_NPFVAL_ORIG NUMBER(20,7),
  L8_NPFVAL_ORIG NUMBER(20,7),
  L9_NPFVAL_ORIG NUMBER(20,7),
  L10_NPFVAL_ORIG NUMBER(20,7),
  L11_NPFVAL_ORIG NUMBER(20,7),
  L12_NPFVAL_ORIG NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  DENUMIRE VARCHAR2(200),
  DEN_CLASEA VARCHAR2(50),
  STIPCAP VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETVL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D9AC6FBE78CF2DBD01881C4C7F045974BEFFB2C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETVL (
  CODBUGETVL NUMBER(20,0),
  CODBUGETPROD NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7),
  ELEMENT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_BUGETVL_T</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A8BD1B13BEA045FCD8305C003E3C83B3207CD6B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_BUGETVL_T (
  ELEMENT VARCHAR2(250),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_C1_CANTCONTOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2C84A95A630AA39126B81E2A319CF0EEDF33B89C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_C1_CANTCONTOR (
  CODCONTRACT1 NUMBER(20,0),
  DATAREF DATE,
  CANT NUMBER(20,7),
  DATAINI DATE,
  IDXINI NUMBER(20,7),
  DATAFIN DATE,
  IDXFIN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAENSEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2979634968031BB10E90EE15E2B30DBB0EDF32BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAENSEC (
  CODCAENSEC NUMBER(20,0),
  CAEN NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAMERE_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8BA71153918CFAC0BF4798E8E3ACBA677E542055</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAMERE_LST (
  CODGEST NUMBER(20,0),
  LOCURI NUMBER(5,0),
  LOCLIB NUMBER(5,0),
  LOCREZ NUMBER(5,0),
  LOCCONTR NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAMPANII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9FBA5FB41CEA4D405A8D3F10809C11AF31D0A7D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAMPANII (
  CODCAMPANIE NUMBER(20,0),
  DENCAMPANIE VARCHAR2(200),
  OBIECTIV VARCHAR2(2000),
  TARGET VARCHAR2(200),
  DATAINIT DATE,
  DATAFIN DATE,
  CODMONEDA NUMBER(20,0),
  CODRESPONSABIL NUMBER(20,0),
  COSTESTIMAT NUMBER(20,7),
  VENITESTIMAT NUMBER(20,7),
  CODSUBUNITATE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAMPANIICOST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA83AAA768BFF23E8864C02A330E2BFCF783180B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAMPANIICOST (
  CODCAMPANIECOST NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  PREFIXDOC VARCHAR2(50),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAMPANIIPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8EABD7CABC1A64603065C6C5B709B97929990C1D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAMPANIIPART (
  CODCAMPANIEPART NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  CODEXTERN VARCHAR2(50),
  CODINTERN VARCHAR2(50),
  REGCOM VARCHAR2(20),
  CODFISCAL VARCHAR2(75),
  SELECTAT NUMBER(1,0),
  CODOPORTUNITATE NUMBER(20,0),
  OPORTUNITATE VARCHAR2(50),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CAMPANIIVENIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B11758EE3CBDB18818774DC6FD5A36C8EC6A83E2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CAMPANIIVENIT (
  CODCAMPANIEVENIT NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  PREFIXDOC VARCHAR2(50),
  CODPART NUMBER(20,0),
  VALFACT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANAMED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9D755FA624D9A08C1E2263BACF7F19D0369751FD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANAMED (
  CODCANAMED NUMBER(20,0),
  DATALISTA DATE,
  OBS VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANAMED1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>527734C17B6C362A59BC3058BFAA9C34D260343E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANAMED1 (
  CODCANAMED1 NUMBER(20,0),
  CODCANAMED NUMBER(20,0),
  CODCNPM VARCHAR2(20),
  CODCIM VARCHAR2(20),
  DENPRODUS VARCHAR2(250),
  FORMA VARCHAR2(250),
  CONCENTR VARCHAR2(150),
  FIRMA VARCHAR2(250),
  DCI VARCHAR2(250),
  AMBALAJ VARCHAR2(350),
  GRUPA VARCHAR2(100),
  PRETPROD NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRETAM NUMBER(20,7),
  STATUTFRM VARCHAR2(50),
  STATUTANM VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANAMEDT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AC121F7500B3206293533DA3424B64EAB7BE8443</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANAMEDT (
  COD_CNPM VARCHAR2(13),
  COD_CIM VARCHAR2(20),
  DEN_PRODUS VARCHAR2(58),
  FORMA VARCHAR2(28),
  CONCENTR VARCHAR2(19),
  AMB VARCHAR2(179),
  FIRMA_APP VARCHAR2(67),
  TARA_APP VARCHAR2(19),
  DCI VARCHAR2(55),
  GRUPA VARCHAR2(9),
  PRET_RID NUMBER(20,7),
  PRET_AM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>185E23FC28A3088D4D637064B39EAFA61B59562A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANTAR (
  CODCANTAR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TOTAL_KG NUMBER(20,7),
  TARA_KG NUMBER(20,7),
  NET_KG NUMBER(20,7),
  AMB1_COD NUMBER(20,0),
  AMB1_KG NUMBER(20,7),
  AMB1_CANT NUMBER(20,0),
  AMB1_RETURNABIL NUMBER(1,0),
  AMB2_COD NUMBER(20,0),
  AMB2_KG NUMBER(20,7),
  AMB2_CANT NUMBER(20,0),
  AMB2_RETURNABIL NUMBER(1,0),
  AMB3_COD NUMBER(20,0),
  AMB3_KG NUMBER(20,7),
  AMB3_CANT NUMBER(20,0),
  AMB3_RETURNABIL NUMBER(1,0),
  AMB4_COD NUMBER(20,0),
  AMB4_KG NUMBER(20,7),
  AMB4_CANT NUMBER(20,0),
  AMB4_RETURNABIL NUMBER(1,0),
  PALET_KG NUMBER(20,7),
  TRANSP1_COD NUMBER(20,0),
  TRANSP1_KG NUMBER(20,7),
  TRANSP1_CANT NUMBER(20,0),
  TRANSP2_COD NUMBER(20,0),
  TRANSP2_KG NUMBER(20,7),
  TRANSP2_CANT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  USERIDBLOCAJ NUMBER(20,0),
  ANULAT NUMBER(1,0),
  INDEXCANTAR NUMBER(2,0),
  RETUR NUMBER(1,0),
  SERIE NUMBER(20,0),
  IDCANTAR NUMBER(20,0),
  FURNIZOR NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  DESTINATIE NUMBER(1,0),
  CLIENT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODCMD1 NUMBER(20,0),
  AMB5_COD NUMBER(20,0),
  AMB5_KG NUMBER(20,7),
  AMB5_CANT NUMBER(20,0),
  AMB5_RETURNABIL NUMBER(1,0),
  AMB6_COD NUMBER(20,0),
  AMB6_KG NUMBER(20,7),
  AMB6_CANT NUMBER(20,0),
  AMB6_RETURNABIL NUMBER(1,0),
  ID_CANTARIRE VARCHAR2(20),
  TRANSPORTATOR VARCHAR2(50),
  NRVEHICOL VARCHAR2(20),
  NRREMORCA VARCHAR2(20),
  CANTDOC NUMBER(20,7),
  SERIEAVIZ VARCHAR2(20),
  LOT VARCHAR2(30),
  DENOBIECT VARCHAR2(200),
  AMB1_DEN VARCHAR2(200),
  AMB2_DEN VARCHAR2(200),
  AMB3_DEN VARCHAR2(200),
  AMB4_DEN VARCHAR2(200),
  TRANSP1_DEN VARCHAR2(200),
  TRANSP2_DEN VARCHAR2(200),
  ARECARNETDOC NUMBER(1,0),
  SERIETXT VARCHAR2(200),
  AMB5_DEN VARCHAR2(200),
  AMB6_DEN VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANTARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>09917A3BE400A707DB2FED2D94D7E8C0B106891B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANTARE (
  CODCANTAR NUMBER(20,0),
  TIP NUMBER(5,0),
  DENUMIRE VARCHAR2(50),
  IP VARCHAR2(20),
  DIREXPORT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CANTARIRI_PE_LOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BCFE02C2C6FF5594DA88AD0504EE66C68ACA9675</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CANTARIRI_PE_LOT (
  CODOBIECT NUMBER(20,0),
  NETKG NUMBER(20,7),
  CODDOC1 NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  SERIE NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  CODCMD NUMBER(20,0),
  CODCANTAR NUMBER(20,0),
  COMANDA VARCHAR2(200),
  ID_CANTARIRE VARCHAR2(20),
  NRAVIZ NUMBER(20,0),
  SERIEAVIZ VARCHAR2(20),
  TRANSPORTATOR VARCHAR2(50),
  NRVEHICOL VARCHAR2(20),
  NRREMORCA VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CARDURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9DEFE354CBDDFD475F6CD877A410F7BF10637952</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CARDURI (
  CODCARD NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  DENUMIRE VARCHAR2(250),
  OBS VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CASHFLOW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F5C5A6D79EC3C8B2A7FD6A178709DA1873E95CC3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CASHFLOW (
  CODCASHFLOW NUMBER(20,0),
  DATA DATE,
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  VALOAREDEREPARTIZAT NUMBER(20,7),
  APROBAT NUMBER(1,0),
  ZILE NUMBER(5,0),
  CODMONEDA NUMBER(20,0),
  SIMBOLMONEDA VARCHAR2(10),
  CODBANK NUMBER(20,0),
  NRCONT VARCHAR2(30),
  SOLDCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CASHFLOW1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>472BBC5F5E32761FF9F60F952A5BAFF562686B9F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CASHFLOW1 (
  CODCASHFLOW1 NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RESTCONV NUMBER(20,7),
  DATAPROPUSA DATE,
  CODOP1 NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  TIP NUMBER(1,0),
  OBS VARCHAR2(300),
  DENPART VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  SIMBOLMONEDA VARCHAR2(10),
  TIPSTR VARCHAR2(50),
  DENCENTRUCOST VARCHAR2(200),
  DENNODANALIZA VARCHAR2(100),
  SIMBOLCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CASHFLOW2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B76130BFCEEA22D0DE3C34BC3AEFAB434A31057F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CASHFLOW2 (
  CODCASHFLOW2 NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RESTCONV NUMBER(20,7),
  DATAPROPUSA DATE,
  CODOP1 NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  TIP NUMBER(1,0),
  OBS VARCHAR2(300),
  DENPART VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  SIMBOLMONEDA VARCHAR2(10),
  TIPSTR VARCHAR2(50),
  DENCENTRUCOST VARCHAR2(200),
  DENNODANALIZA VARCHAR2(2),
  SIMBOLCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CASTOT_PREPAY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7496D6E0B56701D0988AE8226AFD7151967565C9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CASTOT_PREPAY (
  COD_CASTOTPREPAY NUMBER(20,0),
  FURNIZOR VARCHAR2(50),
  IDFURNIZOR NUMBER(10,0),
  SERVICIU VARCHAR2(50),
  IDSERVICIU VARCHAR2(50),
  TELEFON VARCHAR2(20),
  MONEDA VARCHAR2(5),
  VALOARE NUMBER(20,7),
  VALOARERON NUMBER(20,7),
  TRACKINGNUMBER VARCHAR2(20),
  DATATRANZACTIE TIMESTAMP(6),
  PINCODE VARCHAR2(20),
  PINCODEVALID VARCHAR2(10),
  LISTATCM NUMBER(1,0),
  LISTATCHITANTA NUMBER(1,0),
  CODEMULARE NUMBER(20,0),
  JSONRESPONSE CLOB,
  COD_SCALA VARCHAR2(25),
  PINCODE_SERIALNO VARCHAR2(25),
  FOOTER_TEXT CLOB,
  IDTRANZACTIE VARCHAR2(25),
  NRTRANZWME VARCHAR2(15),
  TIPINCARCARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CASTOT_UTILITY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9ED73462468038411F9A7936A93AD6DE0559230</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CASTOT_UTILITY (
  COD_CASTOTUTILITY NUMBER(20,0),
  FURNIZOR VARCHAR2(80),
  SERVICIU VARCHAR2(80),
  DEPLATA NUMBER(20,7),
  PLATIT NUMBER(20,7),
  PLATIT_TEXT VARCHAR2(80),
  COD_SCALA VARCHAR2(50),
  DATATRANZACTIE TIMESTAMP(6),
  CODCLIENT VARCHAR2(50),
  TELEFON VARCHAR2(20),
  NRFACTURA VARCHAR2(30),
  DATAFACTURA TIMESTAMP(6),
  SUCURSALA VARCHAR2(30),
  ATMCOD VARCHAR2(30),
  CUSTOMCODE1 VARCHAR2(30),
  CUSTOMPAYMENTFIELD3 VARCHAR2(30),
  JSONRESPONSE CLOB,
  LISTAT NUMBER(1,0),
  LISTATCM NUMBER(1,0),
  CODEMULARE NUMBER(20,0),
  CARD NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CATEGARTTI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FCC3FA6725755676FB16C05993FE8C4F643BC929</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CATEGARTTI (
  CODCATEGARTTI NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  SIMBOLP NUMBER(20,0),
  SIMBOLN NUMBER(20,0),
  SIMBOLP1 NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  DENUMIREP VARCHAR2(200),
  CODP NUMBER(20,0),
  CODN_STOC NUMBER(20,0),
  CODN_SERV NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CATEGCONST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7DC6E4CB4A32890877093FEDE003FF71D675D1CC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CATEGCONST (
  CODCATEG NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  INDEXLOCAL VARCHAR2(10),
  TIPCATEG VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CDS_BILANT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>673DAB6671214ABA1EB166F369A7EA020CB20F1A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CDS_BILANT (
  COD NUMBER(20,0),
  SCONT VARCHAR2(30),
  DCONT VARCHAR2(100),
  CLASA NUMBER(20,0),
  TCONT NUMBER(20,0),
  TRD NUMBER(20,7),
  TRC NUMBER(20,7),
  SOLDFIND NUMBER(20,7),
  SOLDFINC NUMBER(20,7),
  CODREF NUMBER(20,0),
  SREF VARCHAR2(30),
  TREF NUMBER(20,0),
  NIVEL NUMBER(20,0),
  NRANALITICE NUMBER(20,0),
  REFNIVEL NUMBER(20,0),
  REFNRANALITICE NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,7),
  PRECEDENTD NUMBER(20,7),
  CURENTD NUMBER(20,7),
  SOLDIC NUMBER(20,7),
  PRECEDENTC NUMBER(20,7),
  CURENTC NUMBER(20,7),
  ASOLDID NUMBER(20,7),
  ASOLDIC NUMBER(20,7),
  APRECEDENTD NUMBER(20,7),
  ACURENTD NUMBER(20,7),
  APRECEDENTC NUMBER(20,7),
  ACURENTC NUMBER(20,7),
  ASOLDFIND NUMBER(20,7),
  ASOLDFINC NUMBER(20,7),
  SIIPD NUMBER(20,7),
  SIIPC NUMBER(20,7),
  SIICD NUMBER(20,7),
  SIICC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CENTRALIZARENC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3AB7495DFDBF1225341A9CE885AE45C0D1466C33</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CENTRALIZARENC (
  CODCENTRALIZARE NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTASOC NUMBER(20,0),
  CODOBIECTASOCSEC NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DIFERENTE NUMBER(20,7),
  TIPARTICOL NUMBER(20,0),
  FACTURAT NUMBER(20,7),
  PROCTVA NUMBER(6,3),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(450),
  CANT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DENUMIREASOC VARCHAR2(200),
  DENUMIREASOCSEC VARCHAR2(200),
  DEN_UM1 VARCHAR2(15),
  PARITATE NUMBER(20,7),
  CORECTII NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CENTRALIZARENC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8A3CA7DE987BCADBA42C9E798C0546CC80F283FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CENTRALIZARENC_MAN (
  CODCENTRALIZARE NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTASOC NUMBER(20,0),
  CODOBIECTASOCSEC NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DIFERENTE NUMBER(20,7),
  TIPARTICOL NUMBER(20,0),
  FACTURAT NUMBER(20,7),
  PROCTVA NUMBER(6,3),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(450),
  CANT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DENUMIREASOC VARCHAR2(200),
  DENUMIREASOCSEC VARCHAR2(200),
  DEN_UM1 VARCHAR2(15),
  PARITATE NUMBER(20,7),
  CORECTII NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CENTRECOST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>45B048FFDCA9E21254BC23AF004963FD7A389E57</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CENTRECOST (
  CODCENTRU NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  DENUMIRE VARCHAR2(100),
  TIPCHELT NUMBER(2,0),
  TIPALOC NUMBER(2,0),
  TIP NUMBER(1,0),
  INACTIV NUMBER(1,0),
  DOMENIU VARCHAR2(20),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CENTRECOSTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>814B8A31346E7E7CF1E6701981FA4B6694F66FBA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CENTRECOSTA (
  CODCENTRUA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  NODMAXIMANALIZA1 NUMBER(20,0),
  CODDESCRIPTOR NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CERTIF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5064939A178E2D6A97FE3821561F2DF563452A76</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CERTIF (
  CODCERTIF NUMBER(20,0),
  NRCERTIF VARCHAR2(100),
  DATAPRIMIRE DATE,
  FISIER BLOB,
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  NUMEFISIER VARCHAR2(250),
  EXT VARCHAR2(4),
  SUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  PROVENIENTA VARCHAR2(250),
  CODTARA NUMBER(20,0),
  OBS VARCHAR2(250),
  TIPPART NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DENOBIECT VARCHAR2(250),
  PRODUCTIE NUMBER(1,0),
  CODPRODUCATOR NUMBER(20,0),
  CODEXTERN_OBJ VARCHAR2(80),
  CODINTERN_OBJ VARCHAR2(80),
  PREFIXDOC_INTR VARCHAR2(2),
  NRDOC_INTR NUMBER(20,0),
  DATADOC_INTR DATE,
  ARECARNETDOC NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGACTIONS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>468A6BFDF0FDC75653E04A4D49AE26AAC0871A39</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CFGACTIONS (
  CODCFGACTIONS NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  TIPSQL NUMBER(1,0),
  TIP NUMBER(1,0),
  ID NUMBER(5,0),
  SQLITE CLOB,
  MESAJ VARCHAR2(150)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGACTIONS_TMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5BC9C5BB97BE69E239B7BB2F23C3A1F875857992</HASHVAL>
  <TEXT>CREATE TABLE TMP_CFGACTIONS_TMP (
  CODCFGACTIONS NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  TIPSQL NUMBER(1,0),
  TIP NUMBER(1,0),
  ID NUMBER(5,0),
  SQLITE CLOB,
  MESAJ VARCHAR2(150)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6930193A8F3C1591B832D0B94A1F50614A14FC2D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CFGTABLES (
  CODCFGTABLE NUMBER(20,0),
  NUMETABELA VARCHAR2(20),
  TIPCONFIG NUMBER(1,0),
  MASTER VARCHAR2(20),
  LINKKEY VARCHAR2(20),
  TIPLINK NUMBER(1,0),
  DESCRIERE VARCHAR2(100),
  SUPLIMSQL CLOB,
  UPDATESQL CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>98AE44CDFAEEADCA2B7D760ECF0206AD3F4554AA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CFGTABLES1 (
  CODCFGTABLE1 NUMBER(20,0),
  CODCFGTABLE NUMBER(20,0),
  INDEXLOCAL NUMBER(6,0),
  NUMECAMP VARCHAR2(20),
  CAPTION VARCHAR2(30),
  TIP VARCHAR2(1),
  MARIME NUMBER(6,0),
  ZECIMALE NUMBER(6,0),
  COLWIDTH NUMBER(6,0),
  COLOR NUMBER(10,0),
  OBLIGATORIU NUMBER(1,0),
  NOMLINK NUMBER(10,0),
  LOOKUPDISPLAY VARCHAR2(50),
  TIPFILTRUAFIS NUMBER(2,0),
  FILTRUAFIS VARCHAR2(2000),
  HASTOTAL NUMBER(1,0),
  TMP NUMBER(1,0),
  TOBEUPDATED NUMBER(1,0),
  SQLONCHANGE VARCHAR2(3000),
  VALPREDEF VARCHAR2(1),
  REFERINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES1_TMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6FE6B4593C172048DB34EAC33110D6B9E1DD70E</HASHVAL>
  <TEXT>CREATE TABLE TMP_CFGTABLES1_TMP (
  CODCFGTABLE1 NUMBER(20,0),
  CODCFGTABLE NUMBER(20,0),
  INDEXLOCAL NUMBER(6,0),
  NUMECAMP VARCHAR2(20),
  CAPTION VARCHAR2(30),
  TIP VARCHAR2(1),
  MARIME NUMBER(6,0),
  ZECIMALE NUMBER(6,0),
  COLWIDTH NUMBER(6,0),
  COLOR NUMBER(10,0),
  OBLIGATORIU NUMBER(1,0),
  NOMLINK NUMBER(10,0),
  LOOKUPDISPLAY VARCHAR2(50),
  TIPFILTRUAFIS NUMBER(2,0),
  FILTRUAFIS VARCHAR2(2000),
  HASTOTAL NUMBER(1,0),
  TMP NUMBER(1,0),
  TOBEUPDATED NUMBER(1,0),
  SQLONCHANGE VARCHAR2(3000),
  VALPREDEF VARCHAR2(1),
  REFERINTE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FEF87867C36E61221677D038076F56E432B24841</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CFGTABLES2 (
  CODCFGTABLE2 NUMBER(20,0),
  CODCFGTABLE1 NUMBER(20,0),
  VALOARE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES2_TMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F3A9D64F6A0504F50A5DD899C3DB3FA626DED0A</HASHVAL>
  <TEXT>CREATE TABLE TMP_CFGTABLES2_TMP (
  CODCFGTABLE2 NUMBER(20,0),
  CODCFGTABLE1 NUMBER(20,0),
  VALOARE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CFGTABLES_TMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EC85959C574405FC828C4AA599F11938EB2688FE</HASHVAL>
  <TEXT>CREATE TABLE TMP_CFGTABLES_TMP (
  CODCFGTABLE NUMBER(20,0),
  NUMETABELA VARCHAR2(20),
  TIPCONFIG NUMBER(1,0),
  MASTER VARCHAR2(20),
  LINKKEY VARCHAR2(20),
  TIPLINK NUMBER(1,0),
  DESCRIERE VARCHAR2(100),
  SUPLIMSQL CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D56BA7A8A536F7E1EFFC6671B343CF3D000E27FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS (
  CODCHELTAVANS NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  ANINCEPUT NUMBER(5,0),
  LUNAINCEPUT NUMBER(2,0),
  CODIOART NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  OBSERVATII VARCHAR2(100),
  CODIES1 NUMBER(20,0),
  ISVENIT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  CODSUBUNIT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  OBS VARCHAR2(200),
  CODPART NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  CODINTR NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(30),
  TIPINTERVAL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FA5435576A485C9EB0FC9253B511EC0F4B037EAE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS1 (
  CODCHELTAVANS1 NUMBER(20,0),
  CODCHELTAVANS NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DURATAN NUMBER(10,0),
  DURATAF NUMBER(10,0),
  DFBLOCAT NUMBER(1,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  AMO NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  DATAENDNOUA DATE,
  DATAENDBLOCATA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0),
  CENTRUBLOCAT NUMBER(1,0),
  CODGESTBLOCAT NUMBER(1,0),
  CODANALIZABLOCAT NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  NRCMD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS_INTR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8A2437966A57B449EF4C6004FAF2581C7A1855CC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS_INTR (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(100),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS_NC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3A50A245E5C5C1C19D8961BBF35CB0F212B3F172</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS_NC1 (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(100),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS_SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BE75E5B7A9AFCA071C6D3E65B4571DB9F6712150</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS_SUB (
  CODSUBUNIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTAVANS_TREZOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6A74F17352BDE50F2F6DC105ED9561B4490EC4B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTAVANS_TREZOR (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(100),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTOPER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B60E68EFC306984DF5ACCFC47F8E99484C15AF72</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTOPER (
  CODCHELTOPER NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ANSTOP NUMBER(4,0),
  LUNASTOP NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CHELTOPER1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AC55AF5C37F3EEBF96B6A44448A9F8E76144514B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CHELTOPER1 (
  CODCHELTOPER1 NUMBER(20,0),
  CODCHELTOPER NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DEN_UM VARCHAR2(15),
  DEN_OBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  DEN_CLASEA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CLASEADEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>29EF14F3A509D7F40C971ED796FFA852362175F1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CLASEADEDICATE (
  CODCLASEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CLASEPDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF3BD7F8DA422981EA155AE1423E27C7A1429B81</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CLASEPDEDICATE (
  CODCLASEP NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>20BCA10F57B8520F24BB4AB5357CCFDB4FEB4AA3</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMD (
  CODOBIECT NUMBER(20,0),
  CANTC NUMBER(20,7),
  CANTA NUMBER(20,7),
  RESTA NUMBER(20,7),
  TIP VARCHAR2(20),
  USERID NUMBER(20,0),
  AUXFIELD VARCHAR2(2500),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAD39ED858B086B22097B7749036FDCDD62E6DE9</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMD1 (
  CODOBIECT NUMBER(20,0),
  CANTC NUMBER(20,7),
  CANTA NUMBER(20,7),
  RESTA NUMBER(20,7),
  TIP VARCHAR2(20),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11B57077501C6C32EB8E1BA068EB1D128E738557</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMD2 (
  CODOBIECT NUMBER(20,0),
  CANTC NUMBER(20,7),
  CANTA NUMBER(20,7),
  RESTA NUMBER(20,7),
  TIP VARCHAR2(20),
  USERID NUMBER(20,0),
  AUXFIELD VARCHAR2(2500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDAPROBARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BACB10FE8D271A0988FAA0A7E87D8D1130728BF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDAPROBARI (
  COD NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  NIVEL NUMBER(3,0),
  STARE NUMBER(20,0),
  OBS VARCHAR2(100),
  USERID NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDAVANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB41396BAE18E884F4B04B86DE5BAE639DFD166E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDAVANS (
  CODCMDAVANS NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODIESAVANS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDGANTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F37E0C856ED3AE4D43C0BF065B61BBDB728236D4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDGANTT (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODCOMANDA NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  PRIORITATE NUMBER(5,0),
  DATASTART DATE,
  TERMEN DATE,
  CANTLANSAT NUMBER(15,2),
  DOCUMENT VARCHAR2(83),
  DATADOC DATE,
  DENOBIECT VARCHAR2(200),
  UM VARCHAR2(15),
  DEN_UM1 VARCHAR2(15),
  CODLM NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CODOPERATIE NUMBER(20,0),
  OPERATIE VARCHAR2(200),
  DENRETETA VARCHAR2(250),
  CODPROIECT NUMBER(20,0),
  DENPROIECT VARCHAR2(100),
  NODPARINTE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  NIVELNOD NUMBER(10,0),
  POZNOD NUMBER(10,0),
  CODCMD1PARINTE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  LOCMUNCA VARCHAR2(250),
  TOTALORE NUMBER(10,2),
  OREGANTT NUMBER(10,3),
  TU NUMBER(10,3),
  NROPER NUMBER(10,0),
  CODCOMANDACLI NUMBER(20,0),
  DOCUMENTCLI VARCHAR2(83),
  DATADOCCC DATE,
  CODCOMANDACLI1 NUMBER(20,0),
  DATASTARTCC DATE,
  TERMENCC DATE,
  DEN_PART VARCHAR2(100),
  DENPRODUS VARCHAR2(200),
  UMPRODUS VARCHAR2(15),
  CANTPRODUS NUMBER(20,7),
  INCEPEREOP NUMBER(20,7),
  INCEPERENOD NUMBER(20,7),
  DECALAJOP NUMBER(2,0),
  DECALAJNOD NUMBER(2,0),
  INDEXPARINTE VARCHAR2(50),
  TIPDOC NUMBER(10,0),
  FIX NUMBER(1,0),
  CODMAN NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>763A83FE07B3D11A5514AE34F9B044B2B5BB5100</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDLINK (
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE,
  TERMEN DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BC12D722DA15B7CABCA5ADEBE942CA6D194247BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDLINK_INITIAL (
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDLIVRLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>823022EE4B0525820DE6F8DED01B6B7084E820EA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDLIVRLINK (
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE,
  TERMENCOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDLIVRLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10C7B7689B6B5BF1833D2EA9D5715B7F4B5F33EC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDLIVRLINK_INITIAL (
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE,
  TERMENCOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDPRODMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2389D532D80D55D34150498C0C781EEA68B3164E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDPRODMAN (
  CODCMDPRODMAN NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODMAN NUMBER(20,0),
  NROP NUMBER(10,0),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DSV NUMBER(20,7),
  BPS NUMBER(20,7),
  TPI NUMBER(20,7),
  OBS VARCHAR2(1000),
  DETALII NUMBER(10,0),
  FIX NUMBER(1,0),
  NIVEL NUMBER(5,0),
  DATASTART DATE,
  CODCOMANDA3 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  COEFBPS NUMBER(1,0),
  DEN_OPERATIE VARCHAR2(250),
  DEN_LOCMUNCA VARCHAR2(250),
  DIFICULTATE VARCHAR2(250),
  TARIF NUMBER(20,7),
  ORASTART VARCHAR2(5),
  DURATA NUMBER(20,7),
  UTILAJ VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDPRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0BD5530989C98D70AD4E701E9CFF7CC0A632366F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDPRODMAT (
  CODCMDPRODMAT NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  REZIDUU NUMBER(1,0),
  CODPRODMAT NUMBER(20,0),
  PARITATEECHIV NUMBER(20,7),
  TIPECHIV NUMBER(1,0),
  CUMSEC NUMBER(20,0),
  CCANT NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CODCOMANDA3 NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DEN_OBIECT VARCHAR2(250),
  DENUM VARCHAR2(100),
  REZERVAT NUMBER(20,7),
  NECESAR NUMBER(20,7),
  NECESARINI NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PARITATE NUMBER(20,7),
  CODOBIECTORIG NUMBER(20,0),
  DEN_ORIG VARCHAR2(250),
  CODATRIB NUMBER(20,0),
  TIPCOMPONENT VARCHAR2(250),
  ALTEREZERVARI NUMBER(20,7),
  STOC NUMBER(20,7),
  NECESARCALC NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  CODPRODGEST NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  CODINTERNEKIV VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  CODEXTERNEKIV VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDPRODREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>00C7C280A73C0BC844395CEA2B827983DB522AE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMDPRODREZ (
  CODCMDPRODREZ NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CODCOMANDA3 NUMBER(20,0),
  DEN_OBIECT VARCHAR2(250),
  DEN_UM VARCHAR2(100),
  TIP NUMBER(1,0),
  REZIDUU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMDTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AA7BB9373FE1149F987243F893E5711710DE8385</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMDTL (
  CODOBIECT NUMBER(20,0),
  CANTC NUMBER(20,7),
  CANTA NUMBER(20,7),
  RESTA NUMBER(20,7),
  TIP NUMBER(5,0),
  USERID NUMBER(20,0),
  CODCMDTL NUMBER(20,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD_PLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F76A9823850AD7144F3672406ECE1F109CDE0ED</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMD_PLUNA (
  CODCOMANDA1 NUMBER(20,0),
  CANT1 NUMBER(20,7),
  CANT2 NUMBER(20,7),
  CANT3 NUMBER(20,7),
  CANT4 NUMBER(20,7),
  TERMEN DATE,
  WEEK NUMBER(2,0),
  CODPROGRAMF1 NUMBER(20,0),
  USERID NUMBER(20,0),
  TIP NUMBER(5,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD_PLUNA2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C0298017413514C5BC4CA14F006AE0FC85E8421</HASHVAL>
  <TEXT>CREATE TABLE TMP_CMD_PLUNA2 (
  CODCOMANDA1 NUMBER(20,0),
  CANT1 NUMBER(20,7),
  CANT2 NUMBER(20,7),
  CANT3 NUMBER(20,7),
  CANT4 NUMBER(20,7),
  TERMEN DATE,
  WEEK NUMBER(2,0),
  CODPROGRAMF1 NUMBER(20,0),
  USERID NUMBER(20,0),
  TIP NUMBER(5,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD_TMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>698B62B51D8D782256B1E59DA54A4E1ABC8B2F61</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMD_TMP (
  CODOBIECT NUMBER(20,0),
  RESTA NUMBER(20,7),
  TIP VARCHAR2(20),
  DATADOC DATE,
  CANTC NUMBER(20,7),
  CANTA NUMBER(20,7),
  AUXFIELD VARCHAR2(2500),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODSUBUNIT NUMBER(20,0),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CMD_TMP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F7078B4B588B04FFFF8F223DA87C0D81AA448AD6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CMD_TMP1 (
  COD1 NUMBER(20,0),
  VAL NUMBER(20,7),
  TIP VARCHAR2(20),
  COD2 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CODCONT_CONST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC1EB694ED4592FA05E8056B23644318F319EC13</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CODCONT_CONST (
  CODCONT NUMBER(20,0),
  ESTEOBINV NUMBER(1,0),
  ESTEMIFIX NUMBER(1,0),
  ESTEMIFIXLEASING NUMBER(1,0),
  ESTEAMBALAJ NUMBER(1,0),
  ESTEPRODUS NUMBER(1,0),
  ESTEMATERIAL NUMBER(1,0),
  ESTESTOPAJ NUMBER(1,0),
  ESTECHELTAVANS NUMBER(1,0),
  ESTECUSTODIE NUMBER(1,0),
  ESTEIMBUNATATIREMIFIX NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CODEXTALT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2116342C6F6C08FDFEC3023A070027BDDA3745F1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CODEXTALT (
  COD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CODINTALT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FAADBC98B626B342874C33E71C44D8E952A58105</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CODINTALT (
  COD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>74A40562B226276B9AC8572F9A1F576E746D5486</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA (
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODCMDPARINTE NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  VALDISCOUNT NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODGEST NUMBER(20,0),
  INCHISA NUMBER(1,0),
  SUBUNITSURSA NUMBER(20,0),
  SCADENTAV NUMBER(5,0),
  SERIADOC VARCHAR2(20),
  USERIDBLOCAJ NUMBER(20,0),
  NRI VARCHAR2(30),
  CODTRASEULIVR NUMBER(20,0),
  ORDINELIVRARE NUMBER(20,0),
  MIJLTRANSP NUMBER(20,0),
  INSOTITOR NUMBER(20,0),
  DISPLIVRARE NUMBER(1,0),
  VERIFICAT NUMBER(1,0),
  CODIES NUMBER(20,0),
  FARATRANSPORT NUMBER(1,0),
  PLATAPELOC NUMBER(1,0),
  DATAINREG TIMESTAMP(6),
  FACTURABIL NUMBER(1,0),
  CURS NUMBER(20,7),
  SCHIMB NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  IDIMPORT VARCHAR2(30),
  LISTAT NUMBER(10,0),
  FACTURA_APL_EXT NUMBER(1,0),
  CODPERS_APL_EXT NUMBER(20,0),
  LOT NUMBER(10,0),
  NRTRANSP VARCHAR2(30),
  CODIESAVANS NUMBER(20,0),
  FARAFACTURA NUMBER(1,0),
  DINONLINE NUMBER(1,0),
  PRETCUAMANUNT NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  TIPTRANZACTIE NUMBER(1,0),
  SUBUNITDEST NUMBER(20,0),
  NRMAXAPROBARI NUMBER(10,0),
  STADIUWMS NUMBER(2,0),
  CODPERSC NUMBER(20,0),
  MOTIVINCHIDERE VARCHAR2(80),
  CODPARTCOMIS NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  GRATIE NUMBER(10,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  MODINCHIDERE NUMBER(1,0),
  PLATFORMA_ONLINE NUMBER(2,0),
  REMORCA NUMBER(20,0),
  ROTEFACT NUMBER(1,0),
  NUMEDELEGAT VARCHAR2(420),
  SOLDPART NUMBER(20,7),
  ARECARNETDOC NUMBER(1,0),
  DISCOUNTPART NUMBER(20,7),
  COLDISCPART NUMBER(1,0),
  PRETPROMOAPLICAT NUMBER(1,0),
  TIPCUSTODIE NUMBER(1,0),
  VALOAREAVANS NUMBER(20,7),
  GESTLIVRARESEDIU NUMBER(20,0),
  SCADENTESETATEMANUAL NUMBER(1,0),
  SCADENTAC NUMBER(5,0),
  CODNPARCAUT NUMBER(20,0),
  KMBORD NUMBER(10,0),
  TIPCOMSA NUMBER(1,0),
  CODSUPERVISOR NUMBER(20,0),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  VALTVA NUMBER(20,7),
  DISCTVA NUMBER(20,7),
  VALMIN NUMBER(20,7),
  VALADAOS NUMBER(20,7),
  PROCADAOS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C09677D511C00E7ECC1C94DF3E5F1BE763F2476</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA1 (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTACCEPTAT NUMBER(20,7),
  CULANSARE NUMBER(1,0),
  RESTLANSAT NUMBER(20,7),
  TERMEN DATE,
  ANULAT NUMBER(1,0),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  CODCATPRET NUMBER(20,0),
  CONSUM NUMBER(20,0),
  REZERVATINI NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPSURSA NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  DATAINCARCARII DATE,
  CANTRETURNAT NUMBER(20,7),
  ACCEPTUM1 NUMBER(20,7),
  TIPPLATA NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODRETETA NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  PUCORELAT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  POZITIE NUMBER(10,0),
  TIPLIVRARE NUMBER(1,0),
  CODANALIZANOD NUMBER(20,0),
  EXCEPTIONAL NUMBER(1,0),
  CODCONTRACT1 NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODNORMA NUMBER(20,0),
  MODINCHIDERE NUMBER(1,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODMIFIX NUMBER(20,0),
  TIPLINIESA NUMBER(1,0),
  PRIORITATE NUMBER(5,0),
  DATASTART TIMESTAMP(6),
  CODPROMO1 NUMBER(20,0),
  SUBUNITSURSA NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  DISCMANUAL NUMBER(1,0),
  FURNIZOR NUMBER(20,0),
  PUPROD NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(25),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(30),
  REZERVAT NUMBER(20,7),
  NECESAR NUMBER(20,7),
  NECESARINI NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  DENUM1 VARCHAR2(25),
  TVA NUMBER(20,7),
  PULEI NUMBER(20,7),
  DENUMCORELAT VARCHAR2(25),
  TIPRETETA NUMBER(1,0),
  REZERVARI VARCHAR2(20),
  LANSARI NUMBER(20,0),
  PRODUSPROPRIU NUMBER(10,0),
  CODCRITERIU NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  PARTENER VARCHAR2(100),
  CANTCERT NUMBER(20,7),
  CANTESTIMAT NUMBER(20,7),
  STOCDEPOZIT NUMBER(20,7),
  STOCSECTIE NUMBER(20,7),
  RESTDPS NUMBER(20,7),
  RESTCMD NUMBER(20,7),
  CONTRACT NUMBER(20,0),
  PROMOTIE NUMBER(1,0),
  INTERVENTIE VARCHAR2(200),
  UTILAJ VARCHAR2(200),
  CODUTILAJ2C NUMBER(20,0),
  FARANIVELAPROB NUMBER(1,0),
  PUREAL NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  REZCMDINI NUMBER(20,7),
  CMDCLILANS NUMBER(10,0),
  CMDINTLANS NUMBER(10,0),
  INFOMF VARCHAR2(100),
  CONTSERV NUMBER(20,0),
  ESTEIMBMF NUMBER(1,0),
  DENLAPART VARCHAR2(200),
  PRETOFE NUMBER(20,7),
  SOLDBUGET NUMBER(20,7),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  PUMIN NUMBER(20,7),
  VALADAOS NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  PROCADAOS1 NUMBER(20,7),
  VOUCHERCADOU NUMBER(1,0),
  CODEXTERNLAPART VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DFDB124EC958992D2AB4A6360D90144E3F0205F2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA1_INITIAL (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTACCEPTAT NUMBER(20,7),
  CULANSARE NUMBER(1,0),
  RESTLANSAT NUMBER(20,7),
  TERMEN DATE,
  ANULAT NUMBER(1,0),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  CODCATPRET NUMBER(20,0),
  CONSUM NUMBER(20,0),
  REZERVATINI NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPSURSA NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  DATAINCARCARII DATE,
  CANTRETURNAT NUMBER(20,7),
  ACCEPTUM1 NUMBER(20,7),
  TIPPLATA NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODRETETA NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  PUCORELAT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  POZITIE NUMBER(10,0),
  TIPLIVRARE NUMBER(1,0),
  CODANALIZANOD NUMBER(20,0),
  EXCEPTIONAL NUMBER(1,0),
  CODCONTRACT1 NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODNORMA NUMBER(20,0),
  MODINCHIDERE NUMBER(1,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODMIFIX NUMBER(20,0),
  TIPLINIESA NUMBER(1,0),
  PRIORITATE NUMBER(5,0),
  DATASTART TIMESTAMP(6),
  CODPROMO1 NUMBER(20,0),
  SUBUNITSURSA NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  DISCMANUAL NUMBER(1,0),
  FURNIZOR NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(25),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(30),
  REZERVAT NUMBER(20,7),
  NECESAR NUMBER(20,7),
  NECESARINI NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  DENUM1 VARCHAR2(25),
  TVA NUMBER(20,7),
  PULEI NUMBER(20,7),
  DENUMCORELAT VARCHAR2(25),
  TIPRETETA NUMBER(1,0),
  REZERVARI VARCHAR2(20),
  LANSARI NUMBER(20,0),
  PRODUSPROPRIU NUMBER(10,0),
  CODCRITERIU NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  PARTENER VARCHAR2(100),
  CANTCERT NUMBER(20,7),
  CANTESTIMAT NUMBER(20,7),
  STOCDEPOZIT NUMBER(20,7),
  STOCSECTIE NUMBER(20,7),
  RESTDPS NUMBER(20,7),
  RESTCMD NUMBER(20,7),
  CONTRACT NUMBER(20,0),
  PROMOTIE NUMBER(1,0),
  INTERVENTIE VARCHAR2(200),
  UTILAJ VARCHAR2(200),
  CODUTILAJ2C NUMBER(20,0),
  FARANIVELAPROB NUMBER(1,0),
  PUREAL NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  REZCMDINI NUMBER(20,7),
  CMDCLILANS NUMBER(10,0),
  CMDINTLANS NUMBER(10,0),
  INFOMF VARCHAR2(100),
  CONTSERV NUMBER(20,0),
  ESTEIMBMF NUMBER(1,0),
  DENLAPART VARCHAR2(200),
  PRETOFE NUMBER(20,7),
  SOLDBUGET NUMBER(20,7),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  PUMIN NUMBER(20,7),
  VALADAOS NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  PROCADAOS1 NUMBER(20,7),
  VOUCHERCADOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>765CB2C6271E8D482F2080BDAD3D90E1121638AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA1_MAN (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTACCEPTAT NUMBER(20,7),
  CULANSARE NUMBER(1,0),
  RESTLANSAT NUMBER(20,7),
  TERMEN DATE,
  ANULAT NUMBER(1,0),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  CODCATPRET NUMBER(20,0),
  CONSUM NUMBER(20,0),
  REZERVATINI NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPSURSA NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  DATAINCARCARII DATE,
  CANTRETURNAT NUMBER(20,7),
  ACCEPTUM1 NUMBER(20,7),
  TIPPLATA NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODRETETA NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  PUCORELAT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  POZITIE NUMBER(10,0),
  TIPLIVRARE NUMBER(1,0),
  CODANALIZANOD NUMBER(20,0),
  EXCEPTIONAL NUMBER(1,0),
  CODCONTRACT1 NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODNORMA NUMBER(20,0),
  MODINCHIDERE NUMBER(1,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODMIFIX NUMBER(20,0),
  TIPLINIESA NUMBER(1,0),
  PRIORITATE NUMBER(5,0),
  DATASTART TIMESTAMP(6),
  CODPROMO1 NUMBER(20,0),
  SUBUNITSURSA NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(25),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(30),
  REZERVAT NUMBER(20,7),
  NECESAR NUMBER(20,7),
  NECESARINI NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  DENUM1 VARCHAR2(25),
  TVA NUMBER(20,7),
  PULEI NUMBER(20,7),
  DENUMCORELAT VARCHAR2(25),
  TIPRETETA NUMBER(1,0),
  REZERVARI VARCHAR2(20),
  LANSARI NUMBER(20,0),
  PRODUSPROPRIU NUMBER(10,0),
  CODCRITERIU NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  PARTENER VARCHAR2(100),
  CANTCERT NUMBER(20,7),
  CANTESTIMAT NUMBER(20,7),
  STOCDEPOZIT NUMBER(20,7),
  STOCSECTIE NUMBER(20,7),
  RESTDPS NUMBER(20,7),
  RESTCMD NUMBER(20,7),
  CONTRACT NUMBER(20,0),
  PROMOTIE NUMBER(1,0),
  INTERVENTIE VARCHAR2(200),
  UTILAJ VARCHAR2(200),
  CODUTILAJ2C NUMBER(20,0),
  FARANIVELAPROB NUMBER(1,0),
  PUREAL NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  REZCMDINI NUMBER(20,7),
  CMDCLILANS NUMBER(10,0),
  CMDINTLANS NUMBER(10,0),
  INFOMF VARCHAR2(100),
  CONTSERV NUMBER(20,0),
  ESTEIMBMF NUMBER(1,0),
  DENLAPART VARCHAR2(100),
  PRETOFE NUMBER(20,7),
  SOLDBUGET NUMBER(20,7),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  PUMIN NUMBER(20,7),
  VALADAOS NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  PROCADAOS1 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7DF23A98FADDDD0ABCEF408D42BDF7CC5207C3B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA2 (
  CODCOMANDA2 NUMBER(20,0),
  CODCOMANDA NUMBER(10,0),
  CODLUCRARE NUMBER(20,0),
  OBS VARCHAR2(100),
  CODPART NUMBER(20,0),
  GARANTIE NUMBER(1,0),
  CODNPARCAUT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  ORE NUMBER(10,4),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E6393EEC10E0F9FD0E6E088C9577DB8578BA311</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA3 (
  CODCOMANDA3 NUMBER(20,0),
  CODCOMANDA2 NUMBER(20,0),
  CODOPERATIE NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  OBS VARCHAR2(100),
  TIP NUMBER(1,0),
  EXECUTAT NUMBER(1,0),
  CODCOMANDA NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  DATA DATE,
  CODINTR1_1 NUMBER(20,0),
  CODINTR1_2 NUMBER(20,0),
  CODINTR1_3 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DURATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  TARIF NUMBER(20,7),
  DATASTART DATE,
  CATEGPRET NUMBER(5,0),
  CODPRESTATIE NUMBER(20,0),
  DOCINTR_1 VARCHAR2(100),
  DOCINTR_2 VARCHAR2(100),
  DOCINTR_3 VARCHAR2(100),
  CODSERV NUMBER(20,0),
  CODLOC NUMBER(20,0),
  DURATAH NUMBER(10,2),
  TARIF0 NUMBER(20,7),
  TARIF1 NUMBER(20,7),
  TARIF2 NUMBER(20,7),
  TARIF3 NUMBER(20,7),
  TARIF4 NUMBER(20,7),
  TARIF5 NUMBER(20,7),
  TARIF6 NUMBER(20,7),
  TARIF7 NUMBER(20,7),
  TARIF8 NUMBER(20,7),
  TARIF9 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMANDA4</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>40E198611FB9024E5809E98DAAABA0FB0298C171</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMANDA4 (
  CODCOMANDA4 NUMBER(20,0),
  CODCOMANDA3 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(200),
  CODCOMANDA NUMBER(20,0),
  ELIBERAT NUMBER(1,0),
  ORE NUMBER(10,2),
  CODCOMANDA2 NUMBER(20,0),
  NUME VARCHAR2(60)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMCLI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>083D1F0C35B32E21311E7D73BBD085B1A3D05882</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMCLI (
  CODCOMANDA1 NUMBER(20,0),
  CARNETDOCCLI VARCHAR2(10),
  NRDOCCLI NUMBER(20,0),
  DATADOCCLI DATE,
  SERIEDOCCLI VARCHAR2(20),
  CLIENT VARCHAR2(100),
  TERMENLIVR DATE,
  COMCLOSED CHAR(2),
  COMCANCELED CHAR(2),
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1C NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMDOC_MEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D90434946075AD83DC251196B9ED97FE48DDF1B5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMDOC_MEN (
  DENUMIRE VARCHAR2(200),
  DEN_UM1 VARCHAR2(15),
  CANTCOMANDAT NUMBER,
  CANTACCEPTAT NUMBER,
  RESTACCEPTAT NUMBER,
  PU NUMBER,
  VALCOM NUMBER,
  VALACC NUMBER,
  VALREST NUMBER,
  TERMEN DATE,
  PROCENT NUMBER(6,3),
  VALACCTVA NUMBER,
  OBSLINIE VARCHAR2(200),
  OBS VARCHAR2(500),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  DEN_UM VARCHAR2(15),
  PARITATE NUMBER(30,15),
  COMP_ART VARCHAR2(200),
  COMP_UM VARCHAR2(15),
  COMP_CANT NUMBER(20,7),
  COMP_PRET NUMBER(20,7),
  COMP_TIP VARCHAR2(18),
  LOCMUNCA VARCHAR2(250),
  DSV NUMBER(10,0),
  NROP NUMBER(10,0),
  DETALII NUMBER(10,0),
  OPERATIE VARCHAR2(250),
  BPS NUMBER(10,0),
  TARIF VARCHAR2(150),
  TPIMIN NUMBER(20,7),
  TPIORE NUMBER(20,7),
  TUMIN NUMBER(20,7),
  TUORE NUMBER(20,7),
  MANVAL NUMBER(20,7),
  MANOBS VARCHAR2(1000),
  CODCOMANDA1 NUMBER(20,0),
  UM1 NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CLASA NUMBER(20,0),
  CLASASTATIST NUMBER(20,0),
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIP NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMPARE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7DAD9E8BF20BAA77AD622E97D61CE0D6BA8DC62E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMPARE1 (
  IDENTIFICATOR VARCHAR2(300),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMPARE2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6A1028CAA801596D512FE7AA7D42D7BB44FF0CAD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMPARE2 (
  IDENTIFICATOR VARCHAR2(300),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_COMPENS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B6E57A255883102FB1F0896BDBC82C65C394D35D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_COMPENS (
  CODCOMPENS NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  PARTD NUMBER(20,0),
  PARTC NUMBER(20,0),
  OBSD VARCHAR2(100),
  OBSC VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODGEST NUMBER(20,0),
  TIPCOMPENS NUMBER(1,0),
  CODCENTRU NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODTIPPARTINCERT NUMBER(20,0),
  FLAGS NUMBER(2,0),
  EXCLUSSAFT NUMBER(1,0),
  VALDEBIT NUMBER(20,7),
  VALCREDIT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONCURENTI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2BA3163D2AC10EB1A784C7D529CBF839E0C83BD1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONCURENTI (
  CODCONCURENT NUMBER(20,0),
  DENCONCURENT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONDCOR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1707A9C69ADF35C5881D20517C926601336A92BC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONDCOR1 (
  CODCONDCOR1 NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RND1 VARCHAR2(30),
  COL1 VARCHAR2(30),
  REL VARCHAR2(2),
  RND2 VARCHAR2(30),
  COL2 VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONST1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F961B2B575CFA1D579968D07AFAEA5C91E676F0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONST1 (
  CODCONST1 NUMBER(20,0),
  CODCATEG NUMBER(10,0),
  INDEXLOCAL VARCHAR2(10),
  SIMBOL VARCHAR2(20),
  DENUMIRE VARCHAR2(100),
  TIP NUMBER(10,0),
  DESCRIERE CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONST1EXT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5079DDB3456ADE22459DE0B2CC44C656990CF642</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONST1EXT (
  CODCONST1 NUMBER(20,0),
  CODCATEG NUMBER(10,0),
  INDEXLOCAL VARCHAR2(10),
  SIMBOL VARCHAR2(20),
  DENUMIRE VARCHAR2(100),
  TIP NUMBER(10,0),
  DENCATEG VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTANTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78742C80AD5610558F2E17EAF878E989E9EE6FB1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTANTE (
  SIMBOL VARCHAR2(20),
  VALOARE VARCHAR2(300),
  ANLUNA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B741E680A95B7EE21A86D34E2F948F19E6D10CFC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTLUNA (
  CODCONSTLUNA NUMBER(20,0),
  CODCONST1 NUMBER(10,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  USERID NUMBER(10,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  VALAFIS VARCHAR2(2500),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTLUNAEXT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F3D907AF88260EC77088C784D6276E999B01FECE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTLUNAEXT (
  CODCONSTLUNA NUMBER(20,0),
  CODCONST1 NUMBER(10,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  USERID NUMBER(10,0),
  VALAFIS VARCHAR2(300),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0),
  USERNAME VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTLUNAINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6C49CDDE402B95FC0620E95C523D556B4A9D9200</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTLUNAINI (
  CODCONSTLUNA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTMAKETA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5DE378A28DACFC543A1DC13E58868FE034E8EEE5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTMAKETA (
  CODCONSTMAKETA NUMBER(20,0),
  CODMAKETA NUMBER(20,0),
  CODCONST1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8D2E08091D212E22B7F6685E6D2114745F4519C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTVAL (
  VALOARE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTVALINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>908772B86472D40DCC0A9B55DB089889300532E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTVALINI (
  VALOARE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTVALPOS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A770A8C7154B752F03EEEBE12334CDB9E1CB02D4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTVALPOS (
  COD NUMBER(20,0),
  IDX NUMBER(10,0),
  VALPOSIBILE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0),
  VALOARE VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTVALPOSINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A38EA7B3C6C02050E5310B6FD9CF55E5DCAA4AA4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTVALPOSINI (
  COD NUMBER(20,0),
  IDX NUMBER(10,0),
  VALPOSIBILE VARCHAR2(300),
  CODCONSTLUNA NUMBER(10,0),
  VALOARE VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONSTVAL_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B4EBA7FE001A9188500BA3E297B663B1530668A9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONSTVAL_LST (
  SIMBOL VARCHAR2(30),
  ANLUNASTART NUMBER(5,0),
  ANLUNASTOP NUMBER(5,0),
  VALOARE VARCHAR2(4000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONST_PROCTVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>22DB373244259C5C04EE9FA669873D26B585DD09</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONST_PROCTVA (
  SIMBOL VARCHAR2(20),
  ORD NUMBER(2,0),
  TIP NUMBER(2,0),
  PROCTVA NUMBER(10,3),
  LIMINF NUMBER(10,3),
  LIMSUP NUMBER(10,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONS_AUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D12D6DF250BB25F0CDD692EEA8575E127A323A3E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONS_AUTO (
  CODNPARCAUT NUMBER(20,0),
  DATAPREC DATE,
  BORDPREC NUMBER(10,0),
  DATACURENT DATE,
  BORDCURENT NUMBER(10,0),
  BORDPREC_C NUMBER(10,0),
  CONSUM NUMBER(20,7),
  CONSUM_VAL NUMBER(20,7),
  CODNPARC0 NUMBER(20,0),
  BORDMIN NUMBER(10,0),
  BORDMAX NUMBER(10,0),
  CONSUM_TOTAL NUMBER(20,7),
  CONSUM_TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTCHELTAVANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>45C33566F70A621707772B1B957766AD73F845A6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTCHELTAVANS (
  CONTCHELTAVANS VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTCUSTODIE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>733CA85E62CA6677043CC8B21205F863E82D0321</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTCUSTODIE (
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTMIFIX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7BC38AF0304EED0302D244EC8A619B5F385D511F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTMIFIX (
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTOBINV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>831E13DC22EBBCB0E95366C4C302D973E3289FC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTOBINV (
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>97954583BC419981B85A4D117E209151C37B9514</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACT (
  CODCONTRACT NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DATASTART DATE,
  DATASTOP DATE,
  TIPCONTRACT NUMBER(1,0),
  TIPTARGET NUMBER(1,0),
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  PERTARGET NUMBER(1,0),
  NRLUNI NUMBER(20,0),
  PERFACT NUMBER(2,0),
  ZIFACT NUMBER(2,0),
  PROCMAJ NUMBER(8,5),
  PERCITIRE NUMBER(2,0),
  ZICITIRE NUMBER(2,0),
  TRANSPPART NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER,
  DATACREARE TIMESTAMP(6),
  AGENT NUMBER(20,0),
  CURS NUMBER(22,4),
  AVANS NUMBER(20,2),
  DOBANDA NUMBER(8,5),
  TIPDOBANDA NUMBER(1,0),
  CALCDOBANDA NUMBER(1,0),
  REZIDUALA NUMBER(20,2),
  REZIDUALASEPARAT NUMBER(1,0),
  FACTLEI NUMBER(1,0),
  ASIGANUAL NUMBER(20,2),
  LUNIGRATIE NUMBER(2,0),
  GRATIEFARADOB NUMBER(1,0),
  CODBANCA NUMBER(20,0),
  PROCMAJCURS NUMBER(8,5),
  AUTOPRELUNGIRE NUMBER(1,0),
  LUNIPRELUNGIRE NUMBER(4,0),
  TIPARTICOL NUMBER(1,0),
  TIPUM NUMBER(1,0),
  TIPTARGETV NUMBER(1,0),
  SEMNAT NUMBER(1,0),
  EXPLICATII VARCHAR2(50),
  STOPAJ NUMBER(20,0),
  SUMA1 NUMBER(20,7),
  DISCOUNT1 NUMBER(20,7),
  SUMA2 NUMBER(20,7),
  DISCOUNT2 NUMBER(20,7),
  SUMA3 NUMBER(20,7),
  DISCOUNT3 NUMBER(20,7),
  SUMA4 NUMBER(20,7),
  DISCOUNT4 NUMBER(20,7),
  NRI VARCHAR2(30),
  CASS NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  MAXREPLSIMULTANE NUMBER(5,0),
  MAXZILEREPLA NUMBER(5,0),
  TIPLIVRARE NUMBER(2,0),
  TIPPERFACT NUMBER(1,0),
  MAJORARI NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGENERIC NUMBER(20,0),
  FACTPRETSTANDARD NUMBER(1,0),
  CREDITE_PLAFON NUMBER(20,7),
  CREDITE_PU NUMBER(20,7),
  SOLDPART NUMBER(20,7),
  VALOARE NUMBER(20,7),
  VALDISC NUMBER(20,7),
  FACTURAT NUMBER(1,0),
  CADRU NUMBER(1,0),
  PF NUMBER(1,0),
  VALSIMPLU NUMBER(20,7),
  VALOPTIM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACT0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>054A2484F4A867285FEB76003CC0486499559F21</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACT0 (
  CODCONTRACT0 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  TIPLINIE NUMBER(1,0),
  DATA DATE,
  CURS NUMBER(20,7),
  SUMA NUMBER(20,7),
  FACTURAT NUMBER(1,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DOBANDA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  OLDCURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E788CCDA5D3BD406E6897C25F1B255764F6778C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACT1 (
  CODCONTRACT1 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROCDISC NUMBER(5,2),
  ZILEL NUMBER(5,0),
  ZILEC NUMBER(5,0),
  LANSARE NUMBER(1,0),
  ANEXA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(200),
  GESTACT NUMBER(20,0),
  TVA NUMBER(20,7),
  VALTARGET NUMBER(20,7),
  LIMITACADOU NUMBER(20,7),
  CANTCADOU NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODOBIECTSEC NUMBER(20,0),
  LIMITACADOUSEC NUMBER(20,7),
  TERMENFIX DATE,
  TIPPRET NUMBER(1,0),
  SEDIULIVRARE NUMBER(20,0),
  TIPDISCOUNT NUMBER(1,0),
  TIPDISCOUNTT NUMBER(1,0),
  TIPDISCOUNTC NUMBER(1,0),
  SUMAFIXA NUMBER(20,7),
  TIPDISCOUNTT1 NUMBER(1,0),
  CODCLASA NUMBER(20,0),
  DISCTCUMULAT NUMBER(1,0),
  DISCT NUMBER(20,7),
  CODCONTR1CADRU NUMBER(20,0),
  ADDIM NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIPOBIECT NUMBER(1,0),
  CANTGLOBAL NUMBER(20,7),
  PRETSTANDARD NUMBER(20,7),
  STARE NUMBER(1,0),
  DATALIVR DATE,
  CODAUTO NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  INDEXPARINTE NUMBER(10,0),
  TAXAUSCARE NUMBER(20,7),
  TAXACONDITIONARE NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  UTILAJ_TIP_INDEX NUMBER(2,0),
  VERIFUMA NUMBER(1,0),
  LUSCARE NUMBER(20,7),
  LCONDITIONARE NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRETUM1 NUMBER(20,7),
  PARITATECREDIT NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  DENARTCLI VARCHAR2(200),
  CODEXTCLI VARCHAR2(30),
  DENCADOU VARCHAR2(200),
  DENOBIECTSEC VARCHAR2(200),
  PU NUMBER(20,7),
  CANTUNITAR NUMBER(20,7),
  SEL NUMBER(1,0),
  CODLACLIENT VARCHAR2(30),
  UTILAJ VARCHAR2(350),
  CODINTR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODAE NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(150),
  DENSEDIULIVRARE VARCHAR2(100),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODGRUPA NUMBER(20,0),
  DEN_GRECHIV VARCHAR2(250),
  PRET_VANZARE NUMBER(20,7),
  VALOPTIM NUMBER(20,7),
  NRDOCINTR VARCHAR2(50),
  NRDOCIES VARCHAR2(50),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  DENUM1 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACT2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3257904ECA1F5CC8E89DDDCD43D7237D74DCBD7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACT2 (
  CODCONTRACT2 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  DATA DATE,
  DATASTOP DATE,
  SUMA NUMBER(20,7),
  DOBANDA NUMBER(20,7),
  ASIGURARE NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SUSPENDAT NUMBER(1,0),
  SEDIULIVRARE NUMBER(20,0),
  INDEXLOCAL NUMBER(12,2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODDOCT NUMBER(20,0),
  TIPDOCT NUMBER(20,0),
  TOTAL NUMBER(20,7),
  FACTURAT NUMBER(1,0),
  VALDOC NUMBER(20,7),
  FACTURATT NUMBER(1,0),
  SUBUNITDOC VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0962A0079B7CB39EC16C7CE763A2D9EB12428E72</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTC (
  CODCONTRACTC NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTC0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF4175989EA91F1E3C96E07697F3B18B7E83ED7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTC0 (
  CODCONTRACTC0 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTDC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D97951EEF704FA698481F551A05C15568BA25A12</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTDC (
  CODUNIC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TIPFACT NUMBER(20,0),
  CODPART NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  OBS VARCHAR2(450),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTDF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>493DBC728E5E8AD6645DD3AF4354E3384EA63366</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTDF (
  CODUNIC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TIPFACT NUMBER(20,0),
  CODPART NUMBER(20,0),
  NRDOC VARCHAR2(50),
  DATADOC DATE,
  OBS VARCHAR2(500),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D4452FDD4B2D2E7D8D7FDC5A5086235602A39243</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTL (
  CODCONTRACT1 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROCDISC NUMBER(5,2),
  ZILEL NUMBER(5,0),
  ZILEC NUMBER(5,0),
  LANSARE NUMBER(1,0),
  ANEXA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(200),
  GESTACT NUMBER(20,0),
  TVA NUMBER(20,7),
  VALTARGET NUMBER(20,7),
  LIMITACADOU NUMBER(20,7),
  CANTCADOU NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CODOBIECTSEC NUMBER(20,0),
  LIMITACADOUSEC NUMBER(20,7),
  TERMENFIX DATE,
  TIPPRET NUMBER(1,0),
  SEDIULIVRARE NUMBER(20,0),
  TIPDISCOUNT NUMBER(1,0),
  TIPDISCOUNTT NUMBER(1,0),
  TIPDISCOUNTC NUMBER(1,0),
  SUMAFIXA NUMBER(20,7),
  TIPDISCOUNTT1 NUMBER(1,0),
  CODCLASA NUMBER(20,0),
  DISCTCUMULAT NUMBER(1,0),
  DISCT NUMBER(20,7),
  CODCONTR1CADRU NUMBER(20,0),
  ADDIM NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIPOBIECT NUMBER(1,0),
  CANTGLOBAL NUMBER(20,7),
  PRETSTANDARD NUMBER(20,7),
  STARE NUMBER(1,0),
  DATALIVR DATE,
  CODAUTO NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  INDEXPARINTE NUMBER(10,0),
  TAXAUSCARE NUMBER(20,7),
  TAXACONDITIONARE NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  UTILAJ_TIP_INDEX NUMBER(2,0),
  VERIFUMA NUMBER(1,0),
  LUSCARE NUMBER(20,7),
  LCONDITIONARE NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRETUM1 NUMBER(20,7),
  PARITATECREDIT NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  DENARTCLI VARCHAR2(200),
  CODEXTCLI VARCHAR2(30),
  DENCADOU VARCHAR2(200),
  DENOBIECTSEC VARCHAR2(200),
  PU NUMBER(20,7),
  CANTUNITAR NUMBER(20,7),
  SEL NUMBER(1,0),
  CODLACLIENT VARCHAR2(30),
  UTILAJ VARCHAR2(350),
  CODINTR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODAE NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(150),
  DENSEDIULIVRARE VARCHAR2(100),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODGRUPA NUMBER(20,0),
  DEN_GRECHIV VARCHAR2(250),
  PRET_VANZARE NUMBER(20,7),
  VALOPTIM NUMBER(20,7),
  NRDOCINTR VARCHAR2(50),
  NRDOCIES VARCHAR2(50),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  DENUM1 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTSEDII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0FC5C85730083A3361D079570B7EA64C76EC8431</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTSEDII (
  SEDIULIVRARE NUMBER(20,0),
  SEDIUOK NUMBER(1,0),
  ADRESA VARCHAR2(800)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7EE0ED4136E643094736DF888E49A07D96F36B3D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTT (
  CODCONTRACTT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  ZILE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TERMENFIX DATE,
  PROCVALDOC NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  CUMULAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>656DDF25FC5347767B82712963C90B685459192E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTV (
  CODCONTRACTV NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  SUMA NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  CODCONTRACT1 NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>71844A3AF3BFD1384F51200BDCB7ED9DCE33788F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTX (
  CODCONTRACTX NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  PARAMETRU NUMBER(2,0),
  VALMIN NUMBER(20,7),
  PROCPU NUMBER(20,7),
  CORECTIEPU NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTRACTXX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>93A81CA1630006E4285025A743D50F858D793B70</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTRACTXX (
  CODCONTRACTXX NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  PARAMETRU NUMBER(2,0),
  VALSTART NUMBER(20,7),
  VALSTOP NUMBER(20,7),
  ABATERE NUMBER(20,7),
  STARTPROC NUMBER(20,7),
  STARTCORECTIE NUMBER(20,7),
  PROC NUMBER(20,7),
  CORECTIE NUMBER(20,7),
  GENERARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTURIDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9336F669BA8EDC2B4FDEA34FF25029E41D08EDF6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTURIDEDICATE (
  CODBANKCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONTVENITAVANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5ADE326A85A496D8F919EBC1F400114741F0FE67</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONTVENITAVANS (
  CONTVENITAVANS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CONVERTCURSPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DF11635BD8FBD6572013480FE6F7F1FDD1FF6700</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CONVERTCURSPERS (
  CODCONVERT NUMBER(20,0),
  CODPERS NUMBER(20,0),
  ICONTPERS NUMBER(3,0),
  MONEDA_IN NUMBER(20,0),
  MONEDA_OUT NUMBER(20,0),
  SOLDVALUTA_IN NUMBER(20,7),
  SOLDLEI NUMBER(20,7),
  SOLDVALUTA_OUT NUMBER(20,7),
  CURSCONVERSIE NUMBER(20,7),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  OBS VARCHAR2(500),
  SIMBOLCONT VARCHAR2(30),
  CURS_IN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CORELAT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB41029BE3BA27551533C5F9791D855AD5D313AF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CORELAT1 (
  CODCORELAT1 NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  RND1 VARCHAR2(250),
  COL1 VARCHAR2(20),
  REL VARCHAR2(2),
  RND2 VARCHAR2(250),
  COL2 VARCHAR2(20),
  COND VARCHAR2(100),
  ISNUMERIC NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CORELAT2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>81EFE22C159624F46D06B0D0045F53C0CA9F3C3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CORELAT2 (
  CODCORELAT2 NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  CODF1 NUMBER(20,0),
  RND1 VARCHAR2(250),
  COL1 VARCHAR2(20),
  CODF2 NUMBER(20,0),
  RND2 VARCHAR2(250),
  COL2 VARCHAR2(20),
  COD1 VARCHAR2(10),
  COD2 VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CPPRETINFO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8C89FB57AFD1B8FD2739D1D06F05E1A78233F35E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CPPRETINFO (
  CODCATPRET_SURSA NUMBER(20,0),
  CODCATPRET_DEST NUMBER(20,0),
  CODSUBUNIT_DEST NUMBER(20,0),
  SUPRASCRIE_IMPLICIT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CREANTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7EC4DD1315C340B41CFE65DDDE1C8FEE7EB2641D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CREANTE (
  CODCREANTA NUMBER(20,0),
  ANC NUMBER(4,0),
  LUNAC NUMBER(2,0),
  OBS VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CREANTE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6236D32958E7AF1D4C1B5485F149BCE93933A0C7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CREANTE1 (
  CODCREANTA1 NUMBER(20,0),
  CODCREANTA NUMBER(20,0),
  COD NUMBER(20,0),
  CODCONT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(90),
  SIMBOL VARCHAR2(100),
  CONTB VARCHAR2(10),
  TIP NUMBER(10,0),
  PER VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CRITERIIDISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2AC22B1976C576930CE37B7976E49D80CB29AE38</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CRITERIIDISC (
  CODCRITERIU NUMBER(10,0),
  DENCRITERIU VARCHAR2(40),
  EXCLUDVOLTR NUMBER(1,0),
  EXCLUDCANTFACT NUMBER(1,0),
  EXCLUDTERMEN NUMBER(1,0),
  EXCLUDVALDOC NUMBER(1,0),
  EXCLUDDISTANTA NUMBER(1,0),
  PECLASE NUMBER(1,0),
  CUMULAT NUMBER(1,0),
  OFFINVOICE NUMBER(1,0),
  NIVEL NUMBER(5,0),
  CLASA NUMBER(20,0),
  TIPINTERVAL NUMBER(10,0),
  PUNCTE NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  DISCOUNTCURENT NUMBER(20,0),
  INFODISCOUNTCURENT VARCHAR2(3000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CRITERIIDISC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF3B5AE79A8D5B7149AA6339BE3C8ABA6FD578A2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CRITERIIDISC1 (
  CODCRITERIU1 NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  DATASTART DATE,
  SUBUNITATEA NUMBER(20,0),
  DATAEND DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CRONOCASHFLOW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A93C195E558692F9D7669EAD401EEF159C67F5CC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CRONOCASHFLOW (
  CODCRONO NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  DATA DATE,
  SOLD NUMBER(20,7),
  PLATI NUMBER(20,7),
  SOLDFINAL NUMBER(20,7),
  INCASARI NUMBER(20,7),
  DATAS VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURSCASHFLOW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D6A529E8B13DEF71B4011C7BCCE2D3BA8EBBE019</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURSCASHFLOW (
  CODCURS NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  SIMBOL VARCHAR2(5)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURSURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DF8C14AB6BCB075BB9D39301DC77097A91431B89</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURSURI (
  CODCURS NUMBER(20,0),
  DEN_CURS VARCHAR2(30),
  FORMATOR NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURSURI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7375FEC9F523320E98B0BBEA07666FBA46B2B0BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURSURI1 (
  CODCURS1 NUMBER(20,0) NOT NULL,
  CODCURS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURS_BANKCONT_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B8DEC01FAA8F84D72D2C1282E71E1B7F814E299</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURS_BANKCONT_LUNA (
  CODBANKCONT NUMBER(20,0),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURS_MONEDA_REG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FC6B21792049818042D8A5F7EA8CECAD239ABC48</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURS_MONEDA_REG (
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CURS_REGULARIZAT_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>954624E0EB927EE0B21C1F33A573CB2242A06D8D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CURS_REGULARIZAT_LUNA (
  CODGENERAL NUMBER(20,0),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CUSTODIEINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E735FE13F22632B0685AAAE76CC5220C201D6EB7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CUSTODIEINI (
  CODCUSTODIE NUMBER(20,0),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CUSTOMFORM_COD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2552B6AD1D989C8B8344C890D858AC86B4578CD4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CUSTOMFORM_COD (
  TAB_NAME VARCHAR2(50),
  COD_TMP NUMBER(20,0),
  COD_TAB NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_CUSTOMFORM_TAB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34665A352889E3252AD7D412D6A72F036160ED0F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_CUSTOMFORM_TAB (
  TAB_NAME VARCHAR2(50),
  TAB_MASTER VARCHAR2(50),
  COL_PK VARCHAR2(50),
  COL_LINK VARCHAR2(50),
  NIVEL NUMBER(5,0),
  TAB_IDX NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D300</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>844160E64364B2C2C8C38A41B2DB4A1D583E72A0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D300 (
  CODD300 NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  BIFA_INTERNE NUMBER(1,0),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  OBS VARCHAR2(250),
  CISTVA NUMBER(10,0),
  DENCONTRIB VARCHAR2(200),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(15),
  FAX VARCHAR2(15),
  EMAIL VARCHAR2(200),
  BANCA VARCHAR2(50),
  CONT VARCHAR2(50),
  CAEN VARCHAR2(5),
  TIP_DECONT VARCHAR2(1),
  PRO_RATA NUMBER(7,2),
  BIFA_CEREALE VARCHAR2(1),
  SOLICIT_RAMB VARCHAR2(1),
  NR_EVID VARCHAR2(23),
  V_01_0 NUMBER(15,0),
  V_02_0 NUMBER(15,0),
  V_03_0 NUMBER(15,0),
  V_03_1 NUMBER(15,0),
  V_04_0 NUMBER(15,0),
  V_05_0 NUMBER(15,0),
  T_05_0 NUMBER(15,0),
  V_05_1 NUMBER(15,0),
  T_05_1 NUMBER(15,0),
  V_06_0 NUMBER(15,0),
  T_06_0 NUMBER(15,0),
  V_07_0 NUMBER(15,0),
  T_07_0 NUMBER(15,0),
  V_07_1 NUMBER(15,0),
  T_07_1 NUMBER(15,0),
  V_08_0 NUMBER(15,0),
  T_08_0 NUMBER(15,0),
  V_09_0 NUMBER(15,0),
  T_09_0 NUMBER(15,0),
  V_10_0 NUMBER(15,0),
  T_10_0 NUMBER(15,0),
  V_11_0 NUMBER(15,0),
  T_11_0 NUMBER(15,0),
  V_12_0 NUMBER(15,0),
  T_12_0 NUMBER(15,0),
  V_13_0 NUMBER(15,0),
  V_14_0 NUMBER(15,0),
  V_15_0 NUMBER(15,0),
  V_16_0 NUMBER(15,0),
  T_16_0 NUMBER(15,0),
  V_17_0 NUMBER(15,0),
  T_17_0 NUMBER(15,0),
  V_18_0 NUMBER(15,0),
  T_18_0 NUMBER(15,0),
  V_18_1 NUMBER(15,0),
  T_18_1 NUMBER(15,0),
  V_19_0 NUMBER(15,0),
  T_19_0 NUMBER(15,0),
  V_20_0 NUMBER(15,0),
  T_20_0 NUMBER(15,0),
  V_20_1 NUMBER(15,0),
  T_20_1 NUMBER(15,0),
  V_21_0 NUMBER(15,0),
  T_21_0 NUMBER(15,0),
  V_22_0 NUMBER(15,0),
  T_22_0 NUMBER(15,0),
  V_23_0 NUMBER(15,0),
  T_23_0 NUMBER(15,0),
  V_24_0 NUMBER(15,0),
  T_24_0 NUMBER(15,0),
  V_25_0 NUMBER(15,0),
  T_25_0 NUMBER(15,0),
  V_26_0 NUMBER(15,0),
  V_26_1 NUMBER(15,0),
  V_27_0 NUMBER(15,0),
  T_27_0 NUMBER(15,0),
  T_28_0 NUMBER(15,0),
  T_29_0 NUMBER(15,0),
  V_30_0 NUMBER(15,0),
  T_30_0 NUMBER(15,0),
  T_31_0 NUMBER(15,0),
  T_32_0 NUMBER(15,0),
  T_33_0 NUMBER(15,0),
  T_34_0 NUMBER(15,0),
  T_35_0 NUMBER(15,0),
  T_36_0 NUMBER(15,0),
  T_37_0 NUMBER(15,0),
  T_38_0 NUMBER(15,0),
  T_39_0 NUMBER(15,0),
  T_40_0 NUMBER(15,0),
  T_41_0 NUMBER(15,0),
  T_42_0 NUMBER(15,0),
  NR_FACTURI NUMBER(15,0),
  BAZA NUMBER(15,0),
  TVA NUMBER(15,0),
  V_A NUMBER(15,0),
  T_A NUMBER(15,0),
  V_B NUMBER(15,0),
  T_B NUMBER(15,0),
  TEMEI NUMBER(1,0),
  BIFA_MOB VARCHAR2(1),
  BIFA_DISP VARCHAR2(1),
  BIFA_CONS VARCHAR2(1),
  V_12_1 NUMBER(15,0),
  T_12_1 NUMBER(15,0),
  V_12_2 NUMBER(15,0),
  T_12_2 NUMBER(15,0),
  V_12_3 NUMBER(15,0),
  T_12_3 NUMBER(15,0),
  V_25_1 NUMBER(15,0),
  T_25_1 NUMBER(15,0),
  V_25_2 NUMBER(15,0),
  T_25_2 NUMBER(15,0),
  V_25_3 NUMBER(15,0),
  T_25_3 NUMBER(15,0),
  NR_FACTURI_P NUMBER(15,0),
  BAZA_P NUMBER(15,0),
  TVA_P NUMBER(15,0),
  V_A1 NUMBER(15,0),
  T_A1 NUMBER(15,0),
  V_B1 NUMBER(15,0),
  T_B1 NUMBER(15,0),
  T_43_0 NUMBER(15,0),
  T_44_0 NUMBER(15,0),
  V_64_0 NUMBER(15,0),
  T_64_0 NUMBER(15,0),
  V_65_0 NUMBER(15,0),
  T_65_0 NUMBER(15,0),
  TOT_PRECEDENT NUMBER(15,0),
  TOT_CURENT NUMBER(15,0),
  NR_FACTURI_E NUMBER(15,0),
  BAZA_E NUMBER(15,0),
  TVA_E NUMBER(15,0),
  DEPUSREPREZ NUMBER(1,0),
  V_14_1 NUMBER(15,0),
  V_14_2 NUMBER(15,0),
  ETVA NUMBER(1,0),
  V_09_1 NUMBER(15,0),
  T_09_1 NUMBER(15,0),
  V_10_1 NUMBER(15,0),
  T_10_1 NUMBER(15,0),
  V_11_1 NUMBER(15,0),
  T_11_1 NUMBER(15,0),
  V_12_4 NUMBER(15,0),
  T_12_4 NUMBER(15,0),
  V_12_5 NUMBER(15,0),
  T_12_5 NUMBER(15,0),
  V_22_1 NUMBER(15,0),
  T_22_1 NUMBER(15,0),
  V_23_1 NUMBER(15,0),
  T_23_1 NUMBER(15,0),
  V_25_4 NUMBER(15,0),
  T_25_4 NUMBER(15,0),
  V_25_5 NUMBER(15,0),
  T_25_5 NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D9578A93BC109DC7D8D080BAD6A7B665C4B9B16F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390 (
  CODD390 NUMBER(20,0) NOT NULL,
  TIPD390 NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CISTVA VARCHAR2(15),
  DENCONTRIB VARCHAR2(100),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(30),
  FAX VARCHAR2(30),
  EMAIL VARCHAR2(80),
  NRTOTOP NUMBER(20,0),
  BAZAL NUMBER(20,7),
  BAZAT NUMBER(20,7),
  BAZAA NUMBER(20,7),
  BAZAP NUMBER(20,7),
  BAZAS NUMBER(20,7),
  TOTALBAZA NUMBER(20,7),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  OBS VARCHAR2(450),
  NRFIRMECDS NUMBER(20,0),
  BAZAR NUMBER(20,7),
  GENERAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390CA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19EFA2736261857C679955B1F698B267070BA739</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390CA (
  CODD390CA NUMBER(20,0),
  CODD390 NUMBER(20,0),
  TARA_M1 VARCHAR2(2),
  COD_M1 VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390CB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88C99F0593A7ACDD772C3894EFCF2E0B63776966</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390CB (
  CODD390CB NUMBER(20,0),
  CODD390 NUMBER(20,0),
  TARA_M1 VARCHAR2(2),
  COD_M1 VARCHAR2(15),
  MOTIV NUMBER(2,0),
  TARA_M2 VARCHAR2(2),
  COD_M2 VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390D</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1265B5CA4371387024129ED3EB47787895B6774F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390D (
  CODD390D NUMBER(20,0) NOT NULL,
  CODD390O NUMBER(20,0),
  CODD390 NUMBER(20,0),
  IDXFIRMA NUMBER(20,0),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  DOC VARCHAR2(50),
  MONEDADOC VARCHAR2(50),
  TIP VARCHAR2(1),
  BAZAVAL NUMBER(20,7),
  CURS NUMBER(20,7),
  BAZALEI NUMBER(20,7),
  OBS VARCHAR2(500),
  STERS NUMBER(1,0),
  CAZSPECIAL NUMBER(5,0),
  TARA VARCHAR2(2),
  CODO VARCHAR2(30),
  DENO VARCHAR2(100),
  TRANSFERBAZA NUMBER(20,7),
  TRANSFERTIP VARCHAR2(1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390DX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4974FF2BB38FFE05A03208B3C1AADB631233C41</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390DX (
  CODD390D NUMBER(20,0) NOT NULL,
  CODD390O NUMBER(20,0),
  CODD390 NUMBER(20,0),
  IDXFIRMA NUMBER(20,0),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  DOC VARCHAR2(50),
  MONEDADOC VARCHAR2(50),
  TIP VARCHAR2(1),
  BAZAVAL NUMBER(20,7),
  CURS NUMBER(20,7),
  BAZALEI NUMBER(20,7),
  OBS VARCHAR2(450),
  STERS NUMBER(1,0),
  CAZSPECIAL NUMBER(5,0),
  TARA VARCHAR2(2),
  CODO VARCHAR2(30),
  DENO VARCHAR2(100),
  TRANSFERBAZA NUMBER(20,7),
  TRANSFERTIP VARCHAR2(1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D390O</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>719235CBF151FF471A43EE3B35A8AFAA0B14BC9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D390O (
  CODD390O NUMBER(20,0) NOT NULL,
  CODD390 NUMBER(20,0),
  TIP VARCHAR2(1),
  TARA VARCHAR2(2),
  CODO VARCHAR2(30),
  DENO VARCHAR2(100),
  BAZA NUMBER(20,7),
  OBS VARCHAR2(500),
  CAZSPECIAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0A2CAEFB1A7CFD67845A01309CDCE50C4955FBE9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394 (
  CODD394 NUMBER(20,0),
  TIPD394 VARCHAR2(1),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CISTVA VARCHAR2(15),
  DENCONTRIB VARCHAR2(100),
  DOMFISCCONTRIB VARCHAR2(1000),
  TEL VARCHAR2(30),
  FAX VARCHAR2(30),
  EMAIL VARCHAR2(80),
  CIFREPRFISC VARCHAR2(15),
  DENREPRFISC VARCHAR2(100),
  DOMFISCREPRFISC VARCHAR2(1000),
  TELREPRFISC VARCHAR2(30),
  FAXREPRFISC VARCHAR2(30),
  EMAILREPRFISC VARCHAR2(80),
  NRTOTFB NUMBER(20,0),
  BAZALIVR NUMBER(20,7),
  TVALIVR NUMBER(20,7),
  BAZAACHIZ NUMBER(20,7),
  TVAACHIZ NUMBER(20,7),
  BAZAV NUMBER(20,7),
  TVAV NUMBER(20,7),
  BAZAVC NUMBER(20,7),
  TVAVC NUMBER(20,7),
  BAZAC NUMBER(20,7),
  TVAC NUMBER(20,7),
  BAZACC NUMBER(20,7),
  TVACC NUMBER(20,7),
  SUMACONTROL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  NUME VARCHAR2(75),
  PRENUME VARCHAR2(75),
  FUNCTIA VARCHAR2(50),
  CENTRALIZAT NUMBER(1,0),
  TIP NUMBER(1,0),
  SEMESTRU VARCHAR2(2),
  OBS VARCHAR2(250),
  NRFACTL NUMBER(15,0),
  NRFACTA NUMBER(15,0),
  NRFACTV NUMBER(15,0),
  NRFACTC NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF4F492A6B8F9C7ECC3A81B9C5BADED6F9B0D018</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416 (
  CODD39416 NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPD VARCHAR2(1),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  CUI VARCHAR2(50),
  DEN VARCHAR2(100),
  CAEN VARCHAR2(5),
  ADRESA VARCHAR2(160),
  TELEFON VARCHAR2(15),
  FAX VARCHAR2(15),
  EMAIL VARCHAR2(80),
  CIFR VARCHAR2(13),
  DENR VARCHAR2(100),
  ADRESAR VARCHAR2(160),
  TELEFONR VARCHAR2(15),
  FAXR VARCHAR2(15),
  EMAILR VARCHAR2(80),
  CALITATER VARCHAR2(50),
  TIPI NUMBER(1,0),
  DENI VARCHAR2(100),
  CODI VARCHAR2(13),
  FUNCTIEI VARCHAR2(35),
  CALITATEI VARCHAR2(50),
  TVAINCAS NUMBER(1,0),
  OPEFECTUATE NUMBER(1,0),
  ACORDACCESP NUMBER(1,0),
  ACORDACCESC NUMBER(1,0),
  SUMACONTROL NUMBER(20,0),
  RPNO NUMBER(20,0),
  RNNO NUMBER(20,0),
  UENO NUMBER(20,0),
  NONUENO NUMBER(20,0),
  OPEFCFGEN NUMBER(1,0),
  DATAXMLVALID DATE,
  OBS VARCHAR2(200),
  NEREZIDENT NUMBER(1,0),
  PRSAFILIAT NUMBER(1,0),
  EDITMANUAL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416G</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C29E23A55D7613EAA2780307B265258C9A0B3952</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416G (
  CODD39416G NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  BF NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416G1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>100C6F6803C3998148F752A64A3B376DB0ED40DE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416G1 (
  CODD39416G1 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,0),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416G2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FC4C434D02A752DA5909D679632E0456B0100361</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416G2 (
  CODD39416G2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  LUNA NUMBER(2,0),
  NRAMEF NUMBER(20,0),
  BF NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416G3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>45A62EBFCB354D80050C55E8631B1FBF32C794AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416G3 (
  CODD39416G3 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  LUNA NUMBER(2,0),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,0),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CA3421331423935CC2247D544DA7ED88770E29A4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I (
  CODD39416I NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TOTALFACT NUMBER(20,0),
  TOTALFACTBEN NUMBER(20,0),
  TOTALFACTTERTI NUMBER(20,0),
  SOLICIT NUMBER(20,0),
  ACHIZPE NUMBER(20,0),
  ACHIZCR NUMBER(20,0),
  ACHIZCB NUMBER(20,0),
  ACHIZCI NUMBER(20,0),
  ACHIZA NUMBER(20,0),
  ACHIZB24 NUMBER(20,0),
  ACHIZB20 NUMBER(20,0),
  ACHIZB19 NUMBER(20,0),
  ACHIZB9 NUMBER(20,0),
  ACHIZB5 NUMBER(20,0),
  ACHIZS24 NUMBER(20,0),
  ACHIZS20 NUMBER(20,0),
  ACHIZS19 NUMBER(20,0),
  ACHIZS9 NUMBER(20,0),
  ACHIZS5 NUMBER(20,0),
  IMPORTB NUMBER(20,0),
  ACINECORP NUMBER(20,0),
  LIVRARIBI NUMBER(20,0),
  LIVRARIB24 NUMBER(20,0),
  LIVRARIB20 NUMBER(20,0),
  LIVRARIB19 NUMBER(20,0),
  LIVRARIB9 NUMBER(20,0),
  LIVRARIB5 NUMBER(20,0),
  LIVRARIB0 NUMBER(20,0),
  LIVRARITI NUMBER(20,0),
  PREST24 NUMBER(20,0),
  PREST20 NUMBER(20,0),
  PREST19 NUMBER(20,0),
  PREST9 NUMBER(20,0),
  PREST5 NUMBER(20,0),
  PREST0 NUMBER(20,0),
  LIVRARIUE NUMBER(20,0),
  PRESTUE NUMBER(20,0),
  EXPORT NUMBER(20,0),
  LIVINECORP NUMBER(20,0),
  EFECTUAT NUMBER(20,0),
  ACHIZB21 NUMBER(20,0),
  ACHIZB11 NUMBER(20,0),
  ACHIZS21 NUMBER(20,0),
  ACHIZS11 NUMBER(20,0),
  LIVRARIB21 NUMBER(20,0),
  LIVRARIB11 NUMBER(20,0),
  PREST21 NUMBER(20,0),
  PREST11 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C5E285A2DF6793C4381CAD12E348BD599680BCB3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I1 (
  CODD39416I1 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  BAZAFSLCOD NUMBER(20,7),
  TVAFSLCOD NUMBER(20,7),
  BAZAFSL NUMBER(20,7),
  TVAFSL NUMBER(20,7),
  BAZAFSA NUMBER(20,7),
  TVAFSA NUMBER(20,7),
  BAZAFSAI NUMBER(20,7),
  TVAFSAI NUMBER(20,7),
  BAZABFAI NUMBER(20,7),
  TVABFAI NUMBER(20,7),
  TVADED NUMBER(20,7),
  TVADEDI NUMBER(20,7),
  TVACOL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I1R</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FEC981AF6B9D074D58F343BC1B3EBC6D4712C82A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I1R (
  CODD39416 NUMBER(20,0),
  BAZAFSLCOD24 NUMBER(20,7),
  TVAFSLCOD24 NUMBER(20,7),
  BAZAFSLCOD21 NUMBER(20,7),
  TVAFSLCOD21 NUMBER(20,7),
  BAZAFSLCOD20 NUMBER(20,7),
  TVAFSLCOD20 NUMBER(20,7),
  BAZAFSLCOD19 NUMBER(20,7),
  TVAFSLCOD19 NUMBER(20,7),
  BAZAFSLCOD11 NUMBER(20,7),
  TVAFSLCOD11 NUMBER(20,7),
  BAZAFSLCOD09 NUMBER(20,7),
  TVAFSLCOD09 NUMBER(20,7),
  BAZAFSLCOD05 NUMBER(20,7),
  TVAFSLCOD05 NUMBER(20,7),
  BAZAFSL24 NUMBER(20,7),
  TVAFSL24 NUMBER(20,7),
  BAZAFSL21 NUMBER(20,7),
  TVAFSL21 NUMBER(20,7),
  BAZAFSL20 NUMBER(20,7),
  TVAFSL20 NUMBER(20,7),
  BAZAFSL19 NUMBER(20,7),
  TVAFSL19 NUMBER(20,7),
  BAZAFSL11 NUMBER(20,7),
  TVAFSL11 NUMBER(20,7),
  BAZAFSL09 NUMBER(20,7),
  TVAFSL09 NUMBER(20,7),
  BAZAFSL05 NUMBER(20,7),
  TVAFSL05 NUMBER(20,7),
  BAZAFSA24 NUMBER(20,7),
  TVAFSA24 NUMBER(20,7),
  BAZAFSA21 NUMBER(20,7),
  TVAFSA21 NUMBER(20,7),
  BAZAFSA20 NUMBER(20,7),
  TVAFSA20 NUMBER(20,7),
  BAZAFSA19 NUMBER(20,7),
  TVAFSA19 NUMBER(20,7),
  BAZAFSA11 NUMBER(20,7),
  TVAFSA11 NUMBER(20,7),
  BAZAFSA09 NUMBER(20,7),
  TVAFSA09 NUMBER(20,7),
  BAZAFSA05 NUMBER(20,7),
  TVAFSA05 NUMBER(20,7),
  BAZAFSAI24 NUMBER(20,7),
  TVAFSAI24 NUMBER(20,7),
  BAZAFSAI21 NUMBER(20,7),
  TVAFSAI21 NUMBER(20,7),
  BAZAFSAI20 NUMBER(20,7),
  TVAFSAI20 NUMBER(20,7),
  BAZAFSAI19 NUMBER(20,7),
  TVAFSAI19 NUMBER(20,7),
  BAZAFSAI11 NUMBER(20,7),
  TVAFSAI11 NUMBER(20,7),
  BAZAFSAI09 NUMBER(20,7),
  TVAFSAI09 NUMBER(20,7),
  BAZAFSAI05 NUMBER(20,7),
  TVAFSAI05 NUMBER(20,7),
  BAZABFAI24 NUMBER(20,7),
  TVABFAI24 NUMBER(20,7),
  BAZABFAI21 NUMBER(20,7),
  TVABFAI21 NUMBER(20,7),
  BAZABFAI20 NUMBER(20,7),
  TVABFAI20 NUMBER(20,7),
  BAZABFAI19 NUMBER(20,7),
  TVABFAI19 NUMBER(20,7),
  BAZABFAI11 NUMBER(20,7),
  TVABFAI11 NUMBER(20,7),
  BAZABFAI09 NUMBER(20,7),
  TVABFAI09 NUMBER(20,7),
  BAZABFAI05 NUMBER(20,7),
  TVABFAI05 NUMBER(20,7),
  TVADED24 NUMBER(20,7),
  TVADED21 NUMBER(20,7),
  TVADED20 NUMBER(20,7),
  TVADED19 NUMBER(20,7),
  TVADED11 NUMBER(20,7),
  TVADED09 NUMBER(20,7),
  TVADED05 NUMBER(20,7),
  TVADEDI24 NUMBER(20,7),
  TVADEDI21 NUMBER(20,7),
  TVADEDI20 NUMBER(20,7),
  TVADEDI19 NUMBER(20,7),
  TVADEDI11 NUMBER(20,7),
  TVADEDI09 NUMBER(20,7),
  TVADEDI05 NUMBER(20,7),
  TVACOL24 NUMBER(20,7),
  TVACOL21 NUMBER(20,7),
  TVACOL20 NUMBER(20,7),
  TVACOL19 NUMBER(20,7),
  TVACOL11 NUMBER(20,7),
  TVACOL09 NUMBER(20,7),
  TVACOL05 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C904B2A7C816BF4AB3B32B6640110390F07ADCF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I2 (
  CODD39416I2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  NUMARF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I2A</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B8BB3D7756986CE640DBD22674F1FCC0F262F07</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I2A (
  CODD39416I2A NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  NUMARF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I2G</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5702B3776666AB482BDE0E5D3B84C9DB8B669AC6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I2G (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  LUNA NUMBER(2,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  TIPFACTURA NUMBER(1,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>69B121B76951B7914A116EEB74BFDA762D411B25</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I3 (
  CODD39416I3 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPFACTURA NUMBER(20,0),
  SERIEF VARCHAR2(20),
  NUMARF NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  PROCTVA NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I4</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84036A6661D3CB33EE10DDA22D8C9E9A771D90D5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I4 (
  CODD39416I4 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  CAEN VARCHAR2(5),
  TIPOPER NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I4AUX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DDA7716B290D4DB39929CBA229ECCCF3BA07E239</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I4AUX (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODCAENSEC NUMBER(20,0),
  TIPOPER NUMBER(1,0),
  CANTCAEN NUMBER(20,7),
  CANTLIN NUMBER(20,7),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  PROCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416I4C</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F1C3BB3D74FB0D3C39FE5F226145F934612A7A5D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416I4C (
  CODD39416 NUMBER(20,0),
  CAEN VARCHAR2(5)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416N</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>14EC3437D51CA42F4020E3EDD4E782DF60050DD3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416N (
  CODD39416N NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416NS2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>01FCE6DC0FF2BF92E14F2A03DF481C36A6828F54</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416NS2 (
  CODD39416NS2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416R</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20F8EA8401EDE4A7FA71BD52E537C37A928B583E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416R (
  CODD39416R NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  LIVRARIF NUMBER(20,0),
  LIVRARIB NUMBER(20,7),
  LIVRARITVA NUMBER(20,7),
  ACHIZF NUMBER(20,0),
  ACHIZB NUMBER(20,7),
  ACHIZTVA NUMBER(20,7),
  ACHIZIF NUMBER(20,0),
  ACHIZIB NUMBER(20,7),
  ACHIZITVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67965CB76674EFBA8EE0D49C259D56F9CCC8293D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RN (
  CODD39416RN NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RN0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>89032BD6D2C0D084E3D67E85676BB6A8B9840C3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RN0 (
  CODD39416RN0 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  L_PF_F NUMBER(20,0),
  L_PF_BI24 NUMBER(20,7),
  L_PF_TVA24 NUMBER(20,7),
  L_PF_BI20 NUMBER(20,7),
  L_PF_TVA20 NUMBER(20,7),
  L_PF_BI19 NUMBER(20,7),
  L_PF_TVA19 NUMBER(20,7),
  L_PF_BI9 NUMBER(20,7),
  L_PF_TVA9 NUMBER(20,7),
  L_PF_BI5 NUMBER(20,7),
  L_PF_TVA5 NUMBER(20,7),
  LS_PF_F NUMBER(20,0),
  LS_PF_VAL NUMBER(20,7),
  L_PF_BI21 NUMBER(20,7),
  L_PF_TVA21 NUMBER(20,7),
  L_PF_BI11 NUMBER(20,7),
  L_PF_TVA11 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RN1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8E778E1D6EFB60CD3F5A1AD143244DFE968A3178</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RN1 (
  CODD39416RN1 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CATEGTXINV NUMBER(20,0),
  F NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RN1_AUX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E3E1B92249D375BD37FBE9914700331982EA336</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RN1_AUX (
  CODD39416RN1 NUMBER(20,0),
  OLDCOD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RNS2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D51E2C452B79830E4E5F53A762E41E2C74C10745</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RNS2 (
  CODD39416RNS2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  STRP VARCHAR2(75),
  NRP VARCHAR2(15),
  BLP VARCHAR2(30),
  APP VARCHAR2(10),
  TIPDOC NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7),
  DETP VARCHAR2(100),
  CUIVALID NUMBER(1,0),
  LOCP VARCHAR2(50),
  JUDP VARCHAR2(2),
  TARAP VARCHAR2(3),
  SAJUDP VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RNS2_AUX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>849FA2177AC6735AEFBC95A4B61763A8B789646A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RNS2_AUX (
  CODD39416RNS2 NUMBER(20,0),
  OLDCOD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RNS3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2C3F3BFB565B88989B30172D40C0CAA33242327</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RNS3 (
  CODD39416RNS3 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  CODD39416RN1 NUMBER(20,0),
  CODD39416RNS2 NUMBER(20,0),
  F NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODD394 VARCHAR2(8),
  TIPTRANZ NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CATEGTXINV NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FCEB48DF5B29334F15642BF9085D7006B9D3E2D5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RP (
  CODD39416RP NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AA5567976B838C49B1A2FA34A9629A06F0114C1E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RP1 (
  CODD39416RP1 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CATEGTXINV NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RPS2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA6E127851758470E1794174A1E1BF799BC11A40</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RPS2 (
  CODD39416RPS2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7),
  CUIVALID NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416RPS3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>153B7DE0972B6BC7BCDCE246346B69C44DCA87A3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416RPS3 (
  CODD39416RPS3 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  CATEGTXINV NUMBER(20,0),
  CODD394 VARCHAR2(8),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416UE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E69D43F6BE4F3B71FFFB60C18910CC111D63C9EF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416UE (
  CODD39416UE NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416UES2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C8770376AE580078821355600058802EDC129149</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416UES2 (
  CODD39416UES2 NUMBER(20,0),
  CODD39416 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  REGSCUTIRE NUMBER(20,0),
  PROCTVA NUMBER(20,0),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  F NUMBER(20,0),
  BI NUMBER(20,7),
  MARJA NUMBER(20,7),
  TVA NUMBER(20,7),
  TVAMARJA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_ANAF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>00A8267F3E230BCE188449B847FCFFE874D3208D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_ANAF (
  CUI NUMBER(20,0),
  DATA DATE,
  CONTRIBUABIL NUMBER(2,0),
  STARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_DET1_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F966F646CFBA4701A85D7457BB3A6251252ED6D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_DET1_XML (
  TIP_PARTENER NUMBER(1,0),
  COTA NUMBER(2,0),
  DOCUMENT_N NUMBER(1,0),
  BUN NUMBER(2,0),
  NRLIVV NUMBER(15,0),
  BAZALIVV NUMBER(15,0),
  NRACHIZC NUMBER(15,0),
  BAZAACHIZC NUMBER(15,0),
  TVAACHIZC NUMBER(15,0),
  NRN NUMBER(15,0),
  VALN NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_FACT_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7724B5F134B78EFB09F4D33EE72113440CE62D0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_FACT_XML (
  TIP_FACTURA NUMBER(1,0),
  SERIE VARCHAR2(20),
  NR VARCHAR2(20),
  BAZA24 NUMBER(15,0),
  BAZA21 NUMBER(15,0),
  BAZA20 NUMBER(15,0),
  BAZA19 NUMBER(15,0),
  BAZA11 NUMBER(15,0),
  BAZA9 NUMBER(15,0),
  BAZA5 NUMBER(15,0),
  TVA24 NUMBER(15,0),
  TVA21 NUMBER(15,0),
  TVA20 NUMBER(15,0),
  TVA19 NUMBER(15,0),
  TVA11 NUMBER(15,0),
  TVA9 NUMBER(15,0),
  TVA5 NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_GEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>583852E31252CF52715D962120303DFC9178579C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_GEN (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODOBIECT NUMBER(20,0),
  SECTIUNE VARCHAR2(1),
  CUI VARCHAR2(50),
  DENP VARCHAR2(100),
  PERSFIZICA NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  STRP VARCHAR2(100),
  NRP VARCHAR2(15),
  BLP VARCHAR2(30),
  APP VARCHAR2(10),
  TIPTRANZ NUMBER(2,0),
  REGSCUTIRE NUMBER(1,0),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CURS NUMBER(20,7),
  CATEGTXINV NUMBER(20,0),
  CODD394 VARCHAR2(8),
  CODPART NUMBER(20,0),
  F NUMBER(20,0),
  CUI_NR VARCHAR2(50),
  DATA DATE,
  CUIVALID NUMBER(2,0),
  TIPDOCRN NUMBER(1,0),
  STAT_UE NUMBER(1,0),
  EXCEPTIE_D NUMBER(1,0),
  TIPI1 NUMBER(2,0),
  NRBONURI NUMBER(20,0),
  AUTOFACT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  TIPFACTURA NUMBER(2,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  LOCP VARCHAR2(50),
  JUDP VARCHAR2(2),
  TARAP VARCHAR2(3),
  SAJUDP VARCHAR2(2),
  PERSAFILIATA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_INFO_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F9AED1573F0659C1F4B0B8573437062580AEFFF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_INFO_XML (
  NRCUI1 NUMBER(15,0),
  NRCUI2 NUMBER(15,0),
  NRCUI3 NUMBER(15,0),
  NRCUI4 NUMBER(15,0),
  NR_BF_I1 NUMBER(15,0),
  INCASARI_I1 NUMBER(15,0),
  INCASARI_I2 NUMBER(15,0),
  NRFACTURI_TERTI NUMBER(15,0),
  NRFACTURI_BENEF NUMBER(15,0),
  NRFACTURI NUMBER(15,0),
  NRFACTURIL_PF NUMBER(15,0),
  NRFACTURILS_PF NUMBER(15,0),
  VAL_LS_PF NUMBER(15,0),
  TVADED24 NUMBER(15,0),
  TVADED21 NUMBER(15,0),
  TVADED20 NUMBER(15,0),
  TVADED19 NUMBER(15,0),
  TVADED11 NUMBER(15,0),
  TVADED9 NUMBER(15,0),
  TVADED5 NUMBER(15,0),
  TVADEDAI24 NUMBER(15,0),
  TVADEDAI21 NUMBER(15,0),
  TVADEDAI20 NUMBER(15,0),
  TVADEDAI19 NUMBER(15,0),
  TVADEDAI11 NUMBER(15,0),
  TVADEDAI9 NUMBER(15,0),
  TVADEDAI5 NUMBER(15,0),
  TVACOL24 NUMBER(15,0),
  TVACOL21 NUMBER(15,0),
  TVACOL20 NUMBER(15,0),
  TVACOL19 NUMBER(15,0),
  TVACOL11 NUMBER(15,0),
  TVACOL9 NUMBER(15,0),
  TVACOL5 NUMBER(15,0),
  INCASARI_AG NUMBER(15,0),
  COSTURI_AG NUMBER(15,0),
  MARJA_AG NUMBER(15,0),
  TVA_AG NUMBER(15,0),
  PRET_VANZARE NUMBER(15,0),
  PRET_CUMPARARE NUMBER(15,0),
  MARJA_ANTIC NUMBER(15,0),
  TVA_ANTIC NUMBER(15,0),
  SOLICIT NUMBER(1,0),
  ACHIZITIIPE NUMBER(1,0),
  ACHIZITIICR NUMBER(1,0),
  ACHIZITIICB NUMBER(1,0),
  ACHIZITIICI NUMBER(1,0),
  ACHIZITIIA NUMBER(1,0),
  ACHIZITIIB24 NUMBER(1,0),
  ACHIZITIIB21 NUMBER(1,0),
  ACHIZITIIB20 NUMBER(1,0),
  ACHIZITIIB19 NUMBER(1,0),
  ACHIZITIIB11 NUMBER(1,0),
  ACHIZITIIB9 NUMBER(1,0),
  ACHIZITIIB5 NUMBER(1,0),
  ACHIZITIIS24 NUMBER(1,0),
  ACHIZITIIS21 NUMBER(1,0),
  ACHIZITIIS20 NUMBER(1,0),
  ACHIZITIIS19 NUMBER(1,0),
  ACHIZITIIS11 NUMBER(1,0),
  ACHIZITIIS9 NUMBER(1,0),
  ACHIZITIIS5 NUMBER(1,0),
  IMPORTB NUMBER(1,0),
  ACINECORP NUMBER(1,0),
  LIVRARIBI NUMBER(1,0),
  BUN24 NUMBER(1,0),
  BUN21 NUMBER(1,0),
  BUN20 NUMBER(1,0),
  BUN19 NUMBER(1,0),
  BUN11 NUMBER(1,0),
  BUN9 NUMBER(1,0),
  BUN5 NUMBER(1,0),
  VALOARESCUTIT NUMBER(1,0),
  BUNTI NUMBER(1,0),
  PREST24 NUMBER(1,0),
  PREST21 NUMBER(1,0),
  PREST20 NUMBER(1,0),
  PREST19 NUMBER(1,0),
  PREST11 NUMBER(1,0),
  PREST9 NUMBER(1,0),
  PREST5 NUMBER(1,0),
  PRESTSCUTIT NUMBER(1,0),
  LINTRA NUMBER(1,0),
  PRESTINTRA NUMBER(1,0),
  EXPORT NUMBER(1,0),
  LIVINECORP NUMBER(1,0),
  EFECTUAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_LIST_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B42F459956769C589AA9627D8EF9B688CD923A1B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_LIST_XML (
  CAEN VARCHAR2(5),
  COTA NUMBER(2,0),
  OPERAT NUMBER(1,0),
  VALOARE NUMBER(15,0),
  TVA NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_OP11_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4E547177EB8856E342797A14BF30BCC7055E1877</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_OP11_XML (
  IDX_OP1 NUMBER(20,0),
  NRFACTPR NUMBER(15,0),
  CODPR VARCHAR2(8),
  BAZAPR NUMBER(15,0),
  TVAPR NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_OP1_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1EEF55CEF7CBC377247BF47CCD1072F68F812F65</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_OP1_XML (
  IDX_OP1 NUMBER(20,0),
  TIPTRANZ NUMBER(20,0),
  TIP VARCHAR2(2),
  TIP_PARTENER NUMBER(1,0),
  COTA NUMBER(2,0),
  CUIP VARCHAR2(50),
  DENP VARCHAR2(200),
  TARAP VARCHAR2(3),
  LOCP VARCHAR2(75),
  JUDP VARCHAR2(2),
  STRP VARCHAR2(75),
  NRP VARCHAR2(50),
  BLP VARCHAR2(30),
  APP VARCHAR2(50),
  DETP VARCHAR2(100),
  TIP_DOCUMENT NUMBER(1,0),
  NRFACT NUMBER(15,0),
  BAZA NUMBER(15,0),
  TVA NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_OP2_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9633372B821913167453AEC139BA7D8FE42146CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_OP2_XML (
  TIP_OP2 VARCHAR2(2),
  LUNA NUMBER(2,0),
  NRAMEF NUMBER(15,0),
  NRBF NUMBER(15,0),
  TOTAL NUMBER(15,0),
  BAZA21 NUMBER(15,0),
  BAZA20 NUMBER(15,0),
  BAZA19 NUMBER(15,0),
  BAZA11 NUMBER(15,0),
  BAZA9 NUMBER(15,0),
  BAZA5 NUMBER(15,0),
  TVA21 NUMBER(15,0),
  TVA20 NUMBER(15,0),
  TVA19 NUMBER(15,0),
  TVA11 NUMBER(15,0),
  TVA9 NUMBER(15,0),
  TVA5 NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_REZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F7FCF3205F7EF979F73FE555880AC951B8C455F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_REZ (
  CODD39416 NUMBER(20,0),
  OPEFECTUATE NUMBER(1,0),
  SUMACONTROL NUMBER(20,0),
  RPNO NUMBER(20,0),
  RNNO NUMBER(20,0),
  UENO NUMBER(20,0),
  NONUENO NUMBER(20,0),
  OPEFCFGEN NUMBER(1,0),
  LF24 NUMBER(20,0),
  LB24 NUMBER(20,0),
  LTVA24 NUMBER(20,0),
  AF24 NUMBER(20,0),
  AB24 NUMBER(20,0),
  ATVA24 NUMBER(20,0),
  AIF24 NUMBER(20,0),
  AIB24 NUMBER(20,0),
  AITVA24 NUMBER(20,0),
  LF21 NUMBER(20,0),
  LB21 NUMBER(20,0),
  LTVA21 NUMBER(20,0),
  AF21 NUMBER(20,0),
  AB21 NUMBER(20,0),
  ATVA21 NUMBER(20,0),
  AIF21 NUMBER(20,0),
  AIB21 NUMBER(20,0),
  AITVA21 NUMBER(20,0),
  LF20 NUMBER(20,0),
  LB20 NUMBER(20,0),
  LTVA20 NUMBER(20,0),
  AF20 NUMBER(20,0),
  AB20 NUMBER(20,0),
  ATVA20 NUMBER(20,0),
  AIF20 NUMBER(20,0),
  AIB20 NUMBER(20,0),
  AITVA20 NUMBER(20,0),
  LF19 NUMBER(20,0),
  LB19 NUMBER(20,0),
  LTVA19 NUMBER(20,0),
  AF19 NUMBER(20,0),
  AB19 NUMBER(20,0),
  ATVA19 NUMBER(20,0),
  AIF19 NUMBER(20,0),
  AIB19 NUMBER(20,0),
  AITVA19 NUMBER(20,0),
  LF9 NUMBER(20,0),
  LB9 NUMBER(20,0),
  LTVA9 NUMBER(20,0),
  AF9 NUMBER(20,0),
  AB9 NUMBER(20,0),
  ATVA9 NUMBER(20,0),
  AIF9 NUMBER(20,0),
  AIB9 NUMBER(20,0),
  AITVA9 NUMBER(20,0),
  LF11 NUMBER(20,0),
  LB11 NUMBER(20,0),
  LTVA11 NUMBER(20,0),
  AF11 NUMBER(20,0),
  AB11 NUMBER(20,0),
  ATVA11 NUMBER(20,0),
  AIF11 NUMBER(20,0),
  AIB11 NUMBER(20,0),
  AITVA11 NUMBER(20,0),
  LF5 NUMBER(20,0),
  LB5 NUMBER(20,0),
  LTVA5 NUMBER(20,0),
  AF5 NUMBER(20,0),
  AB5 NUMBER(20,0),
  ATVA5 NUMBER(20,0),
  AIF5 NUMBER(20,0),
  AIB5 NUMBER(20,0),
  AITVA5 NUMBER(20,0),
  G_BF NUMBER(20,0),
  G_VAL_10 NUMBER(20,0),
  G_VAL_11 NUMBER(20,0),
  INCASARI_AG NUMBER(20,0),
  COSTURI_AG NUMBER(20,0),
  MARJA_AG NUMBER(20,0),
  TVA_AG NUMBER(20,0),
  PRET_VANZARE NUMBER(20,0),
  PRET_CUMPARARE NUMBER(20,0),
  MARJA_ANTIC NUMBER(20,0),
  TVA_ANTIC NUMBER(20,0),
  PRSAFILIAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_REZ1_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FBC6407D1D7EB7C41D5A5C264743BA83F825BF4A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_REZ1_XML (
  TIP_PARTENER NUMBER(1,0),
  COTA NUMBER(2,0),
  FACTURIL NUMBER(15,0),
  BAZAL NUMBER(15,0),
  TVAL NUMBER(15,0),
  FACTURILS NUMBER(15,0),
  BAZALS NUMBER(15,0),
  FACTURIA NUMBER(15,0),
  BAZAA NUMBER(15,0),
  TVAA NUMBER(15,0),
  FACTURIAI NUMBER(15,0),
  BAZAAI NUMBER(15,0),
  TVAAI NUMBER(15,0),
  FACTURIAS NUMBER(15,0),
  BAZAAS NUMBER(15,0),
  FACTURIV NUMBER(15,0),
  BAZAV NUMBER(15,0),
  FACTURIC NUMBER(15,0),
  BAZAC NUMBER(15,0),
  TVAC NUMBER(15,0),
  FACTURIN NUMBER(15,0),
  DOCUMENT_N NUMBER(1,0),
  BAZAN NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_REZ2_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EE2CC3ECB22D5CD489344DDB2BF95B91DE2D985B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_REZ2_XML (
  COTA NUMBER(2,0),
  BAZAFSLCOD NUMBER(15,0),
  TVAFSLCOD NUMBER(15,0),
  BAZAFSL NUMBER(15,0),
  TVAFSL NUMBER(15,0),
  BAZAFSA NUMBER(15,0),
  TVAFSA NUMBER(15,0),
  BAZAFSAI NUMBER(15,0),
  TVAFSAI NUMBER(15,0),
  BAZABFAI NUMBER(15,0),
  TVABFAI NUMBER(15,0),
  NRFACTURIL NUMBER(15,0),
  BAZAL NUMBER(15,0),
  TVAL NUMBER(15,0),
  NRFACTURIA NUMBER(15,0),
  BAZAA NUMBER(15,0),
  TVAA NUMBER(15,0),
  NRFACTURIAI NUMBER(15,0),
  BAZAAI NUMBER(15,0),
  TVAAI NUMBER(15,0),
  BAZA_INCASARI_I1 NUMBER(15,0),
  TVA_INCASARI_I1 NUMBER(15,0),
  BAZA_INCASARI_I2 NUMBER(15,0),
  TVA_INCASARI_I2 NUMBER(15,0),
  BAZAL_PF NUMBER(15,0),
  TVAL_PF NUMBER(15,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D39416_SERF_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>722815FE05D4A3F8D1F754ACF512B5C58E35230B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D39416_SERF_XML (
  TIP NUMBER(1,0),
  SERIEI VARCHAR2(20),
  NRI VARCHAR2(20),
  NRF VARCHAR2(20),
  DEN VARCHAR2(100),
  CUI VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394A</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DFD3E7F83FDAF133CC63BE40983060A01408CC8F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394A (
  CODD394A NUMBER(20,0),
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(30),
  DENBFP VARCHAR2(100),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(30),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0),
  RO VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394C</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8E1B77FA9EF1804547FA92CB4B1DF40C6FB7FBEA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394C (
  CODD394C NUMBER(20,0),
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(30),
  DENBFP VARCHAR2(200),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(30),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0),
  RO VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394CC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>985C668E2F08428F6756DC1A80232F3393FD85A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394CC (
  CODD394CC NUMBER(20,0),
  CODD394C NUMBER(20,0),
  DENPRODUS VARCHAR2(200),
  CODNC VARCHAR2(8),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  CODSURSA1 NUMBER(20,0),
  OBS VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394L</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4F8D6F3D87FC02D23A7D82596EA2E8455D843943</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394L (
  CODD394L NUMBER(20,0),
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(30),
  DENBFP VARCHAR2(100),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(30),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0),
  RO VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394V</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1494DD982344C43820274E25F25647B34362EEA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394V (
  CODD394V NUMBER(20,0),
  CODD394 NUMBER(20,0),
  TIPOPERATIUNE VARCHAR2(2),
  CISTVABFP VARCHAR2(30),
  DENBFP VARCHAR2(200),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  GENERAT NUMBER(20,0),
  CFTEXT VARCHAR2(30),
  CODSURSA NUMBER(20,0),
  TIPSURSA NUMBER(20,0),
  OBS VARCHAR2(250),
  NRFACT NUMBER(15,0),
  RO VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394VC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0BCC360C3FF02ADC70FFFDBED7E6EF27101E8897</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394VC (
  CODD394VC NUMBER(20,0),
  CODD394V NUMBER(20,0),
  DENPRODUS VARCHAR2(200),
  CODNC VARCHAR2(8),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  CODSURSA1 NUMBER(20,0),
  OBS VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_D394XC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>70788318AD110A9C9023FAECA62C5B4C0904FBA4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_D394XC (
  CODD394XC NUMBER(20,0),
  CODD394X NUMBER(20,0),
  DENPRODUS VARCHAR2(200),
  CODNC VARCHAR2(8),
  BAZA NUMBER(20,7),
  TVA NUMBER(20,7),
  CODSURSA1 NUMBER(20,0),
  OBS VARCHAR2(250),
  CISTVABFP VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DECODE_ICONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F3EED7F03E20DCA9928A1A9EFB25B63566E3DF3E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DECODE_ICONT (
  CODPART NUMBER(20,0),
  ICONT NUMBER(10,0),
  CODCONT NUMBER(20,0),
  LUNA NUMBER(20,0),
  SIMBOL VARCHAR2(50),
  DENUMIRE VARCHAR2(200),
  TIPCONT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESADVEDINET_H</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F87A60F158AF1A2D0A0139412C9EB5616442551</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESADVEDINET_H (
  FILENAME VARCHAR2(100),
  H01 VARCHAR2(20),
  H02 VARCHAR2(10),
  H03 VARCHAR2(10),
  H04 VARCHAR2(2000),
  D01 VARCHAR2(50),
  D02 VARCHAR2(50),
  T01 VARCHAR2(50),
  T02 VARCHAR2(50),
  T03 VARCHAR2(50),
  T04 VARCHAR2(50),
  R01 VARCHAR2(50),
  R02 VARCHAR2(10),
  R03 VARCHAR2(20),
  R04 VARCHAR2(10),
  R05 VARCHAR2(50),
  R06 VARCHAR2(10),
  P01 VARCHAR2(100),
  P02 VARCHAR2(13),
  P03 VARCHAR2(100),
  P04 VARCHAR2(50),
  P05 VARCHAR2(50),
  P06 VARCHAR2(20),
  P07 VARCHAR2(100),
  P08 VARCHAR2(20),
  P09 VARCHAR2(3),
  P10 VARCHAR2(100),
  P11 VARCHAR2(13),
  P12 VARCHAR2(100),
  P13 VARCHAR2(50),
  P14 VARCHAR2(50),
  P15 VARCHAR2(20),
  P16 VARCHAR2(100),
  P17 VARCHAR2(20),
  P18 VARCHAR2(3),
  P19 VARCHAR2(200),
  P20 VARCHAR2(13),
  P21 VARCHAR2(13),
  P22 VARCHAR2(50),
  P23 VARCHAR2(50),
  P24 VARCHAR2(20),
  P25 VARCHAR2(100),
  P26 VARCHAR2(20),
  P27 VARCHAR2(3),
  P28 VARCHAR2(100),
  P29 VARCHAR2(13),
  P30 VARCHAR2(100),
  P31 VARCHAR2(50),
  P32 VARCHAR2(50),
  P33 VARCHAR2(50),
  P34 VARCHAR2(20),
  P35 VARCHAR2(100),
  P36 VARCHAR2(20),
  P37 VARCHAR2(3),
  P38 VARCHAR2(50),
  P39 VARCHAR2(50),
  P40 VARCHAR2(50),
  P41 VARCHAR2(50),
  P42 VARCHAR2(50),
  P43 VARCHAR2(50),
  P44 VARCHAR2(50),
  P45 VARCHAR2(50),
  P46 VARCHAR2(50),
  P47 VARCHAR2(50),
  P48 VARCHAR2(50),
  P49 VARCHAR2(50),
  P50 VARCHAR2(50),
  P51 VARCHAR2(50),
  P52 VARCHAR2(50),
  P53 VARCHAR2(50),
  P54 VARCHAR2(50),
  P55 VARCHAR2(50),
  P56 VARCHAR2(50),
  P57 VARCHAR2(50),
  P58 VARCHAR2(50),
  P59 VARCHAR2(50),
  P60 VARCHAR2(50),
  P61 VARCHAR2(50),
  P62 VARCHAR2(50),
  P63 VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESADVEDINET_L</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A3A0685F84FB1CFAF090FA5E7023F22B7922A89A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESADVEDINET_L (
  D01 NUMBER,
  D02 VARCHAR2(50),
  D03 VARCHAR2(50),
  D04 VARCHAR2(50),
  D05 VARCHAR2(30),
  D06 VARCHAR2(30),
  D07 VARCHAR2(50),
  D08 VARCHAR2(50),
  D09 VARCHAR2(200),
  D10 VARCHAR2(50),
  D11 VARCHAR2(30),
  D12 VARCHAR2(10),
  D13 VARCHAR2(500),
  D14 VARCHAR2(50),
  D15 VARCHAR2(50),
  D16 VARCHAR2(50),
  D17 VARCHAR2(60),
  D18 VARCHAR2(50),
  D19 VARCHAR2(20),
  D20 VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESADVEDINET_P</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>872D21F6350D93D0EFFA49378DBA4CEFF85AC290</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESADVEDINET_P (
  P01 NUMBER,
  P02 VARCHAR2(50),
  P03 VARCHAR2(50),
  P04 VARCHAR2(50),
  P05 VARCHAR2(50),
  P06 VARCHAR2(50),
  P07 VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESADVEDINET_S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F42312533B89C862E2B650F242CDD1443247FC8C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESADVEDINET_S (
  S01 VARCHAR2(50),
  S02 VARCHAR2(50),
  S03 VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESADVTECNET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>072BDF5B190C4DEA039C39A7AB81C46AF673BD0D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESADVTECNET (
  FILENAME VARCHAR2(400),
  INVOICE01 VARCHAR2(20),
  INVOICE02 VARCHAR2(10),
  INVOICE03 VARCHAR2(50),
  INVOICE04 VARCHAR2(10),
  INVOICE05 VARCHAR2(20),
  INVOICE06 VARCHAR2(10),
  INVOICE07 VARCHAR2(13),
  INVOICE08 VARCHAR2(13),
  INVOICE09 VARCHAR2(13),
  INVOICE10 VARCHAR2(3),
  INVOICE11 VARCHAR2(8),
  INVOICE12 VARCHAR2(200),
  INVOICE13 VARCHAR2(20),
  INVOICE14 VARCHAR2(10),
  INVOICE15 VARCHAR2(10),
  INVLINE01 NUMBER(20,0),
  INVLINE02 VARCHAR2(100),
  INVLINE03 VARCHAR2(100),
  INVLINE04 VARCHAR2(100),
  INVLINE05 VARCHAR2(10),
  INVLINE06 VARCHAR2(200),
  INVLINE07 VARCHAR2(20),
  INVLINE08 VARCHAR2(20),
  INVLINE09 VARCHAR2(20),
  INVLINE10 VARCHAR2(20),
  INVLINE11 VARCHAR2(20),
  INVLINE12 VARCHAR2(20),
  INVLINE13 VARCHAR2(50),
  INVLINE14 VARCHAR2(50),
  INVLINE15 VARCHAR2(50),
  INVLINE16 VARCHAR2(20),
  INVLINE17 VARCHAR2(20),
  INVLINE18 VARCHAR2(20),
  INVLINE19 VARCHAR2(20),
  INVLINE20 VARCHAR2(10),
  INVLINE21 VARCHAR2(13),
  INVLINE22 VARCHAR2(20),
  INVLINE23 VARCHAR2(20),
  INVLINE24 VARCHAR2(20),
  MINCANT NUMBER,
  MAXCANT NUMBER,
  UMEANCOMERR NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESCRIPTORI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7D6F4CA7EA93F8ED0F2D58FD30226A6F7404C5C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESCRIPTORI (
  CODDESCRIPTOR NUMBER(20,0),
  DEN_DESCRIPTOR VARCHAR2(50),
  SIMBOL VARCHAR2(10),
  TIP NUMBER(30,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESCRIPTORI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7E1E70B4E2D21CBBD245819CD1E54F169DD8E7E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESCRIPTORI1 (
  CODDESCRIPTOR1 NUMBER(20,0),
  CODDESCRIPTOR NUMBER(20,0),
  VALOARE VARCHAR2(50),
  CODASOCIAT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DESTINATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C32F9FE32754E32F32D33F44CBB599F48170000D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DESTINATII (
  CODDESTINATIE NUMBER(20,0),
  NUMEDESTINATIE VARCHAR2(200),
  PENTRU VARCHAR2(200),
  SEZON VARCHAR2(200),
  ARTICOL VARCHAR2(200),
  ACTIVITATE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DETAILMAK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>56A76ACC1BB6BEDD76A0C2C177D5329C3B2252E0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DETAILMAK (
  CODDETAILMAK NUMBER(20,0),
  CODMASTERMAK NUMBER(20,0),
  CODDOC NUMBER(20,0),
  COD1 NUMBER(20,0),
  COD2 NUMBER(20,0),
  COD3 NUMBER(20,0),
  COD4 NUMBER(20,0),
  COD5 NUMBER(20,0),
  V1 NUMBER(20,7),
  V2 NUMBER(20,7),
  V3 NUMBER(20,7),
  V4 NUMBER(20,7),
  V5 NUMBER(20,7),
  DATA1 DATE,
  DATA2 DATE,
  OBS1 VARCHAR2(100),
  DENCOD1 VARCHAR2(100),
  DENCOD2 VARCHAR2(100),
  DENCOD3 VARCHAR2(100),
  DENCOD4 VARCHAR2(100),
  DENCOD5 VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DETALIIET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>949050BCEAEC66BE7FB75D627BE8C7576EC6953F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DETALIIET (
  CODDETALIU NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODLOCINC NUMBER(20,0),
  ADRESAINC VARCHAR2(150),
  DATATRANSPORT DATE,
  CODLOCDESC NUMBER(20,0),
  ADRESADESC VARCHAR2(150),
  CODPTF NUMBER(20,0),
  CODBV NUMBER(20,0),
  CODPARTTR NUMBER(20,0),
  NRAUTO VARCHAR2(15),
  NRREMORCA1 VARCHAR2(15),
  NRREMORCA2 VARCHAR2(15),
  CODPARTRETAILTR NUMBER(20,0),
  GREUTATE_BRUTA NUMBER(10,2),
  TIPLOCINC NUMBER(5,0),
  TIPLOCDESC NUMBER(5,0),
  CODPTFDESC NUMBER(20,0),
  TIPTRANZACTIE NUMBER(5,0),
  STATCOMUNITAR NUMBER(1,0),
  SIMBAUTO VARCHAR2(3),
  UIT VARCHAR2(20),
  TIPET NUMBER(6,0),
  TIPMEDIU NUMBER(1,0),
  CODDETALIU1 VARCHAR2(20),
  IDINCARCARE VARCHAR2(20),
  STARE VARCHAR2(20),
  STATCOMUNITAR2 NUMBER(1,0),
  SIMBAUTO2 VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DETALIIET1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>251E930F55C632D13381543811B98669BDA1C380</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DETALIIET1 (
  CODDETALIUET1 NUMBER(20,0),
  CODDETALIUET NUMBER(20,0),
  DATATRANSPORT TIMESTAMP(6),
  NRAUTO VARCHAR2(15),
  NRREMORCA1 VARCHAR2(15),
  NRREMORCA2 VARCHAR2(15),
  OBS VARCHAR2(1000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DEZASAMBLARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>067E70CA636DC42ECD85D4C4A65E37AC25B1A9DD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DEZASAMBLARI (
  CODLIVR1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  INCHISA NUMBER(1,0),
  REST NUMBER(20,7),
  DEN_OBIECT VARCHAR2(200),
  DEN_PART VARCHAR2(100),
  DOCINTR VARCHAR2(100),
  DATADOCINTR DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIFB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78309FE0D1960EC043679627668DA001816AE1DE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIFB (
  SIMBOL VARCHAR2(100),
  D_SI_D NUMBER(20,7),
  D_SI_C NUMBER(20,7),
  D_RP_D NUMBER(20,7),
  D_RP_C NUMBER(20,7),
  D_RC_D NUMBER(20,7),
  D_RC_C NUMBER(20,7),
  D_SF_D NUMBER(20,7),
  D_SF_C NUMBER(20,7),
  V_SI_D NUMBER(20,7),
  V_SI_C NUMBER(20,7),
  V_RP_D NUMBER(20,7),
  V_RP_C NUMBER(20,7),
  V_RC_D NUMBER(20,7),
  V_RC_C NUMBER(20,7),
  V_SF_D NUMBER(20,7),
  V_SF_C NUMBER(20,7),
  N_SI_D NUMBER(20,7),
  N_SI_C NUMBER(20,7),
  N_RP_D NUMBER(20,7),
  N_RP_C NUMBER(20,7),
  N_RC_D NUMBER(20,7),
  N_RC_C NUMBER(20,7),
  N_SF_D NUMBER(20,7),
  N_SF_C NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIFBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2C9AB491D1B21C380904CFC2DAB926902C2CB1AA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIFBJ (
  SIMBOLD VARCHAR2(30),
  SIMBOLC VARCHAR2(30),
  CODDOC NUMBER(20,7),
  TIPDOC NUMBER(20,7),
  D_INDEXLOCAL NUMBER(10,0),
  D_GEST VARCHAR2(300),
  D_VALOARE NUMBER(20,7),
  D_VALOAREV NUMBER(20,7),
  D_OBS VARCHAR2(30),
  D_SUBUNITATEA VARCHAR2(300),
  D_DATADOC DATE,
  D_DOCUMENT VARCHAR2(30),
  V_INDEXLOCAL NUMBER(10,0),
  V_GEST VARCHAR2(300),
  V_VALOARE NUMBER(20,7),
  V_VALOAREV NUMBER(20,7),
  V_OBS VARCHAR2(30),
  V_SUBUNITATEA VARCHAR2(300),
  V_DATADOC DATE,
  V_DOCUMENT VARCHAR2(30),
  N_INDEXLOCAL NUMBER(10,0),
  N_GEST VARCHAR2(300),
  N_VALOARE NUMBER(20,7),
  N_VALOAREV NUMBER(20,7),
  N_OBS VARCHAR2(30),
  N_SUBUNITATEA VARCHAR2(300),
  N_DATADOC DATE,
  N_DOCUMENT VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIFICULTATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>667AA85CB53061BFDA2B2551AD5C28D54FACC0DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIFICULTATI (
  CODDIF NUMBER(20,0),
  DENUMIRE VARCHAR2(150)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIFPRETPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D68F347038011308B1BF4308C6C2D64CD13F2BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIFPRETPROD (
  CODDIFPRETPROD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  OPERAT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIFPRETPROD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DFA3286D3300DA4CA8E6D7FA3F427C3827040EF2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIFPRETPROD1 (
  CODDIFPRETPROD1 NUMBER(20,0),
  CODDIFPRETPROD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  ANLUNA NUMBER(5,0),
  DIFPRET NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DIRTY NUMBER(1,0),
  CURENT NUMBER(1,0),
  INTRARI NUMBER(20,7),
  IESIRI NUMBER(20,7),
  XDIFPRET NUMBER(20,7),
  XCODCENTRU NUMBER(20,0),
  XCODANALIZANOD NUMBER(20,0),
  XCURENT NUMBER(1,0),
  XINTRARI NUMBER(20,7),
  XIESIRI NUMBER(20,7),
  PRET NUMBER(20,7),
  PRETREAL NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINAMIC_COLS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6D7B7A03750595496C5D2B73447309689AB065C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINAMIC_COLS (
  FIELDNAME VARCHAR2(50),
  DISPLAY VARCHAR2(200),
  INDEXLOCAL NUMBER(20,0),
  FTYPE NUMBER(1,0),
  FSIZE NUMBER(4,0),
  COD NUMBER(20,0),
  COD2 NUMBER(20,0),
  COD3 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>02D4E6D9F8C8E70FE51AEAA92874435E645FDBB5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTAT (
  CODDINTRASTAT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNAD NUMBER(2,0),
  TIPA NUMBER(1,0),
  TIPD NUMBER(1,0),
  VATNR VARCHAR2(30),
  FIRMNAME VARCHAR2(100),
  CPLASTNAME VARCHAR2(200),
  CPFIRSTNAME VARCHAR2(200),
  CPPOSITION VARCHAR2(50),
  CPPHONE VARCHAR2(15),
  CPFAX VARCHAR2(15),
  CPEMAIL VARCHAR2(80),
  DTP NUMBER(1,0),
  DTPVATNR VARCHAR2(30),
  DTPFIRMNAME VARCHAR2(100),
  DTPSTREET VARCHAR2(100),
  DTPSTREETNUMBER VARCHAR2(15),
  DTPBLOCK VARCHAR2(5),
  DTPSTAIRS VARCHAR2(5),
  DTPAPARTMENT VARCHAR2(10),
  DTPCODLOCALIT NUMBER(20,0),
  DTPPOSTALCODE VARCHAR2(10),
  OBS VARCHAR2(200),
  INVOICEVALUE_A NUMBER(20,0),
  STATISTICALVALUE_A NUMBER(20,0),
  NETMASS_A NUMBER(20,0),
  INVOICEVALUE_D NUMBER(20,0),
  STATISTICALVALUE_D NUMBER(20,0),
  NETMASS_D NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>01E95C84BAC3769025F946A774490099400136EB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTATA (
  CODDINTRASTATA NUMBER(20,0),
  CODDINTRASTAT NUMBER(20,0),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,0),
  STATISTICALVALUE NUMBER(20,0),
  NETMASS NUMBER(20,0),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(3),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,0),
  COUNTRYOFCONSIGNMENT VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTATD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9DD94AB06C2C9974179339B31673DEC0DBD7068B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTATD (
  CODDINTRASTATD NUMBER(20,0),
  CODDINTRASTAT NUMBER(20,0),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,0),
  STATISTICALVALUE NUMBER(20,0),
  NETMASS NUMBER(20,0),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(3),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,0),
  COUNTRYOFDESTINATION VARCHAR2(3),
  PARTNERCOUNTRYCODE VARCHAR2(3),
  PARTNERVATNR VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTAT_GEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>83B93FEB1A6D3753E44857930CA3FC63C8C208A1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTAT_GEN (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  TIPOPER NUMBER(1,0),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,7),
  STATISTICALVALUE NUMBER(20,7),
  NETMASS NUMBER(20,7),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(2),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,7),
  COUNTRYOFCONSIGNMENT VARCHAR2(3),
  COUNTRYOFDESTINATION VARCHAR2(3),
  PARTNERCOUNTRYCODE VARCHAR2(3),
  PARTNERVATNR VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTAT_TRANSP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>07F1982DED2ABC2C362BB6BEA5B67F0BC2C4FB6B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTAT_TRANSP (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  VALTRANSP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTAT_XMLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B70D96A5FB1B30695B7ABF6B5E846ADA31A9D4DE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTAT_XMLD (
  NUMENOD VARCHAR2(20),
  CN8CODE VARCHAR2(8),
  INVOICEVALUE NUMBER(20,0),
  STATISTICALVALUE NUMBER(20,0),
  NETMASS NUMBER(20,0),
  NATUREOFTRANSACTIONACODE VARCHAR2(3),
  NATUREOFTRANSACTIONBCODE VARCHAR2(3),
  DELIVERYTERMSCODE VARCHAR2(3),
  MODEOFTRANSPORTCODE VARCHAR2(3),
  COUNTRYOFORIGIN VARCHAR2(3),
  SUPPLUNITCODE VARCHAR2(15),
  QTYINSUPPLUNITS NUMBER(20,0),
  COUNTRYOFCONSIGNMENT VARCHAR2(3),
  COUNTRYOFDESTINATION VARCHAR2(3),
  PARTNERCOUNTRYCODE VARCHAR2(3),
  PARTNERVATNR VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DINTRASTAT_XMLH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C0871673038A10FC576704263A1B7821030DF1BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DINTRASTAT_XMLH (
  FILENAME VARCHAR2(100),
  VALID NUMBER(5,0),
  ROOTNAME VARCHAR2(18),
  COUNTRYVER VARCHAR2(4),
  EUCOUNTRYVER VARCHAR2(4),
  CNVER VARCHAR2(5),
  MODEOFTRANSPORTVER VARCHAR2(4),
  DELIVERYTERMSVER VARCHAR2(4),
  NATUREOFTRANSACTIONAVER VARCHAR2(4),
  NATUREOFTRANSACTIONBVER VARCHAR2(4),
  COUNTYVER VARCHAR2(1),
  LOCALITYVER VARCHAR2(7),
  UNITVER VARCHAR2(1),
  VATNR VARCHAR2(15),
  FIRMNAME VARCHAR2(100),
  REFPERIOD VARCHAR2(9),
  CREATEDT VARCHAR2(50),
  LASTNAME VARCHAR2(200),
  FIRSTNAME VARCHAR2(200),
  EMAIL VARCHAR2(80),
  PHONE VARCHAR2(15),
  FAX VARCHAR2(15),
  POSITION VARCHAR2(50),
  DTP NUMBER(1,0),
  DTPVATNR VARCHAR2(10),
  DTPFIRMNAME VARCHAR2(100),
  STREET VARCHAR2(100),
  STREETNUMBER VARCHAR2(15),
  BLOCK VARCHAR2(5),
  STAIRS VARCHAR2(5),
  APARTMENT VARCHAR2(10),
  LOCALITYCODE NUMBER(10,0),
  COUNTYCODE NUMBER(3,0),
  POSTALCODE VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIN_CANTARIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D912239E52CD58ACB1017FCEFC1DCCCB7DD04FA2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIN_CANTARIRI (
  CODCANTAR NUMBER(20,0),
  CODBCAR NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DIRECTIVE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D73D09E460F45AB21EEBDAF8E0AE6471935201FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DIRECTIVE (
  DIRECTIVA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>46CD249B8FA7F7B698058E7B4BF69540B0E42A87</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCART (
  CODDISCART NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  GRUPA VARCHAR2(20),
  DENOBIECT VARCHAR2(200),
  CODCRITERIU1 NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCEXCEPTII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>100AAE7E6CE642B106A9ED760484603EBF189B59</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCEXCEPTII (
  CODDISCEXCEPTIE NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCINTERVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A5B3F982C83AB526660EAD319A546287649C0CF4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCINTERVAL (
  CODDISCINTERVAL NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  PROCENT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCMONETAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4637F975B40863F7BAB62D00711BC487648DF8E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCMONETAR (
  CODDISCMONETAR NUMBER(20,0),
  CODIES NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCOUNT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F052B88925FAC5B28D99DF5E7EA5D5E275F07E3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCOUNT (
  CODDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  CODCRITERIU1 NUMBER(10,0),
  CODTIPSEDIU NUMBER(20,0),
  DISCOUNTINFO VARCHAR2(3000),
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISCPROMORETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F1D56F422BED877167BB6E3BB19AE3D13108AA6A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISCPROMORETAIL (
  COD NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DISCPROMO NUMBER(20,7),
  DENUMIRE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISPLIVRARE_WMS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7E554A430CBB0456EBF96B7DBF9E9047A020447</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISPLIVRARE_WMS (
  CODDLWMS NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODGEST NUMBER(20,0),
  SERIE VARCHAR2(75),
  CANT NUMBER(20,7),
  USERID NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISPLIVRARE_WMS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>74C819F8698209DC563E16E445597ADF06972C6C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISPLIVRARE_WMS1 (
  CODDLWMS1 NUMBER(20,0),
  CODDLWMS NUMBER(20,0),
  CANT NUMBER(20,7),
  CODLOCATIENOUA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTANTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ABFC57A5C232D5A9683E81BFC2AFBD6FF5CF4889</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTANTA (
  CODDISTANTA NUMBER(20,0) NOT NULL,
  CODGEST_START NUMBER(20,0),
  CODGEST_STOP NUMBER(20,0),
  CODLOCALIT_START NUMBER(20,0),
  CODLOCALIT_STOP NUMBER(20,0),
  KM NUMBER(20,0),
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(22,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B74AE2EB96ACBB251BBF0FC74A7EB05F231E8CC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB (
  CODDISTRIB NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  ZI NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BBA073B9C95C78F19A75F8CFBCB24E6491DFBB54</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB1 (
  CODDISTRIB1 NUMBER(20,0),
  CODDISTRIB NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CODTRASEU NUMBER(20,0),
  DENPERS VARCHAR2(400),
  NRINREG VARCHAR2(20),
  DENTRASEU VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B488F1FE99B106363CE57293F33CB846BD495261</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB2 (
  CODDISTRIB2 NUMBER(20,0),
  CODDISTRIB NUMBER(20,0),
  CODDISTRIB1 NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  SOLD NUMBER(20,7),
  POZTRASEU NUMBER(20,0),
  DEN_PART VARCHAR2(50),
  OBS VARCHAR2(30),
  ADRESA VARCHAR2(200),
  DEN_JUDET VARCHAR2(30),
  DEN_LOCALIT VARCHAR2(50),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5B352FE3FFD20890C835F899EEA71345D498A28C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB3 (
  CODDISTRIB3 NUMBER(20,0),
  CODDISTRIB NUMBER(20,0),
  CODDISTRIB1 NUMBER(20,0),
  CODDISTRIB2 NUMBER(20,0),
  DOC VARCHAR2(100),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  VALREAL NUMBER(20,7),
  RESTREAL NUMBER(20,7),
  TERMEN DATE,
  ZILESCADENTE NUMBER(10,0),
  SIMBOLCONT VARCHAR2(100),
  DEN_SUBUNIT VARCHAR2(150),
  PREFIXDOC VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIBCHELT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>678AC7FC97D92D71536365C144B8D218995E94D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIBCHELT (
  CODDISTRIBCHELT NUMBER(20,0),
  TIPDOC NUMBER(2,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  FAZA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  COEFPROD NUMBER(20,7),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIBCHELT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>12A190EC0E6ADD2991DBC11DDC27D4C298DB9C3F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIBCHELT1 (
  CODDISTRIBCHELT1 NUMBER(20,0),
  CODDISTRIBCHELT NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  BUTON VARCHAR2(10),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIBCHELT2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>890C21C0F271E3EE0F6A18479006D1BE1E8CA2E2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIBCHELT2 (
  CODDISTRIBCHELT2 NUMBER(20,0),
  CODDISTRIBCHELT1 NUMBER(20,0),
  CODDISTRIBCHELT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(50),
  PROCENT NUMBER(20,7),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(100),
  VALGEST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB_FACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7D8EE9C9C5B2487A71FE92299A35F47AFC4621E3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB_FACT (
  CODDISTRIBFACT NUMBER(20,0),
  CODIES NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DEN_PART VARCHAR2(200),
  VALDOC NUMBER(20,7),
  DEN_PERS VARCHAR2(400),
  SERIEDOC VARCHAR2(20),
  SIMBOLMONEDA VARCHAR2(100),
  ORA VARCHAR2(15),
  CODPERS NUMBER(20,0),
  SEDIU VARCHAR2(300),
  TRASEU VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DISTRIB_INC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>95D023F95BC3DA997BAAF09D667175399FD6AED5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DISTRIB_INC (
  CODDISTRIBINC NUMBER(20,0),
  CODTREZOR1 NUMBER(20,0),
  PREFIXDOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DEN_PART VARCHAR2(200),
  VALDOC NUMBER(20,7),
  DEN_PERS VARCHAR2(400),
  SERIEDOC VARCHAR2(20),
  SIMBOLMONEDA VARCHAR2(100),
  ORA VARCHAR2(15),
  CODPERS NUMBER(20,0),
  SEDIU VARCHAR2(30),
  TRASEU VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCASOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0D0CE596CD662E077BEFC5753F0CCB69A7C657DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCASOC (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOCASOC NUMBER(20,0),
  TIPDOCASOC NUMBER(20,0),
  DENDOC VARCHAR2(500),
  DENDOCASOC VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCCARNETE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9559A3564F0803B5BB3350DC0BFF10072744B61E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCCARNETE (
  CODCARNET NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  DENUMIRE VARCHAR2(50),
  SERIE VARCHAR2(20),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  FREENR NUMBER(20,0),
  INACTIV NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  LIMITA NUMBER(20,0),
  STARTNRINI NUMBER(20,0),
  DEDICAT NUMBER(1,0),
  COMENZIONLINE NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  FARASALVARE NUMBER(1,0),
  IN_UPDATE NUMBER(1,0),
  ALLSUBUNIT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCFREE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>714FBD0C977264A19B537D3B21A16AAC7C9BBE22</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCFREE (
  CODDOCFREE NUMBER(20,0),
  CODCARNET NUMBER(20,0),
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BFB4842BA205802E50064CD73EE0893355ECED01</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCLINK (
  CODDOCLINK NUMBER(20,0),
  CODCARNET NUMBER(20,0),
  CODMACHETA NUMBER(10,0),
  DENMACHETA VARCHAR2(45)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5E844CCFD4014B4CB09C44F7DEB7BE4E1C8C193</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCS (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCSUPLIM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>72B43A30D0832623EC1FD7C11853D0470075F277</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCSUPLIM (
  CODDOCSUPLIM NUMBER(20,0),
  TIPDOC NUMBER(2,0),
  DENDOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCSUPLIM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A8FB3527FEB6F0F28092A1249D9D89EA218A1EB6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCSUPLIM1 (
  CODDOCSUPLIM1 NUMBER(20,0),
  CODDOCSUPLIM NUMBER(20,0),
  DENLINIE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCUMENTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2847EEE9014B100B133D61AB2E225C7CA4FBA12D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCUMENTE (
  CODDOCUMENT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  FILENAME VARCHAR2(200),
  DOC BLOB,
  OBS VARCHAR2(4000),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODDOSAR NUMBER(20,0),
  CODDEPOZIT NUMBER(20,0),
  TIPDOCUMENT NUMBER(2,0),
  EXPEFACT NUMBER(1,0),
  EXTERN NUMBER(1,0),
  INCARCAT NUMBER(1,0),
  MARIME NUMBER(20,6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCUSERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>04769DECF0BAC5FCAE7B3E1FCB0D123399ABC446</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCUSERS (
  CODDOCUSERS NUMBER(20,0),
  CODCARNET NUMBER(20,0),
  CODUSER NUMBER(10,0),
  USERNAME VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0B296860352A7AE0F1A8F4391C370728278F4612</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE (
  FILENAME VARCHAR2(200),
  INVOICE00A VARCHAR2(3),
  INVOICE00B VARCHAR2(20),
  INVOICE00C VARCHAR2(20),
  INVOICE01 VARCHAR2(60),
  INVOICE01B VARCHAR2(20),
  INVOICE02 VARCHAR2(5),
  INVOICE03 VARCHAR2(10),
  INVOICE03B VARCHAR2(20),
  INVOICE04 VARCHAR2(5),
  INVOICE05 VARCHAR2(200),
  INVOICE06 VARCHAR2(3),
  INVOICE07 VARCHAR2(3),
  INVOICE08 VARCHAR2(3),
  INVOICE09 VARCHAR2(3),
  INVOICE10 VARCHAR2(3),
  INVOICE11 NUMBER,
  INVOICE12A VARCHAR2(50),
  INVOICE12B VARCHAR2(10),
  INVOICE13A VARCHAR2(50),
  INVOICE13B VARCHAR2(10),
  INVOICE14A VARCHAR2(50),
  INVOICE14B VARCHAR2(10),
  INVOICE15A VARCHAR2(50),
  INVOICE15B VARCHAR2(10),
  INVOICE16A VARCHAR2(20),
  INVOICE16B VARCHAR2(20),
  INVOICE17A VARCHAR2(20),
  INVOICE17B VARCHAR2(20),
  INVOICE18A VARCHAR2(20),
  INVOICE18B VARCHAR2(20),
  INVOICE19A VARCHAR2(20),
  INVOICE19B VARCHAR2(20),
  ASP01 VARCHAR2(50),
  ASP02 VARCHAR2(20),
  ASP03 VARCHAR2(13),
  ASP04 VARCHAR2(200),
  ASP_ADR01 VARCHAR2(20),
  ASP_ADR02 VARCHAR2(100),
  ASP_ADR03 VARCHAR2(20),
  ASP_ADR04 VARCHAR2(11),
  ASP_ADR05 VARCHAR2(54),
  ASP_ADR06 VARCHAR2(10),
  ASP_ADR07 VARCHAR2(50),
  ASP_ADR08 VARCHAR2(2),
  ASP_ADR09 VARCHAR2(2),
  ASP_ADR10 VARCHAR2(50),
  ASP_PLE01 VARCHAR2(20),
  ASP_PLE02 VARCHAR2(19),
  ASP_PLE03 VARCHAR2(3),
  ACP01 VARCHAR2(75),
  ACP02 VARCHAR2(100),
  ACP_ADR01 VARCHAR2(20),
  ACP_ADR02 VARCHAR2(100),
  ACP_ADR03 VARCHAR2(47),
  ACP_ADR04 VARCHAR2(51),
  ACP_ADR05 VARCHAR2(54),
  ACP_ADR06 VARCHAR2(10),
  ACP_ADR07 VARCHAR2(30),
  ACP_ADR08 VARCHAR2(2),
  ACP_ADR09 VARCHAR2(3),
  ACP_ADR10 VARCHAR2(13),
  ACP_PLE01 VARCHAR2(20),
  ACP_PLE02 VARCHAR2(20),
  ACP_PLE03 VARCHAR2(20),
  DEL01 VARCHAR2(10),
  DEL_LOC01 VARCHAR2(13),
  DEL_LOC02 VARCHAR2(100),
  DEL_LOC03 VARCHAR2(13),
  DEL_ADR01 VARCHAR2(20),
  DEL_ADR02 VARCHAR2(100),
  DEL_ADR03 VARCHAR2(47),
  DEL_ADR04 VARCHAR2(51),
  DEL_ADR05 VARCHAR2(54),
  DEL_ADR06 VARCHAR2(10),
  DEL_ADR07 VARCHAR2(30),
  DEL_ADR08 VARCHAR2(2),
  DEL_ADR09 VARCHAR2(3),
  PM1 VARCHAR2(2),
  PM2 VARCHAR2(10),
  PM3A VARCHAR2(30),
  PM3B VARCHAR2(3),
  PM3C VARCHAR2(50),
  PM3D VARCHAR2(30),
  PM3_ADR01 VARCHAR2(20),
  PM3_ADR02 VARCHAR2(20),
  PM3_ADR03 VARCHAR2(20),
  PM3_ADR04 VARCHAR2(20),
  PM3_ADR05 VARCHAR2(54),
  PM3_ADR06 VARCHAR2(20),
  PM3_ADR07 VARCHAR2(30),
  PM3_ADR08 VARCHAR2(2),
  PM3_ADR09 VARCHAR2(2),
  PM3_ADR10 VARCHAR2(20),
  PM4A VARCHAR2(50),
  PM4B VARCHAR2(3),
  PM4C VARCHAR2(50),
  PM4_ADR01 VARCHAR2(20),
  PM4_ADR02 VARCHAR2(20),
  PM4_ADR03 VARCHAR2(20),
  PM4_ADR04 VARCHAR2(20),
  PM4_ADR05 VARCHAR2(75),
  PM4_ADR06 VARCHAR2(20),
  PM4_ADR07 VARCHAR2(20),
  PM4_ADR08 VARCHAR2(10),
  PM4_ADR09 VARCHAR2(2),
  PM4_ADR10 VARCHAR2(20),
  PT1 VARCHAR2(20),
  PT2 VARCHAR2(20),
  PT3 VARCHAR2(20),
  PT4 VARCHAR2(20),
  PT5 VARCHAR2(20),
  PT6 VARCHAR2(20),
  PT7 VARCHAR2(20),
  PT8 VARCHAR2(20),
  PT9A VARCHAR2(20),
  PT9B VARCHAR2(20),
  PT9C VARCHAR2(20),
  PT9D VARCHAR2(20),
  PT9E VARCHAR2(40),
  PT9F VARCHAR2(1),
  PT9G VARCHAR2(20),
  PER01 VARCHAR2(20),
  PER02 VARCHAR2(20),
  PER03 VARCHAR2(20),
  PER04 VARCHAR2(20),
  PER05 VARCHAR2(20),
  PER06 VARCHAR2(20),
  PER07 VARCHAR2(20),
  PER08 VARCHAR2(20),
  PER09 VARCHAR2(20),
  TAX01 VARCHAR2(40),
  TAX02 VARCHAR2(14),
  TAX02B VARCHAR2(20),
  TAX02C VARCHAR2(20),
  TAX03 VARCHAR2(14),
  TAX04 VARCHAR2(14),
  TST03 VARCHAR2(20),
  TST04 VARCHAR2(20),
  TST06 VARCHAR2(20),
  TST07 VARCHAR2(20),
  TST08 VARCHAR2(20),
  TST09 VARCHAR2(20),
  TST10 VARCHAR2(20),
  TST11 VARCHAR2(20),
  TST12 VARCHAR2(20),
  TST13 VARCHAR2(16),
  TST14 VARCHAR2(20),
  TST15 VARCHAR2(20),
  TST16 VARCHAR2(20),
  TST17 VARCHAR2(20),
  TST18 VARCHAR2(20),
  TST19 VARCHAR2(1),
  TST20 VARCHAR2(20),
  TST21 VARCHAR2(1),
  TST22 VARCHAR2(3),
  TST23 VARCHAR2(3),
  LMT01 VARCHAR2(20),
  LMT04 VARCHAR2(20),
  LMT05 VARCHAR2(20),
  LMT06 VARCHAR2(20),
  LMT07 VARCHAR2(20),
  LMT08 VARCHAR2(20),
  CODIES1 NUMBER(20,0),
  LINE01 NUMBER,
  LINE02 VARCHAR2(200),
  LINE03A VARCHAR2(3),
  LINE03B VARCHAR2(16),
  LINE03C VARCHAR2(16),
  LINE03D VARCHAR2(1),
  LINE03E VARCHAR2(3),
  LINE04A VARCHAR2(16),
  LINE04B VARCHAR2(16),
  LINE05A VARCHAR2(14),
  LINE05B VARCHAR2(14),
  LINE05C VARCHAR2(14),
  LINE05D VARCHAR2(20),
  LINE05E VARCHAR2(3),
  LINE05F VARCHAR2(20),
  LINE05G VARCHAR2(5),
  LINED01A VARCHAR2(50),
  LINED01B VARCHAR2(10),
  LINED02A VARCHAR2(50),
  LINED02B VARCHAR2(10),
  LINED03A VARCHAR2(50),
  LINED03B VARCHAR2(10),
  LINED04A VARCHAR2(50),
  LINED04B VARCHAR2(10),
  LINED05A VARCHAR2(20),
  LINED05B VARCHAR2(20),
  LINE06 VARCHAR2(200),
  LINE06A VARCHAR2(80),
  LINE06B VARCHAR2(20),
  LINE06C VARCHAR2(20),
  LINE06D VARCHAR2(33),
  LINE06E VARCHAR2(1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_AC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E1FDF47B87B9622FC4C8CA1A001966E9FAFA584D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_AC (
  CODIES1 NUMBER(20,0),
  AC01 VARCHAR2(1),
  AC02 VARCHAR2(10),
  AC03 VARCHAR2(50),
  AC04 VARCHAR2(50),
  AC05 NUMBER(20,7),
  AC06 NUMBER(20,0),
  AC07 NUMBER(10,0),
  AC08 NUMBER(20,7),
  AC09 NUMBER(20,7),
  AC10 VARCHAR2(50),
  AC11 VARCHAR2(50),
  AC12 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_AC_XML</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>915D503A1FEC9F551CCB8598AB220DD995B52BAF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_AC_XML (
  CODIES1 NUMBER(20,0),
  AC01 VARCHAR2(1),
  AC02 VARCHAR2(10),
  AC03 VARCHAR2(50),
  AC04 VARCHAR2(50),
  AC05 VARCHAR2(30),
  AC06 VARCHAR2(20),
  AC07 NUMBER(10,0),
  AC08 VARCHAR2(30),
  AC09 VARCHAR2(30),
  AC10 VARCHAR2(50),
  AC11 VARCHAR2(50),
  AC12 VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_DESADV_H</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E220D8DF834AAA882C1145F8EE3A7C64B5CA2430</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_DESADV_H (
  FILENAME VARCHAR2(100),
  H_ID VARCHAR2(60),
  H_COPYINDICATOR VARCHAR2(20),
  H_UUID VARCHAR2(20),
  H_ISSUEDATE VARCHAR2(20),
  H_ISSUETIME VARCHAR2(20),
  H_DOCUMENTSTATUSCODE VARCHAR2(20),
  H_DESPATCHADVICETYPECODE VARCHAR2(20),
  H_NOTE VARCHAR2(200),
  H_LINECOUNTNUMERIC NUMBER(5,0),
  H_ORD_ID VARCHAR2(20),
  H_ORD_SALESORDERID VARCHAR2(20),
  H_ORD_UUID VARCHAR2(20),
  H_ORD_ISSUEDATE VARCHAR2(20),
  H_DSP_CUSTAAID VARCHAR2(100),
  H_DSP_P_ENDPOINTID VARCHAR2(13),
  H_DSP_P_ENDPOINTIDX VARCHAR2(20),
  H_DSP_P_PI_ID VARCHAR2(13),
  H_DSP_P_PN_NAME VARCHAR2(200),
  H_DSP_P_PA_STREETNAME VARCHAR2(100),
  H_DSP_P_PA_ADSTRNAME VARCHAR2(100),
  H_DSP_P_PA_BUILDINGNAME VARCHAR2(20),
  H_DSP_P_PA_BUILDINGNUMBER VARCHAR2(11),
  H_DSP_P_PA_CITYNAME VARCHAR2(50),
  H_DSP_P_PA_POSTALZONE VARCHAR2(10),
  H_DSP_P_PA_COUNTRYSUBENTITY VARCHAR2(50),
  H_DSP_P_PA_AL_LINE VARCHAR2(20),
  H_DSP_P_PA_C_IDCODE VARCHAR2(20),
  H_DSP_P_PTS_REGNAME VARCHAR2(20),
  H_DSP_P_PTS_COMPID VARCHAR2(20),
  H_DSP_P_PTS_EXEMPTIONREASON VARCHAR2(20),
  H_DSP_P_PTS_TS_ID VARCHAR2(20),
  H_DSP_P_PTS_TS_TAXTYPECODE VARCHAR2(20),
  H_DSP_P_C_NAME VARCHAR2(20),
  H_DSP_P_C_TELEPHONE VARCHAR2(20),
  H_DSP_P_C_TELEFAX VARCHAR2(20),
  H_DSP_P_C_EMAIL VARCHAR2(20),
  H_DCP_CUSTAAID VARCHAR2(20),
  H_DCP_P_ENDPOINTID VARCHAR2(13),
  H_DCP_P_ENDPOINTIDX VARCHAR2(20),
  H_DCP_P_PI_ID VARCHAR2(75),
  H_DCP_P_PN_NAME VARCHAR2(100),
  H_DCP_P_PA_STRNAME VARCHAR2(100),
  H_DCP_P_PA_ADSTRNAME VARCHAR2(100),
  H_DCP_P_PA_BUILDINGNAME VARCHAR2(20),
  H_DCP_P_PA_BUILDINGNUMBER VARCHAR2(51),
  H_DCP_P_PA_CITYNAME VARCHAR2(50),
  H_DCP_P_PA_POSTALZONE VARCHAR2(20),
  H_DCP_P_PA_COUNTRYSUBENTITY VARCHAR2(30),
  H_DCP_P_PA_AL_LINE VARCHAR2(20),
  H_DCP_P_PA_C_IDCODE VARCHAR2(3),
  H_DCP_P_PTS_REGNAME VARCHAR2(20),
  H_DCP_P_PTS_COMPID VARCHAR2(20),
  H_DCP_P_PTS_EXEMPTIONREASON VARCHAR2(20),
  H_DCP_P_PTS_TS_ID VARCHAR2(20),
  H_DCP_P_PTS_TS_TAXTYPECODE VARCHAR2(20),
  H_DCP_P_C_NAME VARCHAR2(20),
  H_DCP_P_C_TELEPHONE VARCHAR2(20),
  H_DCP_P_C_TELEFAX VARCHAR2(20),
  H_DCP_P_C_EMAIL VARCHAR2(20),
  H_BCP_CUSTAAID VARCHAR2(20),
  H_BCP_P_ENDPOINTID VARCHAR2(13),
  H_BCP_P_ENDPOINTIDX VARCHAR2(20),
  H_BCP_P_PI_ID VARCHAR2(75),
  H_BCP_P_PN_NAME VARCHAR2(100),
  H_BCP_P_PA_STRNAME VARCHAR2(100),
  H_BCP_P_PA_ADSTRNAME VARCHAR2(100),
  H_BCP_P_PA_BUILDINGNAME VARCHAR2(20),
  H_BCP_P_PA_BUILDINGNUMBER VARCHAR2(51),
  H_BCP_P_PA_CITYNAME VARCHAR2(50),
  H_BCP_P_PA_POSTALZONE VARCHAR2(20),
  H_BCP_P_PA_COUNTRYSUBENTITY VARCHAR2(30),
  H_BCP_P_PA_AL_LINE VARCHAR2(20),
  H_BCP_P_PA_C_IDCODE VARCHAR2(3),
  H_BCP_P_PTS_REGNAME VARCHAR2(20),
  H_BCP_P_PTS_COMPID VARCHAR2(20),
  H_BCP_P_PTS_EXEMPTIONREASON VARCHAR2(20),
  H_BCP_P_PTS_TS_ID VARCHAR2(20),
  H_BCP_P_PTS_TS_TAXTYPECODE VARCHAR2(20),
  H_BCP_P_C_NAME VARCHAR2(20),
  H_BCP_P_C_TELEPHONE VARCHAR2(20),
  H_BCP_P_C_TELEFAX VARCHAR2(20),
  H_BCP_P_C_EMAIL VARCHAR2(20),
  H_SSP_CUSTAAID VARCHAR2(100),
  H_SSP_P_ENDPOINTID VARCHAR2(13),
  H_SSP_P_ENDPOINTIDX VARCHAR2(20),
  H_SSP_P_PI_ID VARCHAR2(13),
  H_SSP_P_PN_NAME VARCHAR2(200),
  H_SSP_P_PA_STRNAME VARCHAR2(100),
  H_SSP_P_PA_ADSTRNAME VARCHAR2(100),
  H_SSP_P_PA_BUILDINGNAME VARCHAR2(20),
  H_SSP_P_PA_BUILDINGNUMBER VARCHAR2(51),
  H_SSP_P_PA_CITYNAME VARCHAR2(50),
  H_SSP_P_PA_POSTALZONE VARCHAR2(10),
  H_SSP_P_PA_COUNTRYSUBENTITY VARCHAR2(50),
  H_SSP_P_PA_AL_LINE VARCHAR2(20),
  H_SSP_P_PA_C_IDCODE VARCHAR2(20),
  H_SSP_P_PTS_REGNAME VARCHAR2(20),
  H_SSP_P_PTS_COMPID VARCHAR2(20),
  H_SSP_P_PTS_EXEMPTIONREASON VARCHAR2(20),
  H_SSP_P_PTS_TS_ID VARCHAR2(20),
  H_SSP_P_PTS_TS_TAXTYPECODE VARCHAR2(20),
  H_SSP_P_C_NAME VARCHAR2(20),
  H_SSP_P_C_TELEPHONE VARCHAR2(20),
  H_SSP_P_C_TELEFAX VARCHAR2(20),
  H_SSP_P_C_EMAIL VARCHAR2(20),
  H_OCP_CUSTAAID VARCHAR2(20),
  H_OCP_P_ENDPOINTID VARCHAR2(20),
  H_OCP_P_ENDPOINTIDX VARCHAR2(20),
  H_OCP_P_PI_ID VARCHAR2(20),
  H_OCP_P_PN_NAME VARCHAR2(20),
  H_OCP_P_PA_STRNAME VARCHAR2(20),
  H_OCP_P_PA_ADSTRNAME VARCHAR2(20),
  H_OCP_P_PA_BUILDINGNAME VARCHAR2(20),
  H_OCP_P_PA_BUILDINGNUMBER VARCHAR2(20),
  H_OCP_P_PA_CITYNAME VARCHAR2(20),
  H_OCP_P_PA_POSTALZONE VARCHAR2(20),
  H_OCP_P_PA_COUNTRYSUBENTITY VARCHAR2(20),
  H_OCP_P_PA_AL_LINE VARCHAR2(20),
  H_OCP_P_PA_C_IDCODE VARCHAR2(20),
  H_OCP_P_PTS_REGNAME VARCHAR2(20),
  H_OCP_P_PTS_COMPID VARCHAR2(20),
  H_OCP_P_PTS_EXEMPTIONREASON VARCHAR2(20),
  H_OCP_P_PTS_TS_ID VARCHAR2(20),
  H_OCP_P_PTS_TS_TAXTYPECODE VARCHAR2(20),
  H_OCP_P_C_NAME VARCHAR2(20),
  H_OCP_P_C_TELEPHONE VARCHAR2(20),
  H_OCP_P_C_TELEFAX VARCHAR2(20),
  H_OCP_P_C_EMAIL VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_DESADV_L</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F8ED9C4B43C7340B30A2EAEBB4E6148B15DF1976</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_DESADV_L (
  L_ID NUMBER(5,0),
  L_UUID VARCHAR2(20),
  L_NOTE VARCHAR2(200),
  L_LINESTATUSCODE VARCHAR2(20),
  L_DELIVEREDCANT VARCHAR2(16),
  L_DELIVEREDCANTX VARCHAR2(3),
  L_BACKORDERCANT VARCHAR2(20),
  L_BACKORDERREASON VARCHAR2(20),
  L_OUTSTANDINGCANT VARCHAR2(20),
  L_OUTSTANDINGREASON VARCHAR2(20),
  L_OVERSUPPLYCANT VARCHAR2(20),
  L_OVERSUPPLYREASON VARCHAR2(20),
  L_OLR_LINEID NUMBER(5,0),
  L_OLR_SALESORDERLINEID VARCHAR2(20),
  L_OLR_UUID VARCHAR2(20),
  L_OLR_LINESTATUSCODE VARCHAR2(20),
  L_OLR_ORD_ID VARCHAR2(60),
  L_OLR_ORD_SALESORDERID VARCHAR2(20),
  L_OLR_ORD_UUID VARCHAR2(20),
  L_OLR_ORD_ID_ISSUEDATE VARCHAR2(20),
  L_I_DESCRIPTION VARCHAR2(200),
  L_I_PACKCANT VARCHAR2(20),
  L_I_PACKSIZENUMERIC VARCHAR2(20),
  L_I_CATALOGUEINDICATOR VARCHAR2(20),
  L_I_NAME VARCHAR2(20),
  L_I_HAZARDOUSRISKINDICATOR VARCHAR2(20),
  L_I_ADINFORMATION VARCHAR2(20),
  L_I_KEYWORD VARCHAR2(20),
  L_I_BRANDNAME VARCHAR2(20),
  L_I_MODELNAME VARCHAR2(20),
  L_I_II1_ID VARCHAR2(80),
  L_I_II2_ID VARCHAR2(20),
  L_I_II3_ID VARCHAR2(20),
  L_I_II_MANUFACTUREDATE VARCHAR2(20),
  L_I_II_MANUFACTURETIME VARCHAR2(20),
  L_I_II_BESTBEFOREDATE VARCHAR2(20),
  L_I_II_SERIALID VARCHAR2(20),
  L_I_II_LI_LOTNUMBERID VARCHAR2(20),
  L_I_II_LI_EXPIRYDATE VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_DESADV_S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3C237491E61E390D6407E898191B0EFB974334EF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_DESADV_S (
  S_ID VARCHAR2(20),
  S_D_ACTUALDELIVERYDATE VARCHAR2(20),
  S_D_ACTUALDELIVERYTIME VARCHAR2(20),
  S_D_DA_STRNAME VARCHAR2(20),
  S_D_DA_ADSTRNAME VARCHAR2(20),
  S_D_DA_BUILDINGNAME VARCHAR2(20),
  S_D_DA_BUILDINGNUMBER VARCHAR2(20),
  S_D_DA_CITYNAME VARCHAR2(20),
  S_D_DA_POSTALZONE VARCHAR2(20),
  S_D_DA_COUNTRYSUBENTITY VARCHAR2(20),
  S_D_DA_AL_LINE VARCHAR2(20),
  S_D_DA_C_IDCODE VARCHAR2(20),
  S_D_RDP_STARTDATE VARCHAR2(20),
  S_D_RDP_STARTTIME VARCHAR2(20),
  S_D_RDP_ENDDATE VARCHAR2(20),
  S_D_RDP_ENDTIME VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_DESADV_SC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CE839B0BA1D94E04E56B28712435C105766C6F1D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_DESADV_SC (
  S_C_ID VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_DESADV_ST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>14EB9D4E0EF331D8925A1E8699A2DC063319F7AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_DESADV_ST (
  S_THU_ID VARCHAR2(20),
  S_THU_QUANTITY VARCHAR2(20),
  S_THU_RMI VARCHAR2(20),
  S_THU_PACKAGELEVELCODE VARCHAR2(20),
  S_THU_PACKAGINGTYPECODE VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOCXCHANGE_TAX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20924F6DB5155103D9B416283E0E6686BD2C2245</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOCXCHANGE_TAX (
  TAXSUBTOTAL01 VARCHAR2(20),
  TAXSUBTOTAL02 VARCHAR2(20),
  TAXSUBTOTAL03 VARCHAR2(20),
  TAXSUBTOTAL04 VARCHAR2(20),
  TAXSUBTOTAL05 VARCHAR2(20),
  TAXSUBTOTAL06 VARCHAR2(20),
  TAXSUBTOTAL07 VARCHAR2(20),
  TAXSUBTOTAL08 VARCHAR2(20),
  TAXSUBTOTAL09 VARCHAR2(20),
  TAXSUBTOTAL10 VARCHAR2(20),
  TAXSUBTOTAL11 VARCHAR2(20),
  TAXSUBTOTAL12 VARCHAR2(20),
  TAXSUBTOTAL13 VARCHAR2(20),
  TAXSUBTOTAL14 VARCHAR2(20),
  TAXSUBTOTAL15 VARCHAR2(20),
  TAXSUBTOTAL16 VARCHAR2(20),
  TAXSUBTOTAL17 VARCHAR2(20),
  TAXSUBTOTAL18 VARCHAR2(20),
  TAXSUBTOTAL19 VARCHAR2(20),
  TAXSUBTOTAL20 VARCHAR2(20),
  TAXSUBTOTAL21 VARCHAR2(20),
  TAXSUBTOTAL22 VARCHAR2(20),
  TAXSUBTOTAL23 VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOC_ANALIZAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3810A7500C98FF20012BEDBFFE9C7C08429D8F63</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOC_ANALIZAT (
  CODDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SERIADOC VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOC_DIRTY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>99E777C0E60C48F71E4771407975E2BFDABA1E94</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOC_DIRTY (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOMENIIACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>493AE066070DE94A5250DB86ED82EBA59700EC82</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOMENIIACT (
  CODDOMENIUACT NUMBER(20,0),
  DENDOMENIUACT VARCHAR2(160),
  CODCAEN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DOSARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3944DEA44CF3361D2BBA6AD7712B42343097CA1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DOSARE (
  CODDOSAR NUMBER(6,0) NOT NULL,
  DENUMIRE VARCHAR2(30),
  DULAP VARCHAR2(20),
  RAFT VARCHAR2(20),
  TIP NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DPROFIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>18B62D028B8FE3A081AD9FC948100F7E2163BF86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DPROFIT (
  CODDPROFIT NUMBER(20,0),
  TIPPROFIT NUMBER(5,0),
  TIPAN NUMBER(5,0),
  ELEMSIMVENIT NUMBER(20,7),
  ELEMSIMCHELT NUMBER(20,7),
  DEDUCERI NUMBER(20,7),
  DEDREZLEG NUMBER(20,7),
  DEDPROFITR NUMBER(20,7),
  DEDALTE NUMBER(20,7),
  CHELTAFVENIT NUMBER(20,7),
  CHELTPRADM NUMBER(20,7),
  CHELTPRNEDED NUMBER(20,7),
  PIERDERE NUMBER(20,7),
  PROFITCONTA NUMBER(20,7),
  PROFITIMPOZ NUMBER(20,7),
  SUMAMAX NUMBER(20,7),
  CHELTSPONSOR NUMBER(20,7),
  IMPOZITPROFIT NUMBER(20,7),
  IMPOZITPROFITD NUMBER(20,7),
  AN NUMBER(4,0),
  TRIMESTRU NUMBER(1,0),
  TOTALRULAJV NUMBER(20,7),
  TOTALVENITURI NUMBER(20,7),
  TOTALSUMEV NUMBER(20,7),
  TOTALRULAJC NUMBER(20,7),
  TOTALCHELT NUMBER(20,7),
  TOTALSUMEC NUMBER(20,7),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AMOFISC NUMBER(20,7),
  CHELTDOBPREC NUMBER(20,7),
  PROVFISC NUMBER(20,7),
  CREDITFISCEXT NUMBER(20,7),
  IMPPROFREINV NUMBER(20,7),
  ALTESCUTIRI NUMBER(20,7),
  CIFRAAFACERI NUMBER(20,7),
  CREDITFISCAL NUMBER(20,7),
  IMPOZITPROFITC NUMBER(20,7),
  IMPPROFDIF NUMBER(20,7),
  ANGENERARE NUMBER(4,0),
  LUNAGENERARE NUMBER(2,0),
  SPONSORREPORT NUMBER(20,7),
  CODNC NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TRIMESTRUT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DPROFITC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EF8E2BDB78B2934C5726D71C8DF98C783DF18E8B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DPROFITC (
  CODDPROFITC NUMBER(20,0),
  CODDPROFIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  RULAJ NUMBER(20,7),
  CHELTUIELI NUMBER(20,7),
  SUMA NUMBER(20,7),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DPROFITV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF3C38C844AB4186C41A1D08DAF7C7006712781A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DPROFITV (
  CODDPROFITV NUMBER(20,0),
  CODDPROFIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  RULAJ NUMBER(20,7),
  VENITURI NUMBER(20,7),
  SUMA NUMBER(20,7),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DVI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A0AB418A758F2CE2C5C0ACC612246D8D4C58F8AB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DVI (
  CODDVI NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODVAMA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CONTCHELT NUMBER(20,0),
  CONTTVA NUMBER(20,0),
  TAXEINCLUSE NUMBER(1,0),
  FISAVAMA NUMBER(1,0),
  TAXEPECHELT NUMBER(1,0),
  TIPREPSUPLIM NUMBER(1,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPIMPORT NUMBER(1,0),
  VALDOCVAMA NUMBER(20,7),
  TVADOCVAMA NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  SERIADOC VARCHAR2(20),
  SCADENTAC NUMBER(5,0),
  VALTOTALA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_DVI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F463F1B5D20847EF8D983408CEFB14CCF1997760</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_DVI1 (
  CODDVI1 NUMBER(20,0),
  CODDVI NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  INDEXLOCAL NUMBER(7,0),
  PRETIMPORT NUMBER(20,7),
  PRETVALUTA NUMBER(20,7),
  PRETORIGINAL NUMBER(20,7),
  TVA NUMBER(20,7),
  UMSEC NUMBER(10,0),
  ADDIM NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARETAXA NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  TVANEDED NUMBER(1,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  INFOSUPLIM VARCHAR2(30),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  SIMBOLCONTSERV VARCHAR2(100),
  CODTVA NUMBER(20,0),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  CODOBLIGSTORNO NUMBER(20,0),
  PROCADAOS NUMBER(20,7),
  TG DATE,
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  CODACCIZEDVI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EDINET1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2085E46D567430569CA3A65F7C871C219FD6FE15</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EDINET1 (
  CODIES1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CANT NUMBER(20,7),
  VAL NUMBER(20,7),
  TVA NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  NRLINII NUMBER(20,0),
  TAXCATEGORYCODED VARCHAR2(10),
  CODLIVR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTCLI NUMBER(20,0),
  TAXA NUMBER(1,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EDINET_D</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CCB3854CAC7787B6068A5E567BBDEB435E124B52</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EDINET_D (
  D01 NUMBER,
  D02 VARCHAR2(100),
  D03 VARCHAR2(100),
  D04 VARCHAR2(80),
  D05 VARCHAR2(80),
  D06 CHAR(2),
  D07 CHAR(1),
  D08 VARCHAR2(100),
  D09 VARCHAR2(20),
  D10 VARCHAR2(10),
  D11 VARCHAR2(40),
  D12 VARCHAR2(20),
  DE1 VARCHAR2(10),
  DE2 VARCHAR2(40),
  DE3 VARCHAR2(20),
  D13 VARCHAR2(20),
  D14 VARCHAR2(20),
  D15 VARCHAR2(20),
  D16 VARCHAR2(40),
  D17 VARCHAR2(40),
  D18 VARCHAR2(40),
  D19 VARCHAR2(20),
  D20 VARCHAR2(20),
  D21 VARCHAR2(35),
  D22 VARCHAR2(100),
  D23 VARCHAR2(25),
  D24 VARCHAR2(25),
  D25 VARCHAR2(100),
  D26 VARCHAR2(100),
  D27 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EDINET_H</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>96E011237D6F60A7CCEEEECF9130AE43EBF8335A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EDINET_H (
  FILENAME VARCHAR2(255),
  H01 VARCHAR2(255),
  H02 VARCHAR2(10),
  H03 VARCHAR2(10),
  H04 VARCHAR2(10),
  H05 NUMBER,
  H06 VARCHAR2(1),
  H07 VARCHAR2(2),
  H08 VARCHAR2(20),
  H09 VARCHAR2(3),
  H10 VARCHAR2(1),
  H11 VARCHAR2(1),
  H12 VARCHAR2(500),
  H13 VARCHAR2(255),
  H14 VARCHAR2(10),
  H15 VARCHAR2(20),
  O01 VARCHAR2(255),
  O02 VARCHAR2(25),
  L01 VARCHAR2(25),
  L02 VARCHAR2(20),
  L03 VARCHAR2(10),
  R01 VARCHAR2(255),
  R02 VARCHAR2(10),
  C01 VARCHAR2(20),
  C02 VARCHAR2(75),
  C03 VARCHAR2(100),
  C04 VARCHAR2(100),
  C05 NUMBER(5,0),
  C06 VARCHAR2(10),
  C07 VARCHAR2(50),
  C08 VARCHAR2(3),
  F01 VARCHAR2(20),
  F02 VARCHAR2(100),
  F03 VARCHAR2(100),
  F04 NUMBER(5,0),
  F05 VARCHAR2(10),
  F06 VARCHAR2(50),
  F07 VARCHAR2(3),
  D01 VARCHAR2(20),
  D02 VARCHAR2(100),
  D03 VARCHAR2(100),
  D04 NUMBER(5,0),
  D05 VARCHAR2(10),
  D06 VARCHAR2(50),
  D07 VARCHAR2(3),
  V01 VARCHAR2(20),
  V02 VARCHAR2(100),
  V03 VARCHAR2(20),
  V04 VARCHAR2(20),
  V05 VARCHAR2(30),
  V06 VARCHAR2(200),
  V07 VARCHAR2(50),
  V08 VARCHAR2(200),
  V09 VARCHAR2(100),
  V10 VARCHAR2(5),
  V11 VARCHAR2(10),
  V12 VARCHAR2(50),
  V13 VARCHAR2(3),
  V14 VARCHAR2(100),
  V15 NUMBER(20,7),
  VC1 VARCHAR2(100),
  VC2 VARCHAR2(100),
  E01 VARCHAR2(20),
  E02 VARCHAR2(200),
  E03 VARCHAR2(100),
  E04 NUMBER(5,0),
  E05 VARCHAR2(10),
  E06 VARCHAR2(50),
  E07 VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EDINET_S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EE36E865A1D91322D06205A5B0F07587C0AF5486</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EDINET_S (
  S01 VARCHAR2(20),
  S02 VARCHAR2(20),
  S03 VARCHAR2(20),
  S04 VARCHAR2(20),
  S05 VARCHAR2(20),
  S06 VARCHAR2(20),
  S07 VARCHAR2(20),
  S08 VARCHAR2(20),
  S09 VARCHAR2(20),
  S10 VARCHAR2(20),
  S11 VARCHAR2(20),
  S12 VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EDI_IES1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9CF23F7115BD3B12EF3E94CB2119E05AFE129BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EDI_IES1 (
  CODIES1 NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTCLI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EFACTURA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3FA24D1631F2AE50BBA81F3CE94F47C788ACDFC9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EFACTURA (
  CODIES NUMBER(20,0),
  IDINCARCARE VARCHAR2(20),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  STARE VARCHAR2(20),
  TIPMEDIU NUMBER(1,0),
  MESAJE CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EFACT_CUSTOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84A8A8C7C52E1F8F148BB94E081338723B366253</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EFACT_CUSTOM (
  CODEFACTC NUMBER(20,0),
  DEN_EFCUSTOM VARCHAR2(200),
  SQLCAMPURI CLOB,
  SQLCAMPURI1 CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EFCUSTOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>004BF09E9D4170D9FDF2A95CE0A4E5AEAF3D3F2A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EFCUSTOM (
  CODEFCUSTOM NUMBER(20,0),
  DEN_EFCUSTOM VARCHAR2(30),
  SQLCAMPURI CLOB,
  SQLCAMPURI1 CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMBUGET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA46498FFCE4046B0FED0FC21BE7423ECCAC8BB7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMBUGET (
  CODELEMBUGET NUMBER(20,0) NOT NULL,
  ELEMENT VARCHAR2(250),
  SIMBOL VARCHAR2(30),
  TIP NUMBER(5,0),
  FUNCTIE NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMBUGET1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>525CAC926056E8A01F86BB01BF42A91B7A898AED</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMBUGET1 (
  CODELEMBUGET1 NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMBUGET2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2122E56BA0AF41BB235FB72705D66C7122ABFC25</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMBUGET2 (
  CODELEMBUGET2 NUMBER(20,0),
  CODELEMBUGET NUMBER(20,0),
  AN NUMBER(4,0),
  S1 NUMBER(20,7),
  S2 NUMBER(20,7),
  S3 NUMBER(20,7),
  S4 NUMBER(20,7),
  S5 NUMBER(20,7),
  S6 NUMBER(20,7),
  S7 NUMBER(20,7),
  S8 NUMBER(20,7),
  S9 NUMBER(20,7),
  S10 NUMBER(20,7),
  S11 NUMBER(20,7),
  S12 NUMBER(20,7),
  S13 NUMBER(20,7),
  S14 NUMBER(20,7),
  S15 NUMBER(20,7),
  S16 NUMBER(20,7),
  S17 NUMBER(20,7),
  S18 NUMBER(20,7),
  S19 NUMBER(20,7),
  S20 NUMBER(20,7),
  S21 NUMBER(20,7),
  S22 NUMBER(20,7),
  S23 NUMBER(20,7),
  S24 NUMBER(20,7),
  S25 NUMBER(20,7),
  S26 NUMBER(20,7),
  S27 NUMBER(20,7),
  S28 NUMBER(20,7),
  S29 NUMBER(20,7),
  S30 NUMBER(20,7),
  S31 NUMBER(20,7),
  S32 NUMBER(20,7),
  S33 NUMBER(20,7),
  S34 NUMBER(20,7),
  S35 NUMBER(20,7),
  S36 NUMBER(20,7),
  S37 NUMBER(20,7),
  S38 NUMBER(20,7),
  S39 NUMBER(20,7),
  S40 NUMBER(20,7),
  S41 NUMBER(20,7),
  S42 NUMBER(20,7),
  S43 NUMBER(20,7),
  S44 NUMBER(20,7),
  S45 NUMBER(20,7),
  S46 NUMBER(20,7),
  S47 NUMBER(20,7),
  S48 NUMBER(20,7),
  S49 NUMBER(20,7),
  S50 NUMBER(20,7),
  S51 NUMBER(20,7),
  S52 NUMBER(20,7),
  S53 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMENTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34BE524E10D7D68CE0F8E287F45356C40127A963</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMENTE (
  CODELEMENT NUMBER(20,0),
  DEN_ELEMENT VARCHAR2(100),
  TIP NUMBER(2,0),
  CODDESCRIPTORBAZA NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  CV NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMENTEA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7580A319CA5E5CF5BAF976426FEAD4C40B7F7C49</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMENTEA (
  CODELEMENTA NUMBER(20,0),
  CODELEMENT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  NODMAXIMANALIZA1 NUMBER(20,0),
  CODDESCRIPTOR NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMENTEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>817F58239D0E1C2D762CA16A156368E20A5CB21E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMENTEC (
  CODELEMENTC NUMBER(20,0),
  CODELEMENTM NUMBER(20,0),
  MASCA VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ELEMENTEM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4CC9588D410BC1345927E03F62142AA8E45CE80</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ELEMENTEM (
  CODELEMENTM NUMBER(20,0),
  CODELEMENT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DENTIPMAKETA VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6440600793C39F00F0716C7422AC12551FC3A964</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE (
  CODEMULARE NUMBER(20,0),
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  TIPCASAMARCAT NUMBER(5,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  INCASARECLIENT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODRESTNP NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTSIMPLIF NUMBER(1,0),
  IDBON NUMBER,
  FACTURARE NUMBER(1,0),
  DELEGAT NUMBER(20,0),
  EXCLUSDISCOUNT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  CODSEDIURETAIL NUMBER(20,0),
  PUNCTECUMUL NUMBER(20,0),
  VALPUNCTECUMUL NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  VALVALUTA NUMBER(20,7),
  INFOFACTURA VARCHAR2(30),
  INFOCLIENT VARCHAR2(200),
  TOTALPUNCTEUSED NUMBER(20,0),
  TOTALVALPUNCTE NUMBER(22,2),
  SUMAINCASATA NUMBER(20,7),
  CODCATPRETPART NUMBER(20,0),
  TIPCATPRETPART NUMBER(20,0),
  INFODELEGAT VARCHAR2(150),
  FACTANULAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C901E8A9E914768A95C8CF4EA37B34174AC14DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE1 (
  CODEMULARE1 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0),
  DISCMANUAL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  PRETNEPROMO NUMBER(20,7),
  PROMOTIONAT NUMBER(1,0),
  FORCEPROMO NUMBER(1,0),
  INFOPROMO VARCHAR2(100),
  INFOPROMODISC VARCHAR2(100),
  CODPROMO1 NUMBER(20,0),
  PROCTVABON NUMBER(20,7),
  TAXA NUMBER(1,0),
  CODEMUL1AVANS NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  PARITATE NUMBER(20,7),
  VALOAREAFISATA NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  NRDOCLINK VARCHAR2(40),
  PROMOTIE NUMBER(1,0),
  CODCLASA NUMBER(20,0),
  VOUCHERCADOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE1RETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>95276EBCFA0024ABD911AFA8FA24D10F8F4E8FE6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE1RETAIL (
  CODEMULARE1 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0),
  DISCMANUAL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  PRETNEPROMO NUMBER(20,7),
  PROMOTIONAT NUMBER(1,0),
  FORCEPROMO NUMBER(1,0),
  INFOPROMO VARCHAR2(100),
  INFOPROMODISC VARCHAR2(100),
  CODPROMO1 NUMBER(20,0),
  PROCTVABON NUMBER(20,7),
  TAXA NUMBER(1,0),
  CODEMUL1AVANS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE1_BACKUP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E4D9076F2CDE5F321DB138FAC040C1C91B0D3BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE1_BACKUP (
  CODEMULARE1 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0),
  DISCMANUAL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  PRETNEPROMO NUMBER(20,7),
  PROMOTIONAT NUMBER(1,0),
  FORCEPROMO NUMBER(1,0),
  INFOPROMO VARCHAR2(100),
  INFOPROMODISC VARCHAR2(100),
  CODPROMO1 NUMBER(20,0),
  PROCTVABON NUMBER(20,7),
  TAXA NUMBER(1,0),
  CODEMUL1AVANS NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  PARITATE NUMBER(20,7),
  VALOAREAFISATA NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  NRDOCLINK VARCHAR2(40),
  PROMOTIE NUMBER(1,0),
  CODCLASA NUMBER(20,0),
  VOUCHERCADOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3FA39C4D47C049EB7DDAA0B44710FC46D56DB0F0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE2 (
  CODEMULARE2 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODBANKCONT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODCARD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARE2RETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E8CC9DCFFE2F3861E4A97A6D6A40F2B9F31E7ABC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARE2RETAIL (
  CODEMULARE2 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODBANKCONT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODCARD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULARERETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7FB85B158A543CAB02B82DF728BCADC7B742DF81</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULARERETAIL (
  CODEMULARE NUMBER(20,0) NOT NULL,
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  TIPCASAMARCAT NUMBER(5,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  INCASARECLIENT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODRESTNP NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTSIMPLIF NUMBER(1,0),
  IDBON NUMBER,
  FACTURARE NUMBER(1,0),
  DELEGAT NUMBER(20,0),
  EXCLUSDISCOUNT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  CODSEDIURETAIL NUMBER(20,0),
  PUNCTECUMUL NUMBER(20,0),
  VALPUNCTECUMUL NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  VALVALUTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULPUNCTEUSED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9AE46CD45A112672559266AC8C41C365301210CB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULPUNCTEUSED (
  COD NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  PUNCTEUSED NUMBER(20,7),
  VALACORDATA NUMBER(20,7),
  INFOPUNCTAJ VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULSTINGERI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5036A66E5ADE68AA309E2A87B16B260B7B20EA83</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULSTINGERI (
  CODEMULSTINGERE NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,7),
  VALOARE NUMBER(20,7),
  INFO VARCHAR2(30),
  TIPDOCSTINS NUMBER(4,0),
  SEMNIFDOCSTINS NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMULSTINGERI_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87EB4ED5457DCAE36654629F4D1B7B08CB0EEAC5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMULSTINGERI_INITIAL (
  CODEMULSTINGERE NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,7),
  VALOARE NUMBER(20,7),
  INFO VARCHAR2(30),
  TIPDOCSTINS NUMBER(4,0),
  SEMNIFDOCSTINS NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMUL_CODBARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F88CC8548357C780ED41AE86A2F2DE38E7423C8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMUL_CODBARE (
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRETNIRSTOC NUMBER(20,7),
  CODNIR NUMBER(20,0),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EMUL_CODBARE_AMB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>99A5D9124B664B211778F1B073A933BEC75A12BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EMUL_CODBARE_AMB (
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRETNIRSTOC NUMBER(20,7),
  CODNIR NUMBER(20,0),
  REST NUMBER(20,7),
  UMAMBALARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTEMIFIX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62661FBF328E1EC0F876A3FFD6B20627526BA36D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTEMIFIX (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTEOBINV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C46CB5BD15EAE957C7E5A4262FDD0CBC5F24262F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTEOBINV (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARINOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>878F87C40E18FA8FE0CE9A7A2DB6316D2EA2F47C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARINOD (
  CODESTIMARENOD NUMBER(20,0),
  CODESTIMAREPROD NUMBER(20,0),
  CODESTIMAREPROD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  SAPTAMANA NUMBER(2,0),
  AN NUMBER(4,0),
  DENUMIRE VARCHAR2(150),
  OBS VARCHAR2(250),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  PROIECTANT NUMBER(20,0),
  TOTALCOMINT NUMBER(20,7),
  TOTALCOMFURN NUMBER(20,7),
  TOTALREZERVAT NUMBER(20,7),
  TOTALREZOLVAT NUMBER(20,7),
  TOTALREALIZAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENUM VARCHAR2(15),
  UMSEC NUMBER(20,0),
  NECESARAUT NUMBER(20,7),
  RETETA VARCHAR2(250),
  RETETAPARINTE VARCHAR2(250),
  CODPRODCOMPPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3B51C91FE881F00D99552F3F9A6B8E31D8892569</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD (
  CODESTIMAREPROD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS VARCHAR2(400),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(2,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(10),
  ANIMPORT NUMBER(4,0),
  SAPTAMANAF NUMBER(2,0),
  ANF NUMBER(4,0),
  CODOFERTA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B95ABD5EA2CCB65FA8A13237E7776143B517025</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD1 (
  CODESTIMAREPROD1 NUMBER(20,0),
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  PRET NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  VAL_C1 NUMBER(20,7),
  VAL_C2 NUMBER(20,7),
  VAL_C3 NUMBER(20,7),
  VAL_C4 NUMBER(20,7),
  VAL_C5 NUMBER(20,7),
  VAL_C6 NUMBER(20,7),
  VAL_C7 NUMBER(20,7),
  VAL_C8 NUMBER(20,7),
  VAL_C9 NUMBER(20,7),
  VAL_C10 NUMBER(20,7),
  VAL_C11 NUMBER(20,7),
  VAL_C12 NUMBER(20,7),
  VAL_C13 NUMBER(20,7),
  VAL_C14 NUMBER(20,7),
  VAL_C15 NUMBER(20,7),
  VAL_C16 NUMBER(20,7),
  VAL_C17 NUMBER(20,7),
  VAL_C18 NUMBER(20,7),
  VAL_C19 NUMBER(20,7),
  VAL_C20 NUMBER(20,7),
  VAL_C21 NUMBER(20,7),
  VAL_C22 NUMBER(20,7),
  VAL_C23 NUMBER(20,7),
  VAL_C24 NUMBER(20,7),
  VAL_C25 NUMBER(20,7),
  VAL_C26 NUMBER(20,7),
  VAL_C27 NUMBER(20,7),
  VAL_C28 NUMBER(20,7),
  VAL_C29 NUMBER(20,7),
  VAL_C30 NUMBER(20,7),
  VAL_C31 NUMBER(20,7),
  VAL_C32 NUMBER(20,7),
  VAL_C33 NUMBER(20,7),
  VAL_C34 NUMBER(20,7),
  VAL_C35 NUMBER(20,7),
  VAL_C36 NUMBER(20,7),
  VAL_C37 NUMBER(20,7),
  VAL_C38 NUMBER(20,7),
  VAL_C39 NUMBER(20,7),
  VAL_C40 NUMBER(20,7),
  VAL_C41 NUMBER(20,7),
  VAL_C42 NUMBER(20,7),
  VAL_C43 NUMBER(20,7),
  VAL_C44 NUMBER(20,7),
  VAL_C45 NUMBER(20,7),
  VAL_C46 NUMBER(20,7),
  VAL_C47 NUMBER(20,7),
  VAL_C48 NUMBER(20,7),
  VAL_C49 NUMBER(20,7),
  VAL_C50 NUMBER(20,7),
  VAL_C51 NUMBER(20,7),
  VAL_C52 NUMBER(20,7),
  VAL_C53 NUMBER(20,7),
  VAL_N1 NUMBER(20,7),
  VAL_N2 NUMBER(20,7),
  VAL_N3 NUMBER(20,7),
  VAL_N4 NUMBER(20,7),
  VAL_N5 NUMBER(20,7),
  VAL_N6 NUMBER(20,7),
  VAL_N7 NUMBER(20,7),
  VAL_N8 NUMBER(20,7),
  VAL_N9 NUMBER(20,7),
  VAL_N10 NUMBER(20,7),
  VAL_N11 NUMBER(20,7),
  VAL_N12 NUMBER(20,7),
  VAL_N13 NUMBER(20,7),
  VAL_N14 NUMBER(20,7),
  VAL_N15 NUMBER(20,7),
  VAL_N16 NUMBER(20,7),
  VAL_N17 NUMBER(20,7),
  VAL_N18 NUMBER(20,7),
  VAL_N19 NUMBER(20,7),
  VAL_N20 NUMBER(20,7),
  VAL_N21 NUMBER(20,7),
  VAL_N22 NUMBER(20,7),
  VAL_N23 NUMBER(20,7),
  VAL_N24 NUMBER(20,7),
  VAL_N25 NUMBER(20,7),
  VAL_N26 NUMBER(20,7),
  VAL_N27 NUMBER(20,7),
  VAL_N28 NUMBER(20,7),
  VAL_N29 NUMBER(20,7),
  VAL_N30 NUMBER(20,7),
  VAL_N31 NUMBER(20,7),
  VAL_N32 NUMBER(20,7),
  VAL_N33 NUMBER(20,7),
  VAL_N34 NUMBER(20,7),
  VAL_N35 NUMBER(20,7),
  VAL_N36 NUMBER(20,7),
  VAL_N37 NUMBER(20,7),
  VAL_N38 NUMBER(20,7),
  VAL_N39 NUMBER(20,7),
  VAL_N40 NUMBER(20,7),
  VAL_N41 NUMBER(20,7),
  VAL_N42 NUMBER(20,7),
  VAL_N43 NUMBER(20,7),
  VAL_N44 NUMBER(20,7),
  VAL_N45 NUMBER(20,7),
  VAL_N46 NUMBER(20,7),
  VAL_N47 NUMBER(20,7),
  VAL_N48 NUMBER(20,7),
  VAL_N49 NUMBER(20,7),
  VAL_N50 NUMBER(20,7),
  VAL_N51 NUMBER(20,7),
  VAL_N52 NUMBER(20,7),
  VAL_N53 NUMBER(20,7),
  DEPASIRE NUMBER(20,7),
  VAL_T1 NUMBER(20,7),
  VAL_T2 NUMBER(20,7),
  VAL_T3 NUMBER(20,7),
  VAL_T4 NUMBER(20,7),
  VAL_T5 NUMBER(20,7),
  VAL_T6 NUMBER(20,7),
  VAL_T7 NUMBER(20,7),
  VAL_T8 NUMBER(20,7),
  VAL_T9 NUMBER(20,7),
  VAL_T10 NUMBER(20,7),
  VAL_T11 NUMBER(20,7),
  VAL_T12 NUMBER(20,7),
  VAL_T13 NUMBER(20,7),
  VAL_T14 NUMBER(20,7),
  VAL_T15 NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  DENUM VARCHAR2(15),
  DEN_CLASEAS VARCHAR2(50),
  NEC_C1 NUMBER(20,7),
  NEC_C2 NUMBER(20,7),
  NEC_C3 NUMBER(20,7),
  NEC_C4 NUMBER(20,7),
  NEC_C5 NUMBER(20,7),
  NEC_C6 NUMBER(20,7),
  NEC_C7 NUMBER(20,7),
  NEC_C8 NUMBER(20,7),
  NEC_C9 NUMBER(20,7),
  NEC_C10 NUMBER(20,7),
  NEC_C11 NUMBER(20,7),
  NEC_C12 NUMBER(20,7),
  NEC_C13 NUMBER(20,7),
  NEC_C14 NUMBER(20,7),
  NEC_C15 NUMBER(20,7),
  NEC_C16 NUMBER(20,7),
  NEC_C17 NUMBER(20,7),
  NEC_C18 NUMBER(20,7),
  NEC_C19 NUMBER(20,7),
  NEC_C20 NUMBER(20,7),
  NEC_C21 NUMBER(20,7),
  NEC_C22 NUMBER(20,7),
  NEC_C23 NUMBER(20,7),
  NEC_C24 NUMBER(20,7),
  NEC_C25 NUMBER(20,7),
  NEC_C26 NUMBER(20,7),
  NEC_C27 NUMBER(20,7),
  NEC_C28 NUMBER(20,7),
  NEC_C29 NUMBER(20,7),
  NEC_C30 NUMBER(20,7),
  NEC_C31 NUMBER(20,7),
  NEC_C32 NUMBER(20,7),
  NEC_C33 NUMBER(20,7),
  NEC_C34 NUMBER(20,7),
  NEC_C35 NUMBER(20,7),
  NEC_C36 NUMBER(20,7),
  NEC_C37 NUMBER(20,7),
  NEC_C38 NUMBER(20,7),
  NEC_C39 NUMBER(20,7),
  NEC_C40 NUMBER(20,7),
  NEC_C41 NUMBER(20,7),
  NEC_C42 NUMBER(20,7),
  NEC_C43 NUMBER(20,7),
  NEC_C44 NUMBER(20,7),
  NEC_C45 NUMBER(20,7),
  NEC_C46 NUMBER(20,7),
  NEC_C47 NUMBER(20,7),
  NEC_C48 NUMBER(20,7),
  NEC_C49 NUMBER(20,7),
  NEC_C50 NUMBER(20,7),
  NEC_C51 NUMBER(20,7),
  NEC_C52 NUMBER(20,7),
  NEC_N1 NUMBER(20,7),
  NEC_N2 NUMBER(20,7),
  NEC_N3 NUMBER(20,7),
  NEC_N4 NUMBER(20,7),
  NEC_N5 NUMBER(20,7),
  NEC_N6 NUMBER(20,7),
  NEC_N7 NUMBER(20,7),
  NEC_N8 NUMBER(20,7),
  NEC_N9 NUMBER(20,7),
  NEC_N10 NUMBER(20,7),
  NEC_N11 NUMBER(20,7),
  NEC_N12 NUMBER(20,7),
  NEC_N13 NUMBER(20,7),
  NEC_N14 NUMBER(20,7),
  NEC_N15 NUMBER(20,7),
  NEC_N16 NUMBER(20,7),
  NEC_N17 NUMBER(20,7),
  NEC_N18 NUMBER(20,7),
  NEC_N19 NUMBER(20,7),
  NEC_N20 NUMBER(20,7),
  NEC_N21 NUMBER(20,7),
  NEC_N22 NUMBER(20,7),
  NEC_N23 NUMBER(20,7),
  NEC_N24 NUMBER(20,7),
  NEC_N25 NUMBER(20,7),
  NEC_N26 NUMBER(20,7),
  NEC_N27 NUMBER(20,7),
  NEC_N28 NUMBER(20,7),
  NEC_N29 NUMBER(20,7),
  NEC_N30 NUMBER(20,7),
  NEC_N31 NUMBER(20,7),
  NEC_N32 NUMBER(20,7),
  NEC_N33 NUMBER(20,7),
  NEC_N34 NUMBER(20,7),
  NEC_N35 NUMBER(20,7),
  NEC_N36 NUMBER(20,7),
  NEC_N37 NUMBER(20,7),
  NEC_N38 NUMBER(20,7),
  NEC_N39 NUMBER(20,7),
  NEC_N40 NUMBER(20,7),
  NEC_N41 NUMBER(20,7),
  NEC_N42 NUMBER(20,7),
  NEC_N43 NUMBER(20,7),
  NEC_N44 NUMBER(20,7),
  NEC_N45 NUMBER(20,7),
  NEC_N46 NUMBER(20,7),
  NEC_N47 NUMBER(20,7),
  NEC_N48 NUMBER(20,7),
  NEC_N49 NUMBER(20,7),
  NEC_N50 NUMBER(20,7),
  NEC_N51 NUMBER(20,7),
  NEC_N52 NUMBER(20,7),
  NEC_C53 NUMBER(20,7),
  NEC_N53 NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  COEFUM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD1M</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6401B97508B22ADA97D047B8D2CACA15AE32DE24</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD1M (
  CODESTIMAREPROD1M NUMBER(20,0),
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  NEC_C1 NUMBER(20,7),
  NEC_C2 NUMBER(20,7),
  NEC_C3 NUMBER(20,7),
  NEC_C4 NUMBER(20,7),
  NEC_C5 NUMBER(20,7),
  NEC_C6 NUMBER(20,7),
  NEC_C7 NUMBER(20,7),
  NEC_C8 NUMBER(20,7),
  NEC_C9 NUMBER(20,7),
  NEC_C10 NUMBER(20,7),
  NEC_C11 NUMBER(20,7),
  NEC_C12 NUMBER(20,7),
  NEC_C13 NUMBER(20,7),
  NEC_C14 NUMBER(20,7),
  NEC_C15 NUMBER(20,7),
  NEC_C16 NUMBER(20,7),
  NEC_C17 NUMBER(20,7),
  NEC_C18 NUMBER(20,7),
  NEC_C19 NUMBER(20,7),
  NEC_C20 NUMBER(20,7),
  NEC_C21 NUMBER(20,7),
  NEC_C22 NUMBER(20,7),
  NEC_C23 NUMBER(20,7),
  NEC_C24 NUMBER(20,7),
  NEC_C25 NUMBER(20,7),
  NEC_C26 NUMBER(20,7),
  NEC_C27 NUMBER(20,7),
  NEC_C28 NUMBER(20,7),
  NEC_C29 NUMBER(20,7),
  NEC_C30 NUMBER(20,7),
  NEC_C31 NUMBER(20,7),
  NEC_C32 NUMBER(20,7),
  NEC_C33 NUMBER(20,7),
  NEC_C34 NUMBER(20,7),
  NEC_C35 NUMBER(20,7),
  NEC_C36 NUMBER(20,7),
  NEC_C37 NUMBER(20,7),
  NEC_C38 NUMBER(20,7),
  NEC_C39 NUMBER(20,7),
  NEC_C40 NUMBER(20,7),
  NEC_C41 NUMBER(20,7),
  NEC_C42 NUMBER(20,7),
  NEC_C43 NUMBER(20,7),
  NEC_C44 NUMBER(20,7),
  NEC_C45 NUMBER(20,7),
  NEC_C46 NUMBER(20,7),
  NEC_C47 NUMBER(20,7),
  NEC_C48 NUMBER(20,7),
  NEC_C49 NUMBER(20,7),
  NEC_C50 NUMBER(20,7),
  NEC_C51 NUMBER(20,7),
  NEC_C52 NUMBER(20,7),
  NEC_N1 NUMBER(20,7),
  NEC_N2 NUMBER(20,7),
  NEC_N3 NUMBER(20,7),
  NEC_N4 NUMBER(20,7),
  NEC_N5 NUMBER(20,7),
  NEC_N6 NUMBER(20,7),
  NEC_N7 NUMBER(20,7),
  NEC_N8 NUMBER(20,7),
  NEC_N9 NUMBER(20,7),
  NEC_N10 NUMBER(20,7),
  NEC_N11 NUMBER(20,7),
  NEC_N12 NUMBER(20,7),
  NEC_N13 NUMBER(20,7),
  NEC_N14 NUMBER(20,7),
  NEC_N15 NUMBER(20,7),
  NEC_N16 NUMBER(20,7),
  NEC_N17 NUMBER(20,7),
  NEC_N18 NUMBER(20,7),
  NEC_N19 NUMBER(20,7),
  NEC_N20 NUMBER(20,7),
  NEC_N21 NUMBER(20,7),
  NEC_N22 NUMBER(20,7),
  NEC_N23 NUMBER(20,7),
  NEC_N24 NUMBER(20,7),
  NEC_N25 NUMBER(20,7),
  NEC_N26 NUMBER(20,7),
  NEC_N27 NUMBER(20,7),
  NEC_N28 NUMBER(20,7),
  NEC_N29 NUMBER(20,7),
  NEC_N30 NUMBER(20,7),
  NEC_N31 NUMBER(20,7),
  NEC_N32 NUMBER(20,7),
  NEC_N33 NUMBER(20,7),
  NEC_N34 NUMBER(20,7),
  NEC_N35 NUMBER(20,7),
  NEC_N36 NUMBER(20,7),
  NEC_N37 NUMBER(20,7),
  NEC_N38 NUMBER(20,7),
  NEC_N39 NUMBER(20,7),
  NEC_N40 NUMBER(20,7),
  NEC_N41 NUMBER(20,7),
  NEC_N42 NUMBER(20,7),
  NEC_N43 NUMBER(20,7),
  NEC_N44 NUMBER(20,7),
  NEC_N45 NUMBER(20,7),
  NEC_N46 NUMBER(20,7),
  NEC_N47 NUMBER(20,7),
  NEC_N48 NUMBER(20,7),
  NEC_N49 NUMBER(20,7),
  NEC_N50 NUMBER(20,7),
  NEC_N51 NUMBER(20,7),
  NEC_N52 NUMBER(20,7),
  NEC_C53 NUMBER(20,7),
  NEC_N53 NUMBER(20,7),
  CF_C1 NUMBER(20,7),
  CF_C2 NUMBER(20,7),
  CF_C3 NUMBER(20,7),
  CF_C4 NUMBER(20,7),
  CF_C5 NUMBER(20,7),
  CF_C6 NUMBER(20,7),
  CF_C7 NUMBER(20,7),
  CF_C8 NUMBER(20,7),
  CF_C9 NUMBER(20,7),
  CF_C10 NUMBER(20,7),
  CF_C11 NUMBER(20,7),
  CF_C12 NUMBER(20,7),
  CF_C13 NUMBER(20,7),
  CF_C14 NUMBER(20,7),
  CF_C15 NUMBER(20,7),
  CF_C16 NUMBER(20,7),
  CF_C17 NUMBER(20,7),
  CF_C18 NUMBER(20,7),
  CF_C19 NUMBER(20,7),
  CF_C20 NUMBER(20,7),
  CF_C21 NUMBER(20,7),
  CF_C22 NUMBER(20,7),
  CF_C23 NUMBER(20,7),
  CF_C24 NUMBER(20,7),
  CF_C25 NUMBER(20,7),
  CF_C26 NUMBER(20,7),
  CF_C27 NUMBER(20,7),
  CF_C28 NUMBER(20,7),
  CF_C29 NUMBER(20,7),
  CF_C30 NUMBER(20,7),
  CF_C31 NUMBER(20,7),
  CF_C32 NUMBER(20,7),
  CF_C33 NUMBER(20,7),
  CF_C34 NUMBER(20,7),
  CF_C35 NUMBER(20,7),
  CF_C36 NUMBER(20,7),
  CF_C37 NUMBER(20,7),
  CF_C38 NUMBER(20,7),
  CF_C39 NUMBER(20,7),
  CF_C40 NUMBER(20,7),
  CF_C41 NUMBER(20,7),
  CF_C42 NUMBER(20,7),
  CF_C43 NUMBER(20,7),
  CF_C44 NUMBER(20,7),
  CF_C45 NUMBER(20,7),
  CF_C46 NUMBER(20,7),
  CF_C47 NUMBER(20,7),
  CF_C48 NUMBER(20,7),
  CF_C49 NUMBER(20,7),
  CF_C50 NUMBER(20,7),
  CF_C51 NUMBER(20,7),
  CF_C52 NUMBER(20,7),
  CF_C53 NUMBER(20,7),
  CF_N1 NUMBER(20,7),
  CF_N2 NUMBER(20,7),
  CF_N3 NUMBER(20,7),
  CF_N4 NUMBER(20,7),
  CF_N5 NUMBER(20,7),
  CF_N6 NUMBER(20,7),
  CF_N7 NUMBER(20,7),
  CF_N8 NUMBER(20,7),
  CF_N9 NUMBER(20,7),
  CF_N10 NUMBER(20,7),
  CF_N11 NUMBER(20,7),
  CF_N12 NUMBER(20,7),
  CF_N13 NUMBER(20,7),
  CF_N14 NUMBER(20,7),
  CF_N15 NUMBER(20,7),
  CF_N16 NUMBER(20,7),
  CF_N17 NUMBER(20,7),
  CF_N18 NUMBER(20,7),
  CF_N19 NUMBER(20,7),
  CF_N20 NUMBER(20,7),
  CF_N21 NUMBER(20,7),
  CF_N22 NUMBER(20,7),
  CF_N23 NUMBER(20,7),
  CF_N24 NUMBER(20,7),
  CF_N25 NUMBER(20,7),
  CF_N26 NUMBER(20,7),
  CF_N27 NUMBER(20,7),
  CF_N28 NUMBER(20,7),
  CF_N29 NUMBER(20,7),
  CF_N30 NUMBER(20,7),
  CF_N31 NUMBER(20,7),
  CF_N32 NUMBER(20,7),
  CF_N33 NUMBER(20,7),
  CF_N34 NUMBER(20,7),
  CF_N35 NUMBER(20,7),
  CF_N36 NUMBER(20,7),
  CF_N37 NUMBER(20,7),
  CF_N38 NUMBER(20,7),
  CF_N39 NUMBER(20,7),
  CF_N40 NUMBER(20,7),
  CF_N41 NUMBER(20,7),
  CF_N42 NUMBER(20,7),
  CF_N43 NUMBER(20,7),
  CF_N44 NUMBER(20,7),
  CF_N45 NUMBER(20,7),
  CF_N46 NUMBER(20,7),
  CF_N47 NUMBER(20,7),
  CF_N48 NUMBER(20,7),
  CF_N49 NUMBER(20,7),
  CF_N50 NUMBER(20,7),
  CF_N51 NUMBER(20,7),
  CF_N52 NUMBER(20,7),
  CF_N53 NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  COEFUM NUMBER(20,7),
  PRET NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  VAL_C1 NUMBER(20,7),
  VAL_C2 NUMBER(20,7),
  VAL_C3 NUMBER(20,7),
  VAL_C4 NUMBER(20,7),
  VAL_C5 NUMBER(20,7),
  VAL_C6 NUMBER(20,7),
  VAL_C7 NUMBER(20,7),
  VAL_C8 NUMBER(20,7),
  VAL_C9 NUMBER(20,7),
  VAL_C10 NUMBER(20,7),
  VAL_C11 NUMBER(20,7),
  VAL_C12 NUMBER(20,7),
  VAL_C13 NUMBER(20,7),
  VAL_C14 NUMBER(20,7),
  VAL_C15 NUMBER(20,7),
  VAL_C16 NUMBER(20,7),
  VAL_C17 NUMBER(20,7),
  VAL_C18 NUMBER(20,7),
  VAL_C19 NUMBER(20,7),
  VAL_C20 NUMBER(20,7),
  VAL_C21 NUMBER(20,7),
  VAL_C22 NUMBER(20,7),
  VAL_C23 NUMBER(20,7),
  VAL_C24 NUMBER(20,7),
  VAL_C25 NUMBER(20,7),
  VAL_C26 NUMBER(20,7),
  VAL_C27 NUMBER(20,7),
  VAL_C28 NUMBER(20,7),
  VAL_C29 NUMBER(20,7),
  VAL_C30 NUMBER(20,7),
  VAL_C31 NUMBER(20,7),
  VAL_C32 NUMBER(20,7),
  VAL_C33 NUMBER(20,7),
  VAL_C34 NUMBER(20,7),
  VAL_C35 NUMBER(20,7),
  VAL_C36 NUMBER(20,7),
  VAL_C37 NUMBER(20,7),
  VAL_C38 NUMBER(20,7),
  VAL_C39 NUMBER(20,7),
  VAL_C40 NUMBER(20,7),
  VAL_C41 NUMBER(20,7),
  VAL_C42 NUMBER(20,7),
  VAL_C43 NUMBER(20,7),
  VAL_C44 NUMBER(20,7),
  VAL_C45 NUMBER(20,7),
  VAL_C46 NUMBER(20,7),
  VAL_C47 NUMBER(20,7),
  VAL_C48 NUMBER(20,7),
  VAL_C49 NUMBER(20,7),
  VAL_C50 NUMBER(20,7),
  VAL_C51 NUMBER(20,7),
  VAL_C52 NUMBER(20,7),
  VAL_C53 NUMBER(20,7),
  VAL_N1 NUMBER(20,7),
  VAL_N2 NUMBER(20,7),
  VAL_N3 NUMBER(20,7),
  VAL_N4 NUMBER(20,7),
  VAL_N5 NUMBER(20,7),
  VAL_N6 NUMBER(20,7),
  VAL_N7 NUMBER(20,7),
  VAL_N8 NUMBER(20,7),
  VAL_N9 NUMBER(20,7),
  VAL_N10 NUMBER(20,7),
  VAL_N11 NUMBER(20,7),
  VAL_N12 NUMBER(20,7),
  VAL_N13 NUMBER(20,7),
  VAL_N14 NUMBER(20,7),
  VAL_N15 NUMBER(20,7),
  VAL_N16 NUMBER(20,7),
  VAL_N17 NUMBER(20,7),
  VAL_N18 NUMBER(20,7),
  VAL_N19 NUMBER(20,7),
  VAL_N20 NUMBER(20,7),
  VAL_N21 NUMBER(20,7),
  VAL_N22 NUMBER(20,7),
  VAL_N23 NUMBER(20,7),
  VAL_N24 NUMBER(20,7),
  VAL_N25 NUMBER(20,7),
  VAL_N26 NUMBER(20,7),
  VAL_N27 NUMBER(20,7),
  VAL_N28 NUMBER(20,7),
  VAL_N29 NUMBER(20,7),
  VAL_N30 NUMBER(20,7),
  VAL_N31 NUMBER(20,7),
  VAL_N32 NUMBER(20,7),
  VAL_N33 NUMBER(20,7),
  VAL_N34 NUMBER(20,7),
  VAL_N35 NUMBER(20,7),
  VAL_N36 NUMBER(20,7),
  VAL_N37 NUMBER(20,7),
  VAL_N38 NUMBER(20,7),
  VAL_N39 NUMBER(20,7),
  VAL_N40 NUMBER(20,7),
  VAL_N41 NUMBER(20,7),
  VAL_N42 NUMBER(20,7),
  VAL_N43 NUMBER(20,7),
  VAL_N44 NUMBER(20,7),
  VAL_N45 NUMBER(20,7),
  VAL_N46 NUMBER(20,7),
  VAL_N47 NUMBER(20,7),
  VAL_N48 NUMBER(20,7),
  VAL_N49 NUMBER(20,7),
  VAL_N50 NUMBER(20,7),
  VAL_N51 NUMBER(20,7),
  VAL_N52 NUMBER(20,7),
  VAL_N53 NUMBER(20,7),
  DEPASIRE NUMBER(20,7),
  VAL_T1 NUMBER(20,7),
  VAL_T2 NUMBER(20,7),
  VAL_T3 NUMBER(20,7),
  VAL_T4 NUMBER(20,7),
  VAL_T5 NUMBER(20,7),
  VAL_T6 NUMBER(20,7),
  VAL_T7 NUMBER(20,7),
  VAL_T8 NUMBER(20,7),
  VAL_T9 NUMBER(20,7),
  VAL_T10 NUMBER(20,7),
  VAL_T11 NUMBER(20,7),
  VAL_T12 NUMBER(20,7),
  VAL_T13 NUMBER(20,7),
  VAL_T14 NUMBER(20,7),
  VAL_T15 NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  DEN_UM VARCHAR2(15),
  SIMBOL VARCHAR2(100),
  DEN_PART VARCHAR2(100),
  CODEXTERN VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD1MVT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9D1A37C90F69755647EFF4287F65335EFF1F2CEA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD1MVT (
  CODESTIMAREPROD NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  TOTAL NUMBER(20,7),
  T1 NUMBER(20,7),
  T2 NUMBER(20,7),
  T3 NUMBER(20,7),
  T4 NUMBER(20,7),
  T5 NUMBER(20,7),
  T6 NUMBER(20,7),
  T7 NUMBER(20,7),
  T8 NUMBER(20,7),
  T9 NUMBER(20,7),
  T10 NUMBER(20,7),
  T11 NUMBER(20,7),
  T12 NUMBER(20,7),
  T13 NUMBER(20,7),
  T14 NUMBER(20,7),
  T15 NUMBER(20,7),
  DEPASIRE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD1N</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>781D17D2196072C627B253A774141DE32C0E72A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD1N (
  CODESTIMAREPROD1N NUMBER(20,0),
  CODESTIMAREPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NEC_C1 NUMBER(20,7),
  NEC_C2 NUMBER(20,7),
  NEC_C3 NUMBER(20,7),
  NEC_C4 NUMBER(20,7),
  NEC_C5 NUMBER(20,7),
  NEC_C6 NUMBER(20,7),
  NEC_C7 NUMBER(20,7),
  NEC_C8 NUMBER(20,7),
  NEC_C9 NUMBER(20,7),
  NEC_C10 NUMBER(20,7),
  NEC_C11 NUMBER(20,7),
  NEC_C12 NUMBER(20,7),
  NEC_C13 NUMBER(20,7),
  NEC_C14 NUMBER(20,7),
  NEC_C15 NUMBER(20,7),
  NEC_C16 NUMBER(20,7),
  NEC_C17 NUMBER(20,7),
  NEC_C18 NUMBER(20,7),
  NEC_C19 NUMBER(20,7),
  NEC_C20 NUMBER(20,7),
  NEC_C21 NUMBER(20,7),
  NEC_C22 NUMBER(20,7),
  NEC_C23 NUMBER(20,7),
  NEC_C24 NUMBER(20,7),
  NEC_C25 NUMBER(20,7),
  NEC_C26 NUMBER(20,7),
  NEC_C27 NUMBER(20,7),
  NEC_C28 NUMBER(20,7),
  NEC_C29 NUMBER(20,7),
  NEC_C30 NUMBER(20,7),
  NEC_C31 NUMBER(20,7),
  NEC_C32 NUMBER(20,7),
  NEC_C33 NUMBER(20,7),
  NEC_C34 NUMBER(20,7),
  NEC_C35 NUMBER(20,7),
  NEC_C36 NUMBER(20,7),
  NEC_C37 NUMBER(20,7),
  NEC_C38 NUMBER(20,7),
  NEC_C39 NUMBER(20,7),
  NEC_C40 NUMBER(20,7),
  NEC_C41 NUMBER(20,7),
  NEC_C42 NUMBER(20,7),
  NEC_C43 NUMBER(20,7),
  NEC_C44 NUMBER(20,7),
  NEC_C45 NUMBER(20,7),
  NEC_C46 NUMBER(20,7),
  NEC_C47 NUMBER(20,7),
  NEC_C48 NUMBER(20,7),
  NEC_C49 NUMBER(20,7),
  NEC_C50 NUMBER(20,7),
  NEC_C51 NUMBER(20,7),
  NEC_C52 NUMBER(20,7),
  NEC_N1 NUMBER(20,7),
  NEC_N2 NUMBER(20,7),
  NEC_N3 NUMBER(20,7),
  NEC_N4 NUMBER(20,7),
  NEC_N5 NUMBER(20,7),
  NEC_N6 NUMBER(20,7),
  NEC_N7 NUMBER(20,7),
  NEC_N8 NUMBER(20,7),
  NEC_N9 NUMBER(20,7),
  NEC_N10 NUMBER(20,7),
  NEC_N11 NUMBER(20,7),
  NEC_N12 NUMBER(20,7),
  NEC_N13 NUMBER(20,7),
  NEC_N14 NUMBER(20,7),
  NEC_N15 NUMBER(20,7),
  NEC_N16 NUMBER(20,7),
  NEC_N17 NUMBER(20,7),
  NEC_N18 NUMBER(20,7),
  NEC_N19 NUMBER(20,7),
  NEC_N20 NUMBER(20,7),
  NEC_N21 NUMBER(20,7),
  NEC_N22 NUMBER(20,7),
  NEC_N23 NUMBER(20,7),
  NEC_N24 NUMBER(20,7),
  NEC_N25 NUMBER(20,7),
  NEC_N26 NUMBER(20,7),
  NEC_N27 NUMBER(20,7),
  NEC_N28 NUMBER(20,7),
  NEC_N29 NUMBER(20,7),
  NEC_N30 NUMBER(20,7),
  NEC_N31 NUMBER(20,7),
  NEC_N32 NUMBER(20,7),
  NEC_N33 NUMBER(20,7),
  NEC_N34 NUMBER(20,7),
  NEC_N35 NUMBER(20,7),
  NEC_N36 NUMBER(20,7),
  NEC_N37 NUMBER(20,7),
  NEC_N38 NUMBER(20,7),
  NEC_N39 NUMBER(20,7),
  NEC_N40 NUMBER(20,7),
  NEC_N41 NUMBER(20,7),
  NEC_N42 NUMBER(20,7),
  NEC_N43 NUMBER(20,7),
  NEC_N44 NUMBER(20,7),
  NEC_N45 NUMBER(20,7),
  NEC_N46 NUMBER(20,7),
  NEC_N47 NUMBER(20,7),
  NEC_N48 NUMBER(20,7),
  NEC_N49 NUMBER(20,7),
  NEC_N50 NUMBER(20,7),
  NEC_N51 NUMBER(20,7),
  NEC_N52 NUMBER(20,7),
  NEC_C53 NUMBER(20,7),
  NEC_N53 NUMBER(20,7),
  STOC NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  COEFUM NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(100),
  DEN_UM VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ESTIMARIPROD1VT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EC0DFBDFFEB7DE81724C2D314825993FA2351AAE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ESTIMARIPROD1VT (
  CODESTIMAREPROD NUMBER(20,0),
  C1 NUMBER(20,7),
  C2 NUMBER(20,7),
  C3 NUMBER(20,7),
  C4 NUMBER(20,7),
  C5 NUMBER(20,7),
  C6 NUMBER(20,7),
  C7 NUMBER(20,7),
  C8 NUMBER(20,7),
  C9 NUMBER(20,7),
  C10 NUMBER(20,7),
  C11 NUMBER(20,7),
  C12 NUMBER(20,7),
  C13 NUMBER(20,7),
  C14 NUMBER(20,7),
  C15 NUMBER(20,7),
  C16 NUMBER(20,7),
  C17 NUMBER(20,7),
  C18 NUMBER(20,7),
  C19 NUMBER(20,7),
  C20 NUMBER(20,7),
  C21 NUMBER(20,7),
  C22 NUMBER(20,7),
  C23 NUMBER(20,7),
  C24 NUMBER(20,7),
  C25 NUMBER(20,7),
  C26 NUMBER(20,7),
  C27 NUMBER(20,7),
  C28 NUMBER(20,7),
  C29 NUMBER(20,7),
  C30 NUMBER(20,7),
  C31 NUMBER(20,7),
  C32 NUMBER(20,7),
  C33 NUMBER(20,7),
  C34 NUMBER(20,7),
  C35 NUMBER(20,7),
  C36 NUMBER(20,7),
  C37 NUMBER(20,7),
  C38 NUMBER(20,7),
  C39 NUMBER(20,7),
  C40 NUMBER(20,7),
  C41 NUMBER(20,7),
  C42 NUMBER(20,7),
  C43 NUMBER(20,7),
  C44 NUMBER(20,7),
  C45 NUMBER(20,7),
  C46 NUMBER(20,7),
  C47 NUMBER(20,7),
  C48 NUMBER(20,7),
  C49 NUMBER(20,7),
  C50 NUMBER(20,7),
  C51 NUMBER(20,7),
  C52 NUMBER(20,7),
  N1 NUMBER(20,7),
  N2 NUMBER(20,7),
  N3 NUMBER(20,7),
  N4 NUMBER(20,7),
  N5 NUMBER(20,7),
  N6 NUMBER(20,7),
  N7 NUMBER(20,7),
  N8 NUMBER(20,7),
  N9 NUMBER(20,7),
  N10 NUMBER(20,7),
  N11 NUMBER(20,7),
  N12 NUMBER(20,7),
  N13 NUMBER(20,7),
  N14 NUMBER(20,7),
  N15 NUMBER(20,7),
  N16 NUMBER(20,7),
  N17 NUMBER(20,7),
  N18 NUMBER(20,7),
  N19 NUMBER(20,7),
  N20 NUMBER(20,7),
  N21 NUMBER(20,7),
  N22 NUMBER(20,7),
  N23 NUMBER(20,7),
  N24 NUMBER(20,7),
  N25 NUMBER(20,7),
  N26 NUMBER(20,7),
  N27 NUMBER(20,7),
  N28 NUMBER(20,7),
  N29 NUMBER(20,7),
  N30 NUMBER(20,7),
  N31 NUMBER(20,7),
  N32 NUMBER(20,7),
  N33 NUMBER(20,7),
  N34 NUMBER(20,7),
  N35 NUMBER(20,7),
  N36 NUMBER(20,7),
  N37 NUMBER(20,7),
  N38 NUMBER(20,7),
  N39 NUMBER(20,7),
  N40 NUMBER(20,7),
  N41 NUMBER(20,7),
  N42 NUMBER(20,7),
  N43 NUMBER(20,7),
  N44 NUMBER(20,7),
  N45 NUMBER(20,7),
  N46 NUMBER(20,7),
  N47 NUMBER(20,7),
  N48 NUMBER(20,7),
  N49 NUMBER(20,7),
  N50 NUMBER(20,7),
  N51 NUMBER(20,7),
  N52 NUMBER(20,7),
  C53 NUMBER(20,7),
  N53 NUMBER(20,7),
  TOTAL NUMBER(20,7),
  T1 NUMBER(20,7),
  T2 NUMBER(20,7),
  T3 NUMBER(20,7),
  T4 NUMBER(20,7),
  T5 NUMBER(20,7),
  T6 NUMBER(20,7),
  T7 NUMBER(20,7),
  T8 NUMBER(20,7),
  T9 NUMBER(20,7),
  T10 NUMBER(20,7),
  T11 NUMBER(20,7),
  T12 NUMBER(20,7),
  T13 NUMBER(20,7),
  T14 NUMBER(20,7),
  T15 NUMBER(20,7),
  DEPASIRE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>965C5AF8FFE0BD72C697D2E14E39FEB8A99B1004</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA (
  CODETVA NUMBER(20,0) NOT NULL,
  CIF VARCHAR2(75),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  DATA_INCARCARE DATE,
  DENUMIRE VARCHAR2(200),
  ID VARCHAR2(50),
  CONSOLIDAT VARCHAR2(50),
  DATA_SPV DATE,
  ID_SPV VARCHAR2(50),
  DOMICILIU VARCHAR2(150),
  SUBUNITATEA NUMBER(20,0),
  RD1_1_VAL_ETRANS NUMBER(20,7),
  RD1_VAL NUMBER(20,7),
  RD1_VAL_390 NUMBER(20,7),
  RD10_TVA NUMBER(20,7),
  RD10_TVA_394 NUMBER(20,7),
  RD10_TVA_AMEF NUMBER(20,7),
  RD10_TVA_EFCT NUMBER(20,7),
  RD10_VAL NUMBER(20,7),
  RD10_VAL_394 NUMBER(20,7),
  RD10_VAL_AMEF NUMBER(20,7),
  RD10_VAL_EFCT NUMBER(20,7),
  RD101_TVA_REGAC NUMBER(20,7),
  RD101_VAL_REGAC NUMBER(20,7),
  RD11_TVA NUMBER(20,7),
  RD11_TVA_394 NUMBER(20,7),
  RD11_TVA_AMEF NUMBER(20,7),
  RD11_TVA_EFCT NUMBER(20,7),
  RD11_VAL NUMBER(20,7),
  RD11_VAL_394 NUMBER(20,7),
  RD11_VAL_AMEF NUMBER(20,7),
  RD11_VAL_EFCT NUMBER(20,7),
  RD111_TVA_REGAC NUMBER(20,7),
  RD111_VAL_REGAC NUMBER(20,7),
  RD12_TVA NUMBER(20,7),
  RD12_TVA_394 NUMBER(20,7),
  RD12_TVA_EFCT NUMBER(20,7),
  RD12_VAL NUMBER(20,7),
  RD12_VAL_394 NUMBER(20,7),
  RD12_VAL_EFCT NUMBER(20,7),
  RD121_TVA NUMBER(20,7),
  RD121_TVA_394 NUMBER(20,7),
  RD121_VAL NUMBER(20,7),
  RD121_VAL_394 NUMBER(20,7),
  RD122_TVA NUMBER(20,7),
  RD122_TVA_394 NUMBER(20,7),
  RD122_VAL NUMBER(20,7),
  RD122_VAL_394 NUMBER(20,7),
  RD123_TVA NUMBER(20,7),
  RD123_TVA_394 NUMBER(20,7),
  RD123_VAL NUMBER(20,7),
  RD123_VAL_394 NUMBER(20,7),
  RD13_VAL NUMBER(20,7),
  RD13_VAL_EFCT NUMBER(20,7),
  RD14_15_VAL NUMBER(20,7),
  RD14_15_VAL_AMEF NUMBER(20,7),
  RD14_15_VAL_EFCT NUMBER(20,7),
  RD14_15_VAL_VAMA NUMBER(20,7),
  RD2_VAL NUMBER(20,7),
  RD2_VAL_390 NUMBER(20,7),
  RD20_TVA NUMBER(20,7),
  RD20_VAL NUMBER(20,7),
  RD201_TVA NUMBER(20,7),
  RD201_VAL NUMBER(20,7),
  RD21_TVA NUMBER(20,7),
  RD21_VAL NUMBER(20,7),
  RD22_TVA NUMBER(20,7),
  RD22_VAL NUMBER(20,7),
  RD221_TVA NUMBER(20,7),
  RD221_VAL NUMBER(20,7),
  RD23_TVA NUMBER(20,7),
  RD23_VAL NUMBER(20,7),
  RD24_TVA NUMBER(20,7),
  RD24_TVA_394 NUMBER(20,7),
  RD24_TVA_EFCT_I NUMBER(20,7),
  RD24_TVA_EFCT_N NUMBER(20,7),
  RD24_TVA_EFCT_T NUMBER(20,7),
  RD24_TVA_VAMA NUMBER(20,7),
  RD24_VAL NUMBER(20,7),
  RD24_VAL_394 NUMBER(20,7),
  RD24_VAL_EFCT_I NUMBER(20,7),
  RD24_VAL_EFCT_N NUMBER(20,7),
  RD24_VAL_EFCT_T NUMBER(20,7),
  RD24_VAL_VAMA NUMBER(20,7),
  RD25_TVA NUMBER(20,7),
  RD25_TVA_394 NUMBER(20,7),
  RD25_TVA_EFCT_I NUMBER(20,7),
  RD25_TVA_EFCT_N NUMBER(20,7),
  RD25_TVA_EFCT_T NUMBER(20,7),
  RD25_TVA_VAMA NUMBER(20,7),
  RD25_VAL NUMBER(20,7),
  RD25_VAL_394 NUMBER(20,7),
  RD25_VAL_EFCT_I NUMBER(20,7),
  RD25_VAL_EFCT_N NUMBER(20,7),
  RD25_VAL_EFCT_T NUMBER(20,7),
  RD25_VAL_VAMA NUMBER(20,7),
  RD26_TVA NUMBER(20,7),
  RD26_TVA_394 NUMBER(20,7),
  RD26_TVA_EFCT_I NUMBER(20,7),
  RD26_TVA_EFCT_N NUMBER(20,7),
  RD26_TVA_EFCT_T NUMBER(20,7),
  RD26_TVA_VAMA NUMBER(20,7),
  RD26_VAL NUMBER(20,7),
  RD26_VAL_394 NUMBER(20,7),
  RD26_VAL_EFCT_I NUMBER(20,7),
  RD26_VAL_EFCT_N NUMBER(20,7),
  RD26_VAL_EFCT_T NUMBER(20,7),
  RD26_VAL_VAMA NUMBER(20,7),
  RD27_TVA NUMBER(20,7),
  RD27_VAL NUMBER(20,7),
  RD271_TVA NUMBER(20,7),
  RD271_VAL NUMBER(20,7),
  RD272_TVA NUMBER(20,7),
  RD272_VAL NUMBER(20,7),
  RD273_TVA NUMBER(20,7),
  RD273_VAL NUMBER(20,7),
  RD28_TVA NUMBER(20,7),
  RD28_TVA_EFCT NUMBER(20,7),
  RD3_VAL NUMBER(20,7),
  RD3_VAL_390 NUMBER(20,7),
  RD30_VAL NUMBER(20,7),
  RD30_VAL_EFCT NUMBER(20,7),
  RD30_VAL_VAMA NUMBER(20,7),
  RD31_VAL NUMBER(20,7),
  RD31_VAL_390 NUMBER(20,7),
  RD4_VAL NUMBER(20,7),
  RD4_VAL_390 NUMBER(20,7),
  RD5_TVA NUMBER(20,7),
  RD5_TVA_390 NUMBER(20,7),
  RD5_VAL NUMBER(20,7),
  RD5_VAL_390 NUMBER(20,7),
  RD51_TVA NUMBER(20,7),
  RD51_TVA_390 NUMBER(20,7),
  RD51_VAL NUMBER(20,7),
  RD51_VAL_390 NUMBER(20,7),
  RD52_TVA_ETRANS NUMBER(20,7),
  RD52_VAL_ETRANS NUMBER(20,7),
  RD6_TVA NUMBER(20,7),
  RD6_TVA_390 NUMBER(20,7),
  RD6_VAL NUMBER(20,7),
  RD6_VAL_390 NUMBER(20,7),
  RD7_TVA NUMBER(20,7),
  RD7_TVA_390 NUMBER(20,7),
  RD7_TVA_VAMA NUMBER(20,7),
  RD7_VAL NUMBER(20,7),
  RD7_VAL_390 NUMBER(20,7),
  RD7_VAL_VAMA NUMBER(20,7),
  RD71_TVA NUMBER(20,7),
  RD71_TVA_390 NUMBER(20,7),
  RD71_VAL NUMBER(20,7),
  RD71_VAL_390 NUMBER(20,7),
  RD8_TVA NUMBER(20,7),
  RD8_TVA_390 NUMBER(20,7),
  RD8_VAL NUMBER(20,7),
  RD8_VAL_390 NUMBER(20,7),
  RD9_TVA NUMBER(20,7),
  RD9_TVA_394 NUMBER(20,7),
  RD9_TVA_AMEF NUMBER(20,7),
  RD9_TVA_EFCT NUMBER(20,7),
  RD9_VAL NUMBER(20,7),
  RD9_VAL_394 NUMBER(20,7),
  RD9_VAL_AMEF NUMBER(20,7),
  RD9_VAL_EFCT NUMBER(20,7),
  RD9_1_TVA NUMBER(20,7),
  RD9_1_TVA_394 NUMBER(20,7),
  RD9_1_TVA_AMEF NUMBER(20,7),
  RD9_1_TVA_EFCT NUMBER(20,7),
  RD9_1_VAL NUMBER(20,7),
  RD9_1_VAL_394 NUMBER(20,7),
  RD9_1_VAL_AMEF NUMBER(20,7),
  RD9_1_VAL_EFCT NUMBER(20,7),
  RD11_1_TVA NUMBER(20,7),
  RD11_1_TVA_394 NUMBER(20,7),
  RD11_1_TVA_AMEF NUMBER(20,7),
  RD11_1_TVA_EFCT NUMBER(20,7),
  RD11_1_VAL NUMBER(20,7),
  RD11_1_VAL_394 NUMBER(20,7),
  RD11_1_VAL_AMEF NUMBER(20,7),
  RD11_1_VAL_EFCT NUMBER(20,7),
  RD111_1_TVA_REGAC NUMBER(20,7),
  RD111_1_VAL_REGAC NUMBER(20,7),
  RD124_TVA NUMBER(20,7),
  RD124_TVA_394 NUMBER(20,7),
  RD124_VAL NUMBER(20,7),
  RD124_VAL_394 NUMBER(20,7),
  RD125_TVA NUMBER(20,7),
  RD125_TVA_394 NUMBER(20,7),
  RD125_VAL NUMBER(20,7),
  RD125_VAL_394 NUMBER(20,7),
  RD24_1_TVA NUMBER(20,7),
  RD24_1_TVA_394 NUMBER(20,7),
  RD24_1_TVA_EFCT_I NUMBER(20,7),
  RD24_1_TVA_EFCT_N NUMBER(20,7),
  RD24_1_TVA_EFCT_T NUMBER(20,7),
  RD24_1_TVA_VAMA NUMBER(20,7),
  RD24_1_VAL NUMBER(20,7),
  RD24_1_VAL_394 NUMBER(20,7),
  RD24_1_VAL_EFCT_I NUMBER(20,7),
  RD24_1_VAL_EFCT_N NUMBER(20,7),
  RD24_1_VAL_EFCT_T NUMBER(20,7),
  RD24_1_VAL_VAMA NUMBER(20,7),
  RD25_1_TVA NUMBER(20,7),
  RD25_1_TVA_394 NUMBER(20,7),
  RD25_1_TVA_EFCT_I NUMBER(20,7),
  RD25_1_TVA_EFCT_N NUMBER(20,7),
  RD25_1_TVA_EFCT_T NUMBER(20,7),
  RD25_1_TVA_VAMA NUMBER(20,7),
  RD25_1_VAL NUMBER(20,7),
  RD25_1_VAL_394 NUMBER(20,7),
  RD25_1_VAL_EFCT_I NUMBER(20,7),
  RD25_1_VAL_EFCT_N NUMBER(20,7),
  RD25_1_VAL_EFCT_T NUMBER(20,7),
  RD25_1_VAL_VAMA NUMBER(20,7),
  RD274_TVA NUMBER(20,7),
  RD274_VAL NUMBER(20,7),
  RD275_TVA NUMBER(20,7),
  RD275_VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_390_394</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC87D64139829BCACD0E44D898ABEB403F4F67B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_390_394 (
  CODETVA_390_394 NUMBER(20,0),
  CODETVA NUMBER(20,0),
  TIP VARCHAR2(10),
  NUMAR_INREGISTRARE VARCHAR2(75),
  DATA_INREGISTRARE DATE,
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  TIP_DUK VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_AMEF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB03B0AF1CBD660FE5FDC65ACD7C72F3FA03D5C6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_AMEF (
  CODETVA_AMEF NUMBER(20,0),
  CODETVA NUMBER(20,0),
  DATA_Z DATE,
  NUI VARCHAR2(20),
  NR_Z VARCHAR2(20),
  VALOARE_19 NUMBER(20,7),
  TVA_19 NUMBER(20,7),
  VALOARE_9 NUMBER(20,7),
  TVA_9 NUMBER(20,7),
  VALOARE_5 NUMBER(20,7),
  TVA_5 NUMBER(20,7),
  VALOARE_0 NUMBER(20,7),
  TVA_0 NUMBER(20,7),
  VALOARE_21 NUMBER(20,7),
  TVA_21 NUMBER(20,7),
  VALOARE_11 NUMBER(20,7),
  TVA_11 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_ETRANSPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FDBB18FFC71865EB897CC29D7A898B9E1D611123</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_ETRANSPORT (
  CODETVA_ETRANSPORT NUMBER(20,0),
  CODETVA NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DOMICILIU VARCHAR2(150),
  NUMAR_TRN VARCHAR2(20),
  PC_COD VARCHAR2(75),
  PC_DENUMIRE VARCHAR2(100),
  PC_COD_TARA VARCHAR2(5),
  TIP VARCHAR2(100),
  SCOP VARCHAR2(100),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_FACTURA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5AE858275121AC12C9767E810DC06EEA1377BA9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_FACTURA (
  CODETVA_FACTURA NUMBER(20,0),
  CODETVA NUMBER(20,0),
  DATA_SELECTIE DATE,
  DATA_INCEPUT DATE,
  DEN_CUMPARATOR VARCHAR2(200),
  NR_FACTURA VARCHAR2(50),
  TIP_FACTURA NUMBER(20,0),
  CUMP_CUI VARCHAR2(75),
  DATA_SFARSIT DATE,
  TIP VARCHAR2(10),
  DATA_EMITERE DATE,
  VANZ_CUI VARCHAR2(75),
  DEN_VANZATOR VARCHAR2(200),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  ID VARCHAR2(20),
  CIF VARCHAR2(75),
  DATA_INREGISTRARE DATE,
  DATA_LIVRARE DATE,
  DATA_SCADENTA DATE,
  COD_DATA_EXIGIBILA NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_FACTURA_TVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5442F374477422429799417E877DC1ECC00256C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_FACTURA_TVA (
  CODETVA_FACTURA_TVA NUMBER(20,0),
  CODETVA_FACTURA NUMBER(20,0),
  CODETVA NUMBER(20,0),
  BAZA_LEI NUMBER(20,7),
  BAZA_CALCUL NUMBER(20,7),
  COTA_TVA NUMBER(20,7),
  CATEG_TVA VARCHAR2(20),
  TVA_LEI NUMBER(20,7),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_LOCUINTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>23353FCB1554E33D6DD7573A223DD6C16B3FFFB3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_LOCUINTE (
  CODETVA_LOCUINTE NUMBER(20,0),
  CODETVA NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DOMICILIU VARCHAR2(200),
  DATA_INREGISTRARE DATE,
  NUMAR_INCHEIERE_AUTENTIF VARCHAR2(50),
  DATA_INCHEIERE_AUTENTIF DATE,
  VALOARE_LOCUINTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_VAMA_EXPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C5ADB7CC79C334BFCB9131D820FB8DE7E06AEF77</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_VAMA_EXPORT (
  CODETVA_VAMA_EXPORT NUMBER(20,0),
  CODETVA NUMBER(20,0),
  NR_MRN VARCHAR2(100),
  DATA_MRN DATE,
  VALOARE NUMBER(20,7),
  MONEDA VARCHAR2(20),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ETVA_VAMA_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AD718257E0E42A0F39452FB4B404D5D1538D9A90</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ETVA_VAMA_IMPORT (
  CODETVA_VAMA_IMPORT NUMBER(20,0),
  CODETVA NUMBER(20,0),
  NR_MRN VARCHAR2(100),
  DATA_MRN DATE,
  ARTICOL VARCHAR2(100),
  VAL_IMPOZABILA NUMBER(20,7),
  COTA_TVA NUMBER(2,0),
  TVA NUMBER(20,7),
  TIP_PLATA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EURO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>35393B257506C28382686BF7571DA37E1D68A2DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EURO (
  COD NUMBER(20,0),
  CODCASA NUMBER(20,0),
  PLU NUMBER(10,0),
  DEP NUMBER(10,0),
  TVACASA NUMBER(10,0),
  OBIECT NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CONT NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  STOC NUMBER(20,7),
  FARACTRL NUMBER(1,0),
  VANDUT NUMBER(20,7),
  BARCOD VARCHAR2(30),
  PLULINK NUMBER(20,0),
  DESCRIPTIV NUMBER(1,0),
  SERVICIU NUMBER(1,0),
  CANTAR NUMBER(1,0),
  STERS NUMBER(1,0),
  SELECTAT NUMBER(1,0),
  DEN_DEP VARCHAR2(250),
  DEN_TVA VARCHAR2(50),
  DEN_OBIECT VARCHAR2(250),
  DEN_GEST VARCHAR2(250),
  DEN_CONT VARCHAR2(250),
  DIFERENTA NUMBER(20,7),
  UM NUMBER(20,0),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  DEN_UM VARCHAR2(50),
  CODTVA NUMBER(20,0),
  PROCENT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVALS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C213F9A35BDB1DCC274D2692BCB8EE9C42DDFA6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVALS (
  CODEVALS NUMBER(20,0),
  CODIDENTEVALS NUMBER(20,0),
  DEN_EVALUARE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVALSEV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1F99331295BEE7F07A345352C3F85C16FAE5BA11</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVALSEV (
  CODEVALSEV NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  CODEVALUATOR NUMBER(20,0),
  DEN_EVALUATOR VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVALSTES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>114ECE22C526A1BFCAD9FBA7A96E0424B5993C01</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVALSTES (
  CODEVALSTES NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  CODTES NUMBER(20,0),
  DEN_TES VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVALUARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C74620D46BE861EE0C17C7A18E654B7F919BFC8E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVALUARI (
  CODEVALUARE NUMBER(20,0),
  CODEVALUATOR NUMBER(20,0),
  DATAORA DATE,
  RUNDAEVALUARE NUMBER(20,0),
  NREVALUATORI NUMBER(20,0),
  NRESANTIOANE NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  CODDESTINATIE NUMBER(20,0),
  NUMETESATURA VARCHAR2(200),
  OBS VARCHAR2(100),
  NUMEEVALUATOR VARCHAR2(200),
  NUMEDESTINATIE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVALUATORI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>614DFB81AEE6059D564011F4BFEDDAE8C383639E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVALUATORI (
  CODEVALUATOR NUMBER(20,0),
  NUME VARCHAR2(200),
  ORDINE NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EVIDENTAMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>206F750311D610537B214B5AC28296AB1FB58E96</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EVIDENTAMF (
  CODMIFIX NUMBER(20,0),
  CODPART1 NUMBER(20,0),
  CODPART2 NUMBER(20,0),
  CODPART3 NUMBER(20,0),
  DATASTART DATE,
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODCLASIF NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DEN_IOART VARCHAR2(60),
  TIPAMORTIZARE VARCHAR2(50),
  STARE VARCHAR2(50),
  DEN_CLASIF VARCHAR2(1000),
  DURATANORMATA NUMBER(20,7),
  DURATAF NUMBER(20,7),
  VALINTRARE NUMBER(20,7),
  AMOCUMUL NUMBER(20,7),
  VALNETACONTA NUMBER(20,7),
  VALREEVAL NUMBER(20,7),
  VALNETACURENTA NUMBER(20,7),
  ASIGURATOR VARCHAR2(100),
  VALASIGURATA NUMBER(20,7),
  NRINVENTAR NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  DEN_CENTRU VARCHAR2(100),
  UMSEC NUMBER(20,0),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODNIRSTOC NUMBER(20,0),
  DATAACHIZ DATE,
  ADAOS NUMBER(20,7),
  CONT NUMBER(20,0),
  DIFPRET NUMBER(1,0),
  MG NUMBER(1,0),
  CODMIFIX1 NUMBER(20,0),
  CODSTARE NUMBER(3,0),
  DEN_UM1 VARCHAR2(100),
  ARETVANEEX NUMBER(1,0),
  PARITATE NUMBER(30,15),
  LASTCODNIRSTOC NUMBER(20,0),
  LASTPU NUMBER(20,7),
  LASTCODGEST NUMBER(20,0),
  LASTCODIOART NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPAMO NUMBER(3,0),
  DFBLOCAT NUMBER(1,0),
  STARECURENTA NUMBER(3,0),
  VALNETACONTA_L NUMBER(20,7),
  DATALASTINTR DATE,
  ANLASTINTR NUMBER(4,0),
  LUNALASTINTR NUMBER(2,0),
  RESPONSABIL VARCHAR2(500),
  CODNIRSER NUMBER(20,0),
  CODSERIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPCOCACOLA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FE801246FD8F500AEC2C0FFE1094C1615A963BF4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPCOCACOLA (
  STO1 TIMESTAMP(6),
  STO2 TIMESTAMP(6),
  STO3 TIMESTAMP(6),
  OTHERS TIMESTAMP(6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPERT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>38309BF1D5678538472046AC837526FB42FE3A13</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPERT (
  CODEXPERT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DIRTY NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DENDOC VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPERT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BF0C31E843EE897C0528541DB37B6732FBD1B35E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPERT1 (
  CODEXPERT1 NUMBER(20,0),
  CODEXPERT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  INDEXJURN NUMBER(20,0),
  GESTJURN NUMBER(20,0),
  SUBUNITJURN NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  TIPCONT NUMBER(1,0),
  CODELEMENT NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  ANALIZANODJURN NUMBER(20,0),
  SIMBOLCONT VARCHAR2(50),
  DENANALIZANOD VARCHAR2(200),
  DENELEMENT VARCHAR2(200),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  BUTON VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPERTJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A187268EC3F5B9B42A4321856B4E18BA056D7D6A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPERTJ (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(30),
  CODCENTRU NUMBER(20,0),
  SIMBCONTDEBIT VARCHAR2(30),
  SIMBCONCREDIT VARCHAR2(30),
  DIRTY NUMBER(20,0),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPH_COMPOSEDPRODUCTS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>677016F9ABB31E79858F440D81C64B883BFBEEF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPH_COMPOSEDPRODUCTS (
  COMPOSEDINTERNALITEMCODE VARCHAR2(20),
  COMPOSEDITEMCODE VARCHAR2(20),
  INTERNALITEMCODE VARCHAR2(20),
  COMPONENTCODE VARCHAR2(20),
  QTTY NUMBER(20,7),
  PERCENT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPH_PAYMENTS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5950E95DDEFE49B97BF4F0C79BFDA42A1222F9D1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPH_PAYMENTS (
  STARTDATE VARCHAR2(8),
  ENDDATE VARCHAR2(8),
  PAYMENTNUMBER VARCHAR2(20),
  PAYMENTINTERNALID VARCHAR2(20),
  SALESINVOICEINTERNALHID VARCHAR2(20),
  PAYMENTVALUE NUMBER(20,7),
  PAYMENTDATE VARCHAR2(8)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPH_PURCHASE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2E3AB222B8F88D428E5BEC9E6EC7BF29CBCE379E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPH_PURCHASE (
  STARTDATE VARCHAR2(8),
  ENDDATE VARCHAR2(8),
  INTERNALHID VARCHAR2(20),
  DATADOC VARCHAR2(8),
  NRDOC VARCHAR2(20),
  SERIALNO VARCHAR2(20),
  LOCATIONCODE VARCHAR2(100),
  AMOUNTH NUMBER(20,7),
  VATH NUMBER(20,7),
  AMOUNTWITHVATH NUMBER(20,7),
  INVOICEDUEDATE VARCHAR2(8),
  INTERNALDETID VARCHAR2(20),
  INTERNALITEMCODE VARCHAR2(100),
  ITEMCODE VARCHAR2(100),
  ITEMNAME VARCHAR2(200),
  QTTY NUMBER(20,7),
  AMOUNTDET NUMBER(20,7),
  VATDET NUMBER(20,7),
  AMOUNTWITHVATDET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPH_SALES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>586342AC0419C6DC7A2C5D4FFDDFD1E77477672B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPH_SALES (
  STARTDATE VARCHAR2(8),
  ENDDATE VARCHAR2(8),
  INTERNALHID VARCHAR2(20),
  DATADOC VARCHAR2(8),
  NRDOC VARCHAR2(20),
  SERIALNO VARCHAR2(20),
  LOCATIONCODE VARCHAR2(100),
  AMOUNTH NUMBER(20,7),
  VATH NUMBER(20,7),
  AMOUNTWITHVATH NUMBER(20,7),
  INVOICEDUEDATE VARCHAR2(8),
  AGENTNAME VARCHAR2(300),
  AGENTPIN VARCHAR2(30),
  CLIENTCODE VARCHAR2(20),
  CLIENTNAME VARCHAR2(100),
  CLIENTFISCALREGISTRATION VARCHAR2(30),
  CLIENTLOCATIONINTERNALID VARCHAR2(20),
  CLIENTLOCATIONNAME VARCHAR2(100),
  CLIENTLOCATIONCODE VARCHAR2(100),
  CLIENTLOCATIONADDRESS VARCHAR2(200),
  CLIENTLOCATIONCITY VARCHAR2(100),
  CLIENTLOCATIONCOUNTY VARCHAR2(100),
  CLIENTCATEGORY VARCHAR2(100),
  INTERNALDETID VARCHAR2(40),
  INTERNALITEMCODE VARCHAR2(100),
  ITEMCODE VARCHAR2(100),
  ITEMNAME VARCHAR2(200),
  QTTY NUMBER(20,7),
  AMOUNTDET NUMBER(20,7),
  VATDET NUMBER(20,7),
  AMOUNTWITHVATDET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPH_STOCK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF326D7F5AAED6F13A273787241E9DC7B2DB594E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPH_STOCK (
  STARTDATE VARCHAR2(8),
  ENDDATE VARCHAR2(8),
  INTERNALITEMCODE VARCHAR2(100),
  ITEMCODE VARCHAR2(100),
  ITEMNAME VARCHAR2(200),
  QTTY NUMBER(20,7),
  STOCKDATE VARCHAR2(8),
  LOCATIONCODE VARCHAR2(100),
  STOCKVALUE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPLINES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6C18A48F7ACA27E60C4035B18D25A04806F99095</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPLINES (
  LINIE VARCHAR2(2000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXPLINES_ORD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>49FDB551568688F061881447FE938BD4C1455A35</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXPLINES_ORD (
  ORD NUMBER(20,0),
  LINIE VARCHAR2(2000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXTCFGTABLE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54B3FAE1F1D9BB0736E4904F4CBF0B2618A01A26</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXTCFGTABLE (
  COD_EXTCFGTABLE NUMBER(20,0),
  NUME_TABELA VARCHAR2(30),
  DESCRIERE VARCHAR2(500),
  MASTER_TABLE VARCHAR2(30),
  LINK_KEY VARCHAR2(30),
  STATE NUMBER(2,0),
  TIP_DOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_EXT_COD_CORESP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3DED1B20FFEE1A9AA2289AF3D2DE367F165DC772</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_EXT_COD_CORESP (
  NUME_TABELA_MASTER VARCHAR2(30),
  OLD_CODE NUMBER(20,0),
  NEW_CODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FACTSALINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>425FF25D9B3FAD154947634C3BCB01D226342005</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FACTSALINK (
  CODIES1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FACTSALINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60A46C8F4C4E7819C25CF6A6F8D247E0E1AABB48</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FACTSALINK_INITIAL (
  CODIES1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC5EF5FD929067F6DC299E0621970EDADB9A4801</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZ (
  CODFAZ NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CODPERS NUMBER(20,0),
  DIAGRAMA NUMBER(20,0),
  ALIMPOMPA NUMBER(20,7),
  ALIMBCF NUMBER(20,7),
  ALIMAVANS NUMBER(20,7),
  KMPLECARE NUMBER(10,0),
  KMSOSIRE NUMBER(10,0),
  KMN NUMBER(10,0),
  CSARCINA NUMBER(20,7),
  CSARCINAR NUMBER(20,7),
  CSTART NUMBER(20,7),
  CIMOTOR NUMBER(20,7),
  CCURSE NUMBER(20,7),
  CRAER NUMBER(20,7),
  CIARNA NUMBER(20,7),
  OREREGIE NUMBER(20,7),
  OREACORD NUMBER(20,7),
  OREN NUMBER(20,7),
  TONES NUMBER(20,7),
  ORES NUMBER(20,7),
  TSTART NUMBER(20,0),
  TIMOTOR NUMBER(20,0),
  TCURSE NUMBER(20,0),
  RAER NUMBER(1,0),
  PARCURSN NUMBER(1,0),
  REZERVORPLECARE NUMBER(20,7),
  CODFAZS NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CONSUM NUMBER(20,7),
  REZERVORCALC NUMBER(20,7),
  REZERVOR NUMBER(20,7),
  OBS VARCHAR2(250),
  TIPPARCURS NUMBER(10,0),
  CODBC NUMBER(20,0),
  CODDECONT NUMBER(20,0),
  CODAUTO1 NUMBER(20,0),
  CODAUTO2 NUMBER(20,0),
  PARCURSR1 NUMBER(20,7),
  PARCURSR2 NUMBER(20,7),
  PARCURS1 NUMBER(20,7),
  PARCURS2 NUMBER(20,7),
  T1 NUMBER(20,7),
  T2 NUMBER(20,7),
  ECHIV1 NUMBER(20,7),
  ECHIV2 NUMBER(20,7),
  CODGRAUTO NUMBER(20,0),
  PARCURSB NUMBER(20,7),
  PARCURSM NUMBER(20,7),
  PARCURSO NUMBER(20,7),
  B NUMBER(20,7),
  M NUMBER(20,7),
  O NUMBER(20,7),
  ECHIVB NUMBER(20,7),
  ECHIVM NUMBER(20,7),
  ECHIVO NUMBER(20,7),
  TIPAERODIN NUMBER(20,0),
  NRREM NUMBER(20,7),
  PARCURSAERO NUMBER(20,7),
  AEROSR NUMBER(20,7),
  ECHIVAERO NUMBER(20,7),
  ECHIVINST NUMBER(20,7),
  CODINTR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODTREZOR NUMBER(20,0),
  CMM NUMBER(20,7),
  CONSSTAT NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  NRINREG VARCHAR2(20),
  MARCA NUMBER(20,0),
  ALIMTOTAL NUMBER(20,7),
  KMPARCURS NUMBER(20,7),
  RESTSPECIFICAT NUMBER(20,7),
  TKM NUMBER(20,7),
  TKMPLIN NUMBER(20,7),
  TKMGOL NUMBER(20,7),
  TKMSPOR NUMBER(20,7),
  TKMTOT NUMBER(20,7),
  TR_TOTALKM NUMBER(20,7),
  TR_TOTALOPRIRI NUMBER(10,0),
  TR_DURATA VARCHAR2(50),
  INST_TOTAL VARCHAR2(50),
  TECHIVGRUPA NUMBER(20,7),
  R1_TIPINCARC VARCHAR2(50),
  R2_TIPINCARC VARCHAR2(50),
  TPARCURS NUMBER(20,7),
  PUTERE NUMBER(20,7),
  AUTO_TIP NUMBER(1,0),
  AUTO_MASAU NUMBER(10,0),
  AUTO_TIPINCARC NUMBER(1,0),
  DIFREZERVOR NUMBER(20,7),
  INTRARE VARCHAR2(50),
  BC VARCHAR2(50),
  DECONT VARCHAR2(50),
  CONSUMMEDIU NUMBER(20,7),
  CONSSTATH NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZ0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E722CE2B5457B491BE5CEF21ACB8350B3CF6B5CC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZ0 (
  CODFAZ0 NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  KMPLECARE NUMBER(20,7),
  KMSOSIRE NUMBER(20,7),
  DATAPLECARE DATE,
  CODPERS NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDOC VARCHAR2(30),
  NRDOC VARCHAR2(30),
  RUTA VARCHAR2(200),
  TIPTRANSPORT VARCHAR2(50),
  CANT NUMBER(20,7),
  KMINC NUMBER(20,7),
  KMGOL NUMBER(20,7),
  OBS VARCHAR2(250),
  CODANALIZANOD NUMBER(20,0),
  SOFER VARCHAR2(400),
  KM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZ1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B65CF6BB414EFC296B168F192DF6AFFFB91A9C61</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZ1 (
  CODFAZ1 NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  KM NUMBER(20,7),
  INCARCAT NUMBER(1,0),
  TIPSURSA NUMBER(20,0),
  CATDRUM NUMBER(20,0),
  COEF NUMBER(20,7),
  CODFAZ0 NUMBER(20,0),
  DENCATDRUM VARCHAR2(100),
  KMECHIV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZ2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AEAF9B605E8AA35E2056415BFC0754E1F582F3D7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZ2 (
  CODFAZ2 NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODINSTAUTO NUMBER(20,0),
  CANT NUMBER(20,7),
  SPOR NUMBER(20,7),
  PARCURSECHIV NUMBER(20,7),
  INSTALATIE VARCHAR2(200),
  PRESTATIE VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZ3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>610FEAFF840E7F3A0A321C30B10D1B16826B0EF0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZ3 (
  CODFAZ3 NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODTRASEU NUMBER(20,0),
  PARCURGERI NUMBER(10,0),
  KMTRASEU NUMBER(20,7),
  OPRIRI NUMBER(10,0),
  DURATA VARCHAR2(50),
  DENTRASEU VARCHAR2(100),
  DURATAORE NUMBER(10,0),
  DURATAMINUTE NUMBER(10,0),
  TOTALKM NUMBER(20,7),
  ORE NUMBER(10,0),
  MINUTE NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FAZINTR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>03C15D2A80F251A1748C60521FEA3E3ACCDD95C9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FAZINTR (
  CODFAZINTR NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CANTCOMB NUMBER(20,7),
  DOC VARCHAR2(100),
  REST NUMBER(20,7),
  ALTEFAZ NUMBER(20,7),
  CANTINTR NUMBER(20,7),
  ARTICOL VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FDS_D100</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2FA348787F063F5FBA2BA05A4C677175FC261C4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FDS_D100 (
  SIMBOL VARCHAR2(100),
  TIP NUMBER(1,0),
  CURENTD NUMBER(20,7),
  CURENTC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FIRMA_ADR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6566F341472954E960449469BF31C05EE2B16CA3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FIRMA_ADR (
  CODSUBUNIT NUMBER(20,0),
  DENFIRMA VARCHAR2(200),
  CODFISCAL VARCHAR2(13),
  NRJ VARCHAR2(20),
  PERSFIZ NUMBER(1,0),
  DENTARA VARCHAR2(50),
  SIMBTARA VARCHAR2(3),
  DENJUDET VARCHAR2(50),
  SIMBJUDET VARCHAR2(2),
  DENLOCALIT VARCHAR2(50),
  CODPOSTAL VARCHAR2(10),
  STRADA VARCHAR2(100),
  NR1 VARCHAR2(5),
  NR2 VARCHAR2(5),
  BLOC VARCHAR2(5),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(20),
  AP VARCHAR2(5),
  TELEFON1 VARCHAR2(20),
  TELEFON2 VARCHAR2(20),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(500),
  SECTOR VARCHAR2(5),
  NUMEADMIN VARCHAR2(50),
  PRENUMEADMIN VARCHAR2(50),
  CAPITALS NUMBER(20,7),
  CODBANKCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FIRMECUPLATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2D1DDBDE260E8370898916CDF559CB4E3FB8098F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FIRMECUPLATE (
  COD NUMBER(20,0),
  ID VARCHAR2(30),
  CUPLATA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAEVALP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>31388AE44D7EFA3437B619579D8AAFED5130C3A9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAEVALP (
  CODFISA NUMBER(20,0),
  CODEVALUARE NUMBER(20,0),
  CR NUMBER(2,0),
  EN NUMBER(2,0),
  MT NUMBER(2,0),
  FR NUMBER(2,0),
  SG NUMBER(2,0),
  NA NUMBER(2,0),
  AN NUMBER(2,0),
  UG NUMBER(2,0),
  NUMETESATURA VARCHAR2(200),
  RUNDAEVALUARE NUMBER(2,0),
  CODEVALUATOR NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  CODDESTINATIE NUMBER(20,0),
  NUMEEVALUATOR VARCHAR2(200),
  NUMEDESTINATIE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAEVALT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A40DA360B3901B033664E291BA10F90959CED7D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAEVALT (
  CODFISA NUMBER(20,0),
  CODEVALUARE NUMBER(20,0),
  NOTA NUMBER(2,0),
  NUMETESATURA VARCHAR2(200),
  RUNDAEVALUARE NUMBER(2,0),
  CODEVALUATOR NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  CODDESTINATIE NUMBER(20,0),
  NUMEEVALUATOR VARCHAR2(200),
  NUMEDESTINATIE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAINF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E5C493069F99DF56FB3CE316AF94580C89BFE49E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAINF (
  CODFISAINF NUMBER(20,0),
  CODFISASUP NUMBER(20,0),
  POZNOM NUMBER(10,0),
  CODOBIECTINF NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANTINSUP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  DIMT VARCHAR2(50),
  COMPLEX NUMBER(1,0),
  MATERIAL NUMBER(1,0),
  CODFISAPRO NUMBER(20,0),
  UMDIMT NUMBER(20,0),
  CONSUMATOR NUMBER(20,0),
  MASA NUMBER(20,7),
  DEN_OBIECT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAINFMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9B4740A817B9EB025655FE0D8BD1F0BDA7B6E87</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAINFMAT (
  CODFISAINF NUMBER(20,0),
  CODFISASUP NUMBER(20,0),
  POZNOM NUMBER(10,0),
  CODOBIECTINF NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANTINSUP NUMBER(10,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  DIMT VARCHAR2(50),
  COMPLEX NUMBER(1,0),
  MATERIAL NUMBER(1,0),
  CODFISAPRO NUMBER(20,0),
  UMDIMT NUMBER(20,0),
  CONSUMATOR NUMBER(20,0),
  MASA NUMBER(20,7),
  DEN_OBIECT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EFA5B7ECF7B03CDA2221A4700F0337C3C5ABF061</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMAN (
  CODFISAMAN NUMBER(20,0),
  CODTRASEU NUMBER(20,0),
  NROP NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODLOCM NUMBER(20,0),
  CODDIF NUMBER(10,0),
  DSV NUMBER(10,0),
  TPI NUMBER(10,0),
  TU NUMBER(10,0),
  BPS NUMBER(10,0),
  FINAL NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  CODFISATEH NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMAND</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>216B2E4F3EEAAA9C36890A3AACAF73DB8240DF27</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMAND (
  CODFISAMAND NUMBER(20,0),
  CODFISAMAN NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODDIF NUMBER(20,0),
  TPI NUMBER(10,0),
  TU NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7984D464F208BFE0F436C7EA710C50FFDC054C45</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMAS (
  CODFISAMAS NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  CODRESPONSABIL NUMBER(20,0),
  CODINSPECTOR NUMBER(20,0),
  OBS VARCHAR2(250),
  APROBAT NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  HFACTOR NUMBER(2,0),
  CODOBIECT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CARNETDOC_I NUMBER(20,0),
  NRDOC_I NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMAS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A809CF490706FE5F8FD9DD225E1C27DEFB444AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMAS1 (
  CODFISAMAS1 NUMBER(20,0),
  CODFISAMAS NUMBER(20,0),
  CODPRODMAS NUMBER(20,0),
  VALOARE NUMBER(20,7),
  STARE NUMBER(10,0),
  OBS VARCHAR2(50),
  DESCRIERE VARCHAR2(200),
  FRECVENTA VARCHAR2(30),
  METODA VARCHAR2(150),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20EF73BA479858C822325E7B590652D3E5069B37</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMAT (
  CODFISAINF NUMBER(20,0),
  CODFISASUP NUMBER(20,0),
  POZNOM NUMBER(10,0),
  CODOBIECTINF NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANTINSUP NUMBER(10,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  DIMT VARCHAR2(50),
  COMPLEX NUMBER(1,0),
  MATERIAL NUMBER(1,0),
  CODFISAPRO NUMBER(20,0),
  UMDIMT NUMBER(20,0),
  CONSUMATOR NUMBER(20,0),
  MASA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2292F6B48C36A020E359B66F9B086E86A39FA0D1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMF (
  CODFISAMF NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  CODOPERATIE NUMBER(5,0),
  DATAOPERATIE DATE,
  GESTSURSA NUMBER(20,0),
  GESTDEST NUMBER(20,0),
  PRETI NUMBER(20,7),
  PRETE NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  INFOOPERATIE VARCHAR2(50),
  DENGESTSURSA VARCHAR2(300),
  DENGESTDEST VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAMF_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>593923C81616EEE32A967C2DA53629AB5301E8E0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAMF_INI (
  CODFISAMF NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  CODOPERATIE NUMBER(5,0),
  DATAOPERATIE DATE,
  GESTSURSA NUMBER(20,0),
  GESTDEST NUMBER(20,0),
  PRETI NUMBER(20,7),
  PRETE NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  INFOOPERATIE VARCHAR2(50),
  DENGESTSURSA VARCHAR2(300),
  DENGESTDEST VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D6A9628F372BCEB8E90D5BF3E1C9A3B1A5D11945</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAPART (
  ISSOLDINI NUMBER(1,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  NRI VARCHAR2(20),
  VALDOC NUMBER(20,7),
  VALDOCBAZA NUMBER(20,7),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  DATADECONT DATE,
  CODPERS NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  PARTENER NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  SEMNIFICATIE NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  TERMEN DATE,
  MAJORARI NUMBER(20,7),
  VALOARE NUMBER(20,7),
  DSTINSSERIA VARCHAR2(20),
  DSTINSCARNET NUMBER(20,0),
  DSTINSPREFIX VARCHAR2(20),
  DSTINSNR NUMBER(20,0),
  DSTINSDATA DATE,
  DSTINSAN NUMBER(20,0),
  DSTINSLUNA NUMBER(20,0),
  DEBIT_AJDEP NUMBER(20,0),
  CREDIT_AJDEP NUMBER(20,0),
  SOLD_AJDEP NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  DSTINSTIPDOC NUMBER(20,0),
  DSTINSCODDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAPART_OBLIG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2A62D9E42044437F03B51636B8C258362C5BAD03</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAPART_OBLIG (
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISAREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6AA71C769CEFCBFCDF5CF63FB598AB98053BFBB4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISAREZ (
  CODFISAREZ NUMBER(20,0),
  CODTRASEU NUMBER(20,0),
  CODPREZ NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  CODFISATEH NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISASDV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>15BE20BECA62CDAB23E21A6ECADF2CA6FD3AA7E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISASDV (
  CODFISASDV NUMBER(20,0),
  CODFISAMAN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODSDV NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISASUP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF6C610506C8E223CB744EBBA3B65F2EC72C78CD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISASUP (
  CODFISASUP NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECTNOD NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  OBS VARCHAR2(3000),
  PROIECTANT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  BLOCAT NUMBER(1,0),
  DEN_PROIECTANT VARCHAR2(400),
  DEN_UM VARCHAR2(50),
  DENUMIRE VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISASUPMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2FC528C3855B2CFA944A603FC37695F361348FF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISASUPMAT (
  CODFISASUP NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECTNOD NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  OBS VARCHAR2(3000),
  PROIECTANT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  BLOCAT NUMBER(1,0),
  DEN_PROIECTANT VARCHAR2(400),
  DEN_UM VARCHAR2(50),
  DENUMIRE VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISATEH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F09304DC50ED2121203CB0A114786C8714657D5D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISATEH (
  CODFISATEH NUMBER(20,0),
  CODFISASUP NUMBER(20,0),
  INTOCMITA NUMBER(20,0),
  DATAFISA DATE,
  FINALIZATA NUMBER(1,0),
  BLOCATA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FISA_MENTENANTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6F69D1E3016AA732185A63CD0E16FB6C72D5FE4C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FISA_MENTENANTA (
  NR NUMBER(10,0),
  OPERATIE VARCHAR2(1000),
  CODUTILAJ2 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FORMATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>90BF756AA56A1B34287C673DAD3EE2BF581DD02E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FORMATII (
  CODFORMATIE NUMBER(20,0),
  DEN_FORMATIE VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FORMATII1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E51036F6D0110C66D1CC936CE7C3C531C88668D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FORMATII1 (
  CODFORMATIE1 NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  LOCMUNCA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  DEN_LOCMUNCA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FORMATII_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>96E93C6288F6AF09131C1C58B3E2ABA542237AAC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FORMATII_MAN (
  CODFORMATIE NUMBER(20,0),
  DEN_FORMATIE VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FORMATORI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F8A180D564604DEA6B96AED0D6C5C07245773DF6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FORMATORI (
  CODFORMATOR NUMBER(20,0),
  DEN_FORMATOR VARCHAR2(30),
  EMAIL VARCHAR2(100),
  TELEFON VARCHAR2(20),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUNCTII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F75925DA8FE18B794200FD996EC80391637614C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUNCTII (
  CODFUNCTIE NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(100),
  CODEXTERN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUNCTII1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A0ECBE4D61BE7DE48DEA591BA1A3E9C44A2270A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUNCTII1 (
  CODFUNCTIE1 NUMBER(20,0) NOT NULL,
  CODFUNCTIE NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C9764482072D99531DDFF56FF660582942311B3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZART (
  CODARTINIT NUMBER(20,0),
  CODARTFIN NUMBER(20,0),
  CODOBJINIT NUMBER(20,0),
  CODOBJFIN NUMBER(20,0),
  CODEXTERNINIT VARCHAR2(80),
  CODEXTERNFIN VARCHAR2(80),
  PRODINIT VARCHAR2(50),
  PRODFIN VARCHAR2(50),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE,
  CODINTERNINIT VARCHAR2(80),
  CODINTERNFIN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8599EBBC56CA60CA22FB8C15592CD752FC57F17D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZAUTO (
  CODAUTOINIT NUMBER(20,0),
  CODAUTOFIN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A47A716C105DD61A9CFE2116CB76D4E000BF539</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZGEST (
  CODGESTINIT NUMBER(20,0),
  CODGESTFIN NUMBER(20,0),
  SUBUNITINIT VARCHAR2(100),
  SUBUNITFIN VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZLOCALIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ABF0E2446ECF8CA5E771D48010F351EF56828924</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZLOCALIT (
  CODLOCALITINIT NUMBER(20,0),
  CODLOCALITFIN NUMBER(20,0),
  SIMBAUTOINIT VARCHAR2(2),
  SIMBAUTOFIN VARCHAR2(2),
  DENSUPINIT VARCHAR2(50),
  DENSUPFIN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AFF2C2EAF9BEE10081FE6BE9721B9725E9FF09BC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZPART (
  CODPARTINIT NUMBER(20,0),
  CODPARTFIN NUMBER(20,0),
  CODLOCINIT NUMBER(20,0),
  CODLOCFIN NUMBER(20,0),
  CODEXTINIT VARCHAR2(50),
  CODEXTFIN VARCHAR2(50),
  CODFISCINIT VARCHAR2(75),
  CODFISCFIN VARCHAR2(75),
  LOCALITINIT VARCHAR2(50),
  LOCALITFIN VARCHAR2(50),
  INFOINIT VARCHAR2(250),
  INFOFIN VARCHAR2(250),
  USERID NUMBER(20,0),
  USERSTR VARCHAR2(250),
  DATA DATE,
  TELEFONINIT VARCHAR2(40),
  TELEFONFIN VARCHAR2(40)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_FUZPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>33D66B1D42AC2513C07FB1BAF1D7F3866BDE9683</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_FUZPERS (
  CODPERSINIT NUMBER(20,0),
  CODPERSFIN NUMBER(20,0),
  SUBUNITINIT VARCHAR2(100),
  SUBUNITFIN VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GANTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B03D03000B2D1B724141D1E8B468CED0B8675914</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GANTT (
  CODGANTT NUMBER(20,0) NOT NULL,
  CODCMDPRODMAN NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DSTART DATE,
  CANT NUMBER(10,0),
  NSTART DATE,
  OSTART NUMBER(7,3),
  PRIORITATE NUMBER(20,0),
  DIRECTIE NUMBER(1,0),
  OSTOP NUMBER(7,3),
  BLOCAT NUMBER(1,0),
  ORDINE NUMBER(20,0),
  CODMAN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GANTT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ECADA749C3ECE612CF05D70083F2E64648C63F9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GANTT1 (
  CODGANTT1 NUMBER(20,0) NOT NULL,
  CODGANTT NUMBER(20,0),
  DEPLASARE NUMBER,
  CANT NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENERAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>167F641DB8B860FAFD4AA3732BD384D0254B22E6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENERAL (
  CODGENERAL NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  ICONTAVANS NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  DATATVA DATE,
  INITIALIZARI NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENERAL_CECURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6A6EA9E80482EE16639521009BAEF15E1365CE3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENERAL_CECURI (
  CODGENERAL NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  ICONTAVANS NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  DATATVA DATE,
  INITIALIZARI NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENERAL_LITIGII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3BA70DD985948A6C65E5D4D48BBE602DDFD4290</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENERAL_LITIGII (
  CODGENERAL NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  ICONTAVANS NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  DATATVA DATE,
  INITIALIZARI NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENMONETARERETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0129CDAC83B6B44B676D45017F228622CED07394</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENMONETARERETAIL (
  CODPOSTRETAIL NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  CARNETCMD NUMBER(20,0),
  CARNETNP NUMBER(20,0),
  CARNETBC NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  CONTCASH NUMBER(20,0),
  CONTCEC NUMBER(20,0),
  CONTCARD NUMBER(20,0),
  CONTTICHET NUMBER(20,0),
  DESCARCAREPROD NUMBER(1,0),
  DENUMIRE VARCHAR2(50),
  ID NUMBER(3,0),
  NUMEFIRMA VARCHAR2(30),
  SUBUNITATEA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  NRLIVR NUMBER(20,0),
  NRCMD NUMBER(20,0),
  SERIACMD VARCHAR2(20),
  NRNP NUMBER(20,0),
  SERIANP VARCHAR2(20),
  NRBC NUMBER(20,0),
  SERIABC VARCHAR2(20),
  NRNIR NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6),
  SELECTAT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  INFOMONETAR VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_ART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>64FBCADA1B43BB8CB3D776E2431FF1A69F2E68F9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENNP_ART (
  CODINTR1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  NRDOC NUMBER(20,3),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  PRIORITATE NUMBER(10,0),
  DURATAR NUMBER(20,7),
  DURATA NUMBER(20,7),
  TERMEN DATE,
  UMSEC NUMBER(20,0),
  PROGRAMAT NUMBER(20,7),
  PROGRAMAT_P NUMBER(20,7),
  PU NUMBER(20,7),
  REALIZAT NUMBER(20,7),
  REALIZAT_P NUMBER(20,7),
  PREDAT NUMBER(20,7),
  PREDAT_P NUMBER(20,7),
  UM1 NUMBER(20,0),
  DEN_UMS VARCHAR2(15),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RAPORTAT NUMBER(20,7),
  RAPORTAT_P NUMBER(20,7),
  REBUT NUMBER(20,7),
  REBUT_P NUMBER(20,7),
  RAPORTATUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(10,0),
  UM NUMBER(20,0),
  PARITATE NUMBER(20,7),
  DEN_UM1 VARCHAR2(15),
  TIPSERIE NUMBER(1,0),
  CODFISA NUMBER(20,0),
  AVIZAT NUMBER(1,0),
  AREFISA NUMBER(10,0),
  FISAMAS VARCHAR2(100),
  PRET NUMBER(20,7),
  PRET_P NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  CODPROGRAMF1 NUMBER(20,0),
  MASA NUMBER(20,7),
  CODGESTNIR NUMBER(20,0),
  CODLOCNIR NUMBER(20,0),
  CODIOARTNIR NUMBER(20,0),
  GESTNIR VARCHAR2(100),
  GESTLOCCONT VARCHAR2(500),
  LOCATIENIR VARCHAR2(30),
  IOARTNIR VARCHAR2(60),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  DONE NUMBER(1,0),
  CODPERS NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DEN_ANGAJAT VARCHAR2(450),
  INCHISA NUMBER(1,0),
  CODCOMANDA NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  DATADOC DATE,
  CODGEST NUMBER(20,0),
  PREDATTOT NUMBER(20,7),
  PREDATTOT_P NUMBER(20,7),
  RESTPF NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  TOTALUM1 NUMBER(20,7),
  UTILAJ VARCHAR2(200),
  ORASTART DATE,
  NRSCHIMBURI NUMBER(10,0),
  ORESCHIMB NUMBER(20,7),
  OREPEZI NUMBER(10,0),
  TIPARTICOL VARCHAR2(1),
  OBSCLI VARCHAR2(500),
  NRDOCCLI NUMBER(20,3),
  CODINTERN VARCHAR2(80),
  FROMPP NUMBER(20,0),
  CONSUM NUMBER(20,0),
  R_PREDAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_CMD1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52E2505B712261F1D55F46812746BD0E08626950</HASHVAL>
  <TEXT>CREATE TABLE TMP_GENNP_CMD1 (
  CODPROGRAMF1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRIORITATE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  TERMEN DATE,
  CANT NUMBER(20,7),
  USERID NUMBER(20,0),
  REBUT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_CMDMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A345C92A3EFA859E33D6F1043F46386E83F70A2D</HASHVAL>
  <TEXT>CREATE TABLE TMP_GENNP_CMDMAN (
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_CRS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0DCA3F307F706CFB24D605787CEB1D89628EA0BC</HASHVAL>
  <TEXT>CREATE TABLE TMP_GENNP_CRS (
  CODCMDPRODMAT NUMBER(20,0),
  CODPROGRAMF1 NUMBER(20,0),
  CANT NUMBER(20,7),
  USERID NUMBER(20,0),
  TIP NUMBER(10,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>25D2AC705E22244460C00662170DD8A149F881AA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENNP_MAN (
  CODCOMANDA1 NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  DEN_OP VARCHAR2(100),
  DEN_TARIF VARCHAR2(150),
  TARIF NUMBER(20,7),
  ORETOTAL NUMBER(20,7),
  ORE NUMBER(20,7),
  VALOARE NUMBER(20,7),
  TOTAL NUMBER(20,7),
  UNITAR NUMBER(20,7),
  DATADOC DATE,
  REALIZAT NUMBER(20,7),
  PRODREBUTATE NUMBER(20,7),
  PROGRAMAT NUMBER(20,7),
  CODPERS NUMBER(20,0),
  DEN_ANGAJAT VARCHAR2(500),
  MARCA NUMBER(20,0),
  RAPORTAT NUMBER(20,7),
  ORASTART DATE,
  NRSCHIMBURI NUMBER(5,0),
  ORESCHIMB NUMBER(20,7),
  OREPEZI NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODMAN NUMBER(20,0),
  TU NUMBER(20,7),
  TUMIN NUMBER(20,7),
  BPS NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0),
  DETALII NUMBER(10,0),
  NROP NUMBER(10,0),
  DATASTARTC VARCHAR2(50),
  DATASTOPC VARCHAR2(50),
  DATASTART DATE,
  DATASTOP DATE,
  REBUTATE NUMBER(20,7),
  REFACUTE NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0),
  LASTOP NUMBER(10,0),
  FIRSTOP NUMBER(10,0),
  DETLASTOP NUMBER(10,0),
  PRELUATALTE NUMBER(20,7),
  CODLOC NUMBER(20,0),
  OBS VARCHAR2(1000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CE3853812F299AD26CB9E332ED94161DE3F55059</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENNP_MAT (
  CODIES1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  UMSEC NUMBER(20,0),
  TOTAL NUMBER(20,7),
  TOTALUM1 NUMBER(20,7),
  TOTAL_P NUMBER(20,7),
  PROGRAMAT NUMBER(20,7),
  PROGRAMAT_P NUMBER(20,7),
  UNITAR NUMBER(20,7),
  UNITAR_P NUMBER(20,7),
  REALIZAT NUMBER(20,7),
  REALIZAT_P NUMBER(20,7),
  CONSUMAT NUMBER(20,7),
  CONSUMAT_P NUMBER(20,7),
  UM1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RAPORTAT NUMBER(20,7),
  RAPORTAT_P NUMBER(20,7),
  RAPORTATUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(10,0),
  UM NUMBER(20,0),
  PARITATE NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODCMDPRODMAT NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  TERMEN DATE,
  CODPROGRAMF1 NUMBER(20,0),
  TIPARTICOL VARCHAR2(1),
  DEN_UM1 VARCHAR2(30),
  PRET NUMBER(20,7),
  PRET_P NUMBER(20,7),
  SUPLIMENT NUMBER(10,0),
  STOC NUMBER(20,7),
  STOC_P NUMBER(20,7),
  STOCT NUMBER(20,7),
  TIP NUMBER(2,0),
  NRDOC NUMBER(20,3),
  MATECHIV NUMBER(20,0),
  ECHIVALENTA NUMBER(20,0),
  CANTECHIVALATA NUMBER(20,7),
  ECHIVSTRING VARCHAR2(2),
  CODCOMANDA NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  DEN_PRODUS VARCHAR2(250),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(2,0),
  CODIOART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENLOCATIE VARCHAR2(50),
  GESTLOCCONT VARCHAR2(500),
  DEN_CLASEA VARCHAR2(50),
  DEN_UM_1 VARCHAR2(30),
  DEN_UM_2 VARCHAR2(30),
  TRANSFERAT NUMBER(20,7),
  PARITATEDURI NUMBER(20,7),
  ZECIMALE NUMBER(4,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_MATC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7E4285BFD06B960F0AF27D334FACB6A438C5C889</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENNP_MATC (
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  UMSEC NUMBER(20,0),
  TOTAL NUMBER(20,7),
  PROGRAMAT NUMBER(20,7),
  REALIZAT NUMBER(20,7),
  CONSUMAT NUMBER(20,7),
  UM1 NUMBER(20,0),
  RAPORTAT NUMBER(20,7),
  TRANSFER NUMBER(20,7),
  UM NUMBER(20,0),
  PARITATE NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  TIPARTICOL VARCHAR2(1),
  DEN_UM1 VARCHAR2(15),
  STOC NUMBER(20,7),
  STOCT NUMBER(20,7),
  CODOBIECTEKIV NUMBER(20,0),
  DENUMIREEKIV VARCHAR2(200),
  CANTEKIV NUMBER(20,7),
  STOCEKIV NUMBER(20,7),
  STOCTEKIV NUMBER(20,7),
  ZECIMALE NUMBER(4,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GENNP_REZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C1095417CAA45E2CE16601D22257A2DABA0F19C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GENNP_REZ (
  CODINTR1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  NRDOC NUMBER(20,3),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  PRIORITATE NUMBER(20,0),
  DURATAR NUMBER(20,7),
  DURATA NUMBER(20,7),
  TERMEN DATE,
  UMSEC NUMBER(20,0),
  PROGRAMAT NUMBER(20,7),
  UNITAR NUMBER(20,7),
  REALIZAT NUMBER(20,7),
  PREDAT NUMBER(20,7),
  UM1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RAPORTAT NUMBER(20,7),
  RAPORTATUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(10,0),
  PARITATE NUMBER(20,7),
  DEN_UM1 VARCHAR2(30),
  TIPSERIE NUMBER(1,0),
  PRET NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  CODPROGRAMF1 NUMBER(20,0),
  MASA NUMBER(20,7),
  CODGESTNIR NUMBER(20,0),
  CODLOCNIR NUMBER(20,0),
  CODIOARTNIR NUMBER(20,0),
  GESTNIR VARCHAR2(100),
  GESTLOCCONT VARCHAR2(300),
  LOCATIENIR VARCHAR2(50),
  IOARTNIR VARCHAR2(100),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  DONE NUMBER(10,0),
  CODPERS NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DEN_ANGAJAT CHAR(400),
  INCHISA NUMBER(10,0),
  CODCOMANDA NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  TOTAL NUMBER(20,7),
  TOTALUM1 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GEN_PENALITATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6DEFA34DF40F646B49938BCD503CEDDC842F181A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GEN_PENALITATI (
  CODOBLIGPIF NUMBER(20,0),
  PREFIXDOC VARCHAR2(4),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  TERMEN DATE,
  REST NUMBER(20,7),
  MAJORARI NUMBER(20,7),
  PRELUAT NUMBER(20,7),
  LOCATIE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  MONEDA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  MAJANTERIOARE NUMBER(20,7),
  DATA_LAST_FACTMAJ DATE,
  DATA_LAST_PLATA DATE,
  RESTOBLIG NUMBER(20,7),
  VALOBLIG NUMBER(20,7),
  GRATIEDOC NUMBER(10,0),
  STORNO NUMBER(20,7),
  SCADENTAV NUMBER(10,0),
  VALMAJ NUMBER(20,7),
  ZILE NUMBER(10,0),
  CODUNIC NUMBER(10,0),
  RESTLADATA NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GEN_PENALITATI_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D12A094C80A3156E5FB1E4CEBDCDD938BF6C8F0A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GEN_PENALITATI_MAN (
  CODOBLIGPIF NUMBER(20,0),
  PREFIXDOC VARCHAR2(4),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  TERMEN DATE,
  REST NUMBER(20,7),
  MAJORARI NUMBER(20,7),
  PRELUAT NUMBER(20,7),
  LOCATIE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  MONEDA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  MAJANTERIOARE NUMBER(20,7),
  DATA_LAST_FACTMAJ DATE,
  DATA_LAST_PLATA DATE,
  RESTOBLIG NUMBER(20,7),
  VALOBLIG NUMBER(20,7),
  GRATIEDOC NUMBER(10,0),
  STORNO NUMBER(20,7),
  SCADENTAV NUMBER(10,0),
  VALMAJ NUMBER(20,7),
  ZILE NUMBER(10,0),
  CODUNIC NUMBER(10,0),
  RESTLADATA NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GESTCMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BE2B5785F85F0B26E38495C64EE89EF07255AC9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GESTCMD (
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DEN_GEST VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GESTDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C60987C0995E1E06981439818A7829B740DDCF3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GESTDEDICATE (
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GEST_CASA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F15B3958EF8D69A335A2B3A3502B265C28E98D4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GEST_CASA (
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GFA_CONTR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A427D1AB207B8187716CECED0A474BB94A21B8FC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GFA_CONTR (
  CODCONTRACT NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  PARTENER NUMBER(20,0),
  MONEDA NUMBER(20,0),
  AGENT NUMBER(20,0),
  SCADENTA DATE,
  VALOARE NUMBER(20,7),
  PROCMAJ NUMBER(8,5),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DEN_PART VARCHAR2(100),
  SIMB_MON VARCHAR2(5),
  DEN_AGENT VARCHAR2(401),
  FACTURAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DEN_JUDET VARCHAR2(30),
  DEN_LOCALIT VARCHAR2(50),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  FACTLEI NUMBER(1,0),
  DATACONTR DATE,
  SCADENTAV NUMBER(5,0),
  OBS VARCHAR2(250),
  CODPERSC NUMBER(20,0),
  DATASTOP DATE,
  DSTART DATE,
  DSTOP DATE,
  SEDIULIVRARE NUMBER(20,0),
  OBSFACT VARCHAR2(450),
  BANCA NUMBER(20,0),
  DEN_BANCA VARCHAR2(50),
  NRAUXFACT NUMBER(20,0),
  CURS NUMBER(20,7),
  CODANALIZA NUMBER(20,0),
  SEDIULIVRDEN VARCHAR2(100),
  DENTRASEU VARCHAR2(100),
  POZTRASEU NUMBER(20,0),
  DENTRASEU1 VARCHAR2(100),
  POZTRASEU1 NUMBER(20,0),
  DATASCADV DATE,
  ZILESCADV NUMBER(5,0),
  PERFACT NUMBER(2,0),
  CONTR_SEDLIVR NUMBER(20,0),
  PROCMAJCURS NUMBER(8,5),
  AVANS NUMBER(2,0),
  ZIFACT NUMBER(2,0),
  SEDIULIVRADR VARCHAR2(200),
  EXPLICATII VARCHAR2(50),
  CREDITE_PLAFON NUMBER(20,7),
  CREDITE_PU NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GFA_CONTR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77C459B8BDDCF99B78A5A443A8F1B1D1D151D290</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GFA_CONTR1 (
  CODCONTRACT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PU NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(5,2),
  CODARTICOL NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  TIPARTICOL VARCHAR2(1),
  CONTSERVICIU NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(30,15),
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  MG NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  ZILEC NUMBER(5,0),
  OBS VARCHAR2(200),
  ZILEPLATA NUMBER(5,0),
  CODCENTRU NUMBER(20,0),
  TIPPRET NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  SEDIULIVRARE NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CANTCONTRACT NUMBER(20,7),
  NRAUXFACT NUMBER,
  VALRATA NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CONTR_SEDLIVR NUMBER(20,0),
  CONTR_SLDEN VARCHAR2(100),
  CONTR_SLADR VARCHAR2(300),
  CONTORDATAREF DATE,
  CONTORDATAINI DATE,
  CONTORIDXINI NUMBER(20,7),
  CONTORDATAFIN DATE,
  CONTORIDXFIN NUMBER(20,7),
  PARITATECREDIT NUMBER(20,7),
  SERIEF VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GRECHIV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>804949ABD58348E79F9D43C28C8CD84C5F1AABE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GRECHIV (
  CODGRECHIV NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  COD VARCHAR2(32),
  IND NUMBER(10,0),
  INFO VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_GRUPEDRUM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C548F88DB2C79C2F4208F767C16C95DE7E3B231E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_GRUPEDRUM (
  CODGRUPA NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  COEF NUMBER(20,7),
  DESCRIERE CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2A4D777DF2E9FF74C14FF395256FB5041481103</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IH (
  CODIES NUMBER(20,0),
  DENXML VARCHAR2(100),
  ITH01 VARCHAR2(50),
  ITH02 VARCHAR2(25),
  ITH03 VARCHAR2(50),
  ITH04 VARCHAR2(50),
  ITH05 VARCHAR2(25),
  ITH06 VARCHAR2(25),
  ITH07 VARCHAR2(1),
  IH01 VARCHAR2(25),
  IH02 VARCHAR2(25),
  IH03 VARCHAR2(50),
  IH04 VARCHAR2(50),
  IH05 VARCHAR2(200),
  IH06 VARCHAR2(25),
  IH07 VARCHAR2(25),
  IH08 VARCHAR2(3),
  IH08A VARCHAR2(3),
  IH09 VARCHAR2(20),
  IH10 VARCHAR2(2),
  IH11 VARCHAR2(20),
  IH12 VARCHAR2(20),
  IH13 VARCHAR2(25),
  IH14 VARCHAR2(10),
  IH15 VARCHAR2(10),
  IH16 NUMBER(10,0),
  IH19 VARCHAR2(25),
  IH20 VARCHAR2(25),
  IH21 VARCHAR2(80),
  IH22 VARCHAR2(3),
  IH23 VARCHAR2(3),
  IHCC01 VARCHAR2(1),
  IHCC02 VARCHAR2(3),
  IHCC02A VARCHAR2(9),
  IHCC03 VARCHAR2(3),
  IHCC03A VARCHAR2(9),
  IHCC04 VARCHAR2(25),
  IH24 VARCHAR2(25),
  IH25 VARCHAR2(25),
  IH26 VARCHAR2(25),
  IH27 VARCHAR2(25),
  IS01 NUMBER(18,0),
  IS02 VARCHAR2(25),
  IS03 VARCHAR2(25),
  IS04 VARCHAR2(25),
  IS05 VARCHAR2(25),
  ITS01 NUMBER(6,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IID</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C93F2414E6080777856C504FD31EEC80D116138</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IID (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IID01 VARCHAR2(2),
  IID02 VARCHAR2(25),
  IID03 VARCHAR2(50),
  IID04 VARCHAR2(50),
  IID05 VARCHAR2(50),
  IID06 VARCHAR2(50),
  IID07 VARCHAR2(50),
  IID08 VARCHAR2(50),
  IID09 VARCHAR2(2),
  IID10 VARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IIDCF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>06F8FC95D7D432DE97C9436AC1A60F0864E86FD2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IIDCF (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IIDCF01 NUMBER(2,0),
  IIDCF02 VARCHAR2(35),
  IIDCF03 VARCHAR2(35)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>939AC1F0DE2A3D3CBE4385AD05C1080353A8681F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IN (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IH28 VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IPT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F4E21836B6C85B0DDCA71642F5B8E6CD85F6D740</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IPT (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IH17 VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_IRV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9947C78D72010F394796DEB52FFFCBE95EBF3B33</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_IRV (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IH18 VARCHAR2(25),
  IH18A VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_ITAX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>482AFF41166789BA215027392E975AFCA695BC97</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_ITAX (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  IHT01 VARCHAR2(3),
  IHT02 VARCHAR2(80),
  IHT03 VARCHAR2(25),
  IHT04 VARCHAR2(25),
  IHT05 VARCHAR2(25),
  IHT06 VARCHAR2(1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_ITD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>72D4C1AB0325A4B77BBA3592A1E14DA3948F5BC5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_ITD (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ITH08 VARCHAR2(80),
  ITH08A VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0AD39179DB49592C63E6E6A1A850E8732B1C10EA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINE (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  L01 NUMBER(6,0),
  L02 VARCHAR2(25),
  L03 VARCHAR2(20),
  L04 VARCHAR2(25),
  L05 VARCHAR2(25),
  L06 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINEDR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C4594CFC29C226D11EB83F59E62049354D53B52B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINEDR (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  LDR01 VARCHAR2(35),
  LDR01A VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINEQ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2860DE99CDDB84BDDEA134CB6D048D0FCFF886E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINEQ (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  LQ01 VARCHAR2(2),
  LQ02 VARCHAR2(2),
  LQ03 VARCHAR2(25),
  LQ04 VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINERGD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5019C3E2383C0851616989248EB8838A6BC6863</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINERGD (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  LRGD01 VARCHAR2(35),
  LRGD01A VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINERLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67E8E19596F2CC70CA1F5755C9D0B463241E05BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINERLD (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  LRLD01 VARCHAR2(25),
  LRLD01A VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_LINET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>732CA0BB3573668E40B180E448E1816AD43415CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_LINET (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  LT01 VARCHAR2(20),
  LT02 VARCHAR2(25),
  LT03 VARCHAR2(25),
  LT04 VARCHAR2(35),
  LT05 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_PROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9FFCE8CD8B5EB31A717DE452B03B14129AE97D7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_PROD (
  CODIES1 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  P01 VARCHAR2(5),
  P01A VARCHAR2(4),
  P02 VARCHAR2(80),
  P03 VARCHAR2(2),
  P04 VARCHAR2(25),
  P05 VARCHAR2(3),
  P06 VARCHAR2(25),
  P07 VARCHAR2(3),
  P08 VARCHAR2(25),
  PCC01 VARCHAR2(1),
  PCC02 VARCHAR2(3),
  PCC02A VARCHAR2(9),
  PCC03 VARCHAR2(3),
  PCC03A VARCHAR2(9),
  PCC04 VARCHAR2(25),
  P09 VARCHAR2(3),
  P10 VARCHAR2(25),
  P11 VARCHAR2(25),
  P12 VARCHAR2(2),
  P13 VARCHAR2(2),
  P14 VARCHAR2(25),
  P15 VARCHAR2(25),
  P16 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_SI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>55B1A77FCD0A5E3CF5575C35F808D7A981654918</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_SI (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  SI01 VARCHAR2(25),
  SI02 VARCHAR2(25),
  SI03 VARCHAR2(25),
  SI04 VARCHAR2(25),
  SICC01 VARCHAR2(25),
  SICC02 VARCHAR2(25),
  SIHCC02A VARCHAR2(25),
  SICC03 VARCHAR2(25),
  SIHCC03A VARCHAR2(25),
  SICC04 VARCHAR2(25),
  SI05 VARCHAR2(25),
  SI06 VARCHAR2(25)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_SIFN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7831D7145EBF552EA3093FC3D8B9A48D644110E7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_SIFN (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ORD2 NUMBER(20,0),
  SI07 VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_SIID</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AFB83DF60549B8B01CCDCE74DE9FD2ECF6FA3B53</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_SIID (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ORD2 NUMBER(20,0),
  SIID01 VARCHAR2(2),
  SIID02 VARCHAR2(25),
  SIID03 VARCHAR2(50),
  SIID04 VARCHAR2(50),
  SIID05 VARCHAR2(50),
  SIID06 VARCHAR2(50),
  SIID07 VARCHAR2(50),
  SIID08 VARCHAR2(50),
  SIID09 VARCHAR2(2),
  SIID10 VARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_SIIDCF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>976A7B08D000A60DABC3D33B6782E9F86765FA24</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_SIIDCF (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ORD2 NUMBER(20,0),
  SIIDCF01 NUMBER(2,0),
  SIIDCF02 VARCHAR2(35),
  SIIDCF03 VARCHAR2(35)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_SITAX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>672070F6DCD4E2400AB201C7536F09898456DC55</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_SITAX (
  CODIES NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ORD2 NUMBER(20,0),
  SIT01 VARCHAR2(3),
  SIT02 VARCHAR2(80),
  SIT03 VARCHAR2(25),
  SIT04 VARCHAR2(25),
  SIT05 VARCHAR2(25),
  SIT06 VARCHAR2(1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IATA_TAX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>189FFDFB3BA9AB4B019DFE5BE4875FDE16F5C1D4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IATA_TAX (
  CODIES1 NUMBER(20,0),
  ORDPROD NUMBER(20,0),
  ORDTAX NUMBER(20,0),
  T01 VARCHAR2(10),
  T02 VARCHAR2(35),
  T03 VARCHAR2(10),
  T04 VARCHAR2(3),
  T05 VARCHAR2(10),
  T06 VARCHAR2(10),
  T07 VARCHAR2(5),
  T08 VARCHAR2(3),
  T09 VARCHAR2(1),
  T10 VARCHAR2(3),
  T10A NUMBER(9,0),
  T11 VARCHAR2(3),
  T11A NUMBER(9,0),
  T12 NUMBER(18,6),
  T13 VARCHAR2(10),
  T14 NUMBER(18,6),
  T15 NUMBER(18,6),
  T16 NUMBER(18,2),
  T17 VARCHAR2(10),
  T18 NUMBER(18,6),
  T19 NUMBER(18,6),
  TQ_A1 NUMBER(18,6),
  TQ_A2 VARCHAR2(5),
  TQ_B1 NUMBER(18,6),
  TQ_B2 VARCHAR2(5),
  T20 NUMBER(18,2),
  T21 NUMBER(18,2),
  T22 VARCHAR2(1),
  ST01 VARCHAR2(10),
  ST02 VARCHAR2(35),
  ST03 VARCHAR2(10),
  ST04 VARCHAR2(3),
  ST05 VARCHAR2(10),
  ST06 VARCHAR2(10),
  ST07 VARCHAR2(5),
  ST08 VARCHAR2(3),
  ST09 VARCHAR2(1),
  ST10 VARCHAR2(3),
  ST10A NUMBER(9,0),
  ST11 VARCHAR2(3),
  ST11A NUMBER(9,0),
  ST12 NUMBER(18,6),
  ST13 VARCHAR2(10),
  ST14 NUMBER(18,6),
  ST15 NUMBER(18,6),
  ST16 NUMBER(18,2),
  ST17 VARCHAR2(10),
  ST18 NUMBER(18,6),
  ST19 NUMBER(18,6),
  STQ_A1 NUMBER(18,6),
  STQ_A2 VARCHAR2(5),
  STQ_B1 NUMBER(18,6),
  STQ_B2 VARCHAR2(5),
  ST20 NUMBER(18,2),
  ST21 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IDENTEVALS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8148320D3F5A4417A9C948915661A520FECB2014</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IDENTEVALS (
  CODIDENTEVALS NUMBER(20,0),
  NUME VARCHAR2(50),
  DATAORA DATE,
  NREVALUATORI NUMBER(3,0),
  NRESANTIOANE NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESCADOU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>26DBA649BF28A79990087F56DBFB999F43247B9F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESCADOU (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANTOBIECT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CANTCADOU NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0),
  ZECIMALE NUMBER(1,0),
  DENCADOU VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESDISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2A346BA8B02DB60DACD24E4EA6AAC5FD7EECF251</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESDISC (
  CODIESDISC NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  OFFINVOICE NUMBER(1,0),
  PROCENT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODCATEGDISC NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  CUMULAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESDISCC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13C24CDF505E91A7F51B3C999C22FE3D78A175F7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESDISCC (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PJDISC NUMBER(20,7),
  DISCUNITAR NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESDISCV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD5BA7558DF24A992C78BBF1A486A9E83ABE65BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESDISCV (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  BAZA NUMBER(20,7),
  DISC NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESFURN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34A85B59363F3F0A0F1036A19150486868D48C9A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESFURN (
  CODIES NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CODNIRSTOCROOT NUMBER(20,0),
  PIES NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>845074D9743382E2CAD593F7D4F3A50DC9BA1CC9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRI (
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  CARNETAE NUMBER(20,0),
  NRAE NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ACCIZE NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  AGENT NUMBER(20,0),
  MAJORARI NUMBER(20,7),
  OBS VARCHAR2(600),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  BUGETARE NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  TIPFACTURA NUMBER(10,0),
  CODGESTPROD NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  TIPCONSUMATOR NUMBER(2,0),
  CODAUTO NUMBER(20,0),
  PARTCUSTODIE NUMBER(20,0),
  CODCMDINTERNA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  COMISION NUMBER(20,7),
  CODBANKCONT NUMBER(20,0),
  TIPCASAMARCAT NUMBER(5,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPTRANZACTIE NUMBER(5,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  DISCVOL NUMBER(20,7),
  DISCTER NUMBER(20,7),
  MONEDATRANSF NUMBER(20,7),
  NRI VARCHAR2(50),
  CONTSUPLIM NUMBER(20,0),
  DATAINREG TIMESTAMP(6),
  CUSTODIE NUMBER(1,0),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  CARNETCERTIF NUMBER(20,0),
  NRCERTIF NUMBER(20,0),
  SERIACERTIF VARCHAR2(10),
  STARERESTITUIRE NUMBER(1,0),
  IDIMPORT VARCHAR2(30),
  LISTATCERTIF NUMBER(1,0),
  FARAREG NUMBER(1,0),
  CODPERSC NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  CODIESMAMB NUMBER(20,0),
  PROCTVADOC NUMBER(20,7),
  CODANALIZA NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  TVAINCASARE NUMBER(1,0),
  DATATVA DATE,
  CODCONTRACT NUMBER(20,0),
  FACTSIMPLIF NUMBER(1,0),
  TRANSPORTATOR NUMBER(20,0),
  STADIUWMS NUMBER(2,0),
  CODMONETAR NUMBER(20,0),
  NUMARBONURI NUMBER(5,0),
  EMISADECLIENT NUMBER(1,0),
  NRINFOCM NUMBER(5,0),
  NRINCASULT NUMBER(5,0),
  NRINCASIM NUMBER(5,0),
  CODPARTTERT NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  NATURATRANZ NUMBER(2,0),
  MODTRANSP NUMBER(2,0),
  SPLITTVA NUMBER(1,0),
  GRATIE NUMBER(10,0),
  TIPSAFT NUMBER(2,0),
  CODTVASERV NUMBER(20,0),
  PROCTVAOSS NUMBER(6,3),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  NOACCIZE NUMBER(1,0),
  NRNIR VARCHAR2(20),
  DATANIR DATE,
  PLATFORMA_ONLINE NUMBER(2,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7),
  REMORCA NUMBER(20,0),
  PROIECT VARCHAR2(20),
  CONTRACT VARCHAR2(20),
  COMANDA VARCHAR2(20),
  EXCLUSINTRASTAT NUMBER(1,0),
  NUMEDELEGAT VARCHAR2(50),
  SOLDPART NUMBER(20,7),
  SCADENTAV NUMBER(5,0),
  PARTENERCOMUNITAR NUMBER(1,0),
  SIMBAUTOTARA VARCHAR2(3),
  SCADENTESETATEMANUAL NUMBER(1,0),
  DISCOUNTPART NUMBER(20,7),
  COLDISCPART NUMBER(1,0),
  TOTDISCOFFINVOICEF NUMBER(20,7),
  TOTDISCOFFINVOICEC NUMBER(20,7),
  GESTLIVRARESEDIU NUMBER(20,0),
  DEZAGREGARE NUMBER(1,0),
  MAJORARICLIENT NUMBER(20,7),
  CODRECLAMATIE NUMBER(20,0),
  EF_IDINCARCARE VARCHAR2(20),
  EF_IDDESCARCARE VARCHAR2(20),
  EF_TIPMEDIU NUMBER(1,0),
  EF_STATUS VARCHAR2(20),
  CODCONTTVAOSS NUMBER(20,0),
  UIT VARCHAR2(20),
  ET_IDINCARCARE VARCHAR2(20),
  ET_IDDESCARCARE VARCHAR2(20),
  ET_TIPMEDIU NUMBER(1,0),
  ET_STATUS VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9645D51122F68415B2A0A542CB6CF429BFB1C29</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRI1 (
  CODIES1 NUMBER(20,0),
  CODIES NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  TIPLIVRARE NUMBER(1,0),
  GARANTIE NUMBER(20,0),
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  MIFIX NUMBER(1,0),
  ZILE NUMBER(5,0),
  COSTTRANSPORT NUMBER(20,7),
  ZILECMD NUMBER(20,0),
  CODLIVR1PRODVAL NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CADOU NUMBER(20,0),
  TIPPLATA NUMBER(1,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODIOARTCUST NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  CANTCORELAT NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  CODOBLIGMONETAR NUMBER(20,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1D3BCS NUMBER(1,0),
  CODOBLIGMAJORAT NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  ICONTPART NUMBER(2,0),
  CANTCONSTATAT NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  IMPOZABIL NUMBER(1,0),
  PRETUM1 NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODPARTCOMISEMUL NUMBER(20,0),
  ADMAX NUMBER(20,7),
  VALFIN NUMBER(20,7),
  TVAFIN NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(50),
  CODCATPRET NUMBER(20,0),
  SIMBOLCONTSERV VARCHAR2(100),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  DENOBIECTORIG VARCHAR2(200),
  DENUMCORELAT VARCHAR2(25),
  CODEMULSTINGERE NUMBER(20,0),
  COEFUM_CANTAR NUMBER(20,5),
  DISPLIVR NUMBER(1,0),
  PROMOTIE NUMBER(1,0),
  CUSTODIE NUMBER(1,0),
  CMDINT NUMBER(20,0),
  CONTRACT NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  PUREAL NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  DENCLASA VARCHAR2(150),
  CANTUM2 NUMBER(20,7),
  INFOMF VARCHAR2(100),
  INFODOCRETUR VARCHAR2(50),
  UM1 NUMBER(20,0),
  RELATIEUM1 NUMBER(20,7),
  SIMBOLIOPART VARCHAR2(50),
  UTILAJ VARCHAR2(400),
  UM2 NUMBER(20,0),
  INFOBCAR VARCHAR2(50),
  TAXCODE NUMBER(20,0),
  CODVAMAL VARCHAR2(80),
  CODCPV VARCHAR2(10),
  RISCFISCAL NUMBER(1,0),
  CODCENTRALIZARE NUMBER(20,0),
  VOUCHERCADOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRI1RETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>926710C12220A57C1DF5CBEEE04CF1B29A089D31</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRI1RETAIL (
  CODIES1RETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  GARANTIE NUMBER(20,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  ZILE NUMBER(5,0),
  CADOU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  TAXA NUMBER(1,0),
  CODAGENTEMULARE NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODIOARTVAL NUMBER(20,0),
  TVANEEX NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  SIMBOLCONTSERV VARCHAR2(100),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  PUREAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRI1RETAIL_PREL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>267DE8A485AC9007B2231D6A298B8891CE41F177</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRI1RETAIL_PREL (
  CODIES1RETAIL NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  GARANTIE NUMBER(20,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  ZILE NUMBER(5,0),
  CADOU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  TAXA NUMBER(1,0),
  CODAGENTEMULARE NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODIOARTVAL NUMBER(20,0),
  TVANEEX NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  SIMBOLCONTSERV VARCHAR2(100),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  PUREAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRI1_TVAINCAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6B59396776C3508FDB844BFAEFE8103ACAB3BA2A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRI1_TVAINCAS (
  CODIES1 NUMBER(20,0),
  CODIES NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  UMSEC NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  CONT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  TIPLIVRARE NUMBER(1,0),
  GARANTIE NUMBER(20,0),
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(450),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  MIFIX NUMBER(1,0),
  ZILE NUMBER(5,0),
  COSTTRANSPORT NUMBER(20,7),
  ZILECMD NUMBER(20,0),
  CODLIVR1PRODVAL NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CADOU NUMBER(20,0),
  TIPPLATA NUMBER(1,0),
  PRETPROMO NUMBER(1,0),
  CADOULINK NUMBER(5,0),
  CODIOARTCUST NUMBER(20,0),
  UMCORELAT NUMBER(20,0),
  CANTCORELAT NUMBER(20,7),
  PUCORELAT NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  CODOBLIGMONETAR NUMBER(20,0),
  TAXA NUMBER(1,0),
  TERMENCONTRACT DATE,
  CODLINIEDOCIMP NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1D3BCS NUMBER(1,0),
  CODOBLIGMAJORAT NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VALDISCPRET NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  ICONTPART NUMBER(2,0),
  CANTCONSTATAT NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  CODUTILAJ NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  IMPOZABIL NUMBER(1,0),
  PRETUM1 NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODPARTCOMISEMUL NUMBER(20,0),
  ADMAX NUMBER(20,7),
  VALFIN NUMBER(20,7),
  TVAFIN NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(50),
  CODCATPRET NUMBER(20,0),
  SIMBOLCONTSERV VARCHAR2(100),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  ROTUNJIRE NUMBER(2,0),
  DENOBIECTORIG VARCHAR2(200),
  DENUMCORELAT VARCHAR2(25),
  CODEMULSTINGERE NUMBER(20,0),
  COEFUM_CANTAR NUMBER(20,5),
  DISPLIVR NUMBER(1,0),
  PROMOTIE NUMBER(1,0),
  CUSTODIE NUMBER(1,0),
  CMDINT NUMBER(20,0),
  CONTRACT NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  PUREAL NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  DENCLASA VARCHAR2(50),
  CANTUM2 NUMBER(20,7),
  INFOMF VARCHAR2(100),
  INFODOCRETUR VARCHAR2(50),
  UM1 NUMBER(20,0),
  RELATIEUM1 NUMBER(20,7),
  SIMBOLIOPART VARCHAR2(50),
  UTILAJ VARCHAR2(400),
  UM2 NUMBER(20,0),
  INFOBCAR VARCHAR2(50),
  TAXCODE NUMBER(20,0),
  CODVAMAL VARCHAR2(80),
  CODCPV VARCHAR2(10),
  RISCFISCAL NUMBER(1,0),
  CODCENTRALIZARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRIRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF4E807217AAA7BA4BB82BC27410381628239C9E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRIRETAIL (
  CODIESRETAIL NUMBER(20,0),
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODPARTRETAIL NUMBER(20,0),
  PARTENER NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  OBS VARCHAR2(450),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODFISCALRETAIL NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODSEDIURETAIL NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  NRI VARCHAR2(30),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  PROCTVADOC NUMBER(20,7),
  DATATVA DATE,
  TIPMODIF VARCHAR2(1),
  AGENT NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7),
  UIT VARCHAR2(20),
  ET_IDINCARCARE VARCHAR2(20),
  ET_IDDESCARCARE VARCHAR2(20),
  ET_TIPMEDIU NUMBER(1,0),
  ET_STATUS VARCHAR2(20),
  PARTENERCOMUNITAR NUMBER(1,0),
  SIMBAUTOTARA VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESIRIRETAIL_PREL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E80EE9559C5BB4AFDC03538B52EFDC71ECB2F2D8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESIRIRETAIL_PREL (
  CODIESRETAIL NUMBER(20,0),
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODPARTRETAIL NUMBER(20,0),
  PARTENER NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  DELEGATRETAIL NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  OBS VARCHAR2(450),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODFISCALRETAIL NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODSEDIURETAIL NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  LISTAT NUMBER(1,0),
  INFOCM NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  NRI VARCHAR2(30),
  FARATRANSPORT NUMBER(1,0),
  TIPCHELT NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  PROCTVADOC NUMBER(20,7),
  DATATVA DATE,
  TIPMODIF VARCHAR2(1),
  AGENT NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  CODPARTRETAILCOMIS NUMBER(20,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  ROTEFACT NUMBER(1,0),
  FLAGS NUMBER(5,0),
  IDDESCARCARE NUMBER(20,0),
  VALDOCEFACT NUMBER(20,7),
  UIT VARCHAR2(20),
  ET_IDINCARCARE VARCHAR2(20),
  ET_IDDESCARCARE VARCHAR2(20),
  ET_TIPMEDIU NUMBER(1,0),
  ET_STATUS VARCHAR2(20),
  PARTENERCOMUNITAR NUMBER(1,0),
  SIMBAUTOTARA VARCHAR2(3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A288C5276E015EF6C15C8EE626F4946A7E226685</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESLINK (
  CODIES1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  MONEDAAVIZ NUMBER(20,0),
  CURSAVIZ NUMBER(20,7),
  PRETAVIZ NUMBER(20,7),
  TVAAVIZ NUMBER(20,7),
  CANTAVIZ NUMBER(20,7),
  DATAAVIZ DATE,
  DATACOMANDA DATE,
  CUSTODIE NUMBER(1,0),
  ACTUALIZPRET NUMBER(1,0),
  CODCOMAND1ORIG NUMBER(20,0),
  SUBUNITAVIZ NUMBER(20,0),
  PROCDISCAVIZ NUMBER(20,7),
  TIPTVAAVIZ NUMBER(2,0),
  FLAGS NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CF53A82B61511DA101FC0E9F36E3A76B35B6626A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESLINK_INITIAL (
  CODIES1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  MONEDAAVIZ NUMBER(20,0),
  CURSAVIZ NUMBER(20,7),
  PRETAVIZ NUMBER(20,7),
  TVAAVIZ NUMBER(20,7),
  CANTAVIZ NUMBER(20,7),
  DATAAVIZ DATE,
  DATACOMANDA DATE,
  CUSTODIE NUMBER(1,0),
  ACTUALIZPRET NUMBER(1,0),
  CODCOMAND1ORIG NUMBER(20,0),
  SUBUNITAVIZ NUMBER(20,0),
  PROCDISCAVIZ NUMBER(20,7),
  TIPTVAAVIZ NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESPRODLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B28FDA69612B0579A29D3B084ABF170430BB38EF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESPRODLINK (
  CODIES1 NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  CANT NUMBER(20,7),
  CODLINIECOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  CODPROGRAMF1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESPRODLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6FE8608BD355052BC1E0EBE475F1400CA68B55BC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESPRODLINK_INITIAL (
  CODIES1 NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  CANT NUMBER(20,7),
  CODLINIECOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  CODPROGRAMF1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESPUNCTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10E8F68967ABB5CF9B343D3405D6E706A3C60445</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESPUNCTE (
  CODIESPUNCTE NUMBER(20,0),
  CODIES NUMBER(20,0),
  PUNCTEDOC NUMBER(20,7),
  PUNCTEANULATE NUMBER(20,7),
  PUNCTESTINSE NUMBER(20,7),
  BLOCAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESVALLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>616CA4E8CC11AD9EC4C1D2EB0E8B23D49A9CF0CF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESVALLINK (
  CODIES1 NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES NUMBER(20,0),
  TIPLINK NUMBER(5,0),
  DATADOC DATE,
  PRET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IESVALLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7BD1602AF1E4BC2CF7E5432C97B68C3DA6CF8352</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IESVALLINK_INITIAL (
  CODIES1 NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES NUMBER(20,0),
  TIPLINK NUMBER(5,0),
  DATADOC DATE,
  PRET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IES_CONTR2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>474EA46477B5F591A1EF19CEEA5865FE1D8BC3BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IES_CONTR2 (
  CODCONTRACT2 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IES_DISCLIN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0D89042745FB1FB5C0F9567DEFFEF38B77AE740C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IES_DISCLIN (
  CODIES1 NUMBER(20,0),
  LINVAL NUMBER(20,7),
  LINTVA NUMBER(20,7),
  DISCVAL NUMBER(20,7),
  DISCTVA NUMBER(20,7),
  DV_CALC NUMBER(20,7),
  DT_CALC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IMBMIFIXLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6D0EC3918BC8D8DC504E3B29623002BA39640671</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IMBMIFIXLINK (
  CODIMBMIFIXLINK NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IMBMIFIXLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>43C8474CB4C225ED643F5CB391D5EAED69F67BC6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IMBMIFIXLINK_INITIAL (
  CODIMBMIFIXLINK NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IMPORT_MIFIX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B4160FF45F1D9DE4D504EF61EFE2D557882616D1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IMPORT_MIFIX (
  COD NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  CODCLASIF NUMBER(20,0),
  PRET NUMBER(20,7),
  ANINTRARE NUMBER(5,0),
  LUNAINTRARE NUMBER(2,0),
  CODIOART NUMBER(20,0),
  DURATAN NUMBER(10,0),
  DURATAF NUMBER(10,0),
  CANT NUMBER(20,7),
  STARE NUMBER(3,0),
  TIPAMO NUMBER(3,0),
  AMO NUMBER(20,7),
  CODPERS NUMBER(20,0),
  CODGEST NUMBER(20,0),
  NRINVENTAR NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  OBS VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IMPORT_POS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FCA57CCFC8A0FF5E1B85583B885C569DDB8FABC4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IMPORT_POS (
  CODPRODUS VARCHAR2(30),
  CODSECTIE VARCHAR2(30),
  PRET NUMBER(20,7),
  CANTITATE NUMBER(20,7),
  DATA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INACTIVRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>725BE88AD867A990174B16824F3839C778655298</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INACTIVRETAIL (
  CODINACTIVRETAIL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INFOSTINSE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0DFC8B16FCE553B97ABC7804BE857B6E97EB6340</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INFOSTINSE (
  CODGENERAL NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INLOCUIREAGENT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7E2447BC5A4F04F9B824A4D543E51B4301D1C3A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INLOCUIREAGENT (
  OLDCODAGENT NUMBER(20,0),
  NEWCODAGENT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTERFATAKLG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7D5B098C2975AA83EE5482069F64FA0EAAB29EB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTERFATAKLG (
  COD NUMBER(20,0),
  TIPMESAJ VARCHAR2(30),
  DATA TIMESTAMP(6),
  NUMEFISIER VARCHAR2(50),
  XML CLOB,
  IDMESAJ VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTERVAL_LISTARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>754EB0E9C177C142721069695C299EA2AF44F2ED</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTERVAL_LISTARE (
  CODJOB1 NUMBER(20,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  ANEND NUMBER(5,0),
  LUNAEND NUMBER(2,0),
  ZISTART NUMBER(2,0),
  ZIEND NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>186C2E58ED3BE99E793F221AAA4E5EC6075E2474</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRARI (
  CODINTR NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  MAJORARI NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  COMPLEX NUMBER(1,0),
  SATELIT NUMBER(1,0),
  INITIALIZARI NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  BUGETARE NUMBER(1,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  TIPREPSUPLIM NUMBER(1,0),
  CODLOCATIE NUMBER(20,0),
  TIPFACTURA NUMBER(10,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPTVA NUMBER(2,0),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPTRANZACTIE NUMBER(5,0),
  DISCVOL NUMBER(20,7),
  DISCTER NUMBER(20,7),
  NRI VARCHAR2(20),
  SCHIMB NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  IDIMPORT VARCHAR2(30),
  DELEGAT NUMBER(20,0),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  FARAREG NUMBER(1,0),
  EXCLUSPLATA NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  PRORATA NUMBER(3,0),
  CODCONTRACT NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  TVAINCASARE NUMBER(1,0),
  TVAINCASARE_F NUMBER(1,0),
  CURSDOC NUMBER(20,7),
  TRANSPORTATOR NUMBER(20,0),
  VALTRANSPORT NUMBER(20,7),
  CUSTODIE NUMBER(1,0),
  FACTSIMPLIF NUMBER(1,0),
  AGENT NUMBER(20,0),
  CURSNIR NUMBER(20,7),
  STADIUWMS NUMBER(2,0),
  DATAREFSCAD DATE,
  AUTOFACTURARE NUMBER(1,0),
  TIPLIVRARE NUMBER(2,0),
  NATURATRANZ NUMBER(2,0),
  MODTRANSP NUMBER(2,0),
  SPLITTVA NUMBER(1,0),
  ORDONANTAT NUMBER(1,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  PROCSTOPAJ NUMBER(5,2),
  TIPSAFT NUMBER(2,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  ROTEFACT NUMBER(1,0),
  IDDESCARCARE VARCHAR2(20),
  VALDOCEFACT NUMBER(20,7),
  DATATVA DATE,
  APROBAT NUMBER(1,0),
  SOLDPART NUMBER(20,7),
  SCADENTAC NUMBER(5,0),
  SCADENTESETATEMANUAL NUMBER(1,0),
  NUMEDELEGAT VARCHAR2(50),
  PARTCOMUNITAR NUMBER(1,0),
  SIMBAUTOTARA VARCHAR2(3),
  DEZAGREGARE NUMBER(1,0),
  UIT VARCHAR2(20),
  ET_IDINCARCARE VARCHAR2(20),
  ET_IDDESCARCARE VARCHAR2(20),
  ET_TIPMEDIU NUMBER(1,0),
  ET_STATUS VARCHAR2(20),
  EF_IDINCARCARE VARCHAR2(20),
  EF_IDDESCARCARE VARCHAR2(20),
  EF_TIPMEDIU NUMBER(1,0),
  EF_STATUS VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRARI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C17893B2C4EFA7C3C98E60A74E0EA03AF6A58B81</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRARI1 (
  CODINTR1 NUMBER(20,0),
  CODINTR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(10,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  CONTSERV NUMBER(10,0),
  GESTACT NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  ADDIM NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  NRCERTIF VARCHAR2(25),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  PURIDICATA NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  FURNAVIZSUBUNIT NUMBER(20,0),
  DATAACHIZAVIZSUBUNIT DATE,
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  MIFIX NUMBER(1,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(200),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ZILE NUMBER(5,0),
  CODCMD1AE NUMBER(20,0),
  ZILECMD NUMBER(5,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODINTR1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CUSTODIE NUMBER(1,0),
  RESTASTEPTARE NUMBER(20,7),
  CONTASTEPTARE NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  TAXA NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  TERMENCONTRACT DATE,
  PRETUM1 NUMBER(20,7),
  ICONTPART NUMBER(2,0),
  ROTVALTAXA NUMBER(2,0),
  CODINTR1LINK NUMBER(20,0),
  CODNIMOB NUMBER(20,0),
  GESTPRODAVIZSUB NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  IMPOZABIL NUMBER(1,0),
  TIPDOCIMP NUMBER(5,0),
  ADMAX NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(50),
  SIMBOLCONTSERV VARCHAR2(100),
  GESTIMPLICITA NUMBER(20,0),
  CODTVA NUMBER(20,0),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  SEL VARCHAR2(3),
  CERTIFICAT NUMBER(1,0),
  ARETG NUMBER(1,0),
  CODGENERAL NUMBER(20,0),
  TIPPRETMAX NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  ESTEIMBMF NUMBER(1,0),
  INFOMF VARCHAR2(100),
  COEFUM_CANTAR NUMBER(20,5),
  TIPSERIE NUMBER(1,0),
  FISAMASURATORI VARCHAR2(30),
  CMDINT NUMBER(20,0),
  CONTRACT NUMBER(20,0),
  INDEXINTERVENTIE NUMBER(10,0),
  INDEXEDITABIL NUMBER(1,0),
  UTILAJ VARCHAR2(200),
  DATASTARTS VARCHAR2(50),
  DATAENDS VARCHAR2(50),
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CANTUM2 NUMBER(20,7),
  INFOBCAR VARCHAR2(50),
  LOCATIEIMPLICITA NUMBER(20,0),
  UM1 NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  SIMBOLIOPART VARCHAR2(50),
  CODVAMAL VARCHAR2(80),
  CODACCIZEDVI NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  CODCPV VARCHAR2(10),
  RISCFISCAL NUMBER(1,0),
  CODCENTRALIZARE NUMBER(20,0),
  COD_CATALOG VARCHAR2(91),
  DENLAPART VARCHAR2(200),
  CODEXTERNLAPART VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRARI1_TVAINCAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3AD9954D9703E6D683562D2E79A3A111560D46C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRARI1_TVAINCAS (
  CODINTR1 NUMBER(20,0),
  CODINTR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(10,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  CONTSERV NUMBER(10,0),
  GESTACT NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  ADDIM NUMBER(20,7),
  RESTFACT NUMBER(20,7),
  NRCERTIF VARCHAR2(25),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  PURIDICATA NUMBER(20,7),
  PROCADAOS NUMBER(20,7),
  FURNAVIZSUBUNIT NUMBER(20,0),
  DATAACHIZAVIZSUBUNIT DATE,
  CODOBLIGSTORNO NUMBER(20,0),
  CURSFACTURAAVANS NUMBER(20,7),
  MIFIX NUMBER(1,0),
  COEFDISCMAJ NUMBER(20,7),
  OBS VARCHAR2(200),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CONTDISCOUNT NUMBER(20,0),
  ZILE NUMBER(5,0),
  CODCMD1AE NUMBER(20,0),
  ZILECMD NUMBER(5,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODINTR1STORNO NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CUSTODIE NUMBER(1,0),
  RESTASTEPTARE NUMBER(20,7),
  CONTASTEPTARE NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  CODCMDINT1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  TAXA NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  TERMENCONTRACT DATE,
  PRETUM1 NUMBER(20,7),
  ICONTPART NUMBER(2,0),
  ROTVALTAXA NUMBER(2,0),
  CODINTR1LINK NUMBER(20,0),
  CODNIMOB NUMBER(20,0),
  GESTPRODAVIZSUB NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  IMPOZABIL NUMBER(1,0),
  TIPDOCIMP NUMBER(5,0),
  ADMAX NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(23,10),
  PROCTVA NUMBER(20,7),
  NRDOCLINK VARCHAR2(50),
  SIMBOLCONTSERV VARCHAR2(100),
  GESTIMPLICITA NUMBER(20,0),
  CODTVA NUMBER(20,0),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  SEL VARCHAR2(3),
  CERTIFICAT NUMBER(1,0),
  ARETG NUMBER(1,0),
  CODGENERAL NUMBER(20,0),
  TIPPRETMAX NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  ESTEIMBMF NUMBER(1,0),
  INFOMF VARCHAR2(100),
  COEFUM_CANTAR NUMBER(20,5),
  TIPSERIE NUMBER(1,0),
  FISAMASURATORI VARCHAR2(30),
  CMDINT NUMBER(20,0),
  CONTRACT NUMBER(20,0),
  INDEXINTERVENTIE NUMBER(10,0),
  INDEXEDITABIL NUMBER(1,0),
  UTILAJ VARCHAR2(200),
  DATASTARTS VARCHAR2(50),
  DATAENDS VARCHAR2(50),
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CANTUM2 NUMBER(20,7),
  INFOBCAR VARCHAR2(50),
  LOCATIEIMPLICITA NUMBER(20,0),
  UM1 NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  SIMBOLIOPART VARCHAR2(50),
  CODVAMAL VARCHAR2(80),
  CODACCIZEDVI NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  CODCPV VARCHAR2(10),
  RISCFISCAL NUMBER(1,0),
  CODCENTRALIZARE NUMBER(20,0),
  COD_CATALOG VARCHAR2(54),
  DENLAPART VARCHAR2(200),
  CODEXTERNLAPART VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRASTAT_NC_OBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2D684902EFE82AD1103FBB612EFDAEA16CE76724</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRASTAT_NC_OBJ (
  COD NUMBER(21,0),
  CODPARINTE NUMBER(21,0),
  CODBUNIC NUMBER(21,0),
  CN VARCHAR2(30),
  DEN_EN VARCHAR2(3000),
  DEN_RO VARCHAR2(3000),
  SU VARCHAR2(30),
  NIVEL NUMBER(2,0),
  AREFII NUMBER(1,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRASTEPTLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A840C71184BEF633AFD809E042B2BEC0A1FDA5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRASTEPTLINK (
  CODINTR1 NUMBER(20,0),
  CODLINIEFACTURA NUMBER(20,0),
  CANT NUMBER(20,7),
  MONEDAFACT NUMBER(20,0),
  CURSFACT NUMBER(20,7),
  PRETFACT NUMBER(20,7),
  TVAFACT NUMBER(20,7),
  DATAFACT DATE,
  CONTFACT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRASTEPTLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B96419CA46E3ED33DA392D37F7EB4EA419B8AB04</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRASTEPTLINK_INITIAL (
  CODINTR1 NUMBER(20,0),
  CODLINIEFACTURA NUMBER(20,0),
  CANT NUMBER(20,7),
  MONEDAFACT NUMBER(20,0),
  CURSFACT NUMBER(20,7),
  PRETFACT NUMBER(20,7),
  TVAFACT NUMBER(20,7),
  DATAFACT DATE,
  CONTFACT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRCADOU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4000832E3FAD68F1CEBD0207EC0AF2B91A6303B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRCADOU (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANTOBIECT NUMBER(20,7),
  CODCADOU NUMBER(20,0),
  CANTCADOU NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0),
  ZECIMALE NUMBER(1,0),
  DENCADOU VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRDISCC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3C0C0A9EDDCEA6E321BD4A023CE07AA7C237B74F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRDISCC (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PJDISC NUMBER(20,7),
  DISCUNITAR NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRDISCV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CB21DB358838C66126A9F1F2118A3A56990C1273</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRDISCV (
  PARTENER NUMBER(20,0),
  LOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  BAZA NUMBER(20,7),
  DISC NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRDOCTRANSP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7BA41DC1F34819035E0396C1F6D09F7098B5446A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRDOCTRANSP (
  COD NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODINTRLINK NUMBER(20,0),
  VALTRANSPORT NUMBER(20,7),
  DEN_PART VARCHAR2(100),
  NRDOCLINK NUMBER(20,0),
  DATADOCLINK DATE,
  PREFIXDOC VARCHAR2(2),
  VOLTOT NUMBER(20,7),
  MASATOT NUMBER(20,7),
  VALTOT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRDOCTRANSP_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>046943A873FCE83A4F484A88963115311B69CBE6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRDOCTRANSP_INI (
  COD NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODINTRLINK NUMBER(20,0),
  VALTRANSPORT NUMBER(20,7),
  DEN_PART VARCHAR2(100),
  NRDOCLINK NUMBER(20,0),
  DATADOCLINK DATE,
  PREFIXDOC VARCHAR2(2),
  VOLTOT NUMBER(20,7),
  MASATOT NUMBER(20,7),
  VALTOT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D0393ABECD6E8566973B3B72F295DCCFA6EB0055</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRLINK (
  CODINTR1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  MONEDAAVIZ NUMBER(20,0),
  CURSAVIZ NUMBER(20,7),
  PRETAVIZ NUMBER(20,7),
  TVAAVIZ NUMBER(20,7),
  CANTAVIZ NUMBER(20,7),
  DATAAVIZ DATE,
  DATACOMANDA DATE,
  ACTUALIZPRET NUMBER(1,0),
  SUBUNITAVIZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>69260D1B859737D6F6A69ED11018A43A225C2BB5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRLINK_INITIAL (
  CODINTR1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRPRODLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E7B73E666D705F843FFE1DCA2EFEC83B531F3DA5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRPRODLINK (
  CODINTR1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0),
  MONEDAAVIZ NUMBER(20,0),
  CURSAVIZ NUMBER(20,7),
  PRETAVIZ NUMBER(20,7),
  TVAAVIZ NUMBER(20,7),
  CANTAVIZ NUMBER(20,7),
  DATAAVIZ DATE,
  DATACOMANDA DATE,
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INTRPRODLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A1403BD27DC3D96CCF4FBB68B613986EB83BA289</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INTRPRODLINK_INITIAL (
  CODINTR1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIEAVIZ NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>523A3A7826C27AB44507961FF33C1E445184AF6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTAR (
  CODINVENTAR NUMBER(20,0),
  NRINVENTAR NUMBER(10,0),
  DATAINVENTAR DATE,
  GESTIUNE NUMBER(20,0),
  RESPONSABIL NUMBER(20,0),
  OBSERVATII VARCHAR2(250),
  TIP NUMBER(1,0),
  DIMINUARE NUMBER(20,0),
  MARIRE NUMBER(20,0),
  FACTURARE NUMBER(20,0),
  IART NUMBER(1,0),
  ITIPCONT NUMBER(1,0),
  SUBUNITATE NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPREZOLVARE NUMBER(10,0),
  FLGPALM NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ICLASE NUMBER(1,0),
  IPROD NUMBER(1,0),
  ICLASES NUMBER(1,0),
  ICLASEW NUMBER(1,0),
  REZDIF NUMBER(1,0),
  MARJA NUMBER(20,7),
  DOCMARIRE VARCHAR2(100),
  DOCDIMINUARE VARCHAR2(100),
  VALSCRIPTIC NUMBER(20,7),
  VALFAPTIC NUMBER(20,7),
  VALMARIRI NUMBER(20,7),
  VALDIMINUARI NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTAR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>82B715CED89FAD06A9FE99988F773F4B7FA8D4E0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTAR1 (
  CODINVENTAR1 NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  SCRIPTIC NUMBER(20,7),
  FAPTIC NUMBER(20,7),
  SCRIPTICUM1 NUMBER(20,7),
  FAPTICUM1 NUMBER(20,7),
  SCRIPTICUM2 NUMBER(20,7),
  FAPTICUM2 NUMBER(20,7),
  EXPIRARE DATE,
  REZOLVAT NUMBER(1,0),
  VALOARE NUMBER(20,7),
  ORDINE NUMBER(20,0),
  UM1 NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPSERIE NUMBER(1,0),
  ARETG NUMBER(1,0),
  SERIE VARCHAR2(75),
  DEN_LOCATIE VARCHAR2(250),
  DEN_OBIECT VARCHAR2(250),
  CODEXTERN VARCHAR2(80),
  DEN_UM VARCHAR2(50),
  DEN_UM1 VARCHAR2(50),
  DEN_UM2 VARCHAR2(50),
  DIFERENTE NUMBER(20,7),
  DIFERENTEUM1 NUMBER(20,7),
  DIFERENTEUM2 NUMBER(20,7),
  REZOLVATUM1 NUMBER(1,0),
  REZOLVATUM2 NUMBER(1,0),
  PRODUCATOR VARCHAR2(200),
  DEN_UMSEC VARCHAR2(50),
  PARITATE NUMBER(15,8),
  CODINTERN VARCHAR2(80),
  TGSTRING VARCHAR2(10),
  CONTIMPLICIT VARCHAR2(60),
  DENUMIRE VARCHAR2(250),
  DEN_CLASEA VARCHAR2(150),
  REZNEGATIVE NUMBER(1,0),
  CODEXTERNLOC VARCHAR2(20),
  CODIOART NUMBER(20,0),
  DEN_CLASEAS VARCHAR2(250),
  SERIED VARCHAR2(75),
  DEN_IOART VARCHAR2(2500),
  CODEXTERNART VARCHAR2(30),
  POZNEGATIVE NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTCLASE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FFD4BD52C667B525C05E8B2561BC2197D8773FCC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTCLASE (
  CODINVENTCLASE NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(150)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTCLASES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6FA5806DE97ECF613B0D0D9AAEA83088A451B608</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTCLASES (
  CODINVENTCLASES NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODCLASEAS NUMBER(20,0),
  DEN_CLASEAS VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTCONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9E58404F73B00275EA3195C29E814AFD6F17402F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTCONT (
  CODINVENTCONT NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODTIPCONT NUMBER(20,0),
  SELECTAT NUMBER(1,0),
  DEN_TIPCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>499879004D1FD7E6847AE555CF4E2B8CFBF774DE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTPROD (
  CODINVENTPROD NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>709F8FD578E918685AE944976B1EF5FD8F88959E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTREZ (
  CODREZOLVARE NUMBER(20,0),
  CODINVENTAR1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  REZOLVAT NUMBER(20,7),
  REZOLVATUM1 NUMBER(20,7),
  REZOLVATUM2 NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  TVA NUMBER(10,7),
  TG TIMESTAMP(6),
  PRETMAXIMAL NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  DATAACHIZ DATE,
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_INVENTSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C30C9539E411588D24BC3E716EC4D726F804C1BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_INVENTSTOC (
  CODINVENTSTOC NUMBER(20,0),
  CODINVENTAR1 NUMBER(20,0),
  CODINVENTAR NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PRET NUMBER(20,7),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  REZERVAT NUMBER(20,7),
  ALTEREZERVARI NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  DEN_IOART VARCHAR2(60)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>25018102E2E6679BE5096EA58A58557956202925</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOA (
  CODIOART NUMBER(20,0),
  MG NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D45D3D8AF527D0DE1A474148E4B741DBB38403F8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOART (
  CODIOART NUMBER(20,0),
  DEN_IOART VARCHAR2(60),
  SIMBOL VARCHAR2(15),
  CODVANZARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOART1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB085AC256F376C09A033A63150D53A5E539BCF4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOART1 (
  CODIOART1 NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CONT NUMBER(20,0),
  DIFERENTE NUMBER(20,0),
  CHELTUIELI NUMBER(20,0),
  VENITURI NUMBER(20,0),
  PLUSINVENTAR NUMBER(20,0),
  MINUSINVENTAR NUMBER(20,0),
  CHELTTVACOLECTAT NUMBER(20,0),
  CONTROTUNJIRI NUMBER(20,0),
  DIVERSE NUMBER(20,0),
  CUSTODIE NUMBER(20,0),
  ACCIZELATRANSFER NUMBER(1,0),
  DESCARCAREG NUMBER(1,0),
  CONTABGEST NUMBER(1,0),
  BAZA NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  TVANEEX VARCHAR2(10),
  MG NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PUSTANDARD NUMBER(1,0),
  PROVIZION NUMBER(20,0),
  CHELTPROVIZION NUMBER(20,0),
  VENITPROVIZION NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOARTDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A37EC8B7599FC5D4A2470526EFB947B7DF1167C9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOARTDEDICATE (
  CODIOART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOARTLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C408EB02BC63ABAFDD208DFBC173834F1FD34907</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOARTLINK (
  CODIOARTLINK NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODMACHETA NUMBER(10,0),
  CODIOARTECHIV NUMBER(20,0),
  DENMACHETA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOART_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>96EB9AA782604E809711AA1AA2B9176064110D9F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOART_LUNA (
  CODIOART1 NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CONT NUMBER(20,0),
  DIFERENTE NUMBER(20,0),
  CHELTUIELI NUMBER(20,0),
  VENITURI NUMBER(20,0),
  PLUSINVENTAR NUMBER(20,0),
  MINUSINVENTAR NUMBER(20,0),
  CHELTTVACOLECTAT NUMBER(20,0),
  CONTROTUNJIRI NUMBER(20,0),
  DIVERSE NUMBER(20,0),
  CUSTODIE NUMBER(20,0),
  ACCIZELATRANSFER NUMBER(1,0),
  DESCARCAREG NUMBER(1,0),
  CONTABGEST NUMBER(1,0),
  BAZA NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  TVANEEX VARCHAR2(10),
  MG NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PUSTANDARD NUMBER(1,0),
  PROVIZION NUMBER(20,0),
  CHELTPROVIZION NUMBER(20,0),
  VENITPROVIZION NUMBER(20,0),
  DEN_IOART VARCHAR2(60),
  ESTEMIFIX NUMBER(1,0),
  ESTEOBINV NUMBER(1,0),
  ESTECUSTODIE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOBANK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4DECCE325683AA651F56E8C66D20222CB010BC48</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOBANK (
  CODIOBANK NUMBER(20,0),
  DEN_IOBANK VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOBANK1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6B4D7FD64ADE1A8A69FC08EF7DF489B25439E30</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOBANK1 (
  CODIOBANK1 NUMBER(30,0),
  CODIOBANK NUMBER(20,0),
  CONT NUMBER(20,0),
  DOBANDA NUMBER(20,0),
  COMISION NUMBER(20,0),
  CHELTUIELICV NUMBER(20,0),
  VENITURICV NUMBER(20,0),
  PCEC NUMBER(20,0),
  PEFECTE NUMBER(20,0),
  PEFECTEREM NUMBER(20,0),
  ICEC NUMBER(20,0),
  IEFECTE NUMBER(20,0),
  IEFECTEREM NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOBANK_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>44FBAEEFE23CB7C2BD7274A44C09B4305C0AFA6B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOBANK_LUNA (
  CODIOBANK1 NUMBER(30,0),
  CODIOBANK NUMBER(20,0),
  CONT NUMBER(20,0),
  DOBANDA NUMBER(20,0),
  COMISION NUMBER(20,0),
  CHELTUIELICV NUMBER(20,0),
  VENITURICV NUMBER(20,0),
  PCEC NUMBER(20,0),
  PEFECTE NUMBER(20,0),
  PEFECTEREM NUMBER(20,0),
  ICEC NUMBER(20,0),
  IEFECTE NUMBER(20,0),
  IEFECTEREM NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOFILIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>024683086679711E994011DF54D74CC317FFF56A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOFILIAL (
  CODIOFILIAL NUMBER(20,0),
  DEN_IOFILIAL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOFILIAL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3072F2DFCF51B4C0678F92457EC7D9F45857FE9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOFILIAL1 (
  CODIOFILIAL1 NUMBER(20,0),
  CODIOFILIAL NUMBER(10,0),
  CONTDECONTARE NUMBER(20,0),
  CONTDECONTSERV NUMBER(20,0),
  CONTDECONTCB NUMBER(20,0),
  CONTDECONTCMP NUMBER(20,0),
  CONTDECONTAREF NUMBER(20,0),
  ISFIRMA NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOFILIAL_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A600E4805229CE6E57751DBDAB45B542A9A0A67</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOFILIAL_LUNA (
  CODIOFILIAL1 NUMBER(20,0),
  CODIOFILIAL NUMBER(10,0),
  CONTDECONTARE NUMBER(20,0),
  CONTDECONTSERV NUMBER(20,0),
  CONTDECONTCB NUMBER(20,0),
  CONTDECONTCMP NUMBER(20,0),
  CONTDECONTAREF NUMBER(20,0),
  ISFIRMA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>70879CAD6BD8EA008D497613D6ACCF4B90F84D62</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPART (
  CODIOPART NUMBER(20,0),
  DEN_IOPART VARCHAR2(30),
  SIMBOL VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPART1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34548CBDC7933CA0C0C114A99BABC34ADDBE5823</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPART1 (
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  CONTSUPLIMF6 NUMBER(20,0),
  CONTSUPLIMF7 NUMBER(20,0),
  CONTSUPLIMF8 NUMBER(20,0),
  CONTSUPLIMF9 NUMBER(20,0),
  CONTSUPLIMF10 NUMBER(20,0),
  CONTSUPLIMF11 NUMBER(20,0),
  CONTSUPLIMF12 NUMBER(20,0),
  CONTSUPLIMF13 NUMBER(20,0),
  CONTSUPLIMF14 NUMBER(20,0),
  CONTSUPLIMF15 NUMBER(20,0),
  CONTSUPLIMF16 NUMBER(20,0),
  CONTSUPLIMF17 NUMBER(20,0),
  CONTSUPLIMF18 NUMBER(20,0),
  CONTSUPLIMF19 NUMBER(20,0),
  CONTSUPLIMF20 NUMBER(20,0),
  CONTSUPLIMF21 NUMBER(20,0),
  CONTSUPLIMF22 NUMBER(20,0),
  CONTSUPLIMF23 NUMBER(20,0),
  CONTSUPLIMF24 NUMBER(20,0),
  CONTSUPLIMF25 NUMBER(20,0),
  CONTSUPLIMF26 NUMBER(20,0),
  CONTSUPLIMF27 NUMBER(20,0),
  CONTSUPLIMF28 NUMBER(20,0),
  CONTSUPLIMF29 NUMBER(20,0),
  CONTSUPLIMF30 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPARTDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DE71E3FCC1A20976E20C772E7767D271A932B1D3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPARTDEDICATE (
  CODIOPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPARTDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A647F4D6F1838FA9B63433F97B828FA185867747</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPARTDOC (
  CODPART NUMBER(20,0),
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPARTLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77F447797E37F1348C3AFB0006EE2CB438F0059E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPARTLUNA (
  CODPART NUMBER(20,0),
  CODPART1 NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  CODIOPART NUMBER(20,0),
  CODIOPART1 NUMBER(20,0),
  DEN_IOPART VARCHAR2(30),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPARTVAMA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3BD83CC0EE1B72D7743DBBA7AF3B503097CAC529</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPARTVAMA (
  CODPART NUMBER(20,0),
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPART_CFGLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0FA8FFEEAB231E7B576EFE36DA67725B7EBBD8F4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPART_CFGLUNA (
  CODIOPART1 NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  CONTCHELTAVANS NUMBER(20,0),
  CONTVENITAVANS NUMBER(20,0),
  CONTGARANTIEEF NUMBER(20,0),
  CONTGARANTIETF NUMBER(20,0),
  CONTGARANTIEEC NUMBER(20,0),
  CONTGARANTIETC NUMBER(20,0),
  CONTSUPLIMF1 NUMBER(20,0),
  CONTSUPLIMF2 NUMBER(20,0),
  CONTSUPLIMF3 NUMBER(20,0),
  CONTSUPLIMF4 NUMBER(20,0),
  CONTSUPLIMF5 NUMBER(20,0),
  CONTSUPLIMC1 NUMBER(20,0),
  CONTSUPLIMC2 NUMBER(20,0),
  CONTSUPLIMC3 NUMBER(20,0),
  CONTSUPLIMC4 NUMBER(20,0),
  CONTSUPLIMC5 NUMBER(20,0),
  CONTSUPLIMF6 NUMBER(20,0),
  CONTSUPLIMF7 NUMBER(20,0),
  CONTSUPLIMF8 NUMBER(20,0),
  CONTSUPLIMF9 NUMBER(20,0),
  CONTSUPLIMF10 NUMBER(20,0),
  CONTSUPLIMF11 NUMBER(20,0),
  CONTSUPLIMF12 NUMBER(20,0),
  CONTSUPLIMF13 NUMBER(20,0),
  CONTSUPLIMF14 NUMBER(20,0),
  CONTSUPLIMF15 NUMBER(20,0),
  CONTSUPLIMF16 NUMBER(20,0),
  CONTSUPLIMF17 NUMBER(20,0),
  CONTSUPLIMF18 NUMBER(20,0),
  CONTSUPLIMF19 NUMBER(20,0),
  CONTSUPLIMF20 NUMBER(20,0),
  CONTSUPLIMF21 NUMBER(20,0),
  CONTSUPLIMF22 NUMBER(20,0),
  CONTSUPLIMF23 NUMBER(20,0),
  CONTSUPLIMF24 NUMBER(20,0),
  CONTSUPLIMF25 NUMBER(20,0),
  CONTSUPLIMF26 NUMBER(20,0),
  CONTSUPLIMF27 NUMBER(20,0),
  CONTSUPLIMF28 NUMBER(20,0),
  CONTSUPLIMF29 NUMBER(20,0),
  CONTSUPLIMF30 NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPART_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3A66FC6CDE98D38D8A93EC2CD8A7FE278F982A0F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPART_LUNA (
  CODPART NUMBER(20,0),
  CODPART1 NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  CODIOPART NUMBER,
  CREDITCLIENT NUMBER(18,2),
  VOLUMTRANZC NUMBER(18,2),
  CREDITFURN NUMBER(18,2),
  VOLUMTRANZF NUMBER(16,2),
  CODIOPART1 NUMBER(20,0),
  DEN_IOPART VARCHAR2(30),
  CONTFURNIZOR NUMBER(20,0),
  CONTCLIENT NUMBER(20,0),
  CONTFURNAVANS NUMBER(20,0),
  CONTCLIENTAVANS NUMBER(20,0),
  CONTFURNAVIZ NUMBER(20,0),
  CONTCLIENTAVIZ NUMBER(20,0),
  CONTFURNMF NUMBER(20,0),
  CONTCREDITD NUMBER(20,0),
  CONTDEBITD NUMBER(20,0),
  CONTLITIGII NUMBER(20,0),
  CONTFURNAVS NUMBER(20,0),
  CONTFURNAVIC NUMBER(20,0),
  CONTFURNAVIN NUMBER(20,0),
  CONTTERTI NUMBER(20,0),
  CONTFURNLEAS NUMBER(20,0),
  CONTNCRF NUMBER(20,0),
  CONTNCRC NUMBER(20,0),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TVANEEXP VARCHAR2(10),
  TVANEEXI VARCHAR2(10),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9EF788E8968D49B92686FF954CC8D958C651822</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPERS (
  CODIOPERS NUMBER(20,0),
  DEN_IOPERS VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPERS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F08158F8A28DEBEC3A49F8F5143FEDD4089AD49</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPERS1 (
  CODIOPERS1 NUMBER(20,0),
  CODIOPERS NUMBER(20,0),
  CONTAVANSDECONT NUMBER(20,0),
  CONTIMPUTATII NUMBER(20,0),
  CONTGARANTII NUMBER(20,0),
  CONTALTERETINERI NUMBER(20,0),
  CONTAVANS NUMBER(20,0),
  CONTLIKI NUMBER(20,0),
  CONTNERIDICATE NUMBER(20,0),
  CONTBOALA NUMBER(20,0),
  CONTPARTSAL NUMBER(20,0),
  CONTNATURA NUMBER(20,0),
  CONTECHIPAMENT NUMBER(20,0),
  CONTIMPOZIT NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPERS_CFGLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>663DCCC8EE808F020C00E55AE6808798E142AA02</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPERS_CFGLUNA (
  CODIOPERS1 NUMBER(20,0),
  CODIOPERS NUMBER(20,0),
  CONTAVANSDECONT NUMBER(20,0),
  CONTIMPUTATII NUMBER(20,0),
  CONTGARANTII NUMBER(20,0),
  CONTALTERETINERI NUMBER(20,0),
  CONTAVANS NUMBER(20,0),
  CONTLIKI NUMBER(20,0),
  CONTNERIDICATE NUMBER(20,0),
  CONTBOALA NUMBER(20,0),
  CONTPARTSAL NUMBER(20,0),
  CONTNATURA NUMBER(20,0),
  CONTECHIPAMENT NUMBER(20,0),
  CONTIMPOZIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_IOPERS_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F4605C5223944F794B2104DA778EC6FB35102C2A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_IOPERS_LUNA (
  CODPERS NUMBER(20,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  DEN_IOPERS VARCHAR2(30),
  CODIOPERS1 NUMBER(20,0),
  CODIOPERS NUMBER(20,0),
  CONTAVANSDECONT NUMBER(20,0),
  CONTIMPUTATII NUMBER(20,0),
  CONTGARANTII NUMBER(20,0),
  CONTALTERETINERI NUMBER(20,0),
  CONTAVANS NUMBER(20,0),
  CONTLIKI NUMBER(20,0),
  CONTNERIDICATE NUMBER(20,0),
  CONTBOALA NUMBER(20,0),
  CONTPARTSAL NUMBER(20,0),
  CONTNATURA NUMBER(20,0),
  CONTECHIPAMENT NUMBER(20,0),
  CONTIMPOZIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JC_AUX1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>05D46871E6DC3383C768D1416B2BBBC5BBA6DA5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JC_AUX1 (
  NAV_CODDOC NUMBER(30,7),
  NAV_TIPDOC NUMBER(30,7),
  COEFDOC NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JC_D300</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>190CACF510AC1CE8895A4E80546A845CE1BF7029</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JC_D300 (
  NAV_CODDOC NUMBER(30,7),
  NAV_CODDOC1 NUMBER(30,7),
  NAV_TIPDOC NUMBER(30,7),
  ORDDOC NUMBER(30,7),
  PREFIXDOC VARCHAR2(30),
  TIPDOC VARCHAR2(30),
  NRDOC VARCHAR2(20),
  NRI VARCHAR2(50),
  DATADOC DATE,
  SERIADOC VARCHAR2(20),
  DEN_PART VARCHAR2(200),
  CODFISCAL VARCHAR2(100),
  VALDOC NUMBER(30,7),
  BAZA_MAX NUMBER(30,7),
  TVA_MAX NUMBER(30,7),
  BAZA_MED NUMBER(30,7),
  TVA_MED NUMBER(30,7),
  BAZA_MIN NUMBER(30,7),
  TVA_MIN NUMBER(30,7),
  BAZA_REGMAX NUMBER(30,7),
  TVA_REGMAX NUMBER(30,7),
  BAZA_REGMIN NUMBER(30,7),
  TVA_REGMIN NUMBER(30,7),
  BAZA_REG NUMBER(30,7),
  TVA_REG NUMBER(30,7),
  BAZA_REG2 NUMBER(30,7),
  TVA_REG2 NUMBER(30,7),
  BAZA_REG3 NUMBER(30,7),
  TVA_REG3 NUMBER(30,7),
  BAZA_REG4 NUMBER(30,7),
  TVA_REG4 NUMBER(30,7),
  BAZA_REG5 NUMBER(30,7),
  TVA_REG5 NUMBER(30,7),
  TVA_0 NUMBER(30,7),
  AICB_BAZA NUMBER(30,7),
  AICB_TVA NUMBER(30,7),
  AICB_SCUT NUMBER(30,7),
  AICB_NEIMP NUMBER(30,7),
  AICS_SCUT NUMBER(30,7),
  AICS_NEIMP NUMBER(30,7),
  RS315_BAZA NUMBER(30,7),
  RS315_TVA NUMBER(30,7),
  BS150_BAZA NUMBER(30,7),
  BS150_TVA NUMBER(30,7),
  BS160_BAZA NUMBER(30,7),
  BS160_TVA NUMBER(30,7),
  BS160_BMAX NUMBER(30,7),
  BS160_TMAX NUMBER(30,7),
  BS160_BMIN NUMBER(30,7),
  BS160_TMIN NUMBER(30,7),
  BS160_BMED NUMBER(30,7),
  BS160_TMED NUMBER(30,7),
  BS160_BREG NUMBER(30,7),
  BS160_TREG NUMBER(30,7),
  BS160_BREG2 NUMBER(30,7),
  BS160_TREG2 NUMBER(30,7),
  BS160_BREG3 NUMBER(30,7),
  BS160_TREG3 NUMBER(30,7),
  BS160_BREG4 NUMBER(30,7),
  BS160_TREG4 NUMBER(30,7),
  BS160_BREG5 NUMBER(30,7),
  BS160_TREG5 NUMBER(30,7),
  PRORATA NUMBER(30,7),
  TVAN_MAX NUMBER(30,7),
  TVAN_MED NUMBER(30,7),
  TVAN_MIN NUMBER(30,7),
  TVAN_REG NUMBER(30,7),
  TVAN_REG2 NUMBER(30,7),
  TVAN_REG3 NUMBER(30,7),
  TVAN_REG4 NUMBER(30,7),
  TVAN_REG5 NUMBER(30,7),
  TVANEDED NUMBER(30,7),
  TVANPRORATA NUMBER(30,7),
  TVAMPRORATA NUMBER(30,7),
  OBS VARCHAR2(500),
  SUBUNITATE VARCHAR2(100),
  UE VARCHAR2(2),
  TI VARCHAR2(2),
  DATACDOC DATE,
  OPERATOR VARCHAR2(300),
  ANDOC NUMBER(30,7),
  LUNADOC NUMBER(30,7),
  TVALAINC VARCHAR2(2),
  TVALAINCF VARCHAR2(2),
  RESTOL NUMBER(30,7),
  BAZAOBLIG NUMBER(30,7),
  TVANOBLIG NUMBER(30,7),
  PLATAPREFIX VARCHAR2(30),
  PLATATIP VARCHAR2(30),
  PLATANR VARCHAR2(20),
  PLATADATA DATE,
  PLATAVAL NUMBER(30,7),
  PLATAVFT NUMBER(30,7),
  PLATATVA NUMBER(30,7),
  RESTVAL NUMBER(30,7),
  RESTTVA NUMBER(30,7),
  SOLDVAL NUMBER(30,7),
  SOLDTVA NUMBER(30,7),
  DOCVAL NUMBER(30,7),
  DOCBAZA NUMBER(30,7),
  DOCTVA NUMBER(30,7),
  TIPTVADOC VARCHAR2(50),
  TVA_RET NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JOBCOREL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54578491ECE58CF501E26D0EC628C37BB5C17B14</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JOBCOREL (
  CODCOREL NUMBER(20,0),
  CODJOB NUMBER(20,0),
  CODJOB1_1 NUMBER(20,0),
  TABLA1 VARCHAR2(50),
  LOOKUPFIELD1 VARCHAR2(50),
  VALDESCRIP1 VARCHAR2(100),
  CODJOB1_2 NUMBER(20,0),
  TABLA2 VARCHAR2(50),
  LOOKUPFIELD2 VARCHAR2(50),
  VALDESCRIP2 VARCHAR2(100),
  STARE NUMBER(2,0),
  ZECIMALE NUMBER(2,0),
  LOOKUPFIELD11 VARCHAR2(50),
  LOOKUPFIELD21 VARCHAR2(50),
  DEN_LISTA1 VARCHAR2(150),
  DEN_LISTA2 VARCHAR2(150)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JOBCORELREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0DBD2A546B22F6235B1A072D4652CCC0CAC98894</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JOBCORELREZ (
  CODCORELREZ NUMBER(20,0),
  CODCOREL NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(300),
  VALOARE1 NUMBER(20,7),
  VALOARE2 NUMBER(20,7),
  DIFERENTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JOBLISTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD0BAA57DC838ACFAC160727FF27E2C3424FF07C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JOBLISTE (
  CODJOB NUMBER(20,0),
  USERID NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODORAR NUMBER(20,0),
  TIPJOB NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  NEWDEPO NUMBER(1,0),
  WEBSERVER NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JOBLISTE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>595B5123A94D41E2308F84E27BA9A7BA1FFCEE96</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JOBLISTE1 (
  CODJOB1 NUMBER(20,0),
  CODJOB NUMBER(20,0),
  LISTAID NUMBER(20,0),
  LISTAVER NUMBER(10,0),
  TIPEXECUTIE NUMBER(1,0),
  DATAEXECUTIE TIMESTAMP(6),
  PERIOADA NUMBER(10,0),
  EXECUTATA NUMBER(1,0),
  PRINTARE NUMBER(1,0),
  ACTION NUMBER(37,0),
  FISIER_EXPORT VARCHAR2(200),
  EXPORT NUMBER(1,0),
  OBS VARCHAR2(3000),
  ACTIV NUMBER(1,0),
  ARECONFIG NUMBER(1,0),
  TIPINTERVAL NUMBER(1,0),
  TABLA VARCHAR2(200),
  EMAIL VARCHAR2(200),
  JOBID NUMBER(20,0),
  ORAEXECUTIE VARCHAR2(5),
  DEN_LISTA VARCHAR2(150)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JOBLISTECONFIG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>29E2B57E7BF3474B671E4801B045F585F706145A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JOBLISTECONFIG (
  CODJOBCONFIG NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  FILENAME VARCHAR2(100),
  FILECONFIG BLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F18F26FCD07B89E48CFDF4E7506F291BA7B6D1EA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNAL (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNAL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>385D8970C30C2292E6816CDC82DD45DA72CA59BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNAL1 (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(20,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNAL1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>56DB13ABC3580A1E3A0C784C7A7F54F462AA7623</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNAL1_MAN (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(20,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNALS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0F36A7D309525F3C92360C8C1D967709ABA022A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNALS (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNALS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>79EA4475A6D783B3CF354CA6774F7136363D2650</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNALS1 (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(5,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(5,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JURNAL_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C939F7A68838B10DCD32529A06D88D3D5896E819</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JURNAL_MAN (
  CODJURNAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(35),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JV_D300</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BEE89F026A9933C30CB6B8E0D25CD81430FA55A2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JV_D300 (
  NAV_CODDOC NUMBER(30,7),
  NAV_CODDOC1 NUMBER(30,7),
  NAV_TIPDOC NUMBER(30,7),
  ORDDOC NUMBER(30,7),
  DATADOC DATE,
  NRDOC NUMBER(30,7),
  NRI VARCHAR2(50),
  PREFIXDOC VARCHAR2(30),
  SERIADOC VARCHAR2(20),
  DEN_PART VARCHAR2(100),
  CODFISCAL VARCHAR2(100),
  VALDOC NUMBER(30,7),
  BAZA_MAX NUMBER(30,7),
  TVA_MAX NUMBER(30,7),
  BAZA_MED NUMBER(30,7),
  TVA_MED NUMBER(30,7),
  BAZA_MIN NUMBER(30,7),
  TVA_MIN NUMBER(30,7),
  BAZA_REGMAX NUMBER(30,7),
  TVA_REGMAX NUMBER(30,7),
  BAZA_REGMIN NUMBER(30,7),
  TVA_REGMIN NUMBER(30,7),
  BAZA_REG NUMBER(30,7),
  TVA_REG NUMBER(30,7),
  BAZA_REG2 NUMBER(30,7),
  TVA_REG2 NUMBER(30,7),
  BAZA_REG3 NUMBER(30,7),
  TVA_REG3 NUMBER(30,7),
  BAZA_REG4 NUMBER(30,7),
  TVA_REG4 NUMBER(30,7),
  BAZA_REG5 NUMBER(30,7),
  TVA_REG5 NUMBER(30,7),
  BUNURI_CU_TI NUMBER(30,7),
  TVA_BUNURI_CU_TI NUMBER(30,7),
  BUNURI_CU_TI_BMAX NUMBER(30,7),
  BUNURI_CU_TI_TMAX NUMBER(30,7),
  BUNURI_CU_TI_BMED NUMBER(30,7),
  BUNURI_CU_TI_TMED NUMBER(30,7),
  BUNURI_CU_TI_BMIN NUMBER(30,7),
  BUNURI_CU_TI_TMIN NUMBER(30,7),
  BUNURI_CU_TI_BREG NUMBER(30,7),
  BUNURI_CU_TI_TREG NUMBER(30,7),
  BUNURI_CU_TI_BREG2 NUMBER(30,7),
  BUNURI_CU_TI_TREG2 NUMBER(30,7),
  BUNURI_CU_TI_BREG3 NUMBER(30,7),
  BUNURI_CU_TI_TREG3 NUMBER(30,7),
  BUNURI_CU_TI_BREG4 NUMBER(30,7),
  BUNURI_CU_TI_TREG4 NUMBER(30,7),
  BUNURI_CU_TI_BREG5 NUMBER(30,7),
  BUNURI_CU_TI_TREG5 NUMBER(30,7),
  NONRO_DED NUMBER(30,7),
  SERV_NONRO_DED NUMBER(30,7),
  NONRO_NONDED NUMBER(30,7),
  SERV_NONRO_NONDED NUMBER(30,7),
  RO_DED NUMBER(30,7),
  RO_NONDED NUMBER(30,7),
  A_1521_22 NUMBER(30,7),
  TVA_A_311_322 NUMBER(30,7),
  ART143AD NUMBER(30,7),
  ART143BC NUMBER(30,7),
  SERV143BC NUMBER(30,7),
  ART294AB NUMBER(30,7),
  ART294CD NUMBER(30,7),
  ART292 NUMBER(30,7),
  OPER_NEIMP NUMBER(30,7),
  OBS VARCHAR2(500),
  SUBUNITATEA VARCHAR2(150),
  UE VARCHAR2(2),
  TI VARCHAR2(2),
  DATACDOC DATE,
  OPERATOR VARCHAR2(300),
  ANDOC NUMBER(30,7),
  LUNADOC NUMBER(30,7),
  TVALAINC VARCHAR2(2),
  RESTOL NUMBER(30,7),
  BAZAOBLIG NUMBER(30,7),
  TVANOBLIG NUMBER(30,7),
  INCPREFIX VARCHAR2(30),
  INCTIP VARCHAR2(30),
  INCNR VARCHAR2(20),
  INCDATA DATE,
  INCVAL NUMBER(30,7),
  INCVFT NUMBER(30,7),
  INCTVA NUMBER(30,7),
  RESTVAL NUMBER(30,7),
  RESTTVA NUMBER(30,7),
  SOLDVAL NUMBER(30,7),
  SOLDTVA NUMBER(30,7),
  DOCVAL NUMBER(30,7),
  DOCBAZA NUMBER(30,7),
  DOCTVA NUMBER(30,7),
  TIPTVADOC VARCHAR2(50),
  BAZA_SERV_278 NUMBER(30,7),
  TVA_SERV_278 NUMBER(30,7),
  BAZA_OSS NUMBER(30,7),
  TVA_OSS NUMBER(30,7),
  A_311_322_BMAX NUMBER(30,7),
  A_311_322_TMAX NUMBER(30,7),
  A_311_322_BMED NUMBER(30,7),
  A_311_322_TMED NUMBER(30,7),
  A_311_322_BMIN NUMBER(30,7),
  A_311_322_TMIN NUMBER(30,7),
  A_311_322_BREG NUMBER(30,7),
  A_311_322_TREG NUMBER(30,7),
  A_311_322_BREG2 NUMBER(30,7),
  A_311_322_TREG2 NUMBER(30,7),
  A_311_322_BREG3 NUMBER(30,7),
  A_311_322_TREG3 NUMBER(30,7),
  A_311_322_BREG4 NUMBER(30,7),
  A_311_322_TREG4 NUMBER(30,7),
  A_311_322_BREG5 NUMBER(30,7),
  A_311_322_TREG5 NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_JV_DISCIES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0583694A47EF9A32D0092D56E4806933B609FB31</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_JV_DISCIES (
  CODIES1 NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  VALD NUMBER(20,7),
  TVAD NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_KM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C6E9FEEB5F93F9A9BFE12B4ED9A7A44D47B20FD8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_KM1 (
  CODNPARCAUT NUMBER(20,0),
  FIRST_KM NUMBER(10,0),
  LAST_KM NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D1D3F850C159BE6D73393F0E6DD430736E9FFBC5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE (
  CODLANSARE NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  CANT NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  ANULAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  AUTOMAT NUMBER(1,0),
  CODSCENARIU NUMBER(20,0),
  OBS VARCHAR2(450),
  CLIENT VARCHAR2(200),
  NRCMD NUMBER(20,0),
  DATACMD DATE,
  DENOBIECT VARCHAR2(200),
  ACCEPTAT NUMBER(20,7),
  TERMENLIVRARE DATE,
  REZOLVAT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CARNETDOCCOMINT NUMBER(20,0),
  NRDOCCOMINT NUMBER(20,0),
  SERIADOCCOMINT VARCHAR2(20),
  CARNETDOCCOMFURN NUMBER(20,0),
  NRDOCCOMFURN NUMBER(20,0),
  SERIADOCCOMFURN VARCHAR2(20),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODGEST NUMBER(20,0),
  VERSIUNE VARCHAR2(250),
  DEN_SCENARIU VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1011C060F5EC3FCE5B5EFC681BD9832EBCCDAD4E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE0 (
  CODLANSARE0 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  CODSCENARIU NUMBER(20,0),
  TERMEN DATE,
  CANTUM1 NUMBER(20,7),
  PRODUS VARCHAR2(200),
  CANTACCEPTAT NUMBER(20,7),
  RESTLANSAT NUMBER(20,7),
  PROIECT VARCHAR2(100),
  SCENARIU VARCHAR2(50),
  CLIENT VARCHAR2(100),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  TERMENLIVRARE DATE,
  CODEXTERN VARCHAR2(80),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  CODUM1 NUMBER(20,0),
  PARITATED1 NUMBER(12,7),
  PARITATED2 NUMBER(12,7),
  PARITATED3 NUMBER(12,7),
  OBS VARCHAR2(500),
  OBSARTICOL VARCHAR2(200),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7B24FC3E59B3011BFC26A27C936E36DE92B70185</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE1 (
  CODLANSARE1 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODREZERVATS NUMBER(20,0),
  CODLANSARE0 NUMBER(20,0),
  OBS VARCHAR2(500),
  NODPARINTE NUMBER(20,0),
  CODCMD1P NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  DENRETETA VARCHAR2(200),
  GESTIUNE VARCHAR2(200),
  NRCMD NUMBER(20,0),
  DATACMD DATE,
  CANTREZERVAT NUMBER(20,7),
  COMANDA VARCHAR2(100),
  UM VARCHAR2(50),
  CODCMD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENLOCATIE VARCHAR2(30),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4194357C67622BF50B61A2B207400F530CD234EE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE2 (
  CODLANSARE1 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODREZERVATS NUMBER(20,0),
  CODLANSARE0 NUMBER(20,0),
  OBS VARCHAR2(500),
  NODPARINTE NUMBER(20,0),
  CODCMD1P NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  DENRETETA VARCHAR2(200),
  GESTIUNE VARCHAR2(200),
  NRCMD NUMBER(20,0),
  DATACMD DATE,
  CANTREZERVAT NUMBER(20,7),
  COMANDA VARCHAR2(100),
  UM VARCHAR2(50),
  CODCMD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENLOCATIE VARCHAR2(30),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>757A29079E9E50DA57977F9641D22482CADA6B20</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE3 (
  CODLANSARE1 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODREZERVATS NUMBER(20,0),
  CODLANSARE0 NUMBER(20,0),
  OBS VARCHAR2(500),
  NODPARINTE NUMBER(20,0),
  CODCMD1P NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  DENRETETA VARCHAR2(200),
  GESTIUNE VARCHAR2(200),
  NRCMD NUMBER(20,0),
  DATACMD DATE,
  CANTREZERVAT NUMBER(20,7),
  COMANDA VARCHAR2(100),
  UM VARCHAR2(50),
  CODCMD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENLOCATIE VARCHAR2(30),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARE4</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BFBF0E4F0BDEE711943B3697E02D0CAEC549A405</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARE4 (
  CODLANSARE1 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  TIP NUMBER(1,0),
  CODCMD1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODREZERVATS NUMBER(20,0),
  CODLANSARE0 NUMBER(20,0),
  OBS VARCHAR2(500),
  NODPARINTE NUMBER(20,0),
  CODCMD1P NUMBER(20,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  DENRETETA VARCHAR2(200),
  GESTIUNE VARCHAR2(200),
  NRCMD NUMBER(20,0),
  DATACMD DATE,
  CANTREZERVAT NUMBER(20,7),
  COMANDA VARCHAR2(100),
  UM VARCHAR2(50),
  CODCMD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENLOCATIE VARCHAR2(30),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(80),
  PRODUS NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  UMSPEC VARCHAR2(50),
  CANTUM1 NUMBER(20,7),
  STOC NUMBER(20,7),
  RESTCMDF NUMBER(20,7),
  RESTCMDI NUMBER(20,7),
  RESTCMDC NUMBER(20,7),
  LANSAT NUMBER(20,7),
  STOCMIN NUMBER(20,7),
  INDEXPARINTE VARCHAR2(50),
  CANTBC NUMBER(20,0),
  PRELUAT NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSARENEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F491B6B109488E43A49B16F17AAA3D2888FA7A3F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSARENEC (
  CODLANSARE0 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CANT NUMBER(20,7),
  NECESARP NUMBER(20,7),
  NECESAR NUMBER(20,7),
  REZOLVAT NUMBER(20,7),
  REZERVAT NUMBER(20,7),
  NESOSIT NUMBER(20,7),
  RESTREZERVAT NUMBER(20,7),
  RESTNESOSIT NUMBER(20,7),
  TOTREZERVAT NUMBER(20,7),
  TOTNESOSIT NUMBER(20,7),
  STOC NUMBER(20,7),
  CMDINT NUMBER(20,7),
  DIFERENTE NUMBER(20,7),
  PARITATEECHIV NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D41BDB0BCFBFE0A1A9D8265B1BEA9A69D0CD92AB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSGEST (
  CODLANSGEST NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  NRSCHIMBURI NUMBER(5,0),
  CAPACITATE NUMBER(10,0),
  INCARCARE NUMBER(10,0),
  INCARCARER NUMBER(10,0),
  DEN_GEST VARCHAR2(100),
  SIMBOL VARCHAR2(15),
  ORESCHIMB NUMBER(4,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A7B2C1520161AF2C1D0B62D8F2925BE57B848E99</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSPROD (
  CODLANSPROD NUMBER(20,0),
  SAPTAMANA NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  OBS VARCHAR2(250),
  DIRTY NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  DEN_SUBUNIT VARCHAR2(100),
  TOTALVAL NUMBER(20,7),
  TOTALVALACC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSPROD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BBA25C5C77D8F6832AA80B80281A64E0E71D8415</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSPROD1 (
  CODLANSPROD1 NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTCOMANDATF NUMBER(20,7),
  STOC NUMBER(20,7),
  CANTLANSAT NUMBER(20,7),
  STOCESTIMAT NUMBER(20,7),
  STOCOPTIM NUMBER(20,7),
  CANTCOMANDATN NUMBER(20,7),
  NECESAR NUMBER(20,7),
  OBS VARCHAR2(250),
  NECESART NUMBER(20,7),
  PREDARI NUMBER(20,7),
  PRET NUMBER(20,7),
  COEFUM NUMBER(20,7),
  VALOARE NUMBER(20,7),
  VALOAREACC NUMBER(20,7),
  CODGEST NUMBER(20,0),
  TIMPEST NUMBER(20,7),
  RESTD NUMBER(20,7),
  EXCLUS NUMBER(1,0),
  STOCMAX NUMBER(20,7),
  ACCPREV NUMBER(20,7),
  AVGSPI NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  DENUM VARCHAR2(15),
  DEN_CLASEAS VARCHAR2(50),
  DEN_GEST VARCHAR2(100),
  SIMBOL VARCHAR2(15),
  CULOARE NUMBER(8,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSPROD2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C94B80FE8D5F589704AD87A03BF0F3D7E7B534C9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSPROD2 (
  CODLANSPROD2 NUMBER(20,0),
  CODLANSPROD1 NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CANT NUMBER(20,7),
  TIMP NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSPROD2S</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1CD0D1CE244FFCB550289D108E5825EC85A8C9A3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSPROD2S (
  CODLANSPROD2S NUMBER(20,0),
  CODLANSPROD1 NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  TIMPEST NUMBER(20,7),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>978D32EED2DC493F71121B97BB44191DC4DCB8C8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSZ (
  CODLANSZ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  OPERAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OBS VARCHAR2(250),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SAPTAMANA NUMBER(10,0),
  DIRTY NUMBER(1,0),
  FINALIZAT NUMBER(1,0),
  ALLGEST NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  CARNETDOCCOMINT NUMBER(20,0),
  NRDOCCOMINT NUMBER(20,0),
  SERIADOCCOMINT VARCHAR2(20),
  NOI NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LANSZ1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>163D1838742E503FFFECEB8E90BCA9596BA2779A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LANSZ1 (
  CODLANSZ1 NUMBER(20,0),
  CODLANSZ NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  LUNI NUMBER(20,7),
  MARTI NUMBER(20,7),
  MIERCURI NUMBER(20,7),
  JOI NUMBER(20,7),
  VINERI NUMBER(20,7),
  SAMBATA NUMBER(20,7),
  DUMINICA NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  CODPLANIFNOD NUMBER(20,0),
  CODCMD1_LUNI NUMBER(20,0),
  CODCMD1_MARTI NUMBER(20,0),
  CODCMD1_MIERCURI NUMBER(20,0),
  CODCMD1_JOI NUMBER(20,0),
  CODCMD1_VINERI NUMBER(20,0),
  CODCMD1_SAMBATA NUMBER(20,0),
  CODCMD1_DUMINICA NUMBER(20,0),
  TOTAL NUMBER(20,7),
  LASTWEEK NUMBER(20,7),
  TOTALDELANSAT NUMBER(20,7),
  TOTALLANSAT NUMBER(20,7),
  REPORT NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  LANS_LUNI NUMBER(20,7),
  LANS_MARTI NUMBER(20,7),
  LANS_MIERCURI NUMBER(20,7),
  LANS_JOI NUMBER(20,7),
  LANS_VINERI NUMBER(20,7),
  LANS_SAMBATA NUMBER(20,7),
  LANS_DUMINICA NUMBER(20,7),
  ALTE NUMBER(20,7),
  RESTDELANSAT NUMBER(20,7),
  CODPRODCOMP NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  DEN_CLASEPROD VARCHAR2(50),
  ORDINE NUMBER(5,0),
  CODPLANIFPROD NUMBER(20,0),
  RETETA VARCHAR2(250),
  DEN_CLASEAS VARCHAR2(50),
  GESTIMPLICITA VARCHAR2(100),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  CODNORMA NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODGEST NUMBER(20,0),
  GESTRETETA VARCHAR2(100),
  REPORTALTE NUMBER(20,7),
  DIRTY NUMBER(10,0),
  DIRTYINI NUMBER(10,0),
  ISOK NUMBER(1,0),
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(50),
  STOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LASTPRETACHIZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D7F0E5C810E1E963AF2E78804B5D3E1C4A3D59B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LASTPRETACHIZ (
  CODOBIECT NUMBER(20,0),
  PRETACHIZ NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LEVEL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3C8037367CC1ACF35221D03657C48C82B9A61DC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LEVEL1 (
  SIMBOL VARCHAR2(300),
  NIVEL_1 VARCHAR2(50),
  NIVEL_2 VARCHAR2(50),
  NIVEL_3 VARCHAR2(50),
  NIVEL_4 VARCHAR2(50),
  NIVEL_5 VARCHAR2(50),
  NIVEL_6 VARCHAR2(50),
  NIVEL_7 VARCHAR2(50),
  NIVEL_8 VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LINIICODIF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>33936757853FD8A4CCF74995E60F978A34F8B802</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LINIICODIF (
  OLDCODE NUMBER(20,0),
  NEWCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIPSA_CORESP_PLANP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CB751BE34A1E5324F1BCCB0D58E6D785852EC26</HASHVAL>
  <TEXT>CREATE TABLE TMP_LIPSA_CORESP_PLANP (
  SIMBOL VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>92DC72F592AD5573CD3774CAA66DE0E3B70D6AC9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA (
  CODCONT NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_BRUT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>49378FD4EBE4490A20791E6205C0F1EB9D41135F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_BRUT (
  CODCONT NUMBER(20,0),
  CODCOMUN NUMBER(20,0),
  SIMBOLPLANP VARCHAR2(100),
  OFFSET NUMBER(1,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJGRUP NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_IFRS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3C32FEDDD6D396AEC1D9F57FB7913C3116296509</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_IFRS (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D1430088F0DDFCBD4DD825AFA43AAD07311607CA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SEC (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SECF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E492CE55F699F8526FBB4DBA8D78008E679E4AF2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SECF (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SECFP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>365342220260FC47D309F319D2B1E171CB9D33F9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SECFP (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SECI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CCFA673D1AD913348B395D6A66154B0C5BEC8012</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SECI (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SECIP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FE9D1DCC9AF84B4614F26E7706F9E86DBC10168E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SECIP (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALANTA_SEC_PREC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF69FA27C1BEADEA2A3AE704606F81652A9CF145</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALANTA_SEC_PREC (
  CODCONT NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  TOTALCPD NUMBER(20,3),
  TOTALCPC NUMBER(20,3),
  RULAJD NUMBER(20,3),
  RULAJC NUMBER(20,3),
  RULAJIFRS NUMBER(20,3),
  RULAJGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  TOTALCD NUMBER(20,3),
  TOTALCC NUMBER(20,3),
  SOLDFD NUMBER(20,3),
  SOLDFC NUMBER(20,3),
  SOLDFIFRS NUMBER(20,3),
  SOLDFGRUP NUMBER(20,3),
  INDEX_SINTETIC NUMBER(10,0),
  FRUNZA NUMBER(1,0),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  SIMBOLSITFIN VARCHAR2(50),
  SIMBPLANP VARCHAR2(3200),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDFIFRSD NUMBER(20,3),
  SOLDFIFRSC NUMBER(20,3),
  RULAJIFRSD NUMBER(20,3),
  RULAJIFRSC NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  SOLDIIFRSD NUMBER(20,3),
  SOLDIIFRSC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_BALCUMUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1468DA820CA87F8F84BDC5B0BCB57728C06BCFE4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_BALCUMUL (
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  TIPCONT NUMBER(1,0),
  BALSINT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDIIFRS NUMBER(20,3),
  SOLDVIIFRS NUMBER(20,3),
  SOLDIGRUP NUMBER(20,3),
  SOLDVIGRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJPIFRS NUMBER(20,3),
  RULAJVPIFRS NUMBER(20,3),
  RULAJPIFRSD NUMBER(20,3),
  RULAJVPIFRSD NUMBER(20,3),
  RULAJPIFRSC NUMBER(20,3),
  RULAJVPIFRSC NUMBER(20,3),
  RULAJPGRUP NUMBER(20,3),
  RULAJVPGRUP NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJCIFRS NUMBER(20,3),
  RULAJVCIFRS NUMBER(20,3),
  RULAJCIFRSD NUMBER(20,3),
  RULAJVCIFRSD NUMBER(20,3),
  RULAJCIFRSC NUMBER(20,3),
  RULAJVCIFRSC NUMBER(20,3),
  RULAJCGRUP NUMBER(20,3),
  RULAJVCGRUP NUMBER(20,3),
  SIMBSINT VARCHAR2(100),
  CODCONT NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  CODSINT NUMBER(20,0),
  DEN_CONT VARCHAR2(200),
  NRANALITICE NUMBER(3,0),
  VIZIBILBALANTA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_CENTRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6117C3FF80C90FEC0EEB810255C7914A15E83745</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_CENTRSTOC (
  ARTICOL VARCHAR2(100),
  STOC NUMBER(20,7),
  CLASA VARCHAR2(100),
  UM VARCHAR2(10),
  VALPRETI NUMBER(20,7),
  VALPRETA NUMBER(20,7),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_COLS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EEB913841B3DAAA48BBF163BDF17003CCA4DA409</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_COLS (
  LISTA VARCHAR2(50),
  TABLA VARCHAR2(50),
  COLOANA VARCHAR2(50),
  TIPCOL VARCHAR2(50),
  LUNGIME NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_COMPENS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E041A0909AB493E661F5254F7230833CE878161F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_COMPENS (
  CODDOC NUMBER(20,0),
  IDX NUMBER(20,0),
  EXPLD VARCHAR2(350),
  PARTD VARCHAR2(100),
  CODPARTD NUMBER(20,0),
  CODCONTD NUMBER(20,0),
  VALD NUMBER(30,7),
  RESTD NUMBER(30,7),
  CURSD NUMBER(30,7),
  TVAD NUMBER(30,7),
  PROVIZIOND NUMBER(30,7),
  PREFIXDOCD VARCHAR2(50),
  NRDOCD NUMBER(20,0),
  DATADOCD DATE,
  EXPLC VARCHAR2(350),
  PARTC VARCHAR2(100),
  CODPARTC NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  VALC NUMBER(30,7),
  RESTC NUMBER(30,7),
  CURSC NUMBER(30,7),
  TVAC NUMBER(30,7),
  PROVIZIONC NUMBER(30,7),
  PREFIXDOCC VARCHAR2(50),
  NRDOCC NUMBER(20,0),
  DATADOCC DATE,
  CODOBLIGSTINSD NUMBER(20,0),
  CODOBLIGSTINSC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_DISPLIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E1222F65AECBAE5F73826E405DD682B49F215853</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_DISPLIVR (
  CODLIVRTOT NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIESINT1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  GEST NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(20,7),
  DENOBIECT VARCHAR2(100),
  DENGESTIOART VARCHAR2(100),
  STOCREZOLVAT NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  GESTIMPLICITA NUMBER(20,0),
  VALTOT NUMBER(20,7),
  FURNIZOR VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_DURATAMED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10944DD218479FC708962502DC2B4F15FA475A6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_DURATAMED (
  CODDOC NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  DOC VARCHAR2(200),
  INITIALIZARI NUMBER(1,0),
  DATADOC DATE,
  CODCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  SOLDINI NUMBER(20,7),
  SOLDFIN NUMBER(20,7),
  SOLDINIT NUMBER(20,7),
  SOLDFINT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_EMULARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CACE8224C293D7B408DDFEC968033F86DC242804</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_EMULARE (
  ID NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  NRBON NUMBER(20,0),
  DATABON DATE,
  VALOARE NUMBER(20,7),
  VALOAREDISCOUNT NUMBER(20,7),
  LISTAT NUMBER(1,0),
  PRELUAT NUMBER(1,0),
  CODCASAMARCAT NUMBER(20,0),
  TVATOTAL NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  TIPCASAMARCAT NUMBER(5,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATALISTARE TIMESTAMP(6),
  CODIES NUMBER(20,0),
  CODPART NUMBER(20,0),
  INCASARECLIENT NUMBER(1,0),
  CODMONETAR NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODPOSTRETAIL NUMBER(20,0),
  CODAECUSTODIE NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODRESTNP NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTSIMPLIF NUMBER(1,0),
  IDBON NUMBER,
  FACTURARE NUMBER(1,0),
  DELEGAT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_EMULARE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1BAB160329C5B3609B8DAFBD216416049B7309A5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_EMULARE1 (
  ID NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  DISCOUNT NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  TVA NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PRETNIRSTOC NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  CODEMULSTINGERE NUMBER(20,0),
  FARASTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  TIPLIVRARE NUMBER(1,0),
  CADOU NUMBER(20,0),
  PRETPROMO NUMBER(1,0),
  CODGESTORIG NUMBER(20,0),
  CODNIRSTOCREZ NUMBER(20,0),
  CODNIRSERREZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_FCRUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C9A4929E1ADE1A7D9FB7EB1090D8893EB0BD826</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_FCRUL (
  CODCONT NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_FCSOLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>521BAC8FA8E04A1EAFBAD91478DE60D8C03F353D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_FCSOLD (
  CODCONT NUMBER(20,0),
  DEBIT NUMBER(20,3),
  CREDIT NUMBER(20,3),
  DEBITV NUMBER(20,3),
  CREDITV NUMBER(20,3),
  SOLD NUMBER(20,3),
  SOLDV NUMBER(20,3),
  IFRS NUMBER(20,3),
  IFRSV NUMBER(20,3),
  SOLD_IFRS NUMBER(20,3),
  SOLD_IFRSV NUMBER(20,3),
  GRUP NUMBER(20,3),
  GRUPV NUMBER(20,3),
  SOLD_GRUP NUMBER(20,3),
  SOLD_GRUPV NUMBER(20,3),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_FISACONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84CDA1130D65AB1D47CCD6B163117036EE0CD076</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_FISACONT (
  NAV_CODDOC NUMBER(20,0),
  NAV_TIPDOC NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCORESP NUMBER(20,0),
  DEBIT NUMBER(24,7),
  CREDIT NUMBER(24,7),
  DEBITV NUMBER(24,7),
  CREDITV NUMBER(24,7),
  VALOARE NUMBER(24,7),
  VALOAREV NUMBER(24,7),
  SOLD NUMBER(24,7),
  SOLDV NUMBER(24,7) NOT NULL,
  OBS VARCHAR2(200),
  DOCUMENT VARCHAR2(100),
  DATADOC DATE,
  SUBUNITATEA NUMBER(20,0),
  GEST NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODCENTRU NUMBER(20,0),
  ORDINE NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  IFRS NUMBER(24,7),
  IFRSV NUMBER(24,7),
  SOLD_IFRS NUMBER(24,7),
  SOLD_IFRSV NUMBER(24,7),
  GRUP NUMBER(24,7),
  GRUPV NUMBER(24,7),
  SOLD_GRUP NUMBER(24,7),
  SOLD_GRUPV NUMBER(24,7),
  CURS_DOC NUMBER(24,7),
  CODMONEDA_DOC NUMBER(20,0),
  VAL_DOC NUMBER(24,7),
  CODANALIZANOD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_IESIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B57C87A9E6759E7454B1B0B366D1DCE5A4F2A85F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_IESIRI (
  DEN_ARTICOL VARCHAR2(4000),
  SIMBOL VARCHAR2(30),
  DEN_UM VARCHAR2(15),
  CANT NUMBER(20,7),
  PU NUMBER(20,7),
  TVA_UNITAR NUMBER,
  TVA_TOTAL NUMBER(20,7),
  PRETCUTVA NUMBER,
  VALCUTVA NUMBER,
  CODIES NUMBER(20,0),
  DEN_PART VARCHAR2(50),
  DATADOC DATE,
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DOCUMENT VARCHAR2(53),
  VALOARE NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_INTRARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0A50E874EEA18E3DB56652BAA9E67D444E8EBFE4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_INTRARI (
  DEN_ARTICOL VARCHAR2(100),
  SIMBOL VARCHAR2(30),
  DEN_UM VARCHAR2(15),
  CANT NUMBER(20,7),
  PU NUMBER(20,7),
  TVA_UNITAR NUMBER,
  TVA_TOTAL NUMBER(20,7),
  PRETCUTVA NUMBER,
  VALCUTVA NUMBER,
  CODINTR NUMBER(20,0),
  DEN_PART VARCHAR2(50),
  DATADOC DATE,
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DOCUMENT VARCHAR2(100),
  VALOARE NUMBER(10,5)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_IOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>81025F5E8F9083FDFB4BBBFE84507E0FC3B33E27</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_IOART (
  DENUMIRE VARCHAR2(50),
  REPREZ VARCHAR2(10),
  DIFERENTE VARCHAR2(10),
  CHELTUIELI VARCHAR2(10),
  VENITURI VARCHAR2(10),
  PLUSINVENTAR VARCHAR2(10),
  MINUSINVENTAR VARCHAR2(10),
  CHELTTVACOLECTAT VARCHAR2(10),
  CONTROTUNJIRI VARCHAR2(10),
  DIVERSE VARCHAR2(10),
  ACCIZELATRANSFER VARCHAR2(10),
  DESCARCAREG VARCHAR2(2),
  CONTABGEST VARCHAR2(2),
  BAZA VARCHAR2(2),
  DIFPRET VARCHAR2(2),
  ARETVANEEX VARCHAR2(2),
  TVANEEX VARCHAR2(10),
  MG VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_IOPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CDB75A4F62B2E987C9407CC14521E3100AA9ED0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_IOPART (
  DENUMIRE VARCHAR2(50),
  CONTFURNIZOR VARCHAR2(10),
  CONTCLIENT VARCHAR2(10),
  CONTFURNAVANS VARCHAR2(10),
  CONTCLIENTAVANS VARCHAR2(10),
  CONTFURNAVIZ VARCHAR2(10),
  CONTCLIENTAVIZ VARCHAR2(10),
  CONTFURNMF VARCHAR2(10),
  CONTCREDITD VARCHAR2(10),
  CONTDEBITD VARCHAR2(10),
  CONTLITIGII VARCHAR2(10),
  CONTFURNAVS VARCHAR2(10),
  CONTFURNAVIC VARCHAR2(10),
  CONTFURNAVIN VARCHAR2(10),
  CONTTERTI VARCHAR2(10),
  TVANEEXF VARCHAR2(10),
  TVANEEXC VARCHAR2(10),
  TIP VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_IOPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1D3B25D76E2778EFAFE98B13E908AE29CA3ECB50</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_IOPERS (
  DENUMIRE VARCHAR2(50),
  CONTAVANSDECONT VARCHAR2(10),
  CONTIMPUTATII VARCHAR2(10),
  CONTGARANTII VARCHAR2(10),
  CONTALTERETINERI VARCHAR2(10),
  CONTAVANS VARCHAR2(10),
  CONTLIKI VARCHAR2(10),
  CONTNERIDICATE VARCHAR2(10),
  CONTBOALA VARCHAR2(10),
  CONTPARTSAL VARCHAR2(10),
  CONTNATURA VARCHAR2(10),
  CONTECHIPAMENT VARCHAR2(10),
  CONTIMPOZIT VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_LOHN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>31FADF5DD9AA8251A820603C08001A25ECF729E4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_LOHN (
  CODIES1 NUMBER(20,0),
  CODL1 NUMBER(20,0),
  CODNP1 NUMBER(20,0),
  CODCI1 NUMBER(20,0),
  CODCC1 NUMBER(20,0),
  CODBC1 NUMBER(20,0),
  CODBCL1 NUMBER(20,0),
  CODCPM NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODIIOA1 NUMBER(20,0),
  CODEIOA1 NUMBER(20,0),
  IESCODCIF NUMBER(20,0),
  INTRCODCIF NUMBER(20,0),
  IESCODSSOC NUMBER(20,0),
  INTRCODSSOC NUMBER(20,0),
  COEFX NUMBER(20,0),
  COEFIN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_NIR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6858B5535DE294EB7214830D727D20D90F76643D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_NIR (
  CODNIRSTOC NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  DENOBIECT VARCHAR2(100),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  PRETACHIZ NUMBER(20,7),
  PROCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_NOMPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8950D1808530CD3F91E7FE85B76A21E2F9B92CFF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_NOMPART (
  DENUMIRE VARCHAR2(100),
  CODFISCAL VARCHAR2(75),
  REGCOM VARCHAR2(50),
  LOCALITATE VARCHAR2(50),
  JUDET VARCHAR2(100),
  ADRESA VARCHAR2(200),
  TELEFON VARCHAR2(40),
  EMAIL VARCHAR2(50),
  CREDITF NUMBER(20,7),
  CREDITC NUMBER(20,7),
  SIMBOLBANCA VARCHAR2(100),
  CONTBANCA VARCHAR2(100),
  DISCOUNT NUMBER(20,7),
  PERSFIZICA VARCHAR2(2),
  CATEGPRET VARCHAR2(100),
  CLASAPART VARCHAR2(100),
  VOLUMTRANZC NUMBER(20,7),
  VOLUMTRANZF NUMBER(20,7),
  TIPCONT VARCHAR2(50),
  SOLDREAL NUMBER(20,7),
  SCADENTAC NUMBER(2,0),
  SCADENTAV NUMBER(2,0),
  AGENT VARCHAR2(100),
  DISTANTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_PARAMS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>567A1903790E298070463D558D1D744999541CC5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_PARAMS (
  IDX NUMBER(5,0),
  DENUMIRE VARCHAR2(200),
  VALOARE VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_PMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3B457026508B203044CAA39C1DF33C74DDD36AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_PMP (
  CODOBIECT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  TIP NUMBER(1,0),
  CANT NUMBER(20,7),
  VACHIZLEI NUMBER(20,7),
  VACHIZVAL NUMBER(20,7),
  VPMPLEI NUMBER(20,7),
  VPMPVAL NUMBER(20,7),
  TIPLINIE VARCHAR2(100),
  DOCUMENT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_PROFORMA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>72B3167D4E152E74210BB806BE73032B40E2C5E3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_PROFORMA1 (
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  UMSEC NUMBER(10,0),
  DENUM VARCHAR2(15),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  TIPSURSA NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  TIPLINIE VARCHAR2(1),
  PROCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_RAPSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B4683027881586A07027DB8BD709A2BEC825F21</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_RAPSTOC (
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CANT NUMBER(20,5),
  SEMN NUMBER(2,0),
  PROMO NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_REGCASSA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C77F3CEB016D933111C94C825CB115C8A65E4EA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_REGCASSA (
  DATADOC DATE,
  EXPLICATII VARCHAR2(100),
  INCASARE NUMBER(20,7),
  PLATA NUMBER(20,7),
  VALDOC NUMBER(20,7),
  SOLD_COL NUMBER(20,7),
  ICONT NUMBER(10,0),
  CODPART NUMBER(20,0),
  CONT VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_SCADENTARCL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>29591B7A1DBA5623494434AA599B165716CB66E8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_SCADENTARCL (
  DENPART VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  MAJORARE NUMBER(20,7),
  REST NUMBER(20,7),
  VALMAJ NUMBER(20,7),
  ZILE_TRECUTE NUMBER(4,0),
  ZILE_DEPASIRE NUMBER(4,0),
  DOCUMENT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_SCADENTARF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B80C29948D0DD10CF75B35B6AEFDA62AFA0A845</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_SCADENTARF (
  DENPART VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  MAJORARE NUMBER(20,7),
  REST NUMBER(20,7),
  VALMAJ NUMBER(20,7),
  ZILE_TRECUTE NUMBER(4,0),
  ZILE_DEPASIRE NUMBER(4,0),
  DOCUMENT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_SITONINV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BA40C113A76BE27DDAC3C4B931B8088D7E484569</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_SITONINV (
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCRITERIU NUMBER(20,0),
  CODCONT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  PROC NUMBER(20,7),
  BAZADISC NUMBER(20,7),
  VALDISC NUMBER(20,7),
  VALDISCANT NUMBER(20,7),
  VALDISCFIN NUMBER(20,7),
  CODMONEDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_SOLDPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>73ED14107B525ED4B49558A73AB6B9A35D7025F6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_SOLDPART (
  PARTENER VARCHAR2(100),
  CONT VARCHAR2(10),
  SOLDL NUMBER(20,7),
  SOLDV NUMBER(20,7),
  MONEDA VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_STOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67C8095DB16DB7128D9DDC5DD4E95780D6CE31CF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_STOC (
  CODNIRSTOC NUMBER(20,0),
  UMSEC VARCHAR2(20),
  CODOBIECT NUMBER(20,0),
  DEN_ARTICOL VARCHAR2(50),
  CODIOART NUMBER(20,0),
  DEN_IOART VARCHAR2(30),
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(30),
  PRETACHIZ NUMBER(20,7),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(20,7),
  REST NUMBER(20,0),
  STOC NUMBER(20,0),
  PRELUAT NUMBER(20,0),
  PROCENTADAOS NUMBER(20,7),
  INTRATLA DATE,
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(30),
  SERIE VARCHAR2(30),
  CODNIRSER NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODINTR NUMBER(20,0),
  FLAG NUMBER(20,0),
  NIRINITIAL NUMBER(20,0),
  INTR1INITIAL NUMBER(20,0),
  VALSTOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIST_URMSUPV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54B956EDBC685EF21B09BDF9DD2469C743B42F8B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIST_URMSUPV (
  NAV_CODDOC NUMBER(20,0),
  NAV_TIPDOC NUMBER(20,0),
  PERSOANA VARCHAR2(410),
  CAMPMODIF VARCHAR2(20),
  TIPDOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TABELA VARCHAR2(20),
  OLDVAL VARCHAR2(30),
  NEWVAL VARCHAR2(30),
  EXPLIC VARCHAR2(2500),
  OBS VARCHAR2(500),
  POSTR VARCHAR2(50),
  FACT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7161F196863E1531DED578B787E254C911706BC4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR (
  CODLIVR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  DATALIVR DATE,
  OBS VARCHAR2(100),
  TIPLIVR NUMBER(2,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  EXPORTAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C14C110E2F522A9A36FB0093D2811A87DA71ABC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR1 (
  CODLIVR1 NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  TIPLINIE VARCHAR2(1),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVANEEX NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODLIVRTOT NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  TIPSERIE NUMBER(20,0),
  SERIE VARCHAR2(75),
  PROCENTADAOS NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  OBS VARCHAR2(200),
  PUAVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  DATAPROD1 DATE,
  TG1 DATE,
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3ECBE6DDE9F68965E4E43A68F0C8853AF4703D60</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR1_INITIAL (
  CODLIVR1 NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  TIPLINIE VARCHAR2(1),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVANEEX NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODLIVRTOT NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  TIPSERIE NUMBER(20,0),
  SERIE VARCHAR2(75),
  PROCENTADAOS NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  OBS VARCHAR2(200),
  PUAVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  DATAPROD1 DATE,
  TG1 DATE,
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR1_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>53F40F80223233BA43CDEA3F63D09C450F38E3C1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR1_MAT (
  CODLIVR1 NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  TIPLINIE VARCHAR2(1),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVANEEX NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODLIVRTOT NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  TIPSERIE NUMBER(20,0),
  SERIE VARCHAR2(75),
  PROCENTADAOS NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  OBS VARCHAR2(200),
  PUAVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  DATAPROD1 DATE,
  TG1 DATE,
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR1_MAT_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20B56DB42E358D4F7F0D576F834D286421D201D6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR1_MAT_INITIAL (
  CODLIVR1 NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(30,17),
  CODNIRSER NUMBER(20,0),
  PMP NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTIESVAL NUMBER(20,7),
  CANTREZERVAT NUMBER(30,17),
  CODCERTIF NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODGESTORIG NUMBER(20,0),
  BLOCATUM1 NUMBER(1,0),
  CODLIVR1PARINTE NUMBER(20,0),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  TIPLINIE VARCHAR2(1),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVANEEX NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODLIVRTOT NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  TIPSERIE NUMBER(20,0),
  SERIE VARCHAR2(75),
  PROCENTADAOS NUMBER(20,7),
  GESTIMPLICITA NUMBER(20,0),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  OBS VARCHAR2(200),
  PUAVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  DATAPROD1 DATE,
  TG1 DATE,
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRARI_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78E23EAE67EEAF2B7494ABEA8BC90EDB17F80604</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRARI_LUNA (
  CODNIRSTOC NUMBER(20,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRARI_SER_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3A091860AEE1D35F368DAD01112ED306CDBF488F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRARI_SER_LUNA (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3D807A259A079883E7321C06AFEF27889E9A7A8F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRART (
  CODLIVRART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  CANTDISPONIBIL NUMBER(20,7),
  CANTREZERVAT NUMBER(20,7),
  CANTCOMENZI NUMBER(20,7),
  CODCLIENT NUMBER(20,0),
  SEDIU VARCHAR2(200),
  CODJUDET NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  DATACOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ECCF361E3B5C343405ACC41E7072D293C7FCBB10</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRAT (
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRAT_SER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>918BDA41CC0C04A2162DB458891030CFD6CED929</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRAT_SER (
  CODNIRSER NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRNIRSTOC_LA_DATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4825C2507983AB5A1F8DE65141FEE0510AF78BBB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRNIRSTOC_LA_DATA (
  CODNIRSTOC NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRTOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>90231170C415E95CAD8FCC336547BFD4552D1262</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRTOT (
  CODLIVRTOT NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIESINT1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(23,10),
  DENOBIECT VARCHAR2(200),
  DENGESTIOART VARCHAR2(200),
  STOCREZOLVAT NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  MG NUMBER(1,0),
  INDEXMASTER NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  CONT NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  SUFIXTVANEEX VARCHAR2(10),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  ACCIZELATRANSFER NUMBER(1,0),
  PMP NUMBER(20,7),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  NRDOCLINK VARCHAR2(30),
  RELATIEUM1 NUMBER(2,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODPRODCOMP NUMBER(20,0),
  CODCOMAND1LNK NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODCOMAND1ORIG NUMBER(20,0),
  ARETG NUMBER(1,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRTOT_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>923ACB5CA865E2D829F0E21D0625697FEF19BB20</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRTOT_MAT (
  CODLIVRTOT NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIESINT1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENGESTIOART VARCHAR2(100),
  STOCREZOLVAT NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  MG NUMBER(1,0),
  INDEXMASTER NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  CONT NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  SUFIXTVANEEX VARCHAR2(10),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  ACCIZELATRANSFER NUMBER(1,0),
  PMP NUMBER(20,7),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  CODLINIECOMANDA NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  NRDOCLINK VARCHAR2(30),
  RELATIEUM1 NUMBER(2,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODPRODCOMP NUMBER(20,0),
  CODCOMAND1LNK NUMBER(20,0),
  CONTINTERMED NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CODCOMAND1ORIG NUMBER(20,0),
  ARETG NUMBER(1,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  CUSTODIEINTRARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C49DADB6380D6BE0983F29FB13799111323899FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRVAL (
  CODLIVRVAL NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  GEST NUMBER(20,0),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  TVANEEX NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVRVAL_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60C7FCDAADB535707F3A6892F9E0539E103B5E02</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVRVAL_INITIAL (
  CODLIVRVAL NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  GEST NUMBER(20,0),
  PRETINREG NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  TVANEEX NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR_DATA_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>702C3EF46B4F61268219BE217123C369E028A172</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR_DATA_GEST (
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR_IN_INTERVALUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>878F0F6D7A032D1D8CFB96547690C53652279C0B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR_IN_INTERVALUL (
  CODOBIECT NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR_LA_DATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>691830960CF1666F5B326EA2FB89413AEAB594D5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR_LA_DATA (
  CODOBIECT NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C67D3FE92D5B625B864833B0FF9234B77D5A760B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR_MAT (
  CODLIVR NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  DATALIVR DATE,
  OBS VARCHAR2(100),
  TIPLIVR NUMBER(2,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LIVR_NEREZOLVATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F562D594BD40BC0635FF77197ACF21DA5A6B6DF0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LIVR_NEREZOLVATE (
  SERIEFACTURA VARCHAR2(20),
  NRFACTURA NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  CANT NUMBER(20,7),
  DENUM VARCHAR2(30),
  CLIENT VARCHAR2(100),
  COMANDA VARCHAR2(30),
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODUM1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOCATIIGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C1648136B26B74B861E28B83026185A5F558816</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LOCATIIGEST (
  CODLOCATIE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  INDEXLOCAL NUMBER(10,0),
  NRCELULE NUMBER(10,0),
  DESCRIERE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOCMUNCA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F72F6B2EEE18376315E565754491DC2EDC1DF4C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LOCMUNCA (
  CODLOC NUMBER(20,0),
  SIMBOL VARCHAR2(10),
  DENUMIRE VARCHAR2(250),
  TIP NUMBER(1,0),
  DSV NUMBER(10,0),
  ACTIVI NUMBER(10,0),
  SPECIAL NUMBER(1,0),
  CODLOCDEF NUMBER(20,0),
  MINUTEON NUMBER(4,0),
  MINUTEOFF NUMBER(4,0),
  FARA_GANT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOCMUNCA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>675AB62B5BA37EC7B9DB69AE1C11047E25F68943</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LOCMUNCA1 (
  CODLOC1 NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  ORE NUMBER(10,7),
  CODUTILAJ NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  NICKNAME VARCHAR2(30),
  NRINV NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DEN_GEST VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOCMUNCA2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>234ABA3DDD829B701AB5EF65643140A80669BC4A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LOCMUNCA2 (
  CODLOC2 NUMBER(20,0),
  CODLOC1 NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODLOC1ASOC NUMBER(20,0),
  ORESTART NUMBER(7,3),
  DATASTART DATE,
  ORESTOP NUMBER(7,3),
  DATASTOP DATE,
  MINUNEON NUMBER(4,0),
  MINUNEOFF NUMBER(4,0),
  OREACTIV NUMBER(7,3),
  CODLOCASOC NUMBER(20,0),
  DENLOCASOC VARCHAR2(250),
  DENLOC1ASOC VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOCURIMUNCAOBS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7CC54031A98B9924FA33A5BCA0AB064449D7544E</HASHVAL>
  <TEXT>CREATE TABLE TMP_LOCURIMUNCAOBS (
  IDOBS NUMBER(20,0),
  CODPROGRAMF1 NUMBER(20,0),
  CODLOCMUNCA NUMBER(20,0),
  OBS VARCHAR2(3000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LOGIMPORTDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>664EA2FE21F36E9C314F709F8C0E44BEBBABA846</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LOGIMPORTDOC (
  COD NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  IDIMPORT VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DATAIMPORT TIMESTAMP(6),
  CODPART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  TIPOPERATIE VARCHAR2(1),
  CANTVECHI NUMBER(20,7),
  CANTNOU NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_290</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6C8F40FB16AE15F806F7DA6F27C7F2D9B69E30E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_290 (
  CODPRETM NUMBER(20,0),
  DENOBJ VARCHAR2(300),
  DEN_CATPRET VARCHAR2(300),
  DEN_UM VARCHAR2(300),
  ROT NUMBER(20,7),
  PRETREFERINTA NUMBER(20,7),
  LEI NUMBER(20,7),
  PADAOSLEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  PRETNOU NUMBER(20,7),
  PADAOSNOU NUMBER(20,7),
  PRETNOUV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_291</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>785400DB3ADD3FD0A6F87BC543581994ABF8B8F0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_291 (
  CODPRETM NUMBER(20,0),
  DENOBJ VARCHAR2(300),
  DEN_CATPRET VARCHAR2(300),
  DEN_UM VARCHAR2(300),
  ROT NUMBER(20,7),
  PRETREFERINTA NUMBER(20,7),
  LEI NUMBER(20,7),
  PADAOSLEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  PRETNOU NUMBER(20,7),
  PADAOSNOU NUMBER(20,7),
  PRETNOUV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_292</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B91DC708FC9D808782E6F52C5069ED682A45159B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_292 (
  CODPRETM NUMBER(20,0),
  DENOBJ VARCHAR2(300),
  DEN_CATPRET VARCHAR2(300),
  DEN_UM VARCHAR2(300),
  ROT NUMBER(20,7),
  PRETREFERINTA NUMBER(20,7),
  LEI NUMBER(20,7),
  PADAOSLEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  PRETNOU NUMBER(20,7),
  PADAOSNOU NUMBER(20,7),
  PRETNOUV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_293</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E9B893D204378304F6EABBC18545FB8F5AA1A2CB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_293 (
  CODPRETM NUMBER(20,0),
  DENOBJ VARCHAR2(300),
  DEN_CATPRET VARCHAR2(300),
  DEN_UM VARCHAR2(300),
  ROT NUMBER(20,7),
  PRETREFERINTA NUMBER(20,7),
  LEI NUMBER(20,7),
  PADAOSLEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  PRETNOU NUMBER(20,7),
  PADAOSNOU NUMBER(20,7),
  PRETNOUV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_BALS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2EAADCC74C10AD3B9A70DCD6FC08C7797C4B83EE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_BALS (
  GEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CONT NUMBER(20,0),
  MG NUMBER(1,0),
  SERIE VARCHAR2(100),
  SEROBS VARCHAR2(300),
  TG DATE,
  CODCERTIF NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  PUVAL NUMBER(20,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SI NUMBER(20,7),
  SI1 NUMBER(20,7),
  SI2 NUMBER(20,7),
  CI NUMBER(20,7),
  CI1 NUMBER(20,7),
  CI2 NUMBER(20,7),
  CE NUMBER(20,7),
  CE1 NUMBER(20,7),
  CE2 NUMBER(20,7),
  IR NUMBER(20,7),
  TI NUMBER(20,7),
  IE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_BALSF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EFF7B77D4A3E265E82BDC126C2A02192B223BC2C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_BALSF (
  FURN NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  GEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CONT NUMBER(20,0),
  MG NUMBER(1,0),
  SERIE VARCHAR2(100),
  SEROBS VARCHAR2(300),
  TG DATE,
  CODCERTIF NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  SI NUMBER(20,7),
  CI NUMBER(20,7),
  CP NUMBER(20,7),
  CE NUMBER(20,7),
  CC NUMBER(20,7),
  CT NUMBER(20,7),
  SF NUMBER(20,7),
  SI1 NUMBER(20,7),
  CI1 NUMBER(20,7),
  CP1 NUMBER(20,7),
  CE1 NUMBER(20,7),
  CC1 NUMBER(20,7),
  CT1 NUMBER(20,7),
  SF1 NUMBER(20,7),
  SI2 NUMBER(20,7),
  CI2 NUMBER(20,7),
  CP2 NUMBER(20,7),
  CE2 NUMBER(20,7),
  CC2 NUMBER(20,7),
  CT2 NUMBER(20,7),
  SF2 NUMBER(20,7),
  SOLDI NUMBER(20,7),
  VI NUMBER(20,7),
  VP NUMBER(20,7),
  VE NUMBER(20,7),
  VC NUMBER(20,7),
  VT NUMBER(20,7),
  SOLDF NUMBER(20,7),
  CANTINTRAS NUMBER(20,7),
  CANTINTRT NUMBER(20,7),
  CANTINTRASUM1 NUMBER(20,7),
  CANTINTRTUM1 NUMBER(20,7),
  CANTINTRASUM2 NUMBER(20,7),
  CANTINTRTUM2 NUMBER(20,7),
  VALINTRAS NUMBER(20,7),
  VALINTRT NUMBER(20,7),
  CANTIESAS NUMBER(20,7),
  CANTIEST NUMBER(20,7),
  CANTIESASUM1 NUMBER(20,7),
  CANTIESTUM1 NUMBER(20,7),
  CANTIESASUM2 NUMBER(20,7),
  CANTIESTUM2 NUMBER(20,7),
  VALIESAS NUMBER(20,7),
  VALIEST NUMBER(20,7),
  CANTDIMIN NUMBER(20,7),
  CANTMARIRI NUMBER(20,7),
  CANTDIMINUM1 NUMBER(20,7),
  CANTMARIRIUM1 NUMBER(20,7),
  CANTDIMINUM2 NUMBER(20,7),
  CANTMARIRIUM2 NUMBER(20,7),
  VALDIMIN NUMBER(20,7),
  VALMARIRI NUMBER(20,7),
  VALVANZARI NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  VALORIC NUMBER(1,0),
  CANTINTRMP NUMBER(20,7),
  CANTINTRMPUM1 NUMBER(20,7),
  CANTINTRMPUM2 NUMBER(20,7),
  VALINTRMP NUMBER(20,7),
  CANTIESMP NUMBER(20,7),
  CANTIESMPUM1 NUMBER(20,7),
  CANTIESMPUM2 NUMBER(20,7),
  VALIESMP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_CANTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0AD50FDD8CF8380BDBE99CA5FEDF456668B64F7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_CANTAR (
  CODCANTAR NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TOTAL_KG NUMBER(20,7),
  TARA_KG NUMBER(20,7),
  NET_KG NUMBER(20,7),
  AMB1_COD NUMBER(20,0),
  AMB1_KG NUMBER(20,7),
  AMB1_CANT NUMBER(20,0),
  AMB1_RETURNABIL NUMBER(1,0),
  AMB2_COD NUMBER(20,0),
  AMB2_KG NUMBER(20,7),
  AMB2_CANT NUMBER(20,0),
  AMB2_RETURNABIL NUMBER(1,0),
  AMB3_COD NUMBER(20,0),
  AMB3_KG NUMBER(20,7),
  AMB3_CANT NUMBER(20,0),
  AMB3_RETURNABIL NUMBER(1,0),
  AMB4_COD NUMBER(20,0),
  AMB4_KG NUMBER(20,7),
  AMB4_CANT NUMBER(20,0),
  AMB4_RETURNABIL NUMBER(1,0),
  PALET_KG NUMBER(20,7),
  TRANSP1_COD NUMBER(20,0),
  TRANSP1_KG NUMBER(20,7),
  TRANSP1_CANT NUMBER(20,0),
  TRANSP2_COD NUMBER(20,0),
  TRANSP2_KG NUMBER(20,7),
  TRANSP2_CANT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  USERIDBLOCAJ NUMBER(20,0),
  ANULAT NUMBER(1,0),
  INDEXCANTAR NUMBER(2,0),
  RETUR NUMBER(1,0),
  SERIE NUMBER(20,0),
  IDCANTAR NUMBER(20,0),
  FURNIZOR NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  DESTINATIE NUMBER(1,0),
  CLIENT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODCMD1 NUMBER(20,0),
  AMB5_COD NUMBER(20,0),
  AMB5_KG NUMBER(20,7),
  AMB5_CANT NUMBER(20,0),
  AMB5_RETURNABIL NUMBER(1,0),
  AMB6_COD NUMBER(20,0),
  AMB6_KG NUMBER(20,7),
  AMB6_CANT NUMBER(20,0),
  AMB6_RETURNABIL NUMBER(1,0),
  ID_CANTARIRE VARCHAR2(20),
  TRANSPORTATOR VARCHAR2(50),
  NRVEHICOL VARCHAR2(20),
  NRREMORCA VARCHAR2(20),
  CANTDOC NUMBER(20,7),
  SERIEAVIZ VARCHAR2(20),
  LOT VARCHAR2(30),
  DENOBIECT VARCHAR2(200),
  AMB1_DEN VARCHAR2(200),
  AMB2_DEN VARCHAR2(200),
  AMB3_DEN VARCHAR2(200),
  AMB4_DEN VARCHAR2(200),
  TRANSP1_DEN VARCHAR2(200),
  TRANSP2_DEN VARCHAR2(200),
  ARECARNETDOC NUMBER(1,0),
  SERIETXT VARCHAR2(200),
  AMB5_DEN VARCHAR2(200),
  AMB6_DEN VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_CDOCIMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FB05089DB633526057CD3CB7A001A6EF95225F78</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_CDOCIMP (
  ORD NUMBER(5,0),
  ERR VARCHAR2(4000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_CURS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>006E0F6B7607B78B98B2C894C72D982958F0CDB7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_CURS (
  CODMONEDA NUMBER(20,0),
  VALOARE NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_DETBALSINT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C607BC943EC4227B43B676540BE50CF59D6DF02</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_DETBALSINT (
  CODPART NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  TIPCONT NUMBER(1,0),
  CODMONEDA NUMBER(20,0),
  ORDINE NUMBER(5,0),
  DEBIT NUMBER(20,7),
  CREDIT NUMBER(20,7),
  TVA NUMBER(20,7),
  DEBIT_AJDEP NUMBER(20,7),
  CREDIT_AJDEP NUMBER(20,7),
  IFRS NUMBER(20,7),
  TIPSOLD VARCHAR2(1),
  SOLD_COL NUMBER(20,7),
  SOLD_COL_CUTVA NUMBER(20,7),
  SOLD_COL_IFRS NUMBER(20,7),
  SOLD_COL_TOTAL NUMBER(20,7),
  SOLD_COL_AJDEP NUMBER(20,7),
  SOLD_COL_D NUMBER(20,7),
  SOLD_COL_C NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_DOCEMULARE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8FDC13DC4263B6ED16F9EC470ECB8B89EFDDEF6D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_DOCEMULARE1 (
  CODEMULARE1 NUMBER(20,0),
  PRETART NUMBER(20,7),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_DOCNEOPERATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B36FF1FAC4D7B442612F3239205A5FE7D9480255</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_DOCNEOPERATE (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SUBUNITATEA NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PART VARCHAR2(401),
  VALDOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_DOCUMENTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>336DD4544F0E05DDEDBCB798ADFD399A24ED56E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_DOCUMENTE (
  CODGENERAL NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  LUNA NUMBER(2,0),
  DATADOC DATE,
  PREFIXDOC VARCHAR2(30),
  NRDOC NUMBER,
  VALDOC NUMBER,
  CURS NUMBER,
  TVA NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  CODOBLIGPIF NUMBER(20,0),
  SEMNIFICATIE NUMBER(20,0),
  TIPFACTURA NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODGENERALSTINS NUMBER(20,0),
  VALSTINS NUMBER(20,7),
  DIFIFRS NUMBER(20,7),
  CURSIFRS NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  ICONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_DOC_CONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D6FEFBA538332F27A3663160A2B9040E0786CF69</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_DOC_CONT (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_EUDR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6BA628AF9BC061AEB92CDD325DD79A1BA2476569</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_EUDR (
  CODNIRSTOC NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_EXPERTBAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CEBFE3DA9A72EE5BCED477ED71A681017F533E86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_EXPERTBAL (
  CODCONT NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CLASA NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  TIPCONT VARCHAR2(15),
  NAME VARCHAR2(200),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODSINTETIC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SIMBSINTETIC VARCHAR2(100),
  DEN_SINTETIC VARCHAR2(200),
  SIMB_NOD VARCHAR2(100),
  DEN_NOD VARCHAR2(200),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_EXPERTBALRAW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>86D8EB7F0BE32F79E5AB2D13C84E7643085F0691</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_EXPERTBALRAW (
  CODCONT NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  RULAJD NUMBER(20,7),
  RULAJC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_EXTERNE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7FC30946264D048327C1B9C645874E1753B23E78</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_EXTERNE (
  ORDINE NUMBER(20,0),
  SQLTEXT CLOB,
  LISTID NUMBER(20,0),
  LISTVER NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_FACTINTOCMIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>55287E93667DF2C910816D57EFEAC82CA8A0AEE3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_FACTINTOCMIT (
  CODIES1 NUMBER(20,0),
  CANT_AVIZ NUMBER(20,7),
  VALD_AVIZ NUMBER(20,7),
  TVA_AVIZ NUMBER(20,7),
  CANT_FACT NUMBER(20,7),
  VALD_FACT NUMBER(20,7),
  TVA_FACT NUMBER(20,7),
  VAL_ACHIZ NUMBER(20,7),
  SERII VARCHAR2(3200),
  IOARTL VARCHAR2(3200),
  CONTIOARTL VARCHAR2(3200),
  CONTCUSTL VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_FISACONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C9033EDEAFF3F27CCF8AAE053ECA09D0CCED5590</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_FISACONT (
  NAV_CODDOC NUMBER(20,0),
  NAV_TIPDOC NUMBER(20,0),
  CONT VARCHAR2(100),
  CORESP VARCHAR2(100),
  DEN_CONT VARCHAR2(200),
  NAME_CONT VARCHAR2(200),
  DEN_CORESP VARCHAR2(200),
  NAME_CORESP VARCHAR2(200),
  DEBIT NUMBER(20,7),
  CREDIT NUMBER(20,7),
  DEBITV NUMBER(20,0),
  CREDITV NUMBER(20,0),
  VALOARE NUMBER(20,0),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  MISCARE NUMBER(1,0),
  ORDINE NUMBER(10,0),
  DATADOC DATE,
  SOLD_COL NUMBER(20,0),
  SOLDV NUMBER(20,7),
  SOLD_COLV NUMBER(20,7),
  TIPSOLD VARCHAR2(1),
  TIPSOLDV VARCHAR2(1),
  SUBUNITATEA VARCHAR2(200),
  DOCUMENT VARCHAR2(50),
  LUNA VARCHAR2(30),
  DEN_GEST VARCHAR2(200),
  CONT_PSEC VARCHAR2(30),
  CORESP_PSEC VARCHAR2(30),
  CONT_PTER VARCHAR2(30),
  CORESP_PTER VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_FISAIMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3AE3BB4D1D75B703BF89513CFDCAC41E65E4A1E</HASHVAL>
  <TEXT>CREATE TABLE TMP_LST_FISAIMOB (
  CODNIRSTOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODDOCSEC NUMBER(20,0),
  TIPDOCSEC NUMBER(10,0),
  INDEXLOCAL NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  NRINVENTAR NUMBER(20,0),
  DEN_PART VARCHAR2(250),
  CODMIFIX NUMBER(20,0),
  CODOPERATIE NUMBER(5,0),
  DATAOPERATIE DATE,
  GESTSURSA NUMBER(20,0),
  GESTDEST NUMBER(20,0),
  PRETI NUMBER(20,7),
  PRETE NUMBER(20,7),
  PREFIXDOC VARCHAR2(50),
  NRDOC NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  DATADOC DATE,
  OBS VARCHAR2(400),
  MF NUMBER(1,0),
  IMBMF NUMBER(1,0),
  TIPOPERATIE VARCHAR2(100),
  DIRTY NUMBER(5,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODPART NUMBER(20,0),
  CODPARTSEC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODNS NUMBER(20,0),
  CODIOART1 NUMBER(20,0),
  CODMIFIX1 NUMBER(20,0),
  IMBUNATATIRE NUMBER(20,0),
  DATAOP DATE,
  ORDINE NUMBER(5,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_FISAMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E740C5075C26F31800087BD0A1D56E2514A25B8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_FISAMF (
  CODNIRSTOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOCSEC NUMBER(20,0),
  TIPDOCSEC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DENUMIRE VARCHAR2(400),
  NRINVENTAR NUMBER(20,0),
  DEN_PART VARCHAR2(400),
  CODMIFIX NUMBER(20,0),
  CODOPERATIE NUMBER(20,0),
  DATAOPERATIE DATE,
  GESTSURSA NUMBER(20,0),
  GESTDEST NUMBER(20,0),
  PRETI NUMBER(20,7),
  PRETE NUMBER(20,7),
  PREFIXDOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  DATADOC DATE,
  OBS VARCHAR2(400),
  MF NUMBER(10,0),
  IMBMF NUMBER(10,0),
  TIPOPERATIE CHAR(50),
  JURNAL VARCHAR2(1000),
  DIRTY NUMBER(10,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODPART NUMBER(20,0),
  CODPARTSEC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODNS NUMBER(20,0),
  CODVAMA NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_FM_SI2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C3A35E4C9DA2A58F557D80CA089C40F45D110FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_FM_SI2 (
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_GENPEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0D0A34699CA3CBD2EEC057B4E7C79A0A568B3636</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_GENPEN (
  CODOBLIGPIF NUMBER(20,0),
  PREFIXDOC VARCHAR2(4),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  TERMEN DATE,
  REST NUMBER(20,7),
  MAJORARI NUMBER(20,7),
  PRELUAT NUMBER(20,7),
  LOCATIE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  MONEDA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  MAJANTERIOARE NUMBER(20,7),
  DATA_LAST_FACTMAJ DATE,
  DATA_LAST_PLATA DATE,
  RESTOBLIG NUMBER(20,7),
  VALOBLIG NUMBER(20,7),
  GRATIEDOC NUMBER(10,0),
  STORNO NUMBER(20,7),
  SCADENTAV NUMBER(10,0),
  VALMAJ NUMBER(20,7),
  ZILE NUMBER(10,0),
  CODUNIC NUMBER(20,0),
  RESTLADATA NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  VALMAJORARI NUMBER(20,7),
  VALMAJORARIINI NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_GRAD_INC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F4E46D0719144EE4FCA355CA61225C94BA878D9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_GRAD_INC (
  CODGEST NUMBER(20,0),
  CODGRECHIV NUMBER(20,0),
  ZIUA DATE,
  MASINI_TOT NUMBER(20,0),
  MASINI_INC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_IESIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>799A033D634FA1D89B02B0F12C51EE9D06014CB8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_IESIRI (
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CURS NUMBER(20,7),
  PARTENER NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIECOMANDACC NUMBER(20,0),
  TRANSPORT VARCHAR2(50),
  CODIES1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  OBSART VARCHAR2(500),
  PUMAXIMAL NUMBER(20,7),
  PU NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PIES NUMBER(20,7),
  COEF_TVA NUMBER(20,7),
  TVALIN NUMBER(20,7),
  TVAU NUMBER(20,7),
  CANT NUMBER(20,7),
  CANTLIVR NUMBER(20,7),
  TIPART VARCHAR2(30),
  VALACHIZ NUMBER(20,7),
  PUMAXNS NUMBER(20,7),
  GARANTIE NUMBER(20,0),
  SERII VARCHAR2(3200),
  TG VARCHAR2(3200),
  TGCANT VARCHAR2(3200),
  TIPSERIE VARCHAR2(100),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  COSTTRANSPORT NUMBER(20,7),
  CADOU NUMBER(1,0),
  CODCADOU NUMBER(20,0),
  CODAE NUMBER(20,0),
  TERMEN DATE,
  CODOBIECT1 NUMBER(20,0),
  CODIOPART1 NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  DENOBIECTORIG VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODIOART1 NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODLINIEDOCIMP NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODLINIECOMANDADL NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_IESSIMPL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CBB69D2D03A7929DE23A5C91210CFFDE377183E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_IESSIMPL (
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  COEFDISCMAJ NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODLINIECOMANDACC NUMBER(20,0),
  CODLINIECOMANDADL NUMBER(20,0),
  TRANSPORT VARCHAR2(50),
  CODIES1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  CODOBIECT NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  DENOBIECTORIG VARCHAR2(200),
  UMSEC NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CONTSERV NUMBER(20,0),
  OBSART VARCHAR2(500),
  PUMAXIMAL NUMBER(20,7),
  PU NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PIES NUMBER(20,7),
  COEF_TVA NUMBER(20,7),
  TVALIN NUMBER(20,7),
  TVAU NUMBER(20,7),
  CANT NUMBER(20,7),
  TIPART VARCHAR2(30),
  GARANTIE NUMBER(20,0),
  COSTTRANSPORT NUMBER(20,7),
  CADOU NUMBER(1,0),
  CODCADOU NUMBER(20,0),
  CODAE NUMBER(20,0),
  TERMEN DATE,
  CODIOPART1 NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  CODAGENTEMULARE NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODLINIEDOCIMP NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODIES1STORNO NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CODOBIECT1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_INTRARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A948350079132D28942364ABC6933BDE46F57D6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_INTRARI (
  CODINTR NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  GESTACT NUMBER(10,0),
  OBSART VARCHAR2(200),
  ADDIM NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  CODCONT NUMBER(20,0),
  PU NUMBER(20,7),
  DISCU NUMBER(20,7),
  COEF_TVA NUMBER,
  CANT NUMBER(20,7),
  TVAU NUMBER(20,7),
  COEFTNED NUMBER,
  CANTREC NUMBER(20,7),
  TIPART VARCHAR2(8),
  VALACHIZ NUMBER(20,7),
  VALINREG NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  SERII VARCHAR2(4000),
  TG VARCHAR2(4000),
  TIPSERIE VARCHAR2(15),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  DATANIR VARCHAR2(4000),
  CODIOART1 NUMBER(20,0),
  CODPART1 NUMBER(20,0),
  CODCONTRACT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  TAXASTOPAJU NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_INTRSINT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F60E106812BA89888203F4B0653A0E5E6581DC4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_INTRSINT (
  CODINTR NUMBER(20,0),
  VAL NUMBER(20,7),
  TVA NUMBER(20,7),
  VALINT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_JURNAL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4A41B0D9C0EEF94C836EE642AA206F31CF1AF262</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_JURNAL1 (
  CODJURNAL1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODBAZAD NUMBER(20,0),
  TIPBAZAD NUMBER(5,0),
  ICONTBAZAD NUMBER(20,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODBAZAC NUMBER(20,0),
  TIPBAZAC NUMBER(5,0),
  ICONTBAZAC NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  GEST NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  OBS VARCHAR2(200),
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  DIRTY NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  VALOAREGRUP NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7),
  BAZAD VARCHAR2(50),
  INFOBAZAD VARCHAR2(250),
  DESCRD VARCHAR2(50),
  INFODESCRD VARCHAR2(250),
  BAZAC VARCHAR2(50),
  INFOBAZAC VARCHAR2(250),
  DESCRC VARCHAR2(50),
  INFODESCRC VARCHAR2(250),
  CODCONTD NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  DOCLEGATURA VARCHAR2(250),
  ARTICOL VARCHAR2(250),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PARTENER VARCHAR2(250),
  DATACREARE DATE,
  INDEX_JURNAL NUMBER(20,0),
  OBSLINIE VARCHAR2(450),
  CODDOC1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CODMONEDADOC NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  COD_CODFISCAL NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  VALDOC NUMBER(20,7),
  CURS NUMBER(20,7),
  TVADOC NUMBER(20,7),
  USERID NUMBER(20,0),
  CODAUTO NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_LIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B7BF2460063EB6FA8859DA1D35AD7285E191406D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_LIVR (
  ISIES NUMBER(1,0),
  ISTRANF NUMBER(1,0),
  ISINTR NUMBER(1,0),
  CODLIVR NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PARTENER NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  GESTD NUMBER(20,0),
  CODLOCATIED NUMBER(20,0),
  MONEDA NUMBER(20,0),
  AGENT NUMBER(20,0),
  LOCATIELIVR NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  GEST NUMBER(20,0),
  GESTORIG NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PU NUMBER(20,7),
  OBSART VARCHAR2(3200),
  OBSDOC VARCHAR2(250),
  COEF_TVA NUMBER(20,7),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  DATALIVR DATE,
  DELEGAT NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CONTLIN NUMBER(20,0),
  VALINREG NUMBER(20,7),
  TVANEEX NUMBER(20,7),
  VALACHIZ NUMBER(20,7),
  VALACHIZVAL NUMBER(20,7),
  CODIOART NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  CANTT NUMBER(20,7),
  CANT NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  FURN NUMBER(20,0),
  GESTFURN NUMBER(20,0),
  NRCERTIF VARCHAR2(3200),
  DATAACHIZ DATE,
  SERIELOT VARCHAR2(100),
  PMPVALUTA NUMBER(20,7),
  PMPDOC NUMBER(20,7),
  PMPVALUTADOC NUMBER(20,7),
  PMP NUMBER(20,7),
  MAXCODNIRSTOC NUMBER(20,0),
  PARTCUSTODIE NUMBER(20,0),
  TG VARCHAR2(3200),
  SERIE VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_MATRCV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6A47C3E63F7DA8BCBE491D62EC6011C171ADCB8E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_MATRCV (
  TIPLINIE NUMBER(5,0),
  CODCONT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODCONT9 NUMBER(20,0),
  VALALOC NUMBER(20,7),
  VALNEALOC NUMBER(20,7),
  VANZARI NUMBER(20,7),
  MARFURI NUMBER(20,7),
  ALTEACTIV NUMBER(20,7),
  ELEMFINANC NUMBER(20,7),
  ELEMEXCEPT NUMBER(20,7),
  CHIMPPROF NUMBER(20,7),
  VALTOT NUMBER(20,7),
  TOTALTIP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_NAPR2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B513DE6CDF1F515C220C67EBC5663A625B9CDDD1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_NAPR2 (
  CODOBIECT NUMBER(20,0),
  CODUM1 NUMBER(20,0),
  ARTICOL VARCHAR2(200),
  UM VARCHAR2(50),
  TOTVANZ NUMBER(30,7),
  MEDIEVANZ NUMBER(30,7),
  NECESAR NUMBER(30,7),
  STOCREAL NUMBER(30,7),
  CODEXTERN VARCHAR2(100),
  CODINTERN VARCHAR2(100),
  PRODUCATOR VARCHAR2(200),
  STOCMIN NUMBER(30,7),
  STOCMED NUMBER(30,7),
  STOCMAX NUMBER(30,7),
  CANTC_CF NUMBER(30,7),
  CANTA_CF NUMBER(30,7),
  RESTA_CF NUMBER(30,7),
  CANTC_CC NUMBER(30,7),
  CANTA_CC NUMBER(30,7),
  RESTA_CC NUMBER(30,7),
  CANTC_CSIN NUMBER(30,7),
  CANTA_CSIN NUMBER(30,7),
  RESTA_CSIN NUMBER(30,7),
  CANTC_CSIES NUMBER(30,7),
  CANTA_CSIES NUMBER(30,7),
  RESTA_CSIES NUMBER(30,7),
  CANTC_CG NUMBER(30,7),
  CANTA_CG NUMBER(30,7),
  RESTA_CG NUMBER(30,7),
  CANTC_CIIN NUMBER(30,7),
  CANTA_CIIN NUMBER(30,7),
  RESTA_CIIN NUMBER(30,7),
  CANTC_CIIES NUMBER(30,7),
  CANTA_CIIES NUMBER(30,7),
  RESTA_CIIES NUMBER(30,7),
  REZERVAT NUMBER(30,7),
  ULTFURN VARCHAR2(200),
  ULTPRACHIZ NUMBER(30,7),
  CANTC_CSERV NUMBER(20,7),
  CANTA_CSERV NUMBER(20,7),
  RESTA_CSERV NUMBER(20,7),
  CODULTFURN NUMBER(20,0),
  MEDIEVANZZ NUMBER(30,7),
  IESNED NUMBER(20,7),
  IES12 NUMBER(20,7),
  IES3 NUMBER(20,7),
  NECESAR2 NUMBER(20,7),
  ULTCANT NUMBER(20,7),
  PULTFURN VARCHAR2(200),
  PULTPRACHIZ NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_NAPR6</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3E4541D7DA396AF76DD3DFD41B7B9842BF588AC3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_NAPR6 (
  DENUMIRE VARCHAR2(200),
  STOCMIN NUMBER(20,7),
  STOC NUMBER(20,7),
  CANT NUMBER(20,7),
  CANTPREC NUMBER(20,7),
  RATA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  UM VARCHAR2(15),
  CODUM1 NUMBER(20,0),
  CODOBIECT NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  PRODUCATOR VARCHAR2(200),
  ULTFURN VARCHAR2(200),
  ULTPRACHIZ NUMBER(20,7),
  CODULTFURN NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  ZILE NUMBER(10,0),
  VANZARI NUMBER(20,7),
  DATACMD DATE,
  CODPART NUMBER(20,0),
  PERAPROVIZ NUMBER(10,0),
  NECESART NUMBER(20,7),
  CODCATALOG VARCHAR2(60),
  IES12 NUMBER(20,7),
  IES3 NUMBER(20,7),
  NECESAR2 NUMBER(20,7),
  ULTCANT NUMBER(20,7),
  PULTFURN VARCHAR2(200),
  PULTPRACHIZ NUMBER(30,7),
  RESTA_CF NUMBER(30,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PART1CRM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C8D8FB12D2596555E7903AD05899245D20CA442</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PART1CRM (
  CODPART NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DEN_ACTIVIT VARCHAR2(50),
  ALSTART NUMBER(20,0),
  ALSTOP NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PARTCOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3859B83C25515A300672684D9676A1CCD676CDEE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PARTCOM (
  CODPART NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  SOLD NUMBER(20,7),
  SOLDTVA NUMBER(20,7),
  CREDIT NUMBER(20,7),
  VALP_COMNEFACT NUMBER(20,7),
  VALA_COMNEFACT NUMBER(20,7),
  TERMENDEPASIT NUMBER(20,7),
  SOLDDEP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PREGLIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3D699DD35F6DD48F014EA35EA9DC5A1584873C40</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PREGLIVR (
  TRASEU VARCHAR2(100),
  POZTRASEU NUMBER(20,0),
  CLIENT VARCHAR2(100),
  SERIEDOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SOFER VARCHAR2(401),
  MIJLTRANSP VARCHAR2(100),
  NRTRANSP VARCHAR2(20),
  MASADOC NUMBER(20,7),
  VOLUMDOC NUMBER(20,7),
  MASATRASEU NUMBER(20,7),
  VOLUMTRASEU NUMBER(20,7),
  MASAUTILA NUMBER(20,7),
  VOLUMUTIL NUMBER(20,7),
  CODTRASEU NUMBER(20,0),
  LUNGTRANSP NUMBER(10,0),
  LATTRANSP NUMBER(10,0),
  INALTTRANSP NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PROFIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>581593B208F657A24442CA389F443F7ED7746AE2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PROFIT (
  CURS NUMBER(20,7),
  TIPDOC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CLIENT VARCHAR2(200),
  COEFDISCMAJ NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  ADDIM NUMBER(20,7),
  AGENT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TRANSPORT NUMBER(20,7),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(20),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTIES NUMBER(20,7),
  CANTIN NUMBER(20,7),
  UMSEC NUMBER(20,0),
  PRETVANZ NUMBER(20,7),
  DISCVANZ NUMBER(20,7),
  PROCDISCVANZ NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PRETFURN NUMBER(20,7),
  FURN NUMBER(20,0),
  VALDISCINTR NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  PRETMAX NUMBER(20,7),
  PRETACHIZC NUMBER(20,7),
  PRETINREGC NUMBER(20,7),
  TERMEDIES NUMBER(20,0),
  TERMEDIN NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CURSDOC NUMBER(20,7),
  CODGESTPROD NUMBER(20,0),
  CURSREFACHIZ NUMBER(20,7),
  CURSREFVANZ NUMBER(20,7),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PROMO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0DE1F03D4F1330E082243A48ED7B4E70B4412F36</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PROMO (
  CODPROMO NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  NRSUBUNIT NUMBER(20,0),
  LISTSUBUNIT VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_PROMOPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>586F149949FB511DA2B28ADBA31DAF9220CD7016</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_PROMOPART (
  CODPROMO NUMBER(20,0),
  DEN_PART VARCHAR2(3200),
  DEN_CLASEP VARCHAR2(3200),
  CIF VARCHAR2(3200),
  AUTORIZATIE VARCHAR2(3200),
  REGCOM VARCHAR2(3200),
  DEN_LOCALIT VARCHAR2(3200),
  COD_PART VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_RB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>904C179DFF332F2BB94A77FBD25EE2209EEC0D57</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_RB (
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DATAREG DATE,
  DOCCUMUL VARCHAR2(100),
  PREFIXDOC VARCHAR2(30),
  SERIEDOC VARCHAR2(30),
  NRI VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  AGENT NUMBER(20,0),
  EXPLICATII VARCHAR2(100),
  DEN_PART VARCHAR2(200),
  CONT NUMBER(20,0),
  OBS VARCHAR2(500),
  TIPTRANZ NUMBER(5,0),
  VAL NUMBER(20,7),
  VALDOC NUMBER(20,7),
  CURS NUMBER(20,7),
  CODBANCA NUMBER(20,0),
  SOLD_COL NUMBER(20,7),
  SOLDLEI_COL NUMBER(20,7),
  ORDINE NUMBER(5,0),
  SUBUNITATEA NUMBER(20,0),
  IDXLOC NUMBER(5,0),
  ANLUNA NUMBER(5,0),
  CODPART NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODGEST NUMBER(20,0),
  USERID NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_RECEPTII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1D71AF799533E29DD485E7E1256B0A9702ED184C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_RECEPTII (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  USERID NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CODIES NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  NRNIR NUMBER(20,0),
  DATANIR DATE,
  TIPNIR NUMBER(5,0),
  GEST NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  CODCLASEG NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODUMNIR NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  ARETVANEEX NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  CONT NUMBER(20,0),
  CODTVA NUMBER(20,0),
  PROCTVA NUMBER(6,3),
  CODARTICOL NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODUM1 NUMBER(20,0),
  CODUM2 NUMBER(20,0),
  CLASASTATIST NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OPERAT VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_SCAD_PARTVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F22E1267AB0F6762C2AD8458C899CB0C99450192</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_SCAD_PARTVAL (
  PARTENER NUMBER(20,0),
  PARTVALIESAC NUMBER(20,7),
  PARTVALIESAP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_SCAD_SERTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8975BE5F9D33EECD8D8CAE1FBF3F4D41E9A183BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_SCAD_SERTAR (
  CODOBLIGPIF NUMBER(20,0),
  DECONT VARCHAR2(3200),
  DOC VARCHAR2(3200),
  SER VARCHAR2(3200),
  NRDOC VARCHAR2(3200),
  DATADOC VARCHAR2(3200),
  VALOARE NUMBER(20,7),
  DATADECONT VARCHAR2(3200),
  VALASOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_SCAD_STINS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C5C2BF11FDB2716998A95F3DD46FEC4C72A0E9D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_SCAD_STINS (
  CODSTINSPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_SITCONSUM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0DFF87A7323127288AA79A8F0859A13B32C329F5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_SITCONSUM (
  CODIES NUMBER(20,0),
  CODLIVR NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  CODIOART1 NUMBER(20,0),
  GEST NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  NAV_CODDOC NUMBER(30,7),
  NAV_TIPDOC NUMBER(30,7),
  PREFIXDOC VARCHAR2(10),
  NRDOC NUMBER(30,7),
  DATADOC DATE,
  DOCIESIRE VARCHAR2(150),
  GEST_PROD VARCHAR2(100),
  GEST_SURSA VARCHAR2(100),
  DENUMIRE VARCHAR2(200),
  PRODUS VARCHAR2(200),
  CONT VARCHAR2(100),
  CHELTUIELI VARCHAR2(30),
  PU NUMBER(30,7),
  CANT NUMBER(30,7),
  UM VARCHAR2(50),
  VALOARE NUMBER(30,7),
  MASINA VARCHAR2(30),
  PERS VARCHAR2(300),
  CANTUM1 NUMBER(30,7),
  CANTUM2 NUMBER(30,7),
  UM1 VARCHAR2(50),
  UM2 VARCHAR2(50),
  SERII VARCHAR2(3200),
  SERCANT VARCHAR2(3200),
  SEROBS VARCHAR2(3200),
  TIPRETETA VARCHAR2(30),
  NRCI NUMBER(30,7),
  DATACI DATE,
  NRCC NUMBER(30,7),
  DATACC DATE,
  CLIENT VARCHAR2(100),
  PMP NUMBER(30,7),
  PMPVALUTA NUMBER(30,7),
  PMPPREC NUMBER(30,7),
  PMPPRECVAL NUMBER(30,7),
  PRETACHIZ NUMBER(30,7),
  VALACHIZ NUMBER(30,7),
  SERIIPROD VARCHAR2(3200),
  NRNP VARCHAR2(3200),
  CODLIVR1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_SITDATORII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0AB09CA1357DE6BEFC1B070411EA32A20FEBDF5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_SITDATORII (
  TAB NUMBER(1,0),
  CODOBLIGPIF NUMBER(20,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  TERMEN DATE,
  ZILESCADENTE NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100),
  SUBUNITATEA NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  CODLOCATIE NUMBER(20,0),
  SEDIU VARCHAR2(100),
  CECNEINCASAT NUMBER(1,0),
  OBS VARCHAR2(500),
  AGENT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STINGATORI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>29BE38059D6A98961C4E5E9007FABAC3B67E21A5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STINGATORI (
  CODOBLIGPIF NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOCS NUMBER(20,0),
  TIPDOCS NUMBER(20,0),
  DOCSTINGATOR VARCHAR2(100),
  DATADECONT DATE,
  DATADOC DATE,
  DATAINC DATE,
  AGENT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODSTINSPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALFTVA NUMBER(20,7),
  CURS NUMBER(20,7),
  MONEDA NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  CODBANCA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STINSI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88F82B6DFC57749D8C5AB76CD38C7D781AB509BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STINSI (
  CODOBLIGSTINGATOR NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECT1 NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  DOCSTINS VARCHAR2(100),
  DATADOC DATE,
  SUBUNITATEA NUMBER(20,0),
  CURS NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARELINIE NUMBER(20,7),
  VALDOC NUMBER(20,7),
  VALOBLIGLINIE NUMBER(20,7),
  COEFTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  TERMEN DATE,
  AGENT NUMBER(20,0),
  CONT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODBANCA NUMBER(20,0),
  REST NUMBER(20,7),
  RESTLINIE NUMBER(20,7),
  TIPSTOC NUMBER(1,0),
  GESTACT NUMBER(20,0),
  PRETVANZ NUMBER(20,7),
  CANT NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  GESTDEN VARCHAR2(3200),
  GESTSIMB VARCHAR2(3200),
  FURNIZORI VARCHAR2(3200),
  INFOCM NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C255729FF027A5E617F480E74585E6445B2371CB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOC (
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  CODCERTIF NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(3,0),
  CODLOCATIE NUMBER(20,0),
  GEST NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INTRATLA DATE,
  ANLUNA NUMBER(5,0),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRIDOC VARCHAR2(50),
  OBSDOC VARCHAR2(500),
  OBSDOC1 VARCHAR2(4000),
  DOC VARCHAR2(54),
  XCODTRANSF NUMBER(20,0),
  XCODIES NUMBER(20,0),
  XCODINTR NUMBER(20,0),
  PRET NUMBER(20,7),
  PRETACHIZ NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  ADAOSUNITAR NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  FURN NUMBER(20,0),
  CODIOART1 NUMBER(20,0),
  ARETVANEEX NUMBER(1,0),
  MG NUMBER(1,0),
  CONT NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  PUVAL NUMBER(20,7),
  PRDOC NUMBER(20,7),
  MONEDADOC NUMBER(20,0),
  REZERVAT NUMBER(20,7),
  REZERVATUM1 NUMBER(20,7),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  CANTSER NUMBER(30,15),
  SERIE VARCHAR2(75),
  OBSSER VARCHAR2(200),
  NRCERTIFSER VARCHAR2(100),
  DATAPRIMIRE DATE,
  DATAPROD DATE,
  PROVENIENTA VARCHAR2(250),
  DEN_TARA VARCHAR2(30),
  OBSCERTIF VARCHAR2(250),
  STARE VARCHAR2(50),
  TG DATE,
  ZILEEXP NUMBER(20,0),
  STAREDD VARCHAR2(13),
  ROOTCC NUMBER(20,0),
  PRETORIG NUMBER(20,7),
  CURSDOC NUMBER(20,7),
  SERII VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_IES_PER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DCB590FC4F8976F45399A89B5FF5E63609DE5D8A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_IES_PER (
  CODOBIECT NUMBER(20,0),
  GEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTAS NUMBER(20,7),
  CANTT NUMBER(20,7),
  VALTOTACH NUMBER(20,7),
  VALTOTOUT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_LAST_NS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51938CB29EBEDEF5CA02FF26D5E0683387942F43</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_LAST_NS (
  CODOBIECT NUMBER(20,0),
  CODNIRSTOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_STOCCOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7C1258CD83566DE8F8FE3DD2548CEF0000919E0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_STOCCOM (
  CODOBIECT NUMBER(20,0),
  RESTCOM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_STOCPER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB5CA44763C4A283A979AF1FF3C40312423A6607</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_STOCPER (
  CODOBIECT NUMBER(20,0),
  GEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  STOCFIN NUMBER(20,7),
  PZISTOC NUMBER(20,7),
  UZISTOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_STOCREAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4164D29E889C0D3CF379AECAAA57864C21CB0C4A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_STOCREAL (
  CODOBIECT NUMBER(20,0),
  GEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CANT NUMBER(20,7),
  VALTOTIN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCEP_STOCREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1A9A945287D8EA9BFAE5DF2AB128869BA1DD1CD3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCEP_STOCREZ (
  CODOBIECT NUMBER(20,0),
  REZERVAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_STOCOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB48B8298AA3326CEC173EA22B9096F42A64000D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_STOCOBJ (
  CODOBIECT NUMBER(20,0),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_TABS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B93F18591410A9BB267F36A6F4CC857DF1A5F914</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_TABS (
  ORDINE NUMBER(5,0),
  TABLENAME CLOB,
  ALIASNAME VARCHAR2(100),
  JOINCOND VARCHAR2(3200),
  FORCEVALID NUMBER(1,0),
  ISVIEW NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_TOP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EC7DB8D9FBFA6AB978E984EB8CD3AE3029BDD6F2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_TOP (
  CODPART NUMBER(20,0),
  VALTOT NUMBER(20,7),
  VALTOTCUTVA NUMBER(20,7),
  VALTOT_VAL NUMBER(20,7),
  VALTOTCUTVA_VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_TOPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B6564FE4C3BBE8ACEFEF9915F15B5B756B86E038</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_TOPART (
  TIPARTICOL CHAR(10),
  CODOBIECT NUMBER(20,0),
  CODFURN NUMBER(20,0),
  TIPFURN NUMBER(10,0),
  CANT NUMBER(20,7),
  VALACHLEI NUMBER(20,7),
  VALLEI NUMBER(20,7),
  TVALEI NUMBER(20,7),
  DATADOC DATE,
  DOC VARCHAR2(100),
  SUBUNITATEA VARCHAR2(100),
  VALADAOSLEI NUMBER(20,7),
  CURS NUMBER(20,7),
  CANTACHIZ NUMBER(20,7),
  FURNIZOR VARCHAR2(2500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_TVAINCAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>42C85C4D5E9E3B5DCAA199FF2EC0BEF320A76887</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_TVAINCAS (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  DATASTINGERE DATE,
  VALSTINSA NUMBER(20,7),
  DATASTOP DATE,
  COEF NUMBER(30,17),
  COEFBAZA NUMBER(30,17),
  COEFTVA NUMBER(30,17),
  TIPSTINGERE NUMBER(20,0),
  PREFIXSTINGERE VARCHAR2(30),
  NRSTINGERE NUMBER(20,0),
  COEFDOC NUMBER(30,17),
  COEFDOCBAZA NUMBER(30,17),
  COEFDOCTVA NUMBER(30,17),
  ORDDOC NUMBER(20,7),
  COUNTDOC NUMBER(20,7),
  COEFPLATA NUMBER(30,17),
  COEFPLATABAZA NUMBER(30,17),
  COEFPLATATVA NUMBER(30,17),
  RESTDOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_URMARTPEFURN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B984FEA44A3D9E755B700C967C1544AABABCCA70</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_URMARTPEFURN (
  DATA DATE,
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_URMCONTR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3A10B10C84C718FF261EB83ECE53DE78AE98E9CD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_URMCONTR (
  CODCONTRACT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  IDXDOC NUMBER(20,0),
  INTRARE NUMBER(1,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CANT NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PU NUMBER(20,7),
  TVA NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  CODPART NUMBER(20,7),
  CODCONT NUMBER(20,7),
  CODCOMANDA1 NUMBER(20,0),
  CANTSOLD NUMBER(20,7),
  CANTDOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_URMCONTRARENDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C637D12F9BAA223A22B8EDF5AF51D8A0493BC537</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_URMCONTRARENDA (
  CODCONTRACT NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  CODBONA NUMBER(20,0),
  CODFPN NUMBER(20,0),
  CODAEPN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_URMINCMON</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B94DF4D14DD38A47FA3AFD2A116B459AF2DE7312</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_URMINCMON (
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DATADOC DATE,
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CURS NUMBER(20,7),
  MONEDA NUMBER(20,0),
  AGENT NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  DOC VARCHAR2(100),
  CODOBIECT NUMBER(20,0),
  CODOBIECT1 NUMBER(20,0),
  CONT NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALLIN NUMBER(20,7),
  TVALIN NUMBER(20,7),
  COEFTVA NUMBER(20,7),
  PRETVANZ NUMBER(20,7),
  CANT NUMBER(20,7),
  CODBANCA NUMBER(20,0),
  TIPSTOC NUMBER(1,0),
  GESTACT NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  GESTDEN VARCHAR2(3200),
  GESTSIMB VARCHAR2(3200),
  FURNIZORI VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_URMPLARTIART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F53AD4AE076798AFD216F8811307A89D04A3BB66</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_URMPLARTIART (
  NAV_CODDOC NUMBER(20,0),
  NAV_CODDOC1 NUMBER(20,0),
  NAV_TIPDOC NUMBER(20,0),
  DSTINSPR VARCHAR2(30),
  DSTINSNR VARCHAR2(30),
  DSTINSDATA DATE,
  TOTAL_DOCUMENT NUMBER(20,7),
  VAL_STINGATOR NUMBER(20,7),
  VAL_STINGFTVA NUMBER(20,7),
  COEFTVA NUMBER(20,7),
  SOLD_LIN NUMBER(20,7),
  SOLD_DOC NUMBER(20,7),
  ORDINE NUMBER(20,0),
  ORDLIN NUMBER(20,0),
  DSTINGPR VARCHAR2(30),
  DSTINGNR VARCHAR2(30),
  DSTINGDATA DATE,
  DATADECONT DATE,
  DATA DATE,
  DATAPLATA DATE,
  DATA_STINS DATE,
  TERMEN DATE,
  SCADENTA DATE,
  DIFZILE NUMBER(5,0),
  DEPZILE NUMBER(5,0),
  DEPZILEDEC NUMBER(5,0),
  DEPZILEPLATA NUMBER(5,0),
  CODPART NUMBER(20,0),
  AGENT_STING NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DSTINSCURS NUMBER(20,7),
  MONEDA NUMBER(20,0),
  DSTINSSUB NUMBER(20,0),
  DSTINGSUB NUMBER(20,0),
  DSTINSAN NUMBER(4,0),
  DSTINSLUNA NUMBER(2,0),
  DSTINGAN NUMBER(4,0),
  DSTINGLUNA NUMBER(2,0),
  DSTINGCURS NUMBER(20,0),
  CODBANCA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_VALACHIZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8531C97B83A4FB332B3F386D9AA1238A3759E79E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_VALACHIZ (
  CODLIVR1 NUMBER(20,0),
  VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LST_VENITURIRAC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BFB891FC05BD80FF802BBB8543B611C426182148</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LST_VENITURIRAC (
  NAV_CODDOC NUMBER(20,0),
  NAV_TIPDOC NUMBER(20,0),
  REZERVARE NUMBER(20,0),
  DATAREZ DATE,
  NRREF VARCHAR2(100),
  SERIAREZ VARCHAR2(20),
  TIPREZ VARCHAR2(9),
  GESTIUNE VARCHAR2(100),
  CLIENT VARCHAR2(100),
  NRAUTO VARCHAR2(15),
  ARTICOLE VARCHAR2(200),
  CLASAAUTO VARCHAR2(250),
  PRETOFERTA NUMBER(20,7),
  PUREZ NUMBER(20,7),
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  Z NUMBER,
  DURATA NUMBER,
  DEPASIRE NUMBER,
  K NUMBER,
  VALTOTALA NUMBER,
  CODGEST NUMBER(20,0),
  CATE NUMBER,
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PU NUMBER,
  PROCENT NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_LUNA_RECORDS_FLAGS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B10F85D196EA474B8E03E3E6733513EBEAB29553</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_LUNA_RECORDS_FLAGS (
  USERID NUMBER(20,0),
  NART_FLG NUMBER(1,0),
  NARTOBJ_FLG NUMBER(1,0),
  IOART_FLG NUMBER(1,0),
  NTVA_FLG NUMBER(1,0),
  NTAXE_FLG NUMBER(1,0),
  IOPART_FLG NUMBER(1,0),
  IOPERS_FLG NUMBER(1,0),
  TARIFE_FLG NUMBER(1,0),
  PRETM_FLG NUMBER(1,0),
  IOFILIAL_FLG NUMBER(1,0),
  IOBANK_FLG NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MACHETE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BA6FD97CFB0D5B4088BB0817EE2C4BC69537AE44</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MACHETE (
  CODMACHETA NUMBER(20,0),
  PREFIX VARCHAR2(3),
  NUMEPRESC VARCHAR2(15),
  NUMEEXT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MAILURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EB4150B8D85DEC6B7A0306D6C45EB336C4F5C01A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MAILURI (
  CODMAIL NUMBER(20,0),
  SENDER VARCHAR2(200),
  RECIPIENTS VARCHAR2(500),
  SUBJECT VARCHAR2(200),
  MESSAGE VARCHAR2(3000),
  USERID NUMBER(20,0),
  DATA DATE,
  STATUS NUMBER(1,0),
  EROARE VARCHAR2(3000),
  HOST VARCHAR2(200),
  PORT NUMBER(20,0),
  DOMAIN VARCHAR2(200),
  CODFIRMA NUMBER(20,0),
  CODSERVER NUMBER(20,0),
  MSG CLOB,
  CODDOC1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  WEBSERVER NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MAILURI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>999B01792B9E0659D5A5C2A39BF7AD3A92D77842</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MAILURI1 (
  CODMAIL1 NUMBER(20,0),
  CODMAIL NUMBER(20,0),
  FILENAME VARCHAR2(100),
  ATTACHFILE BLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MAILURIDOCS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6003533900C028CB3134849C2A4F70467BDDA59</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MAILURIDOCS (
  CODMAILDOC NUMBER(20,0),
  CODMAIL NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODAGENDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A1EFB721732C6F54A1757C72087A82B92E342EE6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA (
  CODUNIC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4FE021298218954C806E37C4273A95AAB210AD5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA2 (
  CODUNIC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6AB8731B6E738BCF99F7E6A8E322D8ECF4F0611A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA3 (
  CODUNIC NUMBER(20,0),
  VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRACHAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C0E117AF474A3AB717A7342BF1B795537ADA06D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRACHAR (
  VALOARE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_285</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>098020C5D6CFA8509FA99B70A152FEA51DAF5316</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_285 (
  NAV_TIPDOC NUMBER(20,0),
  NAV_CODDOC NUMBER(10,0),
  PRODUS NUMBER(20,0),
  CANTPRODUSL NUMBER(20,7),
  CANTPRODUS NUMBER(20,7),
  MATERIAL NUMBER(20,0),
  CANTMATERIAL NUMBER(20,7),
  VALMATERIAL NUMBER(20,7),
  PRETMATERIAL NUMBER(20,7),
  CANTMATERIAL_R NUMBER(20,7),
  VALMATERIAL_R NUMBER(20,7),
  PRETMATERIAL_R NUMBER(20,7),
  BC VARCHAR2(50),
  CMD VARCHAR2(50),
  NP VARCHAR2(50),
  CODCMDPRODMAT NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSTOCCONSUM NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_COMPUSI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D9CC487D21EADC17CDFFFD842995644CB503FA6E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_COMPUSI (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  REGIE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_CONSUM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>616C0F57527BEF2A7B93F97702E8BB9B1DDB579F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_CONSUM (
  CODCOMANDA1 NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTMAT NUMBER(20,7),
  CANTPROD NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_IESSINT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E87D86D24873E9AA800036C655338FDC5F3D5BB4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_IESSINT (
  CODIES NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  CODPROMO NUMBER(20,7),
  VAL NUMBER(20,7),
  VALADDIM NUMBER(20,7),
  TVA NUMBER(20,7),
  COSTTRANSPORT NUMBER(20,7),
  DOFFIV NUMBER(20,7),
  DONIV NUMBER(20,7),
  TERMEN DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_INTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E5958105A2F5E5E3924B059CE08606676FD2F8F9</HASHVAL>
  <TEXT>CREATE TABLE TMP_MANEVRA_INTR1 (
  CODINTR1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  CANTPREDATA NUMBER(20,7),
  CODNIRSTOC NUMBER(20,0),
  PRETPREDARE NUMBER(20,7),
  NP VARCHAR2(50),
  SERIINP VARCHAR2(2500),
  SETIMANANP VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_INTR1_GRUPC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D71E09122745AD7A3F7FA3CF7DE6DD16144941A</HASHVAL>
  <TEXT>CREATE TABLE TMP_MANEVRA_INTR1_GRUPC (
  CODCMDPRODMAT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRETCONSUM NUMBER(20,7),
  CODNIRSTOCCONSUM NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  BC VARCHAR2(50),
  TIPLINIE NUMBER(10,0),
  CONT VARCHAR2(60),
  CODCMDPRODMAT_MAT NUMBER(20,0),
  CANT_MAT NUMBER(20,7),
  CANT_RET NUMBER(20,7),
  PRET_RET NUMBER(20,7),
  CANTK NUMBER(20,7),
  PRET_CONTABIL NUMBER(20,7),
  VAL_CONTABILA NUMBER(20,7),
  GESTIUNE VARCHAR2(100),
  NPS VARCHAR2(50),
  ANLUNA NUMBER(10,0),
  CODCMDPRODMAT_SEMI NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  CMDS VARCHAR2(50),
  SERIIBC VARCHAR2(2500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_INTR1_GRUPL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2FED84A27F5002CB0EED18D495F0740221E9E5DE</HASHVAL>
  <TEXT>CREATE TABLE TMP_MANEVRA_INTR1_GRUPL (
  CODCMDPRODMAT NUMBER(20,0),
  CANTPREDATA NUMBER(20,7),
  CANTLANSATA NUMBER(20,7),
  CMD VARCHAR2(50),
  ANLUNA NUMBER(10,0),
  PRET_RET NUMBER(20,7),
  UMP VARCHAR2(15)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_INTR1_GRUPO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>739608981A393B7E98FB99CBBA363C2E0B353824</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_INTR1_GRUPO (
  CODOBIECT NUMBER(20,0),
  CANTPREDATA NUMBER(20,7),
  CANTLANSATA NUMBER(20,7),
  CANTTOTALPREDATA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_LINIICOMENZI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0376CDE00CFA4625D7E951ED2A9EC72F342C8619</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_LINIICOMENZI (
  CODCOMANDA1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_LISTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F00684C79B68F431A85E456D5A2DE62BB25A2B8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_LISTE (
  FILTRU VARCHAR2(100),
  VALOARE VARCHAR2(250),
  FILTRU1 VARCHAR2(100),
  VALOARE1 VARCHAR2(250),
  FILTRU2 VARCHAR2(100),
  VALOARE2 VARCHAR2(250),
  FILTRU3 VARCHAR2(100),
  VALOARE3 VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_NIRSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>92042E86571708DCA1F79864B0E629C057D32F2E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_NIRSER (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  TG DATE,
  SERIE VARCHAR2(75),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_PREDARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>73B7542F230E82C11D2C5D65191F955D7DB8FFF0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_PREDARI (
  CODCOMANDA1 NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_PRETURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>35901FA339678326F78D9E4D10597A0E6824B998</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_PRETURI (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  STARE NUMBER(1,0),
  DEN_CLASEAS VARCHAR2(50),
  CURS NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTEKIV NUMBER(20,0),
  DENUMIREEKIV VARCHAR2(200),
  OBJ_CODEXTERN VARCHAR2(80),
  OBJ_CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_PRETURI_DETALII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>99392A4077A0AC2B11627849064D6AF88631BFFE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_PRETURI_DETALII (
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(20,7),
  CODNIRSTOC NUMBER(20,7),
  STARE NUMBER(1,0),
  ORDINE NUMBER(10,0),
  CANT NUMBER(20,7),
  DATAACHIZ DATE,
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  CODOBIECTGENERIC NUMBER(20,0),
  OBJ_CODEXTERN VARCHAR2(80),
  OBJ_CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANEVRA_SERII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>94CD94A37749627CEC790FD4C8369524C634056A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANEVRA_SERII (
  CODNIRSTOC NUMBER(20,0),
  SERII VARCHAR2(3200),
  FLAG NUMBER(20,0),
  SERII_IES VARCHAR2(3200),
  SERII_STOC VARCHAR2(3200),
  CODLIVR1 NUMBER(20,0),
  CODAUX1 NUMBER(20,0),
  TG VARCHAR2(3200),
  NRCERTIF VARCHAR2(3200),
  DATAPROD VARCHAR2(3200),
  SERII_AUX1 VARCHAR2(3200),
  SERII_AUX2 VARCHAR2(3200),
  SERII_OBS VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANPRETM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C0125FA871070F90557D5266E8A327AD9302C6B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANPRETM (
  CODOBIECT NUMBER(20,0),
  LEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANPRODLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>12CC07191FF90143CEECCA0C763FBA4182BB9B03</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANPRODLINK (
  CODRAPORTP2 NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MANPRODLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E612DC8F515DA75A98854D3DE774610B0E80B507</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MANPRODLINK_INITIAL (
  CODRAPORTP2 NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7),
  CODPROGRAMF1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MARIRI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C1AB49D08F9822A4EE88ADF48859FAE83C92E5F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MARIRI (
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MARIRI_SER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D368D50AF4360AD17AF2F8FBCD378AEE6F670AC3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MARIRI_SER (
  CODNIRSER NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MARIRI_STOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>972537E2A38689BC536330B994252BC3A0191C3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MARIRI_STOC (
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASCASERART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B81FF69BD2922B025FD027E8C7798C37A024DEFB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASCASERART (
  CODMASCA NUMBER(20,0),
  MASCA VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASCASERART1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>96E4A43B5A5FA8EF1FE2E5EBB40517522F7C89BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASCASERART1 (
  CODMASCA1 NUMBER(20,0),
  CODMASCA NUMBER(20,0),
  DENELEMENT VARCHAR2(100),
  VALORI VARCHAR2(100),
  ELEMENT VARCHAR2(10),
  LUNGIME NUMBER(10,0),
  FILL VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASTERCHELTAVANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D59F55DA23891E9505EC65068052E277D21CDA5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASTERCHELTAVANS (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASTERDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>645A82A2FE7E96E1BE7653EDE43A7848ACBEB7FD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASTERDOC (
  COD NUMBER(20,0),
  CODDOSAR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASTERMAK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CA378E304B353A38E9E11872E8950EFCFC52106B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASTERMAK (
  CODMASTERMAK NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(6,0),
  COD1 NUMBER(20,0),
  COD2 NUMBER(20,0),
  COD3 NUMBER(20,0),
  COD4 NUMBER(20,0),
  COD5 NUMBER(20,0),
  V1 NUMBER(20,7),
  V2 NUMBER(20,7),
  V3 NUMBER(20,7),
  V4 NUMBER(20,7),
  V5 NUMBER(20,7),
  DATA1 DATE,
  DATA2 DATE,
  OBS1 VARCHAR2(50),
  OBS2 VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MASTERMIFIX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>364172DFB229C698C0E014D9EBBCD1AB1F03FAD5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MASTERMIFIX (
  CODNIRSTOC NUMBER(20,0),
  CODCLASIF NUMBER(20,0),
  DURATAN NUMBER(10,0),
  DURATANF NUMBER(10,0),
  DURATANG NUMBER(10,0),
  CODANALIZA NUMBER(20,0),
  CODCLASIFBLOCAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D57C98040253ED261AB71B4AEBC144AE9CB70D3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX (
  CODMEDEX NUMBER(20,0),
  DATALISTA DATE,
  OBS VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEX1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4FFD27ADAECD640421F6DBD159F23BE4D7F5AFB0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX1 (
  CODMEDEX1 NUMBER(20,0),
  CODMEDEX NUMBER(20,0),
  CODCIM VARCHAR2(20),
  DENUMIRE VARCHAR2(500),
  PREZENTARE VARCHAR2(500),
  NARCOTIC NUMBER(1,0),
  FRACTIONAL NUMBER(1,0),
  SPECIAL NUMBER(1,0),
  AREBIOECHIVALENT NUMBER(1,0),
  CANT NUMBER(10,0),
  PRETAM NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRESCRIERE VARCHAR2(100),
  VALIDDELA DATE,
  VALIDPANALA DATE,
  DCI VARCHAR2(250),
  CONC VARCHAR2(250),
  FORMAFARM VARCHAR2(500),
  PRODUCATOR VARCHAR2(250),
  TARA VARCHAR2(50),
  GRUPA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEX1_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C21EAB6A05474A140CA5436AE3D46E872A0F892A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX1_LST (
  CODMEDEX1 NUMBER(20,0),
  CODMEDEX NUMBER(20,0),
  CODCIM VARCHAR2(20),
  DENUMIRE VARCHAR2(500),
  PREZENTARE VARCHAR2(500),
  NARCOTIC NUMBER(1,0),
  FRACTIONAL NUMBER(1,0),
  SPECIAL NUMBER(1,0),
  AREBIOECHIVALENT NUMBER(1,0),
  CANT NUMBER(10,0),
  PRETAM NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRESCRIERE VARCHAR2(100),
  VALIDDELA DATE,
  VALIDPANALA DATE,
  DCI VARCHAR2(250),
  CONC VARCHAR2(250),
  FORMAFARM VARCHAR2(500),
  PRODUCATOR VARCHAR2(250),
  TARA VARCHAR2(50),
  GRUPA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEX2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3CFEBC944EC0A7C6ED422A1AE6E65FC1EFB938CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX2 (
  CODMEDEX2 NUMBER(20,0),
  CODMEDEX NUMBER(20,0),
  TIPCOMPENS VARCHAR2(10),
  CODCIM VARCHAR2(20),
  CODBOALA VARCHAR2(10),
  PRETAM NUMBER(20,7),
  PRETAMUT NUMBER(20,7),
  COPLATA NUMBER(20,7),
  COPLATA90 NUMBER(20,7),
  PRETRID NUMBER(20,7),
  PRETREF NUMBER(20,7),
  LEGISPECIALE NUMBER(1,0),
  APROBARE VARCHAR2(10),
  VALPESTE NUMBER(20,7),
  SPECIALITATE NUMBER(1,0),
  INSULINA VARCHAR2(10),
  DCI VARCHAR2(250),
  GRUPA VARCHAR2(50),
  VALIDDELA DATE,
  VALIDPANALA DATE,
  NHPCODE VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEXT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>81A9F3D0A24E2414057B94BC1C049BF7CF4C8D31</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEXT (
  COD_COMERC VARCHAR2(20),
  DENUMIRE VARCHAR2(90),
  DEN_INTERN VARCHAR2(90),
  PRODUCATOR VARCHAR2(50),
  TARA VARCHAR2(30),
  PREZENTARE VARCHAR2(30),
  CONCENTRAT VARCHAR2(30),
  UM VARCHAR2(30),
  UT NUMBER(16,0),
  FORMA VARCHAR2(50),
  LISTE_NEW VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MEDEX_TARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>729075648081C905222E1C486E180C047CE2C108</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MEDEX_TARI (
  CODMEDEXT NUMBER(20,0),
  CODMEDEX NUMBER(20,0),
  COD VARCHAR2(50),
  TARA VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENUDASH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>369DCE6B37237623F3D7D8AC5D11009FA04E272F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENUDASH (
  CODMENUDASH NUMBER(20,0) NOT NULL,
  CAPTION VARCHAR2(250),
  MODUL NUMBER(2,0),
  MENU NUMBER(2,0),
  PROG NUMBER(2,0),
  UNI NUMBER(1,0),
  LISTID NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENUDASH0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D05C88ACA43612EDCDABFD88560A524240590FC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENUDASH0 (
  CODMENUDASH0 NUMBER(20,0) NOT NULL,
  CODMENUDASH NUMBER(20,0),
  AUTOSHOW NUMBER(2,0),
  USERID NUMBER(20,0),
  CONFIG BLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENUDASH1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CE0765530056E09B397109AE380D98ED35EDFC66</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENUDASH1 (
  CODMENUDASH1 NUMBER(20,0) NOT NULL,
  CODMENUDASH NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0),
  NUME VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENUDATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB93A3A4DDFA3BBDAA0F2283AFEC6C28CC1E3350</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENUDATE (
  CODMENUDATE NUMBER(20,0),
  DEN_MENU VARCHAR2(100),
  USERID VARCHAR2(20),
  NRBUTON NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENUDATE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9ABE2BAF45D887A8BFCAD86D1FAC9C2DC78D6320</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENUDATE1 (
  CODMENUDATE1 NUMBER(20,0),
  CODMENUDATE NUMBER(20,0),
  DEN_MENU VARCHAR2(100),
  ACTION VARCHAR2(100),
  INDEXLOCAL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MENULISTE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4B9F9B3BD13CED7B0594C401600E4EFAA01955D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MENULISTE1 (
  CODMENU1 NUMBER(20,0) NOT NULL,
  CODMENU NUMBER(20,0),
  CODJOB1 NUMBER(20,0),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MESE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>810BA1FA0D5559EC4893EBA29D4D9FE8CD98C496</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MESE (
  CODMASA NUMBER(20,0),
  CODSALA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  STARE NUMBER(5,0),
  X NUMBER(10,0),
  Y NUMBER(10,0),
  WIDTH NUMBER(10,0),
  HEIGHT NUMBER(10,0),
  NUMARLOCURI NUMBER(10,0),
  TEXTAFISARE VARCHAR2(100),
  FORMA NUMBER(1,0),
  BLOCATA NUMBER(1,0),
  USERID NUMBER(20,0),
  CODOSPATAR NUMBER(20,0),
  MODPLATAIMPLICIT NUMBER(3,0),
  PROTOCOL NUMBER(1,0),
  DENSALA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MESE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>680170FDFF912BFEC19DEF0F24739645DFFDCF5C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MESE1 (
  CODMASA1 NUMBER(20,0),
  CODMASA NUMBER(20,0),
  CODOSPATAR NUMBER(20,0),
  OSPATAR VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MFCLASIF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>971574443FF58FDDAF3BA24454D17B565CBB9E1B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MFCLASIF (
  CODCLASIF NUMBER(20,0),
  DENUMIRE VARCHAR2(1200),
  SIMBOL VARCHAR2(20),
  DURATA NUMBER(6,0),
  DURATAF NUMBER(6,0),
  DURATAG NUMBER(6,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MIFIX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4EF005AED612D880F98580F45B7D918F0A45AF77</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MIFIX (
  CODTMPMIFIX NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  TIP VARCHAR2(2),
  NRINVENTAR NUMBER(20,0),
  ANINTRARE NUMBER(4,0),
  LUNAINTRARE NUMBER(2,0),
  CODMIFIX1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  CODCLASIF NUMBER(20,0),
  TIPAMO NUMBER(3,0),
  STARE NUMBER(3,0),
  DURATAN NUMBER(10,0),
  GRADU NUMBER(8,4),
  DURATAF NUMBER(10,0),
  AMO NUMBER(20,7),
  NEUTIL NUMBER(20,7),
  DFBLOCAT NUMBER(1,0),
  CODPERS NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODNIRSER NUMBER(20,0),
  PLECAT NUMBER(1,0),
  CODNIRSTOCVECHI NUMBER(20,0),
  CODMIFIX1VECHI NUMBER(20,0),
  CANTMIFIX1VECHI NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  SERIE VARCHAR2(75),
  TIPREEVAL NUMBER(1,0),
  PRETREEVAL NUMBER(20,7),
  AMOREEVAL NUMBER(20,7),
  DATAREEVAL DATE,
  INCLUDRATA NUMBER(1,0),
  AMOVECHI NUMBER(20,7),
  PRETVECHI NUMBER(20,7),
  NEUTILVECHI NUMBER(20,7),
  CODSERIE NUMBER(20,0),
  CODNIRSTOCNOU NUMBER(20,0),
  NEUTILREEVAL NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  NRDOCREEVAL NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  AMOLUNA NUMBER(20,7),
  AMOINI NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DENLOCATIE VARCHAR2(200),
  OBS VARCHAR2(30),
  DURATANF NUMBER(10,0),
  DURATAFF NUMBER(10,0),
  AMOF NUMBER(20,7),
  DURATANG NUMBER(10,0),
  DURATAFG NUMBER(10,0),
  AMOG NUMBER(20,7),
  ANINTRAREG NUMBER(4,0),
  LUNAINTRAREG NUMBER(2,0),
  DFBLOCAT_F NUMBER(1,0),
  DFBLOCAT_G NUMBER(1,0),
  PRETINITIAL NUMBER(20,7),
  REZERVA NUMBER(20,7),
  REZERVABLOCAT NUMBER(1,0),
  CODSABLON NUMBER(20,0),
  SERIEINV VARCHAR2(30),
  AMOBLOCAT NUMBER(1,0),
  CODMIFIXIMB NUMBER(20,0),
  INFOMFIMB VARCHAR2(100),
  CENTRUBLOCAT NUMBER(1,0),
  CODCLASIFBLOCAT NUMBER(1,0),
  CODPERSBLOCAT NUMBER(1,0),
  NODANALIZABLOCAT NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  AMOREZERVA NUMBER(20,7),
  AMORBLOCAT NUMBER(1,0),
  AMOFBLOCAT NUMBER(1,0),
  AMOGBLOCAT NUMBER(1,0),
  CODLOCATIESTOC NUMBER(20,0),
  PRETINIBLOCAT NUMBER(1,0),
  PRETINITIAL_F NUMBER(20,7),
  PRETINITIAL_FBLOCAT NUMBER(1,0),
  UTILAJ VARCHAR2(300),
  CODUTILAJ NUMBER(20,0),
  TIPSTORNO NUMBER(1,0),
  AMOANPREC NUMBER(20,7),
  CODMIFIXVECHI NUMBER(20,0),
  NRINVENTARVECHI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MIFIX1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>50CEE0CC5BAD3FC63AC24CFFF2C4E14D99F03EEE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MIFIX1 (
  CODMIFIX1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  CODCLASIF NUMBER(20,0),
  TIPAMO NUMBER(3,0),
  STARE NUMBER(3,0),
  DURATAN NUMBER(10,0),
  GRADU NUMBER(8,4),
  DURATAF NUMBER(10,0),
  AMO NUMBER(20,7),
  NEUTIL NUMBER(20,7),
  DFBLOCAT NUMBER(1,0),
  CODPERS NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODNIRSER NUMBER(20,0),
  TIPREEVAL NUMBER(1,0),
  DATAREEVAL DATE,
  INCLUDRATA NUMBER(1,0),
  AMOVECHI NUMBER(20,7),
  PRETVECHI NUMBER(20,7),
  NEUTILVECHI NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DURATANF NUMBER(10,0),
  DURATAFF NUMBER(10,0),
  AMOF NUMBER(20,7),
  DURATANG NUMBER(10,0),
  DURATAFG NUMBER(10,0),
  AMOG NUMBER(20,7),
  DFBLOCAT_F NUMBER(1,0),
  DFBLOCAT_G NUMBER(1,0),
  PRETINITIAL NUMBER(20,7),
  REZERVA NUMBER(20,7),
  REZERVABLOCAT NUMBER(1,0),
  CODSABLON NUMBER(20,0),
  AMOBLOCAT NUMBER(1,0),
  CENTRUBLOCAT NUMBER(1,0),
  CODCLASIFBLOCAT NUMBER(1,0),
  CODPERSBLOCAT NUMBER(1,0),
  NODANALIZABLOCAT NUMBER(1,0),
  CODAUTO NUMBER(20,0),
  AMOREZERVA NUMBER(20,7),
  AMORBLOCAT NUMBER(1,0),
  AMOFBLOCAT NUMBER(1,0),
  AMOGBLOCAT NUMBER(1,0),
  PRETINIBLOCAT NUMBER(1,0),
  PRETINITIAL_F NUMBER(20,7),
  PRETINITIAL_FBLOCAT NUMBER(1,0),
  TIPSTORNO NUMBER(1,0),
  AMOANPREC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MIFIXTRANSF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AFD9867E2FF540C2C71323D9F56412D055B2B0F5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MIFIXTRANSF (
  CODTMPMIFIX NUMBER(20,0),
  CANTTRANSF NUMBER(20,7),
  CODNOUNIRSTOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MIFIX_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CD500863DCFB8FE9303DFA0BBB7276179991E16E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MIFIX_INITIAL (
  CODMIFIX NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MISCARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>307B699F0C47B8135A16607BB76ABD4211FBB396</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MISCARI (
  CODOBIECT NUMBER(20,0),
  CANTINTR NUMBER(20,7),
  CANTIES NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MODIRESTCMD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D07EEA253B879894E6FE0230EA1C87147A73073</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MODIRESTCMD1 (
  CODRESTCMD1 NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DUM VARCHAR2(50),
  CANT NUMBER(20,7),
  CANTNOUA NUMBER(20,7),
  OBS VARCHAR2(100),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MODPLATA2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B938B0AB0A2757A71E7901EE1499BC3ABF80844</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MODPLATA2 (
  CODMODPLATA2 NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODCARD NUMBER(20,0),
  VALOARE NUMBER(20,7),
  SIMBOL VARCHAR2(100),
  DENUMIRE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MODPLATAIESRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>443436DC0951AC0F1CBE4C29F6B910FE52F5B655</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MODPLATAIESRETAIL (
  COD NUMBER(20,0),
  CODIESRETAIL NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  CODBANKCONT NUMBER(20,0),
  VOUCHERSGR NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MODURIPLATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>86D9319E00564D206B723EE2FA8E878AF8D487B2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MODURIPLATI (
  CODMODPLATA NUMBER(20,0),
  CODIES NUMBER(20,0),
  TIPPLATA NUMBER(5,0),
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DENMODPLATA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MONETARLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E86A58BCC22719BF956BE25F990D3D883DF3272</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MONETARLINK (
  CODMONETAR NUMBER(20,0),
  CODFACTURA NUMBER(20,0),
  NRFACTURA NUMBER(20,0),
  DATAFACTURA DATE,
  VALOARE NUMBER(20,7),
  DEN_PART VARCHAR2(100),
  CODFISCAL VARCHAR2(75),
  OBS VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MONETARLINK_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4EA546091FC0D2044E559598657006F146D1425D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MONETARLINK_INI (
  CODMONETAR NUMBER(20,0),
  CODFACTURA NUMBER(20,0),
  NRFACTURA NUMBER(20,0),
  DATAFACTURA DATE,
  VALOARE NUMBER(20,7),
  DEN_PART VARCHAR2(100),
  CODFISCAL VARCHAR2(75),
  OBS VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MON_DISCLIN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>265B23222C7C15C5C0C7289C38DEA2BF029ECA48</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MON_DISCLIN (
  CODIES1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  CALC NUMBER(1,0),
  LINVAL NUMBER(20,7),
  LINTVA NUMBER(20,7),
  DISCVAL NUMBER(20,7),
  DISCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MON_DISCPROC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8BD272F1887A570DE6A5AD3BDD66239FB7D36855</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MON_DISCPROC (
  PROCTVA NUMBER(20,7),
  REST_VAL NUMBER(20,7),
  REST_TVA NUMBER(20,7),
  DTOT_VAL NUMBER(20,7),
  DTOT_TVA NUMBER(20,7),
  DREP_VAL NUMBER(20,7),
  DREP_TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MOTIVE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F2AEDB70BEE95FD486A0215F1BCFB30F1F5BF530</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MOTIVE (
  CODMOTIV NUMBER(20,0),
  CONTINUT VARCHAR2(200),
  TIP NUMBER(2,0),
  COD VARCHAR2(50),
  MOTIV VARCHAR2(1000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MOTIVEP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>25564326E8FF404572E77D5E1C332735BAEBE857</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MOTIVEP (
  CODMOTIV NUMBER(20,0),
  DENMOTIV VARCHAR2(80),
  MOTIV VARCHAR2(240)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_MUTACMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19F8FAD31F6D93E1F5D035124B84977BDCB3FFB3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_MUTACMD (
  CODRESTCMD1 NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DUM VARCHAR2(50),
  CANT NUMBER(20,7),
  CANTMUTATA NUMBER(20,7),
  CANTINI NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NACTIVIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6A9A3F047CC83C4545E38228DCE906B9D1B1A35</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NACTIVIT (
  CODACTIVIT NUMBER(20,0),
  DEN_ACTIVIT VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62549AEC3C07D34C7D46CDD7389863E506A9631B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENDA (
  CODAGENDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  SEDIUSOCIAL NUMBER(1,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(350),
  SECTOR NUMBER(2,0),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  CODPOSTAL VARCHAR2(10),
  KM NUMBER(7,2),
  OBS VARCHAR2(100),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODTIPSEDIU NUMBER(10,0),
  CODFISCAL VARCHAR2(75),
  CODAGENT NUMBER(20,0),
  CODCLIENT VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  POZTRASEU NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODCORESP NUMBER(20,0),
  TRANSPCLIENT NUMBER(1,0),
  COEFUTILAJE NUMBER(7,2),
  SUPRAFATA NUMBER(10,2),
  MODSERVIRE NUMBER(1,0),
  IDSEDIU VARCHAR2(20),
  COD_CODFISCAL NUMBER(20,0),
  TELEFONP VARCHAR2(40),
  EDI_EXPTIP NUMBER(1,0),
  EDI_PARTTIP NUMBER(1,0),
  EDI_PARTID VARCHAR2(20),
  EDI_OBJTIP NUMBER(1,0),
  GLN VARCHAR2(13),
  GESTLIVRARE NUMBER(20,0),
  LONGITUDINE VARCHAR2(50),
  LATITUDINE VARCHAR2(50),
  OBS2 VARCHAR2(400),
  EDI_IMPTIP NUMBER(1,0),
  EDI_FURNTIP NUMBER(1,0),
  EDI_FURNID VARCHAR2(20),
  EDI_OBJTIPIMP NUMBER(1,0),
  EDI_EXPCUMUL NUMBER(1,0),
  EDI_EXPEAN NUMBER(1,0),
  EDI_OBJTIP2 NUMBER(1,0),
  CODTRASEU1 NUMBER(20,0),
  POZTRASEU1 NUMBER(20,0),
  CODANTREPOZIT VARCHAR2(20),
  ZILETRANSPORT NUMBER(3,0),
  EDI_DENUM NUMBER(1,0),
  EDI_SUBDIREXP VARCHAR2(30),
  VERFACT NUMBER(10,0),
  VERDISPLIVR NUMBER(10,0),
  VERPROFORMA NUMBER(10,0),
  VERFACTAVIZ NUMBER(10,0),
  VERAVIZIES NUMBER(10,0),
  ADRESA VARCHAR2(200),
  FACTURARE VARCHAR2(50),
  JUDET VARCHAR2(30),
  SVERFACT VARCHAR2(50),
  SVERDISPLIVR VARCHAR2(50),
  SVERPROFORMA VARCHAR2(50),
  SVERFACTAVIZ VARCHAR2(50),
  SVERAVIZIES VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2C1D6685544F7D492FBAA10642879DB86A599281</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENDA1 (
  CODAGENDA1 NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  ANSTART NUMBER(5,0),
  LUNASTART NUMBER(2,0),
  CREDITCLIENT NUMBER(18,2),
  ZILEDEPASIRE NUMBER(10,0),
  NRFACTSOLD NUMBER(20,7),
  SCADENTAV NUMBER(5,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(5,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENDA_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77BCACC83D23A62D97BA93077A24A35F1530E71C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENDA_IMPORT (
  CODAGENDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  SEDIUSOCIAL NUMBER(1,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(200),
  SECTOR NUMBER(2,0),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  CODPOSTAL VARCHAR2(10),
  KM NUMBER(7,2),
  OBS VARCHAR2(100),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODTIPSEDIU NUMBER(10,0),
  CODFISCAL VARCHAR2(75),
  CODAGENT NUMBER(20,0),
  CODCLIENT VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  POZTRASEU NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODCORESP NUMBER(20,0),
  TRANSPCLIENT NUMBER(1,0),
  COEFUTILAJE NUMBER(7,2),
  SUPRAFATA NUMBER(10,2),
  MODSERVIRE NUMBER(1,0),
  IDSEDIU VARCHAR2(20),
  COD_CODFISCAL NUMBER(20,0),
  TELEFONP VARCHAR2(40),
  EDI_EXPTIP NUMBER(1,0),
  EDI_PARTTIP NUMBER(1,0),
  EDI_PARTID VARCHAR2(20),
  EDI_OBJTIP NUMBER(1,0),
  GLN VARCHAR2(13),
  GESTLIVRARE NUMBER(20,0),
  ADRESA VARCHAR2(200),
  FACTURARE VARCHAR2(50),
  TIPSEDIU NUMBER(1,0),
  SEDIU VARCHAR2(100),
  CODINTERNPART VARCHAR2(50),
  LOCALITATE VARCHAR2(50),
  JUDET VARCHAR2(30),
  TARA VARCHAR2(30),
  CODEXTERNPART VARCHAR2(50),
  CODFISCALPART VARCHAR2(75),
  MARCAAGENT NUMBER(10,0),
  CODTRASEU1 NUMBER(20,0),
  SIMBOLTRASEULIVR VARCHAR2(20),
  SIMBOLTRASEUVIZIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENDA_PERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9CB106A964DA2B0B72A25810951E8244950DCCC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENDA_PERS (
  CODAGENDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  SEDIUSOCIAL NUMBER(1,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(200),
  SECTOR NUMBER(2,0),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  CODPOSTAL VARCHAR2(10),
  KM NUMBER(7,2),
  OBS VARCHAR2(100),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODTIPSEDIU NUMBER(10,0),
  CODFISCAL VARCHAR2(75),
  CODAGENT NUMBER(20,0),
  CODCLIENT VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  POZTRASEU NUMBER(20,0),
  ADRESA VARCHAR2(200),
  TELEFONP VARCHAR2(40)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENDA_TRASEU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>49DA6CD60E7FD7EE07C367F8234659017E53BBC3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENDA_TRASEU (
  CODAGENDA NUMBER(20,0),
  FIRMA VARCHAR2(100),
  SEDIU VARCHAR2(100),
  ZONA VARCHAR2(50),
  JUDET VARCHAR2(50),
  LOCALITATE VARCHAR2(50),
  ADRESA VARCHAR2(200),
  SSOC NUMBER(1,0),
  POZTRASEU NUMBER(20,0),
  CODTRASEULIVR NUMBER(20,0),
  LAT NUMBER(20,7),
  LNG NUMBER(20,7),
  CODPART NUMBER(20,0),
  NOU NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENTI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E24E24FB5308A14BE37E3A7763EE503A8CF3A209</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENTI1 (
  CODAGENT1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENTIPROC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6149602F793EC83B072FF5F02BDE57FC63FE48D9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENTIPROC (
  CODAGENTPROC NUMBER(20,0),
  CODAGENT1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PECLASEA NUMBER(1,0),
  CODPART NUMBER(20,0),
  PECLASEP NUMBER(1,0),
  PROC NUMBER(20,7),
  DENART VARCHAR2(200),
  DENPART VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAGENTIVAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>584EF2205CC55079FCD970EFED3ADA239CD23FF9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAGENTIVAL (
  CODAGENTVAL NUMBER(20,0),
  CODAGENT1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  VALMAX NUMBER(20,7),
  SIMBOL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E6DA0620AC6C124890C251252D215426A1D3828B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NART (
  CODARTICOL NUMBER(20,0),
  DEN_ARTICOL VARCHAR2(100),
  TIPARTICOL VARCHAR2(1),
  CLASA NUMBER(20,0),
  UM NUMBER(10,0),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  CONTIMPLICIT NUMBER(10,0),
  GESTIMPLICITA NUMBER(10,0),
  CERTIFICAT NUMBER(1,0),
  ARETG NUMBER(1,0),
  EVOLUTIEPRET NUMBER(1,0),
  CONTSERVICIU NUMBER(20,0),
  INCREMENTSERIE NUMBER(10,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  CASADEMARCAT NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CLASASTATIST NUMBER(20,0),
  COMENZIONLINE NUMBER(1,0),
  CODEXTERNART VARCHAR2(30),
  SUFIXCODEXTERN VARCHAR2(60),
  RESTNEGLIJCMD NUMBER(10,5),
  MUSAICALITATE NUMBER(1,0),
  NRZILESTOCMEDIU NUMBER(4,0),
  CODCENTRU NUMBER(20,0),
  DCI VARCHAR2(100),
  PARITATED1 NUMBER(12,7),
  PARITATED2 NUMBER(12,7),
  PARITATED3 NUMBER(12,7),
  CULOARE NUMBER(8,0),
  CLASAW NUMBER(20,0),
  CHECKISAUTENTIC NUMBER(1,0),
  PROCPERISAB NUMBER(8,4),
  CODMASCA NUMBER(20,0),
  TIPSTOC NUMBER(2,0),
  CONSTRUCTIENOUA NUMBER(1,0),
  RISCFISCAL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NART1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A8AB88428FADBF18774FAE34A6174C381CA5BC0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NART1 (
  CODARTICOL1 NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODTVA NUMBER(10,0),
  CODACCIZE NUMBER(10,0),
  CODTAXA1 NUMBER(10,0),
  CODTAXA2 NUMBER(10,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODACCIZEDVI NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  TAXCODE NUMBER(20,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTAMB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C6B75AF74D4138BC2611C8B3DF36A4459122C6B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTAMB (
  CODAMB NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTRETURN NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODEXTERN VARCHAR2(40),
  CODPLU NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  MASA NUMBER(20,7),
  LUNGIME NUMBER(20,7),
  LATIME NUMBER(20,7),
  INALTIME NUMBER(20,7),
  LXLAT NUMBER(1,0),
  LXH NUMBER(1,0),
  LATXH NUMBER(1,0),
  GREUTSPECIFICA NUMBER(20,7),
  IMPLICITTIPDOC NUMBER(20,0),
  TIP NUMBER(1,0),
  RETURNABIL NUMBER(1,0),
  NR_RANDURI NUMBER(3,0),
  ADMAX NUMBER(1,0),
  DENOBIECTRETURN VARCHAR2(100),
  DENUMSEC VARCHAR2(200),
  IMPLICIT NUMBER(1,0),
  PARITATE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTATR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B764CAB5DC2022BE3A5C9F99DA8A2B0E5D38515</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTATR (
  CODARTATR NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  ACTIV NUMBER(1,0),
  CODVALPREDEF NUMBER(20,0),
  OBLIGATORIU NUMBER(1,0),
  SELECTIE NUMBER(1,0),
  FACTURABIL NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  OBS VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTATR_LST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D2ECA5B53C004DC1C5867C8BAB54DDE09ECAB540</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTATR_LST (
  CODARTICOL NUMBER(20,0),
  OBS VARCHAR2(3200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTCLI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>064F04E4240AD575452BF4515B32922AEC260F0B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTCLI (
  CODARTCLI NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(30),
  UMSEC NUMBER(20,0),
  CODMONEDA NUMBER(10,0),
  PRET NUMBER(20,7),
  TIPCODAFISAT NUMBER(1,0),
  UMCORELAT NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLACLIENT VARCHAR2(30),
  CODCLASEP NUMBER(20,0),
  CODGAMA NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  OBS VARCHAR2(100),
  OBS2 VARCHAR2(400),
  UMSECIMPDOC NUMBER(20,0),
  DURATATR NUMBER(20,7),
  ZILESTOC NUMBER(20,7),
  GLN VARCHAR2(13),
  IDSPECIFIC VARCHAR2(30),
  DENUMCOREL VARCHAR2(100),
  DEN_PART VARCHAR2(100),
  SIMBOLCLASAP VARCHAR2(30),
  DENGAMA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTDELETED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E29393A5D39846F57FD3D9F7A04A04EF4156CD73</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTDELETED (
  CODARTICOL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTDIM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6D55DBAB70ACA9588C48D49CDF5B49A40F8B0DFD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTDIM (
  CODARTDIM NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTIMPLICITE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>90BA872BF6632E1D89C8E88E5154873034A4235D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTIMPLICITE (
  CODIMPLICIT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CONTIMPLICIT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  LOCATIEIMPLICITA NUMBER(20,0),
  NEVANDABIL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9786E8EA87FD71CEAEC12B25A654C2DECCC9F7F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJ (
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  VOLUM NUMBER(20,5),
  STOCMIN NUMBER(20,5),
  STOCMAX NUMBER(20,5),
  RETURNABIL NUMBER(1,0),
  LUNIGARANTIE NUMBER(4,0),
  OBS VARCHAR2(300),
  PROCADAOSNIR NUMBER(5,2),
  ROTUNJIRE NUMBER(2,0),
  ADAOSEXCEPTIE NUMBER(5,2),
  PROMOTIE NUMBER(1,0),
  ROTVALUTA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  UMAMBALARE NUMBER(10,0),
  PRETMINIM NUMBER(20,5),
  TERMENPLATA NUMBER(5,0),
  DATAADAUGARII DATE,
  CODPLU NUMBER(20,0),
  USESTOCMED NUMBER(1,0),
  DURMAXAPROV NUMBER(10,0),
  CODCNAS VARCHAR2(20),
  CODCARACT NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  DISCPROMO NUMBER(20,7),
  TARAORIGINE NUMBER(20,0),
  ZILEVALABIL NUMBER(10,0),
  ZILEDISTRIB NUMBER(10,0),
  CODPERISABIL NUMBER(20,0),
  NEFACTURABIL NUMBER(1,0),
  GREUTSPECIFICA NUMBER(20,7),
  STOCMED NUMBER(20,5),
  INACTIVCMDONLINE NUMBER(1,0),
  PRODUSPROPRIU NUMBER(1,0),
  MESAJINACTIV VARCHAR2(100),
  AUTORIZATIE VARCHAR2(20),
  EXPIRAREAUTORIZ DATE,
  TRADUCARTGENERIC NUMBER(1,0),
  CODD394 VARCHAR2(8),
  INACTIV NUMBER(1,0),
  FARACMDFURN NUMBER(1,0),
  FARANIVELAPROB NUMBER(1,0),
  DESCARCAREINTEGRALA NUMBER(1,0),
  FARASTOC NUMBER(1,0),
  CODCATEGARTTI NUMBER(20,0),
  COEFCNAS NUMBER(20,7),
  EXPORTEMCS NUMBER(1,0),
  CODNC VARCHAR2(10),
  CODACCIZABIL VARCHAR2(10),
  RAPCNAS NUMBER(1,0),
  LANSIMP NUMBER(1,0),
  EXPORTKLG NUMBER(1,0),
  EXPORTATKLG TIMESTAMP(6),
  CODANALIZANOD NUMBER(20,0),
  SAFT_EXPORT NUMBER(1,0),
  CANTVANZ NUMBER(20,7),
  CODCPV VARCHAR2(10),
  EXCLUSLISTARECM NUMBER(1,0),
  ANTIBIOTIC NUMBER(1,0),
  CERTIF_DDS NUMBER(1,0),
  DENOBIECT VARCHAR2(200),
  AREATRIBUTE NUMBER(1,0),
  STOCMINSUB NUMBER(20,5),
  STOCMAXSUB NUMBER(20,5),
  STOCMEDSUB NUMBER(20,5),
  SIMBOLCLASA VARCHAR2(50),
  DENPRODUCATOR VARCHAR2(50),
  COMENZIONLINE NUMBER(1,0),
  PRETMAXIMAL NUMBER(20,7),
  DENCARACTSUPLIM VARCHAR2(80),
  GRUPA VARCHAR2(20),
  CODCATALOG VARCHAR2(20),
  OPTIONALE NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJ1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF322FED7BBF79B69FB282B4C4C3FD74ED05600D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJ1 (
  CODOBIECT1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETMAXIMAL NUMBER(24,7),
  PROCADAOSMAXIMAL NUMBER(24,7),
  ADAOSLA NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PRETREFERINTA NUMBER(24,7),
  TIPPRETMAX NUMBER(1,0),
  COMPENSAT NUMBER(1,0),
  TIPCOMPENSARE VARCHAR2(10),
  GRUPA VARCHAR2(20),
  UPLIFT NUMBER(10,7),
  CODMONEDA NUMBER(20,0),
  PUNCTE NUMBER(10,0),
  UMIDITATE NUMBER(20,7),
  CORPURI_STRAINE NUMBER(20,7),
  INCOLTIT NUMBER(20,7),
  HECTOLITRICA NUMBER(20,7),
  GLUTEN NUMBER(20,7),
  FUZARITATE NUMBER(20,7),
  CADERE NUMBER(20,7),
  DEFORMARE NUMBER(20,7),
  STICLOZITATE NUMBER(20,7),
  SPARTURI NUMBER(20,7),
  PUNCTESECTIE NUMBER(10,0),
  TIPPRET NUMBER(1,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  D390EXCLUS NUMBER(1,0),
  COST NUMBER(20,7),
  CANTSERVAUTO NUMBER(20,7),
  PROTEINA NUMBER(20,7),
  AFLATOXINA NUMBER(20,7),
  ATAC_PLOSNITA NUMBER(20,7),
  CONTINUT_ULEI NUMBER(20,7),
  ACIDITATE NUMBER(20,7),
  SISTAVE NUMBER(20,7),
  REFRACTIE NUMBER(20,7),
  INDICE_W NUMBER(20,7),
  TOXINA_DON NUMBER(20,7),
  BOABE_TOXICE NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  MAX_UMIDITATE NUMBER(20,7),
  MAX_CORPURI_STRAINE NUMBER(20,7),
  MAX_INCOLTIT NUMBER(20,7),
  MAX_HECTOLITRICA NUMBER(20,7),
  MAX_GLUTEN NUMBER(20,7),
  MAX_FUZARITATE NUMBER(20,7),
  MAX_CADERE NUMBER(20,7),
  MAX_DEFORMARE NUMBER(20,7),
  MAX_STICLOZITATE NUMBER(20,7),
  MAX_SPARTURI NUMBER(20,7),
  MAX_PROTEINA NUMBER(20,7),
  MAX_AFLATOXINA NUMBER(20,7),
  MAX_ATAC_PLOSNITA NUMBER(20,7),
  MAX_CONTINUT_ULEI NUMBER(20,7),
  MAX_ACIDITATE NUMBER(20,7),
  MAX_SISTAVE NUMBER(20,7),
  MAX_REFRACTIE NUMBER(20,7),
  MAX_INDICE_W NUMBER(20,7),
  MAX_TOXINA_DON NUMBER(20,7),
  MAX_BOABE_TOXICE NUMBER(20,7),
  MIN_UMIDITATE NUMBER(20,7),
  MIN_CORPURI_STRAINE NUMBER(20,7),
  MIN_INCOLTIT NUMBER(20,7),
  MIN_HECTOLITRICA NUMBER(20,7),
  MIN_GLUTEN NUMBER(20,7),
  MIN_FUZARITATE NUMBER(20,7),
  MIN_CADERE NUMBER(20,7),
  MIN_DEFORMARE NUMBER(20,7),
  MIN_STICLOZITATE NUMBER(20,7),
  MIN_SPARTURI NUMBER(20,7),
  MIN_PROTEINA NUMBER(20,7),
  MIN_AFLATOXINA NUMBER(20,7),
  MIN_ATAC_PLOSNITA NUMBER(20,7),
  MIN_CONTINUT_ULEI NUMBER(20,7),
  MIN_ACIDITATE NUMBER(20,7),
  MIN_SISTAVE NUMBER(20,7),
  MIN_REFRACTIE NUMBER(20,7),
  MIN_INDICE_W NUMBER(20,7),
  MIN_TOXINA_DON NUMBER(20,7),
  MIN_BOABE_TOXICE NUMBER(20,7),
  PRETPROD NUMBER(20,7),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJCOLET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20E036DC9F2BCD5E45DA1BC19EB0C6D462A3EBF3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJCOLET (
  CODOBJCOLET NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CONTINUT VARCHAR2(30),
  IDCOLET VARCHAR2(10),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJIMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>15DC39622AD66DA1AB96CFFC3C8597A098290F38</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJIMP (
  CODOBJIMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  LOCATIEIMPLICITA NUMBER(20,0),
  DURMAXAPROV NUMBER(10,0),
  CONTIMPLICIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJSUBUNIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E00FEA8490A88FE17130EE324E27EF01257C07DA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJSUBUNIT (
  CODS NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7),
  STOCMED NUMBER(20,7),
  PROCSTOCMIN NUMBER(20,7),
  PROCSTOCMAX NUMBER(20,7),
  PROCSTOCMED NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENSUBUNIT VARCHAR2(100),
  DEN_GEST VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJSUBUNIT_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4D3CA98CEF24AF8ECE39E704CD754B781C05FA69</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJSUBUNIT_INI (
  CODS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJSUBUNIT_SEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>110AFDF72DD5C65E53266BF957B5295FCA67A098</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJSUBUNIT_SEC (
  CODS NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  STOCMIN NUMBER(20,7),
  STOCMAX NUMBER(20,7),
  STOCMED NUMBER(20,7),
  PROCSTOCMIN NUMBER(20,7),
  PROCSTOCMAX NUMBER(20,7),
  PROCSTOCMED NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENSUBUNIT VARCHAR2(100),
  DEN_GEST VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJTRAD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8927E782F73DE5968904BE658C0CC71C22CF5E16</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJTRAD (
  CODOBIECTTRAD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODLIMBA NUMBER(20,0),
  DENUMIRETRAD VARCHAR2(200),
  DESCRIERE NCLOB,
  AVERTIZARE VARCHAR2(200),
  DENOBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJ_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0E6D9C74765B9573729B62F00233774DE4E44B37</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJ_IMPORT (
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODVAMAL VARCHAR2(80),
  MASA NUMBER(20,5),
  VOLUM NUMBER(20,5),
  STOCMIN NUMBER(20,5),
  STOCMAX NUMBER(20,5),
  RETURNABIL NUMBER(1,0),
  LUNIGARANTIE NUMBER(4,0),
  OBS VARCHAR2(300),
  PROCADAOSNIR NUMBER(5,2),
  ROTUNJIRE NUMBER(2,0),
  ADAOSEXCEPTIE NUMBER(5,2),
  PROMOTIE NUMBER(1,0),
  ROTVALUTA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  UMAMBALARE NUMBER(10,0),
  PRETMINIM NUMBER(20,5),
  TERMENPLATA NUMBER(5,0),
  DATAADAUGARII DATE,
  CODPLU NUMBER(20,0),
  USESTOCMED NUMBER(1,0),
  DURMAXAPROV NUMBER(10,0),
  CODCNAS VARCHAR2(20),
  CODCARACT NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  DISCPROMO NUMBER(20,7),
  TARAORIGINE NUMBER(20,0),
  ZILEVALABIL NUMBER(10,0),
  ZILEDISTRIB NUMBER(10,0),
  CODPERISABIL NUMBER(20,0),
  NEFACTURABIL NUMBER(1,0),
  GREUTSPECIFICA NUMBER(20,7),
  STOCMED NUMBER(20,5),
  INACTIVCMDONLINE NUMBER(1,0),
  PRODUSPROPRIU NUMBER(1,0),
  MESAJINACTIV VARCHAR2(100),
  AUTORIZATIE VARCHAR2(20),
  EXPIRAREAUTORIZ DATE,
  TRADUCARTGENERIC NUMBER(1,0),
  CODD394 VARCHAR2(8),
  INACTIV NUMBER(1,0),
  FARACMDFURN NUMBER(1,0),
  FARANIVELAPROB NUMBER(1,0),
  DENOBIECT VARCHAR2(200),
  AREATRIBUTE NUMBER(1,0),
  STOCMINSUB NUMBER(20,5),
  STOCMAXSUB NUMBER(20,5),
  STOCMEDSUB NUMBER(20,5),
  SIMBOLCLASA VARCHAR2(50),
  DENPRODUCATOR VARCHAR2(50),
  COMENZIONLINE NUMBER(1,0),
  PRETMAXIMAL NUMBER(20,7),
  DENCARACTSUPLIM VARCHAR2(80),
  GRUPA VARCHAR2(20),
  CODCATALOG VARCHAR2(30),
  TIPARTICOL NUMBER(1,0),
  SIMBOL_CLASEAS VARCHAR2(30),
  SIMBOL_CENTRUCOST VARCHAR2(20),
  DEN_UM VARCHAR2(15),
  DEN_UM1 VARCHAR2(15),
  DEN_UM2 VARCHAR2(15),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  SIMBOL_GEST VARCHAR2(15),
  SIMBOL_IOART VARCHAR2(15),
  SIMBOL_CONTSERV VARCHAR2(30),
  TIPSERIE NUMBER(1,0),
  SIMBOL_MONEDAPRET VARCHAR2(5),
  PRETREFERINTA NUMBER(20,7),
  PUNCTESECTIE NUMBER(10,0),
  TIPPRET NUMBER(1,0),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  CODCLASEAS NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  CONTIMPLICIT NUMBER(20,0),
  CODOBIECTNOU NUMBER(20,0),
  CODEXTERN_LOCATIE VARCHAR2(20),
  LOCATIEIMPLICITA NUMBER(20,0),
  DCI VARCHAR2(100),
  COEFCNAS NUMBER(20,7),
  SIMBOL_AUTO_TARA VARCHAR2(3),
  SIMBOL_CLASEASW VARCHAR2(50),
  UMAMB VARCHAR2(500),
  CODEXT_UMAMB VARCHAR2(500),
  IDCLIENT VARCHAR2(100),
  DENLACLIENT VARCHAR2(200),
  CODEXTERNLACLIENT VARCHAR2(100),
  LUNGIME_AMB VARCHAR2(500),
  LATIME_AMB VARCHAR2(500),
  INALTIME_AMB VARCHAR2(500),
  CODLACLIENT VARCHAR2(30),
  IMPLICITCODCLIENT NUMBER(1,0),
  CODCPV VARCHAR2(10),
  CONSTRUCTIENOUA NUMBER(1,0),
  RISCFISCAL NUMBER(1,0),
  EXPORTEMCS NUMBER(1,0),
  CODNC VARCHAR2(10),
  CODACCIZABIL VARCHAR2(10),
  PROCTVA NUMBER(6,3),
  CODTVA NUMBER(20,0),
  GREUT_AMB VARCHAR2(500),
  MASA_AMB VARCHAR2(500),
  PRET_UMAMB VARCHAR2(2000),
  ZILESTOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOBJ_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>53EDF7D69D4BA8378A18538AAF8B32BD568316D9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOBJ_LUNA (
  CODOBIECT1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRETMAXIMAL NUMBER(24,7),
  PROCADAOSMAXIMAL NUMBER(24,7),
  ADAOSLA NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  PRETREFERINTA NUMBER(24,7),
  TIPPRETMAX NUMBER(1,0),
  COMPENSAT NUMBER(1,0),
  TIPCOMPENSARE VARCHAR2(10),
  GRUPA VARCHAR2(20),
  UPLIFT NUMBER(10,7),
  CODMONEDA NUMBER(20,0),
  PUNCTE NUMBER(10,0),
  UMIDITATE NUMBER(20,7),
  CORPURI_STRAINE NUMBER(20,7),
  INCOLTIT NUMBER(20,7),
  HECTOLITRICA NUMBER(20,7),
  GLUTEN NUMBER(20,7),
  FUZARITATE NUMBER(20,7),
  CADERE NUMBER(20,7),
  DEFORMARE NUMBER(20,7),
  STICLOZITATE NUMBER(20,7),
  SPARTURI NUMBER(20,7),
  PUNCTESECTIE NUMBER(10,0),
  TIPPRET NUMBER(1,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  D390EXCLUS NUMBER(1,0),
  COST NUMBER(20,7),
  CANTSERVAUTO NUMBER(20,7),
  PROTEINA NUMBER(20,7),
  AFLATOXINA NUMBER(20,7),
  ATAC_PLOSNITA NUMBER(20,7),
  CONTINUT_ULEI NUMBER(20,7),
  ACIDITATE NUMBER(20,7),
  SISTAVE NUMBER(20,7),
  REFRACTIE NUMBER(20,7),
  INDICE_W NUMBER(20,7),
  TOXINA_DON NUMBER(20,7),
  BOABE_TOXICE NUMBER(20,7),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOPT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3ABCD63490C15581449FEA68C28B5847A8013D74</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOPT (
  CODOPT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTOPT NUMBER(20,0),
  STANDARD NUMBER(1,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODTIPLOCATIE NUMBER(20,0),
  FORCELEI NUMBER(1,0),
  DENOBIECTOPT VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  STOC NUMBER(20,7),
  PRET NUMBER(20,7),
  SELECTAT NUMBER(1,0),
  LEI NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NARTOPTIUNI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B73CABDE72FC59F0261F04DAD9EFB8B337C4B20D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NARTOPTIUNI (
  CODOPTIUNE NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NART_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D141CD9F72F144C7C03410938947B65D4C4A0C41</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NART_LUNA (
  CODARTICOL1 NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODTVA NUMBER(10,0),
  CODACCIZE NUMBER(10,0),
  CODTAXA1 NUMBER(10,0),
  CODTAXA2 NUMBER(10,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODACCIZEDVI NUMBER(20,0),
  TAXCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATRIB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19222006C61BE54026A570752045808A25AF36C5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATRIB (
  CODATRIBUT NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  TIPVALOARE NUMBER(1,0),
  PREFIX VARCHAR2(20),
  COLSUPLIM VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATRIB1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0924E902A72316A903811F165531FDB22638AA6D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATRIB1 (
  CODVALATR NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  VALOARE VARCHAR2(50),
  CODOBIECTASOC NUMBER(20,0),
  CODEXTERN VARCHAR2(10),
  GRUPA VARCHAR2(5),
  INACTIV NUMBER(1,0),
  PROCMAJPU NUMBER(8,5),
  INACTIVCMDONLINE NUMBER(1,0),
  MESAJINACTIV VARCHAR2(100),
  DENOBIECTASOC VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATRIB1TRAD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13847F8BEC01380DDCF9C2AE7293D4AB6BD878C0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATRIB1TRAD (
  CODATRIB1TRAD NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODLIMBA NUMBER(20,0),
  MESAJINACTIV VARCHAR2(100),
  DENUMIRE VARCHAR2(50),
  DENLIMBA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATRIB2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF524E7205B89A282151BC742FDB2116D8023344</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATRIB2 (
  CODATRIB2 NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  PROCMAJ NUMBER(8,5),
  DENARTICOL VARCHAR2(100),
  CODEXTERNART VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATROBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC22F9F5923DB3237D0659852D9F32995719C72F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATROBJ (
  CODATROBJ NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTATR NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NATRTRAD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FDAC59D5A1FBE931494012BE5C62C179CA6F032B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NATRTRAD (
  CODNATRTRAD NUMBER(20,0),
  CODATRIBUT NUMBER(20,0),
  DENATRIB VARCHAR2(50),
  CODVALATR NUMBER(20,0),
  VALATR VARCHAR2(50),
  VALATRTRAD VARCHAR2(50),
  MESAJINACTIV VARCHAR2(100),
  MESAJINACTIVTRAD VARCHAR2(100),
  CODATRIB1TRAD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NAUTORIZATIIAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>28E74701B283342D43E09B215390DE2C5BDD249A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NAUTORIZATIIAUTO (
  CODAUTORIZATII NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  ATENTIONARE NUMBER(10,0),
  CODSERVICIU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NBANCIRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>243F421D4E7B1DBEC5A8D053E4A7BF5693D9A3C2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NBANCIRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODBANK NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  CONTBANCA VARCHAR2(30),
  SUCURSALA VARCHAR2(20),
  CODMONEDA NUMBER(20,0),
  DENBANCA VARCHAR2(50),
  DENLOCALIT VARCHAR2(50),
  CODPARTB NUMBER(20,0),
  CODJUDET NUMBER(20,0),
  CODTARA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NBANK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2783180FD67459DFD4D4E585A43D7FB4AA312847</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NBANK (
  CODBANK NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  CODSWIFT VARCHAR2(30),
  CODBNR VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NBANKCONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5976D7B19FB8EDCA46697731CE0587AC1E44B3E1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NBANKCONT (
  CODBANKCONT NUMBER(20,0),
  CODBANK NUMBER(20,0),
  DEN_CONT VARCHAR2(30),
  CODLOCALITATE NUMBER(20,0),
  NRCONT VARCHAR2(30),
  CODMONEDA NUMBER(20,0),
  FILIALA VARCHAR2(20),
  DATADESKIS DATE,
  DATAINKIS DATE,
  CREDIT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  POS NUMBER(1,0),
  POSID VARCHAR2(30),
  CONTTVA NUMBER(1,0),
  FARAREG NUMBER(1,0),
  FARA_CASH_FLOW NUMBER(1,0),
  OBS VARCHAR2(300),
  IMPLICITEF NUMBER(1,0),
  INSTITPUBLICE NUMBER(1,0),
  ORDINE NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NBANKCONT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A91DA59A0BB694E3E7C7FBEA6BA44E0DB7C3E7B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NBANKCONT1 (
  CODBANKCONT1 NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  CODIOBANCA NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NBANKSOLDLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D39E1955D73DA757F0D9FC510B4B8DDC0BAA6A9E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NBANKSOLDLUNA (
  CODBANKSOLDLUNA NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  SOLDLEI NUMBER(24,7),
  SOLDVALUTA NUMBER(24,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  REGULARIZARE NUMBER(1,0),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D73235EDE677A398A9103FF3AFEE34708DC29BDD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NC (
  CODNC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PART NUMBER(20,0),
  JURNALTVA NUMBER(5,0),
  TIPTRANZ NUMBER(5,0),
  TIPTVA NUMBER(5,0),
  VALOARE NUMBER(20,3),
  MONEDA NUMBER(20,0),
  CURS NUMBER(20,7),
  OBS VARCHAR2(100),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SABLON NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  APROBAT NUMBER(1,0),
  VALOARELEI NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E81F5E540366A81D8C80175B5C92EBC63F745D92</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NC1 (
  CODNC1 NUMBER(20,0),
  CODNC NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,3),
  OBS VARCHAR2(80),
  CODGEST NUMBER(20,0),
  PARTD NUMBER(1,0),
  PARTC NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  ICONTD NUMBER(3,0),
  ICONTC NUMBER(3,0),
  TIPLINIETVA NUMBER(5,0),
  CODCENTRU NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  PERSD NUMBER(1,0),
  PERSC NUMBER(1,0),
  CODPART NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  RESTIMBMF NUMBER(20,7),
  CODCMDINT1 NUMBER(20,0),
  MFSAFT NUMBER(20,0),
  SIMBOLCONTD VARCHAR2(100),
  SIMBOLCONTC VARCHAR2(100),
  FARAREG NUMBER(1,0),
  TERMEN DATE,
  IDENTIFLINIE VARCHAR2(300),
  INFOMF VARCHAR2(100),
  CMDINT NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  SIMBOLCC VARCHAR2(100),
  DENNOD VARCHAR2(300),
  DENAGENT VARCHAR2(500),
  DEN_PART VARCHAR2(100),
  NRINREG VARCHAR2(20),
  DEN_FORMATIE VARCHAR2(100),
  INFOMFSAFT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCARSUPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A99A31BD9E7B51B85AB17281CAB553D63D443BBE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCARSUPART (
  CODCARSUPART NUMBER(20,0),
  DEN_CARSUPART VARCHAR2(80),
  CULOARE NUMBER(8,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCASEMARCAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EBFCEE54BE834F03750AB485D6E4779366A00247</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCASEMARCAT (
  CODCASEMARCAT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  NUMAR NUMBER(10,0),
  PORT NUMBER(20,0),
  TIP NUMBER(10,0),
  MODEL NUMBER(10,0),
  CODFISCAL VARCHAR2(12),
  CODBARECANTAR NUMBER(1,0),
  PLUMAXCANTAR NUMBER(20,0),
  NRMAXPLU NUMBER(20,0),
  LUNGIMETEXT NUMBER(5,0),
  TIPDRIVER NUMBER(5,0),
  RATA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  GESTDESTTRANSF NUMBER(20,0),
  CODIOARTDESTTRANSF NUMBER(20,0),
  TIPINFOART NUMBER(2,0),
  CODCARNETTRANSF NUMBER(20,0),
  TEXTPROMO VARCHAR2(300),
  CODCARNETNIR NUMBER(20,0),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCASEMARCAT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9DDBACFC08D34C0FC2A399C8D37B1730BA44F7CD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCASEMARCAT1 (
  CODCASEMARCAT1 NUMBER(20,0),
  CODCASEMARCAT NUMBER(20,0),
  CODGESTIUNE NUMBER(20,0),
  DENGESTIUNE VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCASEMARCAT2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>14B2D6CF3F1F6ACF120DEEF19288268627A34716</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCASEMARCAT2 (
  CODCASEMARCAT2 NUMBER(20,0),
  CODCASEMARCAT NUMBER(20,0),
  PROCENT_TVA NUMBER(20,7),
  PARAMCASA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCATPRET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EC48AF0A36784467CF54B37E6F8B3C33C6332A29</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCATPRET (
  CODCATPRET NUMBER(20,0),
  DEN_CATPRET VARCHAR2(30),
  TIP NUMBER(2,0),
  SIMBOL VARCHAR2(10),
  PROCDINIMPLICIT NUMBER(20,7),
  SUMAFIXAIMPLICIT NUMBER(20,7),
  CODCATMASTER NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCCADOURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CDCDA4F2FF410CAF7117D4F048462F7B3420257A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCCADOURI (
  CODNCCADOURI NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODOBIECTASOC NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DIFERENTE NUMBER(20,7),
  CODOBIECTASOCSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  CANTFACT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  DENUMIREASOC VARCHAR2(250),
  DEN_UM1 VARCHAR2(250),
  TIPARTICOL NUMBER(1,0),
  DENUMIREASOCSEC VARCHAR2(250),
  PRET NUMBER(20,7),
  PARITATE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9051FDD464FCAAF1103EBD2A015D1CB5952934B4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEA (
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(150),
  SIMBOL VARCHAR2(50),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  VERLISTSUPLFACT NUMBER(10,0),
  VERLISTSUPLTOALL NUMBER(1,0),
  CODIDENT VARCHAR2(250),
  VERLISTSUPLAVIZ NUMBER(20,0),
  DISCOFE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D594352243E51B154A4F3CAD0B0D732C48F83FF1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEAS (
  CODCLASEAS NUMBER(20,0),
  DEN_CLASEAS VARCHAR2(250),
  SIMBOL VARCHAR2(250),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  VERLISTSUPLFACT NUMBER(10,0),
  VERLISTSUPLTOALL NUMBER(1,0),
  TIP NUMBER(1,0),
  CODIDENT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEDISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>80ADCE8EF780A798889A19F81585A8FCC307C079</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEDISC (
  CODCLASEDISC NUMBER(20,0),
  DEN_CLASEDISC VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6B5D164A3937367077D655070EEABDE9F52D215A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEG (
  CODCLASEG NUMBER(20,0),
  DEN_CLASEG VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEINT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8071A14ED668B2282B26A45E5EFD8A50C346AE80</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEINT (
  CODCLASEINT NUMBER(20,0),
  DEN_CLASEINT VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BAFF75215C9837979AE44CB5ACE0F7611EE2DEE5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEMF (
  CODCLASEMF NUMBER(20,0),
  DEN_CLASEMF VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEOP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FAF4CABB347EEA14D631F93BB503FB1024757700</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEOP (
  CODCLASEOP NUMBER(20,0),
  DEN_CLASEOP VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEOPT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DE9CD086BD06497DF779EB0E3C4CD7C18A969C2F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEOPT (
  CODCLASEOPT NUMBER(20,0),
  DENUMIRE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FB1967FFC38CE55D6BE25C766AD662F58A71F45E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEP (
  CODCLASEP NUMBER(20,0),
  DEN_CLASEP VARCHAR2(30),
  SIMBOL VARCHAR2(30),
  NIVEL NUMBER(2,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0),
  CODIDENT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCLASEPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>717961D1C49BE68B767AB516C070429BCD23E295</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCLASEPROD (
  CODCLASEPROD NUMBER(20,0),
  DEN_CLASEPROD VARCHAR2(50),
  SIMBOL VARCHAR2(30),
  PREFIX NUMBER(1,0),
  NIVEL NUMBER(3,0),
  NRANALITICE NUMBER(3,0),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCODFISCRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2863FF79E8A82070E74C60F6F4F7BB7D06338459</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCODFISCRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  PRINCIPAL NUMBER(1,0),
  COD_CODFISCAL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88AB6DF85FAC583D63AE7ED1B9AE29B8762D07E7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(200),
  NAME VARCHAR2(150),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50),
  ANINACTIV NUMBER(5,0),
  LUNAINACTIV NUMBER(2,0),
  CODSAFT VARCHAR2(70),
  TAXTYPE NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  IMPOZIT NUMBER(1,0),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B5A598E2DB8D1D01426E3CDE9747257F02CBF49</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT1 (
  CODCONT1 NUMBER(20,0),
  CODCONT NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  CONTSECUNDAR NUMBER(20,0),
  CONTTERTIAR NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  TIPINCHIDERE NUMBER(1,0),
  CONTSECUNDARG NUMBER(20,0),
  CONTSECUNDARGO NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODCENTRUS NUMBER(20,0),
  CODCENTRUSG NUMBER(20,0),
  CODCENTRUSGO NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  CODANALIZANOD NUMBER(20,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT1SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D75BC1172655B99C4A644D0A448D9F76346E2205</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT1SUB (
  COD NUMBER(20,0),
  CODCONT1 NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  TIPINCHIDERE NUMBER(1,0),
  DENSUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT1_BAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2E4C3B2C9ABAB971E2BBDC81C2148D796BD5153</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT1_BAL (
  CODCONT NUMBER(20,0),
  CODCOMUN NUMBER(20,0),
  SIMBOLPLANP VARCHAR2(100),
  FRUNZA NUMBER(1,0),
  FRUNZAS NUMBER(1,0),
  SEMN NUMBER(2,0),
  OFFSET NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTCOMUN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FCB0BE0126ED2D4D3AC13498DD90D1B5E9AB552F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTCOMUN (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  TIPCONT NUMBER(1,0),
  BALSINT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  CODPARINTE NUMBER(20,0),
  DEN_CONT VARCHAR2(200),
  NRANALITICE NUMBER(3,0),
  VIZIBILBALANTA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTECHIV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD1A5BEB1FD00D8D6E0E65ED51E8D6138ADFEEC6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTECHIV (
  CODCONTECHIV NUMBER(20,0),
  CONTVECHI NUMBER(20,0),
  CONTNOU NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTECHIVSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13ADD58A3883354262D276ECE62F787B957E28AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTECHIVSUB (
  CODCONTECHIVSUB NUMBER(20,0),
  CODCONTECHIV NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTFIRMECUPL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BAC06151F6A4E8E94B2000DFBAEF09522AFAA6FB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTFIRMECUPL (
  CODUNIC NUMBER(20,0),
  CODFIRMACUPL NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCONTCOMUN NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  TIPCONT NUMBER(1,0),
  BALSINT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  CODPARINTE NUMBER(20,0),
  DEN_CONT VARCHAR2(200),
  NRANALITICE NUMBER(3,0),
  SIMBOLCONTCOMUN VARCHAR2(30),
  LEGATURAINVALIDA NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTREP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B65BD8E10FE2451AEBA5D5C6B8C384D71DC545E0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTREP (
  CODCONTREP NUMBER(20,0),
  CODCONT NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SIMBOL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTREPRUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>727831526FE6FBFC6D55E16B3916550949754525</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTREPRUL (
  CODCONTREPRUL NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  SIMBOL VARCHAR2(30),
  ACTIV NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTREPRULSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8AB59943E09FF66C415B788CC59AAB34C48017F4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTREPRULSUB (
  CODREPRULSUB NUMBER(20,0),
  CODCONTREPRUL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  RULAJPD NUMBER(20,7),
  RULAJPC NUMBER(20,7),
  RULAJVPD NUMBER(20,7),
  RULAJVPC NUMBER(20,7),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  DENSUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTREPSOLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>330C2C1F66E6083364BA0C3F2747D1032720E190</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTREPSOLD (
  CODCONTREPSOLD NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  SIMBOL VARCHAR2(30),
  ACTIV NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTREPSOLDSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DC518B7A445419E9B05432EEF1AD86F86F3D28C2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTREPSOLDSUB (
  CODREPSOLDSUB NUMBER(20,0),
  CODCONTREPSOLD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SOLDID NUMBER(20,7),
  SOLDIC NUMBER(20,7),
  SOLDVID NUMBER(20,7),
  SOLDVIC NUMBER(20,7),
  SOLDI_IFRS NUMBER(20,7),
  SOLDVI_IFRS NUMBER(20,7),
  SOLDI_GRUP NUMBER(20,7),
  SOLDVI_GRUP NUMBER(20,7),
  DENSUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTRUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1927F9F80FCE11EE304D44A1CA7944F7769FF8F2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTRUL (
  CODCONTRUL NUMBER(20,0),
  CODCONT NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTRULS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E92FDB7DA98428295113AF0F4C30AC77840EC95</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTRULS (
  CODCONTRULS NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTRULSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34BB93ACDA6BB47E56726D8CAB4022BBBC5E535F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTRULSUB (
  CODCONTRULSUB NUMBER(20,0),
  CODCONTRUL NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3),
  DENSUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTRULT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A34B888C466F755F8B051373DA78F031FCF25DA9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTRULT (
  CODCONTRULT NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E9721BA3CBFB57CA6B28E8AC7806C37F1BADB397</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTS (
  CODCONTS NUMBER(20,0),
  SIMBOL VARCHAR2(30),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(50),
  NAME VARCHAR2(50),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>86E9488B6296D1B5EC11216457454A4F9E0DEF04</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTS1 (
  CODCONTS1 NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  SUPLCENTRE NUMBER(1,0),
  CODCONT NUMBER(20,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTSOLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2BD8EF0CAADFA4727EEB44A1087CB5B3977D9047</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTSOLD (
  CODCONTSOLD NUMBER(20,0),
  CODCONT NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTSOLDS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5AED8CB91103F2110C83EAF03F87FFEB45FE78D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTSOLDS (
  CODCONTSOLDS NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTSOLDSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E0C67E523C789CD98013293EC28B3115A553DBA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTSOLDSUB (
  CODCONTSOLDSUB NUMBER(20,0),
  CODCONTSOLD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  DENSUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTSOLDT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>55A21DBA2FF1FC1582611D21B62A52B5BD7B0729</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTSOLDT (
  CODCONTSOLDT NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>837DA9E017FCF37AEC1675AE2B06FAFC95EF9667</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTT (
  CODCONTT NUMBER(20,0),
  SIMBOL VARCHAR2(30),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(50),
  NAME VARCHAR2(50),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONTT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1EB4143C9575192291623DDB26E8F4CB8F68477B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONTT1 (
  CODCONTT1 NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  NRANALITICE NUMBER(3,0),
  CONTTRANSFD NUMBER(20,0),
  CONTTRANSFC NUMBER(20,0),
  CONTINKIDSOLD NUMBER(20,0),
  PARTICIPATIUNE NUMBER(1,0),
  SINCRONIZARE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CONTTRANSFCDIM NUMBER(20,0),
  SUPLCENTRE NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT_BAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>385D85039E60CBA72679837344429552DC380EA6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT_BAL (
  CODCONT NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  CODCONTS NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  CLASA NUMBER(1,0),
  DEN_CONT VARCHAR2(200),
  NAME VARCHAR2(150),
  TIPCONT NUMBER(1,0),
  VIZIBILBALANTA NUMBER(1,0),
  BALANTASINTETICA NUMBER(1,0),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  SIMBOLSITFIN VARCHAR2(50),
  CENTRUCOST VARCHAR2(100),
  SIMBCENTRUCOST VARCHAR2(100),
  NRANALITICE NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT_LUNA_1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60B92852E07CFC892B7959C837FC8C812EB1612F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT_LUNA_1 (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  NRANALITICE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT_LUNA_2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FFD18BF15D6DACF6B8193351495B212282A125B9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT_LUNA_2 (
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100),
  NIVEL NUMBER(2,0),
  CODPARINTE NUMBER(20,0),
  NRANALITICE NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SOLDID NUMBER(20,3),
  SOLDIC NUMBER(20,3),
  SOLDVID NUMBER(20,3),
  SOLDVIC NUMBER(20,3),
  SOLDI_IFRS NUMBER(20,3),
  SOLDVI_IFRS NUMBER(20,3),
  SOLDI_GRUP NUMBER(20,3),
  SOLDVI_GRUP NUMBER(20,3),
  RULAJPD NUMBER(20,3),
  RULAJPC NUMBER(20,3),
  RULAJCD NUMBER(20,3),
  RULAJCC NUMBER(20,3),
  RULAJVPD NUMBER(20,3),
  RULAJVPC NUMBER(20,3),
  RULAJVCD NUMBER(20,3),
  RULAJVCC NUMBER(20,3),
  RULAJP_IFRS NUMBER(20,3),
  RULAJC_IFRS NUMBER(20,3),
  RULAJVP_IFRS NUMBER(20,3),
  RULAJVC_IFRS NUMBER(20,3),
  RULAJP_GRUP NUMBER(20,3),
  RULAJC_GRUP NUMBER(20,3),
  RULAJVP_GRUP NUMBER(20,3),
  RULAJVC_GRUP NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCONT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F1F6CC0771A8EC395FC89D7ECA59281441CC706E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCONT_MAN (
  CODCONT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SOLDID NUMBER(20,7),
  SOLDIC NUMBER(20,7),
  SOLDVID NUMBER(20,7),
  SOLDVIC NUMBER(20,7),
  SOLDI_IFRS NUMBER(20,7),
  SOLDVI_IFRS NUMBER(20,7),
  SOLDI_GRUP NUMBER(20,7),
  SOLDVI_GRUP NUMBER(20,7),
  RULAJPD NUMBER(20,7),
  RULAJPC NUMBER(20,7),
  RULAJCD NUMBER(20,7),
  RULAJCC NUMBER(20,7),
  RULAJVPD NUMBER(20,7),
  RULAJVPC NUMBER(20,7),
  RULAJVCD NUMBER(20,7),
  RULAJVCC NUMBER(20,7),
  RULAJP_IFRS NUMBER(20,7),
  RULAJC_IFRS NUMBER(20,7),
  RULAJVP_IFRS NUMBER(20,7),
  RULAJVC_IFRS NUMBER(20,7),
  RULAJP_GRUP NUMBER(20,7),
  RULAJC_GRUP NUMBER(20,7),
  RULAJVP_GRUP NUMBER(20,7),
  RULAJVC_GRUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCVDISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1BA0391BC379C30AD8BA57E06446F8B4521594E5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCVDISC (
  CODNCREDIT1 NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCVDISC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1826F08367171132E4937B2830012054CAE4203</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCVDISC_MAN (
  CODDISCOUNT NUMBER(20,0),
  CANT NUMBER(20,0),
  VALOARE NUMBER(20,0),
  PROC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NCVDISC_VOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F6ED8557D4FB44C009FCA3A38146EC4C66CCDCFD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NCVDISC_VOL (
  CODOBIECT NUMBER(20,0),
  VALOARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NDELEGATRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7754C59BF87A28171D8D40771A80DC314E04427D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NDELEGATRETAIL (
  COD NUMBER(20,0) NOT NULL,
  CODPARTRETAIL NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  DATADOC DATE,
  ACTIV NUMBER(1,0),
  IMPLICIT NUMBER(1,0),
  OBS VARCHAR2(250),
  CODPARTTR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NECESAR5</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F109762C07877842AE83462C2565EC1D19A68090</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NECESAR5 (
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  FURNIZOR VARCHAR2(250),
  NRINDICATOR NUMBER(2,0),
  INDICATOR VARCHAR2(200),
  STOCMIN NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  PRET NUMBER(20,7),
  ORDINE NUMBER(1,0),
  L1 NUMBER(20,7),
  L2 NUMBER(20,7),
  L3 NUMBER(20,7),
  L4 NUMBER(20,7),
  L5 NUMBER(20,7),
  L6 NUMBER(20,7),
  L7 NUMBER(20,7),
  L8 NUMBER(20,7),
  L9 NUMBER(20,7),
  L10 NUMBER(20,7),
  L11 NUMBER(20,7),
  L12 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NECHIV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B183A991C1142E21B4B87A843F6245EF50854BE3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NECHIV (
  CODECHIV NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  CODGRUPA NUMBER(20,0),
  GENERIC NUMBER(1,0),
  INDEXLOCAL NUMBER(7,0),
  IND NUMBER(10,0),
  DEN_UM VARCHAR2(15),
  DENOBIECTECHIV VARCHAR2(200),
  CODOBIECTECHIV NUMBER(20,0),
  ZECIMALE NUMBER(4,0),
  CODEXTERN VARCHAR2(100),
  CODINTERN VARCHAR2(100),
  CODCATALOG VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NELEMAEROAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1D69D89F0C38CF1D96A071166FDE539F40008AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NELEMAEROAUTO (
  CODELEMAEROAUTO NUMBER(20,0),
  ELEMENT VARCHAR2(200),
  SPOR NUMBER(20,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NGAMEART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F51013CB512C4F6F5DAC52EDCA8167357B290DD7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NGAMEART (
  CODGAMA NUMBER(20,0),
  DENUMIRE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F995A28AC71457857C45FF77A1232169D27B3A4F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NGEST (
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  SIMBOL VARCHAR2(50),
  CODCLASA NUMBER(20,0),
  CODACTIVIT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  CODGESTIONAR NUMBER(20,0),
  CUSTODIE NUMBER(1,0),
  CODSUBUNIT NUMBER(20,0),
  VERDISPLIVR NUMBER(10,0),
  VERDISPLIVRTRANSF NUMBER(10,0),
  VERDISPLIVRSUBUNIT NUMBER(10,0),
  VERNIR NUMBER(10,0),
  VERNIRTRANSF NUMBER(10,0),
  VERNIRSUBUNIT NUMBER(10,0),
  TIP NUMBER(1,0),
  GMASTER NUMBER(1,0),
  NRSCHIMBURI NUMBER(5,0),
  ORESCHIMB NUMBER(4,2),
  ORASTART DATE,
  COEFCHELTMAT NUMBER(20,7),
  COEFCHELTMAN NUMBER(20,7),
  VEREMULARE NUMBER(10,0),
  CODPOSTRETAIL NUMBER(10,0),
  ANALITICCONT VARCHAR2(10),
  CANTITATE NUMBER(20,7),
  INACTIV NUMBER(1,0),
  VERFACTIES NUMBER(20,0),
  VERCHITANTA NUMBER(20,0),
  CODCAENSEC NUMBER(20,0),
  CODGESTTR NUMBER(20,0),
  ZILETERMEN NUMBER(10,0),
  ZILELUCR NUMBER(5,0),
  CODANTREPOZIT VARCHAR2(20),
  CAPPROD NUMBER(20,7),
  CARNETCMDINT NUMBER(20,0),
  CARNETBC NUMBER(20,0),
  CARNETNP NUMBER(20,0),
  CARNETRP NUMBER(20,0),
  OBS VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NGEST1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D5F7B2E29C89A16727AFE1E3812DEEF79807FE4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NGEST1 (
  CODGEST1 NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  TIPGEST NUMBER(2,0),
  CHELTUIELI NUMBER(20,0),
  CHELTUIELIAUX NUMBER(20,0),
  CHELTUIELIIND NUMBER(20,0),
  CHELTUIELIADMIN NUMBER(20,0),
  CHELTUIELIDESF NUMBER(20,0),
  VENITURI NUMBER(20,0),
  VENITURIK NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SUPRAFATA NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NGEST_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9D069C33A1D6A0C971C5F1743CFC482520DEBB4E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NGEST_LUNA (
  CODGEST1 NUMBER(20,0) NOT NULL,
  CODGEST NUMBER(20,0),
  TIPGEST NUMBER(2,0),
  CHELTUIELI NUMBER(20,0),
  VENITURI NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NGRUPEAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AF197FC803FEF8D48A872B09977A59727E4EE275</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NGRUPEAUTO (
  CODGRUPEAUTO NUMBER(20,0),
  GRUPA VARCHAR2(200),
  SPORB NUMBER(20,7),
  SPORRES NUMBER(20,7),
  SPORALTE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIMOB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6899ADE6162A3F4A76977157A532912BD020111D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIMOB (
  CODNIMOB NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DATASTART DATE,
  DATASTOP DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NINSTAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E40008AEECB318AE1C325B1DD3131306F08BC347</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NINSTAUTO (
  CODINSTAUTO NUMBER(20,0),
  INSTALATIE VARCHAR2(200),
  PRESTATIE VARCHAR2(200),
  SPOR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NINTERVENTIIAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3043AF4BFBD349A471EF899F52B4DCDB58FA0203</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NINTERVENTIIAUTO (
  CODINTERVENTIIAUTO NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  PERTIP NUMBER(1,0),
  PERDURATA NUMBER(10,0),
  PERKM NUMBER(10,0),
  ATENTIONAREZILE NUMBER(10,0),
  ATENTIONAREKM NUMBER(10,0),
  TIP NUMBER(1,0),
  SERVICIU NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  ACCIDENTALA NUMBER(1,0),
  CLASA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AFFC33BF9A2E942D3825A4D7AC8E0E14EB722AF9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIR (
  CODNIR NUMBER(20,0),
  CODINTR NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  CODIES NUMBER(20,0),
  CARNETNIR NUMBER(20,0),
  NRNIR NUMBER(20,0),
  DATANIR DATE,
  GEST NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPNIR NUMBER(3,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  VALOARE NUMBER(20,7),
  CODIOARTIMPLICIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D9096A251358ECE545F50ACA141F23557F02F434</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIR1 (
  CODNIRSTOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DIFERENTA NUMBER(20,6),
  TIPDIF VARCHAR2(1),
  CUIIMPUT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>660CAC0F8A78B5F506D38563C9A85C9260AFAB5A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRLUNA (
  CODNIRSTOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3EACC3AE80A7AA5101C4014BEFF777669A86F4C4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSER (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  REST NUMBER(20,7),
  OBS VARCHAR2(200),
  CANTUM1 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  CODCERTIF NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  TG DATE,
  DIVIZOR NUMBER(10,0),
  BUCATI NUMBER(10,0),
  DATAPROD1 DATE,
  TG1 DATE,
  CODPRODUCATOR NUMBER(20,0),
  SERIE VARCHAR2(75),
  PARITATE NUMBER(20,7),
  NRCERTIF VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSERINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FA29EBBE3AD63BC61D63A568135F6DC483F0C82F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSERINI (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  REST NUMBER(20,7),
  OBS VARCHAR2(200),
  CANTUM1 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  CODCERTIF NUMBER(20,0),
  DATAPROD DATE,
  STARE NUMBER(2,0),
  TG DATE,
  DIVIZOR NUMBER(10,0),
  BUCATI NUMBER(10,0),
  DATAPROD1 DATE,
  TG1 DATE,
  CODPRODUCATOR NUMBER(20,0),
  SERIE VARCHAR2(75),
  PARITATE NUMBER(20,7),
  NRCERTIF VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSERLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F6972861E4F2686A38143B58D6C63EB098EBFF5F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSERLUNA (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>81EC15950007324E5E9FC36730224233D2BAB6B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC (
  CODNIRSTOC NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODLIVR1 NUMBER(20,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DISCLIKISTOC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SUPLNEDED NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  ADMAX NUMBER(20,7),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(23,10),
  VALOARE NUMBER(20,7),
  MG NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ACCIZELATRANSFER NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  ANALITICTVA VARCHAR2(10),
  CONT NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODTVA NUMBER(20,0),
  INDEXMASTER NUMBER(20,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  PRETINITIAL NUMBER(20,7),
  ADAOSINITIAL NUMBER(20,7),
  CODIOARTINITIAL NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  TIPPRETMAX NUMBER(1,0),
  DENFURN VARCHAR2(100),
  PUSTANDARD NUMBER(1,0),
  PRETREFERINTA NUMBER(20,7),
  MGPARINTE NUMBER(1,0),
  ACTUALIZPRET NUMBER(1,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  DENCLASA VARCHAR2(150),
  CODEXTERNCLI VARCHAR2(30),
  SUPLIMCLASA NUMBER(12,2),
  PUVANZARE NUMBER(20,7),
  ADAOSPUVANZ NUMBER(20,7),
  CATPRETVANZ NUMBER(20,0),
  TIPCATPRETVANZ NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>316D92EE7B25304EC1F256DF5B745C9B7CBFB97A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC1 (
  CODNIRSTOC NUMBER(20,0),
  CODNIRSTOCORIG NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  PRETMAT NUMBER(20,7),
  DIRTY NUMBER(1,0),
  DINSTOC NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>744CBBE5120F831C9976BB449D5A16562EE1D7B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC1_MAN (
  CODNIRSTOC NUMBER(20,0),
  CODNIRSTOCORIG NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODLUNA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOCINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C05A8E26D310CD17680CC81A2BD5F9D136190E39</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOCINI (
  CODNIRSTOC NUMBER(20,0),
  CODOBJSTOCINI NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODINTR NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  PRETINREG NUMBER(20,7),
  TVA NUMBER(20,7),
  TG DATE,
  TIPSERIE NUMBER(1,0),
  FURNIZOR NUMBER(20,0),
  MG NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  CANTNIR NUMBER(20,7),
  INITIALIZARI NUMBER(1,0),
  PUMAXIMAL NUMBER(20,7),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(20,7),
  CODTRANSF1 NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODLIVR1 NUMBER(20,7),
  NRCERTIF VARCHAR2(25),
  PUVAL NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  DENOBIECT VARCHAR2(200),
  PUSTANDARD NUMBER(1,0),
  TIPNIR NUMBER(3,0),
  CODGESTPROD NUMBER(20,0),
  PRETINITIAL NUMBER(20,7),
  ACHIZINITIAL NUMBER(20,7),
  CODIOARTINITIAL NUMBER(20,0),
  ACTUALIZPRET NUMBER(1,0),
  REST NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  CODCENTRU NUMBER(20,0),
  TIPIMPORT NUMBER(1,0),
  PROVIZION NUMBER(20,7),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C714AC4CA59AE96482C91CABDE0CF6CC66C943E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC_INITIAL (
  CODNIRSTOC NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODLIVR1 NUMBER(20,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DISCLIKISTOC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SUPLNEDED NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  ADMAX NUMBER(20,7),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(30),
  PARITATE NUMBER(23,10),
  VALOARE NUMBER(20,7),
  MG NUMBER(1,0),
  DIFPRET NUMBER(1,0),
  ACCIZELATRANSFER NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  ANALITICTVA VARCHAR2(10),
  CONT NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODTVA NUMBER(20,0),
  INDEXMASTER NUMBER(20,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  PRETINITIAL NUMBER(20,7),
  ADAOSINITIAL NUMBER(20,7),
  CODIOARTINITIAL NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  TIPPRETMAX NUMBER(1,0),
  DENFURN VARCHAR2(100),
  PUSTANDARD NUMBER(1,0),
  PRETREFERINTA NUMBER(20,7),
  MGPARINTE NUMBER(1,0),
  ACTUALIZPRET NUMBER(1,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  DENCLASA VARCHAR2(150),
  CODEXTERNCLI VARCHAR2(30),
  SUPLIMCLASA NUMBER(12,2),
  PUVANZARE NUMBER(20,7),
  ADAOSPUVANZ NUMBER(20,7),
  CATPRETVANZ NUMBER(20,0),
  TIPCATPRETVANZ NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC_LA_DATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2DDD68CDC145E1C88D55DDCE3AA2976C50BFE1BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC_LA_DATA (
  CODNIRSTOC NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>39642387E31C768D67700E28FAE088AE92AF88BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC_MAN (
  CODNIRSTOC NUMBER(20,0),
  CODNIR NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CODTRANSF1 NUMBER(20,0),
  CODDVI1 NUMBER(20,0),
  CODNIRSTOCPARINTE NUMBER(20,0),
  CANTNIR NUMBER(20,7),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  PRET NUMBER(20,7),
  ADAOS NUMBER(20,7),
  TVA NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODLIVR1 NUMBER(20,0),
  REST NUMBER(20,7),
  PROCENTADAOS NUMBER(20,7),
  SUPLIMENT NUMBER(20,7),
  CANTFURN NUMBER(20,7),
  ROTLEI NUMBER(2,0),
  ROTVALUTA NUMBER(2,0),
  CODLOCATIE NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  TG DATE,
  PUMAXIMAL NUMBER(20,7),
  FURN NUMBER(20,0),
  DATAACHIZ DATE,
  TIPDOCACHIZ NUMBER(20,0),
  CODGESTPROD NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DISCLIKISTOC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PUVAL NUMBER(20,7),
  PROVIZION NUMBER(20,7),
  SUPLNEDED NUMBER(20,7),
  SERIELOT VARCHAR2(100),
  ADMAX NUMBER(20,7),
  EUDR_RN VARCHAR2(20),
  EUDR_VN VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRSTOC_RECOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5501E144516E6129AF6E9B6BAE3269C4292E9219</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRSTOC_RECOD (
  CODVECHI NUMBER(20,0),
  CODNOU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRURI_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>287FFD0199BA73AF1AE64B533B5CB7F0A1777AE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRURI_LUNA (
  CODNIRSTOC NUMBER(20,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIRURI_SER_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60AED1BFEC3E8F38C20749C50EDCDC9D7FAF0039</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIRURI_SER_LUNA (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIR_DATA_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>80E92E66AE90CAE234DC58F4C7E16F4B631DDB79</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIR_DATA_GEST (
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIR_IN_INTERVALUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8EF2943F40486172D7AE0E042A9CC128AB7D48A1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIR_IN_INTERVALUL (
  CODOBIECT NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NIR_LA_DATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>91198501BC8BC50F242A04C32AD60FDD37BCAC33</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NIR_LA_DATA (
  CODOBIECT NUMBER(20,0),
  CANTNIR NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NJUDET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A7030DA434556F53FF14B80583B816738BA7644A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NJUDET (
  CODJUDET NUMBER(20,0),
  DEN_JUDET VARCHAR2(30),
  SIMBAUTO VARCHAR2(2),
  OBS VARCHAR2(500),
  CODTARA NUMBER(20,0),
  REGCOM NUMBER(3,0),
  CODDRP NUMBER(3,0),
  DENDRP VARCHAR2(15),
  JS NUMBER(3,0),
  ITM NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NLIMBA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9D5977C4FD313C66F693DA95411540ECB8BD801C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NLIMBA (
  CODLIMBA NUMBER(20,0),
  DENLIMBA VARCHAR2(100),
  CODTARA NUMBER(20,0),
  EXTLINK VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NLIMCREDIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7779B3F770472B857216512032D6205A6C5B9578</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NLIMCREDIT (
  CODLIMCREDIT NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  DATACONTR DATE,
  DATAEXP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  INVESTITIE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NLIMCREDIT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84661C68C838455963C33CACCF91B9E991104479</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NLIMCREDIT1 (
  CODLIMCREDIT1 NUMBER(20,0),
  CODLIMCREDIT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  DATA DATE,
  SUMA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NLOCALIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6BEEFEE07FE8DCE7BA497A3DDFC06291832C92D7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NLOCALIT (
  CODLOCALIT NUMBER(20,0),
  DEN_LOCALIT VARCHAR2(100),
  TIP VARCHAR2(20),
  CODJUDET NUMBER(20,0),
  OBS VARCHAR2(300),
  CODTARA NUMBER(20,0),
  DENSUP VARCHAR2(50),
  SIRUTA NUMBER(10,0),
  CODZONA NUMBER(20,0),
  LATITUDINE NUMBER(20,7),
  LONGITUDINE NUMBER(20,7),
  CODPOSTAL VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NLOCATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>851A34B7ACB655B9D7DFA5D63D0C16533E470F5B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NLOCATII (
  CODLOCATIE NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  INDEXLOCAL NUMBER(10,0),
  NRCELULE NUMBER(10,0),
  DESCRIERE VARCHAR2(200),
  CODEXTERN VARCHAR2(20),
  TIPLOCATIE NUMBER(1,0),
  CODLOCFIXA NUMBER(20,0),
  CODVECINLEFT NUMBER(20,0),
  CODVECINRIGHT NUMBER(20,0),
  COORDX NUMBER(10,0),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMAKETE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>64B848D34A557633BDD9821C5520DF25F57812BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMAKETE (
  CODMAKETA NUMBER(20,0),
  ESTELISTA NUMBER(1,0),
  DENMAKETA VARCHAR2(100),
  DISPLAY VARCHAR2(150),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMARCIAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>780EAFC2A9C8D8887D28B89B18EE46866F285C7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMARCIAUTO (
  CODMARCIAUTO NUMBER(20,0),
  MARCA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMESERII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>236BC4562EE533DD2E64BE366713C7522764FD56</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMESERII (
  CODMESERIE NUMBER(20,0),
  DEN_MESERIE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMODELEAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7FF0C0423411D71981027815B39737076084622</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMODELEAUTO (
  CODMODELEAUTO NUMBER(20,0),
  MODEL VARCHAR2(50),
  CODMARCIAUTO NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMONEDE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B7A2EC4A21ED832F17DBA984F3D29B99DFB84C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMONEDE (
  CODMONEDA NUMBER(20,0),
  DEN_MONEDA VARCHAR2(30),
  SIMBOL VARCHAR2(5),
  SDENUMIRE VARCHAR2(30),
  SSIMBOL VARCHAR2(5),
  ZECIMALE NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMONEDE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9071960F05429E798240F44881D18BB9DEF109E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMONEDE1 (
  CODMONEDA1 NUMBER(20,0),
  CODMONEDA NUMBER(10,0),
  CODBANCA NUMBER(20,0),
  DATA DATE,
  VALOARE NUMBER(23,6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMVS_LOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3149150138E6E9FCB308407844A0D126A41F1D31</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMVS_LOT (
  CODSERIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  GTIN VARCHAR2(100),
  SERIE VARCHAR2(100),
  DATAEXP VARCHAR2(10),
  DENUMIRE VARCHAR2(200),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NMVS_SERII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>652F40C97620E3655003B776061DB45819CA5B81</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NMVS_SERII (
  COD NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  SERIE VARCHAR2(75),
  RASPUNS VARCHAR2(500),
  CODRASPUNS VARCHAR2(50),
  STATUS VARCHAR2(50),
  DATAVERIF DATE,
  VERIFICARE NUMBER(1,0),
  SKEMETYPE VARCHAR2(10),
  GLN VARCHAR2(50),
  USERID NUMBER(20,0),
  MOTIV VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NODECHIV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A025E2A7D1BDB6973CCD94CA97C69777F16E6EAC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NODECHIV (
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  TIP NUMBER(1,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CODTIP NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  CODATRIB NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NODECHIV1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>44CF193BA60C111D8D65A06EC4AD5F0B3034626C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NODECHIV1 (
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PARITATE NUMBER(20,7),
  TIP NUMBER(1,0),
  CODTIP NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  CODATRIB NUMBER(20,0),
  STOC NUMBER(20,7),
  CANTECHIVALATA NUMBER(20,7),
  DENOBIECTECHIV VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D460B9FD8DCB114A7B987DF05B793A5F00B44981</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NODMAT (
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CANT NUMBER(10,0),
  NODORIGINAL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOPER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>377D33D1701C83BA7307113CCBF729AF51D6227E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOPER (
  CODOP NUMBER(20,0),
  CODEXTERN VARCHAR2(15),
  DENUMIRE VARCHAR2(60),
  CLASAOP NUMBER(20,0),
  TIP NUMBER(1,0),
  ACTIV NUMBER(1,0),
  CODSERVICIU NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  LOCMUNCA NUMBER(20,0),
  MARCAAUTO NUMBER(20,0),
  MODELAUTO NUMBER(20,0),
  FACTURABIL NUMBER(2,0),
  DURATA NUMBER(20,0),
  CODTIPLUCRARE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODPRESTATIE NUMBER(20,0),
  ORE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOPER1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>84D8C3C4F53D7978C4FBF4A650568F803EB01B92</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOPER1 (
  CODOP1 NUMBER(20,0),
  CODOP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(10,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(10,0),
  DENUM VARCHAR2(200),
  DENOBIECT VARCHAR2(300)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NORMEMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54EAE33131BB680D3979E4A014FDB4261FCC9167</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NORMEMAT (
  CODNORMEMAT NUMBER(20,0),
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CANTUM1 NUMBER(20,7),
  CODMAT NUMBER(20,0),
  DEN_OBIECT VARCHAR2(250),
  RELATIEUM1 NUMBER(2,0),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  CODUM NUMBER(20,0),
  CODUMSPEC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EF4E61AEF77A9B20A6BC08B28696255F62567C32</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDIT (
  CODNCREDIT NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  CODCONTV NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  DATAFACT DATE,
  TIPARTICOL NUMBER(1,0),
  OBS VARCHAR2(300),
  CODCONTRACT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  VOLUMPEARTICOLE NUMBER(1,0),
  CODCONTZ NUMBER(20,0),
  PRETBRUTC NUMBER(1,0),
  PRETBRUTV NUMBER(1,0),
  CODCARNET NUMBER(20,0),
  TRIMESTRIALA NUMBER(1,0),
  CORECTIE NUMBER(1,0),
  CODNCCORECTIE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(3),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  PREVIZIONARE NUMBER(1,0),
  IESIRIPEVOLUM NUMBER(1,0),
  CURS NUMBER(20,7),
  INCHISA NUMBER(20,0),
  VALORIGTER NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  ARECARNETDOC NUMBER(1,0),
  DATASTARTD DATE,
  DATASTOPD DATE,
  SERIEDOC VARCHAR2(20),
  CONTRACT VARCHAR2(200),
  DISCTER NUMBER(20,7),
  DISCVOL NUMBER(20,7),
  DISCCANT NUMBER(20,7),
  PENALIZARI NUMBER(20,7),
  TOTALT NUMBER(20,7),
  TOTALLEIT NUMBER(20,7),
  TOTALV NUMBER(20,7),
  TOTALLEIV NUMBER(20,7),
  TOTALC NUMBER(20,7),
  TOTALLEIC NUMBER(20,7),
  TOTALP NUMBER(20,7),
  TOTALLEIP NUMBER(20,7),
  TOTALZ NUMBER(20,7),
  TOTALLEIZ NUMBER(20,7),
  TOTALDISCZ NUMBER(20,7),
  TIPDISCV NUMBER(1,0),
  DISCPROV NUMBER(20,7),
  ARECORECTII NUMBER(10,0),
  TOTALDISCV NUMBER(20,7),
  TOTALFACT NUMBER(20,7),
  TOTALDIF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDIT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>04DED99D1369127AE8C675C1C571D03C75A02CDA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDIT1 (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  TIPOPER VARCHAR2(1),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  PREVIZIONAT NUMBER(20,7),
  CODDISCOUNT NUMBER(20,0),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  TIP NUMBER(1,0),
  PROCTVA NUMBER(6,3),
  OBSNAV VARCHAR2(450),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B8A442689A10F4569FD069FF43693EEC99B380D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITC (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  ARTICOL VARCHAR2(250),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DOC VARCHAR2(250),
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VAL NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  PROCDISC NUMBER(20,7),
  VALFARATVA NUMBER(20,7),
  PRET_B NUMBER(20,7),
  VAL_B NUMBER(20,7),
  VALLEI_B NUMBER(20,7),
  DISCOUNT_B NUMBER(20,7),
  VALFARATVA_B NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VAL_N NUMBER(20,7),
  VALLEI_N NUMBER(20,7),
  DISCOUNT_N NUMBER(20,7),
  VALFARATVA_N NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  PROCTVA NUMBER(6,3),
  OBSNAV VARCHAR2(450),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITCT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>28684E3A0F59082266A6293BDE09A61B3A6E104A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITCT (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  ARTICOL VARCHAR2(250),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DOC VARCHAR2(250),
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VAL NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  DOCSTINGATOR VARCHAR2(250),
  VALPLATA NUMBER(20,7),
  TERMEN DATE,
  VALOAREOLD NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITCT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F91792F53DAFE0A2088FC972AF1C7FDD239A077A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITCT_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  ARTICOL VARCHAR2(250),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DOC VARCHAR2(250),
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VAL NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  DOCSTINGATOR VARCHAR2(250),
  VALPLATA NUMBER(20,7),
  TERMEN DATE,
  VALOAREOLD NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A278B9C3C0DEE276880CF34EB32EF6613EAAC9CF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITC_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  ARTICOL VARCHAR2(250),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DOC VARCHAR2(250),
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VAL NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  PROCDISC NUMBER(20,7),
  VALFARATVA NUMBER(20,7),
  PRET_B NUMBER(20,7),
  VAL_B NUMBER(20,7),
  VALLEI_B NUMBER(20,7),
  DISCOUNT_B NUMBER(20,7),
  VALFARATVA_B NUMBER(20,7),
  PRET_N NUMBER(20,7),
  VAL_N NUMBER(20,7),
  VALLEI_N NUMBER(20,7),
  DISCOUNT_N NUMBER(20,7),
  VALFARATVA_N NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  PROCTVA NUMBER(6,3),
  OBSNAV VARCHAR2(450),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITFACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B0F28F4E97124810767A074707765A711800FC0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITFACT (
  CODNCFACT NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  VALT NUMBER(20,7),
  CODDOC1 NUMBER(20,0),
  RESTVAL NUMBER(20,7),
  VALALTE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITFACT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C84AA0EFC4167DAEB755960744F9DD44198D0B63</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITFACT_MAN (
  CODNCFACT NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  VALT NUMBER(20,7),
  CODDOC1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5F81EF4BD88335CAABB0895598926D7C0BCC6651</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITP (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  DOC VARCHAR2(250),
  CONT VARCHAR2(100),
  MONEDA VARCHAR2(100),
  TERMEN DATE,
  SUBUNITATEA VARCHAR2(250),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  VALPLATA NUMBER(20,7),
  DOCPLATA VARCHAR2(250),
  ZILEPLATA NUMBER(10,0),
  DISCOUNT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITP_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67C6E81CB2194DADD31DD030D4AE9959FF9E0705</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITP_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  DOC VARCHAR2(250),
  CONT VARCHAR2(100),
  MONEDA VARCHAR2(100),
  TERMEN DATE,
  SUBUNITATEA VARCHAR2(250),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  VALPLATA NUMBER(20,7),
  DOCPLATA VARCHAR2(250),
  ZILEPLATA NUMBER(10,0),
  DISCOUNT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8944BDA2606825EA7CC2E57277700045B15AD8F7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITT (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  PREVIZIONAT NUMBER(20,7),
  DOC VARCHAR2(250),
  CONT VARCHAR2(100),
  MONEDA VARCHAR2(100),
  TERMEN DATE,
  SUBUNITATEA VARCHAR2(250),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  VALPLATA NUMBER(20,7),
  DOCPLATA VARCHAR2(250),
  ZILEPLATA NUMBER(10,0),
  DISCOUNT NUMBER(20,7),
  ARTICOL VARCHAR2(250),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  VALFARATVA NUMBER(20,7),
  PROCTVA NUMBER(6,3),
  VALORIG NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  TERMENFIX DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CA13C574C537DBD7C0E59A7AA9B5B7D2DDCB3930</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITT_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  PREVIZIONAT NUMBER(20,7),
  DOC VARCHAR2(250),
  CONT VARCHAR2(100),
  MONEDA VARCHAR2(100),
  TERMEN DATE,
  SUBUNITATEA VARCHAR2(250),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  VALPLATA NUMBER(20,7),
  DOCPLATA VARCHAR2(250),
  ZILEPLATA NUMBER(10,0),
  DISCOUNT NUMBER(20,7),
  ARTICOL VARCHAR2(250),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  VALFARATVA NUMBER(20,7),
  PROCTVA NUMBER(6,3),
  VALORIG NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  TERMENFIX DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6B3258F5B0995C7FDFEE4F5B76FD296C3798DA5D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITV (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  DOC VARCHAR2(250),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  VALDOC_B NUMBER(20,7),
  VALLEI_B NUMBER(20,7),
  DISCOUNT_B NUMBER(20,7),
  VALDOC_N NUMBER(20,7),
  VALLEI_N NUMBER(20,7),
  DISCOUNT_N NUMBER(20,7),
  CODDOCMASTER NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  PROCTVA NUMBER(6,3),
  PROCDISC NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITV_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5264266C4492D1A01F35FBF73E008E75E54C940</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITV_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  DOC VARCHAR2(250),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  VALDOC_B NUMBER(20,7),
  VALLEI_B NUMBER(20,7),
  DISCOUNT_B NUMBER(20,7),
  VALDOC_N NUMBER(20,7),
  VALLEI_N NUMBER(20,7),
  DISCOUNT_N NUMBER(20,7),
  CODDOCMASTER NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  PROCTVA NUMBER(6,3),
  PROCDISC NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F239732BF2871F81D9DD593EB57292F05DC91109</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITZ (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  DOC VARCHAR2(250),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  DISCOUNT NUMBER(20,7),
  DENCRITERIU VARCHAR2(40),
  CREDITAT NUMBER(20,7),
  DEN_CLASEDISC VARCHAR2(50),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITZC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EAF1A6FC816DE586D34198A7795F434138CB39C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITZC (
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  DENCRITERIU VARCHAR2(40),
  CREDITAT NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  DEN_CLASEDISC VARCHAR2(50),
  PROCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITZC_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3EF957566524457DF016B07E3596F122D107CF47</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITZC_MAN (
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  DENCRITERIU VARCHAR2(40),
  CREDITAT NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  DEN_CLASEDISC VARCHAR2(50),
  PROCTVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDITZ_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4D2216A1F54D7359F1751A19888295994F896464</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDITZ_MAN (
  CODNCREDIT1 NUMBER(20,0),
  CODNCREDIT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODOBLIGSTINS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODOBLIGSTINGATOR NUMBER(20,0),
  OBS VARCHAR2(200),
  VALDIF NUMBER(20,7),
  VALOAREOLD NUMBER(20,7),
  CODCLASEDISC NUMBER(20,0),
  CODNCREDIT1ORIG NUMBER(20,0),
  CODDISCOUNT NUMBER(20,0),
  VALDOC NUMBER(20,7),
  VALLEI NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  DOC VARCHAR2(250),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MONEDA VARCHAR2(100),
  SEDIU VARCHAR2(250),
  CURS NUMBER(20,4),
  DISCOUNT NUMBER(20,7),
  DENCRITERIU VARCHAR2(40),
  CREDITAT NUMBER(20,7),
  DEN_CLASEDISC VARCHAR2(50),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NOTECREDIT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3691F72B29EDBCC1013C8414A381891D2FB04EAD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NOTECREDIT_MAN (
  CODNCREDIT NUMBER(20,0),
  CODCONTRACT2 NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  CODCONTV NUMBER(20,0),
  CODCONTT NUMBER(20,0),
  CODCONTC NUMBER(20,0),
  CODCONTP NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  DATAFACT DATE,
  TIPARTICOL NUMBER(1,0),
  OBS VARCHAR2(300),
  CODCONTRACT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  VOLUMPEARTICOLE NUMBER(1,0),
  CODCONTZ NUMBER(20,0),
  PRETBRUTC NUMBER(1,0),
  PRETBRUTV NUMBER(1,0),
  CODCARNET NUMBER(20,0),
  TRIMESTRIALA NUMBER(1,0),
  CORECTIE NUMBER(1,0),
  CODNCCORECTIE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(3),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  PREVIZIONARE NUMBER(1,0),
  IESIRIPEVOLUM NUMBER(1,0),
  ARECARNETDOC NUMBER(1,0),
  DATASTARTD DATE,
  DATASTOPD DATE,
  SERIEDOC VARCHAR2(20),
  CONTRACT VARCHAR2(200),
  DISCTER NUMBER(20,7),
  DISCVOL NUMBER(20,7),
  DISCCANT NUMBER(20,7),
  PENALIZARI NUMBER(20,7),
  TOTALT NUMBER(20,7),
  TOTALLEIT NUMBER(20,7),
  TOTALV NUMBER(20,7),
  TOTALLEIV NUMBER(20,7),
  TOTALC NUMBER(20,7),
  TOTALLEIC NUMBER(20,7),
  TOTALP NUMBER(20,7),
  TOTALLEIP NUMBER(20,7),
  TOTALZ NUMBER(20,7),
  TOTALLEIZ NUMBER(20,7),
  TOTALDISCZ NUMBER(20,7),
  TIPDISCV NUMBER(1,0),
  DISCPROV NUMBER(20,7),
  ARECORECTII NUMBER(10,0),
  TOTALDISCV NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARC0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4C62E7539BB71489BF6F5F0E46CA41FD56B80708</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARC0 (
  CODNPARC0 NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  DATABORD DATE,
  KMBORD NUMBER(10,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  CODPERS NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  CODCMD NUMBER(20,0),
  COMB NUMBER(5,0),
  SOFER VARCHAR2(400),
  FAZ VARCHAR2(50),
  CMD VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARC0_MAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23250B2DB3C19F632931EFD4BCB5D2F68EF4B061</HASHVAL>
  <TEXT>CREATE TABLE TMP_NPARC0_MAN (
  CODNPARC0 NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  DATABORD DATE,
  KMBORD NUMBER(10,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  CODPERS NUMBER(20,0),
  CODFAZ NUMBER(20,0),
  CODCMD NUMBER(20,0),
  COMB NUMBER(5,0),
  SOFER VARCHAR2(400),
  FAZ VARCHAR2(50),
  CMD VARCHAR2(50),
  DATACITIRES VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>346801DA5A2D2BA2D3B99550EBE498DF4D228920</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARC1 (
  CODNPARC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  ART NUMBER(20,0),
  CANT NUMBER(10,0),
  POZITIE NUMBER(1,0),
  BORDINSTAL NUMBER(10,0),
  ATENTIE NUMBER(10,0),
  COD NUMBER(20,0),
  CODPART NUMBER(20,0),
  MONTAT NUMBER(1,0),
  ANOTIMP NUMBER(1,0),
  ADANCIME NUMBER(2,0),
  LATIME NUMBER(4,0),
  INALTIME NUMBER(3,0),
  DIAMETRU NUMBER(3,0),
  GAMA NUMBER(1,0),
  RUNFLAT NUMBER(1,0),
  SUV NUMBER(1,0),
  OFFROAD NUMBER(1,0),
  XL NUMBER(1,0),
  MS NUMBER(1,0),
  OBS VARCHAR2(500),
  SERIA VARCHAR2(75),
  DOT NUMBER(4,0),
  BORDDEM NUMBER(10,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(50),
  SERIE VARCHAR2(75)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARC2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F66B0DCB2EFFDEE700E2FA0EE0E742DA9F24E290</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARC2 (
  CODNPARC2 NUMBER(20,0),
  COD NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DOC NUMBER(20,0),
  SN VARCHAR2(20),
  ELIBERAT DATE,
  EXPIRA DATE,
  ATENTIE NUMBER(10,0),
  OBS VARCHAR2(500),
  VALOARE NUMBER(20,7),
  CODINTR1 NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DOCUMENT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARC3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10C16AD59D7471BED7F3053FF2979E102DA8A531</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARC3 (
  CODNPARC3 NUMBER(20,0),
  COD NUMBER(20,0),
  INTERVENTIE NUMBER(20,0),
  DATAU DATE,
  KMU NUMBER(10,0),
  DATAV DATE,
  KMV NUMBER(10,0),
  DATAA DATE,
  KMA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  CODCMD NUMBER(20,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCAUT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>33CA7705299EDF5350170067FBA99627F8D8C461</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCAUT (
  CODNPARCAUT NUMBER(20,0),
  CODART NUMBER(20,0),
  NRINV NUMBER(20,0),
  NRINREG VARCHAR2(20),
  SOFER NUMBER(20,0),
  KMPORNIRE NUMBER(20,0),
  TIP NUMBER(1,0),
  DATAINREG DATE,
  MARCA NUMBER(20,0),
  MODEL NUMBER(20,0),
  ANF NUMBER(4,0),
  SERIEC VARCHAR2(20),
  CULOARE NUMBER(20,0),
  LUNG NUMBER(10,0),
  LAT NUMBER(10,0),
  INALT NUMBER(10,0),
  TIPMOTOR VARCHAR2(20),
  SERIEM VARCHAR2(20),
  MOTOR NUMBER(20,0),
  CILINDREE NUMBER(10,0),
  PUTERE NUMBER(10,0),
  CMM NUMBER(10,2),
  CMU NUMBER(10,2),
  CME NUMBER(10,2),
  TIPINCARC NUMBER(1,0),
  GREUTATE NUMBER(10,0),
  MASAM NUMBER(10,0),
  MASAU NUMBER(10,0),
  MASAURDF NUMBER(10,0),
  MASAURFDF NUMBER(10,0),
  LOCT NUMBER(4,0),
  LOCF NUMBER(4,0),
  LOCS NUMBER(4,0),
  LOCP NUMBER(4,0),
  ANVRECOMF VARCHAR2(15),
  ANVRECOMS VARCHAR2(15),
  ANVOPT1F VARCHAR2(15),
  ANVOPT1S VARCHAR2(15),
  ANVOPT2F VARCHAR2(15),
  ANVOPT2S VARCHAR2(15),
  KG NUMBER(10,2),
  KGR NUMBER(10,2),
  SARCINA NUMBER(20,0),
  CODPUTERE NUMBER(20,0),
  GRUPAUTO NUMBER(20,0),
  TIPREM NUMBER(20,0),
  INSTSP NUMBER(20,0),
  AER NUMBER(20,0),
  REZERVOR NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  CULOAREC VARCHAR2(50),
  SURSAE VARCHAR2(50),
  EXTERN NUMBER(1,0),
  PARTENER NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODGEST NUMBER(20,0),
  PARTLEAS NUMBER(20,0),
  NRCONTR VARCHAR2(50),
  MONEDA NUMBER(20,0),
  RATALEAS NUMBER(10,2),
  RATARCA NUMBER(10,2),
  RATACASCO NUMBER(10,2),
  DATAACHIZ DATE,
  DATAENDLEAS DATE,
  PARTUTILIZ NUMBER(20,0),
  PERSUTILIZ NUMBER(20,0),
  OBS VARCHAR2(200),
  TIPULEI VARCHAR2(50),
  TIPVEHICUL NUMBER(1,0),
  CODDEALER NUMBER(20,0),
  LIMITAKM NUMBER(8,0),
  DOTARI VARCHAR2(500),
  CODRADIO VARCHAR2(15),
  TRANSMISIE NUMBER(1,0),
  TRACTIUNE NUMBER(1,0),
  GPS NUMBER(1,0),
  GPL NUMBER(1,0),
  FRIGO NUMBER(1,0),
  CODPARTGPS NUMBER(20,0),
  CODEXTERN VARCHAR2(100),
  CODARTCOMB NUMBER(20,0),
  CONSSTATH NUMBER(20,7),
  NUMEDEALER VARCHAR2(250),
  DEN_OBIECT VARCHAR2(250),
  GR_OBIECT VARCHAR2(250),
  DEN_MODEL VARCHAR2(50),
  DEN_MARCA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCAUT0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>00DF0B54BA70C51EEFB7073ADBACC2ABEE25DA5E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCAUT0 (
  CODNPARC0 NUMBER(20,0) NOT NULL,
  CODPARCAUT NUMBER(20,0),
  DATABORD DATE,
  KMBORD NUMBER(10,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCAUT_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F2A665194173BA3546A47E604C3ADDF2131F5626</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCAUT_MAN (
  CODNPARCAUT NUMBER(20,0),
  CODART NUMBER(20,0),
  NRINV NUMBER(20,0),
  NRINREG VARCHAR2(20),
  SOFER NUMBER(20,0),
  KMPORNIRE NUMBER(20,0),
  TIP NUMBER(1,0),
  DATAINREG DATE,
  MARCA NUMBER(20,0),
  MODEL NUMBER(20,0),
  ANF NUMBER(4,0),
  SERIEC VARCHAR2(20),
  CULOARE NUMBER(20,0),
  LUNG NUMBER(10,0),
  LAT NUMBER(10,0),
  INALT NUMBER(10,0),
  TIPMOTOR VARCHAR2(20),
  SERIEM VARCHAR2(20),
  MOTOR NUMBER(20,0),
  CILINDREE NUMBER(10,0),
  PUTERE NUMBER(10,0),
  CMM NUMBER(10,2),
  CMU NUMBER(10,2),
  CME NUMBER(10,2),
  TIPINCARC NUMBER(1,0),
  GREUTATE NUMBER(10,0),
  MASAM NUMBER(10,0),
  MASAU NUMBER(10,0),
  MASAURDF NUMBER(10,0),
  MASAURFDF NUMBER(10,0),
  LOCT NUMBER(4,0),
  LOCF NUMBER(4,0),
  LOCS NUMBER(4,0),
  LOCP NUMBER(4,0),
  ANVRECOMF VARCHAR2(15),
  ANVRECOMS VARCHAR2(15),
  ANVOPT1F VARCHAR2(15),
  ANVOPT1S VARCHAR2(15),
  ANVOPT2F VARCHAR2(15),
  ANVOPT2S VARCHAR2(15),
  KG NUMBER(10,2),
  KGR NUMBER(10,2),
  SARCINA NUMBER(20,0),
  CODPUTERE NUMBER(20,0),
  GRUPAUTO NUMBER(20,0),
  TIPREM NUMBER(20,0),
  INSTSP NUMBER(20,0),
  AER NUMBER(20,0),
  REZERVOR NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  CULOAREC VARCHAR2(50),
  SURSAE VARCHAR2(50),
  EXTERN NUMBER(1,0),
  PARTENER NUMBER(20,0),
  INACTIV NUMBER(1,0),
  CODGEST NUMBER(20,0),
  PARTLEAS NUMBER(20,0),
  NRCONTR VARCHAR2(50),
  MONEDA NUMBER(20,0),
  RATALEAS NUMBER(10,2),
  RATARCA NUMBER(10,2),
  RATACASCO NUMBER(10,2),
  DATAACHIZ DATE,
  DATAENDLEAS DATE,
  PARTUTILIZ NUMBER(20,0),
  PERSUTILIZ NUMBER(20,0),
  OBS VARCHAR2(200),
  TIPULEI VARCHAR2(50),
  TIPVEHICUL NUMBER(1,0),
  CODDEALER NUMBER(20,0),
  LIMITAKM NUMBER(8,0),
  DOTARI VARCHAR2(500),
  CODRADIO VARCHAR2(15),
  TRANSMISIE NUMBER(1,0),
  TRACTIUNE NUMBER(1,0),
  GPS NUMBER(1,0),
  GPL NUMBER(1,0),
  FRIGO NUMBER(1,0),
  CODPARTGPS NUMBER(20,0),
  CODEXTERN VARCHAR2(100),
  CODARTCOMB NUMBER(20,0),
  CONSSTATH NUMBER(20,7),
  NUMEDEALER VARCHAR2(250),
  DEN_OBIECT VARCHAR2(250),
  GR_OBIECT VARCHAR2(250),
  DEN_MODEL VARCHAR2(50),
  DEN_MARCA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCCOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DB81DBFABC4B17DCA40F476B971FA530F034AEE3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCCOM (
  CODNPARCCOM NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  KMBORD NUMBER(10,0),
  TIPCOMSA NUMBER(1,0),
  DATAINCHIDERII DATE,
  INMATRROM NUMBER(1,0),
  INSPECTIE NUMBER(1,0),
  PIESECLIENT NUMBER(1,0),
  PROBADRUM NUMBER(1,0),
  SPALARE NUMBER(1,0),
  DZ NUMBER(1,0),
  NIVREZERVOR NUMBER(2,0),
  NRDOSARDAUNE VARCHAR2(30),
  NRAUTREP VARCHAR2(30),
  DATAAUTREP DATE,
  KMGARANTIE NUMBER(6,0),
  DATAGARANTIE DATE,
  TIPCOMANDA VARCHAR2(20),
  ASIGURATOR NUMBER(20,0),
  DISTANTA NUMBER(5,0),
  ADRESASEDIU VARCHAR2(30),
  OBS VARCHAR2(1500),
  RECOMANDARI VARCHAR2(500),
  NRORE NUMBER(20,7),
  CATEGPRET NUMBER(5,0),
  KMBORDE NUMBER(10,0),
  IDRAR NUMBER(20,0),
  ANULATRAR NUMBER(5,0),
  FINALIZATRAR NUMBER(5,0),
  SERIACOM VARCHAR2(20),
  NRCOM NUMBER(20,0),
  DATACOM DATE,
  PARTCOM VARCHAR2(100),
  VALCOM NUMBER(20,7),
  MONCOM VARCHAR2(30),
  OBSCOM VARCHAR2(1500),
  PARCPROPRIU NUMBER(1,0),
  INMATRICULARE DATE,
  SERIEAUTO VARCHAR2(20),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  CULOARE VARCHAR2(50),
  ENERGIE VARCHAR2(50),
  DOCUMENT VARCHAR2(200),
  TIPRAC NUMBER(1,0),
  DATAFABR NUMBER(4,0),
  TIPVEHICUL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCCOM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>42E0193F85D1A77D20EFD7EED77E2BD3336DE4DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCCOM1 (
  CODCOMANDA3 NUMBER(20,0),
  COMANDA VARCHAR2(100),
  DATA DATE,
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  TIP NUMBER(1,0),
  EXECUTAT NUMBER(1,0),
  OPERATIE VARCHAR2(60),
  LUCRARE VARCHAR2(60),
  GARANTIE NUMBER(1,0),
  CODLUCRARE NUMBER(20,0),
  CODOPERATIE NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  CODCOMANDA2 NUMBER(20,0),
  CODINTR1_1 NUMBER(20,0),
  CODINTR1_2 NUMBER(20,0),
  CODINTR1_3 NUMBER(20,0),
  DOCINTR_1 VARCHAR2(100),
  DOCINTR_2 VARCHAR2(100),
  DOCINTR_3 VARCHAR2(100),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>448AA14522B71A41AF189A6925C1438CD81A3B1B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCG (
  CODNPARCG NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODGESTINI NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCMD NUMBER(20,0),
  STATUS NUMBER(1,0),
  DATA DATE,
  CMD VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARCSA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>443860CB1AB60D4E61A9FE850F911DDF63984302</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARCSA (
  CODNPARCCOM NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  KMBORD NUMBER(10,0),
  TIPCOMSA NUMBER(1,0),
  DATAINCHIDERII DATE,
  INMATRROM NUMBER(1,0),
  INSPECTIE NUMBER(1,0),
  PIESECLIENT NUMBER(1,0),
  PROBADRUM NUMBER(1,0),
  SPALARE NUMBER(1,0),
  DZ NUMBER(1,0),
  NIVREZERVOR NUMBER(2,0),
  NRDOSARDAUNE VARCHAR2(30),
  NRAUTREP VARCHAR2(30),
  DATAAUTREP DATE,
  KMGARANTIE NUMBER(6,0),
  DATAGARANTIE DATE,
  TIPCOMANDA VARCHAR2(20),
  ASIGURATOR NUMBER(20,0),
  DISTANTA NUMBER(5,0),
  ADRESASEDIU VARCHAR2(30),
  OBS VARCHAR2(1500),
  RECOMANDARI VARCHAR2(500),
  NRORE NUMBER(20,7),
  CATEGPRET NUMBER(5,0),
  KMBORDE NUMBER(10,0),
  IDRAR NUMBER(20,0),
  ANULATRAR NUMBER(5,0),
  FINALIZATRAR NUMBER(5,0),
  SERIACOM VARCHAR2(20),
  NRCOM NUMBER(20,0),
  DATACOM DATE,
  PARTCOM VARCHAR2(100),
  VALCOM NUMBER(20,7),
  MONCOM VARCHAR2(30),
  OBSCOM VARCHAR2(1500),
  PARCPROPRIU NUMBER(1,0),
  INMATRICULARE DATE,
  SERIEAUTO VARCHAR2(20),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  CULOARE VARCHAR2(50),
  ENERGIE VARCHAR2(50),
  DOCUMENT VARCHAR2(200),
  TIPRAC NUMBER(1,0),
  DATAFABR NUMBER(4,0),
  TIPVEHICUL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>73D49E7A58D0BB048B2EC9CD157F57D6A8627E31</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPART (
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  REGCOM VARCHAR2(20),
  CODEXTERN VARCHAR2(50),
  CODMONEDA NUMBER(20,0),
  AUTORIZATIE VARCHAR2(50),
  CODINTERN VARCHAR2(50),
  CODCLASA NUMBER(20,0),
  CODCATEGPRET NUMBER(20,0),
  TIPPART NUMBER(1,0),
  SCADENTAC NUMBER(5,0),
  SCADENTAV NUMBER(5,0),
  DISCOUNT NUMBER(6,3),
  CODCATEGDISC NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPPARTENER NUMBER(2,0),
  DATAADAUGARII DATE,
  OBS VARCHAR2(300),
  POZA BLOB,
  PERSOANAFIZICA NUMBER(1,0),
  VERFACT NUMBER(10,0),
  VERDISPLIVR NUMBER(10,0),
  COLDISCOUNT NUMBER(1,0),
  INFOBLOCAT VARCHAR2(100),
  EXPIRAREAUTORIZ DATE,
  CODSTATISTICBNR VARCHAR2(30),
  MUSAICOLET NUMBER(1,0),
  STRATEGIC NUMBER(1,0),
  CIFRAAFACERI NUMBER(20,7),
  DOMENIUACTIV VARCHAR2(200),
  NRANGAJATI NUMBER(20,0),
  SURSALEAD NUMBER(20,0),
  LEAD NUMBER(1,0),
  TVALAINCASARE NUMBER(1,0),
  MODAPLICPROCDISC NUMBER(1,0),
  PROCCURSTRANSF NUMBER(20,7),
  VERPROFORMA NUMBER(10,0),
  FIDELIZARE NUMBER(1,0),
  MAJORARI NUMBER(20,7),
  TIPBLOCAJ NUMBER(1,0),
  POPRIRE_ANAF NUMBER(1,0),
  CODRESPONSABIL NUMBER(20,0),
  CODDOMENIUACT NUMBER(20,0),
  DOCDEFONORCOM NUMBER(1,0),
  MODPROMOFACTCOM NUMBER(1,0),
  VALIDAREPRETOFERTA NUMBER(1,0),
  IESCUCOMANDA NUMBER(1,0),
  VERFACTAVIZ NUMBER(10,0),
  VALMINCMD NUMBER(20,7),
  CANTMINCMD NUMBER(20,7),
  ZIAPROVIZ NUMBER(10,0),
  PERAPROVIZ NUMBER(10,0),
  CODCONTRACTCADRU NUMBER(20,0),
  DATANASTERE DATE,
  SPLITTVA NUMBER(1,0),
  GDPR NUMBER(1,0),
  ZILELIVRARE NUMBER(5,0),
  SAFT_EXPORT NUMBER(1,0),
  FARAPENALIZARI NUMBER(1,0),
  INACTIV NUMBER(1,0),
  PREOFEFURNVAR NUMBER(1,0),
  TIPANALIZAPRET NUMBER(1,0),
  VERAVIZIES NUMBER(10,0),
  EF_ITEM NUMBER(1,0),
  EF_PARTY NUMBER(1,0),
  EF_IMPARTGEN NUMBER(1,0),
  EF_CUSTOM NUMBER(20,0),
  EF_TAXE NUMBER(1,0),
  CATEGTARIF NUMBER(2,0),
  EF_PROIECT VARCHAR2(20),
  ZILEACHIZ NUMBER(5,0),
  CULOARE NUMBER(8,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPART1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1A5BA1B25337ADA2DF4CFF962C666F77C0260D52</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPART1 (
  CODPART1 NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODIOPART NUMBER(20,0),
  CREDITCLIENT NUMBER(18,2),
  VOLUMTRANZC NUMBER(18,2),
  CREDITFURN NUMBER(18,2),
  VOLUMTRANZF NUMBER(16,2),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SCADENTAV NUMBER(5,0),
  SCADENTAC NUMBER(5,0),
  DISCOUNT NUMBER(6,3),
  CASSBAZAMIN NUMBER(1,0),
  SIMBOLCASS VARCHAR2(2),
  GDPR NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPART1CRM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C4224B4E6E6886FB68EBAAFB7D346D3ED6554B2D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPART1CRM (
  CODPART1CRM NUMBER(20,0),
  CODPART NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CIFRAAFACERI NUMBER(20,7),
  NRANGAJATI NUMBER(20,0),
  LEAD NUMBER(1,0),
  SURSALEAD NUMBER(20,0),
  CODRESPONSABIL NUMBER(20,0),
  STARE NUMBER(2,0),
  MODPLATA NUMBER(20,0),
  CIP NUMBER(1,0),
  DATASTART DATE,
  DATAEND DATE,
  PROFIT NUMBER(20,7),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTACTIVIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A8413513DD9D99EF7FAB347D972683628D290B2F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTACTIVIT (
  CODPARTACTIVIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODACTIVIT NUMBER(20,0),
  DIM NUMBER(10,2),
  CODPART1CRM NUMBER(20,0),
  DENACTIVIT VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C6E0A9630A2A7B5790A24CF08E8D5AEDA01E8D95</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTB (
  CODPARTB NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODBANK NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  CONTBANCA VARCHAR2(30),
  SUCURSALA VARCHAR2(20),
  CODSWIFT VARCHAR2(30),
  CODMONEDA NUMBER(20,0),
  TIPCOMISION NUMBER(1,0),
  OBS VARCHAR2(100),
  CONTTVA NUMBER(1,0),
  SIMBOL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTB_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B69CD4693D5FCE8CC1268E55F557B1B0A9B187F4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTB_IMPORT (
  CODPARTB NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODBANK NUMBER(20,0),
  FACTURARE NUMBER(1,0),
  CODLOCALIT NUMBER(20,0),
  CONTBANCA VARCHAR2(30),
  SUCURSALA VARCHAR2(20),
  CODSWIFT VARCHAR2(30),
  CODMONEDA NUMBER(20,0),
  SIMBOL VARCHAR2(30),
  DENBANCA VARCHAR2(50),
  SIMBOLBANCA VARCHAR2(30),
  CODINTERNPART VARCHAR2(50),
  LOCALITATE VARCHAR2(50),
  JUDET VARCHAR2(30),
  TARA VARCHAR2(30),
  SIMBOLMONEDA VARCHAR2(30),
  CODEXTERNPART VARCHAR2(50),
  CODFISCALPART VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTCODFISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>24084F183FCC5317E443D97DDC5B58879FEAC7BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTCODFISC (
  COD_CODFISCAL NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  PRINCIPAL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTCONCURENTI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3A87AF9025C115695A7358986E7B67DFBDF58B7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTCONCURENTI (
  CODPARTCONCURENT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODCONCURENT NUMBER(20,0),
  CODPART1CRM NUMBER(20,0),
  DENCONCURENT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTDISC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>47DD1EE7F56A7A060D6AF3413F752263F4AA677A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTDISC (
  CODPARTDISC NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODCATEGDISC NUMBER(20,0),
  INDEXLOCAL NUMBER(4,0),
  DEN_PART VARCHAR2(100),
  CODCLASA NUMBER(20,0),
  CUMULAT NUMBER(1,0),
  OFFINVOICE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTDISC2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E12CFB920F6E6BED985C51A394213068FAC5B86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTDISC2 (
  CODPARTDISC NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODCATEGDISC NUMBER(20,0),
  INDEXLOCAL NUMBER(4,0),
  DEN_PART VARCHAR2(100),
  CODCLASA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTDISCRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7F216083CC8F2A995F9A65C3CA069362F9229FBE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTDISCRETAIL (
  COD NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  CODCATEGDISC NUMBER(20,0),
  INDEXLOCAL NUMBER(4,0),
  CODPARTDISC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTDOMACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D7DC3BCCF875D8A56A4DE3BEFBE57775247049BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTDOMACT (
  CODPARTDOMACT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODDOMENIUACT NUMBER(20,0),
  CODPART1CRM NUMBER(20,0),
  DENDOMENIUACT VARCHAR2(160),
  CODCAEN VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTLSTCLASE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9C7480CA8C65E5389E19656E8ABA70A1E6F5E5AA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTLSTCLASE (
  CODNPARTLSTCLASE NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODCLASA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTOPORTUNITATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>10997581E973D4303C890B28E33250A70F757583</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTOPORTUNITATI (
  CODOPORTUNITATE NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODCARNETDOC NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODAGENT NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  VENITEST NUMBER(20,7),
  VENITPROB NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A24B7366E2379C189D1E61406F10934074E2C3E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTRETAIL (
  CODPARTRETAIL NUMBER(20,0),
  CODPART NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  REGCOM VARCHAR2(20),
  OBS VARCHAR2(300),
  CODEXTERN VARCHAR2(50),
  CODINTERN VARCHAR2(50),
  TIPPART NUMBER(1,0),
  COLDISCOUNT NUMBER(1,0),
  DATACREARE TIMESTAMP(6),
  USERID NUMBER(20,0),
  TIPMODIF VARCHAR2(1),
  CODCLASA NUMBER(20,0),
  FIDELIZARE NUMBER(1,0),
  DATANASTERE DATE,
  BLOCAT NUMBER(1,0),
  INFOBLOCAT VARCHAR2(100),
  CODCATEGPRET NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTSUBUNIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3808D7AE90E29C8FC523A6FA13FAD40EB575AD6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTSUBUNIT (
  CODPARTSUBUNIT NUMBER(20,0),
  CODPART NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  ZIAPROVIZ NUMBER(10,0),
  PERAPROVIZ NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTTR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AA48865E20EF2B0A9C9F240CF7ED74ADF6B5BA61</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTTR (
  CODPARTTR NUMBER(20,0),
  CODPART NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  ACTIV NUMBER(1,0),
  DATADOC DATE,
  CODPERS NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  OBS VARCHAR2(250),
  PERMIS VARCHAR2(50),
  NRPASS VARCHAR2(12),
  CODTARA VARCHAR2(3),
  ADRESA VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  TELEFON VARCHAR2(20),
  EMAIL VARCHAR2(50),
  SEDII NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTTR_2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5E807972687ACA8923C71D34DAB936EB31B0AD1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTTR_2 (
  CODPARTTR NUMBER(20,0),
  CODPART NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  ACTIV NUMBER(1,0),
  DATADOC DATE,
  CODPERS NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  OBS VARCHAR2(250),
  PERMIS VARCHAR2(50),
  NRPASS VARCHAR2(12),
  CODTARA VARCHAR2(3),
  ADRESA VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  TELEFON VARCHAR2(20),
  SEDII NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTTR_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9899704DE96C6E5060B2DFCDD9B59A0A7D385173</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTTR_IMPORT (
  CODPARTTR NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  DELEGAT VARCHAR2(150),
  CNP VARCHAR2(30),
  DOC VARCHAR2(2),
  SERIEDOC VARCHAR2(20),
  NRDOC VARCHAR2(10),
  ELIBERAT VARCHAR2(50),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(100),
  CODEXTERNPART VARCHAR2(50),
  CODINTERNPART VARCHAR2(50),
  CODFISCALPART VARCHAR2(75)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTTR_LNK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>387E2CC1E4A4B132C331265F6512CDAE7DA601BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTTR_LNK (
  CODPARTTRLNK NUMBER(20,0),
  CODPARTTR NUMBER(20,0),
  CODPART NUMBER(20,0),
  SEDII NUMBER(1,0),
  DELEGAT VARCHAR2(150),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPARTTR_LNK1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>756D60BB02809F08F924011D9DBD1D30D3361513</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPARTTR_LNK1 (
  CODPARTTRLNK1 NUMBER(20,0),
  CODPARTTRLNK NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  SEDIU VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPART_ANAF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C39A8EFA7DD1E5E0C3B8DF504996B8111BF96992</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPART_ANAF (
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(200),
  CUI NUMBER(20,0),
  DATA DATE,
  STARE NUMBER(1,0),
  OLD_CONTRIB NUMBER(2,0),
  CONTRIBUABIL NUMBER(2,0),
  OLD_SPLITTVA NUMBER(1,0),
  SPLITTVA NUMBER(1,0),
  ADRESA VARCHAR2(500),
  LOCALITATE VARCHAR2(50),
  JUDET VARCHAR2(30),
  STRADA VARCHAR2(100),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  NUMAR1 NUMBER(20,0),
  NUMAR2 VARCHAR2(10),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  OLD_ADRESA VARCHAR2(500),
  CHANGE_ADRESA NUMBER(1,0),
  OLD_RTVAI NUMBER(1,0),
  RTVAI NUMBER(1,0),
  OLD_NRREGCOM VARCHAR2(30),
  NRREGCOM VARCHAR2(30),
  DENUMIRE VARCHAR2(100),
  CHANGE_DEN NUMBER(1,0),
  OLD_INACTIV NUMBER(1,0),
  INACTIV NUMBER(1,0),
  STAREINREG VARCHAR2(100),
  STAREINACTIV VARCHAR2(50),
  MESAJ VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPART_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4BB89B3E1E0F9A7F05954E1DCADB5D4FDE47E50E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPART_IMPORT (
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  REGCOM VARCHAR2(20),
  CODEXTERN VARCHAR2(50),
  CODMONEDA NUMBER(20,0),
  AUTORIZATIE VARCHAR2(30),
  CODINTERN VARCHAR2(50),
  CODCLASA NUMBER(20,0),
  CODCATEGPRET NUMBER(20,0),
  TIPPART NUMBER(1,0),
  SCADENTAC NUMBER(5,0),
  SCADENTAV NUMBER(5,0),
  DISCOUNT NUMBER(6,3),
  CODCATEGDISC NUMBER(20,0),
  BLOCAT NUMBER(1,0),
  TIPPARTENER NUMBER(2,0),
  DATAADAUGARII DATE,
  OBS VARCHAR2(300),
  POZA BLOB,
  PERSOANAFIZICA NUMBER(1,0),
  VERFACT NUMBER(10,0),
  VERDISPLIVR NUMBER(10,0),
  COLDISCOUNT NUMBER(1,0),
  INFOBLOCAT VARCHAR2(30),
  EXPIRAREAUTORIZ DATE,
  CODSTATISTICBNR VARCHAR2(30),
  MUSAICOLET NUMBER(1,0),
  STRATEGIC NUMBER(1,0),
  CIFRAAFACERI NUMBER(20,7),
  DOMENIUACTIV VARCHAR2(200),
  NRANGAJATI NUMBER(20,0),
  SURSALEAD NUMBER(20,0),
  LEAD NUMBER(1,0),
  TVALAINCASARE NUMBER(1,0),
  MODAPLICPROCDISC NUMBER(1,0),
  PROCCURSTRANSF NUMBER(20,7),
  VERPROFORMA NUMBER(10,0),
  SIMBOLCLASA VARCHAR2(30),
  SIMBOL_IOPART VARCHAR2(30),
  CODFISCALPRINCIPAL VARCHAR2(75),
  SIMBOLBANCA VARCHAR2(30),
  DENBANCA VARCHAR2(30),
  CONTBANCA VARCHAR2(30),
  CONTIMPLICIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C809D43E4BE866E26723FA751325BDD17452F137</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERS (
  CODPERS NUMBER(20,0),
  MARCA NUMBER(20,0),
  NUME VARCHAR2(30),
  PRENUME VARCHAR2(30),
  CNP VARCHAR2(30),
  BISERIA VARCHAR2(3),
  BINR VARCHAR2(8),
  LOCNASTERE NUMBER(20,0),
  ADRESA VARCHAR2(40),
  PRENUMET VARCHAR2(20),
  PRENUMEM VARCHAR2(20),
  LOCALITN NUMBER(20,0),
  DATAN DATE,
  SCIVILA NUMBER(1,0),
  SMILITAR NUMBER(1,0),
  ACTIV NUMBER(1,0),
  STRAINATATE NUMBER(1,0),
  AGENT NUMBER(1,0),
  DELEGAT NUMBER(1,0),
  AGENDA NUMBER(20,0),
  BIELIBERATDE VARCHAR2(50),
  LADATADE DATE,
  TARAN NUMBER(20,0),
  CETATENIE NUMBER(1,0),
  POZA BLOB,
  LOGONNAME NUMBER(20,0),
  ACCMAS VARCHAR2(100),
  COMISION NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODLOC NUMBER(20,0),
  DATAPLECARII DATE,
  DATAANGAJARII DATE,
  OBS VARCHAR2(250),
  OREPEZI NUMBER(4,2),
  CODCENTRU NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  IBAN VARCHAR2(30),
  CODBANK NUMBER(20,0),
  CODANALIZA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F3E883F86CAB7D85378FDE1B2DAAA5C31244097B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERS1 (
  CODPERS1 NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODIOPERS NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  CODFORMATIE NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0),
  CODMESERIE NUMBER(20,0),
  SCHIMB NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCONTACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3E9792CDCFD57FACEA70BCF66A41F78DAF76846</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCONTACT (
  CODPERSC NUMBER(20,0),
  NUME VARCHAR2(20),
  PRENUME VARCHAR2(40),
  TELEFON VARCHAR2(40),
  EMAIL VARCHAR2(100),
  FUNCTIE VARCHAR2(100),
  DATANASTERE DATE,
  RZONA NUMBER(1,0),
  ID NUMBER(10,0),
  TIP NUMBER(1,0),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  SERIEBI VARCHAR2(3),
  NRBI VARCHAR2(10),
  ELIBERATBI VARCHAR2(100),
  DATABI DATE,
  CNP VARCHAR2(30),
  OBS VARCHAR2(240),
  CODLOCATIE NUMBER(20,0),
  NUMELOCATIE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCONTACT_IMPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD6EC4DEB2F9232A94A329680C0DE127AA8508BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCONTACT_IMPORT (
  CODPERSC NUMBER(20,0),
  NUME VARCHAR2(20),
  PRENUME VARCHAR2(40),
  TELEFON VARCHAR2(40),
  EMAIL VARCHAR2(40),
  FUNCTIE VARCHAR2(100),
  DATANASTERE DATE,
  RZONA NUMBER(1,0),
  ID NUMBER(10,0),
  TIP NUMBER(1,0),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  SERIEBI VARCHAR2(3),
  NRBI VARCHAR2(10),
  ELIBERATBI VARCHAR2(100),
  DATABI DATE,
  CNP VARCHAR2(30),
  CODINTERNPART VARCHAR2(50),
  CODEXTERNPART VARCHAR2(50),
  CODFISCALPART VARCHAR2(75)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCURS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>129A9BA0D3BB84DD9F849B1587C35EBDD477774F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCURS (
  CODNPERSCURS NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  STARE NUMBER(1,0),
  DATA DATE,
  NOTA NUMBER(10,0),
  DATAPLAN DATE,
  ORE_REALIZ NUMBER(10,0),
  TIPFORMARE NUMBER(1,0),
  NIVELFORMARE NUMBER(1,0),
  CODOBIECTIV NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0),
  DEN_OBIECTIV VARCHAR2(50),
  SUPLIM NUMBER(1,0),
  DEN_CURS VARCHAR2(30),
  DEN_TEMA VARCHAR2(60),
  SSTARE VARCHAR2(30),
  STIPFORMARE VARCHAR2(30),
  SNIVELFORMARE VARCHAR2(30),
  ORE_AFER NUMBER(10,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  ACTIV NUMBER(1,0),
  DATAANGAJARII DATE,
  DATAPLECARII DATE,
  PLECAT NUMBER(1,0),
  SEL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCURS0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2EC995F18638A7E369881713FEC5A0316C1B10AC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCURS0 (
  CODPERS NUMBER(20,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  FORMATIE VARCHAR2(50),
  FUNCTIE VARCHAR2(50),
  MESERIE VARCHAR2(50),
  SCHIMB NUMBER(2,0),
  ACTIV NUMBER(1,0),
  DATAANGAJARII DATE,
  DATAPLECARII DATE,
  PLECAT NUMBER(1,0),
  SELECTAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCURSX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B3BD7E885F682D012D2ECD68674D24D5EA27912</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCURSX (
  CODNPERSCURS NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  STARE NUMBER(1,0),
  DATA DATE,
  NOTA NUMBER(10,0),
  DATAPLAN DATE,
  ORE_REALIZ NUMBER(10,0),
  TIPFORMARE NUMBER(1,0),
  NIVELFORMARE NUMBER(1,0),
  CODOBIECTIV NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0),
  DEN_OBIECTIV VARCHAR2(50),
  SUPLIM NUMBER(1,0),
  DEN_CURS VARCHAR2(30),
  DEN_TEMA VARCHAR2(60),
  SSTARE VARCHAR2(30),
  STIPFORMARE VARCHAR2(30),
  SNIVELFORMARE VARCHAR2(30),
  ORE_AFER NUMBER(10,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  ACTIV NUMBER(1,0),
  DATAPLECARII DATE,
  PLECAT NUMBER(1,0),
  SEL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCURSY</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D7541E7461B62C3EF56BA043F4553D8587F55A6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCURSY (
  CODNPERSCURS NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  STARE NUMBER(1,0),
  DATA DATE,
  NOTA NUMBER(10,0),
  DATAPLAN DATE,
  ORE_REALIZ NUMBER(10,0),
  TIPFORMARE NUMBER(1,0),
  NIVELFORMARE NUMBER(1,0),
  CODOBIECTIV NUMBER(20,0),
  CODFUNCTIE NUMBER(20,0),
  DEN_OBIECTIV VARCHAR2(50),
  SUPLIM NUMBER(1,0),
  DEN_CURS VARCHAR2(30),
  DEN_TEMA VARCHAR2(60),
  SSTARE VARCHAR2(30),
  STIPFORMARE VARCHAR2(30),
  SNIVELFORMARE VARCHAR2(30),
  ORE_AFER NUMBER(10,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200),
  ACTIV NUMBER(1,0),
  DATAPLECARII DATE,
  PLECAT NUMBER(1,0),
  SEL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCVLOCM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>302F6FAD28329D811DBED33A7CBA82208066E32E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCVLOCM (
  CODPERSCVLOCM NUMBER(20,0),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DELA DATE,
  PANALA DATE,
  LOCMUNCA VARCHAR2(30),
  CODFISCAL VARCHAR2(75)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCVPAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>39938EAEB588277ABCE98BB31D33CAF0BE2B9D0D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCVPAS (
  CODPERSCVPAS NUMBER(20,0),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  PASIUNE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCVSCOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4A262A5646FFDF3BBB490D2BB7C73ED93DEF3AC6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCVSCOL (
  CODPERSCVSCOL NUMBER(20,0),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DELA DATE,
  PANALA DATE,
  SCOALA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSCVSKIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E3553310CB691C9D078020D3FECE8C46F7F2229</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSCVSKIL (
  CODPERSCVSKIL NUMBER(20,0),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  SKILL VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERSSOLDLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>92BBDCA78DC85949447AE81E8BE320FE24C3E7ED</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERSSOLDLUNA (
  CODPERSSOLDLUNA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SIMBOL VARCHAR2(30),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPERS_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>95283F031A6A7FC12529441975E34AE16D4A666D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPERS_MANEVRA (
  CODPERS NUMBER(20,0),
  MARCA NUMBER(20,0),
  NUME VARCHAR2(30),
  PRENUME VARCHAR2(30),
  NUMEPRENUME VARCHAR2(60),
  EMAIL VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NPLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>753E9FF16FBC514FD5362B0F512FED5F1CEF14DA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NPLINK (
  CODNIRSTOC NUMBER(20,0),
  CODIES1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NREMAUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1778D7428A969C9BF551AC49F153DD65ADA2AFF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NREMAUTO (
  CODREMAUTO NUMBER(20,0),
  TIPURIREMORCI VARCHAR2(200),
  SPOR_150_1 NUMBER(10,2),
  SPOR_150_2 NUMBER(10,2),
  SPOR150_215_1 NUMBER(10,2),
  SPOR150_215_2 NUMBER(10,2),
  SPOR215_1 NUMBER(10,2),
  SPOR215_2 NUMBER(10,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSCADTL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>64BBC2C3309FBBFF88D437C2F3FA96F8F765F0CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSCADTL (
  CODSCADTL NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  DATACONTR DATE,
  DATAEXP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATEA NUMBER(20,0),
  TOTRATA NUMBER(20,7),
  TOTDOBANDA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSCADTL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54B87D7CCF447496B32CECF59FC042902E85D93C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSCADTL1 (
  CODSCADTL1 NUMBER(20,0),
  CODSCADTL NUMBER(20,0),
  DATASCAD DATE,
  RATA NUMBER(20,7),
  DOBANDA NUMBER(20,7),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSEDIIPARTRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FDB67BDA2AE5A279F7A68FE946CED684C001900C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSEDIIPARTRETAIL (
  CODSEDIU NUMBER(20,0),
  CODPARTRETAIL NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  CODLOCALIT NUMBER(20,0),
  DENLOCALIT VARCHAR2(50),
  CODJUDET NUMBER(20,0),
  CODTARA NUMBER(20,0),
  TELEFON VARCHAR2(40),
  FAX VARCHAR2(20),
  EMAIL VARCHAR2(350),
  STRADA VARCHAR2(100),
  NR1 NUMBER(5,0),
  NR2 VARCHAR2(10),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  SECTOR NUMBER(2,0),
  CODPOSTAL VARCHAR2(10),
  SEDIUSOCIAL NUMBER(1,0),
  CODAGENDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSERII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>95A0D39D7487424DFC5678202ECEADFC46C6577C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSERII (
  CODSERIE NUMBER(20,0),
  SERIE VARCHAR2(75),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(100),
  CODPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSERTAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9085F44AF1D4144C96E629A5CE358993F1C999BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSERTAR (
  CODSERTAR NUMBER(20,0),
  CODEMITENT NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  SUBUNITATE NUMBER(20,0),
  TIP NUMBER(1,0),
  DECONT NUMBER(1,0),
  DOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALOARE NUMBER(20,7),
  DATADECONT DATE,
  DEPUS NUMBER(1,0),
  DATACREARE DATE,
  USERID NUMBER(20,0),
  OBS VARCHAR2(500),
  DATAOBLIG DATE,
  BANCA NUMBER(20,0),
  MONEDA NUMBER(20,0),
  NRI VARCHAR2(30),
  INDEXLOCAL NUMBER(5,0),
  EMITENT VARCHAR2(100),
  PARTENER VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSERTAR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7CC7C4D0EDBE9D0D2A045CF1E063F1EC1A8F4101</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSERTAR1 (
  CODSERTAR1 NUMBER(20,0),
  CODSERTAR NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CODGENERAL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSERTAR1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>159B624E2BF8CE631DBD2E10DAE04025BA1FC166</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSERTAR1_INITIAL (
  CODSERTAR1 NUMBER(20,0),
  CODSERTAR NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CODGENERAL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSUBUNIT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9E1841D1394FFDED214BDAAE1B3AF4168D986161</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSUBUNIT (
  CODSUBUNIT NUMBER(20,0),
  DEN_SUBUNIT VARCHAR2(100),
  CIF VARCHAR2(30),
  REGCOM VARCHAR2(20),
  CODBANKCONT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  SATELITWM NUMBER(1,0),
  ANPORNIRE NUMBER(5,0),
  LUNAPORNIRE NUMBER(2,0),
  NUMEPRESC VARCHAR2(8),
  NOECONOMICACTIV NUMBER(1,0),
  CODSIUI VARCHAR2(15),
  CODCASA NUMBER(20,0),
  CAPITAL_SOCIAL NUMBER(20,2),
  CODBANKCONTTREZ NUMBER(20,0),
  EFACT NUMBER(1,0),
  TIPUNITJURIDICA NUMBER(1,0),
  CODPERS NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  NRCONT VARCHAR2(30),
  CODBANCATREZ NUMBER(20,0),
  NRCONTTREZ VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NSUBUNIT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9C4709EC31707C0BCCE28AC614108691188DAF4A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NSUBUNIT1 (
  CODSUBUNIT1 NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODIOFILIAL NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  TVALAINCASARE NUMBER(1,0),
  CAEN VARCHAR2(5),
  CODTVA NUMBER(20,0),
  ISFIRMA NUMBER(1,0),
  GRDECLARATIE NUMBER(3,0),
  MODEDITAREJURNAL NUMBER(1,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  PRELCANTBCAR NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F844E2FAB13673EF4E960A208EE024827540236E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTARI (
  CODTARA NUMBER(20,0),
  DEN_TARA VARCHAR2(30),
  SIMBAUTO VARCHAR2(3),
  CODMONEDA NUMBER(20,0),
  OBS VARCHAR2(300),
  STATCOMUNITAR NUMBER(1,0),
  CODLIMBA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTAXE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A184A91168DA3E4878A82157EECD3A2004D4A6B4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTAXE (
  CODTAXA NUMBER(20,0),
  DEN_TAXA VARCHAR2(30),
  CENTRALIZAT NUMBER(1,0),
  TIPPART NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTAXE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2625CEC95E107CF107426D5D01202513867CF269</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTAXE1 (
  CODTAXA1 NUMBER(20,0),
  CODTAXA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  LACEAPLIC NUMBER(1,0),
  CODCONT NUMBER(20,0),
  CODCONTCHELT NUMBER(20,0),
  ORICARETIP NUMBER(1,0),
  CODIOARTEXCL NUMBER(20,0),
  EXCLUSACCIZE NUMBER(1,0),
  EXCLUSEXPORT NUMBER(1,0),
  JACHIZ NUMBER(1,0),
  JVANZ NUMBER(1,0),
  CUMJACHIZ NUMBER(1,0),
  CUMJVANZ NUMBER(1,0),
  BAZAMAX NUMBER(20,7),
  BAZAMIN NUMBER(20,7),
  CODSERVFACT NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  STOPAJ NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SERVICIUMONETAR NUMBER(20,0),
  PROCDIMINUAREB NUMBER(12,2),
  ROTVALOARE NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  BAZAMED NUMBER(20,7),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTAXE_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ACEACFF7BF1790CC449149396DAD047F6A4C5D0C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTAXE_LUNA (
  CODTAXA1 NUMBER(20,0),
  CODTAXA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  LACEAPLIC NUMBER(1,0),
  CODCONT NUMBER(20,0),
  CODCONTCHELT NUMBER(20,0),
  ORICARETIP NUMBER(1,0),
  CODIOARTEXCL NUMBER(20,0),
  EXCLUSACCIZE NUMBER(1,0),
  EXCLUSEXPORT NUMBER(1,0),
  JACHIZ NUMBER(1,0),
  JVANZ NUMBER(1,0),
  CUMJACHIZ NUMBER(1,0),
  CUMJVANZ NUMBER(1,0),
  BAZAMAX NUMBER(20,7),
  BAZAMIN NUMBER(20,7),
  CODSERVFACT NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  STOPAJ NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  SERVICIUMONETAR NUMBER(20,0),
  PROCDIMINUAREB NUMBER(12,2),
  ROTVALOARE NUMBER(2,0),
  DEN_TAXA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTIPSEDII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>036A6CC8F3DE42A5F8ABC1BE3D0CBA86178E3BF6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTIPSEDII (
  CODTIPSEDIU NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  ICLASA NUMBER(1,0),
  CONTRONLY NUMBER(1,0),
  TIPBENEFICIAR NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTIPSEDII1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0544F107B18FA0F6F9702CB0CF16A54BF4FCA939</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTIPSEDII1 (
  CODTIPSEDIU1 NUMBER(20,0),
  CODTIPSEDIU NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENCLASEA VARCHAR2(200),
  DENOBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTIPSEDII2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D3742D6A2331D467560EDFE55E12DC199EA1CAFF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTIPSEDII2 (
  CODTIPSEDIU1 NUMBER(20,0),
  CODTIPSEDIU NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENCLASEA VARCHAR2(200),
  DENOBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA90EF91868B45933099CFF264DB0B0CC9BA3DB7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTVA (
  CODTVA NUMBER(20,0),
  DEN_TVA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTVA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3F5F59305AC2C32277C56CAB733AB014C062948</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTVA1 (
  CODTVA1 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  PROCENT NUMBER(6,3),
  CODCONTDED NUMBER(20,0),
  CODCONTCOLE NUMBER(20,0),
  CODCONTNEEX NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NTVA_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>42D481952E65EBD44DD4187FD659232209BE7B70</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NTVA_LUNA (
  CODTVA1 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  PROCENT NUMBER(6,3),
  CODCONTDED NUMBER(20,0),
  CODCONTCOLE NUMBER(20,0),
  CODCONTNEEX NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  DEN_TVA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NUM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>09D04112C307CF0A98B0907A3DB3DEF039A132C2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NUM (
  CODUM NUMBER(20,0),
  DEN_UM VARCHAR2(15),
  TIP VARCHAR2(20),
  ZECIMALE NUMBER(4,0),
  TIPUM NUMBER(1,0),
  COEF NUMBER(20,5),
  CODUMSAFT NUMBER(20,0),
  PARITATEUMSAFT NUMBER(20,7),
  ACTUALIZART NUMBER(1,0),
  OBS VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  DEN_EANCOM VARCHAR2(15),
  DEN_INTRASTAT VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NUM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C11EFE620B0DD4523E8125C68EA7830A5D41CDB2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NUM1 (
  CODUM1 NUMBER(20,0),
  CODUM NUMBER(10,0),
  SECUNDARA NUMBER(1,0),
  DEN_UM1 VARCHAR2(15),
  PARITATE NUMBER(30,15),
  ZECIMALE NUMBER(4,0),
  OBS VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  DEN_EANCOM VARCHAR2(15),
  DEN_INTRASTAT VARCHAR2(15),
  INACTIV NUMBER(1,0),
  CODUMSAFT NUMBER(20,0),
  PARITATEUMSAFT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_NZONE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AC0C9D4706535EA3F7DE72F2895753FFC6BA53F8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_NZONE (
  CODZONA NUMBER(20,0),
  DEN_ZONA VARCHAR2(50),
  SIMBOL VARCHAR2(10),
  OBS VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBIECTE_FACTURATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7033B51FCC9BA9570B94F849EC711EDE201B191F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBIECTE_FACTURATE (
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CODLINIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBIECTIVE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2BBD7DBE94F5713D3BC9D9FC722742A49FBCADE9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBIECTIVE (
  CODOBIECTIV NUMBER(20,0),
  TIP NUMBER(1,0),
  DEN_OBIECTIV VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBJSTOCINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DE0D26081A3F50DC09AA6FDF841A3328D363F0EA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBJSTOCINI (
  CODOBJSTOCINI NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  UMSEC NUMBER(20,0),
  DENUM VARCHAR2(15),
  TIPSERIE VARCHAR2(1),
  CONTIMPLICIT NUMBER(10,0),
  ARETG NUMBER(1,0),
  TVA NUMBER(20,7),
  PUMAXIMAL NUMBER(20,7),
  STOCTOTAL NUMBER(20,7),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  RELATIEUM2 NUMBER(2,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CERTIFICAT NUMBER(1,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBJTRAD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F2D9A171FB22D4F933D0CBED0FE5E61E08E86A49</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBJTRAD (
  CODOBIECTTRAD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODLIMBA NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DENUMIRETRAD VARCHAR2(200),
  DESCRIERE VARCHAR2(3000),
  AVERTIZARE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBLIGPART_LA_DATA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DAB4E15C70B1BF1981358DA2AE9841585FC5843E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBLIGPART_LA_DATA (
  CODOBLIGPIF NUMBER(20,0),
  ICONT NUMBER(20,0),
  SEMNIFICATIE NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  PREFIXDOC VARCHAR2(3),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CONT NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  MONEDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TERMEN DATE,
  CODAGENT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBLIGPIF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9B91C0E2BB3F673792AEF064E99E8D9D3BD436A7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBLIGPIF (
  CODOBLIGPIF NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  TIPPLATA NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  TIP VARCHAR2(1),
  CONTBANKTRANZACTIE NUMBER(20,0),
  CODOBLIGASOCIAT NUMBER(20,0),
  VALOAREAFISATA NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODTRANSA NUMBER(20,0),
  RESTTRANSA NUMBER(20,7),
  COEFPROVIZION NUMBER(20,7),
  ADAOSDOC NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  TVAAFISAT NUMBER(20,7),
  SPLITTVA NUMBER(1,0),
  VALPROVIZION NUMBER(20,7),
  PROCENT NUMBER(20,7),
  ZILE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(200),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  CODTREZOR1 NUMBER(20,0),
  SEMNIFCODSTINS NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100),
  SUMALEI NUMBER(20,7),
  MONEDA NUMBER(20,0),
  SUMAVALUTA NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRSEMNIF VARCHAR2(30),
  CODTERMEN NUMBER(10,0),
  AGENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(250),
  PLATA NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  CURSDOCSTINS NUMBER(20,7),
  TVALEI NUMBER(20,7),
  CURSTRANSA NUMBER(20,7),
  INFOTRANSA VARCHAR2(30),
  FARAREG NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  TIPTVA NUMBER(2,0),
  TIPTRANZACTIE NUMBER(5,0),
  PRORATA NUMBER(3,0),
  SERIADOC VARCHAR2(20),
  CURSISTORIC NUMBER(20,7),
  CODTIPPARTINCERT NUMBER(20,0),
  OBIECTTRANZSTINS NUMBER(5,0),
  TAXCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBLIGPIF_ASOCIAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>75C825A74E6F680D80F7801BAD547FE0FBD0A4BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBLIGPIF_ASOCIAT (
  CODOBLIGPIF NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  TIPPLATA NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  TIP VARCHAR2(1),
  CONTBANKTRANZACTIE NUMBER(20,0),
  CODOBLIGASOCIAT NUMBER(20,0),
  VALOAREAFISATA NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODTRANSA NUMBER(20,0),
  RESTTRANSA NUMBER(20,7),
  COEFPROVIZION NUMBER(20,7),
  ADAOSDOC NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  TVAAFISAT NUMBER(20,7),
  SPLITTVA NUMBER(1,0),
  VALPROVIZION NUMBER(20,7),
  PROCENT NUMBER(20,7),
  ZILE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  CODTREZOR1 NUMBER(20,0),
  SEMNIFCODSTINS NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100),
  SUMALEI NUMBER(20,7),
  MONEDA NUMBER(20,0),
  SUMAVALUTA NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRSEMNIF VARCHAR2(30),
  CODTERMEN NUMBER(10,0),
  AGENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(250),
  PLATA NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  CURSDOCSTINS NUMBER(20,7),
  TVALEI NUMBER(20,7),
  CURSTRANSA NUMBER(20,7),
  INFOTRANSA VARCHAR2(30),
  FARAREG NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  TIPTVA NUMBER(2,0),
  TIPTRANZACTIE NUMBER(5,0),
  PRORATA NUMBER(3,0),
  SERIADOC VARCHAR2(20),
  CURSISTORIC NUMBER(20,7),
  CODTIPPARTINCERT NUMBER(20,0),
  OBIECTTRANZSTINS NUMBER(5,0),
  TAXCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBLIGPIF_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>92158B82890E554D90B7115BFEC6F1D94F1F08C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBLIGPIF_INITIAL (
  CODOBLIGPIF NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  TIPPLATA NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  TIP VARCHAR2(1),
  CONTBANKTRANZACTIE NUMBER(20,0),
  CODOBLIGASOCIAT NUMBER(20,0),
  VALOAREAFISATA NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODTRANSA NUMBER(20,0),
  RESTTRANSA NUMBER(20,7),
  COEFPROVIZION NUMBER(20,7),
  ADAOSDOC NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  TVAAFISAT NUMBER(20,7),
  SPLITTVA NUMBER(1,0),
  VALPROVIZION NUMBER(20,7),
  PROCENT NUMBER(20,7),
  ZILE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  CODTREZOR1 NUMBER(20,0),
  SEMNIFCODSTINS NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100),
  SUMALEI NUMBER(20,7),
  MONEDA NUMBER(20,0),
  SUMAVALUTA NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRSEMNIF VARCHAR2(30),
  CODTERMEN NUMBER(10,0),
  AGENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(250),
  PLATA NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  CURSDOCSTINS NUMBER(20,7),
  TVALEI NUMBER(20,7),
  CURSTRANSA NUMBER(20,7),
  INFOTRANSA VARCHAR2(30),
  FARAREG NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  TIPTVA NUMBER(2,0),
  TIPTRANZACTIE NUMBER(5,0),
  PRORATA NUMBER(3,0),
  SERIADOC VARCHAR2(20),
  CURSISTORIC NUMBER(20,7),
  CODTIPPARTINCERT NUMBER(20,0),
  OBIECTTRANZSTINS NUMBER(5,0),
  TAXCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OBLIGVAMA_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A3CBE070456C46F311B4B3A22E1C34691598F7A2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OBLIGVAMA_INITIAL (
  CODOBLIGPIF NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  REST NUMBER(20,7),
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  TIPPLATA NUMBER(2,0),
  MAJORARI NUMBER(20,7),
  SEMNIFICATIE NUMBER(20,0),
  TIP VARCHAR2(1),
  CONTBANKTRANZACTIE NUMBER(20,0),
  CODOBLIGASOCIAT NUMBER(20,0),
  VALOAREAFISATA NUMBER(20,7),
  GRATIE NUMBER(10,0),
  CODGEST NUMBER(20,0),
  CODNPARCAUT NUMBER(20,0),
  CODTRANSA NUMBER(20,0),
  RESTTRANSA NUMBER(20,7),
  COEFPROVIZION NUMBER(20,7),
  ADAOSDOC NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  TVANEDED NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  TVAAFISAT NUMBER(20,7),
  SPLITTVA NUMBER(1,0),
  VALPROVIZION NUMBER(20,7),
  PROCENT NUMBER(20,7),
  ZILE NUMBER(20,7),
  DENDOCLEGATURA VARCHAR2(100),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  CODTREZOR1 NUMBER(20,0),
  SEMNIFCODSTINS NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100),
  SUMALEI NUMBER(20,7),
  MONEDA NUMBER(20,0),
  SUMAVALUTA NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRSEMNIF VARCHAR2(30),
  CODTERMEN NUMBER(10,0),
  AGENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(250),
  PLATA NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  PROCTVAAVANS NUMBER(20,7),
  CURSDOCSTINS NUMBER(20,7),
  TVALEI NUMBER(20,7),
  CURSTRANSA NUMBER(20,7),
  INFOTRANSA VARCHAR2(30),
  FARAREG NUMBER(1,0),
  TVAINCASARE NUMBER(1,0),
  TIPTVA NUMBER(2,0),
  TIPTRANZACTIE NUMBER(5,0),
  PRORATA NUMBER(3,0),
  SERIADOC VARCHAR2(20),
  CURSISTORIC NUMBER(20,7),
  CODTIPPARTINCERT NUMBER(20,0),
  OBIECTTRANZSTINS NUMBER(5,0),
  TAXCODE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OFERTA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CB570FDB7AA4E3ACEEA8C912805AC3C3FBD0AC42</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OFERTA (
  CODOFERTA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  PARTENER NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(500),
  MONEDA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODPERSC NUMBER(20,0),
  DATACERERE DATE,
  DATAOFERTA DATE,
  OFERTAT NUMBER(1,0),
  TOATESUBUNIT NUMBER(1,0),
  AGENT NUMBER(20,0),
  TIPLIVRARE NUMBER(2,0),
  NRMAXAPROBARI NUMBER(5,0),
  TIPBENEFICIAR NUMBER(1,0),
  CODCLASEP NUMBER(20,0),
  NRI VARCHAR2(30),
  CODNPARCAUT NUMBER(20,0),
  CODPARTCOMIS NUMBER(20,0),
  PROCDISC NUMBER(20,7),
  CODANALIZA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CURS NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  SENDMAIL NUMBER(1,0),
  VALACHIZ NUMBER(20,7),
  VALMARJA NUMBER(20,7),
  DISCOUNTPART NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OFERTA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FCF7CEA86DABDFF47AC96669ACE355029244C8A7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OFERTA1 (
  CODOFERTA1 NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  PRET NUMBER(20,7),
  OBS VARCHAR2(200),
  ZILEL NUMBER(10,0),
  ZILEC NUMBER(10,0),
  PROCADAOS NUMBER(20,2),
  PROCDISCOUNT NUMBER(25,7),
  CODEXTOFE VARCHAR2(30),
  CANTMINUM1 NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CANTMAX NUMBER(20,7),
  CODCATPRET NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CANTOPTIMUM1 NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  PRETREF NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  DATACERTIFI DATE,
  DATACERTIFF DATE,
  CODCENTRU NUMBER(20,0),
  PRETACHIZ NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  GESTACT NUMBER(20,0),
  CODLINIEDOCIMP NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  DENARTCLI VARCHAR2(200),
  CODEXTCLI VARCHAR2(30),
  PU NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  DENUM1 VARCHAR2(25),
  TIPCATPRET NUMBER(3,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODEXTERNART VARCHAR2(30),
  CODLACLIENT VARCHAR2(30),
  CODCLASEP NUMBER(20,0),
  PEARTICOL NUMBER(1,0),
  TIPLINIE VARCHAR2(1),
  COEFDISCMAJ NUMBER(20,7),
  CODCRITERIU NUMBER(20,0),
  PUREAL NUMBER(20,7),
  PULEI NUMBER(20,7),
  TVA NUMBER(20,7),
  PROIECT VARCHAR2(100),
  IDXAUTON NUMBER(5,0),
  CODRETETA NUMBER(20,0),
  CONSUM NUMBER(1,0),
  FLGCOLOR NUMBER(5,0),
  MARJA NUMBER(20,7),
  VALMARJA NUMBER(20,7),
  VALACHIZ NUMBER(20,7),
  ROTUNJIRE NUMBER(2,0),
  DEN_GRECHIV VARCHAR2(250),
  CODVAMAL VARCHAR2(80),
  PRODUCATOR VARCHAR2(100),
  CLASAARTICOL VARCHAR2(150),
  DENARTCLI_INI VARCHAR2(200),
  CODEXTCLI_INI VARCHAR2(30),
  CODLACLIENT_INI VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OFERTA1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A7C970443AB91BBB4021D84A614FA036347B7777</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OFERTA1_INITIAL (
  CODOFERTA1 NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  PRET NUMBER(20,7),
  OBS VARCHAR2(200),
  ZILEL NUMBER(10,0),
  ZILEC NUMBER(10,0),
  PROCADAOS NUMBER(20,2),
  PROCDISCOUNT NUMBER(25,7),
  CODEXTOFE VARCHAR2(30),
  CANTMINUM1 NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CANTMAX NUMBER(20,7),
  CODCATPRET NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CANTOPTIMUM1 NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  VALOARE NUMBER(20,7),
  DENARTCLI VARCHAR2(100),
  CODEXTCLI VARCHAR2(30),
  PU NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  DENUM1 VARCHAR2(25),
  TIPCATPRET NUMBER(3,0),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODEXTERNART VARCHAR2(20),
  CODLACLIENT VARCHAR2(30),
  CODCLASEP NUMBER(20,0),
  PEARTICOL NUMBER(1,0),
  TIPLINIE VARCHAR2(1),
  COEFDISCMAJ NUMBER(20,7),
  CODCRITERIU NUMBER(20,0),
  PUREAL NUMBER(20,7),
  PULEI NUMBER(20,7),
  TVA NUMBER(20,7),
  PROIECT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_ARTICOLE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9CEB06017B505B16DACDD4B67712C08B3A61C48A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_ARTICOLE (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  CODARTICOL NUMBER(20,0),
  TERMENLIVR DATE,
  CODUM NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  RESTLIVR NUMBER(20,7),
  LIVRSTOC NUMBER(20,7),
  LIVRECHIV NUMBER(20,7),
  CODEKIV NUMBER(20,0),
  DENEKIV VARCHAR2(200),
  PARITATEEKIV NUMBER(20,7),
  CODUMEKIV NUMBER(20,0),
  CODUMSPEC NUMBER(20,0),
  CANTSPEC NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RELATIEUMSPEC NUMBER(2,0),
  RELATIEUMALT NUMBER(2,0),
  CANTARIBIL NUMBER(1,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  VALOARE NUMBER(20,7),
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  SCADENTA NUMBER(5,0),
  TERMENPLATA NUMBER(5,0),
  NET NUMBER(20,7),
  BRUT NUMBER(20,7),
  A1 NUMBER(20,7),
  A2 NUMBER(20,7),
  A3 NUMBER(20,7),
  A4 NUMBER(20,7),
  KGA1 NUMBER(20,7),
  KGA2 NUMBER(20,7),
  KGA3 NUMBER(20,7),
  KGA4 NUMBER(20,7),
  FLAGINCHIDERE NUMBER(1,0),
  PROCTVA NUMBER(6,3),
  RESTNEGLIJCMD NUMBER(10,5),
  COEFDISCMAJ NUMBER(20,7),
  IDXGRUP NUMBER(5,0),
  A5 NUMBER(20,7),
  KGA5 NUMBER(20,7),
  A6 NUMBER(20,7),
  KGA6 NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  TIPLINIE VARCHAR2(2),
  CONTSERV NUMBER(20,0),
  GESTACT NUMBER(20,0),
  DEN_UM1 VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_COMENZI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>265EF967DC2158BB09CBDB0124AD96B6F7FEFF9F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_COMENZI (
  POZ NUMBER(20,0),
  CODCLIENT NUMBER(20,0),
  DENCLIENT VARCHAR2(200),
  CODSEDIU NUMBER(20,0),
  DENSEDIU VARCHAR2(200),
  SEDIUSOCIAL NUMBER(1,0),
  CODFISCAL NUMBER(20,0),
  TIPCOMANDA NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  CODAGENT NUMBER(20,0),
  DENAGENT VARCHAR2(500),
  CODDELEGAT NUMBER(20,0),
  CODPERS NUMBER(20,0),
  FARATRANSPORT NUMBER(1,0),
  CODMIJLTRANSP NUMBER(20,0),
  CODTRASEULIVR NUMBER(20,0),
  OBS VARCHAR2(500),
  CODCOMANDA NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SCADENTAV NUMBER(5,0),
  CURS NUMBER(20,4),
  MODDOC NUMBER(1,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SERIADOC VARCHAR2(20),
  TIPDOCAMB NUMBER(20,0),
  CARNETDOCAMB NUMBER(20,0),
  CODDOCAMB NUMBER(20,0),
  NRDOCAMB NUMBER(20,0),
  SERIADOCAMB VARCHAR2(20),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  GDI NUMBER(1,0),
  GAA NUMBER(1,0),
  A1 NUMBER(20,0),
  A2 NUMBER(20,0),
  A3 NUMBER(20,0),
  A4 NUMBER(20,0),
  A5 NUMBER(20,7),
  A6 NUMBER(20,7),
  KGA1 NUMBER(20,7),
  KGA2 NUMBER(20,7),
  KGA3 NUMBER(20,7),
  KGA4 NUMBER(20,7),
  KGA5 NUMBER(20,7),
  KGA6 NUMBER(20,7),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  REST NUMBER(20,7),
  FLAGLUCRU NUMBER(1,0),
  FLAGINCHIDERE NUMBER(1,0),
  DENTRASEU VARCHAR2(100),
  DENDELEGAT VARCHAR2(150),
  DENMIJLTRANSP VARCHAR2(15),
  VALOARE NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  EXCLPROMOAUT NUMBER(1,0),
  COUNTNEINCHISE NUMBER(5,0),
  CUSTODIE NUMBER(1,0),
  IDXGRUP NUMBER(5,0),
  SIMBCARNETDOC VARCHAR2(10),
  DENCARNETDOC VARCHAR2(50),
  GRLIVR NUMBER(20,7),
  MIJLTRANSP NUMBER(20,0),
  NRTRANSP VARCHAR2(30),
  TIPCMD VARCHAR2(100),
  IS_ETRANSP NUMBER(1,0),
  CARNETCH NUMBER(20,0),
  NRCH NUMBER(20,0),
  SERIACH VARCHAR2(20),
  SIMBCARNETCH VARCHAR2(10),
  VALREST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_GRUPCOM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>91D2BF89BD11D54D81745D37EA5AE8D99092C64E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_GRUPCOM (
  IDXGRUP NUMBER(5,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SERIADOC VARCHAR2(20),
  TIPDOCAMB NUMBER(20,0),
  CARNETDOCAMB NUMBER(20,0),
  CODDOCAMB NUMBER(20,0),
  NRDOCAMB NUMBER(20,0),
  SERIADOCAMB VARCHAR2(20),
  CARNETLIVR NUMBER(20,0),
  NRLIVR NUMBER(20,0),
  GDI NUMBER(1,0),
  GAA NUMBER(1,0),
  A1 NUMBER(20,0),
  A2 NUMBER(20,0),
  A3 NUMBER(20,0),
  A4 NUMBER(20,0),
  OBS VARCHAR2(500),
  CNT NUMBER(5,0),
  A5 NUMBER(20,0),
  A6 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_LIVRSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FF98C289C941610FDA9C39B052B655745E4429FE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_LIVRSTOC (
  CODARTICOL NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  PRODUCATOR VARCHAR2(50),
  CODTIPCONT NUMBER(20,0),
  DATAINTRSTOC DATE,
  EXPIRA DATE,
  CODSERIE NUMBER(20,0),
  SERIEOBIECT VARCHAR2(30),
  CODUM NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  STOC NUMBER(20,7),
  PRELUAT NUMBER(20,7),
  CANTAR NUMBER(20,7),
  REZERVATCOM1CURENTA NUMBER(20,7),
  REZERVATCOM1ALTELE NUMBER(20,7),
  REZERVATCOMCURENTA NUMBER(20,7),
  REZERVATCOMALTELE NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  STOCINITIAL NUMBER(20,7),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  SERIADOC VARCHAR2(20),
  NRDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_PRELSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>882F2302070B41D606584F9C4EA747BCD4573221</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_PRELSTOC (
  CODCOMANDA1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PRELUAT NUMBER(20,7),
  REZERVAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ONORCOM_STOCBUF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0BBA71698584D7789F8F9BED4FC7BDE546C5CC4E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ONORCOM_STOCBUF (
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  PRELUAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPORTUNITATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>20DABF43791EDDEE8A3E803132F979A2376CE237</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPORTUNITATI (
  CODOPORTUNITATE NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODCARNETDOC NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODAGENT NUMBER(20,0),
  CODCAMPANIE NUMBER(20,0),
  VENITEST NUMBER(20,7),
  VENITPROB NUMBER(3,0),
  CODSUBUNITATE NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  PROBVANZ NUMBER(3,0),
  DATASEMNARE DATE,
  CODCONTRACT NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  CODLEAD NUMBER(20,0),
  CODTASK NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  CODPROIECTCRM NUMBER(20,0),
  CODCLASEOPT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  OBS VARCHAR2(500),
  CURS NUMBER(20,7),
  CODFISCAL NUMBER(20,0),
  PARTCODFISCAL VARCHAR2(75),
  PARTLOCALIT VARCHAR2(50),
  PARTCIFRAAFACERI NUMBER(20,7),
  PARTNRANGAJATI NUMBER(20,0),
  PARTDOMENIUACT VARCHAR2(160)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPORTUNITATI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>298C9E8B5CC8ECFACF73A6E9829B921A973FC891</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPORTUNITATI1 (
  CODOPORTUNITATE1 NUMBER(20,0),
  CODOPORTUNITATE NUMBER(20,0),
  INDEXLOCAL NUMBER(3,0),
  STADIU NUMBER(1,0),
  CODAGENT NUMBER(20,0),
  INFO VARCHAR2(2000),
  DATAC DATE,
  CODMOTIV NUMBER(20,0),
  FOLLOWUP DATE,
  CODTASK NUMBER(20,0),
  CODPERS NUMBER(20,0),
  TASK VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPPER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87968EA4568ECEC93310C70BD1E54DF2A1759280</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPPER (
  CODOPPER NUMBER(20,0),
  OBS VARCHAR2(100),
  AN NUMBER(4,0),
  VALOARE NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPPER1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA026A218EB5CDD26C6671DFBE037139D6EAC99B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPPER1 (
  CODOPPER1 NUMBER(20,0),
  CODOPPER NUMBER(20,0),
  SAPTAMANA NUMBER(2,0),
  TIPOPER NUMBER(2,0),
  VALOARE NUMBER(20,7),
  TERMEN DATE,
  OBS VARCHAR2(250),
  CODELEMBUGET NUMBER(20,0),
  ELEMENT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPREG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5963E777F1D2E5E44E5907711F6C397B5BF297D3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPREG (
  CODOP NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  OBS VARCHAR2(100),
  TIPTRANZ NUMBER(1,0),
  TIPDECONT NUMBER(3,0),
  ZIDECONT NUMBER(2,0),
  CODMONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN_START NUMBER(4,0),
  LUNA_START NUMBER(2,0),
  AN_MAX NUMBER(4,0),
  LUNA_MAX NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OPREG1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>42FEAC9A4653D5CE6542B9BC8C572281A26BECE5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OPREG1 (
  CODOP1 NUMBER(20,0),
  CODOP NUMBER(20,0),
  TERMEN DATE,
  STINS NUMBER(1,0),
  OBS VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ORAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>43B37C62D8F9A77963017F7A62D4A32ED644483C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ORAR (
  CODORAR NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  OBS VARCHAR2(50),
  REPETARE NUMBER(1,0),
  INTERVAL NUMBER(4,0),
  ORA NUMBER(2,0),
  MIN NUMBER(2,0),
  ZILE_SAPT VARCHAR2(30),
  ZILE_LUNA VARCHAR2(300),
  DATA_START DATE,
  DATA_FIN DATE,
  DATACREARE DATE,
  USERID NUMBER(20,0),
  EXPLICATII VARCHAR2(1000),
  EXPIRAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OREGANTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1777529582E70B3FBB0874D93330CEF49CCE2054</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OREGANTT (
  SAPT NUMBER,
  DATA DATE,
  CODLM NUMBER(20,0),
  CODLM1 NUMBER(20,0),
  ORE NUMBER(10,3),
  CATELM1 NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OREGANTT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2584BB0455CC201267FF8CF9C913A876B0EBDF5D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OREGANTT1 (
  SAPT NUMBER,
  DATA DATE,
  CODLM NUMBER(20,0),
  CODLM1 NUMBER(20,0),
  ORE NUMBER(10,3),
  CATELM1 NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ORELM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>82963D66CDD7537E84D6626B5A97BBECDDBCF3B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ORELM (
  CODORELM NUMBER(20,0) NOT NULL,
  DATALM DATE NOT NULL,
  CODLM NUMBER(20,0),
  CODLM1 NUMBER(20,0),
  ORE NUMBER(2,0),
  SAPTAMANA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OREPONTAJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>410189C78EC5EF96F70EACB1504D5E5D825960BC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OREPONTAJ (
  CODFORMATIE NUMBER(20,0) NOT NULL,
  CODPERS NUMBER(20,0),
  ORE NUMBER(5,0),
  SALAR NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  NUMEPRENUME VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OSPATARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8090AA792A0BB456F65716B62C2CD09912CF3645</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OSPATARI (
  COD NUMBER(20,0),
  CODPERS NUMBER(20,0),
  PAROLA VARCHAR2(50),
  CODRESTAURANT NUMBER(20,0),
  SUPERVIZOR NUMBER(1,0),
  VERLISTNP NUMBER(5,0),
  NUMEPERS VARCHAR2(400),
  NEWRECORD NUMBER(1,0),
  DENVERLISTNP VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_OSPATARI_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EEFE92220EE35C202B04C37B7B790A64D25776A3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_OSPATARI_INI (
  COD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>12B7F36096AF1F286F7FC00A7FF30EC23D761ABE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETE (
  CODPACHETE NUMBER(20,0),
  DATAP TIMESTAMP(6),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATE NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(10,0),
  COLECTOR NUMBER(20,0),
  DATACOLECTARE TIMESTAMP(6),
  VERIFICATOR NUMBER(20,0),
  DATAVERIFICARE TIMESTAMP(6),
  TRANSPORTATOR NUMBER(20,0),
  DATATRANSPORT TIMESTAMP(6),
  NRPACHETE NUMBER(10,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  IDENTIFICATORP VARCHAR2(50),
  LISTAT NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPPART VARCHAR2(100),
  SEDIU NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  TIPLIVRARE NUMBER(10,0),
  TIPPACHET NUMBER(1,0),
  SPONSORIZARE NUMBER(1,0),
  DENGEST VARCHAR2(200),
  SERIEDOC VARCHAR2(20),
  DEN_PART VARCHAR2(200),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  DEN_SEDIU VARCHAR2(250),
  NUMEDELEGAT VARCHAR2(250),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E57A2B4B30D1F7E3FD25E858B27F97D5D4AD874D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETE1 (
  CODPACHETE1 NUMBER(20,0),
  CODPACHETE NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  DENTIPDOC VARCHAR2(200),
  SERIEDOC VARCHAR2(200),
  NRDOC NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  CODPART NUMBER(20,0),
  PARTENER VARCHAR2(250),
  VALOARE NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETECOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FE0CE1D5631F0A5EA0A8F9DE69571F71104C4FE8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETECOL (
  PACHET NUMBER(10,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEDLLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E65C751530F87930D014E8A580D436E09709A44B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEDLLINK (
  CODCOMANDA1 NUMBER(20,0),
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEDLLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>18780C5680CE262F724D0F508A2E2D63CABE51FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEDLLINK_INITIAL (
  CODCOMANDA1 NUMBER(20,0),
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>37224D6DF4EB55137F34E380C8F977AAC80DA6C9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEGEST (
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(100),
  VALOARE NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETELINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1365F6F2EBF93D0A0CC21FAFC36EED28D9F6335</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETELINK (
  CODIES1 NUMBER(20,0),
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETELINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9477EAE9026F350516FDECB57F6C3001B2F7539E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETELINK_INITIAL (
  CODIES1 NUMBER(20,0),
  CODPACHETEOBJ NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>806EE74CDAAF26C9DB94FC1E3F71F135F521820D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEOBJ (
  CODPACHETEOBJ NUMBER(20,0),
  CODPACHETE NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  LIVRAT NUMBER(20,7),
  DEN_UM1 VARCHAR2(15),
  DENUMIRE VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEOBJL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B145D84FF1F419DA60994C51B014FE5A064F0ED3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEOBJL (
  CODPACHETEOBJL NUMBER(20,0),
  CODPACHETE NUMBER(20,0),
  CODLIVR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PACHET NUMBER(10,0),
  CODREZERVATS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DENOBIECT VARCHAR2(250),
  UM NUMBER(20,0),
  DEN_UM1 VARCHAR2(15),
  CODOBIECT NUMBER(20,0),
  CANTAMB NUMBER(20,7),
  COLETE NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  CODAMB NUMBER(20,0),
  OK NUMBER(5,0),
  DENAMB VARCHAR2(200),
  CODGEST NUMBER(20,0),
  DENUM1 VARCHAR2(15),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  PRET NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEOBJLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>847DEF57A4CC8C1B0119B368AA1571ACAF4AE70D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEOBJLINK (
  CODIES1 NUMBER(20,0),
  CODPACHETEOBJL NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACHETEOBJLINK_I</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5D785ACD72F5737EDD9A7B3943D77CFDCF83B867</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACHETEOBJLINK_I (
  CODIES1 NUMBER(20,0),
  CODPACHETEOBJL NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACKING</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9350EFACE778BE4AB3CC4AB31920DACCE5727578</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACKING (
  CODPACKING NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  OBS VARCHAR2(200),
  DIRTY NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACKING1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19F0C5764F40F390D2AD95BF19A992B040B1ED23</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACKING1 (
  CODPACKING1 NUMBER(20,0),
  CODPACKING NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODAMB_PRIMAR NUMBER(20,0),
  CODAMB_SECUNDAR NUMBER(20,0),
  CODAMB_TERTIAR NUMBER(20,0),
  CANTAMB NUMBER(20,7),
  CANTAMBXPRIMAR NUMBER(20,7),
  CANTAMBXSECUNDAR NUMBER(20,7),
  CANTAMBXTERTIAR NUMBER(20,7),
  CANTOBJ NUMBER(20,7),
  DENAMB_PRIMAR VARCHAR2(200),
  DENAMB_SECUNDAR VARCHAR2(200),
  DENAMB_TERTIAR VARCHAR2(200),
  DENOBIECT VARCHAR2(200),
  CANTXPRIMAR NUMBER(20,7),
  NR_RANDXPRIMAR NUMBER(3,0),
  CANTRANDXPRIMAR NUMBER(20,7),
  CANTXSECUNDAR NUMBER(20,7),
  NR_RANDXSECUNDAR NUMBER(3,0),
  CANTRANDXSECUNDAR NUMBER(20,7),
  CANTXTERTIAR NUMBER(20,7),
  NR_RANDXTERTIAR NUMBER(3,0),
  CANTRANDXTERTIAR NUMBER(20,7),
  CANTCOMANDA NUMBER(20,7),
  DELETED NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACKING2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>353CF33C123FCCAA1C04782326D8639803441EE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACKING2 (
  CODPACKING2 NUMBER(20,0),
  CODPACKING1 NUMBER(20,0),
  SSCC VARCHAR2(18),
  OBS VARCHAR2(2500),
  CODAMB_FINAL NUMBER(20,0),
  CANTOBJ NUMBER(20,7),
  DEN_AMB VARCHAR2(200),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PACKING3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2E3CB38C7B0175F318066F98D4609B1FC4BABF04</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PACKING3 (
  CODPACKING3 NUMBER(20,0),
  CODPACKING2 NUMBER(20,0),
  CODREZERVATS NUMBER(20,0),
  CANT NUMBER(20,7),
  UMSEC NUMBER(20,0),
  SERIE VARCHAR2(75),
  CODSERIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PARTICIP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9292743A83B216A4AC4CEC113897B42A7D63391D</HASHVAL>
  <TEXT>CREATE TABLE TMP_PARTICIP (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  PROCENT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PARTTOT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C3B9A4E7354E882D0820BE729FB9E07D98365DC0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PARTTOT (
  CODPARTTOT NUMBER(20,0),
  CODPART NUMBER(20,0),
  SOLDREAL NUMBER(20,2),
  NEOPERAT NUMBER(20,2),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCALCUL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77D09ADE72D0D14FC8FC4F06D6957644ED8A0871</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCALCUL (
  CODPC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  CUMULAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  VARIANTA NUMBER(20,0),
  DATADOC DATE,
  TIPPUNCT NUMBER(3,0),
  OBSERVATII VARCHAR2(50),
  TIPALOC NUMBER(2,0),
  VALF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E73BB79D136D6BCD79A5227C08CEDB97CADA613E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCART (
  CODPCART NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CANT NUMBER(20,7),
  VAL NUMBER(20,7),
  VALS NUMBER(20,7),
  VALI NUMBER(20,7),
  VALA NUMBER(20,7),
  VALC NUMBER(20,7),
  VALG NUMBER(20,7),
  MAT NUMBER(20,7),
  PUNCTE NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  COEF NUMBER(20,7),
  MAN NUMBER(20,7),
  VALMAN NUMBER(20,7),
  CANTTOT NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  VALTOT NUMBER(20,7),
  VALLINIE NUMBER(20,7),
  REST NUMBER(20,7),
  ANLUNA NUMBER(6,0),
  PUCALC NUMBER(20,7),
  PRETMAT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CENTRU VARCHAR2(20),
  DENOBIECT VARCHAR2(200),
  DENIOART VARCHAR2(50),
  DENUM VARCHAR2(15),
  PRETREFERINTA NUMBER(20,7),
  PRETRETETA NUMBER(20,7),
  COMANDA VARCHAR2(50),
  DATACMD DATE,
  TIPPRET NUMBER(1,0),
  OBJ_CODEXTERN VARCHAR2(80),
  OBJ_CODINTERN VARCHAR2(80),
  CONSUM NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCART_PRET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E59E5BA85E5CAF5F577DB5D5D3011245EC310F17</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCART_PRET (
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCDIR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7FC5EC0618E352ECF4786F1ADA6CE0C5E2131DFB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCDIR (
  CODPCDIR NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  CODCMD1 NUMBER(20,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCFIRMA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>35A23FAE58003FC06DAEB38FCB56B839D55D50E2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCFIRMA (
  CODPCFIRMA NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCFIRMA_BUF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>916F7BB3FCE33C8DB86305014658B70F2AA9D8A5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCFIRMA_BUF (
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CD3808487ABBE56CCB71CAED2A475264A246DBF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCGEST (
  CODPCGEST NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  MANS NUMBER(20,7),
  VALI NUMBER(20,7),
  VALA NUMBER(20,7),
  VALC NUMBER(20,7),
  VALG NUMBER(20,7),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  PUNCTE NUMBER(20,7),
  VALMATN NUMBER(20,7),
  VALPUNCT NUMBER(20,7),
  COEFMAN NUMBER(20,7),
  DENGEST VARCHAR2(30),
  VALS NUMBER(20,7),
  VALD NUMBER(20,7),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>69A15D5B6911C8E105139284FDD0C7470FE3E752</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII (
  CODPCSECTII NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  FAZA NUMBER(1,0),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6E4B6294BFE53F7A53211995E98C5221BFFBDA98</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII2 (
  CODPCSECTII2 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  FAZA NUMBER(1,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII2_1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>23B8CCF14904A44A4720D0FF8DAF8F68FC57D86A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII2_1 (
  CODPCSECTII2_1 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DB5BBA0D299226531BEC72E38456EE28DD3280E7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII3 (
  CODPCSECTII3 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  FAZA NUMBER(1,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII3_1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3F8E651DFCBAF0F5AF25C242F21AF95D8DEEB131</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII3_1 (
  CODPCSECTII3_1 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII4</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ACE878884651F4865B19713FC77B176813F76966</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII4 (
  CODPCSECTII4 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  FAZA NUMBER(1,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII5</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AD2D3793F05221E20FD4180BA8A39400D1D8E148</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII5 (
  CODPCSECTII5 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  FAZA NUMBER(1,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20),
  TOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PCSECTII5_1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B84C8EC74EA618F7DA32F0EA930A165164B9B13E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PCSECTII5_1 (
  CODPCSECTII5_1 NUMBER(20,0),
  CODPC NUMBER(20,0),
  CODNEST NUMBER(20,0),
  VAL NUMBER(20,7),
  CODD NUMBER(20,0),
  CODC NUMBER(20,0),
  CODCC NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DENGEST VARCHAR2(30),
  CENTRU VARCHAR2(30),
  DEBIT VARCHAR2(20),
  CREDIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PERISABIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0671022CEB31C6D8937B19E57275907A37D8A765</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PERISABIL (
  CODPERISABIL NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  OBS VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PERISABIL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A9C243DB397814F92E26EAC58B0F2535CE04FE94</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PERISABIL1 (
  CODPERISABIL1 NUMBER(20,0),
  CODPERISABIL NUMBER(20,0),
  LUNA_INI NUMBER(20,0),
  LUNA_FIN NUMBER(20,0),
  NRZILE NUMBER(3,0),
  OBS1 VARCHAR2(200),
  NRZILEDIR NUMBER(3,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PERISABIL2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C413A7196B7A90A8E43036C0C68DB0D14522B2D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PERISABIL2 (
  CODPERISABIL2 NUMBER(20,0),
  CODPERISABIL NUMBER(20,0),
  LUNA_INI NUMBER(2,0),
  LUNA_FIN NUMBER(2,0),
  ZI_INI NUMBER(2,0),
  ZI_FIN NUMBER(2,0),
  STOCMEDIU NUMBER(20,7),
  TIPSEZON NUMBER(1,0),
  OBS1 VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PERSONAL_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>58BA51C37222C7D1F8D38009F2E0E3077DA3C49B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PERSONAL_MAN (
  COD NUMBER(20,0),
  PERSOANE VARCHAR2(2500),
  MARCI VARCHAR2(2500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PER_TVACOLECTAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6FA5FD531D5A7CB02BD256292ADEF22CDE461407</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PER_TVACOLECTAT (
  DATA1 DATE,
  DATA2 DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_LOCM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A962AED37F7BA2588C6508DE2E392F29644BE241</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_LOCM (
  DENUMIRE VARCHAR2(200),
  DISPONIBIL NUMBER(20,7),
  NECESAR NUMBER(20,7),
  DIFERENTE NUMBER(20,7),
  CODLOCMUNCA NUMBER(20,0),
  DISPONIBILM NUMBER(20,7),
  NECESARM NUMBER(20,7),
  DIFERENTEM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_LOCM_CMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>36C04F0F7C3E2D2E144C61F853227D58293DA64F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_LOCM_CMD (
  CODLMC NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DATAPROGRAMARE DATE,
  NRCMD NUMBER(20,3),
  PRIORITATE NUMBER(10,0),
  DEN_OBIECT VARCHAR2(200),
  NECESAR NUMBER(20,7),
  NECESARM NUMBER(20,7),
  DEN_UM VARCHAR2(15),
  CANTPROD NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODOP NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_LOCM_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>895C699B012056FA3F51D5E41AFF63C800B16D09</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_LOCM_GEST (
  SECTIE VARCHAR2(200),
  CODGEST NUMBER(20,0),
  CODLOCMUNCA NUMBER(20,0),
  DISPONIBIL NUMBER(20,7),
  NECESAR NUMBER(20,7),
  DIFERENTE NUMBER(20,7),
  DISPONIBILM NUMBER(20,7),
  NECESARM NUMBER(20,7),
  DIFERENTEM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8E5EB8681BF5AB685A88C13C37AB417DEE0AF9D9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAN (
  CODOP NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  DEN_OP VARCHAR2(250),
  DEN_TARIF VARCHAR2(250),
  TARIF NUMBER(20,7),
  ORE NUMBER(20,7),
  VALOARE NUMBER(20,7),
  OREM NUMBER(20,7),
  OPERATII NUMBER(20,7),
  DEN_LOCM VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAN_CMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A5C0F84F49BB38131CC1A2C54D7A9CC7CDACED44</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAN_CMD (
  CODOP NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  DATADOC DATE,
  NRDOC NUMBER(20,3),
  DENUMIRE VARCHAR2(250),
  CODEXTERN VARCHAR2(40),
  NECESAR NUMBER(20,7),
  NECESARM NUMBER(20,7),
  DEN_UM VARCHAR2(15),
  CANTPROD NUMBER(20,7),
  VALOARE NUMBER(20,7),
  PRIORITATE NUMBER(10,0),
  OPERATII NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAN_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>32EA9E903ACC38AD88C6EFA5589852C469E5E727</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAN_GEST (
  CODOP NUMBER(20,0),
  CODGEST NUMBER(20,0),
  DEN_GEST VARCHAR2(250),
  ORE NUMBER(20,7),
  VALOARE NUMBER(20,7),
  OREM NUMBER(20,7),
  OPERATII NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CDD62EEDD462FDFF193B42A0417784AF74EB11FD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAT (
  CODOBIECT NUMBER(20,0),
  TERMEN VARCHAR2(10),
  CULANSARE NUMBER(1,0),
  UMSEC NUMBER(10,0),
  CODCOMANDA1 NUMBER(20,0),
  NRDOC NUMBER(20,3),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  DEN_UM1 VARCHAR2(15),
  NECESAR NUMBER,
  CONSUMAT NUMBER,
  DIFERENTE NUMBER,
  STOCDISP NUMBER,
  REZERVAT NUMBER,
  STOCFURN NUMBER,
  ALTEREZ NUMBER(20,7),
  RESTASIGURAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAT_CMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1107F0F1AF4A408C0347193AE94E5796C49685B4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAT_CMD (
  NRDOC NUMBER(20,3),
  DATADOC DATE,
  DENOBJ VARCHAR2(200),
  DEN_UM VARCHAR2(15),
  CANT NUMBER(20,7),
  TIP NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  STOCREZ NUMBER(20,7),
  CODEXTERN VARCHAR2(200),
  CANTPROD NUMBER(20,7),
  PRIORITATE NUMBER(10,0),
  CODCOMANDA1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_MAT_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AB1FE16C1B21401D189E7ED6595B4105FA49B3F9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_MAT_GEST (
  CODOBIECT NUMBER(20,0),
  DENOBJ VARCHAR2(200),
  DEN_UM VARCHAR2(15),
  DEN_GEST VARCHAR2(100),
  CANTPROGRAMAT NUMBER(20,7),
  STOCDISP NUMBER(20,7),
  RESTASIGURAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  REZERVAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_SDV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A7B5718DDCEDC07BAA5D5E851F3FEB732C9F786</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_SDV (
  DENUMIRE VARCHAR2(200),
  DEN_UM VARCHAR2(15),
  CODEXTERN VARCHAR2(40),
  REST NUMBER,
  STOCFURN NUMBER,
  CANTACT NUMBER,
  CANTDOC NUMBER,
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_SDV_CMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E6D9F5E76DB8706635BDCC6A0D13F4895DCD74E2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_SDV_CMD (
  NRCMD NUMBER(20,3),
  PRIORITATE NUMBER(10,0),
  DEN_OBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(200),
  UM VARCHAR2(200),
  CANTPROGRAMAT NUMBER(20,7),
  SECTIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PF_SDV_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2A81BCD38481D70F0D616B2D0AC8518A181BD3EE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PF_SDV_GEST (
  CODPROGRAMFSDV NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  DEN_GEST VARCHAR2(200),
  DEN_UM VARCHAR2(200),
  STOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PGS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD11A82048A821398A1C5AD54711228A5D695237</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PGS (
  CODPGS NUMBER(20,0),
  DENUMIRE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PGS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DAD9C28C2953E17FF4A2EB56B18D8610FF1CB559</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PGS1 (
  CODPGS1 NUMBER(20,0),
  CODPGS NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PKG_GLOBALS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9AF575B433D92014125BD2BC174BDBBC5059BBB1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PKG_GLOBALS (
  USERID NUMBER(18,0),
  FIRMAID NUMBER(18,0),
  ANLUCRU NUMBER(18,0),
  LUNALUCRU NUMBER(18,0),
  ANBLOCAT NUMBER(18,0),
  LUNABLOCATA NUMBER(18,0),
  ANPREC NUMBER(18,0),
  LUNAPREC NUMBER(18,0),
  USERNAME VARCHAR2(100),
  FIRMANAME VARCHAR2(100),
  SUBUNITATE VARCHAR2(100),
  EXEVERSION VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANCURS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>646082D952A78BE23B009110400AE7F566D684B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANCURS (
  CODPLANCURS NUMBER(20,0),
  CODPERS NUMBER(20,0),
  NR NUMBER(20,0),
  DATACURS DATE,
  TIP VARCHAR2(100),
  AN NUMBER(4,0),
  LUNA VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANCURS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7CFAD15128F697B61F582AF90CA87C85ECAE31AE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANCURS1 (
  CODPLANCURS1 NUMBER(20,0),
  CODPLANCURS NUMBER(20,0),
  CODTEMA NUMBER(20,0),
  DATAPLAN DATE,
  STARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFCMDMAT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9485E2A6E503D985D2C8FFE876B3BD5F70B8E010</HASHVAL>
  <TEXT>CREATE TABLE TMP_PLANIFCMDMAT (
  CODOBIECT NUMBER(20,0),
  STOC NUMBER(20,7),
  STOCMIN NUMBER(20,0),
  PRET NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2991779D67EA130D5A97777861F5E85C5DC7BC5B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFLINK (
  CODCOMANDA1 NUMBER(20,0),
  CODSTARE1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>142019F4FB96BB409584668CA10031AF79BC445C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFLINK_INITIAL (
  CODCOMANDA1 NUMBER(20,0),
  CODSTARE1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFNOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>00F6F85A2981D5C9FB4B8B788D1102EA90E45B81</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFNOD (
  CODPLANIFNOD NUMBER(20,0),
  CODPLANIFPROD1 NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  CODPROIECTNOD NUMBER(20,0),
  VERSIUNE NUMBER(1,0),
  CANTPRODRETETA NUMBER(20,7),
  CANTMATRETETA NUMBER(20,7),
  NECESAR NUMBER(20,7),
  DENUMIRE VARCHAR2(150),
  OBS VARCHAR2(250),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  PROIECTANT NUMBER(20,0),
  TOTALCOMINT NUMBER(20,7),
  TOTALCOMFURN NUMBER(20,7),
  TOTALREZERVAT NUMBER(20,7),
  TOTALREZOLVAT NUMBER(20,7),
  TOTALREALIZAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENUM VARCHAR2(15),
  UMSEC NUMBER(20,0),
  NECESARAUT NUMBER(20,7),
  RETETA VARCHAR2(250),
  RETETAPARINTE VARCHAR2(250),
  CODPRODCOMPPARINTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFNODZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A37DE88078D25ABFDE3F0AA301BF00C266295DD0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFNODZ (
  CODPLANIFNOD NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  ORDINE NUMBER(5,0),
  NECESAR NUMBER(20,7),
  NEXTWEEK NUMBER(20,7),
  REFWEEK NUMBER(20,7),
  USERID NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFNODZTL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A2377D5F7E34BD63EFD58C04B5D641D17ABC048</HASHVAL>
  <TEXT>CREATE TABLE TMP_PLANIFNODZTL (
  CODRETETA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NECESAR NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFPROD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DAE13EEBC1525BC18FA3239468875C348B637EB4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFPROD (
  CODPLANIFPROD NUMBER(20,0),
  CODLANSPROD NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  OBS VARCHAR2(250),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  SAPTAMANA NUMBER(10,0),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  PREFIXDOC VARCHAR2(3),
  INSAPTAMANA NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  DEN_SUBUNIT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFPROD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ECC1B014F82CE7F8311425416C94AE6B1EA5DE09</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFPROD1 (
  CODPLANIFPROD1 NUMBER(20,0),
  CODPLANIFPROD NUMBER(20,0),
  CODLANSPROD1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  OBS VARCHAR2(250),
  NECESAR NUMBER(20,7),
  CANT NUMBER(20,7),
  CUPROIECT NUMBER(1,0),
  CODPROIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  DENUM VARCHAR2(15),
  RETETA VARCHAR2(250),
  PROIECT VARCHAR2(250),
  DEN_CLASEAS VARCHAR2(50),
  DEN_IOART VARCHAR2(60),
  CODINTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFSTOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2B8825122E7F20707C20A20D5C759D91E6D7933D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFSTOC (
  CODOBIECT NUMBER(20,0),
  TG VARCHAR2(3200),
  CANT NUMBER(20,7),
  SERIE VARCHAR2(3200),
  CODGEST NUMBER(20,0),
  FILTRU VARCHAR2(50),
  CANTREZ NUMBER(20,7),
  CODSERIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLANIFSTOC_CLONA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D28045394520102EB905D59E8F8925CF1E4FDCD4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLANIFSTOC_CLONA (
  CODOBIECT NUMBER(20,0),
  TG VARCHAR2(3200),
  CANT NUMBER(20,7),
  SERIE VARCHAR2(3200),
  CODGEST NUMBER(20,0),
  FILTRU VARCHAR2(50),
  CANTREZ NUMBER(20,7),
  CODSERIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88BC08C17F558F4CDAACDD1100B2D6CB4440EBDB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATI (
  CODPLATA NUMBER(20,0),
  DATA DATE,
  CODBANKCONT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  VALOAREDEREPARTIZAT NUMBER(20,7),
  APROBAT NUMBER(1,0),
  TIPDOC NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODANALIZA NUMBER(20,0),
  OBS VARCHAR2(500),
  CURS NUMBER(20,7),
  SIMBOLMONEDA VARCHAR2(10),
  CODBANK NUMBER(20,0),
  NRCONT VARCHAR2(30),
  SOLDCONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>68E56933584274B6D0CBEBC0CC994761DD205403</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATI1 (
  CODPLATA1 NUMBER(20,0),
  CODPLATA NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  CONTDEST VARCHAR2(50),
  ADRESAFURN VARCHAR2(200),
  INDEXLOCAL NUMBER(10,0),
  STINSA NUMBER(1,0),
  CODSWIFT VARCHAR2(30),
  CODBNR VARCHAR2(30),
  CODSTATISTICBNR VARCHAR2(30),
  CODBANK NUMBER(20,0),
  TIPCOMISION VARCHAR2(6),
  CODPART NUMBER(20,0),
  SPLITTVA NUMBER(1,0),
  REST NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODANALIZANODX NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  DENPART VARCHAR2(100),
  DOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TERMEN DATE,
  SUBUNITATEA NUMBER(20,0),
  AVANS NUMBER(1,0),
  TVADOC NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  SOLDBUGET NUMBER(20,7),
  CODFISCAL VARCHAR2(75),
  SIMBOLCLASA VARCHAR2(30),
  OBS VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATI1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0B9885A61839CF5FABE392CA1069500FF7752B75</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATI1_INITIAL (
  CODPLATA1 NUMBER(20,0),
  CODPLATA NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  CONTDEST VARCHAR2(50),
  ADRESAFURN VARCHAR2(200),
  INDEXLOCAL NUMBER(10,0),
  STINSA NUMBER(1,0),
  CODSWIFT VARCHAR2(30),
  CODBNR VARCHAR2(30),
  CODSTATISTICBNR VARCHAR2(30),
  CODBANK NUMBER(20,0),
  TIPCOMISION VARCHAR2(6),
  CODPART NUMBER(20,0),
  SPLITTVA NUMBER(1,0),
  REST NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODANALIZANODX NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  DENPART VARCHAR2(100),
  DOC VARCHAR2(10),
  NRDOC NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TERMEN DATE,
  SUBUNITATEA NUMBER(20,0),
  AVANS NUMBER(1,0),
  TVADOC NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  SOLDBUGET NUMBER(20,7),
  CODFISCAL VARCHAR2(75),
  SIMBOLCLASA VARCHAR2(30),
  OBS VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATI2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>02B5FA709F441E080C7D4F9DF95EF18A974B9179</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATI2 (
  CODPLATA2 NUMBER(20,0),
  CODPLATA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CONTDEST VARCHAR2(30),
  CODSWIFT VARCHAR2(30),
  VALOARE NUMBER(20,7),
  NRDOC NUMBER(20,0),
  NUME VARCHAR2(200),
  PRENUME VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATIACCRUALLS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B03BC891E24A0DAE3801E7CD0F3D9E16EA1A5D8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATIACCRUALLS (
  PARTENER NUMBER(20,0),
  PROCENT NUMBER(20,7),
  CODDISCOUNT NUMBER(20,0),
  OFFINVOICE NUMBER(2,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  PLATA NUMBER(20,7),
  ORDINE NUMBER(2,0),
  MAXORD NUMBER(2,0),
  FILTRU VARCHAR2(10),
  CODMONEDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATIPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>26F537CAF4EA969813ADFF279F8BCDC46868FB87</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATIPART (
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  SUMA NUMBER(20,7),
  DOCLEGATURA VARCHAR2(3),
  SUMADETALII NUMBER(20,7),
  AVANS NUMBER(1,0),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  SIMBOLCLASA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLATIPART_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7641540A00B8B2AB9342F3C6A8ADDDEF17F709B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PLATIPART_INITIAL (
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  SUMA NUMBER(20,7),
  DOCLEGATURA VARCHAR2(3),
  SUMADETALII NUMBER(20,7),
  AVANS NUMBER(1,0),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  SIMBOLCLASA VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13B8A48F09CFFC228205678F1463E3690C678176</HASHVAL>
  <TEXT>CREATE TABLE TMP_PLUNA (
  CODCMDPL NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  STOC NUMBER(20,7),
  MEDIEV NUMBER(20,7),
  CANTCC NUMBER(20,7),
  CANTCI NUMBER(20,7),
  WEEK1 NUMBER(20,7),
  WEEK2 NUMBER(20,7),
  WEEK3 NUMBER(20,7),
  WEEK4 NUMBER(20,7),
  WEEK5 NUMBER(20,7),
  PRET NUMBER(20,7),
  USERID NUMBER(20,0),
  RESTCMDINT NUMBER(20,7),
  CODMONEDA NUMBER(20,0),
  PRWEEK1 NUMBER(20,7),
  PRWEEK2 NUMBER(20,7),
  PRWEEK3 NUMBER(20,7),
  PRWEEK4 NUMBER(20,7),
  PRWEEK5 NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>703368F828D3EF112266B230C1D47728EA342670</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PMP (
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  PMP NUMBER(20,7),
  PMPVALUTA NUMBER(20,7),
  PMPPREC NUMBER(20,7),
  PMPPRECVALUTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PMP_ACT_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0D9408D2E18DC6B985A79CE02B7327CE7A62A93A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PMP_ACT_LUNA (
  CODLIVR1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(4,0),
  PMP NUMBER(20,7),
  CODIES NUMBER(20,0),
  TIPDOC NUMBER(2,0),
  PMPVALUTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PMP_CALC_I</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ECF7EA4CC6CC9815DF53900FBD38537D1EFEA289</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PMP_CALC_I (
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CANTINTR NUMBER(20,7),
  VALINTR NUMBER(20,7),
  VALVALUTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PMP_CALC_P</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0FD780DD8BDF52112B998D5FCDB64AD1D5785606</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PMP_CALC_P (
  CODOBIECT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CANTINTR NUMBER(20,7),
  VALINTR NUMBER(20,7),
  VALVALUTA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_POSBANCAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AA0DF26748BB33A71C1EC1EBA84D84FFC91B3783</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_POSBANCAR (
  CODPOSBANCAR NUMBER(5,0) NOT NULL,
  INDEXLOCAL NUMBER(2,0),
  TIPPOS NUMBER(3,0),
  PORTSERIAL NUMBER(2,0),
  IP VARCHAR2(50),
  INACTIV NUMBER(1,0),
  USERID NUMBER(20,0),
  REMOTE NUMBER(1,0),
  IPSERVERPOS VARCHAR2(50),
  PORTSERVERPOS NUMBER(10,0),
  DENUMIRE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_POSTRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F2BDBD4886AE26BC5763CF4BA1B86831A24E1A5D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_POSTRETAIL (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  ID NUMBER(3,0),
  NUMEFIRMA VARCHAR2(30),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRECMDLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>865179F2FFFBB9ED9F9D735819AB11A839CCBDA8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRECMDLINK (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODPRECOMANDA1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRECMDLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>272636E943A8DFC2FA58E891BE335189785D9AAF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRECMDLINK_INITIAL (
  CODCOMANDA1 NUMBER(20,0) NOT NULL,
  CODPRECOMANDA1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRECOMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DD032BE03555638609F1F5FB8A80116D3C8479AF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRECOMANDA (
  CODPRECOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  DATADOC DATE,
  VALOARE NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  OBS VARCHAR2(200),
  MONEDA NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  INCHISA NUMBER(1,0),
  SERIADOC VARCHAR2(20),
  VERIFICAT NUMBER(1,0),
  CODSTARE1 NUMBER(20,0),
  SAPTAMANAC NUMBER(2,0),
  ANC NUMBER(4,0),
  SAPTAMANAG NUMBER(10,0),
  ANG NUMBER(4,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRECOMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3162A14973C0B4EC9C4AA7F9DA2830CB3157C91A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRECOMANDA1 (
  CODPRECOMANDA1 NUMBER(20,0),
  CODPRECOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(10,0),
  PU NUMBER(21,7),
  CANT NUMBER(20,7),
  REST NUMBER(20,7),
  TERMEN DATE,
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  OBS VARCHAR2(200),
  PRETORIG NUMBER(20,7),
  COEFDISCMAJ NUMBER(20,7),
  SCADENTA NUMBER(5,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CODCONTRACT1 NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODOFERTA1 NUMBER(20,0),
  PRETUM1 NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  MONEDA NUMBER(20,0),
  CODSTARE1 NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CANTMIN NUMBER(20,7),
  DATASTART DATE,
  VALOARE NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(50),
  DENUM1 VARCHAR2(50),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  UM1 NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  PARITATE NUMBER(20,7),
  ROTUNJIRE NUMBER(2,0),
  OFERTA VARCHAR2(50),
  PROMO VARCHAR2(50),
  CONTRACT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PREDARI_LANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B35474307C394B718CB34536BB0B3367654351F</HASHVAL>
  <TEXT>CREATE TABLE TMP_PREDARI_LANSPROD (
  CANT NUMBER(20,7),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRELAUTOMAT_CODGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CB59D9D2947E14272303120CCBD7AD76083E21B5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRELAUTOMAT_CODGEST (
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRELAUTOMAT_CODIOART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>39AC4FB50B64489E2453336BAB09DB01EF531B86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRELAUTOMAT_CODIOART (
  CODIOART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRESTATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2FFC28D933B2D4CA1D83D17F6B932FA9FA3B1723</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRESTATII (
  CODPRESTATIE NUMBER(20,0),
  COD VARCHAR2(50),
  DENUMIRE VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRETACH</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77310AAAFAED4178EBB57AA9EAD869EE15106F54</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRETACH (
  CODOBIECT NUMBER(20,0),
  PRETACH NUMBER(20,7),
  DATAPRET DATE,
  DEN_PART VARCHAR2(100),
  SURSA VARCHAR2(20),
  CANT NUMBER(20,7),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRETM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA8BD08E2141E82F66E59575939F7544573E7812</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRETM (
  CODPRETM NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  LEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  MONEDA NUMBER(20,0),
  IMPLICIT NUMBER(1,0),
  PROC NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  SUBUNITATEA NUMBER(20,0),
  GRUPA VARCHAR2(10),
  ROTUNJIRE NUMBER(2,0),
  SUMAFIXAIMPLICIT NUMBER(20,7),
  DENCATPRET VARCHAR2(30),
  DENTIPCATPRET VARCHAR2(50),
  TIPCATPRET NUMBER(2,0),
  DETALIERE VARCHAR2(1),
  CODCATMASTER NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRETMAMB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B5870A89132C2933652B34BD964AFEDFF6906786</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRETMAMB (
  CODPRETMAMB NUMBER(20,0),
  CODPRETM NUMBER(20,0),
  CODAMB NUMBER(20,0),
  LEI NUMBER(20,7),
  VALUTA NUMBER(20,7),
  DENUMSEC VARCHAR2(15),
  PARITATE NUMBER(20,7),
  LEIUMP NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODCATPRET NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  UMSEC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROCESARE_DLWMS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D8D3DCE51FFD821A2E094A4481A5CE4933DF377B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROCESARE_DLWMS (
  COD NUMBER(20,0),
  CODREZERVATS NUMBER(20,0),
  CANT NUMBER(20,7),
  OLDCODNIRSTOC NUMBER(20,0),
  OLDCODNIRSER NUMBER(20,0),
  OLDCODLOCATIE NUMBER(20,0),
  NEWCODLOCATIE NUMBER(20,0),
  NEWCODNIRSTOC NUMBER(20,0),
  NEWCODNIRSER NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROC_ACT_DATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C9FEE3AA922DEBB7ECD881A049BB1EA3FDF7989</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROC_ACT_DATE (
  CODPROCACT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  OBS VARCHAR2(200),
  CODORAR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROC_ACT_DEF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>429C8DF5404A8D28ADFB1BA1D92668823ED4D549</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROC_ACT_DEF (
  CODPROCACTDEF NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODINTERN VARCHAR2(200),
  SQL CLOB
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODCOMP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D482454ED812ED02B07D575908912CB1469A3BB3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODCOMP (
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(250),
  DATA DATE,
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  CANT NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPRETETA NUMBER(1,0),
  CANTUM1 NUMBER(20,7),
  PRET NUMBER(20,7),
  COEFINDIRECTE NUMBER(20,7),
  IMPLICIT NUMBER(1,0),
  DESCRIERE CLOB,
  INACTIV NUMBER(1,0),
  GEST NUMBER(20,0),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  OBSERVATII VARCHAR2(3000),
  PROIECTANT NUMBER(20,0),
  CODCLASAPROD NUMBER(20,0),
  INVIZIBILA NUMBER(1,0),
  GENERIC NUMBER(1,0),
  DURATA NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  HFACTOR NUMBER(2,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  TIPPRET NUMBER(1,0),
  CODPROIECT NUMBER(20,0),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  CODMONEDA NUMBER(20,0),
  PRETVALUTA NUMBER(20,7),
  AG NUMBER(20,7),
  VALAG NUMBER(20,7),
  PROFIT NUMBER(20,7),
  VALPROFIT NUMBER(20,7),
  PRETFINAL NUMBER(20,7),
  VALPROFITV NUMBER(20,7),
  PRETFINALV NUMBER(20,7),
  TOTPRETCOEF NUMBER(20,7),
  TOTPRETFIX NUMBER(20,7),
  TOTPRETCOEFV NUMBER(20,7),
  TOTPRETFIXV NUMBER(20,7),
  VALREGIEMAN NUMBER(20,7),
  ASCUNS NUMBER(1,0),
  CODUTILIZARE NUMBER(20,0),
  NOHFACTOR NUMBER(1,0),
  DEN_OBIECT VARCHAR2(250),
  DEN_UM VARCHAR2(100),
  DEN_UMSPEC VARCHAR2(100),
  RELATIEUM1 NUMBER(2,0),
  UM1 NUMBER(20,0),
  UM NUMBER(20,0),
  TOTALMAT NUMBER(20,7),
  TOTALMAN NUMBER(20,7),
  TOTALREZ NUMBER(20,7),
  TOTALPROD NUMBER(20,7),
  GENERICOLD NUMBER(1,0),
  INACTIVOLD NUMBER(1,0),
  VALTOTAL NUMBER(20,7),
  IMPLICITOLD NUMBER(20,0),
  NRCMD NUMBER(10,0),
  DURATAAFIS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODCOMP_MAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02BE6CF1D5B5FE11FFD385F9F6AA2E0A0B565D3C</HASHVAL>
  <TEXT>CREATE TABLE TMP_PRODCOMP_MAN (
  CODPRODCOMP NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  USERID NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E69DD30F2CA35A035223FCAFBE43B1C40453FACB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODGEST (
  CODPRODGEST NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODGEST NUMBER(20,0),
  COEFMAT NUMBER(20,7),
  COEFMAN NUMBER(20,7),
  TIMPEST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>157718AE92A4DCA142CE8B6EB89A21450D598900</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODMAN (
  CODMAN NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  NROP NUMBER(10,0),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DSV NUMBER(20,7),
  BPS NUMBER(20,7),
  TPI NUMBER(20,7),
  OBS VARCHAR2(1000),
  DETALII NUMBER(10,0),
  FIX NUMBER(1,0),
  NIVEL NUMBER(5,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  COEFBPS NUMBER(1,0),
  DEN_OPERATIE VARCHAR2(250),
  DEN_LOCMUNCA VARCHAR2(250),
  DIFICULTATE VARCHAR2(250),
  TARIF NUMBER(20,7),
  TUH NUMBER(20,7),
  TPIH NUMBER(20,7),
  CODEXTERN VARCHAR2(15),
  BARA VARCHAR2(100),
  VALOARELEI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODMAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D40E44CD473836FEF3F6F34B5A87DCE45EE1766A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODMAS (
  CODPRODMAS NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODPRODGEST NUMBER(20,0),
  DESCRIERE VARCHAR2(200),
  FRECVENTA VARCHAR2(20),
  METODA VARCHAR2(150),
  CODOBIECT NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODMAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BFD549802E37DCCF8A9BDBCB5BF50F4061CC56AF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODMAT (
  CODMAT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CANTUM1 NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  TIP NUMBER(1,0),
  CODATRIBUT NUMBER(20,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  OBS VARCHAR2(300),
  ADDDIM NUMBER(20,7),
  ADDDIM_TRANSP NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PROCREAL NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  CODMAN NUMBER(20,0),
  COPYD1 NUMBER(12,7),
  COPYD2 NUMBER(12,7),
  COPYD3 NUMBER(12,7),
  ETAPA NUMBER(10,0),
  PRETV NUMBER(20,7),
  PRINCIPAL NUMBER(1,0),
  CONSUM NUMBER(20,7),
  DEN_OBIECT VARCHAR2(250),
  CODARTICOL NUMBER(20,0),
  CODUM NUMBER(20,0),
  CODUMSPEC NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  PARITATE NUMBER(20,7),
  DENUM VARCHAR2(15),
  CODINTERN VARCHAR2(80),
  PRODUCATOR VARCHAR2(100),
  CANTT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  RETETA VARCHAR2(250),
  NROP NUMBER(10,0),
  OPER VARCHAR2(60)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODMATECHIV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>209EABCC1A71477D85282AC95573071E3AB7B380</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODMATECHIV (
  CODMATECHIV NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODMAT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PARITATE NUMBER(20,7),
  ORDINE NUMBER(10,0),
  DENUMIRE VARCHAR2(200),
  UM NUMBER(20,0),
  DEN_UM VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODMAT_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A68D715C1A5AA7CBF9AF5288E1E09E5118A82C79</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODMAT_INITIAL (
  CODMAT NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  CANTUM1 NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  TIP NUMBER(1,0),
  CODATRIBUT NUMBER(20,0),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  VALREGIE NUMBER(20,7),
  OBS VARCHAR2(300),
  ADDDIM NUMBER(20,7),
  ADDDIM_TRANSP NUMBER(20,7),
  PRETORIG NUMBER(20,7),
  PROCREAL NUMBER(20,7),
  VALOARE NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  CODMAN NUMBER(20,0),
  COPYD1 NUMBER(12,7),
  COPYD2 NUMBER(12,7),
  COPYD3 NUMBER(12,7),
  ETAPA NUMBER(10,0),
  PRETV NUMBER(20,7),
  PRINCIPAL NUMBER(1,0),
  CONSUM NUMBER(20,7),
  DEN_OBIECT VARCHAR2(250),
  CODARTICOL NUMBER(20,0),
  CODUM NUMBER(20,0),
  CODUMSPEC NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  PARITATE NUMBER(20,7),
  DENUM VARCHAR2(15),
  CODINTERN VARCHAR2(80),
  PRODUCATOR VARCHAR2(100),
  CANTT NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  RETETA VARCHAR2(250),
  NROP NUMBER(10,0),
  OPER VARCHAR2(60)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODNET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1EC77DCDF96AC39FEAAD739E571237BC60495148</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODNET (
  CODPRODNET NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(150),
  TIP NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODNET1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FE24283984B52C25E07A5C7FBA8C46EB08708B7B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODNET1 (
  CODPRODNET1 NUMBER(20,0),
  CODPRODNET NUMBER(20,0),
  TIP NUMBER(1,0),
  CODDOC1 NUMBER(20,0),
  EXPLICATII VARCHAR2(150),
  VALMAT NUMBER(20,7),
  VALMAN NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  DIFCANT NUMBER(20,7),
  CANTREAL NUMBER(20,7),
  PRET NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  DIRTY NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CANT NUMBER(20,7),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DENUMIRE VARCHAR2(200),
  MATERIAL VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODNORME</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1733BCBBFD3F86B8EAEB64EC9DA86BF7D562B13F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODNORME (
  CODNORMA NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  NORMA VARCHAR2(250),
  INDEXLOCAL NUMBER(10,0),
  IMPLICIT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  DATAACTIV DATE,
  DATAINACTIV DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0A32FB5B659B8D5BCA8D910F78CDBDF4B6402480</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODREZ (
  CODREZ NUMBER(20,0),
  CODPRODCOMP NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  REZIDUU NUMBER(1,0),
  CANTUM1 NUMBER(20,7),
  CODPRODGEST NUMBER(20,0),
  OBS VARCHAR2(300),
  DEN_OBIECT VARCHAR2(250),
  CODARTICOL NUMBER(20,0),
  CODUM NUMBER(20,0),
  CODUMSPEC NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  PARITATE NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  DENUM VARCHAR2(15),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PRODSDV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2105C52626A06791B40862A775C7E264FE441443</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PRODSDV (
  CODPRODSDV NUMBER(20,0),
  CODPRODMAN NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODSDV NUMBER(20,0),
  CODGENERIC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CODPRODCOMP NUMBER(20,0),
  DENUMIRE VARCHAR2(250),
  CODUM NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  PARITATE NUMBER(20,7),
  DENUM VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROFIT_NCLASEA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F432603A82A52695C79246D4FBAB6A08F2D605B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROFIT_NCLASEA (
  CODCLASEA NUMBER(20,0),
  DEN_CLASEA VARCHAR2(150),
  NIVEL NUMBER(3,0),
  SIMBOL VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E0CAF8DEAA02367A2049DF1F826BDDD58EC3EA4D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMF (
  CODPROGRAMF NUMBER(20,0),
  DATAINREG DATE,
  VDELA DATE,
  VPANALA DATE,
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  TIP NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  TIPDURATA NUMBER(1,0),
  NRDOC NUMBER(10,0),
  OBS VARCHAR2(200),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  ALLGEST NUMBER(1,0),
  ALLTIPCONT NUMBER(1,0),
  VDELAORA VARCHAR2(30),
  VPANALAORA VARCHAR2(30),
  ZILEN NUMBER(10,0),
  DURATA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMF1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9E262E76F2A7B67CCEF0C22130C5B16E44956730</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMF1 (
  CODPROGRAMF1 NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODGEST NUMBER(20,0),
  PRIORITATE NUMBER(20,0),
  TERMEN DATE,
  CANTPROGRAMAT NUMBER(20,7),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(1,0),
  DEN_GEST VARCHAR2(100),
  NRCMD NUMBER(20,3),
  DEN_OBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  UM VARCHAR2(15),
  TERMENEXEC DATE,
  DEN_CLIENT VARCHAR2(100),
  TERMENLIVR DATE,
  CODOBIECT NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  DURATA NUMBER(20,7),
  DURATAM NUMBER(20,7),
  DEN_FORMATIE VARCHAR2(100),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  LANSAT NUMBER(20,7),
  CODPERS NUMBER(20,0),
  CANTRETETA NUMBER(20,7),
  DURATARETETA NUMBER(20,7),
  TERMENCMDINT DATE,
  CODCMDPRODMAN NUMBER(20,0),
  SAPTAMANA NUMBER(2,0),
  NRCMDCLI NUMBER(20,3),
  OBSCMDINT VARCHAR2(200),
  OBSCMDCLI VARCHAR2(200),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMF1_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D0F5D1CFE54E9EA29527329C131910821DB7E1F6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMF1_MANEVRA (
  CODPROGRAMF1 NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODGEST NUMBER(20,0),
  PRIORITATE NUMBER(20,0),
  TERMEN DATE,
  CANTPROGRAMAT NUMBER(20,7),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(1,0),
  DEN_GEST VARCHAR2(100),
  NRCMD NUMBER(20,3),
  DEN_OBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(40),
  UM VARCHAR2(15),
  TERMENEXEC DATE,
  DEN_CLIENT VARCHAR2(100),
  TERMENLIVR DATE,
  CODOBIECT NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  DURATA NUMBER(20,7),
  DURATAM NUMBER(20,7),
  DEN_FORMATIE VARCHAR2(100),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  LANSAT NUMBER(20,7),
  CODPERS NUMBER(20,0),
  CANTRETETA NUMBER(20,7),
  DURATARETETA NUMBER(20,7),
  TERMENCMDINT DATE,
  CODCMDPRODMAN NUMBER(20,0),
  SAPTAMANA NUMBER(2,0),
  NRCMDCLI NUMBER(20,3),
  OBSCMDINT VARCHAR2(200),
  OBSCMDCLI VARCHAR2(200),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMFCONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B68F1215C9E0731117D00E44EBA357BD9E611F5A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMFCONT (
  CODPROGRAMF NUMBER(20,0),
  CODIOART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMFGEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7E3C071B910C5F9422EEAE6E25B35588D446D71C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMFGEST (
  CODPROGRAMF NUMBER(20,0),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMFMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>195AB4745B2C5BA5284D6CD2B7AC15A0882495E7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMFMAN (
  CODPFMAN NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMFMAN_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A8A52C64DACBFAA29FCD45008A9A7B346C832493</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMFMAN_MANEVRA (
  CODPFMAN NUMBER(20,0),
  CODPROGRAMF NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROGRAMF_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD3B4353D655BA0062BF002FC90A0411BDBB7688</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROGRAMF_MANEVRA (
  CODPROGRAMF NUMBER(20,0),
  DATAINREG DATE,
  VDELA DATE,
  VPANALA DATE,
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  TIP NUMBER(1,0),
  CODFORMATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  TIPDURATA NUMBER(1,0),
  VDELAORA VARCHAR2(30),
  VPANALAORA VARCHAR2(30),
  ZILEN NUMBER(10,0),
  ALLGEST NUMBER(1,0),
  ALLTIPCONT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>66C9CB5A2200863A0B27EB2DF0574042A79515E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECT (
  CODPROIECT NUMBER(20,0),
  CODVERSIUNE NUMBER(10,0),
  CODOBIECTPROD NUMBER(20,0),
  VERSIUNE VARCHAR2(100),
  INTOCMITA NUMBER(20,0),
  DATAPROIECT DATE,
  CLASA NUMBER(20,0),
  PROCESARE NUMBER(1,0),
  COMPLEX NUMBER(1,0),
  ACTIV NUMBER(1,0),
  FINALIZAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  INVIZIBILA NUMBER(1,0),
  GENERIC NUMBER(1,0),
  IMPLICIT NUMBER(1,0),
  DURATA NUMBER(20,7),
  MARJAORDINE NUMBER(20,7),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250),
  CODEXTERN VARCHAR2(80),
  ASCUNS NUMBER(1,0),
  CODUTILIZARE NUMBER(20,0),
  CODIDENTIFICARE NUMBER(20,0),
  DEN_PROCESARE VARCHAR2(50),
  DEN_PERS VARCHAR2(400),
  MASA NUMBER(20,7),
  DEN_OBIECT VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTCRM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>53D88FD6DEC75D7CA17EB41257D92EE23577627F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTCRM (
  CODPROIECTCRM NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  DESCRIERE VARCHAR2(500),
  VALOARE NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62FEB74338F8DF86FAED84C8944A368F0A084D6A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTE (
  CODPROIECT NUMBER(20,0),
  VERSIUNE VARCHAR2(100),
  DURATA NUMBER(20,7),
  DATAPROIECT DATE,
  INACTIV NUMBER(1,0),
  FINALIZAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  GENERIC NUMBER(1,0),
  IMPLICIT NUMBER(1,0),
  OBS1 VARCHAR2(250),
  OBS2 VARCHAR2(250),
  OBS3 VARCHAR2(250),
  OBS4 VARCHAR2(250),
  OBS5 VARCHAR2(250),
  OBS6 VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTGRID</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DA7CBFFB947CBBED6CE948C7C0FA28827C7E4FDE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTGRID (
  ORDINE NUMBER(10,0),
  INCEPERE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5C697DBFE5DFE5C7A840758EC28E17397609151</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTMAN (
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  DEN_OBIECT VARCHAR2(200),
  TIP NUMBER(1,0),
  SIMBOL VARCHAR2(100),
  DURATA NUMBER(20,7),
  CANT NUMBER(20,7),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(10,0),
  DURATANOD NUMBER(20,7),
  COPILMAXIM NUMBER(20,7),
  NODCRITIC VARCHAR2(100),
  BARA VARCHAR2(100),
  DECALAJ NUMBER(20,7),
  INCEPERE NUMBER(20,7),
  LOTOPTIM NUMBER(20,7),
  INDEXPARINTE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTNOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C3AF7143C3C81715CE4C7D8EDB3D78AB3349C035</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTNOD (
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  DENUMIRE VARCHAR2(150),
  OBS VARCHAR2(250),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  PROIECTANT NUMBER(20,0),
  NECESAR NUMBER(20,7),
  TOTALCOMINT NUMBER(20,7),
  TOTALCOMFURN NUMBER(20,7),
  TOTALREZERVAT NUMBER(20,7),
  TOTALREZOLVAT NUMBER(20,7),
  TOTALREALIZAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENUM VARCHAR2(15),
  UMSEC NUMBER(20,0),
  NECESARAUT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTNOD_LANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>16383C1B2C512B03E61D8E4C047BC76CFE12AAB8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROIECTNOD_LANS (
  CODLANSARE0 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NODORIGINAL NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODRETETA NUMBER(20,0),
  TIP NUMBER(1,0),
  CODOBIECT NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  CODPRODMAT NUMBER(20,0),
  NIVEL NUMBER(10,0),
  ORDINE NUMBER(5,0),
  DECALAJ NUMBER(10,0),
  INCEPERE NUMBER(20,7),
  DENUMIRE VARCHAR2(150),
  OBS VARCHAR2(250),
  IDENTIFICATOR VARCHAR2(100),
  DATADOCUMENTATIE DATE,
  ARHIVA VARCHAR2(50),
  PROIECTANT NUMBER(20,0),
  NECESAR NUMBER(20,7),
  TOTALCOMINT NUMBER(20,7),
  TOTALCOMFURN NUMBER(20,7),
  TOTALREZERVAT NUMBER(20,7),
  TOTALREZOLVAT NUMBER(20,7),
  TOTALREALIZAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  DENUM VARCHAR2(15),
  UMSEC NUMBER(20,0),
  NECESARAUT NUMBER(20,7),
  TIPECHIV NUMBER(10,0),
  PARITATE NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  NECESARUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  PARITATED1 NUMBER(12,7),
  PARITATED2 NUMBER(12,7),
  PARITATED3 NUMBER(12,7),
  CANTUM1 NUMBER(20,7),
  UM1 NUMBER(20,0),
  STOC NUMBER(20,7),
  RESTCMDF NUMBER(20,7),
  RESTCMDI NUMBER(20,7),
  RESTCMDC NUMBER(20,7),
  LANSAT NUMBER(20,7),
  STOCMIN NUMBER(20,7),
  COPII NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROIECTNOD_MAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3CDD7744CB240CD65513AEEF0FCFCEC10F2B68D</HASHVAL>
  <TEXT>CREATE TABLE TMP_PROIECTNOD_MAN (
  CODPROIECTNOD NUMBER(20,0),
  CODPROIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  NECESAR NUMBER(20,7),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F5934056EC8F3702CD3041B15BBC14E87B847C4D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMO (
  CODPROMO NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DATASTART DATE,
  DATAEND DATE,
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  MONEDA NUMBER(20,0),
  TIPPROMOTIE NUMBER(1,0),
  TIPCONDITIE NUMBER(1,0),
  OBS VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIPCLASEP NUMBER(1,0),
  TIPSERVIRE NUMBER(1,0),
  DEMANA NUMBER(1,0),
  VALMIN NUMBER(20,7),
  PRAGURI NUMBER(1,0),
  CANTMIN NUMBER(20,7),
  ORASTART VARCHAR2(5),
  ORASTOP VARCHAR2(5),
  EXCLALTEPROMO NUMBER(1,0),
  PRETCUAMANUNT NUMBER(1,0),
  CONF_ACTIVE NUMBER(1,0),
  STOCLIMITAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMO1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6AA7B8335BA18C9696F85C2998BAD5237E8D9FB3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMO1 (
  CODPROMO1 NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  ZILEC NUMBER(5,0),
  TIPLIMITA NUMBER(1,0),
  TG_MAX DATE,
  ZILE_EXP NUMBER(5,0),
  GRUPAPRET VARCHAR2(5),
  VALMIN NUMBER(20,7),
  PRETAMANUNT NUMBER(20,7),
  CANTOPTIM NUMBER(20,7),
  CODARTICOL NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  MODAPLIC NUMBER(1,0),
  VALDISC NUMBER(20,7),
  CUECHIVALENTE NUMBER(1,0),
  CANT_MAX NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  AUXLIMITA VARCHAR2(100),
  OBJCUATRIB NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  CODEXTERNART VARCHAR2(30),
  PEARTICOL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMO1CADOU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>267B653F9E7D460CF47E2C73F86FB1CE139C5277</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMO1CADOU (
  CODCADOU NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  TIPLIMITA NUMBER(1,0),
  TG_MAX DATE,
  ZILE_EXP NUMBER(5,0),
  CODPROMO NUMBER(20,0),
  VALMIN NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  AUXLIMITA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMO1CADOUSER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F6DF7B990C9E1EE5F89700401D372E92DBBFAC5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMO1CADOUSER (
  CODCADOUS NUMBER(20,0),
  CODCADOU NUMBER(20,0),
  SERIE VARCHAR2(30),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMO1SER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>09BD26C18857A079D0731FFD2C0F4C306276AC14</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMO1SER (
  CODPROMO1S NUMBER(20,0),
  CODPROMO1 NUMBER(20,0),
  SERIE VARCHAR2(30),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMOPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>111A06A2EBABAF929D82BA47440EFAEE91D8DCA6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMOPART (
  CODPROMOPART NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  CODCLASEP NUMBER(20,0),
  PARTENER NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODFISCAL NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  PRIORITAR NUMBER(1,0),
  INDEXLOCAL NUMBER(5,0),
  DENUMIRE VARCHAR2(100),
  DEN_SEDIU VARCHAR2(100),
  DEN_CODFISCAL VARCHAR2(100),
  DEN_PERSC VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMOPRAG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EBBA9C2D786AF377E1AECB39A6AB20238F04F7C5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMOPRAG (
  CODPRAG NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  VALMIN NUMBER(20,7),
  PROCDISC NUMBER(20,2),
  CANTMIN NUMBER(20,7),
  VALDISC NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PROMOSUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>34BE888052D6D73FE0F5828AD37A8AB93A67ACE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PROMOSUB (
  CODPROMOSUB NUMBER(20,0),
  CODPROMO NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  DENUMIRE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PUNCTAJE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>49AA478AFAC8B23F837640FA3ED43D3AC73438BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PUNCTAJE (
  CODPUNCTAJ NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DATASTART DATE,
  DATAEND DATE,
  TIP NUMBER(5,0),
  CASADEMARCAT NUMBER(1,0),
  FACTURARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PUNCTAJVALDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>384E71087257921B588F9EF6DC6067FB016E007C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PUNCTAJVALDOC (
  COD NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  LIMITAVAL NUMBER(20,7),
  PUNCTE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_PUNCTEUSE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>013973F5181A415A5010FAD943656C7C04509FC6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_PUNCTEUSE (
  COD NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  PUNCTE NUMBER(20,0),
  VALACORDATA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RACDETALIEREINFO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D47E57614A3E273D4FCB60B7DC4D6FEDD02794E8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RACDETALIEREINFO (
  COD NUMBER(20,0) NOT NULL,
  SUBUNITATE VARCHAR2(100),
  GESTIUNE VARCHAR2(100),
  LOCATIE VARCHAR2(100),
  CLASA VARCHAR2(50),
  NRAUTO VARCHAR2(30),
  MARCA VARCHAR2(20),
  MODEL VARCHAR2(40),
  ANFAB VARCHAR2(10),
  KMBORD VARCHAR2(20),
  COMB VARCHAR2(100),
  DATABORD VARCHAR2(100),
  STATUS VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RACDETALIEREINFOG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3BD3CEE6F476E7BF258AFAA21FD5F02C62D4A1AB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RACDETALIEREINFOG (
  COD NUMBER(20,0) NOT NULL,
  SUBUNITATE VARCHAR2(100),
  GESTIUNE VARCHAR2(100),
  LOCATIE VARCHAR2(100),
  CLASA VARCHAR2(50),
  NRAUTO VARCHAR2(30),
  MARCA VARCHAR2(20),
  MODEL VARCHAR2(40),
  DATASOSIRE VARCHAR2(40),
  STATUS VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_AUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>168E07A1B35B6E531B5B8BD35D29BAF0DB1ADB6B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_AUTO (
  CODAUTO NUMBER,
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER,
  TRANSFERAT NUMBER,
  Q NUMBER,
  DATASTART DATE,
  DATASTOP DATE,
  CODCLASA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_AUTO_CEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6482403A7184DE16A84DAC4DB5E66F7062B31C5F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_AUTO_CEN (
  CODAUTO NUMBER,
  CODGEST NUMBER,
  Q NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_CARS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5B1CEF61DD616EBA6B645A916C833B6D879C7CBB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_CARS (
  CODAUTO NUMBER(20,0) NOT NULL,
  DATA DATE,
  CODGEST NUMBER,
  GESTIUNE VARCHAR2(100),
  SUBUNITATE NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  INACTIV NUMBER,
  EXTERN NUMBER,
  CODOBIECT NUMBER(20,0),
  NRAUTO VARCHAR2(20),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  ANF NUMBER(4,0),
  CODGRECHIV NUMBER,
  IND NUMBER,
  CLASA VARCHAR2(250),
  GENERIC NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_CATP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51D164ACF8931B5014D0D46838ACD87EFE9769AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_CATP (
  CODRAC_CATP NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(50),
  CODCONTRACT NUMBER(20,0),
  ABONAMENT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_CATP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C9876988B656BD85556C69AF0908FBCC64F42D76</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_CATP1 (
  CODRAC_CATP1 NUMBER(20,0),
  CODRAC_CATP NUMBER(20,0),
  CODRAC_P NUMBER(20,0),
  OBS VARCHAR2(100),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_CATP2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>71CE97296C195DC865E4D442F8229A9DD5CE45B9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_CATP2 (
  CODRAC_CATP2 NUMBER(20,0),
  CODRAC_CATP NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_CATPX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C792A24136EFC849A59CF646A893550C75B5EAB0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_CATPX (
  CODRAC_CATP NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  CODSEDIU NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODSUBUNITATE NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  OBS VARCHAR2(50),
  CODCONTRACT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_EMU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>187B5EA371F061C255D9F8B1F9BD09492086D50A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_EMU (
  CODCOMANDA NUMBER(20,0),
  CANT NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_P</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D35EA71D2C9F32AD439D69B0E197CF83584E7157</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_P (
  CODRAC_P NUMBER(20,0),
  OBS VARCHAR2(100),
  TIP NUMBER(1,0),
  MONEDA NUMBER(20,0),
  I1 NUMBER(6,0),
  I2 NUMBER(6,0),
  I3 NUMBER(6,0),
  I4 NUMBER(6,0),
  I5 NUMBER(6,0),
  I6 NUMBER(6,0),
  VALFIXA NUMBER(20,7),
  LINIAR NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_P0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87D0E2C826B9255DE6A9FF2654EF9C622FDEED0B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_P0 (
  CODRAC_P0 NUMBER(20,0),
  CODRAC_P NUMBER(20,0),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_P1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>46097B65911378D9EB03C7D6C5467481FC8537CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_P1 (
  CODRAC_P1 NUMBER(20,0),
  CODRAC_P0 NUMBER(20,0),
  CODGRUPA NUMBER(20,0),
  P1 NUMBER(20,7),
  P2 NUMBER(20,7),
  P3 NUMBER(20,7),
  P4 NUMBER(20,7),
  P5 NUMBER(20,7),
  P6 NUMBER(20,7),
  FIX NUMBER(20,7),
  GARANTIE NUMBER(20,7),
  DEN_GRUPA VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_REZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>566D94FE472761EA6B66D07DF0F66339F6550D53</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_REZ (
  CODRAC_REZ NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  NR_REF VARCHAR2(100),
  CODCOMISIONAR NUMBER(20,0),
  CODLOCALIT_PREL NUMBER(20,0),
  ADRESA_PREL VARCHAR2(150),
  CODLOCALIT_LIVR NUMBER(20,0),
  ADRESA_LIVR VARCHAR2(150),
  NR_ZBOR VARCHAR2(20),
  CODCONTR_PRELIVR NUMBER(20,0),
  FACTLUNARA NUMBER(1,0),
  SUMAGARANTIE NUMBER(20,7),
  CODCMDACCIDENT NUMBER(20,0),
  NUME_CARD VARCHAR2(100),
  EXPIRA_CARD DATE,
  CODCCV NUMBER(20,0),
  OBS_CONTRACT VARCHAR2(100),
  CODTIPASIG NUMBER(20,0),
  EMAIL VARCHAR2(100),
  TELEFON VARCHAR2(100),
  TIPREZERVARE NUMBER(1,0),
  DATASTART DATE,
  DATASTOP DATE,
  CODDELEGAT1 NUMBER(20,0),
  CODDELEGAT2 NUMBER(20,0),
  CODGESTSURSA NUMBER(20,0),
  CODGESTDEST NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  KMIN NUMBER(10,0),
  KMOUT NUMBER(10,0),
  COMBIN NUMBER(10,0),
  COMBOUT NUMBER(10,0),
  KMNEXTREV NUMBER(10,0),
  CODSEDIUCOMIS NUMBER(20,0),
  CODREZERVARE NUMBER(20,0),
  CODMODEL NUMBER(20,0),
  CODMARCA NUMBER(20,0),
  DATAFACT DATE,
  CODPARTEXT NUMBER(20,0),
  PROCCEDAT NUMBER(5,2),
  DATAPRED DATE,
  CODVOUCHER NUMBER(20,0),
  PREDAT NUMBER(1,0),
  CODSOFER NUMBER(20,0),
  VALSOFERCM NUMBER(20,7),
  VALSOFERF NUMBER(20,7),
  VALCLIENTCM NUMBER(20,7),
  VALCLIENTF NUMBER(20,7),
  CODSOFER1 NUMBER(20,0),
  CODSOFER2 NUMBER(20,0),
  FARATVA NUMBER(1,0),
  SURSACLIENT VARCHAR2(20),
  DIFERENTE NUMBER(20,7),
  VALV NUMBER(20,7),
  RESTV NUMBER(20,7),
  NUMEDELEGAT1 VARCHAR2(100),
  NUMEDELEGAT2 VARCHAR2(100),
  RESTCLIENT NUMBER(20,7),
  RESTSOFER NUMBER(20,7),
  ZILE NUMBER(5,0),
  ORE NUMBER(2,0),
  PARITATE NUMBER(23,10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_REZP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5D81D4B5C15C0A5D6C5465868A14CBE0E951854</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_REZP (
  CODRAC_REZP NUMBER(20,0),
  CODRAC_REZ NUMBER(20,0),
  TIP NUMBER(1,0),
  NR_CARD NUMBER(20,0),
  NUME_CARD VARCHAR2(100),
  EXPIRA_CARD DATE,
  CODCCV NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAC_REZS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D73E11BBAB45809D9AF98058C1957750C5AFF881</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAC_REZS (
  CODRAC_REZS NUMBER(20,0),
  CODRAC_REZ NUMBER(20,0),
  CODSUPLIM NUMBER(20,0),
  ZILE NUMBER(5,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTARE_CONSUM</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DBA519C74AAE324009F568CA1BAD63F948B94159</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTARE_CONSUM (
  CODIES1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  UMSEC NUMBER(20,0),
  TOTAL NUMBER(20,7),
  TOTAL_P NUMBER(20,7),
  PROGRAMAT NUMBER(20,7),
  PROGRAMAT_P NUMBER(20,7),
  UNITAR NUMBER(20,7),
  UNITAR_P NUMBER(20,7),
  REALIZAT NUMBER(20,7),
  REALIZAT_P NUMBER(20,7),
  CONSUMAT NUMBER(20,7),
  CONSUMAT_P NUMBER(20,7),
  UM1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RAPORTAT NUMBER(20,7),
  RAPORTAT_P NUMBER(20,7),
  RAPORTATUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  UM NUMBER(20,0),
  PARITATE NUMBER(20,7),
  TIPSERIE NUMBER(1,0),
  CODCMDPRODMAT NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  SCHIMB NUMBER(1,0),
  TIPARTICOL VARCHAR2(1),
  DEN_UM1 VARCHAR2(15),
  TERMEN DATE,
  PRET NUMBER(20,7),
  PRET_P NUMBER(20,7),
  SUPLIMENT NUMBER(1,0),
  STOC NUMBER(20,7),
  STOC_P NUMBER(20,7),
  STOCT NUMBER(20,7),
  TIP NUMBER(1,0),
  NRDOC NUMBER(20,0),
  MATECHIV NUMBER(20,0),
  ECHIVALENTA NUMBER(20,0),
  CANTECHIVALATA NUMBER(20,7),
  ECHIVSTRING CHAR(2),
  CODCOMANDA NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  DEN_PRODUS VARCHAR2(200),
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  GESTLOCCONT VARCHAR2(192),
  DEN_CLASEA VARCHAR2(50),
  DEN_UM_1 VARCHAR2(15),
  DEN_UM_2 VARCHAR2(15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7265A70CEB18B462B1B4DB9DFEA43CB2BD42AD84</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP (
  CODRAPORTP NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATAI DATE,
  DATAS DATE,
  PE_FORMATIE NUMBER(1,0),
  SECTIE NUMBER(20,0),
  FORMATIE NUMBER(20,0),
  PROGRAMF NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  INTRERUPERI NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  SCHIMB NUMBER(1,0),
  OBS VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>54D3F653E2FFF58C5FDB409C06C2D824DDFED08F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP0 (
  CODRAPORTP0 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  OBS VARCHAR2(400),
  COMANDA VARCHAR2(100),
  DENOBIECT VARCHAR2(200),
  CODRETETA NUMBER(20,0),
  UTILAJ VARCHAR2(200),
  CODUTILAJ2C NUMBER(20,0),
  DEREALIZAT NUMBER(20,7),
  CLIENTU VARCHAR2(100),
  FURNU VARCHAR2(100),
  SERIEF VARCHAR2(50),
  CODEXTERNCLIU VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B860EF9644595AF9FD075D3D651E34DBDB4E2A2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP1 (
  CODRAPORTP1 NUMBER(20,0),
  CODRAPORTP0 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  ANGAJAT NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  INDICE NUMBER(20,7),
  PRODREALIZAT NUMBER(20,7),
  PRODREBUT NUMBER(20,7),
  TIMP NUMBER(20,7),
  VALOARE NUMBER(20,7),
  DEN_ANGAJAT VARCHAR2(100),
  MARCA NUMBER(20,0),
  CODRAPORTP2C NUMBER(20,0),
  CODRAPORTP1C NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP1C</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B705F1C12815AD70FE99D830E04F055AD5021CE7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP1C (
  CODRAPORTP1C NUMBER(20,0),
  CODRAPORTP0 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  ANGAJAT NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  PRODREALIZAT NUMBER(20,7),
  PRODREBUT NUMBER(20,7),
  DEN_ANGAJAT VARCHAR2(100),
  MARCA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DCBD35F5617AEE7288FD9AA7C3A4FAE7B4F9E43E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP2 (
  CODRAPORTP2 NUMBER(20,0),
  CODRAPORTP1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODMAN NUMBER(20,0),
  REALIZAT NUMBER(20,7),
  REBUT NUMBER(20,7),
  CODOP NUMBER(20,0),
  CODLOC NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TU NUMBER(20,7),
  CODUTILAJ NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  REFACUT NUMBER(20,7),
  CODIES1 NUMBER(20,0),
  OBS VARCHAR2(1000),
  VALOARE NUMBER(20,7),
  INDEXOPER NUMBER(5,0),
  COMANDA VARCHAR2(100),
  UTILAJ VARCHAR2(200),
  OPERATIE VARCHAR2(300),
  DURATA NUMBER(20,7),
  TARIF NUMBER(20,7),
  NRDOCLINK VARCHAR2(30),
  TIPLOCMUNCA NUMBER(1,0),
  DATASTARTC VARCHAR2(20),
  DATASTOPC VARCHAR2(20),
  CODRAPORTP1C NUMBER(20,0),
  CODRAPORTP2C NUMBER(20,0),
  CODRAPORTP0 NUMBER(20,0),
  DURATAH NUMBER(20,7),
  TUH NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP2C</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4DBA51AF7C2F1CE298287AC55267129F895B6D0E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP2C (
  CODRAPORTP2C NUMBER(20,0),
  CODRAPORTP0 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODMAN NUMBER(20,0),
  REALIZAT NUMBER(20,0),
  REBUT NUMBER(20,0),
  CODOP NUMBER(20,0),
  VALOARE NUMBER(20,7),
  OPERATIE VARCHAR2(300),
  NROP NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPORTP3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D199321CB9C8C209DE9004EB8DC398F65FD9EACF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPORTP3 (
  CODRAPORTP3 NUMBER(20,0) NOT NULL,
  CODRAPORTP1 NUMBER(20,0),
  CODRAPORTP NUMBER(20,0),
  CODMOTIV NUMBER(20,0),
  ORE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0795963D5FA3D1574342577A90281F4EEBBEBE5C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED (
  CODWORKPLACE VARCHAR2(20),
  CIM VARCHAR2(20),
  NUMARLOT VARCHAR2(75),
  DATAEXPIRARELOT DATE,
  TIP NUMBER(1,0),
  SEMN NUMBER(1,0),
  CANT NUMBER(20,7),
  DATAOP DATE,
  CODTIPPART NUMBER(1,0),
  CODTIPDOC NUMBER(1,0),
  PART VARCHAR2(100),
  NRFACTURA NUMBER(20,0),
  NRAVIZ NUMBER(20,0),
  DATADOC DATE,
  CODTARA VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB09A39AA0AFCB4AD1F92C14E46A88A78DC25A68</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED0 (
  CODWORKPLACE VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4E30A54B8A0E0676632BF9F3D1FDBA90D993DCF1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED1 (
  CODWORKPLACE VARCHAR2(20),
  CIM VARCHAR2(20),
  NUMARLOT VARCHAR2(75),
  DATAEXPIRARELOT DATE,
  STOCANT NUMBER(20,0),
  STOC NUMBER(20,0),
  ARETRANZ NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED_CUMULAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3EB7EC5570A61C955540D4B51273B8A5F644FAD5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED_CUMULAT (
  CODWORKPLACE VARCHAR2(20),
  CIM VARCHAR2(20),
  NUMARLOT VARCHAR2(75),
  DATAEXPIRARELOT DATE,
  ORDINE NUMBER(1,0),
  TIP VARCHAR2(20),
  CANT NUMBER(20,0),
  TIPPART VARCHAR2(100),
  TIPDOC VARCHAR2(50),
  PART VARCHAR2(100),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODTARA VARCHAR2(5)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED_NAO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C22DF656FE2E62D2FCDED5F3842CA13E6635837B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED_NAO (
  CODOBIECT NUMBER(20,0),
  CIM VARCHAR2(20),
  COEFCNAS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RAPSTOCMED_SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8453ADFD8B67081234A3F90C101C06259BD5EF33</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RAPSTOCMED_SUB (
  CODSUBUNIT NUMBER(20,0),
  CODWORKPLACE VARCHAR2(15),
  CIF VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RECEPTIEWMS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>522DA260FFED1145AAA16F8A8ADA1238CBD4F2BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RECEPTIEWMS (
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIE NUMBER(20,0),
  TIPSERIE NUMBER(1,0),
  CODNIR NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  TG DATE,
  DATAPROD DATE,
  USERID NUMBER(20,0),
  NEWCODGEST NUMBER(20,0),
  OBSSERIE VARCHAR2(200),
  NEWCODLOCATIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RECLAMATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>726E2881F2A873346A2D19DBF37D2953A2E6ED29</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RECLAMATII (
  CODRECLAMATIE NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  CODUTILIZATOR NUMBER(20,0),
  MOTIV VARCHAR2(500),
  RECLAMATIE VARCHAR2(300),
  CODPART NUMBER(20,0),
  CODDOCR NUMBER(20,0),
  TIPDOCR NUMBER(20,0),
  REZOLVAT NUMBER(1,0),
  DATAREZ DATE,
  CODRESP NUMBER(20,0),
  IMPUTABILA NUMBER(1,0),
  TIPIMPUT NUMBER(1,0),
  CODPIMPUT NUMBER(20,0),
  CODPERSC NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RECLAMATII1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0B91745D5F96E659F715B302937E49778851E172</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RECLAMATII1 (
  CODRECLAMATIE1 NUMBER(20,0),
  CODRECLAMATIE NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  CANT NUMBER(20,7),
  OBS VARCHAR2(300),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUMS NUMBER(20,7),
  PU NUMBER(20,7),
  IMPUTABIL NUMBER(5,0),
  DENOBIECT VARCHAR2(150),
  DENUM VARCHAR2(50),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODINTERN VARCHAR2(80),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RECLAMATII2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7D213582492C76A917D19661CC254B94C47AF0C5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RECLAMATII2 (
  CODRECLAMATIE2 NUMBER(20,0),
  CODRECLAMATIE NUMBER(20,0),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REFACERECARNET_CARNETE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>303501AF208E68E6B3DD05739921A21FA9F2BFAD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REFACERECARNET_CARNETE (
  CODCARNET NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REFACERECARNET_FREENR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13BCE155FC0084C1C724CB8C6ECAA1D7699DB2D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REFACERECARNET_FREENR (
  STARTNR NUMBER(20,0),
  ENDNR NUMBER(20,0),
  CODDOCFREE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REFACERECARNET_INTERVALE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EEE574B0858B7E8E8CC07B296CE95093E6CA146E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REFACERECARNET_INTERVALE (
  IDGROUP NUMBER(20,0),
  NRMIN NUMBER(20,0),
  NRMAX NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REFACERECARNET_NRDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60280B49AD39950458BEB6ED018D469FAB15BB9E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REFACERECARNET_NRDOC (
  NRDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8406F35EAB877FFDF25CEC16FA41877746D63E7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG (
  CODREG NUMBER(20,0),
  TIPREG NUMBER(10,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODBANK NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(23,7),
  DIRTY NUMBER(1,0),
  OBS VARCHAR2(300),
  CODSUBUNIT NUMBER(20,0),
  PROVIZION NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CURS_IFRS NUMBER(20,7),
  SIMBOLMONEDA VARCHAR2(5),
  SIMBOLBANK VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CBFCA0C46B458DF7824E4EF08FA7EF56936CCFCC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG1 (
  CODREG1 NUMBER(20,0),
  CODREG NUMBER(20,0),
  CODGENERAL NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CONT NUMBER(20,0),
  SEMN NUMBER(1,0),
  CURS NUMBER(23,7),
  SEMNIFICATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  DIFERENTA NUMBER(20,7),
  DENPART VARCHAR2(100),
  TIPDOC NUMBER(20,0),
  DOCUMENT VARCHAR2(50),
  SIMBOLCONT VARCHAR2(100),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(30),
  CODBANK NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  DENUMIRECONT VARCHAR2(30),
  NRCONT VARCHAR2(30),
  TIPTRANZ NUMBER(1,0),
  SIMBOLBANK VARCHAR2(10),
  CODPART NUMBER(20,0),
  COEFPROVIZION NUMBER(20,7),
  MODIFICARI NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG1CONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F2D46F918668C1B71E0206E545A9C0822F3AF535</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG1CONT (
  CODREG1CONT NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  DIFERENTA NUMBER(20,7),
  CONT NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG1CONT_MARTOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>831875E1CE9868704EE48B8058431E51A1147FD9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG1CONT_MARTOR (
  CODREG1CONT NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  DIFERENTA NUMBER(20,7),
  CONT NUMBER(20,0),
  SIMBOLCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BCA1450827787E88B112DE01AAC74C9714C35736</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG1_INITIAL (
  CODGENERAL NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODOBLIGPIF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REG1_MARTOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>225669B2A3F9A5376EDE806F0E9CC49EB73BB8A0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REG1_MARTOR (
  CODGENERAL NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGLEAS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F1920F494476159DE0F84E17C6055C71F5638465</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGLEAS1 (
  CODREGLEAS1 NUMBER(20,0),
  CODREG NUMBER(20,0),
  SOLDREG NUMBER(20,7),
  CODCONTRACT NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODGEST NUMBER(20,0),
  NRCONTR NUMBER(20,0),
  DATACONTR DATE,
  VALCONTR NUMBER(20,7),
  VALREG NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGOSS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>73A6FBA58DEE9770BF455F3AC72A1DDA0FB10EBE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGOSS (
  CODREGOSS NUMBER(20,0),
  TIPREG NUMBER(10,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TRIMESTRUL NUMBER(1,0),
  CODBANK NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(23,7),
  DIRTY NUMBER(1,0),
  OBS VARCHAR2(300),
  CODSUBUNIT NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODANALIZA NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CURS_IFRS NUMBER(20,7),
  SIMBOLMONEDA VARCHAR2(5),
  SIMBOLBANK VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGOSS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E1E54FC3E0AEA219614A69170015B015D12701D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGOSS1 (
  CODREGOSS1 NUMBER(20,0),
  CODREGOSS NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TVADOCVAL NUMBER(20,7),
  TVADOC NUMBER(20,7),
  TVADOCREG NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CONT NUMBER(20,0),
  SEMN NUMBER(1,0),
  CURS NUMBER(23,7),
  SEMNIFICATIE NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  DIFERENTA NUMBER(20,7),
  MODIFICARI NUMBER(1,0),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  DOC VARCHAR2(100),
  CODTVASERV NUMBER(20,0),
  CODTVASERV1 NUMBER(20,0),
  DELETED NUMBER(1,0),
  SIMBOLCONT VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGPART_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C321BC351B5DD6917E82FF6EFE361CF5CFB846B0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGPART_LUNA (
  CODGENERAL NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  ICONT NUMBER(20,0),
  SEMNIFICATIE NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODIOPART1 NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CURS NUMBER(20,7),
  TVA NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  DATADOC DATE,
  NRDOC NUMBER(20,0),
  COEFPROVIZION NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGPERS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7038EB786BF5E64AE995750773EF19DD8345731D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGPERS1 (
  CODREGPERS1 NUMBER(20,0),
  CODREG NUMBER(20,0),
  SOLDDOC NUMBER(20,7),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODPERS NUMBER(20,0),
  CODCONT NUMBER(20,0),
  ICONT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DIFERENTA NUMBER(20,7),
  DEN_PERS VARCHAR2(401),
  DEN_CONT VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGPERS1_MARTOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0661AAB986518D50AB7458148985CF40E701F22E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGPERS1_MARTOR (
  CODPERS NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  ICONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGTREZOR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>231967FB6AA62DC1962F8EAB02D9973941A67D9C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGTREZOR1 (
  CODREGTREZOR1 NUMBER(20,0),
  CODREG NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7),
  SOLDDOC NUMBER(20,7),
  SOLDDOCREG NUMBER(20,7),
  CODBANK NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  DIFERENTA NUMBER(20,7),
  DEN_CONT VARCHAR2(30),
  NRCONT VARCHAR2(30),
  FILIALA VARCHAR2(20),
  CREDIT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REGTREZOR1_MARTOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7789EB594021065084C102EF8B9734D58CD18C3F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REGTREZOR1_MARTOR (
  CODBANKCONT NUMBER(20,0),
  SOLDDOCVAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTARTINACTIVE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7860CA4F2BA7CAC119462427E602949F3E294E58</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTARTINACTIVE (
  COD NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTAURANTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>12137CB8897F1BD0C165DB74661327C507C2DC24</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTAURANTE (
  CODRESTAURANT NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  SUBUNITATEA NUMBER(20,0),
  TIPORAR NUMBER(1,0),
  ORASTART TIMESTAMP(6),
  ORAEND TIMESTAMP(6),
  TIPUNICITATE NUMBER(1,0),
  TIPGESTIMPLICITA NUMBER(1,0),
  POSTWMRETAIL NUMBER(1,0),
  CODPOSTRETAIL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTCLASE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EBD092D5FAB1C168BFFA871CC2CC180299ECEB2F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTCLASE (
  COD NUMBER(20,0),
  CODCLASEA NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0),
  NEWRECORD NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTCLASE_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E7EF6B33600F09A8D60743085F60FA309B4F1866</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTCLASE_INI (
  COD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTCMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EC650BADE3377EDD5A30053FBDE75FBA77C60BBB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTCMD (
  CODRESTCMD NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  CODMASA NUMBER(20,0),
  CODOSPATAR NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DESCHIDERE TIMESTAMP(6),
  INCHIDERE TIMESTAMP(6),
  INCHISA NUMBER(1,0),
  OBS VARCHAR2(100),
  NRPERS NUMBER(5,0),
  DIMINUAT NUMBER(1,0),
  ADRESALIVRARE VARCHAR2(400),
  NUMEPERS VARCHAR2(400),
  NEWRECORD NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTCMD1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>813330A69BB80D75C5F492C789D9F1DC127D6981</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTCMD1 (
  CODRESTCMD1 NUMBER(20,0),
  CODRESTCMD NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  PRET NUMBER(20,7),
  CANT NUMBER(20,7),
  OBS VARCHAR2(100),
  CODGEST NUMBER(20,0),
  LISTAREGEST NUMBER(1,0),
  FARALISTARE NUMBER(1,0),
  TIPUM NUMBER(1,0),
  CANTARIT NUMBER(1,0),
  PROCTVA NUMBER(20,7),
  ORDINE NUMBER(3,0),
  TAXA NUMBER(1,0),
  DENUMIRE VARCHAR2(100),
  DUM VARCHAR2(50),
  NEWRECORD NUMBER(1,0),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  FAKEEDITBTN VARCHAR2(2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTCMD1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87CBBEB7D2740991D24B838C6E579FA7ADAD089B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTCMD1_INITIAL (
  CODRESTCMD1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTGESTIMPLICITE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>41D96D2E53235D72331B91ED5ACD06E5BD428819</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTGESTIMPLICITE (
  COD NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  GESTIMPLICITA NUMBER(20,0),
  NEWRECORD NUMBER(1,0),
  DENOBIECT VARCHAR2(200),
  DENGEST VARCHAR2(100),
  CODCLASA NUMBER(20,0),
  GESTSETATA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTGESTIMPLICITE_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BC60040219F35A7DD1968E21ADC2E071CD3F4CD4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTGESTIMPLICITE_INI (
  COD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTGESTLISTVER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DAE2C39277D7211E5D73A4693AA072E85F46B91A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTGESTLISTVER (
  COD NUMBER(20,0),
  CODGEST NUMBER(20,0),
  LISTVER NUMBER(20,0),
  FARALISTARE NUMBER(20,0),
  DENGEST VARCHAR2(100),
  DENVER VARCHAR2(100),
  NEWRECORD NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTNP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>826E80A675BF1F542FE08AD5E7E89541D8D785B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTNP (
  CODRESTNP NUMBER(20,0),
  CODRESTCMD NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  CODPART NUMBER(20,0),
  VALOARE NUMBER(20,7),
  VALDISC NUMBER(20,7),
  PROTOCOL NUMBER(1,0),
  LISTATCM NUMBER(1,0),
  DATACREARE TIMESTAMP(6),
  TIPCASAMARCAT NUMBER(10,0),
  TEXTNEFISCAL VARCHAR2(100),
  FACTURARE NUMBER(1,0),
  LISTAT NUMBER(1,0),
  CODPARTRETAIL NUMBER(20,0),
  VALMARTOR_CMD NUMBER(20,7),
  NEWRECORD NUMBER(1,0),
  SALA VARCHAR2(100),
  MASA VARCHAR2(100),
  OSPATAR VARCHAR2(100),
  NRCOMANDA NUMBER(20,0),
  ADRESALIVRARE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTNP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5CEA699462392C19747496DED6C54F318665ED9A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTNP1 (
  CODRESTNP1 NUMBER(20,0),
  CODRESTNP NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  DISCMANUAL NUMBER(1,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  DUM VARCHAR2(30),
  NEWRECORD NUMBER(1,0),
  PARITATE NUMBER(20,7),
  TAXA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTNP1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0FAFBDFF4BC7C46313470007923F96A374712EDE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTNP1_INITIAL (
  CODRESTNP1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTNP2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6B83301127A53583A6FEB3F0B0B63B8A376BF40</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTNP2 (
  CODRESTNP2 NUMBER(20,0),
  CODRESTNP NUMBER(20,0),
  TIPPLATA NUMBER(10,0),
  VALOARE NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  NEWRECORD NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTNP2_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C8F62C1C06390C8F46C651849D74C3A1C96FD19</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTNP2_INITIAL (
  CODRESTNP2 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTOBIECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9ACB3042BF3A2FFB7D43708B0DF6AD2300061311</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTOBIECT (
  COD NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  CODSALA NUMBER(20,0),
  X NUMBER(20,0),
  Y NUMBER(20,0),
  WIDTH NUMBER(20,0),
  HEIGHT NUMBER(20,0),
  COLOR NUMBER(20,0),
  TEXTAFISARE VARCHAR2(100),
  FORMA NUMBER(1,0),
  POZA BLOB,
  IS3D NUMBER(1,0),
  NIVEL NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTOBSART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>21E0C7C8998B2BF58EFC750CF4156EAE599F395D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTOBSART (
  COD NUMBER(20,0),
  CODRESTAURANT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  OBS VARCHAR2(100),
  NEWRECORD NUMBER(1,0),
  SELECTAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RESTOBSART_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB0950E2366C147E922C3B5035743E9D81BD93FB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RESTOBSART_INI (
  COD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REST_VANZARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D52464D2CA015EC626AED75D30BC3389589D8024</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REST_VANZARI (
  SALA VARCHAR2(30),
  MASA VARCHAR2(100),
  OSPATAR VARCHAR2(401),
  NRCOMANDA NUMBER(20,0),
  DESCHIDERE TIMESTAMP(6),
  INCHIDERE TIMESTAMP(6),
  NRNOTAPLATA NUMBER(20,0),
  DENART VARCHAR2(200),
  DENUM VARCHAR2(15),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  DISCOUNT NUMBER(20,7),
  VALARTICOL NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RETURO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>780D3AD5E6C37AB6234EE71CE1E8652979596609</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RETURO (
  CODRETURO NUMBER(20,0),
  SESSIONID VARCHAR2(100),
  STARTEDAT TIMESTAMP(6),
  REFUND NUMBER(20,7),
  VOUCHERBARCODE VARCHAR2(100),
  RVM_SERIALNUMBER VARCHAR2(100),
  RVM_TYPE VARCHAR2(100),
  LOCATION_CUSTOMERID VARCHAR2(100),
  LOCATION_NAME VARCHAR2(100),
  IS_USED NUMBER(1,0),
  USED_DATE TIMESTAMP(6),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  UPLOAD_DATE TIMESTAMP(6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RETUROSTINS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EF3D7BEF0CA42ACA75127C5347D6F4CBDF100501</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RETUROSTINS (
  CODRETUROSTINS NUMBER(20,0),
  CODRETURO NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  STARTEDAT TIMESTAMP(6),
  VOUCHERBARCODE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZERVARI_COMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2A9EBE169E7ABA8CD3631F6E2FA64A625D0ACBBD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZERVARI_COMANDA (
  PRODUS VARCHAR2(200),
  UMPRODUS VARCHAR2(15),
  TERMEN DATE,
  CANTACCEPTAT NUMBER(20,7),
  COMPONENT VARCHAR2(200),
  GESTIUNE VARCHAR2(30),
  TIPCONTABIL VARCHAR2(60),
  UMCOMPONENT VARCHAR2(15),
  NECESAR NUMBER(20,7),
  REZSTOC NUMBER(20,7),
  CERFURN NUMBER(20,7),
  NESOSIT NUMBER(20,7),
  NEACOPERIT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZERVATS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9C050FBAC5CC13410A69D56B99D35F472B55AD08</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZERVATS (
  CODREZERVATS NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  REST NUMBER(30,17),
  UMSEC NUMBER(20,0),
  CODCMDPRODMAT NUMBER(20,0),
  REZERVATINI NUMBER(30,17),
  CODOBIECT NUMBER(20,0),
  CODCOMANDA1F NUMBER(20,0),
  CODINVENTAR1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZ_CCOM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D433C9B1E1F99143919834C6C394ED0A43C5527E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZ_CCOM1 (
  CODCOMANDA1 NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  TERMEN DATE,
  CODOBIECT NUMBER(20,0),
  UM VARCHAR2(15),
  RESTACCEPTAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  PARITATE NUMBER(30,15),
  CODPROIECT NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  TIPCOMANDA NUMBER
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZ_PROIECTNOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4580EE8E32551D16236D4AE63AD06230200EE08D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZ_PROIECTNOD (
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  POZITIE NUMBER(10,0),
  CODPROIECTNOD NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  NIVEL NUMBER(10,0),
  CANT NUMBER(20,7),
  NECESAR NUMBER(20,7),
  CODRETETA NUMBER(20,0),
  REZERVAT NUMBER(20,7),
  REZFURN NUMBER(20,7),
  REZOLVAT NUMBER(20,7),
  INDEXPARINTE VARCHAR2(50),
  ORDINE NUMBER(10,0),
  REZCMDFURN NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZ_REZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4EAA53B9FC1AD0F1809695EE456E5418865ACEF6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZ_REZ (
  CODCOMANDA1 NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODOBIECT NUMBER,
  CODGEST NUMBER(20,0),
  CANT NUMBER,
  RESTCOM NUMBER,
  UM VARCHAR2(15),
  UMSEC NUMBER,
  REZ NUMBER,
  REZINI NUMBER,
  REZFURN NUMBER,
  REZCMDFURN NUMBER,
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  GEST_IOART VARCHAR2(100),
  NECESAR NUMBER,
  NECESARINI NUMBER,
  CODIOART NUMBER(20,0),
  IDX NUMBER,
  REZOLVAT NUMBER,
  REZFURNINI NUMBER,
  DEN_UMSEC VARCHAR2(50),
  DEN_UM1 VARCHAR2(50),
  DEN_UM2 VARCHAR2(50),
  DATADOC DATE,
  UM1 NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  PARITATE NUMBER(20,7),
  RELATIEUM1 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  CMDFLIBER NUMBER(20,7),
  REZCMDFURN_INI NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_REZ_STOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>77FF0E59ADA496FFD4B5A88DAAE416405E945AE2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_REZ_STOC (
  CODNIRSER NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  STOC NUMBER,
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  REST NUMBER,
  UMSEC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RULAJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C5779C6DCBCAE8E9A1729D37E7B87BAFA034BEF0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RULAJ (
  CODCONT NUMBER(20,0),
  TIP VARCHAR2(1),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7),
  VALOARE_GRUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RULAJ_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>814C3EF900A20134B80EB0037B4B0E41C4F15F58</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RULAJ_MAN (
  CODCONT NUMBER(20,0),
  TIP VARCHAR2(1),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7),
  VALOARE_GRUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_RULAJ_PREC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0067C0F00079154130EA497B53DA6C56ED978655</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_RULAJ_PREC (
  CODCONT NUMBER(20,0),
  TIP VARCHAR2(1),
  VALOARE NUMBER(20,7),
  VALOAREV NUMBER(20,7),
  SUBUNITATEA NUMBER(20,0),
  VALOARE_IFRS NUMBER(20,7),
  VALOAREV_IFRS NUMBER(20,7),
  VALOARE_GRUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SABLCOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7E0133A84FE1619F7D081A0BE040A37EC421AB86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SABLCOL (
  CODSABLON NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  INDEXLOCAL NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SABLONDESCRIPT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B32B3097E27940B82A55716640F2DB7594D7C28B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SABLONDESCRIPT (
  CODSABLON NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  SIMBOL VARCHAR2(50),
  CODDESCRIPTOR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SABLONDESCRIPT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9931D45FD0EEA20BE9ACA97839A838B846084FC7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SABLONDESCRIPT1 (
  CODSABLON1 NUMBER(20,0),
  CODSABLON NUMBER(20,0),
  CODDESCRIPTOR1 NUMBER(20,0),
  PROCENT NUMBER(20,7),
  VALOARE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT01</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D65EE0795B802A0754C530BB6E394F96A1187E62</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT01 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(2),
  COL04 NVARCHAR2(9),
  COL05 DATE,
  COL06 NVARCHAR2(70),
  COL07 NVARCHAR2(256),
  COL08 NVARCHAR2(18),
  COL09 NUMBER(20,0),
  COL10 NUMBER(20,0),
  COL11 NVARCHAR2(3),
  COL12 NUMBER(20,0),
  COL13 NVARCHAR2(256),
  COL14 NVARCHAR2(9),
  COL15 NVARCHAR2(9),
  COL16 NVARCHAR2(18),
  COL17 NVARCHAR2(70)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT02</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0BB2D4C53C948C068D79516CBD810662DD9D56FE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT02 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(70),
  COL04 DATE,
  COL05 DATE,
  COL06 NUMBER(20,0),
  COL07 NUMBER(20,0),
  COL08 NUMBER(20,0),
  COL09 NUMBER(20,0),
  COL10 NVARCHAR2(256),
  COL11 NVARCHAR2(256)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT03</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DADC4BABBCB7D61F6771A6EF1A5A253BF2263BE7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT03 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(70),
  COL03 NVARCHAR2(256),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(35),
  COL06 NVARCHAR2(35),
  COL07 NVARCHAR2(18),
  COL08 DATE,
  COL09 NUMBER(18,2),
  COL10 NUMBER(18,2),
  COL11 NUMBER(18,2),
  COL12 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT04</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C75E087D54878AB187A2789357A64AB791F1F7AE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT04 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 NVARCHAR2(9),
  COL05 NVARCHAR2(70),
  COL06 NUMBER(18,2),
  COL07 NUMBER(18,2),
  COL08 NUMBER(18,2),
  COL09 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT05</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A4891055BA578E2AF3CC9B9D431568A779EE7653</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT05 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 NVARCHAR2(9),
  COL05 NVARCHAR2(70),
  COL06 NUMBER(18,2),
  COL07 NUMBER(18,2),
  COL08 NUMBER(18,2),
  COL09 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT06</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D3595A416E459969CD09C980EFEBA63451E9E9CF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT06 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(70),
  COL04 NUMBER(20,0),
  COL05 NUMBER(20,0),
  COL06 NUMBER(20,0),
  COL07 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT07</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6CC6D58CE4C09F45966A6A4BA33E3BE15510080C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT07 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(70),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(70),
  COL05 NVARCHAR2(35),
  COL06 NVARCHAR2(35),
  COL07 NVARCHAR2(18),
  COL08 NVARCHAR2(35),
  COL09 NVARCHAR2(2),
  COL10 NVARCHAR2(18)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT08</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>613779586993B91046ED22B7EE5D3258C7D75A6A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT08 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(18),
  COL05 NVARCHAR2(70),
  COL06 NVARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT09</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C0A46107993BC6994CCD8D7574D04FB73DFC619B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT09 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(35),
  COL04 NVARCHAR2(18),
  COL05 NVARCHAR2(18),
  COL06 NVARCHAR2(70),
  COL07 NVARCHAR2(70),
  COL08 NVARCHAR2(18),
  COL09 NVARCHAR2(18)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT10</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C5D14B89C743DE95EF144E55CC11D4FF91536E02</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT10 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(9),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(35),
  COL06 DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT11</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B2922D9E11E7854AE5AA304DE425AD8312876DC1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT11 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(35),
  COL04 NVARCHAR2(70),
  COL05 NVARCHAR2(18)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT12</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B66149CFB74D81CBF3F22C56537B41574260195</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT12 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(256),
  COL04 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT13</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>41F67C7EE899B5EE2ED215D2AEA6199ADB8EC512</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT13 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(9),
  COL04 DATE,
  COL05 DATE,
  COL06 NVARCHAR2(256),
  COL07 NUMBER(22,7),
  COL08 NUMBER(20,0),
  COL09 NUMBER(5,4),
  COL10 NVARCHAR2(2),
  COL11 NVARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT14</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1B87DB430C6EBDC672A2EE570E639B2BBAAABF6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT14 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(256)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT15</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2C658B33E149B6FAED5852B4742E2FACA6F68C72</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT15 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(256),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(256)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT16</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62932BE06F96F9C837387A90B7087D38879A1232</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT16 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(256)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT17</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9AF7FFCB0712FE05D1369AC492426EDF16A4EF88</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT17 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(70),
  COL03 NVARCHAR2(9),
  COL04 NVARCHAR2(70),
  COL05 NVARCHAR2(256),
  COL06 NVARCHAR2(35),
  COL07 NVARCHAR2(70),
  COL08 NVARCHAR2(9),
  COL09 NVARCHAR2(9),
  COL10 NVARCHAR2(9),
  COL11 NUMBER(22,7),
  COL12 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT18</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>000588F5F3B95FC2B2D422E6664B7BE285ED7F86</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT18 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(9),
  COL03 NVARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT19</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D416B971E0902B4A3E02F2DE6401EF68C13AA7B2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT19 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(70),
  COL05 NVARCHAR2(70),
  COL06 NVARCHAR2(18),
  COL07 NVARCHAR2(18),
  COL08 NVARCHAR2(35),
  COL09 NVARCHAR2(35),
  COL10 NVARCHAR2(9),
  COL11 NUMBER(22,7),
  COL12 NUMBER(18,2),
  COL13 NUMBER(22,6),
  COL14 NUMBER(18,2),
  COL15 NUMBER(22,6),
  COL16 NUMBER(18,2),
  COL17 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT20</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A0BB993E9FC1AE62151A82F3CF567A687D472AF0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT20 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(18),
  COL03 NVARCHAR2(35)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT21</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C2D1C1D7EF586996C17079C59FE405E35F1595C5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT21 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 NVARCHAR2(70)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT22</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DE654AC7BD1BAB9398FF2871546E63686CE8E335</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT22 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(70),
  COL04 NVARCHAR2(256),
  COL05 NUMBER(20,0),
  COL06 DATE,
  COL07 DATE,
  COL08 DATE,
  COL09 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT23</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3332E5A67A87D35AB75585CC70622DC30C15D3A9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT23 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(70),
  COL03 NVARCHAR2(35),
  COL04 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT24</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EA43BD3A2B21B906C5F2C2F7D677842C4E2609DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT24 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(18),
  COL05 NUMBER(18,2),
  COL06 NUMBER(18,2),
  COL07 NUMBER(18,2),
  COL08 NUMBER(22,7),
  COL09 NUMBER(22,7),
  COL10 NUMBER(18,2),
  COL11 NUMBER(18,2),
  COL12 NUMBER(18,2),
  COL13 NUMBER(18,2),
  COL14 NVARCHAR2(35),
  COL15 NUMBER(22,7),
  COL16 NUMBER(18,2),
  COL17 NUMBER(18,2),
  COL18 NUMBER(20,0),
  COL19 NUMBER(18,2),
  COL20 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT25</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>94307984EF591CE778B4CF7EE95D688AC111AC87</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT25 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT26</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3E39A81A57FDBDAD6915099C5662B8E30332A66B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT26 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT27</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9041D733B8B4E15007B9A1A4DB000CB9CF27E4E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT27 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(256),
  COL05 NVARCHAR2(9),
  COL06 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT28</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>312458097FF31C404A4765CD4654FA968773F7CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT28 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(70),
  COL04 NUMBER(20,0),
  COL05 NUMBER(20,0),
  COL06 DATE,
  COL07 NVARCHAR2(35),
  COL08 NVARCHAR2(18),
  COL09 NVARCHAR2(256),
  COL10 NVARCHAR2(35),
  COL11 DATE,
  COL12 DATE,
  COL13 NVARCHAR2(35),
  COL14 NVARCHAR2(35),
  COL15 NVARCHAR2(18),
  COL16 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT29</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E135650981F26E96B046272D2AC7E533F53100BF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT29 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(70),
  COL05 NUMBER(20,0),
  COL06 DATE,
  COL07 NVARCHAR2(35),
  COL08 NVARCHAR2(35),
  COL09 NVARCHAR2(35),
  COL10 NVARCHAR2(256),
  COL11 NUMBER(20,0),
  COL12 NUMBER(20,0),
  COL13 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT30</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7B689647470FFE49C6D0BCC0B81AE63FA9D30F29</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT30 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(9),
  COL04 NVARCHAR2(256),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT31</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>49B8F4DD113B71EC7A7E08C4AAA6A4D4BC3136C4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT31 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(18,2),
  COL03 NVARCHAR2(3),
  COL04 NUMBER(18,2),
  COL05 NUMBER(18,4)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT32</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A6BAF27D56282E8E9D6132BED5DA3A5809EB95A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT32 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(9),
  COL04 NVARCHAR2(9),
  COL05 NUMBER(22,7),
  COL06 NUMBER(22,7),
  COL07 NVARCHAR2(70),
  COL08 NUMBER(20,0),
  COL09 NVARCHAR2(70),
  COL10 NVARCHAR2(35)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT33</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>858DD34182BA7AA93922228945DF570D11AA7AAF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT33 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT34</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C652EEA0A3BED600C09DD371EA3860DDE8403AA6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT34 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(70),
  COL04 NUMBER(20,0),
  COL05 NUMBER(20,0),
  COL06 NVARCHAR2(70),
  COL07 NVARCHAR2(35),
  COL08 NUMBER(20,0),
  COL09 NUMBER(20,0),
  COL10 DATE,
  COL11 NVARCHAR2(9),
  COL12 NUMBER(20,0),
  COL13 NUMBER(20,0),
  COL14 NVARCHAR2(70),
  COL15 NVARCHAR2(9),
  COL16 NVARCHAR2(35),
  COL17 DATE,
  COL18 NVARCHAR2(35),
  COL19 NVARCHAR2(35),
  COL20 NVARCHAR2(70),
  COL21 NVARCHAR2(256),
  COL22 NUMBER(20,0),
  COL23 NUMBER(20,0),
  COL24 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT35</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1F9CA3F49C61CBE7403F2E4D9C207E6706729BF8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT35 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(70),
  COL04 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT36</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>52CB6AB5120F911C6B343601074920AC1599480E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT36 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(70),
  COL04 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT37</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>95AE45BE92D99E0DAC32C3706A02D3EB3D2885B3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT37 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 DATE,
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(18),
  COL06 NVARCHAR2(35),
  COL07 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT38</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0E6B112DCF385D126E68917279C49BC3595B6289</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT38 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(70),
  COL05 NUMBER(20,0),
  COL06 NUMBER(20,0),
  COL07 NUMBER(20,0),
  COL08 NUMBER(20,0),
  COL09 NVARCHAR2(9),
  COL10 NVARCHAR2(70),
  COL11 NVARCHAR2(256),
  COL12 NUMBER(20,0),
  COL13 NUMBER(22,6),
  COL14 NVARCHAR2(9),
  COL15 NUMBER(22,7),
  COL16 NUMBER(18,2),
  COL17 DATE,
  COL18 NUMBER(20,0),
  COL19 NVARCHAR2(256),
  COL20 NUMBER(20,0),
  COL21 NVARCHAR2(9),
  COL22 NUMBER(20,0),
  COL23 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT39</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>81404217BEB43AD52B2D78F2E96EFEF6AC5CDB96</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT39 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(70),
  COL03 DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT40</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B0B1E2F63A2233107E831DD5B0C4CEE8F22C5FD7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT40 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 DATE,
  COL04 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT41</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>003132233B23CE93C3E9741BE272DF9D105B9D5A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT41 (
  COL01 NUMBER(20,0),
  COL02 DATE,
  COL03 DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT42</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B37D95AB829854B1660C7E8E2E478520235EC5CB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT42 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT43</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DF3EF17D9464F7A489E35558E68EC0E74E46DE94</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT43 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NVARCHAR2(256)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT44</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>23FA17FF23C2F29C2FD65BC518F8D01A79FCD943</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT44 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NUMBER(20,0),
  COL04 DATE,
  COL05 NVARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT45</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5D7DAF70C88796D204D9B5A0223A751D2DFA763</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT45 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2),
  COL05 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT46</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C7504F4B64D778C1093FF1ECD7311F92E2E9930E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT46 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT47</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>27E447983509AD2D0B794119C54498668954ECE5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT47 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT48</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A7CEB4AEE497136E641CAC7BE037C11F6A77A21A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT48 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 NUMBER(20,0),
  COL05 NUMBER(20,0),
  COL06 NVARCHAR2(70),
  COL07 DATE,
  COL08 NVARCHAR2(18),
  COL09 NVARCHAR2(256),
  COL10 NVARCHAR2(35),
  COL11 NVARCHAR2(35),
  COL12 NVARCHAR2(35),
  COL13 NUMBER(20,0),
  COL14 NUMBER(20,0),
  COL15 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT49</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1F5FB91565B4A853C834F2D836F9AE545BBB556</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT49 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(70),
  COL06 NUMBER(20,0),
  COL07 NVARCHAR2(35),
  COL08 NVARCHAR2(35),
  COL09 DATE,
  COL10 NVARCHAR2(256),
  COL11 NVARCHAR2(9),
  COL12 NUMBER(20,0),
  COL13 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT50</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FED450C218DE60C6720E1D7F7E0B0936D57A3ADB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT50 (
  COL01 NUMBER(20,0),
  COL02 NVARCHAR2(35),
  COL03 NUMBER(20,0),
  COL04 DATE,
  COL05 NVARCHAR2(9)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT51</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4A208514E34A1576DA47003EA2D12E0DEB63DC8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT51 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(18,2),
  COL04 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT52</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>43F5089C47367403C80DE6B9A66AEDE554CA6A21</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT52 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(22,6),
  COL04 NUMBER(22,6),
  COL05 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT53</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>217E0D2BFCD3E4C21B7D3445ED232182D2467258</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT53 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(35),
  COL04 DATE,
  COL05 DATE,
  COL06 DATE,
  COL07 DATE,
  COL08 NVARCHAR2(9),
  COL09 NVARCHAR2(35),
  COL10 NVARCHAR2(35),
  COL11 NUMBER(20,0),
  COL12 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT54</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A6544A5EDAC58CFC76FE1DDE3659CE2E8F1FF159</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT54 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(18)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT55</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CC30685CA9F1CD817650640F241363EB948590E2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT55 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NVARCHAR2(70),
  COL05 NVARCHAR2(70),
  COL06 NVARCHAR2(35),
  COL07 NVARCHAR2(35),
  COL08 NUMBER(20,0),
  COL09 NUMBER(20,0),
  COL10 NVARCHAR2(70),
  COL11 NVARCHAR2(70),
  COL12 NUMBER(22,6),
  COL13 NVARCHAR2(9),
  COL14 NUMBER(22,7),
  COL15 NUMBER(18,2),
  COL16 NVARCHAR2(9),
  COL17 NVARCHAR2(256),
  COL18 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT56</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>19E058CAEE9A6B18EF188037B56FF97E6164E80F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT56 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT57</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AE4E618AD2433C584724BE23393BF70BD6B428AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT57 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(70),
  COL04 NVARCHAR2(35),
  COL05 NVARCHAR2(9),
  COL06 NVARCHAR2(256),
  COL07 DATE,
  COL08 NUMBER(20,0),
  COL09 NVARCHAR2(70),
  COL10 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT58</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FDD681ABCF9BB76220FA8E9CCD410F3C231B3DCA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT58 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0),
  COL03 NVARCHAR2(18),
  COL04 NUMBER(18,2),
  COL05 NUMBER(18,2),
  COL06 NUMBER(18,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT59</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>44496CDF8BFBF108B20DAC44AF963DD4ED4BA186</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT59 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT60</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FEC64F92CA527E18E3A1EC6E252222FCE4420A08</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT60 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT61</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A1F8A5E2F7706F3E1DDFF6A92818270F2C5FDA2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT61 (
  COL01 NUMBER(20,0),
  COL02 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_CC4426</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3CF98B27EDFC8B25A402319B8B756668ED0ED19C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_CC4426 (
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_CODSAF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD7FC95D750E99090370A116F5D1C0BB5BADD513</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_CODSAF (
  CODSAFTTAB NUMBER(5,0),
  CODSURSA NUMBER(20,0),
  CODSAF NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  CODAUX NUMBER(20,0),
  IDXAUX NUMBER(5,0),
  CODSTRING VARCHAR2(70)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_EXCL_J1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E62B1B8D04C7C17F8EDA503A524C678A2587902B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_EXCL_J1 (
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CONTD NUMBER(20,0),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10),
  CONTC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_JURNAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>92F31BDD0DBE0433676CAA3BF81CE8E095A1659E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_JURNAL (
  CODJURNAL NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  DATADOC DATE,
  DOCUMENT VARCHAR2(100),
  DESCRIPTION NVARCHAR2(256),
  CODMONEDA NUMBER(20,0),
  CURRENCYCODE NVARCHAR2(3),
  EXCHANGERATE NUMBER(18,4),
  EXCL_TAXINFO NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_JURNAL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2AE4EA8082320C13DEB3040316127849500DB246</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_JURNAL1 (
  CODJURNAL1 NUMBER(20,0) NOT NULL,
  CODMIFIX1 NUMBER(20,0),
  CODMIFIX NUMBER(20,0),
  CODJURNAL NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CONTD NUMBER(20,0),
  CONTC NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DATADOC DATE,
  TIPREEVAL NUMBER(1,0),
  ASSETTRANSACTIONTYPE VARCHAR2(3),
  TIPTRANZACTIE NUMBER(7,0),
  SEMN NUMBER(2,0),
  CODDESCRD NUMBER(20,0),
  ICONTD NUMBER(20,0),
  TIPCONTD NUMBER(5,0),
  ANALITICCONTD VARCHAR2(10),
  CODDESCRC NUMBER(20,0),
  ICONTC NUMBER(20,0),
  TIPCONTC NUMBER(5,0),
  ANALITICCONTC VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_JURNALDET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F58693F6C08072F001E033F6A948AA6B066A360F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_JURNALDET (
  CODJURNAL NUMBER(20,0) NOT NULL,
  CODPART NUMBER(20,0),
  CODPART_2 NUMBER(20,0),
  DATADOC DATE,
  DATACREARE TIMESTAMP(6),
  TIPTRANZ NUMBER(1,0),
  OBIECTTRANZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_MANEVRA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0C71121C9F43600DE529A0DCB23C26953E0214E7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_MANEVRA (
  FILTRU VARCHAR2(20) NOT NULL,
  AL NUMBER(5,0) NOT NULL,
  CODUNIC NUMBER(20,0) NOT NULL
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_MIFIX1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>894490A9B5F83DE724A638AD6A7EA3142CEE5EB2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_MIFIX1 (
  CODMIFIX1 NUMBER(20,0) NOT NULL,
  CODMIFIX NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_NCONT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F068CBF51AF3DEF77DE8E7A2EE0E6463E4D1933</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_NCONT (
  CODCONT NUMBER(20,0),
  SIMBOL NVARCHAR2(100),
  CODSAFT NVARCHAR2(70),
  CLASA NUMBER(1,0),
  DEN_CONT NVARCHAR2(200),
  TIPCONT NUMBER(1,0),
  NIVEL NUMBER(2,0),
  FRUNZA NUMBER(1,0),
  NO_SOLDPART NUMBER(1,0),
  VALID NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_NPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>62FC7C7665FEFFAD69EC3B706B6A9EAD4661CEEA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_NPART (
  CODPART NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CLIENT NUMBER(1,0),
  FURNIZOR NUMBER(1,0),
  SOLDI NUMBER(20,3),
  SOLDF NUMBER(20,3)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_NPARTDET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>41D73F4A3E168A9500CFDA54093FF698FC1E1E84</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_NPARTDET (
  CODPART NUMBER(20,0),
  PERSFIZICA NUMBER(1,0),
  COD_CODFISCAL NUMBER(20,0),
  CODFISCAL VARCHAR2(75),
  STATCOMUNITAR NUMBER(1,0),
  SIMBTARA VARCHAR2(75),
  PARTID VARCHAR2(35)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_NPARTFUZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1AED3D3CC7F28BF1B99BCE5FF309C50926486ACF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_NPARTFUZ (
  CODPARTFUZ NUMBER(20,0),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_PARAMS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E5C7324D1FE9FFFA0B3671009EEFCD567EF4E51F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_PARAMS (
  CODFIRMA NUMBER(20,0),
  USERID NUMBER(20,0),
  TIP NUMBER(1,0),
  ANINI NUMBER(4,0),
  LUNAINI NUMBER(2,0),
  ANFIN NUMBER(4,0),
  LUNAFIN NUMBER(2,0),
  ANP NUMBER(4,0),
  LUNAP NUMBER(2,0),
  CODBANKCONT NUMBER(20,0),
  CODSUBUNIT NUMBER(20,0),
  PERSCONTACT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_STOCKMOVEMENT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5F675F0BFD7222DE5654CD3A7C7A065D27542E05</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_STOCKMOVEMENT (
  CODSAF NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODPARINTE NUMBER(20,0),
  TAB VARCHAR2(1),
  MOVEMENTTYPE VARCHAR2(9),
  DATADOC DATE,
  CODPART NUMBER(20,0),
  LINES_COUNT NUMBER(20,0),
  LINES_SUM NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_TAXINFO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13665EBA216F0D16549C5FF4F577C44633E153B5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_TAXINFO (
  CODTI NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODCONTDED NUMBER(20,0),
  TAXTYPE NVARCHAR2(9),
  TAXCODE NVARCHAR2(9),
  TAXPERCENTAGE NUMBER(22,7),
  TAXBASE NUMBER(22,7),
  TAXBASEDESCRIPTION NVARCHAR2(70),
  CODTAXAMOUNTSAF_AMOUNT NUMBER(20,0),
  TAXEXEMPTIONREASON NVARCHAR2(70),
  TAXDECLARATIONPERIOD NVARCHAR2(35),
  TAXVAL NUMBER(22,7),
  CHEIE_CODCONTDED NUMBER(20,0),
  CHEIE_CODCONTCOL NUMBER(20,0),
  CHEIE_TAXVAL NUMBER(22,7),
  CHEIE_BAZATVAMARJA NUMBER(22,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAFT_TAXINFO_MP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8DF1761C7EBFF5CF33FB42B9885F56DEAE1E7E58</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAFT_TAXINFO_MP (
  CODTI NUMBER(20,0),
  IDXLOCAL NUMBER(5,0),
  CODCONT NUMBER(20,0),
  TAXBASE NUMBER(22,7),
  TAXVAL NUMBER(22,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SALI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>04A9594224D79B275BD70C81CB79FF4A68F2FEBD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SALI (
  CODSALA NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  CODPERS NUMBER(20,0),
  NUMARMESE NUMBER(5,0),
  CODRESTAURANT NUMBER(20,0),
  CODCATPRET NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SALIUSERI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>26D06EB353849B9215F7AC69DE9FE3B2F1652961</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SALIUSERI (
  COD NUMBER(20,0),
  CODSALA NUMBER(20,0),
  USERNAME VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_CATRET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87808CDAD551D4497A6E9D6A0C3A315F5C86A9D0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_CATRET (
  CODCATRET NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_CATSPOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EE7BE5A7240AFE2956F13F53B95ADEE0F6334DB2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_CATSPOR (
  CODCATSPOR NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_CONTRPP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2DDDBDCF7E1B0440B1ACB3F44B3109EAA9F5A209</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_CONTRPP (
  CODCONTRPP NUMBER(20,0) NOT NULL,
  SUCURSALA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_CONTRPP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B63CE87F78B700D1906E07AE31CF5ABF96220638</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_CONTRPP1 (
  CODCONTRPP1 NUMBER(2,0) NOT NULL,
  CODCONTRPP NUMBER(2,0),
  ANGAJAT NUMBER(20,0),
  NRCONTRACT VARCHAR2(15),
  DATASTART DATE,
  DATASTOP DATE,
  FOND NUMBER(2,0),
  PLATAFIRMA NUMBER(1,0),
  CONTBANCAR VARCHAR2(30),
  MODPLATA NUMBER(2,0),
  RATA NUMBER(2,0),
  ZIPLATA NUMBER(2,0),
  DATAINREG DATE,
  PLAFONLEI NUMBER(2,0),
  PLAFONEURO NUMBER(2,0),
  DIFERENTE NUMBER(2,0),
  VALRATEAN NUMBER(2,0),
  RETNEIMPOZ NUMBER(2,0),
  RETIMPOZ NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_DEDGEN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1458240E3F66ED3BB16080AD2CDC98AEFE1CF2F8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_DEDGEN (
  CODDEDGEN NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  BAZA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_DEDGEN0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CB524138C3682787D63E6970EEEE6B48F18641D6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_DEDGEN0 (
  CODDEDGEN0 NUMBER(20,0),
  CODDEDGEN NUMBER(20,0),
  CONTRACT NUMBER(1,0),
  CONVENTIE NUMBER(1,0),
  CONVENTIECM NUMBER(1,0),
  CUMULS NUMBER(1,0),
  CUMULP NUMBER(1,0),
  SPECIAL NUMBER(1,0),
  SPECIALCV NUMBER(1,0),
  ASIMILATE NUMBER(1,0),
  CALCUL NUMBER(2,0),
  MARIME NUMBER(20,7),
  ROT NUMBER(20,7),
  MODROT NUMBER(2,0),
  COOP NUMBER(1,0),
  INTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_DEDGEN1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B3F40B0A2DE3025AB6CBECA4439814BFC81FE467</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_DEDGEN1 (
  CODDEDGEN1 NUMBER(20,0),
  CODDEDGEN0 NUMBER(20,0),
  CODDEDGEN NUMBER(20,0),
  PERS NUMBER(2,0),
  LIMSUP NUMBER(20,7),
  LIMINF NUMBER(20,7),
  RELATIE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_FONDP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>78C937780CDA8F9A27D7D8F883C5929B862D2570</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_FONDP (
  CODFONDP NUMBER(20,0),
  DENUMIRE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_IMPOZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>12FB61C9040843A5BF153C7226A2C4BCC875BDCF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_IMPOZ (
  CODIMPOZ NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  LUNAR NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_IMPOZ0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>82180D3D379070BB065A4D5A36C6EDF5406106C8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_IMPOZ0 (
  CODIMPOZ0 NUMBER(20,0),
  CODIMPOZ NUMBER(20,0),
  LACONTR NUMBER(1,0),
  LACONV NUMBER(1,0),
  LACONVCM NUMBER(1,0),
  LACUMULSAL NUMBER(1,0),
  LACUMULPENS NUMBER(1,0),
  LASPECIAL NUMBER(1,0),
  LASPECIALCV NUMBER(1,0),
  LAASIMILATE NUMBER(1,0),
  ROT NUMBER(20,0),
  TRUNCHIERE NUMBER(1,0),
  COOP NUMBER(1,0),
  INTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_IMPOZ1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5681FB2ED1562013E06DAA18565EB838DA05EC17</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_IMPOZ1 (
  CODIMPOZ1 NUMBER(20,0),
  CODIMPOZ0 NUMBER(20,0),
  CODIMPOZ NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  VALFIXA NUMBER(20,7),
  PROCENT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NASIG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>13C01601EE99C41EF040DA3479B3C18CA8ABF7BA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NASIG (
  CODNASIG NUMBER(20,0),
  TIP VARCHAR2(50),
  CODASIG NUMBER(20,0),
  CARACTER NUMBER(2,0),
  INTRERUPERE NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NASIG0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B7450E8DE8893EFD715636071D03680E51AD3BD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NASIG0 (
  CODNASIG0 NUMBER(20,0),
  CODNASIG NUMBER(20,0),
  BAZACALCUL NUMBER(6,0),
  ANGAJATOR NUMBER(1,0),
  CONT1 NUMBER(20,0),
  ASIGURARE NUMBER(1,0),
  CONT2 NUMBER(20,0),
  CONTRIBSALMINECFIRMA NUMBER(6,0),
  CONTRIBSALMINECCAS NUMBER(6,0),
  PENALIZARE NUMBER(20,7),
  IMPOZIT NUMBER(1,0),
  CRESTERECOPIL NUMBER(1,0),
  SUSPENDARECM NUMBER(1,0),
  BUGET NUMBER(6,0),
  NOANGAJAT NUMBER(1,0),
  NOANGAJATOR NUMBER(1,0),
  ZILEPLATAFIRMA NUMBER(6,0),
  NEAVIZATCAS NUMBER(1,0),
  PLAFONARE NUMBER(6,0),
  NODEDUCERE NUMBER(1,0),
  CONSTRUCTII NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NASIG1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>482337A6B557BF5E226CEF28F7AB9AC1CDC410D5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NASIG1 (
  CODNASIG1 NUMBER(20,0),
  CODNASIG0 NUMBER(20,0),
  MODCALCUL NUMBER(2,0),
  CONDITIONARE NUMBER(2,0),
  UMV NUMBER(2,0),
  DMODCALC VARCHAR2(50),
  DCOND VARCHAR2(50),
  DUM VARCHAR2(4)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NASIG2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D82B3D62DDC45B02B304586AA896C96EC776A9FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NASIG2 (
  CODNASIG2 NUMBER(20,0),
  CODNASIG0 NUMBER(20,0),
  CODNASIG1 NUMBER(20,0),
  CUANTUM NUMBER(20,7),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NASIG3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6035D8E5B59B2C6DD890B1D1D2B9ED3B33B36918</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NASIG3 (
  CODNASIG3 NUMBER(20,0),
  CODNASIG0 NUMBER(20,0),
  TIP NUMBER(2,0),
  ELEMCALCUL NUMBER(2,0),
  MULTIPLICARE NUMBER(20,7),
  CODCONT NUMBER(20,0),
  CONTRIBUTIE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NCONTRIB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>701A07B22BD75FED6A58966777EFAD7B2D7CED5C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NCONTRIB (
  CODNCONTRIB NUMBER(20,0),
  TIP NUMBER(2,0),
  DENUMIRE VARCHAR2(30),
  TIPCONTRIBUTIE NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NCONTRIB1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>87D54B98E6A9870DC26874001AE576D542ACEF1B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NCONTRIB1 (
  CODNCONTRIB1 NUMBER(20,0),
  CODNCONTRIB NUMBER(20,0),
  MARIME NUMBER(20,7),
  MODCALCUL NUMBER(2,0),
  IMPOZITATCTR NUMBER(1,0),
  CODCONT NUMBER(20,0),
  CODCONTCHELT NUMBER(20,0),
  CODCONTCAS NUMBER(20,0),
  CODCONTAMBP NUMBER(20,0),
  LACONTR NUMBER(1,0),
  LACONV NUMBER(1,0),
  LACONVCM NUMBER(1,0),
  LACUMULSAL NUMBER(1,0),
  LACUMULPENS NUMBER(1,0),
  LAPARTSAL NUMBER(1,0),
  LAPREAVIZ NUMBER(1,0),
  LASPECIAL NUMBER(1,0),
  LASPECIALCV NUMBER(1,0),
  LAASIMILATE NUMBER(1,0),
  GRUPA1 NUMBER(1,0),
  GRUPA2 NUMBER(1,0),
  GRUPA3 NUMBER(1,0),
  GRUPA4 NUMBER(1,0),
  SPECIALCB NUMBER(1,0),
  IMPOZITATCV NUMBER(1,0),
  IMPOZITATCVCM NUMBER(1,0),
  IMPOZITATCS NUMBER(1,0),
  IMPOZITATCP NUMBER(1,0),
  IMPOZITATSPEC NUMBER(1,0),
  IMPOZITATSPECCV NUMBER(1,0),
  IMPOZITATAS NUMBER(1,0),
  VARSTAMIN NUMBER(2,0),
  VENITMIN NUMBER(20,7),
  VENITMAX NUMBER(20,7),
  TIPCONTRACTUAL NUMBER(2,0),
  BUGET NUMBER(2,0),
  TIPLIMITARE NUMBER(2,0),
  REFERINTA NUMBER(2,0),
  MULTIPLIC NUMBER(20,7),
  CONSTRUCTII NUMBER(1,0),
  LACOOP NUMBER(1,0),
  LAINTERNSHIP NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NDREP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3EA3E3DCEF694ECF51881FDC7E5ADC873091D760</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NDREP (
  CODNDREP NUMBER(20,0),
  DENUMIRE VARCHAR2(50),
  TIP NUMBER(2,0),
  MODCALC NUMBER(2,0),
  DATAADAUG DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NDREP0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F1498D0FC0B5D75AAE84FBE3FEC2B03FCE05E158</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NDREP0 (
  CODNDREP0 NUMBER(20,0),
  CODNDREP NUMBER(20,0),
  ART NUMBER(20,0),
  MARIME NUMBER(20,7),
  IMPOZIT NUMBER(1,0),
  DEDUCERI NUMBER(1,0),
  TVA NUMBER(1,0),
  ZIUA NUMBER(20,0),
  GEST NUMBER(20,0),
  CODCONT NUMBER(20,0),
  TOTALCANT NUMBER(20,7),
  TOTALVAL NUMBER(20,7),
  TOTALCUTVA NUMBER(20,7),
  TICHETMASA NUMBER(1,0),
  CODDOC NUMBER(20,0),
  ALTEDEDUCERI NUMBER(1,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ART_DEN VARCHAR2(100),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_NDREP1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0AE11911F94146328AD28EE72531BE752B00ABE4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_NDREP1 (
  CODNDREP1 NUMBER(20,0),
  CODNDREP0 NUMBER(20,0),
  CODNDREP NUMBER(20,0),
  CONTRIB NUMBER(20,0),
  TIP_CONTRIB NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_RETINERI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>33CD281BD57DC9837322E61B6CA3452D501313F8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_RETINERI (
  CODRETINERE NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  CODCATRET NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_RETINERI0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B8373FF575D844C3CF649C9D480157577243ED0B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_RETINERI0 (
  CODRETINERE0 NUMBER(20,0),
  CODRETINERE NUMBER(20,0),
  MARIME NUMBER(20,7),
  MODCALCUL NUMBER(2,0),
  CARACTER NUMBER(2,0),
  CONT NUMBER(2,0),
  TERT NUMBER(20,0),
  NEIMPOZ NUMBER(1,0),
  NRCONTR VARCHAR2(15),
  DATACONTR DATE,
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_SPORURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E37ABD8CCB71520F7147CE85BA31FBB6D3920EF7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_SPORURI (
  CODSPOR NUMBER(20,0),
  DENUMIRE VARCHAR2(30),
  SIMBOL VARCHAR2(7),
  CODCATSPOR NUMBER(20,0),
  SALBAZA NUMBER(1,0),
  NIVELSALBAZA NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_SPORURI0</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EA55286596DA0A9EF8D91AEB5D7ADC7E2533AFA6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_SPORURI0 (
  CODSPOR0 NUMBER(20,0),
  CODSPOR NUMBER(20,0),
  TIP NUMBER(2,0),
  TIPTRANSA NUMBER(2,0),
  TIPCALCSPOR NUMBER(2,0),
  ZILENEMO NUMBER(3,0),
  VALOARE NUMBER(20,7),
  BUGET NUMBER(2,0),
  ITMTIP NUMBER(6,0),
  ITMSPOR NUMBER(6,0),
  TARIFARREFL NUMBER(1,0),
  INTRS VARCHAR2(50),
  INTRC VARCHAR2(50),
  INTRSNS VARCHAR2(50),
  INTRSNC VARCHAR2(50),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_SPORURI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F1735A73A175F2F6C02722F238C08FFE8928D1E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_SPORURI1 (
  CODSPOR1 NUMBER(20,0),
  CODSPOR NUMBER(20,0),
  LIMINF NUMBER(20,7),
  LIMSUP NUMBER(20,7),
  VALSPOR NUMBER(20,7),
  CODSPOR0 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAL_SPORURI2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7EE5F2CDA364D6D123995C36A58D13817FA59C74</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAL_SPORURI2 (
  CODSPOR2 NUMBER(20,0),
  CODSPOR NUMBER(20,0),
  CODSPOREXCLUS NUMBER(20,0),
  CODSPOR0 NUMBER(20,0),
  DENEXCL VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SAPTGANTT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88AD968E57AFD97B5DB966B9779FEA206BEC75B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SAPTGANTT (
  CODLM NUMBER(20,0),
  Z1 NUMBER(7,3),
  Z2 NUMBER(7,3),
  Z3 NUMBER(7,3),
  Z4 NUMBER(7,3),
  Z5 NUMBER(7,3),
  Z6 NUMBER(7,3),
  Z7 NUMBER(7,3),
  AN NUMBER(7,3),
  LUNA NUMBER(2,0),
  SAPT NUMBER,
  DATA1 DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCADCL_COEFG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A39FED003690A8D06A0269E35FCEDA74E92DD33D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCADCL_COEFG (
  CODOBLIGPIF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  COEF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCADENTARCL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B1C338E72B3649391F09117B036FC9078C29BA25</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCADENTARCL (
  CODOBLIGPIF NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  NRI VARCHAR2(50),
  BLOCAT NUMBER(1,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  RESTVAL NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  MAJORARE NUMBER(20,7),
  ZILE_TRECUTE NUMBER(20,0),
  ZILE_DEPASIRE NUMBER(20,0),
  CONT NUMBER(20,0),
  ADAOSDOC NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CURSINI NUMBER(20,7),
  OBS VARCHAR2(500),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  SUBUNITATEA NUMBER(20,0),
  AGENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  CODGENERAL NUMBER(20,0),
  COEFPROVIZION NUMBER(20,7),
  EXCLUSPLATA NUMBER(1,0),
  CURS NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  USERID NUMBER(20,0),
  TVAMEDIU NUMBER(20,7),
  TVAINCASARE NUMBER(1,0),
  ANSAPT NUMBER(6,0),
  CODDOC1 NUMBER(20,0),
  CODTIPPARTINCERT NUMBER(20,0),
  LEG_DOC VARCHAR2(30),
  LEG_NRDOC NUMBER(20,0),
  LEG_DATADOC DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCADENTARF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C6F53F5167E04CAA21D40B48BC9FC514E11581F3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCADENTARF (
  CODOBLIGPIF NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODPART NUMBER(20,0),
  DOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  NRI VARCHAR2(30),
  BLOCAT NUMBER(1,0),
  TERMEN DATE,
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  RESTVAL NUMBER(20,7),
  RESTSPLITTVA NUMBER(20,7),
  RESTTVA NUMBER(20,7),
  MAJORARE NUMBER(20,7),
  ZILE_TRECUTE NUMBER(20,0),
  ZILE_DEPASIRE NUMBER(20,0),
  CONT NUMBER(20,0),
  ADAOSDOC NUMBER(20,7),
  MONEDA NUMBER(20,0),
  CURSINI NUMBER(20,7),
  OBS VARCHAR2(500),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  SUBUNITATEA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  AGENT NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  CODGENERAL NUMBER(20,0),
  EXCLUSPLATA NUMBER(1,0),
  CURS NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  USERID NUMBER(20,0),
  TVAMEDIU NUMBER(20,7),
  TVAINCASARE NUMBER(1,0),
  SPLITTVA NUMBER(1,0),
  ANSAPT NUMBER(6,0),
  CODDOC1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCADENTARST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>60D1B5676DB2B308DC86DF306CA85D0860D26CFD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCADENTARST (
  CODSTINSPIF NUMBER(20,0),
  VALOARE NUMBER(20,0),
  TVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCADF_COEFG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F75CD869D09556CDD219E8B3AC1CFC635E21BD50</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCADF_COEFG (
  CODOBLIGPIF NUMBER(20,0),
  CODGEST NUMBER(20,0),
  COEF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCENARIILIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0A8A52D026451ED3775BE66F29617375E76CCEB1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCENARIILIVR (
  CODSCENARIU NUMBER(20,0),
  DEN_SCENARIU VARCHAR2(50),
  CODTRASEU NUMBER(20,0),
  TIP NUMBER(1,0),
  OBS VARCHAR2(200),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DEFINITIV NUMBER(1,0),
  DSTART DATE,
  DEND DATE,
  TIPDATA NUMBER(1,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  TMASA NUMBER(20,7),
  TVOLUM NUMBER(20,7),
  DMASA NUMBER(20,7),
  DVOLUM NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCENARIILIVR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F4E3E8C191C97C5F244ABAA211AC8649988883A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCENARIILIVR1 (
  CODSCENARIU1 NUMBER(20,0),
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CANT NUMBER(30,17),
  LANS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCENARIILIVR2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD4964D78EA310E254EF3613E1BF6ABFB4F44FA9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCENARIILIVR2 (
  CODSCENARIU2 NUMBER(20,0),
  CODSCENARIU NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  DATASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCHEDULER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67FD93FCA7F3D6177FDFAA5C693DC5648C0F4A30</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCHEDULER (
  CODJOB1 NUMBER(20,0),
  JOB_ACTION VARCHAR2(4000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SCHIMBURI_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>AB541B32FF01D9B9B6EA7BF3E2158389A1BB03B1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SCHIMBURI_MAN (
  CODGEST NUMBER(20,0),
  SCHIMB NUMBER(5,0),
  SCHIMBS VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SELARTOFE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D8C8D3364B16ECF54FA9600C32366C9E4068091A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SELARTOFE (
  CODOFERTA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SEMNIFICATII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0A9BFBEAAEDAC8E3AFE4F9DDA41E48B1E9BE9DE0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SEMNIFICATII (
  DEBIT NUMBER(10,0),
  CREDIT NUMBER(10,0),
  ALIAS VARCHAR2(100),
  SEMN NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SERIALIZARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1977309434FD7CBE91C53F8B2CB2535D866A20E1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SERIALIZARI (
  COD NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODSERIELOT NUMBER(20,0),
  DATAEXP VARCHAR2(10),
  SERIE VARCHAR2(75),
  GTIN VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SERVFACT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4AAE4CD7FCF7EC963EA1892DA51F6626D20CB7C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SERVFACT (
  CODSERVFACT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODOBIECT NUMBER(20,0),
  MODCALCUL NUMBER(5,0),
  SUMAPORNIREKM NUMBER(20,7),
  SUMAPORNIRECANT NUMBER(20,7),
  PROCPORNIREKM NUMBER(20,7),
  PROCPORNIRECANT NUMBER(20,7),
  COD VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SERVFACT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2F575A54ADCB3EB79DAD6C917728FAB93FA8B3E1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SERVFACT1 (
  CODSERVFACT1 NUMBER(20,0),
  CODSERVFACT NUMBER(20,0),
  PANALA NUMBER(20,7),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SERVPOST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FBFDD07EDFA6B7E9930A4188661CFDA1D5315226</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SERVPOST (
  CODSERVICIU NUMBER(20,0),
  DENSERVICIU VARCHAR2(160),
  CODOBIECT NUMBER(20,0),
  TARIF NUMBER(20,4),
  DENUMIRE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETGROUPS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>16D125C997E8DAEDA2D17255FA5D54B81FDB7C69</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETGROUPS (
  CODSETUSERS NUMBER(20,0),
  CODSET NUMBER(20,0),
  CODUSER NUMBER(20,0),
  USERNAME VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETLISTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD631FD3F7156992C06DA1C972ED6FF8FDEAB223</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETLISTE (
  CODSET NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  DEDICAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETTASK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>937EEF98A4ACE3E1F58B315A8FF8919DBB529B59</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETTASK (
  CODTASK NUMBER(20,0),
  PROBLEMA VARCHAR2(4000),
  DESTINATAR VARCHAR2(30),
  EXECUTANT VARCHAR2(30),
  USERNAME VARCHAR2(30),
  TERMEN DATE,
  DATATASK DATE,
  DATAREZ DATE,
  DOMENIU VARCHAR2(50),
  TIP VARCHAR2(50),
  REZOLVARE VARCHAR2(4000),
  OBSERVATII VARCHAR2(4000),
  PRIORITATE NUMBER(6,0),
  DONE NUMBER(1,0),
  MODIFICAT NUMBER(1,0),
  MESAJCATRE VARCHAR2(30),
  STERS NUMBER(1,0),
  PROIECT VARCHAR2(50),
  DOMSG NUMBER(1,0),
  CODMSG1 NUMBER(20,0),
  DOMAIL NUMBER(1,0),
  CODMAIL NUMBER(20,0),
  ZBEFORE NUMBER(2,0),
  CODFIRMA NUMBER(20,0),
  CODPART NUMBER(20,0),
  FACTURABIL NUMBER(1,0),
  FACTURAT NUMBER(1,0),
  VALOARE NUMBER(20,2),
  CODMONEDA NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODFACTURA NUMBER(20,0),
  CODOFERTA NUMBER(20,0),
  CODPERS NUMBER(20,0),
  CODSERVICIU NUMBER(20,0),
  CODCONTRACT1 NUMBER(20,0),
  VERSIUNE NUMBER(7,3),
  PREFIXDOC VARCHAR2(5),
  NRDOC NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  ARTICOLASOCIAT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  COMANDA VARCHAR2(100),
  FACTURA VARCHAR2(100),
  OFERTA VARCHAR2(100),
  FIRMA VARCHAR2(50),
  CONTRACT VARCHAR2(100),
  CODOBIECT NUMBER(20,0),
  ORATASK VARCHAR2(5),
  ORAREZ VARCHAR2(5),
  DENASOCIAT VARCHAR2(250),
  CODLINK NUMBER(20,0),
  TIPLINK NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETTASK1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3F312BFE6DD8D0500EF1A2929A415C8608976D95</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETTASK1 (
  CODTASK1 NUMBER(20,0),
  CODTASK NUMBER(20,0),
  MESAJCATRE VARCHAR2(30),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETTASKOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>64D217E1311DCC9256F1FBD5DEB290C88D671950</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETTASKOBJ (
  CODTASKOBJ NUMBER(20,0),
  CODTASK NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  NEPRELUABIL NUMBER(1,0),
  PRET NUMBER(20,7),
  CODPERS NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DEN_OBIECT VARCHAR2(250),
  PERSOANA VARCHAR2(400),
  VALOARE NUMBER(20,7),
  DEN_UM VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETTASKOBJASOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5BF3BD01C4DDA999FFA27B72605D83C102B219AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETTASKOBJASOC (
  CODTASKOBJASOC NUMBER(20,0) NOT NULL,
  CODTASK NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  SERII VARCHAR2(2500),
  CODINTERN VARCHAR2(250),
  CODIES1 NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  DENUMIRE VARCHAR2(250)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SETUSERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FDAA81FBCAF971FD4ACED1C94AFE2774B9915F8C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SETUSERS (
  CODSETUSERS NUMBER(20,0),
  CODSET NUMBER(20,0),
  CODUSER NUMBER(20,0),
  USERNAME VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SGRCOLECT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4E2E7D435BD2809542A9030F798247B025BB1316</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SGRCOLECT (
  CODSGRCOLECT NUMBER(20,0),
  DATA DATE,
  VALOARE NUMBER(20,7),
  DATACREARE TIMESTAMP(6),
  CODMARIRE NUMBER(20,0),
  VOUCHERBARCODE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SGRCOLECT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B371A4A1E1D602285B3914D7B3880F725AEEA44</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SGRCOLECT1 (
  CODSGRCOLECT1 NUMBER(20,0),
  CODSGRCOLECT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PRET NUMBER(10,2),
  CANT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  VALOARE NUMBER(10,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SIM_CCOM1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD85C38D9702C488DB42161D86127F1674E61325</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SIM_CCOM1 (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  TIPCOMANDA NUMBER(2,0),
  TERMEN DATE,
  CODCLIENT NUMBER(20,0),
  DEN_CLIENT VARCHAR2(100),
  TRASEU VARCHAR2(80),
  POZTRASEU NUMBER(4,0),
  CODTARA NUMBER(20,0),
  DEN_TARA VARCHAR2(30),
  CODZONA NUMBER(20,0),
  DEN_ZONA VARCHAR2(50),
  CODLOCALIT NUMBER(20,0),
  DEN_LOCALIT VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  CODEXTERN VARCHAR2(80),
  UMSEC NUMBER(20,0),
  UM VARCHAR2(15),
  CODGRUPA NUMBER(20,0),
  PARITATEGRUPA NUMBER(20,7),
  GRUPAE VARCHAR2(100),
  OBJGENERIC VARCHAR2(200),
  MASAO NUMBER(20,7),
  VOLUMO NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  VERSIUNE VARCHAR2(100),
  DENMAT VARCHAR2(200),
  HTAG VARCHAR2(500),
  CANTACCEPTAT NUMBER(20,7),
  STOCREZERVAT NUMBER(20,7),
  SCENDEFINITIVE NUMBER(20,7),
  ALTESCENARII NUMBER(20,7),
  REST NUMBER(20,7),
  DEREZOLVAT NUMBER(20,7),
  LANSSCENARIU NUMBER(20,7),
  LANSAT NUMBER(20,7),
  ACTIV NUMBER(2,0),
  TIPCLIENT VARCHAR2(100),
  OK NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SIM_LANS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>30309C095260A89B426E321C7E773F9AD688A575</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SIM_LANS (
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CANT NUMBER(20,7),
  CODPROIECT NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODLANSARE NUMBER(20,0),
  OK NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SIM_LANS1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6D0DBBC9B4821B7A28816876920990A895BF16A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SIM_LANS1 (
  CODCOMANDA1 NUMBER(20,0),
  DENUMIRE VARCHAR2(260),
  CODOBIECT NUMBER(20,0),
  PREF VARCHAR2(50),
  NIVEL NUMBER(10,0),
  POZITIE NUMBER(10,0),
  CODPROIECTNOD NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  TIP NUMBER(1,0),
  NECESARP NUMBER(20,7),
  NECESAR NUMBER(20,7),
  REZERVAT NUMBER(20,7),
  NESOSIT NUMBER(20,7),
  CERERE NUMBER(20,7),
  STOC NUMBER(20,7),
  CMDINT NUMBER(20,7),
  DIFERENTE NUMBER(20,7),
  ZECIMALE NUMBER(3,0),
  UMSEC NUMBER(20,0),
  DEN_UM VARCHAR2(15),
  MATECHIV NUMBER(20,0),
  CODEXTERN VARCHAR2(80),
  DATASTART DATE,
  DATASTARTCMDINT DATE,
  CODCOMANDA1I NUMBER(20,0),
  INDEXPARINTE VARCHAR2(50),
  REZOLVAT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SIM_NODECHIV1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DB00F43B7D681FB77E75E01BE1EA57A49017D7A6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SIM_NODECHIV1 (
  CODCOMANDA1 NUMBER(20,0),
  CODPROIECTNOD NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PARITATE NUMBER(20,7),
  TIP NUMBER(1,0),
  CODTIP NUMBER(20,0),
  CODOBIECTORIG NUMBER(20,0),
  NODORIGINAL NUMBER(20,0),
  CODATRIB NUMBER(20,0),
  STOC NUMBER(20,7),
  CANTECHIVALATA NUMBER(20,7),
  DENOBIECTECHIV VARCHAR2(200),
  CODEXTERN VARCHAR2(80)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFIN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>719C40B9F9D8AD28E36E3001C16BDCDAB4734178</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFIN (
  CODSITFIN NUMBER(20,0),
  CODF VARCHAR2(10),
  DENUMIRE VARCHAR2(100),
  SECTIUNE VARCHAR2(50),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  TIP NUMBER(1,0),
  TIPPLAN NUMBER(1,0),
  PELUNI NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFINALTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F6200D9C56396F9F6BD26B17D980F5AF1FA54348</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFINALTE (
  CODALTE NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  FUNCTIE VARCHAR2(250),
  RAND NUMBER(10,0),
  COLOANA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFINBUGET</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>431637796263C97661AC4CF22D138A308F86838F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFINBUGET (
  CODSITFINBUGET NUMBER(20,0),
  CODSITFINLIN NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFINCOL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>35ED9B33FBECDE1FF3581A2CFDB5C03D29653FFA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFINCOL (
  CODCOLOANA NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  NRCOL NUMBER(10,0),
  DENUMIRE VARCHAR2(100),
  TIPCOL NUMBER(5,0),
  CORELATIE VARCHAR2(100),
  IDENTIFICATORCOL VARCHAR2(10),
  FLGEXPORT NUMBER(1,0),
  CONTA NUMBER(10,0),
  DENTIPCOL VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFINLIN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C747D4FAA0F4E6736AA500DE9BA06A0B1B79A9AE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFINLIN (
  CODLINIE NUMBER(20,0),
  CODSITFIN NUMBER(20,0),
  NRLINIE NUMBER(10,0),
  DENUMIRE VARCHAR2(250),
  TOTAL NUMBER(1,0),
  CORELATIE VARCHAR2(1500),
  RND NUMBER(10,0),
  TIPCONTA NUMBER(5,0),
  OBS VARCHAR2(250),
  VALSUPLIM NUMBER(20,7),
  FARANEGATIVE NUMBER(1,0),
  CORSIMB VARCHAR2(3000),
  DENTOTAL VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SITFINSEC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>72B61C1D3D9ADC1369C69EEA95E603536F0E0196</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SITFINSEC (
  CODSITFIN NUMBER(20,0),
  CODF VARCHAR2(10),
  DENUMIRE VARCHAR2(100),
  SECTIUNE VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDCASHFLOW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>042B93DA59666E32D38AB5E0A47FDE20FD677691</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDCASHFLOW (
  CODSOLD NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  SOLD NUMBER(20,7),
  SOLDCONV NUMBER(20,7),
  SIMBOLBANCA VARCHAR2(30),
  NRCONT VARCHAR2(30),
  SIMBOLMONEDA VARCHAR2(10)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D0B4FDE4076657EE6364E85CA241D8D92CD08F50</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDINI (
  CODSOLDINI NUMBER(20,0),
  CODPART NUMBER(20,0),
  SOLDREAL NUMBER(20,7),
  VOLUMTRANZC NUMBER(20,7),
  VOLUMTRANZF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDPART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8C6A8C6B7FC24CAEA71550FCB610035B3681E742</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDPART (
  CODSOLDPART NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODCONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,3),
  SOLDVALUTA NUMBER(20,3),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDPERS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EAA112AC7CD962512423CF9158838151063DCE04</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDPERS (
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SOLDLEI NUMBER(20,7),
  SOLDVALUTA NUMBER(20,7),
  SEMN NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDPERSINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>714C4ED99D5265DE7C5CD8C04DDB2E1C16E71099</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDPERSINI (
  CODSOLDPERSINI NUMBER(20,0),
  CODPERS NUMBER(20,0),
  SOLDTOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SOLDPERS_SUB</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>828237205F7FF5CCE7FC7E8C35AEB0B9354D6949</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SOLDPERS_SUB (
  CODPERS NUMBER(20,0),
  ICONT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  SOLDLEI NUMBER(20,7),
  SOLDVALUTA NUMBER(20,7),
  SEMN NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SPLITCHELT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FFB2E01DD3D5C6048515F4087209980C1EEFE550</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SPLITCHELT (
  CODSPLITCHELT NUMBER(20,0),
  TIPDOC NUMBER(2,0),
  CODOBIECT NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  ACTIV NUMBER(1,0),
  CODCONT NUMBER(20,0),
  FAZA NUMBER(1,0),
  CODANALIZA NUMBER(20,0),
  DEN_OBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SPLITCHELT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>67D8FC0904E52DAB645785016DF461551C93ECBD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SPLITCHELT1 (
  CODSPLITCHELT1 NUMBER(20,0),
  CODSPLITCHELT NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODGEST NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  OBS VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  PROCENT NUMBER(20,7),
  CODANALIZANOD NUMBER(20,0),
  CODFORMATIE NUMBER(20,0),
  PUNCTE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SPVARHIVA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7635B385A435DF6D28E917DD5276F3C2AAA1D7AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SPVARHIVA (
  CODSPVARHIVA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  ZIP BLOB,
  TIPDOC NUMBER(3,0),
  ID_DS VARCHAR2(20),
  CIF VARCHAR2(30),
  CODDOCWME NUMBER(20,0),
  DATADOCSPV DATE,
  CIF_PARTENER VARCHAR2(75),
  VAL_DOC_SPV NUMBER(20,7),
  TVA_DOC_SPV NUMBER(20,7),
  ID_DOC_SPV VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STAREESTIMARI1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D4352AA8EC43827A6FD7E432E373E0333B0503E4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STAREESTIMARI1 (
  CODSTARE NUMBER(20,0),
  CODSTARE1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  STOCMIN NUMBER(20,7),
  STOCINI NUMBER(20,7),
  STOCPREC NUMBER(20,7),
  ESTIMARI NUMBER(20,7),
  CMDF NUMBER(20,7),
  NECESAR NUMBER(20,7),
  STOCFINAL NUMBER(20,7),
  PRET NUMBER(20,7),
  STOCVAL NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CMDFP NUMBER(20,7),
  RESTPRECMD NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  NECESARACC NUMBER(20,7),
  RESTPRECMDA NUMBER(20,7),
  RESTNECESAR NUMBER(20,7),
  CMDFTS NUMBER(20,7),
  PART1NEC NUMBER(20,7),
  DIRTY NUMBER(10,0),
  ACCEPTATTS NUMBER(20,7),
  STOCDC NUMBER(20,7),
  UMSEC NUMBER(20,0),
  UM1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  NECESARUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  DEN_UMSEC VARCHAR2(50),
  DEN_UM1 VARCHAR2(50),
  DIRTYCMDF NUMBER(10,0),
  BLOCAT NUMBER(10,0),
  BLOCAT1 NUMBER(10,0),
  VALNECESAR NUMBER(20,0),
  CONSUM NUMBER(20,7),
  MODIFICAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STAREESTIMARI1_CENTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4FF5076316A77ED398FB1CBF3CFFF326702BCD2</HASHVAL>
  <TEXT>CREATE TABLE TMP_STAREESTIMARI1_CENTR (
  CODSTARE NUMBER(20,0),
  CODSTARE1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  STOCMIN NUMBER(20,7),
  STOCINI NUMBER(20,7),
  STOCPREC NUMBER(20,7),
  ESTIMARI NUMBER(20,7),
  CMDF NUMBER(20,7),
  NECESAR NUMBER(20,7),
  STOCFINAL NUMBER(20,7),
  PRET NUMBER(20,7),
  STOCVAL NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  CMDFP NUMBER(20,7),
  RESTPRECMD NUMBER(20,7),
  INDEXLOCAL NUMBER(10,0),
  NECESARACC NUMBER(20,7),
  RESTPRECMDA NUMBER(20,7),
  RESTNECESAR NUMBER(20,7),
  CMDFTS NUMBER(20,7),
  ACCEPTATTS NUMBER(20,7),
  STOCDC NUMBER(20,7),
  UMSEC NUMBER(20,0),
  UM1 NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  NECESARUM1 NUMBER(20,7),
  RELATIEUM1 NUMBER(2,0),
  DEN_UMSEC VARCHAR2(50),
  DEN_UM1 VARCHAR2(50),
  VALNECESAR NUMBER(20,0),
  CONSUM NUMBER(20,7),
  AN NUMBER(4,0),
  SAPTAMANA NUMBER(2,0),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STATCON</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>156D59275E6F3ADD2981A9770BA0861AA2CE5760</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STATCON (
  CODSTATCON NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  ATRIBUT NUMBER(1,0),
  DEN_EVALUARE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STATCOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E944B80CEB375374981A23F899390CBE78AFD79</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STATCOR (
  CODSTATCOR NUMBER(20,0),
  CODEVALS NUMBER(20,0),
  ATRIBUT NUMBER(1,0),
  DEN_EVALUARE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STATCOR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B52B053E1D9CE1B9A4D89CB3EAA388F49B04F732</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STATCOR1 (
  CODSTATCOR1 NUMBER(20,0),
  CODSTATCOR NUMBER(20,0),
  CODTESATURA NUMBER(20,0),
  VALOARE NUMBER(10,8),
  AI NUMBER(2,1),
  RII NUMBER(2,1)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STATUSDECL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E36634BEFCB857BF885EC0F2492DCFB352D33B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STATUSDECL (
  CODSTATUSDECL NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  IDINCARCARE VARCHAR2(20),
  IDDESCARCARE VARCHAR2(20),
  DATAINCARCARE TIMESTAMP(6),
  STARE VARCHAR2(20),
  TIPMEDIU NUMBER(1,0),
  USERNAME VARCHAR2(20),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  COMPNAME VARCHAR2(20),
  FILENAME VARCHAR2(250),
  MESAJE CLOB,
  CIF VARCHAR2(20),
  SERIE_CERTIF VARCHAR2(250),
  UIT VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STINGERE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5CD076B523EF65A90B7A8533E7C2DFC97E4808FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STINGERE (
  CODSTINGERE NUMBER(20,0),
  CODSTINSPIF NUMBER(20,0),
  CODSTINGATORPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPLATA1 NUMBER(20,0),
  VALTRANZF NUMBER(20,7),
  VALTRANZC NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODSUBUNITSTINS NUMBER(20,0),
  TIPDOCPLATI NUMBER(2,0),
  PROCSTOPAJ NUMBER(5,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STINGERETVA_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>093058660C3C7C15D113B0A709528697D543F2D2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STINGERETVA_LUNA (
  CODOBLIGPIF NUMBER(20,0),
  BEFORESPLIT NUMBER(20,7),
  AFTERSPLIT NUMBER(20,7),
  VALOBLIG NUMBER(20,7),
  TVAOBLIG NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STINGERE_ASOCIAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2BE92F77803848C3C595F5D8B532FDFC592EDF74</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STINGERE_ASOCIAT (
  CODSTINGERE NUMBER(20,0),
  CODSTINSPIF NUMBER(20,0),
  CODSTINGATORPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPLATA1 NUMBER(20,0),
  VALTRANZF NUMBER(20,7),
  VALTRANZC NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODSUBUNITSTINS NUMBER(20,0),
  TIPDOCPLATI NUMBER(2,0),
  PROCSTOPAJ NUMBER(5,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STINGERE_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E8DE72C3AF131EE92D6580F9BF7AF05DAF5E4BCC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STINGERE_INITIAL (
  CODSTINGERE NUMBER(20,0),
  CODSTINSPIF NUMBER(20,0),
  CODSTINGATORPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPLATA1 NUMBER(20,0),
  VALTRANZF NUMBER(20,7),
  VALTRANZC NUMBER(20,7),
  DINCARETVA NUMBER(20,7),
  CODSUBUNITSTINS NUMBER(20,0),
  TIPDOCPLATI NUMBER(2,0),
  PROCSTOPAJ NUMBER(5,2)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STINGERE_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BA43795DFCAC45739B20F62762C8F8CB5F46443D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STINGERE_LUNA (
  CODSTINSPIF NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DINCARETVA NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCEXTERN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>06B21A2BBC93F3B31ACD1DA0A1F82910F0FF2700</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCEXTERN (
  CODCOMUN VARCHAR2(100),
  STOC NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>423E0CF34B88D82AC2E6C1EE96017B81097891F2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCINI (
  CODSTOCINI NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODPERS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCINIART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>157050DB38DC004F407F811E3A9E31B57207B340</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCINIART (
  CODOBIECT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCLOCK_BULK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7EC322AAAA09E1D1B57447248FE3048F878D6F47</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCLOCK_BULK (
  USERID NUMBER(20,0),
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCPOSURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E3671847757070B4716B0350915E956E1E80B6A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCPOSURI (
  CODSTOCPOS NUMBER(20,0),
  CODPOS NUMBER(20,0),
  TIPPOS NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODIOART NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  CODDEP NUMBER(3,0),
  PLU NUMBER(20,0),
  PRETNOU NUMBER(20,7),
  STOC NUMBER(20,7),
  BARCODE VARCHAR2(30),
  DENOBIECT VARCHAR2(200),
  MODIFICARI NUMBER(1,0),
  PRETART NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  CANTARIBIL NUMBER(1,0),
  SERVICIU NUMBER(1,0),
  DEN_UM VARCHAR2(15),
  UMSEC NUMBER(20,0),
  PROCTVA NUMBER(20,7),
  CODTVA NUMBER(20,0),
  PRETUPDATED NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  SIMBOLCONTSERV VARCHAR2(30),
  SIMBOLGEST VARCHAR2(15),
  DEN_GEST VARCHAR2(100),
  VIZIBIL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCREAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EA7F0E226E062ADA2246D2127A052CC4F4A52E5F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCREAL (
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  TIP VARCHAR2(20),
  CODGEST NUMBER(20,0),
  CANTUM1 NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCREAL_NEC5</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>726CA07D5D9DCC013D041E23C9EC0BF5C0E9A5AE</HASHVAL>
  <TEXT>CREATE TABLE TMP_STOCREAL_NEC5 (
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  TIP VARCHAR2(20),
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCREZ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F5BBCEC5D3FD3318A00269D783780F58F246CBCC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCREZ (
  CODOBIECT NUMBER(20,0),
  REZERVAT NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CODGEST NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCVALINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>39D7C90EEFE0EE801E136D06EC04C3A97D3AD691</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCVALINI (
  CODSTOCVALINI NUMBER(20,0),
  GEST NUMBER(20,0),
  SOLDTOTAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOCVALLUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8B8F29E0D34C700649E5728AE5F2835F33F2461C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOCVALLUNA (
  CODSTOCVALLUNA NUMBER(20,0),
  GEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  TVA NUMBER(20,7),
  SOLD NUMBER(20,7),
  ADAOS NUMBER(20,7),
  SOLDINTR NUMBER(20,7),
  ADAOSINTR NUMBER(20,7),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  VALACHIZ NUMBER(20,7),
  DIFPRET NUMBER(1,0),
  ARETVANEEX NUMBER(1,0),
  MG NUMBER(1,0),
  PUSTANDARD NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOC_DATA_GEST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B59BCCF0924712FBCB5B04892F342DF3B8C50E85</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOC_DATA_GEST (
  CODGEST NUMBER(20,0),
  CODIOART NUMBER(20,0),
  VALOARE NUMBER(20,7),
  DATASTOC DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOC_MOMENT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1E18CB6F3AD5BF9A9D0472E6CCE7765C53682C1D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOC_MOMENT (
  DATASTOC DATE,
  CODNIRSTOC NUMBER(20,0),
  CODNIRSER NUMBER(20,0),
  REST NUMBER(20,7),
  RESTUM1 NUMBER(20,7),
  RESTUM2 NUMBER(20,7),
  CODIOART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  UMSEC NUMBER(20,0),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STOPAJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5353404987FFD8C97B9B5E64C99E84B0C64ADC53</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STOPAJ (
  NUME VARCHAR2(50),
  PRENUME VARCHAR2(50),
  CNP VARCHAR2(15),
  DATAANG DATE,
  DATASF DATE,
  CASASN VARCHAR2(2),
  TIPASIG NUMBER(2,0),
  BAZACASS NUMBER(20,7),
  BNETCASS NUMBER(20,7),
  CONTRCASS NUMBER(20,7),
  BAZAIMPOZIT NUMBER(20,7),
  BNETIMPOZIT NUMBER(20,7),
  IMPOZIT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STORNOCMDF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>896C93FF1796E875147FF0E385D61080AA81604F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STORNOCMDF (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STORNOCMDF_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E2D864ADE1E483E7D3B8EFE50A99717A506F1E2B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STORNOCMDF_INI (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CODINTR1 NUMBER(20,0),
  CANT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STRUCTURAANAF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>24A2B8DD6C2335EC1D02EAE6DBE29DD97A3CB4E8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_STRUCTURAANAF (
  CUI NUMBER(20,0),
  DATA DATE,
  STARE NUMBER(1,0),
  CONTRIBUABIL NUMBER(2,0),
  DENUMIRE VARCHAR2(100),
  ADRESA VARCHAR2(500),
  LOCALITATE VARCHAR2(50),
  JUDET VARCHAR2(30),
  STRADA VARCHAR2(100),
  BLOC VARCHAR2(30),
  SCARA VARCHAR2(5),
  NUMAR1 NUMBER(20,0),
  NUMAR2 VARCHAR2(10),
  ETAJ VARCHAR2(10),
  APART VARCHAR2(10),
  NRREGCOM VARCHAR2(30),
  SPLITTVA NUMBER(1,0),
  RTVAI NUMBER(1,0),
  STAREINREG VARCHAR2(100),
  STAREINACTIV VARCHAR2(100),
  MESAJ VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>586218F2308BE7B042FE132144A02917CD6534CB</HASHVAL>
  <TEXT>CREATE TABLE TMP_STT (
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODBANKCONT NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  DATADOC DATE,
  CARNETDOC NUMBER(20,0),
  SERIEDOC VARCHAR2(20),
  NRDOC NUMBER(20,0),
  DOCUMENT VARCHAR2(100),
  CURSDOC NUMBER(20,7),
  INCASARI NUMBER(20,7),
  PLATI NUMBER(20,7),
  SOLDIN NUMBER(20,7),
  INCASARILEI NUMBER(20,7),
  PLATILEI NUMBER(20,7),
  SOLDINLEI NUMBER(20,7),
  EXPLICATII VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STTREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>16127F6D4FE32D283F80ED8CE273D4721510D69D</HASHVAL>
  <TEXT>CREATE TABLE TMP_STTREG (
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODMONEDA NUMBER(20,0),
  CURS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_STTSOLDDOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4FFA4B20754CE0A990EB71EF4C4AAF2EA1CC9AEE</HASHVAL>
  <TEXT>CREATE TABLE TMP_STTSOLDDOC (
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CODBANKCONT NUMBER(20,0),
  DATADOC DATE,
  SOLDIN NUMBER(20,7),
  SOLDINLEI NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_CUS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5C1ECE0208AD91D63C93BE4CF13F568CFA8861CE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_CUS (
  CODPART NUMBER(20,0),
  COMP_CODE VARCHAR2(200),
  SALESORG VARCHAR2(200),
  DISTR_CHAN VARCHAR2(200),
  DIVISION VARCHAR2(200),
  CUSTOMERF VARCHAR2(200),
  CUSTOMER VARCHAR2(200),
  COUNTRY VARCHAR2(200),
  ZATTRIB1 VARCHAR2(200),
  ZKDKG1 VARCHAR2(200),
  ZCLIEHIER1 VARCHAR2(200),
  ZCLIEHIER2 VARCHAR2(200),
  ZCLIEHIER3 VARCHAR2(200),
  SALES_OFF VARCHAR2(200),
  SALES_GRP VARCHAR2(200),
  SALES_DIST VARCHAR2(200),
  CUST_GROUP VARCHAR2(200),
  PRICE_GRP VARCHAR2(200),
  PRICE_LIST VARCHAR2(200),
  CUST_GRP1 VARCHAR2(200),
  CUST_GRP2 VARCHAR2(200),
  CUST_GRP3 VARCHAR2(200),
  CUST_GRP4 VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_INV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C5476DCB37176565605916C379A468994E075E4F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_INV (
  CODIES NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPART NUMBER(20,0),
  COMP_CODE VARCHAR2(200),
  SALESORG VARCHAR2(200),
  DISTR_CHAN VARCHAR2(200),
  DIVISION VARCHAR2(200),
  BILL_NUM VARCHAR2(200),
  SOLD_TO VARCHAR2(200),
  BILL_TYPE VARCHAR2(200),
  DOC_CATEG_INV VARCHAR2(200),
  BILL_DATE VARCHAR2(200),
  DOC_CURRCY VARCHAR2(200),
  LOC_CURRCY VARCHAR2(200),
  PAYER VARCHAR2(200),
  BILL_ITEM VARCHAR2(200),
  ITEM_CATEG_INV VARCHAR2(200),
  MATERIAL VARCHAR2(200),
  BILLTOPRTY VARCHAR2(200),
  SHIP_TO VARCHAR2(200),
  INV_QTY VARCHAR2(200),
  SALES_UNIT VARCHAR2(200),
  NETVAL_INV VARCHAR2(200),
  ZNET_VAL VARCHAR2(200),
  COST VARCHAR2(200),
  ZCOST VARCHAR2(200),
  CO_AREA VARCHAR2(200),
  PLANT VARCHAR2(200),
  DOC_NUMBER VARCHAR2(200),
  S_ORD_ITEM VARCHAR2(200),
  DOC_TYPE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_MAT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FA11D071216CA37D3DC1871A076C244A7DDB2B0A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_MAT (
  CODOBIECT NUMBER(20,0),
  PLANT VARCHAR2(200),
  SALESORG VARCHAR2(200),
  DISTR_CHAN VARCHAR2(200),
  MATERIAL VARCHAR2(200),
  MAKTX VARCHAR2(200),
  F VARCHAR2(200),
  ZMMSTA VARCHAR2(200),
  ZNBSPCB VARCHAR2(200),
  ZNBPCB VARCHAR2(200),
  ZNBBOX VARCHAR2(200),
  ZNBPAL VARCHAR2(200),
  MRP_CONTRL VARCHAR2(200),
  MAT_KONDM VARCHAR2(200),
  ZMTPOS VARCHAR2(200),
  MAT_STGRP VARCHAR2(200),
  MATL_GRP_4 VARCHAR2(200),
  ZVPRSV VARCHAR2(200),
  VAL_CLASS VARCHAR2(200),
  ZVERPR VARCHAR2(200),
  ZSTPRS VARCHAR2(200),
  CURRENCY VARCHAR2(200),
  VOLUMEUNIT VARCHAR2(200),
  ZVOLPCB VARCHAR2(200),
  MAT_TYPE VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_NSG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0672A2A69754DC41DD0E78E57650F4C43E3CD084</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_NSG (
  CODOBIECT NUMBER(20,0),
  VAL NUMBER(20,7),
  QTY NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_ORD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B3D9EB2DC28B71CE567B2577777A31925D34B0A8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_ORD (
  CODCOMANDA NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODPART NUMBER(20,0),
  COMP_CODE VARCHAR2(200),
  SALESORG VARCHAR2(200),
  DISTR_CHAN VARCHAR2(200),
  DIVISION VARCHAR2(200),
  DOC_NUMBER VARCHAR2(200),
  SOLD_TO VARCHAR2(200),
  DOC_TYPE VARCHAR2(200),
  DOC_CATEG_ORD VARCHAR2(200),
  ZABRVW VARCHAR2(200),
  ZVDATU VARCHAR2(200),
  LOC_CURRCY VARCHAR2(200),
  S_ORD_ITEM VARCHAR2(200),
  ITEM_CATEG_ORD VARCHAR2(200),
  MATERIAL VARCHAR2(200),
  ZEEDATU VARCHAR2(200),
  ZERDAT VARCHAR2(200),
  REASON_REJ VARCHAR2(200),
  DOC_CURRCY VARCHAR2(200),
  PLANT VARCHAR2(200),
  ZKZTLF VARCHAR2(200),
  BILLTOPRTY VARCHAR2(200),
  PAYER VARCHAR2(200),
  SHIP_TO VARCHAR2(200),
  ZKDMAT2 VARCHAR2(200),
  REQ_DATE VARCHAR2(200),
  CONF_QTY VARCHAR2(200),
  SALES_UNIT VARCHAR2(200),
  GI_DATE VARCHAR2(200),
  LOAD_DATE VARCHAR2(200),
  MATAV_DATE VARCHAR2(200),
  ZCMD_VAL VARCHAR2(200),
  ZVAL_LC VARCHAR2(200),
  ZCCOST_DC VARCHAR2(200),
  ZCCOST_LC VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBSID_STK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E6BA94771DCDA47CE46C23057194EB4B398265DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBSID_STK (
  CODOBIECT NUMBER(20,0),
  PLANT VARCHAR2(200),
  COMP_CODE VARCHAR2(200),
  SALESORG VARCHAR2(200),
  DISTR_CHAN VARCHAR2(200),
  DAY VARCHAR2(200),
  MATERIAL VARCHAR2(200),
  STOR_LOC VARCHAR2(200),
  SUPPLIER VARCHAR2(200),
  VAL VARCHAR2(200),
  LOC_CURRCY VARCHAR2(200),
  QTY VARCHAR2(200),
  STOR_UNIT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_SUBUNITDEDICATE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EC0DF7AB8A68DB5FC6DCF2713B71DB2292E8623D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_SUBUNITDEDICATE (
  CODSUBUNIT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARGETAG</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2DB3E760FE1058075425B2C03093DFD403EC17F3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARGETAG (
  CODTARGETAG NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  OPERAT NUMBER(1,0),
  ACTIV NUMBER(1,0),
  AGENT NUMBER(20,0),
  MONEDA NUMBER(20,0),
  DATASTART DATE,
  DATASTOP DATE,
  TIPTARGET NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER,
  DATACREARE TIMESTAMP(6),
  LUNASTART NUMBER(2,0),
  ANSTART NUMBER(4,0),
  LUNAEND NUMBER(2,0),
  ANEND NUMBER(4,0),
  NRCLIENTI NUMBER(10,0),
  CLIENT NUMBER(20,0),
  CLASAPART NUMBER(20,0),
  TIPPART NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARGETAG1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>99340B364CEBD029952FC367C1D5E3211B8ABC6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARGETAG1 (
  CODTARGETAG1 NUMBER(20,0),
  CODTARGETAG NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  UMSEC NUMBER(20,0),
  CANT NUMBER(20,7),
  VALOARE NUMBER(20,7),
  OBS VARCHAR2(200),
  MASA NUMBER(20,7),
  CANTMIN NUMBER(20,7),
  CANTMAX NUMBER(20,7),
  CODCLASAS NUMBER(20,0),
  VOLUM NUMBER(20,7),
  INDEXLOCAL NUMBER(5,0),
  TIPLINIE VARCHAR2(1),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  PARITATE NUMBER(20,7),
  CODARTICOL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARIFEMAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A29EA16A39B18F09C94F8980DD535845FE7AA3C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARIFEMAN (
  CODTARIF NUMBER(20,0),
  DENUMIRE VARCHAR2(150),
  CODEXTERN VARCHAR2(80),
  CODMONEDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARIFEMAN1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E4F81188710DE2769BEC5A4D524E7D89760A1195</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARIFEMAN1 (
  CODTARIF1 NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TARIF NUMBER(20,7),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  TARIF1 NUMBER(20,7),
  TARIF2 NUMBER(20,7),
  TARIF3 NUMBER(20,7),
  TARIF4 NUMBER(20,7),
  TARIF5 NUMBER(20,7),
  TARIF6 NUMBER(20,7),
  TARIF7 NUMBER(20,7),
  TARIF8 NUMBER(20,7),
  TARIF9 NUMBER(20,7),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARIFEMAN_LUNA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>397299D179FAB5C8064C57DE80665322F45D3756</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARIFEMAN_LUNA (
  CODTARIF1 NUMBER(20,0),
  CODTARIF NUMBER(20,0),
  TARIF NUMBER(20,7),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TARIFE_MASTER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4CB5429A5842E80F38BD7C4A2AF3E454A00C96BE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TARIFE_MASTER (
  CODTARIFM NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TAXDECL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F8FD6CB3409D04D53985E23D9010B160145499B7</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TAXDECL (
  CODTAXDECL NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  TAXCODE NUMBER(20,0),
  TAXBASE NUMBER(22,7),
  CHEIA VARCHAR2(400),
  MANUAL NUMBER(1,0),
  CODCONT NUMBER(20,0),
  TAXVAL NUMBER(22,7),
  ANLUNA NUMBER(5,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TAXE_ACCIZE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B09475D37CEE9CDE8926454DA7F3491B9898F2AD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TAXE_ACCIZE (
  CODOBIECT NUMBER(20,0),
  CODSERVFACT NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODTAXA NUMBER(20,0),
  LACEAPLIC NUMBER(20,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  PROC NUMBER(20,7),
  BAZAMAX NUMBER(20,7),
  BAZAMIN NUMBER(20,7),
  CODLINIE NUMBER(20,0),
  ROTVALOARE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TECNETL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>688A9429AC4850444C87CED9C8698609D5EBFFD9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TECNETL (
  CODIES1 NUMBER(20,0),
  LINENO NUMBER(20,0),
  CANT NUMBER(20,4),
  GROSSPRICE NUMBER(20,4),
  ITEMDISCOUNTAMOUNT NUMBER(20,4),
  NETPRICE NUMBER(20,4),
  NETPRICECORECTION NUMBER(20,4),
  CODOBIECT NUMBER(20,0),
  CODARTCLI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TEME</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A8E3AAE7B6A9D00DF8E1221D44CCF6D81F405D67</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TEME (
  CODTEMA NUMBER(20,0),
  DEN_TEMA VARCHAR2(60),
  ORE NUMBER(10,0),
  PRET NUMBER(20,7),
  CODFORMATOR NUMBER(20,0),
  CODCURS NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TERMENECMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3524CC9636B450F6A3F5463D21257C3F0A354EAD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TERMENECMD (
  CODTERMEN NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  ZILE NUMBER(5,0),
  PROCENT NUMBER(20,7),
  TIPPLATA NUMBER(2,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TESATURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C2BB252F9333BAEF0CEE6C198383C05369DA59E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TESATURI (
  CODTESATURA NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  COMPOZITIE VARCHAR2(300),
  MASASPECIFICA VARCHAR2(200),
  LEGATURA VARCHAR2(200),
  DESIMEU VARCHAR2(200),
  DESIMEB VARCHAR2(200),
  CATEGORIE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TESTINV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>475A6BCE0E593FC9D10A2B46334EAD90410B980A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TESTINV (
  CODINVENTAR NUMBER(20,0),
  NRINVENTAR NUMBER(20,0),
  DEN VARCHAR2(100),
  COD1 NUMBER(20,0),
  COD2 NUMBER(20,0),
  ORD1 NUMBER(20,0),
  ORD2 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TIPCHELT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C1014D2DF002648A34B975C4CE19A021759810AE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TIPCHELT (
  CODTIPCHELT NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TIPLUCRARISA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD07E90232A9C68B574F0B39B11DEDA2EFB0DCCB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TIPLUCRARISA (
  CODTIPLUCRARE NUMBER(20,0),
  DENUMIRE VARCHAR2(60),
  ARTSERVFACT NUMBER(20,0),
  CLASALUCRARI VARCHAR2(40),
  CODGEST NUMBER(20,0),
  CODINTERVENTIE NUMBER(20,0),
  TOTI NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TIPLUCRARISA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>42EF6BFCBB7E2216A90FCD97E17A9D6BF031FB58</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TIPLUCRARISA1 (
  CODTIPLUCRARE1 NUMBER(20,0),
  CODTIPLUCRARE NUMBER(20,0),
  CODPERS NUMBER(20,0),
  NUME VARCHAR2(20),
  PRENUME VARCHAR2(40),
  OBS VARCHAR2(240)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TIPPARTINCERT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E37E0D1B34C26EA7EAF59AC5A343551F3BFA04D6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TIPPARTINCERT (
  CODTIPPARTINCERT NUMBER(20,0),
  TIPCLIENT VARCHAR2(50),
  TIPIMPOZITARE VARCHAR2(30)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TIPURIPLATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2AA5567FBA0EDA23450A6CDDECDB5DB567ED5AAB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TIPURIPLATI (
  CODTIPPLATA NUMBER(20,0),
  TIPCASA NUMBER(5,0),
  TIPPLATA NUMBER(5,0),
  DENPLATA VARCHAR2(30),
  INVIZIBIL NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPCLI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7391EE626F9E55D11A212FF376A99E9C5B7C675E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPCLI (
  CODSUBUNIT NUMBER(20,0),
  CODCLIENT NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODAGENT NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  IDXLOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TIPLINIE VARCHAR2(1),
  CANT NUMBER(20,7),
  VAL NUMBER(20,7),
  TVA NUMBER(20,7),
  VALACHIZ NUMBER(20,7),
  CURS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPCLI_ADAOSURI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>272126DF25530B020FEC8E8C0E34231E9D9AD9B8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPCLI_ADAOSURI (
  CODIES1 NUMBER(20,0),
  ADAOS NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPCLI_VALAGENT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B5D0A8882BD2AE560A4D353E26CBDB7B66653280</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPCLI_VALAGENT (
  AGENT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  VALTOTAGENT NUMBER(20,7),
  VALTOTAGENT_VAL NUMBER(20,7),
  ADAOSTOT NUMBER(20,7),
  ADAOSTOT_VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPCLI_VALAGENTART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>FD778C2DB0EDA1DFD606A1E8927FA152D01A45FE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPCLI_VALAGENTART (
  AGENT NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  VALTOTAGENT NUMBER(20,7),
  VALTOTAGENT_VAL NUMBER(20,7),
  CANT NUMBER(20,7),
  ADAOSTOT NUMBER(20,7),
  ADAOSTOT_VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPCLI_VALCLIENT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6897F83E3C3406C519C10EDA0D491FA88254E0F3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPCLI_VALCLIENT (
  CODPART NUMBER(20,0),
  SUBUNITATEA NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  VALTOT NUMBER(20,7),
  VALTOT_VAL NUMBER(20,7),
  ADAOSTOT NUMBER(20,7),
  ADAOSTOT_VAL NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOPPEANI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F9557F3AC80BBD8BA34161E299E4EFDC29E4E124</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOPPEANI (
  AN NUMBER(4,0),
  VAL NUMBER(20,7),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOTALPUNCTE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C0A3F7A925FAC6E875942660AF8B2594EE5D31D5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOTALPUNCTE (
  COD NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  PUNCTE NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPOSTRETAIL NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TOWORD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A953ABFD28899B84F2F5D914DC91E3B8004537DB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TOWORD (
  CODTOWORD NUMBER(20,0),
  CODDOC NUMBER(20,0),
  NUMEDOC VARCHAR2(50),
  SQLVIEW VARCHAR2(200),
  SQLDATE VARCHAR2(200),
  SQLLINII VARCHAR2(200),
  CALE VARCHAR2(200),
  NUMEVIEW VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSACARD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D63901128D0FD96E0B6B3FC02E79E5501C658257</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSACARD (
  CODTRANSACARD NUMBER(20,0),
  CODEMULARE NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSEINI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>99FF92E4596A5148B36D21E2BE9863B21A249C93</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSEINI (
  CODBANKCONT NUMBER(20,0),
  INFOCONT VARCHAR2(50),
  CODMONEDA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSF</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D8B34D1D214DD110AF4316E7D2B40407D00FF528</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSF (
  CODTRANSF NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETAE NUMBER(20,0),
  NRAE NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  TIPREPSUPLIM NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPMODIFPRET NUMBER(1,0),
  STORNO NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODGESTCMD NUMBER(20,0),
  LISTAT NUMBER(1,0),
  REEVALUARE NUMBER(1,0),
  SERIADOC VARCHAR2(20),
  IDIMPORT VARCHAR2(30),
  CODANALIZA NUMBER(20,0),
  AJUSTVALSTOC NUMBER(1,0),
  STADIUWMS NUMBER(2,0),
  SUBUNITDEST NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  CORECTIE NUMBER(1,0),
  CANTRETPREL NUMBER(20,7),
  UIT VARCHAR2(20),
  ET_IDINCARCARE VARCHAR2(20),
  ET_IDDESCARCARE VARCHAR2(20),
  ET_TIPMEDIU NUMBER(1,0),
  ET_STATUS VARCHAR2(20),
  TIPFACTURA NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSF1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>918D26473A95D5E00BEC0CF6DA0E4C3DB1D21570</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSF1 (
  CODTRANSF1 NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  OBS VARCHAR2(500),
  CODCONT NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  COSTTRANSPORT NUMBER(20,7),
  CODMIFIX NUMBER(20,0),
  PUVAL NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  CODAUTO NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODLINIEDOCIMP NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  DENUM VARCHAR2(15),
  VALOARE NUMBER(20,7),
  PARITATE NUMBER(20,7),
  PROCTVA NUMBER(20,7),
  CODACCIZE NUMBER(20,0),
  CODTAXA1 NUMBER(20,0),
  CODTAXA2 NUMBER(20,0),
  CODTVA NUMBER(20,0),
  NRDOCLINK VARCHAR2(30),
  INFOMF VARCHAR2(50),
  CODEXTERN VARCHAR2(80),
  CODINTERN VARCHAR2(80),
  UM1 NUMBER(20,0),
  RELATIEUM1 NUMBER(2,0),
  CMDINT NUMBER(20,0),
  COEFUM_CANTAR NUMBER(20,5)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSF1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>865545B8FA113442FB048CF1C4C9FFC4A8C378AF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSF1_INITIAL (
  CODTRANSF1 NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSFLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2AFED57C5E5389BB7BDB5645790611DF78558F46</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSFLINK (
  CODTRANSF1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSFLINK_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8E6F62DEB624171208D1E5EE894BBEDA5EBAB0A6</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSFLINK_INITIAL (
  CODTRANSF1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7),
  DATACOMANDA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSPORT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>8F3E08D6D2E0876F42F8E9ED021A4945125C595A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSPORT (
  CODTRANSPORT NUMBER(20,0),
  DATATRANSPORT TIMESTAMP(6),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATE NUMBER(20,0),
  INDICATIV VARCHAR2(100),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TIPREPART NUMBER(1,0),
  CODPARCAUTO NUMBER(20,0),
  CODSOFER NUMBER(20,0),
  COLETE NUMBER(1,0),
  REP_TRANSF NUMBER(1,0),
  REP_SUBUNIT NUMBER(1,0),
  TIP NUMBER(1,0),
  MASINA VARCHAR2(200),
  SARCINA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  DATASTART DATE,
  DATASTOP DATE,
  DATASTARTDVI DATE,
  DATASTOPDVI DATE,
  TIPLIVRARE NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSPORT1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>622C8445A9601BB815F5814C19E55E10000A7DFD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSPORT1 (
  CODTRANSPORT1 NUMBER(20,0),
  CODTRANSPORT NUMBER(20,0),
  CODCOLET NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  SERIECOLET VARCHAR2(200),
  NRCOLET NUMBER(20,0),
  DATACOLET TIMESTAMP(6),
  SERIEDOC VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  TIPPARTENER VARCHAR2(200),
  CODPART NUMBER(20,0),
  PARTENER VARCHAR2(200),
  PREFIXDOC VARCHAR2(2),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSPORT1_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E7942C9E0348C2DBDDAF96F7A34EF20DE6DBEF49</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSPORT1_INI (
  CODTRANSPORT1 NUMBER(20,0),
  CODTRANSPORT NUMBER(20,0),
  CODCOLET NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  SERIECOLET VARCHAR2(200),
  NRCOLET NUMBER(20,0),
  DATACOLET TIMESTAMP(6),
  SERIEDOC VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  TIPPARTENER VARCHAR2(200),
  CODPART NUMBER(20,0),
  PARTENER VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRANSPORT2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EDC15F6B8AA35C80D203B45468AB4C8F01599882</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRANSPORT2 (
  CODTRANSPORT2 NUMBER(20,0),
  CODTRANSPORT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  CODTRANSPORT1 NUMBER(20,0),
  CODDOC1 NUMBER(20,0),
  ARTICOL VARCHAR2(200),
  CANT NUMBER(20,7),
  DEN_UM1 VARCHAR2(30),
  DOCUMENT VARCHAR2(100),
  VALOARE NUMBER(20,7),
  VAL NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  SERIEDOC VARCHAR2(50),
  NRDOC NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  CODPART NUMBER(20,0),
  PARTENER VARCHAR2(200),
  PREFIXDOC VARCHAR2(2),
  OPERAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASBC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6942DFB5FA94DB416DF4D0E0CFD77A98B75303E9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASBC (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  MATERIAL VARCHAR2(200),
  SERIEMATERIAL VARCHAR2(2500),
  IOARTMATERIAL VARCHAR2(60),
  CANTMATERIAL NUMBER(20,7),
  PRETMATERIAL NUMBER(20,7),
  VALMATERIAL NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASCMDINT</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D07D751182753A264D624B05BDBF89E524BC5540</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASCMDINT (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  PRODUS VARCHAR2(200),
  SERIEPRODUS VARCHAR2(75),
  IOARTPRODUS VARCHAR2(60),
  CANTPRODUS NUMBER(20,7),
  PRETPRODUS NUMBER(20,7),
  VALPRODUS NUMBER(20,7),
  MATERIAL VARCHAR2(200),
  SERIEMATERIAL VARCHAR2(2500),
  IOARTMATERIAL VARCHAR2(60),
  CANTMATERIAL NUMBER(20,7),
  PRETMATERIAL NUMBER(20,7),
  VALMATERIAL NUMBER(20,7),
  OPERATIE VARCHAR2(60),
  NROP NUMBER(20,7),
  VALOP NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0),
  CODCMDPRODMAN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>83D853EC072D0A28A5827EA3E1816B96783016FD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEU (
  CODTRASEU NUMBER(20,0),
  CODFISASUP NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  POZT NUMBER(10,0),
  EXECUTANT NUMBER(20,0),
  CLASATEH NUMBER(20,0),
  SIMBOL_GEST VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ECB7111E9041CB618BB92B9974A868BCBA61237E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR (
  CODTRASEULIVR NUMBER(20,0),
  DENTRASEU VARCHAR2(100),
  SIMBOLTRASEU VARCHAR2(20),
  OPRIRI NUMBER(10,0),
  ORE NUMBER(10,0),
  MINUTE NUMBER(2,0),
  TIP NUMBER(2,0),
  LAT NUMBER(20,7),
  LNG NUMBER(20,7),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_ALLCMD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>651DDA6F579A141201E7609B78F81E6A726EC13F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_ALLCMD (
  CODCOMANDA NUMBER(20,0),
  PARTENER VARCHAR2(200),
  CODAGENDA NUMBER(20,0),
  CODJUDET NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODAUTO NUMBER(20,0),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  SELECTIE NUMBER(1,0),
  SEDIU VARCHAR2(250),
  JUDET VARCHAR2(200),
  LOCALITATE VARCHAR2(200),
  CODTRASEU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_ALLCMD_BAZA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>EADA6965FEE2A17941AE7AE5B072218AA64F4541</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_ALLCMD_BAZA (
  CODCOMANDA NUMBER(20,0),
  PARTENER VARCHAR2(200),
  CODAGENDA NUMBER(20,0),
  CODJUDET NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODAUTO NUMBER(20,0),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  SELECTIE NUMBER(1,0),
  SEDIU VARCHAR2(250),
  JUDET VARCHAR2(200),
  LOCALITATE VARCHAR2(200),
  CODTRASEU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_ARTLIVR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>DB75A8058B7BA11D8AF3E96193941EEA4735A9FF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_ARTLIVR (
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODTRASEU NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  DENOBIECT VARCHAR2(200),
  INSOTITOR NUMBER(20,0),
  MIJLOCTRANSP NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_AUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>56CD0DB7F1761B3F4708E42C1442A42FC728A611</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_AUTO (
  CODAUTO NUMBER(20,0),
  MODEL VARCHAR2(50),
  MARCA VARCHAR2(50),
  SOFER VARCHAR2(400),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  MASAI NUMBER(20,7),
  VOLUMI NUMBER(20,7),
  DENUMIRE VARCHAR2(250),
  CODTRASEU NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_COMANDA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>E62DB58BDC728AAACAB31C9A2300263DB319EFAE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_COMANDA (
  CODCOMANDA NUMBER(20,0),
  PARTENER NUMBER(20,0),
  MONEDA NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  OBS VARCHAR2(200),
  DEN_PARTENER VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_COMANDA1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C6A419A988B1CE31EE6B611C8730B259A30F550E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_COMANDA1 (
  CODCOMANDA1 NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  CODART NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  PU NUMBER(20,6),
  VALOARE NUMBER(20,6),
  TERMEN DATE,
  ADDIM NUMBER(20,7),
  PROCDISC NUMBER(20,7),
  CONSUM NUMBER(20,0),
  CULANSARE NUMBER(1,0),
  SCADENTA NUMBER(5,0),
  OBS VARCHAR2(200),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  DENOBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_COMENZI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>371C9ABBCBDE18336D920F8F02BF33E14CFD19F9</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_COMENZI (
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  CODOBIECTECHIV NUMBER(20,0),
  CODARTICOLECHIV NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  CANTDISPONIBIL NUMBER(20,7),
  CANTREZERVAT NUMBER(20,7),
  CANTCOMENZI NUMBER(20,7),
  CODUM NUMBER(20,0),
  ZECIMALEUM NUMBER(4,0),
  CODCLIENT NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  CODJUDET NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CODTRASEU NUMBER(20,0),
  POZTRASEU NUMBER(20,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODMIJLTRANSP NUMBER(20,0),
  MASAU NUMBER(20,7),
  VOLUMU NUMBER(20,7),
  DELEGAT NUMBER(20,0),
  INSOTITOR NUMBER(20,0),
  DATASOSIRII DATE,
  INREGNULA NUMBER(1,0),
  MASAO NUMBER(20,7),
  VOLUMO NUMBER(20,7),
  DENOBIECT VARCHAR2(200),
  CODPROIECT NUMBER(20,0),
  FLAGLUCRU NUMBER(1,0),
  CODTARA NUMBER(20,0),
  CODZONA NUMBER(20,0),
  DEN_ZONA VARCHAR2(50),
  DEN_TARA VARCHAR2(30),
  DEN_JUDET VARCHAR2(30),
  DEN_LOCALIT VARCHAR2(50),
  DEN_CLIENT VARCHAR2(100),
  CODOBIECTECHIVGEN NUMBER(20,0),
  PARITATEECHIVGEN NUMBER(20,7),
  ZECIMALEUMECHIVGEN NUMBER(4,0),
  DENOBIECTECHIVGEN VARCHAR2(200),
  CODUMECHIVGEN NUMBER(20,0),
  TRANSPCLIENT NUMBER(1,0),
  CODGRUPA NUMBER(20,0),
  PARITATEGRUPA NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  TIPDOC NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_COMENZICLIENTI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>37CF91DE10089757FE5462B0DC448D353A9D48B5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_COMENZICLIENTI (
  CODCLIENT NUMBER(20,0),
  CODJUDETCLIENT NUMBER(20,0),
  CODLOCALITCLIENT NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  CANTREZERVAT NUMBER(20,7),
  CODCOMANDA NUMBER(20,0),
  CODARTECHIV NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  ZECIMALEUM NUMBER(4,0),
  INREGNULA NUMBER(1,0),
  CODCOMANDA1 NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  FLAGLUCRU NUMBER(1,0),
  DEN_CLIENT VARCHAR2(100),
  TIPDOC NUMBER(10,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_INCARCARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>3D7665998857DCF7F0F2FE97B4DBB1623A1519CD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_INCARCARE (
  CODTRASEU NUMBER(20,0),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  MIJLOCTRANSP NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  DATASOSIRII DATE,
  MASAUTILA NUMBER(20,7),
  VOLUMUTIL NUMBER(20,7),
  INSOTITOR NUMBER(20,0),
  DIFMASA NUMBER(20,7),
  DIFVOLUM NUMBER(20,7),
  TMPIDX NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_LIVRARE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D1253CCFBF5F276A086ACC1F115CFB661C70548F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_LIVRARE (
  POZITIE NUMBER(20,0),
  CODCLIENT NUMBER(20,0),
  CODJUDETCLIENT NUMBER(20,0),
  CODLOCALITCLIENT NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODTRASEU NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODAGENDA NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  INSOTITOR NUMBER(20,0),
  MIJLOCTRANSP NUMBER(20,0),
  DEN_CLIENT VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_TOTALART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>702C8633A4870EBF5D3610A77FB1F8BB2873121C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_TOTALART (
  CODART NUMBER(20,0),
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  CANTDISPONIBIL NUMBER(20,7),
  CANTREZERVAT NUMBER(20,7),
  CANTCOMENZI NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  ZECIMALEUM NUMBER(4,0),
  INREGNULA NUMBER(1,0),
  DENOBIECT VARCHAR2(200),
  RESTACCEPTAT NUMBER(20,7),
  CODGRUPA NUMBER(20,0),
  PARITATEGRUPA NUMBER(20,7),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_TRASEUART</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9F127E460AEAB38EA2A7FB6CB910A1048E404DB1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_TRASEUART (
  CODCLIENT NUMBER(20,0),
  NRCOMANDA NUMBER(20,0),
  DATACOMANDA DATE,
  CODUM NUMBER(20,0),
  CANTCOMANDAT NUMBER(20,7),
  CANTACCEPTAT NUMBER(20,7),
  CANTREZERVAT NUMBER(20,7),
  MASA NUMBER(20,7),
  VOLUM NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODCOMANDA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  MASAUM NUMBER(20,7),
  VOLUMUM NUMBER(20,7),
  INREGNULA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASEULIVR_TRASEUARTINFO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>425AC5CDCE7514ACD1E76ECF8DE952A9B69BA667</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASEULIVR_TRASEUARTINFO (
  CODTRASEU NUMBER(20,0),
  DENTRASEU VARCHAR2(100),
  SIMBOLTRASEU VARCHAR2(20),
  CODOBIECT NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  DENARTICOL VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASNP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6E116CF89A99CC2EF769085511A470335224D3DC</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASNP (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  PRODUS VARCHAR2(200),
  SERIEPRODUS VARCHAR2(75),
  IOARTPRODUS VARCHAR2(60),
  CANTPRODUS NUMBER(20,7),
  PRETPRODUS NUMBER(20,7),
  VALPRODUS NUMBER(20,7),
  CODCMDPRODMAT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRASRP</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>534D2A414904C5FD085282556D2C5D3C7F481AA5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRASRP (
  COD NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  OPERATIE VARCHAR2(60),
  NROP NUMBER(20,7),
  VALOP NUMBER(20,7),
  CODCMDPRODMAN NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TREE_ANALIZANOD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6F5C0CFAC463DF6E4661FC2E0AA3A709F8723BE8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TREE_ANALIZANOD (
  CODANALIZANOD NUMBER(20,0),
  NIVEL NUMBER(2,0),
  DEN_DESCRIPTOR VARCHAR2(50),
  SIMBOL VARCHAR2(10),
  VALOARE VARCHAR2(50),
  TIP NUMBER(30,0),
  CODASOCIAT NUMBER(20,0),
  POZITIE NUMBER(10,0),
  IDX VARCHAR2(500)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TREZOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9E2E218281B359FBF26E4BDE961DC23C6B275D7E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TREZOR (
  CODTREZOR NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  ICONTPERS NUMBER(20,0),
  MONEDAPERS NUMBER(20,0),
  DATADOC DATE,
  NUMEDOC VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  AGENT NUMBER(20,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATAINREG TIMESTAMP(6),
  IDIMPORT VARCHAR2(30),
  CODANALIZA NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  LISTAT NUMBER(1,0),
  CODBANK NUMBER(20,0),
  NRCONT VARCHAR2(100),
  CODMONEDA NUMBER(20,0),
  SIMBOLMONEDA VARCHAR2(30),
  SOLDCURENT NUMBER(20,7),
  INCASARI NUMBER(20,7),
  PLATI NUMBER(20,7),
  CREDIT NUMBER(1,0),
  CURSREG NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TREZOR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>51327F4DD4E249ED90D1E65C15DABCC337152B76</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TREZOR1 (
  CODTREZOR1 NUMBER(20,0),
  CODTREZOR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPTRANZ NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  DOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  CURS NUMBER(20,7),
  COMISION NUMBER(20,7),
  OBIECTTRANZ NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPDECONT NUMBER(1,0),
  DATADECONT DATE,
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(200),
  INITIALIZARI NUMBER(1,0),
  AGENT NUMBER(20,0),
  ANULAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODLOCATIE NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  SERIEDOC VARCHAR2(20),
  CODSERTAR NUMBER(20,0),
  NRI VARCHAR2(40),
  CODCOMANDA NUMBER(20,0),
  PLATATVA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0),
  CODPLATA1 NUMBER(20,0),
  DENTRANZ VARCHAR2(120),
  CODAVANS NUMBER(20,0),
  NUMEAGENT VARCHAR2(100),
  INFOCONTBANCAR VARCHAR2(100),
  CODBANCA NUMBER(20,0),
  CODMONEDA NUMBER(10,0),
  SUBUNITATEA NUMBER(20,0),
  IDENTIFLINIE VARCHAR2(100),
  INFOCMD VARCHAR2(50),
  CMDINT NUMBER(20,0),
  TAXCODE VARCHAR2(250),
  TAXBASE VARCHAR2(250),
  LINKRETURO NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TREZOR1_INITIAL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1C87BB12E52957E14C0BE71BA4AEEBDFB9B8C447</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TREZOR1_INITIAL (
  CODTREZOR1 NUMBER(20,0),
  CODTREZOR NUMBER(20,0),
  CURS NUMBER(20,7),
  TIPTRANZ NUMBER(1,0),
  OBIECTTRANZ NUMBER(20,0),
  VALDOC NUMBER(20,7),
  CODPART NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TREZORRETAIL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>091B29F908E7A8AB7364C449F7B54AD759402652</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TREZORRETAIL (
  CODTREZOR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRIGAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5A65E4F1169464438551C69126F88EB2D7315763</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRIGAR (
  CODTRIGAR NUMBER(20,0),
  TABLENAME VARCHAR2(20),
  TRIG CLOB,
  VARIABILE CLOB,
  TIP NUMBER(1,0),
  OPERATIE NUMBER(1,0),
  MOMENT NUMBER(1,0),
  MASTERFIELD VARCHAR2(20),
  MASTERTABLE VARCHAR2(20),
  MAINTABLE VARCHAR2(20),
  INITIATOR NUMBER(20,0),
  DESTINATAR VARCHAR2(300),
  SUBIECT VARCHAR2(200),
  ANTET VARCHAR2(2000),
  FINAL VARCHAR2(2000),
  OBS VARCHAR2(500),
  INACTIV NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TRIGAR1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>2A233E7813288634870E13F011B421B874EEACE8</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TRIGAR1 (
  CODTRIGAR1 NUMBER(20,0),
  CODTRIGAR NUMBER(20,0),
  FIELDNAME VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TVAINCAS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB46672CAD5AAF458752EDCCACE8191BCFF898E1</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TVAINCAS (
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  SERIADOC VARCHAR2(20),
  DATADOC DATE,
  DATASTINGERE DATE,
  VALSTINSA NUMBER(20,7),
  DATASTOP DATE,
  COEF NUMBER(30,17),
  COEFBAZA NUMBER(30,17),
  COEFTVA NUMBER(30,17),
  TIPSTINGERE NUMBER(20,0),
  PREFIXSTINGERE VARCHAR2(30),
  NRSTINGERE NUMBER(20,0),
  INITIALIZARI NUMBER(1,0),
  ANSTINGERE NUMBER(4,0),
  LUNASTINGERE NUMBER(2,0),
  PARTENER NUMBER(20,0),
  SPLITTVA NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TVAMONETAR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9E8EEFE90A66841BAFE060645AC25EA614F5E87B</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TVAMONETAR (
  CODTVAMONETAR NUMBER(20,0),
  CODIES NUMBER(20,0),
  BONURI NUMBER(5,0),
  CODTVA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7),
  PROCENT NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TVASERV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9EF2923B4FA430CA5D1564EB215DA30F89BCD769</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TVASERV (
  CODTVASERV NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  CODTARA NUMBER(20,0),
  TIPCOTA NUMBER(10,0),
  PROCENT NUMBER(20,7),
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_TVASERV1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D4DDD2D4324A8140C11EBB55A6D9D315BEB3E73C</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_TVASERV1 (
  CODTVASERV1 NUMBER(20,0),
  CODTVASERV NUMBER(20,0),
  CODCONT NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0),
  ANSFARSIT NUMBER(4,0),
  LUNASFARSIT NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UMA</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>5E430E394519945B83758D7919F8A38DEA77E433</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UMA (
  CODOBIECT NUMBER(20,0),
  DUMA1 VARCHAR2(15),
  PUMA1 NUMBER(30,15),
  DUMA2 VARCHAR2(15),
  PUMA2 NUMBER(30,15),
  DUMA3 VARCHAR2(15),
  PUMA3 NUMBER(30,15),
  PUMAC NUMBER(30,15),
  PUMAP NUMBER(30,15)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UPD_COEFDISCMAJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>C51AB73C82B13676CED4AC917CE5E31E379F1824</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UPD_COEFDISCMAJ (
  CODIES1 NUMBER(20,0),
  OLDCOEFDISCMAJ NUMBER(20,7),
  NEWCOEFDISCMAJ NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USED_ANTERIOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B9B2E7E804033A35CCB8FA2ED6970EAB4E72F381</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USED_ANTERIOR (
  NRDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USED_ULTERIOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1BD555917E1157DA8AD09C8CBCEDB428D73EFFFD</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USED_ULTERIOR (
  NRDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USERDOC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>B0828A2EF003DA9BCE88A6999D81914D204AC581</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USERDOC (
  CODUTILIZATOR NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USERSCONST</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0BF6DB3F653AF421BCDDD8AD0BC43C107367A2A0</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USERSCONST (
  USERID NUMBER(20,0),
  USERNAME VARCHAR2(100),
  GRUPNAME VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USERSQL</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CCE4FBED3693F869CC05BF71F40A010F0E37C115</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USERSQL (
  CODSQL NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  OBS VARCHAR2(200),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  SQLTEXT CLOB,
  WHERECLAUSE VARCHAR2(1000),
  REZULTAT VARCHAR2(1000)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USERSQL1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>0AE0676238E8E95854D75758A9BD40FD40C45D27</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USERSQL1 (
  CODSQL1 NUMBER(20,0),
  CODSQL NUMBER(20,0),
  TABLA VARCHAR2(50),
  NUME VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_USERSQL2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A6DBAADF362AEE2758755730D86C1D9436D74FA</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_USERSQL2 (
  CODSQL2 NUMBER(20,0),
  CODSQL NUMBER(20,0),
  CODSQL1 NUMBER(20,0),
  TIPJOIN NUMBER(1,0),
  JOINON VARCHAR2(100),
  JOINWHERE VARCHAR2(100)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>61B83C4A40CEAACD37295EA1C595E0EC25B49DC3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE (
  CODUTILAJ NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  NRINVENTAR NUMBER(20,0),
  ETICHETA VARCHAR2(50),
  TIPUTILAJ VARCHAR2(50),
  FLOTA VARCHAR2(50),
  MODEL VARCHAR2(50),
  ANF NUMBER(4,0),
  SERIEF VARCHAR2(50),
  INCARCARE NUMBER(10,0),
  DATAGARANTIE DATE,
  INGARANTIE NUMBER(1,0),
  LUNGIME NUMBER(20,7),
  LATIME NUMBER(20,7),
  INALTIME NUMBER(20,7),
  OBS VARCHAR2(300),
  INACTIV NUMBER(1,0),
  CORECTIEINDEX NUMBER(20,0),
  UM NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATAGARANTIEI DATE,
  APROBAT NUMBER(1,0),
  DATASTART DATE,
  NRCONTR VARCHAR2(50),
  DATACONTR DATE,
  CODFURNIZOR NUMBER(20,0),
  DOC VARCHAR2(50),
  TIP NUMBER(5,0),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(250),
  HFACTOR NUMBER(2,0),
  AGENT NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DINCONTRACT NUMBER(10,0),
  FURNIZOR VARCHAR2(250),
  CODCONTRFACT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>643DD652891D6CE2988E882E2C28A89812FBD51E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE1 (
  CODUTILAJ1 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  NRCONTR VARCHAR2(20),
  CARNETCONTR VARCHAR2(20),
  STATUS_PART NUMBER(1,0),
  STATUS_DEPO NUMBER(1,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DATA DATE,
  USERID NUMBER(20,0),
  DATACREARE DATE,
  OBS VARCHAR2(200),
  STATUS_SERVICE NUMBER(1,0),
  INDEXLOCAL NUMBER(10,0),
  CODPERS NUMBER(20,0),
  ESTETIC NUMBER(5,0),
  DENLOCATIE VARCHAR2(200),
  RESPONSABIL VARCHAR2(400)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE2</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>4F208C73A85F700BEABA9A167F92133AAD90C45D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE2 (
  CODUTILAJ2 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  INTERVENTIE NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODUTILAJ20 NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  KMPARCURSI NUMBER(20,7),
  CODOBIECT NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  UMSEC NUMBER(20,0),
  DENUMIRE VARCHAR2(200),
  DEN_UM1 VARCHAR2(15),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  RELATIEUM1 NUMBER(20,7),
  RESTDEPREDAT NUMBER(20,7),
  CODGEST NUMBER(20,0),
  PERTIP NUMBER(1,0),
  PERDURATA NUMBER(10,0),
  PERKM NUMBER(10,0),
  ATENTIONAREZILE NUMBER(10,0),
  ATENTIONAREKM NUMBER(10,0),
  DATACURENTA DATE,
  INDEXPORNIRE NUMBER(10,0),
  NRINTERVENTII NUMBER(10,0),
  DATAFINALA DATE,
  DEN_INTERVENTIE VARCHAR2(200),
  ACCIDENTALA NUMBER(1,0),
  DURATA NUMBER(20,7),
  NRSCHIMBURI NUMBER(5,0),
  ORESCHIMB NUMBER(4,2),
  ORASTART DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE20</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>769203200974B4B90A6E744185D709BD0F6410A4</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE20 (
  CODUTILAJ20 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRIERE VARCHAR2(2500),
  STARE NUMBER(5,0),
  OPERATOR NUMBER(20,0),
  OBS VARCHAR2(500),
  CODIES NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(250),
  CODPERSC NUMBER(20,0),
  CALLCENTER NUMBER(1,0),
  CODBC NUMBER(20,0),
  PRIORITATE VARCHAR2(200),
  DENOPERATOR VARCHAR2(50),
  FACTURARE VARCHAR2(50),
  DEVIZ NUMBER(1,0),
  TELEFON VARCHAR2(40),
  BONCONSUM VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE2C</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6F6BFF88F4A48E041822599917DDCDC165D15DDB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE2C (
  CODUTILAJ2C NUMBER(20,0),
  CODUTILAJ2 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  INDEXC NUMBER(10,0),
  DATAINDEXC DATE,
  CODCOMANDA1 NUMBER(20,0),
  EXPLICATII CLOB,
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6),
  INDEXV NUMBER(10,0),
  DATAV DATE,
  RESETAT NUMBER(1,0),
  INDEXLOCAL NUMBER(10,0),
  ORESTART NUMBER(7,3),
  ORESTOP NUMBER(7,3),
  NRDOC NUMBER(10,0),
  DATADOC DATE,
  DEN_GEST VARCHAR2(100),
  CODCOMANDA NUMBER(20,0),
  TIPDOC NUMBER(10,0),
  DURATA NUMBER(20,7),
  DATASTARTS VARCHAR2(50),
  DATAENDS VARCHAR2(50),
  CODINTR1 NUMBER(20,0),
  INDEXA NUMBER(10,0),
  DATAA DATE,
  ALERTA NUMBER(2,0),
  ZIV VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE2P</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>86AC362B7873A65160CF93A550331F25E5D22A30</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE2P (
  CODUTILAJ2P NUMBER(20,0),
  CODUTILAJ2 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  CODPERS NUMBER(20,0),
  ANGAJAT VARCHAR2(400),
  MARCA NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJE3</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>135194912A53198FC87B6E1F38F52AD04FFBB64E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJE3 (
  CODUTILAJ3 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  DATABORD DATE,
  INDEXBORD NUMBER(20,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CORECTIEINDEX NUMBER(10,0),
  TIP_INDEX NUMBER(1,0),
  INDEXRESETAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJEDEV</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>6AE7ADD9E216C51DD601EB5718D2BA75A9BDDFCF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJEDEV (
  CODUTILAJDEV NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  CODUTILAJ20 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CANTFACT NUMBER(20,7),
  FACTURABIL NUMBER(1,0),
  CODIES1 NUMBER(20,0),
  CODUTILAJ2 NUMBER(20,0),
  TIPLIVRARE NUMBER(20,0),
  TVA NUMBER(20,7),
  CONSUMABIL NUMBER(1,0),
  CANTCONS NUMBER(20,7),
  DENUMIRE VARCHAR2(200),
  SERVICIU NUMBER(20,0),
  DENSERVICIU VARCHAR2(200),
  CODAUTO NUMBER(20,0),
  VALOARE NUMBER(20,7),
  UM NUMBER(20,0),
  PARITATE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILAJETIPINDEX</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>7A881821FA34F3348E284AE804AC2343DDB6F426</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILAJETIPINDEX (
  CODTINDEX NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  TIP_INDEX NUMBER(1,0),
  DENUMIRE VARCHAR2(100),
  UM NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_UTILIZATOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>9A4CE2A109C84DD74D18F5A700594875197967FE</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_UTILIZATOR (
  CODUTILIZATOR NUMBER(18,0),
  USERNAME VARCHAR2(30),
  NUME VARCHAR2(50),
  DENGRUP VARCHAR2(50)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VALATREXCEPTII</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>F663649BAB54FD13AADEAA0388512DFAF3427B6F</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VALATREXCEPTII (
  CODEXCEPTIE NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODARTICOL NUMBER(20,0),
  DENARTICOL VARCHAR2(100),
  CODEXTERNART VARCHAR2(20)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VALID_NARTOBJ</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1FF1D88D407C6DB8D30D0FA0B1858602101AAE1E</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VALID_NARTOBJ (
  CODOBIECT NUMBER(20,0),
  DENOBIECT VARCHAR2(200)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VANZARI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>644648E4A4A4E81F4B60197082EB0EF9C7B47D55</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VANZARI (
  CODVANZARE NUMBER(20,0),
  CODPART NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  CODEMULARE NUMBER(20,0),
  CODEMULAREFACT NUMBER(20,0),
  OBS VARCHAR2(200),
  VALBON NUMBER(20,7),
  TVABON NUMBER(20,7),
  VALDISCBON NUMBER(20,7),
  TVADISCBON NUMBER(20,7),
  VALFACTURA NUMBER(20,7),
  TVAFACTURA NUMBER(20,7),
  VALDISCFACTURA NUMBER(20,7),
  TVADISCFACTURA NUMBER(20,7),
  INFOBON VARCHAR2(100),
  INFOFACT VARCHAR2(100),
  CODIES NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VARIABILE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>CA6E599B0E49F91442FE79FE1A05B11A342F30C5</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VARIABILE (
  CODJOB1 NUMBER(20,0),
  SQL_EXEC VARCHAR2(4000),
  TIP_SQL NUMBER(1,0),
  ORDINE NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VENITAVANS_IES</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D2007630C59737A8BB09E54744EB039D8C521F74</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VENITAVANS_IES (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(500),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VENITAVANS_NC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A20DF42D70306F6944CF17F5D22FE3AAC9271882</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VENITAVANS_NC1 (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(100),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VENITAVANS_TREZOR</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>40699EDDA5318AB5BD3A586DD7DFF2F2308B645A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VENITAVANS_TREZOR (
  CODINTR1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  CODNC1 NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATADOC DATE,
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  DENUMIRE VARCHAR2(200),
  DEN_PART VARCHAR2(200),
  VALOARE NUMBER(20,7),
  REZOLVAT NUMBER(20,0),
  OBSCHELT VARCHAR2(100),
  OBSDOC VARCHAR2(100),
  DEN_GEST VARCHAR2(100),
  CODGEST_REZ NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHER</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BD09530BADD3830919C8399A01555B4CADBAFBF3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHER (
  CODVOUCHER NUMBER(20,0),
  CODPARTENER NUMBER(20,0),
  OBS VARCHAR2(100),
  DATASTART DATE,
  DATASTOP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODCMD NUMBER(20,0),
  CODIES NUMBER(10,0),
  CODGEST NUMBER(20,0),
  OBS1 VARCHAR2(500),
  REST NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHER1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>439C4C84CFB8A2241F286D121D89B2D65A33A485</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHER1 (
  COD NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(20,0),
  DOC VARCHAR2(100),
  DATADOC DATE,
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHERCADOU</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>1F09F641C8773E344F8ECF09B6D673E2E6BE980D</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHERCADOU (
  COD NUMBER(20,0),
  BARCODE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  DATASTART TIMESTAMP(6),
  DATASTOP TIMESTAMP(6),
  IS_USED NUMBER(1,0),
  USED_DATE TIMESTAMP(6)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHERCADOULINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>80F734EF0118858B4E6C679894D02FCF93E7AB15</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHERCADOULINK (
  COD NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  TIPOPERATIE NUMBER(1,0),
  BARCODE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  DATASTART TIMESTAMP(6),
  DATASTOP TIMESTAMP(6),
  ZILEVALABIL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  POSTAT NUMBER(1,0),
  MODIFICAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHERCADOULINK_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BDA9F6BC05C200661A127AD4F83DC86FFE184525</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHERCADOULINK_INI (
  COD NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  TIPOPERATIE NUMBER(1,0),
  BARCODE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  DATASTART TIMESTAMP(6),
  DATASTOP TIMESTAMP(6),
  ZILEVALABIL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  POSTAT NUMBER(1,0),
  MODIFICAT NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_VOUCHERLINK</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D5C2CE3BDC23441B7FB30A550E476EBD0CD09416</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_VOUCHERLINK (
  CODVLINK NUMBER(20,0),
  CODVOUCHER NUMBER(20,0),
  CODCMD NUMBER(20,0),
  CODIES NUMBER(20,0),
  VALOARE NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_V_AUTO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>D767F97CA13725A58CC2636407907676AE619480</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_V_AUTO (
  CODAUTO NUMBER(20,0),
  CODGEST NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  Q NUMBER(10,0),
  DATASTART DATE,
  DATASTOP DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_V_RAC_CARS</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BCB5ABDC801249F3A4B0F6C488E41B35159EDF26</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_V_RAC_CARS (
  CODAUTO NUMBER(20,0),
  SUBUNITATE VARCHAR2(100),
  GESTIUNE VARCHAR2(100),
  CLASA VARCHAR2(250),
  NRAUTO VARCHAR2(30),
  MARCA VARCHAR2(50),
  MODEL VARCHAR2(50),
  INACTIV NUMBER(2,0),
  CODGEST NUMBER(20,0),
  CODCLASA NUMBER(20,0),
  CODGRECHIV NUMBER(20,0),
  ANF NUMBER(4,0),
  DATA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_WEEKCASHFLOW</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>BB2C588440B2E677EFE30B4B568182492CB992EB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_WEEKCASHFLOW (
  CODCASHFLOW NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SAPTAMANA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  TIP NUMBER(1,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_WEEKCASHFLOW1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>310273A101E08AB1D0E70DB4F58D10F35C8610BB</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_WEEKCASHFLOW1 (
  CODCASHFLOW1 NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  INDEXTIPLINIE VARCHAR2(10),
  INDEXLOCAL VARCHAR2(10),
  INDEXSECUNDAR VARCHAR2(10),
  TITLU VARCHAR2(10),
  DENUMIRE VARCHAR2(100),
  SIMBOLCONT VARCHAR2(100),
  VALOARE NUMBER(20,7),
  RESTANTE NUMBER(20,7),
  VIZIBIL NUMBER(1,0),
  CODPART NUMBER(20,0),
  HEADERFOOTER NUMBER(1,0),
  AREDETALII NUMBER(1,0),
  DETALIU NUMBER(1,0),
  EXPANDAT NUMBER(1,0),
  ESTETOTAL NUMBER(1,0),
  EDITABIL NUMBER(1,0),
  OBS VARCHAR2(50),
  WEEK1 NUMBER(20,7),
  WEEK2 NUMBER(20,7),
  WEEK3 NUMBER(20,7),
  WEEK4 NUMBER(20,7),
  WEEK5 NUMBER(20,7),
  WEEK6 NUMBER(20,7),
  WEEK7 NUMBER(20,7),
  WEEK8 NUMBER(20,7),
  WEEK9 NUMBER(20,7),
  WEEK10 NUMBER(20,7),
  WEEK11 NUMBER(20,7),
  WEEK12 NUMBER(20,7),
  WEEK13 NUMBER(20,7),
  WEEK14 NUMBER(20,7),
  WEEK15 NUMBER(20,7),
  WEEK16 NUMBER(20,7),
  WEEK17 NUMBER(20,7),
  WEEK18 NUMBER(20,7),
  WEEK19 NUMBER(20,7),
  WEEK20 NUMBER(20,7),
  WEEK21 NUMBER(20,7),
  WEEK22 NUMBER(20,7),
  WEEK23 NUMBER(20,7),
  WEEK24 NUMBER(20,7),
  WEEK25 NUMBER(20,7),
  WEEK26 NUMBER(20,7),
  WEEK27 NUMBER(20,7),
  WEEK28 NUMBER(20,7),
  WEEK29 NUMBER(20,7),
  WEEK30 NUMBER(20,7),
  WEEK31 NUMBER(20,7),
  WEEK32 NUMBER(20,7),
  WEEK33 NUMBER(20,7),
  WEEK34 NUMBER(20,7),
  WEEK35 NUMBER(20,7),
  WEEK36 NUMBER(20,7),
  WEEK37 NUMBER(20,7),
  WEEK38 NUMBER(20,7),
  WEEK39 NUMBER(20,7),
  WEEK40 NUMBER(20,7),
  WEEK41 NUMBER(20,7),
  WEEK42 NUMBER(20,7),
  WEEK43 NUMBER(20,7),
  WEEK44 NUMBER(20,7),
  WEEK45 NUMBER(20,7),
  WEEK46 NUMBER(20,7),
  WEEK47 NUMBER(20,7),
  WEEK48 NUMBER(20,7),
  WEEK49 NUMBER(20,7),
  WEEK50 NUMBER(20,7),
  WEEK51 NUMBER(20,7),
  WEEK52 NUMBER(20,7),
  PESTE52 NUMBER(20,7),
  CODDOC NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_WEEKCASHPLATI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>18C8427BFA36B81F1A473A11C8B0556E06CCCE5A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_WEEKCASHPLATI (
  CODCASHPLATI NUMBER(20,0),
  CODCASHFLOW1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  DATAPLATA DATE,
  SUMAPLATA NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMENOBLIG DATE,
  RESTOBLIG NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODBANKCONT NUMBER(20,0),
  CODPART NUMBER(20,0),
  DEN_PART VARCHAR2(100),
  CODMONEDA NUMBER(20,0),
  SIMBOLMONEDA VARCHAR2(5),
  SIMBOLCONT VARCHAR2(100),
  OLDSUMAPLATA NUMBER(20,7),
  OLDDATAPLATA DATE,
  RESTOBLIGRAMAS NUMBER(20,7),
  OLDTERMENOBLIG DATE,
  DEN_CONT VARCHAR2(60),
  OLDCODBANKCONT NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_WEEKCASHPLATI_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>85CA05D906A842967726F4086A4ED8E2C944A853</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_WEEKCASHPLATI_INI (
  CODCASHPLATI NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_WEEKCASHSOLD</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>789973D0C1E21D50FD29E570421B629B1300C6C2</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_WEEKCASHSOLD (
  CODSOLD NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  SOLD NUMBER(20,7),
  PLATI NUMBER(20,7),
  REST NUMBER(20,7),
  CODLIMCREDIT NUMBER(20,0),
  CODMONEDA NUMBER(20,0),
  DEN_CONT VARCHAR2(60)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ZEURO</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>A4BFEC0EA07847F0603FFFBBFE00F689FD99C9C3</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ZEURO (
  COD NUMBER(20,0),
  CODCASA NUMBER(20,0),
  PLU NUMBER(20,7),
  DEP NUMBER(10,0),
  OBIECT NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CONT NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  STOC NUMBER(20,7),
  VANDUT NUMBER(20,7),
  CODMONETAR NUMBER(20,0),
  Z NUMBER(20,0),
  DATAZ DATE,
  SERVICIU NUMBER(1,0),
  DEN_OBIECT VARCHAR2(250),
  UM NUMBER(20,0),
  UM1 NUMBER(20,0),
  UM2 NUMBER(20,0),
  DEN_UM VARCHAR2(50),
  CODTVA NUMBER(20,0),
  PROCENT NUMBER(20,7),
  CONTSERV NUMBER(20,0),
  SIMBOLCONTSERV VARCHAR2(30),
  VALDISCPRET NUMBER(20,7)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ZILE</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>ABF8D1F5FD45E10ED64FC086554EDCB7D6356178</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ZILE (
  ZIUA DATE NOT NULL
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ZINELUC</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>41FFE84FD358FC72184C3FA5BBB95D395F254F58</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ZINELUC (
  CODZINELUC NUMBER(20,0),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  ANCAL NUMBER(4,0),
  LUNACAL NUMBER(2,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TMP_ZINELUC1</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>237B5FA1C03521C326CAF51CE75DA8F055E656EF</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TMP_ZINELUC1 (
  CODZINELUC1 NUMBER(20,0),
  CODZINELUC NUMBER(20,0),
  ZI NUMBER(2,0),
  DATA DATE
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TM__NMVS_SERII_INI</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>88D92B3E5C12AA7DF71765E06DCB12319CB61B7A</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TM__NMVS_SERII_INI (
  COD NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TOTALPUNCTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0789C2D8BEB96A1477A1BBC92909CB259B6F0AD1</HASHVAL>
  <TEXT>CREATE TABLE TOTALPUNCTE (
  COD NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODPUNCTAJ NUMBER(20,0),
  PUNCTE NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODPOSTRETAIL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TOWORD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A11FC1746E18DEA4A93E6E5AF00BBFD5E952312</HASHVAL>
  <TEXT>CREATE TABLE TOWORD (
  CODTOWORD NUMBER(20,0) NOT NULL,
  CODDOC NUMBER(20,0),
  NUMEDOC VARCHAR2(50),
  SQLVIEW VARCHAR2(200),
  SQLDATE VARCHAR2(200),
  SQLLINII VARCHAR2(200),
  CALE VARCHAR2(200),
  NUMEVIEW VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSACARD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B31FBF1A5962985DA6A204C02ACFAEE73D120444</HASHVAL>
  <TEXT>CREATE TABLE TRANSACARD (
  CODTRANSACARD NUMBER(20,0) NOT NULL,
  CODEMULARE NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSEINI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD058F7A8B388BB802E851638375EBE5795F54FA</HASHVAL>
  <TEXT>CREATE TABLE TRANSEINI (
  CODBANKCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69355ABFF9BD2E4FFF5BE12A4AAA381F3D6081EE</HASHVAL>
  <TEXT>CREATE TABLE TRANSF (
  CODTRANSF NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  ANULAT NUMBER(20,0),
  BLOCAT NUMBER(20,0),
  OPERAT NUMBER(20,0),
  PREFIXDOC VARCHAR2(2),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  CARNETAE NUMBER(20,0),
  NRAE NUMBER(20,0),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  VALSUPLIM NUMBER(20,7),
  CONTSUPLIM NUMBER(20,0),
  TIPREPSUPLIM NUMBER(1,0),
  OBS VARCHAR2(250),
  SUBUNITATEA NUMBER(20,0),
  DELEGAT NUMBER(20,0),
  CODPART NUMBER(20,0),
  TIPMODIFPRET NUMBER(1,0),
  STORNO NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  MIJLTRANSP VARCHAR2(15),
  NRTRANSP VARCHAR2(30),
  CODGESTCMD NUMBER(20,0),
  LISTAT NUMBER(1,0),
  REEVALUARE NUMBER(1,0),
  SERIADOC VARCHAR2(20),
  IDIMPORT VARCHAR2(30),
  CODANALIZA NUMBER(20,0),
  AJUSTVALSTOC NUMBER(1,0),
  STADIUWMS NUMBER(2,0),
  SUBUNITDEST NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  TIPET NUMBER(6,0),
  IS_ETRANSP NUMBER(1,0),
  CORECTIE NUMBER(6,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSF1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>55991753F74DB764979001B4330A051DE3805277</HASHVAL>
  <TEXT>CREATE TABLE TRANSF1 (
  CODTRANSF1 NUMBER(20,0) NOT NULL,
  CODTRANSF NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  OBS CLOB,
  CODCONT NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  COSTTRANSPORT NUMBER(20,7),
  CODMIFIX NUMBER(20,0),
  PUVAL NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  CODAUTO NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODLINIEDOCIMP NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSF1_MAN</NAME>
  <TEMP>Y</TEMP>
  <HASHVAL>492F3C74D2F6CBC1B4304FF26B75FBEE25D32B59</HASHVAL>
  <TEXT>CREATE GLOBAL TEMPORARY TABLE TRANSF1_MAN (
  CODTRANSF1 NUMBER(20,0),
  CODTRANSF NUMBER(20,0),
  INDEXLOCAL NUMBER(20,0),
  TIPLINIE VARCHAR2(1),
  UMSEC NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  PU NUMBER(20,7),
  CANT NUMBER(20,7),
  TVA NUMBER(20,7),
  OBS CLOB,
  CODCONT NUMBER(20,0),
  PUMAXIMAL NUMBER(20,7),
  COSTTRANSPORT NUMBER(20,7),
  CODMIFIX NUMBER(20,0),
  PUVAL NUMBER(20,7),
  CODCENTRU NUMBER(20,0),
  CODRETETA NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODANALIZANOD NUMBER(20,0),
  D1 NUMBER(20,7),
  D2 NUMBER(20,7),
  D3 NUMBER(20,7),
  CANTUM1 NUMBER(20,7),
  PRELUAT NUMBER(1,0),
  CODOBIECTORIG NUMBER(20,0),
  PARITATEORIG NUMBER(20,7),
  CANTUM2 NUMBER(20,7),
  CODAUTO NUMBER(20,0),
  CODEMULARE1 NUMBER(20,0),
  TIPDOCIMP NUMBER(5,0),
  CODLINIEDOCIMP NUMBER(20,0)
) ON COMMIT PRESERVE ROWS</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSFLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93593130B735031D59C0E4036DA65D09316C1B41</HASHVAL>
  <TEXT>CREATE TABLE TRANSFLINK (
  CODTRANSF1 NUMBER(20,0),
  CODLINIECOMANDA NUMBER(20,0),
  CANT NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E91F650CB28192F28F36896842DED2FF37EA767</HASHVAL>
  <TEXT>CREATE TABLE TRANSPORT (
  CODTRANSPORT NUMBER(20,0) NOT NULL,
  DATATRANSPORT TIMESTAMP(6),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  SUBUNITATE NUMBER(20,0),
  INDICATIV VARCHAR2(100),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  ANULAT NUMBER(1,0),
  AN NUMBER(20,0),
  LUNA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TIPREPART NUMBER(1,0),
  CODPARCAUTO NUMBER(20,0),
  CODSOFER NUMBER(20,0),
  COLETE NUMBER(1,0),
  REP_TRANSF NUMBER(1,0),
  REP_SUBUNIT NUMBER(1,0),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSPORT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6E85BD76F3E2B75D5B01E915CFCA6F065B0FB8A</HASHVAL>
  <TEXT>CREATE TABLE TRANSPORT1 (
  CODTRANSPORT1 NUMBER(20,0) NOT NULL,
  CODTRANSPORT NUMBER(20,0),
  CODCOLET NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRANSPORT2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C85F2D7F45B877204AAF8F2A650775883C2148DD</HASHVAL>
  <TEXT>CREATE TABLE TRANSPORT2 (
  CODTRANSPORT2 NUMBER(20,0) NOT NULL,
  CODTRANSPORT NUMBER(20,0),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(10,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRASEU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9CACD8B4D4C9CA1914B534AF4CC1A23F719E1927</HASHVAL>
  <TEXT>CREATE TABLE TRASEU (
  CODTRASEU NUMBER(20,0) NOT NULL,
  CODFISASUP NUMBER(20,0),
  INDEXLOCAL NUMBER(10,0),
  POZT NUMBER(10,0),
  EXECUTANT NUMBER(20,0),
  CLASATEH NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRASEULIVR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A23FA37359C863F1E8526902387745981088EDF</HASHVAL>
  <TEXT>CREATE TABLE TRASEULIVR (
  CODTRASEULIVR NUMBER(20,0) NOT NULL,
  DENTRASEU VARCHAR2(100),
  SIMBOLTRASEU VARCHAR2(20),
  OPRIRI NUMBER(10,0),
  ORE NUMBER(10,0),
  MINUTE NUMBER(2,0),
  TIP NUMBER(2,0),
  LAT NUMBER(20,7),
  LNG NUMBER(20,7),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1DC76A9F49BAB9155E83EAC0548F32F8F6AEC04F</HASHVAL>
  <TEXT>CREATE TABLE TREZOR (
  CODTREZOR NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(20,0),
  CODBANCA NUMBER(20,0),
  ICONTPERS NUMBER(20,0),
  MONEDAPERS NUMBER(20,0),
  DATADOC DATE,
  NUMEDOC VARCHAR2(50),
  AN NUMBER(5,0),
  LUNA NUMBER(2,0),
  AGENT NUMBER(20,0),
  OPERAT NUMBER(1,0),
  BLOCAT NUMBER(1,0),
  SUBUNITATEA NUMBER(20,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  DATAINREG TIMESTAMP(6),
  IDIMPORT VARCHAR2(30),
  CODANALIZA NUMBER(20,0),
  CARNETDOC NUMBER(20,0),
  NRDOC NUMBER(20,0),
  SERIADOC VARCHAR2(20),
  LISTAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TREZOR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AFE994ABB021C4AEBA8D6740C856E871B9ECF87</HASHVAL>
  <TEXT>CREATE TABLE TREZOR1 (
  CODTREZOR1 NUMBER(20,0) NOT NULL,
  CODTREZOR NUMBER(20,0),
  INDEXLOCAL NUMBER(5,0),
  TIPTRANZ NUMBER(1,0),
  CARNETDOC NUMBER(20,0),
  DOC VARCHAR2(30),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  VALDOC NUMBER(20,7),
  CURS NUMBER(20,7),
  COMISION NUMBER(20,7),
  OBIECTTRANZ NUMBER(20,0),
  CODPART NUMBER(10,0),
  TIPDECONT NUMBER(1,0),
  DATADECONT DATE,
  AN NUMBER(7,0),
  LUNA NUMBER(2,0),
  OBS VARCHAR2(200),
  INITIALIZARI NUMBER(1,0),
  AGENT NUMBER(20,0),
  ANULAT NUMBER(1,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6),
  CODLOCATIE NUMBER(20,0),
  CODCENTRU NUMBER(20,0),
  SERIEDOC VARCHAR2(20),
  CODSERTAR NUMBER(20,0),
  NRI VARCHAR2(40),
  CODCOMANDA NUMBER(20,0),
  PLATATVA NUMBER(1,0),
  CODGEST NUMBER(20,0),
  CODCMDINT1 NUMBER(20,0),
  CODPLATA1 NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TREZOR1_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECDD00761D6FBE6DD42DBE20DC9CE034FA5B1B07</HASHVAL>
  <TEXT>CREATE TABLE TREZOR1_REG (
  CODREG NUMBER(20,0),
  CODTREZOR1 NUMBER(20,0),
  CURS NUMBER(20,4),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TREZORRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D20027E189947FDF2A07E8C86DE4EE57500779A7</HASHVAL>
  <TEXT>CREATE TABLE TREZORRETAIL (
  CODTREZOR NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRIGAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5858FE85B02E4627B8A280688088FB7B9409BA3E</HASHVAL>
  <TEXT>CREATE TABLE TRIGAR (
  CODTRIGAR NUMBER(20,0) NOT NULL,
  TABLENAME VARCHAR2(20),
  TRIG CLOB,
  VARIABILE CLOB,
  TIP NUMBER(1,0),
  OPERATIE NUMBER(1,0),
  MOMENT NUMBER(1,0),
  MASTERFIELD VARCHAR2(20),
  MASTERTABLE VARCHAR2(20),
  MAINTABLE VARCHAR2(20),
  INITIATOR NUMBER(20,0),
  DESTINATAR VARCHAR2(300),
  SUBIECT VARCHAR2(200),
  ANTET VARCHAR2(2000),
  FINAL VARCHAR2(2000),
  OBS VARCHAR2(500),
  INACTIV NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRIGAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C9D1485D0ACC3E22FFC8189F0E4BB2120DE52535</HASHVAL>
  <TEXT>CREATE TABLE TRIGAR1 (
  CODTRIGAR1 NUMBER(20,0) NOT NULL,
  CODTRIGAR NUMBER(20,0),
  FIELDNAME VARCHAR2(20)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TRIGAR_MODIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6641E7573B19DE89D8C73F62205193277B735A3C</HASHVAL>
  <TEXT>CREATE TABLE TRIGAR_MODIF (
  DATAMODIF DATE,
  USERMODIF NUMBER(10,0),
  CODMASTER NUMBER(20,0),
  COD NUMBER(20,0),
  TABLENAME VARCHAR2(20),
  FIELDNAME VARCHAR2(20),
  OLDVALUE VARCHAR2(100),
  NEWVALUE VARCHAR2(100),
  CODMODIF NUMBER(20,0) NOT NULL
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TVAMONETAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF2450D9A0007D9DF73F657DE8D119535FEE1BC8</HASHVAL>
  <TEXT>CREATE TABLE TVAMONETAR (
  CODTVAMONETAR NUMBER(20,0),
  CODIES NUMBER(20,0),
  BONURI NUMBER(5,0),
  CODTVA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  TVA NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TVASERV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F988C43D7777885BAF2C841F9BB2A6C0C742AE96</HASHVAL>
  <TEXT>CREATE TABLE TVASERV (
  CODTVASERV NUMBER(20,0) NOT NULL,
  DENUMIRE VARCHAR2(200),
  CODTARA NUMBER(20,0),
  TIPCOTA NUMBER(10,0),
  PROCENT NUMBER(20,7),
  CODCONT NUMBER(20,0),
  SIMBOL VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>TVASERV1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9C468286628389D0A3950DCC5172756D3F7D22B</HASHVAL>
  <TEXT>CREATE TABLE TVASERV1 (
  CODTVASERV1 NUMBER(20,0) NOT NULL,
  CODTVASERV NUMBER(20,0),
  CODCONT NUMBER(20,0),
  ANSTART NUMBER(4,0),
  LUNASTART NUMBER(2,0),
  ALSTART NUMBER(5,0),
  ALSTOP NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>USERSQL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ECCD4DEAD29A3C23EA4E6714AF8D809076314EC2</HASHVAL>
  <TEXT>CREATE TABLE USERSQL (
  CODSQL NUMBER(20,0),
  DENUMIRE VARCHAR2(100),
  OBS VARCHAR2(200),
  USERID NUMBER(20,0),
  DATACREARE DATE,
  SQLTEXT CLOB,
  WHERECLAUSE VARCHAR2(1000),
  REZULTAT VARCHAR2(1000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>USERSQL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>67872C2D1D92CD1080D391CCAD5F1E5F4991B94D</HASHVAL>
  <TEXT>CREATE TABLE USERSQL1 (
  CODSQL1 NUMBER(20,0),
  CODSQL NUMBER(20,0),
  TABLA VARCHAR2(50),
  NUME VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>USERSQL2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD992D424FCFB8423120B9164A16A66D542CB445</HASHVAL>
  <TEXT>CREATE TABLE USERSQL2 (
  CODSQL2 NUMBER(20,0),
  CODSQL NUMBER(20,0),
  CODSQL1 NUMBER(20,0),
  TIPJOIN NUMBER(1,0),
  JOINON VARCHAR2(100),
  JOINWHERE VARCHAR2(100)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>USER_ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D515E46B9AA7FBD68028EEC6AC7EF0FB784CEFF</HASHVAL>
  <TEXT>CREATE TABLE USER_ALERTE (
  USERID NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D500E6E6129737A5E8B294775B5C52BCB72999E0</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE (
  CODUTILAJ NUMBER(20,0) NOT NULL,
  CODOBIECT NUMBER(20,0),
  NRINVENTAR NUMBER(20,0),
  ETICHETA VARCHAR2(50),
  TIPUTILAJ VARCHAR2(50),
  FLOTA VARCHAR2(50),
  MODEL VARCHAR2(50),
  ANF NUMBER(4,0),
  SERIEF VARCHAR2(50),
  INCARCARE NUMBER(10,0),
  DATAGARANTIE DATE,
  INGARANTIE NUMBER(1,0),
  LUNGIME NUMBER(20,7),
  LATIME NUMBER(20,7),
  INALTIME NUMBER(20,7),
  OBS VARCHAR2(300),
  INACTIV NUMBER(1,0),
  CORECTIEINDEX NUMBER(10,0),
  UM NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7),
  CODGEST NUMBER(20,0),
  CODPART NUMBER(20,0),
  CODIES1 NUMBER(20,0),
  DATAGARANTIEI DATE,
  APROBAT NUMBER(1,0),
  DATASTART DATE,
  NRCONTR VARCHAR2(50),
  DATACONTR DATE,
  CODFURNIZOR NUMBER(20,0),
  DOC VARCHAR2(50),
  TIP NUMBER(5,0),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(250),
  HFACTOR NUMBER(2,0),
  AGENT NUMBER(20,0),
  CODPRODUCATOR NUMBER(20,0),
  CODLOCATIE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>938A94661B3C4001C003CC93FDE4653CB8250B66</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE1 (
  CODUTILAJ1 NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  NRCONTR VARCHAR2(20),
  CARNETCONTR VARCHAR2(20),
  STATUS_PART NUMBER(1,0),
  STATUS_DEPO NUMBER(1,0),
  CODPART NUMBER(20,0),
  CODLOCATIE NUMBER(20,0),
  DATA DATE,
  USERID NUMBER(20,0),
  DATACREARE DATE,
  OBS VARCHAR2(200),
  STATUS_SERVICE NUMBER(1,0),
  INDEXLOCAL NUMBER(10,0),
  CODPERS NUMBER(20,0),
  ESTETIC NUMBER(5,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF3E2B0DA84312ACB698F1B0A19308ED7B663360</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE2 (
  CODUTILAJ2 NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  INTERVENTIE NUMBER(20,0),
  CODCOMANDA1 NUMBER(20,0),
  CODUTILAJ20 NUMBER(20,0),
  CODAUTO NUMBER(20,0),
  KMPARCURSI NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE20</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D90AEBE240DBF422FB04977148E26CF68E01EC74</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE20 (
  CODUTILAJ20 NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRIERE VARCHAR2(2500),
  STARE NUMBER(5,0),
  OPERATOR NUMBER(20,0),
  OBS VARCHAR2(500),
  CODIES NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(250),
  CODPERSC NUMBER(20,0),
  CALLCENTER NUMBER(1,0),
  CODBC NUMBER(20,0),
  PRIORITATE VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE20_MON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B65AA0F46B7B32DF0DB0E9A7E9634E77AFF35BA6</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE20_MON (
  CODUTILAJ20 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  DESCRIERE VARCHAR2(2500),
  STARE NUMBER(5,0),
  OPERATOR NUMBER(20,0),
  OBS VARCHAR2(500),
  CODIES NUMBER(20,0),
  CODLOCALIT NUMBER(20,0),
  ADRESA VARCHAR2(250),
  DENOPERATOR VARCHAR2(50),
  FACTURARE VARCHAR2(50),
  DEVIZ NUMBER(1,0),
  DATAMODIF DATE,
  CODBC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE2C</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F67E2EBEDAB01A6EFAAA199F2AC30ECC8FFBCB95</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE2C (
  CODUTILAJ2C NUMBER(20,0) NOT NULL,
  CODUTILAJ2 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  INDEXC NUMBER(10,0),
  DATAINDEXC DATE,
  CODCOMANDA1 NUMBER(20,0),
  EXPLICATII CLOB,
  DATASTART TIMESTAMP(6),
  DATAEND TIMESTAMP(6),
  INDEXV NUMBER(10,0),
  DATAV DATE,
  RESETAT NUMBER(1,0),
  INDEXLOCAL NUMBER(10,0),
  ORESTART NUMBER(7,3),
  ORESTOP NUMBER(7,3)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE2P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>879C3F3C0484A679D4905824D6F95F77724A82FA</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE2P (
  CODUTILAJ2P NUMBER(20,0) NOT NULL,
  CODUTILAJ2 NUMBER(20,0),
  CODUTILAJ NUMBER(20,0),
  CODPERS NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJE3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0045FE45728311A5CEE2BB1C431925B6D13AC18C</HASHVAL>
  <TEXT>CREATE TABLE UTILAJE3 (
  CODUTILAJ3 NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  DATABORD DATE,
  INDEXBORD NUMBER(20,7),
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  CORECTIEINDEX NUMBER(10,0),
  TIP_INDEX NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJEDEV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>816C5F74B2B0FC6E378211088A09E67E3E2B5F0E</HASHVAL>
  <TEXT>CREATE TABLE UTILAJEDEV (
  CODUTILAJDEV NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  CODUTILAJ20 NUMBER(20,0),
  CODOBIECT NUMBER(20,0),
  CANT NUMBER(20,7),
  PRET NUMBER(20,7),
  CANTFACT NUMBER(20,7),
  FACTURABIL NUMBER(1,0),
  CODIES1 NUMBER(20,0),
  CODUTILAJ2 NUMBER(20,0),
  TIPLIVRARE NUMBER(20,0),
  TVA NUMBER(20,7),
  CONSUMABIL NUMBER(1,0),
  CANTCONS NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJEMON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3613489B2B95BE656C8C9AC2D4CF15772693B133</HASHVAL>
  <TEXT>CREATE TABLE UTILAJEMON (
  CODMONITORIZARE NUMBER(20,0) NOT NULL,
  CODUTILAJ20 NUMBER(20,0),
  USERID NUMBER(20,0),
  DATAMODIF TIMESTAMP(6),
  STAREV NUMBER(5,0),
  STAREN NUMBER(5,0),
  TIPMODIF VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>UTILAJETIPINDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF27DEE8ACC3DD6E3C84CF1DE3470EDB22E13A15</HASHVAL>
  <TEXT>CREATE TABLE UTILAJETIPINDEX (
  CODTINDEX NUMBER(20,0) NOT NULL,
  CODUTILAJ NUMBER(20,0),
  TIP_INDEX NUMBER(1,0),
  DENUMIRE VARCHAR2(100),
  UM NUMBER(20,0),
  PLAFONCANTF NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VALATREXCEPTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28B42DA4A28DB10A16A23DB84414CCBB243980B3</HASHVAL>
  <TEXT>CREATE TABLE VALATREXCEPTII (
  CODEXCEPTIE NUMBER(20,0),
  CODVALATR NUMBER(20,0),
  CODARTICOL NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VANZARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2593D172D9CC118440ABA577C429F669F4E9397</HASHVAL>
  <TEXT>CREATE TABLE VANZARI (
  CODVANZARE NUMBER(20,0),
  CODPART NUMBER(20,0),
  DATADOC TIMESTAMP(6),
  VALDOC NUMBER(20,7),
  TVADOC NUMBER(20,7),
  VALDISCOUNT NUMBER(20,7),
  TVADISCOUNT NUMBER(20,7),
  CODEMULARE NUMBER(20,0),
  CODEMULAREFACT NUMBER(20,0),
  OBS VARCHAR2(200)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VARIABILE_SESIUNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D8D5C346055AEC1E1E103850387BC94021697BF</HASHVAL>
  <TEXT>CREATE TABLE VARIABILE_SESIUNE (
  CODJOB1 NUMBER(20,0),
  SQL_EXEC VARCHAR2(4000),
  TIP_SQL NUMBER(1,0),
  ORDINE NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VERSION</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F84BDC8157192EBBA66C0F9ABCAFA86096F981E0</HASHVAL>
  <TEXT>CREATE TABLE VERSION (
  VERSION NUMBER(10,8) NOT NULL,
  JOBOK NUMBER(1,0),
  MINRETAIL NUMBER(10,8),
  MINRESTAURANT NUMBER(10,8)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VIEW_JOINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>69DCCEBF6A8BED5A5B58202C42E0ECB977576C9A</HASHVAL>
  <TEXT>CREATE TABLE VIEW_JOINS (
  CODVIEW_JOINS NUMBER(20,0) NOT NULL,
  VIEWNAME VARCHAR2(50),
  JOINURI VARCHAR2(3000)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>071E70FAFF77E15141E3AB10D49225F1A934D63D</HASHVAL>
  <TEXT>CREATE TABLE VOUCHER (
  CODVOUCHER NUMBER(20,0) NOT NULL,
  CODPARTENER NUMBER(20,0),
  OBS VARCHAR2(100),
  DATASTART DATE,
  DATASTOP DATE,
  MONEDA NUMBER(20,0),
  VALOARE NUMBER(20,7),
  CODCMD NUMBER(20,0),
  CODIES NUMBER(20,0),
  CODGEST NUMBER(20,0),
  OBS1 VARCHAR2(500)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VOUCHERCADOU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A89E606A2072B843458B4CDC9C1DDE02D7722248</HASHVAL>
  <TEXT>CREATE TABLE VOUCHERCADOU (
  COD NUMBER(20,0) NOT NULL,
  BARCODE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  DATASTART TIMESTAMP(6),
  DATASTOP TIMESTAMP(6),
  IS_USED NUMBER(1,0),
  USED_DATE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VOUCHERCADOULINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10A0A8DC5A07908EE2322F6BFFE1D09242492C05</HASHVAL>
  <TEXT>CREATE TABLE VOUCHERCADOULINK (
  COD NUMBER(20,0) NOT NULL,
  TIPDOC NUMBER(5,0),
  CODDOC NUMBER(20,0),
  TIPOPERATIE NUMBER(1,0),
  BARCODE VARCHAR2(50),
  VALOARE NUMBER(20,7),
  DATASTART TIMESTAMP(6),
  DATASTOP TIMESTAMP(6),
  ZILEVALABIL NUMBER(5,0),
  CODOBIECT NUMBER(20,0),
  POSTAT NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>VOUCHERLINK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F7AC7DECF10C4288B1D53F1EF1D425357C4C928</HASHVAL>
  <TEXT>CREATE TABLE VOUCHERLINK (
  CODVLINK NUMBER(20,0) NOT NULL,
  CODVOUCHER NUMBER(20,0) NOT NULL,
  CODCMD NUMBER(20,0),
  CODIES NUMBER(20,0),
  VALOARE NUMBER(20,7)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WEEKCASHFLOW</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BAF3DF917CE312D3B7C7FBA3C290F7C8BDD49516</HASHVAL>
  <TEXT>CREATE TABLE WEEKCASHFLOW (
  CODCASHFLOW NUMBER(20,0) NOT NULL,
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  SAPTAMANA NUMBER(2,0),
  SUBUNITATEA NUMBER(20,0),
  TIP NUMBER(1,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WEEKCASHFLOW1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1CF77B37A073BEEC72270D8F82B8BF97A42E1EA7</HASHVAL>
  <TEXT>CREATE TABLE WEEKCASHFLOW1 (
  CODCASHFLOW1 NUMBER(20,0) NOT NULL,
  CODCASHFLOW NUMBER(20,0),
  INDEXTIPLINIE VARCHAR2(10),
  INDEXLOCAL VARCHAR2(10),
  INDEXSECUNDAR VARCHAR2(10),
  TITLU VARCHAR2(10),
  DENUMIRE VARCHAR2(100),
  SIMBOLCONT VARCHAR2(100),
  VALOARE NUMBER(20,7),
  RESTANTE NUMBER(20,7),
  VIZIBIL NUMBER(1,0),
  CODPART NUMBER(20,0),
  HEADERFOOTER NUMBER(1,0),
  AREDETALII NUMBER(1,0),
  DETALIU NUMBER(1,0),
  EXPANDAT NUMBER(1,0),
  ESTETOTAL NUMBER(1,0),
  EDITABIL NUMBER(1,0),
  OBS VARCHAR2(50),
  WEEK1 NUMBER(20,7),
  WEEK2 NUMBER(20,7),
  WEEK3 NUMBER(20,7),
  WEEK4 NUMBER(20,7),
  WEEK5 NUMBER(20,7),
  WEEK6 NUMBER(20,7),
  WEEK7 NUMBER(20,7),
  WEEK8 NUMBER(20,7),
  WEEK9 NUMBER(20,7),
  WEEK10 NUMBER(20,7),
  WEEK11 NUMBER(20,7),
  WEEK12 NUMBER(20,7),
  WEEK13 NUMBER(20,7),
  WEEK14 NUMBER(20,7),
  WEEK15 NUMBER(20,7),
  WEEK16 NUMBER(20,7),
  WEEK17 NUMBER(20,7),
  WEEK18 NUMBER(20,7),
  WEEK19 NUMBER(20,7),
  WEEK20 NUMBER(20,7),
  WEEK21 NUMBER(20,7),
  WEEK22 NUMBER(20,7),
  WEEK23 NUMBER(20,7),
  WEEK24 NUMBER(20,7),
  WEEK25 NUMBER(20,7),
  WEEK26 NUMBER(20,7),
  WEEK27 NUMBER(20,7),
  WEEK28 NUMBER(20,7),
  WEEK29 NUMBER(20,7),
  WEEK30 NUMBER(20,7),
  WEEK31 NUMBER(20,7),
  WEEK32 NUMBER(20,7),
  WEEK33 NUMBER(20,7),
  WEEK34 NUMBER(20,7),
  WEEK35 NUMBER(20,7),
  WEEK36 NUMBER(20,7),
  WEEK37 NUMBER(20,7),
  WEEK38 NUMBER(20,7),
  WEEK39 NUMBER(20,7),
  WEEK40 NUMBER(20,7),
  WEEK41 NUMBER(20,7),
  WEEK42 NUMBER(20,7),
  WEEK43 NUMBER(20,7),
  WEEK44 NUMBER(20,7),
  WEEK45 NUMBER(20,7),
  WEEK46 NUMBER(20,7),
  WEEK47 NUMBER(20,7),
  WEEK48 NUMBER(20,7),
  WEEK49 NUMBER(20,7),
  WEEK50 NUMBER(20,7),
  WEEK51 NUMBER(20,7),
  WEEK52 NUMBER(20,7),
  PESTE52 NUMBER(20,7),
  CODDOC NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WEEKCASHPLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5D578B96D377B7121877BD25DEC59948AEAB9B7</HASHVAL>
  <TEXT>CREATE TABLE WEEKCASHPLATI (
  CODCASHPLATI NUMBER(20,0),
  CODCASHFLOW1 NUMBER(20,0),
  CODOBLIGPIF NUMBER(20,0),
  DATAPLATA DATE,
  SUMAPLATA NUMBER(20,7),
  PREFIXDOC VARCHAR2(2),
  NRDOC NUMBER(20,0),
  DATADOC DATE,
  TERMENOBLIG DATE,
  RESTOBLIG NUMBER(20,7),
  CODDOC NUMBER(20,0),
  TIPDOC NUMBER(5,0),
  CODBANKCONT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WEEKCASHSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0E376CAEA3C294BE5902A4978AC189BAAE0E58C3</HASHVAL>
  <TEXT>CREATE TABLE WEEKCASHSOLD (
  CODSOLD NUMBER(20,0),
  CODCASHFLOW NUMBER(20,0),
  CODBANKCONT NUMBER(20,0),
  SOLD NUMBER(20,7),
  PLATI NUMBER(20,7),
  REST NUMBER(20,7),
  CODLIMCREDIT NUMBER(20,0)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WME_FLAGS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>29D42F7368566870D855B25A509D3C1B7975147C</HASHVAL>
  <TEXT>CREATE TABLE WME_FLAGS (
  SPV_EFACT_READALL NUMBER(1,0),
  CIF VARCHAR2(30)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>WM_FLAG_TMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9EBAAC0E2491BFAD75150C7EF2796D10CF630BA</HASHVAL>
  <TEXT>CREATE TABLE WM_FLAG_TMP (
  TMP_NAME VARCHAR2(30),
  FLAG VARCHAR2(50)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>X</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC0ED49B1466FB724768A4E07E44EB6AA0CC9F28</HASHVAL>
  <TEXT>CREATE TABLE X (
  VIEW_NAME VARCHAR2(30),
  TEST CLOB
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>XXX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0B78EBB83E76B33C720E7B7F9C26574DB755EB5</HASHVAL>
  <TEXT>CREATE TABLE XXX (
  XXX VARCHAR2(1)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ZEURO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8080A173304DE9C7A4A80D69FF944283D004685F</HASHVAL>
  <TEXT>CREATE TABLE ZEURO (
  COD NUMBER(20,0) NOT NULL,
  CODCASA NUMBER(20,0),
  PLU NUMBER(20,7),
  DEP NUMBER(10,0),
  OBIECT NUMBER(20,0),
  GESTIUNE NUMBER(20,0),
  CONT NUMBER(20,0),
  TVA NUMBER(20,7),
  PRET NUMBER(20,7),
  STOC NUMBER(20,7),
  VANDUT NUMBER(20,7),
  CODMONETAR NUMBER(20,0),
  Z NUMBER(20,0),
  DATAZ DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ZINELUC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2539B16CD5AEC53CFE44679E6EA7B399D7DF15E3</HASHVAL>
  <TEXT>CREATE TABLE ZINELUC (
  CODZINELUC NUMBER(20,0) NOT NULL,
  AN NUMBER(4,0),
  LUNA NUMBER(2,0),
  USERID NUMBER(20,0),
  DATACREARE TIMESTAMP(6)
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TABLE</TYPE>
  <NAME>ZINELUC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EED278D4A499570FDC027401005BFDCCD3927169</HASHVAL>
  <TEXT>CREATE TABLE ZINELUC1 (
  CODZINELUC1 NUMBER(20,0) NOT NULL,
  CODZINELUC NUMBER(20,0),
  ZI NUMBER(2,0),
  DATA DATE
) TABLESPACE WMDATA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>DET_CONTOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDF498002386EC1B5B60B081D9486B817416A2C0</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE DET_CONTOR AS OBJECT (
  CodContract1 NUMBER(20),
  DataRef      DATE,
  DataIni      DATE,
  IdxIni       NUMBER(20,7),
  DataFin      DATE,
  IdxFin       NUMBER(20,7),
  Cant         NUMBER(20,7)
);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>NUMBER_LIST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A9B5CEA1CAD6227FBED45E6A5143FFEDBEB6CD8</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE NUMBER_LIST IS TABLE OF NUMBER(20)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>TERMENE_CONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8F978CE7071AC1F12AAB1CAB9C791F7A3AF751B</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE TERMENE_CONTRACT AS OBJECT (
  tip       VARCHAR2(100),
  termen1   DATE,
  termen2   DATE,
  termen3   VARCHAR2(1000),
  disc1     NUMBER(20,7),
  disc2     NUMBER(20,7),
  disc3     VARCHAR2(1000)
);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>T_CLOB_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0347C2A3CB877157B669E564F8325CAC80BE46A</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE T_CLOB_AGG as object
(
   total  CLOB,
   STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_clob_agg                                       ) RETURN NUMBER,
   MEMBER FUNCTION ODCIAggregateIterate   (self IN OUT t_clob_agg, value IN CLOB                        ) RETURN NUMBER,
   MEMBER FUNCTION ODCIAggregateTerminate (self IN     t_clob_agg, returnValue OUT clob, flags IN number) RETURN NUMBER,
   MEMBER FUNCTION ODCIAggregateMerge     (self IN OUT t_clob_agg, ctx2 IN t_clob_agg                   ) RETURN NUMBER
);
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>T_OBJATRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E114EC25E5034E7A1584F075E8D8445C907D9656</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE T_OBJATRIB AS OBJECT (den VARCHAR2(50), cod VARCHAR2(50), val VARCHAR2(50));</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>T_STRAGG3200</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1BA8BCBE9BD8709A6B3A46B415D2213A990A4788</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE T_STRAGG3200 AS OBJECT
(
  g_string  VARCHAR2(3200),
  g_gata    NUMBER(1),
  STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_stragg3200) RETURN NUMBER,
  MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_stragg3200, value IN VARCHAR2) RETURN NUMBER,
  MEMBER FUNCTION ODCIAggregateTerminate(self IN t_stragg3200, returnValue OUT VARCHAR2, flags IN NUMBER) RETURN NUMBER,
  MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_stragg3200, ctx2 IN t_stragg3200) RETURN NUMBER
);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>T_STRING_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>736F2E47EE7A07C7A213805EB421651218F8F65A</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE T_STRING_AGG AS OBJECT
(
  g_string  VARCHAR2(32767),

  STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
    RETURN NUMBER,

  MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                       value  IN      VARCHAR2 )
     RETURN NUMBER,

  MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                         returnValue  OUT  VARCHAR2,
                                         flags        IN   NUMBER)
    RETURN NUMBER,

  MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                     ctx2  IN      t_string_agg)
    RETURN NUMBER
);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>VARCHAR_LIST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3FA5C997DC43A89B3005DA35E246DED17B4126AA</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE VARCHAR_LIST IS TABLE OF VARCHAR2(50) ;

</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>VC2X_NT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F9876411EC931CB750FC60A8ED2EC74CD34E2A24</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE VC2x_NT AS TABLE OF VARCHAR2(4000);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>VC2_NT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4CEC87C2D67247897CDF2DFD6C7274264C5480E4</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE VC2_NT AS TABLE OF VARCHAR2(3000);</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE</TYPE>
  <NAME>VC2_OBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E48564BEB93169602C01022A48E40784E232F7C3</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE VC2_OBJ AS OBJECT (VC2 VARCHAR2(3000));</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE BODY</TYPE>
  <NAME>T_CLOB_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2D02A0CD3308E7C630EDE5E3DC514852ED45873</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE BODY T_CLOB_AGG IS
  STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_clob_agg) RETURN NUMBER IS
  BEGIN
    sctx := t_clob_agg( null );
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_clob_agg, value IN clob) RETURN NUMBER IS
    invalid_lob_locator exception;
    pragma exception_init(invalid_lob_locator, -06502);
  BEGIN
    dbms_lob.append(self.total, value);
    dbms_lob.append(self.total, PKG_GLOBALS.SEP);
    RETURN ODCIConst.Success;
  EXCEPTION
    WHEN invalid_lob_locator THEN
      dbms_lob.createtemporary(self.total, true);
      dbms_lob.append(self.total, value);
      dbms_lob.append(self.total, PKG_GLOBALS.SEP);
      RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateTerminate(self IN t_clob_agg, returnValue OUT clob, flags IN number) RETURN NUMBER IS
  BEGIN
    returnValue := self.total;
    dbms_lob.trim(returnValue, dbms_lob.getlength(returnValue)-1);
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_clob_agg, ctx2 IN t_clob_agg) RETURN NUMBER IS
  BEGIN
    dbms_lob.append(self.total,ctx2.total);
    RETURN ODCIConst.Success;
  END;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE BODY</TYPE>
  <NAME>T_STRAGG3200</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>994D47AE4D44E72B9F58D3E4CFAD449F4F23B239</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE BODY T_STRAGG3200 IS
  STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_stragg3200) RETURN NUMBER IS
  BEGIN
    sctx := t_stragg3200(NULL,0);
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_stragg3200, value IN VARCHAR2) RETURN NUMBER IS
  BEGIN
    IF SELF.g_string IS NULL THEN
      IF LengthB(Value)&gt;3200
      THEN g_gata := 1;
      ELSE g_gata := 0;
      END IF;

      IF g_gata =0
      THEN SELF.g_string := value;
      END IF;
    ELSIF g_gata = 0 AND Value IS NOT NULL THEN
      IF LengthB(self.g_string || PKG_GLOBALS.SEP || value)&gt;3200
      THEN g_gata := 1;
      ELSE g_gata := 0;
      END IF;

      IF g_gata =0
      THEN SELF.g_string := self.g_string || PKG_GLOBALS.SEP || value;
      END IF;
    END IF;
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateTerminate(self IN t_stragg3200, returnValue OUT VARCHAR2, flags IN NUMBER) RETURN NUMBER IS
  BEGIN
    returnValue := SELF.g_string;
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_stragg3200, ctx2 IN t_stragg3200)
    RETURN NUMBER IS
  BEGIN
    IF SELF.g_string IS NULL THEN
      SELF.g_string := ctx2.g_string;
    ELSIF ctx2.g_string IS NOT NULL THEN
      SELF.g_string := SELF.g_string || PKG_GLOBALS.SEP || ctx2.g_string;
    END IF;

    RETURN ODCIConst.Success;
  END;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>TYPE BODY</TYPE>
  <NAME>T_STRING_AGG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2800754943BA6E7133C449E88720D7EC8A7BE86F</HASHVAL>
  <TEXT>CREATE OR REPLACE TYPE BODY T_STRING_AGG IS
  STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
    RETURN NUMBER IS
  BEGIN
    sctx := t_string_agg(NULL);
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                       value  IN      VARCHAR2 )
    RETURN NUMBER IS
  BEGIN
    SELF.g_string := self.g_string || PKG_GLOBALS.SEP || value;
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                         returnValue  OUT  VARCHAR2,
                                         flags        IN   NUMBER)
    RETURN NUMBER IS
  BEGIN
    returnValue := RTRIM(LTRIM(SELF.g_string, PKG_GLOBALS.SEP), PKG_GLOBALS.SEP);
    RETURN ODCIConst.Success;
  END;

  MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                     ctx2  IN      t_string_agg)
    RETURN NUMBER IS
  BEGIN
    SELF.g_string := SELF.g_string || PKG_GLOBALS.SEP || ctx2.g_string;
    RETURN ODCIConst.Success;
  END;
END;</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>NXT_BC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03CAE8A3A1C8DF8F95B45E85D6FBC58B3D8DC021</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW NXT_BC (
&quot;CODBC&quot;,&quot;CLASA&quot;,&quot;SIMBCLASA&quot;,&quot;SIMBGEST&quot;,&quot;GEST_LIVR&quot;) AS
select bc.CODBC,
LISTAGG(bc.CLASA,&apos;;&apos;) WITHIN GROUP (ORDER BY bc.CLASA) AS CLASA,
LISTAGG(bc.SIMBCLASA,&apos;;&apos;) WITHIN GROUP (ORDER BY bc.SIMBCLASA) AS SIMBCLASA,
LISTAGG(bc.SIMBGEST,&apos;;&apos;) WITHIN GROUP (ORDER BY bc.SIMBGEST) AS SIMBGEST,
LISTAGG(bc.GEST_LIVR,&apos;;&apos;) WITHIN GROUP (ORDER BY bc.GEST_LIVR) AS GEST_LIVR
 from
(
select ies.codies as CODBC,nvl(ncg.den_claseg,&apos;ND&apos;) CLASA,
nvl(ncg.simbol,&apos;ND&apos;) as SIMBCLASA,
ng.simbol SIMBGEST,
ng.den_gest GEST_LIVR from iesiri ies
inner join iesiri1 ies1 on ies1.codies=ies.codies and ies.tipdoc=24
inner join livr l on l.codies=ies.codies and l.tiplivr=ies.tipdoc
inner join livr1 l1 on l1.codlivr=l.codlivr and l1.codies1=ies1.codies1
inner join nirstoc ns on ns.codnirstoc=l1.codnirstoc
inner join nir on nir.codnir=ns.codnir
inner join ngest ng on ng.codgest=nir.gest
left join nclaseg ncg on ncg.codclaseg=ng.codclasa
group by ies.codies,ncg.den_claseg,ncg.simbol,ng.simbol,ng.den_gest) bc
group by bc.CODBC</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_IOBANK1_CODIOBANK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C475A642BE3F77A6CC53092510209B6694272905</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_IOBANK1_CODIOBANK1 (
&quot;CODIOBANK1&quot;) AS
SELECT codiobank1 FROM IOBANK1 ORDER BY codiobank1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_IOBANK_CODIOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8C9149481E9C108E26C2AB7354A30E7A38ED65A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_IOBANK_CODIOBANK (
&quot;CODIOBANK&quot;) AS
SELECT codiobank FROM IOBANK ORDER BY codiobank 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_IOPART1_CODIOPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD4E7657FD76EF4598C00E155C78F382FF967E1F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_IOPART1_CODIOPART1 (
&quot;CODIOPART1&quot;) AS
SELECT CodIOPart1 FROM IOPART1 ORDER BY CodIOPart1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_IOPART_CODIOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB7D2DE4B6C9A37CD7D98EEF3252EAB1E2ABBFCE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_IOPART_CODIOPART (
&quot;CODIOPART&quot;) AS
SELECT CodIOPart FROM IOPART ORDER BY CodIOPart 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NAGENDA_CODAGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2507CA1D07DF0DEA6529A2A51BEBA1BBC2D35E9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NAGENDA_CODAGENDA (
&quot;CODAGENDA&quot;) AS
SELECT codagenda FROM NAGENDA ORDER BY codagenda 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NART_DEN_ARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEFF01669FCF0C11A886D4F343649CB5EA0E41C7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NART_DEN_ARTICOL (
&quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;) AS
SELECT CodArticol, UPPER(Den_Articol) as Den_Articol FROM NART ORDER BY UPPER(Den_Articol), CodArticol 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NATRIB_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>088C3B4F3AF57B2C76CF28CFCA5838E2E99BFF9D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NATRIB_DENUMIRE (
&quot;CODATRIBUT&quot;,&quot;DENUMIRE&quot;) AS
SELECT CodAtribut, UPPER(Denumire) as Denumire FROM NATRIB ORDER BY UPPER(Denumire), CodAtribut 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NBANKCONT1_CODBANKCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>15A8FDD4EB70BCB05F1C0216CBBB2C30C7ED634F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NBANKCONT1_CODBANKCONT1 (
&quot;CODBANKCONT1&quot;) AS
SELECT codbankcont1 FROM NBANKCONT1 ORDER BY codbankcont1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NBANKCONT_CODBANKCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A3E7C8ED5AF33A31686DF32127A81F2EF585256</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NBANKCONT_CODBANKCONT (
&quot;CODBANKCONT&quot;) AS
SELECT CodBankCont FROM NBANKCONT ORDER BY CodBankCont 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NBANK_CODBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09ED63F2B25032D2C39C6FD98A7A6E8F6CED2530</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NBANK_CODBANK (
&quot;CODBANK&quot;) AS
SELECT CodBANK FROM NBANK ORDER BY CodBANK 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NBANK_DENUMIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2467BD8DFA48D38BBDF64CE69E7169925F13FC4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NBANK_DENUMIRE (
&quot;CODBANK&quot;,&quot;DENUMIRE&quot;) AS
SELECT CodBANK, UPPER(Denumire) as Denumire FROM NBANK ORDER BY UPPER(Denumire), CodBANK 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NJUDET_CODJUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>605CFDAE1F09589343B0902B2C4E62AC046DA8DC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NJUDET_CODJUDET (
&quot;CODJUDET&quot;) AS
SELECT codjudet FROM NJUDET ORDER BY codjudet 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NJUDET_DEN_JUDET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40BA5890AAC6B810429E31744FE123BFFB1705AF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NJUDET_DEN_JUDET (
&quot;CODJUDET&quot;,&quot;DEN_JUDET&quot;) AS
SELECT codjudet, UPPER(den_judet) as den_judet FROM NJUDET ORDER BY UPPER(den_judet), codjudet 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NLOCALIT_CODLOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>314EDD636F8582419CF3152FAD141039016A7FC4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NLOCALIT_CODLOCALIT (
&quot;CODLOCALIT&quot;) AS
SELECT codlocalit FROM NLOCALIT ORDER BY codlocalit 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NLOCALIT_DEN_LOCALIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13AA0A4594BEBAA90B316F210511067C6A0F8775</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NLOCALIT_DEN_LOCALIT (
&quot;CODLOCALIT&quot;,&quot;DEN_LOCALIT&quot;) AS
SELECT codlocalit, UPPER(den_localit) as den_localit FROM NLOCALIT ORDER BY UPPER(den_localit), codlocalit 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NMONEDE1_CODMONEDA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F380A25404D8777AA929237E8EDC6B4868C7F77D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NMONEDE1_CODMONEDA1 (
&quot;CODMONEDA1&quot;) AS
SELECT codmoneda1 FROM NMONEDE1 ORDER BY codmoneda1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NMONEDE_CODMONEDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B34B9C9C5C229F3A64E59E5A08530161B81D7BB8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NMONEDE_CODMONEDA (
&quot;CODMONEDA&quot;) AS
SELECT codmoneda FROM NMONEDE ORDER BY codmoneda 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NPARTB_CODPARTB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37A6F7B4DB71AE5D7BCA1C1621752A68A40C2F7D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NPARTB_CODPARTB (
&quot;CODPARTB&quot;) AS
SELECT CodPartB FROM NPARTB ORDER BY CodPartB 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NPART_DEN_PART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>240AF4E38846A7389CF2F9B816F6C96295458FE5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NPART_DEN_PART (
&quot;CODPART&quot;,&quot;DEN_PART&quot;) AS
SELECT CodPart, UPPER(Den_part) as Den_part FROM NPART ORDER BY UPPER(Den_part), CodPart 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NPERSCONTACT_CODPERSC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5B3A6169143801D45AD2215DCAC0D823689173B1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NPERSCONTACT_CODPERSC (
&quot;CODPERSC&quot;) AS
SELECT codpersc FROM NPERSCONTACT ORDER BY codpersc 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NTARI_CODTARA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DCBDA5E8FB5E69042E13EE27B0151667FA99A4E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NTARI_CODTARA (
&quot;CODTARA&quot;) AS
SELECT codtara FROM NTARI ORDER BY codtara 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NTARI_DEN_TARA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4EA47D681CAFB312AFBD01550643E323BA6E702D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NTARI_DEN_TARA (
&quot;CODTARA&quot;,&quot;DEN_TARA&quot;) AS
SELECT codtara, UPPER(den_tara) as den_tara FROM NTARI ORDER BY UPPER(den_tara), codtara 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NUM1_CODUM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1F549FF72F4D7692427ED1E973D267814EF5492A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NUM1_CODUM1 (
&quot;CODUM1&quot;) AS
SELECT codum1 FROM NUM1 ORDER BY codum1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NUM1_DEN_UM1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1476CFF376C476561A69866757B1516AF2066B01</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NUM1_DEN_UM1 (
&quot;CODUM1&quot;,&quot;DEN_UM1&quot;) AS
SELECT codum1, UPPER(den_um1) as den_um1 FROM NUM1 ORDER BY UPPER(den_um1), codum1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NUM_CODUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>37DE29183900BB6BC8040FF3BEDA88B407EE75FE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NUM_CODUM (
&quot;CODUM&quot;) AS
SELECT codum FROM NUM ORDER BY codum 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VIEW_NUM_DEN_UM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>375EDC85F8848F30EBD7FE20F61C9D5BDAEC6809</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VIEW_NUM_DEN_UM (
&quot;CODUM&quot;,&quot;DEN_UM&quot;) AS
SELECT codum, UPPER(den_um) as den_um FROM NUM ORDER BY UPPER(den_um), codum 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>VNPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC120625E252605617D9265BA97171A03C967668</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW VNPART (
&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;REGCOM&quot;,&quot;CODEXTERN&quot;,&quot;CODMONEDA&quot;,&quot;AUTORIZATIE&quot;,&quot;CODINTERN&quot;,&quot;CODCLASA&quot;,&quot;CODCATEGPRET&quot;,&quot;TIPPART&quot;,&quot;SCADENTAC&quot;,&quot;SCADENTAV&quot;,&quot;DISCOUNT&quot;,&quot;CODCATEGDISC&quot;,&quot;BLOCAT&quot;,&quot;TIPPARTENER&quot;,&quot;DATAADAUGARII&quot;,&quot;OBS&quot;,&quot;POZA&quot;,&quot;PERSOANAFIZICA&quot;,&quot;VERFACT&quot;,&quot;VERDISPLIVR&quot;,&quot;COLDISCOUNT&quot;,&quot;INFOBLOCAT&quot;,&quot;EXPIRAREAUTORIZ&quot;,&quot;CODSTATISTICBNR&quot;,&quot;MUSAICOLET&quot;,&quot;STRATEGIC&quot;,&quot;CIFRAAFACERI&quot;,&quot;DOMENIUACTIV&quot;,&quot;NRANGAJATI&quot;,&quot;SURSALEAD&quot;,&quot;LEAD&quot;,&quot;TVALAINCASARE&quot;,&quot;MODAPLICPROCDISC&quot;,&quot;PROCCURSTRANSF&quot;,&quot;VERPROFORMA&quot;,&quot;FIDELIZARE&quot;,&quot;MAJORARI&quot;,&quot;TIPBLOCAJ&quot;,&quot;POPRIRE_ANAF&quot;,&quot;CODRESPONSABIL&quot;,&quot;CODDOMENIUACT&quot;,&quot;DOCDEFONORCOM&quot;,&quot;MODPROMOFACTCOM&quot;,&quot;VALIDAREPRETOFERTA&quot;,&quot;IESCUCOMANDA&quot;,&quot;VERFACTAVIZ&quot;,&quot;VALMINCMD&quot;,&quot;CANTMINCMD&quot;,&quot;ZIAPROVIZ&quot;,&quot;PERAPROVIZ&quot;,&quot;CODCONTRACTCADRU&quot;,&quot;DATANASTERE&quot;,&quot;SPLITTVA&quot;,&quot;GDPR&quot;,&quot;ZILELIVRARE&quot;,&quot;CODFISCAL&quot;) AS
select P.&quot;CODPART&quot;,P.&quot;DEN_PART&quot;,P.&quot;REGCOM&quot;,P.&quot;CODEXTERN&quot;,P.&quot;CODMONEDA&quot;,P.&quot;AUTORIZATIE&quot;,P.&quot;CODINTERN&quot;,P.&quot;CODCLASA&quot;,P.&quot;CODCATEGPRET&quot;,P.&quot;TIPPART&quot;,P.&quot;SCADENTAC&quot;,P.&quot;SCADENTAV&quot;,P.&quot;DISCOUNT&quot;,P.&quot;CODCATEGDISC&quot;,P.&quot;BLOCAT&quot;,P.&quot;TIPPARTENER&quot;,P.&quot;DATAADAUGARII&quot;,P.&quot;OBS&quot;,P.&quot;POZA&quot;,P.&quot;PERSOANAFIZICA&quot;,P.&quot;VERFACT&quot;,P.&quot;VERDISPLIVR&quot;,P.&quot;COLDISCOUNT&quot;,P.&quot;INFOBLOCAT&quot;,P.&quot;EXPIRAREAUTORIZ&quot;,P.&quot;CODSTATISTICBNR&quot;,P.&quot;MUSAICOLET&quot;,P.&quot;STRATEGIC&quot;,P.&quot;CIFRAAFACERI&quot;,P.&quot;DOMENIUACTIV&quot;,P.&quot;NRANGAJATI&quot;,P.&quot;SURSALEAD&quot;,P.&quot;LEAD&quot;,P.&quot;TVALAINCASARE&quot;,P.&quot;MODAPLICPROCDISC&quot;,P.&quot;PROCCURSTRANSF&quot;,P.&quot;VERPROFORMA&quot;,P.&quot;FIDELIZARE&quot;,P.&quot;MAJORARI&quot;,P.&quot;TIPBLOCAJ&quot;,P.&quot;POPRIRE_ANAF&quot;,P.&quot;CODRESPONSABIL&quot;,P.&quot;CODDOMENIUACT&quot;,P.&quot;DOCDEFONORCOM&quot;,P.&quot;MODPROMOFACTCOM&quot;,P.&quot;VALIDAREPRETOFERTA&quot;,P.&quot;IESCUCOMANDA&quot;,P.&quot;VERFACTAVIZ&quot;,P.&quot;VALMINCMD&quot;,P.&quot;CANTMINCMD&quot;,P.&quot;ZIAPROVIZ&quot;,P.&quot;PERAPROVIZ&quot;,P.&quot;CODCONTRACTCADRU&quot;,P.&quot;DATANASTERE&quot;,P.&quot;SPLITTVA&quot;,P.&quot;GDPR&quot;,P.&quot;ZILELIVRARE&quot;, F.CODFISCAL from
npart P
 LEFT JOIN NPARTCODFISC F ON F.CODPART = P.CODPART AND F.PRINCIPAL = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ADAOSM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD6C8785B11A02456001012183D20D718EF91B0F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ADAOSM (
&quot;CODADAOSM&quot;,&quot;DATA_DOC&quot;) AS
select a.codadaosm, To_Char(a.data,&apos;dd.mm.yyyy&apos;) data_doc
    from adaosm a 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66B9CC921C1F0490D7D4363BA38B6F05E6B9A053</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AGENDA (
&quot;CODAGENDA&quot;,&quot;TIP&quot;,&quot;CODLOCALIT&quot;,&quot;SEDIUSOCIAL&quot;,&quot;TELEFON&quot;,&quot;FAX&quot;,&quot;EMAIL&quot;,&quot;SECTOR&quot;,&quot;STRADA&quot;,&quot;NR1&quot;,&quot;NR2&quot;,&quot;BLOC&quot;,&quot;SCARA&quot;,&quot;ETAJ&quot;,&quot;APART&quot;,&quot;CODPOSTAL&quot;,&quot;KM&quot;,&quot;OBS&quot;,&quot;CODBANKCONT&quot;,&quot;CODPART&quot;,&quot;CODGEST&quot;,&quot;CODSUBUNIT&quot;,&quot;CODTIPSEDIU&quot;,&quot;CODFISCAL&quot;,&quot;CODAGENT&quot;,&quot;CODCLIENT&quot;,&quot;CODTRASEU&quot;,&quot;POZTRASEU&quot;,&quot;INACTIV&quot;,&quot;CODCORESP&quot;,&quot;TRANSPCLIENT&quot;,&quot;COEFUTILAJE&quot;,&quot;SUPRAFATA&quot;,&quot;MODSERVIRE&quot;,&quot;IDSEDIU&quot;,&quot;COD_CODFISCAL&quot;,&quot;TELEFONP&quot;,&quot;EDI_EXPTIP&quot;,&quot;EDI_PARTTIP&quot;,&quot;EDI_PARTID&quot;,&quot;EDI_OBJTIP&quot;,&quot;GLN&quot;,&quot;GESTLIVRARE&quot;,&quot;LONGITUDINE&quot;,&quot;LATITUDINE&quot;,&quot;OBS2&quot;,&quot;EDI_IMPTIP&quot;,&quot;EDI_FURNTIP&quot;,&quot;EDI_FURNID&quot;,&quot;EDI_OBJTIPIMP&quot;,&quot;ADRESA&quot;) AS
select A.&quot;CODAGENDA&quot;,A.&quot;TIP&quot;,A.&quot;CODLOCALIT&quot;,A.&quot;SEDIUSOCIAL&quot;,A.&quot;TELEFON&quot;,A.&quot;FAX&quot;,A.&quot;EMAIL&quot;,A.&quot;SECTOR&quot;,A.&quot;STRADA&quot;,A.&quot;NR1&quot;,A.&quot;NR2&quot;,A.&quot;BLOC&quot;,A.&quot;SCARA&quot;,A.&quot;ETAJ&quot;,A.&quot;APART&quot;,A.&quot;CODPOSTAL&quot;,A.&quot;KM&quot;,A.&quot;OBS&quot;,A.&quot;CODBANKCONT&quot;,A.&quot;CODPART&quot;,A.&quot;CODGEST&quot;,A.&quot;CODSUBUNIT&quot;,A.&quot;CODTIPSEDIU&quot;,A.&quot;CODFISCAL&quot;,A.&quot;CODAGENT&quot;,A.&quot;CODCLIENT&quot;,A.&quot;CODTRASEU&quot;,A.&quot;POZTRASEU&quot;,A.&quot;INACTIV&quot;,A.&quot;CODCORESP&quot;,A.&quot;TRANSPCLIENT&quot;,A.&quot;COEFUTILAJE&quot;,A.&quot;SUPRAFATA&quot;,A.&quot;MODSERVIRE&quot;,A.&quot;IDSEDIU&quot;,A.&quot;COD_CODFISCAL&quot;,A.&quot;TELEFONP&quot;,A.&quot;EDI_EXPTIP&quot;,A.&quot;EDI_PARTTIP&quot;,A.&quot;EDI_PARTID&quot;,A.&quot;EDI_OBJTIP&quot;,A.&quot;GLN&quot;,A.&quot;GESTLIVRARE&quot;,A.&quot;LONGITUDINE&quot;,A.&quot;LATITUDINE&quot;,A.&quot;OBS2&quot;,A.&quot;EDI_IMPTIP&quot;,A.&quot;EDI_FURNTIP&quot;,A.&quot;EDI_FURNID&quot;,A.&quot;EDI_OBJTIPIMP&quot;, GETADRESA(A.SECTOR, A.STRADA,A.NR1,A.NR2, A.BLOC, A.SCARA, A.ETAJ, A.APART, A.CODPOSTAL) ADRESA
from
  NAGENDA A
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E725D37ACAA468D370B30AF50F5B7B0B1AF90AD2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ALERTE (
&quot;CODALERTA&quot;,&quot;DENUMIRE&quot;,&quot;OBS&quot;,&quot;CODORAR&quot;,&quot;DENUMIRE_ORAR&quot;,&quot;DENUMIRE_DEF&quot;,&quot;TIPALERTA&quot;) AS
select a.codalerta,a.denumire,a.obs, o.codorar, o.denumire as denumire_orar, o.Obs denumire_def, Nvl(a.Tipalerta,0) Tipalerta
    from alerte a left join orar o on o.codOrar = a.codOrar
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ALERTE_DEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95166BE55297B819FACB6F4CDF7491D678848FA8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ALERTE_DEF (
&quot;CODALERTADEF&quot;,&quot;DENUMIRE&quot;,&quot;SQL&quot;) AS
select a.codalertadef,a.denumire,a.sql
    from alerte_def a
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AMBALAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1469B786C23F9074E4F8AFB309E62ECD7968D2C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AMBALAJE (
&quot;CODOBIECT&quot;,&quot;DENUMIRE&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;MASA&quot;,&quot;VOLUM&quot;,&quot;UMAMBALARE&quot;) AS
SELECT 
  O.CodObiect, O.Denumire, A.UM, A.Clasa, A.TipSerie, A.TipArticol, A.AreTG, A.UM1, A.UM2, O.CODEXTERN, O.CODINTERN, O.Masa, O.Volum, O.UMAMBALARE 
FROM NARTOBJ O 
  INNER JOIN NART A ON A.CodArticol = O.CodArticol
WHERE O.RETURNABIL = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ART_CANAMED</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9EB5CD7827BD8C1AD9997D4BF5B5678A4667D20C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ART_CANAMED (
&quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CONTSERVICIU&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;ATRIBUTE&quot;) AS
SELECT
  A.CODARTICOL,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  AI.CONTIMPLICIT,
  AI.GESTIMPLICITA,
  A.CONTSERVICIU,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.UM1,
  A.UM2,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  MAX(T.CODATROBJ) AS ATRIBUTE
FROM NART A
  LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL= A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT JOIN NARTOBJ O ON O.CODARTICOL= A.CODARTICOL
  LEFT JOIN NATROBJ T ON T.CODOBIECT = O.CODOBIECT
  LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT JOIN TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
WHERE PKG_SELECTARTICOLE.CONDITIECLASA(A.CLASA) = 1 AND o.codarticol = pkg_globals.Get_CODCANAMED
GROUP BY
  A.CODARTICOL,
  A.DEN_ARTICOL, A.UM, A.CLASA, A.TIPSERIE, A.TIPARTICOL, A.ARETG, AI.CONTIMPLICIT, AI.GESTIMPLICITA, A.CERTIFICAT, A.EVOLUTIEPRET, A.CONTSERVICIU,
  A.UM1, A.UM2, NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2,
  TVALUNA.PROCENT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ART_SIMPLU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DD05AF6306DA6DC87B06F5B8894DBDF96C918821</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ART_SIMPLU (
&quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;) AS
SELECT
  A.CODARTICOL,
  A.DEN_ARTICOL
FROM
  NART A 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AUTO_CEN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2AA14D9A64974B123573B1BAC3089225C223F776</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AUTO_CEN (
&quot;CODAUTO&quot;,&quot;CODGEST&quot;,&quot;Q&quot;) AS
select &quot;CODAUTO&quot;,&quot;CODGEST&quot;,&quot;Q&quot;
from (Select CodAuto, CodGest, Sum(Q) Q from TMP_V_AUTO group by CodAuto, CodGest)
where Q &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE60304C2D25A6B26DC761CF489C69FC98E42BAB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_COMPENS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;PV&apos; AS DOC,
  C.NRDOC,
  C.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  C.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS

FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = C.SUBUNITATEA
WHERE
--  nvl(c.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1351 AND O.ICONT IN (3, 5, 10, 11)
 )AND
 O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_FACTURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B2F5707259AFADC79FF9637BACDCDA089E469AE6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_FACTURA (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN IESIRI I  ON I.CODIES     = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
 WHERE
--   nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.ICONT = PKG_NOMPART.GET_PART_ICONT_ANALIZAT)  AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 210 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_FACTURABILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE390239CA1371027966ACE198A73F8DC3523221</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_FACTURABILE (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  G.CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN IESIRI I  ON I.CODIES     = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
 WHERE
--   nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 210 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4646658C23DA260D3DD2E467BEDC27353D8A81C6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_NC (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
  N.NRDOC,
  N.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  N.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = N.SUBUNITATEA
WHERE
--  nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1201 AND
  ((O.VALOARE &lt; 0 AND O.ICONT IN (3, 10, 11))OR(O.VALOARE &gt; 0 AND O.ICONT IN (5)))
 )AND
 O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_NC_ROSU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>755F12A110F2994765B74BD9471E6FDEB8D113F7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_NC_ROSU (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
  N.NRDOC,
  N.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  N.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT  NS ON NS.CODSUBUNIT = N.SUBUNITATEA
WHERE
--  nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1200 AND  O.VALOARE &lt; 0 AND O.ICONT IN (5))AND
 O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2692AFE8036C835F2D09A88C5BFAFB760C2D2C3D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT_TREZOR (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC AS DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR ,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT
  (
   PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))
  )
   AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  T.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
	 LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR = T1.CODTREZOR
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = T.SUBUNITATEA
WHERE
--   nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   T1.AN * 12 + T1.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 410)
   AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6799F191C762A8135627E6E96C99CF74BDA9DA7E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_COMPENS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;PV&apos; AS DOC,
  C.NRDOC,
  C.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  C.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT  = C.SUBUNITATEA
WHERE
--  nvl(c.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1301 )AND  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_FACTURA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6E64272DF830DC498393808368ACA0149B97C90D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_FACTURA (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR    = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= I.SUBUNITATEA
WHERE
--   nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.ICONT = PKG_NOMPART.GET_PART_ICONT_ANALIZAT)  AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 110 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_FACTURABILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A656EDACCA5131354D1DCD8EDCC299DF87D452A9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_FACTURABILE (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  G.CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR    = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= I.SUBUNITATEA
WHERE
--   nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
--  (O.ICONT = PKG_NOMPART.GET_PART_ICONT_ANALIZAT)  AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 110 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>75C5CB1E9298137FEE47596DC98BF2E50E6F9B37</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_NC (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
  N.NRDOC,
  N.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  N.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT  = N.SUBUNITATEA
WHERE
--  nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1200 AND
  ((O.VALOARE &lt; 0 AND O.ICONT IN (2, 8, 9, 15))OR(O.VALOARE &gt; 0 AND O.ICONT IN (4, 12, 13, 14)))
 )AND
 O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_NC_ROSU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45611C8E4BC9466C054FFAC9BE9C7527E149D54D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_NC_ROSU (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
  N.NRDOC,
  N.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  N.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = N.SUBUNITATEA
WHERE
-- nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
 N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
 (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
 (O.SEMNIFICATIE = 1201 AND O.VALOARE &lt; 0 AND O.ICONT IN (4, 12))AND
 O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
 PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>599C0AF38203FB45B4FDD6A57EE7A742FA464320</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN_TREZOR (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC AS DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR ,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
--PKG_GLOBALS.SIMBOLCONTOBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  T.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
	LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR = T1.CODTREZOR
	LEFT OUTER JOIN NSUBUNIT  NSUB  ON NSUB.CODSUBUNIT = T.SUBUNITATEA
WHERE
--   nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   T1.AN * 12 + T1.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 310)
   AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVIZE_IESIRE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9126CB3DE85E0FD83380B601AD3DD59786C4574</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVIZE_IESIRE (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;NIVEL&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;,&quot;INDEXLOCAL&quot;,&quot;CODINTERN&quot;,&quot;CODCOMANDA1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTVALUTA&quot;,&quot;CODEXTCLI&quot;,&quot;REZIDUU&quot;,&quot;RELATIEUM1&quot;,&quot;MAT_D1&quot;,&quot;MAT_D2&quot;,&quot;MAT_D3&quot;,&quot;TIPTVA&quot;,&quot;TIPPLATA&quot;,&quot;CADOU&quot;,&quot;PRETPROMO&quot;,&quot;CADOULINK&quot;,&quot;BENEFICIAR&quot;,&quot;DENLAPARTENER&quot;,&quot;UMCORELAT&quot;,&quot;PUCORELAT&quot;,&quot;CANTCORELAT&quot;,&quot;ORDINEPRELUARE&quot;,&quot;PRODUS&quot;,&quot;CODEXTERN&quot;,&quot;CUSTODIE&quot;,&quot;CODPROIECT&quot;,&quot;CODPRODCOMP&quot;,&quot;NRI&quot;,&quot;CODSUBUNIT&quot;,&quot;DEN_SUBUNIT&quot;,&quot;UMSECSURSA&quot;) AS
SELECT
  I.PREFIXDOC,
  I.NRDOC,
  0 Nivel,
  I.DATADOC,
  I1.CODIES1 AS CODLINIESTINSA,
  I1.PU AS PRET,
  I1.CODOBIECT,
  I1.CANT,
  I1.RESTFACT AS REST,
  I1.RESTFACT AS RESTINITIAL,
  0 AS PRELUAT,
  I1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;,&apos;1&apos;,&apos;S&apos;) AS TIPLINIE,
  0 AS TERMEN,
  A.CONTSERVICIU,
  NVL(G.MONEDA, 0) AS MONEDAAVIZ,
  NVL(GREG.CURS, G.CURS) AS CURSAVIZ,
  I1.TVA AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  I1.ADDIM,
  I1.PROCDISC,
  I.CODLOCATIE,
  U1.PARITATE,
  I.AGENT,
  P.NUME || &apos; &apos; || P.PRENUME AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  I1.MIFIX,
  0 AS ARETG,
  0 AS CERTIFICAT,
  I.OBS AS OBSDOC,
  I1.OBS AS OBSARTICOL,
  0 AS ZILEPLATA,
  (SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  I1.GARANTIE,
  I.CODIES AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART,
  I1.INDEXLOCAL,
  O.CODINTERN,
  0 AS CODCOMANDA1,
  0 AS D1,
  0 AS D2,
  0 AS D3,
  O.ROTVALUTA,
  &apos; &apos; CODEXTCLI,
  0 REZIDUU,
  0 RELATIEUM1,
  0 MAT_D1,
  0 MAT_D2,
  0 MAT_D3,
  I.TIPTVA,
  0 TIPPLATA,
  I1.CADOU,
  I1.PRETPROMO,
  I1.CADOULINK,
  &apos; &apos; Beneficiar,
  &apos; &apos; DenLaPartener,
  I1.UMCORELAT,
  I1.PUCORELAT,
  I1.CantCorelat,
  0 ORDINEPRELUARE,
  &apos; &apos; Produs,
  O.CODEXTERN,
  0 CUSTODIE,
  0 CODPROIECT,
  0 CODPRODCOMP,
  I.NRI,
  S.CODSUBUNIT,
  S.DEN_SUBUNIT,
  1 AS UMSECSURSA
FROM
  IESIRI1 I1
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
    ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN IESIRI I ON I.CODIES  = I1.CODIES
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1  = I1.UMSEC
  LEFT OUTER JOIN NPERS P ON P.CODPERS  = I.AGENT
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
WHERE
  I.TIPDOC = 20 AND
--  NVL(I.CUSTODIE, 0) = 0 AND
  I1.TIPLINIE NOT IN (&apos;T&apos;, &apos;G&apos;) AND
  I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU + PKG_GLOBALS.GET_DEFAZAJ_AVIZ_OUT  AND
  PKG_IESIRI.CONDITIE_PART_AVIZ(I.PARTENER) = 1
  AND  I.OPERAT = 1 AND I.ANULAT = 0
  AND NVL(I1.CODIES1STORNO, 0) = 0
	 AND nvl(I.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(I.subunitatea,1),pkg_globals.GETSUBUNITATE)
  AND ((I1.RESTFACT &lt;&gt; 0)OR(I1.RESTFACT = 0)AND(I1.CODIES1 IN( SELECT CODLINIEAVIZ FROM TMP_IESLINK_INITIAL)))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVIZE_IESIRE_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42AFCDDF9A0DA4C68EDDDFCAD2B1F315E2DC5A3C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVIZE_IESIRE_EXT (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;NIVEL&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;,&quot;INDEXLOCAL&quot;,&quot;CODINTERN&quot;,&quot;CODCOMANDA1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTVALUTA&quot;,&quot;CODEXTCLI&quot;,&quot;REZIDUU&quot;,&quot;RELATIEUM1&quot;,&quot;MAT_D1&quot;,&quot;MAT_D2&quot;,&quot;MAT_D3&quot;,&quot;TIPTVA&quot;,&quot;TIPPLATA&quot;,&quot;CADOU&quot;,&quot;PRETPROMO&quot;,&quot;CADOULINK&quot;,&quot;BENEFICIAR&quot;,&quot;DENLAPARTENER&quot;,&quot;UMCORELAT&quot;,&quot;PUCORELAT&quot;,&quot;CANTCORELAT&quot;,&quot;ORDINEPRELUARE&quot;,&quot;PRODUS&quot;,&quot;CODEXTERN&quot;,&quot;CUSTODIE&quot;,&quot;CODPROIECT&quot;,&quot;CODPRODCOMP&quot;,&quot;NRI&quot;,&quot;CODSUBUNIT&quot;,&quot;DEN_SUBUNIT&quot;,&quot;UMSECSURSA&quot;,&quot;CODCENTRU&quot;,&quot;DENCENTRU&quot;) AS
SELECT
  I.PREFIXDOC,
  I.NRDOC,
  0 Nivel,
  I.DATADOC,
  I1.CODIES1 AS CODLINIESTINSA,
  I1.PU * U1.PARITATE AS PRET,
  I1.CODOBIECT,
  ROUND(I1.CANT / U1.PARITATE, 12) AS CANT,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS REST,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS RESTINITIAL,
  0 AS PRELUAT,
  I1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;,&apos;1&apos;,&apos;S&apos;) AS TIPLINIE,
  0 AS TERMEN,
  A.CONTSERVICIU,
  NVL(G.MONEDA, 0) AS MONEDAAVIZ,
  NVL(GREG.CURS, G.CURS) AS CURSAVIZ,
  I1.TVA AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  I1.ADDIM,
  I1.PROCDISC,
  I.CODLOCATIE,
  U1.PARITATE,
  I.AGENT,
  P.NUME || &apos; &apos; || P.PRENUME AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  I1.MIFIX,
  0 AS ARETG,
  0 AS CERTIFICAT,
  I.OBS AS OBSDOC,
  I1.OBS AS OBSARTICOL,
  0 AS ZILEPLATA,
--(SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  U1.Den_UM1 AS DENUMPRINCIPALA,
  I1.GARANTIE,
  I.CODIES AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART,
  I1.INDEXLOCAL,
  O.CODINTERN,
  0 AS CODCOMANDA1,
  0 AS D1,
  0 AS D2,
  0 AS D3,
  O.ROTVALUTA,
  &apos; &apos; CODEXTCLI,
  0 REZIDUU,
  0 RELATIEUM1,
  0 MAT_D1,
  0 MAT_D2,
  0 MAT_D3,
  I.TIPTVA,
  0 TIPPLATA,
  I1.CADOU,
  I1.PRETPROMO,
  I1.CADOULINK,
  &apos; &apos; Beneficiar,
  &apos; &apos; DenLaPartener,
  I1.UMCORELAT,
  I1.PUCORELAT,
  I1.CantCorelat,
  0 ORDINEPRELUARE,
  &apos; &apos; Produs,
  O.CODEXTERN,
  I.CUSTODIE,
  0 CODPROIECT,
  0 CODPRODCOMP,
  I.NRI,
  S.CODSUBUNIT,
  S.DEN_SUBUNIT,
  1 AS UMSECSURSA,
  I1.CODCENTRU,
  CC.DENUMIRE AS DENCENTRU
FROM
  IESIRI1 I1
  LEFT OUTER JOIN CENTRECOST CC ON CC.CODCENTRU = I1.CODCENTRU
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
    ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN IESIRI I ON I.CODIES  = I1.CODIES
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC = I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1  = I1.UMSEC
  LEFT OUTER JOIN NPERS P ON P.CODPERS  = I.AGENT
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA  = G.MONEDA
WHERE
  I.TIPDOC = 20 AND
--NVL(I.CUSTODIE, 0) = 0 AND
  I1.TIPLINIE NOT IN (&apos;T&apos;, &apos;G&apos;) AND
  I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU + PKG_GLOBALS.GET_DEFAZAJ_AVIZ_OUT  AND
  PKG_IESIRI.CONDITIE_PART_AVIZ(I.PARTENER) = 1
  AND  I.OPERAT = 1 AND I.ANULAT = 0
  AND NVL(I1.CODIES1STORNO, 0) = 0
  AND NVL(I1.CUSTODIEINTRARE, 0) = 0
	AND nvl(I.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(I.subunitatea,1),pkg_globals.GETSUBUNITATE)
  AND ((I1.RESTFACT &lt;&gt; 0)OR(I1.RESTFACT = 0)AND(I1.CODIES1 IN( SELECT CODLINIEAVIZ FROM TMP_IESLINK_INITIAL)))
  AND NVL(TIPCONSUMATOR, 0) &lt;&gt; 2
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVIZE_INTRARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>265DF5E4DEB084CACDFC2425D8564B3C7E4C35E2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVIZE_INTRARE (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;NIVEL&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;,&quot;INDEXLOCAL&quot;,&quot;CODINTERN&quot;,&quot;CODCOMANDA1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTVALUTA&quot;,&quot;CODEXTCLI&quot;,&quot;REZIDUU&quot;,&quot;RELATIEUM1&quot;,&quot;MAT_D1&quot;,&quot;MAT_D2&quot;,&quot;MAT_D3&quot;,&quot;TIPTVA&quot;,&quot;TIPPLATA&quot;,&quot;CADOU&quot;,&quot;PRETPROMO&quot;,&quot;CADOULINK&quot;,&quot;BENEFICIAR&quot;,&quot;DENLAPARTENER&quot;,&quot;UMCORELAT&quot;,&quot;PUCORELAT&quot;,&quot;CANTCORELAT&quot;,&quot;ORDINEPRELUARE&quot;,&quot;PRODUS&quot;,&quot;CODEXTERN&quot;,&quot;CUSTODIE&quot;,&quot;CODPROIECT&quot;,&quot;CODPRODCOMP&quot;,&quot;NRI&quot;,&quot;CODSUBUNIT&quot;,&quot;DEN_SUBUNIT&quot;,&quot;UMSECSURSA&quot;,&quot;CODCENTRU&quot;,&quot;DENCENTRU&quot;) AS
SELECT
  I.PREFIXDOC,
  I.NRDOC,
  0 Nivel,
  I.DATADOC,
  I1.CODINTR1 AS CODLINIESTINSA,
  I1.PU * U1.PARITATE AS PRET,
  I1.CODOBIECT,
  ROUND(I1.CANT / U1.PARITATE, 12) AS CANT,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS REST,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS RESTINITIAL,
  0 AS PRELUAT,
  I1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;,&apos;1&apos;,&apos;S&apos;, &apos;2&apos;, &apos;=&apos;) AS TIPLINIE,
  0 AS TERMEN,
  A.CONTSERVICIU,
  NVL(G.MONEDA, 0) AS MONEDAAVIZ,
  NVL(GREG.CURS, G.CURS) AS CURSAVIZ,
  I1.TVA AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  I1.ADDIM,
  0 AS PROCDISC,
  I.CODLOCATIE,
  U1.PARITATE,
  0 AS AGENT,
  &apos;... nedefinit ...&apos; AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  I1.MIFIX,
  0 AS ARETG,
  0 AS CERTIFICAT,
  I.OBS AS OBSDOC,
  I1.OBS AS OBSARTICOL,
  0 AS ZILEPLATA,
  U1.Den_UM1 AS DENUMPRINCIPALA,
--  (SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  0 AS GARANTIE,
  I.CODINTR AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART,
  I1.INDEXLOCAL,
  O.CODINTERN,
  0 AS CODCOMANDA1,
  0 AS D1,
  0 AS D2,
  0 AS D3,
  O.ROTVALUTA,
  &apos; &apos; CODEXTCLI,
  0 REZIDUU,
  0 RELATIEUM1,
  0 MAT_D1,
  0 MAT_D2,
  0 MAT_D3,
  I.TIPTVA,
  0 TIPPLATA,
  0 CADOU,
  0 PRETPROMO,
  0 CADOULINK,
  &apos; &apos; Beneficiar,
  &apos; &apos; DenLaPartener,
  0 AS UMCORELAT,
  0 AS PUCORELAT,
  0 AS CantCorelat,
  0 ORDINEPRELUARE,
  &apos; &apos; Produs,
  O.CODEXTERN,
  0 CUSTODIE,
  0 CODPROIECT,
  0 CODPRODCOMP,
  I.NRI,
  S.CODSUBUNIT,
  S.DEN_SUBUNIT,
  1 AS UMSECSURSA,
  I1.CODCENTRU,
  CC.DENUMIRE AS DENCENTRU
FROM
  INTRARI1 I1
  LEFT OUTER JOIN CENTRECOST CC ON CC.CODCENTRU = I1.CODCENTRU
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC  = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1 = I1.UMSEC
  LEFT OUTER JOIN NMONEDE M   ON M.CODMONEDA = G.MONEDA
WHERE
 I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU + PKG_GLOBALS.GET_DEFAZAJ_AVIZ_IN AND
 I.TIPDOC = 2 AND NVL(I.TIPFACTURA, 0) &lt;&gt; 9 AND
 I1.TIPLINIE NOT IN (&apos;T&apos;, &apos;G&apos;) AND
 PKG_INTRARI.CONDITIE_PART_AVIZ(I.PARTENER) = 1 AND
 I.OPERAT = 1 AND I.ANULAT = 0
 AND NVL(I1.CODINTR1STORNO, 0) = 0
	AND nvl(I.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(I.subunitatea,1),pkg_globals.GETSUBUNITATE)
 AND ((I1.RESTFACT &lt;&gt; 0)OR(I1.RESTFACT = 0)AND(I1.CODINTR1 IN( SELECT CODLINIEAVIZ FROM TMP_INTRLINK_INITIAL)))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVIZE_INTRARE_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>74703400EA001BB8DF6C29B724DF9EE1FB064A25</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVIZE_INTRARE_EXT (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;NIVEL&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;,&quot;INDEXLOCAL&quot;,&quot;CODINTERN&quot;,&quot;CODCOMANDA1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTVALUTA&quot;,&quot;CODEXTCLI&quot;,&quot;REZIDUU&quot;,&quot;RELATIEUM1&quot;,&quot;MAT_D1&quot;,&quot;MAT_D2&quot;,&quot;MAT_D3&quot;,&quot;TIPTVA&quot;,&quot;TIPPLATA&quot;,&quot;CADOU&quot;,&quot;PRETPROMO&quot;,&quot;CADOULINK&quot;,&quot;BENEFICIAR&quot;,&quot;DENLAPARTENER&quot;,&quot;UMCORELAT&quot;,&quot;PUCORELAT&quot;,&quot;CANTCORELAT&quot;,&quot;ORDINEPRELUARE&quot;,&quot;PRODUS&quot;,&quot;CODEXTERN&quot;,&quot;CUSTODIE&quot;,&quot;CODPROIECT&quot;,&quot;CODPRODCOMP&quot;,&quot;NRI&quot;,&quot;CODSUBUNIT&quot;,&quot;DEN_SUBUNIT&quot;,&quot;UMSECSURSA&quot;,&quot;CODCENTRU&quot;,&quot;DENCENTRU&quot;,&quot;CODCONTRACT1&quot;,&quot;NRCONTRACT&quot;,&quot;GESTACT&quot;,&quot;CANTUMS&quot;,&quot;RESTINITIALUMS&quot;,&quot;PRELUATUMS&quot;,&quot;ZILECMD&quot;,&quot;UM1&quot;,&quot;CODUM1&quot;,&quot;TAXA&quot;,&quot;INFOCMD&quot;,&quot;CODANALIZANOD&quot;,&quot;TERMENCONTRACT&quot;) AS
SELECT
  I.PREFIXDOC,
  I.NRDOC,
  0 Nivel,
  I.DATADOC,
  I1.CODINTR1 AS CODLINIESTINSA,
  I1.PU * U1.PARITATE AS PRET,
  I1.CODOBIECT,
  ROUND(I1.CANT / U1.PARITATE, 12) AS CANT,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS REST,
  ROUND(I1.RESTFACT / U1.PARITATE, 12) AS RESTINITIAL,
  0 AS PRELUAT,
  I1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;, &apos;2&apos;, &apos;=&apos;, &apos;1&apos;,&apos;S&apos;) AS TIPLINIE,
  0 AS TERMEN,
  A.CONTSERVICIU,
  NVL(G.MONEDA, 0) AS MONEDAAVIZ,
  NVL(GREG.CURS, G.CURS) AS CURSAVIZ,
  I1.TVA AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  I1.ADDIM,
  0 AS PROCDISC,
  I.CODLOCATIE,
  U1.PARITATE,
  0 AS AGENT,
  &apos;... nedefinit ...&apos; AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  I1.MIFIX,
  0 AS ARETG,
  0 AS CERTIFICAT,
  I.OBS AS OBSDOC,
  I1.OBS AS OBSARTICOL,
  0 AS ZILEPLATA,
  U1.Den_UM1 AS DENUMPRINCIPALA,
--  (SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  0 AS GARANTIE,
  I.CODINTR AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART,
  I1.INDEXLOCAL,
  O.CODINTERN,
  0 AS CODCOMANDA1,
  0 AS D1,
  0 AS D2,
  0 AS D3,
  O.ROTVALUTA,
  &apos; &apos; CODEXTCLI,
  0 REZIDUU,
  0 RELATIEUM1,
  0 MAT_D1,
  0 MAT_D2,
  0 MAT_D3,
  I.TIPTVA,
  0 TIPPLATA,
  0 CADOU,
  0 PRETPROMO,
  0 CADOULINK,
  &apos; &apos; Beneficiar,
  &apos; &apos; DenLaPartener,
  0 AS UMCORELAT,
  0 AS PUCORELAT,
  0 AS CantCorelat,
  0 ORDINEPRELUARE,
  &apos; &apos; Produs,
  O.CODEXTERN,
  0 CUSTODIE,
  0 CODPROIECT,
  0 CODPRODCOMP,
  I.NRI,
  S.CODSUBUNIT,
  S.DEN_SUBUNIT,
  1 AS UMSECSURSA,
  I1.CODCENTRU,
  CC.DENUMIRE AS DENCENTRU,
  C1.CODCONTRACT1,
  CONTR.NRDOC AS NRCONTRACT,
  I1.GESTACT,
  0 AS CantUMS,
  0 AS RestInitialUMS,
  0  AS PreluatUMS,
  I1.ZILECMD,
  A.UM1,
  U1.CodUM1,
  I1.Taxa,
  TO_CHAR(CMD.NRDOC) || &apos;/&apos; || TO_CHAR(CMD.DATADOC, &apos;DD.MM.YYYY&apos;) AS INFOCMD,
  I1.CODANALIZANOD,
  I1.TERMENCONTRACT
FROM
  INTRARI1 I1
  LEFT OUTER JOIN INTRLINK IL ON IL.CODINTR1  = I1.CODINTR1
  LEFT OUTER JOIN COMANDA1 CC1 ON IL.CODLINIECOMANDA  = CC1.CODCOMANDA1
  LEFT OUTER JOIN COMANDA  CMD ON CMD.CODCOMANDA  = CC1.CODCOMANDA
  LEFT OUTER JOIN CENTRECOST CC ON CC.CODCENTRU = I1.CODCENTRU
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN CONTRACT1 C1 ON C1.CODCONTRACT1 = I1.CODCONTRACT1
  LEFT OUTER JOIN CONTRACT  CONTR ON CONTR.CODCONTRACT = C1.CODCONTRACT
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = I1.CODINTR
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.SUBUNITATEA
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC  = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NUM1 U1   ON U1.CODUM1 = I1.UMSEC
  LEFT OUTER JOIN NMONEDE M   ON M.CODMONEDA = G.MONEDA
WHERE
 I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU + PKG_GLOBALS.GET_DEFAZAJ_AVIZ_IN AND
 I.TIPDOC = 2 AND NVL(I.TIPFACTURA, 0) &lt;&gt; 9 AND
 I1.TIPLINIE NOT IN (&apos;T&apos;, &apos;G&apos;) AND
 PKG_INTRARI.CONDITIE_PART_AVIZ(I.PARTENER) = 1 AND
 I.OPERAT = 1 AND I.ANULAT = 0
 AND NVL(I1.CUSTODIE, 0) = 0
 AND NVL(I1.CODINTR1STORNO, 0) = 0
 AND ((I1.RESTFACT &lt;&gt; 0)OR(I1.RESTFACT = 0)AND(I1.CODINTR1 IN( SELECT CODLINIEAVIZ FROM TMP_INTRLINK_INITIAL)))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_ARTICOLE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D5446AD1800712FA452F45428A399452AC0B641</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_ARTICOLE (
&quot;CODOBIECT&quot;,&quot;CODINTERN&quot;,&quot;CODEXTERN&quot;,&quot;ARTICOL&quot;,&quot;TIPARTICOL&quot;,&quot;DENCLASAART&quot;,&quot;SIMBCLASAART&quot;,&quot;UM&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;DATASYSTEM&quot;,&quot;MASA&quot;) AS
SELECT CAST (O.CodObiect AS VARCHAR(32)) CodObiect, O.CODINTERN, O.CODEXTERN, O.DENUMIRE Articol, A.tiparticol, CA.Den_ClaseA DenClasaArt,
       CA.simbol simbclasaart, U.Den_UM UM, U1.Den_UM UM1, U2.Den_UM UM2, Trunc(SYSDATE) datasystem, O.Masa
FROM NARTOBJ O
  LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT JOIN NUM U ON U.CODUM = A.UM
  LEFT JOIN NUM U1 ON U1.CODUM = A.UM1
  LEFT JOIN NUM U2 ON U2.CODUM = A.UM2
  LEFT JOIN NCLASEA CA ON CA.CODCLASEA = A.CLASA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_CLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12D5286584BEB7053ED5C5D59F1ADCE162DBD10E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_CLASEA (
&quot;NIV1&quot;,&quot;NIV2&quot;,&quot;NIV3&quot;,&quot;NIV4&quot;,&quot;NIV5&quot;) AS
select
  case when coalesce(cls.nivel,0) = 1 then cls.simbol when coalesce(cls.nivel,0) &gt; 1 then pkg_list_base_utils.GetParinteNivelClsA(1,cls.codclasea) end niv1,
  case when coalesce(cls.nivel,0) = 2 then cls.simbol when coalesce(cls.nivel,0) &gt; 2 then pkg_list_base_utils.GetParinteNivelClsA(2,cls.codclasea) end niv2,
  case when coalesce(cls.nivel,0) = 3 then cls.simbol when coalesce(cls.nivel,0) &gt; 3 then pkg_list_base_utils.GetParinteNivelClsA(3,cls.codclasea) end niv3,
  case when coalesce(cls.nivel,0) = 4 then cls.simbol when coalesce(cls.nivel,0) &gt; 4 then pkg_list_base_utils.GetParinteNivelClsA(4,cls.codclasea) end niv4,
  case when coalesce(cls.nivel,0) = 5 then cls.simbol when coalesce(cls.nivel,0) &gt; 5 then pkg_list_base_utils.GetParinteNivelClsA(5,cls.codclasea) end niv5
from nclasea cls
order by cls.codident
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_CLASEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>338E2AA1FB8250A19621C1B5EF2F291741908D21</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_CLASEP (
&quot;NIV1&quot;,&quot;NIV2&quot;,&quot;NIV3&quot;,&quot;NIV4&quot;,&quot;NIV5&quot;) AS
select
  case when coalesce(cls.nivel,0) = 1 then cls.simbol when coalesce(cls.nivel,0) &gt; 1 then pkg_list_base_utils.GetParinteNivelClsP(1,cls.codclasep) end niv1,
  case when coalesce(cls.nivel,0) = 2 then cls.simbol when coalesce(cls.nivel,0) &gt; 2 then pkg_list_base_utils.GetParinteNivelClsP(2,cls.codclasep) end niv2,
  case when coalesce(cls.nivel,0) = 3 then cls.simbol when coalesce(cls.nivel,0) &gt; 3 then pkg_list_base_utils.GetParinteNivelClsP(3,cls.codclasep) end niv3,
  case when coalesce(cls.nivel,0) = 4 then cls.simbol when coalesce(cls.nivel,0) &gt; 4 then pkg_list_base_utils.GetParinteNivelClsP(4,cls.codclasep) end niv4,
  case when coalesce(cls.nivel,0) = 5 then cls.simbol when coalesce(cls.nivel,0) &gt; 5 then pkg_list_base_utils.GetParinteNivelClsP(5,cls.codclasep) end niv5
from nclasep cls
order by cls.codident
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_COMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40FFF6472BD88CA58A45F1107E03501CE0F4D33B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_COMENZI (
&quot;NUMEDOC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;PARTENER&quot;,&quot;CODPART&quot;,&quot;CODGEST&quot;,&quot;CUDSUBUNIT&quot;,&quot;CODOBIECT&quot;,&quot;DENOBIECT&quot;,&quot;DENUM&quot;,&quot;CANTCOMANDAT&quot;,&quot;CANTACCEPTAT&quot;,&quot;RESTACCEPTAT&quot;,&quot;PU&quot;,&quot;INDEXDOC&quot;,&quot;DATASYSTEM&quot;,&quot;ANLUNA&quot;) AS
SELECT
  XM.NUMEPRESC NUMEDOC, 
  C.CODCOMANDA, C.TIPDOC, C.PREFIXDOC, C.NRDOC, C.DATADOC, Mon.SIMBOL MONEDA, Round(C.CURS,4) Curs,
  DECODE ( C.TipDoc, 44, NS.Den_Subunit, 43, NG.Den_Gest, NP.Den_Part) Partener, NP.CodPart, NG.CodGest, NS.CodSubunit,
  C1.CodObiect, nobj.denumire denobiect, num1.den_um1 denum,
  c1.cantcomandat/num1.paritate cantcomandat, c1.cantacceptat/num1.paritate cantacceptat, c1.restacceptat/num1.paritate restacceptat, c1.pu*num1.paritate pu,
  C1.IndexLocal IndexDoc, Trunc(SYSDATE) datasystem, c.an*100+c.luna AnLuna
FROM comanda c
  LEFT JOIN comanda1 c1 ON c.codcomanda = c1.codcomanda
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = c.tipdoc
	LEFT JOIN nmonede mon ON mon.codmoneda = c.moneda
	LEFT JOIN nartobj nobj ON nobj.codobiect = c1.codobiect
  LEFT JOIN nart art ON nobj.codarticol = art.codarticol
  LEFT JOIN nartobjsubunit nobjs ON nobjs.codobiect = nobj.codobiect AND nobjs.subunitate = DECODE(C.TipDoc,44,c.subunitsursa,c.subunitatea)
	LEFT JOIN num1 ON num1.codum1 = c1.umsec
  LEFT JOIN num us ON us.codum = art.um1
  LEFT JOIN npers ag on c.agent = ag.codpers
  LEFT JOIN nclasea cla on art.clasa = cla.codclasea
  LEFT JOIN nclaseas cs on art.clasastatist = cs.codclaseas
  LEFT JOIN npart np ON np.codpart = c.partener
  LEFT JOIN ngest ng ON ng.codgest = c.codgest
  LEFT JOIN nsubunit ns ON ns.codsubunit = c.subunitatea
  LEFT JOIN nsubunit s On s.codsubunit = c.subunitatea
WHERE c.anulat = 0 AND c.operat = 1</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE5C529103D1695D82D4BB9527518863BA14F984</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_IESIRI (
&quot;NUMEDOC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;PREFIXDOC&quot;,&quot;SERIEDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;PARTENER&quot;,&quot;CODPART&quot;,&quot;DATAADAUGARII&quot;,&quot;CODCLASEP&quot;,&quot;CODINTERNPART&quot;,&quot;VECHIMECLIENT&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;PRETORIG&quot;,&quot;PU&quot;,&quot;PRETFINAL&quot;,&quot;TVALIN&quot;,&quot;INDEXDOC&quot;,&quot;CODLIVR1&quot;,&quot;CODAE&quot;,&quot;CODAE1&quot;,&quot;NRLIVR&quot;,&quot;DATALIVR&quot;,&quot;LOCALITATE&quot;,&quot;JUDET&quot;,&quot;AGENT&quot;,&quot;PRETACHIZORIG&quot;,&quot;PRETACHIZ&quot;,&quot;PRETINREG&quot;,&quot;DATAACHIZ&quot;,&quot;FURNIZOR&quot;,&quot;VECHIMEFURNIZOR&quot;,&quot;GESTIUNE&quot;,&quot;LOCATIE&quot;,&quot;CONT&quot;,&quot;DEN_CONT&quot;,&quot;TIPCONTABIL&quot;,&quot;TERMENLIVR&quot;,&quot;DATASYSTEM&quot;,&quot;MG&quot;,&quot;ANLUNA&quot;,&quot;CURSSITV&quot;) AS
SELECT
  XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC,I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
  CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(CURRENT_DATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
  M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, P.CODPART CODPART,P.DATAADAUGARII,P.CODCLASA CODCLASEP,P.CODINTERN CODINTERNPART, Trunc(vc.vechime) VECHIMECLIENT,
  CAST(I1.CODOBIECT AS VARCHAR(32)) CODOBIECT,
  CASE WHEN Coalesce(AE1.CANT,I1.CANT) = 0 THEN 0 ELSE Round(I1.CANT*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT),4) END Cant,
  Round(I1.Pretorig*CASE WHEN i.tipdoc NOT IN (16,21) OR Coalesce(i1.cant*i1.pu,0) = 0  THEN 1 ELSE 1 - Coalesce(i1.tva,0)/(i1.cant*i1.pu) END,4) PretOrig, -- fara TVA
  Round(I1.PU - CASE WHEN i.tipdoc NOT IN (16,21) OR Coalesce(i1.cant,0) = 0 THEN 0 ELSE Coalesce(i1.tva,0)/i1.cant END,4) PU, -- fara TVA
  Round(
    CASE
      WHEN i.tipdoc = 16 THEN i1.pu - CASE WHEN i1.cant = 0 THEN 0 ELSE Coalesce(i1.tva,0)/i1.cant END
      ELSE PKG_LIST_BASE_IESIRI.CALCPIES(i.codies, i.tipdoc, i1.cant, i1.pu, i1.tva, i1.addim ,i1.coefdiscmaj, i1.valdiscpret)
    END *
    CASE
      WHEN I.TIPDOC &lt;&gt; 16 THEN 1
      WHEN Coalesce(i1.pu * i1.cant, 0) = 0 THEN 0
      WHEN Coalesce(i1.valdiscpret, 0) &lt;&gt; 0 THEN 1+i1.valdiscpret/(i1.pu * i1.cant)
      ELSE PKG_LIST_BASE_UTILS.GetCoefDiscMonetar(i.codies, i1.tiplinie, i1.codobiect, i1.contserv, -1, 1)
    END
  ,4) PretFinal, -- fara TVA
  CASE WHEN Coalesce(AE1.CANT,I1.CANT) = 0 THEN 0 ELSE Round(I1.TVA*Coalesce(L1.CANT,AE1.CANT,I1.CANT)/Coalesce(AE1.CANT,I1.CANT),4) END TvaLin,
  I1.INDEXLOCAL INDEXDOC, CAST(Coalesce(L1.CODLIVR1,0) AS VARCHAR(32)) CODLIVR1, CAST(AE1.CODIES  AS VARCHAR(32)) CODAE, CAST(AE1.CODIES1  AS VARCHAR(32)) CODAE1, CAST(L1.NRLIVR AS VARCHAR(32)) NRLIVR,
  CASE WHEN L1.DATALIVR BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(CURRENT_DATE),120) THEN L1.DATALIVR ELSE NULL END DATALIVR,
  llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos; &apos;||ag.prenume agent,
  Round(CASE WHEN L1.PretAchizOrig IS NOT NULL THEN L1.PretAchizOrig WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchizOrig,
  Round(CASE WHEN L1.PretAchiz     IS NOT NULL THEN L1.PretAchiz     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretAchiz,
  Round(CASE WHEN L1.PretInreg     IS NOT NULL THEN L1.PretInreg     WHEN ae.initializari = 1 AND ae.custodie = 1 THEN ae1.pucorelat ELSE 0 END,4) PretInreg,
  L1.DATAACHIZ, F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor,
  G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, c1.termen TermenLivr,
  Trunc(CURRENT_DATE) datasystem, ioa1.mg, i.an*100+i.luna AnLuna, CREF.CURS CURSSITV
FROM IESIRI1 I1
  INNER JOIN IESIRI I ON I.CODIES  = I1.CODIES
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = I.TIPDOC
  LEFT JOIN NMONEDE M ON M.CODMONEDA = Coalesce(I.MONEDA,0)
  LEFT JOIN IESLINK ILAE ON ILAE.CODIES1 = I1.CODIES1 AND I.TIPDOC = 26 AND ILAE.CODLINIEAVIZ IS NOT NULL
  LEFT JOIN IESIRI1 AE1 ON AE1.CODIES1 = ILAE.CODLINIEAVIZ
  LEFT JOIN IESIRI AE ON AE.CODIES = AE1.CODIES
  LEFT JOIN (
    SELECT
      l1.codlivr1, l1.codlivr, l1.codies1, l1.cant, l.nrlivr, l.datalivr,
      CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(CURRENT_DATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
      CASE WHEN nso.codnirstoc IS NOT NULL THEN Coalesce(nso.pret-nso.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Coalesce(lv.pretachiz,0) ELSE NULL END PretAchizOrig,
      CASE WHEN ns.codnirstoc  IS NOT NULL THEN Coalesce(ns.pret - ns.adaos,0) WHEN lv.codlivrval IS NOT NULL THEN Coalesce(lv.pretachiz,0) ELSE NULL END PretAchiz,
      CASE WHEN ns.codnirstoc  IS NOT NULL THEN Coalesce(ns.pret,0)            WHEN lv.codlivrval IS NOT NULL THEN Coalesce(lv.pretinreg,0) ELSE NULL END PretInreg,
      Ns.furn,
      Coalesce(LV.GEST, N.GEST, 0) gest,
      NS.CODLOCATIE,
      COALESCE(lv.codioart, ns.codioart,0) codioart
    FROM iesiri i
      INNER JOIN livr l ON l.codies = i.codies AND l.tiplivr = i.tipdoc
      INNER JOIN Livr1 L1 ON l.codlivr = l1.codlivr
      LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
      LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIRSTOC1 NS1 ON NS1.CODNIRSTOC = L1.CODNIRSTOC
      LEFT JOIN NIRSTOC NSO ON NSO.CODNIRSTOC = NS1.CODNIRSTOCORIG
      LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
    WHERE Coalesce(I.OPERAT,0) = 1 AND Coalesce(I.ANULAT,0) = 0
      AND I.TIPDOC NOT IN (14,15) -- MISCARI INTERNE
  ) L1 ON l1.codies1 = Coalesce(ae1.codies1, i1.codies1)
  LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
  LEFT JOIN NUM1 U1 ON U1.CODUM1  = I1.UMSEC
  LEFT JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT JOIN NPART F ON F.CODPART = L1.FURN
  LEFT JOIN NGEST G ON G.CODGEST = L1.GEST
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = L1.CODLOCATIE
  LEFT JOIN NPERS AG ON AG.CODPERS  = I.AGENT
  LEFT JOIN NAGENDA slivr ON slivr.codagenda = i.codlocatie
  LEFT JOIN NLOCALIT llivr ON llivr.codlocalit = slivr.codlocalit
  LEFT JOIN NJUDET jlivr ON jlivr.codjudet = llivr.codjudet
  LEFT JOIN IOART ioa ON ioa.codioart = COALESCE(ae1.codioartcust, l1.codioart)
  LEFT JOIN IOART1 ioa1 ON ioa1.codioart = ioa.codioart AND i.an*100+i.luna BETWEEN ioa1.alstart AND ioa1.alstop
  LEFT JOIN NCONT NC ON nc.codcont = Coalesce(ioa1.cont, i1.cont)
  LEFT JOIN IESLINK ILC ON ILC.CODIES1 = Coalesce(AE1.CODIES1, I1.CODIES1) AND ILC.CODLINIECOMANDA IS NOT NULL
  LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
  LEFT JOIN (SELECT partener, Min(datadoc)   vechime FROM iesiri  WHERE partener IS not null AND datadoc   BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(CURRENT_DATE),120) GROUP BY partener) vc ON vc.partener = i.partener
  LEFT JOIN (SELECT furn,     Min(dataachiz) vechime FROM nirstoc WHERE furn     IS not null AND dataachiz BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(CURRENT_DATE),120) GROUP BY furn    ) vf ON vf.furn = l1.furn
  LEFT JOIN (
    SELECT
      CASE WHEN N1.DATA = Min(N1.DATA) OVER (ORDER BY N1.DATA) THEN To_Date(&apos;00010101&apos;,&apos;YYYYMMDD&apos;) ELSE N1.DATA END DATASTART,
      Coalesce(LEAD(N1.DATA) OVER (ORDER BY N1.DATA) - 1,To_Date(&apos;25001231&apos;,&apos;YYYYMMDD&apos;)) DATASTOP,
      N1.VALOARE CURS
    FROM (
      SELECT
        Coalesce(Max (CASE WHEN SIMB = &apos;BANCASITV&apos;  THEN To_Number(Valoare, &apos;99999999999999999999&apos;) ELSE 0 END), 0) Codbanca,
        Coalesce(Max (CASE WHEN SIMB = &apos;MONEDASITV&apos; THEN To_Number(Valoare, &apos;99999999999999999999&apos;) ELSE 0 END), 0) CodMoneda
      FROM (
        SELECT UPPER(C1.simbol) SIMB, CL.CODCONSTLUNA, ROW_NUMBER() OVER (PARTITION BY UPPER(C1.simbol) ORDER BY ANSTART DESC, LUNASTART DESC) IDXConst
        FROM CONST1 C1
          INNER JOIN CATEGCONST CT ON CT.CODCATEG = C1.CODCATEG
          INNER JOIN CONSTLUNA CL ON CL.codconst1 = C1.codConst1
        WHERE UPPER(C1.simbol) IN (&apos;BANCASITV&apos;, &apos;MONEDASITV&apos;) AND CL.USERID = 0
      ) CL LEFT JOIN CONSTVAL CV ON CV.CODCONSTLUNA = CL.CODCONSTLUNA
      WHERE IDXConst = 1
    ) TMP INNER JOIN NMONEDE1 N1 ON N1.Codbanca = TMP.CodBanca AND N1.CodMoneda = TMP.CodMoneda
  ) CREF ON CREF.DATASTART &lt;= I.DATADOC AND CREF.DATASTOP &gt;= I.DATADOC
WHERE Coalesce(I.OPERAT,0) = 1 AND Coalesce(I.ANULAT,0) = 0
  AND I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)
  AND I.TIPDOC NOT IN (14,15) -- MISCARI INTERNE</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7CD7EA9757C68B8FD8651F0B7FAD2C42227619C1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_INTRARI (
&quot;NUMEDOC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;PREFIXDOC&quot;,&quot;SERIEDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;PARTENER&quot;,&quot;VECHIMEFURN&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;PRETORIG&quot;,&quot;PU&quot;,&quot;PRETFINAL&quot;,&quot;TVALIN&quot;,&quot;INDEXDOC&quot;,&quot;CODNIRSTOC&quot;,&quot;CODAE&quot;,&quot;CODAE1&quot;,&quot;NRRECEPT&quot;,&quot;DATARECEPT&quot;,&quot;LOCALITATE&quot;,&quot;JUDET&quot;,&quot;AGENT&quot;,&quot;PRETACHIZ&quot;,&quot;PRETINREG&quot;,&quot;DATAACHIZ&quot;,&quot;GESTIUNE&quot;,&quot;LOCATIE&quot;,&quot;CONT&quot;,&quot;DEN_CONT&quot;,&quot;TIPCONTABIL&quot;,&quot;TERMENLIVR&quot;,&quot;DATASYSTEM&quot;,&quot;MG&quot;,&quot;ANLUNA&quot;) AS
SELECT
  XM.NUMEPRESC NUMEDOC, CAST(I.CODINTR AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE SERIEDOC, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
  CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
  M.SIMBOL MONEDA, Round(I.CURS,4) Curs, P.DEN_PART PARTENER, Trunc(vc.vechime) VECHIMEFURN,
  CAST(i1.CodObiect AS VARCHAR(32)) CodObiect, Round(Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT),4) Cant, Round(I1.Pretorig,4) PretOrig, Round(I1.PU,4) PU,
  Round(I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj),4) PretFinal,
  Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Coalesce(-L1.CANT,NS.CANTNIR,I1.CANT)/I1.CANT END,4) TvaLin,
  I1.INDEXLOCAL INDEXDOC, CAST(Nvl(NS.CODNIRSTOC,0) AS CHAR(32)) CODNIRSTOC, CAST(AE1.CODINTR AS VARCHAR(32)) CODAE, CAST(AE1.CODINTR1 AS VARCHAR(32)) CODAE1, CAST(N.NRNIR AS VARCHAR(32)) NRRECEPT,
  CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATARECEPT,
  llivr.den_localit localitate, jlivr.den_judet judet, ag.nume||&apos; &apos;||ag.prenume agent,
  Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret - ns.adaos WHEN lv.codlivrval IS NOT NULL THEN lv.pretachiz ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretAchiz,
  Round(CASE WHEN ns.codnirstoc IS NOT NULL THEN ns.pret WHEN lv.codlivrval IS NOT NULL THEN lv.pretinreg ELSE I1.Pretorig*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) END,4) PretInreg,
  CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
  G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, c1.termen TermenLivr, Trunc(SYSDATE) datasystem,
  ioa1.mg, i.an*100+i.luna AnLuna
FROM INTRARI I
  INNER JOIN INTRARI1 I1 ON I1.CODINTR  = I.CODINTR
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = I.TIPDOC
  LEFT JOIN NMONEDE M ON M.CODMONEDA = Nvl(I.MONEDA,0)
  LEFT JOIN INTRLINK ILAE ON ILAE.CODINTR1 = I1.CODINTR1 AND I.TIPDOC = 9 AND ILAE.CODLINIEAVIZ IS NOT NULL
  LEFT JOIN INTRARI1 AE1 ON AE1.CODINTR1 = ILAE.CODLINIEAVIZ
  LEFT JOIN INTRARI AE ON AE.CODINTR = AE1.CODINTR
  LEFT JOIN DVI ON DVI.CODINTR = I.CODINTR
  LEFT JOIN DVI1 ON DVI1.CODDVI = DVI.CODDVI AND DVI1.CODINTR1 = I1.CODINTR1
  LEFT JOIN LIVR1 L1 ON L1.CODINTR1 = I1.CODINTR1
  LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
  LEFT JOIN NIRSTOC NS ON NS.CODOBIECT = I1.CODOBIECT AND ( ((L1.CODLIVR1 IS NOT NULL) AND (NS.CODNIRSTOC = L1.CODNIRSTOC)) OR ((L1.CODLIVR1 IS NULL) AND ((NS.CODINTR1 = NVL(AE1.CODINTR1,I1.CODINTR1)) OR (NS.CODDVI1 = DVI1.CODDVI1))))
  LEFT JOIN NIR N ON N.CODINTR = NVL(AE.CODINTR, I.CODINTR) AND N.CODNIR = NS.CODNIR
  LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
  LEFT JOIN NUM1 U1 ON U1.CODUM1  = I1.UMSEC
  LEFT JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT JOIN NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
  LEFT JOIN NPERS AG ON AG.CODPERS  = I.AGENT
  LEFT JOIN NAGENDA SLIVR ON SLIVR.CODAGENDA = I.CODLOCATIE
  LEFT JOIN NLOCALIT LLIVR ON LLIVR.CODLOCALIT = SLIVR.CODLOCALIT
  LEFT JOIN NJUDET JLIVR ON JLIVR.CODJUDET = LLIVR.CODJUDET
  LEFT JOIN IOART IOA ON IOA.CODIOART = COALESCE(LV.CODIOART, NS.CODIOART)
  LEFT JOIN (
    SELECT x.CODIOART, x.CodIoart1,
      CASE WHEN x.AnStart*12+x.LunaStart = fl.AnInitial*12+fl.LunaInitiala THEN 0 ELSE x.AnStart*12+x.LunaStart END ALStart ,
      Nvl(Lead(AnStart*12+LunaStart) Over (PARTITION BY Codioart ORDER BY AnStart*12+LunaStart)-1,fl.AnMaxim*12+fl.LunaMaxima) ALStop
    FROM Ioart1 x CROSS JOIN firmaluni fl
  ) iox ON iox.codioart = ioa.codioart AND i.an*12+i.luna BETWEEN iox.ALStart AND iox.ALStop
  LEFT JOIN IOART1 ioa1 ON ioa1.codioart1 = iox.codioart1
  LEFT JOIN NCONT NC ON NC.CODCONT = IOA1.CONT
  LEFT JOIN INTRLINK ILC ON ILC.CODINTR1 = Nvl(AE1.CODINTR1, I1.CODINTR1) AND ILAE.CODLINIECOMANDA IS NOT NULL
  LEFT JOIN COMANDA1 C1 ON C1.CODCOMANDA1 = ILC.CODLINIECOMANDA
  LEFT JOIN (SELECT PARTENER, MIN(DATADOC) VECHIME FROM INTRARI WHERE PARTENER IS NOT NULL AND DATADOC BETWEEN TO_DATE(1970,&apos;YYYY&apos;) AND ADD_MONTHS(TRUNC(SYSDATE),120) GROUP BY PARTENER) VC ON VC.PARTENER = I.PARTENER
WHERE NVL(I.OPERAT,0) = 1 AND NVL(I.ANULAT,0) = 0
  AND I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_JURNAL1_CU_ARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C22E5CA669E766DE79EBA42F9CBE0BE888B030EC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_JURNAL1_CU_ARTICOL (
&quot;CODOBIECT&quot;,&quot;DENUMIRE&quot;,&quot;CLASA&quot;,&quot;SIMBOL_DEBIT&quot;,&quot;SIMBOL_CREDIT&quot;,&quot;CODJURNAL1&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CODBAZAD&quot;,&quot;TIPBAZAD&quot;,&quot;ICONTBAZAD&quot;,&quot;CODDESCRD&quot;,&quot;ICONTD&quot;,&quot;TIPCONTD&quot;,&quot;ANALITICCONTD&quot;,&quot;CODBAZAC&quot;,&quot;TIPBAZAC&quot;,&quot;ICONTBAZAC&quot;,&quot;CODDESCRC&quot;,&quot;ICONTC&quot;,&quot;TIPCONTC&quot;,&quot;ANALITICCONTC&quot;,&quot;GEST&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DIRTY&quot;,&quot;SUBUNITATEA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;) AS
select
  case
    when j1.tipdoc in (1,2,3,4,6,7,9) then i1.codobiect
    when j1.tipdoc = 5 then dvi1.codobiect
    when j1.tipdoc in (12,13) then t1.codobiect
    when j1.tipdoc in (14,15,19,20,21,22,23,24,26) then ies1.codobiect
  end codobiect,
  o.denumire, cls.den_clasea Clasa,
  cd.simbol simbol_debit,
  cc.simbol simbol_credit,
  j1.CODJURNAL1,j1.CODDOC,j1.TIPDOC,j1.INDEXLOCAL,j1.CODBAZAD,j1.TIPBAZAD,
  j1.ICONTBAZAD,j1.CODDESCRD,j1.ICONTD,j1.TIPCONTD,j1.ANALITICCONTD,j1.CODBAZAC,
  j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,
  j1.GEST,j1.VALOARE,j1.VALOAREV,j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
  j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,j1.VALOARE_IFRS,j1.VALOAREV_IFRS
from jurnal1 j1
     inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
     inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
     left join intrari1 i1 on i1.codintr1 = j1.indexlocal
     left join dvi1 on dvi1.coddvi1 = j1.indexlocal
     left join transf1 t1 on t1.codtransf1 = j1.indexlocal
     left join iesiri1 ies1 on ies1.codies1 = j1.indexlocal
     left join nartobj o on o.codobiect = coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect)
     left join nart a on a.codarticol = o.codarticol
     left join nclasea cls on cls.codclasea = a.clasa
where coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect) &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_JURNAL_1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B8B26B58FF48F9AF6D4969FD4AA4E702D53113F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_JURNAL_1 (
&quot;TIPDOC&quot;,&quot;CODDOC&quot;,&quot;INDEXDOC&quot;,&quot;COD INREGISTRARE&quot;,&quot;NOTA COD&quot;,&quot;NOTA DESCRIERE&quot;,&quot;JURNAL COD&quot;,&quot;JURNAL DESCRIERE&quot;,&quot;DATA&quot;,&quot;CONT DEBIT SIMBOL&quot;,&quot;CONT DEBIT DESCRIERE&quot;,&quot;CONT CREDIT SIMBOL&quot;,&quot;CONT CREDIT DESCRIERE&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;GESTIUNE&quot;,&quot;OBSERVATII&quot;,&quot;ANLUNALUCRU&quot;,&quot;DOCUMENT&quot;,&quot;SIMBOLCONTSECUNDARDEBIT&quot;,&quot;DENUMIRECONTSECUNDARDEBIT&quot;,&quot;SIMBOLCONTSECUNDARCREDIT&quot;,&quot;DENUMIRECONTSECUNDARCREDIT&quot;,&quot;SUBUNITATEA&quot;) AS
SELECT
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
  IndexLocal IndexDoc,
  J.CodJurnal &quot;COD INREGISTRARE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
  DataDoc Data,
  CD.Simbol &quot;CONT DEBIT SIMBOL&quot;,
  CD.Den_Cont &quot;CONT DEBIT DESCRIERE&quot;,
  CC.Simbol &quot;CONT CREDIT SIMBOL&quot;,
  CC.Den_Cont &quot;CONT CREDIT DESCRIERE&quot;,
  J.VALOARE,
  J.VALOAREV,
  g.den_gest GESTIUNE,
  J.OBS OBSERVATII,
  J.AN*10+J.Luna ANLUNALUCRU,
  J.DOCUMENT,
  CSD.SIMBOL SIMBOLCONTSECUNDARDEBIT,
  CSD.DEN_CONT DENUMIRECONTSECUNDARDEBIT,
  CSC.SIMBOL SIMBOLCONTSECUNDARCREDIT,
  CSC.DEN_CONT DENUMIRECONTSECUNDARCREDIT,
  S.DEN_SUBUNIT SUBUNITATEA
FROM jurnal j
  INNER JOIN ncont cd ON cd.codcont = contd
  INNER JOIN ncont cc ON cc.codcont = contc
  INNER JOIN NCONT1 CD1 ON CD1.CODCONT = CD.CODCONT
  INNER JOIN NCONT1 CC1 ON CC1.CODCONT = CC.CODCONT
  LEFT  JOIN NCONTS CSD ON CSD.CODCONTS = CD1.CONTSECUNDAR
  LEFT  JOIN NCONTS CSC ON CSC.CODCONTS = CC1.CONTSECUNDAR
  LEFT JOIN ngest g ON g.codgest = j.gest
  LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = G.CODSUBUNIT
WHERE CD1.ANSTART*12+CD1.LUNASTART = (SELECT MAX(CD2.ANSTART*12+CD2.LUNASTART) FROM NCONT1 CD2 WHERE CD2.CODCONT = CD1.CODCONT AND CD2.ANSTART*12+CD2.LUNASTART &lt;= J.AN*12+J.LUNA)
  AND CC1.ANSTART*12+CC1.LUNASTART = (SELECT MAX(CC2.ANSTART*12+CC2.LUNASTART) FROM NCONT1 CC2 WHERE CC2.CODCONT = CC1.CODCONT AND CC2.ANSTART*12+CC2.LUNASTART &lt;= J.AN*12+J.LUNA)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_JURNAL_2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F16D733DA5EDCEBE809D22C7AF6BA2E281B7852</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_JURNAL_2 (
&quot;REC_ID&quot;,&quot;OPERATIE&quot;,&quot;COD INTERN&quot;,&quot;COD PARINTE&quot;,&quot;TIPDOC&quot;,&quot;CODDOC&quot;,&quot;INDEXDOC&quot;,&quot;TIP CONT&quot;,&quot;COD INREGISTRARE&quot;,&quot;NOTA COD&quot;,&quot;NOTA DESCRIERE&quot;,&quot;JURNAL COD&quot;,&quot;JURNAL DESCRIERE&quot;,&quot;DATA&quot;,&quot;CONT SIMBOL&quot;,&quot;CONT DESCRIERE&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;GESTIUNE&quot;,&quot;OBSERVATII&quot;,&quot;DOCUMENT&quot;,&quot;ANLUNALUCRU&quot;,&quot;VIZIBIL BALANTA&quot;,&quot;BALANTA SINTETICA&quot;) AS
SELECT
  Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
  &apos;DEBITARE&apos; OPERATIE,
  C.CODCONT &quot;COD INTERN&quot;,
  C.CODPARINTE &quot;COD PARINTE&quot;,
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
  IndexLocal IndexDoc,
  Decode(c.tipcont,0,&apos;Debitor&apos;,1,&apos;Creditor&apos;,&apos;Debitor/Creditor&apos;) &quot;TIP CONT&quot;,
  J.CodJurnal &quot;COD INREGISTRARE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
  DataDoc Data,
  C.Simbol &quot;CONT SIMBOL&quot;,
  C.Den_Cont &quot;CONT DESCRIERE&quot;,
  J.VALOARE,
  J.VALOAREV,
  g.den_gest GESTIUNE,
  J.OBS OBSERVATII,
  J.DOCUMENT,
  J.AN*10+J.Luna ANLUNALUCRU,
  Decode(c.vizibilbalanta,1,&apos;DA&apos;,&apos;NU&apos;) &quot;VIZIBIL BALANTA&quot;,
  Decode(c.balantasintetica,1,&apos;DA&apos;,&apos;NU&apos;) &quot;BALANTA SINTETICA&quot;
FROM jurnal j
  LEFT JOIN ncont c ON c.codcont = j.contd
  LEFT JOIN ngest g ON g.codgest = j.gest
UNION ALL
SELECT
  Row_Number() OVER (ORDER BY J.CodJurnal) RECID,
  &apos;CREDITARE&apos; OPERATIE,
  C.CODCONT &quot;COD INTERN&quot;,
  C.CODPARINTE &quot;COD PARINTE&quot;,
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.tipdoc END TipDoc,
  CASE WHEN j.tipdoc IN (32,36) THEN NULL ELSE j.coddoc END CodDoc,
  IndexLocal IndexDoc,
  Decode(c.tipcont,0,&apos;Debitor&apos;,1,&apos;Creditor&apos;,&apos;Debitor/Creditor&apos;) &quot;TIP CONT&quot;,
  J.CodJurnal &quot;COD INREGISTRARE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
  DataDoc Data,
  C.Simbol &quot;CONT SIMBOL&quot;,
  C.Den_Cont &quot;CONT DESCRIERE&quot;,
  J.VALOARE,
  J.VALOAREV,
  g.den_gest GESTIUNE,
  J.OBS OBSERVATII,
  J.DOCUMENT,
  J.AN*10+J.Luna ANLUNALUCRU,
  Decode(c.vizibilbalanta,1,&apos;DA&apos;,&apos;NU&apos;) &quot;VIZIBIL BALANTA&quot;,
  Decode(c.balantasintetica,1,&apos;DA&apos;,&apos;NU&apos;) &quot;BALANTA SINTETICA&quot;
FROM jurnal j
  LEFT JOIN ncont c ON c.codcont = j.contc
  LEFT JOIN ngest g ON g.codgest = j.gest
UNION ALL
SELECT
  tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
  &apos;SOLD DEBITOR&apos; OPERATIE,
  C.CODCONT &quot;COD INTERN&quot;,
  C.CODPARINTE &quot;COD PARINTE&quot;,
  NULL TipDoc,
  NULL CodDoc,
  NULL IndexDoc,
  Decode(c.tipcont,0,&apos;Debitor&apos;,1,&apos;Creditor&apos;,&apos;Debitor/Creditor&apos;) &quot;TIP CONT&quot;,
  NULL &quot;COD INREGISTRARE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
  To_Date( To_Char(cr.an,&apos;fm0000&apos;)||To_Char(cr.luna,&apos;fm00&apos;),&apos;yyyymm&apos;) Data,
  C.Simbol &quot;CONT SIMBOL&quot;,
  C.Den_Cont &quot;CONT DESCRIERE&quot;,
  CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldid, 0) + Nvl(cr.rulajpd, 0) END VALOARE,
  CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvid,0) + Nvl(cr.rulajvpd,0) END VALOAREV,
  NULL GESTIUNE,
  NULL OBSERVATII,
  NULL DOCUMENT,
  CR.AN*10+CR.Luna ANLUNALUCRU,
  Decode(c.vizibilbalanta,1,&apos;DA&apos;,&apos;NU&apos;) &quot;VIZIBIL BALANTA&quot;,
  Decode(c.balantasintetica,1,&apos;DA&apos;,&apos;NU&apos;) &quot;BALANTA SINTETICA&quot;
FROM ncontrul cr
  INNER JOIN ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
  INNER JOIN ncont c ON c.codcont = cr.codcont
  CROSS JOIN (SELECT Count(1) Nr FROM Jurnal) tmp
UNION ALL
SELECT
  tmp.nr + Row_Number() OVER (ORDER BY CR.CodContRUL) RECID,
  &apos;SOLD CREDITOR&apos; OPERATIE,
  C.CODCONT &quot;COD INTERN&quot;,
  C.CODPARINTE &quot;COD PARINTE&quot;,
  NULL TipDoc,
  NULL CodDoc,
  NULL IndexDoc,
  Decode(c.tipcont,0,&apos;Debitor&apos;,1,&apos;Creditor&apos;,&apos;Debitor/Creditor&apos;) &quot;TIP CONT&quot;,
  NULL &quot;COD INREGISTRARE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;NOTA COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;NOTA DESCRIERE&quot;,
  CAST (NULL AS NUMBER(10)) &quot;JURNAL COD&quot;,
  CAST (NULL AS VARCHAR2(100)) &quot;JURNAL DESCRIERE&quot;,
  To_Date( To_Char(cr.an,&apos;fm0000&apos;)||To_Char(cr.luna,&apos;fm00&apos;),&apos;yyyymm&apos;) Data,
  C.Simbol &quot;CONT SIMBOL&quot;,
  C.Den_Cont &quot;CONT DESCRIERE&quot;,
  CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldic, 0) + Nvl(cr.rulajpc, 0) END VALOARE,
  CASE WHEN c.clasa IN (6,7) THEN 0 ELSE Nvl(cs.soldvic,0) + Nvl(cr.rulajvpc,0) END VALOAREV,
  NULL GESTIUNE,
  NULL OBSERVATII,
  NULL DOCUMENT,
  CR.AN*10+CR.Luna ANLUNALUCRU,
  Decode(c.vizibilbalanta,1,&apos;DA&apos;,&apos;NU&apos;) &quot;VIZIBIL BALANTA&quot;,
  Decode(c.balantasintetica,1,&apos;DA&apos;,&apos;NU&apos;) &quot;BALANTA SINTETICA&quot;
FROM ncontrul cr
  INNER JOIN ncontsold cs ON cs.codcont = cr.codcont AND cs.an = cr.an
  INNER JOIN ncont c ON c.codcont = cr.codcont
  CROSS JOIN (SELECT Count(1) Nr FROM Jurnal) tmp</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_J_CHELT_ETX1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>179B39F0648B4616A6B5E6F423118E4B1AA05BF0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_J_CHELT_ETX1 (
&quot;CODOBIECT&quot;,&quot;DENUMIRE&quot;,&quot;CLASA&quot;,&quot;CODCMDINT1&quot;,&quot;NR_CMDINT&quot;,&quot;DATA_CMDINT&quot;,&quot;CANTCOMANDAT&quot;,&quot;CCOMANDI1&quot;,&quot;SIMBOL_DEBIT&quot;,&quot;SIMBOL_CREDIT&quot;,&quot;CODJURNAL1&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CODBAZAD&quot;,&quot;TIPBAZAD&quot;,&quot;ICONTBAZAD&quot;,&quot;CODDESCRD&quot;,&quot;ICONTD&quot;,&quot;TIPCONTD&quot;,&quot;ANALITICCONTD&quot;,&quot;CODBAZAC&quot;,&quot;TIPBAZAC&quot;,&quot;ICONTBAZAC&quot;,&quot;CODDESCRC&quot;,&quot;ICONTC&quot;,&quot;TIPCONTC&quot;,&quot;ANALITICCONTC&quot;,&quot;GEST&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;VAL_CONT&quot;,&quot;VALV_CONT&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DIRTY&quot;,&quot;SUBUNITATEA&quot;,&quot;ANLUNA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;,&quot;VAL_IFRS_CONT&quot;,&quot;VALV_IFRS_CONT&quot;) AS
select
i1.codobiect,
o.denumire, cls.den_clasea Clasa,
0 codcmdint1,
null as nr_cmdint,
null as data_cmdint,
0 CANTCOMANDAT,
i1.codcmdint1 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join intrari1 i1 on i1.codintr1 = j1.indexlocal
inner join intrari i on i.codintr = i1.codintr and j1.coddoc = i.codintr and j1.tipdoc = i.tipdoc
left join nartobj o on o.codobiect = i1.codobiect
left join nart a on a.codarticol = o.codarticol
left join nclasea cls on cls.codclasea = a.clasa
where
j1.AN&gt;2017 and
i1.codobiect &gt; 0 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/) and
nvl(i1.codcmdint1,0) = 0
union all
select
dvi1.codobiect,
o.denumire,
cls.den_clasea Clasa,
0 codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
i1.codcmdint1 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join dvi1 on dvi1.coddvi1 = j1.indexlocal
inner join intrari1 i1 on dvi1.codintr1 = i1.codintr1
inner join dvi on dvi.coddvi = dvi1.coddvi
inner join intrari i on i.codintr = i1.codintr and i.codintr = dvi.codintr and i.codintr = j1.coddoc and i.tipdoc = j1.tipdoc
inner join nartobj o on o.codobiect = dvi1.codobiect
inner join nart a on a.codarticol = o.codarticol
left join nclasea cls on cls.codclasea = a.clasa
where
j1.AN&gt;2017 and
dvi1.codobiect &gt; 0 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/) and
nvl(i1.codcmdint1,0) = 0
union all
select
t1.codobiect,
o.denumire,
cls.den_clasea Clasa,
0 codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
0 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join transf1 t1 on t1.codtransf1 = j1.indexlocal
inner join transf t on t.codtransf = t1.codtransf and j1.tipdoc = t.tipdoc and t.codtransf = j1.coddoc
inner join nartobj o on o.codobiect = t1.codobiect
inner join nart a on a.codarticol = o.codarticol
left join nclasea cls on cls.codclasea = a.clasa
where
j1.AN&gt;2017 and
t1.codobiect &gt; 0 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/)
union all
select
ies1.codobiect,
o.denumire, cls.den_clasea Clasa,
ies1.codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
0 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join iesiri1 ies1 on ies1.codies1 = j1.indexlocal
inner join iesiri ies on ies.codies = ies1.codies and j1.tipdoc = ies.tipdoc and j1.coddoc = ies.codies
inner join nartobj o on o.codobiect = ies1.codobiect
left join nart a on a.codarticol = o.codarticol
left join nclasea cls on cls.codclasea = a.clasa
where
j1.AN&gt;2017 and
ies1.codobiect &gt; 0 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/) and
nvl(ies1.codcmdint1,0) = 0
union all
select
0 codobiect,
&apos;...nedefinit...&apos; denumire,
&apos;...nedefinit...&apos; Clasa,
0 codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
0 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join trezor1 t1 on t1.codtrezor1 = j1.indexlocal
inner join trezor t on t.codtrezor = j1.coddoc and t.codtrezor = t1.codtrezor and t.tipdoc = j1.tipdoc
where
j1.AN&gt;2017 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/)
union all
select
0 codobiect,
&apos;...nedefinit...&apos; denumire,
&apos;...nedefinit...&apos; Clasa,
0 codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
0 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join nc1 on nc1.codnc1 = j1.indexlocal
inner join nc on nc.codnc = j1.coddoc and j1.tipdoc = 35 and nc.codnc = nc1.codnc
where
j1.AN&gt;2017 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/)
union all
select
0 codobiect,
&apos;...nedefinit...&apos; denumire,
&apos;...nedefinit...&apos; Clasa,
0 codcmdint1,
null nr_cmdint,
null data_cmdint,
0 CANTCOMANDAT,
0 ccomandi1,
cd.simbol simbol_debit,
cc.simbol simbol_credit,
j1.CODJURNAL1,
j1.CODDOC,
j1.TIPDOC,
j1.INDEXLOCAL,
j1.CODBAZAD,
j1.TIPBAZAD,
j1.ICONTBAZAD,
j1.CODDESCRD,
j1.ICONTD,
j1.TIPCONTD,
j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,j1.GEST,
j1.VALOARE,j1.VALOAREV,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.an*100+j1.luna AnLuna,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
inner join cheltavans ca on ca.codcheltavans = j1.coddoc and j1.tipdoc = 52
where
j1.AN&gt;2017 and
cd.simbol not in (&apos;601&apos;,&apos;607&apos;,&apos;665&apos;,&apos;681.01&apos;,&apos;681.02&apos;,&apos;681.03&apos;,&apos;681.04&apos;,&apos;691&apos;) and
(cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; /*OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;*/)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_MISCINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12DD943AC32885802ACCE08A13178F981516FD0C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_MISCINT (
&quot;NUMEDOC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;PREFIXDOC&quot;,&quot;SERIEDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODOBIECT&quot;,&quot;CANT&quot;,&quot;PU&quot;,&quot;TVALIN&quot;,&quot;INDEXDOC&quot;,&quot;CODDOC1&quot;,&quot;NRLIVREC&quot;,&quot;DATALIVREC&quot;,&quot;PRETACHIZ&quot;,&quot;PRETINREG&quot;,&quot;DATAACHIZ&quot;,&quot;FURNIZOR&quot;,&quot;VECHIMEFURNIZOR&quot;,&quot;GESTIUNE&quot;,&quot;LOCATIE&quot;,&quot;CONT&quot;,&quot;DEN_CONT&quot;,&quot;TIPCONTABIL&quot;,&quot;DATASYSTEM&quot;,&quot;MG&quot;,&quot;ANLUNA&quot;) AS
SELECT ------- diminuari si mariri -------
  XM.NUMEPRESC NUMEDOC, CAST(I.CODIES AS VARCHAR(32)) CODDOC, I.TIPDOC, I.PREFIXDOC, DC.SERIE seriedoc, CAST(I.NRDOC AS VARCHAR(32)) NRDOC,
  CASE WHEN I.DATADOC BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN I.DATADOC ELSE NULL END DATADOC,
  CAST(I1.CodObiect AS VARCHAR(32)) CodObiect, Round(Nvl(L1.CANT, I1.CANT),4) Cant, Round(I1.PU,4) PU, Round(CASE WHEN Nvl(I1.CANT,0) = 0 THEN 0 ELSE I1.TVA*Nvl(L1.CANT, I1.CANT)/I1.CANT END,4) TvaLin,
  I1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
  CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
  Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
  CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
  F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont, ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
  ioa1.mg, i.an*100+i.luna AnLuna
FROM IESIRI I
  INNER JOIN LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
  INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
  INNER JOIN IESIRI1 I1 ON I1.CODIES1  = L1.CODIES1
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = I.TIPDOC
  LEFT JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
  LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = I.CARNETDOC
  LEFT JOIN NUM1 U1 ON U1.CODUM1  = I1.UMSEC
  LEFT JOIN NPART F ON F.CODPART = NS.FURN
  LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
  LEFT JOIN IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
  LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = IOA.CODIOART
  LEFT JOIN NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, I1.CONT)
  LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
WHERE Nvl(I.OPERAT,0) = 1 AND Nvl(I.ANULAT,0) = 0
  AND IOA1.ANSTART * 12 + IOA1.LUNASTART = (SELECT MAX(ANSTART*12+LUNASTART) FROM IOART1 WHERE CODIOART = IOA.CODIOART AND ANSTART*12+LUNASTART &lt;= I.AN * 12 + I.LUNA)
  AND I1.TIPLINIE IN (&apos;=&apos;,&apos;S&apos;,&apos;V&apos;)
  AND I.TIPDOC IN (14,15)
UNION ALL
SELECT -- iesiri prin transfer
  XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)) NRDOC,
  CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
  CAST(T1.CodObiect AS VARCHAR(32)) CodObiect, -Round(Nvl(L1.CANT, T1.CANT),4) Cant, Round(T1.PU,4) PU, -Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(L1.CANT, T1.CANT)/T1.CANT END,4) TvaLin,
  T1.INDEXLOCAL INDEXDOC, CAST(Nvl(L1.CODLIVR1,0) AS VARCHAR(32)) CODDOC1, CAST(L.NRLIVR AS VARCHAR(32)) NRLIVREC,
  CASE WHEN L.DATALIVR BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN L.DATALIVR ELSE NULL END DATALIVREC,
  Round(COALESCE(lv.pretachiz, ns.pret - ns.adaos),4) PretAchiz, Round(COALESCE(lv.pretinreg, ns.pret),4) PretInreg,
  CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
  F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
  ioa1.mg, t.an*100+t.luna AnLuna
FROM TRANSF T
  INNER JOIN LIVR L ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
  INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
	INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF AND T1.CODTRANSF1 = L1.CODIES1
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = T.TIPDOC
  LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
  LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
	LEFT JOIN LIVRVAL LV ON L1.CODLIVR1 = LV.CODLIVR1
  LEFT JOIN NUM1 U1 ON U1.CODUM1  = T1.UMSEC
  LEFT JOIN NPART F ON F.CODPART = NS.FURN
  LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN NGEST G ON G.CODGEST = Nvl(N.GEST, LV.GEST)
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
  LEFT JOIN IOART IOA ON IOA.CODIOART = NVL(LV.CODIOART, NS.CODIOART)
  LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = IOA.CODIOART
  LEFT JOIN NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
  LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0
  AND IOA1.ANSTART * 12 + IOA1.LUNASTART = (SELECT MAX (ANSTART*12+LUNASTART) FROM IOART1 WHERE CODIOART = IOA.CODIOART AND ANSTART*12+LUNASTART &lt;= T.AN * 12 + T.LUNA)
UNION ALL
SELECT -- intrari prin transfer
  XM.NUMEPRESC NUMEDOC, CAST(T.CODTRANSF AS VARCHAR(32)) CODDOC, T.TIPDOC, T.PREFIXDOC, DC.SERIE SERIEDOC, CAST(T.NRDOC AS VARCHAR(32)), CASE WHEN T.DATADOC BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN T.DATADOC ELSE NULL END DATADOC,
  CAST(T1.CodObiect AS VARCHAR(32)), Round(Nvl(NS.CANTNIR, T1.CANT),4) Cant, Round(T1.PU,4) PU, Round(CASE WHEN Nvl(T1.CANT,0) = 0 THEN 0 ELSE T1.TVA*Nvl(NS.CANTNIR, T1.CANT)/T1.CANT END,4) TvaLin,
  T1.INDEXLOCAL INDEXDOC, CAST( Nvl(NS.CODNIRSTOC,0) AS VARCHAR(32))  CODDOC1, CAST(N.NRNIR AS VARCHAR(32))  NRLIVREC, CASE WHEN N.DATANIR BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN N.DATANIR ELSE NULL END DATALIVREC,
  Round(ns.pret - ns.adaos,4) PretAchiz, Round(ns.pret,4) PretInreg,
  CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
  F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
  ioa1.mg, t.an*100+t.luna AnLuna
FROM TRANSF T
  INNER JOIN TRANSF1 T1 ON T1.CODTRANSF = T.CODTRANSF
  INNER JOIN NIR N ON T.CODTRANSF = N.CODTRANSF
  INNER JOIN NIRSTOC NS ON NS.CODTRANSF1 = T1.CODTRANSF1 AND NS.CODNIR = N.CODNIR
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = T.TIPDOC
  LEFT JOIN DOCCARNETE DC ON DC.CODCARNET = T.CARNETDOC
  LEFT JOIN NUM1 U1 ON U1.CODUM1  = T1.UMSEC
  LEFT JOIN NPART F ON F.CODPART = NS.FURN
  LEFT JOIN NGEST G ON G.CODGEST = N.GEST
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
  LEFT JOIN IOART IOA ON IOA.CODIOART = NS.CODIOART
  LEFT JOIN IOART1 IOA1 ON IOA1.CODIOART = IOA.CODIOART
  LEFT JOIN NCONT NC ON NC.CODCONT = NVL(IOA1.CONT, T1.CODCONT)
  LEFT JOIN (SELECT furn, Min(dataachiz) vechime FROM nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
WHERE Nvl(T.OPERAT,0) = 1 AND Nvl(T.ANULAT,0) = 0
  AND IOA1.ANSTART * 12 + IOA1.LUNASTART = (SELECT MAX (ANSTART*12+LUNASTART) FROM IOART1 WHERE CODIOART = IOA.CODIOART AND ANSTART*12+LUNASTART &lt;= T.AN * 12 + T.LUNA)</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C96CCB810AC4243DACD2A297179B7ABDC9045DFB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_STOC (
&quot;CODOBIECT&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;DATASTOC&quot;,&quot;PACHIZ&quot;,&quot;PINREG&quot;,&quot;DATAACHIZ&quot;,&quot;FURNIZOR&quot;,&quot;VECHIMEFURNIZOR&quot;,&quot;GESTIUNE&quot;,&quot;LOCATIE&quot;,&quot;CONT&quot;,&quot;DEN_CONT&quot;,&quot;TIPCONTABIL&quot;,&quot;DATASYSTEM&quot;,&quot;MG&quot;,&quot;ANLUNA&quot;) AS
SELECT
  CAST(Ns.CodObiect AS VARCHAR(32)) CodObiect, NL.REST, NL.RESTUM1, NL.RESTUM2, Last_Day(To_Date(NL.An||&apos;.&apos;||NL.Luna,&apos;yyyy.mm&apos;)) DataStoc, Round(ns.pret - ns.adaos,4) PAchiz, ns.pret PInreg,
  CASE WHEN NS.DATAACHIZ BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) THEN NS.DATAACHIZ ELSE NULL END DATAACHIZ,
  F.DEN_PART Furnizor, Trunc(vf.vechime) VechimeFurnizor, G.DEN_GEST GESTIUNE, LOC.DENUMIRE LOCATIE, nc.simbol cont, nc.den_cont,  ioa.den_ioart tipcontabil, Trunc(SYSDATE) datasystem,
  ioa1.mg, nl.an*100+nl.luna anluna
FROM NIRLUNA NL
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = NL.CODNIRSTOC
  INNER JOIN NARTOBJ O ON O.CODOBIECT = NS.CODOBIECT
  INNER JOIN IOART IOA ON IOA.CODIOART = NS.CODIOART
  INNER JOIN (
    SELECT
      x.CODIOART, x.MG, x.Cont,
      CASE WHEN x.AnStart*12+x.LunaStart = fl.AnInitial*12+fl.LunaInitiala THEN 0 ELSE x.AnStart*12+x.LunaStart END ALStart ,
      Nvl(Lead(AnStart*12+LunaStart) Over (PARTITION BY Codioart ORDER BY AnStart*12+LunaStart)-1,fl.AnMaxim*12+fl.LunaMaxima) ALStop
    FROM Ioart1 x CROSS JOIN firmaluni fl
  ) IOA1 ON IOA1.CODIOART = NS.CODIOART AND nl.an*12+nl.luna BETWEEN ioa1.ALStart AND ioa1.ALStop
  LEFT JOIN NCONT NC ON NC.CODCONT = IOA1.CONT
  LEFT JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT JOIN NUM U  ON U.CODUM  = A.UM
  LEFT JOIN NUM U1 ON U1.CODUM = A.UM1
  LEFT JOIN NUM U2 ON U2.CODUM = A.UM2
  LEFT JOIN NCLASEA CA ON CA.CODCLASEA = A.CLASA
  LEFT JOIN NPART F ON F.CODPART = NS.FURN
  LEFT JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN NGEST G ON G.CODGEST = N.GEST
  LEFT JOIN NLOCATII LOC ON LOC.CODLOCATIE = NS.CODLOCATIE
  LEFT JOIN (SELECT furn, Min(dataachiz) vechime   FROM nirstoc WHERE furn IS not null AND dataachiz BETWEEN To_Date(1970,&apos;yyyy&apos;) AND Add_months(Trunc(SYSDATE),120) GROUP BY furn) vf ON vf.furn = ns.furn
WHERE NL.AN*12+NL.LUNA &lt;= (SELECT AnCurent*12+LunaCurenta-1 FROM FIRMALUNI)
  AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
  AND IOA1.MG &lt;&gt; 5
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_STOC_MOMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CF3EF084FAD36C7D2AA7D5F9BD308290BCAC4E3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_STOC_MOMENT (
&quot;CODNIRSTOC&quot;,&quot;UMSEC&quot;,&quot;CODOBIECT&quot;,&quot;CODIOART&quot;,&quot;GEST&quot;,&quot;PRETACHIZ&quot;,&quot;PRET&quot;,&quot;ADAOS&quot;,&quot;TVA&quot;,&quot;TIPSERIE&quot;,&quot;STOC&quot;,&quot;PRELUAT&quot;,&quot;PROCENTADAOS&quot;,&quot;INTRATLA&quot;,&quot;TG&quot;,&quot;PUMAXIMAL&quot;,&quot;CODPART&quot;,&quot;SERIE&quot;,&quot;CODNIRSER&quot;,&quot;CODSERIE&quot;,&quot;CODNIR&quot;,&quot;CODINTR1&quot;,&quot;CODINTR&quot;,&quot;FLAG&quot;,&quot;CODTRANSF1&quot;,&quot;DATAACHIZ&quot;,&quot;TIPDOCACHIZ&quot;,&quot;TIPINTRARESTOC&quot;,&quot;LOCATIE&quot;,&quot;RESTUM1&quot;,&quot;STOCUM1&quot;,&quot;PRELUATUM1&quot;,&quot;RESTUM2&quot;,&quot;STOCUM2&quot;,&quot;PRELUATUM2&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;FURNIZOR&quot;,&quot;CODLOCATIE&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DENFURN&quot;) AS
SELECT
  NS.CODNIRSTOC,
  NS.UMSEC,
  NS.CODOBIECT,
  NS.CODIOART,
  NIRCURENT.GEST,
  ROUND(NS.PRET - COALESCE(NS.ADAOS, 0), 10) AS PRETACHIZ,
  ROUND(NS.PRET, 10) AS PRET,
  NS.ADAOS,
  NS.TVA,
  NS.TIPSERIE,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN ROUND(NSE.REST, 10)
     ELSE ROUND(NS.REST, 10)
   END
   ) AS STOC,
  0.0 AS PRELUAT,
  NS.PROCENTADAOS,
  NIRCURENT.DATANIR AS INTRATLA,
  NS.TG,
  NS.PUMAXIMAL,
  NS.FURN AS CODPART,
  (CASE
    WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE)
    ELSE &apos;&apos;
   END
  ) AS SERIE,
  COALESCE(NSE.CODNIRSER, 0) CODNIRSER,
  NSE.CODSERIE,
  0 AS CODNIR,
  0 AS CODINTR1,
  0 AS CODINTR,
  0 AS FLAG,
  CODTRANSF1,
  NS.DATAACHIZ,
  NS.TIPDOCACHIZ,
  NIRCURENT.TIPNIR AS TIPINTRARESTOC,
  L.DENUMIRE AS LOCATIE,
  NS.RESTUM1,
  NS.RESTUM1 AS STOCUM1,
  0.0 AS PRELUATUM1,
  NS.RESTUM2,
  NS.RESTUM2 AS STOCUM2,
  0.0 AS PRELUATUM2,
  NS.CODGESTPROD,
  NS.SUBUNITATEA,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS FURNIZOR,
  NS.CODLOCATIE,
  S.DEN_SUBUNIT,
  ACLI.DENUMIRE AS DENFURN
FROM
  NIRSTOC NS
  INNER JOIN NIR NIRCURENT         ON NIRCURENT.CODNIR      = NS.CODNIR
  INNER JOIN NGEST G               ON G.CODGEST             = NIRCURENT.GEST
  INNER JOIN NSUBUNIT S            ON S.CODSUBUNIT          = G.CODSUBUNIT
  LEFT  JOIN NARTCLI  ACLI         ON ACLI.CODOBIECT        = NS.CODOBIECT AND ACLI.CODPART = NS.FURN
  LEFT  JOIN NLOCATII L            ON L.CODLOCATIE          = NS.CODLOCATIE
  LEFT  JOIN NIRSER NSE            ON NSE.CODNIRSTOC        = NS.CODNIRSTOC,
  (SELECT CODIOART, MG FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= (select anmaxim*12+lunamaxima from firmaluni))
  ) IOALUNA
WHERE
  NS.REST &lt;&gt; 0 AND IOALUNA.CODIOART = NS.CODIOART
  AND IOALUNA.MG &lt;&gt; 5 AND IOALUNA.MG &lt;&gt; 3
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BUGETPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2075E441CF8E929091FA70B568AEC815BEDD033D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BUGETPROD (
&quot;CODBUGETPROD&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS&quot;,&quot;ANULAT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;SAPTAMANA&quot;,&quot;ANIMPORT&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;) AS
select
  codbugetprod,
  an,
  luna,
  subunitatea,
  userid,
  datacreare,
  obs,
  nvl(anulat,0) anulat,
  nvl(operat,0) operat,
  nvl(blocat,0) blocat,
  saptamana,
  animport,
  iso_week_to_date(an, saptamana) datastart,
  iso_week_to_date(an, saptamana) + 6 datastop
from bugetprod
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BUGETRECTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B676C7E44B523C2B6DBA6786356A3B6FE7E9721</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BUGETRECTIF (
&quot;CODBUGETRECTIF&quot;,&quot;DEN_ANALIZA&quot;,&quot;DATADOC&quot;,&quot;NRDOC&quot;,&quot;AN&quot;,&quot;LUNASURSA&quot;,&quot;LUNADEST&quot;,&quot;DATACREARE&quot;,&quot;OBS&quot;,&quot;USERNAME&quot;) AS
select
  B.codbugetRectif,
  A.DEN_ANALIZA,
  B.DataDoc,
  B.Nrdoc,
  B.An,
  B.LunaSursa,
  B.LunaDest,
  B.datacreare,
  B.obs,
  UT.Username
from bugetRectif B
Left join Analiza A on A.CodAnaliza=B.CodAnaliza
LEFT JOIN TMP_UTILIZATOR UT on UT.CodUtilizator = B.USERID
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CARNETEMACHETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9831349D595D49F1CB6BFB0D12C3A2A75C09DD1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CARNETEMACHETA (
&quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;,&quot;SUBUNITATEA&quot;,&quot;CODPOSTRETAIL&quot;,&quot;DEN_SUBUNIT&quot;) AS
SELECT &quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;, SUBUNITATEA, CODPOSTRETAIL,
       DEN_SUBUNIT
FROM
  DOCCARNETE D,
  NSUBUNIT S
WHERE
  D.SUBUNITATEA = S.CODSUBUNIT
  AND CODCARNET IN
  (SELECT CODCARNET FROM DOCLINK WHERE CODMACHETA = PKG_CARNETEDOC.GETMACHETACURENTA )
  AND
  ( NVL(SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
    OR COALESCE(ALLSUBUNIT, 0) = 1
  )
  AND ( (NVL(DEDICAT,0) = 0)
        OR
        (EXISTS (SELECT CODDOCUSERS FROM DOCUSERS WHERE CODUSER = PKG_GLOBALS.GETUSERID AND  CODCARNET = D.CODCARNET ) )
      )
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CARNETEMACHETA_0</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EB7E55A4EAE504C9C0A7C7311E0BA4215D660259</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CARNETEMACHETA_0 (
&quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;,&quot;SUBUNITATEA&quot;,&quot;CODPOSTRETAIL&quot;,&quot;DEN_SUBUNIT&quot;) AS
SELECT &quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;, SUBUNITATEA, CODPOSTRETAIL,
       DEN_SUBUNIT
FROM
  DOCCARNETE D,
  NSUBUNIT S
WHERE
  D.SUBUNITATEA = S.CODSUBUNIT
  AND CODCARNET IN
  (SELECT CODCARNET FROM DOCLINK WHERE CODMACHETA = PKG_CARNETEDOC.GETMACHETACURENTA )
  AND
  ( NVL(SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
    OR COALESCE(ALLSUBUNIT, 0) = 1
  )
  AND ( (NVL(DEDICAT,0) = 0)
        OR
        (EXISTS (SELECT CODDOCUSERS FROM DOCUSERS WHERE CODUSER = PKG_GLOBALS.GETUSERID AND  CODCARNET = D.CODCARNET ) )
      )
UNION ALL
SELECT
0 CODCARNET, &apos;&apos; SIMBOL,&apos;...nedefinit...&apos; DENUMIRE,&apos;&apos; SERIE,null STARTNR,null ENDNR, null FREENR, 0 INACTIV, 0 SUBUNITATEA, 0 CODPOSTRETAIL,&apos;&apos; DEN_SUBUNIT
FROM DUAL
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CARNETE_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0CD86EC79C9DE5A1500816C0C943DABB5D3974D8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CARNETE_SUB (
&quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;,&quot;SUBUNITATEA&quot;,&quot;CODPOSTRETAIL&quot;) AS
SELECT &quot;CODCARNET&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;STARTNR&quot;,&quot;ENDNR&quot;,&quot;FREENR&quot;,&quot;INACTIV&quot;, SUBUNITATEA, CODPOSTRETAIL
FROM DOCCARNETE D
WHERE
CODCARNET IN
(SELECT CODCARNET FROM DOCLINK WHERE CODMACHETA = PKG_CARNETEDOC.GETMACHETACURENTA )
AND
NVL(SUBUNITATEA,1) = PKG_GLOBALS.GETSUBUNITATE_DOC
AND ( (NVL(DEDICAT,0) = 0)
      OR
      (EXISTS (SELECT CODDOCUSERS FROM DOCUSERS WHERE CODUSER = PKG_GLOBALS.GETUSERID AND  CODCARNET = D.CODCARNET ) ))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CATEGCONST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B10DFE2E8DE9E702A504B1E8344292FFDA8D15F9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CATEGCONST (
&quot;CODCATEG&quot;,&quot;INDEXLOCAL&quot;,&quot;DENUMIRE&quot;,&quot;TIPCATEG&quot;) AS
SELECT c.CODCATEG, C.INDEXLOCAL, c.DENUMIRE, c.TIPCATEG
FROM CATEGCONST c
WHERE c.TIPCATEG = PKG_CATEGCONST.GETTIPCATEGORIE
ORDER BY INDEXLOCAL</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CENTRECOST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>099130906EF422673B029B45AF5C94A8F8A2703A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CENTRECOST (
&quot;CODCENTRU&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;DOMENIU&quot;) AS
select codcentru, simbol, denumire, domeniu
    from centrecost
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE8C104B058BE65E42ABAC1E4106B9F2BFC9A689</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CERTIF (
&quot;CODCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;DATAPRIMIRE&quot;,&quot;FISIER&quot;,&quot;CODPART&quot;,&quot;CODOBIECT&quot;,&quot;CODSERIE&quot;,&quot;NUMEFISIER&quot;,&quot;EXT&quot;,&quot;SUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DENUMIRE&quot;,&quot;SERIE&quot;,&quot;CODGEST&quot;,&quot;DEN_PART&quot;,&quot;NUMEEXTFIS&quot;,&quot;TIPPART&quot;) AS
SELECT
      C.CodCertif,
      C.NrCertif,
      C.DataPrimire,
      C.Fisier,
      C.CodPart,
      C.CodObiect,
      C.CodSerie,
      C.NumeFisier,
      C.Ext,
      C.Subunitate,
      C.UserId,
      C.DataCreare,
      OBJ.Denumire,
      S.Serie,
      C.Codgest,
      case
        when C.TipPart &lt;&gt; 3 then P.Den_Part
        else G.Den_Gest
      end Den_Part,
      C.NUMEFISIER||&apos;.&apos;||C.Ext NumeExtFis,
      C.TipPart
    FROM CERTIF C
         INNER JOIN NARTOBJ OBJ ON C.CodObiect = OBJ.CodObiect
         INNER JOIN NSERII    S ON C.CodSerie  = S.CodSerie
         LEFT  JOIN NPART     P ON C.CodPart   = P.CodPart
         LEFT  JOIN NGEST     G ON C.CodGest   = G.CodGest 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>09808282D1FFD791221C397AA77E3105FC9BFEA6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_INI (
&quot;CODINTR1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;NRDOC&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;) AS
SELECT
  I1.CODINTR1,
  I.DATADOC,
  I.AN,
  I.LUNA,
  I.NRDOC,
  O.DENUMIRE,
  CASE
    WHEN I.TIPDOC = 3 THEN ROUND((I1.PU * I1.CANT - I1.TVA ) * NVL(I.CURS, 1), 2)
    ELSE ROUND((I1.PU * I1.CANT) * NVL(I.CURS, 1), 2)
  END AS VALOARE
FROM
   CHELTAVANS CAV,
   CHELTAVANS1 CAV1,
   INTRARI I,
   INTRARI1 I1,
   NARTOBJ O
WHERE
  I1.TIPLINIE            = &apos;S&apos;
  AND CAV.CODINTR1       = I1.CODINTR1
  AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
  AND CAV1.ANSTART       = PKG_GLOBALS.GETANLUCRU
  AND CAV1.LUNASTART     = PKG_GLOBALS.GETLUNALUCRU
--  AND PKG_CATEGCONST.ESTECHELTAVANS(I1.CONTSERV) = 1
  AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(I1.CONTSERV))
  AND I.CODINTR   = I1.CODINTR
  AND I.OPERAT    = 1
  AND I.ANULAT    = 0
  AND O.CODOBIECT = I1.CODOBIECT
  AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
  AND NVL(I.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(I.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
  AND NVL(I.SUBUNITATEA,1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_INTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52DFF648A11FDD9C394E2E2EBDFABAE3657B27EB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_INTR (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;) AS
SELECT
  I1.CODINTR1,
  0 AS CODOBLIGPIF,
  0 AS CODNC1,
  I.DATADOC,
  I.AN,
  I.LUNA,
  O.DENUMIRE,
  P.DEN_PART,
  CASE
    WHEN I.TIPDOC = 3 AND C.TipTVAMixt=&apos;2&apos; THEN ROUND((I1.PU * I1.CANT - I1.TVA )     * NVL(I.CURS, 1), 2)
    WHEN I.TIPDOC = 3 AND I1.TVANEDED = 1  THEN ROUND((I1.PU * I1.CANT  )             * NVL(I.CURS, 1), 2)
    WHEN I.TIPDOC = 3 AND I1.TVANEDED = 3  THEN ROUND((I1.PU * I1.CANT - I1.TVA / 2 ) * NVL(I.CURS, 1), 2)
    WHEN I.TIPDOC = 3                      THEN ROUND((I1.PU * I1.CANT - I1.TVA )     * NVL(I.CURS, 1), 2)
    WHEN C.TipTVAMixt=&apos;2&apos;                  THEN ROUND((I1.PU * I1.CANT)               * NVL(I.CURS, 1), 2)
    WHEN I1.TVANEDED = 1                   THEN ROUND((I1.PU * I1.CANT + I1.TVA)      * NVL(I.CURS, 1), 2)
    WHEN I1.TVANEDED = 3                   THEN ROUND((I1.PU * I1.CANT + I1.TVA / 2)  * NVL(I.CURS, 1), 2)
    ELSE ROUND((I1.PU * I1.CANT) * NVL(I.CURS, 1), 2)
  END VALOARE,
  ( SELECT DECODE(COUNT(*),0,0,1)
    FROM CHELTAVANS CAV, CHELTAVANS1 CAV1
    WHERE CAV.CODINTR1 = I1.CODINTR1 AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS AND CAV1.ANSTART = PKG_GLOBALS.GETANLUCRU AND CAV1.LUNASTART = PKG_GLOBALS.GETLUNALUCRU
  ) AS REZOLVAT
FROM INTRARI I
  INNER JOIN INTRARI1 I1 ON I1.CODINTR = I.CODINTR
  INNER JOIN NPART P ON P.CODPART = I.PARTENER
  INNER JOIN NARTOBJ O ON O.CODOBIECT = I1.CODOBIECT
  CROSS JOIN (SELECT Nvl(pkg_categconst.GetValConstanta(&apos;TipTVAMixt100&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU),&apos;0&apos;) TipTVAMixt FROM dual) C
WHERE I.TIPDOC &lt;&gt; 2
  AND I.OPERAT = 1 AND I.ANULAT = 0
  AND I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
  AND I1.TIPLINIE = &apos;S&apos;
  AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(I1.CONTSERV))
  AND NVL(I.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(I.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
  AND NVL(I.SUBUNITATEA,1) IN (SELECT codsubunit FROM tmp_subunitdedicate)
  AND (
    -- POZITII DIN INTRARI1 CARE NU AU FOST INCA DESCRISE
    (SELECT COUNT(AV1.CODCHELTAVANS1) FROM CHELTAVANS AV, CHELTAVANS1 AV1 WHERE AV.CODINTR1 = I1.CODINTR1 AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS) = 0
    OR
    -- POZITII DIN CHELTAVANS1 CARE S-AU PROPAGAT PRIN INCHIDERE DE LUNA IN LUNA DE LUCRU
    (SELECT COUNT(AV1.CODCHELTAVANS1) FROM CHELTAVANS AV, CHELTAVANS1 AV1 WHERE AV.CODINTR1 = I1.CODINTR1 AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS AND AV1.ANSTART = PKG_GLOBALS.GETANLUCRU AND AV1.LUNASTART = PKG_GLOBALS.GETLUNALUCRU) &gt; 0
  )</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_INTR_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8056659751CBF2859086D1FF3AE71A17F943204</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_INTR_EXT (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_CHELTAVANS_INTR CT
  left join ngest ng on ng.codgest = ct.codgest_rez
  left join nsubunit nsch on nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODINTR1 AS AV_CODINTR1, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODINTR1, 0) &lt;&gt; 0
    GROUP by CODINTR1
  ) AV1_INTR
  ON AV1_INTR.AV_CODINTR1 = CT.CODINTR1
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_INTR.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_NC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>913142DE519FF7CA86831E936794B3F204B959E3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_NC1 (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;) AS
SELECT
   0 AS CODINTR1,
   0 AS CODOBLIGPIF,
   N1.CODNC1 ,
   N.DATADOC,
   N.AN,
   N.LUNA,
  &apos;Chelt Avans din NC &apos; AS DENUMIRE,
  P.DEN_PART,
  NVL(N1. VALOARE, 0) * DECODE(NVL(N.CURS, 0), 0, 1, NVL(N.CURS, 0))  AS VALOARE,
 (SELECT DECODE(COUNT(*), 0, 0, 1)
 FROM
   CHELTAVANS CAV,
   CHELTAVANS1 CAV1
 WHERE
   CAV.CODNC1             = N1.CODNC1
   AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
   AND CAV1.ANSTART       = PKG_GLOBALS.GETANLUCRU
   AND CAV1.LUNASTART     = PKG_GLOBALS.GETLUNALUCRU
 ) AS REZOLVAT
FROM
  NC1 N1,
  NC N
  LEFT OUTER JOIN NPART P ON P.CODPART = N.PART
WHERE
 N.CODNC = N1.CODNC
 AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(N1.CONTD))
 AND N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
 AND NVL(N.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(N.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
 AND NVL(N.SUBUNITATEA,1) IN (SELECT codsubunit FROM tmp_subunitdedicate)
 AND
 (
  (SELECT COUNT(AV1.CODCHELTAVANS1) -- POZITII DIN INTRARI1 CARE NU AU FOST INCA DESCRISE
   FROM
     CHELTAVANS AV, CHELTAVANS1 AV1
   WHERE AV.CODNC1 = N1.CODNC1 AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS) = 0
  OR
  (SELECT COUNT(AV1.CODCHELTAVANS1) -- POZITII DIN CHELTAVANS1 CARE S-AU PROPAGAT PRIN INCHIDERE DE LUNA IN LUNA DE LUCRU
   FROM
     CHELTAVANS AV, CHELTAVANS1 AV1
   WHERE
     AV.CODNC1            = N1.CODNC1
     AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS
     AND AV1.ANSTART      = PKG_GLOBALS.GETANLUCRU
     AND AV1.LUNASTART    = PKG_GLOBALS.GETLUNALUCRU
  ) &gt; 0
 )

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_NC1_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1105977F82AFED09F21C8B81AB563ACCAC3560B7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_NC1_EXT (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_CHELTAVANS_NC1 CT
  LEFT JOIN ngest ng ON ng.codgest = ct.codgest_rez
  LEFT JOIN nsubunit nsch ON nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODNC1 AS AV_CODNC1, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODNC1, 0) &lt;&gt; 0
    GROUP by CODNC1
  ) AV1_NC1
  ON AV1_NC1.AV_CODNC1 = CT.CODNC1
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_NC1.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B480FCC234C7F9F1AD622BA2160A7C4691D7108B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_TREZOR (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;) AS
SELECT
   0 AS CODINTR1,
   O.CODOBLIGPIF,
   0 AS CODNC1,
   T1.DATADOC,
   T1.AN,
   T1.LUNA,
  CASE
   WHEN O.SEMNIFICATIE = 900 THEN &apos;Direct pe cheltuieli(TVA)&apos;
                             ELSE &apos;Datorii, taxe, impozite&apos;
  END AS DENUMIRE,
  P.DEN_PART,
  NVL(O. VALOARE, 0) * DECODE(NVL(G.CURS, 0), 0, 1, NVL(G.CURS, 0)) - NVL(G.TVA, 0) AS VALOARE,
 (SELECT DECODE(COUNT(*), 0, 0, 1)
 FROM
   CHELTAVANS CAV,
   CHELTAVANS1 CAV1
 WHERE
   CAV.CODOBLIGPIF        = O.CODOBLIGPIF
   AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
   AND CAV1.ANSTART       = PKG_GLOBALS.GETANLUCRU
   AND CAV1.LUNASTART     = PKG_GLOBALS.GETLUNALUCRU
 ) AS REZOLVAT
FROM
  OBLIGPIF O,
  NPART P,
  GENERAL G,
  TREZOR1 T1,
  TREZOR T
WHERE
 O.SEMNIFICATIE IN (900, 950)
 AND O.CODGENERAL = G.CODGENERAL
 AND P.CODPART    = O.CODPART
 AND T1.CODTREZOR1 = G.CODDOC
 AND T1.CODTREZOR  = T.CODTREZOR
--AND PKG_CATEGCONST.ESTECHELTAVANS(O.ICONT) = 1
-- AND O.ICONT = PKG_GLOBALS.GETCONTCHELTAVANS
 AND EXISTS (SELECT CONTCHELTAVANS FROM TMP_CONTCHELTAVANS WHERE CONTCHELTAVANS = TO_CHAR(O.ICONT))
 AND T.OPERAT    = 1
 AND T1.ANULAT   = 0
 AND T.AN * 12 + T.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
 AND NVL(T.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(T.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
 AND EXISTS (SELECT codsubunit FROM tmp_subunitdedicate WHERE CODSUBUNIT =  NVL(T.SUBUNITATEA,1))
 AND
 (
  (SELECT COUNT(AV1.CODCHELTAVANS1) -- POZITII DIN INTRARI1 CARE NU AU FOST INCA DESCRISE
   FROM
     CHELTAVANS AV, CHELTAVANS1 AV1
   WHERE AV.CODOBLIGPIF = O.CODOBLIGPIF AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS) = 0
  OR
  (SELECT COUNT(AV1.CODCHELTAVANS1) -- POZITII DIN CHELTAVANS1 CARE S-AU PROPAGAT PRIN INCHIDERE DE LUNA IN LUNA DE LUCRU
   FROM
     CHELTAVANS AV, CHELTAVANS1 AV1
   WHERE
     AV.CODOBLIGPIF       = O.CODOBLIGPIF
     AND AV.CODCHELTAVANS = AV1.CODCHELTAVANS
     AND AV1.ANSTART      = PKG_GLOBALS.GETANLUCRU
     AND AV1.LUNASTART    = PKG_GLOBALS.GETLUNALUCRU
  ) &gt; 0
 )

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS_TREZOR_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F848A9A373013CA86677F28797CE7A5C94190B56</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS_TREZOR_EXT (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_CHELTAVANS_TREZOR CT
  LEFT JOIN ngest ng ON ng.codgest = ct.codgest_rez
  LEFT JOIN nsubunit nsch ON nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODOBLIGPIF AS AV_CODOBLIGPIF, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODOBLIGPIF, 0) &lt;&gt; 0
    GROUP by CODOBLIGPIF
  ) AV1_TREZOR
  ON AV1_TREZOR.AV_CODOBLIGPIF = CT.CODOBLIGPIF
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_TREZOR.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CLASEOP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBE6DDDF86DA44C1C01696F531FBFA64FA035661</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CLASEOP (
&quot;CODCLASEOP&quot;,&quot;DEN_CLASEOP&quot;) AS
select CodClaseOp, Den_ClaseOp
    from NCLASEOP 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CMDINTACTIVE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>31900585D40BF7FF1A9F57B6F42AAB6191079239</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CMDINTACTIVE (
&quot;CODCOMANDA1&quot;,&quot;CODCOMANDA&quot;,&quot;COMANDA&quot;,&quot;DATADOC&quot;,&quot;ZIUA&quot;,&quot;CODCOMANDACLI1&quot;,&quot;CODCOMANDACLI&quot;,&quot;CMDCLI&quot;,&quot;CLIENT&quot;,&quot;DEN_GEST&quot;,&quot;DEN_FORMATIE&quot;,&quot;SCHIMB&quot;,&quot;NIVEL&quot;,&quot;PRODUS&quot;,&quot;TERMENCMDINT&quot;,&quot;TERMENCMDCLI&quot;,&quot;CODRETETA&quot;,&quot;RETETA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;CODGEST&quot;,&quot;CANTACCEPTAT&quot;,&quot;UMSEC&quot;,&quot;TERMEN&quot;) AS
SELECT
   C1.CODCOMANDA1, C.CODCOMANDA,
   C.PREFIXDOC||C.SeriaDOC||C.NRDOC||&apos;/&apos;||C.DATADOC Comanda,
   C.DATADOC, EXTRACT( DAY FROM C.DATADOC) Ziua,
   KC1.CODCOMANDA1 CODCOMANDACLI1, KC.CODCOMANDA CODCOMANDACLI,
   KC.PREFIXDOC||KC.SeriaDOC||KC.NRDOC||&apos;/&apos;||KC.DATADOC CmdCli,
   P.DEN_PART CLIENT,
   G.DEN_GEST, F.DEN_FORMATIE, C.SCHIMB,
   C1.NIVEL, O.DENUMIRE PRODUS, C1.TERMEN TermenCmdInt, KC1.TERMEN TermenCmdCli, C1.CodReteta, R.Obs RETETA,
   C.AN,
   C.LUNA,
   C.SUBUNITATEA,
   C.CODGEST,
   C1.CantAcceptat,
   C1.UMSec,
	 C1.Termen
 FROM COMANDA C
   INNER JOIN COMANDA1 C1 ON C1.CODCOMANDA = C.CODCOMANDA
   INNER JOIN CMDPRODMAT MAT ON MAT.CODCOMANDA1 = C1.CODCOMANDA1 AND NVL(MAT.CODPRODMAT,0) = 0
   INNER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
   INNER JOIN PRODCOMP R ON R.CodProdComp = C1.CODRETETA
   LEFT JOIN NGEST G ON G.CODGEST = C.CODGEST
   LEFT JOIN FORMATII F ON F.CODFORMATIE = C.CODFORMATIE
   LEFT JOIN CMDLINK K ON K.CODCOMANDA1 = C1.CODCOMANDA1
   LEFT JOIN COMANDA1 KC1 ON KC1.CODCOMANDA1 = K.CODLINIECOMANDA
   LEFT JOIN COMANDA  KC ON KC.CODCOMANDA = KC1.CODCOMANDA
   LEFT JOIN NPART    P ON P.CODPART = KC.PARTENER
 WHERE C.TIPDOC = 53 AND C.OPERAT = 1 AND C.ANULAT = 0 AND NVL(C.INCHISA, 0) = 0 AND C1.CONSUM &lt;&gt; 0 AND MAT.REST &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CODURIFISCALE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DF858A91F5D137396C54B1F28488FF2F18DE93B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CODURIFISCALE (
&quot;COD_CODFISCAL&quot;,&quot;CODPART&quot;,&quot;CODFISCAL&quot;,&quot;PRINCIPAL&quot;) AS
SELECT &quot;COD_CODFISCAL&quot;,&quot;CODPART&quot;,&quot;CODFISCAL&quot;,&quot;PRINCIPAL&quot; 
FROM NPARTCODFISC 
WHERE 
CODPART = PKG_NOMPART.GET_PART_CURENT_CF
ORDER BY PRINCIPAL DESC 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CODURIFISCALERETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BC5F68DD5EB814B6934689B1AF17B902B871301</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CODURIFISCALERETAIL (
&quot;COD&quot;,&quot;CODPARTRETAIL&quot;,&quot;CODFISCAL&quot;,&quot;PRINCIPAL&quot;) AS
SELECT &quot;COD&quot;,&quot;CODPARTRETAIL&quot;,&quot;CODFISCAL&quot;,&quot;PRINCIPAL&quot;
FROM ncodfiscretail
WHERE
CODPARTRETAIL = PKG_NOMPART.GET_PART_CURENT_CF
ORDER BY PRINCIPAL DESC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_COMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F311ABAA39E649BB354A1430E016C555D3E58FE4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_COMENZI (
&quot;CODCOMANDA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;VALOARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;CODCONTRACT&quot;,&quot;CODCMDPARINTE&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;CANTACCEPTAT&quot;,&quot;RESTACCEPTAT&quot;,&quot;STARECOMANDA&quot;) AS
SELECT
  CMD.&quot;CODCOMANDA&quot;,CMD.&quot;TIPDOC&quot;,CMD.&quot;ANULAT&quot;,CMD.&quot;BLOCAT&quot;,CMD.&quot;OPERAT&quot;,CMD.&quot;PREFIXDOC&quot;,CMD.&quot;NRDOC&quot;,CMD.&quot;CARNETDOC&quot;,CMD.&quot;DATADOC&quot;,CMD.&quot;PARTENER&quot;,CMD.&quot;VALOARE&quot;,CMD.&quot;AN&quot;,CMD.&quot;LUNA&quot;,CMD.&quot;OBS&quot;,CMD.&quot;MONEDA&quot;,CMD.&quot;CODCONTRACT&quot;,CMD.&quot;CODCMDPARINTE&quot;,CMD.&quot;DEN_PART&quot;,CMD.&quot;SIMBOL&quot;,CMD.&quot;CANTACCEPTAT&quot;,CMD.&quot;RESTACCEPTAT&quot;,
  (
     CASE
       WHEN CMD.CANTACCEPTAT = 0 THEN &apos;NECONFIRMATA&apos;
       WHEN CMD.CANTACCEPTAT =  CMD.RESTACCEPTAT THEN &apos;NEFACTURATA&apos;
       WHEN CMD.CANTACCEPTAT &lt;&gt; 0 AND CMD.RESTACCEPTAT = 0 THEN &apos;FACTURATA INTEGRAL&apos;
       WHEN CMD.CANTACCEPTAT &gt; CMD.RESTACCEPTAT  THEN &apos;FACTURATA PARTIAL&apos;
       ELSE &apos;&apos;
     END
  ) AS STARECOMANDA
FROM
(
SELECT
 c.CODCOMANDA, c.TIPDOC, c.ANULAT, c.BLOCAT, c.OPERAT, c.PREFIXDOC, c.NRDOC,
 c.CARNETDOC, c.DATADOC, c.PARTENER, c.VALOARE, c.AN, c.LUNA,
 c.OBS, c.MONEDA, c.CODCONTRACT, c.CODCMDPARINTE, p.Den_Part,  M.SIMBOL,
 (SELECT NVL(SUM(CANTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS CANTACCEPTAT,
 (SELECT NVL(SUM(RESTACCEPTAT), 0) FROM COMANDA1 C1 WHERE C1.CODCOMANDA = C.CODCOMANDA) AS RESTACCEPTAT
FROM
  COMANDA c
  LEFT OUTER JOIN NPART P ON P.CODPART = C.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
WHERE
C.TIPDOC = PKG_GLOBALS.GETTIPCOMANDA AND
NVL(C.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE,1,NVL(C.SUBUNITATEA,1),PKG_GLOBALS.GETSUBUNITATE) AND
C.AN * 12 + C.LUNA = PKG_GLOBALS.ANLUNALUCRU
) CMD 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_COMENZI_CLIENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8A3A79731EBAEF02AF097BCD53F917807917FA8B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_COMENZI_CLIENTI (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;NIVEL&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANTACCEPTAT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;) AS
SELECT
  C.PREFIXDOC,
  C.NRDOC,
  0 Nivel,
  C.DATADOC,
  C1.CODCOMANDA1 AS CODLINIESTINSA,
  C1.PU AS PRET,
  C1.CODOBIECT,
  C1.CANTACCEPTAT,
  C1.RESTACCEPTAT AS REST,
  C1.RESTACCEPTAT AS RESTINITIAL,
  0 AS PRELUAT,
  C1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;,&apos;1&apos;,&apos;S&apos;) AS TIPLINIE,
  C1.TERMEN AS TERMEN,
  A.CONTSERVICIU,
  C.MONEDA AS MONEDAAVIZ,
  0 AS CURSAVIZ,
  0 AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  C1.ADDIM,
  C1.PROCDISC,
  C.CODLOCATIE,
  U1.PARITATE,
  C.AGENT,
  P.NUME || &apos; &apos; || P.PRENUME AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  0 AS MIFIX,
  A.ARETG,
  A.CERTIFICAT,
  C.OBS AS OBSDOC,
  C1.OBS AS OBSARTICOL,
  C1.SCADENTA AS ZILEPLATA,
  (SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  0 AS GARANTIE,
  C.CODCOMANDA AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART
FROM
  COMANDA1 C1
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1 = C1.UMSEC
  LEFT OUTER JOIN NPERS P ON P.CODPERS = C.AGENT
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
WHERE
  C.TIPDOC = 18
  AND NVL(C.INCHISA, 0) = 0
  AND C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
  AND PKG_COMANDA.CONDITIE_PART_COMANDA(C.PARTENER) = 1
  AND C.OPERAT = 1 AND C.ANULAT = 0
  AND nvl(C.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE)
  AND ((C1.RESTACCEPTAT &lt;&gt; 0)OR(C1.RESTACCEPTAT = 0)
  AND (C1.CODCOMANDA1 IN( SELECT CODLINIECOMANDA FROM TMP_IESLINK_INITIAL)))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_COMENZI_FURNIZORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>873CE1DFF59264437DB073FEA8DCAEECFB130C72</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_COMENZI_FURNIZORI (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODLINIESTINSA&quot;,&quot;PRET&quot;,&quot;CODOBIECT&quot;,&quot;CANTACCEPTAT&quot;,&quot;REST&quot;,&quot;RESTINITIAL&quot;,&quot;PRELUAT&quot;,&quot;UMSEC&quot;,&quot;DENUM&quot;,&quot;PROCTVA&quot;,&quot;TIPLINIE&quot;,&quot;TERMEN&quot;,&quot;CONTSERVICIU&quot;,&quot;MONEDAAVIZ&quot;,&quot;CURSAVIZ&quot;,&quot;TVAAVIZ&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;GESTIMPLICITA&quot;,&quot;ADDIM&quot;,&quot;PROCDISC&quot;,&quot;CODLOCATIE&quot;,&quot;PARITATE&quot;,&quot;AGENT&quot;,&quot;DENAGENT&quot;,&quot;SIMBOL&quot;,&quot;DENOBIECT&quot;,&quot;ECHIVALENTA&quot;,&quot;CANTECHIVALATA&quot;,&quot;MIFIX&quot;,&quot;ARETG&quot;,&quot;CERTIFICAT&quot;,&quot;OBSDOC&quot;,&quot;OBSARTICOL&quot;,&quot;ZILEPLATA&quot;,&quot;DENUMPRINCIPALA&quot;,&quot;GARANTIE&quot;,&quot;CODDOC&quot;,&quot;PRELDINSTOC&quot;,&quot;ZILEART&quot;) AS
SELECT
  C.PREFIXDOC,
  C.NRDOC,
  C.DATADOC,
  C1.CODCOMANDA1 AS CODLINIESTINSA,
  C1.PU AS PRET,
  C1.CODOBIECT,
  C1.CANTACCEPTAT,
  C1.RESTACCEPTAT AS REST,
  C1.RESTACCEPTAT AS RESTINITIAL,
  0 AS PRELUAT,
  C1.UMSEC,
  U1.DEN_UM1 AS DENUM,
  PKG_SELECTARTICOLE.GETPROCTVALUNALUCRU(A.CODARTICOL) AS PROCTVA,
  DECODE(NVL(A.TIPARTICOL,&apos;0&apos;), &apos;0&apos;, &apos;=&apos;,&apos;1&apos;,&apos;S&apos;) AS TIPLINIE,
  C1.TERMEN AS TERMEN,
  A.CONTSERVICIU,
  C.MONEDA AS MONEDAAVIZ,
  0 AS CURSAVIZ,
  0 AS TVAAVIZ,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.GESTIMPLICITA,
  C1.ADDIM,
  C1.PROCDISC,
  C.CODLOCATIE,
  U1.PARITATE,
  C.AGENT,
  P.NUME || &apos; &apos; || P.PRENUME AS DENAGENT,
  M.SIMBOL,
  O.DENUMIRE AS DENOBIECT,
  0 AS ECHIVALENTA,
  0 AS CANTECHIVALATA,
  0 AS MIFIX,
  A.ARETG,
  A.CERTIFICAT,
  C.OBS AS OBSDOC,
  C1.OBS AS OBSARTICOL,
  0 AS ZILEPLATA,
  (SELECT DEN_UM FROM NUM WHERE CODUM = A.UM) AS DENUMPRINCIPALA,
  0 AS GARANTIE,
  C.CODCOMANDA AS CODDOC,
  0 AS PRELDINSTOC,
  O.TERMENPLATA AS ZILEART
FROM
  COMANDA1 C1
  LEFT OUTER JOIN NARTOBJ O ON O.CODOBIECT = C1.CODOBIECT
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN COMANDA C ON C.CODCOMANDA = C1.CODCOMANDA
  LEFT OUTER JOIN NUM1 U1 ON U1.CODUM1 = C1.UMSEC
  LEFT OUTER JOIN NPERS P ON P.CODPERS = C.AGENT
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = NVL(C.MONEDA, 0)
WHERE
  C.TIPDOC = 8
  AND NVL(C.INCHISA, 0) = 0
  AND C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
  AND nvl(C.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1, nvl(c.subunitatea,1), pkg_globals.GETSUBUNITATE)
  AND PKG_COMANDA.CONDITIE_PART_COMANDA(C.PARTENER) = 1
  AND C.OPERAT = 1 AND C.ANULAT = 0
  AND ((C1.RESTACCEPTAT &lt;&gt; 0)OR(C1.RESTACCEPTAT = 0)
  AND (C1.CODCOMANDA1 IN( SELECT CODLINIECOMANDA FROM TMP_INTRLINK_INITIAL)))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DD1F9D7EAD712F9B1343670E4CBA66A9FE47E38</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_COMPENS (
&quot;CODCOMPENS&quot;,&quot;DATADOC&quot;,&quot;NRDOC&quot;,&quot;OBSD&quot;,&quot;OBSC&quot;,&quot;TIPCOMPENS&quot;,&quot;PARTDEBIT&quot;,&quot;PARTCREDIT&quot;) AS
SELECT
  C.CODCOMPENS, C.DATADOC, C.NRDOC, C.OBSD, C.OBSC, C.Tipcompens,
  PD.DEN_PART AS PARTDEBIT, PC.DEN_PART AS PARTCREDIT
FROM
  COMPENS C
  LEFT OUTER JOIN NPART PD ON PD.CODPART = C.PARTD
  LEFT OUTER JOIN NPART PC ON PC.CODPART = C.PARTC
WHERE
nvl(C.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
AN * 12 + LUNA = PKG_GLOBALS.AnLunaLucru 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONST_GRAMADA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C3B904C399B66586D12D673150FCD514379E90E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONST_GRAMADA (
&quot;CODCATEG&quot;,&quot;CODCONST1&quot;,&quot;DENUMIRE&quot;,&quot;SIMBOL&quot;,&quot;INDEXLOCAL&quot;,&quot;SECTIUNE&quot;,&quot;UTILIZATOR&quot;,&quot;TIP&quot;,&quot;TIPCATEG&quot;,&quot;USERID&quot;,&quot;VALOARE&quot;,&quot;GRAMADA&quot;) AS
SELECT DISTINCT
  codcateg,codconst1,denumire,simbol,indexlocal,sectiune,
  CASE tipcateg WHEN &apos;G&apos; THEN &apos;General&apos; WHEN &apos;U&apos; THEN getUserName(userid) ELSE &apos;..&apos; END Utilizator, tip, tipcateg, userid,
  pkg_categconst.GetValAfis(Tip, CodConstLuna) valoare, 1 gramada
FROM (
  SELECT
    Row_Number() OVER (PARTITION BY c1.codconst1 ORDER BY cL.anstart*12+cL.lunastart DESC) RNum,
    c.codcateg,c1.codconst1,c1.denumire,c1.simbol,c1.indexlocal,c.denumire sectiune, c1.tip, C.tipcateg,
    cL.userid, cL.CodConstLuna
  FROM categconst c
    INNER JOIN const1 c1    ON c1.codcateg  = c.codcateg
    LEFT  JOIN constluna cL ON cL.codconst1 = c1.codconst1
  WHERE Coalesce((cL.anstart*12+cL.lunastart) ,0) &lt;= Coalesce(pkg_globals.GetANLUCRU*12+pkg_globals.getLunaLucru,0)
    AND c1.tip &lt;&gt; 0
    AND Coalesce(cL.userid, 0) = CASE WHEN c.tipcateg = &apos;G&apos; THEN 0 ELSE pkg_globals.GETUSERID END
)
WHERE RNum = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTACTPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93B13934B458C1D3B4A141B828744F1EFE6B6749</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTACTPART (
&quot;CODPART&quot;,&quot;CODPERSC&quot;,&quot;NUME&quot;,&quot;PRENUME&quot;,&quot;TELEFON&quot;,&quot;EMAIL&quot;,&quot;FUNCTIE&quot;) AS
SELECT CODPART, CODPERSC, NUME, PRENUME, TELEFON, EMAIL, FUNCTIE
FROM NPERSCONTACT
WHERE TIP = 1 AND CODPART = PKG_NOMPART.GET_PART_CURENT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTRACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7067F67714183974D8A64FD1A12EFF2679E6A3DB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTRACT (
&quot;CODCONTRACT&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;ACTIV&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;CODPERSC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DEN_PART&quot;,&quot;EXPLICATII&quot;,&quot;DEN_MONEDA&quot;,&quot;DEN_LOCALIT&quot;,&quot;SUBUNITATEDOC&quot;,&quot;PERSC&quot;) AS
SELECT
  C.CODCONTRACT, C.TIPDOC, C.ANULAT, C.BLOCAT, C.OPERAT, C.ACTIV, C.NRDOC, C.DATADOC, C.DATASTART, C.DATASTOP, C.PARTENER,
  C.CODLOCATIE, C.CODFISCAL, C.CODPERSC, C.AN, C.LUNA, C.OBS, C.MONEDA, C.SUBUNITATEA, C.USERID, C.DATACREARE, 
  P.Den_Part, C.EXPLICATII, M.Den_Moneda, L.Den_Localit, S.DEN_SUBUNIT SUBUNITATEDOC, PC.NUME ||&apos; &apos;||PC.PRENUME PersC
FROM
  CONTRACT C
  LEFT JOIN NPART        P  ON P.Codpart    = NVL(C.Partener, 0)
  LEFT JOIN NAGENDA      A  ON A.Codagenda  = NVL(C.CodLocatie, 0)
  LEFT JOIN NLOCALIT     L  ON L.Codlocalit = NVL(A.CodLocalit, 0)
  LEFT JOIN NMONEDE      M  ON M.CodMoneda  = NVL(C.Moneda, 0)
  LEFT JOIN NPERSCONTACT PC ON PC.CODPERSC  = C.CODPERSC
  LEFT JOIN NSUBUNIT     S  ON S.CODSUBUNIT = C.SUBUNITATEA
WHERE C.TipDoc = PKG_GLOBALS.GETTIPCONTRACT
AND NVL(C.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE,1,NVL(C.SUBUNITATEA,1),PKG_GLOBALS.GETSUBUNITATE)
AND (C.AN * 12 + C.LUNA) &lt;= PKG_GLOBALS.ANLUNALUCRU</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTRACT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8B8A9ADBB6EE70F4580442B8D70E70CDDBC0D498</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTRACT1 (
&quot;CODCONTRACT1&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;) AS
SELECT &quot;CODCONTRACT1&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot; from
(SELECT
  C1.CODCONTRACT1, &apos;C&apos;||C.SERIADOC||C.NRDOC||&apos;.&apos;|| C1.Indexlocal||&apos;-&apos;||C1.Anexa as NrDoc, Nvl(C1.Datastart, C.DataStart) DataStart, Nvl(C1.DataStop,C.DataStop) DataStop
FROM
  CONTRACT1 C1,
  CONTRACT C
WHERE C1.CODCONTRACT = C.CODCONTRACT)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTURI_BANCARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>243ACD462B70D2BDD219F4AE9542F9CC2E297A88</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTURI_BANCARE (
&quot;CODBANKCONT&quot;,&quot;NRCONT&quot;,&quot;DEN_CONT&quot;,&quot;SIMBOLBANCA&quot;,&quot;CODMONEDA&quot;,&quot;SIMBMONEDA&quot;) AS
SELECT
  BC.CODBANKCONT, BC.NRCONT, BC.DEN_CONT, B.SIMBOL as SIMBOLBANCA, BC.CODMONEDA,  M.SIMBOL AS SIMBMONEDA
FROM
  NBANKCONT BC
  LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK
  LEFT OUTER JOIN NMONEDE  M ON M.CODMONEDA = BC.CODMONEDA
WHERE
BC.CODBANK &lt;&gt; 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTURI_BANKA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>73B9E5F2E7215B3457F5C00B2B75AD4BBA861962</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTURI_BANKA (
&quot;CODBANKCONT&quot;,&quot;NRCONT&quot;,&quot;DEN_CONT&quot;,&quot;FILIALA&quot;,&quot;CODMONEDA&quot;,&quot;SIMBMONEDA&quot;,&quot;CURSREG&quot;) AS
SELECT BC.CODBANKCONT, BC.NRCONT, BC.DEN_CONT, BC.FILIALA,  BC.CODMONEDA,  M.SIMBOL AS SIMBMONEDA, REG.CURS AS CURSREG
FROM NBANKCONT BC
  LEFT JOIN NMONEDE  M ON M.CODMONEDA = BC.CODMONEDA
  LEFT JOIN TMP_CURS_BANKCONT_LUNA REG ON REG.CODBANKCONT = BC.CODBANKCONT
WHERE BC.CODBANK = PKG_CONTURIBANCI.GETBANCACURENTA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONTURI_VIRAMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B939AEC025A5EB551691EE32268DC193DD5F6FD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONTURI_VIRAMENT (
&quot;CODBANKCONT&quot;,&quot;NRCONT&quot;,&quot;DEN_CONT&quot;,&quot;SIMBOLBANCA&quot;,&quot;CODMONEDA&quot;,&quot;SIMBMONEDA&quot;) AS
SELECT 
  BC.CODBANKCONT, BC.NRCONT, BC.DEN_CONT, B.SIMBOL as SIMBOLBANCA, BC.CODMONEDA,  M.SIMBOL AS SIMBMONEDA
FROM 
  NBANKCONT BC
  LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK
  LEFT OUTER JOIN NMONEDE  M ON M.CODMONEDA = BC.CODMONEDA
WHERE 
 BC.CODBANKCONT &lt;&gt;  PKG_CONTURIBANCI.GETCONT_SURSA_VIRAMENT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_IN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0798435CDFF4B3E0EE6C5A4FD46046E193B9E9AD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_IN (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS,
       ICONTPERS AS ICONT,
       MONEDA_IN AS CODMONEDA,
       NVL(-SUM(SOLDLEI), 0) AS SOLDLEI,
       NVL(-SUM(SOLDVALUTA_IN), 0) AS SOLDVALUTA
FROM
 CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP  AND LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
 CODPERS, ICONTPERS, MONEDA_IN 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_IN_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7FFBDA8E172B420141D0B2DDB5558AEC8DBC58AD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_IN_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS,
       ICONTPERS AS ICONT,
       MONEDA_IN AS CODMONEDA,
       SUBUNITATEA,
       NVL(-SUM(SOLDLEI), 0) AS SOLDLEI,
       NVL(-SUM(SOLDVALUTA_IN), 0) AS SOLDVALUTA
FROM
 CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP  AND LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
 CODPERS, ICONTPERS, MONEDA_IN, SUBUNITATEA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_LUNA_IN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5EA46AF92D3EFF049ACA31AC7F93DDEC307D18E0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_LUNA_IN (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS,
       ICONTPERS AS ICONT,
       MONEDA_IN AS CODMONEDA,
       NVL(-SUM(SOLDLEI), 0) AS SOLDLEI,
       NVL(-SUM(SOLDVALUTA_IN), 0) AS SOLDVALUTA
FROM
 CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP  AND LUNA = PKG_GLOBALS.GETLUNATEMP
  AND CODPERS = PKG_NOMPERS.GET_PERSOANA_CURENTA
  AND ICONTPERS = PKG_NOMPERS.GET_ICONTPERS_CURENT
  AND MONEDA_IN = PKG_NOMPERS.GET_MONEDAPERS_CURENT
GROUP BY
 CODPERS, ICONTPERS, MONEDA_IN 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_LUNA_OUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A15D2A86CC0F492988DBE0725C69810BEDA4E16</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_LUNA_OUT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
  CODPERS,
  ICONTPERS AS ICONT,
  MONEDA_OUT AS CODMONEDA,
  NVL(SUM(SOLDLEI), 0) AS SOLDLEI,
  NVL(SUM(SOLDVALUTA_OUT), 0) AS SOLDVALUTA
FROM
  CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP
  AND LUNA = PKG_GLOBALS.GETLUNATEMP
  AND CODPERS = PKG_NOMPERS.GET_PERSOANA_CURENTA
  AND ICONTPERS = PKG_NOMPERS.GET_ICONTPERS_CURENT
  AND MONEDA_OUT = PKG_NOMPERS.GET_MONEDAPERS_CURENT
GROUP BY
   CODPERS,
   ICONTPERS,
   MONEDA_OUT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_OUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCCD8BFB52222AD589B9710AF0BCE2DE6A86433C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_OUT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
  CODPERS,
  ICONTPERS AS ICONT,
  MONEDA_OUT AS CODMONEDA,
  NVL(SUM(SOLDLEI), 0) AS SOLDLEI,
  NVL(SUM(SOLDVALUTA_OUT), 0) AS SOLDVALUTA
FROM
  CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP  AND LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
   CODPERS,
   ICONTPERS,
   MONEDA_OUT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CONVERT_SOLDPERS_OUT_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>999188C7B68D3BB0D15260EBE2D13E410077F481</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CONVERT_SOLDPERS_OUT_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
  CODPERS,
  ICONTPERS AS ICONT,
  MONEDA_OUT AS CODMONEDA,
  SUBUNITATEA,
  NVL(SUM(SOLDLEI), 0) AS SOLDLEI,
  NVL(SUM(SOLDVALUTA_OUT), 0) AS SOLDVALUTA
FROM
  CONVERTCURSPERS
WHERE
  AN = PKG_GLOBALS.GETANTEMP  AND LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
   CODPERS,
   ICONTPERS,
   MONEDA_OUT,
   SUBUNITATEA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CRITERII1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>888D74C4609839117D0D09EA8817E2CFAC5DB3B8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CRITERII1 (
&quot;CODCRITERIU&quot;,&quot;DATASTART&quot;,&quot;DATAEND&quot;,&quot;CODCRITERIU1&quot;,&quot;SUBUNITATEA&quot;) AS
SELECT CODCRITERIU, DATASTART, DATAEND, CODCRITERIU1, SUBUNITATEA
FROM
(
  SELECT C1.CODCRITERIU, C1.DATASTART, C1.CODCRITERIU1, C1.SUBUNITATEA,
        NVL(
        (SELECT MIN(CC1.DATASTART - 1)
         FROM CRITERIIDISC1 CC1
         WHERE CC1.CODCRITERIU = C1.CODCRITERIU AND CC1.SUBUNITATEA = C1.SUBUNITATEA
               AND CC1.DATASTART &gt; C1.DATASTART
        ), LAST_DAY(TO_DATE(&apos;01.&apos;||LPAD(TO_CHAR(PKG_GLOBALS.GETLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||TO_CHAR(PKG_GLOBALS.GETANLUCRU),&apos;DD.MM.YYYY&apos;))
        )  DATAEND
  FROM CRITERIIDISC1 C1
  WHERE C1.DATASTART &lt;= LAST_DAY(TO_DATE(&apos;01.&apos;||LPAD(TO_CHAR(PKG_GLOBALS.GETLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||TO_CHAR(PKG_GLOBALS.GETANLUCRU),&apos;DD.MM.YYYY&apos;))
)
WHERE EXTRACT(YEAR FROM DATAEND) = PKG_GLOBALS.GETANLUCRU AND EXTRACT(MONTH FROM DATAEND) = PKG_GLOBALS.GETLUNALUCRU
      AND (PKG_GLOBALS.GETSUBUNITATE = SUBUNITATEA OR PKG_GLOBALS.GETSUBUNITATE = 1)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CRITERIIDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC486F37793A4AC86ED06AC44005F720B6179409</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CRITERIIDISC (
&quot;CODCRITERIU&quot;,&quot;DENCRITERIU&quot;,&quot;OFFINVOICE&quot;,&quot;PUNCTE&quot;,&quot;TIPDISC&quot;) AS
SELECT
  CODCRITERIU,
  DENCRITERIU,
  OFFINVOICE,
  NVL(PUNCTE, 0) AS PUNCTE,
  CASE
    WHEN NVL(PUNCTE, 0) = 1 THEN &apos;Puncte&apos;
    ELSE &apos;Discount&apos;
  END AS TIPDISC
FROM CRITERIIDISC
WHERE
CODCRITERIU &gt; 20
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DATABORD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD6B4D83F129EC7CB9BAC35E5ECE9241EDE99244</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DATABORD (
&quot;CODNPARCAUT&quot;,&quot;CODNPARC0&quot;) AS
select P0.CODNPARCAUT, Max(CodNParc0) CodNParc0
  from nparc0 p0,
       (SELECT CODNPARCAUT, Max(DATABORD) DATABORD from nparc0 group by CODNPARCAUT) X
 where x.codnparcaut = p0.codnparcaut
   and x.DataBord = p0.DataBord
 group by P0.Codnparcaut
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DECODE_DESCRIPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>02AD050CB97AE650633EA503EDD53F1C711751AE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DECODE_DESCRIPT (
&quot;CODDESCRIPTOR&quot;,&quot;DEN_DESCRIPTOR&quot;,&quot;CODANALIZA&quot;,&quot;INDEXLOCAL&quot;) AS
SELECT D.CODDESCRIPTOR, D.DEN_DESCRIPTOR, A1.CODANALIZA, A1.INDEXLOCAL
 FROM ANALIZA1 A1 INNER JOIN DESCRIPTORI D ON A1.CODDESCRIPTOR = D.CODDESCRIPTOR
 ORDER BY A1.INDEXLOCAL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DENANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BBD9199A38033232F6ADE8CA90D192239F38C73</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DENANALIZA (
&quot;CODANALIZANOD&quot;,&quot;DENUMIRE&quot;,&quot;SIMBOL&quot;) AS
WITH /*recursive*/ recA(CODANALIZANOD, NIVEL, DENUMIRE, SIMBOL) AS (
  SELECT
    AN.CODANALIZANOD, 0 AS NIVEL,
		CASE
      WHEN aa.Tip = 1 THEN AN.SimbolNod||&apos;=&apos;||AN.DenNod
      ELSE D1.VALOARE
    END DENUMIRE,
    CASE
      WHEN aa.Tip = 1 THEN AN.SimbolNod
      ELSE LPAD(AN.POZITIE, 2, &apos;0&apos;)
    END SIMBOL
  FROM AnalizaNod AN
    LEFT JOIN Analiza aa ON aa.CodAnaliza = an.CodAnaliza
    LEFT JOIN DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
  WHERE AN.NODPARINTE = 0
  UNION ALL
  SELECT
    AN.CODANALIZANOD, recA.NIVEL + 1 NIVEL,
		CASE
      WHEN aa.Tip = 1 THEN AN.SimbolNod||&apos;=&apos;||AN.DenNod
      ELSE D1.VALOARE
    END DENUMIRE,
    CASE
      WHEN aa.Tip = 1 THEN AN.SimbolNod 
      WHEN recA.NIVEL = 0 THEN LPAD(AN.POZITIE, 2,&apos;0&apos;) 
      ELSE recA.SIMBOL||&apos;.&apos;||LPAD(AN.POZITIE, 2,&apos;0&apos;) END SIMBOL
  FROM recA
    INNER JOIN AnalizaNod AN ON An.NODPARINTE = recA.CODANALIZANOD
    LEFT JOIN Analiza aa ON aa.CodAnaliza = an.CodAnaliza
    LEFT JOIN DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
)
SELECT CodAnalizaNod, Denumire, Simbol
FROM recA V</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DESCRIPTORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>653586D7F04007F011C2DB49F776F0734D44B3EE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DESCRIPTORI (
&quot;CODDESCRIPTOR&quot;,&quot;DEN_DESCRIPTOR&quot;,&quot;SIMBOL&quot;,&quot;TIP&quot;) AS
select d.coddescriptor,d.den_descriptor, d.simbol,
        decode(d.tip,0 ,&apos;Diverse&apos;,
                     80 ,&apos;Tari&apos;,
                     81 ,&apos;Judete&apos;,
                     82 ,&apos;Orase&apos;,
                     85 ,&apos;Activitati&apos;,
                     70 ,&apos;Subunitati&apos;,
                     86 ,&apos;Gestiuni&apos;,
                     87 ,&apos;Centre cost&apos;,
                     90 ,&apos;Formatii&apos;,
                     100 ,&apos;Clase articole&apos;,
                     22 ,&apos;Articole&apos;,
                     75 ,&apos;Parc auto&apos;,
                     2 ,&apos;Conturi&apos;,
                     60 ,&apos;Parteneri&apos;,
                     50 ,&apos;Personal&apos;,
                     11 ,&apos;Monede&apos;,
                     101 ,&apos;Utilaje&apos;,
                     &apos;...nedefinit...&apos;
               ) tip
  from descriptori d
/*
         0 ,&apos;Diverse&apos;,
         80 ,&apos;Tari&apos;,
         81 ,&apos;Judete&apos;,
         82 ,&apos;Orase&apos;,
         85 ,&apos;Activitati&apos;,
         70 ,&apos;Subunitati&apos;,
         86 ,&apos;Gestiuni&apos;,
         87 ,&apos;Centre cost&apos;,
         90 ,&apos;Formatii&apos;,
         100 ,&apos;Clase articole&apos;,
         22 ,&apos;Articole&apos;,
         75 ,&apos;Parc auto&apos;,
         2 ,&apos;Conturi&apos;,
         60 ,&apos;Parteneri&apos;,
         50 ,&apos;Personal&apos;,
         11 ,&apos;Monede&apos;
*/</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DESCRIPTORI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0F5BC261DFD1ABF96FED28FDB56AE22FA9CC68C9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DESCRIPTORI1 (
&quot;CODDESCRIPTOR1&quot;,&quot;CODDESCRIPTOR&quot;,&quot;VALOARE&quot;,&quot;CODASOCIAT&quot;,&quot;TIP&quot;,&quot;DENASOCIAT&quot;,&quot;DEN_DESCRIPTOR&quot;,&quot;SIMBOL&quot;) AS
SELECT D1.CODDESCRIPTOR1, D1.CODDESCRIPTOR, D1.VALOARE, D1.CODASOCIAT, D.Tip, PKG_DESCRIPTORI.GetDenAsociat(D.Tip, D1.CODASOCIAT) DENASOCIAT, D.DEN_DESCRIPTOR, D.Simbol
FROM DESCRIPTORI D
  LEFT JOIN DESCRIPTORI1 D1 ON D1.CODDESCRIPTOR = D.CODDESCRIPTOR

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DESTINATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C979553F02226ADC3EBFC3470F844EB478941C6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DESTINATII (
&quot;CODDESTINATIE&quot;,&quot;NUMEDESTINATIE&quot;,&quot;PENTRU&quot;,&quot;SEZON&quot;,&quot;ARTICOL&quot;,&quot;ACTIVITATE&quot;) AS
SELECT
  codDestinatie,
  numedestinatie,
  case
     WHEN PENTRU = 0 THEN &apos;Femei&apos;
     WHEN PENTRU = 1 THEN &apos;Barbati&apos;
  end PENTRU,
  case
     WHEN SEZON = 0 THEN &apos;Cald&apos;
     WHEN SEZON = 1 THEN &apos;Rece&apos;
  end SEZON,
  case
     WHEN ARTICOL = 0 THEN &apos;Bluza&apos;
     WHEN ARTICOL = 1 THEN &apos;Camasa&apos;
     WHEN ARTICOL = 2 THEN &apos;Fusta&apos;
     WHEN ARTICOL = 3 THEN &apos;Geaca&apos;
     WHEN ARTICOL = 4 THEN &apos;Palton&apos;
     WHEN ARTICOL = 5 THEN &apos;Pantalon&apos;
     WHEN ARTICOL = 6 THEN &apos;Pardesiu&apos;
     WHEN ARTICOL = 7 THEN &apos;Pijama&apos;
     WHEN ARTICOL = 8 THEN &apos;Rochie&apos;
  end ARTICOL,
  case
     WHEN ACTIVITATE = 0 THEN &apos;Casual&apos;
     WHEN ACTIVITATE = 1 THEN &apos;Casual office&apos;
     WHEN ACTIVITATE = 2 THEN &apos;Clasic&apos;
     WHEN ACTIVITATE = 3 THEN &apos;Odihna&apos;
     WHEN ACTIVITATE = 4 THEN &apos;Sport&apos;
  end ACTIVITATE
FROM DESTINATII
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DIMINUARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC84B48FD72C1C6406F4386AF328721009E31F22</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DIMINUARI (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;) AS
SELECT
   i.CodIes, i.TipDoc, i.Anulat, i.Blocat, i.Operat, i.PrefixDoc, i.CarnetDoc,
   i.NrDoc, i.DataDoc, i.Partener, i.CarnetAE, i.NrAE, i.ValDoc, i.TVADoc,
   0 AS MONEDA, 1 AS Curs, i.Accize, i.Delegat, i.Agent, i.Majorari,
   i.Obs, i.An, i.Luna
FROM
  IESIRI i
WHERE
i.tipdoc = PKG_GLOBALS.GetTipIesire AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
i.An * 12 + i.Luna = PKG_GLOBALS.AnLunaLucru 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISCART_CLS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3C08B4D322C9B16A4E2BCE3B678C60E7079F309</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISCART_CLS (
&quot;CODOBIECT&quot;,&quot;CODDISCOUNT&quot;,&quot;LIMINF&quot;,&quot;LIMSUP&quot;,&quot;PROCENT&quot;,&quot;GRUPA&quot;,&quot;CLASA&quot;) AS
SELECT OCLS.CODOBIECT, DA.CODDISCOUNT, DI.LIMINF, DI.LIMSUP, DI.PROCENT,
       COALESCE(TMPS.GRUPA,&apos;...NEDEFINIT...&apos;) GRUPA, CLSS.DEN_CLASEA CLASA
FROM DISCART DA,
     NCLASEA CLSS,
     NART ARTCLS,
     NARTOBJ OCLS,
     NARTOBJ1 TMPS,
     DISCINTERVAL DI
WHERE DI.CODDISCOUNT = DA.CODDISCOUNT AND CLSS.CODCLASEA = NVL(DA.CODCLASA,0)
      AND COALESCE(DA.CODCLASA,0) &gt; 0 AND ARTCLS.CLASA = DA.CODCLASA AND OCLS.CODARTICOL = ARTCLS.CODARTICOL
      AND TMPS.CODOBIECT = OCLS.CODOBIECT AND TMPS.ANSTART*12+TMPS.LUNASTART = (SELECT MAX(T2.ANSTART*12+T2.LUNASTART) FROM NARTOBJ1 T2 WHERE T2.CODOBIECT = TMPS.CODOBIECT
      AND T2.ANSTART*12+T2.LUNASTART &lt;= PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISCART_GRUPA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2A4595646BF02D8B49337D5C995F249498E46C6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISCART_GRUPA (
&quot;CODOBIECT&quot;,&quot;CODDISCOUNT&quot;,&quot;LIMINF&quot;,&quot;LIMSUP&quot;,&quot;PROCENT&quot;,&quot;GRUPA&quot;,&quot;CLASA&quot;) AS
SELECT OG.CODOBIECT, DA.CODDISCOUNT, DI.LIMINF, DI.LIMSUP, DI.PROCENT,
       TMPG.GRUPA, COALESCE(CLSG.DEN_CLASEA,&apos;...NEDEFINIT...&apos;) CLASA
FROM DISCART DA,
     NARTOBJ1 TMPG,
     NARTOBJ OG,
     NART ARTG
     LEFT JOIN NCLASEA CLSG ON CLSG.CODCLASEA = ARTG.CLASA,
     DISCINTERVAL DI
WHERE DI.CODDISCOUNT = DA.CODDISCOUNT AND TMPG.GRUPA = DA.GRUPA AND LENGTH(COALESCE(DA.GRUPA,&apos;&apos;)) &gt; 0
      AND OG.CODOBIECT = TMPG.CODOBIECT AND ARTG.CODARTICOL = OG.CODARTICOL
      AND TMPG.ANSTART*12+TMPG.LUNASTART =
      (SELECT MAX(T2.ANSTART*12+T2.LUNASTART) FROM NARTOBJ1 T2 WHERE T2.CODOBIECT = TMPG.CODOBIECT
       AND T2.ANSTART*12+T2.LUNASTART &lt;= PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISCART_OBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0FF5E80239BA90688BA28D9277B24B5A9DD95118</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISCART_OBJ (
&quot;CODOBIECT&quot;,&quot;CODDISCOUNT&quot;,&quot;LIMINF&quot;,&quot;LIMSUP&quot;,&quot;PROCENT&quot;,&quot;GRUPA&quot;,&quot;CLASA&quot;) AS
SELECT
  O.CODOBIECT, DA.CODDISCOUNT, DI.LIMINF, DI.LIMSUP, DI.PROCENT, TMP.GRUPA, COALESCE(CLSA.DEN_CLASEA,&apos;...NEDEFINIT...&apos;) CLASA
FROM DISCART DA,
     NARTOBJ O,
     NART ART
     LEFT JOIN NCLASEA CLSA ON CLSA.CODCLASEA = ART.CLASA,
     NARTOBJ1 TMP,
     DISCINTERVAL DI
WHERE DI.CODDISCOUNT = DA.CODDISCOUNT AND DA.CODOBIECT = O.CODOBIECT AND COALESCE(DA.CODOBIECT,0) &gt; 0
      AND ART.CODARTICOL = O.CODARTICOL AND TMP.CODOBIECT = O.CODOBIECT
      AND TMP.ANSTART*12+TMP.LUNASTART = (SELECT MAX(T2.ANSTART*12+T2.LUNASTART) FROM NARTOBJ1 T2 WHERE T2.CODOBIECT = TMP.CODOBIECT
                                          AND T2.ANSTART*12+T2.LUNASTART &lt;= PKG_GLOBALS.GetANLUCRU*12+PKG_GLOBALS.GetLUNALUCRU)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISC_OFF_INVOICE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BE35E94522957CCBACFDCF73E164658C1BC7A1B6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISC_OFF_INVOICE (
&quot;CODPART&quot;,&quot;CODCATEGDISC&quot;,&quot;CODDISCOUNT&quot;,&quot;CODTIPSEDIU&quot;,&quot;OFFINVOICE&quot;,&quot;PROCENT&quot;) AS
with CRValide as (select CL.CODCRITERIU1, CL.CODCRITERIU from criteriidisc1 CL
where   extract(Year from cl.DATASTART) * 12 + extract(Month from cl.DATASTART) =
        (SELECT MAX(extract(Year from cl1.DATASTART) * 12 + extract(Month from cl1.DATASTART))
         FROM criteriidisc1 CL1
         WHERE
            CL1.Subunitatea = PKG_GLOBALS.GETSUBUNITATE_DOC
            AND
            CL1.CODCRITERIU1 = CL.CODCRITERIU1 AND
            extract(Year from cl1.DATASTART) * 12 + extract(Month from cl1.DATASTART) &lt;= pkg_globals.AnLunaLucru))
SELECT PD.CodPart, PD.CODCATEGDISC, D.CODDISCOUNT, NVL(D.CodTipSediu, 0) CodTipSediu, C.Offinvoice, Di.PROCENT
FROM   NPARTDISC PD
       inner join CRValide CR on CR.CODCRITERIU = PD.CODCATEGDISC
       inner join criteriidisc C on C.CODCRITERIU = CR.CODCRITERIU
       inner join Discount D on D.CODCRITERIU1 = CR.CODCRITERIU1
       inner join discinterval Di on Di.CODDISCOUNT = D.CODDISCOUNT
       WHERE C.Offinvoice &gt; 0

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISTANTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B7E61BAEF6D7FC71B26D69D456772F909F4EFFAF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISTANTA (
&quot;CODDISTANTA&quot;,&quot;CODGESTSTART&quot;,&quot;DENGESTSTART&quot;,&quot;CODGESTSTOP&quot;,&quot;DENGESTSTOP&quot;,&quot;CODLOCALITSTART&quot;,&quot;DENLOCALITSTART&quot;,&quot;CODLOCALITSTOP&quot;,&quot;DENLOCALITSTOP&quot;,&quot;KM&quot;,&quot;CODMONEDA&quot;,&quot;SMONEDA&quot;,&quot;VALOARE&quot;) AS
SELECT
       D.CodDistanta,
       G1.CodGest CodGestStart,
       G1.Den_Gest DenGestStart,
       G2.CodGest CodGestStop,
       G2.Den_Gest DenGestStop,
       L1.CodLocalit CodLocalitStart,
       L1.Den_Localit DenLocalitStart,
       L2.CodLocalit CodLocalitStop,
       L2.Den_Localit DenLocalitStop,
       D.Km,
       M.CODMONEDA,
       M.SIMBOL Smoneda,
       D.Valoare
FROM DISTANTA D
         INNER JOIN NMONEDE M on M.CodMoneda = Nvl(D.Moneda,0)
         INNER JOIN NGEST G1 on G1.CODGEST = Nvl(D.CODGEST_START,0)
         INNER JOIN NGEST G2 on G2.CODGEST = Nvl(D.CODGEST_STOP,0)
         INNER JOIN NLOCALIT L1 on L1.CODLOCALIT = Nvl(D.CODLOCALIT_START,0)
         INNER JOIN NLOCALIT L2 on L2.CODLOCALIT = Nvl(D.CODLOCALIT_STOP,0)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISTRIB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49D80EA5E024EABF0F12406ACF7A32DBD9E85123</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISTRIB (
&quot;CODDISTRIB&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;ZI&quot;,&quot;SUBUNITATEA&quot;) AS
select CODDISTRIB,AN,LUNA,ZI, subunitatea
    from distrib 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>594D38F2E873831948FC26C319B36470FA2F632E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DVI (
&quot;CODINTR&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALDOC&quot;,&quot;TIPDOC&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;NRDVI&quot;,&quot;DATADVI&quot;,&quot;OPERAT&quot;,&quot;ANULAT&quot;,&quot;TIPIMPORT&quot;) AS
SELECT
  I.CODINTR, I.PREFIXDOC, I.NRDOC, I.DATADOC, I.VALDOC, I.TIPDOC, P.DEN_PART, M.SIMBOL, D.NRDOC AS NRDVI, D.DATADOC AS DATADVI,
  I.OPERAT, I.ANULAT,
( CASE
    WHEN D.TIPIMPORT = 0 THEN &apos;DVI&apos;
    WHEN D.TIPIMPORT = 1 THEN &apos;DVOT&apos;
    WHEN D.TIPIMPORT = 2 THEN &apos;DVI4428&apos;
   END ) AS TIPIMPORT
FROM
  INTRARI I
  LEFT OUTER JOIN NPART   P ON P.CODPART   = I.PARTENER
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN DVI     D ON D.CODINTR   = I.CODINTR
WHERE
  G.SEMNIFICATIE = 100 AND I.TIPDOC = 5 AND I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EFACTCLONA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6887269F1384458EE8ABE8AC3F838F5462A5139</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EFACTCLONA (
&quot;CODEFCUSTOM&quot;,&quot;DEN_EFCUSTOM&quot;,&quot;SQLCAMPURI&quot;) AS
select CODEFCUSTOM, DEN_EFCUSTOM, SQLCAMPURI
    from EFCustom
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EFACT_CUSTOM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D07B8D893E23C1F92C1AA647F994992039DDF8FB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EFACT_CUSTOM (
&quot;CODEFACTC&quot;,&quot;DEN_EFCUSTOM&quot;,&quot;SQLCAMPURI&quot;,&quot;SQLCAMPURI1&quot;) AS
select a.codefactc,
       a.DEN_EFCUSTOM,
       a.sqlcampuri,
       a.sqlcampuri1
    from efact_custom a
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ELEMBUGET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>64528CAD262BD703F26369471AC239DB01EF369D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ELEMBUGET (
&quot;CODELEMBUGET&quot;,&quot;ELEMENT&quot;,&quot;SIMBOL&quot;,&quot;TIP&quot;,&quot;FUNCTIE&quot;,&quot;CLASE&quot;) AS
select
  b.codelembuget,
  b.element,
  b.simbol,
  case
    when b.tip = 1 then &apos;Element de cheltuiala&apos;
    else &apos;Element de venit&apos;
  end tip,
  case
    when b.functie = 0 then &apos;Estimare costuri si venituri din productie pe clase articole&apos;
    when b.functie = 1 then &apos;Estimare plati si incasari saptamale&apos;
    when b.functie = 2 then &apos;Estimare variatie stoc pe clase articole&apos;
  end functie,
  case
    when b.functie in (0,2) then (select stragg3200(cls.den_clasea)
                             from elembuget1 b1
                                  inner join nclasea cls on cls.codclasea = b1.codclasea
                             where b1.codelembuget = b.codelembuget)
  end clase
from elembuget b
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ELEMENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7CC2AC30FBB262E12BBB39B71ACF1E853F4B26D5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ELEMENTE (
&quot;CODELEMENT&quot;,&quot;DEN_ELEMENT&quot;,&quot;DENTIP&quot;,&quot;TIP&quot;,&quot;SIMBOL&quot;,&quot;CODDESCRIPTORBAZA&quot;) AS
SELECT CODELEMENT,DEN_ELEMENT,DECODE(TIP,0,&apos;Chelt&apos;,1,&apos;Venit&apos;,2,&apos;Bifunc&apos;) Dentip, Tip, SIMBOL,CODDESCRIPTORBAZA
 FROM ELEMENTE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ELEMENTE_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>710FBB5A0735EA2DF22371A231DDA05CE683426E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ELEMENTE_ANALIZA (
&quot;CODELEMENT&quot;,&quot;DEN_ELEMENT&quot;,&quot;SIMBOL&quot;,&quot;TIP&quot;,&quot;CODDESCRIPTORBAZA&quot;,&quot;SEL&quot;) AS
SELECT E.CODELEMENT,E.DEN_ELEMENT,E.SIMBOL, E.TIP,E.CODDESCRIPTORBAZA, 0 SEL
      FROM ELEMENTE E INNER JOIN ELEMENTEM EM ON E.CODELEMENT   = EM.CODELEMENT
                      INNER JOIN ELEMENTEC EC ON EC.CODELEMENTM = EM.CODELEMENTM
                      INNER JOIN ELEMENTEA EA ON E.CODELEMENT   = EA.CODELEMENT
      WHERE (INSTR(PKG_ELEMENTE.GET_SIMBOL,EC.MASCA) = 1)AND
            EM.TIPDOC = PKG_ELEMENTE.GET_TIPDOC AND
            EA.CODANALIZA = PKG_ELEMENTE.GET_CODANALIZA AND
            (E.TIP = 2 OR E.TIP = PKG_ELEMENTE.GET_TIPCONT)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ELEMENTE_ANALIZA_ALL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3B21ECC976B1F97A61EA83E77DD5CC11FCB8BBDE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ELEMENTE_ANALIZA_ALL (
&quot;CODELEMENT&quot;,&quot;DEN_ELEMENT&quot;,&quot;SIMBOL&quot;,&quot;TIP&quot;,&quot;CODDESCRIPTORBAZA&quot;,&quot;SEL&quot;) AS
SELECT E.CODELEMENT,E.DEN_ELEMENT,E.Simbol, E.TIP,E.CODDESCRIPTORBAZA, 0 SEL
      FROM ELEMENTE E INNER JOIN ELEMENTEM EM ON E.CODELEMENT   = EM.CODELEMENT
                      INNER JOIN ELEMENTEA EA ON E.CODELEMENT   = EA.CODELEMENT
      WHERE EM.TIPDOC = PKG_ELEMENTE.GET_TIPDOC AND
            EA.CODANALIZA = PKG_ELEMENTE.GET_CODANALIZA AND
            (E.TIP = 2 OR E.TIP = PKG_ELEMENTE.GET_TIPCONT)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EMULARE_NEDESCARCATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF299D2BDCDC943F91E6F113DDE430EFD8DA6F44</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EMULARE_NEDESCARCATA (
&quot;CODOBIECT&quot;,&quot;CODGEST&quot;,&quot;CANT&quot;) AS
SELECT
  CODOBIECT,
  CODGEST,
  SUM(CANT) AS CANT
FROM
  EMULARE E,
  EMULARE1 E1
WHERE
  NVL(E.PRELUAT, 0) = 0
  AND NVL(E.FACTURARE, 0) = 0
  AND E1.CODEMULARE = E.CODEMULARE
  AND NVL(CODGEST, 0) &lt;&gt; 0
GROUP BY CODOBIECT, CODGEST
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ESTIMARIPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0275CE8822CC54C349B52EC579E11E20D34D494</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ESTIMARIPROD (
&quot;CODESTIMAREPROD1&quot;,&quot;CODESTIMAREPROD&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS&quot;,&quot;ANULAT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;SAPTAMANA&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;PREFIXDOC&quot;,&quot;ANIMPORT&quot;) AS
select es1.codestimareprod1, es.codestimareprod, es.an, es.luna, es.subunitatea, es.userid,
       es.datacreare, es.obs, nvl(es.anulat,0) anulat, nvl(es.operat,0) operat, nvl(es.blocat,0) blocat,
       es.saptamana, es.nrdoc, es.datadoc, es.carnetdoc, es.seriadoc, es.prefixdoc, es.animport
from estimariprod es
     inner join (select min(codestimareprod1) codestimareprod1, codestimareprod from estimariprod1 group by codestimareprod) es1 on es1.codestimareprod = es.codestimareprod
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8DFACCDBB088CE49C3B497028F95C1EAB8E40813</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EVALS (
&quot;CODEVALS&quot;,&quot;DEN_EVALUARE&quot;,&quot;DATAORA&quot;) AS
SELECT E.Codevals, E.Den_evaluare, I.DataOra FROM EvalS E
Left join IdentEvalS I on I.CodIdentEvalS = E.CodIdentEvalS
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EVALUARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CEBCB800B3FFE9AA3A6F5F424EA6298AB5E1E931</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EVALUARI (
&quot;CODEVALUARE&quot;,&quot;DATAORA&quot;,&quot;RUNDAEVALUARE&quot;,&quot;NREVALUATORI&quot;,&quot;NRESANTIOANE&quot;,&quot;CODEVALUATOR&quot;,&quot;CODTESATURA&quot;,&quot;NUMEEVALUATOR&quot;,&quot;OBS&quot;,&quot;NUMETESATURA&quot;,&quot;NUMEDESTINATIE&quot;) AS
SELECT
     E.CODEVALUARE   ,
     E.DATAORA,
     E.rundaevaluare,
     E.nrevaluatori ,
     E.nresantioane ,
     E.CODevaluator,
     E.codtesatura,
     Ev.NUME numeevaluator,
     E.obs,
     T.Denumire NUMETESATURA,
     D.NumeDestinatie NUMEDESTINATIE
  FROM EVALUARI E
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EVALUATORI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6302FF1700EA01BAE45C689E2C57FCDB21452CD5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EVALUATORI (
&quot;CODEVALUATOR&quot;,&quot;NUME&quot;,&quot;ORDINE&quot;) AS
SELECT
  Codevaluator,
  NUME,
  ORDINE
FROM EVALUATORI
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EXPERTDEFECTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B1ED30A9627418AB8C203A844C2049C5A05CC91D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EXPERTDEFECTE (
&quot;CODUNIC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;OBS&quot;,&quot;DEN_SUBUNIT&quot;,&quot;NUMEDOC&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;,&quot;CODEXPERT&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;CODCENTRU&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;SUBUNITATEA&quot;) AS
with EXP AS
(
select distinct CodExpert, Cate, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, Sum(AreJurn) AreJurn, Sum(AreExp) AreExp , Sum(DifJurn) DifJurn
from
(
Select CodExpert, Cate, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD,
       Case when ValJurn   = 0 then 0 else 1 end AreJurn,
       Case when ValExpert = 0 then 0 else 1 end AreExp,
       Case when ValJurn = ValExpert then 0 else 1 end DifJurn
from (
select Sum(CodExpert) CodExpert, Sum(Cate) Cate, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, Sum(VALEXPERT) VALEXPERT, Sum(VALJURN) VALJURN
from (select E1.CodExpert, 1 Cate, E.CodDoc, E.TipDoc, E1.INDEXJURN INDEXLOCAL, E1.GESTJURN GEST, E1.SUBUNITJURN SUBUNITATEA, E1.CONTD, E1.CONTC, E1.CODCENTRU, E1.ANALIZANODJURN CODANALIZANOD, Sum(Valoare) VALEXPERT, 0 VALJURN
      from Expert1 e1, Expert e  WHERE E.AN * 12 + E.LUNA = PKG_GLOBALS.ANLUNALUCRU AND E.CodAnaliza = PKG_EXPERT.GetCodAnaliza and E1.CodExpert = E.CodExpert
      Group By E1.CodExpert, E.CodDoc, E.TipDoc, E1.INDEXJURN, E1.GESTJURN, E1.SUBUNITJURN, E1.CONTD, E1.CONTC, E1.CODCENTRU, E1.ANALIZANODJURN
      UNION ALL
      select 0 CodExpert, 0 Cate, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, 0 VALEXPERT, Sum(Valoare) VALJURN
      from JURNAL  WHERE AN * 12 + LUNA = PKG_GLOBALS.ANLUNALUCRU
      Group By CodDoc, TipDoc, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD
      UNION ALL
      select 0 CodExpert, 0 Cate, D1.CodDOCSUPLIM CODDOC, D.TipDoc, D1.CodDOCSUPLIM1 , 0, D.SUBUNITATEA, 0, 0, 0, 0, 0 VALEXPERT, Sum(D1.Valoare) VALJURN
      from DOCSUPLIM1 D1 inner join DOCSUPLIM D on D.CodDOCSUPLIM = D1.CodDOCSUPLIM  WHERE D.AN * 12 + D.LUNA = PKG_GLOBALS.ANLUNALUCRU
      Group By D1.CodDOCSUPLIM, D.TipDoc, D1.CodDOCSUPLIM1, D.SUBUNITATEA)
Group By CodDoc, TipDoc, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD)
where Round(ValEXPERT - ValJurn, 2) &lt;&gt; 0)
Group By CodExpert, Cate, CodDoc, TipDoc, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD
)
select &quot;CODUNIC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;OBS&quot;,&quot;DEN_SUBUNIT&quot;,&quot;NUMEDOC&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;,
       Case when Cate &gt; 0 then CODEXPERT/Cate else 0 end &quot;CODEXPERT&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;CODCENTRU&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;SUBUNITATEA&quot;
from(
select RowNum CodUnic, E.CodDoc, E.TipDoc, E.IndexLocal, NVL(J.DataDoc, D.DataDoc) DataDoc, Nvl(J.Document, D.DenDoc) Document, Nvl(J.Obs, D.NrDoc) Obs,
       S.Den_Subunit, PKG_LIST_BASE_UTILS.decode_tipdoc(E.TIPDOC) AS NumeDoc, AreJurn, AreExp, DifJurn, CodExpert,Cate,
       E.CONTD, E.CONTC, E.GEST, E.CODCENTRU, E.CODANALIZANOD, Nvl(J.VALOARE, 0) Valoare,  0 VALOAREV, E.SUBUNITATEA
from EXP E left join Nsubunit S on S.CodSubunit = E.Subunitatea
           left join Jurnal J on  J.CodDoc     = E.CodDoc
                              and J.TipDoc           = E.TipDoc
                              and J.INDEXLOCAl       = E.INDEXLOCAl
                              and J.GEST             = E.GEST
                              and J.SUBUNITATEA      = E.SUBUNITATEA
                              and J.CONTD            = E.CONTD
                              and J.CONTC            = E.CONTC
                              and J.CODCENTRU        = E.CODCENTRU
                              and J.CODANALIZANOD    = E.CODANALIZANOD
															and J.AN * 12 + J.LUNA = PKG_GLOBALS.ANLUNALUCRU
           left join DOCSUPLIM D on D.TipDoc = E.TipDoc and D.CODDOCSUPLIM = E.CodDoc)
where (PKG_EXPERT.GetTipanaliza = 0 and TipDoc &lt;&gt; 32) or (TipDoc = PKG_EXPERT.GetTipanaliza)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EXPERTDEFECTEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6801005E28E3E1507ECD58464FE719E606CF40BB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EXPERTDEFECTEX (
&quot;CODEXPERT1&quot;,&quot;CODEXPERT&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;) AS
with EXP AS
(
select distinct CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, Sum(AreJurn) AreJurn, Sum(AreExp) AreExp , Sum(DifJurn) DifJurn
from
(
Select CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD,
       Case when ValJurn   = 0 then 0 else 1 end AreJurn,
       Case when ValExpert = 0 then 0 else 1 end AreExp,
       Case when ValJurn = ValExpert then 0 else 1 end DifJurn
from (
select CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, Sum(VALEXPERT) VALEXPERT, Sum(VALJURN) VALJURN
from (select E1.CodExpert1, E1.CodExpert, E.CodDoc, E.TipDoc, E1.INDEXJURN INDEXLOCAL, E1.GESTJURN GEST, E1.SUBUNITJURN SUBUNITATEA, E1.CONTD, E1.CONTC, E1.CODCENTRU, E1.ANALIZANODJURN CODANALIZANOD, Sum(Valoare) VALEXPERT, 0 VALJURN
      from Expert1 e1, Expert e  WHERE E.AN * 12 + E.LUNA = PKG_GLOBALS.ANLUNALUCRU AND E.CodAnaliza = PKG_EXPERT.GetCodAnaliza and E1.CodExpert = E.CodExpert
      Group By E1.CodExpert1, E1.CodExpert, E.CodDoc, E.TipDoc, E1.INDEXJURN, E1.GESTJURN, E1.SUBUNITJURN, E1.CONTD, E1.CONTC, E1.CODCENTRU, E1.ANALIZANODJURN
      )
Group By CodDoc, TipDoc, CodExpert1, CodExpert, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD)
where Round(ValEXPERT - ValJurn, 2) &lt;&gt; 0)
Group By CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD)
select &quot;CODEXPERT1&quot;,&quot;CODEXPERT&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;
from EXP
where ((PKG_EXPERT.GetTipanaliza = 0 and TipDoc &lt;&gt; 32) or (TipDoc = PKG_EXPERT.GetTipanaliza))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_EXPERTINCOMPLETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E6B5C7891B29292508E306E8E9E729E123AD6A6A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_EXPERTINCOMPLETE (
&quot;CODUNIC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;OBS&quot;,&quot;DEN_SUBUNIT&quot;,&quot;NUMEDOC&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;,&quot;CODEXPERT1&quot;,&quot;CODEXPERT&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;CODCENTRU&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;SUBUNITATEA&quot;) AS
with EXP AS
(
select distinct CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD, Sum(AreJurn) AreJurn, Sum(AreExp) AreExp , Sum(DifJurn) DifJurn
from
(
Select CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAL, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD,
       Case when ValJurn   = 0 then 0 else 1 end AreJurn,
       Case when ValExpert = 0 then 0 else 1 end AreExp,
       Case when ValJurn = ValExpert then 0 else 1 end DifJurn
from (
select Sum(CodExpert1) CodExpert1,
       Sum(CodExpert) CodExpert,
       CodDoc,
       TipDoc,
       INDEXLOCAL,
       GEST,
       SUBUNITATEA,
       CONTD,
       CONTC,
       CODCENTRU,
       CODANALIZANOD,
       Sum(VALEXPERT) VALEXPERT,
       Sum(VALJURN) VALJURN
  from (select E1.CodExpert1,
               E1.CodExpert,
               E.CodDoc,
               E.TipDoc,
               E1.INDEXJURN INDEXLOCAL,
               E1.GESTJURN GEST,
               E1.SUBUNITJURN SUBUNITATEA,
               E1.CONTD,
               E1.CONTC,
               E1.CODCENTRU,
               E1.ANALIZANODJURN CODANALIZANOD,
               Sum(Valoare) VALEXPERT,
               0 VALJURN
          from Expert1 e1, Expert e
         WHERE E.AN * 12 + E.LUNA = PKG_GLOBALS.ANLUNALUCRU
           AND E.CodAnaliza = PKG_EXPERT.GetCodAnaliza
           and E1.CodExpert = E.CodExpert
					 and Nvl(E1.CODANALIZANOD,0) = 0
         Group By E1.CodExpert1,
                  E1.CodExpert,
                  E.CodDoc,
                  E.TipDoc,
                  E1.INDEXJURN,
                  E1.GESTJURN,
                  E1.SUBUNITJURN,
                  E1.CONTD,
                  E1.CONTC,
                  E1.CODCENTRU,
                  E1.ANALIZANODJURN
)
 Group By CodDoc,
          TipDoc,
          INDEXLOCAl,
          GEST,
          SUBUNITATEA,
          CONTD,
          CONTC,
          CODCENTRU,
          CODANALIZANOD)
)
Group By CodExpert1, CodExpert, CodDoc, TipDoc, INDEXLOCAl, GEST, SUBUNITATEA, CONTD, CONTC, CODCENTRU, CODANALIZANOD)
select &quot;CODUNIC&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;OBS&quot;,&quot;DEN_SUBUNIT&quot;,&quot;NUMEDOC&quot;,&quot;AREJURN&quot;,&quot;AREEXP&quot;,&quot;DIFJURN&quot;,&quot;CODEXPERT1&quot;,&quot;CODEXPERT&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;CODCENTRU&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;SUBUNITATEA&quot;
from(
select RowNum CodUnic, E.CodDoc, E.TipDoc, E.IndexLocal, NVL(J.DataDoc, D.DataDoc) DataDoc, Nvl(J.Document, D.DenDoc) Document, Nvl(J.Obs, D.NrDoc) Obs,
       S.Den_Subunit, PKG_LIST_BASE_UTILS.decode_tipdoc(E.TIPDOC) AS NumeDoc, AreJurn, AreExp, DifJurn, CodExpert1, CodExpert,
       E.CONTD, E.CONTC, E.GEST, E.CODCENTRU, E.CODANALIZANOD, Nvl(J.VALOARE, 0) Valoare,  0 VALOAREV, E.SUBUNITATEA
from EXP E left join Nsubunit S on S.CodSubunit = E.Subunitatea
           left join Jurnal J on  J.CodDoc     = E.CodDoc
                              and J.TipDoc           = E.TipDoc
                              and J.INDEXLOCAl       = E.INDEXLOCAl
                              and J.GEST             = E.GEST
                              and J.SUBUNITATEA      = E.SUBUNITATEA
                              and J.CONTD            = E.CONTD
                              and J.CONTC            = E.CONTC
                              and J.CODCENTRU        = E.CODCENTRU
                              and J.CODANALIZANOD    = E.CODANALIZANOD
															and J.AN * 12 + J.LUNA = PKG_GLOBALS.ANLUNALUCRU
           left join DOCSUPLIM D on D.TipDoc = E.TipDoc and D.CODDOCSUPLIM = E.CodDoc)
where (PKG_EXPERT.GetTipanaliza = 0 and TipDoc &lt;&gt; 32) or (TipDoc = PKG_EXPERT.GetTipanaliza)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_FISAEVALP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A874F7A2B131A6EAA08E3D2837561CF95813322</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_FISAEVALP (
&quot;CODFISA&quot;,&quot;CODEVALUARE&quot;,&quot;CR&quot;,&quot;EN&quot;,&quot;MT&quot;,&quot;FR&quot;,&quot;SG&quot;,&quot;NA&quot;,&quot;AN&quot;,&quot;UG&quot;,&quot;RUNDAEVALUARE&quot;,&quot;CODEVALUATOR&quot;,&quot;CODTESATURA&quot;,&quot;CODDESTINATIE&quot;,&quot;NUMEEVALUATOR&quot;,&quot;NUMETESATURA&quot;,&quot;NUMEDESTINATIE&quot;) AS
SELECT
     FP.CodFisa   ,
     FP.CodEvaluare,
     FP.CR ,
     FP.EN ,
     FP.MT ,
     FP.FR ,
     FP.SG ,
     FP.NA ,
     FP.AN ,
     FP.UG ,
     E.rundaevaluare,
     E.codevaluator,
     E.codtesatura,
     E.coddestinatie,
     Ev.NUME numeevaluator,
     T.Denumire NUMETESATURA,
     D.NumeDestinatie NUMEDESTINATIE
  FROM FisaEvalP FP
  inner join evaluari E on E.Codevaluare=FP.Codevaluare
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_FISAEVALT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2617723443783FC16C0ED312BF76FA9FB38F78EE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_FISAEVALT (
&quot;CODFISA&quot;,&quot;CODEVALUARE&quot;,&quot;NOTA&quot;,&quot;RUNDAEVALUARE&quot;,&quot;CODEVALUATOR&quot;,&quot;CODTESATURA&quot;,&quot;CODDESTINATIE&quot;,&quot;NUMEEVALUATOR&quot;,&quot;NUMETESATURA&quot;,&quot;NUMEDESTINATIE&quot;) AS
SELECT
     FT.CodFisa   ,
     FT.CodEvaluare,
     FT.NOTA,
     E.rundaevaluare,
     E.codevaluator,
     E.codtesatura,
     E.coddestinatie,
     Ev.NUME numeevaluator,
     T.Denumire NUMETESATURA,
     D.NumeDestinatie NUMEDESTINATIE
  FROM FisaEvalT FT
  inner join evaluari E on E.Codevaluare=FT.Codevaluare
  Inner join Evaluatori Ev on EV.Codevaluator=E.codevaluator
  Inner join Tesaturi T on T.CodTesatura=E.CodTesatura
  Inner join Destinatii D on D.CodDestinatie=E.CodDestinatie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_FISATEH</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B20F5B993E1D19CDD5A39A45AFE25DAFED77EF2B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_FISATEH (
&quot;CODFISATEH&quot;,&quot;DENUMIRE&quot;,&quot;VERSIUNE&quot;,&quot;DATAFISA&quot;,&quot;FINALIZATA&quot;,&quot;BLOCATA&quot;,&quot;INTOCMITA&quot;) AS
select F.CodFisaTeh, Obj.Denumire, P.Versiune, F.DataFisa, F.Finalizata, F.Blocata, F.Intocmita
from FISATEH F
     Inner Join FISASUP FS on F.CodFisaSup = FS.CodFisaSup
     Inner Join ProiectNod NOD on FS.CODPROIECTNOD = NOD.CODPROIECTNOD
     Inner Join Proiect P on NOD.CODPROIECT = P.CODPROIECT
     LEFT  Join NARTOBJ Obj on FS.CODOBIECTNOD = OBJ.CODOBIECT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_FORMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61A060975DDC36A752372BA82E639897204169A0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_FORMATII (
&quot;CODFORMATIE&quot;,&quot;DEN_FORMATIE&quot;,&quot;SIMBOL&quot;,&quot;DEN_GEST&quot;) AS
SELECT F.CODFORMATIE,F.DEN_FORMATIE,F.SIMBOL , NG.DEN_GEST
FROM FORMATII F  LEFT JOIN NGEST NG ON F.CODGEST = NG.CODGEST 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IDENTEVALS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>28C3868C0A0AC58631D24FB25C4611AB80CB2D78</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IDENTEVALS (
&quot;CODIDENTEVALS&quot;,&quot;NUME&quot;,&quot;DATAORA&quot;,&quot;NREVALUATORI&quot;,&quot;NRESANTIOANE&quot;) AS
SELECT &quot;CODIDENTEVALS&quot;,&quot;NUME&quot;,&quot;DATAORA&quot;,&quot;NREVALUATORI&quot;,&quot;NRESANTIOANE&quot; FROM IdentEvalS
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E3F53C2B6F88F05650825F5D00223CF792EA3280</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = PKG_GLOBALS.GETTIPIESIRE AND I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_AE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>450B8A2BB3C2C70600C3C8263B00C2D959BF4159</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_AE (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = 20 AND
		nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_CF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8D5E4830F4EA5E9F5E2BA8C20233072CE9BB515</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_CF (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = 21 AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_CONSUM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>336DDCE0FEE4FCF52553FFC7AAB9CB43482F7A69</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_CONSUM (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;DEN_GEST&quot;,&quot;SERIADOC&quot;) AS
SELECT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC, I.NRDOC, I.DATADOC,
   I.NRAE, I.VALDOC, I.TVADOC, G.DEN_GEST, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
WHERE
  I.TIPDOC = PKG_GLOBALS.GETTIPIESIRE AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_FACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>404CE02765661423902E8B1FE4222D6E7FCF9822</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_FACT (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES AND G.SEMNIFICATIE = 200
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = 19 AND
		nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_FACTAVIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A1E3C54A74A7F307E9286628120415A0ACD069AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_FACTAVIZ (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = 26 AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_IN_ROSU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F2DF692344BEA5B772EADC0CF6D0902AA09D8AA6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_IN_ROSU (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   G.MONEDA, G.CURS, I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES AND G.SEMNIFICATIE = 200
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = PKG_GLOBALS.GET_TIPDOC_IMPORTAT AND
  PKG_NOMPART.PART_DOCROSU_VALID(I.PARTENER)=1 AND
  I.ANULAT = 0 AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_ROSU_CLIENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>297601A03F511249D5999CA6133A0F708F290FDA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_ROSU_CLIENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,

--  PKG_GLOBALS.SIMBOLCONTOBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
  PKG_PLANCONTURI.GETSIMBOLCONT
  (
   PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))
  )
   AS SIMBOLCONT,


  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN IESIRI I ON I.CODIES = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT = I.SUBUNITATEA
WHERE
--   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 200 AND O.VALOARE &lt; 0)
--   AND nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE)
   AND O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
   PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_SUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F4A923DD51BE87F64D9ED7A8797F26EF3219FB39</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_SUBUNIT (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;DEN_SUBUNIT&quot;,&quot;SERIADOC&quot;,&quot;LISTAT&quot;) AS
SELECT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC, I.NRDOC, I.DATADOC,
   I.NRAE, I.VALDOC, I.TVADOC, S.DEN_SUBUNIT, I.SERIADOC, I.LISTAT
FROM
  IESIRI I
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
WHERE
  I.TIPDOC = PKG_GLOBALS.GETTIPIESIRE AND
		nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IESIRI_VALUTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1C2B93093D050A26819C29B0BB0666ABFB7989AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IESIRI_VALUTA (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SIMBOL&quot;,&quot;SERIADOC&quot;) AS
SELECT DISTINCT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC,
   I.NRDOC, I.DATADOC, I.PARTENER, I.CARNETAE, I.NRAE,
 --  I.VALDOC,
   ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
   I.TVADOC,
   G.MONEDA, G.CURS, I.ACCIZE, I.DELEGAT, I.AGENT, I.MAJORARI,
   I.OBS, I.AN, I.LUNA,  P.DEN_PART, M.SIMBOL, I.SERIADOC
FROM
  IESIRI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC= I.TIPDOC AND G.CODDOC = I.CODIES
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
WHERE
  I.TIPDOC = 22 AND
	nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IES_SUBUNIT_IMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FBB18E9A2FC1756900E94310E7A892856FC9728E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IES_SUBUNIT_IMP (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;DEN_SUBUNIT&quot;,&quot;SERIADOC&quot;,&quot;DEN_SUB_SURSA&quot;) AS
SELECT
   I.CODIES, I.TIPDOC, I.ANULAT, I.BLOCAT, I.OPERAT, I.PREFIXDOC, I.CARNETDOC, I.NRDOC, I.DATADOC,
   I.NRAE, I.VALDOC, I.TVADOC, S.DEN_SUBUNIT, I.SERIADOC,  SS.DEN_SUBUNIT AS DEN_SUB_SURSA
FROM
  IESIRI I
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
  LEFT OUTER JOIN NSUBUNIT SS ON SS.CODSUBUNIT = I.SUBUNITATEA
WHERE
  I.TIPDOC = 23 AND
--nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.ANLUNALUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INCASARI_VIRAMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A123C2E6A21909E661EC6C6555D89852659C40A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INCASARI_VIRAMENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;,&quot;TIPDOC&quot;,&quot;CODDOC&quot;,&quot;COEFPROVIZION&quot;,&quot;NUMEAGENT&quot;,&quot;OBS&quot;,&quot;ROSU&quot;,&quot;CODCENTRU&quot;,&quot;DENCENTRU&quot;,&quot;SERIADOC&quot;,&quot;CURSISTORIC&quot;,&quot;OBIECTTRANZSTINS&quot;,&quot;CODANALIZANOD&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC AS DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
	CASE WHEN O.ICONT &lt; 10000
	THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(O.ICONT, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))
	ELSE PKG_PLANCONTURI.GETSIMBOLCONT(O.ICONT)
	END  AS SIMBOLCONT,
--  PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;   &apos; AS SEDIU,
  T.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS,
  G.TIPDOC,
  G.CODDOC,
  O.COEFPROVIZION,
  &apos;   &apos; AS NUMEAGENT,
  &apos;   &apos; AS OBS,
  0  AS ROSU,
  CEN.CODCENTRU,
  CEN.DENUMIRE AS DENCENTRU,
  T1.SERIEDOC AS SERIADOC,
  G.CURS AS CURSISTORIC,
  0 AS OBIECTTRANZSTINS,
  O.CODANALIZANOD
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN CENTRECOST CEN ON CEN.CODCENTRU = O.CODCENTRU
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
	 LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR = T1.CODTREZOR
	 LEFT OUTER JOIN NSUBUNIT  NS  ON NS.CODSUBUNIT = T.SUBUNITATEA
WHERE
--   nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   T.AN * 12 + T.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 801)
   AND
   O.CODPART            = PKG_NOMPART.GET_PART_CURENT AND
   O.CONTBANKTRANZACTIE = PKG_CONTURIBANCI.GETCONT_SURSA_VIRAMENT
-- AND  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INFOOFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4E8076BE7642DC88D3DAFCA4C9B1250DE8B051C0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INFOOFERTA (
&quot;CODOFERTA1&quot;,&quot;INFO&quot;) AS
select CODOFERTA1, NRDOC || &apos;/&apos; || TO_CHAR(DATAOFERTA, &apos;DD.MM.YYYY&apos;) AS INFO
   from
     OFERTA1 O1,
     OFERTA O
   WHERE
     O.CODOFERTA = O1.CODOFERTA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INFO_OBJ_LUNA_LUCRU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0AA9860A7733908E46B8F765934F5F67F38088F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INFO_OBJ_LUNA_LUCRU (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;TERMENPLATA&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;) AS
SELECT
  A.CODARTICOL, O.CODOBIECT, A.UM, A.CLASA, A.TIPSERIE, A.TIPARTICOL,
  A.ARETG, A.CONTIMPLICIT, A.GESTIMPLICITA, A.CERTIFICAT, A.EVOLUTIEPRET, A.CONTSERVICIU,
  A.UM1, A.UM2, O.CODEXTERN,  O.CODINTERN, O.UMAMBALARE, O.STOCMIN, O.STOCMAX, O.RETURNABIL, O.TERMENPLATA,
  NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2, NVL(TVALUNA.PROCENT, -1) AS PROCTVA
FROM
  NART A,
  NARTOBJ O
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
LEFT OUTER JOIN
(
    SELECT N.CODTVA,N1.CODTVA1,N.DEN_TVA,N1.PROCENT,N1.CODCONTDED,N1.CODCONTCOLE,N1.CODCONTNEEX
    FROM NTVA N LEFT JOIN NTVA1 N1
    ON 	N.CODTVA = N1.CODTVA
       WHERE N1.ANSTART * 12 + N1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 NT1
                                                 WHERE NT1.CODTVA = N1.CODTVA AND
    					     ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
) TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA

WHERE
  O.CODARTICOL = A.CODARTICOL AND O.CODOBIECT = PKG_SELECTARTICOLE.GETOBIECTANALIZAT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>461D9EA2060221AFE202E882BB607563BE2372E2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = PKG_GLOBALS.GETTIPINTRARE AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) -- PENTRU A ELIMINA DIN VIEW INTRARILE PROVENITE DIN IESIRI IN ROSU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI1_CODINTR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D95B2576D3F36CFE2525408044C3082AFBCFB7BE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI1_CODINTR1 (
&quot;CODINTR1&quot;) AS
SELECT CodIntr1 FROM INTRARI1 ORDER BY CodIntr1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_AE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C1B17379465977764E42D5448BB713BC0FE79D5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_AE (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = 2 AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_CF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>403AA99562079CE133D4EA7B9A852258762ED2E0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_CF (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = 3 AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_CODINTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2A00C955108F5F430442F98D1B743B41B89EE81</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_CODINTR (
&quot;CODINTR&quot;) AS
SELECT CodIntr FROM INTRARI ORDER BY CodIntr 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_FACT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>65E30C00DFC1611ACB63D38FA32BE3CC74A1C6B2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_FACT (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;SERIADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,I.SERIADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = 1 AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_FACTAVIZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>128EF2F850A15D84A1603ED81E9F5644B3D40B3B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_FACTAVIZ (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = 9 AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_PERSF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>627EF9E89E70AAC4A23CEEF99B015D543AB6AF11</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_PERSF (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_PART&quot;,&quot;MONEDA&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC, I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ, I.CARNETDOC,
  ROUND(I.VALDOC - I.TVADOC, 2) + ROUND(I.TVADOC, 2) AS VALDOC,
  I.TVADOC,
  I.MAJORARI,
  I.AN,
  I.LUNA,
  I.OBS,
  I.SATELIT,
  I.COMPLEX,
  P.DEN_PART,
  M.SIMBOL AS MONEDA
FROM
  INTRARI I
  LEFT OUTER JOIN GENERAL G ON G.TIPDOC    = I.TIPDOC AND G.CODDOC = I.CODINTR
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = G.MONEDA
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NPART P ON P.CODPART = I.PARTENER
WHERE
I.TIPDOC = 4 AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_PROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF4447705462458EEF9E13B9FE034B28CA9996DF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_PROD (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_GEST&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC,  I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ,  I.CARNETDOC, I.VALDOC, I.TVADOC, I.MAJORARI, I.AN,   I.LUNA,
  I.OBS,      I.SATELIT, I.COMPLEX, G.DEN_GEST
FROM
  INTRARI I
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NGEST G ON G.CODGEST = I.CODGESTPROD
WHERE
I.TIPDOC = PKG_GLOBALS.GETTIPINTRARE AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) -- PENTRU A ELIMINA DIN VIEW INTRARILE PROVENITE DIN IESIRI IN ROSU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_ROSU_FURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B3332A6484829225A7CC1855169EEDC359E985D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_ROSU_FURN (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  ABS(O.VALOARE) AS VALOARE ,
  ABS(O.REST) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  ABS(O.REST) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT  = I.SUBUNITATEA
WHERE
--  nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 100 AND O.VALOARE &lt; 0)
   AND
	 nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INTRARI_SUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A18DADAB4DC0B22804670EBF453DC7A826E92681</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INTRARI_SUBUNIT (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;SATELIT&quot;,&quot;COMPLEX&quot;,&quot;DEN_SUBUNIT&quot;) AS
SELECT DISTINCT
  I.CODINTR,  I.TIPDOC,  I.ANULAT, I.BLOCAT,  I.OPERAT, I.PREFIXDOC, I.NRDOC, I.DATADOC,
  I.PARTENER, I.NRAVIZ,  I.CARNETDOC, I.VALDOC, I.TVADOC, I.MAJORARI, I.AN,   I.LUNA,
  I.OBS,      I.SATELIT, I.COMPLEX, S.DEN_SUBUNIT
FROM
  INTRARI I
  LEFT OUTER JOIN NIR N ON N.CODINTR = I.CODINTR
  LEFT OUTER JOIN NSUBUNIT S ON S.CODSUBUNIT = I.CODSUBUNIT
WHERE
I.TIPDOC = PKG_GLOBALS.GETTIPINTRARE AND I.AN * 12 + I.LUNA = PKG_GLOBALS.ANLUNALUCRU AND
nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
((N.TIPNIR IS NULL)OR(N.TIPNIR = I.TIPDOC)) -- PENTRU A ELIMINA DIN VIEW INTRARILE PROVENITE DIN IESIRI IN ROSU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_INVENTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43A672CA8D94BFD6EC3F87B5DF5C2D01B9CC84AE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_INVENTAR (
&quot;CODINVENTAR&quot;,&quot;NRINVENTAR&quot;,&quot;DATAINVENTAR&quot;,&quot;GESTIUNE&quot;,&quot;RESPONSABIL&quot;,&quot;OBSERVATII&quot;,&quot;TIP&quot;,&quot;DIMINUARE&quot;,&quot;MARIRE&quot;,&quot;FACTURARE&quot;,&quot;IART&quot;,&quot;ITIPCONT&quot;,&quot;SUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPREZOLVARE&quot;,&quot;DEN_GESTIUNE&quot;,&quot;DEN_RESPONSABIL&quot;,&quot;DEN_SUBUNITATE&quot;,&quot;FLGPALM&quot;) AS
select
i.CODINVENTAR,
i.NRINVENTAR,
i.DATAINVENTAR,
i.GESTIUNE,
i.RESPONSABIL,
i.OBSERVATII,
i.TIP,
i.DIMINUARE,
i.MARIRE,
i.FACTURARE,
i.IART,
i.ITIPCONT,
i.SUBUNITATE,
i.USERID,
i.DATACREARE,
i.TIPREZOLVARE, g.den_gest as den_gestiune, p.nume||&apos; &apos;||p.prenume as den_responsabil, s.den_subunit as den_subunitate,
i.flgpalm
from inventar i
     inner join ngest g on i.Gestiune = g.codgest
     inner join npers p on i.responsabil = p.codpers
     inner join nsubunit s on i.subunitate = s.codsubunit
where nvl(i.subunitate,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitate,1),pkg_globals.GETSUBUNITATE)

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>769B46EF4D284669A9BF32106A725E4436B33D0B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART (
&quot;CODIOART&quot;,&quot;DEN_IOART&quot;,&quot;SIMBOL&quot;,&quot;ACTIV&quot;,&quot;SIMBOLCONT&quot;,&quot;MG&quot;,&quot;CODVANZARE&quot;,&quot;DESCARCAREG&quot;,&quot;METODA_GEST&quot;,&quot;NRLINKURI&quot;) AS
SELECT
  I.&quot;CODIOART&quot;,
  I.&quot;DEN_IOART&quot;,
  I.SIMBOL,
  NVL((SELECT
         MAX(ANSTART * 12 + LUNASTART) FROM IOART1 I1
       WHERE
         CODIOART = I.CODIOART AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU), 0)
         AS ACTIV,
   PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOALUNA.CONT, 0)) AS SIMBOLCONT,
   IOALUNA.MG,
   I.CODVANZARE,
   IOALUNA.DESCARCAREG,
   case  IOALUNA.MG
        when 1 then &apos;FIFO - primul intrat, primul iesit&apos;
        when 2 then &apos;LIFO - ultimul intrat, primul iesit&apos;
        when 3 then &apos;PMP - pret mediu ponderat&apos;
        when 4 then &apos;IDS - identificare specifica&apos;
        when 5 then &apos;VALORIC - fara evidenta cantitativa&apos;
    else &apos;&apos;
   end as metoda_gest,
(SELECT COUNT(*) FROM IOARTLINK IL WHERE IL.CODIOART = I.CODIOART) AS NRLINKURI
FROM
  IOART I
  LEFT OUTER JOIN
  (SELECT CODIOART, CONT, MG, IO1.DESCARCAREG FROM IOART1 IO1
   WHERE
    IO1.ANSTART * 12 + IO1.LUNASTART =
      (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
       WHERE
        IO2.CODIOART = IO1.CODIOART AND IO2.AnStart * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
       )
  ) IOALUNA ON IOALUNA.CODIOART = I.CODIOART
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART1_CODIOART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5FD03A21568562371A76DA8DE3AC0ABB96E69C25</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART1_CODIOART1 (
&quot;CODIOART1&quot;) AS
SELECT codioart1 FROM IOART1 ORDER BY codioart1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART1_LUNALUCRU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1B3F3570A5D6B927E4BC5213CC5575E498CE6B4F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART1_LUNALUCRU (
&quot;CODIOART1&quot;,&quot;CODIOART&quot;,&quot;CONT&quot;,&quot;DIFERENTE&quot;,&quot;CHELTUIELI&quot;,&quot;VENITURI&quot;,&quot;PLUSINVENTAR&quot;,&quot;MINUSINVENTAR&quot;,&quot;CHELTTVACOLECTAT&quot;,&quot;CONTROTUNJIRI&quot;,&quot;DIVERSE&quot;,&quot;CUSTODIE&quot;,&quot;ACCIZELATRANSFER&quot;,&quot;DESCARCAREG&quot;,&quot;CONTABGEST&quot;,&quot;BAZA&quot;,&quot;DIFPRET&quot;,&quot;ARETVANEEX&quot;,&quot;TVANEEX&quot;,&quot;MG&quot;,&quot;ANSTART&quot;,&quot;LUNASTART&quot;,&quot;PUSTANDARD&quot;,&quot;CODVANZARE&quot;,&quot;NRLINKURI&quot;) AS
SELECT
&quot;CODIOART1&quot;,
I1.&quot;CODIOART&quot;,
&quot;CONT&quot;,
&quot;DIFERENTE&quot;,
&quot;CHELTUIELI&quot;,
&quot;VENITURI&quot;,
&quot;PLUSINVENTAR&quot;,
&quot;MINUSINVENTAR&quot;,
&quot;CHELTTVACOLECTAT&quot;,
&quot;CONTROTUNJIRI&quot;,
&quot;DIVERSE&quot;,
&quot;CUSTODIE&quot;,
&quot;ACCIZELATRANSFER&quot;,
&quot;DESCARCAREG&quot;,
&quot;CONTABGEST&quot;,
&quot;BAZA&quot;,
&quot;DIFPRET&quot;,
&quot;ARETVANEEX&quot;,
&quot;TVANEEX&quot;,
&quot;MG&quot;,
&quot;ANSTART&quot;,
&quot;LUNASTART&quot;,
&quot;PUSTANDARD&quot;,
&quot;CODVANZARE&quot;,
(SELECT COUNT(*) FROM IOARTLINK IL WHERE IL.CODIOART = IO.CODIOART) AS NRLINKURI
FROM IoArt1 i1, IOART IO
 WHERE
 i1.AnStart * 12 + i1.LunaStart =
  (SELECT MAX(i2.AnStart * 12 + i2.LunaStart) FROM IoArt1 i2
   WHERE
    i2.CodIoArt = i1.CodIoArt AND
    i2.AnStart * 12 + i2.LunaStart &lt;= PKG_GLOBALS.AnLunaLucru
   )
 AND IO.CODIOART = I1.CODIOART

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART_CODIOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>880128520FD395CF4F53861F062CD3AB89A5CC74</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART_CODIOART (
&quot;CODIOART&quot;) AS
SELECT codioart FROM IOART ORDER BY codioart 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART_IMOB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0410963F73648F2F818C7CDB6B3E0F9C7ED48911</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART_IMOB (
&quot;CODIOART&quot;,&quot;DEN_IOART&quot;,&quot;ACTIV&quot;,&quot;SIMBOLCONT&quot;,&quot;MG&quot;,&quot;CODVANZARE&quot;,&quot;NRLINKURI&quot;) AS
SELECT
  I.&quot;CODIOART&quot;,
  I.&quot;DEN_IOART&quot;,
  NVL((SELECT
         MAX(ANSTART * 12 + LUNASTART) FROM IOART1 I1
       WHERE
         CODIOART = I.CODIOART AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0) AS ACTIV,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOALUNA.CONT, 0)) AS SIMBOLCONT,
  IOALUNA.MG,
  I.CODVANZARE,
  (SELECT COUNT(*) FROM IOARTLINK IL WHERE IL.CODIOART = I.CODIOART) AS NRLINKURI
FROM
  IOART I
  LEFT OUTER JOIN
  (SELECT CODIOART, CONT, MG FROM IOART1 IO1
   WHERE
    IO1.ANSTART * 12 + IO1.LUNASTART =
      (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
       WHERE
        IO2.CODIOART = IO1.CODIOART AND IO2.AnStart * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU
       )
  ) IOALUNA ON IOALUNA.CODIOART = I.CODIOART
  WHERE PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(IOALUNA.CONT) &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4204DC68D063D110E0E4FF620987FB342870ABB6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART_LUNA (
&quot;CODIOART&quot;,&quot;CODIOART1&quot;,&quot;DEN_IOART&quot;,&quot;CONT&quot;,&quot;DIFERENTE&quot;,&quot;CHELTUIELI&quot;,&quot;VENITURI&quot;,&quot;PLUSINVENTAR&quot;,&quot;MINUSINVENTAR&quot;,&quot;CHELTTVACOLECTAT&quot;,&quot;CONTROTUNJIRI&quot;,&quot;DIVERSE&quot;,&quot;ACCIZELATRANSFER&quot;,&quot;DESCARCAREG&quot;,&quot;CONTABGEST&quot;,&quot;BAZA&quot;,&quot;DIFPRET&quot;,&quot;ARETVANEEX&quot;,&quot;TVANEEX&quot;,&quot;MG&quot;,&quot;CODVANZARE&quot;) AS
SELECT io.codioart,io1.codioart1,io.den_ioart,io1.cont,io1.diferente,io1.cheltuieli,
       io1.venituri,io1.plusinventar,io1.minusinventar,io1.chelttvacolectat,io1.controtunjiri,io1.diverse,
			 io1.accizelatransfer,io1.descarcareg,io1.contabgest,io1.baza,io1.difpret,io1.aretvaneex,io1.tvaneex,
			 io1.mg, io.CODVANZARE
FROM ioart io LEFT JOIN ioart1 io1
ON io.codioart = io1.codioart
 WHERE io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM ioart1 i1
                                             WHERE i1.codioart = io1.codioart AND
                                              anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
    					)

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART_MF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03C72EA701185F6CF0B345F1223C71301D270D35</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART_MF (
&quot;CODIOART&quot;,&quot;DEN_IOART&quot;,&quot;SIMBOL&quot;,&quot;ACTIV&quot;,&quot;SIMBOLCONT&quot;,&quot;MG&quot;,&quot;CODVANZARE&quot;,&quot;DESCARCAREG&quot;,&quot;METODA_GEST&quot;,&quot;NRLINKURI&quot;,&quot;TIPMF&quot;,&quot;TIPIMOB&quot;) AS
SELECT
  I.&quot;CODIOART&quot;,
  I.&quot;DEN_IOART&quot;,
  I.SIMBOL,
  NVL((SELECT
         MAX(ANSTART * 12 + LUNASTART) FROM IOART1 I1
       WHERE
         CODIOART = I.CODIOART AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0) AS ACTIV,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOALUNA.CONT, 0)) AS SIMBOLCONT,
  IOALUNA.MG,
  I.CODVANZARE,
  IOALUNA.DESCARCAREG,
  case  IOALUNA.MG
        when 1 then &apos;FIFO - primul intrat, primul iesit&apos;
        when 2 then &apos;LIFO - ultimul intrat, primul iesit&apos;
        when 3 then &apos;PMP - pret mediu ponderat&apos;
        when 4 then &apos;IDS - identificare specifica&apos;
        when 5 then &apos;VALORIC - fara evidenta cantitativa&apos;
    else &apos;&apos;
   end as metoda_gest,
  (SELECT COUNT(*) FROM IOARTLINK IL WHERE IL.CODIOART = I.CODIOART) AS NRLINKURI,
  PKG_CATEGCONST.ESTEMIFIX(IOALUNA.CONT) TIPMF,
  PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(IOALUNA.CONT) TIPIMOB
FROM
  IOART I
  LEFT OUTER JOIN
  (SELECT CODIOART, CONT, MG, IO1.DESCARCAREG FROM IOART1 IO1
   WHERE
    IO1.ANSTART * 12 + IO1.LUNASTART =
      (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
       WHERE
        IO2.CODIOART = IO1.CODIOART AND IO2.AnStart * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU
       )
  ) IOALUNA ON IOALUNA.CODIOART = I.CODIOART
  WHERE PKG_CATEGCONST.ESTEMIFIX(IOALUNA.CONT) &gt; 0 OR PKG_CATEGCONST.ESTEIMBUNATATIREMIFIX(IOALUNA.CONT) &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOART_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>27E7711EF086D3DA9FA51CFA1B343F1E3ADFCA18</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOART_MIFIX (
&quot;CODIOART&quot;,&quot;DEN_IOART&quot;,&quot;ACTIV&quot;,&quot;SIMBOLCONT&quot;,&quot;MG&quot;,&quot;CODVANZARE&quot;,&quot;CONT&quot;,&quot;NRLINKURI&quot;,&quot;DIFPRET&quot;) AS
SELECT
  I.&quot;CODIOART&quot;,
  I.&quot;DEN_IOART&quot;,
  NVL((SELECT
         MAX(ANSTART * 12 + LUNASTART) FROM IOART1 I1
       WHERE
         CODIOART = I.CODIOART AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0) AS ACTIV,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOALUNA.CONT, 0)) AS SIMBOLCONT,
  IOALUNA.MG,
  I.CODVANZARE,
  IOALUNA.CONT,
  (SELECT COUNT(*) FROM IOARTLINK IL WHERE IL.CODIOART = I.CODIOART) AS NRLINKURI,
  IOALUNA.DIFPRET
FROM
  IOART I
  LEFT OUTER JOIN
  (SELECT CODIOART, CONT, MG, DIFPRET FROM IOART1 IO1
   WHERE
    IO1.ANSTART * 12 + IO1.LUNASTART =
      (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
       WHERE
        IO2.CODIOART = IO1.CODIOART AND IO2.AnStart * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU
       )
  ) IOALUNA ON IOALUNA.CODIOART = I.CODIOART
  WHERE PKG_CATEGCONST.ESTECONTPENTRU_ANLUNA(IOALUNA.CONT, &apos;CMIFIX&apos;, PKG_GLOBALS.GetANTEMP, PKG_GLOBALS.GETLUNATEMP) &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOBANK</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A21CCB6498366C293BD8B87935D883727BC7B7AB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOBANK (
&quot;CODIOBANK&quot;,&quot;DEN_IOBANK&quot;,&quot;ACTIV&quot;,&quot;CONT&quot;) AS
SELECT DISTINCT
    I.codiobank,
    I.den_iobank,
    coalesce((
        SELECT
            MAX(ib1.anstart * 12 + ib1.lunastart)
        FROM
            iobank1 ib1
        WHERE
                ib1.codiobank = i.codiobank
            AND ib1.anstart * 12 + ib1.lunastart &lt;= PKG_GLOBALS.ANLUNALUCRU
    ),
        0) AS activ,
  LAST_VALUE(NC.SIMBOL) over (partition by i1.codiobank order by i1.anstart * 12 + i1.lunastart
                                        range between unbounded preceding and unbounded following) cont
FROM
    iobank   i
    LEFT JOIN iobank1  i1 ON i.codiobank = i1.codiobank
    LEFT JOIN NCONT NC ON NC.CODCONT = I1.CONT
WHERE i1.codiobank IS NULL OR i1.anstart * 12 + i1.lunastart &lt;= PKG_GLOBALS.ANLUNALUCRU
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOBANK1_CODIOBANK1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A85BEEA55C52177BA45FFCAF0FBBA3CDEBE5074</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOBANK1_CODIOBANK1 (
&quot;CODIOBANK1&quot;) AS
SELECT codiobank1 FROM IOBANK1 ORDER BY codiobank1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOBANK_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F824F727C0A579E0DA5FD8EC79897958A56B1554</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOBANK_LUNA (
&quot;CODIOBANK&quot;,&quot;CODIOBANK1&quot;,&quot;DEN_IOBANK&quot;,&quot;CONT&quot;,&quot;DOBANDA&quot;,&quot;COMISION&quot;,&quot;CHELTUIELICV&quot;,&quot;VENITURICV&quot;) AS
SELECT io.codiobank,io1.codiobank1,io.den_iobank,io1.cont,io1.dobanda,io1.comision,io1.cheltuielicv,
       io1.venituricv
FROM iobank io LEFT JOIN iobank1 io1
ON io.codiobank = io1.codiobank
    WHERE io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iobank1 i1
                                             WHERE i1.codiobank = io1.codiobank AND
						anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
				              ) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOFILIAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F931D1DAC9FF7F7D65C54AA98E42F0A9D375B55C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOFILIAL (
&quot;CODIOFILIAL&quot;,&quot;DEN_IOFILIAL&quot;,&quot;ACTIV&quot;) AS
SELECT CODIOFILIAL,
       DEN_IOFILIAL, 
 NVL((SELECT 
     MAX(ANSTART * 12 + LUNASTART) FROM IOFILIAL1 I1
     WHERE 
     CODIOFILIAL = I.CODIOFILIAL AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0) 
 AS ACTIV
FROM 
IOFILIAL I 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOFILIAL_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24BA0A2EA99028ED6DE5B80C2A7916331957C2CA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOFILIAL_LUNA (
&quot;CODIOFILIAL&quot;,&quot;CODIOFILIAL1&quot;,&quot;DEN_IOFILIAL&quot;,&quot;CONTDECONTARE&quot;,&quot;CONTDECONTSERV&quot;,&quot;CONTDECONTCB&quot;,&quot;CONTDECONTCMP&quot;,&quot;CONTDECONTAREF&quot;,&quot;ISFIRMA&quot;) AS
SELECT io.codiofilial,io1.codiofilial1,io.den_iofilial,io1.contdecontare,io1.contdecontServ,io1.contdecontCB,io1.contdecontCmp,
       io1.CONTDECONTAREF, io1.Isfirma
FROM iofilial io LEFT JOIN iofilial1 io1
ON io.codiofilial = io1.codiofilial
    WHERE io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iofilial1 i1
                                             WHERE i1.codiofilial = io1.codiofilial AND
					      anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
					      )

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68375D22FED8590C02E74AD04CBDF1E78D792420</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOPART (
&quot;CODIOPART&quot;,&quot;DEN_IOPART&quot;,&quot;ACTIV&quot;,&quot;SIMBCONTFURNIZOR&quot;,&quot;SIMBCONTCLIENT&quot;,&quot;SIMBCONTFURNAVANS&quot;,&quot;SIMBCONTCLIENTAVANS&quot;,&quot;SIMBCONTFURNAVIZ&quot;,&quot;SIMBCONTCLIENTAVIZ&quot;) AS
SELECT
 I.&quot;CODIOPART&quot;,
 &quot;DEN_IOPART&quot;,
 NVL((SELECT
     MAX(ANSTART * 12 + LUNASTART) FROM IOPART1 I1
     WHERE
     CODIOPART = I.CODIOPART AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0)
 AS ACTIV,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTFURNIZOR, 0))    AS SIMBCONTFURNIZOR,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTCLIENT, 0))      AS SIMBCONTCLIENT,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTFURNAVANS, 0))   AS SIMBCONTFURNAVANS,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTCLIENTAVANS, 0)) AS SIMBCONTCLIENTAVANS,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTFURNAVIZ, 0))    AS SIMBCONTFURNAVIZ,
 PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPARTLUNA.CONTCLIENTAVIZ, 0))  AS SIMBCONTCLIENTAVIZ
FROM
  IOPART I
  LEFT OUTER JOIN
  (SELECT * FROM IOPART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOPART1 IO2
   WHERE
    IO2.CODIOPART = IO1.CODIOPART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
   ) IOPARTLUNA ON IOPARTLUNA.CODIOPART = I.CODIOPART
WHERE
 PKG_CONFIGPART.COD_IOPART_EDITAT_VALID(I.CODIOPART) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOPART1_CODIOPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7093B90415F224AA28D3017A8925BE12B40C53FE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOPART1_CODIOPART1 (
&quot;CODIOPART1&quot;) AS
SELECT CodIOPart1 FROM IOPART1 ORDER BY CodIOPart1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOPART_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D7D8BEF342E8440AD019EE430E50201004ADF8AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOPART_LUNA (
&quot;CODIOPART&quot;,&quot;CODIOPART1&quot;,&quot;DEN_IOPART&quot;,&quot;CONTFURNIZOR&quot;,&quot;CONTCLIENT&quot;,&quot;CONTFURNAVANS&quot;,&quot;CONTCLIENTAVANS&quot;,&quot;CONTFURNAVIZ&quot;,&quot;CONTCLIENTAVIZ&quot;,&quot;CONTFURNMF&quot;,&quot;CONTCREDITD&quot;,&quot;CONTDEBITD&quot;,&quot;CONTLITIGII&quot;,&quot;CONTFURNAVS&quot;,&quot;CONTFURNAVIC&quot;,&quot;CONTFURNAVIN&quot;,&quot;CONTTERTI&quot;,&quot;CONTFURNLEAS&quot;,&quot;CONTNCRF&quot;,&quot;CONTNCRC&quot;,&quot;CONTCHELTAVANS&quot;,&quot;CONTVENITAVANS&quot;,&quot;CONTGARANTIEEF&quot;,&quot;CONTGARANTIETF&quot;,&quot;CONTGARANTIEEC&quot;,&quot;CONTGARANTIETC&quot;,&quot;CONTSUPLIMF1&quot;,&quot;CONTSUPLIMF2&quot;,&quot;CONTSUPLIMF3&quot;,&quot;CONTSUPLIMF4&quot;,&quot;CONTSUPLIMF5&quot;,&quot;CONTSUPLIMC1&quot;,&quot;CONTSUPLIMC2&quot;,&quot;CONTSUPLIMC3&quot;,&quot;CONTSUPLIMC4&quot;,&quot;CONTSUPLIMC5&quot;,&quot;TVANEEXF&quot;,&quot;TVANEEXC&quot;,&quot;TVANEEXP&quot;,&quot;TVANEEXI&quot;,&quot;TIP&quot;) AS
SELECT io.codiopart,io1.codiopart1,io.den_iopart,io1.contfurnizor,io1.contclient,io1.contfurnavans,io1.contclientavans,
       io1.contfurnaviz,io1.contclientaviz,io1.contfurnmf,io1.contcreditd,io1.contdebitd,io1.contlitigii,io1.contfurnavs,
			 io1.contfurnavic,io1.contfurnavin,io1.contterti,
			 io1.contfurnLeas,
       io1.contncrf        ,
       io1.contncrc        ,
       io1.contcheltavans  ,
       io1.contvenitavans  ,
       io1.contgarantieEF   ,
       io1.contgarantieTF   ,
       io1.contgarantieEC   ,
       io1.contgarantieTC   ,
			 io1.ContSuplimF1 ,
			 io1.ContSuplimF2 ,
			 io1.ContSuplimF3 ,
			 io1.ContSuplimF4 ,
			 io1.ContSuplimF5 ,
			 io1.ContSuplimC1 ,
			 io1.ContSuplimC2 ,
			 io1.ContSuplimC3 ,
			 io1.ContSuplimC4 ,
			 io1.ContSuplimC5 ,
			 io1.tvaneexf,io1.tvaneexc,io1.tvaneexP,io1.tvaneexI,io1.tip
FROM iopart io LEFT JOIN iopart1 io1
ON io.codiopart = io1.codiopart
   WHERE io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iopart1 i1
                                             WHERE i1.codiopart = io1.codiopart AND
					     anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
                                             )

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F10468636876209BC849C12314E976492BD04E8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOPERS (
&quot;CODIOPERS&quot;,&quot;DEN_IOPERS&quot;,&quot;ACTIV&quot;,&quot;CAVANSDECONT&quot;,&quot;CIMPUTATII&quot;,&quot;CGARANTII&quot;,&quot;CALTE&quot;) AS
SELECT
  I.CODIOPERS,
  DEN_IOPERS,
  NVL((SELECT
       MAX(ANSTART * 12 + LUNASTART) FROM IOPERS1 I1
       WHERE
       CODIOPERS = I.CODIOPERS AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0)
  AS ACTIV,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPERSLUNA.CONTAVANSDECONT,  0)) AS CAVANSDECONT,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPERSLUNA.CONTIMPUTATII,    0)) AS CIMPUTATII,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPERSLUNA.CONTGARANTII,     0)) AS CGARANTII,
  PKG_PLANCONTURI.GETSIMBOLCONT(NVL(IOPERSLUNA.CONTALTERETINERI, 0)) AS CALTE
FROM
  IOPERS I
  LEFT OUTER JOIN
  (SELECT * FROM IOPERS1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOPERS1 IO2
   WHERE
    IO2.CODIOPERS = IO1.CODIOPERS AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
   ) IOPERSLUNA ON IOPERSLUNA.CODIOPERS = I.CODIOPERS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_IOPERS_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB3A820626558E4F57F634E3F5E416B0F15BA625</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_IOPERS_LUNA (
&quot;CODIOPERS&quot;,&quot;CODIOPERS1&quot;,&quot;DEN_IOPERS&quot;,&quot;CONTAVANSDECONT&quot;,&quot;CONTIMPUTATII&quot;,&quot;CONTGARANTII&quot;,&quot;CONTALTERETINERI&quot;,&quot;CONTAVANS&quot;,&quot;CONTLIKI&quot;,&quot;CONTNERIDICATE&quot;,&quot;CONTBOALA&quot;,&quot;CONTPARTSAL&quot;,&quot;CONTNATURA&quot;,&quot;CONTECHIPAMENT&quot;,&quot;CONTIMPOZIT&quot;) AS
SELECT io.codiopers,io1.codiopers1,io.den_iopers,io1.contavansdecont,io1.contimputatii,io1.contgarantii,
       io1.contalteretineri,io1.contavans,io1.contliki,io1.contneridicate,io1.contboala,io1.contpartsal,
			 io1.contnatura,io1.contechipament,io1.contimpozit
FROM iopers io LEFT JOIN iopers1 io1
 ON io.codiopers = io1.codiopers
     WHERE io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iopers1 i1
                                             WHERE i1.codiopers = io1.codiopers AND
						  anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
						) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JOBLISTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E4E429E03B0A3163960AE1003A21712DA43B24A7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JOBLISTE (
&quot;CODJOB&quot;,&quot;USERID&quot;,&quot;DENUMIRE&quot;,&quot;TIPJOB&quot;,&quot;USERNAME&quot;,&quot;NUME&quot;) AS
select J.CODJOB, J.USERID, J.DENUMIRE, J.TipJob, U.USERNAME, U.Nume
    from jobliste J left join Tmp_Utilizator U on U.CODUTILIZATOR = J.USERID
    where Nvl(J.TipJob ,0) &lt; 2

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JURNAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05ABC86300A6BAAF4BB9CE269A7F23C45F54DF09</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JURNAL (
&quot;TIPINREG&quot;,&quot;CENTRUCOST&quot;,&quot;SIMBCONTDEBIT&quot;,&quot;SIMBCONCREDIT&quot;,&quot;V&quot;,&quot;CODJURNAL&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;) AS
SELECT
  1 TipInreg,
  J.CodCentru CentruCost,
  CD.Simbol SIMBCONTDEBIT, CC.Simbol SIMBCONCREDIT, J.Valoare V, J.CODJURNAL, J.CODDOC, J.TIPDOC, J.INDEXLOCAL,
  J.CONTD, J.CONTC, J.GEST, J.VALOARE, J.VALOAREV, J.OBS, J.AN, J.LUNA, J.SUBUNITATEA, J.DATADOC, J.DOCUMENT, J.CODCENTRU, J.VALOAREGRUP,
  J.VALOARE_IFRS, J.VALOAREV_IFRS
FROM JURNAL J
  INNER JOIN NCONT CD ON CD.Codcont = J.ContD
  INNER JOIN NCONT CC ON CC.Codcont = J.ContC
WHERE J.an*12 + J.luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JURNAL1_CU_ARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF09AAD6BAC4F2639C6318A59CEBD8CFDE07301D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JURNAL1_CU_ARTICOL (
&quot;CODOBIECT&quot;,&quot;DENUMIRE&quot;,&quot;CLASA&quot;,&quot;SIMBOL_DEBIT&quot;,&quot;SIMBOL_CREDIT&quot;,&quot;CODJURNAL1&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CODBAZAD&quot;,&quot;TIPBAZAD&quot;,&quot;ICONTBAZAD&quot;,&quot;CODDESCRD&quot;,&quot;ICONTD&quot;,&quot;TIPCONTD&quot;,&quot;ANALITICCONTD&quot;,&quot;CODBAZAC&quot;,&quot;TIPBAZAC&quot;,&quot;ICONTBAZAC&quot;,&quot;CODDESCRC&quot;,&quot;ICONTC&quot;,&quot;TIPCONTC&quot;,&quot;ANALITICCONTC&quot;,&quot;GEST&quot;,&quot;CLASAGEST&quot;,&quot;LOCALITATE&quot;,&quot;JUDET&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;VAL_CONT&quot;,&quot;VALV_CONT&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DIRTY&quot;,&quot;SUBUNITATEA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;CODANALIZANOD&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;,&quot;VAL_IFRS_CONT&quot;,&quot;VALV_IFRS_CONT&quot;) AS
select
  case
    when j1.tipdoc in (1,2,3,4,6,7,9) then i1.codobiect
    when j1.tipdoc = 5 then dvi1.codobiect
    when j1.tipdoc in (12,13) then t1.codobiect
    when j1.tipdoc in (14,15,19,20,21,22,23,24,26) then ies1.codobiect
  end codobiect,
  o.denumire, cls.den_clasea Clasa,
  cd.simbol simbol_debit,
  cc.simbol simbol_credit,
j1.CODJURNAL1,j1.CODDOC,j1.TIPDOC,j1.INDEXLOCAL,j1.CODBAZAD,j1.TIPBAZAD,
j1.ICONTBAZAD,j1.CODDESCRD,j1.ICONTD,j1.TIPCONTD,j1.ANALITICCONTD,j1.CODBAZAC,
j1.TIPBAZAC,j1.ICONTBAZAC,j1.CODDESCRC,j1.ICONTC,j1.TIPCONTC,j1.ANALITICCONTC,g.den_gest gest,clsg.den_claseg ClasaGest,
  loc.den_localit localitate, jud.den_judet judet,
  j1.VALOARE,j1.VALOAREV,
  case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOARE else j1.VALOARE end val_cont,
  case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then - j1.VALOAREV else j1.VALOAREV end valV_cont,
  j1.OBS,j1.AN,j1.LUNA,j1.DIRTY,j1.SUBUNITATEA,
j1.DATADOC,j1.DOCUMENT,j1.CODCENTRU,j1.VALOAREGRUP,j1.CODANALIZANOD,
  j1.VALOARE_IFRS,j1.VALOAREV_IFRS,
  case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOARE_IFRS else j1.VALOARE_IFRS end val_ifrs_cont,
  case when cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; then -j1.VALOAREV_IFRS else j1.VALOAREV_IFRS end valv_ifrs_cont
from jurnal1 j1
     inner join ncont cd on cd.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrD, j1.IcontD, j1.TipContD, j1.AnaliticContD, j1.An, j1.Luna)
     inner join ncont cc on cc.codcont = pkg_jurnal.GETCONTFORJURNAL(j1.CodDescrC, j1.IcontC, j1.TipContC, j1.AnaliticContC, j1.An, j1.Luna)
     left join intrari1 i1 on i1.codintr1 = j1.indexlocal
     left join dvi1 on dvi1.coddvi1 = j1.indexlocal
     left join transf1 t1 on t1.codtransf1 = j1.indexlocal
     left join iesiri1 ies1 on ies1.codies1 = j1.indexlocal
     left join nartobj o on o.codobiect = coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect)
     left join nart a on a.codarticol = o.codarticol
     left join nclasea cls on cls.codclasea = a.clasa
     left join ngest g on j1.gest = g.codgest
     left join nagenda ag on g.codgest = ag.codgest and ag.tip = 6
     left join nlocalit loc on loc.codlocalit = ag.codlocalit
     left join njudet jud on jud.codjudet = loc.codjudet
     left join nclaseg clsg on g.codclasa = clsg.codclaseg
where coalesce(i1.codobiect,dvi1.codobiect,t1.codobiect,ies1.codobiect) &gt; 0 and
      (cd.simbol LIKE &apos;6%&apos; OR cd.simbol LIKE &apos;709&apos; OR cc.simbol LIKE &apos;7%&apos; OR cc.simbol LIKE &apos;609&apos;)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JURNAL_S</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F70AF341EAA8AAFFEF7F58BCD4AAC3D4B185C334</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JURNAL_S (
&quot;TIPINREG&quot;,&quot;CENTRUCOST&quot;,&quot;SIMBCONTDEBIT&quot;,&quot;SIMBCONCREDIT&quot;,&quot;V&quot;,&quot;CODJURNAL&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;) AS
SELECT
  2 TipInreg,
  CASE WHEN Coalesce(C1D.CodCentruS, 0) &lt;&gt; 0 THEN C1D.CodCentruS WHEN Coalesce(C1C.CodCentruS,0) &lt;&gt; 0 THEN C1C.CodCentruS ELSE Coalesce(J.CodCentru,0) END CentruCost,
  CD.Simbol SIMBCONTDEBIT, CC.Simbol SIMBCONCREDIT, J.Valoare V, J.CODJURNAL, J.CODDOC, J.TIPDOC, J.INDEXLOCAL,
  J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.CODCENTRU,J.VALOAREGRUP,
  J.VALOARE_IFRS, J.VALOAREV_IFRS
FROM JURNAL J
  INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
  INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
  INNER JOIN NCONTS CD  ON CD.CODCONTS = C1D.CONTSECUNDAR
  INNER JOIN NCONTS CC  ON CC.CODCONTS = C1C.CONTSECUNDAR
WHERE J.an*12 + J.luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
  AND Nvl(C1D.CONTSECUNDAR,0) &gt; 0
  AND Nvl(C1C.CONTSECUNDAR,0) &gt; 0
  AND EXISTS (SELECT 1 FROM nconts1 cs1d WHERE cs1d.codconts = cd.codconts AND cs1d.anstart*12+cs1d.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
  AND EXISTS (SELECT 1 FROM nconts1 cs1c WHERE cs1c.codconts = cc.codconts AND cs1c.anstart*12+cs1c.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
UNION ALL
SELECT
  3 TipInreg,
  CASE WHEN Coalesce(C1D.CodCentruSG, 0) &lt;&gt; 0 THEN C1D.CodCentruSG WHEN Coalesce(C1C.CodCentruSG,0) &lt;&gt; 0 THEN C1C.CodCentruSG ELSE Coalesce(J.CodCentru,0) END CentruCost,
  CD.Simbol SIMBCONTDEBIT, CC.Simbol SIMBCONCREDIT, NVL(J.ValoareGrup, J.Valoare) V, J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,
  J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.CODCENTRU,J.VALOAREGRUP,
  J.VALOARE_IFRS, J.VALOAREV_IFRS
FROM JURNAL J
  INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
  INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
  INNER JOIN NCONTS CD  ON CD.CODCONTS = C1D.CONTSECUNDARG
  INNER JOIN NCONTS CC  ON CC.CODCONTS = C1C.CONTSECUNDARG
WHERE J.an*12 + J.luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
  AND Nvl(C1D.CONTSECUNDARG,0) &gt; 0
  AND Nvl(C1C.CONTSECUNDARG,0) &gt; 0
  AND EXISTS (SELECT 1 FROM nconts1 cs1d WHERE cs1d.codconts = cd.codconts AND cs1d.anstart*12+cs1d.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
  AND EXISTS (SELECT 1 FROM nconts1 cs1c WHERE cs1c.codconts = cc.codconts AND cs1c.anstart*12+cs1c.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
UNION ALL
SELECT
  4 TipInreg,
  CASE WHEN Coalesce(C1D.CodCentruSGO, 0) &lt;&gt; 0 THEN C1D.CodCentruSGO WHEN Coalesce(C1C.CodCentruSGO,0) &lt;&gt; 0 THEN C1C.CodCentruSGO ELSE Coalesce(J.CodCentru,0) END CentruCost,
  CD.Simbol SIMBCONTDEBIT, CC.Simbol SIMBCONCREDIT, NVL(J.ValoareGrup, J.Valoare) V, J.CODJURNAL,J.CODDOC,J.TIPDOC,J.INDEXLOCAL,
  J.CONTD,J.CONTC,J.GEST,J.VALOARE,J.VALOAREV,J.OBS,J.AN,J.LUNA,J.SUBUNITATEA,J.DATADOC,J.DOCUMENT,J.CODCENTRU,J.VALOAREGRUP,
  J.VALOARE_IFRS, J.VALOAREV_IFRS
FROM JURNAL J
  INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
  INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
  INNER JOIN NCONTS CD  ON CD.CODCONTS = C1D.CONTSECUNDARGO
  INNER JOIN NCONTS CC  ON CC.CODCONTS = C1C.CONTSECUNDARGO
WHERE J.an*12 + J.luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
  AND Nvl(C1D.CONTSECUNDARGO,0) &gt; 0
  AND Nvl(C1C.CONTSECUNDARGO,0) &gt; 0
  AND EXISTS (SELECT 1 FROM nconts1 cs1d WHERE cs1d.codconts = cd.codconts AND cs1d.anstart*12+cs1d.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
  AND EXISTS (SELECT 1 FROM nconts1 cs1c WHERE cs1c.codconts = cc.codconts AND cs1c.anstart*12+cs1c.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JURNAL_T</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>66A7F969956A62B783F5FE23A9EE2417109A7972</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JURNAL_T (
&quot;TIPINREG&quot;,&quot;CENTRUCOST&quot;,&quot;SIMBCONTDEBIT&quot;,&quot;SIMBCONCREDIT&quot;,&quot;V&quot;,&quot;CODJURNAL&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;INDEXLOCAL&quot;,&quot;CONTD&quot;,&quot;CONTC&quot;,&quot;GEST&quot;,&quot;VALOARE&quot;,&quot;VALOAREV&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;DATADOC&quot;,&quot;DOCUMENT&quot;,&quot;CODCENTRU&quot;,&quot;VALOAREGRUP&quot;,&quot;VALOARE_IFRS&quot;,&quot;VALOAREV_IFRS&quot;) AS
SELECT
  5 TipInreg,
  J.CodCentru CentruCost,
  CD.Simbol SIMBCONTDEBIT, CC.Simbol SIMBCONCREDIT, J.Valoare V, J.CODJURNAL, J.CODDOC, J.TIPDOC, J.INDEXLOCAL,
  J.CONTD, J.CONTC, J.GEST, J.VALOARE, J.VALOAREV, J.OBS, J.AN, J.LUNA, J.SUBUNITATEA, J.DATADOC, J.DOCUMENT, J.CODCENTRU, J.VALOAREGRUP,
  J.VALOARE_IFRS, J.VALOAREV_IFRS
FROM JURNAL J
  INNER JOIN NCONT1 C1D ON C1D.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContD, J.An, J.Luna)
  INNER JOIN NCONT1 C1C ON C1C.CodCont1 = PKG_PlanConturi.GET_CONT_COD_CARACT_LUNA(J.ContC, J.An, J.Luna)
  INNER JOIN NCONTT CD  ON CD.CODCONTT = C1D.CONTTERTIAR
  INNER JOIN NCONTT CC  ON CC.CODCONTT = C1C.CONTTERTIAR
WHERE J.an*12 + J.luna BETWEEN pkg_list_base_regjurnal.LunaIni AND pkg_list_base_regjurnal.LunaFin
  AND Nvl(C1D.CONTTERTIAR,0) &gt; 0
  AND Nvl(C1C.CONTTERTIAR,0) &gt; 0
  AND EXISTS (SELECT 1 FROM ncontt1 ct1d WHERE ct1d.codcontt = cd.codcontt AND ct1d.anstart*12+ct1d.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
  AND EXISTS (SELECT 1 FROM ncontt1 ct1c WHERE ct1c.codcontt = cc.codcontt AND ct1c.anstart*12+ct1c.lunastart &lt;= pkg_list_base_regjurnal.LunaFin)
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_JUSTIFICARE_AVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B18514FA3A29FDBE74C5A9BAB0E84EB907F1EEE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_JUSTIFICARE_AVANS (
&quot;CODTREZOR&quot;,&quot;DATADOC&quot;,&quot;NUMEDOC&quot;,&quot;NUME&quot;,&quot;PRENUME&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;TIPDOC&quot;,&quot;UTILIZATOR&quot;) AS
SELECT
  T.CODTREZOR, T.DATADOC, T.NUMEDOC, P.NUME, P.PRENUME, T.OPERAT, T.BLOCAT, T.TIPDOC, NUMEPRENUME(U.NUME, U.PRENUME) Utilizator 
FROM TREZOR T
  LEFT JOIN NPERS P ON P.CODPERS = T.CODBANCA
  LEFT JOIN NPERS U ON U.LOGONNAME = T.USERID
WHERE TIPDOC = 33 AND AN * 12 + LUNA = PKG_GLOBALS.AnLunaLucru</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LANSARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5DAF29F3EF041C97AA79C7F3F3E143B1133478FE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LANSARI (
&quot;CODLANSARE&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DENUMIRE&quot;,&quot;CANT&quot;,&quot;NRCOM&quot;,&quot;DATACOM&quot;,&quot;DEN_PART&quot;,&quot;DEN_SCENARIU&quot;) AS
SELECT
  l.codlansare,
  l.NRDOC ,
  l.datadoc,
  obj.denumire,
  l.cant,
  c.nrdoc nrcom,
  c.datadoc datacom,
  p.den_part,
  s.DEN_SCENARIU
from
  lansare l
  inner join proiect pc on l.codproiect = pc.codproiect
  inner join nartobj obj on pc.codobiectprod = obj.codobiect
  left join comanda1 c1 on l.codcmd1 = c1.codcomanda1
  left join comanda c on c1.codcomanda = c.codcomanda
  left join npart p on c.partener = p.codpart
  left join ScenariiLivr s on s.codscenariu = l.codscenariu

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LANSPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>433E0EE35CC4A43CAAF405A26290EE16FAE2706E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LANSPROD (
&quot;CODLANSPROD&quot;,&quot;SAPTAMANA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;OBS&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;) AS
select L.CODLANSPROD, L.SAPTAMANA, SUB.DEN_SUBUNIT,
       L.Obs,
       trunc(trunc(to_date(L.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + (L.Saptamana - 1) * 7 DataStart,
       trunc(trunc(to_date(L.AN,&apos;yyyy&apos;),&apos;yyyy&apos;),&apos;iw&apos;) + L.Saptamana  * 7 - 1 DataStop
  from LANSPROD L
       INNER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = L.SUBUNITATEA
  WHERE L.AN = PKG_GLOBALS.GetANLUCRU

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LANSZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CE877DE6530C52BC527DB6D750FD7DC4B855550A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LANSZ (
&quot;CODLANSZ&quot;,&quot;SAPTAMANA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;SUBUNITATEA&quot;,&quot;FINALIZAT&quot;) AS
select LZ.CODLANSZ, LZ.SAPTAMANA, SUB.DEN_SUBUNIT, G.DEN_GEST,
       LZ.Obs,
       iso_week_to_date(lz.an, lz.saptamana) datastart,
       iso_week_to_date(lz.an, lz.saptamana) + 6 datastop,
       LZ.SUBUNITATEA, LZ.FINALIZAT
  from LANSZ LZ
       INNER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = LZ.SUBUNITATEA
       INNER JOIN NGEST G ON LZ.CODGEST = G.CODGEST
  WHERE LZ.AN = PKG_GLOBALS.GetANLUCRU
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LINII_COMENZI_CLIENTI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>97693304640D411FCED529D3AAF965B8BC8564BF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LINII_COMENZI_CLIENTI (
&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;RESTACCEPTAT&quot;,&quot;CODOBIECT&quot;,&quot;TERMEN&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;CANT&quot;,&quot;RESTLANSAT&quot;) AS
select
    c.prefixdoc, c.nrdoc, c.datadoc,
    c1.restacceptat, c1.CodObiect, c1.termen,
    obj.denumire, p.den_part, c1.cantacceptat cant,
    c1.restlansat
  from
    comanda c
    inner join comanda1 c1 on c.codcomanda = c1.codcomanda
    inner join nartobj obj on c1.codobiect = obj.codobiect
    left  join npart p on c.partener = p.codpart
  where
    c.tipdoc = 18 and c1.restacceptat &gt; 0 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_ANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85C09E1D24098CD0FF4FDF1B7C83F9DE393512F9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_ANALIZA (
&quot;CODANALIZA&quot;,&quot;DEN_ANALIZA&quot;,&quot;IDELEMENT&quot;,&quot;IDCENTRU&quot;,&quot;INACTIV&quot;) AS
SELECT &quot;CODANALIZA&quot;,&quot;DEN_ANALIZA&quot;,&quot;IDELEMENT&quot;,&quot;IDCENTRU&quot;,&quot;INACTIV&quot;
FROM ANALIZA
WHERE codAnaliza = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_ASIGURARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>303D15E6B66F322EA94997F27EA9EE470A83C5B0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_ASIGURARI (
&quot;CODASIGURARE&quot;,&quot;NRDOC&quot;,&quot;CODPART&quot;,&quot;DATASTART&quot;,&quot;TERMEN&quot;,&quot;CODCLASEMF&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALOARE&quot;) AS
select &quot;CODASIGURARE&quot;,&quot;NRDOC&quot;,&quot;CODPART&quot;,&quot;DATASTART&quot;,&quot;TERMEN&quot;,&quot;CODCLASEMF&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALOARE&quot; from ASIGURARI
where CODASIGURARE = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_AUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2AD9BCDC611AA3A2F632A221CDB89E9196F415D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_AUTO (
&quot;CODNPARCAUT&quot;,&quot;CODART&quot;,&quot;NRINV&quot;,&quot;NRINREG&quot;,&quot;SOFER&quot;,&quot;KMPORNIRE&quot;,&quot;TIP&quot;,&quot;DATAINREG&quot;,&quot;MARCA&quot;,&quot;MODEL&quot;,&quot;ANF&quot;,&quot;SERIEC&quot;,&quot;CULOARE&quot;,&quot;LUNG&quot;,&quot;LAT&quot;,&quot;INALT&quot;,&quot;TIPMOTOR&quot;,&quot;SERIEM&quot;,&quot;MOTOR&quot;,&quot;CILINDREE&quot;,&quot;PUTERE&quot;,&quot;CMM&quot;,&quot;CMU&quot;,&quot;CME&quot;,&quot;TIPINCARC&quot;,&quot;GREUTATE&quot;,&quot;MASAM&quot;,&quot;MASAU&quot;,&quot;MASAURDF&quot;,&quot;MASAURFDF&quot;,&quot;LOCT&quot;,&quot;LOCF&quot;,&quot;LOCS&quot;,&quot;LOCP&quot;,&quot;ANVRECOMF&quot;,&quot;ANVRECOMS&quot;,&quot;ANVOPT1F&quot;,&quot;ANVOPT1S&quot;,&quot;ANVOPT2F&quot;,&quot;ANVOPT2S&quot;,&quot;KG&quot;,&quot;KGR&quot;,&quot;SARCINA&quot;,&quot;CODPUTERE&quot;,&quot;GRUPAUTO&quot;,&quot;TIPREM&quot;,&quot;INSTSP&quot;,&quot;AER&quot;,&quot;REZERVOR&quot;,&quot;VOLUMU&quot;,&quot;CULOAREC&quot;,&quot;SURSAE&quot;) AS
select &quot;CODNPARCAUT&quot;,&quot;CODART&quot;,&quot;NRINV&quot;,&quot;NRINREG&quot;,&quot;SOFER&quot;,&quot;KMPORNIRE&quot;,&quot;TIP&quot;,&quot;DATAINREG&quot;,&quot;MARCA&quot;,&quot;MODEL&quot;,&quot;ANF&quot;,&quot;SERIEC&quot;,
       &quot;CULOARE&quot;,&quot;LUNG&quot;,&quot;LAT&quot;,&quot;INALT&quot;,&quot;TIPMOTOR&quot;,&quot;SERIEM&quot;,&quot;MOTOR&quot;,&quot;CILINDREE&quot;,&quot;PUTERE&quot;,&quot;CMM&quot;,&quot;CMU&quot;,&quot;CME&quot;,&quot;TIPINCARC&quot;,
       &quot;GREUTATE&quot;,&quot;MASAM&quot;,&quot;MASAU&quot;,&quot;MASAURDF&quot;,&quot;MASAURFDF&quot;,&quot;LOCT&quot;,&quot;LOCF&quot;,&quot;LOCS&quot;,&quot;LOCP&quot;,&quot;ANVRECOMF&quot;,&quot;ANVRECOMS&quot;,&quot;ANVOPT1F&quot;,
       &quot;ANVOPT1S&quot;,&quot;ANVOPT2F&quot;,&quot;ANVOPT2S&quot;,&quot;KG&quot;,&quot;KGR&quot;,&quot;SARCINA&quot;,&quot;CODPUTERE&quot;,&quot;GRUPAUTO&quot;,&quot;TIPREM&quot;,&quot;INSTSP&quot;,&quot;AER&quot;,&quot;REZERVOR&quot;,
       &quot;VOLUMU&quot;,&quot;CULOAREC&quot;,&quot;SURSAE&quot;
from nparcaut where codnparcaut = pkg_globals.GET_RECID_DOC_LISTARE

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_BCAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C73D0E0D0D27D75BAD03EFDB7F0908C73296CD43</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_BCAR (
&quot;CODBCAR&quot;,&quot;OPERAT&quot;,&quot;CODCANTARIN&quot;,&quot;CODCANTAROUT&quot;,&quot;TIPDOC&quot;,&quot;CODDOC1&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;PREFIXAVIZIN&quot;,&quot;NRAVIZIN&quot;,&quot;NRAVIZOUT&quot;,&quot;DATAAVIZIN&quot;,&quot;ISUMIDITATE&quot;,&quot;IAUMIDITATE&quot;,&quot;ISSTRAINE&quot;,&quot;IASTRAINE&quot;,&quot;ISINCOLTIT&quot;,&quot;IAINCOLTIT&quot;,&quot;ISHECTOLITRICA&quot;,&quot;IAHECTOLITRICA&quot;,&quot;ISGLUTEN&quot;,&quot;IAGLUTEN&quot;,&quot;ISFUZARITATE&quot;,&quot;IAFUZARITATE&quot;,&quot;ISCADERE&quot;,&quot;IACADERE&quot;,&quot;ISDEFORMARE&quot;,&quot;IADEFORMARE&quot;,&quot;ISSTICLOZITATE&quot;,&quot;IASTICLOZITATE&quot;,&quot;ISSPARTURI&quot;,&quot;IASPARTURI&quot;,&quot;CODOBIECT&quot;,&quot;BRUTKG&quot;,&quot;TARA&quot;,&quot;NETKG&quot;,&quot;UTILKG&quot;,&quot;PRETACHIZ&quot;,&quot;PRETUSCARE&quot;,&quot;CODPARTENER&quot;,&quot;CODSEDIU&quot;,&quot;CODDELEGAT&quot;,&quot;CODSUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODSERIE&quot;,&quot;RETUR&quot;,&quot;MODCANTAR&quot;,&quot;USERIDBLOCAJ&quot;,&quot;TIPBCAR&quot;,&quot;CODGESTIMPL&quot;,&quot;CODLOCATIMPL&quot;,&quot;OBSERVATII&quot;,&quot;CODPERS&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;CODAUTO&quot;,&quot;ICUMIDITATE&quot;,&quot;ICSTRAINE&quot;,&quot;ICINCOLTIT&quot;,&quot;ICHECTOLITRICA&quot;,&quot;ICGLUTEN&quot;,&quot;ICFUZARITATE&quot;,&quot;ICCADERE&quot;,&quot;ICDEFORMARE&quot;,&quot;ICSTICLOZITATE&quot;,&quot;ICSPARTURI&quot;,&quot;NETKGCLIENT&quot;,&quot;UTILKGCLIENT&quot;,&quot;INFOCLIENT&quot;,&quot;CODDOC1STORNO&quot;,&quot;CODBCARDEST&quot;,&quot;CODCONTRACT1&quot;,&quot;NRREMORCA&quot;,&quot;CODREMORCA&quot;,&quot;UTILSTASKG&quot;,&quot;PRETCONFIRMAT&quot;,&quot;ISPROTEINA&quot;,&quot;ISAFLATOXINA&quot;,&quot;ISATAC_PLOSNITA&quot;,&quot;ISCONTINUT_ULEI&quot;,&quot;ISACIDITATE&quot;,&quot;IAPROTEINA&quot;,&quot;IAAFLATOXINA&quot;,&quot;IAATAC_PLOSNITA&quot;,&quot;IACONTINUT_ULEI&quot;,&quot;IAACIDITATE&quot;,&quot;ICPROTEINA&quot;,&quot;ICAFLATOXINA&quot;,&quot;ICATAC_PLOSNITA&quot;,&quot;ICCONTINUT_ULEI&quot;,&quot;ICACIDITATE&quot;) AS
SELECT &quot;CODBCAR&quot;,&quot;OPERAT&quot;,&quot;CODCANTARIN&quot;,&quot;CODCANTAROUT&quot;,&quot;TIPDOC&quot;,&quot;CODDOC1&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;PREFIXAVIZIN&quot;,&quot;NRAVIZIN&quot;,&quot;NRAVIZOUT&quot;,&quot;DATAAVIZIN&quot;,&quot;ISUMIDITATE&quot;,&quot;IAUMIDITATE&quot;,&quot;ISSTRAINE&quot;,&quot;IASTRAINE&quot;,&quot;ISINCOLTIT&quot;,&quot;IAINCOLTIT&quot;,&quot;ISHECTOLITRICA&quot;,&quot;IAHECTOLITRICA&quot;,&quot;ISGLUTEN&quot;,&quot;IAGLUTEN&quot;,&quot;ISFUZARITATE&quot;,&quot;IAFUZARITATE&quot;,&quot;ISCADERE&quot;,&quot;IACADERE&quot;,&quot;ISDEFORMARE&quot;,&quot;IADEFORMARE&quot;,&quot;ISSTICLOZITATE&quot;,&quot;IASTICLOZITATE&quot;,&quot;ISSPARTURI&quot;,&quot;IASPARTURI&quot;,&quot;CODOBIECT&quot;,&quot;BRUTKG&quot;,&quot;TARA&quot;,&quot;NETKG&quot;,&quot;UTILKG&quot;,&quot;PRETACHIZ&quot;,&quot;PRETUSCARE&quot;,&quot;CODPARTENER&quot;,&quot;CODSEDIU&quot;,&quot;CODDELEGAT&quot;,&quot;CODSUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODSERIE&quot;,&quot;RETUR&quot;,&quot;MODCANTAR&quot;,&quot;USERIDBLOCAJ&quot;,&quot;TIPBCAR&quot;,&quot;CODGESTIMPL&quot;,&quot;CODLOCATIMPL&quot;,&quot;OBSERVATII&quot;,&quot;CODPERS&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;CODAUTO&quot;,&quot;ICUMIDITATE&quot;,&quot;ICSTRAINE&quot;,&quot;ICINCOLTIT&quot;,&quot;ICHECTOLITRICA&quot;,&quot;ICGLUTEN&quot;,&quot;ICFUZARITATE&quot;,&quot;ICCADERE&quot;,&quot;ICDEFORMARE&quot;,&quot;ICSTICLOZITATE&quot;,&quot;ICSPARTURI&quot;,&quot;NETKGCLIENT&quot;,&quot;UTILKGCLIENT&quot;,&quot;INFOCLIENT&quot;,&quot;CODDOC1STORNO&quot;,&quot;CODBCARDEST&quot;,&quot;CODCONTRACT1&quot;,&quot;NRREMORCA&quot;,&quot;CODREMORCA&quot;,&quot;UTILSTASKG&quot;,&quot;PRETCONFIRMAT&quot;,&quot;ISPROTEINA&quot;,&quot;ISAFLATOXINA&quot;,&quot;ISATAC_PLOSNITA&quot;,&quot;ISCONTINUT_ULEI&quot;,&quot;ISACIDITATE&quot;,&quot;IAPROTEINA&quot;,&quot;IAAFLATOXINA&quot;,&quot;IAATAC_PLOSNITA&quot;,&quot;IACONTINUT_ULEI&quot;,&quot;IAACIDITATE&quot;,&quot;ICPROTEINA&quot;,&quot;ICAFLATOXINA&quot;,&quot;ICATAC_PLOSNITA&quot;,&quot;ICCONTINUT_ULEI&quot;,&quot;ICACIDITATE&quot;
FROM BCAR
WHERE CODBCAR = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_BUGETEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>73508A64C03C662973D33C5E554B954C59137643</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_BUGETEMF (
&quot;CODBUGETMF&quot;,&quot;CODMIFIX&quot;,&quot;USERID&quot;,&quot;SUBUNITATEA&quot;,&quot;DATACREARE&quot;) AS
select &quot;CODBUGETMF&quot;,&quot;CODMIFIX&quot;,&quot;USERID&quot;,&quot;SUBUNITATEA&quot;,&quot;DATACREARE&quot;
from BUGETMF
where CODBUGETMF = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_CANTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2EE83E8C404B8F651B117C291295AE1C889925F0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_CANTAR (
&quot;CODCANTAR&quot;,&quot;CODOBIECT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATE&quot;,&quot;NRAVIZ&quot;) AS
SELECT CODCANTAR, CODOBIECT, AN, LUNA, SUBUNITATE, NRAVIZ
FROM CANTAR
WHERE CODCANTAR = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_CC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35CF150C651F83A280303076BF95545673C90257</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_CC (
&quot;CODCENTRU&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;TIPCHELT&quot;,&quot;TIPALOC&quot;,&quot;TIP&quot;,&quot;INACTIV&quot;,&quot;DOMENIU&quot;) AS
select &quot;CODCENTRU&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;TIPCHELT&quot;,&quot;TIPALOC&quot;,&quot;TIP&quot;,&quot;INACTIV&quot;,&quot;DOMENIU&quot;
    from centrecost
WHERE codcentru = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_CERTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DF95B351AA656E78CF2A769E18B097FA764E13AD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_CERTIF (
&quot;CODCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;DATAPRIMIRE&quot;,&quot;FISIER&quot;,&quot;CODPART&quot;,&quot;CODOBIECT&quot;,&quot;CODSERIE&quot;,&quot;NUMEFISIER&quot;,&quot;EXT&quot;,&quot;SUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODTARA&quot;,&quot;PROVENIENTA&quot;,&quot;OBS&quot;,&quot;TIPPART&quot;) AS
select &quot;CODCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;DATAPRIMIRE&quot;,&quot;FISIER&quot;,&quot;CODPART&quot;,&quot;CODOBIECT&quot;,&quot;CODSERIE&quot;,&quot;NUMEFISIER&quot;,&quot;EXT&quot;,&quot;SUBUNITATE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODTARA&quot;,&quot;PROVENIENTA&quot;,&quot;OBS&quot;,&quot;TIPPART&quot; from certif where codcertif = pkg_globals.GET_RECID_DOC_LISTARE 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87745E90CB7F564F667FC995FE000D2E5A2C2E14</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_COMANDA (
&quot;CODCOMANDA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;VALOARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;CODCONTRACT&quot;,&quot;CODCMDPARINTE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;VALDISCOUNT&quot;,&quot;CODLOCATIE&quot;,&quot;SUBUNITATEA&quot;,&quot;CODFISCAL&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODGEST&quot;,&quot;INCHISA&quot;,&quot;SUBUNITSURSA&quot;,&quot;SCADENTAV&quot;,&quot;SERIADOC&quot;,&quot;USERIDBLOCAJ&quot;,&quot;NRI&quot;,&quot;CODTRASEULIVR&quot;,&quot;ORDINELIVRARE&quot;,&quot;MIJLTRANSP&quot;,&quot;INSOTITOR&quot;,&quot;DISPLIVRARE&quot;,&quot;VERIFICAT&quot;,&quot;CODIES&quot;,&quot;FARATRANSPORT&quot;,&quot;PLATAPELOC&quot;,&quot;DATAINREG&quot;,&quot;FACTURABIL&quot;,&quot;CURS&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;LISTAT&quot;,&quot;FACTURA_APL_EXT&quot;,&quot;CODPERS_APL_EXT&quot;,&quot;LOT&quot;,&quot;NRTRANSP&quot;,&quot;CODIESAVANS&quot;,&quot;FARAFACTURA&quot;,&quot;DINONLINE&quot;,&quot;PRETCUAMANUNT&quot;,&quot;CODANALIZA&quot;,&quot;TIPTRANZACTIE&quot;,&quot;SUBUNITDEST&quot;,&quot;NRMAXAPROBARI&quot;,&quot;STADIUWMS&quot;,&quot;CODPERSC&quot;) AS
SELECT &quot;CODCOMANDA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;VALOARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;CODCONTRACT&quot;,&quot;CODCMDPARINTE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;VALDISCOUNT&quot;,&quot;CODLOCATIE&quot;,&quot;SUBUNITATEA&quot;,&quot;CODFISCAL&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODGEST&quot;,&quot;INCHISA&quot;,&quot;SUBUNITSURSA&quot;,&quot;SCADENTAV&quot;,&quot;SERIADOC&quot;,&quot;USERIDBLOCAJ&quot;,&quot;NRI&quot;,&quot;CODTRASEULIVR&quot;,&quot;ORDINELIVRARE&quot;,&quot;MIJLTRANSP&quot;,&quot;INSOTITOR&quot;,&quot;DISPLIVRARE&quot;,&quot;VERIFICAT&quot;,&quot;CODIES&quot;,&quot;FARATRANSPORT&quot;,&quot;PLATAPELOC&quot;,&quot;DATAINREG&quot;,&quot;FACTURABIL&quot;,&quot;CURS&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;LISTAT&quot;,&quot;FACTURA_APL_EXT&quot;,&quot;CODPERS_APL_EXT&quot;,&quot;LOT&quot;,&quot;NRTRANSP&quot;,&quot;CODIESAVANS&quot;,&quot;FARAFACTURA&quot;,&quot;DINONLINE&quot;,&quot;PRETCUAMANUNT&quot;,&quot;CODANALIZA&quot;,&quot;TIPTRANZACTIE&quot;,&quot;SUBUNITDEST&quot;,&quot;NRMAXAPROBARI&quot;,&quot;STADIUWMS&quot;,&quot;CODPERSC&quot;
FROM COMANDA
WHERE CODCOMANDA = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AEA32F2CEA9BB430DA195E7FBB992D997FA04E1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_COMPENS (
&quot;CODCOMPENS&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;PARTD&quot;,&quot;PARTC&quot;,&quot;OBSD&quot;,&quot;OBSC&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODGEST&quot;,&quot;TIPCOMPENS&quot;,&quot;CODCENTRU&quot;,&quot;AGENT&quot;,&quot;CODANALIZA&quot;,&quot;CODTIPPARTINCERT&quot;) AS
SELECT &quot;CODCOMPENS&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;PARTD&quot;,&quot;PARTC&quot;,&quot;OBSD&quot;,&quot;OBSC&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODGEST&quot;,&quot;TIPCOMPENS&quot;,&quot;CODCENTRU&quot;,&quot;AGENT&quot;,&quot;CODANALIZA&quot;,&quot;CODTIPPARTINCERT&quot;
FROM COMPENS
WHERE
  codcompens = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_CONTRACTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82AA4233C8C2E7279239AA0DCBD674E53A637C8D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_CONTRACTE (
&quot;CODCONTRACT&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;ACTIV&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;TIPCONTRACT&quot;,&quot;TIPTARGET&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;CODPERSC&quot;,&quot;MONEDA&quot;,&quot;PERTARGET&quot;,&quot;NRLUNI&quot;,&quot;PERFACT&quot;,&quot;ZIFACT&quot;,&quot;PROCMAJ&quot;,&quot;PERCITIRE&quot;,&quot;ZICITIRE&quot;,&quot;TRANSPPART&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;AGENT&quot;,&quot;CURS&quot;,&quot;AVANS&quot;,&quot;DOBANDA&quot;,&quot;TIPDOBANDA&quot;,&quot;CALCDOBANDA&quot;,&quot;REZIDUALA&quot;,&quot;REZIDUALASEPARAT&quot;,&quot;FACTLEI&quot;,&quot;ASIGANUAL&quot;,&quot;LUNIGRATIE&quot;,&quot;GRATIEFARADOB&quot;,&quot;CODBANCA&quot;,&quot;PROCMAJCURS&quot;,&quot;AUTOPRELUNGIRE&quot;,&quot;LUNIPRELUNGIRE&quot;,&quot;TIPARTICOL&quot;,&quot;TIPUM&quot;,&quot;TIPTARGETV&quot;,&quot;SEMNAT&quot;,&quot;EXPLICATII&quot;,&quot;STOPAJ&quot;,&quot;SUMA1&quot;,&quot;DISCOUNT1&quot;,&quot;SUMA2&quot;,&quot;DISCOUNT2&quot;,&quot;SUMA3&quot;,&quot;DISCOUNT3&quot;,&quot;SUMA4&quot;,&quot;DISCOUNT4&quot;,&quot;NRI&quot;,&quot;CASS&quot;,&quot;CODANALIZA&quot;,&quot;MAXREPLSIMULTANE&quot;,&quot;MAXZILEREPLA&quot;) AS
SELECT &quot;CODCONTRACT&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;ACTIV&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;TIPCONTRACT&quot;,&quot;TIPTARGET&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;CODPERSC&quot;,&quot;MONEDA&quot;,&quot;PERTARGET&quot;,&quot;NRLUNI&quot;,&quot;PERFACT&quot;,&quot;ZIFACT&quot;,&quot;PROCMAJ&quot;,&quot;PERCITIRE&quot;,&quot;ZICITIRE&quot;,&quot;TRANSPPART&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;AGENT&quot;,&quot;CURS&quot;,&quot;AVANS&quot;,&quot;DOBANDA&quot;,&quot;TIPDOBANDA&quot;,&quot;CALCDOBANDA&quot;,&quot;REZIDUALA&quot;,&quot;REZIDUALASEPARAT&quot;,&quot;FACTLEI&quot;,&quot;ASIGANUAL&quot;,&quot;LUNIGRATIE&quot;,&quot;GRATIEFARADOB&quot;,&quot;CODBANCA&quot;,&quot;PROCMAJCURS&quot;,&quot;AUTOPRELUNGIRE&quot;,&quot;LUNIPRELUNGIRE&quot;,&quot;TIPARTICOL&quot;,&quot;TIPUM&quot;,&quot;TIPTARGETV&quot;,&quot;SEMNAT&quot;,&quot;EXPLICATII&quot;,&quot;STOPAJ&quot;,&quot;SUMA1&quot;,&quot;DISCOUNT1&quot;,&quot;SUMA2&quot;,&quot;DISCOUNT2&quot;,&quot;SUMA3&quot;,&quot;DISCOUNT3&quot;,&quot;SUMA4&quot;,&quot;DISCOUNT4&quot;,&quot;NRI&quot;,&quot;CASS&quot;,&quot;CODANALIZA&quot;,&quot;MAXREPLSIMULTANE&quot;,&quot;MAXZILEREPLA&quot;
from contract
where codcontract = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_DEVIZ_UTILAJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C9135728CBC1E19333404AB06B87277A1D6A13E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_DEVIZ_UTILAJ (
&quot;CODUTILAJ20&quot;,&quot;CODUTILAJ&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DESCRIERE&quot;,&quot;STARE&quot;,&quot;OPERATOR&quot;,&quot;OBS&quot;,&quot;CODIES&quot;,&quot;CODLOCALIT&quot;,&quot;ADRESA&quot;) AS
select
  CODUTILAJ20,
  CODUTILAJ,
  NRDOC,
  DATADOC,
  DESCRIERE,
  STARE,
  OPERATOR,
  OBS,
  CODIES,
  CODLOCALIT,
  ADRESA
from utilaje20
where CODUTILAJ20 = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_DVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2D88DFB6898E5B7863496EC1FD2286F874757C7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_DVI (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;COMPLEX&quot;,&quot;SATELIT&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPTVA&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;NRI&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;DELEGAT&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;FARAREG&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODAUTO&quot;,&quot;PRORATA&quot;,&quot;CODCONTRACT&quot;,&quot;CODANALIZA&quot;,&quot;TVAINCASARE&quot;,&quot;TVAINCASARE_F&quot;,&quot;CURSDOC&quot;,&quot;TRANSPORTATOR&quot;,&quot;VALTRANSPORT&quot;,&quot;CUSTODIE&quot;,&quot;FACTSIMPLIF&quot;,&quot;AGENT&quot;,&quot;CURSNIR&quot;,&quot;STADIUWMS&quot;,&quot;DATAREFSCAD&quot;,&quot;AUTOFACTURARE&quot;) AS
SELECT &quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;COMPLEX&quot;,&quot;SATELIT&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPTVA&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;NRI&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;DELEGAT&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;FARAREG&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODAUTO&quot;,&quot;PRORATA&quot;,&quot;CODCONTRACT&quot;,&quot;CODANALIZA&quot;,&quot;TVAINCASARE&quot;,&quot;TVAINCASARE_F&quot;,&quot;CURSDOC&quot;,&quot;TRANSPORTATOR&quot;,&quot;VALTRANSPORT&quot;,&quot;CUSTODIE&quot;,&quot;FACTSIMPLIF&quot;,&quot;AGENT&quot;,&quot;CURSNIR&quot;,&quot;STADIUWMS&quot;,&quot;DATAREFSCAD&quot;,&quot;AUTOFACTURARE&quot;
FROM INTRARI
WHERE
codintr = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_EMULARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>323A74A6EDD68EC4B0B90EE4F2A3471F1B24C924</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_EMULARE (
&quot;CODEMULARE&quot;,&quot;NRBON&quot;,&quot;DATABON&quot;,&quot;VALOARE&quot;,&quot;VALOAREDISCOUNT&quot;,&quot;LISTAT&quot;,&quot;PRELUAT&quot;,&quot;CODCASAMARCAT&quot;,&quot;TVATOTAL&quot;,&quot;TVADISCOUNT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DATALISTARE&quot;,&quot;CODIES&quot;,&quot;CODPART&quot;,&quot;INCASARECLIENT&quot;,&quot;CODMONETAR&quot;,&quot;CODPERS&quot;,&quot;CODPOSTRETAIL&quot;,&quot;CODAECUSTODIE&quot;,&quot;CODLOCATIE&quot;,&quot;CODAGENT&quot;,&quot;OBS&quot;,&quot;CODRESTNP&quot;,&quot;CODPARTCOMIS&quot;,&quot;TEXTNEFISCAL&quot;,&quot;FACTSIMPLIF&quot;,&quot;IDBON&quot;,&quot;FACTURARE&quot;,&quot;DELEGAT&quot;,&quot;EXCLUSDISCOUNT&quot;,&quot;CODPARTRETAIL&quot;,&quot;CODIESRETAIL&quot;,&quot;CODSEDIURETAIL&quot;,&quot;PUNCTECUMUL&quot;,&quot;VALPUNCTECUMUL&quot;) AS
SELECT &quot;CODEMULARE&quot;,&quot;NRBON&quot;,&quot;DATABON&quot;,&quot;VALOARE&quot;,&quot;VALOAREDISCOUNT&quot;,&quot;LISTAT&quot;,&quot;PRELUAT&quot;,&quot;CODCASAMARCAT&quot;,&quot;TVATOTAL&quot;,&quot;TVADISCOUNT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DATALISTARE&quot;,&quot;CODIES&quot;,&quot;CODPART&quot;,&quot;INCASARECLIENT&quot;,&quot;CODMONETAR&quot;,&quot;CODPERS&quot;,&quot;CODPOSTRETAIL&quot;,&quot;CODAECUSTODIE&quot;,&quot;CODLOCATIE&quot;,&quot;CODAGENT&quot;,&quot;OBS&quot;,&quot;CODRESTNP&quot;,&quot;CODPARTCOMIS&quot;,&quot;TEXTNEFISCAL&quot;,&quot;FACTSIMPLIF&quot;,&quot;IDBON&quot;,&quot;FACTURARE&quot;,&quot;DELEGAT&quot;,&quot;EXCLUSDISCOUNT&quot;,&quot;CODPARTRETAIL&quot;,&quot;CODIESRETAIL&quot;,&quot;CODSEDIURETAIL&quot;,&quot;PUNCTECUMUL&quot;,&quot;VALPUNCTECUMUL&quot;
FROM EMULARE
WHERE codemulare = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_EVIDENTAMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>296E8DE6FE1DD8567B2993734D7FFF54E21AE412</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_EVIDENTAMF (
&quot;CODMIFIX&quot;,&quot;TIP&quot;,&quot;NRINVENTAR&quot;,&quot;ANINTRARE&quot;,&quot;LUNAINTRARE&quot;,&quot;OBS&quot;,&quot;ANINTRAREG&quot;,&quot;LUNAINTRAREG&quot;,&quot;SERIEINV&quot;,&quot;CODMIFIXIMB&quot;,&quot;RESTIMBMF&quot;) AS
select CODMIFIX,TIP,NRINVENTAR,ANINTRARE,LUNAINTRARE,OBS,ANINTRAREG,LUNAINTRAREG,SERIEINV,CODMIFIXIMB,RESTIMBMF
from MIFIX
WHERE CODMIFIX = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_EXPERT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC4E23FE499D5E1C630DD3B0CA01144579EA6B03</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_EXPERT (
&quot;CODEXPERT&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DIRTY&quot;,&quot;CODANALIZA&quot;) AS
SELECT &quot;CODEXPERT&quot;,&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DIRTY&quot;,&quot;CODANALIZA&quot;
FROM EXPERT WHERE codExpert = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_FAZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1C98F4B86EFDEBB6A4E3FD9AC6F90749BEB7D538</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_FAZ (
&quot;CODFAZ&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;DENUMIRE&quot;,&quot;NRINREG&quot;,&quot;DEN_SUBUNIT&quot;,&quot;SOFER&quot;,&quot;KMPLECARE&quot;,&quot;KMSOSIRE&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;) AS
SELECT
  FZ.CodFAZ, FZ.NrDoc, FZ.DataDoc, OBJ.Denumire, AUTO.NrInreg, SUB.Den_Subunit,
  (select STRAGG3200(distinct p.nume||&apos; &apos;||p.prenume)
   from faz0
        inner join npers p on p.codpers = faz0.codpers
   where faz0.codfaz = fz.codfaz
  ) Sofer,
  FZ.KmPlecare, FZ.kmSosire, FZ.Operat, FZ.Blocat, FZ.Anulat
FROM FAZ FZ
  INNER JOIN NPARCAUT  AUTO ON FZ.CodAuto = AUTO.CodNParcAut
  INNER JOIN NARTOBJ    OBJ ON OBJ.CodObiect = AUTO.CodArt
  INNER JOIN NSUBUNIT   SUB ON SUB.CodSubunit = FZ.Subunitatea
  LEFT  JOIN NPERS        S ON S.CODPERS = FZ.CodPers
WHERE FZ.CODFAZ = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E4C3C0713892B4E9AC5FB95DF23C8EE3325A35A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_IESIRI (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;VALDISCOUNT&quot;,&quot;TVADISCOUNT&quot;,&quot;CONTDISCOUNT&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;CONTINTERMED&quot;,&quot;TIPTVA&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPCONSUMATOR&quot;,&quot;CODAUTO&quot;,&quot;PARTCUSTODIE&quot;,&quot;CODCMDINTERNA&quot;,&quot;CODPERS&quot;,&quot;COMISION&quot;,&quot;CODBANKCONT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;LISTAT&quot;,&quot;INFOCM&quot;,&quot;CURSDOC&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;MONEDATRANSF&quot;,&quot;NRI&quot;,&quot;CONTSUPLIM&quot;,&quot;DATAINREG&quot;,&quot;CUSTODIE&quot;,&quot;FARATRANSPORT&quot;,&quot;TIPCHELT&quot;,&quot;CARNETCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;SERIACERTIF&quot;,&quot;STARERESTITUIRE&quot;,&quot;IDIMPORT&quot;,&quot;LISTATCERTIF&quot;,&quot;FARAREG&quot;,&quot;CODPERSC&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODIESMAMB&quot;,&quot;PROCTVADOC&quot;,&quot;CODANALIZA&quot;,&quot;CODAECUSTODIE&quot;,&quot;TVAINCASARE&quot;,&quot;DATATVA&quot;,&quot;CODCONTRACT&quot;,&quot;FACTSIMPLIF&quot;,&quot;TRANSPORTATOR&quot;,&quot;STADIUWMS&quot;,&quot;CODMONETAR&quot;,&quot;NUMARBONURI&quot;,&quot;EMISADECLIENT&quot;,&quot;CANTPREL&quot;) AS
SELECT DISTINCT
&quot;CODIES&quot;,
&quot;TIPDOC&quot;,
&quot;ANULAT&quot;,
&quot;BLOCAT&quot;,
&quot;OPERAT&quot;,
&quot;PREFIXDOC&quot;,
&quot;CARNETDOC&quot;,
&quot;NRDOC&quot;,
&quot;DATADOC&quot;,
&quot;PARTENER&quot;,
&quot;CARNETAE&quot;,
&quot;NRAE&quot;,
&quot;VALDOC&quot;,
&quot;TVADOC&quot;,
&quot;VALDISCOUNT&quot;,
&quot;TVADISCOUNT&quot;,
&quot;CONTDISCOUNT&quot;,
&quot;ACCIZE&quot;,
&quot;DELEGAT&quot;,
&quot;AGENT&quot;,
&quot;MAJORARI&quot;,
&quot;OBS&quot;,
&quot;AN&quot;,
&quot;LUNA&quot;,
&quot;INITIALIZARI&quot;,
&quot;CODSUBUNIT&quot;,
&quot;CODFISCAL&quot;,
&quot;SERIADOC&quot;,
&quot;BUGETARE&quot;,
&quot;CODLOCATIE&quot;,
&quot;TIPFACTURA&quot;,
&quot;CODGESTPROD&quot;,
&quot;CONTINTERMED&quot;,&quot;TIPTVA&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPCONSUMATOR&quot;,&quot;CODAUTO&quot;,&quot;PARTCUSTODIE&quot;,&quot;CODCMDINTERNA&quot;,&quot;CODPERS&quot;,&quot;COMISION&quot;,&quot;CODBANKCONT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;LISTAT&quot;,&quot;INFOCM&quot;,&quot;CURSDOC&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;MONEDATRANSF&quot;,&quot;NRI&quot;,&quot;CONTSUPLIM&quot;,&quot;DATAINREG&quot;,&quot;CUSTODIE&quot;,&quot;FARATRANSPORT&quot;,&quot;TIPCHELT&quot;,&quot;CARNETCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;SERIACERTIF&quot;,&quot;STARERESTITUIRE&quot;,&quot;IDIMPORT&quot;,&quot;LISTATCERTIF&quot;,&quot;FARAREG&quot;,&quot;CODPERSC&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODIESMAMB&quot;,&quot;PROCTVADOC&quot;,&quot;CODANALIZA&quot;,&quot;CODAECUSTODIE&quot;,&quot;TVAINCASARE&quot;,&quot;DATATVA&quot;,&quot;CODCONTRACT&quot;,&quot;FACTSIMPLIF&quot;,&quot;TRANSPORTATOR&quot;,&quot;STADIUWMS&quot;,&quot;CODMONETAR&quot;,&quot;NUMARBONURI&quot;,&quot;EMISADECLIENT&quot;,
CASE
  WHEN I.TIPDOC = 23 THEN
 (SELECT NVL(SUM(INTR1.CANT), 0) FROM INTRARI INTR, INTRARI1 INTR1  WHERE INTR.SUBUNITATEA = I.CODSUBUNIT AND INTR.NRDOC = I.NRDOC AND ( INTR.SERIADOC IS NULL OR (I.SERIADOC = INTR.SERIADOC))
 AND INTR1.CODINTR = INTR.CODINTR AND INTR.TIPDOC = 6)
 ELSE 0
END AS CANTPREL
FROM IESIRI I
WHERE
 codies = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C488C84CD24D52FDE670177D00B8576191630316</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_INTRARI (
&quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;COMPLEX&quot;,&quot;SATELIT&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPTVA&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;NRI&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;DELEGAT&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;FARAREG&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODAUTO&quot;,&quot;PRORATA&quot;,&quot;CODCONTRACT&quot;,&quot;CODANALIZA&quot;,&quot;TVAINCASARE&quot;,&quot;TVAINCASARE_F&quot;,&quot;CURSDOC&quot;,&quot;TRANSPORTATOR&quot;,&quot;VALTRANSPORT&quot;,&quot;CUSTODIE&quot;,&quot;FACTSIMPLIF&quot;,&quot;AGENT&quot;,&quot;CURSNIR&quot;,&quot;STADIUWMS&quot;,&quot;DATAREFSCAD&quot;,&quot;AUTOFACTURARE&quot;) AS
SELECT DISTINCT &quot;CODINTR&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;NRAVIZ&quot;,&quot;CARNETDOC&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;MAJORARI&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;COMPLEX&quot;,&quot;SATELIT&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPTVA&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;NRI&quot;,&quot;SCHIMB&quot;,&quot;CODFORMATIE&quot;,&quot;IDIMPORT&quot;,&quot;DELEGAT&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;FARAREG&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODAUTO&quot;,&quot;PRORATA&quot;,&quot;CODCONTRACT&quot;,&quot;CODANALIZA&quot;,&quot;TVAINCASARE&quot;,&quot;TVAINCASARE_F&quot;,&quot;CURSDOC&quot;,&quot;TRANSPORTATOR&quot;,&quot;VALTRANSPORT&quot;,&quot;CUSTODIE&quot;,&quot;FACTSIMPLIF&quot;,&quot;AGENT&quot;,&quot;CURSNIR&quot;,&quot;STADIUWMS&quot;,&quot;DATAREFSCAD&quot;,&quot;AUTOFACTURARE&quot;
FROM INTRARI
WHERE
codintr = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_LANSARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>390B3E2A93CCBF90A90A7AD274EA2FB7B4C558E9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_LANSARI (
&quot;CODLANSARE&quot;,&quot;CODCMD1&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;CANT&quot;,&quot;CODPROIECT&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;ANULAT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;AUTOMAT&quot;,&quot;CODSCENARIU&quot;,&quot;OBS&quot;) AS
SELECT  &quot;CODLANSARE&quot;,&quot;CODCMD1&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;CANT&quot;,&quot;CODPROIECT&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;ANULAT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;AUTOMAT&quot;,&quot;CODSCENARIU&quot;,&quot;OBS&quot;
from lansare
where codlansare = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7F81B4B7C36B4E40838C08C8F3ED9CCA3AE9E360</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_LOCMUNCA (
&quot;CODLOC&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;TIP&quot;,&quot;DSV&quot;,&quot;TIPSTRING&quot;) AS
SELECT
  CodLoc, Simbol, Denumire, Tip, DSV,
  CASE
    WHEN Tip = 0 then &apos;Manual&apos;
    WHEN Tip = 1 then &apos;Mijloc fix&apos;
    WHEN Tip = 2 then &apos;Utilaj&apos;
    ELSE &apos; &apos;
  END TipString
FROM
  LOCMUNCA
WHERE
 codloc = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_MARIRI_DIMIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A72D7C05D95CF88E1371D863C37132A573FDD1E0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_MARIRI_DIMIN (
&quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;VALDISCOUNT&quot;,&quot;TVADISCOUNT&quot;,&quot;CONTDISCOUNT&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;CONTINTERMED&quot;,&quot;TIPTVA&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPCONSUMATOR&quot;,&quot;CODAUTO&quot;,&quot;PARTCUSTODIE&quot;,&quot;CODCMDINTERNA&quot;,&quot;CODPERS&quot;,&quot;COMISION&quot;,&quot;CODBANKCONT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;LISTAT&quot;,&quot;INFOCM&quot;,&quot;CURSDOC&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;MONEDATRANSF&quot;,&quot;NRI&quot;,&quot;CONTSUPLIM&quot;,&quot;DATAINREG&quot;,&quot;CUSTODIE&quot;,&quot;FARATRANSPORT&quot;,&quot;TIPCHELT&quot;,&quot;CARNETCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;SERIACERTIF&quot;,&quot;STARERESTITUIRE&quot;,&quot;IDIMPORT&quot;,&quot;LISTATCERTIF&quot;,&quot;FARAREG&quot;,&quot;CODPERSC&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODIESMAMB&quot;,&quot;PROCTVADOC&quot;,&quot;CODANALIZA&quot;,&quot;CODAECUSTODIE&quot;,&quot;TVAINCASARE&quot;,&quot;DATATVA&quot;,&quot;CODCONTRACT&quot;,&quot;FACTSIMPLIF&quot;,&quot;TRANSPORTATOR&quot;,&quot;STADIUWMS&quot;,&quot;CODMONETAR&quot;,&quot;NUMARBONURI&quot;,&quot;EMISADECLIENT&quot;) AS
SELECT  &quot;CODIES&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PARTENER&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;VALDISCOUNT&quot;,&quot;TVADISCOUNT&quot;,&quot;CONTDISCOUNT&quot;,&quot;ACCIZE&quot;,&quot;DELEGAT&quot;,&quot;AGENT&quot;,&quot;MAJORARI&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;INITIALIZARI&quot;,&quot;CODSUBUNIT&quot;,&quot;CODFISCAL&quot;,&quot;SERIADOC&quot;,&quot;BUGETARE&quot;,&quot;CODLOCATIE&quot;,&quot;TIPFACTURA&quot;,&quot;CODGESTPROD&quot;,&quot;CONTINTERMED&quot;,&quot;TIPTVA&quot;,&quot;SUBUNITATEA&quot;,&quot;TIPCONSUMATOR&quot;,&quot;CODAUTO&quot;,&quot;PARTCUSTODIE&quot;,&quot;CODCMDINTERNA&quot;,&quot;CODPERS&quot;,&quot;COMISION&quot;,&quot;CODBANKCONT&quot;,&quot;TIPCASAMARCAT&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPTRANZACTIE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;LISTAT&quot;,&quot;INFOCM&quot;,&quot;CURSDOC&quot;,&quot;DISCVOL&quot;,&quot;DISCTER&quot;,&quot;MONEDATRANSF&quot;,&quot;NRI&quot;,&quot;CONTSUPLIM&quot;,&quot;DATAINREG&quot;,&quot;CUSTODIE&quot;,&quot;FARATRANSPORT&quot;,&quot;TIPCHELT&quot;,&quot;CARNETCERTIF&quot;,&quot;NRCERTIF&quot;,&quot;SERIACERTIF&quot;,&quot;STARERESTITUIRE&quot;,&quot;IDIMPORT&quot;,&quot;LISTATCERTIF&quot;,&quot;FARAREG&quot;,&quot;CODPERSC&quot;,&quot;EXCLUSPLATA&quot;,&quot;CODIESMAMB&quot;,&quot;PROCTVADOC&quot;,&quot;CODANALIZA&quot;,&quot;CODAECUSTODIE&quot;,&quot;TVAINCASARE&quot;,&quot;DATATVA&quot;,&quot;CODCONTRACT&quot;,&quot;FACTSIMPLIF&quot;,&quot;TRANSPORTATOR&quot;,&quot;STADIUWMS&quot;,&quot;CODMONETAR&quot;,&quot;NUMARBONURI&quot;,&quot;EMISADECLIENT&quot;
FROM IESIRI
WHERE
codies = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A9A6E117525DCE331F825A0B9D7FFC22B119E53</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_MIFIX (
&quot;CODNIRSTOC&quot;,&quot;PRET&quot;,&quot;DEN_OBJ&quot;,&quot;DEN_GEST&quot;,&quot;CODGEST&quot;,&quot;DEN_IOART&quot;,&quot;DATANIR&quot;,&quot;STOC&quot;,&quot;DETALIULUNA&quot;,&quot;REZOLVAT&quot;,&quot;OK&quot;,&quot;DEN_SUBUNIT&quot;,&quot;CODSUBUNIT&quot;) AS
SELECT
    CODNIRSTOC,
    PRET,
    DENUMIRE DEN_OBJ,
    DEN_GEST,
    CODGEST,
    DEN_IOART,
    DATANIR,
    STOC,
    DETALIULUNA,
    REZOLVAT,
    CASE
       WHEN MIFIX.STOC = MIFIX.REZOLVAT THEN 1
       ELSE 0
    END
    AS OK,
    DEN_SUBUNIT,
    CODSUBUNIT
     FROM
   (
      SELECT
         NS.CODNIRSTOC,
         NS.PRET,
         O.DENUMIRE,
         G.DEN_GEST,
         G.CODGEST,
         IO.DEN_IOART,
         N.DATANIR,
         PKG_INTRARI.GET_REST_STOC_IN_LUNA(NS.CODNIRSTOC, PKG_GLOBALS.GetANLUCRU, PKG_GLOBALS.GetLUNALUCRU) AS STOC,
         NVL((SELECT SUM(CANT) FROM  MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GetANLUCRU AND LUNASTART = PKG_GLOBALS.GetLUNALUCRU  AND STARE IN (1, 2, 5)), 0) AS REZOLVAT,
         NVL((SELECT COUNT(*) FROM  MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GetANLUCRU AND LUNASTART = PKG_GLOBALS.GetLUNALUCRU ), 0) AS DETALIULUNA,
         SUB.DEN_SUBUNIT,
         SUB.CODSUBUNIT
      FROM
        NIRSTOC NS,
         NIR    N,
         NGEST  G,
         NSUBUNIT SUB,
         NARTOBJ O,
         IOART IO
      WHERE
        N.CODNIR = NS.CODNIR AND
        EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) &lt;= PKG_GLOBALS.GetANLUCRU * 12 + PKG_GLOBALS.GetLUNALUCRU AND
        NS.CODIOART = IO.CODIOART AND
        N.GEST = G.CODGEST AND
        NS.CODOBIECT = O.CODOBIECT AND
        SUB.CODSUBUNIT = G.CODSUBUNIT
  ) MIFIX
    WHERE
     ((STOC &lt;&gt; 0) OR (STOC = 0 AND REZOLVAT &lt;&gt; 0)OR(STOC = 0 AND REZOLVAT = 0 AND DETALIULUNA &gt; 0))
     AND CODNIRSTOC = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_MISCARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2B6C2B2C00A0531D53E9452556435BD947284B0B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_MISCARI (
&quot;CODTRANSF&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;DELEGAT&quot;,&quot;CODPART&quot;,&quot;TIPMODIFPRET&quot;,&quot;STORNO&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;CODGESTCMD&quot;,&quot;LISTAT&quot;,&quot;REEVALUARE&quot;,&quot;SERIADOC&quot;,&quot;IDIMPORT&quot;,&quot;CODANALIZA&quot;,&quot;AJUSTVALSTOC&quot;,&quot;STADIUWMS&quot;,&quot;SUBUNITDEST&quot;) AS
SELECT &quot;CODTRANSF&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALSUPLIM&quot;,&quot;CONTSUPLIM&quot;,&quot;TIPREPSUPLIM&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;DELEGAT&quot;,&quot;CODPART&quot;,&quot;TIPMODIFPRET&quot;,&quot;STORNO&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;CODGESTCMD&quot;,&quot;LISTAT&quot;,&quot;REEVALUARE&quot;,&quot;SERIADOC&quot;,&quot;IDIMPORT&quot;,&quot;CODANALIZA&quot;,&quot;AJUSTVALSTOC&quot;,&quot;STADIUWMS&quot;,&quot;SUBUNITDEST&quot;
FROM TRANSF
WHERE
 codtransf = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D0834CA4C53B3075DF93F0E1FB542935F21F0282</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NART (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;CODPRODUCATOR&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;CODVAMAL&quot;,&quot;MASA&quot;,&quot;VOLUM&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;LUNIGARANTIE&quot;,&quot;OBS&quot;,&quot;PROCADAOSNIR&quot;,&quot;ROTUNJIRE&quot;,&quot;ADAOSEXCEPTIE&quot;,&quot;PROMOTIE&quot;,&quot;ROTVALUTA&quot;,&quot;DENUMIRE&quot;,&quot;UMAMBALARE&quot;,&quot;PRETMINIM&quot;,&quot;TERMENPLATA&quot;,&quot;DATAADAUGARII&quot;,&quot;CODPLU&quot;,&quot;USESTOCMED&quot;,&quot;DURMAXAPROV&quot;,&quot;CODCNAS&quot;,&quot;CODCARACT&quot;,&quot;BLOCAT&quot;,&quot;DISCPROMO&quot;,&quot;TARAORIGINE&quot;,&quot;ZILEVALABIL&quot;,&quot;ZILEDISTRIB&quot;,&quot;CODPERISABIL&quot;,&quot;NEFACTURABIL&quot;) AS
select &quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;CODPRODUCATOR&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;CODVAMAL&quot;,&quot;MASA&quot;,&quot;VOLUM&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;LUNIGARANTIE&quot;,&quot;OBS&quot;,&quot;PROCADAOSNIR&quot;,&quot;ROTUNJIRE&quot;,&quot;ADAOSEXCEPTIE&quot;,&quot;PROMOTIE&quot;,&quot;ROTVALUTA&quot;,&quot;DENUMIRE&quot;,&quot;UMAMBALARE&quot;,&quot;PRETMINIM&quot;,&quot;TERMENPLATA&quot;,&quot;DATAADAUGARII&quot;,&quot;CODPLU&quot;,&quot;USESTOCMED&quot;,&quot;DURMAXAPROV&quot;,&quot;CODCNAS&quot;,&quot;CODCARACT&quot;,&quot;BLOCAT&quot;,&quot;DISCPROMO&quot;,&quot;TARAORIGINE&quot;,&quot;ZILEVALABIL&quot;,&quot;ZILEDISTRIB&quot;,&quot;CODPERISABIL&quot;,&quot;NEFACTURABIL&quot; from nartobj where codarticol = pkg_globals.GET_RECID_DOC_LISTARE 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C598AE630F4D4E23B3801C0E048DF9A44C1516E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NC (
&quot;CODNC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PART&quot;,&quot;JURNALTVA&quot;,&quot;TIPTRANZ&quot;,&quot;TIPTVA&quot;,&quot;VALOARE&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SABLON&quot;,&quot;CARNETDOC&quot;,&quot;CODANALIZA&quot;) AS
SELECT &quot;CODNC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PART&quot;,&quot;JURNALTVA&quot;,&quot;TIPTRANZ&quot;,&quot;TIPTVA&quot;,&quot;VALOARE&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SABLON&quot;,&quot;CARNETDOC&quot;,&quot;CODANALIZA&quot;
FROM NC
WHERE codnc = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EDFFAE4A9887F356ED7507E349C4491D65EBEC58</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NGEST (
&quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;SIMBOL&quot;,&quot;CODCLASA&quot;,&quot;CODACTIVIT&quot;,&quot;CODCONT&quot;,&quot;CODCATPRET&quot;,&quot;CODGESTIONAR&quot;,&quot;CUSTODIE&quot;,&quot;CODSUBUNIT&quot;,&quot;VERDISPLIVR&quot;,&quot;VERDISPLIVRTRANSF&quot;,&quot;VERDISPLIVRSUBUNIT&quot;,&quot;VERNIR&quot;,&quot;VERNIRTRANSF&quot;,&quot;VERNIRSUBUNIT&quot;,&quot;TIP&quot;,&quot;GMASTER&quot;,&quot;NRSCHIMBURI&quot;,&quot;ORESCHIMB&quot;,&quot;ORASTART&quot;,&quot;COEFCHELTMAT&quot;,&quot;COEFCHELTMAN&quot;,&quot;VEREMULARE&quot;,&quot;CODPOSTRETAIL&quot;,&quot;ANALITICCONT&quot;,&quot;CANTITATE&quot;,&quot;INACTIV&quot;,&quot;VERFACTIES&quot;,&quot;VERCHITANTA&quot;,&quot;CODCAENSEC&quot;,&quot;CODGESTTR&quot;) AS
SELECT &quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;SIMBOL&quot;,&quot;CODCLASA&quot;,&quot;CODACTIVIT&quot;,&quot;CODCONT&quot;,&quot;CODCATPRET&quot;,&quot;CODGESTIONAR&quot;,&quot;CUSTODIE&quot;,&quot;CODSUBUNIT&quot;,&quot;VERDISPLIVR&quot;,&quot;VERDISPLIVRTRANSF&quot;,&quot;VERDISPLIVRSUBUNIT&quot;,&quot;VERNIR&quot;,&quot;VERNIRTRANSF&quot;,&quot;VERNIRSUBUNIT&quot;,&quot;TIP&quot;,&quot;GMASTER&quot;,&quot;NRSCHIMBURI&quot;,&quot;ORESCHIMB&quot;,&quot;ORASTART&quot;,&quot;COEFCHELTMAT&quot;,&quot;COEFCHELTMAN&quot;,&quot;VEREMULARE&quot;,&quot;CODPOSTRETAIL&quot;,&quot;ANALITICCONT&quot;,&quot;CANTITATE&quot;,&quot;INACTIV&quot;,&quot;VERFACTIES&quot;,&quot;VERCHITANTA&quot;,&quot;CODCAENSEC&quot;,&quot;CODGESTTR&quot;
 FROM NGEST
 WHERE
   CODGEST = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A2848CA2CF2F7E539BADD7D75C70D369B1BD40BA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NOTECREDIT (
&quot;CODNCREDIT&quot;,&quot;NRDOC&quot;,&quot;SERIADOC&quot;,&quot;CODCONTRACT2&quot;,&quot;CODPART&quot;,&quot;TIPDOC&quot;,&quot;DEN_PART&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;CONTRACT&quot;,&quot;AN&quot;,&quot;LUNA&quot;) AS
SELECT
    NC.CODNCREDIT,
    NC.NrDoc, NC.SeriaDoc,
    NC.CODCONTRACT2,
    NC.CODPART,
    NC.TIPDOC,
    P.DEN_PART,
    NC.DataStart,
    NC.DataStop,
    C.NRDOC Contract,
    NC.An,
    NC.Luna
  FROM
    NOTECREDIT NC
    INNER JOIN NPART P ON NC.CODPART = P.CODPART
    LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
    LEFT JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
  WHERE
    nvl(NC.Subunitatea, 1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(NC.Subunitatea,1),pkg_globals.GETSUBUNITATE)
    and nc.codncredit = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NOTECREDIT_CU_DIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>121CE40B713385AF024C32DA254EBEFD5E1BD936</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NOTECREDIT_CU_DIF (
&quot;CODNCREDIT&quot;,&quot;NRDOC&quot;,&quot;SERIADOC&quot;,&quot;CODCONTRACT2&quot;,&quot;CODPART&quot;,&quot;TIPDOC&quot;,&quot;DEN_PART&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CONTRACT&quot;,&quot;DIFERENTE&quot;,&quot;CORECTIE&quot;) AS
SELECT
  CODNCREDIT, NRDOC, SERIADOC, CODCONTRACT2, CODPART, TIPDOC, DEN_PART , DATASTART, DATASTOP,
  AN, LUNA, CONTRACT, DIFERENTE, CORECTIE
from
( select
  NC.CODNCREDIT, NC.NrDoc, NC.SeriaDoc,
  NC.CODCONTRACT2,
  NC.CODPART,
  NC.TIPDOC,
  P.DEN_PART,
  NC.DataStart,
  NC.DataStop,
  NC.AN, NC.LUNA,
  case
    when NVL(C.CodContract, 0) = 0 then
    case when nvl(CC.codcontract,0) = 0 then &apos;...fara...&apos;
    else CC.NRDOC||&apos;/&apos;||to_char(CC.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(CC.DataStop, &apos;DD.MM.YYYY&apos;) end
    else C.NRDOC||&apos;/&apos;||to_char(C.DataStart, &apos;DD.MM.YYYY&apos;)||&apos;-&apos;||to_char(C.DataStop, &apos;DD.MM.YYYY&apos;)
  end Contract,
  case
    when nc.corectie = 1 then - ROUND(NVL(Rep.Valoare, 0) + NVL(Facturat.Valoare, 0), 2)
    else ROUND(NVL(Rep.Valoare, 0) - NVL(Facturat.Valoare, 0) - NVL(COR.Valoare, 0), 2)
  end DIFERENTE,
  nvl(NC.Corectie,0) Corectie
FROM
  NOTECREDIT NC
  INNER JOIN NPART P ON NC.CODPART = P.CODPART
  LEFT  JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
  LEFT  JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
  LEFT  JOIN CONTRACT CC ON NC.CODCONTRACT = CC.CODCONTRACT
  LEFT  JOIN (SELECT NC.CODNCREDIT, SUM(nvl(NC1.VALOARE,0) - nvl(NC1.VALOAREOLD,0)) VALOARE
              FROM NOTECREDIT NC
                   INNER JOIN NOTECREDIT1 NC1 ON NC.CODNCREDIT = NC1.CODNCREDIT
              GROUP BY NC.CODNCREDIT) REP ON REP.CODNCREDIT = NC.CODNCREDIT
  LEFT  JOIN (SELECT CODNCREDIT, SUM(COALESCE(VALOARE,0)) VALOARE FROM
              (
              SELECT NCF.CODNCREDIT, SUM(NCF.VALDOC) VALOARE
              FROM NOTECREDIT NC
                   INNER JOIN NOTECREDITFACT NCF ON NCF.CODNCREDIT = NC.CODNCREDIT
                   INNER JOIN IESIRI1 I1 ON NCF.CODDOC1 = I1.CODIES1
                   INNER JOIN IESIRI I ON I.CODIES = I1.CODIES AND NCF.TIPDOC = I.TIPDOC
              GROUP BY NCF.CODNCREDIT
              UNION ALL
              SELECT NCF.CODNCREDIT, SUM(NCF.VALDOC) VALOARE
              FROM NOTECREDIT NC
                   INNER JOIN NOTECREDITFACT NCF ON NCF.CODNCREDIT = NC.CODNCREDIT
                   INNER JOIN IESIRI I ON NCF.CODDOC = I.CODIES AND NCF.TIPDOC = I.TIPDOC
              GROUP BY NCF.CODNCREDIT
              UNION ALL
              SELECT NCF.CODNCREDIT, SUM(NCF.VALDOC) VALOARE
              FROM NOTECREDIT NC
                   INNER JOIN NOTECREDITFACT NCF ON NCF.CODNCREDIT = NC.CODNCREDIT
                   INNER JOIN INTRARI1 I1 ON NCF.CODDOC1 = I1.CODINTR1
                   INNER JOIN INTRARI I ON I.CODINTR = I1.CODINTR AND NCF.TIPDOC = I.TIPDOC
              GROUP BY NCF.CODNCREDIT
              UNION ALL
              SELECT NCF.CODNCREDIT, SUM(NCF.VALDOC) VALOARE
              FROM NOTECREDIT NC
                   INNER JOIN NOTECREDITFACT NCF ON NCF.CODNCREDIT = NC.CODNCREDIT
                   INNER JOIN INTRARI I ON NCF.CODDOC = I.CODINTR AND NCF.TIPDOC = I.TIPDOC
              GROUP BY NCF.CODNCREDIT
              )
              GROUP BY CODNCREDIT
             ) FACTURAT ON FACTURAT.CODNCREDIT = NC.CODNCREDIT
  LEFT  JOIN (SELECT COR.CODNCCORECTIE CODNCREDIT, SUM(NC1.VALOAREOLD - NC1.VALOARE) VALOARE
              FROM NOTECREDIT COR
                   INNER JOIN NOTECREDIT1 NC1 ON COR.CODNCREDIT = NC1.CODNCREDIT
              WHERE COR.CORECTIE = 1
              GROUP BY COR.CODNCCORECTIE) COR ON COR.CODNCREDIT = NC.CODNCREDIT
WHERE NC.Subunitatea = pkg_globals.GETSUBUNITATE_DOC AND ROUND(NVL(Rep.Valoare, 0) - NVL(Facturat.Valoare, 0) - NVL(COR.Valoare, 0), 2) &lt;&gt; 0 and nvl(NC.Corectie,0) in (0,2) )
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB32580B5D914935C541A81D71D26039AC06FCD9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NPART (
&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;REGCOM&quot;,&quot;CODEXTERN&quot;,&quot;CODMONEDA&quot;,&quot;AUTORIZATIE&quot;,&quot;CODINTERN&quot;,&quot;CODCLASA&quot;,&quot;CODCATEGPRET&quot;,&quot;TIPPART&quot;,&quot;SCADENTAC&quot;,&quot;SCADENTAV&quot;,&quot;DISCOUNT&quot;,&quot;CODCATEGDISC&quot;,&quot;BLOCAT&quot;,&quot;TIPPARTENER&quot;,&quot;DATAADAUGARII&quot;,&quot;OBS&quot;,&quot;POZA&quot;,&quot;PERSOANAFIZICA&quot;,&quot;VERFACT&quot;,&quot;VERDISPLIVR&quot;,&quot;COLDISCOUNT&quot;) AS
select &quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;REGCOM&quot;,&quot;CODEXTERN&quot;,&quot;CODMONEDA&quot;,&quot;AUTORIZATIE&quot;,&quot;CODINTERN&quot;,&quot;CODCLASA&quot;,&quot;CODCATEGPRET&quot;,&quot;TIPPART&quot;,&quot;SCADENTAC&quot;,&quot;SCADENTAV&quot;,&quot;DISCOUNT&quot;,&quot;CODCATEGDISC&quot;,&quot;BLOCAT&quot;,&quot;TIPPARTENER&quot;,&quot;DATAADAUGARII&quot;,&quot;OBS&quot;,&quot;POZA&quot;,&quot;PERSOANAFIZICA&quot;,&quot;VERFACT&quot;,&quot;VERDISPLIVR&quot;,&quot;COLDISCOUNT&quot; from npart where codpart = pkg_globals.GET_RECID_DOC_LISTARE 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_NPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35EFF579B75A53A6BCADE9D08C3C59F1EF4D255E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_NPERS (
&quot;CODPERS&quot;,&quot;MARCA&quot;,&quot;NUME&quot;,&quot;PRENUME&quot;,&quot;CNP&quot;,&quot;BISERIA&quot;,&quot;BINR&quot;,&quot;LOCNASTERE&quot;,&quot;ADRESA&quot;,&quot;PRENUMET&quot;,&quot;PRENUMEM&quot;,&quot;LOCALITN&quot;,&quot;DATAN&quot;,&quot;SCIVILA&quot;,&quot;SMILITAR&quot;,&quot;ACTIV&quot;,&quot;STRAINATATE&quot;,&quot;AGENT&quot;,&quot;DELEGAT&quot;,&quot;AGENDA&quot;,&quot;BIELIBERATDE&quot;,&quot;LADATADE&quot;,&quot;TARAN&quot;,&quot;CETATENIE&quot;,&quot;POZA&quot;,&quot;LOGONNAME&quot;,&quot;ACCMAS&quot;,&quot;COMISION&quot;,&quot;CODGEST&quot;,&quot;CODANALIZANOD&quot;,&quot;CODSUBUNIT&quot;) AS
select &quot;CODPERS&quot;,&quot;MARCA&quot;,&quot;NUME&quot;,&quot;PRENUME&quot;,&quot;CNP&quot;,&quot;BISERIA&quot;,&quot;BINR&quot;,&quot;LOCNASTERE&quot;,&quot;ADRESA&quot;,&quot;PRENUMET&quot;,&quot;PRENUMEM&quot;,&quot;LOCALITN&quot;,&quot;DATAN&quot;,&quot;SCIVILA&quot;,&quot;SMILITAR&quot;,&quot;ACTIV&quot;,&quot;STRAINATATE&quot;,&quot;AGENT&quot;,&quot;DELEGAT&quot;,&quot;AGENDA&quot;,&quot;BIELIBERATDE&quot;,&quot;LADATADE&quot;,&quot;TARAN&quot;,&quot;CETATENIE&quot;,&quot;POZA&quot;,&quot;LOGONNAME&quot;,&quot;ACCMAS&quot;,&quot;COMISION&quot;,&quot;CODGEST&quot;,&quot;CODANALIZANOD&quot;,&quot;CODSUBUNIT&quot;
from
  NPERS
where
  CODPERS = pkg_globals.GET_RECID_DOC_LISTARE

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_OFERTA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A01071286CB101C5665BE08AA6D62A18189E620</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_OFERTA (
&quot;CODOFERTA&quot;,&quot;TIPDOC&quot;,&quot;NRDOC&quot;,&quot;ANULAT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;) AS
SELECT O.CODOFERTA, O.TIPDOC, O.NRDOC, O.ANULAT, O.OPERAT, O.BLOCAT, O.An, O.Luna
FROM OFERTA O
WHERE O.CODOFERTA = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_OPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EF97A7E0D2A8386FE97137C08C8321E14479F377</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_OPORT (
&quot;CODOPORTUNITATE&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODCARNETDOC&quot;,&quot;CODPARTENER&quot;,&quot;CODMONEDA&quot;,&quot;TIP&quot;,&quot;CODAGENT&quot;,&quot;CODCAMPANIE&quot;,&quot;VENITEST&quot;,&quot;VENITPROB&quot;,&quot;CODSUBUNITATE&quot;,&quot;CODOFERTA&quot;,&quot;CODCOMANDA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;PROBVANZ&quot;,&quot;DATASEMNARE&quot;,&quot;CODCONTRACT&quot;,&quot;SERIADOC&quot;,&quot;CODLEAD&quot;,&quot;CODTASK&quot;) AS
select &quot;CODOPORTUNITATE&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODCARNETDOC&quot;,&quot;CODPARTENER&quot;,&quot;CODMONEDA&quot;,&quot;TIP&quot;,&quot;CODAGENT&quot;,&quot;CODCAMPANIE&quot;,&quot;VENITEST&quot;,&quot;VENITPROB&quot;,&quot;CODSUBUNITATE&quot;,&quot;CODOFERTA&quot;,&quot;CODCOMANDA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;PROBVANZ&quot;,&quot;DATASEMNARE&quot;,&quot;CODCONTRACT&quot;,&quot;SERIADOC&quot;,&quot;CODLEAD&quot;,&quot;CODTASK&quot;
from OPORTUNITATI
where CodOportunitate = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_OPREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95F2FB0951BC9968C9E0693BFF0953528C0213F0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_OPREG (
&quot;CODOP&quot;,&quot;CODPART&quot;,&quot;CODBANCA&quot;,&quot;OBS&quot;,&quot;TIPTRANZ&quot;,&quot;TIPDECONT&quot;,&quot;ZIDECONT&quot;,&quot;CODMONEDA&quot;,&quot;VALOARE&quot;,&quot;AN_START&quot;,&quot;LUNA_START&quot;,&quot;AN_MAX&quot;,&quot;LUNA_MAX&quot;,&quot;SUBUNITATEA&quot;) AS
select &quot;CODOP&quot;,&quot;CODPART&quot;,&quot;CODBANCA&quot;,&quot;OBS&quot;,&quot;TIPTRANZ&quot;,&quot;TIPDECONT&quot;,&quot;ZIDECONT&quot;,&quot;CODMONEDA&quot;,&quot;VALOARE&quot;,&quot;AN_START&quot;,&quot;LUNA_START&quot;,&quot;AN_MAX&quot;,&quot;LUNA_MAX&quot;,&quot;SUBUNITATEA&quot;
from
  OPREG
WHERE
  CODOP = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_ORDONANTARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>268187AC70A181052137E61B2C4B6F3B868383D0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_ORDONANTARI (
&quot;CODPLATA&quot;,&quot;DATA&quot;,&quot;CODBANKCONT&quot;,&quot;VALOARE&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;VALOAREDEREPARTIZAT&quot;,&quot;APROBAT&quot;,&quot;TIPDOC&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODANALIZA&quot;,&quot;OBS&quot;,&quot;CURS&quot;) AS
select
  CODPLATA,DATA,CODBANKCONT,VALOARE,CARNETDOC,NRDOC,AN,LUNA,
  SUBUNITATEA,VALOAREDEREPARTIZAT,APROBAT,TIPDOC,USERID,DATACREARE,
  CODANALIZA,OBS,CURS
from plati
where codplata = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B3E14E97E3D4BE43FFFA7A3248926C8A8CB14661</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PACHETE (
&quot;CODPACHETE&quot;,&quot;DATAP&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SUBUNITATE&quot;,&quot;GESTIUNE&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;COLECTOR&quot;,&quot;DATACOLECTARE&quot;,&quot;VERIFICATOR&quot;,&quot;DATAVERIFICARE&quot;,&quot;TRANSPORTATOR&quot;,&quot;DATATRANSPORT&quot;,&quot;NRPACHETE&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;IDENTIFICATORP&quot;,&quot;LISTAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CODPART&quot;,&quot;TIPPART&quot;,&quot;SEDIU&quot;,&quot;DELEGAT&quot;,&quot;TIPLIVRARE&quot;,&quot;TIPPACHET&quot;) AS
SELECT &quot;CODPACHETE&quot;,&quot;DATAP&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SUBUNITATE&quot;,&quot;GESTIUNE&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;COLECTOR&quot;,&quot;DATACOLECTARE&quot;,&quot;VERIFICATOR&quot;,&quot;DATAVERIFICARE&quot;,&quot;TRANSPORTATOR&quot;,&quot;DATATRANSPORT&quot;,&quot;NRPACHETE&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;IDENTIFICATORP&quot;,&quot;LISTAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CODPART&quot;,&quot;TIPPART&quot;,&quot;SEDIU&quot;,&quot;DELEGAT&quot;,&quot;TIPLIVRARE&quot;,&quot;TIPPACHET&quot;
from pachete
where
  codpachete = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4AFB9942CB1AE7479853FCAF7E672BC8A5223898</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PLANIFPROD (
&quot;CODPLANIFPROD&quot;,&quot;CODLANSPROD&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;SAPTAMANA&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;PREFIXDOC&quot;,&quot;INSAPTAMANA&quot;) AS
select &quot;CODPLANIFPROD&quot;,&quot;CODLANSPROD&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;SAPTAMANA&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;PREFIXDOC&quot;,&quot;INSAPTAMANA&quot;
  from planifprod
  where codplanifprod = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PLATI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3A7F9BD22EB034171EFB8759A2057AE4C2D298D5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PLATI (
&quot;CODPLATA&quot;,&quot;DATA&quot;,&quot;CODBANKCONT&quot;,&quot;VALOARE&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;SUBUNITATEA&quot;,&quot;VALOAREDEREPARTIZAT&quot;,&quot;APROBAT&quot;,&quot;TIPDOC&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;CODANALIZA&quot;,&quot;OBS&quot;,&quot;CURS&quot;) AS
SELECT DISTINCT
p.codplata,
    p.data,
    p.codbankcont,
    p.valoare,
    p.carnetdoc,
    p.nrdoc,
    p.an,
    p.luna,
    p.subunitatea,
    p.valoarederepartizat,
    p.aprobat,
    p.tipdoc,
    p.userid,
    p.datacreare,
    p.codanaliza,
    p.obs,
    p.curs
FROM PLATI P
WHERE
 CODPLATA = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PRECOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53B379FFA8223196545DE39ED35A4B545AB353AE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PRECOMENZI (
&quot;CODPRECOMANDA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;INCHISA&quot;,&quot;SERIADOC&quot;,&quot;VERIFICAT&quot;) AS
select
  CODPRECOMANDA,
  TIPDOC,
  ANULAT,
  BLOCAT,
  OPERAT,
  PREFIXDOC,
  NRDOC,
  CARNETDOC,
  DATADOC,
  VALOARE,
  AN,
  LUNA,
  OBS,
  MONEDA,
  SUBUNITATEA,
  USERID,
  DATACREARE,
  INCHISA,
  SERIADOC,
  VERIFICAT
from precomanda
where codprecomanda = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB51D2A840F9C1235D2E64D6373838902791BE15</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PRODCOMP (
&quot;CODPRODCOMP&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;,&quot;DATA&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;CANT&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;TIPRETETA&quot;,&quot;CANTUM1&quot;,&quot;PRET&quot;,&quot;COEFINDIRECTE&quot;,&quot;IMPLICIT&quot;,&quot;DESCRIERE&quot;,&quot;INACTIV&quot;,&quot;GEST&quot;,&quot;IDENTIFICATOR&quot;,&quot;DATADOCUMENTATIE&quot;,&quot;ARHIVA&quot;,&quot;OBSERVATII&quot;,&quot;PROIECTANT&quot;,&quot;CODCLASAPROD&quot;,&quot;INVIZIBILA&quot;,&quot;GENERIC&quot;,&quot;DURATA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;HFACTOR&quot;,&quot;VALMAT&quot;,&quot;VALMAN&quot;,&quot;VALREGIE&quot;,&quot;TIPPRET&quot;,&quot;CODPROIECT&quot;,&quot;OBS1&quot;,&quot;OBS2&quot;,&quot;OBS3&quot;,&quot;OBS4&quot;,&quot;OBS5&quot;,&quot;OBS6&quot;,&quot;CODMONEDA&quot;,&quot;PRETVALUTA&quot;,&quot;AG&quot;,&quot;VALAG&quot;,&quot;PROFIT&quot;,&quot;VALPROFIT&quot;,&quot;PRETFINAL&quot;,&quot;VALPROFITV&quot;,&quot;PRETFINALV&quot;,&quot;TOTPRETCOEF&quot;,&quot;TOTPRETFIX&quot;,&quot;TOTPRETCOEFV&quot;,&quot;TOTPRETFIXV&quot;,&quot;VALREGIEMAN&quot;) AS
select  &quot;CODPRODCOMP&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;,&quot;DATA&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;CANT&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;TIPRETETA&quot;,&quot;CANTUM1&quot;,&quot;PRET&quot;,&quot;COEFINDIRECTE&quot;,&quot;IMPLICIT&quot;,&quot;DESCRIERE&quot;,&quot;INACTIV&quot;,&quot;GEST&quot;,&quot;IDENTIFICATOR&quot;,&quot;DATADOCUMENTATIE&quot;,&quot;ARHIVA&quot;,&quot;OBSERVATII&quot;,&quot;PROIECTANT&quot;,&quot;CODCLASAPROD&quot;,&quot;INVIZIBILA&quot;,&quot;GENERIC&quot;,&quot;DURATA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;HFACTOR&quot;,&quot;VALMAT&quot;,&quot;VALMAN&quot;,&quot;VALREGIE&quot;,&quot;TIPPRET&quot;,&quot;CODPROIECT&quot;,&quot;OBS1&quot;,&quot;OBS2&quot;,&quot;OBS3&quot;,&quot;OBS4&quot;,&quot;OBS5&quot;,&quot;OBS6&quot;,&quot;CODMONEDA&quot;,&quot;PRETVALUTA&quot;,&quot;AG&quot;,&quot;VALAG&quot;,&quot;PROFIT&quot;,&quot;VALPROFIT&quot;,&quot;PRETFINAL&quot;,&quot;VALPROFITV&quot;,&quot;PRETFINALV&quot;,&quot;TOTPRETCOEF&quot;,&quot;TOTPRETFIX&quot;,&quot;TOTPRETCOEFV&quot;,&quot;TOTPRETFIXV&quot;,&quot;VALREGIEMAN&quot;
 from prodcomp
    where CODPRODCOMP =  pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PRODCOMP_COMANDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F843D70D9DAE87A32506C81CA841A7589AB26C2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PRODCOMP_COMANDA (
&quot;CODCOMANDA1&quot;,&quot;DENUMIRE&quot;,&quot;CODOBIECT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;TIPSTRINGRETETA&quot;) AS
select distinct c1.codcomanda1, obj.denumire, c1.codobiect, c.prefixdoc, c.nrdoc, c.datadoc, c.An,C.Luna,
       case
         when c1.consum = 1 then &apos;Agregare&apos;
         else &apos;Dezagregare&apos;
       end TipStringReteta
  from comanda1 c1
       inner join comanda c on c1.codcomanda = c.codcomanda
       inner join nartobj obj on c1.codobiect = obj.codobiect
       inner join cmdprodmat cmd on cmd.codcomanda1 = c1.codcomanda1
  where c.tipdoc = 53 and ((cmd.rest &gt; 0) or exists (select codliniecomanda from tmp_iesprodlink_initial where codliniecomanda = c1.codcomanda1))
  and c.codgest = pkg_nomgest.GET_GEST_CURENTA_LOCATII and nvl(c.anulat,0) = 0 and nvl(c.inchisa,0) = 0 and c.operat = 1 --and
--  c.datadoc &lt;= PKG_IESIRI.GETDATADOC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PRODCOMP_COMANDA_INTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4DFD710146283D9E30BC734305C58E72C5776859</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PRODCOMP_COMANDA_INTR (
&quot;CODCOMANDA1&quot;,&quot;DENUMIRE&quot;,&quot;CODOBIECT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;TIPSTRINGRETETA&quot;) AS
select c1.codcomanda1, obj.denumire, c1.codobiect, c.prefixdoc, c.nrdoc, c.datadoc, C.An, c.Luna,
       case
         when c1.consum = 1 then &apos;Agregare&apos;
         else &apos;Dezagregare&apos;
       end TipStringReteta
  from comanda1 c1
       inner join comanda c on c1.codcomanda = c.codcomanda
       left join nartobj obj on c1.codobiect = obj.codobiect
  where c.tipdoc = 53 and (pkg_comanda.sunt_prod_neintrate(c1.codcomanda1) &gt; 0 or
  exists (select codcomanda1 from tmp_intrprodlink_initial where codcomanda1 = c1.codcomanda1 ))
  and c.codgest = pkg_nomgest.GET_GEST_CURENTA_LOCATII and c.anulat &lt;&gt; 1 and c.inchisa &lt;&gt; 1 and c.operat = 1 and
  c.datadoc &lt;= PKG_IESIRI.GETDATADOC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>33466971109A1F76007329DF1B9CACB8CAF6F1DF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PROIECT (
&quot;CODPROIECT&quot;,&quot;CODVERSIUNE&quot;,&quot;CODOBIECTPROD&quot;,&quot;VERSIUNE&quot;,&quot;INTOCMITA&quot;,&quot;DATAPROIECT&quot;,&quot;CLASA&quot;,&quot;PROCESARE&quot;,&quot;COMPLEX&quot;,&quot;ACTIV&quot;,&quot;FINALIZAT&quot;,&quot;BLOCAT&quot;,&quot;INVIZIBILA&quot;,&quot;GENERIC&quot;,&quot;IMPLICIT&quot;,&quot;DURATA&quot;,&quot;MARJAORDINE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS1&quot;,&quot;OBS2&quot;,&quot;OBS3&quot;,&quot;OBS4&quot;,&quot;OBS5&quot;,&quot;OBS6&quot;,&quot;CODEXTERN&quot;) AS
select &quot;CODPROIECT&quot;,&quot;CODVERSIUNE&quot;,&quot;CODOBIECTPROD&quot;,&quot;VERSIUNE&quot;,&quot;INTOCMITA&quot;,&quot;DATAPROIECT&quot;,&quot;CLASA&quot;,&quot;PROCESARE&quot;,&quot;COMPLEX&quot;,&quot;ACTIV&quot;,&quot;FINALIZAT&quot;,&quot;BLOCAT&quot;,&quot;INVIZIBILA&quot;,&quot;GENERIC&quot;,&quot;IMPLICIT&quot;,&quot;DURATA&quot;,&quot;MARJAORDINE&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;OBS1&quot;,&quot;OBS2&quot;,&quot;OBS3&quot;,&quot;OBS4&quot;,&quot;OBS5&quot;,&quot;OBS6&quot;,&quot;CODEXTERN&quot;
  from proiect
  where CODPROIECT =  pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E495E44230EE79EA294E6DB3C8506A7B08916AC6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_PROMO (
&quot;CODPROMO&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATAEND&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;CODPERSC&quot;,&quot;MONEDA&quot;,&quot;TIPPROMOTIE&quot;,&quot;TIPCONDITIE&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPCLASEP&quot;,&quot;TIPSERVIRE&quot;,&quot;DEMANA&quot;,&quot;VALMIN&quot;,&quot;PRAGURI&quot;,&quot;CANTMIN&quot;,&quot;ORASTART&quot;,&quot;ORASTOP&quot;) AS
SELECT &quot;CODPROMO&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATAEND&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;CODPERSC&quot;,&quot;MONEDA&quot;,&quot;TIPPROMOTIE&quot;,&quot;TIPCONDITIE&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;TIPCLASEP&quot;,&quot;TIPSERVIRE&quot;,&quot;DEMANA&quot;,&quot;VALMIN&quot;,&quot;PRAGURI&quot;,&quot;CANTMIN&quot;,&quot;ORASTART&quot;,&quot;ORASTOP&quot;
FROM PROMO
WHERE CODPROMO = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_RAPORTP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FEF78AE200289ADA3C97ED1DC734557E33EF57AF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_RAPORTP (
&quot;CODRAPORTP&quot;,&quot;NRDOC&quot;,&quot;DATAI&quot;,&quot;DATAS&quot;,&quot;PE_FORMATIE&quot;,&quot;SECTIE&quot;,&quot;FORMATIE&quot;,&quot;PROGRAMF&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;INTRERUPERI&quot;,&quot;CODCENTRU&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;SCHIMB&quot;) AS
SELECT &quot;CODRAPORTP&quot;,&quot;NRDOC&quot;,&quot;DATAI&quot;,&quot;DATAS&quot;,&quot;PE_FORMATIE&quot;,&quot;SECTIE&quot;,&quot;FORMATIE&quot;,&quot;PROGRAMF&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;INTRERUPERI&quot;,&quot;CODCENTRU&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;SERIADOC&quot;,&quot;SCHIMB&quot;
FROM RAPORTP
WHERE CODRAPORTP = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5A1A0FBC54439761B2848CB7884DA6CBB5CBB705</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_RECLAMATII (
&quot;CODDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;TIPDOC&quot;,&quot;NRDOC&quot;,&quot;SERIADOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;CODSUBUNIT&quot;,&quot;CODUTILIZATOR&quot;,&quot;MOTIV&quot;,&quot;RECLAMATIE&quot;,&quot;CODPART&quot;,&quot;CODDOCR&quot;,&quot;TIPDOCR&quot;,&quot;REZOLVAT&quot;,&quot;DATAREZ&quot;,&quot;CODRESP&quot;,&quot;IMPUTABILA&quot;,&quot;TIPIMPUT&quot;,&quot;CODPIMPUT&quot;) AS
SELECT &quot;CODRECLAMATIE&quot; as CodDoc,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;TIPDOC&quot;,&quot;NRDOC&quot;,&quot;SERIADOC&quot;,&quot;DATADOC&quot;,&quot;CARNETDOC&quot;,&quot;CODSUBUNIT&quot;,&quot;CODUTILIZATOR&quot;,&quot;MOTIV&quot;,&quot;RECLAMATIE&quot;,&quot;CODPART&quot;,&quot;CODDOCR&quot;,&quot;TIPDOCR&quot;,&quot;REZOLVAT&quot;,&quot;DATAREZ&quot;,&quot;CODRESP&quot;,&quot;IMPUTABILA&quot;,&quot;TIPIMPUT&quot;,&quot;CODPIMPUT&quot;
FROM Reclamatii
WHERE
 codReclamatie = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_REG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A60C4755FA339EF4B33413010CFC58DB280F3400</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_REG (
&quot;CODREG&quot;,&quot;TIPREG&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODBANK&quot;,&quot;CODMONEDA&quot;,&quot;CURS&quot;,&quot;DIRTY&quot;,&quot;OBS&quot;,&quot;CODSUBUNIT&quot;,&quot;PROVIZION&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CODGEST&quot;,&quot;CODANALIZA&quot;,&quot;CODANALIZANOD&quot;,&quot;CODCENTRU&quot;,&quot;CURS_IFRS&quot;) AS
select &quot;CODREG&quot;,&quot;TIPREG&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODBANK&quot;,&quot;CODMONEDA&quot;,&quot;CURS&quot;,&quot;DIRTY&quot;,&quot;OBS&quot;,&quot;CODSUBUNIT&quot;,&quot;PROVIZION&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CODGEST&quot;,&quot;CODANALIZA&quot;,&quot;CODANALIZANOD&quot;,&quot;CODCENTRU&quot;,&quot;CURS_IFRS&quot;
FROM REG
WHERE CODREG = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_REGOSS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7903DDD49DC60DDA423E9D2EF61FDB7F0ACF1921</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_REGOSS (
&quot;CODREGOSS&quot;,&quot;TIPREG&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;TRIMESTRUL&quot;,&quot;CODBANK&quot;,&quot;CODMONEDA&quot;,&quot;CURS&quot;,&quot;DIRTY&quot;,&quot;OBS&quot;,&quot;CODSUBUNIT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;CODGEST&quot;,&quot;CODANALIZA&quot;,&quot;CODANALIZANOD&quot;,&quot;CODCENTRU&quot;,&quot;CURS_IFRS&quot;) AS
select CODREGOSS,
       TIPREG,
       NRDOC,
       DATADOC,
       TRIMESTRUL,
       CODBANK,
       CODMONEDA,
       CURS,
       DIRTY,
       OBS,
       CODSUBUNIT,
       AN,
       LUNA,
       CODGEST,
       CODANALIZA,
       CODANALIZANOD,
       CODCENTRU,
       CURS_IFRS
  FROM REGOSS
 WHERE CODREGOSS = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_SERTAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB28A6218A9380A697FC6F2F022AAF01E305BB57</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_SERTAR (
&quot;CODSERTAR&quot;,&quot;CODEMITENT&quot;,&quot;CODPARTENER&quot;,&quot;SUBUNITATE&quot;,&quot;TIP&quot;,&quot;DECONT&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;DATADECONT&quot;,&quot;DEPUS&quot;,&quot;DATACREARE&quot;,&quot;USERID&quot;,&quot;OBS&quot;,&quot;DATAOBLIG&quot;,&quot;BANCA&quot;,&quot;MONEDA&quot;) AS
SELECT  &quot;CODSERTAR&quot;,&quot;CODEMITENT&quot;,&quot;CODPARTENER&quot;,&quot;SUBUNITATE&quot;,&quot;TIP&quot;,&quot;DECONT&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;DATADECONT&quot;,&quot;DEPUS&quot;,&quot;DATACREARE&quot;,&quot;USERID&quot;,&quot;OBS&quot;,&quot;DATAOBLIG&quot;,&quot;BANCA&quot;,&quot;MONEDA&quot;
FROM NSERTAR
WHERE CODSERTAR = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_TASKURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CCFD4AC26582B6662DEB91ED4F464E04524CEC94</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_TASKURI (
&quot;CODTASK&quot;,&quot;PROBLEMA&quot;,&quot;DESTINATAR&quot;,&quot;EXECUTANT&quot;,&quot;USERNAME&quot;,&quot;TERMEN&quot;,&quot;DATATASK&quot;,&quot;DATAREZ&quot;,&quot;DOMENIU&quot;,&quot;TIP&quot;,&quot;REZOLVARE&quot;,&quot;OBSERVATII&quot;,&quot;PRIORITATE&quot;,&quot;DONE&quot;,&quot;MODIFICAT&quot;,&quot;MESAJCATRE&quot;,&quot;STERS&quot;,&quot;PROIECT&quot;) AS
select &quot;CODTASK&quot;,&quot;PROBLEMA&quot;,&quot;DESTINATAR&quot;,&quot;EXECUTANT&quot;,&quot;USERNAME&quot;,&quot;TERMEN&quot;,&quot;DATATASK&quot;,&quot;DATAREZ&quot;,&quot;DOMENIU&quot;,&quot;TIP&quot;,&quot;REZOLVARE&quot;,&quot;OBSERVATII&quot;,&quot;PRIORITATE&quot;,&quot;DONE&quot;,&quot;MODIFICAT&quot;,&quot;MESAJCATRE&quot;,&quot;STERS&quot;,&quot;PROIECT&quot;
    from table(winmadmin.pkg_userfirme.LIST_PIPE_SETTASK)
where codtask = pkg_globals.GET_RECID_DOC_LISTARE</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_TASKURILOCO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>241FB115519FDBF7C96BD9C4765E8F62C7C2A8E9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_TASKURILOCO (
&quot;CODTASK&quot;,&quot;PROBLEMA&quot;,&quot;DESTINATAR&quot;,&quot;EXECUTANT&quot;,&quot;USERNAME&quot;,&quot;TERMEN&quot;,&quot;DATATASK&quot;,&quot;DATAREZ&quot;,&quot;DOMENIU&quot;,&quot;TIP&quot;,&quot;REZOLVARE&quot;,&quot;OBSERVATII&quot;,&quot;PRIORITATE&quot;,&quot;DONE&quot;,&quot;MODIFICAT&quot;,&quot;MESAJCATRE&quot;,&quot;STERS&quot;,&quot;PROIECT&quot;) AS
select &quot;CODTASK&quot;,&quot;PROBLEMA&quot;,&quot;DESTINATAR&quot;,&quot;EXECUTANT&quot;,&quot;USERNAME&quot;,&quot;TERMEN&quot;,&quot;DATATASK&quot;,&quot;DATAREZ&quot;,&quot;DOMENIU&quot;,&quot;TIP&quot;,&quot;REZOLVARE&quot;,&quot;OBSERVATII&quot;,&quot;PRIORITATE&quot;,&quot;DONE&quot;,&quot;MODIFICAT&quot;,&quot;MESAJCATRE&quot;,&quot;STERS&quot;,&quot;PROIECT&quot;
    from SETTASK
where codtask = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9540F5ED9403248DCA5CFB15DD84A9EDD705402B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_TREZOR (
&quot;CODTREZOR&quot;,&quot;TIPDOC&quot;,&quot;CODBANCA&quot;,&quot;ICONTPERS&quot;,&quot;MONEDAPERS&quot;,&quot;DATADOC&quot;,&quot;NUMEDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;AGENT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DATAINREG&quot;,&quot;IDIMPORT&quot;,&quot;CODANALIZA&quot;) AS
SELECT &quot;CODTREZOR&quot;,&quot;TIPDOC&quot;,&quot;CODBANCA&quot;,&quot;ICONTPERS&quot;,&quot;MONEDAPERS&quot;,&quot;DATADOC&quot;,&quot;NUMEDOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;AGENT&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DATAINREG&quot;,&quot;IDIMPORT&quot;,&quot;CODANALIZA&quot;
FROM TREZOR
WHERE
codtrezor = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>87420712A0D1FB8D31F71A8B8275FFF93C1614E8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_UTILAJE (
&quot;CODUTILAJ&quot;,&quot;CODOBIECT&quot;,&quot;NRINVENTAR&quot;,&quot;ETICHETA&quot;,&quot;TIPUTILAJ&quot;,&quot;FLOTA&quot;,&quot;MODEL&quot;,&quot;ANF&quot;,&quot;SERIEF&quot;,&quot;INCARCARE&quot;,&quot;DATAGARANTIE&quot;,&quot;INGARANTIE&quot;,&quot;LUNGIME&quot;,&quot;LATIME&quot;,&quot;INALTIME&quot;,&quot;OBS&quot;,&quot;INACTIV&quot;,&quot;CORECTIEINDEX&quot;,&quot;UM&quot;,&quot;PLAFONCANTF&quot;,&quot;CODGEST&quot;,&quot;CODPART&quot;,&quot;CODIES1&quot;,&quot;DATAGARANTIEI&quot;,&quot;APROBAT&quot;,&quot;DATASTART&quot;,&quot;NRCONTR&quot;,&quot;DATACONTR&quot;,&quot;CODFURNIZOR&quot;,&quot;DOC&quot;,&quot;TIP&quot;,&quot;CODLOCALIT&quot;,&quot;ADRESA&quot;,&quot;HFACTOR&quot;,&quot;AGENT&quot;) AS
select &quot;CODUTILAJ&quot;,&quot;CODOBIECT&quot;,&quot;NRINVENTAR&quot;,&quot;ETICHETA&quot;,&quot;TIPUTILAJ&quot;,&quot;FLOTA&quot;,&quot;MODEL&quot;,&quot;ANF&quot;,&quot;SERIEF&quot;,&quot;INCARCARE&quot;,&quot;DATAGARANTIE&quot;,&quot;INGARANTIE&quot;,&quot;LUNGIME&quot;,&quot;LATIME&quot;,&quot;INALTIME&quot;,&quot;OBS&quot;,&quot;INACTIV&quot;,&quot;CORECTIEINDEX&quot;,&quot;UM&quot;,&quot;PLAFONCANTF&quot;,&quot;CODGEST&quot;,&quot;CODPART&quot;,&quot;CODIES1&quot;,&quot;DATAGARANTIEI&quot;,&quot;APROBAT&quot;,&quot;DATASTART&quot;,&quot;NRCONTR&quot;,&quot;DATACONTR&quot;,&quot;CODFURNIZOR&quot;,&quot;DOC&quot;,&quot;TIP&quot;,&quot;CODLOCALIT&quot;,&quot;ADRESA&quot;,&quot;HFACTOR&quot;,&quot;AGENT&quot;
    from utilaje
where CODUTILAJ =  pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LISTA_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B808F7E3307DD47CF430D246F1DD082F81D56563</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LISTA_VOUCHER (
&quot;CODDOC&quot;,&quot;OBS&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;VALOARE&quot;) AS
SELECT &quot;CODVOUCHER&quot; as CodDoc,
      &quot;OBS&quot;,
      &quot;DATASTART&quot;,
      &quot;DATASTOP&quot;,
      &quot;VALOARE&quot;
FROM VOUCHER
WHERE
 codVoucher = pkg_globals.GET_RECID_DOC_LISTARE
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_LIVRARI_SER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D025FBFDC2F494FC0407C9D436D4C46CEADC233F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_LIVRARI_SER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT L1.CODNIRSER, L1.CODNIRSTOC, -1 * NVL(L1.CANT,0) AS REST, -1 * NVL(L1.CANTUM1,0) AS RESTUM1, -1 * NVL(L1.CANTUM2,0) AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5
  AND L.DATALIVR &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC

UNION ALL

 -- IESIRI
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (14, 16, 19, 20, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5
  AND L.DATALIVR &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC

UNION ALL

 -- MISCARI INTERNE
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5
  AND L.DATALIVR &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC


UNION ALL

  -- MARIRI DE STOC
SELECT  L1.CODNIRSER, L1.CODNIRSTOC,  L1.CANT AS REST, L1.CANTUM1 AS RESTUM1, L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5
  AND L.DATALIVR &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_NIRURI_SER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>394522518F4BB3C869A88418D630D39CAEBABFBA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_NIRURI_SER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = N.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (19, 20, 21, 22, 23, 24, 25) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

-- NIR-uri din MISCARI INTERNE
SELECT  NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_PMP_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>549F6C7E5AD21CFD9F3A74D43030FC9209F1C72F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_PMP_IESIRI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
(
   SELECT * FROM
   (
      SELECT
           NS.CODOBIECT,
           G.CODSUBUNIT,
           (
           CASE
             WHEN (T.CODTRANSF IS NOT NULL)and
                  (T.TIPDOC between 12 and 13)             THEN -L1.CANT
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 14) THEN -L1.CANT
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN  L1.CANT
             WHEN I.CODINTR IS NOT NULL                    THEN -L1.CANT
             ELSE  0
           END)
           AS CANTINTR,
           CASE
             WHEN (T.CODTRANSF IS NOT NULL)and
                  (T.TIPDOC between 12 and 13)             THEN  (NS.PRET  - NVL(NS.ADAOS, 0)) * (-L1.CANT)
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 14) THEN  (NS.PRET  - NVL(NS.ADAOS, 0)) * (-L1.CANT)
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN  (NS.PRET  - NVL(NS.ADAOS, 0)) *   L1.CANT
             WHEN I.CODINTR IS NOT NULL                    THEN  (NS.PRET  - NVL(NS.ADAOS, 0)) * (-L1.CANT)
             ELSE 0
           END
           AS VALINTR,
           CASE
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT
             ELSE -L1.CANT
           END
           AS RESTLUNA,
          CASE
            WHEN I.CODINTR IS NOT NULL THEN I.AN
            WHEN E.CODIES IS NOT NULL THEN E.AN
            ELSE T.AN
          END AS AN,
          CASE
            WHEN I.CODINTR IS NOT NULL THEN I.LUNA
            WHEN E.CODIES IS NOT NULL THEN E.LUNA
            ELSE T.LUNA
          END AS LUNA,
          CASE
             WHEN (T.CODTRANSF IS NOT NULL)and
                  (T.TIPDOC between 12 and 13)             THEN  (NS.PUVAL) * (-L1.CANT)
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 14) THEN  (NS.PUVAL) * (-L1.CANT)
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN  (NS.PUVAL) *   L1.CANT
             WHEN I.CODINTR IS NOT NULL                    THEN  (NS.PUVAL) * (-L1.CANT)
             ELSE 0
           END
           AS VALVALUTA
      FROM
        LIVR1 L1,
        LIVR L
        LEFT OUTER JOIN IESIRI  E ON E.CODIES    = L.CODIES    AND E.TIPDOC = L.TIPLIVR
        LEFT OUTER JOIN INTRARI I ON I.CODINTR   = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
        LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR,
        NIRSTOC NS,
        TMP_IOART_LUNA IO,
        NIR N,
        NGEST G
      WHERE
       L1.CODLIVR = L.CODLIVR
       AND L.TipLivr IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
       AND NS.CODNIRSTOC = L1.CODNIRSTOC
       AND NS.CODIOART = IO.CODIOART
       AND IO.MG = 3
       AND N.CODNIR = NS.CODNIR
       AND N.GEST = G.CODGEST
       AND pkg_list_base_utils.EsteObiectValid(ns.codobiect) = 1
       AND  io.anstart * 12 + io.lunastart = (select max(io1.anstart*12+io1.lunastart) from ioart1 io1
                                              where io1.codioart = io.codioart and
                                              (io1.anstart*12+io1.lunastart) &lt;= (PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP)
                                            )
  ) WHERE
     AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY
CODOBIECT, CODSUBUNIT
-----
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_PMP_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7251EC9ED9035357EA622CA2BCEFC0793BA3F9B5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_PMP_INTRARI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
(
   SELECT * FROM
   (
   SELECT -- INTRARI IN STOC
     NS.CODOBIECT,
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
    (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR AS RESTLUNA,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.AN
       ELSE T.AN
     END AS AN,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.LUNA
       ELSE T.LUNA
     END AS LUNA,
     (NS.PUVAL) * NS.CANTNIR  AS VALVALUTA
   FROM
     NIRSTOC NS,
     NIR N
     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
     LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
     TMP_IOART_LUNA IO,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
     AND G.CODGEST = N.GEST
     AND pkg_list_base_utils.EsteObiectValid(ns.codobiect) = 1
     AND  io.anstart * 12 + io.lunastart = (select max(io1.anstart*12+io1.lunastart) from ioart1 io1
                                              where io1.codioart = io.codioart and
                                              (io1.anstart*12+io1.lunastart) &lt;= (PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP)
                                            )
  )
  WHERE
    AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_STOCSER_LUNA_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4F9C7A8AF0C44E35DE568446F220194A7239CB69</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_STOCSER_LUNA_PREC (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NL.CODNIRSER, NL.CODNIRSTOC, NL.REST, NL.RESTUM1, NL.RESTUM2
FROM
  NIRSERLUNA NL,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  NL.AN = PKG_GLOBALS.GETANPRECEDENT
  AND NL.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
  AND NL.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIVRARI_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10DEE1D1B19DDE423A40CED9981F7331F9AEDDEE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIVRARI_LUNA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST,  -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM INTRARI I
  INNER JOIN LIVR L ON L.CODINTR = I.CODINTR AND L.TIPLIVR = I.TIPDOC
  INNER JOIN LIVR1 L1 ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7)
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L.OPERAT = 1 AND L.ANULAT = 0
  AND Coalesce(N.OPERAT, 0) = 1
  AND IO.MG &lt;&gt; 5
UNION ALL
 -- IESIRI
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM IESIRI I
  INNER JOIN LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
  INNER JOIN LIVR1 L1 ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC IN (14, 16, 19, 20, 21, 23, 24)
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L.OPERAT = 1 AND L.ANULAT = 0
  AND Coalesce(N.OPERAT, 0) = 1
  AND IO.MG &lt;&gt; 5
UNION ALL
 -- MISCARI INTERNE
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM TRANSF T
  INNER JOIN LIVR L ON L.CODTRANSF = T.CODTRANSF AND L.TIPLIVR = T.TIPDOC
  INNER JOIN LIVR1 L1 ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE T.OPERAT = 1 AND T.ANULAT = 0 AND T.TIPDOC IN (12, 13)
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L.OPERAT = 1 AND L.ANULAT = 0
  AND Coalesce(N.OPERAT, 0) = 1
  AND IO.MG &lt;&gt; 5
UNION ALL
  -- MARIRI DE STOC
SELECT L1.CODNIRSTOC,  L1.CANT AS REST,  L1.CANTUM1 AS RESTUM1,  L1.CANTUM2 AS RESTUM2
FROM IESIRI I
  INNER JOIN LIVR L ON L.CODIES = I.CODIES AND L.TIPLIVR = I.TIPDOC
  INNER JOIN LIVR1 L1 ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC = 15
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L.OPERAT = 1 AND L.ANULAT = 0
  AND Coalesce(N.OPERAT, 0) = 1
  AND IO.MG &lt;&gt; 5</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIVRARI_LUNA_LA_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1A97368A4A603FCAFD9E06F28EB51A2AE58C9FAD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIVRARI_LUNA_LA_DATA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST,  -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L1.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5
UNION ALL
 -- IESIRI
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  L.TIPLIVR IN (14, 16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L1.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5
UNION ALL
 -- MISCARI INTERNE
SELECT L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L1.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5
UNION ALL
  -- MARIRI DE STOC
SELECT L1.CODNIRSTOC,  L1.CANT AS REST,  L1.CANTUM1 AS RESTUM1,  L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND L1.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIVRARI_SER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BCDB5C88D0A50BFCA4BB78EBF0CB08620E145812</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIVRARI_SER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

 -- IESIRI
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (14, 16, 19, 20, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

 -- MISCARI INTERNE
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5


UNION ALL

  -- MARIRI DE STOC
SELECT  L1.CODNIRSER, L1.CODNIRSTOC,  L1.CANT AS REST, L1.CANTUM1 AS RESTUM1, L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIVRARI_SER_LUNA_LADATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>552DBE725411A804229631F0EAA25BB70CAFC596</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIVRARI_SER_LUNA_LADATA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

 -- IESIRI
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (14, 16, 19, 20, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

 -- MISCARI INTERNE
SELECT  L1.CODNIRSER, L1.CODNIRSTOC, -1 * L1.CANT AS REST, -1 * L1.CANTUM1 AS RESTUM1, -1 * L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS  ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC AND
  T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5


UNION ALL

  -- MARIRI DE STOC
SELECT  L1.CODNIRSER, L1.CODNIRSTOC,  L1.CANT AS REST, L1.CANTUM1 AS RESTUM1, L1.CANTUM2 AS RESTUM2
FROM
  LIVR1 L1
  LEFT OUTER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NS.TIPSERIE &gt; 0 AND
  L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  L.DATALIVR &lt;= PKG_GLOBALS.GETDATACALCULSTOC AND
  I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LOCATIIPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C868D62425F91464AF83B6D0E472538D374C948E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LOCATIIPART (
&quot;CODAGENDA&quot;,&quot;OBS&quot;,&quot;CODAGENT&quot;,&quot;SEDIUSOCIAL&quot;,&quot;TRANSPCLIENT&quot;,&quot;ADRESALOCATIE&quot;,&quot;DEN_LOCALIT&quot;,&quot;AGENTIMPLICIT&quot;,&quot;CODPART&quot;,&quot;COD_CODFISCAL&quot;,&quot;TIP&quot;,&quot;CODCORESP&quot;,&quot;CODFISCAL&quot;,&quot;CODCLIENT&quot;,&quot;IDSEDIU&quot;,&quot;GESTLIVRARE&quot;,&quot;EMAIL&quot;,&quot;CODTRASEU&quot;,&quot;SSOC&quot;) AS
SELECT
   A.CODAGENDA,
   A.Obs,
   A.CODAGENT,
   A.SEDIUSOCIAL,
   A.TranspClient,
   GetAdresa (A.sector, A.strada, A.nr1, A.NR2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) AS ADRESALOCATIE,
   L.DEN_LOCALIT,
   P.Nume || &apos; &apos; || P.Prenume AS AGENTIMPLICIT,
   A.CodPart,
   A.COD_CODFISCAL,
   A.TIP,
   A.CODCORESP,
   CF.CODFISCAL AS CODFISCAL,
   A.CODCLIENT,
   A.IDSEDIU,
   A.GESTLIVRARE,
   A.EMAIL,
   A.Codtraseu,
   CASE
     WHEN A.SEDIUSOCIAL = 1 THEN &apos;L&apos;
     WHEN A.SEDIUSOCIAL = 2 THEN &apos;F&apos;
     WHEN A.SEDIUSOCIAL = 3 THEN &apos;L+F&apos;
     WHEN A.SEDIUSOCIAL = 4 THEN &apos;SS&apos;
     WHEN A.SEDIUSOCIAL = 5 THEN &apos;SS+L&apos;
     WHEN A.SEDIUSOCIAL = 6 THEN &apos;SS+F&apos;
     WHEN A.SEDIUSOCIAL = 7 THEN &apos;SS+L+F&apos;
     WHEN A.SEDIUSOCIAL = 9 THEN &apos;Livrare la beneficiar&apos;
   END SSOC
FROM
   NAGENDA A
   LEFT OUTER JOIN NPARTCODFISC CF ON CF.COD_CODFISCAL = A.COD_CODFISCAL
   LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
		 LEFT JOIN NPERS P ON P.CodPers = A.CodAgent
WHERE
  COALESCE(A.TIP,0) = 0 AND A.CODPART = PKG_NOMPART.GET_PART_CURENT_LOCATII AND Nvl(a.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 1) &lt;&gt; 0)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LOCATIIPARTRETAIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>937C0B1FF5C20B389F3E8470F2F680B527929153</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LOCATIIPARTRETAIL (
&quot;CODSEDIU&quot;,&quot;CODPARTRETAIL&quot;,&quot;DENUMIRE&quot;,&quot;CODLOCALIT&quot;,&quot;DENLOCALIT&quot;,&quot;CODJUDET&quot;,&quot;CODTARA&quot;,&quot;TELEFON&quot;,&quot;FAX&quot;,&quot;EMAIL&quot;,&quot;STRADA&quot;,&quot;NR1&quot;,&quot;NR2&quot;,&quot;BLOC&quot;,&quot;SCARA&quot;,&quot;ETAJ&quot;,&quot;APART&quot;,&quot;SECTOR&quot;,&quot;CODPOSTAL&quot;,&quot;SEDIUSOCIAL&quot;,&quot;CODAGENDA&quot;,&quot;ADRESASEDIU&quot;,&quot;TARA&quot;,&quot;UE&quot;) AS
SELECT
   A.CODSEDIU,
   A.CODPARTRETAIL,
   A.DENUMIRE,
   A.CODLOCALIT,
   A.DENLOCALIT,
   A.CODJUDET,
   A.CODTARA,
   A.TELEFON,
   A.FAX,
   A.EMAIL,
   A.STRADA,
   A.NR1,
   A.NR2,
   A.BLOC,
   A.SCARA,
   A.ETAJ,
   A.APART,
   A.SECTOR,
   A.CODPOSTAL,
   A.SEDIUSOCIAL,
   A.CODAGENDA,
   GetAdresa (A.sector, A.strada, A.nr1, A.NR2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) AS ADRESASEDIU,
   Coalesce(T.SIMBAUTO, &apos;RO&apos;)   Tara,
   Coalesce(T.STATCOMUNITAR, 0) UE
FROM
   nsediipartretail A
   LEFT JOIN NTARI T ON T.CODTARA = A.CODTARA
WHERE
  A.CODPARTRETAIL = PKG_NOMPART.GET_PART_CURENT_LOCATII AND (BITAND(A.SEDIUSOCIAL, 1) &lt;&gt; 0)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LOCATIIPART_PROMOOF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DC4E07591E2B5CC04D798181522E968FE4E41E14</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LOCATIIPART_PROMOOF (
&quot;CODAGENDA&quot;,&quot;OBS&quot;,&quot;CODAGENT&quot;,&quot;SEDIUSOCIAL&quot;,&quot;TRANSPCLIENT&quot;,&quot;ADRESALOCATIE&quot;,&quot;DEN_LOCALIT&quot;,&quot;AGENTIMPLICIT&quot;,&quot;CODPART&quot;) AS
SELECT A.CODAGENDA, A.Obs, A.CODAGENT, A.SEDIUSOCIAL, A.TranspClient,
  GetAdresa (A.sector, A.strada, A.nr1, A.NR2, A.bloc, A.scara, A.etaj, A.apart, A.codpostal) AS ADRESALOCATIE,
  L.DEN_LOCALIT, P.Nume || &apos; &apos; || P.Prenume AS AGENTIMPLICIT, A.CodPart
FROM NAGENDA A
     LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
     LEFT JOIN NPERS P ON P.CodPers = A.CodAgent
WHERE A.TIP = 0 AND A.CODPART = PKG_NOMPART.GET_PART_CURENT_LOCATII AND Nvl(a.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 1) &lt;&gt; 0)
  AND PKG_NOMPART.TIPSERVIRE_LOCATII_OK(A.ModServire) = 1
UNION ALL
SELECT 0 CodAgenda, &apos;TOATE&apos; Obs, 0 CodAGent, null SEDIUSOCIAL, 0 TranspClient,
  &apos;...nedefinit...&apos; AdresaLocatie,
  &apos;...nedefinit...&apos; DEN_LOCALIT, &apos;...nedefinit...&apos; AGENTIMPLICIT, PKG_NOMPART.GET_PART_CURENT_LOCATII CodPart
FROM DUAL
WHERE PKG_NOMPART.GET_PART_CURENT_LOCATII &lt;&gt; 0
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LOCATII_GESTIUNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7E8CCC8B7F0D5AC42B7D7953A72785E58A8CBEFD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LOCATII_GESTIUNE (
&quot;CODLOCATIE&quot;,&quot;CODGEST&quot;,&quot;DENUMIRE&quot;,&quot;INDEXLOCAL&quot;,&quot;NRCELULE&quot;,&quot;DESCRIERE&quot;,&quot;CODEXTERN&quot;,&quot;TIPLOCATIE&quot;,&quot;CODLOCFIXA&quot;,&quot;CODVECINLEFT&quot;,&quot;CODVECINRIGHT&quot;,&quot;COORDX&quot;,&quot;INACTIV&quot;) AS
SELECT &quot;CODLOCATIE&quot;,&quot;CODGEST&quot;,&quot;DENUMIRE&quot;,&quot;INDEXLOCAL&quot;, &quot;NRCELULE&quot;, &quot;DESCRIERE&quot;, &quot;CODEXTERN&quot;, &quot;TIPLOCATIE&quot;, &quot;CODLOCFIXA&quot;, &quot;CODVECINLEFT&quot;, &quot;CODVECINRIGHT&quot;,  &quot;COORDX&quot;, &quot;INACTIV&quot;
FROM NLOCATII
WHERE NVL(CODGEST,0) = 0
or
CODGEST = PKG_NOMGEST.GET_GEST_CURENTA_LOCATII
or
((PKG_NOMGEST.GET_Locatia_CURENTA &gt; 0)and (CODLOCATIE = PKG_NOMGEST.GET_Locatia_CURENTA))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LOCMUNCA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0C541430C0A8A612194B52F77C1764045F1BC56</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LOCMUNCA (
&quot;CODLOC&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;TIP&quot;,&quot;DSV&quot;,&quot;SPECIAL&quot;,&quot;TIPSTRING&quot;,&quot;FARA_GANT&quot;) AS
SELECT
  CodLoc, Simbol, Denumire, Tip, DSV,SPECIAL,
  CASE
    WHEN Tip = 0 then &apos;Manual&apos;
    WHEN Tip = 1 then &apos;Mijloc fix&apos;
    WHEN Tip = 2 then &apos;Utilaj&apos;
    ELSE &apos; &apos;
  END TipString, FARA_GANT
FROM
  LOCMUNCA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LST_LOCATIIPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F40F247680E3F42A512613A20D56E3BC28390DE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LST_LOCATIIPART (
&quot;CODAGENDA&quot;,&quot;DEN_PART&quot;,&quot;OBS&quot;) AS
SELECT a.codagenda, p.den_part, a.obs 
FROM nagenda a INNER JOIN npart p ON p.codpart = a.codpart 
WHERE a.tip = 0</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MANOPERAGANTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D994282EA9876C8372189F9AE995924ACD18ED14</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MANOPERAGANTT (
&quot;CODCOMANDA1&quot;,&quot;CODCOMANDA&quot;,&quot;CODGEST&quot;,&quot;CODLOC&quot;,&quot;CODRETETA&quot;,&quot;DEN_GEST&quot;,&quot;LOCMUNCA&quot;,&quot;ZILE&quot;,&quot;ZILEREST&quot;,&quot;ORE&quot;,&quot;OREREST&quot;,&quot;CODOPERATIE&quot;,&quot;REALIZAT&quot;,&quot;REBUTAT&quot;,&quot;REFACUT&quot;,&quot;IDXGEST&quot;,&quot;NRSCHIMBURI&quot;,&quot;ORESCHIMB&quot;,&quot;ORASTART&quot;,&quot;OPERATIE&quot;,&quot;TIPLM&quot;,&quot;TU&quot;,&quot;OREZI&quot;,&quot;IDX&quot;,&quot;NIVEL&quot;,&quot;DATASTART&quot;,&quot;LANSAT&quot;,&quot;DOCUMENT&quot;,&quot;DATADOC&quot;,&quot;DENOBIECT&quot;,&quot;DOCUMENTCLI&quot;,&quot;DEN_PART&quot;,&quot;RETETA&quot;,&quot;CANTACCEPTAT&quot;,&quot;RESTACCEPTAT&quot;,&quot;TERMEN&quot;,&quot;TERMENCC&quot;,&quot;DATADOCCC&quot;,&quot;UM&quot;,&quot;UMSEC&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;CANTUM1&quot;,&quot;UM1&quot;,&quot;DEN_UM1&quot;,&quot;RELATIEUM1&quot;,&quot;CANTPROD&quot;,&quot;CODCMDPRODMAN&quot;,&quot;REST&quot;,&quot;CODCOMANDACLI&quot;) AS
SELECT x.codcomanda1,
       x.codcomanda,
			 x.CodGest,
       x.CodLoc,
       x.CodReteta,
       x.Den_Gest,
       x.LocMunca,
       Round(x.tu / DECODE(NVL(x.OreZi, 0), 0, 8, x.OreZi) / 60 *
             x.cantacceptat / x.cantprod,
             5) zile,
       Round(x.tu / DECODE(NVL(x.OreZi, 0), 0, 8, x.OreZi) / 60 *
             (x.CantAcceptat - nvl(x.realizat, 0) + nvl(x.rebutat, 0)) /
             x.cantprod,
             5) ZileRest,
       Round(x.tu / 60 * (x.cantacceptat / x.cantprod), 5) Ore,
       Round(x.tu / 60 *
             (x.CantAcceptat - nvl(x.realizat, 0) + nvl(x.rebutat, 0)) /
             x.cantprod,
             5) OreRest,
       x.CodOperatie,
       x.realizat,
       x.rebutat,
       x.refacut,
       x.idxgest,
       x.nrschimburi,
       x.oreschimb, x.OraStart,
       x.operatie,
       x.tiplm,
       x.tu,
       x.orezi,
       x.Idx,
			 X.Nivel,
       x.DataStart,
			 x.Lansat,
       x.Document,
			 x.DataDoc,
       x.DenObiect,
       x.DocumentCli,
			 x.Den_Part,
       x.Reteta,
       x.CantAcceptat,
       x.RestAcceptat,
       x.Termen,
       x.TermenCC,
			 x.DataDocCC,
       x.UM, x.UMSec, x.D1, x.D2, x.D3, x.CANTUM1, x.UM1, X.Den_UM1, x.RelatieUM1,
			 X.cantprod,
       x.codcmdprodman,
       x.lansat - nvl(x.realizat, 0) + nvl(x.rebutat, 0) rest,
			 x.CodcomandaCli
  from (SELECT c.PREFIXDOC || c.NrDoc ||&apos;.&apos;||C1.Indexlocal Document, c.Datadoc,
               cl.PREFIXDOC || cl.NrDoc||&apos;.&apos;||C1.Indexlocal DocumentCli,
               P.Den_Part,
               o.Denumire DenObiect,
							 pc.OBS as Reteta,
               cm.Rest RestAcceptat,
               cm.cant cantacceptat,
               c1.Termen,cl1.Termen TermenCC,
               c1.codcomanda1,
							 c1.codcomanda,
               C1.Prioritate idx,
							 pm.nivel,
               Nvl(PM.DataStart, C1.DataStart) DataStart,
               c1.codreteta, c1.UMSec, c1.D1, c1.D2, c1.D3,
							 Case when nvl(C1.CANTAcceptat,0)= 0 then 0 else nvl(C1.AcceptUM1,0)*nvl(C1.RestAcceptat,0)/nvl(C1.CANTAcceptat,0) end CANTUM1, A.UM1, A.RelatieUM1,
               pm.codcmdprodman,
               pm.cant lansat,
               pc.cant cantprod,
               (SELECT Sum(Nvl(realizat, 0))
                  FROM raportp2
                 WHERE codcomanda1 = c1.codcomanda1
                   AND codman = pm.codman) realizat,
               (SELECT Sum(Nvl(Rebut, 0))
                  FROM raportp2
                 WHERE codcomanda1 = c1.codcomanda1
                   AND codman = pm.codman) rebutat,
               (SELECT Sum(Nvl(Refacut, 0))
                  FROM raportp2
                 WHERE codcomanda1 = c1.codcomanda1
                   AND codman = pm.codman) Refacut,
               1 idxgest,
               g.codgest,
               g.den_gest,
               g.nrschimburi,
               g.oreschimb, to_number(g.orastart - to_date(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;)) Orastart,
               LPAD(Nvl(pm.nrop, 0), 2, &apos;_&apos;) || &apos;/&apos; || op.denumire operatie,
               lm.codloc,
               lm.denumire locmunca,
               Decode(Nvl(lm.tip, 0), 0, &apos;Manual&apos;, 1, &apos;Utilaj&apos;, 2, &apos;Mifix&apos;) tiplm,
               pm.tu,
               op.codop CodOperatie,
               u.DEN_UM UM,
               uu.DEN_UM Den_UM1,
							 Case when (SELECT SUM(Nvl(lm1.ore,0)) FROM locmunca1 lm1 WHERE lm1.codloc = lm.codloc) &gt; 0
							   then (SELECT SUM(Nvl(lm1.ore,0)) FROM locmunca1 lm1 WHERE lm1.codloc = lm.codloc)
  						   else NVL(g.nrschimburi * g.oreschimb, 8)
               end orezi,
							 cl.codcomanda CodcomandaCli,
							 cl.DataDoc DataDocCC
          FROM comanda1 c1
         INNER JOIN comanda c ON c.codcomanda = c1.codcomanda
         INNER JOIN CmdprodMat cm ON cm.codComanda1 = c1.codComanda1 and cm.Tip = 0
         INNER JOIN prodcomp pc ON pc.codprodcomp = c1.codreteta
         LEFT JOIN Cmdlink ck ON ck.codComanda1 = c1.codComanda1
         LEFT JOIN comanda1 cl1 ON ck.CODLINIECOMANDA = cl1.codcomanda1
         LEFT JOIN comanda cl ON cl.CODCOMANDA = cl1.codcomanda
         LEFT JOIN npart p ON p.codpart = Cl.PARTENER
         LEFT JOIN nartobj o ON o.codobiect = c1.codobiect
         LEFT JOIN nart A ON A.CODARTICOL = o.CODARTICOL
         LEFT JOIN NUM U ON U.CodUM = A.UM
         LEFT JOIN NUM UU ON UU.CodUM = A.UM1
         LEFT JOIN cmdprodman pm ON pm.codcomanda1 = c1.codcomanda1
         LEFT JOIN ngest g ON g.codgest = C.codgest
         LEFT JOIN noper op ON op.codop = pm.codop
         LEFT JOIN locmunca lm ON lm.codloc = pm.codloc
where C.TipDoc = 53 and C.Operat = 1 and Nvl(C.Inchisa,0) = 0 ) X
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MENUDATE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>90C209F030D30F073D737B7B8EB691981D433F61</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MENUDATE (
&quot;CODMENUDATE&quot;,&quot;DEN_MENU&quot;,&quot;USERID&quot;,&quot;NRBUTON&quot;) AS
select &quot;CODMENUDATE&quot;,&quot;DEN_MENU&quot;,&quot;USERID&quot;,&quot;NRBUTON&quot; from MENUDATE where userid = pkg_globals.getuserid 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MFCLASIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>010995E8E8151040295A35F11FBAC0AD2942D613</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MFCLASIF (
&quot;CODCLASIF&quot;,&quot;DENUMIRE&quot;,&quot;SIMBOL&quot;,&quot;DURATA&quot;,&quot;DURATAF&quot;,&quot;DURATAG&quot;) AS
SELECT
&quot;CODCLASIF&quot;,
&quot;DENUMIRE&quot;,
&quot;SIMBOL&quot;,
&quot;DURATA&quot;,
DURATAF,
DURATAG
FROM MFCLASIF 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MIFIX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3EBC62370811FF74044018AD874BACC95120C0EE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MIFIX (
&quot;CODNIRSTOC&quot;,&quot;PRET&quot;,&quot;DENUMIRE&quot;,&quot;DEN_GEST&quot;,&quot;CODGEST&quot;,&quot;DEN_IOART&quot;,&quot;DATANIR&quot;,&quot;STOC&quot;,&quot;DETALIULUNA&quot;,&quot;REZOLVAT&quot;,&quot;OK&quot;,&quot;DEN_SUBUNIT&quot;,&quot;CODSUBUNIT&quot;) AS
SELECT
  MIFIX.&quot;CODNIRSTOC&quot;,
  MIFIX.&quot;PRET&quot;,
  MIFIX.&quot;DENUMIRE&quot;,
  MIFIX.&quot;DEN_GEST&quot;,
  MIFIX.&quot;CODGEST&quot;,
  MIFIX.&quot;DEN_IOART&quot;,
  MIFIX.&quot;DATANIR&quot;,
  MIFIX.&quot;STOC&quot;,
  MIFIX.&quot;DETALIULUNA&quot;,
  MIFIX.&quot;REZOLVAT&quot;,
  CASE
    WHEN MIFIX.STOC = MIFIX.REZOLVAT THEN 1
    ELSE 0
  END
  AS OK,
  MIFIX.&quot;DEN_SUBUNIT&quot;,
  MIFIX.&quot;CODSUBUNIT&quot;
FROM
  (
  SELECT
    NS.CODNIRSTOC,
    NS.PRET,
    O.DENUMIRE,
    G.DEN_GEST,
    G.CODGEST,
    IO.DEN_IOART,
    N.DATANIR,
    PKG_INTRARI.GET_REST_STOC_IN_LUNA(NS.CODNIRSTOC, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) AS STOC,
    NVL((SELECT SUM(CANT) FROM MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GETANLUCRU AND LUNASTART = PKG_GLOBALS.GETLUNALUCRU  AND STARE IN (1, 2)), 0) AS REZOLVAT,
    NVL((SELECT COUNT(*) FROM MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GETANLUCRU AND LUNASTART = PKG_GLOBALS.GETLUNALUCRU ), 0) AS DETALIULUNA,
    SUB.DEN_SUBUNIT,
    SUB.CODSUBUNIT
  FROM
    NIRSTOC NS,
    NIR N,
    NGEST G,
    NSUBUNIT SUB,
    NARTOBJ O,
    IOART IO,
    TMP_IOART_LUNA  IOALUNA
  WHERE
    N.CODNIR = NS.CODNIR AND
    EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
    NS.CODIOART = IOALUNA.CODIOART AND
    PKG_CATEGCONST.ESTEMIFIX(IOALUNA.CONT) = 1 AND
    N.GEST = G.CODGEST AND
    NS.CODOBIECT = O.CODOBIECT AND
    IOALUNA.CODIOART = IO.CODIOART AND
    SUB.CODSUBUNIT = G.CODSUBUNIT AND
    NVL(G.CODSUBUNIT,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
  ) MIFIX
WHERE
(STOC &lt;&gt; 0) OR (STOC = 0 AND REZOLVAT &lt;&gt; 0)OR(STOC=0 AND REZOLVAT = 0 AND DETALIULUNA &gt; 0) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MISCARI_INTERNE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D2238071ECC2ED954140BB12714BF629E3E7534</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MISCARI_INTERNE (
&quot;CODTRANSF&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;CARNETDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CARNETAE&quot;,&quot;NRAE&quot;,&quot;VALDOC&quot;,&quot;TVADOC&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;LISTAT&quot;) AS
SELECT
  t.CodTransf, t.TipDoc, t.Anulat, t.Blocat, t.Operat, t.PrefixDoc, t.CarnetDoc,
  t.NrDoc, t.DataDoc, t.CarnetAE, t.NrAE, t.ValDoc, t.TVADoc,
  t.Obs, t.An, t.Luna, t.listat
FROM
  TRANSF t
WHERE
 t.tipdoc = PKG_GLOBALS.GetTipMiscareInterna AND
nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
 t.An * 12 + t.Luna = PKG_GLOBALS.AnLunaLucru 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NACTIVIT_CODACTIVIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A63D16D08501A37D7187D4C038806BC272D36993</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NACTIVIT_CODACTIVIT (
&quot;CODACTIVIT&quot;) AS
SELECT codactivit FROM NACTIVIT ORDER BY codactivit 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NAGENDA_CODAGENDA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CED91796024D1FCF3506615FE0CAE82587D822BD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NAGENDA_CODAGENDA (
&quot;CODAGENDA&quot;) AS
SELECT codagenda FROM NAGENDA ORDER BY codagenda 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D25747BE65110767722E4572F0A96630B95A8D74</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NART (
&quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CONTSERVICIU&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;RELATIEUM1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;DCI&quot;,&quot;CODEXTERNART&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;DEN_IOART&quot;,&quot;DEN_GEST&quot;,&quot;CULOARE&quot;,&quot;CODACCIZEDVI&quot;,&quot;ATRIBUTE&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;CODVAMAL&quot;,&quot;DENUMIRETRAD&quot;,&quot;BLOCAT&quot;,&quot;PRODUCATOR&quot;,&quot;PROMOTIE&quot;,&quot;INACTIV&quot;,&quot;CODCPV&quot;,&quot;FARACMDFURN&quot;,&quot;RISC_FISCAL&quot;,&quot;ATCH&quot;) AS
SELECT
  A.CODARTICOL,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  AI.CONTIMPLICIT,
  AI.GESTIMPLICITA,
  A.CONTSERVICIU,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.UM1,
  A.UM2,
  A.Relatieum1,
  A.D1,
  A.D2,
  A.D3,
  A.DCI,
  A.CODEXTERNART || A.SUFIXCODEXTERN AS CODEXTERNART,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  IOA.DEN_IOART,
  GI.DEN_GEST,
	A.Culoare,
  NART1LUNA.CODACCIZEDVI,
  MAX(T.CODATROBJ) AS ATRIBUTE,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT CODEXTERN FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS CODEXTERN,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT CODINTERN FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS CODINTERN,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT CODVAMAL  FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS CODVAMAL,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT DENUMIRETRAD FROM NARTOBJ O2, NARTOBJTRAD TRAD WHERE O2.CODARTICOL = A.CODARTICOL AND TRAD.CODOBIECT = O2.CODOBIECT AND TRAD.CODLIMBA = PKG_GLOBALS.GETLIMBADENART) ELSE NULL END) AS DENUMIRETRAD,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT NVL(O2.BLOCAT, 0) FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE 0 END) AS BLOCAT,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT DEN_PART FROM NPART P, NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL AND O2.CODPRODuCATOR = P.CODPART) ELSE NULL END) AS PRODUCATOR,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT PROMOTIE FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS PROMOTIE,
  (CASE WHEN EXISTS (SELECT 1 FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL AND NVL(O1.INACTIV, 0) &lt;&gt; 1) THEN 0 ELSE 1 END) AS INACTIV,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT O2.CODCPV FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS CODCPV,
  (CASE WHEN (SELECT COUNT(1) FROM NARTOBJ O1 WHERE O1.CODARTICOL = A.CODARTICOL) = 1 THEN (SELECT O2.FARACMDFURN FROM NARTOBJ O2 WHERE O2.CODARTICOL = A.CODARTICOL) ELSE NULL END) AS FARACMDFURN,
  A.RISCFISCAL AS RISC_FISCAL,
  (CASE WHEN (SELECT COUNT(1) FROM DOCUMENTE D WHERE D.CODDOC = A.CODARTICOL AND D.TIPDOC = 501) &gt; 0 THEN 1 ELSE 0 END) AS ATCH
FROM NART A
  LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL= A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT JOIN NARTOBJ O ON O.CODARTICOL = A.CODARTICOL
  LEFT JOIN NATROBJ T ON T.CODOBIECT = O.CODOBIECT
  LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT JOIN TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
  LEFT JOIN IOART IOA ON AI.CONTIMPLICIT = IOA.CODIOART
  LEFT JOIN NGEST GI ON GI.CODGEST = AI.GESTIMPLICITA
WHERE PKG_SELECTARTICOLE.CONDITIECLASA(A.CLASA) = 1 AND PKG_SELECTARTICOLE.CONDITIERETURNABIL(O.RETURNABIL) = 1
GROUP BY
  A.CODARTICOL,
  A.DEN_ARTICOL, A.UM, A.CLASA, A.TIPSERIE, A.TIPARTICOL, A.ARETG, AI.CONTIMPLICIT, AI.GESTIMPLICITA, A.CERTIFICAT, A.EVOLUTIEPRET, A.CONTSERVICIU,
  A.UM1, A.UM2, A.Relatieum1, A.D1, A.D2, A.D3, A.DCI, A.CODEXTERNART || A.SUFIXCODEXTERN, NART1LUNA.CODTVA, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2,
  TVALUNA.PROCENT, IOA.DEN_IOART, GI.DEN_GEST, A.Culoare,  NART1LUNA.CODACCIZEDVI,
  A.RISCFISCAL
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NART1_CODARTICOL1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7719948F04C2BB1C5575D9033AA5CA1CCA7FF65E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NART1_CODARTICOL1 (
&quot;CODARTICOL1&quot;) AS
SELECT CodArticol1 FROM NART1 ORDER BY CodArticol1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NARTATR_CODARTATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>93F3517FE5770BCDDDA6AE940259892E678EB13A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NARTATR_CODARTATR (
&quot;CODARTATR&quot;) AS
SELECT CodArtAtr FROM NARTATR ORDER BY CodArtAtr 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NARTOBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B6387A1E16EC2A59C7111927CACA4B8CDC782AC4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NARTOBJ (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERNART&quot;,&quot;SUFIXCODEXTERN&quot;,&quot;CULOARE&quot;,&quot;CODVAMAL&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;TERMENPLATA&quot;,&quot;PROCADAOSNIR&quot;,&quot;PROMOTIE&quot;,&quot;BLOCAT&quot;,&quot;ROTUNJIRE&quot;,&quot;NEFACTURABIL&quot;,&quot;CANTARIBIL&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODACCIZEDVI&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;TIPPRETMAX&quot;,&quot;PUMAXLUNA&quot;,&quot;PROCTVA&quot;,&quot;DENOBIECT&quot;,&quot;PRODUSPROPRIU&quot;,&quot;INACTIV&quot;,&quot;FARACMDFURN&quot;,&quot;RELATIEUM1&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;DCI&quot;,&quot;DENLOCATIE&quot;,&quot;DENUMIRETRAD&quot;,&quot;DEN_IOART&quot;,&quot;DEN_GEST&quot;,&quot;CODATROBJ&quot;,&quot;FARASTOC&quot;) AS
SELECT
    CODARTICOL,
    CODOBIECT,
    DEN_ARTICOL,
    UM,
    CLASA,
    TIPSERIE,
    TIPARTICOL,
    ARETG,
    CONTIMPLICIT,
    PRODUCATOR,
    GESTIMPLICITA,
    CERTIFICAT,
    EVOLUTIEPRET,
    CONTSERVICIU,
    UM1,
    UM2,
    CODEXTERNART,
    SUFIXCODEXTERN,
    Culoare,
    CODVAMAL,
    CODEXTERN,
    CODINTERN,
    UMAMBALARE,
    STOCMIN,
    STOCMAX,
    TERMENPLATA,
    PROCADAOSNIR,
    PROMOTIE,
    BLOCAT,
    ROTUNJIRE,
    NEFACTURABIL,
    CANTARIBIL,
    CODTVA,
    CODACCIZE,
    CODACCIZEDVI,
    CODTAXA1,
    CODTAXA2,
    TIPPRETMAX,
    PUMAXLUNA,
    PROCTVA,
    NVL(vc2_nt_to_vc3200(CAST(COLLECT(VC2_OBJ(DENOBIECT).VC2 ORDER BY INDEXLOCAL) AS vc2_nt), &apos; &apos;),  &apos;... fara atribute ...&apos;) AS DENOBIECT,
    PRODUSPROPRIU,
    INACTIV,
    FARACMDFURN,
    Relatieum1,
    D1,
    D2,
    D3,
    DCI,
    DENLOCATIE,
    DENUMIRETRAD,
    DEN_IOART,
    DEN_GEST,
    MIN(CODATROBJ) AS CODATROBJ,
    FARASTOC
FROM
(
  SELECT
    A.CODARTICOL,
    O.CODOBIECT,
    A.DEN_ARTICOL,
    A.UM,
    A.CLASA,
    A.TIPSERIE,
    A.TIPARTICOL,
    A.ARETG,
    CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END CONTIMPLICIT,
    P.DEN_PART AS PRODUCATOR,
    CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END GESTIMPLICITA,
    A.CERTIFICAT,
    A.EVOLUTIEPRET,
    A.CONTSERVICIU,
    A.UM1,
    A.UM2,
    A.CODEXTERNART,
    A.SUFIXCODEXTERN,
    A.Culoare,
    O.CODVAMAL,
    O.CODEXTERN,
    O.CODINTERN,
    O.UMAMBALARE,
    O.STOCMIN,
    O.STOCMAX,
    O.TERMENPLATA,
    O.PROCADAOSNIR,
    O.PROMOTIE,
    O.BLOCAT,
    O.ROTVALUTA AS ROTUNJIRE,
    O.NEFACTURABIL,
    U.TipUM CANTARIBIL,
    NART1LUNA.CODTVA,
    NART1LUNA.CODACCIZE,
    NART1LUNA.CODACCIZEDVI,
    NART1LUNA.CODTAXA1,
    NART1LUNA.CODTAXA2,
    NARTOBJ1LUNA.TIPPRETMAX,
    NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
    NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
    NVL(B.VALOARE, &apos;... fara atribute ...&apos;) AS DENOBIECT,
    O.PRODUSPROPRIU,
    O.INACTIV,
    O.FARACMDFURN,
    A.Relatieum1,
    A.D1,
    A.D2,
    A.D3,
    A.DCI,
    LOC.DENUMIRE AS DENLOCATIE,
    TRAD.DENUMIRETRAD,
    IOA.DEN_IOART,
    GI.DEN_GEST,
    NVL(T.CODOBIECT, 0) As CODATROBJ,
    NVL(T.INDEXLOCAL, 0) AS INDEXLOCAL,
    NVL(O.FARASTOC,0) FARASTOC
  FROM NARTOBJ O
    INNER JOIN NART A ON O.CODARTICOL = A.CODARTICOL
    INNER JOIN NUM U ON U.CODUM = A.UM
    LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
    LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
    LEFT JOIN NLOCATII LOC ON CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END = LOC.CODLOCATIE
    LEFT JOIN NPART P ON CODPART = O.CODPRODUCATOR
    LEFT JOIN NATROBJ T ON T.CODOBIECT = O.CODOBIECT
    LEFT JOIN NATRIB1 B ON T.CODVALATR = B.CODVALATR
    LEFT JOIN NARTOBJTRAD TRAD ON TRAD.CODOBIECT = O.CODOBIECT AND TRAD.CODLIMBA = PKG_GLOBALS.GETLIMBADENART
    LEFT JOIN IOART IOA ON CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END = IOA.CODIOART
    LEFT JOIN NGEST GI ON GI.CODGEST = CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END
    LEFT JOIN (
      SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2, CODACCIZEDVI FROM NART1 A1
      WHERE A1.AnStart * 12 + A1.LunaStart = (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11 WHERE A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
    ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
    LEFT JOIN (
      SELECT N.CODTVA,N1.CODTVA1,N.DEN_TVA,N1.PROCENT,N1.CODCONTDED,N1.CODCONTCOLE,N1.CODCONTNEEX
      FROM NTVA N LEFT JOIN NTVA1 N1 ON N.CODTVA = N1.CODTVA
      WHERE N1.ANSTART * 12 + N1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 NT1 WHERE NT1.CODTVA = N1.CODTVA AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
    ) TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
    LEFT JOIN (
      SELECT CODOBIECT, TIPPRETMAX, PRETMAXIMAL
      FROM NARTOBJ1 O1
      WHERE O1.ANSTART * 12 + O1.LUNASTART = (SELECT MAX(O11.ANSTART * 12 + O11.LUNASTART) FROM NARTOBJ1 O11 WHERE O11.CODOBIECT = O1.CODOBIECT AND O11.AnStart * 12 + O11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
    ) NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  WHERE
    O.CODARTICOL =  PKG_SELECTARTICOLE.GETCODARTCURENT
  ORDER BY NVL(T.INDEXLOCAL, 0)
)
  GROUP BY
    CODARTICOL,
    CODOBIECT,
    DEN_ARTICOL,
    UM,
    CLASA,
    TIPSERIE,
    TIPARTICOL,
    ARETG,
    CONTIMPLICIT,
    PRODUCATOR,
    GESTIMPLICITA,
    CERTIFICAT,
    EVOLUTIEPRET,
    CONTSERVICIU,
    UM1,
    UM2,
    CODEXTERNART,
    SUFIXCODEXTERN,
    CODVAMAL,
    CODEXTERN,
    CODINTERN,
    UMAMBALARE,
    STOCMIN,
    STOCMAX,
    TERMENPLATA,
    PROCADAOSNIR,
    PROMOTIE,
    BLOCAT,
    ROTUNJIRE,
    NEFACTURABIL,
    CANTARIBIL,
    CODTVA,
    CODACCIZE,
    CODACCIZEDVI,
    CODTAXA1,
    CODTAXA2,
    TIPPRETMAX,
    PUMAXLUNA,
    PROCTVA,
    PRODUSPROPRIU,
    INACTIV,
    FARACMDFURN,
    Relatieum1,
    D1,
    D2,
    D3,
    DCI,
    DENLOCATIE,
    DENUMIRETRAD,
    DEN_IOART,
    DEN_GEST,
    Culoare,
    FARASTOC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NARTOBJ1_CODOBIECT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>324C972FEB3F7253E324109F961C44E59468367B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NARTOBJ1_CODOBIECT1 (
&quot;CODOBIECT1&quot;) AS
SELECT CodObiect1 FROM NARTOBJ1 ORDER BY CodObiect1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NARTOBJ_CODOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0D5035BDEC8F4564EA843917B9BE0502AB88FD6F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NARTOBJ_CODOBIECT (
&quot;CODOBIECT&quot;) AS
SELECT CodObiect FROM NARTOBJ ORDER BY CodObiect 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NART_CODARTICOL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B15C5FE9A5A53FB1919DBDD4DEC1D0089D2AF8EA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NART_CODARTICOL (
&quot;CODARTICOL&quot;) AS
SELECT CodArticol FROM NART ORDER BY CodArticol 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NATRIB1_CODVALATR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>052C350658301FDFDBB60947BD876285448FBE90</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NATRIB1_CODVALATR (
&quot;CODVALATR&quot;) AS
SELECT CodValAtr FROM NATRIB1 ORDER BY CodValAtr 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NATRIB_CODATRIBUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>469D272A8A81407E537A9F1F3880753385BA691D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NATRIB_CODATRIBUT (
&quot;CODATRIBUT&quot;) AS
SELECT CodAtribut FROM NATRIB ORDER BY CodAtribut 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NATROBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE56B3F0B8146A6CAF4EEFAE67C221A6D40A8C0E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NATROBJ (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;OBIECT&quot;) AS
select a.codarticol, b.codobiect, getnumeobiect(den_articol,b.codobiect,0) obiect
from tmp_nart a, tmp_nartobj b
where a.codarticol = b.codarticol 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NATROBJ1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AB08A964DC2F0657A83465044F7D8F39ECC5D10</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NATROBJ1 (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;OBIECT&quot;) AS
select a.codarticol, b.codobiect, getnumeobiect1(den_articol,b.codobiect,0) obiect
from nart a, nartobj b
where a.codarticol = b.codarticol 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NATROBJ_CODATROBJ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F8D87B0F8E79A5FDCE918A12344B781356E6DC62</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NATROBJ_CODATROBJ (
&quot;CODATROBJ&quot;) AS
SELECT CodAtrOBJ FROM NATROBJ ORDER BY CodAtrOBJ 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NBANKCONT1_CODBANKCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B76A8C7CFA83873065BEF14D884DAB6BA9A54CCE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NBANKCONT1_CODBANKCONT1 (
&quot;CODBANKCONT1&quot;) AS
SELECT codbankcont1 FROM NBANKCONT1 ORDER BY codbankcont1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NBANK_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D4B0085764411E781881458ACDBFE7C539BB48E1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NBANK_LUNA (
&quot;CODBANK&quot;,&quot;DENUMIRE&quot;,&quot;SIMBOL&quot;,&quot;CODBANKCONT&quot;,&quot;DEN_CONT&quot;,&quot;CODLOCALITATE&quot;,&quot;NRCONT&quot;,&quot;CODMONEDA&quot;,&quot;FILIALA&quot;,&quot;DATADESKIS&quot;,&quot;DATAINKIS&quot;,&quot;CREDIT&quot;,&quot;CODBANKCONT1&quot;,&quot;CODIOBANCA&quot;,&quot;CODIOBANK1&quot;,&quot;DEN_IOBANK&quot;,&quot;CONT&quot;,&quot;DOBANDA&quot;,&quot;COMISION&quot;,&quot;CHELTUIELICV&quot;,&quot;VENITURICV&quot;) AS
SELECT nb.codbank,nb.denumire,nb.simbol,nbk.codbankcont,nbk.den_cont,nbk.codlocalitate,nbk.nrcont,
       nbk.codmoneda,nbk.filiala,nbk.datadeskis,nbk.datainkis,nbk.credit,nbk1.codbankcont1,nbk1.codiobanca,
			 io1.codiobank1,io.den_iobank,io1.cont,io1.dobanda,io1.comision,io1.cheltuielicv,
       io1.venituricv
FROM
nbank nb LEFT JOIN nbankcont nbk ON nb.codbank = nbk.codbank
         LEFT JOIN nbankcont1 nbk1 ON nbk.codbankcont = nbk1.codbankcont
				 LEFT JOIN iobank io ON nbk1.codiobanca = io.codiobank
				 LEFT JOIN iobank1 io1 ON io.codiobank = io1.codiobank
WHERE	nbk1.anstart * 12 + nbk1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM nbankcont1 nb1
                                             WHERE nb1.codbankcont = nbk1.codbankcont AND
																						 anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
																						 )
AND
io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iobank1 i1
                                             WHERE i1.codiobank = io1.codiobank AND
						anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
				              ) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7D0E88A01D9CBB8C0D7E8FF7C8EBF60BD202F073</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NC (
&quot;CODNC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PART&quot;,&quot;JURNALTVA&quot;,&quot;TIPTRANZ&quot;,&quot;TIPTVA&quot;,&quot;VALOARE&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;OBS&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DEN_PART&quot;,&quot;SABLON&quot;) AS
SELECT
 CODNC, NRDOC, DATADOC, PART, JURNALTVA, TIPTRANZ, TIPTVA, VALOARE, MONEDA, CURS, N.OBS,
 AN, LUNA, P.DEN_PART, N.SABLON
FROM
NC N
LEFT OUTER JOIN NPART P ON P.CODPART = N.PART
WHERE
	nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  12 * AN + LUNA = PKG_GLOBALS.Anlunalucru AND NVL(N.SABLON, 0) = 0 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NC1_CODNC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0C84F1C932749BD0BA0562A8D38B6FF5DE389DCE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NC1_CODNC1 (
&quot;CODNC1&quot;) AS
SELECT CodNC1 FROM NC1 ORDER BY CodNC1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCATPRET_CODCATPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>589D569B450FAEF0111C61C386176F683CB1DEA8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCATPRET_CODCATPRET (
&quot;CODCATPRET&quot;) AS
SELECT CodCatPret FROM NCATPRET ORDER BY CodCatPret 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89989D04D4690F9ACD5276F1BA60430912ECEA67</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEART (
&quot;CODCLASEA&quot;,&quot;DEN_CLASEA&quot;,&quot;SIMBOL&quot;,&quot;PREFIX&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;VERLISTSUPLFACT&quot;,&quot;VERLISTSUPLTOALL&quot;,&quot;LEV&quot;,&quot;CODIDENT&quot;,&quot;VERLISTSUPLAVIZ&quot;,&quot;DISCOFE&quot;) AS
Select codclasea, den_clasea, simbol, prefix, nivel, nranalitice, codparinte, VerListSuplFact, VerListSuplToAll,level lev, CodIdent, VerListSuplAviz,
       DiscOfe
from nclasea
start with nvl(codparinte,0) = 0
connect by prior codclasea=codparinte
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEARTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA675A4FE964D43269691AFA04B08AE877892E72</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEARTS (
&quot;CODCLASEAS&quot;,&quot;DEN_CLASEAS&quot;,&quot;SIMBOL&quot;,&quot;PREFIX&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;VERLISTSUPLFACT&quot;,&quot;VERLISTSUPLTOALL&quot;,&quot;LEV&quot;,&quot;TIP&quot;,&quot;CODIDENT&quot;) AS
Select codclaseas, den_claseas, simbol, prefix, nivel, nranalitice, codparinte, VerListSuplFact, VerListSuplToAll,level lev,nvl(Tip,0) tip, CodIdent
from nclaseas
start with nvl(codparinte,0) = 0
connect by prior codclaseas=codparinte
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEA_CODCLASEA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3E1087FC54D4B4A024A22576AE8C8631D9630C38</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEA_CODCLASEA (
&quot;CODCLASEA&quot;) AS
SELECT CodClaseA FROM NCLASEA ORDER BY CodClaseA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9C2F429CE1D531FF23730927DC12EC097FB635EC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEDISC (
&quot;CODCLASEDISC&quot;,&quot;DEN_CLASEDISC&quot;,&quot;SIMBOL&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
SELECT
  CODCLASEDISC,
  DEN_CLASEDISC,
  SIMBOL,
  NIVEL,
  NRANALITICE,
  CODPARINTE,
  LEVEL LEV
FROM
  NCLASEDISC
START WITH NVL(CODPARINTE,0) = 0
CONNECT BY PRIOR CODCLASEDISC=CODPARINTE

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>41806F47CB1799082DA52026F94EE4481A22432E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEGEST (
&quot;CODCLASEG&quot;,&quot;DEN_CLASEG&quot;,&quot;SIMBOL&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
Select codclaseg, den_claseg, simbol, nivel, nranalitice, codparinte, level lev
from nclaseg
start with nvl(codparinte,0) = 0
connect by prior codclaseg=codparinte 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEG_CODCLASEG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>10A7E68D6196BF8669B2619BA1F2C27F4E8252B8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEG_CODCLASEG (
&quot;CODCLASEG&quot;) AS
SELECT CodClaseG FROM NCLASEG ORDER BY CodClaseG 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEINT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9B65FEF2954F692F12C3F2C4A7F6110D6A16E001</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEINT (
&quot;CODCLASEINT&quot;,&quot;DEN_CLASEINT&quot;,&quot;SIMBOL&quot;,&quot;PREFIX&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
Select codclaseint, den_claseint, simbol, prefix, nivel, nranalitice, codparinte, level lev
from nclaseint
start with nvl(codparinte,0) = 0
connect by prior codclaseint=codparinte

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEMF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E05C015AF5BE17EAA437743271CA51746D87D38A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEMF (
&quot;CODCLASEMF&quot;,&quot;DEN_CLASEMF&quot;,&quot;SIMBOL&quot;,&quot;PREFIX&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
WITH  /*RECURSIVE*/ A ( codclasemf, den_clasemf, simbol, prefix, nivel, nranalitice, codparinte, lev)
AS (
  SELECT codclasemf, den_clasemf, simbol, prefix, nivel, nranalitice, codparinte, 0 lev
  FROM nclasemf  
  WHERE COALESCE( codparinte, 0) = 0
  UNION ALL
  SELECT n.codclasemf, n.den_clasemf, n.simbol, n.prefix, n.nivel, n.nranalitice, n.codparinte, a.lev + 1 lev
  FROM nclasemf n INNER JOIN A on A.CODCLASEMF = N.CODPARINTE
)
SELECT CODCLASEMF, DEN_CLASEMF, SIMBOL, PREFIX, NIVEL, NRANALITICE, CODPARINTE, LEV
FROM A</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D60BD3650228A457D4D5DF57585E3C52CF52DAC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEPART (
&quot;CODCLASEP&quot;,&quot;DEN_CLASEP&quot;,&quot;SIMBOL&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
Select codclasep, den_clasep, simbol, /*prefix,*/ nivel, nranalitice, codparinte, level lev
from nclaseP
start with nvl(codparinte,0) = 0
connect by prior codclasep=codparinte 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5CDD5A843CF67FC715CE648785C40D667E2AAA1B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEPROD (
&quot;CODCLASEPROD&quot;,&quot;DEN_CLASEPROD&quot;,&quot;SIMBOL&quot;,&quot;PREFIX&quot;,&quot;NIVEL&quot;,&quot;NRANALITICE&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;) AS
Select codclaseprod, den_claseprod, simbol, prefix, nivel, nranalitice, codparinte, level lev
from nclaseprod
start with nvl(codparinte,0) = 0
connect by prior codclaseprod=codparinte
---------------------------------------------------------v_nclaseprod 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCLASEP_CODCLASEP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E29746CE7DCBDF7260B194712EF509933F7A5921</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCLASEP_CODCLASEP (
&quot;CODCLASEP&quot;) AS
SELECT CodClaseP FROM NCLASEP ORDER BY CodClaseP 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>03846C7D0813FD86119345C24ACCC31D1423099A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONT (
&quot;CODCONT&quot;,&quot;SIMBOL&quot;,&quot;CLASA&quot;,&quot;DEN_CONT&quot;,&quot;NAME&quot;,&quot;TIPCONT&quot;,&quot;TIP&quot;,&quot;VIZIBILBALANTA&quot;,&quot;BALANTASINTETICA&quot;,&quot;NIVEL&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;,&quot;ACTIV&quot;,&quot;COPIL&quot;,&quot;COPIIACTIVI&quot;) AS
SELECT
  CODCONT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TipCont,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL,
  MIN( ANSTART * 12 + LUNASTART) AS COPIIACTIVI
FROM
(
SELECT
  V.CODCONT,
  V.SIMBOL,
  V.CLASA,
  V.DEN_CONT,
  V.NAME,
  V.TIPCONT,
  DECODE(NVL(V.TIPCONT,0), 0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;) TIP,
  V.VIZIBILBALANTA,
  V.BALANTASINTETICA,
  V.NIVEL,
  V.CODPARINTE,
  LEVEL LEV,
  NVL(N1.CODCONT, 0) AS ACTIV,
  NVL(N2.CODPARINTE, 0) AS COPIL,
  N4.ANSTART,
  N4.LUNASTART
FROM
  NCONT V
  LEFT OUTER JOIN NCONT1 N1 ON (N1.CODCONT = V.CODCONT AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
  LEFT OUTER JOIN NCONT N2  ON (N2.CODPARINTE = V.CODCONT)
  LEFT OUTER JOIN NCONT1 N4 ON N4.CODCONT = N2.CODCONT
  START WITH V.CODPARINTE IS NULL CONNECT BY PRIOR V.CODCONT = V.CODPARINTE
)
GROUP BY
  CODCONT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIPCONT,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONT1_CODCONT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>60E3D9978D24DBF0E1293A9A455746136F7118F6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONT1_CODCONT1 (
&quot;CODCONT1&quot;) AS
SELECT CodCont1 FROM NCONT1 ORDER BY CodCont1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTREP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA616E83B7AFAC18086DE391A441B0ECDC8514AE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTREP (
&quot;CODCONTREP&quot;,&quot;CODCONT&quot;) AS
SELECT CODCONTREP, CODCONT FROM NCONTREP WHERE CODCONT = PKG_PLANCONTURI.GETCODCONTREP 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTRULS_CODCONTRULS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5D3354470680AEBC5E7706646881558EA35CA16A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTRULS_CODCONTRULS (
&quot;CODCONTRULS&quot;) AS
SELECT CodcontrulS FROM NCONTRULS ORDER BY CodcontrulS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTRULT_CODCONTRULT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DB00B21E9D5F25556E762138F9B6880EA2140676</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTRULT_CODCONTRULT (
&quot;CODCONTRULT&quot;) AS
SELECT CodContRulT FROM NCONTRULT ORDER BY CodContRulT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTRUL_CODCONTRUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A459636C3FA6370B8DB7EB6A6E2088A93190CDC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTRUL_CODCONTRUL (
&quot;CODCONTRUL&quot;) AS
SELECT CodContRul FROM NCONTRUL ORDER BY CodContRul 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>ABCDDC0D6364054465AE853462E2804CF2392BCA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTS (
&quot;CODCONTS&quot;,&quot;SIMBOL&quot;,&quot;CLASA&quot;,&quot;DEN_CONT&quot;,&quot;NAME&quot;,&quot;TIP&quot;,&quot;VIZIBILBALANTA&quot;,&quot;BALANTASINTETICA&quot;,&quot;NIVEL&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;,&quot;ACTIV&quot;,&quot;COPIL&quot;,&quot;COPIIACTIVI&quot;) AS
SELECT
  CODCONTS,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL,
  MIN( ANSTART * 12 + LUNASTART) AS COPIIACTIVI
FROM
(
SELECT
  V.CODCONTS,
  V.SIMBOL,
  V.CLASA,
  V.DEN_CONT,
  V.NAME,
  DECODE(NVL(V.TIPCONT,0), 0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;) TIP,
  V.VIZIBILBALANTA,
  V.BALANTASINTETICA,
  V.NIVEL,
  V.CODPARINTE,
  LEVEL LEV,
  NVL(N1.CODCONTS, 0) AS ACTIV,
  NVL(N2.CODPARINTE, 0) AS COPIL,
  N4.ANSTART,
  N4.LUNASTART
FROM
  NCONTS V
  LEFT OUTER JOIN NCONTS1 N1 ON (N1.CODCONTS = V.CODCONTS AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
  LEFT OUTER JOIN NCONTS N2  ON (N2.CODPARINTE = V.CODCONTS)
  LEFT OUTER JOIN NCONTS1 N4 ON N4.CODCONTS = N2.CODCONTS
  START WITH V.CODPARINTE IS NULL CONNECT BY PRIOR V.CODCONTS = V.CODPARINTE
)
GROUP BY
  CODCONTS,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTS1_CODCONTS1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E86437504C8AAE10EF1DC153EB7C07BE3EF2B6C5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTS1_CODCONTS1 (
&quot;CODCONTS1&quot;) AS
SELECT CodContS1 FROM NCONTS1 ORDER BY CodContS1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTSOLDS_CODCONTSOLDS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BBF183414374DD596E68A8C3F55CF2DC61DA9A85</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTSOLDS_CODCONTSOLDS (
&quot;CODCONTSOLDS&quot;) AS
SELECT CodContSoldS FROM NCONTSOLDS ORDER BY CodContSoldS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTSOLDT_CODCONTSOLDT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB80AE6F5ED37DBEC4B23858A35E0455AAE18F07</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTSOLDT_CODCONTSOLDT (
&quot;CODCONTSOLDT&quot;) AS
SELECT CodContSoldT FROM NCONTSOLDT ORDER BY CodContSoldT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTSOLD_CODCONTSOLD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0E02463E775E1CE5194A182FA30D7FF59C0164B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTSOLD_CODCONTSOLD (
&quot;CODCONTSOLD&quot;) AS
SELECT CodContSold FROM NCONTSOLD ORDER BY CodContSold 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTS_CODCONTS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>88E51AD28C55F91B37BC6732CA794EEAB6F31137</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTS_CODCONTS (
&quot;CODCONTS&quot;) AS
SELECT CodContS FROM NCONTS ORDER BY CodContS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D40C73DBFB28DD73214C46E043A235063C95351A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTT (
&quot;CODCONTT&quot;,&quot;SIMBOL&quot;,&quot;CLASA&quot;,&quot;DEN_CONT&quot;,&quot;NAME&quot;,&quot;TIP&quot;,&quot;VIZIBILBALANTA&quot;,&quot;BALANTASINTETICA&quot;,&quot;NIVEL&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;,&quot;ACTIV&quot;,&quot;COPIL&quot;,&quot;COPIIACTIVI&quot;) AS
SELECT
  CODCONTT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL,
  MIN( ANSTART * 12 + LUNASTART) AS COPIIACTIVI
FROM
(
SELECT
  V.CODCONTT,
  V.SIMBOL,
  V.CLASA,
  V.DEN_CONT,
  V.NAME,
  DECODE(NVL(V.TIPCONT,0), 0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;) TIP,
  V.VIZIBILBALANTA,
  V.BALANTASINTETICA,
  V.NIVEL,
  V.CODPARINTE,
  LEVEL LEV,
  NVL(N1.CODCONTT, 0) AS ACTIV,
  NVL(N2.CODPARINTE, 0) AS COPIL,
  N4.ANSTART,
  N4.LUNASTART
FROM
  NCONTT V
  LEFT OUTER JOIN NCONTT1 N1 ON (N1.CODCONTT = V.CODCONTT AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
  LEFT OUTER JOIN NCONTT N2  ON (N2.CODPARINTE = V.CODCONTT)
  LEFT OUTER JOIN NCONTT1 N4 ON N4.CODCONTT = N2.CODCONTT
  START WITH V.CODPARINTE IS NULL CONNECT BY PRIOR V.CODCONTT = V.CODPARINTE
)
GROUP BY
  CODCONTT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTT1_CODCONTT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8FDEEFDBC572EA063C06FB6F4F7D48B6808A7AD4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTT1_CODCONTT1 (
&quot;CODCONTT1&quot;) AS
SELECT CodContT1 FROM NCONTT1 ORDER BY CodContT1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONTT_CODCONTT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E33ACB03D59736DF5F8F963A4777E3D7DC1EE9A0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONTT_CODCONTT (
&quot;CODCONTT&quot;) AS
SELECT CodContT FROM NCONTT ORDER BY CodContT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONT_CODCONT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>44DBD7AD1249C35B0D144B4AED42FE07604864A7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONT_CODCONT (
&quot;CODCONT&quot;) AS
SELECT CodCont FROM NCONT ORDER BY CodCont 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONT_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>18C63EE111173298E67AF1816C5606E39C0FB6E1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONT_EXT (
&quot;CODCONT&quot;,&quot;SIMBOL&quot;,&quot;CLASA&quot;,&quot;DEN_CONT&quot;,&quot;NAME&quot;,&quot;TIPCONT&quot;,&quot;TIP&quot;,&quot;VIZIBILBALANTA&quot;,&quot;BALANTASINTETICA&quot;,&quot;NIVEL&quot;,&quot;CODPARINTE&quot;,&quot;ACTIV&quot;,&quot;ANLUNAINACTIV&quot;,&quot;COPIL&quot;,&quot;COPIIACTIVI&quot;,&quot;ECHIVALAT&quot;,&quot;SIMBOLSITFIN&quot;,&quot;SIMBOLTERTIAR&quot;,&quot;CODSAFT&quot;,&quot;TAXTYPE&quot;,&quot;SIMB_CONTSECUNDAR&quot;,&quot;SIMB_CONTSECUNDARG&quot;,&quot;SIMB_CONTSECUNDARGO&quot;,&quot;SIMB_CODCENTRUS&quot;,&quot;SIMB_CODCENTRUSG&quot;,&quot;SIMB_CODCENTRUSGO&quot;,&quot;TAXCODE&quot;,&quot;IMPOZIT&quot;) AS
SELECT CODCONT,
       SIMBOL,
       CLASA,
       DEN_CONT,
       NAME,
       TipCont,
       TIP,
       VIZIBILBALANTA,
       BALANTASINTETICA,
       NIVEL,
       CODPARINTE,
       --  LEV,
       ACTIV,
       ANLUNAINACTIV,
       COPIL,
       COPIIACTIVI,
       (SELECT MIN(AN * 12 + LUNA) FROM NCONTECHIV WHERE CONTVECHI = CODCONT) AS ECHIVALAT,
       SIMBOLSITFIN,
       SIMBOLTERTIAR,
       CODSAFT,
       TAXTYPE,
       SIMB_CONTSECUNDAR,
       SIMB_CONTSECUNDARG,
       SIMB_CONTSECUNDARGO,
       SIMB_CODCENTRUS,
       SIMB_CODCENTRUSG,
       SIMB_CODCENTRUSGO,
       TAXCODE,
       IMPOZIT
  FROM (SELECT CODCONT,
               SIMBOL,
               CLASA,
               DEN_CONT,
               NAME,
               TipCont,
               TIP,
               VIZIBILBALANTA,
               BALANTASINTETICA,
               NIVEL,
               CODPARINTE,
               --  LEV,
               ACTIV,
               ANLUNAINACTIV,
               COPIL,
               MIN(ANSTART * 12 + LUNASTART) AS COPIIACTIVI,
               SIMBOLSITFIN,
               SIMBOLTERTIAR,
               CODSAFT,
               TAXTYPE,
               SIMB_CONTSECUNDAR,
               SIMB_CONTSECUNDARG,
               SIMB_CONTSECUNDARGO,
               SIMB_CODCENTRUS,
               SIMB_CODCENTRUSG,
               SIMB_CODCENTRUSGO,
               TAXCODE,
               IMPOZIT
          FROM (SELECT V.CODCONT,
                       V.SIMBOL,
                       V.CLASA,
                       V.DEN_CONT,
                       V.NAME,
                       V.TIPCONT,
                       DECODE(NVL(V.TIPCONT, 0),
                              0,
                              &apos;ACTIV&apos;,
                              1,
                              &apos;PASIV&apos;,
                              2,
                              &apos;BIFUNC&apos;) TIP,
                       V.VIZIBILBALANTA,
                       V.BALANTASINTETICA,
                       V.NIVEL,
                       V.CODPARINTE,
                       --  LEVEL LEV,
                       NVL(N1.CODCONT, 0) AS ACTIV,
                       NVL(N2.CODPARINTE, 0) AS COPIL,
                       N4.ANSTART,
                       N4.LUNASTART,
                       NVL(V.ANINACTIV, 0) * 12 + NVL(V.LUNAINACTIV, 0) AS ANLUNAINACTIV,
                       V.SIMBOLSITFIN,
                       N5.SIMBOL AS SIMBOLTERTIAR,
                       V.CODSAFT,
                       V.TAXTYPE,
                       N5.SIMB_CONTSECUNDAR,
                       N5.SIMB_CONTSECUNDARG,
                       N5.SIMB_CONTSECUNDARGO,
                       N5.SIMB_CODCENTRUS,
                       N5.SIMB_CODCENTRUSG,
                       N5.SIMB_CODCENTRUSGO,
                       V.TAXCODE,
                       V.IMPOZIT
                  FROM --  NCONT V
                       (SELECT *
                          FROM NCONT
                         START WITH CODPARINTE IS NULL
                        CONNECT BY PRIOR CODCONT = CODPARINTE) V
                  LEFT OUTER JOIN NCONT1 N1
                    ON (N1.CODCONT = V.CODCONT AND
                       ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
                  LEFT OUTER JOIN NCONT N2
                    ON (N2.CODPARINTE = V.CODCONT)
                  LEFT OUTER JOIN NCONT1 N4
                    ON N4.CODCONT = N2.CODCONT
                  LEFT OUTER JOIN (SELECT INR.CODCONT,
                                         NTT.SIMBOL,
                                         NCTS1.SIMBOL as SIMB_CONTSECUNDAR,
                                         NCTS2.SIMBOL as SIMB_CONTSECUNDARG,
                                         NCTS3.SIMBOL as SIMB_CONTSECUNDARGO,
                                         CCS1.SIMBOL  as SIMB_CODCENTRUS,
                                         CCS2.SIMBOL  as SIMB_CODCENTRUSG,
                                         CCS3.SIMBOL  as SIMB_CODCENTRUSGO
                                    FROM (SELECT DISTINCT FIRST_VALUE(NCT1.CONTTERTIAR) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CONTTERTIAR,
                                                          FIRST_VALUE(NCT1.CONTSECUNDAR) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CONTSECUNDAR,
                                                          FIRST_VALUE(NCT1.CONTSECUNDARG) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CONTSECUNDARG,
                                                          FIRST_VALUE(NCT1.CONTSECUNDARGO) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CONTSECUNDARGO,
                                                          FIRST_VALUE(NCT1.CODCENTRUS) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CODCENTRUS,
                                                          FIRST_VALUE(NCT1.CODCENTRUSG) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CODCENTRUSG,
                                                          FIRST_VALUE(NCT1.CODCENTRUSGO) OVER(PARTITION BY NCT1.CODCONT ORDER BY NCT1.ANSTART * 12 + NCT1.LUNASTART DESC) AS CODCENTRUSGO,
                                                          NCT1.CODCONT AS CODCONT
                                            FROM NCONT1 NCT1
                                           WHERE NCT1.ANSTART * 12 +
                                                 NCT1.LUNASTART &lt;=
                                                 PKG_GLOBALS.ANLUNALUCRU) INR
                                    LEFT JOIN NCONTT NTT
                                      ON NTT.CODCONTT = INR.CONTTERTIAR
                                    LEFT JOIN NCONTS NCTS1
                                      ON NCTS1.CODCONTS = INR.CONTSECUNDAR
                                    LEFT JOIN NCONTS NCTS2
                                      ON NCTS2.CODCONTS = INR.CONTSECUNDARG
                                    LEFT JOIN NCONTS NCTS3
                                      ON NCTS3.CODCONTS = INR.CONTSECUNDARGO
                                    LEFT JOIN CENTRECOST CCS1
                                      ON CCS1.CODCENTRU = INR.CODCENTRUS
                                    LEFT JOIN CENTRECOST CCS2
                                      ON CCS2.CODCENTRU = INR.CODCENTRUSG
                                    LEFT JOIN CENTRECOST CCS3
                                      ON CCS3.CODCENTRU = INR.CODCENTRUSGO) N5
                    ON N5.CODCONT = V.CODCONT)
         GROUP BY CODCONT,
                  SIMBOL,
                  CLASA,
                  DEN_CONT,
                  NAME,
                  TIPCONT,
                  TIP,
                  VIZIBILBALANTA,
                  BALANTASINTETICA,
                  NIVEL,
                  CODPARINTE,
                  --  LEV,
                  ACTIV,
                  ANLUNAINACTIV,
                  COPIL,
                  SIMBOLSITFIN,
                  SIMBOLTERTIAR,
                  CODSAFT,
                  TAXTYPE,
                  SIMB_CONTSECUNDAR,
                  SIMB_CONTSECUNDARG,
                  SIMB_CONTSECUNDARGO,
                  SIMB_CODCENTRUS,
                  SIMB_CODCENTRUSG,
                  SIMB_CODCENTRUSGO,
                  TAXCODE,
                  IMPOZIT)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NCONT_WM</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0B6B308D497CB475D2C67198ED1E09DB61722488</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NCONT_WM (
&quot;CODCONT&quot;,&quot;SIMBOL&quot;,&quot;CLASA&quot;,&quot;DEN_CONT&quot;,&quot;NAME&quot;,&quot;TIPCONT&quot;,&quot;TIP&quot;,&quot;VIZIBILBALANTA&quot;,&quot;BALANTASINTETICA&quot;,&quot;NIVEL&quot;,&quot;CODPARINTE&quot;,&quot;LEV&quot;,&quot;ACTIV&quot;,&quot;COPIL&quot;,&quot;NRANALITICE&quot;,&quot;COPIIACTIVI&quot;) AS
SELECT
  CODCONT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TipCont,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL,
  NRANALITICE,
  MIN( ANSTART * 12 + LUNASTART) AS COPIIACTIVI
FROM
(
SELECT
  V.CODCONT,
  V.SIMBOL,
  V.CLASA,
  V.DEN_CONT,
  V.NAME,
  V.TIPCONT,
  DECODE(NVL(V.TIPCONT,0), 0, &apos;ACTIV&apos;,1,&apos;PASIV&apos;,2,&apos;BIFUNC&apos;) TIP,
  V.VIZIBILBALANTA,
  V.BALANTASINTETICA,
  V.NIVEL,
  V.CODPARINTE,
  LEVEL LEV,
  NVL(N1.CODCONT, 0) AS ACTIV,
  NVL(N2.CODPARINTE, 0) AS COPIL,
  NVL(N1.NRANALITICE, 0) AS NRANALITICE,
  N4.ANSTART,
  N4.LUNASTART
FROM
  NCONT V
  LEFT OUTER JOIN NCONT1 N1 ON (N1.CODCONT = V.CODCONT AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
  LEFT OUTER JOIN NCONT N2  ON (N2.CODPARINTE = V.CODCONT)
  LEFT OUTER JOIN NCONT1 N4 ON N4.CODCONT = N2.CODCONT
  START WITH V.CODPARINTE IS NULL CONNECT BY PRIOR V.CODCONT = V.CODPARINTE
)
GROUP BY
  CODCONT,
  SIMBOL,
  CLASA,
  DEN_CONT,
  NAME,
  TIPCONT,
  TIP,
  VIZIBILBALANTA,
  BALANTASINTETICA,
  NIVEL,
  CODPARINTE,
  LEV,
  ACTIV,
  COPIL,
  NRANALITICE 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NC_CODNC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEF11F06CF22FABA27DCDE2785B046BC7C1C7B48</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NC_CODNC (
&quot;CODNC&quot;) AS
SELECT CodNC FROM NC WHERE NVL(Sablon, 0) = 0 ORDER BY CodNC 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NC_SABLOANE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2BB22FE7F0F150F89AA220A33197187E3022579</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NC_SABLOANE (
&quot;CODNC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;PART&quot;,&quot;JURNALTVA&quot;,&quot;TIPTRANZ&quot;,&quot;TIPTVA&quot;,&quot;MONEDA&quot;,&quot;OBS&quot;,&quot;VALOARE&quot;,&quot;AJURNALTVA&quot;,&quot;ATIPTRANZ&quot;,&quot;ATIPTVA&quot;,&quot;DENMONEDA&quot;,&quot;DEN_PART&quot;) AS
SELECT
 N.Codnc,n.nrdoc, n.datadoc, n.part, n.jurnaltva, n.tiptranz, n.tiptva, n.moneda, n.obs, n.valoare,
 case NVL(N.JURNALTVA, 0) when 1 then &apos;nu apare in jurnal TVA&apos; when 2 then &apos;Jurnal cumparari&apos; when 3 then &apos;Jurnal vanzari&apos; else &apos;-&apos; end aJurnalTVA,
 case when NVL(N.JURNALTVA, 0) = 1 then &apos;-&apos;
      else case NVL(N.TIPTRANZ, 0) when 1 then &apos;Tranzactie interna&apos; when 2 then &apos;Livrare intracomunitara&apos; when 3 then &apos;Export&apos; else &apos;-&apos; end
 end aTipTranz,
 case when NVL(N.JURNALTVA, 0) = 1 then &apos;-&apos;
      else
        case NVL(N.TIPTVA, 0)
          when 1 then &apos;taxare normala&apos;
          when 2 then &apos;taxare inversa&apos;
          when 3 then &apos;tranzactie triunghiulara&apos;
          when 4 then &apos;locul livrarii/prestarii in afara Romaniei&apos;
          when 5 then &apos;intracom.,scutit, cu drept de ded.(lit.a/d)&apos;
          when 6 then &apos;intracom.,scutit, cu drept de ded.(lit.b/c)&apos;
          else &apos;-&apos;
        end
 end aTipTVA,
 DM.Den_Moneda DenMoneda, P.den_part
FROM
 NC N
LEFT OUTER JOIN NPART P ON P.CODPART = N.PART
LEFT OUTER JOIN NMONEDE DM ON DM.CODMONEDA = N.Moneda
WHERE
 NVL(N.Sablon, 0) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6AC36AEBA2AEBD6652288F5B8BFD7EC9786927A3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NGEST (
&quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;SIMBOL&quot;,&quot;CODACTIVIT&quot;,&quot;DEN_LOCALIT&quot;,&quot;DEN_JUDET&quot;,&quot;SIMBAUTO&quot;,&quot;DEN_ACTIVIT&quot;,&quot;CODCATPRET&quot;,&quot;DEN_SUBUNIT&quot;,&quot;TIP&quot;,&quot;OBS_GEST&quot;,&quot;CLASA_CARACT&quot;,&quot;INACTIV&quot;,&quot;GEST_PRINCIPAL&quot;) AS
SELECT
 T1.CODGEST,
 T1.DEN_GEST,
 T1.SIMBOL,
 T1.CODACTIVIT,
 T2.DEN_LOCALIT,
 T3.DEN_JUDET,
 T3.SIMBAUTO,
 T4.DEN_ACTIVIT,
 T1.CODCATPRET,
 SUB.DEN_SUBUNIT,
 CASE COALESCE(G.TIP,0)
   WHEN 0 THEN &apos;Depozit sau Auxiliare&apos;
   WHEN 1 THEN &apos;Magazin&apos;
   WHEN 2 THEN &apos;Sectie productie&apos;
   WHEN 3 THEN &apos;Depozit de sectie&apos;
   WHEN 4 THEN &apos;Stocuri neconforme&apos;
   WHEN 5 THEN &apos;Parcela agricola&apos;
   WHEN 6 THEN &apos;Camera&apos;
   WHEN 7 THEN &apos;Parc auto&apos;
 END TIP,
 T1.OBS_GEST,
 T1.CLASA_CARACT,
 T1.INACTIV,
 T1.GEST_PRINCIPAL
FROM
 (SELECT A.CODGEST, A.DEN_GEST, A.SIMBOL, A.CODACTIVIT,
         A.CODCATPRET, A.CODSUBUNIT, COUNT(*) NRINREG,
         B.CODLOCALIT, A.OBS as OBS_GEST, NCL.DEN_CLASEG as CLASA_CARACT,
         A.INACTIV, A.gmaster as GEST_PRINCIPAL
      FROM
      NGEST A
      LEFT JOIN  NAGENDA B  ON A.CODGEST=B.CODGEST
      LEFT JOIN  NCATPRET CAT  ON CAT.CODCATPRET  = A.CODCATPRET
      LEFT JOIN  NCLASEG NCL on NCL.codclaseg = A.codclasa
 		WHERE pkg_nomgest.GESTIUNE_DEDICATA(a.codgest) = 1
          AND (pkg_categconst.GetValConstanta(&apos;Holding&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) &lt;&gt; 1 OR
               pkg_categconst.GetValConstanta(&apos;Holding&apos;, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) = 1 AND (A.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1))
		GROUP BY A.CODGEST, A.DEN_GEST, A.SIMBOL, A.CODACTIVIT, A.CODCATPRET, A.CODSUBUNIT, B.CODLOCALIT, A.OBS, NCL.DEN_CLASEG, A.INACTIV, A.gmaster)
  T1,
  NLOCALIT T2,
  NJUDET T3,
  NACTIVIT T4,
  NSUBUNIT SUB,
  NGEST G
WHERE
  T1.CODLOCALIT = T2.CODLOCALIT(+)
  AND T2.CODJUDET = T3.CODJUDET(+)
  AND NRINREG = 1
  AND T1.CODACTIVIT = T4.CODACTIVIT(+)
  AND T1.CODSUBUNIT = SUB.CODSUBUNIT(+)
  AND T1.CODGEST = G.CODGEST
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NGEST_CODGEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8CC93738F2BCFE601CC531B0786C6BE2F3BA67B5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NGEST_CODGEST (
&quot;CODGEST&quot;) AS
SELECT codgest FROM NGEST ORDER BY codgest 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NGEST_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C81E69864576AC8B1BCF571A46D5F71D8958BF6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NGEST_DOC (
&quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;SIMBOL&quot;,&quot;CODACTIVIT&quot;,&quot;INACTIV&quot;,&quot;DEN_LOCALIT&quot;,&quot;DEN_JUDET&quot;,&quot;SIMBAUTO&quot;,&quot;DEN_ACTIVIT&quot;,&quot;CODCATPRET&quot;,&quot;TIPCATPRET&quot;) AS
SELECT
  T1.CODGEST,
  T1.DEN_GEST,
  T1.SIMBOL,
  T1.CODACTIVIT,
  T1.INACTIV,
  T2.DEN_LOCALIT,
  T3.DEN_JUDET,
  T3.SIMBAUTO,
  T4.DEN_ACTIVIT,
  T1.CODCATPRET,
  T1.TIPCATPRET
FROM
(  SELECT
     A.CODGEST,
     A.DEN_GEST,
     A.SIMBOL,
     A.CODACTIVIT,
     NVL(A.INACTIV, 0) AS INACTIV,
     A.CODCATPRET,
     CAT.TIP AS TIPCATPRET,
     COUNT(*) NRINREG,
     B.CODLOCALIT
   FROM
     NGEST A
     LEFT JOIN  NAGENDA B     ON A.CODGEST = B.CODGEST
     LEFT JOIN  NCATPRET CAT   ON CAT.CODCATPRET = A.CODCATPRET
   WHERE
     (pkg_nomgest.GESTIUNE_DEDICATA(a.codgest) = 1 AND PKG_GLOBALS.SUBUNITATEDOC_VALIDA(a.codsubunit) = 1) OR a.codgest = 0
   GROUP BY A.CODGEST, A.DEN_GEST, A.SIMBOL, A.CODACTIVIT, NVL(A.INACTIV, 0),  A.CODCATPRET, CAT.TIP, B.CODLOCALIT ) T1,
NLOCALIT T2, NJUDET T3, NACTIVIT T4 WHERE T1.CODLOCALIT=T2.CODLOCALIT(+) AND T2.CODJUDET = T3.CODJUDET(+) AND NRINREG=1 AND T1.CODACTIVIT = T4.CODACTIVIT(+)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRSER_CODNIRSER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D69D120DE69612C1C39FE858338F721A72C9BE0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRSER_CODNIRSER (
&quot;CODNIRSER&quot;) AS
SELECT CodNIRSER FROM NIRSER ORDER BY CodNIRSER 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRSTOC_CODNIRSTOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>153D2506109B39B983DF9557EE522C656915F7EB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRSTOC_CODNIRSTOC (
&quot;CODNIRSTOC&quot;) AS
SELECT CodNirStoc FROM NIRSTOC ORDER BY CodNirStoc 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRURI_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A58FCAE5F7555916EB8E33C042F1248F42BB83D3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRURI_LUNA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM INTRARI I
  INNER JOIN NIR N ON N.CODINTR = I.CODINTR AND N.TIPNIR = I.TIPDOC
  INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC IN (1, 2, 3, 4, 5, 6, 7)
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND N.ANULAT = 0 AND N.OPERAT = 1
  AND IO.MG &lt;&gt; 5
UNION ALL
-- NIR-uri din IESIRI IN ROSU
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM IESIRI I
  INNER JOIN NIR N ON N.CODIES = I.CODIES AND N.TIPNIR = I.TIPDOC
  INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND I.AN*12+I.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE I.OPERAT = 1 AND I.ANULAT = 0 AND I.TIPDOC IN (14, 15, 19, 20, 21, 22, 23, 24, 25)
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND IO.MG &lt;&gt; 5
UNION ALL
-- NIR-uri din MISCARI INTERNE
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM TRANSF T
  INNER JOIN NIR N ON N.CODTRANSF = T.CODTRANSF AND N.TIPNIR = T.TIPDOC
  INNER JOIN NIRSTOC NS ON NS.CODNIR = N.CODNIR
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART AND T.AN*12+T.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
WHERE T.OPERAT = 1 AND T.ANULAT = 0 AND T.TIPDOC IN (12, 13)
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND N.ANULAT = 0 AND N.OPERAT = 1
  AND IO.MG &lt;&gt; 5</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRURI_LUNA_LA_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EA6ABC2E786EE7F6D135E07DDD4E9213FF9BC8FE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRURI_LUNA_LA_DATA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
AND N.DATANIR &lt;= PKG_GLOBALS.GETDATACALCULSTOC
AND NS.CODIOART = IO.CODIOART
AND IO.MG &lt;&gt; 5

UNION ALL
-- NIR-uri din IESIRI IN ROSU
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = N.CODIES,
  TMP_IOART_LUNA IO
WHERE
  N.TIPNIR IN (19, 20, 21, 22,23, 24, 25) AND  N.ANULAT = 0 AND N.OPERAT = 1
AND N.DATANIR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC
AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
AND NS.CODIOART = IO.CODIOART
AND IO.MG &lt;&gt; 5

UNION ALL

-- NIR-uri din MISCARI INTERNE
SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND N.DATANIR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRURI_SER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E72D85386B48F6423F9182D040B9529C993890C3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRURI_SER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = N.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (19, 20, 21, 22, 23, 24, 25) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

-- NIR-uri din MISCARI INTERNE
SELECT  NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIRURI_SER_LUNA_LADATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E941E9410550EE2B5426AAFEC0CBDB1C67BA7364</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIRURI_SER_LUNA_LADATA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND N.DATANIR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

SELECT NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN IESIRI I ON I.CODIES = N.CODIES,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (19, 20, 21, 22, 23, 24, 25) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND N.DATANIR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC
  AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5

UNION ALL

-- NIR-uri din MISCARI INTERNE
SELECT  NSE.CODNIRSER, NSE.CODNIRSTOC, NSE.CANTNIR AS REST, NSE.CANTUM1 AS RESTUM1, NSE.CANTUM2 AS RESTUM2
FROM
  NIRSER NSE,
  NIRSTOC NS
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF,
  TMP_IOART_LUNA IO
WHERE
  NSE.CODNIRSTOC = NS.CODNIRSTOC AND
  N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND N.DATANIR &lt;=  PKG_GLOBALS.GETDATACALCULSTOC
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND IO.CODIOART = NS.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NIR_CODNIR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85074AB46DBD968CEDA96C9756A2F60E0D678E83</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NIR_CODNIR (
&quot;CODNIR&quot;) AS
SELECT CodNIR FROM NIR ORDER BY CodNIR 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NMESERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>AB53353DE6B2CC1B3F68479AFBF094BBF0BEF6A4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NMESERII (
&quot;CODMESERIE&quot;,&quot;DEN_MESERIE&quot;) AS
select codmeserie, den_meserie
    from nmeserii 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NMODELEAUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>11E73B9F1A833DE3C1926A8CEA673CFC6958A2AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NMODELEAUTO (
&quot;CODMODELEAUTO&quot;,&quot;CODMARCIAUTO&quot;,&quot;MARCA&quot;,&quot;MODEL&quot;) AS
SELECT A.CODMODELEAUTO, B.CODMARCIAUTO, B.MARCA, A.MODEL
FROM NMODELEAUTO A LEFT JOIN NMARCIAUTO B ON B.CODMARCIAUTO = A.CODMARCIAUTO</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NODURIANALIZA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>005385535F61AA7D810102F447A792210526E735</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NODURIANALIZA (
&quot;CODANALIZANOD&quot;,&quot;SIMBOL&quot;,&quot;DENUMIRE&quot;,&quot;NIVEL&quot;,&quot;NODPARINTE&quot;,&quot;COPIL&quot;,&quot;CODANALIZA&quot;,&quot;CODASOCIAT&quot;,&quot;TIP&quot;,&quot;SIMBOLNOD&quot;,&quot;DENNOD&quot;) AS
WITH /*recursive*/ recA(CODANALIZANOD, CODANALIZA, CODDESCRIPTOR1, NODPARINTE, INACTIV, SIMBOLNOD, TIP, NIVEL, CODASOCIAT, SIMBOL, DENUMIRE, SEPA) AS (
  SELECT
    AN.CODANALIZANOD, AN.CODANALIZA, AN.CODDESCRIPTOR1, AN.NODPARINTE, AN.INACTIV, AN.SimbolNod, Coalesce(AN.Tip, D.Tip) Tip, 0 AS NIVEL,
    D1.CODASOCIAT,
    CASE WHEN aa.Tip = 1 THEN AN.SimbolNod ELSE LPAD(AN.POZITIE, 2, &apos;0&apos;) END SIMBOL,
		CASE WHEN aa.Tip = 1 THEN AN.Dennod    ELSE D1.VALOARE               END DENUMIRE,
    GSA.SepA
  FROM AnalizaNod AN
    LEFT JOIN Analiza aa ON aa.CodAnaliza = an.CodAnaliza
    LEFT JOIN DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
    LEFT JOIN DESCRIPTORI D ON D.CODDESCRIPTOR = D1.CODDESCRIPTOR
    CROSS JOIN (SELECT PKG_GLOBALS.GetSeparatorAdancime SepA FROM dual) GSA
  WHERE AN.NODPARINTE = 0
  UNION ALL
  SELECT
    AN.CODANALIZANOD, AN.CODANALIZA, AN.CODDESCRIPTOR1, AN.NODPARINTE, AN.INACTIV, AN.SimbolNod, Coalesce(AN.Tip, D.Tip) Tip, recA.NIVEL + 1 NIVEL,
    D1.CODASOCIAT,
    CASE WHEN aa.Tip = 1 THEN AN.SimbolNod WHEN recA.NIVEL = 0 THEN LPAD(AN.POZITIE, 2,&apos;0&apos;) ELSE recA.SIMBOL||&apos;.&apos;||LPAD(AN.POZITIE, 2,&apos;0&apos;) END SIMBOL,
		CASE WHEN aa.Tip = 1 THEN AN.Dennod    WHEN recA.NIVEL = 0 THEN D1.VALOARE              ELSE recA.DENUMIRE||recA.SepA||D1.VALOARE      END DENUMIRE,
    recA.SepA
  FROM recA
    INNER JOIN AnalizaNod AN ON An.NODPARINTE = recA.CODANALIZANOD
    LEFT JOIN Analiza aa ON aa.CodAnaliza = an.CodAnaliza
    LEFT JOIN DESCRIPTORI1 D1 ON AN.CODDESCRIPTOR1 = D1.CODDESCRIPTOR1
    LEFT JOIN DESCRIPTORI D ON D.CODDESCRIPTOR = D1.CODDESCRIPTOR
)
SELECT DISTINCT V.CODANALIZANOD, V.simbol, V.denumire, V.Nivel, V.NODPARINTE, Coalesce(N.NODPARINTE/* ??? NU AR TREBUI SA FIE N.CODANALIZANOD ??? */,0) AS COPIL, V.CODANALIZA, V.CODASOCIAT, V.Tip, V.SimbolNod,
       d1.valoare dennod
FROM recA V
     inner join analizanod a on a.codanalizanod = v.codanalizanod
     left join descriptori1 d1 on d1.coddescriptor1 = a.coddescriptor1
     LEFT OUTER JOIN ANALIZANOD N ON N.NODPARINTE = V.CODANALIZANOD
WHERE Coalesce(v.nodparinte,0) &lt;&gt; 0 and Coalesce(v.Inactiv,0)  &lt;&gt; 1
UNION ALL
SELECT 0 AS CODANALIZANOD, &apos;0&apos; as SIMBOL, &apos;... nedefinita ...&apos; AS DENUMIRE, 0 as NIVEL, 0 as NODPARINTE, 0 as COPIL, 0 as CODANALIZA, 0 CODASOCIAT, 0 TIP, &apos;?&apos; SimbolNod, &apos;... nedefinita ...&apos; AS DENNOD
FROM dual
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NOTECREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDD815F09F84145D8C5B328D68B0756DABCDDEC8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NOTECREDIT (
&quot;CODNCREDIT&quot;,&quot;CODCONTRACT2&quot;,&quot;CODPART&quot;,&quot;TIPDOC&quot;,&quot;DEN_PART&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;CONTRACT&quot;) AS
SELECT
    NC.CODNCREDIT,
    NC.CODCONTRACT2,
    NC.CODPART,
    NC.TIPDOC,
    P.DEN_PART,
    NC.DataStart,
    NC.DataStop,
    C.NRDOC Contract
  FROM
    NOTECREDIT NC
    INNER JOIN NPART P ON NC.CODPART = P.CODPART
    LEFT JOIN CONTRACT2 C2 ON NC.CODCONTRACT2 = C2.CODCONTRACT2
    LEFT JOIN CONTRACT C ON C2.CODCONTRACT = C.CODCONTRACT
  WHERE
    nvl(NC.Subunitatea, 1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(NC.Subunitatea,1),pkg_globals.GETSUBUNITATE) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPARCAUT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>715BF9D3AD3BC376399F0C6CDEB1223074D1017B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPARCAUT (
&quot;CODNPARCAUT&quot;,&quot;CODART&quot;,&quot;TIP&quot;,&quot;NRINV&quot;,&quot;NRINREG&quot;,&quot;SOFER&quot;,&quot;DENSOFER&quot;,&quot;MARCA&quot;,&quot;DENART&quot;,&quot;MASAU&quot;,&quot;VOLUMU&quot;,&quot;LUNG&quot;,&quot;LAT&quot;,&quot;INALT&quot;,&quot;CODMIFIX&quot;,&quot;PUTERE&quot;,&quot;TIPINCARC&quot;,&quot;CMM&quot;,&quot;EXTERN&quot;,&quot;PARTENER&quot;,&quot;CODMODEL&quot;,&quot;CODMARCA&quot;,&quot;MARCAAUTO&quot;,&quot;MODELAUTO&quot;,&quot;DEN_SUBUNIT&quot;,&quot;CODGEST&quot;,&quot;CODSUBUNIT&quot;,&quot;CODGRUPA&quot;,&quot;DENCLASA&quot;,&quot;IND&quot;,&quot;DEN_GEST&quot;,&quot;INACTIV&quot;,&quot;STARE&quot;,&quot;SERIEC&quot;,&quot;GENERIC&quot;,&quot;NRCONTR&quot;,&quot;SPOR_150_1&quot;,&quot;SPOR_150_2&quot;,&quot;SPOR150_215_1&quot;,&quot;SPOR150_215_2&quot;,&quot;SPOR215_1&quot;,&quot;SPOR215_2&quot;,&quot;CONSSTATH&quot;,&quot;DEN_PART&quot;,&quot;DEALER&quot;) AS
SELECT
  pa.CODNPARCAUT, pa.CODART, nvl(pa.TIP,0) TIP, pa.NRINV, pa.NRINREG,
	pa.SOFER, (npers.nume||&apos; &apos;||npers.prenume) densofer, npers.marca, nartobj.denumire denart,
  pa.MASAU, pa.VOLUMU, pa.lung, pa.lat, pa.inalt, null CODMIFIX, pa.putere, pa.tipincarc, pa.cmm, pa.extern, pa.partener,
	pa.Model CodModel, pa.marca CodMarca, nma.marca MArcaAuto, nmo.model ModelAuto,
  Sub.DEN_SUBUNIT DEN_SUBUNIT,
	Nvl(PA.CodGest, 0) CodGest,
	Nvl(G.CODSUBUNIT, 0) CODSUBUNIT,
	E.CodGrupa, GrE.Denumire DenClasa, Nvl(GrE.Ind, 0) Ind,
	G.DEN_GEST DEN_GEST,
  nvl(pa.inactiv,0) inactiv,
  case nvl(pa.inactiv,0)
    when 0 then &apos;Activ&apos;
    when 2 then &apos;Conservare&apos;
    when 3 then &apos;Dauna totala&apos;
    when 4 then &apos;La vanzare&apos;
    when 1 then &apos;Vandut&apos;
    when 5 then &apos;Radiat&apos;
  end Stare,
  pa.seriec, E.Generic, pa.nrcontr,
  rem.SPOR_150_1,rem.SPOR_150_2,rem.SPOR150_215_1,
  rem.SPOR150_215_2,rem.SPOR215_1,rem.SPOR215_2, pa.consstath, p.Den_Part, dl.den_part as dealer
FROM nparcaut pa
  LEFT JOIN npers ON pa.sofer = npers.codpers
  LEFT JOIN nartobj on pa.codart = nartobj.codobiect
  Left join NEchiv  E  on E.Codobiect = nartobj.codobiect
  Left join GrEchiv GrE  on GrE.CODGRECHIV = E.CodGrupa
	Left join nmarciauto nma on nma.CODMARCIAUTO = pa.Marca
	Left join nmodeleauto nmo on nmo.CODMODELEAUTO = pa.model
  LEFT JOIN NGEST G on G.CODGEST = PA.CODGEST
  LEFT JOIN NPART P on P.CODPART = PA.PARTENER
	LEFT JOIN NSUBUNIT SUB on SUB.CODSUBUNIT = G.CODSUBUNIT
  LEFT JOIN NPART DL ON DL.CODPART = PA.CODDEALER
  left join nremauto rem on rem.codremauto = pa.tiprem
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPARCAUTO_GEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E43F33FA15885C572EB806C5FCD84BE131A664A2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPARCAUTO_GEST (
&quot;CODAUTO&quot;,&quot;CODGEST&quot;,&quot;DATAIN&quot;,&quot;DATAOUT&quot;) AS
with Crono as ( Select RowNum Poz, p.CodNparcAut CodAuto, p.CodGest, P.Data
                from (select * from nparcG where Nvl(CodGest, 0) &gt; 0 order by CodNParcAut, Data) p )
 Select x.CodAuto,
        x.CodGest,
        x.Data DataIn,
        Nvl(Y.Data, SysDate) DataOut
  from Crono X
	left join Crono Y on X.Codauto = Y.CodAuto and y.poz = x.Poz + 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPARCAUT_SOFER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61F6E30E2DCB8944B9A500DA075E8DFD373940A4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPARCAUT_SOFER (
&quot;CODNPARCAUT&quot;,&quot;CODART&quot;,&quot;NRINV&quot;,&quot;NRINREG&quot;,&quot;SOFER&quot;,&quot;DENSOFER&quot;,&quot;DENART&quot;,&quot;INACTIV&quot;) AS
select
  nparcaut.CODNPARCAUT,
  nparcaut.CODART,
  nparcaut.NRINV,
  nparcaut.NRINREG,
  nparcaut.SOFER,
  (npers.nume||&apos; &apos;||npers.prenume) as densofer, nartobj.denumire as denart,
  nvl(nparcaut.inactiv,0) inactiv
    from nparcaut
    left join npers on nparcaut.sofer = npers.codpers
    left join nartobj on nparcaut.codart = nartobj.codobiect
   where nparcaut.sofer = pkg_nompers.GET_PERSOANA_CURENTA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26A850D8D86605393433BCEC542EACCCD221D610</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPART (
&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;CODAGENT&quot;,&quot;CODMONEDA&quot;,&quot;DEN_LOCALIT&quot;,&quot;COD_CODFISCAL&quot;,&quot;CODFISCAL&quot;,&quot;BLOCAT&quot;,&quot;SCADENTAC&quot;,&quot;SCADENTAV&quot;,&quot;STATCOMUNITAR&quot;,&quot;DEN_TARA&quot;,&quot;TIPCATPRET&quot;,&quot;CODCATPRET&quot;,&quot;TIPPARTENER&quot;,&quot;AUTORIZATIE&quot;,&quot;STRATEGIC&quot;,&quot;LEAD&quot;,&quot;SIMBAUTO&quot;,&quot;CODCLASA&quot;,&quot;CIFRAAFACERI&quot;,&quot;DENDOMENIUACT&quot;,&quot;RESPONSABILSRV&quot;,&quot;NRANGAJATI&quot;,&quot;REGCOM&quot;,&quot;DEN_JUDET&quot;,&quot;AGENT&quot;,&quot;DENCAMPANIE&quot;,&quot;ACTIVITPROPRIE&quot;,&quot;SIMBOLCLASA&quot;,&quot;OBS&quot;,&quot;IESCUCOMANDA&quot;,&quot;CONTBANCA&quot;,&quot;PERSOANAFIZICA&quot;,&quot;DATAADAUGARII&quot;) AS
SELECT
  P.CODPART,
  P.DEN_PART,
  P.CODEXTERN,
  P.CODINTERN,
  A.CODAGENT,
  P.CODMONEDA,
  L.DEN_LOCALIT,
  F.COD_CODFISCAL AS COD_CODFISCAL,
  F.CODFISCAL AS CODFISCAL,
  P.BLOCAT,
  P.SCADENTAC,
  P.SCADENTAV,
  T.STATCOMUNITAR,
  T.DEN_TARA,
  CAT.TIP AS TIPCATPRET,
  CAT.CODCATPRET,
  P.TIPPARTENER,
  P.AUTORIZATIE,
  P.STRATEGIC,
  P.LEAD,
  J.SIMBAUTO,
  P.CODCLASA,
  CRM.CifraAfaceri,
  DAX.DenDomeniuAct,
  NP.Prenume || &apos; &apos; || NP.Nume AS ResponsabilSrv,
  CRM.NrAngajati,
  P.RegCom,
  J.Den_Judet,
  NPA.Prenume || &apos; &apos; || NPA.Nume AS Agent,
  C.DenCampanie,
  pkg_nompart.GET_PARTACTIVIT(p.codpart) ActivitProprie,
  CLP.SIMBOL AS SIMBOLCLASA,
  P.OBS,
  P.IESCUCOMANDA,
  PB.CONTBANCA,
  P.PERSOANAFIZICA,
  P.DATAADAUGARII
FROM
  NPART P
  LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = P.CODCATEGPRET
  LEFT JOIN NPARTCODFISC F ON F.CODPART = P.CODPART AND F.PRINCIPAL = 1
  LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART AND Nvl(a.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 4) &lt;&gt; 0)
  LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
  LEFT JOIN NJUDET J ON J.CodJudet = L.CodJudet
  LEFT JOIN NTARI T ON T.CODTARA = L.CODTARA
  LEFT JOIN DOMENIIACT DA ON DA.CodDomeniuAct = P.CodDomeniuAct
  LEFT JOIN NPERS NP ON NP.Codpers = P.CodResponsabil
  LEFT JOIN NPERS NPA ON NPA.CodPers = A.CodAgent
  LEFT JOIN NCLASEP CLP ON CLP.CODCLASEP = P.CODCLASA
  LEFT JOIN NPARTB PB ON PB.CODPART = P.CODPART AND NVL(PB.IMPLICIT, 0) = 1
  LEFT JOIN (
    SELECT ccp.codpart, MAX(ccp.codcampaniepart) KEEP (Dense_Rank LAST ORDER BY cc.DataInit) codcampaniepart
    FROM CampaniiPart CCP INNER JOIN Campanii cc ON cc.codcampanie = ccp.codcampanie
    GROUP BY ccp.codpart
  ) xC ON xC.CodPart = P.CodPart
  LEFT JOIN (
             SELECT stragg3200(D.DENDOMENIUACT) DENDOMENIUACT, N1.CODPART
             FROM npartdomact ND
                  INNER JOIN NPART1CRM N1 ON ND.CODPART1CRM = N1.CODPART1CRM AND N1.CODPART = ND.CODPART
                  INNER JOIN domeniiact D ON D.CODDOMENIUACT = ND.CODDOMENIUACT
             WHERE
               last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;))
               between n1.datastart and n1.dataend
               or
               (last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;)) &gt;= n1.datastart and n1.dataend is null)
             GROUP BY N1.CODPART
            ) DAX ON DAX.CODPART = P.CODPART
  LEFT JOIN (
             SELECT N1.CODPART, N1.NRANGAJATI, N1.CIFRAAFACERI
             FROM NPART1CRM N1
             WHERE
               last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;))
               between n1.datastart and n1.dataend
               or
               (last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;)) &gt;= n1.datastart and n1.dataend is null)
            ) CRM ON CRM.CODPART = P.CODPART
  LEFT JOIN CAMPANIIPART CP ON CP.codcampaniepart = xc.codcampaniepart
  LEFT JOIN CAMPANII C ON C.codcampanie = cp.codcampanie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPART1_CODPART1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>648914BED9AE64AA60CA17FFE95E06764B249CBC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPART1_CODPART1 (
&quot;CODPART1&quot;) AS
SELECT CodPart1 FROM NPART1 ORDER BY CodPart1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPARTDISC_CODPARTDISC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>864B8D3EF509F4DE0176FA6A6D4AE9E71FD5F160</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPARTDISC_CODPARTDISC (
&quot;CODPARTDISC&quot;) AS
SELECT CodPartDisc FROM NPARTDISC ORDER BY CodPartDisc 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPARTTR_CODPARTTR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC14931FE856EAB27AEE07C156450B4266F57677</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPARTTR_CODPARTTR (
&quot;CODPARTTR&quot;,&quot;DELEGAT&quot;,&quot;MIJLTRANSP&quot;,&quot;NRTRANSP&quot;,&quot;ACTIV&quot;,&quot;CODPERS&quot;,&quot;TELEFON&quot;) AS
SELECT CODPARTTR, DELEGAT, MIJLTRANSP, NRTRANSP, ACTIV,CODPERS,TELEFON FROM NPARTTR ORDER BY CodPartTr
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPART_CODPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6413206E119575D5DE1AC5A8768C3A6D742B818A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPART_CODPART (
&quot;CODPART&quot;) AS
SELECT CodPart FROM NPART ORDER BY CodPart 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPART_LEADS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BD54CECEC469FDDB10425B73039A683EBF63BC4C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPART_LEADS (
&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;CODAGENT&quot;,&quot;CODMONEDA&quot;,&quot;DEN_LOCALIT&quot;,&quot;COD_CODFISCAL&quot;,&quot;CODFISCAL&quot;,&quot;BLOCAT&quot;,&quot;SCADENTAC&quot;,&quot;SCADENTAV&quot;,&quot;STATCOMUNITAR&quot;,&quot;DEN_TARA&quot;,&quot;TIPCATPRET&quot;,&quot;CODCATPRET&quot;,&quot;TIPPARTENER&quot;,&quot;AUTORIZATIE&quot;,&quot;STRATEGIC&quot;,&quot;LEAD&quot;,&quot;SIMBAUTO&quot;,&quot;CODCLASA&quot;,&quot;CIFRAAFACERI&quot;,&quot;DENDOMENIUACT&quot;,&quot;RESPONSABILSRV&quot;,&quot;NRANGAJATI&quot;,&quot;REGCOM&quot;,&quot;DEN_JUDET&quot;,&quot;AGENT&quot;,&quot;DENCAMPANIE&quot;,&quot;ACTIVITPROPRIE&quot;,&quot;SIMBOLCLASA&quot;,&quot;OBS&quot;,&quot;IESCUCOMANDA&quot;,&quot;CONTBANCA&quot;) AS
SELECT
  P.CODPART,
  P.DEN_PART,
  P.CODEXTERN,
  P.CODINTERN,
  A.CODAGENT,
  P.CODMONEDA,
  L.DEN_LOCALIT,
  F.COD_CODFISCAL AS COD_CODFISCAL,
  F.CODFISCAL AS CODFISCAL,
  P.BLOCAT,
  P.SCADENTAC,
  P.SCADENTAV,
  T.STATCOMUNITAR,
  T.DEN_TARA,
  CAT.TIP AS TIPCATPRET,
  CAT.CODCATPRET,
  P.TIPPARTENER,
  P.AUTORIZATIE,
  P.STRATEGIC,
  NVL(LEADS.LEAD,0) LEAD,
  J.SIMBAUTO,
  P.CODCLASA,
  P.CifraAfaceri,
  DAX.DenDomeniuAct,
  NP.Prenume || &apos; &apos; || NP.Nume AS ResponsabilSrv,
  P.NrAngajati,
  P.RegCom,
  J.Den_Judet,
  NPA.Prenume || &apos; &apos; || NPA.Nume AS Agent,
  C.DenCampanie,
  pkg_nompart.GET_PARTACTIVIT(p.codpart) ActivitProprie,
  CP.SIMBOL AS SIMBOLCLASA,
  P.OBS,
  P.IESCUCOMANDA,
  PB.CONTBANCA
FROM
  NPART P
  LEFT JOIN NCATPRET CAT ON CAT.CODCATPRET = P.CODCATEGPRET
  LEFT JOIN NPARTCODFISC F ON F.CODPART = P.CODPART AND F.PRINCIPAL = 1
  LEFT JOIN NAGENDA A ON A.CODPART = P.CODPART AND Nvl(a.Inactiv,0) = 0 AND (BITAND(A.SEDIUSOCIAL, 4) &lt;&gt; 0)
  LEFT JOIN NLOCALIT L ON L.CODLOCALIT = A.CODLOCALIT
  LEFT JOIN NJUDET J ON J.CodJudet = L.CodJudet
  LEFT JOIN NTARI T ON T.CODTARA = L.CODTARA
  LEFT JOIN DOMENIIACT DA ON DA.CodDomeniuAct = P.CodDomeniuAct
  LEFT JOIN NPERS NP ON NP.Codpers = P.CodResponsabil
  LEFT JOIN NPERS NPA ON NPA.CodPers = A.CodAgent
  LEFT JOIN NCLASEP CP ON CP.CODCLASEP = P.CODCLASA
  LEFT JOIN NPARTB PB ON PB.CODPART = P.CODPART AND NVL(PB.IMPLICIT, 0) = 1
  LEFT JOIN (
    SELECT ccp.codpart, MAX(ccp.codcampaniepart) KEEP (Dense_Rank LAST ORDER BY cc.DataInit) codcampaniepart
    FROM CampaniiPart CCP INNER JOIN Campanii cc ON cc.codcampanie = ccp.codcampanie
    GROUP BY ccp.codpart
  ) xC ON xC.CodPart = P.CodPart
  LEFT JOIN (
             SELECT stragg3200(D.DENDOMENIUACT) DENDOMENIUACT, N1.CODPART
             FROM npartdomact ND
                  INNER JOIN NPART1CRM N1 ON ND.CODPART1CRM = N1.CODPART1CRM AND N1.CODPART = ND.CODPART
                  INNER JOIN domeniiact D ON D.CODDOMENIUACT = ND.CODDOMENIUACT
             WHERE
               last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;))
               between n1.datastart and n1.dataend
               or
               (last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;)) &gt;= n1.datastart and n1.dataend is null)
             GROUP BY N1.CODPART
            ) DAX ON DAX.CODPART = P.CODPART
  LEFT JOIN (
             SELECT DISTINCT N1.CODPART, LAST_VALUE(N1.LEAD) over (partition by n1.codpart order by n1.datastart) LEAD
             FROM NPART1CRM N1
             WHERE
               last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;))
               between n1.datastart and n1.dataend
               or
               (last_day(to_date(&apos;01.&apos;||lpad(to_char(PKG_GLOBALS.GetLUNALUCRU),2,&apos;0&apos;)||&apos;.&apos;||to_char(PKG_GLOBALS.GetANLUCRU),&apos;dd.mm.yyyy&apos;)) &gt;= n1.datastart and n1.dataend is null)
            ) LEADS ON LEADS.CODPART = P.CODPART
  LEFT JOIN CAMPANIIPART CP ON CP.codcampaniepart = xc.codcampaniepart
  LEFT JOIN CAMPANII C ON C.codcampanie = cp.codcampanie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NPART_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7299FCFC945B8E6F798AB0EFA4DEE6BBC8C85180</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NPART_LUNA (
&quot;CODPART&quot;,&quot;CODPART1&quot;,&quot;DEN_PART&quot;,&quot;CODIOPART&quot;,&quot;CREDITCLIENT&quot;,&quot;VOLUMTRANZC&quot;,&quot;CREDITFURN&quot;,&quot;VOLUMTRANZF&quot;,&quot;CODIOPART1&quot;,&quot;DEN_IOPART&quot;,&quot;CONTFURNIZOR&quot;,&quot;CONTCLIENT&quot;,&quot;CONTFURNAVANS&quot;,&quot;CONTCLIENTAVANS&quot;,&quot;CONTFURNAVIZ&quot;,&quot;CONTCLIENTAVIZ&quot;,&quot;CONTFURNMF&quot;,&quot;CONTCREDITD&quot;,&quot;CONTDEBITD&quot;,&quot;CONTLITIGII&quot;,&quot;CONTFURNAVS&quot;,&quot;CONTFURNAVIC&quot;,&quot;CONTFURNAVIN&quot;,&quot;CONTTERTI&quot;,&quot;CONTFURNLEAS&quot;,&quot;CONTNCRF&quot;,&quot;CONTNCRC&quot;,&quot;CONTCHELTAVANS&quot;,&quot;CONTVENITAVANS&quot;,&quot;CONTGARANTIEEF&quot;,&quot;CONTGARANTIETF&quot;,&quot;CONTGARANTIEEC&quot;,&quot;CONTGARANTIETC&quot;,&quot;CONTSUPLIMF1&quot;,&quot;CONTSUPLIMF2&quot;,&quot;CONTSUPLIMF3&quot;,&quot;CONTSUPLIMF4&quot;,&quot;CONTSUPLIMF5&quot;,&quot;CONTSUPLIMC1&quot;,&quot;CONTSUPLIMC2&quot;,&quot;CONTSUPLIMC3&quot;,&quot;CONTSUPLIMC4&quot;,&quot;CONTSUPLIMC5&quot;,&quot;TVANEEXF&quot;,&quot;TVANEEXC&quot;,&quot;TIP&quot;,&quot;CASSBAZAMIN&quot;,&quot;SIMBOLCASS&quot;,&quot;TVANEEXP&quot;,&quot;TVANEEXI&quot;) AS
SELECT n.codpart, n1.codpart1, n.den_part, nvl(n1.codiopart,0)codiopart, n1.creditclient,n1.volumtranzc,n1.creditfurn,n1.volumtranzf,
       io1.codiopart1,io.den_iopart,io1.contfurnizor,io1.contclient,io1.contfurnavans,io1.contclientavans,
       io1.contfurnaviz,io1.contclientaviz,io1.contfurnmf,io1.contcreditd,io1.contdebitd,io1.contlitigii,io1.contfurnavs,
			 io1.contfurnavic,io1.contfurnavin,
			 io1.contterti,
			 io1.contfurnLeas,
       io1.contncrf        ,
       io1.contncrc        ,
       io1.contcheltavans  ,
       io1.contvenitavans  ,
       io1.contgarantieEF   ,
       io1.contgarantieTF   ,
       io1.contgarantieEC   ,
       io1.contgarantieTC   ,
			 io1.ContSuplimF1 ,
			 io1.ContSuplimF2 ,
			 io1.ContSuplimF3 ,
			 io1.ContSuplimF4 ,
			 io1.ContSuplimF5 ,
			 io1.ContSuplimC1 ,
			 io1.ContSuplimC2 ,
			 io1.ContSuplimC3 ,
			 io1.ContSuplimC4 ,
			 io1.ContSuplimC5 ,
			 io1.tvaneexf,io1.tvaneexc,io1.tip, n1.CASSBAZAMIN, n1.SimbolCASS,io1.tvaneexP,io1.tvaneexI
FROM npart n LEFT OUTER JOIN npart1 n1 ON n.codpart = n1.codpart
             LEFT OUTER JOIN iopart io ON nvl(n1.codiopart,0) = nvl(io.codiopart,0)
						 LEFT OUTER JOIN iopart1 io1 ON io.codiopart = io1.codiopart
  WHERE n1.anstart * 12 + n1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM npart1 np1
                                             WHERE np1.codpart = n1.codpart AND
					   anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
					  )
	AND
	  io1.anstart * 12 + io1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM iopart1 i1
                                             WHERE i1.codiopart = io1.codiopart AND
                                              anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
              )

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B9CF4812FC89EA0E6B08612C574CF2EDDA3BFDA0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NSUBUNIT (
&quot;CODSUBUNIT&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_LOCALIT&quot;,&quot;DEN_JUDET&quot;,&quot;SIMBAUTO&quot;,&quot;SIMBAUTOTARA&quot;,&quot;STATCOMUNITAR&quot;,&quot;DEN_CONT&quot;,&quot;NRCONT&quot;,&quot;CODLOCALIT&quot;) AS
select t1.codsubunit ,t1.den_subunit, t2.den_localit, t3.den_judet, t3.simbauto,t4.simbauto as SimbAutoTara, t4.statcomunitar,
       nbk.den_cont,nbk.nrcont, t2.CodLocalit
from (  select a.codsubunit, a.codbankcont , a.den_subunit, count(*) nrinreg, b.codlocalit
      from nsubunit a, nagenda b where  a.codsubunit=b.codsubunit(+) AND a.codsubunit &lt;&gt; 1
      group by a.codsubunit,a.codbankcont, a.den_subunit, b.codlocalit ) t1, nlocalit t2, njudet t3, ntari t4, nbankcont nbk
where t1.codlocalit=t2.codlocalit(+) and t2.codjudet = t3.codjudet(+) and t2.codtara = t4.codtara(+)
      AND t1.codbankcont = nbk.codbankcont(+)
      and nrinreg=1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NSUBUNIT1_CODSUBUNIT1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C29C61D28A4A5D974310D566160D2D5E44792651</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NSUBUNIT1_CODSUBUNIT1 (
&quot;CODSUBUNIT1&quot;) AS
SELECT CodSubunit1 FROM NSUBUNIT1 ORDER BY CodSubunit1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NSUBUNIT_CODSUBUNIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6B38340689E8F52039085360245A8EBF8B54B5A0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NSUBUNIT_CODSUBUNIT (
&quot;CODSUBUNIT&quot;) AS
SELECT codsubunit FROM NSUBUNIT ORDER BY codsubunit 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTAXE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2F09BE9C2B11760304BE5200B99B3C86FEB264AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTAXE (
&quot;CODTAXA&quot;,&quot;DEN_TAXA&quot;,&quot;ACTIV&quot;) AS
SELECT &quot;CODTAXA&quot;,
       &quot;DEN_TAXA&quot;, 
 NVL((SELECT 
     MAX(ANSTART * 12 + LUNASTART) FROM NTAXE1 
     WHERE 
     CODTAXA = T.CODTAXA AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0) 
 AS ACTIV
FROM 
NTAXE T 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTAXE1_CODTAXA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9E017903706C2CDADB2C212B8B7FE0A65451C82C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTAXE1_CODTAXA1 (
&quot;CODTAXA1&quot;) AS
SELECT CodTaxa1 FROM NTAXE1 ORDER BY CodTaxa1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTAXE_CODTAXA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>724B51326CB288F4280A5B1A027B81B2A48A532E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTAXE_CODTAXA (
&quot;CODTAXA&quot;) AS
SELECT CodTaxa FROM NTAXE ORDER BY CodTaxa 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTAXE_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>62B4EA3019A4B4D76BA54347CB0C3934E3961F84</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTAXE_LUNA (
&quot;CODTAXA&quot;,&quot;CODTAXA1&quot;,&quot;DEN_TAXA&quot;,&quot;VALOARE&quot;,&quot;LACEAPLIC&quot;,&quot;CODCONT&quot;,&quot;CODCONTCHELT&quot;,&quot;ORICARETIP&quot;,&quot;CODIOARTEXCL&quot;,&quot;EXCLUSACCIZE&quot;,&quot;EXCLUSEXPORT&quot;,&quot;JACHIZ&quot;,&quot;JVANZ&quot;,&quot;CUMJACHIZ&quot;,&quot;CUMJVANZ&quot;,&quot;BAZAMAX&quot;,&quot;BAZAMIN&quot;,&quot;CODSERVFACT&quot;,&quot;FACTURABIL&quot;,&quot;STOPAJ&quot;) AS
SELECT n.codtaxa,n1.codtaxa1,n.den_taxa,n1.valoare,n1.laceaplic,n1.codcont,n1.codcontchelt,n1.oricaretip,
       n1.codioartexcl,n1.exclusaccize,n1.exclusexport,n1.jachiz,n1.jvanz,n1.cumjachiz,n1.cumjvanz,n1.BazaMax,
			 n1.BazaMin,n1.codservfact,n1.facturabil,n1.stopaj
FROM
ntaxe n LEFT JOIN ntaxe1 n1
ON n.codtaxa = n1.codtaxa
  WHERE n1.anstart * 12 + n1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM ntaxe1 nt1
                                             WHERE nt1.codtaxa = n1.codtaxa AND
					  anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
					)

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>26B50590FA6EC5112EF276E21CE1508AE6DE8CC9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTVA (
&quot;CODTVA&quot;,&quot;DEN_TVA&quot;,&quot;ACTIV&quot;,&quot;PROCENT&quot;) AS
SELECT DISTINCT T.CODTVA,  T.DEN_TVA, NVL(T1.CODTVA, 0)  ACTIV,  NVL(T1.PROCENT, 0) PROCENT
FROM
  NTVA T LEFT OUTER JOIN NTVA1 T1 ON T1.CODTVA = T.CODTVA
WHERE
 T1.ANSTART * 12 + T1.LUNASTART = (SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART) FROM NTVA1 T2 WHERE T2.CODTVA = T.CODTVA
 AND T2.ANSTART * 12 + T2.LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTVA1_CODTVA1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3D2B2CAAE1CE50FF9FACA51C9771E926864D10DF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTVA1_CODTVA1 (
&quot;CODTVA1&quot;) AS
SELECT CodTva1 FROM NTVA1 ORDER BY CodTva1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTVA_CODTVA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B16986F177CBB398F2D61F77E259BC08DC7F0589</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTVA_CODTVA (
&quot;CODTVA&quot;) AS
SELECT CodTva FROM NTVA ORDER BY CodTva 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_NTVA_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>43454FE75ACA5CA3D1039D0F12B9B5351CD30FA7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_NTVA_LUNA (
&quot;CODTVA&quot;,&quot;CODTVA1&quot;,&quot;DEN_TVA&quot;,&quot;PROCENT&quot;,&quot;CODCONTDED&quot;,&quot;CODCONTCOLE&quot;,&quot;CODCONTNEEX&quot;) AS
SELECT n.codtva,n1.codtva1,n.den_tva,n1.procent,n1.codcontded,n1.codcontcole,n1.codcontneex
FROM ntva n LEFT JOIN ntva1 n1
ON 	n.codtva = n1.codtva
   WHERE n1.anstart * 12 + n1.lunastart = (SELECT MAX(anstart * 12 + lunastart) FROM ntva1 nt1
                                             WHERE nt1.codtva = n1.codtva AND
					     anstart * 12 + lunastart &lt;= pkg_globals.AnLunaLucru
					   ) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBIECTEECHIVALENTE_CUMUL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B53190A17F0609D1646946FA3FF1259D385E1C74</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBIECTEECHIVALENTE_CUMUL (
&quot;CODOBIECT&quot;,&quot;DENOBIECT&quot;,&quot;CODEXTERN&quot;,&quot;PARITATE&quot;,&quot;CODGRUPA&quot;,&quot;NECESAR&quot;,&quot;TIP&quot;) AS
SELECT
  O.&quot;CODOBIECT&quot;, O.&quot;DENUMIRE&quot; DENOBIECT, O.&quot;CODEXTERN&quot;, E.PARITATE, 0 CODGRUPA, E.PARITATE * PKG_PROIECT.GETNECESAR NECESAR, &apos;ECH.RETETA&apos; TIP
FROM
  PRODMATECHIV E
  inner join NARTOBJ O on e.codobiect = o.codobiect
WHERE
  E.CODMAT = PKG_PRODCOMP.GET_MAT_ECHIVALAT
UNION ALL
SELECT
  O.&quot;CODOBIECT&quot;, O.&quot;DENUMIRE&quot; DENOBIECT, O.&quot;CODEXTERN&quot;, E.PARITATE, E.CODGRUPA, E.PARITATE * PKG_PROIECT.GETNECESAR NECESAR, &apos;ECH.GRUPA&apos; TIP
FROM
  NECHIV E
  inner join NARTOBJ O on e.codobiect = o.codobiect
WHERE
  E.CODGRUPA = PKG_SELECTARTICOLE.GET_GRUPA_OBIECT_ECHIVALAT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBIECTEECHIVALENTE_RETETA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>21EB9D2CE65B882E1FFD5D62BEBBA494B1F97B05</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBIECTEECHIVALENTE_RETETA (
&quot;CODOBIECT&quot;,&quot;DENOBIECT&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;PARITATE&quot;,&quot;CODGRUPA&quot;,&quot;NECESAR&quot;) AS
SELECT
  O.&quot;CODOBIECT&quot;, O.&quot;DENUMIRE&quot; DENOBIECT, O.&quot;CODEXTERN&quot;, O.&quot;CODINTERN&quot;, E.PARITATE, 0 CODGRUPA, E.PARITATE * PKG_PROIECT.GETNECESAR NECESAR
FROM
  PRODMATECHIV E
  inner join NARTOBJ O on e.codobiect = o.codobiect
WHERE
  E.CODMAT = PKG_SELECTARTICOLE.GET_GRUPA_OBIECT_ECHIVALAT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBIECTEECHIVALENTE_SIMPLU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0011ED1C5E5B3111E8F5E09C8299634BD5198A24</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBIECTEECHIVALENTE_SIMPLU (
&quot;CODOBIECT&quot;,&quot;DENOBIECT&quot;,&quot;CODEXTERN&quot;,&quot;PARITATE&quot;,&quot;CODGRUPA&quot;,&quot;NECESAR&quot;,&quot;CODINTERN&quot;) AS
SELECT
  O.&quot;CODOBIECT&quot;, O.&quot;DENUMIRE&quot; DENOBIECT, O.&quot;CODEXTERN&quot;,
	E.PARITATE / PKG_SELECTARTICOLE.GET_PARITATE_OBIECT_ECHIVALAT PARITATE,
	E.CODGRUPA,
	E.PARITATE * PKG_PROIECT.GETNECESAR NECESAR,
	O.CODINTERN
FROM
  NECHIV E
  inner join NARTOBJ O on e.codobiect = o.codobiect
WHERE
  E.CODGRUPA = PKG_SELECTARTICOLE.GET_GRUPA_OBIECT_ECHIVALAT
union all
SELECT
  0 , &apos;..nedefinit..&apos;, null, 1, 0, 1, null
FROM dual
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBINV</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF10B345CFEAC070FA2C640BE68F8D50AA2CABEB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBINV (
&quot;CODNIRSTOC&quot;,&quot;PRET&quot;,&quot;DENUMIRE&quot;,&quot;DEN_GEST&quot;,&quot;CODGEST&quot;,&quot;DEN_IOART&quot;,&quot;DATANIR&quot;,&quot;STOC&quot;,&quot;DETALIULUNA&quot;,&quot;REZOLVAT&quot;,&quot;OK&quot;,&quot;DEN_SUBUNIT&quot;) AS
SELECT
  MIFIX.&quot;CODNIRSTOC&quot;,
  MIFIX.&quot;PRET&quot;,
  MIFIX.&quot;DENUMIRE&quot;,
  MIFIX.&quot;DEN_GEST&quot;,
  MIFIX.&quot;CODGEST&quot;,
  MIFIX.&quot;DEN_IOART&quot;,
  MIFIX.&quot;DATANIR&quot;,
  MIFIX.&quot;STOC&quot;,
  MIFIX.&quot;DETALIULUNA&quot;,
  MIFIX.&quot;REZOLVAT&quot;,
  CASE
    WHEN MIFIX.STOC = MIFIX.REZOLVAT THEN 1
    ELSE 0
  END
  AS OK,
   MIFIX.&quot;DEN_SUBUNIT&quot;
FROM
  (
  SELECT
    NS.CODNIRSTOC,
    NS.PRET,
    O.DENUMIRE,
    G.DEN_GEST,
    G.CODGEST,
    IO.DEN_IOART,
    N.DATANIR,
    PKG_INTRARI.GET_REST_STOC_IN_LUNA(NS.CODNIRSTOC, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU) AS STOC,
    NVL((SELECT SUM(CANT) FROM MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GETANLUCRU AND LUNASTART = PKG_GLOBALS.GETLUNALUCRU  AND STARE IN (1, 2)), 0) AS REZOLVAT,
    NVL((SELECT COUNT(*) FROM MIFIX1 WHERE CODNIRSTOC = NS.CODNIRSTOC AND ANSTART = PKG_GLOBALS.GETANLUCRU AND LUNASTART = PKG_GLOBALS.GETLUNALUCRU ), 0) AS DETALIULUNA,
    SUB.DEN_SUBUNIT
  FROM
    NIRSTOC NS,
    NIR N,
    NGEST G,
    NSUBUNIT SUB,
    NARTOBJ O,
    IOART IO,
    /*
    (SELECT CODIOART, CONT FROM IOART1 IO1  WHERE
     IO1.ANSTART * 12 + IO1.LUNASTART =
    (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
     WHERE
      IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     )*/
     TMP_IOART_LUNA IOALUNA
  WHERE
    N.CODNIR = NS.CODNIR AND
    EXTRACT(YEAR FROM N.DATANIR) * 12 + EXTRACT(MONTH FROM N.DATANIR) &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
    NS.CODIOART = IOALUNA.CODIOART AND
    PKG_CATEGCONST.ESTEOBINV(IOALUNA.CONT) = 1 AND
    N.GEST = G.CODGEST AND
    SUB.CODSUBUNIT = G.CODSUBUNIT AND
    NS.CODOBIECT = O.CODOBIECT AND
    NVL(G.CODSUBUNIT,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE) AND
    IOALUNA.CODIOART = IO.CODIOART
  ) MIFIX
WHERE
--(STOC &lt;&gt; 0) OR (STOC = 0 AND REZOLVAT &lt;&gt; 0)OR(STOC=0 AND REZOLVAT = 0)
(STOC &lt;&gt; 0) OR (STOC = 0 AND REZOLVAT &lt;&gt; 0)OR(STOC=0 AND REZOLVAT = 0 AND DETALIULUNA &gt; 0) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBJART_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B36A8E6AD6AC8B66D05F14F40DCA7F151BF4CFEC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBJART_EXT (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;TERMENPLATA&quot;,&quot;PROCADAOSNIR&quot;,&quot;PROMOTIE&quot;,&quot;BLOCAT&quot;,&quot;NEFACTURABIL&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;TIPPRETMAX&quot;,&quot;PUMAXLUNA&quot;,&quot;DENOBIECT&quot;,&quot;RELATIEUM1&quot;,&quot;RELATIEUM2&quot;,&quot;PRETVANZARE&quot;,&quot;PRETVALUTA&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTUNJIRE&quot;,&quot;CODGRUPA&quot;,&quot;CANTARIBIL&quot;,&quot;CODVAMAL&quot;,&quot;PRODUSPROPRIU&quot;,&quot;CODEXTERNART&quot;) AS
SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  O.NEFACTURABIL,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE AS DENOBIECT,
  A.RELATIEUM1,
  A.RELATIEUM2,
  (
  SELECT PM.LEI
  FROM
    PRETM PM,
    NCATPRET CAT
  WHERE
    PM.CODOBIECT = O.CODOBIECT
    AND CAT.CODCATPRET = PM.CODCATPRET
    AND nvl(PM.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(PM.subunitatea, 1), pkg_globals.GETSUBUNITATE)
    AND PM.IMPLICIT = 1
    AND CAT.TIP IN (1, 2)
    AND ROWNUM &lt;=1
   ) AS PRETVANZARE,
  (
  SELECT PM.VALUTA
  FROM
    PRETM PM,
    NCATPRET CAT
  WHERE
    PM.CODOBIECT = O.CODOBIECT
    AND CAT.CODCATPRET = PM.CODCATPRET
    AND nvl(PM.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(PM.subunitatea, 1), pkg_globals.GETSUBUNITATE)
    AND PM.IMPLICIT = 1
    AND CAT.TIP IN (1, 2)
    AND ROWNUM &lt;=1
   ) AS PRETVALUTA,
   A.D1,
   A.D2,
   A.D3,
   O.ROTVALUTA AS ROTUNJIRE,
   NVL(E.CODGRUPA, 0) CodGrupa,
   U.TipUM CANTARIBIL,
   O.CODVAMAL,
   O.Produspropriu,
   A.CODEXTERNART || A.SUFIXCODEXTERN AS CODEXTERNART
FROM
  NART A
  inner join num u on u.codum = a.um
  LEFT OUTER JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC,
  NARTOBJ O
  LEFT OUTER JOIN NPART P ON P.CODPART = O.CODPRODUCATOR
  LEFT OUTER JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
  LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  LEFT OUTER JOIN NECHIV E ON E.CODOBIECT = O.CODOBIECT
  LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
WHERE
  O.CODARTICOL = A.CODARTICOL
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBJART_SIMPLU</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FF5D6DC40E7721EDF159B90FC49EFC60DB6534EB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBJART_SIMPLU (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DENUMIRE&quot;,&quot;CODEXTERN&quot;,&quot;UM&quot;,&quot;CODINTERN&quot;,&quot;DCI&quot;,&quot;CODGRUPA&quot;,&quot;CODEXTERNART&quot;,&quot;PRODUCATOR&quot;,&quot;SIMBOLCLASA&quot;,&quot;INACTIV&quot;,&quot;TIPARTICOL&quot;,&quot;PRETVANZARE&quot;,&quot;PRETVALUTA&quot;,&quot;PROMOTIE&quot;,&quot;CLASA&quot;,&quot;CULOARE&quot;,&quot;CARACTSUPL&quot;,&quot;CODVAMAL&quot;,&quot;DEN_IOART&quot;,&quot;DEN_GEST&quot;,&quot;DENLOCATIE&quot;,&quot;DEN_TARA&quot;,&quot;CODIOART&quot;,&quot;CODLOCATIE&quot;,&quot;CODGEST&quot;,&quot;DEN_CLASEAS&quot;,&quot;DEN_CLASEA&quot;,&quot;RISC_FISCAL&quot;,&quot;GREUTSPECIFICA&quot;) AS
SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  O.DENUMIRE,
  O.CODEXTERN,
  A.UM,
  O.CODINTERN,
  A.DCI,
  NVL(E.CODGRUPA, 0) CodGrupa,
  CASE
    WHEN A.SUFIXCODEXTERN IS NOT NULL THEN A.CODEXTERNART || &apos; &apos; || A.SUFIXCODEXTERN
    ELSE A.CODEXTERNART
  END CODEXTERNART,
  P.DEN_PART AS PRODUCATOR,
  CLA.SIMBOL AS SIMBOLCLASA,
  O.INACTIV,
  A.TipArticol,
  PMM.LEI AS PRETVANZARE,
  PMM.VALUTA AS PRETVALUTA,
  O.PROMOTIE,
  A.CLASA,
  NVL(CAR.Culoare, A.Culoare) Culoare, CAR.den_carsupart CaractSupl,
  O.CODVAMAL,
  IOA.DEN_IOART,
  G.DEN_GEST,
  LOC.DENUMIRE AS DENLOCATIE,
  T.DEN_TARA,
  IOA.CODIOART,
  LOC.CODLOCATIE,
  G.CODGEST,
  CLAS.DEN_CLASEAS,
  CLA.DEN_CLASEA,
  COALESCE(A.RISCFISCAL,0) as RISC_FISCAL,
  O.GREUTSPECIFICA
FROM
  NARTOBJ O
  LEFT OUTER JOIN NART A ON A.CODARTICOL = O.CODARTICOL
  LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT JOIN IOART IOA ON CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE COALESCE(OI.CONTIMPLICIT,0) END = IOA.CODIOART
  LEFT JOIN NLOCATII LOC ON CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE COALESCE(OI.LOCATIEIMPLICITA,0) END = LOC.CODLOCATIE
  LEFT JOIN NGEST G  ON CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE COALESCE(OI.GESTIMPLICITA,0) END = G.CODGEST
  LEFT JOIN NCLASEA CLA ON CLA.CODCLASEA = A.CLASA
  LEFT JOIN NCLASEAS CLAS ON CLAS.CODCLASEAS = A.CLASASTATIST
  LEFT JOIN NPART P ON P.CODPART = O.CODPRODUCATOR
  LEFT JOIN NAGENDA Ag ON Ag.CODPART = P.CODPART AND Nvl(ag.Inactiv,0) = 0 AND (BITAND(Ag.SEDIUSOCIAL, 4) &lt;&gt; 0)
  LEFT JOIN NLOCALIT L ON L.CODLOCALIT = Ag.CODLOCALIT
  LEFT JOIN NJUDET J ON J.CodJudet = L.CodJudet
  LEFT JOIN NTARI T ON T.CODTARA = L.CODTARA
  LEFT JOIN NECHIV E ON E.CODOBIECT = O.CODOBIECT
  LEFT JOIN TMP_MANPRETM PMM ON PMM.CODOBIECT = O.CODOBIECT
	LEFT JOIN NCARSUPART CAR ON CAR.codcarsupart = O.CODCARACT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBJ_ART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>936E7CFDA21C96A8A9AEA2B04BC21158B6637D7D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBJ_ART (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODCNAS&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;TERMENPLATA&quot;,&quot;PROCADAOSNIR&quot;,&quot;PROMOTIE&quot;,&quot;BLOCAT&quot;,&quot;NEFACTURABIL&quot;,&quot;FARACMDFURN&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODACCIZEDVI&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;TIPPRETMAX&quot;,&quot;PUMAXLUNA&quot;,&quot;DENOBIECT&quot;,&quot;RELATIEUM1&quot;,&quot;RELATIEUM2&quot;,&quot;PRETVANZARE&quot;,&quot;PRETVALUTA&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;DCI&quot;,&quot;CULOARE&quot;,&quot;ROTUNJIRE&quot;,&quot;CODGRUPA&quot;,&quot;INDGRUPA&quot;,&quot;CANTARIBIL&quot;,&quot;CODVAMAL&quot;,&quot;CASADEMARCAT&quot;,&quot;PRODUSPROPRIU&quot;,&quot;CODEXTERNART&quot;,&quot;CUATRIBUTE&quot;,&quot;ATRIBUTE_OBIECT&quot;,&quot;TRADUCARTGENERIC&quot;,&quot;INACTIV&quot;,&quot;SIMBOLCLASA&quot;,&quot;DENUMIRECLASA&quot;,&quot;SIMBOLCLASASTAT&quot;,&quot;DENLOCATIE&quot;,&quot;DENUMIRETRAD&quot;,&quot;PART_IMPLICIT&quot;,&quot;DEN_UM&quot;,&quot;DEN_UM1&quot;,&quot;DEN_UM2&quot;,&quot;DEN_IOART&quot;,&quot;DEN_GEST&quot;,&quot;GREUTSPECIFICA&quot;,&quot;NEVANDABIL&quot;,&quot;FARASTOC&quot;,&quot;CODIDENT&quot;,&quot;PARITATED1&quot;,&quot;PARITATED2&quot;,&quot;PARITATED3&quot;,&quot;DEN_CONTSERVICIU&quot;,&quot;MASA&quot;,&quot;LOCATIEIMPLICITA&quot;) AS
SELECT
/*+ INDEX(O IDX_NARTOBJ_CODARTICOL )
    INDEX(CLA NCLASEA_PK )
    INDEX(CLA_S NCLASEAS_PK )
    INDEX(IOA IOART_PK )
 */
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  IOA.CODIOART CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  GI.CODGEST GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODCNAS,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  O.NEFACTURABIL,
  O.FARACMDFURN,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODACCIZEDVI,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE AS DENOBIECT,
  A.RELATIEUM1,
  A.RELATIEUM2,
  PMM.LEI AS PRETVANZARE,
  PMM.VALUTA AS PRETVALUTA,
  A.D1,
  A.D2,
  A.D3,
  A.DCI,
  A.Culoare,
  O.ROTVALUTA AS ROTUNJIRE,
  NVL(E.CODGRUPA, 0) CodGrupa,
  NVL(E.Ind, 0) IndGrupa,
  U.TipUM CANTARIBIL,
  O.CODVAMAL,
  A.CASADEMARCAT,
  O.Produspropriu,
  A.CODEXTERNART || A.SUFIXCODEXTERN AS CODEXTERNART,
 -- (SELECT COUNT(*) FROM NATROBJ AO, NARTOBJ OB WHERE OB.CODARTICOL = A.CODARTICOL AND AO.CODOBIECT = OB.CODOBIECT) AS CUATRIBUTE,
 -- (SELECT COUNT(*) FROM NATROBJ AO WHERE AO.CODOBIECT = O.CODOBIECT) AS ATRIBUTE_OBIECT,
   NVL(V_NARTATR.CODARTATR, 0) AS CUATRIBUTE,
   NVL(V_NATROBJ.CODATROBJ, 0) AS ATRIBUTE_OBIECT,
  NVL(O.TRADUCARTGENERIC, 0) AS TRADUCARTGENERIC,
  NVL(O.INACTIV, 0) AS INACTIV,
  CLA.SIMBOL AS SIMBOLCLASA,
  CLA.DEN_CLASEA AS DENUMIRECLASA,
  CLA_S.DEN_CLASEAS AS SIMBOLCLASASTAT,
  LOC.DENUMIRE AS DENLOCATIE,
  TRAD.DENUMIRETRAD,
  PART_IMPL.DEN_PART AS PART_IMPLICIT,
  U.DEN_UM,
  USEC.DEN_UM AS DEN_UM1,
  UALT.DEN_UM AS DEN_UM2,
  IOA.DEN_IOART,
  GI.DEN_GEST,
  O.GREUTSPECIFICA,
  AI.NEVANDABIL,
  NVL(O.FARASTOC,0) FARASTOC,
  CLA.CODIDENT,
  A.PARITATED1,
  A.PARITATED2,
  A.PARITATED3,
  CS.SIMBOL DEN_CONTSERVICIU,
  O.MASA,
  LOC.CODLOCATIE LOCATIEIMPLICITA
  FROM NARTOBJ O
  LEFT JOIN (SELECT CODOBIECT, MIN(CODATROBJ) AS CODATROBJ FROM NATROBJ GROUP BY CODOBIECT ) V_NATROBJ ON V_NATROBJ.CODOBIECT = O.CODOBIECT
  INNER JOIN NART A ON O.CODARTICOL = A.CODARTICOL
  LEFT JOIN (SELECT CODARTICOL, MIN(CODARTATR) AS CODARTATR FROM NARTATR GROUP BY CODARTICOL ) V_NARTATR ON V_NARTATR.CODARTICOL =A.CODARTICOL
  LEFT JOIN NCLASEA  CLA   ON CLA.CODCLASEA = A.CLASA
  LEFT JOIN NCLASEAS CLA_S ON CLA_S.CODCLASEAS = A.CLASASTATIST
  LEFT join num u on u.codum = a.um
  LEFT join num uSEC on uSEC.codum = a.um1
  LEFT join num uALT on uALT.codum = a.um2
  LEFT JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
  LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
  LEFT JOIN IOART IOA ON CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE OI.CONTIMPLICIT END = IOA.CODIOART
  LEFT JOIN NLOCATII LOC ON CASE WHEN COALESCE(OI.LOCATIEIMPLICITA,0) = 0 THEN AI.LOCATIEIMPLICITA ELSE OI.LOCATIEIMPLICITA END = LOC.CODLOCATIE
  LEFT JOIN TMP_MANPRETM PMM ON PMM.CODOBIECT = O.CODOBIECT
  LEFT JOIN NPART P ON P.CODPART = O.CODPRODUCATOR
  LEFT JOIN TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
  LEFT JOIN TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
  LEFT JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  LEFT JOIN NECHIV E ON E.CODOBIECT = O.CODOBIECT
  LEFT JOIN NARTOBJTRAD TRAD ON TRAD.CODOBIECT = O.CODOBIECT AND TRAD.CODLIMBA = PKG_GLOBALS.GETLIMBADENART
  LEFT JOIN NARTCLI CL ON CL.CODOBIECT = O.CODOBIECT AND NVL(CL.IMPLICIT, 0) = 1
  LEFT JOIN NPART PART_IMPL ON PART_IMPL.CODPART = CL.CODPART
  LEFT JOIN NGEST GI ON GI.CODGEST = CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END
  LEFT JOIN NCONT CS ON CS.CODCONT = A.CONTSERVICIU
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBJ_ART_AUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4319F0888D91A3DAF83DE2ACB6A4E47B07414541</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBJ_ART_AUTO (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;TERMENPLATA&quot;,&quot;PROCADAOSNIR&quot;,&quot;PROMOTIE&quot;,&quot;BLOCAT&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;TIPPRETMAX&quot;,&quot;PUMAXLUNA&quot;,&quot;DENUMIRE&quot;) AS
SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE OI.CONTIMPLICIT END CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE
FROM
  NART A
  LEFT OUTER JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC,
  NARTOBJ O
  LEFT OUTER JOIN NPART P ON CODPART = O.CODPRODUCATOR
  LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT OUTER JOIN
/*
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.AnStart * 12 + A1.LunaStart =
   (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     )
*/ TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
LEFT OUTER JOIN
/*
(
    SELECT N.CODTVA,N1.CODTVA1,N.DEN_TVA,N1.PROCENT,N1.CODCONTDED,N1.CODCONTCOLE,N1.CODCONTNEEX
    FROM NTVA N LEFT JOIN NTVA1 N1
    ON   N.CODTVA = N1.CODTVA
       WHERE N1.ANSTART * 12 + N1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 NT1
                                                 WHERE NT1.CODTVA = N1.CODTVA AND
                   ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
)*/
TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA

   LEFT OUTER JOIN
/*
  (SELECT CODOBIECT, TIPPRETMAX, PRETMAXIMAL FROM NARTOBJ1 O1  WHERE
   O1.ANSTART * 12 + O1.LUNASTART =
   (SELECT MAX(O11.ANSTART * 12 + O11.LUNASTART) FROM NARTOBJ1 O11
    WHERE
       O11.CODOBIECT = O1.CODOBIECT AND O11.AnStart * 12 + O11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     )
*/ TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
WHERE
  O.CODARTICOL = A.CODARTICOL
  AND   PKG_SELECTARTICOLE.CONDITIECLASA(A.CLASA) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBJ_ART_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B77941E9748D2F931C0990565DE6DF19CD4FC2C5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBJ_ART_SERII (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;TERMENPLATA&quot;,&quot;PROCADAOSNIR&quot;,&quot;PROMOTIE&quot;,&quot;BLOCAT&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;TIPPRETMAX&quot;,&quot;PUMAXLUNA&quot;,&quot;DENOBIECT&quot;,&quot;RELATIEUM1&quot;,&quot;RELATIEUM2&quot;,&quot;PRETVANZARE&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;ROTUNJIRE&quot;) AS
SELECT
  A.CODARTICOL,
  O.CODOBIECT,
  A.DEN_ARTICOL,
  A.UM,
  A.CLASA,
  A.TIPSERIE,
  A.TIPARTICOL,
  A.ARETG,
  CASE WHEN COALESCE(OI.CONTIMPLICIT,0) = 0 THEN AI.CONTIMPLICIT ELSE OI.CONTIMPLICIT END CONTIMPLICIT,
  P.DEN_PART AS PRODUCATOR,
  CASE WHEN COALESCE(OI.GESTIMPLICITA,0) = 0 THEN AI.GESTIMPLICITA ELSE OI.GESTIMPLICITA END GESTIMPLICITA,
  A.CERTIFICAT,
  A.EVOLUTIEPRET,
  A.CONTSERVICIU,
  A.UM1,
  A.UM2,
  O.CODEXTERN,
  O.CODINTERN,
  O.UMAMBALARE,
  O.STOCMIN,
  O.STOCMAX,
  O.RETURNABIL,
  O.TERMENPLATA,
  O.PROCADAOSNIR,
  O.PROMOTIE,
  O.BLOCAT,
  NART1LUNA.CODTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NARTOBJ1LUNA.TIPPRETMAX,
  NARTOBJ1LUNA.PRETMAXIMAL AS PUMAXLUNA,
  O.DENUMIRE AS DENOBIECT,
  A.RELATIEUM1,
  A.RELATIEUM2,
  (
  SELECT PM.LEI
  FROM
    PRETM PM,
    NCATPRET CAT
  WHERE
    PM.CODOBIECT = O.CODOBIECT
    AND CAT.CODCATPRET = PM.CODCATPRET
    AND nvl(PM.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE, 1, nvl(PM.subunitatea, 1), pkg_globals.GETSUBUNITATE)
    AND PM.IMPLICIT = 1
    AND CAT.TIP IN (1, 2)
    AND ROWNUM &lt;=1
   ) AS PRETVANZARE,
   A.D1,
   A.D2,
   A.D3,
   O.ROTVALUTA AS ROTUNJIRE
FROM
  NART A
  LEFT OUTER JOIN NARTIMPLICITE AI ON AI.CODARTICOL = A.CODARTICOL AND AI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC,
  NARTOBJ O
  LEFT OUTER JOIN NPART P ON CODPART = O.CODPRODUCATOR
  LEFT JOIN NARTOBJIMP OI ON OI.CODOBIECT = O.CODOBIECT AND OI.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE_DOC
  LEFT OUTER JOIN
  TMP_NART_LUNA NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
  LEFT OUTER JOIN TMP_NTVA_LUNA TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA
  LEFT OUTER JOIN TMP_NARTOBJ_LUNA NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
WHERE
  O.CODARTICOL = A.CODARTICOL
  AND PKG_SELECTARTICOLE.CONDITIECLASA(A.CLASA) = 1 AND A.Tipserie &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIGPART_LA_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1184E21875EC6ECAB104ADE3E2155CFBA936A0B5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIGPART_LA_DATA (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;VALOARE&quot;,&quot;ICONT&quot;,&quot;SEMNIFICATIE&quot;,&quot;CODPART&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;STINS&quot;,&quot;CODDOC&quot;,&quot;MONEDA&quot;,&quot;TIPDOC&quot;,&quot;TERMEN&quot;) AS
SELECT
  CODOBLIGPIF,
  CODGENERAL,
  VALOARE,
  ICONT,
  SEMNIFICATIE,
  CODPART,
 	CODGEST,
 	CURS,
  TVA,
  STINS,
  CODDOC,
  MONEDA,
  TIPDOC,
  TERMEN
 FROM
   (
    -- INTRARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
  			G.CODDOC,
     G.MONEDA,
     G.TIPDOC,
     O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
     O.SEMNIFICATIE IN (100, 110)
     AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)

   UNION ALL

-- obligatii de stins provenite din DVI -uri
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
  			G.CODDOC,
     G.MONEDA,
     G.TIPDOC,
     O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT OUTER JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE
      O.SEMNIFICATIE IN (130)
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)

    UNION ALL
   -- AVIZE INTRARE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
--      CASE
--        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
--        ELSE S.VALOARE
--      END AS STINS,
      S.VALOARE AS STINS,
  		 	G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
         OBLIGPIF O
         LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
         LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
         LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
         LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
        O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2
        AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
        AND (I.OPERAT = 1)AND(I.ANULAT = 0)



    UNION ALL

   -- AVIZE IESIRE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
--      CASE
--        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
--        ELSE S.VALOARE
--      END AS STINS,
      S.VALOARE AS STINS,
   			G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (240)
      AND I.TIPDOC = 20
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)


    UNION ALL

   -- obligatii de stins provenite din IESIRI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
   			G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (200, 210)
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)

    UNION ALL
   -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
   			G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE
     ((T1.INITIALIZARI = 1)OR(NVL(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))AND
      G.TIPDOC IN (29, 30, 31, 33)
      AND NVL(T.DATADOC, TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;))  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND G.SEMNIFICATIE IN (310, 410, 330, 430)

    UNION ALL

   -- obligatii de stins provenite din NOTE CONTABILE
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
   			G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
      LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
    WHERE
      O.SEMNIFICATIE IN (1200, 1201)
      AND N.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART

    UNION ALL

   -- obligatii de stins provenite din COMPENSARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
   			G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (1301, 1351, 1303)
      AND C.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART

) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIGPART_LA_DATA_PE_PART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5874E6974C4F68FF3A58A1B6420F14FC209F8BAC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIGPART_LA_DATA_PE_PART (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;VALOARE&quot;,&quot;ICONT&quot;,&quot;SEMNIFICATIE&quot;,&quot;CODPART&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;STINS&quot;,&quot;CODDOC&quot;,&quot;MONEDA&quot;,&quot;TIPDOC&quot;,&quot;TERMEN&quot;) AS
SELECT
  CODOBLIGPIF,
  CODGENERAL,
  VALOARE,
  ICONT,
  SEMNIFICATIE,
  CODPART,
  CODGEST,
  CURS,
  TVA,
  STINS,
  CODDOC,
  MONEDA,
  TIPDOC,
  TERMEN
 FROM
   (
    -- INTRARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
       NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
     O.SEMNIFICATIE IN (100, 110)
     AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
     AND I.OPERAT = 1 AND I.ANULAT = 0
     AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
   UNION ALL
-- obligatii de stins provenite din DVI -uri
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
      NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT OUTER JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE
      O.SEMNIFICATIE IN (130)
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- AVIZE INTRARE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
      NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      S.VALOARE AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
         OBLIGPIF O
         LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
         LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
         LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
         LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
        O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2
        AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
        AND I.OPERAT = 1 AND I.ANULAT = 0
        AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- AVIZE IESIRE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
      NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      S.VALOARE AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (240)
      AND I.TIPDOC = 20
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- obligatii de stins provenite din IESIRI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
       NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (200, 210)
      AND I.DATADOC  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND I.OPERAT = 1 AND I.ANULAT = 0
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
      NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
         G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE
     ((T1.INITIALIZARI = 1)OR(NVL(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))AND
      G.TIPDOC IN (29, 30, 31, 33)
      AND NVL(T.DATADOC, TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;))  &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND G.SEMNIFICATIE IN (310, 410, 330, 430)
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- obligatii de stins provenite din NOTE CONTABILE
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
       NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
      LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
    WHERE
      O.SEMNIFICATIE IN (1200, 1201)
      AND N.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
    UNION ALL
   -- obligatii de stins provenite din COMPENSARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
      NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
      G.CODDOC,
      G.MONEDA,
      G.TIPDOC,
      O.TERMEN
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (1301, 1351, 1303)
      AND C.DATADOC &lt;= PKG_GLOBALS.GETDATASOLDPART
      AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIGPIF_DE_STINS_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DEB3394EB1B770F3B9383C6513EC27E3F277B0CA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIGPIF_DE_STINS_LUNA (
&quot;CODOBLIGPIF&quot;,&quot;REST&quot;,&quot;RESTTVA&quot;,&quot;RESTSPLITTVA&quot;) AS
SELECT 
  O.CODOBLIGPIF, O.VALOARE AS REST, 
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
WHERE O.SEMNIFICATIE IN (100) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- AVIZE DE STINS
SELECT 
  O.CODOBLIGPIF, O.VALOARE AS REST,
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
WHERE O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2 AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- AVANSURI PE FACTURA INTRARI
SELECT
  O.CODOBLIGPIF, O.VALOARE AS REST,
  CASE
    WHEN O.VALOARE * Coalesce(G.TVA, 0) = 0 THEN 0
    WHEN (SELECT SUM(OS.VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
    ELSE O.VALOARE * Coalesce(G.TVA, 0)/ (SELECT SUM(OS.VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL)
  END AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
WHERE O.SEMNIFICATIE IN (110, 120) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- obligatii de stins provenite din DVI -uri
SELECT
  O.CODOBLIGPIF, O.VALOARE AS REST,
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
  LEFT JOIN DVI D      ON G.CODDOC     = D.CODDVI
  LEFT JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
WHERE O.SEMNIFICATIE IN (130) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- obligatii de stins provenite din IESIRI
SELECT
  O.CODOBLIGPIF, O.VALOARE AS REST,
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN IESIRI I   ON  I.CODIES = G.CODDOC
WHERE O.SEMNIFICATIE IN (200) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- obligatii de stins provenite din IESIRI
SELECT O.CODOBLIGPIF, O.VALOARE AS REST, Coalesce(G.TVA, 0) AS RESTTVA, Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN IESIRI I   ON  I.CODIES = G.CODDOC
WHERE O.SEMNIFICATIE IN (240) AND I.TIPDOC = 20 AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- AVANSURI PE FACTURA IESIRI + GARANTII PE FACTURA
SELECT
  O.CODOBLIGPIF,
  O.VALOARE AS REST,
  CASE
    WHEN O.VALOARE * Coalesce(G.TVA, 0) = 0 THEN 0
    WHEN (SELECT SUM(OS.VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL) = 0 THEN 0
    ELSE O.VALOARE * Coalesce(G.TVA, 0)/ (SELECT SUM(OS.VALOARE) FROM OBLIGPIF OS WHERE OS.CODGENERAL = O.CODGENERAL)
  END AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
WHERE O.SEMNIFICATIE IN (210, 220) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1)AND(I.ANULAT = 0)
UNION ALL -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
SELECT
  O.CODOBLIGPIF, O.VALOARE AS REST,
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
  LEFT JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
WHERE ((T1.INITIALIZARI = 1)OR(Coalesce(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))
  AND G.TIPDOC IN (29, 30, 31, 33)
  AND T1.AN = PKG_GLOBALS.GETANTEMP AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND G.SEMNIFICATIE IN (310, 330, 410, 430, 500, 600)
UNION ALL -- obligatii de stins provenite din NOTE CONTABILE
SELECT
  O.CODOBLIGPIF, O.VALOARE AS REST,
  Coalesce(G.TVA, 0) AS RESTTVA,
  Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
  LEFT JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
WHERE O.SEMNIFICATIE IN (1200, 1201, 1250, 1251)  AND N1.AN = PKG_GLOBALS.GETANTEMP AND N1.LUNA = PKG_GLOBALS.GETLUNATEMP
UNION ALL -- obligatii de stins provenite din COMPENSARI
SELECT O.CODOBLIGPIF, O.VALOARE AS REST, Coalesce(G.TVA, 0) AS RESTTVA, Coalesce(O.DINCARETVA, 0) AS RESTSPLITTVA
FROM OBLIGPIF O
  LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
  LEFT JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
WHERE O.SEMNIFICATIE IN (1301, 1303, 1351) AND C.AN = PKG_GLOBALS.GETANTEMP AND C.LUNA = PKG_GLOBALS.GETLUNATEMP</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIGPIF_STINGERI_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9625F1C6E8064AC07A67DD644F67714AE4D9CD94</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIGPIF_STINGERI_LUNA (
&quot;CODOBLIGPIF&quot;,&quot;REST&quot;,&quot;RESTTVA&quot;,&quot;RESTSPLITTVA&quot;) AS
SELECT
  OSTINS.CODOBLIGPIF,
  -(
    I1.PU * I1.CANT +
    Coalesce(I1STINS.TVA , 0) * CASE WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0 ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT) END
  ) AS REST,
  0 AS RESTTVA,
  0 AS RESTSPLITTVA
FROM
  OBLIGPIF O,
  GENERAL G,
  INTRARI I,
  INTRARI1 I1,
  INTRLINK IL,
  INTRARI1 I1STINS,
  INTRARI  ISTINS,
  GENERAL GSTINS,
  OBLIGPIF OSTINS
WHERE O.SEMNIFICATIE          = 140
  AND G.CODGENERAL            = O.CODGENERAL
  AND G.TIPDOC                = 9
  AND I.CODINTR               = G.CODDOC
  AND I1.CODINTR              = I.CODINTR
  AND IL.CODINTR1             = I1.CODINTR1
  AND IL.CODLINIEAVIZ         = I1STINS.CODINTR1
  AND ISTINS.CODINTR          = I1STINS.CODINTR
  AND ISTINS.CODINTR          = GSTINS.CODDOC
  AND ISTINS.TIPDOC           = GSTINS.TIPDOC
  AND GSTINS.SEMNIFICATIE     = 140
  AND Coalesce(I1STINS.CUSTODIE, 0) = 0
  AND OSTINS.CODGENERAL       = GSTINS.CODGENERAL
  AND I.OPERAT                = 1
  AND I.AN                    = PKG_GLOBALS.GETANTEMP
  AND I.LUNA                  = PKG_GLOBALS.GETLUNATEMP
UNION ALL -- DVI LA AVIZ
SELECT
  CODOBLIGPIF,
  ROUND(SUM(REST), 2) AS REST,
  0 AS RESTTVA,
  0 AS RESTSPLITTVA
FROM (
  SELECT
    OSTINS.CODOBLIGPIF,
    -(
      ROUND((D1.PRETIMPORT / I.CURS), 6) * I1.CANT +
      Coalesce(I1STINS.TVA , 0) * CASE WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0 ELSE ROUND((D1.PRETIMPORT / I.CURS), 6) * I1.CANT /( I1STINS.PU * I1STINS.CANT) END
    ) AS REST,
    0 AS RESTTVA
  FROM
    OBLIGPIF O,
    GENERAL G,
    INTRARI I,
    INTRARI1 I1 LEFT JOIN DVI1 D1 ON D1.CODINTR1 = I1.CODINTR1,
    INTRLINK IL,
    INTRARI1 I1STINS,
    INTRARI  ISTINS,
    GENERAL GSTINS,
    OBLIGPIF OSTINS
  WHERE O.SEMNIFICATIE     = 140
    AND G.CODGENERAL       = O.CODGENERAL
    AND G.TIPDOC           = 5
    AND I.CODINTR          = G.CODDOC
    AND I1.CODINTR         = I.CODINTR
    AND IL.CODINTR1        = I1.CODINTR1
    AND IL.CODLINIEAVIZ    = I1STINS.CODINTR1
    AND ISTINS.CODINTR     = I1STINS.CODINTR
    AND ISTINS.CODINTR     = GSTINS.CODDOC
    AND ISTINS.TIPDOC      = GSTINS.TIPDOC
    AND OSTINS.CODGENERAL  = GSTINS.CODGENERAL
    AND I.OPERAT           = 1
    AND I.AN               = PKG_GLOBALS.GETANTEMP
    AND I.LUNA             = PKG_GLOBALS.GETLUNATEMP
) GROUP BY CODOBLIGPIF
UNION ALL -- AVIZE DE IESIRE STINSE
SELECT
  OSTINS.CODOBLIGPIF,
  -(
    I1.PU * I1.CANT * CASE WHEN Coalesce(I1STINS.PROCDISC, 0) &lt;&gt; 0 THEN ((100 + Coalesce(I1STINS.PROCDISC, 0)) / 100) ELSE 1 END +
    Coalesce(I1STINS.TVA, 0) *
    CASE
      WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
      ELSE I1.PU * I1.CANT * CASE WHEN Coalesce(I1STINS.PROCDISC, 0) &lt;&gt; 0 THEN ((100 + Coalesce(I1STINS.PROCDISC, 0)) / 100) ELSE 1 END /(I1STINS.PU * I1STINS.CANT)
    END
  ) AS REST,
  0 AS RESTTVA,
  0 AS RESTSPLITTVA
FROM
  OBLIGPIF O,
  GENERAL G,
  IESIRI I,
  IESIRI1 I1,
  IESLINK IL,
  IESIRI1 I1STINS,
  IESIRI  ISTINS,
  GENERAL GSTINS,
  OBLIGPIF OSTINS
WHERE O.SEMNIFICATIE          = 240
  AND G.CODGENERAL            = O.CODGENERAL
  AND G.TIPDOC                = 26
  AND I.CODIES                = G.CODDOC
  AND I1.CODIES               = I.CODIES
  AND IL.CODIES1              = I1.CODIES1
  AND IL.CODLINIEAVIZ         = I1STINS.CODIES1
  AND ISTINS.CODIES           = I1STINS.CODIES
  AND Coalesce(ISTINS.CUSTODIE, 0) = 0
  AND ISTINS.CODIES           = GSTINS.CODDOC
  AND ISTINS.TIPDOC           = GSTINS.TIPDOC
  AND GSTINS.SEMNIFICATIE     = 240
  AND OSTINS.CODGENERAL       = GSTINS.CODGENERAL
  AND I.OPERAT                = 1
  AND I.AN                    = PKG_GLOBALS.GETANTEMP
  AND I.LUNA                  = PKG_GLOBALS.GETLUNATEMP
UNION ALL -- TREZORERIE
SELECT
  O_STINS.CODOBLIGPIF,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -(S.VALOARE + Coalesce(S.DINCARETVA, 0)) ELSE S.VALOARE + Coalesce(S.DINCARETVA, 0) END AS REST,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(G.TVA, 0)                      ELSE Coalesce(G.TVA, 0)                    END AS RESTTVA,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(S.DINCARETVA, 0)               ELSE Coalesce(S.DINCARETVA, 0)             END AS RESTSPLITTVA
FROM STINGERE S
  LEFT JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL  G  ON G.CODGENERAL   = O_STINGATOR.CODGENERAL
  LEFT JOIN TREZOR1  T1 ON T1.CODTREZOR1  = G.CODDOC
  LEFT JOIN TREZOR   T  ON T.CODTREZOR    = T1.CODTREZOR
  LEFT JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
WHERE T.OPERAT = 1
  AND G.TIPDOC IN (29, 30, 31, 33) --AND T1.AN = PKG_GLOBALS.GETANTEMP AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND O_STINS.SEMNIFICATIE NOT IN (800, 801)
UNION ALL -- COMPENS
SELECT
  O_STINS.CODOBLIGPIF,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -(S.VALOARE + Coalesce(S.DINCARETVA, 0)) ELSE S.VALOARE + Coalesce(S.DINCARETVA, 0) END AS REST,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(G.TVA, 0)                      ELSE Coalesce(G.TVA, 0)                    END AS RESTTVA,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(S.DINCARETVA, 0)               ELSE Coalesce(S.DINCARETVA, 0)             END AS RESTSPLITTVA
FROM STINGERE S
  LEFT JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT JOIN COMPENS CO ON CO.CODCOMPENS = G.CODDOC
  LEFT JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
WHERE G.TIPDOC = 28 AND CO.AN = PKG_GLOBALS.GETANTEMP AND CO.LUNA = PKG_GLOBALS.GETLUNATEMP
UNION ALL
SELECT
  O_STINS.CODOBLIGPIF,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -S.VALOARE          ELSE S.VALOARE          END AS REST,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(G.TVA, 0) ELSE Coalesce(G.TVA, 0) END AS RESTTVA,
  0 AS RESTSPLITTVA
FROM STINGERE S
  LEFT JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT JOIN INTRARI I ON I.CODINTR = G.CODDOC
  LEFT JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
WHERE G.SEMNIFICATIE IN (111, 121) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1) AND (I.ANULAT = 0)
UNION ALL
SELECT
  O_STINS.CODOBLIGPIF,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -S.VALOARE                 ELSE S.VALOARE                 END AS REST,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(G.TVA, 0)        ELSE Coalesce(G.TVA, 0)        END AS RESTTVA,
  CASE WHEN O_STINS.VALOARE &gt;= 0 THEN -Coalesce(S.DINCARETVA, 0) ELSE Coalesce(S.DINCARETVA, 0) END AS RESTSPLITTVA
FROM STINGERE S
  LEFT JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
  LEFT JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
WHERE G.SEMNIFICATIE IN (211, 221, 400) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND (I.OPERAT = 1) AND (I.ANULAT = 0)</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_CLIENT_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E9222BC92CB74577B061ACB0545EC5D661EB7BE5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_CLIENT_COMPENS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
 &apos;PV&apos; AS DOC,
  C.NRDOC,
  C.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  C.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN NSUBUNIT NS ON NS.CODSUBUNIT  = C.SUBUNITATEA
WHERE
--  nvl(c.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  O.SEMNIFICATIE IN (1301, 1303, 1351) AND O.ICONT IN (3, 10, 11) AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_CLIENT_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5050E54F658BE3750E7FBB67272A6D30A38D7A8B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_CLIENT_IESIRI (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST
   - NVL((SELECT SUM(ES.VALOARE) FROM EMULSTINGERI ES, EMULARE E WHERE ES.CODOBLIGPIF = O.CODOBLIGPIF AND E.CODEMULARE = ES.CODEMULARE AND NVL(E.PRELUAT, 0) = 0), 0)
  AS REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST
   - NVL((SELECT SUM(ES.VALOARE) FROM EMULSTINGERI ES, EMULARE E WHERE ES.CODOBLIGPIF = O.CODOBLIGPIF AND E.CODEMULARE = ES.CODEMULARE AND NVL(E.PRELUAT, 0) = 0), 0)
   AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN IESIRI I ON I.CODIES    = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NS ON NS.CODSUBUNIT  = I.SUBUNITATEA
WHERE
--   nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.ICONT NOT IN (6, 7)) AND --fara 408 si 418
  (O.VALOARE &gt;= 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 200 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--   G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
    PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_CLIENT_INCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7161DD965DBFD4E5F769C3B68BB3B1A7365ED6A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_CLIENT_INCURS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(O.ICONT, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
--PKG_GLOBALS.SIMBOLCONTOBLIG(O.SEMNIFICATIE, O.ICONT, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(O.CONTBANKTRANZACTIE, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  T.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
	 LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR = T1.CODTREZOR
	 LEFT OUTER JOIN NSUBUNIT  NS  ON NS.CODSUBUNIT = T.SUBUNITATEA
WHERE
   T.AN * 12 + T.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
--   nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	(O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  O.SEMNIFICATIE = 600 AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_CLIENT_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>05D8317AA474A8E0AB49EA39991F89D10FA1EDD7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_CLIENT_NC (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
   N.NRDOC,
  N.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  N.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT NS ON NS.CODSUBUNIT  = N.SUBUNITATEA
 WHERE
--  nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  O.SEMNIFICATIE IN (1200) AND O.ICONT IN (3, 10, 11) AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_FURN_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE57152907D69F052747D9333FD3D027DA706E8B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_FURN_COMPENS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
 &apos;PV&apos; AS DOC,
  C.NRDOC,
  C.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 AS PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  C.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= C.SUBUNITATEA
WHERE
--   nvl(c.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(c.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   C.AN * 12 + C.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.VALOARE &gt; 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  O.SEMNIFICATIE IN (1351) AND O.ICONT IN (2, 8, 9, 15) AND
  O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
--  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
   PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_FURN_INCURS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>878CD41E0884E70489CBDA12A382A598D252EB51</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_FURN_INCURS (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
--  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_CONTURIBANCI.GET_BANKCONT_COD_CARACT_LUNA(O.CODCONTVIRAMENT, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(O.ICONT, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU)) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
  T.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
  LEFT OUTER JOIN TREZOR   T ON T.CODTREZOR = T1.CODTREZOR
	 LEFT OUTER JOIN NSUBUNIT  NS  ON NS.CODSUBUNIT = T.SUBUNITATEA
WHERE
   T.AN * 12 + T.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
--   AND nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE)
   AND (O.VALOARE &gt; 0)
   AND (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA)))
   AND O.SEMNIFICATIE = 500
   AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
---  G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
   AND PKG_MONEDE.MONEDA_VALIDA(G.MONEDA)= 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_FURN_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BFD7449AC33DF2155D2752097227CF1422E2857F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_FURN_INTRARI (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  I.PREFIXDOC AS DOC,
  I.NRDOC,
  I.DATADOC,
  O.VALOARE,
  O.REST - COALESCE(O.DINCARETVA, 0) AS REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST - COALESCE(O.DINCARETVA, 0) AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN INTRARI I ON I.CODINTR    = G.CODDOC
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= I.SUBUNITATEA
WHERE
--  nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  (I.OPERAT = 1)AND(I.ANULAT = 0)AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.ICONT NOT IN (6, 7)) AND --fara 408 si 418
  (O.VALOARE &gt;= 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 100 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1



UNION  ALL
-- INCLUD DVI-uri
SELECT
  O.CODOBLIGPIF,
  &apos;DVOT&apos; AS PREFIXDOC,
  D.NRDOC,
  D.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  I.CODLOCATIE,
  A.OBS AS SEDIU,
  I.SUBUNITATEA,
  NSUB.DEN_SUBUNIT,
  G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN DVI D ON D.CODDVI = G.CODDOC
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = D.CODINTR
  LEFT OUTER JOIN NAGENDA A ON A.CODAGENDA  = I.CODLOCATIE
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= I.SUBUNITATEA
WHERE
--  nvl(i.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(i.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
  (I.OPERAT = 1)AND(I.ANULAT = 0)AND
   I.AN * 12 + I.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.ICONT NOT IN (6, 7)) AND --fara 408 si 418
  (O.VALOARE &gt;= 0) AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE = 130 AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
  PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_FURN_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>89A951C92F795512E3A49237CBD3038D262E4DE6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_FURN_NC (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  O.CODOBLIGPIF,
  &apos;NC&apos; AS DOC,
   N.NRDOC,
  N.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
  PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;&apos; AS SEDIU,
   N.SUBUNITATEA,
   NSUB.DEN_SUBUNIT,
   G.PROCTVAAVANS
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC  N  ON N.CODNC   = N1.CODNC
  LEFT OUTER JOIN NSUBUNIT NSUB ON NSUB.CODSUBUNIT= N.SUBUNITATEA
WHERE
  (O.VALOARE &gt; 0) AND
	--nvl(n.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(n.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   N.AN * 12 + N.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
   O.SEMNIFICATIE IN (1201) AND O.ICONT IN (2, 8, 9, 15) AND
   O.CODPART = PKG_NOMPART.GET_PART_CURENT AND
-- G.MONEDA  = PKG_MONEDE.GET_MONEDA_CURENTA
   PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OFERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2E166BB66169F6ABF74D5F0BB680E69863B6642B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OFERTE (
&quot;CODOFERTA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;SERIE&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATAEND&quot;,&quot;PARTENER&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;CODLOCATIE&quot;,&quot;SUBUNITATEA&quot;,&quot;CODFISCAL&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;PE_CLASA&quot;,&quot;DEN_PART&quot;,&quot;DEN_MONEDA&quot;,&quot;DEN_LOCALIT&quot;,&quot;SUBUNITATEDOC&quot;,&quot;SEDIU&quot;,&quot;TOATESUBUNIT&quot;,&quot;UTILIZATOR&quot;,&quot;VALOARE&quot;) AS
SELECT
  O.CODOFERTA, O.TIPDOC, O.ANULAT, O.BLOCAT, O.OPERAT, C.SERIE, O.NRDOC, O.DATASTART, O.DATAEND, O.PARTENER,
  O.AN, O.LUNA, O.OBS, O.MONEDA, O.CODLOCATIE, O.SUBUNITATEA, O.CODFISCAL, O.USERID, O.DATACREARE,
  Decode(O.TipBeneficiar, 1, &apos;DA&apos;, &apos;NU&apos;) Pe_Clasa, Coalesce(P.Den_Part, CP.Den_Clasep, &apos;...&apos;) Den_Part, M.Den_Moneda, L.Den_Localit Den_Localit, S.DEN_SUBUNIT SUBUNITATEDOC, AG.OBS SEDIU, O.ToateSubunit,
  NUMEPRENUME(U.NUME, U.PRENUME) Utilizator,
  (SELECT Sum(Nvl(O1.CANTMIN*O1.PRET,0)) FROM OFERTA1 O1 WHERE O1.CodOferta = O.CodOferta) Valoare
FROM OFERTA O
  LEFT JOIN NPART      P ON NVL(O.Partener, 0)    = P.Codpart    AND Nvl(TipBeneficiar, 0) = 0
  LEFT JOIN NCLASEP   CP ON NVL(O.CodClaseP, 0)   = CP.CodClaseP AND Nvl(TipBeneficiar, 0) = 1
  LEFT JOIN NAGENDA   AG ON NVL(O.CodLocatie, 0)  = AG.Codagenda
  LEFT JOIN NLOCALIT   L ON NVL(AG.CodLocalit, 0) = L.Codlocalit
  LEFT JOIN NMONEDE    M ON NVL(O.Moneda, 0)      = M.CodMoneda
  LEFT JOIN NSUBUNIT   S ON S.CODSUBUNIT = O.SUBUNITATEA
  LEFT JOIN DOCCARNETE C ON C.CODCARNET = O.CARNETDOC
  LEFT JOIN NPERS U ON U.LOGONNAME = O.USERID
WHERE O.TipDoc = PKG_GLOBALS.GETTIPOFERTA
  AND ((NVL(O.ToateSubunit,0) = 1)or(NVL(O.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE,1,NVL(O.SUBUNITATEA,1),PKG_GLOBALS.GETSUBUNITATE)))
  AND O.DATASTART &lt;= LAST_DAY(To_Date(&apos;01.&apos;||PKG_GLOBALS.GetLunaLucru||&apos;.&apos;||PKG_GLOBALS.GetAnLucru,&apos;DD.MM.YYYY&apos;))
  AND O.DATAEND &gt;= To_Date(&apos;01.&apos;||PKG_GLOBALS.GetLunaLucru||&apos;.&apos;||PKG_GLOBALS.GetAnLucru,&apos;DD.MM.YYYY&apos;)</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OPERATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F7E59992CFA97FF16FFCA18A10F7C6D779A5DEDE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OPERATII (
&quot;CODOP&quot;,&quot;CODEXTERN&quot;,&quot;DENUMIRE&quot;,&quot;CLASAOP&quot;,&quot;TIP&quot;,&quot;ACTIV&quot;,&quot;LOCMUNCA&quot;,&quot;MARCAAUTO&quot;,&quot;MODELAUTO&quot;,&quot;FACTURABIL&quot;,&quot;DURATA&quot;,&quot;ORE&quot;,&quot;DENTIPLUCRARE&quot;,&quot;DEN_CLASEOP&quot;) AS
select
  N.CodOp, N.CodExtern, N.Denumire, N.ClasaOp, N.Tip, N.Activ,LM.Denumire LocMunca, MA.Marca Marcaauto,MO.Model Modelauto,
  N.Facturabil,
  N.Durata, Round(N.Durata/60, 2) Ore , TL.DENUMIRE DenTipLucrare,CLS.DEN_CLASEOP
from NOPER N
    LEFT JOIN tiplucrarisa TL on TL.CODTIPLUCRARE = N.CODTIPLUCRARE
    LEFT JOIN NMARCIAUTO MA on MA.CodMarciAuto = N. Marcaauto
    LEFT JOIN NMODELEAUTO MO on MO.CodModeleAuto = N.Modelauto
    LEFT JOIN LOCMUNCA LM on LM.CODLOC = N.LOCMUNCA
    LEFT JOIN NCLASEOP CLS ON N.CLASAOP = CLS.CODCLASEOP
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OPREG</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D92EE6E12457894C1E998B88E5FD244EE5A0448D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OPREG (
&quot;CODOP&quot;,&quot;TIPTRANZ&quot;,&quot;ZIDECONT&quot;,&quot;TIPDECONT&quot;,&quot;CODMONEDA&quot;,&quot;CODPART&quot;,&quot;VALOARE&quot;,&quot;AN_MAX&quot;,&quot;LUNA_MAX&quot;,&quot;DEN_PART&quot;) AS
select
  o.codop, o.tiptranz, o.zidecont, o.tipdecont, o.codmoneda, o.codpart,
  o.valoare, o.an_max, o.luna_max, p.den_part
from opreg o
     inner join npart p on o.codpart = p.codpart

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_ORAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>257047BFB00D3F58EABB1CC07FE18B1C7D5CDC91</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_ORAR (
&quot;CODORAR&quot;,&quot;DENUMIRE&quot;,&quot;OBS&quot;,&quot;EXPIRAT&quot;) AS
SELECT
  o.codorar,
  o.denumire,
  o.obs,
  Decode(PKG_ORAR.Expirat(DENUMIRE),1,&apos;DA&apos;,&apos;NU&apos;) expirat
FROM ORAR o
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PACHETE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>38C86760887CE2E39780B81521CEB6201AFDC1CE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PACHETE (
&quot;CODPACHETE&quot;,&quot;DATAP&quot;,&quot;NRDOC&quot;,&quot;NRPACHETE&quot;,&quot;IDENTIFICATORP&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;DEN_GEST&quot;,&quot;DEN_COLECTOR&quot;,&quot;DEN_VERFICATOR&quot;,&quot;DEN_TRANSPORTATOR&quot;,&quot;SIMBOL&quot;,&quot;SERIE&quot;,&quot;LISTAT&quot;,&quot;PARTENER&quot;) AS
select P.CODPACHETE, P.DATAP, p.nrdoc, p.nrpachete, p.identificatorp, p.operat, p.blocat, p.anulat,
G.DEN_GEST, NP1.NUME||&apos; &apos;||NP1.PRENUME AS DEN_COLECTOR,  NP2.NUME||&apos; &apos;||NP2.PRENUME AS DEN_VERFICATOR,
NP3.NUME||&apos; &apos;||NP3.PRENUME AS DEN_TRANSPORTATOR, DC.SIMBOL, DC.SERIE, p.listat, PKG_Pachete.getpartener(P.CODPACHETE) Partener
  FROM PACHETE P LEFT OUTER JOIN NPERS NP1 ON P.COLECTOR = NP1.CODPERS
                 LEFT OUTER JOIN NPERS NP2 ON P.VERIFICATOR = NP2.CODPERS
                 LEFT OUTER JOIN NPERS NP3 ON P.TRANSPORTATOR = NP3.CODPERS
                 LEFT OUTER JOIN DOCCARNETE DC ON P.CARNETDOC = DC.CODCARNET
                 LEFT OUTER JOIN NGEST G ON P.GESTIUNE = G.CODGEST
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PARTTOT_CODPARTTOT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>489694433DABDF8F4F8C13EC6CE1549D8F2DAE86</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PARTTOT_CODPARTTOT (
&quot;CODPARTTOT&quot;) AS
SELECT CodPartTot FROM PARTTOT ORDER BY CodPartTot 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PERISABIL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC23725495379E629DC4A81C3EC5711FAF930ABC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PERISABIL (
&quot;CODPERISABIL&quot;,&quot;DENUMIRE&quot;,&quot;OBS&quot;) AS
select &quot;CODPERISABIL&quot;,&quot;DENUMIRE&quot;,&quot;OBS&quot; from perisabil 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PLANIFPROD</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B369B4394EFAA4364F6017889C8CAF4FA6A057E5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PLANIFPROD (
&quot;CODPLANIFPROD&quot;,&quot;CODLANSPROD&quot;,&quot;SAPTAMANA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;OBS&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;SUBUNITATEA&quot;,&quot;INSAPTAMANA&quot;,&quot;AN&quot;,&quot;OPERAT&quot;) AS
select P.CODPLANIFPROD, P.CODLANSPROD, P.SAPTAMANA, SUB.DEN_SUBUNIT,
       P.Obs,
       iso_week_to_date(p.an, p.saptamana) datastart,
       iso_week_to_date(p.an, p.saptamana) + 6 datastop,
       P.NRDOC, P.DATADOC, P.Subunitatea, nvl(P.InSaptamana,1) InSaptamana, P.An, P.Operat
  from PLANIFPROD P
       INNER JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = P.SUBUNITATEA
  WHERE P.AN = PKG_GLOBALS.GetANLUCRU
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PLATI_VIRAMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A25ABA2C33ED66380EC53152C86E045312D0914F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PLATI_VIRAMENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;,&quot;TIPDOC&quot;,&quot;CODDOC&quot;,&quot;COEFPROVIZION&quot;,&quot;NUMEAGENT&quot;,&quot;OBS&quot;,&quot;ROSU&quot;,&quot;CODCENTRU&quot;,&quot;DENCENTRU&quot;,&quot;SERIADOC&quot;,&quot;CURSISTORIC&quot;,&quot;OBIECTTRANZSTINS&quot;,&quot;CODANALIZANOD&quot;) AS
SELECT
  O.CODOBLIGPIF,
  T1.DOC AS DOC,
  T1.NRDOC,
  T1.DATADOC,
  O.VALOARE,
  O.REST,
  O.TERMEN,
  0 As PRELUAT,
  O.REST AS RAMAS,
  0 AS CODSTINGATOR ,
  O.SEMNIFICATIE AS SEMNIFCODSTINS,
	CASE WHEN O.ICONT &lt; 10000
	THEN PKG_PLANCONTURI.GETSIMBOLCONT(PKG_CATEGCONST.GETVALCONSTBYCODE(O.ICONT, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))
	ELSE PKG_PLANCONTURI.GETSIMBOLCONT(O.ICONT)
	END  AS SIMBOLCONT,
  O.ICONT,
  G.MONEDA AS CODMONEDA,
  PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
  NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  0 AS CODLOCATIE,
  &apos;   &apos; AS SEDIU,
  T.SUBUNITATEA,
  NS.DEN_SUBUNIT,
  G.PROCTVAAVANS,
  G.TIPDOC,
  G.CODDOC,
  O.COEFPROVIZION,
  &apos;   &apos; AS NUMEAGENT,
  &apos;   &apos; AS OBS,
  0  AS ROSU,
  CEN.CODCENTRU,
  CEN.DENUMIRE AS DENCENTRU,
  T1.SERIEDOC AS SERIADOC,
  G.CURS AS CURSISTORIC,
  0 AS OBIECTTRANZSTINS,
  O.CODANALIZANOD
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT OUTER JOIN CENTRECOST CEN ON CEN.CODCENTRU = O.CODCENTRU
 	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
	 LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR = T1.CODTREZOR
	 LEFT OUTER JOIN NSUBUNIT  NS  ON NS.CODSUBUNIT = T.SUBUNITATEA
WHERE
--   nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
   T.AN * 12 + T.LUNA &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU AND
  (O.REST &lt;&gt; 0 OR (O.REST = 0 AND O.CODOBLIGPIF IN (SELECT CODUNIC FROM TMP_MANEVRA))) AND
  (O.SEMNIFICATIE = 800)
AND
  O.CODPART         = PKG_NOMPART.GET_PART_CURENT AND
  O.ContBankTranzactie = PKG_CONTURIBANCI.GETCONT_SURSA_VIRAMENT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0E2B996906FC9316BB916FD1A0E30F97AE647C7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_IESIRI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
  CODOBIECT,
  CODSUBUNIT,
  SUM(CANTINTR)  AS CANTINTR,
  SUM(VALINTR)   AS VALINTR,
  SUM(RESTLUNA)  AS RESTLUNA,
  SUM(VALVALUTA) AS VALVALUTA
FROM (
  SELECT CODOBIECT, CODSUBUNIT, CANTINTR, RESTLUNA, CANTINTR * PU AS VALINTR, CANTINTR * PUVAL VALVALUTA, AN, LUNA
  FROM (
    SELECT
      NS.CODOBIECT, G.CODSUBUNIT, (NS.PRET  - Coalesce(NS.ADAOS, 0)) PU, Coalesce(NS.PUVAL,0) PUVAL,
      CASE
        WHEN T.CODTRANSF IS NOT NULL                                              THEN -L1.CANT
        WHEN I.CODINTR   IS NOT NULL                     AND (K.VALOARE = &apos;3&apos;)    THEN -L1.CANT
				WHEN E.CodIes    IS NOT NULL AND (E.TipDoc = 23) AND (K.VALOARE = &apos;3&apos;)    THEN -L1.CANT
        WHEN E.CodIes    IS NOT NULL AND (E.TipDoc = 15) AND N.CODIES = L.CodIES  THEN  L1.CANT
        WHEN E.CodIes    IS NOT NULL                     AND N.CODIES = L.CodIES  THEN -L1.CANT
        ELSE 0
      END AS CANTINTR,
      CASE WHEN (E.CODIES IS NOT NULL) AND (E.TIPDOC = 15) THEN L1.CANT ELSE -L1.CANT END AS RESTLUNA,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.AN   WHEN E.CODIES  IS NOT NULL THEN E.AN   ELSE T.AN   END AS AN,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.LUNA WHEN E.CODIES  IS NOT NULL THEN E.LUNA ELSE T.LUNA END AS LUNA
    FROM LIVR L
      INNER JOIN LIVR1          L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC        NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN TMP_IOART_LUNA IO ON IO.CODIOART   = NS.CODIOART
      INNER JOIN NIR            N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST          G  ON G.CODGEST     = N.GEST
      LEFT  JOIN IESIRI         E  ON E.CODIES      = L.CODIES    AND E.TIPDOC = L.TIPLIVR
      LEFT  JOIN INTRARI        I  ON I.CODINTR     = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
      LEFT  JOIN TRANSF         T  ON T.CODTRANSF   = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR
      CROSS JOIN ( SELECT VALOARE FROM TMP_CONSTANTE WHERE SIMBOL = &apos;TRANSFPMP&apos; AND AnLuna = PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP ) K
    WHERE L.OPERAT = 1 AND L.ANULAT = 0 AND IO.MG = 3
  )
  WHERE AN = PKG_GLOBALS.GETANTEMP AND LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT
UNION ALL
SELECT
  CODOBIECT,
  CODSUBUNIT,
  SUM(CANTINTR)  AS CANTINTR,
  SUM(VALINTR)   AS VALINTR,
  SUM(RESTLUNA)  AS RESTLUNA,
  SUM(VALVALUTA) AS VALVALUTA
FROM (
  SELECT CODOBIECT, CODSUBUNIT, CANTINTR, RESTLUNA, CANTINTR * PU AS VALINTR, CANTINTR * PUVAL VALVALUTA, AN, LUNA
  FROM (
    SELECT
      NS.CODOBIECT, G.CODSUBUNIT, (NS.PRET  - Coalesce(NS.ADAOS, 0)) PU, (Coalesce(NS.PUVAL,0)) AS PUVAL,
      NS.CANTNIR AS CANTINTR,
      0 AS RESTLUNA,
      T.AN,
      T.LUNA
    FROM NIR N
      INNER JOIN NIRSTOC        NS  ON N.CODNIR       = NS.CODNIR
      INNER JOIN NIRSTOC        NSP ON NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
      INNER JOIN TRANSF         T   ON T.CODTRANSF    = N.CODTRANSF
      INNER JOIN TMP_IOART_LUNA IO  ON IO.CODIOART    = NS.CODIOART
      INNER JOIN TMP_IOART_LUNA IOP ON IOP.CODIOART   = NSP.CODIOART
      INNER JOIN NGEST          G   ON G.CODGEST      = N.GEST
			CROSS JOIN ( SELECT VALOARE FROM TMP_CONSTANTE WHERE SIMBOL = &apos;TRANSFPMP&apos; AND AnLuna = PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP AND VALOARE &lt;&gt; &apos;3&apos; ) K
		WHERE N.TIPNIR = 12 AND N.OPERAT = 1 AND N.ANULAT = 0
      AND IO.MG &lt;&gt; 3
      AND IOP.MG = 3
  )
  WHERE AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_IESIRI_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B532D38EA838250AB78C94CEF6D41F311DAA9F1A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_IESIRI_DOC (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;RESTLUNA&quot;,&quot;VALRESTLUNA&quot;,&quot;VALRESTLUNAV&quot;) AS
SELECT CODOBIECT, CODSUBUNIT, SUM(RESTLUNA) AS RESTLUNA, SUM(VALRESTLUNA) AS VALRESTLUNA, SUM(VALRESTLUNAV) AS VALRESTLUNAV
FROM (
  SELECT CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV, AN, LUNA   
  FROM (
    SELECT
      NS.CODOBIECT, G.CODSUBUNIT,
      CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT                 ELSE -L1.CANT                 END AS RESTLUNA,
      CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT*L1.PMPDOC       ELSE -L1.CANT*L1.PMPDOC       END AS VALRESTLUNA,
      CASE WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT*L1.PMPVALUTADOC ELSE -L1.CANT*L1.PMPVALUTADOC END AS VALRESTLUNAV,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.AN   WHEN E.CODIES IS NOT NULL THEN E.AN   ELSE T.AN   END AS AN,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.LUNA WHEN E.CODIES IS NOT NULL THEN E.LUNA ELSE T.LUNA END AS LUNA
    FROM LIVR L 
      INNER JOIN LIVR1          L1 ON L1.CODLIVR    = L.CODLIVR
      INNER JOIN NIRSTOC        NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
      INNER JOIN TMP_IOART_LUNA IO ON IO.CODIOART   = NS.CODIOART
      INNER JOIN NIR            N  ON N.CODNIR      = NS.CODNIR
      INNER JOIN NGEST          G  ON G.CODGEST     = N.GEST
      LEFT  JOIN IESIRI         E  ON E.CODIES      = L.CODIES    AND E.TIPDOC = L.TIPLIVR AND E.CodIes    &lt;&gt; PKG_GLOBALS.GetPMPCodIes
      LEFT  JOIN INTRARI        I  ON I.CODINTR     = L.CODINTR   AND I.TIPDOC = L.TIPLIVR AND I.Codintr   &lt;&gt; PKG_GLOBALS.GetPMPCodIntr
      LEFT  JOIN TRANSF         T  ON T.CODTRANSF   = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR AND T.CODTRANSF &lt;&gt; PKG_GLOBALS.GetPMPCodTransf
    WHERE L.OPERAT = 1 AND L.ANULAT = 0
      AND IO.MG = 3
  ) ssub1
  WHERE AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
) ssub2 
GROUP BY CODOBIECT, CODSUBUNIT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B8F636BFE3464119ED96E26AD3B9CDAC729440F5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_INTRARI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
  CODOBIECT,
  CODSUBUNIT,
  SUM(CANTINTR)  AS CANTINTR,
  SUM(VALINTR)   AS VALINTR,
  SUM(RESTLUNA)  AS RESTLUNA,
  SUM(VALVALUTA) AS VALVALUTA
FROM (
  SELECT *
  FROM (
    SELECT -- INTRARI IN STOC
      NS.CODOBIECT,
      G.CODSUBUNIT,
      NS.CANTNIR AS CANTINTR,
      (NS.PRET  - Coalesce(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
      NS.CANTNIR AS RESTLUNA,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.AN   ELSE T.AN   END AS AN,
      CASE WHEN I.CODINTR IS NOT NULL THEN I.LUNA ELSE T.LUNA END AS LUNA,
      (Coalesce(NS.PUVAL,0)) * NS.CANTNIR AS VALVALUTA
    FROM
      NIRSTOC NS,
      NIR N
      LEFT JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
      LEFT JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
      TMP_IOART_LUNA IO,
      NGEST G
    WHERE NS.CODIOART = IO.CODIOART
      AND IO.MG = 3
      AND NS.CODNIR = N.CODNIR
      AND N.ANULAT = 0 AND N.OPERAT = 1
      AND G.CODGEST = N.GEST
  )
  WHERE AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_INTRARI_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>42C4DE673AB249D1E34AA08DB098FF4008E837A3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_INTRARI_DOC (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;RESTLUNA&quot;,&quot;VALRESTLUNA&quot;,&quot;VALRESTLUNAV&quot;) AS
SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALRESTLUNA) AS VALRESTLUNA,
     SUM(VALRESTLUNAV) AS VALRESTLUNAV
   FROM
(
   SELECT * FROM
   (
   SELECT -- INTRARI IN STOC
     NS.CODOBIECT,
     G.CODSUBUNIT,
     NS.CANTNIR AS RESTLUNA,
    (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALRESTLUNA,
     NS.PUVAL * NS.CANTNIR AS VALRESTLUNAV,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.AN
       ELSE T.AN
     END AS AN,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.LUNA
       ELSE T.LUNA
     END AS LUNA
   FROM
     NIRSTOC NS,
     NIR N
     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
     LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
     TMP_IOART_LUNA IO,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.ANULAT = 0 AND N.OPERAT = 1
     AND G.CODGEST = N.GEST
  )
  WHERE
   AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_OBIECT_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B5381C3D78C1FC263F7D61AD83FFC5BDB9E49369</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_OBIECT_IESIRI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
(
   SELECT * FROM
   (
      SELECT
           NS.CODOBIECT,
           G.CODSUBUNIT,
           (
           CASE
             WHEN (T.CODTRANSF IS NOT NULL)
							    OR((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = &apos;3&apos;))
                  OR (I.CODINTR IS NOT NULL AND (K.VALOARE = &apos;3&apos;))
						 THEN -L1.CANT
             WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
               CASE
                 WHEN L.Tiplivr = 15 THEN L1.CANT
                 ELSE -L1.CANT
               END
             ELSE  0
           END)
           AS CANTINTR,
           CASE
             WHEN (T.CODTRANSF IS NOT NULL)
							    OR((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = &apos;3&apos;))
                  OR (I.CODINTR IS NOT NULL AND (K.VALOARE = &apos;3&apos;))
						 THEN  (NS.PRET  - NVL(NS.ADAOS, 0)) * (-L1.CANT)
             WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
               CASE
                 WHEN L.Tiplivr = 15 THEN (NS.PRET  - NVL(NS.ADAOS, 0)) * (L1.CANT)
                 ELSE (NS.PRET  - NVL(NS.ADAOS, 0)) * (-L1.CANT)
               END
             ELSE 0
           END
           AS VALINTR,
           CASE
             WHEN (E.CODIES IS NOT NULL)and(E.TIPDOC = 15) THEN L1.CANT
             ELSE -L1.CANT
           END
           AS RESTLUNA,
          CASE
            WHEN I.CODINTR IS NOT NULL THEN I.AN
            WHEN E.CODIES IS NOT NULL THEN E.AN
            ELSE T.AN
          END AS AN,
          CASE
            WHEN I.CODINTR IS NOT NULL THEN I.LUNA
            WHEN E.CODIES IS NOT NULL THEN E.LUNA
            ELSE T.LUNA
          END AS LUNA,
          CASE
             WHEN (T.CODTRANSF IS NOT NULL)
							    OR ((E.CodIes is not null) and (E.TipDoc = 23) AND (K.VALOARE = &apos;3&apos;))
						 THEN  (NVL(NS.PUVAL,0)) * (-L1.CANT)
             WHEN N.CODIES = L.CodIES and (E.CodIes is not null) THEN
               CASE
                 WHEN L.Tiplivr = 15 THEN (NVL(NS.PUVAL,0)) * L1.CANT
                 ELSE (NVL(NS.PUVAL,0)) * (-L1.CANT)
               END
             ELSE 0
           END
           AS VALVALUTA
      FROM
        LIVR1 L1,
        LIVR L
        LEFT OUTER JOIN IESIRI  E ON E.CODIES    = L.CODIES    AND E.TIPDOC = L.TIPLIVR
        LEFT OUTER JOIN INTRARI I ON I.CODINTR   = L.CODINTR   AND I.TIPDOC = L.TIPLIVR
        LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF = L.CODTRANSF AND T.TIPDOC = L.TIPLIVR,
				TMP_CONSTANTE K,
        NIRSTOC NS,
        TMP_IOART_LUNA IO,
        NIR N,
        NGEST G
      WHERE
       K.SIMBOL = &apos;TRANSFPMP&apos; and K.AnLuna = PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP
       AND
			 L1.CODLIVR = L.CODLIVR
       AND L.OPERAT = 1 AND L.ANULAT = 0
       AND NS.CODNIRSTOC = L1.CODNIRSTOC
       AND NS.CODOBIECT = PKG_INCHIDERI.GET_CODOBIECT_PMP
       AND NS.CODIOART = IO.CODIOART
       AND IO.MG = 3
       AND N.CODNIR = NS.CODNIR
       AND N.GEST = G.CODGEST
  ) WHERE
    AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY
CODOBIECT, CODSUBUNIT

UNION ALL

SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
(
   SELECT * FROM
   (
      SELECT
           NS.CODOBIECT,
           G.CODSUBUNIT,
           NS.CANTNIR AS CANTINTR,
           (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
           0  AS RESTLUNA,
           T.AN,
           T.LUNA,
           (NVL(NS.PUVAL,0)) * NS.CANTNIR  AS VALVALUTA
      FROM
        NIRSTOC NS,
        NIRSTOC NSP,
        NIR N,
        TRANSF T,
        TMP_IOART_LUNA IO,
        TMP_IOART_LUNA IOP,
        NGEST G,
				TMP_CONSTANTE K
			WHERE
				K.SIMBOL = &apos;TRANSFPMP&apos; and K.AnLuna = (PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP) AND K.VALOARE &lt;&gt; &apos;3&apos;
        AND NS.CODOBIECT = PKG_INCHIDERI.GET_CODOBIECT_PMP
			  AND NS.CODNIR = N.CODNIR
        AND N.TIPNIR = 12
        AND T.CODTRANSF = N.CODTRANSF
        AND NSP.CODNIRSTOC = NS.CODNIRSTOCPARINTE
        AND NS.CODIOART = IO.CODIOART
        AND IO.MG &lt;&gt; 3
        AND NSP.CODIOART = IOP.CODIOART
        AND IOP.MG = 3
        AND N.OPERAT = 1 AND N.ANULAT = 0
        AND N.GEST = G.CODGEST
  )
  WHERE
    AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY
CODOBIECT, CODSUBUNIT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_OBIECT_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1C273B715364123F07083D32F840DFADA110BB7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_OBIECT_INTRARI (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
     CODOBIECT,
     CODSUBUNIT,
     SUM(CANTINTR) AS CANTINTR,
     SUM(VALINTR) AS VALINTR,
     SUM(RESTLUNA) AS RESTLUNA,
     SUM(VALVALUTA) AS VALVALUTA
   FROM
(
   SELECT * FROM
   (
   SELECT -- INTRARI IN STOC
     NS.CODOBIECT,
     G.CODSUBUNIT,
     NS.CANTNIR AS CANTINTR,
    (NS.PRET  - NVL(NS.ADAOS, 0)) * NS.CANTNIR AS VALINTR,
     NS.CANTNIR AS RESTLUNA,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.AN
       ELSE T.AN
     END AS AN,
     CASE
       WHEN I.CODINTR IS NOT NULL THEN I.LUNA
       ELSE T.LUNA
     END AS LUNA,
     (NVL(NS.PUVAL,0)) * NS.CANTNIR AS VALVALUTA
   FROM
     NIRSTOC NS,
     NIR N
     LEFT OUTER JOIN INTRARI I ON I.CODINTR    = N.CODINTR   AND N.TIPNIR = I.TIPDOC
     LEFT OUTER JOIN TRANSF  T ON T.CODTRANSF  = N.CODTRANSF AND N.TIPNIR = T.TIPDOC,
     TMP_IOART_LUNA IO,
     NGEST G
   WHERE
     NS.CODIOART = IO.CODIOART
     AND NS.CODOBIECT = PKG_INCHIDERI.GET_CODOBIECT_PMP
     AND IO.MG = 3
     AND NS.CODNIR = N.CODNIR
     AND N.ANULAT = 0 AND N.OPERAT = 1
     AND G.CODGEST = N.GEST
  )
  WHERE
   AN = PKG_GLOBALS.GETANTEMP AND  LUNA = PKG_GLOBALS.GETLUNATEMP
)
GROUP BY CODOBIECT, CODSUBUNIT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PRECOMENZI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9303F8388F6701D37AF63793F943DCE50F0FAD1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PRECOMENZI (
&quot;CODPRECOMANDA&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CARNETDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;MONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;INCHISA&quot;,&quot;SERIADOC&quot;,&quot;VERIFICAT&quot;) AS
select
  CODPRECOMANDA,
  TIPDOC,
  ANULAT,
  BLOCAT,
  OPERAT,
  PREFIXDOC,
  NRDOC,
  CARNETDOC,
  DATADOC,
  VALOARE,
  AN,
  LUNA,
  OBS,
  MONEDA,
  SUBUNITATEA,
  USERID,
  DATACREARE,
  INCHISA,
  SERIADOC,
  VERIFICAT
from precomanda
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PROC_ACT_DEF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C309194C7A5EEFE396FA5C2EC72E2D97A3B5D64</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PROC_ACT_DEF (
&quot;CODPROCACTDEF&quot;,&quot;DENUMIRE&quot;,&quot;CODINTERN&quot;,&quot;SQL&quot;) AS
select &quot;CODPROCACTDEF&quot;,&quot;DENUMIRE&quot;,&quot;CODINTERN&quot;,&quot;SQL&quot; FROM PROC_ACT_DEF
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PRODCOMP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>292699E13FBFCC375D036547E631892DFEFC3407</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PRODCOMP (
&quot;CODPRODCOMP&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;,&quot;DATA&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;DENUMIRE&quot;,&quot;CANT&quot;,&quot;DEN_UM&quot;,&quot;CODARTICOL&quot;,&quot;TIPRETETA&quot;,&quot;PRET&quot;,&quot;COEFINDIRECTE&quot;,&quot;IMPLICIT&quot;,&quot;TIPSTRING&quot;,&quot;CODINTERN&quot;,&quot;INACTIV&quot;,&quot;ASCUNS&quot;) AS
select &quot;CODPRODCOMP&quot;,
       &quot;CODOBIECT&quot;,
       &quot;OBS&quot;,
       &quot;DATA&quot;,
       &quot;ANULAT&quot;,
       &quot;BLOCAT&quot;,
       &quot;OPERAT&quot;,
       &quot;DENUMIRE&quot;,
       &quot;CANT&quot;,
       &quot;DEN_UM&quot;,
       &quot;CODARTICOL&quot;,
       &quot;TIPRETETA&quot;,
       &quot;PRET&quot;,
       &quot;COEFINDIRECTE&quot;,
       &quot;IMPLICIT&quot;,
       &quot;TIPSTRING&quot;,
       &quot;CODINTERN&quot;,
       &quot;INACTIV&quot;,
       &quot;ASCUNS&quot;
from (select
        P.CODPRODCOMP,
        P.CODOBIECT,
        P.OBS,
        P.DATA,
        P.ANULAT,
        P.BLOCAT,
        P.OPERAT,
        OBJ.DENUMIRE,
        P.Cant,
        NUM.Den_UM,
        ART.CodArticol,
        P.TipReteta,
        P.Pret,
        P.CoefIndirecte,
        P.Implicit,
        case
          when P.TipReteta = 2 then &apos;Dezagregare&apos;
          else &apos;Agregare&apos;
        end TipString,
        OBJ.CodIntern,
        P.INACTIV,
        P.ASCUNS
from PRODCOMP P
     Inner Join NArtObj OBJ on P.CODOBIECT = OBJ.CODOBIECT
     Inner Join NArt ART on OBJ.CODARTICOL = ART.CODARTICOL
     Inner Join NUM on ART.UM = NUM.CODUM
where P.Operat = 1 AND P.Blocat &lt;&gt; 1 AND P.Anulat &lt;&gt; 1
)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PRODCOMP_BYOBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6DCFDAEC712DCDAEAF9CB0275F356F20B63082BA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PRODCOMP_BYOBIECT (
&quot;CODPRODCOMP&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;,&quot;DATA&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;DENUMIRE&quot;,&quot;CANT&quot;,&quot;TIPRETETA&quot;,&quot;TIPSTRINGRETETA&quot;,&quot;CODARTICOL&quot;,&quot;UM&quot;,&quot;DEN_UM&quot;,&quot;IMPLICIT&quot;) AS
select P.CODPRODCOMP, P.CODOBIECT, P.OBS, P.DATA, P.ANULAT, P.BLOCAT, P.OPERAT, OBJ.DENUMIRE, P.CANT, P.Tipreteta,
       case
         when P.TipReteta = 1 then &apos;Agregare&apos;
         else &apos;Dezagregare&apos;
       end as TipStringReteta,
       OBJ.CODARTICOL,
       ART.Um,
       NUM.DEN_UM,
       P.Implicit
  from PRODCOMP P
       INNER JOIN NARTOBJ OBJ ON P.CODOBIECT = OBJ.Codobiect
       INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
       INNER JOIN NUM ON ART.UM = NUM.CODUM
  where P.CODOBIECT = PKG_SELECTARTICOLE.GETOBIECTANALIZAT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PRODCOMP_DEZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>61802EA22E2FF633C41C49AB54DAC21AAAFE3AB2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PRODCOMP_DEZ (
&quot;CODPRODCOMP&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;,&quot;DATA&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;DENUMIRE&quot;,&quot;CANT&quot;,&quot;DEN_UM&quot;,&quot;CODARTICOL&quot;,&quot;TIPRETETA&quot;,&quot;PRET&quot;,&quot;COEFINDIRECTE&quot;,&quot;IMPLICIT&quot;,&quot;TIPSTRING&quot;) AS
select &quot;CODPRODCOMP&quot;,
       &quot;CODOBIECT&quot;,
       &quot;OBS&quot;,
       &quot;DATA&quot;,
       &quot;ANULAT&quot;,
       &quot;BLOCAT&quot;,
       &quot;OPERAT&quot;,
       &quot;DENUMIRE&quot;,
       &quot;CANT&quot;,
       &quot;DEN_UM&quot;,
       &quot;CODARTICOL&quot;,
       &quot;TIPRETETA&quot;,
       &quot;PRET&quot;,
       &quot;COEFINDIRECTE&quot;,
       &quot;IMPLICIT&quot;,
       &quot;TIPSTRING&quot;
from (select
        P.CODPRODCOMP,
        P.CODOBIECT,
        P.OBS,
        P.DATA,
        P.ANULAT,
        P.BLOCAT,
        P.OPERAT,
        OBJ.DENUMIRE,
        P.Cant,
        NUM.Den_UM,
        ART.CodArticol,
        P.TipReteta,
        P.Pret,
        P.CoefIndirecte,
        P.Implicit,
        case
          when P.TipReteta = 2 then &apos;Dezagregare&apos;
          else &apos;Agregare&apos;
        end TipString
from PRODCOMP P
     Inner Join NArtObj OBJ on P.CODOBIECT = OBJ.CODOBIECT
     Inner Join NArt ART on OBJ.CODARTICOL = ART.CODARTICOL
     Inner Join NUM on ART.UM = NUM.CODUM
where P.Operat = 1 AND P.Blocat &lt;&gt; 1 AND P.Anulat &lt;&gt; 1 AND P.TipReteta = 2 ) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PROIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>49F98662EF00066E6B839DE670AF0E60EA0C43C6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PROIECT (
&quot;CODPROIECT&quot;,&quot;DENUMIRE&quot;,&quot;CODVERSIUNE&quot;,&quot;VERSIUNE&quot;,&quot;DATAPROIECT&quot;,&quot;ACTIV&quot;,&quot;FINALIZAT&quot;,&quot;BLOCAT&quot;,&quot;DEN_UM&quot;,&quot;CANT&quot;,&quot;PRET&quot;) AS
select P.CodProiect, Obj.Denumire, P.CodVersiune, P.Versiune, P.DataProiect, P.activ,
         P.Finalizat, P.Blocat, num.den_um, pn.cant, pc.pret
    from Proiect P
         inner Join NArtObj OBJ on P.CODOBIECTPROD = OBJ.CODOBIECT
         inner join nart art on obj.codarticol = art.codarticol
         inner join num on art.um = num.codum
         inner join ProiectNod PN on P.CODPROIECT = PN.CODPROIECT AND nvl(PN.NODORIGINAL, 0) = 0
         inner join prodcomp pc on pn.codreteta = pc.codprodcomp 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PROIECT_TREE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D6F265FFAA1A91A5D8088E1649F16304311E8D70</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PROIECT_TREE (
&quot;ORDINE&quot;,&quot;CODPROIECTNOD&quot;,&quot;DENUMIRE&quot;,&quot;TIP&quot;,&quot;CODPARINTE&quot;,&quot;COPIL&quot;) AS
SELECT &quot;ORDINE&quot;,&quot;CODPROIECTNOD&quot;,&quot;DENUMIRE&quot;,&quot;TIP&quot;,&quot;CODPARINTE&quot;,&quot;COPIL&quot; FROM
(
SELECT
  ROWNUM AS ORDINE,
  CODPROIECTNOD,
  DENUMIRE,
  TIP,
  CODPARINTE,
  copil
FROM
(
SELECT
  V.CODPROIECTNOD,
  OBJ.DENUMIRE,
  V.TIP,
  V.CODPARINTE,
  connect_by_isleaf copil
FROM
  ( SELECT PN.CodProiectNod,
           PN.CodObiect,
           PN.Tip,
           PN.NODORIGINAL CodParinte
    FROM PROIECTNOD PN
         INNER JOIN PROIECT P ON PN.Codproiect = P.CODPROIECT
    WHERE P.CODPROIECT = pkg_proiect.getcodproiect
     ) V
  LEFT JOIN NARTOBJ OBJ ON V.CODOBIECT = OBJ.CodObiect
  START WITH V.CODPARINTE IS NULL CONNECT BY PRIOR  V.CODPROIECTNOD = V.CODPARINTE
)
order by codproiectnod
) ORDER BY ORDINE 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PROMO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>607139EC5CF706445AE07D916A1EABAD4F90D375</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PROMO (
&quot;CODPROMO&quot;,&quot;TIPDOC&quot;,&quot;ANULAT&quot;,&quot;BLOCAT&quot;,&quot;OPERAT&quot;,&quot;NRDOC&quot;,&quot;DATASTART&quot;,&quot;DATAEND&quot;,&quot;PARTENER&quot;,&quot;CODLOCATIE&quot;,&quot;CODFISCAL&quot;,&quot;MONEDA&quot;,&quot;OBS&quot;,&quot;SUBUNITATEA&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;DEN_PART&quot;,&quot;DEN_MONEDA&quot;,&quot;DEN_LOCALIT&quot;,&quot;SUBUNITATEDOC&quot;) AS
SELECT
  P.CODPROMO, P.TIPDOC, P.ANULAT, P.BLOCAT, P.OPERAT, P.NRDOC, P.DATASTART, P.DATAEND,
  CASE Nvl(PP.CNT,0) WHEN 0 THEN P.Partener WHEN 1 THEN PP.PARTENER ELSE 0 END partener,
  CASE Nvl(PP.CNT,0) WHEN 0 THEN P.CodLocatie WHEN 1 THEN PP.CodLocatie ELSE 0 END codlocatie,
  CASE Nvl(PP.CNT,0) WHEN 0 THEN P.CODFISCAL WHEN 1 THEN PP.CODFISCAL ELSE 0 END codfiscal,
  P.MONEDA, P.OBS,
  CASE
    WHEN Nvl(PS.CNT,0) = 0 THEN P.Subunitatea
    WHEN Nvl(PS.CNT,0) = 1 THEN PS.Subunitatea
    ELSE PKG_GLOBALS.GETSUBUNITATE
  END subunitatea,
  P.AN, P.LUNA, P.USERID, P.DATACREARE,
  NP.Den_Part,
  M.Den_Moneda, L.Den_Localit, S.DEN_SUBUNIT SUBUNITATEDOC
FROM PROMO P
  LEFT JOIN (
    SELECT
      CODPROMO, Min(SUBUNITATEA) SUBUNITATEA, Count(1) Cnt,
      Sum(CASE WHEN SUBUNITATEA = PKG_GLOBALS.GETSUBUNITATE THEN 1 ELSE 0 END) OK
    FROM PROMOSUB
    GROUP BY CODPROMO ) PS ON PS.CodPromo = P.CodPromo
  LEFT JOIN (
    SELECT
      CODPROMO,
      Min(CODCLASEP) CODCLASEP, Min(PARTENER) PARTENER, Min(CODLOCATIE) CODLOCATIE,
      Min(CODFISCAL) CODFISCAL, Min(CODPERSC) CODPERSC, Count(1) Cnt
    FROM PROMOPART
    GROUP BY CODPROMO ) PP ON PP.CodPromo = P.CodPromo
  LEFT JOIN NPART    NP ON NP.CodPArt   = CASE Nvl(PP.CNT,0) WHEN 0 THEN P.Partener WHEN 1 THEN PP.PARTENER ELSE 0 END
  LEFT JOIN NAGENDA AG ON AG.Codagenda = CASE Nvl(PP.CNT,0) WHEN 0 THEN P.CodLocatie WHEN 1 THEN PP.CodLocatie ELSE 0 END
  LEFT JOIN NLOCALIT L ON L.Codlocalit = AG.CodLocalit
  LEFT JOIN NMONEDE  M ON M.CodMoneda  = P.Moneda
  LEFT JOIN NSUBUNIT S ON S.CodSubunit = CASE
                                           WHEN Nvl(PS.CNT,0) = 0 THEN P.Subunitatea
                                           WHEN Nvl(PS.CNT,0) = 1 THEN PS.Subunitatea
                                           ELSE PKG_GLOBALS.GETSUBUNITATE
                                         END
WHERE P.TIPDOC = PKG_GLOBALS.GETTIPPROMOTIE
  AND P.DATAEND &gt;= To_Date(&apos;01.&apos;||PKG_GLOBALS.GetLunaLucru||&apos;.&apos;||PKG_GLOBALS.GetAnLucru,&apos;DD.MM.YYYY&apos;)
  AND (PKG_GLOBALS.GETSUBUNITATE = 1 OR Nvl(P.Subunitatea,0) = 1 OR Nvl(PS.OK,0) = 1 OR Nvl(P.Subunitatea,0) = PKG_GLOBALS.GETSUBUNITATE)
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RAC_CARS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F6E2978F7D417DF143F466D092F19D172B021CD9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RAC_CARS (
&quot;CODAUTO&quot;,&quot;DATA&quot;,&quot;CODGEST&quot;,&quot;GESTIUNE&quot;,&quot;SUBUNITATE&quot;,&quot;CODCLASA&quot;,&quot;INACTIV&quot;,&quot;EXTERN&quot;,&quot;CODOBIECT&quot;,&quot;NRAUTO&quot;,&quot;MARCA&quot;,&quot;MODEL&quot;,&quot;ANF&quot;,&quot;CODGRECHIV&quot;,&quot;IND&quot;,&quot;CLASA&quot;,&quot;GENERIC&quot;) AS
SELECT
  P.CodNParcAut CodAuto,
  NPG.Data,
  Coalesce(NPG.CodGest,0) CodGest, NG.Den_Gest Gestiune, NG.Codsubunit Subunitate, NG.CodClasa,
	Coalesce(NPG.Status,0) Inactiv, Coalesce(P.Extern,0) Extern,
	P.CodArt CodObiect,
	P.Nrinreg NrAuto, Ma.Marca, Mo.Model, P.AnF,
  Coalesce(G.CodGrEchiv, 0) CodGrEchiv, Coalesce(G.IND,0) Ind, G.DENUMIRE Clasa, Coalesce(E.Generic,0) Generic
FROM NParcAut P
  INNER JOIN NParcG NPG ON NPG.CodNParcAut = P.CodNParcAut
  LEFT JOIN NEchiv E ON E.Codobiect = P.CodArt
  LEFT JOIN GrEchiv G ON G.CODGRECHIV = E.CodGrupa
  LEFT JOIN Nmodeleauto Mo ON Mo.CODMODELEAUTO = p.Model
  LEFT JOIN Nmarciauto Ma ON Ma.CODMarciAuto = p.Marca
  LEFT JOIN NGest NG on NG.CODGEST = NPG.CodGest
WHERE NPG.Data = ( SELECT Max(xNPG.DATA)
                   FROM NParcG xNPG
									 WHERE xNPG.CodNParcAut = P.CodNParcAut
									 AND ((Pkg_Rac_Rez.RAC_DATACuOra = 1 and xNPG.Data &lt;= Pkg_Rac_Rez.RAC_DATASTART)
									       or
												 Trunc(xNPG.Data) &lt;= Pkg_Rac_Rez.RAC_DATASTART))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RAC_CATP</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BC897F02C026332505EE6312E2E4DE27BD2D6B11</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RAC_CATP (
&quot;CODRAC_CATP&quot;,&quot;OBS&quot;,&quot;CODPART&quot;,&quot;CODAGENDA&quot;,&quot;CODGEST&quot;,&quot;CODSUBUNIT&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;PART&quot;,&quot;GEST&quot;,&quot;SEDIU&quot;,&quot;SUBUNIT&quot;,&quot;CODSEDIU&quot;,&quot;ABONAMENT&quot;) AS
SELECT
      R.CODRAC_CATP,
      R.OBS,
      P.CODPART,
      S.codagenda ,
      0 CodGest,
      0 Codsubunit,
      R.DATASTART,
      R.DATASTOP,
      P.Den_Part Part,
      G.Gest,
      S.OBS Sediu,
      SB.Subunit,
      R.CODSEDIU,
      NVL(R.Abonament,0) abonament
FROM Rac_CATP R
         LEFT  JOIN NPART P on P.CodPART = Nvl(R.CODPARTENER,0)
         LEFT  JOIN NAGENDA S on s.codagenda = Nvl(R.CODSEDIU,0)
         LEFT  JOIN
            (Select Codrac_Catp, string_agg(Den_Gest) Gest from
               ( Select distinct R.Codrac_Catp, G.Den_Gest
                 from RAC_CATP2 R
                 inner join NGEst G on G.CodGest = R.CodGest where Nvl(R.CodGest,0) &gt; 0)
            group by Codrac_Catp) G on G.Codrac_Catp = R.Codrac_Catp
         LEFT  JOIN
            (Select Codrac_Catp, string_agg(Den_Subunit) Subunit from
               ( Select distinct R.Codrac_Catp, S.Den_Subunit
                 from RAC_CATP2 R
                 inner join NSubunit S on S.CodSubunit = R.CodSubunitate where Nvl(R.CodSubunitate,0) &gt; 0)
            group by Codrac_Catp) SB on SB.Codrac_Catp = R.Codrac_Catp
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RAC_P</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>920934B9F7596E41F4E24F426E39E1EAD5B58B07</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RAC_P (
&quot;CODRAC_P&quot;,&quot;OBS&quot;,&quot;SMONEDA&quot;,&quot;TIPC&quot;,&quot;CODTIP&quot;) AS
SELECT
      R.Codrac_p,
			R.Obs,
			M.Simbol SMoneda,
			case
        when R.Tip = 0 then &apos;Zile&apos;
        when R.Tip = 1 then &apos;Km&apos;
        when R.Tip = 2 then &apos;Ore&apos;
        when R.Tip = 3 then &apos;Buc&apos;
        else &apos;?&apos;
      end TipC,
      R.Tip CodTip
    FROM Rac_P R
         INNER JOIN NMONEDE M on M.CodMoneda = Nvl(R.Moneda,0)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RAC_TRANSFER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C2737E0666A63F1897BB86010D6CD6C80E8E923</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RAC_TRANSFER (
&quot;CODGESTSURSA&quot;,&quot;CODGESTDEST&quot;,&quot;CODAUTO&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;DATAPRED&quot;) AS
select X.&quot;CODGESTSURSA&quot;,X.&quot;CODGESTDEST&quot;,X.&quot;CODAUTO&quot;,X.&quot;DATASTART&quot;,X.&quot;DATASTOP&quot;,X.&quot;DATAPRED&quot; from
(
select R.CodGestSursa, R.CodGestDest, NVL(C.MijlTransp,0) CodAuto, R.DataStart, R.DataStop, R.DataPred
 from RAC_REZ  R
 inner join Comanda c on R.codcomanda = c.codcomanda
 where Nvl(C.Operat, 0) = 1
       and Nvl(R.Predat, 0) = 1
       and R.CodGestSursa &lt;&gt; R.CodGestDest
       and Pkg_Rac_Rez.RAC_DATASTART &gt; R.DataPred
union all
select X.CodGestDest CodGestSursa, R.CodGestSursa CodGestDest, NVL(C.MijlTransp,0) CodAuto, R.DataStart, R.DataStop, R.DataPred
 from RAC_REZ  R
 inner join Comanda c on R.codcomanda = c.codcomanda
 inner join Comanda XX on XX.codcomanda = R.CodRezervare
 inner join Rac_Rez X on X.codcomanda = XX.codcomanda
 where Nvl(C.Operat, 0) = 1
       and Nvl(R.Predat,0) = 1
       and Nvl(R.CodRezervare, 0) &gt; 0
			 and Nvl(XX.Mijltransp,0) = Nvl(C.Mijltransp,0)
       and R.CodGestSursa &lt;&gt; R.CodGestDest
       and Pkg_Rac_Rez.RAC_DATASTART &gt; R.DataPred
) X
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RECLAMATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53D5F9127D33FA944552536CC3C4CAC38730C414</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RECLAMATII (
&quot;CODRECLAMATIE&quot;,&quot;NRDOC&quot;,&quot;SERIADOC&quot;,&quot;TIPDOC&quot;,&quot;CODDOC&quot;,&quot;DATADOC&quot;,&quot;DEN_SUBUNIT&quot;,&quot;CODSUBUNIT&quot;,&quot;MOTIV&quot;,&quot;RECLAMATIE&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;DEN_PART&quot;,&quot;CODPART&quot;,&quot;TIPDOCR&quot;,&quot;CODDOCR&quot;,&quot;REZOLVAT&quot;,&quot;DATAREZ&quot;,&quot;RESP&quot;,&quot;USERNAME&quot;,&quot;DATACREARE&quot;,&quot;IMPUTABILA&quot;,&quot;TIPIMPUT&quot;) AS
SELECT
    R.CODRECLAMATIE,
    R.NRDOC,
    R.SERIADOC,
    M1.NUMEEXT TipDoc,
    R.CodDOC,
    R.DATADOC,
    S.Den_subunit,
    R.CODSUBUNIT,
    R.Motiv,
    R.Reclamatie,
    R.Operat,
    R.Blocat,
    R.Anulat,
    PR.DEN_PART,
    R.Codpart,
    M2.NUMEEXT TipDocR,
    R.CodDOCR,
    Decode(R.Rezolvat,0,&apos;Nu&apos;,1,&apos;Da&apos;) Rezolvat,
    R.DataRez,
    NP.Nume||&apos; &apos;||NP.Prenume Resp,
    UT.Username,
    Case when C.TipDoc is not null then C.DataCreare
         when I.TipDoc is not null then I.DataCreare
         when E.TipDoc is not null then E.DataCreare
   end DataCreare, R.IMPUTABILA, R.TIPIMPUT
FROM RECLAMATII R
 LEFT JOIN NPART PR on PR.CodPart = R.CodPart
 LEFT JOIN NPers NP on NP.CodPers = R.CodResp
 LEFT JOIN NSUBUNIT S ON S.CodSubunit = R.Codsubunit
 LEFT JOIN MACHETE M1 on M1.CODMACHETA = R.Tipdoc
 LEFT JOIN MACHETE M2 on M2.CODMACHETA = R.TipdocR
 LEFT JOIN TMP_UTILIZATOR UT on UT.CodUtilizator = R.CodUtilizator
 left join Comanda  C  on C.CodComanda  = R.CodDoc and C.TipDoc = R.TipDoc
 left join Intrari  I  on I.CodIntr     = R.CodDoc and I.TipDoc = R.TipDoc
 left join Iesiri   E  on E.CodIes      = R.CodDoc and E.TipDoc = R.TipDoc
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_DE_STINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>193D9036142DA2BF5FFBBD7107C3B9FE8AD2564D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_DE_STINS (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;VALOARE&quot;,&quot;ICONT&quot;,&quot;SEMNIFICATIE&quot;,&quot;CODPART&quot;,&quot;CODIOPART1&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;STINS&quot;,&quot;COEFPROVIZION&quot;) AS
SELECT
  CODOBLIGPIF,
  CODGENERAL,
  VALOARE,
  ICONT,
  SEMNIFICATIE,
  CODPART,
  CODIOPART1,
 	CODGEST,
 	CURS,
  TVA,
  STINS,
	COEFPROVIZION
 FROM
   (
    -- INTRARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
     O.SEMNIFICATIE IN (100, 110, 120) AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)
     AND G.MONEDA = PKG_REG.GETMONEDAREG
     AND NVL(G.FaraReg, 0) = 0

   UNION ALL

-- obligatii de stins provenite din DVI -uri
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT OUTER JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE
      O.SEMNIFICATIE IN (130) AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND G.MONEDA = PKG_REG.GETMONEDAREG
      AND NVL(G.FaraReg, 0) = 0

    UNION ALL
   -- AVIZE INTRARE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
--      CASE
--        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
--        ELSE S.VALOARE
--      END AS STINS,
      S.VALOARE AS STINS,
		   	O.COEFPROVIZION
    FROM
         OBLIGPIF O
         LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
         LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
         LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
         LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
         LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
        O.SEMNIFICATIE IN (140) AND I.TIPDOC = 2 AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
        AND (I.OPERAT = 1)AND(I.ANULAT = 0)
        AND G.MONEDA = PKG_REG.GETMONEDAREG
        AND NVL(G.FaraReg, 0) + NVL(I.FaraReg, 0) = 0



    UNION ALL

   -- AVIZE IESIRE DE STINS
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
--      CASE
--        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
--        ELSE S.VALOARE
--      END AS STINS,
      S.VALOARE AS STINS,
		   	O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (240) AND I.TIPDOC = 20 AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND G.MONEDA = PKG_REG.GETMONEDAREG
       AND NVL(G.FaraReg, 0) +  NVL(I.FaraReg, 0) = 0


    UNION ALL

   -- obligatii de stins provenite din IESIRI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (200, 210, 220) AND I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND G.MONEDA = PKG_REG.GETMONEDAREG
      AND NVL(G.FaraReg, 0) = 0

    UNION ALL
   -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      NVL(O.VALOARE, 0) - NVL(G.TVA, 0) AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE
     ((T1.INITIALIZARI = 1)OR(NVL(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))AND
      G.TIPDOC IN (29, 30, 31, 33) AND
      T1.AN = PKG_GLOBALS.GETANLUCRU AND
      T1.LUNA = PKG_GLOBALS.GETLUNALUCRU AND
      G.SEMNIFICATIE IN (310, 410, 330, 430, 500, 600)
      AND G.MONEDA = PKG_REG.GETMONEDAREG
      AND NVL(G.FaraReg, 0) = 0

    UNION ALL

   -- obligatii de stins provenite din NOTE CONTABILE
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      O.VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (1200, 1201)  AND N1.AN = PKG_GLOBALS.GETANLUCRU AND N1.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND G.MONEDA = PKG_REG.GETMONEDAREG
      AND NVL(G.FaraReg, 0) = 0

    UNION ALL

   -- obligatii de stins provenite din COMPENSARI
    SELECT
      O.CODOBLIGPIF,
      O.CODGENERAL,
      CASE
        WHEN O.SEMNIFICATIE = 1303 THEN NVL(O.VALOARE, 0)
        ELSE NVL(O.VALOARE, 0) - NVL(G.TVA, 0)
      END
      AS VALOARE,
      O.ICONT,
      O.SEMNIFICATIE,
      O.CODPART,
      IO.CODIOPART1,
      O.CODGEST,
     	NVL(GREG.CURS, G.CURS) AS CURS,
      G.TVA,
      CASE
        WHEN O.VALOARE &lt; 0 THEN -S.VALOARE
        ELSE S.VALOARE
      END AS STINS,
			O.COEFPROVIZION
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
      LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (1301, 1351, 1303) AND C.AN = PKG_GLOBALS.GETANLUCRU AND C.LUNA = PKG_GLOBALS.GETLUNALUCRU
      AND G.MONEDA = PKG_REG.GETMONEDAREG
      AND NVL(G.FaraReg, 0) = 0

)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_IESIRI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A61CB318AC4C027291014385D9777F905CEE215</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_IESIRI (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;ICONT&quot;,&quot;SIMBOLCONT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;SEMNIFICATIE&quot;,&quot;REST&quot;,&quot;VALOARE&quot;,&quot;VALOAREREG&quot;,&quot;VALOAREDOC&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;) AS
SELECT
  OL.CODOBLIGPIF, G.CodGeneral, O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
	I.PrefixDoc, I.NrDoc, I.DataDoc,
  O.CodPart, NP.Den_Part,
  O.Semnificatie,
  NVL(OL.Rest, 0) AS Rest,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0))
		ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))))
	END) AS Valoare,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * PKG_REG.GetCursReg)
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * NVL(GREG.CURS, G.CURS))
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * NVL(GREG.CURS, G.CURS))
	END) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIFLUNA OL
  LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN IESIRI I ON I.CODIES = G.CODDOC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  TO_DATE(&apos;01.&apos; || TO_CHAR(OL.LUNA) || &apos;.&apos; || TO_CHAR(OL.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
  O.SEMNIFICATIE IN (200, 210) AND
  -- 200: iesiri catre clienti
  -- 210: incasari in avans facturate
  G.MONEDA = PKG_REG.GetMonedaReg
UNION ALL
-- IESIRI DIN OBLIGPIF
SELECT
  O.CODOBLIGPIF, G.CodGeneral, O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
	I.PrefixDoc, I.NrDoc, I.DataDoc,
  O.CodPart, NP.Den_Part,
  O.Semnificatie,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Rest,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Valoare,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * PKG_REG.GetCursReg) AS ValoareReg,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN IESIRI I ON I.CODIES = G.CODDOC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  O.SEMNIFICATIE IN (200, 210) AND
  -- 200: iesiri catre clienti
  -- 210: incasari in avans facturate
  G.MONEDA = PKG_REG.GetMonedaReg AND
  NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0 AND
	I.Luna = PKG_GLOBALS.GETLUNALUCRU AND I.An = PKG_GLOBALS.GETANLUCRU AND
  NVL(I.INITIALIZARI, 0) &lt;&gt; 1
UNION ALL
-- STINGERI PRIN TREZOR
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN IESIRI I_STINS ON I_STINS.CODIES = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINGATOR ON T1_STINGATOR.CODTREZOR1 = G_STINGATOR.CODDOC
	LEFT OUTER JOIN TREZOR T_STINGATOR ON T_STINGATOR.CODTREZOR = T1_STINGATOR.CODTREZOR
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (200) AND
  O_STINGATOR.SEMNIFICATIE IN (400, 420) AND
  -- 400 stinge 200
  -- 420 stinge 200 in rosu
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1)) AND
	NVL(T_STINGATOR.OPERAT, 0) = 1 AND NVL(T1_STINGATOR.ANULAT, 0) = 0 AND
	T1_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND T1_STINGATOR.An = PKG_GLOBALS.GETANLUCRU
UNION ALL
-- STINGERI PRIN IESIRI
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN IESIRI I_STINS ON I_STINS.CODIES = G_STINS.CODDOC
	LEFT OUTER JOIN IESIRI I_STINGATOR ON I_STINGATOR.CODIES = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (210) AND
  O_STINGATOR.SEMNIFICATIE IN (211) AND
	-- 211 stinge 210
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1)) AND
	NVL(I_STINGATOR.OPERAT, 0) = 1 AND NVL(I_STINGATOR.ANULAT, 0) = 0 AND
	I_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND I_STINGATOR.An = PKG_GLOBALS.GETANLUCRU-- AND
UNION ALL
-- STINGERI PRIN COMPENS
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN IESIRI I_STINS ON I_STINS.CODIES = G_STINS.CODDOC
	LEFT OUTER JOIN COMPENS C_STINGATOR ON C_STINGATOR.CODCOMPENS = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (200) AND
  O_STINGATOR.SEMNIFICATIE IN (1300, 1350) AND
	-- 1300, 1350 COMPENS
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1)) AND
	C_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND C_STINGATOR.An = PKG_GLOBALS.GETANLUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_INTRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>920B2603560D53D18A2EDC7B5E57214E3302BDB3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_INTRARI (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;ICONT&quot;,&quot;SIMBOLCONT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;SEMNIFICATIE&quot;,&quot;REST&quot;,&quot;VALOARE&quot;,&quot;VALOAREREG&quot;,&quot;VALOAREDOC&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;) AS
SELECT
  OL.CODOBLIGPIF,	G.CodGeneral,	O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  I.PrefixDoc, I.NrDoc, I.DataDoc,
  O.CODPART, NP.DEN_PART,
  O.Semnificatie,
  NVL(OL.Rest, 0) AS Rest,
	(CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0))
		ELSE (NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1)))
	END) AS Valoare,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * PKG_REG.GetCursReg)
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * NVL(GREG.CURS, G.CURS))
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * NVL(GREG.CURS, G.CURS))
	END) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIFLUNA OL
  LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = G.CODDOC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  TO_DATE(&apos;01.&apos; || TO_CHAR(OL.LUNA) || &apos;.&apos; || TO_CHAR(OL.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
  O.SEMNIFICATIE IN (100, 110) AND
  -- 100: intrari de la furnizori
  -- 110: plati in avans facturate
  G.MONEDA = PKG_REG.GetMonedaReg
UNION ALL
-- INTRARI DIN OBLIGPIF
SELECT
  O.CODOBLIGPIF, G.CodGeneral, O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  I.PrefixDoc, I.NrDoc, I.DataDoc,
  O.CODPART, NP.Den_Part,
  O.Semnificatie,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Rest,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Valoare,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * PKG_REG.GetCursReg) AS ValoareReg,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = G.CODDOC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  O.SEMNIFICATIE IN (100, 110) AND
  -- 100: intrari de la furnizori
  -- 110: plati in avans facturate
  G.MONEDA = PKG_REG.GetMonedaReg AND
  NVL(I.OPERAT, 0) = 1 AND NVL(I.ANULAT, 0) = 0 AND
	I.Luna = PKG_GLOBALS.GETLUNALUCRU AND I.An = PKG_GLOBALS.GETANLUCRU AND
  NVL(I.INITIALIZARI, 0) &lt;&gt; 1
UNION ALL
-- STINGERI	PRIN TREZOR
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN INTRARI I_STINS ON I_STINS.CODINTR = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINGATOR ON T1_STINGATOR.CODTREZOR1 = G_STINGATOR.CODDOC
	LEFT OUTER JOIN TREZOR T_STINGATOR ON T_STINGATOR.CODTREZOR = T1_STINGATOR.CODTREZOR
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (100) AND
  O_STINGATOR.SEMNIFICATIE IN (300, 320) AND
  -- 300 stinge 100
  -- 320 stinge 100 in rosu
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1))  AND
	NVL(T_STINGATOR.OPERAT, 0) = 1 AND NVL(T1_STINGATOR.ANULAT, 0) = 0 AND
	T1_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND T1_STINGATOR.An = PKG_GLOBALS.GETANLUCRU
UNION ALL
-- STINGERI PRIN INTRARI
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN INTRARI I_STINS ON I_STINS.CODINTR = G_STINS.CODDOC
	LEFT OUTER JOIN INTRARI I_STINGATOR ON I_STINGATOR.CODINTR = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (110) AND
  O_STINGATOR.SEMNIFICATIE IN (111) AND
	-- 111 stinge 110
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1)) AND
  NVL(I_STINGATOR.OPERAT, 0) = 1 AND NVL(I_STINGATOR.ANULAT, 0) = 0 AND
	I_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND I_STINGATOR.An = PKG_GLOBALS.GETANLUCRU
UNION ALL
-- STINGERI PRIN COMPENS
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  I_STINS.PrefixDoc, I_STINS.NrDoc, I_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN INTRARI I_STINS ON I_STINS.CODINTR = G_STINS.CODDOC
	LEFT OUTER JOIN COMPENS C_STINGATOR ON C_STINGATOR.CODCOMPENS = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (100) AND
  O_STINGATOR.SEMNIFICATIE IN (1300, 1350) AND
	-- 1300, 1350 COMPENS
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(I_STINS.OPERAT, 0) = 1 AND NVL(I_STINS.ANULAT, 0) = 0) OR (NVL(I_STINS.INITIALIZARI, 0) = 1)) AND
	C_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND C_STINGATOR.An = PKG_GLOBALS.GETANLUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_LUNAPREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4A2E9E7D932B123A574E06019788F0293DF37D74</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_LUNAPREC (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;VALOARE&quot;,&quot;ICONT&quot;,&quot;SEMNIFICATIE&quot;,&quot;CODPART&quot;,&quot;CODIOPART1&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;STINS&quot;,&quot;COEFPROVIZION&quot;) AS
SELECT
  O.CODOBLIGPIF,
  O.CODGENERAL,
  CASE
   WHEN O.SEMNIFICATIE IN (140, 240, 1303) THEN NVL(OL.REST, 0)
   ELSE NVL(OL.REST, 0) - NVL(OL.RESTTVA, 0)
  END AS VALOARE,
  O.ICONT,
  O.SEMNIFICATIE,
  O.CODPART,
  IO.CODIOPART1,
 	NVL(O.CODGEST, 0) AS CODGEST,
 	NVL(GREG.CURS, G.CURS) AS CURS,
  G.TVA,
  CASE
    WHEN O.VALOARE &lt; 0 AND (NOT O.SEMNIFICATIE IN (140, 240)) THEN -S.VALOARE
    ELSE S.VALOARE
  END AS STINS,
	O.COEFPROVIZION
FROM
  OBLIGPIFLUNA OL,
  OBLIGPIF O
  LEFT OUTER JOIN TMP_STINGERE_LUNA  S ON S.CODSTINSPIF = O.CODOBLIGPIF
  LEFT OUTER JOIN TMP_IOPARTLUNA IO ON IO.CODPART = O.CODPART,
  GENERAL G
  LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
WHERE
  OL.AN = PKG_GLOBALS.GetANPRECEDENT
  AND OL.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND OL.REST &lt;&gt; 0
  AND OL.CODOBLIGPIF = O.CODOBLIGPIF
  AND G.CODGENERAL = O.CODGENERAL
  AND G.MONEDA = PKG_REG.GetMonedaReg
  AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 240, 200, 210, 220, 310, 410, 330, 430, 500, 600, 1200, 1201, 1301, 1351, 1303)
  AND NVL(G.FaraReg, 0) = 0
  AND PKG_GLOBALS.ANLUNAAVIZOK(G.TIPDOC, G.CODDOC) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_NC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>966576772CE69174552D90146AE0DFF864CC273F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_NC (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;ICONT&quot;,&quot;SIMBOLCONT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;SEMNIFICATIE&quot;,&quot;REST&quot;,&quot;VALOARE&quot;,&quot;VALOAREREG&quot;,&quot;VALOAREDOC&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;) AS
SELECT
  OL.CODOBLIGPIF,	G.CodGeneral,	O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  &apos;NC&apos; AS PrefixDoc, N.NrDoc, N.DataDoc,
  O.CodPart, NP.Den_Part,
  O.Semnificatie,
  NVL(OL.Rest, 0) AS Rest,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0))
		ELSE (NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1)))
	END) AS Valoare,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * PKG_REG.GetCursReg)
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * NVL(GREG.CURS, G.CURS))
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * NVL(GREG.CURS, G.CURS))
	END) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIFLUNA OL
  LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  TO_DATE(&apos;01.&apos; || TO_CHAR(OL.LUNA) || &apos;.&apos; || TO_CHAR(OL.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
  O.SEMNIFICATIE IN (1200, 1201) AND
  -- 1200: oblig. furnizor
  -- 1201: oblig. client
  G.MONEDA = PKG_REG.GetMonedaReg AND
  NP.DEN_PART IS NOT NULL AND
  NVL(N.Sablon, 0) &lt;&gt; 1
UNION ALL
-- NC DIN OBLIGPIF
SELECT
  O.CODOBLIGPIF, G.CodGeneral, O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  &apos;NC&apos; AS PrefixDoc, N.NrDoc, N.DataDoc,
  O.CodPart, NP.Den_Part,
  O.Semnificatie,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Rest,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Valoare,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * PKG_REG.GetCursReg) AS ValoareReg,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN NC1 N1 ON N1.CODNC1 = G.CODDOC
  LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  O.SEMNIFICATIE IN (1200, 1201) AND
  -- 1200: oblig. furnizor
  -- 1201: oblig. client
  G.MONEDA = PKG_REG.GetMonedaReg AND
	N1.Luna = PKG_GLOBALS.GETLUNALUCRU AND N1.An = PKG_GLOBALS.GETANLUCRU AND
  NP.DEN_PART IS NOT NULL AND
  NVL(N.Sablon, 0) &lt;&gt; 1
UNION ALL
-- STINGERI	PRIN TREZOR
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  &apos;NC&apos;, N_STINS.NrDoc, N_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN NC1 N1_STINS ON N1_STINS.CODNC1 = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINS ON T1_STINS.CODTREZOR1 = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINGATOR ON T1_STINGATOR.CODTREZOR1 = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NC N_STINS ON N_STINS.CODNC = N1_STINS.CODNC
	LEFT OUTER JOIN TREZOR T_STINS ON T_STINS.CODTREZOR = T1_STINS.CODTREZOR
	LEFT OUTER JOIN TREZOR T_STINGATOR ON T_STINGATOR.CODTREZOR = T1_STINGATOR.CODTREZOR
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (1200, 1201) AND
  O_STINGATOR.SEMNIFICATIE IN (300, 400) AND
	-- 300
	-- 400
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
	((NVL(T_STINS.OPERAT, 0) = 1 AND NVL(T1_STINS.ANULAT, 0) = 0) OR NVL(T1_STINS.INITIALIZARI, 0) = 1) AND
	NVL(T_STINGATOR.OPERAT, 0) = 1 AND NVL(T1_STINGATOR.ANULAT, 0) = 0 AND
	T1_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND T1_STINGATOR.An = PKG_GLOBALS.GETANLUCRU
UNION ALL
-- STINGERI PRIN COMPENSARI
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  &apos;NC&apos;, N_STINS.NrDoc, N_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN NC1 N1_STINS ON N1_STINS.CODNC1 = G_STINS.CODDOC
	LEFT OUTER JOIN COMPENS C_STINGATOR ON C_STINGATOR.CODCOMPENS = G_STINGATOR.CODDOC
  LEFT OUTER JOIN NC N_STINS ON N_STINS.CODNC = N1_STINS.CODNC
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (1200, 1201) AND
  O_STINGATOR.SEMNIFICATIE IN (1300, 1350) AND
	-- 1300, 1350 COMPENS
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
	C_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND C_STINGATOR.An = PKG_GLOBALS.GETANLUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGPART_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D788B2E61075AD32D60F8AC3687AAA514ACBFFE4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGPART_TREZOR (
&quot;CODOBLIGPIF&quot;,&quot;CODGENERAL&quot;,&quot;ICONT&quot;,&quot;SIMBOLCONT&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;SEMNIFICATIE&quot;,&quot;REST&quot;,&quot;VALOARE&quot;,&quot;VALOAREREG&quot;,&quot;VALOAREDOC&quot;,&quot;CODGEST&quot;,&quot;CURS&quot;) AS
SELECT
  OL.CODOBLIGPIF,	G.CodGeneral,	O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  T1.Doc, T1.NrDoc, T1.DataDoc,
  O.CodPart, NP.Den_Part,
  O.Semnificatie,
  NVL(OL.Rest, 0) AS Rest,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0))
		ELSE (NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1)))
	END) AS Valoare,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * PKG_REG.GetCursReg)
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O.Valoare, 0) = 0 THEN (NVL(OL.Rest, 0) * NVL(GREG.CURS, G.CURS))
	  ELSE ((NVL(OL.Rest, 0) - (NVL(OL.REST, 0) * NVL(G.TVA, 0) / NVL(O.VALOARE, 1))) * NVL(GREG.CURS, G.CURS))
	END) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIFLUNA OL
  LEFT OUTER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
  LEFT OUTER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  TO_DATE(&apos;01.&apos; || TO_CHAR(OL.LUNA) || &apos;.&apos; || TO_CHAR(OL.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
  O.SEMNIFICATIE IN (310, 410, 330, 430) AND
  -- 310: plati in avans trezor
  -- 410: incasari in avans trezor
	-- 330: plata avans retur client
	-- 430: incasare in avans retur furn.
  G.MONEDA = PKG_REG.GetMonedaReg
UNION ALL
-- TREZOR DIN OBLIGPIF
SELECT
  O.CODOBLIGPIF, G.CodGeneral, O.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.Semnificatie, O.ICont, IOP.CodIOPart1)) AS SimbolCont,
  T1.Doc, T1.NrDoc, T1.DataDoc,
  O.CodPart, NP.Den_Part, O.Semnificatie,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Rest,
  (NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) AS Valoare,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * PKG_REG.GetCursReg) AS ValoareReg,
  ((NVL(O.VALOARE, 0) - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)) AS ValoareDoc,
	NVL(O.CodGest, 0) AS CodGest,
	NVL(GREG.CURS, G.CURS) AS Curs
FROM
  OBLIGPIF O
  LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CodGeneral = G.CodGeneral
	LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
  LEFT OUTER JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
  LEFT OUTER JOIN NPART NP ON NP.CodPart = O.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP ON IOP.CodPart = O.CodPart
WHERE
  O.SEMNIFICATIE IN (310, 410, 330, 430) AND
  -- 310: plati in avans trezor
  -- 410: incasari in avans trezor
	-- 330: plata avans retur client
	-- 430: incasare in avans retur furn.
  G.MONEDA = PKG_REG.GetMonedaReg AND
  NVL(T.OPERAT, 0) = 1 AND NVL(T1.ANULAT, 0) = 0 AND
	T1.Luna = PKG_GLOBALS.GETLUNALUCRU AND T1.An = PKG_GLOBALS.GETANLUCRU AND
  NVL(T1.INITIALIZARI, 0) &lt;&gt; 1
UNION ALL
-- STINGERI PRIN TREZOR
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  T1_STINS.Doc, T1_STINS.NrDoc, T1_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1_STINS ON T1_STINS.CODTREZOR1 = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINGATOR ON T1_STINGATOR.CODTREZOR1 = G_STINGATOR.CODDOC
  LEFT OUTER JOIN TREZOR T_STINS ON T_STINS.CODTREZOR = T1_STINS.CODTREZOR
	LEFT OUTER JOIN TREZOR T_STINGATOR ON T_STINGATOR.CODTREZOR = T1_STINGATOR.CODTREZOR
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (310, 410, 330, 430) AND
  O_STINGATOR.SEMNIFICATIE IN (320, 420) AND
  -- 320 stinge 310, 500, 330
  -- 420 stinge 410, 600, 430
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
  ((NVL(T_STINS.OPERAT, 0) = 1 AND NVL(T1_STINS.ANULAT, 0) = 0) OR NVL(T1_STINS.INITIALIZARI, 0) = 1) AND
	NVL(T_STINGATOR.OPERAT, 0) = 1 AND NVL(T1_STINGATOR.ANULAT, 0) = 0 AND
	T1_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND T1_STINGATOR.An = PKG_GLOBALS.GETANLUCRU
UNION ALL
-- STINGERI PRIN COMPENS
SELECT
  O_STINS.CODOBLIGPIF, G_STINS.CodGeneral, O_STINS.ICont,
	PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O_STINS.Semnificatie, O_STINS.ICont, IOP_STINS.CodIOPart1)) AS SimbolCont,
  T1_STINS.Doc, T1_STINS.NrDoc, T1_STINS.DataDoc,
  O_STINS.CodPart, NP_STINS.Den_Part,
  O_STINS.Semnificatie,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Rest,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -(NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
		ELSE (NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0))
	END) AS Valoare,
	(CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * PKG_REG.GetCursReg)
	END) AS ValoareReg,
  (CASE
	  WHEN NVL(O_STINS.VALOARE, 0) &gt; 0 THEN -((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
		ELSE ((NVL(O_STINGATOR.VALOARE, 0) - NVL(G_STINGATOR.TVA, 0)) * NVL(GREG_STINS.CURS, G_STINS.CURS))
	END) AS ValoareDoc,
	NVL(O_STINS.CodGest, 0) AS CodGest,
	NVL(GREG_STINS.CURS, G_STINS.CURS) AS Curs
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL G_STINS ON G_STINS.CODGENERAL = O_STINS.CODGENERAL
	LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG_STINS ON GREG_STINS.CodGeneral = G_STINS.CodGeneral
	LEFT OUTER JOIN GENERAL G_STINGATOR ON G_STINGATOR.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN TREZOR1 T1_STINS ON T1_STINS.CODTREZOR1 = G_STINS.CODDOC
	LEFT OUTER JOIN TREZOR1 T1_STINGATOR ON T1_STINGATOR.CODTREZOR1 = G_STINGATOR.CODDOC
	LEFT OUTER JOIN COMPENS C_STINGATOR ON C_STINGATOR.CODCOMPENS = G_STINGATOR.CODDOC
  LEFT OUTER JOIN TREZOR T_STINS ON T_STINS.CODTREZOR = T1_STINS.CODTREZOR
	LEFT OUTER JOIN TREZOR T_STINGATOR ON T_STINGATOR.CODTREZOR = T1_STINGATOR.CODTREZOR
  LEFT OUTER JOIN NPART NP_STINS ON NP_STINS.CodPart = O_STINS.CodPart
	LEFT OUTER JOIN TMP_IOPARTLUNA IOP_STINS ON IOP_STINS.CodPart = O_STINS.CodPart
WHERE
  O_STINS.SEMNIFICATIE IN (310, 410, 330, 430) AND
  O_STINGATOR.SEMNIFICATIE IN (1300, 1350) AND
	-- 1300, 1350 COMPENS
  G_STINS.MONEDA = PKG_REG.GetMonedaReg AND
	G_STINGATOR.MONEDA = PKG_REG.GetMonedaReg AND
	((NVL(T_STINS.OPERAT, 0) = 1 AND NVL(T1_STINS.ANULAT, 0) = 0) OR NVL(T1_STINS.INITIALIZARI, 0) = 1) AND
	NVL(T_STINGATOR.OPERAT, 0) = 1 AND NVL(T1_STINGATOR.ANULAT, 0) = 0 AND
	C_STINGATOR.Luna = PKG_GLOBALS.GETLUNALUCRU AND C_STINGATOR.An = PKG_GLOBALS.GETANLUCRU 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REGTREZOR_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A20091B7E602842CF06642768A93D30B6F391095</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REGTREZOR_TREZOR (
&quot;CODTREZOR1&quot;,&quot;VALOARE&quot;,&quot;VALOAREDOC&quot;,&quot;VALOAREREG&quot;) AS
SELECT
    CodTrezor1,
    SUM(Valoare) AS Valoare,
    SUM(ValoareDoc) AS ValoareDoc,
    SUM(ValoareReg) AS ValoareReg
  FROM
  (
    -- TREZOR DIN INITIALIZARI
    SELECT
      T1.CODTREZOR1,
      NVL(T1.VALDOC, 0) AS Valoare,
      NVL(T1.VALDOC, 0) * PKG_REG.GetCursReg AS ValoareReg,
      NVL(T1.VALDOC, 0) * PKG_REG.GetTrezorCurs(T1.CODTREZOR1, T.SUBUNITATEA, BC.CODMONEDA, NVL(T1.CURS, 0)) AS ValoareDoc
    FROM
      NBANKCONT BC
      LEFT OUTER JOIN NBANKCONT1 BC1 ON BC1.CODBANKCONT = BC.CODBANKCONT
      LEFT OUTER JOIN TREZOR T ON T.CODBANCA = BC.CODBANKCONT
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      --LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK
    WHERE
      TO_DATE(&apos;01.&apos; || TO_CHAR(BC1.LUNASTART) || &apos;.&apos; || TO_CHAR(BC1.ANSTART), &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) AND
      BC.CODMONEDA = PKG_REG.GetMonedaReg AND
      NVL(T.OPERAT, 0) = 1 AND
      NVL(T1.ANULAT, 0) = 0 AND
      T1.DATADOC &lt;= PKG_REG.GetDataReg AND
      TO_DATE(&apos;01.&apos; || TO_CHAR(T1.LUNA) || &apos;.&apos; || TO_CHAR(T1.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
      -- ((T.SUBUNITATEA = PKG_REG.GetSubunitReg AND PKG_REG.GetSubunitReg &gt; 1) OR (PKG_REG.GetSubunitReg = 1)) AND
      NVL(T1.INITIALIZARI, 0) = 1
    UNION ALL
    -- TREZOR DIN... TREZOR
    SELECT
      T1.CODTREZOR1,
      NVL(T1.VALDOC, 0) AS Valoare,
      NVL(T1.VALDOC, 0) * PKG_REG.GetCursReg AS ValoareReg,
      NVL(T1.VALDOC, 0) * PKG_REG.GetTrezorCurs(T1.CODTREZOR1, T.SUBUNITATEA, BC.CODMONEDA, NVL(T1.CURS, 0)) AS ValoareDoc
    FROM
      NBANKCONT BC
      LEFT OUTER JOIN NBANKCONT1 BC1 ON BC1.CODBANKCONT = BC.CODBANKCONT
      LEFT OUTER JOIN TREZOR T ON T.CODBANCA = BC.CODBANKCONT
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
      --LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK
    WHERE
      TO_DATE(&apos;01.&apos; || TO_CHAR(BC1.LUNASTART) || &apos;.&apos; || TO_CHAR(BC1.ANSTART), &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) AND
      BC.CODMONEDA = PKG_REG.GetMonedaReg AND
      NVL(T.OPERAT, 0) = 1 AND
      NVL(T1.ANULAT, 0) = 0 AND
      T1.DATADOC &lt;= PKG_REG.GetDataReg AND
      TO_DATE(&apos;01.&apos; || TO_CHAR(T1.LUNA) || &apos;.&apos; || TO_CHAR(T1.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) AND
      -- ((T.SUBUNITATEA = PKG_REG.GetSubunitReg AND PKG_REG.GetSubunitReg &gt; 1) OR (PKG_REG.GetSubunitReg = 1)) AND
      NVL(T1.INITIALIZARI, 0) &lt;&gt; 1
    UNION ALL
    -- TREZOR DIN NBANKSOLDLUNA
    SELECT
      T1.CODTREZOR1,
      NVL(BSL.SoldValuta, 0) AS Valoare,
      NVL(BSL.SoldValuta, 0) * PKG_REG.GetCursReg AS ValoareReg,
      NVL(BSL.SoldLei, 0) AS ValoareDoc
    FROM
      NBANKSOLDLUNA BSL
      LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = BSL.CODBANKCONT
      LEFT OUTER JOIN NBANKCONT1 BC1 ON BC1.CODBANKCONT = BC.CODBANKCONT
      --LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK
      LEFT OUTER JOIN TREZOR T ON T.CODBANCA = BC.CODBANKCONT
      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
    WHERE
      TO_DATE(&apos;01.&apos; || TO_CHAR(BC1.LUNASTART) || &apos;.&apos; || TO_CHAR(BC1.ANSTART), &apos;DD.MM.YYYY&apos;) &lt;= TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) AND
      BC.CODMONEDA = PKG_REG.GetMonedaReg AND
      NVL(T.OPERAT, 0) = 1 AND
      NVL(T1.ANULAT, 0) = 0 AND
      T1.DATADOC &lt;= PKG_REG.GetDataReg AND
      TO_DATE(&apos;01.&apos; || TO_CHAR(T1.LUNA) || &apos;.&apos; || TO_CHAR(T1.AN), &apos;DD.MM.YYYY&apos;) = TO_DATE(&apos;01.&apos; || TO_CHAR(PKG_GLOBALS.GETLUNALUCRU) || &apos;.&apos; || TO_CHAR(PKG_GLOBALS.GETANLUCRU), &apos;DD.MM.YYYY&apos;) - INTERVAL &apos;1&apos; MONTH AND
      -- ((T.SUBUNITATEA = PKG_REG.GetSubunitReg AND PKG_REG.GetSubunitReg &gt; 1) OR (PKG_REG.GetSubunitReg = 1)) AND
      NVL(T1.INITIALIZARI, 0) &lt;&gt; 1
  )
  GROUP BY
    CodTrezor1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REST_OBLIGPIF_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>280BCD74A08BE5A30A4F6C7B4888E43AB2A7E1CF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REST_OBLIGPIF_PREC (
&quot;CODOBLIGPIF&quot;,&quot;REST&quot;,&quot;RESTTVA&quot;,&quot;RESTSPLITTVA&quot;) AS
SELECT CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA
FROM
  OBLIGPIFLUNA
WHERE
 AN = PKG_GLOBALS.GETANPRECEDENT
 AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
 AND NVL(REST, 0) + NVL(RESTTVA, 0) + NVL(RESTSPLITTVA, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_RULAREALERTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59CCCBC26C6ADAB663A9B3A4D18F030EE387A385</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_RULAREALERTE (
&quot;CODALERTA&quot;,&quot;CODRULARE&quot;,&quot;DATARUL&quot;) AS
select distinct ai.codalerta,ai.codrulare,to_char(ai.dataexec,&apos;dd.mm.yyyy hh24:mi&apos;) datarul
from
  alerte a left join alerte_info ai on a.codalerta = ai.codalerta
where a.codalerta = pkg_alerte.GetCodAlerta 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SABLONDESCRIPT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2880A8C1466A6BD52C6A8466E1AE8DD8132B964</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SABLONDESCRIPT (
&quot;CODSABLON&quot;,&quot;DEN_SABLON&quot;,&quot;SIMBOL&quot;,&quot;DEN_DESCRIPTOR&quot;,&quot;CODDESCRIPTOR&quot;,&quot;DENUMIRE&quot;) AS
SELECT S.CODSABLON,S.DENUMIRE DEN_SABLON, S.SIMBOL,D.DEN_DESCRIPTOR, D.CODDESCRIPTOR, S.DENUMIRE
 FROM SABLONDESCRIPT S INNER JOIN DESCRIPTORI D ON S.CODDESCRIPTOR = D.CODDESCRIPTOR

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SEMNIFICATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D8FD6195E9A4CCC41BA3D2653AA3B3436AEAC95B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SEMNIFICATII (
&quot;SEMNIFICATIE&quot;,&quot;SEMN&quot;,&quot;TVA&quot;,&quot;ICONT&quot;,&quot;SIMB&quot;,&quot;OBS&quot;) AS
WITH
  C AS ( -- (1200, 1201)
    SELECT
      LEVEL ICont,
      CASE
        WHEN LEVEL IN (2, 5, 6, 8, 9, 15, 16, 17, 20, 25, 26, 27, 28, 29)  THEN -1
        WHEN LEVEL IN (3, 4, 7,10, 11, 12, 13, 14, 19, 30, 31, 32, 33, 34) THEN 1
        ELSE 0
      END Semn
    FROM DUAL
    CONNECT BY LEVEL &lt;= 34
  ),
  N AS ( --(1301, 1351, 1303)
    SELECT
      LEVEL ICont,
      CASE
        WHEN LEVEL IN (2, 5, 8, 9, 15, 18)  THEN -1
        WHEN LEVEL IN (3, 4, 6, 7, 10, 11, 12, 13, 14, 17) THEN 1
        ELSE 0
      END Semn
    FROM DUAL
    CONNECT BY LEVEL &lt;= 18
  )
--intrari de la furnizori
          SELECT  100 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsObligFurn&apos;                   SIMB, &apos;{provenita din Intrari de bunuri si servicii}&apos;                                   OBS FROM DUAL
UNION ALL SELECT  110 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsAvansFurn&apos;                   SIMB, &apos;{provenita din linii de avans de pe Intrari}&apos;                                    OBS FROM DUAL
UNION ALL SELECT  111 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsStornoAvansFurn&apos;             SIMB, &apos;{provenita din linii de avans in rosu de pe Intrari}&apos;                            OBS FROM DUAL
UNION ALL SELECT  120 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsGarantieFurn&apos;                SIMB, NULL                                                                              OBS FROM DUAL
UNION ALL SELECT  121 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsStornoGarantieFurn&apos;          SIMB, NULL                                                                              OBS FROM DUAL
UNION ALL SELECT  130 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsObligVama&apos;                   SIMB, NULL                                                                              OBS FROM DUAL
UNION ALL SELECT  140 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsAvizeFurn&apos;                   SIMB, &apos;{provenita din Avize de Intrare}&apos;                                                OBS FROM DUAL
--iesiri catre clienti
UNION ALL SELECT  200 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsObligClient&apos;                 SIMB, &apos;{provenita din Iesiri de bunuri si servicii}&apos;                                    OBS FROM DUAL
UNION ALL SELECT  210 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsAvansClient&apos;                 SIMB, &apos;{provenita din linii de avans de pe Iesiri}&apos;                                     OBS FROM DUAL
UNION ALL SELECT  211 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsStornoAvansClient&apos;           SIMB, &apos;{provenita din linii de avans in rosu de pe Iesiri}&apos;                             OBS FROM DUAL
UNION ALL SELECT  220 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsGarantieClient&apos;              SIMB, NULL                                                                              OBS FROM DUAL
UNION ALL SELECT  221 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsStornoGarantieClient&apos;        SIMB, NULL                                                                              OBS FROM DUAL
UNION ALL SELECT  240 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsAvizeClient&apos;                 SIMB, &apos;{provenita din Avize de Iesire}&apos;                                                 OBS FROM DUAL
--tranzactii CASA BANCA *plati catre furnizori
UNION ALL SELECT  300 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsPlataFurn&apos;                   SIMB, &apos;{stinge 100 sau 500}&apos;                                                            OBS FROM DUAL
UNION ALL SELECT  310 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsPlataInAvansFurn&apos;            SIMB, &apos;{creaza Obligatie de incasat de stins}&apos;                                          OBS FROM DUAL
UNION ALL SELECT  320 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsReturFurnizor&apos;               SIMB, &apos;{stinge 100 in rosu , 310 iar pe Tranzactii in curs stinge 500}&apos;                 OBS FROM DUAL
UNION ALL SELECT  330 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsPlataInAvansReturClient&apos;     SIMB, &apos;{creaza Obligatie de incasat de stins}&apos;                                          OBS FROM DUAL
--tranzactii CASA BANCA *incasari de la clienti
UNION ALL SELECT  400 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsIncasareClient&apos;              SIMB, &apos;{stinge 200 sau 600}&apos;                                                            OBS FROM DUAL
UNION ALL SELECT  410 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsIncasareInAvansClient&apos;       SIMB, &apos;{creaza Obligatie de plata de stins}&apos;                                            OBS FROM DUAL
UNION ALL SELECT  420 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsReturClient&apos;                 SIMB, &apos;{stinge 200 in rosu, 410 iar pe Tranzactii in curs stinge 600}&apos;                  OBS FROM DUAL
UNION ALL SELECT  430 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsIncasareInAvansReturFurn&apos;    SIMB, &apos;{creaza Obligatie de incasat de stins}&apos;                                          OBS FROM DUAL
--tranzactii CASA BANCA *tranzactii in curs
UNION ALL SELECT  500 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsPlataInCurs&apos;                 SIMB, &apos;{ plata cu CEC ce urmeaza a fi stins}&apos;                                           OBS FROM DUAL
UNION ALL SELECT  600 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsIncasareInCurs&apos;              SIMB, &apos;{ incasare cu CEC ce urmeaza a fi stins}&apos;                                        OBS FROM DUAL
--tranzactii CASA BANCA *retururi de CEC
UNION ALL SELECT  700 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsReturCECFurn_Fact&apos;           SIMB, &apos;{linie ce reactiveaza in urma unui retur de cec furnizor factura stinsa de cec}&apos; OBS FROM DUAL
UNION ALL SELECT  701 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsReturCECFurn_AnulareAvans&apos;   SIMB, &apos;{linie ce anuleaza in urma unui retur de cec furnizor avansul generat de cec}&apos;   OBS FROM DUAL
UNION ALL SELECT  750 SEMNIFICATIE, -1 Semn, 0 TVA, 0 ICont, &apos;tsReturCECClient_Fact&apos;         SIMB, &apos;{linie ce reactiveaza in urma unui retur de cec client factura stinsa de cec}&apos;   OBS FROM DUAL
UNION ALL SELECT  751 SEMNIFICATIE,  1 Semn, 0 TVA, 0 ICont, &apos;tsReturCECClient_AnulareAvans&apos; SIMB, &apos;{linie ce anuleaza in urma unui retur de cec client avansul generat de cec}&apos;     OBS FROM DUAL
--tranzactii CASA BANCA *viramente
UNION ALL SELECT  800 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsPlataVirament&apos;               SIMB, &apos;{plata Virament ce stinge sau urmeaza a fi stins}&apos;                               OBS FROM DUAL
UNION ALL SELECT  801 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsIncasareVirament&apos;            SIMB, &apos;{incasare Virament ce stinge sau urmeaza a fi stins}&apos;                            OBS FROM DUAL
--tranzactii CASA BANCA *Pe Cont; Obiecttranz = 4
UNION ALL SELECT  900 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsDirectPeCheltuieli&apos;          SIMB, &apos;{*Direct pe cheltuieli(TVA)}&apos;                                                    OBS FROM DUAL
UNION ALL SELECT  901 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsDirectPeVenituri&apos;            SIMB, &apos;{*Direct pe venituri(TVA)}&apos;                                                      OBS FROM DUAL
--tranzactii CASA BANCA *Pe Chelt;ObiectTranz = 5
UNION ALL SELECT  950 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsDatoriiTaxeImpozite&apos;         SIMB, &apos;{Datorii, taxe, impoz}&apos;                                                          OBS FROM DUAL
UNION ALL SELECT  951 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsImprumuturiSubventii&apos;        SIMB, &apos;{imprumuturi, subventii}&apos;                                                        OBS FROM DUAL
UNION ALL SELECT 1000 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsDobanda&apos;                     SIMB, &apos;{Dobanzi; Obiecttranz = 6}&apos;                                                      OBS FROM DUAL
UNION ALL SELECT 1100 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsPlataAngajat&apos;                SIMB, &apos;{Plata personal angajat}&apos;                                                        OBS FROM DUAL
UNION ALL SELECT 1101 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsIncasareAngajat&apos;             SIMB, &apos;{Incasare personal angajat}&apos;                                                     OBS FROM DUAL
--Note contabile
UNION ALL SELECT 1200 SEMNIFICATIE,  C.Semn, 0 TVA, C.ICont, &apos;tsNotaContabilaDebit&apos;          SIMB, &apos;{provenita din note contabile Debit}&apos;                                            OBS FROM C WHERE C.SEMN &lt;&gt; 0
UNION ALL SELECT 1201 SEMNIFICATIE,  C.Semn, 0 TVA, C.ICont, &apos;tsNotaContabilaCredit&apos;         SIMB, &apos;{provenita din note contabile Credit}&apos;                                           OBS FROM C WHERE C.SEMN &lt;&gt; 0
UNION ALL SELECT 1250 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsNotaContabilaAjustareDebit&apos;  SIMB, &apos;{provenita din note contabile Debit}&apos;                                            OBS FROM DUAL
UNION ALL SELECT 1251 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsNotaContabilaAjustareCredit&apos; SIMB, &apos;{provenita din note contabile Credit}&apos;                                           OBS FROM DUAL
--Compensari
UNION ALL SELECT 1300 SEMNIFICATIE,  1 Semn, 1 TVA, 0 ICont, &apos;tsCompensDebit&apos;                SIMB, &apos;{provenita din compensari Debit, partener}&apos;                                      OBS FROM DUAL
UNION ALL SELECT 1301 SEMNIFICATIE,  N.Semn, 0 TVA, N.ICont, &apos;tsCompensDebitFaraLeg&apos;         SIMB, &apos;{provenita din compensari Debit, partener, fara leg}&apos;                            OBS FROM N WHERE N.SEMN &lt;&gt; 0
UNION ALL SELECT 1302 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsCompensDebitPeCont&apos;          SIMB, &apos;{provenita din compensari Debit, direct pe cont}&apos;                                OBS FROM DUAL
UNION ALL SELECT 1303 SEMNIFICATIE,  N.Semn, 0 TVA, N.ICont, &apos;tsCompensDebitLitigii&apos;         SIMB, &apos;{provenita din compensari Debit, litigii}&apos;                                       OBS FROM N WHERE N.SEMN &lt;&gt; 0
UNION ALL SELECT 1350 SEMNIFICATIE, -1 Semn, 1 TVA, 0 ICont, &apos;tsCompensCredit&apos;               SIMB, &apos;{provenita din compensari Credit, partener}&apos;                                     OBS FROM DUAL
UNION ALL SELECT 1351 SEMNIFICATIE,  N.Semn, 0 TVA, N.ICont, &apos;tsCompensCreditFaraLeg&apos;        SIMB, &apos;{provenita din compensari Credit, partener, fara leg}&apos;                           OBS FROM N WHERE N.SEMN &lt;&gt; 0
UNION ALL SELECT 1352 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsCompensCreditPeCont&apos;         SIMB, &apos;{provenita din compensari Credit, direct pe cont}&apos;                               OBS FROM DUAL
UNION ALL SELECT 1353 SEMNIFICATIE,  0 Semn, 0 TVA, 0 ICont, &apos;tsCompensCreditLitigii&apos;        SIMB, &apos;{provenita din compensari Credit, litigii}&apos;                                      OBS FROM DUAL</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SERII_OBIECT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA8591E15DF687936ABE083A637BCFF98CEB4D29</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SERII_OBIECT (
&quot;CODSERIE&quot;,&quot;SERIE&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;) AS
SELECT DISTINCT S.CODSERIE, S.SERIE, S.CODOBIECT, S.OBS
FROM NSERII S
     INNER JOIN NIRSER SER ON SER.CODSERIE = S.CODSERIE
WHERE S.CODOBIECT = PKG_SERII.GETOBIECTCURENT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SERII_OBIECT_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A0234F255F236D9E4AAFF0163CEA9FA622182CB7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SERII_OBIECT_STOC (
&quot;CODSERIE&quot;,&quot;SERIE&quot;,&quot;CODOBIECT&quot;,&quot;OBS&quot;) AS
SELECT DISTINCT S.CODSERIE, S.SERIE, S.CODOBIECT, S.OBS
FROM NSERII S
     INNER JOIN NIRSER SER ON SER.CODSERIE = S.CODSERIE
WHERE S.CODOBIECT = PKG_SERII.GETOBIECTCURENT AND SER.REST &gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SERTARCEC_CLIENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2387AD014B1E8ED753020660B540CA9B08E92155</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SERTARCEC_CLIENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATE&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
    S1.CODOBLIGPIF,
    &apos;SERTAR&apos; AS DOC,
    S.NRDOC,
    S.DATADOC,
    S1.VALOARE,
    S1.VALOARE AS REST,
    O.TERMEN,
    0 AS PRELUAT,
    O.REST AS RAMAS,
    0 AS CODSTINGATOR,
    O.SEMNIFICATIE AS SEMNIFCODSTINS,
    PKG_PLANCONTURI.GETSIMBOLCONT(PKG_GLOBALS.GET_CONT_CONTABIL_OBLIG(O.SEMNIFICATIE, O.ICONT, PKG_NOMPART.GET_PART_COD_CARACT_LUNA(O.CODPART, PKG_GLOBALS.GETANLUCRU, PKG_GLOBALS.GETLUNALUCRU))) AS SIMBOLCONT,
    O.ICONT,
    G.MONEDA AS CODMONEDA,
    PKG_MONEDE.GET_SIMBOL_MONEDA(G.MONEDA) AS SIMBOLMONEDA,
    NVL(GREG.CURS, G.CURS) AS CURS,
    G.TVA,
    I.CODLOCATIE,
    A.OBS SEDIU,
    S.SUBUNITATE,
    SUB.DEN_SUBUNIT,
    G.PROCTVAAVANS
FROM
 NSERTAR S,
 NSERTAR1 S1,
 OBLIGPIF O,
 GENERAL G
 LEFT JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
 LEFT JOIN IESIRI I ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
 LEFT JOIN NAGENDA A ON A.CODAGENDA = I.CODLOCATIE,
 NSUBUNIT SUB
WHERE
  S.CODSERTAR = S1.CODSERTAR
  AND S.DEPUS = 0
  AND S.TIP =1
  AND O.CODOBLIGPIF = S1.CODOBLIGPIF
  AND O.CODGENERAL  = G.CODGENERAL
  AND SUB.CODSUBUNIT = S.SUBUNITATE
  AND O.CODPART = PKG_NOMPART.GET_PART_CURENT
  AND PKG_MONEDE.MONEDA_VALIDA(G.MONEDA) = 1
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SETOC_WEBSERVER_IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>12D8FF5B87E3C261FB78AC21711F7D24947CF216</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SETOC_WEBSERVER_IOART (
&quot;CODOBIECT&quot;,&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;FURN&quot;,&quot;STOC&quot;,&quot;REZERVAT&quot;) AS
SELECT
  CODOBIECT,
  GEST,
  CODIOART,
  0 AS FURN,
  SUM(REST) AS STOC,
  SUM(NVL(REZERVAT, 0)) AS REZERVAT
FROM
(
SELECT
  NS.CODOBIECT,
  N.GEST,
  NS.CODIOART,
  REST,
  (SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC) REZERVAT
FROM
 NIRSTOC NS,
 NIR N
WHERE
 N.CODNIR = NS.CODNIR
)
GROUP BY CODOBIECT, GEST, CODIOART
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SITFIN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7B3EA3BD78F8F8CC7DF3F6A283DE7CA8A00F8EF1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SITFIN (
&quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;,&quot;CODDEN&quot;) AS
select &quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;, CodF||&apos; - &apos;||Denumire CodDen
    from SITFIN
where nvl(Tip,0) = 0

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SITFIN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>53DEA0A78A423301C79203136BC99752CA8CDE16</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SITFIN1 (
&quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;,&quot;CODDEN&quot;) AS
select &quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;, CodF||&apos; - &apos;||Denumire CodDen
from SITFIN
where nvl(Tip,0) = 1

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SITFIN_COLOANE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C8CC29C5FF62A8E3B43EE327D859A0BBB3270882</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SITFIN_COLOANE (
&quot;CODCOLOANA&quot;,&quot;CODSITFIN&quot;,&quot;NRCOL&quot;,&quot;DENUMIRE&quot;,&quot;TIPCOL&quot;,&quot;CORELATIE&quot;,&quot;IDENTIFICATORCOL&quot;,&quot;IDDEN&quot;) AS
select CODCOLOANA,CODSITFIN,NRCOL,DENUMIRE,TIPCOL,CORELATIE,to_number(IDENTIFICATORCOL) identificatorcol, IDENTIFICATORCOL||&apos; - &apos;||DENUMIRE IdDen
    from sitfincol
    where codsitfin = pkg_list_base_sitfin.getcod and tipcol not in (1, 2)
    order by IDENTIFICATORCOL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SITFIN_LINII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7A28449637BF9FB31250524C9319F2466B98F121</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SITFIN_LINII (
&quot;CODLINIE&quot;,&quot;CODSITFIN&quot;,&quot;NRLINIE&quot;,&quot;DENUMIRE&quot;,&quot;TOTAL&quot;,&quot;CORELATIE&quot;,&quot;RND&quot;,&quot;RNDDEN&quot;) AS
select CODLINIE,CODSITFIN,NRLINIE,DENUMIRE,TOTAL,CORELATIE,RND, Rnd||&apos; - &apos;||Denumire RndDen
    from Sitfinlin
    where CodSitFin = PKG_LIST_BASE_SITFIN.GetCod
    order by Rnd 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDBANKLUNAPREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>23764C05102E012526B1464C9212439009B87C01</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDBANKLUNAPREC (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA AS SOLDVALUTA
FROM 
  NBANKSOLDLUNA 
WHERE 
AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA AND
CODBANKCONT = PKG_CONTURIBANCI.GETCONTBANCACURENT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDBANK_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>DA3A41F638691393141955CAC0B664AFF7CB92E4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDBANK_TRANZACTII (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM (
  -- START TRANZACTII CASA
  SELECT
    T.CODBANCA AS CODBANKCONT,
    SUM(
      CASE
        WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN -T1.VALDOC * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
        WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN  T1.VALDOC * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
        WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN -T1.VALDOC * T1.CURS * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
        WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN  T1.VALDOC * T1.CURS * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
      END
    )
    +
    SUM(
      CASE
        WHEN M.CODMONEDA = 0  THEN -NVL(T1.COMISION, 0) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
        WHEN M.CODMONEDA &lt;&gt; 0 THEN -NVL(T1.COMISION, 0) * T1.CURS * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
      END
    )
    AS SOLDLEI,
    SUM(
      CASE
        WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN 0
        WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN 0
        WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN -T1.VALDOC * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
        WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN  T1.VALDOC * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
      END
    )
    +
    SUM(
      CASE
        WHEN  M.CODMONEDA = 0  THEN 0
        WHEN  M.CODMONEDA &lt;&gt; 0 THEN -NVL(T1.COMISION, 0) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
      END
    )
    AS SOLDVALUTA
  FROM TREZOR T
    LEFT JOIN TREZOR1   T1 ON T1.CODTREZOR   = T.CODTREZOR
    LEFT JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
    LEFT JOIN NBANK     NB ON NB.CODBANK     = BC.CODBANK
    LEFT JOIN NMONEDE   M  ON M.CODMONEDA    = BC.CODMONEDA
  WHERE T.TIPDOC NOT IN (31, 33) AND T.OPERAT = 1 AND T1.ANULAT = 0 
    AND T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND T.CODBANCA = PKG_CONTURIBANCI.GETCONTBANCACURENT
  GROUP BY T.CODBANCA
  -- END TRANZACTII CASA
  UNION ALL
  -- START MONETARE
  SELECT M.CODBANKCONT, SUM(M.VALOARE * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)) AS SOLDLEI , 0 AS SOLDVALUTA
  FROM IESIRI I
    INNER JOIN MODURIPLATI M ON M.CODIES=I.CODIES
    INNER JOIN NBANKCONT BC ON BC.CODBANKCONT = M.CODBANKCONT
  WHERE I.ANULAT = 0 AND OPERAT = 1 AND I.TIPDOC = 16
    AND I.AN*12+I.LUNA = PKG_GLOBALS.GETANTEMP*12+PKG_GLOBALS.GETLUNATEMP
    AND M.CODBANKCONT = PKG_CONTURIBANCI.GETCONTBANCACURENT
  GROUP BY M.CODBANKCONT
  -- END MONETARE
)
GROUP BY CODBANKCONT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPARTPRECSUB_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0E633CA5B098099B6B71A9587A95CBEC0EF67BC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPARTPRECSUB_EXT (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
 CODPART,
 ICONT,
 CODMONEDA,
 SUBUNITATEA,
 SUM(SOLDLEI) AS SOLDLEI,
 SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
  SELECT
   CODPART,
   ICONT,
   CODMONEDA,
   SUBUNITATEA,
   CASE
     WHEN NVL(CODMONEDA, 0) = 0 THEN REST
     ELSE REST * CURS
   END AS SOLDLEI,
   CASE
     WHEN NVL(CODMONEDA, 0) &lt;&gt; 0 THEN REST
     ELSE 0
   END AS SOLDVALUTA
  FROM
  (
    SELECT
      O.CODPART,
      O.ICONT,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 130) THEN -OL.REST
        WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2 THEN -OL.REST
        WHEN O.SEMNIFICATIE = 110 THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 200 THEN OL.REST
        WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
        WHEN O.SEMNIFICATIE = 210 THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (310, 330) THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (2, 5, 6, 8, 9, 15, 17) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) THEN OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5, 8, 9, 15) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)  AND O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) THEN OL.REST
        ELSE OL.REST
      END AS REST,
      G.MONEDA AS CODMONEDA,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 110, 130, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I WHERE CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC)
        WHEN O.SEMNIFICATIE IN (200, 210, 240) THEN (SELECT SUBUNITATEA FROM IESIRI I WHERE CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC)

        WHEN O.SEMNIFICATIE IN (310, 330, 410, 430)
        THEN (SELECT SUBUNITATEA FROM TREZOR T, TREZOR1 T1 WHERE CODTREZOR1 = G.CODDOC AND T.CODTREZOR = T1.CODTREZOR)

        WHEN O.SEMNIFICATIE IN (1200, 1201)
        THEN (SELECT SUBUNITATEA FROM NC N, NC1 N1 WHERE CODNC1 = G.CODDOC AND N.CODNC = N1.CODNC)
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) THEN (SELECT SUBUNITATEA FROM COMPENS C WHERE CODCOMPENS = G.CODDOC)
      END  SUBUNITATEA,
      NVL(REG.CURS, G.CURS) AS CURS
    FROM
      OBLIGPIFLUNA OL,
      OBLIGPIF O,
      GENERAL G
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA REG ON REG.CODGENERAL = G.CODGENERAL
    WHERE
      OL.REST &lt;&gt; 0
      AND O.SEMNIFICATIE IN (100, 110, 130, 140, 200, 210, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      AND OL.AN = PKG_GLOBALS.GetANPRECEDENT
      AND OL.LUNA = PKG_GLOBALS.GetLUNAPRECEDENTA
      AND O.CODOBLIGPIF = OL.CODOBLIGPIF
      AND G.CODGENERAL = O.CODGENERAL
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
   )
 )
GROUP BY
 CODPART, ICONT, CODMONEDA, SUBUNITATEA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPARTPREC_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>45C703FD149C1BE7718A0EE834BF80FDF05893B9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPARTPREC_EXT (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
 CODPART,
 ICONT,
 CODMONEDA,
 SUM(SOLDLEI) AS SOLDLEI,
 SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
  SELECT
   CODPART,
   ICONT,
   CODMONEDA,
   CASE
     WHEN NVL(CODMONEDA, 0) = 0 THEN REST
     ELSE REST * CURS
   END AS SOLDLEI,
   CASE
     WHEN NVL(CODMONEDA, 0) &lt;&gt; 0 THEN REST
     ELSE 0
   END AS SOLDVALUTA
  FROM
  (
    SELECT
      O.CODPART,
      O.ICONT,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 130) THEN -OL.REST
        WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2 THEN -OL.REST
        WHEN O.SEMNIFICATIE = 110 THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 200 THEN OL.REST
        WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN OL.REST
        WHEN O.SEMNIFICATIE = 210 THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (310, 330) THEN OL.REST - NVL(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -(OL.REST - NVL(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (2, 5, 6, 8, 9, 15, 17) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1200, 1201) AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) THEN OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5, 8, 9, 15) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)  AND O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) THEN OL.REST
      END AS REST,
      G.MONEDA AS CODMONEDA,
      NVL(REG.CURS, G.CURS) AS CURS
    FROM
      OBLIGPIFLUNA OL,
      OBLIGPIF O,
      GENERAL G
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA REG ON REG.CODGENERAL = G.CODGENERAL
    WHERE
      OL.REST &lt;&gt; 0
      AND O.SEMNIFICATIE IN (100, 110, 130, 140, 200, 210, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      AND OL.AN = PKG_GLOBALS.GetANPRECEDENT
      AND OL.LUNA = PKG_GLOBALS.GetLUNAPRECEDENTA
      AND O.CODOBLIGPIF = OL.CODOBLIGPIF
      AND G.CODGENERAL = O.CODGENERAL
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
   )
 )
GROUP BY
 CODPART, ICONT, CODMONEDA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPARTSUB_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>664EACC54D296F000CC61668E7918EFA0AD4D776</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPARTSUB_EXT (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;,&quot;RESTTVALEI&quot;,&quot;RESTTVAVALUTA&quot;,&quot;SOLD_IFRS&quot;) AS
SELECT
  CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVAL) SOLDVALUTA, SUM(RTVALEI) RESTTVALEI, SUM(RTVAVAL) RESTTVAVALUTA,
  SUM(SOLD_IFRS) SOLD_IFRS
FROM (
  SELECT
    CODPART, ICONT, CODMONEDA, SUBUNITATEA,
    CASE WHEN CODMONEDA = 0 THEN REST ELSE REST * CURS END SOLDLEI,
    CASE WHEN CODMONEDA = 0 THEN 0 ELSE REST END SOLDVAL,
    CASE WHEN CODMONEDA = 0 THEN RTVA ELSE RTVA * CURS END RTVALEI,
    CASE WHEN CODMONEDA = 0 THEN 0 ELSE RTVA END RTVAVAL,
    CASE WHEN CODMONEDA &lt;&gt; 0 THEN REST * DIF_CURS ELSE 0 END SOLD_IFRS
  FROM (
    SELECT
      O.CODPART, O.ICONT, Coalesce(G.MONEDA,0) AS CODMONEDA, COALESCE(REG.CURS,G.CURS,1) AS CURS,
      CASE WHEN Coalesce(REG.CURS_IFRS, 0) &lt;&gt; 0 THEN REG.CURS_IFRS - REG.CURS ELSE 0 END AS DIF_CURS,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 110, 120, 140) THEN (SELECT SUBUNITATEA FROM INTRARI I                                                     WHERE CODINTR       = G.CODDOC AND I.TIPDOC = G.TIPDOC)
        WHEN O.SEMNIFICATIE IN (130)                THEN (SELECT SUBUNITATEA FROM DVI     D  INNER JOIN INTRARI I ON I.CODINTR = D.CODINTR      WHERE D.CODDVI      = G.CODDOC AND G.TIPDOC = 5)
        WHEN O.SEMNIFICATIE IN (200, 210, 220, 240) THEN (SELECT SUBUNITATEA FROM IESIRI  I                                                     WHERE I.CODIES      = G.CODDOC AND I.TIPDOC = G.TIPDOC)
        WHEN O.SEMNIFICATIE IN (310, 330, 410, 430) THEN (SELECT SUBUNITATEA FROM TREZOR1 T1 INNER JOIN TREZOR  T ON T.CODTREZOR = T1.CODTREZOR WHERE T1.CODTREZOR1 = G.CODDOC)
        WHEN O.SEMNIFICATIE IN (1200, 1201)         THEN (SELECT SUBUNITATEA FROM NC1     N1 INNER JOIN NC      N ON N.CODNC = N1.CODNC         WHERE N1.CODNC1     = G.CODDOC)
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303)   THEN (SELECT SUBUNITATEA FROM COMPENS C                                                     WHERE C.CODCOMPENS  = G.CODDOC)
      END AS SUBUNITATEA,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 130)           THEN - OL.REST
        WHEN O.SEMNIFICATIE = 110                   THEN   OL.REST - Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120                   THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2  THEN - OL.REST
        WHEN O.SEMNIFICATIE = 200                   THEN   OL.REST
        WHEN O.SEMNIFICATIE = 210                   THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 220                   THEN  (OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN   OL.REST
        WHEN O.SEMNIFICATIE IN (310, 330)           THEN   OL.REST - Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430)           THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (2, 5, 6, 8, 9,15,16,17,   20,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5,    8, 9,15,16,   18,20,      25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (3, 4,    7,10,11,12,13,14,   18,19,23,24,30,31,32,33,34) THEN OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3, 4, 6, 7,10,11,12,13,14,17,   19,      30,31,32,33,34) THEN OL.REST
        ELSE 0
      END AS REST,
      CASE
        WHEN O.SEMNIFICATIE = 110         THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120         THEN -Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 210         THEN -Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 220         THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (310, 330) THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -Coalesce(OL.RESTTVA, 0)
        ELSE 0
      END AS RTVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN (
        SELECT
          R1.CODGENERAL,
          Max(R.CURS)      KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS,
          Max(R.CURS_IFRS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS_IFRS
        FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
        WHERE R.TIPREG = 46 AND R.AN * 12 + R.LUNA &lt;= PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP
        GROUP BY R1.CODGENERAL
      ) REG ON REG.CODGENERAL = G.CODGENERAL
    WHERE OL.AN = PKG_GLOBALS.GetANTEMP AND OL.LUNA = PKG_GLOBALS.GetLUNATEMP AND OL.REST &lt;&gt; 0 /*IDX_OBLIGPIFLUNA_ALR*/
      AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
   )
 )
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPARTSUB_IFRS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8F0CE3E4B95B66D1FBAAD5187DE247913174216C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPARTSUB_IFRS (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLD_IFRS&quot;) AS
SELECT
  CODPART,
  ICONT,
  SUBUNITATEA,
  SUM(SOLD_IFRS)AS SOLD_IFRS
FROM
(
-- sold precedent
SELECT
  CODPART,
  ICONT,
  SUBUNITATEA,
  SUM(SOLD_IFRS)AS SOLD_IFRS
FROM
  NPARTSOLDLUNASUB
WHERE
  AN       = PKG_GLOBALS.GetANPRECEDENT
  AND LUNA = PKG_GLOBALS.GetLUNAPRECEDENTA
  AND CODMONEDA = 0
  AND NVL(SOLD_IFRS, 0) &lt;&gt; 0
GROUP BY
 CODPART, ICONT, SUBUNITATEA

UNION ALL
-- ajustari luna curenta
SELECT
  CODPART,
  ICONT,
  SUBUNITATEA,
  SUM(SOLDLEI) AS SOLD_IFRS
 FROM
(
SELECT
  O.CODPART,
  ICONT,
  N.SUBUNITATEA,
  CASE
     WHEN O.SEMNIFICATIE IN (1250, 1251) AND O.ICONT IN (2, 5, 6, 8, 9, 15, 17) THEN -O.VALOARE
     WHEN O.SEMNIFICATIE IN (1250, 1251) AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) THEN O.VALOARE
  END AS SOLDLEI
FROM
  OBLIGPIF O,
  GENERAL G,
  NC1 N1,
  NC N
WHERE
  O.SEMNIFICATIE IN (1250, 1251)
  AND G.CODGENERAL = O.CODGENERAL
  AND N1.CODNC1 = G.CODDOC
  AND N.CODNC = N1.CODNC
  AND G.MONEDA = 0
  AND N.AN = PKG_GLOBALS.GetANTEMP
  AND N.LUNA = PKG_GLOBALS.GetLUNATEMP
 )
GROUP BY CODPART, ICONT, SUBUNITATEA
)
GROUP BY CODPART, ICONT, SUBUNITATEA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_CODSOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6BDFCF1003CE4F9396DB438848BF19D2AF9E2F3F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_CODSOLDPART (
&quot;CODSOLDPART&quot;) AS
SELECT CodSoldPart FROM SOLDPART ORDER BY CodSoldPart 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_DE_STINS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>601846E56BD30A0AFA67D7B43A10AE086814CE6A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_DE_STINS (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
  FROM (
    SELECT -- INTRARI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0 THEN  -O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN -O.VALOARE * Coalesce(GREG.CURS, G.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
      END AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS, R1.CONT
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL AND GREG.CONT = O.ICONT
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE ((O.SEMNIFICATIE = 100) OR (O.SEMNIFICATIE = 140)AND(I.TIPDOC = 2))
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT --FACTURI LA AVIZE FURNIZORI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN  0
        WHEN G.MONEDA = 0                  THEN  I1.PU * I1.CANT + Coalesce(I1STINS.TVA,0) * I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
        WHEN G.MONEDA &lt;&gt; 0                 THEN (I1.PU * I1.CANT + Coalesce(I1STINS.TVA,0) * I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)) * Coalesce(GREG.CURS, GSTINS.CURS)
      END AS SOLDLEI,
      CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
        WHEN G.MONEDA = 0                  THEN 0
        WHEN G.MONEDA &lt;&gt; 0                 THEN I1.PU * I1.CANT + Coalesce(I1STINS.TVA,0) * I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
      END AS SOLDVALUTA
    FROM OBLIGPIF O         
      LEFT JOIN GENERAL  G       ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN INTRARI  I       ON I.CODINTR = G.CODDOC
      LEFT JOIN INTRARI1 I1      ON I1.CODINTR = I.CODINTR
      LEFT JOIN INTRLINK IL      ON IL.CODINTR1 = I1.CODINTR1
      LEFT JOIN INTRARI1 I1STINS ON I1STINS.CODINTR1 = IL.CODLINIEAVIZ
      LEFT JOIN INTRARI  ISTINS  ON ISTINS.CODINTR = I1STINS.CODINTR
      LEFT JOIN GENERAL  GSTINS  ON GSTINS.CODDOC = ISTINS.CODINTR AND GSTINS.TIPDOC = ISTINS.TIPDOC
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
    WHERE O.SEMNIFICATIE IN (140) AND I.TIPDOC = 9
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT --DVI LA AVIZE FURNIZORI
      CODPART, ICONT, CODMONEDA,
      -VALOARE * Coalesce(GREG.CURS, GSTINS.CURS) AS SOLDLEI,
      -VALOARE AS SOLDVALUTA
    FROM (
      SELECT
        O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, O.VALOARE,
        ( SELECT I1STINS.CODINTR FROM INTRARI1 I1, INTRLINK IL, INTRARI1 I1STINS WHERE I1.CODINTR = I.CODINTR AND IL.CODINTR1 = I1.CODINTR1 AND I1STINS.CODINTR1 = IL.CODLINIEAVIZ AND ROWNUM = 1 ) AS CODAVIZ
      FROM OBLIGPIF O, GENERAL G, INTRARI I
    WHERE O.SEMNIFICATIE = 140
      AND O.CODGENERAL = G.CODGENERAL
      AND G.TIPDOC = 5
      AND I.CODINTR = G.CODDOC
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    ) DVIAVIZ,
    GENERAL GSTINS
    LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
    WHERE DVIAVIZ.CODAVIZ = GSTINS.CODDOC
      AND GSTINS.TIPDOC = 2
    UNION ALL
    SELECT -- AVANSURI PE FACTURA INTRARI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0  THEN  O.VALOARE - Coalesce(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 THEN (O.VALOARE - Coalesce(G.TVA, 0)) * Coalesce(GREG.CURS, G.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0  THEN 0
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE - Coalesce(G.TVA, 0)
      END AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN(
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE O.SEMNIFICATIE IN (110)
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- obligatii de stins provenite din DVI -uri
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0 THEN  -O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN  -O.VALOARE * Coalesce(GREG.CURS, G.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN(
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE O.SEMNIFICATIE IN (130) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- obligatii de stins provenite din IESIRI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0 THEN  O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE * Coalesce(GREG.CURS, G.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE (O.SEMNIFICATIE = 200 OR  (O.SEMNIFICATIE= 240 AND I.TIPDOC = 20))
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)AND (Coalesce(I.INFOCM, 0) = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT --FACTURI LA AVIZE CLIENTI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
        ELSE -(I1.PU * I1.CANT * ((100 + Coalesce(I1.PROCDISC, 0))/100) + Coalesce(I1STINS.TVA , 0) * (I1.PU * I1.CANT * ((100 + Coalesce(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT) ) )
      END *
      CASE 
        WHEN G.MONEDA &lt;&gt; 0 THEN Coalesce(GREG.CURS, GSTINS.CURS)
        ELSE 1
      END AS SOLDLEI,
      CASE
        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
        WHEN G.MONEDA = 0 THEN  0
        ELSE -(I1.PU * I1.CANT * ((100 + Coalesce(I1.PROCDISC, 0))/100) + Coalesce(I1STINS.TVA , 0) * (I1.PU * I1.CANT * ((100 + Coalesce(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT) ) )
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
      LEFT JOIN IESIRI1 I1 ON  I1.CODIES = I.CODIES
      LEFT JOIN IESLINK IL ON  IL.CODIES1 = I1.CODIES1
      LEFT JOIN IESIRI1  I1STINS ON  I1STINS.CODIES1 = IL.CODLINIEAVIZ
      LEFT JOIN IESIRI   ISTINS ON  ISTINS.CODIES = I1STINS.CODIES
      LEFT JOIN GENERAL GSTINS   ON  GSTINS.CODDOC = ISTINS.CODIES AND GSTINS.TIPDOC = ISTINS.TIPDOC
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
    WHERE O.SEMNIFICATIE IN (240) AND I.TIPDOC = 26
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- AVANSURI PE FACTURA IESIRI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      -(O.VALOARE - Coalesce(G.TVA, 0)) * CASE WHEN G.MONEDA &lt;&gt; 0 THEN Coalesce(GREG.CURS, G.CURS) ELSE 1 END AS SOLDLEI,
      -(O.VALOARE - Coalesce(G.TVA, 0)) * CASE WHEN G.MONEDA &lt;&gt; 0 THEN 1                           ELSE 0 END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN IESIRI I ON  I.CODIES = G.CODDOC
    WHERE O.SEMNIFICATIE IN (210) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0  AND G.SEMNIFICATIE IN (310, 330) THEN   O.VALOARE - Coalesce(G.TVA, 0)
        WHEN G.MONEDA = 0  AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - Coalesce(G.TVA, 0))
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (310, 330) THEN  (O.VALOARE - Coalesce(G.TVA, 0)) * Coalesce(GREG.CURS, G.CURS)
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - Coalesce(G.TVA, 0)) * Coalesce(GREG.CURS, G.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (310, 330) THEN   O.VALOARE - Coalesce(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - Coalesce(G.TVA, 0))
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE ((T1.INITIALIZARI = 1)OR(Coalesce(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))
      AND G.TIPDOC IN (29, 30, 31, 33)
      AND T1.AN = PKG_GLOBALS.GETANTEMP AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND G.SEMNIFICATIE IN (310, 410, 330, 430)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- obligatii de stins provenite din NOTE CONTABILE
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17)          AND G.MONEDA  = 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14, 18) AND G.MONEDA  = 0 THEN  O.VALOARE
        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17)          AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE * Coalesce(GREG.CURS, G.CURS)
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14, 18) AND G.MONEDA &lt;&gt; 0 THEN  O.VALOARE * Coalesce(GREG.CURS, G.CURS)
        ELSE 0
      END AS SOLDLEI,
      CASE
        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17)          AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14, 18) AND G.MONEDA &lt;&gt; 0 THEN  O.VALOARE
        ELSE 0
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G ON G.CODGENERAL  = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
    WHERE O.SEMNIFICATIE IN (1200, 1201)
      AND N1.AN = PKG_GLOBALS.GETANTEMP AND N1.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
    UNION ALL
    SELECT -- obligatii de stins provenite din COMPENSARI
      O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN O.ICONT IN (2, 5, 8, 9, 15)                 AND G.MONEDA  = 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA  = 0 THEN  O.VALOARE
        WHEN O.ICONT IN (2, 5, 8, 9, 15)                 AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE * Coalesce(GREG.CURS, G.CURS)
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0 THEN  O.VALOARE * Coalesce(GREG.CURS, G.CURS)
        ELSE 0
      END AS SOLDLEI,
      CASE
        WHEN O.ICONT IN (2, 5, 8, 9, 15)                 AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0 THEN  O.VALOARE
        ELSE 0
      END AS SOLDVALUTA
    FROM OBLIGPIF O
      LEFT JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN (
        SELECT R1.CODGENERAL, R.CURS
        FROM REG R INNER JOIN REG1 R1 ON R.CODREG  = R1.CODREG
        WHERE R.TIPREG = 46 AND R.AN = PKG_GLOBALS.GETANTEMP AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
      ) GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
    WHERE O.SEMNIFICATIE IN (1301, 1303, 1351)
      AND C.AN = PKG_GLOBALS.GETANTEMP AND C.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
 )
GROUP BY CODPART, ICONT, CODMONEDA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_DE_STINS_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CDD4AAA3FCBF506758CE7A9C4F9411B4A19966D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_DE_STINS_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
 FROM
   (
    -- INTRARI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN  -O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN  -O.VALOARE * NVL(GREG.CURS, G.CURS)

      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL
/*

      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/

      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
     ((O.SEMNIFICATIE = 100) OR (O.SEMNIFICATIE = 140)AND(I.TIPDOC = 2))
     AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)
     AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

    UNION ALL
   --FACTURI LA AVIZE FURNIZORI
    SELECT O.CODPART,
          O.ICONT,
          G.MONEDA AS CODMONEDA,
          I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN   (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
                                 --  I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                    ( CASE
                                        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                        ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                      END
                                     )
                                   )
        WHEN G.MONEDA &lt;&gt; 0 THEN   (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
--                                   I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                    ( CASE
                                        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                        ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                      END
                                     )

                                  )
                                  * NVL(GREG.CURS, GSTINS.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN  (I1.PU * I1.CANT + NVL(I1STINS.TVA , 0) *
--                                 I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                    ( CASE
                                        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                        ELSE I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                      END
                                     )
                                 )
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
      LEFT OUTER JOIN INTRARI1 I1 ON  I1.CODINTR = I.CODINTR
      LEFT OUTER JOIN INTRLINK IL ON  IL.CODINTR1 = I1.CODINTR1
      LEFT OUTER JOIN INTRARI1  I1STINS ON  I1STINS.CODINTR1 = IL.CODLINIEAVIZ
      LEFT OUTER JOIN INTRARI   ISTINS ON  ISTINS.CODINTR = I1STINS.CODINTR
      LEFT OUTER JOIN GENERAL GSTINS   ON  GSTINS.CODDOC = ISTINS.CODINTR AND GSTINS.TIPDOC = ISTINS.TIPDOC

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL


/*
      LEFT OUTER JOIN GENERAL GSTINS   ON  GSTINS.CODDOC = ISTINS.CODINTR AND GSTINS.TIPDOC = ISTINS.TIPDOC
       LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GSTINS.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/


    WHERE
     O.SEMNIFICATIE IN (140) AND I.TIPDOC = 9
     AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)


   UNION ALL

   --DVI LA AVIZE FURNIZORI
  SELECT
    CODPART,
    ICONT,
    CODMONEDA,
    (SELECT SUBUNITATEA FROM INTRARI WHERE CODINTR = GSTINS.CODDOC) AS SUBUNITATEA,
    -VALOARE * NVL(GREG.CURS, GSTINS.CURS) AS SOLDLEI,
    -VALOARE AS SOLDVALUTA
   FROM
  (
  SELECT
   O.CODPART,
   O.ICONT,
   G.MONEDA AS CODMONEDA,
   O.VALOARE,
  (
   SELECT
    I1STINS.CODINTR
   FROM
     INTRARI1 I1,
     INTRLINK IL,
     INTRARI1 I1STINS
   WHERE
    I1.CODINTR = I.CODINTR
    AND IL.CODINTR1 = I1.CODINTR1
    AND I1STINS.CODINTR1 = IL.CODLINIEAVIZ
    AND ROWNUM = 1
   ) AS CODAVIZ
  FROM
   OBLIGPIF O,
   GENERAL G,
   INTRARI I
  WHERE
   O.SEMNIFICATIE = 140
   AND O.CODGENERAL = G.CODGENERAL
   AND G.TIPDOC = 5
   AND I.CODINTR = G.CODDOC
   AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
   AND (I.OPERAT = 1)AND(I.ANULAT = 0)
  ) DVIAVIZ,
    GENERAL GSTINS
    LEFT OUTER JOIN
    (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
     WHERE
       R.CODREG  = R1.CODREG
       AND R.AN   = PKG_GLOBALS.GETANTEMP
       AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND R.TIPREG = 46
     ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL
  WHERE
    DVIAVIZ.CODAVIZ = GSTINS.CODDOC
    AND GSTINS.TIPDOC = 2

   UNION ALL



    -- AVANSURI PE FACTURA INTRARI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN   O.VALOARE - NVL(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 THEN (O.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE - NVL(G.TVA, 0)
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
/*
       LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL


       LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
    WHERE
     O.SEMNIFICATIE IN (110) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)
     AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

   UNION ALL

-- obligatii de stins provenite din DVI -uri
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN  -O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN  -O.VALOARE * NVL(GREG.CURS, G.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/
      LEFT OUTER JOIN DVI D      ON G.CODDOC     = D.CODDVI
      LEFT OUTER JOIN INTRARI I  ON I.CODINTR    = D.CODINTR
    WHERE
     O.SEMNIFICATIE IN (130) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)
     AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1


    UNION ALL

   -- obligatii de stins provenite din IESIRI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN  O.VALOARE
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE * NVL(GREG.CURS, G.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN O.VALOARE
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/

      LEFT OUTER JOIN IESIRI I   ON  I.CODIES = G.CODDOC
    WHERE
     (O.SEMNIFICATIE = 200 OR  (O.SEMNIFICATIE= 240 AND I.TIPDOC = 20))
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)AND (NVL(I.INFOCM, 0) = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

    UNION ALL

   --FACTURI LA AVIZE CLIENTI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN   - (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
                                   --I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                    ( CASE
                                        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                        ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
                                      END
                                     )
                                   )
        WHEN G.MONEDA &lt;&gt; 0 THEN  - (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
                                   --I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                      ( CASE
                                          WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                          ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
                                        END
                                       )
                                   ) * NVL(GREG.CURS, GSTINS.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN - (I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) + NVL(I1STINS.TVA , 0) *
--                                   I1.PU * I1.CANT /( I1STINS.PU * I1STINS.CANT)
                                    ( CASE
                                        WHEN I1STINS.PU * I1STINS.CANT = 0 THEN 0
                                        ELSE I1.PU * I1.CANT * ((100 + NVL(I1.PROCDISC, 0)) / 100) /( I1STINS.PU * I1STINS.CANT)
                                      END
                                     )
                                   )
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN IESIRI I ON  I.CODIES = G.CODDOC
      LEFT OUTER JOIN IESIRI1 I1 ON  I1.CODIES = I.CODIES
      LEFT OUTER JOIN IESLINK IL ON  IL.CODIES1 = I1.CODIES1
      LEFT OUTER JOIN IESIRI1  I1STINS ON  I1STINS.CODIES1 = IL.CODLINIEAVIZ
      LEFT OUTER JOIN IESIRI   ISTINS ON  ISTINS.CODIES = I1STINS.CODIES
      LEFT OUTER JOIN GENERAL GSTINS   ON  GSTINS.CODDOC = ISTINS.CODIES AND GSTINS.TIPDOC = ISTINS.TIPDOC


      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = GSTINS.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GSTINS.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/
    WHERE
      O.SEMNIFICATIE IN (240) AND I.TIPDOC = 26
      AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1)AND(I.ANULAT = 0)

    UNION ALL

 -- AVANSURI PE FACTURA IESIRI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0 THEN  -(O.VALOARE - NVL(G.TVA, 0))
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O.VALOARE - NVL(G.TVA, 0))
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/

      LEFT OUTER JOIN IESIRI I ON  I.CODIES = G.CODDOC
    WHERE
     O.SEMNIFICATIE IN (210) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
     AND (I.OPERAT = 1)AND(I.ANULAT = 0)
     AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

   UNION ALL
   -- obligatii de stins provenite din tranzactii CASA/BANCA (plati in avans = 310, incasari in avans = 410)
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, T.SUBUNITATEA,
    ( CASE
        WHEN G.MONEDA = 0  AND G.SEMNIFICATIE IN (310, 330) THEN   O.VALOARE - NVL(G.TVA, 0)
        WHEN G.MONEDA = 0  AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - NVL(G.TVA, 0))
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (310, 330) THEN  (O.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, G.CURS)
      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (310, 330) THEN   O.VALOARE - NVL(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 AND G.SEMNIFICATIE IN (410, 430) THEN -(O.VALOARE - NVL(G.TVA, 0))
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/

      LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
      LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
    WHERE
     ((T1.INITIALIZARI = 1)OR(NVL(T1.INITIALIZARI, 0) &lt;&gt; 1 AND T.OPERAT = 1))AND
      G.TIPDOC IN (29, 30, 31, 33) AND
      T1.AN = PKG_GLOBALS.GETANTEMP AND
      T1.LUNA = PKG_GLOBALS.GETLUNATEMP AND
      G.SEMNIFICATIE IN (310, 410, 330, 430)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

    UNION ALL

   -- obligatii de stins provenite din NOTE CONTABILE
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, N.SUBUNITATEA,
    ( CASE
        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17) AND G.MONEDA = 0  THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) AND G.MONEDA = 0  THEN  O.VALOARE

        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17) AND G.MONEDA &lt;&gt; 0  THEN -O.VALOARE * NVL(GREG.CURS, G.CURS)
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0  THEN  O.VALOARE * NVL(GREG.CURS, G.CURS)

      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN O.ICONT IN (2, 5, 6, 8, 9, 15, 17) AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0 THEN O.VALOARE
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL


/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/
       LEFT OUTER JOIN NC1 N1   ON  N1.CODNC1 = G.CODDOC
       LEFT OUTER JOIN NC N ON N.CODNC = N1.CODNC
    WHERE
      O.SEMNIFICATIE IN (1200, 1201)  AND N1.AN = PKG_GLOBALS.GETANTEMP AND N1.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

    UNION ALL

   -- obligatii de stins provenite din COMPENSARI
    SELECT O.CODPART, O.ICONT, G.MONEDA AS CODMONEDA, C.SUBUNITATEA,
    ( CASE
        WHEN O.ICONT IN (2, 5, 8, 9, 15) AND G.MONEDA = 0  THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA = 0  THEN  O.VALOARE

        WHEN O.ICONT IN (2, 5, 8, 9, 15) AND G.MONEDA &lt;&gt; 0  THEN -O.VALOARE * NVL(GREG.CURS, G.CURS)
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0  THEN  O.VALOARE * NVL(GREG.CURS, G.CURS)

      END
    )AS SOLDLEI,
    ( CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN O.ICONT IN (2, 5, 8, 9, 15) AND G.MONEDA &lt;&gt; 0 THEN -O.VALOARE
        WHEN O.ICONT IN (3, 4, 6, 7, 10, 11, 12, 13, 14) AND G.MONEDA &lt;&gt; 0 THEN O.VALOARE
      END
    )AS SOLDVALUTA
    FROM
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL = O.CODGENERAL

      LEFT OUTER JOIN
      (SELECT CODGENERAL, R.CURS FROM REG1 R1, REG R
       WHERE
         R.CODREG  = R1.CODREG
         AND R.AN   = PKG_GLOBALS.GETANTEMP
         AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
         AND R.TIPREG = 46
       ) GREG ON GREG.CODGENERAL = G.CODGENERAL

/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = G.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/
      LEFT OUTER JOIN COMPENS C  ON C.CODCOMPENS = G.CODDOC
    WHERE
      O.SEMNIFICATIE IN (1301, 1351, 1303) AND C.AN = PKG_GLOBALS.GETANTEMP AND C.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1

 )
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_EXT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>83C78D948ADADF98257A2D89B48B5F52CE4D33A5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_EXT (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;,&quot;RESTTVALEI&quot;,&quot;RESTTVAVALUTA&quot;,&quot;SOLD_IFRS&quot;) AS
SELECT
  CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) SOLDLEI, SUM(SOLDVAL) SOLDVALUTA, SUM(RTVALEI) RESTTVALEI, SUM(RTVAVAL) RESTTVAVALUTA ,
  SUM(SOLD_IFRS) SOLD_IFRS
FROM (
  SELECT
    CODPART, ICONT, CODMONEDA,
    CASE WHEN CODMONEDA = 0 THEN REST ELSE REST * CURS END SOLDLEI,
    CASE WHEN CODMONEDA = 0 THEN 0 ELSE REST END SOLDVAL,
    CASE WHEN CODMONEDA = 0 THEN RTVA ELSE RTVA * CURS END RTVALEI,
    CASE WHEN CODMONEDA = 0 THEN 0 ELSE RTVA END RTVAVAL,
    CASE WHEN CODMONEDA &lt;&gt; 0 THEN REST * DIF_CURS ELSE 0 END SOLD_IFRS
  FROM (
    SELECT
      O.CODPART, O.ICONT, Nvl(G.MONEDA,0) CODMONEDA, COALESCE(REG.CURS,G.CURS,1) CURS,
      CASE WHEN Coalesce(REG.CURS_IFRS, 0) &lt;&gt; 0 THEN REG.CURS_IFRS - REG.CURS ELSE 0 END AS DIF_CURS,
      CASE
        WHEN O.SEMNIFICATIE IN (100, 130)           THEN - OL.REST
        WHEN O.SEMNIFICATIE = 110                   THEN   OL.REST - Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120                   THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 140 AND G.TIPDOC = 2  THEN - OL.REST
        WHEN O.SEMNIFICATIE = 200                   THEN   OL.REST
        WHEN O.SEMNIFICATIE = 210                   THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 220                   THEN  (OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE = 240 AND G.TIPDOC = 20 THEN   OL.REST
        WHEN O.SEMNIFICATIE IN (310, 330)           THEN   OL.REST - Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430)           THEN -(OL.REST - Coalesce(OL.RESTTVA, 0))
        WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (2, 5, 6, 8, 9,15,16,17,   20,21,22,25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (2, 5,    8, 9,15,16,   18,20,      25,26,27,28,29,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59) THEN -OL.REST
        WHEN O.SEMNIFICATIE IN (1200, 1201)       AND O.ICONT IN (3, 4,    7,10,11,12,13,14,   18,19,23,24,30,31,32,33,34) THEN OL.REST
        WHEN O.SEMNIFICATIE IN (1301, 1351, 1303) AND O.ICONT IN (3, 4, 6, 7,10,11,12,13,14,17,   19,      30,31,32,33,34) THEN OL.REST
        ELSE 0
      END AS REST,
      CASE
        WHEN O.SEMNIFICATIE = 110         THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 120         THEN -Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 210         THEN -Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE = 220         THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (310, 330) THEN  Coalesce(OL.RESTTVA, 0)
        WHEN O.SEMNIFICATIE IN (410, 430) THEN -Coalesce(OL.RESTTVA, 0)
        ELSE 0
      END AS RTVA
    FROM OBLIGPIFLUNA OL
      INNER JOIN OBLIGPIF O ON O.CODOBLIGPIF = OL.CODOBLIGPIF
      INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
      LEFT JOIN (
        SELECT
          R1.CODGENERAL,
          Max(R.CURS)      KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS,
          Max(R.CURS_IFRS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS_IFRS
        FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
        WHERE R.TIPREG = 46 AND R.AN * 12 + R.LUNA &lt;= PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP
        GROUP BY R1.CODGENERAL
      ) REG ON REG.CODGENERAL = G.CODGENERAL
    WHERE OL.AN = PKG_GLOBALS.GetANTEMP AND OL.LUNA = PKG_GLOBALS.GetLUNATEMP AND OL.REST &lt;&gt; 0  /*IDX_OBLIGPIFLUNA_ALR*/
      AND O.SEMNIFICATIE IN (100, 110, 120, 130, 140, 200, 210, 220, 240, 310, 330, 410, 430, 1200, 1201, 1301, 1351, 1303)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O.CODPART) = 1
  )
)
GROUP BY CODPART, ICONT, CODMONEDA</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_IFRS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4C97CD0F6008DEB87F2FEFBFE96DDF41811E037B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_IFRS (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;SOLD_IFRS&quot;) AS
SELECT
  CODPART,
  ICONT,
  SUM(SOLD_IFRS)AS SOLD_IFRS
FROM
(
-- sold precedent
SELECT
  CODPART,
  ICONT,
  SUM(SOLD_IFRS)AS SOLD_IFRS
FROM
  NPARTSOLDLUNA
WHERE
  AN       = PKG_GLOBALS.GetANPRECEDENT
  AND LUNA = PKG_GLOBALS.GetLUNAPRECEDENTA
  AND CODMONEDA = 0
  AND NVL(SOLD_IFRS, 0) &lt;&gt; 0
GROUP BY
 CODPART, ICONT

UNION ALL
-- ajustari luna curenta
SELECT
  CODPART,
  ICONT,
  SUM(SOLDLEI) AS SOLD_IFRS
 FROM
(
SELECT
  O.CODPART,
  ICONT,
  CASE
     WHEN O.SEMNIFICATIE IN (1250, 1251) AND O.ICONT IN (2, 5, 6, 8, 9, 15, 17) THEN -O.VALOARE
     WHEN O.SEMNIFICATIE IN (1250, 1251) AND O.ICONT IN (3, 4, 7,10, 11, 12, 13, 14) THEN O.VALOARE
  END AS SOLDLEI
FROM
  OBLIGPIF O,
  GENERAL G,
  NC1 N1,
  NC N
WHERE
  O.SEMNIFICATIE IN (1250, 1251)
  AND G.CODGENERAL = O.CODGENERAL
  AND N1.CODNC1 = G.CODDOC
  AND N.CODNC = N1.CODNC
  AND G.MONEDA = 0
  AND N.AN = PKG_GLOBALS.GetANTEMP
  AND N.LUNA = PKG_GLOBALS.GetLUNATEMP
 )
GROUP BY CODPART, ICONT
)
GROUP BY CODPART, ICONT

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>54C0B6215D278234EFCA2F12D46474855EDEDD28</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_PREC (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
  P.CODPART,
  P.ICONT,
  P.CODMONEDA,
  CASE
    WHEN R.CURS IS NULL THEN P.SOLDLEI
    ELSE P.SOLDVALUTA * R.CURS
  END AS SOLDLEI,
  P.SOLDVALUTA
FROM
  NPARTSOLDLUNA P
  LEFT OUTER JOIN REG R ON R.CODMONEDA = P.CODMONEDA
  AND R.AN   = PKG_GLOBALS.GETANTEMP
  AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND R.TIPREG = 46
WHERE
  P.AN = PKG_GLOBALS.GETANPRECEDENT AND P.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(P.CODPART) = 1

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_PREC_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CD039F73BA7DB2F5F6DB4053570EA6EA0222565F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_PREC_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT
  P.CODPART,
  P.ICONT,
  P.CODMONEDA,
  P.SUBUNITATEA,
  CASE
    WHEN R.CURS IS NULL THEN P.SOLDLEI
    ELSE P.SOLDVALUTA * R.CURS
  END AS SOLDLEI,
  P.SOLDVALUTA
FROM
  NPARTSOLDLUNASUB P
  LEFT OUTER JOIN REG R ON R.CODMONEDA = P.CODMONEDA
  AND R.AN   = PKG_GLOBALS.GETANTEMP
  AND R.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND R.TIPREG = 46
WHERE
  P.AN = PKG_GLOBALS.GETANPRECEDENT AND P.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(P.CODPART) = 1

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI_COMPENS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CC33D4DBD5D32A62A7B5B76447810A9D70C90886</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI_COMPENS (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
-- stingeri prin compensari
SELECT
 O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA,
 (
   CASE
     -- STINGERE obligatii plata furn +  STINGERE AVANS CLIENT
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  NVL(GREG.CURS, GEN.CURS)
     WHEN O_STINS.SEMNIFICATIE  IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN  S.VALOARE - NVL(G.TVA, 0)
     WHEN O_STINS.SEMNIFICATIE  IN( 410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)


     -- STINGERE AVANS furn  + STINGERE obligatii incasare client
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -S.VALOARE
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  NVL(GREG.CURS, GEN.CURS)
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -(S.VALOARE - NVL(G.TVA, 0))
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))  *  NVL(GREG.CURS, GEN.CURS)
   END
 ) AS SOLDLEI,
 (
   CASE
     -- STINGERE obligatii plata furn + STINGERE AVANS CLIENT
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - NVL(G.TVA, 0)

     -- STINGERE AVANS furn + STINGERE obligatii incasare client
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))
   END
 ) AS SOLDVALUTA
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN COMPENS CO ON CO.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
  LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
  LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
  AND GREG.AN   = PKG_GLOBALS.GETANTEMP
  AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND GREG.TIPREG = 46
*/
WHERE
  G.TIPDOC = 28 AND CO.AN = PKG_GLOBALS.GETANTEMP AND CO.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINS.CODPART) = 1

)
GROUP BY CODPART, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI_COMP_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>56BAAA9993A9B97A93703903FE958D5674336E1C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI_COMP_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
-- stingeri prin compensari
SELECT
 O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA, CO.SUBUNITATEA,
 (
   CASE
     -- STINGERE obligatii plata furn +  STINGERE AVANS CLIENT
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  NVL(GREG.CURS, GEN.CURS)
     WHEN O_STINS.SEMNIFICATIE  IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN  S.VALOARE - NVL(G.TVA, 0)
     WHEN O_STINS.SEMNIFICATIE  IN( 410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)


     -- STINGERE AVANS furn  + STINGERE obligatii incasare client
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -S.VALOARE
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  NVL(GREG.CURS, GEN.CURS)
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN -(S.VALOARE - NVL(G.TVA, 0))
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))  *  NVL(GREG.CURS, GEN.CURS)
   END
 ) AS SOLDLEI,
 (
   CASE
     -- STINGERE obligatii plata furn + STINGERE AVANS CLIENT
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (410, 430) AND O_STINGATOR.SEMNIFICATIE IN (1300) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - NVL(G.TVA, 0)

     -- STINGERE AVANS furn + STINGERE obligatii incasare client
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 200, 1200, 1201, 1301, 1303)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (310, 330)) AND (O_STINGATOR.SEMNIFICATIE IN (1350)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))
   END
 ) AS SOLDVALUTA
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN COMPENS CO ON CO.CODCOMPENS = G.CODDOC
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
  LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
  LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
  AND GREG.AN   = PKG_GLOBALS.GETANTEMP
  AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND GREG.TIPREG = 46
*/
WHERE
  G.TIPDOC = 28 AND CO.AN = PKG_GLOBALS.GETANTEMP AND CO.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINS.CODPART) = 1

)
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C0A36118457B6A64C7F44710F9EF482C50B8F93E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI_TREZOR (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
-- stingeri prin tranzactii casa/banca
SELECT
 O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA,
 (
   CASE
     -- STINGERE obligatii plata furn
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE AVANS furn
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN -(S.VALOARE - NVL(G.TVA, 0))
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE obligatii incasare client
     WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN -S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE AVANS CLIENT
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN S.VALOARE  - NVL(G.TVA, 0)
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)
   END
 ) AS SOLDLEI,
 (
   CASE
     -- STINGERE obligatii plata furn
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE

     -- STINGERE AVANS furn
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))

     -- STINGERE obligatii incasare client
     WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE

     -- STINGERE AVANS CLIENT
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - NVL(G.TVA, 0)
   END
 ) AS SOLDVALUTA
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL  G  ON G.CODGENERAL   = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN TREZOR1  T1 ON T1.CODTREZOR1  = G.CODDOC
  LEFT OUTER JOIN TREZOR   T  ON T.CODTREZOR    = T1.CODTREZOR
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
  LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
  LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
  AND GREG.AN   = PKG_GLOBALS.GETANTEMP
  AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND GREG.TIPREG = 46
*/
WHERE
 T.OPERAT = 1 AND
 G.TIPDOC IN (29, 30, 31, 33) AND T1.AN = PKG_GLOBALS.GETANTEMP AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP AND O_STINS.SEMNIFICATIE NOT IN (500, 600, 800, 801)
 AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINS.CODPART) = 1
)
GROUP BY CODPART, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI_TREZ_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>530A66897A9D16B7E83DC5D56605D541BC9268D2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI_TREZ_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
-- stingeri prin tranzactii casa/banca
SELECT
 O_STINS.CODPART, O_STINS.ICONT, G.MONEDA AS CODMONEDA, T.SUBUNITATEA,
 (
   CASE
     -- STINGERE obligatii plata furn
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE AVANS furn
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN -(S.VALOARE - NVL(G.TVA, 0))
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE obligatii incasare client
     WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN -S.VALOARE
     WHEN O_STINS.SEMNIFICATIE  IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE *  NVL(GREG.CURS, GEN.CURS)

     -- STINGERE AVANS CLIENT
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN S.VALOARE  - NVL(G.TVA, 0)
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN (S.VALOARE - NVL(G.TVA, 0)) *  NVL(GREG.CURS, GEN.CURS)
   END
 ) AS SOLDLEI,
 (
   CASE
     -- STINGERE obligatii plata furn
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (100, 130, 1201, 1351) AND O_STINGATOR.SEMNIFICATIE IN (300, 700) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE

     -- STINGERE AVANS furn
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (100, 130, 310, 330, 1200, 1301)) AND (O_STINGATOR.SEMNIFICATIE IN (320, 701)) AND G.MONEDA &lt;&gt; 0 THEN -(S.VALOARE - NVL(G.TVA, 0))

     -- STINGERE obligatii incasare client
     WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA = 0  THEN 0
     WHEN O_STINS.SEMNIFICATIE IN (200, 1200, 1301, 1303) AND O_STINGATOR.SEMNIFICATIE IN (400, 750) AND G.MONEDA &lt;&gt; 0 THEN -S.VALOARE

     -- STINGERE AVANS CLIENT
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA = 0  THEN 0
     WHEN (O_STINS.SEMNIFICATIE IN (200, 410, 430, 1201, 1351)) AND (O_STINGATOR.SEMNIFICATIE IN (420, 751)) AND G.MONEDA &lt;&gt; 0 THEN S.VALOARE - NVL(G.TVA, 0)
   END
 ) AS SOLDVALUTA
FROM
  STINGERE S
  LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT OUTER JOIN GENERAL  G  ON G.CODGENERAL   = O_STINGATOR.CODGENERAL
  LEFT OUTER JOIN TREZOR1  T1 ON T1.CODTREZOR1  = G.CODDOC
  LEFT OUTER JOIN TREZOR   T  ON T.CODTREZOR    = T1.CODTREZOR
  LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
  LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
  LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
  LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
  AND GREG.AN   = PKG_GLOBALS.GETANTEMP
  AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND GREG.TIPREG = 46
*/
WHERE
  T.OPERAT = 1
  AND G.TIPDOC IN (29, 30, 31, 33)
  AND T1.AN = PKG_GLOBALS.GETANTEMP
  AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND O_STINS.SEMNIFICATIE NOT IN (500, 600, 800, 801)
  AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINS.CODPART) = 1
)
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_AVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F79F6579FDF5D0EE86872C4CE511C45266138B55</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_AVANS (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT O.CODPART AS CODPERS,
       O.ICONT AS ICONT,
       G.MONEDA AS CODMONEDA,
SUM(
  CASE 
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA = 0  THEN   O.REST
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA = 0  THEN  -O.REST
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA &lt;&gt; 0 THEN   O.REST * G.CURS
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA &lt;&gt; 0 THEN  -O.REST * G.CURS
  END 
) AS SOLDLEI, 
SUM(
  CASE 
    WHEN O.SEMNIFICATIE IN (1100, 1101) AND G.MONEDA = 0  THEN 0
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA &lt;&gt; 0  THEN  O.REST
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA &lt;&gt; 0  THEN -O.REST
  END 
) AS SOLDVALUTA
FROM
 OBLIGPIF O
 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
 
WHERE 
 O.SEMNIFICATIE IN (1100, 1101) AND
 T1.AN = PKG_GLOBALS.GETANTEMP  AND T1.LUNA = PKG_GLOBALS.GETLUNATEMP  AND
 O.CODPART = PKG_NOMPERS.GET_PERSOANA_CURENTA AND
 O.ICONT   = PKG_NOMPERS.GET_ICONTPERS_CURENT AND
 G.MONEDA = PKG_NOMPERS.GET_MONEDAPERS_CURENT
GROUP BY 
O.CODPART, O.ICONT, G.MONEDA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_JUSTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>105F2850889EB1178EF7A4A62688F2B1B8D16D2C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_JUSTIF (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT T.CODBANCA AS CODPERS,
       T.ICONTPERS AS ICONT,
       T.MONEDAPERS AS CODMONEDA,
SUM(
  CASE 
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS = 0  THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS = 0  THEN  T1.VALDOC
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS &lt;&gt; 0 THEN -T1.VALDOC * T1.CURS
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS &lt;&gt; 0 THEN  T1.VALDOC * T1.CURS
  END 
) AS SOLDLEI, 
SUM(
  CASE 
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS = 0  THEN 0
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS = 0  THEN 0
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS &lt;&gt; 0 THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS &lt;&gt; 0 THEN  T1.VALDOC
  END 
) AS SOLDVALUTA
FROM
 TREZOR T
 LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
WHERE 
 T.TIPDOC = 33 AND 
 T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP  AND
 T.CODBANCA = PKG_NOMPERS.GET_PERSOANA_CURENTA AND
 T.ICONTPERS = PKG_NOMPERS.GET_ICONTPERS_CURENT AND
 T.MONEDAPERS = PKG_NOMPERS.GET_MONEDAPERS_CURENT
GROUP BY 
T.CODBANCA, T.ICONTPERS, T.MONEDAPERS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_NC_CREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>706292D87A26D0D3E82C107650DF439D152A3049</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_NC_CREDIT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTC AS ICONT,
       NC.MONEDA AS CODMONEDA,
       SUM(
         CASE
           WHEN NC.MONEDA = 0  THEN NC1.VALOARE
           WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE * NC.CURS
         END
       ) AS SOLDLEI,
       SUM(
         CASE
           WHEN NC.MONEDA = 0  THEN 0
           WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE
         END
       ) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTC, 0) &lt;&gt; 0
  AND NVL(NC1.PERSC, 0)  &lt;&gt; 0
  AND NVL(NC1.AGENT, 0)  = PKG_NOMPERS.GET_PERSOANA_CURENTA
  AND NVL(NC1.ICONTC, 0) = PKG_NOMPERS.GET_ICONTPERS_CURENT
  AND NC.MONEDA          = PKG_NOMPERS.GET_MONEDAPERS_CURENT
GROUP BY
   NC1.AGENT,
   NC1.ICONTC,
   NC.MONEDA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_NC_DEBIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7BDF54DCC1162C1559928640C2E3BA6A09E17886</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_NC_DEBIT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTD AS ICONT,
       NC.MONEDA AS CODMONEDA,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN NC1.VALOARE
    WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE * NC.CURS
  END
) AS SOLDLEI,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN 0
    WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE
  END
) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTD, 0) &lt;&gt; 0
  AND NVL(NC1.PERSD, 0)  &lt;&gt; 0
  AND NVL(NC1.AGENT, 0)  = PKG_NOMPERS.GET_PERSOANA_CURENTA
  AND NVL(NC1.ICONTD, 0) = PKG_NOMPERS.GET_ICONTPERS_CURENT
  AND NC.MONEDA          = PKG_NOMPERS.GET_MONEDAPERS_CURENT
 GROUP BY
   NC1.AGENT,
   NC1.ICONTD,
   NC.MONEDA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C91E727C554274F4467DE126D9C360544F1FFD0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_PREC (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM 
  NPERSSOLDLUNA 
WHERE 
  AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA AND
  CODPERS   = PKG_NOMPERS.GET_PERSOANA_CURENTA AND
  ICONT     = PKG_NOMPERS.GET_ICONTPERS_CURENT AND
  CODMONEDA = PKG_NOMPERS.GET_MONEDAPERS_CURENT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_AVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1AB33A27D4467EA598DE90B08D4963E7B475A1F0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_AVANS (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT O.CODPART AS CODPERS,
       O.ICONT AS ICONT,
       G.MONEDA AS CODMONEDA,
SUM(
  CASE
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA = 0  THEN   O.REST
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA = 0  THEN  -O.REST
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA &lt;&gt; 0 THEN   O.REST * G.CURS
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA &lt;&gt; 0 THEN  -O.REST * G.CURS
  END
) AS SOLDLEI,
SUM(
  CASE
    WHEN O.SEMNIFICATIE = 1100 THEN  O.REST
    WHEN O.SEMNIFICATIE = 1101 THEN -O.REST
  END
) AS SOLDVALUTA
FROM
 OBLIGPIF O
 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
 LEFT OUTER JOIN TREZOR T ON T1.CODTREZOR = T.CODTREZOR
WHERE
 O.SEMNIFICATIE IN (1100, 1101) AND T1.ANULAT &lt;&gt; 1 AND T.OPERAT = 1 AND
 T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
O.CODPART, O.ICONT, G.MONEDA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_AVANS_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>359BBDDFE6DA456D496C9DEF001A7902AFFA2659</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_AVANS_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT O.CODPART AS CODPERS,
       O.ICONT AS ICONT,
       G.MONEDA AS CODMONEDA,
       T.SUBUNITATEA,
SUM(
  CASE
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA = 0  THEN   O.REST
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA = 0  THEN  -O.REST
    WHEN O.SEMNIFICATIE = 1100 AND G.MONEDA &lt;&gt; 0 THEN   O.REST * G.CURS
    WHEN O.SEMNIFICATIE = 1101 AND G.MONEDA &lt;&gt; 0 THEN  -O.REST * G.CURS
  END
) AS SOLDLEI,
SUM(
  CASE
    WHEN O.SEMNIFICATIE = 1100 THEN  O.REST
    WHEN O.SEMNIFICATIE = 1101 THEN -O.REST
  END
) AS SOLDVALUTA
FROM
 OBLIGPIF O
 LEFT OUTER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
 LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC
 LEFT OUTER JOIN TREZOR  T  ON T.CODTREZOR   = T1.CODTREZOR
WHERE
 O.SEMNIFICATIE IN (1100, 1101) AND T1.ANULAT &lt;&gt; 1 AND T.OPERAT = 1 AND
 T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
O.CODPART, O.ICONT, G.MONEDA, T.SUBUNITATEA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84C6220037BC099CABCFACCE6847F0456C15F6DC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_INI (
&quot;CODSOLDPERSINI&quot;,&quot;CODPERS&quot;,&quot;NUME&quot;,&quot;PRENUME&quot;,&quot;SOLDTOTAL&quot;) AS
SELECT  I.CODSOLDPERSINI, I.CODPERS, P.NUME, P.PRENUME, 
(SELECT SUM(SOLDLEI) 
 FROM  
   NPERSSOLDLUNA NS 
 WHERE 
   NS.CODPERS = I.CODPERS AND NS.AN = PKG_GLOBALS.GETANTEMP AND NS.LUNA = PKG_GLOBALS.GETLUNATEMP
 ) AS SOLDTOTAL
FROM
 SOLDPERSINI I
 LEFT OUTER JOIN NPERS P ON I.CODPERS = P.CODPERS 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_JUSTIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>A245CCEEE99B3048BB6C1FD6E4494257A7004B1F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_JUSTIF (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT T.CODBANCA AS CODPERS,
       T.ICONTPERS AS ICONT,
       T.MONEDAPERS AS CODMONEDA,
SUM(
  CASE
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS = 0  THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS = 0  THEN  T1.VALDOC
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS &lt;&gt; 0 THEN -T1.VALDOC * T1.CURS
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS &lt;&gt; 0 THEN  T1.VALDOC * T1.CURS
  END
) AS SOLDLEI,
SUM(
  CASE
    WHEN T1.TIPTRANZ = 0 THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 THEN  T1.VALDOC
  END
) AS SOLDVALUTA
FROM
  TREZOR T
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
WHERE
  T.TIPDOC = 33 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1 AND
  T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
  T.CODBANCA, T.ICONTPERS, T.MONEDAPERS
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_JUSTIF_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>016801E90245F91AF2FC4C6BA8715615DDB3DA33</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_JUSTIF_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT T.CODBANCA AS CODPERS,
       T.ICONTPERS AS ICONT,
       T.MONEDAPERS AS CODMONEDA,
       T.SUBUNITATEA,
SUM(
  CASE
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS = 0  THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS = 0  THEN  T1.VALDOC
    WHEN T1.TIPTRANZ = 0 AND T.MONEDAPERS &lt;&gt; 0 THEN -T1.VALDOC * T1.CURS
    WHEN T1.TIPTRANZ = 1 AND T.MONEDAPERS &lt;&gt; 0 THEN  T1.VALDOC * T1.CURS
  END
) AS SOLDLEI,
SUM(
  CASE
    WHEN T1.TIPTRANZ = 0 THEN -T1.VALDOC
    WHEN T1.TIPTRANZ = 1 THEN  T1.VALDOC
  END
) AS SOLDVALUTA
FROM
  TREZOR T
  LEFT OUTER JOIN TREZOR1 T1 ON T1.CODTREZOR = T.CODTREZOR
WHERE
  T.TIPDOC = 33 AND T.OPERAT = 1 AND T1.ANULAT &lt;&gt; 1 AND
  T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
GROUP BY
  T.CODBANCA, T.ICONTPERS, T.MONEDAPERS, T.SUBUNITATEA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_NC_CREDIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2184AB55276D01759C6ECC9BAA369E8CD87B6DA1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_NC_CREDIT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTC AS ICONT,
       NC.MONEDA AS CODMONEDA,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN -NC1.VALOARE
    WHEN NC.MONEDA &lt;&gt; 0  THEN -NC1.VALOARE * NC.CURS
  END
) AS SOLDLEI,
SUM(-NC1.VALOARE) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTC, 0) &lt;&gt; 0
  AND NVL(NC1.PERSC, 0)  &lt;&gt; 0
 GROUP BY
   NC1.AGENT,
   NC1.ICONTC,
   NC.MONEDA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_NC_CREDIT_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>676A65A037104AAC67C8462108AA1ED3C9710D8C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_NC_CREDIT_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTC AS ICONT,
       NC.MONEDA AS CODMONEDA,
       NC.SUBUNITATEA,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN -NC1.VALOARE
    WHEN NC.MONEDA &lt;&gt; 0  THEN -NC1.VALOARE * NC.CURS
  END
) AS SOLDLEI,
SUM(-NC1.VALOARE) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTC, 0) &lt;&gt; 0
  AND NVL(NC1.PERSC, 0)  &lt;&gt; 0
 GROUP BY
   NC1.AGENT,
   NC1.ICONTC,
   NC.MONEDA,
   NC.SUBUNITATEA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_NC_DEBIT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8C47BEA74806F422A0E4B4192133B1C77EBB1369</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_NC_DEBIT (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTD AS ICONT,
       NC.MONEDA AS CODMONEDA,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN NC1.VALOARE
    WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE * NC.CURS
  END
) AS SOLDLEI,
SUM(NC1.VALOARE) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTD, 0) &lt;&gt; 0
  AND NVL(NC1.PERSD, 0)  &lt;&gt; 0
 GROUP BY
   NC1.AGENT,
   NC1.ICONTD,
   NC.MONEDA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_NC_DEBIT_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5E9CC1F8C25EB2B62E4C8FEE09F589D4780E33C1</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_NC_DEBIT_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT NC1.AGENT AS CODPERS,
       NC1.ICONTD AS ICONT,
       NC.MONEDA AS CODMONEDA,
       NC.SUBUNITATEA,
SUM(
  CASE
    WHEN NC.MONEDA = 0  THEN NC1.VALOARE
    WHEN NC.MONEDA &lt;&gt; 0  THEN NC1.VALOARE * NC.CURS
  END
) AS SOLDLEI,
SUM(NC1.VALOARE) AS SOLDVALUTA
FROM
  NC1,
  NC
WHERE
  NC.AN = PKG_GLOBALS.GETANTEMP  AND NC.LUNA = PKG_GLOBALS.GETLUNATEMP
  AND NC.CODNC = NC1.CODNC
  AND NVL(NC1.AGENT, 0)  &lt;&gt; 0
  AND NVL(NC1.ICONTD, 0) &lt;&gt; 0
  AND NVL(NC1.PERSD, 0)  &lt;&gt; 0
 GROUP BY
   NC1.AGENT,
   NC1.ICONTD,
   NC.MONEDA,
   NC.SUBUNITATEA
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>24C235A4B5DAAF62051C02C7220A0A3F1B0DA4B2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_PREC (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM 
  NPERSSOLDLUNA 
WHERE 
  AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_PREC_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>68B5FA6DCDBFE84DBE88D6FDD0B03E1FEBE117AC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_PREC_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
FROM
  NPERSSOLDLUNASUB
WHERE
  AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDURIBANCILUNAPREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>926541CFD3A8E680E72F748BE7163D0428272F61</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDURIBANCILUNAPREC (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, NVL(SOLDLEI,0) SOLDLEI,  NVL(SOLDVALUTA, 0) SOLDVALUTA
FROM
  NBANKSOLDLUNA
WHERE
AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDURIBANCI_LA_DATA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>006F48ABA46853DE67C7E3D6E4AF70AFE0935CAC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDURIBANCI_LA_DATA (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM (

SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA
FROM
  NBANKSOLDLUNA
WHERE
  AN = PKG_GLOBALS.GETANPRECEDENT
  AND LUNA = PKG_GLOBALS.GetLUNAPRECEDENTA
UNION ALL


  -- tranzactii trezorerie
  SELECT T.CODBANCA AS CODBANKCONT,
         SUM(
          CASE
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN  -(T1.VALDOC + NVL(T1.COMISION, 0)) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN   ( T1.VALDOC  - NVL(T1.COMISION, 0)) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN - (T1.VALDOC + NVL(T1.COMISION, 0)) * T1.CURS * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN   (T1.VALDOC - NVL(T1.COMISION, 0)) * T1.CURS  *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
          END
         ) AS  SOLDLEI,
         SUM(
          CASE
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN 0
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN 0
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN -(T1.VALDOC + NVL(T1.COMISION, 0)) *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN ( T1.VALDOC - NVL(T1.COMISION, 0)) *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
          END
        ) AS SOLDVALUTA
  FROM
   TREZOR T
   LEFT OUTER JOIN TREZOR1   T1 ON T1.CODTREZOR   = T.CODTREZOR
   LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
   LEFT OUTER JOIN NBANK     NB ON NB.CODBANK     = BC.CODBANK
   LEFT OUTER JOIN NMONEDE   M  ON M.CODMONEDA    = BC.CODMONEDA
  WHERE
   T.TIPDOC IN (29, 30)
   AND T.OPERAT = 1
   AND NVL(T1.ANULAT, 0) = 0
   AND T.AN * 12 + T.LUNA = PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP
   AND NVL(T.DATADOC, TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;))  &lt;= PKG_GLOBALS.GETDATASOLDBANCI
   AND T.CODBANCA = PKG_CONTURIBANCI.GETCONTBANCACURENT

  GROUP BY T.CODBANCA
  -- end tranzactii trezorerie


  UNION ALL


  -- monetare
  SELECT M.CODBANKCONT, SUM(M.VALOARE *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)) AS SOLDLEI, 0 AS SOLDVALUTA
  FROM
   IESIRI I
   LEFT OUTER JOIN MODURIPLATI M ON M.CODIES=I.CODIES,
   NBANKCONT BC
  WHERE
   I.ANULAT = 0 AND OPERAT = 1 AND I.TIPDOC = 16 --AND M.TIPPLATA = 0
   AND I.AN * 12 + I.LUNA = PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP
   AND NVL(I.DATADOC, TO_DATE(&apos;01.01.1900&apos;, &apos;dd.mm.yyyy&apos;))  &lt;= PKG_GLOBALS.GETDATASOLDBANCI
   AND BC.CODBANKCONT = M.CODBANKCONT
   AND M.VALOARE &lt;&gt; 0
   AND M.CODBANKCONT = PKG_CONTURIBANCI.GETCONTBANCACURENT
  GROUP BY M.CODBANKCONT
  -- end monetare


)
GROUP BY CODBANKCONT

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDURIBANCI_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>941ED3246F2DA4C890F79BCDEAD239CF1F3EE89F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDURIBANCI_TRANZACTII (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM (
  -- tranzactii trezorerie
  SELECT T.CODBANCA AS CODBANKCONT,
         SUM(
          CASE
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN  -(T1.VALDOC + NVL(T1.COMISION, 0)) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN   (T1.VALDOC - NVL(T1.COMISION, 0)) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN - (T1.VALDOC + NVL(T1.COMISION, 0)) * DECODE(NVL(T1.CURS,0), 0, 1, T1.CURS) * DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN   (T1.VALDOC - NVL(T1.COMISION, 0)) * DECODE(NVL(T1.CURS,0), 0, 1, T1.CURS) *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
          END
         ) AS  SOLDLEI,
         SUM(
          CASE
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA = 0  THEN 0
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA = 0  THEN 0
            WHEN T1.TIPTRANZ = 0 AND M.CODMONEDA &lt;&gt; 0 THEN -(T1.VALDOC + NVL(T1.COMISION, 0)) *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
            WHEN T1.TIPTRANZ = 1 AND M.CODMONEDA &lt;&gt; 0 THEN  (T1.VALDOC - NVL(T1.COMISION, 0)) *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)
          END
        ) AS SOLDVALUTA
  FROM
   TREZOR T
   LEFT OUTER JOIN TREZOR1   T1 ON T1.CODTREZOR   = T.CODTREZOR
   LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
   LEFT OUTER JOIN NBANK     NB ON NB.CODBANK     = BC.CODBANK
   LEFT OUTER JOIN NMONEDE   M  ON M.CODMONEDA    = BC.CODMONEDA
  WHERE
   T.TIPDOC IN (29, 30) AND T.OPERAT = 1 AND NVL(T1.ANULAT, 0) = 0 AND
   T.AN = PKG_GLOBALS.GETANTEMP  AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
  GROUP BY T.CODBANCA
  -- end tranzactii trezorerie


  UNION ALL


  -- monetare
  SELECT M.CODBANKCONT, SUM(M.VALOARE *  DECODE(NVL(BC.CREDIT, 0), 0, 1, -1)) AS SOLDLEI, 0 AS SOLDVALUTA
  FROM
   IESIRI I
   LEFT OUTER JOIN MODURIPLATI M ON M.CODIES=I.CODIES,
   NBANKCONT BC
  WHERE
   I.ANULAT = 0 AND OPERAT = 1 AND I.TIPDOC = 16 --AND M.TIPPLATA = 0
   AND I.AN = PKG_GLOBALS.GETANTEMP  AND I.LUNA = PKG_GLOBALS.GETLUNATEMP AND
   BC.CODBANKCONT = M.CODBANKCONT
   AND M.VALOARE &lt;&gt; 0
  GROUP BY M.CODBANKCONT
  -- end monetare


)
GROUP BY CODBANKCONT
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDURIPERSLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C2193E1EE8BAC173BDEBD2FFB81B8DA878B2B3C7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDURIPERSLUNA (
&quot;CODPERS&quot;,&quot;SOLDVALUTA&quot;,&quot;SOLDLEI&quot;,&quot;CODCONT&quot;,&quot;DEN_CONT&quot;) AS
select 0 as CodPers, 0 as SoldValuta, 0 as SoldLei, 0 as CodCont, &apos;&apos; as Den_Cont from DUAL 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLD_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4BD99D2A1163B60AF9E983B4BBECC48D123CFA75</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLD_INI (
&quot;CODSOLDINI&quot;,&quot;CODPART&quot;,&quot;DEN_PART&quot;,&quot;SOLDREAL&quot;) AS
SELECT  I.CODSOLDINI, I.CODPART, P.DEN_PART, 
(SELECT SUM(SOLDLEI) 
 FROM  
   NPARTSOLDLUNA NS 
 WHERE 
   NS.CODPART = I.CODPART AND NS.AN = PKG_GLOBALS.GETANTEMP AND NS.LUNA = PKG_GLOBALS.GETLUNATEMP
 ) AS SOLDREAL

FROM
SOLDINI I
LEFT OUTER JOIN NPART P ON I.CODPART = P.CODPART 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STATCON</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>84A7260F98599E0638E79DCC09CDE0FF036221AE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STATCON (
&quot;CODSTATCON&quot;,&quot;NUME&quot;,&quot;ATRIBUT&quot;) AS
SELECT S.CODSTATCON,I.Nume, Decode(S.Atribut,0,&apos;Cald/Rece&apos;,1,&apos;Moale/Tare&apos;,2,&apos;Subtire/Gros&apos;,3,&apos;Alunecos/Nisipos&apos;,4,&apos;Elastic/Neelastic&apos;,5,&apos;Flexibil/Rigid&apos;,6,&apos;Neted/Aspru&apos;,7,&apos;Usor/Greu&apos;) Atribut
FROM StatCon S
Left join EvalS E on E.CodEvalS = S.CodEvalS
Left join IdentEvalS I on I.CodIdentEvalS = E.CodIdentEvalS
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STATCOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FFA6D3167A3E086748B73B1E141666C370239BD0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STATCOR (
&quot;CODSTATCOR&quot;,&quot;NUME&quot;,&quot;ATRIBUT&quot;) AS
SELECT S.CODSTATCOR,I.Nume, Decode(S.Atribut,0,&apos;Cald/Rece&apos;,1,&apos;Moale/Tare&apos;,2,&apos;Subtire/Gros&apos;,3,&apos;Alunecos/Nisipos&apos;,4,&apos;Elastic/Neelastic&apos;,5,&apos;Flexibil/Rigid&apos;,6,&apos;Neted/Aspru&apos;,7,&apos;Usor/Greu&apos;) Atribut
FROM StatCoR S
Left join EvalS E on E.CodEvalS = S.CodEvalS
Left join IdentEvalS I on I.CodIdentEvalS = E.CodIdentEvalS
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STIFIN1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C42BE67A1E79CFB2ECA8529F6CF3A8C1D4D330AD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STIFIN1 (
&quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;,&quot;CODDEN&quot;) AS
select &quot;CODSITFIN&quot;,&quot;CODF&quot;,&quot;DENUMIRE&quot;,&quot;SECTIUNE&quot;, CodF||&apos; - &apos;||Denumire CodDen
    from SITFIN
where nvl(Tip,0) = 1

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCSER_LUNA_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>86B9B99C5E70D16D448AC550280737E257FB3BD3</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCSER_LUNA_PREC (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NL.CODNIRSER, NL.CODNIRSTOC, NL.REST, NL.RESTUM1, NL.RESTUM2
FROM
  NIRSERLUNA NL,
  NIRSTOC NS,
  TMP_IOART_LUNA IO
WHERE
  NL.AN = PKG_GLOBALS.GETANPRECEDENT
  AND NL.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND NVL(NL.REST, 0) + NVL(NL.RESTUM1, 0) + NVL(NL.RESTUM2, 0) &lt;&gt; 0
  AND NL.CODNIRSTOC = NS.CODNIRSTOC
  AND NS.CODIOART = IO.CODIOART
  AND IO.MG &lt;&gt; 5 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E87E04812DC92A3E54589F3B92F82C54D0EAFAC0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL_INI (
&quot;CODSTOCVALINI&quot;,&quot;GEST&quot;,&quot;DEN_GEST&quot;,&quot;SOLDTOTAL&quot;) AS
SELECT  I.CODSTOCVALINI, I.GEST, G.DEN_GEST,
(SELECT SUM(SOLD)
 FROM
   STOCVALLUNA SV
 WHERE
   SV.GEST = I.GEST AND SV.AN = PKG_GLOBALS.GETANTEMP AND SV.LUNA = PKG_GLOBALS.GETLUNATEMP
 ) AS SOLDTOTAL
FROM
 STOCVALINI I
 LEFT OUTER JOIN NGEST G ON I.GEST = G.CODGEST
WHERE
  NVL(G.CODSUBUNIT,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE,1,NVL(G.CODSUBUNIT,1),PKG_GLOBALS.GETSUBUNITATE)
  AND NVL(G.CODSUBUNIT, 1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL_LIVRARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>59AD96EC0C6D5EAD4E8D5A3530470357734F8EAE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL_LIVRARI (
&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;TVA&quot;,&quot;SOLD&quot;,&quot;ADAOS&quot;,&quot;SOLDINTR&quot;,&quot;ADAOSINTR&quot;) AS
SELECT
GEST, CODIOART, TVA,
SUM(SOLD) AS SOLD, SUM(ADAOS) AS ADAOS, SUM(SOLDINTR) AS SOLDINTR, SUM(ADAOSINTR) AS ADAOSINTR
FROM
(
  SELECT
   LV.GEST,
   LV.CODIOART,
   LV.TVANEEX AS TVA,
   - LV.PRETINREG * L1.CANT AS SOLD,
   - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT AS ADAOS,
   0 AS SOLDINTR,
   0 AS ADAOSINTR
  FROM
    LIVRVAL LV
    LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
    LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    LEFT OUTER JOIN INTRARI I ON I.CODINTR = L.CODINTR
  WHERE
    L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
    I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
   AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(LV.GEST, LV.CODIOART, LV.TVANEEX, L.DATALIVR) = 1

  UNION ALL
   -- IESIRI
  SELECT
   LV.GEST,
   LV.CODIOART,
   LV.TVANEEX AS TVA,
   - LV.PRETINREG * L1.CANT AS SOLD,
   - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT AS ADAOS,
   0 AS SOLDINTR,
   0 AS ADAOSINTR
  FROM
    LIVRVAL LV
    LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
    LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES
  WHERE
    L.TIPLIVR IN (14, 16, 19, 20, 21, 22, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
    I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
    AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(LV.GEST, LV.CODIOART, LV.TVANEEX, L.DATALIVR) = 1

  UNION ALL

   -- MISCARI INTERNE
  SELECT
   LV.GEST,
   LV.CODIOART,
   LV.TVANEEX AS TVA,
   - LV.PRETINREG * L1.CANT AS SOLD,
   - (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT AS ADAOS,
   0 AS SOLDINTR,
   0 AS ADAOSINTR
  FROM
    LIVRVAL LV
    LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
    LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
  WHERE
    L.TIPLIVR IN (12, 13) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
    T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
   AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(LV.GEST, LV.CODIOART, LV.TVANEEX, L.DATALIVR) = 1


  UNION ALL

    -- MARIRI DE STOC
  SELECT
   LV.GEST,
   LV.CODIOART,
   LV.TVANEEX AS TVA,
   LV.PRETINREG * L1.CANT AS SOLD,
   (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT AS ADAOS,
   LV.PRETINREG * L1.CANT AS SOLDINTR,
   (LV.PRETINREG - LV.PRETACHIZ) * L1.CANT AS ADAOSINTR

  FROM
    LIVRVAL LV
    LEFT OUTER JOIN LIVR1 L1 ON L1.CODLIVR1= LV.CODLIVR1
    LEFT OUTER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    LEFT OUTER JOIN IESIRI I ON I.CODIES = L.CODIES
  WHERE
    L.TIPLIVR = 15 AND L.OPERAT = 1 AND L.ANULAT = 0 AND
    I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
   AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(LV.GEST, LV.CODIOART, LV.TVANEEX, L.DATALIVR) = 1
)
GROUP BY GEST, CODIOART, TVA 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL_NIRURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7C574E1162BECDAE914AE2CF261092CC77F5BDA9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL_NIRURI (
&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;TVA&quot;,&quot;SOLD&quot;,&quot;ADAOS&quot;,&quot;SOLDINTR&quot;,&quot;ADAOSINTR&quot;) AS
SELECT
  N.GEST,
  NS.CODIOART, NS.TVA,
  NS.CANTNIR * NS.PRET  AS SOLD,
  NS.CANTNIR * NS.ADAOS AS ADAOS,
  NS.CANTNIR * NS.PRET  AS SOLDINTR,
  NS.CANTNIR * NS.ADAOS AS ADAOSINTR
FROM
  NIRSTOC NS
  LEFT OUTER JOIN
  (SELECT CODIOART, MG, DIFPRET, ARETVANEEX FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP )
   ) IOALUNA ON IOALUNA.CODIOART = NS.CODIOART
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN INTRARI I ON I.CODINTR = N.CODINTR
WHERE
  IOALUNA.MG = 5 AND
  N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7) AND  N.ANULAT = 0 AND N.OPERAT = 1
AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(N.GEST, NS.CODIOART, NS.TVA, N.DATANIR) = 1

UNION ALL
-- NIR-URI DIN MISCARI INTERNE
SELECT
  N.GEST,
  NS.CODIOART, NS.TVA,
  NS.CANTNIR * NS.PRET  AS SOLD,
  NS.CANTNIR * NS.ADAOS AS ADAOS,
  NS.CANTNIR * NS.PRET  AS SOLDINTR,
  NS.CANTNIR * NS.ADAOS AS ADAOSINTR
FROM
  NIRSTOC NS
  LEFT OUTER JOIN
  (SELECT CODIOART, MG, DIFPRET, ARETVANEEX FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANTEMP * 12 + PKG_GLOBALS.GETLUNATEMP )
   ) IOALUNA ON IOALUNA.CODIOART = NS.CODIOART
  LEFT OUTER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT OUTER JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
WHERE
  IOALUNA.MG = 5 AND
  N.TIPNIR IN (12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
 AND T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP
 AND PKG_GLOBALS.FILTRU_STOCVAL_TRANZACTII_OK(N.GEST, NS.CODIOART, NS.TVA, N.DATANIR) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3300632B61361101D06B17F0041AC5258B26D01E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL_PREC (
&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;TVA&quot;,&quot;SOLD&quot;,&quot;ADAOS&quot;,&quot;SOLDINTR&quot;,&quot;ADAOSINTR&quot;) AS
SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
FROM
  STOCVALLUNA
WHERE
  AN = PKG_GLOBALS.GETANPRECEDENT AND LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA AND
  PKG_GLOBALS.FILTRU_STOCVAL_LUNAPREC_OK (GEST, CODIOART, TVA) = 1 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_DOCIMPSERVER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E2B38ACC0AE25C06C1292100B761696AAED06919</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_DOCIMPSERVER (
&quot;CODOBIECT&quot;,&quot;GEST&quot;,&quot;FURN&quot;,&quot;CODIOART&quot;,&quot;STOC&quot;,&quot;REZERVAT&quot;) AS
SELECT
  CODOBIECT,
  GEST,
  FURN,
  0 AS CODIOART,
  SUM(REST) AS STOC,
  SUM(NVL(REZERVAT, 0)) AS REZERVAT
FROM
(
SELECT
  NS.CODOBIECT,
  N.GEST,
  NS.FURN,
  REST,
  (SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC) REZERVAT
FROM
 NIRSTOC NS,
 NIR N
WHERE
 N.CODNIR = NS.CODNIR
)
GROUP BY CODOBIECT, GEST, FURN
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_GENERARE_FACTURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EE1089835864565C2EA0B716CDA85A2937D2A278</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_GENERARE_FACTURI (
&quot;DENOBIECT&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;DENUM&quot;,&quot;CODNIRSTOC&quot;,&quot;UMSEC&quot;,&quot;CODOBIECT&quot;,&quot;CODIOART&quot;,&quot;GEST&quot;,&quot;PRETACHIZ&quot;,&quot;PRET&quot;,&quot;ADAOS&quot;,&quot;TVA&quot;,&quot;TIPSERIE&quot;,&quot;STOC&quot;,&quot;PROCENTADAOS&quot;,&quot;INTRATLA&quot;,&quot;TG&quot;,&quot;PUMAXIMAL&quot;,&quot;CODPART&quot;,&quot;SERIE&quot;,&quot;CODNIRSER&quot;,&quot;CODSERIE&quot;,&quot;DATAACHIZ&quot;,&quot;TIPDOCACHIZ&quot;,&quot;TIPINTRARESTOC&quot;,&quot;LOCATIE&quot;,&quot;FURNIZOR&quot;,&quot;CODTVA&quot;,&quot;PROCTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;TIPARTICOL&quot;,&quot;TERMENPLATA&quot;,&quot;ADAOSEXCEPTIE&quot;,&quot;DENFURN&quot;,&quot;SUPLIMENT&quot;,&quot;DEN_CARSUPART&quot;,&quot;TIPCOMPENSARE&quot;,&quot;DEN_GEST&quot;,&quot;DEN_IOART&quot;,&quot;PRODUCATOR&quot;,&quot;ROTLEI&quot;) AS
SELECT
  O.DENUMIRE AS DENOBIECT,
  O.CODEXTERN,
  O.CODINTERN,
  U1.DEN_UM1 AS DENUM,
  NS.CODNIRSTOC,
  NS.UMSEC,
  NS.CODOBIECT,
  NS.CODIOART,
  NIRCURENT.GEST,
  NS.PRET - NVL( NS.ADAOS, 0) AS PRETACHIZ,
  NS.PRET  AS PRET,
  NVL(NS.ADAOS, 0) AS ADAOS,
  NS.TVA,
  NS.TIPSERIE,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN NSE.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER = NSE.CODNIRSER), 0)
     ELSE NS.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NS.CODNIRSTOC) , 0)
   END
   ) AS STOC,
  NS.PROCENTADAOS,
  NIRCURENT.DATANIR AS INTRATLA,
  NS.TG,
  NS.PUMAXIMAL,
  NS.FURN AS CODPART,
  (CASE
    WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE)
    ELSE &apos;&apos;
   END
  ) AS SERIE,
  NVL(NSE.CODNIRSER, 0) CODNIRSER,
  NSE.CODSERIE,
  NS.DATAACHIZ,
  NS.TIPDOCACHIZ,
  NIRCURENT.TIPNIR AS TIPINTRARESTOC,
  L.DENUMIRE AS LOCATIE,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS FURNIZOR,
  NART1LUNA.CODTVA,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.TIPARTICOL,
  O.TERMENPLATA,
  O.ADAOSEXCEPTIE,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS DENFURN,
  &apos; &apos; AS SUPLIMENT,
  CAR.DEN_CARSUPART,
  NARTOBJ1LUNA.TIPCOMPENSARE,
  G.DEN_GEST,
  IOART.DEN_IOART,
  (SELECT DEN_PART FROM NPART WHERE CODPART = O.CODPRODUCATOR) AS PRODUCATOR,
  O.ROTUNJIRE AS ROTLEI
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIRSER NSE            ON NSE.CODNIRSTOC        = NS.CODNIRSTOC
  LEFT OUTER JOIN NLOCATII L            ON L.CODLOCATIE          = NVL(NS.CODLOCATIE, 0),
  NIR NIRCURENT,
  NGEST G,
  NARTOBJ O
  LEFT OUTER JOIN --tmp_nartobj_luna NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = o.codobiect
  (SELECT CODOBIECT, TIPCOMPENSARE FROM NARTOBJ1 O1  WHERE
  O1.ANSTART * 12 + O1.LUNASTART =
  (SELECT MAX(O11.ANSTART * 12 + O11.LUNASTART) FROM NARTOBJ1 O11
  WHERE
     O11.CODOBIECT = O1.CODOBIECT AND O11.ANSTART * 12 + O11.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  LEFT OUTER JOIN NCARSUPART CAR ON CODCARSUPART = O.CODCARACT,
  NART A
  LEFT OUTER JOIN --tmp_nart_luna NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
 (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.ANSTART * 12 + A1.LUNASTART =
   (SELECT MAX(A11.ANSTART * 12 + A11.LUNASTART) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.ANSTART * 12 + A11.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN --tmp_ntva_luna TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA,
  (
      SELECT N.CODTVA,N1.CODTVA1,N.DEN_TVA,N1.PROCENT,N1.CODCONTDED,N1.CODCONTCOLE,N1.CODCONTNEEX
      FROM NTVA N LEFT JOIN NTVA1 N1
      ON 	N.CODTVA = N1.CODTVA
         WHERE N1.ANSTART * 12 + N1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 NT1
                                                   WHERE NT1.CODTVA = N1.CODTVA AND
      					     ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
  ) TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA,
  NUM1 U1,
  IOART, --tmp_ioart_luna ioaluna
  (SELECT CODIOART, MG FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) IOALUNA
WHERE
  NS.REST &lt;&gt; 0
  AND NIRCURENT.CODNIR = NS.CODNIR
  AND G.CODGEST        = NIRCURENT.GEST
  AND O.CODOBIECT      = NS.CODOBIECT
  AND A.CODARTICOL     = O.CODARTICOL
  AND U1.CODUM1        = NS.UMSEC
  AND IOART.CODIOART   = NS.CODIOART
  AND IOALUNA.CODIOART = NS.CODIOART
  AND (IOALUNA.MG &lt;&gt; 5)AND(IOALUNA.MG &lt;&gt; 3)
  AND PKG_CONFIGART.CODIOART_FILTRU_VALID(IOALUNA.CODIOART) &gt; 0
  AND PKG_NOMGEST.GESTIUNE_DEDICATA(NIRCURENT.GEST)  &gt; 0
  AND PKG_NOMGEST.GESTIUNE_FILTRU_VALIDA(NIRCURENT.GEST) &gt; 0
  AND NVL(G.CODSUBUNIT, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
  AND PKG_CLASEART.CODCLASA_FILTRU_VALID(A.CLASA) &gt; 0 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7476B152127A43580E86E5153F6BD4E199C9F9D7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INI (
&quot;CODSTOCINI&quot;,&quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;OPERATOR&quot;) AS
SELECT  I.CODSTOCINI, I.CODGEST, G.DEN_GEST, P.NUME || &apos; &apos; || P.PRENUME AS OPERATOR
FROM
 STOCINI I
 LEFT OUTER JOIN NGEST G ON I.CODGEST = G.CODGEST
 LEFT OUTER JOIN NPERS P ON I.CODPERS = P.CODPERS
WHERE
nvl(g.codsubunit,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(g.codsubunit,1),pkg_globals.GETSUBUNITATE) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INI_NECESAR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8AA45D5B8170176751A7A0419780E2A211203FC5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INI_NECESAR2 (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  SUM(STOC.REST) REST
FROM (
  SELECT
    NS.CODNIRSTOC,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA
    LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = NE.CODNIRSER AND NSE.CODNIRSTOC = NS.CODNIRSTOC
  WHERE
    N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
  SELECT
    NS.CODNIRSTOC,
    CASE
      WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
      ELSE NSE.CANTNIR
    END REST
  FROM
    NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
    AND N.DATANIR &lt; PKG_LIST_SELFISAMAG.GETDATASTOC
UNION ALL
SELECT
  NS.CODNIRSTOC,
  CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN NIRSER NE ON L1.CODNIRSER = NE.CODNIRSER
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND L.DATALIVR &lt; PKG_LIST_SELFISAMAG.GETDATASTOC
) STOC GROUP BY STOC.CODNIRSTOC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INI_PLANIF</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EAA9A6E17E94D1D76FE41A68BF16EA46F1F3251C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INI_PLANIF (
&quot;CODOBIECT&quot;,&quot;TG&quot;,&quot;CODSERIE&quot;,&quot;REST&quot;,&quot;CANTREZ&quot;,&quot;CODGEST&quot;) AS
SELECT
  STOC.CODOBIECT,
  STOC.TG,
  STOC.CODSERIE,
  SUM(STOC.REST) REST,
  SUM(STOC.CANTREZ) CANTREZ,
  STOC.CODGEST
FROM (
  SELECT
    NS.CODOBIECT,
    NVL(NSE.TG, NS.TG) TG,
    nvl(NSE.CODSERIE, 0) CODSERIE,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    NIR.GEST CODGEST,
    NVL(R.REST,0) CANTREZ
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NIR ON NS.CODNIR = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA
    LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = NE.CODNIRSER AND NSE.CODNIRSTOC = NS.CODNIRSTOC
    LEFT JOIN REZERVATS R ON R.CODNIRSTOC = NS.CODNIRSTOC AND R.CODNIRSER = NSE.CODNIRSER
  WHERE
    N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
  SELECT
    NS.CODOBIECT,
    NVL(NSE.TG, NS.TG) TG,
    NVL(NSE.CODSERIE, 0) CODSERIE,
    CASE
      WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
      ELSE NSE.CANTNIR
    END REST,
    N.GEST CODGEST,
    NVL(R.REST,0) CANTREZ
  FROM
    NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
    LEFT  JOIN REZERVATS R ON R.CODNIRSTOC = NS.CODNIRSTOC AND R.CODNIRSER = NSE.CODNIRSER
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
    AND N.DATANIR &lt; PKG_LIST_SELFISAMAG.GETDATASTOC
UNION ALL
SELECT
  NS.CODOBIECT,
  NVL(NE.TG, NS.TG) TG,
  NVL(NE.CODSERIE, 0) CODSERIE,
  CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
  N.GEST CODGEST,
  NVL(R.REST,0) CANTREZ
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN NIRSER NE ON L1.CODNIRSER = NE.CODNIRSER
  LEFT JOIN REZERVATS R ON R.CODNIRSTOC = NS.CODNIRSTOC AND NE.CODNIRSER = R.CODNIRSER
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND L.DATALIVR &lt; PKG_LIST_SELFISAMAG.GETDATASTOC
) STOC GROUP BY STOC.CODOBIECT, STOC.TG, STOC.CODSERIE, STOC.CODGEST

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>40D50ACFD823B4A4FAE948A436611779B115781E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR1 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClasele = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA

UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU OR T.AN = PKG_GLOBALS.GETANLUCRU AND T.LUNA = PKG_GLOBALS.GETLUNALUCRU)
  AND N.DATANIR &lt;= PKG_INVENTAR.GETDATAINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANLUCRU AND I.LUNA = PKG_GLOBALS.GETLUNALUCRU OR
   IES.AN = PKG_GLOBALS.GETANLUCRU AND IES.LUNA = PKG_GLOBALS.GETLUNALUCRU OR
   T.AN = PKG_GLOBALS.GETANLUCRU AND T.LUNA = PKG_GLOBALS.GETLUNALUCRU)
  AND L.DATALIVR &lt;= PKG_INVENTAR.GETDATAINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0AE1442B2FB3C26BD5103F26CCEA630869FA9276</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR2 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND NVL(I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND NVL(I.DATACREARE, nvl(IES.DATACREARE, T.DATACREARE)) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1118FE5C4B83CED8E0DBB390A7209B5A90AA8688</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR3 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
    pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND N.DATANIR &lt;= PKG_INVENTAR.GETDATAINVENTAR
  AND NVL(I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST
   AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
  IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
  T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND L.DATALIVR &lt;= PKG_INVENTAR.GETDATAINVENTAR
  AND COALESCE(IES.DATACREARE, I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR_LUNAI1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A63ADDB8961AF6788E6CA101453E54A4B8F59D4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR_LUNAI1 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND N.DATANIR &lt;= PKG_INVENTAR.GETDATAINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0),
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND L.DATALIVR &lt;= PKG_INVENTAR.GETDATAINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR_LUNAI2</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F809A897111D76B664011AD0C41E11FEA4E509C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR_LUNAI2 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND NVL(I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND NVL(I.DATACREARE, nvl(IES.DATACREARE, T.DATACREARE)) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_INVENTAR_LUNAI3</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9D3F59E12FE8BEB4ECE2D25BD1E95C535CDB8D45</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_INVENTAR_LUNAI3 (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;,&quot;CODIOART&quot;,&quot;UMSEC&quot;) AS
SELECT
  STOC.CODNIRSTOC,
  STOC.CODNIRSER,
  SUM(NVL(STOC.REST,0)) REST,
  SUM(NVL(STOC.RESTUM1,0)) RESTUM1,
  SUM(NVL(STOC.RESTUM2,0)) RESTUM2,
  STOC.CODIOART,
  STOC.UMSEC
FROM (
  SELECT
    N.CODNIRSTOC,
    nvl(NE.CODNIRSER, 0) CODNIRSER,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST
      ELSE NE.REST
    END REST,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1
      ELSE NE.RESTUM1
    END RESTUM1,
    CASE
      WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2
      ELSE NE.RESTUM2
    END RESTUM2,
    NS.CODIOART,
    NS.UMSEC
  FROM
    NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR ON NS.Codnir = NIR.CODNIR
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA AND NS.TIPSERIE &gt; 0
  WHERE
     ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND NIR.GEST = PKG_INVENTAR.GETCODGEST AND
   N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
UNION ALL -- NIRURI LUNA
 SELECT
   NS.CODNIRSTOC,
   NVL(NSE.CODNIRSER, 0) CODNIRSER,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR
     ELSE NSE.CANTNIR
   END REST,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1
     ELSE NSE.CANTUM1
   END RESTUM1,
   CASE
     WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2
     ELSE NSE.CANTUM2
   END RESTUM2,
   NS.CODIOART,
   NS.UMSEC
  FROM
    NIRSTOC NS
    INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
    INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC AND NS.TIPSERIE &gt; 0
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE
    ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
    N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
  AND (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND N.DATANIR &lt;= PKG_INVENTAR.GETDATAINVENTAR
  AND NVL(I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        case when ns.tipserie &gt; 0 then NVL(L1.CODNIRSER, 0) else 0 end CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART A ON A.CODARTICOL = OBJ.CODARTICOL
  INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
  LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
  LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
  LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
WHERE
  ( EXISTS (SELECT valoare FROM   tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos; AND valoare = ns.codobiect)  OR
         PKG_INVENTAR.isToateArt = 1
     )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos; AND valoare = ns.codioart ) OR
      pkg_INVENTAR.isToateConturile = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEA&apos; AND PKG_GLOBALS.IS_SUBCLAS_OF(nvl(A.clasa,0), to_number(valoare)) = 1 ) OR
      pkg_INVENTAR.isToateClasele = 1
    )
   AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODCLASEAS&apos; AND PKG_CLASEARTS.IS_SUBCLAS_OF(nvl(A.clasastatist,0), to_number(valoare)) = 1) OR
      pkg_INVENTAR.isToateClaseleS = 1
    )
    AND (EXISTS (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODPART&apos; AND valoare = OBJ.Codproducator ) OR
      pkg_INVENTAR.isToateProd = 1
    )
   AND N.GEST = PKG_INVENTAR.GETCODGEST AND
  L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0 AND
  (I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   IES.AN = PKG_GLOBALS.GETANTEMP AND IES.LUNA = PKG_GLOBALS.GETLUNATEMP OR
   T.AN = PKG_GLOBALS.GETANTEMP AND T.LUNA = PKG_GLOBALS.GETLUNATEMP)
  AND L.DATALIVR &lt;= PKG_INVENTAR.GETDATAINVENTAR
  AND COALESCE(IES.DATACREARE, I.DATACREARE, T.DATACREARE) &lt; PKG_INVENTAR.GETDATAINVENTAR + 1
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.MARIRE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
UNION ALL
 SELECT L1.CODNIRSTOC,
        NVL(L1.CODNIRSER, 0) CODNIRSER,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANT ELSE L1.CANT END  REST,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM1 ELSE L1.CANTUM1 END RESTUM1,
        CASE WHEN L.TIPLIVR = 15 THEN -L1.CANTUM2 ELSE L1.CANTUM2 END RESTUM2,
        NS.CODIOART,
        NS.UMSEC
FROM
  LIVR1 L1
  INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
  INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
  INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
  INNER JOIN IESIRI IES ON IES.CODIES = L.CODIES
  INNER JOIN INVENTAR I ON I.DIMINUARE = IES.CODIES
WHERE  I.codinventar = PKG_INVENTAR.GETCODINVENTAR
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER, STOC.CODIOART, STOC.UMSEC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_LA_MOMENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>253DC6ED5ACFE2B4D1B7EB9B805A57CA2F279A83</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_LA_MOMENT (
&quot;CODNIRSTOC&quot;,&quot;UMSEC&quot;,&quot;CODOBIECT&quot;,&quot;CODIOART&quot;,&quot;GEST&quot;,&quot;PRETACHIZ&quot;,&quot;PRET&quot;,&quot;ADAOS&quot;,&quot;TVA&quot;,&quot;TIPSERIE&quot;,&quot;REST&quot;,&quot;STOC&quot;,&quot;PRELUAT&quot;,&quot;PROCENTADAOS&quot;,&quot;INTRATLA&quot;,&quot;TG&quot;,&quot;PUMAXIMAL&quot;,&quot;CODPART&quot;,&quot;SERIE&quot;,&quot;CODNIRSER&quot;,&quot;CODSERIE&quot;,&quot;CODNIR&quot;,&quot;CODINTR1&quot;,&quot;CODINTR&quot;,&quot;FLAG&quot;,&quot;CODTRANSF1&quot;,&quot;DATAACHIZ&quot;,&quot;TIPDOCACHIZ&quot;,&quot;TIPINTRARESTOC&quot;,&quot;LOCATIE&quot;,&quot;RESTUM1&quot;,&quot;STOCUM1&quot;,&quot;PRELUATUM1&quot;,&quot;RESTUM2&quot;,&quot;STOCUM2&quot;,&quot;PRELUATUM2&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;FURNIZOR&quot;,&quot;CODLOCATIE&quot;) AS
SELECT
  NS.CODNIRSTOC,
  NS.UMSEC,
  NS.CODOBIECT,
  NS.CODIOART,
  NIRCURENT.GEST,
  ROUND((NS.PRET - NVL(NS.ADAOS, 0)) * PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10) AS PRETACHIZ,
  ROUND( NS.PRET * PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10) AS PRET,
  NS.ADAOS,
  NS.TVA,
  NS.TIPSERIE,
  (CASE
    WHEN NS.TIPSERIE &gt; 0 THEN  ROUND( NSE.REST / PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10)
    ELSE ROUND( NS.REST / PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10)
   END
  ) AS REST,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN ROUND( NSE.REST / PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10)
     ELSE ROUND( NS.REST / PKG_SELECTARTICOLE.GETPARITATESTOCMOMENT, 10)
   END
   ) AS STOC,
  0.0 AS PRELUAT,
  NS.PROCENTADAOS,
  NIRCURENT.DATANIR AS INTRATLA,
  NS.TG,
  NS.PUMAXIMAL,
  NS.FURN AS CODPART,
  (CASE
    WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE)
    ELSE &apos;&apos;
   END
  ) AS SERIE,
  NVL(NSE.CODNIRSER, 0) CODNIRSER,
  NSE.CODSERIE,
  0 AS CODNIR,
  0 AS CODINTR1,
  0 AS CODINTR,
  0 AS FLAG, -- NECESAR PE MACHETA DE PRELUARE DIN STOC,
  CODTRANSF1,
  NS.DATAACHIZ,
  NS.TIPDOCACHIZ,
  NIRCURENT.TIPNIR AS TIPINTRARESTOC,
  L.DENUMIRE AS LOCATIE,
  NS.RESTUM1,
  NS.RESTUM1 AS STOCUM1,
  0.0 AS PRELUATUM1,
  NS.RESTUM2,
  NS.RESTUM2 AS STOCUM2,
  0.0 AS PRELUATUM2,
  NS.CODGESTPROD,
  NS.SUBUNITATEA,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS FURNIZOR,
 NS.CODLOCATIE
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIRSER NSE            ON NSE.CODNIRSTOC        = NS.CODNIRSTOC
  LEFT OUTER JOIN NIR NIRCURENT         ON NIRCURENT.CODNIR      = NS.CODNIR        -- NIR-UL LINIEI DE STOC CURENTE
  LEFT OUTER JOIN NGEST G               ON G.CODGEST             = NIRCURENT.GEST        -- NIR-UL LINIEI DE STOC CURENTE
  LEFT OUTER JOIN NLOCATII L            ON L.CODLOCATIE          = NS.CODLOCATIE,
  (SELECT CODIOART, MG FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) IOALUNA

WHERE
((NS.REST &lt;&gt; 0) OR(NS.REST = 0 AND EXISTS(SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL WHERE CODNIRSTOC = NS.CODNIRSTOC)))
AND IOALUNA.CODIOART   = NS.CODIOART
AND IOALUNA.MG &lt;&gt; 5
AND IOALUNA.MG &lt;&gt; 3
AND (PKG_SELECTARTICOLE.EXCLUDSTOCDININTRAREA(NIRCURENT.CODINTR) = 0)
AND (PKG_SELECTARTICOLE.EXCLUDSTOCDINTRANSF1(NS.CODTRANSF1) = 0)
AND EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = NS.CODOBIECT)
AND PKG_NOMGEST.GESTIUNE_DEDICATA(NIRCURENT.GEST) &gt; 0
AND  PKG_GLOBALS.SUBUNITATEDOC_VALIDA(G.codsubunit) = 1
AND NVL(G.CODSUBUNIT, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5AD1CF3F5F1234FE5C21073B2CB9C42A531BABDE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_LUNA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSTOC, SUM(REST) REST, SUM(RESTUM1) RESTUM1,SUM(RESTUM2) RESTUM2
FROM (
  SELECT N.CODNIRSTOC, N.REST, N.RESTUM1, N.RESTUM2
  FROM NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
  WHERE N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
  UNION ALL -- NIRURI LUNA
  SELECT NS.CODNIRSTOC, NS.CANTNIR AS REST, NS.CANTUM1 AS RESTUM1, NS.CANTUM2 AS RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT  JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT  JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND trunc(N.DATANIR) &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC
    AND COALESCE(I.AN,T.AN) = PKG_GLOBALS.GETANTEMP
    AND COALESCE(I.LUNA,T.LUNA ) = PKG_GLOBALS.GETLUNATEMP
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
  UNION ALL
  SELECT
    L1.CODNIRSTOC,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANT ELSE -1 * L1.CANT END  REST,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -1 * L1.CANTUM1 END RESTUM1,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -1 * L1.CANTUM2 END RESTUM2
  FROM LIVR L
    INNER JOIN LIVR1 L1 ON L1.CODLIVR = L.CODLIVR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
  WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
	  AND trunc(L.DATALIVR) &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC
    AND COALESCE(I.AN,IES.AN,T.AN) = PKG_GLOBALS.GETANTEMP
    AND COALESCE(I.LUNA,IES.LUNA,T.LUNA ) = PKG_GLOBALS.GETLUNATEMP
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
)
GROUP BY CODNIRSTOC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_LUNA_PREC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3CE7AD5948607A8665AA63CC8E5360EAD37BB7FD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_LUNA_PREC (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT NL.CODNIRSTOC, NL.REST, NL.RESTUM1, NL.RESTUM2
FROM NIRLUNA NL
  INNER JOIN NIRSTOC NS ON NL.CODNIRSTOC = NS.CODNIRSTOC
  INNER JOIN IOART1 IO ON IO.CODIOART = NS.CODIOART
WHERE NL.AN = PKG_GLOBALS.GETANPRECEDENT AND NL.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
  AND (Coalesce(NL.REST, 0) &lt;&gt; 0 OR Coalesce(NL.RESTUM1, 0) &lt;&gt; 0 OR Coalesce(NL.RESTUM2, 0) &lt;&gt; 0)
  AND NL.AN * 12 + NL.LUNA BETWEEN IO.ALSTART AND IO.ALSTOP
  AND IO.MG &lt;&gt; 5</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_LUNA_SER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C112F3CE0AF01BB4A1F2EE600128B6BEF931B9F2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_LUNA_SER (
&quot;CODNIRSTOC&quot;,&quot;CODNIRSER&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT
  STOC.CODNIRSTOC, STOC.CODNIRSER,
  SUM(STOC.REST) REST,
  SUM(STOC.RESTUM1) RESTUM1,
  SUM(STOC.RESTUM2) RESTUM2
FROM (
  SELECT
    NS.CODNIRSTOC, NE.CODNIRSER,
    CASE WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.REST    ELSE NE.REST    END REST,
    CASE WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM1 ELSE NE.RESTUM1 END RESTUM1,
    CASE WHEN NVL(NE.CODNIRSER, 0) = 0 THEN N.RESTUM2 ELSE NE.RESTUM2 END RESTUM2
  FROM NIRLUNA N
    INNER JOIN NIRSTOC NS ON N.CODNIRSTOC = NS.CODNIRSTOC
    LEFT JOIN NIRSERLUNA NE ON N.CODNIRSTOC = NE.CODNIRSTOC AND N.AN = NE.AN AND N.LUNA = NE.LUNA
  WHERE N.AN = PKG_GLOBALS.GETANPRECEDENT AND N.LUNA = PKG_GLOBALS.GETLUNAPRECEDENTA
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
  UNION ALL -- NIRURI LUNA
  SELECT
    NS.CODNIRSTOC, NSE.CODNIRSER,
    CASE WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTNIR ELSE NSE.CANTNIR END REST,
    CASE WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM1 ELSE NSE.CANTUM1 END RESTUM1,
    CASE WHEN NVL(NSE.CODNIRSER, 0) = 0 THEN NS.CANTUM2 ELSE NSE.CANTUM2 END RESTUM2
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT JOIN NIRSER NSE ON NS.CODNIRSTOC = NSE.CODNIRSTOC
    LEFT JOIN INTRARI I ON I.CODINTR = N.CODINTR
    LEFT JOIN TRANSF T ON T.CODTRANSF = N.CODTRANSF
  WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 12, 13) AND  N.ANULAT = 0 AND N.OPERAT = 1
    AND trunc(N.DATANIR) &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC
    AND COALESCE(I.AN,T.AN) = PKG_GLOBALS.GETANTEMP
    AND COALESCE(I.LUNA,T.LUNA ) = PKG_GLOBALS.GETLUNATEMP
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
  UNION ALL
  SELECT
    NS.CODNIRSTOC, NSE.CODNIRSER,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANT    ELSE -L1.CANT    END REST,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM1 ELSE -L1.CANTUM1 END RESTUM1,
    CASE WHEN L.TIPLIVR = 15 THEN L1.CANTUM2 ELSE -L1.CANTUM2 END RESTUM2
  FROM LIVR1 L1
    INNER JOIN LIVR L ON L.CODLIVR = L1.CODLIVR
    INNER JOIN NIRSTOC NS ON NS.CODNIRSTOC = L1.CODNIRSTOC
    LEFT JOIN NIRSER NSE ON NSE.CODNIRSER = L1.CODNIRSER
    LEFT JOIN INTRARI I ON I.CODINTR = L.CODINTR
    LEFT JOIN IESIRI IES ON IES.CODIES = L.CODIES
    LEFT JOIN TRANSF T ON T.CODTRANSF = L.CODTRANSF
  WHERE L.TIPLIVR IN (1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15 ,16, 19, 20, 21, 23, 24) AND L.OPERAT = 1 AND L.ANULAT = 0
    AND trunc(L.DATALIVR) &lt;= PKG_LIST_SELFISAMAG.GETDATASTOC
    AND COALESCE(I.AN,IES.AN,T.AN) = PKG_GLOBALS.GETANTEMP
    AND COALESCE(I.LUNA,IES.LUNA,T.LUNA ) = PKG_GLOBALS.GETLUNATEMP
    AND (PKG_LIST_SELFISAMAG.isToateArt = 1 OR ns.codobiect IN (SELECT valoare FROM tmp_manevra_liste tmp WHERE filtru = &apos;CODOBIECT&apos;))
    AND (PKG_LIST_SELFISAMAG.getNumToateCont = 1 OR NS.CODIOART IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODIOART&apos;) )
) STOC
GROUP BY STOC.CODNIRSTOC, STOC.CODNIRSER
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_MODIF_MEDEX</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D81D47AD49C6B6CE25269327F70D457FA654226D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_MODIF_MEDEX (
&quot;DENOBIECT&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;DENUM&quot;,&quot;CODNIRSTOC&quot;,&quot;UMSEC&quot;,&quot;CODOBIECT&quot;,&quot;CODIOART&quot;,&quot;GEST&quot;,&quot;PRETACHIZ&quot;,&quot;PRET&quot;,&quot;ADAOS&quot;,&quot;TVA&quot;,&quot;TIPSERIE&quot;,&quot;STOC&quot;,&quot;PROCENTADAOS&quot;,&quot;INTRATLA&quot;,&quot;TG&quot;,&quot;PUMAXIMAL&quot;,&quot;CODPART&quot;,&quot;SERIE&quot;,&quot;CODNIRSER&quot;,&quot;CODSERIE&quot;,&quot;DATAACHIZ&quot;,&quot;TIPDOCACHIZ&quot;,&quot;TIPINTRARESTOC&quot;,&quot;LOCATIE&quot;,&quot;FURNIZOR&quot;,&quot;CODTVA&quot;,&quot;PROCTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;TIPARTICOL&quot;,&quot;TERMENPLATA&quot;,&quot;ADAOSEXCEPTIE&quot;,&quot;DENFURN&quot;,&quot;SUPLIMENT&quot;,&quot;DEN_CARSUPART&quot;,&quot;TIPCOMPENSARE&quot;,&quot;DEN_GEST&quot;,&quot;DEN_IOART&quot;,&quot;PRODUCATOR&quot;,&quot;ROTLEI&quot;) AS
SELECT
  O.DENUMIRE AS DENOBIECT,
  O.CODEXTERN,
  O.CODINTERN,
  U1.DEN_UM1 AS DENUM,
  NS.CODNIRSTOC,
  NS.UMSEC,
  NS.CODOBIECT,
  NS.CODIOART,
  NIRCURENT.GEST,
  NS.PRET - NVL( NS.ADAOS, 0) AS PRETACHIZ,
  NS.PRET  AS PRET,
  NVL(NS.ADAOS, 0) AS ADAOS,
  NS.TVA,
  NS.TIPSERIE,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN NSE.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSER = NSE.CODNIRSER), 0)
     ELSE NS.REST - NVL((SELECT SUM(CANT) FROM STOCLOCK WHERE CODNIRSTOC = NS.CODNIRSTOC) , 0)
   END
   ) AS STOC,
  NS.PROCENTADAOS,
  NIRCURENT.DATANIR AS INTRATLA,
  NS.TG,
  NS.PUMAXIMAL,
  NS.FURN AS CODPART,
  (CASE
    WHEN NS.TIPSERIE &gt; 0 THEN (SELECT SERIE FROM NSERII WHERE CODSERIE = NSE.CODSERIE)
    ELSE &apos;&apos;
   END
  ) AS SERIE,
  NVL(NSE.CODNIRSER, 0) CODNIRSER,
  NSE.CODSERIE,
  NS.DATAACHIZ,
  NS.TIPDOCACHIZ,
  NIRCURENT.TIPNIR AS TIPINTRARESTOC,
  L.DENUMIRE AS LOCATIE,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS FURNIZOR,
  NART1LUNA.CODTVA,
  NVL(TVALUNA.PROCENT, -1) AS PROCTVA,
  NART1LUNA.CODACCIZE,
  NART1LUNA.CODTAXA1,
  NART1LUNA.CODTAXA2,
  A.TIPARTICOL,
  O.TERMENPLATA,
  O.ADAOSEXCEPTIE,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS DENFURN,
  &apos; &apos; AS SUPLIMENT,
  CAR.DEN_CARSUPART,
  NARTOBJ1LUNA.TIPCOMPENSARE,
  G.DEN_GEST,
  IOART.DEN_IOART,
  (SELECT DEN_PART FROM NPART WHERE CODPART = O.CODPRODUCATOR) AS PRODUCATOR,
  O.ROTUNJIRE AS ROTLEI
FROM
  NIRSTOC NS
  LEFT OUTER JOIN NIRSER NSE            ON NSE.CODNIRSTOC        = NS.CODNIRSTOC
  LEFT OUTER JOIN NLOCATII L            ON L.CODLOCATIE          = NVL(NS.CODLOCATIE, 0),
  NIR NIRCURENT,
  NGEST G,
  NARTOBJ O
  LEFT OUTER JOIN
  (SELECT CODOBIECT, TIPCOMPENSARE FROM NARTOBJ1 O1  WHERE
  O1.ANSTART * 12 + O1.LUNASTART =
  (SELECT MAX(O11.ANSTART * 12 + O11.LUNASTART) FROM NARTOBJ1 O11
  WHERE
     O11.CODOBIECT = O1.CODOBIECT AND O11.ANSTART * 12 + O11.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) NARTOBJ1LUNA ON NARTOBJ1LUNA.CODOBIECT = O.CODOBIECT
  LEFT OUTER JOIN NCARSUPART CAR ON CODCARSUPART = O.CODCARACT,
  NART A
  LEFT OUTER JOIN
  (SELECT CODARTICOL, CODTVA, CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
   A1.ANSTART * 12 + A1.LUNASTART =
   (SELECT MAX(A11.ANSTART * 12 + A11.LUNASTART) FROM NART1 A11
    WHERE
       A11.CODARTICOL = A1.CODARTICOL AND A11.ANSTART * 12 + A11.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
     ) NART1LUNA ON NART1LUNA.CODARTICOL = A.CODARTICOL
  LEFT OUTER JOIN
  (
      SELECT N.CODTVA,N1.CODTVA1,N.DEN_TVA,N1.PROCENT,N1.CODCONTDED,N1.CODCONTCOLE,N1.CODCONTNEEX
      FROM NTVA N LEFT JOIN NTVA1 N1
      ON 	N.CODTVA = N1.CODTVA
         WHERE N1.ANSTART * 12 + N1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 NT1
                                                   WHERE NT1.CODTVA = N1.CODTVA AND
      					     ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU )
  ) TVALUNA ON TVALUNA.CODTVA = NART1LUNA.CODTVA,
  NUM1 U1,
  IOART,
  (SELECT CODIOART, MG FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) IOALUNA
WHERE
  NS.REST &lt;&gt; 0
  AND NIRCURENT.CODNIR = NS.CODNIR
  AND G.CODGEST        = NIRCURENT.GEST
  AND O.CODOBIECT      = NS.CODOBIECT
  AND A.CODARTICOL     = O.CODARTICOL
  AND U1.CODUM1        = NS.UMSEC
  AND IOART.CODIOART   = NS.CODIOART
  AND IOALUNA.CODIOART = NS.CODIOART
  AND (IOALUNA.MG &lt;&gt; 5)AND(IOALUNA.MG &lt;&gt; 3)
  AND PKG_NOMGEST.GESTIUNE_DEDICATA(NIRCURENT.GEST)  &gt; 0
  AND NVL(G.CODSUBUNIT, 1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(G.CODSUBUNIT, 1), PKG_GLOBALS.GETSUBUNITATE)
  AND EXISTS (SELECT CODUNIC FROM TMP_MANEVRA WHERE CODUNIC = NS.CODOBIECT) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_PT_REZERVARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D5BDB9628AE1A779271759250F64263E9C421EF6</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_PT_REZERVARI (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;DEN_UM&quot;,&quot;CODOBIECT&quot;,&quot;STOC&quot;,&quot;INTRATLA&quot;,&quot;LOCATIE&quot;,&quot;FURNIZOR&quot;,&quot;NIRSTOC&quot;,&quot;DEN_GEST&quot;,&quot;CODGEST&quot;,&quot;CODIOART&quot;,&quot;DEN_IOART&quot;) AS
SELECT
  NSE.CODNIRSER,
  NS.CODNIRSTOC,
  NUM.DEN_UM,
  NS.CODOBIECT,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN ROUND( NSE.REST, 10)
     ELSE ROUND( NS.REST, 10)
   END
  ) - nvl(REZ.Cant, 0) - nvl(Blocat.Cant,0) AS STOC,
  NIRCURENT.DATANIR AS INTRATLA,
  L.DENUMIRE AS LOCATIE,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END AS FURNIZOR,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END||&apos; &apos;||NIRCURENT.DATANIR AS NIRSTOC,
  G.Den_Gest,
  G.CodGest,
  IOA.CODIOART,
  IOA.DEN_IOART
FROM
  NIRSTOC NS
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
  INNER JOIN NUM ON ART.UM = NUM.CODUM
  LEFT OUTER JOIN NIRSER NSE            ON NSE.CODNIRSTOC        = NS.CODNIRSTOC
  LEFT OUTER JOIN (select codnirstoc, nvl(codnirser,0) codnirser, sum(rest) cant from rezervats group by codnirstoc, nvl(codnirser,0)) REZ ON REZ.CodNirStoc = NS.Codnirstoc AND nvl(REZ.CodNirSer,0) = nvl(NSE.CodNirSer,0)
  LEFT OUTER JOIN (select codnirstoc, codnirser, sum(cant) cant from stoclock group by codnirstoc, codnirser) Blocat ON Blocat.CodNirStoc = NS.Codnirstoc AND nvl(Blocat.CodNirSer,0) = nvl(NSE.CodNirSer,0)
  LEFT OUTER JOIN NIR NIRCURENT         ON NIRCURENT.CODNIR      = NS.CODNIR        -- NIR-UL LINIEI DE STOC CURENTE
  LEFT OUTER JOIN NGEST G               ON G.CODGEST             = NIRCURENT.GEST        -- NIR-UL LINIEI DE STOC CURENTE
  LEFT OUTER JOIN NLOCATII L            ON L.CODLOCATIE          = NS.CODLOCATIE,
  (SELECT CODIOART, MG FROM IOART1 IO1  WHERE
   IO1.ANSTART * 12 + IO1.LUNASTART =
  (SELECT MAX(IO2.ANSTART * 12 + IO2.LUNASTART) FROM IOART1 IO2
   WHERE
    IO2.CODIOART = IO1.CODIOART AND IO2.ANSTART * 12 + IO2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
   ) IOALUNA
   LEFT OUTER JOIN IOART IOA ON IOALUNA.CODIOART = IOA.CODIOART
WHERE
((NS.REST &lt;&gt; 0) OR(NS.REST = 0 AND EXISTS(SELECT CODNIRSTOC FROM TMP_LIVR1_INITIAL WHERE CODNIRSTOC = NS.CODNIRSTOC)))
AND IOALUNA.CODIOART   = NS.CODIOART
AND IOALUNA.MG &lt;&gt; 5
AND IOALUNA.MG &lt;&gt; 3
and G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE
and (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN ROUND( NSE.REST, 10)
     ELSE ROUND( NS.REST, 10)
   END
  ) - nvl(REZ.Cant, 0) &gt; 0

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_SERII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>06CB0A4FDA89A43823444B3F00E54BC9D0A217BB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_SERII (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;DEN_UM&quot;,&quot;SERIE&quot;,&quot;DEN_GEST&quot;,&quot;STOC&quot;) AS
SELECT
  NSE.CODNIRSER,
  NS.CODNIRSTOC,
  NUM.DEN_UM,
  SER.SERIE,
  G.DEN_GEST,
  (CASE
     WHEN NS.TIPSERIE &gt; 0 THEN ROUND( NSE.REST, 10)
     ELSE ROUND( NS.REST, 10)
   END
  ) - nvl(REZ.Cant, 0) - nvl(Blocat.Cant,0) AS STOC
FROM
  NIRSTOC NS
  INNER JOIN NARTOBJ OBJ ON NS.CODOBIECT = OBJ.CODOBIECT
  INNER JOIN NART ART ON OBJ.CODARTICOL = ART.CODARTICOL
  INNER JOIN NUM ON ART.UM = NUM.CODUM
  INNER JOIN NIRSER NSE            ON NSE.CODNIRSTOC   = NS.CODNIRSTOC
  INNER JOIN NSERII SER            ON SER.CODSERIE     = NSE.CODSERIE
  INNER JOIN NIR NIRCURENT         ON NIRCURENT.CODNIR = NS.CODNIR
  INNER JOIN NGEST G               ON G.CODGEST        = NIRCURENT.GEST
  LEFT OUTER JOIN (select codnirstoc, codnirser, sum(rest) cant from rezervats group by codnirstoc, codnirser) REZ ON REZ.CodNirStoc = NS.Codnirstoc AND REZ.CodNirSer = NSE.CodNirSer
  LEFT OUTER JOIN (select codnirstoc, codnirser, sum(cant) cant from stoclock group by codnirstoc, codnirser) Blocat ON Blocat.CodNirStoc = NS.Codnirstoc AND Blocat.CodNirSer = NSE.CodNirSer
WHERE
  NS.CodObiect = pkg_selectarticole.GETOBIECTANALIZAT
  and (G.CODSUBUNIT = PKG_GLOBALS.GETSUBUNITATE OR PKG_GLOBALS.GETSUBUNITATE = 1)
  and (CASE
         WHEN NS.TIPSERIE &gt; 0 THEN ROUND( NSE.REST, 10)
         ELSE ROUND( NS.REST, 10)
       END
      ) - nvl(REZ.Cant, 0) &gt; 0

 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_WEBSERVER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B4D6E13C8C95EA9E6C714094C089A1221AC71E54</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_WEBSERVER (
&quot;CODOBIECT&quot;,&quot;GEST&quot;,&quot;FURN&quot;,&quot;CODIOART&quot;,&quot;STOC&quot;,&quot;REZERVAT&quot;) AS
SELECT
  CODOBIECT,
  GEST,
  0 AS FURN,
  0 AS CODIOART,
  SUM(REST) AS STOC,
  SUM(NVL(REZERVAT, 0)) AS REZERVAT
FROM (
  SELECT
    NS.CODOBIECT,
    N.GEST,
    REST,
    (SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC) REZERVAT
  FROM NIRSTOC NS
    INNER JOIN NIR N ON N.CODNIR = NS.CODNIR
    LEFT JOIN TMP_IOART_LUNA IO ON IO.CODIOART = NS.CODIOART
  WHERE Coalesce(IO.MG, 0) &lt;&gt; 5
)
GROUP BY CODOBIECT, GEST</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_WEBSERVER_IOART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>78FD1826B9F87C9EFF2C44425319A87D5B5D11B7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_WEBSERVER_IOART (
&quot;CODOBIECT&quot;,&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;FURN&quot;,&quot;STOC&quot;,&quot;REZERVAT&quot;) AS
SELECT
  CODOBIECT,
  GEST,
  CODIOART,
  0 AS FURN,
  SUM(REST) AS STOC,
  SUM(NVL(REZERVAT, 0)) AS REZERVAT
FROM
(
SELECT
  NS.CODOBIECT,
  N.GEST,
  NS.CODIOART,
  REST,
  (SELECT SUM(REST) FROM REZERVATS R WHERE R.CODNIRSTOC = NS.CODNIRSTOC) REZERVAT
FROM
 NIRSTOC NS,
 NIR N
WHERE
 N.CODNIR = NS.CODNIR
)
GROUP BY CODOBIECT, GEST, CODIOART
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TARIFEMAN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3F31E26C85D20ED373D842848675E32CD3B385B2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TARIFEMAN (
&quot;CODTARIF&quot;,&quot;DENUMIRE&quot;,&quot;ACTIV&quot;,&quot;TARIF&quot;,&quot;CODTARIF1&quot;,&quot;CODEXTERN&quot;,&quot;CODMONEDA&quot;,&quot;DEN_MONEDA&quot;) AS
SELECT
  T.CODTARIF,
  T.DENUMIRE,
  NVL((SELECT
         MAX(ANSTART * 12 + LUNASTART) FROM TARIFEMAN1 T1
       WHERE
         CODTARIF = T.CODTARIF AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU), 0)
         AS ACTIV,
  TARIFLUNA.TARIF,
  TARIFLUNA.CodTarif1,
  T.CODEXTERN,
  COALESCE(T.CODMONEDA,0) CODMONEDA,
  M.DEN_MONEDA
FROM
  TARIFEMAN T
  LEFT OUTER JOIN
  (SELECT T1.CodTarif1, T1.CODTARIF, T1.TARIF FROM TARIFEMAN1 T1
   WHERE
    T1.ANSTART * 12 + T1.LUNASTART =
      (SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART) FROM TARIFEMAN1 T2
       WHERE
        T2.CODTARIF = T1.CODTARIF AND T2.AnStart * 12 + T2.LUNAStart &lt;= PKG_GLOBALS.ANLUNALUCRU
       )
  ) TARIFLUNA ON TARIFLUNA.CODTARIF = T.CODTARIF
  LEFT OUTER JOIN NMONEDE M ON M.CODMONEDA = COALESCE(T.CODMONEDA,0)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TESATURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>947317731E3990E53339DE6CFE1B60782A379153</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TESATURI (
&quot;CODTESATURA&quot;,&quot;DENUMIRE&quot;,&quot;COMPOZITIE&quot;,&quot;MASASPECIFICA&quot;,&quot;LEGATURA&quot;,&quot;DESIMEU&quot;,&quot;DESIMEB&quot;) AS
SELECT
codtesatura,
denumire ,
compozitie ,
masaspecifica,
legatura ,
desimeU,
desimeB
FROM TESATURI
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TEST</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C3E0B870CBFA36CA84E9915B7B3563548092C951</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TEST (
&quot;CODSERVFACT&quot;,&quot;VALOARE&quot;) AS
SELECT CODSERVFACT, SUM(VALOARE) AS VALOARE
FROM
(
    SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE FROM
    (
      SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2
      FROM
      NARTOBJ O
      LEFT OUTER JOIN
       (SELECT CODARTICOL,  CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
        A1.AnStart * 12 + A1.LunaStart =
       (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
        WHERE
         A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
        ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
      WHERE
      CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_TAXE_FACTURARE
    ) INFOOBIECT,
    (
      SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT
      FROM
       NTAXE1 T1
      WHERE T1.ANSTART * 12 + T1.LUNASTART = ( SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART)
      FROM NTAXE1 T2
      WHERE T2.CODTAXA = T1.CODTAXA AND T2.ANSTART * 12 + T2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 +  PKG_GLOBALS.GETLUNALUCRU) AND
      FACTURABIL = 1 AND NVL(CODSERVFACT, 0) &lt;&gt; 0
    ) TAXELUNA
    WHERE
     INFOOBIECT.CODACCIZE = TAXELUNA.CODTAXA OR
     INFOOBIECT.CODTAXA1  = TAXELUNA.CODTAXA OR
     INFOOBIECT.CODTAXA2  = TAXELUNA.CODTAXA
)
GROUP BY
CODSERVFACT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TIPLUCRARISA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>486EBEAE15496ABF55F53C35F8A5065044FC7041</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TIPLUCRARISA (
&quot;CODTIPLUCRARE&quot;,&quot;DENUMIRE&quot;,&quot;ARTSERVFACT&quot;,&quot;CLASALUCRARI&quot;,&quot;DEN_GEST&quot;,&quot;DENINTERV&quot;,&quot;CODINTERVENTIE&quot;) AS
select T.CODTIPLUCRARE,T.DENUMIRE,T.ARTSERVFACT,T.CLASALUCRARI, N.Den_gest,IA.Denumire DenInterv, T.CodInterventie from TIPLUCRARISA T
Left join NGest N on N.CodGest = T.CodGest
Left join ninterventiiauto IA on IA.CODINTERVENTIIAUTO = T.CodInterventie
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TIPSEDII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C902411C3742AA347F21E59EF5859B35EA87C7A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TIPSEDII (
&quot;CODTIPSEDIU&quot;,&quot;DENUMIRE&quot;,&quot;ICLASA&quot;) AS
select Codtipsediu, Denumire, IClasa
    from NTipSedii 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TRANSPORT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6060383941BBA78955D0EA089227C25E54ABB32B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TRANSPORT (
&quot;CODTRANSPORT&quot;,&quot;DATATRANSPORT&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SUBUNITATE&quot;,&quot;INDICATIV&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALOARE&quot;,&quot;TIPREPART&quot;,&quot;CODPARCAUTO&quot;,&quot;CODSOFER&quot;,&quot;COLETE&quot;,&quot;REP_TRANSF&quot;,&quot;REP_SUBUNIT&quot;,&quot;DEN_SUBUNITATE&quot;) AS
select
CODTRANSPORT,
DATATRANSPORT,
USERID,
DATACREARE,
SUBUNITATE,
INDICATIV,
OPERAT,
BLOCAT,
ANULAT,
AN,
LUNA,
VALOARE,
TIPREPART,
CODPARCAUTO,
CODSOFER,
COLETE,
REP_TRANSF,
REP_SUBUNIT,
s.den_subunit as den_subunitate
from transport t
     inner join nsubunit s on t.subunitate = s.codsubunit
where nvl(t.subunitate,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitate,1),pkg_globals.GETSUBUNITATE)
and nvl(t.tip, 0) = 0 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TRANSPORTDVI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4B0EB6B92E8F53A720804A31010037B7E4D15FD5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TRANSPORTDVI (
&quot;CODTRANSPORT&quot;,&quot;DATATRANSPORT&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SUBUNITATE&quot;,&quot;INDICATIV&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALOARE&quot;,&quot;TIPREPART&quot;,&quot;CODPARCAUTO&quot;,&quot;CODSOFER&quot;,&quot;COLETE&quot;,&quot;REP_TRANSF&quot;,&quot;REP_SUBUNIT&quot;,&quot;DEN_SUBUNITATE&quot;) AS
select &quot;CODTRANSPORT&quot;,&quot;DATATRANSPORT&quot;,&quot;USERID&quot;,&quot;DATACREARE&quot;,&quot;SUBUNITATE&quot;,&quot;INDICATIV&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;ANULAT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;VALOARE&quot;,&quot;TIPREPART&quot;,&quot;CODPARCAUTO&quot;,&quot;CODSOFER&quot;,&quot;COLETE&quot;,&quot;REP_TRANSF&quot;,&quot;REP_SUBUNIT&quot;,&quot;DEN_SUBUNITATE&quot; from
(select
CODTRANSPORT,
DATATRANSPORT,
USERID,
DATACREARE,
SUBUNITATE,
INDICATIV,
OPERAT,
BLOCAT,
ANULAT,
AN,
LUNA,
VALOARE,
TIPREPART,
CODPARCAUTO,
CODSOFER,
COLETE,
REP_TRANSF,
REP_SUBUNIT,
s.den_subunit den_subunitate
from transport t
     inner join nsubunit s on t.subunitate = s.codsubunit
where nvl(t.subunitate,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitate,1),pkg_globals.GETSUBUNITATE)
and nvl(t.tip, 0) = 1 ) 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TRANZ_TREZ</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F0E9B78667BF27C13C08B24EA01BF8647DF7F163</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TRANZ_TREZ (
&quot;CODTREZOR1&quot;,&quot;CODTREZOR&quot;,&quot;INDEXLOCAL&quot;,&quot;TIPTRANZ&quot;,&quot;CARNETDOC&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALDOC&quot;,&quot;CURS&quot;,&quot;COMISION&quot;,&quot;OBIECTTRANZ&quot;,&quot;CODPART&quot;,&quot;TIPDECONT&quot;,&quot;DATADECONT&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;OBS&quot;,&quot;INITIALIZARI&quot;,&quot;AGENT&quot;,&quot;ANULAT&quot;,&quot;DOBIECTTRANZ&quot;,&quot;DTIPTRANZ&quot;,&quot;BENEFPLATITOR&quot;,&quot;USERID&quot;) AS
SELECT
 T1.&quot;CODTREZOR1&quot;,T1.&quot;CODTREZOR&quot;,T1.&quot;INDEXLOCAL&quot;,T1.&quot;TIPTRANZ&quot;,T1.&quot;CARNETDOC&quot;,T1.&quot;DOC&quot;,T1.&quot;NRDOC&quot;,T1.&quot;DATADOC&quot;,T1.&quot;VALDOC&quot;,T1.&quot;CURS&quot;,T1.&quot;COMISION&quot;,T1.&quot;OBIECTTRANZ&quot;,T1.&quot;CODPART&quot;,T1.&quot;TIPDECONT&quot;,T1.&quot;DATADECONT&quot;,T1.&quot;AN&quot;,T1.&quot;LUNA&quot;,T1.&quot;OBS&quot;,T1.&quot;INITIALIZARI&quot;,T1.&quot;AGENT&quot;,T1.&quot;ANULAT&quot;,
 (CASE
    WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 0       THEN &apos;Furnizor &apos;
    WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1       THEN &apos;Retur Client &apos;
    WHEN TIPTRANZ IN (0, 1) AND OBIECTTRANZ = 3 THEN &apos;Viramente interne &apos;
    WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 0       THEN &apos;Client &apos;
    WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1       THEN &apos;Retur Furnizor &apos;
    WHEN OBIECTTRANZ = 2                        THEN &apos;Personal angajat &apos;
    WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 4       THEN &apos;Servicii, articole fara NIR...&apos;
    WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 4       THEN &apos;Direct pe venituri...&apos;
    WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 5       THEN &apos;Datorii, taxe, impozite &apos;
    WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 5       THEN &apos;Imprumuturi, subventii &apos;
    WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 6       THEN &apos;Dobanda la depozit&apos;
  END
 ) AS DOBIECTTRANZ,
 (CASE
    WHEN TIPTRANZ = 0 THEN &apos;Plata&apos;
    ELSE &apos;Incasare&apos;
  END
 ) AS DTIPTRANZ,

 (CASE
     WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 0       THEN (SELECT DEN_PART FROM NPART P WHERE CODPART = T1.CODPART)
     WHEN TIPTRANZ = 0 AND OBIECTTRANZ = 1       THEN (SELECT DEN_PART FROM NPART P WHERE CODPART = T1.CODPART)
     WHEN TIPTRANZ IN (0, 1) AND OBIECTTRANZ = 3 THEN (SELECT B.SIMBOL || &apos; - &apos; || NRCONT FROM NBANKCONT BC LEFT OUTER JOIN NBANK B ON B.CODBANK = BC.CODBANK  WHERE CODBANKCONT = T1.CODPART)
     WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 0       THEN  NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T1.CODPART), &apos;&apos;)
     WHEN TIPTRANZ = 1 AND OBIECTTRANZ = 1       THEN  NVL((SELECT DEN_PART FROM NPART P WHERE CODPART = T1.CODPART), &apos;&apos;)
     WHEN OBIECTTRANZ = 2                        THEN  NVL((SELECT NUME || &apos; &apos; || PRENUME FROM NPERS P WHERE CODPERS = T1.CODPART), &apos;&apos;)
    END
 ) BENEFPLATITOR,
 T.USERID
FROM
  TREZOR T,
  TREZOR1 T1
WHERE
  (PKG_GLOBALS.GetCodDocCasaBanca &gt; 0 and T.Codtrezor = PKG_GLOBALS.GetCodDocCasaBanca)
	or
  (TIPDOC = PKG_GLOBALS.GetTipDocCasaBanca
   AND T.AN * 12 + T.LUNA = PKG_GLOBALS.AnLunaLucru
   AND T1.CODTREZOR = T.CODTREZOR
 	 AND nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE))
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>47E330CA932F910AC54178231F3FCDA086A288F0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TREZOR (
&quot;CODTREZOR&quot;,&quot;DATADOC&quot;,&quot;NUMEDOC&quot;,&quot;SIMBOL&quot;,&quot;NRCONT&quot;,&quot;FILIALA&quot;,&quot;SIMBMONEDA&quot;,&quot;OPERAT&quot;,&quot;BLOCAT&quot;,&quot;TIPDOC&quot;) AS
SELECT
  T.CODTREZOR, T.DATADOC, T.NUMEDOC, NB.SIMBOL, BC.NRCONT, BC.FILIALA,
  M.SIMBOL AS SIMBMONEDA, T.OPERAT, T.BLOCAT, T.TIPDOC
FROM
  TREZOR T
  LEFT OUTER JOIN NBANKCONT BC ON BC.CODBANKCONT = T.CODBANCA
  LEFT OUTER JOIN NBANK     NB ON NB.CODBANK     = BC.CODBANK
  LEFT OUTER JOIN NMONEDE  M ON M.CODMONEDA      = BC.CODMONEDA
WHERE
  TIPDOC = PKG_GLOBALS.GetTipDocCasaBanca AND
	nvl(t.subunitatea,1) = decode(pkg_globals.GETSUBUNITATE,1,nvl(t.subunitatea,1),pkg_globals.GETSUBUNITATE) AND
	AN * 12 + LUNA = PKG_GLOBALS.AnLunaLucru 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TRIGAR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>513C0581C487E075E9820461A6247CE4E854378E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TRIGAR (
&quot;CODTRIGAR&quot;,&quot;TABLENAME&quot;,&quot;FIELDNAME&quot;,&quot;INACTIV&quot;,&quot;OBS&quot;) AS
SELECT
t.CodTrigar, t.TableName, string_agg(t1.Fieldname)Fieldname, coalesce(t.inactiv,0) inactiv, t.obs
From Trigar T
left join TRIGAR1 T1 on T1.Codtrigar=T.CodTrigar
group by t.CodTrigar, t.TableName,coalesce(t.inactiv,0),t.obs
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TVA_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2A933667D61AC18D3445CCDB2ACD52C6354B7F41</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TVA_LUNA (
&quot;CODOBIECT&quot;,&quot;DENOBIECT&quot;,&quot;CODTVA&quot;,&quot;PROCENT&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;) AS
SELECT
o.codobiect,
PKG_SELECTARTICOLE.GETDENOBIECTEXT(O.CODOBIECT) AS DENOBIECT,
N1.CODTVA,
TV1.PROCENT,N1.codtaxa1,n1.codtaxa2
FROM
NARTOBJ O,
NART A
LEFT OUTER JOIN
(SELECT CODARTICOL, CODTVA,codtaxa1,codtaxa2 FROM NART1 A1
 WHERE
  A1.ANSTART * 12 + LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NART1 A2 WHERE A1.CODARTICOL = A2.CODARTICOL AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
) N1 ON N1.CODARTICOL = A.CODARTICOL
 LEFT OUTER JOIN
(SELECT CODTVA, PROCENT FROM NTVA1 T1
 WHERE
 T1.ANSTART * 12 + T1.LUNASTART = (SELECT MAX(ANSTART * 12 + LUNASTART) FROM NTVA1 T2 WHERE T1.CODTVA = T2.CODTVA AND ANSTART * 12 + LUNASTART &lt;= PKG_GLOBALS.ANLUNALUCRU)
 ) TV1 ON TV1.CODTVA = N1.CODTVA
WHERE
O.CODARTICOL = A.CODARTICOL
ORDER BY DENOBIECT 
 </TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_UMSEC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E04389063E316E8CC361F15AA57AC6ABDE6500AA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_UMSEC (
&quot;CODUM1&quot;,&quot;CODUM&quot;,&quot;SECUNDARA&quot;,&quot;DEN_UM1&quot;,&quot;PARITATE&quot;,&quot;ZECIMALE&quot;,&quot;OBS&quot;) AS
SELECT CodUM1, CodUM, Secundara, Den_UM1, Paritate, Zecimale, Obs
FROM NUM1
WHERE PKG_SELECTARTICOLE.ConditieUMPrincipala(CodUm) = 1 and COALESCE(INACTIV,0) = 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_CONTRACTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>203A0F52277381D84CEE15E34669DFF8E87ADA35</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_CONTRACTE (
&quot;CODCONTRACT&quot;,&quot;TIPDOC&quot;,&quot;CONTR_NR&quot;,&quot;CONTR_DATA&quot;,&quot;CONTR_DATAI&quot;,&quot;CONTR_DATAS&quot;,&quot;NOTACREDIT_DATAI&quot;,&quot;NOTACREDIT_DATAS&quot;,&quot;FACT&quot;,&quot;FACT_NR&quot;,&quot;FACT_DATA&quot;,&quot;PARTENER&quot;,&quot;ARTICOL&quot;,&quot;CONT&quot;,&quot;UM&quot;,&quot;CANT_FACT&quot;,&quot;CANT_CONTR&quot;,&quot;PRET_ORIGINAL&quot;,&quot;PRET_UNITAR&quot;,&quot;PRET_UNITAR_CU_DISCOUNT&quot;,&quot;VALOARE&quot;,&quot;VALTVA&quot;,&quot;PROCTVA&quot;,&quot;CONTR_TIP&quot;,&quot;SUBUNITATEA&quot;,&quot;CONTR_CADRU&quot;,&quot;CODCONTRCADRU&quot;,&quot;CANTCONTRACTCADRU&quot;) AS
SELECT
c.codcontract CodContract,
c.tipdoc TipDoc,
c.NrDoc Contr_Nr,
c.Datadoc Contr_Data,
c.DataStart Contr_DataI,
c.DataStop Contr_DataS,
nc.datastart NotaCredit_DataI,
nc.datastop NotaCredit_DataS,
i.prefixdoc Fact,
i.nrdoc Fact_Nr,
i.datadoc Fact_Data,
p.den_part Partener,
o.denumire Articol,
ncont.simbol Cont,
CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN &apos;&apos; ELSE um.den_um1 END UM,
i1.cant/NVL(um.paritate,1) Cant_Fact,
c1.cant/NVL(umc.paritate,1) Cant_Contr,
i1.pretorig*um.paritate Pret_Original,
i1.pu*um.paritate Pret_Unitar,
i1.pretorig*um.paritate*Decode(i1.coefdiscmaj,0,1,NULL,1,i1.coefdiscmaj) Pret_Unitar_Cu_discount,
CASE WHEN i1.tiplinie IN (&apos;T&apos;,&apos;G&apos;) THEN i1.restfact ELSE i1.cant * i1.pu END VALOARE,
i1.tva VALTVA,
CASE
WHEN NVL(i1.tva,0) = 0 THEN 0
WHEN i.tipdoc IN (16,21) AND i1.pu * i1.cant = NVL(i1.tva,0) THEN 0
WHEN i.tipdoc IN (16,21) THEN NVL(i1.tva,0) / decode( (i1.pu * i1.cant-NVL(i1.tva,0)),0,1,(i1.pu * i1.cant-NVL(i1.tva,0)) )
WHEN i1.pu * i1.cant = 0 THEN 0
ELSE NVL(i1.tva,0) / decode ( (i1.pu * i1.cant),0,1,(i1.pu * i1.cant) )
END * 100 PROCTVA,
CASE
WHEN (select count(*) from contract cop where cop.codgeneric = c.codcontract) &gt; 0 THEN &apos;CADRU&apos;
WHEN case when coalesce(c.codgeneric,0) &gt; 0 then 1 else 0 end &gt; 0 THEN &apos;SUBCONTRACT&apos; ELSE &apos;NORMAL&apos;
END Contr_Tip,
SB.DEN_SUBUNIT SUBUNITATEA,
CDR.NRDOC||&apos;/&apos;||TO_CHAR(CDR.DATADOC,&apos;DD.MM.YYYY&apos;) CONTR_CADRU,C.CODGENERIC CODCONTRCADRU,
CASE WHEN CDR1.CODCONTRACT1 IS NULL THEN C1.CANT ELSE CDR1.CANT END CANTCONTRACTCADRU
FROM contract c
LEFT JOIN contract1 c1 ON c1.codcontract = c.codcontract-c.codcontract
LEFT JOIN contract2 c2 ON c2.codcontract = c.codcontract
LEFT JOIN notecredit nc ON nc.codncredit = c2.coddoc AND nc.tipdoc = c2.tipdoc
LEFT JOIN notecreditfact ncf ON ncf.codncredit = nc.codncredit
LEFT JOIN iesiri i ON i.codies = ncf.coddoc AND i.tipdoc = ncf.tipdoc
LEFT JOIN iesiri1 i1 ON i1.codies = i.codies
LEFT JOIN npart p ON p.codpart = i.partener
LEFT JOIN nclasep clsp on p.codclasa = clsp.codclasep
LEFT JOIN npers agent on agent.codpers = c.agent
LEFT JOIN nartobj o ON o.codobiect = i1.codobiect
LEFT JOIN num1 um ON um.codum1 = i1.umsec
LEFT JOIN num1 umc ON umc.codum1 = c1.umsec
LEFT JOIN ncont ON ncont.codcont = Coalesce(i1.contserv,i1.contdiscount,0)
LEFT JOIN NSUBUNIT SB ON SB.CODSUBUNIT = C.SUBUNITATEA
LEFT JOIN CONTRACT CDR ON CDR.CODCONTRACT = C.CODGENERIC
LEFT JOIN CONTRACT1 CDR1 ON CDR1.CODCONTRACT = CDR.CODCONTRACT AND (C1.CODCONTR1CADRU = CDR1.CODCONTRACT OR C1.CODOBIECT = CDR1.CODOBIECT)
WHERE c.tipdoc = 27 AND c.operat = 1 AND c.anulat = 0 AND C.SUBUNITATEA = 2
UNION ALL
SELECT
distinct c.codcontract,
c.tipdoc,
c.NrDoc Contr_Nr,
c.Datadoc Contr_Data,
c.DataStart Contr_DataI,
c.DataStop Contr_DataS,
null NotaCredit_DataI,
null NotaCredit_DataS,
i.prefixdoc Fact,
i.nrdoc Fact_Nr,
i.datadoc Fact_Data,
p.den_part Partener,
o.denumire Articol,
ncont.simbol Cont,
um.den_um1 UM,
0 CANT_FACT,
c1.cant/NVL(um.paritate,1) Cant_Contr,
c1.pret*um.paritate Pret_Original,
c1.pret*Coalesce(1+c1.addim/100,1)*um.paritate Pret_Unitar,
c1.pret*Coalesce(1+c1.addim/100,1)*Coalesce(1+c1.procdisc/100,1)*um.paritate Pret_Unitar_Cu_discount,
C1.cant * C1.pret VALOARE,
NULL VALTVA,
NULL PROCTVA,
CASE
WHEN (select count(*) from contract cop where cop.codgeneric = c.codcontract) &gt; 0 THEN &apos;CADRU&apos;
WHEN case when coalesce(c.codgeneric,0) &gt; 0 then 1 else 0 end &gt; 0 THEN &apos;SUBCONTRACT&apos; ELSE &apos;NORMAL&apos;
END CONTR_TIP,
SB.DEN_SUBUNIT SUBUNITATEA,
CDR.NRDOC||&apos;/&apos;||TO_CHAR(CDR.DATADOC,&apos;DD.MM.YYYY&apos;) CONTR_CADRU,C.CODGENERIC CODCONTRCADRU,
CASE WHEN CDR1.CODCONTRACT1 IS NULL THEN C1.CANT ELSE CDR1.CANT END CANTCONTRACTCADRU
FROM contract c
LEFT JOIN contract1 c1 ON c1.codcontract = c.codcontract
LEFT JOIN contract2 c2 ON c2.codcontract = c.codcontract
LEFT JOIN notecredit nc ON nc.codncredit = c2.coddoc AND nc.tipdoc = c2.tipdoc
LEFT JOIN notecreditfact ncf ON ncf.codncredit = nc.codncredit
LEFT JOIN iesiri i ON i.codies = ncf.coddoc AND i.tipdoc = ncf.tipdoc AND i.DataDoc BETWEEN to_date(&apos;01.10.2019&apos;,&apos;dd.mm.yyyy&apos;) AND to_date(&apos;31.10.2019&apos;,&apos;dd.mm.yyyy&apos;)
LEFT JOIN iesiri1 i1 ON i1.codies = i.codies
LEFT JOIN npart p ON p.codpart = c.partener
LEFT JOIN nclasep clsp on p.codclasa = clsp.codclasep
LEFT JOIN npers agent on agent.codpers = c.agent
LEFT JOIN nartobj o ON o.codobiect = c1.codobiect
LEFT JOIN num1 um ON um.codum1 = c1.umsec
LEFT JOIN ncont ON ncont.codcont = Coalesce(i1.contserv,i1.contdiscount,0)
LEFT JOIN NSUBUNIT SB ON SB.CODSUBUNIT = C.SUBUNITATEA
LEFT JOIN CONTRACT CDR ON CDR.CODCONTRACT = C.CODGENERIC
LEFT JOIN CONTRACT1 CDR1 ON CDR1.CODCONTRACT = CDR.CODCONTRACT AND (C1.CODCONTR1CADRU = CDR1.CODCONTRACT OR C1.CODOBIECT = CDR1.CODOBIECT)
WHERE c.tipdoc = 27 AND c.operat = 1 AND c.anulat = 0 AND C.SUBUNITATEA = 2
AND i.codies IS NULL
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_PRETURI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B02518ACE3A66E85324A04940D27ACD8C3762C53</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_PRETURI (
&quot;CODOBIECT&quot;,&quot;DATADOC&quot;,&quot;CODDOC&quot;,&quot;PACHIZ_RON&quot;,&quot;DEN_MONEDA&quot;,&quot;PACHIZ_VAL&quot;,&quot;DEN_UM1&quot;,&quot;FURNIZOR&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CURS&quot;,&quot;TIPNIR&quot;,&quot;PVAL_DOC&quot;,&quot;CANT&quot;,&quot;DATANIR&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;PACHIZ_RON_FS&quot;,&quot;CODPART&quot;,&quot;CODGEST&quot;,&quot;OBSDOC&quot;,&quot;DATA_EXPIRARE&quot;) AS
SELECT TAB.CODOBIECT,
       TAB.DATADOC,
       TAB.CODDOC,
       TAB.PACHIZ_RON,
       MON.DEN_MONEDA,
       TAB.PACHIZ_VAL,
       NUM1.DEN_UM1,
       CASE
         WHEN TIPNIR IN (6, 23) THEN NSUB.DEN_SUBUNIT
         WHEN TIPNIR IN (7,24)  THEN NG.DEN_GEST
         ELSE NP.DEN_PART
       END FURNIZOR,
      -- COALESCE(NG.DEN_GEST, NP.DEN_PART) FURNIZOR,
       TAB.PREFIXDOC,
       TAB.NRDOC,
       TAB.CURS,
       TAB.TIPNIR,
       CASE
         WHEN COALESCE(MONEDA, 0) = 0 THEN
          NULL
         ELSE
          ROUND(TAB.PU, 4)
       END AS PVAL_DOC,
       TAB.CANT,
       TAB.DATANIR,
       S.DEN_SUBUNIT,
       TAB.DEN_GEST,
       TAB.OBS,
       TAB.PACHIZ_RON_FS,
       COALESCE(NP.CODPART, 0) CODPART,
       COALESCE(NG.CODGEST, 0) CODGEST,
       TAB.OBSDOC,
       DATA_EXPIRARE
  FROM (SELECT CODOBIECT,
               DATADOC,
               CODDOC,
               PARTENER,
               MONEDA,
               PACHIZ_RON,
               PACHIZ_VAL,
               CURS,
               TIPNIR,
               UMSEC,
               PREFIXDOC,
               NRDOC,
               DATANIR,
               SUBUNITATEA,
               DEN_GEST,
               OBS,
               PU,
               PACHIZ_RON_FS,
               OBSDOC,
               SUM(CANT) AS CANT,
               vc2_nt_to_vc3200_dist(CAST(COLLECT(VC2_OBJ(DATA_EXPIRARE).VC2) AS vc2_nt)) AS DATA_EXPIRARE
          FROM (SELECT NS.CODOBIECT,
                       COALESCE(INTR.DATADOC, IES.DATADOC) DATADOC,
                       COALESCE(INTR.CODINTR, IES.CODIES) CODDOC,
                       CASE
                         WHEN N.TIPNIR IN (6, 23) THEN
                          COALESCE(INTR.CODSUBUNIT, IES.CODSUBUNIT)
                         WHEN N.TIPNIR IN (7, 24) THEN
                          COALESCE(INTR.CODGESTPROD, IES.CODGESTPROD)
                         ELSE
                          COALESCE(INTR.PARTENER, IES.PARTENER)
                       END PARTENER,
                       COALESCE(COALESCE(IES.MONEDA, INTR.MONEDA), 0) MONEDA,
                       (NS.PRET - NS.ADAOS) PACHIZ_RON,
                       NS.PUVAL PACHIZ_VAL,
                       COALESCE(COALESCE(INTR.CURS, IES.CURS), 1) CURS,
                       N.TIPNIR,
                       NS.UMSEC,
                       COALESCE(INTR.PREFIXDOC, IES.PREFIXDOC) ||
                       COALESCE(INTR.SERIADOC, IES.SERIADOC) PREFIXDOC,
                       COALESCE(INTR.NRDOC, IES.NRDOC) NRDOC,
                       NS.CANTNIR AS CANT,
                       N.DATANIR,
                       COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA) SUBUNITATEA,
                       G.DEN_GEST,
                       INTR1.OBS,
                       CASE
                         WHEN NS.CODINTR1 IS NOT NULL THEN
                          (SELECT PU FROM INTRARI1 WHERE CODINTR1 = NS.CODINTR1)
                         WHEN NS.CODDVI1 IS NOT NULL THEN
                          (SELECT PU
                             FROM INTRARI1
                            WHERE CODINTR1 =
                                  (SELECT CODINTR1
                                     FROM DVI1
                                    WHERE CODDVI1 = NS.CODDVI1))
                       END PU,
                       CASE
                         WHEN COALESCE(SUPLIMENT, 0) &lt;&gt; 0 AND
                              COALESCE(CANTNIR, 0) &lt;&gt; 0 THEN
                          (NS.PRET - NS.ADAOS) -
                          COALESCE(SUPLIMENT, 0) / COALESCE(CANTNIR, 0)
                         ELSE
                          (NS.PRET - NS.ADAOS)
                       END PACHIZ_RON_FS,
                       COALESCE(INTR.OBS, IES.OBS) AS OBSDOC,
                       CASE
                         WHEN NS.TIPSERIE &gt; 0 THEN
                          NSER.NSER_TG
                         ELSE
                          TO_CHAR(NS.TG,&apos;DD.MM.YYYY&apos;)
                       END AS DATA_EXPIRARE
                  FROM TMP_NIRSTOC_MAN NS
                --      INNER JOIN TMP_MANEVRA MAN  ON MAN.CODUNIC = NS.CODOBIECT
                 INNER JOIN NIR N
                    ON NS.CODNIR = N.CODNIR /*AND NS.CODOBIECT = PKG_NOM_ARTICOL.GET_CODOBIECT_ANALIZAT*/
                   AND COALESCE(N.OPERAT, 0) = 1
                   AND COALESCE(N.ANULAT, 0) = 0
                 INNER JOIN NGEST G
                    ON G.CODGEST = N.GEST
                  LEFT JOIN INTRARI1 INTR1
                    ON INTR1.CODINTR1 = NS.CODINTR1
                   AND N.TIPNIR IN (1, 2, 3, 4, 6, 7)
                  LEFT JOIN DVI1
                    ON DVI1.CODDVI1 = NS.CODDVI1
                   AND N.TIPNIR IN (5)
                  LEFT JOIN INTRARI INTR
                    ON INTR.CODINTR = N.CODINTR
                  LEFT JOIN DVI D
                    ON D.CODINTR = INTR.CODINTR
                   AND D.CODDVI = DVI1.CODDVI
                  LEFT JOIN LIVR1 L1
                    ON L1.CODNIRSTOC = NS.CODNIRSTOC
                   AND L1.CANT &lt; 0
                   AND N.TIPNIR IN (19, 20, 21, 22, 23, 24)
                  LEFT JOIN IESIRI1 IES1
                    ON IES1.CODIES1 = L1.CODIES1
                   AND N.TIPNIR IN (19, 20, 21, 22, 23, 24)
                  LEFT JOIN IESIRI IES
                    ON IES.CODIES = IES1.CODIES
                  LEFT JOIN (SELECT INSR.CODNIRSTOC,
                                   vc2_nt_to_vc3200_dist(CAST(COLLECT(VC2_OBJ(TO_CHAR(INSR.TG, &apos;DD.MM.YYYY&apos;)).VC2) AS vc2_nt))  AS NSER_TG
                              FROM NIRSER INSR
                             WHERE INSR.TG IS NOT NULL
                             GROUP BY INSR.CODNIRSTOC) NSER
                    ON NSER.CODNIRSTOC = NS.CODNIRSTOC
                 WHERE N.TIPNIR IN (1, 2, 3, 4, 5, 6, 7, 19, 20, 21, 22, 23, 24)
                --      AND ((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0  OR (EXISTS(SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST)))
                 ORDER BY DATADOC DESC) TB
         GROUP BY CODOBIECT,
                  DATADOC,
                  CODDOC,
                  PARTENER,
                  MONEDA,
                  PACHIZ_RON,
                  PACHIZ_VAL,
                  CURS,
                  TIPNIR,
                  UMSEC,
                  PREFIXDOC,
                  NRDOC,
                  DATANIR,
                  SUBUNITATEA,
                  DEN_GEST,
                  OBS,
                  PU,
                  PACHIZ_RON_FS,
                  OBSDOC) TAB
  LEFT JOIN NPART NP
    ON TAB.PARTENER = NP.CODPART
   AND NOT TAB.TIPNIR IN (6, 7, 24)
  LEFT JOIN NGEST NG
    ON TAB.PARTENER = NG.CODGEST
   AND TAB.TIPNIR IN (7, 24)
  LEFT JOIN NSUBUNIT NSUB
    ON TAB.PARTENER = NSUB.CODSUBUNIT
   AND TAB.TIPNIR IN (6, 23)
  LEFT JOIN NMONEDE MON
    ON MON.CODMONEDA = TAB.MONEDA
  LEFT JOIN NUM1 NUM1X
    ON NUM1X.CODUM1 = TAB.UMSEC
  LEFT JOIN NUM1
    ON NUM1.CODUM = NUM1X.CODUM
   AND NUM1.SECUNDARA = 0
  LEFT JOIN NSUBUNIT S
    ON S.CODSUBUNIT = TAB.SUBUNITATEA
 ORDER BY TAB.DATADOC DESC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_PRETURI_TRANSFVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>B0BF557666A2EA818EB99F9E241B87D14A2114A4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_PRETURI_TRANSFVAL (
&quot;CODOBIECT&quot;,&quot;DATADOC&quot;,&quot;CODDOC&quot;,&quot;PACHIZ_RON&quot;,&quot;DEN_MONEDA&quot;,&quot;PACHIZ_VAL&quot;,&quot;DEN_UM1&quot;,&quot;FURNIZOR&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CURS&quot;,&quot;TIPNIR&quot;,&quot;PVAL_DOC&quot;,&quot;CANT&quot;,&quot;DATANIR&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;PACHIZ_RON_FS&quot;,&quot;CODPPART&quot;,&quot;CODGEST&quot;,&quot;OBSDOC&quot;,&quot;DATA_EXPIRARE&quot;) AS
SELECT CODOBIECT,
       DATADOC,
       CODDOC,
       PRET - ADAOS PACHIZ_RON,
       (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = 0) DEN_MONEDA,
       0 AS PACHIZ_VAL,
       DEN_UM1,
       FURNIZOR,
       PREFIXDOC,
       NRDOC,
       1 AS CURS,
       TIPNIR,
       NULL AS PVAL_DOC,
       CANT,
       DATANIR,
       DEN_SUBUNIT,
       DEN_GEST,
       OBS,
       PACHIZ_RON_FS,
       0 CODPPART,
       COALESCE(CODGEST, 0) CODGEST,
       OBSDOC,
       DATA_EXPIRARE
  FROM (SELECT (SELECT Max(I1.MG) KEEP(Dense_Rank LAST ORDER BY I1.ANSTART * 12 + I1.LUNASTART)
                  FROM IOART1 I1
                 WHERE I1.CODIOART = NS.CODIOART
                   AND I1.ANSTART * 12 + I1.LUNASTART &lt;= T.AN * 12 + T.LUNA) MGDEST,
               NS.CODOBIECT,
               NS.CODIOART,
               COALESCE(NS.PRET, 0) AS PRET,
               COALESCE(NS.ADAOS, 0) AS ADAOS,
               NS.UMSEC,
               T.NRDOC,
               T.DATADOC,
               T.CODTRANSF AS CODDOC,
               T.AN,
               T.LUNA,
               G.DEN_GEST AS FURNIZOR,
               U1.DEN_UM1,
               T.PREFIXDOC,
               N.TIPNIR,
               NS.CANTNIR AS CANT,
               N.DATANIR,
               S.DEN_SUBUNIT,
               G.DEN_GEST,
               INTR1.OBS,
               CASE
                 WHEN COALESCE(NS.SUPLIMENT, 0) &lt;&gt; 0 AND
                      COALESCE(NS.CANTNIR, 0) &lt;&gt; 0 THEN
                  (NS.PRET - NS.ADAOS) -
                  COALESCE(NS.SUPLIMENT, 0) / COALESCE(NS.CANTNIR, 0)
                 ELSE
                  (NS.PRET - NS.ADAOS)
               END PACHIZ_RON_FS,
               G.CODGEST,
               T.OBS AS OBSDOC,
               CASE
                 WHEN NS.TIPSERIE &gt; 0 THEN
                  NSER.NSER_TG
                 ELSE
                  TO_CHAR(NS.TG, &apos;DD.MM.YYYY&apos;)
               END AS DATA_EXPIRARE
          FROM NIRSTOC NS
         INNER JOIN TMP_MANEVRA MAN
            ON MAN.CODUNIC = NS.CODOBIECT
         INNER JOIN NIR N
            ON N.CODNIR = NS.CODNIR
         INNER JOIN TRANSF T
            ON N.CODTRANSF = T.CODTRANSF
         INNER JOIN LIVR1 L1
            ON L1.CODLIVR1 = NS.CODLIVR1
         INNER JOIN LIVRVAL LV
            ON LV.CODLIVR1 = L1.CODLIVR1
         INNER JOIN NUM1 U1X
            ON U1X.CODUM1 = NS.UMSEC
         INNER JOIN NUM1 U1
            ON U1.CODUM = U1X.CODUM
           AND U1.Secundara = 0
         INNER JOIN NGEST G
            ON G.CODGEST = N.GEST
         INNER JOIN NSUBUNIT S
            ON S.CODSUBUNIT = T.SUBUNITATEA
          LEFT JOIN INTRARI1 INTR1
            ON INTR1.CODINTR1 = NS.CODINTR1
          LEFT JOIN (SELECT INSR.CODNIRSTOC,
                           string_agg(TO_CHAR(INSR.TG, &apos;DD.MM.YYYY&apos;)) AS NSER_TG
                      FROM NIRSER INSR
                     WHERE INSR.TG IS NOT NULL
                     GROUP BY INSR.CODNIRSTOC) NSER
            ON NSER.CODNIRSTOC = NS.CODNIRSTOC
         WHERE --NS.CODOBIECT = PKG_NOM_ARTICOL.GET_CODOBIECT_ANALIZAT AND
         N.TIPNIR = 12
        --    AND ((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0  OR (EXISTS(SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST)))
        )
 WHERE MGDEST &lt;&gt; 5
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_PRETURI_VANZARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>7AD3566F27D1E680D451A1251DB730A2BC60C01E</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_PRETURI_VANZARE (
&quot;CODOBIECT&quot;,&quot;DATADOC&quot;,&quot;CODDOC&quot;,&quot;PACHIZ_RON&quot;,&quot;DEN_MONEDA&quot;,&quot;PACHIZ_VAL&quot;,&quot;DEN_UM1&quot;,&quot;CLIENT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CURS&quot;,&quot;TIPLIVR&quot;,&quot;PU_DOC&quot;,&quot;CANT&quot;,&quot;DATANIR&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;CURSTRANSF&quot;,&quot;MONTRANSF&quot;,&quot;PUTRANSF&quot;,&quot;CODPART&quot;,&quot;OBSDOC&quot;) AS
SELECT
  TAB.CODOBIECT,
  TAB.DATADOC,
  TAB.CODDOC,
  ROUND(TAB.PACHIZ_RON,4) AS PACHIZ_RON,
  MON.DEN_MONEDA,
  ROUND(TAB.PACHIZ_VAL,4) AS PACHIZ_VAL,
  NUM1.DEN_UM1,
  CASE
    WHEN TIPLIVR = 23 THEN NSUB.DEN_SUBUNIT
    ELSE  NP.DEN_PART
  END CLIENT ,
  TAB.PREFIXDOC,
  TAB.NRDOC,
  TAB.CURS,
  TAB.TIPLIVR,
  ROUND(TAB.PU, 4) PU_DOC,
  ROUND(TAB.CANT, 5) CANT,
  TAB.DATANIR,
  S.DEN_SUBUNIT,
  TAB.DEN_GEST,
  TAB.OBS,
  TAB.CURSDOC AS CURSTRANSF,
  MON_TRANSF.SIMBOL AS MONTRANSF,
  ROUND(TAB.PUTRANSF, 4) AS PUTRANSF,
  COALESCE (NP.CODPART, 0) CODPART,
  TAB.OBSDOC
FROM (
  SELECT
    CODOBIECT,
    DATADOC,
    CODDOC,
    PARTENER,
    MONEDA,
    PACHIZ_RON,
    PACHIZ_VAL,
    CURS ,
    TIPLIVR,
    UMSEC,
    PREFIXDOC,
    NRDOC,
    DATANIR,
    SUBUNITATEA,
    DEN_GEST,
	OBS,
    PU,
    CURSDOC,
    MONEDATRANSF,
    PUTRANSF,
    OBSDOC,
    SUM(CANT) AS CANT
  FROM  (
    SELECT
      NS.CODOBIECT,
      ES.DATADOC,
      ES.CODIES AS CODDOC,
      CASE
       WHEN LIV.TIPLIVR = 23 THEN ES.CODSUBUNIT
       ELSE  ES.PARTENER
      END PARTENER,
      NVL(ES.MONEDA ,0) MONEDA,
      (NS.PRET - NS.ADAOS) PACHIZ_RON,
      NS.PUVAL PACHIZ_VAL,
      NVL(ES.CURS,1) CURS ,
      LIV.TIPLIVR,
      NS.UMSEC,
      ES.PREFIXDOC || ES.SERIADOC PREFIXDOC,
      ES.NRDOC,
      LIV1.CANT,
      N.DATANIR,
      NVL(ES.SUBUNITATEA,0) SUBUNITATEA,
      G.DEN_GEST,
	  ES1.OBS,
      ES1.PU,
      ES.CURSDOC,
      ES.MONEDATRANSF,
      ES1.PU / DECODE(NVL(ES.CURSDOC, 1), 0, 1, NVL(ES.CURSDOC, 1)) AS PUTRANSF,
      ES.OBS AS OBSDOC
    FROM
      MAN_IESIRI1 ES1
      inner join LIVR1 Liv1 ON Liv1.CodIes1 = ES1.CodIes1
      inner join IESIRI  ES on  ES1.CodIes = ES.CodIes
      inner join LIVR LIV on Liv1.CodLivr = LIV.CodLivr AND LIV.TIPLIVR IN (16, 19, 20, 21, 22, 23)
      inner join NIRSTOC NS on Liv1.CodNirStoc = NS.CodNirStoc
      INNER JOIN NIR N ON NS.CODNIR = N.CODNIR
      INNER JOIN NGEST G ON G.CODGEST = N.GEST
    ORDER BY DATADOC DESC
	) TB
  GROUP BY
    CODOBIECT,
    DATADOC,
    CODDOC,
    PARTENER,
    MONEDA,
    PACHIZ_RON,
    PACHIZ_VAL,
    CURS ,
    TIPLIVR,
    UMSEC,
    PREFIXDOC,
    NRDOC,
    DATANIR,
    SUBUNITATEA,
    DEN_GEST,
    OBS,
    PU,
    CURSDOC,
    MONEDATRANSF,
    PUTRANSF,
    OBSDOC
) TAB
  LEFT JOIN NPART NP ON TAB.PARTENER = NP.CODPART AND TIPLIVR &lt;&gt; 23
  LEFT JOIN NSUBUNIT NSUB ON TAB.PARTENER = NSUB.CODSUBUNIT AND TIPLIVR = 23
  LEFT JOIN NMONEDE MON ON MON.CODMONEDA = TAB.MONEDA
  LEFT JOIN NMONEDE MON_TRANSF ON MON_TRANSF.CODMONEDA = TAB.MONEDATRANSF
  LEFT JOIN NUM1 NUM1X ON NUM1X.CODUM1 = TAB.UMSEC
  LEFT JOIN NUM1 ON NUM1.CODUM = NUM1X.CODUM AND NUM1.SECUNDARA=0
  LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = TAB.SUBUNITATEA
ORDER BY TAB.DATADOC DESC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_PRETVANZ_VALORIC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>95F3C1ACAB3842EC84B2D4303F51477D60CBE3B8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_PRETVANZ_VALORIC (
&quot;CODOBIECT&quot;,&quot;DATADOC&quot;,&quot;CODDOC&quot;,&quot;PACHIZ_RON&quot;,&quot;DEN_MONEDA&quot;,&quot;PACHIZ_VAL&quot;,&quot;DEN_UM1&quot;,&quot;CLIENT&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CURS&quot;,&quot;TIPLIVR&quot;,&quot;PU_DOC&quot;,&quot;CANT&quot;,&quot;DATANIR&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;CURSTRANSF&quot;,&quot;MONTRANSF&quot;,&quot;PUTRANSF&quot;,&quot;CODPART&quot;,&quot;OBSDOC&quot;,&quot;PUREAL&quot;) AS
SELECT
  TAB.CODOBIECT,
  TAB.DATADOC,
  TAB.CODDOC,
  ROUND(TAB.PACHIZ_RON,4) AS PACHIZ_RON,
  MON.DEN_MONEDA,
  ROUND(TAB.PACHIZ_VAL,4) AS PACHIZ_VAL,
  NUM1.DEN_UM1,
  NP.DEN_PART CLIENT,
  TAB.PREFIXDOC,
  TAB.NRDOC,
  TAB.CURS,
  TAB.TIPLIVR,
  ROUND(TAB.PU, 4) PU_DOC,
  ROUND(TAB.CANT, 5) CANT,
  TAB.DATANIR,
  S.DEN_SUBUNIT,
  TAB.DEN_GEST,
  TAB.OBS,
  TAB.CURSDOC AS CURSTRANSF,
  MON_TRANSF.SIMBOL AS MONTRANSF,
  ROUND(TAB.PUTRANSF, 4) AS PUTRANSF,
  COALESCE (NP.CODPART, 0) CODPART,
  TAB.OBSDOC,
  TAB.PUREAL
FROM (
  SELECT
    ES1.CODOBIECT,
    ES.DATADOC,
    ES.CODIES AS CODDOC,
    ES.PARTENER,
    NVL(ES.MONEDA ,0) MONEDA,
    LV.PRETACHIZ  PACHIZ_RON,
    NULL PACHIZ_VAL,
    NVL(ES.CURS,1) CURS ,
    LIV.TIPLIVR,
    LIV1.UMSEC,
    ES.PREFIXDOC || ES.SERIADOC PREFIXDOC,
    ES.NRDOC,
    LIV1.CANT,
    NULL AS DATANIR,
    NVL(ES.SUBUNITATEA,0) SUBUNITATEA,
    G.DEN_GEST,
	ES1.OBS,
    ES1.PU,
    ES.CURSDOC,
    ES.MONEDATRANSF,
    ES1.PU / DECODE(NVL(ES.CURSDOC, 1), 0, 1, NVL(ES.CURSDOC, 1)) AS PUTRANSF,
    ES.OBS AS OBSDOC,
    CASE WHEN ES1.TIPLINIE IN (&apos;=&apos;, &apos;S&apos;, &apos;V&apos;, &apos;R&apos;) THEN Coalesce(ES1.PRETORIG, 0) * Coalesce(ES1.COEFDISCMAJ, 0) * Coalesce(U1.PARITATE,1) ELSE NULL END PUREAL
  FROM
    LIVR1 Liv1
    inner join MAN_IESIRI1 ES1 on Liv1.CodIes1 = ES1.CodIes1
    --AND ES1.CODOBIECT = PKG_NOM_ARTICOL.GET_CODOBIECT_ANALIZAT
    INNER JOIN TMP_MANEVRA MAN ON MAN.CODUNIC = ES1.CODOBIECT
    inner join IESIRI  ES  on ES1.CodIes = ES.CodIes
    inner join LIVR LIV    on Liv1.CodLivr = LIV.CodLivr
    inner join LIVRVAL LV  on Liv1.CODLIVR1 = LV.CODLIVR1
    INNER JOIN NGEST G ON G.CODGEST = LV.GEST
    LEFT  JOIN NUM1 U1 ON  U1.CODUM1 = ES1.UMSEC
  WHERE LIV.TIPLIVR IN (19,20,21,22) ORDER BY DATADOC DESC
) TAB
  LEFT JOIN NPART NP ON TAB.PARTENER = NP.CODPART
  LEFT JOIN NMONEDE MON ON MON.CODMONEDA = TAB.MONEDA
  LEFT JOIN NMONEDE MON_TRANSF ON MON_TRANSF.CODMONEDA = TAB.MONEDATRANSF
  LEFT JOIN NUM1 NUM1X ON NUM1X.CODUM1 = TAB.UMSEC
  LEFT JOIN NUM1 ON NUM1.CODUM = NUM1X.CODUM AND NUM1.SECUNDARA=0
  LEFT JOIN NSUBUNIT S ON S.CODSUBUNIT = TAB.SUBUNITATEA
ORDER BY TAB.DATADOC DESC
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_URMARIRE_PRET_MODIPRET</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FB22DF9B51481F0FE4B21A784D02EF0F2C57A559</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_URMARIRE_PRET_MODIPRET (
&quot;CODOBIECT&quot;,&quot;DATADOC&quot;,&quot;CODDOC&quot;,&quot;PACHIZ_RON&quot;,&quot;DEN_MONEDA&quot;,&quot;PACHIZ_VAL&quot;,&quot;DEN_UM1&quot;,&quot;FURNIZOR&quot;,&quot;PREFIXDOC&quot;,&quot;NRDOC&quot;,&quot;CURS&quot;,&quot;TIPNIR&quot;,&quot;PVAL_DOC&quot;,&quot;CANT&quot;,&quot;DATANIR&quot;,&quot;DEN_SUBUNIT&quot;,&quot;DEN_GEST&quot;,&quot;OBS&quot;,&quot;PACHIZ_RON_FS&quot;,&quot;CODPPART&quot;,&quot;CODGEST&quot;,&quot;OBSDOC&quot;,&quot;DATA_EXPIRARE&quot;) AS
SELECT CODOBIECT,
       DATADOC,
       CODDOC,
       PRET - ADAOS PACHIZ_RON,
       (SELECT DEN_MONEDA FROM NMONEDE WHERE CODMONEDA = 0) DEN_MONEDA,
       0 AS PACHIZ_VAL,
       DEN_UM1,
       FURNIZOR,
       PREFIXDOC,
       NRDOC,
       1 AS CURS,
       TIPNIR,
       NULL AS PVAL_DOC,
       CANT,
       DATANIR,
       DEN_SUBUNIT,
       DEN_GEST,
       OBS,
       PACHIZ_RON_FS,
       0 CODPPART,
       COALESCE(CODGEST, 0) CODGEST,
       OBSDOC,
       DATA_EXPIRARE
  FROM (SELECT (SELECT Max(I1.MG) KEEP(Dense_Rank LAST ORDER BY I1.ANSTART * 12 + I1.LUNASTART)
                   FROM IOART1 I1
                  WHERE I1.CODIOART = NS.CODIOART
                    AND I1.ANSTART * 12 + I1.LUNASTART &lt;= T.AN * 12 + T.LUNA) MGDEST,
                NS.CODOBIECT,
                NS.CODIOART,
                COALESCE(NS.PRET, 0) AS PRET,
                COALESCE(NS.ADAOS, 0) AS ADAOS,
                NS.UMSEC,
                T.NRDOC,
                T.DATADOC,
                T.CODTRANSF AS CODDOC,
                T.AN,
                T.LUNA,
                G.DEN_GEST AS FURNIZOR,
                U1.DEN_UM1,
                T.PREFIXDOC,
                N.TIPNIR,
                NS.CANTNIR AS CANT,
                N.DATANIR,
                S.DEN_SUBUNIT,
                G.DEN_GEST,
                INTR1.OBS,
                CASE
                  WHEN COALESCE(NS.SUPLIMENT, 0) &lt;&gt; 0 AND
                       COALESCE(NS.CANTNIR, 0) &lt;&gt; 0 THEN
                   (NS.PRET - NS.ADAOS) -
                   COALESCE(NS.SUPLIMENT, 0) / COALESCE(NS.CANTNIR, 0)
                  ELSE
                   (NS.PRET - NS.ADAOS)
                END PACHIZ_RON_FS,
                G.CODGEST,
                T.OBS AS OBSDOC,
               CASE
                 WHEN NS.TIPSERIE &gt; 0 THEN
                  NSER.NSER_TG
                 ELSE
                  TO_CHAR(NS.TG, &apos;DD.MM.YYYY&apos;)
               END AS DATA_EXPIRARE
           FROM NIRSTOC NS
          INNER JOIN TMP_MANEVRA MAN
             ON MAN.CODUNIC = NS.CODOBIECT
          INNER JOIN NIR N
             ON N.CODNIR = NS.CODNIR
          INNER JOIN TRANSF T
             ON N.CODTRANSF = T.CODTRANSF
          INNER JOIN LIVR1 L1
             ON L1.CODLIVR1 = NS.CODLIVR1
         -- INNER JOIN LIVRVAL LV ON LV.CODLIVR1 = L1.CODLIVR1
          INNER JOIN NUM1 U1X
             ON U1X.CODUM1 = NS.UMSEC
          INNER JOIN NUM1 U1
             ON U1.CODUM = U1X.CODUM
            AND U1.Secundara = 0
          INNER JOIN NGEST G
             ON G.CODGEST = N.GEST
          INNER JOIN NSUBUNIT S
             ON S.CODSUBUNIT = T.SUBUNITATEA
           LEFT JOIN INTRARI1 INTR1
             ON INTR1.CODINTR1 = NS.CODINTR1
          LEFT JOIN (SELECT INSR.CODNIRSTOC,
                           string_agg(TO_CHAR(INSR.TG, &apos;DD.MM.YYYY&apos;)) AS NSER_TG
                      FROM NIRSER INSR
                     WHERE INSR.TG IS NOT NULL
                     GROUP BY INSR.CODNIRSTOC) NSER
            ON NSER.CODNIRSTOC = NS.CODNIRSTOC
          WHERE --NS.CODOBIECT = PKG_NOM_ARTICOL.GET_CODOBIECT_ANALIZAT AND
          N.TIPNIR = 13
       AND T.TIPMODIFPRET = 5
         --    AND ((SELECT COUNT(*) FROM TMP_GESTDEDICATE) = 0  OR (EXISTS(SELECT CODGEST FROM TMP_GESTDEDICATE WHERE CODGEST = N.GEST)))
         )
 WHERE MGDEST &lt;&gt; 5
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_UTILAJE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D248C824EDF89FE3BF41E850572E1F19905E5C35</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_UTILAJE (
&quot;CODUTILAJ&quot;,&quot;DENUMIRE&quot;,&quot;NRINVENTAR&quot;,&quot;ETICHETA&quot;,&quot;TIPUTILAJ&quot;,&quot;FLOTA&quot;,&quot;INACTIV&quot;,&quot;CODOBIECT&quot;,&quot;CODGEST&quot;,&quot;DEN_GEST&quot;,&quot;ORESCHIMB&quot;,&quot;CODMIFIX&quot;,&quot;NRSCHIMBURI&quot;,&quot;UM&quot;,&quot;DEN_UM&quot;,&quot;MODEL&quot;,&quot;SERIEF&quot;,&quot;APROBAT&quot;,&quot;FURNIZOR&quot;,&quot;DOC&quot;,&quot;CLIENT&quot;,&quot;CODPART&quot;,&quot;CODIES1&quot;,&quot;DATAGARANTIEI&quot;,&quot;DATAGARANTIE&quot;,&quot;INGARANTIESTR&quot;,&quot;TIP&quot;,&quot;TIPN&quot;,&quot;AGENT&quot;,&quot;NRCONTR&quot;,&quot;DATACONTR&quot;,&quot;ANF&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;PRODUCATOR&quot;,&quot;CODEXTERNCLI&quot;,&quot;CODINTERNCLI&quot;,&quot;DEN_LOCALIT&quot;,&quot;ADRESA&quot;,&quot;DATA_LAST_MODIF&quot;,&quot;OBS&quot;) AS
SELECT
  U.CODUTILAJ,
  NOBJ.DENUMIRE,
  case when U.NRINVENTAR = 0 then null else U.NRINVENTAR end NRINVENTAR,
  U.ETICHETA,
  U.TIPUTILAJ,
  U.FLOTA,
  U.INACTIV,
  U.CODOBIECT,
  G.CODGEST,
  G.DEN_GEST,
  G.ORESCHIMB,
  M.CODMIFIX,
  G.Nrschimburi,
	U.UM,
	UM.Den_UM,
	U.Model,
	U.Serief,
  nvl(U.Aprobat,0) Aprobat,
  nvl(P.DEN_PART,&apos;?&apos;) Furnizor,
  case when U.DOC is null and i.codies &gt; 0 then I.NRDOC||&apos;/&apos;||TO_CHAR(I.DATADOC, &apos;DD.MM.YYYY&apos;) else U.Doc end Doc,
  nvl(CLI.DEN_PART,&apos;?&apos;) Client,
  U.CodPart,
  U.CodIes1,
  U.DataGarantieI,
  U.DataGarantie,
  case when U.InGarantie = 1 then &apos;DA&apos; else &apos;NU&apos; end InGarantieStr,
  case
    when u.tip = 0 then &apos;Utilaj propriu&apos;
    when u.tip = 1 then &apos;Utilaj in custodie la client&apos;
    when u.tip = 2 then &apos;Utilaj client cu vanzare proprie&apos;
    when u.tip = 3 then &apos;Utilaj client cu alt furnizor&apos;
    when u.tip = 4 then &apos;Utilaj inchiriat clientului&apos;
  end Tip,
  U.TIP TIPN,
  AG.NUME||&apos; &apos;||AG.PRENUME AGENT,
  U.NRCONTR,
  U.DATACONTR,
  U.ANF,
  NOBJ.CODEXTERN,
  NOBJ.CODINTERN,
  PROD.DEN_PART PRODUCATOR,
  CLI.CODEXTERN CODEXTERNCLI,
  CLI.CODINTERN CODINTERNCLI,
  LOC.DEN_LOCALIT, U.ADRESA,
  mdf.data_last_modif,
  u.obs
FROM UTILAJE U
     INNER JOIN NARTOBJ NOBJ ON U.CODOBIECT = NOBJ.CODOBIECT
     LEFT JOIN NPERS AG ON AG.CODPERS = U.AGENT
     LEFT JOIN NUM UM  ON UM.CODUM = U.UM
     LEFT JOIN MIFIX M ON M.NRINVENTAR = U.NRINVENTAR AND M.TIP = &apos;MF&apos;
     LEFT JOIN MIFIX1 M1 ON M.CODMIFIX = M1.CODMIFIX AND M1.ANSTART*12+M1.LUNASTART = PKG_GLOBALS.AnLunaLucru
     LEFT JOIN NIRSTOC NS ON NS.CODNIRSTOC = M1.CODNIRSTOC
     LEFT JOIN NIR ON NIR.CODNIR = NS.CODNIR
     LEFT JOIN NGEST G ON G.CODGEST = NIR.GEST
     LEFT JOIN IESIRI1 I1 ON I1.CODIES1 = U.CODIES1
     LEFT JOIN IESIRI I ON I1.CODIES = I.CODIES
     LEFT JOIN NPART P ON U.CODFURNIZOR = P.CODPART
     LEFT JOIN NPART PROD ON COALESCE(U.CODPRODUCATOR,NOBJ.CODPRODUCATOR,0) = PROD.CODPART
     LEFT JOIN NPART CLI ON U.CODPART = CLI.CODPART
     LEFT JOIN NLOCALIT LOC ON LOC.CODLOCALIT = U.CODLOCALIT
     LEFT JOIN (select distinct modif.codmaster,
                                 max(datamodif) keep(DENSE_RANK LAST ORDER BY modif.datamodif) OVER(partition by modif.codmaster) as data_last_modif
                   from modificari modif
                  where tablename = &apos;UTILAJE&apos;) mdf on mdf.codmaster = u.codutilaj
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_UTILAJE_CONTOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D15FDB3E5B83FA85859AF06779D5D261B566ABB8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_UTILAJE_CONTOR (
&quot;CODUTILAJ&quot;,&quot;CODOBIECT&quot;,&quot;TIP&quot;,&quot;DENUMIRE&quot;,&quot;MODEL&quot;,&quot;SERIEF&quot;,&quot;NRINVENTAR&quot;,&quot;ETICHETA&quot;,&quot;TIPUTILAJ&quot;,&quot;FLOTA&quot;,&quot;INACTIV&quot;,&quot;APROBAT&quot;,&quot;TIPN&quot;,&quot;DATAGARANTIEI&quot;,&quot;DATAGARANTIE&quot;,&quot;INGARANTIESTR&quot;,&quot;NRCONTR&quot;,&quot;DATACONTR&quot;,&quot;ANF&quot;,&quot;CODPART&quot;,&quot;CODIES1&quot;,&quot;PRODUCATOR&quot;,&quot;FURNIZOR&quot;,&quot;CLIENT&quot;,&quot;AGENT&quot;,&quot;UM&quot;,&quot;DEN_UM&quot;,&quot;ADRESA&quot;,&quot;DEN_LOCALIT&quot;,&quot;TIP_INDEX&quot;,&quot;DENCONTOR&quot;,&quot;PLAFONCANTF&quot;) AS
SELECT
  U.CODUTILAJ, U.CODOBIECT,
  CASE
    WHEN u.tip = 0 THEN &apos;Utilaj propriu&apos;
    WHEN u.tip = 1 THEN &apos;Utilaj in custodie la client&apos;
    WHEN u.tip = 2 THEN &apos;Utilaj client cu vanzare proprie&apos;
    WHEN u.tip = 3 THEN &apos;Utilaj client cu alt furnizor&apos;
    WHEN u.tip = 4 THEN &apos;Utilaj inchiriat clientului&apos;
  END AS Tip,
  NOBJ.DENUMIRE, U.Model, U.Serief, NULLIF(U.NRINVENTAR,0) AS NRINVENTAR, U.ETICHETA, U.TIPUTILAJ, U.FLOTA, U.INACTIV, Coalesce(U.Aprobat,0) Aprobat, U.TIP AS TIPN,
  U.DataGarantieI, U.DataGarantie, CASE WHEN U.InGarantie = 1 THEN &apos;DA&apos; ELSE &apos;NU&apos; END AS InGarantieStr, U.NRCONTR, U.DATACONTR, U.ANF, U.CodPart, U.CodIes1,
  PROD.DEN_PART AS PRODUCATOR, Coalesce(FURN.DEN_PART,&apos;?&apos;) AS Furnizor, Coalesce(CLI.DEN_PART,&apos;?&apos;) AS Client, AG.NUME||&apos; &apos;||AG.PRENUME AS AGENT,
  UM.CODUM AS UM, UM.Den_UM,
  U.ADRESA, LOC.DEN_LOCALIT,
  Coalesce(UIDX.TIP_INDEX, 0) AS TIP_INDEX, UIDX.DENUMIRE AS DENCONTOR, UIDX.PLAFONCANTF 
FROM UTILAJE U
  INNER JOIN NARTOBJ         NOBJ ON NOBJ.CODOBIECT = U.CODOBIECT
  LEFT  JOIN UTILAJETIPINDEX UIDX ON UIDX.CODUTILAJ = U.CODUTILAJ
  LEFT  JOIN NUM             UM   ON UM.CODUM       = Coalesce(UIDX.UM, U.UM)
  LEFT  JOIN NPART           FURN ON FURN.CODPART   = U.CODFURNIZOR
  LEFT  JOIN NPART           PROD ON PROD.CODPART   = COALESCE(U.CODPRODUCATOR, NOBJ.CODPRODUCATOR,0)
  LEFT  JOIN NPART           CLI  ON CLI.CODPART    = U.CODPART
  LEFT  JOIN NPERS           AG   ON AG.CODPERS     = U.AGENT
  LEFT  JOIN NLOCALIT        LOC  ON LOC.CODLOCALIT = U.CODLOCALIT</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_VENITAVANS_IES</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D2721DBDF2433A743E27C3E75F8D670F9F98400F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_VENITAVANS_IES (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_VENITAVANS_IES CT
  left join ngest ng on ng.codgest = ct.codgest_rez
  left join nsubunit nsch on nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODIES1 AS AV_CODIES1, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODIES1, 0) &lt;&gt; 0
    GROUP by CODIES1
  ) AV1_IES
  ON AV1_IES.AV_CODIES1 = CT.CODIES1
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_IES.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_VENITAVANS_INI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1D34A88A37735414C609E04D6BAD285F3E350DA0</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_VENITAVANS_INI (
&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;NRDOC&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;) AS
SELECT
  I1.CODIES1,
  I.DATADOC,
  I.AN,
  I.LUNA,
  I.NRDOC,
  O.DENUMIRE,
  ROUND((I1.PU * I1.CANT) * NVL(I.CURS, 1), 2) AS VALOARE
FROM
   CHELTAVANS CAV,
   CHELTAVANS1 CAV1,
   IESIRI I,
   IESIRI1 I1,
   NARTOBJ O
WHERE
  I1.TIPLINIE            = &apos;S&apos;
  AND CAV.CODIES1       = I1.CODIES1
  AND CAV1.CODCHELTAVANS = CAV.CODCHELTAVANS
  AND CAV.ISVENIT       = 1
  AND CAV1.ANSTART       = PKG_GLOBALS.GETANLUCRU
  AND CAV1.LUNASTART     = PKG_GLOBALS.GETLUNALUCRU
--  AND PKG_CATEGCONST.ESTECHELTAVANS(I1.CONTSERV) = 1
  AND EXISTS (SELECT CONTVENITAVANS FROM tmp_contvenitavans WHERE CONTVENITAVANS = TO_CHAR(I1.CONTSERV))
  AND I.CODIES   = I1.CODIES
  AND I.OPERAT    = 1
  AND I.ANULAT    = 0
  AND O.CODOBIECT = I1.CODOBIECT
  AND I.AN * 12 + I.LUNA &lt; PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU
  AND NVL(I.SUBUNITATEA,1) = DECODE(PKG_GLOBALS.GETSUBUNITATE, 1, NVL(I.SUBUNITATEA, 1), PKG_GLOBALS.GETSUBUNITATE)
  AND NVL(I.SUBUNITATEA,1) IN (SELECT CODSUBUNIT FROM TMP_SUBUNITDEDICATE)
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_VENITAVANS_NC1</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D1BC8BD5993BE01122CF1B2ACE9F8D58B4272F80</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_VENITAVANS_NC1 (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_VENITAVANS_NC1 CT
  left join ngest ng on ng.codgest = ct.codgest_rez
  left join nsubunit nsch on nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODNC1 AS AV_CODNC1, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODNC1, 0) &lt;&gt; 0
    GROUP by CODNC1
  ) AV1_NC1
  ON AV1_NC1.AV_CODNC1 = CT.CODNC1
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_NC1.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_VENITAVANS_TREZOR</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>092A1F37BB40CE76BB93C867E491B13073711A8D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_VENITAVANS_TREZOR (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;CODIES1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;DEN_PART&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;,&quot;OBSCHELT&quot;,&quot;OBSDOC&quot;,&quot;DEN_GEST&quot;,&quot;DEN_GEST_REZ&quot;,&quot;DEN_SUBUNIT_REZ&quot;) AS
SELECT
  CT.CODINTR1,
  CT.CODOBLIGPIF,
  CT.CODNC1,
  CT.CODIES1,
  CT.DATADOC,
  CT.AN,
  CT.LUNA,
  CT.DENUMIRE,
  CT.DEN_PART,
  CT.VALOARE,
  CT.REZOLVAT,
  CT.OBSCHELT,
  CT.OBSDOC,
  CT.DEN_GEST,
  NG.DEN_GEST as DEN_GEST_REZ,
  NSCH.DEN_SUBUNIT as DEN_SUBUNIT_REZ
FROM
  TMP_VENITAVANS_TREZOR CT
  left join ngest ng on ng.codgest = ct.codgest_rez
  left join nsubunit nsch on nsch.codsubunit = ng.codsubunit
  LEFT JOIN
 (SELECT CODOBLIGPIF AS AV_CODOBLIGPIF, MIN(CODCHELTAVANS1) AS CODCHELTAVANS1
  FROM
    CHELTAVANS AV,
    CHELTAVANS1 AV1 WHERE AV.codcheltavans  = AV1.codcheltavans and COALESCE(CODOBLIGPIF, 0) &lt;&gt; 0
    GROUP by CODOBLIGPIF
  ) AV1_TREZOR
  ON AV1_TREZOR.AV_CODOBLIGPIF = CT.CODOBLIGPIF
  WHERE
   REZOLVAT IN (0, 1)
   OR COALESCE(AV1_TREZOR.CODCHELTAVANS1, 0) &lt;&gt; 0
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_VOUCHER</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>E1021674E9A13A9C94A5F5DC125FD60E14C8282D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_VOUCHER (
&quot;CODVOUCHER&quot;,&quot;CODPART&quot;,&quot;PART&quot;,&quot;OBS&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;CODMONEDA&quot;,&quot;SMONEDA&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;CODCMD&quot;,&quot;CODIES&quot;) AS
SELECT
      V.CODVOUCHER,
      P.CODPART,
      P.DEN_PART Part,
      V.OBS,
      V.DATASTART,
      V.DATASTOP,
      M.CODMONEDA,
      M.SIMBOL Smoneda,
      V.VALOARE,
      V.VALOARE - Nvl(X.FOLOSIT,0) REST,
      V.CodCmd, V.CodIes
FROM VOUCHER V
         INNER JOIN NPART P on P.CodPART = Nvl(V.CODPARTENER,0)
         INNER JOIN NMONEDE M on M.CodMoneda = Nvl(V.Moneda,0)
				 LEFT JOIN (Select CodVoucher, Sum(Valoare) FOLOSIT from VOUCHERLINK group by CodVoucher) X on X.CodVoucher = V.Codvoucher
</TEXT>
  <NIVEL>0</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AUTO</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85B56B69134446BFBC9FC297FA9C825E06F78762</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AUTO (
&quot;CODAUTO&quot;,&quot;CODOBIECT&quot;,&quot;CODGEST&quot;,&quot;TRANSFERAT&quot;,&quot;Q&quot;,&quot;DATASTART&quot;,&quot;DATASTOP&quot;,&quot;CODCLASA&quot;) AS
with
PG as
 (Select p.CodNparcAut CodAuto, Nvl(p.CodGestIni,0) CodGestIni, p.CodGest, Nvl(p.Codcmd,0) CodCmd, P.Data
    from (select * from nparcG where Nvl(CodGest,0) &gt; 0 order by CodNParcAut, Data) p),
PTransf as
(Select x.CodCmd,       x.CodAuto,       x.Data,       x.CodGest,       x.CodGestIni CodGestPrec  from PG x where CodCmd = 0),
Cars as
( select Nvl(CodGest,0) CodGest, CodNParcAut CodAuto, CodArt CodObiect  from NPArcAut  where nvl(Extern,0) = 0 and Nvl(CodGest,0) &gt; 0),
vracTransfer as
(Select * from v_rac_Transfer)
------------------------------------------------------------------------------------------------------------------
Select X.CodAuto, X.CodObiect, X.CodGest, X.Transferat, X.Q, X.DataStart, X.DataStop, GG.CodClasa
FROM (
select T.CodAuto, C.CodObiect, T.CodGestSursa CodGest, 1 Transferat, -1 Q, T.DataStart, T.DataStop
       from vracTransfer T
       inner join Cars C on C.CodAuto = T.CodAuto
union all
select T.CodAuto, C.CodObiect, T.CodGestDest  CodGest, 1 Transferat, +1 Q, T.DataStart, T.DataStop
       from vracTransfer T
       inner join Cars C on C.CodAuto = T.CodAuto
union all
select T.CodAuto, C.CodObiect, T.CodGestPrec CodGest, 0 Transferat, -1 Q, T.Data DataStart, T.Data DataStop
       from PTransf T
       inner join Cars C on C.CodAuto = T.CodAuto
where T.CodGestPrec &lt;&gt; 0
union all
      select T.CodAuto, C.CodObiect, T.CodGest            , 0 Transferat, +1 Q, T.Data DataStart, T.Data DataStop
      from PTransf T
      inner join Cars C on C.CodAuto = T.CodAuto
)  X inner join NGEST GG on GG.CodGest = X.CodGest
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_CLIENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FD2A2D8E9531BB3F86AA1973418F22CB43CF0E30</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_CLIENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_CLIENT_TREZOR


UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_IESIRI_ROSU_CLIENT

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_CLIENT_NC

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_CLIENT_COMPENS 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_AVANS_FURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>596995FB30DBC6F1EFDFB65237B3FDB9BD32B3B5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_AVANS_FURN (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_FURN_TREZOR

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_INTRARI_ROSU_FURN

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_FURN_NC

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_AVANS_FURN_COMPENS 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_INCASARI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>434EC57A8A7371AB44E6703F58ADB2E00BFA11E2</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_INCASARI (
&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;NUMEDOC&quot;,&quot;VALDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODOBLIG&quot;,&quot;TIPOBLIG&quot;,&quot;SIMBOBLIG&quot;,&quot;OBSOBLIG&quot;,&quot;VALOBLIG&quot;,&quot;TVAOBLIG&quot;,&quot;TERMENOBLIG&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;CODPART&quot;,&quot;PARTENER&quot;,&quot;CODDOCSTINGERE&quot;,&quot;TIPDOCSTINGERE&quot;,&quot;NUMEDOCSTINGERE&quot;,&quot;VALSTINGERE&quot;,&quot;TVASTINGERE&quot;,&quot;CODSTINGERE&quot;,&quot;TIPSTINGERE&quot;,&quot;SIMBSTINGERE&quot;,&quot;OBSSTINGERE&quot;,&quot;DATASTINGERE&quot;,&quot;NRDOCSTINGERE&quot;,&quot;DATADECONT&quot;,&quot;DATASYSTEM&quot;,&quot;ANLUNA&quot;,&quot;AGENTDOC&quot;,&quot;AGENTSTING&quot;,&quot;ANLUNASTING&quot;,&quot;CURSORIG&quot;,&quot;SUBUNITATE_DOC&quot;,&quot;CODCLASA&quot;,&quot;DEN_CLASEP&quot;) AS
SELECT
  G.CODDOC, G.TIPDOC, XM.NUMEPRESC NUMEDOC,
  COALESCE(INTR.VALDOC, IES.VALDOC, T1.VALDOC, NC1.VALOARE, O.VALOARE) ValDoc,
  CAST (COALESCE(INTR.NRDOC, IES.NRDOC, C.NRDOC, T1.NRDOC, NC.NRDOC) AS VARCHAR2(20)) NrDoc,
  COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) DataDoc,
  O.CODOBLIGPIF CodOblig, O.SEMNIFICATIE TipOblig, XS.SIMB SimbOblig, XS.OBS ObsOblig,
  XS.Semn* (O.VALOARE - XS.TVA*NVL(G.TVA, 0)) ValOblig,
  XS.Semn*XS.TVA*NVL(G.TVA, 0) TVAOblig,
  CASE
    WHEN O.TERMEN IS NULL THEN COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
    WHEN O.TERMEN &gt;= COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) THEN O.TERMEN
    ELSE COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
  END TermenOblig,
  M.SIMBOL MONEDA, COALESCE(REG.CURS,G.CURS,1) CURS, O.CODPART, P.Den_Part Partener,
  GS.CodDoc CodDocStingere, GS.TipDoc TipDocStingere, XMS.NUMEPRESC NumeDocStingere,
  XSS.Semn* (OS.VALOARE - XSS.TVA*NVL(GS.TVA, 0)) ValStingere,
  XSS.Semn*XSS.TVA*NVL(GS.TVA, 0) TVAStingere,
  OS.CODOBLIGPIF CodStingere, OS.SEMNIFICATIE TipStingere, XSS.SIMB SimbStingere, XSS.OBS ObsStingere,
  COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) DataStingere,
  COALESCE(INTRS.NRDOC, IESS.NRDOC, CS.NRDOC, T1S.NRDOC) NRDOCStingere,
  CASE
    WHEN GS.TIPDOC = 31 THEN (
      SELECT
        CASE
          WHEN T1X.DATADOC IS NULL THEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
          WHEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) IS NULL THEN T1X.DATADOC
          ELSE Greatest( T1X.DATADOC, COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC))
        END
      FROM general gc
        INNER JOIN obligpif oc ON oc.codgeneral = gc.codgeneral
        INNER JOIN stingere sc ON sc.codstinspif = oc.codobligpif
        INNER JOIN obligpif osc ON osc.codobligpif = sc.codstingatorpif
        INNER JOIN general gsc ON gsc.codgeneral = osc.codgeneral
        INNER JOIN trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
      WHERE gc.semnificatie IN (500,600) AND gc.tipdoc = 31 AND gc.coddoc = gs.coddoc
    )
    ELSE COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
  END DataDecont,
  Trunc(SYSDATE) datasystem,
  COALESCE(INTR.AN*100+INTR.Luna, IES.AN*100+IES.Luna, C.AN*100+C.Luna, T.AN*100+T.Luna, NC.AN*100+NC.Luna) AnLuna,
  NumePrenume(AGD.NUME, AGD.Prenume) AgentDoc,
  NumePrenume(AGS.NUME, AGS.Prenume) AgentSting,
  COALESCE(INTRS.AN*100+INTRS.Luna, IESS.AN*100+IESS.Luna, CS.AN*100+CS.Luna, TS.AN*100+TS.Luna) AnLunaSting,
  COALESCE(G.CURS,1) CURSORIG,
  SUB.DEN_SUBUNIT SUBUNITATE_DOC,
  CLSP.CODCLASEP CODCLASA,
  CLSP.DEN_CLASEP
FROM OBLIGPIF O
  INNER JOIN V_SEMNIFICATII XS ON XS.SEMNIFICATIE = O.SEMNIFICATIE AND Decode(XS.ICONT,0,1,O.ICONT,1,0) = 1
  INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT JOIN NMONEDE M ON M.CODMONEDA = Nvl(G.MONEDA,0)
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = G.TIPDOC
  LEFT JOIN DVI ON G.CODDOC = DVI.CODDVI AND O.SEMNIFICATIE = 130
  LEFT JOIN INTRARI INTR ON INTR.CODINTR = Nvl(DVI.CODINTR, G.CODDOC) AND INTR.TIPDOC = G.TIPDOC -- 100, 110, 120, 130, 140
  LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC -- 200, 210, 220, 240
  LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28 AND O.SEMNIFICATIE IN (1301, 1351, 1303)
  LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33) AND G.SEMNIFICATIE IN (310, 410, 330, 430)
  LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
  LEFT JOIN NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35 AND O.SEMNIFICATIE IN (1200, 1201)
  LEFT JOIN NC ON NC.CODNC = NC1.CODNC
  LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA)
  LEFT JOIN NPART P ON P.CODPART = O.CODPART
  LEFT JOIN NCLASEP CLSP ON CLSP.CODCLASEP = P.CODCLASA
  LEFT OUTER JOIN (
    SELECT R1.CODGENERAL, Max(R.CURS) KEEP (Dense_Rank LAST ORDER BY R.DATADOC) CURS
    FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG
    WHERE R.TIPREG = 46
    GROUP BY R1.CODGENERAL
  ) REG ON REG.CODGENERAL = G.CODGENERAL
  LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
  LEFT JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
  LEFT JOIN V_SEMNIFICATII XSS ON XSS.SEMNIFICATIE = OS.SEMNIFICATIE AND Decode(XSS.ICONT,0,1,OS.ICONT,1,0) = 1
  LEFT JOIN MACHETE XMS ON XMS.CODMACHETA = GS.TIPDOC
  LEFT JOIN INTRARI INTRS ON INTRS.CODINTR = GS.CODDOC AND INTRS.TIPDOC = GS.TIPDOC
  LEFT JOIN IESIRI IESS ON IESS.CODIES = GS.CODDOC AND IESS.TIPDOC = GS.TIPDOC
  LEFT JOIN COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
  LEFT JOIN TREZOR1 T1S ON T1S.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29, 30, 31, 33)
  LEFT JOIN TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
  LEFT JOIN NPERS AGD ON AGD.CODPERS = Coalesce(INTR.AGENT, IES.AGENT,  C.AGENT,  T1.AGENT,  T.AGENT)
  LEFT JOIN NPERS AGS ON AGS.CODPERS = Coalesce(INTRS.AGENT, IESS.AGENT, CS.AGENT, T1S.AGENT, TS.AGENT)
WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, /*140, */200, 210, 220, /*240, */310, 330, 410, 430, 1200, 1201, 1301, 1303, 1351)
  AND G.TIPDOC NOT IN (2, 20) AND COALESCE(INTRS.AN,IESS.AN,CS.AN,TS.AN) = 2019
ORDER BY O.CODOBLIGPIF
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_BI_OBLIGATII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>F204CD6B5ED88469976880958D6564D3FB4F26D9</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_BI_OBLIGATII (
&quot;CODDOC&quot;,&quot;TIPDOC&quot;,&quot;NUMEDOC&quot;,&quot;VALDOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;CODOBLIG&quot;,&quot;TIPOBLIG&quot;,&quot;SIMBOBLIG&quot;,&quot;OBSOBLIG&quot;,&quot;VALOBLIG&quot;,&quot;TVAOBLIG&quot;,&quot;TERMENOBLIG&quot;,&quot;MONEDA&quot;,&quot;CURS&quot;,&quot;CODPART&quot;,&quot;PARTENER&quot;,&quot;CODDOCSTINGERE&quot;,&quot;TIPDOCSTINGERE&quot;,&quot;NUMEDOCSTINGERE&quot;,&quot;VALSTINGERE&quot;,&quot;TVASTINGERE&quot;,&quot;CODSTINGERE&quot;,&quot;TIPSTINGERE&quot;,&quot;SIMBSTINGERE&quot;,&quot;OBSSTINGERE&quot;,&quot;DATASTINGERE&quot;,&quot;DATADECONT&quot;,&quot;DATASYSTEM&quot;,&quot;ANLUNA&quot;,&quot;AGENTDOC&quot;,&quot;AGENTSTING&quot;,&quot;ANLUNASTING&quot;,&quot;CURSORIG&quot;,&quot;SIMBCONTSTING&quot;,&quot;DENCONTSTING&quot;,&quot;SIMBCONTDOC&quot;,&quot;DENCONTDOC&quot;,&quot;SUBUNITATE_DOC&quot;) AS
SELECT
  G.CODDOC, G.TIPDOC, XM.NUMEPRESC NUMEDOC,
  COALESCE(INTR.VALDOC, IES.VALDOC, T1.VALDOC, NC1.VALOARE, O.VALOARE) ValDoc,
  CAST (COALESCE(INTR.NRDOC, IES.NRDOC, C.NRDOC, T1.NRDOC, NC.NRDOC) AS VARCHAR2(20)) NrDoc,
  COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) DataDoc,
  O.CODOBLIGPIF CodOblig, O.SEMNIFICATIE TipOblig, XS.SIMB SimbOblig, XS.OBS ObsOblig,
  XS.Semn* (O.VALOARE - XS.TVA*NVL(G.TVA, 0)) ValOblig,
  XS.Semn*XS.TVA*NVL(G.TVA, 0) TVAOblig,
  CASE
    WHEN O.TERMEN IS NULL THEN COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
    WHEN O.TERMEN &gt;= COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) THEN O.TERMEN
    ELSE COALESCE(INTR.DATADOC, IES.DATADOC, C.DATADOC, T1.DATADOC, NC.DATADOC) + Nvl(P.ScadentaV, 0)
  END TermenOblig,
  M.SIMBOL MONEDA, COALESCE(REG.CURS,G.CURS,1) CURS, O.CODPART, P.Den_Part Partener,
  GS.CodDoc CodDocStingere, GS.TipDoc TipDocStingere, XMS.NUMEPRESC NumeDocStingere,
  XSS.Semn* (OS.VALOARE - XSS.TVA*NVL(GS.TVA, 0)) ValStingere,
  XSS.Semn*XSS.TVA*NVL(GS.TVA, 0) TVAStingere,
  OS.CODOBLIGPIF CodStingere, OS.SEMNIFICATIE TipStingere, XSS.SIMB SimbStingere, XSS.OBS ObsStingere,
  COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) DataStingere,
  CASE
    WHEN GS.TIPDOC = 31 THEN (
      SELECT
        CASE
          WHEN T1X.DATADOC IS NULL THEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
          WHEN COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC) IS NULL THEN T1X.DATADOC
          ELSE Greatest( T1X.DATADOC, COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC))
        END
      FROM general gc
        INNER JOIN obligpif oc ON oc.codgeneral = gc.codgeneral
        INNER JOIN stingere sc ON sc.codstinspif = oc.codobligpif
        INNER JOIN obligpif osc ON osc.codobligpif = sc.codstingatorpif
        INNER JOIN general gsc ON gsc.codgeneral = osc.codgeneral
        INNER JOIN trezor1 t1x ON t1x.codtrezor1 = gsc.coddoc
      WHERE gc.semnificatie IN (500,600) AND gc.tipdoc = 31 AND gc.coddoc = gs.coddoc
    )
    ELSE COALESCE(INTRS.DATADOC, IESS.DATADOC, CS.DATADOC, T1S.DATADOC)
  END DataDecont,
  Trunc(SYSDATE) datasystem,
  COALESCE(INTR.AN*100+INTR.Luna, IES.AN*100+IES.Luna, C.AN*100+C.Luna, T.AN*100+T.Luna, NC.AN*100+NC.Luna) AnLuna,
  NumePrenume(AGD.NUME, AGD.Prenume) AgentDoc,
  NumePrenume(AGS.NUME, AGS.Prenume) AgentSting,
  COALESCE(INTRS.AN*100+INTRS.Luna, IESS.AN*100+IESS.Luna, CS.AN*100+CS.Luna, TS.AN*100+TS.Luna) AnLunaSting,
  COALESCE(G.CURS,1) CURSORIG,
  CONTS.SIMBOL SIMBCONTSTING,
  CONTS.DEN_CONT DENCONTSTING,
  CONTD.SIMBOL SIMBCONTDOC,
  CONTD.DEN_CONT DENCONTDOC,
  SUB.DEN_SUBUNIT SUBUNITATE_DOC
FROM OBLIGPIF O
  INNER JOIN V_SEMNIFICATII XS ON XS.SEMNIFICATIE = O.SEMNIFICATIE AND Decode(XS.ICONT,0,1,O.ICONT,1,0) = 1
  INNER JOIN GENERAL G ON G.CODGENERAL = O.CODGENERAL
  LEFT JOIN NMONEDE M ON M.CODMONEDA = Nvl(G.MONEDA,0)
  LEFT JOIN MACHETE XM ON XM.CODMACHETA = G.TIPDOC
  LEFT JOIN DVI ON G.CODDOC = DVI.CODDVI AND O.SEMNIFICATIE = 130
  LEFT JOIN INTRARI INTR ON INTR.CODINTR = Nvl(DVI.CODINTR, G.CODDOC) AND INTR.TIPDOC = G.TIPDOC -- 100, 110, 120, 130, 140
  LEFT JOIN IESIRI IES ON IES.CODIES = G.CODDOC AND IES.TIPDOC = G.TIPDOC -- 200, 210, 220, 240
  LEFT JOIN COMPENS C ON C.CODCOMPENS = G.CODDOC AND G.TIPDOC = 28 AND O.SEMNIFICATIE IN (1301, 1351, 1303)
  LEFT JOIN TREZOR1 T1 ON T1.CODTREZOR1 = G.CODDOC AND G.TIPDOC IN (29, 30, 31, 33) AND G.SEMNIFICATIE IN (310, 410, 330, 430)
  LEFT JOIN TREZOR T ON T.CODTREZOR = T1.CODTREZOR
  LEFT JOIN NC1 ON NC1.CODNC1 = G.CODDOC AND G.TIPDOC = 35 AND O.SEMNIFICATIE IN (1200, 1201)
  LEFT JOIN NC ON NC.CODNC = NC1.CODNC
  LEFT JOIN NSUBUNIT SUB ON SUB.CODSUBUNIT = COALESCE(INTR.SUBUNITATEA, IES.SUBUNITATEA, T.SUBUNITATEA, NC.SUBUNITATEA)
  LEFT JOIN NPART P ON P.CODPART = O.CODPART
  LEFT JOIN ( 
    SELECT X.CODGENERAL, X.CURS 
    FROM ( SELECT R1.CODGENERAL, R.CURS, ROW_NUMBER() OVER (PARTITION BY R1.CODGENERAL ORDER BY R.DATADOC DESC) RNOrd FROM REG R INNER JOIN REG1 R1 ON R1.CODREG = R.CODREG WHERE R.TIPREG = 46 ) X 
    WHERE RNOrd = 1
  ) REG ON REG.CODGENERAL = G.CODGENERAL
  LEFT JOIN STINGERE S ON S.CODSTINSPIF = O.CODOBLIGPIF
  LEFT JOIN OBLIGPIF OS ON OS.CODOBLIGPIF = S.CODSTINGATORPIF
  LEFT JOIN GENERAL GS ON GS.CODGENERAL = OS.CODGENERAL
  LEFT JOIN V_SEMNIFICATII XSS ON XSS.SEMNIFICATIE = OS.SEMNIFICATIE AND Decode(XSS.ICONT,0,1,OS.ICONT,1,0) = 1
  LEFT JOIN MACHETE XMS ON XMS.CODMACHETA = GS.TIPDOC
  LEFT JOIN INTRARI INTRS ON INTRS.CODINTR = GS.CODDOC AND INTRS.TIPDOC = GS.TIPDOC
  LEFT JOIN IESIRI IESS ON IESS.CODIES = GS.CODDOC AND IESS.TIPDOC = GS.TIPDOC
  LEFT JOIN COMPENS CS ON CS.CODCOMPENS = GS.CODDOC AND GS.TIPDOC = 28
  LEFT JOIN TREZOR1 T1S ON T1S.CODTREZOR1 = GS.CODDOC AND GS.TIPDOC IN (29, 30, 31, 33)
  LEFT JOIN TREZOR TS ON TS.CODTREZOR = T1S.CODTREZOR
  LEFT JOIN NPERS AGD ON AGD.CODPERS = Coalesce(INTR.AGENT,  IES.AGENT,  C.AGENT,  T1.AGENT,  T.AGENT)
  LEFT JOIN NPERS AGS ON AGS.CODPERS = Coalesce(INTRS.AGENT, IESS.AGENT, CS.AGENT, T1S.AGENT, TS.AGENT)
  LEFT JOIN NCONT CONTD ON CONTD.CODCONT = PKG_LIST_BASE_UTILS.iCont_CodCont(o.icont,o.codpart, COALESCE(INTR.AN*12+INTR.Luna, IES.AN*12+IES.Luna, C.AN*12+C.Luna, T.AN*12+T.Luna, NC.AN*12+NC.Luna) ,o.semnificatie)
  LEFT JOIN NCONT CONTS ON CONTS.CODCONT = PKG_LIST_BASE_UTILS.iCont_CodCont(os.icont,os.codpart, COALESCE(INTRS.AN*12+INTRS.Luna, IESS.AN*12+IESS.Luna, CS.AN*12+CS.Luna, TS.AN*12+TS.Luna) ,os.semnificatie)
WHERE O.SEMNIFICATIE IN (100, 110, 120, 130, 200, 210, 220, 310, 330, 410, 430, 1200, 1201, 1301, 1303, 1351)
  AND NOT G.TIPDOC IN (2, 20) AND COALESCE(INTRS.AN,IESS.AN,CS.AN,TS.AN) = 2019
ORDER BY O.CODOBLIGPIF</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_CHELTAVANS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>39CCECD946606933C8D4D3A96B9DBFCD52046296</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_CHELTAVANS (
&quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;,&quot;CODNC1&quot;,&quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;) AS
SELECT &quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;, &quot;CODNC1&quot;, &quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;
FROM
  V_CHELTAVANS_INTR
UNION ALL
SELECT &quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;, &quot;CODNC1&quot;, &quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;
FROM
  V_CHELTAVANS_TREZOR
UNION ALL
SELECT &quot;CODINTR1&quot;,&quot;CODOBLIGPIF&quot;, &quot;CODNC1&quot;, &quot;DATADOC&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;DENUMIRE&quot;,&quot;VALOARE&quot;,&quot;REZOLVAT&quot;
FROM
  V_CHELTAVANS_NC1

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_DISCART_ALL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>718CE645E6C969D6D6BFF1C38862B9C08D205B51</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_DISCART_ALL (
&quot;CODOBIECT&quot;,&quot;CODDISCOUNT&quot;,&quot;LIMINF&quot;,&quot;LIMSUP&quot;,&quot;PROCENT&quot;,&quot;GRUPA&quot;,&quot;CLASA&quot;) AS
SELECT CODOBIECT, CODDISCOUNT, LIMINF, LIMSUP, PROCENT, GRUPA, CLASA
FROM V_DISCART_OBJ
UNION ALL
SELECT CODOBIECT, CODDISCOUNT, LIMINF, LIMSUP, PROCENT, GRUPA, CLASA
FROM V_DISCART_CLS
UNION ALL
SELECT CODOBIECT, CODDISCOUNT, LIMINF, LIMSUP, PROCENT, GRUPA, CLASA
FROM V_DISCART_GRUPA
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_PMP_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>13EEAD1E45F98E8CE6952DD64AA781A8BC5CACCD</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_PMP_LUNA (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR, SUM(VALINTR) AS VALINTR, SUM(RESTLUNA) AS RESTLUNA, SUM(VALVALUTA) AS VALVALUTA
FROM
(
 SELECT
   CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA, VALVALUTA
 FROM
  V_LIST_PMP_INTRARI
 UNION ALL
 SELECT
   CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA, VALVALUTA
 FROM
  V_LIST_PMP_IESIRI
)
GROUP BY
CODOBIECT, CODSUBUNIT 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_STOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C5614E36F432DF51723FCEAC291BE9CC1196DC0D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_STOC (
&quot;CODNIRSTOC&quot;,&quot;UMSEC&quot;,&quot;CODOBIECT&quot;,&quot;CODIOART&quot;,&quot;GEST&quot;,&quot;PRETACHIZ&quot;,&quot;PRET&quot;,&quot;ADAOS&quot;,&quot;TVA&quot;,&quot;TIPSERIE&quot;,&quot;REST&quot;,&quot;STOC&quot;,&quot;PRELUAT&quot;,&quot;PROCENTADAOS&quot;,&quot;INTRATLA&quot;,&quot;TG&quot;,&quot;PUMAXIMAL&quot;,&quot;CODPART&quot;,&quot;CODNIR&quot;,&quot;CODINTR1&quot;,&quot;CODINTR&quot;,&quot;FLAG&quot;,&quot;CODTRANSF1&quot;,&quot;DATAACHIZ&quot;,&quot;TIPDOCACHIZ&quot;,&quot;TIPINTRARESTOC&quot;,&quot;LOCATIE&quot;,&quot;RESTUM1&quot;,&quot;STOCUM1&quot;,&quot;PRELUATUM1&quot;,&quot;RESTUM2&quot;,&quot;STOCUM2&quot;,&quot;PRELUATUM2&quot;,&quot;CODGESTPROD&quot;,&quot;SUBUNITATEA&quot;,&quot;FURNIZOR&quot;,&quot;CODFURNIZOR&quot;,&quot;CODLOCATIE&quot;,&quot;CODDVI1&quot;,&quot;CODTRANSF&quot;,&quot;TIPNIR&quot;,&quot;CODIES&quot;,&quot;AN&quot;,&quot;LUNA&quot;,&quot;INITIALIZARI&quot;,&quot;D1&quot;,&quot;D2&quot;,&quot;D3&quot;,&quot;PUVAL&quot;,&quot;PROVIZION&quot;) AS
SELECT
  NS.CODNIRSTOC, NS.UMSEC, NS.CODOBIECT, NS.CODIOART, N.GEST,
  ROUND((NS.PRET - NVL(NS.ADAOS, 0)),10) PRETACHIZ, ROUND(NS.PRET, 10) PRET, NS.ADAOS, NS.TVA, NS.TIPSERIE,
  ROUND(V.REST,10) REST, ROUND(V.REST,10) STOC, 0.0 PRELUAT, NS.PROCENTADAOS, NS.DATAACHIZ INTRATLA, NS.TG, NS.PUMAXIMAL, NS.FURN CODPART,
  N.CODNIR CODNIR, NS.CODINTR1 CODINTR1, N.CODINTR CODINTR,
  0 FLAG, NS.CODTRANSF1, NS.DATAACHIZ, NS.TIPDOCACHIZ, N.TIPNIR TIPINTRARESTOC, L.DENUMIRE LOCATIE,
  V.RESTUM1, V.RESTUM1 STOCUM1, 0.0 PRELUATUM1, V.RESTUM2, V.RESTUM2 STOCUM2, 0.0 PRELUATUM2,
  NS.CODGESTPROD, NS.SUBUNITATEA,
  CASE
    WHEN NS.TIPDOCACHIZ = 7 THEN (SELECT DEN_GEST FROM NGEST WHERE CODGEST = NS.CODGESTPROD)
    ELSE (SELECT DEN_PART FROM NPART WHERE CODPART = NS.FURN)
  END FURNIZOR,
  NS.FURN CODFURNIZOR, NS.CODLOCATIE, NS.CODDVI1, T.CODTRANSF, N.TIPNIR, N.CODIES,
  CASE
    WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
    THEN FL.ANINITIAL
    ELSE COALESCE(I.AN,T.AN,IES.AN)
  END AN,
  CASE
    WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
    THEN FL.LUNAINITIALA
    ELSE COALESCE(I.LUNA,T.LUNA,IES.LUNA)
  END LUNA,
  CASE
    WHEN COALESCE(I.AN,T.AN,IES.AN) * 12 + COALESCE(I.LUNA,T.LUNA,IES.LUNA) &lt; (FL.ANINITIAL * 12 + FL.LUNAINITIALA)
    THEN 1
    ELSE 0
  END INITIALIZARI,
  NS.D1, NS.D2, NS.D3,NS.PUVAL,NS.PROVIZION
FROM v_stoc_luna v
  INNER JOIN nirstoc ns ON v.CODNIRSTOC = NS.CODNIRSTOC
  INNER JOIN NIR N      ON N.CODNIR     = NS.CODNIR
  LEFT  JOIN NGEST G    ON G.CODGEST    = N.GEST
  LEFT  JOIN INTRARI I  ON I.CODINTR    = N.CODINTR   AND I.TIPDOC   = N.TIPNIR
  LEFT  JOIN IESIRI IES ON IES.CODIES   = N.CODIES    AND IES.TIPDOC = N.TIPNIR
  LEFT  JOIN NLOCATII L ON L.CODLOCATIE = NS.CODLOCATIE
  LEFT  JOIN TRANSF T   ON T.CODTRANSF  = N.CODTRANSF AND T.TIPDOC   = N.TIPNIR
  CROSS JOIN FIRMALUNI FL
--STEF am gasit cazuri cu livr. anterioare crearii stocului, caz in care ar trebui sa apara livrarile
--de asta am renuntat la filtrele de tip an.luna, respectiva filtrare se face in v_stoc_luna
WHERE v.REST &lt;&gt; 0
  AND (pkg_list_selfisamag.getNumToateGest = 1 OR N.GEST IN (SELECT valoare FROM tmp_manevra_liste WHERE filtru = &apos;CODGEST&apos;))
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_STOCSER_TRANZACTII_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>CDD6A238E892A5F262BFA8B02BE1D9B54940F4CC</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_STOCSER_TRANZACTII_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSER, CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM

(
  -- INTRARI IN STOC
  SELECT CODNIRSER, CODNIRSTOC, NVL(REST,0) REST, nvl(RESTUM1,0) RESTUM1, NVL(RESTUM2,0) RESTUM2 FROM V_LIST_NIRURI_SER_LUNA

  UNION ALL

  -- LIVRARI DIN STOC
  SELECT CODNIRSER, CODNIRSTOC, nvl(REST,0) REST, nvl(RESTUM1,0) RESTUM1, NVL(RESTUM2,0) RESTUM2 FROM V_LIST_LIVRARI_SER_LUNA

)
GROUP BY CODNIRSER, CODNIRSTOC 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_MATERIALEECHIVALENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3C01BC79D33EDC68D7C13D8F4A58D7750311BC95</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_MATERIALEECHIVALENTE (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;DENOBIECT&quot;,&quot;PARITATE&quot;,&quot;CODGRUPA&quot;,&quot;ORDINE&quot;) AS
SELECT
  O.&quot;CODARTICOL&quot;,O.&quot;CODOBIECT&quot;,O.&quot;DEN_ARTICOL&quot;,O.&quot;UM&quot;,O.&quot;CLASA&quot;,O.&quot;TIPSERIE&quot;,O.&quot;TIPARTICOL&quot;,O.&quot;ARETG&quot;,
  O.&quot;CONTIMPLICIT&quot;,O.&quot;GESTIMPLICITA&quot;,O.&quot;CERTIFICAT&quot;,O.&quot;EVOLUTIEPRET&quot;,
  O.&quot;CONTSERVICIU&quot;,O.&quot;UM1&quot;,O.&quot;UM2&quot;,O.&quot;CODEXTERN&quot;,O.&quot;CODINTERN&quot;,O.&quot;UMAMBALARE&quot;,O.&quot;STOCMIN&quot;,O.&quot;STOCMAX&quot;,O.&quot;RETURNABIL&quot;,
  O.&quot;CODTVA&quot;,O.&quot;CODACCIZE&quot;,O.&quot;CODTAXA1&quot;,O.&quot;CODTAXA2&quot;, O.&quot;PROCTVA&quot;,O.&quot;DENOBIECT&quot;, PE.PARITATE, 0 CODGRUPA, PE.ORDINE
FROM
  V_OBJ_ART O,
  PRODMAT MAT
  INNER JOIN PRODMATECHIV PE ON MAT.CODMAT = PE.CODMAT
WHERE
  MAT.CODMAT = PKG_PRODCOMP.GET_MAT_ECHIVALAT
  AND O.CODOBIECT = PE.CODOBIECT
  AND O.CODOBIECT &lt;&gt; MAT.CODOBIECT
ORDER BY PE.ORDINE

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBIECTEECHIVALENTE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>1C4903C8F659EC3FC67723F913AEC3668E638F3C</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBIECTEECHIVALENTE (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;DENOBIECT&quot;,&quot;PARITATE&quot;,&quot;CODGRUPA&quot;) AS
SELECT
  O.&quot;CODARTICOL&quot;,O.&quot;CODOBIECT&quot;,O.&quot;DEN_ARTICOL&quot;,O.&quot;UM&quot;,O.&quot;CLASA&quot;,O.&quot;TIPSERIE&quot;,O.&quot;TIPARTICOL&quot;,O.&quot;ARETG&quot;,
  O.&quot;CONTIMPLICIT&quot;,O.&quot;GESTIMPLICITA&quot;,O.&quot;CERTIFICAT&quot;,O.&quot;EVOLUTIEPRET&quot;,
  O.&quot;CONTSERVICIU&quot;,O.&quot;UM1&quot;,O.&quot;UM2&quot;,O.&quot;CODEXTERN&quot;,O.&quot;CODINTERN&quot;,O.&quot;UMAMBALARE&quot;,O.&quot;STOCMIN&quot;,O.&quot;STOCMAX&quot;,O.&quot;RETURNABIL&quot;,
  O.&quot;CODTVA&quot;,O.&quot;CODACCIZE&quot;,O.&quot;CODTAXA1&quot;,O.&quot;CODTAXA2&quot;, O.&quot;PROCTVA&quot;,O.&quot;DENOBIECT&quot;, E.PARITATE/ORIG.PARITATE PARITATE, E.CODGRUPA
FROM
  V_OBJ_ART O,
  NECHIV E
  inner join NECHIV ORIG ON E.CODGRUPA = ORIG.CODGRUPA AND ORIG.CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_ECHIVALAT
WHERE
  E.CODGRUPA = PKG_SELECTARTICOLE.GET_GRUPA_OBIECT_ECHIVALAT
  AND O.CODOBIECT = E.CODOBIECT
  AND O.CODOBIECT &lt;&gt; PKG_SELECTARTICOLE.GET_OBIECT_ECHIVALAT

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_CLIENT</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>614C0334AA27A191A84C757750D2ED947B95194F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_CLIENT (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_CLIENT_IESIRI

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_CLIENT_NC

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_CLIENT_COMPENS 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_OBLIG_FURN</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>52B975FD66D9A05F6D97BC0769FB80F93609DCF5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_OBLIG_FURN (
&quot;CODOBLIGPIF&quot;,&quot;DOC&quot;,&quot;NRDOC&quot;,&quot;DATADOC&quot;,&quot;VALOARE&quot;,&quot;REST&quot;,&quot;TERMEN&quot;,&quot;PRELUAT&quot;,&quot;RAMAS&quot;,&quot;CODSTINGATOR&quot;,&quot;SEMNIFCODSTINS&quot;,&quot;SIMBOLCONT&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SIMBOLMONEDA&quot;,&quot;CURS&quot;,&quot;TVA&quot;,&quot;CODLOCATIE&quot;,&quot;SEDIU&quot;,&quot;SUBUNITATEA&quot;,&quot;DEN_SUBUNIT&quot;,&quot;PROCTVAAVANS&quot;) AS
SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_FURN_INTRARI

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_FURN_NC

UNION ALL

SELECT
  CODOBLIGPIF, DOC, NRDOC, DATADOC, VALOARE, REST, TERMEN, PRELUAT, RAMAS, CODSTINGATOR, SEMNIFCODSTINS, SIMBOLCONT, ICONT,
  CODMONEDA, SIMBOLMONEDA, CURS, TVA, CODLOCATIE, SEDIU, SUBUNITATEA, DEN_SUBUNIT, PROCTVAAVANS
FROM
  V_OBLIG_FURN_COMPENS 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>776263AAFBA7F6DF7F5253A9AAE10DABDF3D8C3A</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_LUNA (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
  CODOBIECT,
  CODSUBUNIT,
  SUM(CANTINTR)  AS CANTINTR,
  SUM(VALINTR)   AS VALINTR,
  SUM(RESTLUNA)  AS RESTLUNA,
  SUM(VALVALUTA) AS VALVALUTA
FROM (
  SELECT CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA FROM V_PMP_INTRARI UNION ALL
  SELECT CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA FROM V_PMP_IESIRI
)
GROUP BY CODOBIECT, CODSUBUNIT</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_LUNA_DOC</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>8ACC45E0A97211AB9178202317A441379E25645F</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_LUNA_DOC (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;VALVALUTA&quot;) AS
SELECT
CODOBIECT, CODSUBUNIT, SUM(RESTLUNA) AS CANTINTR,
                       SUM(VALRESTLUNA) AS VALINTR,
                       SUM(VALRESTLUNAV) AS VALVALUTA
FROM
(
 SELECT
   CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV
 FROM
  V_PMP_INTRARI_DOC
 UNION ALL
 SELECT
   CODOBIECT, CODSUBUNIT, RESTLUNA, VALRESTLUNA, VALRESTLUNAV
 FROM
  V_PMP_IESIRI_DOC
)
GROUP BY
CODOBIECT, CODSUBUNIT 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_PMP_OBIECT_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9A7BC41A6E03AD1CD8FB348F9D8F5459EA962F82</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_PMP_OBIECT_LUNA (
&quot;CODOBIECT&quot;,&quot;CODSUBUNIT&quot;,&quot;CANTINTR&quot;,&quot;VALINTR&quot;,&quot;RESTLUNA&quot;,&quot;VALVALUTA&quot;) AS
SELECT
CODOBIECT, CODSUBUNIT, SUM(CANTINTR) AS CANTINTR,
                       SUM(VALINTR) AS VALINTR,
                       SUM(RESTLUNA) AS RESTLUNA,
                       SUM(VALVALUTA) AS VALVALUTA
FROM
(
 SELECT
   CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA
 FROM
  V_PMP_OBIECT_INTRARI
 UNION ALL
 SELECT
   CODOBIECT, CODSUBUNIT, CANTINTR, VALINTR, RESTLUNA,VALVALUTA
 FROM
  V_PMP_OBIECT_IESIRI
)
GROUP BY
CODOBIECT, CODSUBUNIT 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_REST_OBLIGPIF_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>2D90CEC4BCD5C553C9420F0FCB6569D29D69AFFF</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_REST_OBLIGPIF_LUNA (
&quot;CODOBLIGPIF&quot;,&quot;REST&quot;,&quot;RESTTVA&quot;,&quot;RESTSPLITTVA&quot;) AS
SELECT CODOBLIGPIF, SUM(REST) AS REST, SUM(RESTTVA) AS RESTTVA, SUM(NVL(RESTSPLITTVA, 0)) AS RESTSPLITTVA
FROM
(
  SELECT CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA FROM V_REST_OBLIGPIF_PREC

  UNION ALL

  SELECT CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA FROM  V_OBLIGPIF_DE_STINS_LUNA


  UNION ALL

  SELECT CODOBLIGPIF, REST, RESTTVA, RESTSPLITTVA FROM  V_OBLIGPIF_STINGERI_LUNA

)
GROUP BY CODOBLIGPIF
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SERVICII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D9EB25C8229417E6799565903FDF69105C46EFE7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SERVICII (
&quot;CODOBIECT&quot;,&quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;DENOBIECT&quot;) AS
SELECT
  &quot;CODOBIECT&quot;, &quot;CODARTICOL&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,
  &quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,
  &quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;, &quot;UMAMBALARE&quot;, &quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;DENOBIECT&quot;
FROM
  V_OBJ_ART
WHERE
  TIPARTICOL = 1 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDBANKLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>82269D09449CCDCDFB4E2CE979ACC2E1910FA0C7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDBANKLUNA (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA
FROM
V_SOLDBANK_TRANZACTII
UNION ALL
SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA
FROM
V_SOLDBANKLUNAPREC
)
GROUP BY CODBANKCONT 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>377753E6F1ADA642A167C71112389FB1F4843F19</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_STINGERI_TREZOR
UNION ALL
 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_STINGERI_COMPENS
UNION ALL
(   -- STORNO AVANSURI PE FACTURA INTRARI
 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM
  (
    SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0 THEN  -(O_STINGATOR.VALOARE - NVL(G.TVA, 0))
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, GEN.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - NVL(G.TVA, 0))
      END AS SOLDVALUTA
    FROM
/*
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
*/
       STINGERE S
       LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
       LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
       LEFT OUTER JOIN INTRARI I  ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
       LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
       LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
       LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
       LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/
    WHERE O_STINGATOR.SEMNIFICATIE IN (111) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1) AND (I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINGATOR.CODPART) = 1
  )
)
UNION ALL
(
 -- STORNO AVANSURI PE FACTURA IESIRE
 -- STINGERE SEMNIFICATIE 400 (MONETARE)
 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA FROM
  (
    SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA,
      CASE
        WHEN G.MONEDA = 0  THEN  O_STINGATOR.VALOARE - NVL(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 THEN (O_STINGATOR.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, GEN.CURS)
      END  * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN O_STINGATOR.VALOARE - NVL(G.TVA, 0)
      END * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDVALUTA
    FROM
/*
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I ON  I.CODIES = G.CODDOC
*/
      STINGERE S
      LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
      LEFT OUTER JOIN IESIRI I  ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
      LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/
    WHERE O_STINGATOR.SEMNIFICATIE IN (211, 400) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1) AND (I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINGATOR.CODPART) = 1
  )
)
)
GROUP BY CODPART, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_STINGERI_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3DCF21D23EDB53E84BC300D3586D9F332CC8B916</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_STINGERI_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_STINGERI_TREZ_SUB
UNION ALL
 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_STINGERI_COMP_SUB
UNION ALL
(   -- STORNO AVANSURI PE FACTURA INTRARI
 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA FROM
  (
    SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
      CASE
        WHEN G.MONEDA = 0 THEN  -(O_STINGATOR.VALOARE - NVL(G.TVA, 0))
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, GEN.CURS)
      END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN -(O_STINGATOR.VALOARE - NVL(G.TVA, 0))
      END AS SOLDVALUTA
    FROM
/*
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN INTRARI I ON  I.CODINTR = G.CODDOC
*/
       STINGERE S
       LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
       LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
       LEFT OUTER JOIN INTRARI I  ON I.CODINTR = G.CODDOC AND I.TIPDOC = G.TIPDOC
       LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
       LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
       LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
       LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
       AND GREG.AN   = PKG_GLOBALS.GETANTEMP
       AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
       AND GREG.TIPREG = 46
*/
    WHERE O_STINGATOR.SEMNIFICATIE IN (111) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1) AND (I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINGATOR.CODPART) = 1
  )
)
UNION ALL
(
 -- STORNO AVANSURI PE FACTURA IESIRE
 -- STINGERE SEMNIFICATIE 400 (MONETARE)
 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA FROM
  (
    SELECT O_STINGATOR.CODPART, O_STINGATOR.ICONT, G.MONEDA AS CODMONEDA, I.SUBUNITATEA,
      CASE
        WHEN G.MONEDA = 0  THEN  O_STINGATOR.VALOARE - NVL(G.TVA, 0)
        WHEN G.MONEDA &lt;&gt; 0 THEN (O_STINGATOR.VALOARE - NVL(G.TVA, 0)) * NVL(GREG.CURS, GEN.CURS)
      END  * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDLEI,
      CASE
        WHEN G.MONEDA = 0 THEN  0
        WHEN G.MONEDA &lt;&gt; 0 THEN O_STINGATOR.VALOARE - NVL(G.TVA, 0)
      END * CASE WHEN O_STINGATOR.SEMNIFICATIE IN (400) THEN -1 ELSE 1 END AS SOLDVALUTA
    FROM
/*
      OBLIGPIF O
      LEFT OUTER JOIN GENERAL G  ON G.CODGENERAL  = O.CODGENERAL
      LEFT OUTER JOIN TMP_CURS_REGULARIZAT_LUNA GREG ON GREG.CODGENERAL = G.CODGENERAL
      LEFT OUTER JOIN IESIRI I ON  I.CODIES = G.CODDOC
*/
      STINGERE S
      LEFT OUTER JOIN OBLIGPIF O_STINGATOR ON O_STINGATOR.CODOBLIGPIF = S.CODSTINGATORPIF
      LEFT OUTER JOIN GENERAL  G ON G.CODGENERAL = O_STINGATOR.CODGENERAL
      LEFT OUTER JOIN IESIRI I  ON I.CODIES = G.CODDOC AND I.TIPDOC = G.TIPDOC
      LEFT OUTER JOIN OBLIGPIF O_STINS ON O_STINS.CODOBLIGPIF = S.CODSTINSPIF
      LEFT OUTER JOIN GENERAL GEN ON GEN.CODGENERAL = O_STINS.CODGENERAL
      LEFT OUTER JOIN TMP_INFOSTINSE GREG ON GREG.CODGENERAL = GEN.CODGENERAL
/*
      LEFT OUTER JOIN REG GREG ON GREG.CODMONEDA = GEN.MONEDA
      AND GREG.AN   = PKG_GLOBALS.GETANTEMP
      AND GREG.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND GREG.TIPREG = 46
*/
    WHERE O_STINGATOR.SEMNIFICATIE IN (211, 400) AND I.AN = PKG_GLOBALS.GETANTEMP AND I.LUNA = PKG_GLOBALS.GETLUNATEMP
      AND (I.OPERAT = 1) AND (I.ANULAT = 0)
      AND PKG_NOMPART.CODPART_SOLD_ANALIZAT_VALID(O_STINGATOR.CODPART) = 1
  )
)
)
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>5C702C5D0FBC3132E915513FC8F45E399B667584</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA_TRANZACTII (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERSOANA_LUNA_JUSTIF
    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERSOANA_LUNA_AVANS

    UNION ALL


    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERSOANA_LUNA_NC_DEBIT

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERSOANA_LUNA_NC_CREDIT

    UNION ALL


    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
      V_CONVERT_SOLDPERS_LUNA_IN

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_CONVERT_SOLDPERS_LUNA_OUT

)
GROUP BY CODPERS, ICONT, CODMONEDA

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>958C4ADFE61F4B46FBF424011E2A6B13658F9C86</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_TRANZACTII (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_JUSTIF

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_AVANS


    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_NC_DEBIT

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_NC_CREDIT

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
      V_CONVERT_SOLDPERS_IN

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
    FROM
    V_CONVERT_SOLDPERS_OUT
)
GROUP BY CODPERS, ICONT, CODMONEDA
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_TRANZACTII_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>D61395E70D340281AADB8B01CF5C570669EC7844</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_TRANZACTII_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_JUSTIF_SUB

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_AVANS_SUB

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_NC_DEBIT_SUB

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
    V_SOLDPERS_NC_CREDIT_SUB

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
      V_CONVERT_SOLDPERS_IN_SUB

    UNION ALL

    SELECT
     CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
    FROM
    V_CONVERT_SOLDPERS_OUT_SUB
)
GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDURIBANCILUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9DB0FCA2D271400334EF07EC20F68DDAAE803EDB</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDURIBANCILUNA (
&quot;CODBANKCONT&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODBANKCONT, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA
FROM
V_SOLDURIBANCI_TRANZACTII
UNION ALL
SELECT CODBANKCONT, SOLDLEI, SOLDVALUTA
FROM
V_SOLDURIBANCILUNAPREC
)
GROUP BY CODBANKCONT

 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCSER_TRANZACTII_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>99262AAE55A4F2376A5D4891A59412565558E9CA</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCSER_TRANZACTII_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSER, CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM

(
  -- INTRARI IN STOC
  SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_NIRURI_SER_LUNA

  UNION ALL

  -- LIVRARI DIN STOC
  SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_LIVRARI_SER_LUNA

)
GROUP BY CODNIRSER, CODNIRSTOC 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>C7A31E5F5AB316F65BC015A3D0723F58FC900AD4</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL_TRANZACTII (
&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;TVA&quot;,&quot;SOLD&quot;,&quot;ADAOS&quot;,&quot;SOLDINTR&quot;,&quot;ADAOSINTR&quot;) AS
SELECT GEST, CODIOART, TVA, SUM(SOLD) AS SOLD, SUM(ADAOS) AS ADAOS, SUM(SOLDINTR) AS SOLDINTR, SUM(ADAOSINTR) AS ADAOSINTR
FROM
(
SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
FROM
V_STOCVAL_NIRURI
UNION ALL
SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
FROM
V_STOCVAL_LIVRARI
)
GROUP BY GEST, CODIOART, TVA 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOC_TRANZACTII_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>35EFD1B482C00CB6B099BC4C2C7CC7121A8F9B6D</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOC_TRANZACTII_LUNA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM

(
  -- INTRARI IN STOC
  SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_NIRURI_LUNA

  UNION ALL

  -- LIVRARI DIN STOC
  SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_LIVRARI_LUNA

)
GROUP BY CODNIRSTOC 
 </TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_TAXE_FACTURABILE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>81C410104B5900A435C9309D345810D69BA91566</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_TAXE_FACTURABILE (
&quot;CODARTICOL&quot;,&quot;CODOBIECT&quot;,&quot;DEN_ARTICOL&quot;,&quot;UM&quot;,&quot;CLASA&quot;,&quot;TIPSERIE&quot;,&quot;TIPARTICOL&quot;,&quot;ARETG&quot;,&quot;CONTIMPLICIT&quot;,&quot;PRODUCATOR&quot;,&quot;GESTIMPLICITA&quot;,&quot;CERTIFICAT&quot;,&quot;EVOLUTIEPRET&quot;,&quot;CONTSERVICIU&quot;,&quot;UM1&quot;,&quot;UM2&quot;,&quot;CODEXTERN&quot;,&quot;CODINTERN&quot;,&quot;UMAMBALARE&quot;,&quot;STOCMIN&quot;,&quot;STOCMAX&quot;,&quot;RETURNABIL&quot;,&quot;CODTVA&quot;,&quot;CODACCIZE&quot;,&quot;CODTAXA1&quot;,&quot;CODTAXA2&quot;,&quot;PROCTVA&quot;,&quot;DENOBIECT&quot;,&quot;VALOARE&quot;,&quot;LACEAPLIC&quot;,&quot;MASA&quot;,&quot;VOLUM&quot;,&quot;NR&quot;,&quot;JACHIZ&quot;,&quot;JVANZ&quot;,&quot;BAZAMAX&quot;,&quot;BAZAMIN&quot;,&quot;ROTVALOARE&quot;,&quot;CENTRALIZAT&quot;,&quot;TIPPART&quot;) AS
SELECT
      OBJCUR.&quot;CODARTICOL&quot;,
      OBJCUR.&quot;CODOBIECT&quot;,
      OBJCUR.&quot;DEN_ARTICOL&quot;,
      OBJCUR.&quot;UM&quot;,
      OBJCUR.&quot;CLASA&quot;,
      OBJCUR.&quot;TIPSERIE&quot;,
      OBJCUR.&quot;TIPARTICOL&quot;,
      OBJCUR.&quot;ARETG&quot;,
      OBJCUR.&quot;CONTIMPLICIT&quot;,
      OBJCUR.&quot;PRODUCATOR&quot;,
      OBJCUR.&quot;GESTIMPLICITA&quot;,
      OBJCUR.&quot;CERTIFICAT&quot;,
      OBJCUR.&quot;EVOLUTIEPRET&quot;,
      OBJCUR.&quot;CONTSERVICIU&quot;,
      OBJCUR.&quot;UM1&quot;,
      OBJCUR.&quot;UM2&quot;,
      OBJCUR.&quot;CODEXTERN&quot;,
      OBJCUR.&quot;CODINTERN&quot;,
      OBJCUR.&quot;UMAMBALARE&quot;,
      OBJCUR.&quot;STOCMIN&quot;,
      OBJCUR.&quot;STOCMAX&quot;,
      OBJCUR.&quot;RETURNABIL&quot;,
      OBJCUR.&quot;CODTVA&quot;,
      OBJCUR.&quot;CODACCIZE&quot;,
      OBJCUR.&quot;CODTAXA1&quot;,
      OBJCUR.&quot;CODTAXA2&quot;,
      OBJCUR.&quot;PROCTVA&quot;,
      OBJCUR.&quot;DENOBIECT&quot;,
      TAXE.VALOARE,
      TAXE.LACEAPLIC,
      OBJAPLIC.&quot;MASA&quot;,
      OBJAPLIC.&quot;VOLUM&quot;,
      TAXE.NR,
      TAXE.JAchiz,
      Nvl(TAXE.JVanz, 1) JVanz,
      TAXE.BazaMax,
      TAXE.BazaMin,
      TAXE.ROTVALOARE,
      NTAXE.Centralizat,
      NTAXE.TIPPART
    FROM
     V_OBJART_EXT OBJCUR
     LEFT OUTER JOIN NARTOBJ OBJAPLIC ON OBJAPLIC.CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_TAXE_FACTURARE,
(
    SELECT CODTAXA, CODSERVFACT, VALOARE, LACEAPLIC, JAchiz, JVanz, BazaMax, BazaMin, NVL(ROTVALOARE, 0) AS ROTVALOARE,  COUNT(*) AS NR
    FROM
    (
       (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, TAXELUNA.JAchiz, TAXELUNA.JVanz, TAXELUNA.BazaMax, TAXELUNA.BazaMin, TAXELUNA.ROTVALOARE FROM
        (
          SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2
          FROM
          NARTOBJ O
          LEFT OUTER JOIN
           (SELECT CODARTICOL,  CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
            A1.AnStart * 12 + A1.LunaStart =
           (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
            WHERE
             A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
            ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
          CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_TAXE_FACTURARE
        ) INFOOBIECT,

        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, JAchiz, Nvl(JVanz, 1) JVanz, BazaMax, BazaMin, ROTVALOARE

          FROM
           NTAXE1 T1
          WHERE T1.ANSTART * 12 + T1.LUNASTART = ( SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART)
          FROM NTAXE1 T2
          WHERE T2.CODTAXA = T1.CODTAXA AND T2.ANSTART * 12 + T2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 +  PKG_GLOBALS.GETLUNALUCRU) AND
          FACTURABIL = 1 AND NVL(CODSERVFACT, 0) &lt;&gt; 0
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODACCIZE = TAXELUNA.CODTAXA
       )

       UNION ALL

       (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, TAXELUNA.JAchiz, TAXELUNA.JVanz, TAXELUNA.BazaMax, TAXELUNA.BazaMin, TAXELUNA.ROTVALOARE  FROM
        (
          SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2
          FROM
          NARTOBJ O
          LEFT OUTER JOIN
           (SELECT CODARTICOL,  CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
            A1.AnStart * 12 + A1.LunaStart =
           (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
            WHERE
             A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
            ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
          CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_TAXE_FACTURARE
        ) INFOOBIECT,
        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, JAchiz, Nvl(JVanz, 1) JVanz, BazaMax, BazaMin, ROTVALOARE
          FROM
           NTAXE1 T1
          WHERE T1.ANSTART * 12 + T1.LUNASTART = ( SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART)
          FROM NTAXE1 T2
          WHERE T2.CODTAXA = T1.CODTAXA AND T2.ANSTART * 12 + T2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 +  PKG_GLOBALS.GETLUNALUCRU) AND
          FACTURABIL = 1 AND NVL(CODSERVFACT, 0) &lt;&gt; 0
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODTAXA1 = TAXELUNA.CODTAXA
       )


       UNION ALL


       (
        SELECT INFOOBIECT.CODOBIECT, TAXELUNA.CODSERVFACT, TAXELUNA.VALOARE, TAXELUNA.CODTAXA, TAXELUNA.LACEAPLIC, TAXELUNA.JAchiz, TAXELUNA.JVanz, TAXELUNA.BazaMax, TAXELUNA.BazaMin, TAXELUNA.ROTVALOARE FROM
        (
          SELECT O.CODOBIECT, NART1LUNA.CODACCIZE, NART1LUNA.CODTAXA1, NART1LUNA.CODTAXA2
          FROM
          NARTOBJ O
          LEFT OUTER JOIN
           (SELECT CODARTICOL,  CODACCIZE, CODTAXA1, CODTAXA2 FROM NART1 A1  WHERE
            A1.AnStart * 12 + A1.LunaStart =
           (SELECT MAX(A11.AnStart * 12 + A11.LunaStart) FROM NART1 A11
            WHERE
             A11.CODARTICOL = A1.CODARTICOL AND A11.AnStart * 12 + A11.LunaStart &lt;= PKG_GLOBALS.GETANLUCRU * 12 + PKG_GLOBALS.GETLUNALUCRU )
            ) NART1LUNA ON NART1LUNA.CODARTICOL = O.CODARTICOL
          WHERE
          CODOBIECT = PKG_SELECTARTICOLE.GET_OBIECT_TAXE_FACTURARE
        ) INFOOBIECT,
        (
          SELECT CODTAXA, CODTAXA1, VALOARE, FACTURABIL, CODSERVFACT, LACEAPLIC, JAchiz, Nvl(JVanz, 1) JVanz, BazaMax, BazaMin, ROTVALOARE
          FROM
           NTAXE1 T1
          WHERE T1.ANSTART * 12 + T1.LUNASTART = ( SELECT MAX(T2.ANSTART * 12 + T2.LUNASTART)
          FROM NTAXE1 T2
          WHERE T2.CODTAXA = T1.CODTAXA AND T2.ANSTART * 12 + T2.LUNASTART &lt;= PKG_GLOBALS.GETANLUCRU * 12 +  PKG_GLOBALS.GETLUNALUCRU) AND
          FACTURABIL = 1 AND NVL(CODSERVFACT, 0) &lt;&gt; 0
        ) TAXELUNA
        WHERE
         INFOOBIECT.CODTAXA2 = TAXELUNA.CODTAXA
       )
    )
    GROUP BY
    CODTAXA, CODSERVFACT, VALOARE, LACEAPLIC, JAchiz, JVanz, BazaMax, BazaMin, NVL(ROTVALOARE, 0)
) TAXE,
NTAXE
WHERE
  TAXE.CODSERVFACT = OBJCUR.CODOBIECT AND
  NTAXE.CODTAXA = Taxe.CodTaxa
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_UMAMBALARE</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>4D9786F02067276E0548984215C767FB4B9A098B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_UMAMBALARE (
&quot;CODUM1&quot;,&quot;CODUM&quot;,&quot;SECUNDARA&quot;,&quot;DEN_UM1&quot;,&quot;PARITATE&quot;,&quot;ZECIMALE&quot;) AS
SELECT 0 AS CODUM1, 0 AS CODUM, 0 AS SECUNDARA, &apos;... nedefinita ...&apos; AS DEN_UM1 , 1 AS PARITATE, 0 AS ZECIMALE FROM DUAL
UNION ALL
SELECT &quot;CODUM1&quot;,&quot;CODUM&quot;,&quot;SECUNDARA&quot;,&quot;DEN_UM1&quot;,&quot;PARITATE&quot;, &quot;ZECIMALE&quot; FROM V_UMSEC
</TEXT>
  <NIVEL>1</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_LIST_STOCSER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>85850FCA9B0A020CA5F517A7AC30350809469552</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_LIST_STOCSER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSER, CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM
(
SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2
FROM
V_LIST_STOCSER_LUNA_PREC

UNION ALL

SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2
FROM
V_LIST_STOCSER_TRANZACTII_LUNA
)
GROUP BY CODNIRSER, CODNIRSTOC 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_TRANZACTII</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>3AE458D6F56F77614101004ED3FB157F8E8BD5C8</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_TRANZACTII (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_DE_STINS

 UNION ALL

 SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
 V_SOLDPART_STINGERI
)
GROUP BY CODPART, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_TRANZACTII_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>79D5888FBEDE4684D13E6CF43ABBA97C7ECA1043</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_TRANZACTII_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
 FROM
 V_SOLDPART_DE_STINS_SUB

 UNION ALL

 SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
FROM
 V_SOLDPART_STINGERI_SUB
)
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>6C53E5179470A6126807798F068919092A1EE75B</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERS_TRANZACTII
UNION ALL
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERS_PREC
)
GROUP BY CODPERS, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERSOANA_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>0A41238E425083A945686F891D4C766209FBDE68</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERSOANA_LUNA (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERSOANA_LUNA_TRANZACTII
UNION ALL
SELECT CODPERS, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERSOANA_LUNA_PREC
)
GROUP BY CODPERS, ICONT, CODMONEDA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPERS_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BA2301BFB9E6326FF488CD2BAEECF894E73D2562</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPERS_SUB (
&quot;CODPERS&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERS_TRANZACTII_SUB
UNION ALL
SELECT CODPERS, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
FROM
V_SOLDPERS_PREC_SUB
)
GROUP BY CODPERS, ICONT, CODMONEDA, SUBUNITATEA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCLUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>EEA8D3167B572C25ED9E99B85018B0C433455DD7</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCLUNA (
&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM (
  SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_STOC_LUNA_PREC
  UNION ALL
  SELECT CODNIRSTOC, REST, RESTUM1, RESTUM2 FROM V_STOC_TRANZACTII_LUNA
) GROUP BY CODNIRSTOC</TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCSER_LUNA</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>9F5D77EEA0868031A8F702AB7E14B9F3D7832FCE</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCSER_LUNA (
&quot;CODNIRSER&quot;,&quot;CODNIRSTOC&quot;,&quot;REST&quot;,&quot;RESTUM1&quot;,&quot;RESTUM2&quot;) AS
SELECT CODNIRSER, CODNIRSTOC, SUM(REST) AS REST, SUM(RESTUM1) AS RESTUM1, SUM(RESTUM2) AS RESTUM2
FROM
(
SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2
FROM
V_STOCSER_LUNA_PREC

UNION ALL

SELECT CODNIRSER, CODNIRSTOC, REST, RESTUM1, RESTUM2
FROM
V_STOCSER_TRANZACTII_LUNA
)
GROUP BY CODNIRSER, CODNIRSTOC 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_STOCVAL</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>FAD4E88BB4FFBE60078B4D5E59251D6D956B2B15</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_STOCVAL (
&quot;GEST&quot;,&quot;CODIOART&quot;,&quot;TVA&quot;,&quot;SOLD&quot;,&quot;ADAOS&quot;,&quot;SOLDINTR&quot;,&quot;ADAOSINTR&quot;) AS
SELECT GEST, CODIOART, TVA, SUM(SOLD) SOLD, SUM(ADAOS) ADAOS, SUM(SOLDINTR) SOLDINTR, SUM(ADAOSINTR) ADAOSINTR
FROM
(
 SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
 FROM
 V_STOCVAL_TRANZACTII
 UNION ALL
 SELECT GEST, CODIOART, TVA, SOLD, ADAOS, SOLDINTR, ADAOSINTR
 FROM
 V_STOCVAL_PREC
 )
 GROUP BY  GEST, CODIOART, TVA 
 </TEXT>
  <NIVEL>2</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>167054250A35D38D018B828C11868BBB6D8E9CD5</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
  SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
  FROM
  V_SOLDPART_TRANZACTII

  UNION ALL

SELECT CODPART, ICONT, CODMONEDA, SOLDLEI, SOLDVALUTA
FROM
--V_SOLDPART_PREC
V_SOLDPARTPREC_EXT
)
GROUP BY CODPART, ICONT, CODMONEDA

 </TEXT>
  <NIVEL>3</NIVEL>
 </ROW>
 <ROW>
  <TYPE>VIEW</TYPE>
  <NAME>V_SOLDPART_SUB</NAME>
  <TEMP>N</TEMP>
  <HASHVAL>BB98C704D5A2E850EDBF8264C22517AAB8536D84</HASHVAL>
  <TEXT>CREATE OR REPLACE VIEW V_SOLDPART_SUB (
&quot;CODPART&quot;,&quot;ICONT&quot;,&quot;CODMONEDA&quot;,&quot;SUBUNITATEA&quot;,&quot;SOLDLEI&quot;,&quot;SOLDVALUTA&quot;) AS
SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SUM(SOLDLEI) AS SOLDLEI, SUM(SOLDVALUTA) AS SOLDVALUTA
FROM
(
  SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
  FROM
  V_SOLDPART_TRANZACTII_SUB

  UNION ALL

SELECT CODPART, ICONT, CODMONEDA, SUBUNITATEA, SOLDLEI, SOLDVALUTA
FROM
--V_SOLDPART_PREC_SUB
 V_SOLDPARTPRECSUB_EXT
)
GROUP BY CODPART, ICONT, CODMONEDA, SUBUNITATEA

 </TEXT>
  <NIVEL>3</NIVEL>
 </ROW>
</ROWSET>
